@lexical/yjs 0.13.0 → 0.14.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/LexicalYjs.dev.esm.js +1599 -0
- package/LexicalYjs.dev.js +5 -5
- package/LexicalYjs.esm.js +18 -0
- package/LexicalYjs.js +1 -1
- package/LexicalYjs.prod.esm.js +7 -0
- package/README.md +2 -0
- package/package.json +6 -4
package/LexicalYjs.dev.js
CHANGED
|
@@ -171,7 +171,7 @@ class CollabTextNode {
|
|
|
171
171
|
syncPropertiesAndTextFromYjs(binding, keysChanged) {
|
|
172
172
|
const lexicalNode = this.getNode();
|
|
173
173
|
if (!(lexicalNode !== null)) {
|
|
174
|
-
throw Error(`syncPropertiesAndTextFromYjs:
|
|
174
|
+
throw Error(`syncPropertiesAndTextFromYjs: could not find decorator node`);
|
|
175
175
|
}
|
|
176
176
|
syncPropertiesFromYjs(binding, this._map, lexicalNode, keysChanged);
|
|
177
177
|
const collabText = this._text;
|
|
@@ -578,7 +578,7 @@ class CollabDecoratorNode {
|
|
|
578
578
|
syncPropertiesFromYjs(binding, keysChanged) {
|
|
579
579
|
const lexicalNode = this.getNode();
|
|
580
580
|
if (!(lexicalNode !== null)) {
|
|
581
|
-
throw Error(`syncPropertiesFromYjs:
|
|
581
|
+
throw Error(`syncPropertiesFromYjs: could not find decorator node`);
|
|
582
582
|
}
|
|
583
583
|
const xmlElem = this._xmlElem;
|
|
584
584
|
syncPropertiesFromYjs(binding, xmlElem, lexicalNode, keysChanged);
|
|
@@ -638,14 +638,14 @@ class CollabElementNode {
|
|
|
638
638
|
getOffset() {
|
|
639
639
|
const collabElementNode = this._parent;
|
|
640
640
|
if (!(collabElementNode !== null)) {
|
|
641
|
-
throw Error(`getOffset:
|
|
641
|
+
throw Error(`getOffset: could not find collab element node`);
|
|
642
642
|
}
|
|
643
643
|
return collabElementNode.getChildOffset(this);
|
|
644
644
|
}
|
|
645
645
|
syncPropertiesFromYjs(binding, keysChanged) {
|
|
646
646
|
const lexicalNode = this.getNode();
|
|
647
647
|
if (!(lexicalNode !== null)) {
|
|
648
|
-
throw Error(`syncPropertiesFromYjs:
|
|
648
|
+
throw Error(`syncPropertiesFromYjs: could not find element node`);
|
|
649
649
|
}
|
|
650
650
|
syncPropertiesFromYjs(binding, this._xmlText, lexicalNode, keysChanged);
|
|
651
651
|
}
|
|
@@ -730,7 +730,7 @@ class CollabElementNode {
|
|
|
730
730
|
// Now diff the children of the collab node with that of our existing Lexical node.
|
|
731
731
|
const lexicalNode = this.getNode();
|
|
732
732
|
if (!(lexicalNode !== null)) {
|
|
733
|
-
throw Error(`syncChildrenFromYjs:
|
|
733
|
+
throw Error(`syncChildrenFromYjs: could not find element node`);
|
|
734
734
|
}
|
|
735
735
|
const key = lexicalNode.__key;
|
|
736
736
|
const prevLexicalChildrenKeys = createChildrenArray(lexicalNode, null);
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
import * as modDev from './LexicalYjs.dev.esm.js';
|
|
8
|
+
import * as modProd from './LexicalYjs.prod.esm.js';
|
|
9
|
+
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
10
|
+
export const CONNECTED_COMMAND = mod.CONNECTED_COMMAND;
|
|
11
|
+
export const TOGGLE_CONNECT_COMMAND = mod.TOGGLE_CONNECT_COMMAND;
|
|
12
|
+
export const createBinding = mod.createBinding;
|
|
13
|
+
export const createUndoManager = mod.createUndoManager;
|
|
14
|
+
export const initLocalState = mod.initLocalState;
|
|
15
|
+
export const setLocalStateFocus = mod.setLocalStateFocus;
|
|
16
|
+
export const syncCursorPositions = mod.syncCursorPositions;
|
|
17
|
+
export const syncLexicalUpdateToYjs = mod.syncLexicalUpdateToYjs;
|
|
18
|
+
export const syncYjsChangesToLexical = mod.syncYjsChangesToLexical;
|
package/LexicalYjs.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const LexicalYjs = process.env.NODE_ENV === 'development' ? require('./LexicalYjs.dev.js') : require('./LexicalYjs.prod.js')
|
|
8
|
+
const LexicalYjs = process.env.NODE_ENV === 'development' ? require('./LexicalYjs.dev.js') : require('./LexicalYjs.prod.js');
|
|
9
9
|
module.exports = LexicalYjs;
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
import{$getNodeByKey as e,$isLineBreakNode as t,$isTextNode as n,$getSelection as o,$isRangeSelection as s,createEditor as l,$isElementNode as i,$isRootNode as r,$isDecoratorNode as c,$setSelection as f,$getRoot as a,$createParagraphNode as u,createCommand as d}from"lexical";import{XmlText as _,Map as h,XmlElement as p,Doc as g,createAbsolutePositionFromRelativePosition as y,createRelativePositionFromTypeIndex as x,compareRelativePositions as m,YTextEvent as k,YMapEvent as b,YXmlEvent as v,UndoManager as P}from"yjs";import{createDOMRange as C,createRectsFromDOMRange as w}from"@lexical/selection";import{$createOffsetView as N}from"@lexical/offset";var T=function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)};class S{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){e.collabNodeMap.delete(this._key)}}function F(e,t){const n=new S(e,t);return e._collabNode=n,n}class E{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($(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&&T(84),K(e,this._map,n,t);const o=this._text;if(n.__text!==o){n.getWritable().__text=o}}destroy(e){e.collabNodeMap.delete(this._key)}}function M(e,t,n,o){const s=new E(e,t,n,o);return e._collabNode=s,s}const z=new Set(["__key","__parent","__next","__prev"]),L=new Set(["__first","__last","__size"]),O=new Set(["__cachedText"]),j=new Set(["__text"]);function A(e,t,o){if(z.has(e))return!0;if(n(t)){if(j.has(e))return!0}else if(i(t)&&(L.has(e)||r(t)&&O.has(e)))return!0;const s=t.constructor,l=o.excludedProperties.get(s);return null!=l&&l.has(e)}function Y(t){const n=e(t);return null===n&&T(85),n}function D(e,o,s){const l=o.__type;let r;if(i(o)){r=V(new _,s,l),r.syncPropertiesFromLexical(e,o,null),r.syncChildrenFromLexical(e,o,null,null,null)}else if(n(o)){r=M(new h,o.__text,s,l),r.syncPropertiesAndTextFromLexical(e,o,null)}else if(t(o)){const e=new h;e.set("__type","linebreak"),r=F(e,s)}else if(c(o)){r=J(new p,s,l),r.syncPropertiesFromLexical(e,o,null)}else T(86);return r._key=o.__key,r}function W(e,t,n){const o=t._collabNode;if(void 0===o){const o=e.editor._nodes,s=function(e){const t=e instanceof h?e.get("__type"):e.getAttribute("__type");return null==t&&T(87),t}(t);void 0===o.get(s)&&T(88,s);const l=t.parent,i=void 0===n&&null!==l?W(e,l):n||null;if(i instanceof Q||T(89),t instanceof _)return V(t,i,s);if(t instanceof h)return"linebreak"===s?F(t,i):M(t,"",i,s);if(t instanceof p)return J(t,i,s)}return o}function I(e,t,n){const o=t.getType(),s=e.editor._nodes.get(o);void 0===s&&T(88,o);const l=new s.klass;if(l.__parent=n,t._key=l.__key,t instanceof Q){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof E?t.syncPropertiesAndTextFromYjs(e,null):t instanceof H&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(l.__key,t),l}function K(e,t,n,o){const s=null===o?t instanceof h?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(A(r,n,e))continue;const c=n[r];let f=t instanceof h?t.get(r):t.getAttribute(r);if(c!==f){if(f instanceof g){const t=e.docMap;c instanceof g&&t.delete(c.guid);const n=l(),o=f.guid;n._key=o,t.set(o,f),f=n}void 0===i&&(i=n.getWritable()),i[r]=f}}}function $(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=>!A(t,o,e))),l.set(s,i));const r=e.editor.constructor;for(let s=0;s<i.length;s++){const l=i[s],c=null===n?void 0:n[l];let f=o[l];if(c!==f){if(f 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 g,l=s.guid;f._key=l,t.set(l,s),f=s,e.editor.update((()=>{o.markDirty()}))}t instanceof h?t.set(l,f):t.setAttribute(l,f)}}}function R(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function B(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 E){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 U(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 G(t,n){const o=[];let s=t.__first;for(;null!==s;){const t=null===n?e(s):n.get(s);null==t&&T(101),o.push(s),s=t.__next}return o}function q(e){const t=e.getParent();if(null!==t){const n=e.getWritable(),o=t.getWritable(),s=e.getPreviousSibling(),l=e.getNextSibling();if(null===s)if(null!==l){const e=l.getWritable();o.__first=l.__key,e.__prev=null}else o.__first=null;else{const e=s.getWritable();if(null!==l){const t=l.getWritable();t.__prev=e.__key,e.__next=t.__key}else e.__next=null;n.__prev=null}if(null===l)if(null!==s){const e=s.getWritable();o.__last=s.__key,e.__next=null}else o.__last=null;else{const e=l.getWritable();if(null!==s){const t=s.getWritable();t.__next=e.__key,e.__prev=t.__key}else e.__prev=null;n.__next=null}o.__size--,n.__parent=null}}class H{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 c(t)?t:null}getNode(){const t=e(this._key);return c(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);$(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&T(83);K(e,this._xmlElem,n,t)}destroy(e){e.collabNodeMap.delete(this._key)}}function J(e,t,n){const o=new H(e,t,n);return e._collabNode=o,o}class Q{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&&T(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&T(91),K(e,this._xmlText,n,t)}applyChildrenYjsDelta(e,t){const n=this._children;let o=0;for(let s=0;s<t.length;s++){const l=t[s],i=l.insert,r=l.delete;if(null!=l.retain)o+=l.retain;else if("number"==typeof r){let e=r;for(;e>0;){const{node:t,nodeIndex:s,offset:l,length:i}=B(this,o,!1);if(t instanceof Q||t instanceof S||t instanceof H)n.splice(s,1),e-=1;else{if(!(t instanceof E))break;{const o=Math.min(e,i),r=0!==s?n[s-1]:null,c=t.getSize();0===l&&1===o&&s>0&&r instanceof E&&i===c&&0===Array.from(t._map.keys()).length?(r._text+=t._text,n.splice(s,1)):0===l&&o===c?n.splice(s,1):t._text=R(t._text,l,o,""),e-=o}}}}else{if(null==i)throw new Error("Unexpected delta format");if("string"==typeof i){const{node:e,offset:t}=B(this,o,!0);e instanceof E?e._text=R(e._text,t,0,i):this._xmlText.delete(t,i.length),o+=i.length}else{const t=i,{nodeIndex:s}=B(this,o,!1),l=W(e,t,this);n.splice(s,0,l),o+=1}}}}syncChildrenFromYjs(e){const t=this.getNode();null===t&&T(92);const o=t.__key,s=G(t,null),l=s.length,i=this._children,r=i.length,c=e.collabNodeMap,f=new Set;let a,u,d=0,_=null;r!==l&&(u=t.getWritable());for(let l=0;l<r;l++){const h=s[d],p=i[l],g=p.getNode(),y=p._key;if(null!==g&&h===y){const t=n(g);if(f.add(h),t)if(p._key=h,p instanceof Q){const t=p._xmlText;p.syncPropertiesFromYjs(e,null),p.applyChildrenYjsDelta(e,t.toDelta()),p.syncChildrenFromYjs(e)}else p instanceof E?p.syncPropertiesAndTextFromYjs(e,null):p instanceof H?p.syncPropertiesFromYjs(e,null):p instanceof S||T(93);_=g,d++}else{if(void 0===a){a=new Set;for(let e=0;e<r;e++){const t=i[e]._key;""!==t&&a.add(t)}}if(null!==g&&void 0!==h&&!a.has(h)){q(Y(h)),l--,d++;continue}u=t.getWritable();const n=I(e,p,o),s=n.__key;if(c.set(s,p),null===_){const e=u.getFirstChild();if(u.__first=s,null!==e){const t=e.getWritable();t.__prev=s,n.__next=t.__key}}else{const e=_.getWritable(),t=_.getNextSibling();if(e.__next=s,n.__prev=_.__key,null!==t){const e=t.getWritable();e.__prev=s,n.__next=e.__key}}l===r-1&&(u.__last=s),u.__size++,_=n}}for(let t=0;t<l;t++){const n=s[t];if(!f.has(n)){const t=Y(n),o=e.collabNodeMap.get(n);void 0!==o&&o.destroy(e),q(t)}}}syncPropertiesFromLexical(e,t,n){$(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(e,t,o,s,l,r){const f=this._children[t],a=Y(o);f instanceof Q&&i(a)?(f.syncPropertiesFromLexical(e,a,s),f.syncChildrenFromLexical(e,a,s,l,r)):f instanceof E&&n(a)?f.syncPropertiesAndTextFromLexical(e,a,s):f instanceof H&&c(a)&&f.syncPropertiesFromLexical(e,a,s)}syncChildrenFromLexical(e,t,n,o,s){const l=this.getPrevNode(n),i=null===l?[]:G(l,n),r=G(t,null),c=i.length-1,f=r.length-1,a=e.collabNodeMap;let u,d,_=0,h=0;for(;_<=c&&h<=f;){const t=i[_],l=r[h];if(t===l)this._syncChildFromLexical(e,h,l,n,o,s),_++,h++;else{void 0===u&&(u=new Set(i)),void 0===d&&(d=new Set(r));const n=d.has(t),o=u.has(l);if(n){const t=D(e,Y(l),this);a.set(l,t),o?(this.splice(e,h,1,t),_++,h++):(this.splice(e,h,0,t),h++)}else this.splice(e,h,1),_++}}const p=_>c,g=h>f;if(p&&!g)for(;h<=f;++h){const t=r[h],n=D(e,Y(t),this);this.append(n),a.set(t,n)}else if(g&&!p)for(let t=this._children.length-1;t>=h;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 Q)t.insertEmbed(s,e._xmlText);else if(e instanceof E){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof S?t.insertEmbed(s,e._map):e instanceof H&&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&&T(94),void this.append(o);const i=l.getOffset();-1===i&&T(95);const r=this._xmlText;if(0!==n&&r.delete(i,l.getSize()),o instanceof Q)r.insertEmbed(i,o._xmlText);else if(o instanceof E){const e=o._map;null===e.parent&&r.insertEmbed(i,e),r.insert(i+1,o._text)}else o instanceof S?r.insertEmbed(i,o._map):o instanceof H&&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.delete(this._key)}}function V(e,t,n){const o=new Q(e,t,n);return e._collabNode=o,o}function X(e,t,n,o,s,l){null==o&&T(81);const i=V(o.get("root",_),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 Z(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 E){l=o._parent._xmlText;const e=o.getOffset();if(-1===e)return null;s=e+1+s}else if(o instanceof Q&&"element"===e.type){const t=e.getNode();if(!i(t))throw Error("Element point must be an element node");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 x(l,s)}function ee(e,t){return y(e,t.doc)}function te(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!m(e,t))return!0;return!1}function ne(e,t){return{color:t,name:e,selection:null}}function oe(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 se(e,t){const n=t.selection;null!==n&&oe(e,n)}function le(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 ie(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 f=c.getBoundingClientRect(),a=n.selection;if(null===o)return null===a?void 0:(n.selection=null,void oe(e,a));n.selection=o;const u=o.caret,d=o.color,_=o.selections,h=o.anchor,p=o.focus,g=h.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=C(l,x,h.offset,m,p.offset);if(null===e)return;k=w(l,e)}const b=_.length,v=k.length;for(let e=0;e<v;e++){const t=k[e];let n=_[e];if(void 0===n){n=document.createElement("span"),_[e]=n;const t=document.createElement("span");n.appendChild(t),r.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:${d};opacity:0.3;`,e===v-1&&u.parentNode!==n&&n.appendChild(u)}for(let e=b-1;e>=v;e--){const t=_[e];r.removeChild(t),_.pop()}}function re(e,t){const n=t.awareness.getLocalState();if(null===n)return;const l=n.anchorPos,i=n.focusPos;if(null!==l&&null!==i){const t=ee(l,e),n=ee(i,e);if(null!==t&&null!==n){const[e,l]=fe(t.type,t.index),[i,r]=fe(n.type,n.index);if(null!==e&&null!==i){const t=e.getKey(),n=i.getKey(),c=o();if(!s(c))return;const f=c.anchor,a=c.focus;ce(f,t,l),ce(a,n,r)}}}}function ce(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 fe(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof Q){const{node:e,offset:o}=B(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function ae(e,t){const n=Array.from(t.awareness.getStates()),o=e.clientID,s=e.cursors,l=e.editor._editorState._nodeMap,i=new Set;for(let t=0;t<n.length;t++){const r=n[t],[c,f]=r;if(c!==o){i.add(c);const{anchorPos:t,focusPos:n,name:o,color:r,focusing:a}=f;let u=null,d=s.get(c);if(void 0===d&&(d=ne(o,r),s.set(c,d)),null!==t&&null!==n&&a){const o=ee(t,e),s=ee(n,e);if(null!==o&&null!==s){const[e,t]=fe(o.type,o.index),[n,l]=fe(s.type,s.index);if(null!==e&&null!==n){const o=e.getKey(),s=n.getKey();if(u=d.selection,null===u)u=le(d,o,t,s,l);else{const e=u.anchor,n=u.focus;e.key=o,e.offset=t,n.key=s,n.offset=l}}}}ie(e,d,u,l)}}const r=Array.from(s.keys());for(let t=0;t<r.length;t++){const n=r[t];if(!i.has(n)){const t=s.get(n);void 0!==t&&(se(e,t),s.delete(n))}}}function ue(e,t,n,o){const l=t.awareness,i=l.getLocalState();if(null===i)return;const{anchorPos:r,focusPos:c,name:f,color:a,focusing:u,awarenessData:d}=i;let _=null,h=null;(null!==o&&(null===r||o.is(n))||null!==n)&&(s(o)&&(_=Z(o.anchor,e),h=Z(o.focus,e)),(te(r,_)||te(c,h))&&l.setLocalState({anchorPos:_,awarenessData:d,color:a,focusPos:h,focusing:u,name:f}))}function de(e,t){const{target:n}=t,o=W(e,n);if(o instanceof Q&&t instanceof k){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 E&&t instanceof b){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof H&&t instanceof v){const{attributesChanged:n}=t;n.size>0&&o.syncPropertiesFromYjs(e,n)}else T(82)}function _e(e,t,n,l){const i=e.editor,r=i._editorState;n.forEach((e=>e.delta)),i.update((()=>{const l=i._pendingEditorState;for(let t=0;t<n.length;t++){const o=n[t];de(e,o)}const c=o();if(s(c))if(U(c)){const n=r._selection;if(s(n)){const o=N(i,0,r),s=N(i,0,l),[d,_]=o.getOffsetsFromSelection(n),h=d>=0&&_>=0?s.createSelectionFromOffsets(d,_,o):null;if(null!==h)f(h);else if(re(e,t),U(c)){const e=a();0===e.getChildrenSize()&&e.append(u()),a().selectEnd()}}ue(e,t,n,o())}else re(e,t)}),{onUpdate:()=>{ae(e,t)},skipTransforms:!0,tag:l?"historic":"collaboration"})}function he(t,s,l,i,r,c,f,u){!function(e,t){e.doc.transact(t,e)}(t,(()=>{i.read((()=>{if(u.has("collaboration")||u.has("historic"))return void(f.size>0&&function(t,o){const s=Array.from(o),l=t.collabNodeMap,i=[];for(let t=0;t<s.length;t++){const o=s[t],r=e(o),c=l.get(o);if(c instanceof E)if(n(r))i.push([c,r.__text]);else{const e=c.getOffset();if(-1===e)continue;const t=c._parent;c._normalized=!0,t._xmlText.delete(e,1),l.delete(o);const n=t._children,s=n.indexOf(c);n.splice(s,1)}}for(let e=0;e<i.length;e++){const[t,n]=i[e];t instanceof E&&"string"==typeof n&&(t._text=n)}}(t,f));if(r.has("root")){const e=l._nodeMap,n=a(),o=t.root;o.syncPropertiesFromLexical(t,n,e),o.syncChildrenFromLexical(t,n,e,r,c)}const i=o(),d=l._selection;ue(t,s,d,i)}))}))}const pe=d("CONNECTED_COMMAND"),ge=d("TOGGLE_CONNECT_COMMAND");function ye(e,t){return new P(t,{trackedOrigins:new Set([e,null])})}function xe(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})}function me(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{pe as CONNECTED_COMMAND,ge as TOGGLE_CONNECT_COMMAND,X as createBinding,ye as createUndoManager,xe as initLocalState,me as setLocalStateFocus,ae as syncCursorPositions,he as syncLexicalUpdateToYjs,_e as syncYjsChangesToLexical};
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -11,18 +11,20 @@
|
|
|
11
11
|
"crdt"
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"version": "0.
|
|
14
|
+
"version": "0.14.0",
|
|
15
15
|
"main": "LexicalYjs.js",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/offset": "0.
|
|
17
|
+
"@lexical/offset": "0.14.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"lexical": "0.
|
|
20
|
+
"lexical": "0.14.0",
|
|
21
21
|
"yjs": ">=13.5.22"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
25
25
|
"url": "https://github.com/facebook/lexical",
|
|
26
26
|
"directory": "packages/lexical-yjs"
|
|
27
|
-
}
|
|
27
|
+
},
|
|
28
|
+
"module": "LexicalYjs.esm.js",
|
|
29
|
+
"sideEffects": false
|
|
28
30
|
}
|