@tmagic/editor 1.8.0-beta.1 → 1.8.0-beta.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/dist/es/Editor.vue_vue_type_script_setup_true_lang.js +31 -5
- package/dist/es/components/CodeBlockEditor.vue_vue_type_script_setup_true_lang.js +21 -113
- package/dist/es/components/CodeParams.vue_vue_type_script_setup_true_lang.js +7 -1
- package/dist/es/components/CompareForm.js +5 -0
- package/dist/es/components/CompareForm.vue_vue_type_script_setup_true_lang.js +196 -0
- package/dist/es/components/ContentMenu.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/FloatingBox.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/components/Icon.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/Resizer.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/ScrollBar.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/ScrollViewer.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/SearchInput.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/SplitView.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/ToolButton.vue_vue_type_script_setup_true_lang.js +7 -7
- package/dist/es/components/Tree.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/TreeNode.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/editorProps.js +2 -0
- package/dist/es/fields/Code.vue_vue_type_script_setup_true_lang.js +20 -4
- package/dist/es/fields/CodeLink.vue_vue_type_script_setup_true_lang.js +3 -6
- package/dist/es/fields/CodeSelect.vue_vue_type_script_setup_true_lang.js +19 -3
- package/dist/es/fields/CodeSelectCol.vue_vue_type_script_setup_true_lang.js +42 -8
- package/dist/es/fields/CondOpSelect.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/DataSourceFieldSelect/FieldSelect.vue_vue_type_script_setup_true_lang.js +14 -6
- package/dist/es/fields/DataSourceFieldSelect/Index.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +41 -16
- package/dist/es/fields/DataSourceInput.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/fields/DataSourceMethodSelect.vue_vue_type_script_setup_true_name_true_lang.js +9 -5
- package/dist/es/fields/DataSourceMethods.vue_vue_type_script_setup_true_lang.js +40 -19
- package/dist/es/fields/DataSourceMocks.vue_vue_type_script_setup_true_lang.js +17 -9
- package/dist/es/fields/DataSourceSelect.vue_vue_type_script_setup_true_lang.js +4 -2
- package/dist/es/fields/DisplayConds.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/EventSelect.vue_vue_type_script_setup_true_lang.js +59 -12
- package/dist/es/fields/KeyValue.vue_vue_type_script_setup_true_lang.js +12 -7
- package/dist/es/fields/PageFragmentSelect.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/Index.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/components/BackgroundPosition.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/components/Border.vue_vue_type_script_setup_true_lang.js +28 -6
- package/dist/es/fields/StyleSetter/components/Box.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/icons/background-repeat/NoRepeat.js +1 -1
- package/dist/es/fields/StyleSetter/icons/background-repeat/Repeat.js +1 -1
- package/dist/es/fields/StyleSetter/icons/background-repeat/RepeatX.js +1 -1
- package/dist/es/fields/StyleSetter/icons/background-repeat/RepeatY.js +1 -1
- package/dist/es/fields/StyleSetter/icons/display/Block.js +1 -1
- package/dist/es/fields/StyleSetter/icons/display/Flex.js +1 -1
- package/dist/es/fields/StyleSetter/icons/display/Inline.js +1 -1
- package/dist/es/fields/StyleSetter/icons/display/InlineBlock.js +1 -1
- package/dist/es/fields/StyleSetter/icons/display/None.js +1 -1
- package/dist/es/fields/StyleSetter/icons/flex-direction/Column.js +1 -1
- package/dist/es/fields/StyleSetter/icons/flex-direction/ColumnReverse.js +1 -1
- package/dist/es/fields/StyleSetter/icons/flex-direction/Row.js +1 -1
- package/dist/es/fields/StyleSetter/icons/flex-direction/RowReverse.js +1 -1
- package/dist/es/fields/StyleSetter/icons/justify-content/Center.js +1 -1
- package/dist/es/fields/StyleSetter/icons/justify-content/FlexEnd.js +1 -1
- package/dist/es/fields/StyleSetter/icons/justify-content/FlexStart.js +1 -1
- package/dist/es/fields/StyleSetter/icons/justify-content/SpaceAround.js +1 -1
- package/dist/es/fields/StyleSetter/icons/justify-content/SpaceBetween.js +1 -1
- package/dist/es/fields/StyleSetter/icons/text-align/Center.js +1 -1
- package/dist/es/fields/StyleSetter/icons/text-align/Left.js +1 -1
- package/dist/es/fields/StyleSetter/icons/text-align/Right.js +1 -1
- package/dist/es/fields/StyleSetter/pro/Background.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/pro/Border.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/pro/Font.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/pro/Layout.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/pro/Position.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/pro/Transform.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/UISelect.vue_vue_type_script_setup_true_lang.js +9 -6
- package/dist/es/hooks/use-code-block-edit.js +7 -4
- package/dist/es/hooks/use-data-source-edit.js +5 -2
- package/dist/es/hooks/use-stage.js +22 -10
- package/dist/es/icons/CenterIcon.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/icons/CodeIcon.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/icons/FolderMinusIcon.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/index.js +14 -3
- package/dist/es/initService.js +7 -7
- package/dist/es/layouts/AddPageBox.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/CodeEditor.vue_vue_type_script_setup_true_lang.js +7 -6
- package/dist/es/layouts/Framework.vue_vue_type_script_setup_true_lang.js +14 -9
- package/dist/es/layouts/NavMenu.vue_vue_type_script_setup_true_lang.js +12 -4
- package/dist/es/layouts/NavMenuColumn.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/history-list/Bucket.js +5 -0
- package/dist/es/layouts/history-list/Bucket.vue_vue_type_script_setup_true_lang.js +71 -0
- package/dist/es/layouts/history-list/BucketTab.js +5 -0
- package/dist/es/layouts/history-list/BucketTab.vue_vue_type_script_setup_true_lang.js +62 -0
- package/dist/es/layouts/history-list/GroupRow.js +5 -0
- package/dist/es/layouts/history-list/GroupRow.vue_vue_type_script_setup_true_lang.js +269 -0
- package/dist/es/layouts/history-list/HistoryDiffDialog.js +5 -0
- package/dist/es/layouts/history-list/HistoryDiffDialog.vue_vue_type_script_setup_true_lang.js +287 -0
- package/dist/es/layouts/history-list/HistoryListPanel.js +5 -0
- package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +327 -0
- package/dist/es/layouts/history-list/InitialRow.js +5 -0
- package/dist/es/layouts/history-list/InitialRow.vue_vue_type_script_setup_true_lang.js +83 -0
- package/dist/es/layouts/history-list/PageTab.js +5 -0
- package/dist/es/layouts/history-list/PageTab.vue_vue_type_script_setup_true_lang.js +95 -0
- package/dist/es/layouts/history-list/composables.js +184 -0
- package/dist/es/layouts/history-list/useHistoryList.js +56 -0
- package/dist/es/layouts/history-list/useHistoryRevert.js +306 -0
- package/dist/es/layouts/page-bar/AddButton.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/page-bar/PageBar.vue_vue_type_script_setup_true_lang.js +5 -3
- package/dist/es/layouts/page-bar/PageBarScrollContainer.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/page-bar/PageList.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/page-bar/Search.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/layouts/props-panel/FormPanel.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/props-panel/PropsPanel.vue_vue_type_script_setup_true_lang.js +6 -2
- package/dist/es/layouts/sidebar/ComponentListPanel.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/layouts/sidebar/Sidebar.vue_vue_type_script_setup_true_lang.js +8 -4
- package/dist/es/layouts/sidebar/code-block/CodeBlockList.vue_vue_type_script_setup_true_lang.js +4 -4
- package/dist/es/layouts/sidebar/code-block/CodeBlockListPanel.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/layouts/sidebar/code-block/useContentMenu.js +1 -1
- package/dist/es/layouts/sidebar/data-source/DataSourceAddButton.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/sidebar/data-source/DataSourceConfigPanel.vue_vue_type_script_setup_true_lang.js +19 -6
- package/dist/es/layouts/sidebar/data-source/DataSourceList.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/sidebar/data-source/DataSourceListPanel.vue_vue_type_script_setup_true_lang.js +25 -3
- package/dist/es/layouts/sidebar/data-source/useContentMenu.js +1 -1
- package/dist/es/layouts/sidebar/layer/LayerMenu.vue_vue_type_script_setup_true_lang.js +6 -6
- package/dist/es/layouts/sidebar/layer/LayerNodeTool.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/layouts/sidebar/layer/LayerPanel.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/sidebar/layer/use-node-status.js +1 -1
- package/dist/es/layouts/workspace/Breadcrumb.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/workspace/Workspace.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/workspace/viewer/NodeListMenu.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/workspace/viewer/Stage.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/layouts/workspace/viewer/StageOverlay.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/workspace/viewer/ViewerMenu.vue_vue_type_script_setup_true_lang.js +9 -9
- package/dist/es/services/BaseService.js +31 -68
- package/dist/es/services/codeBlock.js +286 -8
- package/dist/es/services/componentList.js +2 -2
- package/dist/es/services/dataSource.js +287 -8
- package/dist/es/services/dep.js +21 -9
- package/dist/es/services/editor.js +655 -194
- package/dist/es/services/events.js +2 -2
- package/dist/es/services/history.js +390 -47
- package/dist/es/services/keybinding.js +5 -5
- package/dist/es/services/props.js +8 -8
- package/dist/es/services/stageOverlay.js +2 -2
- package/dist/es/services/storage.js +2 -2
- package/dist/es/services/ui.js +5 -2
- package/dist/es/style.css +456 -8
- package/dist/es/utils/code-block.js +122 -0
- package/dist/es/utils/content-menu.js +19 -12
- package/dist/es/utils/data-source/index.js +2 -0
- package/dist/es/utils/dep/worker.js +1 -1
- package/dist/es/utils/editor.js +105 -51
- package/dist/es/utils/history.js +220 -0
- package/dist/es/utils/indexed-db.js +86 -0
- package/dist/es/utils/undo-redo.js +80 -1
- package/dist/style.css +456 -8
- package/dist/tmagic-editor.umd.cjs +10135 -5646
- package/package.json +8 -8
- package/src/Editor.vue +25 -1
- package/src/components/CodeBlockEditor.vue +20 -109
- package/src/components/CodeParams.vue +6 -0
- package/src/components/CompareForm.vue +277 -0
- package/src/components/ToolButton.vue +2 -2
- package/src/editorProps.ts +9 -0
- package/src/fields/Code.vue +19 -3
- package/src/fields/CodeLink.vue +2 -5
- package/src/fields/CodeSelect.vue +17 -1
- package/src/fields/CodeSelectCol.vue +37 -3
- package/src/fields/DataSourceFieldSelect/FieldSelect.vue +23 -3
- package/src/fields/DataSourceFieldSelect/Index.vue +2 -2
- package/src/fields/DataSourceFields.vue +48 -10
- package/src/fields/DataSourceInput.vue +3 -3
- package/src/fields/DataSourceMethodSelect.vue +12 -4
- package/src/fields/DataSourceMethods.vue +55 -24
- package/src/fields/DataSourceMocks.vue +13 -3
- package/src/fields/DataSourceSelect.vue +4 -1
- package/src/fields/EventSelect.vue +57 -8
- package/src/fields/KeyValue.vue +17 -4
- package/src/fields/StyleSetter/components/Border.vue +15 -6
- package/src/fields/UISelect.vue +5 -2
- package/src/hooks/use-code-block-edit.ts +9 -5
- package/src/hooks/use-data-source-edit.ts +2 -2
- package/src/hooks/use-stage.ts +26 -9
- package/src/index.ts +8 -0
- package/src/initService.ts +1 -1
- package/src/layouts/CodeEditor.vue +17 -5
- package/src/layouts/Framework.vue +11 -6
- package/src/layouts/NavMenu.vue +12 -3
- package/src/layouts/history-list/Bucket.vue +91 -0
- package/src/layouts/history-list/BucketTab.vue +72 -0
- package/src/layouts/history-list/GroupRow.vue +304 -0
- package/src/layouts/history-list/HistoryDiffDialog.vue +273 -0
- package/src/layouts/history-list/HistoryListPanel.vue +367 -0
- package/src/layouts/history-list/InitialRow.vue +71 -0
- package/src/layouts/history-list/PageTab.vue +118 -0
- package/src/layouts/history-list/composables.ts +309 -0
- package/src/layouts/history-list/useHistoryList.ts +60 -0
- package/src/layouts/history-list/useHistoryRevert.ts +405 -0
- package/src/layouts/page-bar/PageBar.vue +4 -2
- package/src/layouts/props-panel/PropsPanel.vue +5 -1
- package/src/layouts/sidebar/ComponentListPanel.vue +9 -5
- package/src/layouts/sidebar/Sidebar.vue +8 -3
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +5 -5
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +1 -1
- package/src/layouts/sidebar/code-block/useContentMenu.ts +1 -1
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +31 -2
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +27 -2
- package/src/layouts/sidebar/data-source/useContentMenu.ts +1 -1
- package/src/layouts/sidebar/layer/LayerMenu.vue +19 -11
- package/src/layouts/sidebar/layer/LayerNodeTool.vue +7 -4
- package/src/layouts/sidebar/layer/use-node-status.ts +9 -6
- package/src/layouts/workspace/viewer/Stage.vue +1 -1
- package/src/layouts/workspace/viewer/ViewerMenu.vue +8 -8
- package/src/services/BaseService.ts +35 -86
- package/src/services/codeBlock.ts +361 -5
- package/src/services/dataSource.ts +336 -6
- package/src/services/dep.ts +32 -9
- package/src/services/editor.ts +834 -194
- package/src/services/history.ts +509 -49
- package/src/services/keybinding.ts +3 -3
- package/src/services/props.ts +2 -2
- package/src/services/ui.ts +7 -0
- package/src/theme/history-list-panel.scss +557 -0
- package/src/theme/page-bar.scss +0 -4
- package/src/theme/props-panel.scss +3 -3
- package/src/theme/style-setter/border.scss +4 -1
- package/src/theme/theme.scss +1 -0
- package/src/type.ts +594 -31
- package/src/utils/code-block.ts +150 -0
- package/src/utils/content-menu.ts +25 -13
- package/src/utils/data-source/index.ts +2 -0
- package/src/utils/dep/worker.ts +5 -3
- package/src/utils/editor.ts +166 -60
- package/src/utils/history.ts +286 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/indexed-db.ts +122 -0
- package/src/utils/undo-redo.ts +111 -0
- package/types/index.d.ts +3171 -889
- package/dist/es/utils/compose.js +0 -44
- package/dist/es/utils/editor-history.js +0 -100
- package/src/utils/compose.ts +0 -52
- package/src/utils/editor-history.ts +0 -138
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2025 Tencent. All rights reserved.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { tMagicMessage } from '@tmagic/design';
|
|
20
|
+
import { defineFormConfig, defineFormItem, type FormConfig, type TableColumnConfig } from '@tmagic/form';
|
|
21
|
+
|
|
22
|
+
import { getEditorConfig } from './config';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 代码块编辑表单配置的统一入口。
|
|
26
|
+
*
|
|
27
|
+
* 用于:
|
|
28
|
+
* - `CodeBlockEditor.vue`:作为代码块新增/编辑的表单结构;
|
|
29
|
+
* - `CompareForm.vue`:在历史差异对比中以"代码块"形态展示前后值。
|
|
30
|
+
*
|
|
31
|
+
* 通过参数控制两端的细微差异(是否启用必填校验 / vs-code onChange 校验 / dataSource 相关字段显示规则等),
|
|
32
|
+
* 避免两边同步两份相同的 schema 而造成漂移。
|
|
33
|
+
*/
|
|
34
|
+
export interface GetCodeBlockFormConfigOptions {
|
|
35
|
+
/**
|
|
36
|
+
* 自定义 `params` 表格的"参数类型"列配置。优先级高于内置默认值;
|
|
37
|
+
* 通常由 `codeBlockService.getParamsColConfig()` 注入业务侧的扩展。
|
|
38
|
+
*/
|
|
39
|
+
paramColConfig?: TableColumnConfig;
|
|
40
|
+
/**
|
|
41
|
+
* 是否在「数据源代码块」语境下使用:
|
|
42
|
+
* - true:`执行时机` 字段会展示,`请求前 / 请求后` 选项仅在 `dataSourceType !== 'base'` 时出现;
|
|
43
|
+
* - false:`执行时机` 字段隐藏(普通代码块没有时机概念)。
|
|
44
|
+
*
|
|
45
|
+
* 注意这里以函数形式传入是为了让 `display` / `options` 在每次渲染时实时取值,
|
|
46
|
+
* 例如外部 `props.isDataSource` 切换或 `dataSourceType` 变更都能立即生效。
|
|
47
|
+
*/
|
|
48
|
+
isDataSource?: () => boolean;
|
|
49
|
+
/** 当 isDataSource 为 true 时使用:返回当前数据源类型(`base` / `http` / ...),决定时机选项是否包含请求前后。 */
|
|
50
|
+
dataSourceType?: () => string | undefined;
|
|
51
|
+
/** vs-code 编辑器的额外 monaco options。一般传 `inject('codeOptions', {})` 的结果。 */
|
|
52
|
+
codeOptions?: Record<string, any>;
|
|
53
|
+
/**
|
|
54
|
+
* 是否启用编辑态特性:
|
|
55
|
+
* - true(默认):`name` 字段加必填校验;vs-code 的 `onChange` 会调用 `parseDSL` 检查语法,出错时弹消息并抛错;
|
|
56
|
+
* - false:纯只读/对比场景,不加校验逻辑。
|
|
57
|
+
*/
|
|
58
|
+
editable?: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 默认的"参数类型"列配置:数字 / 字符串 / 组件 三选一。 */
|
|
62
|
+
const defaultParamColConfig = () =>
|
|
63
|
+
defineFormItem<TableColumnConfig>({
|
|
64
|
+
type: 'row',
|
|
65
|
+
label: '参数类型',
|
|
66
|
+
items: [
|
|
67
|
+
{
|
|
68
|
+
text: '参数类型',
|
|
69
|
+
labelWidth: '70px',
|
|
70
|
+
type: 'select',
|
|
71
|
+
name: 'type',
|
|
72
|
+
options: [
|
|
73
|
+
{ text: '数字', label: '数字', value: 'number' },
|
|
74
|
+
{ text: '字符串', label: '字符串', value: 'text' },
|
|
75
|
+
{ text: '组件', label: '组件', value: 'ui-select' },
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 生成代码块表单配置。返回的是普通对象数组,可直接传给 `<MForm :config>`;
|
|
83
|
+
* 如需响应式的 props 变化(如切换 dataSourceType),调用方在 `computed` 中再次调用本函数即可。
|
|
84
|
+
*/
|
|
85
|
+
export const getCodeBlockFormConfig = (options: GetCodeBlockFormConfigOptions = {}): FormConfig => {
|
|
86
|
+
const { paramColConfig, isDataSource, dataSourceType, codeOptions = {}, editable = true } = options;
|
|
87
|
+
|
|
88
|
+
return defineFormConfig([
|
|
89
|
+
{
|
|
90
|
+
text: '名称',
|
|
91
|
+
name: 'name',
|
|
92
|
+
...(editable ? { rules: [{ required: true, message: '请输入名称', trigger: 'blur' }] } : {}),
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
text: '描述',
|
|
96
|
+
name: 'desc',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
text: '执行时机',
|
|
100
|
+
name: 'timing',
|
|
101
|
+
type: 'select',
|
|
102
|
+
options: () => {
|
|
103
|
+
const list = [
|
|
104
|
+
{ text: '初始化前', value: 'beforeInit' },
|
|
105
|
+
{ text: '初始化后', value: 'afterInit' },
|
|
106
|
+
];
|
|
107
|
+
if (dataSourceType?.() !== 'base') {
|
|
108
|
+
list.push({ text: '请求前', value: 'beforeRequest' });
|
|
109
|
+
list.push({ text: '请求后', value: 'afterRequest' });
|
|
110
|
+
}
|
|
111
|
+
return list;
|
|
112
|
+
},
|
|
113
|
+
display: () => Boolean(isDataSource?.()),
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
type: 'table',
|
|
117
|
+
border: true,
|
|
118
|
+
text: '参数',
|
|
119
|
+
enableFullscreen: false,
|
|
120
|
+
enableToggleMode: false,
|
|
121
|
+
name: 'params',
|
|
122
|
+
dropSort: false,
|
|
123
|
+
items: [
|
|
124
|
+
{ type: 'text', label: '参数名', name: 'name' },
|
|
125
|
+
{ type: 'text', label: '描述', name: 'extra' },
|
|
126
|
+
paramColConfig || defaultParamColConfig(),
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'content',
|
|
131
|
+
type: 'vs-code',
|
|
132
|
+
options: codeOptions,
|
|
133
|
+
autosize: { minRows: 10, maxRows: 30 },
|
|
134
|
+
...(editable
|
|
135
|
+
? {
|
|
136
|
+
onChange: (_formState: any, code: string) => {
|
|
137
|
+
try {
|
|
138
|
+
// 检测 js 代码是否存在语法错误
|
|
139
|
+
getEditorConfig('parseDSL')(code);
|
|
140
|
+
return code;
|
|
141
|
+
} catch (error: any) {
|
|
142
|
+
tMagicMessage.error(error.message);
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
}
|
|
147
|
+
: {}),
|
|
148
|
+
},
|
|
149
|
+
]) as FormConfig;
|
|
150
|
+
};
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { computed, markRaw, type ShallowRef } from 'vue';
|
|
2
2
|
import { CopyDocument, Delete, DocumentCopy } from '@element-plus/icons-vue';
|
|
3
3
|
|
|
4
|
-
import { Id, MContainer, NodeType } from '@tmagic/core';
|
|
4
|
+
import { cloneDeep, Id, MContainer, NodeType } from '@tmagic/core';
|
|
5
5
|
import { calcValueByFontsize, isPage, isPageFragment } from '@tmagic/utils';
|
|
6
6
|
|
|
7
7
|
import ContentMenu from '@editor/components/ContentMenu.vue';
|
|
8
|
-
import type { MenuButton, Services } from '@editor/type';
|
|
8
|
+
import type { HistoryOpSource, MenuButton, Services } from '@editor/type';
|
|
9
9
|
|
|
10
10
|
import { COPY_STORAGE_KEY } from './editor';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* 共享的右键菜单项构造器(画布 ViewerMenu 与图层树 LayerMenu 共用)。
|
|
14
|
+
* `historySource` 用于标记本次操作的途径,调用方按所在面板传入:
|
|
15
|
+
* 画布传 `'stage-contextmenu'`,树形面板传 `'tree-contextmenu'`。
|
|
16
|
+
*/
|
|
17
|
+
export const useDeleteMenu = (historySource?: HistoryOpSource): MenuButton => ({
|
|
13
18
|
type: 'button',
|
|
14
19
|
text: '删除',
|
|
15
20
|
icon: Delete,
|
|
@@ -19,7 +24,7 @@ export const useDeleteMenu = (): MenuButton => ({
|
|
|
19
24
|
},
|
|
20
25
|
handler: ({ editorService }) => {
|
|
21
26
|
const nodes = editorService.get('nodes');
|
|
22
|
-
nodes && editorService.remove(nodes);
|
|
27
|
+
nodes && editorService.remove(nodes, { historySource });
|
|
23
28
|
},
|
|
24
29
|
});
|
|
25
30
|
|
|
@@ -33,7 +38,10 @@ export const useCopyMenu = (): MenuButton => ({
|
|
|
33
38
|
},
|
|
34
39
|
});
|
|
35
40
|
|
|
36
|
-
export const usePasteMenu = (
|
|
41
|
+
export const usePasteMenu = (
|
|
42
|
+
historySource?: HistoryOpSource,
|
|
43
|
+
menu?: ShallowRef<InstanceType<typeof ContentMenu> | null>,
|
|
44
|
+
): MenuButton => ({
|
|
37
45
|
type: 'button',
|
|
38
46
|
text: '粘贴',
|
|
39
47
|
icon: markRaw(DocumentCopy),
|
|
@@ -52,24 +60,28 @@ export const usePasteMenu = (menu?: ShallowRef<InstanceType<typeof ContentMenu>
|
|
|
52
60
|
const initialTop =
|
|
53
61
|
calcValueByFontsize(stage?.renderer?.getDocument(), (rect.top || 0) - (parentRect?.top || 0)) /
|
|
54
62
|
uiService.get('zoom');
|
|
55
|
-
editorService.paste({ left: initialLeft, top: initialTop });
|
|
63
|
+
editorService.paste({ left: initialLeft, top: initialTop }, undefined, { historySource });
|
|
56
64
|
} else {
|
|
57
|
-
editorService.paste();
|
|
65
|
+
editorService.paste(undefined, undefined, { historySource });
|
|
58
66
|
}
|
|
59
67
|
},
|
|
60
68
|
});
|
|
61
69
|
|
|
62
|
-
const moveTo = (id: Id, { editorService }: Services) => {
|
|
70
|
+
const moveTo = async (id: Id, { editorService }: Services, historySource?: HistoryOpSource) => {
|
|
63
71
|
const nodes = editorService.get('nodes') || [];
|
|
64
72
|
const parent = editorService.getNodeById(id) as MContainer;
|
|
65
73
|
|
|
66
|
-
if (!parent) return;
|
|
74
|
+
if (!parent || nodes.length === 0) return;
|
|
67
75
|
|
|
68
|
-
|
|
69
|
-
|
|
76
|
+
// 直接调用 moveToContainer:内部对多选场景已做合并,整批只产生一条历史记录。
|
|
77
|
+
// 不要再走 remove + add 两步,否则会被切成两条历史(且语义也不正确)。
|
|
78
|
+
await editorService.moveToContainer(cloneDeep(nodes), parent.id, {
|
|
79
|
+
doNotSwitchPage: true,
|
|
80
|
+
historySource,
|
|
81
|
+
});
|
|
70
82
|
};
|
|
71
83
|
|
|
72
|
-
export const useMoveToMenu = ({ editorService }: Services): MenuButton => {
|
|
84
|
+
export const useMoveToMenu = ({ editorService }: Services, historySource?: HistoryOpSource): MenuButton => {
|
|
73
85
|
const root = computed(() => editorService.get('root'));
|
|
74
86
|
|
|
75
87
|
return {
|
|
@@ -86,7 +98,7 @@ export const useMoveToMenu = ({ editorService }: Services): MenuButton => {
|
|
|
86
98
|
text: `${page.name}(${page.id})`,
|
|
87
99
|
type: 'button',
|
|
88
100
|
handler: (services: Services) => {
|
|
89
|
-
moveTo(page.id, services);
|
|
101
|
+
moveTo(page.id, services, historySource);
|
|
90
102
|
},
|
|
91
103
|
})),
|
|
92
104
|
};
|
|
@@ -10,6 +10,7 @@ const dataSourceFormConfig: TabConfig = {
|
|
|
10
10
|
items: [
|
|
11
11
|
{
|
|
12
12
|
title: '数据定义',
|
|
13
|
+
status: 'fields',
|
|
13
14
|
items: [
|
|
14
15
|
{
|
|
15
16
|
name: 'fields',
|
|
@@ -20,6 +21,7 @@ const dataSourceFormConfig: TabConfig = {
|
|
|
20
21
|
},
|
|
21
22
|
{
|
|
22
23
|
title: '方法定义',
|
|
24
|
+
status: 'methods',
|
|
23
25
|
items: [
|
|
24
26
|
{
|
|
25
27
|
name: 'methods',
|
package/src/utils/dep/worker.ts
CHANGED
|
@@ -42,9 +42,11 @@ onmessage = (e) => {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
// worker 中 target 均为新建(deps 为空),无需删除阶段,直接批量收集
|
|
46
|
+
const targets = watcher.getCollectableTargets();
|
|
47
|
+
for (const page of mApp.items) {
|
|
48
|
+
watcher.collectItems(page, targets, { pageId: page.id }, true);
|
|
49
|
+
}
|
|
48
50
|
|
|
49
51
|
const data: Record<string, Record<Id, DepData>> = {
|
|
50
52
|
[DepTargetType.DATA_SOURCE]: {},
|
package/src/utils/editor.ts
CHANGED
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
isValueIncludeDataSource,
|
|
36
36
|
} from '@tmagic/utils';
|
|
37
37
|
|
|
38
|
-
import type { EditorNodeInfo } from '@editor/type';
|
|
38
|
+
import type { EditorNodeInfo, StepValue } from '@editor/type';
|
|
39
39
|
import { LayerOffset, Layout } from '@editor/type';
|
|
40
40
|
|
|
41
41
|
export const COPY_STORAGE_KEY = '$MagicEditorCopyData';
|
|
@@ -132,6 +132,34 @@ const getMiddleTop = (node: MNode, parentNode: MNode, stage: StageCore | null) =
|
|
|
132
132
|
return (Math.min(parentHeight, wrapperHeightDeal) - height) / 2;
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
+
// 同时存在一对相反的定位属性(如 left/right)时只保留一个,避免元素被拉伸
|
|
136
|
+
const removeConflictPosition = (style: Record<string, any>, primary: string, secondary: string) => {
|
|
137
|
+
// '' / 0 / undefined / null 视为无效值
|
|
138
|
+
const isInvalid = (value: any) => value === '' || value === 0 || value === undefined || value === null;
|
|
139
|
+
|
|
140
|
+
if (!(primary in style) || !(secondary in style)) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const primaryValue = style[primary];
|
|
145
|
+
const secondaryValue = style[secondary];
|
|
146
|
+
const primaryInvalid = isInvalid(primaryValue);
|
|
147
|
+
const secondaryInvalid = isInvalid(secondaryValue);
|
|
148
|
+
|
|
149
|
+
if (primaryInvalid && !secondaryInvalid) {
|
|
150
|
+
delete style[primary];
|
|
151
|
+
} else if (secondaryInvalid && !primaryInvalid) {
|
|
152
|
+
delete style[secondary];
|
|
153
|
+
} else if (primaryInvalid && secondaryInvalid) {
|
|
154
|
+
// 都是无效值时优先保留 0,否则保留 primary(left/top)
|
|
155
|
+
if (secondaryValue === 0 && primaryValue !== 0) {
|
|
156
|
+
delete style[primary];
|
|
157
|
+
} else {
|
|
158
|
+
delete style[secondary];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
135
163
|
export const getInitPositionStyle = (style: Record<string, any> = {}, layout: Layout) => {
|
|
136
164
|
if (layout === Layout.ABSOLUTE) {
|
|
137
165
|
const newStyle: Record<string, any> = {
|
|
@@ -139,6 +167,9 @@ export const getInitPositionStyle = (style: Record<string, any> = {}, layout: La
|
|
|
139
167
|
position: 'absolute',
|
|
140
168
|
};
|
|
141
169
|
|
|
170
|
+
removeConflictPosition(newStyle, 'left', 'right');
|
|
171
|
+
removeConflictPosition(newStyle, 'top', 'bottom');
|
|
172
|
+
|
|
142
173
|
if (typeof newStyle.left === 'undefined' && typeof newStyle.right === 'undefined') {
|
|
143
174
|
newStyle.left = 0;
|
|
144
175
|
}
|
|
@@ -178,43 +209,68 @@ export const setLayout = (node: MNode, layout: Layout) => {
|
|
|
178
209
|
return node;
|
|
179
210
|
};
|
|
180
211
|
|
|
181
|
-
|
|
182
|
-
const style = {
|
|
183
|
-
...(node.style || {}),
|
|
184
|
-
};
|
|
212
|
+
type PositionKey = 'left' | 'top' | 'right' | 'bottom';
|
|
185
213
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
top: 0,
|
|
190
|
-
};
|
|
214
|
+
// 判断 style 是否显式设置了某个定位属性,使用 typeof 判断以避免将 0(如 right: 0)误判为未设置
|
|
215
|
+
const hasPositionValue = (style: Record<string, any> | undefined, key: PositionKey): boolean =>
|
|
216
|
+
typeof style?.[key] !== 'undefined' && style?.[key] !== '';
|
|
191
217
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
218
|
+
/**
|
|
219
|
+
* 沿节点路径累加(或抵消)某一方向上的定位偏移量
|
|
220
|
+
* 当路径上的祖先使用了反方向定位(例如计算 left 时祖先用了 right)或非数值定位时,
|
|
221
|
+
* 无法简单地通过求和换算坐标,此时返回 0 表示放弃补偿、保持原值
|
|
222
|
+
* @param path 从根到目标节点的路径(含节点自身)
|
|
223
|
+
* @param dir 需要累加的定位方向
|
|
224
|
+
* @param opposite 反方向定位属性
|
|
225
|
+
* @param sign change2Fixed 取 1(累加祖先偏移),Fixed2Other 取 -1(抵消祖先偏移)
|
|
226
|
+
* @param init 偏移量初始值
|
|
227
|
+
*/
|
|
228
|
+
const accumulatePositionOffset = (
|
|
229
|
+
path: MNode[],
|
|
230
|
+
dir: PositionKey,
|
|
231
|
+
opposite: PositionKey,
|
|
232
|
+
sign: 1 | -1,
|
|
233
|
+
init = 0,
|
|
234
|
+
): number => {
|
|
235
|
+
let offset = init;
|
|
236
|
+
for (const value of path) {
|
|
237
|
+
if (hasPositionValue(value.style, opposite) || !isNumber(value.style?.[dir] || 0)) {
|
|
238
|
+
return 0;
|
|
199
239
|
}
|
|
240
|
+
offset = offset + sign * Number(value.style?.[dir] || 0);
|
|
200
241
|
}
|
|
242
|
+
return offset;
|
|
243
|
+
};
|
|
201
244
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
offset.top = offset.top + Number(value.style?.top || 0);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
245
|
+
export const change2Fixed = (node: MNode, path: MNode[]) => {
|
|
246
|
+
const style = {
|
|
247
|
+
...(node.style || {}),
|
|
248
|
+
};
|
|
211
249
|
|
|
212
|
-
|
|
213
|
-
|
|
250
|
+
// 水平方向:以 left 锚定则累加祖先 left,以 right 锚定则累加祖先 right
|
|
251
|
+
if (!hasPositionValue(node.style, 'right') && isNumber(node.style?.left || 0)) {
|
|
252
|
+
const left = accumulatePositionOffset(path, 'left', 'right', 1);
|
|
253
|
+
if (left) {
|
|
254
|
+
style.left = left;
|
|
255
|
+
}
|
|
256
|
+
} else if (hasPositionValue(node.style, 'right') && isNumber(node.style?.right || 0)) {
|
|
257
|
+
const right = accumulatePositionOffset(path, 'right', 'left', 1);
|
|
258
|
+
if (right) {
|
|
259
|
+
style.right = right;
|
|
260
|
+
}
|
|
214
261
|
}
|
|
215
262
|
|
|
216
|
-
|
|
217
|
-
|
|
263
|
+
// 垂直方向:以 top 锚定则累加祖先 top,以 bottom 锚定则累加祖先 bottom
|
|
264
|
+
if (!hasPositionValue(node.style, 'bottom') && isNumber(node.style?.top || 0)) {
|
|
265
|
+
const top = accumulatePositionOffset(path, 'top', 'bottom', 1);
|
|
266
|
+
if (top) {
|
|
267
|
+
style.top = top;
|
|
268
|
+
}
|
|
269
|
+
} else if (hasPositionValue(node.style, 'bottom') && isNumber(node.style?.bottom || 0)) {
|
|
270
|
+
const bottom = accumulatePositionOffset(path, 'bottom', 'top', 1);
|
|
271
|
+
if (bottom) {
|
|
272
|
+
style.bottom = bottom;
|
|
273
|
+
}
|
|
218
274
|
}
|
|
219
275
|
|
|
220
276
|
return style;
|
|
@@ -222,34 +278,29 @@ export const change2Fixed = (node: MNode, root: MApp) => {
|
|
|
222
278
|
|
|
223
279
|
export const Fixed2Other = async (
|
|
224
280
|
node: MNode,
|
|
225
|
-
|
|
281
|
+
path: MNode[],
|
|
226
282
|
getLayout: (parent: MNode, node?: MNode) => Promise<Layout>,
|
|
227
283
|
) => {
|
|
228
|
-
const path = getNodePath(node.id, root.items);
|
|
229
284
|
const cur = path.pop();
|
|
230
285
|
const offset = {
|
|
231
|
-
left:
|
|
232
|
-
top:
|
|
286
|
+
left: 0,
|
|
287
|
+
top: 0,
|
|
288
|
+
right: 0,
|
|
289
|
+
bottom: 0,
|
|
233
290
|
};
|
|
234
291
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
offset.left = offset.left - Number(value.style?.left || 0);
|
|
242
|
-
}
|
|
292
|
+
// 水平方向:抵消祖先在对应锚定方向上的偏移量,初始值为节点自身的偏移
|
|
293
|
+
if (!hasPositionValue(node.style, 'right') && isNumber(node.style?.left || 0)) {
|
|
294
|
+
offset.left = accumulatePositionOffset(path, 'left', 'right', -1, Number(cur?.style?.left || 0));
|
|
295
|
+
} else if (hasPositionValue(node.style, 'right') && isNumber(node.style?.right || 0)) {
|
|
296
|
+
offset.right = accumulatePositionOffset(path, 'right', 'left', -1, Number(cur?.style?.right || 0));
|
|
243
297
|
}
|
|
244
298
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
offset.top = offset.top - Number(value.style?.top || 0);
|
|
252
|
-
}
|
|
299
|
+
// 垂直方向:同上
|
|
300
|
+
if (!hasPositionValue(node.style, 'bottom') && isNumber(node.style?.top || 0)) {
|
|
301
|
+
offset.top = accumulatePositionOffset(path, 'top', 'bottom', -1, Number(cur?.style?.top || 0));
|
|
302
|
+
} else if (hasPositionValue(node.style, 'bottom') && isNumber(node.style?.bottom || 0)) {
|
|
303
|
+
offset.bottom = accumulatePositionOffset(path, 'bottom', 'top', -1, Number(cur?.style?.bottom || 0));
|
|
253
304
|
}
|
|
254
305
|
|
|
255
306
|
const style = node.style || {};
|
|
@@ -269,6 +320,14 @@ export const Fixed2Other = async (
|
|
|
269
320
|
style.top = offset.top;
|
|
270
321
|
}
|
|
271
322
|
|
|
323
|
+
if (offset.right) {
|
|
324
|
+
style.right = offset.right;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (offset.bottom) {
|
|
328
|
+
style.bottom = offset.bottom;
|
|
329
|
+
}
|
|
330
|
+
|
|
272
331
|
return {
|
|
273
332
|
...style,
|
|
274
333
|
position: 'absolute',
|
|
@@ -316,11 +375,18 @@ export const fixNodePosition = (config: MNode, parent: MContainer, stage: StageC
|
|
|
316
375
|
return config.style;
|
|
317
376
|
}
|
|
318
377
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
378
|
+
const style = { ...(config.style || {}) };
|
|
379
|
+
const baseStyle = config.style || {};
|
|
380
|
+
|
|
381
|
+
if (!('right' in baseStyle)) {
|
|
382
|
+
style.left = fixNodeLeft(config, parent, stage?.renderer?.contentWindow?.document);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (!('top' in baseStyle) && !('bottom' in baseStyle)) {
|
|
386
|
+
style.top = getMiddleTop(config, parent, stage);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return style;
|
|
324
390
|
};
|
|
325
391
|
|
|
326
392
|
// 序列化配置
|
|
@@ -460,11 +526,11 @@ export const resolveSelectedNode = (
|
|
|
460
526
|
throw new Error('没有ID,无法选中');
|
|
461
527
|
}
|
|
462
528
|
|
|
463
|
-
const { node, parent, page } = getNodeInfoFn(id);
|
|
529
|
+
const { node, parent, page, path } = getNodeInfoFn(id);
|
|
464
530
|
if (!node) throw new Error('获取不到组件信息');
|
|
465
531
|
if (node.id === rootId) throw new Error('不能选根节点');
|
|
466
532
|
|
|
467
|
-
return { node, parent, page };
|
|
533
|
+
return { node, parent, page, path };
|
|
468
534
|
};
|
|
469
535
|
|
|
470
536
|
/**
|
|
@@ -479,16 +545,16 @@ export const resolveSelectedNode = (
|
|
|
479
545
|
export const toggleFixedPosition = async (
|
|
480
546
|
dist: MNode,
|
|
481
547
|
src: MNode,
|
|
482
|
-
|
|
548
|
+
path: MNode[],
|
|
483
549
|
getLayoutFn: (parent: MNode, node?: MNode | null) => Promise<Layout>,
|
|
484
550
|
): Promise<MNode> => {
|
|
485
551
|
const newConfig = cloneDeep(dist);
|
|
486
552
|
|
|
487
553
|
if (!isPop(src) && newConfig.style?.position) {
|
|
488
554
|
if (isFixed(newConfig.style) && !isFixed(src.style || {})) {
|
|
489
|
-
newConfig.style = change2Fixed(newConfig,
|
|
555
|
+
newConfig.style = change2Fixed(newConfig, path);
|
|
490
556
|
} else if (!isFixed(newConfig.style) && isFixed(src.style || {})) {
|
|
491
|
-
newConfig.style = await Fixed2Other(newConfig,
|
|
557
|
+
newConfig.style = await Fixed2Other(newConfig, path, getLayoutFn);
|
|
492
558
|
}
|
|
493
559
|
}
|
|
494
560
|
|
|
@@ -684,3 +750,43 @@ export const classifyDragSources = (
|
|
|
684
750
|
|
|
685
751
|
return { sameParentIndices, crossParentConfigs, aborted: false };
|
|
686
752
|
};
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* 给「回滚」生成的新 step 用的简短描述生成器。
|
|
756
|
+
* 与 UI 层 `describePageStep` 同义,但避免 service 反向依赖 layouts/,故放在此工具函数中。
|
|
757
|
+
*/
|
|
758
|
+
export const describeStepForRevert = (step: StepValue): string => {
|
|
759
|
+
const items = step.diff ?? [];
|
|
760
|
+
// 在可读名后拼接组件 id,便于在历史面板中精确定位被回滚的组件;id 缺失时退化为仅展示名称。
|
|
761
|
+
const withId = (node: MNode | undefined, label: string): string => {
|
|
762
|
+
const id = node?.id;
|
|
763
|
+
if (id === undefined || id === null || `${id}` === '') return label;
|
|
764
|
+
return label ? `${label}(id: ${id})` : `id: ${id}`;
|
|
765
|
+
};
|
|
766
|
+
switch (step.opType) {
|
|
767
|
+
case 'add': {
|
|
768
|
+
const count = items.length;
|
|
769
|
+
const node = items[0]?.newSchema;
|
|
770
|
+
const label = node?.name || node?.type || '';
|
|
771
|
+
return `撤回新增 ${count} 个节点${count === 1 ? `(${withId(node, label)})` : ''}`;
|
|
772
|
+
}
|
|
773
|
+
case 'remove': {
|
|
774
|
+
const count = items.length;
|
|
775
|
+
const node = items[0]?.oldSchema;
|
|
776
|
+
const label = node?.name || node?.type || '';
|
|
777
|
+
return `还原已删除的 ${count} 个节点${count === 1 ? `(${withId(node, label)})` : ''}`;
|
|
778
|
+
}
|
|
779
|
+
case 'update':
|
|
780
|
+
default: {
|
|
781
|
+
if (items.length === 1) {
|
|
782
|
+
const { newSchema, oldSchema, changeRecords } = items[0];
|
|
783
|
+
const node = newSchema || oldSchema;
|
|
784
|
+
const label = newSchema?.name || newSchema?.type || oldSchema?.name || oldSchema?.type || '';
|
|
785
|
+
const target = withId(node, label);
|
|
786
|
+
const propPath = changeRecords?.[0]?.propPath;
|
|
787
|
+
return propPath ? `还原 ${target} · ${propPath}` : `还原 ${target}`;
|
|
788
|
+
}
|
|
789
|
+
return `还原 ${items.length} 个节点的修改`;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
};
|