@tmagic/editor 1.8.0-beta.1 → 1.8.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/Editor.vue_vue_type_script_setup_true_lang.js +11 -2
- package/dist/es/components/CodeBlockEditor.vue_vue_type_script_setup_true_lang.js +18 -110
- package/dist/es/components/CodeParams.vue_vue_type_script_setup_true_lang.js +6 -0
- package/dist/es/components/CompareForm.js +5 -0
- package/dist/es/components/CompareForm.vue_vue_type_script_setup_true_lang.js +167 -0
- package/dist/es/fields/Code.vue_vue_type_script_setup_true_lang.js +19 -3
- package/dist/es/fields/CodeSelect.vue_vue_type_script_setup_true_lang.js +18 -2
- package/dist/es/fields/CodeSelectCol.vue_vue_type_script_setup_true_lang.js +37 -6
- package/dist/es/fields/DataSourceFieldSelect/FieldSelect.vue_vue_type_script_setup_true_lang.js +3 -1
- package/dist/es/fields/DataSourceFieldSelect/Index.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +14 -6
- package/dist/es/fields/DataSourceMethodSelect.vue_vue_type_script_setup_true_name_true_lang.js +3 -1
- package/dist/es/fields/DataSourceMethods.vue_vue_type_script_setup_true_lang.js +15 -7
- package/dist/es/fields/DataSourceMocks.vue_vue_type_script_setup_true_lang.js +14 -6
- package/dist/es/fields/DataSourceSelect.vue_vue_type_script_setup_true_lang.js +3 -1
- package/dist/es/fields/EventSelect.vue_vue_type_script_setup_true_lang.js +58 -11
- package/dist/es/fields/KeyValue.vue_vue_type_script_setup_true_lang.js +11 -6
- package/dist/es/fields/UISelect.vue_vue_type_script_setup_true_lang.js +8 -5
- package/dist/es/hooks/use-code-block-edit.js +2 -2
- package/dist/es/hooks/use-stage.js +15 -7
- package/dist/es/index.js +3 -1
- package/dist/es/initService.js +6 -6
- package/dist/es/layouts/CodeEditor.vue_vue_type_script_setup_true_lang.js +4 -0
- package/dist/es/layouts/Framework.vue_vue_type_script_setup_true_lang.js +12 -7
- package/dist/es/layouts/NavMenu.vue_vue_type_script_setup_true_lang.js +8 -0
- 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 +84 -0
- package/dist/es/layouts/history-list/CodeBlockTab.js +5 -0
- package/dist/es/layouts/history-list/CodeBlockTab.vue_vue_type_script_setup_true_lang.js +62 -0
- package/dist/es/layouts/history-list/DataSourceTab.js +5 -0
- package/dist/es/layouts/history-list/DataSourceTab.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 +180 -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 +195 -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 +270 -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 +48 -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 +99 -0
- package/dist/es/layouts/history-list/composables.js +154 -0
- package/dist/es/layouts/sidebar/layer/use-node-status.js +1 -1
- package/dist/es/services/BaseService.js +31 -68
- package/dist/es/services/codeBlock.js +205 -8
- package/dist/es/services/componentList.js +2 -2
- package/dist/es/services/dataSource.js +217 -8
- package/dist/es/services/dep.js +21 -9
- package/dist/es/services/editor.js +350 -160
- package/dist/es/services/events.js +2 -2
- package/dist/es/services/history.js +407 -12
- package/dist/es/services/keybinding.js +2 -2
- 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 +2 -2
- package/dist/es/style.css +347 -1
- package/dist/es/utils/code-block.js +122 -0
- package/dist/es/utils/content-menu.js +4 -5
- package/dist/es/utils/dep/worker.js +1 -1
- package/dist/es/utils/editor.js +2 -2
- package/dist/es/utils/undo-redo.js +20 -0
- package/dist/style.css +347 -1
- package/dist/tmagic-editor.umd.cjs +3165 -774
- package/package.json +7 -7
- package/src/Editor.vue +7 -0
- package/src/components/CodeBlockEditor.vue +20 -109
- package/src/components/CodeParams.vue +6 -0
- package/src/components/CompareForm.vue +225 -0
- package/src/editorProps.ts +2 -0
- package/src/fields/Code.vue +19 -3
- package/src/fields/CodeSelect.vue +17 -1
- package/src/fields/CodeSelectCol.vue +30 -2
- package/src/fields/DataSourceFieldSelect/FieldSelect.vue +7 -1
- package/src/fields/DataSourceFieldSelect/Index.vue +2 -2
- package/src/fields/DataSourceFields.vue +12 -3
- package/src/fields/DataSourceMethodSelect.vue +4 -1
- package/src/fields/DataSourceMethods.vue +14 -4
- 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/UISelect.vue +5 -2
- package/src/hooks/use-code-block-edit.ts +5 -2
- package/src/hooks/use-stage.ts +23 -7
- package/src/index.ts +1 -0
- package/src/layouts/CodeEditor.vue +15 -0
- package/src/layouts/Framework.vue +10 -5
- package/src/layouts/NavMenu.vue +9 -0
- package/src/layouts/history-list/Bucket.vue +99 -0
- package/src/layouts/history-list/CodeBlockTab.vue +61 -0
- package/src/layouts/history-list/DataSourceTab.vue +61 -0
- package/src/layouts/history-list/GroupRow.vue +207 -0
- package/src/layouts/history-list/HistoryDiffDialog.vue +212 -0
- package/src/layouts/history-list/HistoryListPanel.vue +271 -0
- package/src/layouts/history-list/InitialRow.vue +41 -0
- package/src/layouts/history-list/PageTab.vue +94 -0
- package/src/layouts/history-list/composables.ts +195 -0
- package/src/layouts/sidebar/layer/use-node-status.ts +9 -6
- package/src/services/BaseService.ts +35 -86
- package/src/services/codeBlock.ts +256 -5
- package/src/services/dataSource.ts +257 -6
- package/src/services/dep.ts +32 -9
- package/src/services/editor.ts +454 -171
- package/src/services/history.ts +452 -8
- package/src/services/props.ts +2 -2
- package/src/theme/history-list-panel.scss +423 -0
- package/src/theme/theme.scss +1 -0
- package/src/type.ts +179 -6
- package/src/utils/code-block.ts +150 -0
- package/src/utils/content-menu.ts +8 -5
- package/src/utils/dep/worker.ts +5 -3
- package/src/utils/index.ts +1 -0
- package/src/utils/undo-redo.ts +23 -0
- package/types/index.d.ts +2105 -810
- 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,49 +1,39 @@
|
|
|
1
|
-
import { compose } from "../utils/compose.js";
|
|
2
1
|
import { EventEmitter } from "events";
|
|
3
2
|
//#region packages/editor/src/services/BaseService.ts
|
|
4
3
|
var methodName = (prefix, name) => `${prefix}${name[0].toUpperCase()}${name.substring(1)}`;
|
|
5
4
|
var isError = (error) => Object.prototype.toString.call(error) === "[object Error]";
|
|
6
|
-
var doAction = (args, scope, sourceMethod, beforeMethodName, afterMethodName
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (isError(returnValue)) throw returnValue;
|
|
18
|
-
}
|
|
19
|
-
return returnValue;
|
|
20
|
-
} catch (error) {
|
|
21
|
-
throw error;
|
|
5
|
+
var doAction = (args, scope, sourceMethod, beforeMethodName, afterMethodName) => {
|
|
6
|
+
let beforeArgs = args;
|
|
7
|
+
for (const beforeMethod of scope.pluginOptionsList[beforeMethodName]) {
|
|
8
|
+
beforeArgs = beforeMethod(...beforeArgs) || [];
|
|
9
|
+
if (isError(beforeArgs)) throw beforeArgs;
|
|
10
|
+
if (!Array.isArray(beforeArgs)) beforeArgs = [beforeArgs];
|
|
11
|
+
}
|
|
12
|
+
let returnValue = sourceMethod.apply(scope, beforeArgs);
|
|
13
|
+
for (const afterMethod of scope.pluginOptionsList[afterMethodName]) {
|
|
14
|
+
returnValue = afterMethod(returnValue, ...beforeArgs);
|
|
15
|
+
if (isError(returnValue)) throw returnValue;
|
|
22
16
|
}
|
|
17
|
+
return returnValue;
|
|
23
18
|
};
|
|
24
|
-
var doAsyncAction = async (args, scope, sourceMethod, beforeMethodName, afterMethodName
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!Array.isArray(beforeArgs)) beforeArgs = [beforeArgs];
|
|
31
|
-
}
|
|
32
|
-
let returnValue = await fn(beforeArgs, sourceMethod.bind(scope));
|
|
33
|
-
for (const afterMethod of scope.pluginOptionsList[afterMethodName]) {
|
|
34
|
-
returnValue = await afterMethod(returnValue, ...beforeArgs);
|
|
35
|
-
if (isError(returnValue)) throw returnValue;
|
|
36
|
-
}
|
|
37
|
-
return returnValue;
|
|
38
|
-
} catch (error) {
|
|
39
|
-
throw error;
|
|
19
|
+
var doAsyncAction = async (args, scope, sourceMethod, beforeMethodName, afterMethodName) => {
|
|
20
|
+
let beforeArgs = args;
|
|
21
|
+
for (const beforeMethod of scope.pluginOptionsList[beforeMethodName]) {
|
|
22
|
+
beforeArgs = await beforeMethod(...beforeArgs) || [];
|
|
23
|
+
if (isError(beforeArgs)) throw beforeArgs;
|
|
24
|
+
if (!Array.isArray(beforeArgs)) beforeArgs = [beforeArgs];
|
|
40
25
|
}
|
|
26
|
+
let returnValue = await sourceMethod.apply(scope, beforeArgs);
|
|
27
|
+
for (const afterMethod of scope.pluginOptionsList[afterMethodName]) {
|
|
28
|
+
returnValue = await afterMethod(returnValue, ...beforeArgs);
|
|
29
|
+
if (isError(returnValue)) throw returnValue;
|
|
30
|
+
}
|
|
31
|
+
return returnValue;
|
|
41
32
|
};
|
|
42
33
|
/**
|
|
43
|
-
*
|
|
44
|
-
* 方法1:
|
|
34
|
+
* 对Class进行扩展
|
|
45
35
|
* 给Class中的每个方法都添加before after两个钩子
|
|
46
|
-
* 给Class添加一个usePlugin方法,
|
|
36
|
+
* 给Class添加一个usePlugin方法,usePlugin方法可以传入一个包含before或者after方法的对象
|
|
47
37
|
*
|
|
48
38
|
* 例如:
|
|
49
39
|
* Class EditorService extends BaseService {
|
|
@@ -68,27 +58,9 @@ var doAsyncAction = async (args, scope, sourceMethod, beforeMethodName, afterMet
|
|
|
68
58
|
*
|
|
69
59
|
* 调用时的参数会透传到before方法的参数中, 然后before的return 会作为原方法的参数和after的参数,after第一个参数则是原方法的return值;
|
|
70
60
|
* 如需终止后续方法调用可以return new Error();
|
|
71
|
-
*
|
|
72
|
-
* 方法2:
|
|
73
|
-
* 给Class中的每个方法都添加中间件
|
|
74
|
-
* 给Class添加一个use方法,use方法可以传入一个包含源对象方法名作为key值的对象
|
|
75
|
-
*
|
|
76
|
-
* 例如:
|
|
77
|
-
* Class EditorService extends BaseService {
|
|
78
|
-
* constructor() {
|
|
79
|
-
* super([ { name: 'add', isAsync: true },]);
|
|
80
|
-
* }
|
|
81
|
-
* add(value) { return result; }
|
|
82
|
-
* };
|
|
83
|
-
*
|
|
84
|
-
* const editorService = new EditorService();
|
|
85
|
-
* editorService.use({
|
|
86
|
-
* add(value, next) { console.log(value); next() },
|
|
87
|
-
* });
|
|
88
61
|
*/
|
|
89
|
-
var
|
|
62
|
+
var BaseService = class extends EventEmitter {
|
|
90
63
|
pluginOptionsList = {};
|
|
91
|
-
middleware = {};
|
|
92
64
|
taskList = [];
|
|
93
65
|
doingTask = false;
|
|
94
66
|
constructor(methods = [], serialMethods = []) {
|
|
@@ -100,14 +72,12 @@ var BaseService_default = class extends EventEmitter {
|
|
|
100
72
|
const afterMethodName = methodName("after", propertyName);
|
|
101
73
|
this.pluginOptionsList[beforeMethodName] = [];
|
|
102
74
|
this.pluginOptionsList[afterMethodName] = [];
|
|
103
|
-
this.middleware[propertyName] = [];
|
|
104
|
-
const fn = compose(this.middleware[propertyName], isAsync);
|
|
105
75
|
Object.defineProperty(scope, propertyName, { value: isAsync ? async (...args) => {
|
|
106
|
-
if (!serialMethods.includes(propertyName)) return doAsyncAction(args, scope, sourceMethod, beforeMethodName, afterMethodName
|
|
76
|
+
if (!serialMethods.includes(propertyName)) return doAsyncAction(args, scope, sourceMethod, beforeMethodName, afterMethodName);
|
|
107
77
|
const promise = new Promise((resolve, reject) => {
|
|
108
78
|
this.taskList.push(async () => {
|
|
109
79
|
try {
|
|
110
|
-
resolve(await doAsyncAction(args, scope, sourceMethod, beforeMethodName, afterMethodName
|
|
80
|
+
resolve(await doAsyncAction(args, scope, sourceMethod, beforeMethodName, afterMethodName));
|
|
111
81
|
} catch (e) {
|
|
112
82
|
reject(e);
|
|
113
83
|
}
|
|
@@ -115,15 +85,9 @@ var BaseService_default = class extends EventEmitter {
|
|
|
115
85
|
});
|
|
116
86
|
if (!this.doingTask) this.doTask();
|
|
117
87
|
return promise;
|
|
118
|
-
} : (...args) => doAction(args, scope, sourceMethod, beforeMethodName, afterMethodName
|
|
88
|
+
} : (...args) => doAction(args, scope, sourceMethod, beforeMethodName, afterMethodName) });
|
|
119
89
|
});
|
|
120
90
|
}
|
|
121
|
-
/**
|
|
122
|
-
* @deprecated 请使用usePlugin代替
|
|
123
|
-
*/
|
|
124
|
-
use(options) {
|
|
125
|
-
for (const [methodName, method] of Object.entries(options)) if (typeof method === "function") this.middleware[methodName].push(method);
|
|
126
|
-
}
|
|
127
91
|
usePlugin(options) {
|
|
128
92
|
for (const [methodName, method] of Object.entries(options)) if (typeof method === "function" && !this.pluginOptionsList[methodName].includes(method)) this.pluginOptionsList[methodName].push(method);
|
|
129
93
|
}
|
|
@@ -132,7 +96,6 @@ var BaseService_default = class extends EventEmitter {
|
|
|
132
96
|
}
|
|
133
97
|
removeAllPlugins() {
|
|
134
98
|
for (const key of Object.keys(this.pluginOptionsList)) this.pluginOptionsList[key] = [];
|
|
135
|
-
for (const key of Object.keys(this.middleware)) this.middleware[key] = [];
|
|
136
99
|
}
|
|
137
100
|
async doTask() {
|
|
138
101
|
this.doingTask = true;
|
|
@@ -145,4 +108,4 @@ var BaseService_default = class extends EventEmitter {
|
|
|
145
108
|
}
|
|
146
109
|
};
|
|
147
110
|
//#endregion
|
|
148
|
-
export {
|
|
111
|
+
export { BaseService as default };
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { CODE_DRAFT_STORAGE_KEY } from "../type.js";
|
|
2
|
-
import
|
|
2
|
+
import BaseService from "./BaseService.js";
|
|
3
|
+
import history_default from "./history.js";
|
|
3
4
|
import { getEditorConfig } from "../utils/config.js";
|
|
4
5
|
import storage_default, { Protocol } from "./storage.js";
|
|
5
6
|
import { COPY_CODE_STORAGE_KEY } from "../utils/editor.js";
|
|
6
7
|
import editor_default from "./editor.js";
|
|
8
|
+
import { getValueByKeyPath, setValueByKeyPath } from "@tmagic/utils";
|
|
7
9
|
import { Target, Watcher } from "@tmagic/core";
|
|
8
10
|
import { reactive } from "vue";
|
|
9
|
-
import { cloneDeep, get, keys, pick } from "lodash-es";
|
|
11
|
+
import { cloneDeep as cloneDeep$1, get, keys, pick } from "lodash-es";
|
|
10
12
|
//#region packages/editor/src/services/codeBlock.ts
|
|
11
13
|
var canUsePluginMethods = {
|
|
12
14
|
async: [
|
|
@@ -18,7 +20,18 @@ var canUsePluginMethods = {
|
|
|
18
20
|
],
|
|
19
21
|
sync: ["setCodeDslByIdSync"]
|
|
20
22
|
};
|
|
21
|
-
|
|
23
|
+
/**
|
|
24
|
+
* 「回滚」生成的新 step 简短描述。仅 service 层使用。
|
|
25
|
+
*/
|
|
26
|
+
var describeRevertCodeBlockStep = (step) => {
|
|
27
|
+
const { oldContent, newContent, changeRecords, id } = step;
|
|
28
|
+
if (oldContent === null && newContent) return `撤回新增 ${newContent.name || newContent.id || id}`;
|
|
29
|
+
if (oldContent && newContent === null) return `还原已删除的 ${oldContent.name || oldContent.id || id}`;
|
|
30
|
+
const name = newContent?.name || oldContent?.name || `${id}`;
|
|
31
|
+
const propPath = changeRecords?.[0]?.propPath;
|
|
32
|
+
return propPath ? `还原 ${name} · ${propPath}` : `还原 ${name}`;
|
|
33
|
+
};
|
|
34
|
+
var CodeBlock = class extends BaseService {
|
|
22
35
|
state = reactive({
|
|
23
36
|
codeDsl: null,
|
|
24
37
|
editable: true,
|
|
@@ -68,10 +81,16 @@ var CodeBlock = class extends BaseService_default {
|
|
|
68
81
|
* 设置代码块ID和代码内容到源dsl
|
|
69
82
|
* @param {Id} id 代码块id
|
|
70
83
|
* @param {CodeBlockContent} codeConfig 代码块内容配置信息
|
|
84
|
+
* @param options 可选配置
|
|
85
|
+
* @param options.changeRecords form 端 propPath/value 列表,用于历史记录的精细化撤销/重做
|
|
86
|
+
* @param options.doNotPushHistory 是否不写入历史记录(默认 false)
|
|
71
87
|
* @returns {void}
|
|
72
88
|
*/
|
|
73
|
-
async setCodeDslById(id, codeConfig) {
|
|
74
|
-
this.setCodeDslByIdSync(id, codeConfig, true
|
|
89
|
+
async setCodeDslById(id, codeConfig, { changeRecords, doNotPushHistory = false } = {}) {
|
|
90
|
+
this.setCodeDslByIdSync(id, codeConfig, true, {
|
|
91
|
+
changeRecords,
|
|
92
|
+
doNotPushHistory
|
|
93
|
+
});
|
|
75
94
|
}
|
|
76
95
|
/**
|
|
77
96
|
* 为了兼容历史原因
|
|
@@ -79,21 +98,33 @@ var CodeBlock = class extends BaseService_default {
|
|
|
79
98
|
* @param {Id} id 代码块id
|
|
80
99
|
* @param {CodeBlockContent} codeConfig 代码块内容配置信息
|
|
81
100
|
* @param {boolean} force 是否强制写入,默认true
|
|
101
|
+
* @param options 可选配置
|
|
102
|
+
* @param options.changeRecords form 端 propPath/value 列表,用于历史记录的精细化撤销/重做
|
|
103
|
+
* @param options.doNotPushHistory 是否不写入历史记录(默认 false)
|
|
104
|
+
* @param options.historyDescription 入栈时附带的人类可读描述,用于历史面板展示
|
|
82
105
|
* @returns {void}
|
|
83
106
|
*/
|
|
84
|
-
setCodeDslByIdSync(id, codeConfig, force = true) {
|
|
107
|
+
setCodeDslByIdSync(id, codeConfig, force = true, { changeRecords, doNotPushHistory = false, historyDescription } = {}) {
|
|
85
108
|
const codeDsl = this.getCodeDsl();
|
|
86
109
|
if (!codeDsl) throw new Error("dsl中没有codeBlocks");
|
|
87
110
|
if (codeDsl[id] && !force) return;
|
|
88
|
-
const codeConfigProcessed = cloneDeep(codeConfig);
|
|
111
|
+
const codeConfigProcessed = cloneDeep$1(codeConfig);
|
|
89
112
|
if (codeConfigProcessed.content) {
|
|
90
113
|
const parseDSL = getEditorConfig("parseDSL");
|
|
91
114
|
if (typeof codeConfigProcessed.content === "string") codeConfigProcessed.content = parseDSL(codeConfigProcessed.content);
|
|
92
115
|
}
|
|
116
|
+
const oldContent = codeDsl[id] ? cloneDeep$1(codeDsl[id]) : null;
|
|
93
117
|
codeDsl[id] = {
|
|
94
118
|
...codeDsl[id] || {},
|
|
95
119
|
...codeConfigProcessed
|
|
96
120
|
};
|
|
121
|
+
const newContent = cloneDeep$1(codeDsl[id]);
|
|
122
|
+
if (!doNotPushHistory) history_default.pushCodeBlock(id, {
|
|
123
|
+
oldContent,
|
|
124
|
+
newContent,
|
|
125
|
+
changeRecords,
|
|
126
|
+
historyDescription
|
|
127
|
+
});
|
|
97
128
|
this.emit("addOrUpdate", id, codeDsl[id]);
|
|
98
129
|
}
|
|
99
130
|
/**
|
|
@@ -170,12 +201,20 @@ var CodeBlock = class extends BaseService_default {
|
|
|
170
201
|
/**
|
|
171
202
|
* 在dsl数据源中删除指定id的代码块
|
|
172
203
|
* @param {Id[]} codeIds 需要删除的代码块id数组
|
|
204
|
+
* @param options 可选配置
|
|
205
|
+
* @param options.doNotPushHistory 是否不写入历史记录(默认 false)
|
|
173
206
|
*/
|
|
174
|
-
async deleteCodeDslByIds(codeIds) {
|
|
207
|
+
async deleteCodeDslByIds(codeIds, { doNotPushHistory = false, historyDescription } = {}) {
|
|
175
208
|
const currentDsl = await this.getCodeDsl();
|
|
176
209
|
if (!currentDsl) return;
|
|
177
210
|
codeIds.forEach((id) => {
|
|
211
|
+
const oldContent = currentDsl[id] ? cloneDeep$1(currentDsl[id]) : null;
|
|
178
212
|
delete currentDsl[id];
|
|
213
|
+
if (oldContent && !doNotPushHistory) history_default.pushCodeBlock(id, {
|
|
214
|
+
oldContent,
|
|
215
|
+
newContent: null,
|
|
216
|
+
historyDescription
|
|
217
|
+
});
|
|
179
218
|
this.emit("remove", id);
|
|
180
219
|
});
|
|
181
220
|
}
|
|
@@ -186,6 +225,78 @@ var CodeBlock = class extends BaseService_default {
|
|
|
186
225
|
return this.state.paramsColConfig;
|
|
187
226
|
}
|
|
188
227
|
/**
|
|
228
|
+
* 撤销指定代码块的最近一次变更。
|
|
229
|
+
*
|
|
230
|
+
* 内部走 setCodeDslByIdSync / deleteCodeDslByIds,因此会自动触发 codeBlockService 的
|
|
231
|
+
* `addOrUpdate` / `remove` 事件,由 initService 中的 handler 重新维护 dep target
|
|
232
|
+
* (DepTargetType.CODE_BLOCK 的 add / remove)。所有写回都带 `doNotPushHistory: true`,
|
|
233
|
+
* 确保不会在历史栈里产生新的记录。
|
|
234
|
+
*
|
|
235
|
+
* @param id 代码块 id
|
|
236
|
+
* @returns 撤销的 step;栈不存在或已无可撤销时返回 null
|
|
237
|
+
*/
|
|
238
|
+
async undo(id) {
|
|
239
|
+
const step = history_default.undoCodeBlock(id);
|
|
240
|
+
if (!step) return null;
|
|
241
|
+
await this.applyHistoryStep(step, true);
|
|
242
|
+
return step;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* 重做指定代码块的下一次变更。
|
|
246
|
+
* @param id 代码块 id
|
|
247
|
+
* @returns 重做的 step;栈不存在或已无可重做时返回 null
|
|
248
|
+
*/
|
|
249
|
+
async redo(id) {
|
|
250
|
+
const step = history_default.redoCodeBlock(id);
|
|
251
|
+
if (!step) return null;
|
|
252
|
+
await this.applyHistoryStep(step, false);
|
|
253
|
+
return step;
|
|
254
|
+
}
|
|
255
|
+
/** 是否可对指定代码块撤销。 */
|
|
256
|
+
canUndo(id) {
|
|
257
|
+
return history_default.canUndoCodeBlock(id);
|
|
258
|
+
}
|
|
259
|
+
/** 是否可对指定代码块重做。 */
|
|
260
|
+
canRedo(id) {
|
|
261
|
+
return history_default.canRedoCodeBlock(id);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* 跳转指定代码块的历史栈到目标游标。语义同 editor.gotoPageStep。
|
|
265
|
+
*
|
|
266
|
+
* @param id 代码块 id
|
|
267
|
+
* @param targetCursor 目标游标位置(已应用步骤数量)
|
|
268
|
+
* @returns 实际移动到的最终游标位置
|
|
269
|
+
*/
|
|
270
|
+
async goto(id, targetCursor) {
|
|
271
|
+
let cursor = history_default.getCodeBlockCursor(id);
|
|
272
|
+
const target = Math.max(0, targetCursor);
|
|
273
|
+
while (cursor > target) {
|
|
274
|
+
if (!await this.undo(id)) break;
|
|
275
|
+
cursor -= 1;
|
|
276
|
+
}
|
|
277
|
+
while (cursor < target) {
|
|
278
|
+
if (!await this.redo(id)) break;
|
|
279
|
+
cursor += 1;
|
|
280
|
+
}
|
|
281
|
+
return cursor;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* 「回滚」指定代码块历史步骤(类 git revert 语义):
|
|
285
|
+
* - 不动原始栈结构(不移动 cursor、不丢弃任何步骤);
|
|
286
|
+
* - 把目标 step 的修改**反向应用**一次,并作为**新步骤**追加到栈顶;
|
|
287
|
+
* - 仅对已应用的步骤生效。
|
|
288
|
+
*
|
|
289
|
+
* @param id 代码块 id
|
|
290
|
+
* @param index 目标 step 在该栈中的索引(0 为最早),通常由历史面板传入
|
|
291
|
+
* @returns 反向后产生的新 step;目标不存在 / 未应用时返回 null
|
|
292
|
+
*/
|
|
293
|
+
async revert(id, index) {
|
|
294
|
+
const entry = history_default.getCodeBlockStepList(id)[index];
|
|
295
|
+
if (!entry?.applied) return null;
|
|
296
|
+
const description = `回滚 #${index + 1}: ${describeRevertCodeBlockStep(entry.step)}`;
|
|
297
|
+
return await this.applyRevertStep(entry.step, description);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
189
300
|
* 生成代码块唯一id
|
|
190
301
|
* @returns {Id} 代码块唯一id
|
|
191
302
|
*/
|
|
@@ -245,6 +356,92 @@ var CodeBlock = class extends BaseService_default {
|
|
|
245
356
|
usePlugin(options) {
|
|
246
357
|
super.usePlugin(options);
|
|
247
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* 反向应用一个 step 并以新 step 入栈。逻辑与 applyHistoryStep(reverse=true) 同构,
|
|
361
|
+
* 差异仅在于通过公开的 setCodeDslByIdSync / deleteCodeDslByIds 触发 push。
|
|
362
|
+
*/
|
|
363
|
+
async applyRevertStep(step, historyDescription) {
|
|
364
|
+
const { id, oldContent, newContent, changeRecords } = step;
|
|
365
|
+
if (oldContent === null && newContent) {
|
|
366
|
+
await this.deleteCodeDslByIds([id], { historyDescription });
|
|
367
|
+
return history_default.getCodeBlockStepList(id).slice(-1)[0]?.step ?? null;
|
|
368
|
+
}
|
|
369
|
+
if (oldContent && newContent === null) {
|
|
370
|
+
this.setCodeDslByIdSync(id, cloneDeep$1(oldContent), true, { historyDescription });
|
|
371
|
+
return history_default.getCodeBlockStepList(id).slice(-1)[0]?.step ?? null;
|
|
372
|
+
}
|
|
373
|
+
if (!oldContent || !newContent) return null;
|
|
374
|
+
if (changeRecords?.length) {
|
|
375
|
+
const current = this.getCodeContentById(id);
|
|
376
|
+
if (!current) return null;
|
|
377
|
+
const patched = cloneDeep$1(current);
|
|
378
|
+
let fallbackToFullReplace = false;
|
|
379
|
+
for (const record of changeRecords) {
|
|
380
|
+
if (!record.propPath) {
|
|
381
|
+
fallbackToFullReplace = true;
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
const value = cloneDeep$1(getValueByKeyPath(record.propPath, oldContent));
|
|
385
|
+
setValueByKeyPath(record.propPath, value, patched);
|
|
386
|
+
}
|
|
387
|
+
this.setCodeDslByIdSync(id, fallbackToFullReplace ? cloneDeep$1(oldContent) : patched, true, {
|
|
388
|
+
changeRecords,
|
|
389
|
+
historyDescription
|
|
390
|
+
});
|
|
391
|
+
return history_default.getCodeBlockStepList(id).slice(-1)[0]?.step ?? null;
|
|
392
|
+
}
|
|
393
|
+
this.setCodeDslByIdSync(id, cloneDeep$1(oldContent), true, { historyDescription });
|
|
394
|
+
return history_default.getCodeBlockStepList(id).slice(-1)[0]?.step ?? null;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* 把一条历史 step 应用到当前代码块服务上。
|
|
398
|
+
*
|
|
399
|
+
* 复用现有的 setCodeDslByIdSync / deleteCodeDslByIds,目的是借助它们发出的事件
|
|
400
|
+
* 触发 initService 中的 dep target 维护(CODE_BLOCK 的 add / remove)。
|
|
401
|
+
* 所有写回都带 `doNotPushHistory: true`,确保不会在历史栈里产生新的记录。
|
|
402
|
+
*
|
|
403
|
+
* - oldContent=null, newContent≠null:原始为新增 → undo 删除;redo 再次 setCodeDslByIdSync
|
|
404
|
+
* - oldContent≠null, newContent=null:原始为删除 → undo 还原写入;redo 再次删除
|
|
405
|
+
* - 两侧都有:原始为更新 → 按 changeRecords 局部 patch;缺省退化为整内容替换
|
|
406
|
+
*
|
|
407
|
+
* @param step 历史 step
|
|
408
|
+
* @param reverse true=撤销,false=重做
|
|
409
|
+
*/
|
|
410
|
+
async applyHistoryStep(step, reverse) {
|
|
411
|
+
const { id, oldContent, newContent, changeRecords } = step;
|
|
412
|
+
if (oldContent === null && newContent) {
|
|
413
|
+
if (reverse) await this.deleteCodeDslByIds([id], { doNotPushHistory: true });
|
|
414
|
+
else this.setCodeDslByIdSync(id, cloneDeep$1(newContent), true, { doNotPushHistory: true });
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if (oldContent && newContent === null) {
|
|
418
|
+
if (reverse) this.setCodeDslByIdSync(id, cloneDeep$1(oldContent), true, { doNotPushHistory: true });
|
|
419
|
+
else await this.deleteCodeDslByIds([id], { doNotPushHistory: true });
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
if (!oldContent || !newContent) return;
|
|
423
|
+
const sourceForValues = reverse ? oldContent : newContent;
|
|
424
|
+
if (changeRecords?.length) {
|
|
425
|
+
const current = this.getCodeContentById(id);
|
|
426
|
+
if (!current) return;
|
|
427
|
+
const patched = cloneDeep$1(current);
|
|
428
|
+
let fallbackToFullReplace = false;
|
|
429
|
+
for (const record of changeRecords) {
|
|
430
|
+
if (!record.propPath) {
|
|
431
|
+
fallbackToFullReplace = true;
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
const value = cloneDeep$1(getValueByKeyPath(record.propPath, sourceForValues));
|
|
435
|
+
setValueByKeyPath(record.propPath, value, patched);
|
|
436
|
+
}
|
|
437
|
+
this.setCodeDslByIdSync(id, fallbackToFullReplace ? cloneDeep$1(sourceForValues) : patched, true, {
|
|
438
|
+
changeRecords,
|
|
439
|
+
doNotPushHistory: true
|
|
440
|
+
});
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
this.setCodeDslByIdSync(id, cloneDeep$1(sourceForValues), true, { doNotPushHistory: true });
|
|
444
|
+
}
|
|
248
445
|
};
|
|
249
446
|
var codeBlock_default = new CodeBlock();
|
|
250
447
|
//#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([]);
|