@lexical/code 0.37.1-nightly.20251015.0 → 0.37.1-nightly.20251017.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.
@@ -9,6 +9,15 @@ import type { CodeHighlightNode } from './CodeHighlightNode';
9
9
  import type { LineBreakNode, TabNode } from 'lexical';
10
10
  export declare function $getFirstCodeNodeOfLine(anchor: CodeHighlightNode | TabNode | LineBreakNode): CodeHighlightNode | TabNode | LineBreakNode;
11
11
  export declare function $getLastCodeNodeOfLine(anchor: CodeHighlightNode | TabNode | LineBreakNode): CodeHighlightNode | TabNode | LineBreakNode;
12
+ /**
13
+ * Determines the visual writing direction of a code line.
14
+ *
15
+ * Scans the line segments (CodeHighlightNode/TabNode) from start to end
16
+ * and returns the first strong direction found ("ltr" or "rtl").
17
+ * If no strong character is found, falls back to the parent element's
18
+ * direction. Returns null if indeterminate.
19
+ */
20
+ export declare function $getCodeLineDirection(anchor: CodeHighlightNode | TabNode | LineBreakNode): 'ltr' | 'rtl' | null;
12
21
  export declare function $getStartOfCodeInLine(anchor: CodeHighlightNode | TabNode, offset: number): null | {
13
22
  node: CodeHighlightNode | TabNode | LineBreakNode;
14
23
  offset: number;
@@ -532,6 +532,40 @@ function $getFirstCodeNodeOfLine(anchor) {
532
532
  function $getLastCodeNodeOfLine(anchor) {
533
533
  return $getLastMatchingCodeNode(anchor, 'next');
534
534
  }
535
+
536
+ /**
537
+ * Determines the visual writing direction of a code line.
538
+ *
539
+ * Scans the line segments (CodeHighlightNode/TabNode) from start to end
540
+ * and returns the first strong direction found ("ltr" or "rtl").
541
+ * If no strong character is found, falls back to the parent element's
542
+ * direction. Returns null if indeterminate.
543
+ */
544
+ function $getCodeLineDirection(anchor) {
545
+ const start = $getFirstCodeNodeOfLine(anchor);
546
+ const end = $getLastCodeNodeOfLine(anchor);
547
+ let node = start;
548
+ while (node !== null) {
549
+ if ($isCodeHighlightNode(node)) {
550
+ const direction = lexical.getTextDirection(node.getTextContent());
551
+ if (direction !== null) {
552
+ return direction;
553
+ }
554
+ }
555
+ if (node === end) {
556
+ break;
557
+ }
558
+ node = node.getNextSibling();
559
+ }
560
+ const parent = start.getParent();
561
+ if (lexical.$isElementNode(parent)) {
562
+ const parentDirection = parent.getDirection();
563
+ if (parentDirection === 'ltr' || parentDirection === 'rtl') {
564
+ return parentDirection;
565
+ }
566
+ }
567
+ return null;
568
+ }
535
569
  function $getStartOfCodeInLine(anchor, offset) {
536
570
  let last = null;
537
571
  let lastNonBlank = null;
@@ -1418,8 +1452,11 @@ function $handleMoveTo(type, event) {
1418
1452
  if (!$isSelectionInCode(selection) || !($isCodeHighlightNode(anchorNode) || lexical.$isTabNode(anchorNode)) || !($isCodeHighlightNode(focusNode) || lexical.$isTabNode(focusNode))) {
1419
1453
  return false;
1420
1454
  }
1421
- if (isMoveToStart) {
1422
- const start = $getStartOfCodeInLine(focusNode, focus.offset);
1455
+ const focusLineNode = focusNode;
1456
+ const direction = $getCodeLineDirection(focusLineNode);
1457
+ const moveToStart = direction === 'rtl' ? !isMoveToStart : isMoveToStart;
1458
+ if (moveToStart) {
1459
+ const start = $getStartOfCodeInLine(focusLineNode, focus.offset);
1423
1460
  if (start !== null) {
1424
1461
  const {
1425
1462
  node,
@@ -1431,10 +1468,10 @@ function $handleMoveTo(type, event) {
1431
1468
  selection.setTextNodeRange(node, offset, node, offset);
1432
1469
  }
1433
1470
  } else {
1434
- focusNode.getParentOrThrow().selectStart();
1471
+ focusLineNode.getParentOrThrow().selectStart();
1435
1472
  }
1436
1473
  } else {
1437
- const node = $getEndOfCodeInLine(focusNode);
1474
+ const node = $getEndOfCodeInLine(focusLineNode);
1438
1475
  node.select();
1439
1476
  }
1440
1477
  event.preventDefault();
@@ -1544,6 +1581,7 @@ const getStartOfCodeInLine = $getStartOfCodeInLine;
1544
1581
 
1545
1582
  exports.$createCodeHighlightNode = $createCodeHighlightNode;
1546
1583
  exports.$createCodeNode = $createCodeNode;
1584
+ exports.$getCodeLineDirection = $getCodeLineDirection;
1547
1585
  exports.$getEndOfCodeInLine = $getEndOfCodeInLine;
1548
1586
  exports.$getFirstCodeNodeOfLine = $getFirstCodeNodeOfLine;
1549
1587
  exports.$getLastCodeNodeOfLine = $getLastCodeNodeOfLine;
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  import { isHTMLElement, addClassNamesToElement, removeClassNamesFromElement, $getAdjacentCaret, mergeRegister } from '@lexical/utils';
10
- import { ElementNode, $createParagraphNode, $isTextNode, $isTabNode, $createTabNode, $createLineBreakNode, $create, TextNode, $applyNodeReplacement, $getSiblingCaret, $isLineBreakNode, defineExtension, $createTextNode, $getNodeByKey, $getSelection, $isRangeSelection, $createPoint, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, INSERT_TAB_COMMAND, $setSelectionFromCaretRange, $getCaretRangeInDirection, $getCaretRange, $getTextPointCaret, $normalizeCaret, KEY_ARROW_UP_COMMAND, MOVE_TO_START, KEY_TAB_COMMAND, COMMAND_PRIORITY_LOW, $insertNodes, KEY_ARROW_DOWN_COMMAND, MOVE_TO_END } from 'lexical';
10
+ import { ElementNode, $createParagraphNode, $isTextNode, $isTabNode, $createTabNode, $createLineBreakNode, $create, TextNode, $applyNodeReplacement, $getSiblingCaret, getTextDirection, $isElementNode, $isLineBreakNode, defineExtension, $createTextNode, $getNodeByKey, $getSelection, $isRangeSelection, $createPoint, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, INSERT_TAB_COMMAND, $setSelectionFromCaretRange, $getCaretRangeInDirection, $getCaretRange, $getTextPointCaret, $normalizeCaret, KEY_ARROW_UP_COMMAND, MOVE_TO_START, KEY_TAB_COMMAND, COMMAND_PRIORITY_LOW, $insertNodes, KEY_ARROW_DOWN_COMMAND, MOVE_TO_END } from 'lexical';
11
11
  import 'prismjs';
12
12
  import 'prismjs/components/prism-clike.js';
13
13
  import 'prismjs/components/prism-javascript.js';
@@ -530,6 +530,40 @@ function $getFirstCodeNodeOfLine(anchor) {
530
530
  function $getLastCodeNodeOfLine(anchor) {
531
531
  return $getLastMatchingCodeNode(anchor, 'next');
532
532
  }
533
+
534
+ /**
535
+ * Determines the visual writing direction of a code line.
536
+ *
537
+ * Scans the line segments (CodeHighlightNode/TabNode) from start to end
538
+ * and returns the first strong direction found ("ltr" or "rtl").
539
+ * If no strong character is found, falls back to the parent element's
540
+ * direction. Returns null if indeterminate.
541
+ */
542
+ function $getCodeLineDirection(anchor) {
543
+ const start = $getFirstCodeNodeOfLine(anchor);
544
+ const end = $getLastCodeNodeOfLine(anchor);
545
+ let node = start;
546
+ while (node !== null) {
547
+ if ($isCodeHighlightNode(node)) {
548
+ const direction = getTextDirection(node.getTextContent());
549
+ if (direction !== null) {
550
+ return direction;
551
+ }
552
+ }
553
+ if (node === end) {
554
+ break;
555
+ }
556
+ node = node.getNextSibling();
557
+ }
558
+ const parent = start.getParent();
559
+ if ($isElementNode(parent)) {
560
+ const parentDirection = parent.getDirection();
561
+ if (parentDirection === 'ltr' || parentDirection === 'rtl') {
562
+ return parentDirection;
563
+ }
564
+ }
565
+ return null;
566
+ }
533
567
  function $getStartOfCodeInLine(anchor, offset) {
534
568
  let last = null;
535
569
  let lastNonBlank = null;
@@ -1416,8 +1450,11 @@ function $handleMoveTo(type, event) {
1416
1450
  if (!$isSelectionInCode(selection) || !($isCodeHighlightNode(anchorNode) || $isTabNode(anchorNode)) || !($isCodeHighlightNode(focusNode) || $isTabNode(focusNode))) {
1417
1451
  return false;
1418
1452
  }
1419
- if (isMoveToStart) {
1420
- const start = $getStartOfCodeInLine(focusNode, focus.offset);
1453
+ const focusLineNode = focusNode;
1454
+ const direction = $getCodeLineDirection(focusLineNode);
1455
+ const moveToStart = direction === 'rtl' ? !isMoveToStart : isMoveToStart;
1456
+ if (moveToStart) {
1457
+ const start = $getStartOfCodeInLine(focusLineNode, focus.offset);
1421
1458
  if (start !== null) {
1422
1459
  const {
1423
1460
  node,
@@ -1429,10 +1466,10 @@ function $handleMoveTo(type, event) {
1429
1466
  selection.setTextNodeRange(node, offset, node, offset);
1430
1467
  }
1431
1468
  } else {
1432
- focusNode.getParentOrThrow().selectStart();
1469
+ focusLineNode.getParentOrThrow().selectStart();
1433
1470
  }
1434
1471
  } else {
1435
- const node = $getEndOfCodeInLine(focusNode);
1472
+ const node = $getEndOfCodeInLine(focusLineNode);
1436
1473
  node.select();
1437
1474
  }
1438
1475
  event.preventDefault();
@@ -1540,4 +1577,4 @@ const getEndOfCodeInLine = $getEndOfCodeInLine;
1540
1577
  /** @deprecated renamed to {@link $getStartOfCodeInLine} by @lexical/eslint-plugin rules-of-lexical */
1541
1578
  const getStartOfCodeInLine = $getStartOfCodeInLine;
1542
1579
 
1543
- export { $createCodeHighlightNode, $createCodeNode, $getEndOfCodeInLine, $getFirstCodeNodeOfLine, $getLastCodeNodeOfLine, $getStartOfCodeInLine, $isCodeHighlightNode, $isCodeNode, CODE_LANGUAGE_FRIENDLY_NAME_MAP, CODE_LANGUAGE_MAP, CodeExtension, CodeHighlightNode, CodeNode, DEFAULT_CODE_LANGUAGE, PrismTokenizer, getCodeLanguageOptions, getCodeLanguages, getCodeThemeOptions, getDefaultCodeLanguage, getEndOfCodeInLine, getFirstCodeNodeOfLine, getLanguageFriendlyName, getLastCodeNodeOfLine, getStartOfCodeInLine, normalizeCodeLang, normalizeCodeLang as normalizeCodeLanguage, registerCodeHighlighting };
1580
+ export { $createCodeHighlightNode, $createCodeNode, $getCodeLineDirection, $getEndOfCodeInLine, $getFirstCodeNodeOfLine, $getLastCodeNodeOfLine, $getStartOfCodeInLine, $isCodeHighlightNode, $isCodeNode, CODE_LANGUAGE_FRIENDLY_NAME_MAP, CODE_LANGUAGE_MAP, CodeExtension, CodeHighlightNode, CodeNode, DEFAULT_CODE_LANGUAGE, PrismTokenizer, getCodeLanguageOptions, getCodeLanguages, getCodeThemeOptions, getDefaultCodeLanguage, getEndOfCodeInLine, getFirstCodeNodeOfLine, getLanguageFriendlyName, getLastCodeNodeOfLine, getStartOfCodeInLine, normalizeCodeLang, normalizeCodeLang as normalizeCodeLanguage, registerCodeHighlighting };
package/LexicalCode.mjs CHANGED
@@ -11,6 +11,7 @@ import * as modProd from './LexicalCode.prod.mjs';
11
11
  const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
12
12
  export const $createCodeHighlightNode = mod.$createCodeHighlightNode;
13
13
  export const $createCodeNode = mod.$createCodeNode;
14
+ export const $getCodeLineDirection = mod.$getCodeLineDirection;
14
15
  export const $getEndOfCodeInLine = mod.$getEndOfCodeInLine;
15
16
  export const $getFirstCodeNodeOfLine = mod.$getFirstCodeNodeOfLine;
16
17
  export const $getLastCodeNodeOfLine = mod.$getLastCodeNodeOfLine;
@@ -9,6 +9,7 @@
9
9
  const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalCode.dev.mjs') : import('./LexicalCode.prod.mjs'));
10
10
  export const $createCodeHighlightNode = mod.$createCodeHighlightNode;
11
11
  export const $createCodeNode = mod.$createCodeNode;
12
+ export const $getCodeLineDirection = mod.$getCodeLineDirection;
12
13
  export const $getEndOfCodeInLine = mod.$getEndOfCodeInLine;
13
14
  export const $getFirstCodeNodeOfLine = mod.$getFirstCodeNodeOfLine;
14
15
  export const $getLastCodeNodeOfLine = mod.$getLastCodeNodeOfLine;
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@lexical/utils"),t=require("lexical");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.`)}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-powershell"),require("prismjs/components/prism-python"),require("prismjs/components/prism-rust"),require("prismjs/components/prism-swift"),require("prismjs/components/prism-typescript"),require("prismjs/components/prism-java"),require("prismjs/components/prism-cpp");const r="javascript";function i(t,n){for(const r of t.childNodes){if(e.isHTMLElement(r)&&r.tagName===n)return!0;i(r,n)}return!1}const o="data-language",s="data-highlight-language",a="data-theme";class g extends t.ElementNode{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new g(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(o,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(s,r));const i=this.getTheme();i&&n.setAttribute(a,i);const g=this.getStyle();return g&&n.setAttribute("style",g),n}updateDOM(e,t,n){const r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(o,r):i&&t.removeAttribute(o);const g=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?g&&r?r!==i&&t.setAttribute(s,r):t.removeAttribute(s):g&&r&&t.setAttribute(s,r);const l=this.__theme,u=e.__theme;l?l!==u&&t.setAttribute(a,l):u&&t.removeAttribute(a);const c=this.__style,p=e.__style;return c?c!==p&&t.setAttribute("style",c):p&&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(o,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(s,r));const i=this.getTheme();i&&n.setAttribute(a,i);const g=this.getStyle();return g&&n.setAttribute("style",g),{element:n}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||i(e,"BR"))?{conversion:c,priority:1}:null,div:()=>({conversion:p,priority:1}),pre:()=>({conversion:c,priority:0}),table:e=>N(e)?{conversion:d,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&N(n)?{conversion:f,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&N(t)?{conversion:f,priority:3}:null}}}static importJSON(e){return l().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(e,n=!0){const r=this.getChildren(),i=r.length;if(i>=2&&"\n"===r[i-1].getTextContent()&&"\n"===r[i-2].getTextContent()&&e.isCollapsed()&&e.anchor.key===this.__key&&e.anchor.offset===i){r[i-1].remove(),r[i-2].remove();const e=t.$createParagraphNode();return this.insertAfter(e,n),e}const{anchor:o,focus:s}=e,a=(o.isBefore(s)?o:s).getNode();if(t.$isTextNode(a)){let e=O(a);const n=[];for(;;)if(t.$isTabNode(e))n.push(t.$createTabNode()),e=e.getNextSibling();else{if(!x(e))break;{let t=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;t<i&&" "===r[t];)t++;if(0!==t&&n.push(T(" ".repeat(t))),t!==i)break;e=e.getNextSibling()}}const r=a.splitText(o.offset)[0],i=0===o.offset?0:1,s=r.getIndexWithinParent()+i,g=a.getParentOrThrow(),l=[t.$createLineBreakNode(),...n];g.splice(s,0,l);const u=n[n.length-1];u?u.select():0===o.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(u(a)){const{offset:n}=e.anchor;a.splice(n,0,[t.$createLineBreakNode()]),a.select(n+1,n+1)}return null}canIndent(){return!1}collapseAtStart(){const e=t.$createParagraphNode();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!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 l(e,n){return t.$create(g).setLanguage(e).setTheme(n)}function u(e){return e instanceof g}function c(e){return{node:l(e.getAttribute(o))}}function p(e){const t=e,n=h(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(h(t))return!0;t=t.parentElement}return!1}(t)?{node:n?l():null}:{node:null}}function d(){return{node:l()}}function f(){return{node:null}}function h(e){return null!==e.style.fontFamily.match("monospace")}function N(e){return e.classList.contains("js-file-line-container")}class m extends t.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new m(e.__text,e.__highlightType||void 0,e.__key)}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=_(t.theme,this.__highlightType);return e.addClassNamesToElement(n,r),n}updateDOM(t,n,r){const i=super.updateDOM(t,n,r),o=_(r.theme,t.__highlightType),s=_(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 l()}}function _(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function T(e="",n){return t.$applyNodeReplacement(new m(e,n))}function x(e){return e instanceof m}function C(n,r){let i=n;for(let o=t.$getSiblingCaret(n,r);o&&(x(o.origin)||t.$isTabNode(o.origin));o=e.$getAdjacentCaret(o))i=o.origin;return i}function O(e){return C(e,"previous")}function S(e){return C(e,"next")}function y(e,r){let i=null,o=null,s=e,a=r,g=e.getTextContent();for(;;){if(0===a){if(s=s.getPreviousSibling(),null===s)break;if(x(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||n(167),t.$isLineBreakNode(s)){i={node:s,offset:1};break}a=Math.max(0,s.getTextContentSize()-1),g=s.getTextContent()}else a--;const e=g[a];x(s)&&" "!==e&&(o={node:s,offset:a})}if(null!==o)return o;let l=null;if(r<e.getTextContentSize())x(e)&&(l=e.getTextContent()[r]);else{const t=e.getNextSibling();x(t)&&(l=t.getTextContent()[0])}if(null!==l&&" "!==l)return i;{const n=function(e,n){let r=e,i=n,o=e.getTextContent(),s=e.getTextContentSize();for(;;){if(!x(r)||i===s){if(r=r.getNextSibling(),null===r||t.$isLineBreakNode(r))return null;x(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(x(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(e,r);return null!==n?n:i}}function $(e){const r=S(e);return t.$isLineBreakNode(r)&&n(168),r}const A=t.defineExtension({name:"@lexical/code",nodes:[g,m]});!function(e){e.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var t={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(t).forEach(function(n){var r=t[n],i=[];/^\w+$/.test(n)||i.push(/\w+/.exec(n)[0]),"diff"===n&&i.push("bold"),e.languages.diff[n]={pattern:RegExp("^(?:["+r+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}}),Object.defineProperty(e.languages.diff,"PREFIXES",{value:t})}(Prism);const b=globalThis.Prism||window.Prism,L={c:"C",clike:"C-like",cpp:"C++",css:"CSS",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},M={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function E(e){return M[e]||e}function v(e){return"string"==typeof e?e:Array.isArray(e)?e.map(v).join(""):v(e.content)}function D(e,t){const n=/^diff-([\w-]+)/i.exec(t),r=e.getTextContent();let i=b.tokenize(r,b.languages[n?"diff":t]);return n&&(i=function(e,t){const n=t,r=b.languages[n],i={tokens:e},o=b.languages.diff.PREFIXES;for(const e of i.tokens){if("string"==typeof e||!(e.type in o)||!Array.isArray(e.content))continue;const t=e.type;let n=0;const i=()=>(n++,new b.Token("prefix",o[t],t.replace(/^(\w+).*/,"$1"))),s=e.content.filter(e=>"string"==typeof e||"prefix"!==e.type),a=e.content.length-s.length,g=b.tokenize(v(s),r);g.unshift(i());const l=/\r\n|\n/g,u=e=>{const t=[];l.lastIndex=0;let r,o=0;for(;n<a&&(r=l.exec(e));){const n=r.index+r[0].length;t.push(e.slice(o,n)),o=n,t.push(i())}if(0!==t.length)return o<e.length&&t.push(e.slice(o)),t},c=e=>{for(let t=0;t<e.length&&n<a;t++){const n=e[t];if("string"==typeof n){const r=u(n);r&&(e.splice(t,1,...r),t+=r.length-1)}else if("string"==typeof n.content){const e=u(n.content);e&&(n.content=e)}else Array.isArray(n.content)?c(n.content):c([n.content])}};c(g),n<a&&g.push(i()),e.content=g}return i.tokens}(i,n[1])),R(i)}function R(e,n){const r=[];for(const i of e)if("string"==typeof i){const e=i.split(/(\n|\t)/),o=e.length;for(let i=0;i<o;i++){const o=e[i];"\n"===o||"\r\n"===o?r.push(t.$createLineBreakNode()):"\t"===o?r.push(t.$createTabNode()):o.length>0&&r.push(T(o,n))}}else{const{content:e,alias:t}=i;"string"==typeof e?r.push(...R([e],"prefix"===i.type&&"string"==typeof t?t:i.type)):Array.isArray(e)&&r.push(...R(e,"unchanged"===i.type?void 0:i.type))}return r}const k={$tokenize(e,t){return D(e,t||this.defaultLanguage)},defaultLanguage:r,tokenize(e,t){return b.tokenize(e,b.languages[t||""]||b.languages[this.defaultLanguage])}};function P(e,n,r){const i=e.getParent();u(i)?B(i,n,r):x(e)&&e.replace(t.$createTextNode(e.__text))}function I(e,n){const r=n.getElementByKey(e.getKey());if(null===r)return;const i=e.getChildren(),o=i.length;if(o===r.__cachedChildrenLength)return;r.__cachedChildrenLength=o;let s="1",a=1;for(let e=0;e<o;e++)t.$isLineBreakNode(i[e])&&(s+="\n"+ ++a);r.setAttribute("data-gutter",s)}const w=new Set;function B(e,n,r){const i=e.getKey();void 0===e.getLanguage()&&e.setLanguage(r.defaultLanguage);const o=e.getLanguage()||r.defaultLanguage;if(!function(e){const t=function(e){const t=/^diff-([\w-]+)/i.exec(e);return t?t[1]:null}(e),n=t||e;try{return!!n&&b.languages.hasOwnProperty(n)}catch(e){return!1}}(o))return e.getIsSyntaxHighlightSupported()&&e.setIsSyntaxHighlightSupported(!1),void async function(){}();e.getIsSyntaxHighlightSupported()||e.setIsSyntaxHighlightSupported(!0),w.has(i)||(w.add(i),n.update(()=>{!function(e,n){const r=t.$getNodeByKey(e);if(!u(r)||!r.isAttached())return;const i=t.$getSelection();if(!t.$isRangeSelection(i))return void n();const o=i.anchor,s=o.offset,a="element"===o.type&&t.$isLineBreakNode(r.getChildAtIndex(o.offset-1));let g=0;if(!a){const e=o.getNode();g=s+e.getPreviousSiblings().reduce((e,t)=>e+t.getTextContentSize(),0)}if(!n())return;if(a)return void o.getNode().select(s,s);r.getChildren().some(e=>{const n=t.$isTextNode(e);if(n||t.$isLineBreakNode(e)){const t=e.getTextContentSize();if(n&&t>=g)return e.select(g,g),!0;g-=t}return!1})}(i,()=>{const n=t.$getNodeByKey(i);if(!u(n)||!n.isAttached())return!1;const o=n.getLanguage()||r.defaultLanguage,s=r.$tokenize(n,o),a=function(e,t){let n=0;for(;n<e.length&&j(e[n],t[n]);)n++;const r=e.length,i=t.length,o=Math.min(r,i)-n;let s=0;for(;s<o;)if(s++,!j(e[r-s],t[i-s])){s--;break}const a=n,g=r-s,l=t.slice(n,i-s);return{from:a,nodesForReplacement:l,to:g}}(n.getChildren(),s),{from:g,to:l,nodesForReplacement:c}=a;return!(g===l&&!c.length)&&(e.splice(g,l-g,c),!0)})},{onUpdate:()=>{w.delete(i)},skipTransforms:!0}))}function j(e,n){return x(e)&&x(n)&&e.__text===n.__text&&e.__highlightType===n.__highlightType||t.$isTabNode(e)&&t.$isTabNode(n)||t.$isLineBreakNode(e)&&t.$isLineBreakNode(n)}function H(e){if(!t.$isRangeSelection(e))return!1;const n=e.anchor.getNode(),r=u(n)?n:n.getParent(),i=e.focus.getNode(),o=u(i)?i:i.getParent();return u(r)&&r.is(o)}function F(e){const r=e.getNodes(),i=[];if(1===r.length&&u(r[0]))return i;let o=[];for(let e=0;e<r.length;e++){const s=r[e];x(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||n(169),t.$isLineBreakNode(s)?o.length>0&&(i.push(o),o=[]):o.push(s)}if(o.length>0){const n=e.isBackward()?e.anchor:e.focus,r=t.$createPoint(o[0].getKey(),0,"text");n.is(r)||i.push(o)}return i}function q(e){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!H(n))return!1;const r=F(n),i=r.length;if(0===i&&n.isCollapsed())return e===t.INDENT_CONTENT_COMMAND&&n.insertNodes([t.$createTabNode()]),!0;if(0===i&&e===t.INDENT_CONTENT_COMMAND&&"\n"===n.getTextContent()){const e=t.$createTabNode(),r=t.$createLineBreakNode(),i=n.isBackward()?"previous":"next";return n.insertNodes([e,r]),t.$setSelectionFromCaretRange(t.$getCaretRangeInDirection(t.$getCaretRange(t.$getTextPointCaret(e,"next",0),t.$normalizeCaret(t.$getSiblingCaret(r,"next"))),i)),!0}for(let o=0;o<i;o++){const i=r[o];if(i.length>0){let r=i[0];if(0===o&&(r=O(r)),e===t.INDENT_CONTENT_COMMAND){const e=t.$createTabNode();if(r.insertBefore(e),0===o){const i=n.isBackward()?"focus":"anchor",o=t.$createPoint(r.getKey(),0,"text");n[i].is(o)&&n[i].set(e.getKey(),0,"text")}}else t.$isTabNode(r)&&r.remove()}}return!0}function z(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.offset,a=o.offset,g=i.getNode(),l=o.getNode(),u=e===t.KEY_ARROW_UP_COMMAND;if(!H(r)||!x(g)&&!t.$isTabNode(g)||!x(l)&&!t.$isTabNode(l))return!1;if(!n.altKey){if(r.isCollapsed()){const e=g.getParentOrThrow();if(u&&0===s&&null===g.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),n.preventDefault(),!0}else if(!u&&s===g.getTextContentSize()&&null===g.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),n.preventDefault(),!0}}return!1}let c,p;if(g.isBefore(l)?(c=O(g),p=S(l)):(c=O(l),p=S(g)),null==c||null==p)return!1;const d=c.getNodesBetween(p);for(let e=0;e<d.length;e++){const n=d[e];if(!x(n)&&!t.$isTabNode(n)&&!t.$isLineBreakNode(n))return!1}n.preventDefault(),n.stopPropagation();const f=u?c.getPreviousSibling():p.getNextSibling();if(!t.$isLineBreakNode(f))return!0;const h=u?f.getPreviousSibling():f.getNextSibling();if(null==h)return!0;const N=x(h)||t.$isTabNode(h)||t.$isLineBreakNode(h)?u?O(h):S(h):null;let m=null!=N?N:h;return f.remove(),d.forEach(e=>e.remove()),e===t.KEY_ARROW_UP_COMMAND?(d.forEach(e=>m.insertBefore(e)),m.insertBefore(f)):(m.insertAfter(f),m=f,d.forEach(e=>{m.insertAfter(e),m=e})),r.setTextNodeRange(g,s,l,a),!0}function W(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.getNode(),a=o.getNode(),g=e===t.MOVE_TO_START;if(!H(r)||!x(s)&&!t.$isTabNode(s)||!x(a)&&!t.$isTabNode(a))return!1;if(g){const e=y(a,o.offset);if(null!==e){const{node:n,offset:i}=e;t.$isLineBreakNode(n)?n.selectNext(0,0):r.setTextNodeRange(n,i,n,i)}else a.getParentOrThrow().selectStart()}else{$(a).select()}return n.preventDefault(),n.stopPropagation(),!0}const K=O,Y=S,U=$,J=y;exports.$createCodeHighlightNode=T,exports.$createCodeNode=l,exports.$getEndOfCodeInLine=$,exports.$getFirstCodeNodeOfLine=O,exports.$getLastCodeNodeOfLine=S,exports.$getStartOfCodeInLine=y,exports.$isCodeHighlightNode=x,exports.$isCodeNode=u,exports.CODE_LANGUAGE_FRIENDLY_NAME_MAP=L,exports.CODE_LANGUAGE_MAP=M,exports.CodeExtension=A,exports.CodeHighlightNode=m,exports.CodeNode=g,exports.DEFAULT_CODE_LANGUAGE=r,exports.PrismTokenizer=k,exports.getCodeLanguageOptions=function(){const e=[];for(const[t,n]of Object.entries(L))e.push([t,n]);return e},exports.getCodeLanguages=()=>Object.keys(b.languages).filter(e=>"function"!=typeof b.languages[e]).sort(),exports.getCodeThemeOptions=function(){return[]},exports.getDefaultCodeLanguage=()=>r,exports.getEndOfCodeInLine=U,exports.getFirstCodeNodeOfLine=K,exports.getLanguageFriendlyName=function(e){const t=E(e);return L[t]||t},exports.getLastCodeNodeOfLine=Y,exports.getStartOfCodeInLine=J,exports.normalizeCodeLang=E,exports.normalizeCodeLanguage=E,exports.registerCodeHighlighting=function(r,i){if(!r.hasNodes([g,m]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");null==i&&(i=k);const o=[];return!0!==r._headless&&o.push(r.registerMutationListener(g,e=>{r.getEditorState().read(()=>{for(const[n,i]of e)if("destroyed"!==i){const e=t.$getNodeByKey(n);null!==e&&I(e,r)}})},{skipInitialization:!1})),o.push(r.registerNodeTransform(g,e=>B(e,r,i)),r.registerNodeTransform(t.TextNode,e=>P(e,r,i)),r.registerNodeTransform(m,e=>P(e,r,i)),r.registerCommand(t.KEY_TAB_COMMAND,e=>{const i=function(e){const r=t.$getSelection();if(!t.$isRangeSelection(r)||!H(r))return null;const i=e?t.OUTDENT_CONTENT_COMMAND:t.INDENT_CONTENT_COMMAND,o=e?t.OUTDENT_CONTENT_COMMAND:t.INSERT_TAB_COMMAND,s=r.anchor,a=r.focus;if(s.is(a))return o;const g=F(r);if(1!==g.length)return i;const l=g[0];let u,c;0===l.length&&n(285),r.isBackward()?(u=a,c=s):(u=s,c=a);const p=O(l[0]),d=S(l[0]),f=t.$createPoint(p.getKey(),0,"text"),h=t.$createPoint(d.getKey(),d.getTextContentSize(),"text");return u.isBefore(f)||h.isBefore(c)?i:f.isBefore(u)||c.isBefore(h)?o:i}(e.shiftKey);return null!==i&&(e.preventDefault(),r.dispatchCommand(i,void 0),!0)},t.COMMAND_PRIORITY_LOW),r.registerCommand(t.INSERT_TAB_COMMAND,()=>!!H(t.$getSelection())&&(t.$insertNodes([t.$createTabNode()]),!0),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.INDENT_CONTENT_COMMAND,e=>q(t.INDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.OUTDENT_CONTENT_COMMAND,e=>q(t.OUTDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!H(n)&&(n.isCollapsed()&&0===r.offset&&null===i.getPreviousSibling()&&u(i.getParentOrThrow())?(e.preventDefault(),!0):z(t.KEY_ARROW_UP_COMMAND,e))},t.COMMAND_PRIORITY_LOW),r.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!H(n)&&(n.isCollapsed()&&r.offset===i.getTextContentSize()&&null===i.getNextSibling()&&u(i.getParentOrThrow())?(e.preventDefault(),!0):z(t.KEY_ARROW_DOWN_COMMAND,e))},t.COMMAND_PRIORITY_LOW),r.registerCommand(t.MOVE_TO_START,e=>W(t.MOVE_TO_START,e),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.MOVE_TO_END,e=>W(t.MOVE_TO_END,e),t.COMMAND_PRIORITY_LOW)),e.mergeRegister(...o)};
9
+ "use strict";var e=require("@lexical/utils"),t=require("lexical");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.`)}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-powershell"),require("prismjs/components/prism-python"),require("prismjs/components/prism-rust"),require("prismjs/components/prism-swift"),require("prismjs/components/prism-typescript"),require("prismjs/components/prism-java"),require("prismjs/components/prism-cpp");const r="javascript";function i(t,n){for(const r of t.childNodes){if(e.isHTMLElement(r)&&r.tagName===n)return!0;i(r,n)}return!1}const o="data-language",s="data-highlight-language",a="data-theme";class l extends t.ElementNode{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new l(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(o,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(s,r));const i=this.getTheme();i&&n.setAttribute(a,i);const l=this.getStyle();return l&&n.setAttribute("style",l),n}updateDOM(e,t,n){const r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(o,r):i&&t.removeAttribute(o);const l=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?l&&r?r!==i&&t.setAttribute(s,r):t.removeAttribute(s):l&&r&&t.setAttribute(s,r);const g=this.__theme,c=e.__theme;g?g!==c&&t.setAttribute(a,g):c&&t.removeAttribute(a);const u=this.__style,d=e.__style;return u?u!==d&&t.setAttribute("style",u):d&&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(o,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(s,r));const i=this.getTheme();i&&n.setAttribute(a,i);const l=this.getStyle();return l&&n.setAttribute("style",l),{element:n}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||i(e,"BR"))?{conversion:u,priority:1}:null,div:()=>({conversion:d,priority:1}),pre:()=>({conversion:u,priority:0}),table:e=>N(e)?{conversion:p,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&N(n)?{conversion:f,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&N(t)?{conversion:f,priority:3}:null}}}static importJSON(e){return g().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(e,n=!0){const r=this.getChildren(),i=r.length;if(i>=2&&"\n"===r[i-1].getTextContent()&&"\n"===r[i-2].getTextContent()&&e.isCollapsed()&&e.anchor.key===this.__key&&e.anchor.offset===i){r[i-1].remove(),r[i-2].remove();const e=t.$createParagraphNode();return this.insertAfter(e,n),e}const{anchor:o,focus:s}=e,a=(o.isBefore(s)?o:s).getNode();if(t.$isTextNode(a)){let e=O(a);const n=[];for(;;)if(t.$isTabNode(e))n.push(t.$createTabNode()),e=e.getNextSibling();else{if(!x(e))break;{let t=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;t<i&&" "===r[t];)t++;if(0!==t&&n.push(T(" ".repeat(t))),t!==i)break;e=e.getNextSibling()}}const r=a.splitText(o.offset)[0],i=0===o.offset?0:1,s=r.getIndexWithinParent()+i,l=a.getParentOrThrow(),g=[t.$createLineBreakNode(),...n];l.splice(s,0,g);const c=n[n.length-1];c?c.select():0===o.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(c(a)){const{offset:n}=e.anchor;a.splice(n,0,[t.$createLineBreakNode()]),a.select(n+1,n+1)}return null}canIndent(){return!1}collapseAtStart(){const e=t.$createParagraphNode();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!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 g(e,n){return t.$create(l).setLanguage(e).setTheme(n)}function c(e){return e instanceof l}function u(e){return{node:g(e.getAttribute(o))}}function d(e){const t=e,n=h(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(h(t))return!0;t=t.parentElement}return!1}(t)?{node:n?g():null}:{node:null}}function p(){return{node:g()}}function f(){return{node:null}}function h(e){return null!==e.style.fontFamily.match("monospace")}function N(e){return e.classList.contains("js-file-line-container")}class m extends t.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new m(e.__text,e.__highlightType||void 0,e.__key)}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=_(t.theme,this.__highlightType);return e.addClassNamesToElement(n,r),n}updateDOM(t,n,r){const i=super.updateDOM(t,n,r),o=_(r.theme,t.__highlightType),s=_(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 g()}}function _(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function T(e="",n){return t.$applyNodeReplacement(new m(e,n))}function x(e){return e instanceof m}function C(n,r){let i=n;for(let o=t.$getSiblingCaret(n,r);o&&(x(o.origin)||t.$isTabNode(o.origin));o=e.$getAdjacentCaret(o))i=o.origin;return i}function O(e){return C(e,"previous")}function S(e){return C(e,"next")}function y(e){const n=O(e),r=S(e);let i=n;for(;null!==i;){if(x(i)){const e=t.getTextDirection(i.getTextContent());if(null!==e)return e}if(i===r)break;i=i.getNextSibling()}const o=n.getParent();if(t.$isElementNode(o)){const e=o.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function $(e,r){let i=null,o=null,s=e,a=r,l=e.getTextContent();for(;;){if(0===a){if(s=s.getPreviousSibling(),null===s)break;if(x(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||n(167),t.$isLineBreakNode(s)){i={node:s,offset:1};break}a=Math.max(0,s.getTextContentSize()-1),l=s.getTextContent()}else a--;const e=l[a];x(s)&&" "!==e&&(o={node:s,offset:a})}if(null!==o)return o;let g=null;if(r<e.getTextContentSize())x(e)&&(g=e.getTextContent()[r]);else{const t=e.getNextSibling();x(t)&&(g=t.getTextContent()[0])}if(null!==g&&" "!==g)return i;{const n=function(e,n){let r=e,i=n,o=e.getTextContent(),s=e.getTextContentSize();for(;;){if(!x(r)||i===s){if(r=r.getNextSibling(),null===r||t.$isLineBreakNode(r))return null;x(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(x(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(e,r);return null!==n?n:i}}function A(e){const r=S(e);return t.$isLineBreakNode(r)&&n(168),r}const b=t.defineExtension({name:"@lexical/code",nodes:[l,m]});!function(e){e.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var t={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(t).forEach(function(n){var r=t[n],i=[];/^\w+$/.test(n)||i.push(/\w+/.exec(n)[0]),"diff"===n&&i.push("bold"),e.languages.diff[n]={pattern:RegExp("^(?:["+r+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}}),Object.defineProperty(e.languages.diff,"PREFIXES",{value:t})}(Prism);const L=globalThis.Prism||window.Prism,M={c:"C",clike:"C-like",cpp:"C++",css:"CSS",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},E={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function v(e){return E[e]||e}function D(e){return"string"==typeof e?e:Array.isArray(e)?e.map(D).join(""):D(e.content)}function k(e,t){const n=/^diff-([\w-]+)/i.exec(t),r=e.getTextContent();let i=L.tokenize(r,L.languages[n?"diff":t]);return n&&(i=function(e,t){const n=t,r=L.languages[n],i={tokens:e},o=L.languages.diff.PREFIXES;for(const e of i.tokens){if("string"==typeof e||!(e.type in o)||!Array.isArray(e.content))continue;const t=e.type;let n=0;const i=()=>(n++,new L.Token("prefix",o[t],t.replace(/^(\w+).*/,"$1"))),s=e.content.filter(e=>"string"==typeof e||"prefix"!==e.type),a=e.content.length-s.length,l=L.tokenize(D(s),r);l.unshift(i());const g=/\r\n|\n/g,c=e=>{const t=[];g.lastIndex=0;let r,o=0;for(;n<a&&(r=g.exec(e));){const n=r.index+r[0].length;t.push(e.slice(o,n)),o=n,t.push(i())}if(0!==t.length)return o<e.length&&t.push(e.slice(o)),t},u=e=>{for(let t=0;t<e.length&&n<a;t++){const n=e[t];if("string"==typeof n){const r=c(n);r&&(e.splice(t,1,...r),t+=r.length-1)}else if("string"==typeof n.content){const e=c(n.content);e&&(n.content=e)}else Array.isArray(n.content)?u(n.content):u([n.content])}};u(l),n<a&&l.push(i()),e.content=l}return i.tokens}(i,n[1])),R(i)}function R(e,n){const r=[];for(const i of e)if("string"==typeof i){const e=i.split(/(\n|\t)/),o=e.length;for(let i=0;i<o;i++){const o=e[i];"\n"===o||"\r\n"===o?r.push(t.$createLineBreakNode()):"\t"===o?r.push(t.$createTabNode()):o.length>0&&r.push(T(o,n))}}else{const{content:e,alias:t}=i;"string"==typeof e?r.push(...R([e],"prefix"===i.type&&"string"==typeof t?t:i.type)):Array.isArray(e)&&r.push(...R(e,"unchanged"===i.type?void 0:i.type))}return r}const P={$tokenize(e,t){return k(e,t||this.defaultLanguage)},defaultLanguage:r,tokenize(e,t){return L.tokenize(e,L.languages[t||""]||L.languages[this.defaultLanguage])}};function I(e,n,r){const i=e.getParent();c(i)?j(i,n,r):x(e)&&e.replace(t.$createTextNode(e.__text))}function w(e,n){const r=n.getElementByKey(e.getKey());if(null===r)return;const i=e.getChildren(),o=i.length;if(o===r.__cachedChildrenLength)return;r.__cachedChildrenLength=o;let s="1",a=1;for(let e=0;e<o;e++)t.$isLineBreakNode(i[e])&&(s+="\n"+ ++a);r.setAttribute("data-gutter",s)}const B=new Set;function j(e,n,r){const i=e.getKey();void 0===e.getLanguage()&&e.setLanguage(r.defaultLanguage);const o=e.getLanguage()||r.defaultLanguage;if(!function(e){const t=function(e){const t=/^diff-([\w-]+)/i.exec(e);return t?t[1]:null}(e),n=t||e;try{return!!n&&L.languages.hasOwnProperty(n)}catch(e){return!1}}(o))return e.getIsSyntaxHighlightSupported()&&e.setIsSyntaxHighlightSupported(!1),void async function(){}();e.getIsSyntaxHighlightSupported()||e.setIsSyntaxHighlightSupported(!0),B.has(i)||(B.add(i),n.update(()=>{!function(e,n){const r=t.$getNodeByKey(e);if(!c(r)||!r.isAttached())return;const i=t.$getSelection();if(!t.$isRangeSelection(i))return void n();const o=i.anchor,s=o.offset,a="element"===o.type&&t.$isLineBreakNode(r.getChildAtIndex(o.offset-1));let l=0;if(!a){const e=o.getNode();l=s+e.getPreviousSiblings().reduce((e,t)=>e+t.getTextContentSize(),0)}if(!n())return;if(a)return void o.getNode().select(s,s);r.getChildren().some(e=>{const n=t.$isTextNode(e);if(n||t.$isLineBreakNode(e)){const t=e.getTextContentSize();if(n&&t>=l)return e.select(l,l),!0;l-=t}return!1})}(i,()=>{const n=t.$getNodeByKey(i);if(!c(n)||!n.isAttached())return!1;const o=n.getLanguage()||r.defaultLanguage,s=r.$tokenize(n,o),a=function(e,t){let n=0;for(;n<e.length&&H(e[n],t[n]);)n++;const r=e.length,i=t.length,o=Math.min(r,i)-n;let s=0;for(;s<o;)if(s++,!H(e[r-s],t[i-s])){s--;break}const a=n,l=r-s,g=t.slice(n,i-s);return{from:a,nodesForReplacement:g,to:l}}(n.getChildren(),s),{from:l,to:g,nodesForReplacement:u}=a;return!(l===g&&!u.length)&&(e.splice(l,g-l,u),!0)})},{onUpdate:()=>{B.delete(i)},skipTransforms:!0}))}function H(e,n){return x(e)&&x(n)&&e.__text===n.__text&&e.__highlightType===n.__highlightType||t.$isTabNode(e)&&t.$isTabNode(n)||t.$isLineBreakNode(e)&&t.$isLineBreakNode(n)}function F(e){if(!t.$isRangeSelection(e))return!1;const n=e.anchor.getNode(),r=c(n)?n:n.getParent(),i=e.focus.getNode(),o=c(i)?i:i.getParent();return c(r)&&r.is(o)}function q(e){const r=e.getNodes(),i=[];if(1===r.length&&c(r[0]))return i;let o=[];for(let e=0;e<r.length;e++){const s=r[e];x(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||n(169),t.$isLineBreakNode(s)?o.length>0&&(i.push(o),o=[]):o.push(s)}if(o.length>0){const n=e.isBackward()?e.anchor:e.focus,r=t.$createPoint(o[0].getKey(),0,"text");n.is(r)||i.push(o)}return i}function z(e){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!F(n))return!1;const r=q(n),i=r.length;if(0===i&&n.isCollapsed())return e===t.INDENT_CONTENT_COMMAND&&n.insertNodes([t.$createTabNode()]),!0;if(0===i&&e===t.INDENT_CONTENT_COMMAND&&"\n"===n.getTextContent()){const e=t.$createTabNode(),r=t.$createLineBreakNode(),i=n.isBackward()?"previous":"next";return n.insertNodes([e,r]),t.$setSelectionFromCaretRange(t.$getCaretRangeInDirection(t.$getCaretRange(t.$getTextPointCaret(e,"next",0),t.$normalizeCaret(t.$getSiblingCaret(r,"next"))),i)),!0}for(let o=0;o<i;o++){const i=r[o];if(i.length>0){let r=i[0];if(0===o&&(r=O(r)),e===t.INDENT_CONTENT_COMMAND){const e=t.$createTabNode();if(r.insertBefore(e),0===o){const i=n.isBackward()?"focus":"anchor",o=t.$createPoint(r.getKey(),0,"text");n[i].is(o)&&n[i].set(e.getKey(),0,"text")}}else t.$isTabNode(r)&&r.remove()}}return!0}function W(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.offset,a=o.offset,l=i.getNode(),g=o.getNode(),c=e===t.KEY_ARROW_UP_COMMAND;if(!F(r)||!x(l)&&!t.$isTabNode(l)||!x(g)&&!t.$isTabNode(g))return!1;if(!n.altKey){if(r.isCollapsed()){const e=l.getParentOrThrow();if(c&&0===s&&null===l.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),n.preventDefault(),!0}else if(!c&&s===l.getTextContentSize()&&null===l.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),n.preventDefault(),!0}}return!1}let u,d;if(l.isBefore(g)?(u=O(l),d=S(g)):(u=O(g),d=S(l)),null==u||null==d)return!1;const p=u.getNodesBetween(d);for(let e=0;e<p.length;e++){const n=p[e];if(!x(n)&&!t.$isTabNode(n)&&!t.$isLineBreakNode(n))return!1}n.preventDefault(),n.stopPropagation();const f=c?u.getPreviousSibling():d.getNextSibling();if(!t.$isLineBreakNode(f))return!0;const h=c?f.getPreviousSibling():f.getNextSibling();if(null==h)return!0;const N=x(h)||t.$isTabNode(h)||t.$isLineBreakNode(h)?c?O(h):S(h):null;let m=null!=N?N:h;return f.remove(),p.forEach(e=>e.remove()),e===t.KEY_ARROW_UP_COMMAND?(p.forEach(e=>m.insertBefore(e)),m.insertBefore(f)):(m.insertAfter(f),m=f,p.forEach(e=>{m.insertAfter(e),m=e})),r.setTextNodeRange(l,s,g,a),!0}function K(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.getNode(),a=o.getNode(),l=e===t.MOVE_TO_START;if(!F(r)||!x(s)&&!t.$isTabNode(s)||!x(a)&&!t.$isTabNode(a))return!1;const g=a;if("rtl"===y(g)?!l:l){const e=$(g,o.offset);if(null!==e){const{node:n,offset:i}=e;t.$isLineBreakNode(n)?n.selectNext(0,0):r.setTextNodeRange(n,i,n,i)}else g.getParentOrThrow().selectStart()}else{A(g).select()}return n.preventDefault(),n.stopPropagation(),!0}const Y=O,U=S,J=A,G=$;exports.$createCodeHighlightNode=T,exports.$createCodeNode=g,exports.$getCodeLineDirection=y,exports.$getEndOfCodeInLine=A,exports.$getFirstCodeNodeOfLine=O,exports.$getLastCodeNodeOfLine=S,exports.$getStartOfCodeInLine=$,exports.$isCodeHighlightNode=x,exports.$isCodeNode=c,exports.CODE_LANGUAGE_FRIENDLY_NAME_MAP=M,exports.CODE_LANGUAGE_MAP=E,exports.CodeExtension=b,exports.CodeHighlightNode=m,exports.CodeNode=l,exports.DEFAULT_CODE_LANGUAGE=r,exports.PrismTokenizer=P,exports.getCodeLanguageOptions=function(){const e=[];for(const[t,n]of Object.entries(M))e.push([t,n]);return e},exports.getCodeLanguages=()=>Object.keys(L.languages).filter(e=>"function"!=typeof L.languages[e]).sort(),exports.getCodeThemeOptions=function(){return[]},exports.getDefaultCodeLanguage=()=>r,exports.getEndOfCodeInLine=J,exports.getFirstCodeNodeOfLine=Y,exports.getLanguageFriendlyName=function(e){const t=v(e);return M[t]||t},exports.getLastCodeNodeOfLine=U,exports.getStartOfCodeInLine=G,exports.normalizeCodeLang=v,exports.normalizeCodeLanguage=v,exports.registerCodeHighlighting=function(r,i){if(!r.hasNodes([l,m]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");null==i&&(i=P);const o=[];return!0!==r._headless&&o.push(r.registerMutationListener(l,e=>{r.getEditorState().read(()=>{for(const[n,i]of e)if("destroyed"!==i){const e=t.$getNodeByKey(n);null!==e&&w(e,r)}})},{skipInitialization:!1})),o.push(r.registerNodeTransform(l,e=>j(e,r,i)),r.registerNodeTransform(t.TextNode,e=>I(e,r,i)),r.registerNodeTransform(m,e=>I(e,r,i)),r.registerCommand(t.KEY_TAB_COMMAND,e=>{const i=function(e){const r=t.$getSelection();if(!t.$isRangeSelection(r)||!F(r))return null;const i=e?t.OUTDENT_CONTENT_COMMAND:t.INDENT_CONTENT_COMMAND,o=e?t.OUTDENT_CONTENT_COMMAND:t.INSERT_TAB_COMMAND,s=r.anchor,a=r.focus;if(s.is(a))return o;const l=q(r);if(1!==l.length)return i;const g=l[0];let c,u;0===g.length&&n(285),r.isBackward()?(c=a,u=s):(c=s,u=a);const d=O(g[0]),p=S(g[0]),f=t.$createPoint(d.getKey(),0,"text"),h=t.$createPoint(p.getKey(),p.getTextContentSize(),"text");return c.isBefore(f)||h.isBefore(u)?i:f.isBefore(c)||u.isBefore(h)?o:i}(e.shiftKey);return null!==i&&(e.preventDefault(),r.dispatchCommand(i,void 0),!0)},t.COMMAND_PRIORITY_LOW),r.registerCommand(t.INSERT_TAB_COMMAND,()=>!!F(t.$getSelection())&&(t.$insertNodes([t.$createTabNode()]),!0),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.INDENT_CONTENT_COMMAND,e=>z(t.INDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.OUTDENT_CONTENT_COMMAND,e=>z(t.OUTDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!F(n)&&(n.isCollapsed()&&0===r.offset&&null===i.getPreviousSibling()&&c(i.getParentOrThrow())?(e.preventDefault(),!0):W(t.KEY_ARROW_UP_COMMAND,e))},t.COMMAND_PRIORITY_LOW),r.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!F(n)&&(n.isCollapsed()&&r.offset===i.getTextContentSize()&&null===i.getNextSibling()&&c(i.getParentOrThrow())?(e.preventDefault(),!0):W(t.KEY_ARROW_DOWN_COMMAND,e))},t.COMMAND_PRIORITY_LOW),r.registerCommand(t.MOVE_TO_START,e=>K(t.MOVE_TO_START,e),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.MOVE_TO_END,e=>K(t.MOVE_TO_END,e),t.COMMAND_PRIORITY_LOW)),e.mergeRegister(...o)};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{isHTMLElement as t,addClassNamesToElement as e,removeClassNamesFromElement as n,$getAdjacentCaret as r,mergeRegister as i}from"@lexical/utils";import{ElementNode as o,$createParagraphNode as s,$isTextNode as l,$isTabNode as u,$createTabNode as c,$createLineBreakNode as g,$create as a,TextNode as p,$applyNodeReplacement as f,$getSiblingCaret as h,$isLineBreakNode as d,defineExtension as m,$createTextNode as y,$getNodeByKey as x,$getSelection as _,$isRangeSelection as S,$createPoint as v,INDENT_CONTENT_COMMAND as T,OUTDENT_CONTENT_COMMAND as b,INSERT_TAB_COMMAND as C,$setSelectionFromCaretRange as N,$getCaretRangeInDirection as j,$getCaretRange as w,$getTextPointCaret as k,$normalizeCaret as A,KEY_ARROW_UP_COMMAND as P,MOVE_TO_START as L,KEY_TAB_COMMAND as O,COMMAND_PRIORITY_LOW as H,$insertNodes as E,KEY_ARROW_DOWN_COMMAND as z,MOVE_TO_END as B}from"lexical";import"prismjs";import"prismjs/components/prism-clike.js";import"prismjs/components/prism-javascript.js";import"prismjs/components/prism-markup.js";import"prismjs/components/prism-markdown.js";import"prismjs/components/prism-c.js";import"prismjs/components/prism-css.js";import"prismjs/components/prism-objectivec.js";import"prismjs/components/prism-sql.js";import"prismjs/components/prism-powershell.js";import"prismjs/components/prism-python.js";import"prismjs/components/prism-rust.js";import"prismjs/components/prism-swift.js";import"prismjs/components/prism-typescript.js";import"prismjs/components/prism-java.js";import"prismjs/components/prism-cpp.js";function D(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.`)}const F="javascript",I=()=>F;function M(e,n){for(const r of e.childNodes){if(t(r)&&r.tagName===n)return!0;M(r,n)}return!1}const J="data-language",R="data-highlight-language",K="data-theme";class $ extends o{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(t){return new $(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 n=document.createElement("code");e(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(J,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(R,r));const i=this.getTheme();i&&n.setAttribute(K,i);const o=this.getStyle();return o&&n.setAttribute("style",o),n}updateDOM(t,e,n){const r=this.__language,i=t.__language;r?r!==i&&e.setAttribute(J,r):i&&e.removeAttribute(J);const o=this.__isSyntaxHighlightSupported;t.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&e.setAttribute(R,r):e.removeAttribute(R):o&&r&&e.setAttribute(R,r);const s=this.__theme,l=t.__theme;s?s!==l&&e.setAttribute(K,s):l&&e.removeAttribute(K);const u=this.__style,c=t.__style;return u?u!==c&&e.setAttribute("style",u):c&&e.removeAttribute("style"),!1}exportDOM(t){const n=document.createElement("pre");e(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(J,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(R,r));const i=this.getTheme();i&&n.setAttribute(K,i);const o=this.getStyle();return o&&n.setAttribute("style",o),{element:n}}static importDOM(){return{code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||M(t,"BR"))?{conversion:U,priority:1}:null,div:()=>({conversion:X,priority:1}),pre:()=>({conversion:U,priority:0}),table:t=>Y(t)?{conversion:Q,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&Y(n)?{conversion:G,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&Y(e)?{conversion:G,priority:3}:null}}}static importJSON(t){return W().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 n=this.getChildren(),r=n.length;if(r>=2&&"\n"===n[r-1].getTextContent()&&"\n"===n[r-2].getTextContent()&&t.isCollapsed()&&t.anchor.key===this.__key&&t.anchor.offset===r){n[r-1].remove(),n[r-2].remove();const t=s();return this.insertAfter(t,e),t}const{anchor:i,focus:o}=t,a=(i.isBefore(o)?i:o).getNode();if(l(a)){let t=it(a);const e=[];for(;;)if(u(t))e.push(c()),t=t.getNextSibling();else{if(!nt(t))break;{let n=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&e.push(et(" ".repeat(n))),n!==i)break;t=t.getNextSibling()}}const n=a.splitText(i.offset)[0],r=0===i.offset?0:1,o=n.getIndexWithinParent()+r,s=a.getParentOrThrow(),l=[g(),...e];s.splice(o,0,l);const p=e[e.length-1];p?p.select():0===i.offset?n.selectPrevious():n.getNextSibling().selectNext(0,0)}if(q(a)){const{offset:e}=t.anchor;a.splice(e,0,[g()]),a.select(e+1,e+1)}return null}canIndent(){return!1}collapseAtStart(){const t=s();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 W(t,e){return a($).setLanguage(t).setTheme(e)}function q(t){return t instanceof $}function U(t){return{node:W(t.getAttribute(J))}}function X(t){const e=t,n=V(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(V(e))return!0;e=e.parentElement}return!1}(e)?{node:n?W():null}:{node:null}}function Q(){return{node:W()}}function G(){return{node:null}}function V(t){return null!==t.style.fontFamily.match("monospace")}function Y(t){return t.classList.contains("js-file-line-container")}class Z extends p{__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)}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(t){const e=this.getWritable();return e.__highlightType=t||void 0,e}canHaveFormat(){return!1}createDOM(t){const n=super.createDOM(t),r=tt(t.theme,this.__highlightType);return e(n,r),n}updateDOM(t,r,i){const o=super.updateDOM(t,r,i),s=tt(i.theme,t.__highlightType),l=tt(i.theme,this.__highlightType);return s!==l&&(s&&n(r,s),l&&e(r,l)),o}static importJSON(t){return et().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 W()}}function tt(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function et(t="",e){return f(new Z(t,e))}function nt(t){return t instanceof Z}function rt(t,e){let n=t;for(let i=h(t,e);i&&(nt(i.origin)||u(i.origin));i=r(i))n=i.origin;return n}function it(t){return rt(t,"previous")}function ot(t){return rt(t,"next")}function st(t,e){let n=null,r=null,i=t,o=e,s=t.getTextContent();for(;;){if(0===o){if(i=i.getPreviousSibling(),null===i)break;if(nt(i)||u(i)||d(i)||D(167),d(i)){n={node:i,offset:1};break}o=Math.max(0,i.getTextContentSize()-1),s=i.getTextContent()}else o--;const t=s[o];nt(i)&&" "!==t&&(r={node:i,offset:o})}if(null!==r)return r;let l=null;if(e<t.getTextContentSize())nt(t)&&(l=t.getTextContent()[e]);else{const e=t.getNextSibling();nt(e)&&(l=e.getTextContent()[0])}if(null!==l&&" "!==l)return n;{const r=function(t,e){let n=t,r=e,i=t.getTextContent(),o=t.getTextContentSize();for(;;){if(!nt(n)||r===o){if(n=n.getNextSibling(),null===n||d(n))return null;nt(n)&&(r=0,i=n.getTextContent(),o=n.getTextContentSize())}if(nt(n)){if(" "!==i[r])return{node:n,offset:r};r++}}}(t,e);return null!==r?r:n}}function lt(t){const e=ot(t);return d(e)&&D(168),e}const ut=m({name:"@lexical/code",nodes:[$,Z]});!function(t){t.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var e={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(e).forEach(function(n){var r=e[n],i=[];/^\w+$/.test(n)||i.push(/\w+/.exec(n)[0]),"diff"===n&&i.push("bold"),t.languages.diff[n]={pattern:RegExp("^(?:["+r+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}}),Object.defineProperty(t.languages.diff,"PREFIXES",{value:e})}(Prism);const ct=globalThis.Prism||window.Prism,gt={c:"C",clike:"C-like",cpp:"C++",css:"CSS",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},at={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function pt(t){return at[t]||t}function ft(t){const e=pt(t);return gt[e]||e}const ht=()=>Object.keys(ct.languages).filter(t=>"function"!=typeof ct.languages[t]).sort();function dt(){const t=[];for(const[e,n]of Object.entries(gt))t.push([e,n]);return t}function mt(){return[]}function yt(t){return"string"==typeof t?t:Array.isArray(t)?t.map(yt).join(""):yt(t.content)}function xt(t,e){const n=/^diff-([\w-]+)/i.exec(e),r=t.getTextContent();let i=ct.tokenize(r,ct.languages[n?"diff":e]);return n&&(i=function(t,e){const n=e,r=ct.languages[n],i={tokens:t},o=ct.languages.diff.PREFIXES;for(const t of i.tokens){if("string"==typeof t||!(t.type in o)||!Array.isArray(t.content))continue;const e=t.type;let n=0;const i=()=>(n++,new ct.Token("prefix",o[e],e.replace(/^(\w+).*/,"$1"))),s=t.content.filter(t=>"string"==typeof t||"prefix"!==t.type),l=t.content.length-s.length,u=ct.tokenize(yt(s),r);u.unshift(i());const c=/\r\n|\n/g,g=t=>{const e=[];c.lastIndex=0;let r,o=0;for(;n<l&&(r=c.exec(t));){const n=r.index+r[0].length;e.push(t.slice(o,n)),o=n,e.push(i())}if(0!==e.length)return o<t.length&&e.push(t.slice(o)),e},a=t=>{for(let e=0;e<t.length&&n<l;e++){const n=t[e];if("string"==typeof n){const r=g(n);r&&(t.splice(e,1,...r),e+=r.length-1)}else if("string"==typeof n.content){const t=g(n.content);t&&(n.content=t)}else Array.isArray(n.content)?a(n.content):a([n.content])}};a(u),n<l&&u.push(i()),t.content=u}return i.tokens}(i,n[1])),_t(i)}function _t(t,e){const n=[];for(const r of t)if("string"==typeof r){const t=r.split(/(\n|\t)/),i=t.length;for(let r=0;r<i;r++){const i=t[r];"\n"===i||"\r\n"===i?n.push(g()):"\t"===i?n.push(c()):i.length>0&&n.push(et(i,e))}}else{const{content:t,alias:e}=r;"string"==typeof t?n.push(..._t([t],"prefix"===r.type&&"string"==typeof e?e:r.type)):Array.isArray(t)&&n.push(..._t(t,"unchanged"===r.type?void 0:r.type))}return n}const St={$tokenize(t,e){return xt(t,e||this.defaultLanguage)},defaultLanguage:F,tokenize(t,e){return ct.tokenize(t,ct.languages[e||""]||ct.languages[this.defaultLanguage])}};function vt(t,e,n){const r=t.getParent();q(r)?Ct(r,e,n):nt(t)&&t.replace(y(t.__text))}function Tt(t,e){const n=e.getElementByKey(t.getKey());if(null===n)return;const r=t.getChildren(),i=r.length;if(i===n.__cachedChildrenLength)return;n.__cachedChildrenLength=i;let o="1",s=1;for(let t=0;t<i;t++)d(r[t])&&(o+="\n"+ ++s);n.setAttribute("data-gutter",o)}const bt=new Set;function Ct(t,e,n){const r=t.getKey();void 0===t.getLanguage()&&t.setLanguage(n.defaultLanguage);const i=t.getLanguage()||n.defaultLanguage;if(!function(t){const e=function(t){const e=/^diff-([\w-]+)/i.exec(t);return e?e[1]:null}(t),n=e||t;try{return!!n&&ct.languages.hasOwnProperty(n)}catch(t){return!1}}(i))return t.getIsSyntaxHighlightSupported()&&t.setIsSyntaxHighlightSupported(!1),void async function(){}();t.getIsSyntaxHighlightSupported()||t.setIsSyntaxHighlightSupported(!0),bt.has(r)||(bt.add(r),e.update(()=>{!function(t,e){const n=x(t);if(!q(n)||!n.isAttached())return;const r=_();if(!S(r))return void e();const i=r.anchor,o=i.offset,s="element"===i.type&&d(n.getChildAtIndex(i.offset-1));let u=0;if(!s){const t=i.getNode();u=o+t.getPreviousSiblings().reduce((t,e)=>t+e.getTextContentSize(),0)}if(!e())return;if(s)return void i.getNode().select(o,o);n.getChildren().some(t=>{const e=l(t);if(e||d(t)){const n=t.getTextContentSize();if(e&&n>=u)return t.select(u,u),!0;u-=n}return!1})}(r,()=>{const e=x(r);if(!q(e)||!e.isAttached())return!1;const i=e.getLanguage()||n.defaultLanguage,o=n.$tokenize(e,i),s=function(t,e){let n=0;for(;n<t.length&&Nt(t[n],e[n]);)n++;const r=t.length,i=e.length,o=Math.min(r,i)-n;let s=0;for(;s<o;)if(s++,!Nt(t[r-s],e[i-s])){s--;break}const l=n,u=r-s,c=e.slice(n,i-s);return{from:l,nodesForReplacement:c,to:u}}(e.getChildren(),o),{from:l,to:u,nodesForReplacement:c}=s;return!(l===u&&!c.length)&&(t.splice(l,u-l,c),!0)})},{onUpdate:()=>{bt.delete(r)},skipTransforms:!0}))}function Nt(t,e){return nt(t)&&nt(e)&&t.__text===e.__text&&t.__highlightType===e.__highlightType||u(t)&&u(e)||d(t)&&d(e)}function jt(t){if(!S(t))return!1;const e=t.anchor.getNode(),n=q(e)?e:e.getParent(),r=t.focus.getNode(),i=q(r)?r:r.getParent();return q(n)&&n.is(i)}function wt(t){const e=t.getNodes(),n=[];if(1===e.length&&q(e[0]))return n;let r=[];for(let t=0;t<e.length;t++){const i=e[t];nt(i)||u(i)||d(i)||D(169),d(i)?r.length>0&&(n.push(r),r=[]):r.push(i)}if(r.length>0){const e=t.isBackward()?t.anchor:t.focus,i=v(r[0].getKey(),0,"text");e.is(i)||n.push(r)}return n}function kt(t){const e=_();if(!S(e)||!jt(e))return!1;const n=wt(e),r=n.length;if(0===r&&e.isCollapsed())return t===T&&e.insertNodes([c()]),!0;if(0===r&&t===T&&"\n"===e.getTextContent()){const t=c(),n=g(),r=e.isBackward()?"previous":"next";return e.insertNodes([t,n]),N(j(w(k(t,"next",0),A(h(n,"next"))),r)),!0}for(let i=0;i<r;i++){const r=n[i];if(r.length>0){let n=r[0];if(0===i&&(n=it(n)),t===T){const t=c();if(n.insertBefore(t),0===i){const r=e.isBackward()?"focus":"anchor",i=v(n.getKey(),0,"text");e[r].is(i)&&e[r].set(t.getKey(),0,"text")}}else u(n)&&n.remove()}}return!0}function At(t,e){const n=_();if(!S(n))return!1;const{anchor:r,focus:i}=n,o=r.offset,s=i.offset,l=r.getNode(),c=i.getNode(),g=t===P;if(!jt(n)||!nt(l)&&!u(l)||!nt(c)&&!u(c))return!1;if(!e.altKey){if(n.isCollapsed()){const t=l.getParentOrThrow();if(g&&0===o&&null===l.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!0}else if(!g&&o===l.getTextContentSize()&&null===l.getNextSibling()){if(null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!0}}return!1}let a,p;if(l.isBefore(c)?(a=it(l),p=ot(c)):(a=it(c),p=ot(l)),null==a||null==p)return!1;const f=a.getNodesBetween(p);for(let t=0;t<f.length;t++){const e=f[t];if(!nt(e)&&!u(e)&&!d(e))return!1}e.preventDefault(),e.stopPropagation();const h=g?a.getPreviousSibling():p.getNextSibling();if(!d(h))return!0;const m=g?h.getPreviousSibling():h.getNextSibling();if(null==m)return!0;const y=nt(m)||u(m)||d(m)?g?it(m):ot(m):null;let x=null!=y?y:m;return h.remove(),f.forEach(t=>t.remove()),t===P?(f.forEach(t=>x.insertBefore(t)),x.insertBefore(h)):(x.insertAfter(h),x=h,f.forEach(t=>{x.insertAfter(t),x=t})),n.setTextNodeRange(l,o,c,s),!0}function Pt(t,e){const n=_();if(!S(n))return!1;const{anchor:r,focus:i}=n,o=r.getNode(),s=i.getNode(),l=t===L;if(!jt(n)||!nt(o)&&!u(o)||!nt(s)&&!u(s))return!1;if(l){const t=st(s,i.offset);if(null!==t){const{node:e,offset:r}=t;d(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r)}else s.getParentOrThrow().selectStart()}else{lt(s).select()}return e.preventDefault(),e.stopPropagation(),!0}function Lt(t,e){if(!t.hasNodes([$,Z]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");null==e&&(e=St);const n=[];return!0!==t._headless&&n.push(t.registerMutationListener($,e=>{t.getEditorState().read(()=>{for(const[n,r]of e)if("destroyed"!==r){const e=x(n);null!==e&&Tt(e,t)}})},{skipInitialization:!1})),n.push(t.registerNodeTransform($,n=>Ct(n,t,e)),t.registerNodeTransform(p,n=>vt(n,t,e)),t.registerNodeTransform(Z,n=>vt(n,t,e)),t.registerCommand(O,e=>{const n=function(t){const e=_();if(!S(e)||!jt(e))return null;const n=t?b:T,r=t?b:C,i=e.anchor,o=e.focus;if(i.is(o))return r;const s=wt(e);if(1!==s.length)return n;const l=s[0];let u,c;0===l.length&&D(285),e.isBackward()?(u=o,c=i):(u=i,c=o);const g=it(l[0]),a=ot(l[0]),p=v(g.getKey(),0,"text"),f=v(a.getKey(),a.getTextContentSize(),"text");return u.isBefore(p)||f.isBefore(c)?n:p.isBefore(u)||c.isBefore(f)?r:n}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n,void 0),!0)},H),t.registerCommand(C,()=>!!jt(_())&&(E([c()]),!0),H),t.registerCommand(T,t=>kt(T),H),t.registerCommand(b,t=>kt(b),H),t.registerCommand(P,t=>{const e=_();if(!S(e))return!1;const{anchor:n}=e,r=n.getNode();return!!jt(e)&&(e.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&q(r.getParentOrThrow())?(t.preventDefault(),!0):At(P,t))},H),t.registerCommand(z,t=>{const e=_();if(!S(e))return!1;const{anchor:n}=e,r=n.getNode();return!!jt(e)&&(e.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&q(r.getParentOrThrow())?(t.preventDefault(),!0):At(z,t))},H),t.registerCommand(L,t=>Pt(L,t),H),t.registerCommand(B,t=>Pt(B,t),H)),i(...n)}const Ot=it,Ht=ot,Et=lt,zt=st;export{et as $createCodeHighlightNode,W as $createCodeNode,lt as $getEndOfCodeInLine,it as $getFirstCodeNodeOfLine,ot as $getLastCodeNodeOfLine,st as $getStartOfCodeInLine,nt as $isCodeHighlightNode,q as $isCodeNode,gt as CODE_LANGUAGE_FRIENDLY_NAME_MAP,at as CODE_LANGUAGE_MAP,ut as CodeExtension,Z as CodeHighlightNode,$ as CodeNode,F as DEFAULT_CODE_LANGUAGE,St as PrismTokenizer,dt as getCodeLanguageOptions,ht as getCodeLanguages,mt as getCodeThemeOptions,I as getDefaultCodeLanguage,Et as getEndOfCodeInLine,Ot as getFirstCodeNodeOfLine,ft as getLanguageFriendlyName,Ht as getLastCodeNodeOfLine,zt as getStartOfCodeInLine,pt as normalizeCodeLang,pt as normalizeCodeLanguage,Lt as registerCodeHighlighting};
9
+ import{isHTMLElement as t,addClassNamesToElement as e,removeClassNamesFromElement as n,$getAdjacentCaret as r,mergeRegister as i}from"@lexical/utils";import{ElementNode as o,$createParagraphNode as s,$isTextNode as l,$isTabNode as u,$createTabNode as c,$createLineBreakNode as g,$create as a,TextNode as f,$applyNodeReplacement as p,$getSiblingCaret as h,getTextDirection as d,$isElementNode as m,$isLineBreakNode as y,defineExtension as x,$createTextNode as _,$getNodeByKey as S,$getSelection as v,$isRangeSelection as T,$createPoint as b,INDENT_CONTENT_COMMAND as C,OUTDENT_CONTENT_COMMAND as N,INSERT_TAB_COMMAND as j,$setSelectionFromCaretRange as w,$getCaretRangeInDirection as k,$getCaretRange as A,$getTextPointCaret as P,$normalizeCaret as L,KEY_ARROW_UP_COMMAND as O,MOVE_TO_START as H,KEY_TAB_COMMAND as E,COMMAND_PRIORITY_LOW as z,$insertNodes as B,KEY_ARROW_DOWN_COMMAND as D,MOVE_TO_END as F}from"lexical";import"prismjs";import"prismjs/components/prism-clike.js";import"prismjs/components/prism-javascript.js";import"prismjs/components/prism-markup.js";import"prismjs/components/prism-markdown.js";import"prismjs/components/prism-c.js";import"prismjs/components/prism-css.js";import"prismjs/components/prism-objectivec.js";import"prismjs/components/prism-sql.js";import"prismjs/components/prism-powershell.js";import"prismjs/components/prism-python.js";import"prismjs/components/prism-rust.js";import"prismjs/components/prism-swift.js";import"prismjs/components/prism-typescript.js";import"prismjs/components/prism-java.js";import"prismjs/components/prism-cpp.js";function I(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.`)}const M="javascript",J=()=>M;function R(e,n){for(const r of e.childNodes){if(t(r)&&r.tagName===n)return!0;R(r,n)}return!1}const K="data-language",$="data-highlight-language",W="data-theme";class q extends o{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(t){return new q(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 n=document.createElement("code");e(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(K,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute($,r));const i=this.getTheme();i&&n.setAttribute(W,i);const o=this.getStyle();return o&&n.setAttribute("style",o),n}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($,r):e.removeAttribute($):o&&r&&e.setAttribute($,r);const s=this.__theme,l=t.__theme;s?s!==l&&e.setAttribute(W,s):l&&e.removeAttribute(W);const u=this.__style,c=t.__style;return u?u!==c&&e.setAttribute("style",u):c&&e.removeAttribute("style"),!1}exportDOM(t){const n=document.createElement("pre");e(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(K,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute($,r));const i=this.getTheme();i&&n.setAttribute(W,i);const o=this.getStyle();return o&&n.setAttribute("style",o),{element:n}}static importDOM(){return{code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||R(t,"BR"))?{conversion:Q,priority:1}:null,div:()=>({conversion:G,priority:1}),pre:()=>({conversion:Q,priority:0}),table:t=>tt(t)?{conversion:V,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&tt(n)?{conversion:Y,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&tt(e)?{conversion:Y,priority:3}:null}}}static importJSON(t){return U().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 n=this.getChildren(),r=n.length;if(r>=2&&"\n"===n[r-1].getTextContent()&&"\n"===n[r-2].getTextContent()&&t.isCollapsed()&&t.anchor.key===this.__key&&t.anchor.offset===r){n[r-1].remove(),n[r-2].remove();const t=s();return this.insertAfter(t,e),t}const{anchor:i,focus:o}=t,a=(i.isBefore(o)?i:o).getNode();if(l(a)){let t=st(a);const e=[];for(;;)if(u(t))e.push(c()),t=t.getNextSibling();else{if(!it(t))break;{let n=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&e.push(rt(" ".repeat(n))),n!==i)break;t=t.getNextSibling()}}const n=a.splitText(i.offset)[0],r=0===i.offset?0:1,o=n.getIndexWithinParent()+r,s=a.getParentOrThrow(),l=[g(),...e];s.splice(o,0,l);const f=e[e.length-1];f?f.select():0===i.offset?n.selectPrevious():n.getNextSibling().selectNext(0,0)}if(X(a)){const{offset:e}=t.anchor;a.splice(e,0,[g()]),a.select(e+1,e+1)}return null}canIndent(){return!1}collapseAtStart(){const t=s();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 U(t,e){return a(q).setLanguage(t).setTheme(e)}function X(t){return t instanceof q}function Q(t){return{node:U(t.getAttribute(K))}}function G(t){const e=t,n=Z(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(Z(e))return!0;e=e.parentElement}return!1}(e)?{node:n?U():null}:{node:null}}function V(){return{node:U()}}function Y(){return{node:null}}function Z(t){return null!==t.style.fontFamily.match("monospace")}function tt(t){return t.classList.contains("js-file-line-container")}class et extends f{__highlightType;constructor(t="",e,n){super(t,n),this.__highlightType=e}static getType(){return"code-highlight"}static clone(t){return new et(t.__text,t.__highlightType||void 0,t.__key)}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(t){const e=this.getWritable();return e.__highlightType=t||void 0,e}canHaveFormat(){return!1}createDOM(t){const n=super.createDOM(t),r=nt(t.theme,this.__highlightType);return e(n,r),n}updateDOM(t,r,i){const o=super.updateDOM(t,r,i),s=nt(i.theme,t.__highlightType),l=nt(i.theme,this.__highlightType);return s!==l&&(s&&n(r,s),l&&e(r,l)),o}static importJSON(t){return rt().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 U()}}function nt(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function rt(t="",e){return p(new et(t,e))}function it(t){return t instanceof et}function ot(t,e){let n=t;for(let i=h(t,e);i&&(it(i.origin)||u(i.origin));i=r(i))n=i.origin;return n}function st(t){return ot(t,"previous")}function lt(t){return ot(t,"next")}function ut(t){const e=st(t),n=lt(t);let r=e;for(;null!==r;){if(it(r)){const t=d(r.getTextContent());if(null!==t)return t}if(r===n)break;r=r.getNextSibling()}const i=e.getParent();if(m(i)){const t=i.getDirection();if("ltr"===t||"rtl"===t)return t}return null}function ct(t,e){let n=null,r=null,i=t,o=e,s=t.getTextContent();for(;;){if(0===o){if(i=i.getPreviousSibling(),null===i)break;if(it(i)||u(i)||y(i)||I(167),y(i)){n={node:i,offset:1};break}o=Math.max(0,i.getTextContentSize()-1),s=i.getTextContent()}else o--;const t=s[o];it(i)&&" "!==t&&(r={node:i,offset:o})}if(null!==r)return r;let l=null;if(e<t.getTextContentSize())it(t)&&(l=t.getTextContent()[e]);else{const e=t.getNextSibling();it(e)&&(l=e.getTextContent()[0])}if(null!==l&&" "!==l)return n;{const r=function(t,e){let n=t,r=e,i=t.getTextContent(),o=t.getTextContentSize();for(;;){if(!it(n)||r===o){if(n=n.getNextSibling(),null===n||y(n))return null;it(n)&&(r=0,i=n.getTextContent(),o=n.getTextContentSize())}if(it(n)){if(" "!==i[r])return{node:n,offset:r};r++}}}(t,e);return null!==r?r:n}}function gt(t){const e=lt(t);return y(e)&&I(168),e}const at=x({name:"@lexical/code",nodes:[q,et]});!function(t){t.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var e={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(e).forEach(function(n){var r=e[n],i=[];/^\w+$/.test(n)||i.push(/\w+/.exec(n)[0]),"diff"===n&&i.push("bold"),t.languages.diff[n]={pattern:RegExp("^(?:["+r+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}}),Object.defineProperty(t.languages.diff,"PREFIXES",{value:e})}(Prism);const ft=globalThis.Prism||window.Prism,pt={c:"C",clike:"C-like",cpp:"C++",css:"CSS",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},ht={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function dt(t){return ht[t]||t}function mt(t){const e=dt(t);return pt[e]||e}const yt=()=>Object.keys(ft.languages).filter(t=>"function"!=typeof ft.languages[t]).sort();function xt(){const t=[];for(const[e,n]of Object.entries(pt))t.push([e,n]);return t}function _t(){return[]}function St(t){return"string"==typeof t?t:Array.isArray(t)?t.map(St).join(""):St(t.content)}function vt(t,e){const n=/^diff-([\w-]+)/i.exec(e),r=t.getTextContent();let i=ft.tokenize(r,ft.languages[n?"diff":e]);return n&&(i=function(t,e){const n=e,r=ft.languages[n],i={tokens:t},o=ft.languages.diff.PREFIXES;for(const t of i.tokens){if("string"==typeof t||!(t.type in o)||!Array.isArray(t.content))continue;const e=t.type;let n=0;const i=()=>(n++,new ft.Token("prefix",o[e],e.replace(/^(\w+).*/,"$1"))),s=t.content.filter(t=>"string"==typeof t||"prefix"!==t.type),l=t.content.length-s.length,u=ft.tokenize(St(s),r);u.unshift(i());const c=/\r\n|\n/g,g=t=>{const e=[];c.lastIndex=0;let r,o=0;for(;n<l&&(r=c.exec(t));){const n=r.index+r[0].length;e.push(t.slice(o,n)),o=n,e.push(i())}if(0!==e.length)return o<t.length&&e.push(t.slice(o)),e},a=t=>{for(let e=0;e<t.length&&n<l;e++){const n=t[e];if("string"==typeof n){const r=g(n);r&&(t.splice(e,1,...r),e+=r.length-1)}else if("string"==typeof n.content){const t=g(n.content);t&&(n.content=t)}else Array.isArray(n.content)?a(n.content):a([n.content])}};a(u),n<l&&u.push(i()),t.content=u}return i.tokens}(i,n[1])),Tt(i)}function Tt(t,e){const n=[];for(const r of t)if("string"==typeof r){const t=r.split(/(\n|\t)/),i=t.length;for(let r=0;r<i;r++){const i=t[r];"\n"===i||"\r\n"===i?n.push(g()):"\t"===i?n.push(c()):i.length>0&&n.push(rt(i,e))}}else{const{content:t,alias:e}=r;"string"==typeof t?n.push(...Tt([t],"prefix"===r.type&&"string"==typeof e?e:r.type)):Array.isArray(t)&&n.push(...Tt(t,"unchanged"===r.type?void 0:r.type))}return n}const bt={$tokenize(t,e){return vt(t,e||this.defaultLanguage)},defaultLanguage:M,tokenize(t,e){return ft.tokenize(t,ft.languages[e||""]||ft.languages[this.defaultLanguage])}};function Ct(t,e,n){const r=t.getParent();X(r)?wt(r,e,n):it(t)&&t.replace(_(t.__text))}function Nt(t,e){const n=e.getElementByKey(t.getKey());if(null===n)return;const r=t.getChildren(),i=r.length;if(i===n.__cachedChildrenLength)return;n.__cachedChildrenLength=i;let o="1",s=1;for(let t=0;t<i;t++)y(r[t])&&(o+="\n"+ ++s);n.setAttribute("data-gutter",o)}const jt=new Set;function wt(t,e,n){const r=t.getKey();void 0===t.getLanguage()&&t.setLanguage(n.defaultLanguage);const i=t.getLanguage()||n.defaultLanguage;if(!function(t){const e=function(t){const e=/^diff-([\w-]+)/i.exec(t);return e?e[1]:null}(t),n=e||t;try{return!!n&&ft.languages.hasOwnProperty(n)}catch(t){return!1}}(i))return t.getIsSyntaxHighlightSupported()&&t.setIsSyntaxHighlightSupported(!1),void async function(){}();t.getIsSyntaxHighlightSupported()||t.setIsSyntaxHighlightSupported(!0),jt.has(r)||(jt.add(r),e.update(()=>{!function(t,e){const n=S(t);if(!X(n)||!n.isAttached())return;const r=v();if(!T(r))return void e();const i=r.anchor,o=i.offset,s="element"===i.type&&y(n.getChildAtIndex(i.offset-1));let u=0;if(!s){const t=i.getNode();u=o+t.getPreviousSiblings().reduce((t,e)=>t+e.getTextContentSize(),0)}if(!e())return;if(s)return void i.getNode().select(o,o);n.getChildren().some(t=>{const e=l(t);if(e||y(t)){const n=t.getTextContentSize();if(e&&n>=u)return t.select(u,u),!0;u-=n}return!1})}(r,()=>{const e=S(r);if(!X(e)||!e.isAttached())return!1;const i=e.getLanguage()||n.defaultLanguage,o=n.$tokenize(e,i),s=function(t,e){let n=0;for(;n<t.length&&kt(t[n],e[n]);)n++;const r=t.length,i=e.length,o=Math.min(r,i)-n;let s=0;for(;s<o;)if(s++,!kt(t[r-s],e[i-s])){s--;break}const l=n,u=r-s,c=e.slice(n,i-s);return{from:l,nodesForReplacement:c,to:u}}(e.getChildren(),o),{from:l,to:u,nodesForReplacement:c}=s;return!(l===u&&!c.length)&&(t.splice(l,u-l,c),!0)})},{onUpdate:()=>{jt.delete(r)},skipTransforms:!0}))}function kt(t,e){return it(t)&&it(e)&&t.__text===e.__text&&t.__highlightType===e.__highlightType||u(t)&&u(e)||y(t)&&y(e)}function At(t){if(!T(t))return!1;const e=t.anchor.getNode(),n=X(e)?e:e.getParent(),r=t.focus.getNode(),i=X(r)?r:r.getParent();return X(n)&&n.is(i)}function Pt(t){const e=t.getNodes(),n=[];if(1===e.length&&X(e[0]))return n;let r=[];for(let t=0;t<e.length;t++){const i=e[t];it(i)||u(i)||y(i)||I(169),y(i)?r.length>0&&(n.push(r),r=[]):r.push(i)}if(r.length>0){const e=t.isBackward()?t.anchor:t.focus,i=b(r[0].getKey(),0,"text");e.is(i)||n.push(r)}return n}function Lt(t){const e=v();if(!T(e)||!At(e))return!1;const n=Pt(e),r=n.length;if(0===r&&e.isCollapsed())return t===C&&e.insertNodes([c()]),!0;if(0===r&&t===C&&"\n"===e.getTextContent()){const t=c(),n=g(),r=e.isBackward()?"previous":"next";return e.insertNodes([t,n]),w(k(A(P(t,"next",0),L(h(n,"next"))),r)),!0}for(let i=0;i<r;i++){const r=n[i];if(r.length>0){let n=r[0];if(0===i&&(n=st(n)),t===C){const t=c();if(n.insertBefore(t),0===i){const r=e.isBackward()?"focus":"anchor",i=b(n.getKey(),0,"text");e[r].is(i)&&e[r].set(t.getKey(),0,"text")}}else u(n)&&n.remove()}}return!0}function Ot(t,e){const n=v();if(!T(n))return!1;const{anchor:r,focus:i}=n,o=r.offset,s=i.offset,l=r.getNode(),c=i.getNode(),g=t===O;if(!At(n)||!it(l)&&!u(l)||!it(c)&&!u(c))return!1;if(!e.altKey){if(n.isCollapsed()){const t=l.getParentOrThrow();if(g&&0===o&&null===l.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!0}else if(!g&&o===l.getTextContentSize()&&null===l.getNextSibling()){if(null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!0}}return!1}let a,f;if(l.isBefore(c)?(a=st(l),f=lt(c)):(a=st(c),f=lt(l)),null==a||null==f)return!1;const p=a.getNodesBetween(f);for(let t=0;t<p.length;t++){const e=p[t];if(!it(e)&&!u(e)&&!y(e))return!1}e.preventDefault(),e.stopPropagation();const h=g?a.getPreviousSibling():f.getNextSibling();if(!y(h))return!0;const d=g?h.getPreviousSibling():h.getNextSibling();if(null==d)return!0;const m=it(d)||u(d)||y(d)?g?st(d):lt(d):null;let x=null!=m?m:d;return h.remove(),p.forEach(t=>t.remove()),t===O?(p.forEach(t=>x.insertBefore(t)),x.insertBefore(h)):(x.insertAfter(h),x=h,p.forEach(t=>{x.insertAfter(t),x=t})),n.setTextNodeRange(l,o,c,s),!0}function Ht(t,e){const n=v();if(!T(n))return!1;const{anchor:r,focus:i}=n,o=r.getNode(),s=i.getNode(),l=t===H;if(!At(n)||!it(o)&&!u(o)||!it(s)&&!u(s))return!1;const c=s;if("rtl"===ut(c)?!l:l){const t=ct(c,i.offset);if(null!==t){const{node:e,offset:r}=t;y(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r)}else c.getParentOrThrow().selectStart()}else{gt(c).select()}return e.preventDefault(),e.stopPropagation(),!0}function Et(t,e){if(!t.hasNodes([q,et]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");null==e&&(e=bt);const n=[];return!0!==t._headless&&n.push(t.registerMutationListener(q,e=>{t.getEditorState().read(()=>{for(const[n,r]of e)if("destroyed"!==r){const e=S(n);null!==e&&Nt(e,t)}})},{skipInitialization:!1})),n.push(t.registerNodeTransform(q,n=>wt(n,t,e)),t.registerNodeTransform(f,n=>Ct(n,t,e)),t.registerNodeTransform(et,n=>Ct(n,t,e)),t.registerCommand(E,e=>{const n=function(t){const e=v();if(!T(e)||!At(e))return null;const n=t?N:C,r=t?N:j,i=e.anchor,o=e.focus;if(i.is(o))return r;const s=Pt(e);if(1!==s.length)return n;const l=s[0];let u,c;0===l.length&&I(285),e.isBackward()?(u=o,c=i):(u=i,c=o);const g=st(l[0]),a=lt(l[0]),f=b(g.getKey(),0,"text"),p=b(a.getKey(),a.getTextContentSize(),"text");return u.isBefore(f)||p.isBefore(c)?n:f.isBefore(u)||c.isBefore(p)?r:n}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n,void 0),!0)},z),t.registerCommand(j,()=>!!At(v())&&(B([c()]),!0),z),t.registerCommand(C,t=>Lt(C),z),t.registerCommand(N,t=>Lt(N),z),t.registerCommand(O,t=>{const e=v();if(!T(e))return!1;const{anchor:n}=e,r=n.getNode();return!!At(e)&&(e.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&X(r.getParentOrThrow())?(t.preventDefault(),!0):Ot(O,t))},z),t.registerCommand(D,t=>{const e=v();if(!T(e))return!1;const{anchor:n}=e,r=n.getNode();return!!At(e)&&(e.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&X(r.getParentOrThrow())?(t.preventDefault(),!0):Ot(D,t))},z),t.registerCommand(H,t=>Ht(H,t),z),t.registerCommand(F,t=>Ht(F,t),z)),i(...n)}const zt=st,Bt=lt,Dt=gt,Ft=ct;export{rt as $createCodeHighlightNode,U as $createCodeNode,ut as $getCodeLineDirection,gt as $getEndOfCodeInLine,st as $getFirstCodeNodeOfLine,lt as $getLastCodeNodeOfLine,ct as $getStartOfCodeInLine,it as $isCodeHighlightNode,X as $isCodeNode,pt as CODE_LANGUAGE_FRIENDLY_NAME_MAP,ht as CODE_LANGUAGE_MAP,at as CodeExtension,et as CodeHighlightNode,q as CodeNode,M as DEFAULT_CODE_LANGUAGE,bt as PrismTokenizer,xt as getCodeLanguageOptions,yt as getCodeLanguages,_t as getCodeThemeOptions,J as getDefaultCodeLanguage,Dt as getEndOfCodeInLine,zt as getFirstCodeNodeOfLine,mt as getLanguageFriendlyName,Bt as getLastCodeNodeOfLine,Ft as getStartOfCodeInLine,dt as normalizeCodeLang,dt as normalizeCodeLanguage,Et as registerCodeHighlighting};
package/index.d.ts CHANGED
@@ -12,7 +12,7 @@ export { $createCodeHighlightNode, $isCodeHighlightNode, CodeHighlightNode, } fr
12
12
  export type { SerializedCodeNode } from './CodeNode';
13
13
  export { $createCodeNode, $isCodeNode, CodeNode, DEFAULT_CODE_LANGUAGE, getDefaultCodeLanguage, } from './CodeNode';
14
14
  export { CODE_LANGUAGE_FRIENDLY_NAME_MAP, CODE_LANGUAGE_MAP, getCodeLanguageOptions, getCodeLanguages, getCodeThemeOptions, getLanguageFriendlyName, normalizeCodeLang, normalizeCodeLang as normalizeCodeLanguage, } from './FacadePrism';
15
- export { $getEndOfCodeInLine, $getFirstCodeNodeOfLine, $getLastCodeNodeOfLine, $getStartOfCodeInLine, } from './FlatStructureUtils';
15
+ export { $getCodeLineDirection, $getEndOfCodeInLine, $getFirstCodeNodeOfLine, $getLastCodeNodeOfLine, $getStartOfCodeInLine, } from './FlatStructureUtils';
16
16
  /** @deprecated renamed to {@link $getFirstCodeNodeOfLine} by @lexical/eslint-plugin rules-of-lexical */
17
17
  export declare const getFirstCodeNodeOfLine: typeof $getFirstCodeNodeOfLine;
18
18
  /** @deprecated renamed to {@link $getLastCodeNodeOfLine} by @lexical/eslint-plugin rules-of-lexical */
package/package.json CHANGED
@@ -8,12 +8,12 @@
8
8
  "code"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.37.1-nightly.20251015.0",
11
+ "version": "0.37.1-nightly.20251017.0",
12
12
  "main": "LexicalCode.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/utils": "0.37.1-nightly.20251015.0",
16
- "lexical": "0.37.1-nightly.20251015.0",
15
+ "@lexical/utils": "0.37.1-nightly.20251017.0",
16
+ "lexical": "0.37.1-nightly.20251017.0",
17
17
  "prismjs": "^1.30.0"
18
18
  },
19
19
  "repository": {