@tmagic/editor 1.1.2 → 1.1.4
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/tmagic-editor.mjs +43 -57
- package/dist/tmagic-editor.mjs.map +1 -1
- package/dist/tmagic-editor.umd.js +43 -57
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/package.json +7 -7
- package/src/layouts/NavMenu.vue +1 -1
- package/src/layouts/sidebar/ComponentListPanel.vue +1 -1
- package/src/layouts/workspace/PageBarScrollContainer.vue +46 -43
- package/src/layouts/workspace/Workspace.vue +3 -3
- package/src/services/editor.ts +10 -4
- package/src/services/ui.ts +6 -6
- package/src/utils/scroll-viewer.ts +1 -0
- package/types/layouts/workspace/PageBarScrollContainer.vue.d.ts +2 -1
- package/types/services/ui.d.ts +3 -3
|
@@ -1218,7 +1218,7 @@
|
|
|
1218
1218
|
if ((parent?.type === schema.NodeType.ROOT || curNode.type === schema.NodeType.ROOT) && node.type !== schema.NodeType.PAGE) {
|
|
1219
1219
|
throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
|
|
1220
1220
|
}
|
|
1221
|
-
if (parent.id !== curNode.id) {
|
|
1221
|
+
if (parent.id !== curNode.id && node.type !== schema.NodeType.PAGE) {
|
|
1222
1222
|
const index = parent.items.indexOf(curNode);
|
|
1223
1223
|
parent?.items?.splice(index + 1, 0, node);
|
|
1224
1224
|
} else {
|
|
@@ -1435,12 +1435,15 @@
|
|
|
1435
1435
|
const node = this.get("node");
|
|
1436
1436
|
const brothers = parent?.items || [];
|
|
1437
1437
|
const index = brothers.findIndex((item) => `${item.id}` === `${node?.id}`);
|
|
1438
|
+
const layout = await this.getLayout(parent, node);
|
|
1439
|
+
const isRelative = layout === Layout.RELATIVE;
|
|
1440
|
+
brothers.splice(index, 1);
|
|
1438
1441
|
if (offset === LayerOffset.TOP) {
|
|
1439
|
-
brothers.splice(brothers.length - 1, 0,
|
|
1442
|
+
brothers.splice(isRelative ? 0 : brothers.length - 1, 0, node);
|
|
1440
1443
|
} else if (offset === LayerOffset.BOTTOM) {
|
|
1441
|
-
brothers.splice(
|
|
1444
|
+
brothers.splice(isRelative ? brothers.length - 1 : 0, 0, node);
|
|
1442
1445
|
} else {
|
|
1443
|
-
brothers.splice(index +
|
|
1446
|
+
brothers.splice(index + (isRelative ? -offset : offset), 0, node);
|
|
1444
1447
|
}
|
|
1445
1448
|
const grandparent = this.getParentById(parent.id);
|
|
1446
1449
|
this.get("stage")?.update({
|
|
@@ -1899,7 +1902,7 @@
|
|
|
1899
1902
|
});
|
|
1900
1903
|
class Ui extends BaseService {
|
|
1901
1904
|
constructor() {
|
|
1902
|
-
super([]);
|
|
1905
|
+
super(["initColumnWidth", "zoom", "calcZoom"]);
|
|
1903
1906
|
globalThis.addEventListener("resize", () => {
|
|
1904
1907
|
this.setColumnWidth({
|
|
1905
1908
|
center: "auto"
|
|
@@ -1927,7 +1930,7 @@
|
|
|
1927
1930
|
get(name) {
|
|
1928
1931
|
return state[name];
|
|
1929
1932
|
}
|
|
1930
|
-
initColumnWidth() {
|
|
1933
|
+
async initColumnWidth() {
|
|
1931
1934
|
const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
|
|
1932
1935
|
if (columnWidthCacheData) {
|
|
1933
1936
|
try {
|
|
@@ -1938,12 +1941,12 @@
|
|
|
1938
1941
|
}
|
|
1939
1942
|
}
|
|
1940
1943
|
}
|
|
1941
|
-
zoom(zoom) {
|
|
1944
|
+
async zoom(zoom) {
|
|
1942
1945
|
this.set("zoom", (this.get("zoom") * 100 + zoom * 100) / 100);
|
|
1943
1946
|
if (this.get("zoom") < 0.1)
|
|
1944
1947
|
this.set("zoom", 0.1);
|
|
1945
1948
|
}
|
|
1946
|
-
calcZoom() {
|
|
1949
|
+
async calcZoom() {
|
|
1947
1950
|
const { stageRect, stageContainerRect } = state;
|
|
1948
1951
|
const { height, width } = stageContainerRect;
|
|
1949
1952
|
if (!width || !height)
|
|
@@ -1982,12 +1985,12 @@
|
|
|
1982
1985
|
globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth));
|
|
1983
1986
|
state.columnWidth = columnWidth;
|
|
1984
1987
|
}
|
|
1985
|
-
setStageRect(value) {
|
|
1988
|
+
async setStageRect(value) {
|
|
1986
1989
|
state.stageRect = {
|
|
1987
1990
|
...state.stageRect,
|
|
1988
1991
|
...value
|
|
1989
1992
|
};
|
|
1990
|
-
state.zoom = this.calcZoom();
|
|
1993
|
+
state.zoom = await this.calcZoom();
|
|
1991
1994
|
}
|
|
1992
1995
|
}
|
|
1993
1996
|
const uiService = new Ui();
|
|
@@ -2544,7 +2547,7 @@
|
|
|
2544
2547
|
className: "scale-to-fit",
|
|
2545
2548
|
icon: vue.markRaw(iconsVue.FullScreen),
|
|
2546
2549
|
tooltip: `\u7F29\u653E\u4EE5\u9002\u5E94(${ctrl}+0)`,
|
|
2547
|
-
handler: () => uiService?.set("zoom", uiService.calcZoom())
|
|
2550
|
+
handler: async () => uiService?.set("zoom", await uiService.calcZoom())
|
|
2548
2551
|
});
|
|
2549
2552
|
break;
|
|
2550
2553
|
case "rule":
|
|
@@ -3436,25 +3439,29 @@
|
|
|
3436
3439
|
const services = vue.inject("services");
|
|
3437
3440
|
const editorService = services?.editorService;
|
|
3438
3441
|
const uiService = services?.uiService;
|
|
3439
|
-
const pageBar = vue.ref();
|
|
3440
3442
|
const itemsContainer = vue.ref();
|
|
3441
|
-
const pageBarWidth = vue.ref(0);
|
|
3442
3443
|
const canScroll = vue.ref(false);
|
|
3443
3444
|
const showAddPageButton = vue.computed(() => uiService?.get("showAddPageButton"));
|
|
3444
|
-
const itemsContainerWidth = vue.
|
|
3445
|
-
let translateLeft = 0;
|
|
3446
|
-
const resizeObserver = new ResizeObserver((entries) => {
|
|
3447
|
-
for (const { contentRect } of entries) {
|
|
3448
|
-
const { width } = contentRect;
|
|
3449
|
-
pageBarWidth.value = width || 0;
|
|
3450
|
-
setCanScroll();
|
|
3451
|
-
}
|
|
3452
|
-
});
|
|
3445
|
+
const itemsContainerWidth = vue.ref(0);
|
|
3453
3446
|
const setCanScroll = () => {
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3447
|
+
itemsContainerWidth.value = (pageBar.value?.clientWidth || 0) - 37 * 2 - (showAddPageButton.value ? 37 : 21);
|
|
3448
|
+
vue.nextTick(() => {
|
|
3449
|
+
if (itemsContainer.value) {
|
|
3450
|
+
canScroll.value = itemsContainer.value.scrollWidth - itemsContainerWidth.value > 1;
|
|
3451
|
+
}
|
|
3452
|
+
});
|
|
3457
3453
|
};
|
|
3454
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
3455
|
+
setCanScroll();
|
|
3456
|
+
});
|
|
3457
|
+
const pageBar = vue.ref();
|
|
3458
|
+
vue.onMounted(() => {
|
|
3459
|
+
pageBar.value && resizeObserver.observe(pageBar.value);
|
|
3460
|
+
});
|
|
3461
|
+
vue.onUnmounted(() => {
|
|
3462
|
+
resizeObserver.disconnect();
|
|
3463
|
+
});
|
|
3464
|
+
let translateLeft = 0;
|
|
3458
3465
|
const scroll = (type) => {
|
|
3459
3466
|
if (!itemsContainer.value)
|
|
3460
3467
|
return;
|
|
@@ -3476,14 +3483,8 @@
|
|
|
3476
3483
|
}
|
|
3477
3484
|
itemsContainer.value.style.transform = `translate(${translateLeft}px, 0px)`;
|
|
3478
3485
|
};
|
|
3479
|
-
vue.
|
|
3480
|
-
|
|
3481
|
-
});
|
|
3482
|
-
vue.onUnmounted(() => {
|
|
3483
|
-
resizeObserver.disconnect();
|
|
3484
|
-
});
|
|
3485
|
-
const root = vue.computed(() => editorService?.get("root"));
|
|
3486
|
-
vue.watch(() => root.value?.items.length, (length = 0, preLength = 0) => {
|
|
3486
|
+
const pageLength = vue.computed(() => editorService?.get("pageLength"));
|
|
3487
|
+
vue.watch(pageLength, (length = 0, preLength = 0) => {
|
|
3487
3488
|
setTimeout(() => {
|
|
3488
3489
|
setCanScroll();
|
|
3489
3490
|
if (length < preLength) {
|
|
@@ -3503,7 +3504,6 @@
|
|
|
3503
3504
|
editorService.add(pageConfig);
|
|
3504
3505
|
};
|
|
3505
3506
|
return (_ctx, _cache) => {
|
|
3506
|
-
const _component_el_icon = vue.resolveComponent("el-icon");
|
|
3507
3507
|
return vue.openBlock(), vue.createElementBlock("div", {
|
|
3508
3508
|
class: "m-editor-page-bar",
|
|
3509
3509
|
ref_key: "pageBar",
|
|
@@ -3515,31 +3515,21 @@
|
|
|
3515
3515
|
class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
|
|
3516
3516
|
onClick: addPage
|
|
3517
3517
|
}, [
|
|
3518
|
-
vue.createVNode(
|
|
3519
|
-
default: vue.withCtx(() => [
|
|
3520
|
-
vue.createVNode(vue.unref(iconsVue.Plus))
|
|
3521
|
-
]),
|
|
3522
|
-
_: 1
|
|
3523
|
-
})
|
|
3518
|
+
vue.createVNode(_sfc_main$h, { icon: vue.unref(iconsVue.Plus) }, null, 8, ["icon"])
|
|
3524
3519
|
])) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$1)),
|
|
3525
3520
|
canScroll.value ? (vue.openBlock(), vue.createElementBlock("div", {
|
|
3526
3521
|
key: 2,
|
|
3527
3522
|
class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
|
|
3528
3523
|
onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
|
|
3529
3524
|
}, [
|
|
3530
|
-
vue.createVNode(
|
|
3531
|
-
default: vue.withCtx(() => [
|
|
3532
|
-
vue.createVNode(vue.unref(iconsVue.ArrowLeftBold))
|
|
3533
|
-
]),
|
|
3534
|
-
_: 1
|
|
3535
|
-
})
|
|
3525
|
+
vue.createVNode(_sfc_main$h, { icon: vue.unref(iconsVue.ArrowLeftBold) }, null, 8, ["icon"])
|
|
3536
3526
|
])) : vue.createCommentVNode("", true),
|
|
3537
|
-
vue.unref(
|
|
3527
|
+
vue.unref(pageLength) ? (vue.openBlock(), vue.createElementBlock("div", {
|
|
3538
3528
|
key: 3,
|
|
3539
3529
|
class: "m-editor-page-bar-items",
|
|
3540
3530
|
ref_key: "itemsContainer",
|
|
3541
3531
|
ref: itemsContainer,
|
|
3542
|
-
style: vue.normalizeStyle(`width: ${
|
|
3532
|
+
style: vue.normalizeStyle(`width: ${itemsContainerWidth.value}px`)
|
|
3543
3533
|
}, [
|
|
3544
3534
|
vue.renderSlot(_ctx.$slots, "default")
|
|
3545
3535
|
], 4)) : vue.createCommentVNode("", true),
|
|
@@ -3548,12 +3538,7 @@
|
|
|
3548
3538
|
class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
|
|
3549
3539
|
onClick: _cache[1] || (_cache[1] = ($event) => scroll("right"))
|
|
3550
3540
|
}, [
|
|
3551
|
-
vue.createVNode(
|
|
3552
|
-
default: vue.withCtx(() => [
|
|
3553
|
-
vue.createVNode(vue.unref(iconsVue.ArrowRightBold))
|
|
3554
|
-
]),
|
|
3555
|
-
_: 1
|
|
3556
|
-
})
|
|
3541
|
+
vue.createVNode(_sfc_main$h, { icon: vue.unref(iconsVue.ArrowRightBold) }, null, 8, ["icon"])
|
|
3557
3542
|
])) : vue.createCommentVNode("", true)
|
|
3558
3543
|
], 512);
|
|
3559
3544
|
};
|
|
@@ -3680,6 +3665,7 @@
|
|
|
3680
3665
|
this.setSize();
|
|
3681
3666
|
this.setScrollSize();
|
|
3682
3667
|
this.resizeObserver.observe(this.container);
|
|
3668
|
+
this.resizeObserver.observe(this.target);
|
|
3683
3669
|
}
|
|
3684
3670
|
destroy() {
|
|
3685
3671
|
this.resizeObserver.disconnect();
|
|
@@ -4332,9 +4318,9 @@
|
|
|
4332
4318
|
}).keydown([ctrl, "numpad-"], (e) => {
|
|
4333
4319
|
e.inputEvent.preventDefault();
|
|
4334
4320
|
services?.uiService.zoom(-0.1);
|
|
4335
|
-
}).keydown([ctrl, "0"], (e) => {
|
|
4321
|
+
}).keydown([ctrl, "0"], async (e) => {
|
|
4336
4322
|
e.inputEvent.preventDefault();
|
|
4337
|
-
services?.uiService.set("zoom", services.uiService.calcZoom());
|
|
4323
|
+
services?.uiService.set("zoom", await services.uiService.calcZoom());
|
|
4338
4324
|
}).keydown([ctrl, "1"], (e) => {
|
|
4339
4325
|
e.inputEvent.preventDefault();
|
|
4340
4326
|
services?.uiService.set("zoom", 1);
|
|
@@ -4348,7 +4334,7 @@
|
|
|
4348
4334
|
return (_ctx, _cache) => {
|
|
4349
4335
|
return vue.openBlock(), vue.createElementBlock("div", {
|
|
4350
4336
|
class: "m-editor-workspace",
|
|
4351
|
-
tabindex: "1",
|
|
4337
|
+
tabindex: "-1",
|
|
4352
4338
|
ref_key: "workspace",
|
|
4353
4339
|
ref: workspace
|
|
4354
4340
|
}, [
|