@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.
@@ -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 {
@@ -1417,12 +1417,15 @@ class Editor$1 extends BaseService {
1417
1417
  const node = this.get("node");
1418
1418
  const brothers = parent?.items || [];
1419
1419
  const index = brothers.findIndex((item) => `${item.id}` === `${node?.id}`);
1420
+ const layout = await this.getLayout(parent, node);
1421
+ const isRelative = layout === Layout.RELATIVE;
1422
+ brothers.splice(index, 1);
1420
1423
  if (offset === LayerOffset.TOP) {
1421
- brothers.splice(brothers.length - 1, 0, brothers.splice(index, 1)[0]);
1424
+ brothers.splice(isRelative ? 0 : brothers.length - 1, 0, node);
1422
1425
  } else if (offset === LayerOffset.BOTTOM) {
1423
- brothers.splice(0, 0, brothers.splice(index, 1)[0]);
1426
+ brothers.splice(isRelative ? brothers.length - 1 : 0, 0, node);
1424
1427
  } else {
1425
- brothers.splice(index + parseInt(`${offset}`, 10), 0, brothers.splice(index, 1)[0]);
1428
+ brothers.splice(index + (isRelative ? -offset : offset), 0, node);
1426
1429
  }
1427
1430
  const grandparent = this.getParentById(parent.id);
1428
1431
  this.get("stage")?.update({
@@ -1881,7 +1884,7 @@ const state = reactive({
1881
1884
  });
1882
1885
  class Ui extends BaseService {
1883
1886
  constructor() {
1884
- super([]);
1887
+ super(["initColumnWidth", "zoom", "calcZoom"]);
1885
1888
  globalThis.addEventListener("resize", () => {
1886
1889
  this.setColumnWidth({
1887
1890
  center: "auto"
@@ -1909,7 +1912,7 @@ class Ui extends BaseService {
1909
1912
  get(name) {
1910
1913
  return state[name];
1911
1914
  }
1912
- initColumnWidth() {
1915
+ async initColumnWidth() {
1913
1916
  const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
1914
1917
  if (columnWidthCacheData) {
1915
1918
  try {
@@ -1920,12 +1923,12 @@ class Ui extends BaseService {
1920
1923
  }
1921
1924
  }
1922
1925
  }
1923
- zoom(zoom) {
1926
+ async zoom(zoom) {
1924
1927
  this.set("zoom", (this.get("zoom") * 100 + zoom * 100) / 100);
1925
1928
  if (this.get("zoom") < 0.1)
1926
1929
  this.set("zoom", 0.1);
1927
1930
  }
1928
- calcZoom() {
1931
+ async calcZoom() {
1929
1932
  const { stageRect, stageContainerRect } = state;
1930
1933
  const { height, width } = stageContainerRect;
1931
1934
  if (!width || !height)
@@ -1964,12 +1967,12 @@ class Ui extends BaseService {
1964
1967
  globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth));
1965
1968
  state.columnWidth = columnWidth;
1966
1969
  }
1967
- setStageRect(value) {
1970
+ async setStageRect(value) {
1968
1971
  state.stageRect = {
1969
1972
  ...state.stageRect,
1970
1973
  ...value
1971
1974
  };
1972
- state.zoom = this.calcZoom();
1975
+ state.zoom = await this.calcZoom();
1973
1976
  }
1974
1977
  }
1975
1978
  const uiService = new Ui();
@@ -2526,7 +2529,7 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2526
2529
  className: "scale-to-fit",
2527
2530
  icon: markRaw(FullScreen),
2528
2531
  tooltip: `\u7F29\u653E\u4EE5\u9002\u5E94(${ctrl}+0)`,
2529
- handler: () => uiService?.set("zoom", uiService.calcZoom())
2532
+ handler: async () => uiService?.set("zoom", await uiService.calcZoom())
2530
2533
  });
2531
2534
  break;
2532
2535
  case "rule":
@@ -3418,25 +3421,29 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3418
3421
  const services = inject("services");
3419
3422
  const editorService = services?.editorService;
3420
3423
  const uiService = services?.uiService;
3421
- const pageBar = ref();
3422
3424
  const itemsContainer = ref();
3423
- const pageBarWidth = ref(0);
3424
3425
  const canScroll = ref(false);
3425
3426
  const showAddPageButton = computed(() => uiService?.get("showAddPageButton"));
3426
- const itemsContainerWidth = computed(() => pageBarWidth.value - 35 * 2 - (showAddPageButton.value ? 35 : 21));
3427
- let translateLeft = 0;
3428
- const resizeObserver = new ResizeObserver((entries) => {
3429
- for (const { contentRect } of entries) {
3430
- const { width } = contentRect;
3431
- pageBarWidth.value = width || 0;
3432
- setCanScroll();
3433
- }
3434
- });
3427
+ const itemsContainerWidth = ref(0);
3435
3428
  const setCanScroll = () => {
3436
- if (itemsContainer.value) {
3437
- canScroll.value = itemsContainer.value.scrollWidth > itemsContainerWidth.value;
3438
- }
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
+ });
3439
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;
3440
3447
  const scroll = (type) => {
3441
3448
  if (!itemsContainer.value)
3442
3449
  return;
@@ -3458,14 +3465,8 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3458
3465
  }
3459
3466
  itemsContainer.value.style.transform = `translate(${translateLeft}px, 0px)`;
3460
3467
  };
3461
- onMounted(() => {
3462
- pageBar.value && resizeObserver.observe(pageBar.value);
3463
- });
3464
- onUnmounted(() => {
3465
- resizeObserver.disconnect();
3466
- });
3467
- const root = computed(() => editorService?.get("root"));
3468
- watch(() => root.value?.items.length, (length = 0, preLength = 0) => {
3468
+ const pageLength = computed(() => editorService?.get("pageLength"));
3469
+ watch(pageLength, (length = 0, preLength = 0) => {
3469
3470
  setTimeout(() => {
3470
3471
  setCanScroll();
3471
3472
  if (length < preLength) {
@@ -3485,7 +3486,6 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3485
3486
  editorService.add(pageConfig);
3486
3487
  };
3487
3488
  return (_ctx, _cache) => {
3488
- const _component_el_icon = resolveComponent("el-icon");
3489
3489
  return openBlock(), createElementBlock("div", {
3490
3490
  class: "m-editor-page-bar",
3491
3491
  ref_key: "pageBar",
@@ -3497,31 +3497,21 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3497
3497
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3498
3498
  onClick: addPage
3499
3499
  }, [
3500
- createVNode(_component_el_icon, null, {
3501
- default: withCtx(() => [
3502
- createVNode(unref(Plus))
3503
- ]),
3504
- _: 1
3505
- })
3500
+ createVNode(_sfc_main$h, { icon: unref(Plus) }, null, 8, ["icon"])
3506
3501
  ])) : (openBlock(), createElementBlock("div", _hoisted_1$1)),
3507
3502
  canScroll.value ? (openBlock(), createElementBlock("div", {
3508
3503
  key: 2,
3509
3504
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3510
3505
  onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
3511
3506
  }, [
3512
- createVNode(_component_el_icon, null, {
3513
- default: withCtx(() => [
3514
- createVNode(unref(ArrowLeftBold))
3515
- ]),
3516
- _: 1
3517
- })
3507
+ createVNode(_sfc_main$h, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
3518
3508
  ])) : createCommentVNode("", true),
3519
- unref(root) ? (openBlock(), createElementBlock("div", {
3509
+ unref(pageLength) ? (openBlock(), createElementBlock("div", {
3520
3510
  key: 3,
3521
3511
  class: "m-editor-page-bar-items",
3522
3512
  ref_key: "itemsContainer",
3523
3513
  ref: itemsContainer,
3524
- style: normalizeStyle(`width: ${unref(itemsContainerWidth)}px`)
3514
+ style: normalizeStyle(`width: ${itemsContainerWidth.value}px`)
3525
3515
  }, [
3526
3516
  renderSlot(_ctx.$slots, "default")
3527
3517
  ], 4)) : createCommentVNode("", true),
@@ -3530,12 +3520,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3530
3520
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
3531
3521
  onClick: _cache[1] || (_cache[1] = ($event) => scroll("right"))
3532
3522
  }, [
3533
- createVNode(_component_el_icon, null, {
3534
- default: withCtx(() => [
3535
- createVNode(unref(ArrowRightBold))
3536
- ]),
3537
- _: 1
3538
- })
3523
+ createVNode(_sfc_main$h, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
3539
3524
  ])) : createCommentVNode("", true)
3540
3525
  ], 512);
3541
3526
  };
@@ -3662,6 +3647,7 @@ class ScrollViewer extends EventEmitter {
3662
3647
  this.setSize();
3663
3648
  this.setScrollSize();
3664
3649
  this.resizeObserver.observe(this.container);
3650
+ this.resizeObserver.observe(this.target);
3665
3651
  }
3666
3652
  destroy() {
3667
3653
  this.resizeObserver.disconnect();
@@ -4314,9 +4300,9 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4314
4300
  }).keydown([ctrl, "numpad-"], (e) => {
4315
4301
  e.inputEvent.preventDefault();
4316
4302
  services?.uiService.zoom(-0.1);
4317
- }).keydown([ctrl, "0"], (e) => {
4303
+ }).keydown([ctrl, "0"], async (e) => {
4318
4304
  e.inputEvent.preventDefault();
4319
- services?.uiService.set("zoom", services.uiService.calcZoom());
4305
+ services?.uiService.set("zoom", await services.uiService.calcZoom());
4320
4306
  }).keydown([ctrl, "1"], (e) => {
4321
4307
  e.inputEvent.preventDefault();
4322
4308
  services?.uiService.set("zoom", 1);
@@ -4330,7 +4316,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4330
4316
  return (_ctx, _cache) => {
4331
4317
  return openBlock(), createElementBlock("div", {
4332
4318
  class: "m-editor-workspace",
4333
- tabindex: "1",
4319
+ tabindex: "-1",
4334
4320
  ref_key: "workspace",
4335
4321
  ref: workspace
4336
4322
  }, [