@tmagic/editor 1.3.0-alpha.18 → 1.3.0-alpha.19
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/style.css +6 -0
- package/dist/tmagic-editor.js +270 -244
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +270 -242
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +10 -10
- package/src/components/CodeBlockEditor.vue +20 -6
- package/src/fields/CodeSelectCol.vue +1 -1
- package/src/fields/DataSourceFields.vue +10 -4
- package/src/fields/DataSourceMethodSelect.vue +1 -1
- package/src/fields/DataSourceMethods.vue +8 -3
- package/src/hooks/index.ts +21 -0
- package/src/{utils → hooks}/use-data-source-method.ts +1 -2
- package/src/{utils/stage.ts → hooks/use-stage.ts} +1 -2
- package/src/index.ts +1 -0
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +1 -1
- package/src/layouts/workspace/Stage.vue +1 -1
- package/src/theme/code-block.scss +10 -0
- package/src/utils/index.ts +0 -1
- package/types/components/CodeBlockEditor.vue.d.ts +2 -0
- package/types/components/ToolButton.vue.d.ts +3 -3
- package/types/hooks/index.d.ts +3 -0
- package/types/{utils → hooks}/use-code-block-edit.d.ts +7 -0
- package/types/{utils → hooks}/use-data-source-method.d.ts +7 -0
- package/types/index.d.ts +1 -0
- package/types/utils/index.d.ts +0 -1
- /package/src/{utils → hooks}/use-code-block-edit.ts +0 -0
- /package/types/{utils/stage.d.ts → hooks/use-stage.d.ts} +0 -0
|
@@ -402,13 +402,17 @@
|
|
|
402
402
|
__name: "CodeBlockEditor",
|
|
403
403
|
props: {
|
|
404
404
|
content: {},
|
|
405
|
-
disabled: { type: Boolean }
|
|
405
|
+
disabled: { type: Boolean },
|
|
406
|
+
isDataSource: { type: Boolean }
|
|
406
407
|
},
|
|
407
408
|
emits: ["submit"],
|
|
408
409
|
setup(__props, { expose: __expose, emit }) {
|
|
410
|
+
const props = __props;
|
|
409
411
|
const services = vue.inject("services");
|
|
410
412
|
const columnWidth = vue.computed(() => services?.uiService.get("columnWidth"));
|
|
411
|
-
const size = vue.computed(
|
|
413
|
+
const size = vue.computed(
|
|
414
|
+
() => columnWidth.value ? columnWidth.value.center + columnWidth.value.right - (props.isDataSource ? 100 : 0) : 600
|
|
415
|
+
);
|
|
412
416
|
const codeEditorHeight = vue.ref("600px");
|
|
413
417
|
const defaultParamColConfig = {
|
|
414
418
|
type: "row",
|
|
@@ -445,16 +449,26 @@
|
|
|
445
449
|
name: "name"
|
|
446
450
|
},
|
|
447
451
|
{
|
|
448
|
-
text: "
|
|
452
|
+
text: "描述",
|
|
449
453
|
name: "desc"
|
|
450
454
|
},
|
|
455
|
+
{
|
|
456
|
+
text: "执行时机",
|
|
457
|
+
name: "timing",
|
|
458
|
+
type: "select",
|
|
459
|
+
options: [
|
|
460
|
+
{ text: "初始化前", value: "beforeInit" },
|
|
461
|
+
{ text: "初始化后", value: "afterInit" }
|
|
462
|
+
],
|
|
463
|
+
display: () => props.isDataSource
|
|
464
|
+
},
|
|
451
465
|
{
|
|
452
466
|
type: "table",
|
|
453
467
|
border: true,
|
|
454
468
|
text: "参数",
|
|
455
469
|
enableFullscreen: false,
|
|
470
|
+
enableToggleMode: false,
|
|
456
471
|
name: "params",
|
|
457
|
-
maxHeight: "300px",
|
|
458
472
|
dropSort: false,
|
|
459
473
|
items: [
|
|
460
474
|
{
|
|
@@ -464,7 +478,7 @@
|
|
|
464
478
|
},
|
|
465
479
|
{
|
|
466
480
|
type: "text",
|
|
467
|
-
label: "
|
|
481
|
+
label: "描述",
|
|
468
482
|
name: "extra"
|
|
469
483
|
},
|
|
470
484
|
services?.codeBlockService.getParamsColConfig() || defaultParamColConfig
|
|
@@ -496,7 +510,7 @@
|
|
|
496
510
|
const openHandler = () => {
|
|
497
511
|
setTimeout(() => {
|
|
498
512
|
if (fomDrawer.value) {
|
|
499
|
-
const height = fomDrawer.value?.bodyHeight -
|
|
513
|
+
const height = fomDrawer.value?.bodyHeight - 348 - (props.isDataSource ? 50 : 0);
|
|
500
514
|
codeEditorHeight.value = `${height > 100 ? height : 600}px`;
|
|
501
515
|
}
|
|
502
516
|
});
|
|
@@ -511,6 +525,7 @@
|
|
|
511
525
|
});
|
|
512
526
|
return (_ctx, _cache) => {
|
|
513
527
|
return vue.openBlock(), vue.createBlock(vue.unref(form.MFormDrawer), {
|
|
528
|
+
class: "m-editor-code-block-editor",
|
|
514
529
|
ref_key: "fomDrawer",
|
|
515
530
|
ref: fomDrawer,
|
|
516
531
|
"label-width": "80px",
|
|
@@ -833,6 +848,10 @@
|
|
|
833
848
|
label: "属性描述",
|
|
834
849
|
prop: "desc"
|
|
835
850
|
},
|
|
851
|
+
{
|
|
852
|
+
label: "默认值",
|
|
853
|
+
prop: "defaultValue"
|
|
854
|
+
},
|
|
836
855
|
{
|
|
837
856
|
label: "操作",
|
|
838
857
|
fixed: "right",
|
|
@@ -908,7 +927,8 @@
|
|
|
908
927
|
},
|
|
909
928
|
{
|
|
910
929
|
name: "description",
|
|
911
|
-
text: "描述"
|
|
930
|
+
text: "描述",
|
|
931
|
+
type: "textarea"
|
|
912
932
|
},
|
|
913
933
|
{
|
|
914
934
|
name: "defaultValue",
|
|
@@ -947,9 +967,10 @@
|
|
|
947
967
|
_: 1
|
|
948
968
|
}, 8, ["disabled"])
|
|
949
969
|
]),
|
|
950
|
-
vue.createVNode(vue.unref(form.
|
|
970
|
+
vue.createVNode(vue.unref(form.MFormDrawer), {
|
|
951
971
|
ref_key: "addDialog",
|
|
952
972
|
ref: addDialog,
|
|
973
|
+
"label-width": "80px",
|
|
953
974
|
title: filedTitle.value,
|
|
954
975
|
config: dataSourceFieldsConfig,
|
|
955
976
|
values: fieldValues.value,
|
|
@@ -1379,9 +1400,13 @@
|
|
|
1379
1400
|
prop: "name"
|
|
1380
1401
|
},
|
|
1381
1402
|
{
|
|
1382
|
-
label: "
|
|
1403
|
+
label: "描述",
|
|
1383
1404
|
prop: "desc"
|
|
1384
1405
|
},
|
|
1406
|
+
{
|
|
1407
|
+
label: "执行时机",
|
|
1408
|
+
prop: "timing"
|
|
1409
|
+
},
|
|
1385
1410
|
{
|
|
1386
1411
|
label: "参数",
|
|
1387
1412
|
prop: "params",
|
|
@@ -1443,6 +1468,7 @@
|
|
|
1443
1468
|
ref: codeBlockEditor,
|
|
1444
1469
|
disabled: _ctx.disabled,
|
|
1445
1470
|
content: vue.unref(codeConfig),
|
|
1471
|
+
"is-data-source": true,
|
|
1446
1472
|
onSubmit: submitCodeHandler
|
|
1447
1473
|
}, null, 8, ["disabled", "content"])) : vue.createCommentVNode("", true)
|
|
1448
1474
|
]);
|
|
@@ -3541,78 +3567,6 @@
|
|
|
3541
3567
|
}
|
|
3542
3568
|
const propsService = new Props();
|
|
3543
3569
|
|
|
3544
|
-
const beforePaste = async (position, config) => {
|
|
3545
|
-
if (!config[0]?.style)
|
|
3546
|
-
return config;
|
|
3547
|
-
const curNode = editorService.get("node");
|
|
3548
|
-
const { left: referenceLeft, top: referenceTop } = config[0].style;
|
|
3549
|
-
const pasteConfigs = await Promise.all(
|
|
3550
|
-
config.map(async (configItem) => {
|
|
3551
|
-
const { offsetX = 0, offsetY = 0, ...positionClone } = position;
|
|
3552
|
-
let pastePosition = positionClone;
|
|
3553
|
-
if (!lodashEs.isEmpty(pastePosition) && curNode?.items) {
|
|
3554
|
-
pastePosition = getPositionInContainer(pastePosition, curNode.id);
|
|
3555
|
-
}
|
|
3556
|
-
if (pastePosition.left && configItem.style?.left) {
|
|
3557
|
-
pastePosition.left = configItem.style.left - referenceLeft + pastePosition.left;
|
|
3558
|
-
}
|
|
3559
|
-
if (pastePosition.top && configItem.style?.top) {
|
|
3560
|
-
pastePosition.top = configItem.style?.top - referenceTop + pastePosition.top;
|
|
3561
|
-
}
|
|
3562
|
-
const pasteConfig = await propsService.setNewItemId(configItem);
|
|
3563
|
-
if (pasteConfig.style) {
|
|
3564
|
-
const { left, top } = pasteConfig.style;
|
|
3565
|
-
if (typeof left === "number" || !!left && !isNaN(Number(left))) {
|
|
3566
|
-
pasteConfig.style.left = Number(left) + offsetX;
|
|
3567
|
-
}
|
|
3568
|
-
if (typeof top === "number" || !!top && !isNaN(Number(top))) {
|
|
3569
|
-
pasteConfig.style.top = Number(top) + offsetY;
|
|
3570
|
-
}
|
|
3571
|
-
pasteConfig.style = {
|
|
3572
|
-
...pasteConfig.style,
|
|
3573
|
-
...pastePosition
|
|
3574
|
-
};
|
|
3575
|
-
}
|
|
3576
|
-
const root = editorService.get("root");
|
|
3577
|
-
if (utils.isPage(pasteConfig) && root) {
|
|
3578
|
-
pasteConfig.name = generatePageNameByApp(root);
|
|
3579
|
-
}
|
|
3580
|
-
return pasteConfig;
|
|
3581
|
-
})
|
|
3582
|
-
);
|
|
3583
|
-
return pasteConfigs;
|
|
3584
|
-
};
|
|
3585
|
-
const getPositionInContainer = (position = {}, id) => {
|
|
3586
|
-
let { left = 0, top = 0 } = position;
|
|
3587
|
-
const parentEl = editorService.get("stage")?.renderer?.contentWindow?.document.getElementById(`${id}`);
|
|
3588
|
-
const parentElRect = parentEl?.getBoundingClientRect();
|
|
3589
|
-
left = left - (parentElRect?.left || 0);
|
|
3590
|
-
top = top - (parentElRect?.top || 0);
|
|
3591
|
-
return {
|
|
3592
|
-
left,
|
|
3593
|
-
top
|
|
3594
|
-
};
|
|
3595
|
-
};
|
|
3596
|
-
const getAddParent = (node) => {
|
|
3597
|
-
const curNode = editorService.get("node");
|
|
3598
|
-
let parentNode;
|
|
3599
|
-
if (utils.isPage(node)) {
|
|
3600
|
-
parentNode = editorService.get("root");
|
|
3601
|
-
} else if (curNode?.items) {
|
|
3602
|
-
parentNode = curNode;
|
|
3603
|
-
} else if (curNode?.id) {
|
|
3604
|
-
parentNode = editorService.getParentById(curNode.id, false);
|
|
3605
|
-
}
|
|
3606
|
-
return parentNode;
|
|
3607
|
-
};
|
|
3608
|
-
const getDefaultConfig = async (addNode, parentNode) => {
|
|
3609
|
-
const { type, inputEvent, ...config } = addNode;
|
|
3610
|
-
const layout = await editorService.getLayout(vue.toRaw(parentNode), addNode);
|
|
3611
|
-
const newNode = { ...vue.toRaw(await propsService.getPropsValue(type, config)) };
|
|
3612
|
-
newNode.style = getInitPositionStyle(newNode.style, layout);
|
|
3613
|
-
return newNode;
|
|
3614
|
-
};
|
|
3615
|
-
|
|
3616
3570
|
let Editor$1 = class Editor extends BaseService {
|
|
3617
3571
|
state = vue.reactive({
|
|
3618
3572
|
root: null,
|
|
@@ -4328,169 +4282,76 @@
|
|
|
4328
4282
|
};
|
|
4329
4283
|
const editorService = new Editor$1();
|
|
4330
4284
|
|
|
4331
|
-
const
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
},
|
|
4343
|
-
columnWidth: {
|
|
4344
|
-
left: 0,
|
|
4345
|
-
right: 0,
|
|
4346
|
-
center: 0
|
|
4347
|
-
},
|
|
4348
|
-
showGuides: true,
|
|
4349
|
-
showRule: true,
|
|
4350
|
-
propsPanelSize: "small",
|
|
4351
|
-
showAddPageButton: true
|
|
4352
|
-
});
|
|
4353
|
-
class Ui extends BaseService {
|
|
4354
|
-
constructor() {
|
|
4355
|
-
super(["zoom", "calcZoom"]);
|
|
4356
|
-
}
|
|
4357
|
-
set(name, value) {
|
|
4358
|
-
const mask = editorService.get("stage")?.mask;
|
|
4359
|
-
if (name === "stageRect") {
|
|
4360
|
-
this.setStageRect(value);
|
|
4361
|
-
return;
|
|
4362
|
-
}
|
|
4363
|
-
if (name === "showGuides") {
|
|
4364
|
-
mask?.showGuides(value);
|
|
4365
|
-
}
|
|
4366
|
-
if (name === "showRule") {
|
|
4367
|
-
mask?.showRule(value);
|
|
4368
|
-
}
|
|
4369
|
-
state[name] = value;
|
|
4370
|
-
}
|
|
4371
|
-
get(name) {
|
|
4372
|
-
return state[name];
|
|
4373
|
-
}
|
|
4374
|
-
async zoom(zoom) {
|
|
4375
|
-
this.set("zoom", (this.get("zoom") * 100 + zoom * 100) / 100);
|
|
4376
|
-
if (this.get("zoom") < 0.1)
|
|
4377
|
-
this.set("zoom", 0.1);
|
|
4378
|
-
}
|
|
4379
|
-
async calcZoom() {
|
|
4380
|
-
const { stageRect, stageContainerRect } = state;
|
|
4381
|
-
const { height, width } = stageContainerRect;
|
|
4382
|
-
if (!width || !height)
|
|
4383
|
-
return 1;
|
|
4384
|
-
const stageWidth = stageRect.width + 30;
|
|
4385
|
-
const stageHeight = stageRect.height + 30;
|
|
4386
|
-
if (width > stageWidth && height > stageHeight) {
|
|
4387
|
-
return 1;
|
|
4388
|
-
}
|
|
4389
|
-
return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
|
|
4390
|
-
}
|
|
4391
|
-
resetState() {
|
|
4392
|
-
this.set("showSrc", false);
|
|
4393
|
-
this.set("uiSelectMode", false);
|
|
4394
|
-
this.set("zoom", 1);
|
|
4395
|
-
this.set("stageContainerRect", {
|
|
4396
|
-
width: 0,
|
|
4397
|
-
height: 0
|
|
4398
|
-
});
|
|
4399
|
-
}
|
|
4400
|
-
destroy() {
|
|
4401
|
-
this.resetState();
|
|
4402
|
-
this.removeAllListeners();
|
|
4403
|
-
this.removeAllPlugins();
|
|
4404
|
-
}
|
|
4405
|
-
async setStageRect(value) {
|
|
4406
|
-
state.stageRect = {
|
|
4407
|
-
...state.stageRect,
|
|
4408
|
-
...value
|
|
4409
|
-
};
|
|
4410
|
-
state.zoom = await this.calcZoom();
|
|
4411
|
-
}
|
|
4412
|
-
}
|
|
4413
|
-
const uiService = new Ui();
|
|
4414
|
-
|
|
4415
|
-
const root = vue.computed(() => editorService.get("root"));
|
|
4416
|
-
const page = vue.computed(() => editorService.get("page"));
|
|
4417
|
-
const zoom = vue.computed(() => uiService.get("zoom") || 1);
|
|
4418
|
-
const uiSelectMode = vue.computed(() => uiService.get("uiSelectMode"));
|
|
4419
|
-
const getGuideLineKey = (key) => `${key}_${root.value?.id}_${page.value?.id}`;
|
|
4420
|
-
const useStage = (stageOptions) => {
|
|
4421
|
-
const stage = new StageCore({
|
|
4422
|
-
render: stageOptions.render,
|
|
4423
|
-
runtimeUrl: stageOptions.runtimeUrl,
|
|
4424
|
-
zoom: zoom.value,
|
|
4425
|
-
autoScrollIntoView: stageOptions.autoScrollIntoView,
|
|
4426
|
-
isContainer: stageOptions.isContainer,
|
|
4427
|
-
containerHighlightClassName: stageOptions.containerHighlightClassName,
|
|
4428
|
-
containerHighlightDuration: stageOptions.containerHighlightDuration,
|
|
4429
|
-
containerHighlightType: stageOptions.containerHighlightType,
|
|
4430
|
-
disabledDragStart: stageOptions.disabledDragStart,
|
|
4431
|
-
canSelect: (el, event, stop) => {
|
|
4432
|
-
const elCanSelect = stageOptions.canSelect(el);
|
|
4433
|
-
if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
|
|
4434
|
-
document.dispatchEvent(new CustomEvent("ui-select", { detail: el }));
|
|
4435
|
-
return stop();
|
|
4285
|
+
const beforePaste = async (position, config) => {
|
|
4286
|
+
if (!config[0]?.style)
|
|
4287
|
+
return config;
|
|
4288
|
+
const curNode = editorService.get("node");
|
|
4289
|
+
const { left: referenceLeft, top: referenceTop } = config[0].style;
|
|
4290
|
+
const pasteConfigs = await Promise.all(
|
|
4291
|
+
config.map(async (configItem) => {
|
|
4292
|
+
const { offsetX = 0, offsetY = 0, ...positionClone } = position;
|
|
4293
|
+
let pastePosition = positionClone;
|
|
4294
|
+
if (!lodashEs.isEmpty(pastePosition) && curNode?.items) {
|
|
4295
|
+
pastePosition = getPositionInContainer(pastePosition, curNode.id);
|
|
4436
4296
|
}
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
moveableOptions: stageOptions.moveableOptions,
|
|
4440
|
-
updateDragEl: stageOptions.updateDragEl
|
|
4441
|
-
});
|
|
4442
|
-
stage.mask.setGuides([
|
|
4443
|
-
getGuideLineFromCache(getGuideLineKey(H_GUIDE_LINE_STORAGE_KEY)),
|
|
4444
|
-
getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY))
|
|
4445
|
-
]);
|
|
4446
|
-
stage.on("select", (el) => {
|
|
4447
|
-
if (`${editorService.get("node")?.id}` === el.id && editorService.get("nodes").length === 1)
|
|
4448
|
-
return;
|
|
4449
|
-
editorService.select(el.id);
|
|
4450
|
-
});
|
|
4451
|
-
stage.on("highlight", (el) => {
|
|
4452
|
-
editorService.highlight(el.id);
|
|
4453
|
-
});
|
|
4454
|
-
stage.on("multi-select", (els) => {
|
|
4455
|
-
editorService.multiSelect(els.map((el) => el.id));
|
|
4456
|
-
});
|
|
4457
|
-
stage.on("update", (ev) => {
|
|
4458
|
-
if (ev.parentEl) {
|
|
4459
|
-
for (const data of ev.data) {
|
|
4460
|
-
editorService.moveToContainer({ id: data.el.id, style: data.style }, ev.parentEl.id);
|
|
4297
|
+
if (pastePosition.left && configItem.style?.left) {
|
|
4298
|
+
pastePosition.left = configItem.style.left - referenceLeft + pastePosition.left;
|
|
4461
4299
|
}
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
return;
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4300
|
+
if (pastePosition.top && configItem.style?.top) {
|
|
4301
|
+
pastePosition.top = configItem.style?.top - referenceTop + pastePosition.top;
|
|
4302
|
+
}
|
|
4303
|
+
const pasteConfig = await propsService.setNewItemId(configItem);
|
|
4304
|
+
if (pasteConfig.style) {
|
|
4305
|
+
const { left, top } = pasteConfig.style;
|
|
4306
|
+
if (typeof left === "number" || !!left && !isNaN(Number(left))) {
|
|
4307
|
+
pasteConfig.style.left = Number(left) + offsetX;
|
|
4308
|
+
}
|
|
4309
|
+
if (typeof top === "number" || !!top && !isNaN(Number(top))) {
|
|
4310
|
+
pasteConfig.style.top = Number(top) + offsetY;
|
|
4311
|
+
}
|
|
4312
|
+
pasteConfig.style = {
|
|
4313
|
+
...pasteConfig.style,
|
|
4314
|
+
...pastePosition
|
|
4315
|
+
};
|
|
4316
|
+
}
|
|
4317
|
+
const root = editorService.get("root");
|
|
4318
|
+
if (utils.isPage(pasteConfig) && root) {
|
|
4319
|
+
pasteConfig.name = generatePageNameByApp(root);
|
|
4320
|
+
}
|
|
4321
|
+
return pasteConfig;
|
|
4322
|
+
})
|
|
4323
|
+
);
|
|
4324
|
+
return pasteConfigs;
|
|
4325
|
+
};
|
|
4326
|
+
const getPositionInContainer = (position = {}, id) => {
|
|
4327
|
+
let { left = 0, top = 0 } = position;
|
|
4328
|
+
const parentEl = editorService.get("stage")?.renderer?.contentWindow?.document.getElementById(`${id}`);
|
|
4329
|
+
const parentElRect = parentEl?.getBoundingClientRect();
|
|
4330
|
+
left = left - (parentElRect?.left || 0);
|
|
4331
|
+
top = top - (parentElRect?.top || 0);
|
|
4332
|
+
return {
|
|
4333
|
+
left,
|
|
4334
|
+
top
|
|
4335
|
+
};
|
|
4336
|
+
};
|
|
4337
|
+
const getAddParent = (node) => {
|
|
4338
|
+
const curNode = editorService.get("node");
|
|
4339
|
+
let parentNode;
|
|
4340
|
+
if (utils.isPage(node)) {
|
|
4341
|
+
parentNode = editorService.get("root");
|
|
4342
|
+
} else if (curNode?.items) {
|
|
4343
|
+
parentNode = curNode;
|
|
4344
|
+
} else if (curNode?.id) {
|
|
4345
|
+
parentNode = editorService.getParentById(curNode.id, false);
|
|
4346
|
+
}
|
|
4347
|
+
return parentNode;
|
|
4348
|
+
};
|
|
4349
|
+
const getDefaultConfig = async (addNode, parentNode) => {
|
|
4350
|
+
const { type, inputEvent, ...config } = addNode;
|
|
4351
|
+
const layout = await editorService.getLayout(vue.toRaw(parentNode), addNode);
|
|
4352
|
+
const newNode = { ...vue.toRaw(await propsService.getPropsValue(type, config)) };
|
|
4353
|
+
newNode.style = getInitPositionStyle(newNode.style, layout);
|
|
4354
|
+
return newNode;
|
|
4494
4355
|
};
|
|
4495
4356
|
|
|
4496
4357
|
const _hoisted_1$h = { class: "m-editor-empty-panel" };
|
|
@@ -7220,6 +7081,171 @@
|
|
|
7220
7081
|
}
|
|
7221
7082
|
});
|
|
7222
7083
|
|
|
7084
|
+
const state = vue.reactive({
|
|
7085
|
+
uiSelectMode: false,
|
|
7086
|
+
showSrc: false,
|
|
7087
|
+
zoom: 1,
|
|
7088
|
+
stageContainerRect: {
|
|
7089
|
+
width: 0,
|
|
7090
|
+
height: 0
|
|
7091
|
+
},
|
|
7092
|
+
stageRect: {
|
|
7093
|
+
width: 375,
|
|
7094
|
+
height: 817
|
|
7095
|
+
},
|
|
7096
|
+
columnWidth: {
|
|
7097
|
+
left: 0,
|
|
7098
|
+
right: 0,
|
|
7099
|
+
center: 0
|
|
7100
|
+
},
|
|
7101
|
+
showGuides: true,
|
|
7102
|
+
showRule: true,
|
|
7103
|
+
propsPanelSize: "small",
|
|
7104
|
+
showAddPageButton: true
|
|
7105
|
+
});
|
|
7106
|
+
class Ui extends BaseService {
|
|
7107
|
+
constructor() {
|
|
7108
|
+
super(["zoom", "calcZoom"]);
|
|
7109
|
+
}
|
|
7110
|
+
set(name, value) {
|
|
7111
|
+
const mask = editorService.get("stage")?.mask;
|
|
7112
|
+
if (name === "stageRect") {
|
|
7113
|
+
this.setStageRect(value);
|
|
7114
|
+
return;
|
|
7115
|
+
}
|
|
7116
|
+
if (name === "showGuides") {
|
|
7117
|
+
mask?.showGuides(value);
|
|
7118
|
+
}
|
|
7119
|
+
if (name === "showRule") {
|
|
7120
|
+
mask?.showRule(value);
|
|
7121
|
+
}
|
|
7122
|
+
state[name] = value;
|
|
7123
|
+
}
|
|
7124
|
+
get(name) {
|
|
7125
|
+
return state[name];
|
|
7126
|
+
}
|
|
7127
|
+
async zoom(zoom) {
|
|
7128
|
+
this.set("zoom", (this.get("zoom") * 100 + zoom * 100) / 100);
|
|
7129
|
+
if (this.get("zoom") < 0.1)
|
|
7130
|
+
this.set("zoom", 0.1);
|
|
7131
|
+
}
|
|
7132
|
+
async calcZoom() {
|
|
7133
|
+
const { stageRect, stageContainerRect } = state;
|
|
7134
|
+
const { height, width } = stageContainerRect;
|
|
7135
|
+
if (!width || !height)
|
|
7136
|
+
return 1;
|
|
7137
|
+
const stageWidth = stageRect.width + 30;
|
|
7138
|
+
const stageHeight = stageRect.height + 30;
|
|
7139
|
+
if (width > stageWidth && height > stageHeight) {
|
|
7140
|
+
return 1;
|
|
7141
|
+
}
|
|
7142
|
+
return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
|
|
7143
|
+
}
|
|
7144
|
+
resetState() {
|
|
7145
|
+
this.set("showSrc", false);
|
|
7146
|
+
this.set("uiSelectMode", false);
|
|
7147
|
+
this.set("zoom", 1);
|
|
7148
|
+
this.set("stageContainerRect", {
|
|
7149
|
+
width: 0,
|
|
7150
|
+
height: 0
|
|
7151
|
+
});
|
|
7152
|
+
}
|
|
7153
|
+
destroy() {
|
|
7154
|
+
this.resetState();
|
|
7155
|
+
this.removeAllListeners();
|
|
7156
|
+
this.removeAllPlugins();
|
|
7157
|
+
}
|
|
7158
|
+
async setStageRect(value) {
|
|
7159
|
+
state.stageRect = {
|
|
7160
|
+
...state.stageRect,
|
|
7161
|
+
...value
|
|
7162
|
+
};
|
|
7163
|
+
state.zoom = await this.calcZoom();
|
|
7164
|
+
}
|
|
7165
|
+
}
|
|
7166
|
+
const uiService = new Ui();
|
|
7167
|
+
|
|
7168
|
+
const root = vue.computed(() => editorService.get("root"));
|
|
7169
|
+
const page = vue.computed(() => editorService.get("page"));
|
|
7170
|
+
const zoom = vue.computed(() => uiService.get("zoom") || 1);
|
|
7171
|
+
const uiSelectMode = vue.computed(() => uiService.get("uiSelectMode"));
|
|
7172
|
+
const getGuideLineKey = (key) => `${key}_${root.value?.id}_${page.value?.id}`;
|
|
7173
|
+
const useStage = (stageOptions) => {
|
|
7174
|
+
const stage = new StageCore({
|
|
7175
|
+
render: stageOptions.render,
|
|
7176
|
+
runtimeUrl: stageOptions.runtimeUrl,
|
|
7177
|
+
zoom: zoom.value,
|
|
7178
|
+
autoScrollIntoView: stageOptions.autoScrollIntoView,
|
|
7179
|
+
isContainer: stageOptions.isContainer,
|
|
7180
|
+
containerHighlightClassName: stageOptions.containerHighlightClassName,
|
|
7181
|
+
containerHighlightDuration: stageOptions.containerHighlightDuration,
|
|
7182
|
+
containerHighlightType: stageOptions.containerHighlightType,
|
|
7183
|
+
disabledDragStart: stageOptions.disabledDragStart,
|
|
7184
|
+
canSelect: (el, event, stop) => {
|
|
7185
|
+
const elCanSelect = stageOptions.canSelect(el);
|
|
7186
|
+
if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
|
|
7187
|
+
document.dispatchEvent(new CustomEvent("ui-select", { detail: el }));
|
|
7188
|
+
return stop();
|
|
7189
|
+
}
|
|
7190
|
+
return elCanSelect;
|
|
7191
|
+
},
|
|
7192
|
+
moveableOptions: stageOptions.moveableOptions,
|
|
7193
|
+
updateDragEl: stageOptions.updateDragEl
|
|
7194
|
+
});
|
|
7195
|
+
stage.mask.setGuides([
|
|
7196
|
+
getGuideLineFromCache(getGuideLineKey(H_GUIDE_LINE_STORAGE_KEY)),
|
|
7197
|
+
getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY))
|
|
7198
|
+
]);
|
|
7199
|
+
stage.on("select", (el) => {
|
|
7200
|
+
if (`${editorService.get("node")?.id}` === el.id && editorService.get("nodes").length === 1)
|
|
7201
|
+
return;
|
|
7202
|
+
editorService.select(el.id);
|
|
7203
|
+
});
|
|
7204
|
+
stage.on("highlight", (el) => {
|
|
7205
|
+
editorService.highlight(el.id);
|
|
7206
|
+
});
|
|
7207
|
+
stage.on("multi-select", (els) => {
|
|
7208
|
+
editorService.multiSelect(els.map((el) => el.id));
|
|
7209
|
+
});
|
|
7210
|
+
stage.on("update", (ev) => {
|
|
7211
|
+
if (ev.parentEl) {
|
|
7212
|
+
for (const data of ev.data) {
|
|
7213
|
+
editorService.moveToContainer({ id: data.el.id, style: data.style }, ev.parentEl.id);
|
|
7214
|
+
}
|
|
7215
|
+
return;
|
|
7216
|
+
}
|
|
7217
|
+
editorService.update(ev.data.map((data) => ({ id: data.el.id, style: data.style })));
|
|
7218
|
+
});
|
|
7219
|
+
stage.on("sort", (ev) => {
|
|
7220
|
+
editorService.sort(ev.src, ev.dist);
|
|
7221
|
+
});
|
|
7222
|
+
stage.on("remove", (ev) => {
|
|
7223
|
+
const nodes = ev.data.map(({ el }) => editorService.getNodeById(el.id));
|
|
7224
|
+
editorService.remove(nodes.filter((node) => Boolean(node)));
|
|
7225
|
+
});
|
|
7226
|
+
stage.on("select-parent", () => {
|
|
7227
|
+
const parent = editorService.get("parent");
|
|
7228
|
+
if (!parent)
|
|
7229
|
+
throw new Error("父节点为空");
|
|
7230
|
+
editorService.select(parent);
|
|
7231
|
+
editorService.get("stage")?.select(parent.id);
|
|
7232
|
+
});
|
|
7233
|
+
stage.on("change-guides", (e) => {
|
|
7234
|
+
uiService.set("showGuides", true);
|
|
7235
|
+
if (!root.value || !page.value)
|
|
7236
|
+
return;
|
|
7237
|
+
const storageKey = getGuideLineKey(
|
|
7238
|
+
e.type === StageCore.GuidesType.HORIZONTAL ? H_GUIDE_LINE_STORAGE_KEY : V_GUIDE_LINE_STORAGE_KEY
|
|
7239
|
+
);
|
|
7240
|
+
if (e.guides.length) {
|
|
7241
|
+
globalThis.localStorage.setItem(storageKey, JSON.stringify(e.guides));
|
|
7242
|
+
} else {
|
|
7243
|
+
globalThis.localStorage.removeItem(storageKey);
|
|
7244
|
+
}
|
|
7245
|
+
});
|
|
7246
|
+
return stage;
|
|
7247
|
+
};
|
|
7248
|
+
|
|
7223
7249
|
const _hoisted_1$1 = {
|
|
7224
7250
|
viewBox: "0 0 24 24",
|
|
7225
7251
|
fill: "none",
|
|
@@ -9062,6 +9088,8 @@
|
|
|
9062
9088
|
exports.storageService = storageService;
|
|
9063
9089
|
exports.styleTabConfig = styleTabConfig;
|
|
9064
9090
|
exports.uiService = uiService;
|
|
9091
|
+
exports.useCodeBlockEdit = useCodeBlockEdit;
|
|
9092
|
+
exports.useDataSourceMethod = useDataSourceMethod;
|
|
9065
9093
|
exports.useStage = useStage;
|
|
9066
9094
|
exports.warn = warn;
|
|
9067
9095
|
|