@nocobase/flow-engine 2.1.0-alpha.1 → 2.1.0-alpha.11
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 +201 -661
- package/README.md +79 -10
- package/lib/BlockScopedFlowEngine.js +0 -1
- package/lib/FlowDefinition.d.ts +6 -0
- package/lib/FlowSchemaRegistry.d.ts +154 -0
- package/lib/FlowSchemaRegistry.js +1427 -0
- package/lib/JSRunner.d.ts +15 -0
- package/lib/JSRunner.js +82 -7
- package/lib/ViewScopedFlowEngine.js +8 -1
- package/lib/acl/Acl.js +13 -3
- package/lib/components/FlowContextSelector.js +155 -10
- package/lib/components/MobilePopup.js +6 -5
- package/lib/components/dnd/gridDragPlanner.d.ts +1 -0
- package/lib/components/dnd/gridDragPlanner.js +59 -3
- package/lib/components/settings/wrappers/component/SwitchWithTitle.js +2 -1
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +76 -15
- package/lib/components/settings/wrappers/contextual/FlowsContextMenu.js +24 -4
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +21 -3
- package/lib/components/subModel/AddSubModelButton.js +27 -1
- package/lib/components/subModel/utils.js +2 -2
- package/lib/components/variables/VariableInput.js +9 -4
- package/lib/components/variables/VariableTag.js +46 -39
- package/lib/components/variables/utils.d.ts +7 -0
- package/lib/components/variables/utils.js +42 -2
- package/lib/data-source/index.d.ts +7 -27
- package/lib/data-source/index.js +84 -51
- package/lib/executor/FlowExecutor.d.ts +2 -1
- package/lib/executor/FlowExecutor.js +190 -26
- package/lib/flow-schema-registry/fieldBinding.d.ts +32 -0
- package/lib/flow-schema-registry/fieldBinding.js +165 -0
- package/lib/flow-schema-registry/modelPatches.d.ts +16 -0
- package/lib/flow-schema-registry/modelPatches.js +235 -0
- package/lib/flow-schema-registry/schemaInference.d.ts +17 -0
- package/lib/flow-schema-registry/schemaInference.js +207 -0
- package/lib/flow-schema-registry/utils.d.ts +25 -0
- package/lib/flow-schema-registry/utils.js +293 -0
- package/lib/flowContext.d.ts +230 -7
- package/lib/flowContext.js +2270 -148
- package/lib/flowEngine.d.ts +160 -1
- package/lib/flowEngine.js +387 -27
- package/lib/flowI18n.js +6 -4
- package/lib/flowSettings.d.ts +14 -6
- package/lib/flowSettings.js +51 -17
- package/lib/index.d.ts +8 -1
- package/lib/index.js +24 -1
- package/lib/lazy-helper.d.ts +14 -0
- package/lib/lazy-helper.js +71 -0
- package/lib/locale/en-US.json +9 -2
- package/lib/locale/index.d.ts +14 -0
- package/lib/locale/zh-CN.json +8 -1
- package/lib/models/CollectionFieldModel.d.ts +1 -0
- package/lib/models/CollectionFieldModel.js +3 -2
- package/lib/models/DisplayItemModel.d.ts +1 -1
- package/lib/models/EditableItemModel.d.ts +1 -1
- package/lib/models/FilterableItemModel.d.ts +1 -1
- package/lib/models/flowModel.d.ts +7 -0
- package/lib/models/flowModel.js +83 -8
- package/lib/provider.js +7 -6
- package/lib/resources/baseRecordResource.d.ts +5 -0
- package/lib/resources/baseRecordResource.js +24 -0
- package/lib/resources/multiRecordResource.d.ts +1 -0
- package/lib/resources/multiRecordResource.js +11 -4
- package/lib/resources/singleRecordResource.js +2 -0
- package/lib/resources/sqlResource.d.ts +4 -3
- package/lib/resources/sqlResource.js +8 -3
- package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.js +12 -2
- package/lib/runjs-context/contexts/JSBlockRunJSContext.js +2 -2
- package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.d.ts +16 -0
- package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.js +125 -0
- package/lib/runjs-context/contexts/JSItemRunJSContext.js +12 -2
- package/lib/runjs-context/contexts/base.js +706 -41
- package/lib/runjs-context/contributions.d.ts +33 -0
- package/lib/runjs-context/contributions.js +88 -0
- package/lib/runjs-context/helpers.js +12 -1
- package/lib/runjs-context/registry.d.ts +1 -1
- package/lib/runjs-context/setup.js +23 -9
- package/lib/runjs-context/snippets/global/api-request.snippet.js +3 -3
- package/lib/runjs-context/snippets/global/import-esm.snippet.js +2 -3
- package/lib/runjs-context/snippets/global/query-selector.snippet.js +8 -3
- package/lib/runjs-context/snippets/global/require-amd.snippet.js +1 -1
- package/lib/runjs-context/snippets/index.d.ts +11 -1
- package/lib/runjs-context/snippets/index.js +61 -40
- package/lib/runjs-context/snippets/scene/block/add-event-listener.snippet.js +10 -7
- package/lib/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.js +3 -3
- package/lib/runjs-context/snippets/scene/block/chartjs-bar.snippet.js +2 -2
- package/lib/runjs-context/snippets/scene/block/echarts-init.snippet.js +2 -2
- package/lib/runjs-context/snippets/scene/block/render-iframe.snippet.js +2 -2
- package/lib/runjs-context/snippets/scene/block/render-react.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/block/resource-example.snippet.js +5 -5
- package/lib/runjs-context/snippets/scene/block/three-users-orbit.snippet.js +6 -6
- package/lib/runjs-context/snippets/scene/block/vue-component.snippet.js +3 -4
- package/lib/runjs-context/snippets/scene/detail/color-by-value.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.js +20 -3
- package/lib/runjs-context/snippets/scene/detail/format-number.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/detail/innerHTML-value.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/detail/percentage-bar.snippet.js +3 -3
- package/lib/runjs-context/snippets/scene/detail/relative-time.snippet.js +3 -3
- package/lib/runjs-context/snippets/scene/detail/status-tag.snippet.js +2 -2
- package/lib/runjs-context/snippets/scene/form/cascade-select.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/form/render-basic.snippet.js +2 -2
- package/lib/runjs-context/snippets/scene/table/cell-open-dialog.snippet.js +6 -3
- package/lib/runjs-context/snippets/scene/table/concat-fields.snippet.js +3 -1
- package/lib/runjsLibs.d.ts +28 -0
- package/lib/runjsLibs.js +532 -0
- package/lib/scheduler/ModelOperationScheduler.d.ts +7 -1
- package/lib/scheduler/ModelOperationScheduler.js +28 -23
- package/lib/server.d.ts +10 -0
- package/lib/server.js +32 -0
- package/lib/types.d.ts +296 -1
- package/lib/utils/associationObjectVariable.d.ts +2 -2
- package/lib/utils/createCollectionContextMeta.js +1 -0
- package/lib/utils/createEphemeralContext.js +2 -2
- package/lib/utils/dateVariable.d.ts +16 -0
- package/lib/utils/dateVariable.js +380 -0
- package/lib/utils/exceptions.d.ts +7 -0
- package/lib/utils/exceptions.js +10 -0
- package/lib/utils/index.d.ts +8 -3
- package/lib/utils/index.js +49 -0
- package/lib/utils/params-resolvers.js +16 -9
- package/lib/utils/parsePathnameToViewParams.js +1 -1
- package/lib/utils/resolveModuleUrl.d.ts +58 -0
- package/lib/utils/resolveModuleUrl.js +65 -0
- package/lib/utils/resolveRunJSObjectValues.d.ts +16 -0
- package/lib/utils/resolveRunJSObjectValues.js +61 -0
- package/lib/utils/runjsModuleLoader.d.ts +58 -0
- package/lib/utils/runjsModuleLoader.js +422 -0
- package/lib/utils/runjsTemplateCompat.d.ts +35 -0
- package/lib/utils/runjsTemplateCompat.js +743 -0
- package/lib/utils/runjsValue.d.ts +29 -0
- package/lib/utils/runjsValue.js +275 -0
- package/lib/utils/safeGlobals.d.ts +18 -8
- package/lib/utils/safeGlobals.js +164 -17
- package/lib/utils/schema-utils.d.ts +17 -1
- package/lib/utils/schema-utils.js +80 -0
- package/lib/views/FlowView.d.ts +7 -1
- package/lib/views/createViewMeta.d.ts +0 -7
- package/lib/views/createViewMeta.js +19 -70
- package/lib/views/index.d.ts +1 -2
- package/lib/views/index.js +4 -3
- package/lib/views/runViewBeforeClose.d.ts +10 -0
- package/lib/views/runViewBeforeClose.js +45 -0
- package/lib/views/useDialog.d.ts +2 -1
- package/lib/views/useDialog.js +28 -6
- package/lib/views/useDrawer.d.ts +2 -1
- package/lib/views/useDrawer.js +27 -5
- package/lib/views/usePage.d.ts +6 -1
- package/lib/views/usePage.js +53 -9
- package/lib/views/usePopover.js +4 -1
- package/lib/views/viewEvents.d.ts +17 -0
- package/lib/views/viewEvents.js +90 -0
- package/package.json +5 -5
- package/server.d.ts +1 -0
- package/server.js +1 -0
- package/src/BlockScopedFlowEngine.ts +2 -5
- package/src/FlowSchemaRegistry.ts +1799 -0
- package/src/JSRunner.ts +111 -5
- package/src/ViewScopedFlowEngine.ts +8 -0
- package/src/__tests__/FlowSchemaRegistry.test.ts +1951 -0
- package/src/__tests__/JSRunner.test.ts +91 -1
- package/src/__tests__/createViewMeta.popup.test.ts +62 -1
- package/src/__tests__/flow-engine.test.ts +48 -0
- package/src/__tests__/flowContext.test.ts +693 -1
- package/src/__tests__/flowEngine.dataSourceDirty.test.ts +63 -0
- package/src/__tests__/flowEngine.modelLoaders.test.ts +249 -0
- package/src/__tests__/flowEngine.saveModel.test.ts +4 -0
- package/src/__tests__/flowModel.openView.navigation.test.ts +28 -0
- package/src/__tests__/flowRunJSContextDefine.test.ts +63 -0
- package/src/__tests__/flowRuntimeContext.test.ts +2 -1
- package/src/__tests__/flowSettings.open.test.tsx +123 -19
- package/src/__tests__/flowSettings.test.ts +94 -15
- package/src/__tests__/provider.test.tsx +0 -5
- package/src/__tests__/renderHiddenInConfig.test.tsx +6 -6
- package/src/__tests__/runjsContext.test.ts +26 -7
- package/src/__tests__/runjsContextImplementations.test.ts +34 -3
- package/src/__tests__/runjsContextRuntime.test.ts +5 -3
- package/src/__tests__/runjsContributions.test.ts +89 -0
- package/src/__tests__/runjsExternalLibs.test.ts +242 -0
- package/src/__tests__/runjsLibsLazyLoading.test.ts +44 -0
- package/src/__tests__/runjsLocales.test.ts +4 -1
- package/src/__tests__/runjsPreprocessDefault.test.ts +72 -0
- package/src/__tests__/runjsRuntimeFeatures.test.ts +166 -0
- package/src/__tests__/runjsSnippets.test.ts +40 -3
- package/src/__tests__/viewScopedFlowEngine.test.ts +3 -3
- package/src/acl/Acl.tsx +3 -3
- package/src/components/FlowContextSelector.tsx +208 -12
- package/src/components/MobilePopup.tsx +4 -2
- package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +3 -3
- package/src/components/__tests__/gridDragPlanner.test.ts +229 -1
- package/src/components/dnd/gridDragPlanner.ts +68 -2
- package/src/components/settings/wrappers/component/SwitchWithTitle.tsx +2 -1
- package/src/components/settings/wrappers/component/__tests__/InlineControls.test.tsx +74 -0
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +109 -16
- package/src/components/settings/wrappers/contextual/FlowsContextMenu.tsx +41 -7
- package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +31 -4
- package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +157 -5
- package/src/components/subModel/AddSubModelButton.tsx +32 -2
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +143 -32
- package/src/components/subModel/utils.ts +1 -1
- package/src/components/variables/VariableInput.tsx +12 -4
- package/src/components/variables/VariableTag.tsx +54 -45
- package/src/components/variables/__tests__/FlowContextSelector.test.tsx +260 -3
- package/src/components/variables/__tests__/VariableTag.test.tsx +50 -0
- package/src/components/variables/__tests__/utils.test.ts +81 -3
- package/src/components/variables/utils.ts +67 -6
- package/src/data-source/index.ts +88 -110
- package/src/executor/FlowExecutor.ts +230 -28
- package/src/executor/__tests__/flowExecutor.test.ts +123 -0
- package/src/flow-schema-registry/fieldBinding.ts +171 -0
- package/src/flow-schema-registry/modelPatches.ts +260 -0
- package/src/flow-schema-registry/schemaInference.ts +210 -0
- package/src/flow-schema-registry/utils.ts +268 -0
- package/src/flowContext.ts +2989 -212
- package/src/flowEngine.ts +434 -23
- package/src/flowI18n.ts +7 -5
- package/src/flowSettings.ts +58 -18
- package/src/index.ts +15 -1
- package/src/lazy-helper.tsx +57 -0
- package/src/locale/en-US.json +9 -2
- package/src/locale/zh-CN.json +8 -1
- package/src/models/CollectionFieldModel.tsx +3 -1
- package/src/models/DisplayItemModel.tsx +1 -1
- package/src/models/EditableItemModel.tsx +1 -1
- package/src/models/FilterableItemModel.tsx +1 -1
- package/src/models/__tests__/dispatchEvent.when.test.ts +768 -0
- package/src/models/__tests__/flowModel.clone.test.ts +416 -0
- package/src/models/__tests__/flowModel.test.ts +20 -4
- package/src/models/flowModel.tsx +112 -7
- package/src/provider.tsx +9 -7
- package/src/resources/__tests__/multiRecordResource.test.ts +44 -0
- package/src/resources/__tests__/sqlResource.test.ts +60 -0
- package/src/resources/baseRecordResource.ts +31 -0
- package/src/resources/multiRecordResource.ts +11 -4
- package/src/resources/singleRecordResource.ts +3 -0
- package/src/resources/sqlResource.ts +11 -6
- package/src/runjs-context/contexts/FormJSFieldItemRunJSContext.ts +10 -0
- package/src/runjs-context/contexts/JSBlockRunJSContext.ts +6 -2
- package/src/runjs-context/contexts/JSEditableFieldRunJSContext.ts +106 -0
- package/src/runjs-context/contexts/JSItemRunJSContext.ts +10 -0
- package/src/runjs-context/contexts/base.ts +715 -44
- package/src/runjs-context/contributions.ts +88 -0
- package/src/runjs-context/helpers.ts +11 -1
- package/src/runjs-context/registry.ts +1 -1
- package/src/runjs-context/setup.ts +25 -9
- package/src/runjs-context/snippets/global/api-request.snippet.ts +3 -3
- package/src/runjs-context/snippets/global/import-esm.snippet.ts +2 -3
- package/src/runjs-context/snippets/global/query-selector.snippet.ts +8 -3
- package/src/runjs-context/snippets/global/require-amd.snippet.ts +1 -1
- package/src/runjs-context/snippets/index.ts +75 -41
- package/src/runjs-context/snippets/scene/block/add-event-listener.snippet.ts +11 -13
- package/src/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.ts +3 -3
- package/src/runjs-context/snippets/scene/block/chartjs-bar.snippet.ts +2 -2
- package/src/runjs-context/snippets/scene/block/echarts-init.snippet.ts +2 -2
- package/src/runjs-context/snippets/scene/block/render-iframe.snippet.ts +2 -2
- package/src/runjs-context/snippets/scene/block/render-react.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/block/render-statistics.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/block/render-timeline.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/block/resource-example.snippet.ts +6 -11
- package/src/runjs-context/snippets/scene/block/three-users-orbit.snippet.ts +6 -6
- package/src/runjs-context/snippets/scene/block/vue-component.snippet.ts +3 -4
- package/src/runjs-context/snippets/scene/detail/color-by-value.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.ts +20 -3
- package/src/runjs-context/snippets/scene/detail/format-number.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/detail/innerHTML-value.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/detail/percentage-bar.snippet.ts +3 -3
- package/src/runjs-context/snippets/scene/detail/relative-time.snippet.ts +3 -3
- package/src/runjs-context/snippets/scene/detail/status-tag.snippet.ts +2 -2
- package/src/runjs-context/snippets/scene/form/cascade-select.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/form/render-basic.snippet.ts +3 -8
- package/src/runjs-context/snippets/scene/table/cell-open-dialog.snippet.ts +6 -3
- package/src/runjs-context/snippets/scene/table/concat-fields.snippet.ts +3 -1
- package/src/runjsLibs.ts +622 -0
- package/src/scheduler/ModelOperationScheduler.ts +41 -24
- package/src/server.ts +11 -0
- package/src/types.ts +359 -1
- package/src/utils/__tests__/dateVariable.test.ts +101 -0
- package/src/utils/__tests__/params-resolvers.test.ts +40 -0
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +7 -0
- package/src/utils/__tests__/runjsRequireAsyncAutoWhitelist.test.ts +38 -0
- package/src/utils/__tests__/runjsTemplateCompat.test.ts +159 -0
- package/src/utils/__tests__/runjsValue.test.ts +44 -0
- package/src/utils/__tests__/safeGlobals.test.ts +57 -2
- package/src/utils/__tests__/utils.test.ts +157 -0
- package/src/utils/associationObjectVariable.ts +2 -2
- package/src/utils/createCollectionContextMeta.ts +1 -0
- package/src/utils/createEphemeralContext.ts +5 -4
- package/src/utils/dateVariable.ts +397 -0
- package/src/utils/exceptions.ts +11 -0
- package/src/utils/index.ts +38 -3
- package/src/utils/params-resolvers.ts +23 -9
- package/src/utils/parsePathnameToViewParams.ts +2 -2
- package/src/utils/resolveModuleUrl.ts +91 -0
- package/src/utils/resolveRunJSObjectValues.ts +46 -0
- package/src/utils/runjsModuleLoader.ts +553 -0
- package/src/utils/runjsTemplateCompat.ts +828 -0
- package/src/utils/runjsValue.ts +287 -0
- package/src/utils/safeGlobals.ts +188 -17
- package/src/utils/schema-utils.ts +109 -1
- package/src/views/FlowView.tsx +11 -1
- package/src/views/__tests__/FlowView.usePage.test.tsx +54 -1
- package/src/views/__tests__/runViewBeforeClose.test.ts +30 -0
- package/src/views/__tests__/useDialog.closeDestroy.test.tsx +44 -16
- package/src/views/__tests__/viewEvents.resolveOpenerEngine.test.ts +28 -0
- package/src/views/createViewMeta.ts +22 -75
- package/src/views/index.tsx +1 -2
- package/src/views/runViewBeforeClose.ts +19 -0
- package/src/views/useDialog.tsx +34 -5
- package/src/views/useDrawer.tsx +33 -4
- package/src/views/usePage.tsx +63 -8
- package/src/views/usePopover.tsx +4 -1
- package/src/views/viewEvents.ts +55 -0
|
@@ -13,6 +13,18 @@ import type { MetaTreeNode } from '../../flowContext';
|
|
|
13
13
|
import type { ContextSelectorItem, Converters } from './types';
|
|
14
14
|
import { isVariableExpression } from '../../utils';
|
|
15
15
|
|
|
16
|
+
const getContextSelectorLabelText = (node: ContextSelectorItem) => {
|
|
17
|
+
if (typeof node.label === 'string') {
|
|
18
|
+
return node.label;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (typeof node.meta?.title === 'string') {
|
|
22
|
+
return node.meta.title;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return node.value;
|
|
26
|
+
};
|
|
27
|
+
|
|
16
28
|
export const parseValueToPath = (value: string): string[] | undefined => {
|
|
17
29
|
if (typeof value !== 'string') return undefined;
|
|
18
30
|
|
|
@@ -66,12 +78,7 @@ export const searchInLoadedNodes = (
|
|
|
66
78
|
const nodePath = [...currentPath, node.value];
|
|
67
79
|
|
|
68
80
|
// 计算可搜索的纯文本标签
|
|
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);
|
|
81
|
+
const labelText = getContextSelectorLabelText(node);
|
|
75
82
|
|
|
76
83
|
// 检查节点标签是否匹配搜索文本
|
|
77
84
|
if (labelText.toLowerCase().includes(lowerSearchText)) {
|
|
@@ -89,6 +96,60 @@ export const searchInLoadedNodes = (
|
|
|
89
96
|
return results;
|
|
90
97
|
};
|
|
91
98
|
|
|
99
|
+
/**
|
|
100
|
+
* 仅在“已加载节点”范围内按关键字过滤 options(保留树结构)。
|
|
101
|
+
* - 匹配父节点:保留原节点引用(含原 children),避免不必要的实体重建。
|
|
102
|
+
* - 匹配子节点:返回裁剪后的父节点副本,children 仅包含命中分支。
|
|
103
|
+
* - 未加载 children(即 children 不为数组)不会递归搜索。
|
|
104
|
+
*/
|
|
105
|
+
export const filterLoadedContextSelectorItems = (
|
|
106
|
+
options: ContextSelectorItem[] | undefined,
|
|
107
|
+
keyword: string,
|
|
108
|
+
): ContextSelectorItem[] => {
|
|
109
|
+
if (!Array.isArray(options) || options.length === 0) return [];
|
|
110
|
+
|
|
111
|
+
const normalizedKeyword = keyword.trim().toLowerCase();
|
|
112
|
+
if (!normalizedKeyword) {
|
|
113
|
+
return options;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const filterNode = (node: ContextSelectorItem): ContextSelectorItem | null => {
|
|
117
|
+
const labelText = getContextSelectorLabelText(node).toLowerCase();
|
|
118
|
+
const selfMatched = labelText.includes(normalizedKeyword);
|
|
119
|
+
|
|
120
|
+
if (selfMatched) {
|
|
121
|
+
return node;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!Array.isArray(node.children) || node.children.length === 0) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const filteredChildren = node.children
|
|
129
|
+
.map((child) => filterNode(child))
|
|
130
|
+
.filter((item): item is ContextSelectorItem => item !== null);
|
|
131
|
+
|
|
132
|
+
if (filteredChildren.length === 0) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 所有子节点都保留原引用时,直接复用父节点对象。
|
|
137
|
+
if (
|
|
138
|
+
filteredChildren.length === node.children.length &&
|
|
139
|
+
filteredChildren.every((child, idx) => child === node.children![idx])
|
|
140
|
+
) {
|
|
141
|
+
return node;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
...node,
|
|
146
|
+
children: filteredChildren,
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
return options.map((node) => filterNode(node)).filter((item): item is ContextSelectorItem => item !== null);
|
|
151
|
+
};
|
|
152
|
+
|
|
92
153
|
export const buildContextSelectorItems = (metaTree: MetaTreeNode[]): ContextSelectorItem[] => {
|
|
93
154
|
if (!metaTree || !Array.isArray(metaTree)) {
|
|
94
155
|
console.warn('buildContextSelectorItems received invalid metaTree:', metaTree);
|
package/src/data-source/index.ts
CHANGED
|
@@ -99,7 +99,7 @@ export class DataSource {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
get displayName() {
|
|
102
|
-
return this.
|
|
102
|
+
return this.flowEngine.translate(this.options.displayName, { ns: 'lm-collections' }) || this.key;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
get key() {
|
|
@@ -187,6 +187,9 @@ export interface CollectionOptions {
|
|
|
187
187
|
export class CollectionManager {
|
|
188
188
|
collections: Map<string, Collection>;
|
|
189
189
|
|
|
190
|
+
allCollectionsInheritChain: string[];
|
|
191
|
+
protected childrenCollectionsName: { supportView?: string[]; notSupportView?: string[] } = {};
|
|
192
|
+
|
|
190
193
|
constructor(public dataSource: DataSource) {
|
|
191
194
|
this.collections = observable.shallow<Map<string, Collection>>(new Map());
|
|
192
195
|
}
|
|
@@ -339,117 +342,80 @@ export class CollectionManager {
|
|
|
339
342
|
};
|
|
340
343
|
return getChildrens(name);
|
|
341
344
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
interfaces?: string | string[],
|
|
347
|
-
opts?: {
|
|
348
|
-
dataSource?: string;
|
|
349
|
-
cached?: Record<string, any>;
|
|
350
|
-
collectionNames?: string[];
|
|
351
|
-
/**
|
|
352
|
-
* 为 true 时允许查询所有关联字段
|
|
353
|
-
* 为 Array<string> 时仅允许查询指定的关联字段
|
|
354
|
-
*/
|
|
355
|
-
association?: boolean | string[];
|
|
356
|
-
/**
|
|
357
|
-
* Max depth of recursion
|
|
358
|
-
*/
|
|
359
|
-
maxDepth?: number;
|
|
360
|
-
allowAllTypes?: boolean;
|
|
361
|
-
/**
|
|
362
|
-
* 排除这些接口的字段
|
|
363
|
-
*/
|
|
364
|
-
exceptInterfaces?: string[];
|
|
365
|
-
/**
|
|
366
|
-
* field value 的前缀,用 . 连接,比如 a.b.c
|
|
367
|
-
*/
|
|
368
|
-
prefixFieldValue?: string;
|
|
369
|
-
/**
|
|
370
|
-
* 是否使用 prefixFieldValue 作为 field value
|
|
371
|
-
*/
|
|
372
|
-
usePrefix?: boolean;
|
|
373
|
-
},
|
|
374
|
-
) {
|
|
375
|
-
const {
|
|
376
|
-
association = false,
|
|
377
|
-
cached = {},
|
|
378
|
-
collectionNames = [collectionName],
|
|
379
|
-
maxDepth = 1,
|
|
380
|
-
allowAllTypes = false,
|
|
381
|
-
exceptInterfaces = [],
|
|
382
|
-
prefixFieldValue = '',
|
|
383
|
-
usePrefix = false,
|
|
384
|
-
dataSource: customDataSourceNameValue,
|
|
385
|
-
} = opts || {};
|
|
386
|
-
|
|
387
|
-
if (collectionNames.length - 1 > maxDepth) {
|
|
388
|
-
return;
|
|
345
|
+
getChildrenCollectionsName(name, isSupportView = false) {
|
|
346
|
+
const cacheKey = isSupportView ? 'supportView' : 'notSupportView';
|
|
347
|
+
if (this.childrenCollectionsName[cacheKey]) {
|
|
348
|
+
return this.childrenCollectionsName[cacheKey].slice();
|
|
389
349
|
}
|
|
390
350
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
? association.includes(field.interface)
|
|
415
|
-
: false)),
|
|
416
|
-
)
|
|
417
|
-
?.map((field) => {
|
|
418
|
-
const result: CascaderProps<any>['options'][0] = {
|
|
419
|
-
value: usePrefix && prefixFieldValue ? `${prefixFieldValue}.${field.name}` : field.name,
|
|
420
|
-
label: field?.uiSchema?.title || field.name,
|
|
421
|
-
...field,
|
|
422
|
-
};
|
|
351
|
+
const children: string[] = [];
|
|
352
|
+
const collections = [...this.getCollections()];
|
|
353
|
+
const getChildrenCollectionsInner = (collectionName: string) => {
|
|
354
|
+
const inheritCollections = collections.filter((v: any) => {
|
|
355
|
+
return [...v.inherits]?.includes(collectionName);
|
|
356
|
+
});
|
|
357
|
+
inheritCollections.forEach((v) => {
|
|
358
|
+
const collectionKey = v.name;
|
|
359
|
+
children.push(collectionKey);
|
|
360
|
+
return getChildrenCollectionsInner(collectionKey);
|
|
361
|
+
});
|
|
362
|
+
if (isSupportView) {
|
|
363
|
+
const sourceCollections = collections.filter((v: any) => {
|
|
364
|
+
return [...v.sources]?.length === 1 && v?.sources[0] === collectionName;
|
|
365
|
+
});
|
|
366
|
+
sourceCollections.forEach((v) => {
|
|
367
|
+
const collectionKey = v.name;
|
|
368
|
+
children.push(v.name);
|
|
369
|
+
return getChildrenCollectionsInner(collectionKey);
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
return _.uniq(children);
|
|
373
|
+
};
|
|
423
374
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
375
|
+
this.childrenCollectionsName[cacheKey] = getChildrenCollectionsInner(name);
|
|
376
|
+
return this.childrenCollectionsName[cacheKey];
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
getAllCollectionsInheritChain(name) {
|
|
380
|
+
if (this.allCollectionsInheritChain) {
|
|
381
|
+
return this.allCollectionsInheritChain.slice();
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const collectionsInheritChain = [name];
|
|
385
|
+
const getInheritChain = (name: string) => {
|
|
386
|
+
const collection = this.getCollection(name);
|
|
387
|
+
if (collection) {
|
|
388
|
+
const { inherits } = collection as any;
|
|
389
|
+
const children = this.getChildrenCollectionsName(name);
|
|
390
|
+
// 搜寻祖先表
|
|
391
|
+
if (inherits) {
|
|
392
|
+
for (let index = 0; index < inherits.length; index++) {
|
|
393
|
+
const collectionKey = inherits[index];
|
|
394
|
+
if (collectionsInheritChain.includes(collectionKey)) {
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
collectionsInheritChain.push(collectionKey);
|
|
398
|
+
getInheritChain(collectionKey);
|
|
443
399
|
}
|
|
444
400
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
401
|
+
// 搜寻后代表
|
|
402
|
+
if (children) {
|
|
403
|
+
for (let index = 0; index < children.length; index++) {
|
|
404
|
+
const collection = this.getCollection(children[index]);
|
|
405
|
+
const collectionKey = collection.name;
|
|
406
|
+
if (collectionsInheritChain.includes(collectionKey)) {
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
collectionsInheritChain.push(collectionKey);
|
|
410
|
+
getInheritChain(collectionKey);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return collectionsInheritChain;
|
|
415
|
+
};
|
|
449
416
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
return options;
|
|
417
|
+
this.allCollectionsInheritChain = getInheritChain(name);
|
|
418
|
+
return this.allCollectionsInheritChain || [];
|
|
453
419
|
}
|
|
454
420
|
}
|
|
455
421
|
|
|
@@ -486,6 +452,9 @@ export class Collection {
|
|
|
486
452
|
if (typeof this.filterTargetKey === 'string') {
|
|
487
453
|
return record[this.filterTargetKey];
|
|
488
454
|
}
|
|
455
|
+
if (Array.isArray(this.filterTargetKey) && this.filterTargetKey.length === 1) {
|
|
456
|
+
return record[this.filterTargetKey[0]];
|
|
457
|
+
}
|
|
489
458
|
return _.pick(record, this.filterTargetKey);
|
|
490
459
|
}
|
|
491
460
|
|
|
@@ -527,7 +496,7 @@ export class Collection {
|
|
|
527
496
|
return this.options.storage || 'local';
|
|
528
497
|
}
|
|
529
498
|
get title() {
|
|
530
|
-
return this.
|
|
499
|
+
return this.flowEngine.translate(this.options.title, { ns: 'lm-collections' }) || this.name;
|
|
531
500
|
}
|
|
532
501
|
|
|
533
502
|
get titleCollectionField() {
|
|
@@ -800,8 +769,8 @@ export class CollectionField {
|
|
|
800
769
|
}
|
|
801
770
|
|
|
802
771
|
get title() {
|
|
803
|
-
const titleValue = this.options?.uiSchema?.title || this.options?.title
|
|
804
|
-
return this.flowEngine.translate(titleValue);
|
|
772
|
+
const titleValue = this.options?.uiSchema?.title || this.options?.title;
|
|
773
|
+
return this.flowEngine.translate(titleValue, { ns: 'lm-collections' }) || this.options.name;
|
|
805
774
|
}
|
|
806
775
|
|
|
807
776
|
set title(value: string) {
|
|
@@ -815,13 +784,22 @@ export class CollectionField {
|
|
|
815
784
|
if (typeof v !== 'object') {
|
|
816
785
|
return v;
|
|
817
786
|
}
|
|
787
|
+
if (v.value === null || v.value === undefined) {
|
|
788
|
+
return v;
|
|
789
|
+
}
|
|
818
790
|
return {
|
|
819
791
|
...v,
|
|
792
|
+
label: v.label ? this.flowEngine.translate(v.label, { ns: 'lm-collections' }) : v.label,
|
|
820
793
|
value: Number(v.value),
|
|
821
794
|
};
|
|
822
795
|
});
|
|
823
796
|
}
|
|
824
|
-
return options
|
|
797
|
+
return options.map((v) => {
|
|
798
|
+
return {
|
|
799
|
+
...v,
|
|
800
|
+
label: this.flowEngine.translate(v.label, { ns: 'lm-collections' }),
|
|
801
|
+
};
|
|
802
|
+
});
|
|
825
803
|
}
|
|
826
804
|
|
|
827
805
|
get defaultValue() {
|