@lexical/utils 0.3.2 → 0.3.5
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 +3 -1
- package/LexicalUtils.prod.js +7 -7
- package/index.d.ts +27 -0
- package/package.json +7 -4
- package/LexicalUtils.d.ts +0 -71
package/LexicalUtils.dev.js
CHANGED
|
@@ -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);
|
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){
|
|
13
|
-
exports.
|
|
14
|
-
exports.registerNestedElementResolver=function(a,b,e,
|
|
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));
|
|
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()}}})};
|
|
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,27 @@
|
|
|
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, LexicalEditor, LexicalNode } from 'lexical';
|
|
9
|
+
import type { Klass } from 'shared/types';
|
|
10
|
+
export declare type DFSNode = Readonly<{
|
|
11
|
+
depth: number;
|
|
12
|
+
node: LexicalNode;
|
|
13
|
+
}>;
|
|
14
|
+
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;
|
|
16
|
+
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;
|
|
18
|
+
export declare function $getNearestBlockElementAncestorOrThrow(startNode: LexicalNode): ElementNode;
|
|
19
|
+
export declare type DOMNodeToLexicalConversion = (element: Node) => LexicalNode;
|
|
20
|
+
export declare type DOMNodeToLexicalConversionMap = Record<string, DOMNodeToLexicalConversion>;
|
|
21
|
+
export declare function $findMatchingParent(startingNode: LexicalNode, findFn: (node: LexicalNode) => boolean): LexicalNode | null;
|
|
22
|
+
declare type Func = () => void;
|
|
23
|
+
export declare function mergeRegister(...func: Array<Func>): () => void;
|
|
24
|
+
export declare function registerNestedElementResolver<N extends ElementNode>(editor: LexicalEditor, targetNode: Klass<N>, cloneNode: (from: N) => N, handleOverlap: (from: N, to: N) => void): () => void;
|
|
25
|
+
export declare function unstable_convertLegacyJSONEditorState(editor: LexicalEditor, maybeStringifiedEditorState: string): EditorState;
|
|
26
|
+
export declare function $restoreEditorState(editor: LexicalEditor, editorState: EditorState): void;
|
|
27
|
+
export {};
|
package/package.json
CHANGED
|
@@ -8,18 +8,21 @@
|
|
|
8
8
|
"utils"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.3.
|
|
11
|
+
"version": "0.3.5",
|
|
12
12
|
"main": "LexicalUtils.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.3.
|
|
14
|
+
"lexical": "0.3.5"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/list": "0.3.
|
|
18
|
-
"@lexical/table": "0.3.
|
|
17
|
+
"@lexical/list": "0.3.5",
|
|
18
|
+
"@lexical/table": "0.3.5"
|
|
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"
|
|
24
27
|
}
|
|
25
28
|
}
|
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;
|