@lexical/code-core 0.46.0 → 0.46.1-nightly.20260629.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.
|
@@ -1074,14 +1074,18 @@ const CodeExtension = /* @__PURE__ */lexical.defineExtension({
|
|
|
1074
1074
|
name: '@lexical/code',
|
|
1075
1075
|
nodes: () => [CodeNode, CodeHighlightNode],
|
|
1076
1076
|
register(editor) {
|
|
1077
|
-
return editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
|
|
1077
|
+
return lexical.mergeRegister(editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
|
|
1078
1078
|
const selection = lexical.$getSelection();
|
|
1079
1079
|
if (lexical.$isRangeSelection(selection) && $exitCodeNodeOnEnter(selection)) {
|
|
1080
1080
|
event.preventDefault();
|
|
1081
1081
|
return true;
|
|
1082
1082
|
}
|
|
1083
1083
|
return false;
|
|
1084
|
-
}, lexical.COMMAND_PRIORITY_LOW)
|
|
1084
|
+
}, lexical.COMMAND_PRIORITY_LOW), editor.registerNodeTransform(lexical.TabNode, node => {
|
|
1085
|
+
if (node.getFormat() !== 0 && $isCodeNode(node.getParent())) {
|
|
1086
|
+
node.setFormat(0);
|
|
1087
|
+
}
|
|
1088
|
+
}));
|
|
1085
1089
|
}
|
|
1086
1090
|
});
|
|
1087
1091
|
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { defineImportRule, sel, ImportOverlays, defineOverlayRules, CoreImportExtension, DOMImportExtension } from '@lexical/html';
|
|
10
|
-
import { getTextDirection, $isElementNode, $isTabNode, $isLineBreakNode, tokenizeRawText, $createTabNode, $createLineBreakNode, $getSiblingCaret, $create, ElementNode, addClassNamesToElement, setDOMStyleFromCSS, $getEditor, $isTextNode, $createParagraphNode, isHTMLElement, $applyNodeReplacement, TextNode, removeClassNamesFromElement, isDOMDocumentNode, isDOMTextNode, $generateNodesFromRawText, defineExtension, KEY_ENTER_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW, configExtension, safeCast,
|
|
10
|
+
import { getTextDirection, $isElementNode, $isTabNode, $isLineBreakNode, tokenizeRawText, $createTabNode, $createLineBreakNode, $getSiblingCaret, $create, ElementNode, addClassNamesToElement, setDOMStyleFromCSS, $getEditor, $isTextNode, $createParagraphNode, isHTMLElement, $applyNodeReplacement, TextNode, removeClassNamesFromElement, isDOMDocumentNode, isDOMTextNode, $generateNodesFromRawText, defineExtension, mergeRegister, KEY_ENTER_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW, TabNode, configExtension, safeCast, 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, effect, namedSignals } from '@lexical/extension';
|
|
12
12
|
import { $onEscapeDown, $onEscapeUp } from '@lexical/utils';
|
|
13
13
|
|
|
@@ -1072,14 +1072,18 @@ const CodeExtension = /* @__PURE__ */defineExtension({
|
|
|
1072
1072
|
name: '@lexical/code',
|
|
1073
1073
|
nodes: () => [CodeNode, CodeHighlightNode],
|
|
1074
1074
|
register(editor) {
|
|
1075
|
-
return editor.registerCommand(KEY_ENTER_COMMAND, event => {
|
|
1075
|
+
return mergeRegister(editor.registerCommand(KEY_ENTER_COMMAND, event => {
|
|
1076
1076
|
const selection = $getSelection();
|
|
1077
1077
|
if ($isRangeSelection(selection) && $exitCodeNodeOnEnter(selection)) {
|
|
1078
1078
|
event.preventDefault();
|
|
1079
1079
|
return true;
|
|
1080
1080
|
}
|
|
1081
1081
|
return false;
|
|
1082
|
-
}, COMMAND_PRIORITY_LOW)
|
|
1082
|
+
}, COMMAND_PRIORITY_LOW), editor.registerNodeTransform(TabNode, node => {
|
|
1083
|
+
if (node.getFormat() !== 0 && $isCodeNode(node.getParent())) {
|
|
1084
|
+
node.setFormat(0);
|
|
1085
|
+
}
|
|
1086
|
+
}));
|
|
1083
1087
|
}
|
|
1084
1088
|
});
|
|
1085
1089
|
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/html"),t=require("lexical"),n=require("@lexical/extension"),r=require("@lexical/utils");function i(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function o(e,n){let r=e;for(let i=t.$getSiblingCaret(e,n);i&&(D(i.origin)||t.$isTabNode(i.origin));i=i.getAdjacentCaret())r=i.origin;return r}function s(e){return o(e,"previous")}function l(e){return o(e,"next")}function a(e){const n=s(e),r=l(e);let i=n;for(;null!==i;){if(D(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 c(e,n){let r=null,o=null,s=e,l=n,a=e.getTextContent();for(;;){if(0===l){const e=s.getPreviousSibling();if(null===e){s=null;break}if(D(e)||t.$isTabNode(e)||t.$isLineBreakNode(e)||i(167),s=e,t.$isLineBreakNode(s)){r={node:s,offset:1};break}l=Math.max(0,s.getTextContentSize()-1),a=s.getTextContent()}else l--;const e=a[l];D(s)&&" "!==e&&(o={node:s,offset:l})}if(null!==o)return o;let c=null;if(n<e.getTextContentSize())D(e)&&(c=e.getTextContent()[n]);else{const t=e.getNextSibling();D(t)&&(c=t.getTextContent()[0])}if(null!==c&&" "!==c)return r;{const i=function(e,n){let r=e,i=n,o=e.getTextContent(),s=e.getTextContentSize();for(;;){if(!D(r)||i===s){if(r=r.getNextSibling(),null===r||t.$isLineBreakNode(r))return null;D(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(D(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(e,n);return null!==i?i:r}}function u(e){const n=l(e);return t.$isLineBreakNode(n)&&i(168),n}function g(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,a=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return e.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==a&&n.focus.set(s,Math.max(0,a-o),"text"),!0}const d="javascript";function f(e,n){for(const r of e.childNodes){if(t.isHTMLElement(r)&&r.tagName===n)return!0;if(f(r,n))return!0}return!1}const h="data-language",p="data-highlight-language",N="data-theme",m=()=>{};class _ extends t.ElementNode{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new _(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(e){const n=document.createElement("code");t.addClassNamesToElement(n,e.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(h,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(p,r));const i=this.getTheme();i&&n.setAttribute(N,i);const o=this.getStyle();return o&&t.setDOMStyleFromCSS(n.style,o),n}updateDOM(e,n,r){const i=this.__language,o=e.__language;i?i!==o&&n.setAttribute(h,i):o&&n.removeAttribute(h);const s=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&o?s&&i?i!==o&&n.setAttribute(p,i):n.removeAttribute(p):s&&i&&n.setAttribute(p,i);const l=this.__theme,a=e.__theme;l?l!==a&&n.setAttribute(N,l):a&&n.removeAttribute(N);const c=this.__style,u=e.__style;return c!==u&&t.setDOMStyleFromCSS(n.style,c,u),!1}exportDOM(e){const n=document.createElement("pre");t.addClassNamesToElement(n,e._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(h,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(p,r));const i=this.getTheme();i&&n.setAttribute(N,i);const o=this.getStyle();return o&&t.setDOMStyleFromCSS(n.style,o),{element:n}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||f(e,"BR"))?{conversion:x,priority:1}:null,div:()=>({conversion:O,priority:1}),pre:()=>({conversion:x,priority:0}),table:e=>b(e)?{conversion:S,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&b(n)?{conversion:M,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&b(t)?{conversion:M,priority:3}:null}}}static importJSON(e){return T().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,r=!0){if(!n.getPeerDependencyFromEditor(t.$getEditor(),"@lexical/code")){m();const t=E(e);if(t)return t}const{anchor:i,focus:o}=e,l=(i.isBefore(o)?i:o).getNode();if(t.$isTextNode(l)){let e=s(l);const n=[];for(;;)if(t.$isTabNode(e))n.push(t.$createTabNode()),e=e.getNextSibling();else{if(!D(e))break;{let t=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;t<i&&" "===r[t];)t++;if(0!==t&&n.push(A(" ".repeat(t))),t!==i)break;e=e.getNextSibling()}}const r=l.splitText(i.offset)[0],o=0===i.offset?0:1,a=r.getIndexWithinParent()+o,c=l.getParentOrThrow(),u=[t.$createLineBreakNode(),...n];c.splice(a,0,u);const g=n[n.length-1];g?g.select():0===i.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(C(l)){const{offset:n}=e.anchor;l.splice(n,0,[t.$createLineBreakNode()]),l.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 T(e,n){return t.$create(_).setLanguage(e).setTheme(n)}function C(e){return e instanceof _}function x(e){return{node:T(e.getAttribute(h))}}function O(e){const t=e,n=$(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if($(t))return!0;t=t.parentElement}return!1}(t)?{node:n?T():null}:{node:null}}function S(){return{node:T()}}function M(){return{node:null}}function $(e){return null!==e.style.fontFamily.match("monospace")}function b(e){return e.classList.contains("js-file-line-container")}function E(e){const{anchor:n}=e;if(e.isCollapsed()&&"element"===n.type){const e=n.getNode();if(C(e)){const r=e.getChildrenSize();if(r>=2&&n.offset===r){const n=e.getLastChild();if(t.$isLineBreakNode(n)&&t.$isLineBreakNode(n.getPreviousSibling())){const n=t.$createParagraphNode();return e.splice(r-2,2,[]).insertAfter(n,!1),n.select(),n}}}}return null}class R extends t.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new R(e.__text,e.__highlightType||void 0,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const n=super.createDOM(e),r=y(e.theme,this.__highlightType);return t.addClassNamesToElement(n,r),n}updateDOM(e,n,r){const i=super.updateDOM(e,n,r),o=y(r.theme,e.__highlightType),s=y(r.theme,this.__highlightType);return o!==s&&(o&&t.removeClassNamesFromElement(n,o),s&&t.addClassNamesToElement(n,s)),i}static importJSON(e){return A().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 T()}}function y(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function A(e="",n){return t.$applyNodeReplacement(new R(e,n))}function D(e){return e instanceof R}const v="data-language";function I(e){return null!==e.style.fontFamily.match("monospace")}function L(e){let t=e.parentElement;for(;null!==t;){if(I(t))return!0;t=t.parentElement}return!1}const P=/* @__PURE__ */e.defineOverlayRules([/* @__PURE__ */e.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:e.sel.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),B=/* @__PURE__ */e.defineImportRule({$import:(e,t)=>[T(t.getAttribute(v)).splice(0,0,e.$importChildren(t))],match:e.sel.tag("pre"),name:"@lexical/code/pre"}),k=/* @__PURE__ */e.defineImportRule({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[T(t.getAttribute(v)).splice(0,0,e.$importChildren(t))]:n()},match:e.sel.tag("code"),name:"@lexical/code/code-multiline"});function W(e){if(!t.isHTMLElement(e))return!1;const n=e.style.fontFamily,r=e.style.whiteSpace;return"string"==typeof n&&/monospace/i.test(n)&&"string"==typeof r&&r.startsWith("pre")}function w(e){let n=!1;const r=[];let i="",o=!1;const s=()=>{o&&(r.push(i),i="",o=!1)};for(const l of Array.from(e.childNodes))if(t.isHTMLElement(l))"DIV"===l.tagName?(s(),r.push(l.textContent||""),n=!0):"BR"===l.tagName?(s(),r.push(""),n=!0):(i+=l.textContent||"",o=!0);else if(t.isDOMTextNode(l)){const e=l.textContent||"";e.length>0&&(i+=e,o=!0)}return s(),n?r:null}function H(e){for(const n of Array.from(e.children)){if(t.isHTMLElement(n)&&W(n)){if(null!==w(n))return!0;const e=n.nextElementSibling;if(e&&W(e))return!0;continue}if(H(n))return!0}return!1}const F=/* @__PURE__ */e.defineImportRule({$import:(e,n,r)=>{if(!W(n)||L(n))return r();const i=w(n);return null===i||0===i.length?r():[T().splice(0,0,t.$generateNodesFromRawText(i.join("\n")))]},match:e.sel.tag("div"),name:"@lexical/code/vscode-wrapper"}),Y=/* @__PURE__ */e.defineImportRule({$import:(e,n,r)=>{if(!W(n)||L(n))return r();const i=n.previousElementSibling;if(i&&W(i))return[];const o=[];let s=n;for(;s&&W(s);)o.push("BR"===s.tagName?"":s.textContent||""),s=s.nextElementSibling;return o.length<2?r():[T().splice(0,0,t.$generateNodesFromRawText(o.join("\n")))]},match:e.sel.tag("div","br"),name:"@lexical/code/vscode-line-run"}),K=/* @__PURE__ */e.defineOverlayRules([F,Y]),U=/* @__PURE__ */e.defineImportRule({$import:(e,t,n)=>I(t)?[T().splice(0,0,e.$importChildren(t))]:L(t)?e.$importChildren(t):n(),match:e.sel.tag("div"),name:"@lexical/code/div"}),z=[/* @__PURE__ */e.defineImportRule({$import:(e,t)=>[T().splice(0,0,e.$importChildren(t,{rules:P}))],match:e.sel.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),/* @__PURE__ */e.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:e.sel.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),k,B,U],J=/* @__PURE__ */t.defineExtension({dependencies:[e.CoreImportExtension,/* @__PURE__ */t.configExtension(e.DOMImportExtension,{preprocess:[(n,r,i)=>{H(t.isDOMDocumentNode(n)?n.body:n)&&r.session.update(e.ImportOverlays,e=>[...e,K]),i()}],rules:z})],name:"@lexical/code",nodes:()=>[_,R],register:e=>e.registerCommand(t.KEY_ENTER_COMMAND,e=>{const n=t.$getSelection();return!(!t.$isRangeSelection(n)||!E(n))&&(e.preventDefault(),!0)},t.COMMAND_PRIORITY_LOW)}),j=/* @__PURE__ */t.defineExtension({dependencies:[J],name:"@lexical/code/Import"});function q(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 V(e){const n=e.getNodes(),r=[];if(1===n.length&&C(n[0]))return r;let o=[];for(let e=0;e<n.length;e++){const s=n[e];D(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||i(169),t.$isLineBreakNode(s)?o.length>0&&(r.push(o),o=[]):o.push(s)}if(o.length>0){const n=e.isBackward()?e.anchor:e.focus,i=t.$createPoint(o[0].getKey(),0,"text");n.is(i)||r.push(o)}return r}function G(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r)||!q(r))return!1;const i=V(r),o=i.length;if(0===o&&r.isCollapsed())return e===t.INDENT_CONTENT_COMMAND&&r.insertNodes([t.$createTabNode()]),!0;if(0===o&&e===t.INDENT_CONTENT_COMMAND&&"\n"===r.getTextContent()){const e=t.$createTabNode(),n=t.$createLineBreakNode(),i=r.isBackward()?"previous":"next";return r.insertNodes([e,n]),t.$setSelectionFromCaretRange(t.$getCaretRangeInDirection(t.$getCaretRange(t.$getTextPointCaret(e,"next",0),t.$normalizeCaret(t.$getSiblingCaret(n,"next"))),i)),!0}for(let l=0;l<o;l++){const o=i[l];if(o.length>0){let i=o[0];if(0===l&&(i=s(i)),e===t.INDENT_CONTENT_COMMAND){const e=t.$createTabNode();if(i.insertBefore(e),0===l){const n=r.isBackward()?"focus":"anchor",o=t.$createPoint(i.getKey(),0,"text");r[n].is(o)&&r[n].set(e.getKey(),0,"text")}}else t.$isTabNode(i)?i.remove():void 0!==n&&D(i)&&g(i,n,r)}}return!0}function Q(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,a=i.offset,c=o.offset,u=i.getNode(),g=o.getNode(),d=e===t.KEY_ARROW_UP_COMMAND;if(!q(r)||!D(u)&&!t.$isTabNode(u)||!D(g)&&!t.$isTabNode(g))return!1;if(!n.altKey){if(r.isCollapsed()){const e=u.getParentOrThrow();if(d&&0===a&&null===u.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),n.preventDefault(),!1}else if(!d&&a===u.getTextContentSize()&&null===u.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),n.preventDefault(),!1}}return!1}let f,h;if(u.isBefore(g)?(f=s(u),h=l(g)):(f=s(g),h=l(u)),null==f||null==h)return!1;const p=f.getNodesBetween(h);for(let e=0;e<p.length;e++){const n=p[e];if(!D(n)&&!t.$isTabNode(n)&&!t.$isLineBreakNode(n))return!1}n.preventDefault(),n.stopPropagation();const N=d?f.getPreviousSibling():h.getNextSibling();if(!t.$isLineBreakNode(N))return!0;const m=d?N.getPreviousSibling():N.getNextSibling();if(null==m)return!0;const _=D(m)||t.$isTabNode(m)||t.$isLineBreakNode(m)?d?s(m):l(m):null;let T=null!=_?_:m;return N.remove(),p.forEach(e=>e.remove()),e===t.KEY_ARROW_UP_COMMAND?(p.forEach(e=>T.insertBefore(e)),T.insertBefore(N)):(T.insertAfter(N),T=N,p.forEach(e=>{T.insertAfter(e),T=e})),r.setTextNodeRange(u,a,g,c),!0}function X(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.getNode(),l=o.getNode(),g=e===t.MOVE_TO_START;if(!q(r)||!D(s)&&!t.$isTabNode(s)||!D(l)&&!t.$isTabNode(l))return!1;const d=l,f="rtl"===a(d)?!g:g,h=i.key,p=i.offset,N=i.type;if(f){const e=c(d,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 d.getParentOrThrow().selectStart()}else{u(d).select()}return n.shiftKey&&r.anchor.set(h,p,N),n.preventDefault(),n.stopPropagation(),!0}function Z(e,n,o){return t.mergeRegister(...o?[e.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>!e.altKey&&r.$onEscapeDown(C,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_RIGHT_COMMAND,e=>r.$onEscapeDown(C,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>!e.altKey&&r.$onEscapeUp(C,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_LEFT_COMMAND,e=>r.$onEscapeUp(C,e),t.COMMAND_PRIORITY_LOW)]:[],e.registerCommand(t.KEY_TAB_COMMAND,n=>{const r=function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!q(n))return null;const r=e?t.OUTDENT_CONTENT_COMMAND:t.INDENT_CONTENT_COMMAND,o=e?t.OUTDENT_CONTENT_COMMAND:t.INSERT_TAB_COMMAND,a=n.anchor,c=n.focus;if(a.is(c))return o;const u=V(n);if(1!==u.length)return r;const g=u[0];let d,f;0===g.length&&i(285),n.isBackward()?(d=c,f=a):(d=a,f=c);const h=s(g[0]),p=l(g[0]),N=t.$createPoint(h.getKey(),0,"text"),m=t.$createPoint(p.getKey(),p.getTextContentSize(),"text");return d.isBefore(N)||m.isBefore(f)?r:N.isBefore(d)||f.isBefore(m)?o:r}(n.shiftKey);return null!==r&&(n.preventDefault(),e.dispatchCommand(r,void 0),!0)},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.INSERT_TAB_COMMAND,()=>!!q(t.$getSelection())&&(t.$insertNodes([t.$createTabNode()]),!0),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.INDENT_CONTENT_COMMAND,()=>G(t.INDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.OUTDENT_CONTENT_COMMAND,()=>G(t.OUTDENT_CONTENT_COMMAND,n),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();if(!q(n))return!1;const o=i.getParent();return n.isCollapsed()&&0===r.offset&&null===i.getPreviousSibling()&&C(o)&&null===o.getPreviousSibling()?(e.preventDefault(),!0):Q(t.KEY_ARROW_UP_COMMAND,e)},t.COMMAND_PRIORITY_LOW),e.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!!q(n)&&(n.isCollapsed()&&r.offset===i.getTextContentSize()&&null===i.getNextSibling()&&C(i.getParentOrThrow())&&null===i.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):Q(t.KEY_ARROW_DOWN_COMMAND,e))},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.MOVE_TO_START,e=>X(t.MOVE_TO_START,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.MOVE_TO_END,e=>X(t.MOVE_TO_END,e),t.COMMAND_PRIORITY_LOW))}const ee=/* @__PURE__ */t.defineExtension({build:(e,t)=>n.namedSignals(t),config:/* @__PURE__ */t.safeCast({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[J],name:"@lexical/code-indent",register:(e,t,r)=>{const i=r.getOutput();return n.effect(()=>{if(!i.disabled.value)return Z(e,i.tabSize.value,i.escapeWithArrows.value)})}});exports.$createCodeHighlightNode=A,exports.$createCodeNode=T,exports.$getCodeLineDirection=a,exports.$getEndOfCodeInLine=u,exports.$getFirstCodeNodeOfLine=s,exports.$getLastCodeNodeOfLine=l,exports.$getStartOfCodeInLine=c,exports.$isCodeHighlightNode=D,exports.$isCodeNode=C,exports.$outdentLeadingSpaces=g,exports.$plainifyCodeContent=function(e){const n=[];return t.tokenizeRawText(e,{linebreak:()=>n.push(t.$createLineBreakNode()),tab:()=>n.push(t.$createTabNode()),text:e=>n.push(A(e))}),n},exports.CodeExtension=J,exports.CodeHighlightNode=R,exports.CodeImportExtension=j,exports.CodeImportRules=z,exports.CodeIndentExtension=ee,exports.CodeNode=_,exports.DEFAULT_CODE_LANGUAGE=d,exports.getDefaultCodeLanguage=()=>d,exports.registerCodeIndentation=Z;
|
|
9
|
+
"use strict";var e=require("@lexical/html"),t=require("lexical"),n=require("@lexical/extension"),r=require("@lexical/utils");function i(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function o(e,n){let r=e;for(let i=t.$getSiblingCaret(e,n);i&&(D(i.origin)||t.$isTabNode(i.origin));i=i.getAdjacentCaret())r=i.origin;return r}function s(e){return o(e,"previous")}function l(e){return o(e,"next")}function a(e){const n=s(e),r=l(e);let i=n;for(;null!==i;){if(D(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 c(e,n){let r=null,o=null,s=e,l=n,a=e.getTextContent();for(;;){if(0===l){const e=s.getPreviousSibling();if(null===e){s=null;break}if(D(e)||t.$isTabNode(e)||t.$isLineBreakNode(e)||i(167),s=e,t.$isLineBreakNode(s)){r={node:s,offset:1};break}l=Math.max(0,s.getTextContentSize()-1),a=s.getTextContent()}else l--;const e=a[l];D(s)&&" "!==e&&(o={node:s,offset:l})}if(null!==o)return o;let c=null;if(n<e.getTextContentSize())D(e)&&(c=e.getTextContent()[n]);else{const t=e.getNextSibling();D(t)&&(c=t.getTextContent()[0])}if(null!==c&&" "!==c)return r;{const i=function(e,n){let r=e,i=n,o=e.getTextContent(),s=e.getTextContentSize();for(;;){if(!D(r)||i===s){if(r=r.getNextSibling(),null===r||t.$isLineBreakNode(r))return null;D(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(D(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(e,n);return null!==i?i:r}}function u(e){const n=l(e);return t.$isLineBreakNode(n)&&i(168),n}function g(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,a=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return e.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==a&&n.focus.set(s,Math.max(0,a-o),"text"),!0}const d="javascript";function f(e,n){for(const r of e.childNodes){if(t.isHTMLElement(r)&&r.tagName===n)return!0;if(f(r,n))return!0}return!1}const h="data-language",p="data-highlight-language",N="data-theme",m=()=>{};class _ extends t.ElementNode{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new _(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(e){const n=document.createElement("code");t.addClassNamesToElement(n,e.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(h,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(p,r));const i=this.getTheme();i&&n.setAttribute(N,i);const o=this.getStyle();return o&&t.setDOMStyleFromCSS(n.style,o),n}updateDOM(e,n,r){const i=this.__language,o=e.__language;i?i!==o&&n.setAttribute(h,i):o&&n.removeAttribute(h);const s=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&o?s&&i?i!==o&&n.setAttribute(p,i):n.removeAttribute(p):s&&i&&n.setAttribute(p,i);const l=this.__theme,a=e.__theme;l?l!==a&&n.setAttribute(N,l):a&&n.removeAttribute(N);const c=this.__style,u=e.__style;return c!==u&&t.setDOMStyleFromCSS(n.style,c,u),!1}exportDOM(e){const n=document.createElement("pre");t.addClassNamesToElement(n,e._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(h,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(p,r));const i=this.getTheme();i&&n.setAttribute(N,i);const o=this.getStyle();return o&&t.setDOMStyleFromCSS(n.style,o),{element:n}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||f(e,"BR"))?{conversion:x,priority:1}:null,div:()=>({conversion:O,priority:1}),pre:()=>({conversion:x,priority:0}),table:e=>b(e)?{conversion:S,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&b(n)?{conversion:M,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&b(t)?{conversion:M,priority:3}:null}}}static importJSON(e){return T().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,r=!0){if(!n.getPeerDependencyFromEditor(t.$getEditor(),"@lexical/code")){m();const t=E(e);if(t)return t}const{anchor:i,focus:o}=e,l=(i.isBefore(o)?i:o).getNode();if(t.$isTextNode(l)){let e=s(l);const n=[];for(;;)if(t.$isTabNode(e))n.push(t.$createTabNode()),e=e.getNextSibling();else{if(!D(e))break;{let t=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;t<i&&" "===r[t];)t++;if(0!==t&&n.push(A(" ".repeat(t))),t!==i)break;e=e.getNextSibling()}}const r=l.splitText(i.offset)[0],o=0===i.offset?0:1,a=r.getIndexWithinParent()+o,c=l.getParentOrThrow(),u=[t.$createLineBreakNode(),...n];c.splice(a,0,u);const g=n[n.length-1];g?g.select():0===i.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(C(l)){const{offset:n}=e.anchor;l.splice(n,0,[t.$createLineBreakNode()]),l.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 T(e,n){return t.$create(_).setLanguage(e).setTheme(n)}function C(e){return e instanceof _}function x(e){return{node:T(e.getAttribute(h))}}function O(e){const t=e,n=$(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if($(t))return!0;t=t.parentElement}return!1}(t)?{node:n?T():null}:{node:null}}function S(){return{node:T()}}function M(){return{node:null}}function $(e){return null!==e.style.fontFamily.match("monospace")}function b(e){return e.classList.contains("js-file-line-container")}function E(e){const{anchor:n}=e;if(e.isCollapsed()&&"element"===n.type){const e=n.getNode();if(C(e)){const r=e.getChildrenSize();if(r>=2&&n.offset===r){const n=e.getLastChild();if(t.$isLineBreakNode(n)&&t.$isLineBreakNode(n.getPreviousSibling())){const n=t.$createParagraphNode();return e.splice(r-2,2,[]).insertAfter(n,!1),n.select(),n}}}}return null}class R extends t.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new R(e.__text,e.__highlightType||void 0,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const n=super.createDOM(e),r=y(e.theme,this.__highlightType);return t.addClassNamesToElement(n,r),n}updateDOM(e,n,r){const i=super.updateDOM(e,n,r),o=y(r.theme,e.__highlightType),s=y(r.theme,this.__highlightType);return o!==s&&(o&&t.removeClassNamesFromElement(n,o),s&&t.addClassNamesToElement(n,s)),i}static importJSON(e){return A().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 T()}}function y(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function A(e="",n){return t.$applyNodeReplacement(new R(e,n))}function D(e){return e instanceof R}const v="data-language";function I(e){return null!==e.style.fontFamily.match("monospace")}function L(e){let t=e.parentElement;for(;null!==t;){if(I(t))return!0;t=t.parentElement}return!1}const P=/* @__PURE__ */e.defineOverlayRules([/* @__PURE__ */e.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:e.sel.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),B=/* @__PURE__ */e.defineImportRule({$import:(e,t)=>[T(t.getAttribute(v)).splice(0,0,e.$importChildren(t))],match:e.sel.tag("pre"),name:"@lexical/code/pre"}),k=/* @__PURE__ */e.defineImportRule({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[T(t.getAttribute(v)).splice(0,0,e.$importChildren(t))]:n()},match:e.sel.tag("code"),name:"@lexical/code/code-multiline"});function W(e){if(!t.isHTMLElement(e))return!1;const n=e.style.fontFamily,r=e.style.whiteSpace;return"string"==typeof n&&/monospace/i.test(n)&&"string"==typeof r&&r.startsWith("pre")}function w(e){let n=!1;const r=[];let i="",o=!1;const s=()=>{o&&(r.push(i),i="",o=!1)};for(const l of Array.from(e.childNodes))if(t.isHTMLElement(l))"DIV"===l.tagName?(s(),r.push(l.textContent||""),n=!0):"BR"===l.tagName?(s(),r.push(""),n=!0):(i+=l.textContent||"",o=!0);else if(t.isDOMTextNode(l)){const e=l.textContent||"";e.length>0&&(i+=e,o=!0)}return s(),n?r:null}function F(e){for(const n of Array.from(e.children)){if(t.isHTMLElement(n)&&W(n)){if(null!==w(n))return!0;const e=n.nextElementSibling;if(e&&W(e))return!0;continue}if(F(n))return!0}return!1}const H=/* @__PURE__ */e.defineImportRule({$import:(e,n,r)=>{if(!W(n)||L(n))return r();const i=w(n);return null===i||0===i.length?r():[T().splice(0,0,t.$generateNodesFromRawText(i.join("\n")))]},match:e.sel.tag("div"),name:"@lexical/code/vscode-wrapper"}),Y=/* @__PURE__ */e.defineImportRule({$import:(e,n,r)=>{if(!W(n)||L(n))return r();const i=n.previousElementSibling;if(i&&W(i))return[];const o=[];let s=n;for(;s&&W(s);)o.push("BR"===s.tagName?"":s.textContent||""),s=s.nextElementSibling;return o.length<2?r():[T().splice(0,0,t.$generateNodesFromRawText(o.join("\n")))]},match:e.sel.tag("div","br"),name:"@lexical/code/vscode-line-run"}),K=/* @__PURE__ */e.defineOverlayRules([H,Y]),U=/* @__PURE__ */e.defineImportRule({$import:(e,t,n)=>I(t)?[T().splice(0,0,e.$importChildren(t))]:L(t)?e.$importChildren(t):n(),match:e.sel.tag("div"),name:"@lexical/code/div"}),z=[/* @__PURE__ */e.defineImportRule({$import:(e,t)=>[T().splice(0,0,e.$importChildren(t,{rules:P}))],match:e.sel.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),/* @__PURE__ */e.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:e.sel.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),k,B,U],J=/* @__PURE__ */t.defineExtension({dependencies:[e.CoreImportExtension,/* @__PURE__ */t.configExtension(e.DOMImportExtension,{preprocess:[(n,r,i)=>{F(t.isDOMDocumentNode(n)?n.body:n)&&r.session.update(e.ImportOverlays,e=>[...e,K]),i()}],rules:z})],name:"@lexical/code",nodes:()=>[_,R],register:e=>t.mergeRegister(e.registerCommand(t.KEY_ENTER_COMMAND,e=>{const n=t.$getSelection();return!(!t.$isRangeSelection(n)||!E(n))&&(e.preventDefault(),!0)},t.COMMAND_PRIORITY_LOW),e.registerNodeTransform(t.TabNode,e=>{0!==e.getFormat()&&C(e.getParent())&&e.setFormat(0)}))}),j=/* @__PURE__ */t.defineExtension({dependencies:[J],name:"@lexical/code/Import"});function q(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 V(e){const n=e.getNodes(),r=[];if(1===n.length&&C(n[0]))return r;let o=[];for(let e=0;e<n.length;e++){const s=n[e];D(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||i(169),t.$isLineBreakNode(s)?o.length>0&&(r.push(o),o=[]):o.push(s)}if(o.length>0){const n=e.isBackward()?e.anchor:e.focus,i=t.$createPoint(o[0].getKey(),0,"text");n.is(i)||r.push(o)}return r}function G(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r)||!q(r))return!1;const i=V(r),o=i.length;if(0===o&&r.isCollapsed())return e===t.INDENT_CONTENT_COMMAND&&r.insertNodes([t.$createTabNode()]),!0;if(0===o&&e===t.INDENT_CONTENT_COMMAND&&"\n"===r.getTextContent()){const e=t.$createTabNode(),n=t.$createLineBreakNode(),i=r.isBackward()?"previous":"next";return r.insertNodes([e,n]),t.$setSelectionFromCaretRange(t.$getCaretRangeInDirection(t.$getCaretRange(t.$getTextPointCaret(e,"next",0),t.$normalizeCaret(t.$getSiblingCaret(n,"next"))),i)),!0}for(let l=0;l<o;l++){const o=i[l];if(o.length>0){let i=o[0];if(0===l&&(i=s(i)),e===t.INDENT_CONTENT_COMMAND){const e=t.$createTabNode();if(i.insertBefore(e),0===l){const n=r.isBackward()?"focus":"anchor",o=t.$createPoint(i.getKey(),0,"text");r[n].is(o)&&r[n].set(e.getKey(),0,"text")}}else t.$isTabNode(i)?i.remove():void 0!==n&&D(i)&&g(i,n,r)}}return!0}function Q(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,a=i.offset,c=o.offset,u=i.getNode(),g=o.getNode(),d=e===t.KEY_ARROW_UP_COMMAND;if(!q(r)||!D(u)&&!t.$isTabNode(u)||!D(g)&&!t.$isTabNode(g))return!1;if(!n.altKey){if(r.isCollapsed()){const e=u.getParentOrThrow();if(d&&0===a&&null===u.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),n.preventDefault(),!1}else if(!d&&a===u.getTextContentSize()&&null===u.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),n.preventDefault(),!1}}return!1}let f,h;if(u.isBefore(g)?(f=s(u),h=l(g)):(f=s(g),h=l(u)),null==f||null==h)return!1;const p=f.getNodesBetween(h);for(let e=0;e<p.length;e++){const n=p[e];if(!D(n)&&!t.$isTabNode(n)&&!t.$isLineBreakNode(n))return!1}n.preventDefault(),n.stopPropagation();const N=d?f.getPreviousSibling():h.getNextSibling();if(!t.$isLineBreakNode(N))return!0;const m=d?N.getPreviousSibling():N.getNextSibling();if(null==m)return!0;const _=D(m)||t.$isTabNode(m)||t.$isLineBreakNode(m)?d?s(m):l(m):null;let T=null!=_?_:m;return N.remove(),p.forEach(e=>e.remove()),e===t.KEY_ARROW_UP_COMMAND?(p.forEach(e=>T.insertBefore(e)),T.insertBefore(N)):(T.insertAfter(N),T=N,p.forEach(e=>{T.insertAfter(e),T=e})),r.setTextNodeRange(u,a,g,c),!0}function X(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.getNode(),l=o.getNode(),g=e===t.MOVE_TO_START;if(!q(r)||!D(s)&&!t.$isTabNode(s)||!D(l)&&!t.$isTabNode(l))return!1;const d=l,f="rtl"===a(d)?!g:g,h=i.key,p=i.offset,N=i.type;if(f){const e=c(d,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 d.getParentOrThrow().selectStart()}else{u(d).select()}return n.shiftKey&&r.anchor.set(h,p,N),n.preventDefault(),n.stopPropagation(),!0}function Z(e,n,o){return t.mergeRegister(...o?[e.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>!e.altKey&&r.$onEscapeDown(C,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_RIGHT_COMMAND,e=>r.$onEscapeDown(C,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>!e.altKey&&r.$onEscapeUp(C,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_LEFT_COMMAND,e=>r.$onEscapeUp(C,e),t.COMMAND_PRIORITY_LOW)]:[],e.registerCommand(t.KEY_TAB_COMMAND,n=>{const r=function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!q(n))return null;const r=e?t.OUTDENT_CONTENT_COMMAND:t.INDENT_CONTENT_COMMAND,o=e?t.OUTDENT_CONTENT_COMMAND:t.INSERT_TAB_COMMAND,a=n.anchor,c=n.focus;if(a.is(c))return o;const u=V(n);if(1!==u.length)return r;const g=u[0];let d,f;0===g.length&&i(285),n.isBackward()?(d=c,f=a):(d=a,f=c);const h=s(g[0]),p=l(g[0]),N=t.$createPoint(h.getKey(),0,"text"),m=t.$createPoint(p.getKey(),p.getTextContentSize(),"text");return d.isBefore(N)||m.isBefore(f)?r:N.isBefore(d)||f.isBefore(m)?o:r}(n.shiftKey);return null!==r&&(n.preventDefault(),e.dispatchCommand(r,void 0),!0)},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.INSERT_TAB_COMMAND,()=>!!q(t.$getSelection())&&(t.$insertNodes([t.$createTabNode()]),!0),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.INDENT_CONTENT_COMMAND,()=>G(t.INDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.OUTDENT_CONTENT_COMMAND,()=>G(t.OUTDENT_CONTENT_COMMAND,n),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();if(!q(n))return!1;const o=i.getParent();return n.isCollapsed()&&0===r.offset&&null===i.getPreviousSibling()&&C(o)&&null===o.getPreviousSibling()?(e.preventDefault(),!0):Q(t.KEY_ARROW_UP_COMMAND,e)},t.COMMAND_PRIORITY_LOW),e.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!!q(n)&&(n.isCollapsed()&&r.offset===i.getTextContentSize()&&null===i.getNextSibling()&&C(i.getParentOrThrow())&&null===i.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):Q(t.KEY_ARROW_DOWN_COMMAND,e))},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.MOVE_TO_START,e=>X(t.MOVE_TO_START,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.MOVE_TO_END,e=>X(t.MOVE_TO_END,e),t.COMMAND_PRIORITY_LOW))}const ee=/* @__PURE__ */t.defineExtension({build:(e,t)=>n.namedSignals(t),config:/* @__PURE__ */t.safeCast({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[J],name:"@lexical/code-indent",register:(e,t,r)=>{const i=r.getOutput();return n.effect(()=>{if(!i.disabled.value)return Z(e,i.tabSize.value,i.escapeWithArrows.value)})}});exports.$createCodeHighlightNode=A,exports.$createCodeNode=T,exports.$getCodeLineDirection=a,exports.$getEndOfCodeInLine=u,exports.$getFirstCodeNodeOfLine=s,exports.$getLastCodeNodeOfLine=l,exports.$getStartOfCodeInLine=c,exports.$isCodeHighlightNode=D,exports.$isCodeNode=C,exports.$outdentLeadingSpaces=g,exports.$plainifyCodeContent=function(e){const n=[];return t.tokenizeRawText(e,{linebreak:()=>n.push(t.$createLineBreakNode()),tab:()=>n.push(t.$createTabNode()),text:e=>n.push(A(e))}),n},exports.CodeExtension=J,exports.CodeHighlightNode=R,exports.CodeImportExtension=j,exports.CodeImportRules=z,exports.CodeIndentExtension=ee,exports.CodeNode=_,exports.DEFAULT_CODE_LANGUAGE=d,exports.getDefaultCodeLanguage=()=>d,exports.registerCodeIndentation=Z;
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{defineImportRule as e,sel as t,ImportOverlays 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 h,$getSiblingCaret as f,$create as p,ElementNode as d,addClassNamesToElement as m,setDOMStyleFromCSS as x,$getEditor as _,$isTextNode as S,$createParagraphNode as y,isHTMLElement as b,$applyNodeReplacement as v,TextNode as C,removeClassNamesFromElement as N,isDOMDocumentNode as T,isDOMTextNode as A,$generateNodesFromRawText as O,defineExtension as P,KEY_ENTER_COMMAND as
|
|
10
|
-
/*@__INLINE__*/function ie(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function oe(e,t){let n=e;for(let r=f(e,t);r&&(Be(r.origin)||u(r.origin));r=r.getAdjacentCaret())n=r.origin;return n}function se(e){return oe(e,"previous")}function le(e){return oe(e,"next")}function ue(e){const t=se(e),n=le(e);let r=t;for(;null!==r;){if(Be(r)){const e=s(r.getTextContent());if(null!==e)return e}if(r===n)break;r=r.getNextSibling()}const i=t.getParent();if(l(i)){const e=i.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function ce(e,t){let n=null,r=null,i=e,o=t,s=e.getTextContent();for(;;){if(0===o){const e=i.getPreviousSibling();if(null===e){i=null;break}if(Be(e)||u(e)||c(e)||ie(167),i=e,c(i)){n={node:i,offset:1};break}o=Math.max(0,i.getTextContentSize()-1),s=i.getTextContent()}else o--;const e=s[o];Be(i)&&" "!==e&&(r={node:i,offset:o})}if(null!==r)return r;let l=null;if(t<e.getTextContentSize())Be(e)&&(l=e.getTextContent()[t]);else{const t=e.getNextSibling();Be(t)&&(l=t.getTextContent()[0])}if(null!==l&&" "!==l)return n;{const r=function(e,t){let n=e,r=t,i=e.getTextContent(),o=e.getTextContentSize();for(;;){if(!Be(n)||r===o){if(n=n.getNextSibling(),null===n||c(n))return null;Be(n)&&(r=0,i=n.getTextContent(),o=n.getTextContentSize())}if(Be(n)){if(" "!==i[r])return{node:n,offset:r};r++}}}(e,t);return null!==r?r:n}}function ae(e){const t=le(e);return c(t)&&ie(168),t}function ge(e){const t=[];return a(e,{linebreak:()=>t.push(h()),tab:()=>t.push(g()),text:e=>t.push(ke(e))}),t}function he(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.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 e.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 fe="javascript",pe=()=>fe;function de(e,t){for(const n of e.childNodes){if(b(n)&&n.tagName===t)return!0;if(de(n,t))return!0}return!1}const me="data-language",xe="data-highlight-language",_e="data-theme",Se=()=>{};class ye extends d{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new ye(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(e){const t=document.createElement("code");m(t,e.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(me,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(xe,n));const r=this.getTheme();r&&t.setAttribute(_e,r);const i=this.getStyle();return i&&x(t.style,i),t}updateDOM(e,t,n){const r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(me,r):i&&t.removeAttribute(me);const o=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&t.setAttribute(xe,r):t.removeAttribute(xe):o&&r&&t.setAttribute(xe,r);const s=this.__theme,l=e.__theme;s?s!==l&&t.setAttribute(_e,s):l&&t.removeAttribute(_e);const u=this.__style,c=e.__style;return u!==c&&x(t.style,u,c),!1}exportDOM(e){const t=document.createElement("pre");m(t,e._config.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(me,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(xe,n));const r=this.getTheme();r&&t.setAttribute(_e,r);const i=this.getStyle();return i&&x(t.style,i),{element:t}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||de(e,"BR"))?{conversion:Ce,priority:1}:null,div:()=>({conversion:Ne,priority:1}),pre:()=>({conversion:Ce,priority:0}),table:e=>Pe(e)?{conversion:Te,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&Pe(n)?{conversion:Ae,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&Pe(t)?{conversion:Ae,priority:3}:null}}}static importJSON(e){return be().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,t=!0){if(!Z(_(),"@lexical/code")){Se();const t=we(e);if(t)return t}const{anchor:n,focus:r}=e,i=(n.isBefore(r)?n:r).getNode();if(S(i)){let e=se(i);const t=[];for(;;)if(u(e))t.push(g()),e=e.getNextSibling();else{if(!Be(e))break;{let n=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&t.push(ke(" ".repeat(n))),n!==i)break;e=e.getNextSibling()}}const r=i.splitText(n.offset)[0],o=0===n.offset?0:1,s=r.getIndexWithinParent()+o,l=i.getParentOrThrow(),c=[h(),...t];l.splice(s,0,c);const a=t[t.length-1];a?a.select():0===n.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(ve(i)){const{offset:t}=e.anchor;i.splice(t,0,[h()]),i.select(t+1,t+1)}return null}canIndent(){return!1}collapseAtStart(){const e=y();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 be(e,t){return p(ye).setLanguage(e).setTheme(t)}function ve(e){return e instanceof ye}function Ce(e){return{node:be(e.getAttribute(me))}}function Ne(e){const t=e,n=Oe(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(Oe(t))return!0;t=t.parentElement}return!1}(t)?{node:n?be():null}:{node:null}}function Te(){return{node:be()}}function Ae(){return{node:null}}function Oe(e){return null!==e.style.fontFamily.match("monospace")}function Pe(e){return e.classList.contains("js-file-line-container")}function we(e){const{anchor:t}=e;if(e.isCollapsed()&&"element"===t.type){const e=t.getNode();if(ve(e)){const n=e.getChildrenSize();if(n>=2&&t.offset===n){const t=e.getLastChild();if(c(t)&&c(t.getPreviousSibling())){const t=y();return e.splice(n-2,2,[]).insertAfter(t,!1),t.select(),t}}}}return null}class He extends C{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new He(e.__text,e.__highlightType||void 0,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const t=super.createDOM(e),n=De(e.theme,this.__highlightType);return m(t,n),t}updateDOM(e,t,n){const r=super.updateDOM(e,t,n),i=De(n.theme,e.__highlightType),o=De(n.theme,this.__highlightType);return i!==o&&(i&&N(t,i),o&&m(t,o)),r}static importJSON(e){return ke().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 be()}}function De(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function ke(e="",t){return v(new He(e,t))}function Be(e){return e instanceof He}const Le="data-language";function $e(e){return null!==e.style.fontFamily.match("monospace")}function Ee(e){let t=e.parentElement;for(;null!==t;){if($e(t))return!0;t=t.parentElement}return!1}const Fe=/* @__PURE__ */r([/* @__PURE__ */e({$import:(e,t)=>e.$importChildren(t),match:t.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),Me=/* @__PURE__ */e({$import:(e,t)=>[be(t.getAttribute(Le)).splice(0,0,e.$importChildren(t))],match:t.tag("pre"),name:"@lexical/code/pre"}),Je=/* @__PURE__ */e({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[be(t.getAttribute(Le)).splice(0,0,e.$importChildren(t))]:n()},match:t.tag("code"),name:"@lexical/code/code-multiline"});function ze(e){if(!b(e))return!1;const t=e.style.fontFamily,n=e.style.whiteSpace;return"string"==typeof t&&/monospace/i.test(t)&&"string"==typeof n&&n.startsWith("pre")}function Ke(e){let t=!1;const n=[];let r="",i=!1;const o=()=>{i&&(n.push(r),r="",i=!1)};for(const s of Array.from(e.childNodes))if(b(s))"DIV"===s.tagName?(o(),n.push(s.textContent||""),t=!0):"BR"===s.tagName?(o(),n.push(""),t=!0):(r+=s.textContent||"",i=!0);else if(A(s)){const e=s.textContent||"";e.length>0&&(r+=e,i=!0)}return o(),t?n:null}function Ie(e){for(const t of Array.from(e.children)){if(b(t)&&ze(t)){if(null!==Ke(t))return!0;const e=t.nextElementSibling;if(e&&ze(e))return!0;continue}if(Ie(t))return!0}return!1}const je=/* @__PURE__ */r([/* @__PURE__ */e({$import:(e,t,n)=>{if(!ze(t)||Ee(t))return n();const r=Ke(t);return null===r||0===r.length?n():[be().splice(0,0,O(r.join("\n")))]},match:t.tag("div"),name:"@lexical/code/vscode-wrapper"}),/* @__PURE__ */e({$import:(e,t,n)=>{if(!ze(t)||Ee(t))return n();const r=t.previousElementSibling;if(r&&ze(r))return[];const i=[];let o=t;for(;o&&ze(o);)i.push("BR"===o.tagName?"":o.textContent||""),o=o.nextElementSibling;return i.length<2?n():[be().splice(0,0,O(i.join("\n")))]},match:t.tag("div","br"),name:"@lexical/code/vscode-line-run"})]),Re=/* @__PURE__ */e({$import:(e,t,n)=>$e(t)?[be().splice(0,0,e.$importChildren(t))]:Ee(t)?e.$importChildren(t):n(),match:t.tag("div"),name:"@lexical/code/div"}),We=[/* @__PURE__ */e({$import:(e,t)=>[be().splice(0,0,e.$importChildren(t,{rules:Fe}))],match:t.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),/* @__PURE__ */e({$import:(e,t)=>e.$importChildren(t),match:t.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),Je,Me,Re],qe=/* @__PURE__ */P({dependencies:[i,/* @__PURE__ */B(o,{preprocess:[(e,t,r)=>{Ie(T(e)?e.body:e)&&t.session.update(n,e=>[...e,je]),r()}],rules:We})],name:"@lexical/code",nodes:()=>[ye,He],register:e=>e.registerCommand(w,e=>{const t=H();return!(!D(t)||!we(t))&&(e.preventDefault(),!0)},k)}),Ue=/* @__PURE__ */P({dependencies:[qe],name:"@lexical/code/Import"});function Ve(e){if(!D(e))return!1;const t=e.anchor.getNode(),n=ve(t)?t:t.getParent(),r=e.focus.getNode(),i=ve(r)?r:r.getParent();return ve(n)&&n.is(i)}function Ge(e){const t=e.getNodes(),n=[];if(1===t.length&&ve(t[0]))return n;let r=[];for(let e=0;e<t.length;e++){const i=t[e];Be(i)||u(i)||c(i)||ie(169),c(i)?r.length>0&&(n.push(r),r=[]):r.push(i)}if(r.length>0){const t=e.isBackward()?e.anchor:e.focus,i=U(r[0].getKey(),0,"text");t.is(i)||n.push(r)}return n}function Qe(e,t){const n=H();if(!D(n)||!Ve(n))return!1;const r=Ge(n),i=r.length;if(0===i&&n.isCollapsed())return e===j&&n.insertNodes([g()]),!0;if(0===i&&e===j&&"\n"===n.getTextContent()){const e=g(),t=h(),r=n.isBackward()?"previous":"next";return n.insertNodes([e,t]),V(G(Q(X(e,"next",0),Y(f(t,"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=se(r)),e===j){const e=g();if(r.insertBefore(e),0===o){const t=n.isBackward()?"focus":"anchor",i=U(r.getKey(),0,"text");n[t].is(i)&&n[t].set(e.getKey(),0,"text")}}else u(r)?r.remove():void 0!==t&&Be(r)&&he(r,t,n)}}return!0}function Xe(e,t){const n=H();if(!D(n))return!1;const{anchor:r,focus:i}=n,o=r.offset,s=i.offset,l=r.getNode(),a=i.getNode(),g=e===M;if(!Ve(n)||!Be(l)&&!u(l)||!Be(a)&&!u(a))return!1;if(!t.altKey){if(n.isCollapsed()){const e=l.getParentOrThrow();if(g&&0===o&&null===l.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),t.preventDefault(),!1}else if(!g&&o===l.getTextContentSize()&&null===l.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),t.preventDefault(),!1}}return!1}let h,f;if(l.isBefore(a)?(h=se(l),f=le(a)):(h=se(a),f=le(l)),null==h||null==f)return!1;const p=h.getNodesBetween(f);for(let e=0;e<p.length;e++){const t=p[e];if(!Be(t)&&!u(t)&&!c(t))return!1}t.preventDefault(),t.stopPropagation();const d=g?h.getPreviousSibling():f.getNextSibling();if(!c(d))return!0;const m=g?d.getPreviousSibling():d.getNextSibling();if(null==m)return!0;const x=Be(m)||u(m)||c(m)?g?se(m):le(m):null;let _=null!=x?x:m;return d.remove(),p.forEach(e=>e.remove()),e===M?(p.forEach(e=>_.insertBefore(e)),_.insertBefore(d)):(_.insertAfter(d),_=d,p.forEach(e=>{_.insertAfter(e),_=e})),n.setTextNodeRange(l,o,a,s),!0}function Ye(e,t){const n=H();if(!D(n))return!1;const{anchor:r,focus:i}=n,o=r.getNode(),s=i.getNode(),l=e===W;if(!Ve(n)||!Be(o)&&!u(o)||!Be(s)&&!u(s))return!1;const a=s,g="rtl"===ue(a)?!l:l,h=r.key,f=r.offset,p=r.type;if(g){const e=ce(a,i.offset);if(null!==e){const{node:t,offset:r}=e;c(t)?t.selectNext(0,0):n.setTextNodeRange(t,r,t,r)}else a.getParentOrThrow().selectStart()}else{ae(a).select()}return t.shiftKey&&n.anchor.set(h,f,p),t.preventDefault(),t.stopPropagation(),!0}function Ze(e,t,n){return $(...n?[e.registerCommand(E,e=>!e.altKey&&ne(ve,e),k),e.registerCommand(F,e=>ne(ve,e),k),e.registerCommand(M,e=>!e.altKey&&re(ve,e),k),e.registerCommand(J,e=>re(ve,e),k)]:[],e.registerCommand(z,t=>{const n=function(e){const t=H();if(!D(t)||!Ve(t))return null;const n=e?R:j,r=e?R:K,i=t.anchor,o=t.focus;if(i.is(o))return r;const s=Ge(t);if(1!==s.length)return n;const l=s[0];let u,c;0===l.length&&ie(285),t.isBackward()?(u=o,c=i):(u=i,c=o);const a=se(l[0]),g=le(l[0]),h=U(a.getKey(),0,"text"),f=U(g.getKey(),g.getTextContentSize(),"text");return u.isBefore(h)||f.isBefore(c)?n:h.isBefore(u)||c.isBefore(f)?r:n}(t.shiftKey);return null!==n&&(t.preventDefault(),e.dispatchCommand(n,void 0),!0)},k),e.registerCommand(K,()=>!!Ve(H())&&(I([g()]),!0),k),e.registerCommand(j,()=>Qe(j),k),e.registerCommand(R,()=>Qe(R,t),k),e.registerCommand(M,e=>{const t=H();if(!D(t))return!1;const{anchor:n}=t,r=n.getNode();if(!Ve(t))return!1;const i=r.getParent();return t.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&ve(i)&&null===i.getPreviousSibling()?(e.preventDefault(),!0):Xe(M,e)},k),e.registerCommand(E,e=>{const t=H();if(!D(t))return!1;const{anchor:n}=t,r=n.getNode();return!!Ve(t)&&(t.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&ve(r.getParentOrThrow())&&null===r.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):Xe(E,e))},k),e.registerCommand(W,e=>Ye(W,e),k),e.registerCommand(q,e=>Ye(q,e),k))}const et=/* @__PURE__ */P({build:(e,t)=>te(t),config:/* @__PURE__ */L({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[qe],name:"@lexical/code-indent",register:(e,t,n)=>{const r=n.getOutput();return ee(()=>{if(!r.disabled.value)return Ze(e,r.tabSize.value,r.escapeWithArrows.value)})}});export{ke as $createCodeHighlightNode,be as $createCodeNode,ue as $getCodeLineDirection,ae as $getEndOfCodeInLine,se as $getFirstCodeNodeOfLine,le as $getLastCodeNodeOfLine,ce as $getStartOfCodeInLine,Be as $isCodeHighlightNode,ve as $isCodeNode,he as $outdentLeadingSpaces,ge as $plainifyCodeContent,qe as CodeExtension,He as CodeHighlightNode,Ue as CodeImportExtension,We as CodeImportRules,et as CodeIndentExtension,ye as CodeNode,fe as DEFAULT_CODE_LANGUAGE,pe as getDefaultCodeLanguage,Ze as registerCodeIndentation};
|
|
9
|
+
import{defineImportRule as e,sel as t,ImportOverlays 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 h,$getSiblingCaret as f,$create as p,ElementNode as d,addClassNamesToElement as m,setDOMStyleFromCSS as x,$getEditor as _,$isTextNode as S,$createParagraphNode as y,isHTMLElement as b,$applyNodeReplacement as v,TextNode as C,removeClassNamesFromElement as N,isDOMDocumentNode as T,isDOMTextNode as A,$generateNodesFromRawText as O,defineExtension as P,mergeRegister as w,KEY_ENTER_COMMAND as H,$getSelection as D,$isRangeSelection as k,COMMAND_PRIORITY_LOW as B,TabNode as F,configExtension as L,safeCast as $,KEY_ARROW_DOWN_COMMAND as E,KEY_ARROW_RIGHT_COMMAND as M,KEY_ARROW_UP_COMMAND as J,KEY_ARROW_LEFT_COMMAND as z,KEY_TAB_COMMAND as K,INSERT_TAB_COMMAND as I,$insertNodes as j,INDENT_CONTENT_COMMAND as R,OUTDENT_CONTENT_COMMAND as W,MOVE_TO_START as q,MOVE_TO_END as U,$createPoint as V,$setSelectionFromCaretRange as G,$getCaretRangeInDirection as Q,$getCaretRange as X,$getTextPointCaret as Y,$normalizeCaret as Z}from"lexical";import{getPeerDependencyFromEditor as ee,effect as te,namedSignals as ne}from"@lexical/extension";import{$onEscapeDown as re,$onEscapeUp as ie}from"@lexical/utils";
|
|
10
|
+
/*@__INLINE__*/function oe(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function se(e,t){let n=e;for(let r=f(e,t);r&&(Fe(r.origin)||u(r.origin));r=r.getAdjacentCaret())n=r.origin;return n}function le(e){return se(e,"previous")}function ue(e){return se(e,"next")}function ce(e){const t=le(e),n=ue(e);let r=t;for(;null!==r;){if(Fe(r)){const e=s(r.getTextContent());if(null!==e)return e}if(r===n)break;r=r.getNextSibling()}const i=t.getParent();if(l(i)){const e=i.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function ae(e,t){let n=null,r=null,i=e,o=t,s=e.getTextContent();for(;;){if(0===o){const e=i.getPreviousSibling();if(null===e){i=null;break}if(Fe(e)||u(e)||c(e)||oe(167),i=e,c(i)){n={node:i,offset:1};break}o=Math.max(0,i.getTextContentSize()-1),s=i.getTextContent()}else o--;const e=s[o];Fe(i)&&" "!==e&&(r={node:i,offset:o})}if(null!==r)return r;let l=null;if(t<e.getTextContentSize())Fe(e)&&(l=e.getTextContent()[t]);else{const t=e.getNextSibling();Fe(t)&&(l=t.getTextContent()[0])}if(null!==l&&" "!==l)return n;{const r=function(e,t){let n=e,r=t,i=e.getTextContent(),o=e.getTextContentSize();for(;;){if(!Fe(n)||r===o){if(n=n.getNextSibling(),null===n||c(n))return null;Fe(n)&&(r=0,i=n.getTextContent(),o=n.getTextContentSize())}if(Fe(n)){if(" "!==i[r])return{node:n,offset:r};r++}}}(e,t);return null!==r?r:n}}function ge(e){const t=ue(e);return c(t)&&oe(168),t}function he(e){const t=[];return a(e,{linebreak:()=>t.push(h()),tab:()=>t.push(g()),text:e=>t.push(Be(e))}),t}function fe(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.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 e.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 pe="javascript",de=()=>pe;function me(e,t){for(const n of e.childNodes){if(b(n)&&n.tagName===t)return!0;if(me(n,t))return!0}return!1}const xe="data-language",_e="data-highlight-language",Se="data-theme",ye=()=>{};class be extends d{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new be(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(e){const t=document.createElement("code");m(t,e.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(xe,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(_e,n));const r=this.getTheme();r&&t.setAttribute(Se,r);const i=this.getStyle();return i&&x(t.style,i),t}updateDOM(e,t,n){const r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(xe,r):i&&t.removeAttribute(xe);const o=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&t.setAttribute(_e,r):t.removeAttribute(_e):o&&r&&t.setAttribute(_e,r);const s=this.__theme,l=e.__theme;s?s!==l&&t.setAttribute(Se,s):l&&t.removeAttribute(Se);const u=this.__style,c=e.__style;return u!==c&&x(t.style,u,c),!1}exportDOM(e){const t=document.createElement("pre");m(t,e._config.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(xe,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(_e,n));const r=this.getTheme();r&&t.setAttribute(Se,r);const i=this.getStyle();return i&&x(t.style,i),{element:t}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||me(e,"BR"))?{conversion:Ne,priority:1}:null,div:()=>({conversion:Te,priority:1}),pre:()=>({conversion:Ne,priority:0}),table:e=>we(e)?{conversion:Ae,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&we(n)?{conversion:Oe,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&we(t)?{conversion:Oe,priority:3}:null}}}static importJSON(e){return ve().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,t=!0){if(!ee(_(),"@lexical/code")){ye();const t=He(e);if(t)return t}const{anchor:n,focus:r}=e,i=(n.isBefore(r)?n:r).getNode();if(S(i)){let e=le(i);const t=[];for(;;)if(u(e))t.push(g()),e=e.getNextSibling();else{if(!Fe(e))break;{let n=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&t.push(Be(" ".repeat(n))),n!==i)break;e=e.getNextSibling()}}const r=i.splitText(n.offset)[0],o=0===n.offset?0:1,s=r.getIndexWithinParent()+o,l=i.getParentOrThrow(),c=[h(),...t];l.splice(s,0,c);const a=t[t.length-1];a?a.select():0===n.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(Ce(i)){const{offset:t}=e.anchor;i.splice(t,0,[h()]),i.select(t+1,t+1)}return null}canIndent(){return!1}collapseAtStart(){const e=y();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 ve(e,t){return p(be).setLanguage(e).setTheme(t)}function Ce(e){return e instanceof be}function Ne(e){return{node:ve(e.getAttribute(xe))}}function Te(e){const t=e,n=Pe(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(Pe(t))return!0;t=t.parentElement}return!1}(t)?{node:n?ve():null}:{node:null}}function Ae(){return{node:ve()}}function Oe(){return{node:null}}function Pe(e){return null!==e.style.fontFamily.match("monospace")}function we(e){return e.classList.contains("js-file-line-container")}function He(e){const{anchor:t}=e;if(e.isCollapsed()&&"element"===t.type){const e=t.getNode();if(Ce(e)){const n=e.getChildrenSize();if(n>=2&&t.offset===n){const t=e.getLastChild();if(c(t)&&c(t.getPreviousSibling())){const t=y();return e.splice(n-2,2,[]).insertAfter(t,!1),t.select(),t}}}}return null}class De extends C{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new De(e.__text,e.__highlightType||void 0,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const t=super.createDOM(e),n=ke(e.theme,this.__highlightType);return m(t,n),t}updateDOM(e,t,n){const r=super.updateDOM(e,t,n),i=ke(n.theme,e.__highlightType),o=ke(n.theme,this.__highlightType);return i!==o&&(i&&N(t,i),o&&m(t,o)),r}static importJSON(e){return Be().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 ve()}}function ke(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function Be(e="",t){return v(new De(e,t))}function Fe(e){return e instanceof De}const Le="data-language";function $e(e){return null!==e.style.fontFamily.match("monospace")}function Ee(e){let t=e.parentElement;for(;null!==t;){if($e(t))return!0;t=t.parentElement}return!1}const Me=/* @__PURE__ */r([/* @__PURE__ */e({$import:(e,t)=>e.$importChildren(t),match:t.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),Je=/* @__PURE__ */e({$import:(e,t)=>[ve(t.getAttribute(Le)).splice(0,0,e.$importChildren(t))],match:t.tag("pre"),name:"@lexical/code/pre"}),ze=/* @__PURE__ */e({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[ve(t.getAttribute(Le)).splice(0,0,e.$importChildren(t))]:n()},match:t.tag("code"),name:"@lexical/code/code-multiline"});function Ke(e){if(!b(e))return!1;const t=e.style.fontFamily,n=e.style.whiteSpace;return"string"==typeof t&&/monospace/i.test(t)&&"string"==typeof n&&n.startsWith("pre")}function Ie(e){let t=!1;const n=[];let r="",i=!1;const o=()=>{i&&(n.push(r),r="",i=!1)};for(const s of Array.from(e.childNodes))if(b(s))"DIV"===s.tagName?(o(),n.push(s.textContent||""),t=!0):"BR"===s.tagName?(o(),n.push(""),t=!0):(r+=s.textContent||"",i=!0);else if(A(s)){const e=s.textContent||"";e.length>0&&(r+=e,i=!0)}return o(),t?n:null}function je(e){for(const t of Array.from(e.children)){if(b(t)&&Ke(t)){if(null!==Ie(t))return!0;const e=t.nextElementSibling;if(e&&Ke(e))return!0;continue}if(je(t))return!0}return!1}const Re=/* @__PURE__ */r([/* @__PURE__ */e({$import:(e,t,n)=>{if(!Ke(t)||Ee(t))return n();const r=Ie(t);return null===r||0===r.length?n():[ve().splice(0,0,O(r.join("\n")))]},match:t.tag("div"),name:"@lexical/code/vscode-wrapper"}),/* @__PURE__ */e({$import:(e,t,n)=>{if(!Ke(t)||Ee(t))return n();const r=t.previousElementSibling;if(r&&Ke(r))return[];const i=[];let o=t;for(;o&&Ke(o);)i.push("BR"===o.tagName?"":o.textContent||""),o=o.nextElementSibling;return i.length<2?n():[ve().splice(0,0,O(i.join("\n")))]},match:t.tag("div","br"),name:"@lexical/code/vscode-line-run"})]),We=/* @__PURE__ */e({$import:(e,t,n)=>$e(t)?[ve().splice(0,0,e.$importChildren(t))]:Ee(t)?e.$importChildren(t):n(),match:t.tag("div"),name:"@lexical/code/div"}),qe=[/* @__PURE__ */e({$import:(e,t)=>[ve().splice(0,0,e.$importChildren(t,{rules:Me}))],match:t.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),/* @__PURE__ */e({$import:(e,t)=>e.$importChildren(t),match:t.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),ze,Je,We],Ue=/* @__PURE__ */P({dependencies:[i,/* @__PURE__ */L(o,{preprocess:[(e,t,r)=>{je(T(e)?e.body:e)&&t.session.update(n,e=>[...e,Re]),r()}],rules:qe})],name:"@lexical/code",nodes:()=>[be,De],register:e=>w(e.registerCommand(H,e=>{const t=D();return!(!k(t)||!He(t))&&(e.preventDefault(),!0)},B),e.registerNodeTransform(F,e=>{0!==e.getFormat()&&Ce(e.getParent())&&e.setFormat(0)}))}),Ve=/* @__PURE__ */P({dependencies:[Ue],name:"@lexical/code/Import"});function Ge(e){if(!k(e))return!1;const t=e.anchor.getNode(),n=Ce(t)?t:t.getParent(),r=e.focus.getNode(),i=Ce(r)?r:r.getParent();return Ce(n)&&n.is(i)}function Qe(e){const t=e.getNodes(),n=[];if(1===t.length&&Ce(t[0]))return n;let r=[];for(let e=0;e<t.length;e++){const i=t[e];Fe(i)||u(i)||c(i)||oe(169),c(i)?r.length>0&&(n.push(r),r=[]):r.push(i)}if(r.length>0){const t=e.isBackward()?e.anchor:e.focus,i=V(r[0].getKey(),0,"text");t.is(i)||n.push(r)}return n}function Xe(e,t){const n=D();if(!k(n)||!Ge(n))return!1;const r=Qe(n),i=r.length;if(0===i&&n.isCollapsed())return e===R&&n.insertNodes([g()]),!0;if(0===i&&e===R&&"\n"===n.getTextContent()){const e=g(),t=h(),r=n.isBackward()?"previous":"next";return n.insertNodes([e,t]),G(Q(X(Y(e,"next",0),Z(f(t,"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=le(r)),e===R){const e=g();if(r.insertBefore(e),0===o){const t=n.isBackward()?"focus":"anchor",i=V(r.getKey(),0,"text");n[t].is(i)&&n[t].set(e.getKey(),0,"text")}}else u(r)?r.remove():void 0!==t&&Fe(r)&&fe(r,t,n)}}return!0}function Ye(e,t){const n=D();if(!k(n))return!1;const{anchor:r,focus:i}=n,o=r.offset,s=i.offset,l=r.getNode(),a=i.getNode(),g=e===J;if(!Ge(n)||!Fe(l)&&!u(l)||!Fe(a)&&!u(a))return!1;if(!t.altKey){if(n.isCollapsed()){const e=l.getParentOrThrow();if(g&&0===o&&null===l.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),t.preventDefault(),!1}else if(!g&&o===l.getTextContentSize()&&null===l.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),t.preventDefault(),!1}}return!1}let h,f;if(l.isBefore(a)?(h=le(l),f=ue(a)):(h=le(a),f=ue(l)),null==h||null==f)return!1;const p=h.getNodesBetween(f);for(let e=0;e<p.length;e++){const t=p[e];if(!Fe(t)&&!u(t)&&!c(t))return!1}t.preventDefault(),t.stopPropagation();const d=g?h.getPreviousSibling():f.getNextSibling();if(!c(d))return!0;const m=g?d.getPreviousSibling():d.getNextSibling();if(null==m)return!0;const x=Fe(m)||u(m)||c(m)?g?le(m):ue(m):null;let _=null!=x?x:m;return d.remove(),p.forEach(e=>e.remove()),e===J?(p.forEach(e=>_.insertBefore(e)),_.insertBefore(d)):(_.insertAfter(d),_=d,p.forEach(e=>{_.insertAfter(e),_=e})),n.setTextNodeRange(l,o,a,s),!0}function Ze(e,t){const n=D();if(!k(n))return!1;const{anchor:r,focus:i}=n,o=r.getNode(),s=i.getNode(),l=e===q;if(!Ge(n)||!Fe(o)&&!u(o)||!Fe(s)&&!u(s))return!1;const a=s,g="rtl"===ce(a)?!l:l,h=r.key,f=r.offset,p=r.type;if(g){const e=ae(a,i.offset);if(null!==e){const{node:t,offset:r}=e;c(t)?t.selectNext(0,0):n.setTextNodeRange(t,r,t,r)}else a.getParentOrThrow().selectStart()}else{ge(a).select()}return t.shiftKey&&n.anchor.set(h,f,p),t.preventDefault(),t.stopPropagation(),!0}function et(e,t,n){return w(...n?[e.registerCommand(E,e=>!e.altKey&&re(Ce,e),B),e.registerCommand(M,e=>re(Ce,e),B),e.registerCommand(J,e=>!e.altKey&&ie(Ce,e),B),e.registerCommand(z,e=>ie(Ce,e),B)]:[],e.registerCommand(K,t=>{const n=function(e){const t=D();if(!k(t)||!Ge(t))return null;const n=e?W:R,r=e?W:I,i=t.anchor,o=t.focus;if(i.is(o))return r;const s=Qe(t);if(1!==s.length)return n;const l=s[0];let u,c;0===l.length&&oe(285),t.isBackward()?(u=o,c=i):(u=i,c=o);const a=le(l[0]),g=ue(l[0]),h=V(a.getKey(),0,"text"),f=V(g.getKey(),g.getTextContentSize(),"text");return u.isBefore(h)||f.isBefore(c)?n:h.isBefore(u)||c.isBefore(f)?r:n}(t.shiftKey);return null!==n&&(t.preventDefault(),e.dispatchCommand(n,void 0),!0)},B),e.registerCommand(I,()=>!!Ge(D())&&(j([g()]),!0),B),e.registerCommand(R,()=>Xe(R),B),e.registerCommand(W,()=>Xe(W,t),B),e.registerCommand(J,e=>{const t=D();if(!k(t))return!1;const{anchor:n}=t,r=n.getNode();if(!Ge(t))return!1;const i=r.getParent();return t.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&Ce(i)&&null===i.getPreviousSibling()?(e.preventDefault(),!0):Ye(J,e)},B),e.registerCommand(E,e=>{const t=D();if(!k(t))return!1;const{anchor:n}=t,r=n.getNode();return!!Ge(t)&&(t.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&Ce(r.getParentOrThrow())&&null===r.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):Ye(E,e))},B),e.registerCommand(q,e=>Ze(q,e),B),e.registerCommand(U,e=>Ze(U,e),B))}const tt=/* @__PURE__ */P({build:(e,t)=>ne(t),config:/* @__PURE__ */$({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[Ue],name:"@lexical/code-indent",register:(e,t,n)=>{const r=n.getOutput();return te(()=>{if(!r.disabled.value)return et(e,r.tabSize.value,r.escapeWithArrows.value)})}});export{Be as $createCodeHighlightNode,ve as $createCodeNode,ce as $getCodeLineDirection,ge as $getEndOfCodeInLine,le as $getFirstCodeNodeOfLine,ue as $getLastCodeNodeOfLine,ae as $getStartOfCodeInLine,Fe as $isCodeHighlightNode,Ce as $isCodeNode,fe as $outdentLeadingSpaces,he as $plainifyCodeContent,Ue as CodeExtension,De as CodeHighlightNode,Ve as CodeImportExtension,qe as CodeImportRules,tt as CodeIndentExtension,be as CodeNode,pe as DEFAULT_CODE_LANGUAGE,de as getDefaultCodeLanguage,et as registerCodeIndentation};
|
package/package.json
CHANGED
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
"code"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.46.0",
|
|
11
|
+
"version": "0.46.1-nightly.20260629.0",
|
|
12
12
|
"main": "./dist/LexicalCodeCore.js",
|
|
13
13
|
"types": "./dist/typescript-too-old.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/
|
|
16
|
-
"@lexical/
|
|
17
|
-
"@lexical/
|
|
18
|
-
"@lexical/
|
|
19
|
-
"lexical": "0.46.0"
|
|
15
|
+
"@lexical/html": "0.46.1-nightly.20260629.0",
|
|
16
|
+
"@lexical/extension": "0.46.1-nightly.20260629.0",
|
|
17
|
+
"@lexical/internal": "0.46.1-nightly.20260629.0",
|
|
18
|
+
"@lexical/utils": "0.46.1-nightly.20260629.0",
|
|
19
|
+
"lexical": "0.46.1-nightly.20260629.0"
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
package/src/CodeExtension.ts
CHANGED
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
configExtension,
|
|
15
15
|
defineExtension,
|
|
16
16
|
KEY_ENTER_COMMAND,
|
|
17
|
+
mergeRegister,
|
|
18
|
+
TabNode,
|
|
17
19
|
} from 'lexical';
|
|
18
20
|
|
|
19
21
|
import {CodeHighlightNode} from './CodeHighlightNode';
|
|
@@ -21,7 +23,7 @@ import {
|
|
|
21
23
|
$installVscodeCodePasteOverlay,
|
|
22
24
|
CodeImportRules,
|
|
23
25
|
} from './CodeImportExtension';
|
|
24
|
-
import {$exitCodeNodeOnEnter, CodeNode} from './CodeNode';
|
|
26
|
+
import {$exitCodeNodeOnEnter, $isCodeNode, CodeNode} from './CodeNode';
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
29
|
* Add code blocks to the editor (syntax highlighting provided separately)
|
|
@@ -40,17 +42,24 @@ export const CodeExtension = /* @__PURE__ */ defineExtension({
|
|
|
40
42
|
name: '@lexical/code',
|
|
41
43
|
nodes: () => [CodeNode, CodeHighlightNode],
|
|
42
44
|
register(editor) {
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
return mergeRegister(
|
|
46
|
+
editor.registerCommand<KeyboardEvent>(
|
|
47
|
+
KEY_ENTER_COMMAND,
|
|
48
|
+
event => {
|
|
49
|
+
const selection = $getSelection();
|
|
50
|
+
if ($isRangeSelection(selection) && $exitCodeNodeOnEnter(selection)) {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
},
|
|
56
|
+
COMMAND_PRIORITY_LOW,
|
|
57
|
+
),
|
|
58
|
+
editor.registerNodeTransform(TabNode, node => {
|
|
59
|
+
if (node.getFormat() !== 0 && $isCodeNode(node.getParent())) {
|
|
60
|
+
node.setFormat(0);
|
|
50
61
|
}
|
|
51
|
-
|
|
52
|
-
},
|
|
53
|
-
COMMAND_PRIORITY_LOW,
|
|
62
|
+
}),
|
|
54
63
|
);
|
|
55
64
|
},
|
|
56
65
|
});
|