@tmagic/editor 1.1.3 → 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.
@@ -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 {
@@ -1902,7 +1902,7 @@
1902
1902
  });
1903
1903
  class Ui extends BaseService {
1904
1904
  constructor() {
1905
- super([]);
1905
+ super(["initColumnWidth", "zoom", "calcZoom"]);
1906
1906
  globalThis.addEventListener("resize", () => {
1907
1907
  this.setColumnWidth({
1908
1908
  center: "auto"
@@ -1930,7 +1930,7 @@
1930
1930
  get(name) {
1931
1931
  return state[name];
1932
1932
  }
1933
- initColumnWidth() {
1933
+ async initColumnWidth() {
1934
1934
  const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
1935
1935
  if (columnWidthCacheData) {
1936
1936
  try {
@@ -1941,12 +1941,12 @@
1941
1941
  }
1942
1942
  }
1943
1943
  }
1944
- zoom(zoom) {
1944
+ async zoom(zoom) {
1945
1945
  this.set("zoom", (this.get("zoom") * 100 + zoom * 100) / 100);
1946
1946
  if (this.get("zoom") < 0.1)
1947
1947
  this.set("zoom", 0.1);
1948
1948
  }
1949
- calcZoom() {
1949
+ async calcZoom() {
1950
1950
  const { stageRect, stageContainerRect } = state;
1951
1951
  const { height, width } = stageContainerRect;
1952
1952
  if (!width || !height)
@@ -1985,12 +1985,12 @@
1985
1985
  globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth));
1986
1986
  state.columnWidth = columnWidth;
1987
1987
  }
1988
- setStageRect(value) {
1988
+ async setStageRect(value) {
1989
1989
  state.stageRect = {
1990
1990
  ...state.stageRect,
1991
1991
  ...value
1992
1992
  };
1993
- state.zoom = this.calcZoom();
1993
+ state.zoom = await this.calcZoom();
1994
1994
  }
1995
1995
  }
1996
1996
  const uiService = new Ui();
@@ -2547,7 +2547,7 @@
2547
2547
  className: "scale-to-fit",
2548
2548
  icon: vue.markRaw(iconsVue.FullScreen),
2549
2549
  tooltip: `\u7F29\u653E\u4EE5\u9002\u5E94(${ctrl}+0)`,
2550
- handler: () => uiService?.set("zoom", uiService.calcZoom())
2550
+ handler: async () => uiService?.set("zoom", await uiService.calcZoom())
2551
2551
  });
2552
2552
  break;
2553
2553
  case "rule":
@@ -3439,25 +3439,29 @@
3439
3439
  const services = vue.inject("services");
3440
3440
  const editorService = services?.editorService;
3441
3441
  const uiService = services?.uiService;
3442
- const pageBar = vue.ref();
3443
3442
  const itemsContainer = vue.ref();
3444
- const pageBarWidth = vue.ref(0);
3445
3443
  const canScroll = vue.ref(false);
3446
3444
  const showAddPageButton = vue.computed(() => uiService?.get("showAddPageButton"));
3447
- const itemsContainerWidth = vue.computed(() => pageBarWidth.value - 35 * 2 - (showAddPageButton.value ? 35 : 21));
3448
- let translateLeft = 0;
3449
- const resizeObserver = new ResizeObserver((entries) => {
3450
- for (const { contentRect } of entries) {
3451
- const { width } = contentRect;
3452
- pageBarWidth.value = width || 0;
3453
- setCanScroll();
3454
- }
3455
- });
3445
+ const itemsContainerWidth = vue.ref(0);
3456
3446
  const setCanScroll = () => {
3457
- if (itemsContainer.value) {
3458
- canScroll.value = itemsContainer.value.scrollWidth > itemsContainerWidth.value;
3459
- }
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
+ });
3460
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;
3461
3465
  const scroll = (type) => {
3462
3466
  if (!itemsContainer.value)
3463
3467
  return;
@@ -3479,14 +3483,8 @@
3479
3483
  }
3480
3484
  itemsContainer.value.style.transform = `translate(${translateLeft}px, 0px)`;
3481
3485
  };
3482
- vue.onMounted(() => {
3483
- pageBar.value && resizeObserver.observe(pageBar.value);
3484
- });
3485
- vue.onUnmounted(() => {
3486
- resizeObserver.disconnect();
3487
- });
3488
- const root = vue.computed(() => editorService?.get("root"));
3489
- 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) => {
3490
3488
  setTimeout(() => {
3491
3489
  setCanScroll();
3492
3490
  if (length < preLength) {
@@ -3506,7 +3504,6 @@
3506
3504
  editorService.add(pageConfig);
3507
3505
  };
3508
3506
  return (_ctx, _cache) => {
3509
- const _component_el_icon = vue.resolveComponent("el-icon");
3510
3507
  return vue.openBlock(), vue.createElementBlock("div", {
3511
3508
  class: "m-editor-page-bar",
3512
3509
  ref_key: "pageBar",
@@ -3518,31 +3515,21 @@
3518
3515
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3519
3516
  onClick: addPage
3520
3517
  }, [
3521
- vue.createVNode(_component_el_icon, null, {
3522
- default: vue.withCtx(() => [
3523
- vue.createVNode(vue.unref(iconsVue.Plus))
3524
- ]),
3525
- _: 1
3526
- })
3518
+ vue.createVNode(_sfc_main$h, { icon: vue.unref(iconsVue.Plus) }, null, 8, ["icon"])
3527
3519
  ])) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$1)),
3528
3520
  canScroll.value ? (vue.openBlock(), vue.createElementBlock("div", {
3529
3521
  key: 2,
3530
3522
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3531
3523
  onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
3532
3524
  }, [
3533
- vue.createVNode(_component_el_icon, null, {
3534
- default: vue.withCtx(() => [
3535
- vue.createVNode(vue.unref(iconsVue.ArrowLeftBold))
3536
- ]),
3537
- _: 1
3538
- })
3525
+ vue.createVNode(_sfc_main$h, { icon: vue.unref(iconsVue.ArrowLeftBold) }, null, 8, ["icon"])
3539
3526
  ])) : vue.createCommentVNode("", true),
3540
- vue.unref(root) ? (vue.openBlock(), vue.createElementBlock("div", {
3527
+ vue.unref(pageLength) ? (vue.openBlock(), vue.createElementBlock("div", {
3541
3528
  key: 3,
3542
3529
  class: "m-editor-page-bar-items",
3543
3530
  ref_key: "itemsContainer",
3544
3531
  ref: itemsContainer,
3545
- style: vue.normalizeStyle(`width: ${vue.unref(itemsContainerWidth)}px`)
3532
+ style: vue.normalizeStyle(`width: ${itemsContainerWidth.value}px`)
3546
3533
  }, [
3547
3534
  vue.renderSlot(_ctx.$slots, "default")
3548
3535
  ], 4)) : vue.createCommentVNode("", true),
@@ -3551,12 +3538,7 @@
3551
3538
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3552
3539
  onClick: _cache[1] || (_cache[1] = ($event) => scroll("right"))
3553
3540
  }, [
3554
- vue.createVNode(_component_el_icon, null, {
3555
- default: vue.withCtx(() => [
3556
- vue.createVNode(vue.unref(iconsVue.ArrowRightBold))
3557
- ]),
3558
- _: 1
3559
- })
3541
+ vue.createVNode(_sfc_main$h, { icon: vue.unref(iconsVue.ArrowRightBold) }, null, 8, ["icon"])
3560
3542
  ])) : vue.createCommentVNode("", true)
3561
3543
  ], 512);
3562
3544
  };
@@ -3683,6 +3665,7 @@
3683
3665
  this.setSize();
3684
3666
  this.setScrollSize();
3685
3667
  this.resizeObserver.observe(this.container);
3668
+ this.resizeObserver.observe(this.target);
3686
3669
  }
3687
3670
  destroy() {
3688
3671
  this.resizeObserver.disconnect();
@@ -4335,9 +4318,9 @@
4335
4318
  }).keydown([ctrl, "numpad-"], (e) => {
4336
4319
  e.inputEvent.preventDefault();
4337
4320
  services?.uiService.zoom(-0.1);
4338
- }).keydown([ctrl, "0"], (e) => {
4321
+ }).keydown([ctrl, "0"], async (e) => {
4339
4322
  e.inputEvent.preventDefault();
4340
- services?.uiService.set("zoom", services.uiService.calcZoom());
4323
+ services?.uiService.set("zoom", await services.uiService.calcZoom());
4341
4324
  }).keydown([ctrl, "1"], (e) => {
4342
4325
  e.inputEvent.preventDefault();
4343
4326
  services?.uiService.set("zoom", 1);
@@ -4351,7 +4334,7 @@
4351
4334
  return (_ctx, _cache) => {
4352
4335
  return vue.openBlock(), vue.createElementBlock("div", {
4353
4336
  class: "m-editor-workspace",
4354
- tabindex: "1",
4337
+ tabindex: "-1",
4355
4338
  ref_key: "workspace",
4356
4339
  ref: workspace
4357
4340
  }, [