@lexical/yjs 0.12.4 → 0.12.6
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.js +8 -3
- package/LexicalYjs.prod.js +2 -2
- package/SyncCursors.d.ts +2 -2
- package/package.json +3 -3
package/LexicalYjs.dev.js
CHANGED
|
@@ -320,6 +320,7 @@ function syncPropertiesFromYjs(binding, sharedType, lexicalNode, keysChanged) {
|
|
|
320
320
|
if (isExcludedProperty(property, lexicalNode, binding)) {
|
|
321
321
|
continue;
|
|
322
322
|
}
|
|
323
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
323
324
|
const prevValue = lexicalNode[property];
|
|
324
325
|
let nextValue = sharedType instanceof yjs.Map ? sharedType.get(property) : sharedType.getAttribute(property);
|
|
325
326
|
if (prevValue !== nextValue) {
|
|
@@ -354,14 +355,16 @@ function syncPropertiesFromLexical(binding, sharedType, prevLexicalNode, nextLex
|
|
|
354
355
|
const EditorClass = binding.editor.constructor;
|
|
355
356
|
for (let i = 0; i < properties.length; i++) {
|
|
356
357
|
const property = properties[i];
|
|
357
|
-
const prevValue =
|
|
358
|
+
const prevValue =
|
|
359
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
360
|
+
prevLexicalNode === null ? undefined : prevLexicalNode[property];
|
|
361
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
358
362
|
let nextValue = nextLexicalNode[property];
|
|
359
363
|
if (prevValue !== nextValue) {
|
|
360
364
|
if (nextValue instanceof EditorClass) {
|
|
361
365
|
const yjsDocMap = binding.docMap;
|
|
362
366
|
let prevDoc;
|
|
363
367
|
if (prevValue instanceof EditorClass) {
|
|
364
|
-
// @ts-expect-error Lexical node
|
|
365
368
|
const prevKey = prevValue._key;
|
|
366
369
|
prevDoc = yjsDocMap.get(prevKey);
|
|
367
370
|
yjsDocMap.delete(prevKey);
|
|
@@ -370,7 +373,6 @@ function syncPropertiesFromLexical(binding, sharedType, prevLexicalNode, nextLex
|
|
|
370
373
|
// If we already have a document, use it.
|
|
371
374
|
const doc = prevDoc || new yjs.Doc();
|
|
372
375
|
const key = doc.guid;
|
|
373
|
-
// @ts-expect-error Lexical node
|
|
374
376
|
nextValue._key = key;
|
|
375
377
|
yjsDocMap.set(key, doc);
|
|
376
378
|
nextValue = doc;
|
|
@@ -1059,6 +1061,9 @@ function createRelativePosition(point, binding) {
|
|
|
1059
1061
|
offset = currentOffset + 1 + offset;
|
|
1060
1062
|
} else if (collabNode instanceof CollabElementNode && point.type === 'element') {
|
|
1061
1063
|
const parent = point.getNode();
|
|
1064
|
+
if (!lexical.$isElementNode(parent)) {
|
|
1065
|
+
throw Error(`Element point must be an element node`);
|
|
1066
|
+
}
|
|
1062
1067
|
let accumulatedOffset = 0;
|
|
1063
1068
|
let i = 0;
|
|
1064
1069
|
let node = parent.getFirstChild();
|
package/LexicalYjs.prod.js
CHANGED
|
@@ -31,8 +31,8 @@ this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=
|
|
|
31
31
|
c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof P)b.insertEmbed(c,a._xmlText);else if(a instanceof F){let d=a._map;null===d.parent&&b.insertEmbed(c,d);b.insert(c+1,a._text)}else a instanceof C?b.insertEmbed(c,a._map):a instanceof U&&b.insertEmbed(c,a._xmlElem);this._children.push(a)}splice(a,b,c,d){let e=this._children;var f=e[b];if(void 0===f)void 0===d&&A(94),this.append(d);else{var h=f.getOffset();-1===h&&A(95);var g=this._xmlText;0!==c&&g.delete(h,f.getSize());d instanceof
|
|
32
32
|
P?g.insertEmbed(h,d._xmlText):d instanceof F?(f=d._map,null===f.parent&&g.insertEmbed(h,f),g.insert(h+1,d._text)):d instanceof C?g.insertEmbed(h,d._map):d instanceof U&&g.insertEmbed(h,d._xmlElem);if(0!==c)for(h=e.slice(b,b+c),g=0;g<h.length;g++)h[g].destroy(a);void 0!==d?e.splice(b,c,d):e.splice(b,c)}}getChildOffset(a){let b=0,c=this._children;for(let d=0;d<c.length;d++){let e=c[d];if(e===a)return b;b+=e.getSize()}return-1}destroy(a){let b=a.collabNodeMap,c=this._children;for(let d=0;d<c.length;d++)c[d].destroy(a);
|
|
33
33
|
b.delete(this._key)}}function M(a,b,c){b=new P(a,b,c);return a._collabNode=b}
|
|
34
|
-
function V(a,b){var c=b.collabNodeMap.get(a.key);if(void 0===c)return null;b=a.offset;let d=c.getSharedType();if(c instanceof F){d=c._parent._xmlText;a=c.getOffset();if(-1===a)return null;b=a+1+b}else if(c instanceof P&&"element"===a.type){
|
|
35
|
-
function W(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!v.compareRelativePositions(a,b))return!0;return!1}function X(a,b){a=a.cursorsContainer;if(null!==a){b=b.selections;let c=b.length;for(let d=0;d<c;d++)a.removeChild(b[d])}}
|
|
34
|
+
function V(a,b){var c=b.collabNodeMap.get(a.key);if(void 0===c)return null;b=a.offset;let d=c.getSharedType();if(c instanceof F){d=c._parent._xmlText;a=c.getOffset();if(-1===a)return null;b=a+1+b}else if(c instanceof P&&"element"===a.type){var e=a.getNode();if(!r.$isElementNode(e))throw Error("Element point must be an element node");c=a=0;for(e=e.getFirstChild();null!==e&&c++<b;)r.$isTextNode(e)?a+=e.getTextContentSize()+1:a++,e=e.getNextSibling();b=a}return v.createRelativePositionFromTypeIndex(d,
|
|
35
|
+
b)}function W(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!v.compareRelativePositions(a,b))return!0;return!1}function X(a,b){a=a.cursorsContainer;if(null!==a){b=b.selections;let c=b.length;for(let d=0;d<c;d++)a.removeChild(b[d])}}
|
|
36
36
|
function Y(a,b){var c=b.awareness.getLocalState();if(null!==c&&(b=c.anchorPos,c=c.focusPos,null!==b&&null!==c&&(b=v.createAbsolutePositionFromRelativePosition(b,a.doc),a=v.createAbsolutePositionFromRelativePosition(c,a.doc),null!==b&&null!==a))){let [d,e]=Z(b.type,b.index),[f,h]=Z(a.type,a.index);if(null!==d&&null!==f){b=d.getKey();c=f.getKey();let g=r.$getSelection();r.$isRangeSelection(g)&&(a=g.focus,ma(g.anchor,b,e),ma(a,c,h))}}}
|
|
37
37
|
function ma(a,b,c){if(a.key!==b||a.offset!==c){let d=r.$getNodeByKey(b);if(null!==d&&!r.$isElementNode(d)&&!r.$isTextNode(d)){let e=d.getParentOrThrow();b=e.getKey();c=d.getIndexWithinParent();d=e}a.set(b,c,r.$isElementNode(d)?"element":"text")}}function Z(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof P){let {node:c,offset:d}=Q(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
|
|
38
38
|
function na(a,b){var c=Array.from(b.awareness.getStates()),d=a.clientID;b=a.cursors;var e=a.editor._editorState._nodeMap;let f=new Set;for(var h=0;h<c.length;h++){let [D,pa]=c[h];if(D!==d){f.add(D);let {anchorPos:ca,focusPos:da,name:qa,color:ra,focusing:sa}=pa;var g=null,m=b.get(D);void 0===m&&(m={color:ra,name:qa,selection:null},b.set(D,m));if(null!==ca&&null!==da&&sa){var p=v.createAbsolutePositionFromRelativePosition(ca,a.doc),n=v.createAbsolutePositionFromRelativePosition(da,a.doc);if(null!==
|
package/SyncCursors.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
import type { Binding } from './Bindings';
|
|
9
|
-
import type {
|
|
9
|
+
import type { BaseSelection, NodeKey } from 'lexical';
|
|
10
10
|
import { Provider } from '.';
|
|
11
11
|
export type CursorSelection = {
|
|
12
12
|
anchor: {
|
|
@@ -29,4 +29,4 @@ export type Cursor = {
|
|
|
29
29
|
};
|
|
30
30
|
export declare function syncLocalCursorPosition(binding: Binding, provider: Provider): void;
|
|
31
31
|
export declare function syncCursorPositions(binding: Binding, provider: Provider): void;
|
|
32
|
-
export declare function syncLexicalSelectionToYjs(binding: Binding, provider: Provider, prevSelection: null |
|
|
32
|
+
export declare function syncLexicalSelectionToYjs(binding: Binding, provider: Provider, prevSelection: null | BaseSelection, nextSelection: null | BaseSelection): void;
|
package/package.json
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"crdt"
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"version": "0.12.
|
|
14
|
+
"version": "0.12.6",
|
|
15
15
|
"main": "LexicalYjs.js",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/offset": "0.12.
|
|
17
|
+
"@lexical/offset": "0.12.6"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"lexical": "0.12.
|
|
20
|
+
"lexical": "0.12.6",
|
|
21
21
|
"yjs": ">=13.5.22"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|