@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.
package/dist/style.css CHANGED
@@ -265,8 +265,11 @@
265
265
  left: 0;
266
266
  z-index: 1;
267
267
  }
268
- .magic-editor-layer-panel .search-input .el-input__suffix {
269
- padding: 10px 5px;
268
+ .magic-editor-layer-panel .search-input .el-input__prefix {
269
+ padding: 7px;
270
+ }
271
+ .magic-editor-layer-panel .magic-editor-layer-tree {
272
+ padding-top: 48px;
270
273
  }
271
274
  .magic-editor-layer-panel .node-content {
272
275
  flex: 1;
@@ -325,11 +328,11 @@
325
328
  .ui-component-panel {
326
329
  height: 100%;
327
330
  border-top: 0 !important;
328
- margin-top: 50px;
331
+ margin-top: 48px;
329
332
  background-color: #ffffff;
330
333
  }
331
334
  .ui-component-panel .search-input {
332
- background: #f8fbff;
335
+ background: #fff;
333
336
  color: #bbbbbb;
334
337
  padding: 10px;
335
338
  position: absolute;
@@ -339,10 +342,7 @@
339
342
  z-index: 1;
340
343
  }
341
344
  .ui-component-panel .search-input .el-input__prefix {
342
- padding: 10px;
343
- }
344
- .ui-component-panel .search-input .el-input__suffix {
345
- padding: 10px 5px;
345
+ padding: 7px;
346
346
  }
347
347
  .ui-component-panel .el-collapse-item > div:first-of-type {
348
348
  border-bottom: 1px solid #d9dbdd;
@@ -2,7 +2,7 @@ import { defineComponent, computed, resolveComponent, openBlock, createBlock, no
2
2
  import serialize from 'serialize-javascript';
3
3
  import { cloneDeep, map, xor, throttle, pick, isEmpty, forIn, omit, keys, mergeWith, uniq } from 'lodash-es';
4
4
  import { TMagicCard, TMagicTooltip, tMagicMessage, TMagicButton, TMagicIcon, TMagicScrollbar, TMagicDivider, TMagicDropdown, TMagicDropdownMenu, TMagicDropdownItem, TMagicDialog, TMagicInput, TMagicTree, TMagicCollapse, TMagicCollapseItem, TMagicTabPane, TMagicTabs, TMagicPopover } from '@tmagic/design';
5
- import { Delete, Close, Edit, Plus, ArrowDown, Grid, Memo, FullScreen, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, View, Link, Files, DocumentCopy, EditPen, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons-vue';
5
+ import { Delete, Close, Edit, Plus, ArrowDown, Grid, Memo, FullScreen, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, View, Link, Search, Files, DocumentCopy, EditPen, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons-vue';
6
6
  import * as monaco from 'monaco-editor';
7
7
  import StageCore, { GuidesType, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS, ContainerHighlightType } from '@tmagic/stage';
8
8
  import { NodeType } from '@tmagic/schema';
@@ -1765,10 +1765,10 @@ class Editor$1 extends BaseService {
1765
1765
  newConfig = setLayout(newConfig, newLayout);
1766
1766
  }
1767
1767
  parentNodeItems[index] = newConfig;
1768
- const nodes = this.get("nodes");
1768
+ const nodes = this.get("nodes") || [];
1769
1769
  const targetIndex = nodes.findIndex((nodeItem) => `${nodeItem.id}` === `${newConfig.id}`);
1770
1770
  nodes.splice(targetIndex, 1, newConfig);
1771
- this.set("nodes", nodes);
1771
+ this.set("nodes", [...nodes]);
1772
1772
  this.get("stage")?.update({
1773
1773
  config: cloneDeep(newConfig),
1774
1774
  parentId: parent.id,
@@ -2390,6 +2390,8 @@ const useStage = (stageOptions) => {
2390
2390
  getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY))
2391
2391
  ]);
2392
2392
  stage.on("select", (el) => {
2393
+ if (`${editorService.get("node")?.id}` === el.id)
2394
+ return;
2393
2395
  editorService.select(el.id);
2394
2396
  });
2395
2397
  stage.on("highlight", (el) => {
@@ -2532,8 +2534,11 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2532
2534
  const changeLeft = (deltaX) => {
2533
2535
  if (typeof props.left === "undefined")
2534
2536
  return;
2535
- const left = Math.max(props.left + deltaX, props.minLeft) || 0;
2537
+ let left = Math.max(props.left + deltaX, props.minLeft) || 0;
2536
2538
  emit("update:left", left);
2539
+ if (clientWidth - left - (props.right || 0) <= 0) {
2540
+ left = props.left;
2541
+ }
2537
2542
  center.value = clientWidth - left - (props.right || 0);
2538
2543
  emit("change", {
2539
2544
  left,
@@ -2544,8 +2549,11 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2544
2549
  const changeRight = (deltaX) => {
2545
2550
  if (typeof props.right === "undefined")
2546
2551
  return;
2547
- const right = Math.max(props.right - deltaX, props.minRight) || 0;
2552
+ let right = Math.max(props.right - deltaX, props.minRight) || 0;
2548
2553
  emit("update:right", right);
2554
+ if (clientWidth - (props.left || 0) - right <= 0) {
2555
+ right = props.right;
2556
+ }
2549
2557
  center.value = clientWidth - (props.left || 0) - right;
2550
2558
  emit("change", {
2551
2559
  left: props.left,
@@ -2599,43 +2607,60 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2599
2607
  const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
2600
2608
  const { editorService, uiService } = inject("services") || {};
2601
2609
  const root = computed(() => editorService?.get("root"));
2610
+ const nodes = computed(() => editorService?.get("nodes") || []);
2602
2611
  const pageLength = computed(() => editorService?.get("pageLength") || 0);
2603
2612
  const showSrc = computed(() => uiService?.get("showSrc"));
2613
+ const LEFT_COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorLeftColumnWidthData";
2614
+ const RIGHT_COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorRightColumnWidthData";
2615
+ const leftColumnWidthCacheData = Number(globalThis.localStorage.getItem(LEFT_COLUMN_WIDTH_STORAGE_KEY));
2616
+ const RightColumnWidthCacheData = Number(globalThis.localStorage.getItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY));
2604
2617
  const columnWidth = ref({
2605
- left: DEFAULT_LEFT_COLUMN_WIDTH,
2618
+ left: leftColumnWidthCacheData,
2606
2619
  center: 0,
2607
- right: 0
2620
+ right: RightColumnWidthCacheData
2608
2621
  });
2609
- uiService?.set("columnWidth", columnWidth.value);
2610
- watchEffect(() => {
2611
- if (pageLength.value <= 0) {
2612
- columnWidth.value.right = void 0;
2613
- columnWidth.value.center = globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH;
2614
- } else {
2615
- columnWidth.value.right = columnWidth.value.right || DEFAULT_RIGHT_COLUMN_WIDTH;
2616
- columnWidth.value.center = globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH - DEFAULT_RIGHT_COLUMN_WIDTH;
2622
+ watch(
2623
+ pageLength,
2624
+ (length) => {
2625
+ const left = columnWidth.value.left || DEFAULT_LEFT_COLUMN_WIDTH;
2626
+ columnWidth.value.left = left;
2627
+ if (length <= 0) {
2628
+ columnWidth.value.right = void 0;
2629
+ columnWidth.value.center = globalThis.document.body.clientWidth - left;
2630
+ } else {
2631
+ const right = columnWidth.value.right || RightColumnWidthCacheData || DEFAULT_RIGHT_COLUMN_WIDTH;
2632
+ columnWidth.value.right = right;
2633
+ columnWidth.value.center = globalThis.document.body.clientWidth - left - right;
2634
+ }
2635
+ uiService?.set("columnWidth", columnWidth);
2636
+ },
2637
+ {
2638
+ immediate: true
2617
2639
  }
2618
- });
2619
- const saveCode = (value) => {
2620
- try {
2621
- editorService?.set("root", eval(value));
2622
- } catch (e) {
2623
- console.error(e);
2640
+ );
2641
+ watch(
2642
+ () => columnWidth.value.right,
2643
+ (right) => {
2644
+ if (typeof right === "undefined")
2645
+ return;
2646
+ globalThis.localStorage.setItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY, `${right}`);
2647
+ }
2648
+ );
2649
+ watch(
2650
+ () => columnWidth.value.left,
2651
+ (left) => {
2652
+ globalThis.localStorage.setItem(LEFT_COLUMN_WIDTH_STORAGE_KEY, `${left}`);
2624
2653
  }
2654
+ );
2655
+ const columnWidthChange = (columnWidth2) => {
2656
+ uiService?.set("columnWidth", columnWidth2);
2625
2657
  };
2626
- const COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorColumnWidthData";
2627
- const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
2628
- if (columnWidthCacheData) {
2658
+ const saveCode = (value) => {
2629
2659
  try {
2630
- const columnWidthCache = JSON.parse(columnWidthCacheData);
2631
- columnWidth.value = columnWidthCache;
2660
+ editorService?.set("root", eval(value));
2632
2661
  } catch (e) {
2633
2662
  console.error(e);
2634
2663
  }
2635
- }
2636
- const columnWidthChange = (columnWidth2) => {
2637
- uiService?.set("columnWidth", columnWidth2);
2638
- globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth2));
2639
2664
  };
2640
2665
  return (_ctx, _cache) => {
2641
2666
  const _component_magic_code_editor = resolveComponent("magic-code-editor");
@@ -2671,7 +2696,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2671
2696
  ]),
2672
2697
  _: 2
2673
2698
  }, [
2674
- unref(pageLength) > 0 ? {
2699
+ unref(pageLength) > 0 && unref(nodes).length === 1 ? {
2675
2700
  name: "right",
2676
2701
  fn: withCtx(() => [
2677
2702
  createVNode(unref(TMagicScrollbar), null, {
@@ -3641,14 +3666,14 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
3641
3666
  }, {
3642
3667
  default: withCtx(() => [
3643
3668
  createVNode(unref(TMagicInput), {
3644
- "prefix-icon": "el-icon-search",
3645
3669
  placeholder: "\u8F93\u5165\u5173\u952E\u5B57\u8FDB\u884C\u8FC7\u6EE4",
3646
3670
  class: "search-input",
3647
3671
  size: "small",
3648
3672
  clearable: "",
3673
+ "prefix-icon": unref(Search),
3649
3674
  modelValue: searchText.value,
3650
3675
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => searchText.value = $event)
3651
- }, null, 8, ["modelValue"]),
3676
+ }, null, 8, ["prefix-icon", "modelValue"]),
3652
3677
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(list), (group, index) => {
3653
3678
  return openBlock(), createElementBlock(Fragment, null, [
3654
3679
  group.items && group.items.length ? (openBlock(), createBlock(unref(TMagicCollapseItem), {
@@ -4018,7 +4043,15 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
4018
4043
  const filterTextChangeHandler = (val) => {
4019
4044
  tree.value?.filter(val);
4020
4045
  };
4021
- const expandNodes = () => {
4046
+ const expandNodes = async () => {
4047
+ if (!tree.value)
4048
+ return;
4049
+ await nextTick();
4050
+ tree.value && Object.entries(tree.value.getStore().nodesMap).forEach(([id, node]) => {
4051
+ if (node.expanded && node.data.items) {
4052
+ expandedKeys.set(id, id);
4053
+ }
4054
+ });
4022
4055
  expandedKeys.forEach((key) => {
4023
4056
  if (!tree.value)
4024
4057
  return;
@@ -4028,26 +4061,7 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
4028
4061
  watch(
4029
4062
  () => editorService?.get("nodes"),
4030
4063
  (nodes) => {
4031
- if (!tree.value)
4032
- return;
4033
- if (!editorService)
4034
- return;
4035
- if (!nodes)
4036
- return;
4037
- selectedNodes.value = nodes;
4038
- const parent = editorService.get("parent");
4039
- if (!parent?.id)
4040
- return;
4041
- const treeNode = tree.value.getNode(parent.id);
4042
- treeNode?.updateChildren();
4043
- setTimeout(() => {
4044
- tree.value && Object.entries(tree.value.getStore().nodesMap).forEach(([id, node]) => {
4045
- if (node.expanded && node.data.items) {
4046
- expandedKeys.set(id, id);
4047
- }
4048
- });
4049
- expandNodes();
4050
- });
4064
+ selectedNodes.value = nodes ?? [];
4051
4065
  }
4052
4066
  );
4053
4067
  const setTreeKeyStatus = () => {
@@ -4064,7 +4078,15 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
4064
4078
  tree.value.setCurrentKey();
4065
4079
  }
4066
4080
  };
4067
- watch(selectedIds, () => {
4081
+ watch([selectedIds, tree], async () => {
4082
+ if (!tree.value || !editorService)
4083
+ return;
4084
+ const parent = editorService.get("parent");
4085
+ if (!parent?.id)
4086
+ return;
4087
+ const treeNode = tree.value.getNode(parent.id);
4088
+ treeNode?.updateChildren();
4089
+ await expandNodes();
4068
4090
  setTreeKeyStatus();
4069
4091
  });
4070
4092
  const keycon = ref();
@@ -4151,16 +4173,18 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
4151
4173
  default: withCtx(() => [
4152
4174
  renderSlot(_ctx.$slots, "layer-panel-header"),
4153
4175
  createVNode(unref(TMagicInput), {
4154
- class: "filterInput",
4176
+ modelValue: filterText.value,
4177
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => filterText.value = $event),
4178
+ class: "search-input",
4155
4179
  size: "small",
4156
4180
  placeholder: "\u8F93\u5165\u5173\u952E\u5B57\u8FDB\u884C\u8FC7\u6EE4",
4157
4181
  clearable: "",
4158
- modelValue: filterText.value,
4159
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => filterText.value = $event),
4182
+ "prefix-icon": unref(Search),
4160
4183
  onChange: filterTextChangeHandler
4161
- }, null, 8, ["modelValue"]),
4184
+ }, null, 8, ["modelValue", "prefix-icon"]),
4162
4185
  unref(values).length ? (openBlock(), createBlock(unref(TMagicTree), {
4163
4186
  key: 0,
4187
+ class: "magic-editor-layer-tree",
4164
4188
  ref_key: "tree",
4165
4189
  ref: tree,
4166
4190
  "node-key": "id",