@lexical/yjs 0.1.14 → 0.1.17

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Dominic Gannaway
3
+ Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/LexicalYjs.dev.js CHANGED
@@ -6,8 +6,9 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
- var yjs = require('yjs');
10
9
  var lexical = require('lexical');
10
+ var yjs = require('yjs');
11
+ var offset = require('@lexical/offset');
11
12
 
12
13
  /**
13
14
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -662,10 +663,8 @@ function syncLexicalDecoratorArrayValueToYjs(binding, collabNode, internalArray,
662
663
 
663
664
  function syncLexicalDecoratorMapToYjs(binding, collabNode, decoratorMap, yjsMap) {
664
665
  const internalMap = decoratorMap._map;
665
- const keys = Array.from(internalMap.keys());
666
666
 
667
- for (let i = 0; i < keys.length; i++) {
668
- const key = keys[i];
667
+ for (const [key] of internalMap) {
669
668
  syncLexicalDecoratorMapKeyToYjs(binding, collabNode, internalMap, yjsMap, key);
670
669
  }
671
670
  }
@@ -1522,7 +1521,7 @@ function createCursorSelection(cursor, anchorKey, anchorOffset, focusKey, focusO
1522
1521
  caret.style.cssText = `position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:rgb(${color});z-index:10;`;
1523
1522
  const name = document.createElement('span');
1524
1523
  name.textContent = cursor.name;
1525
- name.style.cssText = `position:absolute;left:-2px;top:-16px;background-color:rgb(${color});color:#fff;line-height:12px;height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold`;
1524
+ name.style.cssText = `position:absolute;left:-2px;top:-16px;background-color:rgb(${color});color:#fff;line-height:12px;height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`;
1526
1525
  caret.appendChild(name);
1527
1526
  return {
1528
1527
  anchor: {
@@ -1855,368 +1854,6 @@ function syncLexicalSelectionToYjs(binding, provider, prevSelection, nextSelecti
1855
1854
  }
1856
1855
  }
1857
1856
 
1858
- /**
1859
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1860
- *
1861
- * This source code is licensed under the MIT license found in the
1862
- * LICENSE file in the root directory of this source tree.
1863
- *
1864
- *
1865
- */
1866
- class OffsetView {
1867
- constructor(offsetMap, firstNode, blockOffsetSize = 1) {
1868
- this._offsetMap = offsetMap;
1869
- this._firstNode = firstNode;
1870
- this._blockOffsetSize = blockOffsetSize;
1871
- }
1872
-
1873
- createSelectionFromOffsets(originalStart, originalEnd, diffOffsetView) {
1874
- const firstNode = this._firstNode;
1875
-
1876
- if (firstNode === null) {
1877
- return null;
1878
- }
1879
-
1880
- let start = originalStart;
1881
- let end = originalEnd;
1882
- let startOffsetNode = $searchForNodeWithOffset(firstNode, start, this._blockOffsetSize);
1883
- let endOffsetNode = $searchForNodeWithOffset(firstNode, end, this._blockOffsetSize);
1884
-
1885
- if (diffOffsetView !== undefined) {
1886
- start = $getAdjustedOffsetFromDiff(start, startOffsetNode, diffOffsetView, this, this._blockOffsetSize);
1887
- startOffsetNode = $searchForNodeWithOffset(firstNode, start, this._blockOffsetSize);
1888
- end = $getAdjustedOffsetFromDiff(end, endOffsetNode, diffOffsetView, this, this._blockOffsetSize);
1889
- endOffsetNode = $searchForNodeWithOffset(firstNode, end, this._blockOffsetSize);
1890
- }
1891
-
1892
- if (startOffsetNode === null || endOffsetNode === null) {
1893
- return null;
1894
- }
1895
-
1896
- let startKey = startOffsetNode.key;
1897
- let endKey = endOffsetNode.key;
1898
- const startNode = lexical.$getNodeByKey(startKey);
1899
- const endNode = lexical.$getNodeByKey(endKey);
1900
-
1901
- if (startNode === null || endNode === null) {
1902
- return null;
1903
- }
1904
-
1905
- let startOffset = 0;
1906
- let endOffset = 0;
1907
- let startType = 'element';
1908
- let endType = 'element';
1909
-
1910
- if (startOffsetNode.type === 'text') {
1911
- startOffset = start - startOffsetNode.start;
1912
- startType = 'text'; // If we are at the edge of a text node and we
1913
- // don't have a collapsed selection, then let's
1914
- // try and correct the offset node.
1915
-
1916
- const sibling = startNode.getNextSibling();
1917
-
1918
- if (start !== end && startOffset === startNode.getTextContentSize() && lexical.$isTextNode(sibling)) {
1919
- startOffset = 0;
1920
- startKey = sibling.__key;
1921
- }
1922
- } else if (startOffsetNode.type === 'inline') {
1923
- startKey = startNode.getParentOrThrow().getKey();
1924
- startOffset = end > startOffsetNode.start ? startOffsetNode.end : startOffsetNode.start;
1925
- }
1926
-
1927
- if (endOffsetNode.type === 'text') {
1928
- endOffset = end - endOffsetNode.start;
1929
- endType = 'text';
1930
- } else if (endOffsetNode.type === 'inline') {
1931
- endKey = endNode.getParentOrThrow().getKey();
1932
- endOffset = end > endOffsetNode.start ? endOffsetNode.end : endOffsetNode.start;
1933
- }
1934
-
1935
- const selection = lexical.$createRangeSelection();
1936
-
1937
- if (selection === null) {
1938
- return null;
1939
- }
1940
-
1941
- selection.anchor.set(startKey, startOffset, startType);
1942
- selection.focus.set(endKey, endOffset, endType);
1943
- return selection;
1944
- }
1945
-
1946
- getOffsetsFromSelection(selection) {
1947
- const anchor = selection.anchor;
1948
- const focus = selection.focus;
1949
- const offsetMap = this._offsetMap;
1950
- const anchorOffset = anchor.offset;
1951
- const focusOffset = focus.offset;
1952
- let start = -1;
1953
- let end = -1;
1954
-
1955
- if (anchor.type === 'text') {
1956
- const offsetNode = offsetMap.get(anchor.key);
1957
-
1958
- if (offsetNode !== undefined) {
1959
- start = offsetNode.start + anchorOffset;
1960
- }
1961
- } else {
1962
- const node = anchor.getNode().getDescendantByIndex(anchorOffset);
1963
- const offsetNode = offsetMap.get(node.getKey());
1964
-
1965
- if (offsetNode !== undefined) {
1966
- const isAtEnd = node.getIndexWithinParent() !== anchorOffset;
1967
- start = isAtEnd ? offsetNode.end : offsetNode.start;
1968
- }
1969
- }
1970
-
1971
- if (focus.type === 'text') {
1972
- const offsetNode = offsetMap.get(focus.key);
1973
-
1974
- if (offsetNode !== undefined) {
1975
- end = offsetNode.start + focus.offset;
1976
- }
1977
- } else {
1978
- const node = focus.getNode().getDescendantByIndex(focusOffset);
1979
- const offsetNode = offsetMap.get(node.getKey());
1980
-
1981
- if (offsetNode !== undefined) {
1982
- const isAtEnd = node.getIndexWithinParent() !== focusOffset;
1983
- end = isAtEnd ? offsetNode.end : offsetNode.start;
1984
- }
1985
- }
1986
-
1987
- return [start, end];
1988
- }
1989
-
1990
- }
1991
-
1992
- function $getAdjustedOffsetFromDiff(offset, offsetNode, prevOffsetView, offsetView, blockOffsetSize) {
1993
- const prevOffsetMap = prevOffsetView._offsetMap;
1994
- const offsetMap = offsetView._offsetMap;
1995
- const visited = new Set();
1996
- let adjustedOffset = offset;
1997
- let currentNode = offsetNode;
1998
-
1999
- while (currentNode !== null) {
2000
- const key = currentNode.key;
2001
- const prevNode = prevOffsetMap.get(key);
2002
- const diff = currentNode.end - currentNode.start;
2003
- visited.add(key);
2004
-
2005
- if (prevNode === undefined) {
2006
- adjustedOffset += diff;
2007
- } else {
2008
- const prevDiff = prevNode.end - prevNode.start;
2009
-
2010
- if (prevDiff !== diff) {
2011
- adjustedOffset += diff - prevDiff;
2012
- }
2013
- }
2014
-
2015
- const sibling = currentNode.prev;
2016
-
2017
- if (sibling !== null) {
2018
- currentNode = sibling;
2019
- continue;
2020
- }
2021
-
2022
- let parent = currentNode.parent;
2023
-
2024
- while (parent !== null) {
2025
- let parentSibling = parent.prev;
2026
-
2027
- if (parentSibling !== null) {
2028
- const parentSiblingKey = parentSibling.key;
2029
- const prevParentSibling = prevOffsetMap.get(parentSiblingKey);
2030
- const parentDiff = parentSibling.end - parentSibling.start;
2031
- visited.add(parentSiblingKey);
2032
-
2033
- if (prevParentSibling === undefined) {
2034
- adjustedOffset += parentDiff;
2035
- } else {
2036
- const prevParentDiff = prevParentSibling.end - prevParentSibling.start;
2037
-
2038
- if (prevParentDiff !== parentDiff) {
2039
- adjustedOffset += parentDiff - prevParentDiff;
2040
- }
2041
- }
2042
-
2043
- parentSibling = parentSibling.prev;
2044
- }
2045
-
2046
- parent = parent.parent;
2047
- }
2048
-
2049
- break;
2050
- } // Now traverse through the old offsets nodes and find any nodes we missed
2051
- // above, because they were not in the latest offset node view (they have been
2052
- // deleted).
2053
-
2054
-
2055
- const prevFirstNode = prevOffsetView._firstNode;
2056
-
2057
- if (prevFirstNode !== null) {
2058
- currentNode = $searchForNodeWithOffset(prevFirstNode, offset, blockOffsetSize);
2059
- let alreadyVisistedParentOfCurrentNode = false;
2060
-
2061
- while (currentNode !== null) {
2062
- if (!visited.has(currentNode.key)) {
2063
- alreadyVisistedParentOfCurrentNode = true;
2064
- break;
2065
- }
2066
-
2067
- currentNode = currentNode.parent;
2068
- }
2069
-
2070
- if (!alreadyVisistedParentOfCurrentNode) {
2071
- while (currentNode !== null) {
2072
- const key = currentNode.key;
2073
-
2074
- if (!visited.has(key)) {
2075
- const node = offsetMap.get(key);
2076
- const prevDiff = currentNode.end - currentNode.start;
2077
-
2078
- if (node === undefined) {
2079
- adjustedOffset -= prevDiff;
2080
- } else {
2081
- const diff = node.end - node.start;
2082
-
2083
- if (prevDiff !== diff) {
2084
- adjustedOffset += diff - prevDiff;
2085
- }
2086
- }
2087
- }
2088
-
2089
- currentNode = currentNode.prev;
2090
- }
2091
- }
2092
- }
2093
-
2094
- return adjustedOffset;
2095
- }
2096
-
2097
- function $searchForNodeWithOffset(firstNode, offset, blockOffsetSize) {
2098
- let currentNode = firstNode;
2099
-
2100
- while (currentNode !== null) {
2101
- const end = currentNode.end + (currentNode.type !== 'element' || blockOffsetSize === 0 ? 1 : 0);
2102
-
2103
- if (offset < end) {
2104
- const child = currentNode.child;
2105
-
2106
- if (child !== null) {
2107
- currentNode = child;
2108
- continue;
2109
- }
2110
-
2111
- return currentNode;
2112
- }
2113
-
2114
- const sibling = currentNode.next;
2115
-
2116
- if (sibling === null) {
2117
- break;
2118
- }
2119
-
2120
- currentNode = sibling;
2121
- }
2122
-
2123
- return null;
2124
- }
2125
-
2126
- function $createInternalOffsetNode(child, type, start, end, key, parent) {
2127
- // $FlowFixMe: not sure why Flow doesn't like this?
2128
- return {
2129
- child,
2130
- end,
2131
- key,
2132
- next: null,
2133
- parent,
2134
- prev: null,
2135
- start,
2136
- type
2137
- };
2138
- }
2139
-
2140
- function $createOffsetNode(state, key, parent, nodeMap, offsetMap, blockOffsetSize) {
2141
- const node = nodeMap.get(key);
2142
-
2143
- if (node === undefined) {
2144
- {
2145
- throw Error(`createOffsetModel: could not find node by key`);
2146
- }
2147
- }
2148
-
2149
- const start = state.offset;
2150
-
2151
- if (lexical.$isElementNode(node)) {
2152
- const childKeys = node.__children;
2153
- const blockIsEmpty = childKeys.length === 0;
2154
- const child = blockIsEmpty ? null : $createOffsetChild(state, childKeys, null, nodeMap, offsetMap, blockOffsetSize); // If the prev node was not a block or the block is empty, we should
2155
- // account for the user being able to selection the block (due to the \n).
2156
-
2157
- if (!state.prevIsBlock || blockIsEmpty) {
2158
- state.prevIsBlock = true;
2159
- state.offset += blockOffsetSize;
2160
- }
2161
-
2162
- const offsetNode = $createInternalOffsetNode(child, 'element', start, start, key, parent);
2163
-
2164
- if (child !== null) {
2165
- child.parent = offsetNode;
2166
- }
2167
-
2168
- const end = state.offset;
2169
- offsetNode.end = end;
2170
- offsetMap.set(key, offsetNode);
2171
- return offsetNode;
2172
- }
2173
-
2174
- state.prevIsBlock = false;
2175
- const isText = lexical.$isTextNode(node); // $FlowFixMe: isText means __text is available
2176
-
2177
- const length = isText ? node.__text.length : 1;
2178
- const end = state.offset += length;
2179
- const offsetNode = $createInternalOffsetNode(null, isText ? 'text' : 'inline', start, end, key, parent);
2180
- offsetMap.set(key, offsetNode);
2181
- return offsetNode;
2182
- }
2183
-
2184
- function $createOffsetChild(state, children, parent, nodeMap, offsetMap, blockOffsetSize) {
2185
- let firstNode = null;
2186
- let currentNode = null;
2187
- const childrenLength = children.length;
2188
-
2189
- for (let i = 0; i < childrenLength; i++) {
2190
- const childKey = children[i];
2191
- const offsetNode = $createOffsetNode(state, childKey, parent, nodeMap, offsetMap, blockOffsetSize);
2192
-
2193
- if (currentNode === null) {
2194
- firstNode = offsetNode;
2195
- } else {
2196
- offsetNode.prev = currentNode;
2197
- currentNode.next = offsetNode;
2198
- }
2199
-
2200
- currentNode = offsetNode;
2201
- }
2202
-
2203
- return firstNode;
2204
- }
2205
-
2206
- function $createOffsetView(editor, blockOffsetSize = 1, editorState) {
2207
- const targetEditorState = editorState || editor._pendingEditorState || editor._editorState;
2208
- const nodeMap = targetEditorState._nodeMap; // $FlowFixMe: root is always in the Map
2209
-
2210
- const root = nodeMap.get('root');
2211
- const offsetMap = new Map();
2212
- const state = {
2213
- offset: 0,
2214
- prevIsBlock: false
2215
- };
2216
- const node = $createOffsetChild(state, root.__children, null, nodeMap, offsetMap, blockOffsetSize);
2217
- return new OffsetView(offsetMap, node, blockOffsetSize);
2218
- }
2219
-
2220
1857
  /**
2221
1858
  * Copyright (c) Meta Platforms, Inc. and affiliates.
2222
1859
  *
@@ -2331,8 +1968,8 @@ function syncYjsChangesToLexical(binding, provider, events) {
2331
1968
  const prevSelection = currentEditorState._selection;
2332
1969
 
2333
1970
  if (lexical.$isRangeSelection(prevSelection)) {
2334
- const prevOffsetView = $createOffsetView(editor, 0, currentEditorState);
2335
- const nextOffsetView = $createOffsetView(editor, 0, pendingEditorState);
1971
+ const prevOffsetView = offset.$createOffsetView(editor, 0, currentEditorState);
1972
+ const nextOffsetView = offset.$createOffsetView(editor, 0, pendingEditorState);
2336
1973
  const [start, end] = prevOffsetView.getOffsetsFromSelection(prevSelection);
2337
1974
  const nextSelection = nextOffsetView.createSelectionFromOffsets(start, end, prevOffsetView);
2338
1975
 
@@ -2453,6 +2090,8 @@ function syncLexicalUpdateToYjs(binding, provider, prevEditorState, currEditorSt
2453
2090
  *
2454
2091
  *
2455
2092
  */
2093
+ const CONNECTED_COMMAND = lexical.createCommand();
2094
+ const TOGGLE_CONNECT_COMMAND = lexical.createCommand();
2456
2095
  function createUndoManager(binding, root) {
2457
2096
  return new yjs.UndoManager(root, {
2458
2097
  trackedOrigins: new Set([binding, null])
@@ -2487,6 +2126,8 @@ function setLocalStateFocus(provider, name, color, focusing) {
2487
2126
  awareness.setLocalState(localState);
2488
2127
  }
2489
2128
 
2129
+ exports.CONNECTED_COMMAND = CONNECTED_COMMAND;
2130
+ exports.TOGGLE_CONNECT_COMMAND = TOGGLE_CONNECT_COMMAND;
2490
2131
  exports.createBinding = createBinding;
2491
2132
  exports.createUndoManager = createUndoManager;
2492
2133
  exports.initLocalState = initLocalState;
@@ -4,64 +4,57 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- var m=require("yjs"),v=require("lexical");function z(a){throw Error(`Minified Lexical error #${a}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
- class B{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){const a=v.$getNodeByKey(this._key);return v.$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)}}function C(a,b){b=new B(a,b);return a._collabNode=b}
9
- class D{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 v.$isTextNode(a)?a:null}getNode(){const a=v.$getNodeByKey(this._key);return v.$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){const d=
10
- this._parent._xmlText;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;E(a,this._map,d,b);if(null!==d&&(a=d.__text,a!==c)){d=b.__key;b=a;var e=v.$getSelection();a=c.length;v.$isRangeSelection(e)&&e.isCollapsed()&&(e=e.anchor,e.key===d&&(a=e.offset));d=b.length;const f=c.length;let g=e=0;for(;e<d&&e<f&&b[e]===c[e]&&e<a;)e++;for(;g+e<d&&g+e<f&&b[d-g-1]===c[f-g-1];)g++;for(;g+e<d&&g+e<f&&b[e]===c[e];)e++;b=
11
- e;a=c.slice(e,f-g);d=d-e-g;this.spliceText(b,d,a);this._text=c}}syncPropertiesAndTextFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");F(a,this._map,c,b);a=this._text;c.__text!==a&&(c.getWritable().__text=a)}destroy(a){a.collabNodeMap.delete(this._key)}}function G(a,b,c,d){b=new D(a,b,c,d);return a._collabNode=b}const I=new Set("__key __children __parent __cachedText __text __state".split(" "));
12
- function J(a){a=v.$getNodeByKey(a);if(null===a)throw Error("Should never happen");return a}
13
- function aa(a,b,c){const d=b.__type;if(v.$isElementNode(b)){var e=new m.XmlText;c=K(e,c,d);c.syncPropertiesFromLexical(a,b,null);c.syncChildrenFromLexical(a,b,null,null,null)}else if(v.$isTextNode(b))e=new m.Map,c=G(e,b.__text,c,d),c.syncPropertiesAndTextFromLexical(a,b,null);else if(v.$isLineBreakNode(b))a=new m.Map,a.set("__type","linebreak"),c=C(a,c);else if(v.$isDecoratorNode(b))e=new m.XmlElement,c=ba(e,c,d),c.syncPropertiesFromLexical(a,b,null);else throw Error("Should never happen");c._key=
7
+ var k=require("lexical"),r=require("yjs"),z=require("@lexical/offset");function B(a){throw Error(`Minified Lexical error #${a}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
+ class C{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){const a=k.$getNodeByKey(this._key);return k.$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)}}function D(a,b){b=new C(a,b);return a._collabNode=b}
9
+ class E{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 k.$isTextNode(a)?a:null}getNode(){const a=k.$getNodeByKey(this._key);return k.$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){const d=
10
+ this._parent._xmlText;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;F(a,this._map,d,b);if(null!==d&&(a=d.__text,a!==c)){d=b.__key;b=a;var e=k.$getSelection();a=c.length;k.$isRangeSelection(e)&&e.isCollapsed()&&(e=e.anchor,e.key===d&&(a=e.offset));d=b.length;const f=c.length;let g=e=0;for(;e<d&&e<f&&b[e]===c[e]&&e<a;)e++;for(;g+e<d&&g+e<f&&b[d-g-1]===c[f-g-1];)g++;for(;g+e<d&&g+e<f&&b[e]===c[e];)e++;b=
11
+ e;a=c.slice(e,f-g);d=d-e-g;this.spliceText(b,d,a);this._text=c}}syncPropertiesAndTextFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");G(a,this._map,c,b);a=this._text;c.__text!==a&&(c.getWritable().__text=a)}destroy(a){a.collabNodeMap.delete(this._key)}}function I(a,b,c,d){b=new E(a,b,c,d);return a._collabNode=b}const J=new Set("__key __children __parent __cachedText __text __state".split(" "));
12
+ function K(a){a=k.$getNodeByKey(a);if(null===a)throw Error("Should never happen");return a}
13
+ function aa(a,b,c){const d=b.__type;if(k.$isElementNode(b)){var e=new r.XmlText;c=L(e,c,d);c.syncPropertiesFromLexical(a,b,null);c.syncChildrenFromLexical(a,b,null,null,null)}else if(k.$isTextNode(b))e=new r.Map,c=I(e,b.__text,c,d),c.syncPropertiesAndTextFromLexical(a,b,null);else if(k.$isLineBreakNode(b))a=new r.Map,a.set("__type","linebreak"),c=D(a,c);else if(k.$isDecoratorNode(b))e=new r.XmlElement,c=ba(e,c,d),c.syncPropertiesFromLexical(a,b,null);else throw Error("Should never happen");c._key=
14
14
  b.__key;return c}
15
- function L(a,b,c){const d=b._collabNode;if(void 0===d){var e=a.editor._nodes;const f=b instanceof m.Map?b.get("__type"):b.getAttribute("__type");if(null==f)throw Error("Should never happen");if(void 0===e.get(f))throw Error("Should never happen");e=b.parent;a=void 0===c&&null!==e?L(a,e):c||null;if(!(a instanceof M))throw Error("Should never happen");if(b instanceof m.XmlText)return K(b,a,f);if(b instanceof m.Map){if(null===a)throw Error("Should never happen");return"linebreak"===f?C(b,a):G(b,"",a,
16
- f)}if(b instanceof m.XmlElement)return ba(b,a,f)}return d}function F(a,b,c,d){a=null===d?b instanceof m.Map?Array.from(b.keys()):Object.keys(b.getAttributes()):Array.from(d);let e;for(d=0;d<a.length;d++){const f=a[d];if(I.has(f))continue;const g=c[f],h=b instanceof m.Map?b.get(f):b.getAttribute(f);g!==h&&(void 0===e&&(e=c.getWritable()),e[f]=h)}}
17
- function E(a,b,c,d){var e=d.__type,f=a.nodeProperties;a=f.get(e);void 0===a&&(a=Object.keys(d).filter(g=>!I.has(g)),f.set(e,a));for(e=0;e<a.length;e++){f=a[e];const g=d[f];(null===c?void 0:c[f])!==g&&(b instanceof m.Map?b.set(f,g):b.setAttribute(f,g))}}
18
- function N(a,b,c){let d=0,e=0;const f=a._children,g=f.length;for(;e<g;e++){a=f[e];const h=d,n=a.getSize();d+=n;if((c?d>=b:d>b)&&a instanceof D)return b=b-h-1,0>b&&(b=0),{length:n-b,node:a,nodeIndex:e,offset:b};if(d>b)return{length:0,node:a,nodeIndex:e,offset:h};if(e===g-1)return{length:0,node:null,nodeIndex:e+1,offset:h+1}}return{length:0,node:null,nodeIndex:0,offset:0}}
19
- function ca(a){const b=a.anchor;a=a.focus;let c=!1;try{const d=b.getNode(),e=a.getNode();if(!d.isAttached()||!e.isAttached()||v.$isTextNode(d)&&b.offset>d.getTextContentSize()||v.$isTextNode(e)&&a.offset>e.getTextContentSize())c=!0}catch(d){c=!0}return c}function P(a,b){a.doc.transact(b,a)}let Q=!1;function R(a){const b=Q;try{Q=!0,a()}finally{Q=b}}function S(a,b,c,d){const e=c.observe(f=>{Q||P(a,()=>da(a,b,c._map,d,f))});b._unobservers.add(e)}
20
- function T(a,b,c,d){const e=c.observe((f,g)=>{Q||P(a,()=>{0<g&&d.delete(f,g);ea(a,b,c._array,d,f)})});b._unobservers.add(e)}
21
- function da(a,b,c,d,e){const f=c.get(e);c=d.get(e);if(f!==c)if(v.isDecoratorMap(f))void 0===c&&(c=new m.Map,c._lexicalValue=f,c._collabNode=b,c.set("type","map"),d.set(e,c),S(a,b,f,c)),U(a,b,f,c);else if(v.isDecoratorEditor(f)){let g;void 0===c&&(c=new m.Map,c._lexicalValue=f,c._collabNode=b,g=new m.Doc,c.set("doc",g),c.set("type","editor"),d.set(e,c));g=g||c.get("doc");b=c.get("id");d=f.id;b!==d&&(a=a.docMap,a.delete(b),c.set("id",d),a.set(d,g))}else v.isDecoratorArray(f)?(void 0===c&&(c=new m.Array,
22
- c._lexicalValue=f,c._collabNode=b,d.set(e,c),T(a,b,f,c)),fa(a,b,f,c)):((v.isDecoratorArray(c)||v.isDecoratorMap(c))&&c.destroy(),d.set(e,f))}
23
- function ea(a,b,c,d,e){const f=c[e];c=d.get(e);if(f!==c)if(v.isDecoratorMap(f))void 0===c&&(c=new m.Map,c._lexicalValue=f,c._collabNode=b,c.set("type","map"),d.insert(e,[c]),S(a,b,f,c)),U(a,b,f,c);else if(v.isDecoratorEditor(f)){let g;void 0===c&&(c=new m.Map,c._lexicalValue=f,c._collabNode=b,g=new m.Doc,c.set("doc",g),c.set("type","editor"),d.insert(e,[c]));g=g||c.get("doc");b=c.get("id");d=f.id;b!==d&&(a=a.docMap,a.delete(b),c.set("id",d),a.set(d,g))}else v.isDecoratorArray(f)?(void 0===c&&(c=new m.Array,
24
- c._lexicalValue=f,c._collabNode=b,d.insert(e,[c]),T(a,b,f,c)),fa(a,b,f,c)):d.insert(e,[f])}function U(a,b,c,d){c=c._map;const e=Array.from(c.keys());for(let f=0;f<e.length;f++)da(a,b,c,d,e[f])}function fa(a,b,c,d){c=c._array;for(let e=0;e<c.length;e++)ea(a,b,c,d,e)}
25
- function ha(a,b,c,d,e){var f=d.get(e);const g=c.get(e);if(f!==g){let h=g._lexicalValue;g instanceof m.Map?(c=g.get("type"),"editor"===c?void 0===h&&(a=a.docMap,c=g.get("id"),f=g.get("doc"),h=v.createDecoratorEditor(c),g._lexicalValue=h,g._collabNode=b,a.set(c,f),R(()=>d.set(e,h))):"map"===c?(void 0===h&&(h=v.createDecoratorMap(a.editor),S(a,b,h,g),g._lexicalValue=h,g._collabNode=b,R(()=>d.set(e,h))),V(a,b,g,h,null)):z(48)):g instanceof m.Array?(void 0===h&&(h=v.createDecoratorArray(a.editor),T(a,
26
- b,h,g),g._lexicalValue=h,g._collabNode=b,R(()=>d.set(e,h))),ia(a,b,g,h)):R(()=>d.set(e,g))}}
27
- function ja(a,b,c,d,e){var f=d._array[e];const g=c.get(e);if(f!==g){let h=g._lexicalValue;g instanceof m.Map?(c=g.get("type"),"editor"===c?void 0===h&&(a=a.docMap,c=g.get("id"),f=g.get("doc"),h=v.createDecoratorEditor(c),g._lexicalValue=h,g._collabNode=b,a.set(c,f),R(()=>d.splice(e,0,h))):"map"===c?(void 0===h&&(h=v.createDecoratorMap(a.editor),S(a,b,h,g),g._lexicalValue=h,g._collabNode=b,R(()=>d.splice(e,0,h))),V(a,b,g,h,null)):z(48)):g instanceof m.Array?(void 0===h&&(h=v.createDecoratorArray(a.editor),
28
- T(a,b,h,g),g._lexicalValue=h,g._collabNode=b,R(()=>d.splice(e,0,h))),ia(a,b,g,h)):R(()=>d.splice(e,0,g))}}function ia(a,b,c,d){const e=Math.max(c.length,d.getLength());for(let f=0;f<e;f++)ja(a,b,c,d,f)}function V(a,b,c,d,e){e=null===e?Array.from(c.keys()):Array.from(e);for(let f=0;f<e.length;f++)ha(a,b,c,d,e[f])}
29
- class X{constructor(a,b,c){this._key="";this._xmlElem=a;this._parent=b;this._type=c;this._unobservers=new Set}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return v.$isDecoratorNode(a)?a:null}getNode(){const a=v.$getNodeByKey(this._key);return v.$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){const d=this.getPrevNode(c);
30
- c=this._xmlElem;const e=null===d?null:d.__state,f=b.__state;E(a,c,d,b);e!==f&&(b=new m.Map,c.insert(0,[b]),b._lexicalValue=f,b._collabNode=this,U(a,this,f,b),S(a,this,f,b))}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");const d=this._xmlElem,e=d.firstChild,f=c.__state;e._lexicalValue=f;e._collabNode=this;F(a,d,c,b);V(a,this,e,f,null);S(a,this,f,e)}destroy(a){a.collabNodeMap.delete(this._key);this._unobservers.forEach(b=>b());this._unobservers.clear()}}
31
- function ba(a,b,c){b=new X(a,b,c);return a._collabNode=b}
32
- class M{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 v.$isElementNode(a)?a:null}getNode(){const a=v.$getNodeByKey(this._key);return v.$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(){const a=this._parent;if(null===a)throw Error("Should never happen");
33
- return a.getChildOffset(this)}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw this.getNode(),Error("Should never happen");F(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){const c=this._children;let d=0;for(let l=0;l<b.length;l++){var e=b[l],f=e.insert,g=e.delete;if(null!=e.retain)d+=e.retain;else if("number"===typeof g)for(f=g;0<f;){const {node:k,nodeIndex:r,offset:t,length:q}=N(this,d,!1);if(k instanceof M||k instanceof B||k instanceof X)c.splice(r,1),--f;else if(k instanceof
34
- D){e=Math.min(f,q);g=0!==r?c[r-1]:null;var h=k.getSize();if(0===t&&1===e&&0<r&&g instanceof D&&q===h&&0===Array.from(k._map.keys()).length)g._text+=k._text,c.splice(r,1);else if(0===t&&e===h)c.splice(r,1);else{g=k._text;h=t;var n=e;g=g.slice(0,h)+""+g.slice(h+n);k._text=g}f-=e}else break}else if(null!=f)if("string"===typeof f){const {node:k,offset:r}=N(this,d,!0);k instanceof D?(e=k._text,g=r,h=f,e=e.slice(0,g)+h+e.slice(g+0),k._text=e):this._xmlText.delete(r,f.length);d+=f.length}else e=f,{nodeIndex:f}=
35
- N(this,d,!1),e=L(a,e,this),c.splice(f,0,e),d+=1;else throw Error("Unexpected delta format");}}syncChildrenFromYjs(a){var b=this.getNode();if(null===b)throw this.getNode(),Error("Should never happen");var c=b.__key;const d=b.__children;var e=[];const f=d.length,g=this._children,h=g.length,n=a.collabNodeMap,l=new Set;let k,r;h!==f&&(r=ka(b,r,e));let t=0;for(let y=0;y<h;y++){var q=d[t];const x=g[y];var p=x.getNode(),u=x._key;if(null!==p&&q===u){p=v.$isTextNode(p);l.add(q);if(p)if(x._key=q,x instanceof
36
- M)p=x._xmlText,x.syncPropertiesFromYjs(a,null),x.applyChildrenYjsDelta(a,p.toDelta()),x.syncChildrenFromYjs(a);else if(x instanceof D)x.syncPropertiesAndTextFromYjs(a,null);else if(x instanceof X)x.syncPropertiesFromYjs(a,null);else if(!(x instanceof B))throw Error("Should never happen");e[y]=q;t++}else{if(void 0===k)for(k=new Set,u=0;u<h;u++){var w=g[u]._key;""!==w&&k.add(w)}if(null===p||void 0===q||k.has(q)){r=ka(b,r,e);q=a;p=x;u=c;w=p.getType();w=q.editor._nodes.get(w);if(void 0===w)throw Error("createLexicalNode failed");
37
- w=new w.klass;w.__parent=u;p._key=w.__key;p instanceof M?(u=p._xmlText,p.syncPropertiesFromYjs(q,null),p.applyChildrenYjsDelta(q,u.toDelta()),p.syncChildrenFromYjs(q)):p instanceof D?p.syncPropertiesAndTextFromYjs(q,null):p instanceof X&&p.syncPropertiesFromYjs(q,null);q.collabNodeMap.set(w.__key,p);q=w.__key;n.set(q,x);e[y]=q}else y--,t++}}for(b=0;b<f;b++)e=d[b],l.has(e)||(c=J(e).getWritable(),e=a.collabNodeMap.get(e),void 0!==e&&e.destroy(a),c.__parent=null)}syncPropertiesFromLexical(a,b,c){E(a,
38
- this._xmlText,this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=J(c);b instanceof M&&v.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof D&&v.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof X&&v.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var f=this.getPrevNode(c);const g=null===f?[]:f.__children;f=b.__children;const h=g.length-1,n=f.length-1,l=
39
- a.collabNodeMap;let k,r,t=0;for(b=0;t<=h&&b<=n;){var q=g[t];const u=f[b];if(q===u)this._syncChildFromLexical(a,b,u,c,d,e),t++,b++;else{void 0===k&&(k=new Set(g));void 0===r&&(r=new Set(f));var p=r.has(q);q=k.has(u);p?(p=J(u),p=aa(a,p,this),l.set(u,p),q?(this.splice(a,b,1,p),t++):this.splice(a,b,0,p),b++):(this.splice(a,b,1),t++)}}c=t>h;d=b>n;if(c&&!d)for(;b<=n;++b)c=f[b],d=J(c),d=aa(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){const b=
40
- this._xmlText;var c=this._children;c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof M)b.insertEmbed(c,a._xmlText);else if(a instanceof D){const d=a._map;null===d.parent&&b.insertEmbed(c,d);b.insert(c+1,a._text)}else a instanceof B?b.insertEmbed(c,a._map):a instanceof X&&b.insertEmbed(c,a._xmlElem);this._children.push(a)}splice(a,b,c,d){const e=this._children;var f=e[b];if(void 0===f)if(void 0!==d)this.append(d);else throw Error("Should never happen");else{var g=f.getOffset();
41
- if(-1===g)throw Error("Should never happen");var h=this._xmlText;0!==c&&h.delete(g,f.getSize());d instanceof M?h.insertEmbed(g,d._xmlText):d instanceof D?(f=d._map,null===f.parent&&h.insertEmbed(g,f),h.insert(g+1,d._text)):d instanceof B?h.insertEmbed(g,d._map):d instanceof X&&h.insertEmbed(g,d._xmlElem);if(0!==c)for(g=e.slice(b,b+c),h=0;h<g.length;h++)g[h].destroy(a);void 0!==d?e.splice(b,c,d):e.splice(b,c)}}getChildOffset(a){let b=0;const c=this._children;for(let d=0;d<c.length;d++){const e=c[d];
42
- if(e===a)return b;b+=e.getSize()}return-1}destroy(a){const b=a.collabNodeMap,c=this._children;for(let d=0;d<c.length;d++)c[d].destroy(a);b.delete(this._key)}}function ka(a,b,c){return void 0===b?(a=a.getWritable(),a.__children=c,a):b}function K(a,b,c){b=new M(a,b,c);return a._collabNode=b}
43
- function la(a,b){b=b.collabNodeMap.get(a.key);if(void 0===b)return null;a=a.offset;let c=b.getSharedType();if(b instanceof D){c=b._parent._xmlText;b=b.getOffset();if(-1===b)return null;a=b+1+a}return m.createRelativePositionFromTypeIndex(c,a)}function ma(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!m.compareRelativePositions(a,b))return!0;return!1}function na(a,b){a=a.cursorsContainer;if(null!==a){b=b.selections;const c=b.length;for(let d=0;d<c;d++)a.removeChild(b[d])}}
15
+ function M(a,b,c){const d=b._collabNode;if(void 0===d){var e=a.editor._nodes;const f=b instanceof r.Map?b.get("__type"):b.getAttribute("__type");if(null==f)throw Error("Should never happen");if(void 0===e.get(f))throw Error("Should never happen");e=b.parent;a=void 0===c&&null!==e?M(a,e):c||null;if(!(a instanceof O))throw Error("Should never happen");if(b instanceof r.XmlText)return L(b,a,f);if(b instanceof r.Map){if(null===a)throw Error("Should never happen");return"linebreak"===f?D(b,a):I(b,"",a,
16
+ f)}if(b instanceof r.XmlElement)return ba(b,a,f)}return d}function G(a,b,c,d){a=null===d?b instanceof r.Map?Array.from(b.keys()):Object.keys(b.getAttributes()):Array.from(d);let e;for(d=0;d<a.length;d++){const f=a[d];if(J.has(f))continue;const g=c[f],h=b instanceof r.Map?b.get(f):b.getAttribute(f);g!==h&&(void 0===e&&(e=c.getWritable()),e[f]=h)}}
17
+ function F(a,b,c,d){var e=d.__type,f=a.nodeProperties;a=f.get(e);void 0===a&&(a=Object.keys(d).filter(g=>!J.has(g)),f.set(e,a));for(e=0;e<a.length;e++){f=a[e];const g=d[f];(null===c?void 0:c[f])!==g&&(b instanceof r.Map?b.set(f,g):b.setAttribute(f,g))}}
18
+ function P(a,b,c){let d=0,e=0;const f=a._children,g=f.length;for(;e<g;e++){a=f[e];const h=d,p=a.getSize();d+=p;if((c?d>=b:d>b)&&a instanceof E)return b=b-h-1,0>b&&(b=0),{length:p-b,node:a,nodeIndex:e,offset:b};if(d>b)return{length:0,node:a,nodeIndex:e,offset:h};if(e===g-1)return{length:0,node:null,nodeIndex:e+1,offset:h+1}}return{length:0,node:null,nodeIndex:0,offset:0}}
19
+ function ca(a){const b=a.anchor;a=a.focus;let c=!1;try{const d=b.getNode(),e=a.getNode();if(!d.isAttached()||!e.isAttached()||k.$isTextNode(d)&&b.offset>d.getTextContentSize()||k.$isTextNode(e)&&a.offset>e.getTextContentSize())c=!0}catch(d){c=!0}return c}function Q(a,b){a.doc.transact(b,a)}let R=!1;function S(a){const b=R;try{R=!0,a()}finally{R=b}}function T(a,b,c,d){const e=c.observe(f=>{R||Q(a,()=>da(a,b,c._map,d,f))});b._unobservers.add(e)}
20
+ function V(a,b,c,d){const e=c.observe((f,g)=>{R||Q(a,()=>{0<g&&d.delete(f,g);ea(a,b,c._array,d,f)})});b._unobservers.add(e)}
21
+ function da(a,b,c,d,e){const f=c.get(e);c=d.get(e);if(f!==c)if(k.isDecoratorMap(f))void 0===c&&(c=new r.Map,c._lexicalValue=f,c._collabNode=b,c.set("type","map"),d.set(e,c),T(a,b,f,c)),W(a,b,f,c);else if(k.isDecoratorEditor(f)){let g;void 0===c&&(c=new r.Map,c._lexicalValue=f,c._collabNode=b,g=new r.Doc,c.set("doc",g),c.set("type","editor"),d.set(e,c));g=g||c.get("doc");b=c.get("id");d=f.id;b!==d&&(a=a.docMap,a.delete(b),c.set("id",d),a.set(d,g))}else k.isDecoratorArray(f)?(void 0===c&&(c=new r.Array,
22
+ c._lexicalValue=f,c._collabNode=b,d.set(e,c),V(a,b,f,c)),fa(a,b,f,c)):((k.isDecoratorArray(c)||k.isDecoratorMap(c))&&c.destroy(),d.set(e,f))}
23
+ function ea(a,b,c,d,e){const f=c[e];c=d.get(e);if(f!==c)if(k.isDecoratorMap(f))void 0===c&&(c=new r.Map,c._lexicalValue=f,c._collabNode=b,c.set("type","map"),d.insert(e,[c]),T(a,b,f,c)),W(a,b,f,c);else if(k.isDecoratorEditor(f)){let g;void 0===c&&(c=new r.Map,c._lexicalValue=f,c._collabNode=b,g=new r.Doc,c.set("doc",g),c.set("type","editor"),d.insert(e,[c]));g=g||c.get("doc");b=c.get("id");d=f.id;b!==d&&(a=a.docMap,a.delete(b),c.set("id",d),a.set(d,g))}else k.isDecoratorArray(f)?(void 0===c&&(c=new r.Array,
24
+ c._lexicalValue=f,c._collabNode=b,d.insert(e,[c]),V(a,b,f,c)),fa(a,b,f,c)):d.insert(e,[f])}function W(a,b,c,d){c=c._map;for(const [e]of c)da(a,b,c,d,e)}function fa(a,b,c,d){c=c._array;for(let e=0;e<c.length;e++)ea(a,b,c,d,e)}
25
+ function ha(a,b,c,d,e){var f=d.get(e);const g=c.get(e);if(f!==g){let h=g._lexicalValue;g instanceof r.Map?(c=g.get("type"),"editor"===c?void 0===h&&(a=a.docMap,c=g.get("id"),f=g.get("doc"),h=k.createDecoratorEditor(c),g._lexicalValue=h,g._collabNode=b,a.set(c,f),S(()=>d.set(e,h))):"map"===c?(void 0===h&&(h=k.createDecoratorMap(a.editor),T(a,b,h,g),g._lexicalValue=h,g._collabNode=b,S(()=>d.set(e,h))),X(a,b,g,h,null)):B(48)):g instanceof r.Array?(void 0===h&&(h=k.createDecoratorArray(a.editor),V(a,
26
+ b,h,g),g._lexicalValue=h,g._collabNode=b,S(()=>d.set(e,h))),ia(a,b,g,h)):S(()=>d.set(e,g))}}
27
+ function ja(a,b,c,d,e){var f=d._array[e];const g=c.get(e);if(f!==g){let h=g._lexicalValue;g instanceof r.Map?(c=g.get("type"),"editor"===c?void 0===h&&(a=a.docMap,c=g.get("id"),f=g.get("doc"),h=k.createDecoratorEditor(c),g._lexicalValue=h,g._collabNode=b,a.set(c,f),S(()=>d.splice(e,0,h))):"map"===c?(void 0===h&&(h=k.createDecoratorMap(a.editor),T(a,b,h,g),g._lexicalValue=h,g._collabNode=b,S(()=>d.splice(e,0,h))),X(a,b,g,h,null)):B(48)):g instanceof r.Array?(void 0===h&&(h=k.createDecoratorArray(a.editor),
28
+ V(a,b,h,g),g._lexicalValue=h,g._collabNode=b,S(()=>d.splice(e,0,h))),ia(a,b,g,h)):S(()=>d.splice(e,0,g))}}function ia(a,b,c,d){const e=Math.max(c.length,d.getLength());for(let f=0;f<e;f++)ja(a,b,c,d,f)}function X(a,b,c,d,e){e=null===e?Array.from(c.keys()):Array.from(e);for(let f=0;f<e.length;f++)ha(a,b,c,d,e[f])}
29
+ class Y{constructor(a,b,c){this._key="";this._xmlElem=a;this._parent=b;this._type=c;this._unobservers=new Set}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return k.$isDecoratorNode(a)?a:null}getNode(){const a=k.$getNodeByKey(this._key);return k.$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){const d=this.getPrevNode(c);
30
+ c=this._xmlElem;const e=null===d?null:d.__state,f=b.__state;F(a,c,d,b);e!==f&&(b=new r.Map,c.insert(0,[b]),b._lexicalValue=f,b._collabNode=this,W(a,this,f,b),T(a,this,f,b))}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");const d=this._xmlElem,e=d.firstChild,f=c.__state;e._lexicalValue=f;e._collabNode=this;G(a,d,c,b);X(a,this,e,f,null);T(a,this,f,e)}destroy(a){a.collabNodeMap.delete(this._key);this._unobservers.forEach(b=>b());this._unobservers.clear()}}
31
+ function ba(a,b,c){b=new Y(a,b,c);return a._collabNode=b}
32
+ class O{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 k.$isElementNode(a)?a:null}getNode(){const a=k.$getNodeByKey(this._key);return k.$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(){const a=this._parent;if(null===a)throw Error("Should never happen");
33
+ return a.getChildOffset(this)}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw this.getNode(),Error("Should never happen");G(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){const c=this._children;let d=0;for(let q=0;q<b.length;q++){var e=b[q],f=e.insert,g=e.delete;if(null!=e.retain)d+=e.retain;else if("number"===typeof g)for(f=g;0<f;){const {node:l,nodeIndex:t,offset:u,length:n}=P(this,d,!1);if(l instanceof O||l instanceof C||l instanceof Y)c.splice(t,1),--f;else if(l instanceof
34
+ E){e=Math.min(f,n);g=0!==t?c[t-1]:null;var h=l.getSize();if(0===u&&1===e&&0<t&&g instanceof E&&n===h&&0===Array.from(l._map.keys()).length)g._text+=l._text,c.splice(t,1);else if(0===u&&e===h)c.splice(t,1);else{g=l._text;h=u;var p=e;g=g.slice(0,h)+""+g.slice(h+p);l._text=g}f-=e}else break}else if(null!=f)if("string"===typeof f){const {node:l,offset:t}=P(this,d,!0);l instanceof E?(e=l._text,g=t,h=f,e=e.slice(0,g)+h+e.slice(g+0),l._text=e):this._xmlText.delete(t,f.length);d+=f.length}else e=f,{nodeIndex:f}=
35
+ P(this,d,!1),e=M(a,e,this),c.splice(f,0,e),d+=1;else throw Error("Unexpected delta format");}}syncChildrenFromYjs(a){var b=this.getNode();if(null===b)throw this.getNode(),Error("Should never happen");var c=b.__key;const d=b.__children;var e=[];const f=d.length,g=this._children,h=g.length,p=a.collabNodeMap,q=new Set;let l,t;h!==f&&(t=ka(b,t,e));let u=0;for(let y=0;y<h;y++){var n=d[u];const x=g[y];var m=x.getNode(),w=x._key;if(null!==m&&n===w){m=k.$isTextNode(m);q.add(n);if(m)if(x._key=n,x instanceof
36
+ O)m=x._xmlText,x.syncPropertiesFromYjs(a,null),x.applyChildrenYjsDelta(a,m.toDelta()),x.syncChildrenFromYjs(a);else if(x instanceof E)x.syncPropertiesAndTextFromYjs(a,null);else if(x instanceof Y)x.syncPropertiesFromYjs(a,null);else if(!(x instanceof C))throw Error("Should never happen");e[y]=n;u++}else{if(void 0===l)for(l=new Set,w=0;w<h;w++){var v=g[w]._key;""!==v&&l.add(v)}if(null===m||void 0===n||l.has(n)){t=ka(b,t,e);n=a;m=x;w=c;v=m.getType();v=n.editor._nodes.get(v);if(void 0===v)throw Error("createLexicalNode failed");
37
+ v=new v.klass;v.__parent=w;m._key=v.__key;m instanceof O?(w=m._xmlText,m.syncPropertiesFromYjs(n,null),m.applyChildrenYjsDelta(n,w.toDelta()),m.syncChildrenFromYjs(n)):m instanceof E?m.syncPropertiesAndTextFromYjs(n,null):m instanceof Y&&m.syncPropertiesFromYjs(n,null);n.collabNodeMap.set(v.__key,m);n=v.__key;p.set(n,x);e[y]=n}else y--,u++}}for(b=0;b<f;b++)e=d[b],q.has(e)||(c=K(e).getWritable(),e=a.collabNodeMap.get(e),void 0!==e&&e.destroy(a),c.__parent=null)}syncPropertiesFromLexical(a,b,c){F(a,
38
+ this._xmlText,this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=K(c);b instanceof O&&k.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof E&&k.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof Y&&k.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var f=this.getPrevNode(c);const g=null===f?[]:f.__children;f=b.__children;const h=g.length-1,p=f.length-1,q=
39
+ a.collabNodeMap;let l,t,u=0;for(b=0;u<=h&&b<=p;){var n=g[u];const w=f[b];if(n===w)this._syncChildFromLexical(a,b,w,c,d,e),u++,b++;else{void 0===l&&(l=new Set(g));void 0===t&&(t=new Set(f));var m=t.has(n);n=l.has(w);m?(m=K(w),m=aa(a,m,this),q.set(w,m),n?(this.splice(a,b,1,m),u++):this.splice(a,b,0,m),b++):(this.splice(a,b,1),u++)}}c=u>h;d=b>p;if(c&&!d)for(;b<=p;++b)c=f[b],d=K(c),d=aa(a,d,this),this.append(d),q.set(c,d);else if(d&&!c)for(f=this._children.length-1;f>=b;f--)this.splice(a,f,1)}append(a){const b=
40
+ this._xmlText;var c=this._children;c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof O)b.insertEmbed(c,a._xmlText);else if(a instanceof E){const d=a._map;null===d.parent&&b.insertEmbed(c,d);b.insert(c+1,a._text)}else a instanceof C?b.insertEmbed(c,a._map):a instanceof Y&&b.insertEmbed(c,a._xmlElem);this._children.push(a)}splice(a,b,c,d){const e=this._children;var f=e[b];if(void 0===f)if(void 0!==d)this.append(d);else throw Error("Should never happen");else{var g=f.getOffset();
41
+ if(-1===g)throw Error("Should never happen");var h=this._xmlText;0!==c&&h.delete(g,f.getSize());d instanceof O?h.insertEmbed(g,d._xmlText):d instanceof E?(f=d._map,null===f.parent&&h.insertEmbed(g,f),h.insert(g+1,d._text)):d instanceof C?h.insertEmbed(g,d._map):d instanceof Y&&h.insertEmbed(g,d._xmlElem);if(0!==c)for(g=e.slice(b,b+c),h=0;h<g.length;h++)g[h].destroy(a);void 0!==d?e.splice(b,c,d):e.splice(b,c)}}getChildOffset(a){let b=0;const c=this._children;for(let d=0;d<c.length;d++){const e=c[d];
42
+ if(e===a)return b;b+=e.getSize()}return-1}destroy(a){const b=a.collabNodeMap,c=this._children;for(let d=0;d<c.length;d++)c[d].destroy(a);b.delete(this._key)}}function ka(a,b,c){return void 0===b?(a=a.getWritable(),a.__children=c,a):b}function L(a,b,c){b=new O(a,b,c);return a._collabNode=b}
43
+ function la(a,b){b=b.collabNodeMap.get(a.key);if(void 0===b)return null;a=a.offset;let c=b.getSharedType();if(b instanceof E){c=b._parent._xmlText;b=b.getOffset();if(-1===b)return null;a=b+1+a}return r.createRelativePositionFromTypeIndex(c,a)}function ma(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!r.compareRelativePositions(a,b))return!0;return!1}function na(a,b){a=a.cursorsContainer;if(null!==a){b=b.selections;const c=b.length;for(let d=0;d<c;d++)a.removeChild(b[d])}}
44
44
  function oa(a){for(;null!=a;){if(3===a.nodeType)return a;a=a.firstChild}return null}function pa(a){const b=a.parentNode;if(null==b)throw Error("Should never happen");return[b,Array.from(b.childNodes).indexOf(a)]}
45
- function qa(a,b){var c=b.awareness.getLocalState();if(null!==c&&(b=c.anchorPos,c=c.focusPos,null!==b&&null!==c&&(b=m.createAbsolutePositionFromRelativePosition(b,a.doc),a=m.createAbsolutePositionFromRelativePosition(c,a.doc),null!==b&&null!==a))){const [e,f]=Y(b.type,b.index),[g,h]=Y(a.type,a.index);if(null!==e&&null!==g){const n=e.getKey();a=g.getKey();b=v.$getSelection();if(v.$isRangeSelection(b)){var d=b.anchor;c=b.focus;if(d.key!==n||d.offset!==f)d=v.$getNodeByKey(n),b.anchor.set(n,f,v.$isElementNode(d)?
46
- "element":"text");if(c.key!==a||c.offset!==h)c=v.$getNodeByKey(a),b.focus.set(a,h,v.$isElementNode(c)?"element":"text")}}}}function Y(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof M){const {node:c,offset:d}=N(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
47
- function va(a,b){var c=Array.from(b.awareness.getStates()),d=a.clientID;b=a.cursors;var e=a.editor._editorState._nodeMap;const f=new Set;for(var g=0;g<c.length;g++){const [O,Aa]=c[g];if(O!==d){f.add(O);const {anchorPos:ra,focusPos:sa,name:Ba,color:Ca,focusing:Da}=Aa;var h=null,n=b.get(O);void 0===n&&(n={color:Ca,name:Ba,selection:null},b.set(O,n));if(null!==ra&&null!==sa&&Da){var l=m.createAbsolutePositionFromRelativePosition(ra,a.doc),k=m.createAbsolutePositionFromRelativePosition(sa,a.doc);if(null!==
48
- l&&null!==k){const [H,W]=Y(l.type,l.index),[ta,ua]=Y(k.type,k.index);if(null!==H&&null!==ta){k=H.getKey();var r=ta.getKey();h=n.selection;if(null===h){l=n;h=k;k=W;var t=ua,q=l.color,p=document.createElement("span");p.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:rgb(${q});z-index:10;`;var u=document.createElement("span");u.textContent=l.name;u.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:rgb(${q});color:#fff;line-height:12px;height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold`;
49
- p.appendChild(u);h={anchor:{key:h,offset:k},caret:p,color:q,focus:{key:r,offset:t},name:u,range:document.createRange(),selections:[]}}else l=h.anchor,t=h.focus,l.key=k,l.offset=W,t.key=r,t.offset=ua}}}a:{l=a;k=n;p=h;var w=e;q=l.editor;r=q.getRootElement();n=l.cursorsContainer;if(null===n||null===r)break a;h=k.selection;if(null===p){null!==h&&(k.selection=null,na(l,h));break a}else k.selection=p;t=p.range;h=p.caret;k=p.color;l=p.selections;var y=p.anchor,x=p.focus;p=y.key;u=x.key;var A=w.get(p);const H=
50
- w.get(u);w=q.getElementByKey(p);q=q.getElementByKey(u);y=y.offset;x=x.offset;v.$isTextNode(A)&&(w=oa(w));v.$isTextNode(H)&&(q=oa(q));if(void 0!==A&&void 0!==H&&null!==w&&null!==q){"BR"===w.nodeName&&([w,y]=pa(w));"BR"===q.nodeName&&([q,x]=pa(q));A=w.firstChild;w===q&&null!=A&&"BR"===A.nodeName&&0===y&&0===x&&(x=1);try{t.setStart(w,y),t.setEnd(q,x)}catch(W){break a}!t.collapsed||y===x&&p===u||(t.setStart(q,x),t.setEnd(w,y));q=r.getBoundingClientRect();r=getComputedStyle(r);r=parseFloat(r.paddingLeft)+
51
- parseFloat(r.paddingRight);p=Array.from(t.getClientRects());t=p.length;u=l.length;for(A=0;A<t;A++)w=p[A],w.width+r===q.width?(p.splice(A--,1),t--):(y=l[A],void 0===y&&(y=document.createElement("span"),l[A]=y,n.appendChild(y)),y.style.cssText=`position:absolute;top:${w.top}px;left:${w.left}px;height:${w.height}px;width:${w.width}px;background-color:rgba(${k}, 0.3);pointer-events:none;z-index:10;`,A===t-1&&h.parentNode!==y&&y.appendChild(h));for(h=u-1;h>=t;h--)n.removeChild(l[h]),l.pop()}}}}c=Array.from(b.keys());
52
- for(d=0;d<c.length;d++)e=c[d],f.has(e)||(g=b.get(e),void 0!==g&&(g=g.selection,null!==g&&na(a,g),b.delete(e)))}function wa(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:g,name:h,color:n,focusing:l}=e,k=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)v.$isRangeSelection(d)&&(e=la(d.anchor,a),k=la(d.focus,a)),(ma(f,e)||ma(g,k))&&b.setLocalState({anchorPos:e,color:n,focusPos:k,focusing:l,name:h})}}
53
- class xa{constructor(a,b,c=1){this._offsetMap=a;this._firstNode=b;this._blockOffsetSize=c}createSelectionFromOffsets(a,b,c){var d=this._firstNode;if(null===d)return null;var e=Z(d,a,this._blockOffsetSize);let f=Z(d,b,this._blockOffsetSize);void 0!==c&&(a=ya(a,e,c,this,this._blockOffsetSize),e=Z(d,a,this._blockOffsetSize),b=ya(b,f,c,this,this._blockOffsetSize),f=Z(d,b,this._blockOffsetSize));if(null===e||null===f)return null;c=e.key;d=f.key;const g=v.$getNodeByKey(c),h=v.$getNodeByKey(d);if(null===
54
- g||null===h)return null;let n=0,l=0,k="element",r="element";"text"===e.type?(n=a-e.start,k="text",e=g.getNextSibling(),a!==b&&n===g.getTextContentSize()&&v.$isTextNode(e)&&(n=0,c=e.__key)):"inline"===e.type&&(c=g.getParentOrThrow().getKey(),n=b>e.start?e.end:e.start);"text"===f.type?(l=b-f.start,r="text"):"inline"===f.type&&(d=h.getParentOrThrow().getKey(),l=b>f.start?f.end:f.start);a=v.$createRangeSelection();if(null===a)return null;a.anchor.set(c,n,k);a.focus.set(d,l,r);return a}getOffsetsFromSelection(a){var b=
55
- a.anchor,c=a.focus,d=this._offsetMap;const e=b.offset;var f=c.offset;let g=a=-1;if("text"===b.type)b=d.get(b.key),void 0!==b&&(a=b.start+e);else{b=b.getNode().getDescendantByIndex(e);const h=d.get(b.getKey());void 0!==h&&(a=b.getIndexWithinParent()!==e?h.end:h.start)}"text"===c.type?(f=d.get(c.key),void 0!==f&&(g=f.start+c.offset)):(c=c.getNode().getDescendantByIndex(f),d=d.get(c.getKey()),void 0!==d&&(g=c.getIndexWithinParent()!==f?d.end:d.start));return[a,g]}}
56
- function ya(a,b,c,d,e){const f=c._offsetMap;d=d._offsetMap;const g=new Set;let h=a;for(;null!==b;){var n=b.key,l=f.get(n),k=b.end-b.start;g.add(n);void 0===l?h+=k:(n=l.end-l.start,n!==k&&(h+=k-n));k=b.prev;if(null!==k)b=k;else{for(b=b.parent;null!==b;)l=b.prev,null!==l&&(k=l.key,n=f.get(k),l=l.end-l.start,g.add(k),void 0===n?h+=l:(k=n.end-n.start,k!==l&&(h+=l-k))),b=b.parent;break}}c=c._firstNode;if(null!==c){b=Z(c,a,e);for(a=!1;null!==b;){if(!g.has(b.key)){a=!0;break}b=b.parent}if(!a)for(;null!==
57
- b;)a=b.key,g.has(a)||(e=d.get(a),a=b.end-b.start,void 0===e?h-=a:(e=e.end-e.start,a!==e&&(h+=e-a))),b=b.prev}return h}function Z(a,b,c){for(;null!==a;){if(b<a.end+("element"!==a.type||0===c?1:0)){const d=a.child;if(null!==d){a=d;continue}return a}a=a.next;if(null===a)break}return null}
58
- function za(a,b,c,d,e,f){let g=null,h=null;const n=b.length;for(let w=0;w<n;w++){{var l=a;var k=b[w];var r=c,t=d,q=e,p=f,u=t.get(k);void 0===u&&z(3);const y=l.offset;if(v.$isElementNode(u)){const x=u.__children;t=(u=0===x.length)?null:za(l,x,null,t,q,p);if(!l.prevIsBlock||u)l.prevIsBlock=!0,l.offset+=p;r={child:t,end:y,key:k,next:null,parent:r,prev:null,start:y,type:"element"};null!==t&&(t.parent=r);r.end=l.offset;q.set(k,r);k=r}else l.prevIsBlock=!1,p=v.$isTextNode(u),l={child:null,end:l.offset+=
59
- p?u.__text.length:1,key:k,next:null,parent:r,prev:null,start:y,type:p?"text":"inline"},q.set(k,l),k=l}null===h?g=k:(k.prev=h,h.next=k);h=k}return g}function Ea(a,b=1,c){c=(c||a._pendingEditorState||a._editorState)._nodeMap;const d=c.get("root");a=new Map;c=za({offset:0,prevIsBlock:!1},d.__children,null,c,a,b);return new xa(a,c,b)}
60
- function Fa(a,b){var {target:c}=b;const d=L(a,c),e=c._lexicalValue;if(void 0!==e&&d instanceof X)if(c instanceof m.Map)V(a,d,c,e,b.keysChanged);else{if(c instanceof m.Array&&v.isDecoratorArray(e)){b=b.delta;let g=0;for(let h=0;h<b.length;h++){var f=b[h];const n=f.retain,l=f.delete;f=f.insert;if(void 0!==n)g+=n;else if(void 0!==l)R(()=>{e._array.slice(g,g+l).forEach(k=>{(v.isDecoratorArray(k)||v.isDecoratorMap(k))&&k.destroy()});e.splice(g,l)});else if(void 0!==f)ja(a,d,c,e,g);else throw Error("Not supported");
61
- }}}else if(d instanceof M&&b instanceof m.YTextEvent){const {keysChanged:g,childListChanged:h,delta:n}=b;0<g.size&&d.syncPropertiesFromYjs(a,g);h&&(d.applyChildrenYjsDelta(a,n),d.syncChildrenFromYjs(a))}else if(d instanceof D&&b instanceof m.YMapEvent)({keysChanged:c}=b),0<c.size&&d.syncPropertiesAndTextFromYjs(a,c);else if(d instanceof X&&b instanceof m.YXmlEvent)({attributesChanged:c}=b),0<c.size&&d.syncPropertiesFromYjs(a,c);else throw Error("Should never happen");}
62
- exports.createBinding=function(a,b,c,d,e){if(void 0===d||null===d)throw Error("Should never happen");b=d.get("root",m.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 m.UndoManager(b,{trackedOrigins:new Set([a,null])})};
63
- 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=va;
64
- exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,g,h){P(a,()=>{d.read(()=>{if(h.has("collaboration")){if(0<g.size){var n=Array.from(g),l=a.collabNodeMap,k=[];for(let p=0;p<n.length;p++){var r=n[p],t=v.$getNodeByKey(r),q=l.get(r);if(q instanceof D)if(v.$isTextNode(t))k.push([q,t.__text]);else{t=q.getOffset();if(-1===t)continue;const u=q._parent;q._normalized=!0;u._xmlText.delete(t,1);l.delete(r);r=u._children;q=r.indexOf(q);r.splice(q,1)}}for(n=0;n<k.length;n++){const [p,u]=k[n];p._text=u}}}else e.has("root")&&
65
- (k=c._nodeMap,n=v.$getRoot(),l=a.root,l.syncPropertiesFromLexical(a,n,k),l.syncChildrenFromLexical(a,n,k,e,f)),k=v.$getSelection(),wa(a,b,c._selection,k)})})};
66
- exports.syncYjsChangesToLexical=function(a,b,c){const d=a.editor,e=d._editorState;d.update(()=>{var f=d._pendingEditorState;for(var g=0;g<c.length;g++)Fa(a,c[g]);var h=v.$getSelection();if(v.$isRangeSelection(h))if(ca(h)){g=e._selection;if(v.$isRangeSelection(g)){const n=Ea(d,0,e);f=Ea(d,0,f);const [l,k]=n.getOffsetsFromSelection(g);f=f.createSelectionFromOffsets(l,k,n);null!==f?v.$setSelection(f):(qa(a,b),ca(h)&&(h=v.$getRoot(),0===h.getChildrenSize()&&h.append(v.$createParagraphNode()),v.$getRoot().selectEnd()))}wa(a,
67
- b,g,v.$getSelection())}else qa(a,b)},{onUpdate:()=>{va(a,b)},skipTransforms:!0,tag:"collaboration"})};
45
+ function qa(a,b){var c=b.awareness.getLocalState();if(null!==c&&(b=c.anchorPos,c=c.focusPos,null!==b&&null!==c&&(b=r.createAbsolutePositionFromRelativePosition(b,a.doc),a=r.createAbsolutePositionFromRelativePosition(c,a.doc),null!==b&&null!==a))){const [e,f]=Z(b.type,b.index),[g,h]=Z(a.type,a.index);if(null!==e&&null!==g){const p=e.getKey();a=g.getKey();b=k.$getSelection();if(k.$isRangeSelection(b)){var d=b.anchor;c=b.focus;if(d.key!==p||d.offset!==f)d=k.$getNodeByKey(p),b.anchor.set(p,f,k.$isElementNode(d)?
46
+ "element":"text");if(c.key!==a||c.offset!==h)c=k.$getNodeByKey(a),b.focus.set(a,h,k.$isElementNode(c)?"element":"text")}}}}function Z(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof O){const {node:c,offset:d}=P(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
47
+ function va(a,b){var c=Array.from(b.awareness.getStates()),d=a.clientID;b=a.cursors;var e=a.editor._editorState._nodeMap;const f=new Set;for(var g=0;g<c.length;g++){const [N,xa]=c[g];if(N!==d){f.add(N);const {anchorPos:ra,focusPos:sa,name:ya,color:za,focusing:Aa}=xa;var h=null,p=b.get(N);void 0===p&&(p={color:za,name:ya,selection:null},b.set(N,p));if(null!==ra&&null!==sa&&Aa){var q=r.createAbsolutePositionFromRelativePosition(ra,a.doc),l=r.createAbsolutePositionFromRelativePosition(sa,a.doc);if(null!==
48
+ q&&null!==l){const [H,U]=Z(q.type,q.index),[ta,ua]=Z(l.type,l.index);if(null!==H&&null!==ta){l=H.getKey();var t=ta.getKey();h=p.selection;if(null===h){q=p;h=l;l=U;var u=ua,n=q.color,m=document.createElement("span");m.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:rgb(${n});z-index:10;`;var w=document.createElement("span");w.textContent=q.name;w.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:rgb(${n});color:#fff;line-height:12px;height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`;
49
+ m.appendChild(w);h={anchor:{key:h,offset:l},caret:m,color:n,focus:{key:t,offset:u},name:w,range:document.createRange(),selections:[]}}else q=h.anchor,u=h.focus,q.key=l,q.offset=U,u.key=t,u.offset=ua}}}a:{q=a;l=p;m=h;var v=e;n=q.editor;t=n.getRootElement();p=q.cursorsContainer;if(null===p||null===t)break a;h=l.selection;if(null===m){null!==h&&(l.selection=null,na(q,h));break a}else l.selection=m;u=m.range;h=m.caret;l=m.color;q=m.selections;var y=m.anchor,x=m.focus;m=y.key;w=x.key;var A=v.get(m);const H=
50
+ v.get(w);v=n.getElementByKey(m);n=n.getElementByKey(w);y=y.offset;x=x.offset;k.$isTextNode(A)&&(v=oa(v));k.$isTextNode(H)&&(n=oa(n));if(void 0!==A&&void 0!==H&&null!==v&&null!==n){"BR"===v.nodeName&&([v,y]=pa(v));"BR"===n.nodeName&&([n,x]=pa(n));A=v.firstChild;v===n&&null!=A&&"BR"===A.nodeName&&0===y&&0===x&&(x=1);try{u.setStart(v,y),u.setEnd(n,x)}catch(U){break a}!u.collapsed||y===x&&m===w||(u.setStart(n,x),u.setEnd(v,y));n=t.getBoundingClientRect();t=getComputedStyle(t);t=parseFloat(t.paddingLeft)+
51
+ parseFloat(t.paddingRight);m=Array.from(u.getClientRects());u=m.length;w=q.length;for(A=0;A<u;A++)v=m[A],v.width+t===n.width?(m.splice(A--,1),u--):(y=q[A],void 0===y&&(y=document.createElement("span"),q[A]=y,p.appendChild(y)),y.style.cssText=`position:absolute;top:${v.top}px;left:${v.left}px;height:${v.height}px;width:${v.width}px;background-color:rgba(${l}, 0.3);pointer-events:none;z-index:10;`,A===u-1&&h.parentNode!==y&&y.appendChild(h));for(h=w-1;h>=u;h--)p.removeChild(q[h]),q.pop()}}}}c=Array.from(b.keys());
52
+ for(d=0;d<c.length;d++)e=c[d],f.has(e)||(g=b.get(e),void 0!==g&&(g=g.selection,null!==g&&na(a,g),b.delete(e)))}function wa(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:g,name:h,color:p,focusing:q}=e,l=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)k.$isRangeSelection(d)&&(e=la(d.anchor,a),l=la(d.focus,a)),(ma(f,e)||ma(g,l))&&b.setLocalState({anchorPos:e,color:p,focusPos:l,focusing:q,name:h})}}
53
+ function Ba(a,b){var {target:c}=b;const d=M(a,c),e=c._lexicalValue;if(void 0!==e&&d instanceof Y)if(c instanceof r.Map)X(a,d,c,e,b.keysChanged);else{if(c instanceof r.Array&&k.isDecoratorArray(e)){b=b.delta;let g=0;for(let h=0;h<b.length;h++){var f=b[h];const p=f.retain,q=f.delete;f=f.insert;if(void 0!==p)g+=p;else if(void 0!==q)S(()=>{e._array.slice(g,g+q).forEach(l=>{(k.isDecoratorArray(l)||k.isDecoratorMap(l))&&l.destroy()});e.splice(g,q)});else if(void 0!==f)ja(a,d,c,e,g);else throw Error("Not supported");
54
+ }}}else if(d instanceof O&&b instanceof r.YTextEvent){const {keysChanged:g,childListChanged:h,delta:p}=b;0<g.size&&d.syncPropertiesFromYjs(a,g);h&&(d.applyChildrenYjsDelta(a,p),d.syncChildrenFromYjs(a))}else if(d instanceof E&&b instanceof r.YMapEvent)({keysChanged:c}=b),0<c.size&&d.syncPropertiesAndTextFromYjs(a,c);else if(d instanceof Y&&b instanceof r.YXmlEvent)({attributesChanged:c}=b),0<c.size&&d.syncPropertiesFromYjs(a,c);else throw Error("Should never happen");}
55
+ const Ca=k.createCommand(),Da=k.createCommand();exports.CONNECTED_COMMAND=Ca;exports.TOGGLE_CONNECT_COMMAND=Da;exports.createBinding=function(a,b,c,d,e){if(void 0===d||null===d)throw Error("Should never happen");b=d.get("root",r.XmlText);b=L(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}};
56
+ exports.createUndoManager=function(a,b){return new r.UndoManager(b,{trackedOrigins:new Set([a,null])})};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=va;
57
+ exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,g,h){Q(a,()=>{d.read(()=>{if(h.has("collaboration")){if(0<g.size){var p=Array.from(g),q=a.collabNodeMap,l=[];for(let m=0;m<p.length;m++){var t=p[m],u=k.$getNodeByKey(t),n=q.get(t);if(n instanceof E)if(k.$isTextNode(u))l.push([n,u.__text]);else{u=n.getOffset();if(-1===u)continue;const w=n._parent;n._normalized=!0;w._xmlText.delete(u,1);q.delete(t);t=w._children;n=t.indexOf(n);t.splice(n,1)}}for(p=0;p<l.length;p++){const [m,w]=l[p];m._text=w}}}else e.has("root")&&
58
+ (l=c._nodeMap,p=k.$getRoot(),q=a.root,q.syncPropertiesFromLexical(a,p,l),q.syncChildrenFromLexical(a,p,l,e,f)),l=k.$getSelection(),wa(a,b,c._selection,l)})})};
59
+ exports.syncYjsChangesToLexical=function(a,b,c){const d=a.editor,e=d._editorState;d.update(()=>{var f=d._pendingEditorState;for(var g=0;g<c.length;g++)Ba(a,c[g]);var h=k.$getSelection();if(k.$isRangeSelection(h))if(ca(h)){g=e._selection;if(k.$isRangeSelection(g)){const p=z.$createOffsetView(d,0,e);f=z.$createOffsetView(d,0,f);const [q,l]=p.getOffsetsFromSelection(g);f=f.createSelectionFromOffsets(q,l,p);null!==f?k.$setSelection(f):(qa(a,b),ca(h)&&(h=k.$getRoot(),0===h.getChildrenSize()&&h.append(k.$createParagraphNode()),
60
+ k.$getRoot().selectEnd()))}wa(a,b,g,k.$getSelection())}else qa(a,b)},{onUpdate:()=>{va(a,b)},skipTransforms:!0,tag:"collaboration"})};
package/package.json CHANGED
@@ -1,9 +1,5 @@
1
1
  {
2
2
  "name": "@lexical/yjs",
3
- "author": {
4
- "name": "Dominic Gannaway",
5
- "email": "dg@domgan.com"
6
- },
7
3
  "description": "The library provides Yjs editor bindings for Lexical.",
8
4
  "keywords": [
9
5
  "react",
@@ -15,10 +11,13 @@
15
11
  "crdt"
16
12
  ],
17
13
  "license": "MIT",
18
- "version": "0.1.14",
14
+ "version": "0.1.17",
19
15
  "main": "LexicalYjs.js",
16
+ "dependencies": {
17
+ "@lexical/offset": "0.1.17"
18
+ },
20
19
  "peerDependencies": {
21
- "lexical": "0.1.14",
20
+ "lexical": "0.1.17",
22
21
  "yjs": ">=13.5.22"
23
22
  },
24
23
  "repository": {