@lexical/code 0.7.9 → 0.8.1

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.
@@ -18,6 +18,8 @@ import 'prismjs/components/prism-python';
18
18
  import 'prismjs/components/prism-rust';
19
19
  import 'prismjs/components/prism-swift';
20
20
  import 'prismjs/components/prism-typescript';
21
+ import 'prismjs/components/prism-java';
22
+ import 'prismjs/components/prism-cpp';
21
23
  export declare const DEFAULT_CODE_LANGUAGE = "javascript";
22
24
  declare type SerializedCodeHighlightNode = Spread<{
23
25
  highlightType: string | null | undefined;
@@ -18,6 +18,8 @@ import 'prismjs/components/prism-python';
18
18
  import 'prismjs/components/prism-rust';
19
19
  import 'prismjs/components/prism-swift';
20
20
  import 'prismjs/components/prism-typescript';
21
+ import 'prismjs/components/prism-java';
22
+ import 'prismjs/components/prism-cpp';
21
23
  import { TextNode } from 'lexical';
22
24
  declare type TokenContent = string | Token | (string | Token)[];
23
25
  export interface Token {
package/CodeNode.d.ts CHANGED
@@ -19,6 +19,8 @@ import 'prismjs/components/prism-python';
19
19
  import 'prismjs/components/prism-rust';
20
20
  import 'prismjs/components/prism-swift';
21
21
  import 'prismjs/components/prism-typescript';
22
+ import 'prismjs/components/prism-java';
23
+ import 'prismjs/components/prism-cpp';
22
24
  import { ElementNode } from 'lexical';
23
25
  export declare type SerializedCodeNode = Spread<{
24
26
  language: string | null | undefined;
@@ -19,6 +19,8 @@ require('prismjs/components/prism-python');
19
19
  require('prismjs/components/prism-rust');
20
20
  require('prismjs/components/prism-swift');
21
21
  require('prismjs/components/prism-typescript');
22
+ require('prismjs/components/prism-java');
23
+ require('prismjs/components/prism-cpp');
22
24
  var utils = require('@lexical/utils');
23
25
  var lexical = require('lexical');
24
26
 
@@ -35,7 +37,7 @@ const mapToPrismLanguage = language => {
35
37
  };
36
38
  function hasChildDOMNodeTag(node, tagName) {
37
39
  for (const child of node.childNodes) {
38
- if (child instanceof HTMLElement && child.tagName === tagName) {
40
+ if (utils.isHTMLElement(child) && child.tagName === tagName) {
39
41
  return true;
40
42
  }
41
43
  hasChildDOMNodeTag(child, tagName);
@@ -311,8 +313,10 @@ const DEFAULT_CODE_LANGUAGE = 'javascript';
311
313
  const CODE_LANGUAGE_FRIENDLY_NAME_MAP = {
312
314
  c: 'C',
313
315
  clike: 'C-like',
316
+ cpp: 'C++',
314
317
  css: 'CSS',
315
318
  html: 'HTML',
319
+ java: 'Java',
316
320
  js: 'JavaScript',
317
321
  markdown: 'Markdown',
318
322
  objc: 'Objective-C',
@@ -325,6 +329,8 @@ const CODE_LANGUAGE_FRIENDLY_NAME_MAP = {
325
329
  xml: 'XML'
326
330
  };
327
331
  const CODE_LANGUAGE_MAP = {
332
+ cpp: 'cpp',
333
+ java: 'java',
328
334
  javascript: 'js',
329
335
  md: 'markdown',
330
336
  plaintext: 'plain',
@@ -5,14 +5,14 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
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
- require("prismjs/components/prism-typescript");var n=require("@lexical/utils"),u=require("lexical");let v=a=>null!=a&&e.languages.hasOwnProperty(a)?a:void 0;function x(a,b){for(let c of a.childNodes){if(c instanceof HTMLElement&&c.tagName===b)return!0;x(c,b)}return!1}
8
+ require("prismjs/components/prism-typescript");require("prismjs/components/prism-java");require("prismjs/components/prism-cpp");var n=require("@lexical/utils"),u=require("lexical");let v=a=>null!=a&&e.languages.hasOwnProperty(a)?a:void 0;function x(a,b){for(let c of a.childNodes){if(n.isHTMLElement(c)&&c.tagName===b)return!0;x(c,b)}return!1}
9
9
  class y extends u.ElementNode{static getType(){return"code"}static clone(a){return new y(a.__language,a.__key)}constructor(a,b){super(b);this.__language=v(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");
10
10
  return!1}static importDOM(){return{code:a=>null!=a.textContent&&(/\r?\n/.test(a.textContent)||x(a,"BR"))?{conversion:z,priority:1}:null,div:()=>({conversion:aa,priority:1}),pre:()=>({conversion:z,priority:0}),table:a=>A(a)?{conversion:ba,priority:3}:null,td:a=>{let b=a.closest("table");return a.classList.contains("js-file-line")?{conversion:ca,priority:3}:b&&A(b)?{conversion:B,priority:3}:null},tr:a=>(a=a.closest("table"))&&A(a)?{conversion:B,priority:3}:null}}static importJSON(a){let b=C(a.language);
11
11
  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,b=!0){var c=this.getChildren(),d=c.length;if(2<=d&&"\n"===c[d-1].getTextContent()&&"\n"===c[d-2].getTextContent()&&a.isCollapsed()&&a.anchor.key===this.__key&&a.anchor.offset===d)return c[d-1].remove(),c[d-2].remove(),a=u.$createParagraphNode(),this.insertAfter(a,b),a;b=a.anchor.getNode();d=D(b);if(null!=d){c=
12
12
  0;for(d=d.getTextContent();c<d.length&&/[\t ]/.test(d[c]);)c+=1;if(0<c)return c=d.substring(0,c),c=E(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=v(a)}getLanguage(){return this.getLatest().__language}}
13
13
  function C(a){return u.$applyNodeReplacement(new y(a))}function F(a){return a instanceof y}function z(){return{node:C(),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?C():null,preformatted:b}:{node:null}}function ba(){return{node:C(),preformatted:!0}}function B(){return{node:null}}
14
14
  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 A(a){return a.classList.contains("js-file-line-container")}
15
- let G={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",typescript:"TypeScript",xml:"XML"},H={javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function I(a){return H[a]||a}
15
+ let G={c:"C",clike:"C-like",cpp:"C++",css:"CSS",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},H={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function I(a){return H[a]||a}
16
16
  class J extends u.TextNode{constructor(a,b,c){super(a,c);this.__highlightType=b}static getType(){return"code-highlight"}static clone(a){return new J(a.__text,a.__highlightType||void 0,a.__key)}getHighlightType(){return this.getLatest().__highlightType}createDOM(a){let b=super.createDOM(a);a=K(a.theme,this.__highlightType);n.addClassNamesToElement(b,a);return b}updateDOM(a,b,c){let d=super.updateDOM(a,b,c);a=K(c.theme,a.__highlightType);c=K(c.theme,this.__highlightType);a!==c&&(a&&n.removeClassNamesFromElement(b,
17
17
  a),c&&n.addClassNamesToElement(b,c));return d}static importJSON(a){let b=E(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}isParentRequired(){return!0}createParentElementNode(){return C()}}function K(a,b){return b&&a&&a.codeHighlight&&a.codeHighlight[b]}
18
18
  function E(a,b){return u.$applyNodeReplacement(new J(a,b))}function L(a){return a instanceof J}function D(a){let b=null,c=a.getPreviousSiblings();for(c.push(a);0<c.length&&(a=c.pop(),L(a)&&(b=a),!u.$isLineBreakNode(a)););return b}function M(a){let b=null,c=a.getNextSiblings();for(c.unshift(a);0<c.length&&(a=c.shift(),L(a)&&(b=a),!u.$isLineBreakNode(a)););return b}let N={defaultLanguage:"javascript",tokenize(a,b){return e.tokenize(a,e.languages[b||""]||e.languages[this.defaultLanguage])}};
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "code"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.7.9",
11
+ "version": "0.8.1",
12
12
  "main": "LexicalCode.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.7.9"
14
+ "lexical": "0.8.1"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.7.9",
17
+ "@lexical/utils": "0.8.1",
18
18
  "prismjs": "^1.27.0"
19
19
  },
20
20
  "repository": {