Socket
Socket
Sign inDemoInstall

@lexical/utils

Package Overview
Dependencies
Maintainers
6
Versions
154
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lexical/utils - npm Package Compare versions

Comparing version 0.6.5 to 0.7.0

1

index.d.ts

@@ -41,3 +41,2 @@ /** @module @lexical/utils */

export declare function registerNestedElementResolver<N extends ElementNode>(editor: LexicalEditor, targetNode: Klass<N>, cloneNode: (from: N) => N, handleOverlap: (from: N, to: N) => void): () => void;
export declare function unstable_convertLegacyJSONEditorState(editor: LexicalEditor, maybeStringifiedEditorState: string): EditorState;
export declare function $restoreEditorState(editor: LexicalEditor, editorState: EditorState): void;

@@ -44,0 +43,0 @@ export declare function $insertNodeToNearestRoot<T extends LexicalNode>(node: T): T;

@@ -252,133 +252,3 @@ /**

return editor.registerNodeTransform(targetNode, elementNodeTransform);
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
function unstable_internalCreateNodeFromParse(parsedNode, parsedNodeMap, editor, parentKey, activeEditorState) {
const nodeType = parsedNode.__type;
const registeredNode = editor._nodes.get(nodeType);
if (registeredNode === undefined) {
{
throw Error(`createNodeFromParse: type "${nodeType}" + not found`);
}
} // Check for properties that are editors
for (const property in parsedNode) {
const value = parsedNode[property];
if (value != null && typeof value === 'object') {
const parsedEditorState = value.editorState;
if (parsedEditorState != null) {
const nestedEditor = lexical.createEditor({
namespace: parsedEditorState.namespace
});
nestedEditor._nodes = editor._nodes;
nestedEditor._parentEditor = editor._parentEditor;
nestedEditor._pendingEditorState = unstable_convertLegacyJSONEditorState(nestedEditor, parsedEditorState);
parsedNode[property] = nestedEditor;
}
}
}
const NodeKlass = registeredNode.klass;
const parsedKey = parsedNode.__key; // We set the parsedKey to undefined before calling clone() so that
// we get a new random key assigned.
parsedNode.__key = undefined;
const node = NodeKlass.clone(parsedNode);
parsedNode.__key = parsedKey;
const key = node.__key;
activeEditorState._nodeMap.set(key, node);
node.__parent = parentKey; // We will need to recursively handle the children in the case
// of a ElementNode.
if (lexical.$isElementNode(node)) {
const children = parsedNode.__children;
let prevNode = null;
for (let i = 0; i < children.length; i++) {
const childKey = children[i];
if (i === 0) {
node.__first = childKey;
} else if (i === children.length - 1) {
node.__last = childKey;
}
const parsedChild = parsedNodeMap.get(childKey);
if (parsedChild !== undefined) {
const child = unstable_internalCreateNodeFromParse(parsedChild, parsedNodeMap, editor, key, activeEditorState);
const newChildKey = child.__key;
if (prevNode !== null) {
child.__prev = prevNode.__key;
prevNode.__next = newChildKey;
}
node.__children.push(newChildKey);
prevNode = child;
}
}
node.__indent = parsedNode.__indent;
node.__format = parsedNode.__format;
node.__dir = parsedNode.__dir;
} else if (lexical.$isTextNode(node)) {
node.__format = parsedNode.__format;
node.__style = parsedNode.__style;
node.__mode = parsedNode.__mode;
node.__detail = parsedNode.__detail;
}
return node;
}
function unstable_parseEditorState(parsedEditorState, editor) {
// This is hacky, do not do this!
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const EditorStateClass = editor._editorState.constructor;
const nodeMap = new Map();
const editorState = new EditorStateClass(nodeMap);
const parsedNodeMap = new Map(parsedEditorState._nodeMap); // root always exists in Map
const parsedRoot = parsedNodeMap.get('root');
const isUpdating = editor._updating;
try {
editor._updating = false;
editor.update(() => {
const dirtyElements = editor._dirtyElements;
const dirtyLeaves = editor._dirtyLeaves;
const dirtyType = editor._dirtyType;
editor._dirtyElements = new Map();
editor._dirtyLeaves = new Set();
editor._dirtyType = 0;
try {
unstable_internalCreateNodeFromParse(parsedRoot, parsedNodeMap, editor, null, editorState);
} finally {
editor._dirtyElements = dirtyElements;
editor._dirtyLeaves = dirtyLeaves;
editor._dirtyType = dirtyType;
}
});
} finally {
editor._updating = isUpdating;
}
editorState._readOnly = true;
return editorState;
} // TODO: remove this function in version 0.4
function unstable_convertLegacyJSONEditorState(editor, maybeStringifiedEditorState) {
const parsedEditorState = typeof maybeStringifiedEditorState === 'string' ? JSON.parse(maybeStringifiedEditorState) : maybeStringifiedEditorState;
return unstable_parseEditorState(parsedEditorState, editor);
}
function $restoreEditorState(editor, editorState) {

@@ -507,2 +377,1 @@ const FULL_RECONCILE = 2;

exports.removeClassNamesFromElement = removeClassNamesFromElement;
exports.unstable_convertLegacyJSONEditorState = unstable_convertLegacyJSONEditorState;

23

LexicalUtils.prod.js

@@ -7,14 +7,11 @@ /**

*/
'use strict';var m=require("lexical");function p(a){throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?code=${a} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function q(a,b){for(let d of b)if(a.type.startsWith(d))return!0;return!1}function r(a,b){for(;a!==m.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null}
function t(a,b,d,f,g){var c=d._nodes.get(a.__type);void 0===c&&p(5);for(var e in a){var l=a[e];if(null!=l&&"object"===typeof l&&(l=l.editorState,null!=l)){var h=m.createEditor({namespace:l.namespace});h._nodes=d._nodes;h._parentEditor=d._parentEditor;h._pendingEditorState=u(h,l);a[e]=h}}c=c.klass;e=a.__key;a.__key=void 0;c=c.clone(a);a.__key=e;e=c.__key;g._nodeMap.set(e,c);c.__parent=f;if(m.$isElementNode(c)){f=a.__children;l=null;for(h=0;h<f.length;h++){var k=f[h];0===h?c.__first=k:h===f.length-
1&&(c.__last=k);k=b.get(k);if(void 0!==k){k=t(k,b,d,e,g);let n=k.__key;null!==l&&(k.__prev=l.__key,l.__next=n);c.__children.push(n);l=k}}c.__indent=a.__indent;c.__format=a.__format;c.__dir=a.__dir}else m.$isTextNode(c)&&(c.__format=a.__format,c.__style=a.__style,c.__mode=a.__mode,c.__detail=a.__detail);return c}
function v(a,b){let d=b._editorState.constructor,f=new Map,g=new d(f),c=new Map(a._nodeMap),e=c.get("root");a=b._updating;try{b._updating=!1,b.update(()=>{let l=b._dirtyElements,h=b._dirtyLeaves,k=b._dirtyType;b._dirtyElements=new Map;b._dirtyLeaves=new Set;b._dirtyType=0;try{t(e,c,b,null,g)}finally{b._dirtyElements=l,b._dirtyLeaves=h,b._dirtyType=k}})}finally{b._updating=a}g._readOnly=!0;return g}function u(a,b){b="string"===typeof b?JSON.parse(b):b;return v(b,a)}
function w(a,b){let d=a.getChildAtIndex(b);null==d&&(d=a);if(m.$isRootOrShadowRoot(a))throw Error("Can not call $splitNode() on root element");let f=e=>{const l=e.getParentOrThrow(),h=m.$isRootOrShadowRoot(l),k=e!==d||h?m.$copyNode(e):e;if(h)return e.insertAfter(k),[e,k,k];const [n,x,y]=f(l);e=e.getNextSiblings();y.append(k,...e);return[n,x,k]},[g,c]=f(d);return[g,c]}
exports.$dfs=function(a,b){let d=[];a=(a||m.$getRoot()).getLatest();b=b||(m.$isElementNode(a)?a.getLastDescendant():a);for(var f=a,g=0;null!==(f=f.getParent());)g++;for(f=g;null!==a&&!a.is(b);)if(d.push({depth:f,node:a}),m.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild(),f++;else for(g=null;null===g&&null!==a;)g=a.getNextSibling(),null===g?(a=a.getParent(),f--):a=g;null!==a&&a.is(b)&&d.push({depth:f,node:a});return d};exports.$findMatchingParent=r;
exports.$getNearestBlockElementAncestorOrThrow=function(a){a=r(a,b=>m.$isElementNode(b)&&!b.isInline());m.$isElementNode(a)||p(4);return a};exports.$getNearestNodeOfType=function(a,b){for(;null!=a;){if(a instanceof b)return a;a=a.getParent()}return null};
exports.$insertNodeToNearestRoot=function(a){var b=m.$getSelection();if(m.$isRangeSelection(b)){var {focus:d}=b;b=d.getNode();d=d.offset;if(m.$isRootOrShadowRoot(b))d=b.getChildAtIndex(d),null==d?b.append(a):d.insertBefore(a),a.selectNext();else{let f,g;m.$isTextNode(b)?(f=b.getParentOrThrow(),g=b.getIndexWithinParent(),0<d&&(g+=1,b.splitText(d))):(f=b,g=d);[,b]=w(f,g);b.insertBefore(a);b.selectStart()}}else m.$isNodeSelection(b)||m.DEPRECATED_$isGridSelection(b)?(b=b.getNodes(),b[b.length-1].getTopLevelElementOrThrow().insertAfter(a)):
m.$getRoot().append(a),b=m.$createParagraphNode(),a.insertAfter(b),b.select();return a.getLatest()};exports.$restoreEditorState=function(a,b){let d=new Map(b._nodeMap),f=a._pendingEditorState;f&&(f._nodeMap=d);a._dirtyType=2;a=b._selection;m.$setSelection(null===a?null:a.clone())};exports.$splitNode=w;exports.$wrapNodeInElement=function(a,b){b=b();a.replace(b);b.append(a);return b};
exports.addClassNamesToElement=function(a,...b){b.forEach(d=>{"string"===typeof d&&(d=d.split(" ").filter(f=>""!==f),a.classList.add(...d))})};exports.isMimeType=q;
exports.mediaFileReader=function(a,b){let d=a[Symbol.iterator]();return new Promise((f,g)=>{let c=[],e=()=>{const {done:l,value:h}=d.next();if(l)return f(c);const k=new FileReader;k.addEventListener("error",g);k.addEventListener("load",()=>{const n=k.result;"string"===typeof n&&c.push({file:h,result:n});e()});q(h,b)?k.readAsDataURL(h):e()};e()})};exports.mergeRegister=function(...a){return()=>{a.forEach(b=>b())}};
exports.registerNestedElementResolver=function(a,b,d,f){return a.registerNodeTransform(b,g=>{a:{var c=g.getChildren();for(var e=0;e<c.length;e++)if(c[e]instanceof b){c=null;break a}for(c=g;null!==c;)if(e=c,c=c.getParent(),c instanceof b){c={child:e,parent:c};break a}c=null}if(null!==c){const {child:l,parent:h}=c;if(l.is(g)){f(h,g);g=l.getNextSiblings();c=g.length;h.insertAfter(l);if(0!==c){e=d(h);l.insertAfter(e);for(let k=0;k<c;k++)e.append(g[k])}h.canBeEmpty()||0!==h.getChildrenSize()||h.remove()}}})};
exports.removeClassNamesFromElement=function(a,...b){b.forEach(d=>{"string"===typeof d&&a.classList.remove(...d.split(" "))})};exports.unstable_convertLegacyJSONEditorState=u
'use strict';var h=require("lexical");function p(a,b){for(let c of b)if(a.type.startsWith(c))return!0;return!1}function q(a,b){for(;a!==h.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null}
function r(a,b){let c=a.getChildAtIndex(b);null==c&&(c=a);if(h.$isRootOrShadowRoot(a))throw Error("Can not call $splitNode() on root element");let e=f=>{const m=f.getParentOrThrow(),l=h.$isRootOrShadowRoot(m),k=f!==c||l?h.$copyNode(f):f;if(l)return f.insertAfter(k),[f,k,k];const [n,t,u]=e(m);f=f.getNextSiblings();u.append(k,...f);return[n,t,k]},[d,g]=e(c);return[d,g]}
exports.$dfs=function(a,b){let c=[];a=(a||h.$getRoot()).getLatest();b=b||(h.$isElementNode(a)?a.getLastDescendant():a);for(var e=a,d=0;null!==(e=e.getParent());)d++;for(e=d;null!==a&&!a.is(b);)if(c.push({depth:e,node:a}),h.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild(),e++;else for(d=null;null===d&&null!==a;)d=a.getNextSibling(),null===d?(a=a.getParent(),e--):a=d;null!==a&&a.is(b)&&c.push({depth:e,node:a});return c};exports.$findMatchingParent=q;
exports.$getNearestBlockElementAncestorOrThrow=function(a){a=q(a,b=>h.$isElementNode(b)&&!b.isInline());if(!h.$isElementNode(a))throw Error("Minified Lexical error #4; visit https://lexical.dev/docs/error?code=4 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return a};exports.$getNearestNodeOfType=function(a,b){for(;null!=a;){if(a instanceof b)return a;a=a.getParent()}return null};
exports.$insertNodeToNearestRoot=function(a){var b=h.$getSelection();if(h.$isRangeSelection(b)){var {focus:c}=b;b=c.getNode();c=c.offset;if(h.$isRootOrShadowRoot(b))c=b.getChildAtIndex(c),null==c?b.append(a):c.insertBefore(a),a.selectNext();else{let e,d;h.$isTextNode(b)?(e=b.getParentOrThrow(),d=b.getIndexWithinParent(),0<c&&(d+=1,b.splitText(c))):(e=b,d=c);[,b]=r(e,d);b.insertBefore(a);b.selectStart()}}else h.$isNodeSelection(b)||h.DEPRECATED_$isGridSelection(b)?(b=b.getNodes(),b[b.length-1].getTopLevelElementOrThrow().insertAfter(a)):
h.$getRoot().append(a),b=h.$createParagraphNode(),a.insertAfter(b),b.select();return a.getLatest()};exports.$restoreEditorState=function(a,b){let c=new Map(b._nodeMap),e=a._pendingEditorState;e&&(e._nodeMap=c);a._dirtyType=2;a=b._selection;h.$setSelection(null===a?null:a.clone())};exports.$splitNode=r;exports.$wrapNodeInElement=function(a,b){b=b();a.replace(b);b.append(a);return b};
exports.addClassNamesToElement=function(a,...b){b.forEach(c=>{"string"===typeof c&&(c=c.split(" ").filter(e=>""!==e),a.classList.add(...c))})};exports.isMimeType=p;
exports.mediaFileReader=function(a,b){let c=a[Symbol.iterator]();return new Promise((e,d)=>{let g=[],f=()=>{const {done:m,value:l}=c.next();if(m)return e(g);const k=new FileReader;k.addEventListener("error",d);k.addEventListener("load",()=>{const n=k.result;"string"===typeof n&&g.push({file:l,result:n});f()});p(l,b)?k.readAsDataURL(l):f()};f()})};exports.mergeRegister=function(...a){return()=>{a.forEach(b=>b())}};
exports.registerNestedElementResolver=function(a,b,c,e){return a.registerNodeTransform(b,d=>{a:{var g=d.getChildren();for(var f=0;f<g.length;f++)if(g[f]instanceof b){g=null;break a}for(g=d;null!==g;)if(f=g,g=g.getParent(),g instanceof b){g={child:f,parent:g};break a}g=null}if(null!==g){const {child:m,parent:l}=g;if(m.is(d)){e(l,d);d=m.getNextSiblings();g=d.length;l.insertAfter(m);if(0!==g){f=c(l);m.insertAfter(f);for(let k=0;k<g;k++)f.append(d[k])}l.canBeEmpty()||0!==l.getChildrenSize()||l.remove()}}})};
exports.removeClassNamesFromElement=function(a,...b){b.forEach(c=>{"string"===typeof c&&a.classList.remove(...c.split(" "))})}

@@ -11,10 +11,10 @@ {

"license": "MIT",
"version": "0.6.5",
"version": "0.7.0",
"main": "LexicalUtils.js",
"peerDependencies": {
"lexical": "0.6.5"
"lexical": "0.7.0"
},
"dependencies": {
"@lexical/list": "0.6.5",
"@lexical/table": "0.6.5"
"@lexical/list": "0.7.0",
"@lexical/table": "0.7.0"
},

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