@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
|
@@ -1,379 +0,0 @@
|
|
|
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 { uid } from '@formily/shared';
|
|
11
|
-
import _ from 'lodash';
|
|
12
|
-
import { ElementPosition } from './getMousePositionOnElement';
|
|
13
|
-
|
|
14
|
-
type MoveDirection =
|
|
15
|
-
| 'insert-row-above'
|
|
16
|
-
| 'insert-row-below'
|
|
17
|
-
| 'insert-same-column-above'
|
|
18
|
-
| 'insert-same-column-below'
|
|
19
|
-
| 'insert-column-left'
|
|
20
|
-
| 'insert-column-right';
|
|
21
|
-
|
|
22
|
-
interface GridLayoutData {
|
|
23
|
-
rows: Record<string, string[][]>;
|
|
24
|
-
sizes: Record<string, number[]>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const findModelUidPosition = (uid: string, rows: Record<string, string[][]>) => {
|
|
28
|
-
// 找到 sourceUid 和 targetUid 的位置
|
|
29
|
-
let result: { rowId: string; columnIndex: number; itemIndex: number } | null = null;
|
|
30
|
-
|
|
31
|
-
for (const [rowId, columns] of Object.entries(rows)) {
|
|
32
|
-
for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
|
|
33
|
-
const column = columns[columnIndex];
|
|
34
|
-
for (let itemIndex = 0; itemIndex < column.length; itemIndex++) {
|
|
35
|
-
if (column[itemIndex] === uid) {
|
|
36
|
-
result = { rowId, columnIndex, itemIndex };
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return result;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const moveBlock = ({
|
|
46
|
-
sourceUid,
|
|
47
|
-
targetUid,
|
|
48
|
-
direction,
|
|
49
|
-
layoutData,
|
|
50
|
-
}: {
|
|
51
|
-
sourceUid: string;
|
|
52
|
-
targetUid: string;
|
|
53
|
-
direction: MoveDirection;
|
|
54
|
-
layoutData: GridLayoutData;
|
|
55
|
-
}): GridLayoutData => {
|
|
56
|
-
const { rows, sizes } = layoutData;
|
|
57
|
-
const newSizes = _.cloneDeep(sizes);
|
|
58
|
-
let newRows = _.cloneDeep(rows);
|
|
59
|
-
|
|
60
|
-
// 找到 sourceUid 和 targetUid 的位置
|
|
61
|
-
let sourcePosition: { rowId: string; columnIndex: number; itemIndex: number } | null = null;
|
|
62
|
-
let targetPosition: { rowId: string; columnIndex: number; itemIndex: number } | null = null;
|
|
63
|
-
|
|
64
|
-
for (const [rowId, columns] of Object.entries(newRows)) {
|
|
65
|
-
for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
|
|
66
|
-
const column = columns[columnIndex];
|
|
67
|
-
for (let itemIndex = 0; itemIndex < column.length; itemIndex++) {
|
|
68
|
-
if (column[itemIndex] === sourceUid) {
|
|
69
|
-
sourcePosition = { rowId, columnIndex, itemIndex };
|
|
70
|
-
}
|
|
71
|
-
if (column[itemIndex] === targetUid) {
|
|
72
|
-
targetPosition = { rowId, columnIndex, itemIndex };
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (!sourcePosition || !targetPosition) {
|
|
79
|
-
return layoutData; // 如果没有找到 sourceUid 或 targetUid,直接返回原数据
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const removeOldSourceUid = () => {
|
|
83
|
-
// 从原位置移除 sourceUid
|
|
84
|
-
newRows[sourcePosition.rowId][sourcePosition.columnIndex].splice(sourcePosition.itemIndex, 1);
|
|
85
|
-
|
|
86
|
-
// 如果列变空了,移除该列
|
|
87
|
-
if (newRows[sourcePosition.rowId][sourcePosition.columnIndex].length === 0) {
|
|
88
|
-
newRows[sourcePosition.rowId]?.splice(sourcePosition.columnIndex, 1);
|
|
89
|
-
newSizes[sourcePosition.rowId]?.splice(sourcePosition.columnIndex, 1);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// 如果行变空了,移除该行
|
|
93
|
-
if (newRows[sourcePosition.rowId].length === 0) {
|
|
94
|
-
delete newRows[sourcePosition.rowId];
|
|
95
|
-
delete newSizes[sourcePosition.rowId];
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// 移除完之后,重新设置 sourcePosition 和 targetPosition
|
|
99
|
-
for (const [rowId, columns] of Object.entries(newRows)) {
|
|
100
|
-
for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
|
|
101
|
-
const column = columns[columnIndex];
|
|
102
|
-
for (let itemIndex = 0; itemIndex < column.length; itemIndex++) {
|
|
103
|
-
if (column[itemIndex] === sourceUid) {
|
|
104
|
-
sourcePosition = { rowId, columnIndex, itemIndex };
|
|
105
|
-
}
|
|
106
|
-
if (column[itemIndex] === targetUid) {
|
|
107
|
-
targetPosition = { rowId, columnIndex, itemIndex };
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
switch (direction) {
|
|
115
|
-
case 'insert-row-above': {
|
|
116
|
-
// 检查 targetUid 上面是否有其他同列的 uid
|
|
117
|
-
if (targetPosition.itemIndex > 0) {
|
|
118
|
-
return layoutData; // 无效操作,直接返回原数据
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
removeOldSourceUid();
|
|
122
|
-
|
|
123
|
-
// 创建新行 ID
|
|
124
|
-
const newRowId = uid();
|
|
125
|
-
|
|
126
|
-
// 插入到目标行前面
|
|
127
|
-
newRows = insertKey({
|
|
128
|
-
obj: newRows,
|
|
129
|
-
newKey: newRowId,
|
|
130
|
-
newValue: [[sourceUid]],
|
|
131
|
-
referenceKey: targetPosition.rowId,
|
|
132
|
-
position: 'before',
|
|
133
|
-
});
|
|
134
|
-
newSizes[newRowId] = [24];
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
case 'insert-row-below': {
|
|
139
|
-
// 检查 targetUid 所在行的后面是否有同名的 sourceUid
|
|
140
|
-
const nextRowKey = getNextKey(newRows, targetPosition.rowId);
|
|
141
|
-
|
|
142
|
-
if (nextRowKey === sourcePosition.rowId && newRows[nextRowKey].length === 1) {
|
|
143
|
-
return layoutData; // 无效操作,直接返回原数据
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
removeOldSourceUid();
|
|
147
|
-
|
|
148
|
-
// 创建新行ID
|
|
149
|
-
const newRowId = uid();
|
|
150
|
-
|
|
151
|
-
// 插入到目标行后面
|
|
152
|
-
newRows = insertKey({
|
|
153
|
-
obj: newRows,
|
|
154
|
-
newKey: newRowId,
|
|
155
|
-
newValue: [[sourceUid]],
|
|
156
|
-
referenceKey: targetPosition.rowId,
|
|
157
|
-
position: 'after',
|
|
158
|
-
});
|
|
159
|
-
newSizes[newRowId] = [24];
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
case 'insert-same-column-above': {
|
|
164
|
-
removeOldSourceUid();
|
|
165
|
-
|
|
166
|
-
const column = newRows[targetPosition.rowId][targetPosition.columnIndex];
|
|
167
|
-
if (column[targetPosition.itemIndex - 1] === sourceUid) {
|
|
168
|
-
return layoutData; // 无效操作,直接返回原数据
|
|
169
|
-
}
|
|
170
|
-
column.splice(targetPosition.itemIndex, 0, sourceUid);
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
case 'insert-same-column-below': {
|
|
175
|
-
removeOldSourceUid();
|
|
176
|
-
|
|
177
|
-
const column = newRows[targetPosition.rowId][targetPosition.columnIndex];
|
|
178
|
-
if (column[targetPosition.itemIndex + 1] === sourceUid) {
|
|
179
|
-
return layoutData; // 无效操作,直接返回原数据
|
|
180
|
-
}
|
|
181
|
-
column.splice(targetPosition.itemIndex + 1, 0, sourceUid);
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
case 'insert-column-left': {
|
|
186
|
-
removeOldSourceUid();
|
|
187
|
-
|
|
188
|
-
// 在目标列左侧插入新列
|
|
189
|
-
newRows[targetPosition.rowId].splice(targetPosition.columnIndex, 0, [sourceUid]);
|
|
190
|
-
|
|
191
|
-
// 重新计算列宽
|
|
192
|
-
const currentSizes = newSizes[targetPosition.rowId] || [];
|
|
193
|
-
const columnCount = newRows[targetPosition.rowId].length || 0;
|
|
194
|
-
const newColumnWidth = Math.floor(24 / columnCount);
|
|
195
|
-
const remainingWidth = 24 - newColumnWidth;
|
|
196
|
-
|
|
197
|
-
// 按原比例分配剩余宽度
|
|
198
|
-
const totalOldWidth = currentSizes.reduce((sum, size) => sum + size, 0);
|
|
199
|
-
const adjustedSizes = currentSizes.map((size) => Math.floor((size / totalOldWidth) * remainingWidth));
|
|
200
|
-
|
|
201
|
-
// 插入新列宽度
|
|
202
|
-
adjustedSizes.splice(targetPosition.columnIndex, 0, newColumnWidth);
|
|
203
|
-
|
|
204
|
-
// 处理舍入误差
|
|
205
|
-
const totalNewWidth = adjustedSizes.reduce((sum, size) => sum + size, 0);
|
|
206
|
-
if (totalNewWidth < 24) {
|
|
207
|
-
adjustedSizes[adjustedSizes.length - 1] += 24 - totalNewWidth;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
newSizes[targetPosition.rowId] = adjustedSizes;
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
case 'insert-column-right': {
|
|
215
|
-
removeOldSourceUid();
|
|
216
|
-
|
|
217
|
-
// 在目标列右侧插入新列
|
|
218
|
-
newRows[targetPosition.rowId].splice(targetPosition.columnIndex + 1, 0, [sourceUid]);
|
|
219
|
-
|
|
220
|
-
// 重新计算列宽
|
|
221
|
-
const currentSizes = newSizes[targetPosition.rowId] || [];
|
|
222
|
-
const columnCount = newRows[targetPosition.rowId]?.length || 0;
|
|
223
|
-
const newColumnWidth = Math.floor(24 / columnCount);
|
|
224
|
-
const remainingWidth = 24 - newColumnWidth;
|
|
225
|
-
|
|
226
|
-
// 按原比例分配剩余宽度
|
|
227
|
-
const totalOldWidth = currentSizes.reduce((sum, size) => sum + size, 0);
|
|
228
|
-
const adjustedSizes = currentSizes.map((size) => Math.floor((size / totalOldWidth) * remainingWidth));
|
|
229
|
-
|
|
230
|
-
// 插入新列宽度
|
|
231
|
-
adjustedSizes.splice(targetPosition.columnIndex + 1, 0, newColumnWidth);
|
|
232
|
-
|
|
233
|
-
// 处理舍入误差
|
|
234
|
-
const totalNewWidth = adjustedSizes.reduce((sum, size) => sum + size, 0);
|
|
235
|
-
if (totalNewWidth < 24) {
|
|
236
|
-
adjustedSizes[adjustedSizes.length - 1] += 24 - totalNewWidth;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
newSizes[targetPosition.rowId] = adjustedSizes;
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return recalculateAllRowSizesWithProportion({ rows: newRows, sizes: newSizes });
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* 将鼠标在元素上的位置转换为区块移动方向
|
|
249
|
-
*
|
|
250
|
-
* @param position 鼠标在元素上的位置
|
|
251
|
-
* @returns 对应的移动方向
|
|
252
|
-
*/
|
|
253
|
-
export const positionToDirection = (position: ElementPosition): MoveDirection => {
|
|
254
|
-
switch (position) {
|
|
255
|
-
case ElementPosition.TOP:
|
|
256
|
-
return 'insert-same-column-above';
|
|
257
|
-
case ElementPosition.BOTTOM:
|
|
258
|
-
return 'insert-same-column-below';
|
|
259
|
-
case ElementPosition.LEFT:
|
|
260
|
-
return 'insert-column-left';
|
|
261
|
-
case ElementPosition.RIGHT:
|
|
262
|
-
return 'insert-column-right';
|
|
263
|
-
case ElementPosition.TOP_EDGE:
|
|
264
|
-
return 'insert-row-above';
|
|
265
|
-
case ElementPosition.BOTTOM_EDGE:
|
|
266
|
-
return 'insert-row-below';
|
|
267
|
-
case ElementPosition.LEFT_EDGE:
|
|
268
|
-
return 'insert-column-left';
|
|
269
|
-
case ElementPosition.RIGHT_EDGE:
|
|
270
|
-
return 'insert-column-right';
|
|
271
|
-
default:
|
|
272
|
-
throw new Error(`Unsupported position: ${position}`);
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
function insertKey({
|
|
277
|
-
obj,
|
|
278
|
-
newKey,
|
|
279
|
-
newValue,
|
|
280
|
-
referenceKey,
|
|
281
|
-
position,
|
|
282
|
-
}: {
|
|
283
|
-
obj: Record<string, any>;
|
|
284
|
-
newKey: string;
|
|
285
|
-
newValue: any;
|
|
286
|
-
referenceKey: string;
|
|
287
|
-
position: 'before' | 'after';
|
|
288
|
-
}) {
|
|
289
|
-
const result: Record<string, any> = {};
|
|
290
|
-
|
|
291
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
292
|
-
if (position === 'before' && key === referenceKey) {
|
|
293
|
-
result[newKey] = newValue;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
result[key] = value;
|
|
297
|
-
|
|
298
|
-
if (position === 'after' && key === referenceKey) {
|
|
299
|
-
result[newKey] = newValue;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
return result;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
function getNextKey(obj: Record<string, any>, currentKey: string): string | null {
|
|
307
|
-
const keys = Object.keys(obj);
|
|
308
|
-
const index = keys.indexOf(currentKey);
|
|
309
|
-
return index >= 0 && index < keys.length - 1 ? keys[index + 1] : null;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* 重新计算所有行的列宽,保持原有比例的同时确保总宽度为24
|
|
314
|
-
* @param layoutData 当前的布局数据
|
|
315
|
-
* @returns 更新后的布局数据
|
|
316
|
-
*/
|
|
317
|
-
function recalculateAllRowSizesWithProportion(layoutData: GridLayoutData): GridLayoutData {
|
|
318
|
-
const { rows, sizes } = layoutData;
|
|
319
|
-
const newSizes = _.cloneDeep(sizes);
|
|
320
|
-
|
|
321
|
-
for (const [rowId, columns] of Object.entries(rows)) {
|
|
322
|
-
const columnCount = columns.length;
|
|
323
|
-
const currentSizes = sizes[rowId] || [];
|
|
324
|
-
|
|
325
|
-
if (columnCount === 0) {
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
// 如果当前没有尺寸信息或尺寸数量不匹配,使用均等分配
|
|
330
|
-
if (currentSizes.length !== columnCount || currentSizes.every((size) => size === 0)) {
|
|
331
|
-
const baseWidth = Math.floor(24 / columnCount);
|
|
332
|
-
const remainder = 24 % columnCount;
|
|
333
|
-
const newRowSizes = new Array(columnCount).fill(baseWidth);
|
|
334
|
-
|
|
335
|
-
for (let i = 0; i < remainder; i++) {
|
|
336
|
-
newRowSizes[i] += 1;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
newSizes[rowId] = newRowSizes;
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// 计算当前总宽度
|
|
344
|
-
const currentTotal = currentSizes.reduce((sum, size) => sum + size, 0);
|
|
345
|
-
|
|
346
|
-
if (currentTotal === 0) {
|
|
347
|
-
// 如果当前总宽度为0,使用均等分配
|
|
348
|
-
const baseWidth = Math.floor(24 / columnCount);
|
|
349
|
-
const remainder = 24 % columnCount;
|
|
350
|
-
const newRowSizes = new Array(columnCount).fill(baseWidth);
|
|
351
|
-
|
|
352
|
-
for (let i = 0; i < remainder; i++) {
|
|
353
|
-
newRowSizes[i] += 1;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
newSizes[rowId] = newRowSizes;
|
|
357
|
-
} else {
|
|
358
|
-
// 按比例重新分配
|
|
359
|
-
const newRowSizes = currentSizes.map((size) => Math.floor((size / currentTotal) * 24));
|
|
360
|
-
|
|
361
|
-
// 处理舍入误差
|
|
362
|
-
const actualTotal = newRowSizes.reduce((sum, size) => sum + size, 0);
|
|
363
|
-
const diff = 24 - actualTotal;
|
|
364
|
-
|
|
365
|
-
// 将差值分配给最后几列
|
|
366
|
-
for (let i = newRowSizes.length - 1; i >= 0 && diff > 0; i--) {
|
|
367
|
-
const add = Math.min(diff, 1);
|
|
368
|
-
newRowSizes[i] += add;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
newSizes[rowId] = newRowSizes;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
return {
|
|
376
|
-
rows,
|
|
377
|
-
sizes: newSizes,
|
|
378
|
-
};
|
|
379
|
-
}
|
|
@@ -1,190 +0,0 @@
|
|
|
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 type { FlowContext } from '../../flowContext';
|
|
11
|
-
import * as antd from 'antd';
|
|
12
|
-
import React from 'react';
|
|
13
|
-
import * as ReactDOMClient from 'react-dom/client';
|
|
14
|
-
|
|
15
|
-
export type RunJSVersion = 'v1' | (string & {});
|
|
16
|
-
export type RunJSContextCtor = new (delegate: FlowContext) => FlowRunJSContext;
|
|
17
|
-
|
|
18
|
-
export type RunJSDocMeta = {
|
|
19
|
-
label?: string;
|
|
20
|
-
properties?: Record<string, any>;
|
|
21
|
-
methods?: Record<string, any>;
|
|
22
|
-
snipastes?: Record<string, any>;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const classMeta = new WeakMap<Function, RunJSDocMeta>();
|
|
26
|
-
const classDocCache = new WeakMap<Function, RunJSDocMeta>();
|
|
27
|
-
|
|
28
|
-
function deepMerge(base: any, patch: any) {
|
|
29
|
-
if (patch === null) return undefined;
|
|
30
|
-
if (Array.isArray(base) || Array.isArray(patch) || typeof base !== 'object' || typeof patch !== 'object') {
|
|
31
|
-
return patch ?? base;
|
|
32
|
-
}
|
|
33
|
-
const out: any = { ...base };
|
|
34
|
-
for (const k of Object.keys(patch)) {
|
|
35
|
-
const v = deepMerge(base?.[k], patch[k]);
|
|
36
|
-
if (typeof v === 'undefined') delete out[k];
|
|
37
|
-
else out[k] = v;
|
|
38
|
-
}
|
|
39
|
-
return out;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class FlowRunJSContext {
|
|
43
|
-
protected _delegate: FlowContext;
|
|
44
|
-
[key: string]: any;
|
|
45
|
-
static allow?: { keys?: ReadonlyArray<string>; facades?: Record<string, ReadonlyArray<string>> };
|
|
46
|
-
|
|
47
|
-
constructor(delegate: FlowContext) {
|
|
48
|
-
this._delegate = delegate;
|
|
49
|
-
const self = this as any;
|
|
50
|
-
// 常用前端依赖直接注入
|
|
51
|
-
self.React = React;
|
|
52
|
-
self.react = React;
|
|
53
|
-
self.antd = antd;
|
|
54
|
-
self.ReactDOM = ReactDOMClient;
|
|
55
|
-
// 公共方法:分发模型事件
|
|
56
|
-
self.dispatchModelEvent = async (modelOrUid: any, eventName: string, inputArgs?: Record<string, any>) => {
|
|
57
|
-
let model: any = null;
|
|
58
|
-
const engine = (this._delegate as any).engine;
|
|
59
|
-
if (typeof modelOrUid === 'string') {
|
|
60
|
-
model = await engine?.loadModel?.({ uid: modelOrUid });
|
|
61
|
-
} else if (modelOrUid && typeof modelOrUid === 'object' && typeof modelOrUid.dispatchEvent === 'function') {
|
|
62
|
-
model = modelOrUid;
|
|
63
|
-
}
|
|
64
|
-
if (model) {
|
|
65
|
-
model.context?.addDelegate?.(self);
|
|
66
|
-
model.dispatchEvent(eventName, {
|
|
67
|
-
navigation: false,
|
|
68
|
-
...(self.model?.['getInputArgs']?.() || {}),
|
|
69
|
-
...(inputArgs || {}),
|
|
70
|
-
});
|
|
71
|
-
} else {
|
|
72
|
-
self.message?.error?.(
|
|
73
|
-
self.t?.('Model with ID {{uid}} not found', { uid: String(modelOrUid) }) || 'Model not found',
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
// 显式暴露:基础属性(只读 getter 映射到委托)
|
|
79
|
-
this.#exposeProps([
|
|
80
|
-
'message',
|
|
81
|
-
'notification',
|
|
82
|
-
'logger',
|
|
83
|
-
'resource',
|
|
84
|
-
'urlSearchParams',
|
|
85
|
-
'token',
|
|
86
|
-
'role',
|
|
87
|
-
'auth',
|
|
88
|
-
'api',
|
|
89
|
-
'ref',
|
|
90
|
-
'model',
|
|
91
|
-
]);
|
|
92
|
-
// 显式暴露:基础方法(绑定到委托)
|
|
93
|
-
this.#exposeMethods(['t', 'requireAsync', 'copyToClipboard', 'resolveJsonTemplate', 'runAction', 'onRefReady']);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// 供子类/外部一致使用的定义 API(与 FlowContext 的接口保持一致风格)
|
|
97
|
-
defineProperty(key: string, options: { get?: (ctx: any) => any; value?: any }) {
|
|
98
|
-
if (options && typeof options.get === 'function') {
|
|
99
|
-
Object.defineProperty(this, key, {
|
|
100
|
-
configurable: true,
|
|
101
|
-
enumerable: true,
|
|
102
|
-
get: () => options.get?.(this),
|
|
103
|
-
});
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
Object.defineProperty(this, key, {
|
|
107
|
-
configurable: true,
|
|
108
|
-
enumerable: true,
|
|
109
|
-
writable: false,
|
|
110
|
-
value: options?.value,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
defineMethod(name: string, fn: (...args: any[]) => any) {
|
|
114
|
-
Object.defineProperty(this, name, {
|
|
115
|
-
configurable: true,
|
|
116
|
-
enumerable: false,
|
|
117
|
-
writable: false,
|
|
118
|
-
value: fn.bind(this),
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// 工具:将委托上的属性以 getter 暴露
|
|
123
|
-
#exposeProps(names: string[]) {
|
|
124
|
-
for (const k of names) {
|
|
125
|
-
if (Object.prototype.hasOwnProperty.call(this, k)) continue;
|
|
126
|
-
this.defineProperty(k, { get: () => (this._delegate as any)[k] });
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// 工具:将委托上的同名方法绑定暴露
|
|
130
|
-
#exposeMethods(names: string[]) {
|
|
131
|
-
for (const k of names) {
|
|
132
|
-
if (Object.prototype.hasOwnProperty.call(this, k)) continue;
|
|
133
|
-
const src = (this._delegate as any)[k];
|
|
134
|
-
if (typeof src === 'function') {
|
|
135
|
-
this.defineMethod(k, src.bind(this._delegate));
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
static injectDefaultGlobals?(): { window?: any; document?: any } | void;
|
|
141
|
-
|
|
142
|
-
static define(meta: RunJSDocMeta) {
|
|
143
|
-
const prev = classMeta.get(this) || {};
|
|
144
|
-
classMeta.set(this, deepMerge(prev, meta));
|
|
145
|
-
classDocCache.delete(this);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
static getDoc(): RunJSDocMeta {
|
|
149
|
-
const self = this as any;
|
|
150
|
-
if (classDocCache.has(self)) return classDocCache.get(self)!;
|
|
151
|
-
const chain: Function[] = [];
|
|
152
|
-
let cur: any = self;
|
|
153
|
-
while (cur && cur.prototype) {
|
|
154
|
-
chain.unshift(cur);
|
|
155
|
-
cur = Object.getPrototypeOf(cur);
|
|
156
|
-
}
|
|
157
|
-
let merged: RunJSDocMeta = {};
|
|
158
|
-
for (const cls of chain) merged = deepMerge(merged, classMeta.get(cls) || {});
|
|
159
|
-
classDocCache.set(self, merged);
|
|
160
|
-
return merged;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Define base doc on FlowRunJSContext itself
|
|
165
|
-
FlowRunJSContext.define({
|
|
166
|
-
label: 'RunJS base',
|
|
167
|
-
properties: {
|
|
168
|
-
t: "国际化函数。示例:`ctx.t('Hello {name}', { name: 'World' })`",
|
|
169
|
-
logger: "Pino logger 子实例。`ctx.logger.info({ foo: 1 }, 'msg')`",
|
|
170
|
-
message: "AntD 全局消息。`ctx.message.success('done')`",
|
|
171
|
-
notification: "AntD 通知。`ctx.notification.open({ message: 'Hi' })`",
|
|
172
|
-
requireAsync: '异步加载外部库。`const x = await ctx.requireAsync(url)`',
|
|
173
|
-
copyToClipboard: '复制文本到剪贴板。`await ctx.copyToClipboard(text)`',
|
|
174
|
-
resolveJsonTemplate: '解析含 {{ }} 的模板/表达式',
|
|
175
|
-
runAction: '运行当前模型动作。`await ctx.runAction(name, params)`',
|
|
176
|
-
resource: '数据资源(按委托可见)',
|
|
177
|
-
urlSearchParams: 'URL 查询参数对象',
|
|
178
|
-
token: 'API Token',
|
|
179
|
-
role: '当前角色',
|
|
180
|
-
auth: '认证信息(locale/role/user/token)',
|
|
181
|
-
api: 'APIClient 实例',
|
|
182
|
-
React: 'React 命名空间(RunJS 环境可用)',
|
|
183
|
-
react: 'React 别名(小写)',
|
|
184
|
-
ReactDOM: 'ReactDOM 客户端(含 createRoot)',
|
|
185
|
-
antd: 'AntD 组件库(RunJS 环境可用)',
|
|
186
|
-
},
|
|
187
|
-
methods: {
|
|
188
|
-
dispatchModelEvent: "触发模型事件:`await ctx.dispatchModelEvent(modelUid, 'click', { ... })`",
|
|
189
|
-
},
|
|
190
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
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 './FlowRunJSContext';
|
|
11
|
-
|
|
12
|
-
export class LinkageRunJSContext extends FlowRunJSContext {
|
|
13
|
-
constructor(delegate: any) {
|
|
14
|
-
super(delegate);
|
|
15
|
-
this.defineProperty('model', { get: () => (this as any)._delegate['model'] });
|
|
16
|
-
this.defineProperty('fields', { get: () => (this as any)._delegate['fields'] });
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
LinkageRunJSContext.define({
|
|
21
|
-
label: 'Linkage RunJS context',
|
|
22
|
-
properties: {
|
|
23
|
-
model: '当前块/字段模型(只读访问)',
|
|
24
|
-
fields: '可访问的字段集合(只读)',
|
|
25
|
-
},
|
|
26
|
-
methods: {
|
|
27
|
-
message: 'Message API',
|
|
28
|
-
},
|
|
29
|
-
snipastes: {
|
|
30
|
-
'Set field value': { $ref: 'scene/linkage/set-field-value', prefix: 'sn-link-set' },
|
|
31
|
-
'Toggle visible': { $ref: 'scene/linkage/toggle-visible', prefix: 'sn-link-visibility' },
|
|
32
|
-
'Set disabled': { $ref: 'scene/linkage/set-disabled', prefix: 'sn-link-disable' },
|
|
33
|
-
'Set required': { $ref: 'scene/linkage/set-required', prefix: 'sn-link-required' },
|
|
34
|
-
},
|
|
35
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
export * from './registry';
|
|
11
|
-
export * from './helpers';
|
|
12
|
-
export * from './contexts/FlowRunJSContext';
|
|
13
|
-
export * from './contexts/JSBlockRunJSContext';
|
|
14
|
-
export * from './contexts/JSFieldRunJSContext';
|
|
15
|
-
export * from './contexts/JSItemRunJSContext';
|
|
16
|
-
export * from './contexts/FormJSFieldItemRunJSContext';
|
|
17
|
-
export * from './contexts/JSRecordActionRunJSContext';
|
|
18
|
-
export * from './contexts/JSCollectionActionRunJSContext';
|
|
19
|
-
export * from './contexts/LinkageRunJSContext';
|
|
20
|
-
export { engineSnippets } from './snippets';
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
export default {
|
|
11
|
-
contexts: ['*'],
|
|
12
|
-
prefix: 'sn-api-get',
|
|
13
|
-
label: 'GET request template',
|
|
14
|
-
description: 'Basic template to send a GET request via ctx.api',
|
|
15
|
-
content: `
|
|
16
|
-
const res = await ctx.api.request({ url: '/your/api', method: 'get', params: { page: 1 } });
|
|
17
|
-
ctx.message.success(ctx.t('GET request completed'));
|
|
18
|
-
console.log(ctx.t('GET result:'), res);
|
|
19
|
-
`,
|
|
20
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
export default {
|
|
11
|
-
contexts: ['*'],
|
|
12
|
-
prefix: 'sn-api-post',
|
|
13
|
-
label: 'POST request template',
|
|
14
|
-
description: 'Basic template to send a POST request via ctx.api',
|
|
15
|
-
content: `
|
|
16
|
-
const res = await ctx.api.request({ url: '/your/api', method: 'post', data: { name: 'NocoBase' } });
|
|
17
|
-
ctx.message.success(ctx.t('POST request completed'));
|
|
18
|
-
console.log(ctx.t('POST result:'), res);
|
|
19
|
-
`,
|
|
20
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
export default {
|
|
11
|
-
contexts: ['*'],
|
|
12
|
-
prefix: 'sn-log-ctx',
|
|
13
|
-
label: 'Log ctx',
|
|
14
|
-
description: 'Log the whole ctx object to console',
|
|
15
|
-
content: `
|
|
16
|
-
console.log('ctx =>', ctx);
|
|
17
|
-
ctx.message?.success?.(ctx.t('ctx printed'));
|
|
18
|
-
`,
|
|
19
|
-
};
|