@lexical/offset 0.35.1-nightly.20250924.0 → 0.36.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/LexicalOffset.dev.js +3 -0
- package/LexicalOffset.dev.mjs +3 -0
- package/LexicalOffset.prod.js +1 -1
- package/LexicalOffset.prod.mjs +1 -1
- package/package.json +2 -2
package/LexicalOffset.dev.js
CHANGED
package/LexicalOffset.dev.mjs
CHANGED
package/LexicalOffset.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("lexical");function t(e,...t){const n=new URL("https://lexical.dev/docs/error"),s=new URLSearchParams;s.append("code",e);for(const e of t)s.append("v",e);throw n.search=s.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class n{constructor(e,t,n=1){this._offsetMap=e,this._firstNode=t,this._blockOffsetSize=n}createSelectionFromOffsets(t,n,r){const l=this._firstNode;if(null===l)return null;let i=t,f=n,c=o(l,i,this._blockOffsetSize),
|
|
9
|
+
"use strict";var e=require("lexical");function t(e,...t){const n=new URL("https://lexical.dev/docs/error"),s=new URLSearchParams;s.append("code",e);for(const e of t)s.append("v",e);throw n.search=s.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class n{_offsetMap;_firstNode;_blockOffsetSize;constructor(e,t,n=1){this._offsetMap=e,this._firstNode=t,this._blockOffsetSize=n}createSelectionFromOffsets(t,n,r){const l=this._firstNode;if(null===l)return null;let i=t,f=n,c=o(l,i,this._blockOffsetSize),a=o(l,f,this._blockOffsetSize);if(void 0!==r&&(i=s(i,c,r,this,this._blockOffsetSize),c=o(l,i,this._blockOffsetSize),f=s(f,a,r,this,this._blockOffsetSize),a=o(l,f,this._blockOffsetSize)),null===c||null===a)return null;let u=c.key,d=a.key;const p=e.$getNodeByKey(u),g=e.$getNodeByKey(d);if(null===p||null===g)return null;let h=0,y=0,_="element",x="element";if("text"===c.type){h=i-c.start,_="text";const t=p.getNextSibling();i!==f&&h===p.getTextContentSize()&&e.$isTextNode(t)&&(h=0,u=t.__key)}else"inline"===c.type&&(u=p.getParentOrThrow().getKey(),h=f>c.start?c.end:c.start);"text"===a.type?(y=f-a.start,x="text"):"inline"===a.type&&(d=g.getParentOrThrow().getKey(),y=f>a.start?a.end:a.start);const k=e.$createRangeSelection();return null===k?null:(k.anchor.set(u,h,_),k.focus.set(d,y,x),k)}getOffsetsFromSelection(e){const t=e.anchor,n=e.focus,s=this._offsetMap,o=t.offset,r=n.offset;let l=-1,i=-1;if("text"===t.type){const e=s.get(t.key);void 0!==e&&(l=e.start+o)}else{const e=t.getNode().getDescendantByIndex(o);if(null!==e){const t=s.get(e.getKey());if(void 0!==t){l=e.getIndexWithinParent()!==o?t.end:t.start}}}if("text"===n.type){const e=s.get(n.key);void 0!==e&&(i=e.start+n.offset)}else{const e=n.getNode().getDescendantByIndex(r);if(null!==e){const t=s.get(e.getKey());if(void 0!==t){i=e.getIndexWithinParent()!==r?t.end:t.start}}}return[l,i]}}function s(e,t,n,s,r){const l=n._offsetMap,i=s._offsetMap,f=new Set;let c=e,a=t;for(;null!==a;){const e=a.key,t=l.get(e),n=a.end-a.start;if(f.add(e),void 0===t)c+=n;else{const e=t.end-t.start;e!==n&&(c+=n-e)}const s=a.prev;if(null!==s){a=s;continue}let o=a.parent;for(;null!==o;){let e=o.prev;if(null!==e){const t=e.key,n=l.get(t),s=e.end-e.start;if(f.add(t),void 0===n)c+=s;else{const e=n.end-n.start;e!==s&&(c+=s-e)}e=e.prev}o=o.parent}break}const u=n._firstNode;if(null!==u){a=o(u,e,r);let t=!1;for(;null!==a;){if(!f.has(a.key)){t=!0;break}a=a.parent}if(!t)for(;null!==a;){const e=a.key;if(!f.has(e)){const t=i.get(e),n=a.end-a.start;if(void 0===t)c-=n;else{const e=t.end-t.start;n!==e&&(c+=e-n)}}a=a.prev}}return c}function o(e,t,n){let s=e;for(;null!==s;){if(t<s.end+("element"!==s.type||0===n?1:0)){const e=s.child;if(null!==e){s=e;continue}return s}const e=s.next;if(null===e)break;s=e}return null}function r(e,t,n,s,o,r){return{child:e,end:s,key:o,next:null,parent:r,prev:null,start:n,type:t}}function l(n,s,o,l,c,a){const u=l.get(s);void 0===u&&t(3);const d=n.offset;if(e.$isElementNode(u)){const e=f(u,l),t=0===e.length,p=t?null:i(n,e,null,l,c,a);n.prevIsBlock&&!t||(n.prevIsBlock=!0,n.offset+=a);const g=r(p,"element",d,d,s,o);null!==p&&(p.parent=g);const h=n.offset;return g.end=h,c.set(s,g),g}n.prevIsBlock=!1;const p=e.$isTextNode(u),g=p?u.__text.length:1,h=r(null,p?"text":"inline",d,n.offset+=g,s,o);return c.set(s,h),h}function i(e,t,n,s,o,r){let i=null,f=null;const c=t.length;for(let a=0;a<c;a++){const c=l(e,t[a],n,s,o,r);null===f?i=c:(c.prev=f,f.next=c),f=c}return i}function f(n,s){const o=[];let r=n.__first;for(;null!==r;){const n=null===s?e.$getNodeByKey(r):s.get(r);null==n&&t(174),o.push(r),r=n.__next}return o}const c=f;exports.$createChildrenArray=f,exports.$createOffsetView=function(e,t=1,s){const o=(s||e._pendingEditorState||e._editorState)._nodeMap,r=o.get("root"),l=new Map,c=i({offset:0,prevIsBlock:!1},f(r,o),null,o,l,t);return new n(l,c,t)},exports.OffsetView=n,exports.createChildrenArray=c;
|
package/LexicalOffset.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$getNodeByKey as t,$isTextNode as e,$createRangeSelection as n,$isElementNode as
|
|
9
|
+
import{$getNodeByKey as t,$isTextNode as e,$createRangeSelection as n,$isElementNode as o}from"lexical";function s(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class l{_offsetMap;_firstNode;_blockOffsetSize;constructor(t,e,n=1){this._offsetMap=t,this._firstNode=e,this._blockOffsetSize=n}createSelectionFromOffsets(o,s,l){const f=this._firstNode;if(null===f)return null;let c=o,u=s,a=i(f,c,this._blockOffsetSize),d=i(f,u,this._blockOffsetSize);if(void 0!==l&&(c=r(c,a,l,this,this._blockOffsetSize),a=i(f,c,this._blockOffsetSize),u=r(u,d,l,this,this._blockOffsetSize),d=i(f,u,this._blockOffsetSize)),null===a||null===d)return null;let p=a.key,g=d.key;const h=t(p),_=t(g);if(null===h||null===_)return null;let k=0,v=0,y="element",x="element";if("text"===a.type){k=c-a.start,y="text";const t=h.getNextSibling();c!==u&&k===h.getTextContentSize()&&e(t)&&(k=0,p=t.__key)}else"inline"===a.type&&(p=h.getParentOrThrow().getKey(),k=u>a.start?a.end:a.start);"text"===d.type?(v=u-d.start,x="text"):"inline"===d.type&&(g=_.getParentOrThrow().getKey(),v=u>d.start?d.end:d.start);const S=n();return null===S?null:(S.anchor.set(p,k,y),S.focus.set(g,v,x),S)}getOffsetsFromSelection(t){const e=t.anchor,n=t.focus,o=this._offsetMap,s=e.offset,l=n.offset;let r=-1,i=-1;if("text"===e.type){const t=o.get(e.key);void 0!==t&&(r=t.start+s)}else{const t=e.getNode().getDescendantByIndex(s);if(null!==t){const e=o.get(t.getKey());if(void 0!==e){r=t.getIndexWithinParent()!==s?e.end:e.start}}}if("text"===n.type){const t=o.get(n.key);void 0!==t&&(i=t.start+n.offset)}else{const t=n.getNode().getDescendantByIndex(l);if(null!==t){const e=o.get(t.getKey());if(void 0!==e){i=t.getIndexWithinParent()!==l?e.end:e.start}}}return[r,i]}}function r(t,e,n,o,s){const l=n._offsetMap,r=o._offsetMap,f=new Set;let c=t,u=e;for(;null!==u;){const t=u.key,e=l.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 o=u.prev;if(null!==o){u=o;continue}let s=u.parent;for(;null!==s;){let t=s.prev;if(null!==t){const e=t.key,n=l.get(e),o=t.end-t.start;if(f.add(e),void 0===n)c+=o;else{const t=n.end-n.start;t!==o&&(c+=o-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 o=t;for(;null!==o;){if(e<o.end+("element"!==o.type||0===n?1:0)){const t=o.child;if(null!==t){o=t;continue}return o}const t=o.next;if(null===t)break;o=t}return null}function f(t,e,n,o,s,l){return{child:t,end:o,key:s,next:null,parent:l,prev:null,start:n,type:e}}function c(t,n,l,r,i,c){const d=r.get(n);void 0===d&&s(3);const p=t.offset;if(o(d)){const e=a(d,r),o=0===e.length,s=o?null:u(t,e,null,r,i,c);t.prevIsBlock&&!o||(t.prevIsBlock=!0,t.offset+=c);const g=f(s,"element",p,p,n,l);null!==s&&(s.parent=g);const h=t.offset;return g.end=h,i.set(n,g),g}t.prevIsBlock=!1;const g=e(d),h=g?d.__text.length:1,_=f(null,g?"text":"inline",p,t.offset+=h,n,l);return i.set(n,_),_}function u(t,e,n,o,s,l){let r=null,i=null;const f=e.length;for(let u=0;u<f;u++){const f=c(t,e[u],n,o,s,l);null===i?r=f:(f.prev=i,i.next=f),i=f}return r}function a(e,n){const o=[];let l=e.__first;for(;null!==l;){const e=null===n?t(l):n.get(l);null==e&&s(174),o.push(l),l=e.__next}return o}const d=a;function p(t,e=1,n){const o=(n||t._pendingEditorState||t._editorState)._nodeMap,s=o.get("root"),r=new Map,i=u({offset:0,prevIsBlock:!1},a(s,o),null,o,r,e);return new l(r,i,e)}export{a as $createChildrenArray,p as $createOffsetView,l as OffsetView,d as createChildrenArray};
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"offset"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.36.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.
|
|
39
|
+
"lexical": "0.36.0"
|
|
40
40
|
}
|
|
41
41
|
}
|