@lexical/utils 0.3.7 → 0.3.10
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 +21 -1
- package/LexicalUtils.js.flow +2 -0
- package/LexicalUtils.prod.js +3 -2
- package/index.d.ts +3 -2
- package/package.json +4 -4
package/LexicalUtils.dev.js
CHANGED
|
@@ -94,7 +94,7 @@ function $getNearestNodeOfType(node, klass) {
|
|
|
94
94
|
parent = parent.getParent();
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
return
|
|
97
|
+
return null;
|
|
98
98
|
}
|
|
99
99
|
function $getNearestBlockElementAncestorOrThrow(startNode) {
|
|
100
100
|
const blockNode = $findMatchingParent(startNode, node => lexical.$isElementNode(node) && !node.isInline());
|
|
@@ -322,11 +322,31 @@ function $restoreEditorState(editor, editorState) {
|
|
|
322
322
|
const selection = editorState._selection;
|
|
323
323
|
lexical.$setSelection(selection === null ? null : selection.clone());
|
|
324
324
|
}
|
|
325
|
+
function $insertBlockNode(node) {
|
|
326
|
+
const selection = lexical.$getSelection();
|
|
327
|
+
|
|
328
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
329
|
+
const focusNode = selection.focus.getNode();
|
|
330
|
+
focusNode.getTopLevelElementOrThrow().insertAfter(node);
|
|
331
|
+
} else if (lexical.$isNodeSelection(selection) || lexical.$isGridSelection(selection)) {
|
|
332
|
+
const nodes = selection.getNodes();
|
|
333
|
+
nodes[nodes.length - 1].getTopLevelElementOrThrow().insertAfter(node);
|
|
334
|
+
} else {
|
|
335
|
+
const root = lexical.$getRoot();
|
|
336
|
+
root.append(node);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const paragraphNode = lexical.$createParagraphNode();
|
|
340
|
+
node.insertAfter(paragraphNode);
|
|
341
|
+
paragraphNode.select();
|
|
342
|
+
return node.getLatest();
|
|
343
|
+
}
|
|
325
344
|
|
|
326
345
|
exports.$dfs = $dfs;
|
|
327
346
|
exports.$findMatchingParent = $findMatchingParent;
|
|
328
347
|
exports.$getNearestBlockElementAncestorOrThrow = $getNearestBlockElementAncestorOrThrow;
|
|
329
348
|
exports.$getNearestNodeOfType = $getNearestNodeOfType;
|
|
349
|
+
exports.$insertBlockNode = $insertBlockNode;
|
|
330
350
|
exports.$restoreEditorState = $restoreEditorState;
|
|
331
351
|
exports.addClassNamesToElement = addClassNamesToElement;
|
|
332
352
|
exports.mergeRegister = mergeRegister;
|
package/LexicalUtils.js.flow
CHANGED
package/LexicalUtils.prod.js
CHANGED
|
@@ -9,7 +9,8 @@ function q(a,b,e,f,d){var c=e._nodes.get(a.__type);void 0===c&&n(5);for(var h in
|
|
|
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
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
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
|
|
13
|
-
exports
|
|
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;){if(a instanceof b)return a;a=a.getParent()}return null};
|
|
13
|
+
exports.$insertBlockNode=function(a){var b=l.$getSelection();l.$isRangeSelection(b)?b.focus.getNode().getTopLevelElementOrThrow().insertAfter(a):l.$isNodeSelection(b)||l.$isGridSelection(b)?(b=b.getNodes(),b[b.length-1].getTopLevelElementOrThrow().insertAfter(a)):l.$getRoot().append(a);b=l.$createParagraphNode();a.insertAfter(b);b.select();return a.getLatest()};
|
|
14
|
+
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())};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
15
|
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
16
|
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,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
8
|
+
import { EditorState, ElementNode, Klass, LexicalEditor, LexicalNode } from 'lexical';
|
|
9
9
|
export declare type DFSNode = Readonly<{
|
|
10
10
|
depth: number;
|
|
11
11
|
node: LexicalNode;
|
|
@@ -13,7 +13,7 @@ export declare type DFSNode = Readonly<{
|
|
|
13
13
|
export declare function addClassNamesToElement(element: HTMLElement, ...classNames: Array<typeof undefined | boolean | null | string>): void;
|
|
14
14
|
export declare function removeClassNamesFromElement(element: HTMLElement, ...classNames: Array<typeof undefined | boolean | null | string>): void;
|
|
15
15
|
export declare function $dfs(startingNode?: LexicalNode, endingNode?: LexicalNode): Array<DFSNode>;
|
|
16
|
-
export declare function $getNearestNodeOfType<T extends ElementNode>(node: LexicalNode, klass: Klass<T>):
|
|
16
|
+
export declare function $getNearestNodeOfType<T extends ElementNode>(node: LexicalNode, klass: Klass<T>): T | null;
|
|
17
17
|
export declare function $getNearestBlockElementAncestorOrThrow(startNode: LexicalNode): ElementNode;
|
|
18
18
|
export declare type DOMNodeToLexicalConversion = (element: Node) => LexicalNode;
|
|
19
19
|
export declare type DOMNodeToLexicalConversionMap = Record<string, DOMNodeToLexicalConversion>;
|
|
@@ -23,4 +23,5 @@ export declare function mergeRegister(...func: Array<Func>): () => void;
|
|
|
23
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
24
|
export declare function unstable_convertLegacyJSONEditorState(editor: LexicalEditor, maybeStringifiedEditorState: string): EditorState;
|
|
25
25
|
export declare function $restoreEditorState(editor: LexicalEditor, editorState: EditorState): void;
|
|
26
|
+
export declare function $insertBlockNode<T extends LexicalNode>(node: T): T;
|
|
26
27
|
export {};
|
package/package.json
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
"utils"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.3.
|
|
11
|
+
"version": "0.3.10",
|
|
12
12
|
"main": "LexicalUtils.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.3.
|
|
14
|
+
"lexical": "0.3.10"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/list": "0.3.
|
|
18
|
-
"@lexical/table": "0.3.
|
|
17
|
+
"@lexical/list": "0.3.10",
|
|
18
|
+
"@lexical/table": "0.3.10"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|