@tmagic/editor 1.3.0-alpha.17 → 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
package/dist/style.css
CHANGED
|
@@ -742,6 +742,12 @@
|
|
|
742
742
|
.m-fields-code-select .el-card__header {
|
|
743
743
|
display: none;
|
|
744
744
|
}
|
|
745
|
+
.m-editor-code-block-editor .tmagic-design-table {
|
|
746
|
+
height: 180px;
|
|
747
|
+
}
|
|
748
|
+
.m-editor-code-block-editor .el-drawer__body {
|
|
749
|
+
padding: 10px 20px;
|
|
750
|
+
}
|
|
745
751
|
.m-fields-event-select {
|
|
746
752
|
width: 100%;
|
|
747
753
|
}
|
package/dist/tmagic-editor.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as monaco from 'monaco-editor';
|
|
|
5
5
|
import serialize from 'serialize-javascript';
|
|
6
6
|
import { TMagicButton, TMagicCard, tMagicMessage, TMagicIcon, tMagicMessageBox, getConfig as getConfig$1, TMagicTag, TMagicInput, TMagicTooltip, TMagicScrollbar, TMagicDivider, TMagicDropdown, TMagicDropdownMenu, TMagicDropdownItem, TMagicTree, TMagicCollapse, TMagicCollapseItem, TMagicPopover } from '@tmagic/design';
|
|
7
7
|
import { HookType, ActionType, NodeType } from '@tmagic/schema';
|
|
8
|
-
import { MFormDrawer, MForm, createValues,
|
|
8
|
+
import { MFormDrawer, MForm, createValues, MSelect } from '@tmagic/form';
|
|
9
9
|
import { MagicTable } from '@tmagic/table';
|
|
10
10
|
import Gesto from 'gesto';
|
|
11
11
|
import { guid, isPop, getNodePath, isNumber, isPage, toLine, removeClassNameByClassName, isObject as isObject$1, getNodes } from '@tmagic/utils';
|
|
@@ -393,13 +393,17 @@ const _sfc_main$H = /* @__PURE__ */ defineComponent({
|
|
|
393
393
|
__name: "CodeBlockEditor",
|
|
394
394
|
props: {
|
|
395
395
|
content: {},
|
|
396
|
-
disabled: { type: Boolean }
|
|
396
|
+
disabled: { type: Boolean },
|
|
397
|
+
isDataSource: { type: Boolean }
|
|
397
398
|
},
|
|
398
399
|
emits: ["submit"],
|
|
399
400
|
setup(__props, { expose: __expose, emit }) {
|
|
401
|
+
const props = __props;
|
|
400
402
|
const services = inject("services");
|
|
401
403
|
const columnWidth = computed(() => services?.uiService.get("columnWidth"));
|
|
402
|
-
const size = computed(
|
|
404
|
+
const size = computed(
|
|
405
|
+
() => columnWidth.value ? columnWidth.value.center + columnWidth.value.right - (props.isDataSource ? 100 : 0) : 600
|
|
406
|
+
);
|
|
403
407
|
const codeEditorHeight = ref("600px");
|
|
404
408
|
const defaultParamColConfig = {
|
|
405
409
|
type: "row",
|
|
@@ -436,16 +440,26 @@ const _sfc_main$H = /* @__PURE__ */ defineComponent({
|
|
|
436
440
|
name: "name"
|
|
437
441
|
},
|
|
438
442
|
{
|
|
439
|
-
text: "
|
|
443
|
+
text: "描述",
|
|
440
444
|
name: "desc"
|
|
441
445
|
},
|
|
446
|
+
{
|
|
447
|
+
text: "执行时机",
|
|
448
|
+
name: "timing",
|
|
449
|
+
type: "select",
|
|
450
|
+
options: [
|
|
451
|
+
{ text: "初始化前", value: "beforeInit" },
|
|
452
|
+
{ text: "初始化后", value: "afterInit" }
|
|
453
|
+
],
|
|
454
|
+
display: () => props.isDataSource
|
|
455
|
+
},
|
|
442
456
|
{
|
|
443
457
|
type: "table",
|
|
444
458
|
border: true,
|
|
445
459
|
text: "参数",
|
|
446
460
|
enableFullscreen: false,
|
|
461
|
+
enableToggleMode: false,
|
|
447
462
|
name: "params",
|
|
448
|
-
maxHeight: "300px",
|
|
449
463
|
dropSort: false,
|
|
450
464
|
items: [
|
|
451
465
|
{
|
|
@@ -455,7 +469,7 @@ const _sfc_main$H = /* @__PURE__ */ defineComponent({
|
|
|
455
469
|
},
|
|
456
470
|
{
|
|
457
471
|
type: "text",
|
|
458
|
-
label: "
|
|
472
|
+
label: "描述",
|
|
459
473
|
name: "extra"
|
|
460
474
|
},
|
|
461
475
|
services?.codeBlockService.getParamsColConfig() || defaultParamColConfig
|
|
@@ -487,7 +501,7 @@ const _sfc_main$H = /* @__PURE__ */ defineComponent({
|
|
|
487
501
|
const openHandler = () => {
|
|
488
502
|
setTimeout(() => {
|
|
489
503
|
if (fomDrawer.value) {
|
|
490
|
-
const height = fomDrawer.value?.bodyHeight -
|
|
504
|
+
const height = fomDrawer.value?.bodyHeight - 348 - (props.isDataSource ? 50 : 0);
|
|
491
505
|
codeEditorHeight.value = `${height > 100 ? height : 600}px`;
|
|
492
506
|
}
|
|
493
507
|
});
|
|
@@ -502,6 +516,7 @@ const _sfc_main$H = /* @__PURE__ */ defineComponent({
|
|
|
502
516
|
});
|
|
503
517
|
return (_ctx, _cache) => {
|
|
504
518
|
return openBlock(), createBlock(unref(MFormDrawer), {
|
|
519
|
+
class: "m-editor-code-block-editor",
|
|
505
520
|
ref_key: "fomDrawer",
|
|
506
521
|
ref: fomDrawer,
|
|
507
522
|
"label-width": "80px",
|
|
@@ -824,6 +839,10 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
|
|
|
824
839
|
label: "属性描述",
|
|
825
840
|
prop: "desc"
|
|
826
841
|
},
|
|
842
|
+
{
|
|
843
|
+
label: "默认值",
|
|
844
|
+
prop: "defaultValue"
|
|
845
|
+
},
|
|
827
846
|
{
|
|
828
847
|
label: "操作",
|
|
829
848
|
fixed: "right",
|
|
@@ -899,7 +918,8 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
|
|
|
899
918
|
},
|
|
900
919
|
{
|
|
901
920
|
name: "description",
|
|
902
|
-
text: "描述"
|
|
921
|
+
text: "描述",
|
|
922
|
+
type: "textarea"
|
|
903
923
|
},
|
|
904
924
|
{
|
|
905
925
|
name: "defaultValue",
|
|
@@ -938,9 +958,10 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
|
|
|
938
958
|
_: 1
|
|
939
959
|
}, 8, ["disabled"])
|
|
940
960
|
]),
|
|
941
|
-
createVNode(unref(
|
|
961
|
+
createVNode(unref(MFormDrawer), {
|
|
942
962
|
ref_key: "addDialog",
|
|
943
963
|
ref: addDialog,
|
|
964
|
+
"label-width": "80px",
|
|
944
965
|
title: filedTitle.value,
|
|
945
966
|
config: dataSourceFieldsConfig,
|
|
946
967
|
values: fieldValues.value,
|
|
@@ -1370,9 +1391,13 @@ const _sfc_main$A = /* @__PURE__ */ defineComponent({
|
|
|
1370
1391
|
prop: "name"
|
|
1371
1392
|
},
|
|
1372
1393
|
{
|
|
1373
|
-
label: "
|
|
1394
|
+
label: "描述",
|
|
1374
1395
|
prop: "desc"
|
|
1375
1396
|
},
|
|
1397
|
+
{
|
|
1398
|
+
label: "执行时机",
|
|
1399
|
+
prop: "timing"
|
|
1400
|
+
},
|
|
1376
1401
|
{
|
|
1377
1402
|
label: "参数",
|
|
1378
1403
|
prop: "params",
|
|
@@ -1434,6 +1459,7 @@ const _sfc_main$A = /* @__PURE__ */ defineComponent({
|
|
|
1434
1459
|
ref: codeBlockEditor,
|
|
1435
1460
|
disabled: _ctx.disabled,
|
|
1436
1461
|
content: unref(codeConfig),
|
|
1462
|
+
"is-data-source": true,
|
|
1437
1463
|
onSubmit: submitCodeHandler
|
|
1438
1464
|
}, null, 8, ["disabled", "content"])) : createCommentVNode("", true)
|
|
1439
1465
|
]);
|
|
@@ -3532,78 +3558,6 @@ class Props extends BaseService {
|
|
|
3532
3558
|
}
|
|
3533
3559
|
const propsService = new Props();
|
|
3534
3560
|
|
|
3535
|
-
const beforePaste = async (position, config) => {
|
|
3536
|
-
if (!config[0]?.style)
|
|
3537
|
-
return config;
|
|
3538
|
-
const curNode = editorService.get("node");
|
|
3539
|
-
const { left: referenceLeft, top: referenceTop } = config[0].style;
|
|
3540
|
-
const pasteConfigs = await Promise.all(
|
|
3541
|
-
config.map(async (configItem) => {
|
|
3542
|
-
const { offsetX = 0, offsetY = 0, ...positionClone } = position;
|
|
3543
|
-
let pastePosition = positionClone;
|
|
3544
|
-
if (!isEmpty(pastePosition) && curNode?.items) {
|
|
3545
|
-
pastePosition = getPositionInContainer(pastePosition, curNode.id);
|
|
3546
|
-
}
|
|
3547
|
-
if (pastePosition.left && configItem.style?.left) {
|
|
3548
|
-
pastePosition.left = configItem.style.left - referenceLeft + pastePosition.left;
|
|
3549
|
-
}
|
|
3550
|
-
if (pastePosition.top && configItem.style?.top) {
|
|
3551
|
-
pastePosition.top = configItem.style?.top - referenceTop + pastePosition.top;
|
|
3552
|
-
}
|
|
3553
|
-
const pasteConfig = await propsService.setNewItemId(configItem);
|
|
3554
|
-
if (pasteConfig.style) {
|
|
3555
|
-
const { left, top } = pasteConfig.style;
|
|
3556
|
-
if (typeof left === "number" || !!left && !isNaN(Number(left))) {
|
|
3557
|
-
pasteConfig.style.left = Number(left) + offsetX;
|
|
3558
|
-
}
|
|
3559
|
-
if (typeof top === "number" || !!top && !isNaN(Number(top))) {
|
|
3560
|
-
pasteConfig.style.top = Number(top) + offsetY;
|
|
3561
|
-
}
|
|
3562
|
-
pasteConfig.style = {
|
|
3563
|
-
...pasteConfig.style,
|
|
3564
|
-
...pastePosition
|
|
3565
|
-
};
|
|
3566
|
-
}
|
|
3567
|
-
const root = editorService.get("root");
|
|
3568
|
-
if (isPage(pasteConfig) && root) {
|
|
3569
|
-
pasteConfig.name = generatePageNameByApp(root);
|
|
3570
|
-
}
|
|
3571
|
-
return pasteConfig;
|
|
3572
|
-
})
|
|
3573
|
-
);
|
|
3574
|
-
return pasteConfigs;
|
|
3575
|
-
};
|
|
3576
|
-
const getPositionInContainer = (position = {}, id) => {
|
|
3577
|
-
let { left = 0, top = 0 } = position;
|
|
3578
|
-
const parentEl = editorService.get("stage")?.renderer?.contentWindow?.document.getElementById(`${id}`);
|
|
3579
|
-
const parentElRect = parentEl?.getBoundingClientRect();
|
|
3580
|
-
left = left - (parentElRect?.left || 0);
|
|
3581
|
-
top = top - (parentElRect?.top || 0);
|
|
3582
|
-
return {
|
|
3583
|
-
left,
|
|
3584
|
-
top
|
|
3585
|
-
};
|
|
3586
|
-
};
|
|
3587
|
-
const getAddParent = (node) => {
|
|
3588
|
-
const curNode = editorService.get("node");
|
|
3589
|
-
let parentNode;
|
|
3590
|
-
if (isPage(node)) {
|
|
3591
|
-
parentNode = editorService.get("root");
|
|
3592
|
-
} else if (curNode?.items) {
|
|
3593
|
-
parentNode = curNode;
|
|
3594
|
-
} else if (curNode?.id) {
|
|
3595
|
-
parentNode = editorService.getParentById(curNode.id, false);
|
|
3596
|
-
}
|
|
3597
|
-
return parentNode;
|
|
3598
|
-
};
|
|
3599
|
-
const getDefaultConfig = async (addNode, parentNode) => {
|
|
3600
|
-
const { type, inputEvent, ...config } = addNode;
|
|
3601
|
-
const layout = await editorService.getLayout(toRaw(parentNode), addNode);
|
|
3602
|
-
const newNode = { ...toRaw(await propsService.getPropsValue(type, config)) };
|
|
3603
|
-
newNode.style = getInitPositionStyle(newNode.style, layout);
|
|
3604
|
-
return newNode;
|
|
3605
|
-
};
|
|
3606
|
-
|
|
3607
3561
|
let Editor$1 = class Editor extends BaseService {
|
|
3608
3562
|
state = reactive({
|
|
3609
3563
|
root: null,
|
|
@@ -4319,169 +4273,76 @@ let Editor$1 = class Editor extends BaseService {
|
|
|
4319
4273
|
};
|
|
4320
4274
|
const editorService = new Editor$1();
|
|
4321
4275
|
|
|
4322
|
-
const
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
},
|
|
4334
|
-
columnWidth: {
|
|
4335
|
-
left: 0,
|
|
4336
|
-
right: 0,
|
|
4337
|
-
center: 0
|
|
4338
|
-
},
|
|
4339
|
-
showGuides: true,
|
|
4340
|
-
showRule: true,
|
|
4341
|
-
propsPanelSize: "small",
|
|
4342
|
-
showAddPageButton: true
|
|
4343
|
-
});
|
|
4344
|
-
class Ui extends BaseService {
|
|
4345
|
-
constructor() {
|
|
4346
|
-
super(["zoom", "calcZoom"]);
|
|
4347
|
-
}
|
|
4348
|
-
set(name, value) {
|
|
4349
|
-
const mask = editorService.get("stage")?.mask;
|
|
4350
|
-
if (name === "stageRect") {
|
|
4351
|
-
this.setStageRect(value);
|
|
4352
|
-
return;
|
|
4353
|
-
}
|
|
4354
|
-
if (name === "showGuides") {
|
|
4355
|
-
mask?.showGuides(value);
|
|
4356
|
-
}
|
|
4357
|
-
if (name === "showRule") {
|
|
4358
|
-
mask?.showRule(value);
|
|
4359
|
-
}
|
|
4360
|
-
state[name] = value;
|
|
4361
|
-
}
|
|
4362
|
-
get(name) {
|
|
4363
|
-
return state[name];
|
|
4364
|
-
}
|
|
4365
|
-
async zoom(zoom) {
|
|
4366
|
-
this.set("zoom", (this.get("zoom") * 100 + zoom * 100) / 100);
|
|
4367
|
-
if (this.get("zoom") < 0.1)
|
|
4368
|
-
this.set("zoom", 0.1);
|
|
4369
|
-
}
|
|
4370
|
-
async calcZoom() {
|
|
4371
|
-
const { stageRect, stageContainerRect } = state;
|
|
4372
|
-
const { height, width } = stageContainerRect;
|
|
4373
|
-
if (!width || !height)
|
|
4374
|
-
return 1;
|
|
4375
|
-
const stageWidth = stageRect.width + 30;
|
|
4376
|
-
const stageHeight = stageRect.height + 30;
|
|
4377
|
-
if (width > stageWidth && height > stageHeight) {
|
|
4378
|
-
return 1;
|
|
4379
|
-
}
|
|
4380
|
-
return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
|
|
4381
|
-
}
|
|
4382
|
-
resetState() {
|
|
4383
|
-
this.set("showSrc", false);
|
|
4384
|
-
this.set("uiSelectMode", false);
|
|
4385
|
-
this.set("zoom", 1);
|
|
4386
|
-
this.set("stageContainerRect", {
|
|
4387
|
-
width: 0,
|
|
4388
|
-
height: 0
|
|
4389
|
-
});
|
|
4390
|
-
}
|
|
4391
|
-
destroy() {
|
|
4392
|
-
this.resetState();
|
|
4393
|
-
this.removeAllListeners();
|
|
4394
|
-
this.removeAllPlugins();
|
|
4395
|
-
}
|
|
4396
|
-
async setStageRect(value) {
|
|
4397
|
-
state.stageRect = {
|
|
4398
|
-
...state.stageRect,
|
|
4399
|
-
...value
|
|
4400
|
-
};
|
|
4401
|
-
state.zoom = await this.calcZoom();
|
|
4402
|
-
}
|
|
4403
|
-
}
|
|
4404
|
-
const uiService = new Ui();
|
|
4405
|
-
|
|
4406
|
-
const root = computed(() => editorService.get("root"));
|
|
4407
|
-
const page = computed(() => editorService.get("page"));
|
|
4408
|
-
const zoom = computed(() => uiService.get("zoom") || 1);
|
|
4409
|
-
const uiSelectMode = computed(() => uiService.get("uiSelectMode"));
|
|
4410
|
-
const getGuideLineKey = (key) => `${key}_${root.value?.id}_${page.value?.id}`;
|
|
4411
|
-
const useStage = (stageOptions) => {
|
|
4412
|
-
const stage = new StageCore({
|
|
4413
|
-
render: stageOptions.render,
|
|
4414
|
-
runtimeUrl: stageOptions.runtimeUrl,
|
|
4415
|
-
zoom: zoom.value,
|
|
4416
|
-
autoScrollIntoView: stageOptions.autoScrollIntoView,
|
|
4417
|
-
isContainer: stageOptions.isContainer,
|
|
4418
|
-
containerHighlightClassName: stageOptions.containerHighlightClassName,
|
|
4419
|
-
containerHighlightDuration: stageOptions.containerHighlightDuration,
|
|
4420
|
-
containerHighlightType: stageOptions.containerHighlightType,
|
|
4421
|
-
disabledDragStart: stageOptions.disabledDragStart,
|
|
4422
|
-
canSelect: (el, event, stop) => {
|
|
4423
|
-
const elCanSelect = stageOptions.canSelect(el);
|
|
4424
|
-
if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
|
|
4425
|
-
document.dispatchEvent(new CustomEvent("ui-select", { detail: el }));
|
|
4426
|
-
return stop();
|
|
4276
|
+
const beforePaste = async (position, config) => {
|
|
4277
|
+
if (!config[0]?.style)
|
|
4278
|
+
return config;
|
|
4279
|
+
const curNode = editorService.get("node");
|
|
4280
|
+
const { left: referenceLeft, top: referenceTop } = config[0].style;
|
|
4281
|
+
const pasteConfigs = await Promise.all(
|
|
4282
|
+
config.map(async (configItem) => {
|
|
4283
|
+
const { offsetX = 0, offsetY = 0, ...positionClone } = position;
|
|
4284
|
+
let pastePosition = positionClone;
|
|
4285
|
+
if (!isEmpty(pastePosition) && curNode?.items) {
|
|
4286
|
+
pastePosition = getPositionInContainer(pastePosition, curNode.id);
|
|
4427
4287
|
}
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
moveableOptions: stageOptions.moveableOptions,
|
|
4431
|
-
updateDragEl: stageOptions.updateDragEl
|
|
4432
|
-
});
|
|
4433
|
-
stage.mask.setGuides([
|
|
4434
|
-
getGuideLineFromCache(getGuideLineKey(H_GUIDE_LINE_STORAGE_KEY)),
|
|
4435
|
-
getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY))
|
|
4436
|
-
]);
|
|
4437
|
-
stage.on("select", (el) => {
|
|
4438
|
-
if (`${editorService.get("node")?.id}` === el.id && editorService.get("nodes").length === 1)
|
|
4439
|
-
return;
|
|
4440
|
-
editorService.select(el.id);
|
|
4441
|
-
});
|
|
4442
|
-
stage.on("highlight", (el) => {
|
|
4443
|
-
editorService.highlight(el.id);
|
|
4444
|
-
});
|
|
4445
|
-
stage.on("multi-select", (els) => {
|
|
4446
|
-
editorService.multiSelect(els.map((el) => el.id));
|
|
4447
|
-
});
|
|
4448
|
-
stage.on("update", (ev) => {
|
|
4449
|
-
if (ev.parentEl) {
|
|
4450
|
-
for (const data of ev.data) {
|
|
4451
|
-
editorService.moveToContainer({ id: data.el.id, style: data.style }, ev.parentEl.id);
|
|
4288
|
+
if (pastePosition.left && configItem.style?.left) {
|
|
4289
|
+
pastePosition.left = configItem.style.left - referenceLeft + pastePosition.left;
|
|
4452
4290
|
}
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
return;
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4291
|
+
if (pastePosition.top && configItem.style?.top) {
|
|
4292
|
+
pastePosition.top = configItem.style?.top - referenceTop + pastePosition.top;
|
|
4293
|
+
}
|
|
4294
|
+
const pasteConfig = await propsService.setNewItemId(configItem);
|
|
4295
|
+
if (pasteConfig.style) {
|
|
4296
|
+
const { left, top } = pasteConfig.style;
|
|
4297
|
+
if (typeof left === "number" || !!left && !isNaN(Number(left))) {
|
|
4298
|
+
pasteConfig.style.left = Number(left) + offsetX;
|
|
4299
|
+
}
|
|
4300
|
+
if (typeof top === "number" || !!top && !isNaN(Number(top))) {
|
|
4301
|
+
pasteConfig.style.top = Number(top) + offsetY;
|
|
4302
|
+
}
|
|
4303
|
+
pasteConfig.style = {
|
|
4304
|
+
...pasteConfig.style,
|
|
4305
|
+
...pastePosition
|
|
4306
|
+
};
|
|
4307
|
+
}
|
|
4308
|
+
const root = editorService.get("root");
|
|
4309
|
+
if (isPage(pasteConfig) && root) {
|
|
4310
|
+
pasteConfig.name = generatePageNameByApp(root);
|
|
4311
|
+
}
|
|
4312
|
+
return pasteConfig;
|
|
4313
|
+
})
|
|
4314
|
+
);
|
|
4315
|
+
return pasteConfigs;
|
|
4316
|
+
};
|
|
4317
|
+
const getPositionInContainer = (position = {}, id) => {
|
|
4318
|
+
let { left = 0, top = 0 } = position;
|
|
4319
|
+
const parentEl = editorService.get("stage")?.renderer?.contentWindow?.document.getElementById(`${id}`);
|
|
4320
|
+
const parentElRect = parentEl?.getBoundingClientRect();
|
|
4321
|
+
left = left - (parentElRect?.left || 0);
|
|
4322
|
+
top = top - (parentElRect?.top || 0);
|
|
4323
|
+
return {
|
|
4324
|
+
left,
|
|
4325
|
+
top
|
|
4326
|
+
};
|
|
4327
|
+
};
|
|
4328
|
+
const getAddParent = (node) => {
|
|
4329
|
+
const curNode = editorService.get("node");
|
|
4330
|
+
let parentNode;
|
|
4331
|
+
if (isPage(node)) {
|
|
4332
|
+
parentNode = editorService.get("root");
|
|
4333
|
+
} else if (curNode?.items) {
|
|
4334
|
+
parentNode = curNode;
|
|
4335
|
+
} else if (curNode?.id) {
|
|
4336
|
+
parentNode = editorService.getParentById(curNode.id, false);
|
|
4337
|
+
}
|
|
4338
|
+
return parentNode;
|
|
4339
|
+
};
|
|
4340
|
+
const getDefaultConfig = async (addNode, parentNode) => {
|
|
4341
|
+
const { type, inputEvent, ...config } = addNode;
|
|
4342
|
+
const layout = await editorService.getLayout(toRaw(parentNode), addNode);
|
|
4343
|
+
const newNode = { ...toRaw(await propsService.getPropsValue(type, config)) };
|
|
4344
|
+
newNode.style = getInitPositionStyle(newNode.style, layout);
|
|
4345
|
+
return newNode;
|
|
4485
4346
|
};
|
|
4486
4347
|
|
|
4487
4348
|
const _hoisted_1$h = { class: "m-editor-empty-panel" };
|
|
@@ -7211,6 +7072,171 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
|
|
|
7211
7072
|
}
|
|
7212
7073
|
});
|
|
7213
7074
|
|
|
7075
|
+
const state = reactive({
|
|
7076
|
+
uiSelectMode: false,
|
|
7077
|
+
showSrc: false,
|
|
7078
|
+
zoom: 1,
|
|
7079
|
+
stageContainerRect: {
|
|
7080
|
+
width: 0,
|
|
7081
|
+
height: 0
|
|
7082
|
+
},
|
|
7083
|
+
stageRect: {
|
|
7084
|
+
width: 375,
|
|
7085
|
+
height: 817
|
|
7086
|
+
},
|
|
7087
|
+
columnWidth: {
|
|
7088
|
+
left: 0,
|
|
7089
|
+
right: 0,
|
|
7090
|
+
center: 0
|
|
7091
|
+
},
|
|
7092
|
+
showGuides: true,
|
|
7093
|
+
showRule: true,
|
|
7094
|
+
propsPanelSize: "small",
|
|
7095
|
+
showAddPageButton: true
|
|
7096
|
+
});
|
|
7097
|
+
class Ui extends BaseService {
|
|
7098
|
+
constructor() {
|
|
7099
|
+
super(["zoom", "calcZoom"]);
|
|
7100
|
+
}
|
|
7101
|
+
set(name, value) {
|
|
7102
|
+
const mask = editorService.get("stage")?.mask;
|
|
7103
|
+
if (name === "stageRect") {
|
|
7104
|
+
this.setStageRect(value);
|
|
7105
|
+
return;
|
|
7106
|
+
}
|
|
7107
|
+
if (name === "showGuides") {
|
|
7108
|
+
mask?.showGuides(value);
|
|
7109
|
+
}
|
|
7110
|
+
if (name === "showRule") {
|
|
7111
|
+
mask?.showRule(value);
|
|
7112
|
+
}
|
|
7113
|
+
state[name] = value;
|
|
7114
|
+
}
|
|
7115
|
+
get(name) {
|
|
7116
|
+
return state[name];
|
|
7117
|
+
}
|
|
7118
|
+
async zoom(zoom) {
|
|
7119
|
+
this.set("zoom", (this.get("zoom") * 100 + zoom * 100) / 100);
|
|
7120
|
+
if (this.get("zoom") < 0.1)
|
|
7121
|
+
this.set("zoom", 0.1);
|
|
7122
|
+
}
|
|
7123
|
+
async calcZoom() {
|
|
7124
|
+
const { stageRect, stageContainerRect } = state;
|
|
7125
|
+
const { height, width } = stageContainerRect;
|
|
7126
|
+
if (!width || !height)
|
|
7127
|
+
return 1;
|
|
7128
|
+
const stageWidth = stageRect.width + 30;
|
|
7129
|
+
const stageHeight = stageRect.height + 30;
|
|
7130
|
+
if (width > stageWidth && height > stageHeight) {
|
|
7131
|
+
return 1;
|
|
7132
|
+
}
|
|
7133
|
+
return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
|
|
7134
|
+
}
|
|
7135
|
+
resetState() {
|
|
7136
|
+
this.set("showSrc", false);
|
|
7137
|
+
this.set("uiSelectMode", false);
|
|
7138
|
+
this.set("zoom", 1);
|
|
7139
|
+
this.set("stageContainerRect", {
|
|
7140
|
+
width: 0,
|
|
7141
|
+
height: 0
|
|
7142
|
+
});
|
|
7143
|
+
}
|
|
7144
|
+
destroy() {
|
|
7145
|
+
this.resetState();
|
|
7146
|
+
this.removeAllListeners();
|
|
7147
|
+
this.removeAllPlugins();
|
|
7148
|
+
}
|
|
7149
|
+
async setStageRect(value) {
|
|
7150
|
+
state.stageRect = {
|
|
7151
|
+
...state.stageRect,
|
|
7152
|
+
...value
|
|
7153
|
+
};
|
|
7154
|
+
state.zoom = await this.calcZoom();
|
|
7155
|
+
}
|
|
7156
|
+
}
|
|
7157
|
+
const uiService = new Ui();
|
|
7158
|
+
|
|
7159
|
+
const root = computed(() => editorService.get("root"));
|
|
7160
|
+
const page = computed(() => editorService.get("page"));
|
|
7161
|
+
const zoom = computed(() => uiService.get("zoom") || 1);
|
|
7162
|
+
const uiSelectMode = computed(() => uiService.get("uiSelectMode"));
|
|
7163
|
+
const getGuideLineKey = (key) => `${key}_${root.value?.id}_${page.value?.id}`;
|
|
7164
|
+
const useStage = (stageOptions) => {
|
|
7165
|
+
const stage = new StageCore({
|
|
7166
|
+
render: stageOptions.render,
|
|
7167
|
+
runtimeUrl: stageOptions.runtimeUrl,
|
|
7168
|
+
zoom: zoom.value,
|
|
7169
|
+
autoScrollIntoView: stageOptions.autoScrollIntoView,
|
|
7170
|
+
isContainer: stageOptions.isContainer,
|
|
7171
|
+
containerHighlightClassName: stageOptions.containerHighlightClassName,
|
|
7172
|
+
containerHighlightDuration: stageOptions.containerHighlightDuration,
|
|
7173
|
+
containerHighlightType: stageOptions.containerHighlightType,
|
|
7174
|
+
disabledDragStart: stageOptions.disabledDragStart,
|
|
7175
|
+
canSelect: (el, event, stop) => {
|
|
7176
|
+
const elCanSelect = stageOptions.canSelect(el);
|
|
7177
|
+
if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
|
|
7178
|
+
document.dispatchEvent(new CustomEvent("ui-select", { detail: el }));
|
|
7179
|
+
return stop();
|
|
7180
|
+
}
|
|
7181
|
+
return elCanSelect;
|
|
7182
|
+
},
|
|
7183
|
+
moveableOptions: stageOptions.moveableOptions,
|
|
7184
|
+
updateDragEl: stageOptions.updateDragEl
|
|
7185
|
+
});
|
|
7186
|
+
stage.mask.setGuides([
|
|
7187
|
+
getGuideLineFromCache(getGuideLineKey(H_GUIDE_LINE_STORAGE_KEY)),
|
|
7188
|
+
getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY))
|
|
7189
|
+
]);
|
|
7190
|
+
stage.on("select", (el) => {
|
|
7191
|
+
if (`${editorService.get("node")?.id}` === el.id && editorService.get("nodes").length === 1)
|
|
7192
|
+
return;
|
|
7193
|
+
editorService.select(el.id);
|
|
7194
|
+
});
|
|
7195
|
+
stage.on("highlight", (el) => {
|
|
7196
|
+
editorService.highlight(el.id);
|
|
7197
|
+
});
|
|
7198
|
+
stage.on("multi-select", (els) => {
|
|
7199
|
+
editorService.multiSelect(els.map((el) => el.id));
|
|
7200
|
+
});
|
|
7201
|
+
stage.on("update", (ev) => {
|
|
7202
|
+
if (ev.parentEl) {
|
|
7203
|
+
for (const data of ev.data) {
|
|
7204
|
+
editorService.moveToContainer({ id: data.el.id, style: data.style }, ev.parentEl.id);
|
|
7205
|
+
}
|
|
7206
|
+
return;
|
|
7207
|
+
}
|
|
7208
|
+
editorService.update(ev.data.map((data) => ({ id: data.el.id, style: data.style })));
|
|
7209
|
+
});
|
|
7210
|
+
stage.on("sort", (ev) => {
|
|
7211
|
+
editorService.sort(ev.src, ev.dist);
|
|
7212
|
+
});
|
|
7213
|
+
stage.on("remove", (ev) => {
|
|
7214
|
+
const nodes = ev.data.map(({ el }) => editorService.getNodeById(el.id));
|
|
7215
|
+
editorService.remove(nodes.filter((node) => Boolean(node)));
|
|
7216
|
+
});
|
|
7217
|
+
stage.on("select-parent", () => {
|
|
7218
|
+
const parent = editorService.get("parent");
|
|
7219
|
+
if (!parent)
|
|
7220
|
+
throw new Error("父节点为空");
|
|
7221
|
+
editorService.select(parent);
|
|
7222
|
+
editorService.get("stage")?.select(parent.id);
|
|
7223
|
+
});
|
|
7224
|
+
stage.on("change-guides", (e) => {
|
|
7225
|
+
uiService.set("showGuides", true);
|
|
7226
|
+
if (!root.value || !page.value)
|
|
7227
|
+
return;
|
|
7228
|
+
const storageKey = getGuideLineKey(
|
|
7229
|
+
e.type === GuidesType.HORIZONTAL ? H_GUIDE_LINE_STORAGE_KEY : V_GUIDE_LINE_STORAGE_KEY
|
|
7230
|
+
);
|
|
7231
|
+
if (e.guides.length) {
|
|
7232
|
+
globalThis.localStorage.setItem(storageKey, JSON.stringify(e.guides));
|
|
7233
|
+
} else {
|
|
7234
|
+
globalThis.localStorage.removeItem(storageKey);
|
|
7235
|
+
}
|
|
7236
|
+
});
|
|
7237
|
+
return stage;
|
|
7238
|
+
};
|
|
7239
|
+
|
|
7214
7240
|
const _hoisted_1$1 = {
|
|
7215
7241
|
viewBox: "0 0 24 24",
|
|
7216
7242
|
fill: "none",
|
|
@@ -8978,5 +9004,5 @@ const index = {
|
|
|
8978
9004
|
}
|
|
8979
9005
|
};
|
|
8980
9006
|
|
|
8981
|
-
export { CODE_DRAFT_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$H as CodeBlockEditor, _sfc_main$k as CodeBlockList, _sfc_main$j as CodeBlockListPanel, CodeDeleteErrorType, _sfc_main$I as CodeSelect, _sfc_main$E as CodeSelectCol, ColumnLayout, _sfc_main$f as ComponentListPanel, _sfc_main$e as ContentMenu, _sfc_main$C as DataSourceFieldSelect, _sfc_main$D as DataSourceFields, _sfc_main$B as DataSourceInput, _sfc_main$z as DataSourceMethodSelect, _sfc_main$A as DataSourceMethods, _sfc_main$y as DataSourceSelect, DepTargetType, _sfc_main$x as EventSelect, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$F as Icon, KeyBindingCommand, _sfc_main$w as KeyValue, Keys, LayerOffset, _sfc_main$b as LayerPanel, Layout, _sfc_main$t as LayoutContainer, _sfc_main$o as PropsPanel, _sfc_main$u as Resizer, _sfc_main$t as SplitView, _sfc_main$L as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$q as ToolButton, V_GUIDE_LINE_STORAGE_KEY, advancedTabConfig, beforePaste, change2Fixed, codeBlockService, dataSourceService, debug, index as default, depService, displayTabConfig, editorService, error, eventTabConfig, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getAddParent, getConfig, getDefaultConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, historyService, info, isFixed, log, propsService, serializeConfig, setConfig, setLayout, storageService, styleTabConfig, uiService, useStage, warn };
|
|
9007
|
+
export { CODE_DRAFT_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$H as CodeBlockEditor, _sfc_main$k as CodeBlockList, _sfc_main$j as CodeBlockListPanel, CodeDeleteErrorType, _sfc_main$I as CodeSelect, _sfc_main$E as CodeSelectCol, ColumnLayout, _sfc_main$f as ComponentListPanel, _sfc_main$e as ContentMenu, _sfc_main$C as DataSourceFieldSelect, _sfc_main$D as DataSourceFields, _sfc_main$B as DataSourceInput, _sfc_main$z as DataSourceMethodSelect, _sfc_main$A as DataSourceMethods, _sfc_main$y as DataSourceSelect, DepTargetType, _sfc_main$x as EventSelect, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$F as Icon, KeyBindingCommand, _sfc_main$w as KeyValue, Keys, LayerOffset, _sfc_main$b as LayerPanel, Layout, _sfc_main$t as LayoutContainer, _sfc_main$o as PropsPanel, _sfc_main$u as Resizer, _sfc_main$t as SplitView, _sfc_main$L as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$q as ToolButton, V_GUIDE_LINE_STORAGE_KEY, advancedTabConfig, beforePaste, change2Fixed, codeBlockService, dataSourceService, debug, index as default, depService, displayTabConfig, editorService, error, eventTabConfig, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getAddParent, getConfig, getDefaultConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, historyService, info, isFixed, log, propsService, serializeConfig, setConfig, setLayout, storageService, styleTabConfig, uiService, useCodeBlockEdit, useDataSourceMethod, useStage, warn };
|
|
8982
9008
|
//# sourceMappingURL=tmagic-editor.js.map
|