@lexical/utils 0.3.3 → 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.
- package/LexicalUtils.dev.js +11 -6
- package/LexicalUtils.prod.js +6 -6
- package/index.d.ts +26 -0
- package/package.json +4 -7
- package/LexicalUtils.d.ts +0 -71
package/LexicalUtils.dev.js
CHANGED
|
@@ -73,10 +73,10 @@ function $dfs(startingNode, endingNode) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function $getDepth(node) {
|
|
76
|
-
let
|
|
76
|
+
let innerNode = node;
|
|
77
77
|
let depth = 0;
|
|
78
78
|
|
|
79
|
-
while ((
|
|
79
|
+
while ((innerNode = innerNode.getParent()) !== null) {
|
|
80
80
|
depth++;
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -214,7 +214,9 @@ function unstable_internalCreateNodeFromParse(parsedNode, parsedNodeMap, editor,
|
|
|
214
214
|
const parsedEditorState = value.editorState;
|
|
215
215
|
|
|
216
216
|
if (parsedEditorState != null) {
|
|
217
|
-
const nestedEditor = lexical.createEditor(
|
|
217
|
+
const nestedEditor = lexical.createEditor({
|
|
218
|
+
namespace: parsedEditorState.namespace
|
|
219
|
+
});
|
|
218
220
|
nestedEditor._nodes = editor._nodes;
|
|
219
221
|
nestedEditor._parentEditor = editor._parentEditor;
|
|
220
222
|
nestedEditor._pendingEditorState = unstable_convertLegacyJSONEditorState(nestedEditor, parsedEditorState);
|
|
@@ -227,8 +229,7 @@ function unstable_internalCreateNodeFromParse(parsedNode, parsedNodeMap, editor,
|
|
|
227
229
|
const parsedKey = parsedNode.__key; // We set the parsedKey to undefined before calling clone() so that
|
|
228
230
|
// we get a new random key assigned.
|
|
229
231
|
|
|
230
|
-
parsedNode.__key = undefined;
|
|
231
|
-
|
|
232
|
+
parsedNode.__key = undefined;
|
|
232
233
|
const node = NodeKlass.clone(parsedNode);
|
|
233
234
|
parsedNode.__key = parsedKey;
|
|
234
235
|
const key = node.__key;
|
|
@@ -312,7 +313,11 @@ function $restoreEditorState(editor, editorState) {
|
|
|
312
313
|
const FULL_RECONCILE = 2;
|
|
313
314
|
const nodeMap = new Map(editorState._nodeMap);
|
|
314
315
|
const activeEditorState = editor._pendingEditorState;
|
|
315
|
-
|
|
316
|
+
|
|
317
|
+
if (activeEditorState) {
|
|
318
|
+
activeEditorState._nodeMap = nodeMap;
|
|
319
|
+
}
|
|
320
|
+
|
|
316
321
|
editor._dirtyType = FULL_RECONCILE;
|
|
317
322
|
const selection = editorState._selection;
|
|
318
323
|
lexical.$setSelection(selection === null ? null : selection.clone());
|
package/LexicalUtils.prod.js
CHANGED
|
@@ -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,
|
|
9
|
-
a.__indent;
|
|
10
|
-
function t(a,b){let e=b._editorState.constructor,
|
|
11
|
-
exports.$dfs=function(a,b){let e=[];a=(a||l.$getRoot()).getLatest();b=b||(l.$isElementNode(a)?a.getLastDescendant():a);for(var
|
|
12
|
-
exports.$getNearestBlockElementAncestorOrThrow=function(a){
|
|
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
|
+
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,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
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,
|
|
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
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { EditorState, ElementNode, Klass, LexicalEditor, LexicalNode } from 'lexical';
|
|
9
|
+
export declare type DFSNode = Readonly<{
|
|
10
|
+
depth: number;
|
|
11
|
+
node: LexicalNode;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function addClassNamesToElement(element: HTMLElement, ...classNames: Array<typeof undefined | boolean | null | string>): void;
|
|
14
|
+
export declare function removeClassNamesFromElement(element: HTMLElement, ...classNames: Array<typeof undefined | boolean | null | string>): void;
|
|
15
|
+
export declare function $dfs(startingNode?: LexicalNode, endingNode?: LexicalNode): Array<DFSNode>;
|
|
16
|
+
export declare function $getNearestNodeOfType<T extends ElementNode>(node: LexicalNode, klass: Klass<T>): LexicalNode | null;
|
|
17
|
+
export declare function $getNearestBlockElementAncestorOrThrow(startNode: LexicalNode): ElementNode;
|
|
18
|
+
export declare type DOMNodeToLexicalConversion = (element: Node) => LexicalNode;
|
|
19
|
+
export declare type DOMNodeToLexicalConversionMap = Record<string, DOMNodeToLexicalConversion>;
|
|
20
|
+
export declare function $findMatchingParent(startingNode: LexicalNode, findFn: (node: LexicalNode) => boolean): LexicalNode | null;
|
|
21
|
+
declare type Func = () => void;
|
|
22
|
+
export declare function mergeRegister(...func: Array<Func>): () => void;
|
|
23
|
+
export declare function registerNestedElementResolver<N extends ElementNode>(editor: LexicalEditor, targetNode: Klass<N>, cloneNode: (from: N) => N, handleOverlap: (from: N, to: N) => void): () => void;
|
|
24
|
+
export declare function unstable_convertLegacyJSONEditorState(editor: LexicalEditor, maybeStringifiedEditorState: string): EditorState;
|
|
25
|
+
export declare function $restoreEditorState(editor: LexicalEditor, editorState: EditorState): void;
|
|
26
|
+
export {};
|
package/package.json
CHANGED
|
@@ -8,21 +8,18 @@
|
|
|
8
8
|
"utils"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.3.
|
|
11
|
+
"version": "0.3.6",
|
|
12
12
|
"main": "LexicalUtils.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.3.
|
|
14
|
+
"lexical": "0.3.6"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/list": "0.3.
|
|
18
|
-
"@lexical/table": "0.3.
|
|
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
|
}
|
package/LexicalUtils.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import {Class} from 'utility-types';
|
|
10
|
-
|
|
11
|
-
import type {
|
|
12
|
-
EditorState,
|
|
13
|
-
LexicalNode,
|
|
14
|
-
ElementNode,
|
|
15
|
-
LexicalEditor,
|
|
16
|
-
} from 'lexical';
|
|
17
|
-
|
|
18
|
-
export type DFSNode = Readonly<{
|
|
19
|
-
depth: number;
|
|
20
|
-
node: LexicalNode;
|
|
21
|
-
}>;
|
|
22
|
-
|
|
23
|
-
declare function addClassNamesToElement(
|
|
24
|
-
element: HTMLElement,
|
|
25
|
-
...classNames: Array<typeof undefined | boolean | null | string>
|
|
26
|
-
): void;
|
|
27
|
-
declare function removeClassNamesFromElement(
|
|
28
|
-
element: HTMLElement,
|
|
29
|
-
...classNames: Array<typeof undefined | boolean | null | string>
|
|
30
|
-
): void;
|
|
31
|
-
declare function $dfs(
|
|
32
|
-
startingNode?: LexicalNode,
|
|
33
|
-
endingNode?: LexicalNode,
|
|
34
|
-
): Array<DFSNode>;
|
|
35
|
-
declare function $getDepth(node: LexicalNode): number;
|
|
36
|
-
declare function $getNearestNodeOfType<T extends LexicalNode>(
|
|
37
|
-
node: LexicalNode,
|
|
38
|
-
klass: Class<T>,
|
|
39
|
-
): T | null;
|
|
40
|
-
|
|
41
|
-
export type DOMNodeToLexicalConversion = (element: Node) => LexicalNode;
|
|
42
|
-
|
|
43
|
-
export type DOMNodeToLexicalConversionMap = Record<
|
|
44
|
-
string,
|
|
45
|
-
DOMNodeToLexicalConversion
|
|
46
|
-
>;
|
|
47
|
-
declare function $findMatchingParent(
|
|
48
|
-
startingNode: LexicalNode,
|
|
49
|
-
findFn: (node: LexicalNode) => boolean,
|
|
50
|
-
): LexicalNode | null;
|
|
51
|
-
type Func = () => void;
|
|
52
|
-
declare function mergeRegister(...func: Array<Func>): () => void;
|
|
53
|
-
declare function $getNearestBlockElementAncestorOrThrow(
|
|
54
|
-
startNode: LexicalNode,
|
|
55
|
-
): ElementNode;
|
|
56
|
-
declare function registerNestedElementResolver<N>(
|
|
57
|
-
editor: LexicalEditor,
|
|
58
|
-
targetNode: Class<N>,
|
|
59
|
-
cloneNode: (from: N) => N,
|
|
60
|
-
handleOverlap: (from: N, to: N) => void,
|
|
61
|
-
): () => void;
|
|
62
|
-
|
|
63
|
-
export declare function unstable_convertLegacyJSONEditorState(
|
|
64
|
-
editor: LexicalEditor,
|
|
65
|
-
maybeStringifiedEditorState: string,
|
|
66
|
-
): EditorState;
|
|
67
|
-
|
|
68
|
-
export declare function $restoreEditorState(
|
|
69
|
-
editor: LexicalEditor,
|
|
70
|
-
editorState: EditorState,
|
|
71
|
-
): void;
|