@tmagic/editor 1.8.2 → 1.8.3
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 +16 -24
- package/dist/es/fields/CondOpSelect.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/fields/DataSourceFieldSelect/FieldSelect.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/DataSourceFieldSelect/Index.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/DataSourceInput.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/DataSourceMethodSelect.vue_vue_type_script_setup_true_name_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/configs.js +1 -1
- package/dist/es/fields/configs/codeSelect.js +5 -7
- package/dist/es/fields/configs/displayConds.js +8 -9
- package/dist/es/fields/configs/eventSelect.js +30 -27
- package/dist/es/hooks/use-stage.js +18 -18
- package/dist/es/index.js +9 -16
- package/dist/es/initService.js +33 -106
- package/dist/es/layouts/Framework.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 +2 -2
- package/dist/es/layouts/props-panel/use-style-panel.js +1 -1
- package/dist/es/sdk/index.js +151 -0
- package/dist/es/{services → sdk/services}/BaseService.js +1 -1
- package/dist/es/{services/codeBlock.js → sdk/services/CodeBlock.js} +37 -40
- package/dist/es/{services/componentList.js → sdk/services/ComponentList.js} +5 -6
- package/dist/es/{services/dataSource.js → sdk/services/DataSource.js} +38 -37
- package/dist/es/{services/dep.js → sdk/services/Dep.js} +24 -14
- package/dist/es/{services/editor.js → sdk/services/Editor.js} +124 -87
- package/dist/es/{services/events.js → sdk/services/Events.js} +13 -13
- package/dist/es/{services/history.js → sdk/services/History.js} +86 -33
- package/dist/es/{services/props.js → sdk/services/Props.js} +25 -26
- package/dist/es/{services/storage.js → sdk/services/WebStorage.js} +31 -8
- package/dist/es/sdk/utils/dep.js +100 -0
- package/dist/es/sdk/utils/operator.js +70 -0
- package/dist/es/sdk/utils/position.js +8 -0
- package/dist/es/sdk/utils/props.js +281 -0
- package/dist/es/sdk/validate/index.js +286 -0
- package/dist/es/sdk/wiring.js +163 -0
- package/dist/es/sdk.js +15 -0
- package/dist/es/services/keybinding.js +21 -21
- package/dist/es/services/sdk-instance.js +37 -0
- package/dist/es/services/stageOverlay.js +14 -14
- package/dist/es/services/ui.js +6 -6
- package/dist/es/utils/data-source/formConfigs/base.js +1 -1
- package/dist/es/utils/data-source/formConfigs/http.js +1 -1
- package/dist/es/utils/editor.js +2 -2
- package/dist/es/utils/event.js +25 -21
- package/dist/es/utils/operator.js +11 -57
- package/dist/es/utils/props.js +12 -282
- package/dist/es/utils/type-match-rules.js +10 -12
- package/dist/tmagic-editor-headless.umd.cjs +4690 -2891
- package/dist/tmagic-editor-sdk.umd.cjs +9911 -0
- package/dist/tmagic-editor.umd.cjs +14126 -13312
- package/package.json +12 -7
- package/src/Editor.vue +11 -9
- package/src/fields/configs/codeSelect.ts +6 -9
- package/src/fields/configs/displayConds.ts +10 -9
- package/src/fields/configs/eventSelect.ts +40 -25
- package/src/hooks/use-stage.ts +1 -1
- package/src/index.ts +11 -9
- package/src/initService.ts +59 -188
- package/src/layouts/Framework.vue +1 -1
- package/src/layouts/props-panel/PropsPanel.vue +1 -1
- package/src/layouts/props-panel/use-style-panel.ts +1 -1
- package/src/sdk/index.ts +264 -0
- package/src/{services/codeBlock.ts → sdk/services/CodeBlock.ts} +43 -38
- package/src/{services/componentList.ts → sdk/services/ComponentList.ts} +8 -7
- package/src/{services/dataSource.ts → sdk/services/DataSource.ts} +38 -32
- package/src/{services/dep.ts → sdk/services/Dep.ts} +24 -11
- package/src/{services/editor.ts → sdk/services/Editor.ts} +175 -86
- package/src/{services/events.ts → sdk/services/Events.ts} +15 -12
- package/src/{services/history.ts → sdk/services/History.ts} +100 -28
- package/src/{services/props.ts → sdk/services/Props.ts} +25 -25
- package/src/{services/storage.ts → sdk/services/WebStorage.ts} +41 -7
- package/src/sdk/type.ts +191 -0
- package/src/sdk/utils/dep.ts +196 -0
- package/src/sdk/utils/operator.ts +114 -0
- package/src/sdk/utils/position.ts +23 -0
- package/src/sdk/utils/props.ts +368 -0
- package/src/sdk/validate/index.ts +501 -0
- package/src/sdk/wiring.ts +211 -0
- package/src/sdk.ts +19 -0
- package/src/services/keybinding.ts +2 -2
- package/src/services/sdk-instance.ts +66 -0
- package/src/services/stageOverlay.ts +2 -2
- package/src/services/ui.ts +3 -3
- package/src/type.ts +9 -9
- package/src/utils/data-source/formConfigs/base.ts +1 -1
- package/src/utils/data-source/formConfigs/http.ts +1 -1
- package/src/utils/dep/collect-worker-client.ts +9 -6
- package/src/utils/dep/worker.ts +5 -0
- package/src/utils/editor.ts +2 -1
- package/src/utils/event.ts +36 -18
- package/src/utils/operator.ts +21 -87
- package/src/utils/props.ts +17 -332
- package/src/utils/type-match-rules.ts +1 -3
- package/types/index.d.ts +742 -528
- package/types/sdk.d.ts +2572 -0
- /package/src/{services → sdk/services}/BaseService.ts +0 -0
|
@@ -1,15 +1,12 @@
|
|
|
1
|
+
import { COPY_DS_STORAGE_KEY } from "../../utils/editor.js";
|
|
2
|
+
import { createStackStep, describeRevertStep, getLastPushedHistoryIds } from "../../utils/history.js";
|
|
1
3
|
import BaseService from "./BaseService.js";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import storage_default, { Protocol } from "./storage.js";
|
|
5
|
-
import { COPY_DS_STORAGE_KEY } from "../utils/editor.js";
|
|
6
|
-
import editor_default from "./editor.js";
|
|
7
|
-
import { getFormConfig, getFormValue } from "../utils/data-source/index.js";
|
|
4
|
+
import { Protocol } from "./WebStorage.js";
|
|
5
|
+
import { getFormConfig, getFormValue } from "../../utils/data-source/index.js";
|
|
8
6
|
import { getValueByKeyPath, guid, setValueByKeyPath, toLine } from "@tmagic/utils";
|
|
9
7
|
import { Target, Watcher } from "@tmagic/core";
|
|
10
|
-
import { reactive } from "vue";
|
|
11
8
|
import { cloneDeep as cloneDeep$1, get } from "lodash-es";
|
|
12
|
-
//#region packages/editor/src/services/
|
|
9
|
+
//#region packages/editor/src/sdk/services/DataSource.ts
|
|
13
10
|
var canUsePluginMethods = {
|
|
14
11
|
async: [],
|
|
15
12
|
sync: [
|
|
@@ -28,26 +25,29 @@ var canUsePluginMethods = {
|
|
|
28
25
|
]
|
|
29
26
|
};
|
|
30
27
|
var DataSource = class extends BaseService {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
dataSources: [],
|
|
34
|
-
editable: true,
|
|
35
|
-
configs: {},
|
|
36
|
-
values: {},
|
|
37
|
-
events: {},
|
|
38
|
-
methods: {}
|
|
39
|
-
});
|
|
28
|
+
ctx;
|
|
29
|
+
state;
|
|
40
30
|
/**
|
|
41
31
|
* 最近一次写入历史栈的数据源历史记录 uuid。
|
|
42
32
|
* 供 *AndGetHistoryId 系列方法在调用 add / update / remove 后取回本次产生的历史记录 id;
|
|
43
33
|
* 普通方法不读取它,调用前由 *AndGetHistoryId 重置为 null。
|
|
44
34
|
*/
|
|
45
35
|
lastPushedHistoryId = null;
|
|
46
|
-
constructor() {
|
|
36
|
+
constructor(ctx) {
|
|
47
37
|
super(canUsePluginMethods.sync.map((methodName) => ({
|
|
48
38
|
name: methodName,
|
|
49
39
|
isAsync: false
|
|
50
40
|
})));
|
|
41
|
+
this.ctx = ctx;
|
|
42
|
+
this.state = ctx.reactivity.reactive({
|
|
43
|
+
datasourceTypeList: [],
|
|
44
|
+
dataSources: [],
|
|
45
|
+
editable: true,
|
|
46
|
+
configs: {},
|
|
47
|
+
values: {},
|
|
48
|
+
events: {},
|
|
49
|
+
methods: {}
|
|
50
|
+
});
|
|
51
51
|
}
|
|
52
52
|
set(name, value) {
|
|
53
53
|
this.state[name] = value;
|
|
@@ -87,6 +87,7 @@ var DataSource = class extends BaseService {
|
|
|
87
87
|
* @param options.historyDescription 入栈时附带的人类可读描述,用于历史面板展示
|
|
88
88
|
*/
|
|
89
89
|
add(config, { doNotPushHistory = false, historyDescription, historySource } = {}) {
|
|
90
|
+
this.ctx.validator.guardDataSource(config, true);
|
|
90
91
|
const newConfig = {
|
|
91
92
|
...config,
|
|
92
93
|
id: config.id && !this.getDataSourceById(config.id) ? config.id : this.createId()
|
|
@@ -99,7 +100,7 @@ var DataSource = class extends BaseService {
|
|
|
99
100
|
historyDescription,
|
|
100
101
|
source: historySource
|
|
101
102
|
});
|
|
102
|
-
this.lastPushedHistoryId = (step ?
|
|
103
|
+
this.lastPushedHistoryId = (step ? this.ctx.history.push("dataSource", step, newConfig.id) : null)?.uuid ?? null;
|
|
103
104
|
}
|
|
104
105
|
this.emit("add", newConfig);
|
|
105
106
|
this.emit("change", this.get("dataSources"));
|
|
@@ -114,6 +115,7 @@ var DataSource = class extends BaseService {
|
|
|
114
115
|
* @param data.historyDescription 入栈时附带的人类可读描述,用于历史面板展示
|
|
115
116
|
*/
|
|
116
117
|
update(config, { changeRecords = [], doNotPushHistory = false, historyDescription, historySource } = {}) {
|
|
118
|
+
this.ctx.validator.guardDataSource(config, false);
|
|
117
119
|
const dataSources = this.get("dataSources");
|
|
118
120
|
const index = dataSources.findIndex((ds) => ds.id === config.id);
|
|
119
121
|
const oldConfig = dataSources[index];
|
|
@@ -127,7 +129,7 @@ var DataSource = class extends BaseService {
|
|
|
127
129
|
historyDescription,
|
|
128
130
|
source: historySource
|
|
129
131
|
});
|
|
130
|
-
this.lastPushedHistoryId = (step ?
|
|
132
|
+
this.lastPushedHistoryId = (step ? this.ctx.history.push("dataSource", step, newConfig.id) : null)?.uuid ?? null;
|
|
131
133
|
}
|
|
132
134
|
this.emit("update", newConfig, {
|
|
133
135
|
oldConfig,
|
|
@@ -155,7 +157,7 @@ var DataSource = class extends BaseService {
|
|
|
155
157
|
historyDescription,
|
|
156
158
|
source: historySource
|
|
157
159
|
});
|
|
158
|
-
this.lastPushedHistoryId = (step ?
|
|
160
|
+
this.lastPushedHistoryId = (step ? this.ctx.history.push("dataSource", step, id) : null)?.uuid ?? null;
|
|
159
161
|
}
|
|
160
162
|
this.emit("remove", id);
|
|
161
163
|
this.emit("change", this.get("dataSources"));
|
|
@@ -203,7 +205,7 @@ var DataSource = class extends BaseService {
|
|
|
203
205
|
* @returns 撤销的 step;栈不存在或已无可撤销时返回 null
|
|
204
206
|
*/
|
|
205
207
|
undo(id) {
|
|
206
|
-
const step =
|
|
208
|
+
const step = this.ctx.history.undo("dataSource", id);
|
|
207
209
|
if (!step) return null;
|
|
208
210
|
this.applyHistoryStep(step, true);
|
|
209
211
|
return step;
|
|
@@ -214,18 +216,18 @@ var DataSource = class extends BaseService {
|
|
|
214
216
|
* @returns 重做的 step;栈不存在或已无可重做时返回 null
|
|
215
217
|
*/
|
|
216
218
|
redo(id) {
|
|
217
|
-
const step =
|
|
219
|
+
const step = this.ctx.history.redo("dataSource", id);
|
|
218
220
|
if (!step) return null;
|
|
219
221
|
this.applyHistoryStep(step, false);
|
|
220
222
|
return step;
|
|
221
223
|
}
|
|
222
224
|
/** 是否可对指定数据源撤销。 */
|
|
223
225
|
canUndo(id) {
|
|
224
|
-
return
|
|
226
|
+
return this.ctx.history.canUndo("dataSource", id);
|
|
225
227
|
}
|
|
226
228
|
/** 是否可对指定数据源重做。 */
|
|
227
229
|
canRedo(id) {
|
|
228
|
-
return
|
|
230
|
+
return this.ctx.history.canRedo("dataSource", id);
|
|
229
231
|
}
|
|
230
232
|
/**
|
|
231
233
|
* 跳转指定数据源的历史栈到目标游标。语义同 editor.gotoPageStep。
|
|
@@ -235,7 +237,7 @@ var DataSource = class extends BaseService {
|
|
|
235
237
|
* @returns 实际移动到的最终游标位置
|
|
236
238
|
*/
|
|
237
239
|
goto(id, targetCursor) {
|
|
238
|
-
let cursor =
|
|
240
|
+
let cursor = this.ctx.history.getCursor("dataSource", id);
|
|
239
241
|
const target = Math.max(0, targetCursor);
|
|
240
242
|
while (cursor > target) {
|
|
241
243
|
if (!this.undo(id)) break;
|
|
@@ -258,7 +260,7 @@ var DataSource = class extends BaseService {
|
|
|
258
260
|
* @returns 反向后产生的新 step;目标不存在 / 未应用时返回 null
|
|
259
261
|
*/
|
|
260
262
|
revert(id, index) {
|
|
261
|
-
const entry =
|
|
263
|
+
const entry = this.ctx.history.getStepList("dataSource", id)[index];
|
|
262
264
|
if (!entry?.applied) return null;
|
|
263
265
|
const { oldSchema, newSchema, changeRecords } = entry.step.diff?.[0] ?? {};
|
|
264
266
|
if (oldSchema && newSchema && !changeRecords?.length) return null;
|
|
@@ -274,7 +276,7 @@ var DataSource = class extends BaseService {
|
|
|
274
276
|
*/
|
|
275
277
|
revertById(uuids) {
|
|
276
278
|
return uuids.map((uuid) => {
|
|
277
|
-
const location =
|
|
279
|
+
const location = this.ctx.history.findStepLocationByUuid("dataSource", uuid);
|
|
278
280
|
if (!location) return null;
|
|
279
281
|
return this.revert(location.id, location.index);
|
|
280
282
|
});
|
|
@@ -310,7 +312,7 @@ var DataSource = class extends BaseService {
|
|
|
310
312
|
coperWatcher.addTarget(customTarget);
|
|
311
313
|
coperWatcher.collect(copyNodes, {}, true, collectorOptions.type);
|
|
312
314
|
Object.keys(customTarget.deps).forEach((nodeId) => {
|
|
313
|
-
const node =
|
|
315
|
+
const node = this.ctx.editor.getNodeById(nodeId);
|
|
314
316
|
if (!node) return;
|
|
315
317
|
customTarget.deps[nodeId].keys.forEach((key) => {
|
|
316
318
|
const [relateDsId] = get(node, key);
|
|
@@ -321,14 +323,14 @@ var DataSource = class extends BaseService {
|
|
|
321
323
|
});
|
|
322
324
|
});
|
|
323
325
|
}
|
|
324
|
-
|
|
326
|
+
this.ctx.storage.setItem(COPY_DS_STORAGE_KEY, copyData, { protocol: Protocol.OBJECT });
|
|
325
327
|
}
|
|
326
328
|
/**
|
|
327
329
|
* 粘贴数据源
|
|
328
330
|
* @returns
|
|
329
331
|
*/
|
|
330
332
|
paste() {
|
|
331
|
-
|
|
333
|
+
this.ctx.storage.getItem(COPY_DS_STORAGE_KEY).forEach((item) => {
|
|
332
334
|
if (!this.getDataSourceById(item.id)) this.add(item);
|
|
333
335
|
});
|
|
334
336
|
}
|
|
@@ -344,14 +346,14 @@ var DataSource = class extends BaseService {
|
|
|
344
346
|
historyDescription,
|
|
345
347
|
historySource: "rollback"
|
|
346
348
|
});
|
|
347
|
-
return
|
|
349
|
+
return this.ctx.history.getStepList("dataSource", id).slice(-1)[0]?.step ?? null;
|
|
348
350
|
}
|
|
349
351
|
if (oldSchema && !newSchema) {
|
|
350
352
|
this.add(cloneDeep$1(oldSchema), {
|
|
351
353
|
historyDescription,
|
|
352
354
|
historySource: "rollback"
|
|
353
355
|
});
|
|
354
|
-
return
|
|
356
|
+
return this.ctx.history.getStepList("dataSource", id).slice(-1)[0]?.step ?? null;
|
|
355
357
|
}
|
|
356
358
|
if (!oldSchema || !newSchema) return null;
|
|
357
359
|
if (changeRecords?.length) {
|
|
@@ -372,13 +374,13 @@ var DataSource = class extends BaseService {
|
|
|
372
374
|
historyDescription,
|
|
373
375
|
historySource: "rollback"
|
|
374
376
|
});
|
|
375
|
-
return
|
|
377
|
+
return this.ctx.history.getStepList("dataSource", id).slice(-1)[0]?.step ?? null;
|
|
376
378
|
}
|
|
377
379
|
this.update(cloneDeep$1(oldSchema), {
|
|
378
380
|
historyDescription,
|
|
379
381
|
historySource: "rollback"
|
|
380
382
|
});
|
|
381
|
-
return
|
|
383
|
+
return this.ctx.history.getStepList("dataSource", id).slice(-1)[0]?.step ?? null;
|
|
382
384
|
}
|
|
383
385
|
/**
|
|
384
386
|
* 把一条历史 step 应用到当前数据源服务上。
|
|
@@ -431,6 +433,5 @@ var DataSource = class extends BaseService {
|
|
|
431
433
|
this.update(cloneDeep$1(sourceForValues), { doNotPushHistory: true });
|
|
432
434
|
}
|
|
433
435
|
};
|
|
434
|
-
var dataSource_default = new DataSource();
|
|
435
436
|
//#endregion
|
|
436
|
-
export {
|
|
437
|
+
export { DataSource as default };
|
|
@@ -1,25 +1,36 @@
|
|
|
1
1
|
import BaseService from "./BaseService.js";
|
|
2
|
-
import { IdleTask } from "
|
|
3
|
-
import { CollectWorkerClient } from "../utils/dep/collect-worker-client.js";
|
|
2
|
+
import { IdleTask } from "../../utils/dep/idle-task.js";
|
|
4
3
|
import { isPage } from "@tmagic/utils";
|
|
5
4
|
import { DepTargetType, Watcher, traverseTarget } from "@tmagic/core";
|
|
6
|
-
import { reactive, shallowReactive } from "vue";
|
|
7
5
|
import { throttle } from "lodash-es";
|
|
8
|
-
//#region packages/editor/src/services/
|
|
6
|
+
//#region packages/editor/src/sdk/services/Dep.ts
|
|
7
|
+
/** Node 下没有 worker 时使用:始终不可用,依赖收集退回主线程空闲队列 */
|
|
8
|
+
var noopCollectWorker = {
|
|
9
|
+
isSupported: false,
|
|
10
|
+
collectDsl: () => Promise.resolve(null),
|
|
11
|
+
collect: () => Promise.resolve(null),
|
|
12
|
+
terminate: () => {},
|
|
13
|
+
abort: () => {}
|
|
14
|
+
};
|
|
9
15
|
var Dep = class extends BaseService {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
taskLength: 0
|
|
13
|
-
});
|
|
16
|
+
ctx;
|
|
17
|
+
state;
|
|
14
18
|
idleTask = new IdleTask();
|
|
15
|
-
collectWorker
|
|
16
|
-
watcher
|
|
19
|
+
collectWorker;
|
|
20
|
+
watcher;
|
|
17
21
|
waitingWorker;
|
|
18
22
|
resolveWaitingWorker;
|
|
19
23
|
workerGeneration = 0;
|
|
20
24
|
activeBatches = /* @__PURE__ */ new Set();
|
|
21
|
-
constructor() {
|
|
25
|
+
constructor(ctx) {
|
|
22
26
|
super();
|
|
27
|
+
this.ctx = ctx;
|
|
28
|
+
this.state = ctx.reactivity.shallowReactive({
|
|
29
|
+
collecting: false,
|
|
30
|
+
taskLength: 0
|
|
31
|
+
});
|
|
32
|
+
this.collectWorker = ctx.options.collectWorker ?? noopCollectWorker;
|
|
33
|
+
this.watcher = new Watcher({ initialTargets: ctx.reactivity.reactive({}) });
|
|
23
34
|
this.idleTask.on("update-task-length", throttle(({ length }) => {
|
|
24
35
|
this.set("taskLength", length);
|
|
25
36
|
}, 1e3));
|
|
@@ -115,7 +126,7 @@ var Dep = class extends BaseService {
|
|
|
115
126
|
}
|
|
116
127
|
traverseTarget(this.watcher.getTargetsList(), (target) => {
|
|
117
128
|
if (depsData[target.type]?.[target.id]) {
|
|
118
|
-
target.deps = reactive(depsData[target.type][target.id]);
|
|
129
|
+
target.deps = this.ctx.reactivity.reactive(depsData[target.type][target.id]);
|
|
119
130
|
if (target.type === DepTargetType.DATA_SOURCE && dsl.dataSourceDeps) dsl.dataSourceDeps[target.id] = target.deps;
|
|
120
131
|
else if (target.type === DepTargetType.DATA_SOURCE_COND && dsl.dataSourceCondDeps) dsl.dataSourceCondDeps[target.id] = target.deps;
|
|
121
132
|
else if (target.type === DepTargetType.DATA_SOURCE_METHOD && dsl.dataSourceMethodDeps) dsl.dataSourceMethodDeps[target.id] = target.deps;
|
|
@@ -301,6 +312,5 @@ var Dep = class extends BaseService {
|
|
|
301
312
|
this.set("collecting", this.activeBatches.size > 0);
|
|
302
313
|
}
|
|
303
314
|
};
|
|
304
|
-
var dep_default = new Dep();
|
|
305
315
|
//#endregion
|
|
306
|
-
export {
|
|
316
|
+
export { Dep as default };
|