mce 0.17.2 → 0.17.4

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
@@ -1856,7 +1856,7 @@ const _2_box = defineMixin((editor) => {
1856
1856
  const aabbs = {};
1857
1857
  element.children.forEach((child, index) => {
1858
1858
  if (isElement(child)) {
1859
- aabbs[index] = child.globalAabb;
1859
+ aabbs[index] = getAabb(child);
1860
1860
  }
1861
1861
  });
1862
1862
  element.style.left += box.left;
@@ -3240,6 +3240,26 @@ const _autoNest = definePlugin((editor) => {
3240
3240
  }
3241
3241
  };
3242
3242
  });
3243
+ const _clipboard = definePlugin(() => {
3244
+ return {
3245
+ name: "mce:clipboard",
3246
+ loaders: [
3247
+ {
3248
+ name: "mce-clipboard",
3249
+ test: (doc) => {
3250
+ return doc instanceof Document && Boolean(doc.querySelector("mce-clipboard"));
3251
+ },
3252
+ load: async (doc) => {
3253
+ const mce = doc.querySelector("mce-clipboard");
3254
+ if (mce) {
3255
+ return JSON.parse(mce.textContent);
3256
+ }
3257
+ return [];
3258
+ }
3259
+ }
3260
+ ]
3261
+ };
3262
+ });
3243
3263
  const _doc = definePlugin((editor, options) => {
3244
3264
  const {
3245
3265
  root,
@@ -3905,45 +3925,40 @@ function createLayer() {
3905
3925
  registered.value = registered.value.filter((v) => v !== id);
3906
3926
  },
3907
3927
  onMousedown: (e, id) => {
3908
- const start = { x: e.clientX, y: e.clientY };
3909
- function onMove(e2) {
3910
- const current = { x: e2.clientX, y: e2.clientY };
3911
- if (!dragging.value && (Math.abs(current.x - start.x) >= 3 || Math.abs(current.y - start.y) >= 3)) {
3928
+ const from = nodeItems.get(id)?.value;
3929
+ addDragListener(e, {
3930
+ threshold: 10,
3931
+ start: () => {
3912
3932
  dragging.value = true;
3913
- }
3914
- if (dragging.value) {
3915
- const targets = e2.composedPath();
3916
- const layer = targets.find((target) => {
3933
+ },
3934
+ move: ({ event }) => {
3935
+ const layer = event.composedPath().find((target) => {
3917
3936
  return target instanceof HTMLElement && target.classList.contains("m-layer");
3918
3937
  });
3919
3938
  const id2 = layer?.dataset?.id;
3920
3939
  if (id2) {
3921
3940
  droppingItemId.value = id2;
3922
3941
  }
3923
- }
3924
- }
3925
- function onUp() {
3926
- if (droppingItemId.value) {
3927
- const from = nodeItems.get(id)?.value;
3928
- const to = nodeItems.get(droppingItemId.value)?.value;
3929
- if (to && from && !from.equal(to)) {
3930
- let toIndex = to.getIndex() + 1;
3931
- if (to.parent && from.parent && to.parent.equal(from.parent)) {
3932
- toIndex--;
3942
+ },
3943
+ end: () => {
3944
+ if (droppingItemId.value) {
3945
+ const to = nodeItems.get(droppingItemId.value)?.value;
3946
+ if (to && from && !from.equal(to)) {
3947
+ let toIndex = to.getIndex() + 1;
3948
+ if (to.parent && from.parent && to.parent.equal(from.parent)) {
3949
+ toIndex--;
3950
+ }
3951
+ to.parent?.moveChild(
3952
+ from,
3953
+ toIndex
3954
+ );
3933
3955
  }
3934
- to.parent?.moveChild(
3935
- from,
3936
- toIndex
3937
- );
3938
3956
  }
3957
+ dragging.value = false;
3958
+ droppingItemId.value = void 0;
3959
+ dragging.value = false;
3939
3960
  }
3940
- dragging.value = false;
3941
- droppingItemId.value = void 0;
3942
- document.removeEventListener("mousemove", onMove);
3943
- document.removeEventListener("mouseup", onUp);
3944
- }
3945
- document.addEventListener("mousemove", onMove);
3946
- document.addEventListener("mouseup", onUp);
3961
+ });
3947
3962
  }
3948
3963
  });
3949
3964
  return {
@@ -4638,7 +4653,10 @@ const _hover = definePlugin(() => {
4638
4653
  ]
4639
4654
  };
4640
4655
  });
4641
- const _html = definePlugin(() => {
4656
+ const _html = definePlugin((editor) => {
4657
+ const {
4658
+ load
4659
+ } = editor;
4642
4660
  const RE = /\.html$/i;
4643
4661
  return {
4644
4662
  name: "mce:html",
@@ -4661,11 +4679,12 @@ const _html = definePlugin(() => {
4661
4679
  },
4662
4680
  load: async (source) => {
4663
4681
  const dom = new DOMParser().parseFromString(await source.text(), "text/html");
4664
- const mce = dom.querySelector("mce-clipboard");
4665
- if (mce) {
4666
- return JSON.parse(mce.textContent);
4682
+ try {
4683
+ return await load(dom);
4684
+ } catch (_err) {
4685
+ console.log(dom);
4686
+ return [];
4667
4687
  }
4668
- return [];
4669
4688
  }
4670
4689
  }
4671
4690
  ]
@@ -4938,6 +4957,10 @@ const _sfc_main$B = /* @__PURE__ */ defineComponent({
4938
4957
  const _hoisted_1$q = ["data-id"];
4939
4958
  const _hoisted_2$c = { class: "m-layer__content" };
4940
4959
  const _hoisted_3$b = { class: "m-layer__prepend" };
4960
+ const _hoisted_4$5 = {
4961
+ key: 0,
4962
+ class: "m-layer__name"
4963
+ };
4941
4964
  const _sfc_main$A = /* @__PURE__ */ defineComponent({
4942
4965
  ...{
4943
4966
  name: "MceLayer",
@@ -5179,7 +5202,8 @@ const _sfc_main$A = /* @__PURE__ */ defineComponent({
5179
5202
  }, [
5180
5203
  createVNode(unref(_sfc_main$F), { icon: thumbnailIcon.value }, null, 8, ["icon"])
5181
5204
  ], 32),
5182
- createElementVNode("div", {
5205
+ props.root ? (openBlock(), createElementBlock("div", _hoisted_4$5, toDisplayString(unref(t)("layers")), 1)) : (openBlock(), createElementBlock("div", {
5206
+ key: 1,
5183
5207
  class: "m-layer__name",
5184
5208
  onDblclick: onDblclickName
5185
5209
  }, [
@@ -5202,7 +5226,7 @@ const _sfc_main$A = /* @__PURE__ */ defineComponent({
5202
5226
  createElementVNode("div", {
5203
5227
  style: normalizeStyle$1({ visibility: editing.value ? "hidden" : void 0 })
5204
5228
  }, toDisplayString(editValue.value || thumbnailName.value), 5)
5205
- ], 32),
5229
+ ], 32)),
5206
5230
  createElementVNode("div", {
5207
5231
  class: normalizeClass(["m-layer__action", {
5208
5232
  "m-layer__action--hover": hovering.value,
@@ -17244,8 +17268,8 @@ const _zoom = definePlugin((editor) => {
17244
17268
  return {
17245
17269
  name: "mce:zoom",
17246
17270
  commands: [
17247
- { command: "zoomIn", handle: () => camera.value.addZoom(0.25) },
17248
- { command: "zoomOut", handle: () => camera.value.addZoom(-0.25) },
17271
+ { command: "zoomIn", handle: () => camera.value.zoomIn() },
17272
+ { command: "zoomOut", handle: () => camera.value.zoomOut() },
17249
17273
  { command: "zoomTo", handle: zoomTo },
17250
17274
  { command: "zoomTo100", handle: () => zoomTo(1) },
17251
17275
  { command: "zoomToFit", handle: () => zoomTo("root", { strategy: config.value.strategy }) },
@@ -17277,6 +17301,7 @@ const _zoom = definePlugin((editor) => {
17277
17301
  const plugins = [
17278
17302
  _arrange,
17279
17303
  _autoNest,
17304
+ _clipboard,
17280
17305
  _doc,
17281
17306
  _edit,
17282
17307
  _formatPaint,
@@ -0,0 +1,2 @@
1
+ declare const _default: import("..").Plugin;
2
+ export default _default;
@@ -25,6 +25,7 @@ import './mixins/snapshot'
25
25
  import './mixins/tool'
26
26
  import './plugins/arrange'
27
27
  import './plugins/autoNest'
28
+ import './plugins/clipboard'
28
29
  import './plugins/doc'
29
30
  import './plugins/edit'
30
31
  import './plugins/formatPaint'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mce",
3
3
  "type": "module",
4
- "version": "0.17.2",
4
+ "version": "0.17.4",
5
5
  "description": "A headless infinite canvas editor framework built on WebGL rendering, supports exporting to image, video, and PPT. Only the ESM.",
6
6
  "author": "wxm",
7
7
  "license": "MIT",
@@ -55,13 +55,13 @@
55
55
  "dist"
56
56
  ],
57
57
  "dependencies": {
58
- "@floating-ui/vue": "^1.1.10",
58
+ "@floating-ui/vue": "^1.1.11",
59
59
  "@vueuse/components": "^14.2.1",
60
60
  "@vueuse/core": "^14.2.1",
61
61
  "diff": "^8.0.3",
62
62
  "file-saver": "^2.0.5",
63
63
  "lodash-es": "^4.17.23",
64
- "modern-canvas": "^0.15.6",
64
+ "modern-canvas": "^0.15.8",
65
65
  "modern-font": "^0.4.4",
66
66
  "modern-idoc": "^0.10.21",
67
67
  "modern-text": "^1.10.15",