@lexical/utils 0.1.15 → 0.1.18
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/LICENSE +1 -1
- package/LexicalUtils.d.ts +39 -0
- package/LexicalUtils.dev.js +5 -13
- package/LexicalUtils.js.flow +40 -0
- package/LexicalUtils.prod.js +2 -3
- package/package.json +4 -8
package/LICENSE
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
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 {LexicalNode} from 'lexical';
|
|
9
|
+
export type DFSNode = $ReadOnly<{
|
|
10
|
+
depth: number;
|
|
11
|
+
node: LexicalNode;
|
|
12
|
+
}>;
|
|
13
|
+
declare function addClassNamesToElement(
|
|
14
|
+
element: HTMLElement,
|
|
15
|
+
...classNames: Array<typeof undefined | boolean | null | string>
|
|
16
|
+
): void;
|
|
17
|
+
declare function removeClassNamesFromElement(
|
|
18
|
+
element: HTMLElement,
|
|
19
|
+
...classNames: Array<string>
|
|
20
|
+
): void;
|
|
21
|
+
declare function $dfs(
|
|
22
|
+
startingNode?: LexicalNode,
|
|
23
|
+
endingNode?: LexicalNode,
|
|
24
|
+
): Array<DFSNode>;
|
|
25
|
+
declare function $getDepth(node: LexicalNode): number;
|
|
26
|
+
declare function $getNearestNodeOfType<T extends LexicalNode>(
|
|
27
|
+
node: LexicalNode,
|
|
28
|
+
klass: Class<T>,
|
|
29
|
+
): T | null;
|
|
30
|
+
export type DOMNodeToLexicalConversion = (element: Node) => LexicalNode;
|
|
31
|
+
export type DOMNodeToLexicalConversionMap = {
|
|
32
|
+
[string]: DOMNodeToLexicalConversion;
|
|
33
|
+
};
|
|
34
|
+
declare function $findMatchingParent(
|
|
35
|
+
startingNode: LexicalNode,
|
|
36
|
+
findFn: (LexicalNode) => boolean,
|
|
37
|
+
): LexicalNode | null;
|
|
38
|
+
type Func = () => void;
|
|
39
|
+
declare function mergeRegister(...func: Array<Func>): () => void;
|
package/LexicalUtils.dev.js
CHANGED
|
@@ -108,23 +108,15 @@ function $findMatchingParent(startingNode, findFn) {
|
|
|
108
108
|
|
|
109
109
|
return null;
|
|
110
110
|
}
|
|
111
|
-
function
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const previousSibling = node.getPreviousSibling();
|
|
116
|
-
return previousSibling === null || lexical.$isLineBreakNode(previousSibling) || lexical.$isTextNode(previousSibling) && previousSibling.isSimpleText() && previousSibling.getTextContent().endsWith(' ');
|
|
117
|
-
}
|
|
118
|
-
function $isNextSiblingNullOrSpace(node) {
|
|
119
|
-
const nextSibling = node.getNextSibling();
|
|
120
|
-
return nextSibling === null || lexical.$isLineBreakNode(nextSibling) || lexical.$isTextNode(nextSibling) && nextSibling.isSimpleText() && nextSibling.getTextContent().startsWith(' ');
|
|
111
|
+
function mergeRegister(...func) {
|
|
112
|
+
return () => {
|
|
113
|
+
func.forEach(f => f());
|
|
114
|
+
};
|
|
121
115
|
}
|
|
122
116
|
|
|
123
|
-
exports.$areSiblingsNullOrSpace = $areSiblingsNullOrSpace;
|
|
124
117
|
exports.$dfs = $dfs;
|
|
125
118
|
exports.$findMatchingParent = $findMatchingParent;
|
|
126
119
|
exports.$getNearestNodeOfType = $getNearestNodeOfType;
|
|
127
|
-
exports.$isNextSiblingNullOrSpace = $isNextSiblingNullOrSpace;
|
|
128
|
-
exports.$isPreviousSiblingNullOrSpace = $isPreviousSiblingNullOrSpace;
|
|
129
120
|
exports.addClassNamesToElement = addClassNamesToElement;
|
|
121
|
+
exports.mergeRegister = mergeRegister;
|
|
130
122
|
exports.removeClassNamesFromElement = removeClassNamesFromElement;
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
import type {LexicalNode} from 'lexical';
|
|
10
|
+
export type DFSNode = $ReadOnly<{
|
|
11
|
+
depth: number,
|
|
12
|
+
node: LexicalNode,
|
|
13
|
+
}>;
|
|
14
|
+
declare export function addClassNamesToElement(
|
|
15
|
+
element: HTMLElement,
|
|
16
|
+
...classNames: Array<typeof undefined | boolean | null | string>
|
|
17
|
+
): void;
|
|
18
|
+
declare export function removeClassNamesFromElement(
|
|
19
|
+
element: HTMLElement,
|
|
20
|
+
...classNames: Array<string>
|
|
21
|
+
): void;
|
|
22
|
+
declare export function $dfs(
|
|
23
|
+
startingNode?: LexicalNode,
|
|
24
|
+
endingNode?: LexicalNode,
|
|
25
|
+
): Array<DFSNode>;
|
|
26
|
+
declare function $getDepth(node: LexicalNode): number;
|
|
27
|
+
declare export function $getNearestNodeOfType<T: LexicalNode>(
|
|
28
|
+
node: LexicalNode,
|
|
29
|
+
klass: Class<T>,
|
|
30
|
+
): T | null;
|
|
31
|
+
export type DOMNodeToLexicalConversion = (element: Node) => LexicalNode;
|
|
32
|
+
export type DOMNodeToLexicalConversionMap = {
|
|
33
|
+
[string]: DOMNodeToLexicalConversion,
|
|
34
|
+
};
|
|
35
|
+
declare export function $findMatchingParent(
|
|
36
|
+
startingNode: LexicalNode,
|
|
37
|
+
findFn: (LexicalNode) => boolean,
|
|
38
|
+
): LexicalNode | null;
|
|
39
|
+
type Func = () => void;
|
|
40
|
+
declare export function mergeRegister(...func: Array<Func>): () => void;
|
package/LexicalUtils.prod.js
CHANGED
|
@@ -4,6 +4,5 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var
|
|
8
|
-
exports.$
|
|
9
|
-
exports.$findMatchingParent=function(a,b){for(;a!==d.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null};exports.$getNearestNodeOfType=function(a,b){for(;null!=a&&!(a instanceof b);)a=a.getParent();return a};exports.$isNextSiblingNullOrSpace=h;exports.$isPreviousSiblingNullOrSpace=g;exports.addClassNamesToElement=function(a,...b){b.forEach(c=>{null!=c&&"string"===typeof c&&a.classList.add(...c.split(" "))})};exports.removeClassNamesFromElement=function(a,...b){b.forEach(c=>{a.classList.remove(...c.split(" "))})};
|
|
7
|
+
var f=require("lexical");exports.$dfs=function(a,b){const c=[];a=(a||f.$getRoot()).getLatest();b=b||(f.$isElementNode(a)?a.getLastDescendant():a);for(var d=a,e=0;null!==(d=d.getParent());)e++;for(d=e;null!==a&&!a.is(b);)if(c.push({depth:d,node:a}),f.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild(),d++;else for(e=null;null===e&&null!==a;)e=a.getNextSibling(),null===e?(a=a.getParent(),d--):a=e;null!==a&&a.is(b)&&c.push({depth:d,node:a});return c};
|
|
8
|
+
exports.$findMatchingParent=function(a,b){for(;a!==f.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null};exports.$getNearestNodeOfType=function(a,b){for(;null!=a&&!(a instanceof b);)a=a.getParent();return a};exports.addClassNamesToElement=function(a,...b){b.forEach(c=>{null!=c&&"string"===typeof c&&a.classList.add(...c.split(" "))})};exports.mergeRegister=function(...a){return()=>{a.forEach(b=>b())}};exports.removeClassNamesFromElement=function(a,...b){b.forEach(c=>{a.classList.remove(...c.split(" "))})};
|
package/package.json
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lexical/utils",
|
|
3
|
-
"author": {
|
|
4
|
-
"name": "Dominic Gannaway",
|
|
5
|
-
"email": "dg@domgan.com"
|
|
6
|
-
},
|
|
7
3
|
"description": "This package contains misc utilities for Lexical.",
|
|
8
4
|
"keywords": [
|
|
9
5
|
"lexical",
|
|
@@ -12,14 +8,14 @@
|
|
|
12
8
|
"utils"
|
|
13
9
|
],
|
|
14
10
|
"license": "MIT",
|
|
15
|
-
"version": "0.1.
|
|
11
|
+
"version": "0.1.18",
|
|
16
12
|
"main": "LexicalUtils.js",
|
|
17
13
|
"peerDependencies": {
|
|
18
|
-
"lexical": "0.1.
|
|
14
|
+
"lexical": "0.1.18"
|
|
19
15
|
},
|
|
20
16
|
"dependencies": {
|
|
21
|
-
"@lexical/list": "0.1.
|
|
22
|
-
"@lexical/table": "0.1.
|
|
17
|
+
"@lexical/list": "0.1.18",
|
|
18
|
+
"@lexical/table": "0.1.18"
|
|
23
19
|
},
|
|
24
20
|
"repository": {
|
|
25
21
|
"type": "git",
|