@lexical/offset 0.14.5 → 0.15.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.
@@ -3,7 +3,9 @@
3
3
  *
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
  */
8
+
7
9
  'use strict';
8
10
 
9
11
  var lexical = require('lexical');
@@ -15,6 +17,7 @@ var lexical = require('lexical');
15
17
  * LICENSE file in the root directory of this source tree.
16
18
  *
17
19
  */
20
+
18
21
  class OffsetView {
19
22
  constructor(offsetMap, firstNode, blockOffsetSize = 1) {
20
23
  this._offsetMap = offsetMap;
@@ -244,7 +247,7 @@ function $createOffsetNode(state, key, parent, nodeMap, offsetMap, blockOffsetSi
244
247
  }
245
248
  const start = state.offset;
246
249
  if (lexical.$isElementNode(node)) {
247
- const childKeys = createChildrenArray(node, nodeMap);
250
+ const childKeys = $createChildrenArray(node, nodeMap);
248
251
  const blockIsEmpty = childKeys.length === 0;
249
252
  const child = blockIsEmpty ? null : $createOffsetChild(state, childKeys, null, nodeMap, offsetMap, blockOffsetSize);
250
253
 
@@ -288,14 +291,14 @@ function $createOffsetChild(state, children, parent, nodeMap, offsetMap, blockOf
288
291
  }
289
292
  return firstNode;
290
293
  }
291
- function createChildrenArray(element, nodeMap) {
294
+ function $createChildrenArray(element, nodeMap) {
292
295
  const children = [];
293
296
  let nodeKey = element.__first;
294
297
  while (nodeKey !== null) {
295
298
  const node = nodeMap === null ? lexical.$getNodeByKey(nodeKey) : nodeMap.get(nodeKey);
296
299
  if (node === null || node === undefined) {
297
300
  {
298
- throw Error(`createChildrenArray: node does not exist in nodeMap`);
301
+ throw Error(`$createChildrenArray: node does not exist in nodeMap`);
299
302
  }
300
303
  }
301
304
  children.push(nodeKey);
@@ -303,6 +306,8 @@ function createChildrenArray(element, nodeMap) {
303
306
  }
304
307
  return children;
305
308
  }
309
+ /** @deprecated renamed to {@link $createChildrenArray} by @lexical/eslint-plugin rules-of-lexical */
310
+ const createChildrenArray = $createChildrenArray;
306
311
  function $createOffsetView(editor, blockOffsetSize = 1, editorState) {
307
312
  const targetEditorState = editorState || editor._pendingEditorState || editor._editorState;
308
313
  const nodeMap = targetEditorState._nodeMap;
@@ -312,10 +317,11 @@ function $createOffsetView(editor, blockOffsetSize = 1, editorState) {
312
317
  offset: 0,
313
318
  prevIsBlock: false
314
319
  };
315
- const node = $createOffsetChild(state, createChildrenArray(root, nodeMap), null, nodeMap, offsetMap, blockOffsetSize);
320
+ const node = $createOffsetChild(state, $createChildrenArray(root, nodeMap), null, nodeMap, offsetMap, blockOffsetSize);
316
321
  return new OffsetView(offsetMap, node, blockOffsetSize);
317
322
  }
318
323
 
324
+ exports.$createChildrenArray = $createChildrenArray;
319
325
  exports.$createOffsetView = $createOffsetView;
320
326
  exports.OffsetView = OffsetView;
321
327
  exports.createChildrenArray = createChildrenArray;
@@ -3,7 +3,9 @@
3
3
  *
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
  */
8
+
7
9
  import { $getNodeByKey, $isTextNode, $createRangeSelection, $isElementNode } from 'lexical';
8
10
 
9
11
  /**
@@ -13,6 +15,7 @@ import { $getNodeByKey, $isTextNode, $createRangeSelection, $isElementNode } fro
13
15
  * LICENSE file in the root directory of this source tree.
14
16
  *
15
17
  */
18
+
16
19
  class OffsetView {
17
20
  constructor(offsetMap, firstNode, blockOffsetSize = 1) {
18
21
  this._offsetMap = offsetMap;
@@ -242,7 +245,7 @@ function $createOffsetNode(state, key, parent, nodeMap, offsetMap, blockOffsetSi
242
245
  }
243
246
  const start = state.offset;
244
247
  if ($isElementNode(node)) {
245
- const childKeys = createChildrenArray(node, nodeMap);
248
+ const childKeys = $createChildrenArray(node, nodeMap);
246
249
  const blockIsEmpty = childKeys.length === 0;
247
250
  const child = blockIsEmpty ? null : $createOffsetChild(state, childKeys, null, nodeMap, offsetMap, blockOffsetSize);
248
251
 
@@ -286,14 +289,14 @@ function $createOffsetChild(state, children, parent, nodeMap, offsetMap, blockOf
286
289
  }
287
290
  return firstNode;
288
291
  }
289
- function createChildrenArray(element, nodeMap) {
292
+ function $createChildrenArray(element, nodeMap) {
290
293
  const children = [];
291
294
  let nodeKey = element.__first;
292
295
  while (nodeKey !== null) {
293
296
  const node = nodeMap === null ? $getNodeByKey(nodeKey) : nodeMap.get(nodeKey);
294
297
  if (node === null || node === undefined) {
295
298
  {
296
- throw Error(`createChildrenArray: node does not exist in nodeMap`);
299
+ throw Error(`$createChildrenArray: node does not exist in nodeMap`);
297
300
  }
298
301
  }
299
302
  children.push(nodeKey);
@@ -301,6 +304,8 @@ function createChildrenArray(element, nodeMap) {
301
304
  }
302
305
  return children;
303
306
  }
307
+ /** @deprecated renamed to {@link $createChildrenArray} by @lexical/eslint-plugin rules-of-lexical */
308
+ const createChildrenArray = $createChildrenArray;
304
309
  function $createOffsetView(editor, blockOffsetSize = 1, editorState) {
305
310
  const targetEditorState = editorState || editor._pendingEditorState || editor._editorState;
306
311
  const nodeMap = targetEditorState._nodeMap;
@@ -310,8 +315,8 @@ function $createOffsetView(editor, blockOffsetSize = 1, editorState) {
310
315
  offset: 0,
311
316
  prevIsBlock: false
312
317
  };
313
- const node = $createOffsetChild(state, createChildrenArray(root, nodeMap), null, nodeMap, offsetMap, blockOffsetSize);
318
+ const node = $createOffsetChild(state, $createChildrenArray(root, nodeMap), null, nodeMap, offsetMap, blockOffsetSize);
314
319
  return new OffsetView(offsetMap, node, blockOffsetSize);
315
320
  }
316
321
 
317
- export { $createOffsetView, OffsetView, createChildrenArray };
322
+ export { $createChildrenArray, $createOffsetView, OffsetView, createChildrenArray };
package/LexicalOffset.js CHANGED
@@ -3,7 +3,9 @@
3
3
  *
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
  */
8
+
7
9
  'use strict'
8
10
  const LexicalOffset = process.env.NODE_ENV === 'development' ? require('./LexicalOffset.dev.js') : require('./LexicalOffset.prod.js');
9
11
  module.exports = LexicalOffset;
package/LexicalOffset.mjs CHANGED
@@ -3,10 +3,13 @@
3
3
  *
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
  */
8
+
7
9
  import * as modDev from './LexicalOffset.dev.mjs';
8
10
  import * as modProd from './LexicalOffset.prod.mjs';
9
11
  const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
12
+ export const $createChildrenArray = mod.$createChildrenArray;
10
13
  export const $createOffsetView = mod.$createOffsetView;
11
14
  export const OffsetView = mod.OffsetView;
12
15
  export const createChildrenArray = mod.createChildrenArray;
@@ -3,8 +3,11 @@
3
3
  *
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
  */
8
+
7
9
  const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalOffset.dev.mjs') : import('./LexicalOffset.prod.mjs'));
10
+ export const $createChildrenArray = mod.$createChildrenArray;
8
11
  export const $createOffsetView = mod.$createOffsetView;
9
12
  export const OffsetView = mod.OffsetView;
10
13
  export const createChildrenArray = mod.createChildrenArray;
@@ -3,13 +3,15 @@
3
3
  *
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
  */
7
- 'use strict';var p=require("lexical");function t(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.");}
8
- class y{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 f=z(d,a,this._blockOffsetSize);let h=z(d,b,this._blockOffsetSize);void 0!==c&&(a=A(a,f,c,this,this._blockOffsetSize),f=z(d,a,this._blockOffsetSize),b=A(b,h,c,this,this._blockOffsetSize),h=z(d,b,this._blockOffsetSize));if(null===f||null===h)return null;c=f.key;d=h.key;let m=p.$getNodeByKey(c),k=p.$getNodeByKey(d);if(null===m||null===
8
+
9
+ 'use strict';var p=require("lexical"),t;function u(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.");}t=u&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u["default"]:u;
10
+ class w{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 f=x(d,a,this._blockOffsetSize);let h=x(d,b,this._blockOffsetSize);void 0!==c&&(a=B(a,f,c,this,this._blockOffsetSize),f=x(d,a,this._blockOffsetSize),b=B(b,h,c,this,this._blockOffsetSize),h=x(d,b,this._blockOffsetSize));if(null===f||null===h)return null;c=f.key;d=h.key;let m=p.$getNodeByKey(c),k=p.$getNodeByKey(d);if(null===m||null===
9
11
  k)return null;let l=0,e=0,g="element",n="element";"text"===f.type?(l=a-f.start,g="text",f=m.getNextSibling(),a!==b&&l===m.getTextContentSize()&&p.$isTextNode(f)&&(l=0,c=f.__key)):"inline"===f.type&&(c=m.getParentOrThrow().getKey(),l=b>f.start?f.end:f.start);"text"===h.type?(e=b-h.start,n="text"):"inline"===h.type&&(d=k.getParentOrThrow().getKey(),e=b>h.start?h.end:h.start);a=p.$createRangeSelection();if(null===a)return null;a.anchor.set(c,l,g);a.focus.set(d,e,n);return a}getOffsetsFromSelection(a){var b=
10
12
  a.anchor,c=a.focus,d=this._offsetMap;let f=b.offset;var h=c.offset;let m=a=-1;if("text"===b.type)b=d.get(b.key),void 0!==b&&(a=b.start+f);else if(b=b.getNode().getDescendantByIndex(f),null!==b){let k=d.get(b.getKey());void 0!==k&&(a=b.getIndexWithinParent()!==f?k.end:k.start)}"text"===c.type?(h=d.get(c.key),void 0!==h&&(m=h.start+c.offset)):(c=c.getNode().getDescendantByIndex(h),null!==c&&(d=d.get(c.getKey()),void 0!==d&&(m=c.getIndexWithinParent()!==h?d.end:d.start)));return[a,m]}}
11
- function A(a,b,c,d,f){let h=c._offsetMap;d=d._offsetMap;let m=new Set,k=a;for(;null!==b;){var l=b.key,e=h.get(l),g=b.end-b.start;m.add(l);void 0===e?k+=g:(l=e.end-e.start,l!==g&&(k+=g-l));g=b.prev;if(null!==g)b=g;else{for(b=b.parent;null!==b;)e=b.prev,null!==e&&(g=e.key,l=h.get(g),e=e.end-e.start,m.add(g),void 0===l?k+=e:(g=l.end-l.start,g!==e&&(k+=e-g))),b=b.parent;break}}c=c._firstNode;if(null!==c){b=z(c,a,f);for(a=!1;null!==b;){if(!m.has(b.key)){a=!0;break}b=b.parent}if(!a)for(;null!==b;)a=b.key,
12
- m.has(a)||(f=d.get(a),a=b.end-b.start,void 0===f?k-=a:(f=f.end-f.start,a!==f&&(k+=f-a))),b=b.prev}return k}function z(a,b,c){for(;null!==a;){if(b<a.end+("element"!==a.type||0===c?1:0)){let d=a.child;if(null!==d){a=d;continue}return a}a=a.next;if(null===a)break}return null}
13
- function B(a,b,c,d,f,h){let m=null,k=null,l=b.length;for(let v=0;v<l;v++){{var e=a;var g=b[v];var n=c,q=d,w=f,u=h,r=q.get(g);void 0===r&&t(3);let x=e.offset;if(p.$isElementNode(r)){let D=C(r,q);q=(r=0===D.length)?null:B(e,D,null,q,w,u);if(!e.prevIsBlock||r)e.prevIsBlock=!0,e.offset+=u;n={child:q,end:x,key:g,next:null,parent:n,prev:null,start:x,type:"element"};null!==q&&(q.parent=n);n.end=e.offset;w.set(g,n);g=n}else e.prevIsBlock=!1,u=p.$isTextNode(r),e={child:null,end:e.offset+=u?r.__text.length:
14
- 1,key:g,next:null,parent:n,prev:null,start:x,type:u?"text":"inline"},w.set(g,e),g=e}null===k?m=g:(g.prev=k,k.next=g);k=g}return m}function C(a,b){let c=[];for(a=a.__first;null!==a;){let d=null===b?p.$getNodeByKey(a):b.get(a);null!==d&&void 0!==d||t(101);c.push(a);a=d.__next}return c}exports.$createOffsetView=function(a,b=1,c){c=(c||a._pendingEditorState||a._editorState)._nodeMap;let d=c.get("root");a=new Map;c=B({offset:0,prevIsBlock:!1},C(d,c),null,c,a,b);return new y(a,c,b)};
15
- exports.OffsetView=y;exports.createChildrenArray=C
13
+ function B(a,b,c,d,f){let h=c._offsetMap;d=d._offsetMap;let m=new Set,k=a;for(;null!==b;){var l=b.key,e=h.get(l),g=b.end-b.start;m.add(l);void 0===e?k+=g:(l=e.end-e.start,l!==g&&(k+=g-l));g=b.prev;if(null!==g)b=g;else{for(b=b.parent;null!==b;)e=b.prev,null!==e&&(g=e.key,l=h.get(g),e=e.end-e.start,m.add(g),void 0===l?k+=e:(g=l.end-l.start,g!==e&&(k+=e-g))),b=b.parent;break}}c=c._firstNode;if(null!==c){b=x(c,a,f);for(a=!1;null!==b;){if(!m.has(b.key)){a=!0;break}b=b.parent}if(!a)for(;null!==b;)a=b.key,
14
+ m.has(a)||(f=d.get(a),a=b.end-b.start,void 0===f?k-=a:(f=f.end-f.start,a!==f&&(k+=f-a))),b=b.prev}return k}function x(a,b,c){for(;null!==a;){if(b<a.end+("element"!==a.type||0===c?1:0)){let d=a.child;if(null!==d){a=d;continue}return a}a=a.next;if(null===a)break}return null}
15
+ function C(a,b,c,d,f,h){let m=null,k=null,l=b.length;for(let y=0;y<l;y++){{var e=a;var g=b[y];var n=c,q=d,z=f,v=h,r=q.get(g);void 0===r&&t(3);let A=e.offset;if(p.$isElementNode(r)){let E=D(r,q);q=(r=0===E.length)?null:C(e,E,null,q,z,v);if(!e.prevIsBlock||r)e.prevIsBlock=!0,e.offset+=v;n={child:q,end:A,key:g,next:null,parent:n,prev:null,start:A,type:"element"};null!==q&&(q.parent=n);n.end=e.offset;z.set(g,n);g=n}else e.prevIsBlock=!1,v=p.$isTextNode(r),e={child:null,end:e.offset+=v?r.__text.length:
16
+ 1,key:g,next:null,parent:n,prev:null,start:A,type:v?"text":"inline"},z.set(g,e),g=e}null===k?m=g:(g.prev=k,k.next=g);k=g}return m}function D(a,b){let c=[];for(a=a.__first;null!==a;){let d=null===b?p.$getNodeByKey(a):b.get(a);null!==d&&void 0!==d||t(174);c.push(a);a=d.__next}return c}let F=D;exports.$createChildrenArray=D;
17
+ exports.$createOffsetView=function(a,b=1,c){c=(c||a._pendingEditorState||a._editorState)._nodeMap;let d=c.get("root");a=new Map;c=C({offset:0,prevIsBlock:!1},D(d,c),null,c,a,b);return new w(a,c,b)};exports.OffsetView=w;exports.createChildrenArray=F
@@ -3,5 +3,7 @@
3
3
  *
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
  */
7
- import{$getNodeByKey as t,$isTextNode as e,$createRangeSelection as n,$isElementNode as l}from"lexical";var s=function(t){const e=new URLSearchParams;e.append("code",t);for(let t=1;t<arguments.length;t++)e.append("v",arguments[t]);throw Error(`Minified Lexical error #${t}; visit https://lexical.dev/docs/error?${e} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)};class o{constructor(t,e,n=1){this._offsetMap=t,this._firstNode=e,this._blockOffsetSize=n}createSelectionFromOffsets(l,s,o){const f=this._firstNode;if(null===f)return null;let c=l,u=s,a=i(f,c,this._blockOffsetSize),d=i(f,u,this._blockOffsetSize);if(void 0!==o&&(c=r(c,a,o,this,this._blockOffsetSize),a=i(f,c,this._blockOffsetSize),u=r(u,d,o,this,this._blockOffsetSize),d=i(f,u,this._blockOffsetSize)),null===a||null===d)return null;let p=a.key,h=d.key;const g=t(p),v=t(h);if(null===g||null===v)return null;let _=0,k=0,y="element",x="element";if("text"===a.type){_=c-a.start,y="text";const t=g.getNextSibling();c!==u&&_===g.getTextContentSize()&&e(t)&&(_=0,p=t.__key)}else"inline"===a.type&&(p=g.getParentOrThrow().getKey(),_=u>a.start?a.end:a.start);"text"===d.type?(k=u-d.start,x="text"):"inline"===d.type&&(h=v.getParentOrThrow().getKey(),k=u>d.start?d.end:d.start);const S=n();return null===S?null:(S.anchor.set(p,_,y),S.focus.set(h,k,x),S)}getOffsetsFromSelection(t){const e=t.anchor,n=t.focus,l=this._offsetMap,s=e.offset,o=n.offset;let r=-1,i=-1;if("text"===e.type){const t=l.get(e.key);void 0!==t&&(r=t.start+s)}else{const t=e.getNode().getDescendantByIndex(s);if(null!==t){const e=l.get(t.getKey());if(void 0!==e){r=t.getIndexWithinParent()!==s?e.end:e.start}}}if("text"===n.type){const t=l.get(n.key);void 0!==t&&(i=t.start+n.offset)}else{const t=n.getNode().getDescendantByIndex(o);if(null!==t){const e=l.get(t.getKey());if(void 0!==e){i=t.getIndexWithinParent()!==o?e.end:e.start}}}return[r,i]}}function r(t,e,n,l,s){const o=n._offsetMap,r=l._offsetMap,f=new Set;let c=t,u=e;for(;null!==u;){const t=u.key,e=o.get(t),n=u.end-u.start;if(f.add(t),void 0===e)c+=n;else{const t=e.end-e.start;t!==n&&(c+=n-t)}const l=u.prev;if(null!==l){u=l;continue}let s=u.parent;for(;null!==s;){let t=s.prev;if(null!==t){const e=t.key,n=o.get(e),l=t.end-t.start;if(f.add(e),void 0===n)c+=l;else{const t=n.end-n.start;t!==l&&(c+=l-t)}t=t.prev}s=s.parent}break}const a=n._firstNode;if(null!==a){u=i(a,t,s);let e=!1;for(;null!==u;){if(!f.has(u.key)){e=!0;break}u=u.parent}if(!e)for(;null!==u;){const t=u.key;if(!f.has(t)){const e=r.get(t),n=u.end-u.start;if(void 0===e)c-=n;else{const t=e.end-e.start;n!==t&&(c+=t-n)}}u=u.prev}}return c}function i(t,e,n){let l=t;for(;null!==l;){if(e<l.end+("element"!==l.type||0===n?1:0)){const t=l.child;if(null!==t){l=t;continue}return l}const t=l.next;if(null===t)break;l=t}return null}function f(t,e,n,l,s,o){return{child:t,end:l,key:s,next:null,parent:o,prev:null,start:n,type:e}}function c(t,n,o,r,i,c){const d=r.get(n);void 0===d&&s(3);const p=t.offset;if(l(d)){const e=a(d,r),l=0===e.length,s=l?null:u(t,e,null,r,i,c);t.prevIsBlock&&!l||(t.prevIsBlock=!0,t.offset+=c);const h=f(s,"element",p,p,n,o);null!==s&&(s.parent=h);const g=t.offset;return h.end=g,i.set(n,h),h}t.prevIsBlock=!1;const h=e(d),g=h?d.__text.length:1,v=f(null,h?"text":"inline",p,t.offset+=g,n,o);return i.set(n,v),v}function u(t,e,n,l,s,o){let r=null,i=null;const f=e.length;for(let u=0;u<f;u++){const f=c(t,e[u],n,l,s,o);null===i?r=f:(f.prev=i,i.next=f),i=f}return r}function a(e,n){const l=[];let o=e.__first;for(;null!==o;){const e=null===n?t(o):n.get(o);null==e&&s(101),l.push(o),o=e.__next}return l}function d(t,e=1,n){const l=(n||t._pendingEditorState||t._editorState)._nodeMap,s=l.get("root"),r=new Map,i=u({offset:0,prevIsBlock:!1},a(s,l),null,l,r,e);return new o(r,i,e)}export{d as $createOffsetView,o as OffsetView,a as createChildrenArray};
8
+
9
+ import{$getNodeByKey as t,$isTextNode as e,$createRangeSelection as n,$isElementNode as l}from"lexical";function o(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var s=o((function(t){const e=new URLSearchParams;e.append("code",t);for(let t=1;t<arguments.length;t++)e.append("v",arguments[t]);throw Error(`Minified Lexical error #${t}; visit https://lexical.dev/docs/error?${e} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));class r{constructor(t,e,n=1){this._offsetMap=t,this._firstNode=e,this._blockOffsetSize=n}createSelectionFromOffsets(l,o,s){const r=this._firstNode;if(null===r)return null;let c=l,u=o,a=f(r,c,this._blockOffsetSize),d=f(r,u,this._blockOffsetSize);if(void 0!==s&&(c=i(c,a,s,this,this._blockOffsetSize),a=f(r,c,this._blockOffsetSize),u=i(u,d,s,this,this._blockOffsetSize),d=f(r,u,this._blockOffsetSize)),null===a||null===d)return null;let p=a.key,h=d.key;const g=t(p),_=t(h);if(null===g||null===_)return null;let y=0,v=0,k="element",x="element";if("text"===a.type){y=c-a.start,k="text";const t=g.getNextSibling();c!==u&&y===g.getTextContentSize()&&e(t)&&(y=0,p=t.__key)}else"inline"===a.type&&(p=g.getParentOrThrow().getKey(),y=u>a.start?a.end:a.start);"text"===d.type?(v=u-d.start,x="text"):"inline"===d.type&&(h=_.getParentOrThrow().getKey(),v=u>d.start?d.end:d.start);const S=n();return null===S?null:(S.anchor.set(p,y,k),S.focus.set(h,v,x),S)}getOffsetsFromSelection(t){const e=t.anchor,n=t.focus,l=this._offsetMap,o=e.offset,s=n.offset;let r=-1,i=-1;if("text"===e.type){const t=l.get(e.key);void 0!==t&&(r=t.start+o)}else{const t=e.getNode().getDescendantByIndex(o);if(null!==t){const e=l.get(t.getKey());if(void 0!==e){r=t.getIndexWithinParent()!==o?e.end:e.start}}}if("text"===n.type){const t=l.get(n.key);void 0!==t&&(i=t.start+n.offset)}else{const t=n.getNode().getDescendantByIndex(s);if(null!==t){const e=l.get(t.getKey());if(void 0!==e){i=t.getIndexWithinParent()!==s?e.end:e.start}}}return[r,i]}}function i(t,e,n,l,o){const s=n._offsetMap,r=l._offsetMap,i=new Set;let c=t,u=e;for(;null!==u;){const t=u.key,e=s.get(t),n=u.end-u.start;if(i.add(t),void 0===e)c+=n;else{const t=e.end-e.start;t!==n&&(c+=n-t)}const l=u.prev;if(null!==l){u=l;continue}let o=u.parent;for(;null!==o;){let t=o.prev;if(null!==t){const e=t.key,n=s.get(e),l=t.end-t.start;if(i.add(e),void 0===n)c+=l;else{const t=n.end-n.start;t!==l&&(c+=l-t)}t=t.prev}o=o.parent}break}const a=n._firstNode;if(null!==a){u=f(a,t,o);let e=!1;for(;null!==u;){if(!i.has(u.key)){e=!0;break}u=u.parent}if(!e)for(;null!==u;){const t=u.key;if(!i.has(t)){const e=r.get(t),n=u.end-u.start;if(void 0===e)c-=n;else{const t=e.end-e.start;n!==t&&(c+=t-n)}}u=u.prev}}return c}function f(t,e,n){let l=t;for(;null!==l;){if(e<l.end+("element"!==l.type||0===n?1:0)){const t=l.child;if(null!==t){l=t;continue}return l}const t=l.next;if(null===t)break;l=t}return null}function c(t,e,n,l,o,s){return{child:t,end:l,key:o,next:null,parent:s,prev:null,start:n,type:e}}function u(t,n,o,r,i,f){const u=r.get(n);void 0===u&&s(3);const p=t.offset;if(l(u)){const e=d(u,r),l=0===e.length,s=l?null:a(t,e,null,r,i,f);t.prevIsBlock&&!l||(t.prevIsBlock=!0,t.offset+=f);const h=c(s,"element",p,p,n,o);null!==s&&(s.parent=h);const g=t.offset;return h.end=g,i.set(n,h),h}t.prevIsBlock=!1;const h=e(u),g=h?u.__text.length:1,_=c(null,h?"text":"inline",p,t.offset+=g,n,o);return i.set(n,_),_}function a(t,e,n,l,o,s){let r=null,i=null;const f=e.length;for(let c=0;c<f;c++){const f=u(t,e[c],n,l,o,s);null===i?r=f:(f.prev=i,i.next=f),i=f}return r}function d(e,n){const l=[];let o=e.__first;for(;null!==o;){const e=null===n?t(o):n.get(o);null==e&&s(174),l.push(o),o=e.__next}return l}const p=d;function h(t,e=1,n){const l=(n||t._pendingEditorState||t._editorState)._nodeMap,o=l.get("root"),s=new Map,i=a({offset:0,prevIsBlock:!1},d(o,l),null,l,s,e);return new r(s,i,e)}export{d as $createChildrenArray,h as $createOffsetView,r as OffsetView,p as createChildrenArray};
package/index.d.ts CHANGED
@@ -46,6 +46,8 @@ export declare class OffsetView {
46
46
  createSelectionFromOffsets(originalStart: number, originalEnd: number, diffOffsetView?: OffsetView): null | RangeSelection;
47
47
  getOffsetsFromSelection(selection: RangeSelection): [number, number];
48
48
  }
49
- export declare function createChildrenArray(element: ElementNode, nodeMap: null | NodeMap): Array<NodeKey>;
49
+ export declare function $createChildrenArray(element: ElementNode, nodeMap: null | NodeMap): Array<NodeKey>;
50
+ /** @deprecated renamed to {@link $createChildrenArray} by @lexical/eslint-plugin rules-of-lexical */
51
+ export declare const createChildrenArray: typeof $createChildrenArray;
50
52
  export declare function $createOffsetView(editor: LexicalEditor, blockOffsetSize?: number, editorState?: EditorState | null): OffsetView;
51
53
  export {};
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "offset"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.14.5",
11
+ "version": "0.15.0",
12
12
  "main": "LexicalOffset.js",
13
13
  "types": "index.d.ts",
14
14
  "repository": {
@@ -36,6 +36,6 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
- "lexical": "0.14.5"
39
+ "lexical": "0.15.0"
40
40
  }
41
41
  }