@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
|
@@ -12,6 +12,7 @@ import { FlowForkModelContext, FlowModelContext } from '../flowContext';
|
|
|
12
12
|
import type { IModelComponentProps } from '../types';
|
|
13
13
|
import { FlowModel } from './flowModel';
|
|
14
14
|
import { FlowEngine } from '../flowEngine';
|
|
15
|
+
import { uid } from 'uid/secure';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* ForkFlowModel 作为 FlowModel 的独立实例:
|
|
@@ -38,7 +39,7 @@ export class ForkFlowModel<TMaster extends FlowModel = FlowModel> {
|
|
|
38
39
|
private disposed = false;
|
|
39
40
|
|
|
40
41
|
/** fork 在 master.forks 中的索引 */
|
|
41
|
-
public readonly forkId:
|
|
42
|
+
public readonly forkId: string;
|
|
42
43
|
|
|
43
44
|
/** 需要与 master 共享的属性列表 */
|
|
44
45
|
private static readonly SHARED_PROPERTIES = ['stepParams', 'sortIndex'];
|
|
@@ -67,12 +68,12 @@ export class ForkFlowModel<TMaster extends FlowModel = FlowModel> {
|
|
|
67
68
|
// 不需要定义自己的属性了,现在是SHARED_PROPERTIES中指定的少数几个属性,所有属性设置时会自动添加自己的fork内的独有属性
|
|
68
69
|
#flowContext: FlowModelContext;
|
|
69
70
|
|
|
70
|
-
constructor(master: TMaster, initialProps: IModelComponentProps = {}, forkId
|
|
71
|
+
constructor(master: TMaster, initialProps: IModelComponentProps = {}, forkId?: string) {
|
|
71
72
|
void this.localProperties; // 避免 IDE 提示 unused
|
|
72
73
|
this.master = master;
|
|
73
74
|
this.uid = master.uid;
|
|
74
75
|
this.localProps = { ...initialProps };
|
|
75
|
-
this.forkId = forkId;
|
|
76
|
+
this.forkId = forkId || uid();
|
|
76
77
|
this.hidden = this.master.hidden;
|
|
77
78
|
|
|
78
79
|
define(this, {
|
|
@@ -206,6 +207,13 @@ export class ForkFlowModel<TMaster extends FlowModel = FlowModel> {
|
|
|
206
207
|
}
|
|
207
208
|
}
|
|
208
209
|
|
|
210
|
+
/**
|
|
211
|
+
* 清理局部 props,仅影响当前 fork
|
|
212
|
+
*/
|
|
213
|
+
clearProps() {
|
|
214
|
+
return (this.localProps = {});
|
|
215
|
+
}
|
|
216
|
+
|
|
209
217
|
/**
|
|
210
218
|
* render 依旧使用 master 的方法,但合并后的 props 需要透传
|
|
211
219
|
*/
|
|
@@ -224,10 +232,10 @@ export class ForkFlowModel<TMaster extends FlowModel = FlowModel> {
|
|
|
224
232
|
}
|
|
225
233
|
|
|
226
234
|
/**
|
|
227
|
-
*
|
|
235
|
+
* 事件缓存的作用域标识(fork 专用)。
|
|
228
236
|
*/
|
|
229
|
-
public
|
|
230
|
-
return String(this.forkId)
|
|
237
|
+
public getFlowCacheScope(eventName: string): string {
|
|
238
|
+
return `${String(eventName)}:${String(this.forkId)}`;
|
|
231
239
|
}
|
|
232
240
|
|
|
233
241
|
// onUnmount() {
|
|
@@ -250,9 +258,41 @@ export class ForkFlowModel<TMaster extends FlowModel = FlowModel> {
|
|
|
250
258
|
dispose() {
|
|
251
259
|
if (this.disposed) return;
|
|
252
260
|
this.disposed = true;
|
|
261
|
+
// 统一按事件缓存命名规则清理当前 fork 的所有缓存项(覆盖所有事件)
|
|
262
|
+
try {
|
|
263
|
+
const cache = this.flowEngine?.applyFlowCache;
|
|
264
|
+
if (cache && cache.size > 0) {
|
|
265
|
+
const uidSuffixes = [`:${this.uid}`, `-${this.uid}`];
|
|
266
|
+
const forkIdColon = `:${this.forkId}:`;
|
|
267
|
+
const forkIdHyphen = `-${this.forkId}-`;
|
|
268
|
+
|
|
269
|
+
for (const key of cache.keys()) {
|
|
270
|
+
// 事件缓存统一以 event: 或 event- 开头
|
|
271
|
+
const isEventCache = key.startsWith('event:') || key.startsWith('event-');
|
|
272
|
+
if (!isEventCache) continue;
|
|
273
|
+
|
|
274
|
+
// 仅删除当前 fork + 当前 uid 的键
|
|
275
|
+
const endMatches = uidSuffixes.some((s) => key.endsWith(s));
|
|
276
|
+
if (!endMatches) continue;
|
|
277
|
+
|
|
278
|
+
// 限定在去除 uid 后缀的范围内匹配 forkId 片段,避免误伤
|
|
279
|
+
let trimmed = key;
|
|
280
|
+
for (const suf of uidSuffixes) {
|
|
281
|
+
if (trimmed.endsWith(suf)) {
|
|
282
|
+
trimmed = trimmed.slice(0, -suf.length);
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (trimmed.includes(forkIdColon) || trimmed.includes(forkIdHyphen)) {
|
|
287
|
+
cache.delete(key);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
} catch {
|
|
292
|
+
// 忽略清理阶段异常,避免影响后续释放
|
|
293
|
+
}
|
|
294
|
+
|
|
253
295
|
if (this.master && (this.master as any).forks) {
|
|
254
|
-
const forkCacheKey = FlowEngine.generateApplyFlowCacheKey(`${this.forkId}`, 'all', this.uid);
|
|
255
|
-
this.flowEngine.applyFlowCache.delete(forkCacheKey);
|
|
256
296
|
(this.master as any).forks.delete(this as any);
|
|
257
297
|
}
|
|
258
298
|
// 从 master 的 forkCache 中移除自己
|
package/src/provider.tsx
CHANGED
|
@@ -14,6 +14,7 @@ import { FlowContextProvider } from './FlowContextProvider';
|
|
|
14
14
|
import { FlowEngine } from './flowEngine';
|
|
15
15
|
import { useDialog, useDrawer, usePage, usePopover } from './views';
|
|
16
16
|
import { FlowViewer } from './views/FlowView';
|
|
17
|
+
import { observer } from '@formily/reactive-react';
|
|
17
18
|
|
|
18
19
|
interface FlowEngineProviderProps {
|
|
19
20
|
engine: FlowEngine;
|
|
@@ -22,7 +23,7 @@ interface FlowEngineProviderProps {
|
|
|
22
23
|
|
|
23
24
|
const FlowEngineReactContext = createContext<FlowEngine | null>(null);
|
|
24
25
|
|
|
25
|
-
export const FlowEngineProvider: React.FC<FlowEngineProviderProps> = (props) => {
|
|
26
|
+
export const FlowEngineProvider: React.FC<FlowEngineProviderProps> = React.memo((props) => {
|
|
26
27
|
const { engine, children } = props;
|
|
27
28
|
if (!engine) {
|
|
28
29
|
throw new Error('FlowEngineProvider must be supplied with an engine.');
|
|
@@ -32,7 +33,9 @@ export const FlowEngineProvider: React.FC<FlowEngineProviderProps> = (props) =>
|
|
|
32
33
|
<FlowContextProvider context={engine.context}>{children}</FlowContextProvider>
|
|
33
34
|
</FlowEngineReactContext.Provider>
|
|
34
35
|
);
|
|
35
|
-
};
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
FlowEngineProvider.displayName = 'FlowEngineProvider';
|
|
36
39
|
|
|
37
40
|
export const FlowEngineGlobalsContextProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
38
41
|
const { modal, message, notification } = App.useApp();
|
|
@@ -72,20 +75,20 @@ export const FlowEngineGlobalsContextProvider: React.FC<{ children: React.ReactN
|
|
|
72
75
|
}, [engine, drawer, modal, message, notification, config, popover, token, dialog, embed]);
|
|
73
76
|
|
|
74
77
|
return (
|
|
75
|
-
|
|
78
|
+
<ConfigProvider {...config} locale={engine.context.locales?.antd} popupMatchSelectWidth={false}>
|
|
76
79
|
{children}
|
|
77
80
|
{contextHolder as any}
|
|
78
81
|
{popoverContextHolder as any}
|
|
79
82
|
{pageContextHolder as any}
|
|
80
83
|
{dialogContextHolder as any}
|
|
81
84
|
{/* The modal context is provided by App.useApp() */}
|
|
82
|
-
|
|
85
|
+
</ConfigProvider>
|
|
83
86
|
);
|
|
84
87
|
};
|
|
85
|
-
|
|
86
|
-
export const useFlowEngine = (): FlowEngine => {
|
|
88
|
+
// 不 throw Error 怎么处理?
|
|
89
|
+
export const useFlowEngine = ({ throwError = true } = {}): FlowEngine => {
|
|
87
90
|
const context = useContext(FlowEngineReactContext);
|
|
88
|
-
if (!context) {
|
|
91
|
+
if (!context && throwError) {
|
|
89
92
|
// This error should ideally not be hit if FlowEngineProvider is used correctly at the root
|
|
90
93
|
// and always supplied with an engine.
|
|
91
94
|
throw new Error(
|
|
@@ -113,6 +113,7 @@ export class MultiRecordResource<TDataItem = any> extends BaseRecordResource<TDa
|
|
|
113
113
|
async create(data: TDataItem, options?: AxiosRequestConfig): Promise<void> {
|
|
114
114
|
const config = this.mergeRequestConfig({ data }, this.createActionOptions, options);
|
|
115
115
|
await this.runAction('create', config);
|
|
116
|
+
this.emit('saved', data);
|
|
116
117
|
await this.refresh();
|
|
117
118
|
}
|
|
118
119
|
|
|
@@ -129,17 +130,38 @@ export class MultiRecordResource<TDataItem = any> extends BaseRecordResource<TDa
|
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
async update(filterByTk: string | number, data: Partial<TDataItem>, options?: AxiosRequestConfig): Promise<void> {
|
|
133
|
+
const collection = this.context.collection;
|
|
134
|
+
const filterTargetKey = collection?.filterTargetKey;
|
|
135
|
+
const tkData = collection?.getFilterByTK(this.context.record);
|
|
136
|
+
let result = data;
|
|
137
|
+
|
|
138
|
+
// 安全处理 filterTargetKey & tkData
|
|
139
|
+
if (collection && filterTargetKey) {
|
|
140
|
+
if (Array.isArray(filterTargetKey)) {
|
|
141
|
+
result = {
|
|
142
|
+
...data,
|
|
143
|
+
...(tkData || {}),
|
|
144
|
+
};
|
|
145
|
+
} else {
|
|
146
|
+
result = {
|
|
147
|
+
...data,
|
|
148
|
+
[filterTargetKey]: tkData,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
132
153
|
const config = this.mergeRequestConfig(
|
|
133
154
|
{
|
|
134
155
|
params: {
|
|
135
156
|
filterByTk,
|
|
136
157
|
},
|
|
137
|
-
data,
|
|
158
|
+
data: result,
|
|
138
159
|
},
|
|
139
160
|
this.updateActionOptions,
|
|
140
161
|
options,
|
|
141
162
|
);
|
|
142
163
|
await this.runAction('update', config);
|
|
164
|
+
this.emit('saved', data);
|
|
143
165
|
await this.refresh();
|
|
144
166
|
}
|
|
145
167
|
|
|
@@ -166,6 +188,11 @@ export class MultiRecordResource<TDataItem = any> extends BaseRecordResource<TDa
|
|
|
166
188
|
options,
|
|
167
189
|
);
|
|
168
190
|
await this.runAction('destroy', config);
|
|
191
|
+
const currentPage = this.getPage();
|
|
192
|
+
const lastPage = Math.ceil((this.getCount() - _.castArray(filterByTk).length) / this.getPageSize());
|
|
193
|
+
if (currentPage > lastPage) {
|
|
194
|
+
this.setPage(lastPage);
|
|
195
|
+
}
|
|
169
196
|
await this.refresh();
|
|
170
197
|
}
|
|
171
198
|
|
|
@@ -33,16 +33,34 @@ export class SingleRecordResource<TData = any> extends BaseRecordResource<TData>
|
|
|
33
33
|
async save(data: TData, options?: AxiosRequestConfig & { refresh?: boolean }): Promise<void> {
|
|
34
34
|
const config = this.mergeRequestConfig(this.saveActionOptions, _.omit(options, ['refresh']));
|
|
35
35
|
let actionName = 'create';
|
|
36
|
+
let result = data;
|
|
36
37
|
// 如果有 filterByTk,则表示是更新操作
|
|
37
38
|
if (!this.isNewRecord) {
|
|
38
39
|
config.params = config.params || {};
|
|
39
40
|
config.params.filterByTk = this.getFilterByTk();
|
|
40
41
|
actionName = 'update';
|
|
42
|
+
const collection = this.context.collection;
|
|
43
|
+
const filterTargetKey = collection?.filterTargetKey;
|
|
44
|
+
const tkData = collection?.getFilterByTK(this.context.record);
|
|
45
|
+
if (collection && filterTargetKey) {
|
|
46
|
+
if (Array.isArray(filterTargetKey)) {
|
|
47
|
+
result = {
|
|
48
|
+
...data,
|
|
49
|
+
...(tkData || {}),
|
|
50
|
+
};
|
|
51
|
+
} else {
|
|
52
|
+
result = {
|
|
53
|
+
...data,
|
|
54
|
+
[filterTargetKey]: tkData,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
41
58
|
}
|
|
42
59
|
await this.runAction(actionName, {
|
|
43
60
|
...config,
|
|
44
|
-
data,
|
|
61
|
+
data: result,
|
|
45
62
|
});
|
|
63
|
+
this.emit('saved', data);
|
|
46
64
|
if (options?.refresh !== false) {
|
|
47
65
|
await this.refresh();
|
|
48
66
|
}
|
|
@@ -11,6 +11,7 @@ import { observable } from '@formily/reactive';
|
|
|
11
11
|
import _ from 'lodash';
|
|
12
12
|
import { FlowContext, FlowEngineContext } from '../flowContext';
|
|
13
13
|
import { BaseRecordResource } from './baseRecordResource';
|
|
14
|
+
import { parseLiquidContext, transformSQL } from '@nocobase/utils/client';
|
|
14
15
|
|
|
15
16
|
type SQLRunOptions = {
|
|
16
17
|
bind?: Record<string, any>;
|
|
@@ -25,20 +26,6 @@ type SQLSaveOptions = {
|
|
|
25
26
|
dataSourceKey?: string;
|
|
26
27
|
};
|
|
27
28
|
|
|
28
|
-
function transformSQL(template: string) {
|
|
29
|
-
let index = 1;
|
|
30
|
-
const bind = {};
|
|
31
|
-
|
|
32
|
-
const sql = template.replace(/{{\s*([^}]+)\s*}}/g, (_, expr) => {
|
|
33
|
-
const key = `__var${index}`;
|
|
34
|
-
bind[key] = `{{${expr.trim()}}}`;
|
|
35
|
-
index++;
|
|
36
|
-
return `$${key}`;
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
return { sql, bind };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
29
|
export class FlowSQLRepository {
|
|
43
30
|
protected ctx: FlowEngineContext;
|
|
44
31
|
|
|
@@ -56,16 +43,17 @@ export class FlowSQLRepository {
|
|
|
56
43
|
}
|
|
57
44
|
|
|
58
45
|
async run(sql: string, options: SQLRunOptions = {}) {
|
|
59
|
-
const
|
|
60
|
-
const
|
|
46
|
+
const { sql: transformedSQL, bind, liquidContext } = await transformSQL(sql);
|
|
47
|
+
const resolved = await this.ctx.resolveJsonTemplate({ bind, liquidContext });
|
|
48
|
+
const parsedSQL = await parseLiquidContext(transformedSQL, resolved.liquidContext);
|
|
61
49
|
const { data } = await this.ctx.api.request({
|
|
62
50
|
method: 'POST',
|
|
63
51
|
url: 'flowSql:run',
|
|
64
52
|
data: {
|
|
65
|
-
sql:
|
|
53
|
+
sql: parsedSQL,
|
|
66
54
|
...options,
|
|
67
55
|
bind: {
|
|
68
|
-
...bind,
|
|
56
|
+
...resolved.bind,
|
|
69
57
|
...options.bind,
|
|
70
58
|
},
|
|
71
59
|
},
|
|
@@ -91,7 +79,7 @@ export class FlowSQLRepository {
|
|
|
91
79
|
uid,
|
|
92
80
|
},
|
|
93
81
|
});
|
|
94
|
-
const bind = await this.ctx.resolveJsonTemplate(response.data.data || {});
|
|
82
|
+
const { bind, liquidContext } = await this.ctx.resolveJsonTemplate(response.data.data || {});
|
|
95
83
|
const { data } = await this.ctx.api.request({
|
|
96
84
|
method: 'POST',
|
|
97
85
|
url: 'flowSql:runById',
|
|
@@ -100,8 +88,9 @@ export class FlowSQLRepository {
|
|
|
100
88
|
...options,
|
|
101
89
|
bind: {
|
|
102
90
|
...bind,
|
|
103
|
-
...options
|
|
91
|
+
...options?.bind,
|
|
104
92
|
},
|
|
93
|
+
liquidContext,
|
|
105
94
|
},
|
|
106
95
|
});
|
|
107
96
|
return data?.data;
|
|
@@ -233,20 +222,25 @@ export class SQLResource<TData = any> extends BaseRecordResource<TData> {
|
|
|
233
222
|
return this;
|
|
234
223
|
}
|
|
235
224
|
|
|
225
|
+
setLiquidContext(liquidContext: Record<string, any>) {
|
|
226
|
+
this.request.data.liquidContext = liquidContext;
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
|
|
236
230
|
async run() {
|
|
237
231
|
return this._debugEnabled ? await this.runBySQL() : await this.runById();
|
|
238
232
|
}
|
|
239
233
|
|
|
240
234
|
async runBySQL() {
|
|
241
235
|
const sql = this._sql;
|
|
242
|
-
const
|
|
243
|
-
const
|
|
236
|
+
const { sql: transformedSQL, bind, liquidContext } = await transformSQL(sql);
|
|
237
|
+
const resolved = await this.context.resolveJsonTemplate({ bind, liquidContext });
|
|
244
238
|
const options = _.cloneDeep({
|
|
245
239
|
method: 'post',
|
|
246
240
|
...this.getRefreshRequestOptions(),
|
|
247
241
|
});
|
|
248
|
-
options.data.
|
|
249
|
-
options.data.
|
|
242
|
+
options.data.sql = await parseLiquidContext(transformedSQL, resolved.liquidContext);
|
|
243
|
+
options.data.bind = resolved.bind;
|
|
250
244
|
return await this.runAction<TData, any>('run', options);
|
|
251
245
|
}
|
|
252
246
|
|
|
@@ -257,8 +251,9 @@ export class SQLResource<TData = any> extends BaseRecordResource<TData> {
|
|
|
257
251
|
uid: this.request.data.uid,
|
|
258
252
|
},
|
|
259
253
|
});
|
|
260
|
-
const bind = await this.context.resolveJsonTemplate(data);
|
|
254
|
+
const { bind, liquidContext } = await this.context.resolveJsonTemplate(data);
|
|
261
255
|
this.setBind(bind);
|
|
256
|
+
this.setLiquidContext(liquidContext);
|
|
262
257
|
return await this.runAction<TData, any>('runById', {
|
|
263
258
|
method: 'post',
|
|
264
259
|
...this.getRefreshRequestOptions(),
|
|
@@ -7,33 +7,40 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { FlowRunJSContext } from '
|
|
11
|
-
import { createSafeDocument, createSafeWindow } from '../../utils';
|
|
10
|
+
import { FlowRunJSContext } from '../../flowContext';
|
|
12
11
|
|
|
13
|
-
export class FormJSFieldItemRunJSContext extends FlowRunJSContext {
|
|
14
|
-
static injectDefaultGlobals() {
|
|
15
|
-
return { window: createSafeWindow(), document: createSafeDocument() };
|
|
16
|
-
}
|
|
17
|
-
constructor(delegate: any) {
|
|
18
|
-
super(delegate);
|
|
19
|
-
this.defineProperty('element', { get: () => (this as any)._delegate['element'] });
|
|
20
|
-
this.defineProperty('record', { get: () => (this as any)._delegate['record'] });
|
|
21
|
-
this.defineProperty('value', { get: () => (this as any)._delegate['value'] });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
12
|
+
export class FormJSFieldItemRunJSContext extends FlowRunJSContext {}
|
|
24
13
|
|
|
25
14
|
FormJSFieldItemRunJSContext.define({
|
|
26
15
|
label: 'FormJSFieldItem RunJS context',
|
|
27
16
|
properties: {
|
|
28
|
-
element:
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
element: `ElementProxy instance providing a safe DOM container for form field rendering.
|
|
18
|
+
Supports innerHTML, append, and other DOM manipulation methods.`,
|
|
19
|
+
value: `Current field value (read-only in display mode; in controlled scenarios, use setProps to modify).`,
|
|
20
|
+
record: `Current record data object (read-only).
|
|
21
|
+
Contains all field values of the parent record.`,
|
|
31
22
|
},
|
|
32
23
|
methods: {
|
|
33
|
-
onRefReady:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
onRefReady: `Wait for form field container DOM element to be ready before executing callback.
|
|
25
|
+
Parameters: (ref: React.RefObject, callback: (element: HTMLElement) => void, timeout?: number) => void`,
|
|
26
|
+
setProps: `Set form field properties programmatically.
|
|
27
|
+
Parameters: (fieldModel: any, props: { value?: any, disabled?: boolean, visible?: boolean }) => void
|
|
28
|
+
Example: ctx.setProps(fieldModel, { value: "new value" })`,
|
|
38
29
|
},
|
|
39
30
|
});
|
|
31
|
+
|
|
32
|
+
FormJSFieldItemRunJSContext.define(
|
|
33
|
+
{
|
|
34
|
+
label: '表单 JS 字段项 RunJS 上下文',
|
|
35
|
+
properties: {
|
|
36
|
+
element: 'ElementProxy,表单字段容器',
|
|
37
|
+
value: '字段值(展示模式为只读;受控场景用 setProps 修改)',
|
|
38
|
+
record: '当前记录(只读)',
|
|
39
|
+
},
|
|
40
|
+
methods: {
|
|
41
|
+
onRefReady: '容器就绪回调',
|
|
42
|
+
setProps: '设置表单项属性:`setProps(fieldModel, { value })`(由联动/表单上下文提供)',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{ locale: 'zh-CN' },
|
|
46
|
+
);
|
|
@@ -7,46 +7,58 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { FlowRunJSContext } from '
|
|
11
|
-
import { createSafeDocument, createSafeWindow } from '../../utils';
|
|
10
|
+
import { FlowRunJSContext } from '../../flowContext';
|
|
12
11
|
|
|
13
|
-
export class JSBlockRunJSContext extends FlowRunJSContext {
|
|
14
|
-
static injectDefaultGlobals() {
|
|
15
|
-
return { window: createSafeWindow(), document: createSafeDocument() };
|
|
16
|
-
}
|
|
17
|
-
constructor(delegate: any) {
|
|
18
|
-
super(delegate);
|
|
19
|
-
// 显式暴露本场景所需属性
|
|
20
|
-
this.defineProperty('element', { get: () => (this as any)._delegate['element'] });
|
|
21
|
-
this.defineProperty('record', { get: () => (this as any)._delegate['record'] });
|
|
22
|
-
this.defineProperty('value', { get: () => (this as any)._delegate['value'] });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
12
|
+
export class JSBlockRunJSContext extends FlowRunJSContext {}
|
|
25
13
|
|
|
26
14
|
JSBlockRunJSContext.define({
|
|
27
|
-
label: '
|
|
15
|
+
label: 'RunJS context',
|
|
28
16
|
properties: {
|
|
29
|
-
element:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
17
|
+
element: {
|
|
18
|
+
description: `ElementProxy instance providing a safe DOM container.
|
|
19
|
+
Supports innerHTML, append, and other DOM manipulation methods.
|
|
20
|
+
Use this to render content in the JS block.`,
|
|
21
|
+
detail: 'ElementProxy',
|
|
22
|
+
properties: {
|
|
23
|
+
innerHTML: 'Set or read the HTML content of the container element.',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
record: `Current record data object (read-only).
|
|
27
|
+
Available when the JS block is within a data block or detail view context.`,
|
|
28
|
+
value: 'Current value of the field or component, if available in the current context.',
|
|
29
|
+
React: 'React library',
|
|
30
|
+
antd: 'Ant Design library',
|
|
34
31
|
},
|
|
35
32
|
methods: {
|
|
36
|
-
onRefReady:
|
|
33
|
+
onRefReady: `Wait for container DOM element to be ready before executing callback.
|
|
34
|
+
Parameters: (ref: React.RefObject, callback: (element: HTMLElement) => void, timeout?: number) => void
|
|
35
|
+
Example: ctx.onRefReady(ctx.ref, (el) => { el.innerHTML = "Ready!" })`,
|
|
37
36
|
requireAsync: 'Load external library: `const lib = await ctx.requireAsync(url)`',
|
|
38
|
-
|
|
39
|
-
snipastes: {
|
|
40
|
-
'Render HTML': { $ref: 'scene/jsblock/render-basic', prefix: 'sn-jsb-html' },
|
|
41
|
-
'Render React': { $ref: 'scene/jsblock/render-react', prefix: 'sn-jsb-react' },
|
|
42
|
-
'Init ECharts': { $ref: 'libs/echarts-init', prefix: 'sn-echarts' },
|
|
43
|
-
'Render card': { $ref: 'scene/jsblock/render-card', prefix: 'sn-jsb-card' },
|
|
44
|
-
'Button handler': { $ref: 'scene/jsblock/render-button-handler', prefix: 'sn-jsb-button' },
|
|
45
|
-
'JSX mount': { $ref: 'scene/jsblock/jsx-mount', prefix: 'sn-jsx-mount' },
|
|
46
|
-
'JSX unmount': { $ref: 'scene/jsblock/jsx-unmount', prefix: 'sn-jsx-unmount' },
|
|
47
|
-
Notification: { $ref: 'global/notification-open', prefix: 'sn-notify' },
|
|
48
|
-
'Window open': { $ref: 'global/window-open', prefix: 'sn-window-open' },
|
|
49
|
-
'Add click listener': { $ref: 'scene/jsblock/add-event-listener', prefix: 'sn-jsb-click' },
|
|
50
|
-
'Append style': { $ref: 'scene/jsblock/append-style', prefix: 'sn-jsb-style' },
|
|
37
|
+
importAsync: 'Dynamically import ESM module: `const mod = await ctx.importAsync(url)`',
|
|
51
38
|
},
|
|
52
39
|
});
|
|
40
|
+
|
|
41
|
+
JSBlockRunJSContext.define(
|
|
42
|
+
{
|
|
43
|
+
label: 'RunJS 上下文',
|
|
44
|
+
properties: {
|
|
45
|
+
element: {
|
|
46
|
+
description: 'ElementProxy,安全的 DOM 容器,支持 innerHTML/append 等',
|
|
47
|
+
detail: 'ElementProxy',
|
|
48
|
+
properties: {
|
|
49
|
+
innerHTML: '读取或设置容器的 HTML 内容',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
record: '当前记录(只读,用于数据区块/详情等场景)',
|
|
53
|
+
value: '当前值(若存在)',
|
|
54
|
+
React: 'React 库',
|
|
55
|
+
antd: 'Ant Design 库',
|
|
56
|
+
},
|
|
57
|
+
methods: {
|
|
58
|
+
onRefReady: '容器 ref 就绪回调:\n```js\nctx.onRefReady(ctx.ref, el => { /* ... */ })\n```',
|
|
59
|
+
requireAsync: '加载外部库:`const lib = await ctx.requireAsync(url)`',
|
|
60
|
+
importAsync: '按 URL 动态导入 ESM 模块:`const mod = await ctx.importAsync(url)`',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{ locale: 'zh-CN' },
|
|
64
|
+
);
|
|
@@ -7,26 +7,25 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { FlowRunJSContext } from '
|
|
10
|
+
import { FlowRunJSContext } from '../../flowContext';
|
|
11
11
|
|
|
12
|
-
export class JSCollectionActionRunJSContext extends FlowRunJSContext {
|
|
13
|
-
constructor(delegate: any) {
|
|
14
|
-
super(delegate);
|
|
15
|
-
this.defineProperty('resource', { get: () => (this as any)._delegate['resource'] });
|
|
16
|
-
}
|
|
17
|
-
}
|
|
12
|
+
export class JSCollectionActionRunJSContext extends FlowRunJSContext {}
|
|
18
13
|
|
|
19
14
|
JSCollectionActionRunJSContext.define({
|
|
20
15
|
label: 'JSCollectionAction RunJS context',
|
|
21
16
|
properties: {
|
|
22
|
-
resource:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
runAction: 'Run action',
|
|
26
|
-
message: 'Message API',
|
|
27
|
-
},
|
|
28
|
-
snipastes: {
|
|
29
|
-
'Selected count': { $ref: 'scene/actions/collection-selected-count', prefix: 'sn-act-selected-count' },
|
|
30
|
-
'Iterate selected rows': { $ref: 'scene/actions/iterate-selected-rows', prefix: 'sn-act-iterate' },
|
|
17
|
+
resource: `Collection resource instance providing access to selected rows, pagination, and data operations.
|
|
18
|
+
Use ctx.resource.selectedRows to get selected records.
|
|
19
|
+
Use ctx.resource.pagination for page info.`,
|
|
31
20
|
},
|
|
32
21
|
});
|
|
22
|
+
|
|
23
|
+
JSCollectionActionRunJSContext.define(
|
|
24
|
+
{
|
|
25
|
+
label: 'JS 集合动作 RunJS 上下文',
|
|
26
|
+
properties: {
|
|
27
|
+
resource: '列表资源(包含选中行/分页信息等)',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{ locale: 'zh-CN' },
|
|
31
|
+
);
|
|
@@ -0,0 +1,58 @@
|
|
|
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 { FlowRunJSContext } from '../../flowContext';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* RunJS context for JSColumnModel (table custom column).
|
|
14
|
+
* Focused on per-row rendering with access to current record and cell element.
|
|
15
|
+
*/
|
|
16
|
+
export class JSColumnRunJSContext extends FlowRunJSContext {}
|
|
17
|
+
|
|
18
|
+
JSColumnRunJSContext.define({
|
|
19
|
+
label: 'JSColumn RunJS context',
|
|
20
|
+
properties: {
|
|
21
|
+
element:
|
|
22
|
+
'ElementProxy instance providing a safe DOM container for the current table cell. Supports innerHTML/append and basic DOM APIs.',
|
|
23
|
+
record: 'Current row record object (read-only).',
|
|
24
|
+
recordIndex: 'Index of the current row in the page (0-based).',
|
|
25
|
+
collection: 'Collection definition metadata (read-only).',
|
|
26
|
+
viewer:
|
|
27
|
+
'View controller providing dialog/drawer/embed helpers for interactions initiated from the cell (e.g., open details).',
|
|
28
|
+
React: 'React library',
|
|
29
|
+
antd: 'Ant Design library',
|
|
30
|
+
},
|
|
31
|
+
methods: {
|
|
32
|
+
onRefReady:
|
|
33
|
+
'Wait for cell DOM element to be ready before executing callback. Parameters: (ref, callback, timeout?) => void',
|
|
34
|
+
requireAsync: 'Load external library by URL: `const lib = await ctx.requireAsync(url)`',
|
|
35
|
+
importAsync: 'Dynamically import ESM module by URL: `const mod = await ctx.importAsync(url)`',
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
JSColumnRunJSContext.define(
|
|
40
|
+
{
|
|
41
|
+
label: 'JS 列 RunJS 上下文',
|
|
42
|
+
properties: {
|
|
43
|
+
element: 'ElementProxy,表格单元格的安全 DOM 容器,支持 innerHTML/append 等',
|
|
44
|
+
record: '当前行记录对象(只读)',
|
|
45
|
+
recordIndex: '当前行索引(从 0 开始)',
|
|
46
|
+
collection: '集合定义元数据(只读)',
|
|
47
|
+
viewer: '视图控制器,可用于在单元格中触发抽屉/对话框/内嵌等交互',
|
|
48
|
+
React: 'React 库',
|
|
49
|
+
antd: 'Ant Design 库',
|
|
50
|
+
},
|
|
51
|
+
methods: {
|
|
52
|
+
onRefReady: '等待单元格 DOM 就绪后执行回调。参数:(ref, callback, timeout?)',
|
|
53
|
+
requireAsync: '按 URL 异步加载外部库:`const lib = await ctx.requireAsync(url)`',
|
|
54
|
+
importAsync: '按 URL 动态导入 ESM 模块:`const mod = await ctx.importAsync(url)`',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{ locale: 'zh-CN' },
|
|
58
|
+
);
|