@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.
@@ -1,16 +1,12 @@
1
1
  <script>
2
- // Work around the “Prism is not defined” error in consumers
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 = Object.entries(prismComponents.languages)
33
- .filter(([, config]) => 'title' in config)
34
- .map(([key, val]) => {
35
- const { title: label, aliasTitles, alias } = /** @type {Record<string, any>} */ (val);
36
- let aliases = [];
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
- if (editorStore.selection?.blockNodeKey) {
82
- await loadCodeHighlighter(lang);
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.editor.update(() => {
85
- // https://github.com/facebook/lexical/blob/main/packages/lexical-playground/src/plugins/ToolbarPlugin/index.tsx#L713
86
- const node = getNodeByKey(/** @type {string} */ (editorStore.selection.blockNodeKey));
73
+ const node = editorStore.config.isCodeEditor
74
+ ? getRoot().getChildren()[0]
75
+ : blockNodeKey
76
+ ? getNodeByKey(blockNodeKey)
77
+ : null;
87
78
 
88
- if (isCodeNode(node)) {
89
- node.setLanguage(lang);
90
- selectedLanguage = lang;
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
- // Work around the “Prism is not defined” error in consumers
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