@nocobase/flow-engine 2.0.0-alpha.4 → 2.0.0-alpha.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/BlockScopedFlowEngine.d.ts +23 -0
- package/lib/BlockScopedFlowEngine.js +90 -0
- package/lib/FlowContextProvider.d.ts +2 -2
- package/lib/FlowContextProvider.js +3 -3
- package/lib/FlowDefinition.d.ts +4 -2
- package/lib/JSRunner.js +3 -0
- package/lib/ViewScopedFlowEngine.d.ts +1 -1
- package/lib/ViewScopedFlowEngine.js +12 -0
- package/lib/acl/Acl.d.ts +1 -0
- package/lib/acl/Acl.js +11 -0
- package/lib/components/FieldModelRenderer.js +14 -6
- package/lib/components/FieldSkeleton.d.ts +10 -0
- package/lib/components/FieldSkeleton.js +64 -0
- package/lib/components/FlowContextSelector.js +7 -2
- package/lib/components/FlowModelRenderer.d.ts +3 -6
- package/lib/components/FlowModelRenderer.js +16 -47
- package/lib/components/FormItem.js +5 -1
- package/lib/components/MobilePopup.d.ts +20 -0
- package/lib/components/MobilePopup.js +102 -0
- package/lib/components/MobilePopup.style.d.ts +17 -0
- package/lib/components/MobilePopup.style.js +186 -0
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +3 -1
- package/lib/components/settings/independents/dropdown/FlowsDropdownButton.js +2 -2
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +17 -5
- package/lib/components/settings/wrappers/contextual/FlowsContextMenu.js +2 -2
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +2 -2
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +35 -6
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +7 -1
- package/lib/components/variables/VariableInput.js +19 -5
- package/lib/components/variables/VariableTag.js +43 -2
- package/lib/components/variables/types.d.ts +2 -0
- package/lib/data-source/index.d.ts +15 -4
- package/lib/data-source/index.js +42 -13
- package/lib/data-source/sortCollectionsByInherits.d.ts +10 -0
- package/lib/data-source/sortCollectionsByInherits.js +71 -0
- package/lib/emitter.d.ts +6 -0
- package/lib/emitter.js +12 -0
- package/lib/executor/FlowExecutor.d.ts +4 -5
- package/lib/executor/FlowExecutor.js +168 -99
- package/lib/flow-registry/GlobalFlowRegistry.d.ts +1 -0
- package/lib/flow-registry/GlobalFlowRegistry.js +3 -0
- package/lib/flow-registry/InstanceFlowRegistry.d.ts +1 -0
- package/lib/flow-registry/InstanceFlowRegistry.js +3 -0
- package/lib/flowContext.d.ts +37 -5
- package/lib/flowContext.js +224 -87
- package/lib/flowEngine.d.ts +24 -1
- package/lib/flowEngine.js +81 -8
- package/lib/flowSettings.d.ts +2 -1
- package/lib/flowSettings.js +16 -8
- package/lib/hooks/useApplyAutoFlows.js +2 -1
- package/lib/index.d.ts +7 -1
- package/lib/index.js +32 -3
- package/lib/locale/en-US.json +4 -2
- package/lib/locale/index.d.ts +4 -0
- package/lib/locale/zh-CN.json +4 -2
- package/lib/models/CollectionFieldModel.d.ts +3 -0
- package/lib/models/CollectionFieldModel.js +52 -6
- package/lib/models/flowModel.d.ts +30 -29
- package/lib/models/flowModel.js +153 -100
- package/lib/models/forkFlowModel.d.ts +8 -4
- package/lib/models/forkFlowModel.js +38 -8
- package/lib/provider.d.ts +3 -1
- package/lib/provider.js +7 -5
- package/lib/resources/multiRecordResource.js +25 -1
- package/lib/resources/singleRecordResource.js +19 -1
- package/lib/resources/sqlResource.d.ts +1 -0
- package/lib/resources/sqlResource.js +20 -24
- package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.d.ts +1 -6
- package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.js +27 -20
- package/lib/runjs-context/contexts/JSBlockRunJSContext.d.ts +1 -6
- package/lib/runjs-context/contexts/JSBlockRunJSContext.js +46 -33
- package/lib/runjs-context/contexts/JSCollectionActionRunJSContext.d.ts +1 -2
- package/lib/runjs-context/contexts/JSCollectionActionRunJSContext.js +14 -15
- package/lib/runjs-context/contexts/{LinkageRunJSContext.d.ts → JSColumnRunJSContext.d.ts} +6 -3
- package/lib/runjs-context/contexts/JSColumnRunJSContext.js +78 -0
- package/lib/runjs-context/contexts/JSFieldRunJSContext.d.ts +1 -6
- package/lib/runjs-context/contexts/JSFieldRunJSContext.js +28 -24
- package/lib/runjs-context/contexts/JSItemRunJSContext.d.ts +1 -6
- package/lib/runjs-context/contexts/JSItemRunJSContext.js +24 -20
- package/lib/runjs-context/contexts/JSRecordActionRunJSContext.d.ts +1 -2
- package/lib/runjs-context/contexts/JSRecordActionRunJSContext.js +16 -17
- package/lib/runjs-context/contexts/base.d.ts +9 -0
- package/lib/runjs-context/contexts/base.js +205 -0
- package/lib/runjs-context/helpers.d.ts +5 -2
- package/lib/runjs-context/helpers.js +36 -27
- package/lib/runjs-context/registry.d.ts +7 -4
- package/lib/runjs-context/registry.js +10 -42
- package/lib/runjs-context/setup.d.ts +9 -0
- package/lib/runjs-context/setup.js +82 -0
- package/lib/runjs-context/snippets/global/{copy-record-json.snippet.js → api-request.snippet.js} +25 -10
- package/lib/runjs-context/snippets/global/clipboard-copy-text.snippet.js +61 -0
- package/lib/runjs-context/snippets/global/{view-navigation-push.snippet.js → import-esm.snippet.js} +26 -12
- package/lib/runjs-context/snippets/global/message-error.snippet.js +6 -0
- package/lib/runjs-context/snippets/global/message-success.snippet.js +6 -0
- package/lib/runjs-context/snippets/global/notification-open.snippet.d.ts +3 -8
- package/lib/runjs-context/snippets/global/notification-open.snippet.js +8 -1
- package/lib/runjs-context/snippets/global/open-view-dialog.snippet.js +10 -3
- package/lib/runjs-context/snippets/global/open-view-drawer.snippet.js +10 -3
- package/lib/runjs-context/snippets/global/query-selector.snippet.js +53 -0
- package/lib/runjs-context/snippets/global/require-amd.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/{requireAsync.snippet.js → require-amd.snippet.js} +16 -13
- package/lib/runjs-context/snippets/global/window-open.snippet.d.ts +3 -8
- package/lib/runjs-context/snippets/global/window-open.snippet.js +8 -1
- package/lib/runjs-context/snippets/index.d.ts +14 -3
- package/lib/runjs-context/snippets/index.js +162 -40
- package/lib/runjs-context/snippets/scene/block/add-event-listener.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/{jsblock → block}/add-event-listener.snippet.js +11 -2
- package/lib/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.js +64 -0
- package/lib/runjs-context/snippets/scene/block/chartjs-bar.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/chartjs-bar.snippet.js +99 -0
- package/lib/runjs-context/snippets/{libs → scene/block}/echarts-init.snippet.js +24 -7
- package/lib/runjs-context/snippets/scene/block/render-antd-icons.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-antd-icons.snippet.js +65 -0
- package/lib/runjs-context/snippets/scene/block/render-button-handler.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/{jsblock → block}/render-button-handler.snippet.js +17 -9
- package/lib/runjs-context/snippets/scene/block/render-iframe.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-iframe.snippet.js +57 -0
- package/lib/runjs-context/snippets/scene/block/render-info-card.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-info-card.snippet.js +71 -0
- package/lib/runjs-context/snippets/scene/block/render-react-jsx.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/{jsblock/render-card.snippet.js → block/render-react-jsx.snippet.js} +26 -13
- package/lib/runjs-context/snippets/scene/block/render-react.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/{jsblock → block}/render-react.snippet.js +18 -17
- package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.js +95 -0
- package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.js +84 -0
- package/lib/runjs-context/snippets/scene/block/resource-example.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/resource-example.snippet.js +60 -0
- package/lib/runjs-context/snippets/scene/block/three-users-orbit.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/three-users-orbit.snippet.js +283 -0
- package/lib/runjs-context/snippets/scene/block/vue-component.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/vue-component.snippet.js +124 -0
- package/lib/runjs-context/snippets/scene/detail/color-by-value.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/{jsfield → detail}/color-by-value.snippet.js +13 -3
- package/lib/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/{global → scene/detail}/copy-to-clipboard.snippet.js +28 -6
- package/lib/runjs-context/snippets/scene/detail/format-number.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/{jsfield → detail}/format-number.snippet.js +13 -3
- package/lib/runjs-context/snippets/scene/detail/innerHTML-value.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/{jsfield → detail}/innerHTML-value.snippet.js +13 -3
- package/lib/runjs-context/snippets/scene/detail/percentage-bar.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/percentage-bar.snippet.js +82 -0
- package/lib/runjs-context/snippets/scene/detail/relative-time.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/relative-time.snippet.js +80 -0
- package/lib/runjs-context/snippets/scene/detail/status-tag.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/status-tag.snippet.js +74 -0
- package/lib/runjs-context/snippets/scene/form/calculate-total.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/calculate-total.snippet.js +63 -0
- package/lib/runjs-context/snippets/scene/form/cascade-select.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/cascade-select.snippet.js +81 -0
- package/lib/runjs-context/snippets/scene/form/conditional-required.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/conditional-required.snippet.js +64 -0
- package/lib/runjs-context/snippets/scene/form/copy-field-values.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/copy-field-values.snippet.js +74 -0
- package/lib/runjs-context/snippets/scene/form/render-basic.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/{jsitem → form}/render-basic.snippet.js +11 -2
- package/lib/runjs-context/snippets/scene/form/set-disabled.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/{linkage → form}/set-disabled.snippet.js +12 -3
- package/lib/runjs-context/snippets/scene/form/set-field-value.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/{linkage → form}/set-field-value.snippet.js +12 -3
- package/lib/runjs-context/snippets/scene/form/set-required.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/{linkage → form}/set-required.snippet.js +12 -3
- package/lib/runjs-context/snippets/scene/form/toggle-multiple-fields.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/toggle-multiple-fields.snippet.js +67 -0
- package/lib/runjs-context/snippets/scene/form/toggle-visible.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/{linkage → form}/toggle-visible.snippet.js +12 -3
- package/lib/runjs-context/snippets/scene/table/cell-open-dialog.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/cell-open-dialog.snippet.js +64 -0
- package/lib/runjs-context/snippets/scene/table/collection-selected-count.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/{actions → table}/collection-selected-count.snippet.js +11 -2
- package/lib/runjs-context/snippets/scene/table/concat-fields.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/concat-fields.snippet.js +79 -0
- package/lib/runjs-context/snippets/scene/table/destroy-selected.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/{global/log-json-record.snippet.js → scene/table/destroy-selected.snippet.js} +24 -11
- package/lib/runjs-context/snippets/scene/table/export-selected-json.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/export-selected-json.snippet.js +64 -0
- package/lib/runjs-context/snippets/scene/table/iterate-selected-rows.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/{actions → table}/iterate-selected-rows.snippet.js +11 -2
- package/lib/runjs-context/snippets/types.d.ts +9 -1
- package/lib/scheduler/ModelOperationScheduler.d.ts +51 -0
- package/lib/scheduler/ModelOperationScheduler.js +262 -0
- package/lib/types.d.ts +28 -3
- package/lib/types.js +4 -3
- package/lib/utils/associationObjectVariable.d.ts +32 -0
- package/lib/utils/associationObjectVariable.js +157 -0
- package/lib/utils/buildSettingsViewInputArgs.d.ts +19 -0
- package/lib/utils/buildSettingsViewInputArgs.js +75 -0
- package/lib/utils/createEphemeralContext.d.ts +13 -0
- package/lib/utils/createEphemeralContext.js +140 -0
- package/lib/utils/flows.d.ts +10 -0
- package/lib/{runjs-context/snippets/global/api-request-post.snippet.js → utils/flows.js} +21 -15
- package/lib/utils/index.d.ts +7 -2
- package/lib/utils/index.js +21 -2
- package/lib/utils/jsxTransform.d.ts +15 -0
- package/lib/utils/jsxTransform.js +68 -0
- package/lib/utils/params-resolvers.js +3 -3
- package/lib/utils/parsePathnameToViewParams.d.ts +1 -1
- package/lib/utils/parsePathnameToViewParams.js +41 -5
- package/lib/utils/pruneFilter.d.ts +21 -0
- package/lib/{runjs-context/snippets/global/try-catch-async.snippet.js → utils/pruneFilter.js} +24 -16
- package/lib/utils/safeGlobals.d.ts +5 -3
- package/lib/utils/safeGlobals.js +40 -0
- package/lib/utils/schema-utils.js +2 -2
- package/lib/utils/serverContextParams.d.ts +1 -0
- package/lib/utils/translation.d.ts +4 -1
- package/lib/utils/translation.js +6 -2
- package/lib/utils/variablesParams.d.ts +22 -5
- package/lib/utils/variablesParams.js +132 -36
- package/lib/views/DrawerComponent.js +21 -2
- package/lib/views/PageComponent.js +2 -1
- package/lib/views/ViewNavigation.d.ts +3 -9
- package/lib/views/ViewNavigation.js +16 -2
- package/lib/views/createViewMeta.d.ts +29 -1
- package/lib/views/createViewMeta.js +338 -72
- package/lib/views/index.d.ts +1 -0
- package/lib/views/index.js +3 -0
- package/lib/views/useDialog.d.ts +9 -8
- package/lib/views/useDialog.js +19 -14
- package/lib/views/useDrawer.d.ts +9 -8
- package/lib/views/useDrawer.js +54 -35
- package/lib/views/usePage.d.ts +9 -8
- package/lib/views/usePage.js +20 -14
- package/package.json +6 -3
- package/src/BlockScopedFlowEngine.ts +86 -0
- package/src/FlowContextProvider.tsx +4 -2
- package/src/JSRunner.ts +3 -0
- package/src/ViewScopedFlowEngine.ts +15 -1
- package/src/__tests__/JSRunner.test.ts +62 -53
- package/src/__tests__/blockScopedFlowEngine.test.ts +154 -0
- package/src/__tests__/createViewMeta.popup.test.ts +132 -0
- package/src/__tests__/flow-engine.test.ts +3 -0
- package/src/__tests__/flowContext.test.ts +52 -0
- package/src/__tests__/flowContextCreateJSRunner.test.ts +163 -0
- package/src/__tests__/flowEngine.saveModel.test.ts +4 -0
- package/src/__tests__/flowRunJSContextDefine.test.ts +508 -0
- package/src/__tests__/flowSettings.open.test.tsx +2 -0
- package/src/__tests__/flowSettings.test.ts +2 -0
- package/src/__tests__/globalFlowRegistry.test.ts +1 -1
- package/src/__tests__/modelOperationScheduler.test.ts +346 -0
- package/src/__tests__/objectVariable.test.ts +464 -0
- package/src/__tests__/runjsContext.test.ts +216 -35
- package/src/__tests__/runjsContextImplementations.test.ts +217 -0
- package/src/__tests__/runjsContextRuntime.test.ts +269 -0
- package/src/__tests__/runjsEdgeCases.test.ts +281 -0
- package/src/__tests__/runjsLocales.test.ts +36 -0
- package/src/__tests__/runjsRuntimeFeatures.test.ts +461 -0
- package/src/__tests__/runjsSnippets.test.ts +140 -0
- package/src/__tests__/viewScopedFlowEngine.test.ts +3 -3
- package/src/acl/Acl.tsx +14 -0
- package/src/acl/__tests__/Acl.test.tsx +43 -0
- package/src/components/DynamicFlowsEditor.tsx +3 -4
- package/src/components/FieldModelRenderer.tsx +20 -7
- package/src/components/FieldSkeleton.tsx +27 -0
- package/src/components/FlowContextSelector.tsx +6 -2
- package/src/components/FlowModelRenderer.tsx +33 -81
- package/src/components/FormItem.tsx +8 -1
- package/src/components/MobilePopup.style.ts +220 -0
- package/src/components/MobilePopup.tsx +86 -0
- package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +6 -6
- package/src/components/index.ts +1 -0
- package/src/components/settings/independents/dropdown/FlowsDropdownButton.tsx +1 -1
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +17 -4
- package/src/components/settings/wrappers/contextual/FlowsContextMenu.tsx +1 -1
- package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +39 -10
- package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +14 -1
- package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +425 -0
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +5 -7
- package/src/components/variables/VariableInput.tsx +25 -5
- package/src/components/variables/VariableTag.tsx +54 -2
- package/src/components/variables/types.ts +2 -0
- package/src/data-source/__tests__/sortCollectionsByInherits.test.ts +125 -0
- package/src/data-source/index.ts +42 -11
- package/src/data-source/sortCollectionsByInherits.ts +61 -0
- package/src/emitter.ts +14 -0
- package/src/executor/FlowExecutor.ts +213 -119
- package/src/executor/__tests__/ctx-defs-injection.test.ts +197 -0
- package/src/executor/__tests__/flowExecutor.test.ts +151 -5
- package/src/flow-registry/GlobalFlowRegistry.ts +1 -0
- package/src/flow-registry/InstanceFlowRegistry.ts +1 -0
- package/src/flow-registry/__tests__/globalFlowRegistry.test.ts +54 -0
- package/src/flowContext.ts +303 -104
- package/src/flowEngine.ts +96 -6
- package/src/flowSettings.ts +12 -4
- package/src/hooks/useApplyAutoFlows.ts +3 -1
- package/src/index.ts +12 -1
- package/src/locale/en-US.json +4 -2
- package/src/locale/zh-CN.json +4 -2
- package/src/models/CollectionFieldModel.tsx +60 -8
- package/src/models/__tests__/dispatchEvent.behavior.test.ts +169 -0
- package/src/models/__tests__/flowModel.getFlows.sort.test.ts +33 -9
- package/src/models/__tests__/flowModel.scheduleModelOperation.test.tsx +129 -0
- package/src/models/__tests__/flowModel.test.ts +234 -111
- package/src/models/__tests__/forkFlowModel.test.ts +40 -7
- package/src/models/flowModel.tsx +197 -132
- package/src/models/forkFlowModel.ts +48 -8
- package/src/provider.tsx +10 -7
- package/src/resources/multiRecordResource.ts +28 -1
- package/src/resources/singleRecordResource.ts +19 -1
- package/src/resources/sqlResource.ts +20 -25
- package/src/runjs-context/contexts/FormJSFieldItemRunJSContext.ts +28 -21
- package/src/runjs-context/contexts/JSBlockRunJSContext.ts +46 -34
- package/src/runjs-context/contexts/JSCollectionActionRunJSContext.ts +15 -16
- package/src/runjs-context/contexts/JSColumnRunJSContext.ts +58 -0
- package/src/runjs-context/contexts/JSFieldRunJSContext.ts +30 -25
- package/src/runjs-context/contexts/JSItemRunJSContext.ts +25 -21
- package/src/runjs-context/contexts/JSRecordActionRunJSContext.ts +17 -18
- package/src/runjs-context/contexts/base.ts +196 -0
- package/src/runjs-context/helpers.ts +32 -30
- package/src/runjs-context/registry.ts +16 -47
- package/src/runjs-context/setup.ts +51 -0
- package/src/runjs-context/snippets/global/api-request.snippet.ts +38 -0
- package/src/runjs-context/snippets/global/clipboard-copy-text.snippet.ts +42 -0
- package/src/runjs-context/snippets/global/import-esm.snippet.ts +39 -0
- package/src/runjs-context/snippets/global/message-error.snippet.ts +6 -0
- package/src/runjs-context/snippets/global/message-success.snippet.ts +6 -0
- package/src/runjs-context/snippets/global/notification-open.snippet.ts +11 -1
- package/src/runjs-context/snippets/global/open-view-dialog.snippet.ts +10 -3
- package/src/runjs-context/snippets/global/open-view-drawer.snippet.ts +10 -3
- package/src/runjs-context/snippets/global/query-selector.snippet.ts +34 -0
- package/src/runjs-context/snippets/global/require-amd.snippet.ts +30 -0
- package/src/runjs-context/snippets/global/window-open.snippet.ts +11 -1
- package/src/runjs-context/snippets/index.ts +178 -39
- package/src/runjs-context/snippets/scene/{jsblock → block}/add-event-listener.snippet.ts +14 -2
- package/src/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.ts +45 -0
- package/src/runjs-context/snippets/scene/block/chartjs-bar.snippet.ts +80 -0
- package/src/runjs-context/snippets/scene/block/echarts-init.snippet.ts +44 -0
- package/src/runjs-context/snippets/scene/block/render-antd-icons.snippet.ts +46 -0
- package/src/runjs-context/snippets/scene/block/render-button-handler.snippet.ts +35 -0
- package/src/runjs-context/snippets/scene/block/render-iframe.snippet.ts +38 -0
- package/src/runjs-context/snippets/scene/block/render-info-card.snippet.ts +52 -0
- package/src/runjs-context/snippets/scene/block/render-react-jsx.snippet.ts +39 -0
- package/src/runjs-context/snippets/scene/block/render-react.snippet.ts +38 -0
- package/src/runjs-context/snippets/scene/block/render-statistics.snippet.ts +76 -0
- package/src/runjs-context/snippets/scene/block/render-timeline.snippet.ts +65 -0
- package/src/runjs-context/snippets/scene/block/resource-example.snippet.ts +46 -0
- package/src/runjs-context/snippets/scene/block/three-users-orbit.snippet.ts +264 -0
- package/src/runjs-context/snippets/scene/block/vue-component.snippet.ts +105 -0
- package/src/runjs-context/snippets/scene/detail/color-by-value.snippet.ts +33 -0
- package/src/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.ts +45 -0
- package/src/runjs-context/snippets/scene/detail/format-number.snippet.ts +32 -0
- package/src/runjs-context/snippets/scene/detail/innerHTML-value.snippet.ts +31 -0
- package/src/runjs-context/snippets/scene/detail/percentage-bar.snippet.ts +63 -0
- package/src/runjs-context/snippets/scene/detail/relative-time.snippet.ts +61 -0
- package/src/runjs-context/snippets/scene/detail/status-tag.snippet.ts +55 -0
- package/src/runjs-context/snippets/scene/form/calculate-total.snippet.ts +44 -0
- package/src/runjs-context/snippets/scene/form/cascade-select.snippet.ts +62 -0
- package/src/runjs-context/snippets/scene/form/conditional-required.snippet.ts +45 -0
- package/src/runjs-context/snippets/scene/form/copy-field-values.snippet.ts +55 -0
- package/src/runjs-context/snippets/scene/{jsitem → form}/render-basic.snippet.ts +14 -2
- package/src/runjs-context/snippets/scene/{linkage → form}/set-disabled.snippet.ts +15 -3
- package/src/runjs-context/snippets/scene/{linkage → form}/set-field-value.snippet.ts +15 -3
- package/src/runjs-context/snippets/scene/{linkage → form}/set-required.snippet.ts +15 -3
- package/src/runjs-context/snippets/scene/form/toggle-multiple-fields.snippet.ts +48 -0
- package/src/runjs-context/snippets/scene/{linkage → form}/toggle-visible.snippet.ts +15 -3
- package/src/runjs-context/snippets/scene/table/cell-open-dialog.snippet.ts +45 -0
- package/src/runjs-context/snippets/scene/{actions → table}/collection-selected-count.snippet.ts +14 -2
- package/src/runjs-context/snippets/scene/table/concat-fields.snippet.ts +60 -0
- package/src/runjs-context/snippets/scene/table/destroy-selected.snippet.ts +36 -0
- package/src/runjs-context/snippets/scene/table/export-selected-json.snippet.ts +45 -0
- package/src/runjs-context/snippets/scene/{actions → table}/iterate-selected-rows.snippet.ts +14 -2
- package/src/runjs-context/snippets/types.ts +5 -1
- package/src/scheduler/ModelOperationScheduler.ts +304 -0
- package/src/types.ts +34 -0
- package/src/utils/__tests__/flows.test.ts +65 -0
- package/src/utils/__tests__/jsxTransform.test.ts +38 -0
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +25 -0
- package/src/utils/__tests__/pruneFilter.test.ts +38 -0
- package/src/utils/__tests__/safeGlobals.test.ts +22 -1
- package/src/utils/__tests__/variablesParams.test.ts +63 -0
- package/src/utils/associationObjectVariable.ts +180 -0
- package/src/utils/buildSettingsViewInputArgs.ts +72 -0
- package/src/utils/createEphemeralContext.ts +142 -0
- package/src/utils/flows.ts +23 -0
- package/src/utils/index.ts +11 -2
- package/src/utils/jsxTransform.ts +39 -0
- package/src/utils/params-resolvers.ts +2 -2
- package/src/utils/parsePathnameToViewParams.ts +50 -6
- package/src/utils/pruneFilter.ts +41 -0
- package/src/utils/safeGlobals.ts +49 -3
- package/src/utils/schema-utils.ts +1 -1
- package/src/utils/serverContextParams.ts +1 -0
- package/src/utils/translation.ts +7 -2
- package/src/utils/variablesParams.ts +156 -38
- package/src/views/DrawerComponent.tsx +21 -2
- package/src/views/PageComponent.tsx +1 -1
- package/src/views/ViewNavigation.ts +20 -12
- package/src/views/__tests__/ViewNavigation.test.ts +10 -0
- package/src/views/createViewMeta.ts +393 -70
- package/src/views/index.tsx +1 -0
- package/src/views/useDialog.tsx +24 -18
- package/src/views/useDrawer.tsx +74 -45
- package/src/views/usePage.tsx +26 -17
- package/lib/runjs-context/contexts/FlowRunJSContext.d.ts +0 -38
- package/lib/runjs-context/contexts/FlowRunJSContext.js +0 -217
- package/lib/runjs-context/contexts/LinkageRunJSContext.js +0 -62
- package/lib/runjs-context/index.d.ts +0 -19
- package/lib/runjs-context/index.js +0 -57
- package/lib/runjs-context/snippets/global/api-request-get.snippet.d.ts +0 -16
- package/lib/runjs-context/snippets/global/api-request-get.snippet.js +0 -42
- package/lib/runjs-context/snippets/global/api-request-post.snippet.d.ts +0 -16
- package/lib/runjs-context/snippets/global/console-log-ctx.snippet.d.ts +0 -16
- package/lib/runjs-context/snippets/global/console-log-ctx.snippet.js +0 -41
- package/lib/runjs-context/snippets/global/requireAsync.snippet.d.ts +0 -16
- package/lib/runjs-context/snippets/global/sleep.snippet.d.ts +0 -16
- package/lib/runjs-context/snippets/global/sleep.snippet.js +0 -43
- package/lib/runjs-context/snippets/global/try-catch-async.snippet.d.ts +0 -16
- package/lib/runjs-context/snippets/libs/echarts-init.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/actions/collection-selected-count.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/actions/iterate-selected-rows.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/actions/record-id-message.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/actions/record-id-message.snippet.js +0 -43
- package/lib/runjs-context/snippets/scene/actions/run-action-basic.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/actions/run-action-basic.snippet.js +0 -40
- package/lib/runjs-context/snippets/scene/jsblock/add-event-listener.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/jsblock/append-style.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/jsblock/append-style.snippet.js +0 -42
- package/lib/runjs-context/snippets/scene/jsblock/jsx-mount.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/jsblock/jsx-mount.snippet.js +0 -46
- package/lib/runjs-context/snippets/scene/jsblock/jsx-unmount.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/jsblock/jsx-unmount.snippet.js +0 -41
- package/lib/runjs-context/snippets/scene/jsblock/render-basic.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/jsblock/render-basic.snippet.js +0 -41
- package/lib/runjs-context/snippets/scene/jsblock/render-button-handler.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/jsblock/render-react.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/jsfield/color-by-value.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/jsfield/format-number.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/jsfield/innerHTML-value.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/jsitem/render-basic.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/linkage/set-disabled.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/linkage/set-field-value.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/linkage/set-required.snippet.d.ts +0 -15
- package/lib/runjs-context/snippets/scene/linkage/toggle-visible.snippet.d.ts +0 -15
- package/src/runjs-context/contexts/FlowRunJSContext.ts +0 -190
- package/src/runjs-context/contexts/LinkageRunJSContext.ts +0 -35
- package/src/runjs-context/index.ts +0 -20
- package/src/runjs-context/snippets/global/api-request-get.snippet.ts +0 -20
- package/src/runjs-context/snippets/global/api-request-post.snippet.ts +0 -20
- package/src/runjs-context/snippets/global/console-log-ctx.snippet.ts +0 -19
- package/src/runjs-context/snippets/global/copy-record-json.snippet.ts +0 -21
- package/src/runjs-context/snippets/global/copy-to-clipboard.snippet.ts +0 -21
- package/src/runjs-context/snippets/global/log-json-record.snippet.ts +0 -21
- package/src/runjs-context/snippets/global/requireAsync.snippet.ts +0 -24
- package/src/runjs-context/snippets/global/sleep.snippet.ts +0 -21
- package/src/runjs-context/snippets/global/try-catch-async.snippet.ts +0 -22
- package/src/runjs-context/snippets/global/view-navigation-push.snippet.ts +0 -23
- package/src/runjs-context/snippets/libs/echarts-init.snippet.ts +0 -24
- package/src/runjs-context/snippets/scene/actions/record-id-message.snippet.ts +0 -21
- package/src/runjs-context/snippets/scene/actions/run-action-basic.snippet.ts +0 -18
- package/src/runjs-context/snippets/scene/jsblock/append-style.snippet.ts +0 -20
- package/src/runjs-context/snippets/scene/jsblock/jsx-mount.snippet.ts +0 -24
- package/src/runjs-context/snippets/scene/jsblock/jsx-unmount.snippet.ts +0 -19
- package/src/runjs-context/snippets/scene/jsblock/render-basic.snippet.ts +0 -24
- package/src/runjs-context/snippets/scene/jsblock/render-button-handler.snippet.ts +0 -24
- package/src/runjs-context/snippets/scene/jsblock/render-card.snippet.ts +0 -30
- package/src/runjs-context/snippets/scene/jsblock/render-react.snippet.ts +0 -34
- package/src/runjs-context/snippets/scene/jsfield/color-by-value.snippet.ts +0 -20
- package/src/runjs-context/snippets/scene/jsfield/format-number.snippet.ts +0 -19
- package/src/runjs-context/snippets/scene/jsfield/innerHTML-value.snippet.ts +0 -18
- /package/lib/runjs-context/snippets/global/{copy-record-json.snippet.d.ts → api-request.snippet.d.ts} +0 -0
- /package/lib/runjs-context/snippets/global/{copy-to-clipboard.snippet.d.ts → clipboard-copy-text.snippet.d.ts} +0 -0
- /package/lib/runjs-context/snippets/global/{log-json-record.snippet.d.ts → import-esm.snippet.d.ts} +0 -0
- /package/lib/runjs-context/snippets/global/{view-navigation-push.snippet.d.ts → query-selector.snippet.d.ts} +0 -0
- /package/lib/runjs-context/snippets/scene/{jsblock/render-card.snippet.d.ts → block/echarts-init.snippet.d.ts} +0 -0
package/src/flowContext.ts
CHANGED
|
@@ -11,14 +11,17 @@ import { ISchema } from '@formily/json-schema';
|
|
|
11
11
|
import { observable } from '@formily/reactive';
|
|
12
12
|
import { APIClient } from '@nocobase/sdk';
|
|
13
13
|
import type { Router } from '@remix-run/router';
|
|
14
|
-
import * as antd from 'antd';
|
|
15
14
|
import { MessageInstance } from 'antd/es/message/interface';
|
|
15
|
+
import * as antd from 'antd';
|
|
16
|
+
import * as antdIcons from '@ant-design/icons';
|
|
16
17
|
import type { HookAPI } from 'antd/es/modal/useModal';
|
|
17
18
|
import { NotificationInstance } from 'antd/es/notification/interface';
|
|
18
19
|
import _ from 'lodash';
|
|
19
20
|
import pino from 'pino';
|
|
20
21
|
import qs from 'qs';
|
|
21
22
|
import React, { createRef } from 'react';
|
|
23
|
+
import * as ReactDOMClient from 'react-dom/client';
|
|
24
|
+
import { ElementProxy } from './ElementProxy';
|
|
22
25
|
import type { Location } from 'react-router-dom';
|
|
23
26
|
import { ACL } from './acl/Acl';
|
|
24
27
|
import { ContextPathProxy } from './ContextPathProxy';
|
|
@@ -26,21 +29,11 @@ import { DataSource, DataSourceManager } from './data-source';
|
|
|
26
29
|
import { FlowEngine } from './flowEngine';
|
|
27
30
|
import { FlowI18n } from './flowI18n';
|
|
28
31
|
import { JSRunner, JSRunnerOptions } from './JSRunner';
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
APIResource,
|
|
33
|
-
BaseRecordResource,
|
|
34
|
-
FlowResource,
|
|
35
|
-
FlowSQLRepository,
|
|
36
|
-
MultiRecordResource,
|
|
37
|
-
SingleRecordResource,
|
|
38
|
-
SQLResource,
|
|
39
|
-
} from './resources';
|
|
32
|
+
import type { FlowModel } from './models/flowModel';
|
|
33
|
+
import type { ForkFlowModel } from './models/forkFlowModel';
|
|
34
|
+
import { FlowResource, FlowSQLRepository } from './resources';
|
|
40
35
|
import type { ActionDefinition, EventDefinition, ResourceType } from './types';
|
|
41
36
|
import {
|
|
42
|
-
createSafeDocument,
|
|
43
|
-
createSafeWindow,
|
|
44
37
|
escapeT,
|
|
45
38
|
extractPropertyPath,
|
|
46
39
|
extractUsedVariablePaths,
|
|
@@ -53,6 +46,9 @@ import { enqueueVariablesResolve, JSONValue } from './utils/params-resolvers';
|
|
|
53
46
|
import type { RecordRef } from './utils/serverContextParams';
|
|
54
47
|
import { buildServerContextParams as _buildServerContextParams } from './utils/serverContextParams';
|
|
55
48
|
import { FlowView, FlowViewer } from './views/FlowView';
|
|
49
|
+
import { RunJSContextRegistry, getModelClassName } from './runjs-context/registry';
|
|
50
|
+
import { createEphemeralContext } from './utils/createEphemeralContext';
|
|
51
|
+
import dayjs from 'dayjs';
|
|
56
52
|
|
|
57
53
|
// Helper: detect a RecordRef-like object
|
|
58
54
|
function isRecordRefLike(val: any): boolean {
|
|
@@ -142,6 +138,10 @@ export interface PropertyOptions {
|
|
|
142
138
|
// - boolean: true 表示整个顶层变量交给服务端;false 表示仅前端解析
|
|
143
139
|
// - function: 根据子路径决定是否交给服务端(子路径示例:'record.roles[0].name'、'id'、'')
|
|
144
140
|
resolveOnServer?: boolean | ((subPath: string) => boolean);
|
|
141
|
+
// 优化:当需要服务端解析但本属性在 buildVariablesParams 返回空时,是否跳过调用服务端。
|
|
142
|
+
// - 典型场景:formValues / currentObject 仅在“已选关联值”存在时才需要服务端;否则没有必要请求。
|
|
143
|
+
// - 默认 false:保持兼容,其他变量即使没有 contextParams 也可选择调用服务端。
|
|
144
|
+
serverOnlyWhenContextParams?: boolean;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
type RouteOptions = {
|
|
@@ -892,46 +892,19 @@ export class FlowContext {
|
|
|
892
892
|
}
|
|
893
893
|
}
|
|
894
894
|
|
|
895
|
-
export class FlowRunjsContext extends FlowContext {
|
|
896
|
-
constructor(delegate: FlowContext) {
|
|
897
|
-
super();
|
|
898
|
-
this.addDelegate(delegate);
|
|
899
|
-
// Expose React and antd only within runjs context
|
|
900
|
-
// This keeps the scope minimal while enabling React/AntD rendering in scripts
|
|
901
|
-
this.defineProperty('React', { value: React });
|
|
902
|
-
this.defineProperty('antd', { value: antd });
|
|
903
|
-
this.defineMethod(
|
|
904
|
-
'dispatchModelEvent',
|
|
905
|
-
async (modelOrUid: FlowModel | string, eventName: string, inputArgs?: Record<string, any>) => {
|
|
906
|
-
let model: FlowModel | null = null;
|
|
907
|
-
if (typeof modelOrUid === 'string') {
|
|
908
|
-
model = await this.engine.loadModel({ uid: modelOrUid });
|
|
909
|
-
} else if (modelOrUid instanceof FlowModel) {
|
|
910
|
-
model = modelOrUid;
|
|
911
|
-
}
|
|
912
|
-
if (model) {
|
|
913
|
-
model.context.addDelegate(this);
|
|
914
|
-
model.dispatchEvent(eventName, { navigation: false, ...this.model?.['getInputArgs']?.(), ...inputArgs });
|
|
915
|
-
} else {
|
|
916
|
-
this.message.error(this.t('Model with ID {{uid}} not found', { uid: modelOrUid }));
|
|
917
|
-
}
|
|
918
|
-
},
|
|
919
|
-
);
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
|
|
923
895
|
class BaseFlowEngineContext extends FlowContext {
|
|
924
896
|
declare router: Router;
|
|
925
897
|
declare dataSourceManager: DataSourceManager;
|
|
926
898
|
declare requireAsync: (url: string) => Promise<any>;
|
|
899
|
+
declare importAsync: (url: string) => Promise<any>;
|
|
927
900
|
declare createJSRunner: (options?: JSRunnerOptions) => JSRunner;
|
|
901
|
+
declare pageInfo: { version?: 'v1' | 'v2' };
|
|
928
902
|
/**
|
|
929
903
|
* @deprecated use `resolveJsonTemplate` instead
|
|
930
904
|
*/
|
|
931
905
|
declare renderJson: (template: JSONValue) => Promise<any>;
|
|
932
906
|
declare resolveJsonTemplate: (template: JSONValue) => Promise<any>;
|
|
933
907
|
declare runjs: (code: string, variables?: Record<string, any>, options?: JSRunnerOptions) => Promise<any>;
|
|
934
|
-
declare copyToClipboard: (text: string) => Promise<void>;
|
|
935
908
|
declare getAction: <TModel extends FlowModel = FlowModel, TCtx extends FlowContext = FlowContext>(
|
|
936
909
|
name: string,
|
|
937
910
|
) => ActionDefinition<TModel, TCtx> | undefined;
|
|
@@ -1005,10 +978,10 @@ export class FlowEngineContext extends BaseFlowEngineContext {
|
|
|
1005
978
|
});
|
|
1006
979
|
this.defineMethod('runjs', async (code, variables, options?: JSRunnerOptions) => {
|
|
1007
980
|
const mergedGlobals = { ...(options?.globals || {}), ...(variables || {}) };
|
|
1008
|
-
const runner = this.createJSRunner({
|
|
981
|
+
const runner = (await (this as any).createJSRunner({
|
|
1009
982
|
...(options || {}),
|
|
1010
983
|
globals: mergedGlobals,
|
|
1011
|
-
});
|
|
984
|
+
})) as JSRunner;
|
|
1012
985
|
return runner.run(code);
|
|
1013
986
|
});
|
|
1014
987
|
this.defineMethod('renderJson', function (template: any) {
|
|
@@ -1090,6 +1063,17 @@ export class FlowEngineContext extends BaseFlowEngineContext {
|
|
|
1090
1063
|
? _buildServerContextParams(this, autoInput)
|
|
1091
1064
|
: undefined;
|
|
1092
1065
|
|
|
1066
|
+
// 优化:若所有需要服务端解析的变量都声明了 “仅当有 contextParams 时才请求服务端”,
|
|
1067
|
+
// 且本次未能构建出任何 contextParams,则跳过服务端请求,回退到前端解析。
|
|
1068
|
+
if (!autoContextParams) {
|
|
1069
|
+
const keys = Object.keys(serverVarPaths);
|
|
1070
|
+
const allOptional =
|
|
1071
|
+
keys.length > 0 && keys.every((k) => this.getPropertyOptions(k)?.serverOnlyWhenContextParams);
|
|
1072
|
+
if (allOptional) {
|
|
1073
|
+
return resolveExpressions(template, this);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1093
1077
|
if (this.api) {
|
|
1094
1078
|
try {
|
|
1095
1079
|
serverResolved = await enqueueVariablesResolve(this as FlowRuntimeContext<FlowModel>, {
|
|
@@ -1218,50 +1202,60 @@ export class FlowEngineContext extends BaseFlowEngineContext {
|
|
|
1218
1202
|
);
|
|
1219
1203
|
});
|
|
1220
1204
|
});
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
ctx: runCtx,
|
|
1228
|
-
window: createSafeWindow(),
|
|
1229
|
-
document: createSafeDocument(),
|
|
1230
|
-
...options?.globals,
|
|
1231
|
-
},
|
|
1232
|
-
});
|
|
1233
|
-
});
|
|
1234
|
-
// 复制文本到剪贴板(优先使用 Clipboard API,降级到 execCommand)
|
|
1235
|
-
this.defineMethod('copyToClipboard', async (text: string) => {
|
|
1236
|
-
const content = String(text ?? '');
|
|
1237
|
-
try {
|
|
1238
|
-
if (typeof navigator !== 'undefined' && navigator.clipboard && navigator.clipboard.writeText) {
|
|
1239
|
-
await navigator.clipboard.writeText(content);
|
|
1240
|
-
return;
|
|
1241
|
-
}
|
|
1242
|
-
} catch (e) {
|
|
1243
|
-
// 忽略,尝试降级方案
|
|
1205
|
+
// 动态按 URL 加载 ESM 模块
|
|
1206
|
+
// - 使用 Vite / Webpack ignore 注释,避免被预打包或重写
|
|
1207
|
+
// - 返回模块命名空间对象(包含 default 与命名导出)
|
|
1208
|
+
this.defineMethod('importAsync', async (url: string) => {
|
|
1209
|
+
if (!url || typeof url !== 'string') {
|
|
1210
|
+
throw new Error('invalid url');
|
|
1244
1211
|
}
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1212
|
+
const u = url.trim();
|
|
1213
|
+
const g = globalThis as any;
|
|
1214
|
+
g.__nocobaseImportAsyncCache = g.__nocobaseImportAsyncCache || new Map<string, Promise<any>>();
|
|
1215
|
+
const cache: Map<string, Promise<any>> = g.__nocobaseImportAsyncCache;
|
|
1216
|
+
if (cache.has(u)) return cache.get(u)!;
|
|
1217
|
+
// 尝试使用原生 dynamic import(加上 vite/webpack 的 ignore 注释)
|
|
1218
|
+
const nativeImport = () => import(/* @vite-ignore */ /* webpackIgnore: true */ u);
|
|
1219
|
+
// 兜底方案:通过 eval 在运行时构造 import,避免被打包器接管
|
|
1220
|
+
const evalImport = () => {
|
|
1221
|
+
const importer = (0, eval)('u => import(u)');
|
|
1222
|
+
return importer(u);
|
|
1223
|
+
};
|
|
1224
|
+
const p = (async () => {
|
|
1248
1225
|
try {
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
const ok = document.execCommand('copy');
|
|
1258
|
-
document.body.removeChild(ta);
|
|
1259
|
-
if (ok) resolve();
|
|
1260
|
-
else reject(new Error('execCommand copy failed'));
|
|
1261
|
-
} catch (err) {
|
|
1262
|
-
reject(err);
|
|
1226
|
+
return await nativeImport();
|
|
1227
|
+
} catch (err: any) {
|
|
1228
|
+
// 常见于打包产物仍然拦截了 dynamic import 或开发态插件未识别 ignore 注释
|
|
1229
|
+
try {
|
|
1230
|
+
return await evalImport();
|
|
1231
|
+
} catch (err2) {
|
|
1232
|
+
throw err2 || err;
|
|
1233
|
+
}
|
|
1263
1234
|
}
|
|
1264
|
-
});
|
|
1235
|
+
})();
|
|
1236
|
+
cache.set(u, p);
|
|
1237
|
+
return p;
|
|
1238
|
+
});
|
|
1239
|
+
this.defineMethod('createJSRunner', async function (options?: JSRunnerOptions) {
|
|
1240
|
+
try {
|
|
1241
|
+
const mod: any = await import('./runjs-context/setup');
|
|
1242
|
+
if (typeof mod?.setupRunJSContexts === 'function') await mod.setupRunJSContexts();
|
|
1243
|
+
} catch (_) {
|
|
1244
|
+
// ignore if setup is not available
|
|
1245
|
+
}
|
|
1246
|
+
const version = (options?.version as any) || 'v1';
|
|
1247
|
+
const modelClass = getModelClassName(this);
|
|
1248
|
+
const Ctor =
|
|
1249
|
+
(RunJSContextRegistry.resolve(version, modelClass) as any) ||
|
|
1250
|
+
(RunJSContextRegistry.resolve(version, '*') as any) ||
|
|
1251
|
+
FlowRunJSContext;
|
|
1252
|
+
let runCtx: any;
|
|
1253
|
+
if (Ctor) {
|
|
1254
|
+
runCtx = new Ctor(this);
|
|
1255
|
+
}
|
|
1256
|
+
const globals: Record<string, any> = { ctx: runCtx, ...(options?.globals || {}) };
|
|
1257
|
+
const { timeoutMs } = options || {};
|
|
1258
|
+
return new JSRunner({ globals, timeoutMs });
|
|
1265
1259
|
});
|
|
1266
1260
|
// Helper: build server contextParams for variables:resolve
|
|
1267
1261
|
this.defineMethod('buildServerContextParams', function (this: BaseFlowEngineContext, input?: any) {
|
|
@@ -1332,7 +1326,8 @@ export class FlowEngineContext extends BaseFlowEngineContext {
|
|
|
1332
1326
|
'runAction',
|
|
1333
1327
|
async function (this: BaseFlowEngineContext, actionName: string, params?: Record<string, any>) {
|
|
1334
1328
|
const def = this.engine.getAction<FlowModel, FlowEngineContext>(actionName);
|
|
1335
|
-
|
|
1329
|
+
// 使用“临时作用域”上下文,避免将临时定义污染到引擎级上下文,并在创建时应用定义
|
|
1330
|
+
const ctx = await createEphemeralContext(this as unknown as FlowEngineContext, def);
|
|
1336
1331
|
if (!def) {
|
|
1337
1332
|
throw new Error(`Action '${actionName}' not found.`);
|
|
1338
1333
|
}
|
|
@@ -1346,7 +1341,7 @@ export class FlowEngineContext extends BaseFlowEngineContext {
|
|
|
1346
1341
|
}
|
|
1347
1342
|
if (!useRawParams) {
|
|
1348
1343
|
// 先服务端解析,再前端补齐
|
|
1349
|
-
combinedParams = await
|
|
1344
|
+
combinedParams = await ctx.resolveJsonTemplate(combinedParams);
|
|
1350
1345
|
}
|
|
1351
1346
|
|
|
1352
1347
|
if (!def.handler) {
|
|
@@ -1369,12 +1364,25 @@ export class FlowEngineContext extends BaseFlowEngineContext {
|
|
|
1369
1364
|
context: this.createProxy(),
|
|
1370
1365
|
});
|
|
1371
1366
|
});
|
|
1367
|
+
// Provide useResource in base engine context so RunJS can call it directly
|
|
1368
|
+
this.defineMethod(
|
|
1369
|
+
'useResource',
|
|
1370
|
+
function (
|
|
1371
|
+
this: BaseFlowEngineContext,
|
|
1372
|
+
className: 'APIResource' | 'SingleRecordResource' | 'MultiRecordResource' | 'SQLResource',
|
|
1373
|
+
) {
|
|
1374
|
+
if (this.has('resource')) return;
|
|
1375
|
+
this.defineProperty('resource', {
|
|
1376
|
+
get: () => this.createResource(className),
|
|
1377
|
+
});
|
|
1378
|
+
},
|
|
1379
|
+
);
|
|
1372
1380
|
}
|
|
1373
1381
|
}
|
|
1374
1382
|
|
|
1375
1383
|
export class FlowModelContext extends BaseFlowModelContext {
|
|
1376
1384
|
constructor(model: FlowModel) {
|
|
1377
|
-
if (!
|
|
1385
|
+
if (!model || typeof model !== 'object') {
|
|
1378
1386
|
throw new Error('Invalid FlowModel instance');
|
|
1379
1387
|
}
|
|
1380
1388
|
super();
|
|
@@ -1383,7 +1391,7 @@ export class FlowModelContext extends BaseFlowModelContext {
|
|
|
1383
1391
|
this.engine.reactView.onRefReady(ref, cb, timeout);
|
|
1384
1392
|
});
|
|
1385
1393
|
this.defineMethod('runjs', async (code, variables, options?: { version?: string }) => {
|
|
1386
|
-
const runner = this.createJSRunner({
|
|
1394
|
+
const runner = await this.createJSRunner({
|
|
1387
1395
|
globals: variables,
|
|
1388
1396
|
version: options?.version,
|
|
1389
1397
|
});
|
|
@@ -1417,21 +1425,24 @@ export class FlowModelContext extends BaseFlowModelContext {
|
|
|
1417
1425
|
stepParams: {
|
|
1418
1426
|
popupSettings: {
|
|
1419
1427
|
openView: {
|
|
1420
|
-
|
|
1428
|
+
// 持久化首次传入的关键展示/数据参数,供后续路由与再次打开复用
|
|
1429
|
+
..._.pick(opts, ['dataSourceKey', 'collectionName', 'associationName', 'mode', 'size']),
|
|
1421
1430
|
},
|
|
1422
1431
|
},
|
|
1423
1432
|
},
|
|
1424
1433
|
});
|
|
1425
1434
|
await model.save();
|
|
1426
1435
|
}
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1436
|
+
// 若已存在 openView 配置,则按需合并更新(仅覆盖本次显式传入的字段)
|
|
1437
|
+
if (model.getStepParams('popupSettings')?.openView) {
|
|
1438
|
+
const prevOpenView = model.getStepParams('popupSettings')?.openView || {};
|
|
1439
|
+
const incoming = _.pick(opts, ['dataSourceKey', 'collectionName', 'associationName', 'mode', 'size']);
|
|
1440
|
+
const nextOpenView = { ...prevOpenView, ...incoming };
|
|
1441
|
+
// 仅当有变更时才保存,避免不必要的写入
|
|
1442
|
+
if (!_.isEqual(prevOpenView, nextOpenView)) {
|
|
1443
|
+
model.setStepParams('popupSettings', { openView: nextOpenView });
|
|
1444
|
+
await model.save();
|
|
1445
|
+
}
|
|
1435
1446
|
}
|
|
1436
1447
|
|
|
1437
1448
|
// 路由层级的 viewUid:优先使用 routeViewUid(仅用于路由展示);
|
|
@@ -1477,7 +1488,8 @@ export class FlowModelContext extends BaseFlowModelContext {
|
|
|
1477
1488
|
'runAction',
|
|
1478
1489
|
async function (this: BaseFlowModelContext, actionName: string, params?: Record<string, any>) {
|
|
1479
1490
|
const def = this.model.getAction<FlowModel, FlowModelContext>(actionName);
|
|
1480
|
-
|
|
1491
|
+
// 使用“临时作用域”上下文,避免将临时定义污染到模型级上下文,并在创建时应用定义
|
|
1492
|
+
const ctx = await createEphemeralContext(this as unknown as FlowModelContext, def);
|
|
1481
1493
|
if (!def) {
|
|
1482
1494
|
throw new Error(`Action '${actionName}' not found.`);
|
|
1483
1495
|
}
|
|
@@ -1490,7 +1502,7 @@ export class FlowModelContext extends BaseFlowModelContext {
|
|
|
1490
1502
|
useRawParams = await useRawParams(ctx);
|
|
1491
1503
|
}
|
|
1492
1504
|
if (!useRawParams) {
|
|
1493
|
-
combinedParams = await
|
|
1505
|
+
combinedParams = await ctx.resolveJsonTemplate(combinedParams);
|
|
1494
1506
|
}
|
|
1495
1507
|
|
|
1496
1508
|
if (!def.handler) {
|
|
@@ -1507,7 +1519,7 @@ export class FlowForkModelContext extends BaseFlowModelContext {
|
|
|
1507
1519
|
public master: FlowModel,
|
|
1508
1520
|
public fork: ForkFlowModel,
|
|
1509
1521
|
) {
|
|
1510
|
-
if (!
|
|
1522
|
+
if (!master || typeof master !== 'object') {
|
|
1511
1523
|
throw new Error('Invalid FlowModel instance');
|
|
1512
1524
|
}
|
|
1513
1525
|
super();
|
|
@@ -1527,7 +1539,7 @@ export class FlowForkModelContext extends BaseFlowModelContext {
|
|
|
1527
1539
|
},
|
|
1528
1540
|
});
|
|
1529
1541
|
this.defineMethod('runjs', async (code, variables, options?: { version?: string }) => {
|
|
1530
|
-
const runner = this.createJSRunner({
|
|
1542
|
+
const runner = await this.createJSRunner({
|
|
1531
1543
|
globals: variables,
|
|
1532
1544
|
version: options?.version,
|
|
1533
1545
|
});
|
|
@@ -1588,7 +1600,7 @@ export class FlowRuntimeContext<
|
|
|
1588
1600
|
this.engine.reactView.onRefReady(ref, cb, timeout);
|
|
1589
1601
|
});
|
|
1590
1602
|
this.defineMethod('runjs', async (code, variables, options?: { version?: string }) => {
|
|
1591
|
-
const runner = this.createJSRunner({
|
|
1603
|
+
const runner = await this.createJSRunner({
|
|
1592
1604
|
globals: variables,
|
|
1593
1605
|
version: options?.version,
|
|
1594
1606
|
});
|
|
@@ -1641,3 +1653,190 @@ export class FlowRuntimeContext<
|
|
|
1641
1653
|
|
|
1642
1654
|
// 类型别名,方便使用
|
|
1643
1655
|
export type FlowSettingsContext<TModel extends FlowModel = FlowModel> = FlowRuntimeContext<TModel, 'settings'>;
|
|
1656
|
+
|
|
1657
|
+
export type RunJSDocCompletionDoc = {
|
|
1658
|
+
insertText?: string;
|
|
1659
|
+
};
|
|
1660
|
+
|
|
1661
|
+
export type RunJSDocPropertyDoc =
|
|
1662
|
+
| string
|
|
1663
|
+
| {
|
|
1664
|
+
description?: string;
|
|
1665
|
+
detail?: string;
|
|
1666
|
+
type?: string;
|
|
1667
|
+
examples?: string[];
|
|
1668
|
+
completion?: RunJSDocCompletionDoc;
|
|
1669
|
+
properties?: Record<string, RunJSDocPropertyDoc>;
|
|
1670
|
+
};
|
|
1671
|
+
|
|
1672
|
+
export type RunJSDocMethodDoc =
|
|
1673
|
+
| string
|
|
1674
|
+
| {
|
|
1675
|
+
description?: string;
|
|
1676
|
+
detail?: string;
|
|
1677
|
+
examples?: string[];
|
|
1678
|
+
completion?: RunJSDocCompletionDoc;
|
|
1679
|
+
};
|
|
1680
|
+
|
|
1681
|
+
export type RunJSDocMeta = {
|
|
1682
|
+
label?: string;
|
|
1683
|
+
properties?: Record<string, RunJSDocPropertyDoc>;
|
|
1684
|
+
methods?: Record<string, RunJSDocMethodDoc>;
|
|
1685
|
+
snippets?: Record<string, any>;
|
|
1686
|
+
};
|
|
1687
|
+
|
|
1688
|
+
const __runjsClassDefaultMeta = new WeakMap<Function, RunJSDocMeta>();
|
|
1689
|
+
const __runjsClassLocaleMeta = new WeakMap<Function, Map<string, RunJSDocMeta>>();
|
|
1690
|
+
const __runjsDocCache = new WeakMap<Function, Map<string, RunJSDocMeta>>();
|
|
1691
|
+
|
|
1692
|
+
function __runjsDeepMerge(base: any, patch: any) {
|
|
1693
|
+
if (patch === null) return undefined;
|
|
1694
|
+
if (Array.isArray(base) || Array.isArray(patch) || typeof base !== 'object' || typeof patch !== 'object') {
|
|
1695
|
+
return patch ?? base;
|
|
1696
|
+
}
|
|
1697
|
+
const out: any = { ...base };
|
|
1698
|
+
for (const k of Object.keys(patch)) {
|
|
1699
|
+
const v = __runjsDeepMerge(base?.[k], patch[k]);
|
|
1700
|
+
if (typeof v === 'undefined') delete out[k];
|
|
1701
|
+
else out[k] = v;
|
|
1702
|
+
}
|
|
1703
|
+
return out;
|
|
1704
|
+
}
|
|
1705
|
+
export class FlowRunJSContext extends FlowContext {
|
|
1706
|
+
constructor(delegate: FlowContext) {
|
|
1707
|
+
super();
|
|
1708
|
+
this.addDelegate(delegate);
|
|
1709
|
+
this.defineProperty('React', { value: React });
|
|
1710
|
+
this.defineProperty('antd', { value: antd });
|
|
1711
|
+
this.defineProperty('dayjs', { value: dayjs });
|
|
1712
|
+
// 为 JS 运行时代码提供带有 antd/App/ConfigProvider 包裹的 React 根
|
|
1713
|
+
// 保持与 ReactDOMClient 接口一致,优先覆盖 createRoot,其余方法透传
|
|
1714
|
+
const ReactDOMShim: any = {
|
|
1715
|
+
...ReactDOMClient,
|
|
1716
|
+
createRoot: (container: Element | DocumentFragment, options?: any) => {
|
|
1717
|
+
// 兼容 ElementProxy:若传入的是代理对象,取其底层原生元素
|
|
1718
|
+
const realContainer: any = (container as any)?.__el || container;
|
|
1719
|
+
// 使用引擎自带的 reactView.createRoot,以继承应用内的 ConfigProvider/App 上下文与主题
|
|
1720
|
+
return this.engine.reactView.createRoot(realContainer as HTMLElement, options);
|
|
1721
|
+
},
|
|
1722
|
+
};
|
|
1723
|
+
this.defineProperty('ReactDOM', { value: ReactDOMShim });
|
|
1724
|
+
|
|
1725
|
+
// 为第三方/通用库提供统一命名空间:ctx.libs
|
|
1726
|
+
// - 新增库应优先挂载到 ctx.libs.xxx
|
|
1727
|
+
// - 同时保留顶层别名(如 ctx.React / ctx.antd),以兼容历史代码
|
|
1728
|
+
const libs = Object.freeze({
|
|
1729
|
+
React,
|
|
1730
|
+
ReactDOM: ReactDOMShim,
|
|
1731
|
+
antd,
|
|
1732
|
+
dayjs,
|
|
1733
|
+
antdIcons,
|
|
1734
|
+
});
|
|
1735
|
+
this.defineProperty('libs', { value: libs });
|
|
1736
|
+
|
|
1737
|
+
// Convenience: ctx.render(<App />[, container])
|
|
1738
|
+
// - container defaults to ctx.element if available
|
|
1739
|
+
// - internally uses engine.reactView.createRoot to inherit app context
|
|
1740
|
+
// - caches root per container via global WeakMap
|
|
1741
|
+
this.defineMethod(
|
|
1742
|
+
'render',
|
|
1743
|
+
function (
|
|
1744
|
+
this: any,
|
|
1745
|
+
vnode: React.ReactElement | Node | DocumentFragment | string,
|
|
1746
|
+
container?: Element | DocumentFragment,
|
|
1747
|
+
) {
|
|
1748
|
+
const el = (container as any) || (this.element as any);
|
|
1749
|
+
if (!el) throw new Error('ctx.render: container not provided and ctx.element is not available');
|
|
1750
|
+
const containerEl: any = (el as any)?.__el || el; // unwrap ElementProxy
|
|
1751
|
+
const globalRef: any = globalThis as any;
|
|
1752
|
+
globalRef.__nbRunjsRoots = globalRef.__nbRunjsRoots || new WeakMap<any, any>();
|
|
1753
|
+
const rootMap: WeakMap<any, any> = globalRef.__nbRunjsRoots;
|
|
1754
|
+
|
|
1755
|
+
// If vnode is string (HTML), unmount react root and set sanitized HTML
|
|
1756
|
+
if (typeof vnode === 'string') {
|
|
1757
|
+
const existingRoot = rootMap.get(containerEl);
|
|
1758
|
+
if (existingRoot && typeof existingRoot.unmount === 'function') {
|
|
1759
|
+
try {
|
|
1760
|
+
existingRoot.unmount();
|
|
1761
|
+
} finally {
|
|
1762
|
+
rootMap.delete(containerEl);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
const proxy: any = new ElementProxy(containerEl);
|
|
1766
|
+
proxy.innerHTML = String(vnode ?? '');
|
|
1767
|
+
return null;
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
// If vnode is a DOM Node or DocumentFragment, unmount and replace content
|
|
1771
|
+
if (
|
|
1772
|
+
vnode &&
|
|
1773
|
+
(vnode as any).nodeType &&
|
|
1774
|
+
((vnode as any).nodeType === 1 || (vnode as any).nodeType === 3 || (vnode as any).nodeType === 11)
|
|
1775
|
+
) {
|
|
1776
|
+
const existingRoot = rootMap.get(containerEl);
|
|
1777
|
+
if (existingRoot && typeof existingRoot.unmount === 'function') {
|
|
1778
|
+
try {
|
|
1779
|
+
existingRoot.unmount();
|
|
1780
|
+
} finally {
|
|
1781
|
+
rootMap.delete(containerEl);
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
while (containerEl.firstChild) containerEl.removeChild(containerEl.firstChild);
|
|
1785
|
+
containerEl.appendChild(vnode as any);
|
|
1786
|
+
return null;
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
let root = rootMap.get(containerEl);
|
|
1790
|
+
if (!root) {
|
|
1791
|
+
root = this.ReactDOM.createRoot(containerEl);
|
|
1792
|
+
rootMap.set(containerEl, root);
|
|
1793
|
+
}
|
|
1794
|
+
root.render(vnode as any);
|
|
1795
|
+
return root;
|
|
1796
|
+
},
|
|
1797
|
+
);
|
|
1798
|
+
}
|
|
1799
|
+
static define(meta: RunJSDocMeta, options?: { locale?: string }) {
|
|
1800
|
+
const locale = options?.locale;
|
|
1801
|
+
if (locale) {
|
|
1802
|
+
const map = __runjsClassLocaleMeta.get(this) || new Map<string, RunJSDocMeta>();
|
|
1803
|
+
const prev = map.get(locale) || {};
|
|
1804
|
+
map.set(locale, __runjsDeepMerge(prev, meta));
|
|
1805
|
+
__runjsClassLocaleMeta.set(this, map);
|
|
1806
|
+
} else {
|
|
1807
|
+
const prev = __runjsClassDefaultMeta.get(this) || {};
|
|
1808
|
+
__runjsClassDefaultMeta.set(this, __runjsDeepMerge(prev, meta));
|
|
1809
|
+
}
|
|
1810
|
+
__runjsDocCache.delete(this);
|
|
1811
|
+
}
|
|
1812
|
+
static getDoc(locale?: string): RunJSDocMeta {
|
|
1813
|
+
const self = this as any as Function;
|
|
1814
|
+
let cacheForClass = __runjsDocCache.get(self);
|
|
1815
|
+
const cacheKey = String(locale || 'default');
|
|
1816
|
+
if (cacheForClass && cacheForClass.has(cacheKey)) return cacheForClass.get(cacheKey)!;
|
|
1817
|
+
const chain: Function[] = [];
|
|
1818
|
+
let cur: any = self;
|
|
1819
|
+
while (cur && cur.prototype) {
|
|
1820
|
+
chain.unshift(cur);
|
|
1821
|
+
cur = Object.getPrototypeOf(cur);
|
|
1822
|
+
}
|
|
1823
|
+
let merged: RunJSDocMeta = {};
|
|
1824
|
+
for (const cls of chain) {
|
|
1825
|
+
merged = __runjsDeepMerge(merged, __runjsClassDefaultMeta.get(cls) || {});
|
|
1826
|
+
}
|
|
1827
|
+
if (locale) {
|
|
1828
|
+
for (const cls of chain) {
|
|
1829
|
+
const lmap = __runjsClassLocaleMeta.get(cls);
|
|
1830
|
+
if (lmap && lmap.has(locale)) {
|
|
1831
|
+
merged = __runjsDeepMerge(merged, lmap.get(locale));
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
if (!cacheForClass) {
|
|
1836
|
+
cacheForClass = new Map<string, RunJSDocMeta>();
|
|
1837
|
+
__runjsDocCache.set(self, cacheForClass);
|
|
1838
|
+
}
|
|
1839
|
+
cacheForClass.set(cacheKey, merged);
|
|
1840
|
+
return merged;
|
|
1841
|
+
}
|
|
1842
|
+
}
|