mce 0.14.1 → 0.14.3

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/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { Node as Node$1, Element2D, Timeline, Engine, Camera2D, DrawboardEffect, IN_BROWSER, clamp, assets, TimelineNode, Transform2D, DEG_TO_RAD, render, Animation, IN_MAC_OS } from "modern-canvas";
2
- import { reactive, computed, watch, markRaw, ref, warn, shallowRef, onBeforeUnmount, defineComponent, createElementBlock, createCommentVNode, unref, openBlock, normalizeStyle, toDisplayString, createVNode, useAttrs, createBlock, resolveDynamicComponent, normalizeClass, mergeProps, createElementVNode, inject, toValue, getCurrentInstance, provide, readonly, toRef, onMounted, useId, onDeactivated, onActivated, onScopeDispose, useModel, useTemplateRef, withDirectives, vShow, vModelText, nextTick, Fragment, renderList, renderSlot, mergeModels, resolveComponent, withCtx, withModifiers, Teleport, createTextVNode, createSlots, normalizeProps, guardReactiveProps, onBeforeMount, isRef, h, useSlots } from "vue";
1
+ import { Node as Node$1, Element2D, Timeline, Engine, Camera2D, DrawboardEffect, IN_BROWSER, clamp, assets, TimelineNode, Transform2D, DEG_TO_RAD, render, customNodes, Animation, IN_MAC_OS } from "modern-canvas";
2
+ import { reactive, computed, watch, markRaw, ref, warn, shallowRef, onBeforeUnmount, defineComponent, createElementBlock, createCommentVNode, unref, openBlock, normalizeStyle, toDisplayString, createVNode, useAttrs, createBlock, resolveDynamicComponent, normalizeClass, mergeProps, createElementVNode, inject, toValue, getCurrentInstance, provide, readonly, toRef, onMounted, useId, onDeactivated, onActivated, onScopeDispose, useModel, useTemplateRef, withDirectives, vShow, vModelText, nextTick, Fragment, renderList, renderSlot, mergeModels, resolveComponent, withCtx, withModifiers, Teleport, createTextVNode, createSlots, normalizeProps, guardReactiveProps, onBeforeMount, h, isRef, useSlots } from "vue";
3
3
  import { useFileDialog, useEventListener, isClient, onClickOutside, useDebounceFn, useResizeObserver as useResizeObserver$1, useLocalStorage, useImage } from "@vueuse/core";
4
4
  import { getObjectValueByPath, setObjectValueByPath, Observable, Reactivable, idGenerator, property, normalizeElement, normalizeTextContent, normalizeCRLF, isEqualObject } from "modern-idoc";
5
5
  import { saveAs } from "file-saver";
@@ -530,14 +530,14 @@ function initYElement(yMap, element = {}, parentId, regenId = false) {
530
530
  yChildrenIds
531
531
  };
532
532
  }
533
- function iElementToYElements(element, parentId, regenId = false) {
533
+ function iElementToYNodes(element, parentId, regenId = false) {
534
534
  const results = [];
535
- const yElement = new Y.Map();
536
- const { normalized, yChildrenIds } = initYElement(yElement, element, parentId, regenId);
535
+ const yNode = new Y.Map();
536
+ const { normalized, yChildrenIds } = initYElement(yNode, element, parentId, regenId);
537
537
  const id = normalized.id;
538
- results.push({ id, element: yElement });
538
+ results.push({ id, node: yNode });
539
539
  normalized.children?.forEach((iChild) => {
540
- const result = iElementToYElements(iChild, id, regenId);
540
+ const result = iElementToYNodes(iChild, id, regenId);
541
541
  yChildrenIds.push([result[0].id]);
542
542
  results.push(...result);
543
543
  });
@@ -547,7 +547,7 @@ class Doc extends Model {
547
547
  _yChildren;
548
548
  _yChildrenIds;
549
549
  root = reactive(new Node$1());
550
- nodeMap = /* @__PURE__ */ new Map();
550
+ _nodeMap = /* @__PURE__ */ new Map();
551
551
  get meta() {
552
552
  return this.root.meta;
553
553
  }
@@ -615,8 +615,8 @@ class Doc extends Model {
615
615
  }
616
616
  break;
617
617
  case "delete":
618
- this.nodeMap.get(key)?.remove();
619
- this.nodeMap.delete(key);
618
+ this._nodeMap.get(key)?.remove();
619
+ this._nodeMap.delete(key);
620
620
  break;
621
621
  }
622
622
  });
@@ -625,21 +625,21 @@ class Doc extends Model {
625
625
  super.reset();
626
626
  this._yChildren.clear();
627
627
  this._yChildrenIds.delete(0, this._yChildrenIds.length);
628
- this.nodeMap.clear();
628
+ this._nodeMap.clear();
629
629
  this.undoManager.clear();
630
630
  this.indexeddb?.clearData();
631
631
  return this;
632
632
  }
633
- _addElement(element, options = {}) {
633
+ _addNode(node, options = {}) {
634
634
  const { parentId, index, regenId } = options;
635
- const yNodes = iElementToYElements(element, parentId, regenId);
636
- yNodes.forEach((result) => this._yChildren.set(result.id, result.element));
637
- const nodeMap = yNodes.map((result) => this._getOrCreateNode(result.element));
638
- const first = nodeMap[0];
635
+ const yNodes = iElementToYNodes(node, parentId, regenId);
636
+ yNodes.forEach((result) => this._yChildren.set(result.id, result.node));
637
+ const _nodeMap = yNodes.map((result) => this._getOrCreateNode(result.node));
638
+ const first = _nodeMap[0];
639
639
  let parent;
640
640
  let childrenIds;
641
641
  if (parentId && parentId !== this.root.id) {
642
- parent = this.nodeMap.get(parentId);
642
+ parent = this._nodeMap.get(parentId);
643
643
  childrenIds = this._yChildren.get(parentId)?.get("childrenIds");
644
644
  } else {
645
645
  parent = this.root;
@@ -656,20 +656,16 @@ class Doc extends Model {
656
656
  }
657
657
  return first;
658
658
  }
659
- addElement(element, options) {
660
- return this.transact(() => {
661
- return this._addElement(element, options);
662
- });
659
+ addNode(node, options) {
660
+ return this.transact(() => this._addNode(node, options));
663
661
  }
664
- addElements(elements, options) {
665
- return this.transact(() => {
666
- return elements.map((element) => this._addElement(element, options));
667
- });
662
+ addNodes(nodes, options) {
663
+ return this.transact(() => nodes.map((element) => this._addNode(element, options)));
668
664
  }
669
665
  set(source) {
670
666
  const { children = [], meta = {}, ...props } = source;
671
667
  this.reset();
672
- this.addElements(children);
668
+ this.addNodes(children);
673
669
  this.setProperties(props);
674
670
  this._yProps.clear();
675
671
  for (const key in props) {
@@ -678,8 +674,8 @@ class Doc extends Model {
678
674
  this._yProps.set("meta", new Y.Map(Object.entries(meta)));
679
675
  return this;
680
676
  }
681
- _deleteElement(id) {
682
- const node = this.nodeMap.get(id);
677
+ _deleteNode(id) {
678
+ const node = this._nodeMap.get(id);
683
679
  const yNode = this._yChildren.get(id);
684
680
  if (!yNode || !node) {
685
681
  return;
@@ -692,14 +688,17 @@ class Doc extends Model {
692
688
  parentChildrenIds.delete(index);
693
689
  }
694
690
  }
695
- yNode.get("childrenIds").forEach((id2) => this._deleteElement(id2));
691
+ yNode.get("childrenIds").forEach((id2) => this._deleteNode(id2));
696
692
  node.remove();
697
693
  }
698
- deleteElement(id) {
699
- this.transact(() => this._deleteElement(id));
694
+ deleteNode(id) {
695
+ this.transact(() => this._deleteNode(id));
696
+ }
697
+ getNode(id) {
698
+ return this._nodeMap.get(id);
700
699
  }
701
- moveElement(id, toIndex) {
702
- const node = this.nodeMap.get(id);
700
+ moveNode(id, toIndex) {
701
+ const node = this._nodeMap.get(id);
703
702
  if (!node) {
704
703
  return;
705
704
  }
@@ -801,7 +800,7 @@ class Doc extends Model {
801
800
  if (action.insert) {
802
801
  const ids = Array.isArray(action.insert) ? action.insert : [action.insert];
803
802
  ids.forEach((id, index) => {
804
- let child = this.nodeMap.get(id);
803
+ let child = this._nodeMap.get(id);
805
804
  const cb = (child2) => {
806
805
  node.moveChild(child2, retain + index);
807
806
  };
@@ -809,7 +808,7 @@ class Doc extends Model {
809
808
  cb(child);
810
809
  } else {
811
810
  setTimeout(() => {
812
- child = this.nodeMap.get(id);
811
+ child = this._nodeMap.get(id);
813
812
  child && cb(child);
814
813
  }, 0);
815
814
  }
@@ -853,7 +852,7 @@ class Doc extends Model {
853
852
  }
854
853
  _getOrCreateNode(yNode) {
855
854
  const id = yNode.get("id");
856
- let node = this.nodeMap.get(id);
855
+ let node = this._nodeMap.get(id);
857
856
  if (!node) {
858
857
  this.undoManager.addToScope(yNode);
859
858
  node = reactive(
@@ -864,7 +863,7 @@ class Doc extends Model {
864
863
  })
865
864
  );
866
865
  this._proxyNode(node, yNode);
867
- this.nodeMap.set(id, node);
866
+ this._nodeMap.set(id, node);
868
867
  }
869
868
  return node;
870
869
  }
@@ -897,6 +896,8 @@ const _0_context = defineMixin((editor) => {
897
896
  renderEngine.value.start();
898
897
  const drawboardDom = ref();
899
898
  const drawboardAabb = ref({ left: 0, top: 0, width: 0, height: 0 });
899
+ const drawboardPointer = ref();
900
+ const drawboardContextMenuPointer = ref();
900
901
  const doc = ref(new Doc());
901
902
  const root = computed(() => doc.value.root);
902
903
  const nodes = ref([]);
@@ -908,7 +909,6 @@ const _0_context = defineMixin((editor) => {
908
909
  });
909
910
  const textSelection = ref();
910
911
  const hoverElement = ref();
911
- const drawboardPointer = ref();
912
912
  const state = ref();
913
913
  function setCursor(mode) {
914
914
  renderEngine.value.input.setCursor(mode);
@@ -978,9 +978,10 @@ const _0_context = defineMixin((editor) => {
978
978
  hoverElement,
979
979
  drawboardDom,
980
980
  drawboardAabb,
981
+ drawboardPointer,
982
+ drawboardContextMenuPointer,
981
983
  state,
982
984
  setCursor,
983
- drawboardPointer,
984
985
  getGlobalPointer,
985
986
  parseAnchor,
986
987
  isNode,
@@ -1066,6 +1067,7 @@ const _0_font = defineMixin((editor, options) => {
1066
1067
  });
1067
1068
  const en = {
1068
1069
  "cancel": "Cancel",
1070
+ "create": "Create",
1069
1071
  "constrainToAxis": "Constrain to axis",
1070
1072
  "loading": "Loading",
1071
1073
  "drawing": "Drawing",
@@ -1104,6 +1106,7 @@ const en = {
1104
1106
  "saveAs:pdf": "Save as PDF",
1105
1107
  "saveAs:pptx": "Save as PPTX",
1106
1108
  "saveAs:json": "Save as JSON",
1109
+ "addSubNode": "Add sub node",
1107
1110
  "edit": "Edit",
1108
1111
  "undo": "Undo",
1109
1112
  "redo": "Redo",
@@ -1132,6 +1135,8 @@ const en = {
1132
1135
  "panels:layers": "Open layers panel",
1133
1136
  "panels:timeline": "Open timeline panel",
1134
1137
  "panels:statusbar": "Open statusbar panel",
1138
+ "panels:nodeCreator": "Open node creator panel",
1139
+ "nodeCreator": "Create node",
1135
1140
  "toolbelt": "Toolbelt",
1136
1141
  "msaa": "MSAA",
1137
1142
  "pixelate": "Pixelate",
@@ -1166,6 +1171,7 @@ const en = {
1166
1171
  };
1167
1172
  const zhHans = {
1168
1173
  "cancel": "取消",
1174
+ "create": "创建",
1169
1175
  "constrainToAxis": "约束到轴",
1170
1176
  "loading": "加载中...",
1171
1177
  "drawing": "绘制中...",
@@ -1205,6 +1211,7 @@ const zhHans = {
1205
1211
  "saveAs:pdf": "另存为 PDF",
1206
1212
  "saveAs:pptx": "另存为 PPTX",
1207
1213
  "saveAs:json": "另存为 JSON",
1214
+ "addSubNode": "添加子节点",
1208
1215
  "edit": "编辑",
1209
1216
  "undo": "撤销",
1210
1217
  "redo": "重做",
@@ -1233,6 +1240,8 @@ const zhHans = {
1233
1240
  "panels:layers": "打开图层面板",
1234
1241
  "panels:statusbar": "打开状态栏面板",
1235
1242
  "panels:timeline": "打开时间线面板",
1243
+ "panels:nodeCreator": "打开节点创建面板",
1244
+ "nodeCreator": "创建节点",
1236
1245
  "toolbelt": "工具腰带",
1237
1246
  "msaa": "抗锯齿",
1238
1247
  "pixelate": "像素化",
@@ -2284,7 +2293,33 @@ const _3_view = defineMixin((editor) => {
2284
2293
  on("setDoc", onViewMode);
2285
2294
  };
2286
2295
  });
2287
- const _4_0_text = defineMixin((editor) => {
2296
+ const _4_0_node = defineMixin((editor) => {
2297
+ const {
2298
+ doc,
2299
+ selection
2300
+ } = editor;
2301
+ function addNode(value, options = {}) {
2302
+ const {
2303
+ parent,
2304
+ index,
2305
+ active,
2306
+ regenId
2307
+ } = options;
2308
+ const node = doc.value.addNode(value, {
2309
+ parentId: parent?.id,
2310
+ index,
2311
+ regenId
2312
+ });
2313
+ if (active) {
2314
+ selection.value = [node];
2315
+ }
2316
+ return node;
2317
+ }
2318
+ Object.assign(editor, {
2319
+ addNode
2320
+ });
2321
+ });
2322
+ const _4_1_text = defineMixin((editor) => {
2288
2323
  const {
2289
2324
  isElement,
2290
2325
  config,
@@ -2620,7 +2655,7 @@ const _4_2_element = defineMixin((editor) => {
2620
2655
  const elements = doc.value.transact(() => {
2621
2656
  const values = isArray ? value : [value];
2622
2657
  const elements2 = values.map((element) => {
2623
- const el = doc.value.addElement(element, {
2658
+ const el = doc.value.addNode(element, {
2624
2659
  parentId: parent?.id,
2625
2660
  index: offsetIndex,
2626
2661
  regenId
@@ -2764,13 +2799,13 @@ const _4_2_element = defineMixin((editor) => {
2764
2799
  if (id === selection.value[0]?.id) {
2765
2800
  selection.value = [];
2766
2801
  }
2767
- doc.value.deleteElement(id);
2802
+ doc.value.deleteNode(id);
2768
2803
  }
2769
2804
  function updateElement(id, properties) {
2770
2805
  getElement(id)?.setProperties(properties);
2771
2806
  }
2772
2807
  function getElement(id) {
2773
- return doc.value.nodeMap.get(id);
2808
+ return doc.value.getNode(id);
2774
2809
  }
2775
2810
  function resizeElement(element, scaleX, scaleY, options = {}) {
2776
2811
  scaleX = Math.abs(scaleX);
@@ -2841,7 +2876,7 @@ const _4_3_frame = defineMixin((editor) => {
2841
2876
  element.style.width ||= rootAabb.value.width;
2842
2877
  element.style.height ||= rootAabb.value.height;
2843
2878
  const index = toIndex ?? (currentFrameIndex.value > -1 ? currentFrameIndex.value + 1 : frames.value.length - 1);
2844
- doc.value.addElement(element, { index });
2879
+ doc.value.addNode(element, { index });
2845
2880
  setCurrentFrame(index);
2846
2881
  emit("addFrame", index);
2847
2882
  }
@@ -2849,7 +2884,7 @@ const _4_3_frame = defineMixin((editor) => {
2849
2884
  const page = root.value.children[index];
2850
2885
  if (!page)
2851
2886
  return;
2852
- doc.value.addElement(page.toJSON(), {
2887
+ doc.value.addNode(page.toJSON(), {
2853
2888
  index: index + 1,
2854
2889
  regenId: true
2855
2890
  });
@@ -2859,7 +2894,7 @@ const _4_3_frame = defineMixin((editor) => {
2859
2894
  const id = root.value.children[fromIndex]?.id;
2860
2895
  if (!id)
2861
2896
  return;
2862
- doc.value.moveElement(id, toIndex);
2897
+ doc.value.moveNode(id, toIndex);
2863
2898
  frameThumbs.value.splice(
2864
2899
  toIndex,
2865
2900
  0,
@@ -2875,7 +2910,7 @@ const _4_3_frame = defineMixin((editor) => {
2875
2910
  const id = root.value.children[index]?.id;
2876
2911
  if (!id)
2877
2912
  return;
2878
- doc.value.deleteElement(id);
2913
+ doc.value.deleteNode(id);
2879
2914
  frameThumbs.value.splice(index, 1);
2880
2915
  setCurrentFrame(index);
2881
2916
  emit("deleteFrame", index);
@@ -3352,7 +3387,8 @@ const mixins = [
3352
3387
  _2_export,
3353
3388
  _2_load,
3354
3389
  _3_view,
3355
- _4_0_text,
3390
+ _4_0_node,
3391
+ _4_1_text,
3356
3392
  _4_2_element,
3357
3393
  _4_3_frame,
3358
3394
  _4_4_doc,
@@ -3609,11 +3645,11 @@ const _delete = definePlugin((editor) => {
3609
3645
  ]
3610
3646
  };
3611
3647
  });
3612
- const _hoisted_1$m = {
3648
+ const _hoisted_1$n = {
3613
3649
  key: 0,
3614
3650
  class: "mce-drawing__tip"
3615
3651
  };
3616
- const _sfc_main$C = /* @__PURE__ */ defineComponent({
3652
+ const _sfc_main$D = /* @__PURE__ */ defineComponent({
3617
3653
  __name: "Drawing",
3618
3654
  setup(__props) {
3619
3655
  const {
@@ -3631,7 +3667,7 @@ const _sfc_main$C = /* @__PURE__ */ defineComponent({
3631
3667
  top: `${unref(drawboardPointer).y}px`
3632
3668
  })
3633
3669
  }, [
3634
- unref(activeDrawingTool)?.name ? (openBlock(), createElementBlock("div", _hoisted_1$m, toDisplayString(unref(t)(unref(activeDrawingTool).name)), 1)) : createCommentVNode("", true)
3670
+ unref(activeDrawingTool)?.name ? (openBlock(), createElementBlock("div", _hoisted_1$n, toDisplayString(unref(t)(unref(activeDrawingTool).name)), 1)) : createCommentVNode("", true)
3635
3671
  ], 4)) : createCommentVNode("", true);
3636
3672
  };
3637
3673
  }
@@ -3643,7 +3679,7 @@ const _drawingTool = definePlugin((editor) => {
3643
3679
  return {
3644
3680
  name: "mce:drawingTool",
3645
3681
  components: [
3646
- { name: "drawing", type: "overlay", component: _sfc_main$C }
3682
+ { name: "drawing", type: "overlay", component: _sfc_main$D }
3647
3683
  ],
3648
3684
  commands: [
3649
3685
  { command: "setActiveDrawingTool", handle: (val) => setActiveDrawingTool(val) }
@@ -3700,7 +3736,7 @@ const ComponentIcon = defineComponent({
3700
3736
  };
3701
3737
  }
3702
3738
  });
3703
- const _sfc_main$B = /* @__PURE__ */ defineComponent({
3739
+ const _sfc_main$C = /* @__PURE__ */ defineComponent({
3704
3740
  __name: "Icon",
3705
3741
  props: {
3706
3742
  disabled: Boolean,
@@ -4282,7 +4318,7 @@ const defaultHoverStrategy = (context) => {
4282
4318
  }
4283
4319
  return element.findAncestor(cb);
4284
4320
  };
4285
- const _sfc_main$A = /* @__PURE__ */ defineComponent({
4321
+ const _sfc_main$B = /* @__PURE__ */ defineComponent({
4286
4322
  __name: "Frame",
4287
4323
  props: {
4288
4324
  "modelValue": { required: true },
@@ -4350,7 +4386,7 @@ const _sfc_main$A = /* @__PURE__ */ defineComponent({
4350
4386
  };
4351
4387
  }
4352
4388
  });
4353
- const _sfc_main$z = /* @__PURE__ */ defineComponent({
4389
+ const _sfc_main$A = /* @__PURE__ */ defineComponent({
4354
4390
  __name: "Frames",
4355
4391
  setup(__props) {
4356
4392
  const {
@@ -4358,7 +4394,7 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
4358
4394
  } = useEditor();
4359
4395
  return (_ctx, _cache) => {
4360
4396
  return openBlock(true), createElementBlock(Fragment, null, renderList(unref(frames), (frame, key) => {
4361
- return openBlock(), createBlock(_sfc_main$A, {
4397
+ return openBlock(), createBlock(_sfc_main$B, {
4362
4398
  key,
4363
4399
  "model-value": frame
4364
4400
  }, null, 8, ["model-value"]);
@@ -4375,7 +4411,7 @@ const _frame = definePlugin((editor) => {
4375
4411
  return {
4376
4412
  name: "mce:frame",
4377
4413
  components: [
4378
- { type: "overlay", component: _sfc_main$z }
4414
+ { type: "overlay", component: _sfc_main$A }
4379
4415
  ],
4380
4416
  drawingTools: [
4381
4417
  {
@@ -4567,8 +4603,8 @@ const _history = definePlugin((editor) => {
4567
4603
  ]
4568
4604
  };
4569
4605
  });
4570
- const _hoisted_1$l = ["data-name"];
4571
- const _sfc_main$y = /* @__PURE__ */ defineComponent({
4606
+ const _hoisted_1$m = ["data-name"];
4607
+ const _sfc_main$z = /* @__PURE__ */ defineComponent({
4572
4608
  __name: "Hover",
4573
4609
  setup(__props) {
4574
4610
  const {
@@ -4588,7 +4624,7 @@ const _sfc_main$y = /* @__PURE__ */ defineComponent({
4588
4624
  borderRadius: `${(unref(hoverElement).style.borderRadius ?? 0) * unref(camera).zoom.x}px`,
4589
4625
  ...unref(boundingBoxToStyle)(hoverElementObb.value)
4590
4626
  })
4591
- }, null, 12, _hoisted_1$l)) : createCommentVNode("", true);
4627
+ }, null, 12, _hoisted_1$m)) : createCommentVNode("", true);
4592
4628
  };
4593
4629
  }
4594
4630
  });
@@ -4596,7 +4632,7 @@ const _hover = definePlugin(() => {
4596
4632
  return {
4597
4633
  name: "mce:hover",
4598
4634
  components: [
4599
- { type: "overlay", component: _sfc_main$y }
4635
+ { type: "overlay", component: _sfc_main$z }
4600
4636
  ]
4601
4637
  };
4602
4638
  });
@@ -5001,16 +5037,18 @@ const _layerPosition = definePlugin((editor) => {
5001
5037
  ]
5002
5038
  };
5003
5039
  });
5004
- const _sfc_main$x = /* @__PURE__ */ defineComponent({
5040
+ const _sfc_main$y = /* @__PURE__ */ defineComponent({
5005
5041
  __name: "Btn",
5006
5042
  props: {
5007
- active: { type: Boolean }
5043
+ active: { type: Boolean },
5044
+ icon: { type: Boolean }
5008
5045
  },
5009
5046
  setup(__props) {
5010
5047
  return (_ctx, _cache) => {
5011
5048
  return openBlock(), createElementBlock("div", {
5012
5049
  class: normalizeClass(["mce-btn", {
5013
- "mce-btn--active": __props.active
5050
+ "mce-btn--active": __props.active,
5051
+ "mce-btn--icon": __props.icon
5014
5052
  }])
5015
5053
  }, [
5016
5054
  renderSlot(_ctx.$slots, "default")
@@ -5018,9 +5056,9 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
5018
5056
  };
5019
5057
  }
5020
5058
  });
5021
- const _hoisted_1$k = { class: "mce-layer__name" };
5022
- const _hoisted_2$b = { class: "mce-layer__action" };
5023
- const _sfc_main$w = /* @__PURE__ */ defineComponent({
5059
+ const _hoisted_1$l = { class: "mce-layer__name" };
5060
+ const _hoisted_2$c = { class: "mce-layer__action" };
5061
+ const _sfc_main$x = /* @__PURE__ */ defineComponent({
5024
5062
  ...{
5025
5063
  name: "MceLayer",
5026
5064
  inheritAttrs: false
@@ -5090,7 +5128,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
5090
5128
  const node = props.node;
5091
5129
  if (isFrame(node)) {
5092
5130
  return "$frame";
5093
- } else if (node.children.length) {
5131
+ } else if (node.children.filter(isElement).length) {
5094
5132
  return "$group";
5095
5133
  } else if (isElement(node)) {
5096
5134
  if (node.foreground.isValid() && node.foreground.image) {
@@ -5109,47 +5147,45 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
5109
5147
  }
5110
5148
  function onClickContent(e) {
5111
5149
  selecting.value = true;
5112
- if (isElement(props.node)) {
5113
- if (e.shiftKey) {
5114
- const _nodes = [
5115
- ...selection.value.filter((v) => !v.equal(props.node)),
5116
- props.node
5117
- ];
5118
- let min;
5119
- let max;
5120
- _nodes.forEach((el) => {
5121
- const index = nodeIndexMap.get(el.id);
5122
- if (index !== void 0) {
5123
- min = min === void 0 ? index : Math.min(min, index);
5124
- max = max === void 0 ? index : Math.max(max, index);
5150
+ if (e.shiftKey) {
5151
+ const _nodes = [
5152
+ ...selection.value.filter((v) => !v.equal(props.node)),
5153
+ props.node
5154
+ ];
5155
+ let min;
5156
+ let max;
5157
+ _nodes.forEach((el) => {
5158
+ const index = nodeIndexMap.get(el.id);
5159
+ if (index !== void 0) {
5160
+ min = min === void 0 ? index : Math.min(min, index);
5161
+ max = max === void 0 ? index : Math.max(max, index);
5162
+ }
5163
+ });
5164
+ if (min !== void 0 && max !== void 0) {
5165
+ let _selection = nodes.value.slice(min, max + 1);
5166
+ const result = new Set(_selection.map((node) => node.id));
5167
+ const parents = /* @__PURE__ */ new Set();
5168
+ _selection.forEach((node) => node.parent && parents.add(node.parent));
5169
+ parents.forEach((parent) => {
5170
+ if (parent.children.every((ch) => result.has(ch.id))) {
5171
+ const ids = new Set(parent.children.map((ch) => ch.id));
5172
+ _selection = [
5173
+ ..._selection.filter((v) => !ids.has(v.id)),
5174
+ parent
5175
+ ];
5125
5176
  }
5126
5177
  });
5127
- if (min !== void 0 && max !== void 0) {
5128
- let _selection = nodes.value.slice(min, max + 1);
5129
- const result = new Set(_selection.map((node) => node.id));
5130
- const parents = /* @__PURE__ */ new Set();
5131
- _selection.forEach((node) => node.parent && parents.add(node.parent));
5132
- parents.forEach((parent) => {
5133
- if (parent.children.every((ch) => result.has(ch.id))) {
5134
- const ids = new Set(parent.children.map((ch) => ch.id));
5135
- _selection = [
5136
- ..._selection.filter((v) => !ids.has(v.id)),
5137
- parent
5138
- ];
5139
- }
5140
- });
5141
- selection.value = _selection;
5142
- }
5143
- } else if (e.ctrlKey || e.metaKey) {
5144
- const filtered = selection.value.filter((v) => !v.equal(props.node));
5145
- if (filtered.length !== selection.value.length) {
5146
- selection.value = filtered;
5147
- } else {
5148
- selection.value = [...filtered, props.node];
5149
- }
5178
+ selection.value = _selection;
5179
+ }
5180
+ } else if (e.ctrlKey || e.metaKey) {
5181
+ const filtered = selection.value.filter((v) => !v.equal(props.node));
5182
+ if (filtered.length !== selection.value.length) {
5183
+ selection.value = filtered;
5150
5184
  } else {
5151
- selection.value = [props.node];
5185
+ selection.value = [...filtered, props.node];
5152
5186
  }
5187
+ } else {
5188
+ selection.value = [props.node];
5153
5189
  }
5154
5190
  nextTick().then(() => {
5155
5191
  selecting.value = false;
@@ -5185,12 +5221,10 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
5185
5221
  hovering.value = false;
5186
5222
  }
5187
5223
  function onContextmenu(e) {
5188
- if (isElement(props.node)) {
5189
- if (!selection.value.some((v) => v.equal(props.node))) {
5190
- selection.value = [props.node];
5191
- }
5192
- exec("openContextMenu", e);
5224
+ if (!selection.value.some((v) => v.equal(props.node))) {
5225
+ selection.value = [props.node];
5193
5226
  }
5227
+ exec("openContextMenu", e);
5194
5228
  }
5195
5229
  function onInputBlur() {
5196
5230
  editing.value = false;
@@ -5225,7 +5259,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
5225
5259
  class: "mce-layer__expand",
5226
5260
  onClick: onClickExpand
5227
5261
  }, [
5228
- props.node.children.length ? (openBlock(), createBlock(unref(_sfc_main$B), {
5262
+ props.node.children.length ? (openBlock(), createBlock(unref(_sfc_main$C), {
5229
5263
  key: 0,
5230
5264
  icon: "$arrowRight"
5231
5265
  })) : createCommentVNode("", true)
@@ -5239,9 +5273,9 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
5239
5273
  class: "mce-layer__thumbnail",
5240
5274
  onDblclick: onDblclickThumbnail
5241
5275
  }, [
5242
- createVNode(unref(_sfc_main$B), { icon: thumbnailIcon.value }, null, 8, ["icon"])
5276
+ createVNode(unref(_sfc_main$C), { icon: thumbnailIcon.value }, null, 8, ["icon"])
5243
5277
  ], 32),
5244
- createElementVNode("div", _hoisted_1$k, [
5278
+ createElementVNode("div", _hoisted_1$l, [
5245
5279
  withDirectives(createElementVNode("input", {
5246
5280
  ref_key: "inputDom",
5247
5281
  ref: inputDom,
@@ -5258,42 +5292,45 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
5258
5292
  style: normalizeStyle({ visibility: editing.value ? "hidden" : void 0 })
5259
5293
  }, toDisplayString(editValue.value || props.node.name || props.node.id), 5)
5260
5294
  ]),
5261
- createElementVNode("div", _hoisted_2$b, [
5262
- props.root ? (openBlock(), createBlock(_sfc_main$x, {
5295
+ createElementVNode("div", _hoisted_2$c, [
5296
+ props.root ? (openBlock(), createBlock(_sfc_main$y, {
5263
5297
  key: 0,
5298
+ icon: "",
5264
5299
  class: normalizeClass(["mce-layer__btn", {
5265
5300
  "mce-layer__btn--hide": !hovering.value && !unref(isLock)(props.node)
5266
5301
  }]),
5267
5302
  onClick: _cache[1] || (_cache[1] = ($event) => unref(setLock)(props.node, !unref(isLock)(props.node)))
5268
5303
  }, {
5269
5304
  default: withCtx(() => [
5270
- createVNode(unref(_sfc_main$B), {
5305
+ createVNode(unref(_sfc_main$C), {
5271
5306
  icon: unref(isLock)(props.node) ? "$lock" : "$unlock"
5272
5307
  }, null, 8, ["icon"])
5273
5308
  ]),
5274
5309
  _: 1
5275
5310
  }, 8, ["class"])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
5276
- createVNode(_sfc_main$x, {
5311
+ createVNode(_sfc_main$y, {
5312
+ icon: "",
5277
5313
  class: normalizeClass(["mce-layer__btn", {
5278
5314
  "mce-layer__btn--hide": !hovering.value && !unref(isLock)(props.node)
5279
5315
  }]),
5280
5316
  onClick: _cache[2] || (_cache[2] = withModifiers(($event) => unref(setLock)(props.node, !unref(isLock)(props.node)), ["prevent", "stop"]))
5281
5317
  }, {
5282
5318
  default: withCtx(() => [
5283
- createVNode(unref(_sfc_main$B), {
5319
+ createVNode(unref(_sfc_main$C), {
5284
5320
  icon: unref(isLock)(props.node) ? "$lock" : "$unlock"
5285
5321
  }, null, 8, ["icon"])
5286
5322
  ]),
5287
5323
  _: 1
5288
5324
  }, 8, ["class"]),
5289
- createVNode(_sfc_main$x, {
5325
+ createVNode(_sfc_main$y, {
5326
+ icon: "",
5290
5327
  class: normalizeClass(["mce-layer__btn", {
5291
5328
  "mce-layer__btn--hide": !hovering.value && unref(isVisible)(props.node)
5292
5329
  }]),
5293
5330
  onClick: _cache[3] || (_cache[3] = withModifiers(($event) => unref(setVisible)(props.node, !unref(isVisible)(props.node)), ["prevent", "stop"]))
5294
5331
  }, {
5295
5332
  default: withCtx(() => [
5296
- createVNode(unref(_sfc_main$B), {
5333
+ createVNode(unref(_sfc_main$C), {
5297
5334
  icon: unref(isVisible)(props.node) ? "$visible" : "$unvisible"
5298
5335
  }, null, 8, ["icon"])
5299
5336
  ]),
@@ -5315,9 +5352,9 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
5315
5352
  };
5316
5353
  }
5317
5354
  });
5318
- const _hoisted_1$j = { class: "mce-layers" };
5319
- const _hoisted_2$a = { class: "mce-layers__wrapper" };
5320
- const _sfc_main$v = /* @__PURE__ */ defineComponent({
5355
+ const _hoisted_1$k = { class: "mce-layers" };
5356
+ const _hoisted_2$b = { class: "mce-layers__wrapper" };
5357
+ const _sfc_main$w = /* @__PURE__ */ defineComponent({
5321
5358
  __name: "Layers",
5322
5359
  setup(__props) {
5323
5360
  const {
@@ -5365,9 +5402,9 @@ const _sfc_main$v = /* @__PURE__ */ defineComponent({
5365
5402
  }
5366
5403
  });
5367
5404
  return (_ctx, _cache) => {
5368
- return openBlock(), createElementBlock("div", _hoisted_1$j, [
5369
- createElementVNode("div", _hoisted_2$a, [
5370
- createVNode(_sfc_main$w, {
5405
+ return openBlock(), createElementBlock("div", _hoisted_1$k, [
5406
+ createElementVNode("div", _hoisted_2$b, [
5407
+ createVNode(_sfc_main$x, {
5371
5408
  root: true,
5372
5409
  node: unref(root),
5373
5410
  opened: true
@@ -5381,7 +5418,7 @@ const _layers = definePlugin(() => {
5381
5418
  return {
5382
5419
  name: "mce:layers",
5383
5420
  components: [
5384
- { name: "layers", type: "panel", position: "float", component: _sfc_main$v }
5421
+ { name: "layers", type: "panel", position: "float", component: _sfc_main$w }
5385
5422
  ]
5386
5423
  };
5387
5424
  });
@@ -5410,19 +5447,19 @@ const _export_sfc = (sfc, props) => {
5410
5447
  }
5411
5448
  return target;
5412
5449
  };
5413
- const _sfc_main$u = {};
5414
- const _hoisted_1$i = {
5450
+ const _sfc_main$v = {};
5451
+ const _hoisted_1$j = {
5415
5452
  class: "mce-made-with",
5416
5453
  href: "https://github.com/qq15725/mce",
5417
5454
  target: "_blank"
5418
5455
  };
5419
5456
  function _sfc_render(_ctx, _cache) {
5420
- return openBlock(), createElementBlock("a", _hoisted_1$i, [..._cache[0] || (_cache[0] = [
5457
+ return openBlock(), createElementBlock("a", _hoisted_1$j, [..._cache[0] || (_cache[0] = [
5421
5458
  createElementVNode("div", null, "MADE WITH", -1),
5422
5459
  createElementVNode("div", null, "MCE", -1)
5423
5460
  ])]);
5424
5461
  }
5425
- const MadeWith = /* @__PURE__ */ _export_sfc(_sfc_main$u, [["render", _sfc_render]]);
5462
+ const MadeWith = /* @__PURE__ */ _export_sfc(_sfc_main$v, [["render", _sfc_render]]);
5426
5463
  const _madeWith = definePlugin((editor) => {
5427
5464
  const {
5428
5465
  config,
@@ -5440,7 +5477,7 @@ const _madeWith = definePlugin((editor) => {
5440
5477
  ]
5441
5478
  };
5442
5479
  });
5443
- const _sfc_main$t = /* @__PURE__ */ defineComponent({
5480
+ const _sfc_main$u = /* @__PURE__ */ defineComponent({
5444
5481
  ...{
5445
5482
  inheritAttrs: false
5446
5483
  },
@@ -5556,9 +5593,9 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
5556
5593
  };
5557
5594
  }
5558
5595
  });
5559
- const _hoisted_1$h = ["onMouseenter"];
5560
- const _hoisted_2$9 = ["onClick"];
5561
- const _hoisted_3$9 = {
5596
+ const _hoisted_1$i = ["onMouseenter"];
5597
+ const _hoisted_2$a = ["onClick"];
5598
+ const _hoisted_3$a = {
5562
5599
  key: 0,
5563
5600
  class: "mce-list-item__checked"
5564
5601
  };
@@ -5575,7 +5612,7 @@ const _hoisted_7$3 = {
5575
5612
  key: 3,
5576
5613
  class: "mce-list-item__append"
5577
5614
  };
5578
- const _sfc_main$s = /* @__PURE__ */ defineComponent({
5615
+ const _sfc_main$t = /* @__PURE__ */ defineComponent({
5579
5616
  ...{
5580
5617
  name: "MceMenu"
5581
5618
  },
@@ -5656,7 +5693,7 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
5656
5693
  });
5657
5694
  return (_ctx, _cache) => {
5658
5695
  const _component_MceMenu = resolveComponent("MceMenu");
5659
- return openBlock(), createBlock(_sfc_main$t, {
5696
+ return openBlock(), createBlock(_sfc_main$u, {
5660
5697
  ref: "overlayTpl",
5661
5698
  modelValue: isActive.value,
5662
5699
  "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isActive.value = $event),
@@ -5702,8 +5739,8 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
5702
5739
  ]]),
5703
5740
  onClick: (e) => onClickItem(item, index, e)
5704
5741
  }, [
5705
- hasPrepend.value ? (openBlock(), createElementBlock("div", _hoisted_3$9, [
5706
- item.checked ? (openBlock(), createBlock(unref(_sfc_main$B), {
5742
+ hasPrepend.value ? (openBlock(), createElementBlock("div", _hoisted_3$a, [
5743
+ item.checked ? (openBlock(), createBlock(unref(_sfc_main$C), {
5707
5744
  key: 0,
5708
5745
  icon: "$check"
5709
5746
  })) : createCommentVNode("", true)
@@ -5721,13 +5758,13 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
5721
5758
  ])) : createCommentVNode("", true),
5722
5759
  item.children?.length || _ctx.$slots.append ? (openBlock(), createElementBlock("div", _hoisted_7$3, [
5723
5760
  renderSlot(_ctx.$slots, "append", { item }),
5724
- item.children?.length ? (openBlock(), createBlock(unref(_sfc_main$B), {
5761
+ item.children?.length ? (openBlock(), createBlock(unref(_sfc_main$C), {
5725
5762
  key: 0,
5726
5763
  icon: "$arrowRight"
5727
5764
  })) : createCommentVNode("", true)
5728
5765
  ])) : createCommentVNode("", true)
5729
- ], 10, _hoisted_2$9)
5730
- ], 40, _hoisted_1$h))
5766
+ ], 10, _hoisted_2$a)
5767
+ ], 40, _hoisted_1$i))
5731
5768
  ], 64);
5732
5769
  }), 128)),
5733
5770
  opened.value > -1 && __props.items?.[opened.value]?.children?.length ? (openBlock(), createBlock(_component_MceMenu, {
@@ -5778,7 +5815,7 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
5778
5815
  };
5779
5816
  }
5780
5817
  });
5781
- const _sfc_main$r = /* @__PURE__ */ defineComponent({
5818
+ const _sfc_main$s = /* @__PURE__ */ defineComponent({
5782
5819
  __name: "ContextMenu",
5783
5820
  props: {
5784
5821
  "modelValue": { type: Boolean },
@@ -5793,6 +5830,7 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
5793
5830
  const {
5794
5831
  drawboardDom,
5795
5832
  drawboardAabb,
5833
+ drawboardContextMenuPointer,
5796
5834
  contextMenu,
5797
5835
  exec,
5798
5836
  getKbd,
@@ -5801,7 +5839,7 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
5801
5839
  registerCommand,
5802
5840
  unregisterCommand
5803
5841
  } = useEditor();
5804
- const model = useModel(__props, "modelValue");
5842
+ const isActive = useModel(__props, "modelValue");
5805
5843
  const position = useModel(__props, "position");
5806
5844
  const menuRef = useTemplateRef("menuTplRef");
5807
5845
  onBeforeMount(() => {
@@ -5810,15 +5848,24 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
5810
5848
  onBeforeUnmount(() => {
5811
5849
  unregisterCommand("openContextMenu");
5812
5850
  });
5851
+ watch(isActive, (isActive2) => {
5852
+ if (!isActive2) {
5853
+ drawboardContextMenuPointer.value = void 0;
5854
+ }
5855
+ });
5813
5856
  function updateLocation() {
5814
5857
  menuRef.value?.updateLocation();
5815
5858
  }
5816
- function onContextmenu(e) {
5817
- e.preventDefault();
5818
- model.value = true;
5859
+ function onContextmenu(event) {
5860
+ event.preventDefault();
5861
+ isActive.value = true;
5819
5862
  position.value = {
5820
- x: e.clientX,
5821
- y: e.clientY
5863
+ x: event.clientX,
5864
+ y: event.clientY
5865
+ };
5866
+ drawboardContextMenuPointer.value = {
5867
+ x: event.clientX - drawboardAabb.value.left,
5868
+ y: event.clientY - drawboardAabb.value.top
5822
5869
  };
5823
5870
  updateLocation();
5824
5871
  }
@@ -5836,10 +5883,10 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
5836
5883
  updateLocation
5837
5884
  });
5838
5885
  return (_ctx, _cache) => {
5839
- return openBlock(), createBlock(_sfc_main$s, {
5886
+ return openBlock(), createBlock(_sfc_main$t, {
5840
5887
  ref: "menuTplRef",
5841
- modelValue: model.value,
5842
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => model.value = $event),
5888
+ modelValue: isActive.value,
5889
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isActive.value = $event),
5843
5890
  offset: 10,
5844
5891
  class: "mce-context-menu",
5845
5892
  target: position.value,
@@ -5871,7 +5918,8 @@ const _menu = definePlugin((editor, options) => {
5871
5918
  textSelection,
5872
5919
  config,
5873
5920
  exporters,
5874
- pluginsComponents
5921
+ pluginsComponents,
5922
+ isElement
5875
5923
  } = editor;
5876
5924
  const {
5877
5925
  customContextMenu
@@ -5900,6 +5948,9 @@ const _menu = definePlugin((editor, options) => {
5900
5948
  disabled: !hasSelected.value,
5901
5949
  children: [...exporters.values()].filter((v) => Boolean(v.copyAs)).map((v) => ({ key: `copyAs:${v.name}` }))
5902
5950
  }));
5951
+ const nodeMenu = computed(() => [
5952
+ { key: "addSubNode" }
5953
+ ]);
5903
5954
  const editMenus1 = computed(() => [
5904
5955
  { key: "copy", disabled: !hasSelected.value },
5905
5956
  copyAsMenu.value.children.length && copyAsMenu.value,
@@ -6070,8 +6121,10 @@ const _menu = definePlugin((editor, options) => {
6070
6121
  return [
6071
6122
  ...editMenus1.value
6072
6123
  ];
6073
- } else {
6124
+ } else if (selection.value.filter(isElement).length > 0) {
6074
6125
  return [
6126
+ ...nodeMenu.value,
6127
+ { type: "divider" },
6075
6128
  ...editMenus1.value,
6076
6129
  { type: "divider" },
6077
6130
  ...objectMenu1.value,
@@ -6084,6 +6137,12 @@ const _menu = definePlugin((editor, options) => {
6084
6137
  { type: "divider" },
6085
6138
  exportMenu.value
6086
6139
  ];
6140
+ } else {
6141
+ return [
6142
+ ...nodeMenu.value,
6143
+ { type: "divider" },
6144
+ ...editMenus1.value
6145
+ ];
6087
6146
  }
6088
6147
  } else {
6089
6148
  return [
@@ -6106,7 +6165,7 @@ const _menu = definePlugin((editor, options) => {
6106
6165
  return {
6107
6166
  name: "mce:menu",
6108
6167
  components: [
6109
- { type: "overlay", component: _sfc_main$r }
6168
+ { type: "overlay", component: _sfc_main$s }
6110
6169
  ]
6111
6170
  };
6112
6171
  });
@@ -6170,6 +6229,135 @@ const _new = definePlugin((editor) => {
6170
6229
  ]
6171
6230
  };
6172
6231
  });
6232
+ const _hoisted_1$h = { class: "mce-node-creator" };
6233
+ const _hoisted_2$9 = { class: "mce-node-creator__tree" };
6234
+ const _hoisted_3$9 = { class: "mce-node-creator__actions" };
6235
+ const _sfc_main$r = /* @__PURE__ */ defineComponent({
6236
+ __name: "NodeCreator",
6237
+ props: {
6238
+ "isActive": { type: Boolean },
6239
+ "isActiveModifiers": {}
6240
+ },
6241
+ emits: ["update:isActive"],
6242
+ setup(__props) {
6243
+ const {
6244
+ t,
6245
+ addNode,
6246
+ selection
6247
+ } = useEditor();
6248
+ const isActive = useModel(__props, "isActive");
6249
+ const activeNodeName = ref();
6250
+ const exclude = /* @__PURE__ */ new Set([
6251
+ "RenderTarget",
6252
+ "Window",
6253
+ "DrawboardEffect"
6254
+ ]);
6255
+ function buildInheritanceTree(classMap) {
6256
+ const nodes = /* @__PURE__ */ new Map();
6257
+ for (const [name, ctor] of classMap.entries()) {
6258
+ if (exclude.has(name)) {
6259
+ continue;
6260
+ }
6261
+ nodes.set(name, { ctor, name, children: [] });
6262
+ }
6263
+ const ctorToName = /* @__PURE__ */ new Map();
6264
+ for (const [name, ctor] of classMap.entries()) {
6265
+ ctorToName.set(ctor, name);
6266
+ }
6267
+ const roots = [];
6268
+ for (const [, node] of nodes.entries()) {
6269
+ const parentCtor = Object.getPrototypeOf(node.ctor.prototype)?.constructor;
6270
+ if (parentCtor && ctorToName.has(parentCtor)) {
6271
+ const parentName = ctorToName.get(parentCtor);
6272
+ const parentNode = nodes.get(parentName);
6273
+ parentNode.children.push(node);
6274
+ } else {
6275
+ roots.push(node);
6276
+ }
6277
+ }
6278
+ return roots;
6279
+ }
6280
+ const tree = computed(() => buildInheritanceTree(customNodes));
6281
+ function cancel() {
6282
+ isActive.value = false;
6283
+ }
6284
+ function create() {
6285
+ isActive.value = false;
6286
+ const name = activeNodeName.value;
6287
+ if (name) {
6288
+ addNode({
6289
+ name,
6290
+ meta: {
6291
+ inCanvasIs: name
6292
+ }
6293
+ }, {
6294
+ parent: selection.value[0],
6295
+ active: true
6296
+ });
6297
+ }
6298
+ }
6299
+ function Node2(props = {}) {
6300
+ const { indent = 0, node } = props;
6301
+ return [
6302
+ h("div", {
6303
+ class: [
6304
+ "mce-node-creator__node",
6305
+ activeNodeName.value === node.name && "mce-node-creator__node--active"
6306
+ ],
6307
+ style: {
6308
+ "--indent-padding": `${indent * 16}px`
6309
+ },
6310
+ onClick: () => activeNodeName.value = node.name
6311
+ }, node.name),
6312
+ ...node.children.map((node2) => {
6313
+ return h(Node2, { node: node2, indent: indent + 1 });
6314
+ })
6315
+ ];
6316
+ }
6317
+ return (_ctx, _cache) => {
6318
+ return openBlock(), createElementBlock("div", _hoisted_1$h, [
6319
+ createElementVNode("div", _hoisted_2$9, [
6320
+ (openBlock(true), createElementBlock(Fragment, null, renderList(tree.value, (node, index) => {
6321
+ return openBlock(), createBlock(Node2, {
6322
+ key: index,
6323
+ node
6324
+ }, null, 8, ["node"]);
6325
+ }), 128))
6326
+ ]),
6327
+ createElementVNode("div", _hoisted_3$9, [
6328
+ createVNode(_sfc_main$y, { onClick: cancel }, {
6329
+ default: withCtx(() => [
6330
+ createTextVNode(toDisplayString(unref(t)("cancel")), 1)
6331
+ ]),
6332
+ _: 1
6333
+ }),
6334
+ createVNode(_sfc_main$y, { onClick: create }, {
6335
+ default: withCtx(() => [
6336
+ createTextVNode(toDisplayString(unref(t)("create")), 1)
6337
+ ]),
6338
+ _: 1
6339
+ })
6340
+ ])
6341
+ ]);
6342
+ };
6343
+ }
6344
+ });
6345
+ const _node = definePlugin((editor) => {
6346
+ const {
6347
+ registerConfig,
6348
+ config
6349
+ } = editor;
6350
+ registerConfig("nodeCreator", false);
6351
+ return {
6352
+ name: "mce:node",
6353
+ components: [
6354
+ { name: "nodeCreator", type: "panel", position: "float", component: _sfc_main$r }
6355
+ ],
6356
+ commands: [
6357
+ { command: "addSubNode", handle: () => config.value.nodeCreator = true }
6358
+ ]
6359
+ };
6360
+ });
6173
6361
  const _open = definePlugin((editor) => {
6174
6362
  const {
6175
6363
  openFileDialog,
@@ -9751,19 +9939,17 @@ class Path2D extends CompositeCurve {
9751
9939
  return this;
9752
9940
  }
9753
9941
  addPath(path) {
9942
+ const curvePaths = path instanceof Path2D ? path.curves : [path];
9943
+ if (curvePaths.filter((curvePath) => curvePath.curves.length).length === 0) {
9944
+ return this;
9945
+ }
9754
9946
  if (!this.currentCurve.curves.length) {
9755
9947
  const index = this.curves.findIndex((v) => v === this.currentCurve);
9756
9948
  if (index > -1) {
9757
9949
  this.curves.splice(index, 1);
9758
9950
  }
9759
9951
  }
9760
- if (path instanceof Path2D) {
9761
- this.curves.push(
9762
- ...path.curves.filter((curvePath) => curvePath.curves.length).map((v) => v.clone())
9763
- );
9764
- } else if (path.curves.length) {
9765
- this.curves.push(path);
9766
- }
9952
+ this.curves.push(...curvePaths.map((v) => v.clone()));
9767
9953
  this.currentCurve = this.curves[this.curves.length - 1];
9768
9954
  return this;
9769
9955
  }
@@ -10243,7 +10429,7 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
10243
10429
  updateLocation
10244
10430
  });
10245
10431
  return (_ctx, _cache) => {
10246
- return openBlock(), createBlock(_sfc_main$t, {
10432
+ return openBlock(), createBlock(_sfc_main$u, {
10247
10433
  ref: "overlayTpl",
10248
10434
  modelValue: isActive.value,
10249
10435
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isActive.value = $event),
@@ -10850,7 +11036,7 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
10850
11036
  class: "mce-back-selected-aera",
10851
11037
  onClick: _cache[0] || (_cache[0] = withModifiers(($event) => unref(exec)("scrollToSelection", { behavior: "smooth" }), ["prevent"]))
10852
11038
  }, [
10853
- createVNode(unref(_sfc_main$B), { icon: "$gps" }),
11039
+ createVNode(unref(_sfc_main$C), { icon: "$gps" }),
10854
11040
  createElementVNode("span", null, toDisplayString(unref(t)("goBackSelectedArea")), 1)
10855
11041
  ])) : createCommentVNode("", true);
10856
11042
  };
@@ -12515,7 +12701,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
12515
12701
  ])
12516
12702
  ], 64)) : unref(state) === "transforming" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
12517
12703
  createElementVNode("div", _hoisted_8$1, [
12518
- createVNode(unref(_sfc_main$B), { icon: "$mouseRightClick" })
12704
+ createVNode(unref(_sfc_main$C), { icon: "$mouseRightClick" })
12519
12705
  ]),
12520
12706
  _cache[2] || (_cache[2] = createElementVNode("span", null, " / ", -1)),
12521
12707
  createElementVNode("div", _hoisted_9, [
@@ -12529,7 +12715,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
12529
12715
  ])
12530
12716
  ], 64)) : unref(state) ? (openBlock(), createElementBlock("span", _hoisted_13, toDisplayString(unref(t)(unref(state))), 1)) : (openBlock(), createElementBlock(Fragment, { key: 3 }, [
12531
12717
  createElementVNode("div", _hoisted_14, [
12532
- createVNode(unref(_sfc_main$B), { icon: "$mouseLeftClick" }),
12718
+ createVNode(unref(_sfc_main$C), { icon: "$mouseLeftClick" }),
12533
12719
  createElementVNode("span", null, toDisplayString(unref(t)("selectObject")), 1)
12534
12720
  ]),
12535
12721
  _cache[4] || (_cache[4] = createElementVNode("span", null, " + ", -1)),
@@ -12539,7 +12725,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
12539
12725
  ]),
12540
12726
  _cache[5] || (_cache[5] = createElementVNode("div", { class: "mce-statusbar__divider" }, null, -1)),
12541
12727
  createElementVNode("div", _hoisted_17, [
12542
- createVNode(unref(_sfc_main$B), { icon: "$mouseLeftClick" }),
12728
+ createVNode(unref(_sfc_main$C), { icon: "$mouseLeftClick" }),
12543
12729
  createElementVNode("span", null, toDisplayString(unref(t)("selectArea")), 1)
12544
12730
  ]),
12545
12731
  _cache[6] || (_cache[6] = createElementVNode("span", null, " + ", -1)),
@@ -12549,7 +12735,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
12549
12735
  ]),
12550
12736
  _cache[7] || (_cache[7] = createElementVNode("div", { class: "mce-statusbar__divider" }, null, -1)),
12551
12737
  createElementVNode("div", _hoisted_20, [
12552
- createVNode(unref(_sfc_main$B), { icon: "$mouseLeftClick" }),
12738
+ createVNode(unref(_sfc_main$C), { icon: "$mouseLeftClick" }),
12553
12739
  createElementVNode("span", null, toDisplayString(unref(t)("dragSelected")), 1)
12554
12740
  ])
12555
12741
  ], 64))
@@ -12855,7 +13041,7 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
12855
13041
  class: "mce-timeline__play",
12856
13042
  onClick: toggle
12857
13043
  }, [
12858
- createVNode(unref(_sfc_main$B), {
13044
+ createVNode(unref(_sfc_main$C), {
12859
13045
  icon: paused.value ? "$play" : "$pause"
12860
13046
  }, null, 8, ["icon"])
12861
13047
  ])
@@ -13059,14 +13245,15 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
13059
13245
  "show-arrow": ""
13060
13246
  }, {
13061
13247
  activator: withCtx(({ props: slotProps }) => [
13062
- createVNode(_sfc_main$x, mergeProps({
13248
+ createVNode(_sfc_main$y, mergeProps({
13249
+ icon: "",
13063
13250
  class: "mce-toolbelt__btn",
13064
13251
  active: tool.active || tool.checked || false
13065
13252
  }, { ref_for: true }, slotProps, {
13066
13253
  onClick: tool.handle
13067
13254
  }), {
13068
13255
  default: withCtx(() => [
13069
- createVNode(unref(_sfc_main$B), {
13256
+ createVNode(unref(_sfc_main$C), {
13070
13257
  icon: `$${tool.key}`
13071
13258
  }, null, 8, ["icon"])
13072
13259
  ]),
@@ -13081,16 +13268,19 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
13081
13268
  ]),
13082
13269
  _: 2
13083
13270
  }, 1024),
13084
- tool.children?.length ? (openBlock(), createBlock(_sfc_main$s, {
13271
+ tool.children?.length ? (openBlock(), createBlock(_sfc_main$t, {
13085
13272
  key: 0,
13086
13273
  items: tool.children,
13087
13274
  offset: 12,
13088
13275
  location: "top-start"
13089
13276
  }, {
13090
13277
  activator: withCtx(({ props }) => [
13091
- createVNode(_sfc_main$x, mergeProps({ class: "mce-toolbelt__arrow" }, { ref_for: true }, props), {
13278
+ createVNode(_sfc_main$y, mergeProps({
13279
+ icon: "",
13280
+ class: "mce-toolbelt__arrow"
13281
+ }, { ref_for: true }, props), {
13092
13282
  default: withCtx(() => [
13093
- createVNode(unref(_sfc_main$B), { icon: "$arrowDown" })
13283
+ createVNode(unref(_sfc_main$C), { icon: "$arrowDown" })
13094
13284
  ]),
13095
13285
  _: 1
13096
13286
  }, 16)
@@ -13106,7 +13296,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
13106
13296
  ], 64)) : createCommentVNode("", true)
13107
13297
  ]),
13108
13298
  prepend: withCtx(({ item }) => [
13109
- createVNode(unref(_sfc_main$B), {
13299
+ createVNode(unref(_sfc_main$C), {
13110
13300
  class: "mce-toolbelt__icon",
13111
13301
  icon: `$${item.key}`
13112
13302
  }, null, 8, ["icon"])
@@ -13303,6 +13493,7 @@ const plugins = [
13303
13493
  _menu,
13304
13494
  _move,
13305
13495
  _new,
13496
+ _node,
13306
13497
  _open,
13307
13498
  _panels,
13308
13499
  _pen,
@@ -13483,7 +13674,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
13483
13674
  setup(__props, { expose: __expose }) {
13484
13675
  const props = __props;
13485
13676
  const {
13486
- selection,
13677
+ elementSelection,
13487
13678
  selectionAabbInDrawboard,
13488
13679
  isFrame
13489
13680
  } = useEditor();
@@ -13503,7 +13694,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
13503
13694
  return {};
13504
13695
  });
13505
13696
  const offset2 = computed(() => {
13506
- if (selection.value.some((v) => isFrame(v)) || props.location?.startsWith("bottom")) {
13697
+ if (elementSelection.value.some((v) => isFrame(v)) || props.location?.startsWith("bottom")) {
13507
13698
  return 32;
13508
13699
  }
13509
13700
  return 8;
@@ -13516,7 +13707,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
13516
13707
  updateLocation
13517
13708
  });
13518
13709
  return (_ctx, _cache) => {
13519
- return openBlock(), createBlock(_sfc_main$t, {
13710
+ return openBlock(), createBlock(_sfc_main$u, {
13520
13711
  ref: "overlayTpl",
13521
13712
  style: normalizeStyle(style.value),
13522
13713
  class: "mce-floatbar",
@@ -13528,7 +13719,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
13528
13719
  "model-value": true
13529
13720
  }, {
13530
13721
  default: withCtx(() => [
13531
- unref(selection).length > 0 ? renderSlot(_ctx.$slots, "default", { key: 0 }) : createCommentVNode("", true)
13722
+ unref(elementSelection).length > 0 ? renderSlot(_ctx.$slots, "default", { key: 0 }) : createCommentVNode("", true)
13532
13723
  ]),
13533
13724
  _: 3
13534
13725
  }, 8, ["style", "location", "middlewares", "offset", "target"]);
@@ -14331,6 +14522,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
14331
14522
  isElement,
14332
14523
  state,
14333
14524
  resizeElement,
14525
+ selection,
14334
14526
  elementSelection,
14335
14527
  selectionObb,
14336
14528
  selectionObbInDrawboard,
@@ -14353,11 +14545,11 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
14353
14545
  unregisterCommand("startTransform");
14354
14546
  });
14355
14547
  const parentObbs = computed(() => {
14356
- if (elementSelection.value.length !== 1) {
14548
+ if (selection.value.length !== 1) {
14357
14549
  return [];
14358
14550
  }
14359
14551
  const obbs = [];
14360
- elementSelection.value[0]?.findAncestor((ancestor) => {
14552
+ selection.value[0]?.findAncestor((ancestor) => {
14361
14553
  if (isElement(ancestor)) {
14362
14554
  obbs.push(getObb(ancestor, "drawboard"));
14363
14555
  }
@@ -14571,6 +14763,9 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
14571
14763
  top: 60,
14572
14764
  ...props.defaultTransform
14573
14765
  });
14766
+ const defaultSlotProps = {
14767
+ isActive
14768
+ };
14574
14769
  return (_ctx, _cache) => {
14575
14770
  return openBlock(), createBlock(_sfc_main$a, {
14576
14771
  modelValue: transform.value,
@@ -14584,11 +14779,12 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
14584
14779
  createElementVNode("div", mergeProps({ class: "mce-float-panel__card" }, slotProps), [
14585
14780
  __props.title ? (openBlock(), createElementBlock("div", _hoisted_1$2, [
14586
14781
  createElementVNode("div", null, toDisplayString(__props.title), 1),
14587
- createVNode(_sfc_main$x, {
14782
+ createVNode(_sfc_main$y, {
14783
+ icon: "",
14588
14784
  onClick: _cache[0] || (_cache[0] = ($event) => isActive.value = false)
14589
14785
  }, {
14590
14786
  default: withCtx(() => [
14591
- createVNode(unref(_sfc_main$B), { icon: "$close" })
14787
+ createVNode(unref(_sfc_main$C), { icon: "$close" })
14592
14788
  ]),
14593
14789
  _: 1
14594
14790
  })
@@ -14598,7 +14794,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
14598
14794
  onPointerdown: _cache[1] || (_cache[1] = withModifiers(() => {
14599
14795
  }, ["stop"]))
14600
14796
  }, [
14601
- renderSlot(_ctx.$slots, "default")
14797
+ renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps(defaultSlotProps)))
14602
14798
  ], 32)
14603
14799
  ], 16)
14604
14800
  ]),
@@ -14864,6 +15060,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
14864
15060
  elementSelection,
14865
15061
  drawboardAabb,
14866
15062
  drawboardPointer,
15063
+ drawboardContextMenuPointer,
14867
15064
  screenCenterOffset,
14868
15065
  activeDrawingTool
14869
15066
  } = editor;
@@ -15217,27 +15414,6 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
15217
15414
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(pluginsComponents).overlay, (p, key) => {
15218
15415
  return openBlock(), createBlock(resolveDynamicComponent(p.component), { key });
15219
15416
  }), 128)),
15220
- (openBlock(true), createElementBlock(Fragment, null, renderList(unref(pluginsComponents).panel.filter((p) => p.position === "float"), (p, key) => {
15221
- return openBlock(), createElementBlock(Fragment, { key }, [
15222
- unref(config)[p.name] ? (openBlock(), createBlock(_sfc_main$6, {
15223
- key: 0,
15224
- modelValue: unref(config)[p.name],
15225
- "onUpdate:modelValue": ($event) => unref(config)[p.name] = $event,
15226
- title: unref(t)(p.name),
15227
- "default-transform": {
15228
- width: 240,
15229
- height: unref(drawboardAabb).height * 0.7,
15230
- top: unref(screenCenterOffset).top + 24,
15231
- left: unref(screenCenterOffset).left + 24
15232
- }
15233
- }, {
15234
- default: withCtx(() => [
15235
- (openBlock(), createBlock(resolveDynamicComponent(p.component)))
15236
- ]),
15237
- _: 2
15238
- }, 1032, ["modelValue", "onUpdate:modelValue", "title", "default-transform"])) : createCommentVNode("", true)
15239
- ], 64);
15240
- }), 128)),
15241
15417
  renderSlot(_ctx.$slots, "drawboard", normalizeProps(guardReactiveProps(slotProps)))
15242
15418
  ], 40, _hoisted_1)
15243
15419
  ]),
@@ -15261,6 +15437,30 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
15261
15437
  }, 1032, ["modelValue", "onUpdate:modelValue", "position", "size", "order"])) : createCommentVNode("", true)
15262
15438
  ], 64);
15263
15439
  }), 128)),
15440
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(pluginsComponents).panel.filter((p) => p.position === "float"), (p, key) => {
15441
+ return openBlock(), createElementBlock(Fragment, { key }, [
15442
+ unref(config)[p.name] ? (openBlock(), createBlock(_sfc_main$6, {
15443
+ key: 0,
15444
+ modelValue: unref(config)[p.name],
15445
+ "onUpdate:modelValue": ($event) => unref(config)[p.name] = $event,
15446
+ title: unref(t)(p.name),
15447
+ "default-transform": {
15448
+ width: 240,
15449
+ height: unref(drawboardAabb).height * 0.7,
15450
+ left: unref(drawboardAabb).left + (unref(drawboardPointer)?.x ?? unref(drawboardContextMenuPointer)?.x ?? unref(screenCenterOffset).left + 24),
15451
+ top: unref(drawboardAabb).top + (unref(drawboardPointer)?.y ?? unref(drawboardContextMenuPointer)?.y ?? unref(screenCenterOffset).top + 24)
15452
+ }
15453
+ }, {
15454
+ default: withCtx(({ isActive }) => [
15455
+ (openBlock(), createBlock(resolveDynamicComponent(p.component), {
15456
+ "is-active": isActive.value,
15457
+ "onUpdate:isActive": ($event) => isActive.value = $event
15458
+ }, null, 40, ["is-active", "onUpdate:isActive"]))
15459
+ ]),
15460
+ _: 2
15461
+ }, 1032, ["modelValue", "onUpdate:modelValue", "title", "default-transform"])) : createCommentVNode("", true)
15462
+ ], 64);
15463
+ }), 128)),
15264
15464
  createElementVNode("div", _hoisted_3, null, 512)
15265
15465
  ]),
15266
15466
  _: 3
@@ -15295,7 +15495,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
15295
15495
  updateLocation
15296
15496
  });
15297
15497
  return (_ctx, _cache) => {
15298
- return openBlock(), createBlock(_sfc_main$t, {
15498
+ return openBlock(), createBlock(_sfc_main$u, {
15299
15499
  ref: "overlayTpl",
15300
15500
  modelValue: isActive.value,
15301
15501
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isActive.value = $event),
@@ -15323,7 +15523,7 @@ export {
15323
15523
  _sfc_main as Dialog,
15324
15524
  Doc,
15325
15525
  Editor,
15326
- _sfc_main$v as EditorLayers,
15526
+ _sfc_main$w as EditorLayers,
15327
15527
  _sfc_main$1 as EditorLayout,
15328
15528
  _sfc_main$4 as EditorLayoutItem,
15329
15529
  _sfc_main$c as EditorToolbelt,
@@ -15334,7 +15534,7 @@ export {
15334
15534
  MceLayoutKey,
15335
15535
  MceMenuSymbol,
15336
15536
  MceOverlaySymbol,
15337
- _sfc_main$s as Menu,
15537
+ _sfc_main$t as Menu,
15338
15538
  Model,
15339
15539
  _sfc_main$p as Ruler,
15340
15540
  SUPPORTS_CLIPBOARD,
@@ -15360,7 +15560,7 @@ export {
15360
15560
  findChildrenWithProvide,
15361
15561
  getImageSizeFromUrl,
15362
15562
  getRandomValues,
15363
- iElementToYElements,
15563
+ iElementToYNodes,
15364
15564
  imageExtRe,
15365
15565
  imageExts,
15366
15566
  imageMimeTypeExtMap,