UNPKG

@shibi-snowball/c3-shared

Version:

186 lines (175 loc) 5.49 kB
const PROJECT_TARGETS = { FORMS: 'forms', REPORTS: 'reports', VIEWS: 'views', } const PLATFORMS = { WEB: 'web', PWA: 'pwa', } const C3_COMPONENTS = { WEB_EDITABLE_TABLE: 'WebEditableTable', WEB_FORM_FIELD: 'WebFormField', WEB_READONLY_TABLE: 'WebReadonlyTable', WEB_CARD: 'WebCard', PWA_FORM_FIELD: 'PwaFormField', PWA_READONLY_TABLE: 'PwaReadonlyTable', PWA_CARD: 'PwaCard', } const C3_SCHEMA = { type: 'object', properties: { target: { type: 'string', enum: Object.values(PROJECT_TARGETS), }, components: { type: 'object', properties: Object.keys(C3_COMPONENTS).reduce((acc, key) => { acc[C3_COMPONENTS[key]] = { type: 'string', pattern: '^(?:\\.\\/)?[^/]+\\/.*\\.jsx$', } return acc }, {}), additionalProperties: false, default: {}, }, }, required: ['target', 'components'], additionalProperties: false, } const getC3ComponentKey = (value) => { for (const key in C3_COMPONENTS) { if (C3_COMPONENTS[key] === value) { return key } } throw new Error( `The value supplied (${value}, doesn't have an associated key in C3_COMPONENTS.)` ) } const getC3ProjectTargetKey = (value) => { for (const key in PROJECT_TARGETS) { if (PROJECT_TARGETS[key] === value) { return key } } throw new Error( `The value supplied (${value}, doesn't have an associated key in PROJECT_TARGETS.)` ) } const dataTypes = {} const fileMap = { [PROJECT_TARGETS.FORMS]: [ { c3Component: C3_COMPONENTS.WEB_EDITABLE_TABLE, c3ComponentKey: getC3ComponentKey(C3_COMPONENTS.WEB_EDITABLE_TABLE), moduleName: C3_COMPONENTS.WEB_EDITABLE_TABLE + '.jsx', moduleFolderPath: 'src', isMandatory: false, props: { getFieldId: dataTypes.func, getFieldName: dataTypes.string, }, }, { c3Component: C3_COMPONENTS.WEB_FORM_FIELD, c3ComponentKey: getC3ComponentKey(C3_COMPONENTS.WEB_FORM_FIELD), moduleName: C3_COMPONENTS.WEB_FORM_FIELD + '.jsx', moduleFolderPath: 'src', isMandatory: true, props: { getFieldId: dataTypes.func, getFieldName: dataTypes.string, }, }, { c3Component: C3_COMPONENTS.WEB_READONLY_TABLE, c3ComponentKey: getC3ComponentKey(C3_COMPONENTS.WEB_READONLY_TABLE), moduleName: C3_COMPONENTS.WEB_READONLY_TABLE + '.jsx', moduleFolderPath: 'src', isMandatory: false, props: { getFieldId: dataTypes.func, getFieldName: dataTypes.string, }, }, { c3Component: C3_COMPONENTS.WEB_CARD, c3ComponentKey: getC3ComponentKey(C3_COMPONENTS.WEB_CARD), moduleName: C3_COMPONENTS.WEB_CARD + '.jsx', moduleFolderPath: 'src', isMandatory: false, props: { getFieldId: dataTypes.func, getFieldName: dataTypes.string, }, }, { c3Component: C3_COMPONENTS.PWA_FORM_FIELD, c3ComponentKey: getC3ComponentKey(C3_COMPONENTS.PWA_FORM_FIELD), moduleName: C3_COMPONENTS.PWA_FORM_FIELD + '.jsx', moduleFolderPath: 'src', isMandatory: false, props: { getFieldId: dataTypes.func, getFieldName: dataTypes.string, }, }, { c3Component: C3_COMPONENTS.PWA_READONLY_TABLE, c3ComponentKey: getC3ComponentKey(C3_COMPONENTS.PWA_READONLY_TABLE), moduleName: C3_COMPONENTS.PWA_READONLY_TABLE + '.jsx', moduleFolderPath: 'src', isMandatory: false, props: { getFieldId: dataTypes.func, getFieldName: dataTypes.string, }, }, { c3Component: C3_COMPONENTS.PWA_CARD, c3ComponentKey: getC3ComponentKey(C3_COMPONENTS.PWA_CARD), moduleName: C3_COMPONENTS.PWA_CARD + '.jsx', moduleFolderPath: 'src', isMandatory: false, props: { getFieldId: dataTypes.func, getFieldName: dataTypes.string, }, }, ], // [PROJECT_TARGETS.REPORTS]: { // [PLATFORMS.WEB]: [ // { // componentName: "Report", // relativePath: "./src/Report.jsx", // }, // ], // [PLATFORMS.PWA]: [], // }, // [PROJECT_TARGETS.VIEWS]: { // [PLATFORMS.WEB]: [ // { // componentName: "View", // relativePath: "./src/View.jsx", // }, // ], // [PLATFORMS.PWA]: [], // }, } // If you are updating this, please make sure that you are updaing // the main-client's (kf-xg-frontend) react and react-dom version as well. const SUPPORTED_REACT_VERSION = '^18.2.0' const SUPPORTED_REACT_DOM_VERSION = '^18.2.0' export { C3_COMPONENTS, fileMap, SUPPORTED_REACT_VERSION, SUPPORTED_REACT_DOM_VERSION, PROJECT_TARGETS, PLATFORMS, getC3ProjectTargetKey, C3_SCHEMA, }