mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2025-02-23 17:49:49 +08:00
build(dynamic-import): editor-sdk dynamic import succussfully
This commit is contained in:
parent
5dcde6c377
commit
1a084e115d
@ -47,9 +47,9 @@
|
||||
"lint-staged": "^11.0.0",
|
||||
"postcss": "^8.4.5",
|
||||
"postcss-import": "^14.0.2",
|
||||
"tsup": "^5.11.11",
|
||||
"tsup": "^6.2.2",
|
||||
"typescript": "^4.3.2",
|
||||
"vite": "^2.6.4"
|
||||
"vite": "^3.0.8"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
|
@ -47,9 +47,9 @@
|
||||
"@vitejs/plugin-react": "^1.0.1",
|
||||
"babel-jest": "^27.1.0",
|
||||
"jest": "^27.1.0",
|
||||
"tsup": "^5.11.11",
|
||||
"tsup": "^6.2.2",
|
||||
"typescript": "^4.5.0",
|
||||
"vite": "^2.6.13"
|
||||
"vite": "^3.0.8"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@emotion/css": "^11.7.1",
|
||||
|
@ -31,7 +31,6 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/smartxworks/sunmao-ui/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@swc/core": "^1.2.121",
|
||||
"@types/jest": "^26.0.23",
|
||||
@ -42,7 +41,8 @@
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"jest": "^27.0.6",
|
||||
"prettier": "^2.3.2",
|
||||
"tsup": "^5.11.0",
|
||||
"typescript": "^4.5.0"
|
||||
"tsup": "^6.2.2",
|
||||
"typescript": "^4.5.0",
|
||||
"vite": "^3.0.8"
|
||||
}
|
||||
}
|
||||
|
@ -9,19 +9,20 @@
|
||||
"access": "public"
|
||||
},
|
||||
"types": "lib/index.d.ts",
|
||||
"main": "dist/index.cjs.js",
|
||||
"module": "dist/index.es.js",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/esm/index.js",
|
||||
"unpkg": "dist/iife/index.js",
|
||||
"files": [
|
||||
"dist",
|
||||
"lib"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsup src/index.ts --format cjs,esm,iife --legacy-output --clean --sourcemap --platform browser --metafile",
|
||||
"dev": "tsup src/index.ts --watch --format cjs,esm,iife --legacy-output --clean --sourcemap --platform browser",
|
||||
"build": "tsup && npm run visualize",
|
||||
"dev": "tsup --platform browser",
|
||||
"typings": "tsc --emitDeclarationOnly",
|
||||
"prepublish": "npm run build && npm run typings",
|
||||
"test": "jest",
|
||||
"visualize": "esbuild-visualizer --metadata ./dist/metafile-esm.json --exclude *.png"
|
||||
"visualize": "esbuild-visualizer --metadata ./dist/metafile-iife.json --exclude *.png"
|
||||
},
|
||||
"dependencies": {
|
||||
"@chakra-ui/icons": "^1.0.15",
|
||||
@ -33,20 +34,20 @@
|
||||
"@sunmao-ui/runtime": "^0.7.3",
|
||||
"@sunmao-ui/shared": "^0.2.3",
|
||||
"codemirror": "^5.63.3",
|
||||
"lodash": "^4.17.21",
|
||||
"formik": "^2.2.9",
|
||||
"framer-motion": "^4",
|
||||
"immer": "^9.0.6",
|
||||
"lodash": "^4.17.21",
|
||||
"mitt": "^3.0.0",
|
||||
"mobx": "^6.3.8",
|
||||
"mobx-react-lite": "^3.2.2",
|
||||
"rc-select": "^14.1.5",
|
||||
"react-color": "^2.19.3",
|
||||
"tern": "^0.24.3"
|
||||
"react-color": "^2.19.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.14.182",
|
||||
"tsup": "^5.11.0"
|
||||
"esbuild": "^0.15.5",
|
||||
"tsup": "^6.2.2"
|
||||
},
|
||||
"keywords": [],
|
||||
"husky": {
|
||||
@ -61,7 +62,9 @@
|
||||
]
|
||||
},
|
||||
"peerDependencies": {
|
||||
"ajv": "^8.8.2",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2"
|
||||
"react-dom": "^17.0.2",
|
||||
"tern": "^0.24.3"
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import { implementWidget } from '../../utils/widget';
|
||||
import { ExpressionEditor, ExpressionEditorHandle } from '../Form';
|
||||
import { isExpression } from '../../utils/validator';
|
||||
import { getTypeString } from '../../utils/type';
|
||||
import Ajv, { EnumParams } from 'ajv';
|
||||
import { ValidateFunction, EnumParams } from 'ajv';
|
||||
import { ExpressionError } from '@sunmao-ui/runtime';
|
||||
import { CORE_VERSION, CoreWidgetName } from '@sunmao-ui/shared';
|
||||
|
||||
@ -143,8 +143,6 @@ export const ExpressionWidgetOptionsSpec = Type.Object({
|
||||
),
|
||||
});
|
||||
|
||||
const ajv = new Ajv();
|
||||
|
||||
type ExpressionWidgetType = `${typeof CORE_VERSION}/${CoreWidgetName.Expression}`;
|
||||
declare module '../../types/widget' {
|
||||
interface WidgetOptionsMap {
|
||||
@ -164,9 +162,11 @@ export const ExpressionWidget: React.FC<WidgetProps<ExpressionWidgetType>> = pro
|
||||
const [evaledValue, setEvaledValue] = useState<any>({ value: null });
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const editorRef = useRef<ExpressionEditorHandle>(null);
|
||||
const validate = useMemo(() => ajv.compile(spec), [spec]);
|
||||
const validateFuncRef = useRef<ValidateFunction | null>(null);
|
||||
// const validate = useMemo(() => ajv.compile(spec), [spec]);
|
||||
|
||||
const evalCode = useCallback(
|
||||
(code: string) => {
|
||||
async (code: string) => {
|
||||
try {
|
||||
const value = getParsedValue(code, type);
|
||||
const result = isExpression(value)
|
||||
@ -177,10 +177,17 @@ export const ExpressionWidget: React.FC<WidgetProps<ExpressionWidgetType>> = pro
|
||||
throw result;
|
||||
}
|
||||
|
||||
validate(result);
|
||||
if (!validateFuncRef.current) {
|
||||
const { default: Ajv } = await import('ajv');
|
||||
|
||||
if (validate.errors?.length) {
|
||||
const err = validate.errors[0];
|
||||
const ajv = new Ajv();
|
||||
validateFuncRef.current = ajv.compile(spec);
|
||||
}
|
||||
|
||||
validateFuncRef.current(result);
|
||||
|
||||
if (validateFuncRef.current.errors?.length) {
|
||||
const err = validateFuncRef.current.errors[0];
|
||||
|
||||
if (err.keyword === 'type') {
|
||||
throw new TypeError(
|
||||
@ -207,7 +214,7 @@ export const ExpressionWidget: React.FC<WidgetProps<ExpressionWidgetType>> = pro
|
||||
setError(String(err));
|
||||
}
|
||||
},
|
||||
[services, type, validate, spec]
|
||||
[services, type, spec]
|
||||
);
|
||||
const onCodeChange = useMemo(() => debounce(evalCode, 300), [evalCode]);
|
||||
const onFocus = useCallback(() => {
|
||||
|
@ -32,7 +32,10 @@ export const ColorWidget: React.FC<WidgetProps<ColorWidgetType, string>> = props
|
||||
onChange(value);
|
||||
};
|
||||
const SketchPicker = React.lazy(() => {
|
||||
return import('react-color').then(lib => ({ default: lib.SketchPicker }));
|
||||
return import('react-color').then(lib => {
|
||||
console.log('react color SketchPicker', lib.SketchPicker);
|
||||
return lib as any;
|
||||
});
|
||||
});
|
||||
|
||||
return (
|
||||
@ -62,7 +65,7 @@ export const ColorWidget: React.FC<WidgetProps<ColorWidgetType, string>> = props
|
||||
<PopoverContent w="auto">
|
||||
<PopoverArrow />
|
||||
<PopoverBody padding={0}>
|
||||
<Suspense fallback={() => '加载Picker中'}>
|
||||
<Suspense fallback={() => 'Loading Color Picker'}>
|
||||
<SketchPicker
|
||||
width="250px"
|
||||
color={value || '#fff'}
|
||||
|
13
packages/editor-sdk/tsup.config.ts
Normal file
13
packages/editor-sdk/tsup.config.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { defineConfig } from 'tsup';
|
||||
|
||||
export default defineConfig({
|
||||
entry: ['src/index.ts'],
|
||||
format: ['cjs', 'esm', 'iife'],
|
||||
legacyOutput: true,
|
||||
splitting: true,
|
||||
sourcemap: true,
|
||||
clean: true,
|
||||
dts: false,
|
||||
metafile: true,
|
||||
platform: 'browser',
|
||||
});
|
@ -63,6 +63,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/preset-react": "^7.14.5",
|
||||
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
||||
"@sunmao-ui/vite-plugins": "^1.0.5",
|
||||
"@swc/core": "^1.2.121",
|
||||
"@types/codemirror": "^5.60.5",
|
||||
@ -79,9 +80,9 @@
|
||||
"jest-css-modules": "^2.1.0",
|
||||
"postcss": "^8.4.5",
|
||||
"postcss-import": "^14.0.2",
|
||||
"tsup": "^5.11.0",
|
||||
"tsup": "^6.2.2",
|
||||
"typescript": "^4.5.0",
|
||||
"vite": "^2.6.13"
|
||||
"vite": "^3.0.8"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@emotion/react": "^11.1.1"
|
||||
|
@ -7,12 +7,13 @@ import { resolve } from 'path';
|
||||
export default defineConfig({
|
||||
base: './',
|
||||
plugins: [
|
||||
react(),
|
||||
virtualExamplePlugin(),
|
||||
react({
|
||||
jsxRuntime: 'classic',
|
||||
}),
|
||||
],
|
||||
define: {
|
||||
// https://github.com/satya164/react-simple-code-editor/issues/86
|
||||
global: 'globalThis',
|
||||
esbuild: {
|
||||
logOverride: { 'this-is-undefined-in-esm': 'silent' },
|
||||
},
|
||||
build: {
|
||||
rollupOptions: {
|
||||
|
@ -68,9 +68,9 @@
|
||||
"jest": "^27.1.0",
|
||||
"postcss": "^8.4.5",
|
||||
"postcss-import": "^14.0.2",
|
||||
"tsup": "^5.11.0",
|
||||
"tsup": "^6.2.2",
|
||||
"typescript": "^4.5.0",
|
||||
"vite": "^2.6.13"
|
||||
"vite": "^3.0.8"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^17.0.2",
|
||||
|
@ -29,7 +29,8 @@
|
||||
"devDependencies": {
|
||||
"@types/json-schema": "^7.0.7",
|
||||
"jest": "^27.1.0",
|
||||
"tsup": "^5.11.0"
|
||||
"tsup": "^6.2.2",
|
||||
"vite": "^3.0.8"
|
||||
},
|
||||
"keywords": [],
|
||||
"husky": {
|
||||
|
@ -19,11 +19,11 @@
|
||||
"body-parser": "^1.20.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vite": "^2.8.0"
|
||||
"vite": "^3.0.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/body-parser": "^1.19.2",
|
||||
"typescript": "^4.5.0",
|
||||
"vite": "^2.8.0"
|
||||
"tsup": "^6.2.2",
|
||||
"typescript": "^4.5.0"
|
||||
}
|
||||
}
|
||||
|
@ -16,5 +16,8 @@
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/smartxworks/sunmao-ui.git"
|
||||
},
|
||||
"scripts": {}
|
||||
"scripts": {},
|
||||
"devDependencies": {
|
||||
"tsup": "^6.2.2"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user