@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.
@@ -1200,7 +1200,7 @@ class Editor$1 extends BaseService {
1200
1200
  if ((parent?.type === NodeType.ROOT || curNode.type === NodeType.ROOT) && node.type !== NodeType.PAGE) {
1201
1201
  throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
1202
1202
  }
1203
- if (parent.id !== curNode.id) {
1203
+ if (parent.id !== curNode.id && node.type !== NodeType.PAGE) {
1204
1204
  const index = parent.items.indexOf(curNode);
1205
1205
  parent?.items?.splice(index + 1, 0, node);
1206
1206
  } else {
@@ -1884,7 +1884,7 @@ const state = reactive({
1884
1884
  });
1885
1885
  class Ui extends BaseService {
1886
1886
  constructor() {
1887
- super([]);
1887
+ super(["initColumnWidth", "zoom", "calcZoom"]);
1888
1888
  globalThis.addEventListener("resize", () => {
1889
1889
  this.setColumnWidth({
1890
1890
  center: "auto"
@@ -1912,7 +1912,7 @@ class Ui extends BaseService {
1912
1912
  get(name) {
1913
1913
  return state[name];
1914
1914
  }
1915
- initColumnWidth() {
1915
+ async initColumnWidth() {
1916
1916
  const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
1917
1917
  if (columnWidthCacheData) {
1918
1918
  try {
@@ -1923,12 +1923,12 @@ class Ui extends BaseService {
1923
1923
  }
1924
1924
  }
1925
1925
  }
1926
- zoom(zoom) {
1926
+ async zoom(zoom) {
1927
1927
  this.set("zoom", (this.get("zoom") * 100 + zoom * 100) / 100);
1928
1928
  if (this.get("zoom") < 0.1)
1929
1929
  this.set("zoom", 0.1);
1930
1930
  }
1931
- calcZoom() {
1931
+ async calcZoom() {
1932
1932
  const { stageRect, stageContainerRect } = state;
1933
1933
  const { height, width } = stageContainerRect;
1934
1934
  if (!width || !height)
@@ -1967,12 +1967,12 @@ class Ui extends BaseService {
1967
1967
  globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth));
1968
1968
  state.columnWidth = columnWidth;
1969
1969
  }
1970
- setStageRect(value) {
1970
+ async setStageRect(value) {
1971
1971
  state.stageRect = {
1972
1972
  ...state.stageRect,
1973
1973
  ...value
1974
1974
  };
1975
- state.zoom = this.calcZoom();
1975
+ state.zoom = await this.calcZoom();
1976
1976
  }
1977
1977
  }
1978
1978
  const uiService = new Ui();
@@ -2529,7 +2529,7 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2529
2529
  className: "scale-to-fit",
2530
2530
  icon: markRaw(FullScreen),
2531
2531
  tooltip: `\u7F29\u653E\u4EE5\u9002\u5E94(${ctrl}+0)`,
2532
- handler: () => uiService?.set("zoom", uiService.calcZoom())
2532
+ handler: async () => uiService?.set("zoom", await uiService.calcZoom())
2533
2533
  });
2534
2534
  break;
2535
2535
  case "rule":
@@ -3421,25 +3421,29 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3421
3421
  const services = inject("services");
3422
3422
  const editorService = services?.editorService;
3423
3423
  const uiService = services?.uiService;
3424
- const pageBar = ref();
3425
3424
  const itemsContainer = ref();
3426
- const pageBarWidth = ref(0);
3427
3425
  const canScroll = ref(false);
3428
3426
  const showAddPageButton = computed(() => uiService?.get("showAddPageButton"));
3429
- const itemsContainerWidth = computed(() => pageBarWidth.value - 35 * 2 - (showAddPageButton.value ? 35 : 21));
3430
- let translateLeft = 0;
3431
- const resizeObserver = new ResizeObserver((entries) => {
3432
- for (const { contentRect } of entries) {
3433
- const { width } = contentRect;
3434
- pageBarWidth.value = width || 0;
3435
- setCanScroll();
3436
- }
3437
- });
3427
+ const itemsContainerWidth = ref(0);
3438
3428
  const setCanScroll = () => {
3439
- if (itemsContainer.value) {
3440
- canScroll.value = itemsContainer.value.scrollWidth > itemsContainerWidth.value;
3441
- }
3429
+ itemsContainerWidth.value = (pageBar.value?.clientWidth || 0) - 37 * 2 - (showAddPageButton.value ? 37 : 21);
3430
+ nextTick(() => {
3431
+ if (itemsContainer.value) {
3432
+ canScroll.value = itemsContainer.value.scrollWidth - itemsContainerWidth.value > 1;
3433
+ }
3434
+ });
3442
3435
  };
3436
+ const resizeObserver = new ResizeObserver(() => {
3437
+ setCanScroll();
3438
+ });
3439
+ const pageBar = ref();
3440
+ onMounted(() => {
3441
+ pageBar.value && resizeObserver.observe(pageBar.value);
3442
+ });
3443
+ onUnmounted(() => {
3444
+ resizeObserver.disconnect();
3445
+ });
3446
+ let translateLeft = 0;
3443
3447
  const scroll = (type) => {
3444
3448
  if (!itemsContainer.value)
3445
3449
  return;
@@ -3461,14 +3465,8 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3461
3465
  }
3462
3466
  itemsContainer.value.style.transform = `translate(${translateLeft}px, 0px)`;
3463
3467
  };
3464
- onMounted(() => {
3465
- pageBar.value && resizeObserver.observe(pageBar.value);
3466
- });
3467
- onUnmounted(() => {
3468
- resizeObserver.disconnect();
3469
- });
3470
- const root = computed(() => editorService?.get("root"));
3471
- watch(() => root.value?.items.length, (length = 0, preLength = 0) => {
3468
+ const pageLength = computed(() => editorService?.get("pageLength"));
3469
+ watch(pageLength, (length = 0, preLength = 0) => {
3472
3470
  setTimeout(() => {
3473
3471
  setCanScroll();
3474
3472
  if (length < preLength) {
@@ -3488,7 +3486,6 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3488
3486
  editorService.add(pageConfig);
3489
3487
  };
3490
3488
  return (_ctx, _cache) => {
3491
- const _component_el_icon = resolveComponent("el-icon");
3492
3489
  return openBlock(), createElementBlock("div", {
3493
3490
  class: "m-editor-page-bar",
3494
3491
  ref_key: "pageBar",
@@ -3500,31 +3497,21 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3500
3497
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3501
3498
  onClick: addPage
3502
3499
  }, [
3503
- createVNode(_component_el_icon, null, {
3504
- default: withCtx(() => [
3505
- createVNode(unref(Plus))
3506
- ]),
3507
- _: 1
3508
- })
3500
+ createVNode(_sfc_main$h, { icon: unref(Plus) }, null, 8, ["icon"])
3509
3501
  ])) : (openBlock(), createElementBlock("div", _hoisted_1$1)),
3510
3502
  canScroll.value ? (openBlock(), createElementBlock("div", {
3511
3503
  key: 2,
3512
3504
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3513
3505
  onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
3514
3506
  }, [
3515
- createVNode(_component_el_icon, null, {
3516
- default: withCtx(() => [
3517
- createVNode(unref(ArrowLeftBold))
3518
- ]),
3519
- _: 1
3520
- })
3507
+ createVNode(_sfc_main$h, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
3521
3508
  ])) : createCommentVNode("", true),
3522
- unref(root) ? (openBlock(), createElementBlock("div", {
3509
+ unref(pageLength) ? (openBlock(), createElementBlock("div", {
3523
3510
  key: 3,
3524
3511
  class: "m-editor-page-bar-items",
3525
3512
  ref_key: "itemsContainer",
3526
3513
  ref: itemsContainer,
3527
- style: normalizeStyle(`width: ${unref(itemsContainerWidth)}px`)
3514
+ style: normalizeStyle(`width: ${itemsContainerWidth.value}px`)
3528
3515
  }, [
3529
3516
  renderSlot(_ctx.$slots, "default")
3530
3517
  ], 4)) : createCommentVNode("", true),
@@ -3533,12 +3520,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3533
3520
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3534
3521
  onClick: _cache[1] || (_cache[1] = ($event) => scroll("right"))
3535
3522
  }, [
3536
- createVNode(_component_el_icon, null, {
3537
- default: withCtx(() => [
3538
- createVNode(unref(ArrowRightBold))
3539
- ]),
3540
- _: 1
3541
- })
3523
+ createVNode(_sfc_main$h, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
3542
3524
  ])) : createCommentVNode("", true)
3543
3525
  ], 512);
3544
3526
  };
@@ -3665,6 +3647,7 @@ class ScrollViewer extends EventEmitter {
3665
3647
  this.setSize();
3666
3648
  this.setScrollSize();
3667
3649
  this.resizeObserver.observe(this.container);
3650
+ this.resizeObserver.observe(this.target);
3668
3651
  }
3669
3652
  destroy() {
3670
3653
  this.resizeObserver.disconnect();
@@ -4317,9 +4300,9 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4317
4300
  }).keydown([ctrl, "numpad-"], (e) => {
4318
4301
  e.inputEvent.preventDefault();
4319
4302
  services?.uiService.zoom(-0.1);
4320
- }).keydown([ctrl, "0"], (e) => {
4303
+ }).keydown([ctrl, "0"], async (e) => {
4321
4304
  e.inputEvent.preventDefault();
4322
- services?.uiService.set("zoom", services.uiService.calcZoom());
4305
+ services?.uiService.set("zoom", await services.uiService.calcZoom());
4323
4306
  }).keydown([ctrl, "1"], (e) => {
4324
4307
  e.inputEvent.preventDefault();
4325
4308
  services?.uiService.set("zoom", 1);
@@ -4333,7 +4316,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4333
4316
  return (_ctx, _cache) => {
4334
4317
  return openBlock(), createElementBlock("div", {
4335
4318
  class: "m-editor-workspace",
4336
- tabindex: "1",
4319
+ tabindex: "-1",
4337
4320
  ref_key: "workspace",
4338
4321
  ref: workspace
4339
4322
  }, [