@lexical/code-core 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,107 @@
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
+ import type {
11
+ EditorConfig,
12
+ LexicalNode,
13
+ NodeKey,
14
+ ParagraphNode,
15
+ RangeSelection,
16
+ EditorThemeClasses,
17
+ LexicalEditor,
18
+ LineBreakNode,
19
+ SerializedElementNode,
20
+ SerializedTabNode,
21
+ TabNode,
22
+ LexicalExtension,
23
+ ExtensionConfigBase,
24
+ } from 'lexical';
25
+
26
+ import {ElementNode, TextNode} from 'lexical';
27
+
28
+ /**
29
+ * CodeHighlighter
30
+ */
31
+ declare export function $getEndOfCodeInLine(
32
+ anchor: CodeHighlightNode | TabNode,
33
+ ): CodeHighlightNode | TabNode;
34
+
35
+ declare export function $getStartOfCodeInLine(
36
+ anchor: CodeHighlightNode | TabNode,
37
+ offset: number,
38
+ ): null | {
39
+ node: CodeHighlightNode | TabNode | LineBreakNode,
40
+ offset: number,
41
+ };
42
+ /**
43
+ * CodeHighlightNode
44
+ */
45
+
46
+ declare export function $createCodeHighlightNode(
47
+ text: string,
48
+ highlightType?: string,
49
+ ): CodeHighlightNode;
50
+
51
+ declare export function $isCodeHighlightNode(
52
+ node: ?LexicalNode,
53
+ ): node is CodeHighlightNode;
54
+
55
+ declare export class CodeHighlightNode extends TextNode {
56
+ __highlightType: ?string;
57
+ constructor(text: string, highlightType?: string, key?: NodeKey): void;
58
+ static getType(): string;
59
+ static clone(node: CodeHighlightNode): CodeHighlightNode;
60
+ createDOM(config: EditorConfig): HTMLElement;
61
+ setFormat(format: number): this;
62
+ }
63
+
64
+ declare export var DEFAULT_CODE_LANGUAGE: string;
65
+
66
+ declare export var getDefaultCodeLanguage: () => string;
67
+
68
+ declare export function $getFirstCodeNodeOfLine(
69
+ anchor: CodeHighlightNode | TabNode | LineBreakNode,
70
+ ): CodeHighlightNode | TabNode | LineBreakNode;
71
+
72
+ declare export function $getLastCodeNodeOfLine(
73
+ anchor: CodeHighlightNode | TabNode | LineBreakNode,
74
+ ): CodeHighlightNode | TabNode | LineBreakNode;
75
+
76
+ /**
77
+ * CodeNode
78
+ */
79
+
80
+ export type SerializedCodeNode = {
81
+ ...SerializedElementNode,
82
+ language: string | null | void,
83
+ ...
84
+ };
85
+
86
+ declare export function $createCodeNode(language: ?string): CodeNode;
87
+
88
+ declare export function $isCodeNode(
89
+ node: ?LexicalNode,
90
+ ): node is CodeNode;
91
+
92
+ declare export class CodeNode extends ElementNode {
93
+ __language: string | null | void;
94
+ static getType(): string;
95
+ static clone(node: CodeNode): CodeNode;
96
+ constructor(language: ?string, key?: NodeKey): void;
97
+ createDOM(config: EditorConfig): HTMLElement;
98
+ insertNewAfter(
99
+ selection: RangeSelection,
100
+ restoreSelection?: boolean,
101
+ ): null | ParagraphNode | CodeHighlightNode | TabNode;
102
+ collapseAtStart(): true;
103
+ setLanguage(language: string): void;
104
+ getLanguage(): string | void;
105
+ }
106
+
107
+ declare export var CodeExtension: LexicalExtension<ExtensionConfigBase, "@lexical/code", mixed, mixed>;
@@ -0,0 +1,25 @@
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 './LexicalCodeCore.dev.mjs';
10
+ import * as modProd from './LexicalCodeCore.prod.mjs';
11
+ const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
12
+ export const $createCodeHighlightNode = mod.$createCodeHighlightNode;
13
+ export const $createCodeNode = mod.$createCodeNode;
14
+ export const $getCodeLineDirection = mod.$getCodeLineDirection;
15
+ export const $getEndOfCodeInLine = mod.$getEndOfCodeInLine;
16
+ export const $getFirstCodeNodeOfLine = mod.$getFirstCodeNodeOfLine;
17
+ export const $getLastCodeNodeOfLine = mod.$getLastCodeNodeOfLine;
18
+ export const $getStartOfCodeInLine = mod.$getStartOfCodeInLine;
19
+ export const $isCodeHighlightNode = mod.$isCodeHighlightNode;
20
+ export const $isCodeNode = mod.$isCodeNode;
21
+ export const CodeExtension = mod.CodeExtension;
22
+ export const CodeHighlightNode = mod.CodeHighlightNode;
23
+ export const CodeNode = mod.CodeNode;
24
+ export const DEFAULT_CODE_LANGUAGE = mod.DEFAULT_CODE_LANGUAGE;
25
+ export const getDefaultCodeLanguage = mod.getDefaultCodeLanguage;
@@ -0,0 +1,23 @@
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('./LexicalCodeCore.dev.mjs') : import('./LexicalCodeCore.prod.mjs'));
10
+ export const $createCodeHighlightNode = mod.$createCodeHighlightNode;
11
+ export const $createCodeNode = mod.$createCodeNode;
12
+ export const $getCodeLineDirection = mod.$getCodeLineDirection;
13
+ export const $getEndOfCodeInLine = mod.$getEndOfCodeInLine;
14
+ export const $getFirstCodeNodeOfLine = mod.$getFirstCodeNodeOfLine;
15
+ export const $getLastCodeNodeOfLine = mod.$getLastCodeNodeOfLine;
16
+ export const $getStartOfCodeInLine = mod.$getStartOfCodeInLine;
17
+ export const $isCodeHighlightNode = mod.$isCodeHighlightNode;
18
+ export const $isCodeNode = mod.$isCodeNode;
19
+ export const CodeExtension = mod.CodeExtension;
20
+ export const CodeHighlightNode = mod.CodeHighlightNode;
21
+ export const CodeNode = mod.CodeNode;
22
+ export const DEFAULT_CODE_LANGUAGE = mod.DEFAULT_CODE_LANGUAGE;
23
+ export const getDefaultCodeLanguage = mod.getDefaultCodeLanguage;
@@ -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");function t(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 n(t,n){let r=t;for(let i=e.$getSiblingCaret(t,n);i&&(y(i.origin)||e.$isTabNode(i.origin));i=i.getAdjacentCaret())r=i.origin;return r}function r(e){return n(e,"previous")}function i(e){return n(e,"next")}const o="javascript";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",u="data-theme";class g extends e.ElementNode{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new g(e.__language,e.__key)}constructor(e,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(t){const n=document.createElement("code");e.addClassNamesToElement(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(a,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(l,r));const i=this.getTheme();i&&n.setAttribute(u,i);const o=this.getStyle();return o&&n.setAttribute("style",o),n}updateDOM(e,t,n){const r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(a,r):i&&t.removeAttribute(a);const o=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&t.setAttribute(l,r):t.removeAttribute(l):o&&r&&t.setAttribute(l,r);const s=this.__theme,g=e.__theme;s?s!==g&&t.setAttribute(u,s):g&&t.removeAttribute(u);const h=this.__style,c=e.__style;return h?h!==c&&t.setAttribute("style",h):c&&t.removeAttribute("style"),!1}exportDOM(t){const n=document.createElement("pre");e.addClassNamesToElement(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(a,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(l,r));const i=this.getTheme();i&&n.setAttribute(u,i);const o=this.getStyle();return o&&n.setAttribute("style",o),{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=>x(e)?{conversion:f,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&x(n)?{conversion:_,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&x(t)?{conversion:_,priority:3}:null}}}static importJSON(e){return h().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(t,n=!0){const i=this.getChildren(),o=i.length;if(o>=2&&"\n"===i[o-1].getTextContent()&&"\n"===i[o-2].getTextContent()&&t.isCollapsed()&&t.anchor.key===this.__key&&t.anchor.offset===o){i[o-1].remove(),i[o-2].remove();const t=e.$createParagraphNode();return this.insertAfter(t,n),t}const{anchor:s,focus:a}=t,l=(s.isBefore(a)?s:a).getNode();if(e.$isTextNode(l)){let t=r(l);const n=[];for(;;)if(e.$isTabNode(t))n.push(e.$createTabNode()),t=t.getNextSibling();else{if(!y(t))break;{let e=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;e<i&&" "===r[e];)e++;if(0!==e&&n.push(T(" ".repeat(e))),e!==i)break;t=t.getNextSibling()}}const i=l.splitText(s.offset)[0],o=0===s.offset?0:1,a=i.getIndexWithinParent()+o,u=l.getParentOrThrow(),g=[e.$createLineBreakNode(),...n];u.splice(a,0,g);const h=n[n.length-1];h?h.select():0===s.offset?i.selectPrevious():i.getNextSibling().selectNext(0,0)}if(c(l)){const{offset:n}=t.anchor;l.splice(n,0,[e.$createLineBreakNode()]),l.select(n+1,n+1)}return null}canIndent(){return!1}collapseAtStart(){const t=e.$createParagraphNode();return this.getChildren().forEach(e=>t.append(e)),this.replace(t),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function h(t,n){return e.$create(g).setLanguage(t).setTheme(n)}function c(e){return e instanceof g}function d(e){return{node:h(e.getAttribute(a))}}function p(e){const t=e,n=m(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(m(t))return!0;t=t.parentElement}return!1}(t)?{node:n?h():null}:{node:null}}function f(){return{node:h()}}function _(){return{node:null}}function m(e){return null!==e.style.fontFamily.match("monospace")}function x(e){return e.classList.contains("js-file-line-container")}class S extends e.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new S(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=N(t.theme,this.__highlightType);return e.addClassNamesToElement(n,r),n}updateDOM(t,n,r){const i=super.updateDOM(t,n,r),o=N(r.theme,t.__highlightType),s=N(r.theme,this.__highlightType);return o!==s&&(o&&e.removeClassNamesFromElement(n,o),s&&e.addClassNamesToElement(n,s)),i}static importJSON(e){return T().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return h()}}function N(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function T(t="",n){return e.$applyNodeReplacement(new S(t,n))}function y(e){return e instanceof S}const b=e.defineExtension({name:"@lexical/code",nodes:()=>[g,S]});exports.$createCodeHighlightNode=T,exports.$createCodeNode=h,exports.$getCodeLineDirection=function(t){const n=r(t),o=i(t);let s=n;for(;null!==s;){if(y(s)){const t=e.getTextDirection(s.getTextContent());if(null!==t)return t}if(s===o)break;s=s.getNextSibling()}const a=n.getParent();if(e.$isElementNode(a)){const e=a.getDirection();if("ltr"===e||"rtl"===e)return e}return null},exports.$getEndOfCodeInLine=function(n){const r=i(n);return e.$isLineBreakNode(r)&&t(168),r},exports.$getFirstCodeNodeOfLine=r,exports.$getLastCodeNodeOfLine=i,exports.$getStartOfCodeInLine=function(n,r){let i=null,o=null,s=n,a=r,l=n.getTextContent();for(;;){if(0===a){if(s=s.getPreviousSibling(),null===s)break;if(y(s)||e.$isTabNode(s)||e.$isLineBreakNode(s)||t(167),e.$isLineBreakNode(s)){i={node:s,offset:1};break}a=Math.max(0,s.getTextContentSize()-1),l=s.getTextContent()}else a--;const n=l[a];y(s)&&" "!==n&&(o={node:s,offset:a})}if(null!==o)return o;let u=null;if(r<n.getTextContentSize())y(n)&&(u=n.getTextContent()[r]);else{const e=n.getNextSibling();y(e)&&(u=e.getTextContent()[0])}if(null!==u&&" "!==u)return i;{const t=function(t,n){let r=t,i=n,o=t.getTextContent(),s=t.getTextContentSize();for(;;){if(!y(r)||i===s){if(r=r.getNextSibling(),null===r||e.$isLineBreakNode(r))return null;y(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(y(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(n,r);return null!==t?t:i}},exports.$isCodeHighlightNode=y,exports.$isCodeNode=c,exports.CodeExtension=b,exports.CodeHighlightNode=S,exports.CodeNode=g,exports.DEFAULT_CODE_LANGUAGE=o,exports.getDefaultCodeLanguage=()=>o;
@@ -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{getTextDirection as t,$isElementNode as e,$isTabNode as n,$isLineBreakNode as r,$getSiblingCaret as i,$create as o,ElementNode as s,addClassNamesToElement as u,$createParagraphNode as l,$isTextNode as g,$createTabNode as a,$createLineBreakNode as h,isHTMLElement as c,$applyNodeReplacement as p,TextNode as f,removeClassNamesFromElement as _,defineExtension as d}from"lexical";function m(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.`)}function S(t,e){let r=t;for(let o=i(t,e);o&&(R(o.origin)||n(o.origin));o=o.getAdjacentCaret())r=o.origin;return r}function x(t){return S(t,"previous")}function y(t){return S(t,"next")}function T(n){const r=x(n),i=y(n);let o=r;for(;null!==o;){if(R(o)){const e=t(o.getTextContent());if(null!==e)return e}if(o===i)break;o=o.getNextSibling()}const s=r.getParent();if(e(s)){const t=s.getDirection();if("ltr"===t||"rtl"===t)return t}return null}function b(t,e){let i=null,o=null,s=t,u=e,l=t.getTextContent();for(;;){if(0===u){if(s=s.getPreviousSibling(),null===s)break;if(R(s)||n(s)||r(s)||m(167),r(s)){i={node:s,offset:1};break}u=Math.max(0,s.getTextContentSize()-1),l=s.getTextContent()}else u--;const t=l[u];R(s)&&" "!==t&&(o={node:s,offset:u})}if(null!==o)return o;let g=null;if(e<t.getTextContentSize())R(t)&&(g=t.getTextContent()[e]);else{const e=t.getNextSibling();R(e)&&(g=e.getTextContent()[0])}if(null!==g&&" "!==g)return i;{const n=function(t,e){let n=t,i=e,o=t.getTextContent(),s=t.getTextContentSize();for(;;){if(!R(n)||i===s){if(n=n.getNextSibling(),null===n||r(n))return null;R(n)&&(i=0,o=n.getTextContent(),s=n.getTextContentSize())}if(R(n)){if(" "!==o[i])return{node:n,offset:i};i++}}}(t,e);return null!==n?n:i}}function v(t){const e=y(t);return r(e)&&m(168),e}const A="javascript",N=()=>A;function C(t,e){for(const n of t.childNodes){if(c(n)&&n.tagName===e)return!0;C(n,e)}return!1}const O="data-language",H="data-highlight-language",L="data-theme";class J extends s{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(t){return new J(t.__language,t.__key)}constructor(t,e){super(e),this.__language=t||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(t){super.afterCloneFrom(t),this.__language=t.__language,this.__theme=t.__theme,this.__isSyntaxHighlightSupported=t.__isSyntaxHighlightSupported}createDOM(t){const e=document.createElement("code");u(e,t.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute(O,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(H,n));const r=this.getTheme();r&&e.setAttribute(L,r);const i=this.getStyle();return i&&e.setAttribute("style",i),e}updateDOM(t,e,n){const r=this.__language,i=t.__language;r?r!==i&&e.setAttribute(O,r):i&&e.removeAttribute(O);const o=this.__isSyntaxHighlightSupported;t.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&e.setAttribute(H,r):e.removeAttribute(H):o&&r&&e.setAttribute(H,r);const s=this.__theme,u=t.__theme;s?s!==u&&e.setAttribute(L,s):u&&e.removeAttribute(L);const l=this.__style,g=t.__style;return l?l!==g&&e.setAttribute("style",l):g&&e.removeAttribute("style"),!1}exportDOM(t){const e=document.createElement("pre");u(e,t._config.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute(O,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(H,n));const r=this.getTheme();r&&e.setAttribute(L,r);const i=this.getStyle();return i&&e.setAttribute("style",i),{element:e}}static importDOM(){return{code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||C(t,"BR"))?{conversion:M,priority:1}:null,div:()=>({conversion:w,priority:1}),pre:()=>({conversion:M,priority:0}),table:t=>I(t)?{conversion:D,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&I(n)?{conversion:P,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&I(e)?{conversion:P,priority:3}:null}}}static importJSON(t){return k().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setLanguage(t.language).setTheme(t.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(t,e=!0){const r=this.getChildren(),i=r.length;if(i>=2&&"\n"===r[i-1].getTextContent()&&"\n"===r[i-2].getTextContent()&&t.isCollapsed()&&t.anchor.key===this.__key&&t.anchor.offset===i){r[i-1].remove(),r[i-2].remove();const t=l();return this.insertAfter(t,e),t}const{anchor:o,focus:s}=t,u=(o.isBefore(s)?o:s).getNode();if(g(u)){let t=x(u);const e=[];for(;;)if(n(t))e.push(a()),t=t.getNextSibling();else{if(!R(t))break;{let n=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&e.push(j(" ".repeat(n))),n!==i)break;t=t.getNextSibling()}}const r=u.splitText(o.offset)[0],i=0===o.offset?0:1,s=r.getIndexWithinParent()+i,l=u.getParentOrThrow(),g=[h(),...e];l.splice(s,0,g);const c=e[e.length-1];c?c.select():0===o.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(F(u)){const{offset:e}=t.anchor;u.splice(e,0,[h()]),u.select(e+1,e+1)}return null}canIndent(){return!1}collapseAtStart(){const t=l();return this.getChildren().forEach(e=>t.append(e)),this.replace(t),!0}setLanguage(t){const e=this.getWritable();return e.__language=t||void 0,e}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(t){const e=this.getWritable();return e.__isSyntaxHighlightSupported=t,e}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(t){const e=this.getWritable();return e.__theme=t||void 0,e}getTheme(){return this.getLatest().__theme}}function k(t,e){return o(J).setLanguage(t).setTheme(e)}function F(t){return t instanceof J}function M(t){return{node:k(t.getAttribute(O))}}function w(t){const e=t,n=E(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(E(e))return!0;e=e.parentElement}return!1}(e)?{node:n?k():null}:{node:null}}function D(){return{node:k()}}function P(){return{node:null}}function E(t){return null!==t.style.fontFamily.match("monospace")}function I(t){return t.classList.contains("js-file-line-container")}class z extends f{__highlightType;constructor(t="",e,n){super(t,n),this.__highlightType=e}static getType(){return"code-highlight"}static clone(t){return new z(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 e=super.createDOM(t),n=W(t.theme,this.__highlightType);return u(e,n),e}updateDOM(t,e,n){const r=super.updateDOM(t,e,n),i=W(n.theme,t.__highlightType),o=W(n.theme,this.__highlightType);return i!==o&&(i&&_(e,i),o&&u(e,o)),r}static importJSON(t){return j().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 k()}}function W(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function j(t="",e){return p(new z(t,e))}function R(t){return t instanceof z}const B=d({name:"@lexical/code",nodes:()=>[J,z]});export{j as $createCodeHighlightNode,k as $createCodeNode,T as $getCodeLineDirection,v as $getEndOfCodeInLine,x as $getFirstCodeNodeOfLine,y as $getLastCodeNodeOfLine,b as $getStartOfCodeInLine,R as $isCodeHighlightNode,F as $isCodeNode,B as CodeExtension,z as CodeHighlightNode,J as CodeNode,A as DEFAULT_CODE_LANGUAGE,N as getDefaultCodeLanguage};
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # `@lexical/code-core`
2
+
3
+ [![See API Documentation](https://lexical.dev/img/see-api-documentation.svg)](https://lexical.dev/docs/api/modules/lexical_code_core)
4
+
5
+ This package contains the base functionality for the code blocks and code highlighting for Lexical. This package
6
+ is considered an implementation detail and is being used transitionally while the deprecated highlighting
7
+ functionality is still available in `@lexical/code`.
package/index.d.ts ADDED
@@ -0,0 +1,12 @@
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 { CodeExtension } from './CodeExtension';
9
+ export { $createCodeHighlightNode, $isCodeHighlightNode, CodeHighlightNode, } from './CodeHighlightNode';
10
+ export type { SerializedCodeNode } from './CodeNode';
11
+ export { $createCodeNode, $isCodeNode, CodeNode, DEFAULT_CODE_LANGUAGE, getDefaultCodeLanguage, } from './CodeNode';
12
+ export { $getCodeLineDirection, $getEndOfCodeInLine, $getFirstCodeNodeOfLine, $getLastCodeNodeOfLine, $getStartOfCodeInLine, } from './FlatStructureUtils';
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@lexical/code-core",
3
+ "description": "This package contains the base functionality code blocks for Lexical, it is a transitional package for internal use while the @lexical/code API is cleaned up.",
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": "LexicalCodeCore.js",
13
+ "types": "index.d.ts",
14
+ "dependencies": {
15
+ "lexical": "0.41.1-nightly.20260309.0"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/facebook/lexical.git",
20
+ "directory": "packages/lexical-code-core"
21
+ },
22
+ "module": "LexicalCodeCore.mjs",
23
+ "sideEffects": false,
24
+ "exports": {
25
+ ".": {
26
+ "import": {
27
+ "types": "./index.d.ts",
28
+ "development": "./LexicalCodeCore.dev.mjs",
29
+ "production": "./LexicalCodeCore.prod.mjs",
30
+ "node": "./LexicalCodeCore.node.mjs",
31
+ "default": "./LexicalCodeCore.mjs"
32
+ },
33
+ "require": {
34
+ "types": "./index.d.ts",
35
+ "development": "./LexicalCodeCore.dev.js",
36
+ "production": "./LexicalCodeCore.prod.js",
37
+ "default": "./LexicalCodeCore.js"
38
+ }
39
+ }
40
+ }
41
+ }