@react-fabric/lexical 1.0.0-beta.60 → 1.0.0-beta.61
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/dist/cjs/{packages/lexical/src/components → components}/StickyComponent.js +2 -3
- package/dist/cjs/{packages/lexical/src/editor → editor}/LexicalEditor.js +5 -5
- package/dist/cjs/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +101 -95
- package/dist/cjs/i18n/ar.json.js +24 -0
- package/dist/cjs/i18n/en.json.js +24 -0
- package/dist/cjs/i18n/index.js +33 -0
- package/dist/cjs/{packages/lexical/src/index.js → index.js} +1 -0
- package/dist/cjs/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +5 -5
- package/dist/cjs/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +35 -22
- package/dist/esm/{packages/lexical/src/components → components}/StickyComponent.js +2 -3
- package/dist/esm/{packages/lexical/src/editor → editor}/LexicalEditor.js +4 -4
- package/dist/esm/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +43 -37
- package/dist/esm/i18n/ar.json.js +21 -0
- package/dist/esm/i18n/en.json.js +21 -0
- package/dist/esm/i18n/index.js +33 -0
- package/dist/esm/{packages/lexical/src/index.js → index.js} +1 -0
- package/dist/esm/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +2 -2
- package/dist/esm/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +36 -23
- package/dist/types/hooks/useFormatWatcher.d.ts +1 -0
- package/dist/types/i18n/index.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +5 -5
- package/src/components/StickyComponent.tsx +2 -3
- package/src/hooks/useFormatWatcher.ts +3 -0
- package/src/i18n/ar.json +16 -0
- package/src/i18n/en.json +16 -0
- package/src/i18n/index.ts +28 -0
- package/src/index.ts +2 -0
- package/src/plugins/ToolbarPlugin.tsx +34 -23
- package/dist/cjs/_virtual/prism.js +0 -5
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -474
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -21
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -27
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +0 -1537
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +0 -25
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +0 -57
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +0 -252
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +0 -19
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +0 -18
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +0 -572
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +0 -17
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +0 -25
- package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +0 -1614
- package/dist/cjs/node_modules/@lexical/list/LexicalList.js +0 -29
- package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +0 -36
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -838
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +0 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -26
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -1057
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +0 -39
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -45
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +0 -4207
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +0 -23
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +0 -68
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -1166
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +0 -47
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -81
- package/dist/cjs/node_modules/@mdi/js/mdi.js +0 -8
- package/dist/cjs/node_modules/prismjs/components/prism-c.js +0 -82
- package/dist/cjs/node_modules/prismjs/components/prism-clike.js +0 -33
- package/dist/cjs/node_modules/prismjs/components/prism-cpp.js +0 -101
- package/dist/cjs/node_modules/prismjs/components/prism-css.js +0 -66
- package/dist/cjs/node_modules/prismjs/components/prism-java.js +0 -126
- package/dist/cjs/node_modules/prismjs/components/prism-javascript.js +0 -174
- package/dist/cjs/node_modules/prismjs/components/prism-markdown.js +0 -417
- package/dist/cjs/node_modules/prismjs/components/prism-markup.js +0 -188
- package/dist/cjs/node_modules/prismjs/components/prism-objectivec.js +0 -14
- package/dist/cjs/node_modules/prismjs/components/prism-powershell.js +0 -60
- package/dist/cjs/node_modules/prismjs/components/prism-python.js +0 -67
- package/dist/cjs/node_modules/prismjs/components/prism-rust.js +0 -130
- package/dist/cjs/node_modules/prismjs/components/prism-sql.js +0 -34
- package/dist/cjs/node_modules/prismjs/components/prism-swift.js +0 -150
- package/dist/cjs/node_modules/prismjs/components/prism-typescript.js +0 -62
- package/dist/cjs/node_modules/prismjs/prism.js +0 -1951
- package/dist/esm/_virtual/prism.js +0 -5
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -465
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -19
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -18
- package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +0 -1512
- package/dist/esm/node_modules/@lexical/code/LexicalCode.js +0 -21
- package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +0 -32
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +0 -251
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +0 -18
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +0 -17
- package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +0 -563
- package/dist/esm/node_modules/@lexical/link/LexicalLink.js +0 -17
- package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +0 -16
- package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +0 -1595
- package/dist/esm/node_modules/@lexical/list/LexicalList.js +0 -23
- package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +0 -17
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -830
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +0 -23
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -18
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -1028
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +0 -28
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -16
- package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +0 -4156
- package/dist/esm/node_modules/@lexical/table/LexicalTable.js +0 -20
- package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +0 -17
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -1102
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +0 -32
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -17
- package/dist/esm/node_modules/@mdi/js/mdi.js +0 -7
- package/dist/esm/node_modules/prismjs/components/prism-c.js +0 -82
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +0 -33
- package/dist/esm/node_modules/prismjs/components/prism-cpp.js +0 -101
- package/dist/esm/node_modules/prismjs/components/prism-css.js +0 -66
- package/dist/esm/node_modules/prismjs/components/prism-java.js +0 -126
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +0 -174
- package/dist/esm/node_modules/prismjs/components/prism-markdown.js +0 -417
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +0 -188
- package/dist/esm/node_modules/prismjs/components/prism-objectivec.js +0 -14
- package/dist/esm/node_modules/prismjs/components/prism-powershell.js +0 -60
- package/dist/esm/node_modules/prismjs/components/prism-python.js +0 -67
- package/dist/esm/node_modules/prismjs/components/prism-rust.js +0 -130
- package/dist/esm/node_modules/prismjs/components/prism-sql.js +0 -34
- package/dist/esm/node_modules/prismjs/components/prism-swift.js +0 -150
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +0 -62
- package/dist/esm/node_modules/prismjs/prism.js +0 -1951
- /package/dist/cjs/{packages/lexical/src/editor → editor}/theme.js +0 -0
- /package/dist/cjs/{packages/lexical/src/nodes → nodes}/StickyNode.js +0 -0
- /package/dist/cjs/{packages/lexical/src/plugins → plugins}/StickyPlugin.js +0 -0
- /package/dist/cjs/{packages/lexical/src/utils → utils}/index.js +0 -0
- /package/dist/esm/{packages/lexical/src/editor → editor}/theme.js +0 -0
- /package/dist/esm/{packages/lexical/src/nodes → nodes}/StickyNode.js +0 -0
- /package/dist/esm/{packages/lexical/src/plugins → plugins}/StickyPlugin.js +0 -0
- /package/dist/esm/{packages/lexical/src/utils → utils}/index.js +0 -0
|
@@ -1,1537 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var LexicalUtils = require('../utils/LexicalUtils.js');
|
|
4
|
-
var lexical = require('lexical');
|
|
5
|
-
require('../../prismjs/prism.js');
|
|
6
|
-
require('../../prismjs/components/prism-clike.js');
|
|
7
|
-
require('../../prismjs/components/prism-javascript.js');
|
|
8
|
-
require('../../prismjs/components/prism-markup.js');
|
|
9
|
-
require('../../prismjs/components/prism-markdown.js');
|
|
10
|
-
require('../../prismjs/components/prism-c.js');
|
|
11
|
-
require('../../prismjs/components/prism-css.js');
|
|
12
|
-
require('../../prismjs/components/prism-objectivec.js');
|
|
13
|
-
require('../../prismjs/components/prism-sql.js');
|
|
14
|
-
require('../../prismjs/components/prism-powershell.js');
|
|
15
|
-
require('../../prismjs/components/prism-python.js');
|
|
16
|
-
require('../../prismjs/components/prism-rust.js');
|
|
17
|
-
require('../../prismjs/components/prism-swift.js');
|
|
18
|
-
require('../../prismjs/components/prism-typescript.js');
|
|
19
|
-
require('../../prismjs/components/prism-java.js');
|
|
20
|
-
require('../../prismjs/components/prism-cpp.js');
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
24
|
-
*
|
|
25
|
-
* This source code is licensed under the MIT license found in the
|
|
26
|
-
* LICENSE file in the root directory of this source tree.
|
|
27
|
-
*
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
33
|
-
*
|
|
34
|
-
* This source code is licensed under the MIT license found in the
|
|
35
|
-
* LICENSE file in the root directory of this source tree.
|
|
36
|
-
*
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
// Do not require this module directly! Use normal `invariant` calls.
|
|
40
|
-
|
|
41
|
-
function formatDevErrorMessage(message) {
|
|
42
|
-
throw new Error(message);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
47
|
-
*
|
|
48
|
-
* This source code is licensed under the MIT license found in the
|
|
49
|
-
* LICENSE file in the root directory of this source tree.
|
|
50
|
-
*
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
const DEFAULT_CODE_LANGUAGE = 'javascript';
|
|
54
|
-
const getDefaultCodeLanguage = () => DEFAULT_CODE_LANGUAGE;
|
|
55
|
-
function hasChildDOMNodeTag(node, tagName) {
|
|
56
|
-
for (const child of node.childNodes) {
|
|
57
|
-
if (LexicalUtils.isHTMLElement(child) && child.tagName === tagName) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
hasChildDOMNodeTag(child, tagName);
|
|
61
|
-
}
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
const LANGUAGE_DATA_ATTRIBUTE = 'data-language';
|
|
65
|
-
const HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE = 'data-highlight-language';
|
|
66
|
-
const THEME_DATA_ATTRIBUTE = 'data-theme';
|
|
67
|
-
|
|
68
|
-
/** @noInheritDoc */
|
|
69
|
-
class CodeNode extends lexical.ElementNode {
|
|
70
|
-
/** @internal */
|
|
71
|
-
|
|
72
|
-
/** @internal */
|
|
73
|
-
|
|
74
|
-
/** @internal */
|
|
75
|
-
|
|
76
|
-
static getType() {
|
|
77
|
-
return 'code';
|
|
78
|
-
}
|
|
79
|
-
static clone(node) {
|
|
80
|
-
return new CodeNode(node.__language, node.__key);
|
|
81
|
-
}
|
|
82
|
-
constructor(language, key) {
|
|
83
|
-
super(key);
|
|
84
|
-
this.__language = language || undefined;
|
|
85
|
-
this.__isSyntaxHighlightSupported = false;
|
|
86
|
-
this.__theme = undefined;
|
|
87
|
-
}
|
|
88
|
-
afterCloneFrom(prevNode) {
|
|
89
|
-
super.afterCloneFrom(prevNode);
|
|
90
|
-
this.__language = prevNode.__language;
|
|
91
|
-
this.__theme = prevNode.__theme;
|
|
92
|
-
this.__isSyntaxHighlightSupported = prevNode.__isSyntaxHighlightSupported;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// View
|
|
96
|
-
createDOM(config) {
|
|
97
|
-
const element = document.createElement('code');
|
|
98
|
-
LexicalUtils.addClassNamesToElement(element, config.theme.code);
|
|
99
|
-
element.setAttribute('spellcheck', 'false');
|
|
100
|
-
const language = this.getLanguage();
|
|
101
|
-
if (language) {
|
|
102
|
-
element.setAttribute(LANGUAGE_DATA_ATTRIBUTE, language);
|
|
103
|
-
if (this.getIsSyntaxHighlightSupported()) {
|
|
104
|
-
element.setAttribute(HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE, language);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const theme = this.getTheme();
|
|
108
|
-
if (theme) {
|
|
109
|
-
element.setAttribute(THEME_DATA_ATTRIBUTE, theme);
|
|
110
|
-
}
|
|
111
|
-
const style = this.getStyle();
|
|
112
|
-
if (style) {
|
|
113
|
-
element.setAttribute('style', style);
|
|
114
|
-
}
|
|
115
|
-
return element;
|
|
116
|
-
}
|
|
117
|
-
updateDOM(prevNode, dom, config) {
|
|
118
|
-
const language = this.__language;
|
|
119
|
-
const prevLanguage = prevNode.__language;
|
|
120
|
-
if (language) {
|
|
121
|
-
if (language !== prevLanguage) {
|
|
122
|
-
dom.setAttribute(LANGUAGE_DATA_ATTRIBUTE, language);
|
|
123
|
-
}
|
|
124
|
-
} else if (prevLanguage) {
|
|
125
|
-
dom.removeAttribute(LANGUAGE_DATA_ATTRIBUTE);
|
|
126
|
-
}
|
|
127
|
-
const isSyntaxHighlightSupported = this.__isSyntaxHighlightSupported;
|
|
128
|
-
const prevIsSyntaxHighlightSupported = prevNode.__isSyntaxHighlightSupported;
|
|
129
|
-
if (prevIsSyntaxHighlightSupported && prevLanguage) {
|
|
130
|
-
if (isSyntaxHighlightSupported && language) {
|
|
131
|
-
if (language !== prevLanguage) {
|
|
132
|
-
dom.setAttribute(HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE, language);
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
dom.removeAttribute(HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE);
|
|
136
|
-
}
|
|
137
|
-
} else if (isSyntaxHighlightSupported && language) {
|
|
138
|
-
dom.setAttribute(HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE, language);
|
|
139
|
-
}
|
|
140
|
-
const theme = this.__theme;
|
|
141
|
-
const prevTheme = prevNode.__theme;
|
|
142
|
-
if (theme) {
|
|
143
|
-
if (theme !== prevTheme) {
|
|
144
|
-
dom.setAttribute(THEME_DATA_ATTRIBUTE, theme);
|
|
145
|
-
}
|
|
146
|
-
} else if (prevTheme) {
|
|
147
|
-
dom.removeAttribute(THEME_DATA_ATTRIBUTE);
|
|
148
|
-
}
|
|
149
|
-
const style = this.__style;
|
|
150
|
-
const prevStyle = prevNode.__style;
|
|
151
|
-
if (style) {
|
|
152
|
-
if (style !== prevStyle) {
|
|
153
|
-
dom.setAttribute('style', style);
|
|
154
|
-
}
|
|
155
|
-
} else if (prevStyle) {
|
|
156
|
-
dom.removeAttribute('style');
|
|
157
|
-
}
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
|
-
exportDOM(editor) {
|
|
161
|
-
const element = document.createElement('pre');
|
|
162
|
-
LexicalUtils.addClassNamesToElement(element, editor._config.theme.code);
|
|
163
|
-
element.setAttribute('spellcheck', 'false');
|
|
164
|
-
const language = this.getLanguage();
|
|
165
|
-
if (language) {
|
|
166
|
-
element.setAttribute(LANGUAGE_DATA_ATTRIBUTE, language);
|
|
167
|
-
if (this.getIsSyntaxHighlightSupported()) {
|
|
168
|
-
element.setAttribute(HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE, language);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
const theme = this.getTheme();
|
|
172
|
-
if (theme) {
|
|
173
|
-
element.setAttribute(THEME_DATA_ATTRIBUTE, theme);
|
|
174
|
-
}
|
|
175
|
-
const style = this.getStyle();
|
|
176
|
-
if (style) {
|
|
177
|
-
element.setAttribute('style', style);
|
|
178
|
-
}
|
|
179
|
-
return {
|
|
180
|
-
element
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
static importDOM() {
|
|
184
|
-
return {
|
|
185
|
-
// Typically <pre> is used for code blocks, and <code> for inline code styles
|
|
186
|
-
// but if it's a multi line <code> we'll create a block. Pass through to
|
|
187
|
-
// inline format handled by TextNode otherwise.
|
|
188
|
-
code: node => {
|
|
189
|
-
const isMultiLine = node.textContent != null && (/\r?\n/.test(node.textContent) || hasChildDOMNodeTag(node, 'BR'));
|
|
190
|
-
return isMultiLine ? {
|
|
191
|
-
conversion: $convertPreElement,
|
|
192
|
-
priority: 1
|
|
193
|
-
} : null;
|
|
194
|
-
},
|
|
195
|
-
div: () => ({
|
|
196
|
-
conversion: $convertDivElement,
|
|
197
|
-
priority: 1
|
|
198
|
-
}),
|
|
199
|
-
pre: () => ({
|
|
200
|
-
conversion: $convertPreElement,
|
|
201
|
-
priority: 0
|
|
202
|
-
}),
|
|
203
|
-
table: node => {
|
|
204
|
-
const table = node;
|
|
205
|
-
// domNode is a <table> since we matched it by nodeName
|
|
206
|
-
if (isGitHubCodeTable(table)) {
|
|
207
|
-
return {
|
|
208
|
-
conversion: $convertTableElement,
|
|
209
|
-
priority: 3
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
return null;
|
|
213
|
-
},
|
|
214
|
-
td: node => {
|
|
215
|
-
// element is a <td> since we matched it by nodeName
|
|
216
|
-
const td = node;
|
|
217
|
-
const table = td.closest('table');
|
|
218
|
-
if (isGitHubCodeCell(td) || table && isGitHubCodeTable(table)) {
|
|
219
|
-
// Return a no-op if it's a table cell in a code table, but not a code line.
|
|
220
|
-
// Otherwise it'll fall back to the T
|
|
221
|
-
return {
|
|
222
|
-
conversion: convertCodeNoop,
|
|
223
|
-
priority: 3
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
return null;
|
|
227
|
-
},
|
|
228
|
-
tr: node => {
|
|
229
|
-
// element is a <tr> since we matched it by nodeName
|
|
230
|
-
const tr = node;
|
|
231
|
-
const table = tr.closest('table');
|
|
232
|
-
if (table && isGitHubCodeTable(table)) {
|
|
233
|
-
return {
|
|
234
|
-
conversion: convertCodeNoop,
|
|
235
|
-
priority: 3
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
return null;
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
static importJSON(serializedNode) {
|
|
243
|
-
return $createCodeNode().updateFromJSON(serializedNode);
|
|
244
|
-
}
|
|
245
|
-
updateFromJSON(serializedNode) {
|
|
246
|
-
return super.updateFromJSON(serializedNode).setLanguage(serializedNode.language).setTheme(serializedNode.theme);
|
|
247
|
-
}
|
|
248
|
-
exportJSON() {
|
|
249
|
-
return {
|
|
250
|
-
...super.exportJSON(),
|
|
251
|
-
language: this.getLanguage(),
|
|
252
|
-
theme: this.getTheme()
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Mutation
|
|
257
|
-
insertNewAfter(selection, restoreSelection = true) {
|
|
258
|
-
const children = this.getChildren();
|
|
259
|
-
const childrenLength = children.length;
|
|
260
|
-
if (childrenLength >= 2 && children[childrenLength - 1].getTextContent() === '\n' && children[childrenLength - 2].getTextContent() === '\n' && selection.isCollapsed() && selection.anchor.key === this.__key && selection.anchor.offset === childrenLength) {
|
|
261
|
-
children[childrenLength - 1].remove();
|
|
262
|
-
children[childrenLength - 2].remove();
|
|
263
|
-
const newElement = lexical.$createParagraphNode();
|
|
264
|
-
this.insertAfter(newElement, restoreSelection);
|
|
265
|
-
return newElement;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// If the selection is within the codeblock, find all leading tabs and
|
|
269
|
-
// spaces of the current line. Create a new line that has all those
|
|
270
|
-
// tabs and spaces, such that leading indentation is preserved.
|
|
271
|
-
const {
|
|
272
|
-
anchor,
|
|
273
|
-
focus
|
|
274
|
-
} = selection;
|
|
275
|
-
const firstPoint = anchor.isBefore(focus) ? anchor : focus;
|
|
276
|
-
const firstSelectionNode = firstPoint.getNode();
|
|
277
|
-
if (lexical.$isTextNode(firstSelectionNode)) {
|
|
278
|
-
let node = $getFirstCodeNodeOfLine(firstSelectionNode);
|
|
279
|
-
const insertNodes = [];
|
|
280
|
-
// eslint-disable-next-line no-constant-condition
|
|
281
|
-
while (true) {
|
|
282
|
-
if (lexical.$isTabNode(node)) {
|
|
283
|
-
insertNodes.push(lexical.$createTabNode());
|
|
284
|
-
node = node.getNextSibling();
|
|
285
|
-
} else if ($isCodeHighlightNode(node)) {
|
|
286
|
-
let spaces = 0;
|
|
287
|
-
const text = node.getTextContent();
|
|
288
|
-
const textSize = node.getTextContentSize();
|
|
289
|
-
while (spaces < textSize && text[spaces] === ' ') {
|
|
290
|
-
spaces++;
|
|
291
|
-
}
|
|
292
|
-
if (spaces !== 0) {
|
|
293
|
-
insertNodes.push($createCodeHighlightNode(' '.repeat(spaces)));
|
|
294
|
-
}
|
|
295
|
-
if (spaces !== textSize) {
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
node = node.getNextSibling();
|
|
299
|
-
} else {
|
|
300
|
-
break;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
const split = firstSelectionNode.splitText(anchor.offset)[0];
|
|
304
|
-
const x = anchor.offset === 0 ? 0 : 1;
|
|
305
|
-
const index = split.getIndexWithinParent() + x;
|
|
306
|
-
const codeNode = firstSelectionNode.getParentOrThrow();
|
|
307
|
-
const nodesToInsert = [lexical.$createLineBreakNode(), ...insertNodes];
|
|
308
|
-
codeNode.splice(index, 0, nodesToInsert);
|
|
309
|
-
const last = insertNodes[insertNodes.length - 1];
|
|
310
|
-
if (last) {
|
|
311
|
-
last.select();
|
|
312
|
-
} else if (anchor.offset === 0) {
|
|
313
|
-
split.selectPrevious();
|
|
314
|
-
} else {
|
|
315
|
-
split.getNextSibling().selectNext(0, 0);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
if ($isCodeNode(firstSelectionNode)) {
|
|
319
|
-
const {
|
|
320
|
-
offset
|
|
321
|
-
} = selection.anchor;
|
|
322
|
-
firstSelectionNode.splice(offset, 0, [lexical.$createLineBreakNode()]);
|
|
323
|
-
firstSelectionNode.select(offset + 1, offset + 1);
|
|
324
|
-
}
|
|
325
|
-
return null;
|
|
326
|
-
}
|
|
327
|
-
canIndent() {
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
collapseAtStart() {
|
|
331
|
-
const paragraph = lexical.$createParagraphNode();
|
|
332
|
-
const children = this.getChildren();
|
|
333
|
-
children.forEach(child => paragraph.append(child));
|
|
334
|
-
this.replace(paragraph);
|
|
335
|
-
return true;
|
|
336
|
-
}
|
|
337
|
-
setLanguage(language) {
|
|
338
|
-
const writable = this.getWritable();
|
|
339
|
-
writable.__language = language || undefined;
|
|
340
|
-
return writable;
|
|
341
|
-
}
|
|
342
|
-
getLanguage() {
|
|
343
|
-
return this.getLatest().__language;
|
|
344
|
-
}
|
|
345
|
-
setIsSyntaxHighlightSupported(isSupported) {
|
|
346
|
-
const writable = this.getWritable();
|
|
347
|
-
writable.__isSyntaxHighlightSupported = isSupported;
|
|
348
|
-
return writable;
|
|
349
|
-
}
|
|
350
|
-
getIsSyntaxHighlightSupported() {
|
|
351
|
-
return this.getLatest().__isSyntaxHighlightSupported;
|
|
352
|
-
}
|
|
353
|
-
setTheme(theme) {
|
|
354
|
-
const writable = this.getWritable();
|
|
355
|
-
writable.__theme = theme || undefined;
|
|
356
|
-
return writable;
|
|
357
|
-
}
|
|
358
|
-
getTheme() {
|
|
359
|
-
return this.getLatest().__theme;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
function $createCodeNode(language, theme) {
|
|
363
|
-
return lexical.$create(CodeNode).setLanguage(language).setTheme(theme);
|
|
364
|
-
}
|
|
365
|
-
function $isCodeNode(node) {
|
|
366
|
-
return node instanceof CodeNode;
|
|
367
|
-
}
|
|
368
|
-
function $convertPreElement(domNode) {
|
|
369
|
-
const language = domNode.getAttribute(LANGUAGE_DATA_ATTRIBUTE);
|
|
370
|
-
return {
|
|
371
|
-
node: $createCodeNode(language)
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
function $convertDivElement(domNode) {
|
|
375
|
-
// domNode is a <div> since we matched it by nodeName
|
|
376
|
-
const div = domNode;
|
|
377
|
-
const isCode = isCodeElement(div);
|
|
378
|
-
if (!isCode && !isCodeChildElement(div)) {
|
|
379
|
-
return {
|
|
380
|
-
node: null
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
return {
|
|
384
|
-
node: isCode ? $createCodeNode() : null
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
function $convertTableElement() {
|
|
388
|
-
return {
|
|
389
|
-
node: $createCodeNode()
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
function convertCodeNoop() {
|
|
393
|
-
return {
|
|
394
|
-
node: null
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
function isCodeElement(div) {
|
|
398
|
-
return div.style.fontFamily.match('monospace') !== null;
|
|
399
|
-
}
|
|
400
|
-
function isCodeChildElement(node) {
|
|
401
|
-
let parent = node.parentElement;
|
|
402
|
-
while (parent !== null) {
|
|
403
|
-
if (isCodeElement(parent)) {
|
|
404
|
-
return true;
|
|
405
|
-
}
|
|
406
|
-
parent = parent.parentElement;
|
|
407
|
-
}
|
|
408
|
-
return false;
|
|
409
|
-
}
|
|
410
|
-
function isGitHubCodeCell(cell) {
|
|
411
|
-
return cell.classList.contains('js-file-line');
|
|
412
|
-
}
|
|
413
|
-
function isGitHubCodeTable(table) {
|
|
414
|
-
return table.classList.contains('js-file-line-container');
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
/**
|
|
418
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
419
|
-
*
|
|
420
|
-
* This source code is licensed under the MIT license found in the
|
|
421
|
-
* LICENSE file in the root directory of this source tree.
|
|
422
|
-
*
|
|
423
|
-
*/
|
|
424
|
-
|
|
425
|
-
/** @noInheritDoc */
|
|
426
|
-
class CodeHighlightNode extends lexical.TextNode {
|
|
427
|
-
/** @internal */
|
|
428
|
-
|
|
429
|
-
constructor(text = '', highlightType, key) {
|
|
430
|
-
super(text, key);
|
|
431
|
-
this.__highlightType = highlightType;
|
|
432
|
-
}
|
|
433
|
-
static getType() {
|
|
434
|
-
return 'code-highlight';
|
|
435
|
-
}
|
|
436
|
-
static clone(node) {
|
|
437
|
-
return new CodeHighlightNode(node.__text, node.__highlightType || undefined, node.__key);
|
|
438
|
-
}
|
|
439
|
-
getHighlightType() {
|
|
440
|
-
const self = this.getLatest();
|
|
441
|
-
return self.__highlightType;
|
|
442
|
-
}
|
|
443
|
-
setHighlightType(highlightType) {
|
|
444
|
-
const self = this.getWritable();
|
|
445
|
-
self.__highlightType = highlightType || undefined;
|
|
446
|
-
return self;
|
|
447
|
-
}
|
|
448
|
-
canHaveFormat() {
|
|
449
|
-
return false;
|
|
450
|
-
}
|
|
451
|
-
createDOM(config) {
|
|
452
|
-
const element = super.createDOM(config);
|
|
453
|
-
const className = getHighlightThemeClass(config.theme, this.__highlightType);
|
|
454
|
-
LexicalUtils.addClassNamesToElement(element, className);
|
|
455
|
-
return element;
|
|
456
|
-
}
|
|
457
|
-
updateDOM(prevNode, dom, config) {
|
|
458
|
-
const update = super.updateDOM(prevNode, dom, config);
|
|
459
|
-
const prevClassName = getHighlightThemeClass(config.theme, prevNode.__highlightType);
|
|
460
|
-
const nextClassName = getHighlightThemeClass(config.theme, this.__highlightType);
|
|
461
|
-
if (prevClassName !== nextClassName) {
|
|
462
|
-
if (prevClassName) {
|
|
463
|
-
LexicalUtils.removeClassNamesFromElement(dom, prevClassName);
|
|
464
|
-
}
|
|
465
|
-
if (nextClassName) {
|
|
466
|
-
LexicalUtils.addClassNamesToElement(dom, nextClassName);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
return update;
|
|
470
|
-
}
|
|
471
|
-
static importJSON(serializedNode) {
|
|
472
|
-
return $createCodeHighlightNode().updateFromJSON(serializedNode);
|
|
473
|
-
}
|
|
474
|
-
updateFromJSON(serializedNode) {
|
|
475
|
-
return super.updateFromJSON(serializedNode).setHighlightType(serializedNode.highlightType);
|
|
476
|
-
}
|
|
477
|
-
exportJSON() {
|
|
478
|
-
return {
|
|
479
|
-
...super.exportJSON(),
|
|
480
|
-
highlightType: this.getHighlightType()
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
// Prevent formatting (bold, underline, etc)
|
|
485
|
-
setFormat(format) {
|
|
486
|
-
return this;
|
|
487
|
-
}
|
|
488
|
-
isParentRequired() {
|
|
489
|
-
return true;
|
|
490
|
-
}
|
|
491
|
-
createParentElementNode() {
|
|
492
|
-
return $createCodeNode();
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
function getHighlightThemeClass(theme, highlightType) {
|
|
496
|
-
return highlightType && theme && theme.codeHighlight && theme.codeHighlight[highlightType];
|
|
497
|
-
}
|
|
498
|
-
function $createCodeHighlightNode(text = '', highlightType) {
|
|
499
|
-
return lexical.$applyNodeReplacement(new CodeHighlightNode(text, highlightType));
|
|
500
|
-
}
|
|
501
|
-
function $isCodeHighlightNode(node) {
|
|
502
|
-
return node instanceof CodeHighlightNode;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
function $getLastMatchingCodeNode(anchor, direction) {
|
|
506
|
-
let matchingNode = anchor;
|
|
507
|
-
for (let caret = lexical.$getSiblingCaret(anchor, direction); caret && ($isCodeHighlightNode(caret.origin) || lexical.$isTabNode(caret.origin)); caret = LexicalUtils.$getAdjacentCaret(caret)) {
|
|
508
|
-
matchingNode = caret.origin;
|
|
509
|
-
}
|
|
510
|
-
return matchingNode;
|
|
511
|
-
}
|
|
512
|
-
function $getFirstCodeNodeOfLine(anchor) {
|
|
513
|
-
return $getLastMatchingCodeNode(anchor, 'previous');
|
|
514
|
-
}
|
|
515
|
-
function $getLastCodeNodeOfLine(anchor) {
|
|
516
|
-
return $getLastMatchingCodeNode(anchor, 'next');
|
|
517
|
-
}
|
|
518
|
-
function $getStartOfCodeInLine(anchor, offset) {
|
|
519
|
-
let last = null;
|
|
520
|
-
let lastNonBlank = null;
|
|
521
|
-
let node = anchor;
|
|
522
|
-
let nodeOffset = offset;
|
|
523
|
-
let nodeTextContent = anchor.getTextContent();
|
|
524
|
-
// eslint-disable-next-line no-constant-condition
|
|
525
|
-
while (true) {
|
|
526
|
-
if (nodeOffset === 0) {
|
|
527
|
-
node = node.getPreviousSibling();
|
|
528
|
-
if (node === null) {
|
|
529
|
-
break;
|
|
530
|
-
}
|
|
531
|
-
if (!($isCodeHighlightNode(node) || lexical.$isTabNode(node) || lexical.$isLineBreakNode(node))) {
|
|
532
|
-
formatDevErrorMessage(`Expected a valid Code Node: CodeHighlightNode, TabNode, LineBreakNode`);
|
|
533
|
-
}
|
|
534
|
-
if (lexical.$isLineBreakNode(node)) {
|
|
535
|
-
last = {
|
|
536
|
-
node,
|
|
537
|
-
offset: 1
|
|
538
|
-
};
|
|
539
|
-
break;
|
|
540
|
-
}
|
|
541
|
-
nodeOffset = Math.max(0, node.getTextContentSize() - 1);
|
|
542
|
-
nodeTextContent = node.getTextContent();
|
|
543
|
-
} else {
|
|
544
|
-
nodeOffset--;
|
|
545
|
-
}
|
|
546
|
-
const character = nodeTextContent[nodeOffset];
|
|
547
|
-
if ($isCodeHighlightNode(node) && character !== ' ') {
|
|
548
|
-
lastNonBlank = {
|
|
549
|
-
node,
|
|
550
|
-
offset: nodeOffset
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
// lastNonBlank !== null: anchor in the middle of code; move to line beginning
|
|
555
|
-
if (lastNonBlank !== null) {
|
|
556
|
-
return lastNonBlank;
|
|
557
|
-
}
|
|
558
|
-
// Spaces, tabs or nothing ahead of anchor
|
|
559
|
-
let codeCharacterAtAnchorOffset = null;
|
|
560
|
-
if (offset < anchor.getTextContentSize()) {
|
|
561
|
-
if ($isCodeHighlightNode(anchor)) {
|
|
562
|
-
codeCharacterAtAnchorOffset = anchor.getTextContent()[offset];
|
|
563
|
-
}
|
|
564
|
-
} else {
|
|
565
|
-
const nextSibling = anchor.getNextSibling();
|
|
566
|
-
if ($isCodeHighlightNode(nextSibling)) {
|
|
567
|
-
codeCharacterAtAnchorOffset = nextSibling.getTextContent()[0];
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
if (codeCharacterAtAnchorOffset !== null && codeCharacterAtAnchorOffset !== ' ') {
|
|
571
|
-
// Borderline whitespace and code, move to line beginning
|
|
572
|
-
return last;
|
|
573
|
-
} else {
|
|
574
|
-
const nextNonBlank = findNextNonBlankInLine(anchor, offset);
|
|
575
|
-
if (nextNonBlank !== null) {
|
|
576
|
-
return nextNonBlank;
|
|
577
|
-
} else {
|
|
578
|
-
return last;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
function findNextNonBlankInLine(anchor, offset) {
|
|
583
|
-
let node = anchor;
|
|
584
|
-
let nodeOffset = offset;
|
|
585
|
-
let nodeTextContent = anchor.getTextContent();
|
|
586
|
-
let nodeTextContentSize = anchor.getTextContentSize();
|
|
587
|
-
// eslint-disable-next-line no-constant-condition
|
|
588
|
-
while (true) {
|
|
589
|
-
if (!$isCodeHighlightNode(node) || nodeOffset === nodeTextContentSize) {
|
|
590
|
-
node = node.getNextSibling();
|
|
591
|
-
if (node === null || lexical.$isLineBreakNode(node)) {
|
|
592
|
-
return null;
|
|
593
|
-
}
|
|
594
|
-
if ($isCodeHighlightNode(node)) {
|
|
595
|
-
nodeOffset = 0;
|
|
596
|
-
nodeTextContent = node.getTextContent();
|
|
597
|
-
nodeTextContentSize = node.getTextContentSize();
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
if ($isCodeHighlightNode(node)) {
|
|
601
|
-
if (nodeTextContent[nodeOffset] !== ' ') {
|
|
602
|
-
return {
|
|
603
|
-
node,
|
|
604
|
-
offset: nodeOffset
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
nodeOffset++;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
function $getEndOfCodeInLine(anchor) {
|
|
612
|
-
const lastNode = $getLastCodeNodeOfLine(anchor);
|
|
613
|
-
if (!!lexical.$isLineBreakNode(lastNode)) {
|
|
614
|
-
formatDevErrorMessage(`Unexpected lineBreakNode in getEndOfCodeInLine`);
|
|
615
|
-
}
|
|
616
|
-
return lastNode;
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
(function (Prism) {
|
|
620
|
-
|
|
621
|
-
Prism.languages.diff = {
|
|
622
|
-
'coord': [
|
|
623
|
-
// Match all kinds of coord lines (prefixed by "+++", "---" or "***").
|
|
624
|
-
/^(?:\*{3}|-{3}|\+{3}).*$/m,
|
|
625
|
-
// Match "@@ ... @@" coord lines in unified diff.
|
|
626
|
-
/^@@.*@@$/m,
|
|
627
|
-
// Match coord lines in normal diff (starts with a number).
|
|
628
|
-
/^\d.*$/m
|
|
629
|
-
]
|
|
630
|
-
|
|
631
|
-
// deleted, inserted, unchanged, diff
|
|
632
|
-
};
|
|
633
|
-
|
|
634
|
-
/**
|
|
635
|
-
* A map from the name of a block to its line prefix.
|
|
636
|
-
*
|
|
637
|
-
* @type {Object<string, string>}
|
|
638
|
-
*/
|
|
639
|
-
var PREFIXES = {
|
|
640
|
-
'deleted-sign': '-',
|
|
641
|
-
'deleted-arrow': '<',
|
|
642
|
-
'inserted-sign': '+',
|
|
643
|
-
'inserted-arrow': '>',
|
|
644
|
-
'unchanged': ' ',
|
|
645
|
-
'diff': '!',
|
|
646
|
-
};
|
|
647
|
-
|
|
648
|
-
// add a token for each prefix
|
|
649
|
-
Object.keys(PREFIXES).forEach(function (name) {
|
|
650
|
-
var prefix = PREFIXES[name];
|
|
651
|
-
|
|
652
|
-
var alias = [];
|
|
653
|
-
if (!/^\w+$/.test(name)) { // "deleted-sign" -> "deleted"
|
|
654
|
-
alias.push(/\w+/.exec(name)[0]);
|
|
655
|
-
}
|
|
656
|
-
if (name === 'diff') {
|
|
657
|
-
alias.push('bold');
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
Prism.languages.diff[name] = {
|
|
661
|
-
pattern: RegExp('^(?:[' + prefix + '].*(?:\r\n?|\n|(?![\\s\\S])))+', 'm'),
|
|
662
|
-
alias: alias,
|
|
663
|
-
inside: {
|
|
664
|
-
'line': {
|
|
665
|
-
pattern: /(.)(?=[\s\S]).*(?:\r\n?|\n)?/,
|
|
666
|
-
lookbehind: true
|
|
667
|
-
},
|
|
668
|
-
'prefix': {
|
|
669
|
-
pattern: /[\s\S]/,
|
|
670
|
-
alias: /\w+/.exec(name)[0]
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
};
|
|
674
|
-
|
|
675
|
-
});
|
|
676
|
-
|
|
677
|
-
// make prefixes available to Diff plugin
|
|
678
|
-
Object.defineProperty(Prism.languages.diff, 'PREFIXES', {
|
|
679
|
-
value: PREFIXES
|
|
680
|
-
});
|
|
681
|
-
|
|
682
|
-
}(Prism));
|
|
683
|
-
|
|
684
|
-
/**
|
|
685
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
686
|
-
*
|
|
687
|
-
* This source code is licensed under the MIT license found in the
|
|
688
|
-
* LICENSE file in the root directory of this source tree.
|
|
689
|
-
*
|
|
690
|
-
*/
|
|
691
|
-
|
|
692
|
-
const Prism$1 = globalThis.Prism || window.Prism;
|
|
693
|
-
const CODE_LANGUAGE_FRIENDLY_NAME_MAP = {
|
|
694
|
-
c: 'C',
|
|
695
|
-
clike: 'C-like',
|
|
696
|
-
cpp: 'C++',
|
|
697
|
-
css: 'CSS',
|
|
698
|
-
html: 'HTML',
|
|
699
|
-
java: 'Java',
|
|
700
|
-
js: 'JavaScript',
|
|
701
|
-
markdown: 'Markdown',
|
|
702
|
-
objc: 'Objective-C',
|
|
703
|
-
plain: 'Plain Text',
|
|
704
|
-
powershell: 'PowerShell',
|
|
705
|
-
py: 'Python',
|
|
706
|
-
rust: 'Rust',
|
|
707
|
-
sql: 'SQL',
|
|
708
|
-
swift: 'Swift',
|
|
709
|
-
typescript: 'TypeScript',
|
|
710
|
-
xml: 'XML'
|
|
711
|
-
};
|
|
712
|
-
const CODE_LANGUAGE_MAP = {
|
|
713
|
-
cpp: 'cpp',
|
|
714
|
-
java: 'java',
|
|
715
|
-
javascript: 'js',
|
|
716
|
-
md: 'markdown',
|
|
717
|
-
plaintext: 'plain',
|
|
718
|
-
python: 'py',
|
|
719
|
-
text: 'plain',
|
|
720
|
-
ts: 'typescript'
|
|
721
|
-
};
|
|
722
|
-
function normalizeCodeLang(lang) {
|
|
723
|
-
return CODE_LANGUAGE_MAP[lang] || lang;
|
|
724
|
-
}
|
|
725
|
-
function getLanguageFriendlyName(lang) {
|
|
726
|
-
const _lang = normalizeCodeLang(lang);
|
|
727
|
-
return CODE_LANGUAGE_FRIENDLY_NAME_MAP[_lang] || _lang;
|
|
728
|
-
}
|
|
729
|
-
const getCodeLanguages = () => Object.keys(Prism$1.languages).filter(
|
|
730
|
-
// Prism has several language helpers mixed into languages object
|
|
731
|
-
// so filtering them out here to get langs list
|
|
732
|
-
language => typeof Prism$1.languages[language] !== 'function').sort();
|
|
733
|
-
function getCodeLanguageOptions() {
|
|
734
|
-
const options = [];
|
|
735
|
-
for (const [lang, friendlyName] of Object.entries(CODE_LANGUAGE_FRIENDLY_NAME_MAP)) {
|
|
736
|
-
options.push([lang, friendlyName]);
|
|
737
|
-
}
|
|
738
|
-
return options;
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
// Prism has no theme support
|
|
742
|
-
function getCodeThemeOptions() {
|
|
743
|
-
const options = [];
|
|
744
|
-
return options;
|
|
745
|
-
}
|
|
746
|
-
function getDiffedLanguage(language) {
|
|
747
|
-
const DIFF_LANGUAGE_REGEX = /^diff-([\w-]+)/i;
|
|
748
|
-
const diffLanguageMatch = DIFF_LANGUAGE_REGEX.exec(language);
|
|
749
|
-
return diffLanguageMatch ? diffLanguageMatch[1] : null;
|
|
750
|
-
}
|
|
751
|
-
function isCodeLanguageLoaded(language) {
|
|
752
|
-
const diffedLanguage = getDiffedLanguage(language);
|
|
753
|
-
const langId = diffedLanguage ? diffedLanguage : language;
|
|
754
|
-
try {
|
|
755
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
756
|
-
return langId ? Prism$1.languages.hasOwnProperty(langId) : false;
|
|
757
|
-
} catch (_unused) {
|
|
758
|
-
return false;
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
async function loadCodeLanguage(language, editor, codeNodeKey) {
|
|
762
|
-
// NOT IMPLEMENTED
|
|
763
|
-
}
|
|
764
|
-
function getTextContent(token) {
|
|
765
|
-
if (typeof token === 'string') {
|
|
766
|
-
return token;
|
|
767
|
-
} else if (Array.isArray(token)) {
|
|
768
|
-
return token.map(getTextContent).join('');
|
|
769
|
-
} else {
|
|
770
|
-
return getTextContent(token.content);
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
// The following code is extracted/adapted from prismjs v2
|
|
775
|
-
// It will probably be possible to use it directly from prism v2
|
|
776
|
-
// in the future when prismjs v2 is published and Lexical upgrades
|
|
777
|
-
// the prismsjs dependency
|
|
778
|
-
function tokenizeDiffHighlight(tokens, language) {
|
|
779
|
-
const diffLanguage = language;
|
|
780
|
-
const diffGrammar = Prism$1.languages[diffLanguage];
|
|
781
|
-
const env = {
|
|
782
|
-
tokens
|
|
783
|
-
};
|
|
784
|
-
const PREFIXES = Prism$1.languages.diff.PREFIXES;
|
|
785
|
-
for (const token of env.tokens) {
|
|
786
|
-
if (typeof token === 'string' || !(token.type in PREFIXES) || !Array.isArray(token.content)) {
|
|
787
|
-
continue;
|
|
788
|
-
}
|
|
789
|
-
const type = token.type;
|
|
790
|
-
let insertedPrefixes = 0;
|
|
791
|
-
const getPrefixToken = () => {
|
|
792
|
-
insertedPrefixes++;
|
|
793
|
-
return new Prism$1.Token('prefix', PREFIXES[type], type.replace(/^(\w+).*/, '$1'));
|
|
794
|
-
};
|
|
795
|
-
const withoutPrefixes = token.content.filter(t => typeof t === 'string' || t.type !== 'prefix');
|
|
796
|
-
const prefixCount = token.content.length - withoutPrefixes.length;
|
|
797
|
-
const diffTokens = Prism$1.tokenize(getTextContent(withoutPrefixes), diffGrammar);
|
|
798
|
-
|
|
799
|
-
// re-insert prefixes
|
|
800
|
-
// always add a prefix at the start
|
|
801
|
-
diffTokens.unshift(getPrefixToken());
|
|
802
|
-
const LINE_BREAK = /\r\n|\n/g;
|
|
803
|
-
const insertAfterLineBreakString = text => {
|
|
804
|
-
const result = [];
|
|
805
|
-
LINE_BREAK.lastIndex = 0;
|
|
806
|
-
let last = 0;
|
|
807
|
-
let m;
|
|
808
|
-
while (insertedPrefixes < prefixCount && (m = LINE_BREAK.exec(text))) {
|
|
809
|
-
const end = m.index + m[0].length;
|
|
810
|
-
result.push(text.slice(last, end));
|
|
811
|
-
last = end;
|
|
812
|
-
result.push(getPrefixToken());
|
|
813
|
-
}
|
|
814
|
-
if (result.length === 0) {
|
|
815
|
-
return undefined;
|
|
816
|
-
}
|
|
817
|
-
if (last < text.length) {
|
|
818
|
-
result.push(text.slice(last));
|
|
819
|
-
}
|
|
820
|
-
return result;
|
|
821
|
-
};
|
|
822
|
-
const insertAfterLineBreak = toks => {
|
|
823
|
-
for (let i = 0; i < toks.length && insertedPrefixes < prefixCount; i++) {
|
|
824
|
-
const tok = toks[i];
|
|
825
|
-
if (typeof tok === 'string') {
|
|
826
|
-
const inserted = insertAfterLineBreakString(tok);
|
|
827
|
-
if (inserted) {
|
|
828
|
-
toks.splice(i, 1, ...inserted);
|
|
829
|
-
i += inserted.length - 1;
|
|
830
|
-
}
|
|
831
|
-
} else if (typeof tok.content === 'string') {
|
|
832
|
-
const inserted = insertAfterLineBreakString(tok.content);
|
|
833
|
-
if (inserted) {
|
|
834
|
-
tok.content = inserted;
|
|
835
|
-
}
|
|
836
|
-
} else if (Array.isArray(tok.content)) {
|
|
837
|
-
insertAfterLineBreak(tok.content);
|
|
838
|
-
} else {
|
|
839
|
-
insertAfterLineBreak([tok.content]);
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
};
|
|
843
|
-
insertAfterLineBreak(diffTokens);
|
|
844
|
-
if (insertedPrefixes < prefixCount) {
|
|
845
|
-
// we are missing the last prefix
|
|
846
|
-
diffTokens.push(getPrefixToken());
|
|
847
|
-
}
|
|
848
|
-
token.content = diffTokens;
|
|
849
|
-
}
|
|
850
|
-
return env.tokens;
|
|
851
|
-
}
|
|
852
|
-
function $getHighlightNodes(codeNode, language) {
|
|
853
|
-
const DIFF_LANGUAGE_REGEX = /^diff-([\w-]+)/i;
|
|
854
|
-
const diffLanguageMatch = DIFF_LANGUAGE_REGEX.exec(language);
|
|
855
|
-
const code = codeNode.getTextContent();
|
|
856
|
-
let tokens = Prism$1.tokenize(code, Prism$1.languages[diffLanguageMatch ? 'diff' : language]);
|
|
857
|
-
if (diffLanguageMatch) {
|
|
858
|
-
tokens = tokenizeDiffHighlight(tokens, diffLanguageMatch[1]);
|
|
859
|
-
}
|
|
860
|
-
return $mapTokensToLexicalStructure(tokens);
|
|
861
|
-
}
|
|
862
|
-
function $mapTokensToLexicalStructure(tokens, type) {
|
|
863
|
-
const nodes = [];
|
|
864
|
-
for (const token of tokens) {
|
|
865
|
-
if (typeof token === 'string') {
|
|
866
|
-
const partials = token.split(/(\n|\t)/);
|
|
867
|
-
const partialsLength = partials.length;
|
|
868
|
-
for (let i = 0; i < partialsLength; i++) {
|
|
869
|
-
const part = partials[i];
|
|
870
|
-
if (part === '\n' || part === '\r\n') {
|
|
871
|
-
nodes.push(lexical.$createLineBreakNode());
|
|
872
|
-
} else if (part === '\t') {
|
|
873
|
-
nodes.push(lexical.$createTabNode());
|
|
874
|
-
} else if (part.length > 0) {
|
|
875
|
-
nodes.push($createCodeHighlightNode(part, type));
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
} else {
|
|
879
|
-
const {
|
|
880
|
-
content,
|
|
881
|
-
alias
|
|
882
|
-
} = token;
|
|
883
|
-
if (typeof content === 'string') {
|
|
884
|
-
nodes.push(...$mapTokensToLexicalStructure([content], token.type === 'prefix' && typeof alias === 'string' ? alias : token.type));
|
|
885
|
-
} else if (Array.isArray(content)) {
|
|
886
|
-
nodes.push(...$mapTokensToLexicalStructure(content, token.type === 'unchanged' ? undefined : token.type));
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
return nodes;
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
const PrismTokenizer = {
|
|
894
|
-
$tokenize(codeNode, language) {
|
|
895
|
-
return $getHighlightNodes(codeNode, language || this.defaultLanguage);
|
|
896
|
-
},
|
|
897
|
-
defaultLanguage: DEFAULT_CODE_LANGUAGE,
|
|
898
|
-
tokenize(code, language) {
|
|
899
|
-
return Prism$1.tokenize(code, Prism$1.languages[language || ''] || Prism$1.languages[this.defaultLanguage]);
|
|
900
|
-
}
|
|
901
|
-
};
|
|
902
|
-
function $textNodeTransform(node, editor, tokenizer) {
|
|
903
|
-
// Since CodeNode has flat children structure we only need to check
|
|
904
|
-
// if node's parent is a code node and run highlighting if so
|
|
905
|
-
const parentNode = node.getParent();
|
|
906
|
-
if ($isCodeNode(parentNode)) {
|
|
907
|
-
codeNodeTransform(parentNode, editor, tokenizer);
|
|
908
|
-
} else if ($isCodeHighlightNode(node)) {
|
|
909
|
-
// When code block converted into paragraph or other element
|
|
910
|
-
// code highlight nodes converted back to normal text
|
|
911
|
-
node.replace(lexical.$createTextNode(node.__text));
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
function updateCodeGutter(node, editor) {
|
|
915
|
-
const codeElement = editor.getElementByKey(node.getKey());
|
|
916
|
-
if (codeElement === null) {
|
|
917
|
-
return;
|
|
918
|
-
}
|
|
919
|
-
const children = node.getChildren();
|
|
920
|
-
const childrenLength = children.length;
|
|
921
|
-
// @ts-ignore: internal field
|
|
922
|
-
if (childrenLength === codeElement.__cachedChildrenLength) {
|
|
923
|
-
// Avoid updating the attribute if the children length hasn't changed.
|
|
924
|
-
return;
|
|
925
|
-
}
|
|
926
|
-
// @ts-ignore:: internal field
|
|
927
|
-
codeElement.__cachedChildrenLength = childrenLength;
|
|
928
|
-
let gutter = '1';
|
|
929
|
-
let count = 1;
|
|
930
|
-
for (let i = 0; i < childrenLength; i++) {
|
|
931
|
-
if (lexical.$isLineBreakNode(children[i])) {
|
|
932
|
-
gutter += '\n' + ++count;
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
codeElement.setAttribute('data-gutter', gutter);
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
// Using `skipTransforms` to prevent extra transforms since reformatting the code
|
|
939
|
-
// will not affect code block content itself.
|
|
940
|
-
//
|
|
941
|
-
// Using extra cache (`nodesCurrentlyHighlighting`) since both CodeNode and CodeHighlightNode
|
|
942
|
-
// transforms might be called at the same time (e.g. new CodeHighlight node inserted) and
|
|
943
|
-
// in both cases we'll rerun whole reformatting over CodeNode, which is redundant.
|
|
944
|
-
// Especially when pasting code into CodeBlock.
|
|
945
|
-
|
|
946
|
-
const nodesCurrentlyHighlighting = new Set();
|
|
947
|
-
function codeNodeTransform(node, editor, tokenizer) {
|
|
948
|
-
const nodeKey = node.getKey();
|
|
949
|
-
|
|
950
|
-
// When new code block inserted it might not have language selected
|
|
951
|
-
if (node.getLanguage() === undefined) {
|
|
952
|
-
node.setLanguage(tokenizer.defaultLanguage);
|
|
953
|
-
}
|
|
954
|
-
const language = node.getLanguage() || tokenizer.defaultLanguage;
|
|
955
|
-
if (isCodeLanguageLoaded(language)) {
|
|
956
|
-
if (!node.getIsSyntaxHighlightSupported()) {
|
|
957
|
-
node.setIsSyntaxHighlightSupported(true);
|
|
958
|
-
}
|
|
959
|
-
} else {
|
|
960
|
-
if (node.getIsSyntaxHighlightSupported()) {
|
|
961
|
-
node.setIsSyntaxHighlightSupported(false);
|
|
962
|
-
}
|
|
963
|
-
loadCodeLanguage();
|
|
964
|
-
return;
|
|
965
|
-
}
|
|
966
|
-
if (nodesCurrentlyHighlighting.has(nodeKey)) {
|
|
967
|
-
return;
|
|
968
|
-
}
|
|
969
|
-
nodesCurrentlyHighlighting.add(nodeKey);
|
|
970
|
-
|
|
971
|
-
// Using nested update call to pass `skipTransforms` since we don't want
|
|
972
|
-
// each individual CodeHighlightNode to be transformed again as it's already
|
|
973
|
-
// in its final state
|
|
974
|
-
editor.update(() => {
|
|
975
|
-
$updateAndRetainSelection(nodeKey, () => {
|
|
976
|
-
const currentNode = lexical.$getNodeByKey(nodeKey);
|
|
977
|
-
if (!$isCodeNode(currentNode) || !currentNode.isAttached()) {
|
|
978
|
-
return false;
|
|
979
|
-
}
|
|
980
|
-
//const DIFF_LANGUAGE_REGEX = /^diff-([\w-]+)/i;
|
|
981
|
-
const currentLanguage = currentNode.getLanguage() || tokenizer.defaultLanguage;
|
|
982
|
-
//const diffLanguageMatch = DIFF_LANGUAGE_REGEX.exec(currentLanguage);
|
|
983
|
-
|
|
984
|
-
const highlightNodes = tokenizer.$tokenize(currentNode, currentLanguage);
|
|
985
|
-
const diffRange = getDiffRange(currentNode.getChildren(), highlightNodes);
|
|
986
|
-
const {
|
|
987
|
-
from,
|
|
988
|
-
to,
|
|
989
|
-
nodesForReplacement
|
|
990
|
-
} = diffRange;
|
|
991
|
-
if (from !== to || nodesForReplacement.length) {
|
|
992
|
-
node.splice(from, to - from, nodesForReplacement);
|
|
993
|
-
return true;
|
|
994
|
-
}
|
|
995
|
-
return false;
|
|
996
|
-
});
|
|
997
|
-
}, {
|
|
998
|
-
onUpdate: () => {
|
|
999
|
-
nodesCurrentlyHighlighting.delete(nodeKey);
|
|
1000
|
-
},
|
|
1001
|
-
skipTransforms: true
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
// Wrapping update function into selection retainer, that tries to keep cursor at the same
|
|
1006
|
-
// position as before.
|
|
1007
|
-
function $updateAndRetainSelection(nodeKey, updateFn) {
|
|
1008
|
-
const node = lexical.$getNodeByKey(nodeKey);
|
|
1009
|
-
if (!$isCodeNode(node) || !node.isAttached()) {
|
|
1010
|
-
return;
|
|
1011
|
-
}
|
|
1012
|
-
const selection = lexical.$getSelection();
|
|
1013
|
-
// If it's not range selection (or null selection) there's no need to change it,
|
|
1014
|
-
// but we can still run highlighting logic
|
|
1015
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
1016
|
-
updateFn();
|
|
1017
|
-
return;
|
|
1018
|
-
}
|
|
1019
|
-
const anchor = selection.anchor;
|
|
1020
|
-
const anchorOffset = anchor.offset;
|
|
1021
|
-
const isNewLineAnchor = anchor.type === 'element' && lexical.$isLineBreakNode(node.getChildAtIndex(anchor.offset - 1));
|
|
1022
|
-
let textOffset = 0;
|
|
1023
|
-
|
|
1024
|
-
// Calculating previous text offset (all text node prior to anchor + anchor own text offset)
|
|
1025
|
-
if (!isNewLineAnchor) {
|
|
1026
|
-
const anchorNode = anchor.getNode();
|
|
1027
|
-
textOffset = anchorOffset + anchorNode.getPreviousSiblings().reduce((offset, _node) => {
|
|
1028
|
-
return offset + _node.getTextContentSize();
|
|
1029
|
-
}, 0);
|
|
1030
|
-
}
|
|
1031
|
-
const hasChanges = updateFn();
|
|
1032
|
-
if (!hasChanges) {
|
|
1033
|
-
return;
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
// Non-text anchors only happen for line breaks, otherwise
|
|
1037
|
-
// selection will be within text node (code highlight node)
|
|
1038
|
-
if (isNewLineAnchor) {
|
|
1039
|
-
anchor.getNode().select(anchorOffset, anchorOffset);
|
|
1040
|
-
return;
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
// If it was non-element anchor then we walk through child nodes
|
|
1044
|
-
// and looking for a position of original text offset
|
|
1045
|
-
node.getChildren().some(_node => {
|
|
1046
|
-
const isText = lexical.$isTextNode(_node);
|
|
1047
|
-
if (isText || lexical.$isLineBreakNode(_node)) {
|
|
1048
|
-
const textContentSize = _node.getTextContentSize();
|
|
1049
|
-
if (isText && textContentSize >= textOffset) {
|
|
1050
|
-
_node.select(textOffset, textOffset);
|
|
1051
|
-
return true;
|
|
1052
|
-
}
|
|
1053
|
-
textOffset -= textContentSize;
|
|
1054
|
-
}
|
|
1055
|
-
return false;
|
|
1056
|
-
});
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
// Finds minimal diff range between two nodes lists. It returns from/to range boundaries of prevNodes
|
|
1060
|
-
// that needs to be replaced with `nodes` (subset of nextNodes) to make prevNodes equal to nextNodes.
|
|
1061
|
-
function getDiffRange(prevNodes, nextNodes) {
|
|
1062
|
-
let leadingMatch = 0;
|
|
1063
|
-
while (leadingMatch < prevNodes.length) {
|
|
1064
|
-
if (!isEqual(prevNodes[leadingMatch], nextNodes[leadingMatch])) {
|
|
1065
|
-
break;
|
|
1066
|
-
}
|
|
1067
|
-
leadingMatch++;
|
|
1068
|
-
}
|
|
1069
|
-
const prevNodesLength = prevNodes.length;
|
|
1070
|
-
const nextNodesLength = nextNodes.length;
|
|
1071
|
-
const maxTrailingMatch = Math.min(prevNodesLength, nextNodesLength) - leadingMatch;
|
|
1072
|
-
let trailingMatch = 0;
|
|
1073
|
-
while (trailingMatch < maxTrailingMatch) {
|
|
1074
|
-
trailingMatch++;
|
|
1075
|
-
if (!isEqual(prevNodes[prevNodesLength - trailingMatch], nextNodes[nextNodesLength - trailingMatch])) {
|
|
1076
|
-
trailingMatch--;
|
|
1077
|
-
break;
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
const from = leadingMatch;
|
|
1081
|
-
const to = prevNodesLength - trailingMatch;
|
|
1082
|
-
const nodesForReplacement = nextNodes.slice(leadingMatch, nextNodesLength - trailingMatch);
|
|
1083
|
-
return {
|
|
1084
|
-
from,
|
|
1085
|
-
nodesForReplacement,
|
|
1086
|
-
to
|
|
1087
|
-
};
|
|
1088
|
-
}
|
|
1089
|
-
function isEqual(nodeA, nodeB) {
|
|
1090
|
-
// Only checking for code highlight nodes, tabs and linebreaks. If it's regular text node
|
|
1091
|
-
// returning false so that it's transformed into code highlight node
|
|
1092
|
-
return $isCodeHighlightNode(nodeA) && $isCodeHighlightNode(nodeB) && nodeA.__text === nodeB.__text && nodeA.__highlightType === nodeB.__highlightType || lexical.$isTabNode(nodeA) && lexical.$isTabNode(nodeB) || lexical.$isLineBreakNode(nodeA) && lexical.$isLineBreakNode(nodeB);
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
/**
|
|
1096
|
-
* Returns a boolean.
|
|
1097
|
-
* Check that the selection span is within a single CodeNode.
|
|
1098
|
-
* This is used to guard against executing handlers that can only be
|
|
1099
|
-
* applied in a single CodeNode context
|
|
1100
|
-
*/
|
|
1101
|
-
function $isSelectionInCode(selection) {
|
|
1102
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
1103
|
-
return false;
|
|
1104
|
-
}
|
|
1105
|
-
const anchorNode = selection.anchor.getNode();
|
|
1106
|
-
const maybeAnchorCodeNode = $isCodeNode(anchorNode) ? anchorNode : anchorNode.getParent();
|
|
1107
|
-
const focusNode = selection.focus.getNode();
|
|
1108
|
-
const maybeFocusCodeNode = $isCodeNode(focusNode) ? focusNode : focusNode.getParent();
|
|
1109
|
-
return $isCodeNode(maybeAnchorCodeNode) && maybeAnchorCodeNode.is(maybeFocusCodeNode);
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
/**
|
|
1113
|
-
* Returns an Array of code lines
|
|
1114
|
-
* Take the sequence of LineBreakNode | TabNode | CodeHighlightNode forming
|
|
1115
|
-
* the selection and split it by LineBreakNode.
|
|
1116
|
-
* If the selection ends at the start of the last line, it is considered empty.
|
|
1117
|
-
* Empty lines are discarded.
|
|
1118
|
-
*/
|
|
1119
|
-
function $getCodeLines(selection) {
|
|
1120
|
-
const nodes = selection.getNodes();
|
|
1121
|
-
const lines = [];
|
|
1122
|
-
if (nodes.length === 1 && $isCodeNode(nodes[0])) {
|
|
1123
|
-
return lines;
|
|
1124
|
-
}
|
|
1125
|
-
let lastLine = [];
|
|
1126
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
1127
|
-
const node = nodes[i];
|
|
1128
|
-
if (!($isCodeHighlightNode(node) || lexical.$isTabNode(node) || lexical.$isLineBreakNode(node))) {
|
|
1129
|
-
formatDevErrorMessage(`Expected selection to be inside CodeBlock and consisting of CodeHighlightNode, TabNode and LineBreakNode`);
|
|
1130
|
-
}
|
|
1131
|
-
if (lexical.$isLineBreakNode(node)) {
|
|
1132
|
-
if (lastLine.length > 0) {
|
|
1133
|
-
lines.push(lastLine);
|
|
1134
|
-
lastLine = [];
|
|
1135
|
-
}
|
|
1136
|
-
} else {
|
|
1137
|
-
lastLine.push(node);
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
if (lastLine.length > 0) {
|
|
1141
|
-
const selectionEnd = selection.isBackward() ? selection.anchor : selection.focus;
|
|
1142
|
-
|
|
1143
|
-
// Discard the last line if the selection ends exactly at the
|
|
1144
|
-
// start of the line (no real selection)
|
|
1145
|
-
const lastPoint = lexical.$createPoint(lastLine[0].getKey(), 0, 'text');
|
|
1146
|
-
if (!selectionEnd.is(lastPoint)) {
|
|
1147
|
-
lines.push(lastLine);
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
return lines;
|
|
1151
|
-
}
|
|
1152
|
-
function $handleTab(shiftKey) {
|
|
1153
|
-
const selection = lexical.$getSelection();
|
|
1154
|
-
if (!lexical.$isRangeSelection(selection) || !$isSelectionInCode(selection)) {
|
|
1155
|
-
return null;
|
|
1156
|
-
}
|
|
1157
|
-
const indentOrOutdent = !shiftKey ? lexical.INDENT_CONTENT_COMMAND : lexical.OUTDENT_CONTENT_COMMAND;
|
|
1158
|
-
const tabOrOutdent = !shiftKey ? lexical.INSERT_TAB_COMMAND : lexical.OUTDENT_CONTENT_COMMAND;
|
|
1159
|
-
const anchor = selection.anchor;
|
|
1160
|
-
const focus = selection.focus;
|
|
1161
|
-
|
|
1162
|
-
// 1. early decision when there is no real selection
|
|
1163
|
-
if (anchor.is(focus)) {
|
|
1164
|
-
return tabOrOutdent;
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
// 2. If only empty lines or multiple non-empty lines are selected: indent/outdent
|
|
1168
|
-
const codeLines = $getCodeLines(selection);
|
|
1169
|
-
if (codeLines.length !== 1) {
|
|
1170
|
-
return indentOrOutdent;
|
|
1171
|
-
}
|
|
1172
|
-
const codeLine = codeLines[0];
|
|
1173
|
-
const codeLineLength = codeLine.length;
|
|
1174
|
-
if (!(codeLineLength !== 0)) {
|
|
1175
|
-
formatDevErrorMessage(`$getCodeLines only extracts non-empty lines`);
|
|
1176
|
-
} // Take into account the direction of the selection
|
|
1177
|
-
let selectionFirst;
|
|
1178
|
-
let selectionLast;
|
|
1179
|
-
if (selection.isBackward()) {
|
|
1180
|
-
selectionFirst = focus;
|
|
1181
|
-
selectionLast = anchor;
|
|
1182
|
-
} else {
|
|
1183
|
-
selectionFirst = anchor;
|
|
1184
|
-
selectionLast = focus;
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
// find boundary elements of the line
|
|
1188
|
-
// since codeLine only contains TabNode | CodeHighlightNode
|
|
1189
|
-
// the result of these functions should is of Type TabNode | CodeHighlightNode
|
|
1190
|
-
const firstOfLine = $getFirstCodeNodeOfLine(codeLine[0]);
|
|
1191
|
-
const lastOfLine = $getLastCodeNodeOfLine(codeLine[0]);
|
|
1192
|
-
const anchorOfLine = lexical.$createPoint(firstOfLine.getKey(), 0, 'text');
|
|
1193
|
-
const focusOfLine = lexical.$createPoint(lastOfLine.getKey(), lastOfLine.getTextContentSize(), 'text');
|
|
1194
|
-
|
|
1195
|
-
// 3. multiline because selection started strictly before the line
|
|
1196
|
-
if (selectionFirst.isBefore(anchorOfLine)) {
|
|
1197
|
-
return indentOrOutdent;
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
// 4. multiline because the selection stops strictly after the line
|
|
1201
|
-
if (focusOfLine.isBefore(selectionLast)) {
|
|
1202
|
-
return indentOrOutdent;
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
// The selection if within the line.
|
|
1206
|
-
// 4. If it does not touch both borders, it needs a tab
|
|
1207
|
-
if (anchorOfLine.isBefore(selectionFirst) || selectionLast.isBefore(focusOfLine)) {
|
|
1208
|
-
return tabOrOutdent;
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
|
-
// 5. Selection is matching a full line on non-empty code
|
|
1212
|
-
return indentOrOutdent;
|
|
1213
|
-
}
|
|
1214
|
-
function $handleMultilineIndent(type) {
|
|
1215
|
-
const selection = lexical.$getSelection();
|
|
1216
|
-
if (!lexical.$isRangeSelection(selection) || !$isSelectionInCode(selection)) {
|
|
1217
|
-
return false;
|
|
1218
|
-
}
|
|
1219
|
-
const codeLines = $getCodeLines(selection);
|
|
1220
|
-
const codeLinesLength = codeLines.length;
|
|
1221
|
-
|
|
1222
|
-
// Special Indent case
|
|
1223
|
-
// Selection is collapsed at the beginning of a line
|
|
1224
|
-
if (codeLinesLength === 0 && selection.isCollapsed()) {
|
|
1225
|
-
if (type === lexical.INDENT_CONTENT_COMMAND) {
|
|
1226
|
-
selection.insertNodes([lexical.$createTabNode()]);
|
|
1227
|
-
}
|
|
1228
|
-
return true;
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
// Special Indent case
|
|
1232
|
-
// Selection is matching only one LineBreak
|
|
1233
|
-
if (codeLinesLength === 0 && type === lexical.INDENT_CONTENT_COMMAND && selection.getTextContent() === '\n') {
|
|
1234
|
-
const tabNode = lexical.$createTabNode();
|
|
1235
|
-
const lineBreakNode = lexical.$createLineBreakNode();
|
|
1236
|
-
const direction = selection.isBackward() ? 'previous' : 'next';
|
|
1237
|
-
selection.insertNodes([tabNode, lineBreakNode]);
|
|
1238
|
-
lexical.$setSelectionFromCaretRange(lexical.$getCaretRangeInDirection(lexical.$getCaretRange(lexical.$getTextPointCaret(tabNode, 'next', 0), lexical.$normalizeCaret(lexical.$getSiblingCaret(lineBreakNode, 'next'))), direction));
|
|
1239
|
-
return true;
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
// Indent Non Empty Lines
|
|
1243
|
-
for (let i = 0; i < codeLinesLength; i++) {
|
|
1244
|
-
const line = codeLines[i];
|
|
1245
|
-
// a line here is never empty
|
|
1246
|
-
if (line.length > 0) {
|
|
1247
|
-
let firstOfLine = line[0];
|
|
1248
|
-
|
|
1249
|
-
// make sure to consider the first node on the first line
|
|
1250
|
-
// because the line might not be fully selected
|
|
1251
|
-
if (i === 0) {
|
|
1252
|
-
firstOfLine = $getFirstCodeNodeOfLine(firstOfLine);
|
|
1253
|
-
}
|
|
1254
|
-
if (type === lexical.INDENT_CONTENT_COMMAND) {
|
|
1255
|
-
const tabNode = lexical.$createTabNode();
|
|
1256
|
-
firstOfLine.insertBefore(tabNode);
|
|
1257
|
-
// First real code line may need selection adjustment
|
|
1258
|
-
// when firstOfLine is at the selection boundary
|
|
1259
|
-
if (i === 0) {
|
|
1260
|
-
const anchorKey = selection.isBackward() ? 'focus' : 'anchor';
|
|
1261
|
-
const anchorLine = lexical.$createPoint(firstOfLine.getKey(), 0, 'text');
|
|
1262
|
-
if (selection[anchorKey].is(anchorLine)) {
|
|
1263
|
-
selection[anchorKey].set(tabNode.getKey(), 0, 'text');
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
} else if (lexical.$isTabNode(firstOfLine)) {
|
|
1267
|
-
firstOfLine.remove();
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
return true;
|
|
1272
|
-
}
|
|
1273
|
-
function $handleShiftLines(type, event) {
|
|
1274
|
-
// We only care about the alt+arrow keys
|
|
1275
|
-
const selection = lexical.$getSelection();
|
|
1276
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
1277
|
-
return false;
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
// I'm not quite sure why, but it seems like calling anchor.getNode() collapses the selection here
|
|
1281
|
-
// So first, get the anchor and the focus, then get their nodes
|
|
1282
|
-
const {
|
|
1283
|
-
anchor,
|
|
1284
|
-
focus
|
|
1285
|
-
} = selection;
|
|
1286
|
-
const anchorOffset = anchor.offset;
|
|
1287
|
-
const focusOffset = focus.offset;
|
|
1288
|
-
const anchorNode = anchor.getNode();
|
|
1289
|
-
const focusNode = focus.getNode();
|
|
1290
|
-
const arrowIsUp = type === lexical.KEY_ARROW_UP_COMMAND;
|
|
1291
|
-
|
|
1292
|
-
// Ensure the selection is within the codeblock
|
|
1293
|
-
if (!$isSelectionInCode(selection) || !($isCodeHighlightNode(anchorNode) || lexical.$isTabNode(anchorNode)) || !($isCodeHighlightNode(focusNode) || lexical.$isTabNode(focusNode))) {
|
|
1294
|
-
return false;
|
|
1295
|
-
}
|
|
1296
|
-
if (!event.altKey) {
|
|
1297
|
-
// Handle moving selection out of the code block, given there are no
|
|
1298
|
-
// siblings that can natively take the selection.
|
|
1299
|
-
if (selection.isCollapsed()) {
|
|
1300
|
-
const codeNode = anchorNode.getParentOrThrow();
|
|
1301
|
-
if (arrowIsUp && anchorOffset === 0 && anchorNode.getPreviousSibling() === null) {
|
|
1302
|
-
const codeNodeSibling = codeNode.getPreviousSibling();
|
|
1303
|
-
if (codeNodeSibling === null) {
|
|
1304
|
-
codeNode.selectPrevious();
|
|
1305
|
-
event.preventDefault();
|
|
1306
|
-
return true;
|
|
1307
|
-
}
|
|
1308
|
-
} else if (!arrowIsUp && anchorOffset === anchorNode.getTextContentSize() && anchorNode.getNextSibling() === null) {
|
|
1309
|
-
const codeNodeSibling = codeNode.getNextSibling();
|
|
1310
|
-
if (codeNodeSibling === null) {
|
|
1311
|
-
codeNode.selectNext();
|
|
1312
|
-
event.preventDefault();
|
|
1313
|
-
return true;
|
|
1314
|
-
}
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
return false;
|
|
1318
|
-
}
|
|
1319
|
-
let start;
|
|
1320
|
-
let end;
|
|
1321
|
-
if (anchorNode.isBefore(focusNode)) {
|
|
1322
|
-
start = $getFirstCodeNodeOfLine(anchorNode);
|
|
1323
|
-
end = $getLastCodeNodeOfLine(focusNode);
|
|
1324
|
-
} else {
|
|
1325
|
-
start = $getFirstCodeNodeOfLine(focusNode);
|
|
1326
|
-
end = $getLastCodeNodeOfLine(anchorNode);
|
|
1327
|
-
}
|
|
1328
|
-
if (start == null || end == null) {
|
|
1329
|
-
return false;
|
|
1330
|
-
}
|
|
1331
|
-
const range = start.getNodesBetween(end);
|
|
1332
|
-
for (let i = 0; i < range.length; i++) {
|
|
1333
|
-
const node = range[i];
|
|
1334
|
-
if (!$isCodeHighlightNode(node) && !lexical.$isTabNode(node) && !lexical.$isLineBreakNode(node)) {
|
|
1335
|
-
return false;
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
// After this point, we know the selection is within the codeblock. We may not be able to
|
|
1340
|
-
// actually move the lines around, but we want to return true either way to prevent
|
|
1341
|
-
// the event's default behavior
|
|
1342
|
-
event.preventDefault();
|
|
1343
|
-
event.stopPropagation(); // required to stop cursor movement under Firefox
|
|
1344
|
-
|
|
1345
|
-
const linebreak = arrowIsUp ? start.getPreviousSibling() : end.getNextSibling();
|
|
1346
|
-
if (!lexical.$isLineBreakNode(linebreak)) {
|
|
1347
|
-
return true;
|
|
1348
|
-
}
|
|
1349
|
-
const sibling = arrowIsUp ? linebreak.getPreviousSibling() : linebreak.getNextSibling();
|
|
1350
|
-
if (sibling == null) {
|
|
1351
|
-
return true;
|
|
1352
|
-
}
|
|
1353
|
-
const maybeInsertionPoint = $isCodeHighlightNode(sibling) || lexical.$isTabNode(sibling) || lexical.$isLineBreakNode(sibling) ? arrowIsUp ? $getFirstCodeNodeOfLine(sibling) : $getLastCodeNodeOfLine(sibling) : null;
|
|
1354
|
-
let insertionPoint = maybeInsertionPoint != null ? maybeInsertionPoint : sibling;
|
|
1355
|
-
linebreak.remove();
|
|
1356
|
-
range.forEach(node => node.remove());
|
|
1357
|
-
if (type === lexical.KEY_ARROW_UP_COMMAND) {
|
|
1358
|
-
range.forEach(node => insertionPoint.insertBefore(node));
|
|
1359
|
-
insertionPoint.insertBefore(linebreak);
|
|
1360
|
-
} else {
|
|
1361
|
-
insertionPoint.insertAfter(linebreak);
|
|
1362
|
-
insertionPoint = linebreak;
|
|
1363
|
-
range.forEach(node => {
|
|
1364
|
-
insertionPoint.insertAfter(node);
|
|
1365
|
-
insertionPoint = node;
|
|
1366
|
-
});
|
|
1367
|
-
}
|
|
1368
|
-
selection.setTextNodeRange(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
1369
|
-
return true;
|
|
1370
|
-
}
|
|
1371
|
-
function $handleMoveTo(type, event) {
|
|
1372
|
-
const selection = lexical.$getSelection();
|
|
1373
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
1374
|
-
return false;
|
|
1375
|
-
}
|
|
1376
|
-
const {
|
|
1377
|
-
anchor,
|
|
1378
|
-
focus
|
|
1379
|
-
} = selection;
|
|
1380
|
-
const anchorNode = anchor.getNode();
|
|
1381
|
-
const focusNode = focus.getNode();
|
|
1382
|
-
const isMoveToStart = type === lexical.MOVE_TO_START;
|
|
1383
|
-
|
|
1384
|
-
// Ensure the selection is within the codeblock
|
|
1385
|
-
if (!$isSelectionInCode(selection) || !($isCodeHighlightNode(anchorNode) || lexical.$isTabNode(anchorNode)) || !($isCodeHighlightNode(focusNode) || lexical.$isTabNode(focusNode))) {
|
|
1386
|
-
return false;
|
|
1387
|
-
}
|
|
1388
|
-
if (isMoveToStart) {
|
|
1389
|
-
const start = $getStartOfCodeInLine(focusNode, focus.offset);
|
|
1390
|
-
if (start !== null) {
|
|
1391
|
-
const {
|
|
1392
|
-
node,
|
|
1393
|
-
offset
|
|
1394
|
-
} = start;
|
|
1395
|
-
if (lexical.$isLineBreakNode(node)) {
|
|
1396
|
-
node.selectNext(0, 0);
|
|
1397
|
-
} else {
|
|
1398
|
-
selection.setTextNodeRange(node, offset, node, offset);
|
|
1399
|
-
}
|
|
1400
|
-
} else {
|
|
1401
|
-
focusNode.getParentOrThrow().selectStart();
|
|
1402
|
-
}
|
|
1403
|
-
} else {
|
|
1404
|
-
const node = $getEndOfCodeInLine(focusNode);
|
|
1405
|
-
node.select();
|
|
1406
|
-
}
|
|
1407
|
-
event.preventDefault();
|
|
1408
|
-
event.stopPropagation();
|
|
1409
|
-
return true;
|
|
1410
|
-
}
|
|
1411
|
-
function registerCodeHighlighting(editor, tokenizer) {
|
|
1412
|
-
if (!editor.hasNodes([CodeNode, CodeHighlightNode])) {
|
|
1413
|
-
throw new Error('CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor');
|
|
1414
|
-
}
|
|
1415
|
-
if (tokenizer == null) {
|
|
1416
|
-
tokenizer = PrismTokenizer;
|
|
1417
|
-
}
|
|
1418
|
-
const registrations = [];
|
|
1419
|
-
|
|
1420
|
-
// Only register the mutation listener if not in headless mode
|
|
1421
|
-
if (editor._headless !== true) {
|
|
1422
|
-
registrations.push(editor.registerMutationListener(CodeNode, mutations => {
|
|
1423
|
-
editor.update(() => {
|
|
1424
|
-
for (const [key, type] of mutations) {
|
|
1425
|
-
if (type !== 'destroyed') {
|
|
1426
|
-
const node = lexical.$getNodeByKey(key);
|
|
1427
|
-
if (node !== null) {
|
|
1428
|
-
updateCodeGutter(node, editor);
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
});
|
|
1433
|
-
}, {
|
|
1434
|
-
skipInitialization: false
|
|
1435
|
-
}));
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
// Add the rest of the registrations
|
|
1439
|
-
registrations.push(editor.registerNodeTransform(CodeNode, node => codeNodeTransform(node, editor, tokenizer)), editor.registerNodeTransform(lexical.TextNode, node => $textNodeTransform(node, editor, tokenizer)), editor.registerNodeTransform(CodeHighlightNode, node => $textNodeTransform(node, editor, tokenizer)), editor.registerCommand(lexical.KEY_TAB_COMMAND, event => {
|
|
1440
|
-
const command = $handleTab(event.shiftKey);
|
|
1441
|
-
if (command === null) {
|
|
1442
|
-
return false;
|
|
1443
|
-
}
|
|
1444
|
-
event.preventDefault();
|
|
1445
|
-
editor.dispatchCommand(command, undefined);
|
|
1446
|
-
return true;
|
|
1447
|
-
}, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.INSERT_TAB_COMMAND, () => {
|
|
1448
|
-
const selection = lexical.$getSelection();
|
|
1449
|
-
if (!$isSelectionInCode(selection)) {
|
|
1450
|
-
return false;
|
|
1451
|
-
}
|
|
1452
|
-
lexical.$insertNodes([lexical.$createTabNode()]);
|
|
1453
|
-
return true;
|
|
1454
|
-
}, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.INDENT_CONTENT_COMMAND, payload => $handleMultilineIndent(lexical.INDENT_CONTENT_COMMAND), lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND, payload => $handleMultilineIndent(lexical.OUTDENT_CONTENT_COMMAND), lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ARROW_UP_COMMAND, event => {
|
|
1455
|
-
const selection = lexical.$getSelection();
|
|
1456
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
1457
|
-
return false;
|
|
1458
|
-
}
|
|
1459
|
-
const {
|
|
1460
|
-
anchor
|
|
1461
|
-
} = selection;
|
|
1462
|
-
const anchorNode = anchor.getNode();
|
|
1463
|
-
if (!$isSelectionInCode(selection)) {
|
|
1464
|
-
return false;
|
|
1465
|
-
}
|
|
1466
|
-
// If at the start of a code block, prevent selection from moving out
|
|
1467
|
-
if (selection.isCollapsed() && anchor.offset === 0 && anchorNode.getPreviousSibling() === null && $isCodeNode(anchorNode.getParentOrThrow())) {
|
|
1468
|
-
event.preventDefault();
|
|
1469
|
-
return true;
|
|
1470
|
-
}
|
|
1471
|
-
return $handleShiftLines(lexical.KEY_ARROW_UP_COMMAND, event);
|
|
1472
|
-
}, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND, event => {
|
|
1473
|
-
const selection = lexical.$getSelection();
|
|
1474
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
1475
|
-
return false;
|
|
1476
|
-
}
|
|
1477
|
-
const {
|
|
1478
|
-
anchor
|
|
1479
|
-
} = selection;
|
|
1480
|
-
const anchorNode = anchor.getNode();
|
|
1481
|
-
if (!$isSelectionInCode(selection)) {
|
|
1482
|
-
return false;
|
|
1483
|
-
}
|
|
1484
|
-
// If at the end of a code block, prevent selection from moving out
|
|
1485
|
-
if (selection.isCollapsed() && anchor.offset === anchorNode.getTextContentSize() && anchorNode.getNextSibling() === null && $isCodeNode(anchorNode.getParentOrThrow())) {
|
|
1486
|
-
event.preventDefault();
|
|
1487
|
-
return true;
|
|
1488
|
-
}
|
|
1489
|
-
return $handleShiftLines(lexical.KEY_ARROW_DOWN_COMMAND, event);
|
|
1490
|
-
}, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.MOVE_TO_START, event => $handleMoveTo(lexical.MOVE_TO_START, event), lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.MOVE_TO_END, event => $handleMoveTo(lexical.MOVE_TO_END, event), lexical.COMMAND_PRIORITY_LOW));
|
|
1491
|
-
return LexicalUtils.mergeRegister(...registrations);
|
|
1492
|
-
}
|
|
1493
|
-
|
|
1494
|
-
/**
|
|
1495
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1496
|
-
*
|
|
1497
|
-
* This source code is licensed under the MIT license found in the
|
|
1498
|
-
* LICENSE file in the root directory of this source tree.
|
|
1499
|
-
*
|
|
1500
|
-
*/
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
/** @deprecated renamed to {@link $getFirstCodeNodeOfLine} by @lexical/eslint-plugin rules-of-lexical */
|
|
1504
|
-
const getFirstCodeNodeOfLine = $getFirstCodeNodeOfLine;
|
|
1505
|
-
/** @deprecated renamed to {@link $getLastCodeNodeOfLine} by @lexical/eslint-plugin rules-of-lexical */
|
|
1506
|
-
const getLastCodeNodeOfLine = $getLastCodeNodeOfLine;
|
|
1507
|
-
/** @deprecated renamed to {@link $getEndOfCodeInLine} by @lexical/eslint-plugin rules-of-lexical */
|
|
1508
|
-
const getEndOfCodeInLine = $getEndOfCodeInLine;
|
|
1509
|
-
/** @deprecated renamed to {@link $getStartOfCodeInLine} by @lexical/eslint-plugin rules-of-lexical */
|
|
1510
|
-
const getStartOfCodeInLine = $getStartOfCodeInLine;
|
|
1511
|
-
|
|
1512
|
-
exports.$createCodeHighlightNode = $createCodeHighlightNode;
|
|
1513
|
-
exports.$createCodeNode = $createCodeNode;
|
|
1514
|
-
exports.$getEndOfCodeInLine = $getEndOfCodeInLine;
|
|
1515
|
-
exports.$getFirstCodeNodeOfLine = $getFirstCodeNodeOfLine;
|
|
1516
|
-
exports.$getLastCodeNodeOfLine = $getLastCodeNodeOfLine;
|
|
1517
|
-
exports.$getStartOfCodeInLine = $getStartOfCodeInLine;
|
|
1518
|
-
exports.$isCodeHighlightNode = $isCodeHighlightNode;
|
|
1519
|
-
exports.$isCodeNode = $isCodeNode;
|
|
1520
|
-
exports.CODE_LANGUAGE_FRIENDLY_NAME_MAP = CODE_LANGUAGE_FRIENDLY_NAME_MAP;
|
|
1521
|
-
exports.CODE_LANGUAGE_MAP = CODE_LANGUAGE_MAP;
|
|
1522
|
-
exports.CodeHighlightNode = CodeHighlightNode;
|
|
1523
|
-
exports.CodeNode = CodeNode;
|
|
1524
|
-
exports.DEFAULT_CODE_LANGUAGE = DEFAULT_CODE_LANGUAGE;
|
|
1525
|
-
exports.PrismTokenizer = PrismTokenizer;
|
|
1526
|
-
exports.getCodeLanguageOptions = getCodeLanguageOptions;
|
|
1527
|
-
exports.getCodeLanguages = getCodeLanguages;
|
|
1528
|
-
exports.getCodeThemeOptions = getCodeThemeOptions;
|
|
1529
|
-
exports.getDefaultCodeLanguage = getDefaultCodeLanguage;
|
|
1530
|
-
exports.getEndOfCodeInLine = getEndOfCodeInLine;
|
|
1531
|
-
exports.getFirstCodeNodeOfLine = getFirstCodeNodeOfLine;
|
|
1532
|
-
exports.getLanguageFriendlyName = getLanguageFriendlyName;
|
|
1533
|
-
exports.getLastCodeNodeOfLine = getLastCodeNodeOfLine;
|
|
1534
|
-
exports.getStartOfCodeInLine = getStartOfCodeInLine;
|
|
1535
|
-
exports.normalizeCodeLang = normalizeCodeLang;
|
|
1536
|
-
exports.normalizeCodeLanguage = normalizeCodeLang;
|
|
1537
|
-
exports.registerCodeHighlighting = registerCodeHighlighting;
|