@lexical/yjs 0.22.1-nightly.20250103.0 → 0.23.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.js +59 -42
- package/LexicalYjs.dev.mjs +60 -44
- package/LexicalYjs.mjs +1 -0
- package/LexicalYjs.node.mjs +1 -0
- package/LexicalYjs.prod.js +36 -35
- package/LexicalYjs.prod.mjs +1 -1
- package/SyncCursors.d.ts +13 -1
- package/index.d.ts +1 -1
- package/package.json +4 -4
package/LexicalYjs.dev.js
CHANGED
|
@@ -1248,33 +1248,51 @@ function updateCursor(binding, cursor, nextSelection, nodeMap) {
|
|
|
1248
1248
|
selections.pop();
|
|
1249
1249
|
}
|
|
1250
1250
|
}
|
|
1251
|
+
function getAnchorAndFocusCollabNodesForUserState(binding, userState) {
|
|
1252
|
+
const {
|
|
1253
|
+
anchorPos,
|
|
1254
|
+
focusPos
|
|
1255
|
+
} = userState;
|
|
1256
|
+
let anchorCollabNode = null;
|
|
1257
|
+
let anchorOffset = 0;
|
|
1258
|
+
let focusCollabNode = null;
|
|
1259
|
+
let focusOffset = 0;
|
|
1260
|
+
if (anchorPos !== null && focusPos !== null) {
|
|
1261
|
+
const anchorAbsPos = createAbsolutePosition(anchorPos, binding);
|
|
1262
|
+
const focusAbsPos = createAbsolutePosition(focusPos, binding);
|
|
1263
|
+
if (anchorAbsPos !== null && focusAbsPos !== null) {
|
|
1264
|
+
[anchorCollabNode, anchorOffset] = getCollabNodeAndOffset(anchorAbsPos.type, anchorAbsPos.index);
|
|
1265
|
+
[focusCollabNode, focusOffset] = getCollabNodeAndOffset(focusAbsPos.type, focusAbsPos.index);
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
return {
|
|
1269
|
+
anchorCollabNode,
|
|
1270
|
+
anchorOffset,
|
|
1271
|
+
focusCollabNode,
|
|
1272
|
+
focusOffset
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1251
1275
|
function $syncLocalCursorPosition(binding, provider) {
|
|
1252
1276
|
const awareness = provider.awareness;
|
|
1253
1277
|
const localState = awareness.getLocalState();
|
|
1254
1278
|
if (localState === null) {
|
|
1255
1279
|
return;
|
|
1256
1280
|
}
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
1270
|
-
return;
|
|
1271
|
-
}
|
|
1272
|
-
const anchor = selection.anchor;
|
|
1273
|
-
const focus = selection.focus;
|
|
1274
|
-
$setPoint(anchor, anchorKey, anchorOffset);
|
|
1275
|
-
$setPoint(focus, focusKey, focusOffset);
|
|
1276
|
-
}
|
|
1281
|
+
const {
|
|
1282
|
+
anchorCollabNode,
|
|
1283
|
+
anchorOffset,
|
|
1284
|
+
focusCollabNode,
|
|
1285
|
+
focusOffset
|
|
1286
|
+
} = getAnchorAndFocusCollabNodesForUserState(binding, localState);
|
|
1287
|
+
if (anchorCollabNode !== null && focusCollabNode !== null) {
|
|
1288
|
+
const anchorKey = anchorCollabNode.getKey();
|
|
1289
|
+
const focusKey = focusCollabNode.getKey();
|
|
1290
|
+
const selection = lexical.$getSelection();
|
|
1291
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
1292
|
+
return;
|
|
1277
1293
|
}
|
|
1294
|
+
$setPoint(selection.anchor, anchorKey, anchorOffset);
|
|
1295
|
+
$setPoint(selection.focus, focusKey, focusOffset);
|
|
1278
1296
|
}
|
|
1279
1297
|
}
|
|
1280
1298
|
function $setPoint(point, key, offset) {
|
|
@@ -1322,8 +1340,6 @@ function syncCursorPositions(binding, provider) {
|
|
|
1322
1340
|
if (clientID !== localClientID) {
|
|
1323
1341
|
visitedClientIDs.add(clientID);
|
|
1324
1342
|
const {
|
|
1325
|
-
anchorPos,
|
|
1326
|
-
focusPos,
|
|
1327
1343
|
name,
|
|
1328
1344
|
color,
|
|
1329
1345
|
focusing
|
|
@@ -1334,26 +1350,26 @@ function syncCursorPositions(binding, provider) {
|
|
|
1334
1350
|
cursor = createCursor(name, color);
|
|
1335
1351
|
cursors.set(clientID, cursor);
|
|
1336
1352
|
}
|
|
1337
|
-
if (
|
|
1338
|
-
const
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1353
|
+
if (focusing) {
|
|
1354
|
+
const {
|
|
1355
|
+
anchorCollabNode,
|
|
1356
|
+
anchorOffset,
|
|
1357
|
+
focusCollabNode,
|
|
1358
|
+
focusOffset
|
|
1359
|
+
} = getAnchorAndFocusCollabNodesForUserState(binding, awareness);
|
|
1360
|
+
if (anchorCollabNode !== null && focusCollabNode !== null) {
|
|
1361
|
+
const anchorKey = anchorCollabNode.getKey();
|
|
1362
|
+
const focusKey = focusCollabNode.getKey();
|
|
1363
|
+
selection = cursor.selection;
|
|
1364
|
+
if (selection === null) {
|
|
1365
|
+
selection = createCursorSelection(cursor, anchorKey, anchorOffset, focusKey, focusOffset);
|
|
1366
|
+
} else {
|
|
1367
|
+
const anchor = selection.anchor;
|
|
1368
|
+
const focus = selection.focus;
|
|
1369
|
+
anchor.key = anchorKey;
|
|
1370
|
+
anchor.offset = anchorOffset;
|
|
1371
|
+
focus.key = focusKey;
|
|
1372
|
+
focus.offset = focusOffset;
|
|
1357
1373
|
}
|
|
1358
1374
|
}
|
|
1359
1375
|
}
|
|
@@ -1627,6 +1643,7 @@ exports.CONNECTED_COMMAND = CONNECTED_COMMAND;
|
|
|
1627
1643
|
exports.TOGGLE_CONNECT_COMMAND = TOGGLE_CONNECT_COMMAND;
|
|
1628
1644
|
exports.createBinding = createBinding;
|
|
1629
1645
|
exports.createUndoManager = createUndoManager;
|
|
1646
|
+
exports.getAnchorAndFocusCollabNodesForUserState = getAnchorAndFocusCollabNodesForUserState;
|
|
1630
1647
|
exports.initLocalState = initLocalState;
|
|
1631
1648
|
exports.setLocalStateFocus = setLocalStateFocus;
|
|
1632
1649
|
exports.syncCursorPositions = syncCursorPositions;
|
package/LexicalYjs.dev.mjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { $getNodeByKey, $isLineBreakNode, $isTextNode, $getSelection, $isRangeSelection,
|
|
9
|
+
import { $getNodeByKey, $isLineBreakNode, $isTextNode, $getSelection, $isRangeSelection, $isElementNode, $isDecoratorNode, createEditor, $getRoot, $isRootNode, $createParagraphNode, createCommand } from 'lexical';
|
|
10
10
|
import { XmlText, Map as Map$1, XmlElement, Doc, createAbsolutePositionFromRelativePosition, createRelativePositionFromTypeIndex, compareRelativePositions, YTextEvent, YMapEvent, YXmlEvent, UndoManager } from 'yjs';
|
|
11
11
|
import { $createChildrenArray } from '@lexical/offset';
|
|
12
12
|
import { createDOMRange, createRectsFromDOMRange } from '@lexical/selection';
|
|
@@ -1246,33 +1246,51 @@ function updateCursor(binding, cursor, nextSelection, nodeMap) {
|
|
|
1246
1246
|
selections.pop();
|
|
1247
1247
|
}
|
|
1248
1248
|
}
|
|
1249
|
+
function getAnchorAndFocusCollabNodesForUserState(binding, userState) {
|
|
1250
|
+
const {
|
|
1251
|
+
anchorPos,
|
|
1252
|
+
focusPos
|
|
1253
|
+
} = userState;
|
|
1254
|
+
let anchorCollabNode = null;
|
|
1255
|
+
let anchorOffset = 0;
|
|
1256
|
+
let focusCollabNode = null;
|
|
1257
|
+
let focusOffset = 0;
|
|
1258
|
+
if (anchorPos !== null && focusPos !== null) {
|
|
1259
|
+
const anchorAbsPos = createAbsolutePosition(anchorPos, binding);
|
|
1260
|
+
const focusAbsPos = createAbsolutePosition(focusPos, binding);
|
|
1261
|
+
if (anchorAbsPos !== null && focusAbsPos !== null) {
|
|
1262
|
+
[anchorCollabNode, anchorOffset] = getCollabNodeAndOffset(anchorAbsPos.type, anchorAbsPos.index);
|
|
1263
|
+
[focusCollabNode, focusOffset] = getCollabNodeAndOffset(focusAbsPos.type, focusAbsPos.index);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
return {
|
|
1267
|
+
anchorCollabNode,
|
|
1268
|
+
anchorOffset,
|
|
1269
|
+
focusCollabNode,
|
|
1270
|
+
focusOffset
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1249
1273
|
function $syncLocalCursorPosition(binding, provider) {
|
|
1250
1274
|
const awareness = provider.awareness;
|
|
1251
1275
|
const localState = awareness.getLocalState();
|
|
1252
1276
|
if (localState === null) {
|
|
1253
1277
|
return;
|
|
1254
1278
|
}
|
|
1255
|
-
const
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
if (!$isRangeSelection(selection)) {
|
|
1268
|
-
return;
|
|
1269
|
-
}
|
|
1270
|
-
const anchor = selection.anchor;
|
|
1271
|
-
const focus = selection.focus;
|
|
1272
|
-
$setPoint(anchor, anchorKey, anchorOffset);
|
|
1273
|
-
$setPoint(focus, focusKey, focusOffset);
|
|
1274
|
-
}
|
|
1279
|
+
const {
|
|
1280
|
+
anchorCollabNode,
|
|
1281
|
+
anchorOffset,
|
|
1282
|
+
focusCollabNode,
|
|
1283
|
+
focusOffset
|
|
1284
|
+
} = getAnchorAndFocusCollabNodesForUserState(binding, localState);
|
|
1285
|
+
if (anchorCollabNode !== null && focusCollabNode !== null) {
|
|
1286
|
+
const anchorKey = anchorCollabNode.getKey();
|
|
1287
|
+
const focusKey = focusCollabNode.getKey();
|
|
1288
|
+
const selection = $getSelection();
|
|
1289
|
+
if (!$isRangeSelection(selection)) {
|
|
1290
|
+
return;
|
|
1275
1291
|
}
|
|
1292
|
+
$setPoint(selection.anchor, anchorKey, anchorOffset);
|
|
1293
|
+
$setPoint(selection.focus, focusKey, focusOffset);
|
|
1276
1294
|
}
|
|
1277
1295
|
}
|
|
1278
1296
|
function $setPoint(point, key, offset) {
|
|
@@ -1320,8 +1338,6 @@ function syncCursorPositions(binding, provider) {
|
|
|
1320
1338
|
if (clientID !== localClientID) {
|
|
1321
1339
|
visitedClientIDs.add(clientID);
|
|
1322
1340
|
const {
|
|
1323
|
-
anchorPos,
|
|
1324
|
-
focusPos,
|
|
1325
1341
|
name,
|
|
1326
1342
|
color,
|
|
1327
1343
|
focusing
|
|
@@ -1332,26 +1348,26 @@ function syncCursorPositions(binding, provider) {
|
|
|
1332
1348
|
cursor = createCursor(name, color);
|
|
1333
1349
|
cursors.set(clientID, cursor);
|
|
1334
1350
|
}
|
|
1335
|
-
if (
|
|
1336
|
-
const
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1351
|
+
if (focusing) {
|
|
1352
|
+
const {
|
|
1353
|
+
anchorCollabNode,
|
|
1354
|
+
anchorOffset,
|
|
1355
|
+
focusCollabNode,
|
|
1356
|
+
focusOffset
|
|
1357
|
+
} = getAnchorAndFocusCollabNodesForUserState(binding, awareness);
|
|
1358
|
+
if (anchorCollabNode !== null && focusCollabNode !== null) {
|
|
1359
|
+
const anchorKey = anchorCollabNode.getKey();
|
|
1360
|
+
const focusKey = focusCollabNode.getKey();
|
|
1361
|
+
selection = cursor.selection;
|
|
1362
|
+
if (selection === null) {
|
|
1363
|
+
selection = createCursorSelection(cursor, anchorKey, anchorOffset, focusKey, focusOffset);
|
|
1364
|
+
} else {
|
|
1365
|
+
const anchor = selection.anchor;
|
|
1366
|
+
const focus = selection.focus;
|
|
1367
|
+
anchor.key = anchorKey;
|
|
1368
|
+
anchor.offset = anchorOffset;
|
|
1369
|
+
focus.key = focusKey;
|
|
1370
|
+
focus.offset = focusOffset;
|
|
1355
1371
|
}
|
|
1356
1372
|
}
|
|
1357
1373
|
}
|
|
@@ -1621,4 +1637,4 @@ function setLocalStateFocus(provider, name, color, focusing, awarenessData) {
|
|
|
1621
1637
|
awareness.setLocalState(localState);
|
|
1622
1638
|
}
|
|
1623
1639
|
|
|
1624
|
-
export { CONNECTED_COMMAND, TOGGLE_CONNECT_COMMAND, createBinding, createUndoManager, initLocalState, setLocalStateFocus, syncCursorPositions, syncLexicalUpdateToYjs, syncYjsChangesToLexical };
|
|
1640
|
+
export { CONNECTED_COMMAND, TOGGLE_CONNECT_COMMAND, createBinding, createUndoManager, getAnchorAndFocusCollabNodesForUserState, initLocalState, setLocalStateFocus, syncCursorPositions, syncLexicalUpdateToYjs, syncYjsChangesToLexical };
|
package/LexicalYjs.mjs
CHANGED
|
@@ -13,6 +13,7 @@ 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
15
|
export const createUndoManager = mod.createUndoManager;
|
|
16
|
+
export const getAnchorAndFocusCollabNodesForUserState = mod.getAnchorAndFocusCollabNodesForUserState;
|
|
16
17
|
export const initLocalState = mod.initLocalState;
|
|
17
18
|
export const setLocalStateFocus = mod.setLocalStateFocus;
|
|
18
19
|
export const syncCursorPositions = mod.syncCursorPositions;
|
package/LexicalYjs.node.mjs
CHANGED
|
@@ -11,6 +11,7 @@ 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
13
|
export const createUndoManager = mod.createUndoManager;
|
|
14
|
+
export const getAnchorAndFocusCollabNodesForUserState = mod.getAnchorAndFocusCollabNodesForUserState;
|
|
14
15
|
export const initLocalState = mod.initLocalState;
|
|
15
16
|
export const setLocalStateFocus = mod.setLocalStateFocus;
|
|
16
17
|
export const syncCursorPositions = mod.syncCursorPositions;
|
package/LexicalYjs.prod.js
CHANGED
|
@@ -6,47 +6,48 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
'use strict';var
|
|
10
|
-
A=C&&C.__esModule&&Object.prototype.hasOwnProperty.call(C,"default")?C["default"]:C;class E{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){let a=
|
|
9
|
+
'use strict';var p=require("lexical"),v=require("yjs"),x=require("@lexical/offset"),z=require("@lexical/selection"),A;function C(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
|
|
10
|
+
A=C&&C.__esModule&&Object.prototype.hasOwnProperty.call(C,"default")?C["default"]:C;class E{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){let a=p.$getNodeByKey(this._key);return p.$isLineBreakNode(a)?a:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(a){a.collabNodeMap.delete(this._key)}}
|
|
11
11
|
function F(a,b){b=new E(a,b);return a._collabNode=b}
|
|
12
|
-
class G{constructor(a,b,c,d){this._key="";this._map=a;this._parent=c;this._text=b;this._type=d;this._normalized=!1}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return
|
|
13
|
-
a=this.getOffset()+1+a;0!==b&&d.delete(a,b);""!==c&&d.insert(a,c)}syncPropertiesAndTextFromLexical(a,b,c){var d=this.getPrevNode(c);c=b.__text;H(a,this._map,d,b);if(null!==d&&(a=d.__text,a!==c)){d=b.__key;b=a;var e=
|
|
12
|
+
class G{constructor(a,b,c,d){this._key="";this._map=a;this._parent=c;this._text=b;this._type=d;this._normalized=!1}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return p.$isTextNode(a)?a:null}getNode(){let a=p.$getNodeByKey(this._key);return p.$isTextNode(a)?a: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(a,b,c){let d=this._parent._xmlText;
|
|
13
|
+
a=this.getOffset()+1+a;0!==b&&d.delete(a,b);""!==c&&d.insert(a,c)}syncPropertiesAndTextFromLexical(a,b,c){var d=this.getPrevNode(c);c=b.__text;H(a,this._map,d,b);if(null!==d&&(a=d.__text,a!==c)){d=b.__key;b=a;var e=p.$getSelection();a=c.length;p.$isRangeSelection(e)&&e.isCollapsed()&&(e=e.anchor,e.key===d&&(a=e.offset));d=b.length;let f=c.length,h=e=0;for(;e<d&&e<f&&b[e]===c[e]&&e<a;)e++;for(;h+e<d&&h+e<f&&b[d-h-1]===c[f-h-1];)h++;for(;h+e<d&&h+e<f&&b[e]===c[e];)e++;b=e;a=c.slice(e,f-h);d=d-e-h;this.spliceText(b,
|
|
14
14
|
d,a);this._text=c}}syncPropertiesAndTextFromYjs(a,b){let c=this.getNode();null===c&&A(84);I(a,this._map,c,b);a=this._text;c.__text!==a&&(c.getWritable().__text=a)}destroy(a){a.collabNodeMap.delete(this._key)}}function J(a,b,c,d){b=new G(a,b,c,d);return a._collabNode=b}let aa=new Set(["__key","__parent","__next","__prev"]),ba=new Set(["__first","__last","__size"]),ca=new Set(["__cachedText"]),da=new Set(["__text"]);
|
|
15
|
-
function K(a,b,c){if(aa.has(a))return!0;if(
|
|
16
|
-
function M(a,b,c){let d=b.__type;if(
|
|
15
|
+
function K(a,b,c){if(aa.has(a))return!0;if(p.$isTextNode(b)){if(da.has(a))return!0}else if(p.$isElementNode(b)&&(ba.has(a)||p.$isRootNode(b)&&ca.has(a)))return!0;b=c.excludedProperties.get(b.constructor);return null!=b&&b.has(a)}function L(a){a=p.$getNodeByKey(a);null===a&&A(85);return a}
|
|
16
|
+
function M(a,b,c){let d=b.__type;if(p.$isElementNode(b)){var e=new v.XmlText;e=N(e,c,d);e.syncPropertiesFromLexical(a,b,null);e.syncChildrenFromLexical(a,b,null,null,null)}else p.$isTextNode(b)?(e=new v.Map,e=J(e,b.__text,c,d),e.syncPropertiesAndTextFromLexical(a,b,null)):p.$isLineBreakNode(b)?(a=new v.Map,a.set("__type","linebreak"),e=F(a,c)):p.$isDecoratorNode(b)?(e=new v.XmlElement,e=O(e,c,d),e.syncPropertiesFromLexical(a,b,null)):A(86);e._key=b.__key;return e}
|
|
17
17
|
function P(a,b,c){let d=b._collabNode;if(void 0===d){var e=a.editor._nodes;let f=b instanceof v.Map?b.get("__type"):b.getAttribute("__type");null==f&&A(87);void 0===e.get(f)&&A(88,f);e=b.parent;a=void 0===c&&null!==e?P(a,e):c||null;a instanceof Q||A(89);if(b instanceof v.XmlText)return N(b,a,f);if(b instanceof v.Map)return"linebreak"===f?F(b,a):J(b,"",a,f);if(b instanceof v.XmlElement)return O(b,a,f)}return d}
|
|
18
|
-
function I(a,b,c,d){d=null===d?b instanceof v.Map?Array.from(b.keys()):Object.keys(b.getAttributes()):Array.from(d);let e;for(let h=0;h<d.length;h++){let g=d[h];if(K(g,c,a))continue;var f=c[g];let
|
|
19
|
-
function H(a,b,c,d){var e=d.__type,f=a.nodeProperties;let h=f.get(e);void 0===h&&(h=Object.keys(d).filter(
|
|
20
|
-
function R(a,b,c,d){return a.slice(0,b)+d+a.slice(b+c)}function S(a,b,c){let d=0,e=0,f=a._children,h=f.length;for(;e<h;e++){a=f[e];let g=d,
|
|
21
|
-
function T(a){let b=a.anchor;a=a.focus;let c=!1;try{let d=b.getNode(),e=a.getNode();if(!d.isAttached()||!e.isAttached()||
|
|
18
|
+
function I(a,b,c,d){d=null===d?b instanceof v.Map?Array.from(b.keys()):Object.keys(b.getAttributes()):Array.from(d);let e;for(let h=0;h<d.length;h++){let g=d[h];if(K(g,c,a))continue;var f=c[g];let k=b instanceof v.Map?b.get(g):b.getAttribute(g);if(f!==k){if(k instanceof v.Doc){let l=a.docMap;f instanceof v.Doc&&l.delete(f.guid);f=p.createEditor();let t=k.guid;f._key=t;l.set(t,k);k=f}void 0===e&&(e=c.getWritable());e[g]=k}}}
|
|
19
|
+
function H(a,b,c,d){var e=d.__type,f=a.nodeProperties;let h=f.get(e);void 0===h&&(h=Object.keys(d).filter(k=>!K(k,d,a)),f.set(e,h));e=a.editor.constructor;for(f=0;f<h.length;f++){let k=h[f];var g=null===c?void 0:c[k];let l=d[k];if(g!==l){if(l instanceof e){let t=a.docMap,n;g instanceof e&&(g=g._key,n=t.get(g),t.delete(g));g=n||new v.Doc;let m=g.guid;l._key=m;t.set(m,g);l=g;a.editor.update(()=>{d.markDirty()})}b instanceof v.Map?b.set(k,l):b.setAttribute(k,l)}}}
|
|
20
|
+
function R(a,b,c,d){return a.slice(0,b)+d+a.slice(b+c)}function S(a,b,c){let d=0,e=0,f=a._children,h=f.length;for(;e<h;e++){a=f[e];let g=d,k=a.getSize();d+=k;if((c?d>=b:d>b)&&a instanceof G)return c=b-g-1,0>c&&(c=0),{length:d-b,node:a,nodeIndex:e,offset:c};if(d>b)return{length:0,node:a,nodeIndex:e,offset:g};if(e===h-1)return{length:0,node:null,nodeIndex:e+1,offset:g+1}}return{length:0,node:null,nodeIndex:0,offset:0}}
|
|
21
|
+
function T(a){let b=a.anchor;a=a.focus;let c=!1;try{let d=b.getNode(),e=a.getNode();if(!d.isAttached()||!e.isAttached()||p.$isTextNode(d)&&b.offset>d.getTextContentSize()||p.$isTextNode(e)&&a.offset>e.getTextContentSize())c=!0}catch(d){c=!0}return c}function ea(a,b){a.doc.transact(b,a)}
|
|
22
22
|
function U(a){var b=a.getParent();if(null!==b){let e=a.getWritable();b=b.getWritable();var c=a.getPreviousSibling();a=a.getNextSibling();if(null===c)if(null!==a){var d=a.getWritable();b.__first=a.__key;d.__prev=null}else b.__first=null;else{d=c.getWritable();if(null!==a){let f=a.getWritable();f.__prev=d.__key;d.__next=f.__key}else d.__next=null;e.__prev=null}null===a?null!==c?(a=c.getWritable(),b.__last=c.__key,a.__next=null):b.__last=null:(a=a.getWritable(),null!==c?(c=c.getWritable(),c.__next=a.__key,
|
|
23
|
-
a.__prev=c.__key):a.__prev=null,e.__next=null);b.__size--;e.__parent=null}}function V(a,b){if(a=b._nodeMap.get(a)){var c=a.__prev,d=null;c&&(d=
|
|
24
|
-
class W{constructor(a,b,c){this._key="";this._xmlElem=a;this._parent=b;this._type=c}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return
|
|
23
|
+
a.__prev=c.__key):a.__prev=null,e.__next=null);b.__size--;e.__parent=null}}function V(a,b){if(a=b._nodeMap.get(a)){var c=a.__prev,d=null;c&&(d=p.$getNodeByKey(c));null===d&&null!==a.__parent&&(d=p.$getNodeByKey(a.__parent));null===d?p.$getRoot().selectStart():null!==d&&d.isAttached()?d.selectEnd():V(d.__key,b)}else p.$getRoot().selectStart()}
|
|
24
|
+
class W{constructor(a,b,c){this._key="";this._xmlElem=a;this._parent=b;this._type=c}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return p.$isDecoratorNode(a)?a:null}getNode(){let a=p.$getNodeByKey(this._key);return p.$isDecoratorNode(a)?a:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(a,b,c){c=this.getPrevNode(c);H(a,this._xmlElem,c,b)}syncPropertiesFromYjs(a,
|
|
25
25
|
b){let c=this.getNode();null===c&&A(83);I(a,this._xmlElem,c,b)}destroy(a){a.collabNodeMap.delete(this._key)}}function O(a,b,c){b=new W(a,b,c);return a._collabNode=b}
|
|
26
|
-
class Q{constructor(a,b,c){this._key="";this._children=[];this._xmlText=a;this._type=c;this._parent=b}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return
|
|
27
|
-
b){let c=this.getNode();null===c&&A(91);I(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){let c=this._children,d=0;for(let
|
|
28
|
-
g.length&&(h instanceof G?h._text+=g:this._xmlText.delete(
|
|
29
|
-
d.length;var f=this._children;let h=f.length,g=a.collabNodeMap,
|
|
30
|
-
|
|
31
|
-
null);m.collabNodeMap.set(B.__key,
|
|
32
|
-
b,c,d,e,f){b=this._children[b];c=L(c);b instanceof Q&&
|
|
33
|
-
g&&b<=
|
|
26
|
+
class Q{constructor(a,b,c){this._key="";this._children=[];this._xmlText=a;this._type=c;this._parent=b}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return p.$isElementNode(a)?a:null}getNode(){let a=p.$getNodeByKey(this._key);return p.$isElementNode(a)?a:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){let a=this._parent;null===a&&A(90);return a.getChildOffset(this)}syncPropertiesFromYjs(a,
|
|
27
|
+
b){let c=this.getNode();null===c&&A(91);I(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){let c=this._children,d=0;for(let k=0;k<b.length;k++){var e=b[k],f=e.insert,h=e.delete;if(null!=e.retain)d+=e.retain;else if("number"===typeof h)for(e=h;0<e;){let {node:l,nodeIndex:t,offset:n,length:m}=S(this,d,!1);if(l instanceof Q||l instanceof E||l instanceof W)c.splice(t,1),--e;else if(l instanceof G){f=Math.min(e,m);h=0!==t?c[t-1]:null;var g=l.getSize();0===n&&m===g?(c.splice(t,1),g=R(l._text,n,f-1,""),0<
|
|
28
|
+
g.length&&(h instanceof G?h._text+=g:this._xmlText.delete(n,g.length))):l._text=R(l._text,n,f,"");e-=f}else break}else if(null!=f)if("string"===typeof f){let {node:l,offset:t}=S(this,d,!0);l instanceof G?l._text=R(l._text,t,0,f):this._xmlText.delete(t,f.length);d+=f.length}else({nodeIndex:e}=S(this,d,!1)),f=P(a,f,this),c.splice(e,0,f),d+=1;else throw Error("Unexpected delta format");}}syncChildrenFromYjs(a){var b=this.getNode();null===b&&A(92);var c=b.__key;let d=x.$createChildrenArray(b,null),e=
|
|
29
|
+
d.length;var f=this._children;let h=f.length,g=a.collabNodeMap,k=new Set,l;let t=0;var n=null;h!==e&&b.getWritable();for(let y=0;y<h;y++){var m=d[t],r=f[y];var u=r.getNode();var q=r._key;if(null!==u&&m===q)n=p.$isTextNode(u),k.add(m),n&&(r._key=m,r instanceof Q?(n=r._xmlText,r.syncPropertiesFromYjs(a,null),r.applyChildrenYjsDelta(a,n.toDelta()),r.syncChildrenFromYjs(a)):r instanceof G?r.syncPropertiesAndTextFromYjs(a,null):r instanceof W?r.syncPropertiesFromYjs(a,null):r instanceof E||A(93)),n=u,
|
|
30
|
+
t++;else{if(void 0===l)for(l=new Set,q=0;q<h;q++){var w=f[q]._key;""!==w&&l.add(w)}if(null!==u&&void 0!==m&&!l.has(m)){r=L(m);U(r);y--;t++;continue}u=b.getWritable();m=a;q=r;w=c;var B=q.getType();let D=m.editor._nodes.get(B);void 0===D&&A(88,B);B=new D.klass;B.__parent=w;q._key=B.__key;q instanceof Q?(w=q._xmlText,q.syncPropertiesFromYjs(m,null),q.applyChildrenYjsDelta(m,w.toDelta()),q.syncChildrenFromYjs(m)):q instanceof G?q.syncPropertiesAndTextFromYjs(m,null):q instanceof W&&q.syncPropertiesFromYjs(m,
|
|
31
|
+
null);m.collabNodeMap.set(B.__key,q);m=B;q=m.__key;g.set(q,r);null===n?(n=u.getFirstChild(),u.__first=q,null!==n&&(n=n.getWritable(),n.__prev=q,m.__next=n.__key)):(r=n.getWritable(),w=n.getNextSibling(),r.__next=q,m.__prev=n.__key,null!==w&&(n=w.getWritable(),n.__prev=q,m.__next=n.__key));y===h-1&&(u.__last=q);u.__size++;n=m}}for(b=0;b<e;b++)f=d[b],k.has(f)||(c=L(f),f=a.collabNodeMap.get(f),void 0!==f&&f.destroy(a),U(c))}syncPropertiesFromLexical(a,b,c){H(a,this._xmlText,this.getPrevNode(c),b)}_syncChildFromLexical(a,
|
|
32
|
+
b,c,d,e,f){b=this._children[b];c=L(c);b instanceof Q&&p.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof G&&p.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof W&&p.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var f=this.getPrevNode(c);let h=null===f?[]:x.$createChildrenArray(f,c);f=x.$createChildrenArray(b,null);let g=h.length-1,k=f.length-1,l=a.collabNodeMap,t,n,m=0;for(b=0;m<=
|
|
33
|
+
g&&b<=k;){var r=h[m];let q=f[b];if(r===q)this._syncChildFromLexical(a,b,q,c,d,e),m++,b++;else{void 0===t&&(t=new Set(h));void 0===n&&(n=new Set(f));var u=n.has(r);r=t.has(q);u?(u=L(q),u=M(a,u,this),l.set(q,u),r?(this.splice(a,b,1,u),m++):this.splice(a,b,0,u),b++):(this.splice(a,b,1),m++)}}c=m>g;d=b>k;if(c&&!d)for(;b<=k;++b)c=f[b],d=L(c),d=M(a,d,this),this.append(d),l.set(c,d);else if(d&&!c)for(f=this._children.length-1;f>=b;f--)this.splice(a,f,1)}append(a){let b=this._xmlText;var c=this._children;
|
|
34
34
|
c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof Q)b.insertEmbed(c,a._xmlText);else if(a instanceof G){let d=a._map;null===d.parent&&b.insertEmbed(c,d);b.insert(c+1,a._text)}else a instanceof E?b.insertEmbed(c,a._map):a instanceof W&&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
|
|
35
35
|
Q?g.insertEmbed(h,d._xmlText):d instanceof G?(f=d._map,null===f.parent&&g.insertEmbed(h,f),g.insert(h+1,d._text)):d instanceof E?g.insertEmbed(h,d._map):d instanceof W&&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);
|
|
36
36
|
b.delete(this._key)}}function N(a,b,c){b=new Q(a,b,c);return a._collabNode=b}
|
|
37
|
-
function X(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 G){d=c._parent._xmlText;a=c.getOffset();if(-1===a)return null;b=a+1+b}else if(c instanceof Q&&"element"===a.type){var e=a.getNode();
|
|
38
|
-
function Y(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!v.compareRelativePositions(a,b))return!0;return!1}function
|
|
39
|
-
function
|
|
40
|
-
function
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
u.
|
|
44
|
-
if(null
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
function X(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 G){d=c._parent._xmlText;a=c.getOffset();if(-1===a)return null;b=a+1+b}else if(c instanceof Q&&"element"===a.type){var e=a.getNode();p.$isElementNode(e)||A(184);c=a=0;for(e=e.getFirstChild();null!==e&&c++<b;)p.$isTextNode(e)?a+=e.getTextContentSize()+1:a++,e=e.getNextSibling();b=a}return v.createRelativePositionFromTypeIndex(d,b)}
|
|
38
|
+
function Y(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!v.compareRelativePositions(a,b))return!0;return!1}function la(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])}}
|
|
39
|
+
function Z(a,b){let {anchorPos:c,focusPos:d}=b;b=null;let e=0,f=null,h=0;if(null!==c&&null!==d){let g=v.createAbsolutePositionFromRelativePosition(c,a.doc);a=v.createAbsolutePositionFromRelativePosition(d,a.doc);null!==g&&null!==a&&([b,e]=ma(g.type,g.index),[f,h]=ma(a.type,a.index))}return{anchorCollabNode:b,anchorOffset:e,focusCollabNode:f,focusOffset:h}}
|
|
40
|
+
function na(a,b){b=b.awareness.getLocalState();if(null!==b){var {anchorCollabNode:c,anchorOffset:d,focusCollabNode:e,focusOffset:f}=Z(a,b);if(null!==c&&null!==e){a=c.getKey();b=e.getKey();let h=p.$getSelection();p.$isRangeSelection(h)&&(oa(h.anchor,a,d),oa(h.focus,b,f))}}}
|
|
41
|
+
function oa(a,b,c){if(a.key!==b||a.offset!==c){let d=p.$getNodeByKey(b);if(null!==d&&!p.$isElementNode(d)&&!p.$isTextNode(d)){let e=d.getParentOrThrow();b=e.getKey();c=d.getIndexWithinParent();d=e}a.set(b,c,p.$isElementNode(d)?"element":"text")}}function ma(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof Q){let {node:c,offset:d}=S(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
|
|
42
|
+
function pa(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,fa]=c[h];if(D!==d){f.add(D);let {name:ra,color:sa,focusing:ta}=fa;var g=null,k=b.get(D);void 0===k&&(k={color:sa,name:ra,selection:null},b.set(D,k));if(ta){let {anchorCollabNode:ha,anchorOffset:ia,focusCollabNode:ja,focusOffset:ka}=Z(a,fa);if(null!==ha&&null!==ja){var l=ha.getKey(),t=ja.getKey();g=k.selection;if(null===g){g=k;var n=
|
|
43
|
+
ia,m=ka,r=g.color,u=document.createElement("span");u.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${r};z-index:10;`;var q=document.createElement("span");q.textContent=g.name;q.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${r};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`;u.appendChild(q);g={anchor:{key:l,offset:n},caret:u,color:r,focus:{key:t,offset:m},name:q,selections:[]}}else n=
|
|
44
|
+
g.anchor,m=g.focus,n.key=l,n.offset=ia,m.key=t,m.offset=ka}}a:if(l=a,n=k,u=g,r=e,m=l.editor,g=m.getRootElement(),k=l.cursorsContainer,null!==k&&null!==g&&(g=k.offsetParent,null!==g))if(g=g.getBoundingClientRect(),t=n.selection,null===u)null!==t&&(n.selection=null,la(l,t));else{n.selection=u;n=u.caret;t=u.color;l=u.selections;q=u.anchor;u=u.focus;var w=q.key,B=u.key,y=r.get(w);r=r.get(B);if(null!=y&&null!=r){if(y===r&&p.$isLineBreakNode(y))r=[m.getElementByKey(w).getBoundingClientRect()];else{r=z.createDOMRange(m,
|
|
45
|
+
y,q.offset,r,u.offset);if(null===r)break a;r=z.createRectsFromDOMRange(m,r)}u=l.length;m=r.length;for(q=0;q<m;q++)y=r[q],w=l[q],void 0===w&&(w=document.createElement("span"),l[q]=w,B=document.createElement("span"),w.appendChild(B),k.appendChild(w)),y=`position:absolute;top:${y.top-g.top}px;left:${y.left-g.left}px;height:${y.height}px;width:${y.width}px;pointer-events:none;z-index:5;`,w.style.cssText=y,w.firstChild.style.cssText=`${y}left:0;top:0;background-color:${t};opacity:0.3;`,q===m-1&&n.parentNode!==
|
|
46
|
+
w&&w.appendChild(n);for(g=u-1;g>=m;g--)k.removeChild(l[g]),l.pop()}}}}c=Array.from(b.keys());for(d=0;d<c.length;d++)e=c[d],f.has(e)||(h=b.get(e),void 0!==h&&(h=h.selection,null!==h&&la(a,h),b.delete(e)))}
|
|
47
|
+
function qa(a,b,c,d){b=b.awareness;let e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:h,name:g,color:k,focusing:l,awarenessData:t}=e,n=null,m=null;if(null!==d&&(null===f||d.is(c))||null!==c)p.$isRangeSelection(d)&&(n=X(d.anchor,a),m=X(d.focus,a)),(Y(f,n)||Y(h,m))&&b.setLocalState({...e,anchorPos:n,awarenessData:t,color:k,focusPos:m,focusing:l,name:g})}}let ua=p.createCommand("CONNECTED_COMMAND"),va=p.createCommand("TOGGLE_CONNECT_COMMAND");exports.CONNECTED_COMMAND=ua;
|
|
48
|
+
exports.TOGGLE_CONNECT_COMMAND=va;exports.createBinding=function(a,b,c,d,e,f){void 0!==d&&null!==d||A(81);b=d.get("root",v.XmlText);b=N(b,null,"root");b._key="root";return{clientID:d.clientID,collabNodeMap:new Map,cursors:new Map,cursorsContainer:null,doc:d,docMap:e,editor:a,excludedProperties:f||new Map,id:c,nodeProperties:new Map,root:b}};exports.createUndoManager=function(a,b){return new v.UndoManager(b,{trackedOrigins:new Set([a,null])})};exports.getAnchorAndFocusCollabNodesForUserState=Z;
|
|
48
49
|
exports.initLocalState=function(a,b,c,d,e){a.awareness.setLocalState({anchorPos:null,awarenessData:e,color:c,focusPos:null,focusing:d,name:b})};exports.setLocalStateFocus=function(a,b,c,d,e){({awareness:a}=a);let f=a.getLocalState();null===f&&(f={anchorPos:null,awarenessData:e,color:c,focusPos:null,focusing:d,name:b});f.focusing=d;a.setLocalState(f)};exports.syncCursorPositions=pa;
|
|
49
|
-
exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,h,g){
|
|
50
|
-
u instanceof G&&"string"===typeof
|
|
51
|
-
exports.syncYjsChangesToLexical=function(a,b,c,d){let e=a.editor,f=e._editorState;c.forEach(h=>h.delta);e.update(()=>{for(var h=0;h<c.length;h++){var g=a,
|
|
52
|
-
|
|
50
|
+
exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,h,g){ea(a,()=>{d.read(()=>{if(g.has("collaboration")||g.has("historic")){if(0<h.size){var k=Array.from(h),l=a.collabNodeMap,t=[];for(let u=0;u<k.length;u++){var n=k[u],m=p.$getNodeByKey(n),r=l.get(n);if(r instanceof G)if(p.$isTextNode(m))t.push([r,m.__text]);else{m=r.getOffset();if(-1===m)continue;let q=r._parent;r._normalized=!0;q._xmlText.delete(m,1);l.delete(n);n=q._children;r=n.indexOf(r);n.splice(r,1)}}for(k=0;k<t.length;k++){let [u,q]=t[k];
|
|
51
|
+
u instanceof G&&"string"===typeof q&&(u._text=q)}}}else e.has("root")&&(t=c._nodeMap,k=p.$getRoot(),l=a.root,l.syncPropertiesFromLexical(a,k,t),l.syncChildrenFromLexical(a,k,t,e,f)),t=p.$getSelection(),qa(a,b,c._selection,t)})})};
|
|
52
|
+
exports.syncYjsChangesToLexical=function(a,b,c,d){let e=a.editor,f=e._editorState;c.forEach(h=>h.delta);e.update(()=>{for(var h=0;h<c.length;h++){var g=a,k=c[h],{target:l}=k;l=P(g,l);if(l instanceof Q&&k instanceof v.YTextEvent){let {keysChanged:t,childListChanged:n,delta:m}=k;0<t.size&&l.syncPropertiesFromYjs(g,t);n&&(l.applyChildrenYjsDelta(g,m),l.syncChildrenFromYjs(g))}else l instanceof G&&k instanceof v.YMapEvent?({keysChanged:k}=k,0<k.size&&l.syncPropertiesAndTextFromYjs(g,k)):l instanceof W&&
|
|
53
|
+
k instanceof v.YXmlEvent?({attributesChanged:k}=k,0<k.size&&l.syncPropertiesFromYjs(g,k)):A(82)}g=p.$getSelection();p.$isRangeSelection(g)&&(T(g)?(h=f._selection,p.$isRangeSelection(h)&&(na(a,b),T(g)&&V(g.anchor.key,f)),qa(a,b,h,p.$getSelection())):na(a,b))},{onUpdate:()=>{pa(a,b);e.update(()=>{0===p.$getRoot().getChildrenSize()&&p.$getRoot().append(p.$createParagraphNode())})},skipTransforms:!0,tag:d?"historic":"collaboration"})}
|
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,$getRoot as i,$isElementNode as r,$isRootNode as c,$isDecoratorNode as a,$createParagraphNode as f,createCommand as u}from"lexical";import{XmlText as d,Map as _,XmlElement as h,Doc as p,createAbsolutePositionFromRelativePosition as g,createRelativePositionFromTypeIndex as y,compareRelativePositions as x,YTextEvent as m,YMapEvent as k,YXmlEvent as b,UndoManager as v}from"yjs";import{$createChildrenArray as P}from"@lexical/offset";import{createDOMRange as C,createRectsFromDOMRange as w}from"@lexical/selection";function T(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var N=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&&N(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(r(t)&&(L.has(e)||c(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&&N(85),n}function D(e,o,s){const l=o.__type;let i;if(r(o)){i=V(new d,s,l),i.syncPropertiesFromLexical(e,o,null),i.syncChildrenFromLexical(e,o,null,null,null)}else if(n(o)){i=M(new _,o.__text,s,l),i.syncPropertiesAndTextFromLexical(e,o,null)}else if(t(o)){const e=new _;e.set("__type","linebreak"),i=F(e,s)}else if(a(o)){i=J(new h,s,l),i.syncPropertiesFromLexical(e,o,null)}else N(86);return i._key=o.__key,i}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 _?e.get("__type"):e.getAttribute("__type");return null==t&&N(87),t}(t);void 0===o.get(s)&&N(88,s);const l=t.parent,i=void 0===n&&null!==l?W(e,l):n||null;if(i instanceof Q||N(89),t instanceof d)return V(t,i,s);if(t instanceof _)return"linebreak"===s?F(t,i):M(t,"",i,s);if(t instanceof h)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&&N(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 _?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 a=t instanceof _?t.get(r):t.getAttribute(r);if(c!==a){if(a instanceof p){const t=e.docMap;c instanceof p&&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 $(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 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 p,l=s.guid;a._key=l,t.set(l,s),a=s,e.editor.update((()=>{o.markDirty()}))}t instanceof _?t.set(l,a):t.setAttribute(l,a)}}}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(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}}function q(t,n){const o=n._nodeMap.get(t);if(!o)return void i().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():q(l.__key,n):i().selectStart()}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 a(t)?t:null}getNode(){const t=e(this._key);return a(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&&N(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 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&&N(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&N(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();if(0===l&&i===c){n.splice(s,1);const e=R(t._text,l,o-1,"");e.length>0&&(r instanceof E?r._text+=e:this._xmlText.delete(l,e.length))}else 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&&N(92);const o=t.__key,s=P(t,null),l=s.length,i=this._children,r=i.length,c=e.collabNodeMap,a=new Set;let f,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(a.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||N(93);_=g,d++}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!==g&&void 0!==h&&!f.has(h)){G(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(!a.has(n)){const t=Y(n),o=e.collabNodeMap.get(n);void 0!==o&&o.destroy(e),G(t)}}}syncPropertiesFromLexical(e,t,n){$(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(e,t,o,s,l,i){const c=this._children[t],f=Y(o);c instanceof Q&&r(f)?(c.syncPropertiesFromLexical(e,f,s),c.syncChildrenFromLexical(e,f,s,l,i)):c instanceof E&&n(f)?c.syncPropertiesAndTextFromLexical(e,f,s):c instanceof H&&a(f)&&c.syncPropertiesFromLexical(e,f,s)}syncChildrenFromLexical(e,t,n,o,s){const l=this.getPrevNode(n),i=null===l?[]:P(l,n),r=P(t,null),c=i.length-1,a=r.length-1,f=e.collabNodeMap;let u,d,_=0,h=0;for(;_<=c&&h<=a;){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);f.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>a;if(p&&!g)for(;h<=a;++h){const t=r[h],n=D(e,Y(t),this);this.append(n),f.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&&N(94),void this.append(o);const i=l.getOffset();-1===i&&N(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&&N(81);const i=V(o.get("root",d),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();r(t)||N(184);let o=0,l=0,i=t.getFirstChild();for(;null!==i&&l++<s;)n(i)?o+=i.getTextContentSize()+1:o++,i=i.getNextSibling();s=o}return y(l,s)}function ee(e,t){return g(e,t.doc)}function te(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!x(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 a=c.getBoundingClientRect(),f=n.selection;if(null===o)return null===f?void 0:(n.selection=null,void oe(e,f));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-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===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]=ae(t.type,t.index),[i,r]=ae(n.type,n.index);if(null!==e&&null!==i){const t=e.getKey(),n=i.getKey(),c=o();if(!s(c))return;const a=c.anchor,f=c.focus;ce(a,t,l),ce(f,n,r)}}}}function ce(t,o,s){if(t.key!==o||t.offset!==s){let l=e(o);if(null!==l&&!r(l)&&!n(l)){const e=l.getParentOrThrow();o=e.getKey(),s=l.getIndexWithinParent(),l=e}t.set(o,s,r(l)?"element":"text")}}function ae(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 fe(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,a]=r;if(c!==o){i.add(c);const{anchorPos:t,focusPos:n,name:o,color:r,focusing:f}=a;let u=null,d=s.get(c);if(void 0===d&&(d=ne(o,r),s.set(c,d)),null!==t&&null!==n&&f){const o=ee(t,e),s=ee(n,e);if(null!==o&&null!==s){const[e,t]=ae(o.type,o.index),[n,l]=ae(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:a,color:f,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({...i,anchorPos:_,awarenessData:d,color:f,focusPos:h,focusing:u,name:a}))}function de(e,t){const{target:n}=t,o=W(e,n);if(o instanceof Q&&t instanceof m){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 k){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof H&&t instanceof b){const{attributesChanged:n}=t;n.size>0&&o.syncPropertiesFromYjs(e,n)}else N(82)}function _e(e,t,n,l){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];de(e,o)}const l=o();if(s(l))if(U(l)){const n=c._selection;if(s(n)&&(re(e,t),U(l))){q(l.anchor.key,c)}ue(e,t,n,o())}else re(e,t)}),{onUpdate:()=>{fe(e,t),r.update((()=>{0===i().getChildrenSize()&&i().append(f())}))},skipTransforms:!0,tag:l?"historic":"collaboration"})}function he(t,s,l,r,c,a,f,u){!function(e,t){e.doc.transact(t,e)}(t,(()=>{r.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(c.has("root")){const e=l._nodeMap,n=i(),o=t.root;o.syncPropertiesFromLexical(t,n,e),o.syncChildrenFromLexical(t,n,e,c,a)}const r=o(),d=l._selection;ue(t,s,d,r)}))}))}const pe=u("CONNECTED_COMMAND"),ge=u("TOGGLE_CONNECT_COMMAND");function ye(e,t){return new v(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,fe as syncCursorPositions,he as syncLexicalUpdateToYjs,_e as syncYjsChangesToLexical};
|
|
9
|
+
import{$getNodeByKey as e,$isLineBreakNode as t,$isTextNode as n,$getSelection as o,$isRangeSelection as s,$isElementNode as l,$isDecoratorNode as i,createEditor as r,$getRoot as c,$isRootNode as a,$createParagraphNode as f,createCommand as u}from"lexical";import{XmlText as d,Map as _,XmlElement as h,Doc as p,createAbsolutePositionFromRelativePosition as g,createRelativePositionFromTypeIndex as y,compareRelativePositions as x,YTextEvent as m,YMapEvent as b,YXmlEvent as k,UndoManager as v}from"yjs";import{$createChildrenArray as C}from"@lexical/offset";import{createDOMRange as N,createRectsFromDOMRange as P}from"@lexical/selection";function w(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var T=w((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 O{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 E(e,t,n,o){const s=new O(e,t,n,o);return e._collabNode=s,s}const M=new Set(["__key","__parent","__next","__prev"]),z=new Set(["__first","__last","__size"]),L=new Set(["__cachedText"]),j=new Set(["__text"]);function A(e,t,o){if(M.has(e))return!0;if(n(t)){if(j.has(e))return!0}else if(l(t)&&(z.has(e)||a(t)&&L.has(e)))return!0;const s=t.constructor,i=o.excludedProperties.get(s);return null!=i&&i.has(e)}function Y(t){const n=e(t);return null===n&&T(85),n}function D(e,o,s){const r=o.__type;let c;if(l(o)){c=V(new d,s,r),c.syncPropertiesFromLexical(e,o,null),c.syncChildrenFromLexical(e,o,null,null,null)}else if(n(o)){c=E(new _,o.__text,s,r),c.syncPropertiesAndTextFromLexical(e,o,null)}else if(t(o)){const e=new _;e.set("__type","linebreak"),c=F(e,s)}else if(i(o)){c=J(new h,s,r),c.syncPropertiesFromLexical(e,o,null)}else T(86);return c._key=o.__key,c}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 _?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 d)return V(t,i,s);if(t instanceof _)return"linebreak"===s?F(t,i):E(t,"",i,s);if(t instanceof h)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 O?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 _?Array.from(t.keys()):Object.keys(t.getAttributes()):Array.from(o);let l;for(let o=0;o<s.length;o++){const i=s[o];if(A(i,n,e))continue;const c=n[i];let a=t instanceof _?t.get(i):t.getAttribute(i);if(c!==a){if(a instanceof p){const t=e.docMap;c instanceof p&&t.delete(c.guid);const n=r(),o=a.guid;n._key=o,t.set(o,a),a=n}void 0===l&&(l=n.getWritable()),l[i]=a}}}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 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 p,l=s.guid;a._key=l,t.set(l,s),a=s,e.editor.update((()=>{o.markDirty()}))}t instanceof _?t.set(l,a):t.setAttribute(l,a)}}}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 O){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(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}}function q(t,n){const o=n._nodeMap.get(t);if(!o)return void c().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():q(l.__key,n):c().selectStart()}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 i(t)?t:null}getNode(){const t=e(this._key);return i(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 l(t)?t:null}getNode(){const t=e(this._key);return l(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 O))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=R(t._text,l,o-1,"");e.length>0&&(r instanceof O?r._text+=e:this._xmlText.delete(l,e.length))}else 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 O?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=C(t,null),l=s.length,i=this._children,r=i.length,c=e.collabNodeMap,a=new Set;let f,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(a.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 O?p.syncPropertiesAndTextFromYjs(e,null):p instanceof H?p.syncPropertiesFromYjs(e,null):p instanceof S||T(93);_=g,d++}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!==g&&void 0!==h&&!f.has(h)){G(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(!a.has(n)){const t=Y(n),o=e.collabNodeMap.get(n);void 0!==o&&o.destroy(e),G(t)}}}syncPropertiesFromLexical(e,t,n){$(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(e,t,o,s,r,c){const a=this._children[t],f=Y(o);a instanceof Q&&l(f)?(a.syncPropertiesFromLexical(e,f,s),a.syncChildrenFromLexical(e,f,s,r,c)):a instanceof O&&n(f)?a.syncPropertiesAndTextFromLexical(e,f,s):a instanceof H&&i(f)&&a.syncPropertiesFromLexical(e,f,s)}syncChildrenFromLexical(e,t,n,o,s){const l=this.getPrevNode(n),i=null===l?[]:C(l,n),r=C(t,null),c=i.length-1,a=r.length-1,f=e.collabNodeMap;let u,d,_=0,h=0;for(;_<=c&&h<=a;){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);f.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>a;if(p&&!g)for(;h<=a;++h){const t=r[h],n=D(e,Y(t),this);this.append(n),f.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 O){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 O){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",d),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,i=o.getSharedType();if(o instanceof O){i=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();l(t)||T(184);let o=0,i=0,r=t.getFirstChild();for(;null!==r&&i++<s;)n(r)?o+=r.getTextContentSize()+1:o++,r=r.getNextSibling();s=o}return y(i,s)}function ee(e,t){return g(e,t.doc)}function te(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!x(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 a=c.getBoundingClientRect(),f=n.selection;if(null===o)return null===f?void 0:(n.selection=null,void oe(e,f));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 b;if(x===m&&t(x)){b=[l.getElementByKey(g).getBoundingClientRect()]}else{const e=N(l,x,h.offset,m,p.offset);if(null===e)return;b=P(l,e)}const k=_.length,v=b.length;for(let e=0;e<v;e++){const t=b[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-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===v-1&&u.parentNode!==n&&n.appendChild(u)}for(let e=k-1;e>=v;e--){const t=_[e];r.removeChild(t),_.pop()}}function re(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,l=0,i=null,r=0;if(null!==n&&null!==o){const t=ee(n,e),c=ee(o,e);null!==t&&null!==c&&([s,l]=fe(t.type,t.index),[i,r]=fe(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:l,focusCollabNode:i,focusOffset:r}}function ce(e,t){const n=t.awareness.getLocalState();if(null===n)return;const{anchorCollabNode:l,anchorOffset:i,focusCollabNode:r,focusOffset:c}=re(e,n);if(null!==l&&null!==r){const e=l.getKey(),t=r.getKey(),n=o();if(!s(n))return;ae(n.anchor,e,i),ae(n.focus,t,c)}}function ae(t,o,s){if(t.key!==o||t.offset!==s){let i=e(o);if(null!==i&&!l(i)&&!n(i)){const e=i.getParentOrThrow();o=e.getKey(),s=i.getIndexWithinParent(),i=e}t.set(o,s,l(i)?"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 ue(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,a]=r;if(c!==o){i.add(c);const{name:t,color:n,focusing:o}=a;let r=null,f=s.get(c);if(void 0===f&&(f=ne(t,n),s.set(c,f)),o){const{anchorCollabNode:t,anchorOffset:n,focusCollabNode:o,focusOffset:s}=re(e,a);if(null!==t&&null!==o){const e=t.getKey(),l=o.getKey();if(r=f.selection,null===r)r=le(f,e,n,l,s);else{const t=r.anchor,o=r.focus;t.key=e,t.offset=n,o.key=l,o.offset=s}}}ie(e,f,r,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 de(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 _=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({...i,anchorPos:_,awarenessData:d,color:f,focusPos:h,focusing:u,name:a}))}function _e(e,t){const{target:n}=t,o=W(e,n);if(o instanceof Q&&t instanceof m){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 O&&t instanceof b){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof H&&t instanceof k){const{attributesChanged:n}=t;n.size>0&&o.syncPropertiesFromYjs(e,n)}else T(82)}function he(e,t,n,l){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];_e(e,o)}const l=o();if(s(l))if(U(l)){const n=r._selection;if(s(n)&&(ce(e,t),U(l))){q(l.anchor.key,r)}de(e,t,n,o())}else ce(e,t)}),{onUpdate:()=>{ue(e,t),i.update((()=>{0===c().getChildrenSize()&&c().append(f())}))},skipTransforms:!0,tag:l?"historic":"collaboration"})}function pe(t,s,l,i,r,a,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 O)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 O&&"string"==typeof n&&(t._text=n)}}(t,f));if(r.has("root")){const e=l._nodeMap,n=c(),o=t.root;o.syncPropertiesFromLexical(t,n,e),o.syncChildrenFromLexical(t,n,e,r,a)}const i=o(),d=l._selection;de(t,s,d,i)}))}))}const ge=u("CONNECTED_COMMAND"),ye=u("TOGGLE_CONNECT_COMMAND");function xe(e,t){return new v(t,{trackedOrigins:new Set([e,null])})}function me(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})}function be(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{ge as CONNECTED_COMMAND,ye as TOGGLE_CONNECT_COMMAND,X as createBinding,xe as createUndoManager,re as getAnchorAndFocusCollabNodesForUserState,me as initLocalState,be as setLocalStateFocus,ue as syncCursorPositions,pe as syncLexicalUpdateToYjs,he as syncYjsChangesToLexical};
|
package/SyncCursors.d.ts
CHANGED
|
@@ -7,7 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { Binding } from './Bindings';
|
|
9
9
|
import type { BaseSelection, NodeKey } from 'lexical';
|
|
10
|
-
import { Provider } from '.';
|
|
10
|
+
import { Provider, UserState } from '.';
|
|
11
|
+
import { CollabDecoratorNode } from './CollabDecoratorNode';
|
|
12
|
+
import { CollabElementNode } from './CollabElementNode';
|
|
13
|
+
import { CollabLineBreakNode } from './CollabLineBreakNode';
|
|
14
|
+
import { CollabTextNode } from './CollabTextNode';
|
|
11
15
|
export type CursorSelection = {
|
|
12
16
|
anchor: {
|
|
13
17
|
key: NodeKey;
|
|
@@ -27,6 +31,14 @@ export type Cursor = {
|
|
|
27
31
|
name: string;
|
|
28
32
|
selection: null | CursorSelection;
|
|
29
33
|
};
|
|
34
|
+
type AnyCollabNode = CollabDecoratorNode | CollabElementNode | CollabTextNode | CollabLineBreakNode;
|
|
35
|
+
export declare function getAnchorAndFocusCollabNodesForUserState(binding: Binding, userState: UserState): {
|
|
36
|
+
anchorCollabNode: AnyCollabNode | null;
|
|
37
|
+
anchorOffset: number;
|
|
38
|
+
focusCollabNode: AnyCollabNode | null;
|
|
39
|
+
focusOffset: number;
|
|
40
|
+
};
|
|
30
41
|
export declare function $syncLocalCursorPosition(binding: Binding, provider: Provider): void;
|
|
31
42
|
export declare function syncCursorPositions(binding: Binding, provider: Provider): void;
|
|
32
43
|
export declare function syncLexicalSelectionToYjs(binding: Binding, provider: Provider, prevSelection: null | BaseSelection, nextSelection: null | BaseSelection): void;
|
|
44
|
+
export {};
|
package/index.d.ts
CHANGED
|
@@ -59,5 +59,5 @@ export { createBinding } from './Bindings';
|
|
|
59
59
|
export declare function createUndoManager(binding: Binding, root: XmlText): UndoManager;
|
|
60
60
|
export declare function initLocalState(provider: Provider, name: string, color: string, focusing: boolean, awarenessData: object): void;
|
|
61
61
|
export declare function setLocalStateFocus(provider: Provider, name: string, color: string, focusing: boolean, awarenessData: object): void;
|
|
62
|
-
export { syncCursorPositions } from './SyncCursors';
|
|
62
|
+
export { getAnchorAndFocusCollabNodesForUserState, syncCursorPositions, } from './SyncCursors';
|
|
63
63
|
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.
|
|
14
|
+
"version": "0.23.0",
|
|
15
15
|
"main": "LexicalYjs.js",
|
|
16
16
|
"types": "index.d.ts",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@lexical/offset": "0.
|
|
19
|
-
"@lexical/selection": "0.
|
|
20
|
-
"lexical": "0.
|
|
18
|
+
"@lexical/offset": "0.23.0",
|
|
19
|
+
"@lexical/selection": "0.23.0",
|
|
20
|
+
"lexical": "0.23.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"yjs": ">=13.5.22"
|