@tmagic/editor 1.8.0-beta.1 → 1.8.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +294 -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 +313 -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 +11149 -6646
- 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 +281 -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 +421 -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 +613 -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 +3197 -896
- 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
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { CODE_DRAFT_STORAGE_KEY } from "../type.js";
|
|
2
|
-
import
|
|
2
|
+
import BaseService from "./BaseService.js";
|
|
3
3
|
import { getEditorConfig } from "../utils/config.js";
|
|
4
|
+
import { createStackStep, describeRevertStep, getLastPushedHistoryIds } from "../utils/history.js";
|
|
5
|
+
import history_default from "./history.js";
|
|
4
6
|
import storage_default, { Protocol } from "./storage.js";
|
|
5
7
|
import { COPY_CODE_STORAGE_KEY } from "../utils/editor.js";
|
|
6
8
|
import editor_default from "./editor.js";
|
|
9
|
+
import { getValueByKeyPath, setValueByKeyPath } from "@tmagic/utils";
|
|
7
10
|
import { Target, Watcher } from "@tmagic/core";
|
|
8
11
|
import { reactive } from "vue";
|
|
9
|
-
import { cloneDeep, get, keys, pick } from "lodash-es";
|
|
12
|
+
import { cloneDeep as cloneDeep$1, get, keys, pick } from "lodash-es";
|
|
10
13
|
//#region packages/editor/src/services/codeBlock.ts
|
|
11
14
|
var canUsePluginMethods = {
|
|
12
15
|
async: [
|
|
@@ -18,7 +21,7 @@ var canUsePluginMethods = {
|
|
|
18
21
|
],
|
|
19
22
|
sync: ["setCodeDslByIdSync"]
|
|
20
23
|
};
|
|
21
|
-
var CodeBlock = class extends
|
|
24
|
+
var CodeBlock = class extends BaseService {
|
|
22
25
|
state = reactive({
|
|
23
26
|
codeDsl: null,
|
|
24
27
|
editable: true,
|
|
@@ -26,6 +29,16 @@ var CodeBlock = class extends BaseService_default {
|
|
|
26
29
|
undeletableList: [],
|
|
27
30
|
paramsColConfig: void 0
|
|
28
31
|
});
|
|
32
|
+
/**
|
|
33
|
+
* 最近一次写入历史栈的代码块历史记录 uuid(单条写入场景:新增 / 更新)。
|
|
34
|
+
* 供 setCodeDslById(Sync)AndGetHistoryId 取回,普通方法不读取它。
|
|
35
|
+
*/
|
|
36
|
+
lastPushedHistoryId = null;
|
|
37
|
+
/**
|
|
38
|
+
* deleteCodeDslByIds 一次删除多个代码块时,按写入顺序收集的历史记录 uuid 列表。
|
|
39
|
+
* 在 deleteCodeDslByIds 入口处重置,供 deleteCodeDslByIdsAndGetHistoryId 取回。
|
|
40
|
+
*/
|
|
41
|
+
lastDeletedHistoryIds = [];
|
|
29
42
|
constructor() {
|
|
30
43
|
super([...canUsePluginMethods.async.map((methodName) => ({
|
|
31
44
|
name: methodName,
|
|
@@ -43,6 +56,7 @@ var CodeBlock = class extends BaseService_default {
|
|
|
43
56
|
async setCodeDsl(codeDsl) {
|
|
44
57
|
this.state.codeDsl = codeDsl;
|
|
45
58
|
this.emit("code-dsl-change", this.state.codeDsl);
|
|
59
|
+
this.emit("change", this.state.codeDsl);
|
|
46
60
|
}
|
|
47
61
|
/**
|
|
48
62
|
* 获取活动的代码块dsl数据源(默认从dsl中的codeBlocks字段读取)
|
|
@@ -68,10 +82,18 @@ var CodeBlock = class extends BaseService_default {
|
|
|
68
82
|
* 设置代码块ID和代码内容到源dsl
|
|
69
83
|
* @param {Id} id 代码块id
|
|
70
84
|
* @param {CodeBlockContent} codeConfig 代码块内容配置信息
|
|
85
|
+
* @param options 可选配置
|
|
86
|
+
* @param options.changeRecords form 端 propPath/value 列表,用于历史记录的精细化撤销/重做
|
|
87
|
+
* @param options.doNotPushHistory 是否不写入历史记录(默认 false)
|
|
71
88
|
* @returns {void}
|
|
72
89
|
*/
|
|
73
|
-
async setCodeDslById(id, codeConfig) {
|
|
74
|
-
this.setCodeDslByIdSync(id, codeConfig, true
|
|
90
|
+
async setCodeDslById(id, codeConfig, { changeRecords, doNotPushHistory = false, historyDescription, historySource } = {}) {
|
|
91
|
+
this.setCodeDslByIdSync(id, codeConfig, true, {
|
|
92
|
+
changeRecords,
|
|
93
|
+
doNotPushHistory,
|
|
94
|
+
historyDescription,
|
|
95
|
+
historySource
|
|
96
|
+
});
|
|
75
97
|
}
|
|
76
98
|
/**
|
|
77
99
|
* 为了兼容历史原因
|
|
@@ -79,22 +101,39 @@ var CodeBlock = class extends BaseService_default {
|
|
|
79
101
|
* @param {Id} id 代码块id
|
|
80
102
|
* @param {CodeBlockContent} codeConfig 代码块内容配置信息
|
|
81
103
|
* @param {boolean} force 是否强制写入,默认true
|
|
104
|
+
* @param options 可选配置
|
|
105
|
+
* @param options.changeRecords form 端 propPath/value 列表,用于历史记录的精细化撤销/重做
|
|
106
|
+
* @param options.doNotPushHistory 是否不写入历史记录(默认 false)
|
|
107
|
+
* @param options.historyDescription 入栈时附带的人类可读描述,用于历史面板展示
|
|
82
108
|
* @returns {void}
|
|
83
109
|
*/
|
|
84
|
-
setCodeDslByIdSync(id, codeConfig, force = true) {
|
|
110
|
+
setCodeDslByIdSync(id, codeConfig, force = true, { changeRecords, doNotPushHistory = false, historyDescription, historySource } = {}) {
|
|
85
111
|
const codeDsl = this.getCodeDsl();
|
|
86
112
|
if (!codeDsl) throw new Error("dsl中没有codeBlocks");
|
|
87
113
|
if (codeDsl[id] && !force) return;
|
|
88
|
-
const codeConfigProcessed = cloneDeep(codeConfig);
|
|
114
|
+
const codeConfigProcessed = cloneDeep$1(codeConfig);
|
|
89
115
|
if (codeConfigProcessed.content) {
|
|
90
116
|
const parseDSL = getEditorConfig("parseDSL");
|
|
91
117
|
if (typeof codeConfigProcessed.content === "string") codeConfigProcessed.content = parseDSL(codeConfigProcessed.content);
|
|
92
118
|
}
|
|
119
|
+
const oldContent = codeDsl[id] ? cloneDeep$1(codeDsl[id]) : null;
|
|
93
120
|
codeDsl[id] = {
|
|
94
121
|
...codeDsl[id] || {},
|
|
95
122
|
...codeConfigProcessed
|
|
96
123
|
};
|
|
124
|
+
const newContent = cloneDeep$1(codeDsl[id]);
|
|
125
|
+
if (!doNotPushHistory) {
|
|
126
|
+
const step = createStackStep(id, {
|
|
127
|
+
oldValue: oldContent,
|
|
128
|
+
newValue: newContent,
|
|
129
|
+
changeRecords,
|
|
130
|
+
historyDescription,
|
|
131
|
+
source: historySource
|
|
132
|
+
});
|
|
133
|
+
this.lastPushedHistoryId = (step ? history_default.push("codeBlock", step, id) : null)?.uuid ?? null;
|
|
134
|
+
}
|
|
97
135
|
this.emit("addOrUpdate", id, codeDsl[id]);
|
|
136
|
+
this.emit("change", this.getCodeDsl());
|
|
98
137
|
}
|
|
99
138
|
/**
|
|
100
139
|
* 根据代码块id数组获取代码dsl
|
|
@@ -170,14 +209,66 @@ var CodeBlock = class extends BaseService_default {
|
|
|
170
209
|
/**
|
|
171
210
|
* 在dsl数据源中删除指定id的代码块
|
|
172
211
|
* @param {Id[]} codeIds 需要删除的代码块id数组
|
|
212
|
+
* @param options 可选配置
|
|
213
|
+
* @param options.doNotPushHistory 是否不写入历史记录(默认 false)
|
|
173
214
|
*/
|
|
174
|
-
async deleteCodeDslByIds(codeIds) {
|
|
215
|
+
async deleteCodeDslByIds(codeIds, { doNotPushHistory = false, historyDescription, historySource } = {}) {
|
|
175
216
|
const currentDsl = await this.getCodeDsl();
|
|
176
217
|
if (!currentDsl) return;
|
|
218
|
+
this.lastDeletedHistoryIds = [];
|
|
177
219
|
codeIds.forEach((id) => {
|
|
220
|
+
const oldValue = currentDsl[id] ? cloneDeep$1(currentDsl[id]) : null;
|
|
178
221
|
delete currentDsl[id];
|
|
222
|
+
if (oldValue && !doNotPushHistory) {
|
|
223
|
+
const step = createStackStep(id, {
|
|
224
|
+
oldValue,
|
|
225
|
+
newValue: null,
|
|
226
|
+
historyDescription,
|
|
227
|
+
source: historySource
|
|
228
|
+
});
|
|
229
|
+
const uuid = step ? history_default.push("codeBlock", step, id)?.uuid : void 0;
|
|
230
|
+
if (uuid) this.lastDeletedHistoryIds.push(uuid);
|
|
231
|
+
}
|
|
179
232
|
this.emit("remove", id);
|
|
180
233
|
});
|
|
234
|
+
this.emit("change", this.getCodeDsl());
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* 下列 *AndGetHistoryId 方法与对应的写入方法行为完全一致,
|
|
238
|
+
* 返回值在 {@link DslOpWithHistoryIdsResult} 中同时包含原操作结果与本次写入的历史 uuid 列表,
|
|
239
|
+
* 可用于精确引用 / 定位该条历史记录(埋点、revert、跨端同步等)。
|
|
240
|
+
*
|
|
241
|
+
* 当本次操作未写入历史(doNotPushHistory 为 true、或无对应记录)时 historyIds 为 `[]`。
|
|
242
|
+
*/
|
|
243
|
+
/** 等价于 {@link setCodeDslById},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
|
|
244
|
+
async setCodeDslByIdAndGetHistoryId(id, codeConfig, options = {}) {
|
|
245
|
+
this.lastPushedHistoryId = null;
|
|
246
|
+
await this.setCodeDslById(id, codeConfig, options);
|
|
247
|
+
return {
|
|
248
|
+
result: void 0,
|
|
249
|
+
historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId)
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/** 等价于 {@link setCodeDslByIdSync},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
|
|
253
|
+
setCodeDslByIdSyncAndGetHistoryId(id, codeConfig, force = true, options = {}) {
|
|
254
|
+
this.lastPushedHistoryId = null;
|
|
255
|
+
this.setCodeDslByIdSync(id, codeConfig, force, options);
|
|
256
|
+
return {
|
|
257
|
+
result: void 0,
|
|
258
|
+
historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId)
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* 等价于 {@link deleteCodeDslByIds},并额外返回本次写入的全部历史记录 uuid(按删除顺序)。
|
|
263
|
+
* 一次删除多个代码块会产生多条历史记录;未写入任何历史时 historyIds 为 `[]`。
|
|
264
|
+
*/
|
|
265
|
+
async deleteCodeDslByIdsAndGetHistoryId(codeIds, options = {}) {
|
|
266
|
+
this.lastDeletedHistoryIds = [];
|
|
267
|
+
await this.deleteCodeDslByIds(codeIds, options);
|
|
268
|
+
return {
|
|
269
|
+
result: void 0,
|
|
270
|
+
historyIds: [...this.lastDeletedHistoryIds]
|
|
271
|
+
};
|
|
181
272
|
}
|
|
182
273
|
setParamsColConfig(config) {
|
|
183
274
|
this.state.paramsColConfig = config;
|
|
@@ -186,6 +277,95 @@ var CodeBlock = class extends BaseService_default {
|
|
|
186
277
|
return this.state.paramsColConfig;
|
|
187
278
|
}
|
|
188
279
|
/**
|
|
280
|
+
* 撤销指定代码块的最近一次变更。
|
|
281
|
+
*
|
|
282
|
+
* 内部走 setCodeDslByIdSync / deleteCodeDslByIds,因此会自动触发 codeBlockService 的
|
|
283
|
+
* `addOrUpdate` / `remove` 事件,由 initService 中的 handler 重新维护 dep target
|
|
284
|
+
* (DepTargetType.CODE_BLOCK 的 add / remove)。所有写回都带 `doNotPushHistory: true`,
|
|
285
|
+
* 确保不会在历史栈里产生新的记录。
|
|
286
|
+
*
|
|
287
|
+
* @param id 代码块 id
|
|
288
|
+
* @returns 撤销的 step;栈不存在或已无可撤销时返回 null
|
|
289
|
+
*/
|
|
290
|
+
async undo(id) {
|
|
291
|
+
const step = history_default.undo("codeBlock", id);
|
|
292
|
+
if (!step) return null;
|
|
293
|
+
await this.applyHistoryStep(step, true);
|
|
294
|
+
return step;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* 重做指定代码块的下一次变更。
|
|
298
|
+
* @param id 代码块 id
|
|
299
|
+
* @returns 重做的 step;栈不存在或已无可重做时返回 null
|
|
300
|
+
*/
|
|
301
|
+
async redo(id) {
|
|
302
|
+
const step = history_default.redo("codeBlock", id);
|
|
303
|
+
if (!step) return null;
|
|
304
|
+
await this.applyHistoryStep(step, false);
|
|
305
|
+
return step;
|
|
306
|
+
}
|
|
307
|
+
/** 是否可对指定代码块撤销。 */
|
|
308
|
+
canUndo(id) {
|
|
309
|
+
return history_default.canUndo("codeBlock", id);
|
|
310
|
+
}
|
|
311
|
+
/** 是否可对指定代码块重做。 */
|
|
312
|
+
canRedo(id) {
|
|
313
|
+
return history_default.canRedo("codeBlock", id);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* 跳转指定代码块的历史栈到目标游标。语义同 editor.gotoPageStep。
|
|
317
|
+
*
|
|
318
|
+
* @param id 代码块 id
|
|
319
|
+
* @param targetCursor 目标游标位置(已应用步骤数量)
|
|
320
|
+
* @returns 实际移动到的最终游标位置
|
|
321
|
+
*/
|
|
322
|
+
async goto(id, targetCursor) {
|
|
323
|
+
let cursor = history_default.getCursor("codeBlock", id);
|
|
324
|
+
const target = Math.max(0, targetCursor);
|
|
325
|
+
while (cursor > target) {
|
|
326
|
+
if (!await this.undo(id)) break;
|
|
327
|
+
cursor -= 1;
|
|
328
|
+
}
|
|
329
|
+
while (cursor < target) {
|
|
330
|
+
if (!await this.redo(id)) break;
|
|
331
|
+
cursor += 1;
|
|
332
|
+
}
|
|
333
|
+
return cursor;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* 「回滚」指定代码块历史步骤(类 git revert 语义):
|
|
337
|
+
* - 不动原始栈结构(不移动 cursor、不丢弃任何步骤);
|
|
338
|
+
* - 把目标 step 的修改**反向应用**一次,并作为**新步骤**追加到栈顶;
|
|
339
|
+
* - 仅对已应用的步骤生效。
|
|
340
|
+
*
|
|
341
|
+
* @param id 代码块 id
|
|
342
|
+
* @param index 目标 step 在该栈中的索引(0 为最早),通常由历史面板传入
|
|
343
|
+
* @returns 反向后产生的新 step;目标不存在 / 未应用时返回 null
|
|
344
|
+
*/
|
|
345
|
+
async revert(id, index) {
|
|
346
|
+
const entry = history_default.getStepList("codeBlock", id)[index];
|
|
347
|
+
if (!entry?.applied) return null;
|
|
348
|
+
const { oldSchema, newSchema, changeRecords } = entry.step.diff?.[0] ?? {};
|
|
349
|
+
if (oldSchema && newSchema && !changeRecords?.length) return null;
|
|
350
|
+
const description = `回滚 #${index + 1}: ${describeRevertStep(entry.step.data.id, entry.step.diff?.[0], (s) => s.name)}`;
|
|
351
|
+
return await this.applyRevertStep(entry.step, description);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* 通过历史记录 uuid 回滚代码块历史步骤,语义同 {@link revert},
|
|
355
|
+
* 仅无需调用方再传 codeBlockId 与 index:内部会按 uuid 在全部代码块栈中定位对应步骤后再回滚。
|
|
356
|
+
* 按数组顺序依次回滚,返回与入参同序的结果列表(某项失败时为 `null`)。
|
|
357
|
+
*
|
|
358
|
+
* @param uuids 目标历史记录的 uuid 列表,通常由 {@link setCodeDslByIdAndGetHistoryId} 等方法返回的 `historyIds`
|
|
359
|
+
*/
|
|
360
|
+
async revertById(uuids) {
|
|
361
|
+
const results = [];
|
|
362
|
+
for (const uuid of uuids) {
|
|
363
|
+
const location = history_default.findStepLocationByUuid("codeBlock", uuid);
|
|
364
|
+
results.push(location ? await this.revert(location.id, location.index) : null);
|
|
365
|
+
}
|
|
366
|
+
return results;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
189
369
|
* 生成代码块唯一id
|
|
190
370
|
* @returns {Id} 代码块唯一id
|
|
191
371
|
*/
|
|
@@ -245,6 +425,104 @@ var CodeBlock = class extends BaseService_default {
|
|
|
245
425
|
usePlugin(options) {
|
|
246
426
|
super.usePlugin(options);
|
|
247
427
|
}
|
|
428
|
+
/**
|
|
429
|
+
* 反向应用一个 step 并以新 step 入栈。逻辑与 applyHistoryStep(reverse=true) 同构,
|
|
430
|
+
* 差异仅在于通过公开的 setCodeDslByIdSync / deleteCodeDslByIds 触发 push。
|
|
431
|
+
*/
|
|
432
|
+
async applyRevertStep(step, historyDescription) {
|
|
433
|
+
const { id } = step.data;
|
|
434
|
+
const { oldSchema, newSchema, changeRecords } = step.diff?.[0] ?? {};
|
|
435
|
+
if (!oldSchema && newSchema) {
|
|
436
|
+
await this.deleteCodeDslByIds([id], {
|
|
437
|
+
historyDescription,
|
|
438
|
+
historySource: "rollback"
|
|
439
|
+
});
|
|
440
|
+
return history_default.getStepList("codeBlock", id).slice(-1)[0]?.step ?? null;
|
|
441
|
+
}
|
|
442
|
+
if (oldSchema && !newSchema) {
|
|
443
|
+
this.setCodeDslByIdSync(id, cloneDeep$1(oldSchema), true, {
|
|
444
|
+
historyDescription,
|
|
445
|
+
historySource: "rollback"
|
|
446
|
+
});
|
|
447
|
+
return history_default.getStepList("codeBlock", id).slice(-1)[0]?.step ?? null;
|
|
448
|
+
}
|
|
449
|
+
if (!oldSchema || !newSchema) return null;
|
|
450
|
+
if (changeRecords?.length) {
|
|
451
|
+
const current = this.getCodeContentById(id);
|
|
452
|
+
if (!current) return null;
|
|
453
|
+
const patched = cloneDeep$1(current);
|
|
454
|
+
let fallbackToFullReplace = false;
|
|
455
|
+
for (const record of changeRecords) {
|
|
456
|
+
if (!record.propPath) {
|
|
457
|
+
fallbackToFullReplace = true;
|
|
458
|
+
break;
|
|
459
|
+
}
|
|
460
|
+
const value = cloneDeep$1(getValueByKeyPath(record.propPath, oldSchema));
|
|
461
|
+
setValueByKeyPath(record.propPath, value, patched);
|
|
462
|
+
}
|
|
463
|
+
this.setCodeDslByIdSync(id, fallbackToFullReplace ? cloneDeep$1(oldSchema) : patched, true, {
|
|
464
|
+
changeRecords,
|
|
465
|
+
historyDescription,
|
|
466
|
+
historySource: "rollback"
|
|
467
|
+
});
|
|
468
|
+
return history_default.getStepList("codeBlock", id).slice(-1)[0]?.step ?? null;
|
|
469
|
+
}
|
|
470
|
+
this.setCodeDslByIdSync(id, cloneDeep$1(oldSchema), true, {
|
|
471
|
+
historyDescription,
|
|
472
|
+
historySource: "rollback"
|
|
473
|
+
});
|
|
474
|
+
return history_default.getStepList("codeBlock", id).slice(-1)[0]?.step ?? null;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* 把一条历史 step 应用到当前代码块服务上。
|
|
478
|
+
*
|
|
479
|
+
* 复用现有的 setCodeDslByIdSync / deleteCodeDslByIds,目的是借助它们发出的事件
|
|
480
|
+
* 触发 initService 中的 dep target 维护(CODE_BLOCK 的 add / remove)。
|
|
481
|
+
* 所有写回都带 `doNotPushHistory: true`,确保不会在历史栈里产生新的记录。
|
|
482
|
+
*
|
|
483
|
+
* - oldContent=null, newContent≠null:原始为新增 → undo 删除;redo 再次 setCodeDslByIdSync
|
|
484
|
+
* - oldContent≠null, newContent=null:原始为删除 → undo 还原写入;redo 再次删除
|
|
485
|
+
* - 两侧都有:原始为更新 → 按 changeRecords 局部 patch;缺省退化为整内容替换
|
|
486
|
+
*
|
|
487
|
+
* @param step 历史 step
|
|
488
|
+
* @param reverse true=撤销,false=重做
|
|
489
|
+
*/
|
|
490
|
+
async applyHistoryStep(step, reverse) {
|
|
491
|
+
const { id } = step.data;
|
|
492
|
+
const { oldSchema, newSchema, changeRecords } = step.diff?.[0] ?? {};
|
|
493
|
+
if (!oldSchema && newSchema) {
|
|
494
|
+
if (reverse) await this.deleteCodeDslByIds([id], { doNotPushHistory: true });
|
|
495
|
+
else this.setCodeDslByIdSync(id, cloneDeep$1(newSchema), true, { doNotPushHistory: true });
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
if (oldSchema && !newSchema) {
|
|
499
|
+
if (reverse) this.setCodeDslByIdSync(id, cloneDeep$1(oldSchema), true, { doNotPushHistory: true });
|
|
500
|
+
else await this.deleteCodeDslByIds([id], { doNotPushHistory: true });
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
if (!oldSchema || !newSchema) return;
|
|
504
|
+
const sourceForValues = reverse ? oldSchema : newSchema;
|
|
505
|
+
if (changeRecords?.length) {
|
|
506
|
+
const current = this.getCodeContentById(id);
|
|
507
|
+
if (!current) return;
|
|
508
|
+
const patched = cloneDeep$1(current);
|
|
509
|
+
let fallbackToFullReplace = false;
|
|
510
|
+
for (const record of changeRecords) {
|
|
511
|
+
if (!record.propPath) {
|
|
512
|
+
fallbackToFullReplace = true;
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
const value = cloneDeep$1(getValueByKeyPath(record.propPath, sourceForValues));
|
|
516
|
+
setValueByKeyPath(record.propPath, value, patched);
|
|
517
|
+
}
|
|
518
|
+
this.setCodeDslByIdSync(id, fallbackToFullReplace ? cloneDeep$1(sourceForValues) : patched, true, {
|
|
519
|
+
changeRecords,
|
|
520
|
+
doNotPushHistory: true
|
|
521
|
+
});
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
this.setCodeDslByIdSync(id, cloneDeep$1(sourceForValues), true, { doNotPushHistory: true });
|
|
525
|
+
}
|
|
248
526
|
};
|
|
249
527
|
var codeBlock_default = new CodeBlock();
|
|
250
528
|
//#endregion
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BaseService from "./BaseService.js";
|
|
2
2
|
import { shallowReactive } from "vue";
|
|
3
3
|
//#region packages/editor/src/services/componentList.ts
|
|
4
|
-
var ComponentList = class extends
|
|
4
|
+
var ComponentList = class extends BaseService {
|
|
5
5
|
state = shallowReactive({ list: [] });
|
|
6
6
|
constructor() {
|
|
7
7
|
super([]);
|