@lexical/utils 0.3.5 → 0.3.6

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.
@@ -73,10 +73,10 @@ function $dfs(startingNode, endingNode) {
73
73
  }
74
74
 
75
75
  function $getDepth(node) {
76
- let node_ = node;
76
+ let innerNode = node;
77
77
  let depth = 0;
78
78
 
79
- while ((node_ = node_.getParent()) !== null) {
79
+ while ((innerNode = innerNode.getParent()) !== null) {
80
80
  depth++;
81
81
  }
82
82
 
@@ -229,8 +229,7 @@ function unstable_internalCreateNodeFromParse(parsedNode, parsedNodeMap, editor,
229
229
  const parsedKey = parsedNode.__key; // We set the parsedKey to undefined before calling clone() so that
230
230
  // we get a new random key assigned.
231
231
 
232
- parsedNode.__key = undefined; // @ts-expect-error TODO Replace Class utility type with InstanceType
233
-
232
+ parsedNode.__key = undefined;
234
233
  const node = NodeKlass.clone(parsedNode);
235
234
  parsedNode.__key = parsedKey;
236
235
  const key = node.__key;
@@ -314,7 +313,11 @@ function $restoreEditorState(editor, editorState) {
314
313
  const FULL_RECONCILE = 2;
315
314
  const nodeMap = new Map(editorState._nodeMap);
316
315
  const activeEditorState = editor._pendingEditorState;
317
- activeEditorState._nodeMap = nodeMap;
316
+
317
+ if (activeEditorState) {
318
+ activeEditorState._nodeMap = nodeMap;
319
+ }
320
+
318
321
  editor._dirtyType = FULL_RECONCILE;
319
322
  const selection = editorState._selection;
320
323
  lexical.$setSelection(selection === null ? null : selection.clone());
@@ -5,11 +5,11 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict';var l=require("lexical");function n(a){throw Error(`Minified Lexical error #${a}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function p(a,b){for(;a!==l.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null}
8
- function q(a,b,e,k,d){var c=e._nodes.get(a.__type);void 0===c&&n(5);for(var g in a){var h=a[g];if(null!=h&&"object"===typeof h&&(h=h.editorState,null!=h)){var f=l.createEditor({namespace:h.namespace});f._nodes=e._nodes;f._parentEditor=e._parentEditor;f._pendingEditorState=r(f,h);a[g]=f}}c=c.klass;g=a.__key;a.__key=void 0;c=c.clone(a);a.__key=g;g=c.__key;d._nodeMap.set(g,c);c.__parent=k;if(l.$isElementNode(c)){k=a.__children;for(h=0;h<k.length;h++)f=b.get(k[h]),void 0!==f&&(f=q(f,b,e,g,d).__key,c.__children.push(f));
8
+ function q(a,b,e,f,d){var c=e._nodes.get(a.__type);void 0===c&&n(5);for(var h in a){var k=a[h];if(null!=k&&"object"===typeof k&&(k=k.editorState,null!=k)){var g=l.createEditor({namespace:k.namespace});g._nodes=e._nodes;g._parentEditor=e._parentEditor;g._pendingEditorState=r(g,k);a[h]=g}}c=c.klass;h=a.__key;a.__key=void 0;c=c.clone(a);a.__key=h;h=c.__key;d._nodeMap.set(h,c);c.__parent=f;if(l.$isElementNode(c)){f=a.__children;for(k=0;k<f.length;k++)g=b.get(f[k]),void 0!==g&&(g=q(g,b,e,h,d).__key,c.__children.push(g));
9
9
  c.__indent=a.__indent;c.__format=a.__format;c.__dir=a.__dir}else l.$isTextNode(c)&&(c.__format=a.__format,c.__style=a.__style,c.__mode=a.__mode,c.__detail=a.__detail);return c}
10
- function t(a,b){let e=b._editorState.constructor,k=new Map,d=new e(k),c=new Map(a._nodeMap),g=c.get("root");a=b._updating;try{b._updating=!1,b.update(()=>{let h=b._dirtyElements,f=b._dirtyLeaves,m=b._dirtyType;b._dirtyElements=new Map;b._dirtyLeaves=new Set;b._dirtyType=0;try{q(g,c,b,null,d)}finally{b._dirtyElements=h,b._dirtyLeaves=f,b._dirtyType=m}})}finally{b._updating=a}d._readOnly=!0;return d}function r(a,b){b="string"===typeof b?JSON.parse(b):b;return t(b,a)}
11
- exports.$dfs=function(a,b){let e=[];a=(a||l.$getRoot()).getLatest();b=b||(l.$isElementNode(a)?a.getLastDescendant():a);for(var k=a,d=0;null!==(k=k.getParent());)d++;for(k=d;null!==a&&!a.is(b);)if(e.push({depth:k,node:a}),l.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild(),k++;else for(d=null;null===d&&null!==a;)d=a.getNextSibling(),null===d?(a=a.getParent(),k--):a=d;null!==a&&a.is(b)&&e.push({depth:k,node:a});return e};exports.$findMatchingParent=p;
12
- exports.$getNearestBlockElementAncestorOrThrow=function(a){a=p(a,b=>l.$isElementNode(b)&&!b.isInline());l.$isElementNode(a)||n(4);return a};exports.$getNearestNodeOfType=function(a,b){for(;null!=a&&!(a instanceof b);)a=a.getParent();return a};exports.$restoreEditorState=function(a,b){let e=new Map(b._nodeMap);a._pendingEditorState._nodeMap=e;a._dirtyType=2;a=b._selection;l.$setSelection(null===a?null:a.clone())};exports.addClassNamesToElement=function(a,...b){b.forEach(e=>{"string"===typeof e&&a.classList.add(...e.split(" "))})};
13
- exports.mergeRegister=function(...a){return()=>{a.forEach(b=>b())}};
14
- exports.registerNestedElementResolver=function(a,b,e,k){return a.registerNodeTransform(b,d=>{a:{var c=d.getChildren();for(var g=0;g<c.length;g++)if(c[g]instanceof b){c=null;break a}for(c=d;null!==c;)if(g=c,c=c.getParent(),c instanceof b){c={child:g,parent:c};break a}c=null}if(null!==c){const {child:h,parent:f}=c;if(h.is(d)){k(f,d);d=h.getNextSiblings();c=d.length;f.insertAfter(h);if(0!==c){g=e(f);h.insertAfter(g);for(let m=0;m<c;m++)g.append(d[m])}f.canBeEmpty()||0!==f.getChildrenSize()||f.remove()}}})};
10
+ function t(a,b){let e=b._editorState.constructor,f=new Map,d=new e(f),c=new Map(a._nodeMap),h=c.get("root");a=b._updating;try{b._updating=!1,b.update(()=>{let k=b._dirtyElements,g=b._dirtyLeaves,m=b._dirtyType;b._dirtyElements=new Map;b._dirtyLeaves=new Set;b._dirtyType=0;try{q(h,c,b,null,d)}finally{b._dirtyElements=k,b._dirtyLeaves=g,b._dirtyType=m}})}finally{b._updating=a}d._readOnly=!0;return d}function r(a,b){b="string"===typeof b?JSON.parse(b):b;return t(b,a)}
11
+ exports.$dfs=function(a,b){let e=[];a=(a||l.$getRoot()).getLatest();b=b||(l.$isElementNode(a)?a.getLastDescendant():a);for(var f=a,d=0;null!==(f=f.getParent());)d++;for(f=d;null!==a&&!a.is(b);)if(e.push({depth:f,node:a}),l.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild(),f++;else for(d=null;null===d&&null!==a;)d=a.getNextSibling(),null===d?(a=a.getParent(),f--):a=d;null!==a&&a.is(b)&&e.push({depth:f,node:a});return e};exports.$findMatchingParent=p;
12
+ exports.$getNearestBlockElementAncestorOrThrow=function(a){a=p(a,b=>l.$isElementNode(b)&&!b.isInline());l.$isElementNode(a)||n(4);return a};exports.$getNearestNodeOfType=function(a,b){for(;null!=a&&!(a instanceof b);)a=a.getParent();return a};exports.$restoreEditorState=function(a,b){let e=new Map(b._nodeMap),f=a._pendingEditorState;f&&(f._nodeMap=e);a._dirtyType=2;a=b._selection;l.$setSelection(null===a?null:a.clone())};
13
+ exports.addClassNamesToElement=function(a,...b){b.forEach(e=>{"string"===typeof e&&a.classList.add(...e.split(" "))})};exports.mergeRegister=function(...a){return()=>{a.forEach(b=>b())}};
14
+ exports.registerNestedElementResolver=function(a,b,e,f){return a.registerNodeTransform(b,d=>{a:{var c=d.getChildren();for(var h=0;h<c.length;h++)if(c[h]instanceof b){c=null;break a}for(c=d;null!==c;)if(h=c,c=c.getParent(),c instanceof b){c={child:h,parent:c};break a}c=null}if(null!==c){const {child:k,parent:g}=c;if(k.is(d)){f(g,d);d=k.getNextSiblings();c=d.length;g.insertAfter(k);if(0!==c){h=e(g);k.insertAfter(h);for(let m=0;m<c;m++)h.append(d[m])}g.canBeEmpty()||0!==g.getChildrenSize()||g.remove()}}})};
15
15
  exports.removeClassNamesFromElement=function(a,...b){b.forEach(e=>{"string"===typeof e&&a.classList.remove(...e.split(" "))})};exports.unstable_convertLegacyJSONEditorState=r
package/index.d.ts CHANGED
@@ -5,16 +5,15 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { EditorState, ElementNode, LexicalEditor, LexicalNode } from 'lexical';
9
- import type { Klass } from 'shared/types';
8
+ import type { EditorState, ElementNode, Klass, LexicalEditor, LexicalNode } from 'lexical';
10
9
  export declare type DFSNode = Readonly<{
11
10
  depth: number;
12
11
  node: LexicalNode;
13
12
  }>;
14
13
  export declare function addClassNamesToElement(element: HTMLElement, ...classNames: Array<typeof undefined | boolean | null | string>): void;
15
- export declare function removeClassNamesFromElement(element: HTMLElement, ...classNames: Array<string>): void;
14
+ export declare function removeClassNamesFromElement(element: HTMLElement, ...classNames: Array<typeof undefined | boolean | null | string>): void;
16
15
  export declare function $dfs(startingNode?: LexicalNode, endingNode?: LexicalNode): Array<DFSNode>;
17
- export declare function $getNearestNodeOfType<T extends ElementNode>(node: LexicalNode, klass: Klass<T>): T | LexicalNode;
16
+ export declare function $getNearestNodeOfType<T extends ElementNode>(node: LexicalNode, klass: Klass<T>): LexicalNode | null;
18
17
  export declare function $getNearestBlockElementAncestorOrThrow(startNode: LexicalNode): ElementNode;
19
18
  export declare type DOMNodeToLexicalConversion = (element: Node) => LexicalNode;
20
19
  export declare type DOMNodeToLexicalConversionMap = Record<string, DOMNodeToLexicalConversion>;
package/package.json CHANGED
@@ -8,21 +8,18 @@
8
8
  "utils"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.3.5",
11
+ "version": "0.3.6",
12
12
  "main": "LexicalUtils.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.3.5"
14
+ "lexical": "0.3.6"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/list": "0.3.5",
18
- "@lexical/table": "0.3.5"
17
+ "@lexical/list": "0.3.6",
18
+ "@lexical/table": "0.3.6"
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",
22
22
  "url": "https://github.com/facebook/lexical",
23
23
  "directory": "packages/lexical-utils"
24
- },
25
- "devDependencies": {
26
- "utility-types": "^3.10.0"
27
24
  }
28
25
  }