@lexical/code-prism 0.41.1-nightly.20260309.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.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ 'use strict'
10
+ const LexicalCodePrism = process.env.NODE_ENV !== 'production' ? require('./LexicalCodePrism.dev.js') : require('./LexicalCodePrism.prod.js');
11
+ module.exports = LexicalCodePrism;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ /**
11
+ * LexicalCodePrism
12
+ */
13
+
14
+ import type {LexicalEditor} from 'lexical';
15
+
16
+ type TokenContent = string | Token | (string | Token)[];
17
+ export interface Token {
18
+ type: string;
19
+ content: TokenContent;
20
+ }
21
+ export interface Tokenizer {
22
+ defaultLanguage: string;
23
+ tokenize(code: string, language?: string): (string | Token)[];
24
+ }
25
+ declare export var PrismTokenizer: Tokenizer;
26
+
27
+ declare export function registerCodeHighlighting(
28
+ editor: LexicalEditor,
29
+ tokenizer?: Tokenizer,
30
+ ): () => void;
31
+
32
+ declare export function normalizeCodeLanguage(lang: string): string;
33
+
34
+ declare export var getCodeLanguages: () => Array<string>;
35
+ declare export function getLanguageFriendlyName(lang: string): string;
36
+
37
+ declare export var CODE_LANGUAGE_FRIENDLY_NAME_MAP: {[string]: string};
38
+ declare export var CODE_LANGUAGE_MAP: {[string]: string};
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ import * as modDev from './LexicalCodePrism.dev.mjs';
10
+ import * as modProd from './LexicalCodePrism.prod.mjs';
11
+ const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
12
+ export const CODE_LANGUAGE_FRIENDLY_NAME_MAP = mod.CODE_LANGUAGE_FRIENDLY_NAME_MAP;
13
+ export const CODE_LANGUAGE_MAP = mod.CODE_LANGUAGE_MAP;
14
+ export const PrismTokenizer = mod.PrismTokenizer;
15
+ export const getCodeLanguageOptions = mod.getCodeLanguageOptions;
16
+ export const getCodeLanguages = mod.getCodeLanguages;
17
+ export const getCodeThemeOptions = mod.getCodeThemeOptions;
18
+ export const getLanguageFriendlyName = mod.getLanguageFriendlyName;
19
+ export const isCodeLanguageLoaded = mod.isCodeLanguageLoaded;
20
+ export const loadCodeLanguage = mod.loadCodeLanguage;
21
+ export const normalizeCodeLanguage = mod.normalizeCodeLanguage;
22
+ export const registerCodeHighlighting = mod.registerCodeHighlighting;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalCodePrism.dev.mjs') : import('./LexicalCodePrism.prod.mjs'));
10
+ export const CODE_LANGUAGE_FRIENDLY_NAME_MAP = mod.CODE_LANGUAGE_FRIENDLY_NAME_MAP;
11
+ export const CODE_LANGUAGE_MAP = mod.CODE_LANGUAGE_MAP;
12
+ export const PrismTokenizer = mod.PrismTokenizer;
13
+ export const getCodeLanguageOptions = mod.getCodeLanguageOptions;
14
+ export const getCodeLanguages = mod.getCodeLanguages;
15
+ export const getCodeThemeOptions = mod.getCodeThemeOptions;
16
+ export const getLanguageFriendlyName = mod.getLanguageFriendlyName;
17
+ export const isCodeLanguageLoaded = mod.isCodeLanguageLoaded;
18
+ export const loadCodeLanguage = mod.loadCodeLanguage;
19
+ export const normalizeCodeLanguage = mod.normalizeCodeLanguage;
20
+ export const registerCodeHighlighting = mod.registerCodeHighlighting;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ "use strict";var e=require("@lexical/code-core"),t=require("lexical");function n(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.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"),function(e){e.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var t={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(t).forEach(function(n){var o=t[n],i=[];/^\w+$/.test(n)||i.push(/\w+/.exec(n)[0]),"diff"===n&&i.push("bold"),e.languages.diff[n]={pattern:RegExp("^(?:["+o+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}}),Object.defineProperty(e.languages.diff,"PREFIXES",{value:t})}(Prism);const o=globalThis.Prism||window.Prism,i={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"},r={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function s(e){return r[e]||e}function a(e){const t=function(e){const t=/^diff-([\w-]+)/i.exec(e);return t?t[1]:null}(e),n=t||e;try{return!!n&&o.languages.hasOwnProperty(n)}catch(e){return!1}}async function g(e,t,n){}function c(e){return"string"==typeof e?e:Array.isArray(e)?e.map(c).join(""):c(e.content)}function d(e,t){const n=/^diff-([\w-]+)/i.exec(t),i=e.getTextContent();let r=o.tokenize(i,o.languages[n?"diff":t]);return n&&(r=function(e,t){const n=t,i=o.languages[n],r={tokens:e},s=o.languages.diff.PREFIXES;for(const e of r.tokens){if("string"==typeof e||!(e.type in s)||!Array.isArray(e.content))continue;const t=e.type;let n=0;const r=()=>(n++,new o.Token("prefix",s[t],t.replace(/^(\w+).*/,"$1"))),a=e.content.filter(e=>"string"==typeof e||"prefix"!==e.type),g=e.content.length-a.length,d=o.tokenize(c(a),i);d.unshift(r());const l=/\r\n|\n/g,u=e=>{const t=[];l.lastIndex=0;let o,i=0;for(;n<g&&(o=l.exec(e));){const n=o.index+o[0].length;t.push(e.slice(i,n)),i=n,t.push(r())}if(0!==t.length)return i<e.length&&t.push(e.slice(i)),t},f=e=>{for(let t=0;t<e.length&&n<g;t++){const n=e[t];if("string"==typeof n){const o=u(n);o&&(e.splice(t,1,...o),t+=o.length-1)}else if("string"==typeof n.content){const e=u(n.content);e&&(n.content=e)}else Array.isArray(n.content)?f(n.content):f([n.content])}};f(d),n<g&&d.push(r()),e.content=d}return r.tokens}(r,n[1])),l(r)}function l(n,o){const i=[];for(const r of n)if("string"==typeof r){const n=r.split(/(\n|\t)/),s=n.length;for(let r=0;r<s;r++){const s=n[r];"\n"===s||"\r\n"===s?i.push(t.$createLineBreakNode()):"\t"===s?i.push(t.$createTabNode()):s.length>0&&i.push(e.$createCodeHighlightNode(s,o))}}else{const{content:e,alias:t}=r;"string"==typeof e?i.push(...l([e],"prefix"===r.type&&"string"==typeof t?t:r.type)):Array.isArray(e)&&i.push(...l(e,"unchanged"===r.type?void 0:r.type))}return i}const u={$tokenize(e,t){return d(e,t||this.defaultLanguage)},defaultLanguage:e.DEFAULT_CODE_LANGUAGE,tokenize(e,t){return o.tokenize(e,o.languages[t||""]||o.languages[this.defaultLanguage])}};function f(n,o,i){const r=n.getParent();e.$isCodeNode(r)?h(r,o,i):e.$isCodeHighlightNode(n)&&n.replace(t.$createTextNode(n.__text))}function p(e,n){const o=n.getElementByKey(e.getKey());if(null===o)return;const i=e.getChildren(),r=i.length;if(r===o.__cachedChildrenLength)return;o.__cachedChildrenLength=r;let s="1",a=1;for(let e=0;e<r;e++)t.$isLineBreakNode(i[e])&&(s+="\n"+ ++a);o.setAttribute("data-gutter",s)}const N=new Set;function h(n,o,i){const r=n.getKey(),s=o.getKey()+"/"+r;void 0===n.getLanguage()&&n.setLanguage(i.defaultLanguage);const c=n.getLanguage()||i.defaultLanguage;if(!a(c))return n.getIsSyntaxHighlightSupported()&&n.setIsSyntaxHighlightSupported(!1),void g();n.getIsSyntaxHighlightSupported()||n.setIsSyntaxHighlightSupported(!0),N.has(s)||(N.add(s),o.update(()=>{!function(n,o){const i=t.$getNodeByKey(n);if(!e.$isCodeNode(i)||!i.isAttached())return;const r=t.$getSelection();if(!t.$isRangeSelection(r))return void o();const s=r.anchor,a=s.offset,g="element"===s.type&&t.$isLineBreakNode(i.getChildAtIndex(s.offset-1));let c=0;if(!g){const e=s.getNode();c=a+e.getPreviousSiblings().reduce((e,t)=>e+t.getTextContentSize(),0)}if(!o())return;if(g)return void s.getNode().select(a,a);i.getChildren().some(e=>{const n=t.$isTextNode(e);if(n||t.$isLineBreakNode(e)){const t=e.getTextContentSize();if(n&&t>=c)return e.select(c,c),!0;c-=t}return!1})}(r,()=>{const o=t.$getNodeByKey(r);if(!e.$isCodeNode(o)||!o.isAttached())return!1;const s=o.getLanguage()||i.defaultLanguage,a=i.$tokenize(o,s),g=function(e,t){let n=0;for(;n<e.length&&C(e[n],t[n]);)n++;const o=e.length,i=t.length,r=Math.min(o,i)-n;let s=0;for(;s<r;)if(s++,!C(e[o-s],t[i-s])){s--;break}const a=n,g=o-s,c=t.slice(n,i-s);return{from:a,nodesForReplacement:c,to:g}}(o.getChildren(),a),{from:c,to:d,nodesForReplacement:l}=g;return!(c===d&&!l.length)&&(n.splice(c,d-c,l),!0)})},{onUpdate:()=>{N.delete(s)},skipTransforms:!0}))}function C(n,o){return e.$isCodeHighlightNode(n)&&e.$isCodeHighlightNode(o)&&n.__text===o.__text&&n.__highlightType===o.__highlightType||t.$isTabNode(n)&&t.$isTabNode(o)||t.$isLineBreakNode(n)&&t.$isLineBreakNode(o)}function m(n){if(!t.$isRangeSelection(n))return!1;const o=n.anchor.getNode(),i=e.$isCodeNode(o)?o:o.getParent(),r=n.focus.getNode(),s=e.$isCodeNode(r)?r:r.getParent();return e.$isCodeNode(i)&&i.is(s)}function T(o){const i=o.getNodes(),r=[];if(1===i.length&&e.$isCodeNode(i[0]))return r;let s=[];for(let o=0;o<i.length;o++){const a=i[o];e.$isCodeHighlightNode(a)||t.$isTabNode(a)||t.$isLineBreakNode(a)||n(169),t.$isLineBreakNode(a)?s.length>0&&(r.push(s),s=[]):s.push(a)}if(s.length>0){const e=o.isBackward()?o.anchor:o.focus,n=t.$createPoint(s[0].getKey(),0,"text");e.is(n)||r.push(s)}return r}function $(n){const o=t.$getSelection();if(!t.$isRangeSelection(o)||!m(o))return!1;const i=T(o),r=i.length;if(0===r&&o.isCollapsed())return n===t.INDENT_CONTENT_COMMAND&&o.insertNodes([t.$createTabNode()]),!0;if(0===r&&n===t.INDENT_CONTENT_COMMAND&&"\n"===o.getTextContent()){const e=t.$createTabNode(),n=t.$createLineBreakNode(),i=o.isBackward()?"previous":"next";return o.insertNodes([e,n]),t.$setSelectionFromCaretRange(t.$getCaretRangeInDirection(t.$getCaretRange(t.$getTextPointCaret(e,"next",0),t.$normalizeCaret(t.$getSiblingCaret(n,"next"))),i)),!0}for(let s=0;s<r;s++){const r=i[s];if(r.length>0){let i=r[0];if(0===s&&(i=e.$getFirstCodeNodeOfLine(i)),n===t.INDENT_CONTENT_COMMAND){const e=t.$createTabNode();if(i.insertBefore(e),0===s){const n=o.isBackward()?"focus":"anchor",r=t.$createPoint(i.getKey(),0,"text");o[n].is(r)&&o[n].set(e.getKey(),0,"text")}}else t.$isTabNode(i)&&i.remove()}}return!0}function O(n,o){const i=t.$getSelection();if(!t.$isRangeSelection(i))return!1;const{anchor:r,focus:s}=i,a=r.offset,g=s.offset,c=r.getNode(),d=s.getNode(),l=n===t.KEY_ARROW_UP_COMMAND;if(!m(i)||!e.$isCodeHighlightNode(c)&&!t.$isTabNode(c)||!e.$isCodeHighlightNode(d)&&!t.$isTabNode(d))return!1;if(!o.altKey){if(i.isCollapsed()){const e=c.getParentOrThrow();if(l&&0===a&&null===c.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),o.preventDefault(),!0}else if(!l&&a===c.getTextContentSize()&&null===c.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),o.preventDefault(),!0}}return!1}let u,f;if(c.isBefore(d)?(u=e.$getFirstCodeNodeOfLine(c),f=e.$getLastCodeNodeOfLine(d)):(u=e.$getFirstCodeNodeOfLine(d),f=e.$getLastCodeNodeOfLine(c)),null==u||null==f)return!1;const p=u.getNodesBetween(f);for(let n=0;n<p.length;n++){const o=p[n];if(!e.$isCodeHighlightNode(o)&&!t.$isTabNode(o)&&!t.$isLineBreakNode(o))return!1}o.preventDefault(),o.stopPropagation();const N=l?u.getPreviousSibling():f.getNextSibling();if(!t.$isLineBreakNode(N))return!0;const h=l?N.getPreviousSibling():N.getNextSibling();if(null==h)return!0;const C=e.$isCodeHighlightNode(h)||t.$isTabNode(h)||t.$isLineBreakNode(h)?l?e.$getFirstCodeNodeOfLine(h):e.$getLastCodeNodeOfLine(h):null;let T=null!=C?C:h;return N.remove(),p.forEach(e=>e.remove()),n===t.KEY_ARROW_UP_COMMAND?(p.forEach(e=>T.insertBefore(e)),T.insertBefore(N)):(T.insertAfter(N),T=N,p.forEach(e=>{T.insertAfter(e),T=e})),i.setTextNodeRange(c,a,d,g),!0}function _(n,o){const i=t.$getSelection();if(!t.$isRangeSelection(i))return!1;const{anchor:r,focus:s}=i,a=r.getNode(),g=s.getNode(),c=n===t.MOVE_TO_START;if(!m(i)||!e.$isCodeHighlightNode(a)&&!t.$isTabNode(a)||!e.$isCodeHighlightNode(g)&&!t.$isTabNode(g))return!1;const d=g;if("rtl"===e.$getCodeLineDirection(d)?!c:c){const n=e.$getStartOfCodeInLine(d,s.offset);if(null!==n){const{node:e,offset:o}=n;t.$isLineBreakNode(e)?e.selectNext(0,0):i.setTextNodeRange(e,o,e,o)}else d.getParentOrThrow().selectStart()}else{e.$getEndOfCodeInLine(d).select()}return o.preventDefault(),o.stopPropagation(),!0}exports.CODE_LANGUAGE_FRIENDLY_NAME_MAP=i,exports.CODE_LANGUAGE_MAP=r,exports.PrismTokenizer=u,exports.getCodeLanguageOptions=function(){const e=[];for(const[t,n]of Object.entries(i))e.push([t,n]);return e},exports.getCodeLanguages=()=>Object.keys(o.languages).filter(e=>"function"!=typeof o.languages[e]).sort(),exports.getCodeThemeOptions=function(){return[]},exports.getLanguageFriendlyName=function(e){const t=s(e);return i[t]||t},exports.isCodeLanguageLoaded=a,exports.loadCodeLanguage=g,exports.normalizeCodeLanguage=s,exports.registerCodeHighlighting=function(o,i){if(!o.hasNodes([e.CodeNode,e.CodeHighlightNode]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");null==i&&(i=u);const r=[];return!0!==o._headless&&r.push(o.registerMutationListener(e.CodeNode,e=>{o.getEditorState().read(()=>{for(const[n,i]of e)if("destroyed"!==i){const e=t.$getNodeByKey(n);null!==e&&p(e,o)}})},{skipInitialization:!1})),r.push(o.registerNodeTransform(e.CodeNode,e=>h(e,o,i)),o.registerNodeTransform(t.TextNode,e=>f(e,o,i)),o.registerNodeTransform(e.CodeHighlightNode,e=>f(e,o,i)),o.registerCommand(t.KEY_TAB_COMMAND,i=>{const r=function(o){const i=t.$getSelection();if(!t.$isRangeSelection(i)||!m(i))return null;const r=o?t.OUTDENT_CONTENT_COMMAND:t.INDENT_CONTENT_COMMAND,s=o?t.OUTDENT_CONTENT_COMMAND:t.INSERT_TAB_COMMAND,a=i.anchor,g=i.focus;if(a.is(g))return s;const c=T(i);if(1!==c.length)return r;const d=c[0];let l,u;0===d.length&&n(285),i.isBackward()?(l=g,u=a):(l=a,u=g);const f=e.$getFirstCodeNodeOfLine(d[0]),p=e.$getLastCodeNodeOfLine(d[0]),N=t.$createPoint(f.getKey(),0,"text"),h=t.$createPoint(p.getKey(),p.getTextContentSize(),"text");return l.isBefore(N)||h.isBefore(u)?r:N.isBefore(l)||u.isBefore(h)?s:r}(i.shiftKey);return null!==r&&(i.preventDefault(),o.dispatchCommand(r,void 0),!0)},t.COMMAND_PRIORITY_LOW),o.registerCommand(t.INSERT_TAB_COMMAND,()=>!!m(t.$getSelection())&&(t.$insertNodes([t.$createTabNode()]),!0),t.COMMAND_PRIORITY_LOW),o.registerCommand(t.INDENT_CONTENT_COMMAND,e=>$(t.INDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),o.registerCommand(t.OUTDENT_CONTENT_COMMAND,e=>$(t.OUTDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),o.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n)||!m(n))return!1;const o=t.$getRoot().getFirstDescendant(),{anchor:i}=n,r=i.getNode();return(!o||!r||o.getKey()!==r.getKey())&&O(t.KEY_ARROW_UP_COMMAND,e)},t.COMMAND_PRIORITY_LOW),o.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n)||!m(n))return!1;const o=t.$getRoot().getLastDescendant(),{anchor:i}=n,r=i.getNode();return(!o||!r||o.getKey()!==r.getKey())&&O(t.KEY_ARROW_DOWN_COMMAND,e)},t.COMMAND_PRIORITY_LOW),o.registerCommand(t.MOVE_TO_START,e=>_(t.MOVE_TO_START,e),t.COMMAND_PRIORITY_LOW),o.registerCommand(t.MOVE_TO_END,e=>_(t.MOVE_TO_END,e),t.COMMAND_PRIORITY_LOW)),t.mergeRegister(...r)};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ import{$createCodeHighlightNode as e,DEFAULT_CODE_LANGUAGE as t,$isCodeNode as n,$isCodeHighlightNode as r,$getFirstCodeNodeOfLine as o,$getLastCodeNodeOfLine as s,$getCodeLineDirection as i,$getStartOfCodeInLine as c,$getEndOfCodeInLine as a,CodeNode as l,CodeHighlightNode as f}from"@lexical/code-core";import{$createLineBreakNode as g,$createTabNode as u,$createTextNode as p,$isLineBreakNode as d,$getNodeByKey as m,$getSelection as h,$isRangeSelection as y,$isTextNode as x,$isTabNode as j,$createPoint as v,INDENT_CONTENT_COMMAND as S,OUTDENT_CONTENT_COMMAND as w,INSERT_TAB_COMMAND as C,$setSelectionFromCaretRange as k,$getCaretRangeInDirection as N,$getCaretRange as P,$getTextPointCaret as b,$normalizeCaret as T,$getSiblingCaret as L,KEY_ARROW_UP_COMMAND as K,MOVE_TO_START as _,TextNode as A,KEY_TAB_COMMAND as B,COMMAND_PRIORITY_LOW as E,$insertNodes as z,$getRoot as R,KEY_ARROW_DOWN_COMMAND as I,MOVE_TO_END as $,mergeRegister as O}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 D(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}!function(e){e.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var t={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(t).forEach(function(n){var r=t[n],o=[];/^\w+$/.test(n)||o.push(/\w+/.exec(n)[0]),"diff"===n&&o.push("bold"),e.languages.diff[n]={pattern:RegExp("^(?:["+r+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:o,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}}),Object.defineProperty(e.languages.diff,"PREFIXES",{value:t})}(Prism);const H=globalThis.Prism||window.Prism,M={c:"C",clike:"C-like",cpp:"C++",css:"CSS",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},F={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function U(e){return F[e]||e}function X(e){const t=U(e);return M[t]||t}const q=()=>Object.keys(H.languages).filter(e=>"function"!=typeof H.languages[e]).sort();function J(){const e=[];for(const[t,n]of Object.entries(M))e.push([t,n]);return e}function Q(){return[]}function G(e){const t=function(e){const t=/^diff-([\w-]+)/i.exec(e);return t?t[1]:null}(e),n=t||e;try{return!!n&&H.languages.hasOwnProperty(n)}catch(e){return!1}}async function V(e,t,n){}function W(e){return"string"==typeof e?e:Array.isArray(e)?e.map(W).join(""):W(e.content)}function Y(e,t){const n=/^diff-([\w-]+)/i.exec(t),r=e.getTextContent();let o=H.tokenize(r,H.languages[n?"diff":t]);return n&&(o=function(e,t){const n=t,r=H.languages[n],o={tokens:e},s=H.languages.diff.PREFIXES;for(const e of o.tokens){if("string"==typeof e||!(e.type in s)||!Array.isArray(e.content))continue;const t=e.type;let n=0;const o=()=>(n++,new H.Token("prefix",s[t],t.replace(/^(\w+).*/,"$1"))),i=e.content.filter(e=>"string"==typeof e||"prefix"!==e.type),c=e.content.length-i.length,a=H.tokenize(W(i),r);a.unshift(o());const l=/\r\n|\n/g,f=e=>{const t=[];l.lastIndex=0;let r,s=0;for(;n<c&&(r=l.exec(e));){const n=r.index+r[0].length;t.push(e.slice(s,n)),s=n,t.push(o())}if(0!==t.length)return s<e.length&&t.push(e.slice(s)),t},g=e=>{for(let t=0;t<e.length&&n<c;t++){const n=e[t];if("string"==typeof n){const r=f(n);r&&(e.splice(t,1,...r),t+=r.length-1)}else if("string"==typeof n.content){const e=f(n.content);e&&(n.content=e)}else Array.isArray(n.content)?g(n.content):g([n.content])}};g(a),n<c&&a.push(o()),e.content=a}return o.tokens}(o,n[1])),Z(o)}function Z(t,n){const r=[];for(const o of t)if("string"==typeof o){const t=o.split(/(\n|\t)/),s=t.length;for(let o=0;o<s;o++){const s=t[o];"\n"===s||"\r\n"===s?r.push(g()):"\t"===s?r.push(u()):s.length>0&&r.push(e(s,n))}}else{const{content:e,alias:t}=o;"string"==typeof e?r.push(...Z([e],"prefix"===o.type&&"string"==typeof t?t:o.type)):Array.isArray(e)&&r.push(...Z(e,"unchanged"===o.type?void 0:o.type))}return r}const ee={$tokenize(e,t){return Y(e,t||this.defaultLanguage)},defaultLanguage:t,tokenize(e,t){return H.tokenize(e,H.languages[t||""]||H.languages[this.defaultLanguage])}};function te(e,t,o){const s=e.getParent();n(s)?oe(s,t,o):r(e)&&e.replace(p(e.__text))}function ne(e,t){const n=t.getElementByKey(e.getKey());if(null===n)return;const r=e.getChildren(),o=r.length;if(o===n.__cachedChildrenLength)return;n.__cachedChildrenLength=o;let s="1",i=1;for(let e=0;e<o;e++)d(r[e])&&(s+="\n"+ ++i);n.setAttribute("data-gutter",s)}const re=new Set;function oe(e,t,r){const o=e.getKey(),s=t.getKey()+"/"+o;void 0===e.getLanguage()&&e.setLanguage(r.defaultLanguage);const i=e.getLanguage()||r.defaultLanguage;if(!G(i))return e.getIsSyntaxHighlightSupported()&&e.setIsSyntaxHighlightSupported(!1),void V();e.getIsSyntaxHighlightSupported()||e.setIsSyntaxHighlightSupported(!0),re.has(s)||(re.add(s),t.update(()=>{!function(e,t){const r=m(e);if(!n(r)||!r.isAttached())return;const o=h();if(!y(o))return void t();const s=o.anchor,i=s.offset,c="element"===s.type&&d(r.getChildAtIndex(s.offset-1));let a=0;if(!c){const e=s.getNode();a=i+e.getPreviousSiblings().reduce((e,t)=>e+t.getTextContentSize(),0)}if(!t())return;if(c)return void s.getNode().select(i,i);r.getChildren().some(e=>{const t=x(e);if(t||d(e)){const n=e.getTextContentSize();if(t&&n>=a)return e.select(a,a),!0;a-=n}return!1})}(o,()=>{const t=m(o);if(!n(t)||!t.isAttached())return!1;const s=t.getLanguage()||r.defaultLanguage,i=r.$tokenize(t,s),c=function(e,t){let n=0;for(;n<e.length&&se(e[n],t[n]);)n++;const r=e.length,o=t.length,s=Math.min(r,o)-n;let i=0;for(;i<s;)if(i++,!se(e[r-i],t[o-i])){i--;break}const c=n,a=r-i,l=t.slice(n,o-i);return{from:c,nodesForReplacement:l,to:a}}(t.getChildren(),i),{from:a,to:l,nodesForReplacement:f}=c;return!(a===l&&!f.length)&&(e.splice(a,l-a,f),!0)})},{onUpdate:()=>{re.delete(s)},skipTransforms:!0}))}function se(e,t){return r(e)&&r(t)&&e.__text===t.__text&&e.__highlightType===t.__highlightType||j(e)&&j(t)||d(e)&&d(t)}function ie(e){if(!y(e))return!1;const t=e.anchor.getNode(),r=n(t)?t:t.getParent(),o=e.focus.getNode(),s=n(o)?o:o.getParent();return n(r)&&r.is(s)}function ce(e){const t=e.getNodes(),o=[];if(1===t.length&&n(t[0]))return o;let s=[];for(let e=0;e<t.length;e++){const n=t[e];r(n)||j(n)||d(n)||D(169),d(n)?s.length>0&&(o.push(s),s=[]):s.push(n)}if(s.length>0){const t=e.isBackward()?e.anchor:e.focus,n=v(s[0].getKey(),0,"text");t.is(n)||o.push(s)}return o}function ae(e){const t=h();if(!y(t)||!ie(t))return!1;const n=ce(t),r=n.length;if(0===r&&t.isCollapsed())return e===S&&t.insertNodes([u()]),!0;if(0===r&&e===S&&"\n"===t.getTextContent()){const e=u(),n=g(),r=t.isBackward()?"previous":"next";return t.insertNodes([e,n]),k(N(P(b(e,"next",0),T(L(n,"next"))),r)),!0}for(let s=0;s<r;s++){const r=n[s];if(r.length>0){let n=r[0];if(0===s&&(n=o(n)),e===S){const e=u();if(n.insertBefore(e),0===s){const r=t.isBackward()?"focus":"anchor",o=v(n.getKey(),0,"text");t[r].is(o)&&t[r].set(e.getKey(),0,"text")}}else j(n)&&n.remove()}}return!0}function le(e,t){const n=h();if(!y(n))return!1;const{anchor:i,focus:c}=n,a=i.offset,l=c.offset,f=i.getNode(),g=c.getNode(),u=e===K;if(!ie(n)||!r(f)&&!j(f)||!r(g)&&!j(g))return!1;if(!t.altKey){if(n.isCollapsed()){const e=f.getParentOrThrow();if(u&&0===a&&null===f.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),t.preventDefault(),!0}else if(!u&&a===f.getTextContentSize()&&null===f.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),t.preventDefault(),!0}}return!1}let p,m;if(f.isBefore(g)?(p=o(f),m=s(g)):(p=o(g),m=s(f)),null==p||null==m)return!1;const x=p.getNodesBetween(m);for(let e=0;e<x.length;e++){const t=x[e];if(!r(t)&&!j(t)&&!d(t))return!1}t.preventDefault(),t.stopPropagation();const v=u?p.getPreviousSibling():m.getNextSibling();if(!d(v))return!0;const S=u?v.getPreviousSibling():v.getNextSibling();if(null==S)return!0;const w=r(S)||j(S)||d(S)?u?o(S):s(S):null;let C=null!=w?w:S;return v.remove(),x.forEach(e=>e.remove()),e===K?(x.forEach(e=>C.insertBefore(e)),C.insertBefore(v)):(C.insertAfter(v),C=v,x.forEach(e=>{C.insertAfter(e),C=e})),n.setTextNodeRange(f,a,g,l),!0}function fe(e,t){const n=h();if(!y(n))return!1;const{anchor:o,focus:s}=n,l=o.getNode(),f=s.getNode(),g=e===_;if(!ie(n)||!r(l)&&!j(l)||!r(f)&&!j(f))return!1;const u=f;if("rtl"===i(u)?!g:g){const e=c(u,s.offset);if(null!==e){const{node:t,offset:r}=e;d(t)?t.selectNext(0,0):n.setTextNodeRange(t,r,t,r)}else u.getParentOrThrow().selectStart()}else{a(u).select()}return t.preventDefault(),t.stopPropagation(),!0}function ge(e,t){if(!e.hasNodes([l,f]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");null==t&&(t=ee);const n=[];return!0!==e._headless&&n.push(e.registerMutationListener(l,t=>{e.getEditorState().read(()=>{for(const[n,r]of t)if("destroyed"!==r){const t=m(n);null!==t&&ne(t,e)}})},{skipInitialization:!1})),n.push(e.registerNodeTransform(l,n=>oe(n,e,t)),e.registerNodeTransform(A,n=>te(n,e,t)),e.registerNodeTransform(f,n=>te(n,e,t)),e.registerCommand(B,t=>{const n=function(e){const t=h();if(!y(t)||!ie(t))return null;const n=e?w:S,r=e?w:C,i=t.anchor,c=t.focus;if(i.is(c))return r;const a=ce(t);if(1!==a.length)return n;const l=a[0];let f,g;0===l.length&&D(285),t.isBackward()?(f=c,g=i):(f=i,g=c);const u=o(l[0]),p=s(l[0]),d=v(u.getKey(),0,"text"),m=v(p.getKey(),p.getTextContentSize(),"text");return f.isBefore(d)||m.isBefore(g)?n:d.isBefore(f)||g.isBefore(m)?r:n}(t.shiftKey);return null!==n&&(t.preventDefault(),e.dispatchCommand(n,void 0),!0)},E),e.registerCommand(C,()=>!!ie(h())&&(z([u()]),!0),E),e.registerCommand(S,e=>ae(S),E),e.registerCommand(w,e=>ae(w),E),e.registerCommand(K,e=>{const t=h();if(!y(t)||!ie(t))return!1;const n=R().getFirstDescendant(),{anchor:r}=t,o=r.getNode();return(!n||!o||n.getKey()!==o.getKey())&&le(K,e)},E),e.registerCommand(I,e=>{const t=h();if(!y(t)||!ie(t))return!1;const n=R().getLastDescendant(),{anchor:r}=t,o=r.getNode();return(!n||!o||n.getKey()!==o.getKey())&&le(I,e)},E),e.registerCommand(_,e=>fe(_,e),E),e.registerCommand($,e=>fe($,e),E)),O(...n)}export{M as CODE_LANGUAGE_FRIENDLY_NAME_MAP,F as CODE_LANGUAGE_MAP,ee as PrismTokenizer,J as getCodeLanguageOptions,q as getCodeLanguages,Q as getCodeThemeOptions,X as getLanguageFriendlyName,G as isCodeLanguageLoaded,V as loadCodeLanguage,U as normalizeCodeLanguage,ge as registerCodeHighlighting};
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # `@lexical/code-prism`
2
+
3
+ [![See API Documentation](https://lexical.dev/img/see-api-documentation.svg)](https://lexical.dev/docs/api/modules/lexical_code_prism)
4
+
5
+ This package contains the code highlighter for Lexical using the prism engine
package/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ export { PrismTokenizer, registerCodeHighlighting, type Tokenizer, } from './CodeHighlighterPrism';
9
+ export { CODE_LANGUAGE_FRIENDLY_NAME_MAP, CODE_LANGUAGE_MAP, getCodeLanguageOptions, getCodeLanguages, getCodeThemeOptions, getLanguageFriendlyName, isCodeLanguageLoaded, loadCodeLanguage, normalizeCodeLanguage, } from './FacadePrism';
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@lexical/code-prism",
3
+ "description": "This package contains the code highlighter for Lexical using the prism engine",
4
+ "keywords": [
5
+ "lexical",
6
+ "editor",
7
+ "rich-text",
8
+ "code"
9
+ ],
10
+ "license": "MIT",
11
+ "version": "0.41.1-nightly.20260309.0",
12
+ "main": "LexicalCodePrism.js",
13
+ "types": "index.d.ts",
14
+ "dependencies": {
15
+ "@lexical/code-core": "0.41.1-nightly.20260309.0",
16
+ "lexical": "0.41.1-nightly.20260309.0",
17
+ "prismjs": "^1.30.0"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/facebook/lexical.git",
22
+ "directory": "packages/lexical-code-prism"
23
+ },
24
+ "devDependencies": {
25
+ "@types/prismjs": "^1.26.6"
26
+ },
27
+ "module": "LexicalCodePrism.mjs",
28
+ "sideEffects": true,
29
+ "exports": {
30
+ ".": {
31
+ "import": {
32
+ "types": "./index.d.ts",
33
+ "development": "./LexicalCodePrism.dev.mjs",
34
+ "production": "./LexicalCodePrism.prod.mjs",
35
+ "node": "./LexicalCodePrism.node.mjs",
36
+ "default": "./LexicalCodePrism.mjs"
37
+ },
38
+ "require": {
39
+ "types": "./index.d.ts",
40
+ "development": "./LexicalCodePrism.dev.js",
41
+ "production": "./LexicalCodePrism.prod.js",
42
+ "default": "./LexicalCodePrism.js"
43
+ }
44
+ }
45
+ }
46
+ }