@lexical/code 0.38.3-nightly.20251103.0 → 0.38.3-nightly.20251104.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.
- package/LexicalCode.dev.js +5 -4
- package/LexicalCode.dev.mjs +5 -4
- package/LexicalCode.prod.js +1 -1
- package/LexicalCode.prod.mjs +1 -1
- package/package.json +3 -3
package/LexicalCode.dev.js
CHANGED
|
@@ -680,7 +680,7 @@ function $getEndOfCodeInLine(anchor) {
|
|
|
680
680
|
*/
|
|
681
681
|
const CodeExtension = lexical.defineExtension({
|
|
682
682
|
name: '@lexical/code',
|
|
683
|
-
nodes: [CodeNode, CodeHighlightNode]
|
|
683
|
+
nodes: () => [CodeNode, CodeHighlightNode]
|
|
684
684
|
});
|
|
685
685
|
|
|
686
686
|
(function (Prism) {
|
|
@@ -1013,6 +1013,7 @@ function updateCodeGutter(node, editor) {
|
|
|
1013
1013
|
const nodesCurrentlyHighlighting = new Set();
|
|
1014
1014
|
function codeNodeTransform(node, editor, tokenizer) {
|
|
1015
1015
|
const nodeKey = node.getKey();
|
|
1016
|
+
const cacheKey = editor.getKey() + '/' + nodeKey;
|
|
1016
1017
|
|
|
1017
1018
|
// When new code block inserted it might not have language selected
|
|
1018
1019
|
if (node.getLanguage() === undefined) {
|
|
@@ -1030,10 +1031,10 @@ function codeNodeTransform(node, editor, tokenizer) {
|
|
|
1030
1031
|
loadCodeLanguage(language, editor, nodeKey);
|
|
1031
1032
|
return;
|
|
1032
1033
|
}
|
|
1033
|
-
if (nodesCurrentlyHighlighting.has(
|
|
1034
|
+
if (nodesCurrentlyHighlighting.has(cacheKey)) {
|
|
1034
1035
|
return;
|
|
1035
1036
|
}
|
|
1036
|
-
nodesCurrentlyHighlighting.add(
|
|
1037
|
+
nodesCurrentlyHighlighting.add(cacheKey);
|
|
1037
1038
|
|
|
1038
1039
|
// Using nested update call to pass `skipTransforms` since we don't want
|
|
1039
1040
|
// each individual CodeHighlightNode to be transformed again as it's already
|
|
@@ -1063,7 +1064,7 @@ function codeNodeTransform(node, editor, tokenizer) {
|
|
|
1063
1064
|
});
|
|
1064
1065
|
}, {
|
|
1065
1066
|
onUpdate: () => {
|
|
1066
|
-
nodesCurrentlyHighlighting.delete(
|
|
1067
|
+
nodesCurrentlyHighlighting.delete(cacheKey);
|
|
1067
1068
|
},
|
|
1068
1069
|
skipTransforms: true
|
|
1069
1070
|
});
|
package/LexicalCode.dev.mjs
CHANGED
|
@@ -678,7 +678,7 @@ function $getEndOfCodeInLine(anchor) {
|
|
|
678
678
|
*/
|
|
679
679
|
const CodeExtension = defineExtension({
|
|
680
680
|
name: '@lexical/code',
|
|
681
|
-
nodes: [CodeNode, CodeHighlightNode]
|
|
681
|
+
nodes: () => [CodeNode, CodeHighlightNode]
|
|
682
682
|
});
|
|
683
683
|
|
|
684
684
|
(function (Prism) {
|
|
@@ -1011,6 +1011,7 @@ function updateCodeGutter(node, editor) {
|
|
|
1011
1011
|
const nodesCurrentlyHighlighting = new Set();
|
|
1012
1012
|
function codeNodeTransform(node, editor, tokenizer) {
|
|
1013
1013
|
const nodeKey = node.getKey();
|
|
1014
|
+
const cacheKey = editor.getKey() + '/' + nodeKey;
|
|
1014
1015
|
|
|
1015
1016
|
// When new code block inserted it might not have language selected
|
|
1016
1017
|
if (node.getLanguage() === undefined) {
|
|
@@ -1028,10 +1029,10 @@ function codeNodeTransform(node, editor, tokenizer) {
|
|
|
1028
1029
|
loadCodeLanguage(language, editor, nodeKey);
|
|
1029
1030
|
return;
|
|
1030
1031
|
}
|
|
1031
|
-
if (nodesCurrentlyHighlighting.has(
|
|
1032
|
+
if (nodesCurrentlyHighlighting.has(cacheKey)) {
|
|
1032
1033
|
return;
|
|
1033
1034
|
}
|
|
1034
|
-
nodesCurrentlyHighlighting.add(
|
|
1035
|
+
nodesCurrentlyHighlighting.add(cacheKey);
|
|
1035
1036
|
|
|
1036
1037
|
// Using nested update call to pass `skipTransforms` since we don't want
|
|
1037
1038
|
// each individual CodeHighlightNode to be transformed again as it's already
|
|
@@ -1061,7 +1062,7 @@ function codeNodeTransform(node, editor, tokenizer) {
|
|
|
1061
1062
|
});
|
|
1062
1063
|
}, {
|
|
1063
1064
|
onUpdate: () => {
|
|
1064
|
-
nodesCurrentlyHighlighting.delete(
|
|
1065
|
+
nodesCurrentlyHighlighting.delete(cacheKey);
|
|
1065
1066
|
},
|
|
1066
1067
|
skipTransforms: true
|
|
1067
1068
|
});
|
package/LexicalCode.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/utils"),t=require("lexical");function n(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}require("prismjs"),require("prismjs/components/prism-clike"),require("prismjs/components/prism-javascript"),require("prismjs/components/prism-markup"),require("prismjs/components/prism-markdown"),require("prismjs/components/prism-c"),require("prismjs/components/prism-css"),require("prismjs/components/prism-objectivec"),require("prismjs/components/prism-sql"),require("prismjs/components/prism-powershell"),require("prismjs/components/prism-python"),require("prismjs/components/prism-rust"),require("prismjs/components/prism-swift"),require("prismjs/components/prism-typescript"),require("prismjs/components/prism-java"),require("prismjs/components/prism-cpp");const r="javascript";function i(t,n){for(const r of t.childNodes){if(e.isHTMLElement(r)&&r.tagName===n)return!0;i(r,n)}return!1}const o="data-language",s="data-highlight-language",a="data-theme";class l extends t.ElementNode{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new l(e.__language,e.__key)}constructor(e,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(t){const n=document.createElement("code");e.addClassNamesToElement(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(o,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(s,r));const i=this.getTheme();i&&n.setAttribute(a,i);const l=this.getStyle();return l&&n.setAttribute("style",l),n}updateDOM(e,t,n){const r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(o,r):i&&t.removeAttribute(o);const l=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?l&&r?r!==i&&t.setAttribute(s,r):t.removeAttribute(s):l&&r&&t.setAttribute(s,r);const g=this.__theme,c=e.__theme;g?g!==c&&t.setAttribute(a,g):c&&t.removeAttribute(a);const u=this.__style,d=e.__style;return u?u!==d&&t.setAttribute("style",u):d&&t.removeAttribute("style"),!1}exportDOM(t){const n=document.createElement("pre");e.addClassNamesToElement(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(o,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(s,r));const i=this.getTheme();i&&n.setAttribute(a,i);const l=this.getStyle();return l&&n.setAttribute("style",l),{element:n}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||i(e,"BR"))?{conversion:u,priority:1}:null,div:()=>({conversion:d,priority:1}),pre:()=>({conversion:u,priority:0}),table:e=>N(e)?{conversion:p,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&N(n)?{conversion:f,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&N(t)?{conversion:f,priority:3}:null}}}static importJSON(e){return g().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(e,n=!0){const r=this.getChildren(),i=r.length;if(i>=2&&"\n"===r[i-1].getTextContent()&&"\n"===r[i-2].getTextContent()&&e.isCollapsed()&&e.anchor.key===this.__key&&e.anchor.offset===i){r[i-1].remove(),r[i-2].remove();const e=t.$createParagraphNode();return this.insertAfter(e,n),e}const{anchor:o,focus:s}=e,a=(o.isBefore(s)?o:s).getNode();if(t.$isTextNode(a)){let e=O(a);const n=[];for(;;)if(t.$isTabNode(e))n.push(t.$createTabNode()),e=e.getNextSibling();else{if(!x(e))break;{let t=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;t<i&&" "===r[t];)t++;if(0!==t&&n.push(T(" ".repeat(t))),t!==i)break;e=e.getNextSibling()}}const r=a.splitText(o.offset)[0],i=0===o.offset?0:1,s=r.getIndexWithinParent()+i,l=a.getParentOrThrow(),g=[t.$createLineBreakNode(),...n];l.splice(s,0,g);const c=n[n.length-1];c?c.select():0===o.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(c(a)){const{offset:n}=e.anchor;a.splice(n,0,[t.$createLineBreakNode()]),a.select(n+1,n+1)}return null}canIndent(){return!1}collapseAtStart(){const e=t.$createParagraphNode();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function g(e,n){return t.$create(l).setLanguage(e).setTheme(n)}function c(e){return e instanceof l}function u(e){return{node:g(e.getAttribute(o))}}function d(e){const t=e,n=h(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(h(t))return!0;t=t.parentElement}return!1}(t)?{node:n?g():null}:{node:null}}function p(){return{node:g()}}function f(){return{node:null}}function h(e){return null!==e.style.fontFamily.match("monospace")}function N(e){return e.classList.contains("js-file-line-container")}class m extends t.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new m(e.__text,e.__highlightType||void 0,e.__key)}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(t){const n=super.createDOM(t),r=_(t.theme,this.__highlightType);return e.addClassNamesToElement(n,r),n}updateDOM(t,n,r){const i=super.updateDOM(t,n,r),o=_(r.theme,t.__highlightType),s=_(r.theme,this.__highlightType);return o!==s&&(o&&e.removeClassNamesFromElement(n,o),s&&e.addClassNamesToElement(n,s)),i}static importJSON(e){return T().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return g()}}function _(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function T(e="",n){return t.$applyNodeReplacement(new m(e,n))}function x(e){return e instanceof m}function C(n,r){let i=n;for(let o=t.$getSiblingCaret(n,r);o&&(x(o.origin)||t.$isTabNode(o.origin));o=e.$getAdjacentCaret(o))i=o.origin;return i}function O(e){return C(e,"previous")}function S(e){return C(e,"next")}function y(e){const n=O(e),r=S(e);let i=n;for(;null!==i;){if(x(i)){const e=t.getTextDirection(i.getTextContent());if(null!==e)return e}if(i===r)break;i=i.getNextSibling()}const o=n.getParent();if(t.$isElementNode(o)){const e=o.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function $(e,r){let i=null,o=null,s=e,a=r,l=e.getTextContent();for(;;){if(0===a){if(s=s.getPreviousSibling(),null===s)break;if(x(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||n(167),t.$isLineBreakNode(s)){i={node:s,offset:1};break}a=Math.max(0,s.getTextContentSize()-1),l=s.getTextContent()}else a--;const e=l[a];x(s)&&" "!==e&&(o={node:s,offset:a})}if(null!==o)return o;let g=null;if(r<e.getTextContentSize())x(e)&&(g=e.getTextContent()[r]);else{const t=e.getNextSibling();x(t)&&(g=t.getTextContent()[0])}if(null!==g&&" "!==g)return i;{const n=function(e,n){let r=e,i=n,o=e.getTextContent(),s=e.getTextContentSize();for(;;){if(!x(r)||i===s){if(r=r.getNextSibling(),null===r||t.$isLineBreakNode(r))return null;x(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(x(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(e,r);return null!==n?n:i}}function A(e){const r=S(e);return t.$isLineBreakNode(r)&&n(168),r}const b=t.defineExtension({name:"@lexical/code",nodes:[l,m]});!function(e){e.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var t={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(t).forEach(function(n){var r=t[n],i=[];/^\w+$/.test(n)||i.push(/\w+/.exec(n)[0]),"diff"===n&&i.push("bold"),e.languages.diff[n]={pattern:RegExp("^(?:["+r+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}}),Object.defineProperty(e.languages.diff,"PREFIXES",{value:t})}(Prism);const L=globalThis.Prism||window.Prism,M={c:"C",clike:"C-like",cpp:"C++",css:"CSS",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},E={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function v(e){return E[e]||e}function D(e){return"string"==typeof e?e:Array.isArray(e)?e.map(D).join(""):D(e.content)}function k(e,t){const n=/^diff-([\w-]+)/i.exec(t),r=e.getTextContent();let i=L.tokenize(r,L.languages[n?"diff":t]);return n&&(i=function(e,t){const n=t,r=L.languages[n],i={tokens:e},o=L.languages.diff.PREFIXES;for(const e of i.tokens){if("string"==typeof e||!(e.type in o)||!Array.isArray(e.content))continue;const t=e.type;let n=0;const i=()=>(n++,new L.Token("prefix",o[t],t.replace(/^(\w+).*/,"$1"))),s=e.content.filter(e=>"string"==typeof e||"prefix"!==e.type),a=e.content.length-s.length,l=L.tokenize(D(s),r);l.unshift(i());const g=/\r\n|\n/g,c=e=>{const t=[];g.lastIndex=0;let r,o=0;for(;n<a&&(r=g.exec(e));){const n=r.index+r[0].length;t.push(e.slice(o,n)),o=n,t.push(i())}if(0!==t.length)return o<e.length&&t.push(e.slice(o)),t},u=e=>{for(let t=0;t<e.length&&n<a;t++){const n=e[t];if("string"==typeof n){const r=c(n);r&&(e.splice(t,1,...r),t+=r.length-1)}else if("string"==typeof n.content){const e=c(n.content);e&&(n.content=e)}else Array.isArray(n.content)?u(n.content):u([n.content])}};u(l),n<a&&l.push(i()),e.content=l}return i.tokens}(i,n[1])),R(i)}function R(e,n){const r=[];for(const i of e)if("string"==typeof i){const e=i.split(/(\n|\t)/),o=e.length;for(let i=0;i<o;i++){const o=e[i];"\n"===o||"\r\n"===o?r.push(t.$createLineBreakNode()):"\t"===o?r.push(t.$createTabNode()):o.length>0&&r.push(T(o,n))}}else{const{content:e,alias:t}=i;"string"==typeof e?r.push(...R([e],"prefix"===i.type&&"string"==typeof t?t:i.type)):Array.isArray(e)&&r.push(...R(e,"unchanged"===i.type?void 0:i.type))}return r}const P={$tokenize(e,t){return k(e,t||this.defaultLanguage)},defaultLanguage:r,tokenize(e,t){return L.tokenize(e,L.languages[t||""]||L.languages[this.defaultLanguage])}};function I(e,n,r){const i=e.getParent();c(i)?j(i,n,r):x(e)&&e.replace(t.$createTextNode(e.__text))}function w(e,n){const r=n.getElementByKey(e.getKey());if(null===r)return;const i=e.getChildren(),o=i.length;if(o===r.__cachedChildrenLength)return;r.__cachedChildrenLength=o;let s="1",a=1;for(let e=0;e<o;e++)t.$isLineBreakNode(i[e])&&(s+="\n"+ ++a);r.setAttribute("data-gutter",s)}const B=new Set;function j(e,n,r){const i=e.getKey();void 0===e.getLanguage()&&e.setLanguage(r.defaultLanguage);const o=e.getLanguage()||r.defaultLanguage;if(!function(e){const t=function(e){const t=/^diff-([\w-]+)/i.exec(e);return t?t[1]:null}(e),n=t||e;try{return!!n&&L.languages.hasOwnProperty(n)}catch(e){return!1}}(o))return e.getIsSyntaxHighlightSupported()&&e.setIsSyntaxHighlightSupported(!1),void async function(){}();e.getIsSyntaxHighlightSupported()||e.setIsSyntaxHighlightSupported(!0),B.has(i)||(B.add(i),n.update(()=>{!function(e,n){const r=t.$getNodeByKey(e);if(!c(r)||!r.isAttached())return;const i=t.$getSelection();if(!t.$isRangeSelection(i))return void n();const o=i.anchor,s=o.offset,a="element"===o.type&&t.$isLineBreakNode(r.getChildAtIndex(o.offset-1));let l=0;if(!a){const e=o.getNode();l=s+e.getPreviousSiblings().reduce((e,t)=>e+t.getTextContentSize(),0)}if(!n())return;if(a)return void o.getNode().select(s,s);r.getChildren().some(e=>{const n=t.$isTextNode(e);if(n||t.$isLineBreakNode(e)){const t=e.getTextContentSize();if(n&&t>=l)return e.select(l,l),!0;l-=t}return!1})}(i,()=>{const n=t.$getNodeByKey(i);if(!c(n)||!n.isAttached())return!1;const o=n.getLanguage()||r.defaultLanguage,s=r.$tokenize(n,o),a=function(e,t){let n=0;for(;n<e.length&&H(e[n],t[n]);)n++;const r=e.length,i=t.length,o=Math.min(r,i)-n;let s=0;for(;s<o;)if(s++,!H(e[r-s],t[i-s])){s--;break}const a=n,l=r-s,g=t.slice(n,i-s);return{from:a,nodesForReplacement:g,to:l}}(n.getChildren(),s),{from:l,to:g,nodesForReplacement:u}=a;return!(l===g&&!u.length)&&(e.splice(l,g-l,u),!0)})},{onUpdate:()=>{B.delete(i)},skipTransforms:!0}))}function H(e,n){return x(e)&&x(n)&&e.__text===n.__text&&e.__highlightType===n.__highlightType||t.$isTabNode(e)&&t.$isTabNode(n)||t.$isLineBreakNode(e)&&t.$isLineBreakNode(n)}function F(e){if(!t.$isRangeSelection(e))return!1;const n=e.anchor.getNode(),r=c(n)?n:n.getParent(),i=e.focus.getNode(),o=c(i)?i:i.getParent();return c(r)&&r.is(o)}function q(e){const r=e.getNodes(),i=[];if(1===r.length&&c(r[0]))return i;let o=[];for(let e=0;e<r.length;e++){const s=r[e];x(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||n(169),t.$isLineBreakNode(s)?o.length>0&&(i.push(o),o=[]):o.push(s)}if(o.length>0){const n=e.isBackward()?e.anchor:e.focus,r=t.$createPoint(o[0].getKey(),0,"text");n.is(r)||i.push(o)}return i}function z(e){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!F(n))return!1;const r=q(n),i=r.length;if(0===i&&n.isCollapsed())return e===t.INDENT_CONTENT_COMMAND&&n.insertNodes([t.$createTabNode()]),!0;if(0===i&&e===t.INDENT_CONTENT_COMMAND&&"\n"===n.getTextContent()){const e=t.$createTabNode(),r=t.$createLineBreakNode(),i=n.isBackward()?"previous":"next";return n.insertNodes([e,r]),t.$setSelectionFromCaretRange(t.$getCaretRangeInDirection(t.$getCaretRange(t.$getTextPointCaret(e,"next",0),t.$normalizeCaret(t.$getSiblingCaret(r,"next"))),i)),!0}for(let o=0;o<i;o++){const i=r[o];if(i.length>0){let r=i[0];if(0===o&&(r=O(r)),e===t.INDENT_CONTENT_COMMAND){const e=t.$createTabNode();if(r.insertBefore(e),0===o){const i=n.isBackward()?"focus":"anchor",o=t.$createPoint(r.getKey(),0,"text");n[i].is(o)&&n[i].set(e.getKey(),0,"text")}}else t.$isTabNode(r)&&r.remove()}}return!0}function W(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.offset,a=o.offset,l=i.getNode(),g=o.getNode(),c=e===t.KEY_ARROW_UP_COMMAND;if(!F(r)||!x(l)&&!t.$isTabNode(l)||!x(g)&&!t.$isTabNode(g))return!1;if(!n.altKey){if(r.isCollapsed()){const e=l.getParentOrThrow();if(c&&0===s&&null===l.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),n.preventDefault(),!0}else if(!c&&s===l.getTextContentSize()&&null===l.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),n.preventDefault(),!0}}return!1}let u,d;if(l.isBefore(g)?(u=O(l),d=S(g)):(u=O(g),d=S(l)),null==u||null==d)return!1;const p=u.getNodesBetween(d);for(let e=0;e<p.length;e++){const n=p[e];if(!x(n)&&!t.$isTabNode(n)&&!t.$isLineBreakNode(n))return!1}n.preventDefault(),n.stopPropagation();const f=c?u.getPreviousSibling():d.getNextSibling();if(!t.$isLineBreakNode(f))return!0;const h=c?f.getPreviousSibling():f.getNextSibling();if(null==h)return!0;const N=x(h)||t.$isTabNode(h)||t.$isLineBreakNode(h)?c?O(h):S(h):null;let m=null!=N?N:h;return f.remove(),p.forEach(e=>e.remove()),e===t.KEY_ARROW_UP_COMMAND?(p.forEach(e=>m.insertBefore(e)),m.insertBefore(f)):(m.insertAfter(f),m=f,p.forEach(e=>{m.insertAfter(e),m=e})),r.setTextNodeRange(l,s,g,a),!0}function K(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.getNode(),a=o.getNode(),l=e===t.MOVE_TO_START;if(!F(r)||!x(s)&&!t.$isTabNode(s)||!x(a)&&!t.$isTabNode(a))return!1;const g=a;if("rtl"===y(g)?!l:l){const e=$(g,o.offset);if(null!==e){const{node:n,offset:i}=e;t.$isLineBreakNode(n)?n.selectNext(0,0):r.setTextNodeRange(n,i,n,i)}else g.getParentOrThrow().selectStart()}else{A(g).select()}return n.preventDefault(),n.stopPropagation(),!0}const Y=O,U=S,J=A,G=$;exports.$createCodeHighlightNode=T,exports.$createCodeNode=g,exports.$getCodeLineDirection=y,exports.$getEndOfCodeInLine=A,exports.$getFirstCodeNodeOfLine=O,exports.$getLastCodeNodeOfLine=S,exports.$getStartOfCodeInLine=$,exports.$isCodeHighlightNode=x,exports.$isCodeNode=c,exports.CODE_LANGUAGE_FRIENDLY_NAME_MAP=M,exports.CODE_LANGUAGE_MAP=E,exports.CodeExtension=b,exports.CodeHighlightNode=m,exports.CodeNode=l,exports.DEFAULT_CODE_LANGUAGE=r,exports.PrismTokenizer=P,exports.getCodeLanguageOptions=function(){const e=[];for(const[t,n]of Object.entries(M))e.push([t,n]);return e},exports.getCodeLanguages=()=>Object.keys(L.languages).filter(e=>"function"!=typeof L.languages[e]).sort(),exports.getCodeThemeOptions=function(){return[]},exports.getDefaultCodeLanguage=()=>r,exports.getEndOfCodeInLine=J,exports.getFirstCodeNodeOfLine=Y,exports.getLanguageFriendlyName=function(e){const t=v(e);return M[t]||t},exports.getLastCodeNodeOfLine=U,exports.getStartOfCodeInLine=G,exports.normalizeCodeLang=v,exports.normalizeCodeLanguage=v,exports.registerCodeHighlighting=function(r,i){if(!r.hasNodes([l,m]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");null==i&&(i=P);const o=[];return!0!==r._headless&&o.push(r.registerMutationListener(l,e=>{r.getEditorState().read(()=>{for(const[n,i]of e)if("destroyed"!==i){const e=t.$getNodeByKey(n);null!==e&&w(e,r)}})},{skipInitialization:!1})),o.push(r.registerNodeTransform(l,e=>j(e,r,i)),r.registerNodeTransform(t.TextNode,e=>I(e,r,i)),r.registerNodeTransform(m,e=>I(e,r,i)),r.registerCommand(t.KEY_TAB_COMMAND,e=>{const i=function(e){const r=t.$getSelection();if(!t.$isRangeSelection(r)||!F(r))return null;const i=e?t.OUTDENT_CONTENT_COMMAND:t.INDENT_CONTENT_COMMAND,o=e?t.OUTDENT_CONTENT_COMMAND:t.INSERT_TAB_COMMAND,s=r.anchor,a=r.focus;if(s.is(a))return o;const l=q(r);if(1!==l.length)return i;const g=l[0];let c,u;0===g.length&&n(285),r.isBackward()?(c=a,u=s):(c=s,u=a);const d=O(g[0]),p=S(g[0]),f=t.$createPoint(d.getKey(),0,"text"),h=t.$createPoint(p.getKey(),p.getTextContentSize(),"text");return c.isBefore(f)||h.isBefore(u)?i:f.isBefore(c)||u.isBefore(h)?o:i}(e.shiftKey);return null!==i&&(e.preventDefault(),r.dispatchCommand(i,void 0),!0)},t.COMMAND_PRIORITY_LOW),r.registerCommand(t.INSERT_TAB_COMMAND,()=>!!F(t.$getSelection())&&(t.$insertNodes([t.$createTabNode()]),!0),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.INDENT_CONTENT_COMMAND,e=>z(t.INDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.OUTDENT_CONTENT_COMMAND,e=>z(t.OUTDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!F(n)&&(n.isCollapsed()&&0===r.offset&&null===i.getPreviousSibling()&&c(i.getParentOrThrow())?(e.preventDefault(),!0):W(t.KEY_ARROW_UP_COMMAND,e))},t.COMMAND_PRIORITY_LOW),r.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!F(n)&&(n.isCollapsed()&&r.offset===i.getTextContentSize()&&null===i.getNextSibling()&&c(i.getParentOrThrow())?(e.preventDefault(),!0):W(t.KEY_ARROW_DOWN_COMMAND,e))},t.COMMAND_PRIORITY_LOW),r.registerCommand(t.MOVE_TO_START,e=>K(t.MOVE_TO_START,e),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.MOVE_TO_END,e=>K(t.MOVE_TO_END,e),t.COMMAND_PRIORITY_LOW)),e.mergeRegister(...o)};
|
|
9
|
+
"use strict";var e=require("@lexical/utils"),t=require("lexical");function n(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}require("prismjs"),require("prismjs/components/prism-clike"),require("prismjs/components/prism-javascript"),require("prismjs/components/prism-markup"),require("prismjs/components/prism-markdown"),require("prismjs/components/prism-c"),require("prismjs/components/prism-css"),require("prismjs/components/prism-objectivec"),require("prismjs/components/prism-sql"),require("prismjs/components/prism-powershell"),require("prismjs/components/prism-python"),require("prismjs/components/prism-rust"),require("prismjs/components/prism-swift"),require("prismjs/components/prism-typescript"),require("prismjs/components/prism-java"),require("prismjs/components/prism-cpp");const r="javascript";function i(t,n){for(const r of t.childNodes){if(e.isHTMLElement(r)&&r.tagName===n)return!0;i(r,n)}return!1}const o="data-language",s="data-highlight-language",a="data-theme";class l extends t.ElementNode{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new l(e.__language,e.__key)}constructor(e,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(t){const n=document.createElement("code");e.addClassNamesToElement(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(o,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(s,r));const i=this.getTheme();i&&n.setAttribute(a,i);const l=this.getStyle();return l&&n.setAttribute("style",l),n}updateDOM(e,t,n){const r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(o,r):i&&t.removeAttribute(o);const l=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?l&&r?r!==i&&t.setAttribute(s,r):t.removeAttribute(s):l&&r&&t.setAttribute(s,r);const g=this.__theme,c=e.__theme;g?g!==c&&t.setAttribute(a,g):c&&t.removeAttribute(a);const u=this.__style,d=e.__style;return u?u!==d&&t.setAttribute("style",u):d&&t.removeAttribute("style"),!1}exportDOM(t){const n=document.createElement("pre");e.addClassNamesToElement(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(o,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(s,r));const i=this.getTheme();i&&n.setAttribute(a,i);const l=this.getStyle();return l&&n.setAttribute("style",l),{element:n}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||i(e,"BR"))?{conversion:u,priority:1}:null,div:()=>({conversion:d,priority:1}),pre:()=>({conversion:u,priority:0}),table:e=>N(e)?{conversion:p,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&N(n)?{conversion:f,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&N(t)?{conversion:f,priority:3}:null}}}static importJSON(e){return g().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(e,n=!0){const r=this.getChildren(),i=r.length;if(i>=2&&"\n"===r[i-1].getTextContent()&&"\n"===r[i-2].getTextContent()&&e.isCollapsed()&&e.anchor.key===this.__key&&e.anchor.offset===i){r[i-1].remove(),r[i-2].remove();const e=t.$createParagraphNode();return this.insertAfter(e,n),e}const{anchor:o,focus:s}=e,a=(o.isBefore(s)?o:s).getNode();if(t.$isTextNode(a)){let e=O(a);const n=[];for(;;)if(t.$isTabNode(e))n.push(t.$createTabNode()),e=e.getNextSibling();else{if(!x(e))break;{let t=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;t<i&&" "===r[t];)t++;if(0!==t&&n.push(T(" ".repeat(t))),t!==i)break;e=e.getNextSibling()}}const r=a.splitText(o.offset)[0],i=0===o.offset?0:1,s=r.getIndexWithinParent()+i,l=a.getParentOrThrow(),g=[t.$createLineBreakNode(),...n];l.splice(s,0,g);const c=n[n.length-1];c?c.select():0===o.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(c(a)){const{offset:n}=e.anchor;a.splice(n,0,[t.$createLineBreakNode()]),a.select(n+1,n+1)}return null}canIndent(){return!1}collapseAtStart(){const e=t.$createParagraphNode();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function g(e,n){return t.$create(l).setLanguage(e).setTheme(n)}function c(e){return e instanceof l}function u(e){return{node:g(e.getAttribute(o))}}function d(e){const t=e,n=h(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(h(t))return!0;t=t.parentElement}return!1}(t)?{node:n?g():null}:{node:null}}function p(){return{node:g()}}function f(){return{node:null}}function h(e){return null!==e.style.fontFamily.match("monospace")}function N(e){return e.classList.contains("js-file-line-container")}class m extends t.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new m(e.__text,e.__highlightType||void 0,e.__key)}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(t){const n=super.createDOM(t),r=_(t.theme,this.__highlightType);return e.addClassNamesToElement(n,r),n}updateDOM(t,n,r){const i=super.updateDOM(t,n,r),o=_(r.theme,t.__highlightType),s=_(r.theme,this.__highlightType);return o!==s&&(o&&e.removeClassNamesFromElement(n,o),s&&e.addClassNamesToElement(n,s)),i}static importJSON(e){return T().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return g()}}function _(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function T(e="",n){return t.$applyNodeReplacement(new m(e,n))}function x(e){return e instanceof m}function C(n,r){let i=n;for(let o=t.$getSiblingCaret(n,r);o&&(x(o.origin)||t.$isTabNode(o.origin));o=e.$getAdjacentCaret(o))i=o.origin;return i}function O(e){return C(e,"previous")}function S(e){return C(e,"next")}function y(e){const n=O(e),r=S(e);let i=n;for(;null!==i;){if(x(i)){const e=t.getTextDirection(i.getTextContent());if(null!==e)return e}if(i===r)break;i=i.getNextSibling()}const o=n.getParent();if(t.$isElementNode(o)){const e=o.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function $(e,r){let i=null,o=null,s=e,a=r,l=e.getTextContent();for(;;){if(0===a){if(s=s.getPreviousSibling(),null===s)break;if(x(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||n(167),t.$isLineBreakNode(s)){i={node:s,offset:1};break}a=Math.max(0,s.getTextContentSize()-1),l=s.getTextContent()}else a--;const e=l[a];x(s)&&" "!==e&&(o={node:s,offset:a})}if(null!==o)return o;let g=null;if(r<e.getTextContentSize())x(e)&&(g=e.getTextContent()[r]);else{const t=e.getNextSibling();x(t)&&(g=t.getTextContent()[0])}if(null!==g&&" "!==g)return i;{const n=function(e,n){let r=e,i=n,o=e.getTextContent(),s=e.getTextContentSize();for(;;){if(!x(r)||i===s){if(r=r.getNextSibling(),null===r||t.$isLineBreakNode(r))return null;x(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(x(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(e,r);return null!==n?n:i}}function A(e){const r=S(e);return t.$isLineBreakNode(r)&&n(168),r}const b=t.defineExtension({name:"@lexical/code",nodes:()=>[l,m]});!function(e){e.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var t={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(t).forEach(function(n){var r=t[n],i=[];/^\w+$/.test(n)||i.push(/\w+/.exec(n)[0]),"diff"===n&&i.push("bold"),e.languages.diff[n]={pattern:RegExp("^(?:["+r+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}}),Object.defineProperty(e.languages.diff,"PREFIXES",{value:t})}(Prism);const L=globalThis.Prism||window.Prism,M={c:"C",clike:"C-like",cpp:"C++",css:"CSS",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},E={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function v(e){return E[e]||e}function D(e){return"string"==typeof e?e:Array.isArray(e)?e.map(D).join(""):D(e.content)}function k(e,t){const n=/^diff-([\w-]+)/i.exec(t),r=e.getTextContent();let i=L.tokenize(r,L.languages[n?"diff":t]);return n&&(i=function(e,t){const n=t,r=L.languages[n],i={tokens:e},o=L.languages.diff.PREFIXES;for(const e of i.tokens){if("string"==typeof e||!(e.type in o)||!Array.isArray(e.content))continue;const t=e.type;let n=0;const i=()=>(n++,new L.Token("prefix",o[t],t.replace(/^(\w+).*/,"$1"))),s=e.content.filter(e=>"string"==typeof e||"prefix"!==e.type),a=e.content.length-s.length,l=L.tokenize(D(s),r);l.unshift(i());const g=/\r\n|\n/g,c=e=>{const t=[];g.lastIndex=0;let r,o=0;for(;n<a&&(r=g.exec(e));){const n=r.index+r[0].length;t.push(e.slice(o,n)),o=n,t.push(i())}if(0!==t.length)return o<e.length&&t.push(e.slice(o)),t},u=e=>{for(let t=0;t<e.length&&n<a;t++){const n=e[t];if("string"==typeof n){const r=c(n);r&&(e.splice(t,1,...r),t+=r.length-1)}else if("string"==typeof n.content){const e=c(n.content);e&&(n.content=e)}else Array.isArray(n.content)?u(n.content):u([n.content])}};u(l),n<a&&l.push(i()),e.content=l}return i.tokens}(i,n[1])),R(i)}function R(e,n){const r=[];for(const i of e)if("string"==typeof i){const e=i.split(/(\n|\t)/),o=e.length;for(let i=0;i<o;i++){const o=e[i];"\n"===o||"\r\n"===o?r.push(t.$createLineBreakNode()):"\t"===o?r.push(t.$createTabNode()):o.length>0&&r.push(T(o,n))}}else{const{content:e,alias:t}=i;"string"==typeof e?r.push(...R([e],"prefix"===i.type&&"string"==typeof t?t:i.type)):Array.isArray(e)&&r.push(...R(e,"unchanged"===i.type?void 0:i.type))}return r}const P={$tokenize(e,t){return k(e,t||this.defaultLanguage)},defaultLanguage:r,tokenize(e,t){return L.tokenize(e,L.languages[t||""]||L.languages[this.defaultLanguage])}};function I(e,n,r){const i=e.getParent();c(i)?j(i,n,r):x(e)&&e.replace(t.$createTextNode(e.__text))}function w(e,n){const r=n.getElementByKey(e.getKey());if(null===r)return;const i=e.getChildren(),o=i.length;if(o===r.__cachedChildrenLength)return;r.__cachedChildrenLength=o;let s="1",a=1;for(let e=0;e<o;e++)t.$isLineBreakNode(i[e])&&(s+="\n"+ ++a);r.setAttribute("data-gutter",s)}const B=new Set;function j(e,n,r){const i=e.getKey(),o=n.getKey()+"/"+i;void 0===e.getLanguage()&&e.setLanguage(r.defaultLanguage);const s=e.getLanguage()||r.defaultLanguage;if(!function(e){const t=function(e){const t=/^diff-([\w-]+)/i.exec(e);return t?t[1]:null}(e),n=t||e;try{return!!n&&L.languages.hasOwnProperty(n)}catch(e){return!1}}(s))return e.getIsSyntaxHighlightSupported()&&e.setIsSyntaxHighlightSupported(!1),void async function(){}();e.getIsSyntaxHighlightSupported()||e.setIsSyntaxHighlightSupported(!0),B.has(o)||(B.add(o),n.update(()=>{!function(e,n){const r=t.$getNodeByKey(e);if(!c(r)||!r.isAttached())return;const i=t.$getSelection();if(!t.$isRangeSelection(i))return void n();const o=i.anchor,s=o.offset,a="element"===o.type&&t.$isLineBreakNode(r.getChildAtIndex(o.offset-1));let l=0;if(!a){const e=o.getNode();l=s+e.getPreviousSiblings().reduce((e,t)=>e+t.getTextContentSize(),0)}if(!n())return;if(a)return void o.getNode().select(s,s);r.getChildren().some(e=>{const n=t.$isTextNode(e);if(n||t.$isLineBreakNode(e)){const t=e.getTextContentSize();if(n&&t>=l)return e.select(l,l),!0;l-=t}return!1})}(i,()=>{const n=t.$getNodeByKey(i);if(!c(n)||!n.isAttached())return!1;const o=n.getLanguage()||r.defaultLanguage,s=r.$tokenize(n,o),a=function(e,t){let n=0;for(;n<e.length&&H(e[n],t[n]);)n++;const r=e.length,i=t.length,o=Math.min(r,i)-n;let s=0;for(;s<o;)if(s++,!H(e[r-s],t[i-s])){s--;break}const a=n,l=r-s,g=t.slice(n,i-s);return{from:a,nodesForReplacement:g,to:l}}(n.getChildren(),s),{from:l,to:g,nodesForReplacement:u}=a;return!(l===g&&!u.length)&&(e.splice(l,g-l,u),!0)})},{onUpdate:()=>{B.delete(o)},skipTransforms:!0}))}function H(e,n){return x(e)&&x(n)&&e.__text===n.__text&&e.__highlightType===n.__highlightType||t.$isTabNode(e)&&t.$isTabNode(n)||t.$isLineBreakNode(e)&&t.$isLineBreakNode(n)}function F(e){if(!t.$isRangeSelection(e))return!1;const n=e.anchor.getNode(),r=c(n)?n:n.getParent(),i=e.focus.getNode(),o=c(i)?i:i.getParent();return c(r)&&r.is(o)}function q(e){const r=e.getNodes(),i=[];if(1===r.length&&c(r[0]))return i;let o=[];for(let e=0;e<r.length;e++){const s=r[e];x(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||n(169),t.$isLineBreakNode(s)?o.length>0&&(i.push(o),o=[]):o.push(s)}if(o.length>0){const n=e.isBackward()?e.anchor:e.focus,r=t.$createPoint(o[0].getKey(),0,"text");n.is(r)||i.push(o)}return i}function z(e){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!F(n))return!1;const r=q(n),i=r.length;if(0===i&&n.isCollapsed())return e===t.INDENT_CONTENT_COMMAND&&n.insertNodes([t.$createTabNode()]),!0;if(0===i&&e===t.INDENT_CONTENT_COMMAND&&"\n"===n.getTextContent()){const e=t.$createTabNode(),r=t.$createLineBreakNode(),i=n.isBackward()?"previous":"next";return n.insertNodes([e,r]),t.$setSelectionFromCaretRange(t.$getCaretRangeInDirection(t.$getCaretRange(t.$getTextPointCaret(e,"next",0),t.$normalizeCaret(t.$getSiblingCaret(r,"next"))),i)),!0}for(let o=0;o<i;o++){const i=r[o];if(i.length>0){let r=i[0];if(0===o&&(r=O(r)),e===t.INDENT_CONTENT_COMMAND){const e=t.$createTabNode();if(r.insertBefore(e),0===o){const i=n.isBackward()?"focus":"anchor",o=t.$createPoint(r.getKey(),0,"text");n[i].is(o)&&n[i].set(e.getKey(),0,"text")}}else t.$isTabNode(r)&&r.remove()}}return!0}function K(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.offset,a=o.offset,l=i.getNode(),g=o.getNode(),c=e===t.KEY_ARROW_UP_COMMAND;if(!F(r)||!x(l)&&!t.$isTabNode(l)||!x(g)&&!t.$isTabNode(g))return!1;if(!n.altKey){if(r.isCollapsed()){const e=l.getParentOrThrow();if(c&&0===s&&null===l.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),n.preventDefault(),!0}else if(!c&&s===l.getTextContentSize()&&null===l.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),n.preventDefault(),!0}}return!1}let u,d;if(l.isBefore(g)?(u=O(l),d=S(g)):(u=O(g),d=S(l)),null==u||null==d)return!1;const p=u.getNodesBetween(d);for(let e=0;e<p.length;e++){const n=p[e];if(!x(n)&&!t.$isTabNode(n)&&!t.$isLineBreakNode(n))return!1}n.preventDefault(),n.stopPropagation();const f=c?u.getPreviousSibling():d.getNextSibling();if(!t.$isLineBreakNode(f))return!0;const h=c?f.getPreviousSibling():f.getNextSibling();if(null==h)return!0;const N=x(h)||t.$isTabNode(h)||t.$isLineBreakNode(h)?c?O(h):S(h):null;let m=null!=N?N:h;return f.remove(),p.forEach(e=>e.remove()),e===t.KEY_ARROW_UP_COMMAND?(p.forEach(e=>m.insertBefore(e)),m.insertBefore(f)):(m.insertAfter(f),m=f,p.forEach(e=>{m.insertAfter(e),m=e})),r.setTextNodeRange(l,s,g,a),!0}function W(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.getNode(),a=o.getNode(),l=e===t.MOVE_TO_START;if(!F(r)||!x(s)&&!t.$isTabNode(s)||!x(a)&&!t.$isTabNode(a))return!1;const g=a;if("rtl"===y(g)?!l:l){const e=$(g,o.offset);if(null!==e){const{node:n,offset:i}=e;t.$isLineBreakNode(n)?n.selectNext(0,0):r.setTextNodeRange(n,i,n,i)}else g.getParentOrThrow().selectStart()}else{A(g).select()}return n.preventDefault(),n.stopPropagation(),!0}const Y=O,U=S,J=A,G=$;exports.$createCodeHighlightNode=T,exports.$createCodeNode=g,exports.$getCodeLineDirection=y,exports.$getEndOfCodeInLine=A,exports.$getFirstCodeNodeOfLine=O,exports.$getLastCodeNodeOfLine=S,exports.$getStartOfCodeInLine=$,exports.$isCodeHighlightNode=x,exports.$isCodeNode=c,exports.CODE_LANGUAGE_FRIENDLY_NAME_MAP=M,exports.CODE_LANGUAGE_MAP=E,exports.CodeExtension=b,exports.CodeHighlightNode=m,exports.CodeNode=l,exports.DEFAULT_CODE_LANGUAGE=r,exports.PrismTokenizer=P,exports.getCodeLanguageOptions=function(){const e=[];for(const[t,n]of Object.entries(M))e.push([t,n]);return e},exports.getCodeLanguages=()=>Object.keys(L.languages).filter(e=>"function"!=typeof L.languages[e]).sort(),exports.getCodeThemeOptions=function(){return[]},exports.getDefaultCodeLanguage=()=>r,exports.getEndOfCodeInLine=J,exports.getFirstCodeNodeOfLine=Y,exports.getLanguageFriendlyName=function(e){const t=v(e);return M[t]||t},exports.getLastCodeNodeOfLine=U,exports.getStartOfCodeInLine=G,exports.normalizeCodeLang=v,exports.normalizeCodeLanguage=v,exports.registerCodeHighlighting=function(r,i){if(!r.hasNodes([l,m]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");null==i&&(i=P);const o=[];return!0!==r._headless&&o.push(r.registerMutationListener(l,e=>{r.getEditorState().read(()=>{for(const[n,i]of e)if("destroyed"!==i){const e=t.$getNodeByKey(n);null!==e&&w(e,r)}})},{skipInitialization:!1})),o.push(r.registerNodeTransform(l,e=>j(e,r,i)),r.registerNodeTransform(t.TextNode,e=>I(e,r,i)),r.registerNodeTransform(m,e=>I(e,r,i)),r.registerCommand(t.KEY_TAB_COMMAND,e=>{const i=function(e){const r=t.$getSelection();if(!t.$isRangeSelection(r)||!F(r))return null;const i=e?t.OUTDENT_CONTENT_COMMAND:t.INDENT_CONTENT_COMMAND,o=e?t.OUTDENT_CONTENT_COMMAND:t.INSERT_TAB_COMMAND,s=r.anchor,a=r.focus;if(s.is(a))return o;const l=q(r);if(1!==l.length)return i;const g=l[0];let c,u;0===g.length&&n(285),r.isBackward()?(c=a,u=s):(c=s,u=a);const d=O(g[0]),p=S(g[0]),f=t.$createPoint(d.getKey(),0,"text"),h=t.$createPoint(p.getKey(),p.getTextContentSize(),"text");return c.isBefore(f)||h.isBefore(u)?i:f.isBefore(c)||u.isBefore(h)?o:i}(e.shiftKey);return null!==i&&(e.preventDefault(),r.dispatchCommand(i,void 0),!0)},t.COMMAND_PRIORITY_LOW),r.registerCommand(t.INSERT_TAB_COMMAND,()=>!!F(t.$getSelection())&&(t.$insertNodes([t.$createTabNode()]),!0),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.INDENT_CONTENT_COMMAND,e=>z(t.INDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.OUTDENT_CONTENT_COMMAND,e=>z(t.OUTDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!F(n)&&(n.isCollapsed()&&0===r.offset&&null===i.getPreviousSibling()&&c(i.getParentOrThrow())?(e.preventDefault(),!0):K(t.KEY_ARROW_UP_COMMAND,e))},t.COMMAND_PRIORITY_LOW),r.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!F(n)&&(n.isCollapsed()&&r.offset===i.getTextContentSize()&&null===i.getNextSibling()&&c(i.getParentOrThrow())?(e.preventDefault(),!0):K(t.KEY_ARROW_DOWN_COMMAND,e))},t.COMMAND_PRIORITY_LOW),r.registerCommand(t.MOVE_TO_START,e=>W(t.MOVE_TO_START,e),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.MOVE_TO_END,e=>W(t.MOVE_TO_END,e),t.COMMAND_PRIORITY_LOW)),e.mergeRegister(...o)};
|
package/LexicalCode.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{isHTMLElement as t,addClassNamesToElement as e,removeClassNamesFromElement as n,$getAdjacentCaret as r,mergeRegister as i}from"@lexical/utils";import{ElementNode as o,$createParagraphNode as s,$isTextNode as l,$isTabNode as u,$createTabNode as c,$createLineBreakNode as g,$create as a,TextNode as f,$applyNodeReplacement as p,$getSiblingCaret as h,getTextDirection as d,$isElementNode as m,$isLineBreakNode as y,defineExtension as x,$createTextNode as _,$getNodeByKey as S,$getSelection as v,$isRangeSelection as T,$createPoint as b,INDENT_CONTENT_COMMAND as C,OUTDENT_CONTENT_COMMAND as N,INSERT_TAB_COMMAND as j,$setSelectionFromCaretRange as w,$getCaretRangeInDirection as k,$getCaretRange as A,$getTextPointCaret as P,$normalizeCaret as L,KEY_ARROW_UP_COMMAND as O,MOVE_TO_START as H,KEY_TAB_COMMAND as E,COMMAND_PRIORITY_LOW as z,$insertNodes as B,KEY_ARROW_DOWN_COMMAND as D,MOVE_TO_END as F}from"lexical";import"prismjs";import"prismjs/components/prism-clike.js";import"prismjs/components/prism-javascript.js";import"prismjs/components/prism-markup.js";import"prismjs/components/prism-markdown.js";import"prismjs/components/prism-c.js";import"prismjs/components/prism-css.js";import"prismjs/components/prism-objectivec.js";import"prismjs/components/prism-sql.js";import"prismjs/components/prism-powershell.js";import"prismjs/components/prism-python.js";import"prismjs/components/prism-rust.js";import"prismjs/components/prism-swift.js";import"prismjs/components/prism-typescript.js";import"prismjs/components/prism-java.js";import"prismjs/components/prism-cpp.js";function I(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const M="javascript",J=()=>M;function R(e,n){for(const r of e.childNodes){if(t(r)&&r.tagName===n)return!0;R(r,n)}return!1}const K="data-language",$="data-highlight-language",W="data-theme";class q extends o{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(t){return new q(t.__language,t.__key)}constructor(t,e){super(e),this.__language=t||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(t){super.afterCloneFrom(t),this.__language=t.__language,this.__theme=t.__theme,this.__isSyntaxHighlightSupported=t.__isSyntaxHighlightSupported}createDOM(t){const n=document.createElement("code");e(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(K,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute($,r));const i=this.getTheme();i&&n.setAttribute(W,i);const o=this.getStyle();return o&&n.setAttribute("style",o),n}updateDOM(t,e,n){const r=this.__language,i=t.__language;r?r!==i&&e.setAttribute(K,r):i&&e.removeAttribute(K);const o=this.__isSyntaxHighlightSupported;t.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&e.setAttribute($,r):e.removeAttribute($):o&&r&&e.setAttribute($,r);const s=this.__theme,l=t.__theme;s?s!==l&&e.setAttribute(W,s):l&&e.removeAttribute(W);const u=this.__style,c=t.__style;return u?u!==c&&e.setAttribute("style",u):c&&e.removeAttribute("style"),!1}exportDOM(t){const n=document.createElement("pre");e(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(K,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute($,r));const i=this.getTheme();i&&n.setAttribute(W,i);const o=this.getStyle();return o&&n.setAttribute("style",o),{element:n}}static importDOM(){return{code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||R(t,"BR"))?{conversion:Q,priority:1}:null,div:()=>({conversion:G,priority:1}),pre:()=>({conversion:Q,priority:0}),table:t=>tt(t)?{conversion:V,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&tt(n)?{conversion:Y,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&tt(e)?{conversion:Y,priority:3}:null}}}static importJSON(t){return U().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setLanguage(t.language).setTheme(t.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(t,e=!0){const n=this.getChildren(),r=n.length;if(r>=2&&"\n"===n[r-1].getTextContent()&&"\n"===n[r-2].getTextContent()&&t.isCollapsed()&&t.anchor.key===this.__key&&t.anchor.offset===r){n[r-1].remove(),n[r-2].remove();const t=s();return this.insertAfter(t,e),t}const{anchor:i,focus:o}=t,a=(i.isBefore(o)?i:o).getNode();if(l(a)){let t=st(a);const e=[];for(;;)if(u(t))e.push(c()),t=t.getNextSibling();else{if(!it(t))break;{let n=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&e.push(rt(" ".repeat(n))),n!==i)break;t=t.getNextSibling()}}const n=a.splitText(i.offset)[0],r=0===i.offset?0:1,o=n.getIndexWithinParent()+r,s=a.getParentOrThrow(),l=[g(),...e];s.splice(o,0,l);const f=e[e.length-1];f?f.select():0===i.offset?n.selectPrevious():n.getNextSibling().selectNext(0,0)}if(X(a)){const{offset:e}=t.anchor;a.splice(e,0,[g()]),a.select(e+1,e+1)}return null}canIndent(){return!1}collapseAtStart(){const t=s();return this.getChildren().forEach(e=>t.append(e)),this.replace(t),!0}setLanguage(t){const e=this.getWritable();return e.__language=t||void 0,e}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(t){const e=this.getWritable();return e.__isSyntaxHighlightSupported=t,e}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(t){const e=this.getWritable();return e.__theme=t||void 0,e}getTheme(){return this.getLatest().__theme}}function U(t,e){return a(q).setLanguage(t).setTheme(e)}function X(t){return t instanceof q}function Q(t){return{node:U(t.getAttribute(K))}}function G(t){const e=t,n=Z(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(Z(e))return!0;e=e.parentElement}return!1}(e)?{node:n?U():null}:{node:null}}function V(){return{node:U()}}function Y(){return{node:null}}function Z(t){return null!==t.style.fontFamily.match("monospace")}function tt(t){return t.classList.contains("js-file-line-container")}class et extends f{__highlightType;constructor(t="",e,n){super(t,n),this.__highlightType=e}static getType(){return"code-highlight"}static clone(t){return new et(t.__text,t.__highlightType||void 0,t.__key)}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(t){const e=this.getWritable();return e.__highlightType=t||void 0,e}canHaveFormat(){return!1}createDOM(t){const n=super.createDOM(t),r=nt(t.theme,this.__highlightType);return e(n,r),n}updateDOM(t,r,i){const o=super.updateDOM(t,r,i),s=nt(i.theme,t.__highlightType),l=nt(i.theme,this.__highlightType);return s!==l&&(s&&n(r,s),l&&e(r,l)),o}static importJSON(t){return rt().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setHighlightType(t.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(t){return this}isParentRequired(){return!0}createParentElementNode(){return U()}}function nt(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function rt(t="",e){return p(new et(t,e))}function it(t){return t instanceof et}function ot(t,e){let n=t;for(let i=h(t,e);i&&(it(i.origin)||u(i.origin));i=r(i))n=i.origin;return n}function st(t){return ot(t,"previous")}function lt(t){return ot(t,"next")}function ut(t){const e=st(t),n=lt(t);let r=e;for(;null!==r;){if(it(r)){const t=d(r.getTextContent());if(null!==t)return t}if(r===n)break;r=r.getNextSibling()}const i=e.getParent();if(m(i)){const t=i.getDirection();if("ltr"===t||"rtl"===t)return t}return null}function ct(t,e){let n=null,r=null,i=t,o=e,s=t.getTextContent();for(;;){if(0===o){if(i=i.getPreviousSibling(),null===i)break;if(it(i)||u(i)||y(i)||I(167),y(i)){n={node:i,offset:1};break}o=Math.max(0,i.getTextContentSize()-1),s=i.getTextContent()}else o--;const t=s[o];it(i)&&" "!==t&&(r={node:i,offset:o})}if(null!==r)return r;let l=null;if(e<t.getTextContentSize())it(t)&&(l=t.getTextContent()[e]);else{const e=t.getNextSibling();it(e)&&(l=e.getTextContent()[0])}if(null!==l&&" "!==l)return n;{const r=function(t,e){let n=t,r=e,i=t.getTextContent(),o=t.getTextContentSize();for(;;){if(!it(n)||r===o){if(n=n.getNextSibling(),null===n||y(n))return null;it(n)&&(r=0,i=n.getTextContent(),o=n.getTextContentSize())}if(it(n)){if(" "!==i[r])return{node:n,offset:r};r++}}}(t,e);return null!==r?r:n}}function gt(t){const e=lt(t);return y(e)&&I(168),e}const at=x({name:"@lexical/code",nodes:[q,et]});!function(t){t.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var e={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(e).forEach(function(n){var r=e[n],i=[];/^\w+$/.test(n)||i.push(/\w+/.exec(n)[0]),"diff"===n&&i.push("bold"),t.languages.diff[n]={pattern:RegExp("^(?:["+r+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}}),Object.defineProperty(t.languages.diff,"PREFIXES",{value:e})}(Prism);const ft=globalThis.Prism||window.Prism,pt={c:"C",clike:"C-like",cpp:"C++",css:"CSS",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},ht={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function dt(t){return ht[t]||t}function mt(t){const e=dt(t);return pt[e]||e}const yt=()=>Object.keys(ft.languages).filter(t=>"function"!=typeof ft.languages[t]).sort();function xt(){const t=[];for(const[e,n]of Object.entries(pt))t.push([e,n]);return t}function _t(){return[]}function St(t){return"string"==typeof t?t:Array.isArray(t)?t.map(St).join(""):St(t.content)}function vt(t,e){const n=/^diff-([\w-]+)/i.exec(e),r=t.getTextContent();let i=ft.tokenize(r,ft.languages[n?"diff":e]);return n&&(i=function(t,e){const n=e,r=ft.languages[n],i={tokens:t},o=ft.languages.diff.PREFIXES;for(const t of i.tokens){if("string"==typeof t||!(t.type in o)||!Array.isArray(t.content))continue;const e=t.type;let n=0;const i=()=>(n++,new ft.Token("prefix",o[e],e.replace(/^(\w+).*/,"$1"))),s=t.content.filter(t=>"string"==typeof t||"prefix"!==t.type),l=t.content.length-s.length,u=ft.tokenize(St(s),r);u.unshift(i());const c=/\r\n|\n/g,g=t=>{const e=[];c.lastIndex=0;let r,o=0;for(;n<l&&(r=c.exec(t));){const n=r.index+r[0].length;e.push(t.slice(o,n)),o=n,e.push(i())}if(0!==e.length)return o<t.length&&e.push(t.slice(o)),e},a=t=>{for(let e=0;e<t.length&&n<l;e++){const n=t[e];if("string"==typeof n){const r=g(n);r&&(t.splice(e,1,...r),e+=r.length-1)}else if("string"==typeof n.content){const t=g(n.content);t&&(n.content=t)}else Array.isArray(n.content)?a(n.content):a([n.content])}};a(u),n<l&&u.push(i()),t.content=u}return i.tokens}(i,n[1])),Tt(i)}function Tt(t,e){const n=[];for(const r of t)if("string"==typeof r){const t=r.split(/(\n|\t)/),i=t.length;for(let r=0;r<i;r++){const i=t[r];"\n"===i||"\r\n"===i?n.push(g()):"\t"===i?n.push(c()):i.length>0&&n.push(rt(i,e))}}else{const{content:t,alias:e}=r;"string"==typeof t?n.push(...Tt([t],"prefix"===r.type&&"string"==typeof e?e:r.type)):Array.isArray(t)&&n.push(...Tt(t,"unchanged"===r.type?void 0:r.type))}return n}const bt={$tokenize(t,e){return vt(t,e||this.defaultLanguage)},defaultLanguage:M,tokenize(t,e){return ft.tokenize(t,ft.languages[e||""]||ft.languages[this.defaultLanguage])}};function Ct(t,e,n){const r=t.getParent();X(r)?wt(r,e,n):it(t)&&t.replace(_(t.__text))}function Nt(t,e){const n=e.getElementByKey(t.getKey());if(null===n)return;const r=t.getChildren(),i=r.length;if(i===n.__cachedChildrenLength)return;n.__cachedChildrenLength=i;let o="1",s=1;for(let t=0;t<i;t++)y(r[t])&&(o+="\n"+ ++s);n.setAttribute("data-gutter",o)}const jt=new Set;function wt(t,e,n){const r=t.getKey();void 0===t.getLanguage()&&t.setLanguage(n.defaultLanguage);const i=t.getLanguage()||n.defaultLanguage;if(!function(t){const e=function(t){const e=/^diff-([\w-]+)/i.exec(t);return e?e[1]:null}(t),n=e||t;try{return!!n&&ft.languages.hasOwnProperty(n)}catch(t){return!1}}(i))return t.getIsSyntaxHighlightSupported()&&t.setIsSyntaxHighlightSupported(!1),void async function(){}();t.getIsSyntaxHighlightSupported()||t.setIsSyntaxHighlightSupported(!0),jt.has(r)||(jt.add(r),e.update(()=>{!function(t,e){const n=S(t);if(!X(n)||!n.isAttached())return;const r=v();if(!T(r))return void e();const i=r.anchor,o=i.offset,s="element"===i.type&&y(n.getChildAtIndex(i.offset-1));let u=0;if(!s){const t=i.getNode();u=o+t.getPreviousSiblings().reduce((t,e)=>t+e.getTextContentSize(),0)}if(!e())return;if(s)return void i.getNode().select(o,o);n.getChildren().some(t=>{const e=l(t);if(e||y(t)){const n=t.getTextContentSize();if(e&&n>=u)return t.select(u,u),!0;u-=n}return!1})}(r,()=>{const e=S(r);if(!X(e)||!e.isAttached())return!1;const i=e.getLanguage()||n.defaultLanguage,o=n.$tokenize(e,i),s=function(t,e){let n=0;for(;n<t.length&&kt(t[n],e[n]);)n++;const r=t.length,i=e.length,o=Math.min(r,i)-n;let s=0;for(;s<o;)if(s++,!kt(t[r-s],e[i-s])){s--;break}const l=n,u=r-s,c=e.slice(n,i-s);return{from:l,nodesForReplacement:c,to:u}}(e.getChildren(),o),{from:l,to:u,nodesForReplacement:c}=s;return!(l===u&&!c.length)&&(t.splice(l,u-l,c),!0)})},{onUpdate:()=>{jt.delete(r)},skipTransforms:!0}))}function kt(t,e){return it(t)&&it(e)&&t.__text===e.__text&&t.__highlightType===e.__highlightType||u(t)&&u(e)||y(t)&&y(e)}function At(t){if(!T(t))return!1;const e=t.anchor.getNode(),n=X(e)?e:e.getParent(),r=t.focus.getNode(),i=X(r)?r:r.getParent();return X(n)&&n.is(i)}function Pt(t){const e=t.getNodes(),n=[];if(1===e.length&&X(e[0]))return n;let r=[];for(let t=0;t<e.length;t++){const i=e[t];it(i)||u(i)||y(i)||I(169),y(i)?r.length>0&&(n.push(r),r=[]):r.push(i)}if(r.length>0){const e=t.isBackward()?t.anchor:t.focus,i=b(r[0].getKey(),0,"text");e.is(i)||n.push(r)}return n}function Lt(t){const e=v();if(!T(e)||!At(e))return!1;const n=Pt(e),r=n.length;if(0===r&&e.isCollapsed())return t===C&&e.insertNodes([c()]),!0;if(0===r&&t===C&&"\n"===e.getTextContent()){const t=c(),n=g(),r=e.isBackward()?"previous":"next";return e.insertNodes([t,n]),w(k(A(P(t,"next",0),L(h(n,"next"))),r)),!0}for(let i=0;i<r;i++){const r=n[i];if(r.length>0){let n=r[0];if(0===i&&(n=st(n)),t===C){const t=c();if(n.insertBefore(t),0===i){const r=e.isBackward()?"focus":"anchor",i=b(n.getKey(),0,"text");e[r].is(i)&&e[r].set(t.getKey(),0,"text")}}else u(n)&&n.remove()}}return!0}function Ot(t,e){const n=v();if(!T(n))return!1;const{anchor:r,focus:i}=n,o=r.offset,s=i.offset,l=r.getNode(),c=i.getNode(),g=t===O;if(!At(n)||!it(l)&&!u(l)||!it(c)&&!u(c))return!1;if(!e.altKey){if(n.isCollapsed()){const t=l.getParentOrThrow();if(g&&0===o&&null===l.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!0}else if(!g&&o===l.getTextContentSize()&&null===l.getNextSibling()){if(null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!0}}return!1}let a,f;if(l.isBefore(c)?(a=st(l),f=lt(c)):(a=st(c),f=lt(l)),null==a||null==f)return!1;const p=a.getNodesBetween(f);for(let t=0;t<p.length;t++){const e=p[t];if(!it(e)&&!u(e)&&!y(e))return!1}e.preventDefault(),e.stopPropagation();const h=g?a.getPreviousSibling():f.getNextSibling();if(!y(h))return!0;const d=g?h.getPreviousSibling():h.getNextSibling();if(null==d)return!0;const m=it(d)||u(d)||y(d)?g?st(d):lt(d):null;let x=null!=m?m:d;return h.remove(),p.forEach(t=>t.remove()),t===O?(p.forEach(t=>x.insertBefore(t)),x.insertBefore(h)):(x.insertAfter(h),x=h,p.forEach(t=>{x.insertAfter(t),x=t})),n.setTextNodeRange(l,o,c,s),!0}function Ht(t,e){const n=v();if(!T(n))return!1;const{anchor:r,focus:i}=n,o=r.getNode(),s=i.getNode(),l=t===H;if(!At(n)||!it(o)&&!u(o)||!it(s)&&!u(s))return!1;const c=s;if("rtl"===ut(c)?!l:l){const t=ct(c,i.offset);if(null!==t){const{node:e,offset:r}=t;y(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r)}else c.getParentOrThrow().selectStart()}else{gt(c).select()}return e.preventDefault(),e.stopPropagation(),!0}function Et(t,e){if(!t.hasNodes([q,et]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");null==e&&(e=bt);const n=[];return!0!==t._headless&&n.push(t.registerMutationListener(q,e=>{t.getEditorState().read(()=>{for(const[n,r]of e)if("destroyed"!==r){const e=S(n);null!==e&&Nt(e,t)}})},{skipInitialization:!1})),n.push(t.registerNodeTransform(q,n=>wt(n,t,e)),t.registerNodeTransform(f,n=>Ct(n,t,e)),t.registerNodeTransform(et,n=>Ct(n,t,e)),t.registerCommand(E,e=>{const n=function(t){const e=v();if(!T(e)||!At(e))return null;const n=t?N:C,r=t?N:j,i=e.anchor,o=e.focus;if(i.is(o))return r;const s=Pt(e);if(1!==s.length)return n;const l=s[0];let u,c;0===l.length&&I(285),e.isBackward()?(u=o,c=i):(u=i,c=o);const g=st(l[0]),a=lt(l[0]),f=b(g.getKey(),0,"text"),p=b(a.getKey(),a.getTextContentSize(),"text");return u.isBefore(f)||p.isBefore(c)?n:f.isBefore(u)||c.isBefore(p)?r:n}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n,void 0),!0)},z),t.registerCommand(j,()=>!!At(v())&&(B([c()]),!0),z),t.registerCommand(C,t=>Lt(C),z),t.registerCommand(N,t=>Lt(N),z),t.registerCommand(O,t=>{const e=v();if(!T(e))return!1;const{anchor:n}=e,r=n.getNode();return!!At(e)&&(e.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&X(r.getParentOrThrow())?(t.preventDefault(),!0):Ot(O,t))},z),t.registerCommand(D,t=>{const e=v();if(!T(e))return!1;const{anchor:n}=e,r=n.getNode();return!!At(e)&&(e.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&X(r.getParentOrThrow())?(t.preventDefault(),!0):Ot(D,t))},z),t.registerCommand(H,t=>Ht(H,t),z),t.registerCommand(F,t=>Ht(F,t),z)),i(...n)}const zt=st,Bt=lt,Dt=gt,Ft=ct;export{rt as $createCodeHighlightNode,U as $createCodeNode,ut as $getCodeLineDirection,gt as $getEndOfCodeInLine,st as $getFirstCodeNodeOfLine,lt as $getLastCodeNodeOfLine,ct as $getStartOfCodeInLine,it as $isCodeHighlightNode,X as $isCodeNode,pt as CODE_LANGUAGE_FRIENDLY_NAME_MAP,ht as CODE_LANGUAGE_MAP,at as CodeExtension,et as CodeHighlightNode,q as CodeNode,M as DEFAULT_CODE_LANGUAGE,bt as PrismTokenizer,xt as getCodeLanguageOptions,yt as getCodeLanguages,_t as getCodeThemeOptions,J as getDefaultCodeLanguage,Dt as getEndOfCodeInLine,zt as getFirstCodeNodeOfLine,mt as getLanguageFriendlyName,Bt as getLastCodeNodeOfLine,Ft as getStartOfCodeInLine,dt as normalizeCodeLang,dt as normalizeCodeLanguage,Et as registerCodeHighlighting};
|
|
9
|
+
import{isHTMLElement as t,addClassNamesToElement as e,removeClassNamesFromElement as n,$getAdjacentCaret as r,mergeRegister as i}from"@lexical/utils";import{ElementNode as o,$createParagraphNode as s,$isTextNode as l,$isTabNode as u,$createTabNode as c,$createLineBreakNode as g,$create as a,TextNode as f,$applyNodeReplacement as p,$getSiblingCaret as h,getTextDirection as d,$isElementNode as m,$isLineBreakNode as y,defineExtension as x,$createTextNode as _,$getNodeByKey as S,$getSelection as v,$isRangeSelection as T,$createPoint as b,INDENT_CONTENT_COMMAND as C,OUTDENT_CONTENT_COMMAND as N,INSERT_TAB_COMMAND as j,$setSelectionFromCaretRange as w,$getCaretRangeInDirection as k,$getCaretRange as A,$getTextPointCaret as P,$normalizeCaret as L,KEY_ARROW_UP_COMMAND as O,MOVE_TO_START as H,KEY_TAB_COMMAND as E,COMMAND_PRIORITY_LOW as z,$insertNodes as B,KEY_ARROW_DOWN_COMMAND as D,MOVE_TO_END as F}from"lexical";import"prismjs";import"prismjs/components/prism-clike.js";import"prismjs/components/prism-javascript.js";import"prismjs/components/prism-markup.js";import"prismjs/components/prism-markdown.js";import"prismjs/components/prism-c.js";import"prismjs/components/prism-css.js";import"prismjs/components/prism-objectivec.js";import"prismjs/components/prism-sql.js";import"prismjs/components/prism-powershell.js";import"prismjs/components/prism-python.js";import"prismjs/components/prism-rust.js";import"prismjs/components/prism-swift.js";import"prismjs/components/prism-typescript.js";import"prismjs/components/prism-java.js";import"prismjs/components/prism-cpp.js";function I(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const M="javascript",J=()=>M;function R(e,n){for(const r of e.childNodes){if(t(r)&&r.tagName===n)return!0;R(r,n)}return!1}const K="data-language",$="data-highlight-language",W="data-theme";class q extends o{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(t){return new q(t.__language,t.__key)}constructor(t,e){super(e),this.__language=t||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(t){super.afterCloneFrom(t),this.__language=t.__language,this.__theme=t.__theme,this.__isSyntaxHighlightSupported=t.__isSyntaxHighlightSupported}createDOM(t){const n=document.createElement("code");e(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(K,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute($,r));const i=this.getTheme();i&&n.setAttribute(W,i);const o=this.getStyle();return o&&n.setAttribute("style",o),n}updateDOM(t,e,n){const r=this.__language,i=t.__language;r?r!==i&&e.setAttribute(K,r):i&&e.removeAttribute(K);const o=this.__isSyntaxHighlightSupported;t.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&e.setAttribute($,r):e.removeAttribute($):o&&r&&e.setAttribute($,r);const s=this.__theme,l=t.__theme;s?s!==l&&e.setAttribute(W,s):l&&e.removeAttribute(W);const u=this.__style,c=t.__style;return u?u!==c&&e.setAttribute("style",u):c&&e.removeAttribute("style"),!1}exportDOM(t){const n=document.createElement("pre");e(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(K,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute($,r));const i=this.getTheme();i&&n.setAttribute(W,i);const o=this.getStyle();return o&&n.setAttribute("style",o),{element:n}}static importDOM(){return{code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||R(t,"BR"))?{conversion:Q,priority:1}:null,div:()=>({conversion:G,priority:1}),pre:()=>({conversion:Q,priority:0}),table:t=>tt(t)?{conversion:V,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&tt(n)?{conversion:Y,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&tt(e)?{conversion:Y,priority:3}:null}}}static importJSON(t){return U().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setLanguage(t.language).setTheme(t.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(t,e=!0){const n=this.getChildren(),r=n.length;if(r>=2&&"\n"===n[r-1].getTextContent()&&"\n"===n[r-2].getTextContent()&&t.isCollapsed()&&t.anchor.key===this.__key&&t.anchor.offset===r){n[r-1].remove(),n[r-2].remove();const t=s();return this.insertAfter(t,e),t}const{anchor:i,focus:o}=t,a=(i.isBefore(o)?i:o).getNode();if(l(a)){let t=st(a);const e=[];for(;;)if(u(t))e.push(c()),t=t.getNextSibling();else{if(!it(t))break;{let n=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&e.push(rt(" ".repeat(n))),n!==i)break;t=t.getNextSibling()}}const n=a.splitText(i.offset)[0],r=0===i.offset?0:1,o=n.getIndexWithinParent()+r,s=a.getParentOrThrow(),l=[g(),...e];s.splice(o,0,l);const f=e[e.length-1];f?f.select():0===i.offset?n.selectPrevious():n.getNextSibling().selectNext(0,0)}if(X(a)){const{offset:e}=t.anchor;a.splice(e,0,[g()]),a.select(e+1,e+1)}return null}canIndent(){return!1}collapseAtStart(){const t=s();return this.getChildren().forEach(e=>t.append(e)),this.replace(t),!0}setLanguage(t){const e=this.getWritable();return e.__language=t||void 0,e}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(t){const e=this.getWritable();return e.__isSyntaxHighlightSupported=t,e}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(t){const e=this.getWritable();return e.__theme=t||void 0,e}getTheme(){return this.getLatest().__theme}}function U(t,e){return a(q).setLanguage(t).setTheme(e)}function X(t){return t instanceof q}function Q(t){return{node:U(t.getAttribute(K))}}function G(t){const e=t,n=Z(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(Z(e))return!0;e=e.parentElement}return!1}(e)?{node:n?U():null}:{node:null}}function V(){return{node:U()}}function Y(){return{node:null}}function Z(t){return null!==t.style.fontFamily.match("monospace")}function tt(t){return t.classList.contains("js-file-line-container")}class et extends f{__highlightType;constructor(t="",e,n){super(t,n),this.__highlightType=e}static getType(){return"code-highlight"}static clone(t){return new et(t.__text,t.__highlightType||void 0,t.__key)}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(t){const e=this.getWritable();return e.__highlightType=t||void 0,e}canHaveFormat(){return!1}createDOM(t){const n=super.createDOM(t),r=nt(t.theme,this.__highlightType);return e(n,r),n}updateDOM(t,r,i){const o=super.updateDOM(t,r,i),s=nt(i.theme,t.__highlightType),l=nt(i.theme,this.__highlightType);return s!==l&&(s&&n(r,s),l&&e(r,l)),o}static importJSON(t){return rt().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setHighlightType(t.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(t){return this}isParentRequired(){return!0}createParentElementNode(){return U()}}function nt(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function rt(t="",e){return p(new et(t,e))}function it(t){return t instanceof et}function ot(t,e){let n=t;for(let i=h(t,e);i&&(it(i.origin)||u(i.origin));i=r(i))n=i.origin;return n}function st(t){return ot(t,"previous")}function lt(t){return ot(t,"next")}function ut(t){const e=st(t),n=lt(t);let r=e;for(;null!==r;){if(it(r)){const t=d(r.getTextContent());if(null!==t)return t}if(r===n)break;r=r.getNextSibling()}const i=e.getParent();if(m(i)){const t=i.getDirection();if("ltr"===t||"rtl"===t)return t}return null}function ct(t,e){let n=null,r=null,i=t,o=e,s=t.getTextContent();for(;;){if(0===o){if(i=i.getPreviousSibling(),null===i)break;if(it(i)||u(i)||y(i)||I(167),y(i)){n={node:i,offset:1};break}o=Math.max(0,i.getTextContentSize()-1),s=i.getTextContent()}else o--;const t=s[o];it(i)&&" "!==t&&(r={node:i,offset:o})}if(null!==r)return r;let l=null;if(e<t.getTextContentSize())it(t)&&(l=t.getTextContent()[e]);else{const e=t.getNextSibling();it(e)&&(l=e.getTextContent()[0])}if(null!==l&&" "!==l)return n;{const r=function(t,e){let n=t,r=e,i=t.getTextContent(),o=t.getTextContentSize();for(;;){if(!it(n)||r===o){if(n=n.getNextSibling(),null===n||y(n))return null;it(n)&&(r=0,i=n.getTextContent(),o=n.getTextContentSize())}if(it(n)){if(" "!==i[r])return{node:n,offset:r};r++}}}(t,e);return null!==r?r:n}}function gt(t){const e=lt(t);return y(e)&&I(168),e}const at=x({name:"@lexical/code",nodes:()=>[q,et]});!function(t){t.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var e={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(e).forEach(function(n){var r=e[n],i=[];/^\w+$/.test(n)||i.push(/\w+/.exec(n)[0]),"diff"===n&&i.push("bold"),t.languages.diff[n]={pattern:RegExp("^(?:["+r+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}}),Object.defineProperty(t.languages.diff,"PREFIXES",{value:e})}(Prism);const ft=globalThis.Prism||window.Prism,pt={c:"C",clike:"C-like",cpp:"C++",css:"CSS",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},ht={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function dt(t){return ht[t]||t}function mt(t){const e=dt(t);return pt[e]||e}const yt=()=>Object.keys(ft.languages).filter(t=>"function"!=typeof ft.languages[t]).sort();function xt(){const t=[];for(const[e,n]of Object.entries(pt))t.push([e,n]);return t}function _t(){return[]}function St(t){return"string"==typeof t?t:Array.isArray(t)?t.map(St).join(""):St(t.content)}function vt(t,e){const n=/^diff-([\w-]+)/i.exec(e),r=t.getTextContent();let i=ft.tokenize(r,ft.languages[n?"diff":e]);return n&&(i=function(t,e){const n=e,r=ft.languages[n],i={tokens:t},o=ft.languages.diff.PREFIXES;for(const t of i.tokens){if("string"==typeof t||!(t.type in o)||!Array.isArray(t.content))continue;const e=t.type;let n=0;const i=()=>(n++,new ft.Token("prefix",o[e],e.replace(/^(\w+).*/,"$1"))),s=t.content.filter(t=>"string"==typeof t||"prefix"!==t.type),l=t.content.length-s.length,u=ft.tokenize(St(s),r);u.unshift(i());const c=/\r\n|\n/g,g=t=>{const e=[];c.lastIndex=0;let r,o=0;for(;n<l&&(r=c.exec(t));){const n=r.index+r[0].length;e.push(t.slice(o,n)),o=n,e.push(i())}if(0!==e.length)return o<t.length&&e.push(t.slice(o)),e},a=t=>{for(let e=0;e<t.length&&n<l;e++){const n=t[e];if("string"==typeof n){const r=g(n);r&&(t.splice(e,1,...r),e+=r.length-1)}else if("string"==typeof n.content){const t=g(n.content);t&&(n.content=t)}else Array.isArray(n.content)?a(n.content):a([n.content])}};a(u),n<l&&u.push(i()),t.content=u}return i.tokens}(i,n[1])),Tt(i)}function Tt(t,e){const n=[];for(const r of t)if("string"==typeof r){const t=r.split(/(\n|\t)/),i=t.length;for(let r=0;r<i;r++){const i=t[r];"\n"===i||"\r\n"===i?n.push(g()):"\t"===i?n.push(c()):i.length>0&&n.push(rt(i,e))}}else{const{content:t,alias:e}=r;"string"==typeof t?n.push(...Tt([t],"prefix"===r.type&&"string"==typeof e?e:r.type)):Array.isArray(t)&&n.push(...Tt(t,"unchanged"===r.type?void 0:r.type))}return n}const bt={$tokenize(t,e){return vt(t,e||this.defaultLanguage)},defaultLanguage:M,tokenize(t,e){return ft.tokenize(t,ft.languages[e||""]||ft.languages[this.defaultLanguage])}};function Ct(t,e,n){const r=t.getParent();X(r)?wt(r,e,n):it(t)&&t.replace(_(t.__text))}function Nt(t,e){const n=e.getElementByKey(t.getKey());if(null===n)return;const r=t.getChildren(),i=r.length;if(i===n.__cachedChildrenLength)return;n.__cachedChildrenLength=i;let o="1",s=1;for(let t=0;t<i;t++)y(r[t])&&(o+="\n"+ ++s);n.setAttribute("data-gutter",o)}const jt=new Set;function wt(t,e,n){const r=t.getKey(),i=e.getKey()+"/"+r;void 0===t.getLanguage()&&t.setLanguage(n.defaultLanguage);const o=t.getLanguage()||n.defaultLanguage;if(!function(t){const e=function(t){const e=/^diff-([\w-]+)/i.exec(t);return e?e[1]:null}(t),n=e||t;try{return!!n&&ft.languages.hasOwnProperty(n)}catch(t){return!1}}(o))return t.getIsSyntaxHighlightSupported()&&t.setIsSyntaxHighlightSupported(!1),void async function(){}();t.getIsSyntaxHighlightSupported()||t.setIsSyntaxHighlightSupported(!0),jt.has(i)||(jt.add(i),e.update(()=>{!function(t,e){const n=S(t);if(!X(n)||!n.isAttached())return;const r=v();if(!T(r))return void e();const i=r.anchor,o=i.offset,s="element"===i.type&&y(n.getChildAtIndex(i.offset-1));let u=0;if(!s){const t=i.getNode();u=o+t.getPreviousSiblings().reduce((t,e)=>t+e.getTextContentSize(),0)}if(!e())return;if(s)return void i.getNode().select(o,o);n.getChildren().some(t=>{const e=l(t);if(e||y(t)){const n=t.getTextContentSize();if(e&&n>=u)return t.select(u,u),!0;u-=n}return!1})}(r,()=>{const e=S(r);if(!X(e)||!e.isAttached())return!1;const i=e.getLanguage()||n.defaultLanguage,o=n.$tokenize(e,i),s=function(t,e){let n=0;for(;n<t.length&&kt(t[n],e[n]);)n++;const r=t.length,i=e.length,o=Math.min(r,i)-n;let s=0;for(;s<o;)if(s++,!kt(t[r-s],e[i-s])){s--;break}const l=n,u=r-s,c=e.slice(n,i-s);return{from:l,nodesForReplacement:c,to:u}}(e.getChildren(),o),{from:l,to:u,nodesForReplacement:c}=s;return!(l===u&&!c.length)&&(t.splice(l,u-l,c),!0)})},{onUpdate:()=>{jt.delete(i)},skipTransforms:!0}))}function kt(t,e){return it(t)&&it(e)&&t.__text===e.__text&&t.__highlightType===e.__highlightType||u(t)&&u(e)||y(t)&&y(e)}function At(t){if(!T(t))return!1;const e=t.anchor.getNode(),n=X(e)?e:e.getParent(),r=t.focus.getNode(),i=X(r)?r:r.getParent();return X(n)&&n.is(i)}function Pt(t){const e=t.getNodes(),n=[];if(1===e.length&&X(e[0]))return n;let r=[];for(let t=0;t<e.length;t++){const i=e[t];it(i)||u(i)||y(i)||I(169),y(i)?r.length>0&&(n.push(r),r=[]):r.push(i)}if(r.length>0){const e=t.isBackward()?t.anchor:t.focus,i=b(r[0].getKey(),0,"text");e.is(i)||n.push(r)}return n}function Lt(t){const e=v();if(!T(e)||!At(e))return!1;const n=Pt(e),r=n.length;if(0===r&&e.isCollapsed())return t===C&&e.insertNodes([c()]),!0;if(0===r&&t===C&&"\n"===e.getTextContent()){const t=c(),n=g(),r=e.isBackward()?"previous":"next";return e.insertNodes([t,n]),w(k(A(P(t,"next",0),L(h(n,"next"))),r)),!0}for(let i=0;i<r;i++){const r=n[i];if(r.length>0){let n=r[0];if(0===i&&(n=st(n)),t===C){const t=c();if(n.insertBefore(t),0===i){const r=e.isBackward()?"focus":"anchor",i=b(n.getKey(),0,"text");e[r].is(i)&&e[r].set(t.getKey(),0,"text")}}else u(n)&&n.remove()}}return!0}function Ot(t,e){const n=v();if(!T(n))return!1;const{anchor:r,focus:i}=n,o=r.offset,s=i.offset,l=r.getNode(),c=i.getNode(),g=t===O;if(!At(n)||!it(l)&&!u(l)||!it(c)&&!u(c))return!1;if(!e.altKey){if(n.isCollapsed()){const t=l.getParentOrThrow();if(g&&0===o&&null===l.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!0}else if(!g&&o===l.getTextContentSize()&&null===l.getNextSibling()){if(null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!0}}return!1}let a,f;if(l.isBefore(c)?(a=st(l),f=lt(c)):(a=st(c),f=lt(l)),null==a||null==f)return!1;const p=a.getNodesBetween(f);for(let t=0;t<p.length;t++){const e=p[t];if(!it(e)&&!u(e)&&!y(e))return!1}e.preventDefault(),e.stopPropagation();const h=g?a.getPreviousSibling():f.getNextSibling();if(!y(h))return!0;const d=g?h.getPreviousSibling():h.getNextSibling();if(null==d)return!0;const m=it(d)||u(d)||y(d)?g?st(d):lt(d):null;let x=null!=m?m:d;return h.remove(),p.forEach(t=>t.remove()),t===O?(p.forEach(t=>x.insertBefore(t)),x.insertBefore(h)):(x.insertAfter(h),x=h,p.forEach(t=>{x.insertAfter(t),x=t})),n.setTextNodeRange(l,o,c,s),!0}function Ht(t,e){const n=v();if(!T(n))return!1;const{anchor:r,focus:i}=n,o=r.getNode(),s=i.getNode(),l=t===H;if(!At(n)||!it(o)&&!u(o)||!it(s)&&!u(s))return!1;const c=s;if("rtl"===ut(c)?!l:l){const t=ct(c,i.offset);if(null!==t){const{node:e,offset:r}=t;y(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r)}else c.getParentOrThrow().selectStart()}else{gt(c).select()}return e.preventDefault(),e.stopPropagation(),!0}function Et(t,e){if(!t.hasNodes([q,et]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");null==e&&(e=bt);const n=[];return!0!==t._headless&&n.push(t.registerMutationListener(q,e=>{t.getEditorState().read(()=>{for(const[n,r]of e)if("destroyed"!==r){const e=S(n);null!==e&&Nt(e,t)}})},{skipInitialization:!1})),n.push(t.registerNodeTransform(q,n=>wt(n,t,e)),t.registerNodeTransform(f,n=>Ct(n,t,e)),t.registerNodeTransform(et,n=>Ct(n,t,e)),t.registerCommand(E,e=>{const n=function(t){const e=v();if(!T(e)||!At(e))return null;const n=t?N:C,r=t?N:j,i=e.anchor,o=e.focus;if(i.is(o))return r;const s=Pt(e);if(1!==s.length)return n;const l=s[0];let u,c;0===l.length&&I(285),e.isBackward()?(u=o,c=i):(u=i,c=o);const g=st(l[0]),a=lt(l[0]),f=b(g.getKey(),0,"text"),p=b(a.getKey(),a.getTextContentSize(),"text");return u.isBefore(f)||p.isBefore(c)?n:f.isBefore(u)||c.isBefore(p)?r:n}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n,void 0),!0)},z),t.registerCommand(j,()=>!!At(v())&&(B([c()]),!0),z),t.registerCommand(C,t=>Lt(C),z),t.registerCommand(N,t=>Lt(N),z),t.registerCommand(O,t=>{const e=v();if(!T(e))return!1;const{anchor:n}=e,r=n.getNode();return!!At(e)&&(e.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&X(r.getParentOrThrow())?(t.preventDefault(),!0):Ot(O,t))},z),t.registerCommand(D,t=>{const e=v();if(!T(e))return!1;const{anchor:n}=e,r=n.getNode();return!!At(e)&&(e.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&X(r.getParentOrThrow())?(t.preventDefault(),!0):Ot(D,t))},z),t.registerCommand(H,t=>Ht(H,t),z),t.registerCommand(F,t=>Ht(F,t),z)),i(...n)}const zt=st,Bt=lt,Dt=gt,Ft=ct;export{rt as $createCodeHighlightNode,U as $createCodeNode,ut as $getCodeLineDirection,gt as $getEndOfCodeInLine,st as $getFirstCodeNodeOfLine,lt as $getLastCodeNodeOfLine,ct as $getStartOfCodeInLine,it as $isCodeHighlightNode,X as $isCodeNode,pt as CODE_LANGUAGE_FRIENDLY_NAME_MAP,ht as CODE_LANGUAGE_MAP,at as CodeExtension,et as CodeHighlightNode,q as CodeNode,M as DEFAULT_CODE_LANGUAGE,bt as PrismTokenizer,xt as getCodeLanguageOptions,yt as getCodeLanguages,_t as getCodeThemeOptions,J as getDefaultCodeLanguage,Dt as getEndOfCodeInLine,zt as getFirstCodeNodeOfLine,mt as getLanguageFriendlyName,Bt as getLastCodeNodeOfLine,Ft as getStartOfCodeInLine,dt as normalizeCodeLang,dt as normalizeCodeLanguage,Et as registerCodeHighlighting};
|
package/package.json
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"code"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.38.3-nightly.
|
|
11
|
+
"version": "0.38.3-nightly.20251104.0",
|
|
12
12
|
"main": "LexicalCode.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/utils": "0.38.3-nightly.
|
|
16
|
-
"lexical": "0.38.3-nightly.
|
|
15
|
+
"@lexical/utils": "0.38.3-nightly.20251104.0",
|
|
16
|
+
"lexical": "0.38.3-nightly.20251104.0",
|
|
17
17
|
"prismjs": "^1.30.0"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|