@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/lib/views/useDrawer.js
CHANGED
|
@@ -50,12 +50,32 @@ var import_DrawerComponent = __toESM(require("./DrawerComponent"));
|
|
|
50
50
|
var import_usePatchElement = __toESM(require("./usePatchElement"));
|
|
51
51
|
var import_provider = require("../provider");
|
|
52
52
|
var import_ViewScopedFlowEngine = require("../ViewScopedFlowEngine");
|
|
53
|
-
|
|
53
|
+
var import_variablesParams = require("../utils/variablesParams");
|
|
54
54
|
function useDrawer() {
|
|
55
55
|
const holderRef = React.useRef(null);
|
|
56
|
+
const drawerList = React.useMemo(() => import__.observable.shallow({ value: [] }), []);
|
|
57
|
+
const RenderNestedDrawer = React.memo((props) => {
|
|
58
|
+
const { index } = props;
|
|
59
|
+
const [RenderDrawer, setRenderDrawer] = React.useState(null);
|
|
60
|
+
React.useEffect(() => {
|
|
61
|
+
(0, import__.autorun)(() => {
|
|
62
|
+
const list = drawerList.value;
|
|
63
|
+
if (list[index] && RenderDrawer !== list[index]) {
|
|
64
|
+
setRenderDrawer(list[index]);
|
|
65
|
+
}
|
|
66
|
+
if (!list[index]) {
|
|
67
|
+
setRenderDrawer(null);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}, [RenderDrawer, index]);
|
|
71
|
+
if (!RenderDrawer) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
return /* @__PURE__ */ React.createElement(RenderDrawer, null, /* @__PURE__ */ React.createElement(RenderNestedDrawer, { index: index + 1 }));
|
|
75
|
+
});
|
|
76
|
+
RenderNestedDrawer.displayName = "RenderNestedDrawer";
|
|
56
77
|
const open = /* @__PURE__ */ __name((config, flowContext) => {
|
|
57
78
|
var _a, _b;
|
|
58
|
-
uuid += 1;
|
|
59
79
|
const drawerRef = React.createRef();
|
|
60
80
|
let closeFunc;
|
|
61
81
|
let resolvePromise;
|
|
@@ -64,7 +84,7 @@ function useDrawer() {
|
|
|
64
84
|
});
|
|
65
85
|
let currentFooter = null;
|
|
66
86
|
let currentHeader = null;
|
|
67
|
-
const FooterComponent = /* @__PURE__ */ __name(({ children
|
|
87
|
+
const FooterComponent = /* @__PURE__ */ __name(({ children }) => {
|
|
68
88
|
React.useEffect(() => {
|
|
69
89
|
var _a2;
|
|
70
90
|
currentFooter = children;
|
|
@@ -77,7 +97,7 @@ function useDrawer() {
|
|
|
77
97
|
}, [children]);
|
|
78
98
|
return null;
|
|
79
99
|
}, "FooterComponent");
|
|
80
|
-
const HeaderComponent = /* @__PURE__ */ __name((
|
|
100
|
+
const HeaderComponent = /* @__PURE__ */ __name((props) => {
|
|
81
101
|
React.useEffect(() => {
|
|
82
102
|
var _a2;
|
|
83
103
|
currentHeader = props;
|
|
@@ -90,6 +110,15 @@ function useDrawer() {
|
|
|
90
110
|
}, [props]);
|
|
91
111
|
return null;
|
|
92
112
|
}, "HeaderComponent");
|
|
113
|
+
const ctx = new import_flowContext.FlowContext();
|
|
114
|
+
const scopedEngine = (0, import_ViewScopedFlowEngine.createViewScopedEngine)(flowContext.engine);
|
|
115
|
+
ctx.defineProperty("engine", { value: scopedEngine });
|
|
116
|
+
ctx.addDelegate(scopedEngine.context);
|
|
117
|
+
if (config.inheritContext !== false) {
|
|
118
|
+
ctx.addDelegate(flowContext);
|
|
119
|
+
} else {
|
|
120
|
+
ctx.addDelegate(flowContext.engine.context);
|
|
121
|
+
}
|
|
93
122
|
const currentDrawer = {
|
|
94
123
|
type: "drawer",
|
|
95
124
|
inputArgs: config.inputArgs || {},
|
|
@@ -123,24 +152,19 @@ function useDrawer() {
|
|
|
123
152
|
currentHeader = header;
|
|
124
153
|
(_a2 = drawerRef.current) == null ? void 0 : _a2.setHeader(header);
|
|
125
154
|
}, "setHeader"),
|
|
126
|
-
navigation: (_a = config.inputArgs) == null ? void 0 : _a.navigation
|
|
155
|
+
navigation: (_a = config.inputArgs) == null ? void 0 : _a.navigation,
|
|
156
|
+
get record() {
|
|
157
|
+
return (0, import_variablesParams.getViewRecordFromParent)(flowContext, ctx);
|
|
158
|
+
}
|
|
127
159
|
};
|
|
128
|
-
const ctx = new import_flowContext.FlowContext();
|
|
129
160
|
ctx.defineProperty("view", {
|
|
130
161
|
get: /* @__PURE__ */ __name(() => currentDrawer, "get"),
|
|
131
|
-
meta:
|
|
132
|
-
resolveOnServer:
|
|
162
|
+
// meta: createViewMeta(ctx),
|
|
163
|
+
resolveOnServer: (0, import_variablesParams.createViewRecordResolveOnServer)(ctx, () => (0, import_variablesParams.getViewRecordFromParent)(flowContext, ctx))
|
|
133
164
|
});
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (config.inheritContext !== false) {
|
|
138
|
-
ctx.addDelegate(flowContext);
|
|
139
|
-
} else {
|
|
140
|
-
ctx.addDelegate(flowContext.engine.context);
|
|
141
|
-
}
|
|
142
|
-
const DrawerWithContext = (0, import__.observer)(
|
|
143
|
-
(props) => {
|
|
165
|
+
(0, import_createViewMeta.registerPopupVariable)(ctx, currentDrawer);
|
|
166
|
+
const DrawerWithContext = React.memo(
|
|
167
|
+
(0, import__.observer)((props) => {
|
|
144
168
|
var _a2, _b2, _c, _d;
|
|
145
169
|
const mountedRef = React.useRef(false);
|
|
146
170
|
const rawContent = typeof config.content === "function" ? config.content(currentDrawer, ctx) : config.content;
|
|
@@ -159,7 +183,7 @@ function useDrawer() {
|
|
|
159
183
|
ref: drawerRef,
|
|
160
184
|
...config,
|
|
161
185
|
footer: currentFooter,
|
|
162
|
-
header: currentHeader,
|
|
186
|
+
header: config.header || currentHeader,
|
|
163
187
|
hidden: (_d = (_c = config.inputArgs) == null ? void 0 : _c.hidden) == null ? void 0 : _d.value,
|
|
164
188
|
afterClose: () => {
|
|
165
189
|
var _a3;
|
|
@@ -167,18 +191,18 @@ function useDrawer() {
|
|
|
167
191
|
(_a3 = config.onClose) == null ? void 0 : _a3.call(config);
|
|
168
192
|
resolvePromise == null ? void 0 : resolvePromise(config.result);
|
|
169
193
|
scopedEngine.unlinkFromStack();
|
|
170
|
-
}
|
|
194
|
+
},
|
|
195
|
+
isMobile: ctx.isMobileLayout
|
|
171
196
|
},
|
|
172
197
|
content,
|
|
173
198
|
props.children
|
|
174
199
|
);
|
|
175
|
-
}
|
|
176
|
-
{
|
|
177
|
-
displayName: "DrawerWithContext"
|
|
178
|
-
}
|
|
200
|
+
})
|
|
179
201
|
);
|
|
180
|
-
|
|
181
|
-
|
|
202
|
+
DrawerWithContext.displayName = "DrawerWithContext";
|
|
203
|
+
const RenderDrawer = React.memo(({ children }) => /* @__PURE__ */ React.createElement(import_provider.FlowEngineProvider, { engine: scopedEngine }, /* @__PURE__ */ React.createElement(import_FlowContextProvider.FlowViewContextProvider, { context: ctx }, /* @__PURE__ */ React.createElement(DrawerWithContext, null, children))));
|
|
204
|
+
RenderDrawer.displayName = "RenderDrawer";
|
|
205
|
+
closeFunc = (_b = holderRef.current) == null ? void 0 : _b.patchElement(RenderDrawer);
|
|
182
206
|
return Object.assign(promise, currentDrawer);
|
|
183
207
|
}, "open");
|
|
184
208
|
const api = React.useMemo(() => ({ open }), []);
|
|
@@ -186,15 +210,10 @@ function useDrawer() {
|
|
|
186
210
|
React.forwardRef((props, ref) => {
|
|
187
211
|
const [elements, patchElement] = (0, import_usePatchElement.default)();
|
|
188
212
|
React.useImperativeHandle(ref, () => ({ patchElement }), [patchElement]);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return elements.reduceRight((children, renderElement) => {
|
|
194
|
-
return renderElement(children);
|
|
195
|
-
}, null);
|
|
196
|
-
}, "renderNestedElements");
|
|
197
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, renderNestedElements());
|
|
213
|
+
React.useEffect(() => {
|
|
214
|
+
drawerList.value = elements;
|
|
215
|
+
}, [elements]);
|
|
216
|
+
return /* @__PURE__ */ React.createElement(RenderNestedDrawer, { index: 0 });
|
|
198
217
|
})
|
|
199
218
|
);
|
|
200
219
|
return [api, /* @__PURE__ */ React.createElement(ElementsHolder, { key: "drawer-holder", ref: holderRef })];
|
package/lib/views/usePage.d.ts
CHANGED
|
@@ -9,24 +9,25 @@
|
|
|
9
9
|
import React from 'react';
|
|
10
10
|
export declare function usePage(): (React.JSX.Element | {
|
|
11
11
|
open: (config: any, flowContext: any) => Promise<unknown> & {
|
|
12
|
-
type:
|
|
12
|
+
type: "embed";
|
|
13
13
|
inputArgs: any;
|
|
14
14
|
preventClose: boolean;
|
|
15
15
|
destroy: () => void;
|
|
16
16
|
update: (newConfig: any) => void;
|
|
17
17
|
close: (result?: any, force?: boolean) => void;
|
|
18
|
-
Header:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
children
|
|
24
|
-
}
|
|
18
|
+
Header: React.FC<{
|
|
19
|
+
title?: React.ReactNode;
|
|
20
|
+
extra?: React.ReactNode;
|
|
21
|
+
}>;
|
|
22
|
+
Footer: React.FC<{
|
|
23
|
+
children?: React.ReactNode;
|
|
24
|
+
}>;
|
|
25
25
|
setFooter: (footer: React.ReactNode) => void;
|
|
26
26
|
setHeader: (header: {
|
|
27
27
|
title?: React.ReactNode;
|
|
28
28
|
extra?: React.ReactNode;
|
|
29
29
|
}) => void;
|
|
30
30
|
navigation: any;
|
|
31
|
+
readonly record: unknown;
|
|
31
32
|
};
|
|
32
33
|
})[];
|
package/lib/views/usePage.js
CHANGED
|
@@ -50,6 +50,7 @@ var import_PageComponent = require("./PageComponent");
|
|
|
50
50
|
var import_usePatchElement = __toESM(require("./usePatchElement"));
|
|
51
51
|
var import_provider = require("../provider");
|
|
52
52
|
var import_ViewScopedFlowEngine = require("../ViewScopedFlowEngine");
|
|
53
|
+
var import_variablesParams = require("../utils/variablesParams");
|
|
53
54
|
let uuid = 0;
|
|
54
55
|
const PageElementsHolder = import_react.default.memo(
|
|
55
56
|
import_react.default.forwardRef((props, ref) => {
|
|
@@ -69,7 +70,7 @@ function usePage() {
|
|
|
69
70
|
const promise = new Promise((resolve) => {
|
|
70
71
|
resolvePromise = resolve;
|
|
71
72
|
});
|
|
72
|
-
const FooterComponent = /* @__PURE__ */ __name(({ children
|
|
73
|
+
const FooterComponent = /* @__PURE__ */ __name(({ children }) => {
|
|
73
74
|
import_react.default.useEffect(() => {
|
|
74
75
|
var _a2;
|
|
75
76
|
(_a2 = pageRef.current) == null ? void 0 : _a2.setFooter(children);
|
|
@@ -80,7 +81,7 @@ function usePage() {
|
|
|
80
81
|
}, [children]);
|
|
81
82
|
return null;
|
|
82
83
|
}, "FooterComponent");
|
|
83
|
-
const HeaderComponent = /* @__PURE__ */ __name((
|
|
84
|
+
const HeaderComponent = /* @__PURE__ */ __name((props) => {
|
|
84
85
|
import_react.default.useEffect(() => {
|
|
85
86
|
var _a2;
|
|
86
87
|
(_a2 = pageRef.current) == null ? void 0 : _a2.setHeader(props);
|
|
@@ -92,6 +93,15 @@ function usePage() {
|
|
|
92
93
|
return null;
|
|
93
94
|
}, "HeaderComponent");
|
|
94
95
|
const { target, content, preventClose, inheritContext = true, ...restConfig } = config;
|
|
96
|
+
const ctx = new import_flowContext.FlowContext();
|
|
97
|
+
const scopedEngine = (0, import_ViewScopedFlowEngine.createViewScopedEngine)(flowContext.engine);
|
|
98
|
+
ctx.defineProperty("engine", { value: scopedEngine });
|
|
99
|
+
ctx.addDelegate(scopedEngine.context);
|
|
100
|
+
if (inheritContext) {
|
|
101
|
+
ctx.addDelegate(flowContext);
|
|
102
|
+
} else {
|
|
103
|
+
ctx.addDelegate(flowContext.engine.context);
|
|
104
|
+
}
|
|
95
105
|
const currentPage = {
|
|
96
106
|
type: "embed",
|
|
97
107
|
inputArgs: config.inputArgs || {},
|
|
@@ -123,22 +133,18 @@ function usePage() {
|
|
|
123
133
|
var _a2;
|
|
124
134
|
(_a2 = pageRef.current) == null ? void 0 : _a2.setHeader(header);
|
|
125
135
|
}, "setHeader"),
|
|
126
|
-
navigation: (_a = config.inputArgs) == null ? void 0 : _a.navigation
|
|
136
|
+
navigation: (_a = config.inputArgs) == null ? void 0 : _a.navigation,
|
|
137
|
+
get record() {
|
|
138
|
+
return (0, import_variablesParams.getViewRecordFromParent)(flowContext, ctx);
|
|
139
|
+
}
|
|
127
140
|
};
|
|
128
|
-
const ctx = new import_flowContext.FlowContext();
|
|
129
141
|
ctx.defineProperty("view", {
|
|
130
142
|
get: /* @__PURE__ */ __name(() => currentPage, "get"),
|
|
131
|
-
meta:
|
|
132
|
-
|
|
143
|
+
// meta: createViewMeta(ctx),
|
|
144
|
+
// 仅当访问关联字段或前端无本地记录数据时,才交给服务端解析
|
|
145
|
+
resolveOnServer: (0, import_variablesParams.createViewRecordResolveOnServer)(ctx, () => (0, import_variablesParams.getViewRecordFromParent)(flowContext, ctx))
|
|
133
146
|
});
|
|
134
|
-
|
|
135
|
-
ctx.defineProperty("engine", { value: scopedEngine });
|
|
136
|
-
ctx.addDelegate(scopedEngine.context);
|
|
137
|
-
if (inheritContext) {
|
|
138
|
-
ctx.addDelegate(flowContext);
|
|
139
|
-
} else {
|
|
140
|
-
ctx.addDelegate(flowContext.engine.context);
|
|
141
|
-
}
|
|
147
|
+
(0, import_createViewMeta.registerPopupVariable)(ctx, currentPage);
|
|
142
148
|
const PageWithContext = (0, import__.observer)(
|
|
143
149
|
() => {
|
|
144
150
|
var _a2, _b2, _c2, _d;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/flow-engine",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.41",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A standalone flow engine for NocoBase, managing workflows, models, and actions.",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@formily/antd-v5": "1.x",
|
|
10
10
|
"@formily/reactive": "2.x",
|
|
11
|
-
"@nocobase/sdk": "
|
|
11
|
+
"@nocobase/sdk": "2.0.0-alpha.41",
|
|
12
|
+
"@nocobase/shared": "2.0.0-alpha.41",
|
|
12
13
|
"ahooks": "^3.7.2",
|
|
14
|
+
"dayjs": "^1.11.9",
|
|
13
15
|
"dompurify": "^3.0.2",
|
|
14
16
|
"lodash": "^4.x",
|
|
15
17
|
"pino": "^8.0.0",
|
|
@@ -17,6 +19,7 @@
|
|
|
17
19
|
"slate": "^0.103.0",
|
|
18
20
|
"slate-history": "^0.109.0",
|
|
19
21
|
"slate-react": "^0.110.3",
|
|
22
|
+
"sucrase": "^3.35.0",
|
|
20
23
|
"uid": "^2.0.2"
|
|
21
24
|
},
|
|
22
25
|
"peerDependencies": {
|
|
@@ -33,5 +36,5 @@
|
|
|
33
36
|
],
|
|
34
37
|
"author": "NocoBase Team",
|
|
35
38
|
"license": "AGPL-3.0",
|
|
36
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "889e81eef0280c2e45571bd0a4b2db6aa004f8c1"
|
|
37
40
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { FlowEngine } from './flowEngine';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* BlockScopedFlowEngine(区块作用域引擎)
|
|
14
|
+
*
|
|
15
|
+
* 设计目标:
|
|
16
|
+
* - 仅在“区块”作用域内隔离“模型实例表”和“事件缓存”;
|
|
17
|
+
* - 其余能力(动作/事件/模型类/资源/仓库/设置/日志/翻译等)全部直接代理到父引擎;
|
|
18
|
+
* - 使用 Proxy 实现“最小代理”,保持与父引擎的全局一致性。
|
|
19
|
+
*
|
|
20
|
+
* 注意:
|
|
21
|
+
* - 本地化的字段仅有:`_modelInstances`、`_applyFlowCache`、`executor`、`context`、栈指针;
|
|
22
|
+
* - 其它字段/方法均通过 Proxy 转发到父引擎;
|
|
23
|
+
* - 这样可满足“同一 uid 的模型可在不同区块隔离出现(实例/缓存隔离)”与“共享全局注册/仓库”的诉求。
|
|
24
|
+
*/
|
|
25
|
+
export function createBlockScopedEngine(parent: FlowEngine): FlowEngine {
|
|
26
|
+
const local = new FlowEngine();
|
|
27
|
+
if (parent.modelRepository) {
|
|
28
|
+
local.setModelRepository(parent.modelRepository);
|
|
29
|
+
}
|
|
30
|
+
// 继承父级上下文能力
|
|
31
|
+
local.context.addDelegate(parent.context);
|
|
32
|
+
|
|
33
|
+
// 覆盖 unlinkFromStack:BlockScoped 引擎被移除时,修复前后指针,避免“截断”后续视图/作用域
|
|
34
|
+
const originalUnlink = local.unlinkFromStack.bind(local);
|
|
35
|
+
local.unlinkFromStack = function () {
|
|
36
|
+
// 修复指针:prev -> next,next -> prev,然后清理自身指针
|
|
37
|
+
// 若不这么做,移除位于中间的 block 引擎会导致后续整段链丢失
|
|
38
|
+
const prev = (local as any)._previousEngine as FlowEngine | undefined;
|
|
39
|
+
const next = (local as any)._nextEngine as FlowEngine | undefined;
|
|
40
|
+
if (prev) (prev as any)._nextEngine = next;
|
|
41
|
+
if (next) (next as any)._previousEngine = prev;
|
|
42
|
+
(local as any)._previousEngine = undefined as any;
|
|
43
|
+
(local as any)._nextEngine = undefined as any;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// 默认全部代理到父引擎,只有少数字段(实例/缓存/执行器/上下文/链表指针)使用本地值
|
|
47
|
+
const localOnly = new Set<keyof FlowEngine | string>([
|
|
48
|
+
'_modelInstances',
|
|
49
|
+
'_applyFlowCache',
|
|
50
|
+
'executor',
|
|
51
|
+
'context',
|
|
52
|
+
'previousEngine',
|
|
53
|
+
'nextEngine',
|
|
54
|
+
// 栈指针维护方法需要在本地执行,而非代理到父引擎
|
|
55
|
+
'unlinkFromStack',
|
|
56
|
+
'linkAfter',
|
|
57
|
+
'_previousEngine',
|
|
58
|
+
'_nextEngine',
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
const handler: ProxyHandler<FlowEngine> = {
|
|
62
|
+
get(target, prop: string, receiver) {
|
|
63
|
+
if (localOnly.has(prop)) {
|
|
64
|
+
return Reflect.get(target, prop, receiver);
|
|
65
|
+
}
|
|
66
|
+
const value = Reflect.get(parent, prop, receiver);
|
|
67
|
+
if (prop === 'registerModels' && typeof value === 'function') {
|
|
68
|
+
return value.bind(parent);
|
|
69
|
+
}
|
|
70
|
+
return value;
|
|
71
|
+
},
|
|
72
|
+
set(target, prop: string, value: unknown) {
|
|
73
|
+
if (localOnly.has(prop)) {
|
|
74
|
+
return Reflect.set(target, prop, value);
|
|
75
|
+
}
|
|
76
|
+
return Reflect.set(parent, prop, value);
|
|
77
|
+
},
|
|
78
|
+
has(target, prop: string) {
|
|
79
|
+
return prop in target || prop in parent;
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// 与父引擎形成栈式关系,便于在多层作用域间进行全局查找
|
|
84
|
+
local.linkAfter(parent);
|
|
85
|
+
return new Proxy(local, handler) as FlowEngine;
|
|
86
|
+
}
|
|
@@ -18,13 +18,15 @@ export function FlowContextProvider(props: { children: React.ReactNode; context:
|
|
|
18
18
|
return <FlowReactContext.Provider value={props.context}>{props.children}</FlowReactContext.Provider>;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export
|
|
21
|
+
export const FlowViewContextProvider = React.memo((props: { children: React.ReactNode; context: FlowContext }) => {
|
|
22
22
|
return (
|
|
23
23
|
<FlowViewContext.Provider value={props.context}>
|
|
24
24
|
<FlowReactContext.Provider value={props.context}>{props.children}</FlowReactContext.Provider>
|
|
25
25
|
</FlowViewContext.Provider>
|
|
26
26
|
);
|
|
27
|
-
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
FlowViewContextProvider.displayName = 'FlowViewContextProvider';
|
|
28
30
|
|
|
29
31
|
export function useFlowContext<T = FlowEngineContext>() {
|
|
30
32
|
return useContext(FlowReactContext) as T;
|
package/src/JSRunner.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { FlowEngine } from './flowEngine';
|
|
|
13
13
|
* ViewScopedFlowEngine(视图作用域引擎)
|
|
14
14
|
*
|
|
15
15
|
* 设计目标:
|
|
16
|
-
* - 仅在视图(dialog/drawer/embed
|
|
16
|
+
* - 仅在视图(dialog/drawer/embed)作用域内隔离“模型实例表”和“事件缓存”;
|
|
17
17
|
* - 其余能力(动作/事件/模型类/资源/仓库/设置/日志/翻译等)全部直接代理到父引擎;
|
|
18
18
|
* - 使用 Proxy 实现“最小代理”,保持与父引擎的全局一致性。
|
|
19
19
|
*
|
|
@@ -29,6 +29,14 @@ export function createViewScopedEngine(parent: FlowEngine): FlowEngine {
|
|
|
29
29
|
}
|
|
30
30
|
local.context.addDelegate(parent.context);
|
|
31
31
|
|
|
32
|
+
// 视图引擎关闭时,主动释放本地调度器以避免残留任务与引用
|
|
33
|
+
const originalUnlink = local.unlinkFromStack.bind(local);
|
|
34
|
+
local.unlinkFromStack = function () {
|
|
35
|
+
// 释放本地调度器与其事件监听,避免残留引用
|
|
36
|
+
local.disposeScheduler?.();
|
|
37
|
+
return originalUnlink();
|
|
38
|
+
};
|
|
39
|
+
|
|
32
40
|
// 默认全部代理到父引擎,只有少数字段(实例/缓存/执行器/上下文/链表指针)使用本地值
|
|
33
41
|
const localOnly = new Set<keyof FlowEngine | string>([
|
|
34
42
|
'_modelInstances',
|
|
@@ -37,6 +45,12 @@ export function createViewScopedEngine(parent: FlowEngine): FlowEngine {
|
|
|
37
45
|
'context',
|
|
38
46
|
'previousEngine',
|
|
39
47
|
'nextEngine',
|
|
48
|
+
// 调度器与事件总线局部化
|
|
49
|
+
'emitter',
|
|
50
|
+
'_modelOperationScheduler',
|
|
51
|
+
'getScheduler',
|
|
52
|
+
'scheduleModelOperation',
|
|
53
|
+
'disposeScheduler',
|
|
40
54
|
// 栈指针维护方法需要在本地执行,而非代理到父引擎
|
|
41
55
|
'unlinkFromStack',
|
|
42
56
|
'linkAfter',
|
|
@@ -7,86 +7,95 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
10
11
|
import { JSRunner } from '../JSRunner';
|
|
11
12
|
|
|
12
13
|
describe('JSRunner', () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return x + 5;
|
|
18
|
-
`);
|
|
19
|
-
expect(result.success).toBe(true);
|
|
20
|
-
expect(result.value).toBe(15);
|
|
14
|
+
let originalSearch: string;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
originalSearch = globalThis.location?.search || '';
|
|
21
18
|
});
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
// 恢复 URL 查询参数,避免影响其他用例
|
|
22
|
+
try {
|
|
23
|
+
if (typeof window !== 'undefined' && typeof window.history?.replaceState === 'function') {
|
|
24
|
+
window.history.replaceState({}, '', originalSearch || '');
|
|
25
|
+
}
|
|
26
|
+
} catch (_) {
|
|
27
|
+
// ignore
|
|
28
|
+
}
|
|
29
|
+
vi.restoreAllMocks();
|
|
28
30
|
});
|
|
29
31
|
|
|
30
|
-
it('
|
|
32
|
+
it('executes simple code and returns value', async () => {
|
|
31
33
|
const runner = new JSRunner();
|
|
32
|
-
const result = await runner.run(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
`);
|
|
36
|
-
expect(result.success).toBe(false);
|
|
37
|
-
expect(result.error).toBeInstanceOf(Error);
|
|
38
|
-
expect(result.error.message).toBe('Test error');
|
|
34
|
+
const result = await runner.run('return 1 + 2 + 3');
|
|
35
|
+
expect(result.success).toBe(true);
|
|
36
|
+
expect(result.value).toBe(6);
|
|
39
37
|
});
|
|
40
38
|
|
|
41
|
-
it('
|
|
42
|
-
const runner = new JSRunner({
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
expect(
|
|
50
|
-
expect(
|
|
39
|
+
it('injects custom globals and supports register()', async () => {
|
|
40
|
+
const runner = new JSRunner({ globals: { foo: 42 } });
|
|
41
|
+
const res1 = await runner.run('return foo');
|
|
42
|
+
expect(res1.success).toBe(true);
|
|
43
|
+
expect(res1.value).toBe(42);
|
|
44
|
+
|
|
45
|
+
runner.register('bar', 'baz');
|
|
46
|
+
const res2 = await runner.run('return bar');
|
|
47
|
+
expect(res2.success).toBe(true);
|
|
48
|
+
expect(res2.value).toBe('baz');
|
|
51
49
|
});
|
|
52
50
|
|
|
53
|
-
it('
|
|
51
|
+
it('exposes console in sandbox by default', async () => {
|
|
54
52
|
const runner = new JSRunner();
|
|
55
|
-
runner.
|
|
56
|
-
const result = await runner.run(`
|
|
57
|
-
return globalVar + 8;
|
|
58
|
-
`);
|
|
53
|
+
const result = await runner.run('return typeof console !== "undefined"');
|
|
59
54
|
expect(result.success).toBe(true);
|
|
60
|
-
expect(result.value).toBe(
|
|
55
|
+
expect(result.value).toBe(true);
|
|
61
56
|
});
|
|
62
57
|
|
|
63
|
-
it('
|
|
58
|
+
it('supports timers (setTimeout) inside evaluated code', async () => {
|
|
64
59
|
const runner = new JSRunner();
|
|
65
60
|
const result = await runner.run(`
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
69
|
-
const data = await fetchData();
|
|
70
|
-
return data + 50;
|
|
61
|
+
return new Promise((resolve) => {
|
|
62
|
+
setTimeout(() => resolve('ok'), 20);
|
|
63
|
+
});
|
|
71
64
|
`);
|
|
72
65
|
expect(result.success).toBe(true);
|
|
73
|
-
expect(result.value).toBe(
|
|
66
|
+
expect(result.value).toBe('ok');
|
|
74
67
|
});
|
|
75
68
|
|
|
76
|
-
it('
|
|
69
|
+
it('handles thrown errors and marks as non-timeout', async () => {
|
|
70
|
+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
77
71
|
const runner = new JSRunner();
|
|
78
|
-
const result = await runner.run('');
|
|
79
|
-
expect(result.success).toBe(
|
|
80
|
-
expect(result.
|
|
72
|
+
const result = await runner.run('throw new Error("boom")');
|
|
73
|
+
expect(result.success).toBe(false);
|
|
74
|
+
expect(result.timeout).toBe(false);
|
|
75
|
+
expect(result.error).toBeInstanceOf(Error);
|
|
76
|
+
expect((result.error as Error).message).toBe('boom');
|
|
77
|
+
expect(spy).toHaveBeenCalled();
|
|
81
78
|
});
|
|
82
79
|
|
|
83
|
-
it('
|
|
84
|
-
const runner = new JSRunner();
|
|
80
|
+
it('respects timeout setting and marks timeout=true', async () => {
|
|
81
|
+
const runner = new JSRunner({ timeoutMs: 10 });
|
|
85
82
|
const result = await runner.run(`
|
|
86
|
-
|
|
87
|
-
return undefined;
|
|
83
|
+
return new Promise((resolve) => setTimeout(() => resolve('late'), 100));
|
|
88
84
|
`);
|
|
85
|
+
expect(result.success).toBe(false);
|
|
86
|
+
expect(result.timeout).toBe(true);
|
|
87
|
+
expect(result.error).toBeInstanceOf(Error);
|
|
88
|
+
expect((result.error as Error).message).toBe('Execution timed out');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('skips execution when URL contains skipRunJs=true', async () => {
|
|
92
|
+
// 模拟预览模式下通过 URL 参数跳过代码执行
|
|
93
|
+
if (typeof window !== 'undefined' && typeof window.history?.pushState === 'function') {
|
|
94
|
+
window.history.pushState({}, '', '?skipRunJs=true');
|
|
95
|
+
}
|
|
96
|
+
const runner = new JSRunner();
|
|
97
|
+
const result = await runner.run('throw new Error("should not run")');
|
|
89
98
|
expect(result.success).toBe(true);
|
|
90
|
-
expect(result.value).
|
|
99
|
+
expect(result.value).toBeNull();
|
|
91
100
|
});
|
|
92
101
|
});
|