@lexical/yjs 0.36.2 → 0.36.3-nightly.20251003.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/Bindings.d.ts +22 -6
- package/CollabV2Mapping.d.ts +24 -0
- package/LexicalYjs.dev.js +993 -60
- package/LexicalYjs.dev.mjs +993 -63
- package/LexicalYjs.js.flow +1 -1
- package/LexicalYjs.mjs +4 -1
- package/LexicalYjs.node.mjs +4 -1
- package/LexicalYjs.prod.js +1 -1
- package/LexicalYjs.prod.mjs +1 -1
- package/SyncCursors.d.ts +15 -6
- package/SyncEditorStates.d.ts +5 -1
- package/SyncV2.d.ts +14 -0
- package/Utils.d.ts +7 -3
- package/index.d.ts +6 -6
- package/package.json +4 -4
package/LexicalYjs.js.flow
CHANGED
package/LexicalYjs.mjs
CHANGED
|
@@ -12,10 +12,13 @@ const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
|
|
|
12
12
|
export const CONNECTED_COMMAND = mod.CONNECTED_COMMAND;
|
|
13
13
|
export const TOGGLE_CONNECT_COMMAND = mod.TOGGLE_CONNECT_COMMAND;
|
|
14
14
|
export const createBinding = mod.createBinding;
|
|
15
|
+
export const createBindingV2__EXPERIMENTAL = mod.createBindingV2__EXPERIMENTAL;
|
|
15
16
|
export const createUndoManager = mod.createUndoManager;
|
|
16
17
|
export const getAnchorAndFocusCollabNodesForUserState = mod.getAnchorAndFocusCollabNodesForUserState;
|
|
17
18
|
export const initLocalState = mod.initLocalState;
|
|
18
19
|
export const setLocalStateFocus = mod.setLocalStateFocus;
|
|
19
20
|
export const syncCursorPositions = mod.syncCursorPositions;
|
|
20
21
|
export const syncLexicalUpdateToYjs = mod.syncLexicalUpdateToYjs;
|
|
21
|
-
export const
|
|
22
|
+
export const syncLexicalUpdateToYjsV2__EXPERIMENTAL = mod.syncLexicalUpdateToYjsV2__EXPERIMENTAL;
|
|
23
|
+
export const syncYjsChangesToLexical = mod.syncYjsChangesToLexical;
|
|
24
|
+
export const syncYjsChangesToLexicalV2__EXPERIMENTAL = mod.syncYjsChangesToLexicalV2__EXPERIMENTAL;
|
package/LexicalYjs.node.mjs
CHANGED
|
@@ -10,10 +10,13 @@ const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalYjs.
|
|
|
10
10
|
export const CONNECTED_COMMAND = mod.CONNECTED_COMMAND;
|
|
11
11
|
export const TOGGLE_CONNECT_COMMAND = mod.TOGGLE_CONNECT_COMMAND;
|
|
12
12
|
export const createBinding = mod.createBinding;
|
|
13
|
+
export const createBindingV2__EXPERIMENTAL = mod.createBindingV2__EXPERIMENTAL;
|
|
13
14
|
export const createUndoManager = mod.createUndoManager;
|
|
14
15
|
export const getAnchorAndFocusCollabNodesForUserState = mod.getAnchorAndFocusCollabNodesForUserState;
|
|
15
16
|
export const initLocalState = mod.initLocalState;
|
|
16
17
|
export const setLocalStateFocus = mod.setLocalStateFocus;
|
|
17
18
|
export const syncCursorPositions = mod.syncCursorPositions;
|
|
18
19
|
export const syncLexicalUpdateToYjs = mod.syncLexicalUpdateToYjs;
|
|
19
|
-
export const
|
|
20
|
+
export const syncLexicalUpdateToYjsV2__EXPERIMENTAL = mod.syncLexicalUpdateToYjsV2__EXPERIMENTAL;
|
|
21
|
+
export const syncYjsChangesToLexical = mod.syncYjsChangesToLexical;
|
|
22
|
+
export const syncYjsChangesToLexicalV2__EXPERIMENTAL = mod.syncYjsChangesToLexicalV2__EXPERIMENTAL;
|
package/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/offset"),o=require("@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.`)}class i{_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 l(e,t){const n=new i(e,t);return e._collabNode=n,n}class r{_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),i=n.__text;if(k(t,this._map,s,n),null!==s){const t=s.__text;if(t!==i){!function(t,n,o,s){const i=e.$getSelection();let l=s.length;if(e.$isRangeSelection(i)&&i.isCollapsed()){const e=i.anchor;e.key===n&&(l=e.offset)}const r=function(e,t,n){const o=e.length,s=t.length;let i=0,l=0;for(;i<o&&i<s&&e[i]===t[i]&&i<n;)i++;for(;l+i<o&&l+i<s&&e[o-l-1]===t[s-l-1];)l++;for(;l+i<o&&l+i<s&&e[i]===t[i];)i++;return{index:i,insert:t.slice(i,s-l),remove:o-i-l}}(o,s,l);t.spliceText(r.index,r.remove,r.insert)}(this,n.__key,t,i),this._text=i}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();null===n&&s(84),x(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 c(e,t,n,o){const s=new r(e,t,n,o);return e._collabNode=s,s}const a=new Set(["__key","__parent","__next","__prev","__state"]),f=new Set(["__first","__last","__size"]),d=new Set(["__cachedText"]),u=new Set(["__text"]);function h(t,n,o){if(a.has(t)||"function"==typeof n[t])return!0;if(e.$isTextNode(n)){if(u.has(t))return!0}else if(e.$isElementNode(n)&&(f.has(t)||e.$isRootNode(n)&&d.has(t)))return!0;const s=n.constructor,i=o.excludedProperties.get(s);return null!=i&&i.has(t)}function _(n,o,i){const r=o.__type;let a;if(e.$isElementNode(o)){a=O(new t.XmlText,i,r),a.syncPropertiesFromLexical(n,o,null),a.syncChildrenFromLexical(n,o,null,null,null)}else if(e.$isTextNode(o)){a=c(new t.Map,o.__text,i,r),a.syncPropertiesAndTextFromLexical(n,o,null)}else if(e.$isLineBreakNode(o)){const e=new t.Map;e.set("__type","linebreak"),a=l(e,i)}else if(e.$isDecoratorNode(o)){a=w(new t.XmlElement,i,r),a.syncPropertiesFromLexical(n,o,null)}else s(86);return a._key=o.__key,a}function p(e){const t=m(e,"__type");return"string"!=typeof t&&void 0!==t&&s(87),t}function g(e,n,o){const i=n._collabNode;if(void 0===i){const i=e.editor._nodes,r=p(n);"string"!=typeof r&&s(87);void 0===i.get(r)&&s(88,r);const a=n.parent,f=void 0===o&&null!==a?g(e,a):o||null;if(f instanceof P||s(89),n instanceof t.XmlText)return O(n,f,r);if(n instanceof t.Map)return"linebreak"===r?l(n,f):c(n,"",f,r);if(n instanceof t.XmlElement)return w(n,f,r)}return i}function y(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 P){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof r?t.syncPropertiesAndTextFromYjs(e,null):t instanceof v&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(l.__key,t),l}function x(n,o,s,i){const l=null===i?o instanceof t.Map?Array.from(o.keys()):Object.keys(o.getAttributes()):Array.from(i);let r;for(let i=0;i<l.length;i++){const c=l[i];if(h(c,s,n)){"__state"===c&&(r||(r=s.getWritable()),T(n,o,r));continue}const a=s[c];let f=m(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===r&&(r=s.getWritable()),r[c]=f}}}function m(e,n){return e instanceof t.Map?e.get(n):e.getAttribute(n)}function N(e,n,o){e instanceof t.Map?e.set(n,o):e.setAttribute(n,o)}function T(n,o,s){const i=m(o,"__state");i instanceof t.Map&&e.$getWritableNodeState(s).updateFromJSON(i.toJSON())}function k(e,n,o,s){const i=s.__type,l=e.nodeProperties;let r=l.get(i);void 0===r&&(r=Object.keys(s).filter(t=>!h(t,s,e)),l.set(i,r));const c=e.editor.constructor;!function(e,n,o,s){const i=s.__state,l=m(n,"__state");if(!i)return;const[r,c]=i.getInternalState(),a=o&&o.__state,f=l instanceof t.Map?l:new t.Map;if(a===i)return;const[d,u]=a&&f.doc?a.getInternalState():[void 0,new Map];if(r)for(const[e,t]of Object.entries(r))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));l||N(n,"__state",f)}(0,n,o,s);for(let i=0;i<r.length;i++){const l=r[i],a=null===o?void 0:o[l];let f=s[l];if(a!==f){if(f instanceof c){const n=e.docMap;let o;if(a instanceof c){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()})}N(n,l,f)}}}function C(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function $(e,t,n){let o=0,s=0;const i=e._children,l=i.length;for(;s<l;s++){const e=i[s],c=o;o+=e.getSize();if((n?o>=t:o>t)&&e instanceof r){let n=t-c-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:c};if(s===l-1)return{length:0,node:null,nodeIndex:s+1,offset:c+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function S(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 b(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():b(i.__key,n):e.$getRoot().selectStart()}class v{_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);k(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&s(83);x(e,this._xmlElem,n,t)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function w(e,t,n){const o=new v(e,t,n);return e._collabNode=o,o}class P{_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),x(e,this._xmlText,n,t)}applyChildrenYjsDelta(e,t){const n=this._children;let o=0,s=null;for(let l=0;l<t.length;l++){const c=t[l],a=c.insert,f=c.delete;if(null!=c.retain)o+=c.retain;else if("number"==typeof f){let e=f;for(;e>0;){const{node:t,nodeIndex:s,offset:l,length:c}=$(this,o,!1);if(t instanceof P||t instanceof i||t instanceof v)n.splice(s,1),e-=1;else{if(!(t instanceof r))break;{const o=Math.min(e,c),i=0!==s?n[s-1]:null,a=t.getSize();if(0===l&&c===a){n.splice(s,1);const e=C(t._text,l,o-1,"");e.length>0&&(i instanceof r?i._text+=e:this._xmlText.delete(l,e.length))}else t._text=C(t._text,l,o,"");e-=o}}}}else{if(null==a)throw new Error("Unexpected delta format");if("string"==typeof a){const{node:e,offset:t}=$(this,o,!0);e instanceof r?e._text=C(e._text,t,0,a):this._xmlText.delete(t,a.length),o+=a.length}else{const t=a,{node:i,nodeIndex:l,length:c}=$(this,o,!1),f=g(e,t,this);if(i instanceof r&&c>0&&c<i._text.length){const e=i._text,t=e.length-c;i._text=C(e,t,c,""),n.splice(l+1,0,f),s=C(e,0,t,"")}else n.splice(l,0,f);null!==s&&f instanceof r&&(f._text=s+f._text,s=null),o+=1}}}}syncChildrenFromYjs(t){const o=this.getNode();null===o&&s(92);const l=o.__key,c=n.$createChildrenArray(o,null),a=c.length,f=this._children,d=f.length,u=t.collabNodeMap,h=new Set;let _,p,g=0,x=null;d!==a&&(p=o.getWritable());for(let n=0;n<d;n++){const a=c[g],m=f[n],N=m.getNode(),T=m._key;if(null!==N&&a===T){const n=e.$isTextNode(N);if(h.add(a),n)if(m._key=a,m instanceof P){const e=m._xmlText;m.syncPropertiesFromYjs(t,null),m.applyChildrenYjsDelta(t,e.toDelta()),m.syncChildrenFromYjs(t)}else m instanceof r?m.syncPropertiesAndTextFromYjs(t,null):m instanceof v?m.syncPropertiesFromYjs(t,null):m instanceof i||s(93);x=N,g++}else{if(void 0===_){_=new Set;for(let e=0;e<d;e++){const t=f[e]._key;""!==t&&_.add(t)}}if(null!==N&&void 0!==a&&!_.has(a)){const t=e.$getNodeByKeyOrThrow(a);e.removeFromParent(t),n--,g++;continue}p=o.getWritable();const s=y(t,m,l),i=s.__key;if(u.set(i,m),null===x){const e=p.getFirstChild();if(p.__first=i,null!==e){const t=e.getWritable();t.__prev=i,s.__next=t.__key}}else{const e=x.getWritable(),t=x.getNextSibling();if(e.__next=i,s.__prev=x.__key,null!==t){const e=t.getWritable();e.__prev=i,s.__next=e.__key}}n===d-1&&(p.__last=i),p.__size++,x=s}}for(let n=0;n<a;n++){const o=c[n];if(!h.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){k(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 P&&e.$isElementNode(a)?(c.syncPropertiesFromLexical(t,a,s),c.syncChildrenFromLexical(t,a,s,i,l)):c instanceof r&&e.$isTextNode(a)?c.syncPropertiesAndTextFromLexical(t,a,s):c instanceof v&&e.$isDecoratorNode(a)&&c.syncPropertiesFromLexical(t,a,s)}syncChildrenFromLexical(t,o,s,i,l){const r=this.getPrevNode(s),c=null===r?[]:n.$createChildrenArray(r,s),a=n.$createChildrenArray(o,null),f=c.length-1,d=a.length-1,u=t.collabNodeMap;let h,p,g=0,y=0;for(;g<=f&&y<=d;){const n=c[g],o=a[y];if(n===o)this._syncChildFromLexical(t,y,o,s,i,l),g++,y++;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=_(t,e.$getNodeByKeyOrThrow(o),this);u.set(o,n),i?(this.splice(t,y,1,n),g++,y++):(this.splice(t,y,0,n),y++)}else this.splice(t,y,1),g++}}const x=g>f,m=y>d;if(x&&!m)for(;y<=d;++y){const n=a[y],o=_(t,e.$getNodeByKeyOrThrow(n),this);this.append(o),u.set(n,o)}else if(m&&!x)for(let e=this._children.length-1;e>=y;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 P)t.insertEmbed(s,e._xmlText);else if(e instanceof r){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof i?t.insertEmbed(s,e._map):e instanceof v&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,o){const l=this._children,c=l[t];if(void 0===c)return void 0===o&&s(94),void this.append(o);const a=c.getOffset();-1===a&&s(95);const f=this._xmlText;if(0!==n&&f.delete(a,c.getSize()),o instanceof P)f.insertEmbed(a,o._xmlText);else if(o instanceof r){const e=o._map;null===e.parent&&f.insertEmbed(a,e),f.insert(a+1,o._text)}else o instanceof i?f.insertEmbed(a,o._map):o instanceof v&&f.insertEmbed(a,o._xmlElem);if(0!==n){const o=l.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e)}void 0!==o?l.splice(t,n,o):l.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 O(e,t,n){const o=new P(e,t,n);return e._collabNode=o,o}function E(n,o){const i=o.collabNodeMap.get(n.key);if(void 0===i)return null;let l=n.offset,c=i.getSharedType();if(i instanceof r){c=i._parent._xmlText;const e=i.getOffset();if(-1===e)return null;l=e+1+l}else if(i instanceof P&&"element"===n.type){const t=n.getNode();e.$isElementNode(t)||s(184);let o=0,i=0,r=t.getFirstChild();for(;null!==r&&i++<l;)e.$isTextNode(r)?o+=r.getTextContentSize()+1:o++,r=r.getNextSibling();l=o}return t.createRelativePositionFromTypeIndex(c,l)}function M(e,n){return t.createAbsolutePositionFromRelativePosition(e,n.doc)}function F(e,n){if(null==e){if(null!=n)return!0}else if(null==n||!t.compareRelativePositions(e,n))return!0;return!1}function L(e,t){return{color:t,name:e,selection:null}}function A(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 D(e,t){const n=t.selection;null!==n&&A(e,n)}function R(e,t,n,o,s){const i=e.color,l=document.createElement("span");l.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${i};z-index:10;`;const r=document.createElement("span");return r.textContent=e.name,r.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;`,l.appendChild(r),{anchor:{key:t,offset:n},caret:l,color:i,focus:{key:o,offset:s},name:r,selections:[]}}function j(t,n,s,i){const l=t.editor,r=l.getRootElement(),c=t.cursorsContainer;if(null===c||null===r)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 A(t,d));n.selection=s;const u=s.caret,h=s.color,_=s.selections,p=s.anchor,g=s.focus,y=p.key,x=g.key,m=i.get(y),N=i.get(x);if(null==m||null==N)return;let T;if(m===N&&e.$isLineBreakNode(m)){T=[l.getElementByKey(y).getBoundingClientRect()]}else{const e=o.createDOMRange(l,m,p.offset,N,g.offset);if(null===e)return;T=o.createRectsFromDOMRange(l,e)}const k=_.length,C=T.length;for(let e=0;e<C;e++){const t=T[e];let n=_[e];if(void 0===n){n=document.createElement("span"),_[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===C-1&&u.parentNode!==n&&n.appendChild(u)}for(let e=k-1;e>=C;e--){const t=_[e];c.removeChild(t),_.pop()}}function z(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,i=0,l=null,r=0;if(null!==n&&null!==o){const t=M(n,e),c=M(o,e);null!==t&&null!==c&&([s,i]=B(t.type,t.index),[l,r]=B(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:i,focusCollabNode:l,focusOffset:r}}function Y(t,n){const o=n.awareness.getLocalState();if(null===o)return;const{anchorCollabNode:s,anchorOffset:i,focusCollabNode:l,focusOffset:r}=z(t,o);if(null!==s&&null!==l){const t=s.getKey(),n=l.getKey(),o=e.$getSelection();if(!e.$isRangeSelection(o))return;K(o.anchor,t,i),K(o.focus,n,r)}}function K(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 B(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof P){const{node:e,offset:o}=$(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function I(e,t){return t.awareness.getStates()}function W(e,t,n){const{getAwarenessStates:o=I}=n??{},s=Array.from(o(e,t)),i=e.clientID,l=e.cursors,r=e.editor._editorState._nodeMap,c=new Set;for(let t=0;t<s.length;t++){const n=s[t],[o,a]=n;if(o!==i){c.add(o);const{name:t,color:n,focusing:s}=a;let i=null,f=l.get(o);if(void 0===f&&(f=L(t,n),l.set(o,f)),s){const{anchorCollabNode:t,anchorOffset:n,focusCollabNode:o,focusOffset:s}=z(e,a);if(null!==t&&null!==o){const e=t.getKey(),l=o.getKey();if(i=f.selection,null===i)i=R(f,e,n,l,s);else{const t=i.anchor,o=i.focus;t.key=e,t.offset=n,o.key=l,o.offset=s}}}j(e,f,i,r)}}const a=Array.from(l.keys());for(let t=0;t<a.length;t++){const n=a[t];if(!c.has(n)){const t=l.get(n);void 0!==t&&(D(e,t),l.delete(n))}}}function U(t,n,o,s){const i=n.awareness,l=i.getLocalState();if(null===l)return;const{anchorPos:r,focusPos:c,name:a,color:f,focusing:d,awarenessData:u}=l;let h=null,_=null;(null!==s&&(null===r||s.is(o))||null!==o)&&(e.$isRangeSelection(s)&&(h=E(s.anchor,t),_=E(s.focus,t)),(F(r,h)||F(c,_))&&i.setLocalState({...l,anchorPos:h,awarenessData:u,color:f,focusPos:_,focusing:d,name:a}))}function G(n,o){if(o instanceof t.YMapEvent&&function(n,o){const{target:s}=o;if(!s._item||"__state"!==s._item.parentSub||void 0!==p(s)||!(s.parent instanceof t.XmlText||s.parent instanceof t.XmlElement||s.parent instanceof t.Map))return!1;const i=g(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=g(n,i);if(l instanceof P&&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 r&&o instanceof t.YMapEvent){const{keysChanged:e}=o;e.size>0&&l.syncPropertiesAndTextFromYjs(n,e)}else if(l instanceof v&&o instanceof t.YXmlEvent){const{attributesChanged:e}=o;e.size>0&&l.syncPropertiesFromYjs(n,e)}else s(82)}const X=e.createCommand("CONNECTED_COMMAND"),q=e.createCommand("TOGGLE_CONNECT_COMMAND");exports.CONNECTED_COMMAND=X,exports.TOGGLE_CONNECT_COMMAND=q,exports.createBinding=function(e,n,o,i,l,r){null==i&&s(81);const c=O(i.get("root",t.XmlText),null,"root");return c._key="root",{clientID:i.clientID,collabNodeMap:new Map,cursors:new Map,cursorsContainer:null,doc:i,docMap:l,editor:e,excludedProperties:r||new Map,id:o,nodeProperties:new Map,root:c}},exports.createUndoManager=function(e,n){return new t.UndoManager(n,{trackedOrigins:new Set([e,null])})},exports.getAnchorAndFocusCollabNodesForUserState=z,exports.initLocalState=function(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})},exports.setLocalStateFocus=function(e,t,n,o,s){const{awareness:i}=e;let l=i.getLocalState();null===l&&(l={anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t}),l.focusing=o,i.setLocalState(l)},exports.syncCursorPositions=W,exports.syncLexicalUpdateToYjs=function(t,n,o,s,i,l,c,a){!function(e,t){e.doc.transact(t,e)}(t,()=>{s.read(()=>{if(a.has(e.COLLABORATION_TAG)||a.has(e.HISTORIC_TAG))return void(c.size>0&&function(t,n){const o=Array.from(n),s=t.collabNodeMap,i=[],l=[];for(let t=0;t<o.length;t++){const n=o[t],c=e.$getNodeByKey(n),a=s.get(n);if(a instanceof r)if(e.$isTextNode(c))i.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();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,c));if(i.has("root")){const n=o._nodeMap,s=e.$getRoot(),r=t.root;r.syncPropertiesFromLexical(t,s,n),r.syncChildrenFromLexical(t,s,n,i,l)}const s=e.$getSelection(),f=o._selection;U(t,n,f,s)})})},exports.syncYjsChangesToLexical=function(t,n,o,s,i=W){const l=t.editor,r=l._editorState;o.forEach(e=>e.delta),l.update(()=>{for(let e=0;e<o.length;e++){const n=o[e];G(t,n)}const i=e.$getSelection();if(e.$isRangeSelection(i))if(S(i)){const o=r._selection;if(e.$isRangeSelection(o)&&(Y(t,n),S(i))){b(i.anchor.key,r)}U(t,n,o,e.$getSelection())}else Y(t,n);s||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{onUpdate:()=>{i(t,n),l.update(()=>{0===e.$getRoot().getChildrenSize()&&e.$getRoot().append(e.$createParagraphNode())})},skipTransforms:!0,tag:s?e.HISTORIC_TAG:e.COLLABORATION_TAG})};
|
|
9
|
+
"use strict";var e=require("lexical"),t=require("yjs"),n=require("@lexical/offset"),o=require("@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.`)}class i{_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 r(e,t){const n=new i(e,t);return e._collabNode=n,n}function l(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 c{_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),i=n.__text;if(k(t,this._map,s,n),null!==s){const t=s.__text;if(t!==i){!function(t,n,o,s){const i=e.$getSelection();let r=s.length;if(e.$isRangeSelection(i)&&i.isCollapsed()){const e=i.anchor;e.key===n&&(r=e.offset)}const c=l(o,s,r);t.spliceText(c.index,c.remove,c.insert)}(this,n.__key,t,i),this._text=i}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();null===n&&s(84),T(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 a(e,t,n,o){const s=new c(e,t,n,o);return e._collabNode=s,s}const f=new Set(["__key","__parent","__next","__prev","__state"]),d=new Set(["__first","__last","__size"]),u=new Set(["__cachedText"]),h=new Set(["__text"]);function p(t,n,o){if(f.has(t)||"function"==typeof n[t])return!0;if(e.$isTextNode(n)){if(h.has(t))return!0}else if(e.$isElementNode(n)&&(d.has(t)||e.$isRootNode(n)&&u.has(t)))return!0;const s=n.constructor,i=o.excludedProperties.get(s);return null!=i&&i.has(t)}function g(e,t){const n=e.__type,{nodeProperties:o}=t,i=o.get(n);return void 0===i&&s(326,n),i}function y(n,o,i){const l=o.__type;let c;if(e.$isElementNode(o)){c=M(new t.XmlText,i,l),c.syncPropertiesFromLexical(n,o,null),c.syncChildrenFromLexical(n,o,null,null,null)}else if(e.$isTextNode(o)){c=a(new t.Map,o.__text,i,l),c.syncPropertiesAndTextFromLexical(n,o,null)}else if(e.$isLineBreakNode(o)){const e=new t.Map;e.set("__type","linebreak"),c=r(e,i)}else if(e.$isDecoratorNode(o)){c=A(new t.XmlElement,i,l),c.syncPropertiesFromLexical(n,o,null)}else s(86);return c._key=o.__key,c}function _(e){const t=N(e,"__type");return"string"!=typeof t&&void 0!==t&&s(87),t}function m(e,n,o){const i=n._collabNode;if(void 0===i){const i=e.editor._nodes,l=_(n);"string"!=typeof l&&s(87);void 0===i.get(l)&&s(88,l);const c=n.parent,f=void 0===o&&null!==c?m(e,c):o||null;if(f instanceof K||s(89),n instanceof t.XmlText)return M(n,f,l);if(n instanceof t.Map)return"linebreak"===l?r(n,f):a(n,"",f,l);if(n instanceof t.XmlElement)return A(n,f,l)}return i}function x(e,t,n){const o=t.getType(),i=e.editor._nodes.get(o);void 0===i&&s(88,o);const r=new i.klass;if(r.__parent=n,t._key=r.__key,t instanceof K){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof c?t.syncPropertiesAndTextFromYjs(e,null):t instanceof w&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(r.__key,t),r}function T(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(p(c,s,n)){"__state"===c&&L(n)&&(l||(l=s.getWritable()),S(o,l));continue}const a=s[c];let f=N(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 N(e,n){return e instanceof t.Map?e.get(n):e instanceof t.XmlText||e instanceof t.XmlElement?e.getAttribute(n):e[n]}function b(e,n,o){e instanceof t.Map?e.set(n,o):e.setAttribute(n,o)}function S(n,o){const s=N(n,"__state");s instanceof t.Map&&e.$getWritableNodeState(o).updateFromJSON(s.toJSON())}function k(e,n,o,s){const i=Object.keys(g(s,e)),r=e.editor.constructor;!function(e,n,o,s){const i=s.__state,r=N(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||b(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()})}b(n,c,f)}}}function C(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function $(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 c){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 E(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 O(e,t){e.doc.transact(t,e)}function v(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():v(i.__key,n):e.$getRoot().selectStart()}class w{_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);k(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&s(83);T(e,this._xmlElem,n,t)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function A(e,t,n){const o=new w(e,t,n);return e._collabNode=o,o}class K{_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),T(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 l=t[r],a=l.insert,f=l.delete;if(null!=l.retain)o+=l.retain;else if("number"==typeof f){let e=f;for(;e>0;){const{node:t,nodeIndex:s,offset:r,length:l}=$(this,o,!1);if(t instanceof K||t instanceof i||t instanceof w)n.splice(s,1),e-=1;else{if(!(t instanceof c))break;{const o=Math.min(e,l),i=0!==s?n[s-1]:null,a=t.getSize();if(0===r&&l===a){n.splice(s,1);const e=C(t._text,r,o-1,"");e.length>0&&(i instanceof c?i._text+=e:this._xmlText.delete(r,e.length))}else t._text=C(t._text,r,o,"");e-=o}}}}else{if(null==a)throw new Error("Unexpected delta format");if("string"==typeof a){const{node:e,offset:t}=$(this,o,!0);e instanceof c?e._text=C(e._text,t,0,a):this._xmlText.delete(t,a.length),o+=a.length}else{const t=a,{node:i,nodeIndex:r,length:l}=$(this,o,!1),f=m(e,t,this);if(i instanceof c&&l>0&&l<i._text.length){const e=i._text,t=e.length-l;i._text=C(e,t,l,""),n.splice(r+1,0,f),s=C(e,0,t,"")}else n.splice(r,0,f);null!==s&&f instanceof c&&(f._text=s+f._text,s=null),o+=1}}}}syncChildrenFromYjs(t){const o=this.getNode();null===o&&s(92);const r=o.__key,l=n.$createChildrenArray(o,null),a=l.length,f=this._children,d=f.length,u=t.collabNodeMap,h=new Set;let p,g,y=0,_=null;d!==a&&(g=o.getWritable());for(let n=0;n<d;n++){const a=l[y],m=f[n],T=m.getNode(),N=m._key;if(null!==T&&a===N){const n=e.$isTextNode(T);if(h.add(a),n)if(m._key=a,m instanceof K){const e=m._xmlText;m.syncPropertiesFromYjs(t,null),m.applyChildrenYjsDelta(t,e.toDelta()),m.syncChildrenFromYjs(t)}else m instanceof c?m.syncPropertiesAndTextFromYjs(t,null):m instanceof w?m.syncPropertiesFromYjs(t,null):m instanceof i||s(93);_=T,y++}else{if(void 0===p){p=new Set;for(let e=0;e<d;e++){const t=f[e]._key;""!==t&&p.add(t)}}if(null!==T&&void 0!==a&&!p.has(a)){const t=e.$getNodeByKeyOrThrow(a);e.removeFromParent(t),n--,y++;continue}g=o.getWritable();const s=x(t,m,r),i=s.__key;if(u.set(i,m),null===_){const e=g.getFirstChild();if(g.__first=i,null!==e){const t=e.getWritable();t.__prev=i,s.__next=t.__key}}else{const e=_.getWritable(),t=_.getNextSibling();if(e.__next=i,s.__prev=_.__key,null!==t){const e=t.getWritable();e.__prev=i,s.__next=e.__key}}n===d-1&&(g.__last=i),g.__size++,_=s}}for(let n=0;n<a;n++){const o=l[n];if(!h.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){k(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,o,s,i,r){const l=this._children[n],a=e.$getNodeByKeyOrThrow(o);l instanceof K&&e.$isElementNode(a)?(l.syncPropertiesFromLexical(t,a,s),l.syncChildrenFromLexical(t,a,s,i,r)):l instanceof c&&e.$isTextNode(a)?l.syncPropertiesAndTextFromLexical(t,a,s):l instanceof w&&e.$isDecoratorNode(a)&&l.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=y(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 m=g>f,x=_>d;if(m&&!x)for(;_<=d;++_){const n=a[_],o=y(t,e.$getNodeByKeyOrThrow(n),this);this.append(o),u.set(n,o)}else if(x&&!m)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 K)t.insertEmbed(s,e._xmlText);else if(e instanceof c){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof i?t.insertEmbed(s,e._map):e instanceof w&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,o){const r=this._children,l=r[t];if(void 0===l)return void 0===o&&s(94),void this.append(o);const a=l.getOffset();-1===a&&s(95);const f=this._xmlText;if(0!==n&&f.delete(a,l.getSize()),o instanceof K)f.insertEmbed(a,o._xmlText);else if(o instanceof c){const e=o._map;null===e.parent&&f.insertEmbed(a,e),f.insert(a+1,o._text)}else o instanceof i?f.insertEmbed(a,o._map):o instanceof w&&f.insertEmbed(a,o._xmlElem);if(0!==n){const o=r.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e)}void 0!==o?r.splice(t,n,o):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);t.get(this._key)===this&&t.delete(this._key)}}function M(e,t,n){const o=new K(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(328),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(329),e.$isTextNode(o)&&s(330),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)}}function F(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))p(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(r),r}function L(e){return Object.hasOwn(e,"collabNodeMap")}function j(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 c){l=i._parent._xmlText;const e=i.getOffset();if(-1===e)return null;r=e+1+r}else if(i instanceof K&&"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 R(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(323);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 I(e,n){return t.createAbsolutePositionFromRelativePosition(e,n.doc)}function X(e,n){if(null==e){if(null!=n)return!0}else if(null==n||!t.compareRelativePositions(e,n))return!0;return!1}function z(e,t){return{color:t,name:e,selection:null}}function D(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 Y(e,t){const n=t.selection;null!==n&&D(e,n)}function B(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 W(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 D(t,d));n.selection=s;const u=s.caret,h=s.color,p=s.selections,g=s.anchor,y=s.focus,_=g.key,m=y.key,x=i.get(_),T=i.get(m);if(null==x||null==T)return;let N;if(x===T&&e.$isLineBreakNode(x)){N=[r.getElementByKey(_).getBoundingClientRect()]}else{const e=o.createDOMRange(r,x,g.offset,T,y.offset);if(null===e)return;N=o.createRectsFromDOMRange(r,e)}const b=p.length,S=N.length;for(let e=0;e<S;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===S-1&&u.parentNode!==n&&n.appendChild(u)}for(let e=b-1;e>=S;e--){const t=p[e];c.removeChild(t),p.pop()}}function U(t,n){const{anchorPos:o,focusPos:s}=n,i=o?I(o,t):null,r=s?I(s,t):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(L(t)){const[e,t]=q(i.type,i.index),[n,o]=q(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=V(t.mapping,i),[a,f]=V(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 G(t,n){const o=n.awareness.getLocalState();if(null===o)return;const{anchorKey:s,anchorOffset:i,focusKey:r,focusOffset:l}=U(t,o);if(null!==s&&null!==r){const t=e.$getSelection();if(!e.$isRangeSelection(t))return;H(t.anchor,s,i),H(t.focus,r,l)}}function H(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 q(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof K){const{node:e,offset:o}=$(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function V(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 J(e,t){return t.awareness.getStates()}function Q(e,t,n){const{getAwarenessStates:o=J}=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(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=z(t,n),r.set(o,d)),s){const{anchorKey:t,anchorOffset:n,focusKey:o,focusOffset:s}=l.read(()=>U(e,f));if(null!==t&&null!==o)if(i=d.selection,null===i)i=B(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}}W(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&&(Y(e,t),r.delete(n))}}}function Z(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)&&(L(t)?(h=j(s.anchor,t),p=j(s.focus,t)):(h=R(s.anchor,t),p=R(s.focus,t))),(X(l,h)||X(c,p))&&i.setLocalState({...r,anchorPos:h,awarenessData:u,color:f,focusPos:p,focusing:d,name:a}))}const ee=e=>"UNDEFINED"===e.nodeName,te=(n,o,i,r,l,c,a)=>{let f=o.mapping.get(n);if(f&&i&&0===i.size&&!r)return f;const d=ee(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=te(n,o,new Set,!1,l,c,a);null!==t&&e.push(t)}else if(n instanceof t.XmlText){const t=oe(n,o,l,c,a);null!==t&&t.forEach(t=>{null!==t&&e.push(t)})}else s(327)};n.toArray().forEach(i),ne(f,e)}const h=n.getAttributes(l),p={...g(f,o)},y={};for(const e in h)e.startsWith(ge)?y[_e(e)]=h[e]:p[e]=h[e];if(T(o,p,f,i),i){const t=Object.keys(y).filter(e=>i.has(ye(e)));if(t.length>0){const n=e.$getWritableNodeState(f);for(const e of t)n.updateFromUnknown(e,y[e])}}else e.$getWritableNodeState(f).updateFromJSON(y);const _=f.getLatest();return o.mapping.set(n,_),_},ne=(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,[])},oe=(t,n,o,s,i)=>{const r=he(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={...g(o,n),...i.p},f=Object.fromEntries(Object.entries(i).filter(([e])=>e.startsWith(ge)).map(([e,t])=>[_e(e),t]));T(n,a,o,null),e.$getWritableNodeState(o).updateFromJSON(f)}const a=l.map(e=>e.getLatest());return n.mapping.set(t,a),a},se=(n,o)=>n instanceof Array?((e,n)=>{const o=new t.XmlText;return ue(o,e,n),o})(n,o):((n,o)=>{const s=new t.XmlElement(n.getType()),i={...pe(n,o),...me(n)};for(const e in i){const t=i[e];null!==t&&s.setAttribute(e,t)}return n instanceof e.ElementNode?(s.insert(0,le(n).map(e=>se(e,o))),o.mapping.set(s,n),s):s})(n,o),ie=e=>"object"==typeof e&&null!=e,re=(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||ie(r)&&ie(l)&&re(r,l)}return o},le=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},ce=(t,n,o)=>{const s=he(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(ge)));return t.insert===i.getTextContent()&&r===i.getType()&&re(l,pe(i,o))&&re(c,me(i))})},ae=(e,n,o)=>{if(e instanceof t.XmlElement&&!(n instanceof Array)&&Te(e,n)){const t=le(n);return e._length===t.length&&re(e.getAttributes(),{...pe(n,o),...me(n)})&&e.toArray().every((e,n)=>ae(e,t[n],o))}return e instanceof t.XmlText&&n instanceof Array&&ce(e,n,o)},fe=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),de=(e,n,o)=>{const s=e.toArray(),i=le(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(fe(o.mapping.get(e),n))d=!0;else if(!ae(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(fe(o.mapping.get(e),n))d=!0;else if(!ae(e,n,o))break}return{equalityFactor:a+f,foundMappedChild:d}},ue=(n,o,s)=>{s.mapping.set(n,o);const{nAttrs:i,str:r}=(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 r=pe(t,s);return 0===Object.keys(r).length&&(r=null),{attributes:Object.assign({},i,{...o!==e.TextNode.getType()&&{t:o},p:r,...me(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}=l(r,a,d);n.delete(p,h),n.insert(p,u),n.applyDelta(c.map(e=>({attributes:e.attributes,retain:e.insert.length})))},he=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>({...e,attributes:e.attributes??{}})),pe=(e,t)=>{const n=g(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},ge="s_",ye=e=>ge+e,_e=e=>{if(!e.startsWith(ge))throw new Error(`Invalid state key: ${e}`);return e.slice(ge.length)},me=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[ye(e)]=t;for(const[e,t]of o)s[ye(e.key)]=e.unparse(t);return s},xe=(n,o,s,i,r)=>{if(o instanceof t.XmlElement&&o.nodeName!==s.getType()&&(!ee(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={...pe(s,i),...me(s)};for(const n in t)null!=t[n]?e[n]!==t[n]&&"ychange"!==n&&o.setAttribute(n,t[n]):o.removeAttribute(n);for(const n in e)void 0===t[n]&&o.removeAttribute(n)}const l=le(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(fe(i.mapping.get(o),s))s instanceof e.ElementNode&&r.has(s.getKey())&&xe(n,o,s,i,r);else{if(!ae(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(fe(i.mapping.get(o),s))s instanceof e.ElementNode&&r.has(s.getKey())&&xe(n,o,s,i,r);else{if(!ae(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)ce(e,s,i)||ue(e,s,i),u+=1;else{let l=e instanceof t.XmlElement&&Te(e,s),c=d instanceof t.XmlElement&&Te(d,p);if(l&&c){const t=de(e,s,i),n=de(d,p,i);t.foundMappedChild&&!n.foundMappedChild?c=!1:!t.foundMappedChild&&n.foundMappedChild||t.equalityFactor<n.equalityFactor?l=!1:c=!1}l?(xe(n,e,s,i,r),u+=1):c?(xe(n,d,p,i,r),h+=1):(i.mapping.delete(o.get(u)),o.delete(u,1),o.insert(u,[se(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(se(l[t],i));o.insert(u,e)}},Te=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType();function Ne(n,o){if(o instanceof t.YMapEvent&&function(n,o){const{target:s}=o;if(!s._item||"__state"!==s._item.parentSub||void 0!==_(s)||!(s.parent instanceof t.XmlText||s.parent instanceof t.XmlElement||s.parent instanceof t.Map))return!1;const i=m(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,r=m(n,i);if(r instanceof K&&o instanceof t.YTextEvent){const{keysChanged:e,childListChanged:t,delta:s}=o;e.size>0&&r.syncPropertiesFromYjs(n,e),t&&(r.applyChildrenYjsDelta(n,s),r.syncChildrenFromYjs(n))}else if(r instanceof c&&o instanceof t.YMapEvent){const{keysChanged:e}=o;e.size>0&&r.syncPropertiesAndTextFromYjs(n,e)}else if(r instanceof w&&o instanceof t.YXmlEvent){const{attributesChanged:e}=o;e.size>0&&r.syncPropertiesFromYjs(n,e)}else s(82)}function be(t,n,o){const s=e.$getSelection();if(e.$isRangeSelection(s))if(E(s)){const i=t._selection;if(e.$isRangeSelection(i)&&(G(n,o),E(s))){v(s.anchor.key,t)}Z(n,o,i,e.$getSelection())}else G(n,o)}function Se(){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)te(o,e,n.attributesChanged,n.childListChanged);else if(o instanceof t.XmlText&&n instanceof t.YTextEvent){const n=o.parent;n instanceof t.XmlElement?te(n,e,new Set,!0):s(324)}else s(325)}const Ce=e.createCommand("CONNECTED_COMMAND"),$e=e.createCommand("TOGGLE_CONNECT_COMMAND");exports.CONNECTED_COMMAND=Ce,exports.TOGGLE_CONNECT_COMMAND=$e,exports.createBinding=function(e,n,o,i,r,l){null==i&&s(81);const c=M(i.get("root",t.XmlText),null,"root");return c._key="root",{...F(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{...F(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=I(n,e),c=I(o,e);null!==t&&null!==c&&([s,i]=q(t.type,t.index),[r,l]=q(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.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=Q,exports.syncLexicalUpdateToYjs=function(t,n,o,s,i,r,l,a){O(t,()=>{s.read(()=>{if(a.has(e.COLLABORATION_TAG)||a.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),a=s.get(n);if(a instanceof c)if(e.$isTextNode(l))i.push([a,l.__text]);else{const e=a.getOffset();if(-1===e)continue;const t=a._parent;a._normalized=!0,t._xmlText.delete(e,1),r.push(a)}}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(),f=o._selection;Z(t,n,f,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)}),O(t,()=>{s.read(()=>{i.has("root")&&xe(t.doc,t.root,e.$getRoot(),t,new Set(i.keys()));const s=e.$getSelection(),r=o._selection;Z(t,n,r,s)})}))},exports.syncYjsChangesToLexical=function(t,n,o,s,i=Q){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];Ne(t,n)}be(l,t,n),s||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{onUpdate:()=>{i(t,n),r.update(()=>Se())},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:()=>{Q(n,o),l.update(()=>Se())},skipTransforms:!0,tag:r?e.HISTORIC_TAG:e.COLLABORATION_TAG})};
|
package/LexicalYjs.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$getNodeByKey as e,$isLineBreakNode as t,$isTextNode as n,$getSelection as o,$isRangeSelection as s,createEditor as l,$isElementNode as i,$isDecoratorNode as r,$isRootNode as c,$getWritableNodeState as a,$getRoot as f,$getNodeByKeyOrThrow as u,removeFromParent as d,$addUpdateTag as h,SKIP_SCROLL_INTO_VIEW_TAG as _,HISTORIC_TAG as p,COLLABORATION_TAG as g,$createParagraphNode as y,createCommand as x}from"lexical";import{XmlText as m,Map as k,XmlElement as b,Doc as C,createAbsolutePositionFromRelativePosition as N,createRelativePositionFromTypeIndex as v,compareRelativePositions as w,YMapEvent as S,YTextEvent as T,YXmlEvent as P,UndoManager as F}from"yjs";import{$createChildrenArray as O}from"@lexical/offset";import{createDOMRange as E,createRectsFromDOMRange as M}from"@lexical/selection";function L(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.`)}class z{_map;_key;_parent;_type;constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const n=e(this._key);return t(n)?n: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 j(e,t){const n=new z(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(e){if(null===e)return null;const t=e.get(this._key);return n(t)?t:null}getNode(){const t=e(this._key);return n(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(e,t,n){const l=this.getPrevNode(n),i=t.__text;if(V(e,this._map,l,t),null!==l){const e=l.__text;if(e!==i){!function(e,t,n,l){const i=o();let r=l.length;if(s(i)&&i.isCollapsed()){const e=i.anchor;e.key===t&&(r=e.offset)}const c=function(e,t,n){const o=e.length,s=t.length;let l=0,i=0;for(;l<o&&l<s&&e[l]===t[l]&&l<n;)l++;for(;i+l<o&&i+l<s&&e[o-i-1]===t[s-i-1];)i++;for(;i+l<o&&i+l<s&&e[l]===t[l];)l++;return{index:l,insert:t.slice(l,s-i),remove:o-l-i}}(n,l,r);e.spliceText(c.index,c.remove,c.insert)}(this,t.__key,e,i),this._text=i}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();null===n&&L(84),J(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 Y(e,t,n,o){const s=new A(e,t,n,o);return e._collabNode=s,s}const D=new Set(["__key","__parent","__next","__prev","__state"]),I=new Set(["__first","__last","__size"]),K=new Set(["__cachedText"]),$=new Set(["__text"]);function W(e,t,o){if(D.has(e)||"function"==typeof t[e])return!0;if(n(t)){if($.has(e))return!0}else if(i(t)&&(I.has(e)||c(t)&&K.has(e)))return!0;const s=t.constructor,l=o.excludedProperties.get(s);return null!=l&&l.has(e)}function R(e,o,s){const l=o.__type;let c;if(i(o)){c=le(new m,s,l),c.syncPropertiesFromLexical(e,o,null),c.syncChildrenFromLexical(e,o,null,null,null)}else if(n(o)){c=Y(new k,o.__text,s,l),c.syncPropertiesAndTextFromLexical(e,o,null)}else if(t(o)){const e=new k;e.set("__type","linebreak"),c=j(e,s)}else if(r(o)){c=oe(new b,s,l),c.syncPropertiesFromLexical(e,o,null)}else L(86);return c._key=o.__key,c}function U(e){const t=q(e,"__type");return"string"!=typeof t&&void 0!==t&&L(87),t}function B(e,t,n){const o=t._collabNode;if(void 0===o){const o=e.editor._nodes,s=U(t);"string"!=typeof s&&L(87);void 0===o.get(s)&&L(88,s);const l=t.parent,i=void 0===n&&null!==l?B(e,l):n||null;if(i instanceof se||L(89),t instanceof m)return le(t,i,s);if(t instanceof k)return"linebreak"===s?j(t,i):Y(t,"",i,s);if(t instanceof b)return oe(t,i,s)}return o}function G(e,t,n){const o=t.getType(),s=e.editor._nodes.get(o);void 0===s&&L(88,o);const l=new s.klass;if(l.__parent=n,t._key=l.__key,t instanceof se){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof A?t.syncPropertiesAndTextFromYjs(e,null):t instanceof ne&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(l.__key,t),l}function J(e,t,n,o){const s=null===o?t instanceof k?Array.from(t.keys()):Object.keys(t.getAttributes()):Array.from(o);let i;for(let o=0;o<s.length;o++){const r=s[o];if(W(r,n,e)){"__state"===r&&(i||(i=n.getWritable()),Q(e,t,i));continue}const c=n[r];let a=q(t,r);if(c!==a){if(a instanceof C){const t=e.docMap;c instanceof C&&t.delete(c.guid);const n=l(),o=a.guid;n._key=o,t.set(o,a),a=n}void 0===i&&(i=n.getWritable()),i[r]=a}}}function q(e,t){return e instanceof k?e.get(t):e.getAttribute(t)}function H(e,t,n){e instanceof k?e.set(t,n):e.setAttribute(t,n)}function Q(e,t,n){const o=q(t,"__state");o instanceof k&&a(n).updateFromJSON(o.toJSON())}function V(e,t,n,o){const s=o.__type,l=e.nodeProperties;let i=l.get(s);void 0===i&&(i=Object.keys(o).filter(t=>!W(t,o,e)),l.set(s,i));const r=e.editor.constructor;!function(e,t,n,o){const s=o.__state,l=q(t,"__state");if(!s)return;const[i,r]=s.getInternalState(),c=n&&n.__state,a=l instanceof k?l:new k;if(c===s)return;const[f,u]=c&&a.doc?c.getInternalState():[void 0,new Map];if(i)for(const[e,t]of Object.entries(i))f&&t!==f[e]&&a.set(e,t);for(const[e,t]of r)u.get(e)!==t&&a.set(e.key,e.unparse(t));l||H(t,"__state",a)}(0,t,n,o);for(let s=0;s<i.length;s++){const l=i[s],c=null===n?void 0:n[l];let a=o[l];if(c!==a){if(a instanceof r){const t=e.docMap;let n;if(c instanceof r){const e=c._key;n=t.get(e),t.delete(e)}const s=n||new C,l=s.guid;a._key=l,t.set(l,s),a=s,e.editor.update(()=>{o.markDirty()})}H(t,l,a)}}}function X(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function Z(e,t,n){let o=0,s=0;const l=e._children,i=l.length;for(;s<i;s++){const e=l[s],r=o;o+=e.getSize();if((n?o>=t:o>t)&&e instanceof A){let n=t-r-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:r};if(s===i-1)return{length:0,node:null,nodeIndex:s+1,offset:r+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function ee(e){const t=e.anchor,o=e.focus;let s=!1;try{const e=t.getNode(),l=o.getNode();(!e.isAttached()||!l.isAttached()||n(e)&&t.offset>e.getTextContentSize()||n(l)&&o.offset>l.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function te(t,n){const o=n._nodeMap.get(t);if(!o)return void f().selectStart();const s=o.__prev;let l=null;s&&(l=e(s)),null===l&&null!==o.__parent&&(l=e(o.__parent)),null!==l?null!==l&&l.isAttached()?l.selectEnd():te(l.__key,n):f().selectStart()}class ne{_xmlElem;_key;_parent;_type;constructor(e,t,n){this._key="",this._xmlElem=e,this._parent=t,this._type=n}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return r(t)?t:null}getNode(){const t=e(this._key);return r(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);V(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&L(83);J(e,this._xmlElem,n,t)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function oe(e,t,n){const o=new ne(e,t,n);return e._collabNode=o,o}class se{_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 i(t)?t:null}getNode(){const t=e(this._key);return i(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&&L(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&L(91),J(e,this._xmlText,n,t)}applyChildrenYjsDelta(e,t){const n=this._children;let o=0,s=null;for(let l=0;l<t.length;l++){const i=t[l],r=i.insert,c=i.delete;if(null!=i.retain)o+=i.retain;else if("number"==typeof c){let e=c;for(;e>0;){const{node:t,nodeIndex:s,offset:l,length:i}=Z(this,o,!1);if(t instanceof se||t instanceof z||t instanceof ne)n.splice(s,1),e-=1;else{if(!(t instanceof A))break;{const o=Math.min(e,i),r=0!==s?n[s-1]:null,c=t.getSize();if(0===l&&i===c){n.splice(s,1);const e=X(t._text,l,o-1,"");e.length>0&&(r instanceof A?r._text+=e:this._xmlText.delete(l,e.length))}else t._text=X(t._text,l,o,"");e-=o}}}}else{if(null==r)throw new Error("Unexpected delta format");if("string"==typeof r){const{node:e,offset:t}=Z(this,o,!0);e instanceof A?e._text=X(e._text,t,0,r):this._xmlText.delete(t,r.length),o+=r.length}else{const t=r,{node:l,nodeIndex:i,length:c}=Z(this,o,!1),a=B(e,t,this);if(l instanceof A&&c>0&&c<l._text.length){const e=l._text,t=e.length-c;l._text=X(e,t,c,""),n.splice(i+1,0,a),s=X(e,0,t,"")}else n.splice(i,0,a);null!==s&&a instanceof A&&(a._text=s+a._text,s=null),o+=1}}}}syncChildrenFromYjs(e){const t=this.getNode();null===t&&L(92);const o=t.__key,s=O(t,null),l=s.length,i=this._children,r=i.length,c=e.collabNodeMap,a=new Set;let f,h,_=0,p=null;r!==l&&(h=t.getWritable());for(let l=0;l<r;l++){const g=s[_],y=i[l],x=y.getNode(),m=y._key;if(null!==x&&g===m){const t=n(x);if(a.add(g),t)if(y._key=g,y instanceof se){const t=y._xmlText;y.syncPropertiesFromYjs(e,null),y.applyChildrenYjsDelta(e,t.toDelta()),y.syncChildrenFromYjs(e)}else y instanceof A?y.syncPropertiesAndTextFromYjs(e,null):y instanceof ne?y.syncPropertiesFromYjs(e,null):y instanceof z||L(93);p=x,_++}else{if(void 0===f){f=new Set;for(let e=0;e<r;e++){const t=i[e]._key;""!==t&&f.add(t)}}if(null!==x&&void 0!==g&&!f.has(g)){const e=u(g);d(e),l--,_++;continue}h=t.getWritable();const n=G(e,y,o),s=n.__key;if(c.set(s,y),null===p){const e=h.getFirstChild();if(h.__first=s,null!==e){const t=e.getWritable();t.__prev=s,n.__next=t.__key}}else{const e=p.getWritable(),t=p.getNextSibling();if(e.__next=s,n.__prev=p.__key,null!==t){const e=t.getWritable();e.__prev=s,n.__next=e.__key}}l===r-1&&(h.__last=s),h.__size++,p=n}}for(let t=0;t<l;t++){const n=s[t];if(!a.has(n)){const t=u(n),o=e.collabNodeMap.get(n);void 0!==o&&o.destroy(e),d(t)}}}syncPropertiesFromLexical(e,t,n){V(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(e,t,o,s,l,c){const a=this._children[t],f=u(o);a instanceof se&&i(f)?(a.syncPropertiesFromLexical(e,f,s),a.syncChildrenFromLexical(e,f,s,l,c)):a instanceof A&&n(f)?a.syncPropertiesAndTextFromLexical(e,f,s):a instanceof ne&&r(f)&&a.syncPropertiesFromLexical(e,f,s)}syncChildrenFromLexical(e,t,n,o,s){const l=this.getPrevNode(n),i=null===l?[]:O(l,n),r=O(t,null),c=i.length-1,a=r.length-1,f=e.collabNodeMap;let d,h,_=0,p=0;for(;_<=c&&p<=a;){const t=i[_],l=r[p];if(t===l)this._syncChildFromLexical(e,p,l,n,o,s),_++,p++;else{void 0===d&&(d=new Set(i)),void 0===h&&(h=new Set(r));const n=h.has(t),o=d.has(l);if(n){const t=R(e,u(l),this);f.set(l,t),o?(this.splice(e,p,1,t),_++,p++):(this.splice(e,p,0,t),p++)}else this.splice(e,p,1),_++}}const g=_>c,y=p>a;if(g&&!y)for(;p<=a;++p){const t=r[p],n=R(e,u(t),this);this.append(n),f.set(t,n)}else if(y&&!g)for(let t=this._children.length-1;t>=p;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 se)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 z?t.insertEmbed(s,e._map):e instanceof ne&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,o){const s=this._children,l=s[t];if(void 0===l)return void 0===o&&L(94),void this.append(o);const i=l.getOffset();-1===i&&L(95);const r=this._xmlText;if(0!==n&&r.delete(i,l.getSize()),o instanceof se)r.insertEmbed(i,o._xmlText);else if(o instanceof A){const e=o._map;null===e.parent&&r.insertEmbed(i,e),r.insert(i+1,o._text)}else o instanceof z?r.insertEmbed(i,o._map):o instanceof ne&&r.insertEmbed(i,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 le(e,t,n){const o=new se(e,t,n);return e._collabNode=o,o}function ie(e,t,n,o,s,l){null==o&&L(81);const i=le(o.get("root",m),null,"root");return i._key="root",{clientID:o.clientID,collabNodeMap:new Map,cursors:new Map,cursorsContainer:null,doc:o,docMap:s,editor:e,excludedProperties:l||new Map,id:n,nodeProperties:new Map,root:i}}function re(e,t){const o=t.collabNodeMap.get(e.key);if(void 0===o)return null;let s=e.offset,l=o.getSharedType();if(o instanceof A){l=o._parent._xmlText;const e=o.getOffset();if(-1===e)return null;s=e+1+s}else if(o instanceof se&&"element"===e.type){const t=e.getNode();i(t)||L(184);let o=0,l=0,r=t.getFirstChild();for(;null!==r&&l++<s;)n(r)?o+=r.getTextContentSize()+1:o++,r=r.getNextSibling();s=o}return v(l,s)}function ce(e,t){return N(e,t.doc)}function ae(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!w(e,t))return!0;return!1}function fe(e,t){return{color:t,name:e,selection:null}}function ue(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 de(e,t){const n=t.selection;null!==n&&ue(e,n)}function he(e,t,n,o,s){const l=e.color,i=document.createElement("span");i.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${l};z-index:10;`;const r=document.createElement("span");return r.textContent=e.name,r.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${l};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`,i.appendChild(r),{anchor:{key:t,offset:n},caret:i,color:l,focus:{key:o,offset:s},name:r,selections:[]}}function _e(e,n,o,s){const l=e.editor,i=l.getRootElement(),r=e.cursorsContainer;if(null===r||null===i)return;const c=r.offsetParent;if(null===c)return;const a=c.getBoundingClientRect(),f=n.selection;if(null===o)return null===f?void 0:(n.selection=null,void ue(e,f));n.selection=o;const u=o.caret,d=o.color,h=o.selections,_=o.anchor,p=o.focus,g=_.key,y=p.key,x=s.get(g),m=s.get(y);if(null==x||null==m)return;let k;if(x===m&&t(x)){k=[l.getElementByKey(g).getBoundingClientRect()]}else{const e=E(l,x,_.offset,m,p.offset);if(null===e)return;k=M(l,e)}const b=h.length,C=k.length;for(let e=0;e<C;e++){const t=k[e];let n=h[e];if(void 0===n){n=document.createElement("span"),h[e]=n;const t=document.createElement("span");n.appendChild(t),r.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:${d};opacity:0.3;`,e===C-1&&u.parentNode!==n&&n.appendChild(u)}for(let e=b-1;e>=C;e--){const t=h[e];r.removeChild(t),h.pop()}}function pe(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,l=0,i=null,r=0;if(null!==n&&null!==o){const t=ce(n,e),c=ce(o,e);null!==t&&null!==c&&([s,l]=xe(t.type,t.index),[i,r]=xe(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:l,focusCollabNode:i,focusOffset:r}}function ge(e,t){const n=t.awareness.getLocalState();if(null===n)return;const{anchorCollabNode:l,anchorOffset:i,focusCollabNode:r,focusOffset:c}=pe(e,n);if(null!==l&&null!==r){const e=l.getKey(),t=r.getKey(),n=o();if(!s(n))return;ye(n.anchor,e,i),ye(n.focus,t,c)}}function ye(t,o,s){if(t.key!==o||t.offset!==s){let l=e(o);if(null!==l&&!i(l)&&!n(l)){const e=l.getParentOrThrow();o=e.getKey(),s=l.getIndexWithinParent(),l=e}t.set(o,s,i(l)?"element":"text")}}function xe(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof se){const{node:e,offset:o}=Z(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function me(e,t){return t.awareness.getStates()}function ke(e,t,n){const{getAwarenessStates:o=me}=n??{},s=Array.from(o(e,t)),l=e.clientID,i=e.cursors,r=e.editor._editorState._nodeMap,c=new Set;for(let t=0;t<s.length;t++){const n=s[t],[o,a]=n;if(o!==l){c.add(o);const{name:t,color:n,focusing:s}=a;let l=null,f=i.get(o);if(void 0===f&&(f=fe(t,n),i.set(o,f)),s){const{anchorCollabNode:t,anchorOffset:n,focusCollabNode:o,focusOffset:s}=pe(e,a);if(null!==t&&null!==o){const e=t.getKey(),i=o.getKey();if(l=f.selection,null===l)l=he(f,e,n,i,s);else{const t=l.anchor,o=l.focus;t.key=e,t.offset=n,o.key=i,o.offset=s}}}_e(e,f,l,r)}}const a=Array.from(i.keys());for(let t=0;t<a.length;t++){const n=a[t];if(!c.has(n)){const t=i.get(n);void 0!==t&&(de(e,t),i.delete(n))}}}function be(e,t,n,o){const l=t.awareness,i=l.getLocalState();if(null===i)return;const{anchorPos:r,focusPos:c,name:a,color:f,focusing:u,awarenessData:d}=i;let h=null,_=null;(null!==o&&(null===r||o.is(n))||null!==n)&&(s(o)&&(h=re(o.anchor,e),_=re(o.focus,e)),(ae(r,h)||ae(c,_))&&l.setLocalState({...i,anchorPos:h,awarenessData:d,color:f,focusPos:_,focusing:u,name:a}))}function Ce(e,t){if(t instanceof S&&function(e,t){const{target:n}=t;if(!n._item||"__state"!==n._item.parentSub||void 0!==U(n)||!(n.parent instanceof m||n.parent instanceof b||n.parent instanceof k))return!1;const o=B(e,n.parent).getNode();if(o){const e=a(o.getWritable());for(const o of t.keysChanged)e.updateFromUnknown(o,n.get(o))}return!0}(e,t))return;const{target:n}=t,o=B(e,n);if(o instanceof se&&t instanceof T){const{keysChanged:n,childListChanged:s,delta:l}=t;n.size>0&&o.syncPropertiesFromYjs(e,n),s&&(o.applyChildrenYjsDelta(e,l),o.syncChildrenFromYjs(e))}else if(o instanceof A&&t instanceof S){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof ne&&t instanceof P){const{attributesChanged:n}=t;n.size>0&&o.syncPropertiesFromYjs(e,n)}else L(82)}function Ne(e,t,n,l,i=ke){const r=e.editor,c=r._editorState;n.forEach(e=>e.delta),r.update(()=>{for(let t=0;t<n.length;t++){const o=n[t];Ce(e,o)}const i=o();if(s(i))if(ee(i)){const n=c._selection;if(s(n)&&(ge(e,t),ee(i))){te(i.anchor.key,c)}be(e,t,n,o())}else ge(e,t);l||h(_)},{onUpdate:()=>{i(e,t),r.update(()=>{0===f().getChildrenSize()&&f().append(y())})},skipTransforms:!0,tag:l?p:g})}function ve(t,s,l,i,r,c,a,u){!function(e,t){e.doc.transact(t,e)}(t,()=>{i.read(()=>{if(u.has(g)||u.has(p))return void(a.size>0&&function(t,o){const s=Array.from(o),l=t.collabNodeMap,i=[],r=[];for(let t=0;t<s.length;t++){const o=s[t],c=e(o),a=l.get(o);if(a instanceof A)if(n(c))i.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),r.push(a)}}for(let e=0;e<r.length;e++){const t=r[e],n=t.getKey();l.delete(n);const o=t._parent._children,s=o.indexOf(t);o.splice(s,1)}for(let e=0;e<i.length;e++){const[t,n]=i[e];t._text=n}}(t,a));if(r.has("root")){const e=l._nodeMap,n=f(),o=t.root;o.syncPropertiesFromLexical(t,n,e),o.syncChildrenFromLexical(t,n,e,r,c)}const i=o(),d=l._selection;be(t,s,d,i)})})}const we=x("CONNECTED_COMMAND"),Se=x("TOGGLE_CONNECT_COMMAND");function Te(e,t){return new F(t,{trackedOrigins:new Set([e,null])})}function Pe(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})}function Fe(e,t,n,o,s){const{awareness:l}=e;let i=l.getLocalState();null===i&&(i={anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t}),i.focusing=o,l.setLocalState(i)}export{we as CONNECTED_COMMAND,Se as TOGGLE_CONNECT_COMMAND,ie as createBinding,Te as createUndoManager,pe as getAnchorAndFocusCollabNodesForUserState,Pe as initLocalState,Fe as setLocalStateFocus,ke as syncCursorPositions,ve as syncLexicalUpdateToYjs,Ne as syncYjsChangesToLexical};
|
|
9
|
+
import{$getNodeByKey as e,$isLineBreakNode as t,$isTextNode as n,$getSelection as o,$isRangeSelection as s,createEditor as i,$isElementNode as r,$isDecoratorNode as l,$isRootNode as c,$getWritableNodeState as a,$getRoot as f,$getNodeByKeyOrThrow as u,removeFromParent as d,RootNode as h,ElementNode as p,TextNode as g,COLLABORATION_TAG as _,HISTORIC_TAG as y,$addUpdateTag as m,SKIP_SCROLL_INTO_VIEW_TAG as x,$createParagraphNode as T,createCommand as b}from"lexical";import{XmlText as k,Map as S,XmlElement as N,Doc as w,createAbsolutePositionFromRelativePosition as C,createRelativePositionFromTypeIndex as v,compareRelativePositions as O,XmlHook as K,ContentString as P,ContentFormat as M,iterateDeletedStructs as E,Item as F,YMapEvent as A,YTextEvent as j,YXmlEvent as z,UndoManager as L}from"yjs";import{$createChildrenArray as Y}from"@lexical/offset";import{createDOMRange as D,createRectsFromDOMRange as $}from"@lexical/selection";function I(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.`)}class W{_map;_key;_parent;_type;constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const n=e(this._key);return t(n)?n: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 U(e,t){const n=new W(e,t);return e._collabNode=n,n}function R(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 B{_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 n(t)?t:null}getNode(){const t=e(this._key);return n(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(e,t,n){const i=this.getPrevNode(n),r=t.__text;if(le(e,this._map,i,t),null!==i){const e=i.__text;if(e!==r){!function(e,t,n,i){const r=o();let l=i.length;if(s(r)&&r.isCollapsed()){const e=r.anchor;e.key===t&&(l=e.offset)}const c=R(n,i,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&&I(84),oe(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 J(e,t,n,o){const s=new B(e,t,n,o);return e._collabNode=s,s}const q=new Set(["__key","__parent","__next","__prev","__state"]),G=new Set(["__first","__last","__size"]),H=new Set(["__cachedText"]),Q=new Set(["__text"]);function V(e,t,o){if(q.has(e)||"function"==typeof t[e])return!0;if(n(t)){if(Q.has(e))return!0}else if(r(t)&&(G.has(e)||c(t)&&H.has(e)))return!0;const s=t.constructor,i=o.excludedProperties.get(s);return null!=i&&i.has(e)}function X(e,t){const n=e.__type,{nodeProperties:o}=t,s=o.get(n);return void 0===s&&I(326,n),s}function Z(e,o,s){const i=o.__type;let c;if(r(o)){c=_e(new k,s,i),c.syncPropertiesFromLexical(e,o,null),c.syncChildrenFromLexical(e,o,null,null,null)}else if(n(o)){c=J(new S,o.__text,s,i),c.syncPropertiesAndTextFromLexical(e,o,null)}else if(t(o)){const e=new S;e.set("__type","linebreak"),c=U(e,s)}else if(l(o)){c=pe(new N,s,i),c.syncPropertiesFromLexical(e,o,null)}else I(86);return c._key=o.__key,c}function ee(e){const t=se(e,"__type");return"string"!=typeof t&&void 0!==t&&I(87),t}function te(e,t,n){const o=t._collabNode;if(void 0===o){const o=e.editor._nodes,s=ee(t);"string"!=typeof s&&I(87);void 0===o.get(s)&&I(88,s);const i=t.parent,r=void 0===n&&null!==i?te(e,i):n||null;if(r instanceof ge||I(89),t instanceof k)return _e(t,r,s);if(t instanceof S)return"linebreak"===s?U(t,r):J(t,"",r,s);if(t instanceof N)return pe(t,r,s)}return o}function ne(e,t,n){const o=t.getType(),s=e.editor._nodes.get(o);void 0===s&&I(88,o);const i=new s.klass;if(i.__parent=n,t._key=i.__key,t instanceof ge){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof B?t.syncPropertiesAndTextFromYjs(e,null):t instanceof he&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(i.__key,t),i}function oe(e,t,n,o){const s=null===o?t instanceof S?Array.from(t.keys()):t instanceof k||t instanceof N?Object.keys(t.getAttributes()):Object.keys(t):Array.from(o);let r;for(let o=0;o<s.length;o++){const l=s[o];if(V(l,n,e)){"__state"===l&&be(e)&&(r||(r=n.getWritable()),re(t,r));continue}const c=n[l];let a=se(t,l);if(c!==a){if(a instanceof w){const t=e.docMap;c instanceof w&&t.delete(c.guid);const n=i(),o=a.guid;n._key=o,t.set(o,a),a=n}void 0===r&&(r=n.getWritable()),r[l]=a}}}function se(e,t){return e instanceof S?e.get(t):e instanceof k||e instanceof N?e.getAttribute(t):e[t]}function ie(e,t,n){e instanceof S?e.set(t,n):e.setAttribute(t,n)}function re(e,t){const n=se(e,"__state");n instanceof S&&a(t).updateFromJSON(n.toJSON())}function le(e,t,n,o){const s=Object.keys(X(o,e)),i=e.editor.constructor;!function(e,t,n,o){const s=o.__state,i=se(t,"__state");if(!s)return;const[r,l]=s.getInternalState(),c=n&&n.__state,a=i instanceof S?i:new S;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||ie(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 w,r=s.guid;a._key=r,t.set(r,s),a=s,e.editor.update(()=>{o.markDirty()})}ie(t,l,a)}}}function ce(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function ae(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 B){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 fe(e){const t=e.anchor,o=e.focus;let s=!1;try{const e=t.getNode(),i=o.getNode();(!e.isAttached()||!i.isAttached()||n(e)&&t.offset>e.getTextContentSize()||n(i)&&o.offset>i.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function ue(e,t){e.doc.transact(t,e)}function de(t,n){const o=n._nodeMap.get(t);if(!o)return void f().selectStart();const s=o.__prev;let i=null;s&&(i=e(s)),null===i&&null!==o.__parent&&(i=e(o.__parent)),null!==i?null!==i&&i.isAttached()?i.selectEnd():de(i.__key,n):f().selectStart()}class he{_xmlElem;_key;_parent;_type;constructor(e,t,n){this._key="",this._xmlElem=e,this._parent=t,this._type=n}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return l(t)?t:null}getNode(){const t=e(this._key);return l(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);le(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&I(83);oe(e,this._xmlElem,n,t)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function pe(e,t,n){const o=new he(e,t,n);return e._collabNode=o,o}class ge{_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 t=e(this._key);return r(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&&I(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&I(91),oe(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}=ae(this,o,!1);if(t instanceof ge||t instanceof W||t instanceof he)n.splice(s,1),e-=1;else{if(!(t instanceof B))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=ce(t._text,i,o-1,"");e.length>0&&(l instanceof B?l._text+=e:this._xmlText.delete(i,e.length))}else t._text=ce(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}=ae(this,o,!0);e instanceof B?e._text=ce(e._text,t,0,l):this._xmlText.delete(t,l.length),o+=l.length}else{const t=l,{node:i,nodeIndex:r,length:c}=ae(this,o,!1),a=te(e,t,this);if(i instanceof B&&c>0&&c<i._text.length){const e=i._text,t=e.length-c;i._text=ce(e,t,c,""),n.splice(r+1,0,a),s=ce(e,0,t,"")}else n.splice(r,0,a);null!==s&&a instanceof B&&(a._text=s+a._text,s=null),o+=1}}}}syncChildrenFromYjs(e){const t=this.getNode();null===t&&I(92);const o=t.__key,s=Y(t,null),i=s.length,r=this._children,l=r.length,c=e.collabNodeMap,a=new Set;let f,h,p=0,g=null;l!==i&&(h=t.getWritable());for(let i=0;i<l;i++){const _=s[p],y=r[i],m=y.getNode(),x=y._key;if(null!==m&&_===x){const t=n(m);if(a.add(_),t)if(y._key=_,y instanceof ge){const t=y._xmlText;y.syncPropertiesFromYjs(e,null),y.applyChildrenYjsDelta(e,t.toDelta()),y.syncChildrenFromYjs(e)}else y instanceof B?y.syncPropertiesAndTextFromYjs(e,null):y instanceof he?y.syncPropertiesFromYjs(e,null):y instanceof W||I(93);g=m,p++}else{if(void 0===f){f=new Set;for(let e=0;e<l;e++){const t=r[e]._key;""!==t&&f.add(t)}}if(null!==m&&void 0!==_&&!f.has(_)){const e=u(_);d(e),i--,p++;continue}h=t.getWritable();const n=ne(e,y,o),s=n.__key;if(c.set(s,y),null===g){const e=h.getFirstChild();if(h.__first=s,null!==e){const t=e.getWritable();t.__prev=s,n.__next=t.__key}}else{const e=g.getWritable(),t=g.getNextSibling();if(e.__next=s,n.__prev=g.__key,null!==t){const e=t.getWritable();e.__prev=s,n.__next=e.__key}}i===l-1&&(h.__last=s),h.__size++,g=n}}for(let t=0;t<i;t++){const n=s[t];if(!a.has(n)){const t=u(n),o=e.collabNodeMap.get(n);void 0!==o&&o.destroy(e),d(t)}}}syncPropertiesFromLexical(e,t,n){le(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(e,t,o,s,i,c){const a=this._children[t],f=u(o);a instanceof ge&&r(f)?(a.syncPropertiesFromLexical(e,f,s),a.syncChildrenFromLexical(e,f,s,i,c)):a instanceof B&&n(f)?a.syncPropertiesAndTextFromLexical(e,f,s):a instanceof he&&l(f)&&a.syncPropertiesFromLexical(e,f,s)}syncChildrenFromLexical(e,t,n,o,s){const i=this.getPrevNode(n),r=null===i?[]:Y(i,n),l=Y(t,null),c=r.length-1,a=l.length-1,f=e.collabNodeMap;let d,h,p=0,g=0;for(;p<=c&&g<=a;){const t=r[p],i=l[g];if(t===i)this._syncChildFromLexical(e,g,i,n,o,s),p++,g++;else{void 0===d&&(d=new Set(r)),void 0===h&&(h=new Set(l));const n=h.has(t),o=d.has(i);if(n){const t=Z(e,u(i),this);f.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>c,y=g>a;if(_&&!y)for(;g<=a;++g){const t=l[g],n=Z(e,u(t),this);this.append(n),f.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 ge)t.insertEmbed(s,e._xmlText);else if(e instanceof B){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof W?t.insertEmbed(s,e._map):e instanceof he&&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&&I(94),void this.append(o);const r=i.getOffset();-1===r&&I(95);const l=this._xmlText;if(0!==n&&l.delete(r,i.getSize()),o instanceof ge)l.insertEmbed(r,o._xmlText);else if(o instanceof B){const e=o._map;null===e.parent&&l.insertEmbed(r,e),l.insert(r+1,o._text)}else o instanceof W?l.insertEmbed(r,o._map):o instanceof he&&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 _e(e,t,n){const o=new ge(e,t,n);return e._collabNode=o,o}class ye{_nodeMap=new Map;_sharedTypeToNodeKeys=new Map;_nodeKeyToSharedType=new Map;set(e,t){const o=t instanceof Array;this.delete(e);const s=o?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 k){if(o||I(328),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 o&&I(329),n(t)&&I(330),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 k){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)}}function me(e,t,n,o,s){null==n&&I(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))V(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(i),i}function xe(e,t,n,o,s,i){null==o&&I(81);const r=_e(o.get("root",k),null,"root");return r._key="root",{...me(e,n,o,s,i),collabNodeMap:new Map,root:r}}function Te(e,t,n,o,s={}){null==n&&I(81);const{excludedProperties:i,rootName:r="root-v2"}=s;return{...me(e,t,n,o,i),mapping:new ye,root:n.get(r,N)}}function be(e){return Object.hasOwn(e,"collabNodeMap")}function ke(e,t){const o=t.collabNodeMap.get(e.key);if(void 0===o)return null;let s=e.offset,i=o.getSharedType();if(o instanceof B){i=o._parent._xmlText;const e=o.getOffset();if(-1===e)return null;s=e+1+s}else if(o instanceof ge&&"element"===e.type){const t=e.getNode();r(t)||I(184);let o=0,i=0,l=t.getFirstChild();for(;null!==l&&i++<s;)n(l)?o+=l.getTextContentSize()+1:o++,l=l.getNextSibling();s=o}return v(i,s)}function Se(e,t){const{mapping:o}=t,{offset:s}=e,i=e.getNode(),l=o.getSharedType(i);if(void 0===l)return null;if("text"===e.type){n(i)||I(323);let e=i.getPreviousSibling(),t=s;for(;n(e);)t+=e.getTextContentSize(),e=e.getPreviousSibling();return v(l,t)}if("element"===e.type){r(i)||I(184);let e=0,t=i.getFirstChild();for(;null!==t&&e<s;){if(n(t)){let e=t.getNextSibling();for(;n(e);)e=e.getNextSibling()}e++,t=t.getNextSibling()}return v(l,e)}return null}function Ne(e,t){return C(e,t.doc)}function we(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!O(e,t))return!0;return!1}function Ce(e,t){return{color:t,name:e,selection:null}}function ve(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 Oe(e,t){const n=t.selection;null!==n&&ve(e,n)}function Ke(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(e,n,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=n.selection;if(null===o)return null===f?void 0:(n.selection=null,void ve(e,f));n.selection=o;const u=o.caret,d=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&&t(m)){T=[i.getElementByKey(_).getBoundingClientRect()]}else{const e=D(i,m,p.offset,x,g.offset);if(null===e)return;T=$(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:${d};opacity:0.3;`,e===k-1&&u.parentNode!==n&&n.appendChild(u)}for(let e=b-1;e>=k;e--){const t=h[e];l.removeChild(t),h.pop()}}function Me(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,i=0,r=null,l=0;if(null!==n&&null!==o){const t=Ne(n,e),c=Ne(o,e);null!==t&&null!==c&&([s,i]=je(t.type,t.index),[r,l]=je(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:i,focusCollabNode:r,focusOffset:l}}function Ee(e,t){const{anchorPos:o,focusPos:s}=t,i=o?Ne(o,e):null,r=s?Ne(s,e):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(be(e)){const[e,t]=je(i.type,i.index),[n,o]=je(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=ze(e.mapping,i),[a,f]=ze(e.mapping,r);if(a&&l&&(a!==l||f!==c)){const e=a.isBefore(l),t=e?a:l,o=e?f:c;n(t)&&n(t.getNextSibling())&&o===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 Fe(e,t){const n=t.awareness.getLocalState();if(null===n)return;const{anchorKey:i,anchorOffset:r,focusKey:l,focusOffset:c}=Ee(e,n);if(null!==i&&null!==l){const e=o();if(!s(e))return;Ae(e.anchor,i,r),Ae(e.focus,l,c)}}function Ae(t,o,s){if(t.key!==o||t.offset!==s){let i=e(o);if(null!==i&&!r(i)&&!n(i)){const e=i.getParentOrThrow();o=e.getKey(),s=i.getIndexWithinParent(),i=e}t.set(o,s,r(i)?"element":"text")}}function je(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof ge){const{node:e,offset:o}=ae(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function ze(e,t){const o=t.type,s=t.index;if(o instanceof N){const t=e.get(o);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,n(e))for(;l<c.length&&n(c[l]);)l+=1}return[t,l]}{const t=e.get(o);if(void 0===t)return[null,0];let n=0,i=s;for(;i>t[n].getTextContentSize()&&n+1<t.length;)i-=t[n].getTextContentSize(),n++;const r=t[n];return[r,Math.min(i,r.getTextContentSize())]}}function Le(e,t){return t.awareness.getStates()}function Ye(e,t,n){const{getAwarenessStates:o=Le}=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(o!==i){a.add(o);const{name:t,color:n,focusing:s}=f;let i=null,u=r.get(o);if(void 0===u&&(u=Ce(t,n),r.set(o,u)),s){const{anchorKey:t,anchorOffset:n,focusKey:o,focusOffset:s}=l.read(()=>Ee(e,f));if(null!==t&&null!==o)if(i=u.selection,null===i)i=Ke(u,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,u,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&&(Oe(e,t),r.delete(n))}}}function De(e,t,n,o){const i=t.awareness,r=i.getLocalState();if(null===r)return;const{anchorPos:l,focusPos:c,name:a,color:f,focusing:u,awarenessData:d}=r;let h=null,p=null;(null!==o&&(null===l||o.is(n))||null!==n)&&(s(o)&&(be(e)?(h=ke(o.anchor,e),p=ke(o.focus,e)):(h=Se(o.anchor,e),p=Se(o.focus,e))),(we(l,h)||we(c,p))&&i.setLocalState({...r,anchorPos:h,awarenessData:d,color:f,focusPos:p,focusing:u,name:a}))}const $e=e=>"UNDEFINED"===e.nodeName,Ie=(e,t,n,o,s,i,r)=>{let l=t.mapping.get(e);if(l&&n&&0===n.size&&!o)return l;const c=$e(e)?h.getType():e.nodeName,f=t.editor._nodes.get(c);if(void 0===f)throw new Error(`$createOrUpdateNodeFromYElement: Node ${c} is not registered`);if(l||(l=new f.klass,n=null,o=!0),o&&l instanceof p){const n=[],o=e=>{if(e instanceof N){const o=Ie(e,t,new Set,!1,s,i,r);null!==o&&n.push(o)}else if(e instanceof k){const o=Ue(e,t,s,i,r);null!==o&&o.forEach(e=>{null!==e&&n.push(e)})}else I(327)};e.toArray().forEach(o),We(l,n)}const u=e.getAttributes(s),d={...X(l,t)},g={};for(const e in u)e.startsWith(tt)?g[ot(e)]=u[e]:d[e]=u[e];if(oe(t,d,l,n),n){const e=Object.keys(g).filter(e=>n.has(nt(e)));if(e.length>0){const t=a(l);for(const n of e)t.updateFromUnknown(n,g[n])}}else a(l).updateFromJSON(g);const _=l.getLatest();return t.mapping.set(e,_),_},We=(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,[])},Ue=(e,t,o,s,i)=>{const r=Ze(e,o,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 o=e.get(t);if(void 0===o)throw new Error(`$createTextNodesFromYText: Node ${t} is not registered`);const s=new o.klass;if(!n(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={...X(n,t),...s.p},f=Object.fromEntries(Object.entries(s).filter(([e])=>e.startsWith(tt)).map(([e,t])=>[ot(e),t]));oe(t,c,n,null),a(n).updateFromJSON(f)}const f=l.map(e=>e.getLatest());return t.mapping.set(e,f),f},Re=(e,t)=>e instanceof Array?((e,t)=>{const n=new k;return Xe(n,e,t),n})(e,t):((e,t)=>{const n=new N(e.getType()),o={...et(e,t),...st(e)};for(const e in o){const t=o[e];null!==t&&n.setAttribute(e,t)}return e instanceof p?(n.insert(0,qe(e).map(e=>Re(e,t))),t.mapping.set(n,e),n):n})(e,t),Be=e=>"object"==typeof e&&null!=e,Je=(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||Be(r)&&Be(l)&&Je(r,l)}return o},qe=e=>{if(!(e instanceof p))return[];const t=e.getChildren(),o=[];for(let e=0;e<t.length;e++){const s=t[e];if(n(s)){const s=[];for(let o=t[e];e<t.length&&n(o);o=t[++e])s.push(o);e--,o.push(s)}else o.push(s)}return o},Ge=(e,t,n)=>{const o=Ze(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(tt)));return e.insert===s.getTextContent()&&i===s.getType()&&Je(r,et(s,n))&&Je(l,st(s))})},He=(e,t,n)=>{if(e instanceof N&&!(t instanceof Array)&&rt(e,t)){const o=qe(t);return e._length===o.length&&Je(e.getAttributes(),{...et(t,n),...st(t)})&&e.toArray().every((e,t)=>He(e,o[t],n))}return e instanceof k&&t instanceof Array&&Ge(e,t,n)},Qe=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),Ve=(e,t,n)=>{const o=e.toArray(),s=qe(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 K)break;if(Qe(n.mapping.get(e),t))f=!0;else if(!He(e,t,n))break}for(;c+a<l;a++){const e=o[r-a-1],t=s[i-a-1];if(e instanceof K)break;if(Qe(n.mapping.get(e),t))f=!0;else if(!He(e,t,n))break}return{equalityFactor:c+a,foundMappedChild:f}},Xe=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:i,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 M&&(o[n.content.key]=null)),n=n.right;return{nAttrs:o,str:t}})(e),l=t.map((e,t)=>{const o=e.getType();let s=et(e,n);return 0===Object.keys(s).length&&(s=null),{attributes:Object.assign({},i,{...o!==g.getType()&&{t:o},p:s,...st(e),...t>0&&{i:t}}),insert:e.getTextContent(),nodeKey:e.getKey()}}),c=l.map(e=>e.insert).join(""),a=o();let f;if(s(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}=R(r,c,f);e.delete(h,d),e.insert(h,u),e.applyDelta(l.map(e=>({attributes:e.attributes,retain:e.insert.length})))},Ze=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>({...e,attributes:e.attributes??{}})),et=(e,t)=>{const n=X(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},tt="s_",nt=e=>tt+e,ot=e=>{if(!e.startsWith(tt))throw new Error(`Invalid state key: ${e}`);return e.slice(tt.length)},st=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[nt(e)]=t;for(const[e,t]of o)s[nt(e.key)]=e.unparse(t);return s},it=(e,t,n,o,s)=>{if(t instanceof N&&t.nodeName!==n.getType()&&(!$e(t)||n.getType()!==h.getType()))throw new Error("node name mismatch!");if(o.mapping.set(t,n),t instanceof N){const e=t.getAttributes(),s={...et(n,o),...st(n)};for(const n in s)null!=s[n]?e[n]!==s[n]&&"ychange"!==n&&t.setAttribute(n,s[n]):t.removeAttribute(n);for(const n in e)void 0===s[n]&&t.removeAttribute(n)}const i=qe(n),r=i.length,l=t.toArray(),c=l.length,a=Math.min(r,c);let f=0,u=0;for(;f<a;f++){const t=l[f],n=i[f];if(t instanceof K)break;if(Qe(o.mapping.get(t),n))n instanceof p&&s.has(n.getKey())&&it(e,t,n,o,s);else{if(!He(t,n,o))break;o.mapping.set(t,n)}}for(;u+f<a;u++){const t=l[c-u-1],n=i[r-u-1];if(t instanceof K)break;if(Qe(o.mapping.get(t),n))n instanceof p&&s.has(n.getKey())&&it(e,t,n,o,s);else{if(!He(t,n,o))break;o.mapping.set(t,n)}}for(;c-f-u>0&&r-f-u>0;){const n=l[f],a=i[f],d=l[c-u-1],h=i[r-u-1];if(n instanceof k&&a instanceof Array)Ge(n,a,o)||Xe(n,a,o),f+=1;else{let i=n instanceof N&&rt(n,a),r=d instanceof N&&rt(d,h);if(i&&r){const e=Ve(n,a,o),t=Ve(d,h,o);e.foundMappedChild&&!t.foundMappedChild?r=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?i=!1:r=!1}i?(it(e,n,a,o,s),f+=1):r?(it(e,d,h,o,s),u+=1):(o.mapping.delete(t.get(f)),t.delete(f,1),t.insert(f,[Re(a,o)]),f+=1)}}const d=c-f-u;if(1===c&&0===r&&l[0]instanceof k?(o.mapping.delete(l[0]),l[0].delete(0,l[0].length)):d>0&&(t.slice(f,f+d).forEach(e=>o.mapping.delete(e)),t.delete(f,d)),f+u<r){const e=[];for(let t=f;t<r-u;t++)e.push(Re(i[t],o));t.insert(f,e)}},rt=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType();function lt(e,t){if(t instanceof A&&function(e,t){const{target:n}=t;if(!n._item||"__state"!==n._item.parentSub||void 0!==ee(n)||!(n.parent instanceof k||n.parent instanceof N||n.parent instanceof S))return!1;const o=te(e,n.parent).getNode();if(o){const e=a(o.getWritable());for(const o of t.keysChanged)e.updateFromUnknown(o,n.get(o))}return!0}(e,t))return;const{target:n}=t,o=te(e,n);if(o instanceof ge&&t instanceof j){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 B&&t instanceof A){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof he&&t instanceof z){const{attributesChanged:n}=t;n.size>0&&o.syncPropertiesFromYjs(e,n)}else I(82)}function ct(e,t,n,o,s=Ye){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];lt(e,o)}at(r,e,t),o||m(x)},{onUpdate:()=>{s(e,t),i.update(()=>ft())},skipTransforms:!0,tag:o?y:_})}function at(e,t,n){const i=o();if(s(i))if(fe(i)){const r=e._selection;if(s(r)&&(Fe(t,n),fe(i))){de(i.anchor.key,e)}De(t,n,r,o())}else Fe(t,n)}function ft(){0===f().getChildrenSize()&&f().append(T())}function ut(t,s,i,r,l,c,a,u){ue(t,()=>{r.read(()=>{if(u.has(_)||u.has(y))return void(a.size>0&&function(t,o){const s=Array.from(o),i=t.collabNodeMap,r=[],l=[];for(let t=0;t<s.length;t++){const o=s[t],c=e(o),a=i.get(o);if(a instanceof B)if(n(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}}(t,a));if(l.has("root")){const e=i._nodeMap,n=f(),o=t.root;o.syncPropertiesFromLexical(t,n,e),o.syncChildrenFromLexical(t,n,e,l,c)}const r=o(),d=i._selection;De(t,s,d,r)})})}function dt(e,t){const{target:n}=t;if(n instanceof N&&t instanceof z)Ie(n,e,t.attributesChanged,t.childListChanged);else if(n instanceof k&&t instanceof j){const t=n.parent;t instanceof N?Ie(t,e,new Set,!0):I(324)}else I(325)}function ht(e,t,n,o,s){const i=e.editor,r=i._editorState;E(o,o.deleteSet,t=>{if(t.constructor===F){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];dt(e,o)}at(r,e,t),s||m(x)},{discrete:!0,onUpdate:()=>{Ye(e,t),i.update(()=>ft())},skipTransforms:!0,tag:s?y:_})}function pt(e,t,n,s,i,r,l){(l.has(_)||l.has(y))&&0===r.size||(r.forEach(t=>{e.mapping.deleteNode(t)}),ue(e,()=>{s.read(()=>{i.has("root")&&it(e.doc,e.root,f(),e,new Set(i.keys()));const s=o(),r=n._selection;De(e,t,r,s)})}))}const gt=b("CONNECTED_COMMAND"),_t=b("TOGGLE_CONNECT_COMMAND");function yt(e,t){return new L(t,{trackedOrigins:new Set([e,null])})}function mt(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})}function xt(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{gt as CONNECTED_COMMAND,_t as TOGGLE_CONNECT_COMMAND,xe as createBinding,Te as createBindingV2__EXPERIMENTAL,yt as createUndoManager,Me as getAnchorAndFocusCollabNodesForUserState,mt as initLocalState,xt as setLocalStateFocus,Ye as syncCursorPositions,ut as syncLexicalUpdateToYjs,pt as syncLexicalUpdateToYjsV2__EXPERIMENTAL,ct as syncYjsChangesToLexical,ht as syncYjsChangesToLexicalV2__EXPERIMENTAL};
|
package/SyncCursors.d.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import type { Binding } from './Bindings';
|
|
9
8
|
import type { BaseSelection, NodeKey } from 'lexical';
|
|
10
9
|
import { Provider, UserState } from '.';
|
|
10
|
+
import { AnyBinding, type BaseBinding, type Binding } from './Bindings';
|
|
11
11
|
import { CollabDecoratorNode } from './CollabDecoratorNode';
|
|
12
12
|
import { CollabElementNode } from './CollabElementNode';
|
|
13
13
|
import { CollabLineBreakNode } from './CollabLineBreakNode';
|
|
@@ -32,17 +32,26 @@ export type Cursor = {
|
|
|
32
32
|
selection: null | CursorSelection;
|
|
33
33
|
};
|
|
34
34
|
type AnyCollabNode = CollabDecoratorNode | CollabElementNode | CollabTextNode | CollabLineBreakNode;
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated Use `$getAnchorAndFocusForUserState` instead.
|
|
37
|
+
*/
|
|
35
38
|
export declare function getAnchorAndFocusCollabNodesForUserState(binding: Binding, userState: UserState): {
|
|
36
39
|
anchorCollabNode: AnyCollabNode | null;
|
|
37
40
|
anchorOffset: number;
|
|
38
41
|
focusCollabNode: AnyCollabNode | null;
|
|
39
42
|
focusOffset: number;
|
|
40
43
|
};
|
|
41
|
-
export declare function $
|
|
42
|
-
|
|
44
|
+
export declare function $getAnchorAndFocusForUserState(binding: AnyBinding, userState: UserState): {
|
|
45
|
+
anchorKey: NodeKey | null;
|
|
46
|
+
anchorOffset: number;
|
|
47
|
+
focusKey: NodeKey | null;
|
|
48
|
+
focusOffset: number;
|
|
49
|
+
};
|
|
50
|
+
export declare function $syncLocalCursorPosition(binding: AnyBinding, provider: Provider): void;
|
|
51
|
+
export type SyncCursorPositionsFn = (binding: AnyBinding, provider: Provider, options?: SyncCursorPositionsOptions) => void;
|
|
43
52
|
export type SyncCursorPositionsOptions = {
|
|
44
|
-
getAwarenessStates?: (binding:
|
|
53
|
+
getAwarenessStates?: (binding: BaseBinding, provider: Provider) => Map<number, UserState>;
|
|
45
54
|
};
|
|
46
|
-
export declare function syncCursorPositions(binding:
|
|
47
|
-
export declare function syncLexicalSelectionToYjs(binding:
|
|
55
|
+
export declare function syncCursorPositions(binding: AnyBinding, provider: Provider, options?: SyncCursorPositionsOptions): void;
|
|
56
|
+
export declare function syncLexicalSelectionToYjs(binding: AnyBinding, provider: Provider, prevSelection: null | BaseSelection, nextSelection: null | BaseSelection): void;
|
|
48
57
|
export {};
|
package/SyncEditorStates.d.ts
CHANGED
|
@@ -6,10 +6,14 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
import type { EditorState, NodeKey } from 'lexical';
|
|
9
|
+
import type { Transaction as YTransaction } from 'yjs';
|
|
10
|
+
import { YXmlElement, YXmlText } from 'node_modules/yjs/dist/src/internals';
|
|
9
11
|
import { Text as YText, YEvent } from 'yjs';
|
|
10
|
-
import { Binding, Provider } from '.';
|
|
12
|
+
import { Binding, BindingV2, Provider } from '.';
|
|
11
13
|
import { SyncCursorPositionsFn } from './SyncCursors';
|
|
12
14
|
export declare function syncYjsChangesToLexical(binding: Binding, provider: Provider, events: Array<YEvent<YText>>, isFromUndoManger: boolean, syncCursorPositionsFn?: SyncCursorPositionsFn): void;
|
|
13
15
|
type IntentionallyMarkedAsDirtyElement = boolean;
|
|
14
16
|
export declare function syncLexicalUpdateToYjs(binding: Binding, provider: Provider, prevEditorState: EditorState, currEditorState: EditorState, dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>, dirtyLeaves: Set<NodeKey>, normalizedNodes: Set<NodeKey>, tags: Set<string>): void;
|
|
17
|
+
export declare function syncYjsChangesToLexicalV2__EXPERIMENTAL(binding: BindingV2, provider: Provider, events: Array<YEvent<YXmlElement | YXmlText>>, transaction: YTransaction, isFromUndoManger: boolean): void;
|
|
18
|
+
export declare function syncLexicalUpdateToYjsV2__EXPERIMENTAL(binding: BindingV2, provider: Provider, prevEditorState: EditorState, currEditorState: EditorState, dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>, normalizedNodes: Set<NodeKey>, tags: Set<string>): void;
|
|
15
19
|
export {};
|
package/SyncV2.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
import { LexicalNode, NodeKey } from 'lexical';
|
|
9
|
+
import { Doc as YDoc, ID, Snapshot, XmlElement } from 'yjs';
|
|
10
|
+
import { BindingV2 } from './Bindings';
|
|
11
|
+
type ComputeYChange = (event: 'removed' | 'added', id: ID) => Record<string, unknown>;
|
|
12
|
+
export declare const $createOrUpdateNodeFromYElement: (el: XmlElement, binding: BindingV2, keysChanged: Set<string> | null, childListChanged: boolean, snapshot?: Snapshot, prevSnapshot?: Snapshot, computeYChange?: ComputeYChange) => LexicalNode | null;
|
|
13
|
+
export declare const $updateYFragment: (y: YDoc, yDomFragment: XmlElement, node: LexicalNode, binding: BindingV2, dirtyElements: Set<NodeKey>) => void;
|
|
14
|
+
export {};
|
package/Utils.d.ts
CHANGED
|
@@ -5,19 +5,23 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import type { Binding, YjsNode } from '.';
|
|
8
|
+
import type { BaseBinding, Binding, YjsNode } from '.';
|
|
9
9
|
import { EditorState, LexicalNode, NodeKey, RangeSelection } from 'lexical';
|
|
10
10
|
import { Map as YMap, XmlElement, XmlText } from 'yjs';
|
|
11
11
|
import { CollabDecoratorNode } from './CollabDecoratorNode';
|
|
12
12
|
import { CollabElementNode } from './CollabElementNode';
|
|
13
13
|
import { CollabLineBreakNode } from './CollabLineBreakNode';
|
|
14
14
|
import { CollabTextNode } from './CollabTextNode';
|
|
15
|
+
export declare function initializeNodeProperties(binding: BaseBinding): void;
|
|
16
|
+
export declare function getDefaultNodeProperties(node: LexicalNode, binding: BaseBinding): {
|
|
17
|
+
[property: string]: unknown;
|
|
18
|
+
};
|
|
15
19
|
export declare function getIndexOfYjsNode(yjsParentNode: YjsNode, yjsNode: YjsNode): number;
|
|
16
20
|
export declare function $createCollabNodeFromLexicalNode(binding: Binding, lexicalNode: LexicalNode, parent: CollabElementNode): CollabElementNode | CollabTextNode | CollabLineBreakNode | CollabDecoratorNode;
|
|
17
21
|
export declare function getNodeTypeFromSharedType(sharedType: XmlText | YMap<unknown> | XmlElement): string | undefined;
|
|
18
22
|
export declare function $getOrInitCollabNodeFromSharedType(binding: Binding, sharedType: XmlText | YMap<unknown> | XmlElement, parent?: CollabElementNode): CollabElementNode | CollabTextNode | CollabLineBreakNode | CollabDecoratorNode;
|
|
19
23
|
export declare function createLexicalNodeFromCollabNode(binding: Binding, collabNode: CollabElementNode | CollabTextNode | CollabDecoratorNode | CollabLineBreakNode, parentKey: NodeKey): LexicalNode;
|
|
20
|
-
export declare function $syncPropertiesFromYjs(binding:
|
|
24
|
+
export declare function $syncPropertiesFromYjs(binding: BaseBinding, sharedType: XmlText | YMap<unknown> | XmlElement | Record<string, unknown>, lexicalNode: LexicalNode, keysChanged: null | Set<string>): void;
|
|
21
25
|
export declare function syncPropertiesFromLexical(binding: Binding, sharedType: XmlText | YMap<unknown> | XmlElement, prevLexicalNode: null | LexicalNode, nextLexicalNode: LexicalNode): void;
|
|
22
26
|
export declare function spliceString(str: string, index: number, delCount: number, newText: string): string;
|
|
23
27
|
export declare function getPositionFromElementAndOffset(node: CollabElementNode, offset: number, boundaryIsEdge: boolean): {
|
|
@@ -27,5 +31,5 @@ export declare function getPositionFromElementAndOffset(node: CollabElementNode,
|
|
|
27
31
|
offset: number;
|
|
28
32
|
};
|
|
29
33
|
export declare function doesSelectionNeedRecovering(selection: RangeSelection): boolean;
|
|
30
|
-
export declare function syncWithTransaction(binding:
|
|
34
|
+
export declare function syncWithTransaction(binding: BaseBinding, fn: () => void): void;
|
|
31
35
|
export declare function $moveSelectionToPreviousNode(anchorNodeKey: string, currentEditorState: EditorState): void;
|
package/index.d.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
8
|
+
import type { BaseBinding } from './Bindings';
|
|
9
9
|
import type { LexicalCommand } from 'lexical';
|
|
10
|
-
import type { Doc, RelativePosition, UndoManager, XmlText } from 'yjs';
|
|
10
|
+
import type { Doc, RelativePosition, UndoManager, XmlElement, XmlText } from 'yjs';
|
|
11
11
|
import './types';
|
|
12
12
|
export type UserState = {
|
|
13
13
|
anchorPos: null | RelativePosition;
|
|
@@ -55,10 +55,10 @@ export type Delta = Array<Operation>;
|
|
|
55
55
|
export type YjsNode = Record<string, unknown>;
|
|
56
56
|
export type YjsEvent = Record<string, unknown>;
|
|
57
57
|
export type { Provider };
|
|
58
|
-
export type { Binding, ClientID, ExcludedProperties } from './Bindings';
|
|
59
|
-
export { createBinding } from './Bindings';
|
|
60
|
-
export declare function createUndoManager(binding:
|
|
58
|
+
export type { BaseBinding, Binding, BindingV2, ClientID, ExcludedProperties, } from './Bindings';
|
|
59
|
+
export { createBinding, createBindingV2__EXPERIMENTAL } from './Bindings';
|
|
60
|
+
export declare function createUndoManager(binding: BaseBinding, root: XmlText | XmlElement): UndoManager;
|
|
61
61
|
export declare function initLocalState(provider: Provider, name: string, color: string, focusing: boolean, awarenessData: object): void;
|
|
62
62
|
export declare function setLocalStateFocus(provider: Provider, name: string, color: string, focusing: boolean, awarenessData: object): void;
|
|
63
63
|
export { getAnchorAndFocusCollabNodesForUserState, syncCursorPositions, type SyncCursorPositionsFn, } from './SyncCursors';
|
|
64
|
-
export { syncLexicalUpdateToYjs, syncYjsChangesToLexical, } from './SyncEditorStates';
|
|
64
|
+
export { syncLexicalUpdateToYjs, syncLexicalUpdateToYjsV2__EXPERIMENTAL, syncYjsChangesToLexical, syncYjsChangesToLexicalV2__EXPERIMENTAL, } from './SyncEditorStates';
|
package/package.json
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"crdt"
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"version": "0.36.
|
|
14
|
+
"version": "0.36.3-nightly.20251003.0",
|
|
15
15
|
"main": "LexicalYjs.js",
|
|
16
16
|
"types": "index.d.ts",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@lexical/offset": "0.36.
|
|
19
|
-
"@lexical/selection": "0.36.
|
|
20
|
-
"lexical": "0.36.
|
|
18
|
+
"@lexical/offset": "0.36.3-nightly.20251003.0",
|
|
19
|
+
"@lexical/selection": "0.36.3-nightly.20251003.0",
|
|
20
|
+
"lexical": "0.36.3-nightly.20251003.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"yjs": ">=13.5.22"
|