@lexical/code 0.3.5 → 0.3.6

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.
@@ -1001,6 +1001,7 @@ function handleMoveTo(type, event) {
1001
1001
 
1002
1002
  event.preventDefault();
1003
1003
  event.stopPropagation();
1004
+ return true;
1004
1005
  }
1005
1006
 
1006
1007
  function registerCodeHighlighting(editor) {
@@ -24,8 +24,8 @@ function V(a,b){return z(a)&&z(b)?a.__text===b.__text&&a.__highlightType===b.__h
24
24
  function X(a,b){let c=a.getTextContent();b===r.INDENT_CONTENT_COMMAND?0<c.length&&/\s/.test(c[0])?a.setTextContent("\t"+c):(b=y("\t"),a.insertBefore(b)):0===c.indexOf("\t")&&(1===c.length?a.remove():a.setTextContent(c.substring(1)))}
25
25
  function Y(a,b){let c=r.$getSelection();if(!r.$isRangeSelection(c))return!1;let {anchor:d,focus:f}=c,g=d.offset,l=f.offset,h=d.getNode(),k=f.getNode();var n=a===r.KEY_ARROW_UP_COMMAND;if(!z(h)||!z(k))return!1;if(!b.altKey){if(c.isCollapsed())if(a=h.getParentOrThrow(),n&&0===g&&null===h.getPreviousSibling()){if(null===a.getPreviousSibling())return a.selectPrevious(),b.preventDefault(),!0}else if(!n&&g===h.getTextContentSize()&&null===h.getNextSibling()&&null===a.getNextSibling())return a.selectNext(),
26
26
  b.preventDefault(),!0;return!1}var p=J(h);let w=L(k);if(null==p||null==w)return!1;let B=p.getNodesBetween(w);for(let q=0;q<B.length;q++){let U=B[q];if(!z(U)&&!r.$isLineBreakNode(U))return!1}b.preventDefault();b.stopPropagation();b=n?p.getPreviousSibling():w.getNextSibling();if(!r.$isLineBreakNode(b))return!0;p=n?b.getPreviousSibling():b.getNextSibling();if(null==p)return!0;n=n?J(p):L(p);let x=null!=n?n:p;b.remove();B.forEach(q=>q.remove());a===r.KEY_ARROW_UP_COMMAND?(B.forEach(q=>x.insertBefore(q)),
27
- x.insertBefore(b)):(x.insertAfter(b),x=b,B.forEach(q=>{x.insertAfter(q);x=q}));c.setTextNodeRange(h,g,k,l);return!0}function Z(a,b){let c=r.$getSelection();if(!r.$isRangeSelection(c))return!1;let {anchor:d,focus:f}=c,g=d.getNode(),l=f.getNode();a=a===r.MOVE_TO_START;if(!z(g)||!z(l))return!1;let h,k;a?{node:h,offset:k}=N(l):{node:h,offset:k}=O(l);null!==h&&-1!==k&&c.setTextNodeRange(h,k,h,k);b.preventDefault();b.stopPropagation()}exports.$createCodeHighlightNode=y;exports.$createCodeNode=I;
28
- exports.$isCodeHighlightNode=z;exports.$isCodeNode=K;exports.CodeHighlightNode=u;exports.CodeNode=A;exports.getCodeLanguages=()=>Object.keys(e.languages).filter(a=>"function"!==typeof e.languages[a]).sort();exports.getDefaultCodeLanguage=()=>"javascript";exports.getEndOfCodeInLine=O;exports.getFirstCodeHighlightNodeOfLine=J;exports.getLastCodeHighlightNodeOfLine=L;exports.getStartOfCodeInLine=N;
27
+ x.insertBefore(b)):(x.insertAfter(b),x=b,B.forEach(q=>{x.insertAfter(q);x=q}));c.setTextNodeRange(h,g,k,l);return!0}function Z(a,b){let c=r.$getSelection();if(!r.$isRangeSelection(c))return!1;let {anchor:d,focus:f}=c,g=d.getNode(),l=f.getNode();a=a===r.MOVE_TO_START;if(!z(g)||!z(l))return!1;let h,k;a?{node:h,offset:k}=N(l):{node:h,offset:k}=O(l);null!==h&&-1!==k&&c.setTextNodeRange(h,k,h,k);b.preventDefault();b.stopPropagation();return!0}exports.$createCodeHighlightNode=y;
28
+ exports.$createCodeNode=I;exports.$isCodeHighlightNode=z;exports.$isCodeNode=K;exports.CodeHighlightNode=u;exports.CodeNode=A;exports.getCodeLanguages=()=>Object.keys(e.languages).filter(a=>"function"!==typeof e.languages[a]).sort();exports.getDefaultCodeLanguage=()=>"javascript";exports.getEndOfCodeInLine=O;exports.getFirstCodeHighlightNodeOfLine=J;exports.getLastCodeHighlightNodeOfLine=L;exports.getStartOfCodeInLine=N;
29
29
  exports.registerCodeHighlighting=function(a){if(!a.hasNodes([A,u]))throw Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return m.mergeRegister(a.registerMutationListener(A,b=>{a.update(()=>{for(let [f,g]of b)if("destroyed"!==g){var c=r.$getNodeByKey(f);if(null!==c)a:{var d=c;c=a.getElementByKey(d.getKey());if(null===c)break a;d=d.getChildren();let l=d.length;if(l===c.__cachedChildrenLength)break a;c.__cachedChildrenLength=l;let h="1",k=1;for(let n=0;n<l;n++)r.$isLineBreakNode(d[n])&&
30
30
  (h+="\n"+ ++k);c.setAttribute("data-gutter",h)}}})}),a.registerNodeTransform(A,b=>Q(b,a)),a.registerNodeTransform(r.TextNode,b=>P(b,a)),a.registerNodeTransform(u,b=>P(b,a)),a.registerCommand(r.INDENT_CONTENT_COMMAND,()=>W(r.INDENT_CONTENT_COMMAND),r.COMMAND_PRIORITY_LOW),a.registerCommand(r.OUTDENT_CONTENT_COMMAND,()=>W(r.OUTDENT_CONTENT_COMMAND),r.COMMAND_PRIORITY_LOW),a.registerCommand(r.KEY_ARROW_UP_COMMAND,b=>Y(r.KEY_ARROW_UP_COMMAND,b),r.COMMAND_PRIORITY_LOW),a.registerCommand(r.KEY_ARROW_DOWN_COMMAND,
31
31
  b=>Y(r.KEY_ARROW_DOWN_COMMAND,b),r.COMMAND_PRIORITY_LOW),a.registerCommand(r.MOVE_TO_END,b=>Z(r.MOVE_TO_END,b),r.COMMAND_PRIORITY_LOW),a.registerCommand(r.MOVE_TO_START,b=>Z(r.MOVE_TO_START,b),r.COMMAND_PRIORITY_LOW))}
package/index.d.ts CHANGED
@@ -32,7 +32,7 @@ export declare const getDefaultCodeLanguage: () => string;
32
32
  export declare const getCodeLanguages: () => Array<string>;
33
33
  export declare class CodeHighlightNode extends TextNode {
34
34
  __highlightType: string | null | undefined;
35
- constructor(text: string, highlightType?: string, key?: NodeKey);
35
+ constructor(text: string, highlightType?: string | null | undefined, key?: NodeKey);
36
36
  static getType(): string;
37
37
  static clone(node: CodeHighlightNode): CodeHighlightNode;
38
38
  getHighlightType(): string | null | undefined;
@@ -42,7 +42,7 @@ export declare class CodeHighlightNode extends TextNode {
42
42
  exportJSON(): SerializedCodeHighlightNode;
43
43
  setFormat(format: number): this;
44
44
  }
45
- export declare function $createCodeHighlightNode(text: string, highlightType?: string): CodeHighlightNode;
45
+ export declare function $createCodeHighlightNode(text: string, highlightType?: string | null | undefined): CodeHighlightNode;
46
46
  export declare function $isCodeHighlightNode(node: LexicalNode | CodeHighlightNode | null | undefined): node is CodeHighlightNode;
47
47
  export declare class CodeNode extends ElementNode {
48
48
  __language: string | null | undefined;
@@ -61,7 +61,7 @@ export declare class CodeNode extends ElementNode {
61
61
  setLanguage(language: string): void;
62
62
  getLanguage(): string | null | undefined;
63
63
  }
64
- export declare function $createCodeNode(language?: string): CodeNode;
64
+ export declare function $createCodeNode(language?: string | null | undefined): CodeNode;
65
65
  export declare function $isCodeNode(node: LexicalNode | null | undefined): node is CodeNode;
66
66
  export declare function getFirstCodeHighlightNodeOfLine(anchor: LexicalNode): CodeHighlightNode | null | undefined;
67
67
  export declare function getLastCodeHighlightNodeOfLine(anchor: LexicalNode): CodeHighlightNode | null | undefined;
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "code"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.3.5",
11
+ "version": "0.3.6",
12
12
  "main": "LexicalCode.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.3.5"
14
+ "lexical": "0.3.6"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.3.5",
17
+ "@lexical/utils": "0.3.6",
18
18
  "prismjs": "^1.27.0"
19
19
  },
20
20
  "repository": {