@nocobase/flow-engine 2.0.0-alpha.10
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 +100 -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 +61 -0
- package/lib/components/FlowModelRenderer.js +214 -0
- package/lib/components/FormItem.d.ts +18 -0
- package/lib/components/FormItem.js +151 -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/findModelUidPosition.d.ts +13 -0
- package/lib/components/dnd/findModelUidPosition.js +50 -0
- package/lib/components/dnd/gridDragPlanner.d.ts +130 -0
- package/lib/components/dnd/gridDragPlanner.js +497 -0
- package/lib/components/dnd/index.d.ts +24 -0
- package/lib/components/dnd/index.js +164 -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 +212 -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 +334 -0
- package/lib/components/variables/VariableTag.d.ts +11 -0
- package/lib/components/variables/VariableTag.js +189 -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 +737 -0
- package/lib/data-source/jioToJoiSchema.d.ts +19 -0
- package/lib/data-source/jioToJoiSchema.js +114 -0
- package/lib/data-source/sortCollectionsByInherits.d.ts +10 -0
- package/lib/data-source/sortCollectionsByInherits.js +71 -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 +25 -0
- package/lib/executor/FlowExecutor.js +290 -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 +243 -0
- package/lib/flowContext.js +1337 -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 +63 -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 +30 -0
- package/lib/index.js +93 -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 +52 -0
- package/lib/models/CollectionFieldModel.js +280 -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 +342 -0
- package/lib/models/flowModel.js +1154 -0
- package/lib/models/forkFlowModel.d.ts +83 -0
- package/lib/models/forkFlowModel.js +280 -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 +115 -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/FormJSFieldItemRunJSContext.d.ts +11 -0
- package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.js +73 -0
- package/lib/runjs-context/contexts/JSBlockRunJSContext.d.ts +11 -0
- package/lib/runjs-context/contexts/JSBlockRunJSContext.js +91 -0
- package/lib/runjs-context/contexts/JSCollectionActionRunJSContext.d.ts +11 -0
- package/lib/runjs-context/contexts/JSCollectionActionRunJSContext.js +58 -0
- package/lib/runjs-context/contexts/JSColumnRunJSContext.d.ts +15 -0
- package/lib/runjs-context/contexts/JSColumnRunJSContext.js +78 -0
- package/lib/runjs-context/contexts/JSFieldRunJSContext.d.ts +11 -0
- package/lib/runjs-context/contexts/JSFieldRunJSContext.js +74 -0
- package/lib/runjs-context/contexts/JSItemRunJSContext.d.ts +11 -0
- package/lib/runjs-context/contexts/JSItemRunJSContext.js +70 -0
- package/lib/runjs-context/contexts/JSRecordActionRunJSContext.d.ts +11 -0
- package/lib/runjs-context/contexts/JSRecordActionRunJSContext.js +60 -0
- package/lib/runjs-context/contexts/base.d.ts +9 -0
- package/lib/runjs-context/contexts/base.js +169 -0
- package/lib/runjs-context/helpers.d.ts +20 -0
- package/lib/runjs-context/helpers.js +88 -0
- package/lib/runjs-context/registry.d.ts +20 -0
- package/lib/runjs-context/registry.js +61 -0
- package/lib/runjs-context/setup.d.ts +9 -0
- package/lib/runjs-context/setup.js +82 -0
- package/lib/runjs-context/snippets/global/api-request.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/api-request.snippet.js +57 -0
- package/lib/runjs-context/snippets/global/import-esm.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/import-esm.snippet.js +58 -0
- package/lib/runjs-context/snippets/global/message-error.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/message-error.snippet.js +47 -0
- package/lib/runjs-context/snippets/global/message-success.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/message-success.snippet.js +47 -0
- package/lib/runjs-context/snippets/global/notification-open.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/notification-open.snippet.js +50 -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 +54 -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 +54 -0
- package/lib/runjs-context/snippets/global/query-selector.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/query-selector.snippet.js +53 -0
- package/lib/runjs-context/snippets/global/require-amd.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/require-amd.snippet.js +49 -0
- package/lib/runjs-context/snippets/global/window-open.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/window-open.snippet.js +48 -0
- package/lib/runjs-context/snippets/index.d.ts +22 -0
- package/lib/runjs-context/snippets/index.js +213 -0
- package/lib/runjs-context/snippets/scene/block/add-event-listener.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/add-event-listener.snippet.js +55 -0
- package/lib/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.js +64 -0
- package/lib/runjs-context/snippets/scene/block/chartjs-bar.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/chartjs-bar.snippet.js +99 -0
- package/lib/runjs-context/snippets/scene/block/echarts-init.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/echarts-init.snippet.js +63 -0
- package/lib/runjs-context/snippets/scene/block/render-button-handler.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-button-handler.snippet.js +52 -0
- package/lib/runjs-context/snippets/scene/block/render-iframe.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-iframe.snippet.js +57 -0
- package/lib/runjs-context/snippets/scene/block/render-info-card.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-info-card.snippet.js +72 -0
- package/lib/runjs-context/snippets/scene/block/render-react.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-react.snippet.js +57 -0
- package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.js +100 -0
- package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.js +85 -0
- package/lib/runjs-context/snippets/scene/block/resource-example.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/resource-example.snippet.js +60 -0
- package/lib/runjs-context/snippets/scene/block/three-users-orbit.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/three-users-orbit.snippet.js +283 -0
- package/lib/runjs-context/snippets/scene/block/vue-component.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/vue-component.snippet.js +124 -0
- package/lib/runjs-context/snippets/scene/detail/color-by-value.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/color-by-value.snippet.js +52 -0
- package/lib/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.js +64 -0
- package/lib/runjs-context/snippets/scene/detail/format-number.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/format-number.snippet.js +51 -0
- package/lib/runjs-context/snippets/scene/detail/innerHTML-value.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/innerHTML-value.snippet.js +50 -0
- package/lib/runjs-context/snippets/scene/detail/percentage-bar.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/percentage-bar.snippet.js +82 -0
- package/lib/runjs-context/snippets/scene/detail/relative-time.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/relative-time.snippet.js +80 -0
- package/lib/runjs-context/snippets/scene/detail/status-tag.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/status-tag.snippet.js +74 -0
- package/lib/runjs-context/snippets/scene/form/calculate-total.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/calculate-total.snippet.js +63 -0
- package/lib/runjs-context/snippets/scene/form/cascade-select.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/cascade-select.snippet.js +81 -0
- package/lib/runjs-context/snippets/scene/form/conditional-required.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/conditional-required.snippet.js +64 -0
- package/lib/runjs-context/snippets/scene/form/copy-field-values.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/copy-field-values.snippet.js +74 -0
- package/lib/runjs-context/snippets/scene/form/render-basic.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/render-basic.snippet.js +53 -0
- package/lib/runjs-context/snippets/scene/form/set-disabled.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/set-disabled.snippet.js +69 -0
- package/lib/runjs-context/snippets/scene/form/set-field-value.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/set-field-value.snippet.js +68 -0
- package/lib/runjs-context/snippets/scene/form/set-required.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/set-required.snippet.js +69 -0
- package/lib/runjs-context/snippets/scene/form/toggle-multiple-fields.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/toggle-multiple-fields.snippet.js +67 -0
- package/lib/runjs-context/snippets/scene/form/toggle-visible.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/toggle-visible.snippet.js +69 -0
- package/lib/runjs-context/snippets/scene/table/cell-open-dialog.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/cell-open-dialog.snippet.js +64 -0
- package/lib/runjs-context/snippets/scene/table/collection-selected-count.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/collection-selected-count.snippet.js +53 -0
- package/lib/runjs-context/snippets/scene/table/concat-fields.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/concat-fields.snippet.js +79 -0
- package/lib/runjs-context/snippets/scene/table/destroy-selected.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/destroy-selected.snippet.js +55 -0
- package/lib/runjs-context/snippets/scene/table/export-selected-json.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/export-selected-json.snippet.js +64 -0
- package/lib/runjs-context/snippets/scene/table/iterate-selected-rows.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/iterate-selected-rows.snippet.js +52 -0
- package/lib/runjs-context/snippets/types.d.ts +24 -0
- package/lib/runjs-context/snippets/types.js +24 -0
- package/lib/types.d.ts +407 -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 +115 -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 +29 -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 +52 -0
- package/lib/utils/variablesParams.js +161 -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 +168 -0
- package/lib/views/ViewNavigation.d.ts +45 -0
- package/lib/views/ViewNavigation.js +97 -0
- package/lib/views/createViewMeta.d.ts +44 -0
- package/lib/views/createViewMeta.js +377 -0
- package/lib/views/index.d.ts +14 -0
- package/lib/views/index.js +51 -0
- package/lib/views/useDialog.d.ts +32 -0
- package/lib/views/useDialog.js +200 -0
- package/lib/views/useDrawer.d.ts +33 -0
- package/lib/views/useDrawer.js +220 -0
- package/lib/views/usePage.d.ts +32 -0
- package/lib/views/usePage.js +194 -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 +42 -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__/flowContextCreateJSRunner.test.ts +163 -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__/flowRunJSContextDefine.test.ts +508 -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 +241 -0
- package/src/__tests__/runjsContextImplementations.test.ts +217 -0
- package/src/__tests__/runjsContextRuntime.test.ts +269 -0
- package/src/__tests__/runjsEdgeCases.test.ts +281 -0
- package/src/__tests__/runjsLocales.test.ts +36 -0
- package/src/__tests__/runjsRuntimeFeatures.test.ts +449 -0
- package/src/__tests__/runjsSnippets.test.ts +140 -0
- package/src/__tests__/viewScopedFlowEngine.test.ts +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 +68 -0
- package/src/components/FlowContextSelector.tsx +255 -0
- package/src/components/FlowErrorFallback.tsx +316 -0
- package/src/components/FlowModelRenderer.tsx +362 -0
- package/src/components/FormItem.tsx +136 -0
- package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +226 -0
- package/src/components/__tests__/gridDragPlanner.test.ts +494 -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/README.md +149 -0
- package/src/components/dnd/findModelUidPosition.ts +26 -0
- package/src/components/dnd/gridDragPlanner.ts +659 -0
- package/src/components/dnd/index.tsx +128 -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 +223 -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 +360 -0
- package/src/components/variables/VariableTag.tsx +175 -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/__tests__/sortCollectionsByInherits.test.ts +125 -0
- package/src/data-source/index.ts +816 -0
- package/src/data-source/jioToJoiSchema.ts +103 -0
- package/src/data-source/sortCollectionsByInherits.ts +61 -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 +302 -0
- package/src/executor/__tests__/eventStep.test.ts +157 -0
- package/src/executor/__tests__/flowExecutor.test.ts +309 -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 +1742 -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 +53 -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 +46 -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 +306 -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 +2869 -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 +1421 -0
- package/src/models/forkFlowModel.ts +319 -0
- package/src/models/index.ts +17 -0
- package/src/provider.tsx +103 -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/FormJSFieldItemRunJSContext.ts +46 -0
- package/src/runjs-context/contexts/JSBlockRunJSContext.ts +64 -0
- package/src/runjs-context/contexts/JSCollectionActionRunJSContext.ts +31 -0
- package/src/runjs-context/contexts/JSColumnRunJSContext.ts +58 -0
- package/src/runjs-context/contexts/JSFieldRunJSContext.ts +48 -0
- package/src/runjs-context/contexts/JSItemRunJSContext.ts +43 -0
- package/src/runjs-context/contexts/JSRecordActionRunJSContext.ts +33 -0
- package/src/runjs-context/contexts/base.ts +155 -0
- package/src/runjs-context/helpers.ts +58 -0
- package/src/runjs-context/registry.ts +34 -0
- package/src/runjs-context/setup.ts +51 -0
- package/src/runjs-context/snippets/global/api-request.snippet.ts +38 -0
- package/src/runjs-context/snippets/global/import-esm.snippet.ts +39 -0
- package/src/runjs-context/snippets/global/message-error.snippet.ts +26 -0
- package/src/runjs-context/snippets/global/message-success.snippet.ts +26 -0
- package/src/runjs-context/snippets/global/notification-open.snippet.ts +31 -0
- package/src/runjs-context/snippets/global/open-view-dialog.snippet.ts +33 -0
- package/src/runjs-context/snippets/global/open-view-drawer.snippet.ts +33 -0
- package/src/runjs-context/snippets/global/query-selector.snippet.ts +34 -0
- package/src/runjs-context/snippets/global/require-amd.snippet.ts +30 -0
- package/src/runjs-context/snippets/global/window-open.snippet.ts +29 -0
- package/src/runjs-context/snippets/index.ts +195 -0
- package/src/runjs-context/snippets/scene/block/add-event-listener.snippet.ts +41 -0
- package/src/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.ts +45 -0
- package/src/runjs-context/snippets/scene/block/chartjs-bar.snippet.ts +80 -0
- package/src/runjs-context/snippets/scene/block/echarts-init.snippet.ts +44 -0
- package/src/runjs-context/snippets/scene/block/render-button-handler.snippet.ts +33 -0
- package/src/runjs-context/snippets/scene/block/render-iframe.snippet.ts +38 -0
- package/src/runjs-context/snippets/scene/block/render-info-card.snippet.ts +53 -0
- package/src/runjs-context/snippets/scene/block/render-react.snippet.ts +38 -0
- package/src/runjs-context/snippets/scene/block/render-statistics.snippet.ts +81 -0
- package/src/runjs-context/snippets/scene/block/render-timeline.snippet.ts +66 -0
- package/src/runjs-context/snippets/scene/block/resource-example.snippet.ts +46 -0
- package/src/runjs-context/snippets/scene/block/three-users-orbit.snippet.ts +264 -0
- package/src/runjs-context/snippets/scene/block/vue-component.snippet.ts +105 -0
- package/src/runjs-context/snippets/scene/detail/color-by-value.snippet.ts +33 -0
- package/src/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.ts +45 -0
- package/src/runjs-context/snippets/scene/detail/format-number.snippet.ts +32 -0
- package/src/runjs-context/snippets/scene/detail/innerHTML-value.snippet.ts +31 -0
- package/src/runjs-context/snippets/scene/detail/percentage-bar.snippet.ts +63 -0
- package/src/runjs-context/snippets/scene/detail/relative-time.snippet.ts +61 -0
- package/src/runjs-context/snippets/scene/detail/status-tag.snippet.ts +55 -0
- package/src/runjs-context/snippets/scene/form/calculate-total.snippet.ts +44 -0
- package/src/runjs-context/snippets/scene/form/cascade-select.snippet.ts +62 -0
- package/src/runjs-context/snippets/scene/form/conditional-required.snippet.ts +45 -0
- package/src/runjs-context/snippets/scene/form/copy-field-values.snippet.ts +55 -0
- package/src/runjs-context/snippets/scene/form/render-basic.snippet.ts +39 -0
- package/src/runjs-context/snippets/scene/form/set-disabled.snippet.ts +50 -0
- package/src/runjs-context/snippets/scene/form/set-field-value.snippet.ts +49 -0
- package/src/runjs-context/snippets/scene/form/set-required.snippet.ts +50 -0
- package/src/runjs-context/snippets/scene/form/toggle-multiple-fields.snippet.ts +48 -0
- package/src/runjs-context/snippets/scene/form/toggle-visible.snippet.ts +50 -0
- package/src/runjs-context/snippets/scene/table/cell-open-dialog.snippet.ts +45 -0
- package/src/runjs-context/snippets/scene/table/collection-selected-count.snippet.ts +34 -0
- package/src/runjs-context/snippets/scene/table/concat-fields.snippet.ts +60 -0
- package/src/runjs-context/snippets/scene/table/destroy-selected.snippet.ts +36 -0
- package/src/runjs-context/snippets/scene/table/export-selected-json.snippet.ts +45 -0
- package/src/runjs-context/snippets/scene/table/iterate-selected-rows.snippet.ts +33 -0
- package/src/runjs-context/snippets/types.ts +21 -0
- package/src/types.ts +484 -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 +62 -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 +112 -0
- package/src/utils/setupRuntimeContextSteps.ts +89 -0
- package/src/utils/translation.ts +37 -0
- package/src/utils/variablesParams.ts +184 -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 +402 -0
- package/src/views/index.tsx +15 -0
- package/src/views/useDialog.tsx +194 -0
- package/src/views/useDrawer.tsx +229 -0
- package/src/views/usePage.tsx +185 -0
- package/src/views/usePatchElement.tsx +27 -0
- package/src/views/usePopover.tsx +131 -0
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { FlowContext, PropertyMeta, PropertyMetaFactory } from '../flowContext';
|
|
11
|
+
import { buildRecordMeta, inferViewRecordRef } from '../utils/variablesParams';
|
|
12
|
+
import type { RecordRef } from '../utils/serverContextParams';
|
|
13
|
+
import type { Collection } from '../data-source';
|
|
14
|
+
import type { FlowView } from './FlowView';
|
|
15
|
+
|
|
16
|
+
// 判断是否为普通对象(Plain Object),避免对类实例/代理等进行深度遍历
|
|
17
|
+
function isPlainObject(val: any) {
|
|
18
|
+
if (val === null || typeof val !== 'object') return false;
|
|
19
|
+
const proto = Object.getPrototypeOf(val);
|
|
20
|
+
return proto === Object.prototype || proto === null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 懒加载元信息:仅在展开节点时计算子属性;并加入循环引用防护
|
|
24
|
+
function makeMetaFromValue(value: any, title?: string, seen?: WeakSet<any>): any {
|
|
25
|
+
const t = typeof value;
|
|
26
|
+
if (value === null || value === undefined) return { type: 'any', title };
|
|
27
|
+
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
return {
|
|
30
|
+
type: 'array',
|
|
31
|
+
title,
|
|
32
|
+
properties: async () => {
|
|
33
|
+
const max = Math.min(value.length || 0, 10);
|
|
34
|
+
const children: Record<string, any> = {};
|
|
35
|
+
const nextSeen = seen ?? new WeakSet<any>();
|
|
36
|
+
for (let i = 0; i < max; i++) {
|
|
37
|
+
children[String(i)] = makeMetaFromValue(value[i], `#${i}`, nextSeen);
|
|
38
|
+
}
|
|
39
|
+
return children;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (t === 'string') return { type: 'string', title };
|
|
45
|
+
if (t === 'number') return { type: 'number', title };
|
|
46
|
+
if (t === 'boolean') return { type: 'boolean', title };
|
|
47
|
+
|
|
48
|
+
// 仅对普通对象做懒递归;其它对象(如运行时实例)视为 any,防止进入复杂的循环引用
|
|
49
|
+
if (t === 'object' && isPlainObject(value)) {
|
|
50
|
+
return {
|
|
51
|
+
type: 'object',
|
|
52
|
+
title,
|
|
53
|
+
properties: async () => {
|
|
54
|
+
const nextSeen = seen ?? new WeakSet<any>();
|
|
55
|
+
if (nextSeen.has(value)) {
|
|
56
|
+
// 循环引用:不再展开子节点
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
nextSeen.add(value);
|
|
60
|
+
const props: Record<string, any> = {};
|
|
61
|
+
Object.keys(value || {}).forEach((k) => {
|
|
62
|
+
props[k] = makeMetaFromValue(value[k], k, nextSeen);
|
|
63
|
+
});
|
|
64
|
+
return props;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return { type: 'any', title };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Create a meta factory for ctx.view that includes:
|
|
73
|
+
* - buildVariablesParams: { record } via inferRecordRef
|
|
74
|
+
* - properties.record: full collection meta via buildRecordMeta
|
|
75
|
+
* - type/preventClose/inputArgs/navigation fields for better variable selection UX
|
|
76
|
+
*/
|
|
77
|
+
export function createViewMeta(ctx: FlowContext): PropertyMetaFactory {
|
|
78
|
+
const viewTitle = ctx.t('当前视图');
|
|
79
|
+
const factory: PropertyMetaFactory = async () => {
|
|
80
|
+
const view = ctx.view;
|
|
81
|
+
return {
|
|
82
|
+
type: 'object',
|
|
83
|
+
title: ctx.t('当前视图'),
|
|
84
|
+
buildVariablesParams: (c) => {
|
|
85
|
+
const params = inferViewRecordRef(c);
|
|
86
|
+
if (params) {
|
|
87
|
+
return {
|
|
88
|
+
record: params,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
},
|
|
93
|
+
properties: async () => {
|
|
94
|
+
const props: Record<string, any> = {};
|
|
95
|
+
// 仅当能推断到当前记录引用时,才暴露“当前视图记录”,避免出现空子菜单
|
|
96
|
+
const refNow = inferViewRecordRef(ctx);
|
|
97
|
+
if (refNow && refNow.collection) {
|
|
98
|
+
const recordFactory: PropertyMetaFactory = async () => {
|
|
99
|
+
try {
|
|
100
|
+
const ref = inferViewRecordRef(ctx);
|
|
101
|
+
if (!ref?.collection) return null;
|
|
102
|
+
const dsKey = ref.dataSourceKey || 'main';
|
|
103
|
+
const ds = ctx.dataSourceManager?.getDataSource?.(dsKey);
|
|
104
|
+
const col = ds?.collectionManager?.getCollection?.(ref.collection);
|
|
105
|
+
if (!col) return null;
|
|
106
|
+
return (await buildRecordMeta(
|
|
107
|
+
() => col,
|
|
108
|
+
ctx.t('当前视图记录'),
|
|
109
|
+
(c) => inferViewRecordRef(c),
|
|
110
|
+
)) as PropertyMeta;
|
|
111
|
+
} catch (e) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
recordFactory.title = ctx.t('当前视图记录');
|
|
116
|
+
recordFactory.hasChildren = true;
|
|
117
|
+
props.record = recordFactory;
|
|
118
|
+
}
|
|
119
|
+
props.type = { type: 'string', title: ctx.t?.('类型') || '类型' };
|
|
120
|
+
props.preventClose = { type: 'boolean', title: ctx.t?.('是否允许关闭') || '是否允许关闭' };
|
|
121
|
+
props.inputArgs = makeMetaFromValue(view?.inputArgs, ctx.t?.('输入参数') || '输入参数');
|
|
122
|
+
return props;
|
|
123
|
+
},
|
|
124
|
+
} as PropertyMeta;
|
|
125
|
+
};
|
|
126
|
+
// 设置工厂函数的 title,让未加载前的占位标题就是“当前视图”
|
|
127
|
+
factory.title = viewTitle;
|
|
128
|
+
return factory;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 为 ctx.popup 构建元信息:
|
|
133
|
+
* - popup.record:当前弹窗记录(服务端解析)
|
|
134
|
+
* - popup.resource:数据源信息(前端解析)
|
|
135
|
+
* - popup.parent:上级弹窗(无限级,前端解析;不存在则禁用/为空)
|
|
136
|
+
*/
|
|
137
|
+
export function createPopupMeta(ctx: FlowContext): PropertyMetaFactory {
|
|
138
|
+
const t = (k: string) => ctx.t(k);
|
|
139
|
+
|
|
140
|
+
const getCurrentCollection = (): Collection | null => {
|
|
141
|
+
try {
|
|
142
|
+
const ref = inferViewRecordRef(ctx);
|
|
143
|
+
if (!ref?.filterByTk) return null;
|
|
144
|
+
const ds = ctx.dataSourceManager?.getDataSource?.(ref.dataSourceKey || 'main');
|
|
145
|
+
return ds?.collectionManager?.getCollection?.(ref.collection) || null;
|
|
146
|
+
} catch (_) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// 从视图堆栈推断 level 级父弹窗(level=1 上一层)
|
|
152
|
+
const getParentRecordRef = async (level: number): Promise<RecordRef | undefined> => {
|
|
153
|
+
try {
|
|
154
|
+
const nav = ctx.view?.navigation;
|
|
155
|
+
const stack = Array.isArray(nav?.viewStack) ? nav.viewStack : [];
|
|
156
|
+
if (stack.length < 2 || level < 1) return undefined;
|
|
157
|
+
const idx = stack.length - 1 - level;
|
|
158
|
+
if (idx < 0) return undefined;
|
|
159
|
+
const parent = stack[idx];
|
|
160
|
+
if (!parent?.viewUid) return undefined;
|
|
161
|
+
|
|
162
|
+
let model: any = ctx.engine?.getModel?.(parent.viewUid);
|
|
163
|
+
if (!model && typeof ctx.engine?.loadModel === 'function') {
|
|
164
|
+
try {
|
|
165
|
+
model = await ctx.engine.loadModel({ uid: parent.viewUid });
|
|
166
|
+
} catch (e) {
|
|
167
|
+
console.warn('[FlowEngine] popup.getParentRecordRef loadModel failed:', e);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const params = model?.getStepParams?.('popupSettings', 'openView') || {};
|
|
171
|
+
const collection = params?.collectionName;
|
|
172
|
+
const dataSourceKey = params?.dataSourceKey || 'main';
|
|
173
|
+
const filterByTk = parent?.filterByTk ?? parent?.sourceId;
|
|
174
|
+
if (!collection || typeof filterByTk === 'undefined' || filterByTk === null) return undefined;
|
|
175
|
+
return { collection, dataSourceKey, filterByTk };
|
|
176
|
+
} catch (e) {
|
|
177
|
+
console.warn('[FlowEngine] popup.getParentRecordRef failed:', e);
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const hasParentNow = (level: number): boolean => {
|
|
183
|
+
try {
|
|
184
|
+
const nav = ctx.view?.navigation;
|
|
185
|
+
const stack = Array.isArray(nav?.viewStack) ? nav.viewStack : [];
|
|
186
|
+
return stack.length >= level + 1; // level=1 需要至少2层
|
|
187
|
+
} catch (_) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const createParentFactory = (level: number): PropertyMetaFactory => {
|
|
193
|
+
const factory: PropertyMetaFactory = () => {
|
|
194
|
+
const meta: PropertyMeta = {
|
|
195
|
+
type: 'object',
|
|
196
|
+
title: t('Parent popup'),
|
|
197
|
+
disabled: () => !hasParentNow(level),
|
|
198
|
+
disabledReason: () => (!hasParentNow(level) ? t('No parent popup') : undefined),
|
|
199
|
+
properties: async () => {
|
|
200
|
+
const parentRef = await getParentRecordRef(level);
|
|
201
|
+
const props: Record<string, any> = {};
|
|
202
|
+
// 弹窗 UID(纯前端变量)
|
|
203
|
+
props.uid = { type: 'string', title: t('Popup uid') };
|
|
204
|
+
|
|
205
|
+
// 记录分组
|
|
206
|
+
if (parentRef) {
|
|
207
|
+
const parentCollection = (() => {
|
|
208
|
+
try {
|
|
209
|
+
const ds = ctx.dataSourceManager?.getDataSource?.(parentRef.dataSourceKey || 'main');
|
|
210
|
+
return ds?.collectionManager?.getCollection?.(parentRef.collection || '') || null;
|
|
211
|
+
} catch (_) {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
})();
|
|
215
|
+
const base = await buildRecordMeta(
|
|
216
|
+
() => parentCollection,
|
|
217
|
+
t('Popup record'),
|
|
218
|
+
() => parentRef,
|
|
219
|
+
);
|
|
220
|
+
props.record = base || { type: 'object', title: t('Popup record') };
|
|
221
|
+
} else {
|
|
222
|
+
props.record = { type: 'object', title: t('Popup record') };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// 数据源分组(前端显示用)
|
|
226
|
+
const resourceMeta: PropertyMeta = {
|
|
227
|
+
type: 'object',
|
|
228
|
+
title: t('Data source'),
|
|
229
|
+
properties: async () => ({
|
|
230
|
+
dataSourceKey: { type: 'string', title: t('Data source key') },
|
|
231
|
+
collectionName: { type: 'string', title: t('Collection name') },
|
|
232
|
+
filterByTk: { type: 'string', title: t('filterByTk') },
|
|
233
|
+
sourceId: { type: 'string', title: t('sourceId') },
|
|
234
|
+
}),
|
|
235
|
+
};
|
|
236
|
+
props.resource = resourceMeta;
|
|
237
|
+
|
|
238
|
+
// 不在 "上级弹窗" 节点内继续渲染下一层,以避免列表中出现重复的“上级弹窗”层级
|
|
239
|
+
// 仍然保留运行时值中的 parent.parent... 链(buildPopupRuntime 会构建完整链),
|
|
240
|
+
// 以便用户手动输入时可以访问更深层级。
|
|
241
|
+
return props;
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
return meta;
|
|
245
|
+
};
|
|
246
|
+
factory.title = t('Parent popup');
|
|
247
|
+
return factory;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const factory: PropertyMetaFactory = () => {
|
|
251
|
+
const meta: PropertyMeta = {
|
|
252
|
+
type: 'object',
|
|
253
|
+
title: t('Current popup'),
|
|
254
|
+
buildVariablesParams: (c) => {
|
|
255
|
+
const ref = inferViewRecordRef(c);
|
|
256
|
+
const inputArgs = (c?.view as any)?.inputArgs || {};
|
|
257
|
+
const out: Record<string, any> = { record: ref };
|
|
258
|
+
try {
|
|
259
|
+
const srcId = inputArgs?.sourceId;
|
|
260
|
+
const assoc: string | undefined = inputArgs?.associationName;
|
|
261
|
+
const dsKey: string = inputArgs?.dataSourceKey || 'main';
|
|
262
|
+
if (srcId != null && srcId !== '' && assoc && typeof assoc === 'string') {
|
|
263
|
+
// associationName 形如 `posts.comments`,父级集合为 `posts`
|
|
264
|
+
const parentCollectionName = String(assoc).split('.')[0];
|
|
265
|
+
if (parentCollectionName) {
|
|
266
|
+
out.sourceRecord = {
|
|
267
|
+
collection: parentCollectionName,
|
|
268
|
+
dataSourceKey: dsKey,
|
|
269
|
+
filterByTk: srcId,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
} catch (_) {
|
|
274
|
+
// 忽略异常,保持 record 正常返回
|
|
275
|
+
}
|
|
276
|
+
return out;
|
|
277
|
+
},
|
|
278
|
+
properties: async () => {
|
|
279
|
+
const props: Record<string, any> = {};
|
|
280
|
+
// 当前弹窗 UID(纯前端变量)
|
|
281
|
+
props.uid = { type: 'string', title: t('Popup uid') };
|
|
282
|
+
const base = await buildRecordMeta(getCurrentCollection, t('Current popup record'), (c) =>
|
|
283
|
+
inferViewRecordRef(c),
|
|
284
|
+
);
|
|
285
|
+
if (base) props.record = base;
|
|
286
|
+
// 当 view.inputArgs 带有 sourceId + associationName 时,提供“上级记录”变量(基于 sourceId 推断)
|
|
287
|
+
try {
|
|
288
|
+
const inputArgs = (ctx.view as any)?.inputArgs || {};
|
|
289
|
+
const srcId = inputArgs?.sourceId;
|
|
290
|
+
const assoc: string | undefined = inputArgs?.associationName;
|
|
291
|
+
const dsKey: string = inputArgs?.dataSourceKey || 'main';
|
|
292
|
+
if (srcId != null && srcId !== '' && assoc && typeof assoc === 'string') {
|
|
293
|
+
const parentCollectionName = String(assoc).includes('.') ? String(assoc).split('.')[0] : undefined;
|
|
294
|
+
if (parentCollectionName) {
|
|
295
|
+
const parentCollectionAccessor = () => {
|
|
296
|
+
try {
|
|
297
|
+
const ds = ctx.dataSourceManager?.getDataSource?.(dsKey);
|
|
298
|
+
return ds?.collectionManager?.getCollection?.(parentCollectionName) || null;
|
|
299
|
+
} catch (_) {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
const srcMeta = await buildRecordMeta(parentCollectionAccessor, t('Current popup parent record'), () => ({
|
|
304
|
+
collection: parentCollectionName,
|
|
305
|
+
dataSourceKey: dsKey,
|
|
306
|
+
filterByTk: srcId,
|
|
307
|
+
}));
|
|
308
|
+
if (srcMeta) {
|
|
309
|
+
props.sourceRecord = srcMeta;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
} catch (_) {
|
|
314
|
+
// ignore
|
|
315
|
+
}
|
|
316
|
+
const resourceMeta: PropertyMeta = {
|
|
317
|
+
type: 'object',
|
|
318
|
+
title: t('Data source'),
|
|
319
|
+
properties: async () => ({
|
|
320
|
+
dataSourceKey: { type: 'string', title: t('Data source key') },
|
|
321
|
+
collectionName: { type: 'string', title: t('Collection name') },
|
|
322
|
+
filterByTk: { type: 'string', title: t('filterByTk') },
|
|
323
|
+
sourceId: { type: 'string', title: t('sourceId') },
|
|
324
|
+
}),
|
|
325
|
+
};
|
|
326
|
+
props.resource = resourceMeta;
|
|
327
|
+
// 是否展示“上级弹窗”应依据实际视图层级,而不是简单以配置态隐藏。
|
|
328
|
+
// 当存在父级弹窗(不含当前配置弹窗自身)时,展示“上级弹窗”节点。
|
|
329
|
+
const parentRef1 = await getParentRecordRef(1);
|
|
330
|
+
if (parentRef1) {
|
|
331
|
+
props.parent = createParentFactory(1);
|
|
332
|
+
}
|
|
333
|
+
return props;
|
|
334
|
+
},
|
|
335
|
+
};
|
|
336
|
+
return meta;
|
|
337
|
+
};
|
|
338
|
+
factory.title = t('Current popup');
|
|
339
|
+
factory.sort = 975;
|
|
340
|
+
return factory;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 根据视图堆栈构建 popup 运行时值(resource + parent 链)
|
|
345
|
+
*/
|
|
346
|
+
interface PopupNodeResource {
|
|
347
|
+
dataSourceKey: string;
|
|
348
|
+
collectionName?: string;
|
|
349
|
+
filterByTk?: any;
|
|
350
|
+
sourceId?: any;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
interface PopupNode {
|
|
354
|
+
uid?: string;
|
|
355
|
+
resource: PopupNodeResource;
|
|
356
|
+
parent?: PopupNode;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export async function buildPopupRuntime(ctx: FlowContext, view: FlowView): Promise<PopupNode> {
|
|
360
|
+
const nav = view?.navigation;
|
|
361
|
+
const stack = Array.isArray(nav?.viewStack) ? nav.viewStack : [];
|
|
362
|
+
const buildNode = async (idx: number): Promise<PopupNode | undefined> => {
|
|
363
|
+
if (idx < 0 || !stack[idx]?.viewUid) return undefined;
|
|
364
|
+
const viewUid = stack[idx].viewUid;
|
|
365
|
+
let model: any = ctx.engine?.getModel?.(viewUid);
|
|
366
|
+
if (!model && typeof ctx.engine?.loadModel === 'function') {
|
|
367
|
+
model = await ctx.engine?.loadModel({ uid: viewUid });
|
|
368
|
+
}
|
|
369
|
+
const p = model?.getStepParams?.('popupSettings', 'openView') || {};
|
|
370
|
+
const collectionName = p?.collectionName;
|
|
371
|
+
const dataSourceKey = p?.dataSourceKey || 'main';
|
|
372
|
+
const node: PopupNode = {
|
|
373
|
+
uid: viewUid,
|
|
374
|
+
resource: {
|
|
375
|
+
dataSourceKey,
|
|
376
|
+
collectionName,
|
|
377
|
+
filterByTk: stack[idx]?.filterByTk,
|
|
378
|
+
sourceId: stack[idx]?.sourceId,
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
const parentNode = await buildNode(idx - 1);
|
|
382
|
+
if (parentNode) node.parent = parentNode;
|
|
383
|
+
return node;
|
|
384
|
+
};
|
|
385
|
+
const currentNode = await buildNode((view?.navigation?.viewStack?.length || 1) - 1);
|
|
386
|
+
return currentNode;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* 在视图上下文中注册 popup 变量(统一消除重复)
|
|
391
|
+
*/
|
|
392
|
+
export function registerPopupVariable(ctx: FlowContext, view: FlowView) {
|
|
393
|
+
// 始终注册 popup 变量:
|
|
394
|
+
// - 若当前视图无可推断记录,仅在元信息中不呈现 record 字段;
|
|
395
|
+
// - 但仍可依据 navigation 推断并展示上级弹窗信息。
|
|
396
|
+
ctx.defineProperty('popup', {
|
|
397
|
+
get: async () => buildPopupRuntime(ctx, view),
|
|
398
|
+
meta: createPopupMeta(ctx),
|
|
399
|
+
resolveOnServer: (p: string) =>
|
|
400
|
+
p === 'record' || p?.startsWith('record.') || p === 'sourceRecord' || p?.startsWith('sourceRecord.'),
|
|
401
|
+
});
|
|
402
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { useDialog } from './useDialog';
|
|
11
|
+
export { useDrawer } from './useDrawer';
|
|
12
|
+
export { usePage } from './usePage';
|
|
13
|
+
export { usePopover } from './usePopover';
|
|
14
|
+
export { ViewNavigation } from './ViewNavigation';
|
|
15
|
+
export { createViewMeta } from './createViewMeta';
|
|
@@ -0,0 +1,194 @@
|
|
|
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 * as React from 'react';
|
|
11
|
+
import DOMPurify from 'dompurify';
|
|
12
|
+
import { observer } from '..';
|
|
13
|
+
import { FlowContext } from '../flowContext';
|
|
14
|
+
import { FlowViewContextProvider } from '../FlowContextProvider';
|
|
15
|
+
import { registerPopupVariable } from './createViewMeta';
|
|
16
|
+
import DialogComponent from './DialogComponent';
|
|
17
|
+
import usePatchElement from './usePatchElement';
|
|
18
|
+
import { FlowEngineProvider } from '../provider';
|
|
19
|
+
import { createViewScopedEngine } from '../ViewScopedFlowEngine';
|
|
20
|
+
|
|
21
|
+
let uuid = 0;
|
|
22
|
+
|
|
23
|
+
export function useDialog() {
|
|
24
|
+
const holderRef = React.useRef(null);
|
|
25
|
+
|
|
26
|
+
const open = (config, flowContext) => {
|
|
27
|
+
uuid += 1;
|
|
28
|
+
const dialogRef = React.createRef<{
|
|
29
|
+
destroy: () => void;
|
|
30
|
+
update: (config: any) => void;
|
|
31
|
+
setFooter: (footer: React.ReactNode) => void;
|
|
32
|
+
setHeader: (header: { title?: React.ReactNode; extra?: React.ReactNode }) => void;
|
|
33
|
+
}>();
|
|
34
|
+
|
|
35
|
+
// eslint-disable-next-line prefer-const
|
|
36
|
+
let closeFunc: (() => void) | undefined;
|
|
37
|
+
let resolvePromise: (value?: any) => void;
|
|
38
|
+
const promise = new Promise((resolve) => {
|
|
39
|
+
resolvePromise = resolve;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// 使用普通变量来存储状态
|
|
43
|
+
let currentFooter: React.ReactNode = null;
|
|
44
|
+
let currentHeader: any = null;
|
|
45
|
+
|
|
46
|
+
// Footer 组件实现
|
|
47
|
+
const FooterComponent: React.FC<{ children?: React.ReactNode }> = ({ children }) => {
|
|
48
|
+
React.useEffect(() => {
|
|
49
|
+
currentFooter = children;
|
|
50
|
+
dialogRef.current?.setFooter(children);
|
|
51
|
+
|
|
52
|
+
return () => {
|
|
53
|
+
currentFooter = null;
|
|
54
|
+
dialogRef.current?.setFooter(null);
|
|
55
|
+
};
|
|
56
|
+
}, [children]);
|
|
57
|
+
|
|
58
|
+
return null; // Footer 组件本身不渲染内容
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Header 组件实现
|
|
62
|
+
const HeaderComponent: React.FC<{ title?: React.ReactNode; extra?: React.ReactNode }> = (props) => {
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
currentHeader = props;
|
|
65
|
+
dialogRef.current?.setHeader(props);
|
|
66
|
+
|
|
67
|
+
return () => {
|
|
68
|
+
currentHeader = null;
|
|
69
|
+
dialogRef.current?.setHeader(null);
|
|
70
|
+
};
|
|
71
|
+
}, [props]);
|
|
72
|
+
|
|
73
|
+
return null; // Header 组件本身不渲染内容
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// 构造 currentDialog 实例
|
|
77
|
+
const currentDialog = {
|
|
78
|
+
type: 'dialog' as const,
|
|
79
|
+
inputArgs: config.inputArgs || {},
|
|
80
|
+
preventClose: !!config.preventClose,
|
|
81
|
+
destroy: () => dialogRef.current?.destroy(),
|
|
82
|
+
update: (newConfig) => dialogRef.current?.update(newConfig),
|
|
83
|
+
close: (result?: any, force?: boolean) => {
|
|
84
|
+
if (config.preventClose && !force) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
dialogRef.current?.destroy();
|
|
88
|
+
closeFunc?.();
|
|
89
|
+
resolvePromise?.(result);
|
|
90
|
+
},
|
|
91
|
+
Footer: FooterComponent,
|
|
92
|
+
Header: HeaderComponent,
|
|
93
|
+
setFooter: (footer: React.ReactNode) => {
|
|
94
|
+
currentFooter = footer;
|
|
95
|
+
dialogRef.current?.setFooter(footer);
|
|
96
|
+
},
|
|
97
|
+
setHeader: (header: { title?: React.ReactNode; extra?: React.ReactNode }) => {
|
|
98
|
+
currentHeader = header;
|
|
99
|
+
dialogRef.current?.setHeader(header);
|
|
100
|
+
},
|
|
101
|
+
navigation: config.inputArgs?.navigation,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const ctx = new FlowContext();
|
|
105
|
+
// 为当前视图创建作用域引擎(隔离实例与缓存)
|
|
106
|
+
const scopedEngine = createViewScopedEngine(flowContext.engine);
|
|
107
|
+
ctx.defineProperty('engine', { value: scopedEngine });
|
|
108
|
+
ctx.addDelegate(scopedEngine.context);
|
|
109
|
+
if (config.inheritContext !== false) {
|
|
110
|
+
ctx.addDelegate(flowContext);
|
|
111
|
+
} else {
|
|
112
|
+
ctx.addDelegate(flowContext.engine.context);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
ctx.defineProperty('view', {
|
|
116
|
+
get: () => currentDialog,
|
|
117
|
+
// meta: createViewMeta(ctx),
|
|
118
|
+
resolveOnServer: (p: string) => p === 'record' || p.startsWith('record.'),
|
|
119
|
+
});
|
|
120
|
+
// 顶层 popup 变量:弹窗记录/数据源/上级弹窗链(去重封装)
|
|
121
|
+
registerPopupVariable(ctx, currentDialog);
|
|
122
|
+
// 内部组件,在 Provider 内部计算 content
|
|
123
|
+
const DialogWithContext = observer(
|
|
124
|
+
() => {
|
|
125
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
126
|
+
const mountedRef = React.useRef(false);
|
|
127
|
+
const rawContent = typeof config.content === 'function' ? config.content(currentDialog, ctx) : config.content;
|
|
128
|
+
const content =
|
|
129
|
+
typeof rawContent === 'string' ? (
|
|
130
|
+
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(rawContent) }} />
|
|
131
|
+
) : (
|
|
132
|
+
rawContent
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
136
|
+
React.useEffect(() => {
|
|
137
|
+
config.onOpen?.(currentDialog, ctx);
|
|
138
|
+
}, []);
|
|
139
|
+
|
|
140
|
+
if (config.inputArgs?.hidden?.value && !mountedRef.current) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
mountedRef.current = true;
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<DialogComponent
|
|
148
|
+
className="nb-dialog-overflow-hidden"
|
|
149
|
+
key={`dialog-${uuid}`}
|
|
150
|
+
ref={dialogRef}
|
|
151
|
+
hidden={config.inputArgs?.hidden?.value}
|
|
152
|
+
{...config}
|
|
153
|
+
footer={currentFooter}
|
|
154
|
+
header={currentHeader}
|
|
155
|
+
afterClose={() => {
|
|
156
|
+
closeFunc?.();
|
|
157
|
+
config.onClose?.();
|
|
158
|
+
resolvePromise?.(config.result);
|
|
159
|
+
// 关闭时修正 previous/next 指针
|
|
160
|
+
scopedEngine.unlinkFromStack();
|
|
161
|
+
}}
|
|
162
|
+
>
|
|
163
|
+
{content}
|
|
164
|
+
</DialogComponent>
|
|
165
|
+
);
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
displayName: 'DialogWithContext',
|
|
169
|
+
},
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const dialog = (
|
|
173
|
+
<FlowEngineProvider engine={scopedEngine}>
|
|
174
|
+
<FlowViewContextProvider context={ctx}>
|
|
175
|
+
<DialogWithContext />
|
|
176
|
+
</FlowViewContextProvider>
|
|
177
|
+
</FlowEngineProvider>
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
closeFunc = holderRef.current?.patchElement(dialog);
|
|
181
|
+
return Object.assign(promise, currentDialog);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const api = React.useMemo(() => ({ open }), []);
|
|
185
|
+
const ElementsHolder = React.memo(
|
|
186
|
+
React.forwardRef((props, ref) => {
|
|
187
|
+
const [elements, patchElement] = usePatchElement();
|
|
188
|
+
React.useImperativeHandle(ref, () => ({ patchElement }), [patchElement]);
|
|
189
|
+
return <>{elements}</>;
|
|
190
|
+
}),
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
return [api, <ElementsHolder key="dialog-holder" ref={holderRef} />];
|
|
194
|
+
}
|