@sveltia/ui 0.90.0 → 0.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/bottom-navigation/bottom-navigation.svelte +3 -9
- package/dist/components/bottom-navigation/bottom-navigation.svelte.d.ts +4 -39
- package/dist/components/button/button-group.svelte +2 -4
- package/dist/components/button/button-group.svelte.d.ts +3 -19
- package/dist/components/button/select-button-group.svelte +2 -13
- package/dist/components/button/select-button-group.svelte.d.ts +5 -67
- package/dist/components/calendar/calendar.d.ts +9 -0
- package/dist/components/calendar/calendar.js +43 -0
- package/dist/components/calendar/calendar.svelte +26 -27
- package/dist/components/checkbox/checkbox-group.svelte +2 -8
- package/dist/components/checkbox/checkbox-group.svelte.d.ts +4 -39
- package/dist/components/dialog/alert-dialog.svelte.d.ts +2 -3
- package/dist/components/dialog/confirmation-dialog.svelte.d.ts +2 -3
- package/dist/components/dialog/dialog.svelte +6 -7
- package/dist/components/dialog/dialog.svelte.d.ts +2 -3
- package/dist/components/dialog/prompt-dialog.svelte +2 -2
- package/dist/components/dialog/prompt-dialog.svelte.d.ts +2 -3
- package/dist/components/disclosure/disclosure.svelte +14 -16
- package/dist/components/disclosure/disclosure.svelte.d.ts +4 -38
- package/dist/components/drawer/drawer.svelte +22 -39
- package/dist/components/drawer/drawer.svelte.d.ts +3 -24
- package/dist/components/grid/grid-body.svelte +2 -3
- package/dist/components/grid/grid-body.svelte.d.ts +3 -18
- package/dist/components/grid/grid-cell.svelte +2 -8
- package/dist/components/grid/grid-cell.svelte.d.ts +3 -22
- package/dist/components/grid/grid-col-header.svelte +2 -4
- package/dist/components/grid/grid-col-header.svelte.d.ts +3 -19
- package/dist/components/grid/grid-foot.svelte +4 -9
- package/dist/components/grid/grid-foot.svelte.d.ts +3 -22
- package/dist/components/grid/grid-head.svelte +4 -9
- package/dist/components/grid/grid-head.svelte.d.ts +3 -22
- package/dist/components/grid/grid-row-header.svelte +2 -8
- package/dist/components/grid/grid-row-header.svelte.d.ts +3 -22
- package/dist/components/grid/grid-row.svelte +4 -5
- package/dist/components/grid/grid-row.svelte.d.ts +3 -19
- package/dist/components/grid/grid.d.ts +10 -0
- package/dist/components/grid/grid.js +11 -0
- package/dist/components/grid/grid.svelte +6 -7
- package/dist/components/grid/grid.svelte.d.ts +5 -21
- package/dist/components/listbox/listbox.svelte +34 -15
- package/dist/components/listbox/listbox.svelte.d.ts +5 -69
- package/dist/components/listbox/option-group.svelte +2 -8
- package/dist/components/listbox/option-group.svelte.d.ts +4 -39
- package/dist/components/listbox/option.svelte +2 -1
- package/dist/components/menu/menu-item-group.svelte +2 -6
- package/dist/components/menu/menu-item-group.svelte.d.ts +3 -22
- package/dist/components/menu/menu-item.svelte +5 -1
- package/dist/components/menu/menu.svelte +2 -8
- package/dist/components/menu/menu.svelte.d.ts +4 -39
- package/dist/components/radio/radio-group.svelte +2 -17
- package/dist/components/radio/radio-group.svelte.d.ts +5 -67
- package/dist/components/radio/radio.svelte +19 -22
- package/dist/components/radio/radio.svelte.d.ts +10 -40
- package/dist/components/resizable-pane/resizable-handle.svelte +42 -49
- package/dist/components/resizable-pane/resizable-pane-group.svelte +44 -58
- package/dist/components/resizable-pane/resizable-pane-group.svelte.d.ts +3 -19
- package/dist/components/resizable-pane/resizable-pane.svelte +2 -5
- package/dist/components/resizable-pane/resizable-pane.svelte.d.ts +3 -19
- package/dist/components/resizable-pane/sizing.d.ts +24 -0
- package/dist/components/resizable-pane/sizing.js +83 -0
- package/dist/components/select/combobox.svelte +35 -39
- package/dist/components/select/select-tags.svelte +3 -13
- package/dist/components/select/select-tags.svelte.d.ts +5 -67
- package/dist/components/slider/slider.d.ts +5 -4
- package/dist/components/slider/slider.js +28 -23
- package/dist/components/slider/slider.svelte +64 -62
- package/dist/components/slider/slider.svelte.d.ts +4 -37
- package/dist/components/switch/switch.svelte +2 -13
- package/dist/components/switch/switch.svelte.d.ts +5 -67
- package/dist/components/table/table-body.svelte +2 -4
- package/dist/components/table/table-body.svelte.d.ts +3 -19
- package/dist/components/table/table-cell.svelte +2 -8
- package/dist/components/table/table-cell.svelte.d.ts +3 -22
- package/dist/components/table/table-col-header.svelte +2 -8
- package/dist/components/table/table-col-header.svelte.d.ts +3 -22
- package/dist/components/table/table-foot.svelte +2 -8
- package/dist/components/table/table-foot.svelte.d.ts +3 -22
- package/dist/components/table/table-head.svelte +2 -8
- package/dist/components/table/table-head.svelte.d.ts +3 -22
- package/dist/components/table/table-part.svelte +2 -4
- package/dist/components/table/table-part.svelte.d.ts +3 -19
- package/dist/components/table/table-row-header.svelte +2 -8
- package/dist/components/table/table-row-header.svelte.d.ts +3 -22
- package/dist/components/table/table-row.svelte +2 -8
- package/dist/components/table/table-row.svelte.d.ts +3 -22
- package/dist/components/table/table.svelte +2 -4
- package/dist/components/table/table.svelte.d.ts +3 -19
- package/dist/components/tabs/tab-box.svelte +2 -4
- package/dist/components/tabs/tab-box.svelte.d.ts +3 -19
- package/dist/components/tabs/tab-list.svelte +2 -7
- package/dist/components/tabs/tab-list.svelte.d.ts +4 -37
- package/dist/components/tabs/tab-panel.svelte +2 -8
- package/dist/components/tabs/tab-panel.svelte.d.ts +3 -22
- package/dist/components/tabs/tab-panels.svelte +2 -8
- package/dist/components/tabs/tab-panels.svelte.d.ts +3 -22
- package/dist/components/text-editor/code-editor.js +14 -7
- package/dist/components/text-editor/code-editor.svelte +14 -22
- package/dist/components/text-editor/code-editor.svelte.d.ts +5 -103
- package/dist/components/text-editor/config.d.ts +73 -0
- package/dist/components/text-editor/config.js +110 -0
- package/dist/components/text-editor/constants.d.ts +40 -6
- package/dist/components/text-editor/constants.js +81 -7
- package/dist/components/text-editor/conversion/editor-components.js +4 -4
- package/dist/components/text-editor/conversion/html/components.d.ts +16 -0
- package/dist/components/text-editor/conversion/html/components.js +87 -0
- package/dist/components/text-editor/conversion/html/export.d.ts +10 -0
- package/dist/components/text-editor/conversion/html/export.js +360 -0
- package/dist/components/text-editor/conversion/html/import-rules.d.ts +12 -0
- package/dist/components/text-editor/conversion/html/import-rules.js +234 -0
- package/dist/components/text-editor/conversion/html/index.d.ts +10 -0
- package/dist/components/text-editor/conversion/html/index.js +33 -0
- package/dist/components/text-editor/conversion/html/paragraph.d.ts +1 -0
- package/dist/components/text-editor/conversion/html/paragraph.js +123 -0
- package/dist/components/text-editor/conversion/html/task-list.d.ts +13 -0
- package/dist/components/text-editor/conversion/html/task-list.js +82 -0
- package/dist/components/text-editor/conversion/html/unsupported.d.ts +2 -0
- package/dist/components/text-editor/conversion/html/unsupported.js +122 -0
- package/dist/components/text-editor/conversion/html/utils.d.ts +6 -0
- package/dist/components/text-editor/conversion/html/utils.js +34 -0
- package/dist/components/text-editor/conversion/import.js +33 -27
- package/dist/components/text-editor/conversion/markdown/block-conversion.d.ts +4 -0
- package/dist/components/text-editor/conversion/markdown/block-conversion.js +154 -0
- package/dist/components/text-editor/conversion/markdown/block-structure.d.ts +16 -0
- package/dist/components/text-editor/conversion/markdown/block-structure.js +254 -0
- package/dist/components/text-editor/conversion/markdown/code-blocks.d.ts +57 -0
- package/dist/components/text-editor/conversion/markdown/code-blocks.js +279 -0
- package/dist/components/text-editor/conversion/markdown/code-spans.d.ts +19 -0
- package/dist/components/text-editor/conversion/markdown/code-spans.js +71 -0
- package/dist/components/text-editor/conversion/markdown/formatting.d.ts +22 -0
- package/dist/components/text-editor/conversion/markdown/formatting.js +451 -0
- package/dist/components/text-editor/conversion/markdown/index.d.ts +10 -0
- package/dist/components/text-editor/conversion/markdown/index.js +55 -0
- package/dist/components/text-editor/conversion/markdown/placeholders.d.ts +2 -0
- package/dist/components/text-editor/conversion/markdown/placeholders.js +229 -0
- package/dist/components/text-editor/conversion/markdown/syntax.d.ts +99 -0
- package/dist/components/text-editor/conversion/markdown/syntax.js +206 -0
- package/dist/components/text-editor/conversion/placeholder-chars.d.ts +43 -0
- package/dist/components/text-editor/conversion/placeholder-chars.js +51 -0
- package/dist/components/text-editor/conversion/transformers/block-escape.d.ts +1 -0
- package/dist/components/text-editor/conversion/transformers/block-escape.js +53 -26
- package/dist/components/text-editor/conversion/transformers/code.d.ts +3 -14
- package/dist/components/text-editor/conversion/transformers/code.js +78 -16
- package/dist/components/text-editor/conversion/transformers/formatted-code.js +3 -18
- package/dist/components/text-editor/conversion/transformers/inline-code.js +3 -1
- package/dist/components/text-editor/conversion/transformers/link.js +3 -1
- package/dist/components/text-editor/conversion/transformers/raw-syntax.d.ts +0 -19
- package/dist/components/text-editor/conversion/transformers/raw-syntax.js +22 -93
- package/dist/components/text-editor/conversion/transformers/table.js +57 -16
- package/dist/components/text-editor/conversion/transformers/task-list.d.ts +24 -0
- package/dist/components/text-editor/conversion/transformers/task-list.js +53 -0
- package/dist/components/text-editor/conversion/update.d.ts +19 -2
- package/dist/components/text-editor/conversion/update.js +64 -40
- package/dist/components/text-editor/core.d.ts +12 -51
- package/dist/components/text-editor/core.js +47 -77
- package/dist/components/text-editor/editing/commands.js +9 -18
- package/dist/components/text-editor/editing/guards.d.ts +7 -0
- package/dist/components/text-editor/editing/guards.js +123 -0
- package/dist/components/text-editor/editing/raw-markdown.d.ts +7 -2
- package/dist/components/text-editor/editing/raw-markdown.js +68 -8
- package/dist/components/text-editor/editing/selection.js +6 -2
- package/dist/components/text-editor/lexical-root.svelte +89 -47
- package/dist/components/text-editor/lexical-root.svelte.d.ts +4 -67
- package/dist/components/text-editor/shiki/{facade.d.ts → engine.d.ts} +8 -8
- package/dist/components/text-editor/shiki/{facade.js → engine.js} +53 -156
- package/dist/components/text-editor/shiki/highlighter.js +5 -5
- package/dist/components/text-editor/shiki/lexical.d.ts +6 -0
- package/dist/components/text-editor/shiki/lexical.js +165 -0
- package/dist/components/text-editor/shiki/preload.js +1 -1
- package/dist/components/text-editor/shiki/source-highlight.svelte.d.ts +15 -0
- package/dist/components/text-editor/shiki/source-highlight.svelte.js +120 -0
- package/dist/components/text-editor/shiki/version.d.ts +1 -1
- package/dist/components/text-editor/shiki/version.js +1 -1
- package/dist/components/text-editor/store.svelte.js +65 -16
- package/dist/components/text-editor/text-editor.svelte +57 -146
- package/dist/components/text-editor/text-editor.svelte.d.ts +9 -105
- package/dist/components/text-editor/toolbar/actions.d.ts +25 -0
- package/dist/components/text-editor/toolbar/actions.js +107 -0
- package/dist/components/text-editor/toolbar/align-menu-button.svelte +16 -14
- package/dist/components/text-editor/toolbar/format-text-button.svelte +27 -19
- package/dist/components/text-editor/toolbar/insert-horizontal-rule-button.svelte +23 -23
- package/dist/components/text-editor/toolbar/insert-item-button.svelte +1 -1
- package/dist/components/text-editor/toolbar/insert-link-button.svelte +47 -51
- package/dist/components/text-editor/toolbar/insert-menu-button.svelte +1 -1
- package/dist/components/text-editor/toolbar/insert-table-button.svelte +35 -52
- package/dist/components/text-editor/toolbar/table-action-menu.svelte +19 -17
- package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte +34 -11
- package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte.d.ts +0 -8
- package/dist/components/text-editor/toolbar/toggle-block-menu-item.svelte +35 -41
- package/dist/components/text-editor/widgets/emoji-autocomplete.svelte +7 -6
- package/dist/components/text-editor/widgets/floating-link-editor.svelte +19 -32
- package/dist/components/text-editor/widgets/table-cell-menu-button.svelte +28 -32
- package/dist/components/text-field/date-time-input.svelte +7 -8
- package/dist/components/text-field/date-time-input.svelte.d.ts +3 -32
- package/dist/components/text-field/number-input.d.ts +0 -2
- package/dist/components/text-field/number-input.js +25 -25
- package/dist/components/text-field/number-input.svelte +18 -9
- package/dist/components/text-field/number-input.svelte.d.ts +1 -1
- package/dist/components/text-field/text-area.d.ts +2 -0
- package/dist/components/text-field/text-area.js +31 -0
- package/dist/components/text-field/text-area.svelte +12 -25
- package/dist/components/text-field/text-area.svelte.d.ts +5 -67
- package/dist/components/toast/toast.svelte +31 -8
- package/dist/components/toast/toast.svelte.d.ts +6 -6
- package/dist/components/toolbar/toolbar.svelte +2 -7
- package/dist/components/toolbar/toolbar.svelte.d.ts +4 -37
- package/dist/components/tree/tree-item.svelte +2 -6
- package/dist/components/tree/tree-item.svelte.d.ts +3 -22
- package/dist/components/tree/tree.svelte +3 -10
- package/dist/components/tree/tree.svelte.d.ts +4 -39
- package/dist/components/util/group.svelte +2 -7
- package/dist/components/util/group.svelte.d.ts +4 -37
- package/dist/components/util/modal.d.ts +9 -0
- package/dist/components/util/modal.js +30 -0
- package/dist/components/util/modal.svelte +16 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/locales/ar.yaml +2 -0
- package/dist/locales/bg.yaml +2 -0
- package/dist/locales/ca.yaml +2 -0
- package/dist/locales/cs.yaml +2 -0
- package/dist/locales/da.yaml +2 -0
- package/dist/locales/de.yaml +2 -0
- package/dist/locales/el.yaml +2 -0
- package/dist/locales/en-CA.yaml +2 -0
- package/dist/locales/en-GB.yaml +2 -0
- package/dist/locales/en-US.yaml +2 -0
- package/dist/locales/en-ZA.yaml +2 -0
- package/dist/locales/es-CO.yaml +2 -0
- package/dist/locales/es-ES.yaml +2 -0
- package/dist/locales/fa.yaml +2 -0
- package/dist/locales/fi.yaml +2 -0
- package/dist/locales/fr.yaml +2 -0
- package/dist/locales/he.yaml +2 -0
- package/dist/locales/hr.yaml +2 -0
- package/dist/locales/hu.yaml +176 -0
- package/dist/locales/it.yaml +2 -0
- package/dist/locales/ja.yaml +2 -0
- package/dist/locales/ko.yaml +2 -0
- package/dist/locales/nl.yaml +2 -0
- package/dist/locales/pl.yaml +2 -0
- package/dist/locales/pt-BR.yaml +2 -0
- package/dist/locales/pt-PT.yaml +2 -0
- package/dist/locales/ru.yaml +2 -0
- package/dist/locales/sk.yaml +2 -0
- package/dist/locales/sv.yaml +2 -0
- package/dist/locales/tr.yaml +2 -0
- package/dist/locales/uk.yaml +2 -0
- package/dist/locales/vi.yaml +2 -0
- package/dist/locales/zh-CN.yaml +2 -0
- package/dist/locales/zh-TW.yaml +2 -0
- package/dist/services/composite-widget.svelte.d.ts +76 -0
- package/dist/services/composite-widget.svelte.js +157 -0
- package/dist/services/focus.d.ts +2 -0
- package/dist/services/focus.js +68 -0
- package/dist/services/group.svelte.d.ts +17 -69
- package/dist/services/group.svelte.js +128 -391
- package/dist/services/label.d.ts +9 -0
- package/dist/services/label.js +22 -0
- package/dist/services/menu.d.ts +8 -0
- package/dist/services/menu.js +237 -0
- package/dist/services/navigation.d.ts +9 -0
- package/dist/services/navigation.js +13 -0
- package/dist/services/number.d.ts +2 -0
- package/dist/services/number.js +27 -0
- package/dist/services/pointer-drag.d.ts +14 -0
- package/dist/services/pointer-drag.js +89 -0
- package/dist/services/popup.svelte.js +123 -103
- package/dist/services/text.d.ts +3 -0
- package/dist/services/text.js +17 -0
- package/dist/services/tree.svelte.d.ts +29 -43
- package/dist/services/tree.svelte.js +58 -105
- package/dist/services/type-ahead.d.ts +10 -1
- package/dist/services/type-ahead.js +56 -34
- package/dist/typedefs.d.ts +108 -6
- package/dist/typedefs.js +63 -6
- package/package.json +5 -5
- package/dist/components/text-editor/conversion/html.d.ts +0 -30
- package/dist/components/text-editor/conversion/html.js +0 -857
- package/dist/components/text-editor/conversion/markdown.d.ts +0 -56
- package/dist/components/text-editor/conversion/markdown.js +0 -949
- package/dist/components/text-editor/toolbar/code-editor-toolbar.svelte +0 -28
- package/dist/components/text-editor/toolbar/code-editor-toolbar.svelte.d.ts +0 -37
- package/dist/components/text-editor/toolbar/insert-component.d.ts +0 -3
- package/dist/components/text-editor/toolbar/insert-component.js +0 -37
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Thin wrapper around a Shiki highlighter instance.
|
|
2
|
+
* Thin wrapper around a Shiki highlighter instance, independent of any editor. The Lexical glue
|
|
3
|
+
* that turns tokens into nodes and refreshes code blocks lives in `lexical.js`.
|
|
3
4
|
*
|
|
4
5
|
* Adapted from Lexical’s `FacadeShiki.ts` (MIT licensed). Two things differ from upstream, both to
|
|
5
6
|
* keep Shiki out of the consumer’s bundle. First, the engine is loaded on demand rather than
|
|
@@ -10,26 +11,12 @@
|
|
|
10
11
|
* @see https://github.com/sveltia/sveltia-cms/issues/587
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
|
-
import {
|
|
14
|
-
$isCodeNode as isCodeNode,
|
|
15
|
-
$createCodeHighlightNode as createCodeHighlightNode,
|
|
16
|
-
} from '@lexical/code-core';
|
|
17
|
-
import {
|
|
18
|
-
$createLineBreakNode as createLineBreakNode,
|
|
19
|
-
$createTabNode as createTabNode,
|
|
20
|
-
$getNodeByKey as getNodeByKey,
|
|
21
|
-
HISTORY_MERGE_TAG,
|
|
22
|
-
tokenizeRawText,
|
|
23
|
-
} from 'lexical';
|
|
24
|
-
import { getBackgroundUpdateTags } from '../background-update.js';
|
|
25
14
|
import { cachePayload, getCachedPayload } from './cache.js';
|
|
26
15
|
import { LANGUAGES, THEMES } from './generated.js';
|
|
27
16
|
import { getCodeHighlighterLoaders } from './loader.js';
|
|
28
17
|
import { getCodeTheme } from './theme.js';
|
|
29
18
|
|
|
30
19
|
/**
|
|
31
|
-
* @import { CodeNode } from '@lexical/code-core';
|
|
32
|
-
* @import { LexicalEditor, LexicalNode, NodeKey } from 'lexical';
|
|
33
20
|
* @import { HighlightedToken } from '../../../typedefs.js';
|
|
34
21
|
*/
|
|
35
22
|
|
|
@@ -102,57 +89,32 @@ export const isCodeLanguageLoaded = (language) => {
|
|
|
102
89
|
return highlighter.getLoadedLanguages().includes(id);
|
|
103
90
|
};
|
|
104
91
|
|
|
105
|
-
/**
|
|
106
|
-
* Mark a code node dirty so the highlighting transform runs again once an async load has completed.
|
|
107
|
-
* @param {LexicalEditor} editor Editor instance.
|
|
108
|
-
* @param {NodeKey} codeNodeKey Key of the code node to refresh.
|
|
109
|
-
*/
|
|
110
|
-
const refreshCodeNode = (editor, codeNodeKey) => {
|
|
111
|
-
editor.update(
|
|
112
|
-
() => {
|
|
113
|
-
const codeNode = getNodeByKey(codeNodeKey);
|
|
114
|
-
|
|
115
|
-
if (!isCodeNode(codeNode)) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const language = codeNode.getLanguage();
|
|
120
|
-
|
|
121
|
-
if (language && isCodeLanguageLoaded(language) && !codeNode.getIsSyntaxHighlightSupported()) {
|
|
122
|
-
codeNode.setIsSyntaxHighlightSupported(true);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
codeNode.markDirty();
|
|
126
|
-
},
|
|
127
|
-
{ tag: getBackgroundUpdateTags(editor, [HISTORY_MERGE_TAG]) },
|
|
128
|
-
);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
92
|
/**
|
|
132
93
|
* In-flight loads, keyed by what is being loaded.
|
|
133
|
-
* @type {Map<string, { promise: Promise<void>,
|
|
94
|
+
* @type {Map<string, { promise: Promise<void>, callbacks: Set<() => void> }>}
|
|
134
95
|
*/
|
|
135
96
|
const pendingLoads = new Map();
|
|
136
97
|
|
|
137
98
|
/**
|
|
138
|
-
* Run an asynchronous load once, however many callers ask for it while it is in flight, and
|
|
139
|
-
* each
|
|
99
|
+
* Run an asynchronous load once, however many callers ask for it while it is in flight, and call
|
|
100
|
+
* each distinct callback exactly once when it completes.
|
|
140
101
|
*
|
|
141
|
-
* The transform fires on every keystroke, so without this a burst of typing during a load
|
|
142
|
-
* start a download per keystroke and then flood the editor with one update each. That storm
|
|
143
|
-
* enough to starve the final re-highlight, leaving a block tokenized as of an earlier keystroke.
|
|
102
|
+
* The editor transform fires on every keystroke, so without this a burst of typing during a load
|
|
103
|
+
* would start a download per keystroke and then flood the editor with one update each. That storm
|
|
104
|
+
* is enough to starve the final re-highlight, leaving a block tokenized as of an earlier keystroke.
|
|
105
|
+
* Callers that want a single notification for repeated requests should therefore pass the same
|
|
106
|
+
* callback each time.
|
|
144
107
|
* @param {string} key Cache key identifying the load.
|
|
145
108
|
* @param {() => Promise<void>} run Work to perform on the first call.
|
|
146
|
-
* @param {
|
|
147
|
-
* @param {NodeKey} [codeNodeKey] Key of the code node to refresh.
|
|
109
|
+
* @param {() => void} [onLoaded] Function to call once the load completes.
|
|
148
110
|
* @returns {Promise<void>} Promise resolving when the load has completed.
|
|
149
111
|
*/
|
|
150
|
-
const loadOnce = (key, run,
|
|
112
|
+
const loadOnce = (key, run, onLoaded) => {
|
|
151
113
|
let entry = pendingLoads.get(key);
|
|
152
114
|
|
|
153
115
|
if (!entry) {
|
|
154
|
-
/** @type {
|
|
155
|
-
const
|
|
116
|
+
/** @type {Set<() => void>} */
|
|
117
|
+
const callbacks = new Set();
|
|
156
118
|
|
|
157
119
|
const promise = (async () => {
|
|
158
120
|
try {
|
|
@@ -162,32 +124,32 @@ const loadOnce = (key, run, editor, codeNodeKey) => {
|
|
|
162
124
|
}
|
|
163
125
|
|
|
164
126
|
pendingLoads.delete(key);
|
|
165
|
-
|
|
127
|
+
callbacks.forEach((callback) => callback());
|
|
166
128
|
})();
|
|
167
129
|
|
|
168
|
-
entry = { promise,
|
|
130
|
+
entry = { promise, callbacks };
|
|
169
131
|
pendingLoads.set(key, entry);
|
|
170
132
|
}
|
|
171
133
|
|
|
172
|
-
if (
|
|
173
|
-
entry.
|
|
134
|
+
if (onLoaded) {
|
|
135
|
+
entry.callbacks.add(onLoaded);
|
|
174
136
|
}
|
|
175
137
|
|
|
176
138
|
return entry.promise;
|
|
177
139
|
};
|
|
178
140
|
|
|
179
141
|
/**
|
|
180
|
-
* Load the syntax highlighting engine, then
|
|
142
|
+
* Load the syntax highlighting engine, then call the given function.
|
|
181
143
|
*
|
|
182
144
|
* Tokenizing is synchronous because it runs inside a Lexical node transform, so the engine has to
|
|
183
145
|
* be resident before any highlighting can happen. The transform bails out while this is in flight
|
|
184
|
-
* and is re-run by
|
|
185
|
-
* @param {
|
|
186
|
-
*
|
|
146
|
+
* and is re-run by the callback, the same mechanism upstream already uses for grammars.
|
|
147
|
+
* @param {() => void} [onLoaded] Function to call once the load has completed, whether or not it
|
|
148
|
+
* succeeded.
|
|
187
149
|
* @returns {Promise<void> | undefined} Promise resolving when the engine is ready, or `undefined`
|
|
188
150
|
* when it is already loaded or known to be unavailable.
|
|
189
151
|
*/
|
|
190
|
-
export const loadEngine = (
|
|
152
|
+
export const loadEngine = (onLoaded) => {
|
|
191
153
|
if (highlighter || engineUnavailable) {
|
|
192
154
|
return undefined;
|
|
193
155
|
}
|
|
@@ -207,8 +169,7 @@ export const loadEngine = (editor, codeNodeKey) => {
|
|
|
207
169
|
engineUnavailable = true;
|
|
208
170
|
}
|
|
209
171
|
},
|
|
210
|
-
|
|
211
|
-
codeNodeKey,
|
|
172
|
+
onLoaded,
|
|
212
173
|
);
|
|
213
174
|
};
|
|
214
175
|
|
|
@@ -244,15 +205,14 @@ const resolvePayload = async (kind, id, load) => {
|
|
|
244
205
|
};
|
|
245
206
|
|
|
246
207
|
/**
|
|
247
|
-
* Load a grammar or theme into the highlighter once, then
|
|
248
|
-
*
|
|
208
|
+
* Load a grammar or theme into the highlighter once, then call the given function. The configured
|
|
209
|
+
* loader and the highlighter share the method name for each kind.
|
|
249
210
|
* @param {'lang' | 'theme'} kind Payload kind.
|
|
250
211
|
* @param {string} id Language or theme ID.
|
|
251
|
-
* @param {
|
|
252
|
-
* @param {NodeKey} [codeNodeKey] Key of the code node to refresh.
|
|
212
|
+
* @param {() => void} [onLoaded] Function to call once the load has completed.
|
|
253
213
|
* @returns {Promise<void>} Promise resolving when the payload is loaded.
|
|
254
214
|
*/
|
|
255
|
-
const loadAsset = (kind, id,
|
|
215
|
+
const loadAsset = (kind, id, onLoaded) => {
|
|
256
216
|
const method = kind === 'lang' ? 'loadLanguage' : 'loadTheme';
|
|
257
217
|
|
|
258
218
|
return loadOnce(
|
|
@@ -264,8 +224,7 @@ const loadAsset = (kind, id, editor, codeNodeKey) => {
|
|
|
264
224
|
await highlighter[method](payload);
|
|
265
225
|
}
|
|
266
226
|
},
|
|
267
|
-
|
|
268
|
-
codeNodeKey,
|
|
227
|
+
onLoaded,
|
|
269
228
|
);
|
|
270
229
|
};
|
|
271
230
|
|
|
@@ -287,14 +246,13 @@ const findLanguage = (language) =>
|
|
|
287
246
|
export const normalizeCodeLanguage = (language) => findLanguage(language)?.id ?? language;
|
|
288
247
|
|
|
289
248
|
/**
|
|
290
|
-
* Load the grammar for the given language, then
|
|
249
|
+
* Load the grammar for the given language, then call the given function.
|
|
291
250
|
* @param {string} language Language identifier, like `scss` or `diff-js`.
|
|
292
|
-
* @param {
|
|
293
|
-
* @param {NodeKey} [codeNodeKey] Key of the code node to refresh.
|
|
251
|
+
* @param {() => void} [onLoaded] Function to call once the load has completed.
|
|
294
252
|
* @returns {Promise<void> | undefined} Promise resolving when the grammar is ready, or `undefined`
|
|
295
253
|
* when it is already loaded or the language is not supported.
|
|
296
254
|
*/
|
|
297
|
-
export const loadCodeLanguage = (language,
|
|
255
|
+
export const loadCodeLanguage = (language, onLoaded) => {
|
|
298
256
|
const id = getDiffedLanguage(language) ?? language;
|
|
299
257
|
|
|
300
258
|
if (!highlighter || isCodeLanguageLoaded(id)) {
|
|
@@ -307,7 +265,7 @@ export const loadCodeLanguage = (language, editor, codeNodeKey) => {
|
|
|
307
265
|
return undefined;
|
|
308
266
|
}
|
|
309
267
|
|
|
310
|
-
return loadAsset('lang', info.id,
|
|
268
|
+
return loadAsset('lang', info.id, onLoaded);
|
|
311
269
|
};
|
|
312
270
|
|
|
313
271
|
/**
|
|
@@ -324,14 +282,13 @@ export const isCodeThemeLoaded = (theme) => {
|
|
|
324
282
|
};
|
|
325
283
|
|
|
326
284
|
/**
|
|
327
|
-
* Load the given theme, then
|
|
285
|
+
* Load the given theme, then call the given function.
|
|
328
286
|
* @param {string} theme Theme identifier, like `github-light`.
|
|
329
|
-
* @param {
|
|
330
|
-
* @param {NodeKey} [codeNodeKey] Key of the code node to refresh.
|
|
287
|
+
* @param {() => void} [onLoaded] Function to call once the load has completed.
|
|
331
288
|
* @returns {Promise<void> | undefined} Promise resolving when the theme is ready, or `undefined`
|
|
332
289
|
* when it is already loaded or unknown.
|
|
333
290
|
*/
|
|
334
|
-
export const loadCodeTheme = (theme,
|
|
291
|
+
export const loadCodeTheme = (theme, onLoaded) => {
|
|
335
292
|
if (!highlighter || isCodeThemeLoaded(theme)) {
|
|
336
293
|
return undefined;
|
|
337
294
|
}
|
|
@@ -340,92 +297,32 @@ export const loadCodeTheme = (theme, editor, codeNodeKey) => {
|
|
|
340
297
|
return undefined;
|
|
341
298
|
}
|
|
342
299
|
|
|
343
|
-
return loadAsset('theme', theme,
|
|
300
|
+
return loadAsset('theme', theme, onLoaded);
|
|
344
301
|
};
|
|
345
302
|
|
|
346
303
|
/**
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
* @param {
|
|
350
|
-
* @
|
|
304
|
+
* Tokenize a snippet of code with the raw Shiki tokens, for building editor nodes. The engine, the
|
|
305
|
+
* grammar and the theme must all be loaded.
|
|
306
|
+
* @param {string} code Code to tokenize.
|
|
307
|
+
* @param {string} language Language identifier, like `scss` or `diff-js`.
|
|
308
|
+
* @param {string} [theme] Shiki theme ID.
|
|
309
|
+
* @returns {{ tokens: any[][], diff: boolean }} Tokens, one array per line, and whether the
|
|
310
|
+
* language is a `diff-*` language, in which case the code is tokenized with the language it wraps.
|
|
351
311
|
*/
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
tokens.forEach((line, lineIndex) => {
|
|
357
|
-
if (lineIndex) {
|
|
358
|
-
nodes.push(createLineBreakNode());
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
line.forEach((token, tokenIndex) => {
|
|
362
|
-
let { content: text } = token;
|
|
363
|
-
|
|
364
|
-
// Implement `diff-*` languages
|
|
365
|
-
if (diff && tokenIndex === 0 && text.length > 0) {
|
|
366
|
-
const prefixes = ['+', '-', '>', '<', ' '];
|
|
367
|
-
const prefixTypes = ['inserted', 'deleted', 'inserted', 'deleted', 'unchanged'];
|
|
368
|
-
const prefixIndex = prefixes.indexOf(text[0]);
|
|
369
|
-
|
|
370
|
-
if (prefixIndex !== -1) {
|
|
371
|
-
nodes.push(createCodeHighlightNode(prefixes[prefixIndex], prefixTypes[prefixIndex]));
|
|
372
|
-
text = text.slice(1);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
312
|
+
export const tokenizeCode = (code, language, theme) => {
|
|
313
|
+
const diffedLanguage = getDiffedLanguage(language);
|
|
314
|
+
const { tokens } = highlighter.codeToTokens(code, { lang: diffedLanguage ?? language, theme });
|
|
375
315
|
|
|
376
|
-
|
|
377
|
-
token.htmlStyle || engine.getTokenStyleObject(token),
|
|
378
|
-
);
|
|
379
|
-
|
|
380
|
-
tokenizeRawText(text, {
|
|
381
|
-
/**
|
|
382
|
-
* Append a line break node.
|
|
383
|
-
* @returns {number} New node count.
|
|
384
|
-
*/
|
|
385
|
-
linebreak: () => nodes.push(createLineBreakNode()),
|
|
386
|
-
/**
|
|
387
|
-
* Append a tab node.
|
|
388
|
-
* @returns {number} New node count.
|
|
389
|
-
*/
|
|
390
|
-
tab: () => nodes.push(createTabNode()),
|
|
391
|
-
/**
|
|
392
|
-
* Create a highlight node carrying the token’s colour.
|
|
393
|
-
* @param {string} part Text fragment.
|
|
394
|
-
*/
|
|
395
|
-
text: (part) => {
|
|
396
|
-
const node = createCodeHighlightNode(part);
|
|
397
|
-
|
|
398
|
-
node.setStyle(style);
|
|
399
|
-
nodes.push(node);
|
|
400
|
-
},
|
|
401
|
-
});
|
|
402
|
-
});
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
return nodes;
|
|
316
|
+
return { tokens, diff: !!diffedLanguage };
|
|
406
317
|
};
|
|
407
318
|
|
|
408
319
|
/**
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
* The block’s own colours come from `--sui-code-background-color` so that plain and highlighted
|
|
413
|
-
* blocks look alike and follow the app’s theme rather than Shiki’s; only the per-token colours are
|
|
414
|
-
* taken from the theme.
|
|
415
|
-
* @param {CodeNode} codeNode Code node to tokenize.
|
|
416
|
-
* @param {string} language Language identifier.
|
|
417
|
-
* @returns {LexicalNode[]} Lexical nodes.
|
|
320
|
+
* Get the inline style of a Shiki token, preferring its own inline style over the derived one.
|
|
321
|
+
* @param {any} token Token returned by {@link tokenizeCode}.
|
|
322
|
+
* @returns {string} CSS declarations.
|
|
418
323
|
*/
|
|
419
|
-
export const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
const { tokens } = highlighter.codeToTokens(codeNode.getTextContent(), {
|
|
423
|
-
lang: diffedLanguage ?? language,
|
|
424
|
-
theme: codeNode.getTheme(),
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
return mapTokensToLexicalStructure(tokens, !!diffedLanguage);
|
|
428
|
-
};
|
|
324
|
+
export const getTokenStyle = (token) =>
|
|
325
|
+
engine.stringifyTokenStyle(token.htmlStyle || engine.getTokenStyleObject(token));
|
|
429
326
|
|
|
430
327
|
/**
|
|
431
328
|
* Get the theme to highlight a snippet of code with, if it can be highlighted synchronously: the
|
|
@@ -35,7 +35,6 @@ import {
|
|
|
35
35
|
} from 'lexical';
|
|
36
36
|
import { getBackgroundUpdateTags } from '../background-update.js';
|
|
37
37
|
import {
|
|
38
|
-
getHighlightNodes,
|
|
39
38
|
isCodeLanguageLoaded,
|
|
40
39
|
isCodeThemeLoaded,
|
|
41
40
|
isEngineLoaded,
|
|
@@ -44,7 +43,8 @@ import {
|
|
|
44
43
|
loadCodeLanguage,
|
|
45
44
|
loadCodeTheme,
|
|
46
45
|
loadEngine,
|
|
47
|
-
} from './
|
|
46
|
+
} from './engine.js';
|
|
47
|
+
import { getCodeNodeRefresher, getHighlightNodes } from './lexical.js';
|
|
48
48
|
import { CODE_THEME_LIGHT } from './theme.js';
|
|
49
49
|
|
|
50
50
|
/**
|
|
@@ -321,12 +321,12 @@ const codeNodeTransform = (editor, tokenizer, transformState, node) => {
|
|
|
321
321
|
}
|
|
322
322
|
} else if (!isEngineLoaded()) {
|
|
323
323
|
// Dynamic load of the engine itself
|
|
324
|
-
loadEngine(editor, nodeKey);
|
|
324
|
+
loadEngine(getCodeNodeRefresher(editor, nodeKey));
|
|
325
325
|
inFlight = true;
|
|
326
326
|
} else {
|
|
327
327
|
// Dynamic load of themes
|
|
328
328
|
if (!isCodeThemeLoaded(theme)) {
|
|
329
|
-
loadCodeTheme(theme, editor, nodeKey);
|
|
329
|
+
loadCodeTheme(theme, getCodeNodeRefresher(editor, nodeKey));
|
|
330
330
|
inFlight = true;
|
|
331
331
|
}
|
|
332
332
|
|
|
@@ -336,7 +336,7 @@ const codeNodeTransform = (editor, tokenizer, transformState, node) => {
|
|
|
336
336
|
node.setIsSyntaxHighlightSupported(true);
|
|
337
337
|
}
|
|
338
338
|
} else {
|
|
339
|
-
const loadingTask = loadCodeLanguage(language, editor, nodeKey);
|
|
339
|
+
const loadingTask = loadCodeLanguage(language, getCodeNodeRefresher(editor, nodeKey));
|
|
340
340
|
|
|
341
341
|
// If the language is not supported, no download will occur
|
|
342
342
|
if (!loadingTask && node.getIsSyntaxHighlightSupported()) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export function getCodeNodeRefresher(editor: LexicalEditor, codeNodeKey: NodeKey): () => void;
|
|
2
|
+
export function getHighlightNodes(codeNode: CodeNode, language: string): LexicalNode[];
|
|
3
|
+
import type { LexicalEditor } from 'lexical';
|
|
4
|
+
import type { NodeKey } from 'lexical';
|
|
5
|
+
import type { CodeNode } from '@lexical/code-core';
|
|
6
|
+
import type { LexicalNode } from 'lexical';
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lexical glue for the Shiki engine: turning tokens into code highlight nodes, and refreshing code
|
|
3
|
+
* nodes once an async load has completed.
|
|
4
|
+
*
|
|
5
|
+
* Adapted from Lexical’s `FacadeShiki.ts` (MIT licensed).
|
|
6
|
+
* @see https://github.com/facebook/lexical/tree/v0.50.0/packages/lexical-code-shiki
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
$isCodeNode as isCodeNode,
|
|
11
|
+
$createCodeHighlightNode as createCodeHighlightNode,
|
|
12
|
+
} from '@lexical/code-core';
|
|
13
|
+
import {
|
|
14
|
+
$createLineBreakNode as createLineBreakNode,
|
|
15
|
+
$createTabNode as createTabNode,
|
|
16
|
+
$getNodeByKey as getNodeByKey,
|
|
17
|
+
HISTORY_MERGE_TAG,
|
|
18
|
+
tokenizeRawText,
|
|
19
|
+
} from 'lexical';
|
|
20
|
+
import { getBackgroundUpdateTags } from '../background-update.js';
|
|
21
|
+
import { getTokenStyle, isCodeLanguageLoaded, tokenizeCode } from './engine.js';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @import { CodeNode } from '@lexical/code-core';
|
|
25
|
+
* @import { LexicalEditor, LexicalNode, NodeKey } from 'lexical';
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Mark a code node dirty so the highlighting transform runs again once an async load has completed.
|
|
30
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
31
|
+
* @param {NodeKey} codeNodeKey Key of the code node to refresh.
|
|
32
|
+
*/
|
|
33
|
+
const refreshCodeNode = (editor, codeNodeKey) => {
|
|
34
|
+
editor.update(
|
|
35
|
+
() => {
|
|
36
|
+
const codeNode = getNodeByKey(codeNodeKey);
|
|
37
|
+
|
|
38
|
+
if (!isCodeNode(codeNode)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const language = codeNode.getLanguage();
|
|
43
|
+
|
|
44
|
+
if (language && isCodeLanguageLoaded(language) && !codeNode.getIsSyntaxHighlightSupported()) {
|
|
45
|
+
codeNode.setIsSyntaxHighlightSupported(true);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
codeNode.markDirty();
|
|
49
|
+
},
|
|
50
|
+
{ tag: getBackgroundUpdateTags(editor, [HISTORY_MERGE_TAG]) },
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Refresh callbacks created so far, per editor and code node.
|
|
56
|
+
* @type {WeakMap<LexicalEditor, Map<NodeKey, () => void>>}
|
|
57
|
+
*/
|
|
58
|
+
const refreshers = new WeakMap();
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Get a function that refreshes the given code node, to pass to the engine’s loaders as the
|
|
62
|
+
* `onLoaded` callback. The same function is returned for the same node, so the engine calls it once
|
|
63
|
+
* per load, however many keystrokes have asked for that load while it was in flight.
|
|
64
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
65
|
+
* @param {NodeKey} codeNodeKey Key of the code node to refresh.
|
|
66
|
+
* @returns {() => void} Refresh function.
|
|
67
|
+
*/
|
|
68
|
+
export const getCodeNodeRefresher = (editor, codeNodeKey) => {
|
|
69
|
+
let map = refreshers.get(editor);
|
|
70
|
+
|
|
71
|
+
if (!map) {
|
|
72
|
+
map = new Map();
|
|
73
|
+
refreshers.set(editor, map);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let refresher = map.get(codeNodeKey);
|
|
77
|
+
|
|
78
|
+
if (!refresher) {
|
|
79
|
+
/** Refresh the code node. */
|
|
80
|
+
refresher = () => {
|
|
81
|
+
refreshCodeNode(editor, codeNodeKey);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
map.set(codeNodeKey, refresher);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return refresher;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Convert Shiki tokens to Lexical nodes.
|
|
92
|
+
* @param {any[][]} tokens Tokens, one array per line.
|
|
93
|
+
* @param {boolean} diff Whether the language is a `diff-*` language.
|
|
94
|
+
* @returns {LexicalNode[]} Lexical nodes.
|
|
95
|
+
*/
|
|
96
|
+
const mapTokensToLexicalStructure = (tokens, diff) => {
|
|
97
|
+
/** @type {LexicalNode[]} */
|
|
98
|
+
const nodes = [];
|
|
99
|
+
|
|
100
|
+
tokens.forEach((line, lineIndex) => {
|
|
101
|
+
if (lineIndex) {
|
|
102
|
+
nodes.push(createLineBreakNode());
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
line.forEach((token, tokenIndex) => {
|
|
106
|
+
let { content: text } = token;
|
|
107
|
+
|
|
108
|
+
// Implement `diff-*` languages
|
|
109
|
+
if (diff && tokenIndex === 0 && text.length > 0) {
|
|
110
|
+
const prefixes = ['+', '-', '>', '<', ' '];
|
|
111
|
+
const prefixTypes = ['inserted', 'deleted', 'inserted', 'deleted', 'unchanged'];
|
|
112
|
+
const prefixIndex = prefixes.indexOf(text[0]);
|
|
113
|
+
|
|
114
|
+
if (prefixIndex !== -1) {
|
|
115
|
+
nodes.push(createCodeHighlightNode(prefixes[prefixIndex], prefixTypes[prefixIndex]));
|
|
116
|
+
text = text.slice(1);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const style = getTokenStyle(token);
|
|
121
|
+
|
|
122
|
+
tokenizeRawText(text, {
|
|
123
|
+
/**
|
|
124
|
+
* Append a line break node.
|
|
125
|
+
* @returns {number} New node count.
|
|
126
|
+
*/
|
|
127
|
+
linebreak: () => nodes.push(createLineBreakNode()),
|
|
128
|
+
/**
|
|
129
|
+
* Append a tab node.
|
|
130
|
+
* @returns {number} New node count.
|
|
131
|
+
*/
|
|
132
|
+
tab: () => nodes.push(createTabNode()),
|
|
133
|
+
/**
|
|
134
|
+
* Create a highlight node carrying the token’s colour.
|
|
135
|
+
* @param {string} part Text fragment.
|
|
136
|
+
*/
|
|
137
|
+
text: (part) => {
|
|
138
|
+
const node = createCodeHighlightNode(part);
|
|
139
|
+
|
|
140
|
+
node.setStyle(style);
|
|
141
|
+
nodes.push(node);
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
return nodes;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Tokenize a code node’s content into Lexical nodes.
|
|
152
|
+
*
|
|
153
|
+
* Unlike upstream, the theme’s background and foreground colours are not copied onto the code node.
|
|
154
|
+
* The block’s own colours come from `--sui-code-background-color` so that plain and highlighted
|
|
155
|
+
* blocks look alike and follow the app’s theme rather than Shiki’s; only the per-token colours are
|
|
156
|
+
* taken from the theme.
|
|
157
|
+
* @param {CodeNode} codeNode Code node to tokenize.
|
|
158
|
+
* @param {string} language Language identifier.
|
|
159
|
+
* @returns {LexicalNode[]} Lexical nodes.
|
|
160
|
+
*/
|
|
161
|
+
export const getHighlightNodes = (codeNode, language) => {
|
|
162
|
+
const { tokens, diff } = tokenizeCode(codeNode.getTextContent(), language, codeNode.getTheme());
|
|
163
|
+
|
|
164
|
+
return mapTokensToLexicalStructure(tokens, diff);
|
|
165
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { HighlightedToken } from '../../../typedefs.js';
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Maximum length of the Markdown or HTML source to highlight in the plain text mode. The whole
|
|
6
|
+
* source is tokenized on every keystroke, so highlighting a longer one would make typing sluggish.
|
|
7
|
+
*/
|
|
8
|
+
export const MAX_HIGHLIGHT_LENGTH: 20000;
|
|
9
|
+
export function getCodeFenceLanguages(source: string): string[];
|
|
10
|
+
export function createSourceHighlighter({ language, isActive, getSource }: {
|
|
11
|
+
language: "markdown" | "html";
|
|
12
|
+
isActive: () => boolean;
|
|
13
|
+
getSource: () => string;
|
|
14
|
+
}): (source: string) => HighlightedToken[][] | undefined;
|
|
15
|
+
import type { HighlightedToken } from '../../../typedefs.js';
|