@lexical/yjs 0.9.0 → 0.9.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 +4 -1
- package/LexicalYjs.dev.js +10 -2
- package/LexicalYjs.js.flow +3 -0
- package/LexicalYjs.prod.js +26 -26
- package/index.d.ts +1 -1
- package/package.json +3 -3
package/Bindings.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type { CollabTextNode } from './CollabTextNode';
|
|
|
12
12
|
import type { Cursor } from './SyncCursors';
|
|
13
13
|
import type { LexicalEditor, NodeKey } from 'lexical';
|
|
14
14
|
import type { Doc } from 'yjs';
|
|
15
|
+
import { Klass, LexicalNode } from 'lexical';
|
|
15
16
|
import { Provider } from '.';
|
|
16
17
|
export declare type ClientID = number;
|
|
17
18
|
export declare type Binding = {
|
|
@@ -25,5 +26,7 @@ export declare type Binding = {
|
|
|
25
26
|
id: string;
|
|
26
27
|
nodeProperties: Map<string, Array<string>>;
|
|
27
28
|
root: CollabElementNode;
|
|
29
|
+
excludedProperties: ExcludedProperties;
|
|
28
30
|
};
|
|
29
|
-
export declare
|
|
31
|
+
export declare type ExcludedProperties = Map<Klass<LexicalNode>, Set<string>>;
|
|
32
|
+
export declare function createBinding(editor: LexicalEditor, provider: Provider, id: string, doc: Doc | null | undefined, docMap: Map<string, Doc>, excludedProperties?: ExcludedProperties): Binding;
|
package/LexicalYjs.dev.js
CHANGED
|
@@ -362,6 +362,12 @@ function syncPropertiesFromYjs(binding, sharedType, lexicalNode, keysChanged) {
|
|
|
362
362
|
continue;
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
+
const additionalExcludedProperties = binding.excludedProperties.get(lexicalNode.constructor);
|
|
366
|
+
|
|
367
|
+
if (additionalExcludedProperties !== undefined && additionalExcludedProperties.has(property)) {
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
|
|
365
371
|
const prevValue = lexicalNode[property];
|
|
366
372
|
let nextValue = sharedType instanceof yjs.Map ? sharedType.get(property) : sharedType.getAttribute(property);
|
|
367
373
|
|
|
@@ -394,8 +400,9 @@ function syncPropertiesFromLexical(binding, sharedType, prevLexicalNode, nextLex
|
|
|
394
400
|
let properties = nodeProperties.get(type);
|
|
395
401
|
|
|
396
402
|
if (properties === undefined) {
|
|
403
|
+
const additionalExlcudedProperties = binding.excludedProperties.get(nextLexicalNode.constructor);
|
|
397
404
|
properties = Object.keys(nextLexicalNode).filter(property => {
|
|
398
|
-
return !excludedProperties.has(property);
|
|
405
|
+
return !excludedProperties.has(property) || additionalExlcudedProperties && !additionalExlcudedProperties.has(property);
|
|
399
406
|
});
|
|
400
407
|
nodeProperties.set(type, properties);
|
|
401
408
|
}
|
|
@@ -1187,7 +1194,7 @@ function $createCollabElementNode(xmlText, parent, type) {
|
|
|
1187
1194
|
* LICENSE file in the root directory of this source tree.
|
|
1188
1195
|
*
|
|
1189
1196
|
*/
|
|
1190
|
-
function createBinding(editor, provider, id, doc, docMap) {
|
|
1197
|
+
function createBinding(editor, provider, id, doc, docMap, excludedProperties) {
|
|
1191
1198
|
if (!(doc !== undefined && doc !== null)) {
|
|
1192
1199
|
throw Error(`createBinding: doc is null or undefined`);
|
|
1193
1200
|
}
|
|
@@ -1203,6 +1210,7 @@ function createBinding(editor, provider, id, doc, docMap) {
|
|
|
1203
1210
|
doc,
|
|
1204
1211
|
docMap,
|
|
1205
1212
|
editor,
|
|
1213
|
+
excludedProperties: excludedProperties || new Map(),
|
|
1206
1214
|
id,
|
|
1207
1215
|
nodeProperties: new Map(),
|
|
1208
1216
|
root
|
package/LexicalYjs.js.flow
CHANGED
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
ElementNode,
|
|
15
15
|
LexicalCommand,
|
|
16
16
|
LexicalEditor,
|
|
17
|
+
LexicalNode,
|
|
17
18
|
LineBreakNode,
|
|
18
19
|
NodeMap,
|
|
19
20
|
NodeKey,
|
|
@@ -110,6 +111,8 @@ export type Binding = {
|
|
|
110
111
|
root: CollabElementNode,
|
|
111
112
|
};
|
|
112
113
|
|
|
114
|
+
export type ExcludedProperties = Map<Class<LexicalNode>, Set<string>>;
|
|
115
|
+
|
|
113
116
|
declare export class CollabDecoratorNode {
|
|
114
117
|
_xmlElem: XmlElement;
|
|
115
118
|
_key: NodeKey;
|
package/LexicalYjs.prod.js
CHANGED
|
@@ -7,43 +7,43 @@
|
|
|
7
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
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
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,
|
|
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
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
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
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
|
|
15
|
-
function F(a,b,c,d){var e=d.__type,f=a.nodeProperties;let
|
|
16
|
-
function Q(a,b,c){let d=0,e=0,f=a._children,
|
|
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 l=d[h];if(!J.has(l)){var f=a.excludedProperties.get(c.constructor);if(void 0===f||!f.has(l)){var g=c[l];f=b instanceof v.Map?b.get(l):b.getAttribute(l);if(g!==f){if(f instanceof v.Doc){let m=a.docMap;g instanceof v.Doc&&m.delete(g.guid);g=t.createEditor();let n=f.guid;g._key=n;m.set(n,f);f=g}void 0===e&&(e=c.getWritable());e[l]=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 l=a.excludedProperties.get(d.constructor);g=Object.keys(d).filter(m=>!J.has(m)||l&&!l.has(m));f.set(e,g)}e=a.editor.constructor;for(f=0;f<g.length;f++){let l=g[f];var h=null===c?void 0:c[l];let m=d[l];if(h!==m){if(m instanceof e){let n=a.docMap,p;h instanceof e&&(h=h._key,p=n.get(h),n.delete(h));h=p||new v.Doc;let k=h.guid;m._key=k;n.set(k,h);m=h;a.editor.update(()=>{d.markDirty()})}b instanceof v.Map?b.set(l,
|
|
16
|
+
m):b.setAttribute(l,m)}}}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,l=a.getSize();d+=l;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
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}
|
|
18
18
|
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
19
|
a.__prev=c.__key):a.__prev=null,e.__next=null);b.__size--;e.__parent=null}}
|
|
20
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
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
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
|
|
24
|
-
|
|
25
|
-
null===b&&B(92);var c=b.__key;let d=S(b,null),e=d.length;var f=this._children;let
|
|
26
|
-
null):q instanceof C||B(93)),
|
|
27
|
-
null);k.collabNodeMap.set(A.__key,r);k=A;r=k.__key;
|
|
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
|
|
29
|
-
0;k<=
|
|
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
|
|
31
|
-
P?
|
|
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 n=0;n<b.length;n++){var e=b[n],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:p,nodeIndex:k,offset:q,length:u}=Q(this,d,!1);if(p instanceof P||p instanceof C||p instanceof U)c.splice(k,1),--f;else if(p instanceof E){e=Math.min(f,u);g=0!==k?c[k-1]:null;var h=p.getSize();if(0===q&&1===e&&0<k&&g instanceof E&&u===h&&0===Array.from(p._map.keys()).length)g._text+=
|
|
24
|
+
p._text,c.splice(k,1);else if(0===q&&e===h)c.splice(k,1);else{g=p;h=p._text;var l=q,m=e;h=h.slice(0,l)+""+h.slice(l+m);g._text=h}f-=e}else break}else if(null!=f)if("string"===typeof f){let {node:p,offset:k}=Q(this,d,!0);p instanceof E?(e=p,g=p._text,h=k,l=f,g=g.slice(0,h)+l+g.slice(h+0),e._text=g):this._xmlText.delete(k,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,l=new Set,m;let n=0;var p=null;g!==e&&b.getWritable();for(let x=0;x<g;x++){var k=d[n],q=f[x];var u=q.getNode();var r=q._key;if(null!==u&&k===r)p=t.$isTextNode(u),l.add(k),p&&(q._key=k,q instanceof P?(p=q._xmlText,q.syncPropertiesFromYjs(a,null),q.applyChildrenYjsDelta(a,p.toDelta()),q.syncChildrenFromYjs(a)):q instanceof E?q.syncPropertiesAndTextFromYjs(a,null):q instanceof U?q.syncPropertiesFromYjs(a,
|
|
26
|
+
null):q instanceof C||B(93)),p=u,n++;else{if(void 0===m)for(m=new Set,r=0;r<g;r++){var w=f[r]._key;""!==w&&m.add(w)}if(null===u||void 0===k||m.has(k)){u=b.getWritable();k=a;r=q;w=c;var A=r.getType();A=k.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(k,null),r.applyChildrenYjsDelta(k,w.toDelta()),r.syncChildrenFromYjs(k)):r instanceof E?r.syncPropertiesAndTextFromYjs(k,null):r instanceof U&&r.syncPropertiesFromYjs(k,
|
|
27
|
+
null);k.collabNodeMap.set(A.__key,r);k=A;r=k.__key;h.set(r,q);null===p?(p=u.getFirstChild(),u.__first=r,null!==p&&(p=p.getWritable(),p.__prev=r,k.__next=p.__key)):(q=p.getWritable(),w=p.getNextSibling(),q.__next=r,k.__prev=p.__key,null!==w&&(p=w.getWritable(),p.__prev=r,k.__next=p.__key));x===g-1&&(u.__last=r);u.__size++;p=k}else q=K(k),T(q),x--,n++}}for(b=0;b<e;b++)f=d[b],l.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,l=f.length-1,m=a.collabNodeMap,n,p,k=0;for(b=
|
|
29
|
+
0;k<=h&&b<=l;){var q=g[k];let r=f[b];if(q===r)this._syncChildFromLexical(a,b,r,c,d,e),k++,b++;else{void 0===n&&(n=new Set(g));void 0===p&&(p=new Set(f));var u=p.has(q);q=n.has(r);u?(u=K(r),u=L(a,u,this),m.set(r,u),q?(this.splice(a,b,1,u),k++):this.splice(a,b,0,u),b++):(this.splice(a,b,1),k++)}}c=k>h;d=b>l;if(c&&!d)for(;b<=l;++b)c=f[b],d=K(c),d=L(a,d,this),this.append(d),m.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);
|
|
32
32
|
b.delete(this._key)}}function M(a,b,c){b=new P(a,b,c);return a._collabNode=b}
|
|
33
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
34
|
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,
|
|
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
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
|
|
38
|
-
|
|
39
|
-
u.appendChild(r);
|
|
40
|
-
if(null!=x&&null!=q){if(x===q&&t.$isLineBreakNode(x))q=[k.getElementByKey(w).getBoundingClientRect()];else{q=y.createDOMRange(k,x,r.offset,q,u.offset);if(null===q)break a;q=y.createRectsFromDOMRange(k,q)}u=
|
|
41
|
-
w.style.cssText=x,w.firstChild.style.cssText=`${x}left:0;top:0;background-color:${
|
|
42
|
-
function ka(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:
|
|
43
|
-
exports.createBinding=function(a,b,c,d,e){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,id:c,nodeProperties:new Map,root:b}};exports.createUndoManager=function(a,b){return new v.UndoManager(b,{trackedOrigins:new Set([a,null])})};
|
|
44
|
-
exports.setLocalStateFocus=function(a,b,c,d){({awareness:a}=a);let e=a.getLocalState();null===e&&(e={anchorPos:null,color:c,focusPos:null,focusing:d,name:b});e.focusing=d;a.setLocalState(e)};exports.syncCursorPositions=ja;
|
|
45
|
-
exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,h
|
|
46
|
-
u instanceof E&&"string"===typeof r&&(u._text=r)}}}else e.has("root")&&(
|
|
47
|
-
exports.syncYjsChangesToLexical=function(a,b,c,d){let e=a.editor,f=e._editorState;e.update(()=>{var
|
|
48
|
-
U&&
|
|
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,l=b.get(H);void 0===l&&(l={color:na,name:ma,selection:null},b.set(H,l));if(null!==ca&&null!==da&&oa){var m=v.createAbsolutePositionFromRelativePosition(ca,a.doc),n=v.createAbsolutePositionFromRelativePosition(da,a.doc);if(null!==
|
|
38
|
+
m&&null!==n){let [ea,fa]=Z(m.type,m.index),[ha,ia]=Z(n.type,n.index);if(null!==ea&&null!==ha){m=ea.getKey();var p=ha.getKey();h=l.selection;if(null===h){h=l;n=fa;var k=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:m,offset:n},caret:u,color:q,focus:{key:p,offset:k},name:r,selections:[]}}else n=h.anchor,k=h.focus,n.key=m,n.offset=fa,k.key=p,k.offset=ia}}}a:if(m=a,n=l,u=h,q=e,k=m.editor,h=k.getRootElement(),l=m.cursorsContainer,null!==l&&null!==h&&(h=l.offsetParent,null!==h))if(h=h.getBoundingClientRect(),p=n.selection,null===u)null!==p&&(n.selection=null,X(m,p));else{n.selection=u;n=u.caret;p=u.color;m=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=[k.getElementByKey(w).getBoundingClientRect()];else{q=y.createDOMRange(k,x,r.offset,q,u.offset);if(null===q)break a;q=y.createRectsFromDOMRange(k,q)}u=m.length;k=q.length;for(r=0;r<k;r++)x=q[r],w=m[r],void 0===w&&(w=document.createElement("span"),m[r]=w,A=document.createElement("span"),w.appendChild(A),l.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:${p};opacity:0.3;`,r===k-1&&n.parentNode!==w&&w.appendChild(n);for(h=u-1;h>=k;h--)l.removeChild(m[h]),m.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:l,focusing:m}=e,n=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)t.$isRangeSelection(d)&&(e=V(d.anchor,a),n=V(d.focus,a)),(W(f,e)||W(g,n))&&b.setLocalState({anchorPos:e,color:l,focusPos:n,focusing:m,name:h})}}let pa=t.createCommand("CONNECTED_COMMAND"),qa=t.createCommand("TOGGLE_CONNECT_COMMAND");exports.CONNECTED_COMMAND=pa;exports.TOGGLE_CONNECT_COMMAND=qa;
|
|
43
|
+
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){a.awareness.setLocalState({anchorPos:null,color:c,focusPos:null,focusing:d,name:b})};exports.setLocalStateFocus=function(a,b,c,d){({awareness:a}=a);let e=a.getLocalState();null===e&&(e={anchorPos:null,color:c,focusPos:null,focusing:d,name:b});e.focusing=d;a.setLocalState(e)};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 l=Array.from(g),m=a.collabNodeMap,n=[];for(let u=0;u<l.length;u++){var p=l[u],k=t.$getNodeByKey(p),q=m.get(p);if(q instanceof E)if(t.$isTextNode(k))n.push([q,k.__text]);else{k=q.getOffset();if(-1===k)continue;let r=q._parent;q._normalized=!0;r._xmlText.delete(k,1);m.delete(p);p=r._children;q=p.indexOf(q);p.splice(q,1)}}for(l=0;l<n.length;l++){let [u,r]=n[l];
|
|
46
|
+
u instanceof E&&"string"===typeof r&&(u._text=r)}}}else e.has("root")&&(n=c._nodeMap,l=t.$getRoot(),m=a.root,m.syncPropertiesFromLexical(a,l,n),m.syncChildrenFromLexical(a,l,n,e,f)),n=t.$getSelection(),ka(a,b,c._selection,n)})})};
|
|
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 l=a,m=c[h],{target:n}=m;n=O(l,n);if(n instanceof P&&m instanceof v.YTextEvent){let {keysChanged:p,childListChanged:k,delta:q}=m;0<p.size&&n.syncPropertiesFromYjs(l,p);k&&(n.applyChildrenYjsDelta(l,q),n.syncChildrenFromYjs(l))}else n instanceof E&&m instanceof v.YMapEvent?({keysChanged:m}=m,0<m.size&&n.syncPropertiesAndTextFromYjs(l,m)):n instanceof
|
|
48
|
+
U&&m instanceof v.YXmlEvent?({attributesChanged:m}=m,0<m.size&&n.syncPropertiesFromYjs(l,m)):B(82)}h=t.$getSelection();if(t.$isRangeSelection(h))if(R(h)){l=f._selection;if(t.$isRangeSelection(l)){n=z.$createOffsetView(e,0,f);g=z.$createOffsetView(e,0,g);let [p,k]=n.getOffsetsFromSelection(l);g=g.createSelectionFromOffsets(p,k,n);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,l,t.$getSelection())}else Y(a,
|
|
49
49
|
b)},{onUpdate:()=>{ja(a,b)},skipTransforms:!0,tag:d?"historic":"collaboration"})}
|
package/index.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export declare type Delta = Array<Operation>;
|
|
|
52
52
|
export declare type YjsNode = Record<string, unknown>;
|
|
53
53
|
export declare type YjsEvent = Record<string, unknown>;
|
|
54
54
|
export type { Provider };
|
|
55
|
-
export type { Binding, ClientID } from './Bindings';
|
|
55
|
+
export type { Binding, ClientID, ExcludedProperties } from './Bindings';
|
|
56
56
|
export { createBinding } from './Bindings';
|
|
57
57
|
export declare function createUndoManager(binding: Binding, root: XmlText): UndoManager;
|
|
58
58
|
export declare function initLocalState(provider: Provider, name: string, color: string, focusing: boolean): void;
|
package/package.json
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"crdt"
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"version": "0.9.
|
|
14
|
+
"version": "0.9.2",
|
|
15
15
|
"main": "LexicalYjs.js",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/offset": "0.9.
|
|
17
|
+
"@lexical/offset": "0.9.2"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"lexical": "0.9.
|
|
20
|
+
"lexical": "0.9.2",
|
|
21
21
|
"yjs": ">=13.5.22"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|