@lexical/code-core 0.52.1-nightly.20260930.0 → 0.52.1-nightly.20261002.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.
@@ -6,8 +6,8 @@
6
6
  *
7
7
  */
8
8
 
9
- import { sel, ImportOverlays, defineOverlayRules, CoreImportExtension, DOMImportExtension } from '@lexical/html';
10
- import { getTextDirection, $isElementNode, $isTabNode, $isLineBreakNode, tokenizeRawText, $createTabNode, $createLineBreakNode, $getSiblingCaret, getterTableOf, setterTableOf, setterDefaultOf, aliasTableOf, $create, ElementNode, $getDocument, addClassNamesToElement, setDOMStyleFromCSS, $getEditor, $isTextNode, $createParagraphNode, nodeSchema, withAccessors, optional, stringValue, nullable, isHTMLElement, $applyNodeReplacement, TextNode, removeClassNamesFromElement, isDOMDocumentNode, isDOMTextNode, $generateNodesFromRawText, mergeRegister, KEY_ENTER_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW, TabNode, $getNodeByKey, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_TAB_COMMAND, INSERT_TAB_COMMAND, $insertNodes, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, MOVE_TO_START, MOVE_TO_END, $createPoint, $setSelectionFromCaretRange, $getCaretRangeInDirection, $getCaretRange, $getTextPointCaret, $normalizeCaret } from 'lexical';
9
+ import { sel, ImportOverlays, $isBlockLevel, defineOverlayRules, CoreImportExtension, DOMImportExtension } from '@lexical/html';
10
+ import { getTextDirection, $isElementNode, $isTabNode, $isLineBreakNode, tokenizeRawText, $createTabNode, $createLineBreakNode, $getSiblingCaret, getterTableOf, setterTableOf, setterDefaultOf, aliasTableOf, $create, ElementNode, $getDocument, addClassNamesToElement, setDOMStyleFromCSS, $getEditor, $isTextNode, $createParagraphNode, nodeSchema, withAccessors, optional, stringValue, nullable, isHTMLElement, $applyNodeReplacement, TextNode, removeClassNamesFromElement, isDOMDocumentNode, isDOMTextNode, mergeRegister, KEY_ENTER_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW, TabNode, $getNodeByKey, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_TAB_COMMAND, INSERT_TAB_COMMAND, $insertNodes, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, MOVE_TO_START, MOVE_TO_END, $createPoint, $setSelectionFromCaretRange, $getCaretRangeInDirection, $getCaretRange, $getTextPointCaret, $normalizeCaret } from 'lexical';
11
11
  import { getPeerDependencyFromEditor } from '@lexical/extension/getPeerDependencyFromEditor';
12
12
  import { effect } from '@lexical/extension/signals';
13
13
  import { namedSignals } from '@lexical/extension/namedSignals';
@@ -995,6 +995,27 @@ function $isCodeHighlightNode(node) {
995
995
  const LANGUAGE_DATA_ATTRIBUTE = 'data-language';
996
996
  const THEME_DATA_ATTRIBUTE = 'data-theme';
997
997
 
998
+ /**
999
+ * Code editing expects flat CodeHighlightNode, TabNode and LineBreakNode
1000
+ * children. Preserve imported nodes' plain-text representations, separating
1001
+ * block siblings by a line break, then normalize with the code tokenizer.
1002
+ * Nested containers keep their own plain-text separators.
1003
+ */
1004
+ function $normalizeCodeChildren(children) {
1005
+ const text = [];
1006
+ let previousWasBlock = false;
1007
+ for (let i = 0; i < children.length; i++) {
1008
+ const child = children[i];
1009
+ const isBlock = $isBlockLevel(child);
1010
+ if (i > 0 && (isBlock || previousWasBlock)) {
1011
+ text.push('\n');
1012
+ }
1013
+ text.push(child.getTextContent());
1014
+ previousWasBlock = isBlock;
1015
+ }
1016
+ return $plainifyCodeContent(text.join(''));
1017
+ }
1018
+
998
1019
  /**
999
1020
  * True for elements whose `font-family` mentions `monospace` — the
1000
1021
  * heuristic the legacy `<div>` rule uses to spot copy-pasted code blocks
@@ -1029,7 +1050,7 @@ const GitHubCodeTableOverlayRules = /* @__PURE__ */defineOverlayRules([{
1029
1050
  name: '@lexical/code/github-code-table/unwrap'
1030
1051
  }]);
1031
1052
  const PreRule = {
1032
- $import: (ctx, el) => [$createCodeNode(el.getAttribute(LANGUAGE_DATA_ATTRIBUTE), el.getAttribute(THEME_DATA_ATTRIBUTE)).splice(0, 0, ctx.$importChildren(el))],
1053
+ $import: (ctx, el) => [$createCodeNode(el.getAttribute(LANGUAGE_DATA_ATTRIBUTE), el.getAttribute(THEME_DATA_ATTRIBUTE)).splice(0, 0, $normalizeCodeChildren(ctx.$importChildren(el)))],
1033
1054
  match: /* @__PURE__ */sel.tag('pre'),
1034
1055
  name: '@lexical/code/pre'
1035
1056
  };
@@ -1047,7 +1068,7 @@ const MultilineCodeRule = {
1047
1068
  if (!isMultiLine) {
1048
1069
  return $next();
1049
1070
  }
1050
- return [$createCodeNode(el.getAttribute(LANGUAGE_DATA_ATTRIBUTE), el.getAttribute(THEME_DATA_ATTRIBUTE)).splice(0, 0, ctx.$importChildren(el))];
1071
+ return [$createCodeNode(el.getAttribute(LANGUAGE_DATA_ATTRIBUTE), el.getAttribute(THEME_DATA_ATTRIBUTE)).splice(0, 0, $normalizeCodeChildren(ctx.$importChildren(el)))];
1051
1072
  },
1052
1073
  match: /* @__PURE__ */sel.tag('code'),
1053
1074
  name: '@lexical/code/code-multiline'
@@ -1164,7 +1185,7 @@ const VscodeWrapperRule = {
1164
1185
  if (lines === null || lines.length === 0) {
1165
1186
  return $next();
1166
1187
  }
1167
- return [$createCodeNode().splice(0, 0, $generateNodesFromRawText(lines.join('\n')))];
1188
+ return [$createCodeNode().splice(0, 0, $plainifyCodeContent(lines.join('\n')))];
1168
1189
  },
1169
1190
  match: /* @__PURE__ */sel.tag('div'),
1170
1191
  name: '@lexical/code/vscode-wrapper'
@@ -1196,7 +1217,7 @@ const VscodeLineRunRule = {
1196
1217
  if (lines.length < 2) {
1197
1218
  return $next();
1198
1219
  }
1199
- return [$createCodeNode().splice(0, 0, $generateNodesFromRawText(lines.join('\n')))];
1220
+ return [$createCodeNode().splice(0, 0, $plainifyCodeContent(lines.join('\n')))];
1200
1221
  },
1201
1222
  match: /* @__PURE__ */sel.tag('div', 'br'),
1202
1223
  name: '@lexical/code/vscode-line-run'
@@ -1235,18 +1256,13 @@ const $installVscodeCodePasteOverlay = (dom, ctx, $next) => {
1235
1256
 
1236
1257
  /**
1237
1258
  * A `<div style="font-family: …monospace…">` (Google-Docs-style code
1238
- * block) creates a CodeNode. Descendant elements inside a monospace
1239
- * wrapper just unwrap so their text content flows into the surrounding
1240
- * CodeNode.
1259
+ * block) creates a CodeNode. Plain descendant divs defer to the transparent
1260
+ * block rule so their boundaries become separate lines in that CodeNode.
1241
1261
  */
1242
1262
  const DivRule = {
1243
1263
  $import: (ctx, el, $next) => {
1244
1264
  if (isMonospaceElement(el)) {
1245
- return [$createCodeNode().splice(0, 0, ctx.$importChildren(el))];
1246
- }
1247
- if (isMonospaceDescendant(el)) {
1248
- // Unwrap so children flow into the enclosing CodeNode.
1249
- return ctx.$importChildren(el);
1265
+ return [$createCodeNode().splice(0, 0, $normalizeCodeChildren(ctx.$importChildren(el)))];
1250
1266
  }
1251
1267
  return $next();
1252
1268
  },
@@ -1262,9 +1278,9 @@ const DivRule = {
1262
1278
  * on every other `<tr>` / `<td>` paste elsewhere.
1263
1279
  */
1264
1280
  const GitHubCodeTableRule = {
1265
- $import: (ctx, el) => [$createCodeNode().splice(0, 0, ctx.$importChildren(el, {
1281
+ $import: (ctx, el) => [$createCodeNode().splice(0, 0, $normalizeCodeChildren(ctx.$importChildren(el, {
1266
1282
  rules: GitHubCodeTableOverlayRules
1267
- }))],
1283
+ })))],
1268
1284
  match: /* @__PURE__ */sel.tag('table').classAll('js-file-line-container'),
1269
1285
  name: '@lexical/code/github-code-table'
1270
1286
  };
@@ -6,5 +6,5 @@
6
6
  *
7
7
  */
8
8
 
9
- import{sel as t,ImportOverlays as e,defineOverlayRules as n,CoreImportExtension as r,DOMImportExtension as i}from"@lexical/html";import{getTextDirection as o,$isElementNode as s,$isTabNode as l,$isLineBreakNode as c,tokenizeRawText as u,$createTabNode as a,$createLineBreakNode as g,$getSiblingCaret as f,getterTableOf as h,setterTableOf as d,setterDefaultOf as p,aliasTableOf as m,$create as _,ElementNode as x,$getDocument as y,addClassNamesToElement as S,setDOMStyleFromCSS as b,$getEditor as v,$isTextNode as C,$createParagraphNode as T,nodeSchema as N,withAccessors as A,optional as P,stringValue as w,nullable as F,isHTMLElement as O,$applyNodeReplacement as $,TextNode as D,removeClassNamesFromElement as E,isDOMDocumentNode as L,isDOMTextNode as B,$generateNodesFromRawText as H,mergeRegister as k,KEY_ENTER_COMMAND as z,$getSelection as M,$isRangeSelection as K,COMMAND_PRIORITY_LOW as I,TabNode as j,$getNodeByKey as R,KEY_ARROW_DOWN_COMMAND as W,KEY_ARROW_RIGHT_COMMAND as J,KEY_ARROW_UP_COMMAND as q,KEY_ARROW_LEFT_COMMAND as U,KEY_TAB_COMMAND as V,INSERT_TAB_COMMAND as G,$insertNodes as Q,INDENT_CONTENT_COMMAND as X,OUTDENT_CONTENT_COMMAND as Y,MOVE_TO_START as Z,MOVE_TO_END as tt,$createPoint as et,$setSelectionFromCaretRange as nt,$getCaretRangeInDirection as rt,$getCaretRange as it,$getTextPointCaret as ot,$normalizeCaret as st}from"lexical";import{getPeerDependencyFromEditor as lt}from"@lexical/extension/getPeerDependencyFromEditor";import{effect as ct}from"@lexical/extension/signals";import{namedSignals as ut}from"@lexical/extension/namedSignals";import{$onEscapeDown as at,$onEscapeUp as gt}from"@lexical/utils";
10
- /*@__INLINE__*/function ft(t){return()=>{}}function ht(t,...e){throw function(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);return n.search=r.toString(),new 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.`)}(t,...e)}function dt(t,e){let n=t;for(let r=f(t,e);r&&(Gt(r.origin)||l(r.origin));r=r.getAdjacentCaret())n=r.origin;return n}function pt(t){return dt(t,"previous")}function mt(t){return dt(t,"next")}function _t(t){const e=pt(t),n=mt(t);let r=e;for(;null!==r;){if(Gt(r)){const t=o(r.getTextContent());if(null!==t)return t}if(r===n)break;r=r.getNextSibling()}const i=e.getParent();if(s(i)){const t=i.getDirection();if("ltr"===t||"rtl"===t)return t}return null}function xt(t,e){let n=null,r=null,i=t,o=e,s=t.getTextContent();for(;;){if(0===o){const t=i.getPreviousSibling();if(null===t){i=null;break}if(Gt(t)||l(t)||c(t)||ht(167),i=t,c(i)){n={node:i,offset:1};break}o=Math.max(0,i.getTextContentSize()-1),s=i.getTextContent()}else o--;const t=s[o];Gt(i)&&" "!==t&&(r={node:i,offset:o})}if(null!==r)return r;let u=null;if(e<t.getTextContentSize())Gt(t)&&(u=t.getTextContent()[e]);else{const e=t.getNextSibling();Gt(e)&&(u=e.getTextContent()[0])}if(null!==u&&" "!==u)return n;{const r=function(t,e){let n=t,r=e,i=t.getTextContent(),o=t.getTextContentSize();for(;;){if(!Gt(n)||r===o){if(n=n.getNextSibling(),null===n||c(n))return null;Gt(n)&&(r=0,i=n.getTextContent(),o=n.getTextContentSize())}if(Gt(n)){if(" "!==i[r])return{node:n,offset:r};r++}}}(t,e);return null!==r?r:n}}function yt(t){const e=mt(t);return c(e)&&ht(168),e}function St(t){const e=[];return u(t,{linebreak:()=>e.push(g()),tab:()=>e.push(a()),text:t=>e.push(Vt(t))}),e}function bt(t,e,n){if(!Number.isInteger(e)||e<=0)return!1;const r=t.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(e,i[0].length),s=t.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,c=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return t.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==c&&n.focus.set(s,Math.max(0,c-o),"text"),!0}const vt=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;function Ct(t,e){if("number"==typeof t)return Number.isFinite(t)?t:e;if("string"!=typeof t||!vt.test(t))return e;const n=Number(t);return Number.isFinite(n)?n:e}const Tt=t=>{const e=h(t,"format"),n=d(t,"format"),r=p(t,"format");return{exportJSON:function(t){const n=t.__textFormat,r=t.__textStyle,i=(0!==n||""!==r)&&t.shouldSerializeTextStyles();return{children:[],language:t.__language,theme:t.__theme,direction:t.__dir,format:e[t.__format],indent:t.__indent,textFormat:0!==n&&i?n:void 0,textStyle:""!==r&&i?r:void 0,type:t.__type,version:1}},exportCompactJSON:function(t){const n=t.__textFormat,r=t.__textStyle,i=(0!==n||""!==r)&&t.shouldSerializeTextStyles(),o={type:t.__type,children:[]},s=t.__language;void 0!==s&&(o.language=s);const l=t.__theme;void 0!==l&&(o.theme=l);const c=t.__dir;null!=c&&(o.direction=c);const u=e[t.__format];void 0!==u&&""!==u&&(o.format=u);const a=t.__indent;return void 0!==a&&0!==a&&(o.indent=a),void 0!==n&&0!==n&&i&&(o.textFormat=n),void 0!==r&&""!==r&&i&&(o.textStyle=r),o},updateFromJSON:function(t,e){const i=e.direction;t.__dir=null===i||"ltr"===i||"rtl"===i?i:null;const o=e.format;t.__format="string"==typeof o&&o in n?n[o]:r,t.__indent=function(t){const e=Ct(t,0);return e>=0&&e<=Infinity&&Number.isInteger(e)?e:0}(e.indent),t.__textFormat=Ct(e.textFormat,0);const s=e.textStyle;t.__textStyle="string"==typeof s?s:"";const l=e.language;t.setLanguage(null==l||"string"==typeof l?l:"");const c=e.theme;return t.setTheme(void 0===c?void 0:"string"==typeof c?c:""),t}}};function Nt(t,e){t.__highlightType=e.__highlightType}const At=t=>{const e=h(t,"mode"),n=m(t,"detail",0),r=m(t,"format",0),i=d(t,"mode"),o=p(t,"mode");return{exportJSON:function(t){return{highlightType:t.__highlightType,detail:t.__detail,format:t.__format,mode:e[t.__mode],style:t.__style,text:t.__text,type:t.__type,version:1}},exportCompactJSON:function(t){const n={type:t.__type},r=t.__highlightType;void 0!==r&&(n.highlightType=r);const i=t.__detail;void 0!==i&&0!==i&&(n.detail=i);const o=t.__format;void 0!==o&&0!==o&&(n.format=o);const s=e[t.__mode];void 0!==s&&"normal"!==s&&(n.mode=s);const l=t.__style;void 0!==l&&""!==l&&(n.style=l);const c=t.__text;return void 0!==c&&""!==c&&(n.text=c),n},updateFromJSON:function(t,e){const s=e.detail;t.__detail="string"==typeof s&&s in n?n[s]:Ct(s,0);const l=e.format;t.setFormat("string"==typeof l&&l in r?r[l]:Ct(l,0));const c=e.mode;t.__mode="string"==typeof c&&c in i?i[c]:o;const u=e.style;t.__style="string"==typeof u?u:"";const a=e.text;t.__text="string"==typeof a?a:"";const g=e.highlightType;return t.setHighlightType(null==g||"string"==typeof g?g:""),t},afterCloneFrom:Nt}},Pt=/* @__PURE__ */N()({language:/* @__PURE__ */A(/* @__PURE__ */P(/* @__PURE__ */F(/* @__PURE__ */w())),{getter:{field:"__language"}}),theme:/* @__PURE__ */A(/* @__PURE__ */P(/* @__PURE__ */w()),{getter:{field:"__theme"}})}),wt="javascript",Ft=()=>wt;function Ot(t,e){for(const n of t.childNodes){if(O(n)&&n.tagName===e)return!0;if(Ot(n,e))return!0}return!1}const $t="data-language",Dt="data-highlight-language",Et="data-theme",Lt=/* @__PURE__ */ft();class Bt extends x{__language;__theme;__isSyntaxHighlightSupported;$config(){return this.config("code",{extends:x,generated:Tt,importDOM:{code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||Ot(t,"BR"))?{conversion:zt,priority:1}:null,div:()=>({conversion:Mt,priority:1}),pre:()=>({conversion:zt,priority:0}),table:t=>Rt(t)?{conversion:Kt,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&Rt(n)?{conversion:It,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&Rt(e)?{conversion:It,priority:3}:null}},json:Pt})}constructor(t=void 0,e){super(e),this.__language=t||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(t){super.afterCloneFrom(t),function(t,e){t.__language=e.__language,t.__theme=e.__theme}(this,t),this.__isSyntaxHighlightSupported=t.__isSyntaxHighlightSupported}createDOM(t){const e=y().createElement("code");S(e,t.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute($t,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(Dt,n));const r=this.getTheme();r&&e.setAttribute(Et,r);const i=this.getStyle();return i&&b(e.style,i),e}updateDOM(t,e,n){const r=this.__language,i=t.__language;r?r!==i&&e.setAttribute($t,r):i&&e.removeAttribute($t);const o=this.__isSyntaxHighlightSupported;t.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&e.setAttribute(Dt,r):e.removeAttribute(Dt):o&&r&&e.setAttribute(Dt,r);const s=this.__theme,l=t.__theme;s?s!==l&&e.setAttribute(Et,s):l&&e.removeAttribute(Et);const c=this.__style,u=t.__style;return c!==u&&b(e.style,c,u),!1}exportDOM(t){const e=y().createElement("pre");S(e,t._config.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute($t,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(Dt,n));const r=this.getTheme();r&&e.setAttribute(Et,r);const i=this.getStyle();return i&&b(e.style,i),{element:e}}insertNewAfter(t,e=!0){if(!lt(v(),"@lexical/code")){Lt();const e=Wt(t);if(e)return e}const{anchor:n,focus:r}=t,i=(n.isBefore(r)?n:r).getNode();if(C(i)){let t=pt(i);const e=[];for(;;)if(l(t))e.push(a()),t=t.getNextSibling();else{if(!Gt(t))break;{let n=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&e.push(Vt(" ".repeat(n))),n!==i)break;t=t.getNextSibling()}}const r=i.splitText(n.offset)[0],o=0===n.offset?0:1,s=r.getIndexWithinParent()+o,c=i.getParentOrThrow(),u=[g(),...e];c.splice(s,0,u);const f=e[e.length-1];f?f.select():0===n.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(kt(i)){const{offset:e}=t.anchor;i.splice(e,0,[g()]),i.select(e+1,e+1)}return null}canIndent(){return!1}collapseAtStart(){const t=T();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 Ht(t,e){return _(Bt).setLanguage(t).setTheme(e)}function kt(t){return t instanceof Bt}function zt(t){return{node:Ht(t.getAttribute($t),t.getAttribute(Et))}}function Mt(t){const e=t,n=jt(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(jt(e))return!0;e=e.parentElement}return!1}(e)?{node:n?Ht():null}:{node:null}}function Kt(){return{node:Ht()}}function It(){return{node:null}}function jt(t){return null!==t.style.fontFamily.match("monospace")}function Rt(t){return t.classList.contains("js-file-line-container")}function Wt(t){const{anchor:e}=t;if(t.isCollapsed()&&"element"===e.type){const t=e.getNode();if(kt(t)){const n=t.getChildrenSize();if(n>=2&&e.offset===n){const e=t.getLastChild();if(c(e)&&c(e.getPreviousSibling())){const e=T();return t.splice(n-2,2,[]).insertAfter(e,!1),e.select(),e}}}}return null}const Jt=/* @__PURE__ */N()({highlightType:/* @__PURE__ */A(/* @__PURE__ */P(/* @__PURE__ */F(/* @__PURE__ */w())),{getter:{field:"__highlightType"}})});class qt extends D{__highlightType;constructor(t="",e,n){super(t,n),this.__highlightType=e}$config(){return this.config("code-highlight",{extends:D,generated:At,json:Jt})}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=Ut(t.theme,this.__highlightType);return S(e,n),e}updateDOM(t,e,n){const r=super.updateDOM(t,e,n),i=Ut(n.theme,t.__highlightType),o=Ut(n.theme,this.__highlightType);return i!==o&&(i&&E(e,i),o&&S(e,o)),r}setFormat(t){return this}isParentRequired(){return!0}createParentElementNode(){return Ht()}}function Ut(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function Vt(t="",e){return $(new qt(t,e))}function Gt(t){return t instanceof qt}const Qt="data-language",Xt="data-theme";function Yt(t){return null!==t.style.fontFamily.match("monospace")}function Zt(t){let e=t.parentElement;for(;null!==e;){if(Yt(e))return!0;e=e.parentElement}return!1}const te=/* @__PURE__ */n([{$import:(t,e)=>t.$importChildren(e),match:/* @__PURE__ */t.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"}]),ee={$import:(t,e)=>[Ht(e.getAttribute(Qt),e.getAttribute(Xt)).splice(0,0,t.$importChildren(e))],match:/* @__PURE__ */t.tag("pre"),name:"@lexical/code/pre"},ne={$import:(t,e,n)=>{const r=e.textContent||"";return/\r?\n/.test(r)||null!==e.querySelector("br")?[Ht(e.getAttribute(Qt),e.getAttribute(Xt)).splice(0,0,t.$importChildren(e))]:n()},match:/* @__PURE__ */t.tag("code"),name:"@lexical/code/code-multiline"};function re(t){if(!O(t))return!1;const e=t.style.fontFamily,n=t.style.whiteSpace;return"string"==typeof e&&/monospace/i.test(e)&&"string"==typeof n&&n.startsWith("pre")}function ie(t){let e=!1;const n=[];let r="",i=!1;const o=()=>{i&&(n.push(r),r="",i=!1)};for(const s of Array.from(t.childNodes))if(O(s))"DIV"===s.tagName?(o(),n.push(s.textContent||""),e=!0):"BR"===s.tagName?(o(),n.push(""),e=!0):(r+=s.textContent||"",i=!0);else if(B(s)){const t=s.textContent||"";t.length>0&&(r+=t,i=!0)}return o(),e?n:null}function oe(t){for(const e of Array.from(t.children)){if(O(e)&&re(e)){if(null!==ie(e))return!0;const t=e.nextElementSibling;if(t&&re(t))return!0;continue}if(oe(e))return!0}return!1}const se=/* @__PURE__ */n([{$import:(t,e,n)=>{if(!re(e)||Zt(e))return n();const r=ie(e);return null===r||0===r.length?n():[Ht().splice(0,0,H(r.join("\n")))]},match:/* @__PURE__ */t.tag("div"),name:"@lexical/code/vscode-wrapper"},{$import:(t,e,n)=>{if(!re(e)||Zt(e))return n();const r=e.previousElementSibling;if(r&&re(r))return[];const i=[];let o=e;for(;o&&re(o);)i.push("BR"===o.tagName?"":o.textContent||""),o=o.nextElementSibling;return i.length<2?n():[Ht().splice(0,0,H(i.join("\n")))]},match:/* @__PURE__ */t.tag("div","br"),name:"@lexical/code/vscode-line-run"}]),le={$import:(t,e,n)=>Yt(e)?[Ht().splice(0,0,t.$importChildren(e))]:Zt(e)?t.$importChildren(e):n(),match:/* @__PURE__ */t.tag("div"),name:"@lexical/code/div"},ce=[{$import:(t,e)=>[Ht().splice(0,0,t.$importChildren(e,{rules:te}))],match:/* @__PURE__ */t.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"},{$import:(t,e)=>t.$importChildren(e),match:/* @__PURE__ */t.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"},ne,ee,le],ue={dependencies:[r,[i,{preprocess:[(t,n,r)=>{oe(L(t)?t.body:t)&&n.session.update(e,t=>[...t,se]),r()}],rules:ce}]],name:"@lexical/code",nodes:()=>[Bt,qt],register:t=>k(t.registerCommand(z,t=>{const e=M();return!(!K(e)||!Wt(e)||(null!==t&&t.preventDefault(),0))},I),t.registerNodeTransform(j,t=>{0!==t.getFormat()&&kt(t.getParent())&&t.setFormat(0)}))},ae={dependencies:[ue],name:"@lexical/code/Import"};function ge(t){const e=v().getElementByKey(t.getKey());if(null===e)return;const n=t.getChildren(),r=n.length;if(r===e.__cachedChildrenLength)return;e.__cachedChildrenLength=r;let i="1",o=1;for(let t=0;t<r;t++)c(n[t])&&(i+="\n"+ ++o);e.setAttribute("data-gutter",i)}function fe(t){return t._headless?()=>{}:t.registerMutationListener(Bt,e=>{t.read("latest",()=>{for(const[t,n]of e)if("destroyed"!==n){const e=R(t);null!==e&&ge(e)}})},{skipInitialization:!1})}function he(t){if(!K(t))return!1;const e=t.anchor.getNode(),n=kt(e)?e:e.getParent(),r=t.focus.getNode(),i=kt(r)?r:r.getParent();return kt(n)&&n.is(i)}function de(t){const e=t.getNodes(),n=[];if(1===e.length&&kt(e[0]))return n;let r=[];for(let t=0;t<e.length;t++){const i=e[t];Gt(i)||l(i)||c(i)||ht(169),c(i)?r.length>0&&(n.push(r),r=[]):r.push(i)}if(r.length>0){const e=t.isBackward()?t.anchor:t.focus,i=et(r[0].getKey(),0,"text");e.is(i)||n.push(r)}return n}function pe(t,e){const n=M();if(!K(n)||!he(n))return!1;const r=de(n),i=r.length;if(0===i&&n.isCollapsed())return t===X?n.insertNodes([a()]):function(t,e){const n=t.anchor.getNode();if(!Gt(n)&&!l(n))return;const r=pt(n);l(r)?r.remove():void 0!==e&&Gt(r)&&bt(r,e,t)}(n,e),!0;if(0===i&&t===X&&"\n"===n.getTextContent()){const t=a(),e=g(),r=n.isBackward()?"previous":"next";return n.insertNodes([t,e]),nt(rt(it(ot(t,"next",0),st(f(e,"next"))),r)),!0}for(let o=0;o<i;o++){const i=r[o];if(i.length>0){let r=i[0];if(0===o&&(r=pt(r)),t===X){const t=a();if(r.insertBefore(t),0===o){const e=n.isBackward()?"focus":"anchor",i=et(r.getKey(),0,"text");n[e].is(i)&&n[e].set(t.getKey(),0,"text")}}else l(r)?r.remove():void 0!==e&&Gt(r)&&bt(r,e,n)}}return!0}function me(t,e){const n=M();if(!K(n))return!1;const{anchor:r,focus:i}=n,o=r.offset,s=i.offset,u=r.getNode(),a=i.getNode(),g=t===q;if(!he(n)||!Gt(u)&&!l(u)||!Gt(a)&&!l(a))return!1;if(!e.altKey){if(n.isCollapsed()){const t=u.getParentOrThrow();if(g&&0===o&&null===u.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!1}else if(!g&&o===u.getTextContentSize()&&null===u.getNextSibling()&&null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!1}return!1}let f,h;if(u.isBefore(a)?(f=pt(u),h=mt(a)):(f=pt(a),h=mt(u)),null==f||null==h)return!1;const d=f.getNodesBetween(h);for(let t=0;t<d.length;t++){const e=d[t];if(!Gt(e)&&!l(e)&&!c(e))return!1}e.preventDefault(),e.stopPropagation();const p=g?f.getPreviousSibling():h.getNextSibling();if(!c(p))return!0;const m=g?p.getPreviousSibling():p.getNextSibling();if(null==m)return!0;const _=c(m),x=_||!Gt(m)&&!l(m)?null:g?pt(m):mt(m);let y=null!=x?x:m;return p.remove(),d.forEach(t=>t.remove()),_?(d.forEach(t=>{y.insertAfter(t),y=t}),y.insertAfter(p)):t===q?(d.forEach(t=>y.insertBefore(t)),y.insertBefore(p)):(y.insertAfter(p),y=p,d.forEach(t=>{y.insertAfter(t),y=t})),n.setTextNodeRange(u,o,a,s),!0}function _e(t,e){const n=M();if(!K(n))return!1;const{anchor:r,focus:i}=n,o=r.getNode(),s=i.getNode(),u=t===Z;if(!he(n)||!Gt(o)&&!l(o)||!Gt(s)&&!l(s))return!1;const a=s,g="rtl"===_t(a)?!u:u,f=r.key,h=r.offset,d=r.type;if(g){const t=xt(a,i.offset);if(null!==t){const{node:e,offset:r}=t;c(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r)}else a.getParentOrThrow().selectStart()}else yt(a).select();return e.shiftKey&&n.anchor.set(f,h,d),e.preventDefault(),e.stopPropagation(),!0}function xe(t,e,n){return k(...n?[t.registerCommand(W,t=>!t.altKey&&at(kt,t),I),t.registerCommand(J,t=>at(kt,t),I),t.registerCommand(q,t=>!t.altKey&&gt(kt,t),I),t.registerCommand(U,t=>gt(kt,t),I)]:[],t.registerCommand(V,e=>{const n=function(t){const e=M();if(!K(e)||!he(e))return null;const n=t?Y:X,r=t?Y:G,i=e.anchor,o=e.focus;if(i.is(o))return r;const s=de(e);if(1!==s.length)return n;const l=s[0];let c,u;0===l.length&&ht(285),e.isBackward()?(c=o,u=i):(c=i,u=o);const a=pt(l[0]),g=mt(l[0]),f=et(a.getKey(),0,"text"),h=et(g.getKey(),g.getTextContentSize(),"text");return c.isBefore(f)||h.isBefore(u)?n:f.isBefore(c)||u.isBefore(h)?r:n}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n),!0)},I),t.registerCommand(G,()=>!!he(M())&&(Q([a()]),!0),I),t.registerCommand(X,()=>pe(X),I),t.registerCommand(Y,()=>pe(Y,e),I),t.registerCommand(q,t=>{const e=M();if(!K(e))return!1;const{anchor:n}=e,r=n.getNode();if(!he(e))return!1;const i=r.getParent();return e.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&kt(i)&&null===i.getPreviousSibling()?(t.preventDefault(),!0):me(q,t)},I),t.registerCommand(W,t=>{const e=M();if(!K(e))return!1;const{anchor:n}=e,r=n.getNode();return!!he(e)&&(e.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&kt(r.getParentOrThrow())&&null===r.getParentOrThrow().getNextSibling()?(t.preventDefault(),!0):me(W,t))},I),t.registerCommand(Z,t=>_e(Z,t),I),t.registerCommand(tt,t=>_e(tt,t),I))}const ye={build:(t,e)=>ut(e),config:{disabled:!1,escapeWithArrows:!1,tabSize:void 0},dependencies:[ue],name:"@lexical/code-indent",register:(t,e,n)=>{const r=n.getOutput();return ct(()=>{if(!r.disabled.value)return xe(t,r.tabSize.value,r.escapeWithArrows.value)})}};export{Vt as $createCodeHighlightNode,Ht as $createCodeNode,_t as $getCodeLineDirection,yt as $getEndOfCodeInLine,pt as $getFirstCodeNodeOfLine,mt as $getLastCodeNodeOfLine,xt as $getStartOfCodeInLine,Gt as $isCodeHighlightNode,kt as $isCodeNode,bt as $outdentLeadingSpaces,St as $plainifyCodeContent,ue as CodeExtension,qt as CodeHighlightNode,ae as CodeImportExtension,ce as CodeImportRules,ye as CodeIndentExtension,Bt as CodeNode,wt as DEFAULT_CODE_LANGUAGE,Ft as getDefaultCodeLanguage,fe as registerCodeGutter,xe as registerCodeIndentation};
9
+ import{sel as t,ImportOverlays as e,$isBlockLevel as n,defineOverlayRules as r,CoreImportExtension as i,DOMImportExtension as o}from"@lexical/html";import{getTextDirection as s,$isElementNode as l,$isTabNode as u,$isLineBreakNode as c,tokenizeRawText as a,$createTabNode as g,$createLineBreakNode as f,$getSiblingCaret as h,getterTableOf as d,setterTableOf as p,setterDefaultOf as m,aliasTableOf as _,$create as x,ElementNode as y,$getDocument as S,addClassNamesToElement as b,setDOMStyleFromCSS as v,$getEditor as C,$isTextNode as T,$createParagraphNode as N,nodeSchema as A,withAccessors as P,optional as w,stringValue as F,nullable as O,isHTMLElement as D,$applyNodeReplacement as E,TextNode as L,removeClassNamesFromElement as $,isDOMDocumentNode as B,isDOMTextNode as H,mergeRegister as k,KEY_ENTER_COMMAND as z,$getSelection as M,$isRangeSelection as K,COMMAND_PRIORITY_LOW as I,TabNode as j,$getNodeByKey as R,KEY_ARROW_DOWN_COMMAND as W,KEY_ARROW_RIGHT_COMMAND as J,KEY_ARROW_UP_COMMAND as q,KEY_ARROW_LEFT_COMMAND as U,KEY_TAB_COMMAND as V,INSERT_TAB_COMMAND as G,$insertNodes as Q,INDENT_CONTENT_COMMAND as X,OUTDENT_CONTENT_COMMAND as Y,MOVE_TO_START as Z,MOVE_TO_END as tt,$createPoint as et,$setSelectionFromCaretRange as nt,$getCaretRangeInDirection as rt,$getCaretRange as it,$getTextPointCaret as ot,$normalizeCaret as st}from"lexical";import{getPeerDependencyFromEditor as lt}from"@lexical/extension/getPeerDependencyFromEditor";import{effect as ut}from"@lexical/extension/signals";import{namedSignals as ct}from"@lexical/extension/namedSignals";import{$onEscapeDown as at,$onEscapeUp as gt}from"@lexical/utils";
10
+ /*@__INLINE__*/function ft(t){return()=>{}}function ht(t,...e){throw function(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);return n.search=r.toString(),new 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.`)}(t,...e)}function dt(t,e){let n=t;for(let r=h(t,e);r&&(Gt(r.origin)||u(r.origin));r=r.getAdjacentCaret())n=r.origin;return n}function pt(t){return dt(t,"previous")}function mt(t){return dt(t,"next")}function _t(t){const e=pt(t),n=mt(t);let r=e;for(;null!==r;){if(Gt(r)){const t=s(r.getTextContent());if(null!==t)return t}if(r===n)break;r=r.getNextSibling()}const i=e.getParent();if(l(i)){const t=i.getDirection();if("ltr"===t||"rtl"===t)return t}return null}function xt(t,e){let n=null,r=null,i=t,o=e,s=t.getTextContent();for(;;){if(0===o){const t=i.getPreviousSibling();if(null===t){i=null;break}if(Gt(t)||u(t)||c(t)||ht(167),i=t,c(i)){n={node:i,offset:1};break}o=Math.max(0,i.getTextContentSize()-1),s=i.getTextContent()}else o--;const t=s[o];Gt(i)&&" "!==t&&(r={node:i,offset:o})}if(null!==r)return r;let l=null;if(e<t.getTextContentSize())Gt(t)&&(l=t.getTextContent()[e]);else{const e=t.getNextSibling();Gt(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(!Gt(n)||r===o){if(n=n.getNextSibling(),null===n||c(n))return null;Gt(n)&&(r=0,i=n.getTextContent(),o=n.getTextContentSize())}if(Gt(n)){if(" "!==i[r])return{node:n,offset:r};r++}}}(t,e);return null!==r?r:n}}function yt(t){const e=mt(t);return c(e)&&ht(168),e}function St(t){const e=[];return a(t,{linebreak:()=>e.push(f()),tab:()=>e.push(g()),text:t=>e.push(Vt(t))}),e}function bt(t,e,n){if(!Number.isInteger(e)||e<=0)return!1;const r=t.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(e,i[0].length),s=t.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,u=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return t.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==u&&n.focus.set(s,Math.max(0,u-o),"text"),!0}const vt=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;function Ct(t,e){if("number"==typeof t)return Number.isFinite(t)?t:e;if("string"!=typeof t||!vt.test(t))return e;const n=Number(t);return Number.isFinite(n)?n:e}const Tt=t=>{const e=d(t,"format"),n=p(t,"format"),r=m(t,"format");return{exportJSON:function(t){const n=t.__textFormat,r=t.__textStyle,i=(0!==n||""!==r)&&t.shouldSerializeTextStyles();return{children:[],language:t.__language,theme:t.__theme,direction:t.__dir,format:e[t.__format],indent:t.__indent,textFormat:0!==n&&i?n:void 0,textStyle:""!==r&&i?r:void 0,type:t.__type,version:1}},exportCompactJSON:function(t){const n=t.__textFormat,r=t.__textStyle,i=(0!==n||""!==r)&&t.shouldSerializeTextStyles(),o={type:t.__type,children:[]},s=t.__language;void 0!==s&&(o.language=s);const l=t.__theme;void 0!==l&&(o.theme=l);const u=t.__dir;null!=u&&(o.direction=u);const c=e[t.__format];void 0!==c&&""!==c&&(o.format=c);const a=t.__indent;return void 0!==a&&0!==a&&(o.indent=a),void 0!==n&&0!==n&&i&&(o.textFormat=n),void 0!==r&&""!==r&&i&&(o.textStyle=r),o},updateFromJSON:function(t,e){const i=e.direction;t.__dir=null===i||"ltr"===i||"rtl"===i?i:null;const o=e.format;t.__format="string"==typeof o&&o in n?n[o]:r,t.__indent=function(t){const e=Ct(t,0);return e>=0&&e<=Infinity&&Number.isInteger(e)?e:0}(e.indent),t.__textFormat=Ct(e.textFormat,0);const s=e.textStyle;t.__textStyle="string"==typeof s?s:"";const l=e.language;t.setLanguage(null==l||"string"==typeof l?l:"");const u=e.theme;return t.setTheme(void 0===u?void 0:"string"==typeof u?u:""),t}}};function Nt(t,e){t.__highlightType=e.__highlightType}const At=t=>{const e=d(t,"mode"),n=_(t,"detail",0),r=_(t,"format",0),i=p(t,"mode"),o=m(t,"mode");return{exportJSON:function(t){return{highlightType:t.__highlightType,detail:t.__detail,format:t.__format,mode:e[t.__mode],style:t.__style,text:t.__text,type:t.__type,version:1}},exportCompactJSON:function(t){const n={type:t.__type},r=t.__highlightType;void 0!==r&&(n.highlightType=r);const i=t.__detail;void 0!==i&&0!==i&&(n.detail=i);const o=t.__format;void 0!==o&&0!==o&&(n.format=o);const s=e[t.__mode];void 0!==s&&"normal"!==s&&(n.mode=s);const l=t.__style;void 0!==l&&""!==l&&(n.style=l);const u=t.__text;return void 0!==u&&""!==u&&(n.text=u),n},updateFromJSON:function(t,e){const s=e.detail;t.__detail="string"==typeof s&&s in n?n[s]:Ct(s,0);const l=e.format;t.setFormat("string"==typeof l&&l in r?r[l]:Ct(l,0));const u=e.mode;t.__mode="string"==typeof u&&u in i?i[u]:o;const c=e.style;t.__style="string"==typeof c?c:"";const a=e.text;t.__text="string"==typeof a?a:"";const g=e.highlightType;return t.setHighlightType(null==g||"string"==typeof g?g:""),t},afterCloneFrom:Nt}},Pt=/* @__PURE__ */A()({language:/* @__PURE__ */P(/* @__PURE__ */w(/* @__PURE__ */O(/* @__PURE__ */F())),{getter:{field:"__language"}}),theme:/* @__PURE__ */P(/* @__PURE__ */w(/* @__PURE__ */F()),{getter:{field:"__theme"}})}),wt="javascript",Ft=()=>wt;function Ot(t,e){for(const n of t.childNodes){if(D(n)&&n.tagName===e)return!0;if(Ot(n,e))return!0}return!1}const Dt="data-language",Et="data-highlight-language",Lt="data-theme",$t=/* @__PURE__ */ft();class Bt extends y{__language;__theme;__isSyntaxHighlightSupported;$config(){return this.config("code",{extends:y,generated:Tt,importDOM:{code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||Ot(t,"BR"))?{conversion:zt,priority:1}:null,div:()=>({conversion:Mt,priority:1}),pre:()=>({conversion:zt,priority:0}),table:t=>Rt(t)?{conversion:Kt,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&Rt(n)?{conversion:It,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&Rt(e)?{conversion:It,priority:3}:null}},json:Pt})}constructor(t=void 0,e){super(e),this.__language=t||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(t){super.afterCloneFrom(t),function(t,e){t.__language=e.__language,t.__theme=e.__theme}(this,t),this.__isSyntaxHighlightSupported=t.__isSyntaxHighlightSupported}createDOM(t){const e=S().createElement("code");b(e,t.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute(Dt,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(Et,n));const r=this.getTheme();r&&e.setAttribute(Lt,r);const i=this.getStyle();return i&&v(e.style,i),e}updateDOM(t,e,n){const r=this.__language,i=t.__language;r?r!==i&&e.setAttribute(Dt,r):i&&e.removeAttribute(Dt);const o=this.__isSyntaxHighlightSupported;t.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&e.setAttribute(Et,r):e.removeAttribute(Et):o&&r&&e.setAttribute(Et,r);const s=this.__theme,l=t.__theme;s?s!==l&&e.setAttribute(Lt,s):l&&e.removeAttribute(Lt);const u=this.__style,c=t.__style;return u!==c&&v(e.style,u,c),!1}exportDOM(t){const e=S().createElement("pre");b(e,t._config.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute(Dt,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(Et,n));const r=this.getTheme();r&&e.setAttribute(Lt,r);const i=this.getStyle();return i&&v(e.style,i),{element:e}}insertNewAfter(t,e=!0){if(!lt(C(),"@lexical/code")){$t();const e=Wt(t);if(e)return e}const{anchor:n,focus:r}=t,i=(n.isBefore(r)?n:r).getNode();if(T(i)){let t=pt(i);const e=[];for(;;)if(u(t))e.push(g()),t=t.getNextSibling();else{if(!Gt(t))break;{let n=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&e.push(Vt(" ".repeat(n))),n!==i)break;t=t.getNextSibling()}}const r=i.splitText(n.offset)[0],o=0===n.offset?0:1,s=r.getIndexWithinParent()+o,l=i.getParentOrThrow(),c=[f(),...e];l.splice(s,0,c);const a=e[e.length-1];a?a.select():0===n.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(kt(i)){const{offset:e}=t.anchor;i.splice(e,0,[f()]),i.select(e+1,e+1)}return null}canIndent(){return!1}collapseAtStart(){const t=N();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 Ht(t,e){return x(Bt).setLanguage(t).setTheme(e)}function kt(t){return t instanceof Bt}function zt(t){return{node:Ht(t.getAttribute(Dt),t.getAttribute(Lt))}}function Mt(t){const e=t,n=jt(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(jt(e))return!0;e=e.parentElement}return!1}(e)?{node:n?Ht():null}:{node:null}}function Kt(){return{node:Ht()}}function It(){return{node:null}}function jt(t){return null!==t.style.fontFamily.match("monospace")}function Rt(t){return t.classList.contains("js-file-line-container")}function Wt(t){const{anchor:e}=t;if(t.isCollapsed()&&"element"===e.type){const t=e.getNode();if(kt(t)){const n=t.getChildrenSize();if(n>=2&&e.offset===n){const e=t.getLastChild();if(c(e)&&c(e.getPreviousSibling())){const e=N();return t.splice(n-2,2,[]).insertAfter(e,!1),e.select(),e}}}}return null}const Jt=/* @__PURE__ */A()({highlightType:/* @__PURE__ */P(/* @__PURE__ */w(/* @__PURE__ */O(/* @__PURE__ */F())),{getter:{field:"__highlightType"}})});class qt extends L{__highlightType;constructor(t="",e,n){super(t,n),this.__highlightType=e}$config(){return this.config("code-highlight",{extends:L,generated:At,json:Jt})}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=Ut(t.theme,this.__highlightType);return b(e,n),e}updateDOM(t,e,n){const r=super.updateDOM(t,e,n),i=Ut(n.theme,t.__highlightType),o=Ut(n.theme,this.__highlightType);return i!==o&&(i&&$(e,i),o&&b(e,o)),r}setFormat(t){return this}isParentRequired(){return!0}createParentElementNode(){return Ht()}}function Ut(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function Vt(t="",e){return E(new qt(t,e))}function Gt(t){return t instanceof qt}const Qt="data-language",Xt="data-theme";function Yt(t){const e=[];let r=!1;for(let i=0;i<t.length;i++){const o=t[i],s=n(o);i>0&&(s||r)&&e.push("\n"),e.push(o.getTextContent()),r=s}return St(e.join(""))}function Zt(t){return null!==t.style.fontFamily.match("monospace")}function te(t){let e=t.parentElement;for(;null!==e;){if(Zt(e))return!0;e=e.parentElement}return!1}const ee=/* @__PURE__ */r([{$import:(t,e)=>t.$importChildren(e),match:/* @__PURE__ */t.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"}]),ne={$import:(t,e)=>[Ht(e.getAttribute(Qt),e.getAttribute(Xt)).splice(0,0,Yt(t.$importChildren(e)))],match:/* @__PURE__ */t.tag("pre"),name:"@lexical/code/pre"},re={$import:(t,e,n)=>{const r=e.textContent||"";return/\r?\n/.test(r)||null!==e.querySelector("br")?[Ht(e.getAttribute(Qt),e.getAttribute(Xt)).splice(0,0,Yt(t.$importChildren(e)))]:n()},match:/* @__PURE__ */t.tag("code"),name:"@lexical/code/code-multiline"};function ie(t){if(!D(t))return!1;const e=t.style.fontFamily,n=t.style.whiteSpace;return"string"==typeof e&&/monospace/i.test(e)&&"string"==typeof n&&n.startsWith("pre")}function oe(t){let e=!1;const n=[];let r="",i=!1;const o=()=>{i&&(n.push(r),r="",i=!1)};for(const s of Array.from(t.childNodes))if(D(s))"DIV"===s.tagName?(o(),n.push(s.textContent||""),e=!0):"BR"===s.tagName?(o(),n.push(""),e=!0):(r+=s.textContent||"",i=!0);else if(H(s)){const t=s.textContent||"";t.length>0&&(r+=t,i=!0)}return o(),e?n:null}function se(t){for(const e of Array.from(t.children)){if(D(e)&&ie(e)){if(null!==oe(e))return!0;const t=e.nextElementSibling;if(t&&ie(t))return!0;continue}if(se(e))return!0}return!1}const le=/* @__PURE__ */r([{$import:(t,e,n)=>{if(!ie(e)||te(e))return n();const r=oe(e);return null===r||0===r.length?n():[Ht().splice(0,0,St(r.join("\n")))]},match:/* @__PURE__ */t.tag("div"),name:"@lexical/code/vscode-wrapper"},{$import:(t,e,n)=>{if(!ie(e)||te(e))return n();const r=e.previousElementSibling;if(r&&ie(r))return[];const i=[];let o=e;for(;o&&ie(o);)i.push("BR"===o.tagName?"":o.textContent||""),o=o.nextElementSibling;return i.length<2?n():[Ht().splice(0,0,St(i.join("\n")))]},match:/* @__PURE__ */t.tag("div","br"),name:"@lexical/code/vscode-line-run"}]),ue={$import:(t,e,n)=>Zt(e)?[Ht().splice(0,0,Yt(t.$importChildren(e)))]:n(),match:/* @__PURE__ */t.tag("div"),name:"@lexical/code/div"},ce=[{$import:(t,e)=>[Ht().splice(0,0,Yt(t.$importChildren(e,{rules:ee})))],match:/* @__PURE__ */t.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"},{$import:(t,e)=>t.$importChildren(e),match:/* @__PURE__ */t.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"},re,ne,ue],ae={dependencies:[i,[o,{preprocess:[(t,n,r)=>{se(B(t)?t.body:t)&&n.session.update(e,t=>[...t,le]),r()}],rules:ce}]],name:"@lexical/code",nodes:()=>[Bt,qt],register:t=>k(t.registerCommand(z,t=>{const e=M();return!(!K(e)||!Wt(e)||(null!==t&&t.preventDefault(),0))},I),t.registerNodeTransform(j,t=>{0!==t.getFormat()&&kt(t.getParent())&&t.setFormat(0)}))},ge={dependencies:[ae],name:"@lexical/code/Import"};function fe(t){const e=C().getElementByKey(t.getKey());if(null===e)return;const n=t.getChildren(),r=n.length;if(r===e.__cachedChildrenLength)return;e.__cachedChildrenLength=r;let i="1",o=1;for(let t=0;t<r;t++)c(n[t])&&(i+="\n"+ ++o);e.setAttribute("data-gutter",i)}function he(t){return t._headless?()=>{}:t.registerMutationListener(Bt,e=>{t.read("latest",()=>{for(const[t,n]of e)if("destroyed"!==n){const e=R(t);null!==e&&fe(e)}})},{skipInitialization:!1})}function de(t){if(!K(t))return!1;const e=t.anchor.getNode(),n=kt(e)?e:e.getParent(),r=t.focus.getNode(),i=kt(r)?r:r.getParent();return kt(n)&&n.is(i)}function pe(t){const e=t.getNodes(),n=[];if(1===e.length&&kt(e[0]))return n;let r=[];for(let t=0;t<e.length;t++){const i=e[t];Gt(i)||u(i)||c(i)||ht(169),c(i)?r.length>0&&(n.push(r),r=[]):r.push(i)}if(r.length>0){const e=t.isBackward()?t.anchor:t.focus,i=et(r[0].getKey(),0,"text");e.is(i)||n.push(r)}return n}function me(t,e){const n=M();if(!K(n)||!de(n))return!1;const r=pe(n),i=r.length;if(0===i&&n.isCollapsed())return t===X?n.insertNodes([g()]):function(t,e){const n=t.anchor.getNode();if(!Gt(n)&&!u(n))return;const r=pt(n);u(r)?r.remove():void 0!==e&&Gt(r)&&bt(r,e,t)}(n,e),!0;if(0===i&&t===X&&"\n"===n.getTextContent()){const t=g(),e=f(),r=n.isBackward()?"previous":"next";return n.insertNodes([t,e]),nt(rt(it(ot(t,"next",0),st(h(e,"next"))),r)),!0}for(let o=0;o<i;o++){const i=r[o];if(i.length>0){let r=i[0];if(0===o&&(r=pt(r)),t===X){const t=g();if(r.insertBefore(t),0===o){const e=n.isBackward()?"focus":"anchor",i=et(r.getKey(),0,"text");n[e].is(i)&&n[e].set(t.getKey(),0,"text")}}else u(r)?r.remove():void 0!==e&&Gt(r)&&bt(r,e,n)}}return!0}function _e(t,e){const n=M();if(!K(n))return!1;const{anchor:r,focus:i}=n,o=r.offset,s=i.offset,l=r.getNode(),a=i.getNode(),g=t===q;if(!de(n)||!Gt(l)&&!u(l)||!Gt(a)&&!u(a))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(),!1}else if(!g&&o===l.getTextContentSize()&&null===l.getNextSibling()&&null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!1}return!1}let f,h;if(l.isBefore(a)?(f=pt(l),h=mt(a)):(f=pt(a),h=mt(l)),null==f||null==h)return!1;const d=f.getNodesBetween(h);for(let t=0;t<d.length;t++){const e=d[t];if(!Gt(e)&&!u(e)&&!c(e))return!1}e.preventDefault(),e.stopPropagation();const p=g?f.getPreviousSibling():h.getNextSibling();if(!c(p))return!0;const m=g?p.getPreviousSibling():p.getNextSibling();if(null==m)return!0;const _=c(m),x=_||!Gt(m)&&!u(m)?null:g?pt(m):mt(m);let y=null!=x?x:m;return p.remove(),d.forEach(t=>t.remove()),_?(d.forEach(t=>{y.insertAfter(t),y=t}),y.insertAfter(p)):t===q?(d.forEach(t=>y.insertBefore(t)),y.insertBefore(p)):(y.insertAfter(p),y=p,d.forEach(t=>{y.insertAfter(t),y=t})),n.setTextNodeRange(l,o,a,s),!0}function xe(t,e){const n=M();if(!K(n))return!1;const{anchor:r,focus:i}=n,o=r.getNode(),s=i.getNode(),l=t===Z;if(!de(n)||!Gt(o)&&!u(o)||!Gt(s)&&!u(s))return!1;const a=s,g="rtl"===_t(a)?!l:l,f=r.key,h=r.offset,d=r.type;if(g){const t=xt(a,i.offset);if(null!==t){const{node:e,offset:r}=t;c(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r)}else a.getParentOrThrow().selectStart()}else yt(a).select();return e.shiftKey&&n.anchor.set(f,h,d),e.preventDefault(),e.stopPropagation(),!0}function ye(t,e,n){return k(...n?[t.registerCommand(W,t=>!t.altKey&&at(kt,t),I),t.registerCommand(J,t=>at(kt,t),I),t.registerCommand(q,t=>!t.altKey&&gt(kt,t),I),t.registerCommand(U,t=>gt(kt,t),I)]:[],t.registerCommand(V,e=>{const n=function(t){const e=M();if(!K(e)||!de(e))return null;const n=t?Y:X,r=t?Y:G,i=e.anchor,o=e.focus;if(i.is(o))return r;const s=pe(e);if(1!==s.length)return n;const l=s[0];let u,c;0===l.length&&ht(285),e.isBackward()?(u=o,c=i):(u=i,c=o);const a=pt(l[0]),g=mt(l[0]),f=et(a.getKey(),0,"text"),h=et(g.getKey(),g.getTextContentSize(),"text");return u.isBefore(f)||h.isBefore(c)?n:f.isBefore(u)||c.isBefore(h)?r:n}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n),!0)},I),t.registerCommand(G,()=>!!de(M())&&(Q([g()]),!0),I),t.registerCommand(X,()=>me(X),I),t.registerCommand(Y,()=>me(Y,e),I),t.registerCommand(q,t=>{const e=M();if(!K(e))return!1;const{anchor:n}=e,r=n.getNode();if(!de(e))return!1;const i=r.getParent();return e.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&kt(i)&&null===i.getPreviousSibling()?(t.preventDefault(),!0):_e(q,t)},I),t.registerCommand(W,t=>{const e=M();if(!K(e))return!1;const{anchor:n}=e,r=n.getNode();return!!de(e)&&(e.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&kt(r.getParentOrThrow())&&null===r.getParentOrThrow().getNextSibling()?(t.preventDefault(),!0):_e(W,t))},I),t.registerCommand(Z,t=>xe(Z,t),I),t.registerCommand(tt,t=>xe(tt,t),I))}const Se={build:(t,e)=>ct(e),config:{disabled:!1,escapeWithArrows:!1,tabSize:void 0},dependencies:[ae],name:"@lexical/code-indent",register:(t,e,n)=>{const r=n.getOutput();return ut(()=>{if(!r.disabled.value)return ye(t,r.tabSize.value,r.escapeWithArrows.value)})}};export{Vt as $createCodeHighlightNode,Ht as $createCodeNode,_t as $getCodeLineDirection,yt as $getEndOfCodeInLine,pt as $getFirstCodeNodeOfLine,mt as $getLastCodeNodeOfLine,xt as $getStartOfCodeInLine,Gt as $isCodeHighlightNode,kt as $isCodeNode,bt as $outdentLeadingSpaces,St as $plainifyCodeContent,ae as CodeExtension,qt as CodeHighlightNode,ge as CodeImportExtension,ce as CodeImportRules,Se as CodeIndentExtension,Bt as CodeNode,wt as DEFAULT_CODE_LANGUAGE,Ft as getDefaultCodeLanguage,he as registerCodeGutter,ye as registerCodeIndentation};
package/package.json CHANGED
@@ -8,15 +8,15 @@
8
8
  "code"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.52.1-nightly.20260930.0",
11
+ "version": "0.52.1-nightly.20261002.0",
12
12
  "main": "./dist/LexicalCodeCore.js",
13
13
  "types": "./dist/typescript-too-old.d.ts",
14
14
  "dependencies": {
15
- "@lexical/extension": "0.52.1-nightly.20260930.0",
16
- "@lexical/html": "0.52.1-nightly.20260930.0",
17
- "@lexical/internal": "0.52.1-nightly.20260930.0",
18
- "@lexical/utils": "0.52.1-nightly.20260930.0",
19
- "lexical": "0.52.1-nightly.20260930.0"
15
+ "@lexical/extension": "0.52.1-nightly.20261002.0",
16
+ "@lexical/html": "0.52.1-nightly.20261002.0",
17
+ "@lexical/internal": "0.52.1-nightly.20261002.0",
18
+ "@lexical/utils": "0.52.1-nightly.20261002.0",
19
+ "lexical": "0.52.1-nightly.20261002.0"
20
20
  },
21
21
  "repository": {
22
22
  "type": "git",
@@ -7,6 +7,7 @@
7
7
  */
8
8
 
9
9
  import {
10
+ $isBlockLevel,
10
11
  defineImportRule,
11
12
  defineOverlayRules,
12
13
  type DOMPreprocessFn,
@@ -14,17 +15,39 @@ import {
14
15
  sel,
15
16
  } from '@lexical/html';
16
17
  import {
17
- $generateNodesFromRawText,
18
18
  isDOMDocumentNode,
19
19
  isDOMTextNode,
20
20
  isHTMLElement,
21
+ type LexicalNode,
21
22
  } from 'lexical';
22
23
 
23
24
  import {$createCodeNode} from './CodeNode';
25
+ import {$plainifyCodeContent} from './FlatStructureUtils';
24
26
 
25
27
  const LANGUAGE_DATA_ATTRIBUTE = 'data-language';
26
28
  const THEME_DATA_ATTRIBUTE = 'data-theme';
27
29
 
30
+ /**
31
+ * Code editing expects flat CodeHighlightNode, TabNode and LineBreakNode
32
+ * children. Preserve imported nodes' plain-text representations, separating
33
+ * block siblings by a line break, then normalize with the code tokenizer.
34
+ * Nested containers keep their own plain-text separators.
35
+ */
36
+ function $normalizeCodeChildren(children: LexicalNode[]): LexicalNode[] {
37
+ const text: string[] = [];
38
+ let previousWasBlock = false;
39
+ for (let i = 0; i < children.length; i++) {
40
+ const child = children[i];
41
+ const isBlock = $isBlockLevel(child);
42
+ if (i > 0 && (isBlock || previousWasBlock)) {
43
+ text.push('\n');
44
+ }
45
+ text.push(child.getTextContent());
46
+ previousWasBlock = isBlock;
47
+ }
48
+ return $plainifyCodeContent(text.join(''));
49
+ }
50
+
28
51
  /**
29
52
  * True for elements whose `font-family` mentions `monospace` — the
30
53
  * heuristic the legacy `<div>` rule uses to spot copy-pasted code blocks
@@ -67,7 +90,7 @@ const PreRule = defineImportRule({
67
90
  $createCodeNode(
68
91
  el.getAttribute(LANGUAGE_DATA_ATTRIBUTE),
69
92
  el.getAttribute(THEME_DATA_ATTRIBUTE),
70
- ).splice(0, 0, ctx.$importChildren(el)),
93
+ ).splice(0, 0, $normalizeCodeChildren(ctx.$importChildren(el))),
71
94
  ],
72
95
  match: sel.tag('pre'),
73
96
  name: '@lexical/code/pre',
@@ -90,7 +113,7 @@ const MultilineCodeRule = defineImportRule({
90
113
  $createCodeNode(
91
114
  el.getAttribute(LANGUAGE_DATA_ATTRIBUTE),
92
115
  el.getAttribute(THEME_DATA_ATTRIBUTE),
93
- ).splice(0, 0, ctx.$importChildren(el)),
116
+ ).splice(0, 0, $normalizeCodeChildren(ctx.$importChildren(el))),
94
117
  ];
95
118
  },
96
119
  match: sel.tag('code'),
@@ -214,11 +237,7 @@ const VscodeWrapperRule = defineImportRule({
214
237
  return $next();
215
238
  }
216
239
  return [
217
- $createCodeNode().splice(
218
- 0,
219
- 0,
220
- $generateNodesFromRawText(lines.join('\n')),
221
- ),
240
+ $createCodeNode().splice(0, 0, $plainifyCodeContent(lines.join('\n'))),
222
241
  ];
223
242
  },
224
243
  match: sel.tag('div'),
@@ -252,11 +271,7 @@ const VscodeLineRunRule = defineImportRule({
252
271
  return $next();
253
272
  }
254
273
  return [
255
- $createCodeNode().splice(
256
- 0,
257
- 0,
258
- $generateNodesFromRawText(lines.join('\n')),
259
- ),
274
+ $createCodeNode().splice(0, 0, $plainifyCodeContent(lines.join('\n'))),
260
275
  ];
261
276
  },
262
277
  match: sel.tag('div', 'br'),
@@ -307,18 +322,19 @@ export const $installVscodeCodePasteOverlay: DOMPreprocessFn = (
307
322
 
308
323
  /**
309
324
  * A `<div style="font-family: …monospace…">` (Google-Docs-style code
310
- * block) creates a CodeNode. Descendant elements inside a monospace
311
- * wrapper just unwrap so their text content flows into the surrounding
312
- * CodeNode.
325
+ * block) creates a CodeNode. Plain descendant divs defer to the transparent
326
+ * block rule so their boundaries become separate lines in that CodeNode.
313
327
  */
314
328
  const DivRule = defineImportRule({
315
329
  $import: (ctx, el, $next) => {
316
330
  if (isMonospaceElement(el)) {
317
- return [$createCodeNode().splice(0, 0, ctx.$importChildren(el))];
318
- }
319
- if (isMonospaceDescendant(el)) {
320
- // Unwrap so children flow into the enclosing CodeNode.
321
- return ctx.$importChildren(el);
331
+ return [
332
+ $createCodeNode().splice(
333
+ 0,
334
+ 0,
335
+ $normalizeCodeChildren(ctx.$importChildren(el)),
336
+ ),
337
+ ];
322
338
  }
323
339
  return $next();
324
340
  },
@@ -338,7 +354,9 @@ const GitHubCodeTableRule = defineImportRule({
338
354
  $createCodeNode().splice(
339
355
  0,
340
356
  0,
341
- ctx.$importChildren(el, {rules: GitHubCodeTableOverlayRules}),
357
+ $normalizeCodeChildren(
358
+ ctx.$importChildren(el, {rules: GitHubCodeTableOverlayRules}),
359
+ ),
342
360
  ),
343
361
  ],
344
362
  match: sel.tag('table').classAll('js-file-line-container'),