@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,649 @@
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, $isElementNode, $isTabNode, $isLineBreakNode, $getSiblingCaret, $create, ElementNode, addClassNamesToElement, $createParagraphNode, $isTextNode, $createTabNode, $createLineBreakNode, isHTMLElement, $applyNodeReplacement, TextNode, removeClassNamesFromElement, defineExtension } from 'lexical';
10
+
11
+ /**
12
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
13
+ *
14
+ * This source code is licensed under the MIT license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ *
17
+ */
18
+
19
+ // Do not require this module directly! Use normal `invariant` calls.
20
+
21
+ function formatDevErrorMessage(message) {
22
+ throw new Error(message);
23
+ }
24
+
25
+ function $getLastMatchingCodeNode(anchor, direction) {
26
+ let matchingNode = anchor;
27
+ for (let caret = $getSiblingCaret(anchor, direction); caret && ($isCodeHighlightNode(caret.origin) || $isTabNode(caret.origin)); caret = caret.getAdjacentCaret()) {
28
+ matchingNode = caret.origin;
29
+ }
30
+ return matchingNode;
31
+ }
32
+ function $getFirstCodeNodeOfLine(anchor) {
33
+ return $getLastMatchingCodeNode(anchor, 'previous');
34
+ }
35
+ function $getLastCodeNodeOfLine(anchor) {
36
+ return $getLastMatchingCodeNode(anchor, 'next');
37
+ }
38
+
39
+ /**
40
+ * Determines the visual writing direction of a code line.
41
+ *
42
+ * Scans the line segments (CodeHighlightNode/TabNode) from start to end
43
+ * and returns the first strong direction found ("ltr" or "rtl").
44
+ * If no strong character is found, falls back to the parent element's
45
+ * direction. Returns null if indeterminate.
46
+ */
47
+ function $getCodeLineDirection(anchor) {
48
+ const start = $getFirstCodeNodeOfLine(anchor);
49
+ const end = $getLastCodeNodeOfLine(anchor);
50
+ let node = start;
51
+ while (node !== null) {
52
+ if ($isCodeHighlightNode(node)) {
53
+ const direction = getTextDirection(node.getTextContent());
54
+ if (direction !== null) {
55
+ return direction;
56
+ }
57
+ }
58
+ if (node === end) {
59
+ break;
60
+ }
61
+ node = node.getNextSibling();
62
+ }
63
+ const parent = start.getParent();
64
+ if ($isElementNode(parent)) {
65
+ const parentDirection = parent.getDirection();
66
+ if (parentDirection === 'ltr' || parentDirection === 'rtl') {
67
+ return parentDirection;
68
+ }
69
+ }
70
+ return null;
71
+ }
72
+ function $getStartOfCodeInLine(anchor, offset) {
73
+ let last = null;
74
+ let lastNonBlank = null;
75
+ let node = anchor;
76
+ let nodeOffset = offset;
77
+ let nodeTextContent = anchor.getTextContent();
78
+ // eslint-disable-next-line no-constant-condition
79
+ while (true) {
80
+ if (nodeOffset === 0) {
81
+ node = node.getPreviousSibling();
82
+ if (node === null) {
83
+ break;
84
+ }
85
+ if (!($isCodeHighlightNode(node) || $isTabNode(node) || $isLineBreakNode(node))) {
86
+ formatDevErrorMessage(`Expected a valid Code Node: CodeHighlightNode, TabNode, LineBreakNode`);
87
+ }
88
+ if ($isLineBreakNode(node)) {
89
+ last = {
90
+ node,
91
+ offset: 1
92
+ };
93
+ break;
94
+ }
95
+ nodeOffset = Math.max(0, node.getTextContentSize() - 1);
96
+ nodeTextContent = node.getTextContent();
97
+ } else {
98
+ nodeOffset--;
99
+ }
100
+ const character = nodeTextContent[nodeOffset];
101
+ if ($isCodeHighlightNode(node) && character !== ' ') {
102
+ lastNonBlank = {
103
+ node,
104
+ offset: nodeOffset
105
+ };
106
+ }
107
+ }
108
+ // lastNonBlank !== null: anchor in the middle of code; move to line beginning
109
+ if (lastNonBlank !== null) {
110
+ return lastNonBlank;
111
+ }
112
+ // Spaces, tabs or nothing ahead of anchor
113
+ let codeCharacterAtAnchorOffset = null;
114
+ if (offset < anchor.getTextContentSize()) {
115
+ if ($isCodeHighlightNode(anchor)) {
116
+ codeCharacterAtAnchorOffset = anchor.getTextContent()[offset];
117
+ }
118
+ } else {
119
+ const nextSibling = anchor.getNextSibling();
120
+ if ($isCodeHighlightNode(nextSibling)) {
121
+ codeCharacterAtAnchorOffset = nextSibling.getTextContent()[0];
122
+ }
123
+ }
124
+ if (codeCharacterAtAnchorOffset !== null && codeCharacterAtAnchorOffset !== ' ') {
125
+ // Borderline whitespace and code, move to line beginning
126
+ return last;
127
+ } else {
128
+ const nextNonBlank = findNextNonBlankInLine(anchor, offset);
129
+ if (nextNonBlank !== null) {
130
+ return nextNonBlank;
131
+ } else {
132
+ return last;
133
+ }
134
+ }
135
+ }
136
+ function findNextNonBlankInLine(anchor, offset) {
137
+ let node = anchor;
138
+ let nodeOffset = offset;
139
+ let nodeTextContent = anchor.getTextContent();
140
+ let nodeTextContentSize = anchor.getTextContentSize();
141
+ // eslint-disable-next-line no-constant-condition
142
+ while (true) {
143
+ if (!$isCodeHighlightNode(node) || nodeOffset === nodeTextContentSize) {
144
+ node = node.getNextSibling();
145
+ if (node === null || $isLineBreakNode(node)) {
146
+ return null;
147
+ }
148
+ if ($isCodeHighlightNode(node)) {
149
+ nodeOffset = 0;
150
+ nodeTextContent = node.getTextContent();
151
+ nodeTextContentSize = node.getTextContentSize();
152
+ }
153
+ }
154
+ if ($isCodeHighlightNode(node)) {
155
+ if (nodeTextContent[nodeOffset] !== ' ') {
156
+ return {
157
+ node,
158
+ offset: nodeOffset
159
+ };
160
+ }
161
+ nodeOffset++;
162
+ }
163
+ }
164
+ }
165
+ function $getEndOfCodeInLine(anchor) {
166
+ const lastNode = $getLastCodeNodeOfLine(anchor);
167
+ if (!!$isLineBreakNode(lastNode)) {
168
+ formatDevErrorMessage(`Unexpected lineBreakNode in getEndOfCodeInLine`);
169
+ }
170
+ return lastNode;
171
+ }
172
+
173
+ /**
174
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
175
+ *
176
+ * This source code is licensed under the MIT license found in the
177
+ * LICENSE file in the root directory of this source tree.
178
+ *
179
+ */
180
+
181
+ const DEFAULT_CODE_LANGUAGE = 'javascript';
182
+ const getDefaultCodeLanguage = () => DEFAULT_CODE_LANGUAGE;
183
+ function hasChildDOMNodeTag(node, tagName) {
184
+ for (const child of node.childNodes) {
185
+ if (isHTMLElement(child) && child.tagName === tagName) {
186
+ return true;
187
+ }
188
+ hasChildDOMNodeTag(child, tagName);
189
+ }
190
+ return false;
191
+ }
192
+ const LANGUAGE_DATA_ATTRIBUTE = 'data-language';
193
+ const HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE = 'data-highlight-language';
194
+ const THEME_DATA_ATTRIBUTE = 'data-theme';
195
+
196
+ /** @noInheritDoc */
197
+ class CodeNode extends ElementNode {
198
+ /** @internal */
199
+ __language;
200
+ /** @internal */
201
+ __theme;
202
+ /** @internal */
203
+ __isSyntaxHighlightSupported;
204
+ static getType() {
205
+ return 'code';
206
+ }
207
+ static clone(node) {
208
+ return new CodeNode(node.__language, node.__key);
209
+ }
210
+ constructor(language, key) {
211
+ super(key);
212
+ this.__language = language || undefined;
213
+ this.__isSyntaxHighlightSupported = false;
214
+ this.__theme = undefined;
215
+ }
216
+ afterCloneFrom(prevNode) {
217
+ super.afterCloneFrom(prevNode);
218
+ this.__language = prevNode.__language;
219
+ this.__theme = prevNode.__theme;
220
+ this.__isSyntaxHighlightSupported = prevNode.__isSyntaxHighlightSupported;
221
+ }
222
+
223
+ // View
224
+ createDOM(config) {
225
+ const element = document.createElement('code');
226
+ addClassNamesToElement(element, config.theme.code);
227
+ element.setAttribute('spellcheck', 'false');
228
+ const language = this.getLanguage();
229
+ if (language) {
230
+ element.setAttribute(LANGUAGE_DATA_ATTRIBUTE, language);
231
+ if (this.getIsSyntaxHighlightSupported()) {
232
+ element.setAttribute(HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE, language);
233
+ }
234
+ }
235
+ const theme = this.getTheme();
236
+ if (theme) {
237
+ element.setAttribute(THEME_DATA_ATTRIBUTE, theme);
238
+ }
239
+ const style = this.getStyle();
240
+ if (style) {
241
+ element.setAttribute('style', style);
242
+ }
243
+ return element;
244
+ }
245
+ updateDOM(prevNode, dom, config) {
246
+ const language = this.__language;
247
+ const prevLanguage = prevNode.__language;
248
+ if (language) {
249
+ if (language !== prevLanguage) {
250
+ dom.setAttribute(LANGUAGE_DATA_ATTRIBUTE, language);
251
+ }
252
+ } else if (prevLanguage) {
253
+ dom.removeAttribute(LANGUAGE_DATA_ATTRIBUTE);
254
+ }
255
+ const isSyntaxHighlightSupported = this.__isSyntaxHighlightSupported;
256
+ const prevIsSyntaxHighlightSupported = prevNode.__isSyntaxHighlightSupported;
257
+ if (prevIsSyntaxHighlightSupported && prevLanguage) {
258
+ if (isSyntaxHighlightSupported && language) {
259
+ if (language !== prevLanguage) {
260
+ dom.setAttribute(HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE, language);
261
+ }
262
+ } else {
263
+ dom.removeAttribute(HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE);
264
+ }
265
+ } else if (isSyntaxHighlightSupported && language) {
266
+ dom.setAttribute(HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE, language);
267
+ }
268
+ const theme = this.__theme;
269
+ const prevTheme = prevNode.__theme;
270
+ if (theme) {
271
+ if (theme !== prevTheme) {
272
+ dom.setAttribute(THEME_DATA_ATTRIBUTE, theme);
273
+ }
274
+ } else if (prevTheme) {
275
+ dom.removeAttribute(THEME_DATA_ATTRIBUTE);
276
+ }
277
+ const style = this.__style;
278
+ const prevStyle = prevNode.__style;
279
+ if (style) {
280
+ if (style !== prevStyle) {
281
+ dom.setAttribute('style', style);
282
+ }
283
+ } else if (prevStyle) {
284
+ dom.removeAttribute('style');
285
+ }
286
+ return false;
287
+ }
288
+ exportDOM(editor) {
289
+ const element = document.createElement('pre');
290
+ addClassNamesToElement(element, editor._config.theme.code);
291
+ element.setAttribute('spellcheck', 'false');
292
+ const language = this.getLanguage();
293
+ if (language) {
294
+ element.setAttribute(LANGUAGE_DATA_ATTRIBUTE, language);
295
+ if (this.getIsSyntaxHighlightSupported()) {
296
+ element.setAttribute(HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE, language);
297
+ }
298
+ }
299
+ const theme = this.getTheme();
300
+ if (theme) {
301
+ element.setAttribute(THEME_DATA_ATTRIBUTE, theme);
302
+ }
303
+ const style = this.getStyle();
304
+ if (style) {
305
+ element.setAttribute('style', style);
306
+ }
307
+ return {
308
+ element
309
+ };
310
+ }
311
+ static importDOM() {
312
+ return {
313
+ // Typically <pre> is used for code blocks, and <code> for inline code styles
314
+ // but if it's a multi line <code> we'll create a block. Pass through to
315
+ // inline format handled by TextNode otherwise.
316
+ code: node => {
317
+ const isMultiLine = node.textContent != null && (/\r?\n/.test(node.textContent) || hasChildDOMNodeTag(node, 'BR'));
318
+ return isMultiLine ? {
319
+ conversion: $convertPreElement,
320
+ priority: 1
321
+ } : null;
322
+ },
323
+ div: () => ({
324
+ conversion: $convertDivElement,
325
+ priority: 1
326
+ }),
327
+ pre: () => ({
328
+ conversion: $convertPreElement,
329
+ priority: 0
330
+ }),
331
+ table: node => {
332
+ const table = node;
333
+ // domNode is a <table> since we matched it by nodeName
334
+ if (isGitHubCodeTable(table)) {
335
+ return {
336
+ conversion: $convertTableElement,
337
+ priority: 3
338
+ };
339
+ }
340
+ return null;
341
+ },
342
+ td: node => {
343
+ // element is a <td> since we matched it by nodeName
344
+ const td = node;
345
+ const table = td.closest('table');
346
+ if (isGitHubCodeCell(td) || table && isGitHubCodeTable(table)) {
347
+ // Return a no-op if it's a table cell in a code table, but not a code line.
348
+ // Otherwise it'll fall back to the T
349
+ return {
350
+ conversion: convertCodeNoop,
351
+ priority: 3
352
+ };
353
+ }
354
+ return null;
355
+ },
356
+ tr: node => {
357
+ // element is a <tr> since we matched it by nodeName
358
+ const tr = node;
359
+ const table = tr.closest('table');
360
+ if (table && isGitHubCodeTable(table)) {
361
+ return {
362
+ conversion: convertCodeNoop,
363
+ priority: 3
364
+ };
365
+ }
366
+ return null;
367
+ }
368
+ };
369
+ }
370
+ static importJSON(serializedNode) {
371
+ return $createCodeNode().updateFromJSON(serializedNode);
372
+ }
373
+ updateFromJSON(serializedNode) {
374
+ return super.updateFromJSON(serializedNode).setLanguage(serializedNode.language).setTheme(serializedNode.theme);
375
+ }
376
+ exportJSON() {
377
+ return {
378
+ ...super.exportJSON(),
379
+ language: this.getLanguage(),
380
+ theme: this.getTheme()
381
+ };
382
+ }
383
+
384
+ // Mutation
385
+ insertNewAfter(selection, restoreSelection = true) {
386
+ const children = this.getChildren();
387
+ const childrenLength = children.length;
388
+ if (childrenLength >= 2 && children[childrenLength - 1].getTextContent() === '\n' && children[childrenLength - 2].getTextContent() === '\n' && selection.isCollapsed() && selection.anchor.key === this.__key && selection.anchor.offset === childrenLength) {
389
+ children[childrenLength - 1].remove();
390
+ children[childrenLength - 2].remove();
391
+ const newElement = $createParagraphNode();
392
+ this.insertAfter(newElement, restoreSelection);
393
+ return newElement;
394
+ }
395
+
396
+ // If the selection is within the codeblock, find all leading tabs and
397
+ // spaces of the current line. Create a new line that has all those
398
+ // tabs and spaces, such that leading indentation is preserved.
399
+ const {
400
+ anchor,
401
+ focus
402
+ } = selection;
403
+ const firstPoint = anchor.isBefore(focus) ? anchor : focus;
404
+ const firstSelectionNode = firstPoint.getNode();
405
+ if ($isTextNode(firstSelectionNode)) {
406
+ let node = $getFirstCodeNodeOfLine(firstSelectionNode);
407
+ const insertNodes = [];
408
+ // eslint-disable-next-line no-constant-condition
409
+ while (true) {
410
+ if ($isTabNode(node)) {
411
+ insertNodes.push($createTabNode());
412
+ node = node.getNextSibling();
413
+ } else if ($isCodeHighlightNode(node)) {
414
+ let spaces = 0;
415
+ const text = node.getTextContent();
416
+ const textSize = node.getTextContentSize();
417
+ while (spaces < textSize && text[spaces] === ' ') {
418
+ spaces++;
419
+ }
420
+ if (spaces !== 0) {
421
+ insertNodes.push($createCodeHighlightNode(' '.repeat(spaces)));
422
+ }
423
+ if (spaces !== textSize) {
424
+ break;
425
+ }
426
+ node = node.getNextSibling();
427
+ } else {
428
+ break;
429
+ }
430
+ }
431
+ const split = firstSelectionNode.splitText(anchor.offset)[0];
432
+ const x = anchor.offset === 0 ? 0 : 1;
433
+ const index = split.getIndexWithinParent() + x;
434
+ const codeNode = firstSelectionNode.getParentOrThrow();
435
+ const nodesToInsert = [$createLineBreakNode(), ...insertNodes];
436
+ codeNode.splice(index, 0, nodesToInsert);
437
+ const last = insertNodes[insertNodes.length - 1];
438
+ if (last) {
439
+ last.select();
440
+ } else if (anchor.offset === 0) {
441
+ split.selectPrevious();
442
+ } else {
443
+ split.getNextSibling().selectNext(0, 0);
444
+ }
445
+ }
446
+ if ($isCodeNode(firstSelectionNode)) {
447
+ const {
448
+ offset
449
+ } = selection.anchor;
450
+ firstSelectionNode.splice(offset, 0, [$createLineBreakNode()]);
451
+ firstSelectionNode.select(offset + 1, offset + 1);
452
+ }
453
+ return null;
454
+ }
455
+ canIndent() {
456
+ return false;
457
+ }
458
+ collapseAtStart() {
459
+ const paragraph = $createParagraphNode();
460
+ const children = this.getChildren();
461
+ children.forEach(child => paragraph.append(child));
462
+ this.replace(paragraph);
463
+ return true;
464
+ }
465
+ setLanguage(language) {
466
+ const writable = this.getWritable();
467
+ writable.__language = language || undefined;
468
+ return writable;
469
+ }
470
+ getLanguage() {
471
+ return this.getLatest().__language;
472
+ }
473
+ setIsSyntaxHighlightSupported(isSupported) {
474
+ const writable = this.getWritable();
475
+ writable.__isSyntaxHighlightSupported = isSupported;
476
+ return writable;
477
+ }
478
+ getIsSyntaxHighlightSupported() {
479
+ return this.getLatest().__isSyntaxHighlightSupported;
480
+ }
481
+ setTheme(theme) {
482
+ const writable = this.getWritable();
483
+ writable.__theme = theme || undefined;
484
+ return writable;
485
+ }
486
+ getTheme() {
487
+ return this.getLatest().__theme;
488
+ }
489
+ }
490
+ function $createCodeNode(language, theme) {
491
+ return $create(CodeNode).setLanguage(language).setTheme(theme);
492
+ }
493
+ function $isCodeNode(node) {
494
+ return node instanceof CodeNode;
495
+ }
496
+ function $convertPreElement(domNode) {
497
+ const language = domNode.getAttribute(LANGUAGE_DATA_ATTRIBUTE);
498
+ return {
499
+ node: $createCodeNode(language)
500
+ };
501
+ }
502
+ function $convertDivElement(domNode) {
503
+ // domNode is a <div> since we matched it by nodeName
504
+ const div = domNode;
505
+ const isCode = isCodeElement(div);
506
+ if (!isCode && !isCodeChildElement(div)) {
507
+ return {
508
+ node: null
509
+ };
510
+ }
511
+ return {
512
+ node: isCode ? $createCodeNode() : null
513
+ };
514
+ }
515
+ function $convertTableElement() {
516
+ return {
517
+ node: $createCodeNode()
518
+ };
519
+ }
520
+ function convertCodeNoop() {
521
+ return {
522
+ node: null
523
+ };
524
+ }
525
+ function isCodeElement(div) {
526
+ return div.style.fontFamily.match('monospace') !== null;
527
+ }
528
+ function isCodeChildElement(node) {
529
+ let parent = node.parentElement;
530
+ while (parent !== null) {
531
+ if (isCodeElement(parent)) {
532
+ return true;
533
+ }
534
+ parent = parent.parentElement;
535
+ }
536
+ return false;
537
+ }
538
+ function isGitHubCodeCell(cell) {
539
+ return cell.classList.contains('js-file-line');
540
+ }
541
+ function isGitHubCodeTable(table) {
542
+ return table.classList.contains('js-file-line-container');
543
+ }
544
+
545
+ /**
546
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
547
+ *
548
+ * This source code is licensed under the MIT license found in the
549
+ * LICENSE file in the root directory of this source tree.
550
+ *
551
+ */
552
+
553
+ /** @noInheritDoc */
554
+ class CodeHighlightNode extends TextNode {
555
+ /** @internal */
556
+ __highlightType;
557
+ constructor(text = '', highlightType, key) {
558
+ super(text, key);
559
+ this.__highlightType = highlightType;
560
+ }
561
+ static getType() {
562
+ return 'code-highlight';
563
+ }
564
+ static clone(node) {
565
+ return new CodeHighlightNode(node.__text, node.__highlightType || undefined, node.__key);
566
+ }
567
+ getHighlightType() {
568
+ const self = this.getLatest();
569
+ return self.__highlightType;
570
+ }
571
+ setHighlightType(highlightType) {
572
+ const self = this.getWritable();
573
+ self.__highlightType = highlightType || undefined;
574
+ return self;
575
+ }
576
+ canHaveFormat() {
577
+ return false;
578
+ }
579
+ createDOM(config) {
580
+ const element = super.createDOM(config);
581
+ const className = getHighlightThemeClass(config.theme, this.__highlightType);
582
+ addClassNamesToElement(element, className);
583
+ return element;
584
+ }
585
+ updateDOM(prevNode, dom, config) {
586
+ const update = super.updateDOM(prevNode, dom, config);
587
+ const prevClassName = getHighlightThemeClass(config.theme, prevNode.__highlightType);
588
+ const nextClassName = getHighlightThemeClass(config.theme, this.__highlightType);
589
+ if (prevClassName !== nextClassName) {
590
+ if (prevClassName) {
591
+ removeClassNamesFromElement(dom, prevClassName);
592
+ }
593
+ if (nextClassName) {
594
+ addClassNamesToElement(dom, nextClassName);
595
+ }
596
+ }
597
+ return update;
598
+ }
599
+ static importJSON(serializedNode) {
600
+ return $createCodeHighlightNode().updateFromJSON(serializedNode);
601
+ }
602
+ updateFromJSON(serializedNode) {
603
+ return super.updateFromJSON(serializedNode).setHighlightType(serializedNode.highlightType);
604
+ }
605
+ exportJSON() {
606
+ return {
607
+ ...super.exportJSON(),
608
+ highlightType: this.getHighlightType()
609
+ };
610
+ }
611
+
612
+ // Prevent formatting (bold, underline, etc)
613
+ setFormat(format) {
614
+ return this;
615
+ }
616
+ isParentRequired() {
617
+ return true;
618
+ }
619
+ createParentElementNode() {
620
+ return $createCodeNode();
621
+ }
622
+ }
623
+ function getHighlightThemeClass(theme, highlightType) {
624
+ return highlightType && theme && theme.codeHighlight && theme.codeHighlight[highlightType];
625
+ }
626
+ function $createCodeHighlightNode(text = '', highlightType) {
627
+ return $applyNodeReplacement(new CodeHighlightNode(text, highlightType));
628
+ }
629
+ function $isCodeHighlightNode(node) {
630
+ return node instanceof CodeHighlightNode;
631
+ }
632
+
633
+ /**
634
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
635
+ *
636
+ * This source code is licensed under the MIT license found in the
637
+ * LICENSE file in the root directory of this source tree.
638
+ *
639
+ */
640
+
641
+ /**
642
+ * Add code blocks to the editor (syntax highlighting provided separately)
643
+ */
644
+ const CodeExtension = defineExtension({
645
+ name: '@lexical/code',
646
+ nodes: () => [CodeNode, CodeHighlightNode]
647
+ });
648
+
649
+ export { $createCodeHighlightNode, $createCodeNode, $getCodeLineDirection, $getEndOfCodeInLine, $getFirstCodeNodeOfLine, $getLastCodeNodeOfLine, $getStartOfCodeInLine, $isCodeHighlightNode, $isCodeNode, CodeExtension, CodeHighlightNode, CodeNode, DEFAULT_CODE_LANGUAGE, getDefaultCodeLanguage };
@@ -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 LexicalCodeCore = process.env.NODE_ENV !== 'production' ? require('./LexicalCodeCore.dev.js') : require('./LexicalCodeCore.prod.js');
11
+ module.exports = LexicalCodeCore;