@lexical/code-core 0.43.1-nightly.20260416.0 → 0.44.0

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.
@@ -1,3 +1,10 @@
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
+ */
1
8
  /**
2
9
  * Add code blocks to the editor (syntax highlighting provided separately)
3
10
  */
package/CodeNode.d.ts CHANGED
@@ -5,9 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { CodeHighlightNode } from '@lexical/code';
9
8
  import type { DOMConversionMap, DOMExportOutput, EditorConfig, LexicalEditor, LexicalNode, LexicalUpdateJSON, NodeKey, ParagraphNode, RangeSelection, SerializedElementNode, Spread, TabNode } from 'lexical';
10
9
  import { ElementNode } from 'lexical';
10
+ import { type CodeHighlightNode } from './CodeHighlightNode';
11
11
  export type SerializedCodeNode = Spread<{
12
12
  language: string | null | undefined;
13
13
  theme?: string | undefined;
@@ -45,3 +45,4 @@ export declare class CodeNode extends ElementNode {
45
45
  }
46
46
  export declare function $createCodeNode(language?: string | null | undefined, theme?: string | null | undefined): CodeNode;
47
47
  export declare function $isCodeNode(node: LexicalNode | null | undefined): node is CodeNode;
48
+ export declare function $exitCodeNodeOnEnter(selection: RangeSelection): null | ParagraphNode;
@@ -9,6 +9,28 @@
9
9
  'use strict';
10
10
 
11
11
  var lexical = require('lexical');
12
+ var extension = require('@lexical/extension');
13
+
14
+ /**
15
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
16
+ *
17
+ * This source code is licensed under the MIT license found in the
18
+ * LICENSE file in the root directory of this source tree.
19
+ *
20
+ */
21
+
22
+ /*@__INLINE__*/
23
+ function warnOnlyOnce(message) {
24
+ {
25
+ let run = false;
26
+ return () => {
27
+ if (!run) {
28
+ console.warn(message);
29
+ }
30
+ run = true;
31
+ };
32
+ }
33
+ }
12
34
 
13
35
  /**
14
36
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -192,6 +214,7 @@ function hasChildDOMNodeTag(node, tagName) {
192
214
  const LANGUAGE_DATA_ATTRIBUTE = 'data-language';
193
215
  const HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE = 'data-highlight-language';
194
216
  const THEME_DATA_ATTRIBUTE = 'data-theme';
217
+ const noExtensionDeprecation = warnOnlyOnce('Using CodeNode without CodeExtension is deprecated');
195
218
 
196
219
  /** @noInheritDoc */
197
220
  class CodeNode extends lexical.ElementNode {
@@ -238,7 +261,7 @@ class CodeNode extends lexical.ElementNode {
238
261
  }
239
262
  const style = this.getStyle();
240
263
  if (style) {
241
- element.setAttribute('style', style);
264
+ lexical.setDOMStyleFromCSS(element.style, style);
242
265
  }
243
266
  return element;
244
267
  }
@@ -276,12 +299,8 @@ class CodeNode extends lexical.ElementNode {
276
299
  }
277
300
  const style = this.__style;
278
301
  const prevStyle = prevNode.__style;
279
- if (style) {
280
- if (style !== prevStyle) {
281
- dom.setAttribute('style', style);
282
- }
283
- } else if (prevStyle) {
284
- dom.removeAttribute('style');
302
+ if (style !== prevStyle) {
303
+ lexical.setDOMStyleFromCSS(dom.style, style, prevStyle);
285
304
  }
286
305
  return false;
287
306
  }
@@ -302,7 +321,7 @@ class CodeNode extends lexical.ElementNode {
302
321
  }
303
322
  const style = this.getStyle();
304
323
  if (style) {
305
- element.setAttribute('style', style);
324
+ lexical.setDOMStyleFromCSS(element.style, style);
306
325
  }
307
326
  return {
308
327
  element
@@ -383,16 +402,13 @@ class CodeNode extends lexical.ElementNode {
383
402
 
384
403
  // Mutation
385
404
  insertNewAfter(selection, restoreSelection = true) {
386
- const children = this.getChildren();
387
- const childrenLength = children.length;
388
- if (childrenLength >= 2 && children[childrenLength - 1].getTextContent() === '\n' && children[childrenLength - 2].getTextContent() === '\n' && selection.isCollapsed() && selection.anchor.key === this.__key && selection.anchor.offset === childrenLength) {
389
- children[childrenLength - 1].remove();
390
- children[childrenLength - 2].remove();
391
- const newElement = lexical.$createParagraphNode();
392
- this.insertAfter(newElement, restoreSelection);
393
- return newElement;
405
+ if (!extension.getPeerDependencyFromEditor(lexical.$getEditor(), '@lexical/code')) {
406
+ noExtensionDeprecation();
407
+ const el = $exitCodeNodeOnEnter(selection);
408
+ if (el) {
409
+ return el;
410
+ }
394
411
  }
395
-
396
412
  // If the selection is within the codeblock, find all leading tabs and
397
413
  // spaces of the current line. Create a new line that has all those
398
414
  // tabs and spaces, such that leading indentation is preserved.
@@ -540,6 +556,27 @@ function isGitHubCodeCell(cell) {
540
556
  function isGitHubCodeTable(table) {
541
557
  return table.classList.contains('js-file-line-container');
542
558
  }
559
+ function $exitCodeNodeOnEnter(selection) {
560
+ const {
561
+ anchor
562
+ } = selection;
563
+ if (selection.isCollapsed() && anchor.type === 'element') {
564
+ const codeNode = anchor.getNode();
565
+ if ($isCodeNode(codeNode)) {
566
+ const childrenSize = codeNode.getChildrenSize();
567
+ if (childrenSize >= 2 && anchor.offset === childrenSize) {
568
+ const lastChild = codeNode.getLastChild();
569
+ if (lexical.$isLineBreakNode(lastChild) && lexical.$isLineBreakNode(lastChild.getPreviousSibling())) {
570
+ const newElement = lexical.$createParagraphNode();
571
+ codeNode.splice(childrenSize - 2, 2, []).insertAfter(newElement, false);
572
+ newElement.select();
573
+ return newElement;
574
+ }
575
+ }
576
+ }
577
+ }
578
+ return null;
579
+ }
543
580
 
544
581
  /**
545
582
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -641,12 +678,23 @@ function $isCodeHighlightNode(node) {
641
678
  *
642
679
  */
643
680
 
681
+
644
682
  /**
645
683
  * Add code blocks to the editor (syntax highlighting provided separately)
646
684
  */
647
685
  const CodeExtension = lexical.defineExtension({
648
686
  name: '@lexical/code',
649
- nodes: () => [CodeNode, CodeHighlightNode]
687
+ nodes: () => [CodeNode, CodeHighlightNode],
688
+ register(editor) {
689
+ return editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
690
+ const selection = lexical.$getSelection();
691
+ if (lexical.$isRangeSelection(selection) && $exitCodeNodeOnEnter(selection)) {
692
+ event.preventDefault();
693
+ return true;
694
+ }
695
+ return false;
696
+ }, lexical.COMMAND_PRIORITY_LOW);
697
+ }
650
698
  });
651
699
 
652
700
  exports.$createCodeHighlightNode = $createCodeHighlightNode;
@@ -6,7 +6,29 @@
6
6
  *
7
7
  */
8
8
 
9
- import { getTextDirection, $isElementNode, $isTabNode, $isLineBreakNode, $getSiblingCaret, $create, ElementNode, addClassNamesToElement, $createParagraphNode, $isTextNode, $createTabNode, $createLineBreakNode, isHTMLElement, $applyNodeReplacement, TextNode, removeClassNamesFromElement, defineExtension } from 'lexical';
9
+ import { getTextDirection, $isElementNode, $isTabNode, $isLineBreakNode, $getSiblingCaret, $create, ElementNode, addClassNamesToElement, setDOMStyleFromCSS, $getEditor, $isTextNode, $createTabNode, $createLineBreakNode, $createParagraphNode, isHTMLElement, $applyNodeReplacement, TextNode, removeClassNamesFromElement, defineExtension, KEY_ENTER_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW } from 'lexical';
10
+ import { getPeerDependencyFromEditor } from '@lexical/extension';
11
+
12
+ /**
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ *
18
+ */
19
+
20
+ /*@__INLINE__*/
21
+ function warnOnlyOnce(message) {
22
+ {
23
+ let run = false;
24
+ return () => {
25
+ if (!run) {
26
+ console.warn(message);
27
+ }
28
+ run = true;
29
+ };
30
+ }
31
+ }
10
32
 
11
33
  /**
12
34
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -190,6 +212,7 @@ function hasChildDOMNodeTag(node, tagName) {
190
212
  const LANGUAGE_DATA_ATTRIBUTE = 'data-language';
191
213
  const HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE = 'data-highlight-language';
192
214
  const THEME_DATA_ATTRIBUTE = 'data-theme';
215
+ const noExtensionDeprecation = warnOnlyOnce('Using CodeNode without CodeExtension is deprecated');
193
216
 
194
217
  /** @noInheritDoc */
195
218
  class CodeNode extends ElementNode {
@@ -236,7 +259,7 @@ class CodeNode extends ElementNode {
236
259
  }
237
260
  const style = this.getStyle();
238
261
  if (style) {
239
- element.setAttribute('style', style);
262
+ setDOMStyleFromCSS(element.style, style);
240
263
  }
241
264
  return element;
242
265
  }
@@ -274,12 +297,8 @@ class CodeNode extends ElementNode {
274
297
  }
275
298
  const style = this.__style;
276
299
  const prevStyle = prevNode.__style;
277
- if (style) {
278
- if (style !== prevStyle) {
279
- dom.setAttribute('style', style);
280
- }
281
- } else if (prevStyle) {
282
- dom.removeAttribute('style');
300
+ if (style !== prevStyle) {
301
+ setDOMStyleFromCSS(dom.style, style, prevStyle);
283
302
  }
284
303
  return false;
285
304
  }
@@ -300,7 +319,7 @@ class CodeNode extends ElementNode {
300
319
  }
301
320
  const style = this.getStyle();
302
321
  if (style) {
303
- element.setAttribute('style', style);
322
+ setDOMStyleFromCSS(element.style, style);
304
323
  }
305
324
  return {
306
325
  element
@@ -381,16 +400,13 @@ class CodeNode extends ElementNode {
381
400
 
382
401
  // Mutation
383
402
  insertNewAfter(selection, restoreSelection = true) {
384
- const children = this.getChildren();
385
- const childrenLength = children.length;
386
- if (childrenLength >= 2 && children[childrenLength - 1].getTextContent() === '\n' && children[childrenLength - 2].getTextContent() === '\n' && selection.isCollapsed() && selection.anchor.key === this.__key && selection.anchor.offset === childrenLength) {
387
- children[childrenLength - 1].remove();
388
- children[childrenLength - 2].remove();
389
- const newElement = $createParagraphNode();
390
- this.insertAfter(newElement, restoreSelection);
391
- return newElement;
403
+ if (!getPeerDependencyFromEditor($getEditor(), '@lexical/code')) {
404
+ noExtensionDeprecation();
405
+ const el = $exitCodeNodeOnEnter(selection);
406
+ if (el) {
407
+ return el;
408
+ }
392
409
  }
393
-
394
410
  // If the selection is within the codeblock, find all leading tabs and
395
411
  // spaces of the current line. Create a new line that has all those
396
412
  // tabs and spaces, such that leading indentation is preserved.
@@ -538,6 +554,27 @@ function isGitHubCodeCell(cell) {
538
554
  function isGitHubCodeTable(table) {
539
555
  return table.classList.contains('js-file-line-container');
540
556
  }
557
+ function $exitCodeNodeOnEnter(selection) {
558
+ const {
559
+ anchor
560
+ } = selection;
561
+ if (selection.isCollapsed() && anchor.type === 'element') {
562
+ const codeNode = anchor.getNode();
563
+ if ($isCodeNode(codeNode)) {
564
+ const childrenSize = codeNode.getChildrenSize();
565
+ if (childrenSize >= 2 && anchor.offset === childrenSize) {
566
+ const lastChild = codeNode.getLastChild();
567
+ if ($isLineBreakNode(lastChild) && $isLineBreakNode(lastChild.getPreviousSibling())) {
568
+ const newElement = $createParagraphNode();
569
+ codeNode.splice(childrenSize - 2, 2, []).insertAfter(newElement, false);
570
+ newElement.select();
571
+ return newElement;
572
+ }
573
+ }
574
+ }
575
+ }
576
+ return null;
577
+ }
541
578
 
542
579
  /**
543
580
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -639,12 +676,23 @@ function $isCodeHighlightNode(node) {
639
676
  *
640
677
  */
641
678
 
679
+
642
680
  /**
643
681
  * Add code blocks to the editor (syntax highlighting provided separately)
644
682
  */
645
683
  const CodeExtension = defineExtension({
646
684
  name: '@lexical/code',
647
- nodes: () => [CodeNode, CodeHighlightNode]
685
+ nodes: () => [CodeNode, CodeHighlightNode],
686
+ register(editor) {
687
+ return editor.registerCommand(KEY_ENTER_COMMAND, event => {
688
+ const selection = $getSelection();
689
+ if ($isRangeSelection(selection) && $exitCodeNodeOnEnter(selection)) {
690
+ event.preventDefault();
691
+ return true;
692
+ }
693
+ return false;
694
+ }, COMMAND_PRIORITY_LOW);
695
+ }
648
696
  });
649
697
 
650
698
  export { $createCodeHighlightNode, $createCodeNode, $getCodeLineDirection, $getEndOfCodeInLine, $getFirstCodeNodeOfLine, $getLastCodeNodeOfLine, $getStartOfCodeInLine, $isCodeHighlightNode, $isCodeNode, CodeExtension, CodeHighlightNode, CodeNode, DEFAULT_CODE_LANGUAGE, getDefaultCodeLanguage };
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("lexical");function t(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function n(t,n){let r=t;for(let i=e.$getSiblingCaret(t,n);i&&(y(i.origin)||e.$isTabNode(i.origin));i=i.getAdjacentCaret())r=i.origin;return r}function r(e){return n(e,"previous")}function i(e){return n(e,"next")}const o="javascript";function s(t,n){for(const r of t.childNodes){if(e.isHTMLElement(r)&&r.tagName===n)return!0;s(r,n)}return!1}const a="data-language",l="data-highlight-language",g="data-theme";class u extends e.ElementNode{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new u(e.__language,e.__key)}constructor(e,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(t){const n=document.createElement("code");e.addClassNamesToElement(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(a,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(l,r));const i=this.getTheme();i&&n.setAttribute(g,i);const o=this.getStyle();return o&&n.setAttribute("style",o),n}updateDOM(e,t,n){const r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(a,r):i&&t.removeAttribute(a);const o=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&t.setAttribute(l,r):t.removeAttribute(l):o&&r&&t.setAttribute(l,r);const s=this.__theme,u=e.__theme;s?s!==u&&t.setAttribute(g,s):u&&t.removeAttribute(g);const h=this.__style,c=e.__style;return h?h!==c&&t.setAttribute("style",h):c&&t.removeAttribute("style"),!1}exportDOM(t){const n=document.createElement("pre");e.addClassNamesToElement(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(a,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(l,r));const i=this.getTheme();i&&n.setAttribute(g,i);const o=this.getStyle();return o&&n.setAttribute("style",o),{element:n}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||s(e,"BR"))?{conversion:d,priority:1}:null,div:()=>({conversion:p,priority:1}),pre:()=>({conversion:d,priority:0}),table:e=>x(e)?{conversion:f,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&x(n)?{conversion:_,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&x(t)?{conversion:_,priority:3}:null}}}static importJSON(e){return h().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(t,n=!0){const i=this.getChildren(),o=i.length;if(o>=2&&"\n"===i[o-1].getTextContent()&&"\n"===i[o-2].getTextContent()&&t.isCollapsed()&&t.anchor.key===this.__key&&t.anchor.offset===o){i[o-1].remove(),i[o-2].remove();const t=e.$createParagraphNode();return this.insertAfter(t,n),t}const{anchor:s,focus:a}=t,l=(s.isBefore(a)?s:a).getNode();if(e.$isTextNode(l)){let t=r(l);const n=[];for(;;)if(e.$isTabNode(t))n.push(e.$createTabNode()),t=t.getNextSibling();else{if(!y(t))break;{let e=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;e<i&&" "===r[e];)e++;if(0!==e&&n.push(T(" ".repeat(e))),e!==i)break;t=t.getNextSibling()}}const i=l.splitText(s.offset)[0],o=0===s.offset?0:1,a=i.getIndexWithinParent()+o,g=l.getParentOrThrow(),u=[e.$createLineBreakNode(),...n];g.splice(a,0,u);const h=n[n.length-1];h?h.select():0===s.offset?i.selectPrevious():i.getNextSibling().selectNext(0,0)}if(c(l)){const{offset:n}=t.anchor;l.splice(n,0,[e.$createLineBreakNode()]),l.select(n+1,n+1)}return null}canIndent(){return!1}collapseAtStart(){const t=e.$createParagraphNode();return this.getChildren().forEach(e=>t.append(e)),this.replace(t),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function h(t,n){return e.$create(u).setLanguage(t).setTheme(n)}function c(e){return e instanceof u}function d(e){return{node:h(e.getAttribute(a))}}function p(e){const t=e,n=m(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(m(t))return!0;t=t.parentElement}return!1}(t)?{node:n?h():null}:{node:null}}function f(){return{node:h()}}function _(){return{node:null}}function m(e){return null!==e.style.fontFamily.match("monospace")}function x(e){return e.classList.contains("js-file-line-container")}class S extends e.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new S(e.__text,e.__highlightType||void 0,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(t){const n=super.createDOM(t),r=N(t.theme,this.__highlightType);return e.addClassNamesToElement(n,r),n}updateDOM(t,n,r){const i=super.updateDOM(t,n,r),o=N(r.theme,t.__highlightType),s=N(r.theme,this.__highlightType);return o!==s&&(o&&e.removeClassNamesFromElement(n,o),s&&e.addClassNamesToElement(n,s)),i}static importJSON(e){return T().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return h()}}function N(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function T(t="",n){return e.$applyNodeReplacement(new S(t,n))}function y(e){return e instanceof S}const C=e.defineExtension({name:"@lexical/code",nodes:()=>[u,S]});exports.$createCodeHighlightNode=T,exports.$createCodeNode=h,exports.$getCodeLineDirection=function(t){const n=r(t),o=i(t);let s=n;for(;null!==s;){if(y(s)){const t=e.getTextDirection(s.getTextContent());if(null!==t)return t}if(s===o)break;s=s.getNextSibling()}const a=n.getParent();if(e.$isElementNode(a)){const e=a.getDirection();if("ltr"===e||"rtl"===e)return e}return null},exports.$getEndOfCodeInLine=function(n){const r=i(n);return e.$isLineBreakNode(r)&&t(168),r},exports.$getFirstCodeNodeOfLine=r,exports.$getLastCodeNodeOfLine=i,exports.$getStartOfCodeInLine=function(n,r){let i=null,o=null,s=n,a=r,l=n.getTextContent();for(;;){if(0===a){if(s=s.getPreviousSibling(),null===s)break;if(y(s)||e.$isTabNode(s)||e.$isLineBreakNode(s)||t(167),e.$isLineBreakNode(s)){i={node:s,offset:1};break}a=Math.max(0,s.getTextContentSize()-1),l=s.getTextContent()}else a--;const n=l[a];y(s)&&" "!==n&&(o={node:s,offset:a})}if(null!==o)return o;let g=null;if(r<n.getTextContentSize())y(n)&&(g=n.getTextContent()[r]);else{const e=n.getNextSibling();y(e)&&(g=e.getTextContent()[0])}if(null!==g&&" "!==g)return i;{const t=function(t,n){let r=t,i=n,o=t.getTextContent(),s=t.getTextContentSize();for(;;){if(!y(r)||i===s){if(r=r.getNextSibling(),null===r||e.$isLineBreakNode(r))return null;y(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(y(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(n,r);return null!==t?t:i}},exports.$isCodeHighlightNode=y,exports.$isCodeNode=c,exports.CodeExtension=C,exports.CodeHighlightNode=S,exports.CodeNode=u,exports.DEFAULT_CODE_LANGUAGE=o,exports.getDefaultCodeLanguage=()=>o;
9
+ "use strict";var e=require("lexical"),t=require("@lexical/extension");function n(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function r(t,n){let r=t;for(let i=e.$getSiblingCaret(t,n);i&&(L(i.origin)||e.$isTabNode(i.origin));i=i.getAdjacentCaret())r=i.origin;return r}function i(e){return r(e,"previous")}function o(e){return r(e,"next")}const s="javascript";function l(t,n){for(const r of t.childNodes){if(e.isHTMLElement(r)&&r.tagName===n)return!0;l(r,n)}return!1}const a="data-language",g="data-highlight-language",u="data-theme",c=()=>{};class h extends e.ElementNode{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new h(e.__language,e.__key)}constructor(e,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(t){const n=document.createElement("code");e.addClassNamesToElement(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(a,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(g,r));const i=this.getTheme();i&&n.setAttribute(u,i);const o=this.getStyle();return o&&e.setDOMStyleFromCSS(n.style,o),n}updateDOM(t,n,r){const i=this.__language,o=t.__language;i?i!==o&&n.setAttribute(a,i):o&&n.removeAttribute(a);const s=this.__isSyntaxHighlightSupported;t.__isSyntaxHighlightSupported&&o?s&&i?i!==o&&n.setAttribute(g,i):n.removeAttribute(g):s&&i&&n.setAttribute(g,i);const l=this.__theme,c=t.__theme;l?l!==c&&n.setAttribute(u,l):c&&n.removeAttribute(u);const h=this.__style,d=t.__style;return h!==d&&e.setDOMStyleFromCSS(n.style,h,d),!1}exportDOM(t){const n=document.createElement("pre");e.addClassNamesToElement(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(a,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(g,r));const i=this.getTheme();i&&n.setAttribute(u,i);const o=this.getStyle();return o&&e.setDOMStyleFromCSS(n.style,o),{element:n}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||l(e,"BR"))?{conversion:f,priority:1}:null,div:()=>({conversion:_,priority:1}),pre:()=>({conversion:f,priority:0}),table:e=>N(e)?{conversion:m,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&N(n)?{conversion:x,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&N(t)?{conversion:x,priority:3}:null}}}static importJSON(e){return d().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(n,r=!0){if(!t.getPeerDependencyFromEditor(e.$getEditor(),"@lexical/code")){c();const e=T(n);if(e)return e}const{anchor:o,focus:s}=n,l=(o.isBefore(s)?o:s).getNode();if(e.$isTextNode(l)){let t=i(l);const n=[];for(;;)if(e.$isTabNode(t))n.push(e.$createTabNode()),t=t.getNextSibling();else{if(!L(t))break;{let e=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;e<i&&" "===r[e];)e++;if(0!==e&&n.push(b(" ".repeat(e))),e!==i)break;t=t.getNextSibling()}}const r=l.splitText(o.offset)[0],s=0===o.offset?0:1,a=r.getIndexWithinParent()+s,g=l.getParentOrThrow(),u=[e.$createLineBreakNode(),...n];g.splice(a,0,u);const c=n[n.length-1];c?c.select():0===o.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(p(l)){const{offset:t}=n.anchor;l.splice(t,0,[e.$createLineBreakNode()]),l.select(t+1,t+1)}return null}canIndent(){return!1}collapseAtStart(){const t=e.$createParagraphNode();return this.getChildren().forEach(e=>t.append(e)),this.replace(t),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function d(t,n){return e.$create(h).setLanguage(t).setTheme(n)}function p(e){return e instanceof h}function f(e){return{node:d(e.getAttribute(a))}}function _(e){const t=e,n=S(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(S(t))return!0;t=t.parentElement}return!1}(t)?{node:n?d():null}:{node:null}}function m(){return{node:d()}}function x(){return{node:null}}function S(e){return null!==e.style.fontFamily.match("monospace")}function N(e){return e.classList.contains("js-file-line-container")}function T(t){const{anchor:n}=t;if(t.isCollapsed()&&"element"===n.type){const t=n.getNode();if(p(t)){const r=t.getChildrenSize();if(r>=2&&n.offset===r){const n=t.getLastChild();if(e.$isLineBreakNode(n)&&e.$isLineBreakNode(n.getPreviousSibling())){const n=e.$createParagraphNode();return t.splice(r-2,2,[]).insertAfter(n,!1),n.select(),n}}}}return null}class y extends e.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new y(e.__text,e.__highlightType||void 0,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(t){const n=super.createDOM(t),r=C(t.theme,this.__highlightType);return e.addClassNamesToElement(n,r),n}updateDOM(t,n,r){const i=super.updateDOM(t,n,r),o=C(r.theme,t.__highlightType),s=C(r.theme,this.__highlightType);return o!==s&&(o&&e.removeClassNamesFromElement(n,o),s&&e.addClassNamesToElement(n,s)),i}static importJSON(e){return b().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return d()}}function C(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function b(t="",n){return e.$applyNodeReplacement(new y(t,n))}function L(e){return e instanceof y}const O=e.defineExtension({name:"@lexical/code",nodes:()=>[h,y],register:t=>t.registerCommand(e.KEY_ENTER_COMMAND,t=>{const n=e.$getSelection();return!(!e.$isRangeSelection(n)||!T(n))&&(t.preventDefault(),!0)},e.COMMAND_PRIORITY_LOW)});exports.$createCodeHighlightNode=b,exports.$createCodeNode=d,exports.$getCodeLineDirection=function(t){const n=i(t),r=o(t);let s=n;for(;null!==s;){if(L(s)){const t=e.getTextDirection(s.getTextContent());if(null!==t)return t}if(s===r)break;s=s.getNextSibling()}const l=n.getParent();if(e.$isElementNode(l)){const e=l.getDirection();if("ltr"===e||"rtl"===e)return e}return null},exports.$getEndOfCodeInLine=function(t){const r=o(t);return e.$isLineBreakNode(r)&&n(168),r},exports.$getFirstCodeNodeOfLine=i,exports.$getLastCodeNodeOfLine=o,exports.$getStartOfCodeInLine=function(t,r){let i=null,o=null,s=t,l=r,a=t.getTextContent();for(;;){if(0===l){if(s=s.getPreviousSibling(),null===s)break;if(L(s)||e.$isTabNode(s)||e.$isLineBreakNode(s)||n(167),e.$isLineBreakNode(s)){i={node:s,offset:1};break}l=Math.max(0,s.getTextContentSize()-1),a=s.getTextContent()}else l--;const t=a[l];L(s)&&" "!==t&&(o={node:s,offset:l})}if(null!==o)return o;let g=null;if(r<t.getTextContentSize())L(t)&&(g=t.getTextContent()[r]);else{const e=t.getNextSibling();L(e)&&(g=e.getTextContent()[0])}if(null!==g&&" "!==g)return i;{const n=function(t,n){let r=t,i=n,o=t.getTextContent(),s=t.getTextContentSize();for(;;){if(!L(r)||i===s){if(r=r.getNextSibling(),null===r||e.$isLineBreakNode(r))return null;L(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(L(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(t,r);return null!==n?n:i}},exports.$isCodeHighlightNode=L,exports.$isCodeNode=p,exports.CodeExtension=O,exports.CodeHighlightNode=y,exports.CodeNode=h,exports.DEFAULT_CODE_LANGUAGE=s,exports.getDefaultCodeLanguage=()=>s;
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{getTextDirection as t,$isElementNode as e,$isTabNode as n,$isLineBreakNode as r,$getSiblingCaret as i,$create as o,ElementNode as s,addClassNamesToElement as u,$createParagraphNode as l,$isTextNode as g,$createTabNode as h,$createLineBreakNode as a,isHTMLElement as c,$applyNodeReplacement as p,TextNode as f,removeClassNamesFromElement as _,defineExtension as d}from"lexical";function m(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function S(t,e){let r=t;for(let o=i(t,e);o&&(R(o.origin)||n(o.origin));o=o.getAdjacentCaret())r=o.origin;return r}function x(t){return S(t,"previous")}function y(t){return S(t,"next")}function T(n){const r=x(n),i=y(n);let o=r;for(;null!==o;){if(R(o)){const e=t(o.getTextContent());if(null!==e)return e}if(o===i)break;o=o.getNextSibling()}const s=r.getParent();if(e(s)){const t=s.getDirection();if("ltr"===t||"rtl"===t)return t}return null}function b(t,e){let i=null,o=null,s=t,u=e,l=t.getTextContent();for(;;){if(0===u){if(s=s.getPreviousSibling(),null===s)break;if(R(s)||n(s)||r(s)||m(167),r(s)){i={node:s,offset:1};break}u=Math.max(0,s.getTextContentSize()-1),l=s.getTextContent()}else u--;const t=l[u];R(s)&&" "!==t&&(o={node:s,offset:u})}if(null!==o)return o;let g=null;if(e<t.getTextContentSize())R(t)&&(g=t.getTextContent()[e]);else{const e=t.getNextSibling();R(e)&&(g=e.getTextContent()[0])}if(null!==g&&" "!==g)return i;{const n=function(t,e){let n=t,i=e,o=t.getTextContent(),s=t.getTextContentSize();for(;;){if(!R(n)||i===s){if(n=n.getNextSibling(),null===n||r(n))return null;R(n)&&(i=0,o=n.getTextContent(),s=n.getTextContentSize())}if(R(n)){if(" "!==o[i])return{node:n,offset:i};i++}}}(t,e);return null!==n?n:i}}function v(t){const e=y(t);return r(e)&&m(168),e}const C="javascript",A=()=>C;function N(t,e){for(const n of t.childNodes){if(c(n)&&n.tagName===e)return!0;N(n,e)}return!1}const O="data-language",H="data-highlight-language",L="data-theme";class F extends s{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(t){return new F(t.__language,t.__key)}constructor(t,e){super(e),this.__language=t||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(t){super.afterCloneFrom(t),this.__language=t.__language,this.__theme=t.__theme,this.__isSyntaxHighlightSupported=t.__isSyntaxHighlightSupported}createDOM(t){const e=document.createElement("code");u(e,t.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute(O,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(H,n));const r=this.getTheme();r&&e.setAttribute(L,r);const i=this.getStyle();return i&&e.setAttribute("style",i),e}updateDOM(t,e,n){const r=this.__language,i=t.__language;r?r!==i&&e.setAttribute(O,r):i&&e.removeAttribute(O);const o=this.__isSyntaxHighlightSupported;t.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&e.setAttribute(H,r):e.removeAttribute(H):o&&r&&e.setAttribute(H,r);const s=this.__theme,u=t.__theme;s?s!==u&&e.setAttribute(L,s):u&&e.removeAttribute(L);const l=this.__style,g=t.__style;return l?l!==g&&e.setAttribute("style",l):g&&e.removeAttribute("style"),!1}exportDOM(t){const e=document.createElement("pre");u(e,t._config.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute(O,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(H,n));const r=this.getTheme();r&&e.setAttribute(L,r);const i=this.getStyle();return i&&e.setAttribute("style",i),{element:e}}static importDOM(){return{code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||N(t,"BR"))?{conversion:M,priority:1}:null,div:()=>({conversion:w,priority:1}),pre:()=>({conversion:M,priority:0}),table:t=>I(t)?{conversion:D,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&I(n)?{conversion:P,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&I(e)?{conversion:P,priority:3}:null}}}static importJSON(t){return J().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setLanguage(t.language).setTheme(t.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(t,e=!0){const r=this.getChildren(),i=r.length;if(i>=2&&"\n"===r[i-1].getTextContent()&&"\n"===r[i-2].getTextContent()&&t.isCollapsed()&&t.anchor.key===this.__key&&t.anchor.offset===i){r[i-1].remove(),r[i-2].remove();const t=l();return this.insertAfter(t,e),t}const{anchor:o,focus:s}=t,u=(o.isBefore(s)?o:s).getNode();if(g(u)){let t=x(u);const e=[];for(;;)if(n(t))e.push(h()),t=t.getNextSibling();else{if(!R(t))break;{let n=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&e.push(j(" ".repeat(n))),n!==i)break;t=t.getNextSibling()}}const r=u.splitText(o.offset)[0],i=0===o.offset?0:1,s=r.getIndexWithinParent()+i,l=u.getParentOrThrow(),g=[a(),...e];l.splice(s,0,g);const c=e[e.length-1];c?c.select():0===o.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(k(u)){const{offset:e}=t.anchor;u.splice(e,0,[a()]),u.select(e+1,e+1)}return null}canIndent(){return!1}collapseAtStart(){const t=l();return this.getChildren().forEach(e=>t.append(e)),this.replace(t),!0}setLanguage(t){const e=this.getWritable();return e.__language=t||void 0,e}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(t){const e=this.getWritable();return e.__isSyntaxHighlightSupported=t,e}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(t){const e=this.getWritable();return e.__theme=t||void 0,e}getTheme(){return this.getLatest().__theme}}function J(t,e){return o(F).setLanguage(t).setTheme(e)}function k(t){return t instanceof F}function M(t){return{node:J(t.getAttribute(O))}}function w(t){const e=t,n=E(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(E(e))return!0;e=e.parentElement}return!1}(e)?{node:n?J():null}:{node:null}}function D(){return{node:J()}}function P(){return{node:null}}function E(t){return null!==t.style.fontFamily.match("monospace")}function I(t){return t.classList.contains("js-file-line-container")}class z extends f{__highlightType;constructor(t="",e,n){super(t,n),this.__highlightType=e}static getType(){return"code-highlight"}static clone(t){return new z(t.__text,t.__highlightType||void 0,t.__key)}afterCloneFrom(t){super.afterCloneFrom(t),this.__highlightType=t.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(t){const e=this.getWritable();return e.__highlightType=t||void 0,e}canHaveFormat(){return!1}createDOM(t){const e=super.createDOM(t),n=W(t.theme,this.__highlightType);return u(e,n),e}updateDOM(t,e,n){const r=super.updateDOM(t,e,n),i=W(n.theme,t.__highlightType),o=W(n.theme,this.__highlightType);return i!==o&&(i&&_(e,i),o&&u(e,o)),r}static importJSON(t){return j().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setHighlightType(t.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(t){return this}isParentRequired(){return!0}createParentElementNode(){return J()}}function W(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function j(t="",e){return p(new z(t,e))}function R(t){return t instanceof z}const B=d({name:"@lexical/code",nodes:()=>[F,z]});export{j as $createCodeHighlightNode,J as $createCodeNode,T as $getCodeLineDirection,v as $getEndOfCodeInLine,x as $getFirstCodeNodeOfLine,y as $getLastCodeNodeOfLine,b as $getStartOfCodeInLine,R as $isCodeHighlightNode,k as $isCodeNode,B as CodeExtension,z as CodeHighlightNode,F as CodeNode,C as DEFAULT_CODE_LANGUAGE,A as getDefaultCodeLanguage};
9
+ import{getTextDirection as t,$isElementNode as e,$isTabNode as n,$isLineBreakNode as r,$getSiblingCaret as i,$create as o,ElementNode as s,addClassNamesToElement as l,setDOMStyleFromCSS as u,$getEditor as g,$isTextNode as a,$createTabNode as h,$createLineBreakNode as c,$createParagraphNode as p,isHTMLElement as f,$applyNodeReplacement as d,TextNode as _,removeClassNamesFromElement as m,defineExtension as S,KEY_ENTER_COMMAND as x,$getSelection as y,$isRangeSelection as T,COMMAND_PRIORITY_LOW as b}from"lexical";import{getPeerDependencyFromEditor as v}from"@lexical/extension";function C(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function N(t,e){let r=t;for(let o=i(t,e);o&&(X(o.origin)||n(o.origin));o=o.getAdjacentCaret())r=o.origin;return r}function O(t){return N(t,"previous")}function A(t){return N(t,"next")}function H(n){const r=O(n),i=A(n);let o=r;for(;null!==o;){if(X(o)){const e=t(o.getTextContent());if(null!==e)return e}if(o===i)break;o=o.getNextSibling()}const s=r.getParent();if(e(s)){const t=s.getDirection();if("ltr"===t||"rtl"===t)return t}return null}function L(t,e){let i=null,o=null,s=t,l=e,u=t.getTextContent();for(;;){if(0===l){if(s=s.getPreviousSibling(),null===s)break;if(X(s)||n(s)||r(s)||C(167),r(s)){i={node:s,offset:1};break}l=Math.max(0,s.getTextContentSize()-1),u=s.getTextContent()}else l--;const t=u[l];X(s)&&" "!==t&&(o={node:s,offset:l})}if(null!==o)return o;let g=null;if(e<t.getTextContentSize())X(t)&&(g=t.getTextContent()[e]);else{const e=t.getNextSibling();X(e)&&(g=e.getTextContent()[0])}if(null!==g&&" "!==g)return i;{const n=function(t,e){let n=t,i=e,o=t.getTextContent(),s=t.getTextContentSize();for(;;){if(!X(n)||i===s){if(n=n.getNextSibling(),null===n||r(n))return null;X(n)&&(i=0,o=n.getTextContent(),s=n.getTextContentSize())}if(X(n)){if(" "!==o[i])return{node:n,offset:i};i++}}}(t,e);return null!==n?n:i}}function F(t){const e=A(t);return r(e)&&C(168),e}const J="javascript",D=()=>J;function M(t,e){for(const n of t.childNodes){if(f(n)&&n.tagName===e)return!0;M(n,e)}return!1}const k="data-language",w="data-highlight-language",P="data-theme",E=()=>{};class z extends s{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(t){return new z(t.__language,t.__key)}constructor(t,e){super(e),this.__language=t||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(t){super.afterCloneFrom(t),this.__language=t.__language,this.__theme=t.__theme,this.__isSyntaxHighlightSupported=t.__isSyntaxHighlightSupported}createDOM(t){const e=document.createElement("code");l(e,t.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute(k,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(w,n));const r=this.getTheme();r&&e.setAttribute(P,r);const i=this.getStyle();return i&&u(e.style,i),e}updateDOM(t,e,n){const r=this.__language,i=t.__language;r?r!==i&&e.setAttribute(k,r):i&&e.removeAttribute(k);const o=this.__isSyntaxHighlightSupported;t.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&e.setAttribute(w,r):e.removeAttribute(w):o&&r&&e.setAttribute(w,r);const s=this.__theme,l=t.__theme;s?s!==l&&e.setAttribute(P,s):l&&e.removeAttribute(P);const g=this.__style,a=t.__style;return g!==a&&u(e.style,g,a),!1}exportDOM(t){const e=document.createElement("pre");l(e,t._config.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute(k,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(w,n));const r=this.getTheme();r&&e.setAttribute(P,r);const i=this.getStyle();return i&&u(e.style,i),{element:e}}static importDOM(){return{code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||M(t,"BR"))?{conversion:j,priority:1}:null,div:()=>({conversion:R,priority:1}),pre:()=>({conversion:j,priority:0}),table:t=>q(t)?{conversion:B,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&q(n)?{conversion:U,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&q(e)?{conversion:U,priority:3}:null}}}static importJSON(t){return I().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setLanguage(t.language).setTheme(t.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(t,e=!0){if(!v(g(),"@lexical/code")){E();const e=G(t);if(e)return e}const{anchor:r,focus:i}=t,o=(r.isBefore(i)?r:i).getNode();if(a(o)){let t=O(o);const e=[];for(;;)if(n(t))e.push(h()),t=t.getNextSibling();else{if(!X(t))break;{let n=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&e.push(V(" ".repeat(n))),n!==i)break;t=t.getNextSibling()}}const i=o.splitText(r.offset)[0],s=0===r.offset?0:1,l=i.getIndexWithinParent()+s,u=o.getParentOrThrow(),g=[c(),...e];u.splice(l,0,g);const a=e[e.length-1];a?a.select():0===r.offset?i.selectPrevious():i.getNextSibling().selectNext(0,0)}if(W(o)){const{offset:e}=t.anchor;o.splice(e,0,[c()]),o.select(e+1,e+1)}return null}canIndent(){return!1}collapseAtStart(){const t=p();return this.getChildren().forEach(e=>t.append(e)),this.replace(t),!0}setLanguage(t){const e=this.getWritable();return e.__language=t||void 0,e}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(t){const e=this.getWritable();return e.__isSyntaxHighlightSupported=t,e}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(t){const e=this.getWritable();return e.__theme=t||void 0,e}getTheme(){return this.getLatest().__theme}}function I(t,e){return o(z).setLanguage(t).setTheme(e)}function W(t){return t instanceof z}function j(t){return{node:I(t.getAttribute(k))}}function R(t){const e=t,n=$(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if($(e))return!0;e=e.parentElement}return!1}(e)?{node:n?I():null}:{node:null}}function B(){return{node:I()}}function U(){return{node:null}}function $(t){return null!==t.style.fontFamily.match("monospace")}function q(t){return t.classList.contains("js-file-line-container")}function G(t){const{anchor:e}=t;if(t.isCollapsed()&&"element"===e.type){const t=e.getNode();if(W(t)){const n=t.getChildrenSize();if(n>=2&&e.offset===n){const e=t.getLastChild();if(r(e)&&r(e.getPreviousSibling())){const e=p();return t.splice(n-2,2,[]).insertAfter(e,!1),e.select(),e}}}}return null}class K extends _{__highlightType;constructor(t="",e,n){super(t,n),this.__highlightType=e}static getType(){return"code-highlight"}static clone(t){return new K(t.__text,t.__highlightType||void 0,t.__key)}afterCloneFrom(t){super.afterCloneFrom(t),this.__highlightType=t.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(t){const e=this.getWritable();return e.__highlightType=t||void 0,e}canHaveFormat(){return!1}createDOM(t){const e=super.createDOM(t),n=Q(t.theme,this.__highlightType);return l(e,n),e}updateDOM(t,e,n){const r=super.updateDOM(t,e,n),i=Q(n.theme,t.__highlightType),o=Q(n.theme,this.__highlightType);return i!==o&&(i&&m(e,i),o&&l(e,o)),r}static importJSON(t){return V().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setHighlightType(t.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(t){return this}isParentRequired(){return!0}createParentElementNode(){return I()}}function Q(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function V(t="",e){return d(new K(t,e))}function X(t){return t instanceof K}const Y=S({name:"@lexical/code",nodes:()=>[z,K],register:t=>t.registerCommand(x,t=>{const e=y();return!(!T(e)||!G(e))&&(t.preventDefault(),!0)},b)});export{V as $createCodeHighlightNode,I as $createCodeNode,H as $getCodeLineDirection,F as $getEndOfCodeInLine,O as $getFirstCodeNodeOfLine,A as $getLastCodeNodeOfLine,L as $getStartOfCodeInLine,X as $isCodeHighlightNode,W as $isCodeNode,Y as CodeExtension,K as CodeHighlightNode,z as CodeNode,J as DEFAULT_CODE_LANGUAGE,D as getDefaultCodeLanguage};
package/package.json CHANGED
@@ -8,11 +8,12 @@
8
8
  "code"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.43.1-nightly.20260416.0",
11
+ "version": "0.44.0",
12
12
  "main": "LexicalCodeCore.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "lexical": "0.43.1-nightly.20260416.0"
15
+ "@lexical/extension": "0.44.0",
16
+ "lexical": "0.44.0"
16
17
  },
17
18
  "repository": {
18
19
  "type": "git",