@sveltia/ui 0.62.1 → 0.63.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/text-editor/constants.d.ts +0 -1
- package/dist/components/text-editor/constants.js +1 -36
- package/dist/components/text-editor/core.js +24 -31
- package/dist/components/text-editor/lexical-root.svelte +0 -68
- package/dist/components/text-editor/shiki/cache.d.ts +3 -0
- package/dist/components/text-editor/shiki/cache.js +121 -0
- package/dist/components/text-editor/shiki/engine-entry.d.ts +2 -0
- package/dist/components/text-editor/shiki/engine-entry.js +20 -0
- package/dist/components/text-editor/shiki/facade.d.ts +16 -0
- package/dist/components/text-editor/shiki/facade.js +452 -0
- package/dist/components/text-editor/shiki/generated.d.ts +28 -0
- package/dist/components/text-editor/shiki/generated.js +25 -0
- package/dist/components/text-editor/shiki/highlighter.d.ts +11 -0
- package/dist/components/text-editor/shiki/highlighter.js +477 -0
- package/dist/components/text-editor/shiki/loader.d.ts +6 -0
- package/dist/components/text-editor/shiki/loader.js +102 -0
- package/dist/components/text-editor/shiki/theme.d.ts +12 -0
- package/dist/components/text-editor/shiki/theme.js +86 -0
- package/dist/components/text-editor/toolbar/code-language-switcher.svelte +24 -34
- package/dist/components/text-editor/toolbar/toggle-block-menu-item.svelte +1 -5
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/shiki-engine.js +152 -0
- package/dist/typedefs.d.ts +52 -0
- package/dist/typedefs.js +29 -0
- package/package.json +9 -7
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
|
|
3
|
-
// @see https://github.com/remix-run/remix/discussions/8182
|
|
4
|
-
import 'prismjs';
|
|
5
|
-
|
|
6
|
-
import { $isCodeNode as isCodeNode } from '@lexical/code';
|
|
2
|
+
import { $isCodeNode as isCodeNode } from '@lexical/code-core';
|
|
7
3
|
import { _ } from '@sveltia/i18n';
|
|
8
4
|
import { $getNodeByKey as getNodeByKey, $getRoot as getRoot } from 'lexical';
|
|
9
|
-
import prismComponents from 'prismjs/components';
|
|
10
5
|
import { getContext } from 'svelte';
|
|
11
6
|
import Option from '../../listbox/option.svelte';
|
|
12
7
|
import Select from '../../select/select.svelte';
|
|
13
8
|
import { focusEditor, loadCodeHighlighter } from '../core.js';
|
|
9
|
+
import { LANGUAGES } from '../shiki/generated.js';
|
|
14
10
|
|
|
15
11
|
/**
|
|
16
12
|
* @import { TextEditorStore } from '../../../typedefs';
|
|
@@ -29,23 +25,11 @@
|
|
|
29
25
|
} = $props();
|
|
30
26
|
|
|
31
27
|
/** @type {{ key: string, label: string, aliases: string[] }[]} */
|
|
32
|
-
const codeLanguages =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (alias && !aliasTitles) {
|
|
39
|
-
aliases = Array.isArray(alias) ? alias : [alias];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return [
|
|
43
|
-
{ key, label, aliases },
|
|
44
|
-
...Object.entries(aliasTitles ?? {}).map(([k, v]) => ({ key: k, label: v, aliases: [] })),
|
|
45
|
-
];
|
|
46
|
-
})
|
|
47
|
-
.flat(1)
|
|
48
|
-
.sort((a, b) => a.label.localeCompare(b.label));
|
|
28
|
+
const codeLanguages = LANGUAGES.map(({ id, name, aliases = [] }) => ({
|
|
29
|
+
key: id,
|
|
30
|
+
label: name,
|
|
31
|
+
aliases,
|
|
32
|
+
}));
|
|
49
33
|
|
|
50
34
|
/** @type {TextEditorStore} */
|
|
51
35
|
const editorStore = getContext('editorStore');
|
|
@@ -77,20 +61,26 @@
|
|
|
77
61
|
}
|
|
78
62
|
|
|
79
63
|
await focusEditor(editorStore.editor);
|
|
64
|
+
await loadCodeHighlighter(lang);
|
|
80
65
|
|
|
81
|
-
|
|
82
|
-
|
|
66
|
+
editorStore.editor.update(() => {
|
|
67
|
+
// Resolve the target the same way the effect above does. A code editor has exactly one code
|
|
68
|
+
// block, and its `blockNodeKey` is still unset the first time the switcher is used, before
|
|
69
|
+
// the editor has ever been focused.
|
|
70
|
+
// https://github.com/facebook/lexical/blob/main/packages/lexical-playground/src/plugins/ToolbarPlugin/index.tsx#L713
|
|
71
|
+
const { blockNodeKey } = editorStore.selection;
|
|
83
72
|
|
|
84
|
-
editorStore.
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
const node = editorStore.config.isCodeEditor
|
|
74
|
+
? getRoot().getChildren()[0]
|
|
75
|
+
: blockNodeKey
|
|
76
|
+
? getNodeByKey(blockNodeKey)
|
|
77
|
+
: null;
|
|
87
78
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
79
|
+
if (isCodeNode(node)) {
|
|
80
|
+
node.setLanguage(lang);
|
|
81
|
+
selectedLanguage = lang;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
94
84
|
}}
|
|
95
85
|
>
|
|
96
86
|
<Option label={_('_sui.text_editor.plain_text')} value="plain" dir="ltr" />
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
|
|
3
|
-
// @see https://github.com/remix-run/remix/discussions/8182
|
|
4
|
-
import 'prismjs';
|
|
5
|
-
|
|
6
|
-
import { $createCodeNode as createCodeNode } from '@lexical/code';
|
|
2
|
+
import { $createCodeNode as createCodeNode } from '@lexical/code-core';
|
|
7
3
|
import { INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND } from '@lexical/list';
|
|
8
4
|
import {
|
|
9
5
|
$createHeadingNode as createHeadingNode,
|
package/dist/index.d.ts
CHANGED
|
@@ -81,5 +81,9 @@ export { default as Group } from "./components/util/group.svelte";
|
|
|
81
81
|
export { default as Modal } from "./components/util/modal.svelte";
|
|
82
82
|
export { default as Placeholder } from "./components/util/placeholder.svelte";
|
|
83
83
|
export { default as VisibilityObserver } from "./components/util/visibility-observer.svelte";
|
|
84
|
+
export { loadCodeHighlighter } from "./components/text-editor/core.js";
|
|
85
|
+
export { setCodeHighlighterCacheEnabled } from "./components/text-editor/shiki/cache.js";
|
|
86
|
+
export { highlightCodeToHTML } from "./components/text-editor/shiki/facade.js";
|
|
87
|
+
export { setCodeHighlighterLoaders } from "./components/text-editor/shiki/loader.js";
|
|
84
88
|
export * from "./typedefs.js";
|
|
85
89
|
export { initLocales, strings } from "./services/i18n.js";
|
package/dist/index.js
CHANGED
|
@@ -81,6 +81,10 @@ export { default as Group } from './components/util/group.svelte';
|
|
|
81
81
|
export { default as Modal } from './components/util/modal.svelte';
|
|
82
82
|
export { default as Placeholder } from './components/util/placeholder.svelte';
|
|
83
83
|
export { default as VisibilityObserver } from './components/util/visibility-observer.svelte';
|
|
84
|
+
export { loadCodeHighlighter } from './components/text-editor/core.js';
|
|
85
|
+
export { setCodeHighlighterCacheEnabled } from './components/text-editor/shiki/cache.js';
|
|
86
|
+
export { highlightCodeToHTML } from './components/text-editor/shiki/facade.js';
|
|
87
|
+
export { setCodeHighlighterLoaders } from './components/text-editor/shiki/loader.js';
|
|
84
88
|
export { initLocales, strings } from './services/i18n.js';
|
|
85
89
|
|
|
86
90
|
// eslint-disable-next-line import/export
|