@lexical/yjs 0.11.0 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Bindings.d.ts CHANGED
@@ -14,8 +14,8 @@ import type { LexicalEditor, NodeKey } from 'lexical';
14
14
  import type { Doc } from 'yjs';
15
15
  import { Klass, LexicalNode } from 'lexical';
16
16
  import { Provider } from '.';
17
- export declare type ClientID = number;
18
- export declare type Binding = {
17
+ export type ClientID = number;
18
+ export type Binding = {
19
19
  clientID: number;
20
20
  collabNodeMap: Map<NodeKey, CollabElementNode | CollabTextNode | CollabDecoratorNode | CollabLineBreakNode>;
21
21
  cursors: Map<ClientID, Cursor>;
@@ -28,5 +28,5 @@ export declare type Binding = {
28
28
  root: CollabElementNode;
29
29
  excludedProperties: ExcludedProperties;
30
30
  };
31
- export declare type ExcludedProperties = Map<Klass<LexicalNode>, Set<string>>;
31
+ export type ExcludedProperties = Map<Klass<LexicalNode>, Set<string>>;
32
32
  export declare function createBinding(editor: LexicalEditor, provider: Provider, id: string, doc: Doc | null | undefined, docMap: Map<string, Doc>, excludedProperties?: ExcludedProperties): Binding;
@@ -11,7 +11,7 @@ import type { AbstractType, XmlText } from 'yjs';
11
11
  import { CollabDecoratorNode } from './CollabDecoratorNode';
12
12
  import { CollabLineBreakNode } from './CollabLineBreakNode';
13
13
  import { CollabTextNode } from './CollabTextNode';
14
- declare type IntentionallyMarkedAsDirtyElement = boolean;
14
+ type IntentionallyMarkedAsDirtyElement = boolean;
15
15
  export declare class CollabElementNode {
16
16
  _key: NodeKey;
17
17
  _children: Array<CollabElementNode | CollabTextNode | CollabDecoratorNode | CollabLineBreakNode>;
package/LexicalYjs.dev.js CHANGED
@@ -237,7 +237,30 @@ function $createCollabTextNode(map, text, parent, type) {
237
237
  * LICENSE file in the root directory of this source tree.
238
238
  *
239
239
  */
240
- const excludedProperties = new Set(['__key', '__parent', '__cachedText', '__text', '__size', '__next', '__prev', '__first', '__last']);
240
+ const baseExcludedProperties = new Set(['__key', '__parent', '__next', '__prev']);
241
+ const elementExcludedProperties = new Set(['__first', '__last', '__size']);
242
+ const rootExcludedProperties = new Set(['__cachedText']);
243
+ const textExcludedProperties = new Set(['__text']);
244
+
245
+ function isExcludedProperty(name, node, binding) {
246
+ if (baseExcludedProperties.has(name)) {
247
+ return true;
248
+ }
249
+
250
+ if (lexical.$isTextNode(node)) {
251
+ if (textExcludedProperties.has(name)) {
252
+ return true;
253
+ }
254
+ } else if (lexical.$isElementNode(node)) {
255
+ if (elementExcludedProperties.has(name) || lexical.$isRootNode(node) && rootExcludedProperties.has(name)) {
256
+ return true;
257
+ }
258
+ }
259
+
260
+ const nodeKlass = node.constructor;
261
+ const excludedProperties = binding.excludedProperties.get(nodeKlass);
262
+ return excludedProperties != null && excludedProperties.has(name);
263
+ }
241
264
  function $getNodeByKeyOrThrow(key) {
242
265
  const node = lexical.$getNodeByKey(key);
243
266
 
@@ -358,13 +381,7 @@ function syncPropertiesFromYjs(binding, sharedType, lexicalNode, keysChanged) {
358
381
  for (let i = 0; i < properties.length; i++) {
359
382
  const property = properties[i];
360
383
 
361
- if (excludedProperties.has(property)) {
362
- continue;
363
- }
364
-
365
- const additionalExcludedProperties = binding.excludedProperties.get(lexicalNode.constructor);
366
-
367
- if (additionalExcludedProperties !== undefined && additionalExcludedProperties.has(property)) {
384
+ if (isExcludedProperty(property, lexicalNode, binding)) {
368
385
  continue;
369
386
  }
370
387
 
@@ -400,9 +417,8 @@ function syncPropertiesFromLexical(binding, sharedType, prevLexicalNode, nextLex
400
417
  let properties = nodeProperties.get(type);
401
418
 
402
419
  if (properties === undefined) {
403
- const additionalExlcudedProperties = binding.excludedProperties.get(nextLexicalNode.constructor);
404
420
  properties = Object.keys(nextLexicalNode).filter(property => {
405
- return !excludedProperties.has(property) || additionalExlcudedProperties && !additionalExlcudedProperties.has(property);
421
+ return !isExcludedProperty(property, nextLexicalNode, binding);
406
422
  });
407
423
  nodeProperties.set(type, properties);
408
424
  }
@@ -1682,7 +1698,13 @@ function syncEvent(binding, event) {
1682
1698
 
1683
1699
  function syncYjsChangesToLexical(binding, provider, events, isFromUndoManger) {
1684
1700
  const editor = binding.editor;
1685
- const currentEditorState = editor._editorState;
1701
+ const currentEditorState = editor._editorState; // This line precompute the delta before editor update. The reason is
1702
+ // delta is computed when it is accessed. Note that this can only be
1703
+ // safely computed during the event call. If it is accessed after event
1704
+ // call it might result in unexpected behavior.
1705
+ // https://github.com/yjs/yjs/blob/00ef472d68545cb260abd35c2de4b3b78719c9e4/src/utils/YEvent.js#L132
1706
+
1707
+ events.forEach(event => event.delta);
1686
1708
  editor.update(() => {
1687
1709
  const pendingEditorState = editor._pendingEditorState;
1688
1710
 
@@ -4,46 +4,47 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- 'use strict';var t=require("lexical"),v=require("yjs"),y=require("@lexical/selection"),z=require("@lexical/offset");function B(a){throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?code=${a} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
- class C{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){let a=t.$getNodeByKey(this._key);return t.$isLineBreakNode(a)?a:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(a){a.collabNodeMap.delete(this._key)}}function D(a,b){b=new C(a,b);return a._collabNode=b}
9
- class E{constructor(a,b,c,d){this._key="";this._map=a;this._parent=c;this._text=b;this._type=d;this._normalized=!1}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return t.$isTextNode(a)?a:null}getNode(){let a=t.$getNodeByKey(this._key);return t.$isTextNode(a)?a:null}getSharedType(){return this._map}getType(){return this._type}getKey(){return this._key}getSize(){return this._text.length+(this._normalized?0:1)}getOffset(){return this._parent.getChildOffset(this)}spliceText(a,b,c){let d=this._parent._xmlText;
10
- a=this.getOffset()+1+a;0!==b&&d.delete(a,b);""!==c&&d.insert(a,c)}syncPropertiesAndTextFromLexical(a,b,c){var d=this.getPrevNode(c);c=b.__text;F(a,this._map,d,b);if(null!==d&&(a=d.__text,a!==c)){d=b.__key;b=a;var e=t.$getSelection();a=c.length;t.$isRangeSelection(e)&&e.isCollapsed()&&(e=e.anchor,e.key===d&&(a=e.offset));d=b.length;let f=c.length,g=e=0;for(;e<d&&e<f&&b[e]===c[e]&&e<a;)e++;for(;g+e<d&&g+e<f&&b[d-g-1]===c[f-g-1];)g++;for(;g+e<d&&g+e<f&&b[e]===c[e];)e++;b=e;a=c.slice(e,f-g);d=d-e-g;this.spliceText(b,
11
- d,a);this._text=c}}syncPropertiesAndTextFromYjs(a,b){let c=this.getNode();null===c&&B(84);G(a,this._map,c,b);a=this._text;c.__text!==a&&(c.getWritable().__text=a)}destroy(a){a.collabNodeMap.delete(this._key)}}function I(a,b,c,d){b=new E(a,b,c,d);return a._collabNode=b}let J=new Set("__key __parent __cachedText __text __size __next __prev __first __last".split(" "));function K(a){a=t.$getNodeByKey(a);null===a&&B(85);return a}
12
- function L(a,b,c){let d=b.__type;if(t.$isElementNode(b)){var e=new v.XmlText;e=M(e,c,d);e.syncPropertiesFromLexical(a,b,null);e.syncChildrenFromLexical(a,b,null,null,null)}else t.$isTextNode(b)?(e=new v.Map,e=I(e,b.__text,c,d),e.syncPropertiesAndTextFromLexical(a,b,null)):t.$isLineBreakNode(b)?(a=new v.Map,a.set("__type","linebreak"),e=D(a,c)):t.$isDecoratorNode(b)?(e=new v.XmlElement,e=N(e,c,d),e.syncPropertiesFromLexical(a,b,null)):B(86);e._key=b.__key;return e}
13
- function O(a,b,c){let d=b._collabNode;if(void 0===d){var e=a.editor._nodes;let f=b instanceof v.Map?b.get("__type"):b.getAttribute("__type");null==f&&B(87);void 0===e.get(f)&&B(88);e=b.parent;a=void 0===c&&null!==e?O(a,e):c||null;a instanceof P||B(89);if(b instanceof v.XmlText)return M(b,a,f);if(b instanceof v.Map)return"linebreak"===f?D(b,a):I(b,"",a,f);if(b instanceof v.XmlElement)return N(b,a,f)}return d}
14
- function G(a,b,c,d){d=null===d?b instanceof v.Map?Array.from(b.keys()):Object.keys(b.getAttributes()):Array.from(d);let e;for(let h=0;h<d.length;h++){let m=d[h];if(!J.has(m)){var f=a.excludedProperties.get(c.constructor);if(void 0===f||!f.has(m)){var g=c[m];f=b instanceof v.Map?b.get(m):b.getAttribute(m);if(g!==f){if(f instanceof v.Doc){let n=a.docMap;g instanceof v.Doc&&n.delete(g.guid);g=t.createEditor();let p=f.guid;g._key=p;n.set(p,f);f=g}void 0===e&&(e=c.getWritable());e[m]=f}}}}}
15
- function F(a,b,c,d){var e=d.__type,f=a.nodeProperties;let g=f.get(e);if(void 0===g){let m=a.excludedProperties.get(d.constructor);g=Object.keys(d).filter(n=>!J.has(n)||m&&!m.has(n));f.set(e,g)}e=a.editor.constructor;for(f=0;f<g.length;f++){let m=g[f];var h=null===c?void 0:c[m];let n=d[m];if(h!==n){if(n instanceof e){let p=a.docMap,k;h instanceof e&&(h=h._key,k=p.get(h),p.delete(h));h=k||new v.Doc;let l=h.guid;n._key=l;p.set(l,h);n=h;a.editor.update(()=>{d.markDirty()})}b instanceof v.Map?b.set(m,
16
- n):b.setAttribute(m,n)}}}function Q(a,b,c){let d=0,e=0,f=a._children,g=f.length;for(;e<g;e++){a=f[e];let h=d,m=a.getSize();d+=m;if((c?d>=b:d>b)&&a instanceof E)return c=b-h-1,0>c&&(c=0),{length:d-b,node:a,nodeIndex:e,offset:c};if(d>b)return{length:0,node:a,nodeIndex:e,offset:h};if(e===g-1)return{length:0,node:null,nodeIndex:e+1,offset:h+1}}return{length:0,node:null,nodeIndex:0,offset:0}}
17
- function R(a){let b=a.anchor;a=a.focus;let c=!1;try{let d=b.getNode(),e=a.getNode();if(!d.isAttached()||!e.isAttached()||t.$isTextNode(d)&&b.offset>d.getTextContentSize()||t.$isTextNode(e)&&a.offset>e.getTextContentSize())c=!0}catch(d){c=!0}return c}function aa(a,b){a.doc.transact(b,a)}function S(a,b){let c=[];for(a=a.__first;null!==a;){let d=null===b?t.$getNodeByKey(a):b.get(a);null!==d&&void 0!==d||B(101);c.push(a);a=d.__next}return c}
7
+ 'use strict';var r=require("lexical"),v=require("yjs"),y=require("@lexical/selection"),z=require("@lexical/offset");function A(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
+ class C{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){let a=r.$getNodeByKey(this._key);return r.$isLineBreakNode(a)?a:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(a){a.collabNodeMap.delete(this._key)}}function E(a,b){b=new C(a,b);return a._collabNode=b}
9
+ class F{constructor(a,b,c,d){this._key="";this._map=a;this._parent=c;this._text=b;this._type=d;this._normalized=!1}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return r.$isTextNode(a)?a:null}getNode(){let a=r.$getNodeByKey(this._key);return r.$isTextNode(a)?a:null}getSharedType(){return this._map}getType(){return this._type}getKey(){return this._key}getSize(){return this._text.length+(this._normalized?0:1)}getOffset(){return this._parent.getChildOffset(this)}spliceText(a,b,c){let d=this._parent._xmlText;
10
+ a=this.getOffset()+1+a;0!==b&&d.delete(a,b);""!==c&&d.insert(a,c)}syncPropertiesAndTextFromLexical(a,b,c){var d=this.getPrevNode(c);c=b.__text;G(a,this._map,d,b);if(null!==d&&(a=d.__text,a!==c)){d=b.__key;b=a;var e=r.$getSelection();a=c.length;r.$isRangeSelection(e)&&e.isCollapsed()&&(e=e.anchor,e.key===d&&(a=e.offset));d=b.length;let f=c.length,h=e=0;for(;e<d&&e<f&&b[e]===c[e]&&e<a;)e++;for(;h+e<d&&h+e<f&&b[d-h-1]===c[f-h-1];)h++;for(;h+e<d&&h+e<f&&b[e]===c[e];)e++;b=e;a=c.slice(e,f-h);d=d-e-h;this.spliceText(b,
11
+ d,a);this._text=c}}syncPropertiesAndTextFromYjs(a,b){let c=this.getNode();null===c&&A(84);H(a,this._map,c,b);a=this._text;c.__text!==a&&(c.getWritable().__text=a)}destroy(a){a.collabNodeMap.delete(this._key)}}function I(a,b,c,d){b=new F(a,b,c,d);return a._collabNode=b}let aa=new Set(["__key","__parent","__next","__prev"]),ba=new Set(["__first","__last","__size"]),ja=new Set(["__cachedText"]),ka=new Set(["__text"]);
12
+ function J(a,b,c){if(aa.has(a))return!0;if(r.$isTextNode(b)){if(ka.has(a))return!0}else if(r.$isElementNode(b)&&(ba.has(a)||r.$isRootNode(b)&&ja.has(a)))return!0;b=c.excludedProperties.get(b.constructor);return null!=b&&b.has(a)}function K(a){a=r.$getNodeByKey(a);null===a&&A(85);return a}
13
+ function L(a,b,c){let d=b.__type;if(r.$isElementNode(b)){var e=new v.XmlText;e=M(e,c,d);e.syncPropertiesFromLexical(a,b,null);e.syncChildrenFromLexical(a,b,null,null,null)}else r.$isTextNode(b)?(e=new v.Map,e=I(e,b.__text,c,d),e.syncPropertiesAndTextFromLexical(a,b,null)):r.$isLineBreakNode(b)?(a=new v.Map,a.set("__type","linebreak"),e=E(a,c)):r.$isDecoratorNode(b)?(e=new v.XmlElement,e=N(e,c,d),e.syncPropertiesFromLexical(a,b,null)):A(86);e._key=b.__key;return e}
14
+ function O(a,b,c){let d=b._collabNode;if(void 0===d){var e=a.editor._nodes;let f=b instanceof v.Map?b.get("__type"):b.getAttribute("__type");null==f&&A(87);void 0===e.get(f)&&A(88,f);e=b.parent;a=void 0===c&&null!==e?O(a,e):c||null;a instanceof P||A(89);if(b instanceof v.XmlText)return M(b,a,f);if(b instanceof v.Map)return"linebreak"===f?E(b,a):I(b,"",a,f);if(b instanceof v.XmlElement)return N(b,a,f)}return d}
15
+ function H(a,b,c,d){d=null===d?b instanceof v.Map?Array.from(b.keys()):Object.keys(b.getAttributes()):Array.from(d);let e;for(let h=0;h<d.length;h++){let g=d[h];if(J(g,c,a))continue;var f=c[g];let m=b instanceof v.Map?b.get(g):b.getAttribute(g);if(f!==m){if(m instanceof v.Doc){let p=a.docMap;f instanceof v.Doc&&p.delete(f.guid);f=r.createEditor();let n=m.guid;f._key=n;p.set(n,m);m=f}void 0===e&&(e=c.getWritable());e[g]=m}}}
16
+ function G(a,b,c,d){var e=d.__type,f=a.nodeProperties;let h=f.get(e);void 0===h&&(h=Object.keys(d).filter(m=>!J(m,d,a)),f.set(e,h));e=a.editor.constructor;for(f=0;f<h.length;f++){let m=h[f];var g=null===c?void 0:c[m];let p=d[m];if(g!==p){if(p instanceof e){let n=a.docMap,k;g instanceof e&&(g=g._key,k=n.get(g),n.delete(g));g=k||new v.Doc;let l=g.guid;p._key=l;n.set(l,g);p=g;a.editor.update(()=>{d.markDirty()})}b instanceof v.Map?b.set(m,p):b.setAttribute(m,p)}}}
17
+ function Q(a,b,c){let d=0,e=0,f=a._children,h=f.length;for(;e<h;e++){a=f[e];let g=d,m=a.getSize();d+=m;if((c?d>=b:d>b)&&a instanceof F)return c=b-g-1,0>c&&(c=0),{length:d-b,node:a,nodeIndex:e,offset:c};if(d>b)return{length:0,node:a,nodeIndex:e,offset:g};if(e===h-1)return{length:0,node:null,nodeIndex:e+1,offset:g+1}}return{length:0,node:null,nodeIndex:0,offset:0}}
18
+ function R(a){let b=a.anchor;a=a.focus;let c=!1;try{let d=b.getNode(),e=a.getNode();if(!d.isAttached()||!e.isAttached()||r.$isTextNode(d)&&b.offset>d.getTextContentSize()||r.$isTextNode(e)&&a.offset>e.getTextContentSize())c=!0}catch(d){c=!0}return c}function la(a,b){a.doc.transact(b,a)}function S(a,b){let c=[];for(a=a.__first;null!==a;){let d=null===b?r.$getNodeByKey(a):b.get(a);null!==d&&void 0!==d||A(101);c.push(a);a=d.__next}return c}
18
19
  function T(a){var b=a.getParent();if(null!==b){let e=a.getWritable();b=b.getWritable();var c=a.getPreviousSibling();a=a.getNextSibling();if(null===c)if(null!==a){var d=a.getWritable();b.__first=a.__key;d.__prev=null}else b.__first=null;else{d=c.getWritable();if(null!==a){let f=a.getWritable();f.__prev=d.__key;d.__next=f.__key}else d.__next=null;e.__prev=null}null===a?null!==c?(a=c.getWritable(),b.__last=c.__key,a.__next=null):b.__last=null:(a=a.getWritable(),null!==c?(c=c.getWritable(),c.__next=a.__key,
19
20
  a.__prev=c.__key):a.__prev=null,e.__next=null);b.__size--;e.__parent=null}}
20
- class U{constructor(a,b,c){this._key="";this._xmlElem=a;this._parent=b;this._type=c;this._unobservers=new Set}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return t.$isDecoratorNode(a)?a:null}getNode(){let a=t.$getNodeByKey(this._key);return t.$isDecoratorNode(a)?a:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(a,b,c){c=this.getPrevNode(c);
21
- F(a,this._xmlElem,c,b)}syncPropertiesFromYjs(a,b){let c=this.getNode();null===c&&B(83);G(a,this._xmlElem,c,b)}destroy(a){a.collabNodeMap.delete(this._key);this._unobservers.forEach(b=>b());this._unobservers.clear()}}function N(a,b,c){b=new U(a,b,c);return a._collabNode=b}
22
- class P{constructor(a,b,c){this._key="";this._children=[];this._xmlText=a;this._type=c;this._parent=b}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return t.$isElementNode(a)?a:null}getNode(){let a=t.$getNodeByKey(this._key);return t.$isElementNode(a)?a:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){let a=this._parent;null===a&&B(90);return a.getChildOffset(this)}syncPropertiesFromYjs(a,
23
- b){let c=this.getNode();null===c&&B(91);G(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){let c=this._children,d=0;for(let p=0;p<b.length;p++){var e=b[p],f=e.insert,g=e.delete;if(null!=e.retain)d+=e.retain;else if("number"===typeof g)for(f=g;0<f;){let {node:k,nodeIndex:l,offset:q,length:u}=Q(this,d,!1);if(k instanceof P||k instanceof C||k instanceof U)c.splice(l,1),--f;else if(k instanceof E){e=Math.min(f,u);g=0!==l?c[l-1]:null;var h=k.getSize();if(0===q&&1===e&&0<l&&g instanceof E&&u===h&&0===Array.from(k._map.keys()).length)g._text+=
24
- k._text,c.splice(l,1);else if(0===q&&e===h)c.splice(l,1);else{g=k;h=k._text;var m=q,n=e;h=h.slice(0,m)+""+h.slice(m+n);g._text=h}f-=e}else break}else if(null!=f)if("string"===typeof f){let {node:k,offset:l}=Q(this,d,!0);k instanceof E?(e=k,g=k._text,h=l,m=f,g=g.slice(0,h)+m+g.slice(h+0),e._text=g):this._xmlText.delete(l,f.length);d+=f.length}else e=f,{nodeIndex:f}=Q(this,d,!1),e=O(a,e,this),c.splice(f,0,e),d+=1;else throw Error("Unexpected delta format");}}syncChildrenFromYjs(a){var b=this.getNode();
25
- null===b&&B(92);var c=b.__key;let d=S(b,null),e=d.length;var f=this._children;let g=f.length,h=a.collabNodeMap,m=new Set,n;let p=0;var k=null;g!==e&&b.getWritable();for(let x=0;x<g;x++){var l=d[p],q=f[x];var u=q.getNode();var r=q._key;if(null!==u&&l===r)k=t.$isTextNode(u),m.add(l),k&&(q._key=l,q instanceof P?(k=q._xmlText,q.syncPropertiesFromYjs(a,null),q.applyChildrenYjsDelta(a,k.toDelta()),q.syncChildrenFromYjs(a)):q instanceof E?q.syncPropertiesAndTextFromYjs(a,null):q instanceof U?q.syncPropertiesFromYjs(a,
26
- null):q instanceof C||B(93)),k=u,p++;else{if(void 0===n)for(n=new Set,r=0;r<g;r++){var w=f[r]._key;""!==w&&n.add(w)}if(null===u||void 0===l||n.has(l)){u=b.getWritable();l=a;r=q;w=c;var A=r.getType();A=l.editor._nodes.get(A);void 0===A&&B(88);A=new A.klass;A.__parent=w;r._key=A.__key;r instanceof P?(w=r._xmlText,r.syncPropertiesFromYjs(l,null),r.applyChildrenYjsDelta(l,w.toDelta()),r.syncChildrenFromYjs(l)):r instanceof E?r.syncPropertiesAndTextFromYjs(l,null):r instanceof U&&r.syncPropertiesFromYjs(l,
27
- null);l.collabNodeMap.set(A.__key,r);l=A;r=l.__key;h.set(r,q);null===k?(k=u.getFirstChild(),u.__first=r,null!==k&&(k=k.getWritable(),k.__prev=r,l.__next=k.__key)):(q=k.getWritable(),w=k.getNextSibling(),q.__next=r,l.__prev=k.__key,null!==w&&(k=w.getWritable(),k.__prev=r,l.__next=k.__key));x===g-1&&(u.__last=r);u.__size++;k=l}else q=K(l),T(q),x--,p++}}for(b=0;b<e;b++)f=d[b],m.has(f)||(c=K(f),f=a.collabNodeMap.get(f),void 0!==f&&f.destroy(a),T(c))}syncPropertiesFromLexical(a,b,c){F(a,this._xmlText,
28
- this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=K(c);b instanceof P&&t.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof E&&t.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof U&&t.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var f=this.getPrevNode(c);let g=null===f?[]:S(f,c);f=S(b,null);let h=g.length-1,m=f.length-1,n=a.collabNodeMap,p,k,l=0;for(b=
29
- 0;l<=h&&b<=m;){var q=g[l];let r=f[b];if(q===r)this._syncChildFromLexical(a,b,r,c,d,e),l++,b++;else{void 0===p&&(p=new Set(g));void 0===k&&(k=new Set(f));var u=k.has(q);q=p.has(r);u?(u=K(r),u=L(a,u,this),n.set(r,u),q?(this.splice(a,b,1,u),l++):this.splice(a,b,0,u),b++):(this.splice(a,b,1),l++)}}c=l>h;d=b>m;if(c&&!d)for(;b<=m;++b)c=f[b],d=K(c),d=L(a,d,this),this.append(d),n.set(c,d);else if(d&&!c)for(f=this._children.length-1;f>=b;f--)this.splice(a,f,1)}append(a){let b=this._xmlText;var c=this._children;
30
- c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof P)b.insertEmbed(c,a._xmlText);else if(a instanceof E){let d=a._map;null===d.parent&&b.insertEmbed(c,d);b.insert(c+1,a._text)}else a instanceof C?b.insertEmbed(c,a._map):a instanceof U&&b.insertEmbed(c,a._xmlElem);this._children.push(a)}splice(a,b,c,d){let e=this._children;var f=e[b];if(void 0===f)void 0===d&&B(94),this.append(d);else{var g=f.getOffset();-1===g&&B(95);var h=this._xmlText;0!==c&&h.delete(g,f.getSize());d instanceof
31
- P?h.insertEmbed(g,d._xmlText):d instanceof E?(f=d._map,null===f.parent&&h.insertEmbed(g,f),h.insert(g+1,d._text)):d instanceof C?h.insertEmbed(g,d._map):d instanceof U&&h.insertEmbed(g,d._xmlElem);if(0!==c)for(g=e.slice(b,b+c),h=0;h<g.length;h++)g[h].destroy(a);void 0!==d?e.splice(b,c,d):e.splice(b,c)}}getChildOffset(a){let b=0,c=this._children;for(let d=0;d<c.length;d++){let e=c[d];if(e===a)return b;b+=e.getSize()}return-1}destroy(a){let b=a.collabNodeMap,c=this._children;for(let d=0;d<c.length;d++)c[d].destroy(a);
21
+ class U{constructor(a,b,c){this._key="";this._xmlElem=a;this._parent=b;this._type=c;this._unobservers=new Set}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return r.$isDecoratorNode(a)?a:null}getNode(){let a=r.$getNodeByKey(this._key);return r.$isDecoratorNode(a)?a:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(a,b,c){c=this.getPrevNode(c);
22
+ G(a,this._xmlElem,c,b)}syncPropertiesFromYjs(a,b){let c=this.getNode();null===c&&A(83);H(a,this._xmlElem,c,b)}destroy(a){a.collabNodeMap.delete(this._key);this._unobservers.forEach(b=>b());this._unobservers.clear()}}function N(a,b,c){b=new U(a,b,c);return a._collabNode=b}
23
+ class P{constructor(a,b,c){this._key="";this._children=[];this._xmlText=a;this._type=c;this._parent=b}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return r.$isElementNode(a)?a:null}getNode(){let a=r.$getNodeByKey(this._key);return r.$isElementNode(a)?a:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){let a=this._parent;null===a&&A(90);return a.getChildOffset(this)}syncPropertiesFromYjs(a,
24
+ b){let c=this.getNode();null===c&&A(91);H(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){let c=this._children,d=0;for(let n=0;n<b.length;n++){var e=b[n],f=e.insert,h=e.delete;if(null!=e.retain)d+=e.retain;else if("number"===typeof h)for(f=h;0<f;){let {node:k,nodeIndex:l,offset:q,length:u}=Q(this,d,!1);if(k instanceof P||k instanceof C||k instanceof U)c.splice(l,1),--f;else if(k instanceof F){e=Math.min(f,u);h=0!==l?c[l-1]:null;var g=k.getSize();if(0===q&&1===e&&0<l&&h instanceof F&&u===g&&0===Array.from(k._map.keys()).length)h._text+=
25
+ k._text,c.splice(l,1);else if(0===q&&e===g)c.splice(l,1);else{h=k;g=k._text;var m=q,p=e;g=g.slice(0,m)+""+g.slice(m+p);h._text=g}f-=e}else break}else if(null!=f)if("string"===typeof f){let {node:k,offset:l}=Q(this,d,!0);k instanceof F?(e=k,h=k._text,g=l,m=f,h=h.slice(0,g)+m+h.slice(g+0),e._text=h):this._xmlText.delete(l,f.length);d+=f.length}else e=f,{nodeIndex:f}=Q(this,d,!1),e=O(a,e,this),c.splice(f,0,e),d+=1;else throw Error("Unexpected delta format");}}syncChildrenFromYjs(a){var b=this.getNode();
26
+ null===b&&A(92);var c=b.__key;let d=S(b,null),e=d.length;var f=this._children;let h=f.length,g=a.collabNodeMap,m=new Set,p;let n=0;var k=null;h!==e&&b.getWritable();for(let x=0;x<h;x++){var l=d[n],q=f[x];var u=q.getNode();var t=q._key;if(null!==u&&l===t)k=r.$isTextNode(u),m.add(l),k&&(q._key=l,q instanceof P?(k=q._xmlText,q.syncPropertiesFromYjs(a,null),q.applyChildrenYjsDelta(a,k.toDelta()),q.syncChildrenFromYjs(a)):q instanceof F?q.syncPropertiesAndTextFromYjs(a,null):q instanceof U?q.syncPropertiesFromYjs(a,
27
+ null):q instanceof C||A(93)),k=u,n++;else{if(void 0===p)for(p=new Set,t=0;t<h;t++){var w=f[t]._key;""!==w&&p.add(w)}if(null!==u&&void 0!==l&&!p.has(l)){q=K(l);T(q);x--;n++;continue}u=b.getWritable();l=a;t=q;w=c;var B=t.getType();let D=l.editor._nodes.get(B);void 0===D&&A(88,B);B=new D.klass;B.__parent=w;t._key=B.__key;t instanceof P?(w=t._xmlText,t.syncPropertiesFromYjs(l,null),t.applyChildrenYjsDelta(l,w.toDelta()),t.syncChildrenFromYjs(l)):t instanceof F?t.syncPropertiesAndTextFromYjs(l,null):t instanceof
28
+ U&&t.syncPropertiesFromYjs(l,null);l.collabNodeMap.set(B.__key,t);l=B;t=l.__key;g.set(t,q);null===k?(k=u.getFirstChild(),u.__first=t,null!==k&&(k=k.getWritable(),k.__prev=t,l.__next=k.__key)):(q=k.getWritable(),w=k.getNextSibling(),q.__next=t,l.__prev=k.__key,null!==w&&(k=w.getWritable(),k.__prev=t,l.__next=k.__key));x===h-1&&(u.__last=t);u.__size++;k=l}}for(b=0;b<e;b++)f=d[b],m.has(f)||(c=K(f),f=a.collabNodeMap.get(f),void 0!==f&&f.destroy(a),T(c))}syncPropertiesFromLexical(a,b,c){G(a,this._xmlText,
29
+ this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=K(c);b instanceof P&&r.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof F&&r.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof U&&r.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var f=this.getPrevNode(c);let h=null===f?[]:S(f,c);f=S(b,null);let g=h.length-1,m=f.length-1,p=a.collabNodeMap,n,k,l=0;for(b=
30
+ 0;l<=g&&b<=m;){var q=h[l];let t=f[b];if(q===t)this._syncChildFromLexical(a,b,t,c,d,e),l++,b++;else{void 0===n&&(n=new Set(h));void 0===k&&(k=new Set(f));var u=k.has(q);q=n.has(t);u?(u=K(t),u=L(a,u,this),p.set(t,u),q?(this.splice(a,b,1,u),l++):this.splice(a,b,0,u),b++):(this.splice(a,b,1),l++)}}c=l>g;d=b>m;if(c&&!d)for(;b<=m;++b)c=f[b],d=K(c),d=L(a,d,this),this.append(d),p.set(c,d);else if(d&&!c)for(f=this._children.length-1;f>=b;f--)this.splice(a,f,1)}append(a){let b=this._xmlText;var c=this._children;
31
+ c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof P)b.insertEmbed(c,a._xmlText);else if(a instanceof F){let d=a._map;null===d.parent&&b.insertEmbed(c,d);b.insert(c+1,a._text)}else a instanceof C?b.insertEmbed(c,a._map):a instanceof U&&b.insertEmbed(c,a._xmlElem);this._children.push(a)}splice(a,b,c,d){let e=this._children;var f=e[b];if(void 0===f)void 0===d&&A(94),this.append(d);else{var h=f.getOffset();-1===h&&A(95);var g=this._xmlText;0!==c&&g.delete(h,f.getSize());d instanceof
32
+ P?g.insertEmbed(h,d._xmlText):d instanceof F?(f=d._map,null===f.parent&&g.insertEmbed(h,f),g.insert(h+1,d._text)):d instanceof C?g.insertEmbed(h,d._map):d instanceof U&&g.insertEmbed(h,d._xmlElem);if(0!==c)for(h=e.slice(b,b+c),g=0;g<h.length;g++)h[g].destroy(a);void 0!==d?e.splice(b,c,d):e.splice(b,c)}}getChildOffset(a){let b=0,c=this._children;for(let d=0;d<c.length;d++){let e=c[d];if(e===a)return b;b+=e.getSize()}return-1}destroy(a){let b=a.collabNodeMap,c=this._children;for(let d=0;d<c.length;d++)c[d].destroy(a);
32
33
  b.delete(this._key)}}function M(a,b,c){b=new P(a,b,c);return a._collabNode=b}
33
- function V(a,b){var c=b.collabNodeMap.get(a.key);if(void 0===c)return null;b=a.offset;let d=c.getSharedType();if(c instanceof E){d=c._parent._xmlText;a=c.getOffset();if(-1===a)return null;b=a+1+b}else if(c instanceof P&&"element"===a.type){let e=c=0;for(a=a.getNode().getFirstChild();null!==a&&e++<b;)t.$isTextNode(a)?c+=a.getTextContentSize()+1:c++,a=a.getNextSibling();b=c}return v.createRelativePositionFromTypeIndex(d,b)}
34
+ function V(a,b){var c=b.collabNodeMap.get(a.key);if(void 0===c)return null;b=a.offset;let d=c.getSharedType();if(c instanceof F){d=c._parent._xmlText;a=c.getOffset();if(-1===a)return null;b=a+1+b}else if(c instanceof P&&"element"===a.type){let e=c=0;for(a=a.getNode().getFirstChild();null!==a&&e++<b;)r.$isTextNode(a)?c+=a.getTextContentSize()+1:c++,a=a.getNextSibling();b=c}return v.createRelativePositionFromTypeIndex(d,b)}
34
35
  function W(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!v.compareRelativePositions(a,b))return!0;return!1}function X(a,b){a=a.cursorsContainer;if(null!==a){b=b.selections;let c=b.length;for(let d=0;d<c;d++)a.removeChild(b[d])}}
35
- function Y(a,b){var c=b.awareness.getLocalState();if(null!==c&&(b=c.anchorPos,c=c.focusPos,null!==b&&null!==c&&(b=v.createAbsolutePositionFromRelativePosition(b,a.doc),a=v.createAbsolutePositionFromRelativePosition(c,a.doc),null!==b&&null!==a))){let [d,e]=Z(b.type,b.index),[f,g]=Z(a.type,a.index);if(null!==d&&null!==f){b=d.getKey();c=f.getKey();let h=t.$getSelection();t.$isRangeSelection(h)&&(a=h.focus,ba(h.anchor,b,e),ba(a,c,g))}}}
36
- function ba(a,b,c){if(a.key!==b||a.offset!==c){let d=t.$getNodeByKey(b);if(null!==d&&!t.$isElementNode(d)&&!t.$isTextNode(d)){let e=d.getParentOrThrow();b=e.getKey();c=d.getIndexWithinParent();d=e}a.set(b,c,t.$isElementNode(d)?"element":"text")}}function Z(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof P){let {node:c,offset:d}=Q(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
37
- function ja(a,b){var c=Array.from(b.awareness.getStates()),d=a.clientID;b=a.cursors;var e=a.editor._editorState._nodeMap;let f=new Set;for(var g=0;g<c.length;g++){let [H,la]=c[g];if(H!==d){f.add(H);let {anchorPos:ca,focusPos:da,name:ma,color:na,focusing:oa}=la;var h=null,m=b.get(H);void 0===m&&(m={color:na,name:ma,selection:null},b.set(H,m));if(null!==ca&&null!==da&&oa){var n=v.createAbsolutePositionFromRelativePosition(ca,a.doc),p=v.createAbsolutePositionFromRelativePosition(da,a.doc);if(null!==
38
- n&&null!==p){let [ea,fa]=Z(n.type,n.index),[ha,ia]=Z(p.type,p.index);if(null!==ea&&null!==ha){n=ea.getKey();var k=ha.getKey();h=m.selection;if(null===h){h=m;p=fa;var l=ia,q=h.color,u=document.createElement("span");u.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${q};z-index:10;`;var r=document.createElement("span");r.textContent=h.name;r.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${q};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`;
39
- u.appendChild(r);h={anchor:{key:n,offset:p},caret:u,color:q,focus:{key:k,offset:l},name:r,selections:[]}}else p=h.anchor,l=h.focus,p.key=n,p.offset=fa,l.key=k,l.offset=ia}}}a:if(n=a,p=m,u=h,q=e,l=n.editor,h=l.getRootElement(),m=n.cursorsContainer,null!==m&&null!==h&&(h=m.offsetParent,null!==h))if(h=h.getBoundingClientRect(),k=p.selection,null===u)null!==k&&(p.selection=null,X(n,k));else{p.selection=u;p=u.caret;k=u.color;n=u.selections;r=u.anchor;u=u.focus;var w=r.key,A=u.key,x=q.get(w);q=q.get(A);
40
- if(null!=x&&null!=q){if(x===q&&t.$isLineBreakNode(x))q=[l.getElementByKey(w).getBoundingClientRect()];else{q=y.createDOMRange(l,x,r.offset,q,u.offset);if(null===q)break a;q=y.createRectsFromDOMRange(l,q)}u=n.length;l=q.length;for(r=0;r<l;r++)x=q[r],w=n[r],void 0===w&&(w=document.createElement("span"),n[r]=w,A=document.createElement("span"),w.appendChild(A),m.appendChild(w)),x=`position:absolute;top:${x.top-h.top}px;left:${x.left-h.left}px;height:${x.height}px;width:${x.width}px;pointer-events:none;z-index:5;`,
41
- w.style.cssText=x,w.firstChild.style.cssText=`${x}left:0;top:0;background-color:${k};opacity:0.3;`,r===l-1&&p.parentNode!==w&&w.appendChild(p);for(h=u-1;h>=l;h--)m.removeChild(n[h]),n.pop()}}}}c=Array.from(b.keys());for(d=0;d<c.length;d++)e=c[d],f.has(e)||(g=b.get(e),void 0!==g&&(g=g.selection,null!==g&&X(a,g),b.delete(e)))}
42
- function ka(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:g,name:h,color:m,focusing:n,awarenessData:p}=e,k=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)t.$isRangeSelection(d)&&(e=V(d.anchor,a),k=V(d.focus,a)),(W(f,e)||W(g,k))&&b.setLocalState({anchorPos:e,awarenessData:p,color:m,focusPos:k,focusing:n,name:h})}}let pa=t.createCommand("CONNECTED_COMMAND"),qa=t.createCommand("TOGGLE_CONNECT_COMMAND");exports.CONNECTED_COMMAND=pa;
43
- exports.TOGGLE_CONNECT_COMMAND=qa;exports.createBinding=function(a,b,c,d,e,f){void 0!==d&&null!==d||B(81);b=d.get("root",v.XmlText);b=M(b,null,"root");b._key="root";return{clientID:d.clientID,collabNodeMap:new Map,cursors:new Map,cursorsContainer:null,doc:d,docMap:e,editor:a,excludedProperties:f||new Map,id:c,nodeProperties:new Map,root:b}};exports.createUndoManager=function(a,b){return new v.UndoManager(b,{trackedOrigins:new Set([a,null])})};
44
- exports.initLocalState=function(a,b,c,d,e){a.awareness.setLocalState({anchorPos:null,awarenessData:e,color:c,focusPos:null,focusing:d,name:b})};exports.setLocalStateFocus=function(a,b,c,d,e){({awareness:a}=a);let f=a.getLocalState();null===f&&(f={anchorPos:null,awarenessData:e,color:c,focusPos:null,focusing:d,name:b});f.focusing=d;a.setLocalState(f)};exports.syncCursorPositions=ja;
45
- exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,g,h){aa(a,()=>{d.read(()=>{if(h.has("collaboration")||h.has("historic")){if(0<g.size){var m=Array.from(g),n=a.collabNodeMap,p=[];for(let u=0;u<m.length;u++){var k=m[u],l=t.$getNodeByKey(k),q=n.get(k);if(q instanceof E)if(t.$isTextNode(l))p.push([q,l.__text]);else{l=q.getOffset();if(-1===l)continue;let r=q._parent;q._normalized=!0;r._xmlText.delete(l,1);n.delete(k);k=r._children;q=k.indexOf(q);k.splice(q,1)}}for(m=0;m<p.length;m++){let [u,r]=p[m];
46
- u instanceof E&&"string"===typeof r&&(u._text=r)}}}else e.has("root")&&(p=c._nodeMap,m=t.$getRoot(),n=a.root,n.syncPropertiesFromLexical(a,m,p),n.syncChildrenFromLexical(a,m,p,e,f)),p=t.$getSelection(),ka(a,b,c._selection,p)})})};
47
- exports.syncYjsChangesToLexical=function(a,b,c,d){let e=a.editor,f=e._editorState;e.update(()=>{var g=e._pendingEditorState;for(var h=0;h<c.length;h++){var m=a,n=c[h],{target:p}=n;p=O(m,p);if(p instanceof P&&n instanceof v.YTextEvent){let {keysChanged:k,childListChanged:l,delta:q}=n;0<k.size&&p.syncPropertiesFromYjs(m,k);l&&(p.applyChildrenYjsDelta(m,q),p.syncChildrenFromYjs(m))}else p instanceof E&&n instanceof v.YMapEvent?({keysChanged:n}=n,0<n.size&&p.syncPropertiesAndTextFromYjs(m,n)):p instanceof
48
- U&&n instanceof v.YXmlEvent?({attributesChanged:n}=n,0<n.size&&p.syncPropertiesFromYjs(m,n)):B(82)}h=t.$getSelection();if(t.$isRangeSelection(h))if(R(h)){m=f._selection;if(t.$isRangeSelection(m)){p=z.$createOffsetView(e,0,f);g=z.$createOffsetView(e,0,g);let [k,l]=p.getOffsetsFromSelection(m);g=g.createSelectionFromOffsets(k,l,p);null!==g?t.$setSelection(g):(Y(a,b),R(h)&&(g=t.$getRoot(),0===g.getChildrenSize()&&g.append(t.$createParagraphNode()),t.$getRoot().selectEnd()))}ka(a,b,m,t.$getSelection())}else Y(a,
49
- b)},{onUpdate:()=>{ja(a,b)},skipTransforms:!0,tag:d?"historic":"collaboration"})}
36
+ function Y(a,b){var c=b.awareness.getLocalState();if(null!==c&&(b=c.anchorPos,c=c.focusPos,null!==b&&null!==c&&(b=v.createAbsolutePositionFromRelativePosition(b,a.doc),a=v.createAbsolutePositionFromRelativePosition(c,a.doc),null!==b&&null!==a))){let [d,e]=Z(b.type,b.index),[f,h]=Z(a.type,a.index);if(null!==d&&null!==f){b=d.getKey();c=f.getKey();let g=r.$getSelection();r.$isRangeSelection(g)&&(a=g.focus,ma(g.anchor,b,e),ma(a,c,h))}}}
37
+ function ma(a,b,c){if(a.key!==b||a.offset!==c){let d=r.$getNodeByKey(b);if(null!==d&&!r.$isElementNode(d)&&!r.$isTextNode(d)){let e=d.getParentOrThrow();b=e.getKey();c=d.getIndexWithinParent();d=e}a.set(b,c,r.$isElementNode(d)?"element":"text")}}function Z(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof P){let {node:c,offset:d}=Q(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
38
+ function na(a,b){var c=Array.from(b.awareness.getStates()),d=a.clientID;b=a.cursors;var e=a.editor._editorState._nodeMap;let f=new Set;for(var h=0;h<c.length;h++){let [D,pa]=c[h];if(D!==d){f.add(D);let {anchorPos:ca,focusPos:da,name:qa,color:ra,focusing:sa}=pa;var g=null,m=b.get(D);void 0===m&&(m={color:ra,name:qa,selection:null},b.set(D,m));if(null!==ca&&null!==da&&sa){var p=v.createAbsolutePositionFromRelativePosition(ca,a.doc),n=v.createAbsolutePositionFromRelativePosition(da,a.doc);if(null!==
39
+ p&&null!==n){let [ea,fa]=Z(p.type,p.index),[ha,ia]=Z(n.type,n.index);if(null!==ea&&null!==ha){p=ea.getKey();var k=ha.getKey();g=m.selection;if(null===g){g=m;n=fa;var l=ia,q=g.color,u=document.createElement("span");u.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${q};z-index:10;`;var t=document.createElement("span");t.textContent=g.name;t.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${q};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`;
40
+ u.appendChild(t);g={anchor:{key:p,offset:n},caret:u,color:q,focus:{key:k,offset:l},name:t,selections:[]}}else n=g.anchor,l=g.focus,n.key=p,n.offset=fa,l.key=k,l.offset=ia}}}a:if(p=a,n=m,u=g,q=e,l=p.editor,g=l.getRootElement(),m=p.cursorsContainer,null!==m&&null!==g&&(g=m.offsetParent,null!==g))if(g=g.getBoundingClientRect(),k=n.selection,null===u)null!==k&&(n.selection=null,X(p,k));else{n.selection=u;n=u.caret;k=u.color;p=u.selections;t=u.anchor;u=u.focus;var w=t.key,B=u.key,x=q.get(w);q=q.get(B);
41
+ if(null!=x&&null!=q){if(x===q&&r.$isLineBreakNode(x))q=[l.getElementByKey(w).getBoundingClientRect()];else{q=y.createDOMRange(l,x,t.offset,q,u.offset);if(null===q)break a;q=y.createRectsFromDOMRange(l,q)}u=p.length;l=q.length;for(t=0;t<l;t++)x=q[t],w=p[t],void 0===w&&(w=document.createElement("span"),p[t]=w,B=document.createElement("span"),w.appendChild(B),m.appendChild(w)),x=`position:absolute;top:${x.top-g.top}px;left:${x.left-g.left}px;height:${x.height}px;width:${x.width}px;pointer-events:none;z-index:5;`,
42
+ w.style.cssText=x,w.firstChild.style.cssText=`${x}left:0;top:0;background-color:${k};opacity:0.3;`,t===l-1&&n.parentNode!==w&&w.appendChild(n);for(g=u-1;g>=l;g--)m.removeChild(p[g]),p.pop()}}}}c=Array.from(b.keys());for(d=0;d<c.length;d++)e=c[d],f.has(e)||(h=b.get(e),void 0!==h&&(h=h.selection,null!==h&&X(a,h),b.delete(e)))}
43
+ function oa(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:h,name:g,color:m,focusing:p,awarenessData:n}=e,k=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)r.$isRangeSelection(d)&&(e=V(d.anchor,a),k=V(d.focus,a)),(W(f,e)||W(h,k))&&b.setLocalState({anchorPos:e,awarenessData:n,color:m,focusPos:k,focusing:p,name:g})}}let ta=r.createCommand("CONNECTED_COMMAND"),ua=r.createCommand("TOGGLE_CONNECT_COMMAND");exports.CONNECTED_COMMAND=ta;
44
+ exports.TOGGLE_CONNECT_COMMAND=ua;exports.createBinding=function(a,b,c,d,e,f){void 0!==d&&null!==d||A(81);b=d.get("root",v.XmlText);b=M(b,null,"root");b._key="root";return{clientID:d.clientID,collabNodeMap:new Map,cursors:new Map,cursorsContainer:null,doc:d,docMap:e,editor:a,excludedProperties:f||new Map,id:c,nodeProperties:new Map,root:b}};exports.createUndoManager=function(a,b){return new v.UndoManager(b,{trackedOrigins:new Set([a,null])})};
45
+ exports.initLocalState=function(a,b,c,d,e){a.awareness.setLocalState({anchorPos:null,awarenessData:e,color:c,focusPos:null,focusing:d,name:b})};exports.setLocalStateFocus=function(a,b,c,d,e){({awareness:a}=a);let f=a.getLocalState();null===f&&(f={anchorPos:null,awarenessData:e,color:c,focusPos:null,focusing:d,name:b});f.focusing=d;a.setLocalState(f)};exports.syncCursorPositions=na;
46
+ exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,h,g){la(a,()=>{d.read(()=>{if(g.has("collaboration")||g.has("historic")){if(0<h.size){var m=Array.from(h),p=a.collabNodeMap,n=[];for(let u=0;u<m.length;u++){var k=m[u],l=r.$getNodeByKey(k),q=p.get(k);if(q instanceof F)if(r.$isTextNode(l))n.push([q,l.__text]);else{l=q.getOffset();if(-1===l)continue;let t=q._parent;q._normalized=!0;t._xmlText.delete(l,1);p.delete(k);k=t._children;q=k.indexOf(q);k.splice(q,1)}}for(m=0;m<n.length;m++){let [u,t]=n[m];
47
+ u instanceof F&&"string"===typeof t&&(u._text=t)}}}else e.has("root")&&(n=c._nodeMap,m=r.$getRoot(),p=a.root,p.syncPropertiesFromLexical(a,m,n),p.syncChildrenFromLexical(a,m,n,e,f)),n=r.$getSelection(),oa(a,b,c._selection,n)})})};
48
+ exports.syncYjsChangesToLexical=function(a,b,c,d){let e=a.editor,f=e._editorState;c.forEach(h=>h.delta);e.update(()=>{var h=e._pendingEditorState;for(var g=0;g<c.length;g++){var m=a,p=c[g],{target:n}=p;n=O(m,n);if(n instanceof P&&p instanceof v.YTextEvent){let {keysChanged:k,childListChanged:l,delta:q}=p;0<k.size&&n.syncPropertiesFromYjs(m,k);l&&(n.applyChildrenYjsDelta(m,q),n.syncChildrenFromYjs(m))}else n instanceof F&&p instanceof v.YMapEvent?({keysChanged:p}=p,0<p.size&&n.syncPropertiesAndTextFromYjs(m,
49
+ p)):n instanceof U&&p instanceof v.YXmlEvent?({attributesChanged:p}=p,0<p.size&&n.syncPropertiesFromYjs(m,p)):A(82)}g=r.$getSelection();if(r.$isRangeSelection(g))if(R(g)){m=f._selection;if(r.$isRangeSelection(m)){n=z.$createOffsetView(e,0,f);h=z.$createOffsetView(e,0,h);let [k,l]=n.getOffsetsFromSelection(m);h=h.createSelectionFromOffsets(k,l,n);null!==h?r.$setSelection(h):(Y(a,b),R(g)&&(h=r.$getRoot(),0===h.getChildrenSize()&&h.append(r.$createParagraphNode()),r.$getRoot().selectEnd()))}oa(a,b,m,
50
+ r.$getSelection())}else Y(a,b)},{onUpdate:()=>{na(a,b)},skipTransforms:!0,tag:d?"historic":"collaboration"})}
package/SyncCursors.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  import type { Binding } from './Bindings';
9
9
  import type { GridSelection, NodeKey, NodeSelection, RangeSelection } from 'lexical';
10
10
  import { Provider } from '.';
11
- export declare type CursorSelection = {
11
+ export type CursorSelection = {
12
12
  anchor: {
13
13
  key: NodeKey;
14
14
  offset: number;
@@ -22,7 +22,7 @@ export declare type CursorSelection = {
22
22
  name: HTMLSpanElement;
23
23
  selections: Array<HTMLElement>;
24
24
  };
25
- export declare type Cursor = {
25
+ export type Cursor = {
26
26
  color: string;
27
27
  name: string;
28
28
  selection: null | CursorSelection;
@@ -9,6 +9,6 @@ import type { EditorState, NodeKey } from 'lexical';
9
9
  import { Text as YText, YEvent } from 'yjs';
10
10
  import { Binding, Provider } from '.';
11
11
  export declare function syncYjsChangesToLexical(binding: Binding, provider: Provider, events: Array<YEvent<YText>>, isFromUndoManger: boolean): void;
12
- declare type IntentionallyMarkedAsDirtyElement = boolean;
12
+ type IntentionallyMarkedAsDirtyElement = boolean;
13
13
  export declare function syncLexicalUpdateToYjs(binding: Binding, provider: Provider, prevEditorState: EditorState, currEditorState: EditorState, dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>, dirtyLeaves: Set<NodeKey>, normalizedNodes: Set<NodeKey>, tags: Set<string>): void;
14
14
  export {};
package/index.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  import type { Binding } from './Bindings';
10
10
  import type { LexicalCommand } from 'lexical';
11
11
  import type { Doc, RelativePosition, UndoManager, XmlText } from 'yjs';
12
- export declare type UserState = {
12
+ export type UserState = {
13
13
  anchorPos: null | RelativePosition;
14
14
  color: string;
15
15
  focusing: boolean;
@@ -19,7 +19,7 @@ export declare type UserState = {
19
19
  };
20
20
  export declare const CONNECTED_COMMAND: LexicalCommand<boolean>;
21
21
  export declare const TOGGLE_CONNECT_COMMAND: LexicalCommand<boolean>;
22
- export declare type ProviderAwareness = {
22
+ export type ProviderAwareness = {
23
23
  getLocalState: () => UserState | null;
24
24
  getStates: () => Map<number, UserState>;
25
25
  off: (type: 'update', cb: () => void) => void;
@@ -43,15 +43,15 @@ declare interface Provider {
43
43
  on(type: 'update', cb: (arg0: unknown) => void): void;
44
44
  on(type: 'reload', cb: (doc: Doc) => void): void;
45
45
  }
46
- export declare type Operation = {
46
+ export type Operation = {
47
47
  attributes: {
48
48
  __type: string;
49
49
  };
50
50
  insert: string | Record<string, unknown>;
51
51
  };
52
- export declare type Delta = Array<Operation>;
53
- export declare type YjsNode = Record<string, unknown>;
54
- export declare type YjsEvent = Record<string, unknown>;
52
+ export type Delta = Array<Operation>;
53
+ export type YjsNode = Record<string, unknown>;
54
+ export type YjsEvent = Record<string, unknown>;
55
55
  export type { Provider };
56
56
  export type { Binding, ClientID, ExcludedProperties } from './Bindings';
57
57
  export { createBinding } from './Bindings';
package/package.json CHANGED
@@ -11,13 +11,13 @@
11
11
  "crdt"
12
12
  ],
13
13
  "license": "MIT",
14
- "version": "0.11.0",
14
+ "version": "0.11.2",
15
15
  "main": "LexicalYjs.js",
16
16
  "dependencies": {
17
- "@lexical/offset": "0.11.0"
17
+ "@lexical/offset": "0.11.2"
18
18
  },
19
19
  "peerDependencies": {
20
- "lexical": "0.11.0",
20
+ "lexical": "0.11.2",
21
21
  "yjs": ">=13.5.22"
22
22
  },
23
23
  "repository": {