Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lexical/offset

Package Overview
Dependencies
Maintainers
6
Versions
197
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lexical/offset - npm Package Compare versions

Comparing version 0.6.5 to 0.7.0

3

index.d.ts

@@ -9,3 +9,3 @@ /** @module @lexical/offset */

*/
import type { EditorState, LexicalEditor, NodeKey, RangeSelection } from 'lexical';
import type { EditorState, ElementNode, LexicalEditor, NodeKey, NodeMap, RangeSelection } from 'lexical';
declare type OffsetElementNode = {

@@ -51,3 +51,4 @@ child: null | OffsetNode;

}
export declare function createChildrenArray(element: ElementNode, nodeMap: null | NodeMap): Array<NodeKey>;
export declare function $createOffsetView(editor: LexicalEditor, blockOffsetSize?: number, editorState?: EditorState | null): OffsetView;
export {};

@@ -303,3 +303,3 @@ /**

if (lexical.$isElementNode(node)) {
const childKeys = node.__children;
const childKeys = node.getChildrenKeys();
const blockIsEmpty = childKeys.length === 0;

@@ -357,2 +357,21 @@ 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

function createChildrenArray(element, nodeMap) {
const children = [];
let nodeKey = element.__first;
while (nodeKey !== null) {
const node = nodeMap === null ? lexical.$getNodeByKey(nodeKey) : nodeMap.get(nodeKey);
if (node === null || node === undefined) {
{
throw Error(`createChildrenArray: node does not exist in nodeMap`);
}
}
children.push(nodeKey);
nodeKey = node.__next;
}
return children;
}
function $createOffsetView(editor, blockOffsetSize = 1, editorState) {

@@ -367,3 +386,3 @@ const targetEditorState = editorState || editor._pendingEditorState || editor._editorState;

};
const node = $createOffsetChild(state, root.__children, null, nodeMap, offsetMap, blockOffsetSize);
const node = $createOffsetChild(state, createChildrenArray(root, nodeMap), null, nodeMap, offsetMap, blockOffsetSize);
return new OffsetView(offsetMap, node, blockOffsetSize);

@@ -374,1 +393,2 @@ }

exports.OffsetView = OffsetView;
exports.createChildrenArray = createChildrenArray;

@@ -7,10 +7,10 @@ /**

*/
'use strict';var q=require("lexical");
class t{constructor(b,a,c=1){this._offsetMap=b;this._firstNode=a;this._blockOffsetSize=c}createSelectionFromOffsets(b,a,c){var e=this._firstNode;if(null===e)return null;var f=y(e,b,this._blockOffsetSize);let h=y(e,a,this._blockOffsetSize);void 0!==c&&(b=z(b,f,c,this,this._blockOffsetSize),f=y(e,b,this._blockOffsetSize),a=z(a,h,c,this,this._blockOffsetSize),h=y(e,a,this._blockOffsetSize));if(null===f||null===h)return null;c=f.key;e=h.key;let m=q.$getNodeByKey(c),k=q.$getNodeByKey(e);if(null===m||null===
k)return null;let l=0,d=0,g="element",n="element";"text"===f.type?(l=b-f.start,g="text",f=m.getNextSibling(),b!==a&&l===m.getTextContentSize()&&q.$isTextNode(f)&&(l=0,c=f.__key)):"inline"===f.type&&(c=m.getParentOrThrow().getKey(),l=a>f.start?f.end:f.start);"text"===h.type?(d=a-h.start,n="text"):"inline"===h.type&&(e=k.getParentOrThrow().getKey(),d=a>h.start?h.end:h.start);b=q.$createRangeSelection();if(null===b)return null;b.anchor.set(c,l,g);b.focus.set(e,d,n);return b}getOffsetsFromSelection(b){var a=
b.anchor,c=b.focus,e=this._offsetMap;let f=a.offset;var h=c.offset;let m=b=-1;if("text"===a.type)a=e.get(a.key),void 0!==a&&(b=a.start+f);else if(a=a.getNode().getDescendantByIndex(f),null!==a){let k=e.get(a.getKey());void 0!==k&&(b=a.getIndexWithinParent()!==f?k.end:k.start)}"text"===c.type?(h=e.get(c.key),void 0!==h&&(m=h.start+c.offset)):(c=c.getNode().getDescendantByIndex(h),null!==c&&(e=e.get(c.getKey()),void 0!==e&&(m=c.getIndexWithinParent()!==h?e.end:e.start)));return[b,m]}}
function z(b,a,c,e,f){let h=c._offsetMap;e=e._offsetMap;let m=new Set,k=b;for(;null!==a;){var l=a.key,d=h.get(l),g=a.end-a.start;m.add(l);void 0===d?k+=g:(l=d.end-d.start,l!==g&&(k+=g-l));g=a.prev;if(null!==g)a=g;else{for(a=a.parent;null!==a;)d=a.prev,null!==d&&(g=d.key,l=h.get(g),d=d.end-d.start,m.add(g),void 0===l?k+=d:(g=l.end-l.start,g!==d&&(k+=d-g))),a=a.parent;break}}c=c._firstNode;if(null!==c){a=y(c,b,f);for(b=!1;null!==a;){if(!m.has(a.key)){b=!0;break}a=a.parent}if(!b)for(;null!==a;)b=a.key,
m.has(b)||(f=e.get(b),b=a.end-a.start,void 0===f?k-=b:(f=f.end-f.start,b!==f&&(k+=f-b))),a=a.prev}return k}function y(b,a,c){for(;null!==b;){if(a<b.end+("element"!==b.type||0===c?1:0)){let e=b.child;if(null!==e){b=e;continue}return b}b=b.next;if(null===b)break}return null}
function A(b,a,c,e,f,h){let m=null,k=null,l=a.length;for(let v=0;v<l;v++){{var d=b;var g=a[v];var n=c,r=e,w=f,u=h,p=r.get(g);if(void 0===p)throw Error("Minified Lexical error #3; visit https://lexical.dev/docs/error?code=3 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");let x=d.offset;if(q.$isElementNode(p)){let B=p.__children;r=(p=0===B.length)?null:A(d,B,null,r,w,u);if(!d.prevIsBlock||p)d.prevIsBlock=!0,d.offset+=u;n={child:r,end:x,
key:g,next:null,parent:n,prev:null,start:x,type:"element"};null!==r&&(r.parent=n);n.end=d.offset;w.set(g,n);g=n}else d.prevIsBlock=!1,u=q.$isTextNode(p),d={child:null,end:d.offset+=u?p.__text.length:1,key:g,next:null,parent:n,prev:null,start:x,type:u?"text":"inline"},w.set(g,d),g=d}null===k?m=g:(g.prev=k,k.next=g);k=g}return m}
exports.$createOffsetView=function(b,a=1,c){c=(c||b._pendingEditorState||b._editorState)._nodeMap;let e=c.get("root");b=new Map;c=A({offset:0,prevIsBlock:!1},e.__children,null,c,b,a);return new t(b,c,a)};exports.OffsetView=t
'use strict';var p=require("lexical");
class t{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=y(d,a,this._blockOffsetSize);let h=y(d,b,this._blockOffsetSize);void 0!==c&&(a=z(a,f,c,this,this._blockOffsetSize),f=y(d,a,this._blockOffsetSize),b=z(b,h,c,this,this._blockOffsetSize),h=y(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 z(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=y(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 y(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 A(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,r=d,w=f,u=h,q=r.get(g);if(void 0===q)throw Error("Minified Lexical error #3; visit https://lexical.dev/docs/error?code=3 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");let x=e.offset;if(p.$isElementNode(q)){let B=q.getChildrenKeys();r=(q=0===B.length)?null:A(e,B,null,r,w,u);if(!e.prevIsBlock||q)e.prevIsBlock=!0,e.offset+=u;n={child:r,
end:x,key:g,next:null,parent:n,prev:null,start:x,type:"element"};null!==r&&(r.parent=n);n.end=e.offset;w.set(g,n);g=n}else e.prevIsBlock=!1,u=p.$isTextNode(q),e={child:null,end:e.offset+=u?q.__text.length: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);if(null===d||void 0===d)throw Error("createChildrenArray: node does not exist in nodeMap");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=A({offset:0,prevIsBlock:!1},C(d,c),null,c,a,b);return new t(a,c,b)};exports.OffsetView=t;exports.createChildrenArray=C

@@ -11,6 +11,6 @@ {

"license": "MIT",
"version": "0.6.5",
"version": "0.7.0",
"main": "LexicalOffset.js",
"peerDependencies": {
"lexical": "0.6.5"
"lexical": "0.7.0"
},

@@ -17,0 +17,0 @@ "repository": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc