mce 0.17.3 → 0.17.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,9 +43,7 @@ declare const __VLS_base: import("vue").DefineComponent<{}, {
43
43
  readonly onEnd?: ((context: Mce.TransformContext) => any) | undefined;
44
44
  readonly "onUpdate:modelValue"?: ((value: Partial<Mce.TransformValue> | undefined) => any) | undefined;
45
45
  } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps;
46
- $attrs: {
47
- [x: string]: unknown;
48
- };
46
+ $attrs: import("vue").Attrs;
49
47
  $refs: {
50
48
  [x: string]: unknown;
51
49
  };
@@ -230,9 +228,7 @@ declare const __VLS_base: import("vue").DefineComponent<{}, {
230
228
  readonly onEnd?: ((context: Mce.TransformContext) => any) | undefined;
231
229
  readonly "onUpdate:modelValue"?: ((value: Partial<Mce.TransformValue> | undefined) => any) | undefined;
232
230
  } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps;
233
- $attrs: {
234
- [x: string]: unknown;
235
- };
231
+ $attrs: import("vue").Attrs;
236
232
  $refs: {
237
233
  [x: string]: unknown;
238
234
  };
@@ -4,7 +4,7 @@ import type { Transaction } from 'yjs';
4
4
  import { Node } from 'modern-canvas';
5
5
  import { Observable } from 'modern-idoc';
6
6
  import * as Y from 'yjs';
7
- import { IndexeddbProvider } from '../indexeddb';
7
+ import { IndexeddbProvider } from './providers';
8
8
  export type YNode = Y.Map<unknown> & {
9
9
  get: ((prop: 'id') => string) & ((prop: 'name') => string) & ((prop: 'parentId') => string) & ((prop: 'style') => Y.Map<unknown>) & ((prop: 'background') => Y.Map<unknown>) & ((prop: 'shape') => Y.Map<unknown>) & ((prop: 'fill') => Y.Map<unknown>) & ((prop: 'outline') => Y.Map<unknown>) & ((prop: 'text') => Y.Map<unknown>) & ((prop: 'foreground') => Y.Map<unknown>) & ((prop: 'shadow') => Y.Map<unknown>) & ((prop: 'meta') => Y.Map<unknown>) & ((prop: 'childrenIds') => Y.Array<string>) & (<T = unknown>(prop: string) => T);
10
10
  };
@@ -41,6 +41,6 @@ export declare class YDoc extends Observable {
41
41
  _proxyRoot(root: Node): this;
42
42
  protected _proxyProps(obj: CoreObject, yMap: Y.Map<any>, isMeta?: boolean): void;
43
43
  protected _proxyChildren(node: Node, childrenIds: Y.Array<string>): void;
44
- protected _proxyNode(node: Node, yNode?: YNode, yChildrenIds?: Y.Array<string>): void;
44
+ protected _proxyNode(node: Node, yNode?: YNode, yChildrenIds?: Y.Array<string>): Node;
45
45
  protected _initYNode(yNode: YNode): Node;
46
46
  }
@@ -0,0 +1 @@
1
+ export * from './indexeddb';
package/dist/index.js CHANGED
@@ -613,17 +613,26 @@ const customStoreName = "custom";
613
613
  const updatesStoreName = "updates";
614
614
  const PREFERRED_TRIM_SIZE = 500;
615
615
  function fetchUpdates(idbPersistence, beforeApplyUpdatesCallback, afterApplyUpdatesCallback) {
616
- const [updatesStore] = transact(
616
+ const [
617
+ updatesStore
618
+ ] = transact(
617
619
  idbPersistence.db,
618
620
  [updatesStoreName]
619
621
  );
620
- const range = createIDBKeyRangeLowerBound(idbPersistence._dbref, false);
621
- return getAll(updatesStore, range).then((updates) => {
622
+ return getAll(
623
+ updatesStore,
624
+ createIDBKeyRangeLowerBound(idbPersistence._dbref, false)
625
+ ).then((updates) => {
622
626
  if (!idbPersistence._destroyed) {
623
627
  beforeApplyUpdatesCallback?.(updatesStore);
624
- Y.transact(idbPersistence.doc, () => {
625
- updates.forEach((val) => Y.applyUpdate(idbPersistence.doc, val));
626
- }, idbPersistence, false);
628
+ Y.transact(
629
+ idbPersistence.doc,
630
+ () => {
631
+ updates.forEach((val) => Y.applyUpdate(idbPersistence.doc, val));
632
+ },
633
+ idbPersistence,
634
+ false
635
+ );
627
636
  afterApplyUpdatesCallback?.(updatesStore);
628
637
  }
629
638
  }).then(() => getLastKey(updatesStore).then((lastKey) => {
@@ -686,8 +695,8 @@ class IndexeddbProvider extends Observable {
686
695
  }
687
696
  }
688
697
  };
689
- doc.on("update", this._storeUpdate);
690
698
  this.destroy = this.destroy.bind(this);
699
+ doc.on("update", this._storeUpdate);
691
700
  doc.on("destroy", this.destroy);
692
701
  }
693
702
  db = null;
@@ -782,8 +791,7 @@ class YDoc extends Observable {
782
791
  this.undoManager = um;
783
792
  }
784
793
  async loadIndexeddb() {
785
- const indexeddb = new IndexeddbProvider(this._yDoc.guid, this._yDoc);
786
- this.indexeddb = await indexeddb.whenSynced;
794
+ this.indexeddb = await new IndexeddbProvider(this._yDoc.guid, this._yDoc).whenSynced;
787
795
  console.info("loaded data from indexed db");
788
796
  }
789
797
  load() {
@@ -1013,7 +1021,7 @@ class YDoc extends Observable {
1013
1021
  }
1014
1022
  _proxyNode(node, yNode, yChildrenIds) {
1015
1023
  if (node.internalMode !== "default") {
1016
- return;
1024
+ return node;
1017
1025
  }
1018
1026
  const id = node.id;
1019
1027
  if (!yNode) {
@@ -1027,8 +1035,26 @@ class YDoc extends Observable {
1027
1035
  this._yChildren.set(id, yNode);
1028
1036
  this.undoManager.addToScope(yNode);
1029
1037
  }
1030
- if (!this._nodeMap.has(id)) {
1038
+ const _node2 = this._nodeMap.get(id);
1039
+ if (_node2) {
1040
+ node = _node2;
1041
+ } else {
1031
1042
  if (!isReactive(node)) {
1043
+ const handle = (node2) => {
1044
+ if (node2 instanceof Element2D) {
1045
+ if (!node2.text.base.__markRaw__) {
1046
+ const base = markRaw(node2.text.base);
1047
+ base.__markRaw__ = true;
1048
+ base.setPropertyAccessor(node2.text);
1049
+ node2.text.base = base;
1050
+ }
1051
+ }
1052
+ };
1053
+ handle(node);
1054
+ node.findOne((child) => {
1055
+ handle(child);
1056
+ return false;
1057
+ });
1032
1058
  node = reactive(node);
1033
1059
  if (node.parent) {
1034
1060
  node.parent.children[node.getIndex()] = node;
@@ -1064,9 +1090,6 @@ class YDoc extends Observable {
1064
1090
  }
1065
1091
  this._proxyProps(node[key], yMap);
1066
1092
  });
1067
- const base = markRaw(node.text.base);
1068
- base.setPropertyAccessor(node.text);
1069
- node.text.base = base;
1070
1093
  node.text.update();
1071
1094
  node.requestRender();
1072
1095
  }
@@ -1080,20 +1103,19 @@ class YDoc extends Observable {
1080
1103
  }
1081
1104
  this._proxyChildren(node, yChildrenIds);
1082
1105
  }
1106
+ return node;
1083
1107
  }
1084
1108
  _initYNode(yNode) {
1085
1109
  const id = yNode.get("id");
1086
1110
  let node = this._nodeMap.get(id);
1087
1111
  if (!node) {
1088
1112
  this.undoManager.addToScope(yNode);
1089
- node = reactive(
1090
- Node$1.parse({
1091
- meta: {
1092
- inCanvasIs: yNode.get("meta")?.get("inCanvasIs")
1093
- }
1094
- })
1095
- );
1096
- this._proxyNode(node, yNode);
1113
+ node = Node$1.parse({
1114
+ meta: {
1115
+ inCanvasIs: yNode.get("meta")?.get("inCanvasIs")
1116
+ }
1117
+ });
1118
+ node = this._proxyNode(node, yNode);
1097
1119
  this._nodeMap.set(id, node);
1098
1120
  }
1099
1121
  return node;
@@ -1137,21 +1159,11 @@ class Doc extends Node$1 {
1137
1159
  this._yDoc = _doc2;
1138
1160
  this._source = _source;
1139
1161
  }
1140
- transact = (fn, should = true) => {
1141
- return this._yDoc.transact(fn, should);
1142
- };
1143
- undo = () => {
1144
- this._yDoc.undoManager.undo();
1145
- };
1146
- redo = () => {
1147
- this._yDoc.undoManager.redo();
1148
- };
1149
- stopCapturing = () => {
1150
- this._yDoc.undoManager.stopCapturing();
1151
- };
1152
- clearHistory = () => {
1153
- this._yDoc.undoManager.clear();
1154
- };
1162
+ transact = (fn, should = true) => this._yDoc.transact(fn, should);
1163
+ undo = () => this._yDoc.undoManager.undo();
1164
+ redo = () => this._yDoc.undoManager.redo();
1165
+ stopCapturing = () => this._yDoc.undoManager.stopCapturing();
1166
+ clearHistory = () => this._yDoc.undoManager.clear();
1155
1167
  set = (source) => {
1156
1168
  const { children = [], ...props } = source;
1157
1169
  const oldTransacting = this._yDoc._transacting;
@@ -1166,7 +1178,6 @@ class Doc extends Node$1 {
1166
1178
  return this;
1167
1179
  };
1168
1180
  loadIndexeddb = async () => {
1169
- console.log(this._yDoc.id);
1170
1181
  await this._yDoc.loadIndexeddb();
1171
1182
  };
1172
1183
  init = () => {
@@ -1379,7 +1390,11 @@ const _0_font = defineMixin((editor) => {
1379
1390
  } = editor;
1380
1391
  const loading = ref(false);
1381
1392
  async function loadFont(source, options) {
1382
- const res = await fonts.load(source, options);
1393
+ const res = await fonts.load(source, {
1394
+ ...options,
1395
+ injectFontFace: false,
1396
+ injectStyleTag: false
1397
+ });
1383
1398
  emit("loadFont", res);
1384
1399
  return res;
1385
1400
  }
@@ -1856,7 +1871,7 @@ const _2_box = defineMixin((editor) => {
1856
1871
  const aabbs = {};
1857
1872
  element.children.forEach((child, index) => {
1858
1873
  if (isElement(child)) {
1859
- aabbs[index] = child.globalAabb;
1874
+ aabbs[index] = getAabb(child);
1860
1875
  }
1861
1876
  });
1862
1877
  element.style.left += box.left;
@@ -3240,6 +3255,26 @@ const _autoNest = definePlugin((editor) => {
3240
3255
  }
3241
3256
  };
3242
3257
  });
3258
+ const _clipboard = definePlugin(() => {
3259
+ return {
3260
+ name: "mce:clipboard",
3261
+ loaders: [
3262
+ {
3263
+ name: "mce-clipboard",
3264
+ test: (doc) => {
3265
+ return doc instanceof Document && Boolean(doc.querySelector("mce-clipboard"));
3266
+ },
3267
+ load: async (doc) => {
3268
+ const mce = doc.querySelector("mce-clipboard");
3269
+ if (mce) {
3270
+ return JSON.parse(mce.textContent);
3271
+ }
3272
+ return [];
3273
+ }
3274
+ }
3275
+ ]
3276
+ };
3277
+ });
3243
3278
  const _doc = definePlugin((editor, options) => {
3244
3279
  const {
3245
3280
  root,
@@ -3905,45 +3940,40 @@ function createLayer() {
3905
3940
  registered.value = registered.value.filter((v) => v !== id);
3906
3941
  },
3907
3942
  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)) {
3943
+ const from = nodeItems.get(id)?.value;
3944
+ addDragListener(e, {
3945
+ threshold: 10,
3946
+ start: () => {
3912
3947
  dragging.value = true;
3913
- }
3914
- if (dragging.value) {
3915
- const targets = e2.composedPath();
3916
- const layer = targets.find((target) => {
3948
+ },
3949
+ move: ({ event }) => {
3950
+ const layer = event.composedPath().find((target) => {
3917
3951
  return target instanceof HTMLElement && target.classList.contains("m-layer");
3918
3952
  });
3919
3953
  const id2 = layer?.dataset?.id;
3920
3954
  if (id2) {
3921
3955
  droppingItemId.value = id2;
3922
3956
  }
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--;
3957
+ },
3958
+ end: () => {
3959
+ if (droppingItemId.value) {
3960
+ const to = nodeItems.get(droppingItemId.value)?.value;
3961
+ if (to && from && !from.equal(to)) {
3962
+ let toIndex = to.getIndex() + 1;
3963
+ if (to.parent && from.parent && to.parent.equal(from.parent)) {
3964
+ toIndex--;
3965
+ }
3966
+ to.parent?.moveChild(
3967
+ from,
3968
+ toIndex
3969
+ );
3933
3970
  }
3934
- to.parent?.moveChild(
3935
- from,
3936
- toIndex
3937
- );
3938
3971
  }
3972
+ dragging.value = false;
3973
+ droppingItemId.value = void 0;
3974
+ dragging.value = false;
3939
3975
  }
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);
3976
+ });
3947
3977
  }
3948
3978
  });
3949
3979
  return {
@@ -4638,7 +4668,10 @@ const _hover = definePlugin(() => {
4638
4668
  ]
4639
4669
  };
4640
4670
  });
4641
- const _html = definePlugin(() => {
4671
+ const _html = definePlugin((editor) => {
4672
+ const {
4673
+ load
4674
+ } = editor;
4642
4675
  const RE = /\.html$/i;
4643
4676
  return {
4644
4677
  name: "mce:html",
@@ -4661,11 +4694,12 @@ const _html = definePlugin(() => {
4661
4694
  },
4662
4695
  load: async (source) => {
4663
4696
  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);
4697
+ try {
4698
+ return await load(dom);
4699
+ } catch (_err) {
4700
+ console.log(dom);
4701
+ return [];
4667
4702
  }
4668
- return [];
4669
4703
  }
4670
4704
  }
4671
4705
  ]
@@ -4938,6 +4972,10 @@ const _sfc_main$B = /* @__PURE__ */ defineComponent({
4938
4972
  const _hoisted_1$q = ["data-id"];
4939
4973
  const _hoisted_2$c = { class: "m-layer__content" };
4940
4974
  const _hoisted_3$b = { class: "m-layer__prepend" };
4975
+ const _hoisted_4$5 = {
4976
+ key: 0,
4977
+ class: "m-layer__name"
4978
+ };
4941
4979
  const _sfc_main$A = /* @__PURE__ */ defineComponent({
4942
4980
  ...{
4943
4981
  name: "MceLayer",
@@ -5179,7 +5217,8 @@ const _sfc_main$A = /* @__PURE__ */ defineComponent({
5179
5217
  }, [
5180
5218
  createVNode(unref(_sfc_main$F), { icon: thumbnailIcon.value }, null, 8, ["icon"])
5181
5219
  ], 32),
5182
- createElementVNode("div", {
5220
+ props.root ? (openBlock(), createElementBlock("div", _hoisted_4$5, toDisplayString(unref(t)("layers")), 1)) : (openBlock(), createElementBlock("div", {
5221
+ key: 1,
5183
5222
  class: "m-layer__name",
5184
5223
  onDblclick: onDblclickName
5185
5224
  }, [
@@ -5202,7 +5241,7 @@ const _sfc_main$A = /* @__PURE__ */ defineComponent({
5202
5241
  createElementVNode("div", {
5203
5242
  style: normalizeStyle$1({ visibility: editing.value ? "hidden" : void 0 })
5204
5243
  }, toDisplayString(editValue.value || thumbnailName.value), 5)
5205
- ], 32),
5244
+ ], 32)),
5206
5245
  createElementVNode("div", {
5207
5246
  class: normalizeClass(["m-layer__action", {
5208
5247
  "m-layer__action--hover": hovering.value,
@@ -17277,6 +17316,7 @@ const _zoom = definePlugin((editor) => {
17277
17316
  const plugins = [
17278
17317
  _arrange,
17279
17318
  _autoNest,
17319
+ _clipboard,
17280
17320
  _doc,
17281
17321
  _edit,
17282
17322
  _formatPaint,
@@ -3,7 +3,7 @@ import type { IndexCharacter as _IndexCharacter } from 'modern-text/web-componen
3
3
  import type { Ref } from 'vue';
4
4
  import { Aabb2D, Camera2D, DrawboardEffect, Element2D, Engine, Node, Timeline, Vector2 } from 'modern-canvas';
5
5
  import { Fonts } from 'modern-font';
6
- import { Doc } from '../nodes';
6
+ import { Doc } from '../scene';
7
7
  declare global {
8
8
  namespace Mce {
9
9
  type TBlock = 'top' | 'bottom';
@@ -0,0 +1,2 @@
1
+ declare const _default: import("..").Plugin;
2
+ export default _default;
@@ -1,5 +1,5 @@
1
1
  import type { Element } from 'modern-idoc';
2
- import { Doc } from '../nodes';
2
+ import { Doc } from '../scene';
3
3
  declare global {
4
4
  namespace Mce {
5
5
  interface Options {
@@ -18,8 +18,8 @@ export declare class Doc extends Node {
18
18
  protected _source: any;
19
19
  constructor(source?: Mce.DocumentSource);
20
20
  transact: <T>(fn: () => T, should?: boolean) => T;
21
- undo: () => void;
22
- redo: () => void;
21
+ undo: () => any | null;
22
+ redo: () => any | null;
23
23
  stopCapturing: () => void;
24
24
  clearHistory: () => void;
25
25
  set: (source: Document) => this;
@@ -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.3",
4
+ "version": "0.17.5",
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",
@@ -61,10 +61,11 @@
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.8",
65
- "modern-font": "^0.4.4",
64
+ "modern-canvas": "^0.15.9",
65
+ "modern-font": "^0.5.0",
66
66
  "modern-idoc": "^0.10.21",
67
- "modern-text": "^1.10.15",
67
+ "modern-text": "^1.10.16",
68
+ "y-protocols": "^1.0.7",
68
69
  "yjs": "^13.6.29"
69
70
  },
70
71
  "peerDependencies": {
@@ -89,7 +90,7 @@
89
90
  "@types/lodash-es": "^4.17.12",
90
91
  "@vitejs/plugin-vue": "^6.0.4",
91
92
  "jiti": "^2.6.1",
92
- "sass-embedded": "^1.97.3",
93
+ "sass-embedded": "^1.98.0",
93
94
  "typedoc": "^0.28.17",
94
95
  "typedoc-plugin-markdown": "^4.10.0"
95
96
  },
File without changes