@lexical/code 0.6.0 → 0.6.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.
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import { EditorConfig, LexicalNode, NodeKey, SerializedTextNode, Spread, TextNode } from 'lexical';
8
+ import { type EditorConfig, type LexicalNode, type NodeKey, type SerializedTextNode, type Spread, TextNode } from 'lexical';
9
9
  import 'prismjs/components/prism-clike';
10
10
  import 'prismjs/components/prism-javascript';
11
11
  import 'prismjs/components/prism-markup';
@@ -139,7 +139,7 @@ function getHighlightThemeClass(theme, highlightType) {
139
139
  }
140
140
 
141
141
  function $createCodeHighlightNode(text, highlightType) {
142
- return new CodeHighlightNode(text, highlightType);
142
+ return lexical.$applyNodeReplacement(new CodeHighlightNode(text, highlightType));
143
143
  }
144
144
  function $isCodeHighlightNode(node) {
145
145
  return node instanceof CodeHighlightNode;
@@ -416,7 +416,7 @@ class CodeNode extends lexical.ElementNode {
416
416
 
417
417
  }
418
418
  function $createCodeNode(language) {
419
- return new CodeNode(language);
419
+ return lexical.$applyNodeReplacement(new CodeNode(language));
420
420
  }
421
421
  function $isCodeNode(node) {
422
422
  return node instanceof CodeNode;
@@ -7,13 +7,13 @@
7
7
  'use strict';var e=require("prismjs");require("prismjs/components/prism-clike");require("prismjs/components/prism-javascript");require("prismjs/components/prism-markup");require("prismjs/components/prism-markdown");require("prismjs/components/prism-c");require("prismjs/components/prism-css");require("prismjs/components/prism-objectivec");require("prismjs/components/prism-sql");require("prismjs/components/prism-python");require("prismjs/components/prism-rust");require("prismjs/components/prism-swift");
8
8
  var n=require("@lexical/utils"),u=require("lexical");let v={c:"C",clike:"C-like",css:"CSS",html:"HTML",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",xml:"XML"},x={javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain"};function y(a){return x[a]||a}
9
9
  class z extends u.TextNode{constructor(a,b,c){super(a,c);this.__highlightType=b}static getType(){return"code-highlight"}static clone(a){return new z(a.__text,a.__highlightType||void 0,a.__key)}getHighlightType(){return this.getLatest().__highlightType}createDOM(a){let b=super.createDOM(a);a=A(a.theme,this.__highlightType);n.addClassNamesToElement(b,a);return b}updateDOM(a,b,c){let d=super.updateDOM(a,b,c);a=A(c.theme,a.__highlightType);c=A(c.theme,this.__highlightType);a!==c&&(a&&n.removeClassNamesFromElement(b,
10
- a),c&&n.addClassNamesToElement(b,c));return d}static importJSON(a){let b=B(a.text,a.highlightType);b.setFormat(a.format);b.setDetail(a.detail);b.setMode(a.mode);b.setStyle(a.style);return b}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType(),type:"code-highlight",version:1}}setFormat(){return this}}function A(a,b){return b&&a&&a.codeHighlight&&a.codeHighlight[b]}function B(a,b){return new z(a,b)}function C(a){return a instanceof z}
10
+ a),c&&n.addClassNamesToElement(b,c));return d}static importJSON(a){let b=B(a.text,a.highlightType);b.setFormat(a.format);b.setDetail(a.detail);b.setMode(a.mode);b.setStyle(a.style);return b}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType(),type:"code-highlight",version:1}}setFormat(){return this}}function A(a,b){return b&&a&&a.codeHighlight&&a.codeHighlight[b]}function B(a,b){return u.$applyNodeReplacement(new z(a,b))}function C(a){return a instanceof z}
11
11
  function D(a){let b=null,c=a.getPreviousSiblings();for(c.push(a);0<c.length&&(a=c.pop(),C(a)&&(b=a),!u.$isLineBreakNode(a)););return b}function E(a){let b=null,c=a.getNextSiblings();for(c.unshift(a);0<c.length&&(a=c.shift(),C(a)&&(b=a),!u.$isLineBreakNode(a)););return b}let F=a=>null!=a&&e.languages.hasOwnProperty(a)?a:void 0;function G(a,b){for(let c of a.childNodes){if(c instanceof HTMLElement&&c.tagName===b)return!0;G(c,b)}return!1}
12
12
  class H extends u.ElementNode{static getType(){return"code"}static clone(a){return new H(a.__language,a.__key)}constructor(a,b){super(b);this.__language=F(a)}createDOM(a){let b=document.createElement("code");n.addClassNamesToElement(b,a.theme.code);b.setAttribute("spellcheck","false");(a=this.getLanguage())&&b.setAttribute("data-highlight-language",a);return b}updateDOM(a,b){let c=this.__language;a=a.__language;c?c!==a&&b.setAttribute("data-highlight-language",c):a&&b.removeAttribute("data-highlight-language");
13
13
  return!1}static importDOM(){return{code:a=>null!=a.textContent&&(/\r?\n/.test(a.textContent)||G(a,"BR"))?{conversion:I,priority:1}:null,div:()=>({conversion:aa,priority:1}),pre:()=>({conversion:I,priority:0}),table:a=>J(a)?{conversion:ba,priority:4}:null,td:a=>{let b=a.closest("table");return a.classList.contains("js-file-line")?{conversion:ca,priority:4}:b&&J(b)?{conversion:K,priority:4}:null},tr:a=>(a=a.closest("table"))&&J(a)?{conversion:K,priority:4}:null}}static importJSON(a){let b=L(a.language);
14
14
  b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),type:"code",version:1}}insertNewAfter(a){var b=this.getChildren(),c=b.length;if(2<=c&&"\n"===b[c-1].getTextContent()&&"\n"===b[c-2].getTextContent()&&a.isCollapsed()&&a.anchor.key===this.__key&&a.anchor.offset===c)return b[c-1].remove(),b[c-2].remove(),a=u.$createParagraphNode(),this.insertAfter(a),a;b=a.anchor.getNode();var d=D(b);if(null!=d){c=0;
15
15
  for(d=d.getTextContent();c<d.length&&/[\t ]/.test(d[c]);)c+=1;if(0<c)return c=d.substring(0,c),c=B(c),b.insertAfter(c),a.insertNodes([u.$createLineBreakNode()]),c.select(),c}return null}canInsertTab(){let a=u.$getSelection();return u.$isRangeSelection(a)&&a.isCollapsed()?!0:!1}canIndent(){return!1}collapseAtStart(){let a=u.$createParagraphNode();this.getChildren().forEach(b=>a.append(b));this.replace(a);return!0}setLanguage(a){this.getWritable().__language=F(a)}getLanguage(){return this.getLatest().__language}}
16
- function L(a){return new H(a)}function M(a){return a instanceof H}function I(){return{node:L(),preformatted:!0}}function aa(a){let b=null!==a.style.fontFamily.match("monospace");return b||da(a)?{after:c=>{let d=a.parentNode;null!=d&&a!==d.lastChild&&c.push(u.$createLineBreakNode());return c},node:b?L():null,preformatted:b}:{node:null}}function ba(){return{node:L(),preformatted:!0}}function K(){return{node:null}}
16
+ function L(a){return u.$applyNodeReplacement(new H(a))}function M(a){return a instanceof H}function I(){return{node:L(),preformatted:!0}}function aa(a){let b=null!==a.style.fontFamily.match("monospace");return b||da(a)?{after:c=>{let d=a.parentNode;null!=d&&a!==d.lastChild&&c.push(u.$createLineBreakNode());return c},node:b?L():null,preformatted:b}:{node:null}}function ba(){return{node:L(),preformatted:!0}}function K(){return{node:null}}
17
17
  function ca(a){return{after:b=>{a.parentNode&&a.parentNode.nextSibling&&b.push(u.$createLineBreakNode());return b},node:null}}function da(a){for(a=a.parentElement;null!==a;){if(null!==a.style.fontFamily.match("monospace"))return!0;a=a.parentElement}return!1}function J(a){return a.classList.contains("js-file-line-container")}let N={tokenize(a,b){return e.tokenize(a,e.languages[b||""]||e.languages.javascript)}};
18
18
  function O(a,b){var c=a.length;let d=-1;if(b)for(b=0;b<c;b++){let f=a[b];if(" "!==f&&"\t"!==f){d=b;break}}else for(--c;-1<c;c--)if(b=a[c]," "!==b&&"\t"!==b){d=c;break}return d}
19
19
  function P(a){let b=null,c=-1;var d=a.getPreviousSiblings();for(d.push(a);0<d.length;){var f=d.pop();if(C(f)){var g=f.getTextContent();g=O(g,!0);-1!==g&&(b=f,c=g)}if(u.$isLineBreakNode(f))break}if(null===b)for(a=a.getNextSiblings();0<a.length;){d=a.shift();if(C(d)&&(f=d.getTextContent(),f=O(f,!0),-1!==f)){b=d;c=f;break}if(u.$isLineBreakNode(d))break}return{node:b,offset:c}}
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "code"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.6.0",
11
+ "version": "0.6.2",
12
12
  "main": "LexicalCode.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.6.0"
14
+ "lexical": "0.6.2"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.6.0",
17
+ "@lexical/utils": "0.6.2",
18
18
  "prismjs": "^1.27.0"
19
19
  },
20
20
  "repository": {