@nocobase/flow-engine 2.0.0-alpha.2 → 2.0.0-alpha.20
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 +2 -2
- package/lib/JSRunner.js +3 -0
- package/lib/ViewScopedFlowEngine.d.ts +1 -1
- package/lib/components/FieldModelRenderer.js +10 -4
- 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 +2 -5
- package/lib/components/FlowModelRenderer.js +16 -47
- package/lib/components/FormItem.js +5 -1
- package/lib/{runjs-context/snippets/global/requireAsync.snippet.d.ts → components/dnd/findModelUidPosition.d.ts} +4 -7
- package/lib/{runjs-context/snippets/scene/jsblock/jsx-mount.snippet.js → components/dnd/findModelUidPosition.js} +23 -19
- package/lib/components/dnd/gridDragPlanner.d.ts +130 -0
- package/lib/components/dnd/gridDragPlanner.js +497 -0
- package/lib/components/dnd/index.d.ts +2 -2
- package/lib/components/dnd/index.js +5 -5
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +7 -1
- package/lib/components/variables/VariableInput.js +16 -2
- package/lib/components/variables/VariableTag.js +43 -2
- package/lib/components/variables/types.d.ts +2 -0
- package/lib/data-source/index.d.ts +12 -4
- package/lib/data-source/index.js +18 -12
- package/lib/data-source/sortCollectionsByInherits.d.ts +10 -0
- package/lib/data-source/sortCollectionsByInherits.js +71 -0
- package/lib/executor/FlowExecutor.d.ts +4 -5
- package/lib/executor/FlowExecutor.js +122 -94
- package/lib/flowContext.d.ts +33 -5
- package/lib/flowContext.js +145 -74
- package/lib/flowEngine.d.ts +8 -1
- package/lib/flowEngine.js +12 -2
- package/lib/flowSettings.d.ts +2 -1
- package/lib/flowSettings.js +7 -3
- package/lib/hooks/useApplyAutoFlows.js +2 -1
- package/lib/index.d.ts +6 -1
- package/lib/index.js +29 -3
- package/lib/models/CollectionFieldModel.d.ts +2 -0
- package/lib/models/CollectionFieldModel.js +43 -3
- package/lib/models/flowModel.d.ts +28 -29
- package/lib/models/flowModel.js +110 -88
- package/lib/models/forkFlowModel.d.ts +2 -2
- package/lib/models/forkFlowModel.js +29 -6
- package/lib/provider.d.ts +3 -1
- package/lib/provider.js +7 -5
- package/lib/resources/multiRecordResource.js +2 -0
- package/lib/resources/singleRecordResource.js +1 -0
- 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 +169 -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 +160 -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-button-handler.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/{jsblock → block}/render-button-handler.snippet.js +12 -6
- 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 +72 -0
- 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 +12 -11
- 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 +100 -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 +85 -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/types.d.ts +15 -3
- package/lib/types.js +4 -3
- package/lib/utils/buildSettingsViewInputArgs.d.ts +19 -0
- package/lib/utils/buildSettingsViewInputArgs.js +75 -0
- package/lib/utils/index.d.ts +3 -2
- package/lib/utils/index.js +5 -2
- package/lib/utils/params-resolvers.js +2 -2
- package/lib/utils/safeGlobals.d.ts +5 -3
- package/lib/utils/safeGlobals.js +40 -0
- package/lib/utils/serverContextParams.d.ts +1 -0
- package/lib/utils/variablesParams.d.ts +9 -5
- package/lib/utils/variablesParams.js +47 -36
- package/lib/views/PageComponent.js +2 -1
- package/lib/views/createViewMeta.d.ts +29 -1
- package/lib/views/createViewMeta.js +321 -72
- package/lib/views/index.d.ts +1 -0
- package/lib/views/index.js +3 -0
- package/lib/views/useDialog.d.ts +8 -8
- package/lib/views/useDialog.js +8 -7
- package/lib/views/useDrawer.d.ts +8 -8
- package/lib/views/useDrawer.js +40 -26
- package/lib/views/usePage.d.ts +8 -8
- package/lib/views/usePage.js +8 -7
- package/package.json +4 -3
- package/src/BlockScopedFlowEngine.ts +86 -0
- package/src/FlowContextProvider.tsx +4 -2
- package/src/JSRunner.ts +3 -0
- package/src/ViewScopedFlowEngine.ts +1 -1
- package/src/__tests__/JSRunner.test.ts +62 -53
- package/src/__tests__/blockScopedFlowEngine.test.ts +154 -0
- package/src/__tests__/flow-engine.test.ts +3 -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__/globalFlowRegistry.test.ts +1 -1
- 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 +449 -0
- package/src/__tests__/runjsSnippets.test.ts +140 -0
- package/src/__tests__/viewScopedFlowEngine.test.ts +3 -3
- package/src/components/DynamicFlowsEditor.tsx +3 -4
- package/src/components/FieldModelRenderer.tsx +16 -5
- package/src/components/FieldSkeleton.tsx +27 -0
- package/src/components/FlowContextSelector.tsx +6 -2
- package/src/components/FlowModelRenderer.tsx +30 -78
- package/src/components/FormItem.tsx +8 -1
- package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +5 -5
- package/src/components/__tests__/gridDragPlanner.test.ts +494 -0
- package/src/components/dnd/README.md +149 -0
- package/src/components/dnd/findModelUidPosition.ts +26 -0
- package/src/components/dnd/gridDragPlanner.ts +659 -0
- package/src/components/dnd/index.tsx +3 -3
- package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +14 -1
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +1 -0
- package/src/components/variables/VariableInput.tsx +22 -2
- 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 +16 -10
- package/src/data-source/sortCollectionsByInherits.ts +61 -0
- package/src/executor/FlowExecutor.ts +160 -114
- package/src/executor/__tests__/flowExecutor.test.ts +151 -5
- package/src/flowContext.ts +196 -93
- package/src/flowEngine.ts +13 -2
- package/src/flowSettings.ts +8 -3
- package/src/hooks/useApplyAutoFlows.ts +3 -1
- package/src/index.ts +11 -1
- package/src/models/CollectionFieldModel.tsx +43 -4
- package/src/models/__tests__/flowModel.getFlows.sort.test.ts +4 -4
- package/src/models/__tests__/flowModel.test.ts +218 -95
- package/src/models/flowModel.tsx +146 -122
- package/src/models/forkFlowModel.ts +37 -5
- package/src/provider.tsx +10 -7
- package/src/resources/multiRecordResource.ts +2 -0
- package/src/resources/singleRecordResource.ts +1 -0
- 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 +155 -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 +176 -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/{jsblock → block}/render-button-handler.snippet.ts +15 -6
- 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 +53 -0
- package/src/runjs-context/snippets/scene/{jsblock → block}/render-react.snippet.ts +15 -11
- package/src/runjs-context/snippets/scene/block/render-statistics.snippet.ts +81 -0
- package/src/runjs-context/snippets/scene/block/render-timeline.snippet.ts +66 -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/types.ts +13 -0
- package/src/utils/__tests__/safeGlobals.test.ts +22 -1
- package/src/utils/buildSettingsViewInputArgs.ts +72 -0
- package/src/utils/index.ts +2 -2
- package/src/utils/params-resolvers.ts +1 -1
- package/src/utils/safeGlobals.ts +49 -3
- package/src/utils/serverContextParams.ts +1 -0
- package/src/utils/variablesParams.ts +50 -38
- package/src/views/PageComponent.tsx +1 -1
- package/src/views/createViewMeta.ts +372 -70
- package/src/views/index.tsx +1 -0
- package/src/views/useDialog.tsx +12 -10
- package/src/views/useDrawer.tsx +60 -36
- package/src/views/usePage.tsx +13 -10
- package/lib/components/dnd/getMousePositionOnElement.d.ts +0 -50
- package/lib/components/dnd/getMousePositionOnElement.js +0 -95
- package/lib/components/dnd/moveBlock.d.ts +0 -33
- package/lib/components/dnd/moveBlock.js +0 -302
- 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/api-request-post.snippet.js +0 -42
- 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/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/global/try-catch-async.snippet.js +0 -44
- 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-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-card.snippet.js +0 -45
- 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/components/dnd/getMousePositionOnElement.ts +0 -115
- package/src/components/dnd/moveBlock.ts +0 -379
- 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-card.snippet.ts +0 -30
- 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
|
@@ -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
|
+
);
|
|
@@ -7,37 +7,42 @@
|
|
|
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 JSFieldRunJSContext 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('value', { get: () => (this as any)._delegate['value'] });
|
|
21
|
-
this.defineProperty('record', { get: () => (this as any)._delegate['record'] });
|
|
22
|
-
this.defineProperty('collection', { get: () => (this as any)._delegate['collection'] });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
12
|
+
export class JSFieldRunJSContext extends FlowRunJSContext {}
|
|
25
13
|
|
|
26
14
|
JSFieldRunJSContext.define({
|
|
27
15
|
label: 'JSField RunJS context',
|
|
28
16
|
properties: {
|
|
29
|
-
element:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
17
|
+
element: `ElementProxy instance providing a safe DOM container for field rendering.
|
|
18
|
+
Supports innerHTML, append, and other DOM manipulation methods.`,
|
|
19
|
+
value: `Current value of the field (read-only).
|
|
20
|
+
Contains the data value stored in this field.`,
|
|
21
|
+
record: `Current record data object (read-only).
|
|
22
|
+
Contains all field values of the parent record.`,
|
|
23
|
+
collection: `Collection definition metadata (read-only).
|
|
24
|
+
Provides schema information about the collection this field belongs to.`,
|
|
33
25
|
},
|
|
34
26
|
methods: {
|
|
35
|
-
onRefReady:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
'Render value': { $ref: 'scene/jsfield/innerHTML-value', prefix: 'sn-jsf-value' },
|
|
39
|
-
'Message success': { $ref: 'global/message-success', prefix: 'sn-msg-ok' },
|
|
40
|
-
'Format number': { $ref: 'scene/jsfield/format-number', prefix: 'sn-jsf-num' },
|
|
41
|
-
'Color by value': { $ref: 'scene/jsfield/color-by-value', prefix: 'sn-jsf-color' },
|
|
27
|
+
onRefReady: `Wait for field container DOM element to be ready before executing callback.
|
|
28
|
+
Parameters: (ref: React.RefObject, callback: (element: HTMLElement) => void, timeout?: number) => void
|
|
29
|
+
Example: ctx.onRefReady(ctx.ref, (el) => { el.innerHTML = ctx.value })`,
|
|
42
30
|
},
|
|
43
31
|
});
|
|
32
|
+
|
|
33
|
+
JSFieldRunJSContext.define(
|
|
34
|
+
{
|
|
35
|
+
label: 'JS 字段 RunJS 上下文',
|
|
36
|
+
properties: {
|
|
37
|
+
element: 'ElementProxy,字段渲染容器,支持 innerHTML/append 等 DOM 操作',
|
|
38
|
+
value: '字段当前值(只读)',
|
|
39
|
+
record: '当前记录对象(只读,包含父记录全部字段值)',
|
|
40
|
+
collection: '集合定义元数据(只读,描述字段所属集合的 Schema)',
|
|
41
|
+
},
|
|
42
|
+
methods: {
|
|
43
|
+
onRefReady:
|
|
44
|
+
'在字段容器 DOM 就绪后执行回调。参数:(ref, callback, timeout?);示例:ctx.onRefReady(ctx.ref, el => { el.innerHTML = ctx.value })',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{ locale: 'zh-CN' },
|
|
48
|
+
);
|
|
@@ -7,33 +7,37 @@
|
|
|
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 JSItemRunJSContext 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('resource', { get: () => (this as any)._delegate['resource'] });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
12
|
+
export class JSItemRunJSContext extends FlowRunJSContext {}
|
|
24
13
|
|
|
25
14
|
JSItemRunJSContext.define({
|
|
26
15
|
label: 'JSItem RunJS context',
|
|
27
16
|
properties: {
|
|
28
|
-
element:
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
element: `ElementProxy instance providing a safe DOM container for form item rendering.
|
|
18
|
+
Supports innerHTML, append, and other DOM manipulation methods.`,
|
|
19
|
+
resource: `Current resource instance (read-only).
|
|
20
|
+
Provides access to the data resource associated with the current form context.`,
|
|
21
|
+
record: `Current record data object (read-only).
|
|
22
|
+
Contains all field values of the parent record.`,
|
|
31
23
|
},
|
|
32
24
|
methods: {
|
|
33
|
-
onRefReady:
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
snipastes: {
|
|
37
|
-
'Render form item': { $ref: 'scene/jsitem/render-basic', prefix: 'sn-jsitem-basic' },
|
|
25
|
+
onRefReady: `Wait for form item container DOM element to be ready before executing callback.
|
|
26
|
+
Parameters: (ref: React.RefObject, callback: (element: HTMLElement) => void, timeout?: number) => void`,
|
|
38
27
|
},
|
|
39
28
|
});
|
|
29
|
+
|
|
30
|
+
JSItemRunJSContext.define(
|
|
31
|
+
{
|
|
32
|
+
label: 'JS 表单项 RunJS 上下文',
|
|
33
|
+
properties: {
|
|
34
|
+
element: 'ElementProxy,表单项渲染容器,支持 innerHTML/append 等 DOM 操作',
|
|
35
|
+
resource: '当前资源(只读)',
|
|
36
|
+
record: '当前记录(只读)',
|
|
37
|
+
},
|
|
38
|
+
methods: {
|
|
39
|
+
onRefReady: '容器就绪后执行回调。参数:(ref, callback, timeout?)',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{ locale: 'zh-CN' },
|
|
43
|
+
);
|
|
@@ -7,28 +7,27 @@
|
|
|
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 JSRecordActionRunJSContext extends FlowRunJSContext {
|
|
13
|
-
constructor(delegate: any) {
|
|
14
|
-
super(delegate);
|
|
15
|
-
this.defineProperty('record', { get: () => (this as any)._delegate['record'] });
|
|
16
|
-
this.defineProperty('filterByTk', { get: () => (this as any)._delegate['filterByTk'] });
|
|
17
|
-
}
|
|
18
|
-
}
|
|
12
|
+
export class JSRecordActionRunJSContext extends FlowRunJSContext {}
|
|
19
13
|
|
|
20
14
|
JSRecordActionRunJSContext.define({
|
|
21
15
|
label: 'JSRecordAction RunJS context',
|
|
22
16
|
properties: {
|
|
23
|
-
record:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
runAction: 'Run action: `await ctx.runAction(name, params)`',
|
|
28
|
-
message: 'Message API',
|
|
29
|
-
},
|
|
30
|
-
snipastes: {
|
|
31
|
-
'Show record id': { $ref: 'scene/actions/record-id-message', prefix: 'sn-act-record-id' },
|
|
32
|
-
'Run action': { $ref: 'scene/actions/run-action-basic', prefix: 'sn-act-run' },
|
|
17
|
+
record: `Current record data object (read-only).
|
|
18
|
+
Contains all field values of the record associated with this action.`,
|
|
19
|
+
filterByTk: `Primary key or filter key of the current record (read-only).
|
|
20
|
+
Used to identify the specific record in database operations.`,
|
|
33
21
|
},
|
|
34
22
|
});
|
|
23
|
+
|
|
24
|
+
JSRecordActionRunJSContext.define(
|
|
25
|
+
{
|
|
26
|
+
label: 'JS 记录动作 RunJS 上下文',
|
|
27
|
+
properties: {
|
|
28
|
+
record: '当前记录(只读)',
|
|
29
|
+
filterByTk: '主键/过滤键(只读)',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
{ locale: 'zh-CN' },
|
|
33
|
+
);
|
|
@@ -0,0 +1,155 @@
|
|
|
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
|
+
export function defineBaseContextMeta() {
|
|
13
|
+
FlowRunJSContext.define({
|
|
14
|
+
label: 'RunJS base',
|
|
15
|
+
properties: {
|
|
16
|
+
logger: 'Pino logger instance for structured logging. Example: `ctx.logger.info({ foo: 1 }, "message")`',
|
|
17
|
+
message:
|
|
18
|
+
'Ant Design global message API for displaying temporary messages. Example: `ctx.message.success("Operation completed")`',
|
|
19
|
+
notification:
|
|
20
|
+
'Ant Design notification API for displaying notification boxes. Example: `ctx.notification.open({ message: "Title", description: "Content" })`',
|
|
21
|
+
resource: 'Data resource accessible based on current user permissions',
|
|
22
|
+
urlSearchParams: 'URLSearchParams object containing query parameters from the current URL',
|
|
23
|
+
token: 'API authentication token for the current session',
|
|
24
|
+
role: 'Current user role information',
|
|
25
|
+
auth: 'Authentication context containing locale, role, user, and token information',
|
|
26
|
+
api: {
|
|
27
|
+
description: 'APIClient instance for making HTTP requests.',
|
|
28
|
+
detail: 'APIClient',
|
|
29
|
+
properties: {
|
|
30
|
+
request: {
|
|
31
|
+
description:
|
|
32
|
+
'Make an HTTP request using the APIClient instance. Parameters: (options: RequestOptions) => Promise<any>.',
|
|
33
|
+
detail: 'Promise<any>',
|
|
34
|
+
completion: {
|
|
35
|
+
insertText: `await ctx.api.request({ url: '', method: 'get', params: {} })`,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
i18n: {
|
|
41
|
+
description: 'An instance of i18next for managing internationalization.',
|
|
42
|
+
detail: 'i18next',
|
|
43
|
+
properties: {
|
|
44
|
+
language: 'Current active language code.',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
React: 'React namespace providing React library functions and hooks (available in RunJS environment)',
|
|
48
|
+
ReactDOM: 'ReactDOM client API including createRoot for rendering React components',
|
|
49
|
+
antd: 'Ant Design component library',
|
|
50
|
+
},
|
|
51
|
+
methods: {
|
|
52
|
+
t: 'Internationalization function for translating text. Parameters: (key: string, variables?: object) => string. Example: `ctx.t("Hello {name}", { name: "World" })`',
|
|
53
|
+
requireAsync:
|
|
54
|
+
'Asynchronously load external libraries from URL. Parameters: (url: string) => Promise<any>. Example: `const lodash = await ctx.requireAsync("https://cdn.jsdelivr.net/npm/lodash")`',
|
|
55
|
+
importAsync:
|
|
56
|
+
'Dynamically import ESM module by URL. Parameters: (url: string) => Promise<Module>. Example: `const mod = await ctx.importAsync("https://cdn.jsdelivr.net/npm/lit-html@2/+esm")`',
|
|
57
|
+
resolveJsonTemplate:
|
|
58
|
+
'Resolve JSON templates containing variable expressions with {{ }} syntax. Parameters: (template: any, context?: object) => any',
|
|
59
|
+
runAction: {
|
|
60
|
+
description:
|
|
61
|
+
'Execute a data action on the current resource. Parameters: (actionName: string, params: object) => Promise<any>. Example: `await ctx.runAction("create", { values: { name: "test" } })`',
|
|
62
|
+
detail: 'Promise<any>',
|
|
63
|
+
completion: {
|
|
64
|
+
insertText: `await ctx.runAction('create', { values: {} })`,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
openView: {
|
|
68
|
+
description: `Open a view component (page, modal, or drawer) by its unique identifier.
|
|
69
|
+
Parameters: (viewId: string, options?: OpenViewOptions) => Promise<void>
|
|
70
|
+
Options:
|
|
71
|
+
- params: Record<string, any> - Parameters passed to the view component
|
|
72
|
+
- mode: "page" | "modal" | "drawer" - Display mode (default: "drawer")
|
|
73
|
+
- title: string - Modal/drawer title
|
|
74
|
+
- width: number | string - Modal/drawer width
|
|
75
|
+
- navigation: boolean - Whether to use route navigation
|
|
76
|
+
- preventClose: boolean - Prevent closing the view
|
|
77
|
+
- viewUid: string - Custom view UID for routing
|
|
78
|
+
- isMobileLayout: boolean - Use mobile layout (displays as embed)
|
|
79
|
+
Examples:
|
|
80
|
+
- Modal with params: await ctx.openView("user-detail", { params: { id: 123 }, mode: "modal", title: "User Details", width: 800 })
|
|
81
|
+
- Drawer (default): await ctx.openView("settings-page")
|
|
82
|
+
- Page navigation: await ctx.openView("dashboard", { mode: "page" })`,
|
|
83
|
+
detail: 'Promise<void>',
|
|
84
|
+
completion: {
|
|
85
|
+
insertText: `await ctx.openView('view-id', { mode: 'drawer', params: {} })`,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
FlowRunJSContext.define(
|
|
92
|
+
{
|
|
93
|
+
label: 'RunJS 基础',
|
|
94
|
+
properties: {
|
|
95
|
+
logger: 'Pino 日志实例(结构化日志)。示例:`ctx.logger.info({ foo: 1 }, "message")`',
|
|
96
|
+
message: 'Ant Design 全局消息 API,用于显示临时提示。示例:`ctx.message.success("操作成功")`',
|
|
97
|
+
notification:
|
|
98
|
+
'Ant Design 通知 API,用于显示通知框。示例:`ctx.notification.open({ message: "标题", description: "内容" })`',
|
|
99
|
+
resource: '基于当前用户权限可访问的数据资源',
|
|
100
|
+
urlSearchParams: '当前 URL 的查询参数(URLSearchParams 对象)',
|
|
101
|
+
token: '当前会话的 API 认证 token',
|
|
102
|
+
role: '当前用户角色信息',
|
|
103
|
+
auth: '认证上下文,包含 locale、role、user、token 等信息',
|
|
104
|
+
api: {
|
|
105
|
+
description: '用于发起 HTTP 请求的 APIClient 实例',
|
|
106
|
+
detail: 'APIClient',
|
|
107
|
+
properties: {
|
|
108
|
+
request: {
|
|
109
|
+
description: '通过 ctx.api.request 发起 HTTP 请求,入参为 RequestOptions,返回 Promise。',
|
|
110
|
+
detail: 'Promise<any>',
|
|
111
|
+
completion: {
|
|
112
|
+
insertText: `await ctx.api.request({ url: '', method: 'get', params: {} })`,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
i18n: {
|
|
118
|
+
description: 'i18next 实例,可用于管理国际化',
|
|
119
|
+
detail: 'i18next',
|
|
120
|
+
properties: {
|
|
121
|
+
language: '当前激活的语言代码',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
React: 'React 命名空间,提供 React 函数与 hooks(RunJS 环境中可用)',
|
|
125
|
+
ReactDOM: 'ReactDOM 客户端 API,含 createRoot 等渲染方法',
|
|
126
|
+
antd: 'Ant Design 组件库(RunJS 环境中可用)',
|
|
127
|
+
},
|
|
128
|
+
methods: {
|
|
129
|
+
t: '国际化函数,用于翻译文案。参数:(key: string, variables?: object) => string。示例:`ctx.t("你好 {name}", { name: "世界" })`',
|
|
130
|
+
requireAsync:
|
|
131
|
+
'按 URL 异步加载外部库。参数:(url: string) => Promise<any>。示例:`const lodash = await ctx.requireAsync("https://cdn.jsdelivr.net/npm/lodash")`',
|
|
132
|
+
importAsync:
|
|
133
|
+
'按 URL 动态导入 ESM 模块(开发/生产均可用)。参数:(url: string) => Promise<Module>。示例:`const mod = await ctx.importAsync("https://cdn.jsdelivr.net/npm/lit-html@2/+esm")`',
|
|
134
|
+
resolveJsonTemplate: '解析含 {{ }} 变量表达式的 JSON 模板。参数:(template: any, context?: object) => any',
|
|
135
|
+
runAction: {
|
|
136
|
+
description:
|
|
137
|
+
'对当前资源执行数据动作。参数:(actionName: string, params: object) => Promise<any>。示例:`await ctx.runAction("create", { values: { name: "test" } })`',
|
|
138
|
+
detail: 'Promise<any>',
|
|
139
|
+
completion: {
|
|
140
|
+
insertText: `await ctx.runAction('create', { values: {} })`,
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
openView: {
|
|
144
|
+
description:
|
|
145
|
+
'根据唯一标识打开视图(页面/弹窗/抽屉)。参数:(viewId: string, options?: OpenViewOptions) => Promise<void>`,常用选项:params、mode、title、width、navigation、preventClose、viewUid、isMobileLayout。',
|
|
146
|
+
detail: 'Promise<void>',
|
|
147
|
+
completion: {
|
|
148
|
+
insertText: `await ctx.openView('view-id', { mode: 'drawer', params: {} })`,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
{ locale: 'zh-CN' },
|
|
154
|
+
);
|
|
155
|
+
}
|
|
@@ -10,47 +10,49 @@
|
|
|
10
10
|
import type { FlowContext } from '../flowContext';
|
|
11
11
|
import { JSRunner } from '../JSRunner';
|
|
12
12
|
import type { JSRunnerOptions } from '../JSRunner';
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import { FormJSFieldItemRunJSContext } from './contexts/FormJSFieldItemRunJSContext';
|
|
19
|
-
import { JSRecordActionRunJSContext } from './contexts/JSRecordActionRunJSContext';
|
|
20
|
-
import { JSCollectionActionRunJSContext } from './contexts/JSCollectionActionRunJSContext';
|
|
21
|
-
import { LinkageRunJSContext } from './contexts/LinkageRunJSContext';
|
|
13
|
+
import { RunJSContextRegistry, getModelClassName, type RunJSVersion } from './registry';
|
|
14
|
+
|
|
15
|
+
function getLocale(ctx: any): string | undefined {
|
|
16
|
+
return ctx?.api?.auth?.locale || ctx?.i18n?.language || ctx?.locale;
|
|
17
|
+
}
|
|
22
18
|
|
|
23
19
|
export function getRunJSDocFor(ctx: FlowContext, { version = 'v1' as RunJSVersion } = {}) {
|
|
24
20
|
const modelClass = getModelClassName(ctx);
|
|
25
|
-
const ctor =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
const ctor = RunJSContextRegistry.resolve(version, modelClass) || RunJSContextRegistry.resolve(version, '*');
|
|
22
|
+
const locale = getLocale(ctx);
|
|
23
|
+
if ((ctor as any)?.getDoc?.length) {
|
|
24
|
+
// prefer getDoc(locale)
|
|
25
|
+
return (ctor as any).getDoc(locale) || {};
|
|
26
|
+
}
|
|
27
|
+
return (ctor as any)?.getDoc?.() || {};
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
export function createJSRunnerWithVersion(this: FlowContext, options?: JSRunnerOptions) {
|
|
33
31
|
const version = (options?.version as RunJSVersion) || ('v1' as RunJSVersion);
|
|
34
32
|
const modelClass = getModelClassName(this);
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
const globals = { ctx: runCtx, ...
|
|
33
|
+
const ensureFlowContext = (obj: any): FlowContext => obj as FlowContext;
|
|
34
|
+
const Ctor = RunJSContextRegistry.resolve(version, modelClass) || RunJSContextRegistry.resolve(version, '*');
|
|
35
|
+
if (!Ctor) {
|
|
36
|
+
throw new Error('[RunJS] No RunJSContext registered for version/model.');
|
|
37
|
+
}
|
|
38
|
+
const runCtx = new (Ctor as any)(ensureFlowContext(this));
|
|
39
|
+
const globals: Record<string, any> = { ctx: runCtx, ...(options?.globals || {}) };
|
|
40
|
+
// 对字段/区块类上下文,默认注入 window/document 以支持在沙箱中访问 DOM API
|
|
41
|
+
if (modelClass === 'JSFieldModel' || modelClass === 'JSBlockModel') {
|
|
42
|
+
if (typeof window !== 'undefined') globals.window = window as any;
|
|
43
|
+
if (typeof document !== 'undefined') globals.document = document as any;
|
|
44
|
+
}
|
|
42
45
|
// 透传 JSRunnerOptions 其余配置(如 timeoutMs)
|
|
43
46
|
const { timeoutMs } = options || {};
|
|
44
47
|
return new JSRunner({ globals, timeoutMs });
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
export function
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
RunJSContextRegistry.register(v, '*', FlowRunJSContext);
|
|
50
|
+
export function getRunJSScenesForModel(modelClass: string, version: RunJSVersion = 'v1'): string[] {
|
|
51
|
+
const meta = RunJSContextRegistry.getMeta(version, modelClass);
|
|
52
|
+
return Array.isArray(meta?.scenes) ? [...meta!.scenes!] : [];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function getRunJSScenesForContext(ctx: FlowContext, { version = 'v1' as RunJSVersion } = {}): string[] {
|
|
56
|
+
const modelClass = getModelClassName(ctx);
|
|
57
|
+
return getRunJSScenesForModel(modelClass, version);
|
|
56
58
|
}
|