mce 0.17.4 → 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
  }
@@ -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';
@@ -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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mce",
3
3
  "type": "module",
4
- "version": "0.17.4",
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