@lexical/code 0.7.6 → 0.7.8
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/CodeHighlightNode.d.ts +3 -1
- package/CodeNode.d.ts +2 -2
- package/LexicalCode.dev.js +178 -170
- package/LexicalCode.prod.js +24 -23
- package/package.json +3 -3
package/CodeHighlightNode.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import { type EditorConfig, type LexicalNode, type NodeKey, type SerializedTextNode, type Spread, TextNode } from 'lexical';
|
|
8
|
+
import { type EditorConfig, type LexicalNode, type NodeKey, type SerializedTextNode, type Spread, TextNode, ElementNode } from 'lexical';
|
|
9
9
|
import 'prismjs/components/prism-clike';
|
|
10
10
|
import 'prismjs/components/prism-javascript';
|
|
11
11
|
import 'prismjs/components/prism-markup';
|
|
@@ -43,6 +43,8 @@ export declare class CodeHighlightNode extends TextNode {
|
|
|
43
43
|
static importJSON(serializedNode: SerializedCodeHighlightNode): CodeHighlightNode;
|
|
44
44
|
exportJSON(): SerializedCodeHighlightNode;
|
|
45
45
|
setFormat(format: number): this;
|
|
46
|
+
isParentRequired(): true;
|
|
47
|
+
createParentElementNode(): ElementNode;
|
|
46
48
|
}
|
|
47
49
|
export declare function $createCodeHighlightNode(text: string, highlightType?: string | null | undefined): CodeHighlightNode;
|
|
48
50
|
export declare function $isCodeHighlightNode(node: LexicalNode | CodeHighlightNode | null | undefined): node is CodeHighlightNode;
|
package/CodeNode.d.ts
CHANGED
|
@@ -33,14 +33,14 @@ export declare class CodeNode extends ElementNode {
|
|
|
33
33
|
static clone(node: CodeNode): CodeNode;
|
|
34
34
|
constructor(language?: string | null | undefined, key?: NodeKey);
|
|
35
35
|
createDOM(config: EditorConfig): HTMLElement;
|
|
36
|
-
updateDOM(prevNode: CodeNode, dom: HTMLElement): boolean;
|
|
36
|
+
updateDOM(prevNode: CodeNode, dom: HTMLElement, config: EditorConfig): boolean;
|
|
37
37
|
static importDOM(): DOMConversionMap | null;
|
|
38
38
|
static importJSON(serializedNode: SerializedCodeNode): CodeNode;
|
|
39
39
|
exportJSON(): SerializedCodeNode;
|
|
40
40
|
insertNewAfter(selection: RangeSelection, restoreSelection?: boolean): null | ParagraphNode | CodeHighlightNode;
|
|
41
41
|
canInsertTab(): boolean;
|
|
42
42
|
canIndent(): false;
|
|
43
|
-
collapseAtStart():
|
|
43
|
+
collapseAtStart(): boolean;
|
|
44
44
|
setLanguage(language: string): void;
|
|
45
45
|
getLanguage(): string | null | undefined;
|
|
46
46
|
}
|
package/LexicalCode.dev.js
CHANGED
|
@@ -22,170 +22,6 @@ require('prismjs/components/prism-typescript');
|
|
|
22
22
|
var utils = require('@lexical/utils');
|
|
23
23
|
var lexical = require('lexical');
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
27
|
-
*
|
|
28
|
-
* This source code is licensed under the MIT license found in the
|
|
29
|
-
* LICENSE file in the root directory of this source tree.
|
|
30
|
-
*
|
|
31
|
-
*/
|
|
32
|
-
const DEFAULT_CODE_LANGUAGE = 'javascript';
|
|
33
|
-
const CODE_LANGUAGE_FRIENDLY_NAME_MAP = {
|
|
34
|
-
c: 'C',
|
|
35
|
-
clike: 'C-like',
|
|
36
|
-
css: 'CSS',
|
|
37
|
-
html: 'HTML',
|
|
38
|
-
js: 'JavaScript',
|
|
39
|
-
markdown: 'Markdown',
|
|
40
|
-
objc: 'Objective-C',
|
|
41
|
-
plain: 'Plain Text',
|
|
42
|
-
py: 'Python',
|
|
43
|
-
rust: 'Rust',
|
|
44
|
-
sql: 'SQL',
|
|
45
|
-
swift: 'Swift',
|
|
46
|
-
typescript: 'TypeScript',
|
|
47
|
-
xml: 'XML'
|
|
48
|
-
};
|
|
49
|
-
const CODE_LANGUAGE_MAP = {
|
|
50
|
-
javascript: 'js',
|
|
51
|
-
md: 'markdown',
|
|
52
|
-
plaintext: 'plain',
|
|
53
|
-
python: 'py',
|
|
54
|
-
text: 'plain',
|
|
55
|
-
ts: 'typescript'
|
|
56
|
-
};
|
|
57
|
-
function normalizeCodeLang(lang) {
|
|
58
|
-
return CODE_LANGUAGE_MAP[lang] || lang;
|
|
59
|
-
}
|
|
60
|
-
function getLanguageFriendlyName(lang) {
|
|
61
|
-
const _lang = normalizeCodeLang(lang);
|
|
62
|
-
|
|
63
|
-
return CODE_LANGUAGE_FRIENDLY_NAME_MAP[_lang] || _lang;
|
|
64
|
-
}
|
|
65
|
-
const getDefaultCodeLanguage = () => DEFAULT_CODE_LANGUAGE;
|
|
66
|
-
const getCodeLanguages = () => Object.keys(Prism.languages).filter( // Prism has several language helpers mixed into languages object
|
|
67
|
-
// so filtering them out here to get langs list
|
|
68
|
-
language => typeof Prism.languages[language] !== 'function').sort();
|
|
69
|
-
/** @noInheritDoc */
|
|
70
|
-
|
|
71
|
-
class CodeHighlightNode extends lexical.TextNode {
|
|
72
|
-
/** @internal */
|
|
73
|
-
constructor(text, highlightType, key) {
|
|
74
|
-
super(text, key);
|
|
75
|
-
this.__highlightType = highlightType;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
static getType() {
|
|
79
|
-
return 'code-highlight';
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
static clone(node) {
|
|
83
|
-
return new CodeHighlightNode(node.__text, node.__highlightType || undefined, node.__key);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
getHighlightType() {
|
|
87
|
-
const self = this.getLatest();
|
|
88
|
-
return self.__highlightType;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
createDOM(config) {
|
|
92
|
-
const element = super.createDOM(config);
|
|
93
|
-
const className = getHighlightThemeClass(config.theme, this.__highlightType);
|
|
94
|
-
utils.addClassNamesToElement(element, className);
|
|
95
|
-
return element;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
updateDOM(prevNode, dom, config) {
|
|
99
|
-
const update = super.updateDOM(prevNode, dom, config);
|
|
100
|
-
const prevClassName = getHighlightThemeClass(config.theme, prevNode.__highlightType);
|
|
101
|
-
const nextClassName = getHighlightThemeClass(config.theme, this.__highlightType);
|
|
102
|
-
|
|
103
|
-
if (prevClassName !== nextClassName) {
|
|
104
|
-
if (prevClassName) {
|
|
105
|
-
utils.removeClassNamesFromElement(dom, prevClassName);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (nextClassName) {
|
|
109
|
-
utils.addClassNamesToElement(dom, nextClassName);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return update;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
static importJSON(serializedNode) {
|
|
117
|
-
const node = $createCodeHighlightNode(serializedNode.text, serializedNode.highlightType);
|
|
118
|
-
node.setFormat(serializedNode.format);
|
|
119
|
-
node.setDetail(serializedNode.detail);
|
|
120
|
-
node.setMode(serializedNode.mode);
|
|
121
|
-
node.setStyle(serializedNode.style);
|
|
122
|
-
return node;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
exportJSON() {
|
|
126
|
-
return { ...super.exportJSON(),
|
|
127
|
-
highlightType: this.getHighlightType(),
|
|
128
|
-
type: 'code-highlight',
|
|
129
|
-
version: 1
|
|
130
|
-
};
|
|
131
|
-
} // Prevent formatting (bold, underline, etc)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
setFormat(format) {
|
|
135
|
-
return this;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function getHighlightThemeClass(theme, highlightType) {
|
|
141
|
-
return highlightType && theme && theme.codeHighlight && theme.codeHighlight[highlightType];
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function $createCodeHighlightNode(text, highlightType) {
|
|
145
|
-
return lexical.$applyNodeReplacement(new CodeHighlightNode(text, highlightType));
|
|
146
|
-
}
|
|
147
|
-
function $isCodeHighlightNode(node) {
|
|
148
|
-
return node instanceof CodeHighlightNode;
|
|
149
|
-
}
|
|
150
|
-
function getFirstCodeHighlightNodeOfLine(anchor) {
|
|
151
|
-
let currentNode = null;
|
|
152
|
-
const previousSiblings = anchor.getPreviousSiblings();
|
|
153
|
-
previousSiblings.push(anchor);
|
|
154
|
-
|
|
155
|
-
while (previousSiblings.length > 0) {
|
|
156
|
-
const node = previousSiblings.pop();
|
|
157
|
-
|
|
158
|
-
if ($isCodeHighlightNode(node)) {
|
|
159
|
-
currentNode = node;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (lexical.$isLineBreakNode(node)) {
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return currentNode;
|
|
168
|
-
}
|
|
169
|
-
function getLastCodeHighlightNodeOfLine(anchor) {
|
|
170
|
-
let currentNode = null;
|
|
171
|
-
const nextSiblings = anchor.getNextSiblings();
|
|
172
|
-
nextSiblings.unshift(anchor);
|
|
173
|
-
|
|
174
|
-
while (nextSiblings.length > 0) {
|
|
175
|
-
const node = nextSiblings.shift();
|
|
176
|
-
|
|
177
|
-
if ($isCodeHighlightNode(node)) {
|
|
178
|
-
currentNode = node;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (lexical.$isLineBreakNode(node)) {
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return currentNode;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
25
|
/**
|
|
190
26
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
191
27
|
*
|
|
@@ -243,7 +79,7 @@ class CodeNode extends lexical.ElementNode {
|
|
|
243
79
|
return element;
|
|
244
80
|
}
|
|
245
81
|
|
|
246
|
-
updateDOM(prevNode, dom) {
|
|
82
|
+
updateDOM(prevNode, dom, config) {
|
|
247
83
|
const language = this.__language;
|
|
248
84
|
const prevLanguage = prevNode.__language;
|
|
249
85
|
|
|
@@ -262,7 +98,7 @@ class CodeNode extends lexical.ElementNode {
|
|
|
262
98
|
return {
|
|
263
99
|
// Typically <pre> is used for code blocks, and <code> for inline code styles
|
|
264
100
|
// but if it's a multi line <code> we'll create a block. Pass through to
|
|
265
|
-
// inline format handled by TextNode otherwise
|
|
101
|
+
// inline format handled by TextNode otherwise.
|
|
266
102
|
code: node => {
|
|
267
103
|
const isMultiLine = node.textContent != null && (/\r?\n/.test(node.textContent) || hasChildDOMNodeTag(node, 'BR'));
|
|
268
104
|
return isMultiLine ? {
|
|
@@ -284,7 +120,7 @@ class CodeNode extends lexical.ElementNode {
|
|
|
284
120
|
if (isGitHubCodeTable(table)) {
|
|
285
121
|
return {
|
|
286
122
|
conversion: convertTableElement,
|
|
287
|
-
priority:
|
|
123
|
+
priority: 3
|
|
288
124
|
};
|
|
289
125
|
}
|
|
290
126
|
|
|
@@ -298,7 +134,7 @@ class CodeNode extends lexical.ElementNode {
|
|
|
298
134
|
if (isGitHubCodeCell(td)) {
|
|
299
135
|
return {
|
|
300
136
|
conversion: convertTableCellElement,
|
|
301
|
-
priority:
|
|
137
|
+
priority: 3
|
|
302
138
|
};
|
|
303
139
|
}
|
|
304
140
|
|
|
@@ -307,7 +143,7 @@ class CodeNode extends lexical.ElementNode {
|
|
|
307
143
|
// Otherwise it'll fall back to the T
|
|
308
144
|
return {
|
|
309
145
|
conversion: convertCodeNoop,
|
|
310
|
-
priority:
|
|
146
|
+
priority: 3
|
|
311
147
|
};
|
|
312
148
|
}
|
|
313
149
|
|
|
@@ -321,7 +157,7 @@ class CodeNode extends lexical.ElementNode {
|
|
|
321
157
|
if (table && isGitHubCodeTable(table)) {
|
|
322
158
|
return {
|
|
323
159
|
conversion: convertCodeNoop,
|
|
324
|
-
priority:
|
|
160
|
+
priority: 3
|
|
325
161
|
};
|
|
326
162
|
}
|
|
327
163
|
|
|
@@ -513,6 +349,178 @@ function isGitHubCodeTable(table) {
|
|
|
513
349
|
return table.classList.contains('js-file-line-container');
|
|
514
350
|
}
|
|
515
351
|
|
|
352
|
+
/**
|
|
353
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
354
|
+
*
|
|
355
|
+
* This source code is licensed under the MIT license found in the
|
|
356
|
+
* LICENSE file in the root directory of this source tree.
|
|
357
|
+
*
|
|
358
|
+
*/
|
|
359
|
+
const DEFAULT_CODE_LANGUAGE = 'javascript';
|
|
360
|
+
const CODE_LANGUAGE_FRIENDLY_NAME_MAP = {
|
|
361
|
+
c: 'C',
|
|
362
|
+
clike: 'C-like',
|
|
363
|
+
css: 'CSS',
|
|
364
|
+
html: 'HTML',
|
|
365
|
+
js: 'JavaScript',
|
|
366
|
+
markdown: 'Markdown',
|
|
367
|
+
objc: 'Objective-C',
|
|
368
|
+
plain: 'Plain Text',
|
|
369
|
+
py: 'Python',
|
|
370
|
+
rust: 'Rust',
|
|
371
|
+
sql: 'SQL',
|
|
372
|
+
swift: 'Swift',
|
|
373
|
+
typescript: 'TypeScript',
|
|
374
|
+
xml: 'XML'
|
|
375
|
+
};
|
|
376
|
+
const CODE_LANGUAGE_MAP = {
|
|
377
|
+
javascript: 'js',
|
|
378
|
+
md: 'markdown',
|
|
379
|
+
plaintext: 'plain',
|
|
380
|
+
python: 'py',
|
|
381
|
+
text: 'plain',
|
|
382
|
+
ts: 'typescript'
|
|
383
|
+
};
|
|
384
|
+
function normalizeCodeLang(lang) {
|
|
385
|
+
return CODE_LANGUAGE_MAP[lang] || lang;
|
|
386
|
+
}
|
|
387
|
+
function getLanguageFriendlyName(lang) {
|
|
388
|
+
const _lang = normalizeCodeLang(lang);
|
|
389
|
+
|
|
390
|
+
return CODE_LANGUAGE_FRIENDLY_NAME_MAP[_lang] || _lang;
|
|
391
|
+
}
|
|
392
|
+
const getDefaultCodeLanguage = () => DEFAULT_CODE_LANGUAGE;
|
|
393
|
+
const getCodeLanguages = () => Object.keys(Prism.languages).filter( // Prism has several language helpers mixed into languages object
|
|
394
|
+
// so filtering them out here to get langs list
|
|
395
|
+
language => typeof Prism.languages[language] !== 'function').sort();
|
|
396
|
+
/** @noInheritDoc */
|
|
397
|
+
|
|
398
|
+
class CodeHighlightNode extends lexical.TextNode {
|
|
399
|
+
/** @internal */
|
|
400
|
+
constructor(text, highlightType, key) {
|
|
401
|
+
super(text, key);
|
|
402
|
+
this.__highlightType = highlightType;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
static getType() {
|
|
406
|
+
return 'code-highlight';
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
static clone(node) {
|
|
410
|
+
return new CodeHighlightNode(node.__text, node.__highlightType || undefined, node.__key);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
getHighlightType() {
|
|
414
|
+
const self = this.getLatest();
|
|
415
|
+
return self.__highlightType;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
createDOM(config) {
|
|
419
|
+
const element = super.createDOM(config);
|
|
420
|
+
const className = getHighlightThemeClass(config.theme, this.__highlightType);
|
|
421
|
+
utils.addClassNamesToElement(element, className);
|
|
422
|
+
return element;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
updateDOM(prevNode, dom, config) {
|
|
426
|
+
const update = super.updateDOM(prevNode, dom, config);
|
|
427
|
+
const prevClassName = getHighlightThemeClass(config.theme, prevNode.__highlightType);
|
|
428
|
+
const nextClassName = getHighlightThemeClass(config.theme, this.__highlightType);
|
|
429
|
+
|
|
430
|
+
if (prevClassName !== nextClassName) {
|
|
431
|
+
if (prevClassName) {
|
|
432
|
+
utils.removeClassNamesFromElement(dom, prevClassName);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (nextClassName) {
|
|
436
|
+
utils.addClassNamesToElement(dom, nextClassName);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return update;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
static importJSON(serializedNode) {
|
|
444
|
+
const node = $createCodeHighlightNode(serializedNode.text, serializedNode.highlightType);
|
|
445
|
+
node.setFormat(serializedNode.format);
|
|
446
|
+
node.setDetail(serializedNode.detail);
|
|
447
|
+
node.setMode(serializedNode.mode);
|
|
448
|
+
node.setStyle(serializedNode.style);
|
|
449
|
+
return node;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
exportJSON() {
|
|
453
|
+
return { ...super.exportJSON(),
|
|
454
|
+
highlightType: this.getHighlightType(),
|
|
455
|
+
type: 'code-highlight',
|
|
456
|
+
version: 1
|
|
457
|
+
};
|
|
458
|
+
} // Prevent formatting (bold, underline, etc)
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
setFormat(format) {
|
|
462
|
+
return this;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
isParentRequired() {
|
|
466
|
+
return true;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
createParentElementNode() {
|
|
470
|
+
return $createCodeNode();
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function getHighlightThemeClass(theme, highlightType) {
|
|
476
|
+
return highlightType && theme && theme.codeHighlight && theme.codeHighlight[highlightType];
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function $createCodeHighlightNode(text, highlightType) {
|
|
480
|
+
return lexical.$applyNodeReplacement(new CodeHighlightNode(text, highlightType));
|
|
481
|
+
}
|
|
482
|
+
function $isCodeHighlightNode(node) {
|
|
483
|
+
return node instanceof CodeHighlightNode;
|
|
484
|
+
}
|
|
485
|
+
function getFirstCodeHighlightNodeOfLine(anchor) {
|
|
486
|
+
let currentNode = null;
|
|
487
|
+
const previousSiblings = anchor.getPreviousSiblings();
|
|
488
|
+
previousSiblings.push(anchor);
|
|
489
|
+
|
|
490
|
+
while (previousSiblings.length > 0) {
|
|
491
|
+
const node = previousSiblings.pop();
|
|
492
|
+
|
|
493
|
+
if ($isCodeHighlightNode(node)) {
|
|
494
|
+
currentNode = node;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
if (lexical.$isLineBreakNode(node)) {
|
|
498
|
+
break;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
return currentNode;
|
|
503
|
+
}
|
|
504
|
+
function getLastCodeHighlightNodeOfLine(anchor) {
|
|
505
|
+
let currentNode = null;
|
|
506
|
+
const nextSiblings = anchor.getNextSiblings();
|
|
507
|
+
nextSiblings.unshift(anchor);
|
|
508
|
+
|
|
509
|
+
while (nextSiblings.length > 0) {
|
|
510
|
+
const node = nextSiblings.shift();
|
|
511
|
+
|
|
512
|
+
if ($isCodeHighlightNode(node)) {
|
|
513
|
+
currentNode = node;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
if (lexical.$isLineBreakNode(node)) {
|
|
517
|
+
break;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
return currentNode;
|
|
522
|
+
}
|
|
523
|
+
|
|
516
524
|
/**
|
|
517
525
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
518
526
|
*
|
package/LexicalCode.prod.js
CHANGED
|
@@ -5,30 +5,31 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var e=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-python");require("prismjs/components/prism-rust");require("prismjs/components/prism-swift");
|
|
8
|
-
require("prismjs/components/prism-typescript");var n=require("@lexical/utils"),u=require("lexical");let v=
|
|
9
|
-
class
|
|
10
|
-
|
|
11
|
-
function D(a){let b=null,c=a.getPreviousSiblings();for(c.push(a);0<c.length&&(a=c.pop(),C(a)&&(b=a),!u.$isLineBreakNode(a)););return b}function E(a){let b=null,c=a.getNextSiblings();for(c.unshift(a);0<c.length&&(a=c.shift(),C(a)&&(b=a),!u.$isLineBreakNode(a)););return b}let F=a=>null!=a&&e.languages.hasOwnProperty(a)?a:void 0;function G(a,b){for(let c of a.childNodes){if(c instanceof HTMLElement&&c.tagName===b)return!0;G(c,b)}return!1}
|
|
12
|
-
class H extends u.ElementNode{static getType(){return"code"}static clone(a){return new H(a.__language,a.__key)}constructor(a,b){super(b);this.__language=F(a)}createDOM(a){let b=document.createElement("code");n.addClassNamesToElement(b,a.theme.code);b.setAttribute("spellcheck","false");(a=this.getLanguage())&&b.setAttribute("data-highlight-language",a);return b}updateDOM(a,b){let c=this.__language;a=a.__language;c?c!==a&&b.setAttribute("data-highlight-language",c):a&&b.removeAttribute("data-highlight-language");
|
|
13
|
-
return!1}static importDOM(){return{code:a=>null!=a.textContent&&(/\r?\n/.test(a.textContent)||G(a,"BR"))?{conversion:I,priority:1}:null,div:()=>({conversion:aa,priority:1}),pre:()=>({conversion:I,priority:0}),table:a=>J(a)?{conversion:ba,priority:4}:null,td:a=>{let b=a.closest("table");return a.classList.contains("js-file-line")?{conversion:ca,priority:4}:b&&J(b)?{conversion:K,priority:4}:null},tr:a=>(a=a.closest("table"))&&J(a)?{conversion:K,priority:4}:null}}static importJSON(a){let b=L(a.language);
|
|
8
|
+
require("prismjs/components/prism-typescript");var n=require("@lexical/utils"),u=require("lexical");let v=a=>null!=a&&e.languages.hasOwnProperty(a)?a:void 0;function x(a,b){for(let c of a.childNodes){if(c instanceof HTMLElement&&c.tagName===b)return!0;x(c,b)}return!1}
|
|
9
|
+
class y extends u.ElementNode{static getType(){return"code"}static clone(a){return new y(a.__language,a.__key)}constructor(a,b){super(b);this.__language=v(a)}createDOM(a){let b=document.createElement("code");n.addClassNamesToElement(b,a.theme.code);b.setAttribute("spellcheck","false");(a=this.getLanguage())&&b.setAttribute("data-highlight-language",a);return b}updateDOM(a,b){let c=this.__language;a=a.__language;c?c!==a&&b.setAttribute("data-highlight-language",c):a&&b.removeAttribute("data-highlight-language");
|
|
10
|
+
return!1}static importDOM(){return{code:a=>null!=a.textContent&&(/\r?\n/.test(a.textContent)||x(a,"BR"))?{conversion:z,priority:1}:null,div:()=>({conversion:aa,priority:1}),pre:()=>({conversion:z,priority:0}),table:a=>A(a)?{conversion:ba,priority:3}:null,td:a=>{let b=a.closest("table");return a.classList.contains("js-file-line")?{conversion:ca,priority:3}:b&&A(b)?{conversion:B,priority:3}:null},tr:a=>(a=a.closest("table"))&&A(a)?{conversion:B,priority:3}:null}}static importJSON(a){let b=C(a.language);
|
|
14
11
|
b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),type:"code",version:1}}insertNewAfter(a,b=!0){var c=this.getChildren(),d=c.length;if(2<=d&&"\n"===c[d-1].getTextContent()&&"\n"===c[d-2].getTextContent()&&a.isCollapsed()&&a.anchor.key===this.__key&&a.anchor.offset===d)return c[d-1].remove(),c[d-2].remove(),a=u.$createParagraphNode(),this.insertAfter(a,b),a;b=a.anchor.getNode();d=D(b);if(null!=d){c=
|
|
15
|
-
0;for(d=d.getTextContent();c<d.length&&/[\t ]/.test(d[c]);)c+=1;if(0<c)return c=d.substring(0,c),c=
|
|
16
|
-
function
|
|
17
|
-
function ca(a){return{after:b=>{a.parentNode&&a.parentNode.nextSibling&&b.push(u.$createLineBreakNode());return b},node:null}}function da(a){for(a=a.parentElement;null!==a;){if(null!==a.style.fontFamily.match("monospace"))return!0;a=a.parentElement}return!1}function
|
|
12
|
+
0;for(d=d.getTextContent();c<d.length&&/[\t ]/.test(d[c]);)c+=1;if(0<c)return c=d.substring(0,c),c=E(c),b.insertAfter(c),a.insertNodes([u.$createLineBreakNode()]),c.select(),c}return null}canInsertTab(){let a=u.$getSelection();return u.$isRangeSelection(a)&&a.isCollapsed()?!0:!1}canIndent(){return!1}collapseAtStart(){let a=u.$createParagraphNode();this.getChildren().forEach(b=>a.append(b));this.replace(a);return!0}setLanguage(a){this.getWritable().__language=v(a)}getLanguage(){return this.getLatest().__language}}
|
|
13
|
+
function C(a){return u.$applyNodeReplacement(new y(a))}function F(a){return a instanceof y}function z(){return{node:C(),preformatted:!0}}function aa(a){let b=null!==a.style.fontFamily.match("monospace");return b||da(a)?{after:c=>{let d=a.parentNode;null!=d&&a!==d.lastChild&&c.push(u.$createLineBreakNode());return c},node:b?C():null,preformatted:b}:{node:null}}function ba(){return{node:C(),preformatted:!0}}function B(){return{node:null}}
|
|
14
|
+
function ca(a){return{after:b=>{a.parentNode&&a.parentNode.nextSibling&&b.push(u.$createLineBreakNode());return b},node:null}}function da(a){for(a=a.parentElement;null!==a;){if(null!==a.style.fontFamily.match("monospace"))return!0;a=a.parentElement}return!1}function A(a){return a.classList.contains("js-file-line-container")}
|
|
15
|
+
let G={c:"C",clike:"C-like",css:"CSS",html:"HTML",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},H={javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function I(a){return H[a]||a}
|
|
16
|
+
class J extends u.TextNode{constructor(a,b,c){super(a,c);this.__highlightType=b}static getType(){return"code-highlight"}static clone(a){return new J(a.__text,a.__highlightType||void 0,a.__key)}getHighlightType(){return this.getLatest().__highlightType}createDOM(a){let b=super.createDOM(a);a=K(a.theme,this.__highlightType);n.addClassNamesToElement(b,a);return b}updateDOM(a,b,c){let d=super.updateDOM(a,b,c);a=K(c.theme,a.__highlightType);c=K(c.theme,this.__highlightType);a!==c&&(a&&n.removeClassNamesFromElement(b,
|
|
17
|
+
a),c&&n.addClassNamesToElement(b,c));return d}static importJSON(a){let b=E(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(),type:"code-highlight",version:1}}setFormat(){return this}isParentRequired(){return!0}createParentElementNode(){return C()}}function K(a,b){return b&&a&&a.codeHighlight&&a.codeHighlight[b]}
|
|
18
|
+
function E(a,b){return u.$applyNodeReplacement(new J(a,b))}function L(a){return a instanceof J}function D(a){let b=null,c=a.getPreviousSiblings();for(c.push(a);0<c.length&&(a=c.pop(),L(a)&&(b=a),!u.$isLineBreakNode(a)););return b}function M(a){let b=null,c=a.getNextSiblings();for(c.unshift(a);0<c.length&&(a=c.shift(),L(a)&&(b=a),!u.$isLineBreakNode(a)););return b}let N={defaultLanguage:"javascript",tokenize(a,b){return e.tokenize(a,e.languages[b||""]||e.languages[this.defaultLanguage])}};
|
|
18
19
|
function O(a,b){var c=a.length;let d=-1;if(b)for(b=0;b<c;b++){let f=a[b];if(" "!==f&&"\t"!==f){d=b;break}}else for(--c;-1<c;c--)if(b=a[c]," "!==b&&"\t"!==b){d=c;break}return d}
|
|
19
|
-
function P(a){let b=null,c=-1;var d=a.getPreviousSiblings();for(d.push(a);0<d.length;){var f=d.pop();if(
|
|
20
|
-
function Q(a){let b=null,c=-1;var d=a.getNextSiblings();for(d.unshift(a);0<d.length;){var f=d.shift();if(
|
|
21
|
-
function S(a,b,c){let d=a.getKey();T.has(d)||(T.add(d),void 0===a.getLanguage()&&a.setLanguage(c.defaultLanguage),b.update(()=>{ea(d,()=>{var f=u.$getNodeByKey(d);if(!
|
|
20
|
+
function P(a){let b=null,c=-1;var d=a.getPreviousSiblings();for(d.push(a);0<d.length;){var f=d.pop();if(L(f)){var g=f.getTextContent();g=O(g,!0);-1!==g&&(b=f,c=g)}if(u.$isLineBreakNode(f))break}if(null===b)for(a=a.getNextSiblings();0<a.length;){d=a.shift();if(L(d)&&(f=d.getTextContent(),f=O(f,!0),-1!==f)){b=d;c=f;break}if(u.$isLineBreakNode(d))break}return{node:b,offset:c}}
|
|
21
|
+
function Q(a){let b=null,c=-1;var d=a.getNextSiblings();for(d.unshift(a);0<d.length;){var f=d.shift();if(L(f)){var g=f.getTextContent();g=O(g,!1);-1!==g&&(b=f,c=g+1)}if(u.$isLineBreakNode(f))break}if(null===b)for(a=a.getPreviousSiblings();0<a.length;){d=a.pop();if(L(d)&&(f=d.getTextContent(),f=O(f,!1),-1!==f)){b=d;c=f+1;break}if(u.$isLineBreakNode(d))break}return{node:b,offset:c}}function R(a,b,c){let d=a.getParent();F(d)?S(d,b,c):L(a)&&a.replace(u.$createTextNode(a.__text))}let T=new Set;
|
|
22
|
+
function S(a,b,c){let d=a.getKey();T.has(d)||(T.add(d),void 0===a.getLanguage()&&a.setLanguage(c.defaultLanguage),b.update(()=>{ea(d,()=>{var f=u.$getNodeByKey(d);if(!F(f)||!f.isAttached())return!1;var g=f.getTextContent();g=c.tokenize(g,f.getLanguage()||c.defaultLanguage);g=U(g);var k=f.getChildren();for(f=0;f<k.length&&V(k[f],g[f]);)f++;var h=k.length;let l=g.length,p=Math.min(h,l)-f,m=0;for(;m<p;)if(m++,!V(k[h-m],g[l-m])){m--;break}k=f;h-=m;g=g.slice(f,l-m);let {from:w,to:t,nodesForReplacement:r}=
|
|
22
23
|
{from:k,nodesForReplacement:g,to:h};return w!==t||r.length?(a.splice(w,t-w,r),!0):!1})},{onUpdate:()=>{T.delete(d)},skipTransforms:!0}))}
|
|
23
|
-
function U(a){let b=[];a.forEach(c=>{if("string"===typeof c){c=c.split("\n");for(var d=0;d<c.length;d++){let f=c[d];f.length&&b.push(
|
|
24
|
-
function ea(a,b){a=u.$getNodeByKey(a);if(
|
|
25
|
-
function V(a,b){return
|
|
26
|
-
function X(a,b){let c=a.getTextContent();b===u.INDENT_CONTENT_COMMAND?0<c.length&&/\s/.test(c[0])?a.setTextContent("\t"+c):(b=
|
|
27
|
-
function Y(a,b){let c=u.$getSelection();if(!u.$isRangeSelection(c))return!1;let {anchor:d,focus:f}=c,g=d.offset,k=f.offset,h=d.getNode(),l=f.getNode();var p=a===u.KEY_ARROW_UP_COMMAND;if(!
|
|
28
|
-
b.preventDefault(),!0;return!1}var m=D(h);let w=
|
|
29
|
-
r.insertBefore(b)):(r.insertAfter(b),r=b,t.forEach(q=>{r.insertAfter(q);r=q}));c.setTextNodeRange(h,g,l,k);return!0}function fa(a,b){let c=u.$getSelection();if(!u.$isRangeSelection(c))return!1;let {anchor:d,focus:f}=c,g=d.getNode(),k=f.getNode();a=a===u.MOVE_TO_START;if(!
|
|
30
|
-
exports.$createCodeNode=
|
|
31
|
-
exports.getLanguageFriendlyName=function(a){a=
|
|
32
|
-
exports.registerCodeHighlighting=function(a,b){if(!a.hasNodes([
|
|
33
|
-
0;m<h;m++)u.$isLineBreakNode(f[m])&&(l+="\n"+ ++p);d.setAttribute("data-gutter",l)}}})}),a.registerNodeTransform(
|
|
24
|
+
function U(a){let b=[];a.forEach(c=>{if("string"===typeof c){c=c.split("\n");for(var d=0;d<c.length;d++){let f=c[d];f.length&&b.push(E(f));d<c.length-1&&b.push(u.$createLineBreakNode())}}else({content:d}=c),"string"===typeof d?b.push(E(d,c.type)):Array.isArray(d)&&1===d.length&&"string"===typeof d[0]?b.push(E(d[0],c.type)):Array.isArray(d)&&b.push(...U(d))});return b}
|
|
25
|
+
function ea(a,b){a=u.$getNodeByKey(a);if(F(a)&&a.isAttached()){var c=u.$getSelection();if(u.$isRangeSelection(c)){c=c.anchor;var d=c.offset,f="element"===c.type&&u.$isLineBreakNode(a.getChildAtIndex(c.offset-1)),g=0;if(!f){let k=c.getNode();g=d+k.getPreviousSiblings().reduce((h,l)=>h+l.getTextContentSize(),0)}b()&&(f?c.getNode().select(d,d):a.getChildren().some(k=>{let h=u.$isTextNode(k);if(h||u.$isLineBreakNode(k)){let l=k.getTextContentSize();if(h&&l>=g)return k.select(g,g),!0;g-=l}return!1}))}else b()}}
|
|
26
|
+
function V(a,b){return L(a)&&L(b)?a.__text===b.__text&&a.__highlightType===b.__highlightType:u.$isLineBreakNode(a)&&u.$isLineBreakNode(b)?!0:!1}function W(a){var b=u.$getSelection();if(!u.$isRangeSelection(b)||b.isCollapsed())return!1;b=b.getNodes();for(var c=0;c<b.length;c++){var d=b[c];if(!L(d)&&!u.$isLineBreakNode(d))return!1}c=D(b[0]);null!=c&&X(c,a);for(c=1;c<b.length;c++)d=b[c],u.$isLineBreakNode(b[c-1])&&L(d)&&X(d,a);return!0}
|
|
27
|
+
function X(a,b){let c=a.getTextContent();b===u.INDENT_CONTENT_COMMAND?0<c.length&&/\s/.test(c[0])?a.setTextContent("\t"+c):(b=E("\t"),a.insertBefore(b)):0===c.indexOf("\t")&&(1===c.length?a.remove():a.setTextContent(c.substring(1)))}
|
|
28
|
+
function Y(a,b){let c=u.$getSelection();if(!u.$isRangeSelection(c))return!1;let {anchor:d,focus:f}=c,g=d.offset,k=f.offset,h=d.getNode(),l=f.getNode();var p=a===u.KEY_ARROW_UP_COMMAND;if(!L(h)||!L(l))return!1;if(!b.altKey){if(c.isCollapsed())if(a=h.getParentOrThrow(),p&&0===g&&null===h.getPreviousSibling()){if(null===a.getPreviousSibling())return a.selectPrevious(),b.preventDefault(),!0}else if(!p&&g===h.getTextContentSize()&&null===h.getNextSibling()&&null===a.getNextSibling())return a.selectNext(),
|
|
29
|
+
b.preventDefault(),!0;return!1}var m=D(h);let w=M(l);if(null==m||null==w)return!1;let t=m.getNodesBetween(w);for(let q=0;q<t.length;q++){let Z=t[q];if(!L(Z)&&!u.$isLineBreakNode(Z))return!1}b.preventDefault();b.stopPropagation();b=p?m.getPreviousSibling():w.getNextSibling();if(!u.$isLineBreakNode(b))return!0;m=p?b.getPreviousSibling():b.getNextSibling();if(null==m)return!0;p=p?D(m):M(m);let r=null!=p?p:m;b.remove();t.forEach(q=>q.remove());a===u.KEY_ARROW_UP_COMMAND?(t.forEach(q=>r.insertBefore(q)),
|
|
30
|
+
r.insertBefore(b)):(r.insertAfter(b),r=b,t.forEach(q=>{r.insertAfter(q);r=q}));c.setTextNodeRange(h,g,l,k);return!0}function fa(a,b){let c=u.$getSelection();if(!u.$isRangeSelection(c))return!1;let {anchor:d,focus:f}=c,g=d.getNode(),k=f.getNode();a=a===u.MOVE_TO_START;if(!L(g)||!L(k))return!1;let h,l;a?{node:h,offset:l}=P(k):{node:h,offset:l}=Q(k);null!==h&&-1!==l&&c.setTextNodeRange(h,l,h,l);b.preventDefault();b.stopPropagation();return!0}exports.$createCodeHighlightNode=E;
|
|
31
|
+
exports.$createCodeNode=C;exports.$isCodeHighlightNode=L;exports.$isCodeNode=F;exports.CODE_LANGUAGE_FRIENDLY_NAME_MAP=G;exports.CODE_LANGUAGE_MAP=H;exports.CodeHighlightNode=J;exports.CodeNode=y;exports.DEFAULT_CODE_LANGUAGE="javascript";exports.PrismTokenizer=N;exports.getCodeLanguages=()=>Object.keys(e.languages).filter(a=>"function"!==typeof e.languages[a]).sort();exports.getDefaultCodeLanguage=()=>"javascript";exports.getEndOfCodeInLine=Q;exports.getFirstCodeHighlightNodeOfLine=D;
|
|
32
|
+
exports.getLanguageFriendlyName=function(a){a=I(a);return G[a]||a};exports.getLastCodeHighlightNodeOfLine=M;exports.getStartOfCodeInLine=P;exports.normalizeCodeLang=I;
|
|
33
|
+
exports.registerCodeHighlighting=function(a,b){if(!a.hasNodes([y,J]))throw Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");null==b&&(b=N);return n.mergeRegister(a.registerMutationListener(y,c=>{a.update(()=>{for(let [g,k]of c)if("destroyed"!==k){var d=u.$getNodeByKey(g);if(null!==d)a:{var f=d;d=a.getElementByKey(f.getKey());if(null===d)break a;f=f.getChildren();let h=f.length;if(h===d.__cachedChildrenLength)break a;d.__cachedChildrenLength=h;let l="1",p=1;for(let m=
|
|
34
|
+
0;m<h;m++)u.$isLineBreakNode(f[m])&&(l+="\n"+ ++p);d.setAttribute("data-gutter",l)}}})}),a.registerNodeTransform(y,c=>S(c,a,b)),a.registerNodeTransform(u.TextNode,c=>R(c,a,b)),a.registerNodeTransform(J,c=>R(c,a,b)),a.registerCommand(u.INDENT_CONTENT_COMMAND,()=>W(u.INDENT_CONTENT_COMMAND),u.COMMAND_PRIORITY_LOW),a.registerCommand(u.OUTDENT_CONTENT_COMMAND,()=>W(u.OUTDENT_CONTENT_COMMAND),u.COMMAND_PRIORITY_LOW),a.registerCommand(u.KEY_ARROW_UP_COMMAND,c=>Y(u.KEY_ARROW_UP_COMMAND,c),u.COMMAND_PRIORITY_LOW),
|
|
34
35
|
a.registerCommand(u.KEY_ARROW_DOWN_COMMAND,c=>Y(u.KEY_ARROW_DOWN_COMMAND,c),u.COMMAND_PRIORITY_LOW),a.registerCommand(u.MOVE_TO_END,c=>fa(u.MOVE_TO_END,c),u.COMMAND_PRIORITY_LOW),a.registerCommand(u.MOVE_TO_START,c=>fa(u.MOVE_TO_START,c),u.COMMAND_PRIORITY_LOW))}
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"code"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.7.
|
|
11
|
+
"version": "0.7.8",
|
|
12
12
|
"main": "LexicalCode.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.7.
|
|
14
|
+
"lexical": "0.7.8"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.7.
|
|
17
|
+
"@lexical/utils": "0.7.8",
|
|
18
18
|
"prismjs": "^1.27.0"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|