@lexical/code 0.21.1-nightly.20241223.0 → 0.22.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 +2 -6
- package/LexicalCode.dev.mjs +2 -6
- package/LexicalCode.prod.js +6 -6
- package/LexicalCode.prod.mjs +1 -1
- package/package.json +3 -3
package/LexicalCode.dev.js
CHANGED
|
@@ -217,9 +217,7 @@ class CodeNode extends lexical.ElementNode {
|
|
|
217
217
|
exportJSON() {
|
|
218
218
|
return {
|
|
219
219
|
...super.exportJSON(),
|
|
220
|
-
language: this.getLanguage()
|
|
221
|
-
type: 'code',
|
|
222
|
-
version: 1
|
|
220
|
+
language: this.getLanguage()
|
|
223
221
|
};
|
|
224
222
|
}
|
|
225
223
|
|
|
@@ -474,9 +472,7 @@ class CodeHighlightNode extends lexical.TextNode {
|
|
|
474
472
|
exportJSON() {
|
|
475
473
|
return {
|
|
476
474
|
...super.exportJSON(),
|
|
477
|
-
highlightType: this.getHighlightType()
|
|
478
|
-
type: 'code-highlight',
|
|
479
|
-
version: 1
|
|
475
|
+
highlightType: this.getHighlightType()
|
|
480
476
|
};
|
|
481
477
|
}
|
|
482
478
|
|
package/LexicalCode.dev.mjs
CHANGED
|
@@ -215,9 +215,7 @@ class CodeNode extends ElementNode {
|
|
|
215
215
|
exportJSON() {
|
|
216
216
|
return {
|
|
217
217
|
...super.exportJSON(),
|
|
218
|
-
language: this.getLanguage()
|
|
219
|
-
type: 'code',
|
|
220
|
-
version: 1
|
|
218
|
+
language: this.getLanguage()
|
|
221
219
|
};
|
|
222
220
|
}
|
|
223
221
|
|
|
@@ -472,9 +470,7 @@ class CodeHighlightNode extends TextNode {
|
|
|
472
470
|
exportJSON() {
|
|
473
471
|
return {
|
|
474
472
|
...super.exportJSON(),
|
|
475
|
-
highlightType: this.getHighlightType()
|
|
476
|
-
type: 'code-highlight',
|
|
477
|
-
version: 1
|
|
473
|
+
highlightType: this.getHighlightType()
|
|
478
474
|
};
|
|
479
475
|
}
|
|
480
476
|
|
package/LexicalCode.prod.js
CHANGED
|
@@ -13,13 +13,13 @@ function z(a,b){for(let c of a.childNodes){if(d.isHTMLElement(c)&&c.tagName===b)
|
|
|
13
13
|
class A extends m.ElementNode{static getType(){return"code"}static clone(a){return new A(a.__language,a.__key)}constructor(a,b){super(b);this.__language=a;this.__isSyntaxHighlightSupported=y(a)}createDOM(a){let b=document.createElement("code");d.addClassNamesToElement(b,a.theme.code);b.setAttribute("spellcheck","false");if(a=this.getLanguage())b.setAttribute("data-language",a),this.getIsSyntaxHighlightSupported()&&b.setAttribute("data-highlight-language",a);return b}updateDOM(a,b){let c=this.__language,
|
|
14
14
|
e=a.__language;c?c!==e&&(b.setAttribute("data-language",c),this.__isSyntaxHighlightSupported&&b.setAttribute("data-highlight-language",c)):e&&(b.removeAttribute("data-language"),a.__isSyntaxHighlightSupported&&b.removeAttribute("data-highlight-language"));return!1}exportDOM(a){let b=document.createElement("pre");d.addClassNamesToElement(b,a._config.theme.code);b.setAttribute("spellcheck","false");if(a=this.getLanguage())b.setAttribute("data-language",a),this.getIsSyntaxHighlightSupported()&&b.setAttribute("data-highlight-language",
|
|
15
15
|
a);return{element:b}}static importDOM(){return{code:a=>null!=a.textContent&&(/\r?\n/.test(a.textContent)||z(a,"BR"))?{conversion:B,priority:1}:null,div:()=>({conversion:aa,priority:1}),pre:()=>({conversion:B,priority:0}),table:a=>C(a)?{conversion:ba,priority:3}:null,td:a=>{let b=a.closest("table");return a.classList.contains("js-file-line")||b&&C(b)?{conversion:D,priority:3}:null},tr:a=>(a=a.closest("table"))&&C(a)?{conversion:D,priority:3}:null}}static importJSON(a){let b=E(a.language);b.setFormat(a.format);
|
|
16
|
-
b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),language:this.getLanguage()
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function
|
|
20
|
-
|
|
16
|
+
b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),language:this.getLanguage()}}insertNewAfter(a,b=!0){var c=this.getChildren(),e=c.length;if(2<=e&&"\n"===c[e-1].getTextContent()&&"\n"===c[e-2].getTextContent()&&a.isCollapsed()&&a.anchor.key===this.__key&&a.anchor.offset===e)return c[e-1].remove(),c[e-2].remove(),a=m.$createParagraphNode(),this.insertAfter(a,b),a;let {anchor:f,focus:g}=a;b=(f.isBefore(g)?f:g).getNode();if(m.$isTextNode(b)){e=F(b);
|
|
17
|
+
for(c=[];;)if(m.$isTabNode(e))c.push(m.$createTabNode()),e=e.getNextSibling();else if(G(e)){for(var h=0,k=e.getTextContent(),l=e.getTextContentSize();h<l&&" "===k[h];)h++;0!==h&&c.push(H(" ".repeat(h)));if(h!==l)break;e=e.getNextSibling()}else break;e=b.splitText(f.offset)[0];h=0===f.offset?0:1;h=e.getIndexWithinParent()+h;k=b.getParentOrThrow();l=[m.$createLineBreakNode(),...c];k.splice(h,0,l);(c=c[c.length-1])?c.select():0===f.offset?e.selectPrevious():e.getNextSibling().selectNext(0,0)}I(b)&&({offset:a}=
|
|
18
|
+
a.anchor,b.splice(a,0,[m.$createLineBreakNode()]),b.select(a+1,a+1));return null}canIndent(){return!1}collapseAtStart(){let a=m.$createParagraphNode();this.getChildren().forEach(b=>a.append(b));this.replace(a);return!0}setLanguage(a){let b=this.getWritable();b.__language=a;b.__isSyntaxHighlightSupported=y(a)}getLanguage(){return this.getLatest().__language}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}}function E(a){return m.$applyNodeReplacement(new A(a))}
|
|
19
|
+
function I(a){return a instanceof A}function B(a){a=a.getAttribute("data-language");return{node:E(a)}}function aa(a){let b=null!==a.style.fontFamily.match("monospace");var c;if(c=!b){a:{for(a=a.parentElement;null!==a;){if(null!==a.style.fontFamily.match("monospace")){a=!0;break a}a=a.parentElement}a=!1}c=!a}return c?{node:null}:{node:b?E():null}}function ba(){return{node:E()}}function D(){return{node:null}}function C(a){return a.classList.contains("js-file-line-container")}
|
|
20
|
+
let J={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"},K={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function M(a){return K[a]||a}
|
|
21
21
|
class N extends m.TextNode{constructor(a,b,c){super(a,c);this.__highlightType=b}static getType(){return"code-highlight"}static clone(a){return new N(a.__text,a.__highlightType||void 0,a.__key)}getHighlightType(){return this.getLatest().__highlightType}canHaveFormat(){return!1}createDOM(a){let b=super.createDOM(a);a=O(a.theme,this.__highlightType);d.addClassNamesToElement(b,a);return b}updateDOM(a,b,c){let e=super.updateDOM(a,b,c);a=O(c.theme,a.__highlightType);c=O(c.theme,this.__highlightType);a!==
|
|
22
|
-
c&&(a&&d.removeClassNamesFromElement(b,a),c&&d.addClassNamesToElement(b,c));return e}static importJSON(a){let b=H(a.text,a.highlightType);b.setFormat(a.format);b.setDetail(a.detail);b.setMode(a.mode);b.setStyle(a.style);return b}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()
|
|
22
|
+
c&&(a&&d.removeClassNamesFromElement(b,a),c&&d.addClassNamesToElement(b,c));return e}static importJSON(a){let b=H(a.text,a.highlightType);b.setFormat(a.format);b.setDetail(a.detail);b.setMode(a.mode);b.setStyle(a.style);return b}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(){return this}isParentRequired(){return!0}createParentElementNode(){return E()}}function O(a,b){return b&&a&&a.codeHighlight&&a.codeHighlight[b]}
|
|
23
23
|
function H(a,b){return m.$applyNodeReplacement(new N(a,b))}function G(a){return a instanceof N}function F(a){let b=a;for(;G(a)||m.$isTabNode(a);)b=a,a=a.getPreviousSibling();return b}function P(a){let b=a;for(;G(a)||m.$isTabNode(a);)b=a,a=a.getNextSibling();return b}let Q={defaultLanguage:"javascript",tokenize(a,b){return x.tokenize(a,x.languages[b||""]||x.languages[this.defaultLanguage])}};
|
|
24
24
|
function R(a,b){let c=null;var e=null,f=a;let g=b,h=a.getTextContent();for(;;){if(0===g){f=f.getPreviousSibling();if(null===f)break;G(f)||m.$isTabNode(f)||m.$isLineBreakNode(f)||q(167);if(m.$isLineBreakNode(f)){c={node:f,offset:1};break}g=Math.max(0,f.getTextContentSize()-1);h=f.getTextContent()}else g--;let k=h[g];G(f)&&" "!==k&&(e={node:f,offset:g})}if(null!==e)return e;e=null;b<a.getTextContentSize()?G(a)&&(e=a.getTextContent()[b]):(f=a.getNextSibling(),G(f)&&(e=f.getTextContent()[0]));if(null!==
|
|
25
25
|
e&&" "!==e)return c;a:for(e=a,f=a.getTextContent(),a=a.getTextContentSize();;){if(!G(e)||b===a){e=e.getNextSibling();if(null===e||m.$isLineBreakNode(e)){a=null;break a}G(e)&&(b=0,f=e.getTextContent(),a=e.getTextContentSize())}if(G(e)){if(" "!==f[b]){a={node:e,offset:b};break a}b++}}return null!==a?a:c}function S(a){a=P(a);m.$isLineBreakNode(a)&&q(168);return a}function T(a,b,c){let e=a.getParent();I(e)?U(e,b,c):G(a)&&a.replace(m.$createTextNode(a.__text))}let V=new Set;
|
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,mergeRegister as r}from"@lexical/utils";import{ElementNode as o,$createParagraphNode as i,$isTextNode as s,$isTabNode as l,$createTabNode as u,$createLineBreakNode as c,$applyNodeReplacement as a,TextNode as g,$isLineBreakNode as f,$createTextNode as p,$getNodeByKey as h,$getSelection as d,$isRangeSelection as m,INDENT_CONTENT_COMMAND as y,OUTDENT_CONTENT_COMMAND as x,INSERT_TAB_COMMAND as S,KEY_ARROW_UP_COMMAND as _,MOVE_TO_START as v,KEY_TAB_COMMAND as T,COMMAND_PRIORITY_LOW as b,$insertNodes as C,KEY_ARROW_DOWN_COMMAND as j,MOVE_TO_END as N}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 w(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var P=w((function(t){const e=new URLSearchParams;e.append("code",t);for(let t=1;t<arguments.length;t++)e.append("v",arguments[t]);throw Error(`Minified Lexical error #${t}; visit https://lexical.dev/docs/error?${e} 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 O="data-language",M="data-highlight-language";class H extends o{static getType(){return"code"}static clone(t){return new H(t.__language,t.__key)}constructor(t,e){super(e),this.__language=t,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(O,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(M,r)),n}updateDOM(t,e,n){const r=this.__language,o=t.__language;return r?r!==o&&(e.setAttribute(O,r),this.__isSyntaxHighlightSupported&&e.setAttribute(M,r)):o&&(e.removeAttribute(O),t.__isSyntaxHighlightSupported&&e.removeAttribute(M)),!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(O,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(M,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:B,priority:1}),pre:()=>({conversion:E,priority:0}),table:t=>F(t)?{conversion:I,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&F(n)?{conversion:J,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&F(e)?{conversion:J,priority:3}:null}}}static importJSON(t){const e=D(t.language);return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),type:"code",version:1}}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=i();return this.insertAfter(t,e),t}const{anchor:o,focus:a}=t,g=(o.isBefore(a)?o:a).getNode();if(s(g)){let t=tt(g);const e=[];for(;;)if(l(t))e.push(u()),t=t.getNextSibling();else{if(!Z(t))break;{let n=0;const r=t.getTextContent(),o=t.getTextContentSize();for(;n<o&&" "===r[n];)n++;if(0!==n&&e.push(Y(" ".repeat(n))),n!==o)break;t=t.getNextSibling()}}const n=g.splitText(o.offset)[0],r=0===o.offset?0:1,i=n.getIndexWithinParent()+r,s=g.getParentOrThrow(),a=[c(),...e];s.splice(i,0,a);const f=e[e.length-1];f?f.select():0===o.offset?n.selectPrevious():n.getNextSibling().selectNext(0,0)}if(z(g)){const{offset:e}=t.anchor;g.splice(e,0,[c()]),g.select(e+1,e+1)}return null}canIndent(){return!1}collapseAtStart(){const t=i();return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}setLanguage(t){const e=this.getWritable();e.__language=t,e.__isSyntaxHighlightSupported=L(t)}getLanguage(){return this.getLatest().__language}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}}function D(t){return a(new H(t))}function z(t){return t instanceof H}function E(t){return{node:D(t.getAttribute(O))}}function B(t){const e=t,n=R(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(R(e))return!0;e=e.parentElement}return!1}(e)?{node:n?D():null}:{node:null}}function I(){return{node:D()}}function J(){return{node:null}}function R(t){return null!==t.style.fontFamily.match("monospace")}function F(t){return t.classList.contains("js-file-line-container")}const K="javascript",q={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"},U={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function W(t){return U[t]||t}function $(t){const e=W(t);return q[e]||e}const Q=()=>K,X=()=>Object.keys(k.languages).filter((t=>"function"!=typeof k.languages[t])).sort();class G extends g{constructor(t,e,n){super(t,n),this.__highlightType=e}static getType(){return"code-highlight"}static clone(t){return new G(t.__text,t.__highlightType||void 0,t.__key)}getHighlightType(){return this.getLatest().__highlightType}canHaveFormat(){return!1}createDOM(t){const n=super.createDOM(t),r=V(t.theme,this.__highlightType);return e(n,r),n}updateDOM(t,r,o){const i=super.updateDOM(t,r,o),s=V(o.theme,t.__highlightType),l=V(o.theme,this.__highlightType);return s!==l&&(s&&n(r,s),l&&e(r,l)),i}static importJSON(t){const e=Y(t.text,t.highlightType);return e.setFormat(t.format),e.setDetail(t.detail),e.setMode(t.mode),e.setStyle(t.style),e}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType(),type:"code-highlight",version:1}}setFormat(t){return this}isParentRequired(){return!0}createParentElementNode(){return D()}}function V(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function Y(t,e){return a(new G(t,e))}function Z(t){return t instanceof G}function tt(t){let e=t,n=t;for(;Z(n)||l(n);)e=n,n=n.getPreviousSibling();return e}function et(t){let e=t,n=t;for(;Z(n)||l(n);)e=n,n=n.getNextSibling();return e}const nt={defaultLanguage:K,tokenize(t,e){return k.tokenize(t,k.languages[e||""]||k.languages[this.defaultLanguage])}};function rt(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(Z(o)||l(o)||f(o)||P(167),f(o)){n={node:o,offset:1};break}i=Math.max(0,o.getTextContentSize()-1),s=o.getTextContent()}else i--;const t=s[i];Z(o)&&" "!==t&&(r={node:o,offset:i})}if(null!==r)return r;let u=null;if(e<t.getTextContentSize())Z(t)&&(u=t.getTextContent()[e]);else{const e=t.getNextSibling();Z(e)&&(u=e.getTextContent()[0])}if(null!==u&&" "!==u)return n;{const r=function(t,e){let n=t,r=e,o=t.getTextContent(),i=t.getTextContentSize();for(;;){if(!Z(n)||r===i){if(n=n.getNextSibling(),null===n||f(n))return null;Z(n)&&(r=0,o=n.getTextContent(),i=n.getTextContentSize())}if(Z(n)){if(" "!==o[r])return{node:n,offset:r};r++}}}(t,e);return null!==r?r:n}}function ot(t){const e=et(t);return f(e)&&P(168),e}function it(t,e,n){const r=t.getParent();z(r)?ut(r,e,n):Z(t)&&t.replace(p(t.__text))}function st(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++)f(r[t])&&(i+="\n"+ ++s);n.setAttribute("data-gutter",i)}const lt=new Set;function ut(t,e,n){const r=t.getKey();lt.has(r)||(lt.add(r),void 0===t.getLanguage()&&t.setLanguage(n.defaultLanguage),e.update((()=>{!function(t,e){const n=h(t);if(!z(n)||!n.isAttached())return;const r=d();if(!m(r))return void e();const o=r.anchor,i=o.offset,l="element"===o.type&&f(n.getChildAtIndex(o.offset-1));let u=0;if(!l){const t=o.getNode();u=i+t.getPreviousSiblings().reduce(((t,e)=>t+e.getTextContentSize()),0)}if(!e())return;if(l)return void o.getNode().select(i,i);n.getChildren().some((t=>{const e=s(t);if(e||f(t)){const n=t.getTextContentSize();if(e&&n>=u)return t.select(u,u),!0;u-=n}return!1}))}(r,(()=>{const e=h(r);if(!z(e)||!e.isAttached())return!1;const o=e.getTextContent(),i=ct(n.tokenize(o,e.getLanguage()||n.defaultLanguage)),s=function(t,e){let n=0;for(;n<t.length&&at(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++,!at(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:()=>{lt.delete(r)},skipTransforms:!0}))}function ct(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(c()):"\t"===o?n.push(u()):o.length>0&&n.push(Y(o,e))}}else{const{content:t}=r;"string"==typeof t?n.push(...ct([t],r.type)):Array.isArray(t)&&n.push(...ct(t,r.type))}return n}function at(t,e){return Z(t)&&Z(e)&&t.__text===e.__text&&t.__highlightType===e.__highlightType||l(t)&&l(e)||f(t)&&f(e)}function gt(t){if(!m(t))return!1;const e=t.anchor.getNode(),n=t.focus.getNode();if(e.is(n)&&z(e))return!0;const r=e.getParent();return z(r)&&r.is(n.getParent())}function ft(t){const e=t.getNodes(),n=[[]];if(1===e.length&&z(e[0]))return n;let r=n[0];for(let t=0;t<e.length;t++){const o=e[t];Z(o)||l(o)||f(o)||P(169),f(o)?0!==t&&r.length>0&&(r=[],n.push(r)):r.push(o)}return n}function pt(t){const e=d();if(!m(e)||!gt(e))return!1;const n=ft(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=tt(n)),null!==n&&(t===y?n.insertBefore(u()):l(n)&&n.remove())}}return!0}const o=e.getNodes()[0];if(z(o)||Z(o)||l(o)||f(o)||P(171),z(o))return t===y&&e.insertNodes([u()]),!0;const i=tt(o);return null===i&&P(172),t===y?f(i)?i.insertAfter(u()):i.insertBefore(u()):l(i)&&i.remove(),!0}function ht(t,e){const n=d();if(!m(n))return!1;const{anchor:r,focus:o}=n,i=r.offset,s=o.offset,u=r.getNode(),c=o.getNode(),a=t===_;if(!gt(n)||!Z(u)&&!l(u)||!Z(c)&&!l(c))return!1;if(!e.altKey){if(n.isCollapsed()){const t=u.getParentOrThrow();if(a&&0===i&&null===u.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!0}else if(!a&&i===u.getTextContentSize()&&null===u.getNextSibling()){if(null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!0}}return!1}let g,p;if(u.isBefore(c)?(g=tt(u),p=et(c)):(g=tt(c),p=et(u)),null==g||null==p)return!1;const h=g.getNodesBetween(p);for(let t=0;t<h.length;t++){const e=h[t];if(!Z(e)&&!l(e)&&!f(e))return!1}e.preventDefault(),e.stopPropagation();const y=a?g.getPreviousSibling():p.getNextSibling();if(!f(y))return!0;const x=a?y.getPreviousSibling():y.getNextSibling();if(null==x)return!0;const S=Z(x)||l(x)||f(x)?a?tt(x):et(x):null;let v=null!=S?S:x;return y.remove(),h.forEach((t=>t.remove())),t===_?(h.forEach((t=>v.insertBefore(t))),v.insertBefore(y)):(v.insertAfter(y),v=y,h.forEach((t=>{v.insertAfter(t),v=t}))),n.setTextNodeRange(u,i,c,s),!0}function dt(t,e){const n=d();if(!m(n))return!1;const{anchor:r,focus:o}=n,i=r.getNode(),s=o.getNode(),u=t===v;if(!gt(n)||!Z(i)&&!l(i)||!Z(s)&&!l(s))return!1;if(u){const t=rt(s,o.offset);if(null!==t){const{node:e,offset:r}=t;f(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r)}else s.getParentOrThrow().selectStart()}else{ot(s).select()}return e.preventDefault(),e.stopPropagation(),!0}function mt(t,e){if(!t.hasNodes([H,G]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return null==e&&(e=nt),r(t.registerMutationListener(H,(e=>{t.update((()=>{for(const[n,r]of e)if("destroyed"!==r){const e=h(n);null!==e&&st(e,t)}}))}),{skipInitialization:!1}),t.registerNodeTransform(H,(n=>ut(n,t,e))),t.registerNodeTransform(g,(n=>it(n,t,e))),t.registerNodeTransform(G,(n=>it(n,t,e))),t.registerCommand(T,(e=>{const n=function(t){const e=d();if(!m(e)||!gt(e))return null;const n=t?x:y,r=t?x:S;if(ft(e).length>1)return n;const o=e.getNodes()[0];if(z(o)||Z(o)||l(o)||f(o)||P(170),z(o))return n;const i=tt(o),s=et(o),u=e.anchor,c=e.focus;let a,g;return c.isBefore(u)?(a=c,g=u):(a=u,g=c),null!==i&&null!==s&&a.key===i.getKey()&&0===a.offset&&g.key===s.getKey()&&g.offset===s.getTextContentSize()?n:r}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n,void 0),!0)}),b),t.registerCommand(S,(()=>!!gt(d())&&(C([u()]),!0)),b),t.registerCommand(y,(t=>pt(y)),b),t.registerCommand(x,(t=>pt(x)),b),t.registerCommand(_,(t=>ht(_,t)),b),t.registerCommand(j,(t=>ht(j,t)),b),t.registerCommand(N,(t=>dt(N,t)),b),t.registerCommand(v,(t=>dt(v,t)),b))}export{Y as $createCodeHighlightNode,D as $createCodeNode,Z as $isCodeHighlightNode,z as $isCodeNode,q as CODE_LANGUAGE_FRIENDLY_NAME_MAP,U as CODE_LANGUAGE_MAP,G as CodeHighlightNode,H as CodeNode,K as DEFAULT_CODE_LANGUAGE,nt as PrismTokenizer,X as getCodeLanguages,Q as getDefaultCodeLanguage,ot as getEndOfCodeInLine,tt as getFirstCodeNodeOfLine,$ as getLanguageFriendlyName,et as getLastCodeNodeOfLine,rt as getStartOfCodeInLine,W as normalizeCodeLang,mt as registerCodeHighlighting};
|
|
9
|
+
import{isHTMLElement as t,addClassNamesToElement as e,removeClassNamesFromElement as n,mergeRegister as r}from"@lexical/utils";import{ElementNode as o,$createParagraphNode as i,$isTextNode as s,$isTabNode as l,$createTabNode as u,$createLineBreakNode as c,$applyNodeReplacement as a,TextNode as g,$isLineBreakNode as f,$createTextNode as p,$getNodeByKey as h,$getSelection as d,$isRangeSelection as m,INDENT_CONTENT_COMMAND as y,OUTDENT_CONTENT_COMMAND as x,INSERT_TAB_COMMAND as S,KEY_ARROW_UP_COMMAND as _,MOVE_TO_START as v,KEY_TAB_COMMAND as T,COMMAND_PRIORITY_LOW as b,$insertNodes as C,KEY_ARROW_DOWN_COMMAND as j,MOVE_TO_END as N}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 w(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var P=w((function(t){const e=new URLSearchParams;e.append("code",t);for(let t=1;t<arguments.length;t++)e.append("v",arguments[t]);throw Error(`Minified Lexical error #${t}; visit https://lexical.dev/docs/error?${e} 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 O="data-language",M="data-highlight-language";class H extends o{static getType(){return"code"}static clone(t){return new H(t.__language,t.__key)}constructor(t,e){super(e),this.__language=t,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(O,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(M,r)),n}updateDOM(t,e,n){const r=this.__language,o=t.__language;return r?r!==o&&(e.setAttribute(O,r),this.__isSyntaxHighlightSupported&&e.setAttribute(M,r)):o&&(e.removeAttribute(O),t.__isSyntaxHighlightSupported&&e.removeAttribute(M)),!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(O,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(M,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:B,priority:1}),pre:()=>({conversion:E,priority:0}),table:t=>F(t)?{conversion:I,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&F(n)?{conversion:J,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&F(e)?{conversion:J,priority:3}:null}}}static importJSON(t){const e=D(t.language);return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}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=i();return this.insertAfter(t,e),t}const{anchor:o,focus:a}=t,g=(o.isBefore(a)?o:a).getNode();if(s(g)){let t=tt(g);const e=[];for(;;)if(l(t))e.push(u()),t=t.getNextSibling();else{if(!Z(t))break;{let n=0;const r=t.getTextContent(),o=t.getTextContentSize();for(;n<o&&" "===r[n];)n++;if(0!==n&&e.push(Y(" ".repeat(n))),n!==o)break;t=t.getNextSibling()}}const n=g.splitText(o.offset)[0],r=0===o.offset?0:1,i=n.getIndexWithinParent()+r,s=g.getParentOrThrow(),a=[c(),...e];s.splice(i,0,a);const f=e[e.length-1];f?f.select():0===o.offset?n.selectPrevious():n.getNextSibling().selectNext(0,0)}if(z(g)){const{offset:e}=t.anchor;g.splice(e,0,[c()]),g.select(e+1,e+1)}return null}canIndent(){return!1}collapseAtStart(){const t=i();return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}setLanguage(t){const e=this.getWritable();e.__language=t,e.__isSyntaxHighlightSupported=L(t)}getLanguage(){return this.getLatest().__language}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}}function D(t){return a(new H(t))}function z(t){return t instanceof H}function E(t){return{node:D(t.getAttribute(O))}}function B(t){const e=t,n=R(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(R(e))return!0;e=e.parentElement}return!1}(e)?{node:n?D():null}:{node:null}}function I(){return{node:D()}}function J(){return{node:null}}function R(t){return null!==t.style.fontFamily.match("monospace")}function F(t){return t.classList.contains("js-file-line-container")}const K="javascript",q={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"},U={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function W(t){return U[t]||t}function $(t){const e=W(t);return q[e]||e}const Q=()=>K,X=()=>Object.keys(k.languages).filter((t=>"function"!=typeof k.languages[t])).sort();class G extends g{constructor(t,e,n){super(t,n),this.__highlightType=e}static getType(){return"code-highlight"}static clone(t){return new G(t.__text,t.__highlightType||void 0,t.__key)}getHighlightType(){return this.getLatest().__highlightType}canHaveFormat(){return!1}createDOM(t){const n=super.createDOM(t),r=V(t.theme,this.__highlightType);return e(n,r),n}updateDOM(t,r,o){const i=super.updateDOM(t,r,o),s=V(o.theme,t.__highlightType),l=V(o.theme,this.__highlightType);return s!==l&&(s&&n(r,s),l&&e(r,l)),i}static importJSON(t){const e=Y(t.text,t.highlightType);return e.setFormat(t.format),e.setDetail(t.detail),e.setMode(t.mode),e.setStyle(t.style),e}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(t){return this}isParentRequired(){return!0}createParentElementNode(){return D()}}function V(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function Y(t,e){return a(new G(t,e))}function Z(t){return t instanceof G}function tt(t){let e=t,n=t;for(;Z(n)||l(n);)e=n,n=n.getPreviousSibling();return e}function et(t){let e=t,n=t;for(;Z(n)||l(n);)e=n,n=n.getNextSibling();return e}const nt={defaultLanguage:K,tokenize(t,e){return k.tokenize(t,k.languages[e||""]||k.languages[this.defaultLanguage])}};function rt(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(Z(o)||l(o)||f(o)||P(167),f(o)){n={node:o,offset:1};break}i=Math.max(0,o.getTextContentSize()-1),s=o.getTextContent()}else i--;const t=s[i];Z(o)&&" "!==t&&(r={node:o,offset:i})}if(null!==r)return r;let u=null;if(e<t.getTextContentSize())Z(t)&&(u=t.getTextContent()[e]);else{const e=t.getNextSibling();Z(e)&&(u=e.getTextContent()[0])}if(null!==u&&" "!==u)return n;{const r=function(t,e){let n=t,r=e,o=t.getTextContent(),i=t.getTextContentSize();for(;;){if(!Z(n)||r===i){if(n=n.getNextSibling(),null===n||f(n))return null;Z(n)&&(r=0,o=n.getTextContent(),i=n.getTextContentSize())}if(Z(n)){if(" "!==o[r])return{node:n,offset:r};r++}}}(t,e);return null!==r?r:n}}function ot(t){const e=et(t);return f(e)&&P(168),e}function it(t,e,n){const r=t.getParent();z(r)?ut(r,e,n):Z(t)&&t.replace(p(t.__text))}function st(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++)f(r[t])&&(i+="\n"+ ++s);n.setAttribute("data-gutter",i)}const lt=new Set;function ut(t,e,n){const r=t.getKey();lt.has(r)||(lt.add(r),void 0===t.getLanguage()&&t.setLanguage(n.defaultLanguage),e.update((()=>{!function(t,e){const n=h(t);if(!z(n)||!n.isAttached())return;const r=d();if(!m(r))return void e();const o=r.anchor,i=o.offset,l="element"===o.type&&f(n.getChildAtIndex(o.offset-1));let u=0;if(!l){const t=o.getNode();u=i+t.getPreviousSiblings().reduce(((t,e)=>t+e.getTextContentSize()),0)}if(!e())return;if(l)return void o.getNode().select(i,i);n.getChildren().some((t=>{const e=s(t);if(e||f(t)){const n=t.getTextContentSize();if(e&&n>=u)return t.select(u,u),!0;u-=n}return!1}))}(r,(()=>{const e=h(r);if(!z(e)||!e.isAttached())return!1;const o=e.getTextContent(),i=ct(n.tokenize(o,e.getLanguage()||n.defaultLanguage)),s=function(t,e){let n=0;for(;n<t.length&&at(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++,!at(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:()=>{lt.delete(r)},skipTransforms:!0}))}function ct(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(c()):"\t"===o?n.push(u()):o.length>0&&n.push(Y(o,e))}}else{const{content:t}=r;"string"==typeof t?n.push(...ct([t],r.type)):Array.isArray(t)&&n.push(...ct(t,r.type))}return n}function at(t,e){return Z(t)&&Z(e)&&t.__text===e.__text&&t.__highlightType===e.__highlightType||l(t)&&l(e)||f(t)&&f(e)}function gt(t){if(!m(t))return!1;const e=t.anchor.getNode(),n=t.focus.getNode();if(e.is(n)&&z(e))return!0;const r=e.getParent();return z(r)&&r.is(n.getParent())}function ft(t){const e=t.getNodes(),n=[[]];if(1===e.length&&z(e[0]))return n;let r=n[0];for(let t=0;t<e.length;t++){const o=e[t];Z(o)||l(o)||f(o)||P(169),f(o)?0!==t&&r.length>0&&(r=[],n.push(r)):r.push(o)}return n}function pt(t){const e=d();if(!m(e)||!gt(e))return!1;const n=ft(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=tt(n)),null!==n&&(t===y?n.insertBefore(u()):l(n)&&n.remove())}}return!0}const o=e.getNodes()[0];if(z(o)||Z(o)||l(o)||f(o)||P(171),z(o))return t===y&&e.insertNodes([u()]),!0;const i=tt(o);return null===i&&P(172),t===y?f(i)?i.insertAfter(u()):i.insertBefore(u()):l(i)&&i.remove(),!0}function ht(t,e){const n=d();if(!m(n))return!1;const{anchor:r,focus:o}=n,i=r.offset,s=o.offset,u=r.getNode(),c=o.getNode(),a=t===_;if(!gt(n)||!Z(u)&&!l(u)||!Z(c)&&!l(c))return!1;if(!e.altKey){if(n.isCollapsed()){const t=u.getParentOrThrow();if(a&&0===i&&null===u.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!0}else if(!a&&i===u.getTextContentSize()&&null===u.getNextSibling()){if(null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!0}}return!1}let g,p;if(u.isBefore(c)?(g=tt(u),p=et(c)):(g=tt(c),p=et(u)),null==g||null==p)return!1;const h=g.getNodesBetween(p);for(let t=0;t<h.length;t++){const e=h[t];if(!Z(e)&&!l(e)&&!f(e))return!1}e.preventDefault(),e.stopPropagation();const y=a?g.getPreviousSibling():p.getNextSibling();if(!f(y))return!0;const x=a?y.getPreviousSibling():y.getNextSibling();if(null==x)return!0;const S=Z(x)||l(x)||f(x)?a?tt(x):et(x):null;let v=null!=S?S:x;return y.remove(),h.forEach((t=>t.remove())),t===_?(h.forEach((t=>v.insertBefore(t))),v.insertBefore(y)):(v.insertAfter(y),v=y,h.forEach((t=>{v.insertAfter(t),v=t}))),n.setTextNodeRange(u,i,c,s),!0}function dt(t,e){const n=d();if(!m(n))return!1;const{anchor:r,focus:o}=n,i=r.getNode(),s=o.getNode(),u=t===v;if(!gt(n)||!Z(i)&&!l(i)||!Z(s)&&!l(s))return!1;if(u){const t=rt(s,o.offset);if(null!==t){const{node:e,offset:r}=t;f(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r)}else s.getParentOrThrow().selectStart()}else{ot(s).select()}return e.preventDefault(),e.stopPropagation(),!0}function mt(t,e){if(!t.hasNodes([H,G]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return null==e&&(e=nt),r(t.registerMutationListener(H,(e=>{t.update((()=>{for(const[n,r]of e)if("destroyed"!==r){const e=h(n);null!==e&&st(e,t)}}))}),{skipInitialization:!1}),t.registerNodeTransform(H,(n=>ut(n,t,e))),t.registerNodeTransform(g,(n=>it(n,t,e))),t.registerNodeTransform(G,(n=>it(n,t,e))),t.registerCommand(T,(e=>{const n=function(t){const e=d();if(!m(e)||!gt(e))return null;const n=t?x:y,r=t?x:S;if(ft(e).length>1)return n;const o=e.getNodes()[0];if(z(o)||Z(o)||l(o)||f(o)||P(170),z(o))return n;const i=tt(o),s=et(o),u=e.anchor,c=e.focus;let a,g;return c.isBefore(u)?(a=c,g=u):(a=u,g=c),null!==i&&null!==s&&a.key===i.getKey()&&0===a.offset&&g.key===s.getKey()&&g.offset===s.getTextContentSize()?n:r}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n,void 0),!0)}),b),t.registerCommand(S,(()=>!!gt(d())&&(C([u()]),!0)),b),t.registerCommand(y,(t=>pt(y)),b),t.registerCommand(x,(t=>pt(x)),b),t.registerCommand(_,(t=>ht(_,t)),b),t.registerCommand(j,(t=>ht(j,t)),b),t.registerCommand(N,(t=>dt(N,t)),b),t.registerCommand(v,(t=>dt(v,t)),b))}export{Y as $createCodeHighlightNode,D as $createCodeNode,Z as $isCodeHighlightNode,z as $isCodeNode,q as CODE_LANGUAGE_FRIENDLY_NAME_MAP,U as CODE_LANGUAGE_MAP,G as CodeHighlightNode,H as CodeNode,K as DEFAULT_CODE_LANGUAGE,nt as PrismTokenizer,X as getCodeLanguages,Q as getDefaultCodeLanguage,ot as getEndOfCodeInLine,tt as getFirstCodeNodeOfLine,$ as getLanguageFriendlyName,et as getLastCodeNodeOfLine,rt as getStartOfCodeInLine,W as normalizeCodeLang,mt as registerCodeHighlighting};
|
package/package.json
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"code"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.22.0",
|
|
12
12
|
"main": "LexicalCode.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/utils": "0.
|
|
16
|
-
"lexical": "0.
|
|
15
|
+
"@lexical/utils": "0.22.0",
|
|
16
|
+
"lexical": "0.22.0",
|
|
17
17
|
"prismjs": "^1.27.0"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|