@tmagic/editor 1.2.0-beta.4 → 1.2.0-beta.6

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.
@@ -1783,10 +1783,10 @@
1783
1783
  newConfig = setLayout(newConfig, newLayout);
1784
1784
  }
1785
1785
  parentNodeItems[index] = newConfig;
1786
- const nodes = this.get("nodes");
1786
+ const nodes = this.get("nodes") || [];
1787
1787
  const targetIndex = nodes.findIndex((nodeItem) => `${nodeItem.id}` === `${newConfig.id}`);
1788
1788
  nodes.splice(targetIndex, 1, newConfig);
1789
- this.set("nodes", nodes);
1789
+ this.set("nodes", [...nodes]);
1790
1790
  this.get("stage")?.update({
1791
1791
  config: lodashEs.cloneDeep(newConfig),
1792
1792
  parentId: parent.id,
@@ -2408,6 +2408,8 @@
2408
2408
  getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY))
2409
2409
  ]);
2410
2410
  stage.on("select", (el) => {
2411
+ if (`${editorService.get("node")?.id}` === el.id)
2412
+ return;
2411
2413
  editorService.select(el.id);
2412
2414
  });
2413
2415
  stage.on("highlight", (el) => {
@@ -2550,8 +2552,11 @@
2550
2552
  const changeLeft = (deltaX) => {
2551
2553
  if (typeof props.left === "undefined")
2552
2554
  return;
2553
- const left = Math.max(props.left + deltaX, props.minLeft) || 0;
2555
+ let left = Math.max(props.left + deltaX, props.minLeft) || 0;
2554
2556
  emit("update:left", left);
2557
+ if (clientWidth - left - (props.right || 0) <= 0) {
2558
+ left = props.left;
2559
+ }
2555
2560
  center.value = clientWidth - left - (props.right || 0);
2556
2561
  emit("change", {
2557
2562
  left,
@@ -2562,8 +2567,11 @@
2562
2567
  const changeRight = (deltaX) => {
2563
2568
  if (typeof props.right === "undefined")
2564
2569
  return;
2565
- const right = Math.max(props.right - deltaX, props.minRight) || 0;
2570
+ let right = Math.max(props.right - deltaX, props.minRight) || 0;
2566
2571
  emit("update:right", right);
2572
+ if (clientWidth - (props.left || 0) - right <= 0) {
2573
+ right = props.right;
2574
+ }
2567
2575
  center.value = clientWidth - (props.left || 0) - right;
2568
2576
  emit("change", {
2569
2577
  left: props.left,
@@ -2617,43 +2625,60 @@
2617
2625
  const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
2618
2626
  const { editorService, uiService } = vue.inject("services") || {};
2619
2627
  const root = vue.computed(() => editorService?.get("root"));
2628
+ const nodes = vue.computed(() => editorService?.get("nodes") || []);
2620
2629
  const pageLength = vue.computed(() => editorService?.get("pageLength") || 0);
2621
2630
  const showSrc = vue.computed(() => uiService?.get("showSrc"));
2631
+ const LEFT_COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorLeftColumnWidthData";
2632
+ const RIGHT_COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorRightColumnWidthData";
2633
+ const leftColumnWidthCacheData = Number(globalThis.localStorage.getItem(LEFT_COLUMN_WIDTH_STORAGE_KEY));
2634
+ const RightColumnWidthCacheData = Number(globalThis.localStorage.getItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY));
2622
2635
  const columnWidth = vue.ref({
2623
- left: DEFAULT_LEFT_COLUMN_WIDTH,
2636
+ left: leftColumnWidthCacheData,
2624
2637
  center: 0,
2625
- right: 0
2638
+ right: RightColumnWidthCacheData
2626
2639
  });
2627
- uiService?.set("columnWidth", columnWidth.value);
2628
- vue.watchEffect(() => {
2629
- if (pageLength.value <= 0) {
2630
- columnWidth.value.right = void 0;
2631
- columnWidth.value.center = globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH;
2632
- } else {
2633
- columnWidth.value.right = columnWidth.value.right || DEFAULT_RIGHT_COLUMN_WIDTH;
2634
- columnWidth.value.center = globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH - DEFAULT_RIGHT_COLUMN_WIDTH;
2640
+ vue.watch(
2641
+ pageLength,
2642
+ (length) => {
2643
+ const left = columnWidth.value.left || DEFAULT_LEFT_COLUMN_WIDTH;
2644
+ columnWidth.value.left = left;
2645
+ if (length <= 0) {
2646
+ columnWidth.value.right = void 0;
2647
+ columnWidth.value.center = globalThis.document.body.clientWidth - left;
2648
+ } else {
2649
+ const right = columnWidth.value.right || RightColumnWidthCacheData || DEFAULT_RIGHT_COLUMN_WIDTH;
2650
+ columnWidth.value.right = right;
2651
+ columnWidth.value.center = globalThis.document.body.clientWidth - left - right;
2652
+ }
2653
+ uiService?.set("columnWidth", columnWidth);
2654
+ },
2655
+ {
2656
+ immediate: true
2635
2657
  }
2636
- });
2637
- const saveCode = (value) => {
2638
- try {
2639
- editorService?.set("root", eval(value));
2640
- } catch (e) {
2641
- console.error(e);
2658
+ );
2659
+ vue.watch(
2660
+ () => columnWidth.value.right,
2661
+ (right) => {
2662
+ if (typeof right === "undefined")
2663
+ return;
2664
+ globalThis.localStorage.setItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY, `${right}`);
2665
+ }
2666
+ );
2667
+ vue.watch(
2668
+ () => columnWidth.value.left,
2669
+ (left) => {
2670
+ globalThis.localStorage.setItem(LEFT_COLUMN_WIDTH_STORAGE_KEY, `${left}`);
2642
2671
  }
2672
+ );
2673
+ const columnWidthChange = (columnWidth2) => {
2674
+ uiService?.set("columnWidth", columnWidth2);
2643
2675
  };
2644
- const COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorColumnWidthData";
2645
- const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
2646
- if (columnWidthCacheData) {
2676
+ const saveCode = (value) => {
2647
2677
  try {
2648
- const columnWidthCache = JSON.parse(columnWidthCacheData);
2649
- columnWidth.value = columnWidthCache;
2678
+ editorService?.set("root", eval(value));
2650
2679
  } catch (e) {
2651
2680
  console.error(e);
2652
2681
  }
2653
- }
2654
- const columnWidthChange = (columnWidth2) => {
2655
- uiService?.set("columnWidth", columnWidth2);
2656
- globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth2));
2657
2682
  };
2658
2683
  return (_ctx, _cache) => {
2659
2684
  const _component_magic_code_editor = vue.resolveComponent("magic-code-editor");
@@ -2689,7 +2714,7 @@
2689
2714
  ]),
2690
2715
  _: 2
2691
2716
  }, [
2692
- vue.unref(pageLength) > 0 ? {
2717
+ vue.unref(pageLength) > 0 && vue.unref(nodes).length === 1 ? {
2693
2718
  name: "right",
2694
2719
  fn: vue.withCtx(() => [
2695
2720
  vue.createVNode(vue.unref(design.TMagicScrollbar), null, {
@@ -3659,14 +3684,14 @@
3659
3684
  }, {
3660
3685
  default: vue.withCtx(() => [
3661
3686
  vue.createVNode(vue.unref(design.TMagicInput), {
3662
- "prefix-icon": "el-icon-search",
3663
3687
  placeholder: "\u8F93\u5165\u5173\u952E\u5B57\u8FDB\u884C\u8FC7\u6EE4",
3664
3688
  class: "search-input",
3665
3689
  size: "small",
3666
3690
  clearable: "",
3691
+ "prefix-icon": vue.unref(iconsVue.Search),
3667
3692
  modelValue: searchText.value,
3668
3693
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => searchText.value = $event)
3669
- }, null, 8, ["modelValue"]),
3694
+ }, null, 8, ["prefix-icon", "modelValue"]),
3670
3695
  (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(list), (group, index) => {
3671
3696
  return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
3672
3697
  group.items && group.items.length ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicCollapseItem), {
@@ -4036,7 +4061,15 @@
4036
4061
  const filterTextChangeHandler = (val) => {
4037
4062
  tree.value?.filter(val);
4038
4063
  };
4039
- const expandNodes = () => {
4064
+ const expandNodes = async () => {
4065
+ if (!tree.value)
4066
+ return;
4067
+ await vue.nextTick();
4068
+ tree.value && Object.entries(tree.value.getStore().nodesMap).forEach(([id, node]) => {
4069
+ if (node.expanded && node.data.items) {
4070
+ expandedKeys.set(id, id);
4071
+ }
4072
+ });
4040
4073
  expandedKeys.forEach((key) => {
4041
4074
  if (!tree.value)
4042
4075
  return;
@@ -4046,26 +4079,7 @@
4046
4079
  vue.watch(
4047
4080
  () => editorService?.get("nodes"),
4048
4081
  (nodes) => {
4049
- if (!tree.value)
4050
- return;
4051
- if (!editorService)
4052
- return;
4053
- if (!nodes)
4054
- return;
4055
- selectedNodes.value = nodes;
4056
- const parent = editorService.get("parent");
4057
- if (!parent?.id)
4058
- return;
4059
- const treeNode = tree.value.getNode(parent.id);
4060
- treeNode?.updateChildren();
4061
- setTimeout(() => {
4062
- tree.value && Object.entries(tree.value.getStore().nodesMap).forEach(([id, node]) => {
4063
- if (node.expanded && node.data.items) {
4064
- expandedKeys.set(id, id);
4065
- }
4066
- });
4067
- expandNodes();
4068
- });
4082
+ selectedNodes.value = nodes ?? [];
4069
4083
  }
4070
4084
  );
4071
4085
  const setTreeKeyStatus = () => {
@@ -4082,7 +4096,15 @@
4082
4096
  tree.value.setCurrentKey();
4083
4097
  }
4084
4098
  };
4085
- vue.watch(selectedIds, () => {
4099
+ vue.watch([selectedIds, tree], async () => {
4100
+ if (!tree.value || !editorService)
4101
+ return;
4102
+ const parent = editorService.get("parent");
4103
+ if (!parent?.id)
4104
+ return;
4105
+ const treeNode = tree.value.getNode(parent.id);
4106
+ treeNode?.updateChildren();
4107
+ await expandNodes();
4086
4108
  setTreeKeyStatus();
4087
4109
  });
4088
4110
  const keycon = vue.ref();
@@ -4169,16 +4191,18 @@
4169
4191
  default: vue.withCtx(() => [
4170
4192
  vue.renderSlot(_ctx.$slots, "layer-panel-header"),
4171
4193
  vue.createVNode(vue.unref(design.TMagicInput), {
4172
- class: "filterInput",
4194
+ modelValue: filterText.value,
4195
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => filterText.value = $event),
4196
+ class: "search-input",
4173
4197
  size: "small",
4174
4198
  placeholder: "\u8F93\u5165\u5173\u952E\u5B57\u8FDB\u884C\u8FC7\u6EE4",
4175
4199
  clearable: "",
4176
- modelValue: filterText.value,
4177
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => filterText.value = $event),
4200
+ "prefix-icon": vue.unref(iconsVue.Search),
4178
4201
  onChange: filterTextChangeHandler
4179
- }, null, 8, ["modelValue"]),
4202
+ }, null, 8, ["modelValue", "prefix-icon"]),
4180
4203
  vue.unref(values).length ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicTree), {
4181
4204
  key: 0,
4205
+ class: "magic-editor-layer-tree",
4182
4206
  ref_key: "tree",
4183
4207
  ref: tree,
4184
4208
  "node-key": "id",