@ekz/lexical-yjs 0.40.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.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ 'use strict'
10
+ const EkzLexicalYjs = process.env.NODE_ENV !== 'production' ? require('./EkzLexicalYjs.dev.js') : require('./EkzLexicalYjs.prod.js');
11
+ module.exports = EkzLexicalYjs;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ import * as modDev from './EkzLexicalYjs.dev.mjs';
10
+ import * as modProd from './EkzLexicalYjs.prod.mjs';
11
+ const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
12
+ export const $getYChangeState = mod.$getYChangeState;
13
+ export const CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL = mod.CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL;
14
+ export const CONNECTED_COMMAND = mod.CONNECTED_COMMAND;
15
+ export const DIFF_VERSIONS_COMMAND__EXPERIMENTAL = mod.DIFF_VERSIONS_COMMAND__EXPERIMENTAL;
16
+ export const TOGGLE_CONNECT_COMMAND = mod.TOGGLE_CONNECT_COMMAND;
17
+ export const createBinding = mod.createBinding;
18
+ export const createBindingV2__EXPERIMENTAL = mod.createBindingV2__EXPERIMENTAL;
19
+ export const createUndoManager = mod.createUndoManager;
20
+ export const getAnchorAndFocusCollabNodesForUserState = mod.getAnchorAndFocusCollabNodesForUserState;
21
+ export const initLocalState = mod.initLocalState;
22
+ export const renderSnapshot__EXPERIMENTAL = mod.renderSnapshot__EXPERIMENTAL;
23
+ export const setLocalStateFocus = mod.setLocalStateFocus;
24
+ export const syncCursorPositions = mod.syncCursorPositions;
25
+ export const syncLexicalUpdateToYjs = mod.syncLexicalUpdateToYjs;
26
+ export const syncLexicalUpdateToYjsV2__EXPERIMENTAL = mod.syncLexicalUpdateToYjsV2__EXPERIMENTAL;
27
+ export const syncYjsChangesToLexical = mod.syncYjsChangesToLexical;
28
+ export const syncYjsChangesToLexicalV2__EXPERIMENTAL = mod.syncYjsChangesToLexicalV2__EXPERIMENTAL;
29
+ export const syncYjsStateToLexicalV2__EXPERIMENTAL = mod.syncYjsStateToLexicalV2__EXPERIMENTAL;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ const mod = await (process.env.NODE_ENV !== 'production' ? import('./EkzLexicalYjs.dev.mjs') : import('./EkzLexicalYjs.prod.mjs'));
10
+ export const $getYChangeState = mod.$getYChangeState;
11
+ export const CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL = mod.CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL;
12
+ export const CONNECTED_COMMAND = mod.CONNECTED_COMMAND;
13
+ export const DIFF_VERSIONS_COMMAND__EXPERIMENTAL = mod.DIFF_VERSIONS_COMMAND__EXPERIMENTAL;
14
+ export const TOGGLE_CONNECT_COMMAND = mod.TOGGLE_CONNECT_COMMAND;
15
+ export const createBinding = mod.createBinding;
16
+ export const createBindingV2__EXPERIMENTAL = mod.createBindingV2__EXPERIMENTAL;
17
+ export const createUndoManager = mod.createUndoManager;
18
+ export const getAnchorAndFocusCollabNodesForUserState = mod.getAnchorAndFocusCollabNodesForUserState;
19
+ export const initLocalState = mod.initLocalState;
20
+ export const renderSnapshot__EXPERIMENTAL = mod.renderSnapshot__EXPERIMENTAL;
21
+ export const setLocalStateFocus = mod.setLocalStateFocus;
22
+ export const syncCursorPositions = mod.syncCursorPositions;
23
+ export const syncLexicalUpdateToYjs = mod.syncLexicalUpdateToYjs;
24
+ export const syncLexicalUpdateToYjsV2__EXPERIMENTAL = mod.syncLexicalUpdateToYjsV2__EXPERIMENTAL;
25
+ export const syncYjsChangesToLexical = mod.syncYjsChangesToLexical;
26
+ export const syncYjsChangesToLexicalV2__EXPERIMENTAL = mod.syncYjsChangesToLexicalV2__EXPERIMENTAL;
27
+ export const syncYjsStateToLexicalV2__EXPERIMENTAL = mod.syncYjsStateToLexicalV2__EXPERIMENTAL;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ "use strict";var e=require("@ekz/lexical"),t=require("yjs"),n=require("@ekz/lexical-offset"),o=require("@ekz/lexical-selection");function s(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 i(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 r{_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.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);w(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&s(83);$(e,this._xmlElem,n,t)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function l(e,t,n){const o=new r(e,t,n);return e._collabNode=o,o}class c{_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 a(e,t){const n=new c(e,t);return e._collabNode=n,n}class f{_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 s=this.getPrevNode(o),r=n.__text;if(w(t,this._map,s,n),null!==s){const t=s.__text;if(t!==r){!function(t,n,o,s){const r=e.$getSelection();let l=s.length;if(e.$isRangeSelection(r)&&r.isCollapsed()){const e=r.anchor;e.key===n&&(l=e.offset)}const c=i(o,s,l);t.spliceText(c.index,c.remove,c.insert)}(this,n.__key,t,r),this._text=r}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();null===n&&s(84),$(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 d(e,t,n,o){const s=new f(e,t,n,o);return e._collabNode=s,s}class u{_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 null===e&&s(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&s(91),$(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 l=t[i],a=l.insert,d=l.delete;if(null!=l.retain)o+=l.retain;else if("number"==typeof d){let e=d;for(;e>0;){const{node:t,nodeIndex:s,offset:i,length:l}=K(this,o,!1);if(t instanceof u||t instanceof c||t instanceof r)n.splice(s,1),e-=1;else{if(!(t instanceof f))break;{const o=Math.min(e,l),r=0!==s?n[s-1]:null,c=t.getSize();if(0===i&&l===c){n.splice(s,1);const e=M(t._text,i,o-1,"");e.length>0&&(r instanceof f?r._text+=e:this._xmlText.delete(i,e.length))}else t._text=M(t._text,i,o,"");e-=o}}}}else{if(null==a)throw new Error("Unexpected delta format");if("string"==typeof a){const{node:e,offset:t}=K(this,o,!0);e instanceof f?e._text=M(e._text,t,0,a):this._xmlText.delete(t,a.length),o+=a.length}else{const t=a,{node:i,nodeIndex:r,length:l}=K(this,o,!1),c=C(e,t,this);if(i instanceof f&&l>0&&l<i._text.length){const e=i._text,t=e.length-l;i._text=M(e,t,l,""),n.splice(r+1,0,c),s=M(e,0,t,"")}else n.splice(r,0,c);null!==s&&c instanceof f&&(c._text=s+c._text,s=null),o+=1}}}}syncChildrenFromYjs(t){const o=this.getNode();null===o&&s(92);const i=o.__key,l=n.$createChildrenArray(o,null),a=l.length,d=this._children,h=d.length,p=t.collabNodeMap,g=new Set;let _,y,m=0,x=null;h!==a&&(y=o.getWritable());for(let n=0;n<h;n++){const a=l[m],T=d[n],N=T.getNode(),S=T._key;if(null!==N&&a===S){const n=e.$isTextNode(N);if(g.add(a),n)if(T._key=a,T instanceof u){const e=T._xmlText;T.syncPropertiesFromYjs(t,null),T.applyChildrenYjsDelta(t,e.toDelta()),T.syncChildrenFromYjs(t)}else T instanceof f?T.syncPropertiesAndTextFromYjs(t,null):T instanceof r?T.syncPropertiesFromYjs(t,null):T instanceof c||s(93);x=N,m++}else{if(void 0===_){_=new Set;for(let e=0;e<h;e++){const t=d[e]._key;""!==t&&_.add(t)}}if(null!==N&&void 0!==a&&!_.has(a)){const t=e.$getNodeByKeyOrThrow(a);e.removeFromParent(t),n--,m++;continue}y=o.getWritable();const s=k(t,T,i),r=s.__key;if(p.set(r,T),null===x){const e=y.getFirstChild();if(y.__first=r,null!==e){const t=e.getWritable();t.__prev=r,s.__next=t.__key}}else{const e=x.getWritable(),t=x.getNextSibling();if(e.__next=r,s.__prev=x.__key,null!==t){const e=t.getWritable();e.__prev=r,s.__next=e.__key}}n===h-1&&(y.__last=r),y.__size++,x=s}}for(let n=0;n<a;n++){const o=l[n];if(!g.has(o)){const n=e.$getNodeByKeyOrThrow(o),s=t.collabNodeMap.get(o);void 0!==s&&s.destroy(t),e.removeFromParent(n)}}}syncPropertiesFromLexical(e,t,n){w(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,o,s,i,l){const c=this._children[n],a=e.$getNodeByKeyOrThrow(o);c instanceof u&&e.$isElementNode(a)?(c.syncPropertiesFromLexical(t,a,s),c.syncChildrenFromLexical(t,a,s,i,l)):c instanceof f&&e.$isTextNode(a)?c.syncPropertiesAndTextFromLexical(t,a,s):c instanceof r&&e.$isDecoratorNode(a)&&c.syncPropertiesFromLexical(t,a,s)}syncChildrenFromLexical(t,o,s,i,r){const l=this.getPrevNode(s),c=null===l?[]:n.$createChildrenArray(l,s),a=n.$createChildrenArray(o,null),f=c.length-1,d=a.length-1,u=t.collabNodeMap;let h,p,g=0,_=0;for(;g<=f&&_<=d;){const n=c[g],o=a[_];if(n===o)this._syncChildFromLexical(t,_,o,s,i,r),g++,_++;else{void 0===h&&(h=new Set(c)),void 0===p&&(p=new Set(a));const s=p.has(n),i=h.has(o);if(s){const n=E(t,e.$getNodeByKeyOrThrow(o),this);u.set(o,n),i?(this.splice(t,_,1,n),g++,_++):(this.splice(t,_,0,n),_++)}else this.splice(t,_,1),g++}}const y=g>f,m=_>d;if(y&&!m)for(;_<=d;++_){const n=a[_],o=E(t,e.$getNodeByKeyOrThrow(n),this);this.append(o),u.set(n,o)}else if(m&&!y)for(let e=this._children.length-1;e>=_;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 u)t.insertEmbed(s,e._xmlText);else if(e instanceof f){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof c?t.insertEmbed(s,e._map):e instanceof r&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,o){const i=this._children,l=i[t];if(void 0===l)return void 0===o&&s(94),void this.append(o);const a=l.getOffset();-1===a&&s(95);const d=this._xmlText;if(0!==n&&d.delete(a,l.getSize()),o instanceof u)d.insertEmbed(a,o._xmlText);else if(o instanceof f){const e=o._map;null===e.parent&&d.insertEmbed(a,e),d.insert(a+1,o._text)}else o instanceof c?d.insertEmbed(a,o._map):o instanceof r&&d.insertEmbed(a,o._xmlElem);if(0!==n){const o=i.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e)}void 0!==o?i.splice(t,n,o):i.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);t.get(this._key)===this&&t.delete(this._key)}}function h(e,t,n){const o=new u(e,t,n);return e._collabNode=o,o}class p{_nodeMap=new Map;_sharedTypeToNodeKeys=new Map;_nodeKeyToSharedType=new Map;set(n,o){const i=o instanceof Array;this.delete(n);const r=i?o:[o];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||s(331),0===o.length)return;this._sharedTypeToNodeKeys.set(n,o.map(e=>e.getKey()));for(const e of o)this._nodeMap.set(e.getKey(),e),this._nodeKeyToSharedType.set(e.getKey(),n)}else i&&s(332),e.$isTextNode(o)&&s(333),this._sharedTypeToNodeKeys.set(n,[o.getKey()]),this._nodeMap.set(o.getKey(),o),this._nodeKeyToSharedType.set(o.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,i){null==n&&s(81);const r={clientID:n.clientID,cursors:new Map,cursorsContainer:null,doc:n,docMap:o,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))N(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(r),r}function _(e){return Object.hasOwn(e,"collabNodeMap")}const y=new Set(["__key","__parent","__next","__prev","__state"]),m=new Set(["__first","__last","__size"]),x=new Set(["__cachedText"]),T=new Set(["__text"]);function N(t,n,o){if(y.has(t)||"function"==typeof n[t])return!0;if(e.$isTextNode(n)){if(T.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 S(e,t){const n=e.__type,{nodeProperties:o}=t,i=o.get(n);return void 0===i&&s(330,n),i}function E(n,o,i){const r=o.__type;let c;if(e.$isElementNode(o)){c=h(new t.XmlText,i,r),c.syncPropertiesFromLexical(n,o,null),c.syncChildrenFromLexical(n,o,null,null,null)}else if(e.$isTextNode(o)){c=d(new t.Map,o.__text,i,r),c.syncPropertiesAndTextFromLexical(n,o,null)}else if(e.$isLineBreakNode(o)){const e=new t.Map;e.set("__type","linebreak"),c=a(e,i)}else if(e.$isDecoratorNode(o)){c=l(new t.XmlElement,i,r),c.syncPropertiesFromLexical(n,o,null)}else s(86);return c._key=o.__key,c}function b(e){const t=O(e,"__type");return"string"!=typeof t&&void 0!==t&&s(87),t}function C(e,n,o){const i=n._collabNode;if(void 0===i){const i=e.editor._nodes,r=b(n);"string"!=typeof r&&s(87);void 0===i.get(r)&&s(88,r);const c=n.parent,f=void 0===o&&null!==c?C(e,c):o||null;if(f instanceof u||s(89),n instanceof t.XmlText)return h(n,f,r);if(n instanceof t.Map)return"linebreak"===r?a(n,f):d(n,"",f,r);if(n instanceof t.XmlElement)return l(n,f,r)}return i}function k(e,t,n){const o=t.getType(),i=e.editor._nodes.get(o);void 0===i&&s(88,o);const l=new i.klass;if(l.__parent=n,t._key=l.__key,t instanceof u){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof f?t.syncPropertiesAndTextFromYjs(e,null):t instanceof r&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(l.__key,t),l}function $(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(N(c,s,n)){"__state"===c&&_(n)&&(l||(l=s.getWritable()),A(o,l));continue}const a=s[c];let f=O(o,c);if(a!==f){if(f instanceof t.Doc){const o=n.docMap;a instanceof t.Doc&&o.delete(a.guid);const s=e.createEditor(),i=f.guid;s._key=i,o.set(i,f),f=s}void 0===l&&(l=s.getWritable()),l[c]=f}}}function O(e,n){return e instanceof t.Map?e.get(n):e instanceof t.XmlText||e instanceof t.XmlElement?e.getAttribute(n):e[n]}function v(e,n,o){e instanceof t.Map?e.set(n,o):e.setAttribute(n,o)}function A(n,o){const s=O(n,"__state");s instanceof t.Map&&e.$getWritableNodeState(o).updateFromJSON(s.toJSON())}function w(e,n,o,s){const i=Object.keys(S(s,e)),r=e.editor.constructor;!function(e,n,o,s){const i=s.__state,r=O(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||v(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()})}v(n,c,f)}}}function M(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function K(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 f){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 P(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 L(e,t){e.doc.transact(t,e)}function F(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():F(i.__key,n):e.$getRoot().selectStart()}const I=e=>"UNDEFINED"===e.nodeName,R=(n,o,i,r,l,c,a)=>{let f=o.mapping.get(n);if(f&&i&&0===i.size&&!r)return f;const d=I(n)?e.RootNode.getType():n.nodeName,u=o.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=R(n,o,new Set,!1,l,c,a);null!==t&&e.push(t)}else if(n instanceof t.XmlText){const t=X(n,o,l,c,a);null!==t&&t.forEach(t=>{null!==t&&e.push(t)})}else s(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||D(e._item,l)||D(e._item,c)).forEach(i),j(f,e)}const h=n.getAttributes(l);I(n)||void 0===l||(D(n._item,l)?D(n._item,c)||(h[ee("ychange")]=a?a("added",n._item.id):{type:"added"}):h[ee("ychange")]=a?a("removed",n._item.id):{type:"removed"});const p={...S(f,o)},g={};for(const e in h)e.startsWith(Z)?g[te(e)]=h[e]:p[e]=h[e];if($(o,p,f,i),i){const t=Object.keys(g).filter(e=>i.has(ee(e)));if(t.length>0){const n=e.$getWritableNodeState(f);for(const e of t)n.updateFromUnknown(e,g[e])}}else e.$getWritableNodeState(f).updateFromJSON(g);const _=f.getLatest();return o.mapping.set(n,_),_},j=(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,[])},D=(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),X=(t,n,o,s,i)=>{const r=J(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={...S(o,n),...i.p},f=Object.fromEntries(Object.entries(i).filter(([e])=>e.startsWith(Z)).map(([e,t])=>[te(e),t]));$(n,a,o,null),e.$getWritableNodeState(o).updateFromJSON(f)}const a=l.map(e=>e.getLatest());return n.mapping.set(t,a),a},z=(n,o)=>n instanceof Array?((e,n)=>{const o=new t.XmlText;return H(o,e,n),o})(n,o):((n,o)=>{const s=new t.XmlElement(n.getType()),i={...Q(n,o),...ne(n)};for(const e in i){const t=i[e];null!==t&&s.setAttribute(e,t)}return n instanceof e.ElementNode?(s.insert(0,U(n).map(e=>z(e,o))),o.mapping.set(s,n),s):s})(n,o),Y=e=>"object"==typeof e&&null!=e,B=(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||Y(r)&&Y(l)&&B(r,l)}return o},U=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},W=(t,n,o)=>{const s=J(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(Z)));return t.insert===i.getTextContent()&&r===i.getType()&&B(l,Q(i,o))&&B(c,ne(i))})},G=(e,n,o)=>{if(e instanceof t.XmlElement&&!(n instanceof Array)&&se(e,n)){const t=U(n);return e._length===t.length&&B(e.getAttributes(),{...Q(n,o),...ne(n)})&&e.toArray().every((e,n)=>G(e,t[n],o))}return e instanceof t.XmlText&&n instanceof Array&&W(e,n,o)},V=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),q=(e,n,o)=>{const s=e.toArray(),i=U(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(V(o.mapping.get(e),n))d=!0;else if(!G(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(V(o.mapping.get(e),n))d=!0;else if(!G(e,n,o))break}return{equalityFactor:a+f,foundMappedChild:d}},H=(n,o,s)=>{s.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 i=Q(t,s);return 0===Object.keys(i).length&&(i=null),{attributes:Object.assign({},r,{...o!==e.TextNode.getType()&&{t:o},p:i,...ne(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:p}=i(l,a,d);n.delete(p,h),n.insert(p,u),n.applyDelta(c.map(e=>({attributes:e.attributes,retain:e.insert.length})))},J=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>{const t=e.attributes??{};return"ychange"in t&&(t[ee("ychange")]=t.ychange,delete t.ychange),{...e,attributes:t}}),Q=(e,t)=>{const n=S(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},Z="s_",ee=e=>`s_${e}`,te=e=>{if(!e.startsWith(Z))throw new Error(`Invalid state key: ${e}`);return e.slice(Z.length)},ne=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[ee(e)]=t;for(const[e,t]of o)s[ee(e.key)]=e.unparse(t);return s},oe=(n,o,s,i,r)=>{if(o instanceof t.XmlElement&&o.nodeName!==s.getType()&&(!I(o)||s.getType()!==e.RootNode.getType()))throw new Error("node name mismatch!");if(i.mapping.set(o,s),o instanceof t.XmlElement){const e=o.getAttributes(),t={...Q(s,i),...ne(s)};for(const n in t)if(null!=t[n]){e[n]===t[n]||Y(e[n])&&Y(t[n])&&B(e[n],t[n])||"ychange"===n||o.setAttribute(n,t[n])}else o.removeAttribute(n);for(const n in e)void 0===t[n]&&o.removeAttribute(n)}const l=U(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(V(i.mapping.get(o),s))s instanceof e.ElementNode&&r.has(s.getKey())&&oe(n,o,s,i,r);else{if(!G(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(V(i.mapping.get(o),s))s instanceof e.ElementNode&&r.has(s.getKey())&&oe(n,o,s,i,r);else{if(!G(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],p=l[c-h-1];if(e instanceof t.XmlText&&s instanceof Array)W(e,s,i)||H(e,s,i),u+=1;else{let l=e instanceof t.XmlElement&&se(e,s),c=d instanceof t.XmlElement&&se(d,p);if(l&&c){const t=q(e,s,i),n=q(d,p,i);t.foundMappedChild&&!n.foundMappedChild?c=!1:!t.foundMappedChild&&n.foundMappedChild||t.equalityFactor<n.equalityFactor?l=!1:c=!1}l?(oe(n,e,s,i,r),u+=1):c?(oe(n,d,p,i,r),h+=1):(i.mapping.delete(o.get(u)),o.delete(u,1),o.insert(u,[z(s,i)]),u+=1)}}const p=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)):p>0&&(o.slice(u,u+p).forEach(e=>i.mapping.delete(e)),o.delete(u,p)),u+h<c){const e=[];for(let t=u;t<c-h;t++)e.push(z(l[t],i));o.insert(u,e)}},se=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType(),ie=e.createState("ychange",{isEqual:(e,t)=>e===t,parse:e=>e??null});function re(n,o){const i=o.collabNodeMap.get(n.key);if(void 0===i)return null;let r=n.offset,l=i.getSharedType();if(i instanceof f){l=i._parent._xmlText;const e=i.getOffset();if(-1===e)return null;r=e+1+r}else if(i instanceof u&&"element"===n.type){const t=n.getNode();e.$isElementNode(t)||s(184);let o=0,i=0,l=t.getFirstChild();for(;null!==l&&i++<r;)e.$isTextNode(l)?o+=l.getTextContentSize()+1:o++,l=l.getNextSibling();r=o}return t.createRelativePositionFromTypeIndex(l,r)}function le(n,o){const{mapping:i}=o,{offset:r}=n,l=n.getNode(),c=i.getSharedType(l);if(void 0===c)return null;if("text"===n.type){e.$isTextNode(l)||s(326);let n=l.getPreviousSibling(),o=r;for(;e.$isTextNode(n);)o+=n.getTextContentSize(),n=n.getPreviousSibling();return t.createRelativePositionFromTypeIndex(c,o)}if("element"===n.type){e.$isElementNode(l)||s(184);let n=0,o=l.getFirstChild();for(;null!==o&&n<r;){if(e.$isTextNode(o)){let t=o.getNextSibling();for(;e.$isTextNode(t);)t=t.getNextSibling()}n++,o=o.getNextSibling()}return t.createRelativePositionFromTypeIndex(c,n)}return null}function ce(e,n){return t.createAbsolutePositionFromRelativePosition(e,n.doc)}function ae(e,n){if(null==e){if(null!=n)return!0}else if(null==n||!t.compareRelativePositions(e,n))return!0;return!1}function fe(e,t){return{color:t,name:e,selection:null}}function de(e,t){const n=e.cursorsContainer;if(null!==n){const e=t.selections,o=e.length;for(let t=0;t<o;t++)n.removeChild(e[t])}}function ue(e,t){const n=t.selection;null!==n&&de(e,n)}function he(e,t,n,o,s){const i=e.color,r=document.createElement("span");r.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${i};z-index:10;`;const l=document.createElement("span");return l.textContent=e.name,l.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${i};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`,r.appendChild(l),{anchor:{key:t,offset:n},caret:r,color:i,focus:{key:o,offset:s},name:l,selections:[]}}function pe(t,n,s,i){const r=t.editor,l=r.getRootElement(),c=t.cursorsContainer;if(null===c||null===l)return;const a=c.offsetParent;if(null===a)return;const f=a.getBoundingClientRect(),d=n.selection;if(null===s)return null===d?void 0:(n.selection=null,void de(t,d));n.selection=s;const u=s.caret,h=s.color,p=s.selections,g=s.anchor,_=s.focus,y=g.key,m=_.key,x=i.get(y),T=i.get(m);if(null==x||null==T)return;let N;if(x===T&&e.$isLineBreakNode(x)){N=[r.getElementByKey(y).getBoundingClientRect()]}else{const e=o.createDOMRange(r,x,g.offset,T,_.offset);if(null===e)return;N=o.createRectsFromDOMRange(r,e)}const S=p.length,E=N.length;for(let e=0;e<E;e++){const t=N[e];let n=p[e];if(void 0===n){n=document.createElement("span"),p[e]=n;const t=document.createElement("span");n.appendChild(t),c.appendChild(n)}const o=`position:absolute;top:${t.top-f.top}px;left:${t.left-f.left}px;height:${t.height}px;width:${t.width}px;pointer-events:none;z-index:5;`;n.style.cssText=o,n.firstChild.style.cssText=`${o}left:0;top:0;background-color:${h};opacity:0.3;`,e===E-1&&u.parentNode!==n&&n.appendChild(u)}for(let e=S-1;e>=E;e--){const t=p[e];c.removeChild(t),p.pop()}}function ge(t,n){const{anchorPos:o,focusPos:s}=n,i=o?ce(o,t):null,r=s?ce(s,t):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(_(t)){const[e,t]=me(i.type,i.index),[n,o]=me(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=xe(t.mapping,i),[a,f]=xe(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 _e(t,n){const o=n.awareness.getLocalState();if(null===o)return;const{anchorKey:s,anchorOffset:i,focusKey:r,focusOffset:l}=ge(t,o);if(null!==s&&null!==r){const t=e.$getSelection();if(!e.$isRangeSelection(t))return;ye(t.anchor,s,i),ye(t.focus,r,l)}}function ye(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 me(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof u){const{node:e,offset:o}=K(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function xe(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 Te(e,t){return t.awareness.getStates()}function Ne(e,t,n){const{getAwarenessStates:o=Te}=n??{},s=Array.from(o(e,t)),i=e.clientID,r=e.cursors,l=e.editor,c=l._editorState._nodeMap,a=new Set;for(let t=0;t<s.length;t++){const n=s[t],[o,f]=n;if(0!==o&&o!==i){a.add(o);const{name:t,color:n,focusing:s}=f;let i=null,d=r.get(o);if(void 0===d&&(d=fe(t,n),r.set(o,d)),s){const{anchorKey:t,anchorOffset:n,focusKey:o,focusOffset:s}=l.read(()=>ge(e,f));if(null!==t&&null!==o)if(i=d.selection,null===i)i=he(d,t,n,o,s);else{const e=i.anchor,r=i.focus;e.key=t,e.offset=n,r.key=o,r.offset=s}}pe(e,d,i,c)}}const f=Array.from(r.keys());for(let t=0;t<f.length;t++){const n=f[t];if(!a.has(n)){const t=r.get(n);void 0!==t&&(ue(e,t),r.delete(n))}}}function Se(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,p=null;(null!==s&&(null===l||s.is(o))||null!==o)&&(e.$isRangeSelection(s)&&(_(t)?(h=re(s.anchor,t),p=re(s.focus,t)):(h=le(s.anchor,t),p=le(s.focus,t))),(ae(l,h)||ae(c,p))&&i.setLocalState({...r,anchorPos:h,awarenessData:u,color:f,focusPos:p,focusing:d,name:a}))}function Ee(n,o){if(o instanceof t.YMapEvent&&function(n,o){const{target:s}=o;if(!s._item||"__state"!==s._item.parentSub||void 0!==b(s)||!(s.parent instanceof t.XmlText||s.parent instanceof t.XmlElement||s.parent instanceof t.Map))return!1;const i=C(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,o))return;const{target:i}=o,l=C(n,i);if(l instanceof u&&o instanceof t.YTextEvent){const{keysChanged:e,childListChanged:t,delta:s}=o;e.size>0&&l.syncPropertiesFromYjs(n,e),t&&(l.applyChildrenYjsDelta(n,s),l.syncChildrenFromYjs(n))}else if(l instanceof f&&o instanceof t.YMapEvent){const{keysChanged:e}=o;e.size>0&&l.syncPropertiesAndTextFromYjs(n,e)}else if(l instanceof r&&o instanceof t.YXmlEvent){const{attributesChanged:e}=o;e.size>0&&l.syncPropertiesFromYjs(n,e)}else s(82)}function be(t,n,o){const s=e.$getSelection();if(e.$isRangeSelection(s))if(P(s)){const i=t._selection;if(e.$isRangeSelection(i)&&(_e(n,o),P(s))){F(s.anchor.key,t)}Se(n,o,i,e.$getSelection())}else _e(n,o)}function Ce(){0===e.$getRoot().getChildrenSize()&&e.$getRoot().append(e.$createParagraphNode())}function ke(e,n){const{target:o}=n;if(o instanceof t.XmlElement&&n instanceof t.YXmlEvent)R(o,e,n.attributesChanged,n.childListChanged);else if(o instanceof t.XmlText&&n instanceof t.YTextEvent){const n=o.parent;n instanceof t.XmlElement?R(n,e,new Set,!0):s(327)}else s(328)}const $e=e.createCommand("CONNECTED_COMMAND"),Oe=e.createCommand("TOGGLE_CONNECT_COMMAND"),ve=e.createCommand("DIFF_VERSIONS_COMMAND"),Ae=e.createCommand("CLEAR_DIFF_VERSIONS_COMMAND");exports.$getYChangeState=function(t){return e.$getState(t,ie)},exports.CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL=Ae,exports.CONNECTED_COMMAND=$e,exports.DIFF_VERSIONS_COMMAND__EXPERIMENTAL=ve,exports.TOGGLE_CONNECT_COMMAND=Oe,exports.createBinding=function(e,n,o,i,r,l){null==i&&s(81);const c=h(i.get("root",t.XmlText),null,"root");return c._key="root",{...g(e,o,i,r,l),collabNodeMap:new Map,root:c}},exports.createBindingV2__EXPERIMENTAL=function(e,n,o,i,r={}){null==o&&s(81);const{excludedProperties:l,rootName:c="root-v2"}=r;return{...g(e,n,o,i,l),mapping:new p,root:o.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=ce(n,e),c=ce(o,e);null!==t&&null!==c&&([s,i]=me(t.type,t.index),[r,l]=me(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.renderSnapshot__EXPERIMENTAL=(n,o=t.snapshot(n.doc),i=t.emptySnapshot)=>{const{doc:r}=n;r.gc&&s(325),r.transact(s=>{const l=new t.PermanentUserData(r);l&&l.dss.forEach(e=>{t.iterateDeletedStructs(s,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(),R(n.root,n,null,!0,o,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=Ne,exports.syncLexicalUpdateToYjs=function(t,n,o,s,i,r,l,c){L(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 f)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)}const s=e.$getSelection(),a=o._selection;Se(t,n,a,s)})})},exports.syncLexicalUpdateToYjsV2__EXPERIMENTAL=function(t,n,o,s,i,r,l){(l.has(e.COLLABORATION_TAG)||l.has(e.HISTORIC_TAG))&&0===r.size||(r.forEach(e=>{t.mapping.deleteNode(e)}),L(t,()=>{s.read(()=>{i.has("root")&&oe(t.doc,t.root,e.$getRoot(),t,new Set(i.keys()));const s=e.$getSelection(),r=o._selection;Se(t,n,r,s)})}))},exports.syncYjsChangesToLexical=function(t,n,o,s,i=Ne){const r=t.editor,l=r._editorState;o.forEach(e=>e.delta),r.update(()=>{for(let e=0;e<o.length;e++){const n=o[e];Ee(t,n)}be(l,t,n),s||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{onUpdate:()=>{i(t,n),r.update(()=>Ce())},skipTransforms:!0,tag:s?e.HISTORIC_TAG:e.COLLABORATION_TAG})},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];ke(n,t)}be(c,n,o),r||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{discrete:!0,onUpdate:()=>{Ne(n,o),l.update(()=>Ce())},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(),R(t.root,t,null,!0),e.$addUpdateTag(e.COLLABORATION_TAG)},{discrete:!0,onUpdate:()=>{Ne(t,n),o.update(()=>Ce())},skipTransforms:!0,tag:e.COLLABORATION_TAG})};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ import{$isDecoratorNode as e,$getNodeByKey as t,$isLineBreakNode as n,$isTextNode as o,$getSelection as s,$isRangeSelection as i,$isElementNode as r,$getNodeByKeyOrThrow as l,removeFromParent as c,createEditor as a,$isRootNode as f,$getWritableNodeState as d,$getRoot as u,RootNode as h,ElementNode as p,TextNode as g,$getState as _,createState as y,COLLABORATION_TAG as m,HISTORIC_TAG as x,$addUpdateTag as T,SKIP_SCROLL_INTO_VIEW_TAG as b,$createParagraphNode as k,createCommand as S}from"@ekz/lexical";import{XmlText as N,XmlElement as v,Map as w,Doc as C,typeListToArraySnapshot as O,Snapshot as K,isDeleted as M,XmlHook as E,ContentString as P,ContentFormat as F,snapshot as A,emptySnapshot as j,PermanentUserData as z,iterateDeletedStructs as L,createAbsolutePositionFromRelativePosition as D,createRelativePositionFromTypeIndex as Y,compareRelativePositions as I,Item as $,YMapEvent as W,YTextEvent as U,YXmlEvent as R,UndoManager as B}from"yjs";import{$createChildrenArray as q}from"@ekz/lexical-offset";import{createDOMRange as J,createRectsFromDOMRange as G}from"@ekz/lexical-selection";function V(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 H(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 Q{_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.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);Ne(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&V(83);Te(e,this._xmlElem,n,t)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function X(e,t,n){const o=new Q(e,t,n);return e._collabNode=o,o}class Z{_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 ee(e,t){const n=new Z(e,t);return e._collabNode=n,n}class te{_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(Ne(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=H(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();null===n&&V(84),Te(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 ne(e,t,n,o){const s=new te(e,t,n,o);return e._collabNode=s,s}class oe{_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 null===e&&V(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&V(91),Te(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 oe||t instanceof Z||t instanceof Q)n.splice(s,1),e-=1;else{if(!(t instanceof te))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=ve(t._text,i,o-1,"");e.length>0&&(l instanceof te?l._text+=e:this._xmlText.delete(i,e.length))}else t._text=ve(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 te?e._text=ve(e._text,t,0,l):this._xmlText.delete(t,l.length),o+=l.length}else{const t=l,{node:i,nodeIndex:r,length:c}=we(this,o,!1),a=me(e,t,this);if(i instanceof te&&c>0&&c<i._text.length){const e=i._text,t=e.length-c;i._text=ve(e,t,c,""),n.splice(r+1,0,a),s=ve(e,0,t,"")}else n.splice(r,0,a);null!==s&&a instanceof te&&(a._text=s+a._text,s=null),o+=1}}}}syncChildrenFromYjs(e){const t=this.getNode();null===t&&V(92);const n=t.__key,s=q(t,null),i=s.length,r=this._children,a=r.length,f=e.collabNodeMap,d=new Set;let u,h,p=0,g=null;a!==i&&(h=t.getWritable());for(let i=0;i<a;i++){const _=s[p],y=r[i],m=y.getNode(),x=y._key;if(null!==m&&_===x){const t=o(m);if(d.add(_),t)if(y._key=_,y instanceof oe){const t=y._xmlText;y.syncPropertiesFromYjs(e,null),y.applyChildrenYjsDelta(e,t.toDelta()),y.syncChildrenFromYjs(e)}else y instanceof te?y.syncPropertiesAndTextFromYjs(e,null):y instanceof Q?y.syncPropertiesFromYjs(e,null):y instanceof Z||V(93);g=m,p++}else{if(void 0===u){u=new Set;for(let e=0;e<a;e++){const t=r[e]._key;""!==t&&u.add(t)}}if(null!==m&&void 0!==_&&!u.has(_)){const e=l(_);c(e),i--,p++;continue}h=t.getWritable();const o=xe(e,y,n),s=o.__key;if(f.set(s,y),null===g){const e=h.getFirstChild();if(h.__first=s,null!==e){const t=e.getWritable();t.__prev=s,o.__next=t.__key}}else{const e=g.getWritable(),t=g.getNextSibling();if(e.__next=s,o.__prev=g.__key,null!==t){const e=t.getWritable();e.__prev=s,o.__next=e.__key}}i===a-1&&(h.__last=s),h.__size++,g=o}}for(let t=0;t<i;t++){const n=s[t];if(!d.has(n)){const t=l(n),o=e.collabNodeMap.get(n);void 0!==o&&o.destroy(e),c(t)}}}syncPropertiesFromLexical(e,t,n){Ne(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,s,i,c,a){const f=this._children[n],d=l(s);f instanceof oe&&r(d)?(f.syncPropertiesFromLexical(t,d,i),f.syncChildrenFromLexical(t,d,i,c,a)):f instanceof te&&o(d)?f.syncPropertiesAndTextFromLexical(t,d,i):f instanceof Q&&e(d)&&f.syncPropertiesFromLexical(t,d,i)}syncChildrenFromLexical(e,t,n,o,s){const i=this.getPrevNode(n),r=null===i?[]:q(i,n),c=q(t,null),a=r.length-1,f=c.length-1,d=e.collabNodeMap;let u,h,p=0,g=0;for(;p<=a&&g<=f;){const t=r[p],i=c[g];if(t===i)this._syncChildFromLexical(e,g,i,n,o,s),p++,g++;else{void 0===u&&(u=new Set(r)),void 0===h&&(h=new Set(c));const n=h.has(t),o=u.has(i);if(n){const t=_e(e,l(i),this);d.set(i,t),o?(this.splice(e,g,1,t),p++,g++):(this.splice(e,g,0,t),g++)}else this.splice(e,g,1),p++}}const _=p>a,y=g>f;if(_&&!y)for(;g<=f;++g){const t=c[g],n=_e(e,l(t),this);this.append(n),d.set(t,n)}else if(y&&!_)for(let t=this._children.length-1;t>=g;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 oe)t.insertEmbed(s,e._xmlText);else if(e instanceof te){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof Z?t.insertEmbed(s,e._map):e instanceof Q&&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 0===o&&V(94),void this.append(o);const r=i.getOffset();-1===r&&V(95);const l=this._xmlText;if(0!==n&&l.delete(r,i.getSize()),o instanceof oe)l.insertEmbed(r,o._xmlText);else if(o instanceof te){const e=o._map;null===e.parent&&l.insertEmbed(r,e),l.insert(r+1,o._text)}else o instanceof Z?l.insertEmbed(r,o._map):o instanceof Q&&l.insertEmbed(r,o._xmlElem);if(0!==n){const o=s.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e)}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);t.get(this._key)===this&&t.delete(this._key)}}function se(e,t,n){const o=new oe(e,t,n);return e._collabNode=o,o}class ie{_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 N){if(n||V(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&&V(332),o(t)&&V(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 N){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 re(e,t,n,o,s){null==n&&V(81);const i={clientID:n.clientID,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))pe(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(i),i}function le(e,t,n,o,s,i){null==o&&V(81);const r=se(o.get("root",N),null,"root");return r._key="root",{...re(e,n,o,s,i),collabNodeMap:new Map,root:r}}function ce(e,t,n,o,s={}){null==n&&V(81);const{excludedProperties:i,rootName:r="root-v2"}=s;return{...re(e,t,n,o,i),mapping:new ie,root:n.get(r,v)}}function ae(e){return Object.hasOwn(e,"collabNodeMap")}const fe=new Set(["__key","__parent","__next","__prev","__state"]),de=new Set(["__first","__last","__size"]),ue=new Set(["__cachedText"]),he=new Set(["__text"]);function pe(e,t,n){if(fe.has(e)||"function"==typeof t[e])return!0;if(o(t)){if(he.has(e))return!0}else if(r(t)&&(de.has(e)||f(t)&&ue.has(e)))return!0;const s=t.constructor,i=n.excludedProperties.get(s);return null!=i&&i.has(e)}function ge(e,t){const n=e.__type,{nodeProperties:o}=t,s=o.get(n);return void 0===s&&V(330,n),s}function _e(t,s,i){const l=s.__type;let c;if(r(s)){c=se(new N,i,l),c.syncPropertiesFromLexical(t,s,null),c.syncChildrenFromLexical(t,s,null,null,null)}else if(o(s)){c=ne(new w,s.__text,i,l),c.syncPropertiesAndTextFromLexical(t,s,null)}else if(n(s)){const e=new w;e.set("__type","linebreak"),c=ee(e,i)}else if(e(s)){c=X(new v,i,l),c.syncPropertiesFromLexical(t,s,null)}else V(86);return c._key=s.__key,c}function ye(e){const t=be(e,"__type");return"string"!=typeof t&&void 0!==t&&V(87),t}function me(e,t,n){const o=t._collabNode;if(void 0===o){const o=e.editor._nodes,s=ye(t);"string"!=typeof s&&V(87);void 0===o.get(s)&&V(88,s);const i=t.parent,r=void 0===n&&null!==i?me(e,i):n||null;if(r instanceof oe||V(89),t instanceof N)return se(t,r,s);if(t instanceof w)return"linebreak"===s?ee(t,r):ne(t,"",r,s);if(t instanceof v)return X(t,r,s)}return o}function xe(e,t,n){const o=t.getType(),s=e.editor._nodes.get(o);void 0===s&&V(88,o);const i=new s.klass;if(i.__parent=n,t._key=i.__key,t instanceof oe){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof te?t.syncPropertiesAndTextFromYjs(e,null):t instanceof Q&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(i.__key,t),i}function Te(e,t,n,o){const s=null===o?t instanceof w?Array.from(t.keys()):t instanceof N||t instanceof v?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(pe(r,n,e)){"__state"===r&&ae(e)&&(i||(i=n.getWritable()),Se(t,i));continue}const l=n[r];let c=be(t,r);if(l!==c){if(c instanceof C){const t=e.docMap;l instanceof C&&t.delete(l.guid);const n=a(),o=c.guid;n._key=o,t.set(o,c),c=n}void 0===i&&(i=n.getWritable()),i[r]=c}}}function be(e,t){return e instanceof w?e.get(t):e instanceof N||e instanceof v?e.getAttribute(t):e[t]}function ke(e,t,n){e instanceof w?e.set(t,n):e.setAttribute(t,n)}function Se(e,t){const n=be(e,"__state");n instanceof w&&d(t).updateFromJSON(n.toJSON())}function Ne(e,t,n,o){const s=Object.keys(ge(o,e)),i=e.editor.constructor;!function(e,t,n,o){const s=o.__state,i=be(t,"__state");if(!s)return;const[r,l]=s.getInternalState(),c=n&&n.__state,a=i instanceof w?i:new w;if(c===s)return;const[f,d]=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)d.get(e)!==t&&a.set(e.key,e.unparse(t));i||ke(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 C,r=s.guid;a._key=r,t.set(r,s),a=s,e.editor.update(()=>{o.markDirty()})}ke(t,l,a)}}}function ve(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 te){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 Ce(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 Oe(e,t){e.doc.transact(t,e)}function Ke(e,n){const o=n._nodeMap.get(e);if(!o)return void u().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():Ke(i.__key,n):u().selectStart()}const Me=e=>"UNDEFINED"===e.nodeName,Ee=(e,t,n,o,s,i,r)=>{let l=t.mapping.get(e);if(l&&n&&0===n.size&&!o)return l;const c=Me(e)?h.getType():e.nodeName,a=t.editor._nodes.get(c);if(void 0===a)throw new Error(`$createOrUpdateNodeFromYElement: Node ${c} is not registered`);if(l||(l=new a.klass,n=null,o=!0),o&&l instanceof p){const n=[],o=e=>{if(e instanceof v){const o=Ee(e,t,new Set,!1,s,i,r);null!==o&&n.push(o)}else if(e instanceof N){const o=Ae(e,t,s,i,r);null!==o&&o.forEach(e=>{null!==e&&n.push(e)})}else V(329)};void 0===s||void 0===i?e.toArray().forEach(o):O(e,new K(i.ds,s.sv)).filter(e=>!e._item.deleted||Fe(e._item,s)||Fe(e._item,i)).forEach(o),Pe(l,n)}const f=e.getAttributes(s);Me(e)||void 0===s||(Fe(e._item,s)?Fe(e._item,i)||(f[Je("ychange")]=r?r("added",e._item.id):{type:"added"}):f[Je("ychange")]=r?r("removed",e._item.id):{type:"removed"});const u={...ge(l,t)},g={};for(const e in f)e.startsWith(qe)?g[Ge(e)]=f[e]:u[e]=f[e];if(Te(t,u,l,n),n){const e=Object.keys(g).filter(e=>n.has(Je(e)));if(e.length>0){const t=d(l);for(const n of e)t.updateFromUnknown(n,g[n])}}else d(l).updateFromJSON(g);const _=l.getLatest();return t.mapping.set(e,_),_},Pe=(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,[])},Fe=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!M(t.ds,e.id),Ae=(e,t,n,s,i)=>{const r=Re(e,n,s,i);let l=t.mapping.get(e)??[];const c=r.map(e=>e.attributes.t??g.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={...ge(n,t),...s.p},a=Object.fromEntries(Object.entries(s).filter(([e])=>e.startsWith(qe)).map(([e,t])=>[Ge(e),t]));Te(t,c,n,null),d(n).updateFromJSON(a)}const a=l.map(e=>e.getLatest());return t.mapping.set(e,a),a},je=(e,t)=>e instanceof Array?((e,t)=>{const n=new N;return Ue(n,e,t),n})(e,t):((e,t)=>{const n=new v(e.getType()),o={...Be(e,t),...Ve(e)};for(const e in o){const t=o[e];null!==t&&n.setAttribute(e,t)}return e instanceof p?(n.insert(0,De(e).map(e=>je(e,t))),t.mapping.set(n,e),n):n})(e,t),ze=e=>"object"==typeof e&&null!=e,Le=(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||ze(r)&&ze(l)&&Le(r,l)}return o},De=e=>{if(!(e instanceof p))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},Ye=(e,t,n)=>{const o=Re(e);return o.length===t.length&&o.every((e,o)=>{const s=t[o],i=e.attributes.t??g.getType(),r=e.attributes.p??{},l=Object.fromEntries(Object.entries(e.attributes).filter(([e])=>e.startsWith(qe)));return e.insert===s.getTextContent()&&i===s.getType()&&Le(r,Be(s,n))&&Le(l,Ve(s))})},Ie=(e,t,n)=>{if(e instanceof v&&!(t instanceof Array)&&Qe(e,t)){const o=De(t);return e._length===o.length&&Le(e.getAttributes(),{...Be(t,n),...Ve(t)})&&e.toArray().every((e,t)=>Ie(e,o[t],n))}return e instanceof N&&t instanceof Array&&Ye(e,t,n)},$e=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),We=(e,t,n)=>{const o=e.toArray(),s=De(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 E)break;if($e(n.mapping.get(e),t))f=!0;else if(!Ie(e,t,n))break}for(;c+a<l;a++){const e=o[r-a-1],t=s[i-a-1];if(e instanceof E)break;if($e(n.mapping.get(e),t))f=!0;else if(!Ie(e,t,n))break}return{equalityFactor:c+a,foundMappedChild:f}},Ue=(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 P?t+=n.content.str:n.content instanceof F&&(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=Be(e,n);return 0===Object.keys(i).length&&(i=null),{attributes:Object.assign({},o,{...s!==g.getType()&&{t:s},p:i,...Ve(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:d,remove:u,index:h}=H(r,c,f);e.delete(h,u),e.insert(h,d),e.applyDelta(l.map(e=>({attributes:e.attributes,retain:e.insert.length})))},Re=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>{const t=e.attributes??{};return"ychange"in t&&(t[Je("ychange")]=t.ychange,delete t.ychange),{...e,attributes:t}}),Be=(e,t)=>{const n=ge(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},qe="s_",Je=e=>`s_${e}`,Ge=e=>{if(!e.startsWith(qe))throw new Error(`Invalid state key: ${e}`);return e.slice(qe.length)},Ve=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[Je(e)]=t;for(const[e,t]of o)s[Je(e.key)]=e.unparse(t);return s},He=(e,t,n,o,s)=>{if(t instanceof v&&t.nodeName!==n.getType()&&(!Me(t)||n.getType()!==h.getType()))throw new Error("node name mismatch!");if(o.mapping.set(t,n),t instanceof v){const e=t.getAttributes(),s={...Be(n,o),...Ve(n)};for(const n in s)if(null!=s[n]){e[n]===s[n]||ze(e[n])&&ze(s[n])&&Le(e[n],s[n])||"ychange"===n||t.setAttribute(n,s[n])}else t.removeAttribute(n);for(const n in e)void 0===s[n]&&t.removeAttribute(n)}const i=De(n),r=i.length,l=t.toArray(),c=l.length,a=Math.min(r,c);let f=0,d=0;for(;f<a;f++){const t=l[f],n=i[f];if(t instanceof E)break;if($e(o.mapping.get(t),n))n instanceof p&&s.has(n.getKey())&&He(e,t,n,o,s);else{if(!Ie(t,n,o))break;o.mapping.set(t,n)}}for(;d+f<a;d++){const t=l[c-d-1],n=i[r-d-1];if(t instanceof E)break;if($e(o.mapping.get(t),n))n instanceof p&&s.has(n.getKey())&&He(e,t,n,o,s);else{if(!Ie(t,n,o))break;o.mapping.set(t,n)}}for(;c-f-d>0&&r-f-d>0;){const n=l[f],a=i[f],u=l[c-d-1],h=i[r-d-1];if(n instanceof N&&a instanceof Array)Ye(n,a,o)||Ue(n,a,o),f+=1;else{let i=n instanceof v&&Qe(n,a),r=u instanceof v&&Qe(u,h);if(i&&r){const e=We(n,a,o),t=We(u,h,o);e.foundMappedChild&&!t.foundMappedChild?r=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?i=!1:r=!1}i?(He(e,n,a,o,s),f+=1):r?(He(e,u,h,o,s),d+=1):(o.mapping.delete(t.get(f)),t.delete(f,1),t.insert(f,[je(a,o)]),f+=1)}}const u=c-f-d;if(1===c&&0===r&&l[0]instanceof N?(o.mapping.delete(l[0]),l[0].delete(0,l[0].length)):u>0&&(t.slice(f,f+u).forEach(e=>o.mapping.delete(e)),t.delete(f,u)),f+d<r){const e=[];for(let t=f;t<r-d;t++)e.push(je(i[t],o));t.insert(f,e)}},Qe=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType(),Xe=y("ychange",{isEqual:(e,t)=>e===t,parse:e=>e??null});function Ze(e){return _(e,Xe)}const et=(e,t=A(e.doc),n=j)=>{const{doc:o}=e;o.gc&&V(325),o.transact(s=>{const i=new z(o);i&&i.dss.forEach(e=>{L(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(()=>{u().clear(),Ee(e.root,e,null,!0,t,n,r)})},e)};function tt(e,t){const n=t.collabNodeMap.get(e.key);if(void 0===n)return null;let s=e.offset,i=n.getSharedType();if(n instanceof te){i=n._parent._xmlText;const e=n.getOffset();if(-1===e)return null;s=e+1+s}else if(n instanceof oe&&"element"===e.type){const t=e.getNode();r(t)||V(184);let n=0,i=0,l=t.getFirstChild();for(;null!==l&&i++<s;)o(l)?n+=l.getTextContentSize()+1:n++,l=l.getNextSibling();s=n}return Y(i,s)}function nt(e,t){const{mapping:n}=t,{offset:s}=e,i=e.getNode(),l=n.getSharedType(i);if(void 0===l)return null;if("text"===e.type){o(i)||V(326);let e=i.getPreviousSibling(),t=s;for(;o(e);)t+=e.getTextContentSize(),e=e.getPreviousSibling();return Y(l,t)}if("element"===e.type){r(i)||V(184);let e=0,t=i.getFirstChild();for(;null!==t&&e<s;){if(o(t)){let e=t.getNextSibling();for(;o(e);)e=e.getNextSibling()}e++,t=t.getNextSibling()}return Y(l,e)}return null}function ot(e,t){return D(e,t.doc)}function st(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!I(e,t))return!0;return!1}function it(e,t){return{color:t,name:e,selection:null}}function rt(e,t){const n=e.cursorsContainer;if(null!==n){const e=t.selections,o=e.length;for(let t=0;t<o;t++)n.removeChild(e[t])}}function lt(e,t){const n=t.selection;null!==n&&rt(e,n)}function ct(e,t,n,o,s){const i=e.color,r=document.createElement("span");r.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${i};z-index:10;`;const l=document.createElement("span");return l.textContent=e.name,l.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${i};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`,r.appendChild(l),{anchor:{key:t,offset:n},caret:r,color:i,focus:{key:o,offset:s},name:l,selections:[]}}function at(e,t,o,s){const i=e.editor,r=i.getRootElement(),l=e.cursorsContainer;if(null===l||null===r)return;const c=l.offsetParent;if(null===c)return;const a=c.getBoundingClientRect(),f=t.selection;if(null===o)return null===f?void 0:(t.selection=null,void rt(e,f));t.selection=o;const d=o.caret,u=o.color,h=o.selections,p=o.anchor,g=o.focus,_=p.key,y=g.key,m=s.get(_),x=s.get(y);if(null==m||null==x)return;let T;if(m===x&&n(m)){T=[i.getElementByKey(_).getBoundingClientRect()]}else{const e=J(i,m,p.offset,x,g.offset);if(null===e)return;T=G(i,e)}const b=h.length,k=T.length;for(let e=0;e<k;e++){const t=T[e];let n=h[e];if(void 0===n){n=document.createElement("span"),h[e]=n;const t=document.createElement("span");n.appendChild(t),l.appendChild(n)}const o=`position:absolute;top:${t.top-a.top}px;left:${t.left-a.left}px;height:${t.height}px;width:${t.width}px;pointer-events:none;z-index:5;`;n.style.cssText=o,n.firstChild.style.cssText=`${o}left:0;top:0;background-color:${u};opacity:0.3;`,e===k-1&&d.parentNode!==n&&n.appendChild(d)}for(let e=b-1;e>=k;e--){const t=h[e];l.removeChild(t),h.pop()}}function ft(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,i=0,r=null,l=0;if(null!==n&&null!==o){const t=ot(n,e),c=ot(o,e);null!==t&&null!==c&&([s,i]=pt(t.type,t.index),[r,l]=pt(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:i,focusCollabNode:r,focusOffset:l}}function dt(e,t){const{anchorPos:n,focusPos:s}=t,i=n?ot(n,e):null,r=s?ot(s,e):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(ae(e)){const[e,t]=pt(i.type,i.index),[n,o]=pt(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=gt(e.mapping,i),[a,f]=gt(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 ut(e,t){const n=t.awareness.getLocalState();if(null===n)return;const{anchorKey:o,anchorOffset:r,focusKey:l,focusOffset:c}=dt(e,n);if(null!==o&&null!==l){const e=s();if(!i(e))return;ht(e.anchor,o,r),ht(e.focus,l,c)}}function ht(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 pt(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof oe){const{node:e,offset:o}=we(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function gt(e,t){const n=t.type,s=t.index;if(n instanceof v){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 yt(e,t,n){const{getAwarenessStates:o=_t}=n??{},s=Array.from(o(e,t)),i=e.clientID,r=e.cursors,l=e.editor,c=l._editorState._nodeMap,a=new Set;for(let t=0;t<s.length;t++){const n=s[t],[o,f]=n;if(0!==o&&o!==i){a.add(o);const{name:t,color:n,focusing:s}=f;let i=null,d=r.get(o);if(void 0===d&&(d=it(t,n),r.set(o,d)),s){const{anchorKey:t,anchorOffset:n,focusKey:o,focusOffset:s}=l.read(()=>dt(e,f));if(null!==t&&null!==o)if(i=d.selection,null===i)i=ct(d,t,n,o,s);else{const e=i.anchor,r=i.focus;e.key=t,e.offset=n,r.key=o,r.offset=s}}at(e,d,i,c)}}const f=Array.from(r.keys());for(let t=0;t<f.length;t++){const n=f[t];if(!a.has(n)){const t=r.get(n);void 0!==t&&(lt(e,t),r.delete(n))}}}function mt(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:d,awarenessData:u}=r;let h=null,p=null;(null!==o&&(null===l||o.is(n))||null!==n)&&(i(o)&&(ae(e)?(h=tt(o.anchor,e),p=tt(o.focus,e)):(h=nt(o.anchor,e),p=nt(o.focus,e))),(st(l,h)||st(c,p))&&s.setLocalState({...r,anchorPos:h,awarenessData:u,color:f,focusPos:p,focusing:d,name:a}))}function xt(e,t){if(t instanceof W&&function(e,t){const{target:n}=t;if(!n._item||"__state"!==n._item.parentSub||void 0!==ye(n)||!(n.parent instanceof N||n.parent instanceof v||n.parent instanceof w))return!1;const o=me(e,n.parent).getNode();if(o){const e=d(o.getWritable());for(const o of t.keysChanged)e.updateFromUnknown(o,n.get(o))}return!0}(e,t))return;const{target:n}=t,o=me(e,n);if(o instanceof oe&&t instanceof U){const{keysChanged:n,childListChanged:s,delta:i}=t;n.size>0&&o.syncPropertiesFromYjs(e,n),s&&(o.applyChildrenYjsDelta(e,i),o.syncChildrenFromYjs(e))}else if(o instanceof te&&t instanceof W){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof Q&&t instanceof R){const{attributesChanged:n}=t;n.size>0&&o.syncPropertiesFromYjs(e,n)}else V(82)}function Tt(e,t,n,o,s=yt){const i=e.editor,r=i._editorState;n.forEach(e=>e.delta),i.update(()=>{for(let t=0;t<n.length;t++){const o=n[t];xt(e,o)}bt(r,e,t),o||T(b)},{onUpdate:()=>{s(e,t),i.update(()=>kt())},skipTransforms:!0,tag:o?x:m})}function bt(e,t,n){const o=s();if(i(o))if(Ce(o)){const r=e._selection;if(i(r)&&(ut(t,n),Ce(o))){Ke(o.anchor.key,e)}mt(t,n,r,s())}else ut(t,n)}function kt(){0===u().getChildrenSize()&&u().append(k())}function St(e,n,i,r,l,c,a,f){Oe(e,()=>{r.read(()=>{if(f.has(m)||f.has(x))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 te)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=u(),o=e.root;o.syncPropertiesFromLexical(e,n,t),o.syncChildrenFromLexical(e,n,t,l,c)}const r=s(),d=i._selection;mt(e,n,d,r)})})}function Nt(e,t){const{target:n}=t;if(n instanceof v&&t instanceof R)Ee(n,e,t.attributesChanged,t.childListChanged);else if(n instanceof N&&t instanceof U){const t=n.parent;t instanceof v?Ee(t,e,new Set,!0):V(327)}else V(328)}function vt(e,t,n,o,s){const i=e.editor,r=i._editorState;L(o,o.deleteSet,t=>{if(t.constructor===$){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];Nt(e,o)}bt(r,e,t),s||T(b)},{discrete:!0,onUpdate:()=>{yt(e,t),i.update(()=>kt())},skipTransforms:!0,tag:s?x:m})}function wt(e,t){e.mapping.clear();const n=e.editor;n.update(()=>{u().clear(),Ee(e.root,e,null,!0),T(m)},{discrete:!0,onUpdate:()=>{yt(e,t),n.update(()=>kt())},skipTransforms:!0,tag:m})}function Ct(e,t,n,o,i,r,l){(l.has(m)||l.has(x))&&0===r.size||(r.forEach(t=>{e.mapping.deleteNode(t)}),Oe(e,()=>{o.read(()=>{i.has("root")&&He(e.doc,e.root,u(),e,new Set(i.keys()));const o=s(),r=n._selection;mt(e,t,r,o)})}))}const Ot=S("CONNECTED_COMMAND"),Kt=S("TOGGLE_CONNECT_COMMAND"),Mt=S("DIFF_VERSIONS_COMMAND"),Et=S("CLEAR_DIFF_VERSIONS_COMMAND");function Pt(e,t){return new B(t,{trackedOrigins:new Set([e,null])})}function Ft(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})}function At(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{Ze as $getYChangeState,Et as CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL,Ot as CONNECTED_COMMAND,Mt as DIFF_VERSIONS_COMMAND__EXPERIMENTAL,Kt as TOGGLE_CONNECT_COMMAND,le as createBinding,ce as createBindingV2__EXPERIMENTAL,Pt as createUndoManager,ft as getAnchorAndFocusCollabNodesForUserState,Ft as initLocalState,et as renderSnapshot__EXPERIMENTAL,At as setLocalStateFocus,yt as syncCursorPositions,St as syncLexicalUpdateToYjs,Ct as syncLexicalUpdateToYjsV2__EXPERIMENTAL,Tt as syncYjsChangesToLexical,vt as syncYjsChangesToLexicalV2__EXPERIMENTAL,wt as syncYjsStateToLexicalV2__EXPERIMENTAL};
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Meta Platforms, Inc. and affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,374 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ import type {Doc, RelativePosition, UndoManager, XmlText} from 'yjs';
11
+ import type {
12
+ DecoratorNode,
13
+ EditorState,
14
+ ElementNode,
15
+ LexicalCommand,
16
+ LexicalEditor,
17
+ LexicalNode,
18
+ LineBreakNode,
19
+ NodeMap,
20
+ NodeKey,
21
+ TextNode,
22
+ } from '@ekz/lexical';
23
+
24
+ // $FlowFixMe[unclear-type]: todo
25
+ export type YjsEvent = Object;
26
+
27
+ export type UserState = {
28
+ anchorPos: null | RelativePosition,
29
+ color: string,
30
+ focusing: boolean,
31
+ focusPos: null | RelativePosition,
32
+ name: string,
33
+ };
34
+
35
+ export type ProviderAwareness = {
36
+ getLocalState: () => UserState | null,
37
+ getStates: () => Map<number, UserState>,
38
+ off: (type: 'update', cb: () => void) => void,
39
+ on: (type: 'update', cb: () => void) => void,
40
+ setLocalState: (UserState | null) => void,
41
+ };
42
+
43
+ declare interface Provider {
44
+ awareness: ProviderAwareness;
45
+ connect(): void | Promise<void>;
46
+ disconnect(): void;
47
+ off(type: 'sync', cb: (isSynced: boolean) => void): void;
48
+ // $FlowFixMe[unclear-type]: temp
49
+ off(type: 'update', cb: (any) => void): void;
50
+ off(type: 'status', cb: ({status: string}) => void): void;
51
+ off(type: 'reload', cb: (doc: Doc) => void): void;
52
+ on(type: 'sync', cb: (isSynced: boolean) => void): void;
53
+ on(type: 'status', cb: ({status: string}) => void): void;
54
+ // $FlowFixMe[unclear-type]: temp
55
+ on(type: 'update', cb: (any) => void): void;
56
+ on(type: 'reload', cb: (doc: Doc) => void): void;
57
+ }
58
+
59
+ export type ClientID = number;
60
+ // $FlowFixMe[unclear-type]: work around for internal
61
+ export type XmlElement = Object;
62
+ // $FlowFixMe[unclear-type]: work around for internal
63
+ export type YMap = Object;
64
+ export type TextOperation = {
65
+ insert?: string | mixed,
66
+ delete?: number,
67
+ retain?: number,
68
+ attributes?: {
69
+ [x: string]: mixed,
70
+ },
71
+ };
72
+
73
+ export type CursorSelection = {
74
+ anchor: {
75
+ key: NodeKey,
76
+ offset: number,
77
+ },
78
+ caret: HTMLElement,
79
+ color: string,
80
+ focus: {
81
+ key: NodeKey,
82
+ offset: number,
83
+ },
84
+ name: HTMLSpanElement,
85
+ selections: Array<HTMLElement>,
86
+ };
87
+
88
+ export type Cursor = {
89
+ color: string,
90
+ name: string,
91
+ selection: null | CursorSelection,
92
+ };
93
+
94
+ export type Binding = {
95
+ clientID: number,
96
+ collabNodeMap: Map<
97
+ NodeKey,
98
+ | CollabElementNode
99
+ | CollabTextNode
100
+ | CollabDecoratorNode
101
+ | CollabLineBreakNode,
102
+ >,
103
+ cursors: Map<ClientID, Cursor>,
104
+ cursorsContainer: null | HTMLElement,
105
+ doc: Doc,
106
+ docMap: Map<string, Doc>,
107
+ editor: LexicalEditor,
108
+ id: string,
109
+ nodeProperties: Map<string, {[property: string]: mixed}>,
110
+ root: CollabElementNode,
111
+ };
112
+
113
+ export type ExcludedProperties = Map<Class<LexicalNode>, Set<string>>;
114
+
115
+ declare export class CollabDecoratorNode {
116
+ _xmlElem: XmlElement;
117
+ _key: NodeKey;
118
+ _parent: CollabElementNode;
119
+ _type: string;
120
+ _unobservers: Set<() => void>;
121
+
122
+ constructor(
123
+ xmlElem: XmlElement,
124
+ parent: CollabElementNode,
125
+ type: string,
126
+ ): void;
127
+
128
+ getPrevNode(nodeMap: null | NodeMap): null | DecoratorNode<{...}>;
129
+
130
+ getNode(): null | DecoratorNode<{...}>;
131
+
132
+ getSharedType(): XmlElement;
133
+
134
+ getType(): string;
135
+
136
+ getKey(): NodeKey;
137
+
138
+ getSize(): number;
139
+
140
+ getOffset(): number;
141
+
142
+ syncPropertiesFromLexical(
143
+ binding: Binding,
144
+ nextLexicalNode: DecoratorNode<{...}>,
145
+ prevNodeMap: null | NodeMap,
146
+ ): void;
147
+
148
+ syncPropertiesFromYjs(
149
+ binding: Binding,
150
+ keysChanged: null | Set<string>,
151
+ ): void;
152
+
153
+ destroy(binding: Binding): void;
154
+ }
155
+
156
+ declare export class CollabLineBreakNode {
157
+ _map: YMap;
158
+ _key: NodeKey;
159
+ _parent: CollabElementNode;
160
+ _type: 'linebreak';
161
+
162
+ constructor(map: YMap, parent: CollabElementNode): void;
163
+
164
+ getNode(): null | LineBreakNode;
165
+
166
+ getKey(): NodeKey;
167
+
168
+ getSharedType(): YMap;
169
+
170
+ getType(): string;
171
+
172
+ getSize(): number;
173
+
174
+ getOffset(): number;
175
+
176
+ destroy(binding: Binding): void;
177
+ }
178
+
179
+ declare export class CollabTextNode {
180
+ _map: YMap;
181
+ _key: NodeKey;
182
+ _parent: CollabElementNode;
183
+ _text: string;
184
+ _type: string;
185
+ _normalized: boolean;
186
+
187
+ constructor(
188
+ map: YMap,
189
+ text: string,
190
+ parent: CollabElementNode,
191
+ type: string,
192
+ ): void;
193
+
194
+ getPrevNode(nodeMap: null | NodeMap): null | TextNode;
195
+
196
+ getNode(): null | TextNode;
197
+
198
+ getSharedType(): YMap;
199
+
200
+ getType(): string;
201
+
202
+ getKey(): NodeKey;
203
+
204
+ getSize(): number;
205
+
206
+ getOffset(): number;
207
+
208
+ spliceText(index: number, delCount: number, newText: string): void;
209
+
210
+ syncPropertiesAndTextFromLexical(
211
+ binding: Binding,
212
+ nextLexicalNode: TextNode,
213
+ prevNodeMap: null | NodeMap,
214
+ ): void;
215
+
216
+ syncPropertiesAndTextFromYjs(
217
+ binding: Binding,
218
+ keysChanged: null | Set<string>,
219
+ ): void;
220
+
221
+ destroy(binding: Binding): void;
222
+ }
223
+
224
+ type IntentionallyMarkedAsDirtyElement = boolean;
225
+
226
+ declare export class CollabElementNode {
227
+ _key: NodeKey;
228
+ _children: Array<
229
+ | CollabElementNode
230
+ | CollabTextNode
231
+ | CollabDecoratorNode
232
+ | CollabLineBreakNode,
233
+ >;
234
+ _xmlText: XmlText;
235
+ _type: string;
236
+ _parent: null | CollabElementNode;
237
+
238
+ constructor(
239
+ xmlText: XmlText,
240
+ parent: null | CollabElementNode,
241
+ type: string,
242
+ ): void;
243
+
244
+ getPrevNode(nodeMap: null | NodeMap): null | ElementNode;
245
+
246
+ getNode(): null | ElementNode;
247
+
248
+ getSharedType(): XmlText;
249
+
250
+ getType(): string;
251
+
252
+ getKey(): NodeKey;
253
+
254
+ isEmpty(): boolean;
255
+
256
+ getSize(): number;
257
+
258
+ getOffset(): number;
259
+
260
+ syncPropertiesFromYjs(
261
+ binding: Binding,
262
+ keysChanged: null | Set<string>,
263
+ ): void;
264
+
265
+ applyChildrenYjsDelta(binding: Binding, deltas: Array<TextOperation>): void;
266
+
267
+ syncChildrenFromYjs(binding: Binding): void;
268
+
269
+ syncPropertiesFromLexical(
270
+ binding: Binding,
271
+ nextLexicalNode: ElementNode,
272
+ prevNodeMap: null | NodeMap,
273
+ ): void;
274
+
275
+ _syncChildFromLexical(
276
+ binding: Binding,
277
+ index: number,
278
+ key: NodeKey,
279
+ prevNodeMap: null | NodeMap,
280
+ dirtyElements: null | Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
281
+ dirtyLeaves: null | Set<NodeKey>,
282
+ ): void;
283
+
284
+ syncChildrenFromLexical(
285
+ binding: Binding,
286
+ nextLexicalNode: ElementNode,
287
+ prevNodeMap: null | NodeMap,
288
+ dirtyElements: null | Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
289
+ dirtyLeaves: null | Set<NodeKey>,
290
+ ): void;
291
+
292
+ append(
293
+ collabNode:
294
+ | CollabElementNode
295
+ | CollabDecoratorNode
296
+ | CollabTextNode
297
+ | CollabLineBreakNode,
298
+ ): void;
299
+
300
+ splice(
301
+ binding: Binding,
302
+ index: number,
303
+ delCount: number,
304
+ collabNode?:
305
+ | CollabElementNode
306
+ | CollabDecoratorNode
307
+ | CollabTextNode
308
+ | CollabLineBreakNode,
309
+ ): void;
310
+
311
+ getChildOffset(
312
+ collabNode:
313
+ | CollabElementNode
314
+ | CollabTextNode
315
+ | CollabDecoratorNode
316
+ | CollabLineBreakNode,
317
+ ): number;
318
+
319
+ destroy(binding: Binding): void;
320
+ }
321
+
322
+ declare export function createUndoManager(
323
+ binding: Binding,
324
+ root: XmlText,
325
+ ): UndoManager;
326
+
327
+ declare export function initLocalState(
328
+ provider: Provider,
329
+ name: string,
330
+ color: string,
331
+ focusing: boolean,
332
+ ): void;
333
+
334
+ declare export function setLocalStateFocus(
335
+ provider: Provider,
336
+ name: string,
337
+ color: string,
338
+ focusing: boolean,
339
+ ): void;
340
+
341
+ declare export function createBinding(
342
+ editor: LexicalEditor,
343
+ provider: Provider,
344
+ id: string,
345
+ doc: ?Doc,
346
+ docMap: Map<string, Doc>,
347
+ ): Binding;
348
+
349
+ declare export function syncCursorPositions(
350
+ binding: Binding,
351
+ provider: Provider,
352
+ ): void;
353
+
354
+ declare export function syncLexicalUpdateToYjs(
355
+ binding: Binding,
356
+ provider: Provider,
357
+ prevEditorState: EditorState,
358
+ currEditorState: EditorState,
359
+ dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
360
+ dirtyLeaves: Set<NodeKey>,
361
+ normalizedNodes: Set<NodeKey>,
362
+ tags: Set<string>,
363
+ ): void;
364
+
365
+ declare export function syncYjsChangesToLexical(
366
+ binding: Binding,
367
+ provider: Provider,
368
+ events: Array<YjsEvent>,
369
+ ): void;
370
+
371
+ declare export var CONNECTED_COMMAND: LexicalCommand<boolean>;
372
+ declare export var TOGGLE_CONNECT_COMMAND: LexicalCommand<boolean>;
373
+
374
+ export type {Provider};
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # `@lexical/yjs`
2
+
3
+ [![See API Documentation](https://lexical.dev/img/see-api-documentation.svg)](https://lexical.dev/docs/api/modules/lexical_yjs)
4
+
5
+ This package provides a set of bindings for Y.js that allow for collaborative editing with Lexical.