@tmagic/editor 1.4.0-beta.1 → 1.4.0-beta.2

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.
Files changed (34) hide show
  1. package/dist/style.css +14 -6
  2. package/dist/tmagic-editor.js +259 -167
  3. package/dist/tmagic-editor.umd.cjs +258 -164
  4. package/package.json +11 -11
  5. package/src/components/CodeBlockEditor.vue +43 -46
  6. package/src/components/FloatingBox.vue +38 -33
  7. package/src/components/SplitView.vue +46 -35
  8. package/src/hooks/index.ts +2 -0
  9. package/src/hooks/use-code-block-edit.ts +1 -1
  10. package/src/hooks/use-editor-content-height.ts +20 -0
  11. package/src/hooks/use-float-box.ts +8 -8
  12. package/src/hooks/use-window-rect.ts +20 -0
  13. package/src/layouts/Framework.vue +33 -34
  14. package/src/layouts/PropsPanel.vue +35 -0
  15. package/src/layouts/sidebar/Sidebar.vue +13 -8
  16. package/src/layouts/workspace/viewer/NodeListMenu.vue +1 -0
  17. package/src/services/stageOverlay.ts +2 -2
  18. package/src/services/ui.ts +6 -0
  19. package/src/theme/code-block.scss +0 -5
  20. package/src/theme/floating-box.scss +2 -2
  21. package/src/theme/props-panel.scss +14 -0
  22. package/src/type.ts +6 -0
  23. package/types/components/CodeBlockEditor.vue.d.ts +45 -24
  24. package/types/components/FloatingBox.vue.d.ts +42 -57
  25. package/types/components/SplitView.vue.d.ts +2 -0
  26. package/types/hooks/index.d.ts +2 -0
  27. package/types/hooks/use-code-block-edit.d.ts +16 -2
  28. package/types/hooks/use-data-source-method.d.ts +16 -2
  29. package/types/hooks/use-editor-content-height.d.ts +3 -0
  30. package/types/hooks/use-window-rect.d.ts +6 -0
  31. package/types/layouts/sidebar/Sidebar.vue.d.ts +1 -1
  32. package/types/services/stageOverlay.d.ts +1 -1
  33. package/types/services/ui.d.ts +6 -0
  34. package/types/type.d.ts +6 -0
@@ -32,7 +32,7 @@
32
32
  emmetMonacoEs.emmetHTML(monaco__namespace);
33
33
  emmetMonacoEs.emmetCSS(monaco__namespace, ["css", "scss"]);
34
34
 
35
- const _hoisted_1$u = {
35
+ const _hoisted_1$t = {
36
36
  class: /* @__PURE__ */ vue.normalizeClass(`magic-code-editor`)
37
37
  };
38
38
  const _sfc_main$U = /* @__PURE__ */ vue.defineComponent({
@@ -193,7 +193,7 @@
193
193
  }
194
194
  });
195
195
  return (_ctx, _cache) => {
196
- return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$u, [
196
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$t, [
197
197
  (vue.openBlock(), vue.createBlock(vue.Teleport, {
198
198
  to: "body",
199
199
  disabled: !fullScreen.value
@@ -459,39 +459,45 @@
459
459
  }
460
460
  });
461
461
 
462
- const _hoisted_1$t = { class: "m-editor-float-box-body" };
463
462
  const _sfc_main$Q = /* @__PURE__ */ vue.defineComponent({
464
463
  __name: "FloatingBox",
465
- props: {
466
- visible: { type: Boolean, default: false },
464
+ props: /* @__PURE__ */ vue.mergeModels({
467
465
  position: { default: () => ({ left: 0, top: 0 }) },
468
- rect: { default: () => ({ width: "auto", height: "auto" }) },
469
466
  title: { default: "" },
470
467
  beforeClose: {}
471
- },
472
- emits: ["update:visible"],
473
- setup(__props, { expose: __expose, emit: __emit }) {
468
+ }, {
469
+ "width": { default: 0 },
470
+ "widthModifiers": {},
471
+ "height": { default: 0 },
472
+ "heightModifiers": {},
473
+ "visible": { type: Boolean, ...{ default: false } },
474
+ "visibleModifiers": {}
475
+ }),
476
+ emits: ["update:width", "update:height", "update:visible"],
477
+ setup(__props, { expose: __expose }) {
478
+ const width = vue.useModel(__props, "width");
479
+ const height = vue.useModel(__props, "height");
480
+ const visible = vue.useModel(__props, "visible");
474
481
  const props = __props;
475
- const emit = __emit;
476
482
  const target = vue.ref();
477
- const dragTarget = vue.ref();
483
+ const titleEl = vue.ref();
478
484
  const zIndex = design.useZIndex();
479
485
  const curZIndex = vue.ref(zIndex.nextZIndex());
480
- const rect = vue.ref({
481
- width: props.rect.width,
482
- height: props.rect.height
483
- });
484
- vue.watchEffect(() => {
485
- rect.value = {
486
- width: props.rect.width,
487
- height: props.rect.height
488
- };
486
+ const titleHeight = vue.ref(0);
487
+ const bodyHeight = vue.computed(() => {
488
+ if (height.value) {
489
+ return height.value - titleHeight.value;
490
+ }
491
+ if (target.value) {
492
+ return target.value.clientHeight - titleHeight.value;
493
+ }
494
+ return "auto";
489
495
  });
490
496
  const style = vue.computed(() => ({
491
497
  left: `${props.position.left}px`,
492
498
  top: `${props.position.top}px`,
493
- width: typeof rect.value.width === "string" ? rect.value.width : `${rect.value.width}px`,
494
- height: typeof rect.value.height === "string" ? rect.value.height : `${rect.value.height}px`
499
+ width: width.value ? `${width.value}px` : "auto",
500
+ height: height.value ? `${height.value}px` : "auto"
495
501
  }));
496
502
  let moveable = null;
497
503
  const initMoveable = () => {
@@ -504,7 +510,7 @@
504
510
  keepRatio: false,
505
511
  origin: false,
506
512
  snappable: true,
507
- dragTarget: dragTarget.value,
513
+ dragTarget: titleEl.value,
508
514
  dragTargetSelf: false,
509
515
  linePadding: 10,
510
516
  controlPadding: 10,
@@ -514,8 +520,8 @@
514
520
  e.target.style.transform = e.transform;
515
521
  });
516
522
  moveable.on("resize", (e) => {
517
- rect.value.width = e.width;
518
- rect.value.height = e.height;
523
+ width.value = e.width;
524
+ height.value = e.height;
519
525
  e.target.style.width = `${e.width}px`;
520
526
  e.target.style.height = `${e.height}px`;
521
527
  e.target.style.transform = e.drag.transform;
@@ -526,11 +532,20 @@
526
532
  moveable = null;
527
533
  };
528
534
  vue.watch(
529
- () => props.visible,
530
- async (visible) => {
531
- if (visible) {
535
+ visible,
536
+ async (visible2) => {
537
+ if (visible2) {
532
538
  await vue.nextTick();
533
- initMoveable();
539
+ const targetRect = target.value?.getBoundingClientRect();
540
+ if (targetRect) {
541
+ width.value = targetRect.width;
542
+ height.value = targetRect.height;
543
+ initMoveable();
544
+ }
545
+ if (titleEl.value) {
546
+ const titleRect = titleEl.value.getBoundingClientRect();
547
+ titleHeight.value = titleRect.height;
548
+ }
534
549
  } else {
535
550
  destroyMoveable();
536
551
  }
@@ -544,7 +559,7 @@
544
559
  });
545
560
  const hide = (cancel) => {
546
561
  if (cancel !== false) {
547
- emit("update:visible", false);
562
+ visible.value = false;
548
563
  }
549
564
  };
550
565
  const closeHandler = () => {
@@ -558,10 +573,12 @@
558
573
  curZIndex.value = zIndex.nextZIndex();
559
574
  };
560
575
  __expose({
561
- target
576
+ bodyHeight,
577
+ target,
578
+ titleEl
562
579
  });
563
580
  return (_ctx, _cache) => {
564
- return _ctx.visible ? (vue.openBlock(), vue.createBlock(vue.Teleport, {
581
+ return visible.value ? (vue.openBlock(), vue.createBlock(vue.Teleport, {
565
582
  key: 0,
566
583
  to: "body"
567
584
  }, [
@@ -573,8 +590,8 @@
573
590
  onMousedown: nextZIndex
574
591
  }, [
575
592
  vue.createElementVNode("div", {
576
- ref_key: "dragTarget",
577
- ref: dragTarget,
593
+ ref_key: "titleEl",
594
+ ref: titleEl,
578
595
  class: "m-editor-float-box-title"
579
596
  }, [
580
597
  vue.renderSlot(_ctx.$slots, "title", {}, () => [
@@ -589,15 +606,49 @@
589
606
  }, null, 8, ["icon"])
590
607
  ])
591
608
  ], 512),
592
- vue.createElementVNode("div", _hoisted_1$t, [
609
+ vue.createElementVNode("div", {
610
+ class: "m-editor-float-box-body",
611
+ style: vue.normalizeStyle({ height: `${bodyHeight.value}px` })
612
+ }, [
593
613
  vue.renderSlot(_ctx.$slots, "body")
594
- ])
614
+ ], 4)
595
615
  ], 36)
596
616
  ])) : vue.createCommentVNode("", true);
597
617
  };
598
618
  }
599
619
  });
600
620
 
621
+ const useEditorContentHeight = () => {
622
+ const services = vue.inject("services");
623
+ const frameworkHeight = vue.computed(() => services?.uiService.get("frameworkRect").height || 0);
624
+ const navMenuHeight = vue.computed(() => services?.uiService.get("navMenuRect").height || 0);
625
+ const editorContentHeight = vue.computed(() => frameworkHeight.value - navMenuHeight.value);
626
+ const height = vue.ref(0);
627
+ vue.watchEffect(() => {
628
+ if (height.value > 0)
629
+ return;
630
+ height.value = editorContentHeight.value;
631
+ });
632
+ return {
633
+ height
634
+ };
635
+ };
636
+
637
+ const useWindowRect = () => {
638
+ const rect = vue.reactive({ width: globalThis.innerWidth, height: globalThis.innerHeight });
639
+ const windowResizeHandler = () => {
640
+ rect.width = globalThis.innerWidth;
641
+ rect.height = globalThis.innerHeight;
642
+ };
643
+ globalThis.addEventListener("resize", windowResizeHandler);
644
+ vue.onBeforeUnmount(() => {
645
+ globalThis.removeEventListener("resize", windowResizeHandler);
646
+ });
647
+ return {
648
+ rect
649
+ };
650
+ };
651
+
601
652
  const _hoisted_1$s = { style: { "display": "flex", "margin-bottom": "10px" } };
602
653
  const _hoisted_2$k = { style: { "flex": "1" } };
603
654
  const _hoisted_3$8 = { style: { "flex": "1" } };
@@ -607,40 +658,36 @@
607
658
  name: "MEditorCodeBlockEditor"
608
659
  },
609
660
  __name: "CodeBlockEditor",
610
- props: {
661
+ props: /* @__PURE__ */ vue.mergeModels({
611
662
  content: {},
612
663
  disabled: { type: Boolean },
613
664
  isDataSource: { type: Boolean },
614
665
  dataSourceType: {},
615
666
  slideType: {}
616
- },
617
- emits: ["submit"],
667
+ }, {
668
+ "width": { default: 670 },
669
+ "widthModifiers": {},
670
+ "visible": { type: Boolean, ...{ default: false } },
671
+ "visibleModifiers": {}
672
+ }),
673
+ emits: /* @__PURE__ */ vue.mergeModels(["submit"], ["update:width", "update:visible"]),
618
674
  setup(__props, { expose: __expose, emit: __emit }) {
675
+ const width = vue.useModel(__props, "width");
676
+ const boxVisible = vue.useModel(__props, "visible");
619
677
  const props = __props;
620
678
  const emit = __emit;
621
679
  const services = vue.inject("services");
680
+ const { height: codeBlockEditorHeight } = useEditorContentHeight();
622
681
  const difVisible = vue.ref(false);
623
- const height = vue.ref(globalThis.innerHeight);
624
- const windowReizehandler = () => {
625
- height.value = globalThis.innerHeight;
626
- };
627
- globalThis.addEventListener("resize", windowReizehandler);
628
- vue.onBeforeUnmount(() => {
629
- globalThis.removeEventListener("resize", windowReizehandler);
630
- });
682
+ const { rect: windowRect } = useWindowRect();
631
683
  const magicVsEditor = vue.ref();
632
684
  const diffChange = () => {
633
- if (!magicVsEditor.value || !fomDrawer.value?.form) {
685
+ if (!magicVsEditor.value || !formBox.value?.form) {
634
686
  return;
635
687
  }
636
- fomDrawer.value.form.values.content = magicVsEditor.value.getEditorValue();
688
+ formBox.value.form.values.content = magicVsEditor.value.getEditorValue();
637
689
  difVisible.value = false;
638
690
  };
639
- const columnWidth = vue.computed(() => services?.uiService.get("columnWidth"));
640
- const size = vue.computed(
641
- () => columnWidth.value ? columnWidth.value.center + columnWidth.value.right - (props.isDataSource ? 100 : 0) : 600
642
- );
643
- const codeEditorHeight = vue.ref("600px");
644
691
  const defaultParamColConfig = {
645
692
  type: "row",
646
693
  label: "参数类型",
@@ -723,7 +770,7 @@
723
770
  name: "content",
724
771
  type: "vs-code",
725
772
  options: vue.inject("codeOptions", {}),
726
- height: codeEditorHeight.value,
773
+ height: "500px",
727
774
  onChange: (formState, code) => {
728
775
  try {
729
776
  getConfig("parseDSL")(code);
@@ -736,26 +783,20 @@
736
783
  }
737
784
  ]);
738
785
  const submitForm = (values) => {
786
+ changedValue.value = void 0;
739
787
  emit("submit", values);
740
788
  };
741
789
  const errorHandler = (error) => {
742
790
  design.tMagicMessage.error(error.message);
743
791
  };
744
- const fomDrawer = vue.ref();
745
- const openHandler = () => {
746
- setTimeout(() => {
747
- if (fomDrawer.value) {
748
- const height2 = fomDrawer.value?.bodyHeight - 348 - (props.isDataSource ? 50 : 0);
749
- codeEditorHeight.value = `${height2 > 100 ? height2 : 600}px`;
750
- }
751
- });
752
- };
792
+ const formBox = vue.ref();
753
793
  const changedValue = vue.ref();
754
794
  const changeHandler = (values) => {
755
795
  changedValue.value = values;
756
796
  };
757
797
  const beforeClose = (done) => {
758
798
  if (!changedValue.value) {
799
+ editVisible.value = false;
759
800
  done();
760
801
  return;
761
802
  }
@@ -766,22 +807,25 @@
766
807
  distinguishCancelAndClose: true
767
808
  }).then(() => {
768
809
  changedValue.value && submitForm(changedValue.value);
810
+ editVisible.value = false;
769
811
  done();
770
812
  }).catch((action) => {
813
+ if (action === "cancel") {
814
+ editVisible.value = false;
815
+ }
771
816
  done(action === "cancel");
772
817
  });
773
818
  };
774
819
  const closedHandler = () => {
775
820
  changedValue.value = void 0;
776
821
  };
777
- const boxVisible = vue.ref(false);
778
822
  const editVisible = vue.ref(false);
779
823
  const floatingBoxBody = vue.ref();
780
824
  const boxPosition = vue.computed(() => {
781
- const columnWidth2 = services?.uiService?.get("columnWidth");
825
+ const columnWidth = services?.uiService?.get("columnWidth");
782
826
  const navMenuRect = services?.uiService?.get("navMenuRect");
783
827
  return {
784
- left: columnWidth2?.left ?? 0,
828
+ left: columnWidth?.left ?? 0,
785
829
  top: (navMenuRect?.top ?? 0) + (navMenuRect?.height ?? 0)
786
830
  };
787
831
  });
@@ -789,13 +833,16 @@
789
833
  async show() {
790
834
  if (props.slideType !== "box") {
791
835
  boxVisible.value = true;
836
+ await vue.nextTick();
792
837
  }
793
- await vue.nextTick();
794
838
  editVisible.value = true;
795
- fomDrawer.value?.show();
796
839
  },
797
- hide() {
798
- fomDrawer.value?.hide();
840
+ async hide() {
841
+ editVisible.value = false;
842
+ if (props.slideType !== "box") {
843
+ await vue.nextTick();
844
+ boxVisible.value = false;
845
+ }
799
846
  }
800
847
  });
801
848
  return (_ctx, _cache) => {
@@ -803,18 +850,23 @@
803
850
  vue.createVNode(_sfc_main$Q, {
804
851
  visible: boxVisible.value,
805
852
  "onUpdate:visible": _cache[0] || (_cache[0] = ($event) => boxVisible.value = $event),
806
- title: "代码编辑",
853
+ width: width.value,
854
+ "onUpdate:width": _cache[1] || (_cache[1] = ($event) => width.value = $event),
855
+ height: vue.unref(codeBlockEditorHeight),
856
+ "onUpdate:height": _cache[2] || (_cache[2] = ($event) => vue.isRef(codeBlockEditorHeight) ? codeBlockEditorHeight.value = $event : null),
857
+ title: _ctx.content.name ? `${_ctx.disabled ? "查看" : "编辑"}${_ctx.content.name}` : "新增代码",
807
858
  position: boxPosition.value,
808
859
  "before-close": beforeClose
809
860
  }, {
810
861
  body: vue.withCtx(() => [
811
862
  vue.createElementVNode("div", {
812
863
  ref_key: "floatingBoxBody",
813
- ref: floatingBoxBody
864
+ ref: floatingBoxBody,
865
+ style: { "height": "100%" }
814
866
  }, null, 512)
815
867
  ]),
816
868
  _: 1
817
- }, 8, ["visible", "position"]),
869
+ }, 8, ["visible", "width", "height", "title", "position"]),
818
870
  editVisible.value ? (vue.openBlock(), vue.createBlock(vue.Teleport, {
819
871
  key: 0,
820
872
  to: floatingBoxBody.value,
@@ -822,39 +874,39 @@
822
874
  }, [
823
875
  vue.createVNode(vue.unref(form.MFormBox), {
824
876
  class: "m-editor-code-block-editor",
825
- ref_key: "fomDrawer",
826
- ref: fomDrawer,
877
+ ref_key: "formBox",
878
+ ref: formBox,
827
879
  "label-width": "80px",
828
880
  "close-on-press-escape": false,
829
881
  title: _ctx.content.name,
830
- width: size.value,
831
882
  config: functionConfig.value,
832
883
  values: _ctx.content,
833
884
  disabled: _ctx.disabled,
885
+ height: floatingBoxBody.value?.clientHeight,
834
886
  onChange: changeHandler,
835
887
  onSubmit: submitForm,
836
888
  onError: errorHandler,
837
- onOpen: openHandler,
838
889
  onClosed: closedHandler
839
890
  }, {
840
891
  left: vue.withCtx(() => [
841
- vue.createVNode(vue.unref(design.TMagicButton), {
892
+ !_ctx.disabled ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicButton), {
893
+ key: 0,
842
894
  type: "primary",
843
895
  link: "",
844
- onClick: _cache[1] || (_cache[1] = ($event) => difVisible.value = true)
896
+ onClick: _cache[3] || (_cache[3] = ($event) => difVisible.value = true)
845
897
  }, {
846
898
  default: vue.withCtx(() => [
847
899
  vue.createTextVNode("查看修改")
848
900
  ]),
849
901
  _: 1
850
- })
902
+ })) : vue.createCommentVNode("", true)
851
903
  ]),
852
904
  _: 1
853
- }, 8, ["title", "width", "config", "values", "disabled"])
905
+ }, 8, ["title", "config", "values", "disabled", "height"])
854
906
  ], 8, ["to", "disabled"])) : vue.createCommentVNode("", true),
855
907
  vue.createVNode(vue.unref(design.TMagicDialog), {
856
908
  modelValue: difVisible.value,
857
- "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => difVisible.value = $event),
909
+ "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => difVisible.value = $event),
858
910
  title: "查看修改",
859
911
  fullscreen: ""
860
912
  }, {
@@ -862,7 +914,7 @@
862
914
  vue.createElementVNode("span", _hoisted_4$7, [
863
915
  vue.createVNode(vue.unref(design.TMagicButton), {
864
916
  size: "small",
865
- onClick: _cache[2] || (_cache[2] = ($event) => difVisible.value = false)
917
+ onClick: _cache[4] || (_cache[4] = ($event) => difVisible.value = false)
866
918
  }, {
867
919
  default: vue.withCtx(() => [
868
920
  vue.createTextVNode("取消")
@@ -913,8 +965,8 @@
913
965
  type: "diff",
914
966
  language: "json",
915
967
  initValues: _ctx.content.content,
916
- modifiedValues: fomDrawer.value?.form?.values.content,
917
- style: vue.normalizeStyle(`height: ${height.value - 200}px`)
968
+ modifiedValues: formBox.value?.form?.values.content,
969
+ style: vue.normalizeStyle(`height: ${vue.unref(windowRect).height - 150}px`)
918
970
  }, null, 8, ["initValues", "modifiedValues", "style"])) : vue.createCommentVNode("", true)
919
971
  ]),
920
972
  _: 1
@@ -3698,7 +3750,7 @@
3698
3750
  return;
3699
3751
  }
3700
3752
  codeConfig.value = {
3701
- name: "代码块",
3753
+ name: "",
3702
3754
  content: `({app, params}) => {
3703
3755
  // place your code here
3704
3756
  }`,
@@ -5845,6 +5897,7 @@
5845
5897
  },
5846
5898
  __name: "SplitView",
5847
5899
  props: {
5900
+ width: {},
5848
5901
  left: {},
5849
5902
  right: {},
5850
5903
  minLeft: { default: 46 },
@@ -5861,17 +5914,19 @@
5861
5914
  const el = vue.ref();
5862
5915
  const hasLeft = vue.computed(() => typeof props.left !== "undefined");
5863
5916
  const hasRight = vue.computed(() => typeof props.right !== "undefined");
5864
- const getCenterWidth = (clientWidth2, l = 0, r = 0) => {
5917
+ const center = vue.ref(0);
5918
+ let clientWidth = 0;
5919
+ const getCenterWidth = (l = 0, r = 0) => {
5865
5920
  let right = r > 0 ? r : 0;
5866
5921
  let left = l > 0 ? l : 0;
5867
- let center2 = clientWidth2 - left - right;
5922
+ let center2 = clientWidth - left - right;
5868
5923
  if (center2 < props.minCenter) {
5869
5924
  center2 = props.minCenter;
5870
5925
  if (right > center2 + props.minRight) {
5871
- right = clientWidth2 - left - center2;
5926
+ right = clientWidth - left - center2;
5872
5927
  } else {
5873
5928
  right = props.minRight;
5874
- left = clientWidth2 - right - center2;
5929
+ left = clientWidth - right - center2;
5875
5930
  }
5876
5931
  }
5877
5932
  return {
@@ -5880,36 +5935,43 @@
5880
5935
  right
5881
5936
  };
5882
5937
  };
5883
- let clientWidth = 0;
5884
- const resizerObserver = new ResizeObserver((entries) => {
5885
- for (const { contentRect } of entries) {
5886
- clientWidth = contentRect.width;
5887
- let left = props.left || 0;
5888
- let right = props.right || 0;
5889
- if (left > clientWidth) {
5890
- left = clientWidth / 3;
5891
- }
5892
- if (right > clientWidth) {
5893
- right = clientWidth / 3;
5894
- }
5895
- const columnWidth = getCenterWidth(clientWidth, left, right);
5896
- center.value = columnWidth.center;
5897
- emit("change", {
5898
- left: columnWidth.left,
5899
- center: center.value,
5900
- right: columnWidth.right
5901
- });
5938
+ const widthChange = (width) => {
5939
+ if (width <= 0) {
5940
+ return;
5902
5941
  }
5903
- });
5904
- vue.onMounted(() => {
5905
- if (el.value) {
5906
- resizerObserver.observe(el.value);
5942
+ clientWidth = width;
5943
+ let left = props.left || 0;
5944
+ let right = props.right || 0;
5945
+ if (left > clientWidth) {
5946
+ left = clientWidth / 3;
5907
5947
  }
5908
- });
5909
- vue.onBeforeUnmount(() => {
5910
- resizerObserver.disconnect();
5911
- });
5912
- const center = vue.ref(0);
5948
+ if (right > clientWidth) {
5949
+ right = clientWidth / 3;
5950
+ }
5951
+ const columnWidth = getCenterWidth(left, right);
5952
+ center.value = columnWidth.center;
5953
+ emit("change", columnWidth);
5954
+ };
5955
+ if (typeof props.width !== "number") {
5956
+ const resizerObserver = new ResizeObserver((entries) => {
5957
+ for (const { contentRect } of entries) {
5958
+ widthChange(contentRect.width);
5959
+ }
5960
+ });
5961
+ vue.onMounted(() => {
5962
+ if (el.value) {
5963
+ resizerObserver.observe(el.value);
5964
+ }
5965
+ });
5966
+ vue.onBeforeUnmount(() => {
5967
+ resizerObserver.disconnect();
5968
+ });
5969
+ } else {
5970
+ vue.watchEffect(() => {
5971
+ if (typeof props.width === "number")
5972
+ widthChange(props.width);
5973
+ });
5974
+ }
5913
5975
  const changeLeft = ({ deltaX }) => {
5914
5976
  if (typeof props.left === "undefined")
5915
5977
  return;
@@ -5918,7 +5980,7 @@
5918
5980
  if (clientWidth - left - (props.right || 0) <= 0) {
5919
5981
  left = props.left;
5920
5982
  }
5921
- const columnWidth = getCenterWidth(clientWidth, left, props.right || 0);
5983
+ const columnWidth = getCenterWidth(left, props.right || 0);
5922
5984
  center.value = columnWidth.center;
5923
5985
  emit("change", {
5924
5986
  left: columnWidth.left,
@@ -5934,7 +5996,7 @@
5934
5996
  if (clientWidth - (props.left || 0) - right <= 0) {
5935
5997
  right = props.right;
5936
5998
  }
5937
- const columnWidth = getCenterWidth(clientWidth, props.left, right);
5999
+ const columnWidth = getCenterWidth(props.left, right);
5938
6000
  center.value = columnWidth.center;
5939
6001
  emit("change", {
5940
6002
  left: columnWidth.left,
@@ -5944,7 +6006,8 @@
5944
6006
  };
5945
6007
  __expose({
5946
6008
  updateWidth() {
5947
- const columnWidth = getCenterWidth(el.value?.clientWidth || clientWidth, props.left, props.right);
6009
+ clientWidth = props.width ?? el.value?.clientWidth ?? clientWidth;
6010
+ const columnWidth = getCenterWidth(props.left, props.right);
5948
6011
  emit("change", {
5949
6012
  left: columnWidth.left,
5950
6013
  center: center.value,
@@ -6603,36 +6666,14 @@
6603
6666
  const stageLoading = vue.computed(() => editorService?.get("stageLoading") || false);
6604
6667
  const showSrc = vue.computed(() => uiService?.get("showSrc"));
6605
6668
  const getLeftColumnWidthCacheData = () => Number(globalThis.localStorage.getItem(LEFT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_LEFT_COLUMN_WIDTH;
6606
- const leftColumnWidthCacheData = getLeftColumnWidthCacheData();
6607
- const RightColumnWidthCacheData = Number(globalThis.localStorage.getItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_RIGHT_COLUMN_WIDTH;
6608
6669
  const columnWidth = vue.ref({
6609
- left: leftColumnWidthCacheData,
6670
+ left: getLeftColumnWidthCacheData(),
6610
6671
  center: 0,
6611
- right: RightColumnWidthCacheData
6672
+ right: Number(globalThis.localStorage.getItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_RIGHT_COLUMN_WIDTH
6673
+ });
6674
+ vue.watch(pageLength, () => {
6675
+ splitView.value?.updateWidth();
6612
6676
  });
6613
- vue.watch(
6614
- [pageLength, splitView],
6615
- () => {
6616
- splitView.value?.updateWidth();
6617
- },
6618
- {
6619
- immediate: true
6620
- }
6621
- );
6622
- vue.watch(
6623
- () => columnWidth.value.right,
6624
- (right) => {
6625
- if (typeof right === "undefined")
6626
- return;
6627
- globalThis.localStorage.setItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY, `${right}`);
6628
- }
6629
- );
6630
- vue.watch(
6631
- () => columnWidth.value.left,
6632
- (left) => {
6633
- globalThis.localStorage.setItem(LEFT_COLUMN_WIDTH_STORAGE_KEY, `${left}`);
6634
- }
6635
- );
6636
6677
  vue.watch(
6637
6678
  () => uiService?.get("hideSlideBar"),
6638
6679
  (hideSlideBar) => {
@@ -6640,11 +6681,29 @@
6640
6681
  }
6641
6682
  );
6642
6683
  const columnWidthChange = (columnW) => {
6643
- columnWidth.value.left = columnW.left;
6644
- columnWidth.value.center = columnW.center;
6645
- columnWidth.value.right = columnW.right;
6684
+ columnWidth.value = columnW;
6685
+ globalThis.localStorage.setItem(LEFT_COLUMN_WIDTH_STORAGE_KEY, `${columnW.left}`);
6686
+ globalThis.localStorage.setItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY, `${columnW.right}`);
6646
6687
  uiService?.set("columnWidth", columnW);
6647
6688
  };
6689
+ const frameworkRect = vue.computed(() => uiService?.get("frameworkRect"));
6690
+ const resizerObserver = new ResizeObserver((entries) => {
6691
+ const { contentRect } = entries[0];
6692
+ uiService?.set("frameworkRect", {
6693
+ width: contentRect.width,
6694
+ height: contentRect.height,
6695
+ left: contentRect.left,
6696
+ top: contentRect.top
6697
+ });
6698
+ });
6699
+ vue.onMounted(() => {
6700
+ if (content.value) {
6701
+ resizerObserver.observe(content.value);
6702
+ }
6703
+ });
6704
+ vue.onBeforeUnmount(() => {
6705
+ resizerObserver.disconnect();
6706
+ });
6648
6707
  const saveCode = (value) => {
6649
6708
  try {
6650
6709
  const parseDSL = getConfig("parseDSL");
@@ -6687,6 +6746,7 @@
6687
6746
  "min-left": 65,
6688
6747
  "min-right": 20,
6689
6748
  "min-center": 100,
6749
+ width: frameworkRect.value?.width || 0,
6690
6750
  onChange: columnWidthChange
6691
6751
  }, vue.createSlots({
6692
6752
  left: vue.withCtx(() => [
@@ -6722,7 +6782,7 @@
6722
6782
  ]),
6723
6783
  key: "0"
6724
6784
  } : void 0
6725
- ]), 1032, ["left", "right"])), [
6785
+ ]), 1032, ["left", "right", "width"])), [
6726
6786
  [_directive_loading, stageLoading.value]
6727
6787
  ]),
6728
6788
  vue.renderSlot(_ctx.$slots, "content-after"),
@@ -6937,7 +6997,9 @@
6937
6997
  },
6938
6998
  emits: ["mounted", "submit-error", "form-error"],
6939
6999
  setup(__props, { expose: __expose, emit: __emit }) {
7000
+ const codeOptions = vue.inject("codeOptions", {});
6940
7001
  const emit = __emit;
7002
+ const showSrc = vue.ref(false);
6941
7003
  const internalInstance = vue.getCurrentInstance();
6942
7004
  const values = vue.ref({});
6943
7005
  const configForm = vue.ref();
@@ -6947,6 +7009,7 @@
6947
7009
  const nodes = vue.computed(() => services?.editorService.get("nodes") || []);
6948
7010
  const propsPanelSize = vue.computed(() => services?.uiService.get("propsPanelSize") || "small");
6949
7011
  const stage = vue.computed(() => services?.editorService.get("stage"));
7012
+ const { height: editorContentHeight } = useEditorContentHeight();
6950
7013
  const init = async () => {
6951
7014
  if (!node.value) {
6952
7015
  curFormConfig.value = [];
@@ -6980,6 +7043,9 @@
6980
7043
  const errorHandler = (e) => {
6981
7044
  emit("form-error", e);
6982
7045
  };
7046
+ const saveCode = (values2) => {
7047
+ services?.editorService.update(values2);
7048
+ };
6983
7049
  __expose({ configForm, submit });
6984
7050
  return (_ctx, _cache) => {
6985
7051
  return vue.withDirectives((vue.openBlock(), vue.createElementBlock("div", _hoisted_1$a, [
@@ -6995,7 +7061,24 @@
6995
7061
  "extend-state": _ctx.extendState,
6996
7062
  onChange: submit,
6997
7063
  onError: errorHandler
6998
- }, null, 8, ["class", "popper-class", "size", "init-values", "config", "extend-state"])
7064
+ }, null, 8, ["class", "popper-class", "size", "init-values", "config", "extend-state"]),
7065
+ vue.createVNode(vue.unref(design.TMagicButton), {
7066
+ class: "m-editor-props-panel-src-icon",
7067
+ circle: "",
7068
+ size: "large",
7069
+ title: "源码",
7070
+ icon: vue.unref(iconsVue.Document),
7071
+ type: showSrc.value ? "primary" : "",
7072
+ onClick: _cache[0] || (_cache[0] = ($event) => showSrc.value = !showSrc.value)
7073
+ }, null, 8, ["icon", "type"]),
7074
+ showSrc.value ? (vue.openBlock(), vue.createBlock(_sfc_main$U, {
7075
+ key: 0,
7076
+ height: `${vue.unref(editorContentHeight)}px`,
7077
+ "init-values": values.value,
7078
+ options: vue.unref(codeOptions),
7079
+ parse: true,
7080
+ onSave: saveCode
7081
+ }, null, 8, ["height", "init-values", "options"])) : vue.createCommentVNode("", true)
6999
7082
  ], 512)), [
7000
7083
  [vue.vShow, nodes.value.length === 1]
7001
7084
  ]);
@@ -7020,33 +7103,33 @@
7020
7103
  const showingBoxKeys = vue.computed(
7021
7104
  () => Object.keys(floatBoxStates.value).filter((key) => floatBoxStates.value[key].status)
7022
7105
  );
7023
- const isDraging = vue.ref(false);
7024
- const dragstartHandler = () => isDraging.value = true;
7106
+ const isDragging = vue.ref(false);
7107
+ const dragstartHandler = () => isDragging.value = true;
7025
7108
  const dragendHandler = (key, e) => {
7026
7109
  floatBoxStates.value[key] = {
7027
7110
  left: e.clientX,
7028
7111
  top: e.clientY,
7029
7112
  status: true
7030
7113
  };
7031
- isDraging.value = false;
7114
+ isDragging.value = false;
7032
7115
  };
7033
7116
  document.body.addEventListener("dragover", (e) => {
7034
- if (!isDraging.value)
7117
+ if (!isDragging.value)
7035
7118
  return;
7036
7119
  e.preventDefault();
7037
7120
  });
7038
7121
  vue.watch(
7039
7122
  () => slideKeys.value,
7040
- () => {
7041
- for (const key in slideKeys.value) {
7123
+ (slideKeys2) => {
7124
+ slideKeys2.forEach((key) => {
7042
7125
  if (floatBoxStates.value[key])
7043
- continue;
7126
+ return;
7044
7127
  floatBoxStates.value[key] = {
7045
7128
  status: false,
7046
7129
  top: 0,
7047
7130
  left: 0
7048
7131
  };
7049
- }
7132
+ });
7050
7133
  },
7051
7134
  {
7052
7135
  deep: true,
@@ -9007,6 +9090,7 @@
9007
9090
  setup(__props, { expose: __expose }) {
9008
9091
  const props = __props;
9009
9092
  const services = vue.inject("services");
9093
+ const columnLeftWitch = vue.computed(() => services?.uiService.get("columnWidth")[ColumnLayout.LEFT] || 0);
9010
9094
  const activeTabName = vue.ref(props.data?.status);
9011
9095
  const getItemConfig = (data) => {
9012
9096
  const map = {
@@ -9235,6 +9319,8 @@
9235
9319
  key: config.$key ?? index,
9236
9320
  visible: vue.unref(floatBoxStates)[config.$key].status,
9237
9321
  "onUpdate:visible": ($event) => vue.unref(floatBoxStates)[config.$key].status = $event,
9322
+ width: columnLeftWitch.value,
9323
+ height: 600,
9238
9324
  title: config.text,
9239
9325
  position: {
9240
9326
  left: vue.unref(floatBoxStates)[config.$key].left,
@@ -9247,7 +9333,7 @@
9247
9333
  ])
9248
9334
  ]),
9249
9335
  _: 2
9250
- }, 1032, ["visible", "onUpdate:visible", "title", "position"])) : vue.createCommentVNode("", true)
9336
+ }, 1032, ["visible", "onUpdate:visible", "width", "title", "position"])) : vue.createCommentVNode("", true)
9251
9337
  ], 64);
9252
9338
  }), 256))
9253
9339
  ]))
@@ -9606,6 +9692,12 @@
9606
9692
  top: 0,
9607
9693
  width: 0,
9608
9694
  height: 0
9695
+ },
9696
+ frameworkRect: {
9697
+ width: 0,
9698
+ height: 0,
9699
+ left: 0,
9700
+ top: 0
9609
9701
  }
9610
9702
  });
9611
9703
  const canUsePluginMethods$2 = {
@@ -10980,7 +11072,7 @@
10980
11072
  subStage?.renderer.contentWindow?.magic.onPageElUpdate(wrapDiv);
10981
11073
  });
10982
11074
  if (await stageOptions?.canSelect?.(contentEl)) {
10983
- subStage?.select(contentEl);
11075
+ subStage?.select(contentEl.id);
10984
11076
  }
10985
11077
  }
10986
11078
  updateHandler = () => {
@@ -11691,8 +11783,10 @@
11691
11783
  exports.uiService = uiService;
11692
11784
  exports.useCodeBlockEdit = useCodeBlockEdit;
11693
11785
  exports.useDataSourceMethod = useDataSourceMethod;
11786
+ exports.useEditorContentHeight = useEditorContentHeight;
11694
11787
  exports.useFloatBox = useFloatBox;
11695
11788
  exports.useStage = useStage;
11789
+ exports.useWindowRect = useWindowRect;
11696
11790
  exports.warn = warn;
11697
11791
 
11698
11792
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });