@nocobase/flow-engine 2.0.0-alpha.9 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/BlockScopedFlowEngine.d.ts +23 -0
- package/lib/BlockScopedFlowEngine.js +92 -0
- package/lib/FlowDefinition.d.ts +6 -4
- package/lib/JSRunner.js +3 -0
- package/lib/ViewScopedFlowEngine.js +15 -1
- package/lib/acl/Acl.d.ts +12 -12
- package/lib/acl/Acl.js +78 -30
- package/lib/components/DynamicFlowsEditor.js +2 -4
- package/lib/components/FieldModelRenderer.js +10 -8
- package/lib/components/FieldSkeleton.d.ts +10 -0
- package/lib/components/FieldSkeleton.js +64 -0
- package/lib/components/FlowContextSelector.js +19 -3
- package/lib/components/FlowModelRenderer.d.ts +2 -1
- package/lib/components/FlowModelRenderer.js +34 -12
- package/lib/components/FormItem.js +5 -1
- package/lib/components/MobilePopup.d.ts +20 -0
- package/lib/components/MobilePopup.js +102 -0
- package/lib/components/MobilePopup.style.d.ts +17 -0
- package/lib/components/MobilePopup.style.js +186 -0
- package/lib/components/common/withFlowDesignMode.d.ts +1 -1
- package/lib/components/common/withFlowDesignMode.js +5 -5
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +3 -1
- package/lib/components/settings/independents/dropdown/FlowsDropdownButton.js +71 -53
- package/lib/components/settings/wrappers/component/SelectWithTitle.d.ts +19 -0
- package/lib/components/settings/wrappers/component/SelectWithTitle.js +136 -0
- package/lib/components/settings/wrappers/component/SwitchWithTitle.d.ts +10 -0
- package/lib/components/settings/wrappers/component/SwitchWithTitle.js +110 -0
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +221 -93
- package/lib/components/settings/wrappers/contextual/FlowsContextMenu.js +71 -54
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +2 -2
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +63 -23
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +11 -6
- package/lib/components/settings/wrappers/embedded/FlowSettings.js +42 -28
- package/lib/components/settings/wrappers/embedded/FlowsSettings.js +3 -3
- package/lib/components/settings/wrappers/embedded/FlowsSettingsContent.js +52 -32
- package/lib/components/subModel/AddSubModelButton.d.ts +7 -0
- package/lib/components/subModel/AddSubModelButton.js +78 -8
- package/lib/components/subModel/LazyDropdown.js +14 -15
- package/lib/components/subModel/utils.d.ts +1 -1
- package/lib/components/subModel/utils.js +21 -11
- package/lib/components/variables/VariableInput.js +5 -3
- package/lib/components/variables/types.d.ts +2 -0
- package/lib/components/variables/utils.js +4 -2
- package/lib/data-source/index.d.ts +43 -4
- package/lib/data-source/index.js +104 -11
- package/lib/data-source/jioToJoiSchema.js +1 -0
- package/lib/emitter.d.ts +6 -0
- package/lib/emitter.js +12 -0
- package/lib/executor/FlowExecutor.js +48 -7
- package/lib/flow-registry/GlobalFlowRegistry.d.ts +1 -0
- package/lib/flow-registry/GlobalFlowRegistry.js +3 -0
- package/lib/flow-registry/InstanceFlowRegistry.d.ts +1 -0
- package/lib/flow-registry/InstanceFlowRegistry.js +3 -0
- package/lib/flowContext.d.ts +6 -0
- package/lib/flowContext.js +111 -30
- package/lib/flowEngine.d.ts +49 -0
- package/lib/flowEngine.js +265 -10
- package/lib/flowSettings.d.ts +4 -3
- package/lib/flowSettings.js +33 -11
- package/lib/hooks/useApplyAutoFlows.d.ts +1 -0
- package/lib/hooks/useApplyAutoFlows.js +2 -2
- package/lib/index.d.ts +4 -2
- package/lib/index.js +11 -5
- package/lib/locale/de-DE.json +62 -0
- package/lib/locale/en-US.json +57 -45
- package/lib/locale/es-ES.json +62 -0
- package/lib/locale/fr-FR.json +62 -0
- package/lib/locale/hu-HU.json +62 -0
- package/lib/locale/id-ID.json +62 -0
- package/lib/locale/index.d.ts +114 -90
- package/lib/locale/it-IT.json +62 -0
- package/lib/locale/ja-JP.json +62 -0
- package/lib/locale/ko-KR.json +62 -0
- package/lib/locale/nl-NL.json +62 -0
- package/lib/locale/pt-BR.json +62 -0
- package/lib/locale/ru-RU.json +62 -0
- package/lib/locale/tr-TR.json +62 -0
- package/lib/locale/uk-UA.json +62 -0
- package/lib/locale/vi-VN.json +62 -0
- package/lib/locale/zh-CN.json +58 -46
- package/lib/locale/zh-TW.json +62 -0
- package/lib/models/CollectionFieldModel.d.ts +6 -2
- package/lib/models/CollectionFieldModel.js +60 -14
- package/lib/models/flowModel.d.ts +43 -4
- package/lib/models/flowModel.js +128 -26
- package/lib/models/forkFlowModel.d.ts +6 -2
- package/lib/models/forkFlowModel.js +9 -2
- package/lib/provider.d.ts +3 -1
- package/lib/provider.js +4 -3
- package/lib/reactive/index.d.ts +10 -0
- package/lib/reactive/index.js +41 -0
- package/lib/reactive/observer.d.ts +19 -0
- package/lib/reactive/observer.js +109 -0
- package/lib/resources/baseRecordResource.d.ts +1 -0
- package/lib/resources/baseRecordResource.js +14 -3
- package/lib/resources/multiRecordResource.d.ts +4 -2
- package/lib/resources/multiRecordResource.js +15 -6
- package/lib/resources/singleRecordResource.js +6 -3
- package/lib/resources/sqlResource.d.ts +1 -0
- package/lib/resources/sqlResource.js +22 -25
- package/lib/runjs-context/contexts/base.js +42 -6
- package/lib/runjs-context/snippets/global/clipboard-copy-text.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/clipboard-copy-text.snippet.js +61 -0
- package/lib/runjs-context/snippets/index.js +3 -0
- package/lib/runjs-context/snippets/scene/block/render-antd-icons.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-antd-icons.snippet.js +65 -0
- package/lib/runjs-context/snippets/scene/block/render-button-handler.snippet.js +6 -4
- package/lib/runjs-context/snippets/scene/block/render-info-card.snippet.js +15 -16
- package/lib/runjs-context/snippets/scene/block/render-react-jsx.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-react-jsx.snippet.js +58 -0
- package/lib/runjs-context/snippets/scene/block/render-react.snippet.js +7 -7
- package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.js +24 -29
- package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.js +20 -21
- package/lib/scheduler/ModelOperationScheduler.d.ts +51 -0
- package/lib/scheduler/ModelOperationScheduler.js +262 -0
- package/lib/types.d.ts +42 -7
- package/lib/types.js +4 -3
- package/lib/utils/associationObjectVariable.d.ts +32 -0
- package/lib/utils/associationObjectVariable.js +157 -0
- package/lib/utils/createCollectionContextMeta.d.ts +1 -1
- package/lib/utils/createCollectionContextMeta.js +8 -4
- package/lib/utils/createEphemeralContext.d.ts +13 -0
- package/lib/utils/createEphemeralContext.js +140 -0
- package/lib/utils/flows.d.ts +10 -0
- package/lib/utils/flows.js +48 -0
- package/lib/utils/index.d.ts +7 -3
- package/lib/utils/index.js +20 -0
- package/lib/utils/jsxTransform.d.ts +15 -0
- package/lib/utils/jsxTransform.js +68 -0
- package/lib/utils/params-resolvers.js +3 -3
- package/lib/utils/parsePathnameToViewParams.d.ts +1 -1
- package/lib/utils/parsePathnameToViewParams.js +41 -5
- package/lib/utils/pruneFilter.d.ts +21 -0
- package/lib/utils/pruneFilter.js +52 -0
- package/lib/utils/safeGlobals.d.ts +5 -3
- package/lib/utils/safeGlobals.js +42 -1
- package/lib/utils/schema-utils.d.ts +6 -0
- package/lib/utils/schema-utils.js +71 -6
- package/lib/utils/serverContextParams.d.ts +3 -0
- package/lib/utils/serverContextParams.js +2 -0
- package/lib/utils/translation.d.ts +4 -1
- package/lib/utils/translation.js +6 -2
- package/lib/utils/variablesParams.d.ts +21 -5
- package/lib/utils/variablesParams.js +103 -34
- package/lib/views/DialogComponent.js +1 -5
- package/lib/views/DrawerComponent.js +18 -9
- package/lib/views/PageComponent.js +3 -4
- package/lib/views/ViewNavigation.d.ts +11 -15
- package/lib/views/ViewNavigation.js +37 -19
- package/lib/views/createViewMeta.d.ts +3 -2
- package/lib/views/createViewMeta.js +164 -53
- package/lib/views/useDialog.d.ts +2 -1
- package/lib/views/useDialog.js +36 -30
- package/lib/views/useDrawer.d.ts +2 -1
- package/lib/views/useDrawer.js +33 -26
- package/lib/views/usePage.d.ts +2 -1
- package/lib/views/usePage.js +40 -29
- package/package.json +6 -3
- package/src/BlockScopedFlowEngine.ts +88 -0
- package/src/JSRunner.ts +3 -0
- package/src/ViewScopedFlowEngine.ts +16 -0
- package/src/__tests__/JSRunner.test.ts +62 -53
- package/src/__tests__/blockScopedFlowEngine.test.ts +154 -0
- package/src/__tests__/createViewMeta.popup.test.ts +142 -0
- package/src/__tests__/flow-engine.test.ts +3 -0
- package/src/__tests__/flowContext.test.ts +70 -0
- package/src/__tests__/flowEngine.destroyModel.test.ts +74 -0
- package/src/__tests__/flowEngine.moveModel.test.ts +43 -0
- package/src/__tests__/flowEngine.removeModel.test.ts +72 -0
- package/src/__tests__/flowEngine.saveModel.test.ts +4 -0
- package/src/__tests__/flowModel.openView.navigation.test.ts +3 -2
- package/src/__tests__/flowSettings.open.test.tsx +2 -0
- package/src/__tests__/flowSettings.test.ts +2 -0
- package/src/__tests__/globalFlowRegistry.test.ts +1 -1
- package/src/__tests__/modelOperationScheduler.test.ts +346 -0
- package/src/__tests__/objectVariable.test.ts +464 -0
- package/src/__tests__/runjsRuntimeFeatures.test.ts +12 -0
- package/src/__tests__/viewScopedFlowEngine.test.ts +98 -0
- package/src/acl/Acl.tsx +85 -31
- package/src/acl/__tests__/Acl.test.tsx +43 -1
- package/src/components/DynamicFlowsEditor.tsx +0 -10
- package/src/components/FieldModelRenderer.tsx +15 -8
- package/src/components/FieldSkeleton.tsx +27 -0
- package/src/components/FlowContextSelector.tsx +20 -2
- package/src/components/FlowModelRenderer.tsx +46 -12
- package/src/components/FormItem.tsx +8 -1
- package/src/components/MobilePopup.style.ts +220 -0
- package/src/components/MobilePopup.tsx +86 -0
- package/src/components/__tests__/FlowModelRenderer.test.tsx +89 -0
- package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +1 -1
- package/src/components/common/withFlowDesignMode.tsx +5 -5
- package/src/components/index.ts +1 -0
- package/src/components/settings/independents/dropdown/FlowsDropdownButton.tsx +34 -17
- package/src/components/settings/wrappers/component/SelectWithTitle.tsx +110 -0
- package/src/components/settings/wrappers/component/SwitchWithTitle.tsx +82 -0
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +260 -121
- package/src/components/settings/wrappers/contextual/FlowsContextMenu.tsx +34 -18
- package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +56 -18
- package/src/components/settings/wrappers/contextual/StepSettings.tsx +1 -2
- package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +12 -6
- package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +565 -0
- package/src/components/settings/wrappers/embedded/FlowSettings.tsx +47 -35
- package/src/components/settings/wrappers/embedded/FlowsSettings.tsx +1 -1
- package/src/components/settings/wrappers/embedded/FlowsSettingsContent.tsx +64 -42
- package/src/components/subModel/AddSubModelButton.tsx +104 -9
- package/src/components/subModel/LazyDropdown.tsx +14 -14
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +168 -7
- package/src/components/subModel/__tests__/utils.test.ts +12 -12
- package/src/components/subModel/utils.ts +25 -6
- package/src/components/variables/VariableInput.tsx +5 -3
- package/src/components/variables/types.ts +2 -0
- package/src/components/variables/utils.ts +7 -3
- package/src/data-source/index.ts +169 -11
- package/src/data-source/jioToJoiSchema.ts +1 -0
- package/src/emitter.ts +14 -0
- package/src/executor/FlowExecutor.ts +56 -8
- package/src/executor/__tests__/ctx-defs-injection.test.ts +197 -0
- package/src/flow-registry/GlobalFlowRegistry.ts +1 -0
- package/src/flow-registry/InstanceFlowRegistry.ts +1 -0
- package/src/flow-registry/__tests__/globalFlowRegistry.test.ts +54 -0
- package/src/flowContext.ts +144 -29
- package/src/flowEngine.ts +328 -8
- package/src/flowSettings.ts +47 -19
- package/src/hooks/useApplyAutoFlows.ts +3 -3
- package/src/index.ts +4 -2
- package/src/locale/de-DE.json +62 -0
- package/src/locale/en-US.json +57 -45
- package/src/locale/es-ES.json +62 -0
- package/src/locale/fr-FR.json +62 -0
- package/src/locale/hu-HU.json +62 -0
- package/src/locale/id-ID.json +62 -0
- package/src/locale/it-IT.json +62 -0
- package/src/locale/ja-JP.json +62 -0
- package/src/locale/ko-KR.json +62 -0
- package/src/locale/nl-NL.json +62 -0
- package/src/locale/pt-BR.json +62 -0
- package/src/locale/ru-RU.json +62 -0
- package/src/locale/tr-TR.json +62 -0
- package/src/locale/uk-UA.json +62 -0
- package/src/locale/vi-VN.json +62 -0
- package/src/locale/zh-CN.json +58 -46
- package/src/locale/zh-TW.json +62 -0
- package/src/models/CollectionFieldModel.tsx +79 -17
- package/src/models/__tests__/dispatchEvent.behavior.test.ts +169 -0
- package/src/models/__tests__/flowEngine.resolveUse.test.ts +170 -0
- package/src/models/__tests__/flowModel.getFlows.sort.test.ts +29 -5
- package/src/models/__tests__/flowModel.scheduleModelOperation.test.tsx +129 -0
- package/src/models/__tests__/flowModel.test.ts +65 -27
- package/src/models/__tests__/forkFlowModel.test.ts +40 -7
- package/src/models/flowModel.tsx +192 -30
- package/src/models/forkFlowModel.ts +11 -3
- package/src/provider.tsx +5 -5
- package/src/reactive/__tests__/observer.test.tsx +211 -0
- package/src/reactive/index.ts +11 -0
- package/src/reactive/observer.tsx +101 -0
- package/src/resources/baseRecordResource.ts +15 -3
- package/src/resources/multiRecordResource.ts +17 -8
- package/src/resources/singleRecordResource.ts +6 -3
- package/src/resources/sqlResource.ts +22 -26
- package/src/runjs-context/contexts/base.ts +47 -6
- package/src/runjs-context/snippets/global/clipboard-copy-text.snippet.ts +42 -0
- package/src/runjs-context/snippets/index.ts +3 -0
- package/src/runjs-context/snippets/scene/block/render-antd-icons.snippet.ts +46 -0
- package/src/runjs-context/snippets/scene/block/render-button-handler.snippet.ts +6 -4
- package/src/runjs-context/snippets/scene/block/render-info-card.snippet.ts +15 -16
- package/src/runjs-context/snippets/scene/block/render-react-jsx.snippet.ts +39 -0
- package/src/runjs-context/snippets/scene/block/render-react.snippet.ts +7 -7
- package/src/runjs-context/snippets/scene/block/render-statistics.snippet.ts +24 -29
- package/src/runjs-context/snippets/scene/block/render-timeline.snippet.ts +20 -21
- package/src/scheduler/ModelOperationScheduler.ts +304 -0
- package/src/types.ts +50 -4
- package/src/utils/__tests__/createCollectionContextMeta.test.ts +51 -0
- package/src/utils/__tests__/flows.test.ts +65 -0
- package/src/utils/__tests__/jsxTransform.test.ts +38 -0
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +25 -0
- package/src/utils/__tests__/pruneFilter.test.ts +38 -0
- package/src/utils/__tests__/safeGlobals.test.ts +23 -1
- package/src/utils/__tests__/utils.test.ts +114 -15
- package/src/utils/__tests__/variablesParams.test.ts +120 -0
- package/src/utils/associationObjectVariable.ts +180 -0
- package/src/utils/createCollectionContextMeta.ts +8 -3
- package/src/utils/createEphemeralContext.ts +142 -0
- package/src/utils/flows.ts +23 -0
- package/src/utils/index.ts +11 -2
- package/src/utils/jsxTransform.ts +39 -0
- package/src/utils/params-resolvers.ts +2 -2
- package/src/utils/parsePathnameToViewParams.ts +50 -6
- package/src/utils/pruneFilter.ts +41 -0
- package/src/utils/safeGlobals.ts +51 -4
- package/src/utils/schema-utils.ts +81 -3
- package/src/utils/serverContextParams.ts +5 -0
- package/src/utils/translation.ts +7 -2
- package/src/utils/variablesParams.ts +125 -42
- package/src/views/DialogComponent.tsx +1 -4
- package/src/views/DrawerComponent.tsx +19 -7
- package/src/views/PageComponent.tsx +2 -4
- package/src/views/ViewNavigation.ts +49 -43
- package/src/views/__tests__/FlowView.usePage.test.tsx +133 -0
- package/src/views/__tests__/ViewNavigation.test.ts +54 -34
- package/src/views/__tests__/useDialog.closeDestroy.test.tsx +132 -0
- package/src/views/createViewMeta.ts +179 -42
- package/src/views/useDialog.tsx +36 -24
- package/src/views/useDrawer.tsx +37 -24
- package/src/views/usePage.tsx +46 -27
|
@@ -342,20 +342,18 @@ const LazyDropdown = /* @__PURE__ */ __name(({ menu, ...props }) => {
|
|
|
342
342
|
}
|
|
343
343
|
setRootItems(resolvedItems);
|
|
344
344
|
}, "loadRootItems");
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
}
|
|
348
|
-
}, [menuVisible, stateVersion, menuItems]);
|
|
345
|
+
loadRootItems();
|
|
346
|
+
}, [stateVersion, menuItems]);
|
|
349
347
|
function buildSearchChildren(children, item, keyPath, path, menuVisible2, resolve) {
|
|
350
348
|
const searchKey = keyPath;
|
|
351
349
|
const currentSearchValue = searchValues[searchKey] || "";
|
|
352
|
-
const filteredChildren = currentSearchValue ? (/* @__PURE__ */ __name(function deepFilter(
|
|
350
|
+
const filteredChildren = currentSearchValue ? (/* @__PURE__ */ __name(function deepFilter(items2) {
|
|
353
351
|
const searchText = currentSearchValue.toLowerCase();
|
|
354
352
|
const tryString = /* @__PURE__ */ __name((v) => {
|
|
355
353
|
if (!v) return "";
|
|
356
354
|
return typeof v === "string" ? v : String(v);
|
|
357
355
|
}, "tryString");
|
|
358
|
-
return
|
|
356
|
+
return items2.map((child) => {
|
|
359
357
|
const labelStr = tryString(child.label).toLowerCase();
|
|
360
358
|
const selfMatch = labelStr.includes(searchText) || child.key && String(child.key).toLowerCase().includes(searchText);
|
|
361
359
|
if (child.type === "group" && Array.isArray(child.children)) {
|
|
@@ -377,8 +375,8 @@ const LazyDropdown = /* @__PURE__ */ __name(({ menu, ...props }) => {
|
|
|
377
375
|
return [searchItem, dividerItem, ...resolvedFiltered];
|
|
378
376
|
}
|
|
379
377
|
__name(buildSearchChildren, "buildSearchChildren");
|
|
380
|
-
const resolveItems = /* @__PURE__ */ __name((
|
|
381
|
-
return
|
|
378
|
+
const resolveItems = /* @__PURE__ */ __name((items2, path = []) => {
|
|
379
|
+
return items2.map((item) => {
|
|
382
380
|
const keyPath = getKeyPath(path, item.key);
|
|
383
381
|
const isGroup = item.type === "group";
|
|
384
382
|
const hasAsyncChildren = typeof item.children === "function";
|
|
@@ -483,6 +481,13 @@ const LazyDropdown = /* @__PURE__ */ __name(({ menu, ...props }) => {
|
|
|
483
481
|
}
|
|
484
482
|
`;
|
|
485
483
|
}, [dropdownMaxHeight]);
|
|
484
|
+
const items = rootLoading && rootItems.length === 0 ? [
|
|
485
|
+
{
|
|
486
|
+
key: "root-loading",
|
|
487
|
+
label: /* @__PURE__ */ import_react.default.createElement(import_antd.Spin, { size: "small" }),
|
|
488
|
+
disabled: true
|
|
489
|
+
}
|
|
490
|
+
] : resolveItems(rootItems);
|
|
486
491
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
487
492
|
import_antd.Dropdown,
|
|
488
493
|
{
|
|
@@ -493,13 +498,7 @@ const LazyDropdown = /* @__PURE__ */ __name(({ menu, ...props }) => {
|
|
|
493
498
|
placement: "bottomLeft",
|
|
494
499
|
menu: {
|
|
495
500
|
...dropdownMenuProps,
|
|
496
|
-
items
|
|
497
|
-
{
|
|
498
|
-
key: "root-loading",
|
|
499
|
-
label: /* @__PURE__ */ import_react.default.createElement(import_antd.Spin, { size: "small" }),
|
|
500
|
-
disabled: true
|
|
501
|
-
}
|
|
502
|
-
] : resolveItems(rootItems),
|
|
501
|
+
items,
|
|
503
502
|
onClick: /* @__PURE__ */ __name(() => {
|
|
504
503
|
}, "onClick"),
|
|
505
504
|
style: {
|
|
@@ -10,7 +10,7 @@ import type { Collection } from '../../data-source';
|
|
|
10
10
|
import { FlowModelContext } from '../../flowContext';
|
|
11
11
|
import { ModelConstructor } from '../../types';
|
|
12
12
|
import { SubModelItem } from './AddSubModelButton';
|
|
13
|
-
export declare function buildSubModelItem(M: ModelConstructor, ctx: FlowModelContext, skipHide?: boolean): SubModelItem
|
|
13
|
+
export declare function buildSubModelItem(M: ModelConstructor, ctx: FlowModelContext, skipHide?: boolean): Promise<SubModelItem | undefined>;
|
|
14
14
|
export declare function buildItems(subModelBaseClass: string | ModelConstructor): (ctx: FlowModelContext) => Promise<any>;
|
|
15
15
|
export declare function buildSubModelItems(subModelBaseClass: string | ModelConstructor, exclude?: any[]): (ctx: FlowModelContext) => Promise<SubModelItem[]>;
|
|
16
16
|
export declare function buildSubModelGroups(subModelBaseClasses?: (string | ModelConstructor)[]): (ctx: FlowModelContext) => Promise<SubModelItem[]>;
|
|
@@ -46,9 +46,16 @@ __export(utils_exports, {
|
|
|
46
46
|
module.exports = __toCommonJS(utils_exports);
|
|
47
47
|
var _ = __toESM(require("lodash"));
|
|
48
48
|
var import_utils = require("../../utils");
|
|
49
|
-
function
|
|
49
|
+
async function callHideFunction(hide, ctx) {
|
|
50
|
+
if (typeof hide === "function") {
|
|
51
|
+
return await hide(ctx);
|
|
52
|
+
}
|
|
53
|
+
return hide;
|
|
54
|
+
}
|
|
55
|
+
__name(callHideFunction, "callHideFunction");
|
|
56
|
+
async function buildSubModelItem(M, ctx, skipHide = false) {
|
|
50
57
|
const meta = M.meta ?? {};
|
|
51
|
-
if (meta.hide && !skipHide) {
|
|
58
|
+
if (await callHideFunction(meta.hide, ctx) && !skipHide) {
|
|
52
59
|
return;
|
|
53
60
|
}
|
|
54
61
|
const item = {
|
|
@@ -127,12 +134,15 @@ function buildItems(subModelBaseClass) {
|
|
|
127
134
|
__name(buildItems, "buildItems");
|
|
128
135
|
function buildSubModelItems(subModelBaseClass, exclude = []) {
|
|
129
136
|
return async (ctx) => {
|
|
130
|
-
var _a;
|
|
137
|
+
var _a, _b;
|
|
131
138
|
const SubModelClasses = ctx.engine.getSubclassesOf(subModelBaseClass);
|
|
132
|
-
let candidates =
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
let candidates = [];
|
|
140
|
+
for (const C of Array.from(SubModelClasses.values())) {
|
|
141
|
+
if (!await callHideFunction((_a = C.meta) == null ? void 0 : _a.hide, ctx)) {
|
|
142
|
+
candidates.push(C);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
candidates = candidates.filter((C) => {
|
|
136
146
|
for (const P of exclude) {
|
|
137
147
|
if (typeof P === "string") {
|
|
138
148
|
if (C.name === P) return false;
|
|
@@ -142,18 +152,18 @@ function buildSubModelItems(subModelBaseClass, exclude = []) {
|
|
|
142
152
|
}
|
|
143
153
|
return true;
|
|
144
154
|
}).sort((A, B) => {
|
|
145
|
-
var _a2,
|
|
146
|
-
return (((_a2 = A.meta) == null ? void 0 : _a2.sort) ?? 1e3) - (((
|
|
155
|
+
var _a2, _b2;
|
|
156
|
+
return (((_a2 = A.meta) == null ? void 0 : _a2.sort) ?? 1e3) - (((_b2 = B.meta) == null ? void 0 : _b2.sort) ?? 1e3);
|
|
147
157
|
});
|
|
148
158
|
if (candidates.length === 0) {
|
|
149
159
|
const BaseClass = typeof subModelBaseClass === "string" ? ctx.engine.getModelClass(subModelBaseClass) : subModelBaseClass;
|
|
150
|
-
if (BaseClass && !((
|
|
160
|
+
if (BaseClass && !await callHideFunction((_b = BaseClass.meta) == null ? void 0 : _b.hide, ctx)) {
|
|
151
161
|
candidates = [BaseClass];
|
|
152
162
|
}
|
|
153
163
|
}
|
|
154
164
|
const items = [];
|
|
155
165
|
for (const M of candidates) {
|
|
156
|
-
const item = buildSubModelItem(M, ctx);
|
|
166
|
+
const item = await buildSubModelItem(M, ctx);
|
|
157
167
|
if (item) items.push(item);
|
|
158
168
|
}
|
|
159
169
|
return items;
|
|
@@ -94,6 +94,7 @@ const VariableInputComponent = /* @__PURE__ */ __name(({
|
|
|
94
94
|
showValueComponent = true,
|
|
95
95
|
onlyLeafSelectable = false,
|
|
96
96
|
clearValue,
|
|
97
|
+
ignoreFieldNames,
|
|
97
98
|
...restProps
|
|
98
99
|
}) => {
|
|
99
100
|
const [currentMetaTreeNode, setCurrentMetaTreeNode] = (0, import_react.useState)(null);
|
|
@@ -143,7 +144,7 @@ const VariableInputComponent = /* @__PURE__ */ __name(({
|
|
|
143
144
|
}, [currentMetaTreeNode, innerValue, resolvedMetaTree, resolvePathFromValue]);
|
|
144
145
|
(0, import_react.useEffect)(() => {
|
|
145
146
|
const restoreFromValue = /* @__PURE__ */ __name(async () => {
|
|
146
|
-
if (!Array.isArray(resolvedMetaTree) ||
|
|
147
|
+
if (!Array.isArray(resolvedMetaTree) || value == null) return;
|
|
147
148
|
if (currentMetaTreeNode) {
|
|
148
149
|
return;
|
|
149
150
|
}
|
|
@@ -196,7 +197,7 @@ const VariableInputComponent = /* @__PURE__ */ __name(({
|
|
|
196
197
|
}, [renderInputComponent, resolvedMetaTreeNode, innerValue]);
|
|
197
198
|
(0, import_react.useEffect)(() => {
|
|
198
199
|
if (!resolvedMetaTreeNode) return;
|
|
199
|
-
if (!Array.isArray(resolvedMetaTree) ||
|
|
200
|
+
if (!Array.isArray(resolvedMetaTree) || innerValue == null) return;
|
|
200
201
|
const finalValue = (resolveValueFromPath == null ? void 0 : resolveValueFromPath(resolvedMetaTreeNode)) || innerValue;
|
|
201
202
|
emitChange(finalValue, resolvedMetaTreeNode);
|
|
202
203
|
setCurrentMetaTreeNode(resolvedMetaTreeNode);
|
|
@@ -264,7 +265,7 @@ const VariableInputComponent = /* @__PURE__ */ __name(({
|
|
|
264
265
|
}, [restProps]);
|
|
265
266
|
const inputProps = (0, import_react.useMemo)(() => {
|
|
266
267
|
const baseProps = {
|
|
267
|
-
value: innerValue
|
|
268
|
+
value: innerValue ?? "",
|
|
268
269
|
onChange: handleInputChange,
|
|
269
270
|
disabled
|
|
270
271
|
};
|
|
@@ -323,6 +324,7 @@ const VariableInputComponent = /* @__PURE__ */ __name(({
|
|
|
323
324
|
parseValueToPath: resolvePathFromValue,
|
|
324
325
|
formatPathToValue: resolveValueFromPath,
|
|
325
326
|
onlyLeafSelectable,
|
|
327
|
+
ignoreFieldNames,
|
|
326
328
|
...!showValueComponent && { children: null, placeholder: restProps == null ? void 0 : restProps.placeholder }
|
|
327
329
|
}
|
|
328
330
|
));
|
|
@@ -18,6 +18,7 @@ export interface FlowContextSelectorProps extends Omit<CascaderProps<ContextSele
|
|
|
18
18
|
formatPathToValue?: (item: MetaTreeNode) => string;
|
|
19
19
|
open?: boolean;
|
|
20
20
|
onlyLeafSelectable?: boolean;
|
|
21
|
+
ignoreFieldNames?: string[];
|
|
21
22
|
}
|
|
22
23
|
export interface ContextSelectorItem {
|
|
23
24
|
label: React.ReactNode;
|
|
@@ -62,6 +63,7 @@ export interface VariableInputProps {
|
|
|
62
63
|
* 默认行为为 null;可设置为 '' 等,以便清空后默认切换为“常量-空字符串”。
|
|
63
64
|
*/
|
|
64
65
|
clearValue?: any;
|
|
66
|
+
ignoreFieldNames?: string[];
|
|
65
67
|
[key: string]: any;
|
|
66
68
|
}
|
|
67
69
|
export interface VariableTagProps {
|
|
@@ -92,6 +92,8 @@ const buildContextSelectorItems = /* @__PURE__ */ __name((metaTree) => {
|
|
|
92
92
|
return [];
|
|
93
93
|
}
|
|
94
94
|
const convertNode = /* @__PURE__ */ __name((node) => {
|
|
95
|
+
const hidden = !!(typeof node.hidden === "function" ? node.hidden() : node.hidden);
|
|
96
|
+
if (hidden) return null;
|
|
95
97
|
const hasChildren = !!(node.children && (typeof node.children === "function" || Array.isArray(node.children) && node.children.length > 0));
|
|
96
98
|
const disabled = !!(typeof node.disabled === "function" ? node.disabled() : node.disabled);
|
|
97
99
|
const option = {
|
|
@@ -103,11 +105,11 @@ const buildContextSelectorItems = /* @__PURE__ */ __name((metaTree) => {
|
|
|
103
105
|
disabled
|
|
104
106
|
};
|
|
105
107
|
if (Array.isArray(node.children) && node.children.length > 0) {
|
|
106
|
-
option.children = node.children.map((child) => convertNode(child));
|
|
108
|
+
option.children = node.children.map((child) => convertNode(child)).filter((item) => item !== null);
|
|
107
109
|
}
|
|
108
110
|
return option;
|
|
109
111
|
}, "convertNode");
|
|
110
|
-
return metaTree.map((node) => convertNode(node));
|
|
112
|
+
return metaTree.map((node) => convertNode(node)).filter((item) => item !== null);
|
|
111
113
|
}, "buildContextSelectorItems");
|
|
112
114
|
const preloadContextSelectorPath = /* @__PURE__ */ __name(async (options, pathSegments, triggerUpdate) => {
|
|
113
115
|
if (!options || !Array.isArray(options) || !pathSegments || pathSegments.length === 0) return;
|
|
@@ -49,7 +49,9 @@ export declare class DataSource {
|
|
|
49
49
|
addCollection(collection: Collection | CollectionOptions): void;
|
|
50
50
|
updateCollection(newOptions: CollectionOptions): void;
|
|
51
51
|
upsertCollection(options: CollectionOptions): Collection;
|
|
52
|
-
upsertCollections(collections: CollectionOptions[]
|
|
52
|
+
upsertCollections(collections: CollectionOptions[], options?: {
|
|
53
|
+
clearFields?: boolean;
|
|
54
|
+
}): void;
|
|
53
55
|
removeCollection(name: string): void;
|
|
54
56
|
clearCollections(): void;
|
|
55
57
|
setOptions(newOptions?: any): void;
|
|
@@ -68,14 +70,46 @@ export declare class CollectionManager {
|
|
|
68
70
|
get flowEngine(): FlowEngine;
|
|
69
71
|
addCollection(collection: Collection | CollectionOptions): void;
|
|
70
72
|
removeCollection(name: string): void;
|
|
71
|
-
updateCollection(newOptions: CollectionOptions
|
|
73
|
+
updateCollection(newOptions: CollectionOptions, options?: {
|
|
74
|
+
clearFields?: boolean;
|
|
75
|
+
}): void;
|
|
72
76
|
upsertCollection(options: CollectionOptions): Collection;
|
|
73
|
-
upsertCollections(collections: CollectionOptions[]
|
|
77
|
+
upsertCollections(collections: CollectionOptions[], options?: {
|
|
78
|
+
clearFields?: boolean;
|
|
79
|
+
}): void;
|
|
74
80
|
sortCollectionsByInherits(collections: CollectionOptions[]): CollectionOptions[];
|
|
75
81
|
getCollection(name: string): Collection | undefined;
|
|
76
82
|
getCollections(): Collection[];
|
|
77
83
|
clearCollections(): void;
|
|
78
84
|
getAssociation(associationName: string): CollectionField | undefined;
|
|
85
|
+
getChildrenCollections(name: any): any[];
|
|
86
|
+
getCollectionFieldsOptions(collectionName: string, type?: string | string[], interfaces?: string | string[], opts?: {
|
|
87
|
+
dataSource?: string;
|
|
88
|
+
cached?: Record<string, any>;
|
|
89
|
+
collectionNames?: string[];
|
|
90
|
+
/**
|
|
91
|
+
* 为 true 时允许查询所有关联字段
|
|
92
|
+
* 为 Array<string> 时仅允许查询指定的关联字段
|
|
93
|
+
*/
|
|
94
|
+
association?: boolean | string[];
|
|
95
|
+
/**
|
|
96
|
+
* Max depth of recursion
|
|
97
|
+
*/
|
|
98
|
+
maxDepth?: number;
|
|
99
|
+
allowAllTypes?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* 排除这些接口的字段
|
|
102
|
+
*/
|
|
103
|
+
exceptInterfaces?: string[];
|
|
104
|
+
/**
|
|
105
|
+
* field value 的前缀,用 . 连接,比如 a.b.c
|
|
106
|
+
*/
|
|
107
|
+
prefixFieldValue?: string;
|
|
108
|
+
/**
|
|
109
|
+
* 是否使用 prefixFieldValue 作为 field value
|
|
110
|
+
*/
|
|
111
|
+
usePrefix?: boolean;
|
|
112
|
+
}): any;
|
|
79
113
|
}
|
|
80
114
|
export declare class Collection {
|
|
81
115
|
fields: Map<string, CollectionField>;
|
|
@@ -83,7 +117,9 @@ export declare class Collection {
|
|
|
83
117
|
inherits: Map<string, Collection>;
|
|
84
118
|
dataSource: DataSource;
|
|
85
119
|
constructor(options?: Record<string, any>);
|
|
120
|
+
clone(): Collection;
|
|
86
121
|
getFilterByTK(record: any): any;
|
|
122
|
+
get titleableFields(): CollectionField[];
|
|
87
123
|
get hidden(): any;
|
|
88
124
|
get flowEngine(): FlowEngine;
|
|
89
125
|
get collectionManager(): CollectionManager;
|
|
@@ -97,7 +133,9 @@ export declare class Collection {
|
|
|
97
133
|
get titleCollectionField(): CollectionField;
|
|
98
134
|
initInherits(): void;
|
|
99
135
|
setDataSource(dataSource: DataSource): void;
|
|
100
|
-
setOptions(newOptions?: any
|
|
136
|
+
setOptions(newOptions?: any, options?: {
|
|
137
|
+
clearFields?: boolean;
|
|
138
|
+
}): void;
|
|
101
139
|
getFields(): CollectionField[];
|
|
102
140
|
getToOneAssociationFields(): CollectionField[];
|
|
103
141
|
getAssociationFields(types?: any[]): CollectionField[];
|
|
@@ -140,6 +178,7 @@ export declare class CollectionField {
|
|
|
140
178
|
get resourceName(): string;
|
|
141
179
|
get collectionName(): any;
|
|
142
180
|
get readonly(): any;
|
|
181
|
+
get titleable(): boolean;
|
|
143
182
|
get fullpath(): string;
|
|
144
183
|
get name(): any;
|
|
145
184
|
get type(): any;
|
package/lib/data-source/index.js
CHANGED
|
@@ -153,8 +153,8 @@ const _DataSource = class _DataSource {
|
|
|
153
153
|
upsertCollection(options) {
|
|
154
154
|
return this.collectionManager.upsertCollection(options);
|
|
155
155
|
}
|
|
156
|
-
upsertCollections(collections) {
|
|
157
|
-
return this.collectionManager.upsertCollections(collections);
|
|
156
|
+
upsertCollections(collections, options = {}) {
|
|
157
|
+
return this.collectionManager.upsertCollections(collections, options);
|
|
158
158
|
}
|
|
159
159
|
removeCollection(name) {
|
|
160
160
|
return this.collectionManager.removeCollection(name);
|
|
@@ -171,7 +171,7 @@ const _DataSource = class _DataSource {
|
|
|
171
171
|
const fieldName = otherKeys.join(".");
|
|
172
172
|
const collection = this.getCollection(collectionName);
|
|
173
173
|
if (!collection) {
|
|
174
|
-
|
|
174
|
+
return;
|
|
175
175
|
}
|
|
176
176
|
const field = collection.getFieldByPath(fieldName);
|
|
177
177
|
if (!field) {
|
|
@@ -205,12 +205,12 @@ const _CollectionManager = class _CollectionManager {
|
|
|
205
205
|
removeCollection(name) {
|
|
206
206
|
this.collections.delete(name);
|
|
207
207
|
}
|
|
208
|
-
updateCollection(newOptions) {
|
|
208
|
+
updateCollection(newOptions, options = {}) {
|
|
209
209
|
const collection = this.getCollection(newOptions.name);
|
|
210
210
|
if (!collection) {
|
|
211
211
|
throw new Error(`Collection ${newOptions.name} not found`);
|
|
212
212
|
}
|
|
213
|
-
collection.setOptions(newOptions);
|
|
213
|
+
collection.setOptions(newOptions, options);
|
|
214
214
|
}
|
|
215
215
|
upsertCollection(options) {
|
|
216
216
|
if (this.collections.has(options.name)) {
|
|
@@ -220,10 +220,10 @@ const _CollectionManager = class _CollectionManager {
|
|
|
220
220
|
}
|
|
221
221
|
return this.getCollection(options.name);
|
|
222
222
|
}
|
|
223
|
-
upsertCollections(collections) {
|
|
223
|
+
upsertCollections(collections, options = {}) {
|
|
224
224
|
for (const collection of (0, import_sortCollectionsByInherits.sortCollectionsByInherits)(collections)) {
|
|
225
225
|
if (this.collections.has(collection.name)) {
|
|
226
|
-
this.updateCollection(collection);
|
|
226
|
+
this.updateCollection(collection, options);
|
|
227
227
|
} else {
|
|
228
228
|
this.addCollection(collection);
|
|
229
229
|
}
|
|
@@ -300,6 +300,74 @@ const _CollectionManager = class _CollectionManager {
|
|
|
300
300
|
}
|
|
301
301
|
return collection.getField(fieldName);
|
|
302
302
|
}
|
|
303
|
+
getChildrenCollections(name) {
|
|
304
|
+
const childrens = [];
|
|
305
|
+
const collections = Array.from(this.collections.values());
|
|
306
|
+
const getChildrens = /* @__PURE__ */ __name((name2) => {
|
|
307
|
+
const inheritCollections = collections.filter((v) => {
|
|
308
|
+
var _a;
|
|
309
|
+
return (_a = v.options.inherits) == null ? void 0 : _a.includes(name2);
|
|
310
|
+
});
|
|
311
|
+
inheritCollections.forEach((v) => {
|
|
312
|
+
const collectionKey = v.name;
|
|
313
|
+
childrens.push(v);
|
|
314
|
+
return getChildrens(collectionKey);
|
|
315
|
+
});
|
|
316
|
+
return childrens;
|
|
317
|
+
}, "getChildrens");
|
|
318
|
+
return getChildrens(name);
|
|
319
|
+
}
|
|
320
|
+
getCollectionFieldsOptions(collectionName, type, interfaces, opts) {
|
|
321
|
+
var _a;
|
|
322
|
+
const {
|
|
323
|
+
association = false,
|
|
324
|
+
cached = {},
|
|
325
|
+
collectionNames = [collectionName],
|
|
326
|
+
maxDepth = 1,
|
|
327
|
+
allowAllTypes = false,
|
|
328
|
+
exceptInterfaces = [],
|
|
329
|
+
prefixFieldValue = "",
|
|
330
|
+
usePrefix = false,
|
|
331
|
+
dataSource: customDataSourceNameValue
|
|
332
|
+
} = opts || {};
|
|
333
|
+
if (collectionNames.length - 1 > maxDepth) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (cached[collectionName]) {
|
|
337
|
+
return import_lodash.default.cloneDeep(cached[collectionName]);
|
|
338
|
+
}
|
|
339
|
+
const collection = this.getCollection(collectionName);
|
|
340
|
+
if (!collection) {
|
|
341
|
+
throw new Error(`Collection ${collectionName} not found`);
|
|
342
|
+
}
|
|
343
|
+
const fields = collection.getFields();
|
|
344
|
+
const options = (_a = fields == null ? void 0 : fields.filter(
|
|
345
|
+
(field) => field.interface && !exceptInterfaces.includes(field.interface) && (allowAllTypes || type && type.includes(field.type) || interfaces && interfaces.includes(field.interface) || (association && field.target && field.target !== collectionName && Array.isArray(association) ? association.includes(field.interface) : false))
|
|
346
|
+
)) == null ? void 0 : _a.map((field) => {
|
|
347
|
+
var _a2, _b;
|
|
348
|
+
const result = {
|
|
349
|
+
value: usePrefix && prefixFieldValue ? `${prefixFieldValue}.${field.name}` : field.name,
|
|
350
|
+
label: ((_a2 = field == null ? void 0 : field.uiSchema) == null ? void 0 : _a2.title) || field.name,
|
|
351
|
+
...field
|
|
352
|
+
};
|
|
353
|
+
if (association && field.target) {
|
|
354
|
+
result.children = collectionNames.includes(field.target) ? [] : this.getCollectionFieldsOptions(field.target, type, interfaces, {
|
|
355
|
+
...opts,
|
|
356
|
+
cached,
|
|
357
|
+
dataSource: customDataSourceNameValue,
|
|
358
|
+
collectionNames: [...collectionNames, field.target],
|
|
359
|
+
prefixFieldValue: usePrefix ? prefixFieldValue ? `${prefixFieldValue}.${field.name}` : field.name : "",
|
|
360
|
+
usePrefix
|
|
361
|
+
});
|
|
362
|
+
if (!((_b = result.children) == null ? void 0 : _b.length)) {
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return result;
|
|
367
|
+
}).filter(Boolean);
|
|
368
|
+
cached[collectionName] = options;
|
|
369
|
+
return options;
|
|
370
|
+
}
|
|
303
371
|
};
|
|
304
372
|
__name(_CollectionManager, "CollectionManager");
|
|
305
373
|
let CollectionManager = _CollectionManager;
|
|
@@ -314,6 +382,11 @@ const _Collection = class _Collection {
|
|
|
314
382
|
this.inherits = import_reactive.observable.shallow(/* @__PURE__ */ new Map());
|
|
315
383
|
this.setFields(options.fields || []);
|
|
316
384
|
}
|
|
385
|
+
clone() {
|
|
386
|
+
const newCollection = new _Collection(import_lodash.default.cloneDeep(this.options));
|
|
387
|
+
newCollection.setDataSource(this.dataSource);
|
|
388
|
+
return newCollection;
|
|
389
|
+
}
|
|
317
390
|
getFilterByTK(record) {
|
|
318
391
|
if (!record) {
|
|
319
392
|
throw new Error("Record is required to get filterByTk");
|
|
@@ -329,6 +402,9 @@ const _Collection = class _Collection {
|
|
|
329
402
|
}
|
|
330
403
|
return import_lodash.default.pick(record, this.filterTargetKey);
|
|
331
404
|
}
|
|
405
|
+
get titleableFields() {
|
|
406
|
+
return this.getFields().filter((field) => field.titleable);
|
|
407
|
+
}
|
|
332
408
|
get hidden() {
|
|
333
409
|
return this.options.hidden || false;
|
|
334
410
|
}
|
|
@@ -378,10 +454,13 @@ const _Collection = class _Collection {
|
|
|
378
454
|
setDataSource(dataSource) {
|
|
379
455
|
this.dataSource = dataSource;
|
|
380
456
|
}
|
|
381
|
-
setOptions(newOptions = {}) {
|
|
457
|
+
setOptions(newOptions = {}, options = {}) {
|
|
382
458
|
Object.keys(this.options).forEach((key) => delete this.options[key]);
|
|
383
459
|
Object.assign(this.options, newOptions);
|
|
384
460
|
this.initInherits();
|
|
461
|
+
if (options.clearFields) {
|
|
462
|
+
this.clearFields();
|
|
463
|
+
}
|
|
385
464
|
this.upsertFields(this.options.fields || []);
|
|
386
465
|
}
|
|
387
466
|
getFields() {
|
|
@@ -440,13 +519,12 @@ const _Collection = class _Collection {
|
|
|
440
519
|
if (otherKeys.length === 0) {
|
|
441
520
|
return field;
|
|
442
521
|
}
|
|
443
|
-
if (!field.targetCollection) {
|
|
522
|
+
if (!(field == null ? void 0 : field.targetCollection)) {
|
|
444
523
|
return null;
|
|
445
524
|
}
|
|
446
525
|
return field.targetCollection.getFieldByPath(otherKeys.join("."));
|
|
447
526
|
}
|
|
448
527
|
getField(fieldName) {
|
|
449
|
-
this.setFields(this.options.fields);
|
|
450
528
|
return this.fields.get(fieldName);
|
|
451
529
|
}
|
|
452
530
|
getFullFieldPath(name) {
|
|
@@ -561,6 +639,9 @@ const _CollectionField = class _CollectionField {
|
|
|
561
639
|
var _a;
|
|
562
640
|
return this.options.readonly || ((_a = this.options.uiSchema) == null ? void 0 : _a["x-read-pretty"]) || false;
|
|
563
641
|
}
|
|
642
|
+
get titleable() {
|
|
643
|
+
return !!(this.options.titleable ?? this.options.titleUsable);
|
|
644
|
+
}
|
|
564
645
|
get fullpath() {
|
|
565
646
|
return this.collection.dataSource.key + "." + this.collection.name + "." + this.name;
|
|
566
647
|
}
|
|
@@ -595,7 +676,19 @@ const _CollectionField = class _CollectionField {
|
|
|
595
676
|
}
|
|
596
677
|
get enum() {
|
|
597
678
|
var _a;
|
|
598
|
-
|
|
679
|
+
const options = ((_a = this.options.uiSchema) == null ? void 0 : _a.enum) || [];
|
|
680
|
+
if (this.type === "integer") {
|
|
681
|
+
return options.map((v) => {
|
|
682
|
+
if (typeof v !== "object") {
|
|
683
|
+
return v;
|
|
684
|
+
}
|
|
685
|
+
return {
|
|
686
|
+
...v,
|
|
687
|
+
value: Number(v.value)
|
|
688
|
+
};
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
return options;
|
|
599
692
|
}
|
|
600
693
|
get defaultValue() {
|
|
601
694
|
return this.options.defaultValue == null ? void 0 : this.options.defaultValue;
|
package/lib/emitter.d.ts
CHANGED
|
@@ -13,4 +13,10 @@ export declare class Emitter {
|
|
|
13
13
|
on(event: string, callback: (...args: any[]) => void): void;
|
|
14
14
|
off(event: string, callback: (...args: any[]) => void): void;
|
|
15
15
|
emit(event: string, ...args: any[]): void;
|
|
16
|
+
/**
|
|
17
|
+
* 异步触发事件:按监听器注册顺序依次(串行)等待执行完成。
|
|
18
|
+
* - 若某个监听器抛错/Promise reject,将中断后续执行并将异常向上传递(便于调用方统一处理)。
|
|
19
|
+
* - 当前不提供并行触发能力;如需并发处理,请在监听器内部自行管理(例如在回调内使用 Promise.all)。
|
|
20
|
+
*/
|
|
21
|
+
emitAsync(event: string, ...args: any[]): Promise<void>;
|
|
16
22
|
}
|
package/lib/emitter.js
CHANGED
|
@@ -49,6 +49,18 @@ const _Emitter = class _Emitter {
|
|
|
49
49
|
}
|
|
50
50
|
(this.events[event] || []).forEach((fn) => fn(...args));
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* 异步触发事件:按监听器注册顺序依次(串行)等待执行完成。
|
|
54
|
+
* - 若某个监听器抛错/Promise reject,将中断后续执行并将异常向上传递(便于调用方统一处理)。
|
|
55
|
+
* - 当前不提供并行触发能力;如需并发处理,请在监听器内部自行管理(例如在回调内使用 Promise.all)。
|
|
56
|
+
*/
|
|
57
|
+
async emitAsync(event, ...args) {
|
|
58
|
+
if (this.paused) return;
|
|
59
|
+
const listeners = (this.events[event] || []).slice();
|
|
60
|
+
for (const fn of listeners) {
|
|
61
|
+
await fn(...args);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
52
64
|
};
|
|
53
65
|
__name(_Emitter, "Emitter");
|
|
54
66
|
let Emitter = _Emitter;
|
|
@@ -46,6 +46,7 @@ var import_flowEngine = require("../flowEngine");
|
|
|
46
46
|
var import_utils = require("../utils");
|
|
47
47
|
var import_exceptions = require("../utils/exceptions");
|
|
48
48
|
var import_setupRuntimeContextSteps = require("../utils/setupRuntimeContextSteps");
|
|
49
|
+
var import_createEphemeralContext = require("../utils/createEphemeralContext");
|
|
49
50
|
const _FlowExecutor = class _FlowExecutor {
|
|
50
51
|
constructor(engine) {
|
|
51
52
|
this.engine = engine;
|
|
@@ -116,6 +117,7 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
116
117
|
let handler;
|
|
117
118
|
let combinedParams = {};
|
|
118
119
|
let useRawParams = step.useRawParams;
|
|
120
|
+
let runtimeCtx;
|
|
119
121
|
if (step.use) {
|
|
120
122
|
const actionDefinition = model.getAction(step.use);
|
|
121
123
|
if (!actionDefinition) {
|
|
@@ -124,14 +126,19 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
124
126
|
);
|
|
125
127
|
continue;
|
|
126
128
|
}
|
|
129
|
+
runtimeCtx = await (0, import_createEphemeralContext.createEphemeralContext)(flowContext, {
|
|
130
|
+
...actionDefinition,
|
|
131
|
+
...step
|
|
132
|
+
});
|
|
127
133
|
handler = step.handler || actionDefinition.handler;
|
|
128
134
|
useRawParams = useRawParams ?? actionDefinition.useRawParams;
|
|
129
|
-
const actionDefaultParams = await (0, import_utils.resolveDefaultParams)(actionDefinition.defaultParams,
|
|
130
|
-
const stepDefaultParams = await (0, import_utils.resolveDefaultParams)(step.defaultParams,
|
|
135
|
+
const actionDefaultParams = await (0, import_utils.resolveDefaultParams)(actionDefinition.defaultParams, runtimeCtx);
|
|
136
|
+
const stepDefaultParams = await (0, import_utils.resolveDefaultParams)(step.defaultParams, runtimeCtx);
|
|
131
137
|
combinedParams = { ...actionDefaultParams, ...stepDefaultParams };
|
|
132
138
|
} else if (step.handler) {
|
|
139
|
+
runtimeCtx = await (0, import_createEphemeralContext.createEphemeralContext)(flowContext, step);
|
|
133
140
|
handler = step.handler;
|
|
134
|
-
const stepDefaultParams = await (0, import_utils.resolveDefaultParams)(step.defaultParams,
|
|
141
|
+
const stepDefaultParams = await (0, import_utils.resolveDefaultParams)(step.defaultParams, runtimeCtx);
|
|
135
142
|
combinedParams = { ...stepDefaultParams };
|
|
136
143
|
} else {
|
|
137
144
|
flowContext.logger.error(
|
|
@@ -144,10 +151,10 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
144
151
|
combinedParams = { ...combinedParams, ...modelStepParams };
|
|
145
152
|
}
|
|
146
153
|
if (typeof useRawParams === "function") {
|
|
147
|
-
useRawParams = await useRawParams(
|
|
154
|
+
useRawParams = await useRawParams(runtimeCtx);
|
|
148
155
|
}
|
|
149
156
|
if (!useRawParams) {
|
|
150
|
-
combinedParams = await
|
|
157
|
+
combinedParams = await runtimeCtx.resolveJsonTemplate(combinedParams);
|
|
151
158
|
}
|
|
152
159
|
try {
|
|
153
160
|
if (!handler) {
|
|
@@ -156,7 +163,7 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
156
163
|
);
|
|
157
164
|
continue;
|
|
158
165
|
}
|
|
159
|
-
const currentStepResult = handler(
|
|
166
|
+
const currentStepResult = handler(runtimeCtx, combinedParams);
|
|
160
167
|
const isAwait = step.isAwait !== false;
|
|
161
168
|
lastResult = isAwait ? await currentStepResult : currentStepResult;
|
|
162
169
|
stepResults[stepKey] = lastResult;
|
|
@@ -192,6 +199,12 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
192
199
|
const runId = `${model.uid}-${eventName}-${Date.now()}`;
|
|
193
200
|
const logger = model.context.logger;
|
|
194
201
|
try {
|
|
202
|
+
await this.engine.emitter.emitAsync(`model:event:${eventName}:start`, {
|
|
203
|
+
uid: model.uid,
|
|
204
|
+
model,
|
|
205
|
+
runId,
|
|
206
|
+
inputArgs
|
|
207
|
+
});
|
|
195
208
|
await ((_a = model.onDispatchEventStart) == null ? void 0 : _a.call(model, eventName, options, inputArgs));
|
|
196
209
|
} catch (err) {
|
|
197
210
|
if (isBeforeRender && err instanceof import_utils.FlowExitException) {
|
|
@@ -215,7 +228,21 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
215
228
|
});
|
|
216
229
|
const execute = /* @__PURE__ */ __name(async () => {
|
|
217
230
|
if (sequential) {
|
|
218
|
-
const
|
|
231
|
+
const flowsWithIndex = flows.map((f, i) => ({ f, i }));
|
|
232
|
+
const ordered = flowsWithIndex.slice().sort((a, b) => {
|
|
233
|
+
var _a2, _b2;
|
|
234
|
+
const regA = a.f["flowRegistry"];
|
|
235
|
+
const regB = b.f["flowRegistry"];
|
|
236
|
+
const typeA = (_a2 = regA == null ? void 0 : regA.constructor) == null ? void 0 : _a2._type;
|
|
237
|
+
const typeB = (_b2 = regB == null ? void 0 : regB.constructor) == null ? void 0 : _b2._type;
|
|
238
|
+
const groupA = typeA === "instance" ? 0 : 1;
|
|
239
|
+
const groupB = typeB === "instance" ? 0 : 1;
|
|
240
|
+
if (groupA !== groupB) return groupA - groupB;
|
|
241
|
+
const sa = a.f.sort ?? 0;
|
|
242
|
+
const sb = b.f.sort ?? 0;
|
|
243
|
+
if (sa !== sb) return sa - sb;
|
|
244
|
+
return a.i - b.i;
|
|
245
|
+
}).map((x) => x.f);
|
|
219
246
|
const results2 = [];
|
|
220
247
|
for (const flow of ordered) {
|
|
221
248
|
try {
|
|
@@ -268,6 +295,13 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
268
295
|
} catch (hookErr) {
|
|
269
296
|
logger.error({ err: hookErr }, `BaseModel.dispatchEvent: End hook error for event '${eventName}'`);
|
|
270
297
|
}
|
|
298
|
+
await this.engine.emitter.emitAsync(`model:event:${eventName}:end`, {
|
|
299
|
+
uid: model.uid,
|
|
300
|
+
model,
|
|
301
|
+
runId,
|
|
302
|
+
inputArgs,
|
|
303
|
+
result
|
|
304
|
+
});
|
|
271
305
|
return result;
|
|
272
306
|
} catch (error) {
|
|
273
307
|
try {
|
|
@@ -278,6 +312,13 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
278
312
|
{ err: error },
|
|
279
313
|
`BaseModel.dispatchEvent: Error executing event '${eventName}' for model '${model.uid}':`
|
|
280
314
|
);
|
|
315
|
+
await this.engine.emitter.emitAsync(`model:event:${eventName}:error`, {
|
|
316
|
+
uid: model.uid,
|
|
317
|
+
model,
|
|
318
|
+
runId,
|
|
319
|
+
inputArgs,
|
|
320
|
+
error
|
|
321
|
+
});
|
|
281
322
|
if (throwOnError) throw error;
|
|
282
323
|
}
|
|
283
324
|
}
|