@lexical/yjs 0.47.1-nightly.20260715.0 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Bindings.d.ts +18 -0
- package/dist/LexicalYjs.dev.js +31 -8
- package/dist/LexicalYjs.dev.mjs +31 -9
- package/dist/LexicalYjs.mjs +1 -0
- package/dist/LexicalYjs.node.mjs +1 -0
- package/dist/LexicalYjs.prod.js +1 -1
- package/dist/LexicalYjs.prod.mjs +1 -1
- package/dist/index.d.ts +2 -2
- package/package.json +4 -4
- package/src/Bindings.ts +42 -17
- package/src/index.ts +6 -1
package/dist/Bindings.d.ts
CHANGED
|
@@ -43,6 +43,24 @@ export interface BindingV2 extends BaseBinding {
|
|
|
43
43
|
}
|
|
44
44
|
export type AnyBinding = Binding | BindingV2;
|
|
45
45
|
export type ExcludedProperties = Map<Klass<LexicalNode>, Set<string>>;
|
|
46
|
+
/** Options for {@link createYjsBinding}. */
|
|
47
|
+
export interface CreateYjsBindingOptions {
|
|
48
|
+
editor: LexicalEditor;
|
|
49
|
+
/** Identifier for this binding, used as the key in `docMap`. */
|
|
50
|
+
id: string;
|
|
51
|
+
doc: Doc;
|
|
52
|
+
docMap: Map<string, Doc>;
|
|
53
|
+
excludedProperties?: ExcludedProperties;
|
|
54
|
+
/** The key used to look up the root `XmlText` shared type on the Yjs `Doc`. Defaults to `'root'`. */
|
|
55
|
+
rootName?: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create a V1 Yjs {@link Binding} that connects a {@link LexicalEditor} to a
|
|
59
|
+
* Yjs `Doc` for real-time collaboration.
|
|
60
|
+
*
|
|
61
|
+
* For the legacy positional-argument API, see {@link createBinding}.
|
|
62
|
+
*/
|
|
63
|
+
export declare function createYjsBinding({ editor, id, doc, docMap, excludedProperties, rootName, }: CreateYjsBindingOptions): Binding;
|
|
46
64
|
export declare function createBinding(editor: LexicalEditor, provider: Provider, id: string, doc: Doc | null | undefined, docMap: Map<string, Doc>, excludedProperties?: ExcludedProperties): Binding;
|
|
47
65
|
export declare function createBindingV2__EXPERIMENTAL(editor: LexicalEditor, id: string, doc: Doc | null | undefined, docMap: Map<string, Doc>, options?: {
|
|
48
66
|
excludedProperties?: ExcludedProperties;
|
package/dist/LexicalYjs.dev.js
CHANGED
|
@@ -901,9 +901,6 @@ class CollabV2Mapping {
|
|
|
901
901
|
}
|
|
902
902
|
|
|
903
903
|
function createBaseBinding(editor, id, doc, docMap, excludedProperties) {
|
|
904
|
-
if (!(doc !== undefined && doc !== null)) {
|
|
905
|
-
formatDevErrorMessage(`createBinding: doc is null or undefined`);
|
|
906
|
-
}
|
|
907
904
|
const binding = {
|
|
908
905
|
clientID: doc.clientID,
|
|
909
906
|
cursorHighlightSheet: null,
|
|
@@ -919,11 +916,24 @@ function createBaseBinding(editor, id, doc, docMap, excludedProperties) {
|
|
|
919
916
|
initializeNodeProperties(binding);
|
|
920
917
|
return binding;
|
|
921
918
|
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
919
|
+
|
|
920
|
+
/** Options for {@link createYjsBinding}. */
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* Create a V1 Yjs {@link Binding} that connects a {@link LexicalEditor} to a
|
|
924
|
+
* Yjs `Doc` for real-time collaboration.
|
|
925
|
+
*
|
|
926
|
+
* For the legacy positional-argument API, see {@link createBinding}.
|
|
927
|
+
*/
|
|
928
|
+
function createYjsBinding({
|
|
929
|
+
editor,
|
|
930
|
+
id,
|
|
931
|
+
doc,
|
|
932
|
+
docMap,
|
|
933
|
+
excludedProperties,
|
|
934
|
+
rootName = 'root'
|
|
935
|
+
}) {
|
|
936
|
+
const rootXmlText = doc.get(rootName, yjs.XmlText);
|
|
927
937
|
const root = $createCollabElementNode(rootXmlText, null, 'root');
|
|
928
938
|
root._key = 'root';
|
|
929
939
|
return {
|
|
@@ -932,6 +942,18 @@ function createBinding(editor, provider, id, doc, docMap, excludedProperties) {
|
|
|
932
942
|
root
|
|
933
943
|
};
|
|
934
944
|
}
|
|
945
|
+
function createBinding(editor, provider, id, doc, docMap, excludedProperties) {
|
|
946
|
+
if (!(doc !== undefined && doc !== null)) {
|
|
947
|
+
formatDevErrorMessage(`createBinding: doc is null or undefined`);
|
|
948
|
+
}
|
|
949
|
+
return createYjsBinding({
|
|
950
|
+
doc,
|
|
951
|
+
docMap,
|
|
952
|
+
editor,
|
|
953
|
+
excludedProperties,
|
|
954
|
+
id
|
|
955
|
+
});
|
|
956
|
+
}
|
|
935
957
|
function createBindingV2__EXPERIMENTAL(editor, id, doc, docMap, options = {}) {
|
|
936
958
|
if (!(doc !== undefined && doc !== null)) {
|
|
937
959
|
formatDevErrorMessage(`createBinding: doc is null or undefined`);
|
|
@@ -3705,6 +3727,7 @@ exports.TOGGLE_CONNECT_COMMAND = TOGGLE_CONNECT_COMMAND;
|
|
|
3705
3727
|
exports.createBinding = createBinding;
|
|
3706
3728
|
exports.createBindingV2__EXPERIMENTAL = createBindingV2__EXPERIMENTAL;
|
|
3707
3729
|
exports.createUndoManager = createUndoManager;
|
|
3730
|
+
exports.createYjsBinding = createYjsBinding;
|
|
3708
3731
|
exports.getAnchorAndFocusCollabNodesForUserState = getAnchorAndFocusCollabNodesForUserState;
|
|
3709
3732
|
exports.initLocalState = initLocalState;
|
|
3710
3733
|
exports.removeCursorHighlightRule = removeCursorHighlightRule;
|
package/dist/LexicalYjs.dev.mjs
CHANGED
|
@@ -899,9 +899,6 @@ class CollabV2Mapping {
|
|
|
899
899
|
}
|
|
900
900
|
|
|
901
901
|
function createBaseBinding(editor, id, doc, docMap, excludedProperties) {
|
|
902
|
-
if (!(doc !== undefined && doc !== null)) {
|
|
903
|
-
formatDevErrorMessage(`createBinding: doc is null or undefined`);
|
|
904
|
-
}
|
|
905
902
|
const binding = {
|
|
906
903
|
clientID: doc.clientID,
|
|
907
904
|
cursorHighlightSheet: null,
|
|
@@ -917,11 +914,24 @@ function createBaseBinding(editor, id, doc, docMap, excludedProperties) {
|
|
|
917
914
|
initializeNodeProperties(binding);
|
|
918
915
|
return binding;
|
|
919
916
|
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
917
|
+
|
|
918
|
+
/** Options for {@link createYjsBinding}. */
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* Create a V1 Yjs {@link Binding} that connects a {@link LexicalEditor} to a
|
|
922
|
+
* Yjs `Doc` for real-time collaboration.
|
|
923
|
+
*
|
|
924
|
+
* For the legacy positional-argument API, see {@link createBinding}.
|
|
925
|
+
*/
|
|
926
|
+
function createYjsBinding({
|
|
927
|
+
editor,
|
|
928
|
+
id,
|
|
929
|
+
doc,
|
|
930
|
+
docMap,
|
|
931
|
+
excludedProperties,
|
|
932
|
+
rootName = 'root'
|
|
933
|
+
}) {
|
|
934
|
+
const rootXmlText = doc.get(rootName, XmlText);
|
|
925
935
|
const root = $createCollabElementNode(rootXmlText, null, 'root');
|
|
926
936
|
root._key = 'root';
|
|
927
937
|
return {
|
|
@@ -930,6 +940,18 @@ function createBinding(editor, provider, id, doc, docMap, excludedProperties) {
|
|
|
930
940
|
root
|
|
931
941
|
};
|
|
932
942
|
}
|
|
943
|
+
function createBinding(editor, provider, id, doc, docMap, excludedProperties) {
|
|
944
|
+
if (!(doc !== undefined && doc !== null)) {
|
|
945
|
+
formatDevErrorMessage(`createBinding: doc is null or undefined`);
|
|
946
|
+
}
|
|
947
|
+
return createYjsBinding({
|
|
948
|
+
doc,
|
|
949
|
+
docMap,
|
|
950
|
+
editor,
|
|
951
|
+
excludedProperties,
|
|
952
|
+
id
|
|
953
|
+
});
|
|
954
|
+
}
|
|
933
955
|
function createBindingV2__EXPERIMENTAL(editor, id, doc, docMap, options = {}) {
|
|
934
956
|
if (!(doc !== undefined && doc !== null)) {
|
|
935
957
|
formatDevErrorMessage(`createBinding: doc is null or undefined`);
|
|
@@ -3694,4 +3716,4 @@ function setLocalStateFocus(provider, name, color, focusing, awarenessData) {
|
|
|
3694
3716
|
awareness.setLocalState(localState);
|
|
3695
3717
|
}
|
|
3696
3718
|
|
|
3697
|
-
export { $getAnchorAndFocusForUserState, $getYChangeState, CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL, CONNECTED_COMMAND, DIFF_VERSIONS_COMMAND__EXPERIMENTAL, TOGGLE_CONNECT_COMMAND, createBinding, createBindingV2__EXPERIMENTAL, createUndoManager, getAnchorAndFocusCollabNodesForUserState, initLocalState, removeCursorHighlightRule, renderSnapshot__EXPERIMENTAL, setLocalStateFocus, syncCursorPositions, syncLexicalUpdateToYjs, syncLexicalUpdateToYjsV2__EXPERIMENTAL, syncYjsChangesToLexical, syncYjsChangesToLexicalV2__EXPERIMENTAL, syncYjsStateToLexicalV2__EXPERIMENTAL };
|
|
3719
|
+
export { $getAnchorAndFocusForUserState, $getYChangeState, CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL, CONNECTED_COMMAND, DIFF_VERSIONS_COMMAND__EXPERIMENTAL, TOGGLE_CONNECT_COMMAND, createBinding, createBindingV2__EXPERIMENTAL, createUndoManager, createYjsBinding, getAnchorAndFocusCollabNodesForUserState, initLocalState, removeCursorHighlightRule, renderSnapshot__EXPERIMENTAL, setLocalStateFocus, syncCursorPositions, syncLexicalUpdateToYjs, syncLexicalUpdateToYjsV2__EXPERIMENTAL, syncYjsChangesToLexical, syncYjsChangesToLexicalV2__EXPERIMENTAL, syncYjsStateToLexicalV2__EXPERIMENTAL };
|
package/dist/LexicalYjs.mjs
CHANGED
|
@@ -18,6 +18,7 @@ export const TOGGLE_CONNECT_COMMAND = mod.TOGGLE_CONNECT_COMMAND;
|
|
|
18
18
|
export const createBinding = mod.createBinding;
|
|
19
19
|
export const createBindingV2__EXPERIMENTAL = mod.createBindingV2__EXPERIMENTAL;
|
|
20
20
|
export const createUndoManager = mod.createUndoManager;
|
|
21
|
+
export const createYjsBinding = mod.createYjsBinding;
|
|
21
22
|
export const getAnchorAndFocusCollabNodesForUserState = mod.getAnchorAndFocusCollabNodesForUserState;
|
|
22
23
|
export const initLocalState = mod.initLocalState;
|
|
23
24
|
export const removeCursorHighlightRule = mod.removeCursorHighlightRule;
|
package/dist/LexicalYjs.node.mjs
CHANGED
|
@@ -16,6 +16,7 @@ export const TOGGLE_CONNECT_COMMAND = mod.TOGGLE_CONNECT_COMMAND;
|
|
|
16
16
|
export const createBinding = mod.createBinding;
|
|
17
17
|
export const createBindingV2__EXPERIMENTAL = mod.createBindingV2__EXPERIMENTAL;
|
|
18
18
|
export const createUndoManager = mod.createUndoManager;
|
|
19
|
+
export const createYjsBinding = mod.createYjsBinding;
|
|
19
20
|
export const getAnchorAndFocusCollabNodesForUserState = mod.getAnchorAndFocusCollabNodesForUserState;
|
|
20
21
|
export const initLocalState = mod.initLocalState;
|
|
21
22
|
export const removeCursorHighlightRule = mod.removeCursorHighlightRule;
|
package/dist/LexicalYjs.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("lexical"),t=require("yjs"),n=require("@lexical/selection");function o(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function s(e,t,n){const o=e.length,s=t.length;let i=0,r=0;for(;i<o&&i<s&&e[i]===t[i]&&i<n;)i++;for(;r+i<o&&r+i<s&&e[o-r-1]===t[s-r-1];)r++;for(;r+i<o&&r+i<s&&e[i]===t[i];)i++;return{index:i,insert:t.slice(i,s-r),remove:o-i-r}}class i{_xmlElem;_key;_parent;_type;constructor(e,t,n){this._key="",this._xmlElem=e,this._parent=t,this._type=n}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isDecoratorNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isDecoratorNode(t)?t:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent instanceof i&&o(394),this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);K(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();if(null===n)return;w(e,this._xmlElem,n,t)}syncSlotsFromYjs(e,t){Y(e,this._xmlElem,t,this)}syncSlotsFromLexical(e,t,n,o,s){z(e,this._xmlElem,t,n,o,s,this)}destroy(e){const t=e.collabNodeMap;B(e,this._xmlElem),t.get(this._key)===this&&t.delete(this._key)}}function r(e,t,n){const o=new i(e,t,n);return e._collabNode=o,o}class l{_map;_key;_parent;_type;constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const t=e.$getNodeByKey(this._key);return e.$isLineBreakNode(t)?t:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function c(e,t){const n=new l(e,t);return e._collabNode=n,n}class a{_map;_key;_parent;_text;_type;_normalized;constructor(e,t,n,o){this._key="",this._map=e,this._parent=n,this._text=t,this._type=o,this._normalized=!1}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isTextNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isTextNode(t)?t: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(e,t,n){const o=this._parent._xmlText,s=this.getOffset()+1+e;0!==t&&o.delete(s,t),""!==n&&o.insert(s,n)}syncPropertiesAndTextFromLexical(t,n,o){const i=this.getPrevNode(o),r=n.__text;if(K(t,this._map,i,n),null!==i){const t=i.__text;if(t!==r){!function(t,n,o,i){const r=e.$getSelection();let l=i.length;if(e.$isRangeSelection(r)&&r.isCollapsed()){const e=r.anchor;e.key===n&&(l=e.offset)}const c=s(o,i,l);t.spliceText(c.index,c.remove,c.insert)}(this,n.__key,t,r),this._text=r}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();if(null===n)return;w(e,this._map,n,t);const o=this._text;n.__text!==o&&n.setTextContent(o)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function f(e,t,n,o){const s=new a(e,t,n,o);return e._collabNode=s,s}class d{_key;_children;_xmlText;_type;_parent;constructor(e,t,n){this._key="",this._children=[],this._xmlText=e,this._type=n,this._parent=t}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isElementNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isElementNode(t)?t:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){const e=this._parent;return e instanceof d||o(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null!==n&&w(e,this._xmlText,n,t)}applyChildrenYjsDelta(e,t){const n=this._children;let o=0,s=null;for(let r=0;r<t.length;r++){const c=t[r],f=c.insert,u=c.delete;if(null!=c.retain)o+=c.retain;else if("number"==typeof u){let e=u;for(;e>0;){const{node:t,nodeIndex:s,offset:r,length:c}=R(this,o,!1);if(t instanceof d||t instanceof l||t instanceof i)n.splice(s,1),e-=1;else{if(!(t instanceof a))break;{const o=Math.min(e,c),i=0!==s?n[s-1]:null,l=t.getSize();if(0===r&&c===l){n.splice(s,1);const e=D(t._text,r,o-1,"");e.length>0&&(i instanceof a?i._text+=e:this._xmlText.delete(r,e.length))}else t._text=D(t._text,r,o,"");e-=o}}}}else{if(null==f)throw new Error("Unexpected delta format");if("string"==typeof f){const{node:e,offset:t}=R(this,o,!0);e instanceof a?e._text=D(e._text,t,0,f):this._xmlText.delete(t,f.length),o+=f.length}else{const t=f;if(void 0===M(t))continue;const{node:i,nodeIndex:r,length:l}=R(this,o,!1),c=O(e,t,this);if(i instanceof a&&l>0&&l<i._text.length){const e=i._text,t=e.length-l;i._text=D(e,t,l,""),n.splice(r+1,0,c),s=D(e,0,t,"")}else n.splice(r,0,c);null!==s&&c instanceof a&&(c._text=s+c._text,s=null),o+=1}}}}syncChildrenFromYjs(t){const n=this.getNode();if(null===n)return;const s=n.__key,r=e.$createChildrenArray(n,null),c=r.length,f=this._children,u=f.length,h=t.collabNodeMap,g=new Set;let p,y,_=0,m=null;u!==c&&(y=n.getWritable());for(let c=0;c<u;c++){const x=r[_],N=f[c],S=N.getNode(),T=N._key;if(null!==S&&x===T){const n=e.$isTextNode(S);if(g.add(x),n)if(N._key=x,N instanceof d){const e=N._xmlText;N.syncPropertiesFromYjs(t,null),N.applyChildrenYjsDelta(t,e.toDelta()),N.syncChildrenFromYjs(t)}else N instanceof a?N.syncPropertiesAndTextFromYjs(t,null):N instanceof i?N.syncPropertiesFromYjs(t,null):N instanceof l||o(93);m=S,_++}else{if(void 0===p){p=new Set;for(let e=0;e<u;e++){const t=f[e]._key;""!==t&&p.add(t)}}if(null!==S&&void 0!==x&&!p.has(x)){const t=e.$getNodeByKeyOrThrow(x);e.$removeFromParent(t),c--,_++;continue}y=n.getWritable();const o=A(t,N,s),i=o.__key;if(h.set(i,N),null===m){const e=y.getFirstChild();if(y.__first=i,null!==e){const t=e.getWritable();t.__prev=i,o.__next=t.__key}}else{const e=m.getWritable(),t=m.getNextSibling();if(e.__next=i,o.__prev=m.__key,null!==t){const e=t.getWritable();e.__prev=i,o.__next=e.__key}}c===u-1&&(y.__last=i),y.__size++,m=o}}for(let n=0;n<c;n++){const o=r[n];if(!g.has(o)){const n=e.$getNodeByKeyOrThrow(o),s=t.collabNodeMap.get(o);void 0!==s&&s.destroy(t),e.$removeFromParent(n)}}this.syncSlotsFromYjs(t,n)}syncSlotsFromYjs(e,t){Y(e,this._xmlText,t,this)}syncPropertiesFromLexical(e,t,n){K(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,o,s,r,l){const c=this._children[n],f=e.$getNodeByKeyOrThrow(o);c instanceof d&&e.$isElementNode(f)?(c.syncPropertiesFromLexical(t,f,s),c.syncChildrenFromLexical(t,f,s,r,l),c.syncSlotsFromLexical(t,f,s,r,l)):c instanceof a&&e.$isTextNode(f)?c.syncPropertiesAndTextFromLexical(t,f,s):c instanceof i&&e.$isDecoratorNode(f)&&(c.syncPropertiesFromLexical(t,f,s),c.syncSlotsFromLexical(t,f,s,r,l))}syncSlotsFromLexical(e,t,n,o,s){z(e,this._xmlText,t,n,o,s,this)}syncChildrenFromLexical(t,n,o,s,i){const r=this.getPrevNode(o),l=null===r?[]:e.$createChildrenArray(r,o),c=e.$createChildrenArray(n,null),a=l.length-1,f=c.length-1,d=t.collabNodeMap;let u,h,g=0,p=0;for(;g<=a&&p<=f;){const n=l[g],r=c[p];if(n===r)this._syncChildFromLexical(t,p,r,o,s,i),g++,p++;else{void 0===u&&(u=new Set(l)),void 0===h&&(h=new Set(c));const o=h.has(n),s=u.has(r);if(o){const n=v(t,e.$getNodeByKeyOrThrow(r),this);d.set(r,n),s?(this.splice(t,p,1,n),g++,p++):(this.splice(t,p,0,n),p++)}else this.splice(t,p,1),g++}}const y=g>a,_=p>f;if(y&&!_)for(;p<=f;++p){const n=c[p],o=v(t,e.$getNodeByKeyOrThrow(n),this);this.append(o),d.set(n,o)}else if(_&&!y)for(let e=this._children.length-1;e>=p;e--)this.splice(t,e,1)}append(e){const t=this._xmlText,n=this._children,o=n[n.length-1],s=void 0!==o?o.getOffset()+o.getSize():0;if(e instanceof d)t.insertEmbed(s,e._xmlText);else if(e instanceof a){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof l?t.insertEmbed(s,e._map):e instanceof i&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,s){const r=this._children,c=r[t];if(void 0===c)return void(void 0!==s&&this.append(s));const f=c.getOffset();-1===f&&o(95);const u=this._xmlText;if(0!==n){const o=r.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e);u.delete(f,c.getSize())}if(s instanceof d)u.insertEmbed(f,s._xmlText);else if(s instanceof a){const e=s._map;null===e.parent&&u.insertEmbed(f,e),u.insert(f+1,s._text)}else s instanceof l?u.insertEmbed(f,s._map):s instanceof i&&u.insertEmbed(f,s._xmlElem);void 0!==s?r.splice(t,n,s):r.splice(t,n)}getChildOffset(e){let t=0;const n=this._children;for(let o=0;o<n.length;o++){const s=n[o];if(s===e)return t;t+=s.getSize()}return-1}destroy(e){const t=e.collabNodeMap,n=this._children;for(let t=0;t<n.length;t++)n[t].destroy(e);B(e,this._xmlText),t.get(this._key)===this&&t.delete(this._key)}}function u(e,t,n){const o=new d(e,t,n);return e._collabNode=o,o}class h{_nodeMap=new Map;_sharedTypeToNodeKeys=new Map;_nodeKeyToSharedType=new Map;set(n,s){const i=s instanceof Array;this.delete(n);const r=i?s:[s];for(const e of r){const t=e.getKey();if(this._nodeKeyToSharedType.has(t)){const e=this._nodeKeyToSharedType.get(t),n=this._sharedTypeToNodeKeys.get(e).indexOf(t);-1!==n&&this._sharedTypeToNodeKeys.get(e).splice(n,1),this._nodeKeyToSharedType.delete(t),this._nodeMap.delete(t)}}if(n instanceof t.XmlText){if(i||o(331),0===s.length)return;this._sharedTypeToNodeKeys.set(n,s.map(e=>e.getKey()));for(const e of s)this._nodeMap.set(e.getKey(),e),this._nodeKeyToSharedType.set(e.getKey(),n)}else i&&o(332),e.$isTextNode(s)&&o(333),this._sharedTypeToNodeKeys.set(n,[s.getKey()]),this._nodeMap.set(s.getKey(),s),this._nodeKeyToSharedType.set(s.getKey(),n)}get(e){const n=this._sharedTypeToNodeKeys.get(e);if(void 0!==n){if(e instanceof t.XmlText){const e=Array.from(n.map(e=>this._nodeMap.get(e)));return e.length>0?e:void 0}return this._nodeMap.get(n[0])}}getSharedType(e){return this._nodeKeyToSharedType.get(e.getKey())}delete(e){const t=this._sharedTypeToNodeKeys.get(e);if(void 0!==t){for(const e of t)this._nodeMap.delete(e),this._nodeKeyToSharedType.delete(e);this._sharedTypeToNodeKeys.delete(e)}}deleteNode(e){const t=this._nodeKeyToSharedType.get(e);t&&this.delete(t),this._nodeMap.delete(e)}has(e){return this._sharedTypeToNodeKeys.has(e)}clear(){this._nodeMap.clear(),this._sharedTypeToNodeKeys.clear(),this._nodeKeyToSharedType.clear()}}function g(e,t,n,s,i){null==n&&o(81);const r={clientID:n.clientID,cursorHighlightSheet:null,cursors:new Map,cursorsContainer:null,doc:n,docMap:s,editor:e,excludedProperties:i||new Map,id:t,nodeProperties:new Map};return function(e){const{editor:t,nodeProperties:n}=e;t.update(()=>{t._nodes.forEach(t=>{const o=new t.klass,s={};for(const[t,n]of Object.entries(o))E(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(r),r}function p(e){return Object.prototype.hasOwnProperty.call(e,"collabNodeMap")}const y="__slots",_=new Set(["__key","__parent","__next","__prev","__state","__slotHost","__slots"]),m=new Set(["__first","__last","__size"]),x=new Set(["__cachedText"]),N=new Set(["__text"]);function S(e,t){e.setAttribute(y,t)}function T(e){return"__proto__"===e||"constructor"===e||"prototype"===e}function b(t){return(e.$isElementNode(t)||e.$isDecoratorNode(t))&&!t.isInline()}function E(t,n,o){if(_.has(t)||"function"==typeof n[t])return!0;if(e.$isTextNode(n)){if(N.has(t))return!0}else if(e.$isElementNode(n)&&(m.has(t)||e.$isRootNode(n)&&x.has(t)))return!0;const s=n.constructor,i=o.excludedProperties.get(s);return null!=i&&i.has(t)}function $(e,t){const n=e.__type,{nodeProperties:s}=t,i=s.get(n);return void 0===i&&o(330,n),i}function C(t,n,o,s,r,l){n instanceof d&&e.$isElementNode(o)?(n.syncPropertiesFromLexical(t,o,s),n.syncChildrenFromLexical(t,o,s,r,l),n.syncSlotsFromLexical(t,o,s,r,l)):n instanceof a&&e.$isTextNode(o)?n.syncPropertiesAndTextFromLexical(t,o,s):n instanceof i&&e.$isDecoratorNode(o)&&(n.syncPropertiesFromLexical(t,o,s),n.syncSlotsFromLexical(t,o,s,r,l))}function k(n,o,s,i){const r=e.$getSlotNames(o),l=e.getDeclaredSlots(o.constructor).length>0;if(0===r.length&&!l)return;const c=new t.Map;let a=!1;for(const t of r){const i=e.$getSlot(o,t);if(null===i)continue;const r=v(n,i,s);n.collabNodeMap.set(i.__key,r),c.set(t,r.getSharedType()),a=!0}(a||l)&&S(i,c)}function v(n,s,i){const l=s.__type;let a;if(e.$isElementNode(s)){const e=new t.XmlText;a=u(e,i,l),a.syncPropertiesFromLexical(n,s,null),a.syncChildrenFromLexical(n,s,null,null,null),k(n,s,a,e)}else if(e.$isTextNode(s)){i instanceof d||o(389);a=f(new t.Map,s.__text,i,l),a.syncPropertiesAndTextFromLexical(n,s,null)}else if(e.$isLineBreakNode(s)){i instanceof d||o(390);const e=new t.Map;e.set("__type","linebreak"),a=c(e,i)}else if(e.$isDecoratorNode(s)){const e=new t.XmlElement;a=r(e,i,l),a.syncPropertiesFromLexical(n,s,null),k(n,s,a,e)}else o(86);return a._key=s.__key,a}function M(e){const t=F(e,"__type");return"string"!=typeof t&&void 0!==t&&o(87),t}function O(e,n,s){const l=n._collabNode;if(void 0===l){const l=e.editor._nodes,a=M(n);"string"!=typeof a&&o(87);void 0===l.get(a)&&o(88,a);const h=n.parent,g=void 0===s&&null!==h?O(e,h):s||null;if(g instanceof d||g instanceof i&&function(e,n){const o=e._xmlElem.getAttribute(y);if(!(o instanceof t.Map))return!1;for(const e of o.values())if(e===n)return!0;return!1}(g,n)||o(391),n instanceof t.XmlText)return u(n,g,a);if(n instanceof t.Map)return g instanceof d||o(392),"linebreak"===a?c(n,g):f(n,"",g,a);if(n instanceof t.XmlElement)return r(n,g,a)}return l}function A(t,n,s){const r=n.getType(),l=t.editor._nodes.get(r);void 0===l&&o(88,r);const c=new l.klass;if(c.__parent=s,n._key=c.__key,n instanceof d){const e=n._xmlText;n.syncPropertiesFromYjs(t,null),n.applyChildrenYjsDelta(t,e.toDelta()),n.syncChildrenFromYjs(t)}else n instanceof a?n.syncPropertiesAndTextFromYjs(t,null):n instanceof i&&(n.syncPropertiesFromYjs(t,null),e.$isDecoratorNode(c)||o(393),n.syncSlotsFromYjs(t,c));return t.collabNodeMap.set(c.__key,n),c}function w(n,o,s,i){const r=null===i?o instanceof t.Map?Array.from(o.keys()):o instanceof t.XmlText||o instanceof t.XmlElement?Object.keys(o.getAttributes()):Object.keys(o):Array.from(i);let l;for(let i=0;i<r.length;i++){const c=r[i];if(E(c,s,n)){"__state"===c&&p(n)&&(l||(l=s.getWritable()),P(o,l));continue}const a=s[c];let f=F(o,c);if(a!==f){if(f instanceof t.Doc){const o=n.docMap;a instanceof t.Doc&&o.delete(a.guid);const s=f.guid;if(o.set(s,f),e.isLexicalEditor(a))a._key=s,f=a;else{const t=e.createEditor();t._key=s,f=t}}void 0===l&&(l=s.getWritable()),l[c]=f}}}function F(e,n){return e instanceof t.Map?e.get(n):e instanceof t.XmlText||e instanceof t.XmlElement?e.getAttribute(n):e[n]}function L(e,n,o){e instanceof t.Map?e.set(n,o):e.setAttribute(n,o)}function P(n,o){const s=F(n,"__state");s instanceof t.Map&&e.$getWritableNodeState(o).updateFromJSON(s.toJSON())}function K(e,n,o,s){const i=Object.keys($(s,e)),r=e.editor.constructor;!function(e,n,o,s){const i=s.__state,r=null===n.doc?void 0:F(n,"__state");if(!i)return;const[l,c]=i.getInternalState(),a=o&&o.__state,f=r instanceof t.Map?r:new t.Map;if(a===i)return;const[d,u]=a&&f.doc?a.getInternalState():[void 0,new Map];if(l)for(const[e,t]of Object.entries(l))d&&t!==d[e]&&f.set(e,t);for(const[e,t]of c)u.get(e)!==t&&f.set(e.key,e.unparse(t));r||L(n,"__state",f)}(0,n,o,s);for(let l=0;l<i.length;l++){const c=i[l],a=null===o?void 0:o[c];let f=s[c];if(a!==f){if(f instanceof r){const n=e.docMap;let o;if(a instanceof r){const e=a._key;o=n.get(e),n.delete(e)}const i=o||new t.Doc,l=i.guid;f._key=l,n.set(l,i),f=i,e.editor.update(()=>{s.markDirty()})}L(n,c,f)}}}function D(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function R(e,t,n){let o=0,s=0;const i=e._children,r=i.length;for(;s<r;s++){const e=i[s],l=o;o+=e.getSize();if((n?o>=t:o>t)&&e instanceof a){let n=t-l-1;n<0&&(n=0);return{length:o-t,node:e,nodeIndex:s,offset:n}}if(o>t)return{length:0,node:e,nodeIndex:s,offset:l};if(s===r-1)return{length:0,node:null,nodeIndex:s+1,offset:l+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function j(t){const n=t.anchor,o=t.focus;let s=!1;try{const t=n.getNode(),i=o.getNode();(!t.isAttached()||!i.isAttached()||e.$isTextNode(t)&&n.offset>t.getTextContentSize()||e.$isTextNode(i)&&o.offset>i.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function I(e,t){e.doc.transact(t,e)}function X(t,n){const o=n._nodeMap.get(t);if(!o)return void e.$getRoot().selectStart();const s=o.__prev;let i=null;s&&(i=e.$getNodeByKey(s)),null===i&&null!==o.__parent&&(i=e.$getNodeByKey(o.__parent)),null!==i?null!==i&&i.isAttached()?i.selectEnd():X(i.__key,n):e.$getRoot().selectStart()}function Y(n,o,s,r){const l=o.getAttribute(y),c=l instanceof t.Map?new Set(l.keys()):new Set;for(const t of e.$getSlotNames(s))if(!c.has(t)){const o=e.$getSlot(s,t);if(null!==o){const e=n.collabNodeMap.get(o.__key);void 0!==e&&e.destroy(n)}e.$removeSlot(s,t)}if(l instanceof t.Map)for(const[o,c]of l.entries()){if(T(o))continue;if(!(c instanceof t.XmlText||c instanceof t.XmlElement||c instanceof t.Map))continue;const l=e.$getSlot(s,o),a=null===l?void 0:n.collabNodeMap.get(l.__key);if(void 0!==a&&a.getSharedType()===c)continue;if(void 0===c._collabNode&&"string"!=typeof F(c,"__type"))continue;if(c instanceof t.Map&&r instanceof i)continue;const f=c._collabNode;if(void 0!==f){const t=e.$getNodeByKey(f._key);if(null!==t&&(t.isAttached()||(e.$isElementNode(t)||e.$isDecoratorNode(t))&&null!==t.getLatest().__slotHost))continue}const d=O(n,c,r),u=A(n,d,null);b(u)?(void 0!==a&&a.destroy(n),e.$setSlot(s,o,u)):n.collabNodeMap.get(u.__key)===d&&n.collabNodeMap.delete(u.__key)}}function z(n,o,s,i,r,l,c){const a=e.$getSlotNames(s),f=o.getAttribute(y);if(0===a.length&&!(f instanceof t.Map))return;let d;f instanceof t.Map?d=f:(d=new t.Map,S(o,d));const u=new Set(a);for(const e of Array.from(d.keys()))if(!u.has(e)){const t=d.get(e),o=null==t?void 0:t._collabNode;void 0!==o&&o.destroy(n),d.delete(e)}const h=n.collabNodeMap;for(const t of a){const o=e.$getSlot(s,t);if(null===o)continue;const a=h.get(o.__key);if(void 0!==a&&d.get(t)===a.getSharedType())C(n,a,o,i,r,l);else{const e=d.get(t),s=null==e?void 0:e._collabNode;void 0!==s&&s.destroy(n);const i=v(n,o,c);h.set(o.__key,i),d.set(t,i.getSharedType())}}}function B(e,n){const o=n.getAttribute(y);if(o instanceof t.Map)for(const t of o.keys()){const n=o.get(t),s=null==n?void 0:n._collabNode;void 0!==s&&s.destroy(e)}}const U=e=>"UNDEFINED"===e.nodeName,W=(n,s,i,r,l,c,a)=>{let f=s.mapping.get(n);if(f&&i&&0===i.size&&!r)return f;const d=U(n)?e.RootNode.getType():n.nodeName,u=s.editor._nodes.get(d);if(void 0===u)throw new Error(`$createOrUpdateNodeFromYElement: Node ${d} is not registered`);if(f||(f=new u.klass,i=null,r=!0),r&&f instanceof e.ElementNode){const e=[],i=n=>{if(n instanceof t.XmlElement){const t=W(n,s,new Set,!1,l,c,a);null!==t&&e.push(t)}else if(n instanceof t.XmlText){const t=V(n,s,l,c,a);null!==t&&t.forEach(t=>{null!==t&&e.push(t)})}else o(329)};void 0===l||void 0===c?n.toArray().forEach(i):t.typeListToArraySnapshot(n,new t.Snapshot(c.ds,l.sv)).filter(e=>!e._item.deleted||G(e._item,l)||G(e._item,c)).forEach(i),H(f,e)}const h=n.getAttributes(l);U(n)||void 0===l||(G(n._item,l)?G(n._item,c)||(h[ue("ychange")]=a?a("added",n._item.id):{type:"added"}):h[ue("ychange")]=a?a("removed",n._item.id):{type:"removed"});const g={...$(f,s)},p={};for(const e in h)e.startsWith(de)?p[he(e)]=h[e]:e!==y&&"__proto__"!==e&&"constructor"!==e&&"prototype"!==e&&(g[e]=h[e]);if(w(s,g,f,i),i){if(i.size>0){const t=e.$getWritableNodeState(f);for(const e of i)if(e.startsWith(de)){const n=he(e);t.updateFromUnknown(n,p[n])}}}else e.$getWritableNodeState(f).updateFromJSON(p);if(f instanceof e.ElementNode||e.$isDecoratorNode(f)){const n=h[y],o=new Set;if(n instanceof t.Map){const i=void 0===l?Array.from(n.entries()):Object.entries(t.typeMapGetAllSnapshot(n,l));for(const[n,r]of i){if(o.add(n),T(n))continue;let i=null;if(r instanceof t.XmlElement&&(i=W(r,s,new Set,!1,l,c,a)),null===i)continue;const d=e.$getSlot(f,n);null!==d&&d.getKey()===i.getKey()||(b(i)?null===i.getLatest().__slotHost&&e.$setSlot(f,n,i):i.isAttached()||J(r,s))}}for(const t of e.$getSlotNames(f))o.has(t)||e.$removeSlot(f,t)}const _=f.getLatest();return s.mapping.set(n,_),_},H=(e,t)=>{const n=e.getChildren(),o=new Set(n.map(e=>e.getKey())),s=new Set(t.map(e=>e.getKey())),i=n.length-1,r=t.length-1;let l=0,c=0;for(;l<=i&&c<=r;){const i=n[l].getKey(),r=t[c].getKey();if(i===r){l++,c++;continue}const a=s.has(i),f=o.has(r);if(!a){if(0===c&&1===e.getChildrenSize())return void e.splice(c,1,t.slice(c));e.splice(c,1,[]),l++;continue}const d=t[c];f?(e.splice(c,1,[d]),l++,c++):(e.splice(c,0,[d]),c++)}const a=l>i,f=c>r;a&&!f?e.append(...t.slice(c)):f&&!a&&e.splice(t.length,e.getChildrenSize()-t.length,[])},G=(e,n)=>void 0===n?!e.deleted:n.sv.has(e.id.client)&&n.sv.get(e.id.client)>e.id.clock&&!t.isDeleted(n.ds,e.id),V=(t,n,o,s,i)=>{const r=ae(t,o,s,i);let l=n.mapping.get(t)??[];const c=r.map(t=>t.attributes.t??e.TextNode.getType());if(!(l.length===c.length&&l.every((e,t)=>e.getType()===c[t]))){const t=n.editor._nodes;l=c.map(n=>{const o=t.get(n);if(void 0===o)throw new Error(`$createTextNodesFromYText: Node ${n} is not registered`);const s=new o.klass;if(!e.$isTextNode(s))throw new Error(`$createTextNodesFromYText: Node ${n} is not a TextNode`);return s})}for(let t=0;t<r.length;t++){const o=l[t],s=r[t],{attributes:i,insert:c}=s;o.__text!==c&&o.setTextContent(c);const a={...$(o,n),...i.p},f=Object.fromEntries(Object.entries(i).filter(([e])=>e.startsWith(de)).map(([e,t])=>[he(e),t]));w(n,a,o,null),e.$getWritableNodeState(o).updateFromJSON(f)}const a=l.map(e=>e.getLatest());return n.mapping.set(t,a),a},q=(n,o)=>{const s=e.$getSlotNames(n);if(0===s.length&&0===e.getDeclaredSlots(n.constructor).length)return;const i=new t.Map;for(const t of s){const s=e.$getSlot(n,t);null!=s&&i.set(t,Z(s,o))}return i},J=(e,n)=>{if((e instanceof t.XmlElement||e instanceof t.XmlText)&&n.mapping.delete(e),e instanceof t.XmlElement){const o=e.getAttribute(y);if(o instanceof t.Map)for(const e of o.values())J(e,n);for(const t of e.toArray())J(t,n)}},Q=(n,o)=>{const s=new t.XmlElement(n.getType()),i={...fe(n,o),...ge(n)};for(const e in i){const t=i[e];null!==t&&s.setAttribute(e,t)}if(!(n instanceof e.ElementNode)){const e=q(n,o);return void 0!==e&&(S(s,e),o.mapping.set(s,n)),s}const r=q(n,o);return void 0!==r&&S(s,r),s.insert(0,oe(n).map(e=>ee(e,o))),o.mapping.set(s,n),s},Z=(t,n)=>{const o=Q(t,n);return e.$isDecoratorNode(t)&&void 0===n.mapping.getSharedType(t)&&n.mapping.set(o,t),o},ee=(e,n)=>e instanceof Array?((e,n)=>{const o=new t.XmlText;return ce(o,e,n),o})(e,n):Q(e,n),te=e=>"object"==typeof e&&null!=e,ne=(e,t)=>{const n=Object.keys(e).filter(t=>null!==e[t]);if(null==t)return 0===n.length;let o=n.length===Object.keys(t).filter(e=>null!==t[e]).length;for(let s=0;s<n.length&&o;s++){const i=n[s],r=e[i],l=t[i];o="ychange"===i||r===l||te(r)&&te(l)&&ne(r,l)}return o},oe=t=>{if(!(t instanceof e.ElementNode))return[];const n=t.getChildren(),o=[];for(let t=0;t<n.length;t++){const s=n[t];if(e.$isTextNode(s)){const s=[];for(let o=n[t];t<n.length&&e.$isTextNode(o);o=n[++t])s.push(o);t--,o.push(s)}else o.push(s)}return o},se=(t,n,o)=>{const s=ae(t);return s.length===n.length&&s.every((t,s)=>{const i=n[s],r=t.attributes.t??e.TextNode.getType(),l=t.attributes.p??{},c=Object.fromEntries(Object.entries(t.attributes).filter(([e])=>e.startsWith(de)));return t.insert===i.getTextContent()&&r===i.getType()&&ne(l,fe(i,o))&&ne(c,ge(i))})},ie=(n,o,s)=>{if(n instanceof t.XmlElement&&!(o instanceof Array)&&ye(n,o)){const i=oe(o),r=n.getAttributes();return delete r[y],n._length===i.length&&ne(r,{...fe(o,s),...ge(o)})&&((n,o,s)=>{const i=e.$getSlotNames(o),r=n.getAttribute(y);if(!(r instanceof t.Map))return 0===i.length;if(r.size!==i.length)return!1;for(const n of i){const i=e.$getSlot(o,n),l=r.get(n);if(null===i||!(l instanceof t.XmlElement)||s.mapping.get(l)!==i)return!1}return!0})(n,o,s)&&n.toArray().every((e,t)=>ie(e,i[t],s))}return n instanceof t.XmlText&&o instanceof Array&&se(n,o,s)},re=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),le=(e,n,o)=>{const s=e.toArray(),i=oe(n),r=i.length,l=s.length,c=Math.min(l,r);let a=0,f=0,d=!1;for(;a<c;a++){const e=s[a],n=i[a];if(e instanceof t.XmlHook)break;if(re(o.mapping.get(e),n))d=!0;else if(!ie(e,n,o))break}for(;a+f<c;f++){const e=s[l-f-1],n=i[r-f-1];if(e instanceof t.XmlHook)break;if(re(o.mapping.get(e),n))d=!0;else if(!ie(e,n,o))break}return{equalityFactor:a+f,foundMappedChild:d}},ce=(n,o,i)=>{i.mapping.set(n,o);const{nAttrs:r,str:l}=(e=>{let n="",o=e._start;const s={};for(;null!==o;)o.deleted||(o.countable&&o.content instanceof t.ContentString?n+=o.content.str:o.content instanceof t.ContentFormat&&(s[o.content.key]=null)),o=o.right;return{nAttrs:s,str:n}})(n),c=o.map((t,n)=>{const o=t.getType();let s=fe(t,i);return 0===Object.keys(s).length&&(s=null),{attributes:Object.assign({},r,{...o!==e.TextNode.getType()&&{t:o},p:s,...ge(t),...n>0&&{i:n}}),insert:t.getTextContent(),nodeKey:t.getKey()}}),a=c.map(e=>e.insert).join(""),f=e.$getSelection();let d;if(e.$isRangeSelection(f)&&f.isCollapsed()){d=0;for(const e of c){if(e.nodeKey===f.anchor.key){d+=f.anchor.offset;break}d+=e.insert.length}}else d=a.length;const{insert:u,remove:h,index:g}=s(l,a,d);n.delete(g,h),n.insert(g,u),n.applyDelta(c.map(e=>({attributes:e.attributes,retain:e.insert.length})))},ae=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>{const t=e.attributes??{};return"ychange"in t&&(t[ue("ychange")]=t.ychange,delete t.ychange),{...e,attributes:t}}),fe=(e,t)=>{const n=$(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},de="s_",ue=e=>`s_${e}`,he=e=>{if(!e.startsWith(de))throw new Error(`Invalid state key: ${e}`);return e.slice(de.length)},ge=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[ue(e)]=t;for(const[e,t]of o)s[ue(e.key)]=e.unparse(t);return s},pe=(n,o,s,i,r)=>{if(o instanceof t.XmlElement&&o.nodeName!==s.getType()&&(!U(o)||s.getType()!==e.RootNode.getType()))throw new Error("node name mismatch!");if(i.mapping.set(o,s),o instanceof t.XmlElement){const l=o.getAttributes(),c={...fe(s,i),...ge(s)};for(const e in c)if(null!=c[e]){l[e]===c[e]||te(l[e])&&te(c[e])&&ne(l[e],c[e])||"ychange"===e||o.setAttribute(e,c[e])}else o.removeAttribute(e);for(const e in l)e!==y&&void 0===c[e]&&o.removeAttribute(e);(s instanceof e.ElementNode||e.$isDecoratorNode(s))&&((n,o,s,i,r)=>{const l=e.$getSlotNames(o),c=n.getAttribute(y);if(0===l.length&&!(c instanceof t.Map)&&0===e.getDeclaredSlots(o.constructor).length)return;let a;c instanceof t.Map?a=c:(a=new t.Map,S(n,a));const f=new Set(l);for(const e of Array.from(a.keys()))if(!f.has(e)){const t=a.get(e);void 0!==t&&J(t,s),a.delete(e)}for(const n of l){const l=e.$getSlot(o,n);if(null==l)continue;const c=a.get(n);c instanceof t.XmlElement&&(l instanceof e.ElementNode||e.$isDecoratorNode(l))&&c===s.mapping.getSharedType(l)?i.has(l.getKey())&&pe(r,c,l,s,i):(c instanceof t.XmlElement&&J(c,s),a.set(n,Z(l,s)))}})(o,s,i,r,n)}const l=oe(s),c=l.length,a=o.toArray(),f=a.length,d=Math.min(c,f);let u=0,h=0;for(;u<d;u++){const o=a[u],s=l[u];if(o instanceof t.XmlHook)break;if(re(i.mapping.get(o),s))s instanceof Array||!(s instanceof e.ElementNode||e.$isDecoratorNode(s))||!r.has(s.getKey())||pe(n,o,s,i,r);else{if(!ie(o,s,i))break;i.mapping.set(o,s)}}for(;h+u<d;h++){const o=a[f-h-1],s=l[c-h-1];if(o instanceof t.XmlHook)break;if(re(i.mapping.get(o),s))s instanceof Array||!(s instanceof e.ElementNode||e.$isDecoratorNode(s))||!r.has(s.getKey())||pe(n,o,s,i,r);else{if(!ie(o,s,i))break;i.mapping.set(o,s)}}for(;f-u-h>0&&c-u-h>0;){const e=a[u],s=l[u],d=a[f-h-1],g=l[c-h-1];if(e instanceof t.XmlText&&s instanceof Array)se(e,s,i)||ce(e,s,i),u+=1;else{let l=e instanceof t.XmlElement&&ye(e,s),c=d instanceof t.XmlElement&&ye(d,g);if(l&&c){const t=le(e,s,i),n=le(d,g,i);t.foundMappedChild&&!n.foundMappedChild?c=!1:!t.foundMappedChild&&n.foundMappedChild||t.equalityFactor<n.equalityFactor?l=!1:c=!1}l?(pe(n,e,s,i,r),u+=1):c?(pe(n,d,g,i,r),h+=1):(i.mapping.delete(o.get(u)),o.delete(u,1),o.insert(u,[ee(s,i)]),u+=1)}}const g=f-u-h;if(1===f&&0===c&&a[0]instanceof t.XmlText?(i.mapping.delete(a[0]),a[0].delete(0,a[0].length)):g>0&&(o.slice(u,u+g).forEach(e=>i.mapping.delete(e)),o.delete(u,g)),u+h<c){const e=[];for(let t=u;t<c-h;t++)e.push(ee(l[t],i));o.insert(u,e)}},ye=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType(),_e=/* @__PURE__ */e.createState("ychange",{isEqual:(e,t)=>e===t,parse:e=>e??null});const me="undefined"!=typeof Highlight&&"undefined"!=typeof CSS&&"highlights"in CSS;function xe(t,n,o){if(!CSS.supports("color",o))return;const s=function(t){const n=t.editor.getRootElement(),o=e.getRootOwnerDocument(n);let s=t.cursorHighlightSheet;null===s&&(s=new(o.defaultView||window).CSSStyleSheet,t.cursorHighlightSheet=s);const i=null!==n?n.getRootNode():null,r=e.isDOMShadowRoot(i)?i:o;return r.adoptedStyleSheets.includes(s)||(r.adoptedStyleSheets=[...r.adoptedStyleSheets,s]),s}(t),i=s.insertRule(`::highlight(${n}) { }`,s.cssRules.length),r=s.cssRules[i];r.style.setProperty("background-color",`color-mix(in srgb, ${o} 30%, transparent)`),r.style.setProperty("color","inherit")}function Ne(e,t){const n=e.cursorHighlightSheet;if(null===n)return;const o=`::highlight(${t})`;for(let e=n.cssRules.length-1;e>=0;e--){const t=n.cssRules[e];if(null!=t&&t.selectorText===o)return void n.deleteRule(e)}}function Se(n,s,i=0){const r=s.collabNodeMap.get(n.key);if(void 0===r)return null;let l=n.offset,c=r.getSharedType();if(r instanceof a){c=r._parent._xmlText;const e=r.getOffset();if(-1===e)return null;l=e+1+l}else if(r instanceof d&&"element"===n.type){const t=n.getNode();e.$isElementNode(t)||o(184);let s=0,i=0,r=t.getFirstChild();for(;null!==r&&i++<l;)e.$isTextNode(r)?s+=r.getTextContentSize()+1:s++,r=r.getNextSibling();l=s}return t.createRelativePositionFromTypeIndex(c,l,i)}function Te(n,s,i=0){const{mapping:r}=s,{offset:l}=n,c=n.getNode(),a=r.getSharedType(c);if(void 0===a)return null;if("text"===n.type){e.$isTextNode(c)||o(326);let n=c.getPreviousSibling(),s=l;for(;e.$isTextNode(n);)s+=n.getTextContentSize(),n=n.getPreviousSibling();return t.createRelativePositionFromTypeIndex(a,s,i)}if("element"===n.type){e.$isElementNode(c)||o(184);let n=0,s=c.getFirstChild();for(;null!==s&&n<l;){if(e.$isTextNode(s)){let t=s.getNextSibling();for(;e.$isTextNode(t);)t=t.getNextSibling()}n++,s=s.getNextSibling()}return t.createRelativePositionFromTypeIndex(a,n,i)}return null}function be(e,n){return t.createAbsolutePositionFromRelativePosition(e,n.doc)}function Ee(e,n){if(null==e){if(null!=n)return!0}else if(null==n||!t.compareRelativePositions(e,n))return!0;return!1}function $e(e,t){return{color:t,name:e,selection:null}}function Ce(e,t){null!==t.highlight&&(CSS.highlights.delete(t.highlightName),Ne(e,t.highlightName));const n=e.cursorsContainer;if(null===n)return;t.caret.parentNode===n&&n.removeChild(t.caret);const o=t.selections;for(let e=0;e<o.length;e++)o[e].parentNode===n&&n.removeChild(o[e])}function ke(e,t){const n=t.selection;null!==n&&Ce(e,n)}function ve(t,n,o,s,i,r,l,c,a={}){const f=t.color,d=e.getRootOwnerDocument(n.editor.getRootElement()),u=d.createElement("span");a.cursor?(u.className=a.cursor,e.setDOMStyleObject(u.style,{"--lexical-cursor-color":f,bottom:"0",position:"absolute",right:"-1px",top:"0"})):e.setDOMStyleObject(u.style,{"background-color":f,bottom:"0",position:"absolute",right:"-1px",top:"0",width:"1px","z-index":"10"});const h=d.createElement("span");h.textContent=t.name,a.cursorName?h.className=a.cursorName:e.setDOMStyleObject(h.style,{"background-color":f,color:"#fff","font-family":"Arial","font-size":"12px","font-weight":"bold",left:"-2px","line-height":"12px",padding:"2px",position:"absolute",top:"-16px","white-space":"nowrap"}),u.appendChild(h);const g=`lexical-cursor-${n.id}-${o}`;let p=null;return c&&me&&(p=new Highlight,CSS.highlights.set(g,p),xe(n,g,f)),{anchor:{key:s,offset:i},caret:u,color:f,focus:{key:r,offset:l},highlight:p,highlightName:g,name:h,selections:[]}}function Me(t,o,s,i,r={}){const l=t.editor,c=l.getRootElement(),a=t.cursorsContainer;if(null===a||null===c)return;const f=e.getRootOwnerDocument(c),d=a.offsetParent;if(null===d)return;const u=d.getBoundingClientRect(),h=o.selection;if(null===s)return null===h?void 0:(o.selection=null,void Ce(t,h));o.selection=s;const g=s.caret,p=s.color,y=s.highlight,_=s.anchor,m=s.focus,x=_.key,N=m.key,S=i.get(x),T=i.get(N);if(null==S||null==T)return;if(null!==y){const t=n.createDOMRange(l,S,_.offset,T,m.offset);if(null===t)return;y.clear(),t.collapsed||y.add(t);const o=t.cloneRange();o.collapse(!1);let s=o.getBoundingClientRect();if(0===s.height&&e.$isLineBreakNode(T)){const e=l.getElementByKey(N);null!==e&&(s=e.getBoundingClientRect())}return e.setDOMStyleObject(g.style,{"background-color":r.cursor?"":p,bottom:"",height:`${s.height||16}px`,left:s.left-u.left+"px","pointer-events":"none",position:"absolute",right:"",top:s.top-u.top+"px",width:"1px","z-index":"10"}),void(g.parentNode!==a&&a.appendChild(g))}const b=s.selections;let E;if(S===T&&e.$isLineBreakNode(S)){E=[l.getElementByKey(x).getBoundingClientRect()]}else{const e=n.createDOMRange(l,S,_.offset,T,m.offset);if(null===e)return;E=n.createRectsFromDOMRange(l,e)}const $=b.length,C=E.length;for(let t=0;t<C;t++){const n=E[t];let o=b[t];if(void 0===o){o=f.createElement("span"),b[t]=o;const e=f.createElement("span");r.selectionBg&&(e.className=r.selectionBg),o.appendChild(e),a.appendChild(o)}const s=n.top-u.top,i=n.left-u.left,l={height:`${n.height}px`,left:`${i}px`,"pointer-events":"none",position:"absolute",top:`${s}px`,width:`${n.width}px`};r.selection?(o.className=r.selection,e.setDOMStyleObject(o.style,{...l,"--lexical-cursor-color":p}),e.setDOMStyleObject(o.firstChild.style,{height:"100%",left:"0",position:"absolute",top:"0",width:"100%"})):(e.setDOMStyleObject(o.style,l),e.setDOMStyleObject(o.firstChild.style,{...l,"background-color":p,left:"0",opacity:"0.3",top:"0","z-index":"5"})),t===C-1&&g.parentNode!==o&&o.appendChild(g)}for(let e=$-1;e>=C;e--){const t=b[e];a.removeChild(t),b.pop()}}function Oe(t,n){const{anchorPos:o,focusPos:s}=n,i=o?be(o,t):null,r=s?be(s,t):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(p(t)){const[e,t]=Fe(i.type,i.index),[n,o]=Fe(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=Le(t.mapping,i),[a,f]=Le(t.mapping,r);if(a&&l&&(a!==l||f!==c)){const t=a.isBefore(l),n=t?a:l,o=t?f:c;e.$isTextNode(n)&&e.$isTextNode(n.getNextSibling())&&o===n.getTextContentSize()&&(t?(a=n.getNextSibling(),f=0):(l=n.getNextSibling(),c=0))}return{anchorKey:null!==l?l.getKey():null,anchorOffset:c,focusKey:null!==a?a.getKey():null,focusOffset:f}}function Ae(t,n){const o=n.awareness.getLocalState();if(null===o)return;const{anchorKey:s,anchorOffset:i,focusKey:r,focusOffset:l}=Oe(t,o);if(null!==s&&null!==r){const t=e.$getSelection();if(!e.$isRangeSelection(t))return;we(t.anchor,s,i),we(t.focus,r,l)}}function we(t,n,o){if(t.key!==n||t.offset!==o){let s=e.$getNodeByKey(n);if(null!==s&&!e.$isElementNode(s)&&!e.$isTextNode(s)){const e=s.getParentOrThrow();n=e.getKey(),o=s.getIndexWithinParent(),s=e}t.set(n,o,e.$isElementNode(s)?"element":"text")}}function Fe(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof d){const{node:e,offset:o}=R(n,t,!0);return null===e?[n,n._children.length]:[e,o]}return[null,0]}function Le(n,o){const s=o.type,i=o.index;if(s instanceof t.XmlElement){const t=n.get(s);if(void 0===t)return[null,0];if(!e.$isElementNode(t))return[t,i];let o=i,r=0;const l=t.getChildren();for(;o>0&&r<l.length;){const t=l[r];if(o-=1,r+=1,e.$isTextNode(t))for(;r<l.length&&e.$isTextNode(l[r]);)r+=1}return[t,r]}{const e=n.get(s);if(void 0===e)return[null,0];let t=0,o=i;for(;o>e[t].getTextContentSize()&&t+1<e.length;)o-=e[t].getTextContentSize(),t++;const r=e[t];return[r,Math.min(o,r.getTextContentSize())]}}function Pe(e,t){return t.awareness.getStates()}function Ke(e,t,n){const{getAwarenessStates:o=Pe,selectionHighlight:s=!1}=n??{},i=Array.from(o(e,t)),r=e.clientID,l=e.cursors,c=e.editor,a=c._config.theme.collaboration,f=c._editorState._nodeMap,d=new Set;for(let t=0;t<i.length;t++){const n=i[t],[o,u]=n;if(0!==o&&o!==r){d.add(o);const{name:t,color:n,focusing:i}=u;let r=null,h=l.get(o);if(void 0===h&&(h=$e(t,n),l.set(o,h)),i){const{anchorKey:t,anchorOffset:n,focusKey:i,focusOffset:l}=c.read(()=>Oe(e,u));if(null!==t&&null!==i)if(r=h.selection,null===r)r=ve(h,e,o,t,n,i,l,s,a);else{const e=r.anchor,o=r.focus;e.key=t,e.offset=n,o.key=i,o.offset=l}}Me(e,h,r,f,a)}}const u=Array.from(l.keys());for(let t=0;t<u.length;t++){const n=u[t];if(!d.has(n)){const t=l.get(n);void 0!==t&&(ke(e,t),l.delete(n))}}}function De(t,n,o,s){const i=n.awareness,r=i.getLocalState();if(null===r)return;const{anchorPos:l,focusPos:c,name:a,color:f,focusing:d,awarenessData:u}=r;let h=null,g=null;if(null!==s&&(null===l||s.is(o))||null!==o){if(e.$isRangeSelection(s)){const e=s.isCollapsed(),n=!e&&s.isBackward(),o=n?-1:0,i=e||n?0:-1;p(t)?(h=Se(s.anchor,t,o),g=Se(s.focus,t,i)):(h=Te(s.anchor,t,o),g=Te(s.focus,t,i))}(Ee(l,h)||Ee(c,g))&&i.setLocalState({...r,anchorPos:h,awarenessData:u,color:f,focusPos:g,focusing:d,name:a})}}function Re(n,s){if(s instanceof t.YMapEvent&&function(n,o){const{target:s}=o;if(!s._item||"__state"!==s._item.parentSub||void 0!==M(s)||!(s.parent instanceof t.XmlText||s.parent instanceof t.XmlElement||s.parent instanceof t.Map))return!1;const i=O(n,s.parent).getNode();if(i){const t=e.$getWritableNodeState(i.getWritable());for(const e of o.keysChanged)t.updateFromUnknown(e,s.get(e))}return!0}(n,s))return;const{target:r}=s;if(s instanceof t.YMapEvent&&r instanceof t.Map&&null!=r._item&&r._item.parentSub===y&&(r.parent instanceof t.XmlText||r.parent instanceof t.XmlElement)){const e=O(n,r.parent);if(e instanceof d){const t=e.getNode();null!==t&&e.syncSlotsFromYjs(n,t)}else if(e instanceof i){const t=e.getNode();null!==t&&e.syncSlotsFromYjs(n,t)}return}const l=O(n,r);if(l instanceof d&&s instanceof t.YTextEvent){const{keysChanged:e,childListChanged:t,delta:o}=s;if(e.size>0&&l.syncPropertiesFromYjs(n,e),e.has(y)){const e=l.getNode();null!==e&&l.syncSlotsFromYjs(n,e)}t&&(l.applyChildrenYjsDelta(n,o),l.syncChildrenFromYjs(n))}else if(l instanceof a&&s instanceof t.YMapEvent){const{keysChanged:e}=s;e.size>0&&l.syncPropertiesAndTextFromYjs(n,e)}else if(l instanceof i&&s instanceof t.YXmlEvent){const{attributesChanged:e}=s;if(e.size>0&&l.syncPropertiesFromYjs(n,e),e.has(y)){const e=l.getNode();null!==e&&l.syncSlotsFromYjs(n,e)}}else o(82)}function je(t,n,o){const s=e.$getSelection();if(e.$isRangeSelection(s))if(j(s)){const i=t._selection;if(e.$isRangeSelection(i)&&(Ae(n,o),j(s))){X(s.anchor.key,t)}De(n,o,i,e.$getSelection())}else Ae(n,o)}function Ie(){0===e.$getRoot().getChildrenSize()&&e.$getRoot().append(e.$createParagraphNode())}function Xe(e,n){const{target:s}=n;if(s instanceof t.XmlElement&&n instanceof t.YXmlEvent)W(s,e,n.attributesChanged,n.childListChanged);else if(s instanceof t.XmlText&&n instanceof t.YTextEvent){const n=s.parent;n instanceof t.XmlElement?W(n,e,new Set,!0):o(327)}else if(s instanceof t.Map&&n instanceof t.YMapEvent&&null!=s._item&&s._item.parentSub===y){const n=s.parent;n instanceof t.XmlElement?W(n,e,new Set([y]),!1):o(388)}else o(328)}const Ye=/* @__PURE__ */e.createCommand("CONNECTED_COMMAND"),ze=/* @__PURE__ */e.createCommand("TOGGLE_CONNECT_COMMAND"),Be=/* @__PURE__ */e.createCommand("DIFF_VERSIONS_COMMAND"),Ue=/* @__PURE__ */e.createCommand("CLEAR_DIFF_VERSIONS_COMMAND");exports.$getAnchorAndFocusForUserState=Oe,exports.$getYChangeState=function(t){return e.$getState(t,_e)},exports.CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL=Ue,exports.CONNECTED_COMMAND=Ye,exports.DIFF_VERSIONS_COMMAND__EXPERIMENTAL=Be,exports.TOGGLE_CONNECT_COMMAND=ze,exports.createBinding=function(e,n,s,i,r,l){null==i&&o(81);const c=u(i.get("root",t.XmlText),null,"root");return c._key="root",{...g(e,s,i,r,l),collabNodeMap:new Map,root:c}},exports.createBindingV2__EXPERIMENTAL=function(e,n,s,i,r={}){null==s&&o(81);const{excludedProperties:l,rootName:c="root-v2"}=r;return{...g(e,n,s,i,l),mapping:new h,root:s.get(c,t.XmlElement)}},exports.createUndoManager=function(e,n){return new t.UndoManager(n,{trackedOrigins:new Set([e,null])})},exports.getAnchorAndFocusCollabNodesForUserState=function(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,i=0,r=null,l=0;if(null!==n&&null!==o){const t=be(n,e),c=be(o,e);null!==t&&null!==c&&([s,i]=Fe(t.type,t.index),[r,l]=Fe(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:i,focusCollabNode:r,focusOffset:l}},exports.initLocalState=function(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})},exports.removeCursorHighlightRule=Ne,exports.renderSnapshot__EXPERIMENTAL=(n,s=t.snapshot(n.doc),i=t.emptySnapshot)=>{const{doc:r}=n;r.gc&&o(325),r.transact(o=>{const l=new t.PermanentUserData(r);l&&l.dss.forEach(e=>{t.iterateDeletedStructs(o,e,e=>{})});const c=(e,t)=>({id:t,type:e,user:("added"===e?l.getUserByClientId(t.client):l.getUserByDeletedId(t))??null});n.mapping.clear(),n.editor.update(()=>{e.$getRoot().clear(),W(n.root,n,null,!0,s,i,c)})},n)},exports.setLocalStateFocus=function(e,t,n,o,s){const{awareness:i}=e;let r=i.getLocalState();null===r&&(r={anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t}),r.focusing=o,i.setLocalState(r)},exports.syncCursorPositions=Ke,exports.syncLexicalUpdateToYjs=function(t,n,o,s,i,r,l,c){I(t,()=>{s.read(()=>{if(c.has(e.COLLABORATION_TAG)||c.has(e.HISTORIC_TAG))return void(l.size>0&&function(t,n){const o=Array.from(n),s=t.collabNodeMap,i=[],r=[];for(let t=0;t<o.length;t++){const n=o[t],l=e.$getNodeByKey(n),c=s.get(n);if(c instanceof a)if(e.$isTextNode(l))i.push([c,l.__text]);else{const e=c.getOffset();if(-1===e)continue;const t=c._parent;c._normalized=!0,t._xmlText.delete(e,1),r.push(c)}}for(let e=0;e<r.length;e++){const t=r[e],n=t.getKey();s.delete(n);const o=t._parent._children,i=o.indexOf(t);o.splice(i,1)}for(let e=0;e<i.length;e++){const[t,n]=i[e];t._text=n}}(t,l));if(i.has("root")){const n=o._nodeMap,s=e.$getRoot(),l=t.root;l.syncPropertiesFromLexical(t,s,n),l.syncChildrenFromLexical(t,s,n,i,r),l.syncSlotsFromLexical(t,s,n,i,r),0===s.getChildrenSize()&&o._nodeMap.size>1&&t.editor.update(()=>Ie())}const s=e.$getSelection(),f=o._selection;De(t,n,f,s)})})},exports.syncLexicalUpdateToYjsV2__EXPERIMENTAL=function(t,n,o,s,i,r,l,c){const a=c.has(e.COLLABORATION_TAG)||c.has(e.HISTORIC_TAG);a&&0===l.size||(l.forEach(e=>{t.mapping.deleteNode(e)}),I(t,()=>{s.read(()=>{if(i.has("root")){const n=e.$getRoot();pe(t.doc,t.root,n,t,new Set([...i.keys(),...r])),!a&&0===n.getChildrenSize()&&o._nodeMap.size>1&&t.editor.update(()=>Ie())}const s=e.$getSelection(),l=o._selection;De(t,n,l,s)})}))},exports.syncYjsChangesToLexical=function(n,o,s,i,r=Ke){const l=n.editor,c=l._editorState;if(s.forEach(e=>e.delta),l.update(()=>{for(let e=0;e<s.length;e++){const t=s[e];Re(n,t)}je(c,n,o),i||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{onUpdate:()=>{r(n,o),n.root.isEmpty()&&l.update(()=>Ie())},skipTransforms:!0,tag:i?e.HISTORIC_TAG:e.COLLABORATION_TAG}),s.length>0){const e=s[0].transaction;t.iterateDeletedStructs(e,e.deleteSet,e=>{if(e.constructor===t.Item){const t=e.content.type;if(t){const e=t._collabNode;void 0!==e&&n.collabNodeMap.get(e._key)===e&&n.collabNodeMap.delete(e._key)}}})}},exports.syncYjsChangesToLexicalV2__EXPERIMENTAL=function(n,o,s,i,r){const l=n.editor,c=l._editorState;t.iterateDeletedStructs(i,i.deleteSet,e=>{if(e.constructor===t.Item){const t=e.content.type;t&&n.mapping.delete(t)}}),s.forEach(e=>e.delta),l.update(()=>{for(let e=0;e<s.length;e++){const t=s[e];Xe(n,t)}je(c,n,o),r||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{discrete:!0,onUpdate:()=>{Ke(n,o),0===n.root.length&&l.update(()=>Ie())},skipTransforms:!0,tag:r?e.HISTORIC_TAG:e.COLLABORATION_TAG})},exports.syncYjsStateToLexicalV2__EXPERIMENTAL=function(t,n){t.mapping.clear();const o=t.editor;o.update(()=>{e.$getRoot().clear(),W(t.root,t,null,!0),e.$addUpdateTag(e.COLLABORATION_TAG)},{discrete:!0,onUpdate:()=>{Ke(t,n),0===t.root.length&&o.update(()=>Ie())},skipTransforms:!0,tag:e.COLLABORATION_TAG})};
|
|
9
|
+
"use strict";var e=require("lexical"),t=require("yjs"),n=require("@lexical/selection");function o(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function s(e,t,n){const o=e.length,s=t.length;let i=0,r=0;for(;i<o&&i<s&&e[i]===t[i]&&i<n;)i++;for(;r+i<o&&r+i<s&&e[o-r-1]===t[s-r-1];)r++;for(;r+i<o&&r+i<s&&e[i]===t[i];)i++;return{index:i,insert:t.slice(i,s-r),remove:o-i-r}}class i{_xmlElem;_key;_parent;_type;constructor(e,t,n){this._key="",this._xmlElem=e,this._parent=t,this._type=n}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isDecoratorNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isDecoratorNode(t)?t:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent instanceof i&&o(394),this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);D(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();if(null===n)return;F(e,this._xmlElem,n,t)}syncSlotsFromYjs(e,t){z(e,this._xmlElem,t,this)}syncSlotsFromLexical(e,t,n,o,s){B(e,this._xmlElem,t,n,o,s,this)}destroy(e){const t=e.collabNodeMap;U(e,this._xmlElem),t.get(this._key)===this&&t.delete(this._key)}}function r(e,t,n){const o=new i(e,t,n);return e._collabNode=o,o}class l{_map;_key;_parent;_type;constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const t=e.$getNodeByKey(this._key);return e.$isLineBreakNode(t)?t:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function c(e,t){const n=new l(e,t);return e._collabNode=n,n}class a{_map;_key;_parent;_text;_type;_normalized;constructor(e,t,n,o){this._key="",this._map=e,this._parent=n,this._text=t,this._type=o,this._normalized=!1}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isTextNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isTextNode(t)?t: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(e,t,n){const o=this._parent._xmlText,s=this.getOffset()+1+e;0!==t&&o.delete(s,t),""!==n&&o.insert(s,n)}syncPropertiesAndTextFromLexical(t,n,o){const i=this.getPrevNode(o),r=n.__text;if(D(t,this._map,i,n),null!==i){const t=i.__text;if(t!==r){!function(t,n,o,i){const r=e.$getSelection();let l=i.length;if(e.$isRangeSelection(r)&&r.isCollapsed()){const e=r.anchor;e.key===n&&(l=e.offset)}const c=s(o,i,l);t.spliceText(c.index,c.remove,c.insert)}(this,n.__key,t,r),this._text=r}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();if(null===n)return;F(e,this._map,n,t);const o=this._text;n.__text!==o&&n.setTextContent(o)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function f(e,t,n,o){const s=new a(e,t,n,o);return e._collabNode=s,s}class d{_key;_children;_xmlText;_type;_parent;constructor(e,t,n){this._key="",this._children=[],this._xmlText=e,this._type=n,this._parent=t}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isElementNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isElementNode(t)?t:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){const e=this._parent;return e instanceof d||o(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null!==n&&F(e,this._xmlText,n,t)}applyChildrenYjsDelta(e,t){const n=this._children;let o=0,s=null;for(let r=0;r<t.length;r++){const c=t[r],f=c.insert,u=c.delete;if(null!=c.retain)o+=c.retain;else if("number"==typeof u){let e=u;for(;e>0;){const{node:t,nodeIndex:s,offset:r,length:c}=j(this,o,!1);if(t instanceof d||t instanceof l||t instanceof i)n.splice(s,1),e-=1;else{if(!(t instanceof a))break;{const o=Math.min(e,c),i=0!==s?n[s-1]:null,l=t.getSize();if(0===r&&c===l){n.splice(s,1);const e=R(t._text,r,o-1,"");e.length>0&&(i instanceof a?i._text+=e:this._xmlText.delete(r,e.length))}else t._text=R(t._text,r,o,"");e-=o}}}}else{if(null==f)throw new Error("Unexpected delta format");if("string"==typeof f){const{node:e,offset:t}=j(this,o,!0);e instanceof a?e._text=R(e._text,t,0,f):this._xmlText.delete(t,f.length),o+=f.length}else{const t=f;if(void 0===O(t))continue;const{node:i,nodeIndex:r,length:l}=j(this,o,!1),c=A(e,t,this);if(i instanceof a&&l>0&&l<i._text.length){const e=i._text,t=e.length-l;i._text=R(e,t,l,""),n.splice(r+1,0,c),s=R(e,0,t,"")}else n.splice(r,0,c);null!==s&&c instanceof a&&(c._text=s+c._text,s=null),o+=1}}}}syncChildrenFromYjs(t){const n=this.getNode();if(null===n)return;const s=n.__key,r=e.$createChildrenArray(n,null),c=r.length,f=this._children,u=f.length,h=t.collabNodeMap,g=new Set;let p,y,_=0,m=null;u!==c&&(y=n.getWritable());for(let c=0;c<u;c++){const x=r[_],N=f[c],S=N.getNode(),T=N._key;if(null!==S&&x===T){const n=e.$isTextNode(S);if(g.add(x),n)if(N._key=x,N instanceof d){const e=N._xmlText;N.syncPropertiesFromYjs(t,null),N.applyChildrenYjsDelta(t,e.toDelta()),N.syncChildrenFromYjs(t)}else N instanceof a?N.syncPropertiesAndTextFromYjs(t,null):N instanceof i?N.syncPropertiesFromYjs(t,null):N instanceof l||o(93);m=S,_++}else{if(void 0===p){p=new Set;for(let e=0;e<u;e++){const t=f[e]._key;""!==t&&p.add(t)}}if(null!==S&&void 0!==x&&!p.has(x)){const t=e.$getNodeByKeyOrThrow(x);e.$removeFromParent(t),c--,_++;continue}y=n.getWritable();const o=w(t,N,s),i=o.__key;if(h.set(i,N),null===m){const e=y.getFirstChild();if(y.__first=i,null!==e){const t=e.getWritable();t.__prev=i,o.__next=t.__key}}else{const e=m.getWritable(),t=m.getNextSibling();if(e.__next=i,o.__prev=m.__key,null!==t){const e=t.getWritable();e.__prev=i,o.__next=e.__key}}c===u-1&&(y.__last=i),y.__size++,m=o}}for(let n=0;n<c;n++){const o=r[n];if(!g.has(o)){const n=e.$getNodeByKeyOrThrow(o),s=t.collabNodeMap.get(o);void 0!==s&&s.destroy(t),e.$removeFromParent(n)}}this.syncSlotsFromYjs(t,n)}syncSlotsFromYjs(e,t){z(e,this._xmlText,t,this)}syncPropertiesFromLexical(e,t,n){D(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,o,s,r,l){const c=this._children[n],f=e.$getNodeByKeyOrThrow(o);c instanceof d&&e.$isElementNode(f)?(c.syncPropertiesFromLexical(t,f,s),c.syncChildrenFromLexical(t,f,s,r,l),c.syncSlotsFromLexical(t,f,s,r,l)):c instanceof a&&e.$isTextNode(f)?c.syncPropertiesAndTextFromLexical(t,f,s):c instanceof i&&e.$isDecoratorNode(f)&&(c.syncPropertiesFromLexical(t,f,s),c.syncSlotsFromLexical(t,f,s,r,l))}syncSlotsFromLexical(e,t,n,o,s){B(e,this._xmlText,t,n,o,s,this)}syncChildrenFromLexical(t,n,o,s,i){const r=this.getPrevNode(o),l=null===r?[]:e.$createChildrenArray(r,o),c=e.$createChildrenArray(n,null),a=l.length-1,f=c.length-1,d=t.collabNodeMap;let u,h,g=0,p=0;for(;g<=a&&p<=f;){const n=l[g],r=c[p];if(n===r)this._syncChildFromLexical(t,p,r,o,s,i),g++,p++;else{void 0===u&&(u=new Set(l)),void 0===h&&(h=new Set(c));const o=h.has(n),s=u.has(r);if(o){const n=v(t,e.$getNodeByKeyOrThrow(r),this);d.set(r,n),s?(this.splice(t,p,1,n),g++,p++):(this.splice(t,p,0,n),p++)}else this.splice(t,p,1),g++}}const y=g>a,_=p>f;if(y&&!_)for(;p<=f;++p){const n=c[p],o=v(t,e.$getNodeByKeyOrThrow(n),this);this.append(o),d.set(n,o)}else if(_&&!y)for(let e=this._children.length-1;e>=p;e--)this.splice(t,e,1)}append(e){const t=this._xmlText,n=this._children,o=n[n.length-1],s=void 0!==o?o.getOffset()+o.getSize():0;if(e instanceof d)t.insertEmbed(s,e._xmlText);else if(e instanceof a){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof l?t.insertEmbed(s,e._map):e instanceof i&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,s){const r=this._children,c=r[t];if(void 0===c)return void(void 0!==s&&this.append(s));const f=c.getOffset();-1===f&&o(95);const u=this._xmlText;if(0!==n){const o=r.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e);u.delete(f,c.getSize())}if(s instanceof d)u.insertEmbed(f,s._xmlText);else if(s instanceof a){const e=s._map;null===e.parent&&u.insertEmbed(f,e),u.insert(f+1,s._text)}else s instanceof l?u.insertEmbed(f,s._map):s instanceof i&&u.insertEmbed(f,s._xmlElem);void 0!==s?r.splice(t,n,s):r.splice(t,n)}getChildOffset(e){let t=0;const n=this._children;for(let o=0;o<n.length;o++){const s=n[o];if(s===e)return t;t+=s.getSize()}return-1}destroy(e){const t=e.collabNodeMap,n=this._children;for(let t=0;t<n.length;t++)n[t].destroy(e);U(e,this._xmlText),t.get(this._key)===this&&t.delete(this._key)}}function u(e,t,n){const o=new d(e,t,n);return e._collabNode=o,o}class h{_nodeMap=new Map;_sharedTypeToNodeKeys=new Map;_nodeKeyToSharedType=new Map;set(n,s){const i=s instanceof Array;this.delete(n);const r=i?s:[s];for(const e of r){const t=e.getKey();if(this._nodeKeyToSharedType.has(t)){const e=this._nodeKeyToSharedType.get(t),n=this._sharedTypeToNodeKeys.get(e).indexOf(t);-1!==n&&this._sharedTypeToNodeKeys.get(e).splice(n,1),this._nodeKeyToSharedType.delete(t),this._nodeMap.delete(t)}}if(n instanceof t.XmlText){if(i||o(331),0===s.length)return;this._sharedTypeToNodeKeys.set(n,s.map(e=>e.getKey()));for(const e of s)this._nodeMap.set(e.getKey(),e),this._nodeKeyToSharedType.set(e.getKey(),n)}else i&&o(332),e.$isTextNode(s)&&o(333),this._sharedTypeToNodeKeys.set(n,[s.getKey()]),this._nodeMap.set(s.getKey(),s),this._nodeKeyToSharedType.set(s.getKey(),n)}get(e){const n=this._sharedTypeToNodeKeys.get(e);if(void 0!==n){if(e instanceof t.XmlText){const e=Array.from(n.map(e=>this._nodeMap.get(e)));return e.length>0?e:void 0}return this._nodeMap.get(n[0])}}getSharedType(e){return this._nodeKeyToSharedType.get(e.getKey())}delete(e){const t=this._sharedTypeToNodeKeys.get(e);if(void 0!==t){for(const e of t)this._nodeMap.delete(e),this._nodeKeyToSharedType.delete(e);this._sharedTypeToNodeKeys.delete(e)}}deleteNode(e){const t=this._nodeKeyToSharedType.get(e);t&&this.delete(t),this._nodeMap.delete(e)}has(e){return this._sharedTypeToNodeKeys.has(e)}clear(){this._nodeMap.clear(),this._sharedTypeToNodeKeys.clear(),this._nodeKeyToSharedType.clear()}}function g(e,t,n,o,s){const i={clientID:n.clientID,cursorHighlightSheet:null,cursors:new Map,cursorsContainer:null,doc:n,docMap:o,editor:e,excludedProperties:s||new Map,id:t,nodeProperties:new Map};return function(e){const{editor:t,nodeProperties:n}=e;t.update(()=>{t._nodes.forEach(t=>{const o=new t.klass,s={};for(const[t,n]of Object.entries(o))$(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(i),i}function p({editor:e,id:n,doc:o,docMap:s,excludedProperties:i,rootName:r="root"}){const l=u(o.get(r,t.XmlText),null,"root");return l._key="root",{...g(e,n,o,s,i),collabNodeMap:new Map,root:l}}function y(e){return Object.prototype.hasOwnProperty.call(e,"collabNodeMap")}const _="__slots",m=new Set(["__key","__parent","__next","__prev","__state","__slotHost","__slots"]),x=new Set(["__first","__last","__size"]),N=new Set(["__cachedText"]),S=new Set(["__text"]);function T(e,t){e.setAttribute(_,t)}function b(e){return"__proto__"===e||"constructor"===e||"prototype"===e}function E(t){return(e.$isElementNode(t)||e.$isDecoratorNode(t))&&!t.isInline()}function $(t,n,o){if(m.has(t)||"function"==typeof n[t])return!0;if(e.$isTextNode(n)){if(S.has(t))return!0}else if(e.$isElementNode(n)&&(x.has(t)||e.$isRootNode(n)&&N.has(t)))return!0;const s=n.constructor,i=o.excludedProperties.get(s);return null!=i&&i.has(t)}function C(e,t){const n=e.__type,{nodeProperties:s}=t,i=s.get(n);return void 0===i&&o(330,n),i}function k(t,n,o,s,r,l){n instanceof d&&e.$isElementNode(o)?(n.syncPropertiesFromLexical(t,o,s),n.syncChildrenFromLexical(t,o,s,r,l),n.syncSlotsFromLexical(t,o,s,r,l)):n instanceof a&&e.$isTextNode(o)?n.syncPropertiesAndTextFromLexical(t,o,s):n instanceof i&&e.$isDecoratorNode(o)&&(n.syncPropertiesFromLexical(t,o,s),n.syncSlotsFromLexical(t,o,s,r,l))}function M(n,o,s,i){const r=e.$getSlotNames(o),l=e.getDeclaredSlots(o.constructor).length>0;if(0===r.length&&!l)return;const c=new t.Map;let a=!1;for(const t of r){const i=e.$getSlot(o,t);if(null===i)continue;const r=v(n,i,s);n.collabNodeMap.set(i.__key,r),c.set(t,r.getSharedType()),a=!0}(a||l)&&T(i,c)}function v(n,s,i){const l=s.__type;let a;if(e.$isElementNode(s)){const e=new t.XmlText;a=u(e,i,l),a.syncPropertiesFromLexical(n,s,null),a.syncChildrenFromLexical(n,s,null,null,null),M(n,s,a,e)}else if(e.$isTextNode(s)){i instanceof d||o(389);a=f(new t.Map,s.__text,i,l),a.syncPropertiesAndTextFromLexical(n,s,null)}else if(e.$isLineBreakNode(s)){i instanceof d||o(390);const e=new t.Map;e.set("__type","linebreak"),a=c(e,i)}else if(e.$isDecoratorNode(s)){const e=new t.XmlElement;a=r(e,i,l),a.syncPropertiesFromLexical(n,s,null),M(n,s,a,e)}else o(86);return a._key=s.__key,a}function O(e){const t=L(e,"__type");return"string"!=typeof t&&void 0!==t&&o(87),t}function A(e,n,s){const l=n._collabNode;if(void 0===l){const l=e.editor._nodes,a=O(n);"string"!=typeof a&&o(87);void 0===l.get(a)&&o(88,a);const h=n.parent,g=void 0===s&&null!==h?A(e,h):s||null;if(g instanceof d||g instanceof i&&function(e,n){const o=e._xmlElem.getAttribute(_);if(!(o instanceof t.Map))return!1;for(const e of o.values())if(e===n)return!0;return!1}(g,n)||o(391),n instanceof t.XmlText)return u(n,g,a);if(n instanceof t.Map)return g instanceof d||o(392),"linebreak"===a?c(n,g):f(n,"",g,a);if(n instanceof t.XmlElement)return r(n,g,a)}return l}function w(t,n,s){const r=n.getType(),l=t.editor._nodes.get(r);void 0===l&&o(88,r);const c=new l.klass;if(c.__parent=s,n._key=c.__key,n instanceof d){const e=n._xmlText;n.syncPropertiesFromYjs(t,null),n.applyChildrenYjsDelta(t,e.toDelta()),n.syncChildrenFromYjs(t)}else n instanceof a?n.syncPropertiesAndTextFromYjs(t,null):n instanceof i&&(n.syncPropertiesFromYjs(t,null),e.$isDecoratorNode(c)||o(393),n.syncSlotsFromYjs(t,c));return t.collabNodeMap.set(c.__key,n),c}function F(n,o,s,i){const r=null===i?o instanceof t.Map?Array.from(o.keys()):o instanceof t.XmlText||o instanceof t.XmlElement?Object.keys(o.getAttributes()):Object.keys(o):Array.from(i);let l;for(let i=0;i<r.length;i++){const c=r[i];if($(c,s,n)){"__state"===c&&y(n)&&(l||(l=s.getWritable()),K(o,l));continue}const a=s[c];let f=L(o,c);if(a!==f){if(f instanceof t.Doc){const o=n.docMap;a instanceof t.Doc&&o.delete(a.guid);const s=f.guid;if(o.set(s,f),e.isLexicalEditor(a))a._key=s,f=a;else{const t=e.createEditor();t._key=s,f=t}}void 0===l&&(l=s.getWritable()),l[c]=f}}}function L(e,n){return e instanceof t.Map?e.get(n):e instanceof t.XmlText||e instanceof t.XmlElement?e.getAttribute(n):e[n]}function P(e,n,o){e instanceof t.Map?e.set(n,o):e.setAttribute(n,o)}function K(n,o){const s=L(n,"__state");s instanceof t.Map&&e.$getWritableNodeState(o).updateFromJSON(s.toJSON())}function D(e,n,o,s){const i=Object.keys(C(s,e)),r=e.editor.constructor;!function(e,n,o,s){const i=s.__state,r=null===n.doc?void 0:L(n,"__state");if(!i)return;const[l,c]=i.getInternalState(),a=o&&o.__state,f=r instanceof t.Map?r:new t.Map;if(a===i)return;const[d,u]=a&&f.doc?a.getInternalState():[void 0,new Map];if(l)for(const[e,t]of Object.entries(l))d&&t!==d[e]&&f.set(e,t);for(const[e,t]of c)u.get(e)!==t&&f.set(e.key,e.unparse(t));r||P(n,"__state",f)}(0,n,o,s);for(let l=0;l<i.length;l++){const c=i[l],a=null===o?void 0:o[c];let f=s[c];if(a!==f){if(f instanceof r){const n=e.docMap;let o;if(a instanceof r){const e=a._key;o=n.get(e),n.delete(e)}const i=o||new t.Doc,l=i.guid;f._key=l,n.set(l,i),f=i,e.editor.update(()=>{s.markDirty()})}P(n,c,f)}}}function R(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function j(e,t,n){let o=0,s=0;const i=e._children,r=i.length;for(;s<r;s++){const e=i[s],l=o;o+=e.getSize();if((n?o>=t:o>t)&&e instanceof a){let n=t-l-1;n<0&&(n=0);return{length:o-t,node:e,nodeIndex:s,offset:n}}if(o>t)return{length:0,node:e,nodeIndex:s,offset:l};if(s===r-1)return{length:0,node:null,nodeIndex:s+1,offset:l+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function I(t){const n=t.anchor,o=t.focus;let s=!1;try{const t=n.getNode(),i=o.getNode();(!t.isAttached()||!i.isAttached()||e.$isTextNode(t)&&n.offset>t.getTextContentSize()||e.$isTextNode(i)&&o.offset>i.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function X(e,t){e.doc.transact(t,e)}function Y(t,n){const o=n._nodeMap.get(t);if(!o)return void e.$getRoot().selectStart();const s=o.__prev;let i=null;s&&(i=e.$getNodeByKey(s)),null===i&&null!==o.__parent&&(i=e.$getNodeByKey(o.__parent)),null!==i?null!==i&&i.isAttached()?i.selectEnd():Y(i.__key,n):e.$getRoot().selectStart()}function z(n,o,s,r){const l=o.getAttribute(_),c=l instanceof t.Map?new Set(l.keys()):new Set;for(const t of e.$getSlotNames(s))if(!c.has(t)){const o=e.$getSlot(s,t);if(null!==o){const e=n.collabNodeMap.get(o.__key);void 0!==e&&e.destroy(n)}e.$removeSlot(s,t)}if(l instanceof t.Map)for(const[o,c]of l.entries()){if(b(o))continue;if(!(c instanceof t.XmlText||c instanceof t.XmlElement||c instanceof t.Map))continue;const l=e.$getSlot(s,o),a=null===l?void 0:n.collabNodeMap.get(l.__key);if(void 0!==a&&a.getSharedType()===c)continue;if(void 0===c._collabNode&&"string"!=typeof L(c,"__type"))continue;if(c instanceof t.Map&&r instanceof i)continue;const f=c._collabNode;if(void 0!==f){const t=e.$getNodeByKey(f._key);if(null!==t&&(t.isAttached()||(e.$isElementNode(t)||e.$isDecoratorNode(t))&&null!==t.getLatest().__slotHost))continue}const d=A(n,c,r),u=w(n,d,null);E(u)?(void 0!==a&&a.destroy(n),e.$setSlot(s,o,u)):n.collabNodeMap.get(u.__key)===d&&n.collabNodeMap.delete(u.__key)}}function B(n,o,s,i,r,l,c){const a=e.$getSlotNames(s),f=o.getAttribute(_);if(0===a.length&&!(f instanceof t.Map))return;let d;f instanceof t.Map?d=f:(d=new t.Map,T(o,d));const u=new Set(a);for(const e of Array.from(d.keys()))if(!u.has(e)){const t=d.get(e),o=null==t?void 0:t._collabNode;void 0!==o&&o.destroy(n),d.delete(e)}const h=n.collabNodeMap;for(const t of a){const o=e.$getSlot(s,t);if(null===o)continue;const a=h.get(o.__key);if(void 0!==a&&d.get(t)===a.getSharedType())k(n,a,o,i,r,l);else{const e=d.get(t),s=null==e?void 0:e._collabNode;void 0!==s&&s.destroy(n);const i=v(n,o,c);h.set(o.__key,i),d.set(t,i.getSharedType())}}}function U(e,n){const o=n.getAttribute(_);if(o instanceof t.Map)for(const t of o.keys()){const n=o.get(t),s=null==n?void 0:n._collabNode;void 0!==s&&s.destroy(e)}}const W=e=>"UNDEFINED"===e.nodeName,H=(n,s,i,r,l,c,a)=>{let f=s.mapping.get(n);if(f&&i&&0===i.size&&!r)return f;const d=W(n)?e.RootNode.getType():n.nodeName,u=s.editor._nodes.get(d);if(void 0===u)throw new Error(`$createOrUpdateNodeFromYElement: Node ${d} is not registered`);if(f||(f=new u.klass,i=null,r=!0),r&&f instanceof e.ElementNode){const e=[],i=n=>{if(n instanceof t.XmlElement){const t=H(n,s,new Set,!1,l,c,a);null!==t&&e.push(t)}else if(n instanceof t.XmlText){const t=q(n,s,l,c,a);null!==t&&t.forEach(t=>{null!==t&&e.push(t)})}else o(329)};void 0===l||void 0===c?n.toArray().forEach(i):t.typeListToArraySnapshot(n,new t.Snapshot(c.ds,l.sv)).filter(e=>!e._item.deleted||V(e._item,l)||V(e._item,c)).forEach(i),G(f,e)}const h=n.getAttributes(l);W(n)||void 0===l||(V(n._item,l)?V(n._item,c)||(h[he("ychange")]=a?a("added",n._item.id):{type:"added"}):h[he("ychange")]=a?a("removed",n._item.id):{type:"removed"});const g={...C(f,s)},p={};for(const e in h)e.startsWith(ue)?p[ge(e)]=h[e]:e!==_&&"__proto__"!==e&&"constructor"!==e&&"prototype"!==e&&(g[e]=h[e]);if(F(s,g,f,i),i){if(i.size>0){const t=e.$getWritableNodeState(f);for(const e of i)if(e.startsWith(ue)){const n=ge(e);t.updateFromUnknown(n,p[n])}}}else e.$getWritableNodeState(f).updateFromJSON(p);if(f instanceof e.ElementNode||e.$isDecoratorNode(f)){const n=h[_],o=new Set;if(n instanceof t.Map){const i=void 0===l?Array.from(n.entries()):Object.entries(t.typeMapGetAllSnapshot(n,l));for(const[n,r]of i){if(o.add(n),b(n))continue;let i=null;if(r instanceof t.XmlElement&&(i=H(r,s,new Set,!1,l,c,a)),null===i)continue;const d=e.$getSlot(f,n);null!==d&&d.getKey()===i.getKey()||(E(i)?null===i.getLatest().__slotHost&&e.$setSlot(f,n,i):i.isAttached()||Q(r,s))}}for(const t of e.$getSlotNames(f))o.has(t)||e.$removeSlot(f,t)}const y=f.getLatest();return s.mapping.set(n,y),y},G=(e,t)=>{const n=e.getChildren(),o=new Set(n.map(e=>e.getKey())),s=new Set(t.map(e=>e.getKey())),i=n.length-1,r=t.length-1;let l=0,c=0;for(;l<=i&&c<=r;){const i=n[l].getKey(),r=t[c].getKey();if(i===r){l++,c++;continue}const a=s.has(i),f=o.has(r);if(!a){if(0===c&&1===e.getChildrenSize())return void e.splice(c,1,t.slice(c));e.splice(c,1,[]),l++;continue}const d=t[c];f?(e.splice(c,1,[d]),l++,c++):(e.splice(c,0,[d]),c++)}const a=l>i,f=c>r;a&&!f?e.append(...t.slice(c)):f&&!a&&e.splice(t.length,e.getChildrenSize()-t.length,[])},V=(e,n)=>void 0===n?!e.deleted:n.sv.has(e.id.client)&&n.sv.get(e.id.client)>e.id.clock&&!t.isDeleted(n.ds,e.id),q=(t,n,o,s,i)=>{const r=fe(t,o,s,i);let l=n.mapping.get(t)??[];const c=r.map(t=>t.attributes.t??e.TextNode.getType());if(!(l.length===c.length&&l.every((e,t)=>e.getType()===c[t]))){const t=n.editor._nodes;l=c.map(n=>{const o=t.get(n);if(void 0===o)throw new Error(`$createTextNodesFromYText: Node ${n} is not registered`);const s=new o.klass;if(!e.$isTextNode(s))throw new Error(`$createTextNodesFromYText: Node ${n} is not a TextNode`);return s})}for(let t=0;t<r.length;t++){const o=l[t],s=r[t],{attributes:i,insert:c}=s;o.__text!==c&&o.setTextContent(c);const a={...C(o,n),...i.p},f=Object.fromEntries(Object.entries(i).filter(([e])=>e.startsWith(ue)).map(([e,t])=>[ge(e),t]));F(n,a,o,null),e.$getWritableNodeState(o).updateFromJSON(f)}const a=l.map(e=>e.getLatest());return n.mapping.set(t,a),a},J=(n,o)=>{const s=e.$getSlotNames(n);if(0===s.length&&0===e.getDeclaredSlots(n.constructor).length)return;const i=new t.Map;for(const t of s){const s=e.$getSlot(n,t);null!=s&&i.set(t,ee(s,o))}return i},Q=(e,n)=>{if((e instanceof t.XmlElement||e instanceof t.XmlText)&&n.mapping.delete(e),e instanceof t.XmlElement){const o=e.getAttribute(_);if(o instanceof t.Map)for(const e of o.values())Q(e,n);for(const t of e.toArray())Q(t,n)}},Z=(n,o)=>{const s=new t.XmlElement(n.getType()),i={...de(n,o),...pe(n)};for(const e in i){const t=i[e];null!==t&&s.setAttribute(e,t)}if(!(n instanceof e.ElementNode)){const e=J(n,o);return void 0!==e&&(T(s,e),o.mapping.set(s,n)),s}const r=J(n,o);return void 0!==r&&T(s,r),s.insert(0,se(n).map(e=>te(e,o))),o.mapping.set(s,n),s},ee=(t,n)=>{const o=Z(t,n);return e.$isDecoratorNode(t)&&void 0===n.mapping.getSharedType(t)&&n.mapping.set(o,t),o},te=(e,n)=>e instanceof Array?((e,n)=>{const o=new t.XmlText;return ae(o,e,n),o})(e,n):Z(e,n),ne=e=>"object"==typeof e&&null!=e,oe=(e,t)=>{const n=Object.keys(e).filter(t=>null!==e[t]);if(null==t)return 0===n.length;let o=n.length===Object.keys(t).filter(e=>null!==t[e]).length;for(let s=0;s<n.length&&o;s++){const i=n[s],r=e[i],l=t[i];o="ychange"===i||r===l||ne(r)&&ne(l)&&oe(r,l)}return o},se=t=>{if(!(t instanceof e.ElementNode))return[];const n=t.getChildren(),o=[];for(let t=0;t<n.length;t++){const s=n[t];if(e.$isTextNode(s)){const s=[];for(let o=n[t];t<n.length&&e.$isTextNode(o);o=n[++t])s.push(o);t--,o.push(s)}else o.push(s)}return o},ie=(t,n,o)=>{const s=fe(t);return s.length===n.length&&s.every((t,s)=>{const i=n[s],r=t.attributes.t??e.TextNode.getType(),l=t.attributes.p??{},c=Object.fromEntries(Object.entries(t.attributes).filter(([e])=>e.startsWith(ue)));return t.insert===i.getTextContent()&&r===i.getType()&&oe(l,de(i,o))&&oe(c,pe(i))})},re=(n,o,s)=>{if(n instanceof t.XmlElement&&!(o instanceof Array)&&_e(n,o)){const i=se(o),r=n.getAttributes();return delete r[_],n._length===i.length&&oe(r,{...de(o,s),...pe(o)})&&((n,o,s)=>{const i=e.$getSlotNames(o),r=n.getAttribute(_);if(!(r instanceof t.Map))return 0===i.length;if(r.size!==i.length)return!1;for(const n of i){const i=e.$getSlot(o,n),l=r.get(n);if(null===i||!(l instanceof t.XmlElement)||s.mapping.get(l)!==i)return!1}return!0})(n,o,s)&&n.toArray().every((e,t)=>re(e,i[t],s))}return n instanceof t.XmlText&&o instanceof Array&&ie(n,o,s)},le=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),ce=(e,n,o)=>{const s=e.toArray(),i=se(n),r=i.length,l=s.length,c=Math.min(l,r);let a=0,f=0,d=!1;for(;a<c;a++){const e=s[a],n=i[a];if(e instanceof t.XmlHook)break;if(le(o.mapping.get(e),n))d=!0;else if(!re(e,n,o))break}for(;a+f<c;f++){const e=s[l-f-1],n=i[r-f-1];if(e instanceof t.XmlHook)break;if(le(o.mapping.get(e),n))d=!0;else if(!re(e,n,o))break}return{equalityFactor:a+f,foundMappedChild:d}},ae=(n,o,i)=>{i.mapping.set(n,o);const{nAttrs:r,str:l}=(e=>{let n="",o=e._start;const s={};for(;null!==o;)o.deleted||(o.countable&&o.content instanceof t.ContentString?n+=o.content.str:o.content instanceof t.ContentFormat&&(s[o.content.key]=null)),o=o.right;return{nAttrs:s,str:n}})(n),c=o.map((t,n)=>{const o=t.getType();let s=de(t,i);return 0===Object.keys(s).length&&(s=null),{attributes:Object.assign({},r,{...o!==e.TextNode.getType()&&{t:o},p:s,...pe(t),...n>0&&{i:n}}),insert:t.getTextContent(),nodeKey:t.getKey()}}),a=c.map(e=>e.insert).join(""),f=e.$getSelection();let d;if(e.$isRangeSelection(f)&&f.isCollapsed()){d=0;for(const e of c){if(e.nodeKey===f.anchor.key){d+=f.anchor.offset;break}d+=e.insert.length}}else d=a.length;const{insert:u,remove:h,index:g}=s(l,a,d);n.delete(g,h),n.insert(g,u),n.applyDelta(c.map(e=>({attributes:e.attributes,retain:e.insert.length})))},fe=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>{const t=e.attributes??{};return"ychange"in t&&(t[he("ychange")]=t.ychange,delete t.ychange),{...e,attributes:t}}),de=(e,t)=>{const n=C(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},ue="s_",he=e=>`s_${e}`,ge=e=>{if(!e.startsWith(ue))throw new Error(`Invalid state key: ${e}`);return e.slice(ue.length)},pe=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[he(e)]=t;for(const[e,t]of o)s[he(e.key)]=e.unparse(t);return s},ye=(n,o,s,i,r)=>{if(o instanceof t.XmlElement&&o.nodeName!==s.getType()&&(!W(o)||s.getType()!==e.RootNode.getType()))throw new Error("node name mismatch!");if(i.mapping.set(o,s),o instanceof t.XmlElement){const l=o.getAttributes(),c={...de(s,i),...pe(s)};for(const e in c)if(null!=c[e]){l[e]===c[e]||ne(l[e])&&ne(c[e])&&oe(l[e],c[e])||"ychange"===e||o.setAttribute(e,c[e])}else o.removeAttribute(e);for(const e in l)e!==_&&void 0===c[e]&&o.removeAttribute(e);(s instanceof e.ElementNode||e.$isDecoratorNode(s))&&((n,o,s,i,r)=>{const l=e.$getSlotNames(o),c=n.getAttribute(_);if(0===l.length&&!(c instanceof t.Map)&&0===e.getDeclaredSlots(o.constructor).length)return;let a;c instanceof t.Map?a=c:(a=new t.Map,T(n,a));const f=new Set(l);for(const e of Array.from(a.keys()))if(!f.has(e)){const t=a.get(e);void 0!==t&&Q(t,s),a.delete(e)}for(const n of l){const l=e.$getSlot(o,n);if(null==l)continue;const c=a.get(n);c instanceof t.XmlElement&&(l instanceof e.ElementNode||e.$isDecoratorNode(l))&&c===s.mapping.getSharedType(l)?i.has(l.getKey())&&ye(r,c,l,s,i):(c instanceof t.XmlElement&&Q(c,s),a.set(n,ee(l,s)))}})(o,s,i,r,n)}const l=se(s),c=l.length,a=o.toArray(),f=a.length,d=Math.min(c,f);let u=0,h=0;for(;u<d;u++){const o=a[u],s=l[u];if(o instanceof t.XmlHook)break;if(le(i.mapping.get(o),s))s instanceof Array||!(s instanceof e.ElementNode||e.$isDecoratorNode(s))||!r.has(s.getKey())||ye(n,o,s,i,r);else{if(!re(o,s,i))break;i.mapping.set(o,s)}}for(;h+u<d;h++){const o=a[f-h-1],s=l[c-h-1];if(o instanceof t.XmlHook)break;if(le(i.mapping.get(o),s))s instanceof Array||!(s instanceof e.ElementNode||e.$isDecoratorNode(s))||!r.has(s.getKey())||ye(n,o,s,i,r);else{if(!re(o,s,i))break;i.mapping.set(o,s)}}for(;f-u-h>0&&c-u-h>0;){const e=a[u],s=l[u],d=a[f-h-1],g=l[c-h-1];if(e instanceof t.XmlText&&s instanceof Array)ie(e,s,i)||ae(e,s,i),u+=1;else{let l=e instanceof t.XmlElement&&_e(e,s),c=d instanceof t.XmlElement&&_e(d,g);if(l&&c){const t=ce(e,s,i),n=ce(d,g,i);t.foundMappedChild&&!n.foundMappedChild?c=!1:!t.foundMappedChild&&n.foundMappedChild||t.equalityFactor<n.equalityFactor?l=!1:c=!1}l?(ye(n,e,s,i,r),u+=1):c?(ye(n,d,g,i,r),h+=1):(i.mapping.delete(o.get(u)),o.delete(u,1),o.insert(u,[te(s,i)]),u+=1)}}const g=f-u-h;if(1===f&&0===c&&a[0]instanceof t.XmlText?(i.mapping.delete(a[0]),a[0].delete(0,a[0].length)):g>0&&(o.slice(u,u+g).forEach(e=>i.mapping.delete(e)),o.delete(u,g)),u+h<c){const e=[];for(let t=u;t<c-h;t++)e.push(te(l[t],i));o.insert(u,e)}},_e=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType(),me=/* @__PURE__ */e.createState("ychange",{isEqual:(e,t)=>e===t,parse:e=>e??null});const xe="undefined"!=typeof Highlight&&"undefined"!=typeof CSS&&"highlights"in CSS;function Ne(t,n,o){if(!CSS.supports("color",o))return;const s=function(t){const n=t.editor.getRootElement(),o=e.getRootOwnerDocument(n);let s=t.cursorHighlightSheet;null===s&&(s=new(o.defaultView||window).CSSStyleSheet,t.cursorHighlightSheet=s);const i=null!==n?n.getRootNode():null,r=e.isDOMShadowRoot(i)?i:o;return r.adoptedStyleSheets.includes(s)||(r.adoptedStyleSheets=[...r.adoptedStyleSheets,s]),s}(t),i=s.insertRule(`::highlight(${n}) { }`,s.cssRules.length),r=s.cssRules[i];r.style.setProperty("background-color",`color-mix(in srgb, ${o} 30%, transparent)`),r.style.setProperty("color","inherit")}function Se(e,t){const n=e.cursorHighlightSheet;if(null===n)return;const o=`::highlight(${t})`;for(let e=n.cssRules.length-1;e>=0;e--){const t=n.cssRules[e];if(null!=t&&t.selectorText===o)return void n.deleteRule(e)}}function Te(n,s,i=0){const r=s.collabNodeMap.get(n.key);if(void 0===r)return null;let l=n.offset,c=r.getSharedType();if(r instanceof a){c=r._parent._xmlText;const e=r.getOffset();if(-1===e)return null;l=e+1+l}else if(r instanceof d&&"element"===n.type){const t=n.getNode();e.$isElementNode(t)||o(184);let s=0,i=0,r=t.getFirstChild();for(;null!==r&&i++<l;)e.$isTextNode(r)?s+=r.getTextContentSize()+1:s++,r=r.getNextSibling();l=s}return t.createRelativePositionFromTypeIndex(c,l,i)}function be(n,s,i=0){const{mapping:r}=s,{offset:l}=n,c=n.getNode(),a=r.getSharedType(c);if(void 0===a)return null;if("text"===n.type){e.$isTextNode(c)||o(326);let n=c.getPreviousSibling(),s=l;for(;e.$isTextNode(n);)s+=n.getTextContentSize(),n=n.getPreviousSibling();return t.createRelativePositionFromTypeIndex(a,s,i)}if("element"===n.type){e.$isElementNode(c)||o(184);let n=0,s=c.getFirstChild();for(;null!==s&&n<l;){if(e.$isTextNode(s)){let t=s.getNextSibling();for(;e.$isTextNode(t);)t=t.getNextSibling()}n++,s=s.getNextSibling()}return t.createRelativePositionFromTypeIndex(a,n,i)}return null}function Ee(e,n){return t.createAbsolutePositionFromRelativePosition(e,n.doc)}function $e(e,n){if(null==e){if(null!=n)return!0}else if(null==n||!t.compareRelativePositions(e,n))return!0;return!1}function Ce(e,t){return{color:t,name:e,selection:null}}function ke(e,t){null!==t.highlight&&(CSS.highlights.delete(t.highlightName),Se(e,t.highlightName));const n=e.cursorsContainer;if(null===n)return;t.caret.parentNode===n&&n.removeChild(t.caret);const o=t.selections;for(let e=0;e<o.length;e++)o[e].parentNode===n&&n.removeChild(o[e])}function Me(e,t){const n=t.selection;null!==n&&ke(e,n)}function ve(t,n,o,s,i,r,l,c,a={}){const f=t.color,d=e.getRootOwnerDocument(n.editor.getRootElement()),u=d.createElement("span");a.cursor?(u.className=a.cursor,e.setDOMStyleObject(u.style,{"--lexical-cursor-color":f,bottom:"0",position:"absolute",right:"-1px",top:"0"})):e.setDOMStyleObject(u.style,{"background-color":f,bottom:"0",position:"absolute",right:"-1px",top:"0",width:"1px","z-index":"10"});const h=d.createElement("span");h.textContent=t.name,a.cursorName?h.className=a.cursorName:e.setDOMStyleObject(h.style,{"background-color":f,color:"#fff","font-family":"Arial","font-size":"12px","font-weight":"bold",left:"-2px","line-height":"12px",padding:"2px",position:"absolute",top:"-16px","white-space":"nowrap"}),u.appendChild(h);const g=`lexical-cursor-${n.id}-${o}`;let p=null;return c&&xe&&(p=new Highlight,CSS.highlights.set(g,p),Ne(n,g,f)),{anchor:{key:s,offset:i},caret:u,color:f,focus:{key:r,offset:l},highlight:p,highlightName:g,name:h,selections:[]}}function Oe(t,o,s,i,r={}){const l=t.editor,c=l.getRootElement(),a=t.cursorsContainer;if(null===a||null===c)return;const f=e.getRootOwnerDocument(c),d=a.offsetParent;if(null===d)return;const u=d.getBoundingClientRect(),h=o.selection;if(null===s)return null===h?void 0:(o.selection=null,void ke(t,h));o.selection=s;const g=s.caret,p=s.color,y=s.highlight,_=s.anchor,m=s.focus,x=_.key,N=m.key,S=i.get(x),T=i.get(N);if(null==S||null==T)return;if(null!==y){const t=n.createDOMRange(l,S,_.offset,T,m.offset);if(null===t)return;y.clear(),t.collapsed||y.add(t);const o=t.cloneRange();o.collapse(!1);let s=o.getBoundingClientRect();if(0===s.height&&e.$isLineBreakNode(T)){const e=l.getElementByKey(N);null!==e&&(s=e.getBoundingClientRect())}return e.setDOMStyleObject(g.style,{"background-color":r.cursor?"":p,bottom:"",height:`${s.height||16}px`,left:s.left-u.left+"px","pointer-events":"none",position:"absolute",right:"",top:s.top-u.top+"px",width:"1px","z-index":"10"}),void(g.parentNode!==a&&a.appendChild(g))}const b=s.selections;let E;if(S===T&&e.$isLineBreakNode(S)){E=[l.getElementByKey(x).getBoundingClientRect()]}else{const e=n.createDOMRange(l,S,_.offset,T,m.offset);if(null===e)return;E=n.createRectsFromDOMRange(l,e)}const $=b.length,C=E.length;for(let t=0;t<C;t++){const n=E[t];let o=b[t];if(void 0===o){o=f.createElement("span"),b[t]=o;const e=f.createElement("span");r.selectionBg&&(e.className=r.selectionBg),o.appendChild(e),a.appendChild(o)}const s=n.top-u.top,i=n.left-u.left,l={height:`${n.height}px`,left:`${i}px`,"pointer-events":"none",position:"absolute",top:`${s}px`,width:`${n.width}px`};r.selection?(o.className=r.selection,e.setDOMStyleObject(o.style,{...l,"--lexical-cursor-color":p}),e.setDOMStyleObject(o.firstChild.style,{height:"100%",left:"0",position:"absolute",top:"0",width:"100%"})):(e.setDOMStyleObject(o.style,l),e.setDOMStyleObject(o.firstChild.style,{...l,"background-color":p,left:"0",opacity:"0.3",top:"0","z-index":"5"})),t===C-1&&g.parentNode!==o&&o.appendChild(g)}for(let e=$-1;e>=C;e--){const t=b[e];a.removeChild(t),b.pop()}}function Ae(t,n){const{anchorPos:o,focusPos:s}=n,i=o?Ee(o,t):null,r=s?Ee(s,t):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(y(t)){const[e,t]=Le(i.type,i.index),[n,o]=Le(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=Pe(t.mapping,i),[a,f]=Pe(t.mapping,r);if(a&&l&&(a!==l||f!==c)){const t=a.isBefore(l),n=t?a:l,o=t?f:c;e.$isTextNode(n)&&e.$isTextNode(n.getNextSibling())&&o===n.getTextContentSize()&&(t?(a=n.getNextSibling(),f=0):(l=n.getNextSibling(),c=0))}return{anchorKey:null!==l?l.getKey():null,anchorOffset:c,focusKey:null!==a?a.getKey():null,focusOffset:f}}function we(t,n){const o=n.awareness.getLocalState();if(null===o)return;const{anchorKey:s,anchorOffset:i,focusKey:r,focusOffset:l}=Ae(t,o);if(null!==s&&null!==r){const t=e.$getSelection();if(!e.$isRangeSelection(t))return;Fe(t.anchor,s,i),Fe(t.focus,r,l)}}function Fe(t,n,o){if(t.key!==n||t.offset!==o){let s=e.$getNodeByKey(n);if(null!==s&&!e.$isElementNode(s)&&!e.$isTextNode(s)){const e=s.getParentOrThrow();n=e.getKey(),o=s.getIndexWithinParent(),s=e}t.set(n,o,e.$isElementNode(s)?"element":"text")}}function Le(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof d){const{node:e,offset:o}=j(n,t,!0);return null===e?[n,n._children.length]:[e,o]}return[null,0]}function Pe(n,o){const s=o.type,i=o.index;if(s instanceof t.XmlElement){const t=n.get(s);if(void 0===t)return[null,0];if(!e.$isElementNode(t))return[t,i];let o=i,r=0;const l=t.getChildren();for(;o>0&&r<l.length;){const t=l[r];if(o-=1,r+=1,e.$isTextNode(t))for(;r<l.length&&e.$isTextNode(l[r]);)r+=1}return[t,r]}{const e=n.get(s);if(void 0===e)return[null,0];let t=0,o=i;for(;o>e[t].getTextContentSize()&&t+1<e.length;)o-=e[t].getTextContentSize(),t++;const r=e[t];return[r,Math.min(o,r.getTextContentSize())]}}function Ke(e,t){return t.awareness.getStates()}function De(e,t,n){const{getAwarenessStates:o=Ke,selectionHighlight:s=!1}=n??{},i=Array.from(o(e,t)),r=e.clientID,l=e.cursors,c=e.editor,a=c._config.theme.collaboration,f=c._editorState._nodeMap,d=new Set;for(let t=0;t<i.length;t++){const n=i[t],[o,u]=n;if(0!==o&&o!==r){d.add(o);const{name:t,color:n,focusing:i}=u;let r=null,h=l.get(o);if(void 0===h&&(h=Ce(t,n),l.set(o,h)),i){const{anchorKey:t,anchorOffset:n,focusKey:i,focusOffset:l}=c.read(()=>Ae(e,u));if(null!==t&&null!==i)if(r=h.selection,null===r)r=ve(h,e,o,t,n,i,l,s,a);else{const e=r.anchor,o=r.focus;e.key=t,e.offset=n,o.key=i,o.offset=l}}Oe(e,h,r,f,a)}}const u=Array.from(l.keys());for(let t=0;t<u.length;t++){const n=u[t];if(!d.has(n)){const t=l.get(n);void 0!==t&&(Me(e,t),l.delete(n))}}}function Re(t,n,o,s){const i=n.awareness,r=i.getLocalState();if(null===r)return;const{anchorPos:l,focusPos:c,name:a,color:f,focusing:d,awarenessData:u}=r;let h=null,g=null;if(null!==s&&(null===l||s.is(o))||null!==o){if(e.$isRangeSelection(s)){const e=s.isCollapsed(),n=!e&&s.isBackward(),o=n?-1:0,i=e||n?0:-1;y(t)?(h=Te(s.anchor,t,o),g=Te(s.focus,t,i)):(h=be(s.anchor,t,o),g=be(s.focus,t,i))}($e(l,h)||$e(c,g))&&i.setLocalState({...r,anchorPos:h,awarenessData:u,color:f,focusPos:g,focusing:d,name:a})}}function je(n,s){if(s instanceof t.YMapEvent&&function(n,o){const{target:s}=o;if(!s._item||"__state"!==s._item.parentSub||void 0!==O(s)||!(s.parent instanceof t.XmlText||s.parent instanceof t.XmlElement||s.parent instanceof t.Map))return!1;const i=A(n,s.parent).getNode();if(i){const t=e.$getWritableNodeState(i.getWritable());for(const e of o.keysChanged)t.updateFromUnknown(e,s.get(e))}return!0}(n,s))return;const{target:r}=s;if(s instanceof t.YMapEvent&&r instanceof t.Map&&null!=r._item&&r._item.parentSub===_&&(r.parent instanceof t.XmlText||r.parent instanceof t.XmlElement)){const e=A(n,r.parent);if(e instanceof d){const t=e.getNode();null!==t&&e.syncSlotsFromYjs(n,t)}else if(e instanceof i){const t=e.getNode();null!==t&&e.syncSlotsFromYjs(n,t)}return}const l=A(n,r);if(l instanceof d&&s instanceof t.YTextEvent){const{keysChanged:e,childListChanged:t,delta:o}=s;if(e.size>0&&l.syncPropertiesFromYjs(n,e),e.has(_)){const e=l.getNode();null!==e&&l.syncSlotsFromYjs(n,e)}t&&(l.applyChildrenYjsDelta(n,o),l.syncChildrenFromYjs(n))}else if(l instanceof a&&s instanceof t.YMapEvent){const{keysChanged:e}=s;e.size>0&&l.syncPropertiesAndTextFromYjs(n,e)}else if(l instanceof i&&s instanceof t.YXmlEvent){const{attributesChanged:e}=s;if(e.size>0&&l.syncPropertiesFromYjs(n,e),e.has(_)){const e=l.getNode();null!==e&&l.syncSlotsFromYjs(n,e)}}else o(82)}function Ie(t,n,o){const s=e.$getSelection();if(e.$isRangeSelection(s))if(I(s)){const i=t._selection;if(e.$isRangeSelection(i)&&(we(n,o),I(s))){Y(s.anchor.key,t)}Re(n,o,i,e.$getSelection())}else we(n,o)}function Xe(){0===e.$getRoot().getChildrenSize()&&e.$getRoot().append(e.$createParagraphNode())}function Ye(e,n){const{target:s}=n;if(s instanceof t.XmlElement&&n instanceof t.YXmlEvent)H(s,e,n.attributesChanged,n.childListChanged);else if(s instanceof t.XmlText&&n instanceof t.YTextEvent){const n=s.parent;n instanceof t.XmlElement?H(n,e,new Set,!0):o(327)}else if(s instanceof t.Map&&n instanceof t.YMapEvent&&null!=s._item&&s._item.parentSub===_){const n=s.parent;n instanceof t.XmlElement?H(n,e,new Set([_]),!1):o(388)}else o(328)}const ze=/* @__PURE__ */e.createCommand("CONNECTED_COMMAND"),Be=/* @__PURE__ */e.createCommand("TOGGLE_CONNECT_COMMAND"),Ue=/* @__PURE__ */e.createCommand("DIFF_VERSIONS_COMMAND"),We=/* @__PURE__ */e.createCommand("CLEAR_DIFF_VERSIONS_COMMAND");exports.$getAnchorAndFocusForUserState=Ae,exports.$getYChangeState=function(t){return e.$getState(t,me)},exports.CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL=We,exports.CONNECTED_COMMAND=ze,exports.DIFF_VERSIONS_COMMAND__EXPERIMENTAL=Ue,exports.TOGGLE_CONNECT_COMMAND=Be,exports.createBinding=function(e,t,n,s,i,r){return null==s&&o(81),p({doc:s,docMap:i,editor:e,excludedProperties:r,id:n})},exports.createBindingV2__EXPERIMENTAL=function(e,n,s,i,r={}){null==s&&o(81);const{excludedProperties:l,rootName:c="root-v2"}=r;return{...g(e,n,s,i,l),mapping:new h,root:s.get(c,t.XmlElement)}},exports.createUndoManager=function(e,n){return new t.UndoManager(n,{trackedOrigins:new Set([e,null])})},exports.createYjsBinding=p,exports.getAnchorAndFocusCollabNodesForUserState=function(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,i=0,r=null,l=0;if(null!==n&&null!==o){const t=Ee(n,e),c=Ee(o,e);null!==t&&null!==c&&([s,i]=Le(t.type,t.index),[r,l]=Le(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:i,focusCollabNode:r,focusOffset:l}},exports.initLocalState=function(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})},exports.removeCursorHighlightRule=Se,exports.renderSnapshot__EXPERIMENTAL=(n,s=t.snapshot(n.doc),i=t.emptySnapshot)=>{const{doc:r}=n;r.gc&&o(325),r.transact(o=>{const l=new t.PermanentUserData(r);l&&l.dss.forEach(e=>{t.iterateDeletedStructs(o,e,e=>{})});const c=(e,t)=>({id:t,type:e,user:("added"===e?l.getUserByClientId(t.client):l.getUserByDeletedId(t))??null});n.mapping.clear(),n.editor.update(()=>{e.$getRoot().clear(),H(n.root,n,null,!0,s,i,c)})},n)},exports.setLocalStateFocus=function(e,t,n,o,s){const{awareness:i}=e;let r=i.getLocalState();null===r&&(r={anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t}),r.focusing=o,i.setLocalState(r)},exports.syncCursorPositions=De,exports.syncLexicalUpdateToYjs=function(t,n,o,s,i,r,l,c){X(t,()=>{s.read(()=>{if(c.has(e.COLLABORATION_TAG)||c.has(e.HISTORIC_TAG))return void(l.size>0&&function(t,n){const o=Array.from(n),s=t.collabNodeMap,i=[],r=[];for(let t=0;t<o.length;t++){const n=o[t],l=e.$getNodeByKey(n),c=s.get(n);if(c instanceof a)if(e.$isTextNode(l))i.push([c,l.__text]);else{const e=c.getOffset();if(-1===e)continue;const t=c._parent;c._normalized=!0,t._xmlText.delete(e,1),r.push(c)}}for(let e=0;e<r.length;e++){const t=r[e],n=t.getKey();s.delete(n);const o=t._parent._children,i=o.indexOf(t);o.splice(i,1)}for(let e=0;e<i.length;e++){const[t,n]=i[e];t._text=n}}(t,l));if(i.has("root")){const n=o._nodeMap,s=e.$getRoot(),l=t.root;l.syncPropertiesFromLexical(t,s,n),l.syncChildrenFromLexical(t,s,n,i,r),l.syncSlotsFromLexical(t,s,n,i,r),0===s.getChildrenSize()&&o._nodeMap.size>1&&t.editor.update(()=>Xe())}const s=e.$getSelection(),f=o._selection;Re(t,n,f,s)})})},exports.syncLexicalUpdateToYjsV2__EXPERIMENTAL=function(t,n,o,s,i,r,l,c){const a=c.has(e.COLLABORATION_TAG)||c.has(e.HISTORIC_TAG);a&&0===l.size||(l.forEach(e=>{t.mapping.deleteNode(e)}),X(t,()=>{s.read(()=>{if(i.has("root")){const n=e.$getRoot();ye(t.doc,t.root,n,t,new Set([...i.keys(),...r])),!a&&0===n.getChildrenSize()&&o._nodeMap.size>1&&t.editor.update(()=>Xe())}const s=e.$getSelection(),l=o._selection;Re(t,n,l,s)})}))},exports.syncYjsChangesToLexical=function(n,o,s,i,r=De){const l=n.editor,c=l._editorState;if(s.forEach(e=>e.delta),l.update(()=>{for(let e=0;e<s.length;e++){const t=s[e];je(n,t)}Ie(c,n,o),i||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{onUpdate:()=>{r(n,o),n.root.isEmpty()&&l.update(()=>Xe())},skipTransforms:!0,tag:i?e.HISTORIC_TAG:e.COLLABORATION_TAG}),s.length>0){const e=s[0].transaction;t.iterateDeletedStructs(e,e.deleteSet,e=>{if(e.constructor===t.Item){const t=e.content.type;if(t){const e=t._collabNode;void 0!==e&&n.collabNodeMap.get(e._key)===e&&n.collabNodeMap.delete(e._key)}}})}},exports.syncYjsChangesToLexicalV2__EXPERIMENTAL=function(n,o,s,i,r){const l=n.editor,c=l._editorState;t.iterateDeletedStructs(i,i.deleteSet,e=>{if(e.constructor===t.Item){const t=e.content.type;t&&n.mapping.delete(t)}}),s.forEach(e=>e.delta),l.update(()=>{for(let e=0;e<s.length;e++){const t=s[e];Ye(n,t)}Ie(c,n,o),r||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{discrete:!0,onUpdate:()=>{De(n,o),0===n.root.length&&l.update(()=>Xe())},skipTransforms:!0,tag:r?e.HISTORIC_TAG:e.COLLABORATION_TAG})},exports.syncYjsStateToLexicalV2__EXPERIMENTAL=function(t,n){t.mapping.clear();const o=t.editor;o.update(()=>{e.$getRoot().clear(),H(t.root,t,null,!0),e.$addUpdateTag(e.COLLABORATION_TAG)},{discrete:!0,onUpdate:()=>{De(t,n),0===t.root.length&&o.update(()=>Xe())},skipTransforms:!0,tag:e.COLLABORATION_TAG})};
|
package/dist/LexicalYjs.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$isDecoratorNode as e,$getNodeByKey as t,$isLineBreakNode as n,$isTextNode as o,$getSelection as s,$isRangeSelection as i,$isElementNode as r,$createChildrenArray as l,$getNodeByKeyOrThrow as c,$removeFromParent as a,isLexicalEditor as f,createEditor as u,$getSlotNames as d,$getSlot as h,$removeSlot as g,$setSlot as p,$isRootNode as y,$getWritableNodeState as _,getDeclaredSlots as m,$getRoot as x,RootNode as S,ElementNode as b,TextNode as T,$getState as N,createState as k,getRootOwnerDocument as v,setDOMStyleObject as w,isDOMShadowRoot as C,COLLABORATION_TAG as F,HISTORIC_TAG as A,$addUpdateTag as M,SKIP_SCROLL_INTO_VIEW_TAG as O,$createParagraphNode as K,createCommand as E}from"lexical";import{XmlText as P,XmlElement as j,Map as L,Doc as z,typeListToArraySnapshot as Y,Snapshot as D,typeMapGetAllSnapshot as I,isDeleted as R,XmlHook as $,ContentString as W,ContentFormat as B,emptySnapshot as U,PermanentUserData as H,iterateDeletedStructs as q,snapshot as J,createAbsolutePositionFromRelativePosition as V,createRelativePositionFromTypeIndex as G,compareRelativePositions as Q,Item as X,YMapEvent as Z,YTextEvent as ee,YXmlEvent as te,UndoManager as ne}from"yjs";import{createDOMRange as oe,createRectsFromDOMRange as se}from"@lexical/selection";function ie(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function re(e,t,n){const o=e.length,s=t.length;let i=0,r=0;for(;i<o&&i<s&&e[i]===t[i]&&i<n;)i++;for(;r+i<o&&r+i<s&&e[o-r-1]===t[s-r-1];)r++;for(;r+i<o&&r+i<s&&e[i]===t[i];)i++;return{index:i,insert:t.slice(i,s-r),remove:o-i-r}}class le{_xmlElem;_key;_parent;_type;constructor(e,t,n){this._key="",this._xmlElem=e,this._parent=t,this._type=n}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e(n)?n:null}getNode(){const n=t(this._key);return e(n)?n:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent instanceof le&&ie(394),this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);Ie(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();if(null===n)return;Le(e,this._xmlElem,n,t)}syncSlotsFromYjs(e,t){He(e,this._xmlElem,t,this)}syncSlotsFromLexical(e,t,n,o,s){qe(e,this._xmlElem,t,n,o,s,this)}destroy(e){const t=e.collabNodeMap;Je(e,this._xmlElem),t.get(this._key)===this&&t.delete(this._key)}}function ce(e,t,n){const o=new le(e,t,n);return e._collabNode=o,o}class ae{_map;_key;_parent;_type;constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const e=t(this._key);return n(e)?e:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function fe(e,t){const n=new ae(e,t);return e._collabNode=n,n}class ue{_map;_key;_parent;_text;_type;_normalized;constructor(e,t,n,o){this._key="",this._map=e,this._parent=n,this._text=t,this._type=o,this._normalized=!1}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return o(t)?t:null}getNode(){const e=t(this._key);return o(e)?e: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(e,t,n){const o=this._parent._xmlText,s=this.getOffset()+1+e;0!==t&&o.delete(s,t),""!==n&&o.insert(s,n)}syncPropertiesAndTextFromLexical(e,t,n){const o=this.getPrevNode(n),r=t.__text;if(Ie(e,this._map,o,t),null!==o){const e=o.__text;if(e!==r){!function(e,t,n,o){const r=s();let l=o.length;if(i(r)&&r.isCollapsed()){const e=r.anchor;e.key===t&&(l=e.offset)}const c=re(n,o,l);e.spliceText(c.index,c.remove,c.insert)}(this,t.__key,e,r),this._text=r}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();if(null===n)return;Le(e,this._map,n,t);const o=this._text;n.__text!==o&&n.setTextContent(o)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function de(e,t,n,o){const s=new ue(e,t,n,o);return e._collabNode=s,s}class he{_key;_children;_xmlText;_type;_parent;constructor(e,t,n){this._key="",this._children=[],this._xmlText=e,this._type=n,this._parent=t}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return r(t)?t:null}getNode(){const e=t(this._key);return r(e)?e:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){const e=this._parent;return e instanceof he||ie(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null!==n&&Le(e,this._xmlText,n,t)}applyChildrenYjsDelta(e,t){const n=this._children;let o=0,s=null;for(let i=0;i<t.length;i++){const r=t[i],l=r.insert,c=r.delete;if(null!=r.retain)o+=r.retain;else if("number"==typeof c){let e=c;for(;e>0;){const{node:t,nodeIndex:s,offset:i,length:r}=$e(this,o,!1);if(t instanceof he||t instanceof ae||t instanceof le)n.splice(s,1),e-=1;else{if(!(t instanceof ue))break;{const o=Math.min(e,r),l=0!==s?n[s-1]:null,c=t.getSize();if(0===i&&r===c){n.splice(s,1);const e=Re(t._text,i,o-1,"");e.length>0&&(l instanceof ue?l._text+=e:this._xmlText.delete(i,e.length))}else t._text=Re(t._text,i,o,"");e-=o}}}}else{if(null==l)throw new Error("Unexpected delta format");if("string"==typeof l){const{node:e,offset:t}=$e(this,o,!0);e instanceof ue?e._text=Re(e._text,t,0,l):this._xmlText.delete(t,l.length),o+=l.length}else{const t=l;if(void 0===Ee(t))continue;const{node:i,nodeIndex:r,length:c}=$e(this,o,!1),a=Pe(e,t,this);if(i instanceof ue&&c>0&&c<i._text.length){const e=i._text,t=e.length-c;i._text=Re(e,t,c,""),n.splice(r+1,0,a),s=Re(e,0,t,"")}else n.splice(r,0,a);null!==s&&a instanceof ue&&(a._text=s+a._text,s=null),o+=1}}}}syncChildrenFromYjs(e){const t=this.getNode();if(null===t)return;const n=t.__key,s=l(t,null),i=s.length,r=this._children,f=r.length,u=e.collabNodeMap,d=new Set;let h,g,p=0,y=null;f!==i&&(g=t.getWritable());for(let i=0;i<f;i++){const l=s[p],_=r[i],m=_.getNode(),x=_._key;if(null!==m&&l===x){const t=o(m);if(d.add(l),t)if(_._key=l,_ instanceof he){const t=_._xmlText;_.syncPropertiesFromYjs(e,null),_.applyChildrenYjsDelta(e,t.toDelta()),_.syncChildrenFromYjs(e)}else _ instanceof ue?_.syncPropertiesAndTextFromYjs(e,null):_ instanceof le?_.syncPropertiesFromYjs(e,null):_ instanceof ae||ie(93);y=m,p++}else{if(void 0===h){h=new Set;for(let e=0;e<f;e++){const t=r[e]._key;""!==t&&h.add(t)}}if(null!==m&&void 0!==l&&!h.has(l)){const e=c(l);a(e),i--,p++;continue}g=t.getWritable();const o=je(e,_,n),s=o.__key;if(u.set(s,_),null===y){const e=g.getFirstChild();if(g.__first=s,null!==e){const t=e.getWritable();t.__prev=s,o.__next=t.__key}}else{const e=y.getWritable(),t=y.getNextSibling();if(e.__next=s,o.__prev=y.__key,null!==t){const e=t.getWritable();e.__prev=s,o.__next=e.__key}}i===f-1&&(g.__last=s),g.__size++,y=o}}for(let t=0;t<i;t++){const n=s[t];if(!d.has(n)){const t=c(n),o=e.collabNodeMap.get(n);void 0!==o&&o.destroy(e),a(t)}}this.syncSlotsFromYjs(e,t)}syncSlotsFromYjs(e,t){He(e,this._xmlText,t,this)}syncPropertiesFromLexical(e,t,n){Ie(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,s,i,l,a){const f=this._children[n],u=c(s);f instanceof he&&r(u)?(f.syncPropertiesFromLexical(t,u,i),f.syncChildrenFromLexical(t,u,i,l,a),f.syncSlotsFromLexical(t,u,i,l,a)):f instanceof ue&&o(u)?f.syncPropertiesAndTextFromLexical(t,u,i):f instanceof le&&e(u)&&(f.syncPropertiesFromLexical(t,u,i),f.syncSlotsFromLexical(t,u,i,l,a))}syncSlotsFromLexical(e,t,n,o,s){qe(e,this._xmlText,t,n,o,s,this)}syncChildrenFromLexical(e,t,n,o,s){const i=this.getPrevNode(n),r=null===i?[]:l(i,n),a=l(t,null),f=r.length-1,u=a.length-1,d=e.collabNodeMap;let h,g,p=0,y=0;for(;p<=f&&y<=u;){const t=r[p],i=a[y];if(t===i)this._syncChildFromLexical(e,y,i,n,o,s),p++,y++;else{void 0===h&&(h=new Set(r)),void 0===g&&(g=new Set(a));const n=g.has(t),o=h.has(i);if(n){const t=Ke(e,c(i),this);d.set(i,t),o?(this.splice(e,y,1,t),p++,y++):(this.splice(e,y,0,t),y++)}else this.splice(e,y,1),p++}}const _=p>f,m=y>u;if(_&&!m)for(;y<=u;++y){const t=a[y],n=Ke(e,c(t),this);this.append(n),d.set(t,n)}else if(m&&!_)for(let t=this._children.length-1;t>=y;t--)this.splice(e,t,1)}append(e){const t=this._xmlText,n=this._children,o=n[n.length-1],s=void 0!==o?o.getOffset()+o.getSize():0;if(e instanceof he)t.insertEmbed(s,e._xmlText);else if(e instanceof ue){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof ae?t.insertEmbed(s,e._map):e instanceof le&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,o){const s=this._children,i=s[t];if(void 0===i)return void(void 0!==o&&this.append(o));const r=i.getOffset();-1===r&&ie(95);const l=this._xmlText;if(0!==n){const o=s.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e);l.delete(r,i.getSize())}if(o instanceof he)l.insertEmbed(r,o._xmlText);else if(o instanceof ue){const e=o._map;null===e.parent&&l.insertEmbed(r,e),l.insert(r+1,o._text)}else o instanceof ae?l.insertEmbed(r,o._map):o instanceof le&&l.insertEmbed(r,o._xmlElem);void 0!==o?s.splice(t,n,o):s.splice(t,n)}getChildOffset(e){let t=0;const n=this._children;for(let o=0;o<n.length;o++){const s=n[o];if(s===e)return t;t+=s.getSize()}return-1}destroy(e){const t=e.collabNodeMap,n=this._children;for(let t=0;t<n.length;t++)n[t].destroy(e);Je(e,this._xmlText),t.get(this._key)===this&&t.delete(this._key)}}function ge(e,t,n){const o=new he(e,t,n);return e._collabNode=o,o}class pe{_nodeMap=new Map;_sharedTypeToNodeKeys=new Map;_nodeKeyToSharedType=new Map;set(e,t){const n=t instanceof Array;this.delete(e);const s=n?t:[t];for(const e of s){const t=e.getKey();if(this._nodeKeyToSharedType.has(t)){const e=this._nodeKeyToSharedType.get(t),n=this._sharedTypeToNodeKeys.get(e).indexOf(t);-1!==n&&this._sharedTypeToNodeKeys.get(e).splice(n,1),this._nodeKeyToSharedType.delete(t),this._nodeMap.delete(t)}}if(e instanceof P){if(n||ie(331),0===t.length)return;this._sharedTypeToNodeKeys.set(e,t.map(e=>e.getKey()));for(const n of t)this._nodeMap.set(n.getKey(),n),this._nodeKeyToSharedType.set(n.getKey(),e)}else n&&ie(332),o(t)&&ie(333),this._sharedTypeToNodeKeys.set(e,[t.getKey()]),this._nodeMap.set(t.getKey(),t),this._nodeKeyToSharedType.set(t.getKey(),e)}get(e){const t=this._sharedTypeToNodeKeys.get(e);if(void 0!==t){if(e instanceof P){const e=Array.from(t.map(e=>this._nodeMap.get(e)));return e.length>0?e:void 0}return this._nodeMap.get(t[0])}}getSharedType(e){return this._nodeKeyToSharedType.get(e.getKey())}delete(e){const t=this._sharedTypeToNodeKeys.get(e);if(void 0!==t){for(const e of t)this._nodeMap.delete(e),this._nodeKeyToSharedType.delete(e);this._sharedTypeToNodeKeys.delete(e)}}deleteNode(e){const t=this._nodeKeyToSharedType.get(e);t&&this.delete(t),this._nodeMap.delete(e)}has(e){return this._sharedTypeToNodeKeys.has(e)}clear(){this._nodeMap.clear(),this._sharedTypeToNodeKeys.clear(),this._nodeKeyToSharedType.clear()}}function ye(e,t,n,o,s){null==n&&ie(81);const i={clientID:n.clientID,cursorHighlightSheet:null,cursors:new Map,cursorsContainer:null,doc:n,docMap:o,editor:e,excludedProperties:s||new Map,id:t,nodeProperties:new Map};return function(e){const{editor:t,nodeProperties:n}=e;t.update(()=>{t._nodes.forEach(t=>{const o=new t.klass,s={};for(const[t,n]of Object.entries(o))Fe(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(i),i}function _e(e,t,n,o,s,i){null==o&&ie(81);const r=ge(o.get("root",P),null,"root");return r._key="root",{...ye(e,n,o,s,i),collabNodeMap:new Map,root:r}}function me(e,t,n,o,s={}){null==n&&ie(81);const{excludedProperties:i,rootName:r="root-v2"}=s;return{...ye(e,t,n,o,i),mapping:new pe,root:n.get(r,j)}}function xe(e){return Object.prototype.hasOwnProperty.call(e,"collabNodeMap")}const Se="__slots",be=new Set(["__key","__parent","__next","__prev","__state","__slotHost","__slots"]),Te=new Set(["__first","__last","__size"]),Ne=new Set(["__cachedText"]),ke=new Set(["__text"]);function ve(e,t){e.setAttribute(Se,t)}function we(e){return"__proto__"===e||"constructor"===e||"prototype"===e}function Ce(t){return(r(t)||e(t))&&!t.isInline()}function Fe(e,t,n){if(be.has(e)||"function"==typeof t[e])return!0;if(o(t)){if(ke.has(e))return!0}else if(r(t)&&(Te.has(e)||y(t)&&Ne.has(e)))return!0;const s=t.constructor,i=n.excludedProperties.get(s);return null!=i&&i.has(e)}function Ae(e,t){const n=e.__type,{nodeProperties:o}=t,s=o.get(n);return void 0===s&&ie(330,n),s}function Me(t,n,s,i,l,c){n instanceof he&&r(s)?(n.syncPropertiesFromLexical(t,s,i),n.syncChildrenFromLexical(t,s,i,l,c),n.syncSlotsFromLexical(t,s,i,l,c)):n instanceof ue&&o(s)?n.syncPropertiesAndTextFromLexical(t,s,i):n instanceof le&&e(s)&&(n.syncPropertiesFromLexical(t,s,i),n.syncSlotsFromLexical(t,s,i,l,c))}function Oe(e,t,n,o){const s=d(t),i=m(t.constructor).length>0;if(0===s.length&&!i)return;const r=new L;let l=!1;for(const o of s){const s=h(t,o);if(null===s)continue;const i=Ke(e,s,n);e.collabNodeMap.set(s.__key,i),r.set(o,i.getSharedType()),l=!0}(l||i)&&ve(o,r)}function Ke(t,s,i){const l=s.__type;let c;if(r(s)){const e=new P;c=ge(e,i,l),c.syncPropertiesFromLexical(t,s,null),c.syncChildrenFromLexical(t,s,null,null,null),Oe(t,s,c,e)}else if(o(s)){i instanceof he||ie(389);c=de(new L,s.__text,i,l),c.syncPropertiesAndTextFromLexical(t,s,null)}else if(n(s)){i instanceof he||ie(390);const e=new L;e.set("__type","linebreak"),c=fe(e,i)}else if(e(s)){const e=new j;c=ce(e,i,l),c.syncPropertiesFromLexical(t,s,null),Oe(t,s,c,e)}else ie(86);return c._key=s.__key,c}function Ee(e){const t=ze(e,"__type");return"string"!=typeof t&&void 0!==t&&ie(87),t}function Pe(e,t,n){const o=t._collabNode;if(void 0===o){const o=e.editor._nodes,s=Ee(t);"string"!=typeof s&&ie(87);void 0===o.get(s)&&ie(88,s);const i=t.parent,r=void 0===n&&null!==i?Pe(e,i):n||null;if(r instanceof he||r instanceof le&&function(e,t){const n=e._xmlElem.getAttribute(Se);if(!(n instanceof L))return!1;for(const e of n.values())if(e===t)return!0;return!1}(r,t)||ie(391),t instanceof P)return ge(t,r,s);if(t instanceof L)return r instanceof he||ie(392),"linebreak"===s?fe(t,r):de(t,"",r,s);if(t instanceof j)return ce(t,r,s)}return o}function je(t,n,o){const s=n.getType(),i=t.editor._nodes.get(s);void 0===i&&ie(88,s);const r=new i.klass;if(r.__parent=o,n._key=r.__key,n instanceof he){const e=n._xmlText;n.syncPropertiesFromYjs(t,null),n.applyChildrenYjsDelta(t,e.toDelta()),n.syncChildrenFromYjs(t)}else n instanceof ue?n.syncPropertiesAndTextFromYjs(t,null):n instanceof le&&(n.syncPropertiesFromYjs(t,null),e(r)||ie(393),n.syncSlotsFromYjs(t,r));return t.collabNodeMap.set(r.__key,n),r}function Le(e,t,n,o){const s=null===o?t instanceof L?Array.from(t.keys()):t instanceof P||t instanceof j?Object.keys(t.getAttributes()):Object.keys(t):Array.from(o);let i;for(let o=0;o<s.length;o++){const r=s[o];if(Fe(r,n,e)){"__state"===r&&xe(e)&&(i||(i=n.getWritable()),De(t,i));continue}const l=n[r];let c=ze(t,r);if(l!==c){if(c instanceof z){const t=e.docMap;l instanceof z&&t.delete(l.guid);const n=c.guid;if(t.set(n,c),f(l))l._key=n,c=l;else{const e=u();e._key=n,c=e}}void 0===i&&(i=n.getWritable()),i[r]=c}}}function ze(e,t){return e instanceof L?e.get(t):e instanceof P||e instanceof j?e.getAttribute(t):e[t]}function Ye(e,t,n){e instanceof L?e.set(t,n):e.setAttribute(t,n)}function De(e,t){const n=ze(e,"__state");n instanceof L&&_(t).updateFromJSON(n.toJSON())}function Ie(e,t,n,o){const s=Object.keys(Ae(o,e)),i=e.editor.constructor;!function(e,t,n,o){const s=o.__state,i=null===t.doc?void 0:ze(t,"__state");if(!s)return;const[r,l]=s.getInternalState(),c=n&&n.__state,a=i instanceof L?i:new L;if(c===s)return;const[f,u]=c&&a.doc?c.getInternalState():[void 0,new Map];if(r)for(const[e,t]of Object.entries(r))f&&t!==f[e]&&a.set(e,t);for(const[e,t]of l)u.get(e)!==t&&a.set(e.key,e.unparse(t));i||Ye(t,"__state",a)}(0,t,n,o);for(let r=0;r<s.length;r++){const l=s[r],c=null===n?void 0:n[l];let a=o[l];if(c!==a){if(a instanceof i){const t=e.docMap;let n;if(c instanceof i){const e=c._key;n=t.get(e),t.delete(e)}const s=n||new z,r=s.guid;a._key=r,t.set(r,s),a=s,e.editor.update(()=>{o.markDirty()})}Ye(t,l,a)}}}function Re(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function $e(e,t,n){let o=0,s=0;const i=e._children,r=i.length;for(;s<r;s++){const e=i[s],l=o;o+=e.getSize();if((n?o>=t:o>t)&&e instanceof ue){let n=t-l-1;n<0&&(n=0);return{length:o-t,node:e,nodeIndex:s,offset:n}}if(o>t)return{length:0,node:e,nodeIndex:s,offset:l};if(s===r-1)return{length:0,node:null,nodeIndex:s+1,offset:l+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function We(e){const t=e.anchor,n=e.focus;let s=!1;try{const e=t.getNode(),i=n.getNode();(!e.isAttached()||!i.isAttached()||o(e)&&t.offset>e.getTextContentSize()||o(i)&&n.offset>i.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function Be(e,t){e.doc.transact(t,e)}function Ue(e,n){const o=n._nodeMap.get(e);if(!o)return void x().selectStart();const s=o.__prev;let i=null;s&&(i=t(s)),null===i&&null!==o.__parent&&(i=t(o.__parent)),null!==i?null!==i&&i.isAttached()?i.selectEnd():Ue(i.__key,n):x().selectStart()}function He(n,o,s,i){const l=o.getAttribute(Se),c=l instanceof L?new Set(l.keys()):new Set;for(const e of d(s))if(!c.has(e)){const t=h(s,e);if(null!==t){const e=n.collabNodeMap.get(t.__key);void 0!==e&&e.destroy(n)}g(s,e)}if(l instanceof L)for(const[o,c]of l.entries()){if(we(o))continue;if(!(c instanceof P||c instanceof j||c instanceof L))continue;const l=h(s,o),a=null===l?void 0:n.collabNodeMap.get(l.__key);if(void 0!==a&&a.getSharedType()===c)continue;if(void 0===c._collabNode&&"string"!=typeof ze(c,"__type"))continue;if(c instanceof L&&i instanceof le)continue;const f=c._collabNode;if(void 0!==f){const n=t(f._key);if(null!==n&&(n.isAttached()||(r(n)||e(n))&&null!==n.getLatest().__slotHost))continue}const u=Pe(n,c,i),d=je(n,u,null);Ce(d)?(void 0!==a&&a.destroy(n),p(s,o,d)):n.collabNodeMap.get(d.__key)===u&&n.collabNodeMap.delete(d.__key)}}function qe(e,t,n,o,s,i,r){const l=d(n),c=t.getAttribute(Se);if(0===l.length&&!(c instanceof L))return;let a;c instanceof L?a=c:(a=new L,ve(t,a));const f=new Set(l);for(const t of Array.from(a.keys()))if(!f.has(t)){const n=a.get(t),o=null==n?void 0:n._collabNode;void 0!==o&&o.destroy(e),a.delete(t)}const u=e.collabNodeMap;for(const t of l){const l=h(n,t);if(null===l)continue;const c=u.get(l.__key);if(void 0!==c&&a.get(t)===c.getSharedType())Me(e,c,l,o,s,i);else{const n=a.get(t),o=null==n?void 0:n._collabNode;void 0!==o&&o.destroy(e);const s=Ke(e,l,r);u.set(l.__key,s),a.set(t,s.getSharedType())}}}function Je(e,t){const n=t.getAttribute(Se);if(n instanceof L)for(const t of n.keys()){const o=n.get(t),s=null==o?void 0:o._collabNode;void 0!==s&&s.destroy(e)}}const Ve=e=>"UNDEFINED"===e.nodeName,Ge=(t,n,o,s,i,r,l)=>{let c=n.mapping.get(t);if(c&&o&&0===o.size&&!s)return c;const a=Ve(t)?S.getType():t.nodeName,f=n.editor._nodes.get(a);if(void 0===f)throw new Error(`$createOrUpdateNodeFromYElement: Node ${a} is not registered`);if(c||(c=new f.klass,o=null,s=!0),s&&c instanceof b){const e=[],o=t=>{if(t instanceof j){const o=Ge(t,n,new Set,!1,i,r,l);null!==o&&e.push(o)}else if(t instanceof P){const o=Ze(t,n,i,r,l);null!==o&&o.forEach(t=>{null!==t&&e.push(t)})}else ie(329)};void 0===i||void 0===r?t.toArray().forEach(o):Y(t,new D(r.ds,i.sv)).filter(e=>!e._item.deleted||Xe(e._item,i)||Xe(e._item,r)).forEach(o),Qe(c,e)}const u=t.getAttributes(i);Ve(t)||void 0===i||(Xe(t._item,i)?Xe(t._item,r)||(u[yt("ychange")]=l?l("added",t._item.id):{type:"added"}):u[yt("ychange")]=l?l("removed",t._item.id):{type:"removed"});const y={...Ae(c,n)},m={};for(const e in u)e.startsWith(pt)?m[_t(e)]=u[e]:e!==Se&&"__proto__"!==e&&"constructor"!==e&&"prototype"!==e&&(y[e]=u[e]);if(Le(n,y,c,o),o){if(o.size>0){const e=_(c);for(const t of o)if(t.startsWith(pt)){const n=_t(t);e.updateFromUnknown(n,m[n])}}}else _(c).updateFromJSON(m);if(c instanceof b||e(c)){const e=u[Se],t=new Set;if(e instanceof L){const o=void 0===i?Array.from(e.entries()):Object.entries(I(e,i));for(const[e,s]of o){if(t.add(e),we(e))continue;let o=null;if(s instanceof j&&(o=Ge(s,n,new Set,!1,i,r,l)),null===o)continue;const a=h(c,e);null!==a&&a.getKey()===o.getKey()||(Ce(o)?null===o.getLatest().__slotHost&&p(c,e,o):o.isAttached()||tt(s,n))}}for(const e of d(c))t.has(e)||g(c,e)}const x=c.getLatest();return n.mapping.set(t,x),x},Qe=(e,t)=>{const n=e.getChildren(),o=new Set(n.map(e=>e.getKey())),s=new Set(t.map(e=>e.getKey())),i=n.length-1,r=t.length-1;let l=0,c=0;for(;l<=i&&c<=r;){const i=n[l].getKey(),r=t[c].getKey();if(i===r){l++,c++;continue}const a=s.has(i),f=o.has(r);if(!a){if(0===c&&1===e.getChildrenSize())return void e.splice(c,1,t.slice(c));e.splice(c,1,[]),l++;continue}const u=t[c];f?(e.splice(c,1,[u]),l++,c++):(e.splice(c,0,[u]),c++)}const a=l>i,f=c>r;a&&!f?e.append(...t.slice(c)):f&&!a&&e.splice(t.length,e.getChildrenSize()-t.length,[])},Xe=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!R(t.ds,e.id),Ze=(e,t,n,s,i)=>{const r=ht(e,n,s,i);let l=t.mapping.get(e)??[];const c=r.map(e=>e.attributes.t??T.getType());if(!(l.length===c.length&&l.every((e,t)=>e.getType()===c[t]))){const e=t.editor._nodes;l=c.map(t=>{const n=e.get(t);if(void 0===n)throw new Error(`$createTextNodesFromYText: Node ${t} is not registered`);const s=new n.klass;if(!o(s))throw new Error(`$createTextNodesFromYText: Node ${t} is not a TextNode`);return s})}for(let e=0;e<r.length;e++){const n=l[e],o=r[e],{attributes:s,insert:i}=o;n.__text!==i&&n.setTextContent(i);const c={...Ae(n,t),...s.p},a=Object.fromEntries(Object.entries(s).filter(([e])=>e.startsWith(pt)).map(([e,t])=>[_t(e),t]));Le(t,c,n,null),_(n).updateFromJSON(a)}const a=l.map(e=>e.getLatest());return t.mapping.set(e,a),a},et=(e,t)=>{const n=d(e);if(0===n.length&&0===m(e.constructor).length)return;const o=new L;for(const s of n){const n=h(e,s);null!=n&&o.set(s,ot(n,t))}return o},tt=(e,t)=>{if((e instanceof j||e instanceof P)&&t.mapping.delete(e),e instanceof j){const n=e.getAttribute(Se);if(n instanceof L)for(const e of n.values())tt(e,t);for(const n of e.toArray())tt(n,t)}},nt=(e,t)=>{const n=new j(e.getType()),o={...gt(e,t),...mt(e)};for(const e in o){const t=o[e];null!==t&&n.setAttribute(e,t)}if(!(e instanceof b)){const o=et(e,t);return void 0!==o&&(ve(n,o),t.mapping.set(n,e)),n}const s=et(e,t);return void 0!==s&&ve(n,s),n.insert(0,lt(e).map(e=>st(e,t))),t.mapping.set(n,e),n},ot=(t,n)=>{const o=nt(t,n);return e(t)&&void 0===n.mapping.getSharedType(t)&&n.mapping.set(o,t),o},st=(e,t)=>e instanceof Array?((e,t)=>{const n=new P;return dt(n,e,t),n})(e,t):nt(e,t),it=e=>"object"==typeof e&&null!=e,rt=(e,t)=>{const n=Object.keys(e).filter(t=>null!==e[t]);if(null==t)return 0===n.length;let o=n.length===Object.keys(t).filter(e=>null!==t[e]).length;for(let s=0;s<n.length&&o;s++){const i=n[s],r=e[i],l=t[i];o="ychange"===i||r===l||it(r)&&it(l)&&rt(r,l)}return o},lt=e=>{if(!(e instanceof b))return[];const t=e.getChildren(),n=[];for(let e=0;e<t.length;e++){const s=t[e];if(o(s)){const s=[];for(let n=t[e];e<t.length&&o(n);n=t[++e])s.push(n);e--,n.push(s)}else n.push(s)}return n},ct=(e,t,n)=>{const o=ht(e);return o.length===t.length&&o.every((e,o)=>{const s=t[o],i=e.attributes.t??T.getType(),r=e.attributes.p??{},l=Object.fromEntries(Object.entries(e.attributes).filter(([e])=>e.startsWith(pt)));return e.insert===s.getTextContent()&&i===s.getType()&&rt(r,gt(s,n))&&rt(l,mt(s))})},at=(e,t,n)=>{if(e instanceof j&&!(t instanceof Array)&&St(e,t)){const o=lt(t),s=e.getAttributes();return delete s[Se],e._length===o.length&&rt(s,{...gt(t,n),...mt(t)})&&((e,t,n)=>{const o=d(t),s=e.getAttribute(Se);if(!(s instanceof L))return 0===o.length;if(s.size!==o.length)return!1;for(const e of o){const o=h(t,e),i=s.get(e);if(null===o||!(i instanceof j)||n.mapping.get(i)!==o)return!1}return!0})(e,t,n)&&e.toArray().every((e,t)=>at(e,o[t],n))}return e instanceof P&&t instanceof Array&&ct(e,t,n)},ft=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),ut=(e,t,n)=>{const o=e.toArray(),s=lt(t),i=s.length,r=o.length,l=Math.min(r,i);let c=0,a=0,f=!1;for(;c<l;c++){const e=o[c],t=s[c];if(e instanceof $)break;if(ft(n.mapping.get(e),t))f=!0;else if(!at(e,t,n))break}for(;c+a<l;a++){const e=o[r-a-1],t=s[i-a-1];if(e instanceof $)break;if(ft(n.mapping.get(e),t))f=!0;else if(!at(e,t,n))break}return{equalityFactor:c+a,foundMappedChild:f}},dt=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:o,str:r}=(e=>{let t="",n=e._start;const o={};for(;null!==n;)n.deleted||(n.countable&&n.content instanceof W?t+=n.content.str:n.content instanceof B&&(o[n.content.key]=null)),n=n.right;return{nAttrs:o,str:t}})(e),l=t.map((e,t)=>{const s=e.getType();let i=gt(e,n);return 0===Object.keys(i).length&&(i=null),{attributes:Object.assign({},o,{...s!==T.getType()&&{t:s},p:i,...mt(e),...t>0&&{i:t}}),insert:e.getTextContent(),nodeKey:e.getKey()}}),c=l.map(e=>e.insert).join(""),a=s();let f;if(i(a)&&a.isCollapsed()){f=0;for(const e of l){if(e.nodeKey===a.anchor.key){f+=a.anchor.offset;break}f+=e.insert.length}}else f=c.length;const{insert:u,remove:d,index:h}=re(r,c,f);e.delete(h,d),e.insert(h,u),e.applyDelta(l.map(e=>({attributes:e.attributes,retain:e.insert.length})))},ht=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>{const t=e.attributes??{};return"ychange"in t&&(t[yt("ychange")]=t.ychange,delete t.ychange),{...e,attributes:t}}),gt=(e,t)=>{const n=Ae(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},pt="s_",yt=e=>`s_${e}`,_t=e=>{if(!e.startsWith(pt))throw new Error(`Invalid state key: ${e}`);return e.slice(pt.length)},mt=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[yt(e)]=t;for(const[e,t]of o)s[yt(e.key)]=e.unparse(t);return s},xt=(t,n,o,s,i)=>{if(n instanceof j&&n.nodeName!==o.getType()&&(!Ve(n)||o.getType()!==S.getType()))throw new Error("node name mismatch!");if(s.mapping.set(n,o),n instanceof j){const r=n.getAttributes(),l={...gt(o,s),...mt(o)};for(const e in l)if(null!=l[e]){r[e]===l[e]||it(r[e])&&it(l[e])&&rt(r[e],l[e])||"ychange"===e||n.setAttribute(e,l[e])}else n.removeAttribute(e);for(const e in r)e!==Se&&void 0===l[e]&&n.removeAttribute(e);(o instanceof b||e(o))&&((t,n,o,s,i)=>{const r=d(n),l=t.getAttribute(Se);if(0===r.length&&!(l instanceof L)&&0===m(n.constructor).length)return;let c;l instanceof L?c=l:(c=new L,ve(t,c));const a=new Set(r);for(const e of Array.from(c.keys()))if(!a.has(e)){const t=c.get(e);void 0!==t&&tt(t,o),c.delete(e)}for(const t of r){const r=h(n,t);if(null==r)continue;const l=c.get(t);l instanceof j&&(r instanceof b||e(r))&&l===o.mapping.getSharedType(r)?s.has(r.getKey())&&xt(i,l,r,o,s):(l instanceof j&&tt(l,o),c.set(t,ot(r,o)))}})(n,o,s,i,t)}const r=lt(o),l=r.length,c=n.toArray(),a=c.length,f=Math.min(l,a);let u=0,g=0;for(;u<f;u++){const n=c[u],o=r[u];if(n instanceof $)break;if(ft(s.mapping.get(n),o))o instanceof Array||!(o instanceof b||e(o))||!i.has(o.getKey())||xt(t,n,o,s,i);else{if(!at(n,o,s))break;s.mapping.set(n,o)}}for(;g+u<f;g++){const n=c[a-g-1],o=r[l-g-1];if(n instanceof $)break;if(ft(s.mapping.get(n),o))o instanceof Array||!(o instanceof b||e(o))||!i.has(o.getKey())||xt(t,n,o,s,i);else{if(!at(n,o,s))break;s.mapping.set(n,o)}}for(;a-u-g>0&&l-u-g>0;){const e=c[u],o=r[u],f=c[a-g-1],d=r[l-g-1];if(e instanceof P&&o instanceof Array)ct(e,o,s)||dt(e,o,s),u+=1;else{let r=e instanceof j&&St(e,o),l=f instanceof j&&St(f,d);if(r&&l){const t=ut(e,o,s),n=ut(f,d,s);t.foundMappedChild&&!n.foundMappedChild?l=!1:!t.foundMappedChild&&n.foundMappedChild||t.equalityFactor<n.equalityFactor?r=!1:l=!1}r?(xt(t,e,o,s,i),u+=1):l?(xt(t,f,d,s,i),g+=1):(s.mapping.delete(n.get(u)),n.delete(u,1),n.insert(u,[st(o,s)]),u+=1)}}const p=a-u-g;if(1===a&&0===l&&c[0]instanceof P?(s.mapping.delete(c[0]),c[0].delete(0,c[0].length)):p>0&&(n.slice(u,u+p).forEach(e=>s.mapping.delete(e)),n.delete(u,p)),u+g<l){const e=[];for(let t=u;t<l-g;t++)e.push(st(r[t],s));n.insert(u,e)}},St=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType(),bt=/* @__PURE__ */k("ychange",{isEqual:(e,t)=>e===t,parse:e=>e??null});function Tt(e){return N(e,bt)}const Nt=(e,t=J(e.doc),n=U)=>{const{doc:o}=e;o.gc&&ie(325),o.transact(s=>{const i=new H(o);i&&i.dss.forEach(e=>{q(s,e,e=>{})});const r=(e,t)=>({id:t,type:e,user:("added"===e?i.getUserByClientId(t.client):i.getUserByDeletedId(t))??null});e.mapping.clear(),e.editor.update(()=>{x().clear(),Ge(e.root,e,null,!0,t,n,r)})},e)},kt="undefined"!=typeof Highlight&&"undefined"!=typeof CSS&&"highlights"in CSS;function vt(e,t,n){if(!CSS.supports("color",n))return;const o=function(e){const t=e.editor.getRootElement(),n=v(t);let o=e.cursorHighlightSheet;null===o&&(o=new(n.defaultView||window).CSSStyleSheet,e.cursorHighlightSheet=o);const s=null!==t?t.getRootNode():null,i=C(s)?s:n;return i.adoptedStyleSheets.includes(o)||(i.adoptedStyleSheets=[...i.adoptedStyleSheets,o]),o}(e),s=o.insertRule(`::highlight(${t}) { }`,o.cssRules.length),i=o.cssRules[s];i.style.setProperty("background-color",`color-mix(in srgb, ${n} 30%, transparent)`),i.style.setProperty("color","inherit")}function wt(e,t){const n=e.cursorHighlightSheet;if(null===n)return;const o=`::highlight(${t})`;for(let e=n.cssRules.length-1;e>=0;e--){const t=n.cssRules[e];if(null!=t&&t.selectorText===o)return void n.deleteRule(e)}}function Ct(e,t,n=0){const s=t.collabNodeMap.get(e.key);if(void 0===s)return null;let i=e.offset,l=s.getSharedType();if(s instanceof ue){l=s._parent._xmlText;const e=s.getOffset();if(-1===e)return null;i=e+1+i}else if(s instanceof he&&"element"===e.type){const t=e.getNode();r(t)||ie(184);let n=0,s=0,l=t.getFirstChild();for(;null!==l&&s++<i;)o(l)?n+=l.getTextContentSize()+1:n++,l=l.getNextSibling();i=n}return G(l,i,n)}function Ft(e,t,n=0){const{mapping:s}=t,{offset:i}=e,l=e.getNode(),c=s.getSharedType(l);if(void 0===c)return null;if("text"===e.type){o(l)||ie(326);let e=l.getPreviousSibling(),t=i;for(;o(e);)t+=e.getTextContentSize(),e=e.getPreviousSibling();return G(c,t,n)}if("element"===e.type){r(l)||ie(184);let e=0,t=l.getFirstChild();for(;null!==t&&e<i;){if(o(t)){let e=t.getNextSibling();for(;o(e);)e=e.getNextSibling()}e++,t=t.getNextSibling()}return G(c,e,n)}return null}function At(e,t){return V(e,t.doc)}function Mt(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!Q(e,t))return!0;return!1}function Ot(e,t){return{color:t,name:e,selection:null}}function Kt(e,t){null!==t.highlight&&(CSS.highlights.delete(t.highlightName),wt(e,t.highlightName));const n=e.cursorsContainer;if(null===n)return;t.caret.parentNode===n&&n.removeChild(t.caret);const o=t.selections;for(let e=0;e<o.length;e++)o[e].parentNode===n&&n.removeChild(o[e])}function Et(e,t){const n=t.selection;null!==n&&Kt(e,n)}function Pt(e,t,n,o,s,i,r,l,c={}){const a=e.color,f=v(t.editor.getRootElement()),u=f.createElement("span");c.cursor?(u.className=c.cursor,w(u.style,{"--lexical-cursor-color":a,bottom:"0",position:"absolute",right:"-1px",top:"0"})):w(u.style,{"background-color":a,bottom:"0",position:"absolute",right:"-1px",top:"0",width:"1px","z-index":"10"});const d=f.createElement("span");d.textContent=e.name,c.cursorName?d.className=c.cursorName:w(d.style,{"background-color":a,color:"#fff","font-family":"Arial","font-size":"12px","font-weight":"bold",left:"-2px","line-height":"12px",padding:"2px",position:"absolute",top:"-16px","white-space":"nowrap"}),u.appendChild(d);const h=`lexical-cursor-${t.id}-${n}`;let g=null;return l&&kt&&(g=new Highlight,CSS.highlights.set(h,g),vt(t,h,a)),{anchor:{key:o,offset:s},caret:u,color:a,focus:{key:i,offset:r},highlight:g,highlightName:h,name:d,selections:[]}}function jt(e,t,o,s,i={}){const r=e.editor,l=r.getRootElement(),c=e.cursorsContainer;if(null===c||null===l)return;const a=v(l),f=c.offsetParent;if(null===f)return;const u=f.getBoundingClientRect(),d=t.selection;if(null===o)return null===d?void 0:(t.selection=null,void Kt(e,d));t.selection=o;const h=o.caret,g=o.color,p=o.highlight,y=o.anchor,_=o.focus,m=y.key,x=_.key,S=s.get(m),b=s.get(x);if(null==S||null==b)return;if(null!==p){const e=oe(r,S,y.offset,b,_.offset);if(null===e)return;p.clear(),e.collapsed||p.add(e);const t=e.cloneRange();t.collapse(!1);let o=t.getBoundingClientRect();if(0===o.height&&n(b)){const e=r.getElementByKey(x);null!==e&&(o=e.getBoundingClientRect())}return w(h.style,{"background-color":i.cursor?"":g,bottom:"",height:`${o.height||16}px`,left:o.left-u.left+"px","pointer-events":"none",position:"absolute",right:"",top:o.top-u.top+"px",width:"1px","z-index":"10"}),void(h.parentNode!==c&&c.appendChild(h))}const T=o.selections;let N;if(S===b&&n(S)){N=[r.getElementByKey(m).getBoundingClientRect()]}else{const e=oe(r,S,y.offset,b,_.offset);if(null===e)return;N=se(r,e)}const k=T.length,C=N.length;for(let e=0;e<C;e++){const t=N[e];let n=T[e];if(void 0===n){n=a.createElement("span"),T[e]=n;const t=a.createElement("span");i.selectionBg&&(t.className=i.selectionBg),n.appendChild(t),c.appendChild(n)}const o=t.top-u.top,s=t.left-u.left,r={height:`${t.height}px`,left:`${s}px`,"pointer-events":"none",position:"absolute",top:`${o}px`,width:`${t.width}px`};i.selection?(n.className=i.selection,w(n.style,{...r,"--lexical-cursor-color":g}),w(n.firstChild.style,{height:"100%",left:"0",position:"absolute",top:"0",width:"100%"})):(w(n.style,r),w(n.firstChild.style,{...r,"background-color":g,left:"0",opacity:"0.3",top:"0","z-index":"5"})),e===C-1&&h.parentNode!==n&&n.appendChild(h)}for(let e=k-1;e>=C;e--){const t=T[e];c.removeChild(t),T.pop()}}function Lt(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,i=0,r=null,l=0;if(null!==n&&null!==o){const t=At(n,e),c=At(o,e);null!==t&&null!==c&&([s,i]=It(t.type,t.index),[r,l]=It(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:i,focusCollabNode:r,focusOffset:l}}function zt(e,t){const{anchorPos:n,focusPos:s}=t,i=n?At(n,e):null,r=s?At(s,e):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(xe(e)){const[e,t]=It(i.type,i.index),[n,o]=It(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=Rt(e.mapping,i),[a,f]=Rt(e.mapping,r);if(a&&l&&(a!==l||f!==c)){const e=a.isBefore(l),t=e?a:l,n=e?f:c;o(t)&&o(t.getNextSibling())&&n===t.getTextContentSize()&&(e?(a=t.getNextSibling(),f=0):(l=t.getNextSibling(),c=0))}return{anchorKey:null!==l?l.getKey():null,anchorOffset:c,focusKey:null!==a?a.getKey():null,focusOffset:f}}function Yt(e,t){const n=t.awareness.getLocalState();if(null===n)return;const{anchorKey:o,anchorOffset:r,focusKey:l,focusOffset:c}=zt(e,n);if(null!==o&&null!==l){const e=s();if(!i(e))return;Dt(e.anchor,o,r),Dt(e.focus,l,c)}}function Dt(e,n,s){if(e.key!==n||e.offset!==s){let i=t(n);if(null!==i&&!r(i)&&!o(i)){const e=i.getParentOrThrow();n=e.getKey(),s=i.getIndexWithinParent(),i=e}e.set(n,s,r(i)?"element":"text")}}function It(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof he){const{node:e,offset:o}=$e(n,t,!0);return null===e?[n,n._children.length]:[e,o]}return[null,0]}function Rt(e,t){const n=t.type,s=t.index;if(n instanceof j){const t=e.get(n);if(void 0===t)return[null,0];if(!r(t))return[t,s];let i=s,l=0;const c=t.getChildren();for(;i>0&&l<c.length;){const e=c[l];if(i-=1,l+=1,o(e))for(;l<c.length&&o(c[l]);)l+=1}return[t,l]}{const t=e.get(n);if(void 0===t)return[null,0];let o=0,i=s;for(;i>t[o].getTextContentSize()&&o+1<t.length;)i-=t[o].getTextContentSize(),o++;const r=t[o];return[r,Math.min(i,r.getTextContentSize())]}}function $t(e,t){return t.awareness.getStates()}function Wt(e,t,n){const{getAwarenessStates:o=$t,selectionHighlight:s=!1}=n??{},i=Array.from(o(e,t)),r=e.clientID,l=e.cursors,c=e.editor,a=c._config.theme.collaboration,f=c._editorState._nodeMap,u=new Set;for(let t=0;t<i.length;t++){const n=i[t],[o,d]=n;if(0!==o&&o!==r){u.add(o);const{name:t,color:n,focusing:i}=d;let r=null,h=l.get(o);if(void 0===h&&(h=Ot(t,n),l.set(o,h)),i){const{anchorKey:t,anchorOffset:n,focusKey:i,focusOffset:l}=c.read(()=>zt(e,d));if(null!==t&&null!==i)if(r=h.selection,null===r)r=Pt(h,e,o,t,n,i,l,s,a);else{const e=r.anchor,o=r.focus;e.key=t,e.offset=n,o.key=i,o.offset=l}}jt(e,h,r,f,a)}}const d=Array.from(l.keys());for(let t=0;t<d.length;t++){const n=d[t];if(!u.has(n)){const t=l.get(n);void 0!==t&&(Et(e,t),l.delete(n))}}}function Bt(e,t,n,o){const s=t.awareness,r=s.getLocalState();if(null===r)return;const{anchorPos:l,focusPos:c,name:a,color:f,focusing:u,awarenessData:d}=r;let h=null,g=null;if(null!==o&&(null===l||o.is(n))||null!==n){if(i(o)){const t=o.isCollapsed(),n=!t&&o.isBackward(),s=n?-1:0,i=t||n?0:-1;xe(e)?(h=Ct(o.anchor,e,s),g=Ct(o.focus,e,i)):(h=Ft(o.anchor,e,s),g=Ft(o.focus,e,i))}(Mt(l,h)||Mt(c,g))&&s.setLocalState({...r,anchorPos:h,awarenessData:d,color:f,focusPos:g,focusing:u,name:a})}}function Ut(e,t){if(t instanceof Z&&function(e,t){const{target:n}=t;if(!n._item||"__state"!==n._item.parentSub||void 0!==Ee(n)||!(n.parent instanceof P||n.parent instanceof j||n.parent instanceof L))return!1;const o=Pe(e,n.parent).getNode();if(o){const e=_(o.getWritable());for(const o of t.keysChanged)e.updateFromUnknown(o,n.get(o))}return!0}(e,t))return;const{target:n}=t;if(t instanceof Z&&n instanceof L&&null!=n._item&&n._item.parentSub===Se&&(n.parent instanceof P||n.parent instanceof j)){const t=Pe(e,n.parent);if(t instanceof he){const n=t.getNode();null!==n&&t.syncSlotsFromYjs(e,n)}else if(t instanceof le){const n=t.getNode();null!==n&&t.syncSlotsFromYjs(e,n)}return}const o=Pe(e,n);if(o instanceof he&&t instanceof ee){const{keysChanged:n,childListChanged:s,delta:i}=t;if(n.size>0&&o.syncPropertiesFromYjs(e,n),n.has(Se)){const t=o.getNode();null!==t&&o.syncSlotsFromYjs(e,t)}s&&(o.applyChildrenYjsDelta(e,i),o.syncChildrenFromYjs(e))}else if(o instanceof ue&&t instanceof Z){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof le&&t instanceof te){const{attributesChanged:n}=t;if(n.size>0&&o.syncPropertiesFromYjs(e,n),n.has(Se)){const t=o.getNode();null!==t&&o.syncSlotsFromYjs(e,t)}}else ie(82)}function Ht(e,t,n,o,s=Wt){const i=e.editor,r=i._editorState;if(n.forEach(e=>e.delta),i.update(()=>{for(let t=0;t<n.length;t++){const o=n[t];Ut(e,o)}qt(r,e,t),o||M(O)},{onUpdate:()=>{s(e,t),e.root.isEmpty()&&i.update(()=>Jt())},skipTransforms:!0,tag:o?A:F}),n.length>0){const t=n[0].transaction;q(t,t.deleteSet,t=>{if(t.constructor===X){const n=t.content.type;if(n){const t=n._collabNode;void 0!==t&&e.collabNodeMap.get(t._key)===t&&e.collabNodeMap.delete(t._key)}}})}}function qt(e,t,n){const o=s();if(i(o))if(We(o)){const r=e._selection;if(i(r)&&(Yt(t,n),We(o))){Ue(o.anchor.key,e)}Bt(t,n,r,s())}else Yt(t,n)}function Jt(){0===x().getChildrenSize()&&x().append(K())}function Vt(e,n,i,r,l,c,a,f){Be(e,()=>{r.read(()=>{if(f.has(F)||f.has(A))return void(a.size>0&&function(e,n){const s=Array.from(n),i=e.collabNodeMap,r=[],l=[];for(let e=0;e<s.length;e++){const n=s[e],c=t(n),a=i.get(n);if(a instanceof ue)if(o(c))r.push([a,c.__text]);else{const e=a.getOffset();if(-1===e)continue;const t=a._parent;a._normalized=!0,t._xmlText.delete(e,1),l.push(a)}}for(let e=0;e<l.length;e++){const t=l[e],n=t.getKey();i.delete(n);const o=t._parent._children,s=o.indexOf(t);o.splice(s,1)}for(let e=0;e<r.length;e++){const[t,n]=r[e];t._text=n}}(e,a));if(l.has("root")){const t=i._nodeMap,n=x(),o=e.root;o.syncPropertiesFromLexical(e,n,t),o.syncChildrenFromLexical(e,n,t,l,c),o.syncSlotsFromLexical(e,n,t,l,c),0===n.getChildrenSize()&&i._nodeMap.size>1&&e.editor.update(()=>Jt())}const r=s(),u=i._selection;Bt(e,n,u,r)})})}function Gt(e,t){const{target:n}=t;if(n instanceof j&&t instanceof te)Ge(n,e,t.attributesChanged,t.childListChanged);else if(n instanceof P&&t instanceof ee){const t=n.parent;t instanceof j?Ge(t,e,new Set,!0):ie(327)}else if(n instanceof L&&t instanceof Z&&null!=n._item&&n._item.parentSub===Se){const t=n.parent;t instanceof j?Ge(t,e,new Set([Se]),!1):ie(388)}else ie(328)}function Qt(e,t,n,o,s){const i=e.editor,r=i._editorState;q(o,o.deleteSet,t=>{if(t.constructor===X){const n=t.content.type;n&&e.mapping.delete(n)}}),n.forEach(e=>e.delta),i.update(()=>{for(let t=0;t<n.length;t++){const o=n[t];Gt(e,o)}qt(r,e,t),s||M(O)},{discrete:!0,onUpdate:()=>{Wt(e,t),0===e.root.length&&i.update(()=>Jt())},skipTransforms:!0,tag:s?A:F})}function Xt(e,t){e.mapping.clear();const n=e.editor;n.update(()=>{x().clear(),Ge(e.root,e,null,!0),M(F)},{discrete:!0,onUpdate:()=>{Wt(e,t),0===e.root.length&&n.update(()=>Jt())},skipTransforms:!0,tag:F})}function Zt(e,t,n,o,i,r,l,c){const a=c.has(F)||c.has(A);a&&0===l.size||(l.forEach(t=>{e.mapping.deleteNode(t)}),Be(e,()=>{o.read(()=>{if(i.has("root")){const t=x();xt(e.doc,e.root,t,e,new Set([...i.keys(),...r])),!a&&0===t.getChildrenSize()&&n._nodeMap.size>1&&e.editor.update(()=>Jt())}const o=s(),l=n._selection;Bt(e,t,l,o)})}))}const en=/* @__PURE__ */E("CONNECTED_COMMAND"),tn=/* @__PURE__ */E("TOGGLE_CONNECT_COMMAND"),nn=/* @__PURE__ */E("DIFF_VERSIONS_COMMAND"),on=/* @__PURE__ */E("CLEAR_DIFF_VERSIONS_COMMAND");function sn(e,t){return new ne(t,{trackedOrigins:new Set([e,null])})}function rn(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})}function ln(e,t,n,o,s){const{awareness:i}=e;let r=i.getLocalState();null===r&&(r={anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t}),r.focusing=o,i.setLocalState(r)}export{zt as $getAnchorAndFocusForUserState,Tt as $getYChangeState,on as CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL,en as CONNECTED_COMMAND,nn as DIFF_VERSIONS_COMMAND__EXPERIMENTAL,tn as TOGGLE_CONNECT_COMMAND,_e as createBinding,me as createBindingV2__EXPERIMENTAL,sn as createUndoManager,Lt as getAnchorAndFocusCollabNodesForUserState,rn as initLocalState,wt as removeCursorHighlightRule,Nt as renderSnapshot__EXPERIMENTAL,ln as setLocalStateFocus,Wt as syncCursorPositions,Vt as syncLexicalUpdateToYjs,Zt as syncLexicalUpdateToYjsV2__EXPERIMENTAL,Ht as syncYjsChangesToLexical,Qt as syncYjsChangesToLexicalV2__EXPERIMENTAL,Xt as syncYjsStateToLexicalV2__EXPERIMENTAL};
|
|
9
|
+
import{$isDecoratorNode as e,$getNodeByKey as t,$isLineBreakNode as n,$isTextNode as o,$getSelection as s,$isRangeSelection as i,$isElementNode as r,$createChildrenArray as l,$getNodeByKeyOrThrow as c,$removeFromParent as a,isLexicalEditor as f,createEditor as u,$getSlotNames as d,$getSlot as h,$removeSlot as g,$setSlot as p,$isRootNode as y,$getWritableNodeState as _,getDeclaredSlots as m,$getRoot as x,RootNode as S,ElementNode as b,TextNode as T,$getState as N,createState as k,getRootOwnerDocument as v,setDOMStyleObject as w,isDOMShadowRoot as C,COLLABORATION_TAG as F,HISTORIC_TAG as M,$addUpdateTag as A,SKIP_SCROLL_INTO_VIEW_TAG as O,$createParagraphNode as K,createCommand as E}from"lexical";import{XmlText as P,XmlElement as j,Map as L,Doc as z,typeListToArraySnapshot as Y,Snapshot as D,typeMapGetAllSnapshot as I,isDeleted as R,XmlHook as $,ContentString as W,ContentFormat as B,emptySnapshot as U,PermanentUserData as H,iterateDeletedStructs as q,snapshot as J,createAbsolutePositionFromRelativePosition as V,createRelativePositionFromTypeIndex as G,compareRelativePositions as Q,Item as X,YMapEvent as Z,YTextEvent as ee,YXmlEvent as te,UndoManager as ne}from"yjs";import{createDOMRange as oe,createRectsFromDOMRange as se}from"@lexical/selection";function ie(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function re(e,t,n){const o=e.length,s=t.length;let i=0,r=0;for(;i<o&&i<s&&e[i]===t[i]&&i<n;)i++;for(;r+i<o&&r+i<s&&e[o-r-1]===t[s-r-1];)r++;for(;r+i<o&&r+i<s&&e[i]===t[i];)i++;return{index:i,insert:t.slice(i,s-r),remove:o-i-r}}class le{_xmlElem;_key;_parent;_type;constructor(e,t,n){this._key="",this._xmlElem=e,this._parent=t,this._type=n}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e(n)?n:null}getNode(){const n=t(this._key);return e(n)?n:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent instanceof le&&ie(394),this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);Re(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();if(null===n)return;ze(e,this._xmlElem,n,t)}syncSlotsFromYjs(e,t){qe(e,this._xmlElem,t,this)}syncSlotsFromLexical(e,t,n,o,s){Je(e,this._xmlElem,t,n,o,s,this)}destroy(e){const t=e.collabNodeMap;Ve(e,this._xmlElem),t.get(this._key)===this&&t.delete(this._key)}}function ce(e,t,n){const o=new le(e,t,n);return e._collabNode=o,o}class ae{_map;_key;_parent;_type;constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const e=t(this._key);return n(e)?e:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function fe(e,t){const n=new ae(e,t);return e._collabNode=n,n}class ue{_map;_key;_parent;_text;_type;_normalized;constructor(e,t,n,o){this._key="",this._map=e,this._parent=n,this._text=t,this._type=o,this._normalized=!1}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return o(t)?t:null}getNode(){const e=t(this._key);return o(e)?e: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(e,t,n){const o=this._parent._xmlText,s=this.getOffset()+1+e;0!==t&&o.delete(s,t),""!==n&&o.insert(s,n)}syncPropertiesAndTextFromLexical(e,t,n){const o=this.getPrevNode(n),r=t.__text;if(Re(e,this._map,o,t),null!==o){const e=o.__text;if(e!==r){!function(e,t,n,o){const r=s();let l=o.length;if(i(r)&&r.isCollapsed()){const e=r.anchor;e.key===t&&(l=e.offset)}const c=re(n,o,l);e.spliceText(c.index,c.remove,c.insert)}(this,t.__key,e,r),this._text=r}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();if(null===n)return;ze(e,this._map,n,t);const o=this._text;n.__text!==o&&n.setTextContent(o)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function de(e,t,n,o){const s=new ue(e,t,n,o);return e._collabNode=s,s}class he{_key;_children;_xmlText;_type;_parent;constructor(e,t,n){this._key="",this._children=[],this._xmlText=e,this._type=n,this._parent=t}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return r(t)?t:null}getNode(){const e=t(this._key);return r(e)?e:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){const e=this._parent;return e instanceof he||ie(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null!==n&&ze(e,this._xmlText,n,t)}applyChildrenYjsDelta(e,t){const n=this._children;let o=0,s=null;for(let i=0;i<t.length;i++){const r=t[i],l=r.insert,c=r.delete;if(null!=r.retain)o+=r.retain;else if("number"==typeof c){let e=c;for(;e>0;){const{node:t,nodeIndex:s,offset:i,length:r}=We(this,o,!1);if(t instanceof he||t instanceof ae||t instanceof le)n.splice(s,1),e-=1;else{if(!(t instanceof ue))break;{const o=Math.min(e,r),l=0!==s?n[s-1]:null,c=t.getSize();if(0===i&&r===c){n.splice(s,1);const e=$e(t._text,i,o-1,"");e.length>0&&(l instanceof ue?l._text+=e:this._xmlText.delete(i,e.length))}else t._text=$e(t._text,i,o,"");e-=o}}}}else{if(null==l)throw new Error("Unexpected delta format");if("string"==typeof l){const{node:e,offset:t}=We(this,o,!0);e instanceof ue?e._text=$e(e._text,t,0,l):this._xmlText.delete(t,l.length),o+=l.length}else{const t=l;if(void 0===Pe(t))continue;const{node:i,nodeIndex:r,length:c}=We(this,o,!1),a=je(e,t,this);if(i instanceof ue&&c>0&&c<i._text.length){const e=i._text,t=e.length-c;i._text=$e(e,t,c,""),n.splice(r+1,0,a),s=$e(e,0,t,"")}else n.splice(r,0,a);null!==s&&a instanceof ue&&(a._text=s+a._text,s=null),o+=1}}}}syncChildrenFromYjs(e){const t=this.getNode();if(null===t)return;const n=t.__key,s=l(t,null),i=s.length,r=this._children,f=r.length,u=e.collabNodeMap,d=new Set;let h,g,p=0,y=null;f!==i&&(g=t.getWritable());for(let i=0;i<f;i++){const l=s[p],_=r[i],m=_.getNode(),x=_._key;if(null!==m&&l===x){const t=o(m);if(d.add(l),t)if(_._key=l,_ instanceof he){const t=_._xmlText;_.syncPropertiesFromYjs(e,null),_.applyChildrenYjsDelta(e,t.toDelta()),_.syncChildrenFromYjs(e)}else _ instanceof ue?_.syncPropertiesAndTextFromYjs(e,null):_ instanceof le?_.syncPropertiesFromYjs(e,null):_ instanceof ae||ie(93);y=m,p++}else{if(void 0===h){h=new Set;for(let e=0;e<f;e++){const t=r[e]._key;""!==t&&h.add(t)}}if(null!==m&&void 0!==l&&!h.has(l)){const e=c(l);a(e),i--,p++;continue}g=t.getWritable();const o=Le(e,_,n),s=o.__key;if(u.set(s,_),null===y){const e=g.getFirstChild();if(g.__first=s,null!==e){const t=e.getWritable();t.__prev=s,o.__next=t.__key}}else{const e=y.getWritable(),t=y.getNextSibling();if(e.__next=s,o.__prev=y.__key,null!==t){const e=t.getWritable();e.__prev=s,o.__next=e.__key}}i===f-1&&(g.__last=s),g.__size++,y=o}}for(let t=0;t<i;t++){const n=s[t];if(!d.has(n)){const t=c(n),o=e.collabNodeMap.get(n);void 0!==o&&o.destroy(e),a(t)}}this.syncSlotsFromYjs(e,t)}syncSlotsFromYjs(e,t){qe(e,this._xmlText,t,this)}syncPropertiesFromLexical(e,t,n){Re(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,s,i,l,a){const f=this._children[n],u=c(s);f instanceof he&&r(u)?(f.syncPropertiesFromLexical(t,u,i),f.syncChildrenFromLexical(t,u,i,l,a),f.syncSlotsFromLexical(t,u,i,l,a)):f instanceof ue&&o(u)?f.syncPropertiesAndTextFromLexical(t,u,i):f instanceof le&&e(u)&&(f.syncPropertiesFromLexical(t,u,i),f.syncSlotsFromLexical(t,u,i,l,a))}syncSlotsFromLexical(e,t,n,o,s){Je(e,this._xmlText,t,n,o,s,this)}syncChildrenFromLexical(e,t,n,o,s){const i=this.getPrevNode(n),r=null===i?[]:l(i,n),a=l(t,null),f=r.length-1,u=a.length-1,d=e.collabNodeMap;let h,g,p=0,y=0;for(;p<=f&&y<=u;){const t=r[p],i=a[y];if(t===i)this._syncChildFromLexical(e,y,i,n,o,s),p++,y++;else{void 0===h&&(h=new Set(r)),void 0===g&&(g=new Set(a));const n=g.has(t),o=h.has(i);if(n){const t=Ee(e,c(i),this);d.set(i,t),o?(this.splice(e,y,1,t),p++,y++):(this.splice(e,y,0,t),y++)}else this.splice(e,y,1),p++}}const _=p>f,m=y>u;if(_&&!m)for(;y<=u;++y){const t=a[y],n=Ee(e,c(t),this);this.append(n),d.set(t,n)}else if(m&&!_)for(let t=this._children.length-1;t>=y;t--)this.splice(e,t,1)}append(e){const t=this._xmlText,n=this._children,o=n[n.length-1],s=void 0!==o?o.getOffset()+o.getSize():0;if(e instanceof he)t.insertEmbed(s,e._xmlText);else if(e instanceof ue){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof ae?t.insertEmbed(s,e._map):e instanceof le&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,o){const s=this._children,i=s[t];if(void 0===i)return void(void 0!==o&&this.append(o));const r=i.getOffset();-1===r&&ie(95);const l=this._xmlText;if(0!==n){const o=s.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e);l.delete(r,i.getSize())}if(o instanceof he)l.insertEmbed(r,o._xmlText);else if(o instanceof ue){const e=o._map;null===e.parent&&l.insertEmbed(r,e),l.insert(r+1,o._text)}else o instanceof ae?l.insertEmbed(r,o._map):o instanceof le&&l.insertEmbed(r,o._xmlElem);void 0!==o?s.splice(t,n,o):s.splice(t,n)}getChildOffset(e){let t=0;const n=this._children;for(let o=0;o<n.length;o++){const s=n[o];if(s===e)return t;t+=s.getSize()}return-1}destroy(e){const t=e.collabNodeMap,n=this._children;for(let t=0;t<n.length;t++)n[t].destroy(e);Ve(e,this._xmlText),t.get(this._key)===this&&t.delete(this._key)}}function ge(e,t,n){const o=new he(e,t,n);return e._collabNode=o,o}class pe{_nodeMap=new Map;_sharedTypeToNodeKeys=new Map;_nodeKeyToSharedType=new Map;set(e,t){const n=t instanceof Array;this.delete(e);const s=n?t:[t];for(const e of s){const t=e.getKey();if(this._nodeKeyToSharedType.has(t)){const e=this._nodeKeyToSharedType.get(t),n=this._sharedTypeToNodeKeys.get(e).indexOf(t);-1!==n&&this._sharedTypeToNodeKeys.get(e).splice(n,1),this._nodeKeyToSharedType.delete(t),this._nodeMap.delete(t)}}if(e instanceof P){if(n||ie(331),0===t.length)return;this._sharedTypeToNodeKeys.set(e,t.map(e=>e.getKey()));for(const n of t)this._nodeMap.set(n.getKey(),n),this._nodeKeyToSharedType.set(n.getKey(),e)}else n&&ie(332),o(t)&&ie(333),this._sharedTypeToNodeKeys.set(e,[t.getKey()]),this._nodeMap.set(t.getKey(),t),this._nodeKeyToSharedType.set(t.getKey(),e)}get(e){const t=this._sharedTypeToNodeKeys.get(e);if(void 0!==t){if(e instanceof P){const e=Array.from(t.map(e=>this._nodeMap.get(e)));return e.length>0?e:void 0}return this._nodeMap.get(t[0])}}getSharedType(e){return this._nodeKeyToSharedType.get(e.getKey())}delete(e){const t=this._sharedTypeToNodeKeys.get(e);if(void 0!==t){for(const e of t)this._nodeMap.delete(e),this._nodeKeyToSharedType.delete(e);this._sharedTypeToNodeKeys.delete(e)}}deleteNode(e){const t=this._nodeKeyToSharedType.get(e);t&&this.delete(t),this._nodeMap.delete(e)}has(e){return this._sharedTypeToNodeKeys.has(e)}clear(){this._nodeMap.clear(),this._sharedTypeToNodeKeys.clear(),this._nodeKeyToSharedType.clear()}}function ye(e,t,n,o,s){const i={clientID:n.clientID,cursorHighlightSheet:null,cursors:new Map,cursorsContainer:null,doc:n,docMap:o,editor:e,excludedProperties:s||new Map,id:t,nodeProperties:new Map};return function(e){const{editor:t,nodeProperties:n}=e;t.update(()=>{t._nodes.forEach(t=>{const o=new t.klass,s={};for(const[t,n]of Object.entries(o))Me(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(i),i}function _e({editor:e,id:t,doc:n,docMap:o,excludedProperties:s,rootName:i="root"}){const r=ge(n.get(i,P),null,"root");return r._key="root",{...ye(e,t,n,o,s),collabNodeMap:new Map,root:r}}function me(e,t,n,o,s,i){return null==o&&ie(81),_e({doc:o,docMap:s,editor:e,excludedProperties:i,id:n})}function xe(e,t,n,o,s={}){null==n&&ie(81);const{excludedProperties:i,rootName:r="root-v2"}=s;return{...ye(e,t,n,o,i),mapping:new pe,root:n.get(r,j)}}function Se(e){return Object.prototype.hasOwnProperty.call(e,"collabNodeMap")}const be="__slots",Te=new Set(["__key","__parent","__next","__prev","__state","__slotHost","__slots"]),Ne=new Set(["__first","__last","__size"]),ke=new Set(["__cachedText"]),ve=new Set(["__text"]);function we(e,t){e.setAttribute(be,t)}function Ce(e){return"__proto__"===e||"constructor"===e||"prototype"===e}function Fe(t){return(r(t)||e(t))&&!t.isInline()}function Me(e,t,n){if(Te.has(e)||"function"==typeof t[e])return!0;if(o(t)){if(ve.has(e))return!0}else if(r(t)&&(Ne.has(e)||y(t)&&ke.has(e)))return!0;const s=t.constructor,i=n.excludedProperties.get(s);return null!=i&&i.has(e)}function Ae(e,t){const n=e.__type,{nodeProperties:o}=t,s=o.get(n);return void 0===s&&ie(330,n),s}function Oe(t,n,s,i,l,c){n instanceof he&&r(s)?(n.syncPropertiesFromLexical(t,s,i),n.syncChildrenFromLexical(t,s,i,l,c),n.syncSlotsFromLexical(t,s,i,l,c)):n instanceof ue&&o(s)?n.syncPropertiesAndTextFromLexical(t,s,i):n instanceof le&&e(s)&&(n.syncPropertiesFromLexical(t,s,i),n.syncSlotsFromLexical(t,s,i,l,c))}function Ke(e,t,n,o){const s=d(t),i=m(t.constructor).length>0;if(0===s.length&&!i)return;const r=new L;let l=!1;for(const o of s){const s=h(t,o);if(null===s)continue;const i=Ee(e,s,n);e.collabNodeMap.set(s.__key,i),r.set(o,i.getSharedType()),l=!0}(l||i)&&we(o,r)}function Ee(t,s,i){const l=s.__type;let c;if(r(s)){const e=new P;c=ge(e,i,l),c.syncPropertiesFromLexical(t,s,null),c.syncChildrenFromLexical(t,s,null,null,null),Ke(t,s,c,e)}else if(o(s)){i instanceof he||ie(389);c=de(new L,s.__text,i,l),c.syncPropertiesAndTextFromLexical(t,s,null)}else if(n(s)){i instanceof he||ie(390);const e=new L;e.set("__type","linebreak"),c=fe(e,i)}else if(e(s)){const e=new j;c=ce(e,i,l),c.syncPropertiesFromLexical(t,s,null),Ke(t,s,c,e)}else ie(86);return c._key=s.__key,c}function Pe(e){const t=Ye(e,"__type");return"string"!=typeof t&&void 0!==t&&ie(87),t}function je(e,t,n){const o=t._collabNode;if(void 0===o){const o=e.editor._nodes,s=Pe(t);"string"!=typeof s&&ie(87);void 0===o.get(s)&&ie(88,s);const i=t.parent,r=void 0===n&&null!==i?je(e,i):n||null;if(r instanceof he||r instanceof le&&function(e,t){const n=e._xmlElem.getAttribute(be);if(!(n instanceof L))return!1;for(const e of n.values())if(e===t)return!0;return!1}(r,t)||ie(391),t instanceof P)return ge(t,r,s);if(t instanceof L)return r instanceof he||ie(392),"linebreak"===s?fe(t,r):de(t,"",r,s);if(t instanceof j)return ce(t,r,s)}return o}function Le(t,n,o){const s=n.getType(),i=t.editor._nodes.get(s);void 0===i&&ie(88,s);const r=new i.klass;if(r.__parent=o,n._key=r.__key,n instanceof he){const e=n._xmlText;n.syncPropertiesFromYjs(t,null),n.applyChildrenYjsDelta(t,e.toDelta()),n.syncChildrenFromYjs(t)}else n instanceof ue?n.syncPropertiesAndTextFromYjs(t,null):n instanceof le&&(n.syncPropertiesFromYjs(t,null),e(r)||ie(393),n.syncSlotsFromYjs(t,r));return t.collabNodeMap.set(r.__key,n),r}function ze(e,t,n,o){const s=null===o?t instanceof L?Array.from(t.keys()):t instanceof P||t instanceof j?Object.keys(t.getAttributes()):Object.keys(t):Array.from(o);let i;for(let o=0;o<s.length;o++){const r=s[o];if(Me(r,n,e)){"__state"===r&&Se(e)&&(i||(i=n.getWritable()),Ie(t,i));continue}const l=n[r];let c=Ye(t,r);if(l!==c){if(c instanceof z){const t=e.docMap;l instanceof z&&t.delete(l.guid);const n=c.guid;if(t.set(n,c),f(l))l._key=n,c=l;else{const e=u();e._key=n,c=e}}void 0===i&&(i=n.getWritable()),i[r]=c}}}function Ye(e,t){return e instanceof L?e.get(t):e instanceof P||e instanceof j?e.getAttribute(t):e[t]}function De(e,t,n){e instanceof L?e.set(t,n):e.setAttribute(t,n)}function Ie(e,t){const n=Ye(e,"__state");n instanceof L&&_(t).updateFromJSON(n.toJSON())}function Re(e,t,n,o){const s=Object.keys(Ae(o,e)),i=e.editor.constructor;!function(e,t,n,o){const s=o.__state,i=null===t.doc?void 0:Ye(t,"__state");if(!s)return;const[r,l]=s.getInternalState(),c=n&&n.__state,a=i instanceof L?i:new L;if(c===s)return;const[f,u]=c&&a.doc?c.getInternalState():[void 0,new Map];if(r)for(const[e,t]of Object.entries(r))f&&t!==f[e]&&a.set(e,t);for(const[e,t]of l)u.get(e)!==t&&a.set(e.key,e.unparse(t));i||De(t,"__state",a)}(0,t,n,o);for(let r=0;r<s.length;r++){const l=s[r],c=null===n?void 0:n[l];let a=o[l];if(c!==a){if(a instanceof i){const t=e.docMap;let n;if(c instanceof i){const e=c._key;n=t.get(e),t.delete(e)}const s=n||new z,r=s.guid;a._key=r,t.set(r,s),a=s,e.editor.update(()=>{o.markDirty()})}De(t,l,a)}}}function $e(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function We(e,t,n){let o=0,s=0;const i=e._children,r=i.length;for(;s<r;s++){const e=i[s],l=o;o+=e.getSize();if((n?o>=t:o>t)&&e instanceof ue){let n=t-l-1;n<0&&(n=0);return{length:o-t,node:e,nodeIndex:s,offset:n}}if(o>t)return{length:0,node:e,nodeIndex:s,offset:l};if(s===r-1)return{length:0,node:null,nodeIndex:s+1,offset:l+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function Be(e){const t=e.anchor,n=e.focus;let s=!1;try{const e=t.getNode(),i=n.getNode();(!e.isAttached()||!i.isAttached()||o(e)&&t.offset>e.getTextContentSize()||o(i)&&n.offset>i.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function Ue(e,t){e.doc.transact(t,e)}function He(e,n){const o=n._nodeMap.get(e);if(!o)return void x().selectStart();const s=o.__prev;let i=null;s&&(i=t(s)),null===i&&null!==o.__parent&&(i=t(o.__parent)),null!==i?null!==i&&i.isAttached()?i.selectEnd():He(i.__key,n):x().selectStart()}function qe(n,o,s,i){const l=o.getAttribute(be),c=l instanceof L?new Set(l.keys()):new Set;for(const e of d(s))if(!c.has(e)){const t=h(s,e);if(null!==t){const e=n.collabNodeMap.get(t.__key);void 0!==e&&e.destroy(n)}g(s,e)}if(l instanceof L)for(const[o,c]of l.entries()){if(Ce(o))continue;if(!(c instanceof P||c instanceof j||c instanceof L))continue;const l=h(s,o),a=null===l?void 0:n.collabNodeMap.get(l.__key);if(void 0!==a&&a.getSharedType()===c)continue;if(void 0===c._collabNode&&"string"!=typeof Ye(c,"__type"))continue;if(c instanceof L&&i instanceof le)continue;const f=c._collabNode;if(void 0!==f){const n=t(f._key);if(null!==n&&(n.isAttached()||(r(n)||e(n))&&null!==n.getLatest().__slotHost))continue}const u=je(n,c,i),d=Le(n,u,null);Fe(d)?(void 0!==a&&a.destroy(n),p(s,o,d)):n.collabNodeMap.get(d.__key)===u&&n.collabNodeMap.delete(d.__key)}}function Je(e,t,n,o,s,i,r){const l=d(n),c=t.getAttribute(be);if(0===l.length&&!(c instanceof L))return;let a;c instanceof L?a=c:(a=new L,we(t,a));const f=new Set(l);for(const t of Array.from(a.keys()))if(!f.has(t)){const n=a.get(t),o=null==n?void 0:n._collabNode;void 0!==o&&o.destroy(e),a.delete(t)}const u=e.collabNodeMap;for(const t of l){const l=h(n,t);if(null===l)continue;const c=u.get(l.__key);if(void 0!==c&&a.get(t)===c.getSharedType())Oe(e,c,l,o,s,i);else{const n=a.get(t),o=null==n?void 0:n._collabNode;void 0!==o&&o.destroy(e);const s=Ee(e,l,r);u.set(l.__key,s),a.set(t,s.getSharedType())}}}function Ve(e,t){const n=t.getAttribute(be);if(n instanceof L)for(const t of n.keys()){const o=n.get(t),s=null==o?void 0:o._collabNode;void 0!==s&&s.destroy(e)}}const Ge=e=>"UNDEFINED"===e.nodeName,Qe=(t,n,o,s,i,r,l)=>{let c=n.mapping.get(t);if(c&&o&&0===o.size&&!s)return c;const a=Ge(t)?S.getType():t.nodeName,f=n.editor._nodes.get(a);if(void 0===f)throw new Error(`$createOrUpdateNodeFromYElement: Node ${a} is not registered`);if(c||(c=new f.klass,o=null,s=!0),s&&c instanceof b){const e=[],o=t=>{if(t instanceof j){const o=Qe(t,n,new Set,!1,i,r,l);null!==o&&e.push(o)}else if(t instanceof P){const o=et(t,n,i,r,l);null!==o&&o.forEach(t=>{null!==t&&e.push(t)})}else ie(329)};void 0===i||void 0===r?t.toArray().forEach(o):Y(t,new D(r.ds,i.sv)).filter(e=>!e._item.deleted||Ze(e._item,i)||Ze(e._item,r)).forEach(o),Xe(c,e)}const u=t.getAttributes(i);Ge(t)||void 0===i||(Ze(t._item,i)?Ze(t._item,r)||(u[_t("ychange")]=l?l("added",t._item.id):{type:"added"}):u[_t("ychange")]=l?l("removed",t._item.id):{type:"removed"});const y={...Ae(c,n)},m={};for(const e in u)e.startsWith(yt)?m[mt(e)]=u[e]:e!==be&&"__proto__"!==e&&"constructor"!==e&&"prototype"!==e&&(y[e]=u[e]);if(ze(n,y,c,o),o){if(o.size>0){const e=_(c);for(const t of o)if(t.startsWith(yt)){const n=mt(t);e.updateFromUnknown(n,m[n])}}}else _(c).updateFromJSON(m);if(c instanceof b||e(c)){const e=u[be],t=new Set;if(e instanceof L){const o=void 0===i?Array.from(e.entries()):Object.entries(I(e,i));for(const[e,s]of o){if(t.add(e),Ce(e))continue;let o=null;if(s instanceof j&&(o=Qe(s,n,new Set,!1,i,r,l)),null===o)continue;const a=h(c,e);null!==a&&a.getKey()===o.getKey()||(Fe(o)?null===o.getLatest().__slotHost&&p(c,e,o):o.isAttached()||nt(s,n))}}for(const e of d(c))t.has(e)||g(c,e)}const x=c.getLatest();return n.mapping.set(t,x),x},Xe=(e,t)=>{const n=e.getChildren(),o=new Set(n.map(e=>e.getKey())),s=new Set(t.map(e=>e.getKey())),i=n.length-1,r=t.length-1;let l=0,c=0;for(;l<=i&&c<=r;){const i=n[l].getKey(),r=t[c].getKey();if(i===r){l++,c++;continue}const a=s.has(i),f=o.has(r);if(!a){if(0===c&&1===e.getChildrenSize())return void e.splice(c,1,t.slice(c));e.splice(c,1,[]),l++;continue}const u=t[c];f?(e.splice(c,1,[u]),l++,c++):(e.splice(c,0,[u]),c++)}const a=l>i,f=c>r;a&&!f?e.append(...t.slice(c)):f&&!a&&e.splice(t.length,e.getChildrenSize()-t.length,[])},Ze=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!R(t.ds,e.id),et=(e,t,n,s,i)=>{const r=gt(e,n,s,i);let l=t.mapping.get(e)??[];const c=r.map(e=>e.attributes.t??T.getType());if(!(l.length===c.length&&l.every((e,t)=>e.getType()===c[t]))){const e=t.editor._nodes;l=c.map(t=>{const n=e.get(t);if(void 0===n)throw new Error(`$createTextNodesFromYText: Node ${t} is not registered`);const s=new n.klass;if(!o(s))throw new Error(`$createTextNodesFromYText: Node ${t} is not a TextNode`);return s})}for(let e=0;e<r.length;e++){const n=l[e],o=r[e],{attributes:s,insert:i}=o;n.__text!==i&&n.setTextContent(i);const c={...Ae(n,t),...s.p},a=Object.fromEntries(Object.entries(s).filter(([e])=>e.startsWith(yt)).map(([e,t])=>[mt(e),t]));ze(t,c,n,null),_(n).updateFromJSON(a)}const a=l.map(e=>e.getLatest());return t.mapping.set(e,a),a},tt=(e,t)=>{const n=d(e);if(0===n.length&&0===m(e.constructor).length)return;const o=new L;for(const s of n){const n=h(e,s);null!=n&&o.set(s,st(n,t))}return o},nt=(e,t)=>{if((e instanceof j||e instanceof P)&&t.mapping.delete(e),e instanceof j){const n=e.getAttribute(be);if(n instanceof L)for(const e of n.values())nt(e,t);for(const n of e.toArray())nt(n,t)}},ot=(e,t)=>{const n=new j(e.getType()),o={...pt(e,t),...xt(e)};for(const e in o){const t=o[e];null!==t&&n.setAttribute(e,t)}if(!(e instanceof b)){const o=tt(e,t);return void 0!==o&&(we(n,o),t.mapping.set(n,e)),n}const s=tt(e,t);return void 0!==s&&we(n,s),n.insert(0,ct(e).map(e=>it(e,t))),t.mapping.set(n,e),n},st=(t,n)=>{const o=ot(t,n);return e(t)&&void 0===n.mapping.getSharedType(t)&&n.mapping.set(o,t),o},it=(e,t)=>e instanceof Array?((e,t)=>{const n=new P;return ht(n,e,t),n})(e,t):ot(e,t),rt=e=>"object"==typeof e&&null!=e,lt=(e,t)=>{const n=Object.keys(e).filter(t=>null!==e[t]);if(null==t)return 0===n.length;let o=n.length===Object.keys(t).filter(e=>null!==t[e]).length;for(let s=0;s<n.length&&o;s++){const i=n[s],r=e[i],l=t[i];o="ychange"===i||r===l||rt(r)&&rt(l)&<(r,l)}return o},ct=e=>{if(!(e instanceof b))return[];const t=e.getChildren(),n=[];for(let e=0;e<t.length;e++){const s=t[e];if(o(s)){const s=[];for(let n=t[e];e<t.length&&o(n);n=t[++e])s.push(n);e--,n.push(s)}else n.push(s)}return n},at=(e,t,n)=>{const o=gt(e);return o.length===t.length&&o.every((e,o)=>{const s=t[o],i=e.attributes.t??T.getType(),r=e.attributes.p??{},l=Object.fromEntries(Object.entries(e.attributes).filter(([e])=>e.startsWith(yt)));return e.insert===s.getTextContent()&&i===s.getType()&<(r,pt(s,n))&<(l,xt(s))})},ft=(e,t,n)=>{if(e instanceof j&&!(t instanceof Array)&&bt(e,t)){const o=ct(t),s=e.getAttributes();return delete s[be],e._length===o.length&<(s,{...pt(t,n),...xt(t)})&&((e,t,n)=>{const o=d(t),s=e.getAttribute(be);if(!(s instanceof L))return 0===o.length;if(s.size!==o.length)return!1;for(const e of o){const o=h(t,e),i=s.get(e);if(null===o||!(i instanceof j)||n.mapping.get(i)!==o)return!1}return!0})(e,t,n)&&e.toArray().every((e,t)=>ft(e,o[t],n))}return e instanceof P&&t instanceof Array&&at(e,t,n)},ut=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),dt=(e,t,n)=>{const o=e.toArray(),s=ct(t),i=s.length,r=o.length,l=Math.min(r,i);let c=0,a=0,f=!1;for(;c<l;c++){const e=o[c],t=s[c];if(e instanceof $)break;if(ut(n.mapping.get(e),t))f=!0;else if(!ft(e,t,n))break}for(;c+a<l;a++){const e=o[r-a-1],t=s[i-a-1];if(e instanceof $)break;if(ut(n.mapping.get(e),t))f=!0;else if(!ft(e,t,n))break}return{equalityFactor:c+a,foundMappedChild:f}},ht=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:o,str:r}=(e=>{let t="",n=e._start;const o={};for(;null!==n;)n.deleted||(n.countable&&n.content instanceof W?t+=n.content.str:n.content instanceof B&&(o[n.content.key]=null)),n=n.right;return{nAttrs:o,str:t}})(e),l=t.map((e,t)=>{const s=e.getType();let i=pt(e,n);return 0===Object.keys(i).length&&(i=null),{attributes:Object.assign({},o,{...s!==T.getType()&&{t:s},p:i,...xt(e),...t>0&&{i:t}}),insert:e.getTextContent(),nodeKey:e.getKey()}}),c=l.map(e=>e.insert).join(""),a=s();let f;if(i(a)&&a.isCollapsed()){f=0;for(const e of l){if(e.nodeKey===a.anchor.key){f+=a.anchor.offset;break}f+=e.insert.length}}else f=c.length;const{insert:u,remove:d,index:h}=re(r,c,f);e.delete(h,d),e.insert(h,u),e.applyDelta(l.map(e=>({attributes:e.attributes,retain:e.insert.length})))},gt=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>{const t=e.attributes??{};return"ychange"in t&&(t[_t("ychange")]=t.ychange,delete t.ychange),{...e,attributes:t}}),pt=(e,t)=>{const n=Ae(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},yt="s_",_t=e=>`s_${e}`,mt=e=>{if(!e.startsWith(yt))throw new Error(`Invalid state key: ${e}`);return e.slice(yt.length)},xt=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[_t(e)]=t;for(const[e,t]of o)s[_t(e.key)]=e.unparse(t);return s},St=(t,n,o,s,i)=>{if(n instanceof j&&n.nodeName!==o.getType()&&(!Ge(n)||o.getType()!==S.getType()))throw new Error("node name mismatch!");if(s.mapping.set(n,o),n instanceof j){const r=n.getAttributes(),l={...pt(o,s),...xt(o)};for(const e in l)if(null!=l[e]){r[e]===l[e]||rt(r[e])&&rt(l[e])&<(r[e],l[e])||"ychange"===e||n.setAttribute(e,l[e])}else n.removeAttribute(e);for(const e in r)e!==be&&void 0===l[e]&&n.removeAttribute(e);(o instanceof b||e(o))&&((t,n,o,s,i)=>{const r=d(n),l=t.getAttribute(be);if(0===r.length&&!(l instanceof L)&&0===m(n.constructor).length)return;let c;l instanceof L?c=l:(c=new L,we(t,c));const a=new Set(r);for(const e of Array.from(c.keys()))if(!a.has(e)){const t=c.get(e);void 0!==t&&nt(t,o),c.delete(e)}for(const t of r){const r=h(n,t);if(null==r)continue;const l=c.get(t);l instanceof j&&(r instanceof b||e(r))&&l===o.mapping.getSharedType(r)?s.has(r.getKey())&&St(i,l,r,o,s):(l instanceof j&&nt(l,o),c.set(t,st(r,o)))}})(n,o,s,i,t)}const r=ct(o),l=r.length,c=n.toArray(),a=c.length,f=Math.min(l,a);let u=0,g=0;for(;u<f;u++){const n=c[u],o=r[u];if(n instanceof $)break;if(ut(s.mapping.get(n),o))o instanceof Array||!(o instanceof b||e(o))||!i.has(o.getKey())||St(t,n,o,s,i);else{if(!ft(n,o,s))break;s.mapping.set(n,o)}}for(;g+u<f;g++){const n=c[a-g-1],o=r[l-g-1];if(n instanceof $)break;if(ut(s.mapping.get(n),o))o instanceof Array||!(o instanceof b||e(o))||!i.has(o.getKey())||St(t,n,o,s,i);else{if(!ft(n,o,s))break;s.mapping.set(n,o)}}for(;a-u-g>0&&l-u-g>0;){const e=c[u],o=r[u],f=c[a-g-1],d=r[l-g-1];if(e instanceof P&&o instanceof Array)at(e,o,s)||ht(e,o,s),u+=1;else{let r=e instanceof j&&bt(e,o),l=f instanceof j&&bt(f,d);if(r&&l){const t=dt(e,o,s),n=dt(f,d,s);t.foundMappedChild&&!n.foundMappedChild?l=!1:!t.foundMappedChild&&n.foundMappedChild||t.equalityFactor<n.equalityFactor?r=!1:l=!1}r?(St(t,e,o,s,i),u+=1):l?(St(t,f,d,s,i),g+=1):(s.mapping.delete(n.get(u)),n.delete(u,1),n.insert(u,[it(o,s)]),u+=1)}}const p=a-u-g;if(1===a&&0===l&&c[0]instanceof P?(s.mapping.delete(c[0]),c[0].delete(0,c[0].length)):p>0&&(n.slice(u,u+p).forEach(e=>s.mapping.delete(e)),n.delete(u,p)),u+g<l){const e=[];for(let t=u;t<l-g;t++)e.push(it(r[t],s));n.insert(u,e)}},bt=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType(),Tt=/* @__PURE__ */k("ychange",{isEqual:(e,t)=>e===t,parse:e=>e??null});function Nt(e){return N(e,Tt)}const kt=(e,t=J(e.doc),n=U)=>{const{doc:o}=e;o.gc&&ie(325),o.transact(s=>{const i=new H(o);i&&i.dss.forEach(e=>{q(s,e,e=>{})});const r=(e,t)=>({id:t,type:e,user:("added"===e?i.getUserByClientId(t.client):i.getUserByDeletedId(t))??null});e.mapping.clear(),e.editor.update(()=>{x().clear(),Qe(e.root,e,null,!0,t,n,r)})},e)},vt="undefined"!=typeof Highlight&&"undefined"!=typeof CSS&&"highlights"in CSS;function wt(e,t,n){if(!CSS.supports("color",n))return;const o=function(e){const t=e.editor.getRootElement(),n=v(t);let o=e.cursorHighlightSheet;null===o&&(o=new(n.defaultView||window).CSSStyleSheet,e.cursorHighlightSheet=o);const s=null!==t?t.getRootNode():null,i=C(s)?s:n;return i.adoptedStyleSheets.includes(o)||(i.adoptedStyleSheets=[...i.adoptedStyleSheets,o]),o}(e),s=o.insertRule(`::highlight(${t}) { }`,o.cssRules.length),i=o.cssRules[s];i.style.setProperty("background-color",`color-mix(in srgb, ${n} 30%, transparent)`),i.style.setProperty("color","inherit")}function Ct(e,t){const n=e.cursorHighlightSheet;if(null===n)return;const o=`::highlight(${t})`;for(let e=n.cssRules.length-1;e>=0;e--){const t=n.cssRules[e];if(null!=t&&t.selectorText===o)return void n.deleteRule(e)}}function Ft(e,t,n=0){const s=t.collabNodeMap.get(e.key);if(void 0===s)return null;let i=e.offset,l=s.getSharedType();if(s instanceof ue){l=s._parent._xmlText;const e=s.getOffset();if(-1===e)return null;i=e+1+i}else if(s instanceof he&&"element"===e.type){const t=e.getNode();r(t)||ie(184);let n=0,s=0,l=t.getFirstChild();for(;null!==l&&s++<i;)o(l)?n+=l.getTextContentSize()+1:n++,l=l.getNextSibling();i=n}return G(l,i,n)}function Mt(e,t,n=0){const{mapping:s}=t,{offset:i}=e,l=e.getNode(),c=s.getSharedType(l);if(void 0===c)return null;if("text"===e.type){o(l)||ie(326);let e=l.getPreviousSibling(),t=i;for(;o(e);)t+=e.getTextContentSize(),e=e.getPreviousSibling();return G(c,t,n)}if("element"===e.type){r(l)||ie(184);let e=0,t=l.getFirstChild();for(;null!==t&&e<i;){if(o(t)){let e=t.getNextSibling();for(;o(e);)e=e.getNextSibling()}e++,t=t.getNextSibling()}return G(c,e,n)}return null}function At(e,t){return V(e,t.doc)}function Ot(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!Q(e,t))return!0;return!1}function Kt(e,t){return{color:t,name:e,selection:null}}function Et(e,t){null!==t.highlight&&(CSS.highlights.delete(t.highlightName),Ct(e,t.highlightName));const n=e.cursorsContainer;if(null===n)return;t.caret.parentNode===n&&n.removeChild(t.caret);const o=t.selections;for(let e=0;e<o.length;e++)o[e].parentNode===n&&n.removeChild(o[e])}function Pt(e,t){const n=t.selection;null!==n&&Et(e,n)}function jt(e,t,n,o,s,i,r,l,c={}){const a=e.color,f=v(t.editor.getRootElement()),u=f.createElement("span");c.cursor?(u.className=c.cursor,w(u.style,{"--lexical-cursor-color":a,bottom:"0",position:"absolute",right:"-1px",top:"0"})):w(u.style,{"background-color":a,bottom:"0",position:"absolute",right:"-1px",top:"0",width:"1px","z-index":"10"});const d=f.createElement("span");d.textContent=e.name,c.cursorName?d.className=c.cursorName:w(d.style,{"background-color":a,color:"#fff","font-family":"Arial","font-size":"12px","font-weight":"bold",left:"-2px","line-height":"12px",padding:"2px",position:"absolute",top:"-16px","white-space":"nowrap"}),u.appendChild(d);const h=`lexical-cursor-${t.id}-${n}`;let g=null;return l&&vt&&(g=new Highlight,CSS.highlights.set(h,g),wt(t,h,a)),{anchor:{key:o,offset:s},caret:u,color:a,focus:{key:i,offset:r},highlight:g,highlightName:h,name:d,selections:[]}}function Lt(e,t,o,s,i={}){const r=e.editor,l=r.getRootElement(),c=e.cursorsContainer;if(null===c||null===l)return;const a=v(l),f=c.offsetParent;if(null===f)return;const u=f.getBoundingClientRect(),d=t.selection;if(null===o)return null===d?void 0:(t.selection=null,void Et(e,d));t.selection=o;const h=o.caret,g=o.color,p=o.highlight,y=o.anchor,_=o.focus,m=y.key,x=_.key,S=s.get(m),b=s.get(x);if(null==S||null==b)return;if(null!==p){const e=oe(r,S,y.offset,b,_.offset);if(null===e)return;p.clear(),e.collapsed||p.add(e);const t=e.cloneRange();t.collapse(!1);let o=t.getBoundingClientRect();if(0===o.height&&n(b)){const e=r.getElementByKey(x);null!==e&&(o=e.getBoundingClientRect())}return w(h.style,{"background-color":i.cursor?"":g,bottom:"",height:`${o.height||16}px`,left:o.left-u.left+"px","pointer-events":"none",position:"absolute",right:"",top:o.top-u.top+"px",width:"1px","z-index":"10"}),void(h.parentNode!==c&&c.appendChild(h))}const T=o.selections;let N;if(S===b&&n(S)){N=[r.getElementByKey(m).getBoundingClientRect()]}else{const e=oe(r,S,y.offset,b,_.offset);if(null===e)return;N=se(r,e)}const k=T.length,C=N.length;for(let e=0;e<C;e++){const t=N[e];let n=T[e];if(void 0===n){n=a.createElement("span"),T[e]=n;const t=a.createElement("span");i.selectionBg&&(t.className=i.selectionBg),n.appendChild(t),c.appendChild(n)}const o=t.top-u.top,s=t.left-u.left,r={height:`${t.height}px`,left:`${s}px`,"pointer-events":"none",position:"absolute",top:`${o}px`,width:`${t.width}px`};i.selection?(n.className=i.selection,w(n.style,{...r,"--lexical-cursor-color":g}),w(n.firstChild.style,{height:"100%",left:"0",position:"absolute",top:"0",width:"100%"})):(w(n.style,r),w(n.firstChild.style,{...r,"background-color":g,left:"0",opacity:"0.3",top:"0","z-index":"5"})),e===C-1&&h.parentNode!==n&&n.appendChild(h)}for(let e=k-1;e>=C;e--){const t=T[e];c.removeChild(t),T.pop()}}function zt(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,i=0,r=null,l=0;if(null!==n&&null!==o){const t=At(n,e),c=At(o,e);null!==t&&null!==c&&([s,i]=Rt(t.type,t.index),[r,l]=Rt(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:i,focusCollabNode:r,focusOffset:l}}function Yt(e,t){const{anchorPos:n,focusPos:s}=t,i=n?At(n,e):null,r=s?At(s,e):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(Se(e)){const[e,t]=Rt(i.type,i.index),[n,o]=Rt(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=$t(e.mapping,i),[a,f]=$t(e.mapping,r);if(a&&l&&(a!==l||f!==c)){const e=a.isBefore(l),t=e?a:l,n=e?f:c;o(t)&&o(t.getNextSibling())&&n===t.getTextContentSize()&&(e?(a=t.getNextSibling(),f=0):(l=t.getNextSibling(),c=0))}return{anchorKey:null!==l?l.getKey():null,anchorOffset:c,focusKey:null!==a?a.getKey():null,focusOffset:f}}function Dt(e,t){const n=t.awareness.getLocalState();if(null===n)return;const{anchorKey:o,anchorOffset:r,focusKey:l,focusOffset:c}=Yt(e,n);if(null!==o&&null!==l){const e=s();if(!i(e))return;It(e.anchor,o,r),It(e.focus,l,c)}}function It(e,n,s){if(e.key!==n||e.offset!==s){let i=t(n);if(null!==i&&!r(i)&&!o(i)){const e=i.getParentOrThrow();n=e.getKey(),s=i.getIndexWithinParent(),i=e}e.set(n,s,r(i)?"element":"text")}}function Rt(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof he){const{node:e,offset:o}=We(n,t,!0);return null===e?[n,n._children.length]:[e,o]}return[null,0]}function $t(e,t){const n=t.type,s=t.index;if(n instanceof j){const t=e.get(n);if(void 0===t)return[null,0];if(!r(t))return[t,s];let i=s,l=0;const c=t.getChildren();for(;i>0&&l<c.length;){const e=c[l];if(i-=1,l+=1,o(e))for(;l<c.length&&o(c[l]);)l+=1}return[t,l]}{const t=e.get(n);if(void 0===t)return[null,0];let o=0,i=s;for(;i>t[o].getTextContentSize()&&o+1<t.length;)i-=t[o].getTextContentSize(),o++;const r=t[o];return[r,Math.min(i,r.getTextContentSize())]}}function Wt(e,t){return t.awareness.getStates()}function Bt(e,t,n){const{getAwarenessStates:o=Wt,selectionHighlight:s=!1}=n??{},i=Array.from(o(e,t)),r=e.clientID,l=e.cursors,c=e.editor,a=c._config.theme.collaboration,f=c._editorState._nodeMap,u=new Set;for(let t=0;t<i.length;t++){const n=i[t],[o,d]=n;if(0!==o&&o!==r){u.add(o);const{name:t,color:n,focusing:i}=d;let r=null,h=l.get(o);if(void 0===h&&(h=Kt(t,n),l.set(o,h)),i){const{anchorKey:t,anchorOffset:n,focusKey:i,focusOffset:l}=c.read(()=>Yt(e,d));if(null!==t&&null!==i)if(r=h.selection,null===r)r=jt(h,e,o,t,n,i,l,s,a);else{const e=r.anchor,o=r.focus;e.key=t,e.offset=n,o.key=i,o.offset=l}}Lt(e,h,r,f,a)}}const d=Array.from(l.keys());for(let t=0;t<d.length;t++){const n=d[t];if(!u.has(n)){const t=l.get(n);void 0!==t&&(Pt(e,t),l.delete(n))}}}function Ut(e,t,n,o){const s=t.awareness,r=s.getLocalState();if(null===r)return;const{anchorPos:l,focusPos:c,name:a,color:f,focusing:u,awarenessData:d}=r;let h=null,g=null;if(null!==o&&(null===l||o.is(n))||null!==n){if(i(o)){const t=o.isCollapsed(),n=!t&&o.isBackward(),s=n?-1:0,i=t||n?0:-1;Se(e)?(h=Ft(o.anchor,e,s),g=Ft(o.focus,e,i)):(h=Mt(o.anchor,e,s),g=Mt(o.focus,e,i))}(Ot(l,h)||Ot(c,g))&&s.setLocalState({...r,anchorPos:h,awarenessData:d,color:f,focusPos:g,focusing:u,name:a})}}function Ht(e,t){if(t instanceof Z&&function(e,t){const{target:n}=t;if(!n._item||"__state"!==n._item.parentSub||void 0!==Pe(n)||!(n.parent instanceof P||n.parent instanceof j||n.parent instanceof L))return!1;const o=je(e,n.parent).getNode();if(o){const e=_(o.getWritable());for(const o of t.keysChanged)e.updateFromUnknown(o,n.get(o))}return!0}(e,t))return;const{target:n}=t;if(t instanceof Z&&n instanceof L&&null!=n._item&&n._item.parentSub===be&&(n.parent instanceof P||n.parent instanceof j)){const t=je(e,n.parent);if(t instanceof he){const n=t.getNode();null!==n&&t.syncSlotsFromYjs(e,n)}else if(t instanceof le){const n=t.getNode();null!==n&&t.syncSlotsFromYjs(e,n)}return}const o=je(e,n);if(o instanceof he&&t instanceof ee){const{keysChanged:n,childListChanged:s,delta:i}=t;if(n.size>0&&o.syncPropertiesFromYjs(e,n),n.has(be)){const t=o.getNode();null!==t&&o.syncSlotsFromYjs(e,t)}s&&(o.applyChildrenYjsDelta(e,i),o.syncChildrenFromYjs(e))}else if(o instanceof ue&&t instanceof Z){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof le&&t instanceof te){const{attributesChanged:n}=t;if(n.size>0&&o.syncPropertiesFromYjs(e,n),n.has(be)){const t=o.getNode();null!==t&&o.syncSlotsFromYjs(e,t)}}else ie(82)}function qt(e,t,n,o,s=Bt){const i=e.editor,r=i._editorState;if(n.forEach(e=>e.delta),i.update(()=>{for(let t=0;t<n.length;t++){const o=n[t];Ht(e,o)}Jt(r,e,t),o||A(O)},{onUpdate:()=>{s(e,t),e.root.isEmpty()&&i.update(()=>Vt())},skipTransforms:!0,tag:o?M:F}),n.length>0){const t=n[0].transaction;q(t,t.deleteSet,t=>{if(t.constructor===X){const n=t.content.type;if(n){const t=n._collabNode;void 0!==t&&e.collabNodeMap.get(t._key)===t&&e.collabNodeMap.delete(t._key)}}})}}function Jt(e,t,n){const o=s();if(i(o))if(Be(o)){const r=e._selection;if(i(r)&&(Dt(t,n),Be(o))){He(o.anchor.key,e)}Ut(t,n,r,s())}else Dt(t,n)}function Vt(){0===x().getChildrenSize()&&x().append(K())}function Gt(e,n,i,r,l,c,a,f){Ue(e,()=>{r.read(()=>{if(f.has(F)||f.has(M))return void(a.size>0&&function(e,n){const s=Array.from(n),i=e.collabNodeMap,r=[],l=[];for(let e=0;e<s.length;e++){const n=s[e],c=t(n),a=i.get(n);if(a instanceof ue)if(o(c))r.push([a,c.__text]);else{const e=a.getOffset();if(-1===e)continue;const t=a._parent;a._normalized=!0,t._xmlText.delete(e,1),l.push(a)}}for(let e=0;e<l.length;e++){const t=l[e],n=t.getKey();i.delete(n);const o=t._parent._children,s=o.indexOf(t);o.splice(s,1)}for(let e=0;e<r.length;e++){const[t,n]=r[e];t._text=n}}(e,a));if(l.has("root")){const t=i._nodeMap,n=x(),o=e.root;o.syncPropertiesFromLexical(e,n,t),o.syncChildrenFromLexical(e,n,t,l,c),o.syncSlotsFromLexical(e,n,t,l,c),0===n.getChildrenSize()&&i._nodeMap.size>1&&e.editor.update(()=>Vt())}const r=s(),u=i._selection;Ut(e,n,u,r)})})}function Qt(e,t){const{target:n}=t;if(n instanceof j&&t instanceof te)Qe(n,e,t.attributesChanged,t.childListChanged);else if(n instanceof P&&t instanceof ee){const t=n.parent;t instanceof j?Qe(t,e,new Set,!0):ie(327)}else if(n instanceof L&&t instanceof Z&&null!=n._item&&n._item.parentSub===be){const t=n.parent;t instanceof j?Qe(t,e,new Set([be]),!1):ie(388)}else ie(328)}function Xt(e,t,n,o,s){const i=e.editor,r=i._editorState;q(o,o.deleteSet,t=>{if(t.constructor===X){const n=t.content.type;n&&e.mapping.delete(n)}}),n.forEach(e=>e.delta),i.update(()=>{for(let t=0;t<n.length;t++){const o=n[t];Qt(e,o)}Jt(r,e,t),s||A(O)},{discrete:!0,onUpdate:()=>{Bt(e,t),0===e.root.length&&i.update(()=>Vt())},skipTransforms:!0,tag:s?M:F})}function Zt(e,t){e.mapping.clear();const n=e.editor;n.update(()=>{x().clear(),Qe(e.root,e,null,!0),A(F)},{discrete:!0,onUpdate:()=>{Bt(e,t),0===e.root.length&&n.update(()=>Vt())},skipTransforms:!0,tag:F})}function en(e,t,n,o,i,r,l,c){const a=c.has(F)||c.has(M);a&&0===l.size||(l.forEach(t=>{e.mapping.deleteNode(t)}),Ue(e,()=>{o.read(()=>{if(i.has("root")){const t=x();St(e.doc,e.root,t,e,new Set([...i.keys(),...r])),!a&&0===t.getChildrenSize()&&n._nodeMap.size>1&&e.editor.update(()=>Vt())}const o=s(),l=n._selection;Ut(e,t,l,o)})}))}const tn=/* @__PURE__ */E("CONNECTED_COMMAND"),nn=/* @__PURE__ */E("TOGGLE_CONNECT_COMMAND"),on=/* @__PURE__ */E("DIFF_VERSIONS_COMMAND"),sn=/* @__PURE__ */E("CLEAR_DIFF_VERSIONS_COMMAND");function rn(e,t){return new ne(t,{trackedOrigins:new Set([e,null])})}function ln(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})}function cn(e,t,n,o,s){const{awareness:i}=e;let r=i.getLocalState();null===r&&(r={anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t}),r.focusing=o,i.setLocalState(r)}export{Yt as $getAnchorAndFocusForUserState,Nt as $getYChangeState,sn as CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL,tn as CONNECTED_COMMAND,on as DIFF_VERSIONS_COMMAND__EXPERIMENTAL,nn as TOGGLE_CONNECT_COMMAND,me as createBinding,xe as createBindingV2__EXPERIMENTAL,rn as createUndoManager,_e as createYjsBinding,zt as getAnchorAndFocusCollabNodesForUserState,ln as initLocalState,Ct as removeCursorHighlightRule,kt as renderSnapshot__EXPERIMENTAL,cn as setLocalStateFocus,Bt as syncCursorPositions,Gt as syncLexicalUpdateToYjs,en as syncLexicalUpdateToYjsV2__EXPERIMENTAL,qt as syncYjsChangesToLexical,Xt as syncYjsChangesToLexicalV2__EXPERIMENTAL,Zt as syncYjsStateToLexicalV2__EXPERIMENTAL};
|
package/dist/index.d.ts
CHANGED
|
@@ -61,8 +61,8 @@ export type Delta = Operation[];
|
|
|
61
61
|
export type YjsNode = Record<string, unknown>;
|
|
62
62
|
export type YjsEvent = Record<string, unknown>;
|
|
63
63
|
export type { Provider };
|
|
64
|
-
export type { BaseBinding, Binding, BindingV2, ClientID, ExcludedProperties, } from './Bindings';
|
|
65
|
-
export { createBinding, createBindingV2__EXPERIMENTAL } from './Bindings';
|
|
64
|
+
export type { BaseBinding, Binding, BindingV2, ClientID, CreateYjsBindingOptions, ExcludedProperties, } from './Bindings';
|
|
65
|
+
export { createBinding, createBindingV2__EXPERIMENTAL, createYjsBinding, } from './Bindings';
|
|
66
66
|
export declare function createUndoManager(binding: BaseBinding, root: XmlText | XmlElement): UndoManager;
|
|
67
67
|
export declare function initLocalState(provider: Provider, name: string, color: string, focusing: boolean, awarenessData: object): void;
|
|
68
68
|
export declare function setLocalStateFocus(provider: Provider, name: string, color: string, focusing: boolean, awarenessData: object): void;
|
package/package.json
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"crdt"
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"version": "0.
|
|
14
|
+
"version": "0.48.0",
|
|
15
15
|
"main": "./dist/LexicalYjs.js",
|
|
16
16
|
"types": "./dist/typescript-too-old.d.ts",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@lexical/internal": "0.
|
|
19
|
-
"lexical": "0.
|
|
20
|
-
"@lexical/selection": "0.
|
|
18
|
+
"@lexical/internal": "0.48.0",
|
|
19
|
+
"lexical": "0.48.0",
|
|
20
|
+
"@lexical/selection": "0.48.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"yjs": "^13.6.31"
|
package/src/Bindings.ts
CHANGED
|
@@ -64,14 +64,10 @@ export type ExcludedProperties = Map<Klass<LexicalNode>, Set<string>>;
|
|
|
64
64
|
function createBaseBinding(
|
|
65
65
|
editor: LexicalEditor,
|
|
66
66
|
id: string,
|
|
67
|
-
doc: Doc
|
|
67
|
+
doc: Doc,
|
|
68
68
|
docMap: Map<string, Doc>,
|
|
69
69
|
excludedProperties?: ExcludedProperties,
|
|
70
70
|
): BaseBinding {
|
|
71
|
-
invariant(
|
|
72
|
-
doc !== undefined && doc !== null,
|
|
73
|
-
'createBinding: doc is null or undefined',
|
|
74
|
-
);
|
|
75
71
|
const binding = {
|
|
76
72
|
clientID: doc.clientID,
|
|
77
73
|
cursorHighlightSheet: null,
|
|
@@ -88,6 +84,46 @@ function createBaseBinding(
|
|
|
88
84
|
return binding;
|
|
89
85
|
}
|
|
90
86
|
|
|
87
|
+
/** Options for {@link createYjsBinding}. */
|
|
88
|
+
export interface CreateYjsBindingOptions {
|
|
89
|
+
editor: LexicalEditor;
|
|
90
|
+
/** Identifier for this binding, used as the key in `docMap`. */
|
|
91
|
+
id: string;
|
|
92
|
+
doc: Doc;
|
|
93
|
+
docMap: Map<string, Doc>;
|
|
94
|
+
excludedProperties?: ExcludedProperties;
|
|
95
|
+
/** The key used to look up the root `XmlText` shared type on the Yjs `Doc`. Defaults to `'root'`. */
|
|
96
|
+
rootName?: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Create a V1 Yjs {@link Binding} that connects a {@link LexicalEditor} to a
|
|
101
|
+
* Yjs `Doc` for real-time collaboration.
|
|
102
|
+
*
|
|
103
|
+
* For the legacy positional-argument API, see {@link createBinding}.
|
|
104
|
+
*/
|
|
105
|
+
export function createYjsBinding({
|
|
106
|
+
editor,
|
|
107
|
+
id,
|
|
108
|
+
doc,
|
|
109
|
+
docMap,
|
|
110
|
+
excludedProperties,
|
|
111
|
+
rootName = 'root',
|
|
112
|
+
}: CreateYjsBindingOptions): Binding {
|
|
113
|
+
const rootXmlText = doc.get(rootName, XmlText) as XmlText;
|
|
114
|
+
const root: CollabElementNode = $createCollabElementNode(
|
|
115
|
+
rootXmlText,
|
|
116
|
+
null,
|
|
117
|
+
'root',
|
|
118
|
+
);
|
|
119
|
+
root._key = 'root';
|
|
120
|
+
return {
|
|
121
|
+
...createBaseBinding(editor, id, doc, docMap, excludedProperties),
|
|
122
|
+
collabNodeMap: new Map(),
|
|
123
|
+
root,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
91
127
|
export function createBinding(
|
|
92
128
|
editor: LexicalEditor,
|
|
93
129
|
provider: Provider,
|
|
@@ -100,18 +136,7 @@ export function createBinding(
|
|
|
100
136
|
doc !== undefined && doc !== null,
|
|
101
137
|
'createBinding: doc is null or undefined',
|
|
102
138
|
);
|
|
103
|
-
|
|
104
|
-
const root: CollabElementNode = $createCollabElementNode(
|
|
105
|
-
rootXmlText,
|
|
106
|
-
null,
|
|
107
|
-
'root',
|
|
108
|
-
);
|
|
109
|
-
root._key = 'root';
|
|
110
|
-
return {
|
|
111
|
-
...createBaseBinding(editor, id, doc, docMap, excludedProperties),
|
|
112
|
-
collabNodeMap: new Map(),
|
|
113
|
-
root,
|
|
114
|
-
};
|
|
139
|
+
return createYjsBinding({doc, docMap, editor, excludedProperties, id});
|
|
115
140
|
}
|
|
116
141
|
|
|
117
142
|
export function createBindingV2__EXPERIMENTAL(
|
package/src/index.ts
CHANGED
|
@@ -81,9 +81,14 @@ export type {
|
|
|
81
81
|
Binding,
|
|
82
82
|
BindingV2,
|
|
83
83
|
ClientID,
|
|
84
|
+
CreateYjsBindingOptions,
|
|
84
85
|
ExcludedProperties,
|
|
85
86
|
} from './Bindings';
|
|
86
|
-
export {
|
|
87
|
+
export {
|
|
88
|
+
createBinding,
|
|
89
|
+
createBindingV2__EXPERIMENTAL,
|
|
90
|
+
createYjsBinding,
|
|
91
|
+
} from './Bindings';
|
|
87
92
|
|
|
88
93
|
export function createUndoManager(
|
|
89
94
|
binding: BaseBinding,
|