@lexical/yjs 0.3.3 → 0.3.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/Bindings.d.ts +29 -0
- package/CollabDecoratorNode.d.ts +30 -0
- package/CollabElementNode.d.ts +47 -0
- package/CollabLineBreakNode.d.ts +26 -0
- package/CollabTextNode.d.ts +32 -0
- package/LexicalYjs.dev.js +4 -1
- package/LexicalYjs.prod.js +2 -2
- package/SyncCursors.d.ts +32 -0
- package/SyncEditorStates.d.ts +13 -0
- package/Utils.d.ts +31 -0
- package/index.d.ts +61 -0
- package/package.json +3 -3
- package/LexicalYjs.d.ts +0 -293
package/Bindings.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { CollabDecoratorNode } from './CollabDecoratorNode';
|
|
9
|
+
import type { CollabElementNode } from './CollabElementNode';
|
|
10
|
+
import type { CollabLineBreakNode } from './CollabLineBreakNode';
|
|
11
|
+
import type { CollabTextNode } from './CollabTextNode';
|
|
12
|
+
import type { Cursor } from './SyncCursors';
|
|
13
|
+
import type { LexicalEditor, NodeKey } from 'lexical';
|
|
14
|
+
import type { Doc } from 'yjs';
|
|
15
|
+
import { WebsocketProvider } from 'y-websocket';
|
|
16
|
+
export declare type ClientID = number;
|
|
17
|
+
export declare type Binding = {
|
|
18
|
+
clientID: number;
|
|
19
|
+
collabNodeMap: Map<NodeKey, CollabElementNode | CollabTextNode | CollabDecoratorNode | CollabLineBreakNode>;
|
|
20
|
+
cursors: Map<ClientID, Cursor>;
|
|
21
|
+
cursorsContainer: null | HTMLElement;
|
|
22
|
+
doc: Doc;
|
|
23
|
+
docMap: Map<string, Doc>;
|
|
24
|
+
editor: LexicalEditor;
|
|
25
|
+
id: string;
|
|
26
|
+
nodeProperties: Map<string, Array<string>>;
|
|
27
|
+
root: CollabElementNode;
|
|
28
|
+
};
|
|
29
|
+
export declare function createBinding(editor: LexicalEditor, provider: WebsocketProvider, id: string, doc: Doc | null | undefined, docMap: Map<string, Doc>): Binding;
|
|
@@ -0,0 +1,30 @@
|
|
|
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 type { Binding } from '.';
|
|
9
|
+
import type { CollabElementNode } from './CollabElementNode';
|
|
10
|
+
import type { DecoratorNode, NodeKey, NodeMap } from 'lexical';
|
|
11
|
+
import type { XmlElement } from 'yjs';
|
|
12
|
+
export declare class CollabDecoratorNode {
|
|
13
|
+
_xmlElem: XmlElement;
|
|
14
|
+
_key: NodeKey;
|
|
15
|
+
_parent: CollabElementNode;
|
|
16
|
+
_type: string;
|
|
17
|
+
_unobservers: Set<() => void>;
|
|
18
|
+
constructor(xmlElem: XmlElement, parent: CollabElementNode, type: string);
|
|
19
|
+
getPrevNode(nodeMap: null | NodeMap): null | DecoratorNode<unknown>;
|
|
20
|
+
getNode(): null | DecoratorNode<unknown>;
|
|
21
|
+
getSharedType(): XmlElement;
|
|
22
|
+
getType(): string;
|
|
23
|
+
getKey(): NodeKey;
|
|
24
|
+
getSize(): number;
|
|
25
|
+
getOffset(): number;
|
|
26
|
+
syncPropertiesFromLexical(binding: Binding, nextLexicalNode: DecoratorNode<unknown>, prevNodeMap: null | NodeMap): void;
|
|
27
|
+
syncPropertiesFromYjs(binding: Binding, keysChanged: null | Set<string>): void;
|
|
28
|
+
destroy(binding: Binding): void;
|
|
29
|
+
}
|
|
30
|
+
export declare function $createCollabDecoratorNode(xmlElem: XmlElement, parent: CollabElementNode, type: string): CollabDecoratorNode;
|
|
@@ -0,0 +1,47 @@
|
|
|
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 type { Binding } from '.';
|
|
9
|
+
import type { ElementNode, IntentionallyMarkedAsDirtyElement, NodeKey, NodeMap } from 'lexical';
|
|
10
|
+
import type { AbstractType, XmlText } from 'yjs';
|
|
11
|
+
import { CollabDecoratorNode } from './CollabDecoratorNode';
|
|
12
|
+
import { CollabLineBreakNode } from './CollabLineBreakNode';
|
|
13
|
+
import { CollabTextNode } from './CollabTextNode';
|
|
14
|
+
export declare class CollabElementNode {
|
|
15
|
+
_key: NodeKey;
|
|
16
|
+
_children: Array<CollabElementNode | CollabTextNode | CollabDecoratorNode | CollabLineBreakNode>;
|
|
17
|
+
_xmlText: XmlText;
|
|
18
|
+
_type: string;
|
|
19
|
+
_parent: null | CollabElementNode;
|
|
20
|
+
constructor(xmlText: XmlText, parent: null | CollabElementNode, type: string);
|
|
21
|
+
getPrevNode(nodeMap: null | NodeMap): null | ElementNode;
|
|
22
|
+
getNode(): null | ElementNode;
|
|
23
|
+
getSharedType(): XmlText;
|
|
24
|
+
getType(): string;
|
|
25
|
+
getKey(): NodeKey;
|
|
26
|
+
isEmpty(): boolean;
|
|
27
|
+
getSize(): number;
|
|
28
|
+
getOffset(): number;
|
|
29
|
+
syncPropertiesFromYjs(binding: Binding, keysChanged: null | Set<string>): void;
|
|
30
|
+
applyChildrenYjsDelta(binding: Binding, deltas: Array<{
|
|
31
|
+
insert?: string | object | AbstractType<unknown>;
|
|
32
|
+
delete?: number;
|
|
33
|
+
retain?: number;
|
|
34
|
+
attributes?: {
|
|
35
|
+
[x: string]: unknown;
|
|
36
|
+
};
|
|
37
|
+
}>): void;
|
|
38
|
+
syncChildrenFromYjs(binding: Binding): void;
|
|
39
|
+
syncPropertiesFromLexical(binding: Binding, nextLexicalNode: ElementNode, prevNodeMap: null | NodeMap): void;
|
|
40
|
+
_syncChildFromLexical(binding: Binding, index: number, key: NodeKey, prevNodeMap: null | NodeMap, dirtyElements: null | Map<NodeKey, IntentionallyMarkedAsDirtyElement>, dirtyLeaves: null | Set<NodeKey>): void;
|
|
41
|
+
syncChildrenFromLexical(binding: Binding, nextLexicalNode: ElementNode, prevNodeMap: null | NodeMap, dirtyElements: null | Map<NodeKey, IntentionallyMarkedAsDirtyElement>, dirtyLeaves: null | Set<NodeKey>): void;
|
|
42
|
+
append(collabNode: CollabElementNode | CollabDecoratorNode | CollabTextNode | CollabLineBreakNode): void;
|
|
43
|
+
splice(binding: Binding, index: number, delCount: number, collabNode?: CollabElementNode | CollabDecoratorNode | CollabTextNode | CollabLineBreakNode): void;
|
|
44
|
+
getChildOffset(collabNode: CollabElementNode | CollabTextNode | CollabDecoratorNode | CollabLineBreakNode): number;
|
|
45
|
+
destroy(binding: Binding): void;
|
|
46
|
+
}
|
|
47
|
+
export declare function $createCollabElementNode(xmlText: XmlText, parent: null | CollabElementNode, type: string): CollabElementNode;
|
|
@@ -0,0 +1,26 @@
|
|
|
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 type { Binding } from '.';
|
|
9
|
+
import type { CollabElementNode } from './CollabElementNode';
|
|
10
|
+
import type { LineBreakNode, NodeKey } from 'lexical';
|
|
11
|
+
import type { Map as YMap } from 'yjs';
|
|
12
|
+
export declare class CollabLineBreakNode {
|
|
13
|
+
_map: YMap<unknown>;
|
|
14
|
+
_key: NodeKey;
|
|
15
|
+
_parent: CollabElementNode;
|
|
16
|
+
_type: 'linebreak';
|
|
17
|
+
constructor(map: YMap<unknown>, parent: CollabElementNode);
|
|
18
|
+
getNode(): null | LineBreakNode;
|
|
19
|
+
getKey(): NodeKey;
|
|
20
|
+
getSharedType(): YMap<unknown>;
|
|
21
|
+
getType(): string;
|
|
22
|
+
getSize(): number;
|
|
23
|
+
getOffset(): number;
|
|
24
|
+
destroy(binding: Binding): void;
|
|
25
|
+
}
|
|
26
|
+
export declare function $createCollabLineBreakNode(map: YMap<unknown>, parent: CollabElementNode): CollabLineBreakNode;
|
|
@@ -0,0 +1,32 @@
|
|
|
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 type { Binding } from '.';
|
|
9
|
+
import type { CollabElementNode } from './CollabElementNode';
|
|
10
|
+
import type { NodeKey, NodeMap, TextNode } from 'lexical';
|
|
11
|
+
import type { Map as YMap } from 'yjs';
|
|
12
|
+
export declare class CollabTextNode {
|
|
13
|
+
_map: YMap<unknown>;
|
|
14
|
+
_key: NodeKey;
|
|
15
|
+
_parent: CollabElementNode;
|
|
16
|
+
_text: string;
|
|
17
|
+
_type: string;
|
|
18
|
+
_normalized: boolean;
|
|
19
|
+
constructor(map: YMap<unknown>, text: string, parent: CollabElementNode, type: string);
|
|
20
|
+
getPrevNode(nodeMap: null | NodeMap): null | TextNode;
|
|
21
|
+
getNode(): null | TextNode;
|
|
22
|
+
getSharedType(): YMap<unknown>;
|
|
23
|
+
getType(): string;
|
|
24
|
+
getKey(): NodeKey;
|
|
25
|
+
getSize(): number;
|
|
26
|
+
getOffset(): number;
|
|
27
|
+
spliceText(index: number, delCount: number, newText: string): void;
|
|
28
|
+
syncPropertiesAndTextFromLexical(binding: Binding, nextLexicalNode: TextNode, prevNodeMap: null | NodeMap): void;
|
|
29
|
+
syncPropertiesAndTextFromYjs(binding: Binding, keysChanged: null | Set<string>): void;
|
|
30
|
+
destroy(binding: Binding): void;
|
|
31
|
+
}
|
|
32
|
+
export declare function $createCollabTextNode(map: YMap<unknown>, text: string, parent: CollabElementNode, type: string): CollabTextNode;
|
package/LexicalYjs.dev.js
CHANGED
|
@@ -1629,7 +1629,10 @@ function handleNormalizationMergeConflicts(binding, normalizedNodes) {
|
|
|
1629
1629
|
|
|
1630
1630
|
for (let i = 0; i < mergedNodes.length; i++) {
|
|
1631
1631
|
const [collabNode, text] = mergedNodes[i];
|
|
1632
|
-
|
|
1632
|
+
|
|
1633
|
+
if (collabNode instanceof CollabTextNode && typeof text === 'string') {
|
|
1634
|
+
collabNode._text = text;
|
|
1635
|
+
}
|
|
1633
1636
|
}
|
|
1634
1637
|
}
|
|
1635
1638
|
|
package/LexicalYjs.prod.js
CHANGED
|
@@ -39,8 +39,8 @@ null!==m)){t=l.length;m=y.createRectsFromDOMRange(q,m);q=m.length;for(p=0;p<q;p+
|
|
|
39
39
|
void 0!==h&&(h=h.selection,null!==h&&U(a,h),b.delete(e)))}function fa(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:h,name:g,color:k,focusing:l}=e,n=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)r.$isRangeSelection(d)&&(e=S(d.anchor,a),n=S(d.focus,a)),(T(f,e)||T(h,n))&&b.setLocalState({anchorPos:e,color:k,focusPos:n,focusing:l,name:g})}}let ka=r.createCommand(),la=r.createCommand();exports.CONNECTED_COMMAND=ka;exports.TOGGLE_CONNECT_COMMAND=la;
|
|
40
40
|
exports.createBinding=function(a,b,c,d,e){if(void 0===d||null===d)throw Error("Should never happen");b=d.get("root",v.XmlText);b=K(b,null,"root");b._key="root";return{clientID:d.clientID,collabNodeMap:new Map,cursors:new Map,cursorsContainer:null,doc:d,docMap:e,editor:a,id:c,nodeProperties:new Map,root:b}};exports.createUndoManager=function(a,b){return new v.UndoManager(b,{trackedOrigins:new Set([a,null])})};
|
|
41
41
|
exports.initLocalState=function(a,b,c,d){a.awareness.setLocalState({anchorPos:null,color:c,focusPos:null,focusing:d,name:b})};exports.setLocalStateFocus=function(a,b,c,d){({awareness:a}=a);let e=a.getLocalState();null===e&&(e={anchorPos:null,color:c,focusPos:null,focusing:d,name:b});e.focusing=d;a.setLocalState(e)};exports.syncCursorPositions=X;
|
|
42
|
-
exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,h,g){ea(a,()=>{d.read(()=>{if(g.has("collaboration")){if(0<h.size){var k=Array.from(h),l=a.collabNodeMap,n=[];for(let p=0;p<k.length;p++){var q=k[p],t=r.$getNodeByKey(q),m=l.get(q);if(m instanceof D)if(r.$isTextNode(t))n.push([m,t.__text]);else{t=m.getOffset();if(-1===t)continue;let u=m._parent;m._normalized=!0;u._xmlText.delete(t,1);l.delete(q);q=u._children;m=q.indexOf(m);q.splice(m,1)}}for(k=0;k<n.length;k++){let [p,u]=n[k];p
|
|
43
|
-
(n=c._nodeMap,k=r.$getRoot(),l=a.root,l.syncPropertiesFromLexical(a,k,n),l.syncChildrenFromLexical(a,k,n,e,f)),n=r.$getSelection(),fa(a,b,c._selection,n)})})};
|
|
42
|
+
exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,h,g){ea(a,()=>{d.read(()=>{if(g.has("collaboration")){if(0<h.size){var k=Array.from(h),l=a.collabNodeMap,n=[];for(let p=0;p<k.length;p++){var q=k[p],t=r.$getNodeByKey(q),m=l.get(q);if(m instanceof D)if(r.$isTextNode(t))n.push([m,t.__text]);else{t=m.getOffset();if(-1===t)continue;let u=m._parent;m._normalized=!0;u._xmlText.delete(t,1);l.delete(q);q=u._children;m=q.indexOf(m);q.splice(m,1)}}for(k=0;k<n.length;k++){let [p,u]=n[k];p instanceof D&&"string"===
|
|
43
|
+
typeof u&&(p._text=u)}}}else e.has("root")&&(n=c._nodeMap,k=r.$getRoot(),l=a.root,l.syncPropertiesFromLexical(a,k,n),l.syncChildrenFromLexical(a,k,n,e,f)),n=r.$getSelection(),fa(a,b,c._selection,n)})})};
|
|
44
44
|
exports.syncYjsChangesToLexical=function(a,b,c){let d=a.editor,e=d._editorState;d.update(()=>{var f=d._pendingEditorState;for(var h=0;h<c.length;h++){var g=a,k=c[h],{target:l}=k;l=M(g,l);if(l instanceof N&&k instanceof v.YTextEvent){let {keysChanged:n,childListChanged:q,delta:t}=k;0<n.size&&l.syncPropertiesFromYjs(g,n);q&&(l.applyChildrenYjsDelta(g,t),l.syncChildrenFromYjs(g))}else if(l instanceof D&&k instanceof v.YMapEvent)({keysChanged:k}=k),0<k.size&&l.syncPropertiesAndTextFromYjs(g,k);else if(l instanceof
|
|
45
45
|
Q&&k instanceof v.YXmlEvent)({attributesChanged:k}=k),0<k.size&&l.syncPropertiesFromYjs(g,k);else throw Error("Should never happen");}h=r.$getSelection();if(r.$isRangeSelection(h))if(P(h)){g=e._selection;if(r.$isRangeSelection(g)){l=A.$createOffsetView(d,0,e);f=A.$createOffsetView(d,0,f);let [n,q]=l.getOffsetsFromSelection(g);f=f.createSelectionFromOffsets(n,q,l);null!==f?r.$setSelection(f):(V(a,b),P(h)&&(f=r.$getRoot(),0===f.getChildrenSize()&&f.append(r.$createParagraphNode()),r.$getRoot().selectEnd()))}fa(a,
|
|
46
46
|
b,g,r.$getSelection())}else V(a,b)},{onUpdate:()=>{X(a,b)},skipTransforms:!0,tag:"collaboration"})}
|
package/SyncCursors.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
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 type { Binding } from './Bindings';
|
|
9
|
+
import type { GridSelection, NodeKey, NodeSelection, RangeSelection } from 'lexical';
|
|
10
|
+
import { WebsocketProvider } from 'y-websocket';
|
|
11
|
+
export declare type CursorSelection = {
|
|
12
|
+
anchor: {
|
|
13
|
+
key: NodeKey;
|
|
14
|
+
offset: number;
|
|
15
|
+
};
|
|
16
|
+
caret: HTMLElement;
|
|
17
|
+
color: string;
|
|
18
|
+
focus: {
|
|
19
|
+
key: NodeKey;
|
|
20
|
+
offset: number;
|
|
21
|
+
};
|
|
22
|
+
name: HTMLSpanElement;
|
|
23
|
+
selections: Array<HTMLElement>;
|
|
24
|
+
};
|
|
25
|
+
export declare type Cursor = {
|
|
26
|
+
color: string;
|
|
27
|
+
name: string;
|
|
28
|
+
selection: null | CursorSelection;
|
|
29
|
+
};
|
|
30
|
+
export declare function syncLocalCursorPosition(binding: Binding, provider: WebsocketProvider): void;
|
|
31
|
+
export declare function syncCursorPositions(binding: Binding, provider: WebsocketProvider): void;
|
|
32
|
+
export declare function syncLexicalSelectionToYjs(binding: Binding, provider: WebsocketProvider, prevSelection: null | RangeSelection | NodeSelection | GridSelection, nextSelection: null | RangeSelection | NodeSelection | GridSelection): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
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 type { EditorState, IntentionallyMarkedAsDirtyElement, NodeKey } from 'lexical';
|
|
9
|
+
import { WebsocketProvider } from 'y-websocket';
|
|
10
|
+
import { Text as YText, YEvent } from 'yjs';
|
|
11
|
+
import { Binding } from '.';
|
|
12
|
+
export declare function syncYjsChangesToLexical(binding: Binding, provider: WebsocketProvider, events: Array<YEvent<YText>>): void;
|
|
13
|
+
export declare function syncLexicalUpdateToYjs(binding: Binding, provider: WebsocketProvider, prevEditorState: EditorState, currEditorState: EditorState, dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>, dirtyLeaves: Set<NodeKey>, normalizedNodes: Set<NodeKey>, tags: Set<string>): void;
|
package/Utils.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
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 type { Binding, YjsNode } from '.';
|
|
9
|
+
import type { LexicalNode, RangeSelection } from 'lexical';
|
|
10
|
+
import { NodeKey } from 'lexical';
|
|
11
|
+
import { Map as YMap, XmlElement, XmlText } from 'yjs';
|
|
12
|
+
import { CollabDecoratorNode } from './CollabDecoratorNode';
|
|
13
|
+
import { CollabElementNode } from './CollabElementNode';
|
|
14
|
+
import { CollabLineBreakNode } from './CollabLineBreakNode';
|
|
15
|
+
import { CollabTextNode } from './CollabTextNode';
|
|
16
|
+
export declare function getIndexOfYjsNode(yjsParentNode: YjsNode, yjsNode: YjsNode): number;
|
|
17
|
+
export declare function $getNodeByKeyOrThrow(key: NodeKey): LexicalNode;
|
|
18
|
+
export declare function $createCollabNodeFromLexicalNode(binding: Binding, lexicalNode: LexicalNode, parent: CollabElementNode): CollabElementNode | CollabTextNode | CollabLineBreakNode | CollabDecoratorNode;
|
|
19
|
+
export declare function getOrInitCollabNodeFromSharedType(binding: Binding, sharedType: XmlText | YMap<unknown> | XmlElement, parent?: CollabElementNode): CollabElementNode | CollabTextNode | CollabLineBreakNode | CollabDecoratorNode;
|
|
20
|
+
export declare function createLexicalNodeFromCollabNode(binding: Binding, collabNode: CollabElementNode | CollabTextNode | CollabDecoratorNode | CollabLineBreakNode, parentKey: NodeKey): LexicalNode;
|
|
21
|
+
export declare function syncPropertiesFromYjs(binding: Binding, sharedType: XmlText | YMap<unknown> | XmlElement, lexicalNode: LexicalNode, keysChanged: null | Set<string>): void;
|
|
22
|
+
export declare function syncPropertiesFromLexical(binding: Binding, sharedType: XmlText | YMap<unknown> | XmlElement, prevLexicalNode: null | LexicalNode, nextLexicalNode: LexicalNode): void;
|
|
23
|
+
export declare function spliceString(str: string, index: number, delCount: number, newText: string): string;
|
|
24
|
+
export declare function getPositionFromElementAndOffset(node: CollabElementNode, offset: number, boundaryIsEdge: boolean): {
|
|
25
|
+
length: number;
|
|
26
|
+
node: CollabElementNode | CollabTextNode | CollabDecoratorNode | CollabLineBreakNode | null;
|
|
27
|
+
nodeIndex: number;
|
|
28
|
+
offset: number;
|
|
29
|
+
};
|
|
30
|
+
export declare function doesSelectionNeedRecovering(selection: RangeSelection): boolean;
|
|
31
|
+
export declare function syncWithTransaction(binding: Binding, fn: () => void): void;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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 type { Binding } from './Bindings';
|
|
9
|
+
import type { LexicalCommand } from 'lexical';
|
|
10
|
+
import type { WebsocketProvider } from 'y-websocket';
|
|
11
|
+
import type { Doc, RelativePosition, UndoManager, XmlText } from 'yjs';
|
|
12
|
+
export declare type UserState = {
|
|
13
|
+
anchorPos: null | RelativePosition;
|
|
14
|
+
color: string;
|
|
15
|
+
focusing: boolean;
|
|
16
|
+
focusPos: null | RelativePosition;
|
|
17
|
+
name: string;
|
|
18
|
+
};
|
|
19
|
+
export declare const CONNECTED_COMMAND: LexicalCommand<boolean>;
|
|
20
|
+
export declare const TOGGLE_CONNECT_COMMAND: LexicalCommand<boolean>;
|
|
21
|
+
export declare type ProviderAwareness = {
|
|
22
|
+
getLocalState: () => UserState | null;
|
|
23
|
+
getStates: () => Map<number, UserState>;
|
|
24
|
+
off: (type: 'update', cb: () => void) => void;
|
|
25
|
+
on: (type: 'update', cb: () => void) => void;
|
|
26
|
+
setLocalState: (arg0: UserState) => void;
|
|
27
|
+
};
|
|
28
|
+
declare interface Provider {
|
|
29
|
+
awareness: ProviderAwareness;
|
|
30
|
+
connect(): void | Promise<void>;
|
|
31
|
+
disconnect(): void;
|
|
32
|
+
off(type: 'sync', cb: (isSynced: boolean) => void): void;
|
|
33
|
+
off(type: 'update', cb: (arg0: unknown) => void): void;
|
|
34
|
+
off(type: 'status', cb: (arg0: {
|
|
35
|
+
status: string;
|
|
36
|
+
}) => void): void;
|
|
37
|
+
off(type: 'reload', cb: (doc: Doc) => void): void;
|
|
38
|
+
on(type: 'sync', cb: (isSynced: boolean) => void): void;
|
|
39
|
+
on(type: 'status', cb: (arg0: {
|
|
40
|
+
status: string;
|
|
41
|
+
}) => void): void;
|
|
42
|
+
on(type: 'update', cb: (arg0: unknown) => void): void;
|
|
43
|
+
on(type: 'reload', cb: (doc: Doc) => void): void;
|
|
44
|
+
}
|
|
45
|
+
export declare type Operation = {
|
|
46
|
+
attributes: {
|
|
47
|
+
__type: string;
|
|
48
|
+
};
|
|
49
|
+
insert: string | Record<string, unknown>;
|
|
50
|
+
};
|
|
51
|
+
export declare type Delta = Array<Operation>;
|
|
52
|
+
export declare type YjsNode = Record<string, unknown>;
|
|
53
|
+
export declare type YjsEvent = Record<string, unknown>;
|
|
54
|
+
export type { Provider };
|
|
55
|
+
export type { Binding, ClientID } from './Bindings';
|
|
56
|
+
export { createBinding } from './Bindings';
|
|
57
|
+
export declare function createUndoManager(binding: Binding, root: XmlText): UndoManager;
|
|
58
|
+
export declare function initLocalState(provider: WebsocketProvider, name: string, color: string, focusing: boolean): void;
|
|
59
|
+
export declare function setLocalStateFocus(provider: WebsocketProvider, name: string, color: string, focusing: boolean): void;
|
|
60
|
+
export { syncCursorPositions } from './SyncCursors';
|
|
61
|
+
export { syncLexicalUpdateToYjs, syncYjsChangesToLexical, } from './SyncEditorStates';
|
package/package.json
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"crdt"
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"version": "0.3.
|
|
14
|
+
"version": "0.3.6",
|
|
15
15
|
"main": "LexicalYjs.js",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/offset": "0.3.
|
|
17
|
+
"@lexical/offset": "0.3.6"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"lexical": "0.3.
|
|
20
|
+
"lexical": "0.3.6",
|
|
21
21
|
"yjs": ">=13.5.22"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
package/LexicalYjs.d.ts
DELETED
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type {
|
|
10
|
-
Doc,
|
|
11
|
-
RelativePosition,
|
|
12
|
-
UndoManager,
|
|
13
|
-
XmlElement,
|
|
14
|
-
XmlText,
|
|
15
|
-
Map as YMap,
|
|
16
|
-
AbstractType,
|
|
17
|
-
} from 'yjs';
|
|
18
|
-
import type {
|
|
19
|
-
DecoratorNode,
|
|
20
|
-
EditorState,
|
|
21
|
-
ElementNode,
|
|
22
|
-
LexicalCommand,
|
|
23
|
-
LexicalEditor,
|
|
24
|
-
LineBreakNode,
|
|
25
|
-
NodeMap,
|
|
26
|
-
NodeKey,
|
|
27
|
-
TextNode,
|
|
28
|
-
IntentionallyMarkedAsDirtyElement,
|
|
29
|
-
} from 'lexical';
|
|
30
|
-
export type YjsEvent = Record<string, any>;
|
|
31
|
-
export type UserState = {
|
|
32
|
-
anchorPos: null | RelativePosition;
|
|
33
|
-
color: string;
|
|
34
|
-
focusing: boolean;
|
|
35
|
-
focusPos: null | RelativePosition;
|
|
36
|
-
name: string;
|
|
37
|
-
};
|
|
38
|
-
export type ProviderAwareness = {
|
|
39
|
-
getLocalState: () => UserState | null;
|
|
40
|
-
getStates: () => Map<number, UserState>;
|
|
41
|
-
off: (type: 'update', cb: () => void) => void;
|
|
42
|
-
on: (type: 'update', cb: () => void) => void;
|
|
43
|
-
setLocalState: (arg0: UserState) => void;
|
|
44
|
-
};
|
|
45
|
-
declare interface Provider {
|
|
46
|
-
awareness: ProviderAwareness;
|
|
47
|
-
connect(): void | Promise<void>;
|
|
48
|
-
disconnect(): void;
|
|
49
|
-
off(type: 'sync', cb: (isSynced: boolean) => void): void;
|
|
50
|
-
off(type: 'update', cb: (arg0: any) => void): void;
|
|
51
|
-
off(type: 'status', cb: (arg0: {status: string}) => void): void;
|
|
52
|
-
off(type: 'reload', cb: (doc: Doc) => void): void;
|
|
53
|
-
on(type: 'sync', cb: (isSynced: boolean) => void): void;
|
|
54
|
-
on(type: 'status', cb: (arg0: {status: string}) => void): void;
|
|
55
|
-
on(type: 'update', cb: (arg0: any) => void): void;
|
|
56
|
-
on(type: 'reload', cb: (doc: Doc) => void): void;
|
|
57
|
-
}
|
|
58
|
-
export type ClientID = number;
|
|
59
|
-
export type CursorSelection = {
|
|
60
|
-
anchor: {
|
|
61
|
-
key: NodeKey;
|
|
62
|
-
offset: number;
|
|
63
|
-
};
|
|
64
|
-
caret: HTMLElement;
|
|
65
|
-
color: string;
|
|
66
|
-
focus: {
|
|
67
|
-
key: NodeKey;
|
|
68
|
-
offset: number;
|
|
69
|
-
};
|
|
70
|
-
name: HTMLSpanElement;
|
|
71
|
-
selections: Array<HTMLElement>;
|
|
72
|
-
};
|
|
73
|
-
export type Cursor = {
|
|
74
|
-
color: string;
|
|
75
|
-
name: string;
|
|
76
|
-
selection: null | CursorSelection;
|
|
77
|
-
};
|
|
78
|
-
export type TextOperation = {
|
|
79
|
-
insert?: string | object | AbstractType<unknown>;
|
|
80
|
-
delete?: number;
|
|
81
|
-
retain?: number;
|
|
82
|
-
attributes?: {
|
|
83
|
-
[x: string]: unknown;
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export type Binding = {
|
|
88
|
-
clientID: number;
|
|
89
|
-
collabNodeMap: Map<
|
|
90
|
-
NodeKey,
|
|
91
|
-
| CollabElementNode
|
|
92
|
-
| CollabTextNode
|
|
93
|
-
| CollabDecoratorNode
|
|
94
|
-
| CollabLineBreakNode
|
|
95
|
-
>;
|
|
96
|
-
cursors: Map<ClientID, Cursor>;
|
|
97
|
-
cursorsContainer: null | HTMLElement;
|
|
98
|
-
doc: Doc;
|
|
99
|
-
docMap: Map<string, Doc>;
|
|
100
|
-
editor: LexicalEditor;
|
|
101
|
-
id: string;
|
|
102
|
-
nodeProperties: Map<string, Array<string>>;
|
|
103
|
-
root: CollabElementNode;
|
|
104
|
-
};
|
|
105
|
-
export declare class CollabDecoratorNode {
|
|
106
|
-
_xmlElem: XmlElement;
|
|
107
|
-
_key: NodeKey;
|
|
108
|
-
_parent: CollabElementNode;
|
|
109
|
-
_type: string;
|
|
110
|
-
_unobservers: Set<() => void>;
|
|
111
|
-
constructor(xmlElem: XmlElement, parent: CollabElementNode, type: string);
|
|
112
|
-
getPrevNode(nodeMap: null | NodeMap): null | DecoratorNode<unknown>;
|
|
113
|
-
getNode(): null | DecoratorNode<unknown>;
|
|
114
|
-
getSharedType(): XmlElement;
|
|
115
|
-
getType(): string;
|
|
116
|
-
getKey(): NodeKey;
|
|
117
|
-
getSize(): number;
|
|
118
|
-
getOffset(): number;
|
|
119
|
-
syncPropertiesFromLexical(
|
|
120
|
-
binding: Binding,
|
|
121
|
-
nextLexicalNode: DecoratorNode<unknown>,
|
|
122
|
-
prevNodeMap: null | NodeMap,
|
|
123
|
-
): void;
|
|
124
|
-
syncPropertiesFromYjs(
|
|
125
|
-
binding: Binding,
|
|
126
|
-
keysChanged: null | Set<string>,
|
|
127
|
-
): void;
|
|
128
|
-
destroy(binding: Binding): void;
|
|
129
|
-
}
|
|
130
|
-
export declare class CollabLineBreakNode {
|
|
131
|
-
_map: YMap<unknown>;
|
|
132
|
-
_key: NodeKey;
|
|
133
|
-
_parent: CollabElementNode;
|
|
134
|
-
_type: 'linebreak';
|
|
135
|
-
constructor(map: YMap<unknown>, parent: CollabElementNode);
|
|
136
|
-
getNode(): null | LineBreakNode;
|
|
137
|
-
getKey(): NodeKey;
|
|
138
|
-
getSharedType(): YMap<unknown>;
|
|
139
|
-
getType(): string;
|
|
140
|
-
getSize(): number;
|
|
141
|
-
getOffset(): number;
|
|
142
|
-
destroy(binding: Binding): void;
|
|
143
|
-
}
|
|
144
|
-
export declare class CollabTextNode {
|
|
145
|
-
_map: YMap<unknown>;
|
|
146
|
-
_key: NodeKey;
|
|
147
|
-
_parent: CollabElementNode;
|
|
148
|
-
_text: string;
|
|
149
|
-
_type: string;
|
|
150
|
-
_normalized: boolean;
|
|
151
|
-
constructor(
|
|
152
|
-
map: YMap<unknown>,
|
|
153
|
-
text: string,
|
|
154
|
-
parent: CollabElementNode,
|
|
155
|
-
type: string,
|
|
156
|
-
);
|
|
157
|
-
getPrevNode(nodeMap: null | NodeMap): null | TextNode;
|
|
158
|
-
getNode(): null | TextNode;
|
|
159
|
-
getSharedType(): YMap<unknown>;
|
|
160
|
-
getType(): string;
|
|
161
|
-
getKey(): NodeKey;
|
|
162
|
-
getSize(): number;
|
|
163
|
-
getOffset(): number;
|
|
164
|
-
spliceText(index: number, delCount: number, newText: string): void;
|
|
165
|
-
syncPropertiesAndTextFromLexical(
|
|
166
|
-
binding: Binding,
|
|
167
|
-
nextLexicalNode: TextNode,
|
|
168
|
-
prevNodeMap: null | NodeMap,
|
|
169
|
-
): void;
|
|
170
|
-
syncPropertiesAndTextFromYjs(
|
|
171
|
-
binding: Binding,
|
|
172
|
-
keysChanged: null | Set<string>,
|
|
173
|
-
): void;
|
|
174
|
-
destroy(binding: Binding): void;
|
|
175
|
-
}
|
|
176
|
-
export declare class CollabElementNode {
|
|
177
|
-
_key: NodeKey;
|
|
178
|
-
_children: Array<
|
|
179
|
-
| CollabElementNode
|
|
180
|
-
| CollabTextNode
|
|
181
|
-
| CollabDecoratorNode
|
|
182
|
-
| CollabLineBreakNode
|
|
183
|
-
>;
|
|
184
|
-
_xmlText: XmlText;
|
|
185
|
-
_type: string;
|
|
186
|
-
_parent: null | CollabElementNode;
|
|
187
|
-
constructor(xmlText: XmlText, parent: null | CollabElementNode, type: string);
|
|
188
|
-
getPrevNode(nodeMap: null | NodeMap): null | ElementNode;
|
|
189
|
-
getNode(): null | ElementNode;
|
|
190
|
-
getSharedType(): XmlText;
|
|
191
|
-
getType(): string;
|
|
192
|
-
getKey(): NodeKey;
|
|
193
|
-
isEmpty(): boolean;
|
|
194
|
-
getSize(): number;
|
|
195
|
-
getOffset(): number;
|
|
196
|
-
syncPropertiesFromYjs(
|
|
197
|
-
binding: Binding,
|
|
198
|
-
keysChanged: null | Set<string>,
|
|
199
|
-
): void;
|
|
200
|
-
applyChildrenYjsDelta(binding: Binding, deltas: Array<TextOperation>): void;
|
|
201
|
-
syncChildrenFromYjs(binding: Binding): void;
|
|
202
|
-
syncPropertiesFromLexical(
|
|
203
|
-
binding: Binding,
|
|
204
|
-
nextLexicalNode: ElementNode,
|
|
205
|
-
prevNodeMap: null | NodeMap,
|
|
206
|
-
): void;
|
|
207
|
-
_syncChildFromLexical(
|
|
208
|
-
binding: Binding,
|
|
209
|
-
index: number,
|
|
210
|
-
key: NodeKey,
|
|
211
|
-
prevNodeMap: null | NodeMap,
|
|
212
|
-
dirtyElements: null | Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
|
|
213
|
-
dirtyLeaves: null | Set<NodeKey>,
|
|
214
|
-
): void;
|
|
215
|
-
syncChildrenFromLexical(
|
|
216
|
-
binding: Binding,
|
|
217
|
-
nextLexicalNode: ElementNode,
|
|
218
|
-
prevNodeMap: null | NodeMap,
|
|
219
|
-
dirtyElements: null | Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
|
|
220
|
-
dirtyLeaves: null | Set<NodeKey>,
|
|
221
|
-
): void;
|
|
222
|
-
append(
|
|
223
|
-
collabNode:
|
|
224
|
-
| CollabElementNode
|
|
225
|
-
| CollabDecoratorNode
|
|
226
|
-
| CollabTextNode
|
|
227
|
-
| CollabLineBreakNode,
|
|
228
|
-
): void;
|
|
229
|
-
splice(
|
|
230
|
-
binding: Binding,
|
|
231
|
-
index: number,
|
|
232
|
-
delCount: number,
|
|
233
|
-
collabNode?:
|
|
234
|
-
| CollabElementNode
|
|
235
|
-
| CollabDecoratorNode
|
|
236
|
-
| CollabTextNode
|
|
237
|
-
| CollabLineBreakNode,
|
|
238
|
-
): void;
|
|
239
|
-
getChildOffset(
|
|
240
|
-
collabNode:
|
|
241
|
-
| CollabElementNode
|
|
242
|
-
| CollabTextNode
|
|
243
|
-
| CollabDecoratorNode
|
|
244
|
-
| CollabLineBreakNode,
|
|
245
|
-
): number;
|
|
246
|
-
destroy(binding: Binding): void;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
export function createUndoManager(binding: Binding, root: XmlText): UndoManager;
|
|
250
|
-
|
|
251
|
-
export function initLocalState(
|
|
252
|
-
provider: Provider,
|
|
253
|
-
name: string,
|
|
254
|
-
color: string,
|
|
255
|
-
focusing: boolean,
|
|
256
|
-
): void;
|
|
257
|
-
|
|
258
|
-
export function setLocalStateFocus(
|
|
259
|
-
provider: Provider,
|
|
260
|
-
name: string,
|
|
261
|
-
color: string,
|
|
262
|
-
focusing: boolean,
|
|
263
|
-
): void;
|
|
264
|
-
|
|
265
|
-
export function createBinding(
|
|
266
|
-
editor: LexicalEditor,
|
|
267
|
-
provider: Provider,
|
|
268
|
-
id: string,
|
|
269
|
-
doc: Doc | null | undefined,
|
|
270
|
-
docMap: Map<string, Doc>,
|
|
271
|
-
): Binding;
|
|
272
|
-
|
|
273
|
-
export function syncCursorPositions(binding: Binding, provider: Provider): void;
|
|
274
|
-
|
|
275
|
-
export function syncLexicalUpdateToYjs(
|
|
276
|
-
binding: Binding,
|
|
277
|
-
provider: Provider,
|
|
278
|
-
prevEditorState: EditorState,
|
|
279
|
-
currEditorState: EditorState,
|
|
280
|
-
dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
|
|
281
|
-
dirtyLeaves: Set<NodeKey>,
|
|
282
|
-
normalizedNodes: Set<NodeKey>,
|
|
283
|
-
tags: Set<string>,
|
|
284
|
-
): void;
|
|
285
|
-
|
|
286
|
-
export function syncYjsChangesToLexical(
|
|
287
|
-
binding: Binding,
|
|
288
|
-
provider: Provider,
|
|
289
|
-
events: Array<YjsEvent>,
|
|
290
|
-
): void;
|
|
291
|
-
export declare var CONNECTED_COMMAND: LexicalCommand<boolean>;
|
|
292
|
-
export declare var TOGGLE_CONNECT_COMMAND: LexicalCommand<boolean>;
|
|
293
|
-
export type {Provider};
|