From c2db198415632e3fa9653a1c08646f0a67514257 Mon Sep 17 00:00:00 2001 From: JackLian Date: Thu, 22 Dec 2022 12:10:00 +0800 Subject: [PATCH] feat: add some big features to engine --- docs/docs/api/common.md | 4 +- docs/docs/api/hotkey.md | 2 +- docs/docs/api/logger.md | 10 +- docs/docs/api/material.md | 15 +- docs/docs/api/plugins.md | 50 +- docs/docs/api/project.md | 6 +- docs/docs/api/setters.md | 6 +- docs/docs/guide/expand/editor/cli.md | 3 +- docs/docs/guide/expand/editor/material.md | 5 +- .../guide/expand/editor/pluginContextMenu.md | 6 +- docs/docs/guide/expand/editor/pluginWidget.md | 5 +- docs/docs/guide/expand/editor/summary.md | 8 +- docs/docs/guide/quickStart/start.md | 4 +- modules/code-generator/babelTransform.js | 22 + modules/code-generator/jest.config.js | 4 + modules/code-generator/package.json | 5 +- .../src/analyzer/componentAnalyzer.ts | 6 +- modules/code-generator/src/cli/run.ts | 4 +- .../src/generator/ModuleBuilder.ts | 4 +- .../src/generator/ProjectBuilder.ts | 6 +- .../code-generator/src/parser/SchemaParser.ts | 50 +- .../rax/containerInjectDataSourceEngine.ts | 8 +- .../src/plugins/component/rax/jsx.ts | 20 +- .../react/containerInjectDataSourceEngine.ts | 8 +- .../src/plugins/component/react/jsx.ts | 6 +- .../framework/rax/plugins/packageJSON.ts | 8 +- .../code-generator/src/standalone-loader.ts | 4 +- .../code-generator/src/standalone-worker.ts | 4 +- modules/code-generator/src/types/analyze.ts | 4 +- modules/code-generator/src/types/core.ts | 46 +- .../code-generator/src/types/intermediate.ts | 17 +- modules/code-generator/src/types/jsx.ts | 10 +- .../code-generator/src/utils/compositeType.ts | 28 +- .../code-generator/src/utils/jsExpression.ts | 6 +- modules/code-generator/src/utils/jsSlot.ts | 6 +- modules/code-generator/src/utils/nodeToJSX.ts | 28 +- modules/code-generator/src/utils/schema.ts | 32 +- .../tests/bugfix/i18n-with-params.test.ts | 4 +- .../bugfix/icejs-import-wrong-naming.test.ts | 4 +- .../bugfix/strict-mode-context-1.test.ts | 4 +- .../tolerate-eval-errors-1-loop.test.ts | 4 +- ...tolerate-eval-errors-2-nested-loop.test.ts | 4 +- .../p0-condition-at-root.test.ts.snap | 8 +- .../public/SchemaParser/p0-basic.test.ts | 4 +- .../tests/public/solutions/rax-app.test.ts | 4 +- .../tests/public/solutions/react-app.test.ts | 4 +- .../tests/utils/schema/handleSubNodes.test.ts | 6 +- .../test/fixtures/rax-component/package.json | 1 - .../test/fixtures/ts-component2/package.json | 1 - package.json | 6 +- packages/designer/babelTransform.js | 22 + packages/designer/jest.config.js | 6 +- packages/designer/package.json | 11 +- .../bem-tools/border-container.tsx | 13 +- .../bem-tools/border-detecting.tsx | 4 +- .../bem-tools/border-resizing.tsx | 7 +- .../bem-tools/border-selecting.tsx | 9 +- .../bem-tools/drag-resize-engine.ts | 6 +- .../builtin-simulator/bem-tools/insertion.tsx | 16 +- .../src/builtin-simulator/create-simulator.ts | 1 + .../src/builtin-simulator/host-view.tsx | 17 +- .../designer/src/builtin-simulator/host.ts | 229 +++------ .../live-editing/live-editing.ts | 15 +- .../builtin-simulator/node-selector/index.tsx | 13 +- .../src/builtin-simulator/renderer.ts | 13 +- .../builtin-simulator/resource-consumer.ts | 5 +- .../src/builtin-simulator/utils/clickable.ts | 2 +- .../builtin-simulator/utils/parse-metadata.ts | 18 +- .../src/builtin-simulator/utils/path.ts | 2 +- packages/designer/src/component-meta.ts | 97 ++-- .../designer/src/designer/active-tracker.ts | 40 +- .../designer/src/designer/builtin-hotkey.ts | 354 ------------- packages/designer/src/designer/clipboard.ts | 2 +- .../designer/src/designer/designer-view.tsx | 14 +- packages/designer/src/designer/designer.ts | 136 +++-- packages/designer/src/designer/detecting.ts | 22 +- .../src/designer/drag-ghost/index.tsx | 10 +- packages/designer/src/designer/dragon.ts | 131 ++--- packages/designer/src/designer/index.ts | 5 +- packages/designer/src/designer/location.ts | 100 ++-- .../designer/src/designer/offset-observer.ts | 2 +- packages/designer/src/designer/scroller.ts | 22 +- .../src/designer/setting/setting-entry.ts | 4 +- .../src/designer/setting/setting-field.ts | 38 +- .../designer/setting/setting-prop-entry.ts | 22 +- .../src/designer/setting/setting-top-entry.ts | 15 +- .../designer/src/designer/setting/utils.ts | 13 +- .../designer/src/document/document-model.ts | 114 ++-- packages/designer/src/document/history.ts | 41 +- .../src/document/node/exclusive-group.ts | 11 +- .../src/document/node/modal-nodes-manager.ts | 13 +- .../src/document/node/node-children.ts | 101 ++-- packages/designer/src/document/node/node.ts | 118 +++-- .../designer/src/document/node/props/prop.ts | 34 +- .../designer/src/document/node/props/props.ts | 16 +- .../document/node/props/value-to-source.ts | 2 + packages/designer/src/document/selection.ts | 14 +- packages/designer/src/icons/index.ts | 1 - .../designer/src/plugin/plugin-context.ts | 45 +- .../designer/src/plugin/plugin-manager.ts | 76 +-- packages/designer/src/plugin/plugin-types.ts | 173 ++----- packages/designer/src/plugin/plugin-utils.ts | 15 +- packages/designer/src/plugin/plugin.ts | 46 +- .../designer/src/project/project-view.tsx | 3 +- packages/designer/src/project/project.less | 4 + packages/designer/src/project/project.ts | 71 ++- packages/designer/src/simulator.ts | 44 +- packages/designer/src/transducers/index.ts | 2 +- packages/designer/src/types/index.ts | 8 +- packages/designer/src/utils/invariant.ts | 2 +- packages/designer/src/utils/slot.ts | 2 +- .../tests/bugs/prop-variable-jse.test.ts | 4 +- .../tests/builtin-simulator/host.test.ts | 28 +- .../tests/designer/builtin-hotkey.test.ts | 41 +- .../designer/tests/designer/designer.test.ts | 50 +- .../designer/tests/designer/dragon.test.ts | 28 +- .../designer/setting/setting-field.test.ts | 11 +- .../setting/setting-prop-entry.test.ts | 8 +- .../setting/setting-top-entry.test.ts | 3 +- .../document-model/document-model.test.ts | 2 +- .../tests/document/history/history.test.ts | 6 +- .../tests/document/node/props/prop.test.ts | 26 +- .../fixtures/component-metadata/abcgroup.ts | 4 +- .../fixtures/component-metadata/abcitem.ts | 4 +- .../fixtures/component-metadata/abcnode.ts | 4 +- .../fixtures/component-metadata/abcoption.ts | 4 +- .../fixtures/component-metadata/button.ts | 6 +- .../fixtures/component-metadata/dialog.ts | 4 +- .../tests/fixtures/component-metadata/div.ts | 4 +- .../fixtures/component-metadata/div10.ts | 4 +- .../tests/fixtures/component-metadata/div2.ts | 4 +- .../tests/fixtures/component-metadata/div3.ts | 4 +- .../tests/fixtures/component-metadata/div4.ts | 4 +- .../tests/fixtures/component-metadata/div5.ts | 4 +- .../tests/fixtures/component-metadata/div6.ts | 4 +- .../tests/fixtures/component-metadata/div7.ts | 4 +- .../tests/fixtures/component-metadata/div8.ts | 4 +- .../tests/fixtures/component-metadata/div9.ts | 4 +- .../tests/fixtures/component-metadata/form.ts | 4 +- .../fixtures/component-metadata/other.ts | 4 +- .../tests/fixtures/component-metadata/page.ts | 4 +- .../fixtures/component-metadata/page2.ts | 4 +- .../component-metadata/root-content.ts | 4 +- .../component-metadata/root-footer.ts | 4 +- .../component-metadata/root-header.ts | 4 +- .../tests/plugin/plugin-manager.test.ts | 100 ++-- .../tests/project/project-methods.test.ts | 4 +- packages/editor-core/package.json | 4 +- packages/editor-core/src/config.ts | 20 +- packages/editor-core/src/di/setter.ts | 94 +++- packages/editor-core/src/editor.ts | 86 +++- packages/editor-core/src/event-bus.ts | 101 ++++ packages/editor-core/src/hotkey.ts | 62 ++- packages/editor-core/src/index.ts | 1 + .../editor-core/src/intl/global-locale.ts | 69 +-- packages/editor-core/src/utils/app-preset.ts | 6 +- .../editor-core/src/utils/assets-transform.ts | 8 +- .../editor-core/src/utils/focus-tracker.ts | 4 +- packages/editor-core/src/utils/logger.ts | 2 +- packages/editor-core/src/utils/preference.ts | 7 +- .../src/widgets/tip/tip-handler.ts | 12 +- .../editor-core/src/widgets/tip/tip-item.tsx | 6 +- packages/editor-core/src/widgets/tip/tip.tsx | 4 +- .../editor-core/src/widgets/title/index.tsx | 6 +- packages/editor-skeleton/package.json | 1 - packages/editor-skeleton/src/area.ts | 7 +- .../src/components/field/fields.tsx | 9 +- .../src/components/field/index.ts | 4 +- .../src/components/popup/index.tsx | 4 +- .../src/components/settings/main.ts | 13 +- .../src/components/settings/settings-pane.tsx | 23 +- .../settings/settings-primary-pane.tsx | 21 +- .../src/components/stage-box/stage-chain.ts | 6 +- .../src/components/widget-views/index.tsx | 30 +- .../widget-views/panel-operation-row.tsx | 2 +- packages/editor-skeleton/src/index.ts | 2 + .../src/layouts/bottom-area.tsx | 4 +- .../editor-skeleton/src/layouts/left-area.tsx | 2 +- .../src/layouts/left-fixed-pane.tsx | 4 +- .../src/layouts/left-float-pane.tsx | 7 +- .../editor-skeleton/src/layouts/main-area.tsx | 6 +- .../src/layouts/right-area.tsx | 4 +- .../editor-skeleton/src/layouts/toolbar.tsx | 2 +- .../editor-skeleton/src/layouts/top-area.tsx | 2 +- .../src/layouts/workbench.less | 30 +- packages/editor-skeleton/src/skeleton.ts | 50 +- .../src/transducers/addon-combine.ts | 14 +- .../src/transducers/parse-func.ts | 13 +- .../src/transducers/parse-props.ts | 34 +- packages/editor-skeleton/src/types.ts | 33 +- packages/editor-skeleton/src/widget/dock.ts | 2 +- packages/editor-skeleton/src/widget/index.ts | 6 + .../editor-skeleton/src/widget/panel-dock.ts | 4 +- packages/editor-skeleton/src/widget/panel.ts | 15 +- packages/editor-skeleton/src/widget/stage.ts | 2 +- packages/editor-skeleton/src/widget/utils.ts | 4 +- .../src/widget/widget-container.ts | 7 +- packages/editor-skeleton/src/widget/widget.ts | 11 +- packages/engine/package.json | 1 - packages/engine/src/engine-core.ts | 191 +++---- packages/engine/src/index.ts | 2 +- .../src/inner-plugins/builtin-hotkey.ts | 412 +++++++++++++++ .../inner-plugins/component-meta-parser.ts | 20 + .../inner-plugins/default-panel-registry.tsx | 43 ++ .../src/inner-plugins/setter-registry.ts | 17 + packages/engine/src/modules/designer-types.ts | 4 - packages/engine/src/modules/live-editing.ts | 4 +- packages/engine/src/modules/lowcode-types.ts | 2 +- packages/engine/src/modules/skeleton-types.ts | 4 +- packages/plugin-designer/package.json | 3 +- packages/plugin-designer/src/index.tsx | 19 +- packages/plugin-outline-pane/package.json | 1 - .../pane-controller.ts} | 412 +++++++-------- .../src/{ => controllers}/tree-master.ts | 65 +-- .../src/{ => controllers}/tree-node.ts | 102 ++-- .../src/controllers/tree.ts | 64 +++ .../plugin-outline-pane/src/helper/consts.ts | 2 + .../src/helper/dwell-timer.ts | 16 +- .../src/helper/indent-track.ts | 17 +- .../plugin-outline-pane/src/icons/index.ts | 9 + .../plugin-outline-pane/src/icons/setting.tsx | 12 + packages/plugin-outline-pane/src/index.ts | 16 - packages/plugin-outline-pane/src/index.tsx | 128 +++++ .../plugin-outline-pane/src/locale/en-US.json | 3 +- .../plugin-outline-pane/src/locale/index.ts | 8 +- .../plugin-outline-pane/src/locale/zh-CN.json | 3 +- packages/plugin-outline-pane/src/tree.ts | 37 -- .../src/views/backup-pane.tsx | 19 - .../src/views/filter-tree.ts | 2 +- .../plugin-outline-pane/src/views/filter.tsx | 17 +- .../plugin-outline-pane/src/views/pane.tsx | 37 +- .../src/views/root-tree-node.tsx | 149 ++++-- .../plugin-outline-pane/src/views/style.less | 8 +- .../src/views/tree-branches.tsx | 110 +++- .../src/views/tree-node.tsx | 125 ++++- .../src/views/tree-title.tsx | 299 +++++++---- .../plugin-outline-pane/src/views/tree.tsx | 98 ++-- packages/rax-simulator-renderer/package.json | 1 - .../src/renderer-view.tsx | 2 +- .../rax-simulator-renderer/src/renderer.ts | 33 +- packages/react-renderer/jest.config.js | 2 +- packages/react-renderer/package.json | 1 - .../react-simulator-renderer/jest.config.js | 2 +- .../react-simulator-renderer/package.json | 3 +- .../src/renderer-view.tsx | 3 +- .../react-simulator-renderer/src/renderer.ts | 12 +- packages/renderer-core/jest.config.js | 2 +- packages/renderer-core/package.json | 6 +- packages/renderer-core/src/hoc/leaf.tsx | 21 +- packages/renderer-core/src/renderer/base.tsx | 24 +- packages/renderer-core/src/renderer/page.tsx | 2 +- .../renderer-core/src/renderer/renderer.tsx | 6 +- packages/renderer-core/src/types/index.ts | 22 +- packages/renderer-core/src/utils/common.ts | 8 +- .../renderer-core/src/utils/is-use-loop.ts | 4 +- packages/renderer-core/src/utils/logger.ts | 4 +- packages/renderer-core/tests/utils/node.ts | 4 +- packages/shell/package.json | 10 +- packages/shell/src/api/canvas.ts | 59 +++ packages/shell/src/{ => api}/common.tsx | 105 ++-- packages/shell/src/{ => api}/event.ts | 35 +- packages/shell/src/api/hotkey.ts | 47 ++ packages/shell/src/api/index.ts | 12 + packages/shell/src/api/logger.ts | 48 ++ packages/shell/src/{ => api}/material.ts | 54 +- packages/shell/src/api/plugins.ts | 63 +++ packages/shell/src/{ => api}/project.ts | 58 ++- packages/shell/src/api/setters.ts | 63 +++ .../shell/src/{ => api}/simulator-host.ts | 5 +- packages/shell/src/{ => api}/skeleton.ts | 64 ++- packages/shell/src/api/workspace.ts | 24 + packages/shell/src/canvas.ts | 23 - packages/shell/src/dragon.ts | 77 --- packages/shell/src/hotkey.ts | 27 - packages/shell/src/index.ts | 47 +- .../shell/src/{ => model}/component-meta.ts | 23 +- packages/shell/src/{ => model}/detecting.ts | 21 +- .../shell/src/{ => model}/document-model.ts | 85 +-- packages/shell/src/{ => model}/drag-object.ts | 10 +- packages/shell/src/model/dragon.ts | 117 +++++ .../shell/src/{ => model}/drop-location.ts | 6 +- packages/shell/src/{ => model}/history.ts | 4 +- packages/shell/src/model/index.ts | 16 + .../shell/src/{ => model}/locate-event.ts | 6 +- .../src/{ => model}/modal-nodes-manager.ts | 8 +- .../shell/src/{ => model}/node-children.ts | 65 ++- packages/shell/src/{ => model}/node.ts | 151 ++++-- packages/shell/src/{ => model}/prop.ts | 14 +- packages/shell/src/{ => model}/props.ts | 18 +- packages/shell/src/{ => model}/selection.ts | 17 +- .../src/{ => model}/setting-prop-entry.ts | 32 +- .../src/{ => model}/setting-top-entry.ts | 8 +- packages/shell/src/model/window.ts | 23 + packages/shell/src/setters.ts | 36 -- packages/shell/src/symbols.ts | 6 +- packages/types/package.json | 3 +- packages/types/src/activity.ts | 4 +- packages/types/src/assets.ts | 199 ------- .../src/deprecated/isActionContentObject.ts | 4 +- packages/types/src/deprecated/isCustomView.ts | 4 +- packages/types/src/deprecated/isDOMText.ts | 4 +- .../types/src/deprecated/isDynamicSetter.ts | 4 +- packages/types/src/deprecated/isI18nData.ts | 3 +- packages/types/src/deprecated/isJSBlock.ts | 4 +- .../types/src/deprecated/isJSExpression.ts | 4 +- packages/types/src/deprecated/isJSFunction.ts | 4 +- packages/types/src/deprecated/isJSSlot.ts | 4 +- .../src/deprecated/isLowCodeComponentType.ts | 4 +- packages/types/src/deprecated/isNodeSchema.ts | 4 +- .../src/deprecated/isProCodeComponentType.ts | 4 +- .../types/src/deprecated/isProjectSchema.ts | 4 +- .../types/src/deprecated/isSetterConfig.ts | 4 +- .../types/src/deprecated/isTitleConfig.ts | 4 +- packages/types/src/designer.ts | 36 +- packages/types/src/disposable.ts | 3 - packages/types/src/dragon.ts | 99 +++- packages/types/src/editor-skeleton.ts | 35 +- packages/types/src/editor.ts | 67 +-- packages/types/src/engine-config.ts | 50 +- packages/types/src/field-config.ts | 111 ---- packages/types/src/i18n.ts | 11 - packages/types/src/icon.ts | 9 - packages/types/src/index.ts | 28 +- packages/types/src/metadata.ts | 485 ------------------ packages/types/src/node.ts | 5 + packages/types/src/npm.ts | 83 --- packages/types/src/prop-config.ts | 65 --- packages/types/src/props-transducer.ts | 12 - packages/types/src/schema.ts | 213 +------- packages/types/src/shell/api/canvas.ts | 38 ++ packages/types/src/shell/api/common.ts | 18 +- packages/types/src/shell/api/event.ts | 7 +- packages/types/src/shell/api/hotkey.ts | 6 +- packages/types/src/shell/api/index.ts | 6 +- packages/types/src/shell/api/logger.ts | 33 ++ packages/types/src/shell/api/material.ts | 20 +- packages/types/src/shell/api/plugins.ts | 37 ++ packages/types/src/shell/api/project.ts | 26 +- packages/types/src/shell/api/setters.ts | 12 +- packages/types/src/shell/api/skeleton.ts | 15 +- packages/types/src/shell/api/workspace.ts | 1 + .../types/src/shell/enum/drag-object-type.ts | 14 + packages/types/src/shell/enum/event-names.ts | 15 + packages/types/src/shell/enum/index.ts | 5 + .../src/shell/enum/prop-value-changed-type.ts | 25 + .../types/src/shell/enum/transform-stage.ts | 19 + .../types/src/shell/enum/transition-type.ts | 13 + packages/types/src/shell/index.ts | 16 +- .../types/src/shell/model/active-tracker.ts | 5 + packages/types/src/shell/model/canvas.ts | 4 - .../types/src/shell/model/component-meta.ts | 23 +- packages/types/src/shell/model/detecting.ts | 10 + .../types/src/shell/model/document-model.ts | 36 +- packages/types/src/shell/model/dragon.ts | 26 +- packages/types/src/shell/model/editor.ts | 29 ++ .../types/src/shell/model/engine-config.ts | 54 ++ .../types/src/shell/model/exclusive-group.ts | 8 + packages/types/src/shell/model/index.ts | 14 +- .../types/src/shell/model/locate-event.ts | 32 +- .../src/shell/model/modal-nodes-manager.ts | 2 +- .../types/src/shell/model/node-children.ts | 25 +- packages/types/src/shell/model/node.ts | 112 +++- .../types/src/shell/model/plugin-context.ts | 47 ++ packages/types/src/shell/model/prop.ts | 10 +- packages/types/src/shell/model/props.ts | 11 +- .../types/src/shell/model/scroll-target.ts | 9 + packages/types/src/shell/model/scrollable.ts | 7 + packages/types/src/shell/model/scroller.ts | 8 + packages/types/src/shell/model/selection.ts | 8 +- .../src/shell/model/setting-prop-entry.ts | 20 +- .../src/{ => shell/model}/setting-target.ts | 17 +- .../src/shell/model/setting-top-entry.ts | 3 +- packages/types/src/shell/model/window.ts | 1 + .../src/shell/type/action-content-object.ts | 19 + .../types/src/shell/type/active-target.ts | 8 + packages/types/src/shell/type/advanced.ts | 85 +++ .../types/src/{ => shell/type}/app-config.ts | 10 +- packages/types/src/shell/type/assets-json.ts | 34 ++ packages/types/src/shell/type/block-schema.ts | 10 + .../types/src/shell/type/component-action.ts | 30 ++ .../src/shell/type/component-description.ts | 16 + .../src/shell/type/component-instance.ts | 6 + .../src/shell/type/component-metadata.ts | 80 +++ .../types/src/shell/type/component-schema.ts | 10 + .../types/src/shell/type/component-sort.ts | 14 + .../types/src/shell/type/composite-value.ts | 11 + packages/types/src/shell/type/configure.ts | 23 + .../types/src/shell/type/container-schema.ts | 57 ++ packages/types/src/shell/type/custom-view.ts | 3 + packages/types/src/shell/type/disposable.ts | 3 + packages/types/src/shell/type/dom-text.ts | 1 + .../types/src/shell/type/drag-any-object.ts | 5 + .../src/shell/type/drag-node-data-object.ts | 10 + .../types/src/shell/type/drag-node-object.ts | 7 + packages/types/src/shell/type/drag-object.ts | 4 + .../types/src/shell/type/dynamic-props.ts | 3 + .../types/src/shell/type/dynamic-setter.ts | 5 + packages/types/src/shell/type/field-config.ts | 43 ++ .../types/src/shell/type/field-extra-props.ts | 67 +++ .../types/src/shell/type/hotkey-callback.ts | 2 + packages/types/src/shell/type/i18n-map.ts | 4 + packages/types/src/shell/type/i8n-data.ts | 7 + packages/types/src/shell/type/icon-config.ts | 6 + packages/types/src/shell/type/icon-type.ts | 4 + packages/types/src/shell/type/index.ts | 74 +++ packages/types/src/shell/type/location.ts | 54 ++ .../src/shell/type/metadata-transducer.ts | 16 + packages/types/src/shell/type/metadata.ts | 202 ++++++++ packages/types/src/shell/type/node-data.ts | 3 + packages/types/src/shell/type/node-schema.ts | 56 ++ packages/types/src/shell/type/npm-info.ts | 33 ++ packages/types/src/shell/type/npm.ts | 16 + packages/types/src/shell/type/package.ts | 55 ++ packages/types/src/shell/type/page-schema.ts | 9 + .../types/src/shell/type/plugin-config.ts | 5 + .../types/src/shell/type/plugin-creater.ts | 5 + .../shell/type/plugin-declaration-property.ts | 21 + .../src/shell/type/plugin-declaration.ts | 11 + packages/types/src/shell/type/plugin-meta.ts | 29 ++ packages/types/src/shell/type/plugin.ts | 7 + .../src/shell/type/preference-value-type.ts | 2 + .../types/src/shell/type/project-schema.ts | 66 +++ .../src/shell/type/prop-change-options.ts | 12 + packages/types/src/shell/type/prop-config.ts | 27 + packages/types/src/shell/type/prop-types.ts | 42 ++ packages/types/src/shell/type/props-list.ts | 7 + packages/types/src/shell/type/props-map.ts | 3 + .../types/src/shell/type/props-transducer.ts | 11 + packages/types/src/shell/type/reference.ts | 35 ++ .../types/src/shell/type/registered-setter.ts | 18 + .../type/remote-component-description.ts | 26 + packages/types/src/shell/type/root-schema.ts | 7 + .../types/src/shell/type/set-value-options.ts | 7 + .../src/{ => shell/type}/setter-config.ts | 28 +- packages/types/src/shell/type/setter-type.ts | 6 + packages/types/src/shell/type/snippet.ts | 27 + packages/types/src/shell/type/tip-config.ts | 9 + packages/types/src/shell/type/tip-content.ts | 5 + packages/types/src/shell/type/title-config.ts | 28 + .../types/src/shell/type/title-content.ts | 5 + .../type/transformed-component-metadata.ts | 8 + .../types/src/{ => shell/type}/value-type.ts | 46 +- .../src/shell/type/widget-base-config.ts | 18 + .../src/shell/type/widget-config-area.ts | 9 + packages/types/src/start-transaction.ts | 4 - packages/types/src/tip.ts | 11 - packages/types/src/title.ts | 32 -- packages/types/src/transform-stage.ts | 8 - packages/types/src/utils.ts | 17 - packages/utils/package.json | 6 +- packages/utils/src/asset.ts | 11 +- packages/utils/src/build-components.ts | 15 +- packages/utils/src/check-types/index.ts | 9 +- .../check-types/is-action-content-object.ts | 4 +- .../utils/src/check-types/is-custom-view.ts | 4 +- packages/utils/src/check-types/is-dom-text.ts | 4 +- .../src/check-types/is-drag-any-object.ts | 5 + .../check-types/is-drag-node-data-object.ts | 5 + .../src/check-types/is-drag-node-object.ts | 5 + .../src/check-types/is-dynamic-setter.ts | 4 +- .../utils/src/check-types/is-i18n-data.ts | 3 +- .../utils/src/check-types/is-isfunction.ts | 3 +- packages/utils/src/check-types/is-jsblock.ts | 3 +- .../utils/src/check-types/is-jsexpression.ts | 4 +- packages/utils/src/check-types/is-jsslot.ts | 4 +- .../is-location-children-detail.ts | 5 + .../utils/src/check-types/is-location-data.ts | 4 + .../check-types/is-lowcode-component-type.ts | 4 +- .../utils/src/check-types/is-node-schema.ts | 4 +- packages/utils/src/check-types/is-node.ts | 3 + .../check-types/is-procode-component-type.ts | 4 +- .../src/check-types/is-project-schema.ts | 4 +- .../utils/src/check-types/is-setter-config.ts | 4 +- .../utils/src/check-types/is-setting-field.ts | 3 + .../utils/src/check-types/is-title-config.ts | 3 +- packages/utils/src/create-icon.tsx | 4 +- packages/utils/src/index.ts | 3 + packages/utils/src/is-plugin-event-name.ts | 8 + packages/utils/src/is-public-event-name.ts | 10 + packages/utils/src/is-shaken.ts | 15 + packages/utils/src/logger.ts | 195 ++++++- packages/utils/src/schema.ts | 24 +- packages/utils/src/transaction-manager.ts | 8 +- packages/workspace/build.json | 5 + packages/workspace/build.test.json | 6 + packages/workspace/jest.config.js | 9 + packages/workspace/package.json | 54 ++ packages/workspace/src/base-context.ts | 141 +++++ packages/workspace/src/editor-view/context.ts | 43 ++ packages/workspace/src/editor-view/view.tsx | 29 ++ .../workspace/src/editor-window/context.ts | 113 ++++ packages/workspace/src/editor-window/view.tsx | 33 ++ packages/workspace/src/index.ts | 84 +++ .../workspace/src/layouts/bottom-area.tsx | 34 ++ packages/workspace/src/layouts/left-area.tsx | 47 ++ .../workspace/src/layouts/left-fixed-pane.tsx | 42 ++ .../workspace/src/layouts/left-float-pane.tsx | 130 +++++ packages/workspace/src/layouts/main-area.tsx | 16 + packages/workspace/src/layouts/theme.less | 62 +++ packages/workspace/src/layouts/top-area.tsx | 62 +++ packages/workspace/src/layouts/workbench.less | 398 ++++++++++++++ packages/workspace/src/layouts/workbench.tsx | 49 ++ packages/workspace/src/less-variables.less | 215 ++++++++ packages/workspace/src/resource.ts | 41 ++ packages/workspace/src/shell-model-factory.ts | 18 + packages/workspace/src/skeleton-context.ts | 3 + packages/workspace/tsconfig.json | 9 + 507 files changed, 9268 insertions(+), 5211 deletions(-) create mode 100644 modules/code-generator/babelTransform.js create mode 100644 packages/designer/babelTransform.js delete mode 100644 packages/designer/src/designer/builtin-hotkey.ts create mode 100644 packages/editor-core/src/event-bus.ts create mode 100644 packages/editor-skeleton/src/widget/index.ts create mode 100644 packages/engine/src/inner-plugins/builtin-hotkey.ts create mode 100644 packages/engine/src/inner-plugins/component-meta-parser.ts create mode 100644 packages/engine/src/inner-plugins/default-panel-registry.tsx create mode 100644 packages/engine/src/inner-plugins/setter-registry.ts rename packages/plugin-outline-pane/src/{main.ts => controllers/pane-controller.ts} (75%) rename packages/plugin-outline-pane/src/{ => controllers}/tree-master.ts (53%) rename packages/plugin-outline-pane/src/{ => controllers}/tree-node.ts (61%) create mode 100644 packages/plugin-outline-pane/src/controllers/tree.ts create mode 100644 packages/plugin-outline-pane/src/helper/consts.ts create mode 100644 packages/plugin-outline-pane/src/icons/setting.tsx delete mode 100644 packages/plugin-outline-pane/src/index.ts create mode 100644 packages/plugin-outline-pane/src/index.tsx delete mode 100644 packages/plugin-outline-pane/src/tree.ts delete mode 100644 packages/plugin-outline-pane/src/views/backup-pane.tsx create mode 100644 packages/shell/src/api/canvas.ts rename packages/shell/src/{ => api}/common.tsx (78%) rename packages/shell/src/{ => api}/event.ts (51%) create mode 100644 packages/shell/src/api/hotkey.ts create mode 100644 packages/shell/src/api/index.ts create mode 100644 packages/shell/src/api/logger.ts rename packages/shell/src/{ => api}/material.ts (70%) create mode 100644 packages/shell/src/api/plugins.ts rename packages/shell/src/{ => api}/project.ts (73%) create mode 100644 packages/shell/src/api/setters.ts rename packages/shell/src/{ => api}/simulator-host.ts (89%) rename packages/shell/src/{ => api}/skeleton.ts (60%) create mode 100644 packages/shell/src/api/workspace.ts delete mode 100644 packages/shell/src/canvas.ts delete mode 100644 packages/shell/src/dragon.ts delete mode 100644 packages/shell/src/hotkey.ts rename packages/shell/src/{ => model}/component-meta.ts (75%) rename packages/shell/src/{ => model}/detecting.ts (60%) rename packages/shell/src/{ => model}/document-model.ts (78%) rename packages/shell/src/{ => model}/drag-object.ts (61%) create mode 100644 packages/shell/src/model/dragon.ts rename packages/shell/src/{ => model}/drop-location.ts (79%) rename packages/shell/src/{ => model}/history.ts (92%) create mode 100644 packages/shell/src/model/index.ts rename packages/shell/src/{ => model}/locate-event.ts (87%) rename packages/shell/src/{ => model}/modal-nodes-manager.ts (84%) rename packages/shell/src/{ => model}/node-children.ts (65%) rename packages/shell/src/{ => model}/node.ts (76%) rename packages/shell/src/{ => model}/prop.ts (74%) rename packages/shell/src/{ => model}/props.ts (81%) rename packages/shell/src/{ => model}/selection.ts (77%) rename packages/shell/src/{ => model}/setting-prop-entry.ts (88%) rename packages/shell/src/{ => model}/setting-top-entry.ts (86%) create mode 100644 packages/shell/src/model/window.ts delete mode 100644 packages/shell/src/setters.ts delete mode 100644 packages/types/src/disposable.ts delete mode 100644 packages/types/src/field-config.ts delete mode 100644 packages/types/src/i18n.ts delete mode 100644 packages/types/src/icon.ts delete mode 100644 packages/types/src/metadata.ts delete mode 100644 packages/types/src/npm.ts delete mode 100644 packages/types/src/prop-config.ts delete mode 100644 packages/types/src/props-transducer.ts create mode 100644 packages/types/src/shell/api/canvas.ts create mode 100644 packages/types/src/shell/api/logger.ts create mode 100644 packages/types/src/shell/api/plugins.ts create mode 100644 packages/types/src/shell/api/workspace.ts create mode 100644 packages/types/src/shell/enum/drag-object-type.ts create mode 100644 packages/types/src/shell/enum/event-names.ts create mode 100644 packages/types/src/shell/enum/index.ts create mode 100644 packages/types/src/shell/enum/prop-value-changed-type.ts create mode 100644 packages/types/src/shell/enum/transform-stage.ts create mode 100644 packages/types/src/shell/enum/transition-type.ts create mode 100644 packages/types/src/shell/model/active-tracker.ts delete mode 100644 packages/types/src/shell/model/canvas.ts create mode 100644 packages/types/src/shell/model/editor.ts create mode 100644 packages/types/src/shell/model/engine-config.ts create mode 100644 packages/types/src/shell/model/exclusive-group.ts create mode 100644 packages/types/src/shell/model/plugin-context.ts create mode 100644 packages/types/src/shell/model/scroll-target.ts create mode 100644 packages/types/src/shell/model/scrollable.ts create mode 100644 packages/types/src/shell/model/scroller.ts rename packages/types/src/{ => shell/model}/setting-target.ts (72%) create mode 100644 packages/types/src/shell/model/window.ts create mode 100644 packages/types/src/shell/type/action-content-object.ts create mode 100644 packages/types/src/shell/type/active-target.ts create mode 100644 packages/types/src/shell/type/advanced.ts rename packages/types/src/{ => shell/type}/app-config.ts (57%) create mode 100644 packages/types/src/shell/type/assets-json.ts create mode 100644 packages/types/src/shell/type/block-schema.ts create mode 100644 packages/types/src/shell/type/component-action.ts create mode 100644 packages/types/src/shell/type/component-description.ts create mode 100644 packages/types/src/shell/type/component-instance.ts create mode 100644 packages/types/src/shell/type/component-metadata.ts create mode 100644 packages/types/src/shell/type/component-schema.ts create mode 100644 packages/types/src/shell/type/component-sort.ts create mode 100644 packages/types/src/shell/type/composite-value.ts create mode 100644 packages/types/src/shell/type/configure.ts create mode 100644 packages/types/src/shell/type/container-schema.ts create mode 100644 packages/types/src/shell/type/custom-view.ts create mode 100644 packages/types/src/shell/type/disposable.ts create mode 100644 packages/types/src/shell/type/dom-text.ts create mode 100644 packages/types/src/shell/type/drag-any-object.ts create mode 100644 packages/types/src/shell/type/drag-node-data-object.ts create mode 100644 packages/types/src/shell/type/drag-node-object.ts create mode 100644 packages/types/src/shell/type/drag-object.ts create mode 100644 packages/types/src/shell/type/dynamic-props.ts create mode 100644 packages/types/src/shell/type/dynamic-setter.ts create mode 100644 packages/types/src/shell/type/field-config.ts create mode 100644 packages/types/src/shell/type/field-extra-props.ts create mode 100644 packages/types/src/shell/type/hotkey-callback.ts create mode 100644 packages/types/src/shell/type/i18n-map.ts create mode 100644 packages/types/src/shell/type/i8n-data.ts create mode 100644 packages/types/src/shell/type/icon-config.ts create mode 100644 packages/types/src/shell/type/icon-type.ts create mode 100644 packages/types/src/shell/type/index.ts create mode 100644 packages/types/src/shell/type/location.ts create mode 100644 packages/types/src/shell/type/metadata-transducer.ts create mode 100644 packages/types/src/shell/type/metadata.ts create mode 100644 packages/types/src/shell/type/node-data.ts create mode 100644 packages/types/src/shell/type/node-schema.ts create mode 100644 packages/types/src/shell/type/npm-info.ts create mode 100644 packages/types/src/shell/type/npm.ts create mode 100644 packages/types/src/shell/type/package.ts create mode 100644 packages/types/src/shell/type/page-schema.ts create mode 100644 packages/types/src/shell/type/plugin-config.ts create mode 100644 packages/types/src/shell/type/plugin-creater.ts create mode 100644 packages/types/src/shell/type/plugin-declaration-property.ts create mode 100644 packages/types/src/shell/type/plugin-declaration.ts create mode 100644 packages/types/src/shell/type/plugin-meta.ts create mode 100644 packages/types/src/shell/type/plugin.ts create mode 100644 packages/types/src/shell/type/preference-value-type.ts create mode 100644 packages/types/src/shell/type/project-schema.ts create mode 100644 packages/types/src/shell/type/prop-change-options.ts create mode 100644 packages/types/src/shell/type/prop-config.ts create mode 100644 packages/types/src/shell/type/prop-types.ts create mode 100644 packages/types/src/shell/type/props-list.ts create mode 100644 packages/types/src/shell/type/props-map.ts create mode 100644 packages/types/src/shell/type/props-transducer.ts create mode 100644 packages/types/src/shell/type/reference.ts create mode 100644 packages/types/src/shell/type/registered-setter.ts create mode 100644 packages/types/src/shell/type/remote-component-description.ts create mode 100644 packages/types/src/shell/type/root-schema.ts create mode 100644 packages/types/src/shell/type/set-value-options.ts rename packages/types/src/{ => shell/type}/setter-config.ts (50%) create mode 100644 packages/types/src/shell/type/setter-type.ts create mode 100644 packages/types/src/shell/type/snippet.ts create mode 100644 packages/types/src/shell/type/tip-config.ts create mode 100644 packages/types/src/shell/type/tip-content.ts create mode 100644 packages/types/src/shell/type/title-config.ts create mode 100644 packages/types/src/shell/type/title-content.ts create mode 100644 packages/types/src/shell/type/transformed-component-metadata.ts rename packages/types/src/{ => shell/type}/value-type.ts (57%) create mode 100644 packages/types/src/shell/type/widget-base-config.ts create mode 100644 packages/types/src/shell/type/widget-config-area.ts delete mode 100644 packages/types/src/start-transaction.ts delete mode 100644 packages/types/src/tip.ts delete mode 100644 packages/types/src/title.ts delete mode 100644 packages/types/src/transform-stage.ts create mode 100644 packages/utils/src/check-types/is-drag-any-object.ts create mode 100644 packages/utils/src/check-types/is-drag-node-data-object.ts create mode 100644 packages/utils/src/check-types/is-drag-node-object.ts create mode 100644 packages/utils/src/check-types/is-location-children-detail.ts create mode 100644 packages/utils/src/check-types/is-location-data.ts create mode 100644 packages/utils/src/check-types/is-node.ts create mode 100644 packages/utils/src/check-types/is-setting-field.ts create mode 100644 packages/utils/src/is-plugin-event-name.ts create mode 100644 packages/utils/src/is-public-event-name.ts create mode 100644 packages/utils/src/is-shaken.ts create mode 100644 packages/workspace/build.json create mode 100644 packages/workspace/build.test.json create mode 100644 packages/workspace/jest.config.js create mode 100644 packages/workspace/package.json create mode 100644 packages/workspace/src/base-context.ts create mode 100644 packages/workspace/src/editor-view/context.ts create mode 100644 packages/workspace/src/editor-view/view.tsx create mode 100644 packages/workspace/src/editor-window/context.ts create mode 100644 packages/workspace/src/editor-window/view.tsx create mode 100644 packages/workspace/src/index.ts create mode 100644 packages/workspace/src/layouts/bottom-area.tsx create mode 100644 packages/workspace/src/layouts/left-area.tsx create mode 100644 packages/workspace/src/layouts/left-fixed-pane.tsx create mode 100644 packages/workspace/src/layouts/left-float-pane.tsx create mode 100644 packages/workspace/src/layouts/main-area.tsx create mode 100644 packages/workspace/src/layouts/theme.less create mode 100644 packages/workspace/src/layouts/top-area.tsx create mode 100644 packages/workspace/src/layouts/workbench.less create mode 100644 packages/workspace/src/layouts/workbench.tsx create mode 100644 packages/workspace/src/less-variables.less create mode 100644 packages/workspace/src/resource.ts create mode 100644 packages/workspace/src/shell-model-factory.ts create mode 100644 packages/workspace/src/skeleton-context.ts create mode 100644 packages/workspace/tsconfig.json diff --git a/docs/docs/api/common.md b/docs/docs/api/common.md index c16d22043..39ee609e8 100644 --- a/docs/docs/api/common.md +++ b/docs/docs/api/common.md @@ -32,14 +32,14 @@ sidebar_position: 11 *引擎版本 >= 1.0.16 ```typescript import { common } from '@alilc/lowcode-engine'; -import { TransitionType } from '@alilc/lowcode-types'; +import { IPublicEnumTransitionType } from '@alilc/lowcode-types'; common.utils.startTransaction(() => { node1.setProps(); node2.setProps(); node3.setProps(); // ... -}, TransitionType.repaint); +}, IPublicEnumTransitionType.repaint); ``` ### createIntl diff --git a/docs/docs/api/hotkey.md b/docs/docs/api/hotkey.md index 60e8a3f3f..cd0cf2944 100644 --- a/docs/docs/api/hotkey.md +++ b/docs/docs/api/hotkey.md @@ -53,7 +53,7 @@ function saveSchema(schema) { // 保存 schema 相关操作 } -const saveSampleHotKey = (ctx: ILowCodePluginContext) => { +const saveSampleHotKey = (ctx: IPublicModelPluginContext) => { return { name: 'saveSample', async init() { diff --git a/docs/docs/api/logger.md b/docs/docs/api/logger.md index d523622d8..211065410 100644 --- a/docs/docs/api/logger.md +++ b/docs/docs/api/logger.md @@ -3,7 +3,7 @@ title: logger - 日志 API sidebar_position: 9 --- ## 模块简介 -引擎日志模块,可以按照 **日志级别 **和** 业务类型 **两个维度来定制日志,基于 [zen-logger](https://web.npm.alibaba-inc.com/package/zen-logger) 封装。 +引擎日志模块,可以按照 **日志级别 **和** 业务类型 **两个维度来定制日志,参考 [zen-logger](https://web.npm.alibaba-inc.com/package/zen-logger) 实现进行封装。 > 注:日志级别可以通过 url query 动态调整,详见下方使用示例。 ## 变量(variables) @@ -22,8 +22,8 @@ function debug(args: any[]): void ``` **调用示例** ```typescript -import { logger } from '@alilc/lowcode-engine'; - +import { Logger } from '@alilc/lowcode-utils'; +const logger = new Logger({ level: 'warn', bizName: 'designer:pluginManager' }); logger.log('Awesome Low-Code Engine'); ``` ## 事件(events) @@ -31,9 +31,9 @@ logger.log('Awesome Low-Code Engine'); ## 使用示例 ```typescript -import { logger } from '@alilc/lowcode-engine'; +import { Logger } from '@alilc/lowcode-utils'; -// 内部实现:logger = getLogger({ level: 'warn', bizName: 'designer:pluginManager' }) +const logger = new Logger({ level: 'warn', bizName: 'designer:pluginManager' }); // 若在 url query 中增加 `__logConf__` 可改变打印日志级别和限定业务类型日志 // 默认:__logConf__=warn:* diff --git a/docs/docs/api/material.md b/docs/docs/api/material.md index 4cf1948cf..f1df43e6c 100644 --- a/docs/docs/api/material.md +++ b/docs/docs/api/material.md @@ -30,10 +30,11 @@ material.setAssets(assets); 通过物料中心接口动态引入资产包 ```typescript -import { ILowCodePluginContext, material, plugins } from '@alilc/lowcode-engine' +import { material, plugins } from '@alilc/lowcode-engine'; +import { IPublicModelPluginContext } from '@alilc/lowcode-types'; // 动态加载 assets -plugins.register((ctx: ILowCodePluginContext) => { +plugins.register((ctx: IPublicModelPluginContext) => { return { name: 'ext-assets', async init() { @@ -88,9 +89,9 @@ material.loadIncrementalAssets(assets2); 在设计器辅助层增加一个扩展 action **类型定义** ```typescript -function addBuiltinComponentAction(action: ComponentAction): void; +function addBuiltinComponentAction(action: IPublicTypeComponentAction): void; -export interface ComponentAction { +export interface IPublicTypeComponentAction { /** * behaviorName */ @@ -102,7 +103,7 @@ export interface ComponentAction { /** * 子集 */ - items?: ComponentAction[]; + items?: IPublicTypeComponentAction[]; /** * 显示与否 * always: 无法禁用 @@ -174,7 +175,7 @@ material.removeBuiltinComponentAction('myIconName'); ```typescript function modifyBuiltinComponentAction( actionName: string, - handle: (action: ComponentAction) => void + handle: (action: IPublicTypeComponentAction) => void ): void; ``` **内置设计器辅助 name** @@ -293,7 +294,7 @@ material.registerMetadataTransducer(addonCombine, 1, 'parse-func'); 获取所有物料元数据管道函数 **类型定义** ```typescript -function getRegisteredMetadataTransducers(): MetadataTransducer[]; +function getRegisteredMetadataTransducers(): IPublicTypeMetadataTransducer[]; ``` **示例** diff --git a/docs/docs/api/plugins.md b/docs/docs/api/plugins.md index f225386fc..bf683b365 100644 --- a/docs/docs/api/plugins.md +++ b/docs/docs/api/plugins.md @@ -13,11 +13,11 @@ sidebar_position: 4 #### 类型定义 ```typescript async function register( - pluginConfigCreator: (ctx: ILowCodePluginContext) => ILowCodePluginConfig, + pluginConfigCreator: (ctx: IPublicModelPluginContext) => IPublicTypePluginConfig, options?: ILowCodeRegisterOptions, ): Promise ``` -pluginConfigCreator 是一个 ILowCodePluginConfig 生成函数,ILowCodePluginConfig 中包含了该插件的 init / destroy 等钩子函数,以及 exports 函数用于返回插件对外暴露的值。 +pluginConfigCreator 是一个 IPublicTypePluginConfig 生成函数,IPublicTypePluginConfig 中包含了该插件的 init / destroy 等钩子函数,以及 exports 函数用于返回插件对外暴露的值。 另外,pluginConfigCreator 还必须挂载 pluginName 字段,全局确保唯一,否则 register 时会报错,可以选择性挂载 meta 字段,用于描述插件的元数据信息,比如兼容的引擎版本、支持的参数配置、依赖插件声明等。 > 注:pluginConfigCreator 挂载 pluginName / meta 可以通过低代码工具链的插件脚手架生成,写如 package.json 后将会自动注入到代码中,具体见 [插件元数据工程化示例](#RO9YY) @@ -26,8 +26,9 @@ pluginConfigCreator 是一个 ILowCodePluginConfig 生成函数,ILowCodePlugin #### 简单示例 ```typescript import { plugins } from '@alilc/lowcode-engine'; +import { IPublicModelPluginContext } from '@alilc/lowcode-types'; -const builtinPluginRegistry = (ctx: ILowCodePluginContext) => { +const builtinPluginRegistry = (ctx: IPublicModelPluginContext) => { return { async init() { const { skeleton } = ctx; @@ -58,8 +59,9 @@ await plugins.register(builtinPluginRegistry); #### 使用 exports 示例 ```typescript import { plugins } from '@alilc/lowcode-engine'; +import { IPublicModelPluginContext } from '@alilc/lowcode-types'; -const pluginA = (ctx: ILowCodePluginContext) => { +const pluginA = (ctx: IPublicModelPluginContext) => { return { async init() {}, exports() { return { x: 1, } }, @@ -67,7 +69,7 @@ const pluginA = (ctx: ILowCodePluginContext) => { } pluginA.pluginName = 'pluginA'; -const pluginB = (ctx: ILowCodePluginContext) => { +const pluginB = (ctx: IPublicModelPluginContext) => { return { async init() { // 获取 pluginA 的导出值 @@ -83,14 +85,15 @@ pluginB.meta = { await plugins.register(pluginA); await plugins.register(pluginB); ``` -> 注:ctx 是在插件 creator 中获取引擎 API 的上下文,具体定义参见 [ILowCodePluginContext](#qEhTb) +> 注:ctx 是在插件 creator 中获取引擎 API 的上下文,具体定义参见 [IPublicModelPluginContext](#qEhTb) #### #### 设置兼容引擎版本示例 ```typescript import { plugins } from '@alilc/lowcode-engine'; +import { IPublicModelPluginContext } from '@alilc/lowcode-types'; -const builtinPluginRegistry = (ctx: ILowCodePluginContext) => { +const builtinPluginRegistry = (ctx: IPublicModelPluginContext) => { return { async init() { ... @@ -108,8 +111,9 @@ await plugins.register(builtinPluginRegistry); #### 设置插件参数版本示例 ```typescript import { plugins } from '@alilc/lowcode-engine'; +import { IPublicModelPluginContext } from '@alilc/lowcode-types'; -const builtinPluginRegistry = (ctx: ILowCodePluginContext, options: any) => { +const builtinPluginRegistry = (ctx: IPublicModelPluginContext, options: any) => { return { async init() { // 1.0.4 之后的传值方式,通过 register(xxx, options) @@ -219,27 +223,27 @@ plugins.delete('builtinPluginRegistry'); ## 事件(events) 无 ## 相关模块 -### ILowCodePluginContext +### IPublicModelPluginContext **类型定义** ```typescript -export interface ILowCodePluginContext { - skeleton: Skeleton; // 参考面板 API - hotkey: Hotkey; // 参考快捷键 API - setters: Setters; // 参考设置器 API - config: EngineConfig; // 参考配置 API - material: Material; // 参考物料 API - event: Event; // 参考事件 API - project: Project; // 参考模型 API - common: Common; // 参考模型 API - logger: Logger; // 参考日志 API - plugins: ILowCodePluginManager; // 即本文档描述内容 +export interface IPublicModelPluginContext { + get skeleton(): IPublicApiSkeleton; + get hotkey(): IPublicApiHotkey; + get setters(): IPublicApiSetters; + get config(): IEngineConfig; + get material(): IPublicApiMaterial; + get event(): IPublicApiEvent; + get project(): IPublicApiProject; + get common(): IPublicApiCommon; + logger: IPublicApiLogger; + plugins: IPublicApiPlugins; preference: IPluginPreferenceMananger; } ``` -### ILowCodePluginConfig +### IPublicTypePluginConfig **类型定义** ```typescript -export interface ILowCodePluginConfig { +export interface IPublicTypePluginConfig { init?(): void; destroy?(): void; exports?(): any; @@ -263,7 +267,7 @@ your-plugin/package.json ``` 转换后的结构: ```json -const debug = (ctx: ILowCodePluginContext, options: any) => { +const debug = (ctx: IPublicModelPluginContext, options: any) => { return {}; } diff --git a/docs/docs/api/project.md b/docs/docs/api/project.md index 7c5896852..64400cf2a 100644 --- a/docs/docs/api/project.md +++ b/docs/docs/api/project.md @@ -79,10 +79,10 @@ addPropsTransducer(transducer: PropsTransducer, stage: TransformStage) **示例 1:在保存的时候删除每一个组件的 props.hidden** ```typescript -import { ILowCodePluginContext, project } from '@alilc/lowcode-engine'; -import { CompositeObject, TransformStage } from '@alilc/lowcode-types'; +import { project } from '@alilc/lowcode-engine'; +import { CompositeObject, TransformStage, IPublicModelPluginContext } from '@alilc/lowcode-types'; -export const deleteHiddenTransducer = (ctx: ILowCodePluginContext) => { +export const deleteHiddenTransducer = (ctx: IPublicModelPluginContext) => { return { name: 'deleteHiddenTransducer', async init() { diff --git a/docs/docs/api/setters.md b/docs/docs/api/setters.md index 41c992e16..b36d7162d 100644 --- a/docs/docs/api/setters.md +++ b/docs/docs/api/setters.md @@ -38,8 +38,9 @@ function registerSetter( ```typescript import { setters, skeleton } from '@alilc/lowcode-engine'; import { setterMap, pluginMap } from '@alilc/lowcode-engine-ext'; +import { IPublicModelPluginContext } from '@alilc/lowcode-types'; -const setterRegistry = (ctx: ILowCodePluginContext) => { +const setterRegistry = (ctx: IPublicModelPluginContext) => { return { name: 'ext-setters-registry', async init() { @@ -209,8 +210,9 @@ function registerSetter( ```typescript import { setters, skeleton } from '@alilc/lowcode-engine'; import { setterMap, pluginMap } from '@alilc/lowcode-engine-ext'; +import { IPublicModelPluginContext } from '@alilc/lowcode-types'; -const setterRegistry = (ctx: ILowCodePluginContext) => { +const setterRegistry = (ctx: IPublicModelPluginContext) => { return { name: 'ext-setters-registry', async init() { diff --git a/docs/docs/guide/expand/editor/cli.md b/docs/docs/guide/expand/editor/cli.md index 0218e6f73..74b9fa821 100644 --- a/docs/docs/guide/expand/editor/cli.md +++ b/docs/docs/guide/expand/editor/cli.md @@ -130,12 +130,13 @@ npm publish 2. 在引擎初始化侧引入插件 ```typescript import Inject, { injectAssets } from '@alilc/lowcode-plugin-inject'; + import { IPublicModelPluginContext } from '@alilc/lowcode-types'; export default async () => { // 注意 Inject 插件必须在其他插件前注册,且所有插件的注册必须 await await plugins.register(Inject); await plugins.register(OtherPlugin); - await plugins.register((ctx: ILowCodePluginContext) => { + await plugins.register((ctx: IPublicModelPluginContext) => { return { name: "editor-init", async init() { diff --git a/docs/docs/guide/expand/editor/material.md b/docs/docs/guide/expand/editor/material.md index a5e374db9..6e4979553 100644 --- a/docs/docs/guide/expand/editor/material.md +++ b/docs/docs/guide/expand/editor/material.md @@ -270,10 +270,11 @@ npm publish ### 在项目中引入资产包 ```typescript -import { ILowCodePluginContext, material, plugins } from '@alilc/lowcode-engine'; +import { material, plugins } from '@alilc/lowcode-engine'; +import { IPublicModelPluginContext } from '@alilc/lowcode-types'; // 动态加载 assets -plugins.register((ctx: ILowCodePluginContext) => { +plugins.register((ctx: IPublicModelPluginContext) => { return { name: 'ext-assets', async init() { diff --git a/docs/docs/guide/expand/editor/pluginContextMenu.md b/docs/docs/guide/expand/editor/pluginContextMenu.md index 9dc75ce65..2f1ab737c 100644 --- a/docs/docs/guide/expand/editor/pluginContextMenu.md +++ b/docs/docs/guide/expand/editor/pluginContextMenu.md @@ -10,9 +10,10 @@ sidebar_position: 6 ```typescript import { plugins } from '@alilc/lowcode-engine'; +import { IPublicModelPluginContext } from '@alilc/lowcode-types'; import { Icon, Message } from '@alifd/next'; -const addHelloAction = (ctx: ILowCodePluginContext) => { +const addHelloAction = (ctx: IPublicModelPluginContext) => { return { async init() { const { addBuiltinComponentAction } = ctx.material; @@ -46,8 +47,9 @@ await plugins.register(addHelloAction); ```typescript import { plugins } from '@alilc/lowcode-engine'; +import { IPublicModelPluginContext } from '@alilc/lowcode-types'; -const removeCopyAction = (ctx: ILowCodePluginContext) => { +const removeCopyAction = (ctx: IPublicModelPluginContext) => { return { async init() { const { removeBuiltinComponentAction } = ctx.material; diff --git a/docs/docs/guide/expand/editor/pluginWidget.md b/docs/docs/guide/expand/editor/pluginWidget.md index f1494bf2a..c319bb2a3 100644 --- a/docs/docs/guide/expand/editor/pluginWidget.md +++ b/docs/docs/guide/expand/editor/pluginWidget.md @@ -17,9 +17,10 @@ sidebar_position: 5 ## 注册插件 API ```typescript -import { plugins, ILowCodePluginContext } from '@alilc/lowcode-engine'; +import { plugins } from '@alilc/lowcode-engine'; +import { IPublicModelPluginContext } from '@alilc/lowcode-types'; -const pluginA = (ctx: ILowCodePluginContext, options: any) => { +const pluginA = (ctx: IPublicModelPluginContext, options: any) => { return { init() { console.log(options.key); diff --git a/docs/docs/guide/expand/editor/summary.md b/docs/docs/guide/expand/editor/summary.md index 872205e21..814340f3d 100644 --- a/docs/docs/guide/expand/editor/summary.md +++ b/docs/docs/guide/expand/editor/summary.md @@ -34,10 +34,11 @@ material.setAssets(assets); 也可以通过异步加载物料中心上的物料。 ```typescript -import { ILowCodePluginContext, material, plugins } from '@alilc/lowcode-engine'; +import { material, plugins } from '@alilc/lowcode-engine'; +import { IPublicModelPluginContext } from '@alilc/lowcode-types'; // 动态加载 assets -plugins.register((ctx: ILowCodePluginContext) => { +plugins.register((ctx: IPublicModelPluginContext) => { return { name: 'ext-assets', async init() { @@ -57,7 +58,8 @@ plugins.register((ctx: ILowCodePluginContext) => { ### 配置插件 可以通过 npm 包的方式引入社区插件,配置如下所示: ```typescript -import { ILowCodePluginContext, plugins } from '@alilc/lowcode-engine'; +import { plugins } from '@alilc/lowcode-engine'; +import { IPublicModelPluginContext } from '@alilc/lowcode-types'; import PluginIssueTracker from '@alilc/lowcode-plugin-issue-tracker'; // 注册一个提 issue 组件到您的编辑器中,方位默认在左栏下侧 diff --git a/docs/docs/guide/quickStart/start.md b/docs/docs/guide/quickStart/start.md index 13f30159e..870360537 100644 --- a/docs/docs/guide/quickStart/start.md +++ b/docs/docs/guide/quickStart/start.md @@ -125,9 +125,9 @@ Demo 根据**不同的设计器所需要的物料不同**,分为了下面的 8 可以在 demo/sample-plugins 直接新增插件,这里我新增的插件目录是 plugin-demo。并且新增了 index.tsx 文件,将下面的代码粘贴到 index.tsx 中。 ```javascript import * as React from 'react'; -import { ILowCodePluginContext } from '@alilc/lowcode-engine'; +import { IPublicModelPluginContext } from '@alilc/lowcode-types'; -const LowcodePluginPluginDemo = (ctx: ILowCodePluginContext) => { +const LowcodePluginPluginDemo = (ctx: IPublicModelPluginContext) => { return { // 插件对外暴露的数据和方法 exports() { diff --git a/modules/code-generator/babelTransform.js b/modules/code-generator/babelTransform.js new file mode 100644 index 000000000..6f5af94ff --- /dev/null +++ b/modules/code-generator/babelTransform.js @@ -0,0 +1,22 @@ +const babelJest = require('babel-jest'); +const getBabelConfig = require('build-scripts-config/lib/config/babel/index.js'); +const formatWinPath = require('build-scripts-config/lib/config/jest/formatWinPath'); +const babelConfig = getBabelConfig(); + +babelConfig.plugins.push(['@babel/plugin-proposal-class-properties', { loose: true }]); + +const jestBabelConfig = { + ...babelConfig, + presets: babelConfig.presets.map((preset) => { + if (Array.isArray(preset) && formatWinPath(preset[0]).indexOf('@babel/preset-env') > -1) { + return [preset[0], { + targets: { + node: 'current', + }, + }]; + } + return preset; + }), +}; + +module.exports = babelJest.createTransformer(jestBabelConfig); \ No newline at end of file diff --git a/modules/code-generator/jest.config.js b/modules/code-generator/jest.config.js index 0f908143d..5c0fbe40a 100644 --- a/modules/code-generator/jest.config.js +++ b/modules/code-generator/jest.config.js @@ -1,4 +1,8 @@ module.exports = { + transform: { + '^.+\\.(js|jsx|ts|tsx)$': './babelTransform.js', + '^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': 'build-scripts-config/lib/config/jest/fileTransform.js', + }, preset: 'ts-jest', testEnvironment: 'node', transformIgnorePatterns: ['/node_modules/(?!core-js)/'], diff --git a/modules/code-generator/package.json b/modules/code-generator/package.json index 25269e88b..19c270f2a 100644 --- a/modules/code-generator/package.json +++ b/modules/code-generator/package.json @@ -98,6 +98,7 @@ "qs": "^6.10.1", "semver": "^7.3.4", "short-uuid": "^3.1.1", + "babel-jest": "^26.5.2", "tslib": "^2.3.1" }, "browser": { @@ -125,11 +126,11 @@ "eslint-plugin-import": "^2.22.1", "eslint-plugin-react": "^7.22.0", "eslint-plugin-react-hooks": "^4.2.0", - "jest": "^27.4.7", + "jest": "^26.5.2", "jest-util": "^27.4.2", "rimraf": "^3.0.2", "standard-version": "^9.1.1", - "ts-jest": "^27.1.3", + "ts-jest": "^26.5.2", "ts-loader": "^6.2.2", "ts-node": "^8.10.2", "tsconfig-paths": "^3.9.0", diff --git a/modules/code-generator/src/analyzer/componentAnalyzer.ts b/modules/code-generator/src/analyzer/componentAnalyzer.ts index 952295a15..69e8ad482 100644 --- a/modules/code-generator/src/analyzer/componentAnalyzer.ts +++ b/modules/code-generator/src/analyzer/componentAnalyzer.ts @@ -1,13 +1,13 @@ -import type { NodeSchema, CompositeObject } from '@alilc/lowcode-types'; +import type { IPublicTypeNodeSchema, IPublicTypeCompositeObject } from '@alilc/lowcode-types'; import type { TComponentAnalyzer } from '../types'; import { handleSubNodes } from '../utils/schema'; export const componentAnalyzer: TComponentAnalyzer = (container) => { let hasRefAttr = false; - const nodeValidator = (n: NodeSchema) => { + const nodeValidator = (n: IPublicTypeNodeSchema) => { if (n.props) { - const props = n.props as CompositeObject; + const props = n.props as IPublicTypeCompositeObject; if (props.ref) { hasRefAttr = true; } diff --git a/modules/code-generator/src/cli/run.ts b/modules/code-generator/src/cli/run.ts index 7dcfd9d5a..ec6814f76 100644 --- a/modules/code-generator/src/cli/run.ts +++ b/modules/code-generator/src/cli/run.ts @@ -9,7 +9,7 @@ import * as path from 'path'; import { getErrorMessage } from '../utils/errors'; import CodeGenerator from '..'; import type { IProjectBuilder } from '..'; -import type { ProjectSchema } from '@alilc/lowcode-types'; +import type { IPublicTypeProjectSchema } from '@alilc/lowcode-types'; /** * 执行出码 CLI 命令 @@ -131,7 +131,7 @@ function isLocalSolution(solution: string) { return solution.startsWith('.') || solution.startsWith('/') || solution.startsWith('~'); } -async function loadSchemaFile(schemaFile: string): Promise { +async function loadSchemaFile(schemaFile: string): Promise { if (!schemaFile) { throw new Error('invalid schema file name'); } diff --git a/modules/code-generator/src/generator/ModuleBuilder.ts b/modules/code-generator/src/generator/ModuleBuilder.ts index f4554ef61..755ca20c6 100644 --- a/modules/code-generator/src/generator/ModuleBuilder.ts +++ b/modules/code-generator/src/generator/ModuleBuilder.ts @@ -1,4 +1,4 @@ -import { ProjectSchema, ResultFile, ResultDir } from '@alilc/lowcode-types'; +import { IPublicTypeProjectSchema, ResultFile, ResultDir } from '@alilc/lowcode-types'; import { BuilderComponentPlugin, @@ -77,7 +77,7 @@ export function createModuleBuilder( }; }; - const generateModuleCode = async (schema: ProjectSchema | string): Promise => { + const generateModuleCode = async (schema: IPublicTypeProjectSchema | string): Promise => { // Init const schemaParser: ISchemaParser = new SchemaParser(); const parseResult: IParseResult = schemaParser.parse(schema); diff --git a/modules/code-generator/src/generator/ProjectBuilder.ts b/modules/code-generator/src/generator/ProjectBuilder.ts index 0d0c5fe84..8f5405882 100644 --- a/modules/code-generator/src/generator/ProjectBuilder.ts +++ b/modules/code-generator/src/generator/ProjectBuilder.ts @@ -1,4 +1,4 @@ -import { ResultDir, ResultFile, ProjectSchema } from '@alilc/lowcode-types'; +import { ResultDir, ResultFile, IPublicTypeProjectSchema } from '@alilc/lowcode-types'; import { IModuleBuilder, @@ -87,13 +87,13 @@ export class ProjectBuilder implements IProjectBuilder { this.extraContextData = extraContextData; } - async generateProject(originalSchema: ProjectSchema | string): Promise { + async generateProject(originalSchema: IPublicTypeProjectSchema | string): Promise { // Init const { schemaParser } = this; const projectRoot = await this.template.generateTemplate(); - let schema: ProjectSchema = + let schema: IPublicTypeProjectSchema = typeof originalSchema === 'string' ? JSON.parse(originalSchema) : originalSchema; // Parse / Format diff --git a/modules/code-generator/src/parser/SchemaParser.ts b/modules/code-generator/src/parser/SchemaParser.ts index ad055250d..8c563ba16 100644 --- a/modules/code-generator/src/parser/SchemaParser.ts +++ b/modules/code-generator/src/parser/SchemaParser.ts @@ -4,14 +4,14 @@ */ import changeCase from 'change-case'; import { - UtilItem, + IPublicTypeUtilItem, NodeDataType, - NodeSchema, - ContainerSchema, - ProjectSchema, - PropsMap, - NodeData, - NpmInfo, + IPublicTypeNodeSchema, + IPublicTypeContainerSchema, + IPublicTypeProjectSchema, + IPublicTypePropsMap, + IPublicTypeNodeData, + IPublicTypeNpmInfo, } from '@alilc/lowcode-types'; import { IPageMeta, @@ -72,18 +72,18 @@ function getRootComponentName(typeName: string, maps: Record = {}; const internalDeps: Record = {}; @@ -140,7 +140,7 @@ export class SchemaParser implements ISchemaParser { let containers: IContainerInfo[]; // Test if this is a lowcode component without container if (schema.componentsTree.length > 0) { - const firstRoot: ContainerSchema = schema.componentsTree[0] as ContainerSchema; + const firstRoot: IPublicTypeContainerSchema = schema.componentsTree[0] as IPublicTypeContainerSchema; if (!firstRoot.fileName && !isValidContainerType(firstRoot)) { // 整个 schema 描述一个容器,且无根节点定义 @@ -150,13 +150,13 @@ export class SchemaParser implements ISchemaParser { props: firstRoot.props || defaultContainer.props, css: firstRoot.css || defaultContainer.css, moduleName: (firstRoot as IContainerInfo).moduleName || defaultContainer.moduleName, - children: schema.componentsTree as NodeSchema[], + children: schema.componentsTree as IPublicTypeNodeSchema[], }; containers = [container]; } else { // 普通带 1 到多个容器的 schema containers = schema.componentsTree.map((n) => { - const subRoot = n as ContainerSchema; + const subRoot = n as IPublicTypeContainerSchema; const container: IContainerInfo = { ...subRoot, componentName: getRootComponentName(subRoot.componentName, compDeps), @@ -173,7 +173,7 @@ export class SchemaParser implements ISchemaParser { // 分析引用能力的依赖 containers = containers.map((con) => ({ ...con, - analyzeResult: componentAnalyzer(con as ContainerSchema), + analyzeResult: componentAnalyzer(con as IPublicTypeContainerSchema), })); // 建立所有容器的内部依赖索引 @@ -211,7 +211,7 @@ export class SchemaParser implements ISchemaParser { handleSubNodes( container.children, { - node: (i: NodeSchema) => processChildren(i), + node: (i: IPublicTypeNodeSchema) => processChildren(i), }, { rerun: true, @@ -255,12 +255,12 @@ export class SchemaParser implements ISchemaParser { .filter((dep) => !!dep); // 分析 Utils 依赖 - let utils: UtilItem[]; + let utils: IPublicTypeUtilItem[]; if (schema.utils) { utils = schema.utils; utilsDeps = schema.utils .filter( - (u): u is { name: string; type: 'npm' | 'tnpm'; content: NpmInfo } => u.type !== 'function', + (u): u is { name: string; type: 'npm' | 'tnpm'; content: IPublicTypeNpmInfo } => u.type !== 'function', ) .map( (u): IExternalDependency => ({ @@ -335,7 +335,7 @@ export class SchemaParser implements ISchemaParser { return handleSubNodes( children, { - node: (i: NodeSchema) => i.componentName, + node: (i: IPublicTypeNodeSchema) => i.componentName, }, { rerun: true, @@ -343,8 +343,8 @@ export class SchemaParser implements ISchemaParser { ); } - decodeSchema(schemaSrc: string | ProjectSchema): ProjectSchema { - let schema: ProjectSchema; + decodeSchema(schemaSrc: string | IPublicTypeProjectSchema): IPublicTypeProjectSchema { + let schema: IPublicTypeProjectSchema; if (typeof schemaSrc === 'string') { try { schema = JSON.parse(schemaSrc); @@ -359,7 +359,7 @@ export class SchemaParser implements ISchemaParser { return schema; } - private collectDataSourcesTypes(schema: ProjectSchema): string[] { + private collectDataSourcesTypes(schema: IPublicTypeProjectSchema): string[] { const dataSourcesTypes = new Set(); // 数据源的默认类型为 fetch diff --git a/modules/code-generator/src/plugins/component/rax/containerInjectDataSourceEngine.ts b/modules/code-generator/src/plugins/component/rax/containerInjectDataSourceEngine.ts index 446b1d3f8..cb7a9e8c3 100644 --- a/modules/code-generator/src/plugins/component/rax/containerInjectDataSourceEngine.ts +++ b/modules/code-generator/src/plugins/component/rax/containerInjectDataSourceEngine.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/indent */ import { - CompositeValue, - JSExpression, + IPublicTypeCompositeValue, + IPublicTypeJSExpression, InterpretDataSourceConfig, isJSExpression, isJSFunction, @@ -56,7 +56,7 @@ const pluginFactory: BuilderComponentPluginFactory = (config?) => (dataSourceConfig && dataSourceConfig.list) || []; const dataSourceEngineOptions = { runtimeConfig: true }; if (dataSourceItems.length > 0) { - const requestHandlersMap: Record = {}; + const requestHandlersMap: Record = {}; dataSourceItems.forEach((ds) => { const dsType = ds.type || 'fetch'; @@ -178,7 +178,7 @@ _defineDataSourceConfig() { export default pluginFactory; -function wrapAsFunction(value: CompositeValue, scope: IScope): CompositeValue { +function wrapAsFunction(value: IPublicTypeCompositeValue, scope: IScope): IPublicTypeCompositeValue { if (isJSExpression(value) || isJSFunction(value)) { return { type: 'JSExpression', diff --git a/modules/code-generator/src/plugins/component/rax/jsx.ts b/modules/code-generator/src/plugins/component/rax/jsx.ts index e0c6dd01f..98c80a492 100644 --- a/modules/code-generator/src/plugins/component/rax/jsx.ts +++ b/modules/code-generator/src/plugins/component/rax/jsx.ts @@ -1,8 +1,8 @@ import { - NodeSchema, - JSExpression, - NpmInfo, - CompositeValue, + IPublicTypeNodeSchema, + IPublicTypeJSExpression, + IPublicTypeNpmInfo, + IPublicTypeCompositeValue, isJSExpression, } from '@alilc/lowcode-types'; @@ -86,7 +86,7 @@ const pluginFactory: BuilderComponentPluginFactory = (config?) => // 2. 小程序出码的时候,很容易出现 Uncaught TypeError: Cannot read property 'avatar' of undefined 这样的异常(如下图的 50 行) -- 因为若直接出码,Rax 构建到小程序的时候会立即计算所有在视图中用到的变量 // 3. 通过 this.xxx 能拿到的东西太多了,而且自定义的 methods 可能会无意间破坏 Rax 框架或小程序框架在页面 this 上的东东 const customHandlers: HandlerSet = { - expression(input: JSExpression, scope: IScope) { + expression(input: IPublicTypeJSExpression, scope: IScope) { return transformJsExpr(generateExpression(input, scope), scope, { dontWrapEval: !tolerateEvalErrors, }); @@ -171,7 +171,7 @@ const pluginFactory: BuilderComponentPluginFactory = (config?) => return next; function generateRaxLoopCtrl( - nodeItem: NodeSchema, + nodeItem: IPublicTypeNodeSchema, scope: IScope, config?: NodeGeneratorConfig, next?: NodePlugin, @@ -218,7 +218,7 @@ function isImportAliasDefineChunk(chunk: ICodeChunk): chunk is ICodeChunk & { ext: { aliasName: string; originalName: string; - dependency: NpmInfo; + dependency: IPublicTypeNpmInfo; }; } { return ( @@ -226,13 +226,13 @@ function isImportAliasDefineChunk(chunk: ICodeChunk): chunk is ICodeChunk & { !!chunk.ext && typeof chunk.ext.aliasName === 'string' && typeof chunk.ext.originalName === 'string' && - !!(chunk.ext.dependency as NpmInfo | null)?.componentName + !!(chunk.ext.dependency as IPublicTypeNpmInfo | null)?.componentName ); } function generateNodeAttrForRax( this: { cfg: PluginConfig }, - attrData: { attrName: string; attrValue: CompositeValue }, + attrData: { attrName: string; attrValue: IPublicTypeCompositeValue }, scope: IScope, config?: NodeGeneratorConfig, next?: AttrPlugin, @@ -257,7 +257,7 @@ function generateNodeAttrForRax( function generateEventHandlerAttrForRax( attrName: string, - attrValue: CompositeValue, + attrValue: IPublicTypeCompositeValue, scope: IScope, config?: NodeGeneratorConfig, ): CodePiece[] { diff --git a/modules/code-generator/src/plugins/component/react/containerInjectDataSourceEngine.ts b/modules/code-generator/src/plugins/component/react/containerInjectDataSourceEngine.ts index 2141c6309..bc5fa54ba 100644 --- a/modules/code-generator/src/plugins/component/react/containerInjectDataSourceEngine.ts +++ b/modules/code-generator/src/plugins/component/react/containerInjectDataSourceEngine.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/indent */ import { - CompositeValue, - JSExpression, + IPublicTypeCompositeValue, + IPublicTypeJSExpression, InterpretDataSourceConfig, isJSExpression, isJSFunction, @@ -72,7 +72,7 @@ const pluginFactory: BuilderComponentPluginFactory = (config?) => (dataSourceConfig && dataSourceConfig.list) || []; const dataSourceEngineOptions = { runtimeConfig: true }; if (dataSourceItems.length > 0) { - const requestHandlersMap: Record = {}; + const requestHandlersMap: Record = {}; dataSourceItems.forEach((ds) => { const dsType = ds.type || 'fetch'; @@ -187,7 +187,7 @@ const pluginFactory: BuilderComponentPluginFactory = (config?) => export default pluginFactory; -function wrapAsFunction(value: CompositeValue, scope: IScope): CompositeValue { +function wrapAsFunction(value: IPublicTypeCompositeValue, scope: IScope): IPublicTypeCompositeValue { if (isJSExpression(value) || isJSFunction(value)) { return { type: 'JSExpression', diff --git a/modules/code-generator/src/plugins/component/react/jsx.ts b/modules/code-generator/src/plugins/component/react/jsx.ts index 445dce7a5..7cf5bd9de 100644 --- a/modules/code-generator/src/plugins/component/react/jsx.ts +++ b/modules/code-generator/src/plugins/component/react/jsx.ts @@ -16,7 +16,7 @@ import { COMMON_CHUNK_NAME } from '../../../const/generator'; import { createReactNodeGenerator } from '../../../utils/nodeToJSX'; import { Scope } from '../../../utils/Scope'; -import { JSExpression } from '@alilc/lowcode-types'; +import { IPublicTypeJSExpression } from '@alilc/lowcode-types'; import { generateExpression } from '../../../utils/jsExpression'; import { transformJsExpr } from '../../../core/jsx/handlers/transformJsExpression'; import { transformThis2Context } from '../../../core/jsx/handlers/transformThis2Context'; @@ -47,7 +47,7 @@ const pluginFactory: BuilderComponentPluginFactory = (config?) => // 这里会将内部的一些子上下文的访问(this.xxx)转换为 __$$context.xxx 的形式 // 与 Rax 所不同的是,这里不会将最顶层的 this 转换掉 const customHandlers: HandlerSet = { - expression(input: JSExpression, scope: IScope, config) { + expression(input: IPublicTypeJSExpression, scope: IScope, config) { return transformJsExpr(generateExpression(input, scope), scope, { dontWrapEval: !(config?.tolerateEvalErrors ?? tolerateEvalErrors), dontTransformThis2ContextAtRootScope: true, @@ -120,7 +120,7 @@ const pluginFactory: BuilderComponentPluginFactory = (config?) => function __$$eval(expr) { try { return expr(); - } catch (error) { + } catch (error) { ${evalErrorsHandler} } } diff --git a/modules/code-generator/src/plugins/project/framework/rax/plugins/packageJSON.ts b/modules/code-generator/src/plugins/project/framework/rax/plugins/packageJSON.ts index e95a3dc0b..401ba3f97 100644 --- a/modules/code-generator/src/plugins/project/framework/rax/plugins/packageJSON.ts +++ b/modules/code-generator/src/plugins/project/framework/rax/plugins/packageJSON.ts @@ -1,4 +1,4 @@ -import { NpmInfo, PackageJSON } from '@alilc/lowcode-types'; +import { IPublicTypeNpmInfo, PackageJSON } from '@alilc/lowcode-types'; import { COMMON_CHUNK_NAME } from '../../../../../const/generator'; import { @@ -84,9 +84,9 @@ const pluginFactory: BuilderComponentPluginFactory = (cfg) export default pluginFactory; -function getNpmDependencies(project: IProjectInfo): NpmInfo[] { - const npmDeps: NpmInfo[] = []; - const npmNameToPkgMap = new Map(); +function getNpmDependencies(project: IProjectInfo): IPublicTypeNpmInfo[] { + const npmDeps: IPublicTypeNpmInfo[] = []; + const npmNameToPkgMap = new Map(); const allDeps = project.packages; diff --git a/modules/code-generator/src/standalone-loader.ts b/modules/code-generator/src/standalone-loader.ts index 882b1de9d..0c8903ddc 100644 --- a/modules/code-generator/src/standalone-loader.ts +++ b/modules/code-generator/src/standalone-loader.ts @@ -1,5 +1,5 @@ import fetch from 'node-fetch'; -import type { ProjectSchema, ResultDir } from '@alilc/lowcode-types'; +import type { IPublicTypeProjectSchema, ResultDir } from '@alilc/lowcode-types'; import type { FlattenFile } from './types/file'; declare const Worker: any; @@ -26,7 +26,7 @@ export type Result = ResultDir | FlattenFile[]; export async function generateCode(options: { solution: 'icejs' | 'rax'; - schema: ProjectSchema; + schema: IPublicTypeProjectSchema; flattenResult?: boolean; workerJsUrl?: string; timeoutInMs?: number; diff --git a/modules/code-generator/src/standalone-worker.ts b/modules/code-generator/src/standalone-worker.ts index 71f56e67a..e00a4877b 100644 --- a/modules/code-generator/src/standalone-worker.ts +++ b/modules/code-generator/src/standalone-worker.ts @@ -1,5 +1,5 @@ /* eslint-disable no-console */ -import type { ProjectSchema } from '@alilc/lowcode-types'; +import type { IPublicTypeProjectSchema } from '@alilc/lowcode-types'; import CodeGen from './standalone'; declare const self: any; @@ -13,7 +13,7 @@ self.onmessage = (event: any) => { self.postMessage({ type: 'ready' }); -async function run(msg: { solution: string; schema: ProjectSchema; flattenResult?: boolean }) { +async function run(msg: { solution: string; schema: IPublicTypeProjectSchema; flattenResult?: boolean }) { try { print('begin run...'); self.postMessage({ type: 'run:begin' }); diff --git a/modules/code-generator/src/types/analyze.ts b/modules/code-generator/src/types/analyze.ts index 43de30743..3bf444d29 100644 --- a/modules/code-generator/src/types/analyze.ts +++ b/modules/code-generator/src/types/analyze.ts @@ -1,7 +1,7 @@ -import type { ContainerSchema } from '@alilc/lowcode-types'; +import type { IPublicTypeContainerSchema } from '@alilc/lowcode-types'; export interface ICompAnalyzeResult { isUsingRef: boolean; } -export type TComponentAnalyzer = (container: ContainerSchema) => ICompAnalyzeResult; +export type TComponentAnalyzer = (container: IPublicTypeContainerSchema) => ICompAnalyzeResult; diff --git a/modules/code-generator/src/types/core.ts b/modules/code-generator/src/types/core.ts index f79db6cd9..b2c110823 100644 --- a/modules/code-generator/src/types/core.ts +++ b/modules/code-generator/src/types/core.ts @@ -1,15 +1,15 @@ import { - JSONArray, - JSONObject, - CompositeArray, - CompositeObject, + IPublicTypeJSONArray, + IPublicTypeJSONObject, + IPublicTypeCompositeArray, + IPublicTypeCompositeObject, ResultDir, ResultFile, NodeDataType, - ProjectSchema, - JSExpression, - JSFunction, - JSSlot, + IPublicTypeProjectSchema, + IPublicTypeJSExpression, + IPublicTypeJSFunction, + IPublicTypeJSSlot, } from '@alilc/lowcode-types'; import { IParseResult } from './intermediate'; @@ -96,7 +96,7 @@ export interface ICompiledModule { export interface IModuleBuilder { generateModule: (input: unknown) => Promise; - generateModuleCode: (schema: ProjectSchema | string) => Promise; + generateModuleCode: (schema: IPublicTypeProjectSchema | string) => Promise; linkCodeChunks: (chunks: Record, fileName: string) => ResultFile[]; addPlugin: (plugin: BuilderComponentPlugin) => void; } @@ -111,16 +111,16 @@ export interface ICodeGenerator { /** * 出码接口,把 Schema 转换成代码文件系统描述 * - * @param {(ProjectSchema)} schema 传入的 Schema + * @param {(IPublicTypeProjectSchema)} schema 传入的 Schema * @returns {ResultDir} * @memberof ICodeGenerator */ - toCode: (schema: ProjectSchema) => Promise; + toCode: (schema: IPublicTypeProjectSchema) => Promise; } export interface ISchemaParser { - validate: (schema: ProjectSchema) => boolean; - parse: (schema: ProjectSchema | string) => IParseResult; + validate: (schema: IPublicTypeProjectSchema) => boolean; + parse: (schema: IPublicTypeProjectSchema | string) => IParseResult; } export interface IProjectTemplate { @@ -165,11 +165,11 @@ export interface IProjectBuilderOptions { } export interface IProjectBuilder { - generateProject: (schema: ProjectSchema | string) => Promise; + generateProject: (schema: IPublicTypeProjectSchema | string) => Promise; } /** 项目级别的前置处理器 */ -export type ProjectPreProcessor = (schema: ProjectSchema) => Promise | ProjectSchema; +export type ProjectPreProcessor = (schema: IPublicTypeProjectSchema) => Promise | IPublicTypeProjectSchema; export interface ProjectPostProcessorOptions { parseResult?: IParseResult; @@ -179,8 +179,8 @@ export interface ProjectPostProcessorOptions { /** 项目级别的后置处理器 */ export type ProjectPostProcessor = ( result: ResultDir, - schema: ProjectSchema, - originalSchema: ProjectSchema | string, + schema: IPublicTypeProjectSchema, + originalSchema: IPublicTypeProjectSchema | string, options: ProjectPostProcessorOptions, ) => Promise | ResultDir; @@ -209,16 +209,16 @@ export type NodeGenerator = (nodeItem: NodeDataType, scope: IScope) => T; // FIXME: 在新的实现中,添加了第一参数 this: CustomHandlerSet 作为上下文。究其本质 // scopeBindings?: IScopeBindings; -// 这个组合只用来用来处理 CompositeValue 类型,不是这个类型的不要放在这里 +// 这个组合只用来用来处理 IPublicTypeCompositeValue 类型,不是这个类型的不要放在这里 export interface HandlerSet { string?: CompositeTypeGenerator; boolean?: CompositeTypeGenerator; number?: CompositeTypeGenerator; - expression?: CompositeTypeGenerator; - function?: CompositeTypeGenerator; - slot?: CompositeTypeGenerator; - array?: CompositeTypeGenerator; - object?: CompositeTypeGenerator; + expression?: CompositeTypeGenerator; + function?: CompositeTypeGenerator; + slot?: CompositeTypeGenerator; + array?: CompositeTypeGenerator; + object?: CompositeTypeGenerator; } export interface CompositeValueGeneratorOptions { diff --git a/modules/code-generator/src/types/intermediate.ts b/modules/code-generator/src/types/intermediate.ts index 30ef1e84b..30d6c4f7f 100644 --- a/modules/code-generator/src/types/intermediate.ts +++ b/modules/code-generator/src/types/intermediate.ts @@ -1,4 +1,9 @@ -import { I18nMap, UtilsMap, ContainerSchema, JSONObject } from '@alilc/lowcode-types'; +import { + IPublicTypeI18nMap, + IPublicTypeUtilsMap, + IPublicTypeContainerSchema, + IPublicTypeJSONObject, +} from '@alilc/lowcode-types'; import { IDependency, INpmPackage } from './deps'; import { ICompAnalyzeResult } from './analyze'; @@ -6,7 +11,7 @@ import { ICompAnalyzeResult } from './analyze'; export interface IParseResult { containers: IContainerInfo[]; globalUtils?: IUtilInfo; - globalI18n?: I18nMap; + globalI18n?: IPublicTypeI18nMap; globalRouter?: IRouterInfo; project?: IProjectInfo; } @@ -15,14 +20,14 @@ export interface IWithDependency { deps?: IDependency[]; } -export interface IContainerInfo extends ContainerSchema, IWithDependency { +export interface IContainerInfo extends IPublicTypeContainerSchema, IWithDependency { containerType: string; moduleName: string; analyzeResult?: ICompAnalyzeResult; } export interface IUtilInfo extends IWithDependency { - utils: UtilsMap; + utils: IPublicTypeUtilsMap; } export interface IRouterInfo extends IWithDependency { @@ -45,8 +50,8 @@ export interface IProjectInfo { css?: string; containersDeps?: IDependency[]; utilsDeps?: IDependency[]; - constants?: JSONObject; - i18n?: I18nMap; + constants?: IPublicTypeJSONObject; + i18n?: IPublicTypeI18nMap; packages: INpmPackage[]; meta?: { name?: string; title?: string } | Record; config?: Record; diff --git a/modules/code-generator/src/types/jsx.ts b/modules/code-generator/src/types/jsx.ts index c79f1d207..28f948d63 100644 --- a/modules/code-generator/src/types/jsx.ts +++ b/modules/code-generator/src/types/jsx.ts @@ -1,4 +1,4 @@ -import { NodeSchema, CompositeValue } from '@alilc/lowcode-types'; +import { IPublicTypeNodeSchema, IPublicTypeCompositeValue } from '@alilc/lowcode-types'; import { HandlerSet, BaseGenerator, NodeGenerator } from './core'; export enum PIECE_TYPE { @@ -17,11 +17,11 @@ export interface CodePiece { export interface AttrData { attrName: string; - attrValue: CompositeValue; + attrValue: IPublicTypeCompositeValue; } -// 对 JSX 出码的理解,目前定制点包含 【包装】【标签名】【属性】 +// 对 JSX 出码的理解,目前定制点包含【包装】【标签名】【属性】 export type AttrPlugin = BaseGenerator; -export type NodePlugin = BaseGenerator; +export type NodePlugin = BaseGenerator; export interface NodeGeneratorConfig { handlers?: HandlerSet; @@ -33,7 +33,7 @@ export interface NodeGeneratorConfig { /** * 是否要容忍对 JSExpression 求值时的异常 * 默认:true - * 注: 如果容忍异常,则会在求值时包裹 try-catch 块 -- 通过 __$$eval / __$$evalArray + * 注:如果容忍异常,则会在求值时包裹 try-catch 块 -- 通过 __$$eval / __$$evalArray * catch 到异常时默认会抛出一个 CustomEvent 事件里面包含异常信息和求值的表达式 */ tolerateEvalErrors?: boolean; diff --git a/modules/code-generator/src/utils/compositeType.ts b/modules/code-generator/src/utils/compositeType.ts index b66e1279c..2e09e2da0 100644 --- a/modules/code-generator/src/utils/compositeType.ts +++ b/modules/code-generator/src/utils/compositeType.ts @@ -1,13 +1,13 @@ import { - CompositeArray, - CompositeValue, - CompositeObject, - JSFunction, - JSExpression, + IPublicTypeCompositeArray, + IPublicTypeCompositeValue, + IPublicTypeCompositeObject, + IPublicTypeJSFunction, + IPublicTypeJSExpression, isJSExpression, isJSFunction, isJSSlot, - JSSlot, + IPublicTypeJSSlot, } from '@alilc/lowcode-types'; import _ from 'lodash'; @@ -43,7 +43,7 @@ function isDataSource(v: unknown): v is DataSource { } function generateArray( - value: CompositeArray, + value: IPublicTypeCompositeArray, scope: IScope, options: CompositeValueGeneratorOptions = {}, ): string { @@ -52,7 +52,7 @@ function generateArray( } function generateObject( - value: CompositeObject, + value: IPublicTypeCompositeObject, scope: IScope, options: CompositeValueGeneratorOptions = {}, ): string { @@ -88,7 +88,7 @@ function generateBool(value: boolean): string { return value ? 'true' : 'false'; } -function genFunction(value: JSFunction): string { +function genFunction(value: IPublicTypeJSFunction): string { const globalVars = parseExpressionGetKeywords(value.value); if (globalVars.includes('arguments')) { @@ -98,7 +98,7 @@ function genFunction(value: JSFunction): string { return generateFunction(value, { isArrow: true }); } -function genJsSlot(value: JSSlot, scope: IScope, options: CompositeValueGeneratorOptions = {}) { +function genJsSlot(value: IPublicTypeJSSlot, scope: IScope, options: CompositeValueGeneratorOptions = {}) { if (options.nodeGenerator) { return generateJsSlot(value, scope, options.nodeGenerator); } @@ -106,7 +106,7 @@ function genJsSlot(value: JSSlot, scope: IScope, options: CompositeValueGenerato } function generateUnknownType( - value: CompositeValue, + value: IPublicTypeCompositeValue, scope: IScope, options: CompositeValueGeneratorOptions = {}, ): string { @@ -128,7 +128,7 @@ function generateUnknownType( // FIXME: 这个是临时方案 // 在遇到 type variable 私有类型时,转换为 JSExpression if (isVariable(value)) { - const transValue: JSExpression = { + const transValue: IPublicTypeJSExpression = { type: 'JSExpression', value: value.variable, }; @@ -188,7 +188,7 @@ function generateUnknownType( if (options.handlers?.object) { return executeFunctionStack(value, scope, options.handlers.object, generateObject, options); } - return generateObject(value as CompositeObject, scope, options); + return generateObject(value as IPublicTypeCompositeObject, scope, options); } if (_.isString(value)) { @@ -218,7 +218,7 @@ function generateUnknownType( // 这一层曾经是对产出做最外层包装的,但其实包装逻辑不应该属于这一层 // 这一层先不去掉,做冗余,方便后续重构 export function generateCompositeType( - value: CompositeValue, + value: IPublicTypeCompositeValue, scope: IScope, options: CompositeValueGeneratorOptions = {}, ): string { diff --git a/modules/code-generator/src/utils/jsExpression.ts b/modules/code-generator/src/utils/jsExpression.ts index d6dc8c027..1162d0820 100644 --- a/modules/code-generator/src/utils/jsExpression.ts +++ b/modules/code-generator/src/utils/jsExpression.ts @@ -2,7 +2,7 @@ import * as parser from '@babel/parser'; import generate from '@babel/generator'; import traverse from '@babel/traverse'; import * as t from '@babel/types'; -import { JSExpression, JSFunction, isJSExpression, isJSFunction } from '@alilc/lowcode-types'; +import { IPublicTypeJSExpression, IPublicTypeJSFunction, isJSExpression, isJSFunction } from '@alilc/lowcode-types'; import { CodeGeneratorError, IScope } from '../types'; import { transformExpressionLocalRef, ParseError } from './expressionParser'; @@ -84,7 +84,7 @@ export function isJsCode(value: unknown): boolean { export function generateExpression(value: any, scope: IScope): string { if (isJSExpression(value)) { - const exprVal = (value as JSExpression).value.trim(); + const exprVal = (value as IPublicTypeJSExpression).value.trim(); if (!exprVal) { return 'null'; } @@ -113,7 +113,7 @@ export function generateFunction( }, ) { if (isJsCode(value)) { - const functionCfg = value as JSFunction; + const functionCfg = value as IPublicTypeJSFunction; if (config.isMember) { return transformFuncExpr2MethodMember(config.name || '', functionCfg.value); } diff --git a/modules/code-generator/src/utils/jsSlot.ts b/modules/code-generator/src/utils/jsSlot.ts index 49f7b3170..265f6857f 100644 --- a/modules/code-generator/src/utils/jsSlot.ts +++ b/modules/code-generator/src/utils/jsSlot.ts @@ -1,4 +1,4 @@ -import { JSSlot, isJSSlot, NodeData } from '@alilc/lowcode-types'; +import { IPublicTypeJSSlot, isJSSlot, IPublicTypeNodeData } from '@alilc/lowcode-types'; import { CodeGeneratorError, NodeGenerator, IScope } from '../types'; import { unwrapJsExprQuoteInJsx } from './jsxHelpers'; @@ -8,7 +8,7 @@ function generateSingleLineComment(commentText: string): string { export function generateJsSlot(slot: any, scope: IScope, generator: NodeGenerator): string { if (isJSSlot(slot)) { - const { title, params, value } = slot as JSSlot; + const { title, params, value } = slot as IPublicTypeJSSlot; // slot 也是分有参数和无参数的 // - 有参数的 slot 就是类似一个 render 函数,需要创建子作用域 @@ -39,7 +39,7 @@ export function generateJsSlot(slot: any, scope: IScope, generator: NodeGenerato } function generateNodeDataOrArrayForJsSlot( - value: NodeData | NodeData[], + value: IPublicTypeNodeData | IPublicTypeNodeData[], generator: NodeGenerator, scope: IScope, ) { diff --git a/modules/code-generator/src/utils/nodeToJSX.ts b/modules/code-generator/src/utils/nodeToJSX.ts index e928b866b..bb03523c0 100644 --- a/modules/code-generator/src/utils/nodeToJSX.ts +++ b/modules/code-generator/src/utils/nodeToJSX.ts @@ -1,6 +1,6 @@ import _ from 'lodash'; import { pipe } from 'fp-ts/function'; -import { NodeSchema, isNodeSchema, NodeDataType, CompositeValue } from '@alilc/lowcode-types'; +import { IPublicTypeNodeSchema, isNodeSchema, NodeDataType, IPublicTypeCompositeValue } from '@alilc/lowcode-types'; import { IScope, @@ -57,7 +57,7 @@ export function isPureString(v: string) { } function generateAttrValue( - attrData: { attrName: string; attrValue: CompositeValue }, + attrData: { attrName: string; attrValue: IPublicTypeCompositeValue }, scope: IScope, config?: NodeGeneratorConfig, ): CodePiece[] { @@ -76,7 +76,7 @@ function generateAttrValue( function generateAttr( attrName: string, - attrValue: CompositeValue, + attrValue: IPublicTypeCompositeValue, scope: IScope, config?: NodeGeneratorConfig, ): CodePiece[] { @@ -115,7 +115,7 @@ function generateAttr( } function generateAttrs( - nodeItem: NodeSchema, + nodeItem: IPublicTypeNodeSchema, scope: IScope, config?: NodeGeneratorConfig, ): CodePiece[] { @@ -144,7 +144,7 @@ function generateAttrs( } function generateBasicNode( - nodeItem: NodeSchema, + nodeItem: IPublicTypeNodeSchema, scope: IScope, config?: NodeGeneratorConfig, ): CodePiece[] { @@ -160,7 +160,7 @@ function generateBasicNode( } function generateSimpleNode( - nodeItem: NodeSchema, + nodeItem: IPublicTypeNodeSchema, scope: IScope, config?: NodeGeneratorConfig, ): CodePiece[] { @@ -216,13 +216,13 @@ function linkPieces(pieces: CodePiece[]): string { } function generateNodeSchema( - nodeItem: NodeSchema, + nodeItem: IPublicTypeNodeSchema, scope: IScope, config?: NodeGeneratorConfig, ): string { const pieces: CodePiece[] = []; if (config?.nodePlugins) { - const res = executeFunctionStack( + const res = executeFunctionStack( nodeItem, scope, config.nodePlugins, @@ -247,11 +247,11 @@ function generateNodeSchema( * @type NodePlugin Extended * * @export - * @param {NodeSchema} nodeItem 当前 UI 节点 + * @param {IPublicTypeNodeSchema} nodeItem 当前 UI 节点 * @returns {CodePiece[]} 实现功能的相关代码片段 */ export function generateReactLoopCtrl( - nodeItem: NodeSchema, + nodeItem: IPublicTypeNodeSchema, scope: IScope, config?: NodeGeneratorConfig, next?: NodePlugin, @@ -301,11 +301,11 @@ export function generateReactLoopCtrl( * @type NodePlugin * * @export - * @param {NodeSchema} nodeItem 当前 UI 节点 + * @param {IPublicTypeNodeSchema} nodeItem 当前 UI 节点 * @returns {CodePiece[]} 实现功能的相关代码片段 */ export function generateConditionReactCtrl( - nodeItem: NodeSchema, + nodeItem: IPublicTypeNodeSchema, scope: IScope, config?: NodeGeneratorConfig, next?: NodePlugin, @@ -336,11 +336,11 @@ export function generateConditionReactCtrl( * @type NodePlugin * * @export - * @param {NodeSchema} nodeItem 当前 UI 节点 + * @param {IPublicTypeNodeSchema} nodeItem 当前 UI 节点 * @returns {CodePiece[]} 实现功能的相关代码片段 */ export function generateReactExprInJS( - nodeItem: NodeSchema, + nodeItem: IPublicTypeNodeSchema, scope: IScope, config?: NodeGeneratorConfig, next?: NodePlugin, diff --git a/modules/code-generator/src/utils/schema.ts b/modules/code-generator/src/utils/schema.ts index 9a4f131d4..509977277 100644 --- a/modules/code-generator/src/utils/schema.ts +++ b/modules/code-generator/src/utils/schema.ts @@ -1,20 +1,20 @@ import * as _ from 'lodash'; import { - JSExpression, - NodeData, - NodeSchema, + IPublicTypeJSExpression, + IPublicTypeNodeData, + IPublicTypeNodeSchema, isJSExpression, isJSSlot, isDOMText, - ContainerSchema, - NpmInfo, - CompositeValue, + IPublicTypeContainerSchema, + IPublicTypeNpmInfo, + IPublicTypeCompositeValue, isNodeSchema, isJSFunction, } from '@alilc/lowcode-types'; import { CodeGeneratorError } from '../types/error'; -export function isContainerSchema(x: any): x is ContainerSchema { +export function isContainerSchema(x: any): x is IPublicTypeContainerSchema { return ( typeof x === 'object' && x && @@ -23,7 +23,7 @@ export function isContainerSchema(x: any): x is ContainerSchema { ); } -export function isNpmInfo(x: any): x is NpmInfo { +export function isNpmInfo(x: any): x is IPublicTypeNpmInfo { return typeof x === 'object' && x && typeof x.package === 'string'; } @@ -43,11 +43,11 @@ const DEFAULT_MAX_DEPTH = 100000; * @returns */ export function handleSubNodes( - children: NodeSchema['children'], + children: IPublicTypeNodeSchema['children'], handlers: { string?: (i: string) => T; - expression?: (i: JSExpression) => T; - node?: (i: NodeSchema) => T; + expression?: (i: IPublicTypeJSExpression) => T; + node?: (i: IPublicTypeNodeSchema) => T; }, options?: { rerun?: boolean; @@ -64,7 +64,7 @@ export function handleSubNodes( } if (Array.isArray(children)) { - const list: NodeData[] = children as NodeData[]; + const list: IPublicTypeNodeData[] = children as IPublicTypeNodeData[]; return list .map((child) => handleSubNodes(child, handlers, { ...opt, maxDepth: maxDepth - 1 })) .reduce((p, c) => p.concat(c), []); @@ -84,7 +84,7 @@ export function handleSubNodes( return handleSubNodes(children.value, handlers, { ...opt, maxDepth: maxDepth - 1 }); } else if (isNodeSchema(children)) { const handler = handlers.node || noop; - const child = children as NodeSchema; + const child = children as IPublicTypeNodeSchema; result = handler(child); if (child.children) { @@ -115,7 +115,7 @@ export function handleSubNodes( return childrenRes; - function handleCompositeValueInProps(value: CompositeValue): T[] { + function handleCompositeValueInProps(value: IPublicTypeCompositeValue): T[] { if (isJSSlot(value)) { return handleSubNodes(value.value, handlers, { ...opt, maxDepth: maxDepth - 1 }); } @@ -125,7 +125,7 @@ export function handleSubNodes( return _.flatMap(value, (v) => handleCompositeValueInProps(v)); } - // CompositeObject + // IPublicTypeCompositeObject if ( !isJSExpression(value) && !isJSFunction(value) && @@ -139,7 +139,7 @@ export function handleSubNodes( } } -export function isValidContainerType(schema: NodeSchema) { +export function isValidContainerType(schema: IPublicTypeNodeSchema) { return [ 'Page', 'Component', diff --git a/modules/code-generator/tests/bugfix/i18n-with-params.test.ts b/modules/code-generator/tests/bugfix/i18n-with-params.test.ts index d640525eb..b58afda8c 100644 --- a/modules/code-generator/tests/bugfix/i18n-with-params.test.ts +++ b/modules/code-generator/tests/bugfix/i18n-with-params.test.ts @@ -1,7 +1,7 @@ import CodeGenerator from '../../src'; import * as fs from 'fs'; import * as path from 'path'; -import { ProjectSchema } from '@alilc/lowcode-types'; +import { IPublicTypeProjectSchema } from '@alilc/lowcode-types'; import { createDiskPublisher } from '../helpers/solutionHelper'; const testCaseBaseName = path.basename(__filename, '.test.ts'); @@ -31,7 +31,7 @@ describe(testCaseBaseName, () => { function exportProject( importPath: string, outputPath: string, - mergeSchema?: Partial, + mergeSchema?: Partial, ) { const schemaJsonStr = fs.readFileSync(importPath, { encoding: 'utf8' }); const schema = { ...JSON.parse(schemaJsonStr), ...mergeSchema }; diff --git a/modules/code-generator/tests/bugfix/icejs-import-wrong-naming.test.ts b/modules/code-generator/tests/bugfix/icejs-import-wrong-naming.test.ts index 1f29fe612..efb7fd5be 100644 --- a/modules/code-generator/tests/bugfix/icejs-import-wrong-naming.test.ts +++ b/modules/code-generator/tests/bugfix/icejs-import-wrong-naming.test.ts @@ -1,7 +1,7 @@ import CodeGenerator from '../../src'; import * as fs from 'fs'; import * as path from 'path'; -import { ProjectSchema } from '@alilc/lowcode-types'; +import { IPublicTypeProjectSchema } from '@alilc/lowcode-types'; import { createDiskPublisher } from '../helpers/solutionHelper'; const testCaseBaseName = path.basename(__filename, '.test.ts'); @@ -198,7 +198,7 @@ describe(testCaseBaseName, () => { function exportProject( importPath: string, outputPath: string, - mergeSchema?: Partial, + mergeSchema?: Partial, ) { const schemaJsonStr = fs.readFileSync(importPath, { encoding: 'utf8' }); const schema = { ...JSON.parse(schemaJsonStr), ...mergeSchema }; diff --git a/modules/code-generator/tests/bugfix/strict-mode-context-1.test.ts b/modules/code-generator/tests/bugfix/strict-mode-context-1.test.ts index 9cfb09325..ebca6a26f 100644 --- a/modules/code-generator/tests/bugfix/strict-mode-context-1.test.ts +++ b/modules/code-generator/tests/bugfix/strict-mode-context-1.test.ts @@ -1,7 +1,7 @@ import CodeGenerator from '../../src'; import * as fs from 'fs'; import * as path from 'path'; -import { ProjectSchema } from '@alilc/lowcode-types'; +import { IPublicTypeProjectSchema } from '@alilc/lowcode-types'; import { createDiskPublisher } from '../helpers/solutionHelper'; import { IceJsProjectBuilderOptions } from '../../src/solutions/icejs'; @@ -33,7 +33,7 @@ describe(testCaseBaseName, () => { function exportProject( importPath: string, outputPath: string, - mergeSchema?: Partial, + mergeSchema?: Partial, options?: IceJsProjectBuilderOptions, ) { const schemaJsonStr = fs.readFileSync(importPath, { encoding: 'utf8' }); diff --git a/modules/code-generator/tests/bugfix/tolerate-eval-errors-1-loop.test.ts b/modules/code-generator/tests/bugfix/tolerate-eval-errors-1-loop.test.ts index 11ba9de05..78f2b50b3 100644 --- a/modules/code-generator/tests/bugfix/tolerate-eval-errors-1-loop.test.ts +++ b/modules/code-generator/tests/bugfix/tolerate-eval-errors-1-loop.test.ts @@ -1,7 +1,7 @@ import CodeGenerator from '../../src'; import * as fs from 'fs'; import * as path from 'path'; -import { ProjectSchema } from '@alilc/lowcode-types'; +import { IPublicTypeProjectSchema } from '@alilc/lowcode-types'; import { createDiskPublisher } from '../helpers/solutionHelper'; import { IceJsProjectBuilderOptions } from '../../src/solutions/icejs'; @@ -28,7 +28,7 @@ test('loop should be generated link __$$evalArray(xxx).map', async () => { function exportProject( importPath: string, outputPath: string, - mergeSchema?: Partial, + mergeSchema?: Partial, options?: IceJsProjectBuilderOptions, ) { const schemaJsonStr = fs.readFileSync(importPath, { encoding: 'utf8' }); diff --git a/modules/code-generator/tests/bugfix/tolerate-eval-errors-2-nested-loop.test.ts b/modules/code-generator/tests/bugfix/tolerate-eval-errors-2-nested-loop.test.ts index e8b65a544..184200593 100644 --- a/modules/code-generator/tests/bugfix/tolerate-eval-errors-2-nested-loop.test.ts +++ b/modules/code-generator/tests/bugfix/tolerate-eval-errors-2-nested-loop.test.ts @@ -1,7 +1,7 @@ import CodeGenerator from '../../src'; import * as fs from 'fs'; import * as path from 'path'; -import { ProjectSchema } from '@alilc/lowcode-types'; +import { IPublicTypeProjectSchema } from '@alilc/lowcode-types'; import { createDiskPublisher } from '../helpers/solutionHelper'; import { IceJsProjectBuilderOptions } from '../../src/solutions/icejs'; @@ -32,7 +32,7 @@ test('loop should be generated link __$$evalArray(xxx).map', async () => { function exportProject( importPath: string, outputPath: string, - mergeSchema?: Partial, + mergeSchema?: Partial, options?: IceJsProjectBuilderOptions, ) { const schemaJsonStr = fs.readFileSync(importPath, { encoding: 'utf8' }); diff --git a/modules/code-generator/tests/plugins/jsx/__snapshots__/p0-condition-at-root.test.ts.snap b/modules/code-generator/tests/plugins/jsx/__snapshots__/p0-condition-at-root.test.ts.snap index 6de472142..391e492f6 100644 --- a/modules/code-generator/tests/plugins/jsx/__snapshots__/p0-condition-at-root.test.ts.snap +++ b/modules/code-generator/tests/plugins/jsx/__snapshots__/p0-condition-at-root.test.ts.snap @@ -22,7 +22,7 @@ Object { function __$$eval(expr) { try { return expr(); - } catch (error) { + } catch (error) { } } @@ -97,7 +97,7 @@ Object { function __$$eval(expr) { try { return expr(); - } catch (error) { + } catch (error) { } } @@ -168,7 +168,7 @@ Object { function __$$eval(expr) { try { return expr(); - } catch (error) { + } catch (error) { } } @@ -236,7 +236,7 @@ Object { function __$$eval(expr) { try { return expr(); - } catch (error) { + } catch (error) { } } diff --git a/modules/code-generator/tests/public/SchemaParser/p0-basic.test.ts b/modules/code-generator/tests/public/SchemaParser/p0-basic.test.ts index 4743e7758..311b93c6b 100644 --- a/modules/code-generator/tests/public/SchemaParser/p0-basic.test.ts +++ b/modules/code-generator/tests/public/SchemaParser/p0-basic.test.ts @@ -1,11 +1,11 @@ -import { ProjectSchema } from '@alilc/lowcode-types'; +import { IPublicTypeProjectSchema } from '@alilc/lowcode-types'; import { SchemaParser } from '../../../src'; import SCHEMA_WITH_SLOT from './data/schema-with-slot.json'; describe('tests/public/SchemaParser/p0-basics', () => { it('should be able to get dependencies in slots', () => { const schemaParser = new SchemaParser(); - const result = schemaParser.parse(SCHEMA_WITH_SLOT as ProjectSchema); + const result = schemaParser.parse(SCHEMA_WITH_SLOT as IPublicTypeProjectSchema); expect(result.containers.map((c) => c.deps)).toMatchSnapshot(); expect(result.containers[0].deps?.some((dep) => dep.componentName === 'Tooltip')).toBeTruthy(); expect(result.containers[0].deps?.some((dep) => dep.componentName === 'Icon')).toBeTruthy(); diff --git a/modules/code-generator/tests/public/solutions/rax-app.test.ts b/modules/code-generator/tests/public/solutions/rax-app.test.ts index 6d96a8e89..320daf6da 100644 --- a/modules/code-generator/tests/public/solutions/rax-app.test.ts +++ b/modules/code-generator/tests/public/solutions/rax-app.test.ts @@ -13,7 +13,7 @@ import { import CodeGenerator from '../../../src'; -import type { ProjectSchema } from '@alilc/lowcode-types'; +import type { IPublicTypeProjectSchema } from '@alilc/lowcode-types'; jest.setTimeout(15 * 1000); @@ -50,7 +50,7 @@ function defineTest(caseDirName: string) { }); } -async function exportProject(schemaJson: ProjectSchema, targetPath: string, projectName: string) { +async function exportProject(schemaJson: IPublicTypeProjectSchema, targetPath: string, projectName: string) { const raxAppBuilder = CodeGenerator.solutions.rax(); const result = await raxAppBuilder.generateProject(schemaJson); diff --git a/modules/code-generator/tests/public/solutions/react-app.test.ts b/modules/code-generator/tests/public/solutions/react-app.test.ts index aff7105ed..f70f10af0 100644 --- a/modules/code-generator/tests/public/solutions/react-app.test.ts +++ b/modules/code-generator/tests/public/solutions/react-app.test.ts @@ -12,7 +12,7 @@ import { import CodeGenerator from '../../../src'; -import type { ProjectSchema } from '@alilc/lowcode-types'; +import type { IPublicTypeProjectSchema } from '@alilc/lowcode-types'; jest.setTimeout(15 * 1000); @@ -49,7 +49,7 @@ function defineTest(caseDirName: string) { }); } -async function exportProject(schemaJson: ProjectSchema, targetPath: string, projectName: string) { +async function exportProject(schemaJson: IPublicTypeProjectSchema, targetPath: string, projectName: string) { const reactAppBuilder = CodeGenerator.solutions.icejs(); const result = await reactAppBuilder.generateProject(schemaJson); diff --git a/modules/code-generator/tests/utils/schema/handleSubNodes.test.ts b/modules/code-generator/tests/utils/schema/handleSubNodes.test.ts index be88e3e30..d88ecdf54 100644 --- a/modules/code-generator/tests/utils/schema/handleSubNodes.test.ts +++ b/modules/code-generator/tests/utils/schema/handleSubNodes.test.ts @@ -1,10 +1,10 @@ -import { NodeData } from '@alilc/lowcode-types'; +import { IPublicTypeNodeData } from '@alilc/lowcode-types'; import { handleSubNodes } from '../../../src/utils/schema'; import SCHEMA_WITH_SLOT from './data/schema-with-slot.json'; describe('utils/schema/handleSubNodes', () => { it('should be able to visit nodes in JSSlot(1)', () => { - const nodes: NodeData[] = [ + const nodes: IPublicTypeNodeData[] = [ { componentName: 'Foo', props: { @@ -28,7 +28,7 @@ describe('utils/schema/handleSubNodes', () => { }); it('should be able to visit nodes in JSSlot(2)', () => { - const nodes: NodeData[] = (SCHEMA_WITH_SLOT as any).componentsTree[0].children; + const nodes: IPublicTypeNodeData[] = (SCHEMA_WITH_SLOT as any).componentsTree[0].children; const result = handleSubNodes(nodes, { node: (node) => node.componentName, diff --git a/modules/material-parser/test/fixtures/rax-component/package.json b/modules/material-parser/test/fixtures/rax-component/package.json index 30fd28d51..2498c777f 100644 --- a/modules/material-parser/test/fixtures/rax-component/package.json +++ b/modules/material-parser/test/fixtures/rax-component/package.json @@ -44,7 +44,6 @@ "@alife/build-plugin-lowcode": "^1.0.17", "@iceworks/spec": "^1.0.0", "@types/rax": "^1.0.0", - "build-plugin-component": "^1.0.0", "driver-universal": "^3.1.0", "eslint": "^6.8.0", "rax": "^1.1.0", diff --git a/modules/material-parser/test/fixtures/ts-component2/package.json b/modules/material-parser/test/fixtures/ts-component2/package.json index 95bb4bd8d..a4ebf783b 100644 --- a/modules/material-parser/test/fixtures/ts-component2/package.json +++ b/modules/material-parser/test/fixtures/ts-component2/package.json @@ -34,7 +34,6 @@ "@alife/build-plugin-lowcode": "^1.0.7", "@alib/build-scripts": "^0.1.3", "@alifd/adaptor-generate": "^0.1.3", - "build-plugin-component": "^0.2.0", "build-plugin-fusion": "^0.1.0", "build-plugin-fusion-cool": "^0.1.0", "build-plugin-moment-locales": "^0.1.0", diff --git a/package.json b/package.json index 572958d82..02585e563 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,10 @@ "typescript": "4.6.2", "yarn": "^1.22.17", "rimraf": "^3.0.2", - "@types/react-router": "5.1.18" + "@types/react-router": "5.1.18", + "build-plugin-component": "^1.12.0", + "babel-jest": "^26.5.2", + "@alilc/lowcode-test-mate": "^1.0.1" }, "engines": { "node": ">=14.17.0 <18" @@ -61,7 +64,6 @@ "lockfile": "enable" }, "resolutions": { - "@builder/babel-preset-ice": "1.0.1", "typescript": "4.6.2" }, "repository": "git@github.com:alibaba/lowcode-engine.git" diff --git a/packages/designer/babelTransform.js b/packages/designer/babelTransform.js new file mode 100644 index 000000000..6f5af94ff --- /dev/null +++ b/packages/designer/babelTransform.js @@ -0,0 +1,22 @@ +const babelJest = require('babel-jest'); +const getBabelConfig = require('build-scripts-config/lib/config/babel/index.js'); +const formatWinPath = require('build-scripts-config/lib/config/jest/formatWinPath'); +const babelConfig = getBabelConfig(); + +babelConfig.plugins.push(['@babel/plugin-proposal-class-properties', { loose: true }]); + +const jestBabelConfig = { + ...babelConfig, + presets: babelConfig.presets.map((preset) => { + if (Array.isArray(preset) && formatWinPath(preset[0]).indexOf('@babel/preset-env') > -1) { + return [preset[0], { + targets: { + node: 'current', + }, + }]; + } + return preset; + }), +}; + +module.exports = babelJest.createTransformer(jestBabelConfig); \ No newline at end of file diff --git a/packages/designer/jest.config.js b/packages/designer/jest.config.js index 6866d24a0..4d6d29173 100644 --- a/packages/designer/jest.config.js +++ b/packages/designer/jest.config.js @@ -1,9 +1,13 @@ const fs = require('fs'); const { join } = require('path'); -const esModules = ['zen-logger'].join('|'); +const esModules = [].join('|'); const pkgNames = fs.readdirSync(join('..')).filter(pkgName => !pkgName.startsWith('.')); const jestConfig = { + transform: { + '^.+\\.(js|jsx|ts|tsx)$': './babelTransform.js', + '^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': 'build-scripts-config/lib/config/jest/fileTransform.js', + }, // transform: { // '^.+\\.[jt]sx?$': 'babel-jest', // // '^.+\\.(ts|tsx)$': 'ts-jest', diff --git a/packages/designer/package.json b/packages/designer/package.json index 320704d38..e147ac312 100644 --- a/packages/designer/package.json +++ b/packages/designer/package.json @@ -22,13 +22,10 @@ "react": "^16", "react-dom": "^16.7.0", "ric-shim": "^1.0.1", - "semver": "^7.3.5", - "zen-logger": "^1.1.0" + "semver": "^7.3.5" }, "devDependencies": { "@alib/build-scripts": "^0.1.29", - "@alilc/lowcode-shell": "1.0.18", - "@alilc/lowcode-test-mate": "^1.0.1", "@testing-library/react": "^11.2.2", "@types/classnames": "^2.2.7", "@types/enzyme": "^3.10.12", @@ -40,9 +37,6 @@ "@types/react": "^16", "@types/react-dom": "^16", "@types/semver": "7.3.9", - "babel-jest": "^26.5.2", - "build-plugin-component": "^1.0.0", - "build-scripts-config": "^3.0.3", "enzyme": "^3.11.0", "enzyme-adapter-react-16": "^1.15.5", "jest": "^26.6.3", @@ -54,9 +48,6 @@ "access": "public", "registry": "https://registry.npmjs.org/" }, - "resolutions": { - "@builder/babel-preset-ice": "1.0.1" - }, "repository": { "type": "http", "url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/designer" diff --git a/packages/designer/src/builtin-simulator/bem-tools/border-container.tsx b/packages/designer/src/builtin-simulator/bem-tools/border-container.tsx index 05a164c98..212cb80bb 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/border-container.tsx +++ b/packages/designer/src/builtin-simulator/bem-tools/border-container.tsx @@ -2,14 +2,14 @@ import * as React from 'react'; import { Component, Fragment, ReactElement, PureComponent } from 'react'; import classNames from 'classnames'; import { computed, observer, Title, globalLocale } from '@alilc/lowcode-editor-core'; -import { I18nData, TitleContent } from '@alilc/lowcode-types'; +import { IPublicTypeI18nData, IPublicTypeTitleContent } from '@alilc/lowcode-types'; import { isI18nData } from '@alilc/lowcode-utils'; import { DropLocation } from '../../designer'; import { BuiltinSimulatorHost } from '../../builtin-simulator/host'; -import { ParentalNode } from '../../document/node'; +import { INode } from '../../document/node'; export class BorderContainerInstance extends PureComponent<{ - title: TitleContent; + title: IPublicTypeTitleContent; rect: DOMRect | null; scale: number; scrollX: number; @@ -37,7 +37,7 @@ export class BorderContainerInstance extends PureComponent<{ } } -function getTitle(title: string | I18nData | ReactElement) { +function getTitle(title: string | IPublicTypeI18nData | ReactElement) { if (typeof title === 'string') return title; if (isI18nData(title)) { const locale = globalLocale.getLocale() || 'zh-CN'; @@ -50,9 +50,8 @@ function getTitle(title: string | I18nData | ReactElement) { export class BorderContainer extends Component<{ host: BuiltinSimulatorHost; }, { - target?: ParentalNode; + target?: INode; }> { - state = {} as any; @computed get scale() { @@ -70,7 +69,7 @@ export class BorderContainer extends Component<{ componentDidMount() { const { host } = this.props; - host.designer.editor.on('designer.dropLocation.change', (loc: DropLocation) => { + host.designer.editor.eventBus.on('designer.dropLocation.change', (loc: DropLocation) => { let { target } = this.state; if (target === loc?.target) return; this.setState({ diff --git a/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx b/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx index c0920c450..ebde9ef2d 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx +++ b/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx @@ -1,14 +1,14 @@ import { Component, Fragment, PureComponent } from 'react'; import classNames from 'classnames'; import { computed, observer, Title } from '@alilc/lowcode-editor-core'; -import { TitleContent } from '@alilc/lowcode-types'; +import { IPublicTypeTitleContent } from '@alilc/lowcode-types'; import { getClosestNode } from '@alilc/lowcode-utils'; import { BuiltinSimulatorHost } from '../host'; export class BorderDetectingInstance extends PureComponent<{ - title: TitleContent; + title: IPublicTypeTitleContent; rect: DOMRect | null; scale: number; scrollX: number; diff --git a/packages/designer/src/builtin-simulator/bem-tools/border-resizing.tsx b/packages/designer/src/builtin-simulator/bem-tools/border-resizing.tsx index 08a44b25d..33dce7712 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/border-resizing.tsx +++ b/packages/designer/src/builtin-simulator/bem-tools/border-resizing.tsx @@ -1,6 +1,6 @@ import React, { Component, Fragment } from 'react'; import DragResizeEngine from './drag-resize-engine'; -import { observer, computed, globalContext, Editor } from '@alilc/lowcode-editor-core'; +import { observer, computed, globalContext } from '@alilc/lowcode-editor-core'; import classNames from 'classnames'; import { SimulatorContext } from '../context'; import { BuiltinSimulatorHost } from '../host'; @@ -172,13 +172,14 @@ export class BoxResizingInstance extends Component<{ metadata.configure.advanced.callbacks.onResizeEnd(e, cbNode); } - const editor = globalContext.get(Editor); + const workspace = globalContext.get('workspace'); + const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); const npm = node?.componentMeta?.npm; const selected = [npm?.package, npm?.componentName].filter((item) => !!item).join('-') || node?.componentMeta?.componentName || ''; - editor?.emit('designer.border.resize', { + editor?.eventBus.emit('designer.border.resize', { selected, layout: node?.parent?.getPropValue('layout') || '', }); diff --git a/packages/designer/src/builtin-simulator/bem-tools/border-selecting.tsx b/packages/designer/src/builtin-simulator/bem-tools/border-selecting.tsx index e5c8ad98a..0280d9055 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/border-selecting.tsx +++ b/packages/designer/src/builtin-simulator/bem-tools/border-selecting.tsx @@ -11,7 +11,7 @@ import { import classNames from 'classnames'; import { observer, computed, Tip, globalContext } from '@alilc/lowcode-editor-core'; import { createIcon, isReactComponent, isActionContentObject } from '@alilc/lowcode-utils'; -import { ActionContentObject } from '@alilc/lowcode-types'; +import { IPublicTypeActionContentObject } from '@alilc/lowcode-types'; import { BuiltinSimulatorHost } from '../host'; import { OffsetObserver } from '../../designer'; import { Node } from '../../document'; @@ -116,7 +116,7 @@ class Toolbar extends Component<{ observed: OffsetObserver }> { } } -function createAction(content: ReactNode | ComponentType | ActionContentObject, key: string, node: Node) { +function createAction(content: ReactNode | ComponentType | IPublicTypeActionContentObject, key: string, node: Node) { if (isValidElement(content)) { return cloneElement(content, { key, node }); } @@ -131,13 +131,14 @@ function createAction(content: ReactNode | ComponentType | ActionContentObj className="lc-borders-action" onClick={() => { action && action(node); - const editor = globalContext.get('editor'); + const workspace = globalContext.get('workspace'); + const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); const npm = node?.componentMeta?.npm; const selected = [npm?.package, npm?.componentName].filter((item) => !!item).join('-') || node?.componentMeta?.componentName || ''; - editor?.emit('designer.border.action', { + editor?.eventBus.emit('designer.border.action', { name: key, selected, }); diff --git a/packages/designer/src/builtin-simulator/bem-tools/drag-resize-engine.ts b/packages/designer/src/builtin-simulator/bem-tools/drag-resize-engine.ts index d65e9b8af..6689379dd 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/drag-resize-engine.ts +++ b/packages/designer/src/builtin-simulator/bem-tools/drag-resize-engine.ts @@ -1,12 +1,12 @@ -import { EventEmitter } from 'events'; import { ISimulatorHost } from '../../simulator'; import { Designer, Point } from '../../designer'; import { cursor } from '@alilc/lowcode-utils'; import { makeEventsHandler } from '../../utils/misc'; +import { createModuleEventBus, IEventBus } from '@alilc/lowcode-editor-core'; // 拖动缩放 export default class DragResizeEngine { - private emitter: EventEmitter; + private emitter: IEventBus; private dragResizing = false; @@ -14,7 +14,7 @@ export default class DragResizeEngine { constructor(designer: Designer) { this.designer = designer; - this.emitter = new EventEmitter(); + this.emitter = createModuleEventBus('DragResizeEngine'); } isDragResizing() { diff --git a/packages/designer/src/builtin-simulator/bem-tools/insertion.tsx b/packages/designer/src/builtin-simulator/bem-tools/insertion.tsx index d6f748deb..e9955004b 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/insertion.tsx +++ b/packages/designer/src/builtin-simulator/bem-tools/insertion.tsx @@ -3,29 +3,27 @@ import { observer } from '@alilc/lowcode-editor-core'; import { BuiltinSimulatorHost } from '../host'; import { DropLocation, - Rect, - isLocationChildrenDetail, - LocationChildrenDetail, isVertical, } from '../../designer'; import { ISimulatorHost } from '../../simulator'; -import { ParentalNode } from '../../document'; +import { INode } from '../../document'; import './insertion.less'; -import { NodeData, NodeSchema } from '@alilc/lowcode-types'; +import { IPublicTypeNodeData, IPublicTypeNodeSchema, IPublicTypeLocationChildrenDetail, IPublicTypeRect } from '@alilc/lowcode-types'; +import { isLocationChildrenDetail } from '@alilc/lowcode-utils'; interface InsertionData { edge?: DOMRect; insertType?: string; vertical?: boolean; - nearRect?: Rect; + nearRect?: IPublicTypeRect; coverRect?: DOMRect; - nearNode?: NodeData; + nearNode?: IPublicTypeNodeData; } /** * 处理拖拽子节点(INode)情况 */ -function processChildrenDetail(sim: ISimulatorHost, container: ParentalNode, detail: LocationChildrenDetail): InsertionData { +function processChildrenDetail(sim: ISimulatorHost, container: INode, detail: IPublicTypeLocationChildrenDetail): InsertionData { let edge = detail.edge || null; if (!edge) { @@ -161,7 +159,7 @@ export class InsertionView extends Component<{ host: BuiltinSimulatorHost }> { y = ((insertType === 'before' ? nearRect.top : nearRect.bottom) + scrollY) * scale; style.width = nearRect.width * scale; } - if (y === 0 && (nearNode as NodeSchema)?.componentMeta?.isTopFixed) { + if (y === 0 && (nearNode as IPublicTypeNodeSchema)?.componentMeta?.isTopFixed) { return null; } } diff --git a/packages/designer/src/builtin-simulator/create-simulator.ts b/packages/designer/src/builtin-simulator/create-simulator.ts index 007286e9c..e46582180 100644 --- a/packages/designer/src/builtin-simulator/create-simulator.ts +++ b/packages/designer/src/builtin-simulator/create-simulator.ts @@ -22,6 +22,7 @@ export function createSimulator( const doc = iframe.contentDocument!; win.LCSimulatorHost = host; + win._ = window._; const styles: any = {}; const scripts: any = {}; diff --git a/packages/designer/src/builtin-simulator/host-view.tsx b/packages/designer/src/builtin-simulator/host-view.tsx index ff40362d1..a7943ea9f 100644 --- a/packages/designer/src/builtin-simulator/host-view.tsx +++ b/packages/designer/src/builtin-simulator/host-view.tsx @@ -6,7 +6,7 @@ import { Project } from '../project'; import './host.less'; /* - Simulator 模拟器,可替换部件,有协议约束, 包含画布的容器,使用场景:当 Canvas 大小变化时,用来居中处理 或 定位 Canvas + Simulator 模拟器,可替换部件,有协议约束,包含画布的容器,使用场景:当 Canvas 大小变化时,用来居中处理 或 定位 Canvas Canvas(DeviceShell) 设备壳层,通过背景图片来模拟,通过设备预设样式改变宽度、高度及定位 CanvasViewport CanvasViewport 页面编排场景中宽高不可溢出 Canvas 区 Content(Shell) 内容外层,宽高紧贴 CanvasViewport,禁用边框,禁用 margin @@ -23,8 +23,8 @@ export class BuiltinSimulatorHostView extends Component { constructor(props: any) { super(props); - const { project, onMount } = this.props; - this.host = (project.simulator as BuiltinSimulatorHost) || new BuiltinSimulatorHost(project); + const { project, onMount, designer } = this.props; + this.host = (project.simulator as BuiltinSimulatorHost) || new BuiltinSimulatorHost(project, designer); this.host.setProps(this.props); onMount?.(this.host); } @@ -76,14 +76,15 @@ class Content extends Component<{ host: BuiltinSimulatorHost }> { private dispose?: () => void; componentDidMount() { - const editor = globalContext.get('editor'); + const workspace = globalContext.get('workspace'); + const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); const onEnableEvents = (type: boolean) => { this.setState({ disabledEvents: type, }); }; - editor.on('designer.builtinSimulator.disabledEvents', onEnableEvents); + editor.eventBus.on('designer.builtinSimulator.disabledEvents', onEnableEvents); this.dispose = () => { editor.removeListener('designer.builtinSimulator.disabledEvents', onEnableEvents); @@ -97,7 +98,7 @@ class Content extends Component<{ host: BuiltinSimulatorHost }> { render() { const sim = this.props.host; const { disabledEvents } = this.state; - const { viewport } = sim; + const { viewport, designer } = sim; const frameStyle: any = { transform: `scale(${viewport.scale})`, height: viewport.contentHeight, @@ -107,10 +108,12 @@ class Content extends Component<{ host: BuiltinSimulatorHost }> { frameStyle.pointerEvents = 'none'; } + const { viewName } = designer; + return (