@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,310 @@
|
|
|
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 { describe, expect, it, vi } from 'vitest';
|
|
11
|
+
import {
|
|
12
|
+
parseValueToPath,
|
|
13
|
+
formatPathToValue,
|
|
14
|
+
loadMetaTreeChildren,
|
|
15
|
+
searchInLoadedNodes,
|
|
16
|
+
buildContextSelectorItems,
|
|
17
|
+
isVariableValue,
|
|
18
|
+
createDefaultConverters,
|
|
19
|
+
} from '../utils';
|
|
20
|
+
import type { MetaTreeNode } from '../../../flowContext';
|
|
21
|
+
import type { ContextSelectorItem } from '../types';
|
|
22
|
+
|
|
23
|
+
describe('Variable Utils', () => {
|
|
24
|
+
describe('parseValueToPath', () => {
|
|
25
|
+
it('should parse {{ ctx.aaa.bbb }} to path array', () => {
|
|
26
|
+
expect(parseValueToPath('{{ ctx.aaa.bbb }}')).toEqual(['aaa', 'bbb']);
|
|
27
|
+
expect(parseValueToPath('{{ctx.user.name}}')).toEqual(['user', 'name']);
|
|
28
|
+
expect(parseValueToPath('{{ ctx.data.items.0.title }}')).toEqual(['data', 'items', '0', 'title']);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should handle edge cases', () => {
|
|
32
|
+
expect(parseValueToPath('{{ ctx }}')).toEqual([]);
|
|
33
|
+
expect(parseValueToPath('{{ctx}}')).toEqual([]);
|
|
34
|
+
expect(parseValueToPath('not a variable')).toBeUndefined();
|
|
35
|
+
expect(parseValueToPath('')).toBeUndefined();
|
|
36
|
+
expect(parseValueToPath('{{ something.else }}')).toBeUndefined();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should handle whitespace variations', () => {
|
|
40
|
+
expect(parseValueToPath('{{ ctx.aaa.bbb }}')).toEqual(['aaa', 'bbb']);
|
|
41
|
+
expect(parseValueToPath('{{ ctx.aaa.bbb}}')).toEqual(['aaa', 'bbb']);
|
|
42
|
+
expect(parseValueToPath('{{ctx.aaa.bbb }}')).toEqual(['aaa', 'bbb']);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('loadMetaTreeChildren', () => {
|
|
47
|
+
it('should load async children from MetaTreeNode', async () => {
|
|
48
|
+
const asyncChildren = async () => [
|
|
49
|
+
{ name: 'child1', title: 'Child 1', type: 'string', paths: ['parent', 'child1'], parentTitles: ['Parent'] },
|
|
50
|
+
{ name: 'child2', title: 'Child 2', type: 'number', paths: ['parent', 'child2'], parentTitles: ['Parent'] },
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
const metaNode: MetaTreeNode = {
|
|
54
|
+
name: 'parent',
|
|
55
|
+
title: 'Parent',
|
|
56
|
+
type: 'object',
|
|
57
|
+
paths: ['parent'],
|
|
58
|
+
children: asyncChildren,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const result = await loadMetaTreeChildren(metaNode);
|
|
62
|
+
expect(result).toHaveLength(2);
|
|
63
|
+
expect(result[0].name).toBe('child1');
|
|
64
|
+
expect(result[1].name).toBe('child2');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should return empty array for nodes without children', async () => {
|
|
68
|
+
const metaNode: MetaTreeNode = {
|
|
69
|
+
name: 'leaf',
|
|
70
|
+
title: 'Leaf',
|
|
71
|
+
type: 'string',
|
|
72
|
+
paths: ['leaf'],
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const result = await loadMetaTreeChildren(metaNode);
|
|
76
|
+
expect(result).toEqual([]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should handle sync children array', async () => {
|
|
80
|
+
const metaNode: MetaTreeNode = {
|
|
81
|
+
name: 'parent',
|
|
82
|
+
title: 'Parent',
|
|
83
|
+
type: 'object',
|
|
84
|
+
paths: ['parent'],
|
|
85
|
+
children: [
|
|
86
|
+
{ name: 'child1', title: 'Child 1', type: 'string', paths: ['parent', 'child1'], parentTitles: ['Parent'] },
|
|
87
|
+
],
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const result = await loadMetaTreeChildren(metaNode);
|
|
91
|
+
expect(result).toHaveLength(1);
|
|
92
|
+
expect(result[0].name).toBe('child1');
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('searchInLoadedNodes', () => {
|
|
97
|
+
const mockOptions: ContextSelectorItem[] = [
|
|
98
|
+
{
|
|
99
|
+
label: 'User',
|
|
100
|
+
value: 'user',
|
|
101
|
+
paths: ['user'],
|
|
102
|
+
children: [
|
|
103
|
+
{ label: 'Name', value: 'name', isLeaf: true, paths: ['user', 'name'] },
|
|
104
|
+
{ label: 'Email', value: 'email', isLeaf: true, paths: ['user', 'email'] },
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
label: 'Data',
|
|
109
|
+
value: 'data',
|
|
110
|
+
paths: ['data'],
|
|
111
|
+
children: [{ label: 'Items', value: 'items', isLeaf: true, paths: ['data', 'items'] }],
|
|
112
|
+
},
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
it('should search in cascader options by label', () => {
|
|
116
|
+
const result = searchInLoadedNodes(mockOptions, 'User');
|
|
117
|
+
expect(result).toHaveLength(1);
|
|
118
|
+
expect(result[0].label).toBe('User');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should search nested options', () => {
|
|
122
|
+
const result = searchInLoadedNodes(mockOptions, 'Name');
|
|
123
|
+
expect(result).toHaveLength(1);
|
|
124
|
+
expect(result[0].label).toBe('Name');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should return empty array for no matches', () => {
|
|
128
|
+
const result = searchInLoadedNodes(mockOptions, 'NonExistent');
|
|
129
|
+
expect(result).toEqual([]);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should handle case insensitive search', () => {
|
|
133
|
+
const result = searchInLoadedNodes(mockOptions, 'user');
|
|
134
|
+
expect(result).toHaveLength(1);
|
|
135
|
+
expect(result[0].label).toBe('User');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should return the same object instances without creating new ones', () => {
|
|
139
|
+
const result = searchInLoadedNodes(mockOptions, 'User');
|
|
140
|
+
expect(result).toHaveLength(1);
|
|
141
|
+
// Verify that the returned object is the exact same instance as the original
|
|
142
|
+
expect(result[0]).toBe(mockOptions[0]);
|
|
143
|
+
expect(result[0].paths).toBe(mockOptions[0].paths);
|
|
144
|
+
|
|
145
|
+
const nestedResult = searchInLoadedNodes(mockOptions, 'Name');
|
|
146
|
+
expect(nestedResult).toHaveLength(1);
|
|
147
|
+
// Verify that nested search also returns the same instance
|
|
148
|
+
expect(nestedResult[0]).toBe(mockOptions[0].children![0]);
|
|
149
|
+
expect(nestedResult[0].paths).toBe(mockOptions[0].children![0].paths);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('buildContextSelectorItems', () => {
|
|
154
|
+
it('should convert MetaTreeNode[] to ContextSelectorItem[]', () => {
|
|
155
|
+
const metaTree: MetaTreeNode[] = [
|
|
156
|
+
{
|
|
157
|
+
name: 'user',
|
|
158
|
+
title: 'User',
|
|
159
|
+
type: 'object',
|
|
160
|
+
paths: ['user'],
|
|
161
|
+
children: [
|
|
162
|
+
{ name: 'name', title: 'Name', type: 'string', paths: ['user', 'name'], parentTitles: ['User'] },
|
|
163
|
+
{ name: 'email', title: 'Email', type: 'string', paths: ['user', 'email'], parentTitles: ['User'] },
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: 'data',
|
|
168
|
+
title: 'Data',
|
|
169
|
+
type: 'string',
|
|
170
|
+
paths: ['data'],
|
|
171
|
+
},
|
|
172
|
+
];
|
|
173
|
+
|
|
174
|
+
const result = buildContextSelectorItems(metaTree);
|
|
175
|
+
expect(result).toHaveLength(2);
|
|
176
|
+
expect(result[0]).toEqual({
|
|
177
|
+
label: 'User',
|
|
178
|
+
value: 'user',
|
|
179
|
+
isLeaf: false,
|
|
180
|
+
meta: metaTree[0],
|
|
181
|
+
paths: ['user'],
|
|
182
|
+
disabled: false,
|
|
183
|
+
children: [
|
|
184
|
+
{
|
|
185
|
+
label: 'Name',
|
|
186
|
+
value: 'name',
|
|
187
|
+
isLeaf: true,
|
|
188
|
+
meta: metaTree[0].children?.[0],
|
|
189
|
+
paths: ['user', 'name'],
|
|
190
|
+
disabled: false,
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
label: 'Email',
|
|
194
|
+
value: 'email',
|
|
195
|
+
isLeaf: true,
|
|
196
|
+
meta: metaTree[0].children?.[1],
|
|
197
|
+
paths: ['user', 'email'],
|
|
198
|
+
disabled: false,
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
});
|
|
202
|
+
expect(result[1]).toEqual({
|
|
203
|
+
label: 'Data',
|
|
204
|
+
value: 'data',
|
|
205
|
+
isLeaf: true,
|
|
206
|
+
meta: metaTree[1],
|
|
207
|
+
paths: ['data'],
|
|
208
|
+
disabled: false,
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('should handle async children by marking as not leaf', () => {
|
|
213
|
+
const metaTree: MetaTreeNode[] = [
|
|
214
|
+
{
|
|
215
|
+
name: 'async',
|
|
216
|
+
title: 'Async Node',
|
|
217
|
+
type: 'object',
|
|
218
|
+
paths: ['async'],
|
|
219
|
+
children: async () => [],
|
|
220
|
+
},
|
|
221
|
+
];
|
|
222
|
+
|
|
223
|
+
const result = buildContextSelectorItems(metaTree);
|
|
224
|
+
expect(result[0]).toEqual({
|
|
225
|
+
label: 'Async Node',
|
|
226
|
+
value: 'async',
|
|
227
|
+
isLeaf: false,
|
|
228
|
+
meta: metaTree[0],
|
|
229
|
+
paths: ['async'],
|
|
230
|
+
disabled: false,
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('should handle invalid metaTree input', () => {
|
|
235
|
+
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
236
|
+
|
|
237
|
+
expect(buildContextSelectorItems(null as any)).toEqual([]);
|
|
238
|
+
expect(buildContextSelectorItems(undefined as any)).toEqual([]);
|
|
239
|
+
expect(buildContextSelectorItems({} as any)).toEqual([]);
|
|
240
|
+
|
|
241
|
+
expect(consoleSpy).toHaveBeenCalledTimes(3);
|
|
242
|
+
consoleSpy.mockRestore();
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('should use name as fallback when title is missing', () => {
|
|
246
|
+
const metaTree: MetaTreeNode[] = [
|
|
247
|
+
{
|
|
248
|
+
name: 'test',
|
|
249
|
+
type: 'object',
|
|
250
|
+
title: '',
|
|
251
|
+
paths: ['test'],
|
|
252
|
+
},
|
|
253
|
+
];
|
|
254
|
+
|
|
255
|
+
const result = buildContextSelectorItems(metaTree);
|
|
256
|
+
|
|
257
|
+
expect(result).toEqual([
|
|
258
|
+
{
|
|
259
|
+
label: 'test',
|
|
260
|
+
value: 'test',
|
|
261
|
+
isLeaf: true,
|
|
262
|
+
meta: { name: 'test', type: 'object', title: '', paths: ['test'] },
|
|
263
|
+
paths: ['test'],
|
|
264
|
+
disabled: false,
|
|
265
|
+
},
|
|
266
|
+
]);
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
describe('isVariableValue', () => {
|
|
271
|
+
it('should detect variable values', () => {
|
|
272
|
+
expect(isVariableValue('{{ ctx.user.name }}')).toBe(true);
|
|
273
|
+
expect(isVariableValue('{{ctx.data}}')).toBe(true);
|
|
274
|
+
expect(isVariableValue('{{ ctx.items.0.title }}')).toBe(true);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('should return false for non-variable values', () => {
|
|
278
|
+
expect(isVariableValue('plain text')).toBe(false);
|
|
279
|
+
expect(isVariableValue('123')).toBe(false);
|
|
280
|
+
expect(isVariableValue('')).toBe(false);
|
|
281
|
+
expect(isVariableValue(null)).toBe(false);
|
|
282
|
+
expect(isVariableValue(undefined)).toBe(false);
|
|
283
|
+
expect(isVariableValue({ key: 'value' })).toBe(false);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('should handle edge cases', () => {
|
|
287
|
+
expect(isVariableValue('{{ something.else }}')).toBe(false);
|
|
288
|
+
expect(isVariableValue('{{ ctx }}')).toBe(true);
|
|
289
|
+
expect(isVariableValue('{ctx.user}')).toBe(false);
|
|
290
|
+
expect(isVariableValue('{{ ctx.user')).toBe(false);
|
|
291
|
+
expect(isVariableValue('ctx.user }}')).toBe(false);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
describe('createDefaultConverters', () => {
|
|
296
|
+
it('should create default converters', () => {
|
|
297
|
+
const converters = createDefaultConverters();
|
|
298
|
+
expect(converters).toHaveProperty('resolvePathFromValue');
|
|
299
|
+
expect(converters).toHaveProperty('resolveValueFromPath');
|
|
300
|
+
expect(typeof converters.resolvePathFromValue).toBe('function');
|
|
301
|
+
expect(typeof converters.resolveValueFromPath).toBe('function');
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('should resolve path from variable value', () => {
|
|
305
|
+
const converters = createDefaultConverters();
|
|
306
|
+
expect(converters.resolvePathFromValue?.('{{ ctx.user.name }}')).toEqual(['user', 'name']);
|
|
307
|
+
expect(converters.resolvePathFromValue?.('static value')).toBeUndefined();
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
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 { VariableInput } from './VariableInput';
|
|
11
|
+
export { SlateVariableEditor } from './SlateVariableEditor';
|
|
12
|
+
export { VariableTag } from './VariableTag';
|
|
13
|
+
export { InlineVariableTag } from './InlineVariableTag';
|
|
14
|
+
export { useResolvedMetaTree } from './useResolvedMetaTree';
|
|
15
|
+
export * from './types';
|
|
16
|
+
export * from './utils';
|
|
@@ -0,0 +1,100 @@
|
|
|
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 React from 'react';
|
|
11
|
+
import { CascaderProps } from 'antd';
|
|
12
|
+
import type { MetaTreeNode } from '../../flowContext';
|
|
13
|
+
|
|
14
|
+
export interface FlowContextSelectorProps
|
|
15
|
+
extends Omit<CascaderProps<ContextSelectorItem>, 'value' | 'onChange' | 'options' | 'children' | 'multiple'> {
|
|
16
|
+
value?: string;
|
|
17
|
+
onChange?: (value: string, metaTreeNode?: MetaTreeNode) => void;
|
|
18
|
+
children?: CascaderProps<ContextSelectorItem>['children'];
|
|
19
|
+
metaTree?: MetaTreeNode[] | (() => MetaTreeNode[] | Promise<MetaTreeNode[]>);
|
|
20
|
+
parseValueToPath?: (value: string) => string[] | undefined;
|
|
21
|
+
formatPathToValue?: (item: MetaTreeNode) => string;
|
|
22
|
+
open?: boolean;
|
|
23
|
+
onlyLeafSelectable?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ContextSelectorItem {
|
|
27
|
+
label: React.ReactNode;
|
|
28
|
+
value: string;
|
|
29
|
+
isLeaf?: boolean;
|
|
30
|
+
children?: ContextSelectorItem[];
|
|
31
|
+
loading?: boolean;
|
|
32
|
+
meta?: MetaTreeNode;
|
|
33
|
+
paths: string[];
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface Converters {
|
|
38
|
+
/**
|
|
39
|
+
* 根据选中的上下文选择器项目,返回一个用于渲染该值的 React 组件类型。
|
|
40
|
+
* 如果返回 null 或 undefined,则会使用默认的渲染组件。
|
|
41
|
+
* @param metaTreeNode 选中的 MetaTreeNode 对象,或者在未选择任何变量时为 null。
|
|
42
|
+
* @returns React.ComponentType<{ value: any; onChange: (value: any) => void; }> | null
|
|
43
|
+
*/
|
|
44
|
+
renderInputComponent?: (metaTreeNode: MetaTreeNode | null) => React.ComponentType<any> | null;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 将一个外部 value 转换成 FlowContextSelector 需要的路径数组。
|
|
48
|
+
* @param value 外部传入的值。
|
|
49
|
+
* @returns string[] | undefined
|
|
50
|
+
*/
|
|
51
|
+
resolvePathFromValue?: (value: any) => string[] | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* 当一个上下文节点被选中后,将其信息转换成最终的外部 value。
|
|
54
|
+
* @param metaTreeNode 选中的 MetaTreeNode 对象。
|
|
55
|
+
* @returns any
|
|
56
|
+
*/
|
|
57
|
+
resolveValueFromPath?: (metaTreeNode: MetaTreeNode) => any;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface VariableInputProps {
|
|
61
|
+
value?: any;
|
|
62
|
+
onChange?: (value: any, contextMeta?: MetaTreeNode) => void;
|
|
63
|
+
converters?: Converters;
|
|
64
|
+
showValueComponent?: boolean;
|
|
65
|
+
metaTree?: MetaTreeNode[] | (() => MetaTreeNode[] | Promise<MetaTreeNode[]>);
|
|
66
|
+
onlyLeafSelectable?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* 清空(点击 Tag 的 clear、或 Input 的 allowClear)时要设置的值。
|
|
69
|
+
* 默认行为为 null;可设置为 '' 等,以便清空后默认切换为“常量-空字符串”。
|
|
70
|
+
*/
|
|
71
|
+
clearValue?: any;
|
|
72
|
+
[key: string]: any;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface VariableTagProps {
|
|
76
|
+
value?: string;
|
|
77
|
+
onClear?: () => void;
|
|
78
|
+
className?: string;
|
|
79
|
+
style?: React.CSSProperties;
|
|
80
|
+
metaTreeNode?: MetaTreeNode | null;
|
|
81
|
+
metaTree?: MetaTreeNode[] | (() => MetaTreeNode[] | Promise<MetaTreeNode[]>);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface VariableTriggerElement {
|
|
85
|
+
type: 'variable-trigger';
|
|
86
|
+
triggerId: string;
|
|
87
|
+
children: [{ text: '' }];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface VariableElement {
|
|
91
|
+
type: 'variable';
|
|
92
|
+
value: string;
|
|
93
|
+
meta?: MetaTreeNode;
|
|
94
|
+
children: [{ text: '' }];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface ParagraphElement {
|
|
98
|
+
type: 'paragraph';
|
|
99
|
+
children: any[];
|
|
100
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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 React from 'react';
|
|
11
|
+
import type { MetaTreeNode } from '../../flowContext';
|
|
12
|
+
|
|
13
|
+
export interface UseResolvedMetaTreeResult {
|
|
14
|
+
resolvedMetaTree: MetaTreeNode[] | undefined;
|
|
15
|
+
loading: boolean;
|
|
16
|
+
error: Error | null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 通用 hook 用于处理异步/同步 metaTree
|
|
21
|
+
* 统一处理 metaTree 为函数(同步/异步)或数组的情况
|
|
22
|
+
*/
|
|
23
|
+
export const useResolvedMetaTree = (
|
|
24
|
+
metaTree?: MetaTreeNode[] | (() => MetaTreeNode[] | Promise<MetaTreeNode[]>),
|
|
25
|
+
): UseResolvedMetaTreeResult => {
|
|
26
|
+
const [resolvedMetaTree, setResolvedMetaTree] = React.useState<MetaTreeNode[] | undefined>();
|
|
27
|
+
const [loading, setLoading] = React.useState(false);
|
|
28
|
+
const [error, setError] = React.useState<Error | null>(null);
|
|
29
|
+
|
|
30
|
+
React.useEffect(() => {
|
|
31
|
+
const resolveMetaTree = async () => {
|
|
32
|
+
if (!metaTree) {
|
|
33
|
+
setResolvedMetaTree(undefined);
|
|
34
|
+
setLoading(false);
|
|
35
|
+
setError(null);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 如果是数组,直接使用
|
|
40
|
+
if (Array.isArray(metaTree)) {
|
|
41
|
+
setResolvedMetaTree(metaTree);
|
|
42
|
+
setLoading(false);
|
|
43
|
+
setError(null);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 如果是函数,需要调用它
|
|
48
|
+
if (typeof metaTree === 'function') {
|
|
49
|
+
setLoading(true);
|
|
50
|
+
setError(null);
|
|
51
|
+
try {
|
|
52
|
+
let result = await metaTree();
|
|
53
|
+
// 兼容返回值仍然是函数(惰性 loader)的情况,继续调用一次获取真正的数组
|
|
54
|
+
if (typeof result === 'function') {
|
|
55
|
+
result = await (result as unknown as () => Promise<MetaTreeNode[]>)();
|
|
56
|
+
}
|
|
57
|
+
setResolvedMetaTree(result as MetaTreeNode[]);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.warn('Failed to resolve metaTree function:', err);
|
|
60
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
61
|
+
setResolvedMetaTree(undefined);
|
|
62
|
+
} finally {
|
|
63
|
+
setLoading(false);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
resolveMetaTree();
|
|
69
|
+
}, [metaTree]);
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
resolvedMetaTree,
|
|
73
|
+
loading,
|
|
74
|
+
error,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
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 React from 'react';
|
|
11
|
+
import { Input } from 'antd';
|
|
12
|
+
import type { MetaTreeNode } from '../../flowContext';
|
|
13
|
+
import type { ContextSelectorItem, Converters } from './types';
|
|
14
|
+
import { isVariableExpression } from '../../utils';
|
|
15
|
+
|
|
16
|
+
export const parseValueToPath = (value: string): string[] | undefined => {
|
|
17
|
+
if (typeof value !== 'string') return undefined;
|
|
18
|
+
|
|
19
|
+
const trimmed = value.trim();
|
|
20
|
+
const variableRegex = /^\{\{\s*ctx(?:\.(.+?))?\s*\}\}$/;
|
|
21
|
+
const match = trimmed.match(variableRegex);
|
|
22
|
+
|
|
23
|
+
if (!match) return undefined;
|
|
24
|
+
|
|
25
|
+
const pathString = match[1];
|
|
26
|
+
if (!pathString) return [];
|
|
27
|
+
|
|
28
|
+
return pathString.split('.');
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const formatPathToValue = (item: MetaTreeNode): string => {
|
|
32
|
+
const path = item?.paths || [];
|
|
33
|
+
if (path.length === 0) return '{{ ctx }}';
|
|
34
|
+
return `{{ ctx.${path.join('.')} }}`;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const loadMetaTreeChildren = async (metaNode: MetaTreeNode): Promise<MetaTreeNode[]> => {
|
|
38
|
+
if (!metaNode?.children) return [];
|
|
39
|
+
|
|
40
|
+
if (typeof metaNode.children === 'function') {
|
|
41
|
+
try {
|
|
42
|
+
return await metaNode.children();
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.warn(`Failed to load children for ${metaNode.name}:`, error);
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return metaNode.children;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// 在已加载的级联选项中搜索,支持模糊匹配
|
|
53
|
+
export const searchInLoadedNodes = (
|
|
54
|
+
options: ContextSelectorItem[],
|
|
55
|
+
searchText: string,
|
|
56
|
+
parentPaths: string[] = [],
|
|
57
|
+
): ContextSelectorItem[] => {
|
|
58
|
+
if (!searchText || !searchText.trim()) return [];
|
|
59
|
+
|
|
60
|
+
const lowerSearchText = searchText.toLowerCase().trim();
|
|
61
|
+
const results: ContextSelectorItem[] = [];
|
|
62
|
+
|
|
63
|
+
// 递归搜索已加载的节点
|
|
64
|
+
const searchRecursive = (nodes: ContextSelectorItem[], currentPath: string[] = []) => {
|
|
65
|
+
for (const node of nodes) {
|
|
66
|
+
const nodePath = [...currentPath, node.value];
|
|
67
|
+
|
|
68
|
+
// 计算可搜索的纯文本标签
|
|
69
|
+
const labelText =
|
|
70
|
+
typeof node.label === 'string'
|
|
71
|
+
? node.label
|
|
72
|
+
: typeof node.meta?.title === 'string'
|
|
73
|
+
? node.meta!.title
|
|
74
|
+
: String(node.value);
|
|
75
|
+
|
|
76
|
+
// 检查节点标签是否匹配搜索文本
|
|
77
|
+
if (labelText.toLowerCase().includes(lowerSearchText)) {
|
|
78
|
+
results.push(node);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 只搜索已加载的子节点(存在children属性表示已加载)
|
|
82
|
+
if (node.children && Array.isArray(node.children)) {
|
|
83
|
+
searchRecursive(node.children, nodePath);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
searchRecursive(options, []);
|
|
89
|
+
return results;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const buildContextSelectorItems = (metaTree: MetaTreeNode[]): ContextSelectorItem[] => {
|
|
93
|
+
if (!metaTree || !Array.isArray(metaTree)) {
|
|
94
|
+
console.warn('buildContextSelectorItems received invalid metaTree:', metaTree);
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const convertNode = (node: MetaTreeNode): ContextSelectorItem => {
|
|
99
|
+
const hasChildren = !!(
|
|
100
|
+
node.children &&
|
|
101
|
+
(typeof node.children === 'function' || (Array.isArray(node.children) && node.children.length > 0))
|
|
102
|
+
);
|
|
103
|
+
// 计算禁用状态:支持 boolean 或函数
|
|
104
|
+
const disabled = !!(typeof node.disabled === 'function' ? node.disabled() : node.disabled);
|
|
105
|
+
const option: ContextSelectorItem = {
|
|
106
|
+
label: node.title || node.name,
|
|
107
|
+
value: node.name,
|
|
108
|
+
isLeaf: !hasChildren,
|
|
109
|
+
meta: node,
|
|
110
|
+
paths: node.paths,
|
|
111
|
+
disabled,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
if (Array.isArray(node.children) && node.children.length > 0) {
|
|
115
|
+
option.children = node.children.map((child) => convertNode(child));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return option;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
return metaTree.map((node) => convertNode(node));
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 预加载:根据路径逐级加载 ContextSelectorItem 的 children,保证打开时已展开对应层级。
|
|
126
|
+
*/
|
|
127
|
+
export const preloadContextSelectorPath = async (
|
|
128
|
+
options: ContextSelectorItem[] | undefined,
|
|
129
|
+
pathSegments: (string | number)[],
|
|
130
|
+
triggerUpdate?: () => void,
|
|
131
|
+
) => {
|
|
132
|
+
if (!options || !Array.isArray(options) || !pathSegments || pathSegments.length === 0) return;
|
|
133
|
+
let list: ContextSelectorItem[] | undefined = options;
|
|
134
|
+
for (let i = 0; i < pathSegments.length && list; i++) {
|
|
135
|
+
const seg = String(pathSegments[i]);
|
|
136
|
+
const opt = list.find((o) => String(o.value) === seg);
|
|
137
|
+
if (!opt) break;
|
|
138
|
+
const meta = opt.meta as MetaTreeNode | undefined;
|
|
139
|
+
const hasLoaded = !!opt.children && Array.isArray(opt.children);
|
|
140
|
+
if (i < pathSegments.length - 1 && !hasLoaded && meta && typeof meta.children === 'function') {
|
|
141
|
+
opt.loading = true;
|
|
142
|
+
try {
|
|
143
|
+
const childNodes = await loadMetaTreeChildren(meta);
|
|
144
|
+
meta.children = childNodes;
|
|
145
|
+
const childOptions = buildContextSelectorItems(childNodes);
|
|
146
|
+
opt.children = childOptions;
|
|
147
|
+
opt.isLeaf = !childOptions || childOptions.length === 0;
|
|
148
|
+
Promise.resolve()
|
|
149
|
+
.then(() => triggerUpdate?.())
|
|
150
|
+
.catch(() => {});
|
|
151
|
+
} finally {
|
|
152
|
+
opt.loading = false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
list = Array.isArray(opt.children) ? opt.children : undefined;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const isVariableValue = (value: any): boolean => {
|
|
160
|
+
return isVariableExpression(value);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export const createDefaultConverters = (): Converters => {
|
|
164
|
+
return {
|
|
165
|
+
resolvePathFromValue: (value: any) => {
|
|
166
|
+
return parseValueToPath(value);
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
resolveValueFromPath: (item: MetaTreeNode) => {
|
|
170
|
+
return formatPathToValue(item);
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export const createFinalConverters = (propConverters?: Converters): Converters => {
|
|
176
|
+
const defaultConverters = createDefaultConverters();
|
|
177
|
+
const mergedConverters = propConverters ? { ...defaultConverters, ...propConverters } : defaultConverters;
|
|
178
|
+
|
|
179
|
+
// 如果用户自定义了 resolveValueFromPath,需要包装一下以保持后备逻辑
|
|
180
|
+
if (propConverters?.resolveValueFromPath) {
|
|
181
|
+
const customResolveValueFromPath = propConverters.resolveValueFromPath;
|
|
182
|
+
return {
|
|
183
|
+
...mergedConverters,
|
|
184
|
+
resolveValueFromPath: (item: MetaTreeNode) => {
|
|
185
|
+
const ret = customResolveValueFromPath(item);
|
|
186
|
+
return ret === undefined ? formatPathToValue(item) : ret;
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return mergedConverters;
|
|
192
|
+
};
|