@tmagic/editor 1.2.0-beta.3 → 1.2.0-beta.5

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.
@@ -2532,8 +2532,11 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2532
2532
  const changeLeft = (deltaX) => {
2533
2533
  if (typeof props.left === "undefined")
2534
2534
  return;
2535
- const left = Math.max(props.left + deltaX, props.minLeft) || 0;
2535
+ let left = Math.max(props.left + deltaX, props.minLeft) || 0;
2536
2536
  emit("update:left", left);
2537
+ if (clientWidth - left - (props.right || 0) <= 0) {
2538
+ left = props.left;
2539
+ }
2537
2540
  center.value = clientWidth - left - (props.right || 0);
2538
2541
  emit("change", {
2539
2542
  left,
@@ -2544,8 +2547,11 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
2544
2547
  const changeRight = (deltaX) => {
2545
2548
  if (typeof props.right === "undefined")
2546
2549
  return;
2547
- const right = Math.max(props.right - deltaX, props.minRight) || 0;
2550
+ let right = Math.max(props.right - deltaX, props.minRight) || 0;
2548
2551
  emit("update:right", right);
2552
+ if (clientWidth - (props.left || 0) - right <= 0) {
2553
+ right = props.right;
2554
+ }
2549
2555
  center.value = clientWidth - (props.left || 0) - right;
2550
2556
  emit("change", {
2551
2557
  left: props.left,
@@ -2601,41 +2607,57 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2601
2607
  const root = computed(() => editorService?.get("root"));
2602
2608
  const pageLength = computed(() => editorService?.get("pageLength") || 0);
2603
2609
  const showSrc = computed(() => uiService?.get("showSrc"));
2610
+ const LEFT_COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorLeftColumnWidthData";
2611
+ const RIGHT_COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorRightColumnWidthData";
2612
+ const leftColumnWidthCacheData = Number(globalThis.localStorage.getItem(LEFT_COLUMN_WIDTH_STORAGE_KEY));
2613
+ const RightColumnWidthCacheData = Number(globalThis.localStorage.getItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY));
2604
2614
  const columnWidth = ref({
2605
- left: DEFAULT_LEFT_COLUMN_WIDTH,
2615
+ left: leftColumnWidthCacheData,
2606
2616
  center: 0,
2607
- right: 0
2617
+ right: RightColumnWidthCacheData
2608
2618
  });
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;
2619
+ watch(
2620
+ pageLength,
2621
+ (length) => {
2622
+ const left = columnWidth.value.left || DEFAULT_LEFT_COLUMN_WIDTH;
2623
+ columnWidth.value.left = left;
2624
+ if (length <= 0) {
2625
+ columnWidth.value.right = void 0;
2626
+ columnWidth.value.center = globalThis.document.body.clientWidth - left;
2627
+ } else {
2628
+ const right = columnWidth.value.right || RightColumnWidthCacheData || DEFAULT_RIGHT_COLUMN_WIDTH;
2629
+ columnWidth.value.right = right;
2630
+ columnWidth.value.center = globalThis.document.body.clientWidth - left - right;
2631
+ }
2632
+ uiService?.set("columnWidth", columnWidth);
2633
+ },
2634
+ {
2635
+ immediate: true
2617
2636
  }
2618
- });
2619
- const saveCode = (value) => {
2620
- try {
2621
- editorService?.set("root", eval(value));
2622
- } catch (e) {
2623
- console.error(e);
2637
+ );
2638
+ watch(
2639
+ () => columnWidth.value.right,
2640
+ (right) => {
2641
+ if (typeof right === "undefined")
2642
+ return;
2643
+ globalThis.localStorage.setItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY, `${right}`);
2624
2644
  }
2645
+ );
2646
+ watch(
2647
+ () => columnWidth.value.left,
2648
+ (left) => {
2649
+ globalThis.localStorage.setItem(LEFT_COLUMN_WIDTH_STORAGE_KEY, `${left}`);
2650
+ }
2651
+ );
2652
+ const columnWidthChange = (columnWidth2) => {
2653
+ uiService?.set("columnWidth", columnWidth2);
2625
2654
  };
2626
- const COLUMN_WIDTH_STORAGE_KEY = "$MagicEditorColumnWidthData";
2627
- const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
2628
- if (columnWidthCacheData) {
2655
+ const saveCode = (value) => {
2629
2656
  try {
2630
- const columnWidthCache = JSON.parse(columnWidthCacheData);
2631
- columnWidth.value = columnWidthCache;
2657
+ editorService?.set("root", eval(value));
2632
2658
  } catch (e) {
2633
2659
  console.error(e);
2634
2660
  }
2635
- }
2636
- const columnWidthChange = (columnWidth2) => {
2637
- uiService?.set("columnWidth", columnWidth2);
2638
- globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth2));
2639
2661
  };
2640
2662
  return (_ctx, _cache) => {
2641
2663
  const _component_magic_code_editor = resolveComponent("magic-code-editor");