@lexical/code 0.26.0 → 0.26.1-nightly.20250303.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 +19 -13
- package/LexicalCode.dev.mjs +19 -13
- package/LexicalCode.prod.js +1 -1
- package/LexicalCode.prod.mjs +1 -1
- package/package.json +3 -3
package/LexicalCode.dev.js
CHANGED
|
@@ -27,6 +27,20 @@ require('prismjs/components/prism-typescript');
|
|
|
27
27
|
require('prismjs/components/prism-java');
|
|
28
28
|
require('prismjs/components/prism-cpp');
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
32
|
+
*
|
|
33
|
+
* This source code is licensed under the MIT license found in the
|
|
34
|
+
* LICENSE file in the root directory of this source tree.
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
// Do not require this module directly! Use normal `invariant` calls.
|
|
39
|
+
|
|
40
|
+
function formatDevErrorMessage(message) {
|
|
41
|
+
throw new Error(message);
|
|
42
|
+
}
|
|
43
|
+
|
|
30
44
|
/**
|
|
31
45
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
32
46
|
*
|
|
@@ -513,14 +527,6 @@ function $getLastCodeNodeOfLine(anchor) {
|
|
|
513
527
|
return $getLastMatchingCodeNode(anchor, 'next');
|
|
514
528
|
}
|
|
515
529
|
|
|
516
|
-
/**
|
|
517
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
518
|
-
*
|
|
519
|
-
* This source code is licensed under the MIT license found in the
|
|
520
|
-
* LICENSE file in the root directory of this source tree.
|
|
521
|
-
*
|
|
522
|
-
*/
|
|
523
|
-
|
|
524
530
|
const PrismTokenizer = {
|
|
525
531
|
defaultLanguage: DEFAULT_CODE_LANGUAGE,
|
|
526
532
|
tokenize(code, language) {
|
|
@@ -541,7 +547,7 @@ function $getStartOfCodeInLine(anchor, offset) {
|
|
|
541
547
|
break;
|
|
542
548
|
}
|
|
543
549
|
if (!($isCodeHighlightNode(node) || lexical.$isTabNode(node) || lexical.$isLineBreakNode(node))) {
|
|
544
|
-
|
|
550
|
+
formatDevErrorMessage(`Expected a valid Code Node: CodeHighlightNode, TabNode, LineBreakNode`);
|
|
545
551
|
}
|
|
546
552
|
if (lexical.$isLineBreakNode(node)) {
|
|
547
553
|
last = {
|
|
@@ -623,7 +629,7 @@ function findNextNonBlankInLine(anchor, offset) {
|
|
|
623
629
|
function $getEndOfCodeInLine(anchor) {
|
|
624
630
|
const lastNode = $getLastCodeNodeOfLine(anchor);
|
|
625
631
|
if (!!lexical.$isLineBreakNode(lastNode)) {
|
|
626
|
-
|
|
632
|
+
formatDevErrorMessage(`Unexpected lineBreakNode in getEndOfCodeInLine`);
|
|
627
633
|
}
|
|
628
634
|
return lastNode;
|
|
629
635
|
}
|
|
@@ -856,7 +862,7 @@ function $getCodeLines(selection) {
|
|
|
856
862
|
for (let i = 0; i < nodes.length; i++) {
|
|
857
863
|
const node = nodes[i];
|
|
858
864
|
if (!($isCodeHighlightNode(node) || lexical.$isTabNode(node) || lexical.$isLineBreakNode(node))) {
|
|
859
|
-
|
|
865
|
+
formatDevErrorMessage(`Expected selection to be inside CodeBlock and consisting of CodeHighlightNode, TabNode and LineBreakNode`);
|
|
860
866
|
}
|
|
861
867
|
if (lexical.$isLineBreakNode(node)) {
|
|
862
868
|
if (i !== 0 && lastLine.length > 0) {
|
|
@@ -885,7 +891,7 @@ function $handleTab(shiftKey) {
|
|
|
885
891
|
const selectionNodes = selection.getNodes();
|
|
886
892
|
const firstNode = selectionNodes[0];
|
|
887
893
|
if (!($isCodeNode(firstNode) || $isCodeHighlightNode(firstNode) || lexical.$isTabNode(firstNode) || lexical.$isLineBreakNode(firstNode))) {
|
|
888
|
-
|
|
894
|
+
formatDevErrorMessage(`Expected selection firstNode to be CodeHighlightNode or TabNode`);
|
|
889
895
|
}
|
|
890
896
|
if ($isCodeNode(firstNode)) {
|
|
891
897
|
return indentOrOutdent;
|
|
@@ -941,7 +947,7 @@ function $handleMultilineIndent(type) {
|
|
|
941
947
|
const selectionNodes = selection.getNodes();
|
|
942
948
|
const firstNode = selectionNodes[0];
|
|
943
949
|
if (!($isCodeNode(firstNode) || $isCodeHighlightNode(firstNode) || lexical.$isTabNode(firstNode) || lexical.$isLineBreakNode(firstNode))) {
|
|
944
|
-
|
|
950
|
+
formatDevErrorMessage(`Expected selection firstNode to be CodeHighlightNode or CodeTabNode`);
|
|
945
951
|
}
|
|
946
952
|
if ($isCodeNode(firstNode)) {
|
|
947
953
|
// CodeNode is empty
|
package/LexicalCode.dev.mjs
CHANGED
|
@@ -25,6 +25,20 @@ import 'prismjs/components/prism-typescript.js';
|
|
|
25
25
|
import 'prismjs/components/prism-java.js';
|
|
26
26
|
import 'prismjs/components/prism-cpp.js';
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
30
|
+
*
|
|
31
|
+
* This source code is licensed under the MIT license found in the
|
|
32
|
+
* LICENSE file in the root directory of this source tree.
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
// Do not require this module directly! Use normal `invariant` calls.
|
|
37
|
+
|
|
38
|
+
function formatDevErrorMessage(message) {
|
|
39
|
+
throw new Error(message);
|
|
40
|
+
}
|
|
41
|
+
|
|
28
42
|
/**
|
|
29
43
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
30
44
|
*
|
|
@@ -511,14 +525,6 @@ function $getLastCodeNodeOfLine(anchor) {
|
|
|
511
525
|
return $getLastMatchingCodeNode(anchor, 'next');
|
|
512
526
|
}
|
|
513
527
|
|
|
514
|
-
/**
|
|
515
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
516
|
-
*
|
|
517
|
-
* This source code is licensed under the MIT license found in the
|
|
518
|
-
* LICENSE file in the root directory of this source tree.
|
|
519
|
-
*
|
|
520
|
-
*/
|
|
521
|
-
|
|
522
528
|
const PrismTokenizer = {
|
|
523
529
|
defaultLanguage: DEFAULT_CODE_LANGUAGE,
|
|
524
530
|
tokenize(code, language) {
|
|
@@ -539,7 +545,7 @@ function $getStartOfCodeInLine(anchor, offset) {
|
|
|
539
545
|
break;
|
|
540
546
|
}
|
|
541
547
|
if (!($isCodeHighlightNode(node) || $isTabNode(node) || $isLineBreakNode(node))) {
|
|
542
|
-
|
|
548
|
+
formatDevErrorMessage(`Expected a valid Code Node: CodeHighlightNode, TabNode, LineBreakNode`);
|
|
543
549
|
}
|
|
544
550
|
if ($isLineBreakNode(node)) {
|
|
545
551
|
last = {
|
|
@@ -621,7 +627,7 @@ function findNextNonBlankInLine(anchor, offset) {
|
|
|
621
627
|
function $getEndOfCodeInLine(anchor) {
|
|
622
628
|
const lastNode = $getLastCodeNodeOfLine(anchor);
|
|
623
629
|
if (!!$isLineBreakNode(lastNode)) {
|
|
624
|
-
|
|
630
|
+
formatDevErrorMessage(`Unexpected lineBreakNode in getEndOfCodeInLine`);
|
|
625
631
|
}
|
|
626
632
|
return lastNode;
|
|
627
633
|
}
|
|
@@ -854,7 +860,7 @@ function $getCodeLines(selection) {
|
|
|
854
860
|
for (let i = 0; i < nodes.length; i++) {
|
|
855
861
|
const node = nodes[i];
|
|
856
862
|
if (!($isCodeHighlightNode(node) || $isTabNode(node) || $isLineBreakNode(node))) {
|
|
857
|
-
|
|
863
|
+
formatDevErrorMessage(`Expected selection to be inside CodeBlock and consisting of CodeHighlightNode, TabNode and LineBreakNode`);
|
|
858
864
|
}
|
|
859
865
|
if ($isLineBreakNode(node)) {
|
|
860
866
|
if (i !== 0 && lastLine.length > 0) {
|
|
@@ -883,7 +889,7 @@ function $handleTab(shiftKey) {
|
|
|
883
889
|
const selectionNodes = selection.getNodes();
|
|
884
890
|
const firstNode = selectionNodes[0];
|
|
885
891
|
if (!($isCodeNode(firstNode) || $isCodeHighlightNode(firstNode) || $isTabNode(firstNode) || $isLineBreakNode(firstNode))) {
|
|
886
|
-
|
|
892
|
+
formatDevErrorMessage(`Expected selection firstNode to be CodeHighlightNode or TabNode`);
|
|
887
893
|
}
|
|
888
894
|
if ($isCodeNode(firstNode)) {
|
|
889
895
|
return indentOrOutdent;
|
|
@@ -939,7 +945,7 @@ function $handleMultilineIndent(type) {
|
|
|
939
945
|
const selectionNodes = selection.getNodes();
|
|
940
946
|
const firstNode = selectionNodes[0];
|
|
941
947
|
if (!($isCodeNode(firstNode) || $isCodeHighlightNode(firstNode) || $isTabNode(firstNode) || $isLineBreakNode(firstNode))) {
|
|
942
|
-
|
|
948
|
+
formatDevErrorMessage(`Expected selection firstNode to be CodeHighlightNode or CodeTabNode`);
|
|
943
949
|
}
|
|
944
950
|
if ($isCodeNode(firstNode)) {
|
|
945
951
|
// CodeNode is empty
|
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");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");"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function n(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var r=n((function(e){const t=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",e);for(let e=1;e<arguments.length;e++)n.append("v",arguments[e]);throw t.search=n.toString(),Error(`Minified Lexical error #${e}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const o=globalThis.Prism||window.Prism,i=e=>{try{return!!e&&o.languages.hasOwnProperty(e)}catch(e){return!1}};function s(t,n){for(const r of t.childNodes){if(e.isHTMLElement(r)&&r.tagName===n)return!0;s(r,n)}return!1}const a="data-language",l="data-highlight-language";class u extends t.ElementNode{static getType(){return"code"}static clone(e){return new u(e.__language,e.__key)}constructor(e,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=i(e)}createDOM(t){const n=document.createElement("code");e.addClassNamesToElement(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(a,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(l,r)),n}updateDOM(e,t,n){const r=this.__language,o=e.__language;return r?r!==o&&(t.setAttribute(a,r),this.__isSyntaxHighlightSupported&&t.setAttribute(l,r)):o&&(t.removeAttribute(a),e.__isSyntaxHighlightSupported&&t.removeAttribute(l)),!1}exportDOM(t){const n=document.createElement("pre");e.addClassNamesToElement(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(a,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(l,r)),{element:n}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||s(e,"BR"))?{conversion:d,priority:1}:null,div:()=>({conversion:p,priority:1}),pre:()=>({conversion:d,priority:0}),table:e=>T(e)?{conversion:f,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&T(n)?{conversion:h,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&T(t)?{conversion:h,priority:3}:null}}}static importJSON(e){return g().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage()}}insertNewAfter(e,n=!0){const r=this.getChildren(),o=r.length;if(o>=2&&"\n"===r[o-1].getTextContent()&&"\n"===r[o-2].getTextContent()&&e.isCollapsed()&&e.anchor.key===this.__key&&e.anchor.offset===o){r[o-1].remove(),r[o-2].remove();const e=t.$createParagraphNode();return this.insertAfter(e,n),e}const{anchor:i,focus:s}=e,a=(i.isBefore(s)?i:s).getNode();if(t.$isTextNode(a)){let e=L(a);const n=[];for(;;)if(t.$isTabNode(e))n.push(t.$createTabNode()),e=e.getNextSibling();else{if(!$(e))break;{let t=0;const r=e.getTextContent(),o=e.getTextContentSize();for(;t<o&&" "===r[t];)t++;if(0!==t&&n.push(y(" ".repeat(t))),t!==o)break;e=e.getNextSibling()}}const r=a.splitText(i.offset)[0],o=0===i.offset?0:1,s=r.getIndexWithinParent()+o,l=a.getParentOrThrow(),u=[t.$createLineBreakNode(),...n];l.splice(s,0,u);const g=n[n.length-1];g?g.select():0===i.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.__isSyntaxHighlightSupported=i(e),t}getLanguage(){return this.getLatest().__language}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}}function g(e){return t.$applyNodeReplacement(new u(e))}function c(e){return e instanceof u}function d(e){return{node:g(e.getAttribute(a))}}function p(e){const t=e,n=N(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(N(t))return!0;t=t.parentElement}return!1}(t)?{node:n?g():null}:{node:null}}function f(){return{node:g()}}function h(){return{node:null}}function N(e){return null!==e.style.fontFamily.match("monospace")}function T(e){return e.classList.contains("js-file-line-container")}const m="javascript",_={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"},C={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function O(e){return C[e]||e}class x extends t.TextNode{constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new x(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=S(t.theme,this.__highlightType);return e.addClassNamesToElement(n,r),n}updateDOM(t,n,r){const o=super.updateDOM(t,n,r),i=S(r.theme,t.__highlightType),s=S(r.theme,this.__highlightType);return i!==s&&(i&&e.removeClassNamesFromElement(n,i),s&&e.addClassNamesToElement(n,s)),o}static importJSON(e){return y().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 S(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function y(e="",n){return t.$applyNodeReplacement(new x(e,n))}function $(e){return e instanceof x}function M(n,r){let o=n;for(let i=t.$getSiblingCaret(n,r);i&&($(i.origin)||t.$isTabNode(i.origin));i=e.$getAdjacentCaret(i))o=i.origin;return o}function L(e){return M(e,"previous")}function b(e){return M(e,"next")}const A={defaultLanguage:m,tokenize(e,t){return o.tokenize(e,o.languages[t||""]||o.languages[this.defaultLanguage])}};function E(e,n){let o=null,i=null,s=e,a=n,l=e.getTextContent();for(;;){if(0===a){if(s=s.getPreviousSibling(),null===s)break;if($(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||r(167),t.$isLineBreakNode(s)){o={node:s,offset:1};break}a=Math.max(0,s.getTextContentSize()-1),l=s.getTextContent()}else a--;const e=l[a];$(s)&&" "!==e&&(i={node:s,offset:a})}if(null!==i)return i;let u=null;if(n<e.getTextContentSize())$(e)&&(u=e.getTextContent()[n]);else{const t=e.getNextSibling();$(t)&&(u=t.getTextContent()[0])}if(null!==u&&" "!==u)return o;{const r=function(e,n){let r=e,o=n,i=e.getTextContent(),s=e.getTextContentSize();for(;;){if(!$(r)||o===s){if(r=r.getNextSibling(),null===r||t.$isLineBreakNode(r))return null;$(r)&&(o=0,i=r.getTextContent(),s=r.getTextContentSize())}if($(r)){if(" "!==i[o])return{node:r,offset:o};o++}}}(e,n);return null!==r?r:o}}function D(e){const n=b(e);return t.$isLineBreakNode(n)&&r(168),n}function v(e,n,r){const o=e.getParent();c(o)?P(o,n,r):$(e)&&e.replace(t.$createTextNode(e.__text))}function R(e,n){const r=n.getElementByKey(e.getKey());if(null===r)return;const o=e.getChildren(),i=o.length;if(i===r.__cachedChildrenLength)return;r.__cachedChildrenLength=i;let s="1",a=1;for(let e=0;e<i;e++)t.$isLineBreakNode(o[e])&&(s+="\n"+ ++a);r.setAttribute("data-gutter",s)}const k=new Set;function P(e,n,r){const o=e.getKey();k.has(o)||(k.add(o),void 0===e.getLanguage()&&e.setLanguage(r.defaultLanguage),n.update((()=>{!function(e,n){const r=t.$getNodeByKey(e);if(!c(r)||!r.isAttached())return;const o=t.$getSelection();if(!t.$isRangeSelection(o))return void n();const i=o.anchor,s=i.offset,a="element"===i.type&&t.$isLineBreakNode(r.getChildAtIndex(i.offset-1));let l=0;if(!a){const e=i.getNode();l=s+e.getPreviousSiblings().reduce(((e,t)=>e+t.getTextContentSize()),0)}if(!n())return;if(a)return void i.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}))}(o,(()=>{const n=t.$getNodeByKey(o);if(!c(n)||!n.isAttached())return!1;const i=n.getTextContent(),s=B(r.tokenize(i,n.getLanguage()||r.defaultLanguage)),a=function(e,t){let n=0;for(;n<e.length&&w(e[n],t[n]);)n++;const r=e.length,o=t.length,i=Math.min(r,o)-n;let s=0;for(;s<i;)if(s++,!w(e[r-s],t[o-s])){s--;break}const a=n,l=r-s,u=t.slice(n,o-s);return{from:a,nodesForReplacement:u,to:l}}(n.getChildren(),s),{from:l,to:u,nodesForReplacement:g}=a;return!(l===u&&!g.length)&&(e.splice(l,u-l,g),!0)}))}),{onUpdate:()=>{k.delete(o)},skipTransforms:!0}))}function B(e,n){const r=[];for(const o of e)if("string"==typeof o){const e=o.split(/(\n|\t)/),i=e.length;for(let o=0;o<i;o++){const i=e[o];"\n"===i||"\r\n"===i?r.push(t.$createLineBreakNode()):"\t"===i?r.push(t.$createTabNode()):i.length>0&&r.push(y(i,n))}}else{const{content:e}=o;"string"==typeof e?r.push(...B([e],o.type)):Array.isArray(e)&&r.push(...B(e,o.type))}return r}function w(e,n){return $(e)&&$(n)&&e.__text===n.__text&&e.__highlightType===n.__highlightType||t.$isTabNode(e)&&t.$isTabNode(n)||t.$isLineBreakNode(e)&&t.$isLineBreakNode(n)}function I(e){if(!t.$isRangeSelection(e))return!1;const n=e.anchor.getNode(),r=e.focus.getNode();if(n.is(r)&&c(n))return!0;const o=n.getParent();return c(o)&&o.is(r.getParent())}function j(e){const n=e.getNodes(),o=[[]];if(1===n.length&&c(n[0]))return o;let i=o[0];for(let e=0;e<n.length;e++){const s=n[e];$(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||r(169),t.$isLineBreakNode(s)?0!==e&&i.length>0&&(i=[],o.push(i)):i.push(s)}return o}function H(e){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!I(n))return!1;const o=j(n),i=o.length;if(o.length>1){for(let n=0;n<i;n++){const r=o[n];if(r.length>0){let o=r[0];0===n&&(o=L(o)),null!==o&&(e===t.INDENT_CONTENT_COMMAND?o.insertBefore(t.$createTabNode()):t.$isTabNode(o)&&o.remove())}}return!0}const s=n.getNodes()[0];if(c(s)||$(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||r(171),c(s))return e===t.INDENT_CONTENT_COMMAND&&n.insertNodes([t.$createTabNode()]),!0;const a=L(s);return e===t.INDENT_CONTENT_COMMAND?t.$isLineBreakNode(a)?a.insertAfter(t.$createTabNode()):a.insertBefore(t.$createTabNode()):t.$isTabNode(a)&&a.remove(),!0}function q(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:o,focus:i}=r,s=o.offset,a=i.offset,l=o.getNode(),u=i.getNode(),g=e===t.KEY_ARROW_UP_COMMAND;if(!I(r)||!$(l)&&!t.$isTabNode(l)||!$(u)&&!t.$isTabNode(u))return!1;if(!n.altKey){if(r.isCollapsed()){const e=l.getParentOrThrow();if(g&&0===s&&null===l.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),n.preventDefault(),!0}else if(!g&&s===l.getTextContentSize()&&null===l.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),n.preventDefault(),!0}}return!1}let c,d;if(l.isBefore(u)?(c=L(l),d=b(u)):(c=L(u),d=b(l)),null==c||null==d)return!1;const p=c.getNodesBetween(d);for(let e=0;e<p.length;e++){const n=p[e];if(!$(n)&&!t.$isTabNode(n)&&!t.$isLineBreakNode(n))return!1}n.preventDefault(),n.stopPropagation();const f=g?c.getPreviousSibling():d.getNextSibling();if(!t.$isLineBreakNode(f))return!0;const h=g?f.getPreviousSibling():f.getNextSibling();if(null==h)return!0;const N=$(h)||t.$isTabNode(h)||t.$isLineBreakNode(h)?g?L(h):b(h):null;let T=null!=N?N:h;return f.remove(),p.forEach((e=>e.remove())),e===t.KEY_ARROW_UP_COMMAND?(p.forEach((e=>T.insertBefore(e))),T.insertBefore(f)):(T.insertAfter(f),T=f,p.forEach((e=>{T.insertAfter(e),T=e}))),r.setTextNodeRange(l,s,u,a),!0}function W(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:o,focus:i}=r,s=o.getNode(),a=i.getNode(),l=e===t.MOVE_TO_START;if(!I(r)||!$(s)&&!t.$isTabNode(s)||!$(a)&&!t.$isTabNode(a))return!1;if(l){const e=E(a,i.offset);if(null!==e){const{node:n,offset:o}=e;t.$isLineBreakNode(n)?n.selectNext(0,0):r.setTextNodeRange(n,o,n,o)}else a.getParentOrThrow().selectStart()}else{D(a).select()}return n.preventDefault(),n.stopPropagation(),!0}const F=L,K=b,z=D,Y=E;exports.$createCodeHighlightNode=y,exports.$createCodeNode=g,exports.$getEndOfCodeInLine=D,exports.$getFirstCodeNodeOfLine=L,exports.$getLastCodeNodeOfLine=b,exports.$getStartOfCodeInLine=E,exports.$isCodeHighlightNode=$,exports.$isCodeNode=c,exports.CODE_LANGUAGE_FRIENDLY_NAME_MAP=_,exports.CODE_LANGUAGE_MAP=C,exports.CodeHighlightNode=x,exports.CodeNode=u,exports.DEFAULT_CODE_LANGUAGE=m,exports.PrismTokenizer=A,exports.getCodeLanguages=()=>Object.keys(o.languages).filter((e=>"function"!=typeof o.languages[e])).sort(),exports.getDefaultCodeLanguage=()=>m,exports.getEndOfCodeInLine=z,exports.getFirstCodeNodeOfLine=F,exports.getLanguageFriendlyName=function(e){const t=O(e);return _[t]||t},exports.getLastCodeNodeOfLine=K,exports.getStartOfCodeInLine=Y,exports.normalizeCodeLang=O,exports.registerCodeHighlighting=function(n,o){if(!n.hasNodes([u,x]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return null==o&&(o=A),e.mergeRegister(n.registerMutationListener(u,(e=>{n.update((()=>{for(const[r,o]of e)if("destroyed"!==o){const e=t.$getNodeByKey(r);null!==e&&R(e,n)}}))}),{skipInitialization:!1}),n.registerNodeTransform(u,(e=>P(e,n,o))),n.registerNodeTransform(t.TextNode,(e=>v(e,n,o))),n.registerNodeTransform(x,(e=>v(e,n,o))),n.registerCommand(t.KEY_TAB_COMMAND,(e=>{const o=function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!I(n))return null;const o=e?t.OUTDENT_CONTENT_COMMAND:t.INDENT_CONTENT_COMMAND,i=e?t.OUTDENT_CONTENT_COMMAND:t.INSERT_TAB_COMMAND;if(j(n).length>1)return o;const s=n.getNodes()[0];if(c(s)||$(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||r(170),c(s))return o;const a=L(s),l=b(s),u=n.anchor,g=n.focus;let d,p;return g.isBefore(u)?(d=g,p=u):(d=u,p=g),null!==a&&null!==l&&d.key===a.getKey()&&0===d.offset&&p.key===l.getKey()&&p.offset===l.getTextContentSize()?o:i}(e.shiftKey);return null!==o&&(e.preventDefault(),n.dispatchCommand(o,void 0),!0)}),t.COMMAND_PRIORITY_LOW),n.registerCommand(t.INSERT_TAB_COMMAND,(()=>!!I(t.$getSelection())&&(t.$insertNodes([t.$createTabNode()]),!0)),t.COMMAND_PRIORITY_LOW),n.registerCommand(t.INDENT_CONTENT_COMMAND,(e=>H(t.INDENT_CONTENT_COMMAND)),t.COMMAND_PRIORITY_LOW),n.registerCommand(t.OUTDENT_CONTENT_COMMAND,(e=>H(t.OUTDENT_CONTENT_COMMAND)),t.COMMAND_PRIORITY_LOW),n.registerCommand(t.KEY_ARROW_UP_COMMAND,(e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,o=r.getNode();return!!I(n)&&(n.isCollapsed()&&0===r.offset&&null===o.getPreviousSibling()&&c(o.getParentOrThrow())?(e.preventDefault(),!0):q(t.KEY_ARROW_UP_COMMAND,e))}),t.COMMAND_PRIORITY_LOW),n.registerCommand(t.KEY_ARROW_DOWN_COMMAND,(e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,o=r.getNode();return!!I(n)&&(n.isCollapsed()&&r.offset===o.getTextContentSize()&&null===o.getNextSibling()&&c(o.getParentOrThrow())?(e.preventDefault(),!0):q(t.KEY_ARROW_DOWN_COMMAND,e))}),t.COMMAND_PRIORITY_LOW),n.registerCommand(t.MOVE_TO_START,(e=>W(t.MOVE_TO_START,e)),t.COMMAND_PRIORITY_LOW),n.registerCommand(t.MOVE_TO_END,(e=>W(t.MOVE_TO_END,e)),t.COMMAND_PRIORITY_LOW))};
|
|
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=globalThis.Prism||window.Prism,o=e=>{try{return!!e&&r.languages.hasOwnProperty(e)}catch(e){return!1}};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 s="data-language",a="data-highlight-language";class l extends t.ElementNode{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=o(e)}createDOM(t){const n=document.createElement("code");e.addClassNamesToElement(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(s,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(a,r)),n}updateDOM(e,t,n){const r=this.__language,o=e.__language;return r?r!==o&&(t.setAttribute(s,r),this.__isSyntaxHighlightSupported&&t.setAttribute(a,r)):o&&(t.removeAttribute(s),e.__isSyntaxHighlightSupported&&t.removeAttribute(a)),!1}exportDOM(t){const n=document.createElement("pre");e.addClassNamesToElement(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(s,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(a,r)),{element:n}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||i(e,"BR"))?{conversion:c,priority:1}:null,div:()=>({conversion:d,priority:1}),pre:()=>({conversion:c,priority:0}),table:e=>h(e)?{conversion:p,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&h(n)?{conversion:f,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&h(t)?{conversion:f,priority:3}:null}}}static importJSON(e){return g().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage()}}insertNewAfter(e,n=!0){const r=this.getChildren(),o=r.length;if(o>=2&&"\n"===r[o-1].getTextContent()&&"\n"===r[o-2].getTextContent()&&e.isCollapsed()&&e.anchor.key===this.__key&&e.anchor.offset===o){r[o-1].remove(),r[o-2].remove();const e=t.$createParagraphNode();return this.insertAfter(e,n),e}const{anchor:i,focus:s}=e,a=(i.isBefore(s)?i:s).getNode();if(t.$isTextNode(a)){let e=y(a);const n=[];for(;;)if(t.$isTabNode(e))n.push(t.$createTabNode()),e=e.getNextSibling();else{if(!$(e))break;{let t=0;const r=e.getTextContent(),o=e.getTextContentSize();for(;t<o&&" "===r[t];)t++;if(0!==t&&n.push(S(" ".repeat(t))),t!==o)break;e=e.getNextSibling()}}const r=a.splitText(i.offset)[0],o=0===i.offset?0:1,s=r.getIndexWithinParent()+o,l=a.getParentOrThrow(),g=[t.$createLineBreakNode(),...n];l.splice(s,0,g);const u=n[n.length-1];u?u.select():0===i.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(u(a)){const{offset:n}=e.anchor;a.splice(n,0,[t.$createLineBreakNode()]),a.select(n+1,n+1)}return null}canIndent(){return!1}collapseAtStart(){const e=t.$createParagraphNode();return this.getChildren().forEach((t=>e.append(t))),this.replace(e),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t.__isSyntaxHighlightSupported=o(e),t}getLanguage(){return this.getLatest().__language}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}}function g(e){return t.$applyNodeReplacement(new l(e))}function u(e){return e instanceof l}function c(e){return{node:g(e.getAttribute(s))}}function d(e){const t=e,n=N(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(N(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 N(e){return null!==e.style.fontFamily.match("monospace")}function h(e){return e.classList.contains("js-file-line-container")}const m="javascript",T={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"},_={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function C(e){return _[e]||e}class O extends t.TextNode{constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new O(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=x(t.theme,this.__highlightType);return e.addClassNamesToElement(n,r),n}updateDOM(t,n,r){const o=super.updateDOM(t,n,r),i=x(r.theme,t.__highlightType),s=x(r.theme,this.__highlightType);return i!==s&&(i&&e.removeClassNamesFromElement(n,i),s&&e.addClassNamesToElement(n,s)),o}static importJSON(e){return S().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 x(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function S(e="",n){return t.$applyNodeReplacement(new O(e,n))}function $(e){return e instanceof O}function M(n,r){let o=n;for(let i=t.$getSiblingCaret(n,r);i&&($(i.origin)||t.$isTabNode(i.origin));i=e.$getAdjacentCaret(i))o=i.origin;return o}function y(e){return M(e,"previous")}function L(e){return M(e,"next")}const A={defaultLanguage:m,tokenize(e,t){return r.tokenize(e,r.languages[t||""]||r.languages[this.defaultLanguage])}};function b(e,r){let o=null,i=null,s=e,a=r,l=e.getTextContent();for(;;){if(0===a){if(s=s.getPreviousSibling(),null===s)break;if($(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||n(167),t.$isLineBreakNode(s)){o={node:s,offset:1};break}a=Math.max(0,s.getTextContentSize()-1),l=s.getTextContent()}else a--;const e=l[a];$(s)&&" "!==e&&(i={node:s,offset:a})}if(null!==i)return i;let g=null;if(r<e.getTextContentSize())$(e)&&(g=e.getTextContent()[r]);else{const t=e.getNextSibling();$(t)&&(g=t.getTextContent()[0])}if(null!==g&&" "!==g)return o;{const n=function(e,n){let r=e,o=n,i=e.getTextContent(),s=e.getTextContentSize();for(;;){if(!$(r)||o===s){if(r=r.getNextSibling(),null===r||t.$isLineBreakNode(r))return null;$(r)&&(o=0,i=r.getTextContent(),s=r.getTextContentSize())}if($(r)){if(" "!==i[o])return{node:r,offset:o};o++}}}(e,r);return null!==n?n:o}}function E(e){const r=L(e);return t.$isLineBreakNode(r)&&n(168),r}function D(e,n,r){const o=e.getParent();u(o)?k(o,n,r):$(e)&&e.replace(t.$createTextNode(e.__text))}function v(e,n){const r=n.getElementByKey(e.getKey());if(null===r)return;const o=e.getChildren(),i=o.length;if(i===r.__cachedChildrenLength)return;r.__cachedChildrenLength=i;let s="1",a=1;for(let e=0;e<i;e++)t.$isLineBreakNode(o[e])&&(s+="\n"+ ++a);r.setAttribute("data-gutter",s)}const R=new Set;function k(e,n,r){const o=e.getKey();R.has(o)||(R.add(o),void 0===e.getLanguage()&&e.setLanguage(r.defaultLanguage),n.update((()=>{!function(e,n){const r=t.$getNodeByKey(e);if(!u(r)||!r.isAttached())return;const o=t.$getSelection();if(!t.$isRangeSelection(o))return void n();const i=o.anchor,s=i.offset,a="element"===i.type&&t.$isLineBreakNode(r.getChildAtIndex(i.offset-1));let l=0;if(!a){const e=i.getNode();l=s+e.getPreviousSiblings().reduce(((e,t)=>e+t.getTextContentSize()),0)}if(!n())return;if(a)return void i.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}))}(o,(()=>{const n=t.$getNodeByKey(o);if(!u(n)||!n.isAttached())return!1;const i=n.getTextContent(),s=P(r.tokenize(i,n.getLanguage()||r.defaultLanguage)),a=function(e,t){let n=0;for(;n<e.length&&B(e[n],t[n]);)n++;const r=e.length,o=t.length,i=Math.min(r,o)-n;let s=0;for(;s<i;)if(s++,!B(e[r-s],t[o-s])){s--;break}const a=n,l=r-s,g=t.slice(n,o-s);return{from:a,nodesForReplacement:g,to:l}}(n.getChildren(),s),{from:l,to:g,nodesForReplacement:c}=a;return!(l===g&&!c.length)&&(e.splice(l,g-l,c),!0)}))}),{onUpdate:()=>{R.delete(o)},skipTransforms:!0}))}function P(e,n){const r=[];for(const o of e)if("string"==typeof o){const e=o.split(/(\n|\t)/),i=e.length;for(let o=0;o<i;o++){const i=e[o];"\n"===i||"\r\n"===i?r.push(t.$createLineBreakNode()):"\t"===i?r.push(t.$createTabNode()):i.length>0&&r.push(S(i,n))}}else{const{content:e}=o;"string"==typeof e?r.push(...P([e],o.type)):Array.isArray(e)&&r.push(...P(e,o.type))}return r}function B(e,n){return $(e)&&$(n)&&e.__text===n.__text&&e.__highlightType===n.__highlightType||t.$isTabNode(e)&&t.$isTabNode(n)||t.$isLineBreakNode(e)&&t.$isLineBreakNode(n)}function I(e){if(!t.$isRangeSelection(e))return!1;const n=e.anchor.getNode(),r=e.focus.getNode();if(n.is(r)&&u(n))return!0;const o=n.getParent();return u(o)&&o.is(r.getParent())}function j(e){const r=e.getNodes(),o=[[]];if(1===r.length&&u(r[0]))return o;let i=o[0];for(let e=0;e<r.length;e++){const s=r[e];$(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||n(169),t.$isLineBreakNode(s)?0!==e&&i.length>0&&(i=[],o.push(i)):i.push(s)}return o}function w(e){const r=t.$getSelection();if(!t.$isRangeSelection(r)||!I(r))return!1;const o=j(r),i=o.length;if(o.length>1){for(let n=0;n<i;n++){const r=o[n];if(r.length>0){let o=r[0];0===n&&(o=y(o)),null!==o&&(e===t.INDENT_CONTENT_COMMAND?o.insertBefore(t.$createTabNode()):t.$isTabNode(o)&&o.remove())}}return!0}const s=r.getNodes()[0];if(u(s)||$(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||n(171),u(s))return e===t.INDENT_CONTENT_COMMAND&&r.insertNodes([t.$createTabNode()]),!0;const a=y(s);return e===t.INDENT_CONTENT_COMMAND?t.$isLineBreakNode(a)?a.insertAfter(t.$createTabNode()):a.insertBefore(t.$createTabNode()):t.$isTabNode(a)&&a.remove(),!0}function H(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:o,focus:i}=r,s=o.offset,a=i.offset,l=o.getNode(),g=i.getNode(),u=e===t.KEY_ARROW_UP_COMMAND;if(!I(r)||!$(l)&&!t.$isTabNode(l)||!$(g)&&!t.$isTabNode(g))return!1;if(!n.altKey){if(r.isCollapsed()){const e=l.getParentOrThrow();if(u&&0===s&&null===l.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),n.preventDefault(),!0}else if(!u&&s===l.getTextContentSize()&&null===l.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),n.preventDefault(),!0}}return!1}let c,d;if(l.isBefore(g)?(c=y(l),d=L(g)):(c=y(g),d=L(l)),null==c||null==d)return!1;const p=c.getNodesBetween(d);for(let e=0;e<p.length;e++){const n=p[e];if(!$(n)&&!t.$isTabNode(n)&&!t.$isLineBreakNode(n))return!1}n.preventDefault(),n.stopPropagation();const f=u?c.getPreviousSibling():d.getNextSibling();if(!t.$isLineBreakNode(f))return!0;const N=u?f.getPreviousSibling():f.getNextSibling();if(null==N)return!0;const h=$(N)||t.$isTabNode(N)||t.$isLineBreakNode(N)?u?y(N):L(N):null;let m=null!=h?h:N;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 q(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:o,focus:i}=r,s=o.getNode(),a=i.getNode(),l=e===t.MOVE_TO_START;if(!I(r)||!$(s)&&!t.$isTabNode(s)||!$(a)&&!t.$isTabNode(a))return!1;if(l){const e=b(a,i.offset);if(null!==e){const{node:n,offset:o}=e;t.$isLineBreakNode(n)?n.selectNext(0,0):r.setTextNodeRange(n,o,n,o)}else a.getParentOrThrow().selectStart()}else{E(a).select()}return n.preventDefault(),n.stopPropagation(),!0}const W=y,F=L,K=E,z=b;exports.$createCodeHighlightNode=S,exports.$createCodeNode=g,exports.$getEndOfCodeInLine=E,exports.$getFirstCodeNodeOfLine=y,exports.$getLastCodeNodeOfLine=L,exports.$getStartOfCodeInLine=b,exports.$isCodeHighlightNode=$,exports.$isCodeNode=u,exports.CODE_LANGUAGE_FRIENDLY_NAME_MAP=T,exports.CODE_LANGUAGE_MAP=_,exports.CodeHighlightNode=O,exports.CodeNode=l,exports.DEFAULT_CODE_LANGUAGE=m,exports.PrismTokenizer=A,exports.getCodeLanguages=()=>Object.keys(r.languages).filter((e=>"function"!=typeof r.languages[e])).sort(),exports.getDefaultCodeLanguage=()=>m,exports.getEndOfCodeInLine=K,exports.getFirstCodeNodeOfLine=W,exports.getLanguageFriendlyName=function(e){const t=C(e);return T[t]||t},exports.getLastCodeNodeOfLine=F,exports.getStartOfCodeInLine=z,exports.normalizeCodeLang=C,exports.registerCodeHighlighting=function(r,o){if(!r.hasNodes([l,O]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return null==o&&(o=A),e.mergeRegister(r.registerMutationListener(l,(e=>{r.update((()=>{for(const[n,o]of e)if("destroyed"!==o){const e=t.$getNodeByKey(n);null!==e&&v(e,r)}}))}),{skipInitialization:!1}),r.registerNodeTransform(l,(e=>k(e,r,o))),r.registerNodeTransform(t.TextNode,(e=>D(e,r,o))),r.registerNodeTransform(O,(e=>D(e,r,o))),r.registerCommand(t.KEY_TAB_COMMAND,(e=>{const o=function(e){const r=t.$getSelection();if(!t.$isRangeSelection(r)||!I(r))return null;const o=e?t.OUTDENT_CONTENT_COMMAND:t.INDENT_CONTENT_COMMAND,i=e?t.OUTDENT_CONTENT_COMMAND:t.INSERT_TAB_COMMAND;if(j(r).length>1)return o;const s=r.getNodes()[0];if(u(s)||$(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||n(170),u(s))return o;const a=y(s),l=L(s),g=r.anchor,c=r.focus;let d,p;return c.isBefore(g)?(d=c,p=g):(d=g,p=c),null!==a&&null!==l&&d.key===a.getKey()&&0===d.offset&&p.key===l.getKey()&&p.offset===l.getTextContentSize()?o:i}(e.shiftKey);return null!==o&&(e.preventDefault(),r.dispatchCommand(o,void 0),!0)}),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.INSERT_TAB_COMMAND,(()=>!!I(t.$getSelection())&&(t.$insertNodes([t.$createTabNode()]),!0)),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.INDENT_CONTENT_COMMAND,(e=>w(t.INDENT_CONTENT_COMMAND)),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.OUTDENT_CONTENT_COMMAND,(e=>w(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,o=r.getNode();return!!I(n)&&(n.isCollapsed()&&0===r.offset&&null===o.getPreviousSibling()&&u(o.getParentOrThrow())?(e.preventDefault(),!0):H(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,o=r.getNode();return!!I(n)&&(n.isCollapsed()&&r.offset===o.getTextContentSize()&&null===o.getNextSibling()&&u(o.getParentOrThrow())?(e.preventDefault(),!0):H(t.KEY_ARROW_DOWN_COMMAND,e))}),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.MOVE_TO_START,(e=>q(t.MOVE_TO_START,e)),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.MOVE_TO_END,(e=>q(t.MOVE_TO_END,e)),t.COMMAND_PRIORITY_LOW))};
|
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 o}from"@lexical/utils";import{ElementNode as i,$createParagraphNode as s,$isTextNode as l,$isTabNode as u,$createTabNode as c,$createLineBreakNode as g,$applyNodeReplacement as a,TextNode as p,$getSiblingCaret as f,$isLineBreakNode as h,$createTextNode as d,$getNodeByKey as m,$getSelection as y,$isRangeSelection as x,INDENT_CONTENT_COMMAND as S,OUTDENT_CONTENT_COMMAND as _,INSERT_TAB_COMMAND as v,KEY_ARROW_UP_COMMAND as T,MOVE_TO_START as N,KEY_TAB_COMMAND as C,COMMAND_PRIORITY_LOW as b,$insertNodes as j,KEY_ARROW_DOWN_COMMAND as w,MOVE_TO_END as P}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";"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function O(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var k=O((function(t){const e=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",t);for(let t=1;t<arguments.length;t++)n.append("v",arguments[t]);throw e.search=n.toString(),Error(`Minified Lexical error #${t}; visit ${e.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const L=globalThis.Prism||window.Prism,A=t=>{try{return!!t&&L.languages.hasOwnProperty(t)}catch(t){return!1}};function H(e,n){for(const r of e.childNodes){if(t(r)&&r.tagName===n)return!0;H(r,n)}return!1}const M="data-language",D="data-highlight-language";class z extends i{static getType(){return"code"}static clone(t){return new z(t.__language,t.__key)}constructor(t,e){super(e),this.__language=t||void 0,this.__isSyntaxHighlightSupported=A(t)}createDOM(t){const n=document.createElement("code");e(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(M,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(D,r)),n}updateDOM(t,e,n){const r=this.__language,o=t.__language;return r?r!==o&&(e.setAttribute(M,r),this.__isSyntaxHighlightSupported&&e.setAttribute(D,r)):o&&(e.removeAttribute(M),t.__isSyntaxHighlightSupported&&e.removeAttribute(D)),!1}exportDOM(t){const n=document.createElement("pre");e(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(M,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(D,r)),{element:n}}static importDOM(){return{code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||H(t,"BR"))?{conversion:F,priority:1}:null,div:()=>({conversion:B,priority:1}),pre:()=>({conversion:F,priority:0}),table:t=>q(t)?{conversion:R,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&q(n)?{conversion:I,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&q(e)?{conversion:I,priority:3}:null}}}static importJSON(t){return J().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setLanguage(t.language)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage()}}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:o,focus:i}=t,a=(o.isBefore(i)?o:i).getNode();if(l(a)){let t=rt(a);const e=[];for(;;)if(u(t))e.push(c()),t=t.getNextSibling();else{if(!et(t))break;{let n=0;const r=t.getTextContent(),o=t.getTextContentSize();for(;n<o&&" "===r[n];)n++;if(0!==n&&e.push(tt(" ".repeat(n))),n!==o)break;t=t.getNextSibling()}}const n=a.splitText(o.offset)[0],r=0===o.offset?0:1,i=n.getIndexWithinParent()+r,s=a.getParentOrThrow(),l=[g(),...e];s.splice(i,0,l);const p=e[e.length-1];p?p.select():0===o.offset?n.selectPrevious():n.getNextSibling().selectNext(0,0)}if(E(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.__isSyntaxHighlightSupported=A(t),e}getLanguage(){return this.getLatest().__language}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}}function J(t){return a(new z(t))}function E(t){return t instanceof z}function F(t){return{node:J(t.getAttribute(M))}}function B(t){const e=t,n=K(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(K(e))return!0;e=e.parentElement}return!1}(e)?{node:n?J():null}:{node:null}}function R(){return{node:J()}}function I(){return{node:null}}function K(t){return null!==t.style.fontFamily.match("monospace")}function q(t){return t.classList.contains("js-file-line-container")}const U="javascript",W={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"},$={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function Q(t){return $[t]||t}function X(t){const e=Q(t);return W[e]||e}const G=()=>U,V=()=>Object.keys(L.languages).filter((t=>"function"!=typeof L.languages[t])).sort();class Y extends p{constructor(t="",e,n){super(t,n),this.__highlightType=e}static getType(){return"code-highlight"}static clone(t){return new Y(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=Z(t.theme,this.__highlightType);return e(n,r),n}updateDOM(t,r,o){const i=super.updateDOM(t,r,o),s=Z(o.theme,t.__highlightType),l=Z(o.theme,this.__highlightType);return s!==l&&(s&&n(r,s),l&&e(r,l)),i}static importJSON(t){return tt().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setHighlightType(t.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(t){return this}isParentRequired(){return!0}createParentElementNode(){return J()}}function Z(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function tt(t="",e){return a(new Y(t,e))}function et(t){return t instanceof Y}function nt(t,e){let n=t;for(let o=f(t,e);o&&(et(o.origin)||u(o.origin));o=r(o))n=o.origin;return n}function rt(t){return nt(t,"previous")}function ot(t){return nt(t,"next")}const it={defaultLanguage:U,tokenize(t,e){return L.tokenize(t,L.languages[e||""]||L.languages[this.defaultLanguage])}};function st(t,e){let n=null,r=null,o=t,i=e,s=t.getTextContent();for(;;){if(0===i){if(o=o.getPreviousSibling(),null===o)break;if(et(o)||u(o)||h(o)||k(167),h(o)){n={node:o,offset:1};break}i=Math.max(0,o.getTextContentSize()-1),s=o.getTextContent()}else i--;const t=s[i];et(o)&&" "!==t&&(r={node:o,offset:i})}if(null!==r)return r;let l=null;if(e<t.getTextContentSize())et(t)&&(l=t.getTextContent()[e]);else{const e=t.getNextSibling();et(e)&&(l=e.getTextContent()[0])}if(null!==l&&" "!==l)return n;{const r=function(t,e){let n=t,r=e,o=t.getTextContent(),i=t.getTextContentSize();for(;;){if(!et(n)||r===i){if(n=n.getNextSibling(),null===n||h(n))return null;et(n)&&(r=0,o=n.getTextContent(),i=n.getTextContentSize())}if(et(n)){if(" "!==o[r])return{node:n,offset:r};r++}}}(t,e);return null!==r?r:n}}function lt(t){const e=ot(t);return h(e)&&k(168),e}function ut(t,e,n){const r=t.getParent();E(r)?at(r,e,n):et(t)&&t.replace(d(t.__text))}function ct(t,e){const n=e.getElementByKey(t.getKey());if(null===n)return;const r=t.getChildren(),o=r.length;if(o===n.__cachedChildrenLength)return;n.__cachedChildrenLength=o;let i="1",s=1;for(let t=0;t<o;t++)h(r[t])&&(i+="\n"+ ++s);n.setAttribute("data-gutter",i)}const gt=new Set;function at(t,e,n){const r=t.getKey();gt.has(r)||(gt.add(r),void 0===t.getLanguage()&&t.setLanguage(n.defaultLanguage),e.update((()=>{!function(t,e){const n=m(t);if(!E(n)||!n.isAttached())return;const r=y();if(!x(r))return void e();const o=r.anchor,i=o.offset,s="element"===o.type&&h(n.getChildAtIndex(o.offset-1));let u=0;if(!s){const t=o.getNode();u=i+t.getPreviousSiblings().reduce(((t,e)=>t+e.getTextContentSize()),0)}if(!e())return;if(s)return void o.getNode().select(i,i);n.getChildren().some((t=>{const e=l(t);if(e||h(t)){const n=t.getTextContentSize();if(e&&n>=u)return t.select(u,u),!0;u-=n}return!1}))}(r,(()=>{const e=m(r);if(!E(e)||!e.isAttached())return!1;const o=e.getTextContent(),i=pt(n.tokenize(o,e.getLanguage()||n.defaultLanguage)),s=function(t,e){let n=0;for(;n<t.length&&ft(t[n],e[n]);)n++;const r=t.length,o=e.length,i=Math.min(r,o)-n;let s=0;for(;s<i;)if(s++,!ft(t[r-s],e[o-s])){s--;break}const l=n,u=r-s,c=e.slice(n,o-s);return{from:l,nodesForReplacement:c,to:u}}(e.getChildren(),i),{from:l,to:u,nodesForReplacement:c}=s;return!(l===u&&!c.length)&&(t.splice(l,u-l,c),!0)}))}),{onUpdate:()=>{gt.delete(r)},skipTransforms:!0}))}function pt(t,e){const n=[];for(const r of t)if("string"==typeof r){const t=r.split(/(\n|\t)/),o=t.length;for(let r=0;r<o;r++){const o=t[r];"\n"===o||"\r\n"===o?n.push(g()):"\t"===o?n.push(c()):o.length>0&&n.push(tt(o,e))}}else{const{content:t}=r;"string"==typeof t?n.push(...pt([t],r.type)):Array.isArray(t)&&n.push(...pt(t,r.type))}return n}function ft(t,e){return et(t)&&et(e)&&t.__text===e.__text&&t.__highlightType===e.__highlightType||u(t)&&u(e)||h(t)&&h(e)}function ht(t){if(!x(t))return!1;const e=t.anchor.getNode(),n=t.focus.getNode();if(e.is(n)&&E(e))return!0;const r=e.getParent();return E(r)&&r.is(n.getParent())}function dt(t){const e=t.getNodes(),n=[[]];if(1===e.length&&E(e[0]))return n;let r=n[0];for(let t=0;t<e.length;t++){const o=e[t];et(o)||u(o)||h(o)||k(169),h(o)?0!==t&&r.length>0&&(r=[],n.push(r)):r.push(o)}return n}function mt(t){const e=y();if(!x(e)||!ht(e))return!1;const n=dt(e),r=n.length;if(n.length>1){for(let e=0;e<r;e++){const r=n[e];if(r.length>0){let n=r[0];0===e&&(n=rt(n)),null!==n&&(t===S?n.insertBefore(c()):u(n)&&n.remove())}}return!0}const o=e.getNodes()[0];if(E(o)||et(o)||u(o)||h(o)||k(171),E(o))return t===S&&e.insertNodes([c()]),!0;const i=rt(o);return t===S?h(i)?i.insertAfter(c()):i.insertBefore(c()):u(i)&&i.remove(),!0}function yt(t,e){const n=y();if(!x(n))return!1;const{anchor:r,focus:o}=n,i=r.offset,s=o.offset,l=r.getNode(),c=o.getNode(),g=t===T;if(!ht(n)||!et(l)&&!u(l)||!et(c)&&!u(c))return!1;if(!e.altKey){if(n.isCollapsed()){const t=l.getParentOrThrow();if(g&&0===i&&null===l.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!0}else if(!g&&i===l.getTextContentSize()&&null===l.getNextSibling()){if(null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!0}}return!1}let a,p;if(l.isBefore(c)?(a=rt(l),p=ot(c)):(a=rt(c),p=ot(l)),null==a||null==p)return!1;const f=a.getNodesBetween(p);for(let t=0;t<f.length;t++){const e=f[t];if(!et(e)&&!u(e)&&!h(e))return!1}e.preventDefault(),e.stopPropagation();const d=g?a.getPreviousSibling():p.getNextSibling();if(!h(d))return!0;const m=g?d.getPreviousSibling():d.getNextSibling();if(null==m)return!0;const S=et(m)||u(m)||h(m)?g?rt(m):ot(m):null;let _=null!=S?S:m;return d.remove(),f.forEach((t=>t.remove())),t===T?(f.forEach((t=>_.insertBefore(t))),_.insertBefore(d)):(_.insertAfter(d),_=d,f.forEach((t=>{_.insertAfter(t),_=t}))),n.setTextNodeRange(l,i,c,s),!0}function xt(t,e){const n=y();if(!x(n))return!1;const{anchor:r,focus:o}=n,i=r.getNode(),s=o.getNode(),l=t===N;if(!ht(n)||!et(i)&&!u(i)||!et(s)&&!u(s))return!1;if(l){const t=st(s,o.offset);if(null!==t){const{node:e,offset:r}=t;h(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r)}else s.getParentOrThrow().selectStart()}else{lt(s).select()}return e.preventDefault(),e.stopPropagation(),!0}function St(t,e){if(!t.hasNodes([z,Y]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return null==e&&(e=it),o(t.registerMutationListener(z,(e=>{t.update((()=>{for(const[n,r]of e)if("destroyed"!==r){const e=m(n);null!==e&&ct(e,t)}}))}),{skipInitialization:!1}),t.registerNodeTransform(z,(n=>at(n,t,e))),t.registerNodeTransform(p,(n=>ut(n,t,e))),t.registerNodeTransform(Y,(n=>ut(n,t,e))),t.registerCommand(C,(e=>{const n=function(t){const e=y();if(!x(e)||!ht(e))return null;const n=t?_:S,r=t?_:v;if(dt(e).length>1)return n;const o=e.getNodes()[0];if(E(o)||et(o)||u(o)||h(o)||k(170),E(o))return n;const i=rt(o),s=ot(o),l=e.anchor,c=e.focus;let g,a;return c.isBefore(l)?(g=c,a=l):(g=l,a=c),null!==i&&null!==s&&g.key===i.getKey()&&0===g.offset&&a.key===s.getKey()&&a.offset===s.getTextContentSize()?n:r}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n,void 0),!0)}),b),t.registerCommand(v,(()=>!!ht(y())&&(j([c()]),!0)),b),t.registerCommand(S,(t=>mt(S)),b),t.registerCommand(_,(t=>mt(_)),b),t.registerCommand(T,(t=>{const e=y();if(!x(e))return!1;const{anchor:n}=e,r=n.getNode();return!!ht(e)&&(e.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&E(r.getParentOrThrow())?(t.preventDefault(),!0):yt(T,t))}),b),t.registerCommand(w,(t=>{const e=y();if(!x(e))return!1;const{anchor:n}=e,r=n.getNode();return!!ht(e)&&(e.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&E(r.getParentOrThrow())?(t.preventDefault(),!0):yt(w,t))}),b),t.registerCommand(N,(t=>xt(N,t)),b),t.registerCommand(P,(t=>xt(P,t)),b))}const _t=rt,vt=ot,Tt=lt,Nt=st;export{tt as $createCodeHighlightNode,J as $createCodeNode,lt as $getEndOfCodeInLine,rt as $getFirstCodeNodeOfLine,ot as $getLastCodeNodeOfLine,st as $getStartOfCodeInLine,et as $isCodeHighlightNode,E as $isCodeNode,W as CODE_LANGUAGE_FRIENDLY_NAME_MAP,$ as CODE_LANGUAGE_MAP,Y as CodeHighlightNode,z as CodeNode,U as DEFAULT_CODE_LANGUAGE,it as PrismTokenizer,V as getCodeLanguages,G as getDefaultCodeLanguage,Tt as getEndOfCodeInLine,_t as getFirstCodeNodeOfLine,X as getLanguageFriendlyName,vt as getLastCodeNodeOfLine,Nt as getStartOfCodeInLine,Q as normalizeCodeLang,St as registerCodeHighlighting};
|
|
9
|
+
import{isHTMLElement as t,addClassNamesToElement as e,removeClassNamesFromElement as n,$getAdjacentCaret as r,mergeRegister as o}from"@lexical/utils";import{ElementNode as i,$createParagraphNode as s,$isTextNode as l,$isTabNode as u,$createTabNode as c,$createLineBreakNode as g,$applyNodeReplacement as a,TextNode as p,$getSiblingCaret as f,$isLineBreakNode as h,$createTextNode as d,$getNodeByKey as m,$getSelection as x,$isRangeSelection as y,INDENT_CONTENT_COMMAND as S,OUTDENT_CONTENT_COMMAND as _,INSERT_TAB_COMMAND as v,KEY_ARROW_UP_COMMAND as N,MOVE_TO_START as T,KEY_TAB_COMMAND as C,COMMAND_PRIORITY_LOW as j,$insertNodes as b,KEY_ARROW_DOWN_COMMAND as w,MOVE_TO_END as P}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 O(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 k=globalThis.Prism||window.Prism,L=t=>{try{return!!t&&k.languages.hasOwnProperty(t)}catch(t){return!1}};function A(e,n){for(const r of e.childNodes){if(t(r)&&r.tagName===n)return!0;A(r,n)}return!1}const H="data-language",D="data-highlight-language";class M extends i{static getType(){return"code"}static clone(t){return new M(t.__language,t.__key)}constructor(t,e){super(e),this.__language=t||void 0,this.__isSyntaxHighlightSupported=L(t)}createDOM(t){const n=document.createElement("code");e(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(H,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(D,r)),n}updateDOM(t,e,n){const r=this.__language,o=t.__language;return r?r!==o&&(e.setAttribute(H,r),this.__isSyntaxHighlightSupported&&e.setAttribute(D,r)):o&&(e.removeAttribute(H),t.__isSyntaxHighlightSupported&&e.removeAttribute(D)),!1}exportDOM(t){const n=document.createElement("pre");e(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(H,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(D,r)),{element:n}}static importDOM(){return{code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||A(t,"BR"))?{conversion:E,priority:1}:null,div:()=>({conversion:F,priority:1}),pre:()=>({conversion:E,priority:0}),table:t=>K(t)?{conversion:B,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&K(n)?{conversion:R,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&K(e)?{conversion:R,priority:3}:null}}}static importJSON(t){return z().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setLanguage(t.language)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage()}}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:o,focus:i}=t,a=(o.isBefore(i)?o:i).getNode();if(l(a)){let t=nt(a);const e=[];for(;;)if(u(t))e.push(c()),t=t.getNextSibling();else{if(!tt(t))break;{let n=0;const r=t.getTextContent(),o=t.getTextContentSize();for(;n<o&&" "===r[n];)n++;if(0!==n&&e.push(Z(" ".repeat(n))),n!==o)break;t=t.getNextSibling()}}const n=a.splitText(o.offset)[0],r=0===o.offset?0:1,i=n.getIndexWithinParent()+r,s=a.getParentOrThrow(),l=[g(),...e];s.splice(i,0,l);const p=e[e.length-1];p?p.select():0===o.offset?n.selectPrevious():n.getNextSibling().selectNext(0,0)}if(J(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.__isSyntaxHighlightSupported=L(t),e}getLanguage(){return this.getLatest().__language}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}}function z(t){return a(new M(t))}function J(t){return t instanceof M}function E(t){return{node:z(t.getAttribute(H))}}function F(t){const e=t,n=I(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(I(e))return!0;e=e.parentElement}return!1}(e)?{node:n?z():null}:{node:null}}function B(){return{node:z()}}function R(){return{node:null}}function I(t){return null!==t.style.fontFamily.match("monospace")}function K(t){return t.classList.contains("js-file-line-container")}const q="javascript",U={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"},W={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function $(t){return W[t]||t}function Q(t){const e=$(t);return U[e]||e}const X=()=>q,G=()=>Object.keys(k.languages).filter((t=>"function"!=typeof k.languages[t])).sort();class V extends p{constructor(t="",e,n){super(t,n),this.__highlightType=e}static getType(){return"code-highlight"}static clone(t){return new V(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=Y(t.theme,this.__highlightType);return e(n,r),n}updateDOM(t,r,o){const i=super.updateDOM(t,r,o),s=Y(o.theme,t.__highlightType),l=Y(o.theme,this.__highlightType);return s!==l&&(s&&n(r,s),l&&e(r,l)),i}static importJSON(t){return Z().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 z()}}function Y(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function Z(t="",e){return a(new V(t,e))}function tt(t){return t instanceof V}function et(t,e){let n=t;for(let o=f(t,e);o&&(tt(o.origin)||u(o.origin));o=r(o))n=o.origin;return n}function nt(t){return et(t,"previous")}function rt(t){return et(t,"next")}const ot={defaultLanguage:q,tokenize(t,e){return k.tokenize(t,k.languages[e||""]||k.languages[this.defaultLanguage])}};function it(t,e){let n=null,r=null,o=t,i=e,s=t.getTextContent();for(;;){if(0===i){if(o=o.getPreviousSibling(),null===o)break;if(tt(o)||u(o)||h(o)||O(167),h(o)){n={node:o,offset:1};break}i=Math.max(0,o.getTextContentSize()-1),s=o.getTextContent()}else i--;const t=s[i];tt(o)&&" "!==t&&(r={node:o,offset:i})}if(null!==r)return r;let l=null;if(e<t.getTextContentSize())tt(t)&&(l=t.getTextContent()[e]);else{const e=t.getNextSibling();tt(e)&&(l=e.getTextContent()[0])}if(null!==l&&" "!==l)return n;{const r=function(t,e){let n=t,r=e,o=t.getTextContent(),i=t.getTextContentSize();for(;;){if(!tt(n)||r===i){if(n=n.getNextSibling(),null===n||h(n))return null;tt(n)&&(r=0,o=n.getTextContent(),i=n.getTextContentSize())}if(tt(n)){if(" "!==o[r])return{node:n,offset:r};r++}}}(t,e);return null!==r?r:n}}function st(t){const e=rt(t);return h(e)&&O(168),e}function lt(t,e,n){const r=t.getParent();J(r)?gt(r,e,n):tt(t)&&t.replace(d(t.__text))}function ut(t,e){const n=e.getElementByKey(t.getKey());if(null===n)return;const r=t.getChildren(),o=r.length;if(o===n.__cachedChildrenLength)return;n.__cachedChildrenLength=o;let i="1",s=1;for(let t=0;t<o;t++)h(r[t])&&(i+="\n"+ ++s);n.setAttribute("data-gutter",i)}const ct=new Set;function gt(t,e,n){const r=t.getKey();ct.has(r)||(ct.add(r),void 0===t.getLanguage()&&t.setLanguage(n.defaultLanguage),e.update((()=>{!function(t,e){const n=m(t);if(!J(n)||!n.isAttached())return;const r=x();if(!y(r))return void e();const o=r.anchor,i=o.offset,s="element"===o.type&&h(n.getChildAtIndex(o.offset-1));let u=0;if(!s){const t=o.getNode();u=i+t.getPreviousSiblings().reduce(((t,e)=>t+e.getTextContentSize()),0)}if(!e())return;if(s)return void o.getNode().select(i,i);n.getChildren().some((t=>{const e=l(t);if(e||h(t)){const n=t.getTextContentSize();if(e&&n>=u)return t.select(u,u),!0;u-=n}return!1}))}(r,(()=>{const e=m(r);if(!J(e)||!e.isAttached())return!1;const o=e.getTextContent(),i=at(n.tokenize(o,e.getLanguage()||n.defaultLanguage)),s=function(t,e){let n=0;for(;n<t.length&&pt(t[n],e[n]);)n++;const r=t.length,o=e.length,i=Math.min(r,o)-n;let s=0;for(;s<i;)if(s++,!pt(t[r-s],e[o-s])){s--;break}const l=n,u=r-s,c=e.slice(n,o-s);return{from:l,nodesForReplacement:c,to:u}}(e.getChildren(),i),{from:l,to:u,nodesForReplacement:c}=s;return!(l===u&&!c.length)&&(t.splice(l,u-l,c),!0)}))}),{onUpdate:()=>{ct.delete(r)},skipTransforms:!0}))}function at(t,e){const n=[];for(const r of t)if("string"==typeof r){const t=r.split(/(\n|\t)/),o=t.length;for(let r=0;r<o;r++){const o=t[r];"\n"===o||"\r\n"===o?n.push(g()):"\t"===o?n.push(c()):o.length>0&&n.push(Z(o,e))}}else{const{content:t}=r;"string"==typeof t?n.push(...at([t],r.type)):Array.isArray(t)&&n.push(...at(t,r.type))}return n}function pt(t,e){return tt(t)&&tt(e)&&t.__text===e.__text&&t.__highlightType===e.__highlightType||u(t)&&u(e)||h(t)&&h(e)}function ft(t){if(!y(t))return!1;const e=t.anchor.getNode(),n=t.focus.getNode();if(e.is(n)&&J(e))return!0;const r=e.getParent();return J(r)&&r.is(n.getParent())}function ht(t){const e=t.getNodes(),n=[[]];if(1===e.length&&J(e[0]))return n;let r=n[0];for(let t=0;t<e.length;t++){const o=e[t];tt(o)||u(o)||h(o)||O(169),h(o)?0!==t&&r.length>0&&(r=[],n.push(r)):r.push(o)}return n}function dt(t){const e=x();if(!y(e)||!ft(e))return!1;const n=ht(e),r=n.length;if(n.length>1){for(let e=0;e<r;e++){const r=n[e];if(r.length>0){let n=r[0];0===e&&(n=nt(n)),null!==n&&(t===S?n.insertBefore(c()):u(n)&&n.remove())}}return!0}const o=e.getNodes()[0];if(J(o)||tt(o)||u(o)||h(o)||O(171),J(o))return t===S&&e.insertNodes([c()]),!0;const i=nt(o);return t===S?h(i)?i.insertAfter(c()):i.insertBefore(c()):u(i)&&i.remove(),!0}function mt(t,e){const n=x();if(!y(n))return!1;const{anchor:r,focus:o}=n,i=r.offset,s=o.offset,l=r.getNode(),c=o.getNode(),g=t===N;if(!ft(n)||!tt(l)&&!u(l)||!tt(c)&&!u(c))return!1;if(!e.altKey){if(n.isCollapsed()){const t=l.getParentOrThrow();if(g&&0===i&&null===l.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!0}else if(!g&&i===l.getTextContentSize()&&null===l.getNextSibling()){if(null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!0}}return!1}let a,p;if(l.isBefore(c)?(a=nt(l),p=rt(c)):(a=nt(c),p=rt(l)),null==a||null==p)return!1;const f=a.getNodesBetween(p);for(let t=0;t<f.length;t++){const e=f[t];if(!tt(e)&&!u(e)&&!h(e))return!1}e.preventDefault(),e.stopPropagation();const d=g?a.getPreviousSibling():p.getNextSibling();if(!h(d))return!0;const m=g?d.getPreviousSibling():d.getNextSibling();if(null==m)return!0;const S=tt(m)||u(m)||h(m)?g?nt(m):rt(m):null;let _=null!=S?S:m;return d.remove(),f.forEach((t=>t.remove())),t===N?(f.forEach((t=>_.insertBefore(t))),_.insertBefore(d)):(_.insertAfter(d),_=d,f.forEach((t=>{_.insertAfter(t),_=t}))),n.setTextNodeRange(l,i,c,s),!0}function xt(t,e){const n=x();if(!y(n))return!1;const{anchor:r,focus:o}=n,i=r.getNode(),s=o.getNode(),l=t===T;if(!ft(n)||!tt(i)&&!u(i)||!tt(s)&&!u(s))return!1;if(l){const t=it(s,o.offset);if(null!==t){const{node:e,offset:r}=t;h(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r)}else s.getParentOrThrow().selectStart()}else{st(s).select()}return e.preventDefault(),e.stopPropagation(),!0}function yt(t,e){if(!t.hasNodes([M,V]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return null==e&&(e=ot),o(t.registerMutationListener(M,(e=>{t.update((()=>{for(const[n,r]of e)if("destroyed"!==r){const e=m(n);null!==e&&ut(e,t)}}))}),{skipInitialization:!1}),t.registerNodeTransform(M,(n=>gt(n,t,e))),t.registerNodeTransform(p,(n=>lt(n,t,e))),t.registerNodeTransform(V,(n=>lt(n,t,e))),t.registerCommand(C,(e=>{const n=function(t){const e=x();if(!y(e)||!ft(e))return null;const n=t?_:S,r=t?_:v;if(ht(e).length>1)return n;const o=e.getNodes()[0];if(J(o)||tt(o)||u(o)||h(o)||O(170),J(o))return n;const i=nt(o),s=rt(o),l=e.anchor,c=e.focus;let g,a;return c.isBefore(l)?(g=c,a=l):(g=l,a=c),null!==i&&null!==s&&g.key===i.getKey()&&0===g.offset&&a.key===s.getKey()&&a.offset===s.getTextContentSize()?n:r}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n,void 0),!0)}),j),t.registerCommand(v,(()=>!!ft(x())&&(b([c()]),!0)),j),t.registerCommand(S,(t=>dt(S)),j),t.registerCommand(_,(t=>dt(_)),j),t.registerCommand(N,(t=>{const e=x();if(!y(e))return!1;const{anchor:n}=e,r=n.getNode();return!!ft(e)&&(e.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&J(r.getParentOrThrow())?(t.preventDefault(),!0):mt(N,t))}),j),t.registerCommand(w,(t=>{const e=x();if(!y(e))return!1;const{anchor:n}=e,r=n.getNode();return!!ft(e)&&(e.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&J(r.getParentOrThrow())?(t.preventDefault(),!0):mt(w,t))}),j),t.registerCommand(T,(t=>xt(T,t)),j),t.registerCommand(P,(t=>xt(P,t)),j))}const St=nt,_t=rt,vt=st,Nt=it;export{Z as $createCodeHighlightNode,z as $createCodeNode,st as $getEndOfCodeInLine,nt as $getFirstCodeNodeOfLine,rt as $getLastCodeNodeOfLine,it as $getStartOfCodeInLine,tt as $isCodeHighlightNode,J as $isCodeNode,U as CODE_LANGUAGE_FRIENDLY_NAME_MAP,W as CODE_LANGUAGE_MAP,V as CodeHighlightNode,M as CodeNode,q as DEFAULT_CODE_LANGUAGE,ot as PrismTokenizer,G as getCodeLanguages,X as getDefaultCodeLanguage,vt as getEndOfCodeInLine,St as getFirstCodeNodeOfLine,Q as getLanguageFriendlyName,_t as getLastCodeNodeOfLine,Nt as getStartOfCodeInLine,$ as normalizeCodeLang,yt as registerCodeHighlighting};
|
package/package.json
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"code"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.26.0",
|
|
11
|
+
"version": "0.26.1-nightly.20250303.0",
|
|
12
12
|
"main": "LexicalCode.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/utils": "0.26.0",
|
|
16
|
-
"lexical": "0.26.0",
|
|
15
|
+
"@lexical/utils": "0.26.1-nightly.20250303.0",
|
|
16
|
+
"lexical": "0.26.1-nightly.20250303.0",
|
|
17
17
|
"prismjs": "^1.27.0"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|