import { pluginManager } from '@/utils'; import { CnFormatProps } from './types'; // CnFormat.registerFormat('CnArrayView', (props: CnFormatProps) => React.ReactNode) export const registerFormat = (name: string, render: any, lowcode: any) => { pluginManager.registerPlugin([ { componentName: 'CnFormat', plugins: [ { name: `CnFormatPlugin-${name}`, sourceCode: (props: CnFormatProps, context) => { const { format } = props; if (format?.toLowerCase() === name.toLowerCase() && !props?.cell) { props.cell = render; } return { props, context }; }, lowCode: lowcode || { getPrototypeList: () => {}, }, }, ], }, ]); }; export const getAllSupportFormat = () => { const allGlobalPlugins = pluginManager.getPluginsByComponentName('CnFormat'); const allSupportFormat: string[] = []; allGlobalPlugins.forEach((plugin) => { const { name } = plugin; allSupportFormat.push(name.replace('CnFormatPlugin-', '').toLowerCase()); }); return allSupportFormat; };