@nocobase/client-v2 2.1.0-alpha.22 → 2.1.0-alpha.23
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/es/Application.d.ts +27 -105
- package/es/BaseApplication.d.ts +176 -0
- package/es/PinnedPluginListContext.d.ts +22 -0
- package/es/Plugin.d.ts +37 -11
- package/es/PluginManager.d.ts +19 -20
- package/es/PluginSettingsManager.d.ts +168 -30
- package/es/RouteRepository.d.ts +124 -0
- package/es/RouterManager.d.ts +18 -13
- package/es/WebSocketClient.d.ts +3 -3
- package/es/acl/ACLProvider.d.ts +81 -0
- package/es/acl/createAclSnippetAllow.d.ts +16 -0
- package/es/acl/index.d.ts +11 -0
- package/es/acl/useAclSnippets.d.ts +16 -0
- package/es/ai/ai-manager.d.ts +15 -0
- package/es/ai/index.d.ts +12 -0
- package/{lib/components → es/ai/skills-manager}/index.d.ts +1 -2
- package/es/ai/skills-manager/types.d.ts +23 -0
- package/es/ai/tools-manager/hooks/context.d.ts +17 -0
- package/es/ai/tools-manager/hooks/index.d.ts +11 -0
- package/es/ai/tools-manager/hooks/provider.d.ts +16 -0
- package/es/ai/tools-manager/index.d.ts +20 -0
- package/es/ai/tools-manager/types.d.ts +90 -0
- package/es/ai/utils.d.ts +10 -0
- package/es/authRedirect.d.ts +63 -0
- package/es/collection-field-interface/CollectionFieldInterface.d.ts +71 -0
- package/es/collection-field-interface/CollectionFieldInterfaceManager.d.ts +109 -0
- package/es/collection-manager/interfaces/checkbox.d.ts +87 -0
- package/es/collection-manager/interfaces/checkboxGroup.d.ts +138 -0
- package/es/collection-manager/interfaces/collection.d.ts +145 -0
- package/es/collection-manager/interfaces/color.d.ts +62 -0
- package/es/collection-manager/interfaces/createdAt.d.ts +96 -0
- package/es/collection-manager/interfaces/createdBy.d.ts +63 -0
- package/es/collection-manager/interfaces/dateOnly.d.ts +103 -0
- package/es/collection-manager/interfaces/datetime.d.ts +121 -0
- package/es/collection-manager/interfaces/datetimeNoTz.d.ts +121 -0
- package/es/collection-manager/interfaces/email.d.ts +87 -0
- package/es/collection-manager/interfaces/icon.d.ts +44 -0
- package/es/collection-manager/interfaces/id.d.ts +71 -0
- package/es/collection-manager/interfaces/index.d.ts +49 -0
- package/es/collection-manager/interfaces/input.d.ts +187 -0
- package/es/collection-manager/interfaces/integer.d.ts +186 -0
- package/es/collection-manager/interfaces/json.d.ts +62 -0
- package/es/collection-manager/interfaces/linkTo.d.ts +90 -0
- package/es/collection-manager/interfaces/m2m.d.ts +268 -0
- package/es/collection-manager/interfaces/m2o.d.ts +215 -0
- package/es/collection-manager/interfaces/markdown.d.ts +108 -0
- package/es/collection-manager/interfaces/multipleSelect.d.ts +141 -0
- package/es/collection-manager/interfaces/nanoid.d.ts +131 -0
- package/es/collection-manager/interfaces/number.d.ts +187 -0
- package/es/collection-manager/interfaces/o2m.d.ts +243 -0
- package/es/collection-manager/interfaces/o2o.d.ts +621 -0
- package/es/collection-manager/interfaces/password.d.ts +112 -0
- package/es/collection-manager/interfaces/percent.d.ts +157 -0
- package/es/collection-manager/interfaces/phone.d.ts +85 -0
- package/es/collection-manager/interfaces/properties/index.d.ts +145 -0
- package/es/collection-manager/interfaces/properties/operators.d.ts +294 -0
- package/es/collection-manager/interfaces/radioGroup.d.ts +134 -0
- package/es/collection-manager/interfaces/richText.d.ts +110 -0
- package/es/collection-manager/interfaces/select.d.ts +139 -0
- package/es/collection-manager/interfaces/snowflake-id.d.ts +117 -0
- package/es/collection-manager/interfaces/subTable.d.ts +172 -0
- package/es/collection-manager/interfaces/tableoid.d.ts +59 -0
- package/es/collection-manager/interfaces/textarea.d.ts +107 -0
- package/es/collection-manager/interfaces/time.d.ts +64 -0
- package/es/collection-manager/interfaces/types.d.ts +38 -0
- package/es/collection-manager/interfaces/unixTimestamp.d.ts +124 -0
- package/es/collection-manager/interfaces/updatedAt.d.ts +96 -0
- package/es/collection-manager/interfaces/updatedBy.d.ts +63 -0
- package/es/collection-manager/interfaces/url.d.ts +72 -0
- package/es/collection-manager/interfaces/utils/index.d.ts +14 -0
- package/es/collection-manager/interfaces/uuid.d.ts +120 -0
- package/es/components/AppComponents.d.ts +27 -0
- package/es/components/Icon.d.ts +24 -0
- package/es/components/index.d.ts +2 -0
- package/es/css-variable/CSSVariableProvider.d.ts +15 -0
- package/es/flow/FlowModelRepository.d.ts +36 -0
- package/es/flow/FlowPage.d.ts +20 -0
- package/es/flow/actions/aclCheck.d.ts +9 -0
- package/es/flow/actions/aclCheckRefresh.d.ts +9 -0
- package/es/flow/actions/afterSuccess.d.ts +9 -0
- package/es/flow/actions/blockHeight.d.ts +9 -0
- package/es/flow/actions/columnFixed.d.ts +9 -0
- package/es/flow/actions/confirm.d.ts +9 -0
- package/es/flow/actions/customVariable.d.ts +9 -0
- package/es/flow/actions/dataLoadingMode.d.ts +9 -0
- package/es/flow/actions/dataScope.d.ts +9 -0
- package/es/flow/actions/dateTimeFormat.d.ts +9 -0
- package/es/flow/actions/displayFieldComponent.d.ts +19 -0
- package/es/flow/actions/fieldComponent.d.ts +9 -0
- package/es/flow/actions/filterFormDefaultValues.d.ts +9 -0
- package/es/flow/actions/formAssignRules.d.ts +9 -0
- package/es/flow/actions/index.d.ts +40 -0
- package/es/flow/actions/layout.d.ts +10 -0
- package/es/flow/actions/linkageRules.d.ts +23 -0
- package/es/flow/actions/linkageRulesRefresh.d.ts +9 -0
- package/es/flow/actions/navigateToURL.d.ts +9 -0
- package/es/flow/actions/numberFormat.d.ts +9 -0
- package/es/flow/actions/openView.d.ts +15 -0
- package/es/flow/actions/overflowMode.d.ts +9 -0
- package/es/flow/actions/pattern.d.ts +9 -0
- package/es/flow/actions/refreshTargetBlocks.d.ts +9 -0
- package/es/flow/actions/renderMode.d.ts +9 -0
- package/es/flow/actions/required.d.ts +9 -0
- package/es/flow/actions/runjs.d.ts +9 -0
- package/es/flow/actions/setTargetDataScope.d.ts +10 -0
- package/es/flow/actions/showMessage.d.ts +9 -0
- package/es/flow/actions/showNotification.d.ts +9 -0
- package/es/flow/actions/sortingRules.d.ts +9 -0
- package/es/flow/actions/titleField.d.ts +9 -0
- package/es/flow/actions/validation.d.ts +9 -0
- package/es/flow/admin-shell/AdminLayoutRouteCoordinator.d.ts +51 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutCompat.d.ts +112 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutComponent.d.ts +10 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.d.ts +107 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +60 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.d.ts +167 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutModel.d.ts +150 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutSlotModels.d.ts +31 -0
- package/es/flow/admin-shell/admin-layout/HelpLite.d.ts +13 -0
- package/{lib/utils/requirejs.d.ts → es/flow/admin-shell/admin-layout/PinnedPluginListLite.d.ts} +5 -8
- package/es/flow/admin-shell/admin-layout/ResetThemeTokenAndKeepAlgorithm.d.ts +13 -0
- package/es/flow/admin-shell/admin-layout/TopbarActionsBar.d.ts +25 -0
- package/es/flow/admin-shell/admin-layout/constants.d.ts +9 -0
- package/es/flow/admin-shell/admin-layout/flowSettingsPreference.d.ts +23 -0
- package/es/flow/admin-shell/admin-layout/index.d.ts +19 -0
- package/es/flow/admin-shell/admin-layout/mobile-layout.d.ts +12 -0
- package/es/flow/admin-shell/admin-layout/mobileMenuNavigation.d.ts +15 -0
- package/es/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.d.ts +42 -0
- package/{lib/context.d.ts → es/flow/admin-shell/admin-layout/useApplications.d.ts} +3 -2
- package/es/flow/admin-shell/useAdminLayoutRoutePage.d.ts +28 -0
- package/es/flow/common/Liquid.d.ts +33 -0
- package/es/flow/common/Markdown/Display.d.ts +9 -0
- package/es/flow/common/Markdown/Edit.d.ts +23 -0
- package/es/flow/common/Markdown/Markdown.d.ts +24 -0
- package/es/flow/common/Markdown/style.d.ts +14 -0
- package/es/flow/common/Markdown/useCDN.d.ts +9 -0
- package/es/flow/components/AdminLayout.d.ts +11 -0
- package/es/flow/components/BlockItemCard.d.ts +16 -0
- package/es/flow/components/ConditionBuilder.d.ts +17 -0
- package/es/flow/components/DefaultValue.d.ts +20 -0
- package/es/flow/components/DynamicFlowsIcon.d.ts +13 -0
- package/es/flow/components/EllipsisWithTooltip.d.ts +17 -0
- package/es/flow/components/ExpiresRadio/index.d.ts +12 -0
- package/es/flow/components/FieldAssignEditor.d.ts +32 -0
- package/es/flow/components/FieldAssignExactDatePicker.d.ts +23 -0
- package/es/flow/components/FieldAssignRulesEditor.d.ts +70 -0
- package/es/flow/components/FieldAssignValueInput.d.ts +88 -0
- package/es/flow/components/FlowRoute.d.ts +28 -0
- package/es/flow/components/Grid/index.d.ts +26 -0
- package/es/flow/components/JsonEditor.d.ts +19 -0
- package/es/flow/components/RunJSValueEditor.d.ts +19 -0
- package/{lib/hooks/useApp.d.ts → es/flow/components/SkeletonFallback.d.ts} +2 -2
- package/es/flow/components/TextAreaWithContextSelector.d.ts +30 -0
- package/es/flow/components/code-editor/core/EditorCore.d.ts +25 -0
- package/es/flow/components/code-editor/core/tooltipParent.d.ts +9 -0
- package/es/flow/components/code-editor/errorHelpers.d.ts +17 -0
- package/es/flow/components/code-editor/extension/CodeEditorExtension.d.ts +14 -0
- package/{lib/hooks → es/flow/components/code-editor/extension}/index.d.ts +1 -3
- package/es/flow/components/code-editor/formatDocInfo.d.ts +17 -0
- package/es/flow/components/code-editor/hooks/useCodeRunner.d.ts +23 -0
- package/es/flow/components/code-editor/hooks/useRunJSDocCompletions.d.ts +15 -0
- package/es/flow/components/code-editor/htmlCompletion.d.ts +11 -0
- package/es/flow/components/code-editor/index.d.ts +31 -0
- package/es/flow/components/code-editor/javascriptCompletion.d.ts +11 -0
- package/es/flow/components/code-editor/javascriptHtmlTemplate.d.ts +16 -0
- package/es/flow/components/code-editor/jsxCompletion.d.ts +10 -0
- package/es/flow/components/code-editor/linter.d.ts +19 -0
- package/es/flow/components/code-editor/panels/LogsPanel.d.ts +15 -0
- package/es/flow/components/code-editor/panels/RightExtra.d.ts +18 -0
- package/es/flow/components/code-editor/panels/SnippetsDrawer.d.ts +18 -0
- package/es/flow/components/code-editor/resolveScenes.d.ts +10 -0
- package/es/flow/components/code-editor/runjsCompletionSource.d.ts +20 -0
- package/es/flow/components/code-editor/runjsCompletions.d.ts +23 -0
- package/es/flow/components/code-editor/runjsDiagnostics.d.ts +46 -0
- package/es/flow/components/code-editor/types.d.ts +32 -0
- package/es/flow/components/drag-drop/Sortable.d.ts +12 -0
- package/es/flow/components/drag-drop/SortableItem.d.ts +12 -0
- package/es/flow/components/drag-drop/index.d.ts +10 -0
- package/es/flow/components/fieldAssignOptions.d.ts +23 -0
- package/es/flow/components/filter/FilterContainer.d.ts +67 -0
- package/es/flow/components/filter/FilterGroup.d.ts +66 -0
- package/es/flow/components/filter/FilterItem.d.ts +40 -0
- package/es/flow/components/filter/LinkageFilterItem.d.ts +51 -0
- package/es/flow/components/filter/VariableFilterItem.d.ts +37 -0
- package/es/flow/components/filter/fieldsToOptions.d.ts +9 -0
- package/es/flow/components/filter/index.d.ts +16 -0
- package/es/flow/components/index.d.ts +14 -0
- package/es/flow/components/placeholders/BlockPlaceholder.d.ts +11 -0
- package/{lib/components/MainComponent.d.ts → es/flow/components/placeholders/FieldPlaceholder.d.ts} +1 -1
- package/es/flow/components/useAssociationTitleFieldSync.d.ts +13 -0
- package/es/flow/flows/editMarkdownFlow.d.ts +10 -0
- package/es/flow/flows/openViewFlow.d.ts +17 -0
- package/es/flow/formily/ReactiveField.d.ts +19 -0
- package/es/flow/formily/index.d.ts +8 -0
- package/es/flow/getViewDiffAndUpdateHidden.d.ts +21 -0
- package/es/flow/index.d.ts +30 -0
- package/es/flow/internal/components/Markdown/DisplayMarkdown.d.ts +10 -0
- package/{lib/utils/globalDeps.d.ts → es/flow/internal/components/Markdown/markdown-it-plugins/mermaidPlugin.d.ts} +3 -3
- package/es/flow/internal/components/Markdown/md.d.ts +11 -0
- package/es/flow/internal/components/Markdown/style.d.ts +9 -0
- package/es/flow/internal/components/Markdown/util.d.ts +15 -0
- package/{lib/components/BlankComponent.d.ts → es/flow/internal/constants/HeightMode.d.ts} +5 -4
- package/es/flow/internal/index.d.ts +11 -0
- package/es/flow/internal/utils/associationValueCoercion.d.ts +15 -0
- package/es/flow/internal/utils/dateTimeUtils.d.ts +10 -0
- package/es/flow/internal/utils/enumOptionsUtils.d.ts +23 -0
- package/es/flow/internal/utils/modelUtils.d.ts +27 -0
- package/es/flow/internal/utils/operatorSchemaHelper.d.ts +15 -0
- package/es/flow/internal/utils/rebuildFieldSubModel.d.ts +33 -0
- package/es/flow/internal/utils/saveStepParamsWithSubModels.d.ts +11 -0
- package/es/flow/internal/utils/titleFieldQuickSync.d.ts +36 -0
- package/es/flow/models/actions/AddChildActionModel.d.ts +16 -0
- package/es/flow/models/actions/AddNewActionModel.d.ts +16 -0
- package/es/flow/models/actions/BulkDeleteActionModel.d.ts +16 -0
- package/es/flow/models/actions/DeleteActionModel.d.ts +15 -0
- package/es/flow/models/actions/EditActionModel.d.ts +16 -0
- package/es/flow/models/actions/ExpandCollapseActionModel.d.ts +19 -0
- package/es/flow/models/actions/FilterActionModel.d.ts +26 -0
- package/{lib/components/RouterBridge.d.ts → es/flow/models/actions/JSActionModel.d.ts} +5 -5
- package/es/flow/models/actions/JSCollectionActionModel.d.ts +14 -0
- package/es/flow/models/actions/JSItemActionModel.d.ts +19 -0
- package/es/flow/models/actions/JSRecordActionModel.d.ts +14 -0
- package/es/flow/models/actions/LinkActionModel.d.ts +15 -0
- package/es/flow/models/actions/LinkActionUtils.d.ts +34 -0
- package/es/flow/models/actions/PopupCollectionActionModel.d.ts +14 -0
- package/es/flow/models/actions/RefreshActionModel.d.ts +14 -0
- package/es/flow/models/actions/UpdateRecordActionModel.d.ts +27 -0
- package/es/flow/models/actions/UpdateRecordActionUtils.d.ts +12 -0
- package/es/flow/models/actions/ViewActionModel.d.ts +15 -0
- package/es/flow/models/actions/index.d.ts +24 -0
- package/es/flow/models/actions/joinUrlSearch.d.ts +12 -0
- package/es/flow/models/base/ActionGroupModel.d.ts +9 -0
- package/es/flow/models/base/ActionGroupModelCore.d.ts +29 -0
- package/es/flow/models/base/ActionModel.d.ts +9 -0
- package/es/flow/models/base/ActionModelCore.d.ts +45 -0
- package/es/flow/models/base/AssociationFieldGroupModel.d.ts +49 -0
- package/es/flow/models/base/BlockGridModel.d.ts +21 -0
- package/es/flow/models/base/BlockModel.d.ts +57 -0
- package/es/flow/models/base/CollectionActionModel.d.ts +12 -0
- package/es/flow/models/base/CollectionBlockModel.d.ts +71 -0
- package/es/flow/models/base/CommonItemModel.d.ts +11 -0
- package/es/flow/models/base/DataBlockModel.d.ts +12 -0
- package/es/flow/models/base/FieldModel.d.ts +17 -0
- package/es/flow/models/base/FilterBlockModel.d.ts +12 -0
- package/es/flow/models/base/GridModel.d.ts +99 -0
- package/es/flow/models/base/PageModel/ChildPageModel.d.ts +21 -0
- package/es/flow/models/base/PageModel/MainPageModel.d.ts +17 -0
- package/es/flow/models/base/PageModel/OldPageModel.d.ts +21 -0
- package/es/flow/models/base/PageModel/PageModel.d.ts +53 -0
- package/es/flow/models/base/PageModel/PageTabModel.d.ts +42 -0
- package/es/flow/models/base/PageModel/RootPageModel.d.ts +24 -0
- package/es/flow/models/base/PageModel/SubPageModel.d.ts +17 -0
- package/es/flow/models/base/PageModel/closeGuard.d.ts +31 -0
- package/{lib → es/flow/models/base/PageModel}/index.d.ts +6 -6
- package/es/flow/models/base/PopupActionModel.d.ts +13 -0
- package/es/flow/models/base/RecordActionModel.d.ts +12 -0
- package/es/flow/models/base/RouteModel.d.ts +11 -0
- package/es/flow/models/base/index.d.ts +24 -0
- package/es/flow/models/blocks/assign-form/AssignFormGridModel.d.ts +15 -0
- package/es/flow/models/blocks/assign-form/AssignFormItemModel.d.ts +22 -0
- package/es/flow/models/blocks/assign-form/AssignFormModel.d.ts +26 -0
- package/es/flow/models/blocks/assign-form/index.d.ts +11 -0
- package/es/flow/models/blocks/details/DetailsAssociationFieldGroupModel.d.ts +12 -0
- package/es/flow/models/blocks/details/DetailsBlockModel.d.ts +41 -0
- package/es/flow/models/blocks/details/DetailsCustomItemModel.d.ts +13 -0
- package/es/flow/models/blocks/details/DetailsGridModel.d.ts +33 -0
- package/es/flow/models/blocks/details/DetailsItemModel.d.ts +60 -0
- package/es/flow/models/blocks/details/DetailsJSFieldItemModel.d.ts +19 -0
- package/es/flow/models/blocks/details/index.d.ts +14 -0
- package/es/flow/models/blocks/details/utils.d.ts +16 -0
- package/es/flow/models/blocks/filter-form/FieldModelSelect.d.ts +10 -0
- package/es/flow/models/blocks/filter-form/FieldOperatorSelect.d.ts +10 -0
- package/es/flow/models/blocks/filter-form/FilterFormActionGroupModel.d.ts +13 -0
- package/es/flow/models/blocks/filter-form/FilterFormActionModel.d.ts +11 -0
- package/es/flow/models/blocks/filter-form/FilterFormBlockModel.d.ts +39 -0
- package/es/flow/models/blocks/filter-form/FilterFormCollapseActionModel.d.ts +18 -0
- package/es/flow/models/blocks/filter-form/FilterFormCustomItemModel.d.ts +13 -0
- package/es/flow/models/blocks/filter-form/FilterFormGridModel.d.ts +43 -0
- package/es/flow/models/blocks/filter-form/FilterFormItemModel.d.ts +59 -0
- package/es/flow/models/blocks/filter-form/FilterFormJSActionModel.d.ts +11 -0
- package/es/flow/models/blocks/filter-form/FilterFormResetActionModel.d.ts +13 -0
- package/es/flow/models/blocks/filter-form/FilterFormSubmitActionModel.d.ts +15 -0
- package/es/flow/models/blocks/filter-form/SourceCascader.d.ts +10 -0
- package/es/flow/models/blocks/filter-form/customFieldOperators.d.ts +34 -0
- package/es/flow/models/blocks/filter-form/fields/FieldComponentProps.d.ts +13 -0
- package/es/flow/models/blocks/filter-form/fields/FilterFormCustomFieldModel.d.ts +52 -0
- package/es/flow/models/blocks/filter-form/fields/FilterFormCustomRecordSelectFieldModel.d.ts +20 -0
- package/{lib/components/RouterContextCleaner.d.ts → es/flow/models/blocks/filter-form/fields/FilterFormFieldModel.d.ts} +3 -4
- package/es/flow/models/blocks/filter-form/fields/FilterFormRecordSelectFieldModel.d.ts +12 -0
- package/es/flow/models/blocks/filter-form/fields/date-time/DateOnlyFilterFieldModel.d.ts +14 -0
- package/es/flow/models/blocks/filter-form/fields/date-time/DateTimeFilterFieldModel.d.ts +13 -0
- package/es/flow/models/blocks/filter-form/fields/date-time/DateTimeNoTzFilterFieldModel.d.ts +13 -0
- package/es/flow/models/blocks/filter-form/fields/date-time/DateTimeTzFilterFieldModel.d.ts +14 -0
- package/es/flow/models/blocks/filter-form/fields/date-time/components/DateFilterDynamicComponent.d.ts +10 -0
- package/es/flow/models/blocks/filter-form/fields/date-time/components/FilterDatePicker.d.ts +10 -0
- package/es/flow/models/blocks/filter-form/fields/date-time/components/FilterRangePicker.d.ts +10 -0
- package/es/flow/models/blocks/filter-form/fields/date-time/index.d.ts +12 -0
- package/es/flow/models/blocks/filter-form/fields/index.d.ts +13 -0
- package/es/flow/models/blocks/filter-form/index.d.ts +23 -0
- package/es/flow/models/blocks/filter-form/legacyDefaultValueMigration.d.ts +13 -0
- package/es/flow/models/blocks/filter-form/valueNormalization.d.ts +17 -0
- package/es/flow/models/blocks/filter-manager/FilterManager.d.ts +141 -0
- package/es/flow/models/blocks/filter-manager/flow-actions/connectFields.d.ts +10 -0
- package/es/flow/models/blocks/filter-manager/flow-actions/customizeFilterRender.d.ts +10 -0
- package/es/flow/models/blocks/filter-manager/flow-actions/defaultOperator.d.ts +9 -0
- package/es/flow/models/blocks/filter-manager/flow-actions/index.d.ts +12 -0
- package/es/flow/models/blocks/filter-manager/flow-actions/operatorComponentProps.d.ts +10 -0
- package/es/flow/models/blocks/filter-manager/index.d.ts +11 -0
- package/es/flow/models/blocks/filter-manager/utils.d.ts +21 -0
- package/es/flow/models/blocks/form/CreateFormModel.d.ts +22 -0
- package/es/flow/models/blocks/form/EditFormModel.d.ts +26 -0
- package/es/flow/models/blocks/form/FormActionGroupModel.d.ts +13 -0
- package/es/flow/models/blocks/form/FormActionModel.d.ts +21 -0
- package/es/flow/models/blocks/form/FormAssociationFieldGroupModel.d.ts +12 -0
- package/es/flow/models/blocks/form/FormAssociationItemModel.d.ts +39 -0
- package/es/flow/models/blocks/form/FormBlockModel.d.ts +96 -0
- package/es/flow/models/blocks/form/FormCustomItemModel.d.ts +13 -0
- package/es/flow/models/blocks/form/FormGridModel.d.ts +35 -0
- package/es/flow/models/blocks/form/FormItemModel.d.ts +39 -0
- package/es/flow/models/blocks/form/FormJSFieldItemModel.d.ts +18 -0
- package/es/flow/models/blocks/form/JSFormActionModel.d.ts +11 -0
- package/es/flow/models/blocks/form/QuickEditFormModel.d.ts +38 -0
- package/es/flow/models/blocks/form/assignRulesUpdateAssociationValues.d.ts +18 -0
- package/es/flow/models/blocks/form/dynamicNamePath.d.ts +19 -0
- package/es/flow/models/blocks/form/index.d.ts +21 -0
- package/es/flow/models/blocks/form/legacyDefaultValueMigration.d.ts +13 -0
- package/es/flow/models/blocks/form/submitHandler.d.ts +9 -0
- package/es/flow/models/blocks/form/submitValues.d.ts +40 -0
- package/es/flow/models/blocks/form/value-runtime/conditions.d.ts +9 -0
- package/es/flow/models/blocks/form/value-runtime/deps.d.ts +23 -0
- package/es/flow/models/blocks/form/value-runtime/form-patch.d.ts +19 -0
- package/es/flow/models/blocks/form/value-runtime/index.d.ts +11 -0
- package/es/flow/models/blocks/form/value-runtime/path.d.ts +25 -0
- package/es/flow/models/blocks/form/value-runtime/rules.d.ts +132 -0
- package/es/flow/models/blocks/form/value-runtime/runtime.d.ts +76 -0
- package/es/flow/models/blocks/form/value-runtime/types.d.ts +62 -0
- package/es/flow/models/blocks/form/value-runtime/utils.d.ts +12 -0
- package/es/flow/models/blocks/index.d.ts +15 -0
- package/es/flow/models/blocks/js-block/JSBlock.d.ts +16 -0
- package/es/flow/models/blocks/js-block/index.d.ts +9 -0
- package/es/flow/models/blocks/shared/legacyDefaultValueMigrationBase.d.ts +20 -0
- package/es/flow/models/blocks/table/JSColumnModel.d.ts +21 -0
- package/es/flow/models/blocks/table/TableActionsColumnModel.d.ts +18 -0
- package/es/flow/models/blocks/table/TableAssociationFieldGroupModel.d.ts +12 -0
- package/es/flow/models/blocks/table/TableBlockModel.d.ts +69 -0
- package/es/flow/models/blocks/table/TableColumnModel.d.ts +29 -0
- package/es/flow/models/blocks/table/TableCustomColumnModel.d.ts +12 -0
- package/es/flow/models/blocks/table/TableJSFieldItemModel.d.ts +19 -0
- package/{lib/hooks/usePlugin.d.ts → es/flow/models/blocks/table/TableSelectModel.d.ts} +6 -3
- package/es/flow/models/blocks/table/dragSort/dragSortComponents.d.ts +14 -0
- package/es/flow/models/blocks/table/dragSort/dragSortHooks.d.ts +13 -0
- package/es/flow/models/blocks/table/dragSort/dragSortSettings.d.ts +39 -0
- package/es/flow/models/blocks/table/dragSort/dragSortUtils.d.ts +37 -0
- package/es/flow/models/blocks/table/dragSort/index.d.ts +12 -0
- package/es/flow/models/blocks/table/index.d.ts +16 -0
- package/es/flow/models/blocks/table/sortUtils.d.ts +32 -0
- package/es/flow/models/blocks/table/utils.d.ts +18 -0
- package/es/flow/models/blocks/utils/transformChildrenToJS.d.ts +42 -0
- package/es/flow/models/fields/AssociationFieldModel/AssociationFieldModel.d.ts +5 -0
- package/es/flow/models/fields/AssociationFieldModel/CascadeSelectFieldModel.d.ts +45 -0
- package/es/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableActionGroupModel.d.ts +11 -0
- package/es/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableActionsColumnModel.d.ts +19 -0
- package/es/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.d.ts +30 -0
- package/es/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/PopupSubTableEditActionModel.d.ts +29 -0
- package/es/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/PopupSubTableFormSubmitActionModel.d.ts +18 -0
- package/es/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/PopupSubTableRemoveActionModel.d.ts +14 -0
- package/es/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/popupSubTableBeforeClose.d.ts +25 -0
- package/es/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/blocks/PopupSubTableFormModel.d.ts +36 -0
- package/es/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/index.d.ts +17 -0
- package/es/flow/models/fields/AssociationFieldModel/RecordPickerFieldModel.d.ts +45 -0
- package/es/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.d.ts +46 -0
- package/es/flow/models/fields/AssociationFieldModel/SubFormFieldModel.d.ts +32 -0
- package/es/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.d.ts +32 -0
- package/es/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableField.d.ts +10 -0
- package/es/flow/models/fields/AssociationFieldModel/SubTableFieldModel/index.d.ts +19 -0
- package/{lib/utils → es/flow/models/fields/AssociationFieldModel}/index.d.ts +7 -3
- package/es/flow/models/fields/AssociationFieldModel/itemChain.d.ts +99 -0
- package/es/flow/models/fields/AssociationFieldModel/recordSelectShared.d.ts +48 -0
- package/es/flow/models/fields/CheckboxFieldModel.d.ts +13 -0
- package/es/flow/models/fields/CheckboxGroupFieldModel.d.ts +13 -0
- package/es/flow/models/fields/ClickableFieldModel.d.ts +25 -0
- package/es/flow/models/fields/CollectionSelectorFieldModel.d.ts +13 -0
- package/es/flow/models/fields/ColorFieldModel.d.ts +14 -0
- package/es/flow/models/fields/DateTimeFieldModel/DateOnlyFieldModel.d.ts +7 -0
- package/es/flow/models/fields/DateTimeFieldModel/DateTimeFieldModel.d.ts +3 -0
- package/es/flow/models/fields/DateTimeFieldModel/DateTimeNoTzFieldModel.d.ts +6 -0
- package/es/flow/models/fields/DateTimeFieldModel/DateTimeTzFieldModel.d.ts +7 -0
- package/es/flow/models/fields/DateTimeFieldModel/index.d.ts +11 -0
- package/es/flow/models/fields/DisplayAssociationField/DisplaySubItemFieldModel.d.ts +26 -0
- package/es/flow/models/fields/DisplayAssociationField/DisplaySubListFieldModel.d.ts +26 -0
- package/es/flow/models/fields/DisplayAssociationField/DisplaySubTableFieldModel.d.ts +20 -0
- package/es/flow/models/fields/DisplayAssociationField/displaySubListUtils.d.ts +14 -0
- package/es/flow/models/fields/DisplayAssociationField/index.d.ts +11 -0
- package/es/flow/models/fields/DisplayCheckboxFieldModel.d.ts +13 -0
- package/es/flow/models/fields/DisplayColorFieldModel.d.ts +13 -0
- package/es/flow/models/fields/DisplayDateTimeFieldModel.d.ts +13 -0
- package/es/flow/models/fields/DisplayEnumFieldModel.d.ts +14 -0
- package/es/flow/models/fields/DisplayHtmlFieldModel.d.ts +13 -0
- package/es/flow/models/fields/DisplayIconFieldModel.d.ts +13 -0
- package/es/flow/models/fields/DisplayJSONFieldModel.d.ts +13 -0
- package/es/flow/models/fields/DisplayNumberFieldModel.d.ts +33 -0
- package/es/flow/models/fields/DisplayPasswordFieldModel.d.ts +13 -0
- package/es/flow/models/fields/DisplayPercentFieldModel.d.ts +13 -0
- package/es/flow/models/fields/DisplayTextFieldModel.d.ts +14 -0
- package/es/flow/models/fields/DisplayTimeFieldModel.d.ts +13 -0
- package/es/flow/models/fields/DisplayTitleFieldModel.d.ts +18 -0
- package/es/flow/models/fields/DisplayURLFieldModel.d.ts +13 -0
- package/es/flow/models/fields/DividerItemModel.d.ts +13 -0
- package/es/flow/models/fields/IconFieldModel.d.ts +13 -0
- package/es/flow/models/fields/InputFieldModel.d.ts +13 -0
- package/es/flow/models/fields/JSEditableFieldModel.d.ts +27 -0
- package/es/flow/models/fields/JSFieldModel.d.ts +45 -0
- package/es/flow/models/fields/JSItemModel.d.ts +27 -0
- package/es/flow/models/fields/JsonFieldModel.d.ts +6 -0
- package/es/flow/models/fields/MarkdownItemModel.d.ts +14 -0
- package/es/flow/models/fields/NumberFieldModel.d.ts +15 -0
- package/es/flow/models/fields/PasswordFieldModel.d.ts +13 -0
- package/es/flow/models/fields/PercentFieldModel.d.ts +14 -0
- package/es/flow/models/fields/RadioGroupFieldModel.d.ts +13 -0
- package/es/flow/models/fields/RichTextFieldModel/index.d.ts +14 -0
- package/es/flow/models/fields/RichTextFieldModel/registerFontSize.d.ts +9 -0
- package/es/flow/models/fields/RichTextFieldModel/registerImageResize.d.ts +9 -0
- package/es/flow/models/fields/RichTextFieldModel/registerSmartBreak.d.ts +12 -0
- package/es/flow/models/fields/RichTextFieldModel/style.d.ts +9 -0
- package/es/flow/models/fields/SelectFieldModel.d.ts +13 -0
- package/es/flow/models/fields/TextareaFieldModel.d.ts +13 -0
- package/es/flow/models/fields/TimeFieldModel.d.ts +5 -0
- package/es/flow/models/fields/VariableFieldFormModel.d.ts +18 -0
- package/es/flow/models/fields/index.d.ts +47 -0
- package/es/flow/models/fields/mobile-components/MobileDatePicker.d.ts +10 -0
- package/es/flow/models/fields/mobile-components/MobileLazySelect.d.ts +11 -0
- package/es/flow/models/fields/mobile-components/MobileSelect.d.ts +10 -0
- package/es/flow/models/fields/mobile-components/MobileTimePicker.d.ts +10 -0
- package/es/flow/models/index.d.ts +13 -0
- package/es/flow/models/topbar/TopbarActionModel.d.ts +114 -0
- package/es/flow/models/topbar/UserCenterTopbarActionModel.d.ts +68 -0
- package/es/flow/models/topbar/index.d.ts +10 -0
- package/es/flow/models/utils/resolveRunJsParams.d.ts +19 -0
- package/es/flow/resolveViewParamsToViewList.d.ts +20 -0
- package/es/flow/system-settings/SystemSettingsSource.d.ts +97 -0
- package/es/flow/system-settings/index.d.ts +10 -0
- package/es/flow/system-settings/useSystemSettings.d.ts +30 -0
- package/es/flow/utils/actionCapability.d.ts +60 -0
- package/es/flow/utils/blockUtils.d.ts +16 -0
- package/es/flow/utils/dispatchEventDeep.d.ts +20 -0
- package/es/flow/utils/index.d.ts +11 -0
- package/es/flow/utils/pagination.d.ts +29 -0
- package/es/flow/utils/useJsonTemplateResolver.d.ts +9 -0
- package/es/flow-compat/ColorPicker.d.ts +15 -0
- package/es/flow-compat/FieldValidation.d.ts +31 -0
- package/es/flow-compat/HighPerformanceSpin.d.ts +11 -0
- package/es/flow-compat/Icon.d.ts +10 -0
- package/es/flow-compat/IconPicker.d.ts +19 -0
- package/es/flow-compat/Password.d.ts +16 -0
- package/es/flow-compat/PasswordStrength.d.ts +16 -0
- package/es/flow-compat/Popover.d.ts +12 -0
- package/es/flow-compat/data.d.ts +15 -0
- package/es/flow-compat/date.d.ts +114 -0
- package/es/flow-compat/fieldValidationConstants.d.ts +383 -0
- package/es/flow-compat/index.d.ts +27 -0
- package/es/flow-compat/lazy.d.ts +17 -0
- package/es/flow-compat/operators.d.ts +582 -0
- package/{lib/hooks/useRouter.d.ts → es/flow-compat/passwordUtils.d.ts} +1 -1
- package/es/flow-compat/routeTypes.d.ts +56 -0
- package/es/flow-compat/useFullscreenOverlay.d.ts +20 -0
- package/es/flow-compat/zIndexContext.d.ts +12 -0
- package/es/hooks/useApp.d.ts +4 -2
- package/es/hooks/usePlugin.d.ts +2 -2
- package/es/hooks/useRouter.d.ts +1 -1
- package/es/i18n.d.ts +22 -0
- package/es/index.d.ts +19 -0
- package/es/index.mjs +1019 -0
- package/es/index.mjs.LICENSE.txt +1 -0
- package/es/locale/languageCodes.d.ts +13 -0
- package/es/nocobase-buildin-plugin/index.d.ts +24 -0
- package/es/nocobase-buildin-plugin/plugins/LocalePlugin.d.ts +15 -0
- package/es/nocobase-buildin-plugin/plugins/dayjsLocale.d.ts +76 -0
- package/es/nocobase-buildin-plugin/plugins/loadConstrueLocale.d.ts +9 -0
- package/es/settings-center/AdminSettingsLayout.d.ts +24 -0
- package/es/settings-center/AdminSettingsLayoutModel.d.ts +28 -0
- package/es/settings-center/PluginManagerPage.d.ts +17 -0
- package/es/settings-center/SystemSettingsPage.d.ts +17 -0
- package/es/settings-center/index.d.ts +13 -0
- package/es/settings-center/utils.d.ts +94 -0
- package/es/theme/AntdAppProvider.d.ts +18 -0
- package/es/theme/compatOldTheme.d.ts +11 -0
- package/es/theme/customAlgorithm.d.ts +12 -0
- package/es/theme/defaultTheme.d.ts +11 -0
- package/es/theme/index.d.ts +35 -0
- package/es/theme/type.d.ts +41 -0
- package/es/utils/index.d.ts +1 -1
- package/es/utils/remotePlugins.d.ts +6 -6
- package/lib/index.js +1019 -40
- package/lib/index.js.LICENSE.txt +1 -0
- package/lib/locale/languageCodes.js +96 -0
- package/package.json +28 -5
- package/src/Application.tsx +76 -432
- package/src/BaseApplication.tsx +648 -0
- package/src/PinnedPluginListContext.tsx +33 -0
- package/src/Plugin.ts +24 -8
- package/src/PluginManager.ts +31 -19
- package/src/PluginSettingsManager.ts +504 -100
- package/src/RouteRepository.ts +247 -0
- package/src/RouterManager.tsx +15 -16
- package/src/WebSocketClient.ts +4 -4
- package/src/__tests__/PluginSettingsManager.test.ts +228 -0
- package/src/__tests__/app.test.tsx +216 -34
- package/src/__tests__/authRedirect.test.ts +181 -0
- package/src/__tests__/dataSourceRuntime.test.tsx +34 -0
- package/src/__tests__/globalDeps.test.ts +1 -0
- package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +185 -0
- package/src/__tests__/settings-center.test.tsx +363 -0
- package/src/acl/ACLProvider.tsx +284 -0
- package/src/acl/__tests__/createAclSnippetAllow.test.ts +42 -0
- package/src/acl/createAclSnippetAllow.ts +33 -0
- package/src/acl/index.ts +12 -0
- package/src/acl/useAclSnippets.ts +25 -0
- package/src/ai/ai-manager.ts +19 -0
- package/src/ai/index.ts +13 -0
- package/src/ai/skills-manager/index.ts +10 -0
- package/src/ai/skills-manager/types.ts +26 -0
- package/src/ai/tools-manager/hooks/context.ts +20 -0
- package/src/ai/tools-manager/hooks/index.ts +22 -0
- package/src/ai/tools-manager/hooks/provider.tsx +53 -0
- package/src/ai/tools-manager/index.ts +42 -0
- package/src/ai/tools-manager/types.ts +106 -0
- package/src/ai/utils.ts +12 -0
- package/src/authRedirect.ts +297 -0
- package/src/collection-field-interface/CollectionFieldInterface.ts +200 -0
- package/src/collection-field-interface/CollectionFieldInterfaceManager.ts +177 -0
- package/src/collection-manager/interfaces/checkbox.ts +41 -0
- package/src/collection-manager/interfaces/checkboxGroup.ts +45 -0
- package/src/collection-manager/interfaces/collection.ts +53 -0
- package/src/collection-manager/interfaces/color.ts +34 -0
- package/src/collection-manager/interfaces/createdAt.ts +41 -0
- package/src/collection-manager/interfaces/createdBy.ts +80 -0
- package/src/collection-manager/interfaces/dateOnly.ts +48 -0
- package/src/collection-manager/interfaces/datetime.ts +66 -0
- package/src/collection-manager/interfaces/datetimeNoTz.ts +66 -0
- package/src/collection-manager/interfaces/email.ts +47 -0
- package/src/collection-manager/interfaces/icon.ts +31 -0
- package/src/collection-manager/interfaces/id.ts +61 -0
- package/src/collection-manager/interfaces/index.ts +51 -0
- package/src/collection-manager/interfaces/input.ts +224 -0
- package/src/collection-manager/interfaces/integer.ts +135 -0
- package/src/collection-manager/interfaces/json.tsx +74 -0
- package/src/collection-manager/interfaces/linkTo.ts +120 -0
- package/src/collection-manager/interfaces/m2m.tsx +262 -0
- package/src/collection-manager/interfaces/m2o.tsx +196 -0
- package/src/collection-manager/interfaces/markdown.ts +84 -0
- package/src/collection-manager/interfaces/multipleSelect.ts +52 -0
- package/src/collection-manager/interfaces/nanoid.ts +82 -0
- package/src/collection-manager/interfaces/number.ts +173 -0
- package/src/collection-manager/interfaces/o2m.tsx +217 -0
- package/src/collection-manager/interfaces/o2o.tsx +561 -0
- package/src/collection-manager/interfaces/password.ts +80 -0
- package/src/collection-manager/interfaces/percent.ts +178 -0
- package/src/collection-manager/interfaces/phone.ts +43 -0
- package/src/collection-manager/interfaces/properties/index.ts +582 -0
- package/src/collection-manager/interfaces/properties/operators.ts +352 -0
- package/src/collection-manager/interfaces/radioGroup.ts +37 -0
- package/src/collection-manager/interfaces/richText.ts +84 -0
- package/src/collection-manager/interfaces/select.ts +50 -0
- package/src/collection-manager/interfaces/snowflake-id.ts +61 -0
- package/src/collection-manager/interfaces/subTable.ts +218 -0
- package/src/collection-manager/interfaces/tableoid.ts +53 -0
- package/src/collection-manager/interfaces/textarea.ts +93 -0
- package/src/collection-manager/interfaces/time.ts +37 -0
- package/src/collection-manager/interfaces/types.ts +41 -0
- package/src/collection-manager/interfaces/unixTimestamp.tsx +68 -0
- package/src/collection-manager/interfaces/updatedAt.ts +41 -0
- package/src/collection-manager/interfaces/updatedBy.ts +79 -0
- package/src/collection-manager/interfaces/url.ts +48 -0
- package/src/collection-manager/interfaces/utils/index.ts +20 -0
- package/src/collection-manager/interfaces/uuid.ts +72 -0
- package/src/components/AppComponents.tsx +245 -0
- package/src/components/Icon.tsx +68 -0
- package/src/components/index.ts +2 -0
- package/src/css-variable/CSSVariableProvider.tsx +108 -0
- package/src/flow/FlowModelRepository.ts +222 -0
- package/src/flow/FlowPage.tsx +118 -0
- package/src/flow/__tests__/FlowModelRepository.test.ts +61 -0
- package/src/flow/__tests__/FlowRoute.test.tsx +474 -0
- package/src/flow/__tests__/getKey.test.ts +61 -0
- package/src/flow/__tests__/getViewDiff.test.ts +180 -0
- package/src/flow/__tests__/helpers/mockFlowApp.ts +49 -0
- package/src/flow/__tests__/resolveViewParamsToViewList.test.ts +278 -0
- package/src/flow/actions/__tests__/aclCheckRefresh.test.ts +129 -0
- package/src/flow/actions/__tests__/dataLoadingMode.test.tsx +69 -0
- package/src/flow/actions/__tests__/dataScope.leftMetaTree.test.tsx +192 -0
- package/src/flow/actions/__tests__/fieldLinkageRules.scopeDepth.test.ts +538 -0
- package/src/flow/actions/__tests__/linkageAssignField.legacy.test.ts +470 -0
- package/src/flow/actions/__tests__/linkageRules.assignFieldOptions.test.tsx +56 -0
- package/src/flow/actions/__tests__/linkageRules.runjsTemplateResolution.test.ts +71 -0
- package/src/flow/actions/__tests__/linkageRules.subFormSetFieldProps.test.ts +109 -0
- package/src/flow/actions/__tests__/linkageRulesRefresh.test.ts +164 -0
- package/src/flow/actions/__tests__/openView.beforeClose.test.tsx +263 -0
- package/src/flow/actions/__tests__/openView.closeDestroy.test.tsx +95 -0
- package/src/flow/actions/__tests__/openView.defineProps.route.test.tsx +152 -0
- package/src/flow/actions/__tests__/openView.subModelKey.test.tsx +95 -0
- package/src/flow/actions/__tests__/setTargetDataScope.leftMetaTree.test.tsx +225 -0
- package/src/flow/actions/__tests__/showMessageNotification.test.ts +79 -0
- package/src/flow/actions/__tests__/subFormFieldLinkageRules.inputArgs.test.ts +173 -0
- package/src/flow/actions/aclCheck.tsx +46 -0
- package/src/flow/actions/aclCheckRefresh.tsx +168 -0
- package/src/flow/actions/afterSuccess.tsx +138 -0
- package/src/flow/actions/blockHeight.tsx +77 -0
- package/src/flow/actions/columnFixed.tsx +35 -0
- package/src/flow/actions/confirm.tsx +63 -0
- package/src/flow/actions/customVariable.tsx +399 -0
- package/src/flow/actions/dataLoadingMode.tsx +61 -0
- package/src/flow/actions/dataScope.tsx +61 -0
- package/src/flow/actions/dateTimeFormat.tsx +188 -0
- package/src/flow/actions/displayFieldComponent.tsx +103 -0
- package/src/flow/actions/fieldComponent.tsx +114 -0
- package/src/flow/actions/filterFormDefaultValues.tsx +134 -0
- package/src/flow/actions/formAssignRules.tsx +117 -0
- package/src/flow/actions/index.ts +55 -0
- package/src/flow/actions/layout.tsx +107 -0
- package/src/flow/actions/linkageRules.tsx +2584 -0
- package/src/flow/actions/linkageRulesRefresh.tsx +82 -0
- package/src/flow/actions/navigateToURL.tsx +142 -0
- package/src/flow/actions/numberFormat.tsx +145 -0
- package/src/flow/actions/openView.tsx +512 -0
- package/src/flow/actions/overflowMode.tsx +36 -0
- package/src/flow/actions/pattern.tsx +122 -0
- package/src/flow/actions/refreshTargetBlocks.tsx +91 -0
- package/src/flow/actions/renderMode.tsx +42 -0
- package/src/flow/actions/required.tsx +70 -0
- package/src/flow/actions/runjs.tsx +48 -0
- package/src/flow/actions/setTargetDataScope.tsx +111 -0
- package/src/flow/actions/showMessage.tsx +155 -0
- package/src/flow/actions/showNotification.tsx +179 -0
- package/src/flow/actions/sortingRules.tsx +125 -0
- package/src/flow/actions/titleField.tsx +141 -0
- package/src/flow/actions/validation.tsx +77 -0
- package/src/flow/admin-shell/AdminLayoutRouteCoordinator.ts +339 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutCompat.tsx +326 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +681 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.ts +338 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuModels.tsx +774 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +964 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutModel.tsx +330 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +127 -0
- package/src/flow/admin-shell/admin-layout/HelpLite.tsx +193 -0
- package/src/flow/admin-shell/admin-layout/PinnedPluginListLite.tsx +129 -0
- package/src/flow/admin-shell/admin-layout/ResetThemeTokenAndKeepAlgorithm.tsx +30 -0
- package/src/flow/admin-shell/admin-layout/TopbarActionsBar.tsx +211 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +2023 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +284 -0
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +211 -0
- package/src/flow/admin-shell/admin-layout/__tests__/flowSettingsPreference.test.ts +44 -0
- package/src/flow/admin-shell/admin-layout/constants.ts +10 -0
- package/src/flow/admin-shell/admin-layout/flowSettingsPreference.ts +54 -0
- package/src/flow/admin-shell/admin-layout/index.ts +20 -0
- package/src/flow/admin-shell/admin-layout/mobile-layout.tsx +35 -0
- package/src/flow/admin-shell/admin-layout/mobileMenuNavigation.ts +30 -0
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.test.ts +214 -0
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.ts +260 -0
- package/src/flow/admin-shell/admin-layout/useApplications.tsx +15 -0
- package/src/flow/admin-shell/useAdminLayoutRoutePage.ts +56 -0
- package/src/flow/common/Liquid.tsx +148 -0
- package/src/flow/common/Markdown/Display.tsx +213 -0
- package/src/flow/common/Markdown/Edit.tsx +437 -0
- package/src/flow/common/Markdown/Markdown.tsx +44 -0
- package/src/flow/common/Markdown/style.ts +53 -0
- package/src/flow/common/Markdown/useCDN.ts +21 -0
- package/src/flow/components/AdminLayout.tsx +167 -0
- package/src/flow/components/BlockItemCard.tsx +204 -0
- package/src/flow/components/ConditionBuilder.tsx +40 -0
- package/src/flow/components/DefaultValue.tsx +732 -0
- package/src/flow/components/DynamicFlowsIcon.tsx +764 -0
- package/src/flow/components/EllipsisWithTooltip.tsx +106 -0
- package/src/flow/components/ExpiresRadio/index.tsx +139 -0
- package/src/flow/components/FieldAssignEditor.tsx +80 -0
- package/src/flow/components/FieldAssignExactDatePicker.tsx +225 -0
- package/src/flow/components/FieldAssignRulesEditor.tsx +1013 -0
- package/src/flow/components/FieldAssignValueInput.tsx +1490 -0
- package/src/flow/components/FlowRoute.tsx +173 -0
- package/src/flow/components/Grid/index.tsx +158 -0
- package/src/flow/components/JsonEditor.tsx +53 -0
- package/src/flow/components/RunJSValueEditor.tsx +50 -0
- package/src/flow/components/SkeletonFallback.tsx +19 -0
- package/src/flow/components/TextAreaWithContextSelector.tsx +139 -0
- package/src/flow/components/__tests__/DefaultValue.test.tsx +1289 -0
- package/src/flow/components/__tests__/DynamicFlowsIcon.test.tsx +193 -0
- package/src/flow/components/__tests__/FieldAssignExactDatePicker.test.tsx +121 -0
- package/src/flow/components/__tests__/FieldAssignRulesEditor.test.tsx +758 -0
- package/src/flow/components/__tests__/FieldAssignValueInput.exactDate.test.tsx +180 -0
- package/src/flow/components/__tests__/FieldAssignValueInput.path.test.ts +298 -0
- package/src/flow/components/__tests__/fieldAssignOptions.test.ts +97 -0
- package/src/flow/components/code-editor/__tests__/SnippetsDrawer.test.tsx +51 -0
- package/src/flow/components/code-editor/__tests__/errorHelpers.test.ts +37 -0
- package/src/flow/components/code-editor/__tests__/javascriptHtmlTemplate.test.ts +101 -0
- package/src/flow/components/code-editor/__tests__/linter.test.ts +106 -0
- package/src/flow/components/code-editor/__tests__/resolveScenes.test.ts +44 -0
- package/src/flow/components/code-editor/__tests__/runjsCompletionSource.test.ts +251 -0
- package/src/flow/components/code-editor/__tests__/runjsCompletions.test.ts +245 -0
- package/src/flow/components/code-editor/__tests__/runjsDiagnostics.test.ts +233 -0
- package/src/flow/components/code-editor/__tests__/runjsLocales.test.ts +24 -0
- package/src/flow/components/code-editor/__tests__/useCodeRunner.test.tsx +273 -0
- package/src/flow/components/code-editor/core/EditorCore.tsx +216 -0
- package/src/flow/components/code-editor/core/tooltipParent.ts +28 -0
- package/src/flow/components/code-editor/errorHelpers.ts +92 -0
- package/src/flow/components/code-editor/extension/CodeEditorExtension.tsx +23 -0
- package/src/flow/components/code-editor/extension/index.ts +10 -0
- package/src/flow/components/code-editor/formatDocInfo.ts +98 -0
- package/src/flow/components/code-editor/hooks/useCodeRunner.ts +333 -0
- package/src/flow/components/code-editor/hooks/useRunJSDocCompletions.ts +41 -0
- package/src/flow/components/code-editor/htmlCompletion.ts +155 -0
- package/src/flow/components/code-editor/index.tsx +286 -0
- package/src/flow/components/code-editor/javascriptCompletion.ts +121 -0
- package/src/flow/components/code-editor/javascriptHtmlTemplate.ts +68 -0
- package/src/flow/components/code-editor/jsxCompletion.ts +244 -0
- package/src/flow/components/code-editor/linter.ts +885 -0
- package/src/flow/components/code-editor/panels/LogsPanel.tsx +68 -0
- package/src/flow/components/code-editor/panels/RightExtra.tsx +71 -0
- package/src/flow/components/code-editor/panels/SnippetsDrawer.tsx +104 -0
- package/src/flow/components/code-editor/resolveScenes.ts +38 -0
- package/src/flow/components/code-editor/runjsCompletionSource.ts +456 -0
- package/src/flow/components/code-editor/runjsCompletions.ts +306 -0
- package/src/flow/components/code-editor/runjsDiagnostics.ts +1077 -0
- package/src/flow/components/code-editor/types.ts +36 -0
- package/src/flow/components/drag-drop/Sortable.tsx +48 -0
- package/src/flow/components/drag-drop/SortableItem.tsx +28 -0
- package/src/flow/components/drag-drop/index.ts +11 -0
- package/src/flow/components/fieldAssignOptions.ts +212 -0
- package/src/flow/components/filter/FilterContainer.tsx +123 -0
- package/src/flow/components/filter/FilterGroup.tsx +320 -0
- package/src/flow/components/filter/FilterItem.tsx +144 -0
- package/src/flow/components/filter/LinkageFilterItem.tsx +511 -0
- package/src/flow/components/filter/VariableFilterItem.tsx +684 -0
- package/src/flow/components/filter/__tests__/FilterGroup.test.tsx +143 -0
- package/src/flow/components/filter/__tests__/LinkageFilterItem.metaTree.test.ts +167 -0
- package/src/flow/components/filter/__tests__/LinkageFilterItem.test.tsx +301 -0
- package/src/flow/components/filter/__tests__/VariableFilterItem.leftMetaTree.test.tsx +196 -0
- package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +406 -0
- package/src/flow/components/filter/fieldsToOptions.ts +71 -0
- package/src/flow/components/filter/index.ts +17 -0
- package/src/flow/components/index.tsx +16 -0
- package/src/flow/components/placeholders/BlockPlaceholder.tsx +68 -0
- package/src/flow/components/placeholders/FieldPlaceholder.tsx +32 -0
- package/src/flow/components/useAssociationTitleFieldSync.ts +49 -0
- package/src/flow/flows/editMarkdownFlow.tsx +143 -0
- package/src/flow/flows/openViewFlow.ts +89 -0
- package/src/flow/formily/ReactiveField.tsx +106 -0
- package/src/flow/formily/index.tsx +8 -0
- package/src/flow/getViewDiffAndUpdateHidden.tsx +86 -0
- package/src/flow/index.ts +108 -0
- package/src/flow/internal/components/Markdown/DisplayMarkdown.tsx +85 -0
- package/src/flow/internal/components/Markdown/markdown-it-plugins/mermaidPlugin.ts +85 -0
- package/src/flow/internal/components/Markdown/md.ts +24 -0
- package/src/flow/internal/components/Markdown/style.ts +165 -0
- package/src/flow/internal/components/Markdown/util.ts +45 -0
- package/src/flow/internal/constants/HeightMode.ts +14 -0
- package/src/flow/internal/index.ts +16 -0
- package/src/flow/internal/utils/__tests__/associationValueCoercion.test.ts +57 -0
- package/src/flow/internal/utils/__tests__/enumOptionsUtils.test.ts +58 -0
- package/src/flow/internal/utils/__tests__/modelUtils.test.ts +66 -0
- package/src/flow/internal/utils/__tests__/rebuildFieldSubModel.test.ts +109 -0
- package/src/flow/internal/utils/__tests__/titleFieldQuickSync.test.ts +93 -0
- package/src/flow/internal/utils/associationValueCoercion.ts +29 -0
- package/src/flow/internal/utils/dateTimeUtils.ts +53 -0
- package/src/flow/internal/utils/enumOptionsUtils.ts +66 -0
- package/src/flow/internal/utils/modelUtils.ts +158 -0
- package/src/flow/internal/utils/operatorSchemaHelper.ts +30 -0
- package/src/flow/internal/utils/rebuildFieldSubModel.ts +94 -0
- package/src/flow/internal/utils/saveStepParamsWithSubModels.ts +40 -0
- package/src/flow/internal/utils/titleFieldQuickSync.ts +95 -0
- package/src/flow/models/actions/AddChildActionModel.tsx +69 -0
- package/src/flow/models/actions/AddNewActionModel.tsx +32 -0
- package/src/flow/models/actions/BulkDeleteActionModel.tsx +61 -0
- package/src/flow/models/actions/DeleteActionModel.tsx +61 -0
- package/src/flow/models/actions/EditActionModel.tsx +31 -0
- package/src/flow/models/actions/ExpandCollapseActionModel.tsx +113 -0
- package/src/flow/models/actions/FilterActionModel.tsx +320 -0
- package/src/flow/models/actions/JSActionModel.tsx +84 -0
- package/src/flow/models/actions/JSCollectionActionModel.tsx +90 -0
- package/src/flow/models/actions/JSItemActionModel.tsx +166 -0
- package/src/flow/models/actions/JSRecordActionModel.tsx +90 -0
- package/src/flow/models/actions/LinkActionModel.tsx +198 -0
- package/src/flow/models/actions/LinkActionUtils.ts +65 -0
- package/src/flow/models/actions/PopupCollectionActionModel.tsx +25 -0
- package/src/flow/models/actions/RefreshActionModel.tsx +45 -0
- package/src/flow/models/actions/UpdateRecordActionModel.tsx +201 -0
- package/src/flow/models/actions/UpdateRecordActionUtils.ts +89 -0
- package/src/flow/models/actions/ViewActionModel.tsx +31 -0
- package/src/flow/models/actions/__tests__/AssignFormRefill.test.ts +55 -0
- package/src/flow/models/actions/__tests__/JSItemActionModel.test.tsx +85 -0
- package/src/flow/models/actions/__tests__/LinkActionModel.test.ts +110 -0
- package/src/flow/models/actions/__tests__/UpdateRecordActionModel.test.ts +72 -0
- package/src/flow/models/actions/index.ts +26 -0
- package/src/flow/models/actions/joinUrlSearch.ts +42 -0
- package/src/flow/models/base/ActionGroupModel.tsx +10 -0
- package/src/flow/models/base/ActionGroupModelCore.tsx +117 -0
- package/src/flow/models/base/ActionModel.tsx +141 -0
- package/src/flow/models/base/ActionModelCore.tsx +174 -0
- package/src/flow/models/base/AssociationFieldGroupModel.tsx +100 -0
- package/src/flow/models/base/BlockGridModel.tsx +98 -0
- package/src/flow/models/base/BlockModel.tsx +247 -0
- package/src/flow/models/base/CollectionActionModel.tsx +23 -0
- package/src/flow/models/base/CollectionBlockModel.tsx +703 -0
- package/src/flow/models/base/CommonItemModel.tsx +12 -0
- package/src/flow/models/base/DataBlockModel.tsx +41 -0
- package/src/flow/models/base/FieldModel.tsx +26 -0
- package/src/flow/models/base/FilterBlockModel.tsx +15 -0
- package/src/flow/models/base/GridModel.tsx +1053 -0
- package/src/flow/models/base/PageModel/ChildPageModel.tsx +114 -0
- package/src/flow/models/base/PageModel/MainPageModel.tsx +32 -0
- package/src/flow/models/base/PageModel/OldPageModel.tsx +97 -0
- package/src/flow/models/base/PageModel/PageModel.tsx +486 -0
- package/src/flow/models/base/PageModel/PageTabModel.tsx +259 -0
- package/src/flow/models/base/PageModel/RootPageModel.tsx +161 -0
- package/src/flow/models/base/PageModel/SubPageModel.tsx +32 -0
- package/src/flow/models/base/PageModel/__tests__/ChildPageModel.test.ts +196 -0
- package/src/flow/models/base/PageModel/__tests__/PageModel.beforeCloseGuard.test.ts +111 -0
- package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +753 -0
- package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +225 -0
- package/src/flow/models/base/PageModel/__tests__/RootPageModel.test.ts +242 -0
- package/src/flow/models/base/PageModel/closeGuard.ts +48 -0
- package/src/flow/models/base/PageModel/index.tsx +16 -0
- package/src/flow/models/base/PopupActionModel.tsx +26 -0
- package/src/flow/models/base/RecordActionModel.tsx +23 -0
- package/src/flow/models/base/RouteModel.tsx +29 -0
- package/src/flow/models/base/__tests__/ActionGroupModel.test.ts +200 -0
- package/src/flow/models/base/__tests__/BlockGridModel.newScene.test.ts +37 -0
- package/src/flow/models/base/__tests__/CollectionBlockModel.capability.test.ts +96 -0
- package/src/flow/models/base/__tests__/CollectionBlockModel.dirtyRefresh.association.test.ts +110 -0
- package/src/flow/models/base/__tests__/CollectionBlockModel.initialBeforeRenderRefresh.test.ts +131 -0
- package/src/flow/models/base/__tests__/CollectionBlockModel.newScene.associatedRecordsVisibility.test.ts +161 -0
- package/src/flow/models/base/__tests__/CollectionBlockModel.title.test.ts +95 -0
- package/src/flow/models/base/__tests__/GridModel.computeOverlayRect.test.ts +423 -0
- package/src/flow/models/base/__tests__/GridModel.dragOverlay.test.ts +129 -0
- package/src/flow/models/base/__tests__/GridModel.dragSnapshotContainer.test.ts +107 -0
- package/src/flow/models/base/__tests__/GridModel.mergeRows.test.ts +107 -0
- package/src/flow/models/base/__tests__/GridModel.recalculateGridSizes.test.ts +67 -0
- package/src/flow/models/base/__tests__/GridModel.visibleLayout.test.ts +217 -0
- package/src/flow/models/base/__tests__/transformRowsToSingleColumn.test.ts +58 -0
- package/src/flow/models/base/index.ts +26 -0
- package/src/flow/models/blocks/assign-form/AssignFormGridModel.tsx +161 -0
- package/src/flow/models/blocks/assign-form/AssignFormItemModel.tsx +409 -0
- package/src/flow/models/blocks/assign-form/AssignFormModel.tsx +96 -0
- package/src/flow/models/blocks/assign-form/index.ts +12 -0
- package/src/flow/models/blocks/details/DetailsAssociationFieldGroupModel.tsx +18 -0
- package/src/flow/models/blocks/details/DetailsBlockModel.tsx +404 -0
- package/src/flow/models/blocks/details/DetailsCustomItemModel.tsx +51 -0
- package/src/flow/models/blocks/details/DetailsGridModel.tsx +106 -0
- package/src/flow/models/blocks/details/DetailsItemModel.tsx +384 -0
- package/src/flow/models/blocks/details/DetailsJSFieldItemModel.tsx +37 -0
- package/src/flow/models/blocks/details/__tests__/DetailsBlockModel.blockHeight.test.tsx +139 -0
- package/src/flow/models/blocks/details/__tests__/DetailsBlockModel.initialPaginationChangeRefresh.test.ts +128 -0
- package/src/flow/models/blocks/details/__tests__/DetailsItemModel.value.test.ts +49 -0
- package/src/flow/models/blocks/details/index.ts +16 -0
- package/src/flow/models/blocks/details/utils.ts +67 -0
- package/src/flow/models/blocks/filter-form/FieldModelSelect.tsx +59 -0
- package/src/flow/models/blocks/filter-form/FieldOperatorSelect.tsx +109 -0
- package/src/flow/models/blocks/filter-form/FilterFormActionGroupModel.tsx +15 -0
- package/src/flow/models/blocks/filter-form/FilterFormActionModel.tsx +12 -0
- package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +334 -0
- package/src/flow/models/blocks/filter-form/FilterFormCollapseActionModel.tsx +132 -0
- package/src/flow/models/blocks/filter-form/FilterFormCustomItemModel.tsx +42 -0
- package/src/flow/models/blocks/filter-form/FilterFormGridModel.tsx +218 -0
- package/src/flow/models/blocks/filter-form/FilterFormItemModel.tsx +780 -0
- package/src/flow/models/blocks/filter-form/FilterFormJSActionModel.tsx +72 -0
- package/src/flow/models/blocks/filter-form/FilterFormResetActionModel.tsx +52 -0
- package/src/flow/models/blocks/filter-form/FilterFormSubmitActionModel.tsx +49 -0
- package/src/flow/models/blocks/filter-form/SourceCascader.tsx +137 -0
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormGridModel.onModelCreated.test.ts +247 -0
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormGridModel.toggleFormFieldsCollapse.test.ts +143 -0
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormItemModel.defineChildren.test.ts +329 -0
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormItemModel.getFilterValue.test.ts +117 -0
- package/src/flow/models/blocks/filter-form/__tests__/customFieldOperators.test.tsx +642 -0
- package/src/flow/models/blocks/filter-form/__tests__/defaultValues.wiring.test.ts +19 -0
- package/src/flow/models/blocks/filter-form/__tests__/legacyDefaultValueMigration.test.ts +107 -0
- package/src/flow/models/blocks/filter-form/__tests__/valueNormalization.test.ts +50 -0
- package/src/flow/models/blocks/filter-form/customFieldOperators.ts +225 -0
- package/src/flow/models/blocks/filter-form/fields/FieldComponentProps.tsx +474 -0
- package/src/flow/models/blocks/filter-form/fields/FilterFormCustomFieldModel.tsx +411 -0
- package/src/flow/models/blocks/filter-form/fields/FilterFormCustomRecordSelectFieldModel.tsx +543 -0
- package/src/flow/models/blocks/filter-form/fields/FilterFormFieldModel.tsx +12 -0
- package/src/flow/models/blocks/filter-form/fields/FilterFormRecordSelectFieldModel.tsx +85 -0
- package/src/flow/models/blocks/filter-form/fields/__tests__/FilterFormCustomFieldModel.recordSelect.test.tsx +633 -0
- package/src/flow/models/blocks/filter-form/fields/date-time/DateOnlyFilterFieldModel.tsx +42 -0
- package/src/flow/models/blocks/filter-form/fields/date-time/DateTimeFilterFieldModel.tsx +17 -0
- package/src/flow/models/blocks/filter-form/fields/date-time/DateTimeNoTzFilterFieldModel.tsx +30 -0
- package/src/flow/models/blocks/filter-form/fields/date-time/DateTimeTzFilterFieldModel.tsx +48 -0
- package/src/flow/models/blocks/filter-form/fields/date-time/components/DateFilterDynamicComponent.tsx +184 -0
- package/src/flow/models/blocks/filter-form/fields/date-time/components/FilterDatePicker.tsx +108 -0
- package/src/flow/models/blocks/filter-form/fields/date-time/components/FilterRangePicker.tsx +84 -0
- package/src/flow/models/blocks/filter-form/fields/date-time/components/__tests__/FilterDatePickers.test.tsx +121 -0
- package/src/flow/models/blocks/filter-form/fields/date-time/index.ts +13 -0
- package/src/flow/models/blocks/filter-form/fields/index.ts +14 -0
- package/src/flow/models/blocks/filter-form/index.ts +25 -0
- package/src/flow/models/blocks/filter-form/legacyDefaultValueMigration.ts +36 -0
- package/src/flow/models/blocks/filter-form/valueNormalization.ts +92 -0
- package/src/flow/models/blocks/filter-manager/FilterManager.ts +488 -0
- package/src/flow/models/blocks/filter-manager/__tests__/FilterManager.bindToTarget.test.ts +446 -0
- package/src/flow/models/blocks/filter-manager/__tests__/FilterManager.test.ts +627 -0
- package/src/flow/models/blocks/filter-manager/__tests__/FilterManager.unbindFromTarget.test.ts +242 -0
- package/src/flow/models/blocks/filter-manager/__tests__/getDefaultOperator.test.ts +69 -0
- package/src/flow/models/blocks/filter-manager/flow-actions/__tests__/defaultOperator.test.tsx +58 -0
- package/src/flow/models/blocks/filter-manager/flow-actions/connectFields.tsx +488 -0
- package/src/flow/models/blocks/filter-manager/flow-actions/customizeFilterRender.tsx +78 -0
- package/src/flow/models/blocks/filter-manager/flow-actions/defaultOperator.tsx +48 -0
- package/src/flow/models/blocks/filter-manager/flow-actions/index.ts +13 -0
- package/src/flow/models/blocks/filter-manager/flow-actions/operatorComponentProps.tsx +47 -0
- package/src/flow/models/blocks/filter-manager/index.ts +13 -0
- package/src/flow/models/blocks/filter-manager/utils.ts +71 -0
- package/src/flow/models/blocks/form/CreateFormModel.tsx +124 -0
- package/src/flow/models/blocks/form/EditFormModel.tsx +298 -0
- package/src/flow/models/blocks/form/FormActionGroupModel.tsx +15 -0
- package/src/flow/models/blocks/form/FormActionModel.tsx +118 -0
- package/src/flow/models/blocks/form/FormAssociationFieldGroupModel.tsx +18 -0
- package/src/flow/models/blocks/form/FormAssociationItemModel.tsx +359 -0
- package/src/flow/models/blocks/form/FormBlockModel.tsx +736 -0
- package/src/flow/models/blocks/form/FormCustomItemModel.tsx +54 -0
- package/src/flow/models/blocks/form/FormGridModel.tsx +106 -0
- package/src/flow/models/blocks/form/FormItemModel.tsx +472 -0
- package/src/flow/models/blocks/form/FormJSFieldItemModel.tsx +36 -0
- package/src/flow/models/blocks/form/JSFormActionModel.tsx +85 -0
- package/src/flow/models/blocks/form/QuickEditFormModel.tsx +280 -0
- package/src/flow/models/blocks/form/__tests__/FormBlockModel.test.tsx +813 -0
- package/src/flow/models/blocks/form/__tests__/QuickEditFormModel.quickEdit.test.ts +69 -0
- package/src/flow/models/blocks/form/__tests__/assignRulesUpdateAssociationValues.test.ts +81 -0
- package/src/flow/models/blocks/form/__tests__/dynamicNamePath.test.ts +33 -0
- package/src/flow/models/blocks/form/__tests__/legacyDefaultValueMigration.test.ts +135 -0
- package/src/flow/models/blocks/form/__tests__/submitValues.test.ts +224 -0
- package/src/flow/models/blocks/form/assignRulesUpdateAssociationValues.ts +73 -0
- package/src/flow/models/blocks/form/dynamicNamePath.ts +68 -0
- package/src/flow/models/blocks/form/index.tsx +23 -0
- package/src/flow/models/blocks/form/legacyDefaultValueMigration.ts +32 -0
- package/src/flow/models/blocks/form/submitHandler.ts +63 -0
- package/src/flow/models/blocks/form/submitValues.ts +227 -0
- package/src/flow/models/blocks/form/value-runtime/__tests__/deps.test.ts +28 -0
- package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +2977 -0
- package/src/flow/models/blocks/form/value-runtime/__tests__/subtable-nested.test.ts +102 -0
- package/src/flow/models/blocks/form/value-runtime/conditions.ts +22 -0
- package/src/flow/models/blocks/form/value-runtime/deps.ts +181 -0
- package/src/flow/models/blocks/form/value-runtime/form-patch.ts +83 -0
- package/src/flow/models/blocks/form/value-runtime/index.ts +12 -0
- package/src/flow/models/blocks/form/value-runtime/path.ts +144 -0
- package/src/flow/models/blocks/form/value-runtime/rules.ts +1878 -0
- package/src/flow/models/blocks/form/value-runtime/runtime.ts +845 -0
- package/src/flow/models/blocks/form/value-runtime/types.ts +72 -0
- package/src/flow/models/blocks/form/value-runtime/utils.ts +25 -0
- package/src/flow/models/blocks/index.ts +17 -0
- package/src/flow/models/blocks/js-block/JSBlock.tsx +180 -0
- package/src/flow/models/blocks/js-block/index.ts +10 -0
- package/src/flow/models/blocks/shared/legacyDefaultValueMigrationBase.ts +176 -0
- package/src/flow/models/blocks/table/JSColumnModel.tsx +279 -0
- package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +238 -0
- package/src/flow/models/blocks/table/TableAssociationFieldGroupModel.tsx +18 -0
- package/src/flow/models/blocks/table/TableBlockModel.tsx +1073 -0
- package/src/flow/models/blocks/table/TableColumnModel.tsx +555 -0
- package/src/flow/models/blocks/table/TableCustomColumnModel.tsx +116 -0
- package/src/flow/models/blocks/table/TableJSFieldItemModel.tsx +38 -0
- package/src/flow/models/blocks/table/TableSelectModel.tsx +75 -0
- package/src/flow/models/blocks/table/__tests__/TableActionsColumnModel.test.tsx +282 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.blockHeight.test.tsx +120 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.popupSourceId.test.ts +87 -0
- package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +72 -0
- package/src/flow/models/blocks/table/__tests__/sortUtils.test.ts +58 -0
- package/src/flow/models/blocks/table/dragSort/dragSortComponents.tsx +90 -0
- package/src/flow/models/blocks/table/dragSort/dragSortHooks.tsx +130 -0
- package/src/flow/models/blocks/table/dragSort/dragSortSettings.ts +62 -0
- package/src/flow/models/blocks/table/dragSort/dragSortUtils.ts +57 -0
- package/src/flow/models/blocks/table/dragSort/index.ts +13 -0
- package/src/flow/models/blocks/table/index.ts +18 -0
- package/src/flow/models/blocks/table/sortUtils.ts +52 -0
- package/src/flow/models/blocks/table/utils.ts +125 -0
- package/src/flow/models/blocks/utils/__tests__/transformChildrenToJS.test.ts +216 -0
- package/src/flow/models/blocks/utils/transformChildrenToJS.ts +158 -0
- package/src/flow/models/fields/AssociationFieldModel/AssociationFieldModel.tsx +47 -0
- package/src/flow/models/fields/AssociationFieldModel/CascadeSelectFieldModel.tsx +822 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableActionGroupModel.tsx +19 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableActionsColumnModel.tsx +212 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +909 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/PopupSubTableEditActionModel.tsx +383 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/PopupSubTableFormSubmitActionModel.tsx +121 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/PopupSubTableRemoveActionModel.tsx +101 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/__tests__/popupSubTableBeforeClose.test.ts +98 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/popupSubTableBeforeClose.ts +158 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/blocks/PopupSubTableFormModel.tsx +235 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/index.tsx +18 -0
- package/src/flow/models/fields/AssociationFieldModel/RecordPickerFieldModel.tsx +514 -0
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +1005 -0
- package/src/flow/models/fields/AssociationFieldModel/SubFormFieldModel.tsx +649 -0
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.tsx +857 -0
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableField.tsx +235 -0
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/index.tsx +395 -0
- package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordPickerFieldModel.itemContext.test.ts +248 -0
- package/src/flow/models/fields/AssociationFieldModel/__tests__/recordSelectShared.fieldNames.test.ts +60 -0
- package/src/flow/models/fields/AssociationFieldModel/index.tsx +16 -0
- package/src/flow/models/fields/AssociationFieldModel/itemChain.ts +362 -0
- package/src/flow/models/fields/AssociationFieldModel/recordSelectShared.tsx +283 -0
- package/src/flow/models/fields/CheckboxFieldModel.tsx +31 -0
- package/src/flow/models/fields/CheckboxGroupFieldModel.tsx +25 -0
- package/src/flow/models/fields/ClickableFieldModel.tsx +286 -0
- package/src/flow/models/fields/CollectionSelectorFieldModel.tsx +94 -0
- package/src/flow/models/fields/ColorFieldModel.tsx +61 -0
- package/src/flow/models/fields/DateTimeFieldModel/DateOnlyFieldModel.tsx +61 -0
- package/src/flow/models/fields/DateTimeFieldModel/DateTimeFieldModel.tsx +26 -0
- package/src/flow/models/fields/DateTimeFieldModel/DateTimeNoTzFieldModel.tsx +53 -0
- package/src/flow/models/fields/DateTimeFieldModel/DateTimeTzFieldModel.tsx +96 -0
- package/src/flow/models/fields/DateTimeFieldModel/index.ts +12 -0
- package/src/flow/models/fields/DisplayAssociationField/DisplaySubItemFieldModel.tsx +70 -0
- package/src/flow/models/fields/DisplayAssociationField/DisplaySubListFieldModel.tsx +136 -0
- package/src/flow/models/fields/DisplayAssociationField/DisplaySubTableFieldModel.tsx +271 -0
- package/src/flow/models/fields/DisplayAssociationField/__tests__/DisplaySubListFieldModel.utils.test.ts +41 -0
- package/src/flow/models/fields/DisplayAssociationField/displaySubListUtils.ts +29 -0
- package/src/flow/models/fields/DisplayAssociationField/index.tsx +12 -0
- package/src/flow/models/fields/DisplayCheckboxFieldModel.tsx +36 -0
- package/src/flow/models/fields/DisplayColorFieldModel.tsx +45 -0
- package/src/flow/models/fields/DisplayDateTimeFieldModel.tsx +59 -0
- package/src/flow/models/fields/DisplayEnumFieldModel.tsx +123 -0
- package/src/flow/models/fields/DisplayHtmlFieldModel.tsx +39 -0
- package/src/flow/models/fields/DisplayIconFieldModel.tsx +24 -0
- package/src/flow/models/fields/DisplayJSONFieldModel.tsx +103 -0
- package/src/flow/models/fields/DisplayNumberFieldModel.tsx +239 -0
- package/src/flow/models/fields/DisplayPasswordFieldModel.tsx +30 -0
- package/src/flow/models/fields/DisplayPercentFieldModel.tsx +165 -0
- package/src/flow/models/fields/DisplayTextFieldModel.tsx +51 -0
- package/src/flow/models/fields/DisplayTimeFieldModel.tsx +47 -0
- package/src/flow/models/fields/DisplayTitleFieldModel.tsx +79 -0
- package/src/flow/models/fields/DisplayURLFieldModel.tsx +41 -0
- package/src/flow/models/fields/DividerItemModel.tsx +100 -0
- package/src/flow/models/fields/IconFieldModel.tsx +172 -0
- package/src/flow/models/fields/InputFieldModel.tsx +65 -0
- package/src/flow/models/fields/JSEditableFieldModel.tsx +219 -0
- package/src/flow/models/fields/JSFieldModel.tsx +184 -0
- package/src/flow/models/fields/JSItemModel.tsx +163 -0
- package/src/flow/models/fields/JsonFieldModel.tsx +121 -0
- package/src/flow/models/fields/MarkdownItemModel.tsx +68 -0
- package/src/flow/models/fields/NumberFieldModel.tsx +68 -0
- package/src/flow/models/fields/PasswordFieldModel.tsx +53 -0
- package/src/flow/models/fields/PercentFieldModel.tsx +53 -0
- package/src/flow/models/fields/RadioGroupFieldModel.tsx +26 -0
- package/src/flow/models/fields/RichTextFieldModel/index.tsx +115 -0
- package/src/flow/models/fields/RichTextFieldModel/registerFontSize.tsx +18 -0
- package/src/flow/models/fields/RichTextFieldModel/registerImageResize.tsx +56 -0
- package/src/flow/models/fields/RichTextFieldModel/registerSmartBreak.tsx +90 -0
- package/src/flow/models/fields/RichTextFieldModel/style.ts +493 -0
- package/src/flow/models/fields/SelectFieldModel.tsx +136 -0
- package/src/flow/models/fields/TextareaFieldModel.tsx +31 -0
- package/src/flow/models/fields/TimeFieldModel.tsx +66 -0
- package/src/flow/models/fields/VariableFieldFormModel.tsx +67 -0
- package/src/flow/models/fields/index.ts +52 -0
- package/src/flow/models/fields/mobile-components/MobileDatePicker.tsx +109 -0
- package/src/flow/models/fields/mobile-components/MobileLazySelect.tsx +319 -0
- package/src/flow/models/fields/mobile-components/MobileSelect.tsx +93 -0
- package/src/flow/models/fields/mobile-components/MobileTimePicker.tsx +37 -0
- package/src/flow/models/index.ts +14 -0
- package/src/flow/models/topbar/TopbarActionModel.tsx +414 -0
- package/src/flow/models/topbar/UserCenterTopbarActionModel.tsx +592 -0
- package/src/flow/models/topbar/index.ts +11 -0
- package/src/flow/models/utils/resolveRunJsParams.ts +24 -0
- package/src/flow/resolveViewParamsToViewList.tsx +79 -0
- package/src/flow/system-settings/SystemSettingsSource.ts +155 -0
- package/src/flow/system-settings/index.ts +11 -0
- package/src/flow/system-settings/useSystemSettings.tsx +51 -0
- package/src/flow/utils/__tests__/actionCapability.test.ts +79 -0
- package/src/flow/utils/__tests__/dispatchEventDeep.test.ts +72 -0
- package/src/flow/utils/__tests__/pagination.test.ts +64 -0
- package/src/flow/utils/actionCapability.ts +150 -0
- package/src/flow/utils/blockUtils.ts +32 -0
- package/src/flow/utils/dispatchEventDeep.ts +66 -0
- package/src/flow/utils/index.ts +12 -0
- package/src/flow/utils/pagination.ts +110 -0
- package/src/flow/utils/useJsonTemplateResolver.ts +25 -0
- package/src/flow-compat/ColorPicker.tsx +88 -0
- package/src/flow-compat/FieldValidation.tsx +598 -0
- package/src/flow-compat/HighPerformanceSpin.tsx +45 -0
- package/src/flow-compat/Icon.tsx +11 -0
- package/src/flow-compat/IconPicker.tsx +186 -0
- package/src/flow-compat/Password.tsx +78 -0
- package/src/flow-compat/PasswordStrength.tsx +27 -0
- package/src/flow-compat/Popover.tsx +60 -0
- package/src/flow-compat/data.ts +21 -0
- package/src/flow-compat/date.ts +116 -0
- package/src/flow-compat/fieldValidationConstants.ts +305 -0
- package/src/flow-compat/index.ts +28 -0
- package/src/flow-compat/lazy.tsx +110 -0
- package/src/flow-compat/operators.ts +367 -0
- package/src/flow-compat/passwordUtils.ts +153 -0
- package/src/flow-compat/routeTypes.ts +61 -0
- package/src/flow-compat/useFullscreenOverlay.ts +139 -0
- package/src/flow-compat/zIndexContext.tsx +28 -0
- package/src/hooks/useApp.ts +5 -3
- package/src/hooks/usePlugin.ts +2 -2
- package/src/i18n.ts +25 -0
- package/src/index.ts +20 -0
- package/src/locale/languageCodes.ts +83 -0
- package/src/nocobase-buildin-plugin/index.tsx +318 -0
- package/src/nocobase-buildin-plugin/plugins/LocalePlugin.ts +61 -0
- package/src/nocobase-buildin-plugin/plugins/dayjsLocale.ts +77 -0
- package/src/nocobase-buildin-plugin/plugins/loadConstrueLocale.ts +182 -0
- package/src/react-is.d.ts +12 -0
- package/src/settings-center/AdminSettingsLayout.tsx +333 -0
- package/src/settings-center/AdminSettingsLayoutModel.tsx +32 -0
- package/src/settings-center/PluginManagerPage.tsx +162 -0
- package/src/settings-center/SystemSettingsPage.tsx +298 -0
- package/src/settings-center/index.ts +14 -0
- package/src/settings-center/utils.tsx +277 -0
- package/src/theme/AntdAppProvider.tsx +52 -0
- package/src/theme/compatOldTheme.ts +21 -0
- package/src/theme/customAlgorithm.ts +43 -0
- package/src/theme/defaultTheme.ts +32 -0
- package/src/theme/index.tsx +104 -0
- package/src/theme/type.ts +50 -0
- package/src/utils/globalDeps.ts +3 -0
- package/src/utils/index.tsx +8 -4
- package/src/utils/remotePlugins.ts +10 -13
- package/lib/Application.d.ts +0 -124
- package/lib/Application.js +0 -499
- package/lib/MockApplication.d.ts +0 -16
- package/lib/MockApplication.js +0 -96
- package/lib/Plugin.d.ts +0 -33
- package/lib/Plugin.js +0 -89
- package/lib/PluginManager.d.ts +0 -46
- package/lib/PluginManager.js +0 -114
- package/lib/PluginSettingsManager.d.ts +0 -68
- package/lib/PluginSettingsManager.js +0 -149
- package/lib/RouterManager.d.ts +0 -69
- package/lib/RouterManager.js +0 -231
- package/lib/WebSocketClient.d.ts +0 -45
- package/lib/WebSocketClient.js +0 -217
- package/lib/components/BlankComponent.js +0 -48
- package/lib/components/MainComponent.js +0 -54
- package/lib/components/RouterBridge.js +0 -66
- package/lib/components/RouterContextCleaner.js +0 -61
- package/lib/components/index.js +0 -32
- package/lib/context.js +0 -38
- package/lib/hooks/index.js +0 -34
- package/lib/hooks/useApp.js +0 -41
- package/lib/hooks/usePlugin.js +0 -42
- package/lib/hooks/useRouter.js +0 -41
- package/lib/utils/globalDeps.js +0 -82
- package/lib/utils/index.js +0 -79
- package/lib/utils/remotePlugins.d.ts +0 -44
- package/lib/utils/remotePlugins.js +0 -131
- package/lib/utils/requirejs.js +0 -1361
- package/lib/utils/types.d.ts +0 -330
- package/lib/utils/types.js +0 -28
|
@@ -0,0 +1,2977 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
11
|
+
import { waitFor } from '@testing-library/react';
|
|
12
|
+
import { EventEmitter } from 'events';
|
|
13
|
+
import dayjs from 'dayjs';
|
|
14
|
+
import { observable } from '@formily/reactive';
|
|
15
|
+
import { get as lodashGet, merge as lodashMerge, set as lodashSet } from 'lodash';
|
|
16
|
+
import { FlowContext, JSRunner } from '@nocobase/flow-engine';
|
|
17
|
+
import { FormValueRuntime } from '..';
|
|
18
|
+
|
|
19
|
+
function createFormStub(initialValues: any = {}) {
|
|
20
|
+
const store: any = JSON.parse(JSON.stringify(initialValues || {}));
|
|
21
|
+
return {
|
|
22
|
+
__store: store,
|
|
23
|
+
getFieldValue: (namePath: any) => lodashGet(store, namePath),
|
|
24
|
+
setFieldValue: (namePath: any, value: any) => lodashSet(store, namePath, value),
|
|
25
|
+
getFieldsValue: () => JSON.parse(JSON.stringify(store)),
|
|
26
|
+
setFieldsValue: (patch: any) => lodashMerge(store, patch),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function createFieldContext(runtime: FormValueRuntime) {
|
|
31
|
+
const ctx: any = new FlowContext();
|
|
32
|
+
ctx.defineProperty('formValues', { get: () => runtime.formValues, cache: false });
|
|
33
|
+
ctx.defineProperty('app', {
|
|
34
|
+
value: {
|
|
35
|
+
jsonLogic: {
|
|
36
|
+
apply: (logic: any) => {
|
|
37
|
+
try {
|
|
38
|
+
const op = logic && typeof logic === 'object' ? Object.keys(logic)[0] : '';
|
|
39
|
+
const args = op ? (logic as any)[op] : [];
|
|
40
|
+
const left = Array.isArray(args) ? args[0] : undefined;
|
|
41
|
+
const right = Array.isArray(args) ? args[1] : undefined;
|
|
42
|
+
|
|
43
|
+
switch (op) {
|
|
44
|
+
case '$eq':
|
|
45
|
+
return left === right;
|
|
46
|
+
case '$ne':
|
|
47
|
+
return left !== right;
|
|
48
|
+
case '$gt':
|
|
49
|
+
return left > right;
|
|
50
|
+
case '$lt':
|
|
51
|
+
return left < right;
|
|
52
|
+
case '$includes':
|
|
53
|
+
return String(left ?? '').includes(String(right ?? ''));
|
|
54
|
+
case '$notIncludes':
|
|
55
|
+
return !String(left ?? '').includes(String(right ?? ''));
|
|
56
|
+
case '$empty':
|
|
57
|
+
return left == null || left === '' || (Array.isArray(left) && left.length === 0);
|
|
58
|
+
case '$notEmpty':
|
|
59
|
+
return !(left == null || left === '' || (Array.isArray(left) && left.length === 0));
|
|
60
|
+
default:
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
} catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
ctx.defineMethod('runjs', async function (this: any, code: string, variables?: Record<string, any>, options?: any) {
|
|
71
|
+
const runner = new JSRunner({ globals: { ctx: this, ...(variables || {}) }, timeoutMs: options?.timeoutMs });
|
|
72
|
+
return runner.run(code);
|
|
73
|
+
});
|
|
74
|
+
ctx.defineMethod('getVar', async function (this: any, varPath: string) {
|
|
75
|
+
const raw = typeof varPath === 'string' ? varPath : String(varPath ?? '');
|
|
76
|
+
const s = raw.trim();
|
|
77
|
+
if (!s) return undefined;
|
|
78
|
+
if (s !== 'ctx' && !s.startsWith('ctx.')) {
|
|
79
|
+
throw new Error(`ctx.getVar(path) expects an expression starting with "ctx.", got: "${s}"`);
|
|
80
|
+
}
|
|
81
|
+
return this.resolveJsonTemplate(`{{ ${s} }}`);
|
|
82
|
+
});
|
|
83
|
+
ctx.defineMethod('resolveJsonTemplate', async function (this: any, template: any) {
|
|
84
|
+
const resolveAny = (val: any): any => {
|
|
85
|
+
if (typeof val === 'string') {
|
|
86
|
+
if (val === '__B__') return this.formValues.b;
|
|
87
|
+
if (val === '__DYNAMIC__') {
|
|
88
|
+
const key = this.formValues.selector;
|
|
89
|
+
return this.formValues[key];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const trimmed = val.trim();
|
|
93
|
+
const match = trimmed.match(/^\{\{\s*ctx(?:\.(.+?))?\s*\}\}$/);
|
|
94
|
+
if (match) {
|
|
95
|
+
const pathString = match[1];
|
|
96
|
+
if (!pathString) return this;
|
|
97
|
+
const segs = pathString.split('.').filter(Boolean);
|
|
98
|
+
return lodashGet(this, segs);
|
|
99
|
+
}
|
|
100
|
+
return val;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (Array.isArray(val)) {
|
|
104
|
+
return val.map((v) => resolveAny(v));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (val && typeof val === 'object') {
|
|
108
|
+
const next: any = {};
|
|
109
|
+
for (const [k, v] of Object.entries(val)) {
|
|
110
|
+
next[k] = resolveAny(v);
|
|
111
|
+
}
|
|
112
|
+
return next;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return val;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
return resolveAny(template);
|
|
119
|
+
});
|
|
120
|
+
return ctx;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
describe('FormValueRuntime (default rules)', () => {
|
|
124
|
+
it('recomputes default on dependency change when current equals last default; user change disables default permanently', async () => {
|
|
125
|
+
const engineEmitter = new EventEmitter();
|
|
126
|
+
const blockEmitter = new EventEmitter();
|
|
127
|
+
const formStub = createFormStub({ b: 'X' });
|
|
128
|
+
|
|
129
|
+
const blockModel: any = {
|
|
130
|
+
uid: 'form-1',
|
|
131
|
+
flowEngine: { emitter: engineEmitter },
|
|
132
|
+
emitter: blockEmitter,
|
|
133
|
+
dispatchEvent: vi.fn(),
|
|
134
|
+
getAclActionName: () => 'create',
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
138
|
+
runtime.mount({ sync: true });
|
|
139
|
+
|
|
140
|
+
const fieldCtx = createFieldContext(runtime);
|
|
141
|
+
fieldCtx.defineProperty('blockModel', { value: blockModel });
|
|
142
|
+
fieldCtx.defineProperty('fieldPathArray', { value: ['a'] });
|
|
143
|
+
|
|
144
|
+
const fieldModel: any = {
|
|
145
|
+
uid: 'field-a',
|
|
146
|
+
context: fieldCtx,
|
|
147
|
+
props: { initialValue: '__B__' },
|
|
148
|
+
getProps: function () {
|
|
149
|
+
return this.props;
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
fieldCtx.defineProperty('model', { value: fieldModel });
|
|
153
|
+
|
|
154
|
+
engineEmitter.emit('model:mounted', { model: fieldModel });
|
|
155
|
+
|
|
156
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('X'));
|
|
157
|
+
|
|
158
|
+
// change dependency -> default updates
|
|
159
|
+
await runtime.setFormValues(fieldCtx, [{ path: ['b'], value: 'Y' }], { source: 'user' });
|
|
160
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('Y'));
|
|
161
|
+
|
|
162
|
+
// user changes target -> default should be disabled permanently
|
|
163
|
+
await runtime.setFormValues(fieldCtx, [{ path: ['a'], value: 'user' }], { source: 'user' });
|
|
164
|
+
await runtime.setFormValues(fieldCtx, [{ path: ['b'], value: 'Z' }], { source: 'user' });
|
|
165
|
+
expect(formStub.getFieldValue(['a'])).toBe('user');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('handles onFieldsChange name as string and triggers default recompute', async () => {
|
|
169
|
+
const engineEmitter = new EventEmitter();
|
|
170
|
+
const blockEmitter = new EventEmitter();
|
|
171
|
+
const formStub = createFormStub({ b: 'X' });
|
|
172
|
+
|
|
173
|
+
const blockModel: any = {
|
|
174
|
+
uid: 'form-3',
|
|
175
|
+
flowEngine: { emitter: engineEmitter },
|
|
176
|
+
emitter: blockEmitter,
|
|
177
|
+
dispatchEvent: vi.fn(),
|
|
178
|
+
getAclActionName: () => 'create',
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
182
|
+
runtime.mount({ sync: true });
|
|
183
|
+
|
|
184
|
+
const fieldCtx = createFieldContext(runtime);
|
|
185
|
+
fieldCtx.defineProperty('blockModel', { value: blockModel });
|
|
186
|
+
fieldCtx.defineProperty('fieldPathArray', { value: ['a'] });
|
|
187
|
+
|
|
188
|
+
const fieldModel: any = {
|
|
189
|
+
uid: 'field-a3',
|
|
190
|
+
context: fieldCtx,
|
|
191
|
+
props: { initialValue: '__B__' },
|
|
192
|
+
getProps: function () {
|
|
193
|
+
return this.props;
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
fieldCtx.defineProperty('model', { value: fieldModel });
|
|
197
|
+
|
|
198
|
+
engineEmitter.emit('model:mounted', { model: fieldModel });
|
|
199
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('X'));
|
|
200
|
+
|
|
201
|
+
// 模拟 antd onFieldsChange: name 可能是 string
|
|
202
|
+
lodashSet((formStub as any).__store, ['b'], 'Y');
|
|
203
|
+
runtime.handleFormFieldsChange([{ name: 'b', touched: true } as any]);
|
|
204
|
+
|
|
205
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('Y'));
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('patched form.setFieldsValue replaces top-level array fields instead of merging stale rows', async () => {
|
|
209
|
+
const engineEmitter = new EventEmitter();
|
|
210
|
+
const blockEmitter = new EventEmitter();
|
|
211
|
+
const formStub = createFormStub({ users: [{ id: 1 }, { id: 2 }, { id: 3 }] });
|
|
212
|
+
|
|
213
|
+
const blockModel: any = {
|
|
214
|
+
uid: 'form-set-fields-value-array-replace',
|
|
215
|
+
flowEngine: { emitter: engineEmitter },
|
|
216
|
+
emitter: blockEmitter,
|
|
217
|
+
dispatchEvent: vi.fn(),
|
|
218
|
+
getAclActionName: () => 'create',
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
222
|
+
runtime.mount({ sync: true });
|
|
223
|
+
|
|
224
|
+
formStub.setFieldsValue({ users: [] });
|
|
225
|
+
formStub.setFieldsValue({ users: [{ id: 'A' }, { id: 'B' }] });
|
|
226
|
+
|
|
227
|
+
await waitFor(() => {
|
|
228
|
+
expect(formStub.getFieldValue(['users'])).toEqual([{ id: 'A' }, { id: 'B' }]);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('tracks dynamic deps (formValues[selector]) and updates subscriptions', async () => {
|
|
233
|
+
const engineEmitter = new EventEmitter();
|
|
234
|
+
const blockEmitter = new EventEmitter();
|
|
235
|
+
const formStub = createFormStub({ selector: 'x', x: 1, y: 2 });
|
|
236
|
+
|
|
237
|
+
const blockModel: any = {
|
|
238
|
+
uid: 'form-2',
|
|
239
|
+
flowEngine: { emitter: engineEmitter },
|
|
240
|
+
emitter: blockEmitter,
|
|
241
|
+
dispatchEvent: vi.fn(),
|
|
242
|
+
getAclActionName: () => 'create',
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
246
|
+
runtime.mount({ sync: true });
|
|
247
|
+
|
|
248
|
+
const fieldCtx = createFieldContext(runtime);
|
|
249
|
+
fieldCtx.defineProperty('blockModel', { value: blockModel });
|
|
250
|
+
fieldCtx.defineProperty('fieldPathArray', { value: ['a'] });
|
|
251
|
+
|
|
252
|
+
const fieldModel: any = {
|
|
253
|
+
uid: 'field-a2',
|
|
254
|
+
context: fieldCtx,
|
|
255
|
+
props: { initialValue: '__DYNAMIC__' },
|
|
256
|
+
getProps: function () {
|
|
257
|
+
return this.props;
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
fieldCtx.defineProperty('model', { value: fieldModel });
|
|
261
|
+
|
|
262
|
+
engineEmitter.emit('model:mounted', { model: fieldModel });
|
|
263
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe(1));
|
|
264
|
+
|
|
265
|
+
// subscribed to x
|
|
266
|
+
await runtime.setFormValues(fieldCtx, [{ path: ['x'], value: 10 }], { source: 'user' });
|
|
267
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe(10));
|
|
268
|
+
|
|
269
|
+
// selector changes -> deps should shift to y
|
|
270
|
+
await runtime.setFormValues(fieldCtx, [{ path: ['selector'], value: 'y' }], { source: 'user' });
|
|
271
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe(2));
|
|
272
|
+
|
|
273
|
+
// x changes should no longer affect a
|
|
274
|
+
await runtime.setFormValues(fieldCtx, [{ path: ['x'], value: 20 }], { source: 'user' });
|
|
275
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
276
|
+
expect(formStub.getFieldValue(['a'])).toBe(2);
|
|
277
|
+
|
|
278
|
+
// y changes should update a
|
|
279
|
+
await runtime.setFormValues(fieldCtx, [{ path: ['y'], value: 30 }], { source: 'user' });
|
|
280
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe(30));
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
describe('FormValueRuntime (form assign rules)', () => {
|
|
285
|
+
it('migrates block-level rule to field instance on mount and restores on unmount', async () => {
|
|
286
|
+
const engineEmitter = new EventEmitter();
|
|
287
|
+
const blockEmitter = new EventEmitter();
|
|
288
|
+
const formStub = createFormStub({ b: 'X' });
|
|
289
|
+
|
|
290
|
+
const blockModel: any = {
|
|
291
|
+
uid: 'form-assign-migrate-1',
|
|
292
|
+
flowEngine: { emitter: engineEmitter },
|
|
293
|
+
emitter: blockEmitter,
|
|
294
|
+
dispatchEvent: vi.fn(),
|
|
295
|
+
getAclActionName: () => 'create',
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
299
|
+
runtime.mount({ sync: true });
|
|
300
|
+
|
|
301
|
+
const blockCtx = createFieldContext(runtime);
|
|
302
|
+
blockModel.context = blockCtx;
|
|
303
|
+
|
|
304
|
+
runtime.syncAssignRules([
|
|
305
|
+
{
|
|
306
|
+
key: 'r1',
|
|
307
|
+
enable: true,
|
|
308
|
+
targetPath: 'a',
|
|
309
|
+
mode: 'assign',
|
|
310
|
+
condition: { logic: '$and', items: [] },
|
|
311
|
+
value: '__B__',
|
|
312
|
+
},
|
|
313
|
+
]);
|
|
314
|
+
|
|
315
|
+
const ruleEngine: any = (runtime as any).ruleEngine;
|
|
316
|
+
const rules: Map<string, any> = ruleEngine.rules;
|
|
317
|
+
const blockId = 'form-assign:r1:block';
|
|
318
|
+
expect(rules.has(blockId)).toBe(true);
|
|
319
|
+
|
|
320
|
+
const fieldCtx = createFieldContext(runtime);
|
|
321
|
+
fieldCtx.defineProperty('blockModel', { value: blockModel });
|
|
322
|
+
|
|
323
|
+
const fieldModel: any = {
|
|
324
|
+
uid: 'field-a-migrate-1',
|
|
325
|
+
subModels: { field: {} },
|
|
326
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
327
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
328
|
+
return { fieldPath: 'a' };
|
|
329
|
+
}
|
|
330
|
+
return undefined;
|
|
331
|
+
},
|
|
332
|
+
};
|
|
333
|
+
fieldCtx.defineProperty('model', { value: fieldModel });
|
|
334
|
+
fieldModel.context = fieldCtx;
|
|
335
|
+
|
|
336
|
+
engineEmitter.emit('model:mounted', { model: fieldModel });
|
|
337
|
+
|
|
338
|
+
const instanceId = 'form-assign:r1:field-a-migrate-1:master';
|
|
339
|
+
expect(rules.has(blockId)).toBe(false);
|
|
340
|
+
expect(rules.has(instanceId)).toBe(true);
|
|
341
|
+
|
|
342
|
+
engineEmitter.emit('model:unmounted', { model: fieldModel });
|
|
343
|
+
|
|
344
|
+
expect(rules.has(instanceId)).toBe(false);
|
|
345
|
+
expect(rules.has(blockId)).toBe(true);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('normalizes date-only value for unixTimestamp target to start-of-day datetime', async () => {
|
|
349
|
+
const engineEmitter = new EventEmitter();
|
|
350
|
+
const blockEmitter = new EventEmitter();
|
|
351
|
+
const formStub = createFormStub({});
|
|
352
|
+
|
|
353
|
+
const blockModel: any = {
|
|
354
|
+
uid: 'form-assign-unix-ts-1',
|
|
355
|
+
flowEngine: { emitter: engineEmitter },
|
|
356
|
+
emitter: blockEmitter,
|
|
357
|
+
dispatchEvent: vi.fn(),
|
|
358
|
+
getAclActionName: () => 'create',
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
362
|
+
runtime.mount({ sync: true });
|
|
363
|
+
|
|
364
|
+
const blockCtx = createFieldContext(runtime);
|
|
365
|
+
blockModel.context = blockCtx;
|
|
366
|
+
|
|
367
|
+
runtime.syncAssignRules([
|
|
368
|
+
{
|
|
369
|
+
key: 'r1',
|
|
370
|
+
enable: true,
|
|
371
|
+
targetPath: 'a',
|
|
372
|
+
mode: 'assign',
|
|
373
|
+
condition: { logic: '$and', items: [] },
|
|
374
|
+
value: '2026-02-12',
|
|
375
|
+
},
|
|
376
|
+
]);
|
|
377
|
+
|
|
378
|
+
const fieldCtx = createFieldContext(runtime);
|
|
379
|
+
fieldCtx.defineProperty('blockModel', { value: blockModel });
|
|
380
|
+
fieldCtx.defineProperty('collectionField', { value: { interface: 'unixTimestamp' } });
|
|
381
|
+
|
|
382
|
+
const fieldModel: any = {
|
|
383
|
+
uid: 'field-a-unix-ts-1',
|
|
384
|
+
subModels: { field: {} },
|
|
385
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
386
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
387
|
+
return { fieldPath: 'a' };
|
|
388
|
+
}
|
|
389
|
+
return undefined;
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
fieldCtx.defineProperty('model', { value: fieldModel });
|
|
393
|
+
fieldModel.context = fieldCtx;
|
|
394
|
+
|
|
395
|
+
engineEmitter.emit('model:mounted', { model: fieldModel });
|
|
396
|
+
|
|
397
|
+
await waitFor(() => {
|
|
398
|
+
const assigned = formStub.getFieldValue(['a']);
|
|
399
|
+
expect(typeof assigned).toBe('string');
|
|
400
|
+
expect(assigned).not.toBe('2026-02-12');
|
|
401
|
+
expect(dayjs(assigned).isValid()).toBe(true);
|
|
402
|
+
expect(dayjs(assigned).format('YYYY-MM-DD')).toBe('2026-02-12');
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it('supports RunJSValue and updates on formValues dependency change', async () => {
|
|
407
|
+
const engineEmitter = new EventEmitter();
|
|
408
|
+
const blockEmitter = new EventEmitter();
|
|
409
|
+
const formStub = createFormStub({ b: 'X' });
|
|
410
|
+
|
|
411
|
+
const blockModel: any = {
|
|
412
|
+
uid: 'form-assign-runjs-1',
|
|
413
|
+
flowEngine: { emitter: engineEmitter },
|
|
414
|
+
emitter: blockEmitter,
|
|
415
|
+
dispatchEvent: vi.fn(),
|
|
416
|
+
getAclActionName: () => 'create',
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
420
|
+
runtime.mount({ sync: true });
|
|
421
|
+
|
|
422
|
+
const blockCtx = createFieldContext(runtime);
|
|
423
|
+
const fieldModel: any = {
|
|
424
|
+
uid: 'field-a-runjs-1',
|
|
425
|
+
context: { fieldPathArray: ['a'] },
|
|
426
|
+
};
|
|
427
|
+
blockCtx.defineProperty('engine', {
|
|
428
|
+
value: {
|
|
429
|
+
getModel: (id: string) => (id === 'field-a-runjs-1' ? fieldModel : null),
|
|
430
|
+
},
|
|
431
|
+
});
|
|
432
|
+
blockModel.context = blockCtx;
|
|
433
|
+
|
|
434
|
+
runtime.syncAssignRules([
|
|
435
|
+
{
|
|
436
|
+
key: 'r1',
|
|
437
|
+
enable: true,
|
|
438
|
+
targetPath: 'a',
|
|
439
|
+
mode: 'assign',
|
|
440
|
+
condition: { logic: '$and', items: [] },
|
|
441
|
+
value: { code: 'return ctx.formValues.b', version: 'v1' },
|
|
442
|
+
},
|
|
443
|
+
]);
|
|
444
|
+
|
|
445
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('X'));
|
|
446
|
+
|
|
447
|
+
await runtime.setFormValues(blockCtx, [{ path: ['b'], value: 'Y' }], { source: 'user' });
|
|
448
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('Y'));
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it('supports RunJSValue and tracks ctx var deps from code', async () => {
|
|
452
|
+
const engineEmitter = new EventEmitter();
|
|
453
|
+
const blockEmitter = new EventEmitter();
|
|
454
|
+
const formStub = createFormStub({});
|
|
455
|
+
|
|
456
|
+
const blockModel: any = {
|
|
457
|
+
uid: 'form-assign-runjs-ctx',
|
|
458
|
+
flowEngine: { emitter: engineEmitter },
|
|
459
|
+
emitter: blockEmitter,
|
|
460
|
+
dispatchEvent: vi.fn(),
|
|
461
|
+
getAclActionName: () => 'create',
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
465
|
+
runtime.mount({ sync: true });
|
|
466
|
+
|
|
467
|
+
const store = observable({ someVar: 'X' });
|
|
468
|
+
|
|
469
|
+
const blockCtx = createFieldContext(runtime);
|
|
470
|
+
blockCtx.defineProperty('someVar', { get: () => store.someVar, cache: false });
|
|
471
|
+
|
|
472
|
+
const fieldModel: any = {
|
|
473
|
+
uid: 'field-a-runjs-ctx',
|
|
474
|
+
context: { fieldPathArray: ['a'] },
|
|
475
|
+
};
|
|
476
|
+
blockCtx.defineProperty('engine', {
|
|
477
|
+
value: {
|
|
478
|
+
getModel: (id: string) => (id === 'field-a-runjs-ctx' ? fieldModel : null),
|
|
479
|
+
},
|
|
480
|
+
});
|
|
481
|
+
blockModel.context = blockCtx;
|
|
482
|
+
|
|
483
|
+
runtime.syncAssignRules([
|
|
484
|
+
{
|
|
485
|
+
key: 'r1',
|
|
486
|
+
enable: true,
|
|
487
|
+
targetPath: 'a',
|
|
488
|
+
mode: 'assign',
|
|
489
|
+
condition: { logic: '$and', items: [] },
|
|
490
|
+
value: { code: 'return ctx.someVar', version: 'v1' },
|
|
491
|
+
},
|
|
492
|
+
]);
|
|
493
|
+
|
|
494
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('X'));
|
|
495
|
+
|
|
496
|
+
store.someVar = 'Y';
|
|
497
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('Y'));
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it('does not write when RunJS execution fails', async () => {
|
|
501
|
+
const engineEmitter = new EventEmitter();
|
|
502
|
+
const blockEmitter = new EventEmitter();
|
|
503
|
+
const formStub = createFormStub({ a: 'INIT' });
|
|
504
|
+
|
|
505
|
+
const blockModel: any = {
|
|
506
|
+
uid: 'form-assign-runjs-error',
|
|
507
|
+
flowEngine: { emitter: engineEmitter },
|
|
508
|
+
emitter: blockEmitter,
|
|
509
|
+
dispatchEvent: vi.fn(),
|
|
510
|
+
getAclActionName: () => 'create',
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
514
|
+
runtime.mount({ sync: true });
|
|
515
|
+
|
|
516
|
+
const blockCtx = createFieldContext(runtime);
|
|
517
|
+
const fieldModel: any = {
|
|
518
|
+
uid: 'field-a-runjs-error',
|
|
519
|
+
context: { fieldPathArray: ['a'] },
|
|
520
|
+
};
|
|
521
|
+
blockCtx.defineProperty('engine', {
|
|
522
|
+
value: {
|
|
523
|
+
getModel: (id: string) => (id === 'field-a-runjs-error' ? fieldModel : null),
|
|
524
|
+
},
|
|
525
|
+
});
|
|
526
|
+
blockModel.context = blockCtx;
|
|
527
|
+
|
|
528
|
+
runtime.syncAssignRules([
|
|
529
|
+
{
|
|
530
|
+
key: 'r1',
|
|
531
|
+
enable: true,
|
|
532
|
+
targetPath: 'a',
|
|
533
|
+
mode: 'assign',
|
|
534
|
+
condition: { logic: '$and', items: [] },
|
|
535
|
+
value: { code: 'throw new Error("bad")', version: 'v1' },
|
|
536
|
+
},
|
|
537
|
+
]);
|
|
538
|
+
|
|
539
|
+
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
540
|
+
expect(formStub.getFieldValue(['a'])).toBe('INIT');
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
it('mode=assign keeps overriding after user change', async () => {
|
|
544
|
+
const engineEmitter = new EventEmitter();
|
|
545
|
+
const blockEmitter = new EventEmitter();
|
|
546
|
+
const formStub = createFormStub({ b: 'X' });
|
|
547
|
+
|
|
548
|
+
const blockModel: any = {
|
|
549
|
+
uid: 'form-assign-1',
|
|
550
|
+
flowEngine: { emitter: engineEmitter },
|
|
551
|
+
emitter: blockEmitter,
|
|
552
|
+
dispatchEvent: vi.fn(),
|
|
553
|
+
getAclActionName: () => 'create',
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
557
|
+
runtime.mount({ sync: true });
|
|
558
|
+
|
|
559
|
+
const blockCtx = createFieldContext(runtime);
|
|
560
|
+
const fieldModel: any = {
|
|
561
|
+
uid: 'field-a',
|
|
562
|
+
context: { fieldPathArray: ['a'] },
|
|
563
|
+
};
|
|
564
|
+
blockCtx.defineProperty('engine', {
|
|
565
|
+
value: {
|
|
566
|
+
getModel: (id: string) => (id === 'field-a' ? fieldModel : null),
|
|
567
|
+
},
|
|
568
|
+
});
|
|
569
|
+
blockModel.context = blockCtx;
|
|
570
|
+
|
|
571
|
+
runtime.syncAssignRules([
|
|
572
|
+
{
|
|
573
|
+
key: 'r1',
|
|
574
|
+
enable: true,
|
|
575
|
+
targetPath: 'a',
|
|
576
|
+
mode: 'assign',
|
|
577
|
+
condition: { logic: '$and', items: [] },
|
|
578
|
+
value: '__B__',
|
|
579
|
+
},
|
|
580
|
+
]);
|
|
581
|
+
|
|
582
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('X'));
|
|
583
|
+
|
|
584
|
+
// user writes to target; assign rule MUST NOT stop(可能会被规则立即回写覆盖)
|
|
585
|
+
await runtime.setFormValues(blockCtx, [{ path: ['a'], value: 'user' }], { source: 'user' });
|
|
586
|
+
|
|
587
|
+
// dependency change triggers overwrite again
|
|
588
|
+
await runtime.setFormValues(blockCtx, [{ path: ['b'], value: 'Y' }], { source: 'user' });
|
|
589
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('Y'));
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
it('mode=default follows explicit semantics and stops after user change', async () => {
|
|
593
|
+
const engineEmitter = new EventEmitter();
|
|
594
|
+
const blockEmitter = new EventEmitter();
|
|
595
|
+
const formStub = createFormStub({ b: 'X' });
|
|
596
|
+
|
|
597
|
+
const blockModel: any = {
|
|
598
|
+
uid: 'form-assign-2',
|
|
599
|
+
flowEngine: { emitter: engineEmitter },
|
|
600
|
+
emitter: blockEmitter,
|
|
601
|
+
dispatchEvent: vi.fn(),
|
|
602
|
+
getAclActionName: () => 'create',
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
606
|
+
runtime.mount({ sync: true });
|
|
607
|
+
|
|
608
|
+
const blockCtx = createFieldContext(runtime);
|
|
609
|
+
const fieldModel: any = {
|
|
610
|
+
uid: 'field-a2',
|
|
611
|
+
context: { fieldPathArray: ['a'] },
|
|
612
|
+
};
|
|
613
|
+
blockCtx.defineProperty('engine', {
|
|
614
|
+
value: {
|
|
615
|
+
getModel: (id: string) => (id === 'field-a2' ? fieldModel : null),
|
|
616
|
+
},
|
|
617
|
+
});
|
|
618
|
+
blockModel.context = blockCtx;
|
|
619
|
+
|
|
620
|
+
runtime.syncAssignRules([
|
|
621
|
+
{
|
|
622
|
+
key: 'r1',
|
|
623
|
+
enable: true,
|
|
624
|
+
targetPath: 'a',
|
|
625
|
+
mode: 'default',
|
|
626
|
+
condition: { logic: '$and', items: [] },
|
|
627
|
+
value: '__B__',
|
|
628
|
+
},
|
|
629
|
+
]);
|
|
630
|
+
|
|
631
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('X'));
|
|
632
|
+
|
|
633
|
+
// user writes to target; default mode MUST stop permanently
|
|
634
|
+
await runtime.setFormValues(blockCtx, [{ path: ['a'], value: 'user' }], { source: 'user' });
|
|
635
|
+
expect(formStub.getFieldValue(['a'])).toBe('user');
|
|
636
|
+
|
|
637
|
+
await runtime.setFormValues(blockCtx, [{ path: ['b'], value: 'Y' }], { source: 'user' });
|
|
638
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
639
|
+
expect(formStub.getFieldValue(['a'])).toBe('user');
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
it('reapplies mode=default value after form reset starts a new create session', async () => {
|
|
643
|
+
const engineEmitter = new EventEmitter();
|
|
644
|
+
const blockEmitter = new EventEmitter();
|
|
645
|
+
const formStub = createFormStub({});
|
|
646
|
+
|
|
647
|
+
const blockModel: any = {
|
|
648
|
+
uid: 'form-assign-reset-reapply-default',
|
|
649
|
+
flowEngine: { emitter: engineEmitter },
|
|
650
|
+
emitter: blockEmitter,
|
|
651
|
+
dispatchEvent: vi.fn(),
|
|
652
|
+
getAclActionName: () => 'create',
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
656
|
+
runtime.mount({ sync: true });
|
|
657
|
+
|
|
658
|
+
const blockCtx = createFieldContext(runtime);
|
|
659
|
+
const fieldModel: any = {
|
|
660
|
+
uid: 'field-a-reset-reapply-default',
|
|
661
|
+
context: { fieldPathArray: ['a'] },
|
|
662
|
+
};
|
|
663
|
+
blockCtx.defineProperty('engine', {
|
|
664
|
+
value: {
|
|
665
|
+
getModel: (id: string) => (id === 'field-a-reset-reapply-default' ? fieldModel : null),
|
|
666
|
+
},
|
|
667
|
+
});
|
|
668
|
+
blockModel.context = blockCtx;
|
|
669
|
+
|
|
670
|
+
runtime.syncAssignRules([
|
|
671
|
+
{
|
|
672
|
+
key: 'r1',
|
|
673
|
+
enable: true,
|
|
674
|
+
targetPath: 'a',
|
|
675
|
+
mode: 'default',
|
|
676
|
+
condition: { logic: '$and', items: [] },
|
|
677
|
+
value: 'AAA',
|
|
678
|
+
},
|
|
679
|
+
]);
|
|
680
|
+
|
|
681
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('AAA'));
|
|
682
|
+
|
|
683
|
+
await runtime.setFormValues(blockCtx, [{ path: ['a'], value: 'AAA1' }], { source: 'user' });
|
|
684
|
+
expect(formStub.getFieldValue(['a'])).toBe('AAA1');
|
|
685
|
+
|
|
686
|
+
formStub.__store.a = undefined;
|
|
687
|
+
delete formStub.__store.a;
|
|
688
|
+
runtime.resetAfterFormReset();
|
|
689
|
+
|
|
690
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('AAA'));
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
it('resets valuesMirror before rescheduling default rules after form reset', async () => {
|
|
694
|
+
const engineEmitter = new EventEmitter();
|
|
695
|
+
const blockEmitter = new EventEmitter();
|
|
696
|
+
const formStub = createFormStub({ selector: 'x', x: 'AAA', y: 'BBB' });
|
|
697
|
+
|
|
698
|
+
const blockModel: any = {
|
|
699
|
+
uid: 'form-assign-reset-values-mirror',
|
|
700
|
+
flowEngine: { emitter: engineEmitter },
|
|
701
|
+
emitter: blockEmitter,
|
|
702
|
+
dispatchEvent: vi.fn(),
|
|
703
|
+
getAclActionName: () => 'create',
|
|
704
|
+
};
|
|
705
|
+
|
|
706
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
707
|
+
runtime.mount({ sync: true });
|
|
708
|
+
|
|
709
|
+
const blockCtx = createFieldContext(runtime);
|
|
710
|
+
const fieldModel: any = {
|
|
711
|
+
uid: 'field-a-reset-values-mirror',
|
|
712
|
+
context: { fieldPathArray: ['a'] },
|
|
713
|
+
};
|
|
714
|
+
blockCtx.defineProperty('engine', {
|
|
715
|
+
value: {
|
|
716
|
+
getModel: (id: string) => (id === 'field-a-reset-values-mirror' ? fieldModel : null),
|
|
717
|
+
},
|
|
718
|
+
});
|
|
719
|
+
blockModel.context = blockCtx;
|
|
720
|
+
|
|
721
|
+
runtime.syncAssignRules([
|
|
722
|
+
{
|
|
723
|
+
key: 'r1',
|
|
724
|
+
enable: true,
|
|
725
|
+
targetPath: 'a',
|
|
726
|
+
mode: 'default',
|
|
727
|
+
condition: { logic: '$and', items: [] },
|
|
728
|
+
value: '__DYNAMIC__',
|
|
729
|
+
},
|
|
730
|
+
]);
|
|
731
|
+
|
|
732
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('AAA'));
|
|
733
|
+
|
|
734
|
+
await runtime.setFormValues(blockCtx, [{ path: ['a'], value: 'AAA1' }], { source: 'user' });
|
|
735
|
+
expect(formStub.getFieldValue(['a'])).toBe('AAA1');
|
|
736
|
+
|
|
737
|
+
for (const key of Object.keys(formStub.__store)) {
|
|
738
|
+
delete formStub.__store[key];
|
|
739
|
+
}
|
|
740
|
+
runtime.resetAfterFormReset();
|
|
741
|
+
|
|
742
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
743
|
+
expect(formStub.getFieldValue(['a'])).toBeUndefined();
|
|
744
|
+
|
|
745
|
+
await runtime.setFormValues(blockCtx, [{ path: ['selector'], value: 'y' }], { source: 'user' });
|
|
746
|
+
await runtime.setFormValues(blockCtx, [{ path: ['y'], value: 'BBB2' }], { source: 'user' });
|
|
747
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('BBB2'));
|
|
748
|
+
});
|
|
749
|
+
|
|
750
|
+
it('skips mode=default form assignment in update form', async () => {
|
|
751
|
+
const engineEmitter = new EventEmitter();
|
|
752
|
+
const blockEmitter = new EventEmitter();
|
|
753
|
+
const formStub = createFormStub({ b: 'X' });
|
|
754
|
+
|
|
755
|
+
const blockModel: any = {
|
|
756
|
+
uid: 'form-assign-update-skip-default',
|
|
757
|
+
flowEngine: { emitter: engineEmitter },
|
|
758
|
+
emitter: blockEmitter,
|
|
759
|
+
dispatchEvent: vi.fn(),
|
|
760
|
+
getAclActionName: () => 'update',
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
764
|
+
runtime.mount({ sync: true });
|
|
765
|
+
|
|
766
|
+
const blockCtx = createFieldContext(runtime);
|
|
767
|
+
const fieldModel: any = {
|
|
768
|
+
uid: 'field-a-update-skip-default',
|
|
769
|
+
context: { fieldPathArray: ['a'] },
|
|
770
|
+
};
|
|
771
|
+
blockCtx.defineProperty('engine', {
|
|
772
|
+
value: {
|
|
773
|
+
getModel: (id: string) => (id === 'field-a-update-skip-default' ? fieldModel : null),
|
|
774
|
+
},
|
|
775
|
+
});
|
|
776
|
+
blockModel.context = blockCtx;
|
|
777
|
+
|
|
778
|
+
runtime.syncAssignRules([
|
|
779
|
+
{
|
|
780
|
+
key: 'r1',
|
|
781
|
+
enable: true,
|
|
782
|
+
targetPath: 'a',
|
|
783
|
+
mode: 'default',
|
|
784
|
+
condition: { logic: '$and', items: [] },
|
|
785
|
+
value: '__B__',
|
|
786
|
+
},
|
|
787
|
+
]);
|
|
788
|
+
|
|
789
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
790
|
+
expect(formStub.getFieldValue(['a'])).toBeUndefined();
|
|
791
|
+
|
|
792
|
+
await runtime.setFormValues(blockCtx, [{ path: ['b'], value: 'Y' }], { source: 'user' });
|
|
793
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
794
|
+
expect(formStub.getFieldValue(['a'])).toBeUndefined();
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
it('syncs UI props for mode=default form assignment on configured fields', async () => {
|
|
798
|
+
const engineEmitter = new EventEmitter();
|
|
799
|
+
const blockEmitter = new EventEmitter();
|
|
800
|
+
const formStub = createFormStub();
|
|
801
|
+
|
|
802
|
+
const blockModel: any = {
|
|
803
|
+
uid: 'form-assign-default-ui-sync',
|
|
804
|
+
flowEngine: { emitter: engineEmitter },
|
|
805
|
+
emitter: blockEmitter,
|
|
806
|
+
dispatchEvent: vi.fn(),
|
|
807
|
+
getAclActionName: () => 'create',
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
811
|
+
runtime.mount({ sync: true });
|
|
812
|
+
|
|
813
|
+
const blockCtx = createFieldContext(runtime);
|
|
814
|
+
blockModel.context = blockCtx;
|
|
815
|
+
|
|
816
|
+
const fieldCtx = createFieldContext(runtime);
|
|
817
|
+
fieldCtx.defineProperty('blockModel', { value: blockModel });
|
|
818
|
+
fieldCtx.defineProperty('fieldPathArray', { value: ['color'] });
|
|
819
|
+
|
|
820
|
+
const colorFieldModel: any = {
|
|
821
|
+
setProps: vi.fn(),
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
const formItemModel: any = {
|
|
825
|
+
uid: 'form-item-color-default-ui-sync',
|
|
826
|
+
context: fieldCtx,
|
|
827
|
+
subModels: { field: colorFieldModel },
|
|
828
|
+
getStepParams: (flowKey: string, stepKey: string) => {
|
|
829
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
830
|
+
return { fieldPath: 'color' };
|
|
831
|
+
}
|
|
832
|
+
return undefined;
|
|
833
|
+
},
|
|
834
|
+
setProps: vi.fn(),
|
|
835
|
+
};
|
|
836
|
+
fieldCtx.defineProperty('model', { value: formItemModel });
|
|
837
|
+
|
|
838
|
+
blockCtx.defineProperty('engine', {
|
|
839
|
+
value: {
|
|
840
|
+
forEachModel: (visit: (model: any) => void) => visit(formItemModel),
|
|
841
|
+
},
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
runtime.syncAssignRules([
|
|
845
|
+
{
|
|
846
|
+
key: 'color-default',
|
|
847
|
+
enable: true,
|
|
848
|
+
targetPath: 'color',
|
|
849
|
+
mode: 'default',
|
|
850
|
+
condition: { logic: '$and', items: [] },
|
|
851
|
+
value: '#1677FF',
|
|
852
|
+
},
|
|
853
|
+
]);
|
|
854
|
+
|
|
855
|
+
await waitFor(() => expect(formStub.getFieldValue(['color'])).toBe('#1677FF'));
|
|
856
|
+
expect(colorFieldModel.setProps).toHaveBeenCalledWith({ value: '#1677FF' });
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
it('linkage assignment takes precedence over mode=assign form assignment', async () => {
|
|
860
|
+
const engineEmitter = new EventEmitter();
|
|
861
|
+
const blockEmitter = new EventEmitter();
|
|
862
|
+
const formStub = createFormStub({ b: 'X' });
|
|
863
|
+
|
|
864
|
+
const blockModel: any = {
|
|
865
|
+
uid: 'form-assign-linkage-precedence',
|
|
866
|
+
flowEngine: { emitter: engineEmitter },
|
|
867
|
+
emitter: blockEmitter,
|
|
868
|
+
dispatchEvent: vi.fn(),
|
|
869
|
+
getAclActionName: () => 'create',
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
873
|
+
runtime.mount({ sync: true });
|
|
874
|
+
|
|
875
|
+
const blockCtx = createFieldContext(runtime);
|
|
876
|
+
blockModel.context = blockCtx;
|
|
877
|
+
|
|
878
|
+
runtime.syncAssignRules([
|
|
879
|
+
{
|
|
880
|
+
key: 'r1',
|
|
881
|
+
enable: true,
|
|
882
|
+
targetPath: 'a',
|
|
883
|
+
mode: 'assign',
|
|
884
|
+
condition: { logic: '$and', items: [] },
|
|
885
|
+
value: '__B__',
|
|
886
|
+
},
|
|
887
|
+
]);
|
|
888
|
+
|
|
889
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('X'));
|
|
890
|
+
|
|
891
|
+
// linkage writes to target; form assignment should NOT immediately write back and override
|
|
892
|
+
await runtime.setFormValues(blockCtx, [{ path: ['a'], value: 'LINK' }], { source: 'linkage' });
|
|
893
|
+
expect(formStub.getFieldValue(['a'])).toBe('LINK');
|
|
894
|
+
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
895
|
+
expect(formStub.getFieldValue(['a'])).toBe('LINK');
|
|
896
|
+
|
|
897
|
+
// dependency change should still update via form assignment (if linkage doesn't re-run)
|
|
898
|
+
await runtime.setFormValues(blockCtx, [{ path: ['b'], value: 'Y' }], { source: 'user' });
|
|
899
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('Y'));
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
it('linkage default value takes precedence over mode=default form assignment', async () => {
|
|
903
|
+
const engineEmitter = new EventEmitter();
|
|
904
|
+
const blockEmitter = new EventEmitter();
|
|
905
|
+
const formStub = createFormStub({ b: 'X' });
|
|
906
|
+
|
|
907
|
+
const blockModel: any = {
|
|
908
|
+
uid: 'form-assign-linkage-default-precedence',
|
|
909
|
+
flowEngine: { emitter: engineEmitter },
|
|
910
|
+
emitter: blockEmitter,
|
|
911
|
+
dispatchEvent: vi.fn(),
|
|
912
|
+
getAclActionName: () => 'create',
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
916
|
+
runtime.mount({ sync: true });
|
|
917
|
+
|
|
918
|
+
const blockCtx = createFieldContext(runtime);
|
|
919
|
+
blockModel.context = blockCtx;
|
|
920
|
+
|
|
921
|
+
const fieldCtx = createFieldContext(runtime);
|
|
922
|
+
fieldCtx.defineProperty('blockModel', { value: blockModel });
|
|
923
|
+
fieldCtx.defineProperty('fieldPathArray', { value: ['a'] });
|
|
924
|
+
|
|
925
|
+
const fieldModel: any = {
|
|
926
|
+
uid: 'field-a-linkage-default-precedence',
|
|
927
|
+
context: fieldCtx,
|
|
928
|
+
props: observable({ initialValue: undefined }),
|
|
929
|
+
getProps: function () {
|
|
930
|
+
return this.props;
|
|
931
|
+
},
|
|
932
|
+
};
|
|
933
|
+
fieldCtx.defineProperty('model', { value: fieldModel });
|
|
934
|
+
|
|
935
|
+
engineEmitter.emit('model:mounted', { model: fieldModel });
|
|
936
|
+
|
|
937
|
+
runtime.syncAssignRules([
|
|
938
|
+
{
|
|
939
|
+
key: 'r1',
|
|
940
|
+
enable: true,
|
|
941
|
+
targetPath: 'a',
|
|
942
|
+
mode: 'default',
|
|
943
|
+
condition: { logic: '$and', items: [] },
|
|
944
|
+
value: '__B__',
|
|
945
|
+
},
|
|
946
|
+
]);
|
|
947
|
+
|
|
948
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('X'));
|
|
949
|
+
|
|
950
|
+
// linkage writes initialValue (default semantics) and SHOULD override form assignment default
|
|
951
|
+
fieldModel.props.initialValue = '__LINK__';
|
|
952
|
+
|
|
953
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('__LINK__'));
|
|
954
|
+
|
|
955
|
+
// dependency change triggers form assignment default recompute, but linkage default still wins
|
|
956
|
+
await runtime.setFormValues(blockCtx, [{ path: ['b'], value: 'Y' }], { source: 'user' });
|
|
957
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('__LINK__'));
|
|
958
|
+
|
|
959
|
+
// linkage default removed -> form assignment default takes effect again
|
|
960
|
+
fieldModel.props.initialValue = undefined;
|
|
961
|
+
|
|
962
|
+
await runtime.setFormValues(blockCtx, [{ path: ['b'], value: 'Z' }], { source: 'user' });
|
|
963
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('Z'));
|
|
964
|
+
});
|
|
965
|
+
|
|
966
|
+
it('tracks ctx var deps and updates when ctx var changes', async () => {
|
|
967
|
+
const engineEmitter = new EventEmitter();
|
|
968
|
+
const blockEmitter = new EventEmitter();
|
|
969
|
+
const formStub = createFormStub({});
|
|
970
|
+
|
|
971
|
+
const blockModel: any = {
|
|
972
|
+
uid: 'form-assign-ctx-deps',
|
|
973
|
+
flowEngine: { emitter: engineEmitter },
|
|
974
|
+
emitter: blockEmitter,
|
|
975
|
+
dispatchEvent: vi.fn(),
|
|
976
|
+
getAclActionName: () => 'create',
|
|
977
|
+
};
|
|
978
|
+
|
|
979
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
980
|
+
runtime.mount({ sync: true });
|
|
981
|
+
|
|
982
|
+
const store = observable({ someVar: 'X' });
|
|
983
|
+
|
|
984
|
+
const blockCtx = createFieldContext(runtime);
|
|
985
|
+
blockCtx.defineProperty('someVar', { get: () => store.someVar, cache: false });
|
|
986
|
+
|
|
987
|
+
const fieldModel: any = {
|
|
988
|
+
uid: 'field-a-ctx',
|
|
989
|
+
context: { fieldPathArray: ['a'] },
|
|
990
|
+
};
|
|
991
|
+
blockCtx.defineProperty('engine', {
|
|
992
|
+
value: {
|
|
993
|
+
getModel: (id: string) => (id === 'field-a-ctx' ? fieldModel : null),
|
|
994
|
+
},
|
|
995
|
+
});
|
|
996
|
+
blockModel.context = blockCtx;
|
|
997
|
+
|
|
998
|
+
runtime.syncAssignRules([
|
|
999
|
+
{
|
|
1000
|
+
key: 'r1',
|
|
1001
|
+
enable: true,
|
|
1002
|
+
targetPath: 'a',
|
|
1003
|
+
mode: 'assign',
|
|
1004
|
+
condition: { logic: '$and', items: [] },
|
|
1005
|
+
value: '{{ ctx.someVar }}',
|
|
1006
|
+
},
|
|
1007
|
+
]);
|
|
1008
|
+
|
|
1009
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('X'));
|
|
1010
|
+
|
|
1011
|
+
store.someVar = 'Y';
|
|
1012
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('Y'));
|
|
1013
|
+
});
|
|
1014
|
+
|
|
1015
|
+
it('runs assign rule even when target model is not mounted yet', async () => {
|
|
1016
|
+
const engineEmitter = new EventEmitter();
|
|
1017
|
+
const blockEmitter = new EventEmitter();
|
|
1018
|
+
const formStub = createFormStub({ b: 'X' });
|
|
1019
|
+
|
|
1020
|
+
const blockModel: any = {
|
|
1021
|
+
uid: 'form-assign-mount',
|
|
1022
|
+
flowEngine: { emitter: engineEmitter },
|
|
1023
|
+
emitter: blockEmitter,
|
|
1024
|
+
dispatchEvent: vi.fn(),
|
|
1025
|
+
getAclActionName: () => 'create',
|
|
1026
|
+
};
|
|
1027
|
+
|
|
1028
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
1029
|
+
runtime.mount({ sync: true });
|
|
1030
|
+
|
|
1031
|
+
const blockCtx = createFieldContext(runtime);
|
|
1032
|
+
const fieldModel: any = {
|
|
1033
|
+
uid: 'field-a-mount',
|
|
1034
|
+
context: { blockModel, fieldPathArray: undefined },
|
|
1035
|
+
};
|
|
1036
|
+
blockCtx.defineProperty('engine', {
|
|
1037
|
+
value: {
|
|
1038
|
+
getModel: (id: string) => (id === 'field-a-mount' ? fieldModel : null),
|
|
1039
|
+
},
|
|
1040
|
+
});
|
|
1041
|
+
blockModel.context = blockCtx;
|
|
1042
|
+
|
|
1043
|
+
runtime.syncAssignRules([
|
|
1044
|
+
{
|
|
1045
|
+
key: 'r1',
|
|
1046
|
+
enable: true,
|
|
1047
|
+
targetPath: 'a',
|
|
1048
|
+
mode: 'assign',
|
|
1049
|
+
condition: { logic: '$and', items: [] },
|
|
1050
|
+
value: '__B__',
|
|
1051
|
+
},
|
|
1052
|
+
]);
|
|
1053
|
+
|
|
1054
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('X'));
|
|
1055
|
+
});
|
|
1056
|
+
|
|
1057
|
+
it('only exposes ctx.item under association target paths', async () => {
|
|
1058
|
+
const engineEmitter = new EventEmitter();
|
|
1059
|
+
const blockEmitter = new EventEmitter();
|
|
1060
|
+
const formStub = createFormStub({});
|
|
1061
|
+
|
|
1062
|
+
const blockModel: any = {
|
|
1063
|
+
uid: 'form-assign-item-scope',
|
|
1064
|
+
flowEngine: { emitter: engineEmitter },
|
|
1065
|
+
emitter: blockEmitter,
|
|
1066
|
+
dispatchEvent: vi.fn(),
|
|
1067
|
+
getAclActionName: () => 'create',
|
|
1068
|
+
};
|
|
1069
|
+
|
|
1070
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
1071
|
+
runtime.mount({ sync: true });
|
|
1072
|
+
|
|
1073
|
+
const blockCtx = createFieldContext(runtime);
|
|
1074
|
+
// 提供集合元信息,避免因 collection 缺失导致 item 直接为 undefined 的短路逻辑误判。
|
|
1075
|
+
blockCtx.defineProperty('collection', { value: { getField: () => null } });
|
|
1076
|
+
blockModel.context = blockCtx;
|
|
1077
|
+
|
|
1078
|
+
runtime.syncAssignRules([
|
|
1079
|
+
{
|
|
1080
|
+
key: 'r1',
|
|
1081
|
+
enable: true,
|
|
1082
|
+
targetPath: 'a',
|
|
1083
|
+
mode: 'assign',
|
|
1084
|
+
condition: { logic: '$and', items: [] },
|
|
1085
|
+
value: {
|
|
1086
|
+
code: "return typeof ctx.item === 'undefined' ? 'YES' : 'NO'",
|
|
1087
|
+
version: 'v1',
|
|
1088
|
+
},
|
|
1089
|
+
},
|
|
1090
|
+
]);
|
|
1091
|
+
|
|
1092
|
+
await waitFor(() => expect(formStub.getFieldValue(['a'])).toBe('YES'));
|
|
1093
|
+
});
|
|
1094
|
+
|
|
1095
|
+
it('supports ctx.item.index in condition for to-many subform list (fork models)', async () => {
|
|
1096
|
+
const engineEmitter = new EventEmitter();
|
|
1097
|
+
const blockEmitter = new EventEmitter();
|
|
1098
|
+
const formStub = createFormStub({ users: [{ nickname: 'A' }, { nickname: 'B' }] });
|
|
1099
|
+
|
|
1100
|
+
const blockModel: any = {
|
|
1101
|
+
uid: 'form-assign-index',
|
|
1102
|
+
flowEngine: { emitter: engineEmitter },
|
|
1103
|
+
emitter: blockEmitter,
|
|
1104
|
+
dispatchEvent: vi.fn(),
|
|
1105
|
+
getAclActionName: () => 'create',
|
|
1106
|
+
};
|
|
1107
|
+
|
|
1108
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
1109
|
+
runtime.mount({ sync: true });
|
|
1110
|
+
|
|
1111
|
+
const blockCtx = createFieldContext(runtime);
|
|
1112
|
+
// 提供集合元信息:RuleEngine 需要依赖 rootCollection 来识别对多关联并计算 ctx.item.index
|
|
1113
|
+
const userRowCollection: any = { getField: () => null };
|
|
1114
|
+
const usersField: any = { type: 'hasMany', isAssociationField: () => true, targetCollection: userRowCollection };
|
|
1115
|
+
const rootCollection: any = { getField: (name: string) => (name === 'users' ? usersField : null) };
|
|
1116
|
+
blockCtx.defineProperty('collection', { value: rootCollection });
|
|
1117
|
+
blockModel.context = blockCtx;
|
|
1118
|
+
|
|
1119
|
+
const masterModel: any = {
|
|
1120
|
+
uid: 'users.nickname',
|
|
1121
|
+
subModels: { field: {} },
|
|
1122
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1123
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1124
|
+
return { fieldPath: 'users.nickname' };
|
|
1125
|
+
}
|
|
1126
|
+
return undefined;
|
|
1127
|
+
},
|
|
1128
|
+
};
|
|
1129
|
+
const masterCtx = createFieldContext(runtime);
|
|
1130
|
+
masterCtx.defineProperty('blockModel', { value: blockModel });
|
|
1131
|
+
masterCtx.defineProperty('model', { value: masterModel });
|
|
1132
|
+
masterModel.context = masterCtx;
|
|
1133
|
+
|
|
1134
|
+
const createRowModel = (forkId: string) => {
|
|
1135
|
+
const rowModel: any = {
|
|
1136
|
+
uid: 'users.nickname',
|
|
1137
|
+
isFork: true,
|
|
1138
|
+
forkId,
|
|
1139
|
+
subModels: { field: {} },
|
|
1140
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1141
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1142
|
+
return { fieldPath: 'users.nickname' };
|
|
1143
|
+
}
|
|
1144
|
+
return undefined;
|
|
1145
|
+
},
|
|
1146
|
+
};
|
|
1147
|
+
const rowCtx = createFieldContext(runtime);
|
|
1148
|
+
rowCtx.defineProperty('blockModel', { value: blockModel });
|
|
1149
|
+
rowCtx.defineProperty('fieldIndex', { value: [forkId] });
|
|
1150
|
+
rowCtx.defineProperty('model', { value: rowModel });
|
|
1151
|
+
rowModel.context = rowCtx;
|
|
1152
|
+
return rowModel;
|
|
1153
|
+
};
|
|
1154
|
+
|
|
1155
|
+
const row0 = createRowModel('users:0');
|
|
1156
|
+
const row1 = createRowModel('users:1');
|
|
1157
|
+
|
|
1158
|
+
// 在真实 FlowEngine 中,fork models 不会出现在 engine.forEachModel 的遍历里;
|
|
1159
|
+
// 需要从 master.forks 中补齐,确保 syncAssignRules 后仍能覆盖已挂载的子表单行。
|
|
1160
|
+
masterModel.forks = new Set([row0, row1]);
|
|
1161
|
+
|
|
1162
|
+
blockCtx.defineProperty('engine', {
|
|
1163
|
+
value: {
|
|
1164
|
+
forEachModel: (cb: any) => {
|
|
1165
|
+
cb(masterModel);
|
|
1166
|
+
},
|
|
1167
|
+
},
|
|
1168
|
+
});
|
|
1169
|
+
|
|
1170
|
+
runtime.syncAssignRules([
|
|
1171
|
+
{
|
|
1172
|
+
key: 'r1',
|
|
1173
|
+
enable: true,
|
|
1174
|
+
targetPath: 'users.nickname',
|
|
1175
|
+
mode: 'assign',
|
|
1176
|
+
condition: {
|
|
1177
|
+
logic: '$and',
|
|
1178
|
+
items: [{ path: '{{ ctx.item.index }}', operator: '$eq', value: 1 }],
|
|
1179
|
+
},
|
|
1180
|
+
value: 'Z',
|
|
1181
|
+
},
|
|
1182
|
+
]);
|
|
1183
|
+
|
|
1184
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 1, 'nickname'])).toBe('Z'));
|
|
1185
|
+
expect(formStub.getFieldValue(['users', 0, 'nickname'])).toBe('A');
|
|
1186
|
+
|
|
1187
|
+
// 重新同步规则(模拟保存后生效):fork 行上的规则也应被重新注册并生效
|
|
1188
|
+
runtime.syncAssignRules([
|
|
1189
|
+
{
|
|
1190
|
+
key: 'r1',
|
|
1191
|
+
enable: true,
|
|
1192
|
+
targetPath: 'users.nickname',
|
|
1193
|
+
mode: 'assign',
|
|
1194
|
+
condition: {
|
|
1195
|
+
logic: '$and',
|
|
1196
|
+
items: [{ path: '{{ ctx.item.index }}', operator: '$eq', value: 1 }],
|
|
1197
|
+
},
|
|
1198
|
+
value: 'Q',
|
|
1199
|
+
},
|
|
1200
|
+
]);
|
|
1201
|
+
|
|
1202
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 1, 'nickname'])).toBe('Q'));
|
|
1203
|
+
});
|
|
1204
|
+
|
|
1205
|
+
it('supports ctx.item.length in condition for to-many subform list (fork models)', async () => {
|
|
1206
|
+
const engineEmitter = new EventEmitter();
|
|
1207
|
+
const blockEmitter = new EventEmitter();
|
|
1208
|
+
const formStub = createFormStub({ users: [{ nickname: 'A' }, { nickname: 'B' }] });
|
|
1209
|
+
|
|
1210
|
+
const blockModel: any = {
|
|
1211
|
+
uid: 'form-assign-length',
|
|
1212
|
+
flowEngine: { emitter: engineEmitter },
|
|
1213
|
+
emitter: blockEmitter,
|
|
1214
|
+
dispatchEvent: vi.fn(),
|
|
1215
|
+
getAclActionName: () => 'create',
|
|
1216
|
+
};
|
|
1217
|
+
|
|
1218
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
1219
|
+
runtime.mount({ sync: true });
|
|
1220
|
+
|
|
1221
|
+
const blockCtx = createFieldContext(runtime);
|
|
1222
|
+
// 提供集合元信息:RuleEngine 需要依赖 rootCollection 来识别对多关联并计算 ctx.item.length
|
|
1223
|
+
const userRowCollection: any = { getField: () => null };
|
|
1224
|
+
const usersField: any = { type: 'hasMany', isAssociationField: () => true, targetCollection: userRowCollection };
|
|
1225
|
+
const rootCollection: any = { getField: (name: string) => (name === 'users' ? usersField : null) };
|
|
1226
|
+
blockCtx.defineProperty('collection', { value: rootCollection });
|
|
1227
|
+
blockModel.context = blockCtx;
|
|
1228
|
+
|
|
1229
|
+
const masterModel: any = {
|
|
1230
|
+
uid: 'users.nickname',
|
|
1231
|
+
subModels: { field: {} },
|
|
1232
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1233
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1234
|
+
return { fieldPath: 'users.nickname' };
|
|
1235
|
+
}
|
|
1236
|
+
return undefined;
|
|
1237
|
+
},
|
|
1238
|
+
};
|
|
1239
|
+
const masterCtx = createFieldContext(runtime);
|
|
1240
|
+
masterCtx.defineProperty('blockModel', { value: blockModel });
|
|
1241
|
+
masterCtx.defineProperty('model', { value: masterModel });
|
|
1242
|
+
masterModel.context = masterCtx;
|
|
1243
|
+
|
|
1244
|
+
const createRowModel = (forkId: string) => {
|
|
1245
|
+
const rowModel: any = {
|
|
1246
|
+
uid: 'users.nickname',
|
|
1247
|
+
isFork: true,
|
|
1248
|
+
forkId,
|
|
1249
|
+
subModels: { field: {} },
|
|
1250
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1251
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1252
|
+
return { fieldPath: 'users.nickname' };
|
|
1253
|
+
}
|
|
1254
|
+
return undefined;
|
|
1255
|
+
},
|
|
1256
|
+
};
|
|
1257
|
+
const rowCtx = createFieldContext(runtime);
|
|
1258
|
+
rowCtx.defineProperty('blockModel', { value: blockModel });
|
|
1259
|
+
rowCtx.defineProperty('fieldIndex', { value: [forkId] });
|
|
1260
|
+
rowCtx.defineProperty('model', { value: rowModel });
|
|
1261
|
+
rowModel.context = rowCtx;
|
|
1262
|
+
return rowModel;
|
|
1263
|
+
};
|
|
1264
|
+
|
|
1265
|
+
const row0 = createRowModel('users:0');
|
|
1266
|
+
const row1 = createRowModel('users:1');
|
|
1267
|
+
masterModel.forks = new Set([row0, row1]);
|
|
1268
|
+
|
|
1269
|
+
blockCtx.defineProperty('engine', {
|
|
1270
|
+
value: {
|
|
1271
|
+
forEachModel: (cb: any) => {
|
|
1272
|
+
cb(masterModel);
|
|
1273
|
+
},
|
|
1274
|
+
},
|
|
1275
|
+
});
|
|
1276
|
+
|
|
1277
|
+
runtime.syncAssignRules([
|
|
1278
|
+
{
|
|
1279
|
+
key: 'r1',
|
|
1280
|
+
enable: true,
|
|
1281
|
+
targetPath: 'users.nickname',
|
|
1282
|
+
mode: 'assign',
|
|
1283
|
+
condition: {
|
|
1284
|
+
logic: '$and',
|
|
1285
|
+
items: [
|
|
1286
|
+
{ path: '{{ ctx.item.index }}', operator: '$eq', value: 1 },
|
|
1287
|
+
{ path: '{{ ctx.item.length }}', operator: '$eq', value: 2 },
|
|
1288
|
+
],
|
|
1289
|
+
},
|
|
1290
|
+
value: 'Z',
|
|
1291
|
+
},
|
|
1292
|
+
]);
|
|
1293
|
+
|
|
1294
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 1, 'nickname'])).toBe('Z'));
|
|
1295
|
+
expect(formStub.getFieldValue(['users', 0, 'nickname'])).toBe('A');
|
|
1296
|
+
});
|
|
1297
|
+
|
|
1298
|
+
it('supports ctx.item.value.* in assign rule value and updates on row value changes (to-many fork models)', async () => {
|
|
1299
|
+
const engineEmitter = new EventEmitter();
|
|
1300
|
+
const blockEmitter = new EventEmitter();
|
|
1301
|
+
const formStub = createFormStub({
|
|
1302
|
+
users: [
|
|
1303
|
+
{ nickname: 'A', display: '' },
|
|
1304
|
+
{ nickname: 'B', display: '' },
|
|
1305
|
+
],
|
|
1306
|
+
});
|
|
1307
|
+
|
|
1308
|
+
const blockModel: any = {
|
|
1309
|
+
uid: 'form-assign-item-value',
|
|
1310
|
+
flowEngine: { emitter: engineEmitter },
|
|
1311
|
+
emitter: blockEmitter,
|
|
1312
|
+
dispatchEvent: vi.fn(),
|
|
1313
|
+
getAclActionName: () => 'create',
|
|
1314
|
+
};
|
|
1315
|
+
|
|
1316
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
1317
|
+
runtime.mount({ sync: true });
|
|
1318
|
+
|
|
1319
|
+
const blockCtx = createFieldContext(runtime);
|
|
1320
|
+
// 提供集合元信息:RuleEngine 需要依赖 rootCollection 来识别对多关联并计算 ctx.item.value
|
|
1321
|
+
const userRowCollection: any = { getField: () => null };
|
|
1322
|
+
const usersField: any = { type: 'hasMany', isAssociationField: () => true, targetCollection: userRowCollection };
|
|
1323
|
+
const rootCollection: any = { getField: (name: string) => (name === 'users' ? usersField : null) };
|
|
1324
|
+
blockCtx.defineProperty('collection', { value: rootCollection });
|
|
1325
|
+
blockModel.context = blockCtx;
|
|
1326
|
+
|
|
1327
|
+
const masterModel: any = {
|
|
1328
|
+
uid: 'users.display',
|
|
1329
|
+
subModels: { field: {} },
|
|
1330
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1331
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1332
|
+
return { fieldPath: 'users.display' };
|
|
1333
|
+
}
|
|
1334
|
+
return undefined;
|
|
1335
|
+
},
|
|
1336
|
+
};
|
|
1337
|
+
const masterCtx = createFieldContext(runtime);
|
|
1338
|
+
masterCtx.defineProperty('blockModel', { value: blockModel });
|
|
1339
|
+
masterCtx.defineProperty('model', { value: masterModel });
|
|
1340
|
+
masterModel.context = masterCtx;
|
|
1341
|
+
|
|
1342
|
+
const createRowModel = (forkId: string) => {
|
|
1343
|
+
const rowModel: any = {
|
|
1344
|
+
uid: 'users.display',
|
|
1345
|
+
isFork: true,
|
|
1346
|
+
forkId,
|
|
1347
|
+
subModels: { field: {} },
|
|
1348
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1349
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1350
|
+
return { fieldPath: 'users.display' };
|
|
1351
|
+
}
|
|
1352
|
+
return undefined;
|
|
1353
|
+
},
|
|
1354
|
+
};
|
|
1355
|
+
const rowCtx = createFieldContext(runtime);
|
|
1356
|
+
rowCtx.defineProperty('blockModel', { value: blockModel });
|
|
1357
|
+
rowCtx.defineProperty('fieldIndex', { value: [forkId] });
|
|
1358
|
+
rowCtx.defineProperty('model', { value: rowModel });
|
|
1359
|
+
rowModel.context = rowCtx;
|
|
1360
|
+
return rowModel;
|
|
1361
|
+
};
|
|
1362
|
+
|
|
1363
|
+
const row0 = createRowModel('users:0');
|
|
1364
|
+
const row1 = createRowModel('users:1');
|
|
1365
|
+
masterModel.forks = new Set([row0, row1]);
|
|
1366
|
+
|
|
1367
|
+
blockCtx.defineProperty('engine', {
|
|
1368
|
+
value: {
|
|
1369
|
+
forEachModel: (cb: any) => {
|
|
1370
|
+
cb(masterModel);
|
|
1371
|
+
},
|
|
1372
|
+
},
|
|
1373
|
+
});
|
|
1374
|
+
|
|
1375
|
+
runtime.syncAssignRules([
|
|
1376
|
+
{
|
|
1377
|
+
key: 'r1',
|
|
1378
|
+
enable: true,
|
|
1379
|
+
targetPath: 'users.display',
|
|
1380
|
+
mode: 'assign',
|
|
1381
|
+
condition: { logic: '$and', items: [] },
|
|
1382
|
+
value: '{{ ctx.item.value.nickname }}',
|
|
1383
|
+
},
|
|
1384
|
+
]);
|
|
1385
|
+
|
|
1386
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 0, 'display'])).toBe('A'));
|
|
1387
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 1, 'display'])).toBe('B'));
|
|
1388
|
+
|
|
1389
|
+
await runtime.setFormValues(blockCtx, [{ path: ['users', 1, 'nickname'], value: 'C' }], { source: 'user' });
|
|
1390
|
+
|
|
1391
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 1, 'display'])).toBe('C'));
|
|
1392
|
+
expect(formStub.getFieldValue(['users', 0, 'display'])).toBe('A');
|
|
1393
|
+
});
|
|
1394
|
+
|
|
1395
|
+
it('supports ctx.getVar("ctx.item.value.*") in RunJS assign value for to-many fork models', async () => {
|
|
1396
|
+
const engineEmitter = new EventEmitter();
|
|
1397
|
+
const blockEmitter = new EventEmitter();
|
|
1398
|
+
const formStub = createFormStub({
|
|
1399
|
+
users: [
|
|
1400
|
+
{ nickname: 'A', display: '' },
|
|
1401
|
+
{ nickname: 'B', display: '' },
|
|
1402
|
+
],
|
|
1403
|
+
});
|
|
1404
|
+
|
|
1405
|
+
const blockModel: any = {
|
|
1406
|
+
uid: 'form-assign-item-getvar',
|
|
1407
|
+
flowEngine: { emitter: engineEmitter },
|
|
1408
|
+
emitter: blockEmitter,
|
|
1409
|
+
dispatchEvent: vi.fn(),
|
|
1410
|
+
getAclActionName: () => 'create',
|
|
1411
|
+
};
|
|
1412
|
+
|
|
1413
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
1414
|
+
runtime.mount({ sync: true });
|
|
1415
|
+
|
|
1416
|
+
const blockCtx = createFieldContext(runtime);
|
|
1417
|
+
const userRowCollection: any = { getField: () => null };
|
|
1418
|
+
const usersField: any = { type: 'hasMany', isAssociationField: () => true, targetCollection: userRowCollection };
|
|
1419
|
+
const rootCollection: any = { getField: (name: string) => (name === 'users' ? usersField : null) };
|
|
1420
|
+
blockCtx.defineProperty('collection', { value: rootCollection });
|
|
1421
|
+
blockModel.context = blockCtx;
|
|
1422
|
+
|
|
1423
|
+
const masterModel: any = {
|
|
1424
|
+
uid: 'users.display.getvar',
|
|
1425
|
+
subModels: { field: {} },
|
|
1426
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1427
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1428
|
+
return { fieldPath: 'users.display' };
|
|
1429
|
+
}
|
|
1430
|
+
return undefined;
|
|
1431
|
+
},
|
|
1432
|
+
};
|
|
1433
|
+
const masterCtx = createFieldContext(runtime);
|
|
1434
|
+
masterCtx.defineProperty('blockModel', { value: blockModel });
|
|
1435
|
+
masterCtx.defineProperty('model', { value: masterModel });
|
|
1436
|
+
masterModel.context = masterCtx;
|
|
1437
|
+
|
|
1438
|
+
const createRowModel = (forkId: string) => {
|
|
1439
|
+
const rowModel: any = {
|
|
1440
|
+
uid: 'users.display.getvar',
|
|
1441
|
+
isFork: true,
|
|
1442
|
+
forkId,
|
|
1443
|
+
subModels: { field: {} },
|
|
1444
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1445
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1446
|
+
return { fieldPath: 'users.display' };
|
|
1447
|
+
}
|
|
1448
|
+
return undefined;
|
|
1449
|
+
},
|
|
1450
|
+
};
|
|
1451
|
+
const rowCtx = createFieldContext(runtime);
|
|
1452
|
+
rowCtx.defineProperty('blockModel', { value: blockModel });
|
|
1453
|
+
rowCtx.defineProperty('fieldIndex', { value: [forkId] });
|
|
1454
|
+
rowCtx.defineProperty('model', { value: rowModel });
|
|
1455
|
+
rowModel.context = rowCtx;
|
|
1456
|
+
return rowModel;
|
|
1457
|
+
};
|
|
1458
|
+
|
|
1459
|
+
const row0 = createRowModel('users:0');
|
|
1460
|
+
const row1 = createRowModel('users:1');
|
|
1461
|
+
masterModel.forks = new Set([row0, row1]);
|
|
1462
|
+
|
|
1463
|
+
blockCtx.defineProperty('engine', {
|
|
1464
|
+
value: {
|
|
1465
|
+
forEachModel: (cb: any) => {
|
|
1466
|
+
cb(masterModel);
|
|
1467
|
+
},
|
|
1468
|
+
},
|
|
1469
|
+
});
|
|
1470
|
+
|
|
1471
|
+
runtime.syncAssignRules([
|
|
1472
|
+
{
|
|
1473
|
+
key: 'r-getvar-item',
|
|
1474
|
+
enable: true,
|
|
1475
|
+
targetPath: 'users.display',
|
|
1476
|
+
mode: 'assign',
|
|
1477
|
+
condition: { logic: '$and', items: [] },
|
|
1478
|
+
value: {
|
|
1479
|
+
code: `const nickname = await ctx.getVar('ctx.item.value.nickname'); return nickname;`,
|
|
1480
|
+
version: 'v2',
|
|
1481
|
+
},
|
|
1482
|
+
},
|
|
1483
|
+
]);
|
|
1484
|
+
|
|
1485
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 0, 'display'])).toBe('A'));
|
|
1486
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 1, 'display'])).toBe('B'));
|
|
1487
|
+
|
|
1488
|
+
await runtime.setFormValues(blockCtx, [{ path: ['users', 1, 'nickname'], value: 'C' }], { source: 'user' });
|
|
1489
|
+
|
|
1490
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 1, 'display'])).toBe('C'));
|
|
1491
|
+
expect(formStub.getFieldValue(['users', 0, 'display'])).toBe('A');
|
|
1492
|
+
});
|
|
1493
|
+
|
|
1494
|
+
it('skips default assign rules in update mode for existing to-many row even if list container became explicit', async () => {
|
|
1495
|
+
const engineEmitter = new EventEmitter();
|
|
1496
|
+
const blockEmitter = new EventEmitter();
|
|
1497
|
+
const formStub = createFormStub({ users: [{ name: '' }, { name: '' }] });
|
|
1498
|
+
|
|
1499
|
+
const blockModel: any = {
|
|
1500
|
+
uid: 'form-assign-default-update',
|
|
1501
|
+
flowEngine: { emitter: engineEmitter },
|
|
1502
|
+
emitter: blockEmitter,
|
|
1503
|
+
dispatchEvent: vi.fn(),
|
|
1504
|
+
getAclActionName: () => 'update',
|
|
1505
|
+
};
|
|
1506
|
+
|
|
1507
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
1508
|
+
runtime.mount({ sync: true });
|
|
1509
|
+
|
|
1510
|
+
const blockCtx = createFieldContext(runtime);
|
|
1511
|
+
// 提供集合元信息:识别对多关联,并计算 ctx.item.index
|
|
1512
|
+
const userRowCollection: any = { getField: () => null };
|
|
1513
|
+
const usersField: any = { type: 'hasMany', isAssociationField: () => true, targetCollection: userRowCollection };
|
|
1514
|
+
const rootCollection: any = { getField: (name: string) => (name === 'users' ? usersField : null) };
|
|
1515
|
+
blockCtx.defineProperty('collection', { value: rootCollection });
|
|
1516
|
+
blockModel.context = blockCtx;
|
|
1517
|
+
|
|
1518
|
+
// 模拟:用户在子表单列表中“增删项/添加行”时,外部系统会触发 users 的 onValuesChange,导致 users 被标记为 explicit。
|
|
1519
|
+
runtime.handleFormValuesChange({ users: [{ name: '' }, { name: '' }] }, formStub.getFieldsValue());
|
|
1520
|
+
|
|
1521
|
+
const masterModel: any = {
|
|
1522
|
+
uid: 'users.name',
|
|
1523
|
+
subModels: { field: {} },
|
|
1524
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1525
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1526
|
+
return { fieldPath: 'users.name' };
|
|
1527
|
+
}
|
|
1528
|
+
return undefined;
|
|
1529
|
+
},
|
|
1530
|
+
};
|
|
1531
|
+
const masterCtx = createFieldContext(runtime);
|
|
1532
|
+
masterCtx.defineProperty('blockModel', { value: blockModel });
|
|
1533
|
+
masterCtx.defineProperty('model', { value: masterModel });
|
|
1534
|
+
masterModel.context = masterCtx;
|
|
1535
|
+
|
|
1536
|
+
const createRowModel = (forkId: string, rowIndex: number, rowIsNew: boolean) => {
|
|
1537
|
+
const rowModel: any = {
|
|
1538
|
+
uid: 'users.name',
|
|
1539
|
+
isFork: true,
|
|
1540
|
+
forkId,
|
|
1541
|
+
subModels: { field: {} },
|
|
1542
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1543
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1544
|
+
return { fieldPath: 'users.name' };
|
|
1545
|
+
}
|
|
1546
|
+
return undefined;
|
|
1547
|
+
},
|
|
1548
|
+
};
|
|
1549
|
+
const rowCtx = createFieldContext(runtime);
|
|
1550
|
+
rowCtx.defineProperty('blockModel', { value: blockModel });
|
|
1551
|
+
rowCtx.defineProperty('fieldIndex', { value: [forkId] });
|
|
1552
|
+
rowCtx.defineProperty('item', {
|
|
1553
|
+
get: () => {
|
|
1554
|
+
const row = formStub.getFieldValue(['users', rowIndex]);
|
|
1555
|
+
const list = formStub.getFieldValue(['users']);
|
|
1556
|
+
return {
|
|
1557
|
+
index: rowIndex,
|
|
1558
|
+
length: Array.isArray(list) ? list.length : undefined,
|
|
1559
|
+
__is_new__: rowIsNew,
|
|
1560
|
+
__is_stored__: !rowIsNew,
|
|
1561
|
+
value: row,
|
|
1562
|
+
};
|
|
1563
|
+
},
|
|
1564
|
+
cache: false,
|
|
1565
|
+
});
|
|
1566
|
+
rowCtx.defineProperty('model', { value: rowModel });
|
|
1567
|
+
rowModel.context = rowCtx;
|
|
1568
|
+
return rowModel;
|
|
1569
|
+
};
|
|
1570
|
+
|
|
1571
|
+
const row0 = createRowModel('users:0', 0, false);
|
|
1572
|
+
const row1 = createRowModel('users:1', 1, false);
|
|
1573
|
+
masterModel.forks = new Set([row0, row1]);
|
|
1574
|
+
|
|
1575
|
+
blockCtx.defineProperty('engine', {
|
|
1576
|
+
value: {
|
|
1577
|
+
forEachModel: (cb: any) => {
|
|
1578
|
+
cb(masterModel);
|
|
1579
|
+
},
|
|
1580
|
+
},
|
|
1581
|
+
});
|
|
1582
|
+
|
|
1583
|
+
runtime.syncAssignRules([
|
|
1584
|
+
{
|
|
1585
|
+
key: 'r1',
|
|
1586
|
+
enable: true,
|
|
1587
|
+
targetPath: 'users.name',
|
|
1588
|
+
mode: 'default',
|
|
1589
|
+
condition: {
|
|
1590
|
+
logic: '$and',
|
|
1591
|
+
items: [{ path: '{{ ctx.item.index }}', operator: '$eq', value: 1 }],
|
|
1592
|
+
},
|
|
1593
|
+
value: 'Z',
|
|
1594
|
+
},
|
|
1595
|
+
]);
|
|
1596
|
+
|
|
1597
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
1598
|
+
expect(formStub.getFieldValue(['users', 1, 'name'])).toBe('');
|
|
1599
|
+
expect(formStub.getFieldValue(['users', 0, 'name'])).toBe('');
|
|
1600
|
+
});
|
|
1601
|
+
|
|
1602
|
+
it('applies default assign rules for newly added to-many row in update mode', async () => {
|
|
1603
|
+
const engineEmitter = new EventEmitter();
|
|
1604
|
+
const blockEmitter = new EventEmitter();
|
|
1605
|
+
const formStub = createFormStub({ users: [{ name: '' }, { name: '', __is_new__: true }] });
|
|
1606
|
+
|
|
1607
|
+
const blockModel: any = {
|
|
1608
|
+
uid: 'form-assign-default-update-new-row',
|
|
1609
|
+
flowEngine: { emitter: engineEmitter },
|
|
1610
|
+
emitter: blockEmitter,
|
|
1611
|
+
dispatchEvent: vi.fn(),
|
|
1612
|
+
getAclActionName: () => 'update',
|
|
1613
|
+
};
|
|
1614
|
+
|
|
1615
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
1616
|
+
runtime.mount({ sync: true });
|
|
1617
|
+
|
|
1618
|
+
const blockCtx = createFieldContext(runtime);
|
|
1619
|
+
const userRowCollection: any = { getField: () => null };
|
|
1620
|
+
const usersField: any = { type: 'hasMany', isAssociationField: () => true, targetCollection: userRowCollection };
|
|
1621
|
+
const rootCollection: any = { getField: (name: string) => (name === 'users' ? usersField : null) };
|
|
1622
|
+
blockCtx.defineProperty('collection', { value: rootCollection });
|
|
1623
|
+
blockModel.context = blockCtx;
|
|
1624
|
+
runtime.handleFormValuesChange(
|
|
1625
|
+
{ users: [{ name: '' }, { name: '', __is_new__: true }] },
|
|
1626
|
+
formStub.getFieldsValue(),
|
|
1627
|
+
);
|
|
1628
|
+
|
|
1629
|
+
const masterModel: any = {
|
|
1630
|
+
uid: 'users.name',
|
|
1631
|
+
subModels: { field: {} },
|
|
1632
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1633
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1634
|
+
return { fieldPath: 'users.name' };
|
|
1635
|
+
}
|
|
1636
|
+
return undefined;
|
|
1637
|
+
},
|
|
1638
|
+
};
|
|
1639
|
+
const masterCtx = createFieldContext(runtime);
|
|
1640
|
+
masterCtx.defineProperty('blockModel', { value: blockModel });
|
|
1641
|
+
masterCtx.defineProperty('model', { value: masterModel });
|
|
1642
|
+
masterModel.context = masterCtx;
|
|
1643
|
+
|
|
1644
|
+
const createRowModel = (forkId: string, rowIndex: number, rowIsNew: boolean) => {
|
|
1645
|
+
const rowModel: any = {
|
|
1646
|
+
uid: 'users.name',
|
|
1647
|
+
isFork: true,
|
|
1648
|
+
forkId,
|
|
1649
|
+
subModels: { field: {} },
|
|
1650
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1651
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1652
|
+
return { fieldPath: 'users.name' };
|
|
1653
|
+
}
|
|
1654
|
+
return undefined;
|
|
1655
|
+
},
|
|
1656
|
+
};
|
|
1657
|
+
const rowCtx = createFieldContext(runtime);
|
|
1658
|
+
rowCtx.defineProperty('blockModel', { value: blockModel });
|
|
1659
|
+
rowCtx.defineProperty('fieldIndex', { value: [forkId] });
|
|
1660
|
+
rowCtx.defineProperty('item', {
|
|
1661
|
+
get: () => {
|
|
1662
|
+
const row = formStub.getFieldValue(['users', rowIndex]);
|
|
1663
|
+
const list = formStub.getFieldValue(['users']);
|
|
1664
|
+
return {
|
|
1665
|
+
index: rowIndex,
|
|
1666
|
+
length: Array.isArray(list) ? list.length : undefined,
|
|
1667
|
+
__is_new__: rowIsNew,
|
|
1668
|
+
__is_stored__: !rowIsNew,
|
|
1669
|
+
value: row,
|
|
1670
|
+
};
|
|
1671
|
+
},
|
|
1672
|
+
cache: false,
|
|
1673
|
+
});
|
|
1674
|
+
rowCtx.defineProperty('model', { value: rowModel });
|
|
1675
|
+
rowModel.context = rowCtx;
|
|
1676
|
+
return rowModel;
|
|
1677
|
+
};
|
|
1678
|
+
|
|
1679
|
+
const row0 = createRowModel('users:0', 0, false);
|
|
1680
|
+
const row1 = createRowModel('users:1', 1, true);
|
|
1681
|
+
masterModel.forks = new Set([row0, row1]);
|
|
1682
|
+
|
|
1683
|
+
blockCtx.defineProperty('engine', {
|
|
1684
|
+
value: {
|
|
1685
|
+
forEachModel: (cb: any) => {
|
|
1686
|
+
cb(masterModel);
|
|
1687
|
+
},
|
|
1688
|
+
},
|
|
1689
|
+
});
|
|
1690
|
+
|
|
1691
|
+
runtime.syncAssignRules([
|
|
1692
|
+
{
|
|
1693
|
+
key: 'r1',
|
|
1694
|
+
enable: true,
|
|
1695
|
+
targetPath: 'users.name',
|
|
1696
|
+
mode: 'default',
|
|
1697
|
+
condition: {
|
|
1698
|
+
logic: '$and',
|
|
1699
|
+
items: [{ path: '{{ ctx.item.index }}', operator: '$eq', value: 1 }],
|
|
1700
|
+
},
|
|
1701
|
+
value: 'Z',
|
|
1702
|
+
},
|
|
1703
|
+
]);
|
|
1704
|
+
|
|
1705
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 1, 'name'])).toBe('Z'));
|
|
1706
|
+
expect(formStub.getFieldValue(['users', 0, 'name'])).toBe('');
|
|
1707
|
+
});
|
|
1708
|
+
|
|
1709
|
+
it('keeps default-disabled for edited to-many leaf when onValuesChange only provides top-level path', async () => {
|
|
1710
|
+
const engineEmitter = new EventEmitter();
|
|
1711
|
+
const blockEmitter = new EventEmitter();
|
|
1712
|
+
const formStub = createFormStub({ b: 'ABC', users: [{ name: '' }] });
|
|
1713
|
+
|
|
1714
|
+
const blockModel: any = {
|
|
1715
|
+
uid: 'form-assign-default-create-user-clear',
|
|
1716
|
+
flowEngine: { emitter: engineEmitter },
|
|
1717
|
+
emitter: blockEmitter,
|
|
1718
|
+
dispatchEvent: vi.fn(),
|
|
1719
|
+
getAclActionName: () => 'create',
|
|
1720
|
+
};
|
|
1721
|
+
|
|
1722
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
1723
|
+
runtime.mount({ sync: true });
|
|
1724
|
+
|
|
1725
|
+
const blockCtx = createFieldContext(runtime);
|
|
1726
|
+
const userRowCollection: any = { getField: () => null };
|
|
1727
|
+
const usersField: any = { type: 'hasMany', isAssociationField: () => true, targetCollection: userRowCollection };
|
|
1728
|
+
const rootCollection: any = { getField: (name: string) => (name === 'users' ? usersField : null) };
|
|
1729
|
+
blockCtx.defineProperty('collection', { value: rootCollection });
|
|
1730
|
+
blockModel.context = blockCtx;
|
|
1731
|
+
|
|
1732
|
+
const masterModel: any = {
|
|
1733
|
+
uid: 'users.name',
|
|
1734
|
+
subModels: { field: {} },
|
|
1735
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1736
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1737
|
+
return { fieldPath: 'users.name' };
|
|
1738
|
+
}
|
|
1739
|
+
return undefined;
|
|
1740
|
+
},
|
|
1741
|
+
};
|
|
1742
|
+
const masterCtx = createFieldContext(runtime);
|
|
1743
|
+
masterCtx.defineProperty('blockModel', { value: blockModel });
|
|
1744
|
+
masterCtx.defineProperty('model', { value: masterModel });
|
|
1745
|
+
masterModel.context = masterCtx;
|
|
1746
|
+
|
|
1747
|
+
const row0: any = {
|
|
1748
|
+
uid: 'users.name',
|
|
1749
|
+
isFork: true,
|
|
1750
|
+
forkId: 'users:0',
|
|
1751
|
+
subModels: { field: {} },
|
|
1752
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1753
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1754
|
+
return { fieldPath: 'users.name' };
|
|
1755
|
+
}
|
|
1756
|
+
return undefined;
|
|
1757
|
+
},
|
|
1758
|
+
};
|
|
1759
|
+
const row0Ctx = createFieldContext(runtime);
|
|
1760
|
+
row0Ctx.defineProperty('blockModel', { value: blockModel });
|
|
1761
|
+
row0Ctx.defineProperty('fieldIndex', { value: ['users:0'] });
|
|
1762
|
+
row0Ctx.defineProperty('model', { value: row0 });
|
|
1763
|
+
row0.context = row0Ctx;
|
|
1764
|
+
masterModel.forks = new Set([row0]);
|
|
1765
|
+
|
|
1766
|
+
blockCtx.defineProperty('engine', {
|
|
1767
|
+
value: {
|
|
1768
|
+
forEachModel: (cb: any) => {
|
|
1769
|
+
cb(masterModel);
|
|
1770
|
+
},
|
|
1771
|
+
},
|
|
1772
|
+
});
|
|
1773
|
+
|
|
1774
|
+
runtime.syncAssignRules([
|
|
1775
|
+
{
|
|
1776
|
+
key: 'r1',
|
|
1777
|
+
enable: true,
|
|
1778
|
+
targetPath: 'users.name',
|
|
1779
|
+
mode: 'default',
|
|
1780
|
+
condition: { logic: '$and', items: [] },
|
|
1781
|
+
value: '__B__',
|
|
1782
|
+
},
|
|
1783
|
+
]);
|
|
1784
|
+
|
|
1785
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 0, 'name'])).toBe('ABC'));
|
|
1786
|
+
|
|
1787
|
+
lodashSet((formStub as any).__store, ['users', 0, 'name'], '');
|
|
1788
|
+
runtime.handleFormFieldsChange([{ name: ['users', 0, 'name'], touched: true } as any]);
|
|
1789
|
+
runtime.handleFormValuesChange({ users: formStub.getFieldValue(['users']) }, formStub.getFieldsValue());
|
|
1790
|
+
|
|
1791
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
1792
|
+
expect(formStub.getFieldValue(['users', 0, 'name'])).toBe('');
|
|
1793
|
+
|
|
1794
|
+
await runtime.setFormValues(blockCtx, [{ path: ['b'], value: 'DEF' }], { source: 'user' });
|
|
1795
|
+
|
|
1796
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
1797
|
+
expect(formStub.getFieldValue(['users', 0, 'name'])).toBe('');
|
|
1798
|
+
});
|
|
1799
|
+
|
|
1800
|
+
it('keeps default enabled for non-user to-many leaf changes (touched=false)', async () => {
|
|
1801
|
+
const engineEmitter = new EventEmitter();
|
|
1802
|
+
const blockEmitter = new EventEmitter();
|
|
1803
|
+
const formStub = createFormStub({ b: 'ABC', users: [{ name: '' }] });
|
|
1804
|
+
|
|
1805
|
+
const blockModel: any = {
|
|
1806
|
+
uid: 'form-assign-default-create-user-clear-system',
|
|
1807
|
+
flowEngine: { emitter: engineEmitter },
|
|
1808
|
+
emitter: blockEmitter,
|
|
1809
|
+
dispatchEvent: vi.fn(),
|
|
1810
|
+
getAclActionName: () => 'create',
|
|
1811
|
+
};
|
|
1812
|
+
|
|
1813
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
1814
|
+
runtime.mount({ sync: true });
|
|
1815
|
+
|
|
1816
|
+
const blockCtx = createFieldContext(runtime);
|
|
1817
|
+
const userRowCollection: any = { getField: () => null };
|
|
1818
|
+
const usersField: any = { type: 'hasMany', isAssociationField: () => true, targetCollection: userRowCollection };
|
|
1819
|
+
const rootCollection: any = { getField: (name: string) => (name === 'users' ? usersField : null) };
|
|
1820
|
+
blockCtx.defineProperty('collection', { value: rootCollection });
|
|
1821
|
+
blockModel.context = blockCtx;
|
|
1822
|
+
|
|
1823
|
+
const masterModel: any = {
|
|
1824
|
+
uid: 'users.name',
|
|
1825
|
+
subModels: { field: {} },
|
|
1826
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1827
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1828
|
+
return { fieldPath: 'users.name' };
|
|
1829
|
+
}
|
|
1830
|
+
return undefined;
|
|
1831
|
+
},
|
|
1832
|
+
};
|
|
1833
|
+
const masterCtx = createFieldContext(runtime);
|
|
1834
|
+
masterCtx.defineProperty('blockModel', { value: blockModel });
|
|
1835
|
+
masterCtx.defineProperty('model', { value: masterModel });
|
|
1836
|
+
masterModel.context = masterCtx;
|
|
1837
|
+
|
|
1838
|
+
const row0: any = {
|
|
1839
|
+
uid: 'users.name',
|
|
1840
|
+
isFork: true,
|
|
1841
|
+
forkId: 'users:0',
|
|
1842
|
+
subModels: { field: {} },
|
|
1843
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1844
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1845
|
+
return { fieldPath: 'users.name' };
|
|
1846
|
+
}
|
|
1847
|
+
return undefined;
|
|
1848
|
+
},
|
|
1849
|
+
};
|
|
1850
|
+
const row0Ctx = createFieldContext(runtime);
|
|
1851
|
+
row0Ctx.defineProperty('blockModel', { value: blockModel });
|
|
1852
|
+
row0Ctx.defineProperty('fieldIndex', { value: ['users:0'] });
|
|
1853
|
+
row0Ctx.defineProperty('model', { value: row0 });
|
|
1854
|
+
row0.context = row0Ctx;
|
|
1855
|
+
masterModel.forks = new Set([row0]);
|
|
1856
|
+
|
|
1857
|
+
blockCtx.defineProperty('engine', {
|
|
1858
|
+
value: {
|
|
1859
|
+
forEachModel: (cb: any) => {
|
|
1860
|
+
cb(masterModel);
|
|
1861
|
+
},
|
|
1862
|
+
},
|
|
1863
|
+
});
|
|
1864
|
+
|
|
1865
|
+
runtime.syncAssignRules([
|
|
1866
|
+
{
|
|
1867
|
+
key: 'r1',
|
|
1868
|
+
enable: true,
|
|
1869
|
+
targetPath: 'users.name',
|
|
1870
|
+
mode: 'default',
|
|
1871
|
+
condition: { logic: '$and', items: [] },
|
|
1872
|
+
value: '__B__',
|
|
1873
|
+
},
|
|
1874
|
+
]);
|
|
1875
|
+
|
|
1876
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 0, 'name'])).toBe('ABC'));
|
|
1877
|
+
|
|
1878
|
+
lodashSet((formStub as any).__store, ['users', 0, 'name'], '');
|
|
1879
|
+
runtime.handleFormFieldsChange([{ name: ['users', 0, 'name'], touched: false } as any]);
|
|
1880
|
+
runtime.handleFormValuesChange({ users: formStub.getFieldValue(['users']) }, formStub.getFieldsValue());
|
|
1881
|
+
|
|
1882
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 0, 'name'])).toBe('ABC'));
|
|
1883
|
+
});
|
|
1884
|
+
|
|
1885
|
+
it('keeps to-many defaults available after add-only list structure changes', async () => {
|
|
1886
|
+
const engineEmitter = new EventEmitter();
|
|
1887
|
+
const blockEmitter = new EventEmitter();
|
|
1888
|
+
const formStub = createFormStub({ b: 'ABC', users: [] });
|
|
1889
|
+
|
|
1890
|
+
const blockModel: any = {
|
|
1891
|
+
uid: 'form-assign-default-create-add-row',
|
|
1892
|
+
flowEngine: { emitter: engineEmitter },
|
|
1893
|
+
emitter: blockEmitter,
|
|
1894
|
+
dispatchEvent: vi.fn(),
|
|
1895
|
+
getAclActionName: () => 'create',
|
|
1896
|
+
};
|
|
1897
|
+
|
|
1898
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
1899
|
+
runtime.mount({ sync: true });
|
|
1900
|
+
|
|
1901
|
+
const blockCtx = createFieldContext(runtime);
|
|
1902
|
+
const userRowCollection: any = { getField: () => null };
|
|
1903
|
+
const usersField: any = { type: 'hasMany', isAssociationField: () => true, targetCollection: userRowCollection };
|
|
1904
|
+
const rootCollection: any = { getField: (name: string) => (name === 'users' ? usersField : null) };
|
|
1905
|
+
blockCtx.defineProperty('collection', { value: rootCollection });
|
|
1906
|
+
blockModel.context = blockCtx;
|
|
1907
|
+
|
|
1908
|
+
const masterModel: any = {
|
|
1909
|
+
uid: 'users.name',
|
|
1910
|
+
subModels: { field: {} },
|
|
1911
|
+
forks: new Set(),
|
|
1912
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1913
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1914
|
+
return { fieldPath: 'users.name' };
|
|
1915
|
+
}
|
|
1916
|
+
return undefined;
|
|
1917
|
+
},
|
|
1918
|
+
};
|
|
1919
|
+
const masterCtx = createFieldContext(runtime);
|
|
1920
|
+
masterCtx.defineProperty('blockModel', { value: blockModel });
|
|
1921
|
+
masterCtx.defineProperty('model', { value: masterModel });
|
|
1922
|
+
masterModel.context = masterCtx;
|
|
1923
|
+
|
|
1924
|
+
blockCtx.defineProperty('engine', {
|
|
1925
|
+
value: {
|
|
1926
|
+
forEachModel: (cb: any) => {
|
|
1927
|
+
cb(masterModel);
|
|
1928
|
+
},
|
|
1929
|
+
},
|
|
1930
|
+
});
|
|
1931
|
+
|
|
1932
|
+
runtime.syncAssignRules([
|
|
1933
|
+
{
|
|
1934
|
+
key: 'r1',
|
|
1935
|
+
enable: true,
|
|
1936
|
+
targetPath: 'users.name',
|
|
1937
|
+
mode: 'default',
|
|
1938
|
+
condition: { logic: '$and', items: [] },
|
|
1939
|
+
value: '__B__',
|
|
1940
|
+
},
|
|
1941
|
+
]);
|
|
1942
|
+
|
|
1943
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
1944
|
+
expect(formStub.getFieldValue(['users', 0, 'name'])).toBeUndefined();
|
|
1945
|
+
|
|
1946
|
+
lodashSet((formStub as any).__store, ['users'], [{ __is_new__: true, name: '' }]);
|
|
1947
|
+
runtime.handleFormValuesChange({ users: formStub.getFieldValue(['users']) }, formStub.getFieldsValue());
|
|
1948
|
+
|
|
1949
|
+
const row0: any = {
|
|
1950
|
+
uid: 'users.name',
|
|
1951
|
+
isFork: true,
|
|
1952
|
+
forkId: 'users:0',
|
|
1953
|
+
subModels: { field: {} },
|
|
1954
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
1955
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
1956
|
+
return { fieldPath: 'users.name' };
|
|
1957
|
+
}
|
|
1958
|
+
return undefined;
|
|
1959
|
+
},
|
|
1960
|
+
};
|
|
1961
|
+
const row0Ctx = createFieldContext(runtime);
|
|
1962
|
+
row0Ctx.defineProperty('blockModel', { value: blockModel });
|
|
1963
|
+
row0Ctx.defineProperty('fieldIndex', { value: ['users:0'] });
|
|
1964
|
+
row0Ctx.defineProperty('model', { value: row0 });
|
|
1965
|
+
row0.context = row0Ctx;
|
|
1966
|
+
masterModel.forks = new Set([row0]);
|
|
1967
|
+
|
|
1968
|
+
engineEmitter.emit('model:mounted', { model: row0 });
|
|
1969
|
+
|
|
1970
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 0, 'name'])).toBe('ABC'));
|
|
1971
|
+
});
|
|
1972
|
+
|
|
1973
|
+
it('marks only edited nested to-many leaf as explicit when payload is top-level', async () => {
|
|
1974
|
+
const engineEmitter = new EventEmitter();
|
|
1975
|
+
const blockEmitter = new EventEmitter();
|
|
1976
|
+
const formStub = createFormStub({
|
|
1977
|
+
b: 'ABC',
|
|
1978
|
+
users: [
|
|
1979
|
+
{
|
|
1980
|
+
roles: [{ roleName: '' }, { roleName: '' }],
|
|
1981
|
+
},
|
|
1982
|
+
],
|
|
1983
|
+
});
|
|
1984
|
+
|
|
1985
|
+
const blockModel: any = {
|
|
1986
|
+
uid: 'form-assign-default-create-nested-roles',
|
|
1987
|
+
flowEngine: { emitter: engineEmitter },
|
|
1988
|
+
emitter: blockEmitter,
|
|
1989
|
+
dispatchEvent: vi.fn(),
|
|
1990
|
+
getAclActionName: () => 'create',
|
|
1991
|
+
};
|
|
1992
|
+
|
|
1993
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
1994
|
+
runtime.mount({ sync: true });
|
|
1995
|
+
|
|
1996
|
+
const blockCtx = createFieldContext(runtime);
|
|
1997
|
+
const rolesCollection: any = { getField: () => null };
|
|
1998
|
+
const rolesField: any = { type: 'hasMany', isAssociationField: () => true, targetCollection: rolesCollection };
|
|
1999
|
+
const usersItemCollection: any = { getField: (name: string) => (name === 'roles' ? rolesField : null) };
|
|
2000
|
+
const usersField: any = { type: 'hasMany', isAssociationField: () => true, targetCollection: usersItemCollection };
|
|
2001
|
+
const rootCollection: any = { getField: (name: string) => (name === 'users' ? usersField : null) };
|
|
2002
|
+
blockCtx.defineProperty('collection', { value: rootCollection });
|
|
2003
|
+
blockModel.context = blockCtx;
|
|
2004
|
+
|
|
2005
|
+
const masterModel: any = {
|
|
2006
|
+
uid: 'users.roles.roleName',
|
|
2007
|
+
subModels: { field: {} },
|
|
2008
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
2009
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
2010
|
+
return { fieldPath: 'users.roles.roleName' };
|
|
2011
|
+
}
|
|
2012
|
+
return undefined;
|
|
2013
|
+
},
|
|
2014
|
+
};
|
|
2015
|
+
const masterCtx = createFieldContext(runtime);
|
|
2016
|
+
masterCtx.defineProperty('blockModel', { value: blockModel });
|
|
2017
|
+
masterCtx.defineProperty('model', { value: masterModel });
|
|
2018
|
+
masterModel.context = masterCtx;
|
|
2019
|
+
|
|
2020
|
+
const createRoleRowModel = (forkId: string, roleIndex: number) => {
|
|
2021
|
+
const rowModel: any = {
|
|
2022
|
+
uid: 'users.roles.roleName',
|
|
2023
|
+
isFork: true,
|
|
2024
|
+
forkId,
|
|
2025
|
+
subModels: { field: {} },
|
|
2026
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
2027
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
2028
|
+
return { fieldPath: 'users.roles.roleName' };
|
|
2029
|
+
}
|
|
2030
|
+
return undefined;
|
|
2031
|
+
},
|
|
2032
|
+
};
|
|
2033
|
+
const rowCtx = createFieldContext(runtime);
|
|
2034
|
+
rowCtx.defineProperty('blockModel', { value: blockModel });
|
|
2035
|
+
rowCtx.defineProperty('fieldIndex', { value: ['users:0', `roles:${roleIndex}`] });
|
|
2036
|
+
rowCtx.defineProperty('model', { value: rowModel });
|
|
2037
|
+
rowModel.context = rowCtx;
|
|
2038
|
+
return rowModel;
|
|
2039
|
+
};
|
|
2040
|
+
|
|
2041
|
+
const roleRow0 = createRoleRowModel('users:0|roles:0', 0);
|
|
2042
|
+
const roleRow1 = createRoleRowModel('users:0|roles:1', 1);
|
|
2043
|
+
masterModel.forks = new Set([roleRow0, roleRow1]);
|
|
2044
|
+
|
|
2045
|
+
blockCtx.defineProperty('engine', {
|
|
2046
|
+
value: {
|
|
2047
|
+
forEachModel: (cb: any) => {
|
|
2048
|
+
cb(masterModel);
|
|
2049
|
+
},
|
|
2050
|
+
},
|
|
2051
|
+
});
|
|
2052
|
+
|
|
2053
|
+
runtime.syncAssignRules([
|
|
2054
|
+
{
|
|
2055
|
+
key: 'r1',
|
|
2056
|
+
enable: true,
|
|
2057
|
+
targetPath: 'users.roles.roleName',
|
|
2058
|
+
mode: 'default',
|
|
2059
|
+
condition: { logic: '$and', items: [] },
|
|
2060
|
+
value: '__B__',
|
|
2061
|
+
},
|
|
2062
|
+
]);
|
|
2063
|
+
|
|
2064
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 0, 'roles', 0, 'roleName'])).toBe('ABC'));
|
|
2065
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 0, 'roles', 1, 'roleName'])).toBe('ABC'));
|
|
2066
|
+
|
|
2067
|
+
lodashSet((formStub as any).__store, ['users', 0, 'roles', 0, 'roleName'], '');
|
|
2068
|
+
runtime.handleFormValuesChange({ users: formStub.getFieldValue(['users']) }, formStub.getFieldsValue());
|
|
2069
|
+
|
|
2070
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
2071
|
+
expect(formStub.getFieldValue(['users', 0, 'roles', 0, 'roleName'])).toBe('');
|
|
2072
|
+
expect(formStub.getFieldValue(['users', 0, 'roles', 1, 'roleName'])).toBe('ABC');
|
|
2073
|
+
|
|
2074
|
+
await runtime.setFormValues(blockCtx, [{ path: ['b'], value: 'DEF' }], { source: 'user' });
|
|
2075
|
+
|
|
2076
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 0, 'roles', 1, 'roleName'])).toBe('DEF'));
|
|
2077
|
+
expect(formStub.getFieldValue(['users', 0, 'roles', 0, 'roleName'])).toBe('');
|
|
2078
|
+
});
|
|
2079
|
+
|
|
2080
|
+
it('assigns to unconfigured field under to-many association using row grid context', async () => {
|
|
2081
|
+
const engineEmitter = new EventEmitter();
|
|
2082
|
+
const blockEmitter = new EventEmitter();
|
|
2083
|
+
const formStub = createFormStub({ users: [{ nickname: 'A' }, { nickname: 'B' }] });
|
|
2084
|
+
|
|
2085
|
+
const blockModel: any = {
|
|
2086
|
+
uid: 'form-assign-grid-row',
|
|
2087
|
+
flowEngine: { emitter: engineEmitter },
|
|
2088
|
+
emitter: blockEmitter,
|
|
2089
|
+
dispatchEvent: vi.fn(),
|
|
2090
|
+
getAclActionName: () => 'create',
|
|
2091
|
+
};
|
|
2092
|
+
|
|
2093
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2094
|
+
runtime.mount({ sync: true });
|
|
2095
|
+
|
|
2096
|
+
const blockCtx = createFieldContext(runtime);
|
|
2097
|
+
// 提供集合元信息:需要识别 users 为对多关联,并允许解析 users.age 的字段元信息
|
|
2098
|
+
const userRowCollection: any = {
|
|
2099
|
+
getField: (name: string) => ({ name, isAssociationField: () => false }),
|
|
2100
|
+
};
|
|
2101
|
+
const usersField: any = { type: 'hasMany', isAssociationField: () => true, targetCollection: userRowCollection };
|
|
2102
|
+
const rootCollection: any = { getField: (name: string) => (name === 'users' ? usersField : null) };
|
|
2103
|
+
blockCtx.defineProperty('collection', { value: rootCollection });
|
|
2104
|
+
blockModel.context = blockCtx;
|
|
2105
|
+
|
|
2106
|
+
// 已配置到 UI 的字段(用于让 RuleEngine 识别哪些 targetPath 已有 FormItemModel,避免重复挂载到 row grid)
|
|
2107
|
+
const configuredFieldModel: any = {
|
|
2108
|
+
uid: 'users.nickname',
|
|
2109
|
+
subModels: { field: {} },
|
|
2110
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
2111
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
2112
|
+
return { fieldPath: 'users.nickname' };
|
|
2113
|
+
}
|
|
2114
|
+
return undefined;
|
|
2115
|
+
},
|
|
2116
|
+
};
|
|
2117
|
+
const configuredCtx = createFieldContext(runtime);
|
|
2118
|
+
configuredCtx.defineProperty('blockModel', { value: blockModel });
|
|
2119
|
+
configuredCtx.defineProperty('model', { value: configuredFieldModel });
|
|
2120
|
+
configuredFieldModel.context = configuredCtx;
|
|
2121
|
+
|
|
2122
|
+
// row grid fork models(每行一个),用于承载未配置字段的赋值规则
|
|
2123
|
+
const gridMaster: any = {
|
|
2124
|
+
uid: 'users.grid',
|
|
2125
|
+
subModels: { items: [] },
|
|
2126
|
+
};
|
|
2127
|
+
const gridMasterCtx = createFieldContext(runtime);
|
|
2128
|
+
gridMasterCtx.defineProperty('blockModel', { value: blockModel });
|
|
2129
|
+
gridMasterCtx.defineProperty('model', { value: gridMaster });
|
|
2130
|
+
gridMaster.context = gridMasterCtx;
|
|
2131
|
+
|
|
2132
|
+
const createGridRow = (forkId: string, rowIndex: number) => {
|
|
2133
|
+
const row: any = {
|
|
2134
|
+
uid: 'users.grid',
|
|
2135
|
+
isFork: true,
|
|
2136
|
+
forkId,
|
|
2137
|
+
subModels: { items: [] },
|
|
2138
|
+
};
|
|
2139
|
+
const ctx = createFieldContext(runtime);
|
|
2140
|
+
ctx.defineProperty('blockModel', { value: blockModel });
|
|
2141
|
+
ctx.defineProperty('fieldIndex', { value: [`users:${rowIndex}`] });
|
|
2142
|
+
ctx.defineProperty('model', { value: row });
|
|
2143
|
+
row.context = ctx;
|
|
2144
|
+
return row;
|
|
2145
|
+
};
|
|
2146
|
+
|
|
2147
|
+
const row0 = createGridRow('row0', 0);
|
|
2148
|
+
const row1 = createGridRow('row1', 1);
|
|
2149
|
+
gridMaster.forks = new Set([row0, row1]);
|
|
2150
|
+
|
|
2151
|
+
blockCtx.defineProperty('engine', {
|
|
2152
|
+
value: {
|
|
2153
|
+
forEachModel: (cb: any) => {
|
|
2154
|
+
cb(configuredFieldModel);
|
|
2155
|
+
cb(gridMaster);
|
|
2156
|
+
},
|
|
2157
|
+
},
|
|
2158
|
+
});
|
|
2159
|
+
|
|
2160
|
+
runtime.syncAssignRules([
|
|
2161
|
+
{
|
|
2162
|
+
key: 'r1',
|
|
2163
|
+
enable: true,
|
|
2164
|
+
targetPath: 'users.age',
|
|
2165
|
+
mode: 'assign',
|
|
2166
|
+
condition: {
|
|
2167
|
+
logic: '$and',
|
|
2168
|
+
items: [{ path: '{{ ctx.item.index }}', operator: '$eq', value: 1 }],
|
|
2169
|
+
},
|
|
2170
|
+
value: 99,
|
|
2171
|
+
},
|
|
2172
|
+
]);
|
|
2173
|
+
|
|
2174
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 1, 'age'])).toBe(99));
|
|
2175
|
+
expect(formStub.getFieldValue(['users', 0, 'age'])).toBeUndefined();
|
|
2176
|
+
});
|
|
2177
|
+
|
|
2178
|
+
it('supports ctx.item.parentItem.index for nested association under to-many', async () => {
|
|
2179
|
+
const engineEmitter = new EventEmitter();
|
|
2180
|
+
const blockEmitter = new EventEmitter();
|
|
2181
|
+
const formStub = createFormStub({
|
|
2182
|
+
users: [{ user: { id: 1, name: 'Old0' } }, { user: { id: 2, name: 'Old1' } }],
|
|
2183
|
+
});
|
|
2184
|
+
|
|
2185
|
+
const blockModel: any = {
|
|
2186
|
+
uid: 'form-assign-current-parent',
|
|
2187
|
+
flowEngine: { emitter: engineEmitter },
|
|
2188
|
+
emitter: blockEmitter,
|
|
2189
|
+
dispatchEvent: vi.fn(),
|
|
2190
|
+
getAclActionName: () => 'create',
|
|
2191
|
+
};
|
|
2192
|
+
|
|
2193
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2194
|
+
runtime.mount({ sync: true });
|
|
2195
|
+
|
|
2196
|
+
const blockCtx = createFieldContext(runtime);
|
|
2197
|
+
|
|
2198
|
+
const userCollection: any = { getField: () => null };
|
|
2199
|
+
const userField: any = { isAssociationField: () => true, type: 'belongsTo', targetCollection: userCollection };
|
|
2200
|
+
const usersItemCollection: any = { getField: (name: string) => (name === 'user' ? userField : null) };
|
|
2201
|
+
const usersField: any = { isAssociationField: () => true, type: 'hasMany', targetCollection: usersItemCollection };
|
|
2202
|
+
const collection: any = { getField: (name: string) => (name === 'users' ? usersField : null) };
|
|
2203
|
+
|
|
2204
|
+
blockCtx.defineProperty('collection', { value: collection });
|
|
2205
|
+
|
|
2206
|
+
const createRowModel = (forkId: string) => {
|
|
2207
|
+
const rowModel: any = {
|
|
2208
|
+
uid: `users.user:${forkId}`,
|
|
2209
|
+
isFork: true,
|
|
2210
|
+
forkId,
|
|
2211
|
+
subModels: { field: { context: { collectionField: userField } } },
|
|
2212
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
2213
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
2214
|
+
return { fieldPath: 'users.user' };
|
|
2215
|
+
}
|
|
2216
|
+
return undefined;
|
|
2217
|
+
},
|
|
2218
|
+
};
|
|
2219
|
+
const rowCtx = createFieldContext(runtime);
|
|
2220
|
+
rowCtx.defineProperty('blockModel', { value: blockModel });
|
|
2221
|
+
rowCtx.defineProperty('collection', { value: collection });
|
|
2222
|
+
rowCtx.defineProperty('fieldIndex', { value: [forkId] });
|
|
2223
|
+
rowCtx.defineProperty('model', { value: rowModel });
|
|
2224
|
+
rowModel.context = rowCtx;
|
|
2225
|
+
return rowModel;
|
|
2226
|
+
};
|
|
2227
|
+
|
|
2228
|
+
const row0 = createRowModel('users:0');
|
|
2229
|
+
const row1 = createRowModel('users:1');
|
|
2230
|
+
|
|
2231
|
+
blockCtx.defineProperty('engine', {
|
|
2232
|
+
value: {
|
|
2233
|
+
forEachModel: (cb: any) => {
|
|
2234
|
+
cb(row0);
|
|
2235
|
+
cb(row1);
|
|
2236
|
+
},
|
|
2237
|
+
},
|
|
2238
|
+
});
|
|
2239
|
+
blockModel.context = blockCtx;
|
|
2240
|
+
|
|
2241
|
+
runtime.syncAssignRules([
|
|
2242
|
+
{
|
|
2243
|
+
key: 'r1',
|
|
2244
|
+
enable: true,
|
|
2245
|
+
targetPath: 'users.user.name',
|
|
2246
|
+
mode: 'assign',
|
|
2247
|
+
condition: {
|
|
2248
|
+
logic: '$and',
|
|
2249
|
+
items: [
|
|
2250
|
+
{ path: '{{ ctx.item.parentItem.index }}', operator: '$eq', value: 1 },
|
|
2251
|
+
{ path: '{{ ctx.item.parentItem.length }}', operator: '$eq', value: 2 },
|
|
2252
|
+
],
|
|
2253
|
+
},
|
|
2254
|
+
value: 'Z',
|
|
2255
|
+
},
|
|
2256
|
+
]);
|
|
2257
|
+
|
|
2258
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 1, 'user', 'name'])).toBe('Z'));
|
|
2259
|
+
expect(formStub.getFieldValue(['users', 0, 'user', 'name'])).toBe('Old0');
|
|
2260
|
+
});
|
|
2261
|
+
|
|
2262
|
+
it('skips nested association write when association value is empty', async () => {
|
|
2263
|
+
const engineEmitter = new EventEmitter();
|
|
2264
|
+
const blockEmitter = new EventEmitter();
|
|
2265
|
+
const formStub = createFormStub({ user: null });
|
|
2266
|
+
|
|
2267
|
+
const blockModel: any = {
|
|
2268
|
+
uid: 'form-assign-assoc-skip-1',
|
|
2269
|
+
flowEngine: { emitter: engineEmitter },
|
|
2270
|
+
emitter: blockEmitter,
|
|
2271
|
+
dispatchEvent: vi.fn(),
|
|
2272
|
+
getAclActionName: () => 'create',
|
|
2273
|
+
};
|
|
2274
|
+
|
|
2275
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2276
|
+
runtime.mount({ sync: true });
|
|
2277
|
+
|
|
2278
|
+
const blockCtx = createFieldContext(runtime);
|
|
2279
|
+
const userCollection: any = { getField: () => null };
|
|
2280
|
+
const userField: any = { isAssociationField: () => true, targetCollection: userCollection };
|
|
2281
|
+
const collection: any = { getField: (name: string) => (name === 'user' ? userField : null) };
|
|
2282
|
+
blockCtx.defineProperty('collection', { value: collection });
|
|
2283
|
+
blockModel.context = blockCtx;
|
|
2284
|
+
|
|
2285
|
+
runtime.syncAssignRules([
|
|
2286
|
+
{
|
|
2287
|
+
key: 'r1',
|
|
2288
|
+
enable: true,
|
|
2289
|
+
targetPath: 'user.name',
|
|
2290
|
+
mode: 'assign',
|
|
2291
|
+
condition: { logic: '$and', items: [] },
|
|
2292
|
+
value: 'Alice',
|
|
2293
|
+
},
|
|
2294
|
+
]);
|
|
2295
|
+
|
|
2296
|
+
// user 为空时不应隐式创建关联对象
|
|
2297
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
2298
|
+
expect(formStub.getFieldValue(['user'])).toBeNull();
|
|
2299
|
+
|
|
2300
|
+
// 当 user 从 null -> {id} 时,应触发重新计算并写入 user.name
|
|
2301
|
+
await runtime.setFormValues(blockCtx, [{ path: ['user'], value: { id: 1 } }], { source: 'user' });
|
|
2302
|
+
await waitFor(() => expect(formStub.getFieldValue(['user', 'name'])).toBe('Alice'));
|
|
2303
|
+
expect(formStub.getFieldValue(['user', 'id'])).toBe(1);
|
|
2304
|
+
});
|
|
2305
|
+
|
|
2306
|
+
it('applies nested association targetKey write when association value is empty', async () => {
|
|
2307
|
+
const engineEmitter = new EventEmitter();
|
|
2308
|
+
const blockEmitter = new EventEmitter();
|
|
2309
|
+
const formStub = createFormStub({ user: null });
|
|
2310
|
+
|
|
2311
|
+
const blockModel: any = {
|
|
2312
|
+
uid: 'form-assign-assoc-tk-1',
|
|
2313
|
+
flowEngine: { emitter: engineEmitter },
|
|
2314
|
+
emitter: blockEmitter,
|
|
2315
|
+
dispatchEvent: vi.fn(),
|
|
2316
|
+
getAclActionName: () => 'create',
|
|
2317
|
+
};
|
|
2318
|
+
|
|
2319
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2320
|
+
runtime.mount({ sync: true });
|
|
2321
|
+
|
|
2322
|
+
const blockCtx = createFieldContext(runtime);
|
|
2323
|
+
const userCollection: any = { getField: () => null, filterTargetKey: 'id' };
|
|
2324
|
+
const userField: any = { isAssociationField: () => true, type: 'belongsTo', targetCollection: userCollection };
|
|
2325
|
+
const collection: any = { getField: (name: string) => (name === 'user' ? userField : null) };
|
|
2326
|
+
blockCtx.defineProperty('collection', { value: collection });
|
|
2327
|
+
blockModel.context = blockCtx;
|
|
2328
|
+
|
|
2329
|
+
runtime.syncAssignRules([
|
|
2330
|
+
{
|
|
2331
|
+
key: 'r1',
|
|
2332
|
+
enable: true,
|
|
2333
|
+
targetPath: 'user.id',
|
|
2334
|
+
mode: 'default',
|
|
2335
|
+
condition: { logic: '$and', items: [] },
|
|
2336
|
+
value: 123,
|
|
2337
|
+
},
|
|
2338
|
+
]);
|
|
2339
|
+
|
|
2340
|
+
await waitFor(() => expect(formStub.getFieldValue(['user', 'id'])).toBe(123));
|
|
2341
|
+
expect(formStub.getFieldValue(['user'])).toEqual({ id: 123 });
|
|
2342
|
+
});
|
|
2343
|
+
|
|
2344
|
+
it('normalizes primitive value to to-one association object by targetKey', async () => {
|
|
2345
|
+
const engineEmitter = new EventEmitter();
|
|
2346
|
+
const blockEmitter = new EventEmitter();
|
|
2347
|
+
const formStub = createFormStub({});
|
|
2348
|
+
|
|
2349
|
+
const blockModel: any = {
|
|
2350
|
+
uid: 'form-assign-assoc-normalize-to-one',
|
|
2351
|
+
flowEngine: { emitter: engineEmitter },
|
|
2352
|
+
emitter: blockEmitter,
|
|
2353
|
+
dispatchEvent: vi.fn(),
|
|
2354
|
+
getAclActionName: () => 'create',
|
|
2355
|
+
};
|
|
2356
|
+
|
|
2357
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2358
|
+
runtime.mount({ sync: true });
|
|
2359
|
+
|
|
2360
|
+
const blockCtx = createFieldContext(runtime);
|
|
2361
|
+
blockCtx.defineProperty('user', { value: { mainDepartment: { id: 9, name: 'Dept 9' } } });
|
|
2362
|
+
|
|
2363
|
+
const departmentCollection: any = { getField: () => null, filterTargetKey: 'id' };
|
|
2364
|
+
const mainDepartmentField: any = {
|
|
2365
|
+
isAssociationField: () => true,
|
|
2366
|
+
type: 'belongsTo',
|
|
2367
|
+
targetCollection: departmentCollection,
|
|
2368
|
+
};
|
|
2369
|
+
const collection: any = {
|
|
2370
|
+
getField: (name: string) => {
|
|
2371
|
+
if (name === 'mainDepartment') return mainDepartmentField;
|
|
2372
|
+
return null;
|
|
2373
|
+
},
|
|
2374
|
+
};
|
|
2375
|
+
blockCtx.defineProperty('collection', { value: collection });
|
|
2376
|
+
blockModel.context = blockCtx;
|
|
2377
|
+
|
|
2378
|
+
runtime.syncAssignRules([
|
|
2379
|
+
{
|
|
2380
|
+
key: 'r1',
|
|
2381
|
+
enable: true,
|
|
2382
|
+
targetPath: 'mainDepartment',
|
|
2383
|
+
mode: 'assign',
|
|
2384
|
+
condition: { logic: '$and', items: [] },
|
|
2385
|
+
value: '{{ ctx.user.mainDepartment.id }}',
|
|
2386
|
+
},
|
|
2387
|
+
]);
|
|
2388
|
+
|
|
2389
|
+
await waitFor(() => expect(formStub.getFieldValue(['mainDepartment'])).toEqual({ id: 9 }));
|
|
2390
|
+
});
|
|
2391
|
+
|
|
2392
|
+
it('normalizes to-many association value to array when source is a single record object', async () => {
|
|
2393
|
+
const engineEmitter = new EventEmitter();
|
|
2394
|
+
const blockEmitter = new EventEmitter();
|
|
2395
|
+
const formStub = createFormStub({});
|
|
2396
|
+
|
|
2397
|
+
const blockModel: any = {
|
|
2398
|
+
uid: 'form-assign-assoc-normalize-to-many',
|
|
2399
|
+
flowEngine: { emitter: engineEmitter },
|
|
2400
|
+
emitter: blockEmitter,
|
|
2401
|
+
dispatchEvent: vi.fn(),
|
|
2402
|
+
getAclActionName: () => 'create',
|
|
2403
|
+
};
|
|
2404
|
+
|
|
2405
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2406
|
+
runtime.mount({ sync: true });
|
|
2407
|
+
|
|
2408
|
+
const blockCtx = createFieldContext(runtime);
|
|
2409
|
+
blockCtx.defineProperty('user', { value: { mainDepartment: { id: 9, name: 'Dept 9' } } });
|
|
2410
|
+
|
|
2411
|
+
const departmentCollection: any = { getField: () => null, filterTargetKey: 'id' };
|
|
2412
|
+
const departmentsField: any = {
|
|
2413
|
+
isAssociationField: () => true,
|
|
2414
|
+
type: 'belongsToMany',
|
|
2415
|
+
targetCollection: departmentCollection,
|
|
2416
|
+
};
|
|
2417
|
+
const collection: any = {
|
|
2418
|
+
getField: (name: string) => {
|
|
2419
|
+
if (name === 'departments') return departmentsField;
|
|
2420
|
+
return null;
|
|
2421
|
+
},
|
|
2422
|
+
};
|
|
2423
|
+
blockCtx.defineProperty('collection', { value: collection });
|
|
2424
|
+
blockModel.context = blockCtx;
|
|
2425
|
+
|
|
2426
|
+
runtime.syncAssignRules([
|
|
2427
|
+
{
|
|
2428
|
+
key: 'r1',
|
|
2429
|
+
enable: true,
|
|
2430
|
+
targetPath: 'departments',
|
|
2431
|
+
mode: 'assign',
|
|
2432
|
+
condition: { logic: '$and', items: [] },
|
|
2433
|
+
value: '{{ ctx.user.mainDepartment }}',
|
|
2434
|
+
},
|
|
2435
|
+
]);
|
|
2436
|
+
|
|
2437
|
+
await waitFor(() => expect(formStub.getFieldValue(['departments'])).toEqual([{ id: 9, name: 'Dept 9' }]));
|
|
2438
|
+
});
|
|
2439
|
+
|
|
2440
|
+
it('keeps rich to-many association value when assign result is semantically equal by targetKey', async () => {
|
|
2441
|
+
const engineEmitter = new EventEmitter();
|
|
2442
|
+
const blockEmitter = new EventEmitter();
|
|
2443
|
+
const formStub = createFormStub({ roles: [{ name: 'root', title: 'Root role' }] });
|
|
2444
|
+
|
|
2445
|
+
const blockModel: any = {
|
|
2446
|
+
uid: 'form-assign-assoc-semantic-to-many',
|
|
2447
|
+
flowEngine: { emitter: engineEmitter },
|
|
2448
|
+
emitter: blockEmitter,
|
|
2449
|
+
dispatchEvent: vi.fn(),
|
|
2450
|
+
getAclActionName: () => 'create',
|
|
2451
|
+
};
|
|
2452
|
+
|
|
2453
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2454
|
+
runtime.mount({ sync: true });
|
|
2455
|
+
|
|
2456
|
+
const blockCtx = createFieldContext(runtime);
|
|
2457
|
+
blockCtx.defineProperty('role', { value: 'root' });
|
|
2458
|
+
|
|
2459
|
+
const rolesCollection: any = { getField: () => null, filterTargetKey: 'name' };
|
|
2460
|
+
const rolesField: any = {
|
|
2461
|
+
isAssociationField: () => true,
|
|
2462
|
+
type: 'belongsToMany',
|
|
2463
|
+
targetCollection: rolesCollection,
|
|
2464
|
+
};
|
|
2465
|
+
const collection: any = {
|
|
2466
|
+
getField: (name: string) => {
|
|
2467
|
+
if (name === 'roles') return rolesField;
|
|
2468
|
+
return null;
|
|
2469
|
+
},
|
|
2470
|
+
};
|
|
2471
|
+
blockCtx.defineProperty('collection', { value: collection });
|
|
2472
|
+
blockModel.context = blockCtx;
|
|
2473
|
+
|
|
2474
|
+
runtime.syncAssignRules([
|
|
2475
|
+
{
|
|
2476
|
+
key: 'r1',
|
|
2477
|
+
enable: true,
|
|
2478
|
+
targetPath: 'roles',
|
|
2479
|
+
mode: 'assign',
|
|
2480
|
+
condition: { logic: '$and', items: [] },
|
|
2481
|
+
value: '{{ ctx.role }}',
|
|
2482
|
+
},
|
|
2483
|
+
]);
|
|
2484
|
+
|
|
2485
|
+
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
2486
|
+
expect(formStub.getFieldValue(['roles'])).toEqual([{ name: 'root', title: 'Root role' }]);
|
|
2487
|
+
});
|
|
2488
|
+
|
|
2489
|
+
it('keeps rich to-one association value when assign result is semantically equal by targetKey', async () => {
|
|
2490
|
+
const engineEmitter = new EventEmitter();
|
|
2491
|
+
const blockEmitter = new EventEmitter();
|
|
2492
|
+
const formStub = createFormStub({ mainDepartment: { id: 9, name: 'Dept 9' } });
|
|
2493
|
+
|
|
2494
|
+
const blockModel: any = {
|
|
2495
|
+
uid: 'form-assign-assoc-semantic-to-one',
|
|
2496
|
+
flowEngine: { emitter: engineEmitter },
|
|
2497
|
+
emitter: blockEmitter,
|
|
2498
|
+
dispatchEvent: vi.fn(),
|
|
2499
|
+
getAclActionName: () => 'create',
|
|
2500
|
+
};
|
|
2501
|
+
|
|
2502
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2503
|
+
runtime.mount({ sync: true });
|
|
2504
|
+
|
|
2505
|
+
const blockCtx = createFieldContext(runtime);
|
|
2506
|
+
blockCtx.defineProperty('user', { value: { mainDepartment: { id: 9 } } });
|
|
2507
|
+
|
|
2508
|
+
const departmentCollection: any = { getField: () => null, filterTargetKey: 'id' };
|
|
2509
|
+
const mainDepartmentField: any = {
|
|
2510
|
+
isAssociationField: () => true,
|
|
2511
|
+
type: 'belongsTo',
|
|
2512
|
+
targetCollection: departmentCollection,
|
|
2513
|
+
};
|
|
2514
|
+
const collection: any = {
|
|
2515
|
+
getField: (name: string) => {
|
|
2516
|
+
if (name === 'mainDepartment') return mainDepartmentField;
|
|
2517
|
+
return null;
|
|
2518
|
+
},
|
|
2519
|
+
};
|
|
2520
|
+
blockCtx.defineProperty('collection', { value: collection });
|
|
2521
|
+
blockModel.context = blockCtx;
|
|
2522
|
+
|
|
2523
|
+
runtime.syncAssignRules([
|
|
2524
|
+
{
|
|
2525
|
+
key: 'r1',
|
|
2526
|
+
enable: true,
|
|
2527
|
+
targetPath: 'mainDepartment',
|
|
2528
|
+
mode: 'assign',
|
|
2529
|
+
condition: { logic: '$and', items: [] },
|
|
2530
|
+
value: '{{ ctx.user.mainDepartment.id }}',
|
|
2531
|
+
},
|
|
2532
|
+
]);
|
|
2533
|
+
|
|
2534
|
+
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
2535
|
+
expect(formStub.getFieldValue(['mainDepartment'])).toEqual({ id: 9, name: 'Dept 9' });
|
|
2536
|
+
});
|
|
2537
|
+
|
|
2538
|
+
it('applies nested association write for updateAssociation field when association value is empty', async () => {
|
|
2539
|
+
const engineEmitter = new EventEmitter();
|
|
2540
|
+
const blockEmitter = new EventEmitter();
|
|
2541
|
+
const formStub = createFormStub({ user: null });
|
|
2542
|
+
|
|
2543
|
+
const blockModel: any = {
|
|
2544
|
+
uid: 'form-assign-assoc-update-1',
|
|
2545
|
+
flowEngine: { emitter: engineEmitter },
|
|
2546
|
+
emitter: blockEmitter,
|
|
2547
|
+
dispatchEvent: vi.fn(),
|
|
2548
|
+
getAclActionName: () => 'create',
|
|
2549
|
+
};
|
|
2550
|
+
|
|
2551
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2552
|
+
runtime.mount({ sync: true });
|
|
2553
|
+
|
|
2554
|
+
const blockCtx = createFieldContext(runtime);
|
|
2555
|
+
const userCollection: any = { getField: () => null };
|
|
2556
|
+
const userField: any = { isAssociationField: () => true, type: 'belongsTo', targetCollection: userCollection };
|
|
2557
|
+
const collection: any = { getField: (name: string) => (name === 'user' ? userField : null) };
|
|
2558
|
+
blockCtx.defineProperty('collection', { value: collection });
|
|
2559
|
+
|
|
2560
|
+
const assocFormItemModel: any = {
|
|
2561
|
+
uid: 'user',
|
|
2562
|
+
subModels: { field: { updateAssociation: true, context: { collectionField: userField } } },
|
|
2563
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
2564
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
2565
|
+
return { fieldPath: 'user' };
|
|
2566
|
+
}
|
|
2567
|
+
return undefined;
|
|
2568
|
+
},
|
|
2569
|
+
};
|
|
2570
|
+
const assocCtx = createFieldContext(runtime);
|
|
2571
|
+
assocCtx.defineProperty('blockModel', { value: blockModel });
|
|
2572
|
+
assocCtx.defineProperty('collection', { value: collection });
|
|
2573
|
+
assocCtx.defineProperty('model', { value: assocFormItemModel });
|
|
2574
|
+
assocFormItemModel.context = assocCtx;
|
|
2575
|
+
|
|
2576
|
+
blockCtx.defineProperty('engine', {
|
|
2577
|
+
value: {
|
|
2578
|
+
forEachModel: (cb: any) => {
|
|
2579
|
+
cb(assocFormItemModel);
|
|
2580
|
+
},
|
|
2581
|
+
},
|
|
2582
|
+
});
|
|
2583
|
+
blockModel.context = blockCtx;
|
|
2584
|
+
|
|
2585
|
+
runtime.syncAssignRules([
|
|
2586
|
+
{
|
|
2587
|
+
key: 'r1',
|
|
2588
|
+
enable: true,
|
|
2589
|
+
targetPath: 'user.name',
|
|
2590
|
+
mode: 'assign',
|
|
2591
|
+
condition: { logic: '$and', items: [] },
|
|
2592
|
+
value: 'Alice',
|
|
2593
|
+
},
|
|
2594
|
+
]);
|
|
2595
|
+
|
|
2596
|
+
await waitFor(() => expect(formStub.getFieldValue(['user', 'name'])).toBe('Alice'));
|
|
2597
|
+
expect(formStub.getFieldValue(['user', '__is_new__'])).toBe(true);
|
|
2598
|
+
});
|
|
2599
|
+
|
|
2600
|
+
it('applies nested assignment under to-many updateAssociation row when row value is missing', async () => {
|
|
2601
|
+
const engineEmitter = new EventEmitter();
|
|
2602
|
+
const blockEmitter = new EventEmitter();
|
|
2603
|
+
const formStub = createFormStub({ users: [] });
|
|
2604
|
+
|
|
2605
|
+
const blockModel: any = {
|
|
2606
|
+
uid: 'form-assign-to-many-update-assoc-1',
|
|
2607
|
+
flowEngine: { emitter: engineEmitter },
|
|
2608
|
+
emitter: blockEmitter,
|
|
2609
|
+
dispatchEvent: vi.fn(),
|
|
2610
|
+
getAclActionName: () => 'create',
|
|
2611
|
+
};
|
|
2612
|
+
|
|
2613
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2614
|
+
runtime.mount({ sync: true });
|
|
2615
|
+
|
|
2616
|
+
const blockCtx = createFieldContext(runtime);
|
|
2617
|
+
|
|
2618
|
+
const usersItemCollection: any = {
|
|
2619
|
+
getField: (name: string) => ({ name, isAssociationField: () => false }),
|
|
2620
|
+
};
|
|
2621
|
+
const usersField: any = { type: 'hasMany', isAssociationField: () => true, targetCollection: usersItemCollection };
|
|
2622
|
+
const rootCollection: any = { getField: (name: string) => (name === 'users' ? usersField : null) };
|
|
2623
|
+
blockCtx.defineProperty('collection', { value: rootCollection });
|
|
2624
|
+
|
|
2625
|
+
const usersFormItemModel: any = {
|
|
2626
|
+
uid: 'users',
|
|
2627
|
+
subModels: { field: { updateAssociation: true, context: { collectionField: usersField } } },
|
|
2628
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
2629
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
2630
|
+
return { fieldPath: 'users' };
|
|
2631
|
+
}
|
|
2632
|
+
return undefined;
|
|
2633
|
+
},
|
|
2634
|
+
};
|
|
2635
|
+
const usersCtx = createFieldContext(runtime);
|
|
2636
|
+
usersCtx.defineProperty('blockModel', { value: blockModel });
|
|
2637
|
+
usersCtx.defineProperty('collection', { value: rootCollection });
|
|
2638
|
+
usersCtx.defineProperty('model', { value: usersFormItemModel });
|
|
2639
|
+
usersFormItemModel.context = usersCtx;
|
|
2640
|
+
|
|
2641
|
+
const gridMaster: any = {
|
|
2642
|
+
uid: 'users.grid',
|
|
2643
|
+
subModels: { items: [] },
|
|
2644
|
+
};
|
|
2645
|
+
const gridMasterCtx = createFieldContext(runtime);
|
|
2646
|
+
gridMasterCtx.defineProperty('blockModel', { value: blockModel });
|
|
2647
|
+
gridMasterCtx.defineProperty('model', { value: gridMaster });
|
|
2648
|
+
gridMaster.context = gridMasterCtx;
|
|
2649
|
+
|
|
2650
|
+
const createGridRow = (forkId: string, rowIndex: number) => {
|
|
2651
|
+
const row: any = {
|
|
2652
|
+
uid: 'users.grid',
|
|
2653
|
+
isFork: true,
|
|
2654
|
+
forkId,
|
|
2655
|
+
subModels: { items: [] },
|
|
2656
|
+
};
|
|
2657
|
+
const ctx = createFieldContext(runtime);
|
|
2658
|
+
ctx.defineProperty('blockModel', { value: blockModel });
|
|
2659
|
+
ctx.defineProperty('fieldIndex', { value: [`users:${rowIndex}`] });
|
|
2660
|
+
ctx.defineProperty('model', { value: row });
|
|
2661
|
+
row.context = ctx;
|
|
2662
|
+
return row;
|
|
2663
|
+
};
|
|
2664
|
+
|
|
2665
|
+
const row0 = createGridRow('row0', 0);
|
|
2666
|
+
gridMaster.forks = new Set([row0]);
|
|
2667
|
+
|
|
2668
|
+
blockCtx.defineProperty('engine', {
|
|
2669
|
+
value: {
|
|
2670
|
+
forEachModel: (cb: any) => {
|
|
2671
|
+
cb(usersFormItemModel);
|
|
2672
|
+
cb(gridMaster);
|
|
2673
|
+
},
|
|
2674
|
+
},
|
|
2675
|
+
});
|
|
2676
|
+
blockModel.context = blockCtx;
|
|
2677
|
+
|
|
2678
|
+
runtime.syncAssignRules([
|
|
2679
|
+
{
|
|
2680
|
+
key: 'r1',
|
|
2681
|
+
enable: true,
|
|
2682
|
+
targetPath: 'users.age',
|
|
2683
|
+
mode: 'assign',
|
|
2684
|
+
condition: { logic: '$and', items: [] },
|
|
2685
|
+
value: 99,
|
|
2686
|
+
},
|
|
2687
|
+
]);
|
|
2688
|
+
|
|
2689
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 0, 'age'])).toBe(99));
|
|
2690
|
+
expect(formStub.getFieldValue(['users', 0, '__is_new__'])).toBe(true);
|
|
2691
|
+
});
|
|
2692
|
+
|
|
2693
|
+
it('supports nested association assign under to-many using row context', async () => {
|
|
2694
|
+
const engineEmitter = new EventEmitter();
|
|
2695
|
+
const blockEmitter = new EventEmitter();
|
|
2696
|
+
const formStub = createFormStub({ users: [{ user: null }] });
|
|
2697
|
+
|
|
2698
|
+
const blockModel: any = {
|
|
2699
|
+
uid: 'form-assign-assoc-to-many-nested',
|
|
2700
|
+
flowEngine: { emitter: engineEmitter },
|
|
2701
|
+
emitter: blockEmitter,
|
|
2702
|
+
dispatchEvent: vi.fn(),
|
|
2703
|
+
getAclActionName: () => 'create',
|
|
2704
|
+
};
|
|
2705
|
+
|
|
2706
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2707
|
+
runtime.mount({ sync: true });
|
|
2708
|
+
|
|
2709
|
+
const blockCtx = createFieldContext(runtime);
|
|
2710
|
+
|
|
2711
|
+
const userCollection: any = { getField: () => null };
|
|
2712
|
+
const userField: any = { isAssociationField: () => true, type: 'belongsTo', targetCollection: userCollection };
|
|
2713
|
+
const usersItemCollection: any = { getField: (name: string) => (name === 'user' ? userField : null) };
|
|
2714
|
+
const usersField: any = { isAssociationField: () => true, type: 'hasMany', targetCollection: usersItemCollection };
|
|
2715
|
+
const collection: any = { getField: (name: string) => (name === 'users' ? usersField : null) };
|
|
2716
|
+
|
|
2717
|
+
blockCtx.defineProperty('collection', { value: collection });
|
|
2718
|
+
|
|
2719
|
+
const createRowModel = (forkId: string) => {
|
|
2720
|
+
const rowModel: any = {
|
|
2721
|
+
uid: `users.user:${forkId}`,
|
|
2722
|
+
isFork: true,
|
|
2723
|
+
forkId,
|
|
2724
|
+
subModels: { field: { context: { collectionField: userField } } },
|
|
2725
|
+
getStepParams(flowKey: string, stepKey: string) {
|
|
2726
|
+
if (flowKey === 'fieldSettings' && stepKey === 'init') {
|
|
2727
|
+
return { fieldPath: 'users.user' };
|
|
2728
|
+
}
|
|
2729
|
+
return undefined;
|
|
2730
|
+
},
|
|
2731
|
+
};
|
|
2732
|
+
const rowCtx = createFieldContext(runtime);
|
|
2733
|
+
rowCtx.defineProperty('blockModel', { value: blockModel });
|
|
2734
|
+
rowCtx.defineProperty('collection', { value: collection });
|
|
2735
|
+
rowCtx.defineProperty('fieldIndex', { value: [forkId] });
|
|
2736
|
+
rowCtx.defineProperty('model', { value: rowModel });
|
|
2737
|
+
rowModel.context = rowCtx;
|
|
2738
|
+
return rowModel;
|
|
2739
|
+
};
|
|
2740
|
+
|
|
2741
|
+
const row0 = createRowModel('users:0');
|
|
2742
|
+
|
|
2743
|
+
blockCtx.defineProperty('engine', {
|
|
2744
|
+
value: {
|
|
2745
|
+
forEachModel: (cb: any) => {
|
|
2746
|
+
cb(row0);
|
|
2747
|
+
},
|
|
2748
|
+
},
|
|
2749
|
+
});
|
|
2750
|
+
blockModel.context = blockCtx;
|
|
2751
|
+
|
|
2752
|
+
runtime.syncAssignRules([
|
|
2753
|
+
{
|
|
2754
|
+
key: 'r1',
|
|
2755
|
+
enable: true,
|
|
2756
|
+
targetPath: 'users.user.name',
|
|
2757
|
+
mode: 'assign',
|
|
2758
|
+
condition: { logic: '$and', items: [] },
|
|
2759
|
+
value: 'Alice',
|
|
2760
|
+
},
|
|
2761
|
+
]);
|
|
2762
|
+
|
|
2763
|
+
// user 为空时不应隐式创建关联对象(users[0].user 仍为 null)
|
|
2764
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
2765
|
+
expect(formStub.getFieldValue(['users', 0, 'user'])).toBeNull();
|
|
2766
|
+
|
|
2767
|
+
// 当 users[0].user 从 null -> {id} 时,应触发重新计算并写入 users[0].user.name
|
|
2768
|
+
await runtime.setFormValues(blockCtx, [{ path: ['users', 0, 'user'], value: { id: 1 } }], { source: 'user' });
|
|
2769
|
+
await waitFor(() => expect(formStub.getFieldValue(['users', 0, 'user', 'name'])).toBe('Alice'));
|
|
2770
|
+
expect(formStub.getFieldValue(['users', 0, 'user', 'id'])).toBe(1);
|
|
2771
|
+
});
|
|
2772
|
+
|
|
2773
|
+
it('does not write to to-many nested path without row index', async () => {
|
|
2774
|
+
const engineEmitter = new EventEmitter();
|
|
2775
|
+
const blockEmitter = new EventEmitter();
|
|
2776
|
+
const formStub = createFormStub({});
|
|
2777
|
+
|
|
2778
|
+
const blockModel: any = {
|
|
2779
|
+
uid: 'form-assign-to-many-skip',
|
|
2780
|
+
flowEngine: { emitter: engineEmitter },
|
|
2781
|
+
emitter: blockEmitter,
|
|
2782
|
+
dispatchEvent: vi.fn(),
|
|
2783
|
+
getAclActionName: () => 'create',
|
|
2784
|
+
};
|
|
2785
|
+
|
|
2786
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2787
|
+
runtime.mount({ sync: true });
|
|
2788
|
+
|
|
2789
|
+
const blockCtx = createFieldContext(runtime);
|
|
2790
|
+
const userCollection: any = { getField: () => null };
|
|
2791
|
+
const usersField: any = { isAssociationField: () => true, type: 'hasMany', targetCollection: userCollection };
|
|
2792
|
+
const collection: any = { getField: (name: string) => (name === 'users' ? usersField : null) };
|
|
2793
|
+
blockCtx.defineProperty('collection', { value: collection });
|
|
2794
|
+
blockModel.context = blockCtx;
|
|
2795
|
+
|
|
2796
|
+
runtime.syncAssignRules([
|
|
2797
|
+
{
|
|
2798
|
+
key: 'r1',
|
|
2799
|
+
enable: true,
|
|
2800
|
+
targetPath: 'users.nickname',
|
|
2801
|
+
mode: 'assign',
|
|
2802
|
+
condition: { logic: '$and', items: [] },
|
|
2803
|
+
value: 'Z',
|
|
2804
|
+
},
|
|
2805
|
+
]);
|
|
2806
|
+
|
|
2807
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
2808
|
+
expect(formStub.getFieldValue(['users'])).toBeUndefined();
|
|
2809
|
+
});
|
|
2810
|
+
|
|
2811
|
+
it('resolves nested to-many indices in order when list field names repeat', async () => {
|
|
2812
|
+
const engineEmitter = new EventEmitter();
|
|
2813
|
+
const blockEmitter = new EventEmitter();
|
|
2814
|
+
const formStub = createFormStub({});
|
|
2815
|
+
|
|
2816
|
+
const blockModel: any = {
|
|
2817
|
+
uid: 'form-resolve-repeated-list-name',
|
|
2818
|
+
flowEngine: { emitter: engineEmitter },
|
|
2819
|
+
emitter: blockEmitter,
|
|
2820
|
+
dispatchEvent: vi.fn(),
|
|
2821
|
+
getAclActionName: () => 'create',
|
|
2822
|
+
};
|
|
2823
|
+
|
|
2824
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2825
|
+
runtime.mount({ sync: true });
|
|
2826
|
+
|
|
2827
|
+
const ctx = createFieldContext(runtime);
|
|
2828
|
+
ctx.defineProperty('fieldIndex', { value: ['products:1', 'products:0'] });
|
|
2829
|
+
|
|
2830
|
+
const resolved = (runtime as any).tryResolveNamePath(ctx, 'products.products.id');
|
|
2831
|
+
expect(resolved).toEqual(['products', 1, 'products', 0, 'id']);
|
|
2832
|
+
|
|
2833
|
+
const resolvedWithExplicit = (runtime as any).tryResolveNamePath(ctx, 'products[0].products.id');
|
|
2834
|
+
expect(resolvedWithExplicit).toEqual(['products', 0, 'products', 0, 'id']);
|
|
2835
|
+
});
|
|
2836
|
+
|
|
2837
|
+
it('keeps deeper linkage write when same txId writes same path later from outer scope', async () => {
|
|
2838
|
+
const engineEmitter = new EventEmitter();
|
|
2839
|
+
const blockEmitter = new EventEmitter();
|
|
2840
|
+
const formStub = createFormStub({ name: 'init' });
|
|
2841
|
+
|
|
2842
|
+
const blockModel: any = {
|
|
2843
|
+
uid: 'form-linkage-scope-depth-keep-inner',
|
|
2844
|
+
flowEngine: { emitter: engineEmitter },
|
|
2845
|
+
emitter: blockEmitter,
|
|
2846
|
+
dispatchEvent: vi.fn(),
|
|
2847
|
+
getAclActionName: () => 'create',
|
|
2848
|
+
};
|
|
2849
|
+
|
|
2850
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2851
|
+
runtime.mount({ sync: true });
|
|
2852
|
+
|
|
2853
|
+
const blockCtx = createFieldContext(runtime);
|
|
2854
|
+
blockModel.context = blockCtx;
|
|
2855
|
+
|
|
2856
|
+
await runtime.setFormValues(blockCtx, [{ path: ['name'], value: '456' }], {
|
|
2857
|
+
source: 'linkage',
|
|
2858
|
+
txId: 'tx-same',
|
|
2859
|
+
linkageTxId: 'tx-same',
|
|
2860
|
+
linkageScopeDepth: 1,
|
|
2861
|
+
});
|
|
2862
|
+
expect(formStub.getFieldValue(['name'])).toBe('456');
|
|
2863
|
+
|
|
2864
|
+
await runtime.setFormValues(blockCtx, [{ path: ['name'], value: '123' }], {
|
|
2865
|
+
source: 'linkage',
|
|
2866
|
+
txId: 'tx-same',
|
|
2867
|
+
linkageTxId: 'tx-same',
|
|
2868
|
+
linkageScopeDepth: 0,
|
|
2869
|
+
});
|
|
2870
|
+
expect(formStub.getFieldValue(['name'])).toBe('456');
|
|
2871
|
+
});
|
|
2872
|
+
|
|
2873
|
+
it('keeps last-write behavior for same-depth linkage writes in same txId', async () => {
|
|
2874
|
+
const engineEmitter = new EventEmitter();
|
|
2875
|
+
const blockEmitter = new EventEmitter();
|
|
2876
|
+
const formStub = createFormStub({ name: 'init' });
|
|
2877
|
+
|
|
2878
|
+
const blockModel: any = {
|
|
2879
|
+
uid: 'form-linkage-scope-depth-same-level',
|
|
2880
|
+
flowEngine: { emitter: engineEmitter },
|
|
2881
|
+
emitter: blockEmitter,
|
|
2882
|
+
dispatchEvent: vi.fn(),
|
|
2883
|
+
getAclActionName: () => 'create',
|
|
2884
|
+
};
|
|
2885
|
+
|
|
2886
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2887
|
+
runtime.mount({ sync: true });
|
|
2888
|
+
|
|
2889
|
+
const blockCtx = createFieldContext(runtime);
|
|
2890
|
+
blockModel.context = blockCtx;
|
|
2891
|
+
|
|
2892
|
+
await runtime.setFormValues(blockCtx, [{ path: ['name'], value: 'first' }], {
|
|
2893
|
+
source: 'linkage',
|
|
2894
|
+
txId: 'tx-same-level',
|
|
2895
|
+
linkageTxId: 'tx-same-level',
|
|
2896
|
+
linkageScopeDepth: 1,
|
|
2897
|
+
});
|
|
2898
|
+
|
|
2899
|
+
await runtime.setFormValues(blockCtx, [{ path: ['name'], value: 'second' }], {
|
|
2900
|
+
source: 'linkage',
|
|
2901
|
+
txId: 'tx-same-level',
|
|
2902
|
+
linkageTxId: 'tx-same-level',
|
|
2903
|
+
linkageScopeDepth: 1,
|
|
2904
|
+
});
|
|
2905
|
+
|
|
2906
|
+
expect(formStub.getFieldValue(['name'])).toBe('second');
|
|
2907
|
+
});
|
|
2908
|
+
|
|
2909
|
+
it('does not block linkage writes across different linkageTxId', async () => {
|
|
2910
|
+
const engineEmitter = new EventEmitter();
|
|
2911
|
+
const blockEmitter = new EventEmitter();
|
|
2912
|
+
const formStub = createFormStub({ name: 'init' });
|
|
2913
|
+
|
|
2914
|
+
const blockModel: any = {
|
|
2915
|
+
uid: 'form-linkage-scope-depth-different-tx',
|
|
2916
|
+
flowEngine: { emitter: engineEmitter },
|
|
2917
|
+
emitter: blockEmitter,
|
|
2918
|
+
dispatchEvent: vi.fn(),
|
|
2919
|
+
getAclActionName: () => 'create',
|
|
2920
|
+
};
|
|
2921
|
+
|
|
2922
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2923
|
+
runtime.mount({ sync: true });
|
|
2924
|
+
|
|
2925
|
+
const blockCtx = createFieldContext(runtime);
|
|
2926
|
+
blockModel.context = blockCtx;
|
|
2927
|
+
|
|
2928
|
+
await runtime.setFormValues(blockCtx, [{ path: ['name'], value: '456' }], {
|
|
2929
|
+
source: 'linkage',
|
|
2930
|
+
txId: 'tx-a',
|
|
2931
|
+
linkageTxId: 'tx-a',
|
|
2932
|
+
linkageScopeDepth: 1,
|
|
2933
|
+
});
|
|
2934
|
+
|
|
2935
|
+
await runtime.setFormValues(blockCtx, [{ path: ['name'], value: '123' }], {
|
|
2936
|
+
source: 'linkage',
|
|
2937
|
+
txId: 'tx-b',
|
|
2938
|
+
linkageTxId: 'tx-b',
|
|
2939
|
+
linkageScopeDepth: 0,
|
|
2940
|
+
});
|
|
2941
|
+
|
|
2942
|
+
expect(formStub.getFieldValue(['name'])).toBe('123');
|
|
2943
|
+
});
|
|
2944
|
+
|
|
2945
|
+
it('propagates linkageTxId in emitted formValuesChange payload', async () => {
|
|
2946
|
+
const engineEmitter = new EventEmitter();
|
|
2947
|
+
const blockEmitter = new EventEmitter();
|
|
2948
|
+
const formStub = createFormStub({ name: 'init' });
|
|
2949
|
+
|
|
2950
|
+
const blockModel: any = {
|
|
2951
|
+
uid: 'form-linkage-propagate-linkage-txid',
|
|
2952
|
+
flowEngine: { emitter: engineEmitter },
|
|
2953
|
+
emitter: blockEmitter,
|
|
2954
|
+
dispatchEvent: vi.fn(),
|
|
2955
|
+
getAclActionName: () => 'create',
|
|
2956
|
+
};
|
|
2957
|
+
|
|
2958
|
+
const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as any });
|
|
2959
|
+
runtime.mount({ sync: true });
|
|
2960
|
+
|
|
2961
|
+
const blockCtx = createFieldContext(runtime);
|
|
2962
|
+
blockModel.context = blockCtx;
|
|
2963
|
+
|
|
2964
|
+
await runtime.setFormValues(blockCtx, [{ path: ['name'], value: '456' }], {
|
|
2965
|
+
source: 'linkage',
|
|
2966
|
+
txId: 'tx-current',
|
|
2967
|
+
linkageTxId: 'tx-root',
|
|
2968
|
+
linkageScopeDepth: 1,
|
|
2969
|
+
});
|
|
2970
|
+
|
|
2971
|
+
const dispatchCalls = blockModel.dispatchEvent.mock.calls.filter((call: any[]) => call[0] === 'formValuesChange');
|
|
2972
|
+
expect(dispatchCalls.length).toBeGreaterThan(0);
|
|
2973
|
+
const payload = dispatchCalls[dispatchCalls.length - 1][1];
|
|
2974
|
+
expect(payload.txId).toBe('tx-current');
|
|
2975
|
+
expect(payload.linkageTxId).toBe('tx-root');
|
|
2976
|
+
});
|
|
2977
|
+
});
|