@nocobase/flow-engine 2.0.0-alpha.2
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/LICENSE +661 -0
- package/README.md +30 -0
- package/lib/ContextPathProxy.d.ts +17 -0
- package/lib/ContextPathProxy.js +65 -0
- package/lib/ElementProxy.d.ts +17 -0
- package/lib/ElementProxy.js +93 -0
- package/lib/FlowContextProvider.d.ts +24 -0
- package/lib/FlowContextProvider.js +82 -0
- package/lib/FlowDefinition.d.ts +423 -0
- package/lib/FlowDefinition.js +257 -0
- package/lib/JSRunner.d.ts +32 -0
- package/lib/JSRunner.js +95 -0
- package/lib/ReactView.d.ts +20 -0
- package/lib/ReactView.js +120 -0
- package/lib/ViewScopedFlowEngine.d.ts +23 -0
- package/lib/ViewScopedFlowEngine.js +81 -0
- package/lib/acl/Acl.d.ts +31 -0
- package/lib/acl/Acl.js +115 -0
- package/lib/action-registry/BaseActionRegistry.d.ts +23 -0
- package/lib/action-registry/BaseActionRegistry.js +57 -0
- package/lib/action-registry/EngineActionRegistry.d.ts +20 -0
- package/lib/action-registry/EngineActionRegistry.js +47 -0
- package/lib/action-registry/ModelActionRegistry.d.ts +34 -0
- package/lib/action-registry/ModelActionRegistry.js +79 -0
- package/lib/components/DynamicFlowsEditor.d.ts +17 -0
- package/lib/components/DynamicFlowsEditor.js +49 -0
- package/lib/components/FieldModelRenderer.d.ts +10 -0
- package/lib/components/FieldModelRenderer.js +94 -0
- package/lib/components/FlowContextSelector.d.ts +11 -0
- package/lib/components/FlowContextSelector.js +221 -0
- package/lib/components/FlowErrorFallback.d.ts +25 -0
- package/lib/components/FlowErrorFallback.js +264 -0
- package/lib/components/FlowModelRenderer.d.ts +64 -0
- package/lib/components/FlowModelRenderer.js +254 -0
- package/lib/components/FormItem.d.ts +18 -0
- package/lib/components/FormItem.js +147 -0
- package/lib/components/common/FlowSettingsButton.d.ts +11 -0
- package/lib/components/common/FlowSettingsButton.js +66 -0
- package/lib/components/common/index.d.ts +9 -0
- package/lib/components/common/index.js +30 -0
- package/lib/components/common/withFlowDesignMode.d.ts +26 -0
- package/lib/components/common/withFlowDesignMode.js +61 -0
- package/lib/components/dnd/getMousePositionOnElement.d.ts +50 -0
- package/lib/components/dnd/getMousePositionOnElement.js +95 -0
- package/lib/components/dnd/index.d.ts +24 -0
- package/lib/components/dnd/index.js +164 -0
- package/lib/components/dnd/moveBlock.d.ts +33 -0
- package/lib/components/dnd/moveBlock.js +302 -0
- package/lib/components/index.d.ts +18 -0
- package/lib/components/index.js +48 -0
- package/lib/components/settings/independents/dropdown/FlowsDropdownButton.d.ts +46 -0
- package/lib/components/settings/independents/dropdown/FlowsDropdownButton.js +225 -0
- package/lib/components/settings/independents/dropdown/index.d.ts +9 -0
- package/lib/components/settings/independents/dropdown/index.js +30 -0
- package/lib/components/settings/independents/index.d.ts +1 -0
- package/lib/components/settings/independents/index.js +30 -0
- package/lib/components/settings/index.d.ts +10 -0
- package/lib/components/settings/index.js +32 -0
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.d.ts +24 -0
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +501 -0
- package/lib/components/settings/wrappers/contextual/FlowsContextMenu.d.ts +45 -0
- package/lib/components/settings/wrappers/contextual/FlowsContextMenu.js +231 -0
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +111 -0
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +484 -0
- package/lib/components/settings/wrappers/contextual/StepRequiredSettingsDialog.d.ts +26 -0
- package/lib/components/settings/wrappers/contextual/StepRequiredSettingsDialog.js +342 -0
- package/lib/components/settings/wrappers/contextual/StepSettings.d.ts +23 -0
- package/lib/components/settings/wrappers/contextual/StepSettings.js +110 -0
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.d.ts +20 -0
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +206 -0
- package/lib/components/settings/wrappers/contextual/StepSettingsDrawer.d.ts +20 -0
- package/lib/components/settings/wrappers/contextual/StepSettingsDrawer.js +47 -0
- package/lib/components/settings/wrappers/contextual/index.d.ts +14 -0
- package/lib/components/settings/wrappers/contextual/index.js +40 -0
- package/lib/components/settings/wrappers/embedded/FlowSettings.d.ts +33 -0
- package/lib/components/settings/wrappers/embedded/FlowSettings.js +207 -0
- package/lib/components/settings/wrappers/embedded/FlowsSettings.d.ts +41 -0
- package/lib/components/settings/wrappers/embedded/FlowsSettings.js +84 -0
- package/lib/components/settings/wrappers/embedded/FlowsSettingsContent.d.ts +16 -0
- package/lib/components/settings/wrappers/embedded/FlowsSettingsContent.js +88 -0
- package/lib/components/settings/wrappers/embedded/index.d.ts +10 -0
- package/lib/components/settings/wrappers/embedded/index.js +32 -0
- package/lib/components/settings/wrappers/index.d.ts +2 -0
- package/lib/components/settings/wrappers/index.js +32 -0
- package/lib/components/subModel/AddSubModelButton.d.ts +62 -0
- package/lib/components/subModel/AddSubModelButton.js +415 -0
- package/lib/components/subModel/LazyDropdown.d.ts +55 -0
- package/lib/components/subModel/LazyDropdown.js +524 -0
- package/lib/components/subModel/index.d.ts +10 -0
- package/lib/components/subModel/index.js +32 -0
- package/lib/components/subModel/utils.d.ts +34 -0
- package/lib/components/subModel/utils.js +287 -0
- package/lib/components/variables/InlineVariableTag.d.ts +21 -0
- package/lib/components/variables/InlineVariableTag.js +123 -0
- package/lib/components/variables/SlateVariableEditor.d.ts +46 -0
- package/lib/components/variables/SlateVariableEditor.js +302 -0
- package/lib/components/variables/VariableInput.d.ts +11 -0
- package/lib/components/variables/VariableInput.js +322 -0
- package/lib/components/variables/VariableTag.d.ts +11 -0
- package/lib/components/variables/VariableTag.js +148 -0
- package/lib/components/variables/VariableTrigger.d.ts +20 -0
- package/lib/components/variables/VariableTrigger.js +136 -0
- package/lib/components/variables/index.d.ts +15 -0
- package/lib/components/variables/index.js +53 -0
- package/lib/components/variables/types.d.ts +93 -0
- package/lib/components/variables/types.js +24 -0
- package/lib/components/variables/useResolvedMetaTree.d.ts +19 -0
- package/lib/components/variables/useResolvedMetaTree.js +91 -0
- package/lib/components/variables/utils.d.ts +22 -0
- package/lib/components/variables/utils.js +177 -0
- package/lib/data-source/index.d.ts +180 -0
- package/lib/data-source/index.js +733 -0
- package/lib/data-source/jioToJoiSchema.d.ts +19 -0
- package/lib/data-source/jioToJoiSchema.js +114 -0
- package/lib/decorators/index.d.ts +9 -0
- package/lib/decorators/index.js +36 -0
- package/lib/decorators/largeField.d.ts +9 -0
- package/lib/decorators/largeField.js +42 -0
- package/lib/emitter.d.ts +16 -0
- package/lib/emitter.js +58 -0
- package/lib/event-registry/BaseEventRegistry.d.ts +22 -0
- package/lib/event-registry/BaseEventRegistry.js +57 -0
- package/lib/event-registry/EngineEventRegistry.d.ts +19 -0
- package/lib/event-registry/EngineEventRegistry.js +47 -0
- package/lib/event-registry/ModelEventRegistry.d.ts +33 -0
- package/lib/event-registry/ModelEventRegistry.js +79 -0
- package/lib/executor/FlowExecutor.d.ts +26 -0
- package/lib/executor/FlowExecutor.js +262 -0
- package/lib/flow-registry/BaseFlowRegistry.d.ts +46 -0
- package/lib/flow-registry/BaseFlowRegistry.js +86 -0
- package/lib/flow-registry/GlobalFlowRegistry.d.ts +22 -0
- package/lib/flow-registry/GlobalFlowRegistry.js +95 -0
- package/lib/flow-registry/InstanceFlowRegistry.d.ts +21 -0
- package/lib/flow-registry/InstanceFlowRegistry.js +59 -0
- package/lib/flow-registry/index.d.ts +11 -0
- package/lib/flow-registry/index.js +34 -0
- package/lib/flowContext.d.ts +215 -0
- package/lib/flowContext.js +1266 -0
- package/lib/flowEngine.d.ts +340 -0
- package/lib/flowEngine.js +781 -0
- package/lib/flowI18n.d.ts +46 -0
- package/lib/flowI18n.js +117 -0
- package/lib/flowSettings.d.ts +266 -0
- package/lib/flowSettings.js +850 -0
- package/lib/hooks/index.d.ts +14 -0
- package/lib/hooks/index.js +40 -0
- package/lib/hooks/useApplyAutoFlows.d.ts +21 -0
- package/lib/hooks/useApplyAutoFlows.js +62 -0
- package/lib/hooks/useFlowModel.d.ts +29 -0
- package/lib/hooks/useFlowModel.js +72 -0
- package/lib/hooks/useFlowModelById.d.ts +11 -0
- package/lib/hooks/useFlowModelById.js +61 -0
- package/lib/hooks/useFlowSettingsContext.d.ts +20 -0
- package/lib/hooks/useFlowSettingsContext.js +61 -0
- package/lib/hooks/useFlowStep.d.ts +17 -0
- package/lib/hooks/useFlowStep.js +56 -0
- package/lib/hooks/useNiceDropdownMaxHeight.d.ts +13 -0
- package/lib/hooks/useNiceDropdownMaxHeight.js +52 -0
- package/lib/index.d.ts +27 -0
- package/lib/index.js +73 -0
- package/lib/locale/en-US.json +61 -0
- package/lib/locale/index.d.ts +141 -0
- package/lib/locale/index.js +70 -0
- package/lib/locale/zh-CN.json +61 -0
- package/lib/models/CollectionFieldModel.d.ts +50 -0
- package/lib/models/CollectionFieldModel.js +242 -0
- package/lib/models/DisplayItemModel.d.ts +12 -0
- package/lib/models/DisplayItemModel.js +41 -0
- package/lib/models/EditableItemModel.d.ts +12 -0
- package/lib/models/EditableItemModel.js +41 -0
- package/lib/models/FilterableItemModel.d.ts +12 -0
- package/lib/models/FilterableItemModel.js +41 -0
- package/lib/models/flowModel.d.ts +344 -0
- package/lib/models/flowModel.js +1133 -0
- package/lib/models/forkFlowModel.d.ts +83 -0
- package/lib/models/forkFlowModel.js +257 -0
- package/lib/models/index.d.ts +14 -0
- package/lib/models/index.js +40 -0
- package/lib/provider.d.ts +22 -0
- package/lib/provider.js +114 -0
- package/lib/resources/apiResource.d.ts +34 -0
- package/lib/resources/apiResource.js +153 -0
- package/lib/resources/baseRecordResource.d.ts +61 -0
- package/lib/resources/baseRecordResource.js +264 -0
- package/lib/resources/filterItem.d.ts +33 -0
- package/lib/resources/filterItem.js +93 -0
- package/lib/resources/flowResource.d.ts +45 -0
- package/lib/resources/flowResource.js +146 -0
- package/lib/resources/index.d.ts +15 -0
- package/lib/resources/index.js +42 -0
- package/lib/resources/multiRecordResource.d.ts +53 -0
- package/lib/resources/multiRecordResource.js +230 -0
- package/lib/resources/singleRecordResource.d.ts +23 -0
- package/lib/resources/singleRecordResource.js +111 -0
- package/lib/resources/sqlResource.d.ts +73 -0
- package/lib/resources/sqlResource.js +294 -0
- package/lib/runjs-context/contexts/FlowRunJSContext.d.ts +38 -0
- package/lib/runjs-context/contexts/FlowRunJSContext.js +217 -0
- package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.d.ts +16 -0
- package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.js +66 -0
- package/lib/runjs-context/contexts/JSBlockRunJSContext.d.ts +16 -0
- package/lib/runjs-context/contexts/JSBlockRunJSContext.js +78 -0
- package/lib/runjs-context/contexts/JSCollectionActionRunJSContext.d.ts +12 -0
- package/lib/runjs-context/contexts/JSCollectionActionRunJSContext.js +59 -0
- package/lib/runjs-context/contexts/JSFieldRunJSContext.d.ts +16 -0
- package/lib/runjs-context/contexts/JSFieldRunJSContext.js +70 -0
- package/lib/runjs-context/contexts/JSItemRunJSContext.d.ts +16 -0
- package/lib/runjs-context/contexts/JSItemRunJSContext.js +66 -0
- package/lib/runjs-context/contexts/JSRecordActionRunJSContext.d.ts +12 -0
- package/lib/runjs-context/contexts/JSRecordActionRunJSContext.js +61 -0
- package/lib/runjs-context/contexts/LinkageRunJSContext.d.ts +12 -0
- package/lib/runjs-context/contexts/LinkageRunJSContext.js +62 -0
- package/lib/runjs-context/helpers.d.ts +17 -0
- package/lib/runjs-context/helpers.js +79 -0
- package/lib/runjs-context/index.d.ts +19 -0
- package/lib/runjs-context/index.js +57 -0
- package/lib/runjs-context/registry.d.ts +17 -0
- package/lib/runjs-context/registry.js +93 -0
- package/lib/runjs-context/snippets/global/api-request-get.snippet.d.ts +16 -0
- package/lib/runjs-context/snippets/global/api-request-get.snippet.js +42 -0
- package/lib/runjs-context/snippets/global/api-request-post.snippet.d.ts +16 -0
- package/lib/runjs-context/snippets/global/api-request-post.snippet.js +42 -0
- package/lib/runjs-context/snippets/global/console-log-ctx.snippet.d.ts +16 -0
- package/lib/runjs-context/snippets/global/console-log-ctx.snippet.js +41 -0
- package/lib/runjs-context/snippets/global/copy-record-json.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/copy-record-json.snippet.js +42 -0
- package/lib/runjs-context/snippets/global/copy-to-clipboard.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/copy-to-clipboard.snippet.js +42 -0
- package/lib/runjs-context/snippets/global/log-json-record.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/log-json-record.snippet.js +42 -0
- package/lib/runjs-context/snippets/global/message-error.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/message-error.snippet.js +41 -0
- package/lib/runjs-context/snippets/global/message-success.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/message-success.snippet.js +41 -0
- package/lib/runjs-context/snippets/global/notification-open.snippet.d.ts +16 -0
- package/lib/runjs-context/snippets/global/notification-open.snippet.js +43 -0
- package/lib/runjs-context/snippets/global/open-view-dialog.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/open-view-dialog.snippet.js +47 -0
- package/lib/runjs-context/snippets/global/open-view-drawer.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/open-view-drawer.snippet.js +47 -0
- package/lib/runjs-context/snippets/global/requireAsync.snippet.d.ts +16 -0
- package/lib/runjs-context/snippets/global/requireAsync.snippet.js +46 -0
- package/lib/runjs-context/snippets/global/sleep.snippet.d.ts +16 -0
- package/lib/runjs-context/snippets/global/sleep.snippet.js +43 -0
- package/lib/runjs-context/snippets/global/try-catch-async.snippet.d.ts +16 -0
- package/lib/runjs-context/snippets/global/try-catch-async.snippet.js +44 -0
- package/lib/runjs-context/snippets/global/view-navigation-push.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/view-navigation-push.snippet.js +44 -0
- package/lib/runjs-context/snippets/global/window-open.snippet.d.ts +16 -0
- package/lib/runjs-context/snippets/global/window-open.snippet.js +41 -0
- package/lib/runjs-context/snippets/index.d.ts +11 -0
- package/lib/runjs-context/snippets/index.js +94 -0
- package/lib/runjs-context/snippets/libs/echarts-init.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/libs/echarts-init.snippet.js +46 -0
- package/lib/runjs-context/snippets/scene/actions/collection-selected-count.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/actions/collection-selected-count.snippet.js +44 -0
- package/lib/runjs-context/snippets/scene/actions/iterate-selected-rows.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/actions/iterate-selected-rows.snippet.js +43 -0
- package/lib/runjs-context/snippets/scene/actions/record-id-message.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/actions/record-id-message.snippet.js +43 -0
- package/lib/runjs-context/snippets/scene/actions/run-action-basic.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/actions/run-action-basic.snippet.js +40 -0
- package/lib/runjs-context/snippets/scene/jsblock/add-event-listener.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/jsblock/add-event-listener.snippet.js +46 -0
- package/lib/runjs-context/snippets/scene/jsblock/append-style.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/jsblock/append-style.snippet.js +42 -0
- package/lib/runjs-context/snippets/scene/jsblock/jsx-mount.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/jsblock/jsx-mount.snippet.js +46 -0
- package/lib/runjs-context/snippets/scene/jsblock/jsx-unmount.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/jsblock/jsx-unmount.snippet.js +41 -0
- package/lib/runjs-context/snippets/scene/jsblock/render-basic.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/jsblock/render-basic.snippet.js +41 -0
- package/lib/runjs-context/snippets/scene/jsblock/render-button-handler.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/jsblock/render-button-handler.snippet.js +46 -0
- package/lib/runjs-context/snippets/scene/jsblock/render-card.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/jsblock/render-card.snippet.js +45 -0
- package/lib/runjs-context/snippets/scene/jsblock/render-react.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/jsblock/render-react.snippet.js +56 -0
- package/lib/runjs-context/snippets/scene/jsfield/color-by-value.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/jsfield/color-by-value.snippet.js +42 -0
- package/lib/runjs-context/snippets/scene/jsfield/format-number.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/jsfield/format-number.snippet.js +41 -0
- package/lib/runjs-context/snippets/scene/jsfield/innerHTML-value.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/jsfield/innerHTML-value.snippet.js +40 -0
- package/lib/runjs-context/snippets/scene/jsitem/render-basic.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/jsitem/render-basic.snippet.js +44 -0
- package/lib/runjs-context/snippets/scene/linkage/set-disabled.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/linkage/set-disabled.snippet.js +60 -0
- package/lib/runjs-context/snippets/scene/linkage/set-field-value.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/linkage/set-field-value.snippet.js +59 -0
- package/lib/runjs-context/snippets/scene/linkage/set-required.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/linkage/set-required.snippet.js +60 -0
- package/lib/runjs-context/snippets/scene/linkage/toggle-visible.snippet.d.ts +15 -0
- package/lib/runjs-context/snippets/scene/linkage/toggle-visible.snippet.js +60 -0
- package/lib/runjs-context/snippets/types.d.ts +16 -0
- package/lib/runjs-context/snippets/types.js +24 -0
- package/lib/types.d.ts +398 -0
- package/lib/types.js +43 -0
- package/lib/utils/autoFlowError.d.ts +16 -0
- package/lib/utils/autoFlowError.js +53 -0
- package/lib/utils/constants.d.ts +29 -0
- package/lib/utils/constants.js +77 -0
- package/lib/utils/context.d.ts +40 -0
- package/lib/utils/context.js +63 -0
- package/lib/utils/createCollectionContextMeta.d.ts +11 -0
- package/lib/utils/createCollectionContextMeta.js +117 -0
- package/lib/utils/exceptions.d.ts +22 -0
- package/lib/utils/exceptions.js +62 -0
- package/lib/utils/flow-definitions.d.ts +11 -0
- package/lib/utils/flow-definitions.js +40 -0
- package/lib/utils/index.d.ts +22 -0
- package/lib/utils/index.js +117 -0
- package/lib/utils/inheritance.d.ts +16 -0
- package/lib/utils/inheritance.js +53 -0
- package/lib/utils/params-resolvers.d.ts +51 -0
- package/lib/utils/params-resolvers.js +309 -0
- package/lib/utils/parsePathnameToViewParams.d.ts +34 -0
- package/lib/utils/parsePathnameToViewParams.js +84 -0
- package/lib/utils/safeGlobals.d.ts +16 -0
- package/lib/utils/safeGlobals.js +179 -0
- package/lib/utils/schema-utils.d.ts +40 -0
- package/lib/utils/schema-utils.js +161 -0
- package/lib/utils/serverContextParams.d.ts +28 -0
- package/lib/utils/serverContextParams.js +106 -0
- package/lib/utils/setupRuntimeContextSteps.d.ts +19 -0
- package/lib/utils/setupRuntimeContextSteps.js +88 -0
- package/lib/utils/translation.d.ts +18 -0
- package/lib/utils/translation.js +58 -0
- package/lib/utils/variablesParams.d.ts +51 -0
- package/lib/utils/variablesParams.js +150 -0
- package/lib/views/DialogComponent.d.ts +22 -0
- package/lib/views/DialogComponent.js +98 -0
- package/lib/views/DrawerComponent.d.ts +11 -0
- package/lib/views/DrawerComponent.js +101 -0
- package/lib/views/FlowView.d.ts +76 -0
- package/lib/views/FlowView.js +81 -0
- package/lib/views/PageComponent.d.ts +10 -0
- package/lib/views/PageComponent.js +167 -0
- package/lib/views/ViewNavigation.d.ts +45 -0
- package/lib/views/ViewNavigation.js +97 -0
- package/lib/views/createViewMeta.d.ts +16 -0
- package/lib/views/createViewMeta.js +171 -0
- package/lib/views/index.d.ts +13 -0
- package/lib/views/index.js +48 -0
- package/lib/views/useDialog.d.ts +32 -0
- package/lib/views/useDialog.js +199 -0
- package/lib/views/useDrawer.d.ts +33 -0
- package/lib/views/useDrawer.js +206 -0
- package/lib/views/usePage.d.ts +32 -0
- package/lib/views/usePage.js +193 -0
- package/lib/views/usePatchElement.d.ts +10 -0
- package/lib/views/usePatchElement.js +54 -0
- package/lib/views/usePopover.d.ts +17 -0
- package/lib/views/usePopover.js +159 -0
- package/package.json +37 -0
- package/src/ContextPathProxy.ts +45 -0
- package/src/ElementProxy.ts +69 -0
- package/src/FlowContextProvider.tsx +40 -0
- package/src/FlowDefinition.ts +275 -0
- package/src/JSRunner.ts +84 -0
- package/src/ReactView.tsx +104 -0
- package/src/ViewScopedFlowEngine.ts +75 -0
- package/src/__tests__/ElementProxy.test.ts +51 -0
- package/src/__tests__/JSRunner.test.ts +92 -0
- package/src/__tests__/ReactView.test.tsx +63 -0
- package/src/__tests__/context-path-proxy.test.ts +35 -0
- package/src/__tests__/flow-engine.test.ts +189 -0
- package/src/__tests__/flowContext.test.ts +2012 -0
- package/src/__tests__/flowEngine.saveModel.test.ts +171 -0
- package/src/__tests__/flowI18n.test.ts +28 -0
- package/src/__tests__/flowModel.getFlows.test.ts +61 -0
- package/src/__tests__/flowModel.openView.navigation.test.ts +78 -0
- package/src/__tests__/flowRuntimeContext.test.ts +187 -0
- package/src/__tests__/flowSettings.open.test.tsx +1920 -0
- package/src/__tests__/flowSettings.test.ts +566 -0
- package/src/__tests__/globalFlowRegistry.test.ts +77 -0
- package/src/__tests__/isFieldInterfaceMatch.test.ts +51 -0
- package/src/__tests__/metaTreeNodeCache.test.ts +234 -0
- package/src/__tests__/path-aggregation.test.ts +85 -0
- package/src/__tests__/provider.test.tsx +28 -0
- package/src/__tests__/renderHiddenInConfig.test.tsx +91 -0
- package/src/__tests__/runjsContext.test.ts +60 -0
- package/src/__tests__/viewScopedFlowEngine.test.ts +212 -0
- package/src/acl/Acl.tsx +109 -0
- package/src/acl/__tests__/Acl.test.tsx +72 -0
- package/src/action-registry/BaseActionRegistry.ts +46 -0
- package/src/action-registry/EngineActionRegistry.ts +32 -0
- package/src/action-registry/ModelActionRegistry.ts +75 -0
- package/src/action-registry/__tests__/engineActionRegistry.test.ts +43 -0
- package/src/action-registry/__tests__/modelActionRegistry.test.ts +107 -0
- package/src/components/DynamicFlowsEditor.tsx +318 -0
- package/src/components/FieldModelRenderer.tsx +62 -0
- package/src/components/FlowContextSelector.tsx +255 -0
- package/src/components/FlowErrorFallback.tsx +316 -0
- package/src/components/FlowModelRenderer.tsx +428 -0
- package/src/components/FormItem.tsx +130 -0
- package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +226 -0
- package/src/components/common/FlowSettingsButton.tsx +30 -0
- package/src/components/common/index.ts +10 -0
- package/src/components/common/withFlowDesignMode.tsx +49 -0
- package/src/components/dnd/getMousePositionOnElement.ts +115 -0
- package/src/components/dnd/index.tsx +128 -0
- package/src/components/dnd/moveBlock.ts +379 -0
- package/src/components/index.ts +20 -0
- package/src/components/settings/independents/dropdown/FlowsDropdownButton.tsx +279 -0
- package/src/components/settings/independents/dropdown/index.ts +10 -0
- package/src/components/settings/independents/index.ts +2 -0
- package/src/components/settings/index.ts +11 -0
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +617 -0
- package/src/components/settings/wrappers/contextual/FlowsContextMenu.tsx +292 -0
- package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +655 -0
- package/src/components/settings/wrappers/contextual/StepRequiredSettingsDialog.tsx +446 -0
- package/src/components/settings/wrappers/contextual/StepSettings.tsx +109 -0
- package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +217 -0
- package/src/components/settings/wrappers/contextual/StepSettingsDrawer.tsx +32 -0
- package/src/components/settings/wrappers/contextual/index.ts +15 -0
- package/src/components/settings/wrappers/embedded/FlowSettings.tsx +258 -0
- package/src/components/settings/wrappers/embedded/FlowsSettings.tsx +111 -0
- package/src/components/settings/wrappers/embedded/FlowsSettingsContent.tsx +96 -0
- package/src/components/settings/wrappers/embedded/index.ts +11 -0
- package/src/components/settings/wrappers/index.ts +5 -0
- package/src/components/subModel/AddSubModelButton.tsx +575 -0
- package/src/components/subModel/LazyDropdown.tsx +714 -0
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +1185 -0
- package/src/components/subModel/__tests__/buildWrapperFieldChildren.test.ts +192 -0
- package/src/components/subModel/__tests__/utils.test.ts +425 -0
- package/src/components/subModel/index.ts +12 -0
- package/src/components/subModel/utils.ts +278 -0
- package/src/components/variables/InlineVariableTag.tsx +97 -0
- package/src/components/variables/SlateVariableEditor.tsx +384 -0
- package/src/components/variables/VariableInput.tsx +342 -0
- package/src/components/variables/VariableTag.tsx +123 -0
- package/src/components/variables/VariableTrigger.tsx +116 -0
- package/src/components/variables/__tests__/FlowContextSelector.test.tsx +553 -0
- package/src/components/variables/__tests__/VariableInput.test.tsx +550 -0
- package/src/components/variables/__tests__/VariableTag.test.tsx +347 -0
- package/src/components/variables/__tests__/test-utils.tsx +62 -0
- package/src/components/variables/__tests__/utils.test.ts +310 -0
- package/src/components/variables/index.ts +16 -0
- package/src/components/variables/types.ts +100 -0
- package/src/components/variables/useResolvedMetaTree.ts +76 -0
- package/src/components/variables/utils.ts +192 -0
- package/src/data-source/__tests__/collection.test.ts +58 -0
- package/src/data-source/__tests__/index.test.ts +82 -0
- package/src/data-source/__tests__/jioToJoiSchema.test.ts +56 -0
- package/src/data-source/index.ts +812 -0
- package/src/data-source/jioToJoiSchema.ts +103 -0
- package/src/decorators/index.ts +10 -0
- package/src/decorators/largeField.ts +14 -0
- package/src/emitter.ts +33 -0
- package/src/event-registry/BaseEventRegistry.ts +40 -0
- package/src/event-registry/EngineEventRegistry.ts +26 -0
- package/src/event-registry/ModelEventRegistry.ts +69 -0
- package/src/event-registry/__tests__/engineEventRegistry.test.ts +48 -0
- package/src/executor/FlowExecutor.ts +256 -0
- package/src/executor/__tests__/eventStep.test.ts +157 -0
- package/src/executor/__tests__/flowExecutor.test.ts +163 -0
- package/src/flow-registry/BaseFlowRegistry.ts +91 -0
- package/src/flow-registry/GlobalFlowRegistry.ts +82 -0
- package/src/flow-registry/InstanceFlowRegistry.ts +39 -0
- package/src/flow-registry/__tests__/globalFlowRegistry.test.ts +141 -0
- package/src/flow-registry/__tests__/instance-and-global-registry.test.ts +67 -0
- package/src/flow-registry/__tests__/instanceFlowRegistry.test.ts +83 -0
- package/src/flow-registry/index.ts +12 -0
- package/src/flowContext.ts +1639 -0
- package/src/flowEngine.ts +905 -0
- package/src/flowI18n.ts +96 -0
- package/src/flowSettings.ts +1045 -0
- package/src/hooks/index.ts +15 -0
- package/src/hooks/useApplyAutoFlows.ts +51 -0
- package/src/hooks/useFlowModel.tsx +59 -0
- package/src/hooks/useFlowModelById.ts +37 -0
- package/src/hooks/useFlowSettingsContext.tsx +37 -0
- package/src/hooks/useFlowStep.tsx +19 -0
- package/src/hooks/useNiceDropdownMaxHeight.ts +34 -0
- package/src/index.ts +38 -0
- package/src/locale/en-US.json +61 -0
- package/src/locale/index.ts +38 -0
- package/src/locale/zh-CN.json +61 -0
- package/src/models/CollectionFieldModel.tsx +269 -0
- package/src/models/DisplayItemModel.tsx +13 -0
- package/src/models/EditableItemModel.tsx +13 -0
- package/src/models/FilterableItemModel.tsx +13 -0
- package/src/models/__tests__/CollectionFieldModel.test.ts +122 -0
- package/src/models/__tests__/defaultParams-on-create.test.ts +83 -0
- package/src/models/__tests__/flow-model-oninit.test.ts +44 -0
- package/src/models/__tests__/flowModel.actions.integration.test.ts +100 -0
- package/src/models/__tests__/flowModel.getFlows.sort.test.ts +100 -0
- package/src/models/__tests__/flowModel.test.ts +2746 -0
- package/src/models/__tests__/flowRegistry.test.ts +512 -0
- package/src/models/__tests__/forkFlowModel.test.ts +1047 -0
- package/src/models/__tests__/model-actions.test.ts +70 -0
- package/src/models/__tests__/model-events.test.ts +69 -0
- package/src/models/flowModel.tsx +1398 -0
- package/src/models/forkFlowModel.ts +287 -0
- package/src/models/index.ts +17 -0
- package/src/provider.tsx +101 -0
- package/src/resources/__tests__/apiResource.test.ts +201 -0
- package/src/resources/__tests__/baseRecordResource.test.ts +262 -0
- package/src/resources/__tests__/filterItem.test.ts +260 -0
- package/src/resources/__tests__/flowResource.test.ts +127 -0
- package/src/resources/apiResource.ts +148 -0
- package/src/resources/baseRecordResource.ts +279 -0
- package/src/resources/filterItem.ts +74 -0
- package/src/resources/flowResource.ts +143 -0
- package/src/resources/index.ts +17 -0
- package/src/resources/multiRecordResource.ts +219 -0
- package/src/resources/singleRecordResource.ts +83 -0
- package/src/resources/sqlResource.ts +299 -0
- package/src/runjs-context/contexts/FlowRunJSContext.ts +190 -0
- package/src/runjs-context/contexts/FormJSFieldItemRunJSContext.ts +39 -0
- package/src/runjs-context/contexts/JSBlockRunJSContext.ts +52 -0
- package/src/runjs-context/contexts/JSCollectionActionRunJSContext.ts +32 -0
- package/src/runjs-context/contexts/JSFieldRunJSContext.ts +43 -0
- package/src/runjs-context/contexts/JSItemRunJSContext.ts +39 -0
- package/src/runjs-context/contexts/JSRecordActionRunJSContext.ts +34 -0
- package/src/runjs-context/contexts/LinkageRunJSContext.ts +35 -0
- package/src/runjs-context/helpers.ts +56 -0
- package/src/runjs-context/index.ts +20 -0
- package/src/runjs-context/registry.ts +65 -0
- package/src/runjs-context/snippets/global/api-request-get.snippet.ts +20 -0
- package/src/runjs-context/snippets/global/api-request-post.snippet.ts +20 -0
- package/src/runjs-context/snippets/global/console-log-ctx.snippet.ts +19 -0
- package/src/runjs-context/snippets/global/copy-record-json.snippet.ts +21 -0
- package/src/runjs-context/snippets/global/copy-to-clipboard.snippet.ts +21 -0
- package/src/runjs-context/snippets/global/log-json-record.snippet.ts +21 -0
- package/src/runjs-context/snippets/global/message-error.snippet.ts +20 -0
- package/src/runjs-context/snippets/global/message-success.snippet.ts +20 -0
- package/src/runjs-context/snippets/global/notification-open.snippet.ts +21 -0
- package/src/runjs-context/snippets/global/open-view-dialog.snippet.ts +26 -0
- package/src/runjs-context/snippets/global/open-view-drawer.snippet.ts +26 -0
- package/src/runjs-context/snippets/global/requireAsync.snippet.ts +24 -0
- package/src/runjs-context/snippets/global/sleep.snippet.ts +21 -0
- package/src/runjs-context/snippets/global/try-catch-async.snippet.ts +22 -0
- package/src/runjs-context/snippets/global/view-navigation-push.snippet.ts +23 -0
- package/src/runjs-context/snippets/global/window-open.snippet.ts +19 -0
- package/src/runjs-context/snippets/index.ts +59 -0
- package/src/runjs-context/snippets/libs/echarts-init.snippet.ts +24 -0
- package/src/runjs-context/snippets/scene/actions/collection-selected-count.snippet.ts +22 -0
- package/src/runjs-context/snippets/scene/actions/iterate-selected-rows.snippet.ts +21 -0
- package/src/runjs-context/snippets/scene/actions/record-id-message.snippet.ts +21 -0
- package/src/runjs-context/snippets/scene/actions/run-action-basic.snippet.ts +18 -0
- package/src/runjs-context/snippets/scene/jsblock/add-event-listener.snippet.ts +29 -0
- package/src/runjs-context/snippets/scene/jsblock/append-style.snippet.ts +20 -0
- package/src/runjs-context/snippets/scene/jsblock/jsx-mount.snippet.ts +24 -0
- package/src/runjs-context/snippets/scene/jsblock/jsx-unmount.snippet.ts +19 -0
- package/src/runjs-context/snippets/scene/jsblock/render-basic.snippet.ts +24 -0
- package/src/runjs-context/snippets/scene/jsblock/render-button-handler.snippet.ts +24 -0
- package/src/runjs-context/snippets/scene/jsblock/render-card.snippet.ts +30 -0
- package/src/runjs-context/snippets/scene/jsblock/render-react.snippet.ts +34 -0
- package/src/runjs-context/snippets/scene/jsfield/color-by-value.snippet.ts +20 -0
- package/src/runjs-context/snippets/scene/jsfield/format-number.snippet.ts +19 -0
- package/src/runjs-context/snippets/scene/jsfield/innerHTML-value.snippet.ts +18 -0
- package/src/runjs-context/snippets/scene/jsitem/render-basic.snippet.ts +27 -0
- package/src/runjs-context/snippets/scene/linkage/set-disabled.snippet.ts +38 -0
- package/src/runjs-context/snippets/scene/linkage/set-field-value.snippet.ts +37 -0
- package/src/runjs-context/snippets/scene/linkage/set-required.snippet.ts +38 -0
- package/src/runjs-context/snippets/scene/linkage/toggle-visible.snippet.ts +38 -0
- package/src/runjs-context/snippets/types.ts +17 -0
- package/src/types.ts +474 -0
- package/src/utils/__tests__/context.test.ts +93 -0
- package/src/utils/__tests__/params-resolvers.test.ts +652 -0
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +104 -0
- package/src/utils/__tests__/safeGlobals.test.ts +29 -0
- package/src/utils/__tests__/utils.test.ts +1021 -0
- package/src/utils/__tests__/variablesParams.test.ts +52 -0
- package/src/utils/autoFlowError.ts +29 -0
- package/src/utils/constants.ts +60 -0
- package/src/utils/context.ts +70 -0
- package/src/utils/createCollectionContextMeta.ts +122 -0
- package/src/utils/exceptions.ts +36 -0
- package/src/utils/flow-definitions.ts +16 -0
- package/src/utils/index.ts +63 -0
- package/src/utils/inheritance.ts +39 -0
- package/src/utils/params-resolvers.ts +482 -0
- package/src/utils/parsePathnameToViewParams.ts +103 -0
- package/src/utils/safeGlobals.ts +188 -0
- package/src/utils/schema-utils.ts +201 -0
- package/src/utils/serverContextParams.ts +111 -0
- package/src/utils/setupRuntimeContextSteps.ts +89 -0
- package/src/utils/translation.ts +37 -0
- package/src/utils/variablesParams.ts +175 -0
- package/src/views/DialogComponent.tsx +79 -0
- package/src/views/DrawerComponent.tsx +72 -0
- package/src/views/FlowView.tsx +103 -0
- package/src/views/PageComponent.tsx +150 -0
- package/src/views/ViewNavigation.ts +122 -0
- package/src/views/__tests__/FlowView.test.ts +31 -0
- package/src/views/__tests__/ViewNavigation.test.ts +191 -0
- package/src/views/__tests__/usePatchElement.test.tsx +28 -0
- package/src/views/createViewMeta.ts +157 -0
- package/src/views/index.tsx +14 -0
- package/src/views/useDialog.tsx +192 -0
- package/src/views/useDrawer.tsx +205 -0
- package/src/views/usePage.tsx +182 -0
- package/src/views/usePatchElement.tsx +27 -0
- package/src/views/usePopover.tsx +131 -0
|
@@ -0,0 +1,219 @@
|
|
|
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 { observable } from '@formily/reactive';
|
|
11
|
+
import { AxiosRequestConfig } from 'axios';
|
|
12
|
+
import _ from 'lodash';
|
|
13
|
+
import { BaseRecordResource } from './baseRecordResource';
|
|
14
|
+
|
|
15
|
+
export class MultiRecordResource<TDataItem = any> extends BaseRecordResource<TDataItem[]> {
|
|
16
|
+
protected _data = observable.ref<TDataItem[]>([]);
|
|
17
|
+
protected _meta = observable.ref<Record<string, any>>({});
|
|
18
|
+
private refreshTimer: NodeJS.Timeout | null = null;
|
|
19
|
+
protected createActionOptions = {};
|
|
20
|
+
protected updateActionOptions = {};
|
|
21
|
+
protected _refreshActionName = 'list';
|
|
22
|
+
|
|
23
|
+
// 请求配置 - 与 APIClient 接口保持一致
|
|
24
|
+
protected request = {
|
|
25
|
+
// url: null as string | null,
|
|
26
|
+
method: 'get' as string,
|
|
27
|
+
params: {
|
|
28
|
+
filter: {} as Record<string, any>,
|
|
29
|
+
filterByTk: null as string | number | string[] | number[] | null,
|
|
30
|
+
appends: [] as string[],
|
|
31
|
+
fields: [] as string[],
|
|
32
|
+
sort: null as string[] | null,
|
|
33
|
+
except: null as string[] | null,
|
|
34
|
+
whitelist: null as string[] | null,
|
|
35
|
+
blacklist: null as string[] | null,
|
|
36
|
+
page: 1 as number,
|
|
37
|
+
pageSize: 20 as number,
|
|
38
|
+
} as Record<string, any>,
|
|
39
|
+
headers: {} as Record<string, any>,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
get supportsFilter() {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
setCreateActionOptions(options: AxiosRequestConfig) {
|
|
47
|
+
this.createActionOptions = options;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
setUpdateActionOptions(options: AxiosRequestConfig) {
|
|
52
|
+
this.updateActionOptions = options;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setSelectedRows(selectedRows: TDataItem[]) {
|
|
57
|
+
this.setMeta({ selectedRows });
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
getSelectedRows(): TDataItem[] {
|
|
62
|
+
return this.getMeta('selectedRows') || [];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getCount(): number {
|
|
66
|
+
return this.getMeta('count');
|
|
67
|
+
}
|
|
68
|
+
setPage(page: number) {
|
|
69
|
+
this.addRequestParameter('page', page);
|
|
70
|
+
return this.setMeta({ page });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
getPage(): number {
|
|
74
|
+
return this.getMeta('page');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
setPageSize(pageSize: number) {
|
|
78
|
+
this.addRequestParameter('pageSize', pageSize);
|
|
79
|
+
return this.setMeta({ pageSize });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
getPageSize(): number {
|
|
83
|
+
return this.getMeta('pageSize');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
getTotalPage(): number {
|
|
87
|
+
return this.getMeta('totalPage');
|
|
88
|
+
}
|
|
89
|
+
getCell(rowIndex: number, columnKey: string): TDataItem | undefined {
|
|
90
|
+
const data = this.getData();
|
|
91
|
+
return data?.[rowIndex]?.[columnKey];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async next(): Promise<void> {
|
|
95
|
+
this.request.params.page += 1;
|
|
96
|
+
await this.refresh();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async previous(): Promise<void> {
|
|
100
|
+
if (this.request.params.page > 1) {
|
|
101
|
+
this.request.params.page -= 1;
|
|
102
|
+
await this.refresh();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async goto(page: number): Promise<void> {
|
|
107
|
+
if (page > 0) {
|
|
108
|
+
this.request.params.page = page;
|
|
109
|
+
await this.refresh();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async create(data: TDataItem, options?: AxiosRequestConfig): Promise<void> {
|
|
114
|
+
const config = this.mergeRequestConfig({ data }, this.createActionOptions, options);
|
|
115
|
+
await this.runAction('create', config);
|
|
116
|
+
await this.refresh();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async get(filterByTk: any): Promise<TDataItem | undefined> {
|
|
120
|
+
const options = {
|
|
121
|
+
params: {
|
|
122
|
+
filterByTk,
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
const { data } = await this.runAction<TDataItem, any>('get', {
|
|
126
|
+
...options,
|
|
127
|
+
});
|
|
128
|
+
return data;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async update(filterByTk: string | number, data: Partial<TDataItem>, options?: AxiosRequestConfig): Promise<void> {
|
|
132
|
+
const config = this.mergeRequestConfig(
|
|
133
|
+
{
|
|
134
|
+
params: {
|
|
135
|
+
filterByTk,
|
|
136
|
+
},
|
|
137
|
+
data,
|
|
138
|
+
},
|
|
139
|
+
this.updateActionOptions,
|
|
140
|
+
options,
|
|
141
|
+
);
|
|
142
|
+
await this.runAction('update', config);
|
|
143
|
+
await this.refresh();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async destroySelectedRows(): Promise<void> {
|
|
147
|
+
const selectedRows = this.getSelectedRows();
|
|
148
|
+
if (selectedRows.length === 0) {
|
|
149
|
+
throw new Error('No rows selected for deletion.');
|
|
150
|
+
}
|
|
151
|
+
await this.destroy(selectedRows);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async destroy(
|
|
155
|
+
filterByTk: string | number | string[] | number[] | TDataItem | TDataItem[],
|
|
156
|
+
options?: AxiosRequestConfig,
|
|
157
|
+
): Promise<void> {
|
|
158
|
+
const config = this.mergeRequestConfig(
|
|
159
|
+
{
|
|
160
|
+
params: {
|
|
161
|
+
filterByTk: _.castArray(filterByTk).map((item) => {
|
|
162
|
+
return typeof item === 'object' ? item['id'] : item; // TODO: ID 字段还需要根据实际情况更改
|
|
163
|
+
}),
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
options,
|
|
167
|
+
);
|
|
168
|
+
await this.runAction('destroy', config);
|
|
169
|
+
await this.refresh();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
setItem(index: number, newDataItem: TDataItem) {
|
|
173
|
+
const oldData = this.getData();
|
|
174
|
+
const newData = oldData.slice(); // 浅拷贝
|
|
175
|
+
newData[index] = { ...newDataItem };
|
|
176
|
+
this.setData(newData);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* 在同一个事件循环内多次调用 refresh 方法时,只有最后一次调用会生效。避免触发多次相同的接口请求。
|
|
181
|
+
* @returns
|
|
182
|
+
*/
|
|
183
|
+
async refresh(): Promise<void> {
|
|
184
|
+
// 清除之前的定时器,确保只有最后一次调用生效
|
|
185
|
+
if (this.refreshTimer) {
|
|
186
|
+
clearTimeout(this.refreshTimer);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// 设置新的定时器,在下一个事件循环执行
|
|
190
|
+
return new Promise<void>((resolve, reject) => {
|
|
191
|
+
this.refreshTimer = setTimeout(async () => {
|
|
192
|
+
try {
|
|
193
|
+
this.clearError();
|
|
194
|
+
this.loading = true;
|
|
195
|
+
const { data, meta } = await this.runAction<TDataItem[], any>(this._refreshActionName, {
|
|
196
|
+
method: 'get',
|
|
197
|
+
...this.getRefreshRequestOptions(),
|
|
198
|
+
});
|
|
199
|
+
this.setData(data).setMeta(meta);
|
|
200
|
+
if (meta?.page) {
|
|
201
|
+
this.setPage(meta.page);
|
|
202
|
+
}
|
|
203
|
+
if (meta?.pageSize) {
|
|
204
|
+
this.setPageSize(meta.pageSize);
|
|
205
|
+
}
|
|
206
|
+
this.emit('refresh');
|
|
207
|
+
this.loading = false;
|
|
208
|
+
resolve();
|
|
209
|
+
} catch (error) {
|
|
210
|
+
this.setError(error);
|
|
211
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
212
|
+
} finally {
|
|
213
|
+
this.refreshTimer = null;
|
|
214
|
+
this.loading = false;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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 { AxiosRequestConfig } from 'axios';
|
|
11
|
+
import _ from 'lodash';
|
|
12
|
+
import { BaseRecordResource } from './baseRecordResource';
|
|
13
|
+
|
|
14
|
+
export class SingleRecordResource<TData = any> extends BaseRecordResource<TData> {
|
|
15
|
+
isNewRecord = false;
|
|
16
|
+
protected saveActionOptions = {};
|
|
17
|
+
protected _refreshActionName = 'get';
|
|
18
|
+
|
|
19
|
+
get supportsFilter() {
|
|
20
|
+
return !this.isNewRecord;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
setSaveActionOptions(options: AxiosRequestConfig) {
|
|
24
|
+
this.saveActionOptions = options;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
setFilterByTk(filterByTk: any) {
|
|
29
|
+
this.isNewRecord = false;
|
|
30
|
+
return super.setFilterByTk(filterByTk);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async save(data: TData, options?: AxiosRequestConfig & { refresh?: boolean }): Promise<void> {
|
|
34
|
+
const config = this.mergeRequestConfig(this.saveActionOptions, _.omit(options, ['refresh']));
|
|
35
|
+
let actionName = 'create';
|
|
36
|
+
// 如果有 filterByTk,则表示是更新操作
|
|
37
|
+
if (!this.isNewRecord) {
|
|
38
|
+
config.params = config.params || {};
|
|
39
|
+
config.params.filterByTk = this.getFilterByTk();
|
|
40
|
+
actionName = 'update';
|
|
41
|
+
}
|
|
42
|
+
await this.runAction(actionName, {
|
|
43
|
+
...config,
|
|
44
|
+
data,
|
|
45
|
+
});
|
|
46
|
+
if (options?.refresh !== false) {
|
|
47
|
+
await this.refresh();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async destroy(options?: AxiosRequestConfig): Promise<void> {
|
|
52
|
+
const config = this.mergeRequestConfig(
|
|
53
|
+
{
|
|
54
|
+
params: {
|
|
55
|
+
filterByTk: this.request.params.filterByTk,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
options,
|
|
59
|
+
);
|
|
60
|
+
await this.runAction('destroy', config);
|
|
61
|
+
this.setData(null);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async refresh(): Promise<void> {
|
|
65
|
+
this.clearError();
|
|
66
|
+
// 如果没有设置 filterByTk,则不执行刷新操作
|
|
67
|
+
// 这是为了避免在没有指定记录的情况下进行不必要的 API 调用
|
|
68
|
+
if (this.isNewRecord) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const { data, meta } = await this.runAction<TData, any>(this._refreshActionName, {
|
|
73
|
+
method: 'get',
|
|
74
|
+
...this.getRefreshRequestOptions(),
|
|
75
|
+
});
|
|
76
|
+
this.setData(data).setMeta(meta);
|
|
77
|
+
this.emit('refresh');
|
|
78
|
+
} catch (error) {
|
|
79
|
+
this.setError(error);
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
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 { observable } from '@formily/reactive';
|
|
11
|
+
import _ from 'lodash';
|
|
12
|
+
import { FlowContext, FlowEngineContext } from '../flowContext';
|
|
13
|
+
import { BaseRecordResource } from './baseRecordResource';
|
|
14
|
+
|
|
15
|
+
type SQLRunOptions = {
|
|
16
|
+
bind?: Record<string, any>;
|
|
17
|
+
type?: 'selectVar' | 'selectRow' | 'selectRows';
|
|
18
|
+
dataSourceKey?: string;
|
|
19
|
+
filter?: Record<string, any>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type SQLSaveOptions = {
|
|
23
|
+
uid: string;
|
|
24
|
+
sql: string;
|
|
25
|
+
dataSourceKey?: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function transformSQL(template: string) {
|
|
29
|
+
let index = 1;
|
|
30
|
+
const bind = {};
|
|
31
|
+
|
|
32
|
+
const sql = template.replace(/{{\s*([^}]+)\s*}}/g, (_, expr) => {
|
|
33
|
+
const key = `__var${index}`;
|
|
34
|
+
bind[key] = `{{${expr.trim()}}}`;
|
|
35
|
+
index++;
|
|
36
|
+
return `$${key}`;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return { sql, bind };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class FlowSQLRepository {
|
|
43
|
+
protected ctx: FlowEngineContext;
|
|
44
|
+
|
|
45
|
+
constructor(ctx: FlowEngineContext) {
|
|
46
|
+
this.ctx = new FlowContext() as FlowEngineContext;
|
|
47
|
+
this.ctx.addDelegate(ctx);
|
|
48
|
+
this.ctx.defineProperty('offset', {
|
|
49
|
+
get: () => 0,
|
|
50
|
+
cache: false,
|
|
51
|
+
});
|
|
52
|
+
this.ctx.defineProperty('limit', {
|
|
53
|
+
get: () => 20,
|
|
54
|
+
cache: false,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async run(sql: string, options: SQLRunOptions = {}) {
|
|
59
|
+
const result = transformSQL(sql);
|
|
60
|
+
const bind = await this.ctx.resolveJsonTemplate(result.bind);
|
|
61
|
+
const { data } = await this.ctx.api.request({
|
|
62
|
+
method: 'POST',
|
|
63
|
+
url: 'flowSql:run',
|
|
64
|
+
data: {
|
|
65
|
+
sql: result.sql,
|
|
66
|
+
...options,
|
|
67
|
+
bind: {
|
|
68
|
+
...bind,
|
|
69
|
+
...options.bind,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
return data?.data;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async save(data: SQLSaveOptions) {
|
|
77
|
+
await this.ctx.api.request({
|
|
78
|
+
method: 'POST',
|
|
79
|
+
url: 'flowSql:save',
|
|
80
|
+
data: {
|
|
81
|
+
...data,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async runById(uid: string, options?: SQLRunOptions) {
|
|
87
|
+
const response = await this.ctx.api.request({
|
|
88
|
+
method: 'GET',
|
|
89
|
+
url: 'flowSql:getBind',
|
|
90
|
+
params: {
|
|
91
|
+
uid,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
const bind = await this.ctx.resolveJsonTemplate(response.data.data || {});
|
|
95
|
+
const { data } = await this.ctx.api.request({
|
|
96
|
+
method: 'POST',
|
|
97
|
+
url: 'flowSql:runById',
|
|
98
|
+
data: {
|
|
99
|
+
uid,
|
|
100
|
+
...options,
|
|
101
|
+
bind: {
|
|
102
|
+
...bind,
|
|
103
|
+
...options.bind,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
return data?.data;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async destroy(uid: string) {
|
|
111
|
+
await this.ctx.api.request({
|
|
112
|
+
url: 'flowSql:destroy',
|
|
113
|
+
params: {
|
|
114
|
+
filterByTk: uid,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export class SQLResource<TData = any> extends BaseRecordResource<TData> {
|
|
121
|
+
protected _data = observable.ref<TData>(null);
|
|
122
|
+
protected _meta = observable.ref<Record<string, any>>({});
|
|
123
|
+
private refreshTimer: NodeJS.Timeout | null = null;
|
|
124
|
+
private _debugEnabled = false;
|
|
125
|
+
private _sql: string;
|
|
126
|
+
|
|
127
|
+
// 请求配置 - 与 APIClient 接口保持一致
|
|
128
|
+
protected request = {
|
|
129
|
+
// url: null as string | null,
|
|
130
|
+
method: 'post' as string,
|
|
131
|
+
params: {} as Record<string, any>,
|
|
132
|
+
data: {} as Record<string, any>,
|
|
133
|
+
headers: {} as Record<string, any>,
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
get refreshActionName() {
|
|
137
|
+
return this._debugEnabled ? 'run' : 'runById';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
get supportsFilter() {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
constructor(context: FlowEngineContext) {
|
|
145
|
+
super(context);
|
|
146
|
+
context.defineProperty('limit', {
|
|
147
|
+
get: () => this.getPageSize(),
|
|
148
|
+
cache: false,
|
|
149
|
+
});
|
|
150
|
+
context.defineProperty('offset', {
|
|
151
|
+
get: () => {
|
|
152
|
+
const page = this.getPage();
|
|
153
|
+
const pageSize = this.getPageSize();
|
|
154
|
+
return (page - 1) * pageSize;
|
|
155
|
+
},
|
|
156
|
+
cache: false,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
protected buildURL(action?: string): string {
|
|
161
|
+
return `flowSql:${action || this.refreshActionName}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
setPage(page: number) {
|
|
165
|
+
this.addRequestParameter('page', page);
|
|
166
|
+
return this.setMeta({ page });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
getPage(): number {
|
|
170
|
+
return this.getMeta('page') || 1;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
setPageSize(pageSize: number) {
|
|
174
|
+
this.addRequestParameter('pageSize', pageSize);
|
|
175
|
+
return this.setMeta({ pageSize });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
setDebug(enabled: boolean) {
|
|
179
|
+
this._debugEnabled = enabled;
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
getPageSize(): number {
|
|
184
|
+
return this.getMeta('pageSize') || 20;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async next(): Promise<void> {
|
|
188
|
+
this.setPage(this.getPage() + 1);
|
|
189
|
+
await this.refresh();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async previous(): Promise<void> {
|
|
193
|
+
if (this.getPage() > 1) {
|
|
194
|
+
this.setPage(this.getPage() - 1);
|
|
195
|
+
await this.refresh();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async goto(page: number): Promise<void> {
|
|
200
|
+
if (page > 0) {
|
|
201
|
+
this.request.params.page = page;
|
|
202
|
+
await this.refresh();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
setDataSourceKey(dataSourceKey: string): this {
|
|
207
|
+
this.request.data.dataSourceKey = dataSourceKey;
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
setSQLType(type: 'selectRows' | 'selectRow' | 'selectVar') {
|
|
212
|
+
this.request.data.type = type;
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
setSQL(sql: string) {
|
|
217
|
+
this._sql = sql;
|
|
218
|
+
return this;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
setFilterByTk(filterByTk: any) {
|
|
222
|
+
this.request.data.uid = filterByTk;
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
setFilter(filter: Record<string, any>) {
|
|
227
|
+
this.request.data.filter = filter;
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
setBind(bind: Record<string, any> | Array<any>) {
|
|
232
|
+
this.request.data.bind = bind;
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async run() {
|
|
237
|
+
return this._debugEnabled ? await this.runBySQL() : await this.runById();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async runBySQL() {
|
|
241
|
+
const sql = this._sql;
|
|
242
|
+
const result = transformSQL(sql);
|
|
243
|
+
const bind = await this.context.resolveJsonTemplate(result.bind);
|
|
244
|
+
const options = _.cloneDeep({
|
|
245
|
+
method: 'post',
|
|
246
|
+
...this.getRefreshRequestOptions(),
|
|
247
|
+
});
|
|
248
|
+
options.data.bind = bind;
|
|
249
|
+
options.data.sql = result.sql;
|
|
250
|
+
return await this.runAction<TData, any>('run', options);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async runById() {
|
|
254
|
+
const { data } = await this.runAction<TData, any>('getBind', {
|
|
255
|
+
method: 'get',
|
|
256
|
+
params: {
|
|
257
|
+
uid: this.request.data.uid,
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
const bind = await this.context.resolveJsonTemplate(data);
|
|
261
|
+
this.setBind(bind);
|
|
262
|
+
return await this.runAction<TData, any>('runById', {
|
|
263
|
+
method: 'post',
|
|
264
|
+
...this.getRefreshRequestOptions(),
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* 在同一个事件循环内多次调用 refresh 方法时,只有最后一次调用会生效。避免触发多次相同的接口请求。
|
|
270
|
+
* @returns
|
|
271
|
+
*/
|
|
272
|
+
async refresh(): Promise<void> {
|
|
273
|
+
// 清除之前的定时器,确保只有最后一次调用生效
|
|
274
|
+
if (this.refreshTimer) {
|
|
275
|
+
clearTimeout(this.refreshTimer);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// 设置新的定时器,在下一个事件循环执行
|
|
279
|
+
return new Promise<void>((resolve, reject) => {
|
|
280
|
+
this.refreshTimer = setTimeout(async () => {
|
|
281
|
+
try {
|
|
282
|
+
this.clearError();
|
|
283
|
+
this.loading = true;
|
|
284
|
+
const { data, meta } = await this.run();
|
|
285
|
+
this.setData(data).setMeta(meta);
|
|
286
|
+
this.emit('refresh');
|
|
287
|
+
this.loading = false;
|
|
288
|
+
resolve();
|
|
289
|
+
} catch (error) {
|
|
290
|
+
this.setError(error);
|
|
291
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
292
|
+
} finally {
|
|
293
|
+
this.refreshTimer = null;
|
|
294
|
+
this.loading = false;
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|