@sveltia/ui 0.25.7 → 0.25.8
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 +15 -11
- 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 +21 -11
- 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 +25 -28
- 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 +9 -4
- 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 +1 -1
|
@@ -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';
|
|
@@ -54,11 +54,21 @@ import prismComponents from 'prismjs/components';
|
|
|
54
54
|
import { blockButtonTypes, textFormatButtonTypes } from '.';
|
|
55
55
|
import { TABLE } from './transformers/table';
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* @import { CreateEditorArgs, LexicalEditor } from 'lexical';
|
|
59
|
+
* @import {
|
|
60
|
+
* TextEditorBlockType,
|
|
61
|
+
* TextEditorConfig,
|
|
62
|
+
* TextEditorInlineType,
|
|
63
|
+
* TextEditorSelectionState,
|
|
64
|
+
* } from '../../typedefs';
|
|
65
|
+
*/
|
|
66
|
+
|
|
57
67
|
const allTransformers = [...TRANSFORMERS, TABLE];
|
|
58
68
|
|
|
59
69
|
/**
|
|
60
70
|
* Lexical editor configuration.
|
|
61
|
-
* @type {
|
|
71
|
+
* @type {CreateEditorArgs}
|
|
62
72
|
*/
|
|
63
73
|
const editorConfig = {
|
|
64
74
|
namespace: 'editor',
|
|
@@ -126,7 +136,7 @@ const editorConfig = {
|
|
|
126
136
|
|
|
127
137
|
/**
|
|
128
138
|
* Get the current selection’s block node key as well as block and inline level types.
|
|
129
|
-
* @returns {
|
|
139
|
+
* @returns {TextEditorSelectionState} Current selection state.
|
|
130
140
|
*/
|
|
131
141
|
const getSelectionTypes = () => {
|
|
132
142
|
const selection = getSelection();
|
|
@@ -142,7 +152,7 @@ const getSelectionTypes = () => {
|
|
|
142
152
|
const anchor = selection.anchor.getNode();
|
|
143
153
|
/** @type {ElementNode | null} */
|
|
144
154
|
let parent = null;
|
|
145
|
-
/** @type {
|
|
155
|
+
/** @type {TextEditorInlineType[]} */
|
|
146
156
|
const inlineTypes = textFormatButtonTypes.filter((type) => selection.hasFormat(type));
|
|
147
157
|
|
|
148
158
|
if (anchor.getType() !== 'root') {
|
|
@@ -158,7 +168,7 @@ const getSelectionTypes = () => {
|
|
|
158
168
|
}
|
|
159
169
|
}
|
|
160
170
|
|
|
161
|
-
const blockType = /** @type {
|
|
171
|
+
const blockType = /** @type {TextEditorBlockType} */ (
|
|
162
172
|
(() => {
|
|
163
173
|
if (!parent) {
|
|
164
174
|
return 'paragraph';
|
|
@@ -199,7 +209,7 @@ const getSelectionTypes = () => {
|
|
|
199
209
|
|
|
200
210
|
/**
|
|
201
211
|
* Listen to changes made on the editor and trigger the Update event.
|
|
202
|
-
* @param {
|
|
212
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
203
213
|
*/
|
|
204
214
|
const onEditorUpdate = (editor) => {
|
|
205
215
|
editor.getRootElement()?.dispatchEvent(
|
|
@@ -217,8 +227,8 @@ const onEditorUpdate = (editor) => {
|
|
|
217
227
|
|
|
218
228
|
/**
|
|
219
229
|
* Initialize the Lexical editor.
|
|
220
|
-
* @param {
|
|
221
|
-
* @returns {
|
|
230
|
+
* @param {TextEditorConfig} config Editor configuration.
|
|
231
|
+
* @returns {LexicalEditor} Editor instance.
|
|
222
232
|
*/
|
|
223
233
|
export const initEditor = ({ components = [], isCodeEditor = false, defaultLanguage = '' }) => {
|
|
224
234
|
components.forEach(({ node, transformer }) => {
|
|
@@ -343,7 +353,7 @@ export const initEditor = ({ components = [], isCodeEditor = false, defaultLangu
|
|
|
343
353
|
|
|
344
354
|
/**
|
|
345
355
|
* Load additional Prism syntax highlighter settings for the given programming language.
|
|
346
|
-
* @param {string} lang
|
|
356
|
+
* @param {string} lang Language name, like scss.
|
|
347
357
|
*/
|
|
348
358
|
export const loadCodeHighlighter = async (lang) => {
|
|
349
359
|
if (lang in window.Prism.languages) {
|
|
@@ -372,8 +382,8 @@ export const loadCodeHighlighter = async (lang) => {
|
|
|
372
382
|
|
|
373
383
|
/**
|
|
374
384
|
* Convert Markdown to Lexical nodes.
|
|
375
|
-
* @param {
|
|
376
|
-
* @param {string} value
|
|
385
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
386
|
+
* @param {string} value Current Markdown value.
|
|
377
387
|
* @returns {Promise<void>} Nothing.
|
|
378
388
|
* @throws {Error} Failed to convert the value to Lexical nodes.
|
|
379
389
|
*/
|
|
@@ -399,7 +409,7 @@ export const convertMarkdownToLexical = async (editor, value) => {
|
|
|
399
409
|
|
|
400
410
|
/**
|
|
401
411
|
* Move focus to the editor so the user can start editing immediately.
|
|
402
|
-
* @param {
|
|
412
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
403
413
|
* @returns {Promise<void>} Nothing.
|
|
404
414
|
*/
|
|
405
415
|
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')) {
|
|
@@ -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);
|
|
@@ -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
|
/**
|
|
@@ -6,109 +6,114 @@ type TextEditor = {
|
|
|
6
6
|
/** A rich text editor based on Lexical. */
|
|
7
7
|
declare const TextEditor: import("svelte").Component<{
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Input value.
|
|
10
10
|
*/
|
|
11
11
|
value?: string | undefined;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Make the text input container flexible.
|
|
14
14
|
*/
|
|
15
15
|
flex?: boolean | undefined;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Enabled modes.
|
|
18
18
|
*/
|
|
19
|
-
modes?:
|
|
19
|
+
modes?: TextEditorMode[] | undefined;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* Enabled buttons.
|
|
22
22
|
*/
|
|
23
|
-
buttons?: (
|
|
23
|
+
buttons?: (TextEditorBlockType | TextEditorInlineType)[] | undefined;
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* Editor components.
|
|
26
26
|
*/
|
|
27
|
-
components?:
|
|
27
|
+
components?: TextEditorComponent[] | undefined;
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* The `class` attribute on the wrapper element.
|
|
30
30
|
*/
|
|
31
31
|
class?: string | undefined;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Whether to hide the widget.
|
|
34
34
|
*/
|
|
35
35
|
hidden?: boolean | undefined;
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
38
38
|
* attribute.
|
|
39
39
|
*/
|
|
40
40
|
disabled?: boolean | undefined;
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* Whether to make the widget read-only. An alias of the
|
|
43
43
|
* `aria-readonly` attribute.
|
|
44
44
|
*/
|
|
45
45
|
readonly?: boolean | undefined;
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
47
|
+
* Whether to mark the widget required. An alias of the
|
|
48
48
|
* `aria-required` attribute.
|
|
49
49
|
*/
|
|
50
50
|
required?: boolean | undefined;
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
52
|
+
* Whether to mark the widget invalid. An alias of the
|
|
53
53
|
* `aria-invalid` attribute.
|
|
54
54
|
*/
|
|
55
55
|
invalid?: boolean | undefined;
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
57
|
+
* Primary slot content.
|
|
58
58
|
*/
|
|
59
|
-
children?:
|
|
59
|
+
children?: Snippet<[]> | undefined;
|
|
60
60
|
} & Record<string, any>, {}, "value">;
|
|
61
61
|
type Props = {
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* Input value.
|
|
64
64
|
*/
|
|
65
65
|
value?: string | undefined;
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
67
|
+
* Make the text input container flexible.
|
|
68
68
|
*/
|
|
69
69
|
flex?: boolean | undefined;
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
71
|
+
* Enabled modes.
|
|
72
72
|
*/
|
|
73
|
-
modes?:
|
|
73
|
+
modes?: TextEditorMode[] | undefined;
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
75
|
+
* Enabled buttons.
|
|
76
76
|
*/
|
|
77
|
-
buttons?: (
|
|
77
|
+
buttons?: (TextEditorBlockType | TextEditorInlineType)[] | undefined;
|
|
78
78
|
/**
|
|
79
|
-
*
|
|
79
|
+
* Editor components.
|
|
80
80
|
*/
|
|
81
|
-
components?:
|
|
81
|
+
components?: TextEditorComponent[] | undefined;
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
83
|
+
* The `class` attribute on the wrapper element.
|
|
84
84
|
*/
|
|
85
85
|
class?: string | undefined;
|
|
86
86
|
/**
|
|
87
|
-
*
|
|
87
|
+
* Whether to hide the widget.
|
|
88
88
|
*/
|
|
89
89
|
hidden?: boolean | undefined;
|
|
90
90
|
/**
|
|
91
|
-
*
|
|
91
|
+
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
92
92
|
* attribute.
|
|
93
93
|
*/
|
|
94
94
|
disabled?: boolean | undefined;
|
|
95
95
|
/**
|
|
96
|
-
*
|
|
96
|
+
* Whether to make the widget read-only. An alias of the
|
|
97
97
|
* `aria-readonly` attribute.
|
|
98
98
|
*/
|
|
99
99
|
readonly?: boolean | undefined;
|
|
100
100
|
/**
|
|
101
|
-
*
|
|
101
|
+
* Whether to mark the widget required. An alias of the
|
|
102
102
|
* `aria-required` attribute.
|
|
103
103
|
*/
|
|
104
104
|
required?: boolean | undefined;
|
|
105
105
|
/**
|
|
106
|
-
*
|
|
106
|
+
* Whether to mark the widget invalid. An alias of the
|
|
107
107
|
* `aria-invalid` attribute.
|
|
108
108
|
*/
|
|
109
109
|
invalid?: boolean | undefined;
|
|
110
110
|
/**
|
|
111
|
-
*
|
|
111
|
+
* Primary slot content.
|
|
112
112
|
*/
|
|
113
|
-
children?:
|
|
113
|
+
children?: Snippet<[]> | undefined;
|
|
114
114
|
};
|
|
115
|
+
import type { TextEditorMode } from '../../typedefs';
|
|
116
|
+
import type { TextEditorBlockType } from '../../typedefs';
|
|
117
|
+
import type { TextEditorInlineType } from '../../typedefs';
|
|
118
|
+
import type { TextEditorComponent } from '../../typedefs';
|
|
119
|
+
import type { Snippet } from 'svelte';
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @typedef {object} Props
|
|
8
|
-
* @property {boolean} [hidden]
|
|
9
|
-
* @property {boolean} [disabled]
|
|
8
|
+
* @property {boolean} [hidden] Whether to hide the widget.
|
|
9
|
+
* @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
|
|
10
10
|
* attribute.
|
|
11
|
-
* @property {boolean} [readonly]
|
|
11
|
+
* @property {boolean} [readonly] Whether to make the widget read-only. An alias of the
|
|
12
12
|
* `aria-readonly` attribute.
|
|
13
13
|
*/
|
|
14
14
|
|
|
@@ -5,32 +5,32 @@ type CodeEditorToolbar = {
|
|
|
5
5
|
};
|
|
6
6
|
declare const CodeEditorToolbar: import("svelte").Component<{
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Whether to hide the widget.
|
|
9
9
|
*/
|
|
10
10
|
hidden?: boolean | undefined;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
13
13
|
* attribute.
|
|
14
14
|
*/
|
|
15
15
|
disabled?: boolean | undefined;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Whether to make the widget read-only. An alias of the
|
|
18
18
|
* `aria-readonly` attribute.
|
|
19
19
|
*/
|
|
20
20
|
readonly?: boolean | undefined;
|
|
21
21
|
} & Record<string, any>, {}, "">;
|
|
22
22
|
type Props = {
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* Whether to hide the widget.
|
|
25
25
|
*/
|
|
26
26
|
hidden?: boolean | undefined;
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
29
29
|
* attribute.
|
|
30
30
|
*/
|
|
31
31
|
disabled?: boolean | undefined;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Whether to make the widget read-only. An alias of the
|
|
34
34
|
* `aria-readonly` attribute.
|
|
35
35
|
*/
|
|
36
36
|
readonly?: boolean | undefined;
|
|
@@ -8,9 +8,13 @@
|
|
|
8
8
|
import Select from '../../select/select.svelte';
|
|
9
9
|
import { focusEditor, loadCodeHighlighter } from '../core';
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* @import { TextEditorStore } from '../../../typedefs';
|
|
13
|
+
*/
|
|
14
|
+
|
|
11
15
|
/**
|
|
12
16
|
* @typedef {object} Props
|
|
13
|
-
* @property {boolean} [disabled]
|
|
17
|
+
* @property {boolean} [disabled] Whether to disable the switcher.
|
|
14
18
|
*/
|
|
15
19
|
|
|
16
20
|
/** @type {Props} */
|
|
@@ -39,7 +43,7 @@
|
|
|
39
43
|
.flat(1)
|
|
40
44
|
.sort((a, b) => a.label.localeCompare(b.label));
|
|
41
45
|
|
|
42
|
-
/** @type {
|
|
46
|
+
/** @type {TextEditorStore} */
|
|
43
47
|
const editorStore = getContext('editorStore');
|
|
44
48
|
|
|
45
49
|
let selectedLanguage = $state('');
|