@tmagic/editor 1.8.2 → 1.8.4-beta.1
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 +23 -25
- 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/headless.js +1 -2
- package/dist/es/hooks/use-stage.js +19 -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/NavMenuColumn.vue_vue_type_script_setup_true_lang.js +12 -2
- package/dist/es/layouts/page-bar/AddButton.vue_vue_type_script_setup_true_lang.js +4 -6
- 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/layouts/sidebar/ComponentListPanel.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/es/layouts/workspace/viewer/Stage.vue_vue_type_script_setup_true_lang.js +3 -0
- 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} +27 -17
- 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/style.css +31 -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/dep/worker.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/style.css +31 -6
- package/dist/themes/magic-admin.css +31 -6
- package/dist/tmagic-editor-headless.umd.cjs +4690 -2891
- package/dist/tmagic-editor-sdk.umd.cjs +9911 -0
- package/dist/tmagic-editor.umd.cjs +14155 -13319
- package/package.json +13 -8
- package/src/Editor.vue +14 -9
- package/src/editorProps.ts +23 -0
- 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 +2 -1
- package/src/index.ts +11 -9
- package/src/initService.ts +59 -188
- package/src/layouts/Framework.vue +1 -1
- package/src/layouts/NavMenuColumn.vue +16 -4
- package/src/layouts/page-bar/AddButton.vue +5 -6
- package/src/layouts/props-panel/PropsPanel.vue +1 -1
- package/src/layouts/props-panel/use-style-panel.ts +1 -1
- package/src/layouts/sidebar/ComponentListPanel.vue +7 -1
- package/src/layouts/workspace/viewer/Stage.vue +5 -0
- 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} +29 -12
- 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/theme/nav-menu.scss +29 -2
- package/src/type.ts +33 -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 +797 -540
- package/types/sdk.d.ts +2594 -0
- /package/src/{services → sdk/services}/BaseService.ts +0 -0
package/dist/es/initService.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isIncludeDataSource } from "./utils/editor.js";
|
|
2
1
|
import { error } from "./utils/logger.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { addDataSourceTargets, classifyUpdatedNodes, getDataSourceRecollectTypes, removeDataSourceTargets, removeTargetDeps, resetDepTargets, writeTargetDeps } from "./sdk/utils/dep.js";
|
|
3
|
+
import { getDepNodeIds, getNodes, isPage } from "@tmagic/utils";
|
|
4
|
+
import { DepTargetType, NodeType, createCodeBlockTarget, updateNode } from "@tmagic/core";
|
|
5
5
|
import { nextTick, onBeforeUnmount, reactive, toRaw, watch } from "vue";
|
|
6
6
|
import { cloneDeep as cloneDeep$1 } from "lodash-es";
|
|
7
7
|
//#region packages/editor/src/initService.ts
|
|
@@ -66,6 +66,10 @@ var initServiceState = (props, { editorService, historyService, componentListSer
|
|
|
66
66
|
watch(() => props.stageRect, (stageRect) => stageRect && uiService.set("stageRect", stageRect), { immediate: true });
|
|
67
67
|
watch(() => props.disabledCodeBlock, (disabledCodeBlock) => propsService.setDisabledCodeBlock(disabledCodeBlock ?? false), { immediate: true });
|
|
68
68
|
watch(() => props.disabledDataSource, (disabledDataSource) => propsService.setDisabledDataSource(disabledDataSource ?? false), { immediate: true });
|
|
69
|
+
watch(() => [props.disabledPageFragment, props.canDropIn], ([disabledPageFragment, canDropIn]) => editorService.setConfig({
|
|
70
|
+
disabledPageFragment: disabledPageFragment ?? false,
|
|
71
|
+
canDropIn
|
|
72
|
+
}), { immediate: true });
|
|
69
73
|
onBeforeUnmount(() => {
|
|
70
74
|
editorService.resetState();
|
|
71
75
|
historyService.resetState();
|
|
@@ -198,20 +202,13 @@ var initServiceEvents = (props, emit, { editorService, codeBlockService, dataSou
|
|
|
198
202
|
runtime?.updateRootConfig?.(dsl);
|
|
199
203
|
}
|
|
200
204
|
};
|
|
201
|
-
const initDataSourceDepTarget = (ds) => {
|
|
202
|
-
depService.addTarget(createDataSourceTarget(ds, reactive({})));
|
|
203
|
-
depService.addTarget(createDataSourceMethodTarget(ds, reactive({})));
|
|
204
|
-
depService.addTarget(createDataSourceCondTarget(ds, reactive({})));
|
|
205
|
-
};
|
|
206
205
|
const rootChangeHandler = (value) => {
|
|
207
206
|
if (!value) return;
|
|
208
207
|
value.codeBlocks = value.codeBlocks || {};
|
|
209
208
|
value.dataSources = value.dataSources || [];
|
|
210
209
|
codeBlockService.setCodeDsl(value.codeBlocks);
|
|
211
210
|
dataSourceService.set("dataSources", value.dataSources);
|
|
212
|
-
depService.
|
|
213
|
-
for (const [id, code] of Object.entries(value.codeBlocks)) depService.addTarget(createCodeBlockTarget(id, code));
|
|
214
|
-
for (const ds of dataSourceService.get("dataSources")) initDataSourceDepTarget(ds);
|
|
211
|
+
resetDepTargets(depService, value.codeBlocks, dataSourceService.get("dataSources"), reactive);
|
|
215
212
|
if (Array.isArray(value.items)) updateStageDsl(value);
|
|
216
213
|
else {
|
|
217
214
|
depService.clear();
|
|
@@ -239,29 +236,7 @@ var initServiceEvents = (props, emit, { editorService, codeBlockService, dataSou
|
|
|
239
236
|
});
|
|
240
237
|
};
|
|
241
238
|
const nodeUpdateHandler = (data) => {
|
|
242
|
-
const needRecollectNodes =
|
|
243
|
-
const normalNodes = [];
|
|
244
|
-
for (const { newNode, oldNode, changeRecords } of data) if (newNode.type === NodeType.ROOT) normalNodes.push(newNode);
|
|
245
|
-
else if (changeRecords?.length) forChangeRecords: for (const record of changeRecords) {
|
|
246
|
-
if (!record.propPath) {
|
|
247
|
-
needRecollectNodes.push(newNode);
|
|
248
|
-
break forChangeRecords;
|
|
249
|
-
}
|
|
250
|
-
if (new RegExp(`${NODE_CONDS_KEY}.(\\d)+.cond`).test(record.propPath) || new RegExp(`${NODE_CONDS_KEY}.(\\d)+.cond.(\\d)+.value`).test(record.propPath) || record.propPath === NODE_CONDS_KEY || isValueIncludeDataSource(record.value)) {
|
|
251
|
-
needRecollectNodes.push(newNode);
|
|
252
|
-
break forChangeRecords;
|
|
253
|
-
}
|
|
254
|
-
for (const target of Object.values(depService.getTargets(DepTargetType.DATA_SOURCE))) {
|
|
255
|
-
if (!target.deps[newNode.id]) continue;
|
|
256
|
-
if (target.deps[newNode.id].keys.includes(record.propPath)) {
|
|
257
|
-
needRecollectNodes.push(newNode);
|
|
258
|
-
break forChangeRecords;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
normalNodes.push(newNode);
|
|
262
|
-
}
|
|
263
|
-
else if (isIncludeDataSource(newNode, oldNode)) needRecollectNodes.push(newNode);
|
|
264
|
-
else normalNodes.push(newNode);
|
|
239
|
+
const { needRecollectNodes, normalNodes } = classifyUpdatedNodes({ dep: depService }, data);
|
|
265
240
|
if (needRecollectNodes.length) {
|
|
266
241
|
const handler = async () => {
|
|
267
242
|
if (!await collectIdle(needRecollectNodes, true, DepTargetType.DATA_SOURCE)) return;
|
|
@@ -269,10 +244,9 @@ var initServiceEvents = (props, emit, { editorService, codeBlockService, dataSou
|
|
|
269
244
|
updateStageNodes(needRecollectNodes);
|
|
270
245
|
};
|
|
271
246
|
handler();
|
|
272
|
-
} else
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
247
|
+
} else updateStageNodes(normalNodes);
|
|
248
|
+
const updatedNodes = [...needRecollectNodes, ...normalNodes];
|
|
249
|
+
Promise.all([collectIdle(updatedNodes, true, DepTargetType.CODE_BLOCK), collectIdle(updatedNodes, true, DepTargetType.DATA_SOURCE_METHOD)]);
|
|
276
250
|
};
|
|
277
251
|
const nodeRemoveHandler = (nodes) => {
|
|
278
252
|
depService.clear(nodes);
|
|
@@ -289,7 +263,7 @@ var initServiceEvents = (props, emit, { editorService, codeBlockService, dataSou
|
|
|
289
263
|
editorService.on("update", nodeUpdateHandler);
|
|
290
264
|
const dataSourceAddHandler = (config) => {
|
|
291
265
|
const handler = async () => {
|
|
292
|
-
|
|
266
|
+
addDataSourceTargets(depService, config, reactive);
|
|
293
267
|
const app = await getTMagicApp();
|
|
294
268
|
if (!app?.dataSourceManager) return;
|
|
295
269
|
app.dataSourceManager.addDataSource(config);
|
|
@@ -307,52 +281,24 @@ var initServiceEvents = (props, emit, { editorService, codeBlockService, dataSou
|
|
|
307
281
|
ds.setFields(config.fields);
|
|
308
282
|
ds.setData(config.mocks?.find((mock) => mock.useInEditor)?.data || ds.getDefaultData());
|
|
309
283
|
};
|
|
310
|
-
|
|
311
|
-
let isModifyField = false;
|
|
312
|
-
let isModifyMock = false;
|
|
313
|
-
let isModifyMethod = false;
|
|
314
|
-
for (const changeRecord of changeRecords) {
|
|
315
|
-
if (!changeRecord.propPath) continue;
|
|
316
|
-
isModifyField = changeRecord.propPath === "fields" || /fields.(\d)+.name/.test(changeRecord.propPath) || /fields.(\d)+.defaultValue/.test(changeRecord.propPath) || /fields.(\d)+$/.test(changeRecord.propPath);
|
|
317
|
-
isModifyMock = changeRecord.propPath === "mocks";
|
|
318
|
-
isModifyMethod = changeRecord.propPath === "methods" || /methods.(\d)+.name/.test(changeRecord.propPath) || /methods.(\d)+$/.test(changeRecord.propPath);
|
|
319
|
-
needRecollectDep = isModifyField || isModifyMock || isModifyMethod;
|
|
320
|
-
if (needRecollectDep) break;
|
|
321
|
-
}
|
|
284
|
+
const types = getDataSourceRecollectTypes(changeRecords);
|
|
322
285
|
const root = editorService.get("root");
|
|
323
|
-
if (
|
|
324
|
-
if (
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
depService.addTarget(createDataSourceMethodTarget(config, reactive({})));
|
|
340
|
-
collectIdlePromises = [collectIdle(root.items, true, DepTargetType.DATA_SOURCE_METHOD)];
|
|
341
|
-
}
|
|
342
|
-
const handler = async () => {
|
|
343
|
-
if (!(await Promise.all(collectIdlePromises)).every(Boolean)) return;
|
|
344
|
-
updateDataSourceSchema();
|
|
345
|
-
await updateDsData();
|
|
346
|
-
updateStageNodes(root.items);
|
|
347
|
-
};
|
|
348
|
-
handler();
|
|
349
|
-
}
|
|
350
|
-
} else if (root?.dataSources) updateDsData();
|
|
351
|
-
};
|
|
352
|
-
const removeDataSourceTarget = (id) => {
|
|
353
|
-
depService.removeTarget(id, DepTargetType.DATA_SOURCE);
|
|
354
|
-
depService.removeTarget(id, DepTargetType.DATA_SOURCE_COND);
|
|
355
|
-
depService.removeTarget(id, DepTargetType.DATA_SOURCE_METHOD);
|
|
286
|
+
if (!types) {
|
|
287
|
+
if (root?.dataSources) updateDsData();
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (!Array.isArray(root?.items)) return;
|
|
291
|
+
depService.clearIdleTasks();
|
|
292
|
+
removeDataSourceTargets(depService, config.id, types);
|
|
293
|
+
addDataSourceTargets(depService, config, reactive, types);
|
|
294
|
+
const collectIdlePromises = types.map((type) => collectIdle(root.items, true, type));
|
|
295
|
+
const handler = async () => {
|
|
296
|
+
if (!(await Promise.all(collectIdlePromises)).every(Boolean)) return;
|
|
297
|
+
updateDataSourceSchema();
|
|
298
|
+
await updateDsData();
|
|
299
|
+
updateStageNodes(root.items);
|
|
300
|
+
};
|
|
301
|
+
handler();
|
|
356
302
|
};
|
|
357
303
|
const dataSourceRemoveHandler = (id) => {
|
|
358
304
|
const root = editorService.get("root");
|
|
@@ -368,7 +314,7 @@ var initServiceEvents = (props, emit, { editorService, codeBlockService, dataSou
|
|
|
368
314
|
updateDataSourceSchema();
|
|
369
315
|
(await getTMagicApp())?.dataSourceManager?.removeDataSource(id);
|
|
370
316
|
updateStageNodes(nodes);
|
|
371
|
-
|
|
317
|
+
removeDataSourceTargets(depService, id);
|
|
372
318
|
};
|
|
373
319
|
handler();
|
|
374
320
|
};
|
|
@@ -387,27 +333,8 @@ var initServiceEvents = (props, emit, { editorService, codeBlockService, dataSou
|
|
|
387
333
|
};
|
|
388
334
|
codeBlockService.on("addOrUpdate", codeBlockAddOrUpdateHandler);
|
|
389
335
|
codeBlockService.on("remove", codeBlockRemoveHandler);
|
|
390
|
-
const targetAddHandler = (target) =>
|
|
391
|
-
|
|
392
|
-
if (!root) return;
|
|
393
|
-
if (target.type === DepTargetType.DATA_SOURCE) {
|
|
394
|
-
if (!root.dataSourceDeps) root.dataSourceDeps = {};
|
|
395
|
-
root.dataSourceDeps[target.id] = target.deps;
|
|
396
|
-
} else if (target.type === DepTargetType.DATA_SOURCE_COND) {
|
|
397
|
-
if (!root.dataSourceCondDeps) root.dataSourceCondDeps = {};
|
|
398
|
-
root.dataSourceCondDeps[target.id] = target.deps;
|
|
399
|
-
} else if (target.type === DepTargetType.DATA_SOURCE_METHOD) {
|
|
400
|
-
if (!root.dataSourceMethodDeps) root.dataSourceMethodDeps = {};
|
|
401
|
-
root.dataSourceMethodDeps[target.id] = target.deps;
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
const targetRemoveHandler = (id, type) => {
|
|
405
|
-
const root = editorService.get("root");
|
|
406
|
-
if (!root) return;
|
|
407
|
-
if (root.dataSourceDeps && type === DepTargetType.DATA_SOURCE) delete root.dataSourceDeps[id];
|
|
408
|
-
if (root.dataSourceCondDeps && type === DepTargetType.DATA_SOURCE_COND) delete root.dataSourceCondDeps[id];
|
|
409
|
-
if (root.dataSourceMethodDeps && type === DepTargetType.DATA_SOURCE_METHOD) delete root.dataSourceMethodDeps[id];
|
|
410
|
-
};
|
|
336
|
+
const targetAddHandler = (target) => writeTargetDeps(editorService.get("root"), target);
|
|
337
|
+
const targetRemoveHandler = (id, type) => removeTargetDeps(editorService.get("root"), id, type);
|
|
411
338
|
depService.on("add-target", targetAddHandler);
|
|
412
339
|
depService.on("remove-target", targetRemoveHandler);
|
|
413
340
|
depService.on("ds-collected", dsDepCollectedHandler);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getEditorConfig } from "../utils/config.js";
|
|
2
|
-
import { Protocol } from "../services/
|
|
2
|
+
import { Protocol } from "../sdk/services/WebStorage.js";
|
|
3
3
|
import { LEFT_COLUMN_WIDTH_STORAGE_KEY, RIGHT_COLUMN_WIDTH_STORAGE_KEY } from "../utils/const.js";
|
|
4
4
|
import { useServices } from "../hooks/use-services.js";
|
|
5
5
|
import SplitView_default from "../components/SplitView.js";
|
|
@@ -12,7 +12,7 @@ var NavMenuColumn_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ de
|
|
|
12
12
|
items: { default: () => [] },
|
|
13
13
|
width: {},
|
|
14
14
|
gap: { default: 3 },
|
|
15
|
-
popoverWidth: {
|
|
15
|
+
popoverWidth: {}
|
|
16
16
|
},
|
|
17
17
|
setup(__props) {
|
|
18
18
|
const props = __props;
|
|
@@ -43,7 +43,17 @@ var NavMenuColumn_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ de
|
|
|
43
43
|
const containerWidth = ref(0);
|
|
44
44
|
const hiddenIndexSet = ref(/* @__PURE__ */ new Set());
|
|
45
45
|
const hasOverflow = computed(() => hiddenIndexSet.value.size > 0);
|
|
46
|
-
const overflowItems = computed(() =>
|
|
46
|
+
const overflowItems = computed(() => {
|
|
47
|
+
const items = props.items.filter((_, index) => hiddenIndexSet.value.has(index)).map((item) => item.type === "divider" ? {
|
|
48
|
+
...item,
|
|
49
|
+
direction: "horizontal"
|
|
50
|
+
} : item);
|
|
51
|
+
let start = 0;
|
|
52
|
+
let end = items.length;
|
|
53
|
+
while (start < end && items[start].type === "divider") start += 1;
|
|
54
|
+
while (end > start && items[end - 1].type === "divider") end -= 1;
|
|
55
|
+
return items.slice(start, end);
|
|
56
|
+
});
|
|
47
57
|
const measureAndCompute = () => {
|
|
48
58
|
if (!columnEl.value) return;
|
|
49
59
|
containerWidth.value = columnEl.value.clientWidth;
|
|
@@ -32,21 +32,19 @@ var AddButton_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
32
32
|
};
|
|
33
33
|
editorService.add(pageConfig);
|
|
34
34
|
};
|
|
35
|
+
const addNormalPage = () => addPage(NodeType.PAGE);
|
|
36
|
+
const addPageFragment = () => addPage(NodeType.PAGE_FRAGMENT);
|
|
35
37
|
return (_ctx, _cache) => {
|
|
36
38
|
return showAddPageButton.value ? (openBlock(), createElementBlock("div", _hoisted_1, [createVNode(unref(TMagicPopover), { "popper-class": "data-source-list-panel-add-menu" }, {
|
|
37
39
|
reference: withCtx(() => [createVNode(Icon_default, { icon: unref(Plus) }, null, 8, ["icon"])]),
|
|
38
40
|
default: withCtx(() => [createVNode(ToolButton_default, { data: {
|
|
39
41
|
type: "button",
|
|
40
42
|
text: "页面",
|
|
41
|
-
handler:
|
|
42
|
-
addPage(unref(NodeType).PAGE);
|
|
43
|
-
}
|
|
43
|
+
handler: addNormalPage
|
|
44
44
|
} }, null, 8, ["data"]), createVNode(ToolButton_default, { data: {
|
|
45
45
|
type: "button",
|
|
46
46
|
text: "页面片",
|
|
47
|
-
handler:
|
|
48
|
-
addPage(unref(NodeType).PAGE_FRAGMENT);
|
|
49
|
-
}
|
|
47
|
+
handler: addPageFragment
|
|
50
48
|
} }, null, 8, ["data"])]),
|
|
51
49
|
_: 1
|
|
52
50
|
})])) : (openBlock(), createElementBlock("div", _hoisted_2));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Protocol } from "../../sdk/services/WebStorage.js";
|
|
2
|
+
import { styleTabConfig } from "../../sdk/utils/props.js";
|
|
3
3
|
import { PROPS_PANEL_WIDTH_STORAGE_KEY } from "../../utils/const.js";
|
|
4
4
|
import { useServices } from "../../hooks/use-services.js";
|
|
5
5
|
import Resizer_default from "../../components/Resizer.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Protocol } from "../../services/
|
|
1
|
+
import { Protocol } from "../../sdk/services/WebStorage.js";
|
|
2
2
|
import { RIGHT_COLUMN_WIDTH_STORAGE_KEY } from "../../utils/const.js";
|
|
3
3
|
import { computed, watch } from "vue";
|
|
4
4
|
//#region packages/editor/src/layouts/props-panel/use-style-panel.ts
|
|
@@ -32,7 +32,11 @@ var ComponentListPanel_vue_vue_type_script_setup_true_lang_default = /*@__PURE__
|
|
|
32
32
|
let timeout;
|
|
33
33
|
let clientX;
|
|
34
34
|
let clientY;
|
|
35
|
-
const appendComponent = (
|
|
35
|
+
const appendComponent = async (item) => {
|
|
36
|
+
if (stageOptions?.beforeAppendComponent) {
|
|
37
|
+
if (await stageOptions.beforeAppendComponent(item) === false) return;
|
|
38
|
+
}
|
|
39
|
+
const { text, type, data = {} } = item;
|
|
36
40
|
editorService.add({
|
|
37
41
|
name: text,
|
|
38
42
|
type,
|
|
@@ -272,6 +272,9 @@ var Stage_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComp
|
|
|
272
272
|
left: calcValueByFontsize(doc, left / zoom.value)
|
|
273
273
|
};
|
|
274
274
|
dragData.inputEvent = e;
|
|
275
|
+
if (props.stageOptions.beforeDropComponent) {
|
|
276
|
+
if (await props.stageOptions.beforeDropComponent(dragData, parent) === false) return;
|
|
277
|
+
}
|
|
275
278
|
editorService.add(dragData, parent, { historySource: "component-panel" });
|
|
276
279
|
}
|
|
277
280
|
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import BaseService from "./services/BaseService.js";
|
|
2
|
+
import { MemoryStorage, Protocol, WebStorage } from "./services/WebStorage.js";
|
|
3
|
+
import CodeBlock from "./services/CodeBlock.js";
|
|
4
|
+
import ComponentList from "./services/ComponentList.js";
|
|
5
|
+
import DataSource from "./services/DataSource.js";
|
|
6
|
+
import Dep from "./services/Dep.js";
|
|
7
|
+
import Editor from "./services/Editor.js";
|
|
8
|
+
import Events from "./services/Events.js";
|
|
9
|
+
import History from "./services/History.js";
|
|
10
|
+
import Props from "./services/Props.js";
|
|
11
|
+
import { DslValidationError, createValidator } from "./validate/index.js";
|
|
12
|
+
import { classifyUpdatedNodes } from "./utils/dep.js";
|
|
13
|
+
import { bindWiring, whenWiringSettled } from "./wiring.js";
|
|
14
|
+
import { nextTick, reactive, shallowReactive, toRaw } from "vue";
|
|
15
|
+
import { cloneDeep, isEmpty } from "lodash-es";
|
|
16
|
+
//#region packages/editor/src/sdk/index.ts
|
|
17
|
+
/**
|
|
18
|
+
* @fileoverview `@tmagic/editor/sdk`:不依赖 DOM 的 DSL 操作 SDK。
|
|
19
|
+
*
|
|
20
|
+
* 每次调用 {@link createDslSdk} 得到一组独立的 service(editor / history / props / dataSource /
|
|
21
|
+
* codeBlock / dep / storage / events / componentList),可在 Node 中运行。浏览器端的
|
|
22
|
+
* `editorService` 等单例就是用同一个工厂创建的默认实例。
|
|
23
|
+
*
|
|
24
|
+
* @module @tmagic/editor/sdk
|
|
25
|
+
*/
|
|
26
|
+
var SERVICE_NAMES = [
|
|
27
|
+
"editor",
|
|
28
|
+
"props",
|
|
29
|
+
"history",
|
|
30
|
+
"dataSource",
|
|
31
|
+
"codeBlock",
|
|
32
|
+
"dep",
|
|
33
|
+
"storage",
|
|
34
|
+
"events",
|
|
35
|
+
"componentList"
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* Node 下默认的 DSL 反序列化:序列化出来的内容是被括号包起来的 JSON(函数、正则等需要自己传入 `parseDSL`)。
|
|
39
|
+
* 刻意不使用 `eval`,避免执行调用方传入的历史快照里的任意代码。
|
|
40
|
+
*/
|
|
41
|
+
var defaultParseDSL = (code) => {
|
|
42
|
+
const text = code.trim();
|
|
43
|
+
const body = text.startsWith("(") && text.endsWith(")") ? text.slice(1, -1) : text;
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(body);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
throw new Error(`默认的 parseDSL 只能解析 JSON,无法还原含函数 / undefined 等的内容(${e?.message ?? e});请在 createDslSdk 的 parseDSL 选项中传入自己的实现`);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
/** 把 options 里的登记表写入各 service,返回需要等待的异步任务(如属性表单配置) */
|
|
51
|
+
var registerOptions = ({ editor, props, events, componentList, dataSource }, options) => {
|
|
52
|
+
if (options.componentGroupList) componentList.setList(options.componentGroupList);
|
|
53
|
+
if (options.datasourceList) dataSource.set("datasourceTypeList", options.datasourceList);
|
|
54
|
+
props.setDisabledCodeBlock(options.disabledCodeBlock ?? false);
|
|
55
|
+
props.setDisabledDataSource(options.disabledDataSource ?? false);
|
|
56
|
+
const pending = [props.setPropsConfigs(options.propsConfigs ?? {}), props.setPropsValues(options.propsValues ?? {})];
|
|
57
|
+
const eventMethodList = Object.entries(options.eventMethodList ?? {});
|
|
58
|
+
events.setEvents(Object.fromEntries(eventMethodList.map(([type, item]) => [type, item.events])));
|
|
59
|
+
events.setMethods(Object.fromEntries(eventMethodList.map(([type, item]) => [type, item.methods])));
|
|
60
|
+
for (const [type, config] of Object.entries(options.datasourceConfigs ?? {})) dataSource.setFormConfig(type, config);
|
|
61
|
+
for (const [type, value] of Object.entries(options.datasourceValues ?? {})) dataSource.setFormValue(type, value);
|
|
62
|
+
for (const [type, item] of Object.entries(options.datasourceEventMethodList ?? {})) {
|
|
63
|
+
dataSource.setFormEvent(type, item.events);
|
|
64
|
+
dataSource.setFormMethod(type, item.methods);
|
|
65
|
+
}
|
|
66
|
+
editor.set("disabledMultiSelect", options.disabledMultiSelect ?? false);
|
|
67
|
+
editor.set("alwaysMultiSelect", options.alwaysMultiSelect ?? false);
|
|
68
|
+
editor.setConfig({
|
|
69
|
+
disabledPageFragment: options.disabledPageFragment ?? false,
|
|
70
|
+
canDropIn: options.canDropIn
|
|
71
|
+
});
|
|
72
|
+
return pending;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* 创建一个相互连线、互相独立的 DSL SDK 实例。
|
|
76
|
+
*
|
|
77
|
+
* @param options 见 {@link SdkOptions}
|
|
78
|
+
*/
|
|
79
|
+
var createDslSdk = (options = {}) => {
|
|
80
|
+
const reactivity = {
|
|
81
|
+
reactive,
|
|
82
|
+
shallowReactive,
|
|
83
|
+
toRaw,
|
|
84
|
+
nextTick,
|
|
85
|
+
...options.reactivity
|
|
86
|
+
};
|
|
87
|
+
const parseDSL = options.parseDSL ?? defaultParseDSL;
|
|
88
|
+
const services = {};
|
|
89
|
+
const ctx = {
|
|
90
|
+
reactivity,
|
|
91
|
+
options,
|
|
92
|
+
validateMode: options.validateMode ?? "strict",
|
|
93
|
+
parseDSL: (code) => parseDSL(code),
|
|
94
|
+
ready: Promise.resolve()
|
|
95
|
+
};
|
|
96
|
+
for (const name of SERVICE_NAMES) Object.defineProperty(ctx, name, {
|
|
97
|
+
get: () => services[name],
|
|
98
|
+
enumerable: true
|
|
99
|
+
});
|
|
100
|
+
services.storage = new WebStorage(ctx, options.storage);
|
|
101
|
+
services.history = new History(ctx);
|
|
102
|
+
services.props = new Props(ctx);
|
|
103
|
+
services.events = new Events(ctx);
|
|
104
|
+
services.componentList = new ComponentList(ctx);
|
|
105
|
+
services.dep = new Dep(ctx);
|
|
106
|
+
services.codeBlock = new CodeBlock(ctx);
|
|
107
|
+
services.dataSource = new DataSource(ctx);
|
|
108
|
+
services.editor = new Editor(ctx);
|
|
109
|
+
const { editor, history } = services;
|
|
110
|
+
const validate = createValidator(ctx);
|
|
111
|
+
ctx.validator = validate;
|
|
112
|
+
const pending = registerOptions(services, options);
|
|
113
|
+
let wiring = null;
|
|
114
|
+
const unbind = () => {
|
|
115
|
+
wiring?.unbind();
|
|
116
|
+
wiring = null;
|
|
117
|
+
};
|
|
118
|
+
const bind = () => {
|
|
119
|
+
wiring ??= bindWiring(ctx);
|
|
120
|
+
return unbind;
|
|
121
|
+
};
|
|
122
|
+
if (options.autoWiring ?? true) bind();
|
|
123
|
+
if (options.history) history.restore(options.history);
|
|
124
|
+
const setDsl = async (dsl) => {
|
|
125
|
+
editor.set("root", dsl ? cloneDeep(dsl) : null);
|
|
126
|
+
await whenWiringSettled(ctx);
|
|
127
|
+
};
|
|
128
|
+
if (options.dsl) pending.push(setDsl(options.dsl));
|
|
129
|
+
ctx.ready = Promise.all(pending).then(() => void 0);
|
|
130
|
+
return {
|
|
131
|
+
...services,
|
|
132
|
+
validate,
|
|
133
|
+
ctx,
|
|
134
|
+
get ready() {
|
|
135
|
+
return ctx.ready;
|
|
136
|
+
},
|
|
137
|
+
getDsl() {
|
|
138
|
+
const root = reactivity.toRaw(editor.get("root"));
|
|
139
|
+
return root && !isEmpty(root) ? cloneDeep(root) : null;
|
|
140
|
+
},
|
|
141
|
+
setDsl,
|
|
142
|
+
bindWiring: bind,
|
|
143
|
+
serializeHistory: () => history.serialize({ jsonSafe: true }),
|
|
144
|
+
destroy() {
|
|
145
|
+
unbind();
|
|
146
|
+
for (const service of Object.values(services)) service.destroy();
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
//#endregion
|
|
151
|
+
export { BaseService, CodeBlock as CodeBlockService, ComponentList as ComponentListService, DataSource as DataSourceService, Dep as DepService, DslValidationError, Editor as EditorService, Events as EventsService, History as HistoryService, MemoryStorage, Props as PropsService, Protocol, WebStorage as StorageService, bindWiring, classifyUpdatedNodes, createDslSdk, createValidator, defaultParseDSL, whenWiringSettled };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
|
-
//#region packages/editor/src/services/BaseService.ts
|
|
2
|
+
//#region packages/editor/src/sdk/services/BaseService.ts
|
|
3
3
|
var methodName = (prefix, name) => `${prefix}${name[0].toUpperCase()}${name.substring(1)}`;
|
|
4
4
|
var isError = (error) => Object.prototype.toString.call(error) === "[object Error]";
|
|
5
5
|
var doAction = (args, scope, sourceMethod, beforeMethodName, afterMethodName) => {
|