@sveltia/ui 0.91.0 → 0.92.1
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/conversion/editor-components.js +4 -4
- package/dist/components/text-editor/conversion/html/export.js +1 -1
- package/dist/components/text-editor/conversion/import.js +32 -26
- 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/update.d.ts +19 -2
- package/dist/components/text-editor/conversion/update.js +63 -39
- package/dist/components/text-editor/core.d.ts +12 -51
- package/dist/components/text-editor/core.js +44 -66
- package/dist/components/text-editor/editing/raw-markdown.d.ts +3 -0
- package/dist/components/text-editor/editing/raw-markdown.js +46 -2
- package/dist/components/text-editor/lexical-root.svelte +49 -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 +53 -145
- package/dist/components/text-editor/text-editor.svelte.d.ts +5 -103
- 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 +26 -24
- 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 +16 -4
- 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 +34 -33
- 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 +33 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/locales/hu.yaml +176 -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 +103 -4
- package/dist/typedefs.js +60 -4
- package/package.json +2 -2
- 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,10 +1,10 @@
|
|
|
1
1
|
export default TextEditor;
|
|
2
2
|
type TextEditor = {
|
|
3
3
|
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
-
$set?(props: Partial<Props & Record<string, any>>): void;
|
|
4
|
+
$set?(props: Partial<EditorCommonProps & WidgetStateProps & FormFieldStateProps & Props & Record<string, any>>): void;
|
|
5
5
|
};
|
|
6
6
|
/** A rich text editor based on Lexical. */
|
|
7
|
-
declare const TextEditor: import("svelte").Component<{
|
|
7
|
+
declare const TextEditor: import("svelte").Component<EditorCommonProps & WidgetStateProps & FormFieldStateProps & {
|
|
8
8
|
/**
|
|
9
9
|
* Input value in the {@link format}. A value set from outside
|
|
10
10
|
* is kept as is until the user changes the content, although the rich text editor writes Markdown
|
|
@@ -25,10 +25,6 @@ declare const TextEditor: import("svelte").Component<{
|
|
|
25
25
|
* change before reading the value, for example to save it. Read-only.
|
|
26
26
|
*/
|
|
27
27
|
pending?: boolean | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* Make the text input container flexible.
|
|
30
|
-
*/
|
|
31
|
-
flex?: boolean | undefined;
|
|
32
28
|
/**
|
|
33
29
|
* The `dir` attribute on the editable text box, both
|
|
34
30
|
* the rich text editor and the `<textarea>` element of the plain text mode.
|
|
@@ -71,52 +67,6 @@ declare const TextEditor: import("svelte").Component<{
|
|
|
71
67
|
* types a shortcode, like `:smi`.
|
|
72
68
|
*/
|
|
73
69
|
useEmojiAutocomplete?: boolean | undefined;
|
|
74
|
-
/**
|
|
75
|
-
* The `class` attribute on the wrapper element.
|
|
76
|
-
*/
|
|
77
|
-
class?: string | undefined;
|
|
78
|
-
/**
|
|
79
|
-
* Whether to hide the widget.
|
|
80
|
-
*/
|
|
81
|
-
hidden?: boolean | undefined;
|
|
82
|
-
/**
|
|
83
|
-
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
84
|
-
* attribute.
|
|
85
|
-
*/
|
|
86
|
-
disabled?: boolean | undefined;
|
|
87
|
-
/**
|
|
88
|
-
* Whether to make the widget read-only. An alias of the
|
|
89
|
-
* `aria-readonly` attribute.
|
|
90
|
-
*/
|
|
91
|
-
readonly?: boolean | undefined;
|
|
92
|
-
/**
|
|
93
|
-
* Whether to mark the widget required. An alias of the
|
|
94
|
-
* `aria-required` attribute.
|
|
95
|
-
*/
|
|
96
|
-
required?: boolean | undefined;
|
|
97
|
-
/**
|
|
98
|
-
* Whether to mark the widget invalid. An alias of the
|
|
99
|
-
* `aria-invalid` attribute.
|
|
100
|
-
*/
|
|
101
|
-
invalid?: boolean | undefined;
|
|
102
|
-
/**
|
|
103
|
-
* The `aria-label` attribute on the editable text box. Either
|
|
104
|
-
* this or `ariaLabelledby` is required for the editor to have an accessible name.
|
|
105
|
-
*/
|
|
106
|
-
ariaLabel?: string | undefined;
|
|
107
|
-
/**
|
|
108
|
-
* The `aria-labelledby` attribute on the editable text box.
|
|
109
|
-
*/
|
|
110
|
-
ariaLabelledby?: string | undefined;
|
|
111
|
-
/**
|
|
112
|
-
* The `aria-describedby` attribute on the editable text
|
|
113
|
-
* box.
|
|
114
|
-
*/
|
|
115
|
-
ariaDescribedby?: string | undefined;
|
|
116
|
-
/**
|
|
117
|
-
* Primary slot content.
|
|
118
|
-
*/
|
|
119
|
-
children?: Snippet<[]> | undefined;
|
|
120
70
|
} & Record<string, any>, {}, "value" | "pending">;
|
|
121
71
|
type Props = {
|
|
122
72
|
/**
|
|
@@ -139,10 +89,6 @@ type Props = {
|
|
|
139
89
|
* change before reading the value, for example to save it. Read-only.
|
|
140
90
|
*/
|
|
141
91
|
pending?: boolean | undefined;
|
|
142
|
-
/**
|
|
143
|
-
* Make the text input container flexible.
|
|
144
|
-
*/
|
|
145
|
-
flex?: boolean | undefined;
|
|
146
92
|
/**
|
|
147
93
|
* The `dir` attribute on the editable text box, both
|
|
148
94
|
* the rich text editor and the `<textarea>` element of the plain text mode.
|
|
@@ -185,55 +131,11 @@ type Props = {
|
|
|
185
131
|
* types a shortcode, like `:smi`.
|
|
186
132
|
*/
|
|
187
133
|
useEmojiAutocomplete?: boolean | undefined;
|
|
188
|
-
/**
|
|
189
|
-
* The `class` attribute on the wrapper element.
|
|
190
|
-
*/
|
|
191
|
-
class?: string | undefined;
|
|
192
|
-
/**
|
|
193
|
-
* Whether to hide the widget.
|
|
194
|
-
*/
|
|
195
|
-
hidden?: boolean | undefined;
|
|
196
|
-
/**
|
|
197
|
-
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
198
|
-
* attribute.
|
|
199
|
-
*/
|
|
200
|
-
disabled?: boolean | undefined;
|
|
201
|
-
/**
|
|
202
|
-
* Whether to make the widget read-only. An alias of the
|
|
203
|
-
* `aria-readonly` attribute.
|
|
204
|
-
*/
|
|
205
|
-
readonly?: boolean | undefined;
|
|
206
|
-
/**
|
|
207
|
-
* Whether to mark the widget required. An alias of the
|
|
208
|
-
* `aria-required` attribute.
|
|
209
|
-
*/
|
|
210
|
-
required?: boolean | undefined;
|
|
211
|
-
/**
|
|
212
|
-
* Whether to mark the widget invalid. An alias of the
|
|
213
|
-
* `aria-invalid` attribute.
|
|
214
|
-
*/
|
|
215
|
-
invalid?: boolean | undefined;
|
|
216
|
-
/**
|
|
217
|
-
* The `aria-label` attribute on the editable text box. Either
|
|
218
|
-
* this or `ariaLabelledby` is required for the editor to have an accessible name.
|
|
219
|
-
*/
|
|
220
|
-
ariaLabel?: string | undefined;
|
|
221
|
-
/**
|
|
222
|
-
* The `aria-labelledby` attribute on the editable text box.
|
|
223
|
-
*/
|
|
224
|
-
ariaLabelledby?: string | undefined;
|
|
225
|
-
/**
|
|
226
|
-
* The `aria-describedby` attribute on the editable text
|
|
227
|
-
* box.
|
|
228
|
-
*/
|
|
229
|
-
ariaDescribedby?: string | undefined;
|
|
230
|
-
/**
|
|
231
|
-
* Primary slot content.
|
|
232
|
-
*/
|
|
233
|
-
children?: Snippet<[]> | undefined;
|
|
234
134
|
};
|
|
135
|
+
import type { EditorCommonProps } from '../../typedefs.js';
|
|
136
|
+
import type { WidgetStateProps } from '../../typedefs.js';
|
|
137
|
+
import type { FormFieldStateProps } from '../../typedefs.js';
|
|
235
138
|
import type { TextEditorValueFormat } from '../../typedefs.js';
|
|
236
139
|
import type { TextEditorMode } from '../../typedefs.js';
|
|
237
140
|
import type { TextEditorNodeType } from '../../typedefs.js';
|
|
238
141
|
import type { TextEditorComponent } from '../../typedefs.js';
|
|
239
|
-
import type { Snippet } from 'svelte';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function runEditorAction(editorStore: TextEditorStore, { raw, rich, focus }: EditorAction): Promise<void>;
|
|
2
|
+
export function refocusEditor(editorStore: TextEditorStore): Promise<void>;
|
|
3
|
+
export function insertEditorComponent(editorStore: TextEditorStore, component: TextEditorComponent): Promise<void>;
|
|
4
|
+
export type EditorAction = {
|
|
5
|
+
/**
|
|
6
|
+
* Edit the `<textarea>`
|
|
7
|
+
* in the plain text mode, which also moves the focus there. Without it, nothing happens in the
|
|
8
|
+
* plain text mode.
|
|
9
|
+
*/
|
|
10
|
+
raw?: ((textArea: HTMLTextAreaElement) => void | Promise<void>) | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Edit the Lexical editor in the
|
|
13
|
+
* rich text mode.
|
|
14
|
+
*/
|
|
15
|
+
rich: (editor: LexicalEditor) => void | Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* When to move the focus back to the Lexical
|
|
18
|
+
* editor: `after` the edit (default), `before` it, for an edit that applies to the selection the
|
|
19
|
+
* focus restores, or not at all, for an edit that moves the focus on its own.
|
|
20
|
+
*/
|
|
21
|
+
focus?: false | "after" | "before" | undefined;
|
|
22
|
+
};
|
|
23
|
+
import type { TextEditorStore } from '../../../typedefs.js';
|
|
24
|
+
import type { TextEditorComponent } from '../../../typedefs.js';
|
|
25
|
+
import type { LexicalEditor } from 'lexical';
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Toolbar actions that work in both the rich text and plain text modes.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { $createParagraphNode as createParagraphNode, $insertNodes as insertNodes } from 'lexical';
|
|
6
|
+
import { focusEditor } from '../editing/caret.js';
|
|
7
|
+
import { insertComponent } from '../editing/raw-markdown.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @import { LexicalEditor } from 'lexical';
|
|
11
|
+
* @import { TextEditorComponent, TextEditorStore } from '../../../typedefs.js';
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {object} EditorAction
|
|
16
|
+
* @property {(textArea: HTMLTextAreaElement) => void | Promise<void>} [raw] Edit the `<textarea>`
|
|
17
|
+
* in the plain text mode, which also moves the focus there. Without it, nothing happens in the
|
|
18
|
+
* plain text mode.
|
|
19
|
+
* @property {(editor: LexicalEditor) => void | Promise<void>} rich Edit the Lexical editor in the
|
|
20
|
+
* rich text mode.
|
|
21
|
+
* @property {'after' | 'before' | false} [focus] When to move the focus back to the Lexical
|
|
22
|
+
* editor: `after` the edit (default), `before` it, for an edit that applies to the selection the
|
|
23
|
+
* focus restores, or not at all, for an edit that moves the focus on its own.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Run a toolbar action in the mode the editor is in.
|
|
28
|
+
* @param {TextEditorStore} editorStore Editor store.
|
|
29
|
+
* @param {EditorAction} action Action.
|
|
30
|
+
* @returns {Promise<void>} Nothing.
|
|
31
|
+
*/
|
|
32
|
+
export const runEditorAction = async (editorStore, { raw, rich, focus = 'after' }) => {
|
|
33
|
+
const { editor, textArea, useRichText } = editorStore;
|
|
34
|
+
|
|
35
|
+
if (!useRichText) {
|
|
36
|
+
// The toolbar is only enabled while the `<textarea>` is there
|
|
37
|
+
/* v8 ignore else */
|
|
38
|
+
if (raw && textArea) {
|
|
39
|
+
await raw(textArea);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The toolbar is only enabled while the editor is there
|
|
46
|
+
/* v8 ignore next 3 */
|
|
47
|
+
if (!editor) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (focus === 'before') {
|
|
52
|
+
await focusEditor(editor);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await rich(editor);
|
|
56
|
+
|
|
57
|
+
if (focus === 'after') {
|
|
58
|
+
await focusEditor(editor);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Move the focus back to the editor shown, the Lexical editor or the `<textarea>`, like after a
|
|
64
|
+
* dialog that leaves the focus alone has been closed without changing anything.
|
|
65
|
+
* @param {TextEditorStore} editorStore Editor store.
|
|
66
|
+
* @returns {Promise<void>} Nothing.
|
|
67
|
+
*/
|
|
68
|
+
export const refocusEditor = async (editorStore) => {
|
|
69
|
+
const { editor, textArea, useRichText } = editorStore;
|
|
70
|
+
|
|
71
|
+
if (!useRichText) {
|
|
72
|
+
textArea?.focus();
|
|
73
|
+
} else if (editor) {
|
|
74
|
+
await focusEditor(editor);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Insert a new instance of the given editor component into the editor: its Markdown in the plain
|
|
80
|
+
* text mode, or its node in the rich text mode. The focus is left to the component.
|
|
81
|
+
* @param {TextEditorStore} editorStore Editor store.
|
|
82
|
+
* @param {TextEditorComponent} component Editor component.
|
|
83
|
+
* @returns {Promise<void>} Nothing.
|
|
84
|
+
*/
|
|
85
|
+
export const insertEditorComponent = (editorStore, component) =>
|
|
86
|
+
runEditorAction(editorStore, {
|
|
87
|
+
/**
|
|
88
|
+
* Insert the component’s Markdown.
|
|
89
|
+
* @param {HTMLTextAreaElement} textArea `<textarea>` element.
|
|
90
|
+
* @returns {void | Promise<void>} Nothing.
|
|
91
|
+
*/
|
|
92
|
+
raw: (textArea) => insertComponent(textArea, component),
|
|
93
|
+
/**
|
|
94
|
+
* Insert the component’s node.
|
|
95
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
96
|
+
*/
|
|
97
|
+
rich: (editor) => {
|
|
98
|
+
editor.update(() => {
|
|
99
|
+
const node = component.createNode();
|
|
100
|
+
|
|
101
|
+
// Add an additional paragraph after a block for easier editing. An inline node stays
|
|
102
|
+
// within the text, which may be in a table cell where a paragraph can’t be added
|
|
103
|
+
insertNodes(node.isInline() ? [node] : [node, createParagraphNode()]);
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
focus: false,
|
|
107
|
+
});
|
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
import MenuItemRadio from '../../menu/menu-item-radio.svelte';
|
|
13
13
|
import Menu from '../../menu/menu.svelte';
|
|
14
14
|
import { ALIGNMENT_OPTIONS } from '../constants.js';
|
|
15
|
-
import {
|
|
15
|
+
import { runEditorAction } from './actions.js';
|
|
16
16
|
import { waitForMenuToClose } from './menu.js';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
+
* @import { LexicalEditor } from 'lexical';
|
|
19
20
|
* @import { TextEditorStore } from '../../../typedefs.js';
|
|
20
21
|
*/
|
|
21
22
|
|
|
@@ -35,20 +36,21 @@
|
|
|
35
36
|
* Align the selected blocks, then move the focus back to the editor.
|
|
36
37
|
* @param {(typeof ALIGNMENT_OPTIONS)[number]['type']} type Alignment.
|
|
37
38
|
* @param {HTMLElement} item Menu item chosen.
|
|
39
|
+
* @returns {Promise<void>} Nothing.
|
|
38
40
|
*/
|
|
39
|
-
const align =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
const align = (type, item) =>
|
|
42
|
+
// The menu is only shown in the rich text mode
|
|
43
|
+
runEditorAction(editorStore, {
|
|
44
|
+
/**
|
|
45
|
+
* Align the selected blocks, and wait for the menu to close.
|
|
46
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
47
|
+
* @returns {Promise<void>} Nothing.
|
|
48
|
+
*/
|
|
49
|
+
rich: async (editor) => {
|
|
50
|
+
editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, type);
|
|
51
|
+
await waitForMenuToClose(item);
|
|
52
|
+
},
|
|
53
|
+
});
|
|
52
54
|
</script>
|
|
53
55
|
|
|
54
56
|
<MenuButton
|
|
@@ -5,14 +5,15 @@
|
|
|
5
5
|
import Button from '../../button/button.svelte';
|
|
6
6
|
import Icon from '../../icon/icon.svelte';
|
|
7
7
|
import { AVAILABLE_BUTTONS, isHtmlOnlyButton } from '../constants.js';
|
|
8
|
-
import { focusEditor } from '../editing/caret.js';
|
|
9
8
|
import {
|
|
10
9
|
editRawText,
|
|
11
10
|
registerRawTextShortcut,
|
|
12
11
|
toggleInlineFormat,
|
|
13
12
|
} from '../editing/raw-markdown.js';
|
|
13
|
+
import { runEditorAction } from './actions.js';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
+
* @import { LexicalEditor } from 'lexical';
|
|
16
17
|
* @import { TextEditorFormatType, TextEditorStore } from '../../../typedefs.js';
|
|
17
18
|
*/
|
|
18
19
|
|
|
@@ -42,30 +43,31 @@
|
|
|
42
43
|
|
|
43
44
|
/**
|
|
44
45
|
* Format the selection.
|
|
46
|
+
* @returns {Promise<void>} Nothing.
|
|
45
47
|
*/
|
|
46
|
-
const format =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
48
|
+
const format = () =>
|
|
49
|
+
runEditorAction(editorStore, {
|
|
50
|
+
/**
|
|
51
|
+
* Format the selected Markdown.
|
|
52
|
+
* @param {HTMLTextAreaElement} textArea `<textarea>` element.
|
|
53
|
+
*/
|
|
54
|
+
raw: (textArea) => {
|
|
55
|
+
// The `<textarea>` is only there for Markdown, which hides the HTML-only formats
|
|
56
|
+
/* v8 ignore else */
|
|
57
|
+
if (!isHtmlOnlyButton(type)) {
|
|
58
|
+
editRawText(textArea, (state) => toggleInlineFormat(state, type));
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* Format the selection.
|
|
63
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
64
|
+
*/
|
|
65
|
+
rich: (editor) => {
|
|
66
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, type);
|
|
67
|
+
},
|
|
68
|
+
// The format applies to the selection, which the focus restores
|
|
69
|
+
focus: 'before',
|
|
70
|
+
});
|
|
69
71
|
|
|
70
72
|
$effect(() => {
|
|
71
73
|
const { textArea } = editorStore;
|
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
import Icon from '../../icon/icon.svelte';
|
|
11
11
|
import { $insertHorizontalRule as insertHorizontalRule } from '../editing/block.js';
|
|
12
12
|
import { AVAILABLE_BUTTONS } from '../constants.js';
|
|
13
|
-
import { focusEditor } from '../editing/caret.js';
|
|
14
13
|
import { editRawText, insertMarkdown } from '../editing/raw-markdown.js';
|
|
15
14
|
import { HORIZONTAL_RULE_MARKDOWN } from '../conversion/transformers/hr.js';
|
|
15
|
+
import { runEditorAction } from './actions.js';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
+
* @import { LexicalEditor } from 'lexical';
|
|
18
19
|
* @import { TextEditorStore } from '../../../typedefs.js';
|
|
19
20
|
*/
|
|
20
21
|
|
|
@@ -25,30 +26,29 @@
|
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Insert a horizontal rule, then move the focus back to the editor.
|
|
29
|
+
* @returns {Promise<void>} Nothing.
|
|
28
30
|
*/
|
|
29
|
-
const insert =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
const insert = () =>
|
|
32
|
+
runEditorAction(editorStore, {
|
|
33
|
+
/**
|
|
34
|
+
* Insert the Markdown.
|
|
35
|
+
* @param {HTMLTextAreaElement} textArea `<textarea>` element.
|
|
36
|
+
* @returns {void | Promise<void>} Nothing.
|
|
37
|
+
*/
|
|
38
|
+
raw: (textArea) =>
|
|
39
|
+
editRawText(textArea, (state) =>
|
|
40
|
+
insertMarkdown(state, HORIZONTAL_RULE_MARKDOWN, { block: true }),
|
|
41
|
+
),
|
|
42
|
+
/**
|
|
43
|
+
* Insert a horizontal rule node.
|
|
44
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
45
|
+
*/
|
|
46
|
+
rich: (editor) => {
|
|
47
|
+
editor.update(() => {
|
|
48
|
+
insertHorizontalRule();
|
|
49
|
+
});
|
|
50
|
+
},
|
|
48
51
|
});
|
|
49
|
-
|
|
50
|
-
await focusEditor(editor);
|
|
51
|
-
};
|
|
52
52
|
</script>
|
|
53
53
|
|
|
54
54
|
<Button
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { getContext } from 'svelte';
|
|
3
3
|
import Button from '../../button/button.svelte';
|
|
4
4
|
import Icon from '../../icon/icon.svelte';
|
|
5
|
-
import { insertEditorComponent } from './
|
|
5
|
+
import { insertEditorComponent } from './actions.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @import { TextEditorComponent, TextEditorStore } from '../../../typedefs.js';
|
|
@@ -30,8 +30,10 @@
|
|
|
30
30
|
insertLink,
|
|
31
31
|
registerRawTextShortcut,
|
|
32
32
|
} from '../editing/raw-markdown.js';
|
|
33
|
+
import { refocusEditor, runEditorAction } from './actions.js';
|
|
33
34
|
|
|
34
35
|
/**
|
|
36
|
+
* @import { LexicalEditor } from 'lexical';
|
|
35
37
|
* @import { TextEditorStore } from '../../../typedefs.js';
|
|
36
38
|
*/
|
|
37
39
|
|
|
@@ -128,61 +130,55 @@
|
|
|
128
130
|
* @see https://github.com/facebook/lexical/discussions/3013
|
|
129
131
|
*/
|
|
130
132
|
const onDialogClose = async (event) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
if (event.detail.returnValue === 'cancel') {
|
|
134
|
+
// The dialog leaves the focus alone (see `restoreFocus` below), so bring it back here
|
|
135
|
+
await refocusEditor(editorStore);
|
|
136
|
+
} else {
|
|
137
|
+
await runEditorAction(editorStore, {
|
|
138
|
+
/**
|
|
139
|
+
* Insert the link’s Markdown.
|
|
140
|
+
* @param {HTMLTextAreaElement} textArea `<textarea>` element.
|
|
141
|
+
* @returns {void | Promise<void>} Nothing.
|
|
142
|
+
*/
|
|
143
|
+
raw: (textArea) =>
|
|
138
144
|
editRawText(textArea, (state) =>
|
|
139
145
|
insertLink(state, { url: anchorURL.trim(), text: hasAnchor ? undefined : anchorText }),
|
|
146
|
+
),
|
|
147
|
+
/**
|
|
148
|
+
* Insert the link text if needed, and link the selection.
|
|
149
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
150
|
+
* @returns {Promise<void>} Nothing.
|
|
151
|
+
*/
|
|
152
|
+
rich: async (editor) => {
|
|
153
|
+
await new Promise((resolve) => {
|
|
154
|
+
editor.update(async () => {
|
|
155
|
+
let _selection = getSelection() ?? getPreviousSelection()?.clone();
|
|
156
|
+
|
|
157
|
+
if (!isRangeSelection(_selection)) {
|
|
158
|
+
_selection = createRangeSelection();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (!hasAnchor) {
|
|
162
|
+
anchorText = anchorText.trim();
|
|
163
|
+
anchorText ||= anchorURL;
|
|
164
|
+
insertNodes([createTextNode(anchorText)]);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
setSelection(_selection);
|
|
168
|
+
resolve(undefined);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// The link applies to the selection, which the focus restores
|
|
173
|
+
await focusEditor(editor);
|
|
174
|
+
editor.dispatchCommand(
|
|
175
|
+
TOGGLE_LINK_COMMAND,
|
|
176
|
+
canSetTarget && openInNewTab ? { url: anchorURL, target: '_blank' } : anchorURL,
|
|
140
177
|
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
anchorURL = '';
|
|
147
|
-
anchorText = '';
|
|
148
|
-
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (event.detail.returnValue !== 'cancel') {
|
|
153
|
-
// The dialog can only be opened from the button, which needs the editor
|
|
154
|
-
/* v8 ignore next */
|
|
155
|
-
if (!editorStore.editor) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
await new Promise((resolve) => {
|
|
160
|
-
editorStore.editor?.update(async () => {
|
|
161
|
-
let _selection = getSelection() ?? getPreviousSelection()?.clone();
|
|
162
|
-
|
|
163
|
-
if (!isRangeSelection(_selection)) {
|
|
164
|
-
_selection = createRangeSelection();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (!hasAnchor) {
|
|
168
|
-
anchorText = anchorText.trim();
|
|
169
|
-
anchorText ||= anchorURL;
|
|
170
|
-
insertNodes([createTextNode(anchorText)]);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
setSelection(_selection);
|
|
174
|
-
resolve(undefined);
|
|
175
|
-
});
|
|
178
|
+
},
|
|
179
|
+
// Moved within the edit above, between inserting the text and linking it
|
|
180
|
+
focus: false,
|
|
176
181
|
});
|
|
177
|
-
|
|
178
|
-
await focusEditor(editorStore.editor);
|
|
179
|
-
editorStore.editor.dispatchCommand(
|
|
180
|
-
TOGGLE_LINK_COMMAND,
|
|
181
|
-
canSetTarget && openInNewTab ? { url: anchorURL, target: '_blank' } : anchorURL,
|
|
182
|
-
);
|
|
183
|
-
} else /* v8 ignore else */ if (editorStore.editor) {
|
|
184
|
-
// The dialog leaves the focus alone (see `restoreFocus` below), so bring it back here
|
|
185
|
-
await focusEditor(editorStore.editor);
|
|
186
182
|
}
|
|
187
183
|
|
|
188
184
|
anchorURL = '';
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import MenuButton from '../../menu/menu-button.svelte';
|
|
6
6
|
import MenuItem from '../../menu/menu-item.svelte';
|
|
7
7
|
import Menu from '../../menu/menu.svelte';
|
|
8
|
-
import { insertEditorComponent } from './
|
|
8
|
+
import { insertEditorComponent } from './actions.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @import { TextEditorComponent, TextEditorStore } from '../../../typedefs.js';
|