@nocobase/flow-engine 2.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +30 -0
- package/lib/ContextPathProxy.d.ts +17 -0
- package/lib/ContextPathProxy.js +65 -0
- package/lib/ElementProxy.d.ts +17 -0
- package/lib/ElementProxy.js +93 -0
- package/lib/FlowContextProvider.d.ts +24 -0
- package/lib/FlowContextProvider.js +82 -0
- package/lib/FlowDefinition.d.ts +423 -0
- package/lib/FlowDefinition.js +257 -0
- package/lib/JSRunner.d.ts +32 -0
- package/lib/JSRunner.js +95 -0
- package/lib/ReactView.d.ts +20 -0
- package/lib/ReactView.js +120 -0
- package/lib/ViewScopedFlowEngine.d.ts +23 -0
- package/lib/ViewScopedFlowEngine.js +81 -0
- package/lib/acl/Acl.d.ts +31 -0
- package/lib/acl/Acl.js +115 -0
- package/lib/action-registry/BaseActionRegistry.d.ts +23 -0
- package/lib/action-registry/BaseActionRegistry.js +57 -0
- package/lib/action-registry/EngineActionRegistry.d.ts +20 -0
- package/lib/action-registry/EngineActionRegistry.js +47 -0
- package/lib/action-registry/ModelActionRegistry.d.ts +34 -0
- package/lib/action-registry/ModelActionRegistry.js +79 -0
- package/lib/components/DynamicFlowsEditor.d.ts +17 -0
- package/lib/components/DynamicFlowsEditor.js +49 -0
- package/lib/components/FieldModelRenderer.d.ts +10 -0
- package/lib/components/FieldModelRenderer.js +100 -0
- package/lib/components/FlowContextSelector.d.ts +11 -0
- package/lib/components/FlowContextSelector.js +221 -0
- package/lib/components/FlowErrorFallback.d.ts +25 -0
- package/lib/components/FlowErrorFallback.js +264 -0
- package/lib/components/FlowModelRenderer.d.ts +61 -0
- package/lib/components/FlowModelRenderer.js +214 -0
- package/lib/components/FormItem.d.ts +18 -0
- package/lib/components/FormItem.js +151 -0
- package/lib/components/common/FlowSettingsButton.d.ts +11 -0
- package/lib/components/common/FlowSettingsButton.js +66 -0
- package/lib/components/common/index.d.ts +9 -0
- package/lib/components/common/index.js +30 -0
- package/lib/components/common/withFlowDesignMode.d.ts +26 -0
- package/lib/components/common/withFlowDesignMode.js +61 -0
- package/lib/components/dnd/findModelUidPosition.d.ts +13 -0
- package/lib/components/dnd/findModelUidPosition.js +50 -0
- package/lib/components/dnd/gridDragPlanner.d.ts +130 -0
- package/lib/components/dnd/gridDragPlanner.js +497 -0
- package/lib/components/dnd/index.d.ts +24 -0
- package/lib/components/dnd/index.js +164 -0
- package/lib/components/index.d.ts +18 -0
- package/lib/components/index.js +48 -0
- package/lib/components/settings/independents/dropdown/FlowsDropdownButton.d.ts +46 -0
- package/lib/components/settings/independents/dropdown/FlowsDropdownButton.js +225 -0
- package/lib/components/settings/independents/dropdown/index.d.ts +9 -0
- package/lib/components/settings/independents/dropdown/index.js +30 -0
- package/lib/components/settings/independents/index.d.ts +1 -0
- package/lib/components/settings/independents/index.js +30 -0
- package/lib/components/settings/index.d.ts +10 -0
- package/lib/components/settings/index.js +32 -0
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.d.ts +24 -0
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +501 -0
- package/lib/components/settings/wrappers/contextual/FlowsContextMenu.d.ts +45 -0
- package/lib/components/settings/wrappers/contextual/FlowsContextMenu.js +231 -0
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +111 -0
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +484 -0
- package/lib/components/settings/wrappers/contextual/StepRequiredSettingsDialog.d.ts +26 -0
- package/lib/components/settings/wrappers/contextual/StepRequiredSettingsDialog.js +342 -0
- package/lib/components/settings/wrappers/contextual/StepSettings.d.ts +23 -0
- package/lib/components/settings/wrappers/contextual/StepSettings.js +110 -0
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.d.ts +20 -0
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +212 -0
- package/lib/components/settings/wrappers/contextual/StepSettingsDrawer.d.ts +20 -0
- package/lib/components/settings/wrappers/contextual/StepSettingsDrawer.js +47 -0
- package/lib/components/settings/wrappers/contextual/index.d.ts +14 -0
- package/lib/components/settings/wrappers/contextual/index.js +40 -0
- package/lib/components/settings/wrappers/embedded/FlowSettings.d.ts +33 -0
- package/lib/components/settings/wrappers/embedded/FlowSettings.js +207 -0
- package/lib/components/settings/wrappers/embedded/FlowsSettings.d.ts +41 -0
- package/lib/components/settings/wrappers/embedded/FlowsSettings.js +84 -0
- package/lib/components/settings/wrappers/embedded/FlowsSettingsContent.d.ts +16 -0
- package/lib/components/settings/wrappers/embedded/FlowsSettingsContent.js +88 -0
- package/lib/components/settings/wrappers/embedded/index.d.ts +10 -0
- package/lib/components/settings/wrappers/embedded/index.js +32 -0
- package/lib/components/settings/wrappers/index.d.ts +2 -0
- package/lib/components/settings/wrappers/index.js +32 -0
- package/lib/components/subModel/AddSubModelButton.d.ts +62 -0
- package/lib/components/subModel/AddSubModelButton.js +415 -0
- package/lib/components/subModel/LazyDropdown.d.ts +55 -0
- package/lib/components/subModel/LazyDropdown.js +524 -0
- package/lib/components/subModel/index.d.ts +10 -0
- package/lib/components/subModel/index.js +32 -0
- package/lib/components/subModel/utils.d.ts +34 -0
- package/lib/components/subModel/utils.js +287 -0
- package/lib/components/variables/InlineVariableTag.d.ts +21 -0
- package/lib/components/variables/InlineVariableTag.js +123 -0
- package/lib/components/variables/SlateVariableEditor.d.ts +46 -0
- package/lib/components/variables/SlateVariableEditor.js +302 -0
- package/lib/components/variables/VariableInput.d.ts +11 -0
- package/lib/components/variables/VariableInput.js +334 -0
- package/lib/components/variables/VariableTag.d.ts +11 -0
- package/lib/components/variables/VariableTag.js +189 -0
- package/lib/components/variables/VariableTrigger.d.ts +20 -0
- package/lib/components/variables/VariableTrigger.js +136 -0
- package/lib/components/variables/index.d.ts +15 -0
- package/lib/components/variables/index.js +53 -0
- package/lib/components/variables/types.d.ts +93 -0
- package/lib/components/variables/types.js +24 -0
- package/lib/components/variables/useResolvedMetaTree.d.ts +19 -0
- package/lib/components/variables/useResolvedMetaTree.js +91 -0
- package/lib/components/variables/utils.d.ts +22 -0
- package/lib/components/variables/utils.js +177 -0
- package/lib/data-source/index.d.ts +180 -0
- package/lib/data-source/index.js +737 -0
- package/lib/data-source/jioToJoiSchema.d.ts +19 -0
- package/lib/data-source/jioToJoiSchema.js +114 -0
- package/lib/data-source/sortCollectionsByInherits.d.ts +10 -0
- package/lib/data-source/sortCollectionsByInherits.js +71 -0
- package/lib/decorators/index.d.ts +9 -0
- package/lib/decorators/index.js +36 -0
- package/lib/decorators/largeField.d.ts +9 -0
- package/lib/decorators/largeField.js +42 -0
- package/lib/emitter.d.ts +16 -0
- package/lib/emitter.js +58 -0
- package/lib/event-registry/BaseEventRegistry.d.ts +22 -0
- package/lib/event-registry/BaseEventRegistry.js +57 -0
- package/lib/event-registry/EngineEventRegistry.d.ts +19 -0
- package/lib/event-registry/EngineEventRegistry.js +47 -0
- package/lib/event-registry/ModelEventRegistry.d.ts +33 -0
- package/lib/event-registry/ModelEventRegistry.js +79 -0
- package/lib/executor/FlowExecutor.d.ts +25 -0
- package/lib/executor/FlowExecutor.js +290 -0
- package/lib/flow-registry/BaseFlowRegistry.d.ts +46 -0
- package/lib/flow-registry/BaseFlowRegistry.js +86 -0
- package/lib/flow-registry/GlobalFlowRegistry.d.ts +22 -0
- package/lib/flow-registry/GlobalFlowRegistry.js +95 -0
- package/lib/flow-registry/InstanceFlowRegistry.d.ts +21 -0
- package/lib/flow-registry/InstanceFlowRegistry.js +59 -0
- package/lib/flow-registry/index.d.ts +11 -0
- package/lib/flow-registry/index.js +34 -0
- package/lib/flowContext.d.ts +243 -0
- package/lib/flowContext.js +1337 -0
- package/lib/flowEngine.d.ts +340 -0
- package/lib/flowEngine.js +781 -0
- package/lib/flowI18n.d.ts +46 -0
- package/lib/flowI18n.js +117 -0
- package/lib/flowSettings.d.ts +266 -0
- package/lib/flowSettings.js +850 -0
- package/lib/hooks/index.d.ts +14 -0
- package/lib/hooks/index.js +40 -0
- package/lib/hooks/useApplyAutoFlows.d.ts +21 -0
- package/lib/hooks/useApplyAutoFlows.js +63 -0
- package/lib/hooks/useFlowModel.d.ts +29 -0
- package/lib/hooks/useFlowModel.js +72 -0
- package/lib/hooks/useFlowModelById.d.ts +11 -0
- package/lib/hooks/useFlowModelById.js +61 -0
- package/lib/hooks/useFlowSettingsContext.d.ts +20 -0
- package/lib/hooks/useFlowSettingsContext.js +61 -0
- package/lib/hooks/useFlowStep.d.ts +17 -0
- package/lib/hooks/useFlowStep.js +56 -0
- package/lib/hooks/useNiceDropdownMaxHeight.d.ts +13 -0
- package/lib/hooks/useNiceDropdownMaxHeight.js +52 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.js +93 -0
- package/lib/locale/en-US.json +61 -0
- package/lib/locale/index.d.ts +141 -0
- package/lib/locale/index.js +70 -0
- package/lib/locale/zh-CN.json +61 -0
- package/lib/models/CollectionFieldModel.d.ts +52 -0
- package/lib/models/CollectionFieldModel.js +280 -0
- package/lib/models/DisplayItemModel.d.ts +12 -0
- package/lib/models/DisplayItemModel.js +41 -0
- package/lib/models/EditableItemModel.d.ts +12 -0
- package/lib/models/EditableItemModel.js +41 -0
- package/lib/models/FilterableItemModel.d.ts +12 -0
- package/lib/models/FilterableItemModel.js +41 -0
- package/lib/models/flowModel.d.ts +342 -0
- package/lib/models/flowModel.js +1154 -0
- package/lib/models/forkFlowModel.d.ts +83 -0
- package/lib/models/forkFlowModel.js +280 -0
- package/lib/models/index.d.ts +14 -0
- package/lib/models/index.js +40 -0
- package/lib/provider.d.ts +22 -0
- package/lib/provider.js +115 -0
- package/lib/resources/apiResource.d.ts +34 -0
- package/lib/resources/apiResource.js +153 -0
- package/lib/resources/baseRecordResource.d.ts +61 -0
- package/lib/resources/baseRecordResource.js +264 -0
- package/lib/resources/filterItem.d.ts +33 -0
- package/lib/resources/filterItem.js +93 -0
- package/lib/resources/flowResource.d.ts +45 -0
- package/lib/resources/flowResource.js +146 -0
- package/lib/resources/index.d.ts +15 -0
- package/lib/resources/index.js +42 -0
- package/lib/resources/multiRecordResource.d.ts +53 -0
- package/lib/resources/multiRecordResource.js +230 -0
- package/lib/resources/singleRecordResource.d.ts +23 -0
- package/lib/resources/singleRecordResource.js +111 -0
- package/lib/resources/sqlResource.d.ts +73 -0
- package/lib/resources/sqlResource.js +294 -0
- package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.d.ts +11 -0
- package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.js +73 -0
- package/lib/runjs-context/contexts/JSBlockRunJSContext.d.ts +11 -0
- package/lib/runjs-context/contexts/JSBlockRunJSContext.js +91 -0
- package/lib/runjs-context/contexts/JSCollectionActionRunJSContext.d.ts +11 -0
- package/lib/runjs-context/contexts/JSCollectionActionRunJSContext.js +58 -0
- package/lib/runjs-context/contexts/JSColumnRunJSContext.d.ts +15 -0
- package/lib/runjs-context/contexts/JSColumnRunJSContext.js +78 -0
- package/lib/runjs-context/contexts/JSFieldRunJSContext.d.ts +11 -0
- package/lib/runjs-context/contexts/JSFieldRunJSContext.js +74 -0
- package/lib/runjs-context/contexts/JSItemRunJSContext.d.ts +11 -0
- package/lib/runjs-context/contexts/JSItemRunJSContext.js +70 -0
- package/lib/runjs-context/contexts/JSRecordActionRunJSContext.d.ts +11 -0
- package/lib/runjs-context/contexts/JSRecordActionRunJSContext.js +60 -0
- package/lib/runjs-context/contexts/base.d.ts +9 -0
- package/lib/runjs-context/contexts/base.js +169 -0
- package/lib/runjs-context/helpers.d.ts +20 -0
- package/lib/runjs-context/helpers.js +88 -0
- package/lib/runjs-context/registry.d.ts +20 -0
- package/lib/runjs-context/registry.js +61 -0
- package/lib/runjs-context/setup.d.ts +9 -0
- package/lib/runjs-context/setup.js +82 -0
- package/lib/runjs-context/snippets/global/api-request.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/api-request.snippet.js +57 -0
- package/lib/runjs-context/snippets/global/import-esm.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/import-esm.snippet.js +58 -0
- package/lib/runjs-context/snippets/global/message-error.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/message-error.snippet.js +47 -0
- package/lib/runjs-context/snippets/global/message-success.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/message-success.snippet.js +47 -0
- package/lib/runjs-context/snippets/global/notification-open.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/notification-open.snippet.js +50 -0
- package/lib/runjs-context/snippets/global/open-view-dialog.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/open-view-dialog.snippet.js +54 -0
- package/lib/runjs-context/snippets/global/open-view-drawer.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/open-view-drawer.snippet.js +54 -0
- package/lib/runjs-context/snippets/global/query-selector.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/query-selector.snippet.js +53 -0
- package/lib/runjs-context/snippets/global/require-amd.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/require-amd.snippet.js +49 -0
- package/lib/runjs-context/snippets/global/window-open.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/window-open.snippet.js +48 -0
- package/lib/runjs-context/snippets/index.d.ts +22 -0
- package/lib/runjs-context/snippets/index.js +213 -0
- package/lib/runjs-context/snippets/scene/block/add-event-listener.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/add-event-listener.snippet.js +55 -0
- package/lib/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.js +64 -0
- package/lib/runjs-context/snippets/scene/block/chartjs-bar.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/chartjs-bar.snippet.js +99 -0
- package/lib/runjs-context/snippets/scene/block/echarts-init.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/echarts-init.snippet.js +63 -0
- package/lib/runjs-context/snippets/scene/block/render-button-handler.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-button-handler.snippet.js +52 -0
- package/lib/runjs-context/snippets/scene/block/render-iframe.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-iframe.snippet.js +57 -0
- package/lib/runjs-context/snippets/scene/block/render-info-card.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-info-card.snippet.js +72 -0
- package/lib/runjs-context/snippets/scene/block/render-react.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-react.snippet.js +57 -0
- package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.js +100 -0
- package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.js +85 -0
- package/lib/runjs-context/snippets/scene/block/resource-example.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/resource-example.snippet.js +60 -0
- package/lib/runjs-context/snippets/scene/block/three-users-orbit.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/three-users-orbit.snippet.js +283 -0
- package/lib/runjs-context/snippets/scene/block/vue-component.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/vue-component.snippet.js +124 -0
- package/lib/runjs-context/snippets/scene/detail/color-by-value.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/color-by-value.snippet.js +52 -0
- package/lib/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.js +64 -0
- package/lib/runjs-context/snippets/scene/detail/format-number.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/format-number.snippet.js +51 -0
- package/lib/runjs-context/snippets/scene/detail/innerHTML-value.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/innerHTML-value.snippet.js +50 -0
- package/lib/runjs-context/snippets/scene/detail/percentage-bar.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/percentage-bar.snippet.js +82 -0
- package/lib/runjs-context/snippets/scene/detail/relative-time.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/relative-time.snippet.js +80 -0
- package/lib/runjs-context/snippets/scene/detail/status-tag.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/status-tag.snippet.js +74 -0
- package/lib/runjs-context/snippets/scene/form/calculate-total.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/calculate-total.snippet.js +63 -0
- package/lib/runjs-context/snippets/scene/form/cascade-select.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/cascade-select.snippet.js +81 -0
- package/lib/runjs-context/snippets/scene/form/conditional-required.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/conditional-required.snippet.js +64 -0
- package/lib/runjs-context/snippets/scene/form/copy-field-values.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/copy-field-values.snippet.js +74 -0
- package/lib/runjs-context/snippets/scene/form/render-basic.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/render-basic.snippet.js +53 -0
- package/lib/runjs-context/snippets/scene/form/set-disabled.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/set-disabled.snippet.js +69 -0
- package/lib/runjs-context/snippets/scene/form/set-field-value.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/set-field-value.snippet.js +68 -0
- package/lib/runjs-context/snippets/scene/form/set-required.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/set-required.snippet.js +69 -0
- package/lib/runjs-context/snippets/scene/form/toggle-multiple-fields.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/toggle-multiple-fields.snippet.js +67 -0
- package/lib/runjs-context/snippets/scene/form/toggle-visible.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/form/toggle-visible.snippet.js +69 -0
- package/lib/runjs-context/snippets/scene/table/cell-open-dialog.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/cell-open-dialog.snippet.js +64 -0
- package/lib/runjs-context/snippets/scene/table/collection-selected-count.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/collection-selected-count.snippet.js +53 -0
- package/lib/runjs-context/snippets/scene/table/concat-fields.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/concat-fields.snippet.js +79 -0
- package/lib/runjs-context/snippets/scene/table/destroy-selected.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/destroy-selected.snippet.js +55 -0
- package/lib/runjs-context/snippets/scene/table/export-selected-json.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/export-selected-json.snippet.js +64 -0
- package/lib/runjs-context/snippets/scene/table/iterate-selected-rows.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/iterate-selected-rows.snippet.js +52 -0
- package/lib/runjs-context/snippets/types.d.ts +24 -0
- package/lib/runjs-context/snippets/types.js +24 -0
- package/lib/types.d.ts +407 -0
- package/lib/types.js +43 -0
- package/lib/utils/autoFlowError.d.ts +16 -0
- package/lib/utils/autoFlowError.js +53 -0
- package/lib/utils/constants.d.ts +29 -0
- package/lib/utils/constants.js +77 -0
- package/lib/utils/context.d.ts +40 -0
- package/lib/utils/context.js +63 -0
- package/lib/utils/createCollectionContextMeta.d.ts +11 -0
- package/lib/utils/createCollectionContextMeta.js +117 -0
- package/lib/utils/exceptions.d.ts +22 -0
- package/lib/utils/exceptions.js +62 -0
- package/lib/utils/flow-definitions.d.ts +11 -0
- package/lib/utils/flow-definitions.js +40 -0
- package/lib/utils/index.d.ts +22 -0
- package/lib/utils/index.js +115 -0
- package/lib/utils/inheritance.d.ts +16 -0
- package/lib/utils/inheritance.js +53 -0
- package/lib/utils/params-resolvers.d.ts +51 -0
- package/lib/utils/params-resolvers.js +309 -0
- package/lib/utils/parsePathnameToViewParams.d.ts +34 -0
- package/lib/utils/parsePathnameToViewParams.js +84 -0
- package/lib/utils/safeGlobals.d.ts +16 -0
- package/lib/utils/safeGlobals.js +179 -0
- package/lib/utils/schema-utils.d.ts +40 -0
- package/lib/utils/schema-utils.js +161 -0
- package/lib/utils/serverContextParams.d.ts +29 -0
- package/lib/utils/serverContextParams.js +106 -0
- package/lib/utils/setupRuntimeContextSteps.d.ts +19 -0
- package/lib/utils/setupRuntimeContextSteps.js +88 -0
- package/lib/utils/translation.d.ts +18 -0
- package/lib/utils/translation.js +58 -0
- package/lib/utils/variablesParams.d.ts +52 -0
- package/lib/utils/variablesParams.js +161 -0
- package/lib/views/DialogComponent.d.ts +22 -0
- package/lib/views/DialogComponent.js +98 -0
- package/lib/views/DrawerComponent.d.ts +11 -0
- package/lib/views/DrawerComponent.js +101 -0
- package/lib/views/FlowView.d.ts +76 -0
- package/lib/views/FlowView.js +81 -0
- package/lib/views/PageComponent.d.ts +10 -0
- package/lib/views/PageComponent.js +168 -0
- package/lib/views/ViewNavigation.d.ts +45 -0
- package/lib/views/ViewNavigation.js +97 -0
- package/lib/views/createViewMeta.d.ts +44 -0
- package/lib/views/createViewMeta.js +377 -0
- package/lib/views/index.d.ts +14 -0
- package/lib/views/index.js +51 -0
- package/lib/views/useDialog.d.ts +32 -0
- package/lib/views/useDialog.js +200 -0
- package/lib/views/useDrawer.d.ts +33 -0
- package/lib/views/useDrawer.js +220 -0
- package/lib/views/usePage.d.ts +32 -0
- package/lib/views/usePage.js +194 -0
- package/lib/views/usePatchElement.d.ts +10 -0
- package/lib/views/usePatchElement.js +54 -0
- package/lib/views/usePopover.d.ts +17 -0
- package/lib/views/usePopover.js +159 -0
- package/package.json +37 -0
- package/src/ContextPathProxy.ts +45 -0
- package/src/ElementProxy.ts +69 -0
- package/src/FlowContextProvider.tsx +42 -0
- package/src/FlowDefinition.ts +275 -0
- package/src/JSRunner.ts +84 -0
- package/src/ReactView.tsx +104 -0
- package/src/ViewScopedFlowEngine.ts +75 -0
- package/src/__tests__/ElementProxy.test.ts +51 -0
- package/src/__tests__/JSRunner.test.ts +92 -0
- package/src/__tests__/ReactView.test.tsx +63 -0
- package/src/__tests__/context-path-proxy.test.ts +35 -0
- package/src/__tests__/flow-engine.test.ts +189 -0
- package/src/__tests__/flowContext.test.ts +2012 -0
- package/src/__tests__/flowContextCreateJSRunner.test.ts +163 -0
- package/src/__tests__/flowEngine.saveModel.test.ts +171 -0
- package/src/__tests__/flowI18n.test.ts +28 -0
- package/src/__tests__/flowModel.getFlows.test.ts +61 -0
- package/src/__tests__/flowModel.openView.navigation.test.ts +78 -0
- package/src/__tests__/flowRunJSContextDefine.test.ts +508 -0
- package/src/__tests__/flowRuntimeContext.test.ts +187 -0
- package/src/__tests__/flowSettings.open.test.tsx +1920 -0
- package/src/__tests__/flowSettings.test.ts +566 -0
- package/src/__tests__/globalFlowRegistry.test.ts +77 -0
- package/src/__tests__/isFieldInterfaceMatch.test.ts +51 -0
- package/src/__tests__/metaTreeNodeCache.test.ts +234 -0
- package/src/__tests__/path-aggregation.test.ts +85 -0
- package/src/__tests__/provider.test.tsx +28 -0
- package/src/__tests__/renderHiddenInConfig.test.tsx +91 -0
- package/src/__tests__/runjsContext.test.ts +241 -0
- package/src/__tests__/runjsContextImplementations.test.ts +217 -0
- package/src/__tests__/runjsContextRuntime.test.ts +269 -0
- package/src/__tests__/runjsEdgeCases.test.ts +281 -0
- package/src/__tests__/runjsLocales.test.ts +36 -0
- package/src/__tests__/runjsRuntimeFeatures.test.ts +449 -0
- package/src/__tests__/runjsSnippets.test.ts +140 -0
- package/src/__tests__/viewScopedFlowEngine.test.ts +212 -0
- package/src/acl/Acl.tsx +109 -0
- package/src/acl/__tests__/Acl.test.tsx +72 -0
- package/src/action-registry/BaseActionRegistry.ts +46 -0
- package/src/action-registry/EngineActionRegistry.ts +32 -0
- package/src/action-registry/ModelActionRegistry.ts +75 -0
- package/src/action-registry/__tests__/engineActionRegistry.test.ts +43 -0
- package/src/action-registry/__tests__/modelActionRegistry.test.ts +107 -0
- package/src/components/DynamicFlowsEditor.tsx +318 -0
- package/src/components/FieldModelRenderer.tsx +68 -0
- package/src/components/FlowContextSelector.tsx +255 -0
- package/src/components/FlowErrorFallback.tsx +316 -0
- package/src/components/FlowModelRenderer.tsx +362 -0
- package/src/components/FormItem.tsx +136 -0
- package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +226 -0
- package/src/components/__tests__/gridDragPlanner.test.ts +494 -0
- package/src/components/common/FlowSettingsButton.tsx +30 -0
- package/src/components/common/index.ts +10 -0
- package/src/components/common/withFlowDesignMode.tsx +49 -0
- package/src/components/dnd/README.md +149 -0
- package/src/components/dnd/findModelUidPosition.ts +26 -0
- package/src/components/dnd/gridDragPlanner.ts +659 -0
- package/src/components/dnd/index.tsx +128 -0
- package/src/components/index.ts +20 -0
- package/src/components/settings/independents/dropdown/FlowsDropdownButton.tsx +279 -0
- package/src/components/settings/independents/dropdown/index.ts +10 -0
- package/src/components/settings/independents/index.ts +2 -0
- package/src/components/settings/index.ts +11 -0
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +617 -0
- package/src/components/settings/wrappers/contextual/FlowsContextMenu.tsx +292 -0
- package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +655 -0
- package/src/components/settings/wrappers/contextual/StepRequiredSettingsDialog.tsx +446 -0
- package/src/components/settings/wrappers/contextual/StepSettings.tsx +109 -0
- package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +223 -0
- package/src/components/settings/wrappers/contextual/StepSettingsDrawer.tsx +32 -0
- package/src/components/settings/wrappers/contextual/index.ts +15 -0
- package/src/components/settings/wrappers/embedded/FlowSettings.tsx +258 -0
- package/src/components/settings/wrappers/embedded/FlowsSettings.tsx +111 -0
- package/src/components/settings/wrappers/embedded/FlowsSettingsContent.tsx +96 -0
- package/src/components/settings/wrappers/embedded/index.ts +11 -0
- package/src/components/settings/wrappers/index.ts +5 -0
- package/src/components/subModel/AddSubModelButton.tsx +575 -0
- package/src/components/subModel/LazyDropdown.tsx +714 -0
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +1185 -0
- package/src/components/subModel/__tests__/buildWrapperFieldChildren.test.ts +192 -0
- package/src/components/subModel/__tests__/utils.test.ts +425 -0
- package/src/components/subModel/index.ts +12 -0
- package/src/components/subModel/utils.ts +278 -0
- package/src/components/variables/InlineVariableTag.tsx +97 -0
- package/src/components/variables/SlateVariableEditor.tsx +384 -0
- package/src/components/variables/VariableInput.tsx +360 -0
- package/src/components/variables/VariableTag.tsx +175 -0
- package/src/components/variables/VariableTrigger.tsx +116 -0
- package/src/components/variables/__tests__/FlowContextSelector.test.tsx +553 -0
- package/src/components/variables/__tests__/VariableInput.test.tsx +550 -0
- package/src/components/variables/__tests__/VariableTag.test.tsx +347 -0
- package/src/components/variables/__tests__/test-utils.tsx +62 -0
- package/src/components/variables/__tests__/utils.test.ts +310 -0
- package/src/components/variables/index.ts +16 -0
- package/src/components/variables/types.ts +100 -0
- package/src/components/variables/useResolvedMetaTree.ts +76 -0
- package/src/components/variables/utils.ts +192 -0
- package/src/data-source/__tests__/collection.test.ts +58 -0
- package/src/data-source/__tests__/index.test.ts +82 -0
- package/src/data-source/__tests__/jioToJoiSchema.test.ts +56 -0
- package/src/data-source/__tests__/sortCollectionsByInherits.test.ts +125 -0
- package/src/data-source/index.ts +816 -0
- package/src/data-source/jioToJoiSchema.ts +103 -0
- package/src/data-source/sortCollectionsByInherits.ts +61 -0
- package/src/decorators/index.ts +10 -0
- package/src/decorators/largeField.ts +14 -0
- package/src/emitter.ts +33 -0
- package/src/event-registry/BaseEventRegistry.ts +40 -0
- package/src/event-registry/EngineEventRegistry.ts +26 -0
- package/src/event-registry/ModelEventRegistry.ts +69 -0
- package/src/event-registry/__tests__/engineEventRegistry.test.ts +48 -0
- package/src/executor/FlowExecutor.ts +302 -0
- package/src/executor/__tests__/eventStep.test.ts +157 -0
- package/src/executor/__tests__/flowExecutor.test.ts +309 -0
- package/src/flow-registry/BaseFlowRegistry.ts +91 -0
- package/src/flow-registry/GlobalFlowRegistry.ts +82 -0
- package/src/flow-registry/InstanceFlowRegistry.ts +39 -0
- package/src/flow-registry/__tests__/globalFlowRegistry.test.ts +141 -0
- package/src/flow-registry/__tests__/instance-and-global-registry.test.ts +67 -0
- package/src/flow-registry/__tests__/instanceFlowRegistry.test.ts +83 -0
- package/src/flow-registry/index.ts +12 -0
- package/src/flowContext.ts +1742 -0
- package/src/flowEngine.ts +905 -0
- package/src/flowI18n.ts +96 -0
- package/src/flowSettings.ts +1045 -0
- package/src/hooks/index.ts +15 -0
- package/src/hooks/useApplyAutoFlows.ts +53 -0
- package/src/hooks/useFlowModel.tsx +59 -0
- package/src/hooks/useFlowModelById.ts +37 -0
- package/src/hooks/useFlowSettingsContext.tsx +37 -0
- package/src/hooks/useFlowStep.tsx +19 -0
- package/src/hooks/useNiceDropdownMaxHeight.ts +34 -0
- package/src/index.ts +46 -0
- package/src/locale/en-US.json +61 -0
- package/src/locale/index.ts +38 -0
- package/src/locale/zh-CN.json +61 -0
- package/src/models/CollectionFieldModel.tsx +306 -0
- package/src/models/DisplayItemModel.tsx +13 -0
- package/src/models/EditableItemModel.tsx +13 -0
- package/src/models/FilterableItemModel.tsx +13 -0
- package/src/models/__tests__/CollectionFieldModel.test.ts +122 -0
- package/src/models/__tests__/defaultParams-on-create.test.ts +83 -0
- package/src/models/__tests__/flow-model-oninit.test.ts +44 -0
- package/src/models/__tests__/flowModel.actions.integration.test.ts +100 -0
- package/src/models/__tests__/flowModel.getFlows.sort.test.ts +100 -0
- package/src/models/__tests__/flowModel.test.ts +2869 -0
- package/src/models/__tests__/flowRegistry.test.ts +512 -0
- package/src/models/__tests__/forkFlowModel.test.ts +1047 -0
- package/src/models/__tests__/model-actions.test.ts +70 -0
- package/src/models/__tests__/model-events.test.ts +69 -0
- package/src/models/flowModel.tsx +1421 -0
- package/src/models/forkFlowModel.ts +319 -0
- package/src/models/index.ts +17 -0
- package/src/provider.tsx +103 -0
- package/src/resources/__tests__/apiResource.test.ts +201 -0
- package/src/resources/__tests__/baseRecordResource.test.ts +262 -0
- package/src/resources/__tests__/filterItem.test.ts +260 -0
- package/src/resources/__tests__/flowResource.test.ts +127 -0
- package/src/resources/apiResource.ts +148 -0
- package/src/resources/baseRecordResource.ts +279 -0
- package/src/resources/filterItem.ts +74 -0
- package/src/resources/flowResource.ts +143 -0
- package/src/resources/index.ts +17 -0
- package/src/resources/multiRecordResource.ts +219 -0
- package/src/resources/singleRecordResource.ts +83 -0
- package/src/resources/sqlResource.ts +299 -0
- package/src/runjs-context/contexts/FormJSFieldItemRunJSContext.ts +46 -0
- package/src/runjs-context/contexts/JSBlockRunJSContext.ts +64 -0
- package/src/runjs-context/contexts/JSCollectionActionRunJSContext.ts +31 -0
- package/src/runjs-context/contexts/JSColumnRunJSContext.ts +58 -0
- package/src/runjs-context/contexts/JSFieldRunJSContext.ts +48 -0
- package/src/runjs-context/contexts/JSItemRunJSContext.ts +43 -0
- package/src/runjs-context/contexts/JSRecordActionRunJSContext.ts +33 -0
- package/src/runjs-context/contexts/base.ts +155 -0
- package/src/runjs-context/helpers.ts +58 -0
- package/src/runjs-context/registry.ts +34 -0
- package/src/runjs-context/setup.ts +51 -0
- package/src/runjs-context/snippets/global/api-request.snippet.ts +38 -0
- package/src/runjs-context/snippets/global/import-esm.snippet.ts +39 -0
- package/src/runjs-context/snippets/global/message-error.snippet.ts +26 -0
- package/src/runjs-context/snippets/global/message-success.snippet.ts +26 -0
- package/src/runjs-context/snippets/global/notification-open.snippet.ts +31 -0
- package/src/runjs-context/snippets/global/open-view-dialog.snippet.ts +33 -0
- package/src/runjs-context/snippets/global/open-view-drawer.snippet.ts +33 -0
- package/src/runjs-context/snippets/global/query-selector.snippet.ts +34 -0
- package/src/runjs-context/snippets/global/require-amd.snippet.ts +30 -0
- package/src/runjs-context/snippets/global/window-open.snippet.ts +29 -0
- package/src/runjs-context/snippets/index.ts +195 -0
- package/src/runjs-context/snippets/scene/block/add-event-listener.snippet.ts +41 -0
- package/src/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.ts +45 -0
- package/src/runjs-context/snippets/scene/block/chartjs-bar.snippet.ts +80 -0
- package/src/runjs-context/snippets/scene/block/echarts-init.snippet.ts +44 -0
- package/src/runjs-context/snippets/scene/block/render-button-handler.snippet.ts +33 -0
- package/src/runjs-context/snippets/scene/block/render-iframe.snippet.ts +38 -0
- package/src/runjs-context/snippets/scene/block/render-info-card.snippet.ts +53 -0
- package/src/runjs-context/snippets/scene/block/render-react.snippet.ts +38 -0
- package/src/runjs-context/snippets/scene/block/render-statistics.snippet.ts +81 -0
- package/src/runjs-context/snippets/scene/block/render-timeline.snippet.ts +66 -0
- package/src/runjs-context/snippets/scene/block/resource-example.snippet.ts +46 -0
- package/src/runjs-context/snippets/scene/block/three-users-orbit.snippet.ts +264 -0
- package/src/runjs-context/snippets/scene/block/vue-component.snippet.ts +105 -0
- package/src/runjs-context/snippets/scene/detail/color-by-value.snippet.ts +33 -0
- package/src/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.ts +45 -0
- package/src/runjs-context/snippets/scene/detail/format-number.snippet.ts +32 -0
- package/src/runjs-context/snippets/scene/detail/innerHTML-value.snippet.ts +31 -0
- package/src/runjs-context/snippets/scene/detail/percentage-bar.snippet.ts +63 -0
- package/src/runjs-context/snippets/scene/detail/relative-time.snippet.ts +61 -0
- package/src/runjs-context/snippets/scene/detail/status-tag.snippet.ts +55 -0
- package/src/runjs-context/snippets/scene/form/calculate-total.snippet.ts +44 -0
- package/src/runjs-context/snippets/scene/form/cascade-select.snippet.ts +62 -0
- package/src/runjs-context/snippets/scene/form/conditional-required.snippet.ts +45 -0
- package/src/runjs-context/snippets/scene/form/copy-field-values.snippet.ts +55 -0
- package/src/runjs-context/snippets/scene/form/render-basic.snippet.ts +39 -0
- package/src/runjs-context/snippets/scene/form/set-disabled.snippet.ts +50 -0
- package/src/runjs-context/snippets/scene/form/set-field-value.snippet.ts +49 -0
- package/src/runjs-context/snippets/scene/form/set-required.snippet.ts +50 -0
- package/src/runjs-context/snippets/scene/form/toggle-multiple-fields.snippet.ts +48 -0
- package/src/runjs-context/snippets/scene/form/toggle-visible.snippet.ts +50 -0
- package/src/runjs-context/snippets/scene/table/cell-open-dialog.snippet.ts +45 -0
- package/src/runjs-context/snippets/scene/table/collection-selected-count.snippet.ts +34 -0
- package/src/runjs-context/snippets/scene/table/concat-fields.snippet.ts +60 -0
- package/src/runjs-context/snippets/scene/table/destroy-selected.snippet.ts +36 -0
- package/src/runjs-context/snippets/scene/table/export-selected-json.snippet.ts +45 -0
- package/src/runjs-context/snippets/scene/table/iterate-selected-rows.snippet.ts +33 -0
- package/src/runjs-context/snippets/types.ts +21 -0
- package/src/types.ts +484 -0
- package/src/utils/__tests__/context.test.ts +93 -0
- package/src/utils/__tests__/params-resolvers.test.ts +652 -0
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +104 -0
- package/src/utils/__tests__/safeGlobals.test.ts +29 -0
- package/src/utils/__tests__/utils.test.ts +1021 -0
- package/src/utils/__tests__/variablesParams.test.ts +52 -0
- package/src/utils/autoFlowError.ts +29 -0
- package/src/utils/constants.ts +60 -0
- package/src/utils/context.ts +70 -0
- package/src/utils/createCollectionContextMeta.ts +122 -0
- package/src/utils/exceptions.ts +36 -0
- package/src/utils/flow-definitions.ts +16 -0
- package/src/utils/index.ts +62 -0
- package/src/utils/inheritance.ts +39 -0
- package/src/utils/params-resolvers.ts +482 -0
- package/src/utils/parsePathnameToViewParams.ts +103 -0
- package/src/utils/safeGlobals.ts +188 -0
- package/src/utils/schema-utils.ts +201 -0
- package/src/utils/serverContextParams.ts +112 -0
- package/src/utils/setupRuntimeContextSteps.ts +89 -0
- package/src/utils/translation.ts +37 -0
- package/src/utils/variablesParams.ts +184 -0
- package/src/views/DialogComponent.tsx +79 -0
- package/src/views/DrawerComponent.tsx +72 -0
- package/src/views/FlowView.tsx +103 -0
- package/src/views/PageComponent.tsx +150 -0
- package/src/views/ViewNavigation.ts +122 -0
- package/src/views/__tests__/FlowView.test.ts +31 -0
- package/src/views/__tests__/ViewNavigation.test.ts +191 -0
- package/src/views/__tests__/usePatchElement.test.tsx +28 -0
- package/src/views/createViewMeta.ts +402 -0
- package/src/views/index.tsx +15 -0
- package/src/views/useDialog.tsx +194 -0
- package/src/views/useDrawer.tsx +229 -0
- package/src/views/usePage.tsx +185 -0
- package/src/views/usePatchElement.tsx +27 -0
- package/src/views/usePopover.tsx +131 -0
|
@@ -0,0 +1,659 @@
|
|
|
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 { uid } from '@formily/shared';
|
|
11
|
+
import _ from 'lodash';
|
|
12
|
+
|
|
13
|
+
/** 栅格系统常量 */
|
|
14
|
+
export const DEFAULT_GRID_COLUMNS = 24;
|
|
15
|
+
|
|
16
|
+
/** 最小 slot 厚度 */
|
|
17
|
+
export const MIN_SLOT_THICKNESS = 16;
|
|
18
|
+
/** 最大 slot 厚度 */
|
|
19
|
+
export const MAX_SLOT_THICKNESS = 48;
|
|
20
|
+
|
|
21
|
+
/** 列边缘最小宽度 */
|
|
22
|
+
export const COLUMN_EDGE_MIN_WIDTH = 12;
|
|
23
|
+
/** 列边缘最大宽度 */
|
|
24
|
+
export const COLUMN_EDGE_MAX_WIDTH = 28;
|
|
25
|
+
/** 列边缘宽度占列宽的比例(原来是 1/5) */
|
|
26
|
+
export const COLUMN_EDGE_WIDTH_RATIO = 0.2;
|
|
27
|
+
|
|
28
|
+
/** 插入区域厚度比例常量 */
|
|
29
|
+
const COLUMN_INSERT_THICKNESS_RATIO = 0.5; // 元素高度的 1/2
|
|
30
|
+
|
|
31
|
+
/** 行间隙高度比例常量 */
|
|
32
|
+
const ROW_GAP_HEIGHT_RATIO = 0.33; // 行高的 1/3
|
|
33
|
+
|
|
34
|
+
export interface Rect {
|
|
35
|
+
top: number;
|
|
36
|
+
left: number;
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface Point {
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface GridLayoutData {
|
|
47
|
+
rows: Record<string, string[][]>;
|
|
48
|
+
sizes: Record<string, number[]>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ColumnSlot {
|
|
52
|
+
type: 'column';
|
|
53
|
+
rowId: string;
|
|
54
|
+
columnIndex: number;
|
|
55
|
+
insertIndex: number;
|
|
56
|
+
position: 'before' | 'after';
|
|
57
|
+
rect: Rect;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface ColumnEdgeSlot {
|
|
61
|
+
type: 'column-edge';
|
|
62
|
+
rowId: string;
|
|
63
|
+
columnIndex: number;
|
|
64
|
+
direction: 'left' | 'right';
|
|
65
|
+
rect: Rect;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface RowGapSlot {
|
|
69
|
+
type: 'row-gap';
|
|
70
|
+
targetRowId: string;
|
|
71
|
+
position: 'above' | 'below';
|
|
72
|
+
rect: Rect;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface EmptyRowSlot {
|
|
76
|
+
type: 'empty-row';
|
|
77
|
+
rect: Rect;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface EmptyColumnSlot {
|
|
81
|
+
type: 'empty-column';
|
|
82
|
+
rowId: string;
|
|
83
|
+
columnIndex: number;
|
|
84
|
+
rect: Rect;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type LayoutSlot = ColumnSlot | ColumnEdgeSlot | RowGapSlot | EmptyRowSlot | EmptyColumnSlot;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 列内插入的配置
|
|
91
|
+
*/
|
|
92
|
+
export interface ColumnInsertConfig {
|
|
93
|
+
/** 高亮区域的高度(像素) */
|
|
94
|
+
height?: number;
|
|
95
|
+
/** 垂直偏移(像素),正数向下,负数向上 */
|
|
96
|
+
offsetTop?: number;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 列边缘的配置
|
|
101
|
+
*/
|
|
102
|
+
export interface ColumnEdgeConfig {
|
|
103
|
+
/** 高亮区域的宽度(像素) */
|
|
104
|
+
width?: number;
|
|
105
|
+
/** 水平偏移(像素),正数向右,负数向左 */
|
|
106
|
+
offsetLeft?: number;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 行间隙的配置
|
|
111
|
+
*/
|
|
112
|
+
export interface RowGapConfig {
|
|
113
|
+
/** 高亮区域的高度(像素) */
|
|
114
|
+
height?: number;
|
|
115
|
+
/** 垂直偏移(像素),正数向下,负数向上 */
|
|
116
|
+
offsetTop?: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 拖拽高亮区域的全局配置
|
|
121
|
+
*/
|
|
122
|
+
export interface DragOverlayConfig {
|
|
123
|
+
/** 列内插入(before 表示在区块上方插入,after 表示在区块下方插入) */
|
|
124
|
+
columnInsert?: {
|
|
125
|
+
before?: ColumnInsertConfig;
|
|
126
|
+
after?: ColumnInsertConfig;
|
|
127
|
+
};
|
|
128
|
+
/** 列边缘(left 表示在左侧新建列,right 表示在右侧新建列) */
|
|
129
|
+
columnEdge?: {
|
|
130
|
+
left?: ColumnEdgeConfig;
|
|
131
|
+
right?: ColumnEdgeConfig;
|
|
132
|
+
};
|
|
133
|
+
/** 行间隙(above 表示在行上方插入,below 表示在行下方插入) */
|
|
134
|
+
rowGap?: {
|
|
135
|
+
above?: RowGapConfig;
|
|
136
|
+
below?: RowGapConfig;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface LayoutSnapshot {
|
|
141
|
+
slots: LayoutSlot[];
|
|
142
|
+
containerRect: Rect;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface BuildLayoutSnapshotOptions {
|
|
146
|
+
container: HTMLElement | null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const toRect = (domRect: DOMRect): Rect => ({
|
|
150
|
+
top: domRect.top,
|
|
151
|
+
left: domRect.left,
|
|
152
|
+
width: domRect.width,
|
|
153
|
+
height: domRect.height,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const clampSlotHeight = (value: number) => Math.max(MIN_SLOT_THICKNESS, Math.min(MAX_SLOT_THICKNESS, value));
|
|
157
|
+
|
|
158
|
+
const createRect = ({ top, left, width, height }: Rect): Rect => ({
|
|
159
|
+
top,
|
|
160
|
+
left,
|
|
161
|
+
width,
|
|
162
|
+
height,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const offsetRect = (rect: Rect, offsets: Partial<Rect>): Rect => ({
|
|
166
|
+
top: offsets.top ?? rect.top,
|
|
167
|
+
left: offsets.left ?? rect.left,
|
|
168
|
+
width: offsets.width ?? rect.width,
|
|
169
|
+
height: offsets.height ?? rect.height,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const createRowGapRect = (source: Rect, position: 'above' | 'below', containerRect: Rect): Rect => {
|
|
173
|
+
const baseHeight = clampSlotHeight(source.height * ROW_GAP_HEIGHT_RATIO);
|
|
174
|
+
if (position === 'above') {
|
|
175
|
+
const available = source.top - containerRect.top;
|
|
176
|
+
const height = clampSlotHeight(Math.max(baseHeight, available));
|
|
177
|
+
return createRect({
|
|
178
|
+
top: source.top - height,
|
|
179
|
+
left: containerRect.left,
|
|
180
|
+
width: containerRect.width,
|
|
181
|
+
height,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const available = containerRect.top + containerRect.height - (source.top + source.height);
|
|
186
|
+
const height = clampSlotHeight(Math.max(baseHeight, available));
|
|
187
|
+
return createRect({
|
|
188
|
+
top: source.top + source.height,
|
|
189
|
+
left: containerRect.left,
|
|
190
|
+
width: containerRect.width,
|
|
191
|
+
height,
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const createColumnEdgeRect = (source: Rect, side: 'left' | 'right'): Rect => {
|
|
196
|
+
const width = Math.min(
|
|
197
|
+
Math.max(COLUMN_EDGE_MIN_WIDTH, source.width * COLUMN_EDGE_WIDTH_RATIO),
|
|
198
|
+
COLUMN_EDGE_MAX_WIDTH,
|
|
199
|
+
);
|
|
200
|
+
return createRect({
|
|
201
|
+
top: source.top,
|
|
202
|
+
left: side === 'left' ? source.left : source.left + source.width - width,
|
|
203
|
+
width,
|
|
204
|
+
height: source.height,
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const createColumnInsertRect = (itemRect: Rect, position: 'before' | 'after'): Rect => {
|
|
209
|
+
const thickness = clampSlotHeight(itemRect.height * COLUMN_INSERT_THICKNESS_RATIO);
|
|
210
|
+
if (position === 'before') {
|
|
211
|
+
return createRect({
|
|
212
|
+
top: itemRect.top,
|
|
213
|
+
left: itemRect.left,
|
|
214
|
+
width: itemRect.width,
|
|
215
|
+
height: thickness,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
return createRect({
|
|
219
|
+
top: itemRect.top + itemRect.height - thickness,
|
|
220
|
+
left: itemRect.left,
|
|
221
|
+
width: itemRect.width,
|
|
222
|
+
height: thickness,
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const expandColumnRect = (columnRect: Rect): Rect => ({
|
|
227
|
+
top: columnRect.top,
|
|
228
|
+
left: columnRect.left,
|
|
229
|
+
width: columnRect.width,
|
|
230
|
+
height: Math.max(columnRect.height, MIN_SLOT_THICKNESS),
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
export const buildLayoutSnapshot = ({ container }: BuildLayoutSnapshotOptions): LayoutSnapshot => {
|
|
234
|
+
if (!container) {
|
|
235
|
+
return {
|
|
236
|
+
slots: [],
|
|
237
|
+
containerRect: { top: 0, left: 0, width: 0, height: 0 },
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const containerRect = toRect(container.getBoundingClientRect());
|
|
242
|
+
const slots: LayoutSlot[] = [];
|
|
243
|
+
|
|
244
|
+
// 获取所有行元素,但只保留直接属于当前容器的(不在子 Grid 中的)
|
|
245
|
+
const allRowElements = Array.from(container.querySelectorAll('[data-grid-row-id]'));
|
|
246
|
+
const rowElements = allRowElements.filter((el) => {
|
|
247
|
+
const htmlEl = el as HTMLElement;
|
|
248
|
+
// 查找该元素最近的带 data-grid-row-id 的祖先容器
|
|
249
|
+
let parent = htmlEl.parentElement;
|
|
250
|
+
while (parent && parent !== container) {
|
|
251
|
+
if (parent.hasAttribute('data-grid-row-id')) {
|
|
252
|
+
// 说明这个元素在另一个 Grid 行内,是嵌套的
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
parent = parent.parentElement;
|
|
256
|
+
}
|
|
257
|
+
// 如果遍历到 container 都没遇到其他 grid-row,说明是直接子元素
|
|
258
|
+
return true;
|
|
259
|
+
}) as HTMLElement[];
|
|
260
|
+
|
|
261
|
+
if (rowElements.length === 0) {
|
|
262
|
+
slots.push({
|
|
263
|
+
type: 'empty-row',
|
|
264
|
+
rect: createRect({
|
|
265
|
+
top: containerRect.top,
|
|
266
|
+
left: containerRect.left,
|
|
267
|
+
width: containerRect.width,
|
|
268
|
+
height: Math.max(containerRect.height, MIN_SLOT_THICKNESS),
|
|
269
|
+
}),
|
|
270
|
+
});
|
|
271
|
+
return { slots, containerRect };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
rowElements.forEach((rowElement, rowIndex) => {
|
|
275
|
+
const rowId = rowElement.dataset.gridRowId;
|
|
276
|
+
if (!rowId) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const rowRect = toRect(rowElement.getBoundingClientRect());
|
|
280
|
+
|
|
281
|
+
if (rowIndex === 0) {
|
|
282
|
+
slots.push({
|
|
283
|
+
type: 'row-gap',
|
|
284
|
+
targetRowId: rowId,
|
|
285
|
+
position: 'above',
|
|
286
|
+
rect: createRowGapRect(rowRect, 'above', containerRect),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const columnElements = Array.from(
|
|
291
|
+
container.querySelectorAll(`[data-grid-column-row-id="${rowId}"][data-grid-column-index]`),
|
|
292
|
+
) as HTMLElement[];
|
|
293
|
+
|
|
294
|
+
const sortedColumns = columnElements.sort((a, b) => {
|
|
295
|
+
const indexA = Number(a.dataset.gridColumnIndex || 0);
|
|
296
|
+
const indexB = Number(b.dataset.gridColumnIndex || 0);
|
|
297
|
+
return indexA - indexB;
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
sortedColumns.forEach((columnElement) => {
|
|
301
|
+
const columnIndex = Number(columnElement.dataset.gridColumnIndex || 0);
|
|
302
|
+
const columnRect = toRect(columnElement.getBoundingClientRect());
|
|
303
|
+
|
|
304
|
+
slots.push({
|
|
305
|
+
type: 'column-edge',
|
|
306
|
+
rowId,
|
|
307
|
+
columnIndex,
|
|
308
|
+
direction: 'left',
|
|
309
|
+
rect: createColumnEdgeRect(columnRect, 'left'),
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
slots.push({
|
|
313
|
+
type: 'column-edge',
|
|
314
|
+
rowId,
|
|
315
|
+
columnIndex,
|
|
316
|
+
direction: 'right',
|
|
317
|
+
rect: createColumnEdgeRect(columnRect, 'right'),
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
const itemElements = Array.from(
|
|
321
|
+
columnElement.querySelectorAll(`[data-grid-item-row-id="${rowId}"][data-grid-column-index="${columnIndex}"]`),
|
|
322
|
+
) as HTMLElement[];
|
|
323
|
+
|
|
324
|
+
const sortedItems = itemElements.sort((a, b) => {
|
|
325
|
+
const indexA = Number(a.dataset.gridItemIndex || 0);
|
|
326
|
+
const indexB = Number(b.dataset.gridItemIndex || 0);
|
|
327
|
+
return indexA - indexB;
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
if (sortedItems.length === 0) {
|
|
331
|
+
slots.push({
|
|
332
|
+
type: 'empty-column',
|
|
333
|
+
rowId,
|
|
334
|
+
columnIndex,
|
|
335
|
+
rect: expandColumnRect(columnRect),
|
|
336
|
+
});
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const firstItemRect = toRect(sortedItems[0].getBoundingClientRect());
|
|
341
|
+
slots.push({
|
|
342
|
+
type: 'column',
|
|
343
|
+
rowId,
|
|
344
|
+
columnIndex,
|
|
345
|
+
insertIndex: 0,
|
|
346
|
+
position: 'before',
|
|
347
|
+
rect: createColumnInsertRect(firstItemRect, 'before'),
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
sortedItems.forEach((itemElement, itemIndex) => {
|
|
351
|
+
const itemRect = toRect(itemElement.getBoundingClientRect());
|
|
352
|
+
slots.push({
|
|
353
|
+
type: 'column',
|
|
354
|
+
rowId,
|
|
355
|
+
columnIndex,
|
|
356
|
+
insertIndex: itemIndex + 1,
|
|
357
|
+
position: 'after',
|
|
358
|
+
rect: createColumnInsertRect(itemRect, 'after'),
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
slots.push({
|
|
364
|
+
type: 'row-gap',
|
|
365
|
+
targetRowId: rowId,
|
|
366
|
+
position: 'below',
|
|
367
|
+
rect: createRowGapRect(rowRect, 'below', containerRect),
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
return {
|
|
372
|
+
slots,
|
|
373
|
+
containerRect,
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
export const getSlotKey = (slot: LayoutSlot): string => {
|
|
378
|
+
switch (slot.type) {
|
|
379
|
+
case 'column':
|
|
380
|
+
return `${slot.type}:${slot.rowId}:${slot.columnIndex}:${slot.insertIndex}:${slot.position}`;
|
|
381
|
+
case 'column-edge':
|
|
382
|
+
return `${slot.type}:${slot.rowId}:${slot.columnIndex}:${slot.direction}`;
|
|
383
|
+
case 'row-gap':
|
|
384
|
+
return `${slot.type}:${slot.targetRowId}:${slot.position}`;
|
|
385
|
+
case 'empty-row':
|
|
386
|
+
return `${slot.type}`;
|
|
387
|
+
case 'empty-column':
|
|
388
|
+
return `${slot.type}:${slot.rowId}:${slot.columnIndex}`;
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
const isPointInsideRect = (point: Point, rect: Rect): boolean => {
|
|
393
|
+
return (
|
|
394
|
+
point.x >= rect.left &&
|
|
395
|
+
point.x <= rect.left + rect.width &&
|
|
396
|
+
point.y >= rect.top &&
|
|
397
|
+
point.y <= rect.top + rect.height
|
|
398
|
+
);
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
const distanceToRect = (point: Point, rect: Rect): number => {
|
|
402
|
+
const dx = Math.max(rect.left - point.x, 0, point.x - (rect.left + rect.width));
|
|
403
|
+
const dy = Math.max(rect.top - point.y, 0, point.y - (rect.top + rect.height));
|
|
404
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
export const resolveDropIntent = (point: Point, slots: LayoutSlot[]): LayoutSlot | null => {
|
|
408
|
+
if (!slots.length) {
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const insideSlot = slots.find((slot) => isPointInsideRect(point, slot.rect));
|
|
413
|
+
if (insideSlot) {
|
|
414
|
+
return insideSlot;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
let closest: LayoutSlot | null = null;
|
|
418
|
+
let minDistance = Number.POSITIVE_INFINITY;
|
|
419
|
+
slots.forEach((slot) => {
|
|
420
|
+
const distance = distanceToRect(point, slot.rect);
|
|
421
|
+
if (distance < minDistance) {
|
|
422
|
+
minDistance = distance;
|
|
423
|
+
closest = slot;
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
return closest;
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
const findUidPosition = (rows: Record<string, string[][]>, uidValue: string) => {
|
|
431
|
+
for (const [rowId, columns] of Object.entries(rows)) {
|
|
432
|
+
for (let columnIndex = 0; columnIndex < columns.length; columnIndex += 1) {
|
|
433
|
+
const column = columns[columnIndex];
|
|
434
|
+
const itemIndex = column.indexOf(uidValue);
|
|
435
|
+
if (itemIndex !== -1) {
|
|
436
|
+
return { rowId, columnIndex, itemIndex };
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return null;
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
const removeItemFromLayout = (layout: GridLayoutData, uidValue: string) => {
|
|
444
|
+
const position = findUidPosition(layout.rows, uidValue);
|
|
445
|
+
if (!position) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const { rowId, columnIndex, itemIndex } = position;
|
|
450
|
+
const columns = layout.rows[rowId];
|
|
451
|
+
const column = columns?.[columnIndex];
|
|
452
|
+
if (!column) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
column.splice(itemIndex, 1);
|
|
457
|
+
|
|
458
|
+
if (column.length === 0) {
|
|
459
|
+
columns.splice(columnIndex, 1);
|
|
460
|
+
if (layout.sizes[rowId]) {
|
|
461
|
+
layout.sizes[rowId].splice(columnIndex, 1);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (columns.length === 0) {
|
|
466
|
+
delete layout.rows[rowId];
|
|
467
|
+
delete layout.sizes[rowId];
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
normalizeRowSizes(rowId, layout);
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
const toIntSizes = (weights: number[], count: number): number[] => {
|
|
475
|
+
if (count === 0) {
|
|
476
|
+
return [];
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const normalizedWeights = weights.map((weight) => (Number.isFinite(weight) && weight > 0 ? weight : 1));
|
|
480
|
+
const total = normalizedWeights.reduce((sum, weight) => sum + weight, 0) || count;
|
|
481
|
+
const ratios = normalizedWeights.map((weight) => weight / total);
|
|
482
|
+
const raw = ratios.map((ratio) => ratio * DEFAULT_GRID_COLUMNS);
|
|
483
|
+
const floors = raw.map((value) => Math.max(1, Math.floor(value)));
|
|
484
|
+
let remainder = DEFAULT_GRID_COLUMNS - floors.reduce((sum, value) => sum + value, 0);
|
|
485
|
+
|
|
486
|
+
if (remainder > 0) {
|
|
487
|
+
const decimals = raw
|
|
488
|
+
.map((value, index) => ({ index, decimal: value - Math.floor(value) }))
|
|
489
|
+
.sort((a, b) => b.decimal - a.decimal);
|
|
490
|
+
let pointer = 0;
|
|
491
|
+
while (remainder > 0 && decimals.length) {
|
|
492
|
+
const target = decimals[pointer % decimals.length].index;
|
|
493
|
+
floors[target] += 1;
|
|
494
|
+
remainder -= 1;
|
|
495
|
+
pointer += 1;
|
|
496
|
+
}
|
|
497
|
+
} else if (remainder < 0) {
|
|
498
|
+
const decimals = raw
|
|
499
|
+
.map((value, index) => ({ index, decimal: value - Math.floor(value) }))
|
|
500
|
+
.sort((a, b) => a.decimal - b.decimal);
|
|
501
|
+
let pointer = 0;
|
|
502
|
+
while (remainder < 0 && decimals.length) {
|
|
503
|
+
const target = decimals[pointer % decimals.length].index;
|
|
504
|
+
if (floors[target] > 1) {
|
|
505
|
+
floors[target] -= 1;
|
|
506
|
+
remainder += 1;
|
|
507
|
+
}
|
|
508
|
+
pointer += 1;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
const diff = DEFAULT_GRID_COLUMNS - floors.reduce((sum, value) => sum + value, 0);
|
|
513
|
+
if (diff !== 0 && floors.length) {
|
|
514
|
+
floors[floors.length - 1] += diff;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
return floors;
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
const normalizeRowSizes = (rowId: string, layout: GridLayoutData) => {
|
|
521
|
+
const columns = layout.rows[rowId];
|
|
522
|
+
if (!columns || columns.length === 0) {
|
|
523
|
+
delete layout.sizes[rowId];
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
const current = layout.sizes[rowId] || new Array(columns.length).fill(DEFAULT_GRID_COLUMNS / columns.length);
|
|
528
|
+
const weights =
|
|
529
|
+
current.length === columns.length ? current : new Array(columns.length).fill(DEFAULT_GRID_COLUMNS / columns.length);
|
|
530
|
+
layout.sizes[rowId] = toIntSizes(weights, columns.length);
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
const insertRow = (
|
|
534
|
+
rows: Record<string, string[][]>,
|
|
535
|
+
referenceRowId: string,
|
|
536
|
+
newRowId: string,
|
|
537
|
+
position: 'before' | 'after',
|
|
538
|
+
value: string[][],
|
|
539
|
+
): Record<string, string[][]> => {
|
|
540
|
+
const entries = Object.entries(rows);
|
|
541
|
+
const result: Record<string, string[][]> = {};
|
|
542
|
+
let inserted = false;
|
|
543
|
+
entries.forEach(([rowId, rowValue]) => {
|
|
544
|
+
if (!inserted && position === 'before' && rowId === referenceRowId) {
|
|
545
|
+
result[newRowId] = value;
|
|
546
|
+
inserted = true;
|
|
547
|
+
}
|
|
548
|
+
result[rowId] = rowValue;
|
|
549
|
+
if (!inserted && position === 'after' && rowId === referenceRowId) {
|
|
550
|
+
result[newRowId] = value;
|
|
551
|
+
inserted = true;
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
if (!inserted) {
|
|
556
|
+
result[newRowId] = value;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
return result;
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
const distributeSizesWithNewColumn = (
|
|
563
|
+
sizes: number[] | undefined,
|
|
564
|
+
insertIndex: number,
|
|
565
|
+
columnCount: number,
|
|
566
|
+
): number[] => {
|
|
567
|
+
if (!sizes || sizes.length === 0) {
|
|
568
|
+
return toIntSizes(new Array(columnCount).fill(1), columnCount);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
const normalized = sizes.map((size) => (Number.isFinite(size) && size > 0 ? size : 1));
|
|
572
|
+
const referenceIndex = Math.max(0, Math.min(insertIndex, normalized.length - 1));
|
|
573
|
+
const reference = normalized[referenceIndex] ?? 1;
|
|
574
|
+
const weights = [...normalized];
|
|
575
|
+
weights.splice(insertIndex, 0, reference);
|
|
576
|
+
return toIntSizes(weights, columnCount);
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
export interface SimulateLayoutOptions {
|
|
580
|
+
slot: LayoutSlot;
|
|
581
|
+
sourceUid: string;
|
|
582
|
+
layout: GridLayoutData;
|
|
583
|
+
generateRowId?: () => string;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
export const simulateLayoutForSlot = ({
|
|
587
|
+
slot,
|
|
588
|
+
sourceUid,
|
|
589
|
+
layout,
|
|
590
|
+
generateRowId,
|
|
591
|
+
}: SimulateLayoutOptions): GridLayoutData => {
|
|
592
|
+
const cloned: GridLayoutData = {
|
|
593
|
+
rows: _.cloneDeep(layout.rows),
|
|
594
|
+
sizes: _.cloneDeep(layout.sizes),
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
removeItemFromLayout(cloned, sourceUid);
|
|
598
|
+
|
|
599
|
+
const createRowId = generateRowId ?? uid;
|
|
600
|
+
|
|
601
|
+
switch (slot.type) {
|
|
602
|
+
case 'column': {
|
|
603
|
+
const columns = cloned.rows[slot.rowId] || [];
|
|
604
|
+
if (!cloned.rows[slot.rowId]) {
|
|
605
|
+
cloned.rows[slot.rowId] = columns;
|
|
606
|
+
}
|
|
607
|
+
if (!columns[slot.columnIndex]) {
|
|
608
|
+
columns[slot.columnIndex] = [];
|
|
609
|
+
}
|
|
610
|
+
const targetColumn = columns[slot.columnIndex];
|
|
611
|
+
targetColumn.splice(slot.insertIndex, 0, sourceUid);
|
|
612
|
+
normalizeRowSizes(slot.rowId, cloned);
|
|
613
|
+
break;
|
|
614
|
+
}
|
|
615
|
+
case 'empty-column': {
|
|
616
|
+
const columns = cloned.rows[slot.rowId] || [];
|
|
617
|
+
if (!cloned.rows[slot.rowId]) {
|
|
618
|
+
cloned.rows[slot.rowId] = columns;
|
|
619
|
+
}
|
|
620
|
+
if (!columns[slot.columnIndex]) {
|
|
621
|
+
columns[slot.columnIndex] = [];
|
|
622
|
+
}
|
|
623
|
+
columns[slot.columnIndex] = [sourceUid];
|
|
624
|
+
normalizeRowSizes(slot.rowId, cloned);
|
|
625
|
+
break;
|
|
626
|
+
}
|
|
627
|
+
case 'column-edge': {
|
|
628
|
+
const columns = cloned.rows[slot.rowId] || [];
|
|
629
|
+
if (!cloned.rows[slot.rowId]) {
|
|
630
|
+
cloned.rows[slot.rowId] = columns;
|
|
631
|
+
}
|
|
632
|
+
const insertIndex = slot.direction === 'left' ? slot.columnIndex : slot.columnIndex + 1;
|
|
633
|
+
columns.splice(insertIndex, 0, [sourceUid]);
|
|
634
|
+
cloned.sizes[slot.rowId] = distributeSizesWithNewColumn(cloned.sizes[slot.rowId], insertIndex, columns.length);
|
|
635
|
+
normalizeRowSizes(slot.rowId, cloned);
|
|
636
|
+
break;
|
|
637
|
+
}
|
|
638
|
+
case 'row-gap': {
|
|
639
|
+
const newRowId = createRowId();
|
|
640
|
+
const rowPosition: 'before' | 'after' = slot.position === 'above' ? 'before' : 'after';
|
|
641
|
+
cloned.rows = insertRow(cloned.rows, slot.targetRowId, newRowId, rowPosition, [[sourceUid]]);
|
|
642
|
+
cloned.sizes[newRowId] = [DEFAULT_GRID_COLUMNS];
|
|
643
|
+
break;
|
|
644
|
+
}
|
|
645
|
+
case 'empty-row': {
|
|
646
|
+
const newRowId = createRowId();
|
|
647
|
+
cloned.rows = {
|
|
648
|
+
...cloned.rows,
|
|
649
|
+
[newRowId]: [[sourceUid]],
|
|
650
|
+
};
|
|
651
|
+
cloned.sizes[newRowId] = [DEFAULT_GRID_COLUMNS];
|
|
652
|
+
break;
|
|
653
|
+
}
|
|
654
|
+
default:
|
|
655
|
+
break;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
return cloned;
|
|
659
|
+
};
|