@tmagic/editor 1.0.0-rc.12 → 1.0.0-rc.13

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.
@@ -10,7 +10,7 @@ import { DEFAULT_EVENTS, DEFAULT_METHODS } from '@tmagic/core';
10
10
  import Gesto from 'gesto';
11
11
  import { ElMessage } from 'element-plus';
12
12
  import KeyController from 'keycon';
13
- import StageCore from '@tmagic/stage';
13
+ import StageCore, { GuidesType } from '@tmagic/stage';
14
14
 
15
15
  if (typeof global === "undefined") {
16
16
  window.global = window;
@@ -722,6 +722,8 @@ var Keys = /* @__PURE__ */ ((Keys2) => {
722
722
  Keys2["ESCAPE"] = "Space";
723
723
  return Keys2;
724
724
  })(Keys || {});
725
+ const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
726
+ const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
725
727
 
726
728
  const COPY_STORAGE_KEY = "$MagicEditorCopyData";
727
729
  const getPageList = (app) => {
@@ -848,6 +850,19 @@ const Fixed2Other = async (node, root, getLayout) => {
848
850
  }
849
851
  return toRelative(node);
850
852
  };
853
+ const getGuideLineFromCache = (key) => {
854
+ if (!key)
855
+ return [];
856
+ const guideLineCacheData = globalThis.localStorage.getItem(key);
857
+ if (guideLineCacheData) {
858
+ try {
859
+ return JSON.parse(guideLineCacheData) || [];
860
+ } catch (e) {
861
+ console.error(e);
862
+ }
863
+ }
864
+ return [];
865
+ };
851
866
 
852
867
  const log = (...args) => {
853
868
  };
@@ -3412,6 +3427,7 @@ const _sfc_main$2 = defineComponent({
3412
3427
  const node = computed(() => services?.editorService.get("node"));
3413
3428
  let stage = null;
3414
3429
  let runtime = null;
3430
+ const getGuideLineKey = (key) => `${key}_${root.value?.id}_${page.value?.id}`;
3415
3431
  watchEffect(() => {
3416
3432
  if (stage)
3417
3433
  return;
@@ -3437,6 +3453,10 @@ const _sfc_main$2 = defineComponent({
3437
3453
  });
3438
3454
  services?.editorService.set("stage", markRaw(stage));
3439
3455
  stage?.mount(stageContainer.value);
3456
+ stage.mask.setGuides([
3457
+ getGuideLineFromCache(getGuideLineKey(H_GUIDE_LINE_STORAGE_KEY)),
3458
+ getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY))
3459
+ ]);
3440
3460
  stage?.on("select", (el) => {
3441
3461
  services?.editorService.select(el.id);
3442
3462
  });
@@ -3449,8 +3469,16 @@ const _sfc_main$2 = defineComponent({
3449
3469
  stage?.on("sort", (ev) => {
3450
3470
  services?.editorService.sort(ev.src, ev.dist);
3451
3471
  });
3452
- stage?.on("changeGuides", () => {
3472
+ stage?.on("changeGuides", (e2) => {
3453
3473
  services?.uiService.set("showGuides", true);
3474
+ if (!root.value || !page.value)
3475
+ return;
3476
+ const storageKey = getGuideLineKey(e2.type === GuidesType.HORIZONTAL ? H_GUIDE_LINE_STORAGE_KEY : V_GUIDE_LINE_STORAGE_KEY);
3477
+ if (e2.guides.length) {
3478
+ globalThis.localStorage.setItem(storageKey, JSON.stringify(e2.guides));
3479
+ } else {
3480
+ globalThis.localStorage.removeItem(storageKey);
3481
+ }
3454
3482
  });
3455
3483
  if (!node.value?.id)
3456
3484
  return;
@@ -3703,7 +3731,9 @@ class ComponentList extends BaseService {
3703
3731
  var componentListService = new ComponentList();
3704
3732
 
3705
3733
  const DEFAULT_LEFT_COLUMN_WIDTH = 310;
3734
+ const MIN_LEFT_COLUMN_WIDTH = 45;
3706
3735
  const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
3736
+ const MIN_RIGHT_COLUMN_WIDTH = 1;
3707
3737
  const COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorColumnWidthData";
3708
3738
  const defaultColumnWidth = {
3709
3739
  left: DEFAULT_LEFT_COLUMN_WIDTH,
@@ -3779,10 +3809,10 @@ class Ui extends BaseService {
3779
3809
  ...toRaw(this.get("columnWidth"))
3780
3810
  };
3781
3811
  if (left) {
3782
- columnWidth.left = left;
3812
+ columnWidth.left = Math.max(left, MIN_LEFT_COLUMN_WIDTH);
3783
3813
  }
3784
3814
  if (right) {
3785
- columnWidth.right = right;
3815
+ columnWidth.right = Math.max(right, MIN_RIGHT_COLUMN_WIDTH);
3786
3816
  }
3787
3817
  if (!center || center === "auto") {
3788
3818
  const bodyWidth = globalThis.document.body.clientWidth;
@@ -4015,5 +4045,5 @@ var index = {
4015
4045
  }
4016
4046
  };
4017
4047
 
4018
- export { COPY_STORAGE_KEY, ComponentListPanel, DEFAULT_CONFIG, Fixed2Other, Keys, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, ToolButton, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, generatePageName, generatePageNameByApp, getConfig, getDefaultPropsValue, getNodeIndex, getPageList, getPageNameList, historyService, info, initPosition, isFixed, log, propsService, setConfig, setLayout, toRelative, uiService, warn };
4048
+ export { COPY_STORAGE_KEY, ComponentListPanel, DEFAULT_CONFIG, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, Keys, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, ToolButton, V_GUIDE_LINE_STORAGE_KEY, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, generatePageName, generatePageNameByApp, getConfig, getDefaultPropsValue, getGuideLineFromCache, getNodeIndex, getPageList, getPageNameList, historyService, info, initPosition, isFixed, log, propsService, setConfig, setLayout, toRelative, uiService, warn };
4019
4049
  //# sourceMappingURL=tmagic-editor.es.js.map