@lexical/code 0.2.1 → 0.2.2
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/LexicalCode.d.ts +71 -0
- package/LexicalCode.dev.js +1 -1
- package/LexicalCode.js.flow +4 -4
- package/LexicalCode.prod.js +2 -1
- package/package.json +3 -3
package/LexicalCode.d.ts
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
|
|
10
|
+
import type {
|
|
11
|
+
EditorConfig,
|
|
12
|
+
LexicalNode,
|
|
13
|
+
NodeKey,
|
|
14
|
+
ParagraphNode,
|
|
15
|
+
RangeSelection,
|
|
16
|
+
EditorThemeClasses,
|
|
17
|
+
LexicalEditor,
|
|
18
|
+
} from 'lexical';
|
|
19
|
+
|
|
20
|
+
import {ElementNode, TextNode} from 'lexical';
|
|
21
|
+
|
|
22
|
+
declare class CodeNode extends ElementNode {
|
|
23
|
+
static getType(): string;
|
|
24
|
+
static clone(node: CodeNode): CodeNode;
|
|
25
|
+
constructor(key?: NodeKey);
|
|
26
|
+
createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement;
|
|
27
|
+
updateDOM(prevNode: CodeNode, dom: HTMLElement): boolean;
|
|
28
|
+
insertNewAfter(
|
|
29
|
+
selection: RangeSelection,
|
|
30
|
+
): null | ParagraphNode | CodeHighlightNode;
|
|
31
|
+
canInsertTab(): true;
|
|
32
|
+
collapseAtStart(): true;
|
|
33
|
+
setLanguage(language: string): void;
|
|
34
|
+
getLanguage(): string | void;
|
|
35
|
+
}
|
|
36
|
+
declare function $createCodeNode(): CodeNode;
|
|
37
|
+
declare function $isCodeNode(node: null | undefined | LexicalNode): boolean;
|
|
38
|
+
|
|
39
|
+
declare function getFirstCodeHighlightNodeOfLine(
|
|
40
|
+
anchor: LexicalNode,
|
|
41
|
+
): null | undefined | CodeHighlightNode;
|
|
42
|
+
|
|
43
|
+
declare function getLastCodeHighlightNodeOfLine(
|
|
44
|
+
anchor: LexicalNode,
|
|
45
|
+
): null | undefined | CodeHighlightNode;
|
|
46
|
+
|
|
47
|
+
declare class CodeHighlightNode extends TextNode {
|
|
48
|
+
__highlightType: null | undefined | string;
|
|
49
|
+
constructor(text: string, highlightType?: string, key?: NodeKey);
|
|
50
|
+
static getType(): string;
|
|
51
|
+
static clone(node: CodeHighlightNode): CodeHighlightNode;
|
|
52
|
+
createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement;
|
|
53
|
+
updateDOM<EditorContext>(
|
|
54
|
+
// $FlowFixMe
|
|
55
|
+
prevNode: CodeHighlightNode,
|
|
56
|
+
dom: HTMLElement,
|
|
57
|
+
config: EditorConfig<EditorContext>,
|
|
58
|
+
): boolean;
|
|
59
|
+
setFormat(format: number): this;
|
|
60
|
+
}
|
|
61
|
+
declare function getHighlightThemeClass(
|
|
62
|
+
theme: EditorThemeClasses,
|
|
63
|
+
highlightType: null | undefined | string,
|
|
64
|
+
): null | undefined | string;
|
|
65
|
+
declare function $createCodeHighlightNode(
|
|
66
|
+
text: string,
|
|
67
|
+
highlightType?: string,
|
|
68
|
+
): CodeHighlightNode;
|
|
69
|
+
declare function $isCodeHighlightNode(node: ?LexicalNode): boolean;
|
|
70
|
+
|
|
71
|
+
declare function registerCodeHighlighting(editor: LexicalEditor): () => void;
|
package/LexicalCode.dev.js
CHANGED
|
@@ -789,7 +789,7 @@ function registerCodeHighlighting(editor) {
|
|
|
789
789
|
}
|
|
790
790
|
}
|
|
791
791
|
});
|
|
792
|
-
}), editor.registerNodeTransform(CodeNode, node => codeNodeTransform(node, editor)), editor.registerNodeTransform(lexical.TextNode, node => textNodeTransform(node, editor)), editor.registerNodeTransform(CodeHighlightNode, node => textNodeTransform(node, editor)), editor.registerCommand(lexical.INDENT_CONTENT_COMMAND, payload => handleMultilineIndent(lexical.INDENT_CONTENT_COMMAND),
|
|
792
|
+
}), editor.registerNodeTransform(CodeNode, node => codeNodeTransform(node, editor)), editor.registerNodeTransform(lexical.TextNode, node => textNodeTransform(node, editor)), editor.registerNodeTransform(CodeHighlightNode, node => textNodeTransform(node, editor)), editor.registerCommand(lexical.INDENT_CONTENT_COMMAND, payload => handleMultilineIndent(lexical.INDENT_CONTENT_COMMAND), lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND, payload => handleMultilineIndent(lexical.OUTDENT_CONTENT_COMMAND), lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ARROW_UP_COMMAND, payload => handleShiftLines(lexical.KEY_ARROW_UP_COMMAND, payload), lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND, payload => handleShiftLines(lexical.KEY_ARROW_DOWN_COMMAND, payload), lexical.COMMAND_PRIORITY_LOW));
|
|
793
793
|
}
|
|
794
794
|
|
|
795
795
|
exports.$createCodeHighlightNode = $createCodeHighlightNode;
|
package/LexicalCode.js.flow
CHANGED
|
@@ -17,7 +17,7 @@ import type {
|
|
|
17
17
|
LexicalEditor,
|
|
18
18
|
} from 'lexical';
|
|
19
19
|
|
|
20
|
-
import {ElementNode} from 'lexical';
|
|
20
|
+
import {ElementNode, TextNode} from 'lexical';
|
|
21
21
|
|
|
22
22
|
declare export class CodeNode extends ElementNode {
|
|
23
23
|
static getType(): string;
|
|
@@ -46,8 +46,6 @@ declare export function getLastCodeHighlightNodeOfLine(
|
|
|
46
46
|
anchor: LexicalNode,
|
|
47
47
|
): ?CodeHighlightNode;
|
|
48
48
|
|
|
49
|
-
import {TextNode} from 'lexical';
|
|
50
|
-
|
|
51
49
|
declare export class CodeHighlightNode extends TextNode {
|
|
52
50
|
__highlightType: ?string;
|
|
53
51
|
constructor(text: string, highlightType?: string, key?: NodeKey): void;
|
|
@@ -74,4 +72,6 @@ declare export function $isCodeHighlightNode(
|
|
|
74
72
|
node: ?LexicalNode,
|
|
75
73
|
): boolean %checks(node instanceof CodeHighlightNode);
|
|
76
74
|
|
|
77
|
-
declare export function registerCodeHighlighting(
|
|
75
|
+
declare export function registerCodeHighlighting(
|
|
76
|
+
editor: LexicalEditor,
|
|
77
|
+
): () => void;
|
package/LexicalCode.prod.js
CHANGED
|
@@ -24,4 +24,5 @@ c.preventDefault(),!0;return!1}var p=H(g);const v=K(k);if(null==p||null==v)retur
|
|
|
24
24
|
w.insertBefore(c)):(w.insertAfter(c),w=c,A.forEach(q=>{w.insertAfter(q);w=q}));b.setTextNodeRange(g,h,k,m);return!0}exports.$createCodeHighlightNode=x;exports.$createCodeNode=I;exports.$isCodeHighlightNode=y;exports.$isCodeNode=J;exports.CodeHighlightNode=t;exports.CodeNode=z;exports.getCodeLanguages=()=>Object.keys(e.languages).filter(a=>"function"!==typeof e.languages[a]).sort();exports.getDefaultCodeLanguage=()=>"javascript";exports.getFirstCodeHighlightNodeOfLine=H;
|
|
25
25
|
exports.getLastCodeHighlightNodeOfLine=K;
|
|
26
26
|
exports.registerCodeHighlighting=function(a){if(!a.hasNodes([z,t]))throw Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return n.mergeRegister(a.registerMutationListener(z,c=>{a.update(()=>{for(const [f,h]of c)if("destroyed"!==h){var b=r.$getNodeByKey(f);if(null!==b)a:{var d=b;b=a.getElementByKey(d.getKey());if(null===b)break a;d=d.getChildren();const m=d.length;if(m===b.__cachedChildrenLength)break a;b.__cachedChildrenLength=m;let g="1",k=1;for(let l=0;l<m;l++)r.$isLineBreakNode(d[l])&&
|
|
27
|
-
(g+="\n"+ ++k);b.setAttribute("data-gutter",g)}}})}),a.registerNodeTransform(z,c=>M(c,a)),a.registerNodeTransform(r.TextNode,c=>L(c,a)),a.registerNodeTransform(t,c=>L(c,a)),a.registerCommand(r.INDENT_CONTENT_COMMAND,()=>S(r.INDENT_CONTENT_COMMAND),
|
|
27
|
+
(g+="\n"+ ++k);b.setAttribute("data-gutter",g)}}})}),a.registerNodeTransform(z,c=>M(c,a)),a.registerNodeTransform(r.TextNode,c=>L(c,a)),a.registerNodeTransform(t,c=>L(c,a)),a.registerCommand(r.INDENT_CONTENT_COMMAND,()=>S(r.INDENT_CONTENT_COMMAND),r.COMMAND_PRIORITY_LOW),a.registerCommand(r.OUTDENT_CONTENT_COMMAND,()=>S(r.OUTDENT_CONTENT_COMMAND),r.COMMAND_PRIORITY_LOW),a.registerCommand(r.KEY_ARROW_UP_COMMAND,c=>U(r.KEY_ARROW_UP_COMMAND,c),r.COMMAND_PRIORITY_LOW),a.registerCommand(r.KEY_ARROW_DOWN_COMMAND,
|
|
28
|
+
c=>U(r.KEY_ARROW_DOWN_COMMAND,c),r.COMMAND_PRIORITY_LOW))};
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"code"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.2.
|
|
11
|
+
"version": "0.2.2",
|
|
12
12
|
"main": "LexicalCode.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.2.
|
|
14
|
+
"lexical": "0.2.2"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.2.
|
|
17
|
+
"@lexical/utils": "0.2.2",
|
|
18
18
|
"prismjs": "^1.27.0"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|