@sveltia/ui 0.25.7 → 0.25.9
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/alert/alert.svelte +7 -3
- package/dist/components/alert/alert.svelte.d.ts +11 -10
- package/dist/components/alert/infobar.svelte +9 -5
- package/dist/components/alert/infobar.svelte.d.ts +15 -14
- package/dist/components/button/button-group.svelte +6 -2
- package/dist/components/button/button-group.svelte.d.ts +7 -6
- package/dist/components/button/button.svelte +5 -2
- package/dist/components/button/button.svelte.d.ts +2 -1
- package/dist/components/button/select-button-group.svelte +12 -8
- package/dist/components/button/select-button-group.svelte.d.ts +19 -18
- package/dist/components/button/select-button.svelte +6 -3
- package/dist/components/button/select-button.svelte.d.ts +4 -3
- package/dist/components/button/split-button.svelte +10 -7
- package/dist/components/button/split-button.svelte.d.ts +18 -17
- package/dist/components/calendar/calendar.svelte +1 -1
- package/dist/components/calendar/calendar.svelte.d.ts +2 -2
- package/dist/components/checkbox/checkbox-group.svelte +9 -5
- package/dist/components/checkbox/checkbox-group.svelte.d.ts +13 -12
- package/dist/components/checkbox/checkbox.svelte +13 -9
- package/dist/components/checkbox/checkbox.svelte.d.ts +19 -17
- package/dist/components/dialog/alert-dialog.svelte +5 -2
- package/dist/components/dialog/alert-dialog.svelte.d.ts +3 -1
- package/dist/components/dialog/confirmation-dialog.svelte +5 -2
- package/dist/components/dialog/confirmation-dialog.svelte.d.ts +3 -1
- package/dist/components/dialog/dialog.svelte +5 -2
- package/dist/components/dialog/dialog.svelte.d.ts +3 -1
- package/dist/components/dialog/prompt-dialog.svelte +16 -7
- package/dist/components/dialog/prompt-dialog.svelte.d.ts +17 -13
- package/dist/components/disclosure/disclosure.svelte +12 -8
- package/dist/components/disclosure/disclosure.svelte.d.ts +21 -20
- package/dist/components/divider/divider.svelte +3 -3
- package/dist/components/divider/divider.svelte.d.ts +6 -6
- package/dist/components/divider/spacer.svelte +2 -2
- package/dist/components/divider/spacer.svelte.d.ts +4 -4
- package/dist/components/drawer/drawer.svelte +18 -13
- package/dist/components/drawer/drawer.svelte.d.ts +39 -37
- package/dist/components/grid/grid-body.svelte +7 -3
- package/dist/components/grid/grid-body.svelte.d.ts +9 -8
- package/dist/components/grid/grid-cell.svelte +6 -2
- package/dist/components/grid/grid-cell.svelte.d.ts +7 -6
- package/dist/components/grid/grid-col-header.svelte +6 -2
- package/dist/components/grid/grid-col-header.svelte.d.ts +7 -6
- package/dist/components/grid/grid-foot.svelte +6 -2
- package/dist/components/grid/grid-foot.svelte.d.ts +7 -6
- package/dist/components/grid/grid-head.svelte +6 -2
- package/dist/components/grid/grid-head.svelte.d.ts +7 -6
- package/dist/components/grid/grid-row-header.svelte +6 -2
- package/dist/components/grid/grid-row-header.svelte.d.ts +7 -6
- package/dist/components/grid/grid-row.svelte +9 -5
- package/dist/components/grid/grid-row.svelte.d.ts +13 -12
- package/dist/components/grid/grid.svelte +10 -6
- package/dist/components/grid/grid.svelte.d.ts +15 -14
- package/dist/components/icon/icon.svelte +2 -2
- package/dist/components/icon/icon.svelte.d.ts +4 -4
- package/dist/components/listbox/listbox.svelte +18 -13
- package/dist/components/listbox/listbox.svelte.d.ts +27 -26
- package/dist/components/listbox/option-group.svelte +9 -5
- package/dist/components/listbox/option-group.svelte.d.ts +13 -12
- package/dist/components/listbox/option.svelte +12 -8
- package/dist/components/listbox/option.svelte.d.ts +17 -15
- package/dist/components/menu/menu-button.svelte +7 -4
- package/dist/components/menu/menu-button.svelte.d.ts +6 -5
- package/dist/components/menu/menu-item-checkbox.svelte +5 -2
- package/dist/components/menu/menu-item-checkbox.svelte.d.ts +3 -1
- package/dist/components/menu/menu-item-group.svelte +9 -5
- package/dist/components/menu/menu-item-group.svelte.d.ts +8 -8
- package/dist/components/menu/menu-item-radio.svelte +5 -2
- package/dist/components/menu/menu-item-radio.svelte.d.ts +3 -1
- package/dist/components/menu/menu-item.svelte +5 -2
- package/dist/components/menu/menu-item.svelte.d.ts +3 -1
- package/dist/components/menu/menu.svelte +9 -5
- package/dist/components/menu/menu.svelte.d.ts +13 -12
- package/dist/components/progressbar/progressbar.svelte +5 -5
- package/dist/components/progressbar/progressbar.svelte.d.ts +10 -10
- package/dist/components/radio/radio-group.svelte +13 -9
- package/dist/components/radio/radio-group.svelte.d.ts +21 -20
- package/dist/components/radio/radio.svelte +15 -11
- package/dist/components/radio/radio.svelte.d.ts +27 -26
- package/dist/components/select/combobox.svelte +6 -3
- package/dist/components/select/combobox.svelte.d.ts +3 -1
- package/dist/components/select/select-tags.svelte +16 -13
- package/dist/components/select/select-tags.svelte.d.ts +27 -28
- package/dist/components/select/select.svelte +5 -1
- package/dist/components/select/select.svelte.d.ts +2 -1
- package/dist/components/slider/slider.svelte +27 -25
- package/dist/components/slider/slider.svelte.d.ts +35 -34
- package/dist/components/switch/switch.svelte +13 -9
- package/dist/components/switch/switch.svelte.d.ts +21 -20
- package/dist/components/table/table-body.svelte +7 -3
- package/dist/components/table/table-body.svelte.d.ts +9 -8
- package/dist/components/table/table-cell.svelte +6 -2
- package/dist/components/table/table-cell.svelte.d.ts +7 -6
- package/dist/components/table/table-col-header.svelte +6 -2
- package/dist/components/table/table-col-header.svelte.d.ts +7 -6
- package/dist/components/table/table-foot.svelte +6 -2
- package/dist/components/table/table-foot.svelte.d.ts +7 -6
- package/dist/components/table/table-head.svelte +6 -2
- package/dist/components/table/table-head.svelte.d.ts +7 -6
- package/dist/components/table/table-row-header.svelte +6 -2
- package/dist/components/table/table-row-header.svelte.d.ts +7 -6
- package/dist/components/table/table-row.svelte +6 -2
- package/dist/components/table/table-row.svelte.d.ts +7 -6
- package/dist/components/table/table.svelte +6 -2
- package/dist/components/table/table.svelte.d.ts +7 -6
- package/dist/components/tabs/tab-box.svelte +7 -3
- package/dist/components/tabs/tab-box.svelte.d.ts +9 -8
- package/dist/components/tabs/tab-list.svelte +12 -8
- package/dist/components/tabs/tab-list.svelte.d.ts +19 -18
- package/dist/components/tabs/tab-panel.svelte +6 -2
- package/dist/components/tabs/tab-panel.svelte.d.ts +7 -6
- package/dist/components/tabs/tab-panels.svelte +6 -2
- package/dist/components/tabs/tab-panels.svelte.d.ts +7 -6
- package/dist/components/tabs/tab.svelte +6 -3
- package/dist/components/tabs/tab.svelte.d.ts +4 -3
- package/dist/components/text-editor/code-editor.svelte +16 -18
- package/dist/components/text-editor/code-editor.svelte.d.ts +25 -24
- package/dist/components/text-editor/core.d.ts +5 -3
- package/dist/components/text-editor/core.js +26 -15
- package/dist/components/text-editor/index.d.ts +12 -6
- package/dist/components/text-editor/index.js +7 -3
- package/dist/components/text-editor/lexical-root.svelte +27 -30
- package/dist/components/text-editor/lexical-root.svelte.d.ts +17 -16
- package/dist/components/text-editor/store.svelte.d.ts +2 -1
- package/dist/components/text-editor/store.svelte.js +10 -5
- package/dist/components/text-editor/text-editor.svelte +22 -13
- package/dist/components/text-editor/text-editor.svelte.d.ts +37 -32
- package/dist/components/text-editor/toolbar/code-editor-toolbar.svelte +3 -3
- package/dist/components/text-editor/toolbar/code-editor-toolbar.svelte.d.ts +6 -6
- package/dist/components/text-editor/toolbar/code-language-switcher.svelte +6 -2
- package/dist/components/text-editor/toolbar/code-language-switcher.svelte.d.ts +2 -2
- package/dist/components/text-editor/toolbar/format-text-button.svelte +6 -2
- package/dist/components/text-editor/toolbar/format-text-button.svelte.d.ts +5 -4
- package/dist/components/text-editor/toolbar/insert-image-button.svelte +6 -2
- package/dist/components/text-editor/toolbar/insert-image-button.svelte.d.ts +5 -4
- package/dist/components/text-editor/toolbar/insert-link-button.svelte +9 -4
- package/dist/components/text-editor/toolbar/insert-menu-button.svelte +6 -2
- package/dist/components/text-editor/toolbar/insert-menu-button.svelte.d.ts +5 -4
- package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte +10 -6
- package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte.d.ts +6 -6
- package/dist/components/text-editor/toolbar/toggle-block-menu-item.svelte +8 -5
- package/dist/components/text-editor/toolbar/toggle-block-menu-item.svelte.d.ts +5 -4
- package/dist/components/text-editor/toolbar/toolbar-wrapper.svelte +7 -3
- package/dist/components/text-editor/toolbar/toolbar-wrapper.svelte.d.ts +9 -8
- package/dist/components/text-editor/transformers/table.d.ts +3 -2
- package/dist/components/text-editor/transformers/table.js +5 -1
- package/dist/components/text-field/number-input.svelte +12 -8
- package/dist/components/text-field/number-input.svelte.d.ts +20 -17
- package/dist/components/text-field/password-input.svelte +8 -4
- package/dist/components/text-field/password-input.svelte.d.ts +10 -7
- package/dist/components/text-field/search-bar.svelte +9 -5
- package/dist/components/text-field/search-bar.svelte.d.ts +14 -11
- package/dist/components/text-field/text-area.svelte +18 -14
- package/dist/components/text-field/text-area.svelte.d.ts +29 -27
- package/dist/components/text-field/text-input.svelte +7 -3
- package/dist/components/text-field/text-input.svelte.d.ts +5 -3
- package/dist/components/toast/toast.svelte +10 -5
- package/dist/components/toast/toast.svelte.d.ts +16 -14
- package/dist/components/toolbar/toolbar.svelte +11 -7
- package/dist/components/toolbar/toolbar.svelte.d.ts +17 -16
- package/dist/components/util/app-shell.svelte +6 -3
- package/dist/components/util/app-shell.svelte.d.ts +7 -8
- package/dist/components/util/group.svelte +8 -4
- package/dist/components/util/group.svelte.d.ts +11 -10
- package/dist/components/util/modal.svelte +7 -3
- package/dist/components/util/modal.svelte.d.ts +2 -1
- package/dist/components/util/placeholder.svelte +5 -1
- package/dist/components/util/placeholder.svelte.d.ts +5 -4
- package/dist/components/util/popup.svelte +23 -17
- package/dist/components/util/popup.svelte.d.ts +36 -33
- package/dist/index.js +3 -3
- package/dist/services/events.svelte.d.ts +2 -1
- package/dist/services/events.svelte.js +12 -8
- package/dist/services/group.svelte.d.ts +2 -1
- package/dist/services/group.svelte.js +16 -12
- package/dist/services/popup.svelte.d.ts +16 -10
- package/dist/services/popup.svelte.js +14 -13
- package/dist/typedefs.d.ts +191 -189
- package/dist/typedefs.js +168 -164
- package/package.json +18 -18
|
@@ -6,101 +6,102 @@ type CodeEditor = {
|
|
|
6
6
|
/** A code editor based on Lexical. */
|
|
7
7
|
declare const CodeEditor: import("svelte").Component<{
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Input value.
|
|
10
10
|
*/
|
|
11
11
|
code?: string | undefined;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Selected language.
|
|
14
14
|
*/
|
|
15
15
|
lang?: string | undefined;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Whether to show the language selector.
|
|
18
18
|
*/
|
|
19
19
|
showLanguageSwitcher?: boolean | undefined;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* Make the text input container flexible.
|
|
22
22
|
*/
|
|
23
23
|
flex?: boolean | undefined;
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* The `class` attribute on the wrapper element.
|
|
26
26
|
*/
|
|
27
27
|
class?: string | undefined;
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* Whether to hide the widget.
|
|
30
30
|
*/
|
|
31
31
|
hidden?: boolean | undefined;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
34
34
|
* attribute.
|
|
35
35
|
*/
|
|
36
36
|
disabled?: boolean | undefined;
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* Whether to make the widget read-only. An alias of the
|
|
39
39
|
* `aria-readonly` attribute.
|
|
40
40
|
*/
|
|
41
41
|
readonly?: boolean | undefined;
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Whether to mark the widget required. An alias of the
|
|
44
44
|
* `aria-required` attribute.
|
|
45
45
|
*/
|
|
46
46
|
required?: boolean | undefined;
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
48
|
+
* Whether to mark the widget invalid. An alias of the
|
|
49
49
|
* `aria-invalid` attribute.
|
|
50
50
|
*/
|
|
51
51
|
invalid?: boolean | undefined;
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
53
|
+
* Primary slot content.
|
|
54
54
|
*/
|
|
55
|
-
children?:
|
|
55
|
+
children?: Snippet<[]> | undefined;
|
|
56
56
|
} & Record<string, any>, {}, "code" | "lang">;
|
|
57
57
|
type Props = {
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
59
|
+
* Input value.
|
|
60
60
|
*/
|
|
61
61
|
code?: string | undefined;
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* Selected language.
|
|
64
64
|
*/
|
|
65
65
|
lang?: string | undefined;
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
67
|
+
* Whether to show the language selector.
|
|
68
68
|
*/
|
|
69
69
|
showLanguageSwitcher?: boolean | undefined;
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
71
|
+
* Make the text input container flexible.
|
|
72
72
|
*/
|
|
73
73
|
flex?: boolean | undefined;
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
75
|
+
* The `class` attribute on the wrapper element.
|
|
76
76
|
*/
|
|
77
77
|
class?: string | undefined;
|
|
78
78
|
/**
|
|
79
|
-
*
|
|
79
|
+
* Whether to hide the widget.
|
|
80
80
|
*/
|
|
81
81
|
hidden?: boolean | undefined;
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
83
|
+
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
84
84
|
* attribute.
|
|
85
85
|
*/
|
|
86
86
|
disabled?: boolean | undefined;
|
|
87
87
|
/**
|
|
88
|
-
*
|
|
88
|
+
* Whether to make the widget read-only. An alias of the
|
|
89
89
|
* `aria-readonly` attribute.
|
|
90
90
|
*/
|
|
91
91
|
readonly?: boolean | undefined;
|
|
92
92
|
/**
|
|
93
|
-
*
|
|
93
|
+
* Whether to mark the widget required. An alias of the
|
|
94
94
|
* `aria-required` attribute.
|
|
95
95
|
*/
|
|
96
96
|
required?: boolean | undefined;
|
|
97
97
|
/**
|
|
98
|
-
*
|
|
98
|
+
* Whether to mark the widget invalid. An alias of the
|
|
99
99
|
* `aria-invalid` attribute.
|
|
100
100
|
*/
|
|
101
101
|
invalid?: boolean | undefined;
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
103
|
+
* Primary slot content.
|
|
104
104
|
*/
|
|
105
|
-
children?:
|
|
105
|
+
children?: Snippet<[]> | undefined;
|
|
106
106
|
};
|
|
107
|
+
import type { Snippet } from 'svelte';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export function initEditor({ components, isCodeEditor, defaultLanguage }:
|
|
1
|
+
export function initEditor({ components, isCodeEditor, defaultLanguage }: TextEditorConfig): LexicalEditor;
|
|
2
2
|
export function loadCodeHighlighter(lang: string): Promise<void>;
|
|
3
|
-
export function convertMarkdownToLexical(editor:
|
|
4
|
-
export function focusEditor(editor:
|
|
3
|
+
export function convertMarkdownToLexical(editor: LexicalEditor, value: string): Promise<void>;
|
|
4
|
+
export function focusEditor(editor: LexicalEditor): Promise<void>;
|
|
5
|
+
import type { TextEditorConfig } from '../../typedefs';
|
|
6
|
+
import type { LexicalEditor } from 'lexical';
|
|
@@ -52,13 +52,26 @@ import {
|
|
|
52
52
|
} from 'lexical';
|
|
53
53
|
import prismComponents from 'prismjs/components';
|
|
54
54
|
import { blockButtonTypes, textFormatButtonTypes } from '.';
|
|
55
|
+
import { dependencies } from '../../../../package.json';
|
|
55
56
|
import { TABLE } from './transformers/table';
|
|
56
57
|
|
|
58
|
+
/**
|
|
59
|
+
* @import { CreateEditorArgs, LexicalEditor } from 'lexical';
|
|
60
|
+
* @import {
|
|
61
|
+
* TextEditorBlockType,
|
|
62
|
+
* TextEditorConfig,
|
|
63
|
+
* TextEditorInlineType,
|
|
64
|
+
* TextEditorSelectionState,
|
|
65
|
+
* } from '../../typedefs';
|
|
66
|
+
*/
|
|
67
|
+
|
|
57
68
|
const allTransformers = [...TRANSFORMERS, TABLE];
|
|
69
|
+
const prismVersion = dependencies.prismjs.replace(/^\D/, '');
|
|
70
|
+
const prismBaseURL = `https://unpkg.com/prismjs@${prismVersion}`;
|
|
58
71
|
|
|
59
72
|
/**
|
|
60
73
|
* Lexical editor configuration.
|
|
61
|
-
* @type {
|
|
74
|
+
* @type {CreateEditorArgs}
|
|
62
75
|
*/
|
|
63
76
|
const editorConfig = {
|
|
64
77
|
namespace: 'editor',
|
|
@@ -126,7 +139,7 @@ const editorConfig = {
|
|
|
126
139
|
|
|
127
140
|
/**
|
|
128
141
|
* Get the current selection’s block node key as well as block and inline level types.
|
|
129
|
-
* @returns {
|
|
142
|
+
* @returns {TextEditorSelectionState} Current selection state.
|
|
130
143
|
*/
|
|
131
144
|
const getSelectionTypes = () => {
|
|
132
145
|
const selection = getSelection();
|
|
@@ -142,7 +155,7 @@ const getSelectionTypes = () => {
|
|
|
142
155
|
const anchor = selection.anchor.getNode();
|
|
143
156
|
/** @type {ElementNode | null} */
|
|
144
157
|
let parent = null;
|
|
145
|
-
/** @type {
|
|
158
|
+
/** @type {TextEditorInlineType[]} */
|
|
146
159
|
const inlineTypes = textFormatButtonTypes.filter((type) => selection.hasFormat(type));
|
|
147
160
|
|
|
148
161
|
if (anchor.getType() !== 'root') {
|
|
@@ -158,7 +171,7 @@ const getSelectionTypes = () => {
|
|
|
158
171
|
}
|
|
159
172
|
}
|
|
160
173
|
|
|
161
|
-
const blockType = /** @type {
|
|
174
|
+
const blockType = /** @type {TextEditorBlockType} */ (
|
|
162
175
|
(() => {
|
|
163
176
|
if (!parent) {
|
|
164
177
|
return 'paragraph';
|
|
@@ -199,7 +212,7 @@ const getSelectionTypes = () => {
|
|
|
199
212
|
|
|
200
213
|
/**
|
|
201
214
|
* Listen to changes made on the editor and trigger the Update event.
|
|
202
|
-
* @param {
|
|
215
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
203
216
|
*/
|
|
204
217
|
const onEditorUpdate = (editor) => {
|
|
205
218
|
editor.getRootElement()?.dispatchEvent(
|
|
@@ -217,8 +230,8 @@ const onEditorUpdate = (editor) => {
|
|
|
217
230
|
|
|
218
231
|
/**
|
|
219
232
|
* Initialize the Lexical editor.
|
|
220
|
-
* @param {
|
|
221
|
-
* @returns {
|
|
233
|
+
* @param {TextEditorConfig} config Editor configuration.
|
|
234
|
+
* @returns {LexicalEditor} Editor instance.
|
|
222
235
|
*/
|
|
223
236
|
export const initEditor = ({ components = [], isCodeEditor = false, defaultLanguage = '' }) => {
|
|
224
237
|
components.forEach(({ node, transformer }) => {
|
|
@@ -343,7 +356,7 @@ export const initEditor = ({ components = [], isCodeEditor = false, defaultLangu
|
|
|
343
356
|
|
|
344
357
|
/**
|
|
345
358
|
* Load additional Prism syntax highlighter settings for the given programming language.
|
|
346
|
-
* @param {string} lang
|
|
359
|
+
* @param {string} lang Language name, like scss.
|
|
347
360
|
*/
|
|
348
361
|
export const loadCodeHighlighter = async (lang) => {
|
|
349
362
|
if (lang in window.Prism.languages) {
|
|
@@ -361,10 +374,8 @@ export const loadCodeHighlighter = async (lang) => {
|
|
|
361
374
|
}
|
|
362
375
|
|
|
363
376
|
try {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
/* @vite-ignore */ `https://unpkg.com/prismjs@1.29.0/components/prism-${canonicalLang}.min.js`
|
|
367
|
-
);
|
|
377
|
+
// eslint-disable-next-line jsdoc/no-bad-blocks
|
|
378
|
+
await import(/* @vite-ignore */ `${prismBaseURL}/components/prism-${canonicalLang}.min.js`);
|
|
368
379
|
} catch {
|
|
369
380
|
//
|
|
370
381
|
}
|
|
@@ -372,8 +383,8 @@ export const loadCodeHighlighter = async (lang) => {
|
|
|
372
383
|
|
|
373
384
|
/**
|
|
374
385
|
* Convert Markdown to Lexical nodes.
|
|
375
|
-
* @param {
|
|
376
|
-
* @param {string} value
|
|
386
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
387
|
+
* @param {string} value Current Markdown value.
|
|
377
388
|
* @returns {Promise<void>} Nothing.
|
|
378
389
|
* @throws {Error} Failed to convert the value to Lexical nodes.
|
|
379
390
|
*/
|
|
@@ -399,7 +410,7 @@ export const convertMarkdownToLexical = async (editor, value) => {
|
|
|
399
410
|
|
|
400
411
|
/**
|
|
401
412
|
* Move focus to the editor so the user can start editing immediately.
|
|
402
|
-
* @param {
|
|
413
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
403
414
|
* @returns {Promise<void>} Nothing.
|
|
404
415
|
*/
|
|
405
416
|
export const focusEditor = async (editor) => {
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { TextEditorBlockType, TextEditorFormatType, TextEditorInlineType } from '../../typedefs';
|
|
3
|
+
*/
|
|
1
4
|
/**
|
|
2
5
|
* List of available buttons.
|
|
3
6
|
* @type {{ [key: string]: { labelKey: string, icon: string, inline: boolean } }}
|
|
@@ -10,14 +13,17 @@ export const availableButtons: {
|
|
|
10
13
|
};
|
|
11
14
|
};
|
|
12
15
|
/**
|
|
13
|
-
* @type {
|
|
16
|
+
* @type {TextEditorFormatType[]}
|
|
14
17
|
*/
|
|
15
|
-
export const textFormatButtonTypes:
|
|
18
|
+
export const textFormatButtonTypes: TextEditorFormatType[];
|
|
16
19
|
/**
|
|
17
|
-
* @type {
|
|
20
|
+
* @type {TextEditorInlineType[]}
|
|
18
21
|
*/
|
|
19
|
-
export const inlineButtonTypes:
|
|
22
|
+
export const inlineButtonTypes: TextEditorInlineType[];
|
|
20
23
|
/**
|
|
21
|
-
* @type {
|
|
24
|
+
* @type {TextEditorBlockType[]}
|
|
22
25
|
*/
|
|
23
|
-
export const blockButtonTypes:
|
|
26
|
+
export const blockButtonTypes: TextEditorBlockType[];
|
|
27
|
+
import type { TextEditorFormatType } from '../../typedefs';
|
|
28
|
+
import type { TextEditorInlineType } from '../../typedefs';
|
|
29
|
+
import type { TextEditorBlockType } from '../../typedefs';
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { TextEditorBlockType, TextEditorFormatType, TextEditorInlineType } from '../../typedefs';
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* List of available buttons.
|
|
3
7
|
* @type {{ [key: string]: { labelKey: string, icon: string, inline: boolean } }}
|
|
@@ -80,15 +84,15 @@ export const availableButtons = {
|
|
|
80
84
|
},
|
|
81
85
|
};
|
|
82
86
|
/**
|
|
83
|
-
* @type {
|
|
87
|
+
* @type {TextEditorFormatType[]}
|
|
84
88
|
*/
|
|
85
89
|
export const textFormatButtonTypes = ['bold', 'italic', 'code'];
|
|
86
90
|
/**
|
|
87
|
-
* @type {
|
|
91
|
+
* @type {TextEditorInlineType[]}
|
|
88
92
|
*/
|
|
89
93
|
export const inlineButtonTypes = [...textFormatButtonTypes, 'link'];
|
|
90
94
|
/**
|
|
91
|
-
* @type {
|
|
95
|
+
* @type {TextEditorBlockType[]}
|
|
92
96
|
*/
|
|
93
97
|
export const blockButtonTypes = [
|
|
94
98
|
'paragraph',
|
|
@@ -2,19 +2,24 @@
|
|
|
2
2
|
import { getContext, onMount } from 'svelte';
|
|
3
3
|
import { initEditor } from './core';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @import { Snippet } from 'svelte';
|
|
7
|
+
* @import { TextEditorStore } from '../../typedefs';
|
|
8
|
+
*/
|
|
9
|
+
|
|
5
10
|
/**
|
|
6
11
|
* @typedef {object} Props
|
|
7
|
-
* @property {string} [class]
|
|
8
|
-
* @property {boolean} [hidden]
|
|
9
|
-
* @property {boolean} [disabled]
|
|
12
|
+
* @property {string} [class] The `class` attribute on the wrapper element.
|
|
13
|
+
* @property {boolean} [hidden] Whether to hide the widget.
|
|
14
|
+
* @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
|
|
10
15
|
* attribute.
|
|
11
|
-
* @property {boolean} [readonly]
|
|
16
|
+
* @property {boolean} [readonly] Whether to make the widget read-only. An alias of the
|
|
12
17
|
* `aria-readonly` attribute.
|
|
13
|
-
* @property {boolean} [required]
|
|
18
|
+
* @property {boolean} [required] Whether to mark the widget required. An alias of the
|
|
14
19
|
* `aria-required` attribute.
|
|
15
|
-
* @property {boolean} [invalid]
|
|
20
|
+
* @property {boolean} [invalid] Whether to mark the widget invalid. An alias of the
|
|
16
21
|
* `aria-invalid` attribute.
|
|
17
|
-
* @property {
|
|
22
|
+
* @property {Snippet} [children] Primary slot content.
|
|
18
23
|
*/
|
|
19
24
|
|
|
20
25
|
/**
|
|
@@ -33,7 +38,7 @@
|
|
|
33
38
|
/* eslint-enable prefer-const */
|
|
34
39
|
} = $props();
|
|
35
40
|
|
|
36
|
-
/** @type {
|
|
41
|
+
/** @type {TextEditorStore} */
|
|
37
42
|
const editorStore = getContext('editorStore');
|
|
38
43
|
|
|
39
44
|
/**
|
|
@@ -50,39 +55,31 @@
|
|
|
50
55
|
|
|
51
56
|
/**
|
|
52
57
|
* Update {@link value} and other state variables whenever the editor content is updated.
|
|
53
|
-
* @param {Event} event
|
|
58
|
+
* @param {Event} event `Update` custom event.
|
|
54
59
|
*/
|
|
55
60
|
const onUpdate = (event) => {
|
|
56
|
-
|
|
61
|
+
const { hasConverterError, useRichText, inputValue } = editorStore;
|
|
62
|
+
|
|
63
|
+
if (hasConverterError || !useRichText) {
|
|
57
64
|
return;
|
|
58
65
|
}
|
|
59
66
|
|
|
60
|
-
const {
|
|
61
|
-
const newValue = detail.value;
|
|
62
|
-
|
|
63
|
-
if (editorStore.inputValue !== newValue) {
|
|
64
|
-
const { useRichText } = editorStore;
|
|
65
|
-
|
|
66
|
-
if (useRichText) {
|
|
67
|
-
// Temporarily disable rich text to prevent unnecessary Markdown conversion that resets
|
|
68
|
-
// Lexical nodes and selection
|
|
69
|
-
editorStore.useRichText = false;
|
|
70
|
-
}
|
|
67
|
+
const { value: newValue, selection } = /** @type {CustomEvent} */ (event).detail;
|
|
71
68
|
|
|
69
|
+
if (inputValue !== newValue) {
|
|
70
|
+
// Temporarily disable rich text to prevent unnecessary Markdown conversion that resets
|
|
71
|
+
// Lexical nodes and selection, then restore the state
|
|
72
|
+
editorStore.useRichText = false;
|
|
72
73
|
editorStore.inputValue = newValue;
|
|
73
|
-
|
|
74
|
-
if (useRichText) {
|
|
75
|
-
// Restore the rich text state
|
|
76
|
-
editorStore.useRichText = true;
|
|
77
|
-
}
|
|
74
|
+
editorStore.useRichText = true;
|
|
78
75
|
}
|
|
79
76
|
|
|
80
|
-
editorStore.selection =
|
|
77
|
+
editorStore.selection = selection;
|
|
81
78
|
};
|
|
82
79
|
|
|
83
80
|
/**
|
|
84
81
|
* Listen to `click` events on the editor. Ignore a click on a link.
|
|
85
|
-
* @param {MouseEvent} event
|
|
82
|
+
* @param {MouseEvent} event `click` event.
|
|
86
83
|
*/
|
|
87
84
|
const onClick = (event) => {
|
|
88
85
|
if (/** @type {HTMLElement} */ (event.target)?.matches('a')) {
|
|
@@ -156,10 +153,10 @@
|
|
|
156
153
|
.lexical-root[aria-invalid=true] {
|
|
157
154
|
border-color: var(--sui-error-border-color);
|
|
158
155
|
}
|
|
159
|
-
.lexical-root
|
|
156
|
+
.lexical-root :global(:first-child) {
|
|
160
157
|
margin-top: 0;
|
|
161
158
|
}
|
|
162
|
-
.lexical-root
|
|
159
|
+
.lexical-root :global(:last-child) {
|
|
163
160
|
margin-bottom: 0;
|
|
164
161
|
}
|
|
165
162
|
.lexical-root :global(strong.italic) {
|
|
@@ -5,69 +5,70 @@ type LexicalRoot = {
|
|
|
5
5
|
};
|
|
6
6
|
declare const LexicalRoot: import("svelte").Component<{
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* The `class` attribute on the wrapper element.
|
|
9
9
|
*/
|
|
10
10
|
class?: string | undefined;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Whether to hide the widget.
|
|
13
13
|
*/
|
|
14
14
|
hidden?: boolean | undefined;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
17
17
|
* attribute.
|
|
18
18
|
*/
|
|
19
19
|
disabled?: boolean | undefined;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* Whether to make the widget read-only. An alias of the
|
|
22
22
|
* `aria-readonly` attribute.
|
|
23
23
|
*/
|
|
24
24
|
readonly?: boolean | undefined;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Whether to mark the widget required. An alias of the
|
|
27
27
|
* `aria-required` attribute.
|
|
28
28
|
*/
|
|
29
29
|
required?: boolean | undefined;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Whether to mark the widget invalid. An alias of the
|
|
32
32
|
* `aria-invalid` attribute.
|
|
33
33
|
*/
|
|
34
34
|
invalid?: boolean | undefined;
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* Primary slot content.
|
|
37
37
|
*/
|
|
38
|
-
children?:
|
|
38
|
+
children?: Snippet<[]> | undefined;
|
|
39
39
|
} & Record<string, any>, {}, "">;
|
|
40
40
|
type Props = {
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* The `class` attribute on the wrapper element.
|
|
43
43
|
*/
|
|
44
44
|
class?: string | undefined;
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
46
|
+
* Whether to hide the widget.
|
|
47
47
|
*/
|
|
48
48
|
hidden?: boolean | undefined;
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
51
51
|
* attribute.
|
|
52
52
|
*/
|
|
53
53
|
disabled?: boolean | undefined;
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
55
|
+
* Whether to make the widget read-only. An alias of the
|
|
56
56
|
* `aria-readonly` attribute.
|
|
57
57
|
*/
|
|
58
58
|
readonly?: boolean | undefined;
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
60
|
+
* Whether to mark the widget required. An alias of the
|
|
61
61
|
* `aria-required` attribute.
|
|
62
62
|
*/
|
|
63
63
|
required?: boolean | undefined;
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
65
|
+
* Whether to mark the widget invalid. An alias of the
|
|
66
66
|
* `aria-invalid` attribute.
|
|
67
67
|
*/
|
|
68
68
|
invalid?: boolean | undefined;
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* Primary slot content.
|
|
71
71
|
*/
|
|
72
|
-
children?:
|
|
72
|
+
children?: Snippet<[]> | undefined;
|
|
73
73
|
};
|
|
74
|
+
import type { Snippet } from 'svelte';
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export function createEditorStore():
|
|
1
|
+
export function createEditorStore(): TextEditorStore;
|
|
2
|
+
import type { TextEditorStore } from '../../typedefs';
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import { generateElementId } from '@sveltia/utils/element';
|
|
2
2
|
import { convertMarkdownToLexical } from './core';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @import { TextEditorConfig, TextEditorSelectionState, TextEditorStore } from '../../typedefs';
|
|
6
|
+
* @import { LexicalEditor } from 'lexical';
|
|
7
|
+
*/
|
|
8
|
+
|
|
4
9
|
/**
|
|
5
10
|
* Create an editor editor store that contains all the states and configuration.
|
|
6
|
-
* @returns {
|
|
11
|
+
* @returns {TextEditorStore} Store.
|
|
7
12
|
*/
|
|
8
13
|
export const createEditorStore = () => {
|
|
9
14
|
/** @type {string} */
|
|
10
15
|
const editorId = generateElementId('editor');
|
|
11
16
|
/** @type {boolean} */
|
|
12
17
|
let initialized = $state(false);
|
|
13
|
-
/** @type {
|
|
18
|
+
/** @type {LexicalEditor | undefined} */
|
|
14
19
|
let editor = $state();
|
|
15
|
-
/** @type {
|
|
20
|
+
/** @type {TextEditorConfig} */
|
|
16
21
|
let config = $state({ modes: [], enabledButtons: [], components: [], isCodeEditor: false });
|
|
17
22
|
/** @type {string} */
|
|
18
23
|
let inputValue = $state('');
|
|
19
|
-
/** @type {
|
|
24
|
+
/** @type {TextEditorSelectionState} */
|
|
20
25
|
let selection = $state({ blockNodeKey: null, blockType: 'paragraph', inlineTypes: [] });
|
|
21
26
|
/** @type {boolean} */
|
|
22
27
|
let useRichText = $state(true);
|
|
@@ -68,7 +73,7 @@ export const createEditorStore = () => {
|
|
|
68
73
|
},
|
|
69
74
|
set config(newValue) {
|
|
70
75
|
config = newValue;
|
|
71
|
-
useRichText = newValue.modes[0] === 'rich-text';
|
|
76
|
+
useRichText = newValue.modes[0] === 'rich-text' || newValue.isCodeEditor;
|
|
72
77
|
},
|
|
73
78
|
get inputValue() {
|
|
74
79
|
return inputValue;
|
|
@@ -13,25 +13,34 @@
|
|
|
13
13
|
import { createEditorStore } from './store.svelte';
|
|
14
14
|
import TextEditorToolbar from './toolbar/text-editor-toolbar.svelte';
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @import { Snippet } from 'svelte';
|
|
18
|
+
* @import {
|
|
19
|
+
* TextEditorBlockType,
|
|
20
|
+
* TextEditorComponent,
|
|
21
|
+
* TextEditorInlineType,
|
|
22
|
+
* TextEditorMode,
|
|
23
|
+
* } from '../../typedefs';
|
|
24
|
+
*/
|
|
25
|
+
|
|
16
26
|
/**
|
|
17
27
|
* @typedef {object} Props
|
|
18
|
-
* @property {string} [value]
|
|
19
|
-
* @property {boolean} [flex]
|
|
20
|
-
* @property {
|
|
21
|
-
* @property {(
|
|
22
|
-
*
|
|
23
|
-
* @property {
|
|
24
|
-
* @property {
|
|
25
|
-
* @property {boolean} [
|
|
26
|
-
* @property {boolean} [disabled] - Whether to disable the widget. An alias of the `aria-disabled`
|
|
28
|
+
* @property {string} [value] Input value.
|
|
29
|
+
* @property {boolean} [flex] Make the text input container flexible.
|
|
30
|
+
* @property {TextEditorMode[]} [modes] Enabled modes.
|
|
31
|
+
* @property {(TextEditorBlockType | TextEditorInlineType)[]} [buttons] Enabled buttons.
|
|
32
|
+
* @property {TextEditorComponent[]} [components] Editor components.
|
|
33
|
+
* @property {string} [class] The `class` attribute on the wrapper element.
|
|
34
|
+
* @property {boolean} [hidden] Whether to hide the widget.
|
|
35
|
+
* @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
|
|
27
36
|
* attribute.
|
|
28
|
-
* @property {boolean} [readonly]
|
|
37
|
+
* @property {boolean} [readonly] Whether to make the widget read-only. An alias of the
|
|
29
38
|
* `aria-readonly` attribute.
|
|
30
|
-
* @property {boolean} [required]
|
|
39
|
+
* @property {boolean} [required] Whether to mark the widget required. An alias of the
|
|
31
40
|
* `aria-required` attribute.
|
|
32
|
-
* @property {boolean} [invalid]
|
|
41
|
+
* @property {boolean} [invalid] Whether to mark the widget invalid. An alias of the
|
|
33
42
|
* `aria-invalid` attribute.
|
|
34
|
-
* @property {
|
|
43
|
+
* @property {Snippet} [children] Primary slot content.
|
|
35
44
|
*/
|
|
36
45
|
|
|
37
46
|
/**
|