@lexical/offset
Advanced tools
Comparing version 0.23.2-nightly.20250114.0 to 0.23.2-nightly.20250115.0
@@ -9,10 +9,2 @@ /** | ||
'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; | ||
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=== | ||
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= | ||
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]}} | ||
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, | ||
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} | ||
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: | ||
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; | ||
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 | ||
"use strict";var e=require("lexical");function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n=t((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));class l{constructor(e,t,n=1){this._offsetMap=e,this._firstNode=t,this._blockOffsetSize=n}createSelectionFromOffsets(t,n,l){const r=this._firstNode;if(null===r)return null;let i=t,f=n,c=o(r,i,this._blockOffsetSize),u=o(r,f,this._blockOffsetSize);if(void 0!==l&&(i=s(i,c,l,this,this._blockOffsetSize),c=o(r,i,this._blockOffsetSize),f=s(f,u,l,this,this._blockOffsetSize),u=o(r,f,this._blockOffsetSize)),null===c||null===u)return null;let a=c.key,d=u.key;const p=e.$getNodeByKey(a),g=e.$getNodeByKey(d);if(null===p||null===g)return null;let h=0,y=0,x="element",_="element";if("text"===c.type){h=i-c.start,x="text";const t=p.getNextSibling();i!==f&&h===p.getTextContentSize()&&e.$isTextNode(t)&&(h=0,a=t.__key)}else"inline"===c.type&&(a=p.getParentOrThrow().getKey(),h=f>c.start?c.end:c.start);"text"===u.type?(y=f-u.start,_="text"):"inline"===u.type&&(d=g.getParentOrThrow().getKey(),y=f>u.start?u.end:u.start);const v=e.$createRangeSelection();return null===v?null:(v.anchor.set(a,h,x),v.focus.set(d,y,_),v)}getOffsetsFromSelection(e){const t=e.anchor,n=e.focus,l=this._offsetMap,s=t.offset,o=n.offset;let r=-1,i=-1;if("text"===t.type){const e=l.get(t.key);void 0!==e&&(r=e.start+s)}else{const e=t.getNode().getDescendantByIndex(s);if(null!==e){const t=l.get(e.getKey());if(void 0!==t){r=e.getIndexWithinParent()!==s?t.end:t.start}}}if("text"===n.type){const e=l.get(n.key);void 0!==e&&(i=e.start+n.offset)}else{const e=n.getNode().getDescendantByIndex(o);if(null!==e){const t=l.get(e.getKey());if(void 0!==t){i=e.getIndexWithinParent()!==o?t.end:t.start}}}return[r,i]}}function s(e,t,n,l,s){const r=n._offsetMap,i=l._offsetMap,f=new Set;let c=e,u=t;for(;null!==u;){const e=u.key,t=r.get(e),n=u.end-u.start;if(f.add(e),void 0===t)c+=n;else{const e=t.end-t.start;e!==n&&(c+=n-e)}const l=u.prev;if(null!==l){u=l;continue}let s=u.parent;for(;null!==s;){let e=s.prev;if(null!==e){const t=e.key,n=r.get(t),l=e.end-e.start;if(f.add(t),void 0===n)c+=l;else{const e=n.end-n.start;e!==l&&(c+=l-e)}e=e.prev}s=s.parent}break}const a=n._firstNode;if(null!==a){u=o(a,e,s);let t=!1;for(;null!==u;){if(!f.has(u.key)){t=!0;break}u=u.parent}if(!t)for(;null!==u;){const e=u.key;if(!f.has(e)){const t=i.get(e),n=u.end-u.start;if(void 0===t)c-=n;else{const e=t.end-t.start;n!==e&&(c+=e-n)}}u=u.prev}}return c}function o(e,t,n){let l=e;for(;null!==l;){if(t<l.end+("element"!==l.type||0===n?1:0)){const e=l.child;if(null!==e){l=e;continue}return l}const e=l.next;if(null===e)break;l=e}return null}function r(e,t,n,l,s,o){return{child:e,end:l,key:s,next:null,parent:o,prev:null,start:n,type:t}}function i(t,l,s,o,i,u){const a=o.get(l);void 0===a&&n(3);const d=t.offset;if(e.$isElementNode(a)){const e=c(a,o),n=0===e.length,p=n?null:f(t,e,null,o,i,u);t.prevIsBlock&&!n||(t.prevIsBlock=!0,t.offset+=u);const g=r(p,"element",d,d,l,s);null!==p&&(p.parent=g);const h=t.offset;return g.end=h,i.set(l,g),g}t.prevIsBlock=!1;const p=e.$isTextNode(a),g=p?a.__text.length:1,h=r(null,p?"text":"inline",d,t.offset+=g,l,s);return i.set(l,h),h}function f(e,t,n,l,s,o){let r=null,f=null;const c=t.length;for(let u=0;u<c;u++){const c=i(e,t[u],n,l,s,o);null===f?r=c:(c.prev=f,f.next=c),f=c}return r}function c(t,l){const s=[];let o=t.__first;for(;null!==o;){const t=null===l?e.$getNodeByKey(o):l.get(o);null==t&&n(174),s.push(o),o=t.__next}return s}const u=c;exports.$createChildrenArray=c,exports.$createOffsetView=function(e,t=1,n){const s=(n||e._pendingEditorState||e._editorState)._nodeMap,o=s.get("root"),r=new Map,i=f({offset:0,prevIsBlock:!1},c(o,s),null,s,r,t);return new l(r,i,t)},exports.OffsetView=l,exports.createChildrenArray=u; |
@@ -11,3 +11,3 @@ { | ||
"license": "MIT", | ||
"version": "0.23.2-nightly.20250114.0", | ||
"version": "0.23.2-nightly.20250115.0", | ||
"main": "LexicalOffset.js", | ||
@@ -40,4 +40,4 @@ "types": "index.d.ts", | ||
"dependencies": { | ||
"lexical": "0.23.2-nightly.20250114.0" | ||
"lexical": "0.23.2-nightly.20250115.0" | ||
} | ||
} |
38596
768
+ Addedlexical@0.23.2-nightly.20250115.0(transitive)
- Removedlexical@0.23.2-nightly.20250114.0(transitive)