@lexical/code 0.2.1 → 0.2.4

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 CHANGED
@@ -0,0 +1,78 @@
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(
38
+ node: null | undefined | LexicalNode,
39
+ ): node is CodeNode;
40
+
41
+ declare function getFirstCodeHighlightNodeOfLine(
42
+ anchor: LexicalNode,
43
+ ): null | undefined | CodeHighlightNode;
44
+
45
+ declare function getLastCodeHighlightNodeOfLine(
46
+ anchor: LexicalNode,
47
+ ): null | undefined | CodeHighlightNode;
48
+
49
+ declare function getDefaultCodeLanguage(): string;
50
+ declare function getCodeLanguages(): Array<string>;
51
+
52
+ declare class CodeHighlightNode extends TextNode {
53
+ __highlightType: null | undefined | string;
54
+ constructor(text: string, highlightType?: string, key?: NodeKey);
55
+ static getType(): string;
56
+ static clone(node: CodeHighlightNode): CodeHighlightNode;
57
+ createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement;
58
+ updateDOM<EditorContext>(
59
+ // $FlowFixMe
60
+ prevNode: CodeHighlightNode,
61
+ dom: HTMLElement,
62
+ config: EditorConfig<EditorContext>,
63
+ ): boolean;
64
+ setFormat(format: number): this;
65
+ }
66
+ declare function getHighlightThemeClass(
67
+ theme: EditorThemeClasses,
68
+ highlightType: null | undefined | string,
69
+ ): null | undefined | string;
70
+ declare function $createCodeHighlightNode(
71
+ text: string,
72
+ highlightType?: string,
73
+ ): CodeHighlightNode;
74
+ declare function $isCodeHighlightNode(
75
+ node: ?LexicalNode,
76
+ ): node is CodeHighlightNode;
77
+
78
+ declare function registerCodeHighlighting(editor: LexicalEditor): () => void;
@@ -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), 1), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND, payload => handleMultilineIndent(lexical.OUTDENT_CONTENT_COMMAND), 1), editor.registerCommand(lexical.KEY_ARROW_UP_COMMAND, payload => handleShiftLines(lexical.KEY_ARROW_UP_COMMAND, payload), 1), editor.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND, payload => handleShiftLines(lexical.KEY_ARROW_DOWN_COMMAND, payload), 1));
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;
@@ -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,7 +46,8 @@ declare export function getLastCodeHighlightNodeOfLine(
46
46
  anchor: LexicalNode,
47
47
  ): ?CodeHighlightNode;
48
48
 
49
- import {TextNode} from 'lexical';
49
+ declare export function getDefaultCodeLanguage(): string;
50
+ declare export function getCodeLanguages(): Array<string>;
50
51
 
51
52
  declare export class CodeHighlightNode extends TextNode {
52
53
  __highlightType: ?string;
@@ -74,4 +75,6 @@ declare export function $isCodeHighlightNode(
74
75
  node: ?LexicalNode,
75
76
  ): boolean %checks(node instanceof CodeHighlightNode);
76
77
 
77
- declare export function registerCodeHighlighting(editor: LexicalEditor): () => void;
78
+ declare export function registerCodeHighlighting(
79
+ editor: LexicalEditor,
80
+ ): () => void;
@@ -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),1),a.registerCommand(r.OUTDENT_CONTENT_COMMAND,()=>S(r.OUTDENT_CONTENT_COMMAND),1),a.registerCommand(r.KEY_ARROW_UP_COMMAND,c=>U(r.KEY_ARROW_UP_COMMAND,c),1),a.registerCommand(r.KEY_ARROW_DOWN_COMMAND,c=>U(r.KEY_ARROW_DOWN_COMMAND,c),1))};
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.1",
11
+ "version": "0.2.4",
12
12
  "main": "LexicalCode.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.2.1"
14
+ "lexical": "0.2.4"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.2.1",
17
+ "@lexical/utils": "0.2.4",
18
18
  "prismjs": "^1.27.0"
19
19
  },
20
20
  "repository": {