@sveltia/ui 0.91.0 → 0.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/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 +16 -12
- 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 +1 -1
- 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
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
<script>
|
|
9
9
|
import { _ } from '@sveltia/i18n';
|
|
10
10
|
import { onMount } from 'svelte';
|
|
11
|
-
import {
|
|
11
|
+
import { setFocusedMember } from '../../services/group.svelte.js';
|
|
12
12
|
import { createOptionRegistry, getSelectedItemDetail } from '../../services/select.svelte.js';
|
|
13
|
-
import {
|
|
13
|
+
import { isPrintableKey, TypeAhead } from '../../services/type-ahead.js';
|
|
14
14
|
import Button from '../button/button.svelte';
|
|
15
15
|
import Icon from '../icon/icon.svelte';
|
|
16
16
|
import Listbox from '../listbox/listbox.svelte';
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
editable = true,
|
|
39
39
|
position = 'bottom-left',
|
|
40
40
|
filterThreshold = 5,
|
|
41
|
+
selectOnTypeAhead = true,
|
|
41
42
|
ariaLabel = undefined,
|
|
42
43
|
children,
|
|
43
44
|
chevronIcon,
|
|
@@ -70,12 +71,16 @@
|
|
|
70
71
|
* @type {HTMLElement | undefined}
|
|
71
72
|
*/
|
|
72
73
|
let listboxSlot = $state();
|
|
73
|
-
/** @type {string} */
|
|
74
|
-
let label = $state('');
|
|
75
74
|
/** @type {boolean} */
|
|
76
75
|
let showFilter = $state(false);
|
|
77
76
|
/** @type {string} */
|
|
78
77
|
let searchTerms = $state('');
|
|
78
|
+
/**
|
|
79
|
+
* Characters typed on the collapsed combobox that opened the dropdown, to be carried over to the
|
|
80
|
+
* filter once it’s shown. See {@link selectOnTypeAhead}.
|
|
81
|
+
* @type {string}
|
|
82
|
+
*/
|
|
83
|
+
let pendingSearchTerms = '';
|
|
79
84
|
/**
|
|
80
85
|
* Number of options matching the current search terms, as last reported by the listbox.
|
|
81
86
|
* @type {number}
|
|
@@ -102,17 +107,10 @@
|
|
|
102
107
|
const registry = createOptionRegistry();
|
|
103
108
|
|
|
104
109
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* selected.
|
|
110
|
+
* Label of the option matching the {@link value}. A value that matches no option, including
|
|
111
|
+
* `undefined`, gives an empty label.
|
|
108
112
|
*/
|
|
109
|
-
const
|
|
110
|
-
const entry = registry.find(value);
|
|
111
|
-
|
|
112
|
-
label = entry?.label ?? '';
|
|
113
|
-
// With no matching entry, this deselects every option
|
|
114
|
-
registry.selectOnly(value);
|
|
115
|
-
};
|
|
113
|
+
const label = $derived(registry.find(value)?.label ?? '');
|
|
116
114
|
|
|
117
115
|
/**
|
|
118
116
|
* Raise a `Change` event for an option known only through its registry entry. There is no option
|
|
@@ -135,8 +133,6 @@
|
|
|
135
133
|
const detail = getSelectedItemDetail(target);
|
|
136
134
|
|
|
137
135
|
value = detail.value;
|
|
138
|
-
|
|
139
|
-
_onChange();
|
|
140
136
|
onChange?.(new CustomEvent('Change', { detail }));
|
|
141
137
|
};
|
|
142
138
|
|
|
@@ -149,7 +145,6 @@
|
|
|
149
145
|
const { target } = /** @type {Event & { target: HTMLInputElement }} */ (event);
|
|
150
146
|
|
|
151
147
|
value = target.value;
|
|
152
|
-
_onChange();
|
|
153
148
|
restProps.oninput?.(event);
|
|
154
149
|
onChange?.(
|
|
155
150
|
new CustomEvent('Change', {
|
|
@@ -168,21 +163,16 @@
|
|
|
168
163
|
* whose label starts with what has been typed, without expanding the dropdown — the way a native
|
|
169
164
|
* `<select>` behaves and the Select-Only Combobox pattern expects. There is no option element to
|
|
170
165
|
* report while the dropdown is collapsed, so the `Change` event carries the registry entry.
|
|
166
|
+
*
|
|
167
|
+
* With `selectOnTypeAhead` disabled, as in `<SelectTags>` where every change commits a tag, a
|
|
168
|
+
* printable character opens the dropdown instead, and goes into the filter if it’s shown, so the
|
|
169
|
+
* user can narrow down the options before picking one.
|
|
171
170
|
* @param {KeyboardEvent} event The `keydown` event.
|
|
172
171
|
*/
|
|
173
172
|
const onComboboxKeyDown = (event) => {
|
|
174
|
-
const { key
|
|
175
|
-
|
|
176
|
-
if (
|
|
177
|
-
disabled ||
|
|
178
|
-
readonly ||
|
|
179
|
-
isPopupOpen ||
|
|
180
|
-
key.length !== 1 ||
|
|
181
|
-
key === ' ' ||
|
|
182
|
-
ctrlKey ||
|
|
183
|
-
metaKey ||
|
|
184
|
-
altKey
|
|
185
|
-
) {
|
|
173
|
+
const { key } = event;
|
|
174
|
+
|
|
175
|
+
if (disabled || readonly || isPopupOpen || !isPrintableKey(event)) {
|
|
186
176
|
return;
|
|
187
177
|
}
|
|
188
178
|
|
|
@@ -190,11 +180,18 @@
|
|
|
190
180
|
// a printable key on a non-editable element starts Firefox’s find-as-you-type.
|
|
191
181
|
event.preventDefault();
|
|
192
182
|
|
|
183
|
+
if (!selectOnTypeAhead) {
|
|
184
|
+
pendingSearchTerms = key;
|
|
185
|
+
isPopupOpen = true;
|
|
186
|
+
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
193
190
|
const entries = registry.entries.filter((entry) => !entry.disabled);
|
|
194
191
|
|
|
195
|
-
const index =
|
|
196
|
-
entries.map((entry) =>
|
|
197
|
-
|
|
192
|
+
const index = typeAhead.match(
|
|
193
|
+
entries.map((entry) => entry.label ?? ''),
|
|
194
|
+
key,
|
|
198
195
|
entries.findIndex((entry) => entry.value === value),
|
|
199
196
|
);
|
|
200
197
|
|
|
@@ -209,7 +206,6 @@
|
|
|
209
206
|
}
|
|
210
207
|
|
|
211
208
|
value = entry.value;
|
|
212
|
-
_onChange();
|
|
213
209
|
dispatchEntryChange(entry);
|
|
214
210
|
};
|
|
215
211
|
|
|
@@ -239,8 +235,7 @@
|
|
|
239
235
|
}
|
|
240
236
|
|
|
241
237
|
// `<Group>` tracks the focused member with this class, and moves it on from there
|
|
242
|
-
option
|
|
243
|
-
listbox.setAttribute('aria-activedescendant', option.id);
|
|
238
|
+
setFocusedMember(listbox, option);
|
|
244
239
|
|
|
245
240
|
option.scrollIntoView(true);
|
|
246
241
|
};
|
|
@@ -299,15 +294,15 @@
|
|
|
299
294
|
}
|
|
300
295
|
|
|
301
296
|
value = entry.value;
|
|
302
|
-
label = entry.label;
|
|
303
297
|
|
|
304
298
|
// There is no element to report while the dropdown has never been expanded
|
|
305
299
|
dispatchEntryChange(entry);
|
|
306
300
|
});
|
|
307
301
|
|
|
302
|
+
// Mark the option matching the value as selected. A value that matches no option, including
|
|
303
|
+
// `undefined`, deselects every option, so the previous option doesn’t stay selected.
|
|
308
304
|
$effect(() => {
|
|
309
|
-
|
|
310
|
-
_onChange();
|
|
305
|
+
registry.selectOnly(value);
|
|
311
306
|
});
|
|
312
307
|
</script>
|
|
313
308
|
|
|
@@ -423,7 +418,8 @@
|
|
|
423
418
|
bind:open={isPopupOpen}
|
|
424
419
|
onOpen={() => {
|
|
425
420
|
showFilter = filterThreshold === -1 ? false : registry.count > filterThreshold;
|
|
426
|
-
searchTerms = '';
|
|
421
|
+
searchTerms = showFilter ? pendingSearchTerms : '';
|
|
422
|
+
pendingSearchTerms = '';
|
|
427
423
|
}}
|
|
428
424
|
>
|
|
429
425
|
<div role="none" class="combobox-inner">
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { getDropIndex, getDropTarget, getKeyboardMoveTarget, moveItem } from './select-tags.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* @import {
|
|
12
|
+
* @import { ContainerProps, FormFieldStateProps, WidgetStateProps } from '../../typedefs.js';
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -17,17 +17,6 @@
|
|
|
17
17
|
* @property {{ label: string, value: any, searchValue?: string }[]} options Available options.
|
|
18
18
|
* @property {string[]} [values] Selected option values.
|
|
19
19
|
* @property {number} [max] Maximum number of selectable options.
|
|
20
|
-
* @property {string} [class] The `class` attribute on the wrapper element.
|
|
21
|
-
* @property {boolean} [hidden] Whether to hide the widget.
|
|
22
|
-
* @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
|
|
23
|
-
* attribute.
|
|
24
|
-
* @property {boolean} [readonly] Whether to make the widget read-only. An alias of the
|
|
25
|
-
* `aria-readonly` attribute.
|
|
26
|
-
* @property {boolean} [required] Whether to mark the widget required. An alias of the
|
|
27
|
-
* `aria-required` attribute.
|
|
28
|
-
* @property {boolean} [invalid] Whether to mark the widget invalid. An alias of the
|
|
29
|
-
* `aria-invalid` attribute.
|
|
30
|
-
* @property {Snippet} [children] Primary slot content.
|
|
31
20
|
* @property {(event: CustomEvent<{ value: string }>) => void} [onAddValue] Custom `AddValue`
|
|
32
21
|
* event handler.
|
|
33
22
|
* @property {(event: CustomEvent<{ value: string }>) => void} [onRemoveValue] Custom
|
|
@@ -37,7 +26,7 @@
|
|
|
37
26
|
*/
|
|
38
27
|
|
|
39
28
|
/**
|
|
40
|
-
* @type {Props & Record<string, any>}
|
|
29
|
+
* @type {ContainerProps & WidgetStateProps & FormFieldStateProps & Props & Record<string, any>}
|
|
41
30
|
*/
|
|
42
31
|
let {
|
|
43
32
|
/* eslint-disable prefer-const */
|
|
@@ -255,6 +244,7 @@
|
|
|
255
244
|
{readonly}
|
|
256
245
|
{required}
|
|
257
246
|
{invalid}
|
|
247
|
+
selectOnTypeAhead={false}
|
|
258
248
|
onChange={() => {
|
|
259
249
|
// The select only reports a change once an option has been picked. Check for `undefined`
|
|
260
250
|
// rather than a falsy value, as `null`, `false`, `0` and an empty string are valid values
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export default SelectTags;
|
|
2
2
|
type SelectTags = {
|
|
3
3
|
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
-
$set?(props: Partial<Props & Record<string, any>>): void;
|
|
4
|
+
$set?(props: Partial<ContainerProps & WidgetStateProps & FormFieldStateProps & Props & Record<string, any>>): void;
|
|
5
5
|
};
|
|
6
|
-
declare const SelectTags: import("svelte").Component<{
|
|
6
|
+
declare const SelectTags: import("svelte").Component<ContainerProps & WidgetStateProps & FormFieldStateProps & {
|
|
7
7
|
/**
|
|
8
8
|
* Available options.
|
|
9
9
|
*/
|
|
@@ -20,38 +20,6 @@ declare const SelectTags: import("svelte").Component<{
|
|
|
20
20
|
* Maximum number of selectable options.
|
|
21
21
|
*/
|
|
22
22
|
max?: number | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* The `class` attribute on the wrapper element.
|
|
25
|
-
*/
|
|
26
|
-
class?: string | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* Whether to hide the widget.
|
|
29
|
-
*/
|
|
30
|
-
hidden?: boolean | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
33
|
-
* attribute.
|
|
34
|
-
*/
|
|
35
|
-
disabled?: boolean | undefined;
|
|
36
|
-
/**
|
|
37
|
-
* Whether to make the widget read-only. An alias of the
|
|
38
|
-
* `aria-readonly` attribute.
|
|
39
|
-
*/
|
|
40
|
-
readonly?: boolean | undefined;
|
|
41
|
-
/**
|
|
42
|
-
* Whether to mark the widget required. An alias of the
|
|
43
|
-
* `aria-required` attribute.
|
|
44
|
-
*/
|
|
45
|
-
required?: boolean | undefined;
|
|
46
|
-
/**
|
|
47
|
-
* Whether to mark the widget invalid. An alias of the
|
|
48
|
-
* `aria-invalid` attribute.
|
|
49
|
-
*/
|
|
50
|
-
invalid?: boolean | undefined;
|
|
51
|
-
/**
|
|
52
|
-
* Primary slot content.
|
|
53
|
-
*/
|
|
54
|
-
children?: Snippet<[]> | undefined;
|
|
55
23
|
/**
|
|
56
24
|
* Custom `AddValue`
|
|
57
25
|
* event handler.
|
|
@@ -91,38 +59,6 @@ type Props = {
|
|
|
91
59
|
* Maximum number of selectable options.
|
|
92
60
|
*/
|
|
93
61
|
max?: number | undefined;
|
|
94
|
-
/**
|
|
95
|
-
* The `class` attribute on the wrapper element.
|
|
96
|
-
*/
|
|
97
|
-
class?: string | undefined;
|
|
98
|
-
/**
|
|
99
|
-
* Whether to hide the widget.
|
|
100
|
-
*/
|
|
101
|
-
hidden?: boolean | undefined;
|
|
102
|
-
/**
|
|
103
|
-
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
104
|
-
* attribute.
|
|
105
|
-
*/
|
|
106
|
-
disabled?: boolean | undefined;
|
|
107
|
-
/**
|
|
108
|
-
* Whether to make the widget read-only. An alias of the
|
|
109
|
-
* `aria-readonly` attribute.
|
|
110
|
-
*/
|
|
111
|
-
readonly?: boolean | undefined;
|
|
112
|
-
/**
|
|
113
|
-
* Whether to mark the widget required. An alias of the
|
|
114
|
-
* `aria-required` attribute.
|
|
115
|
-
*/
|
|
116
|
-
required?: boolean | undefined;
|
|
117
|
-
/**
|
|
118
|
-
* Whether to mark the widget invalid. An alias of the
|
|
119
|
-
* `aria-invalid` attribute.
|
|
120
|
-
*/
|
|
121
|
-
invalid?: boolean | undefined;
|
|
122
|
-
/**
|
|
123
|
-
* Primary slot content.
|
|
124
|
-
*/
|
|
125
|
-
children?: Snippet<[]> | undefined;
|
|
126
62
|
/**
|
|
127
63
|
* Custom `AddValue`
|
|
128
64
|
* event handler.
|
|
@@ -145,4 +81,6 @@ type Props = {
|
|
|
145
81
|
values: string[];
|
|
146
82
|
}>) => void) | undefined;
|
|
147
83
|
};
|
|
148
|
-
import type {
|
|
84
|
+
import type { ContainerProps } from '../../typedefs.js';
|
|
85
|
+
import type { WidgetStateProps } from '../../typedefs.js';
|
|
86
|
+
import type { FormFieldStateProps } from '../../typedefs.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function getSliderSteps({ min, max, step, barWidth }: {
|
|
1
|
+
export function getSliderSteps({ min, max, step: _step, barWidth }: {
|
|
2
2
|
min: number;
|
|
3
3
|
max: number;
|
|
4
4
|
step: number;
|
|
@@ -16,11 +16,12 @@ export function getSliderKeyTargetIndex({ key, rtl, currentIndex, length }: {
|
|
|
16
16
|
currentIndex: number;
|
|
17
17
|
length: number;
|
|
18
18
|
}): number;
|
|
19
|
-
export function
|
|
19
|
+
export function clampThumbIndex({ valueIndex, index, positionList, sliderPositions }: {
|
|
20
20
|
valueIndex: number;
|
|
21
|
-
|
|
21
|
+
index: number;
|
|
22
|
+
positionList: number[];
|
|
22
23
|
sliderPositions: number[];
|
|
23
|
-
}):
|
|
24
|
+
}): number;
|
|
24
25
|
export function getSliderCurrentIndex({ valueList, value, decreasing }: {
|
|
25
26
|
valueList: number[];
|
|
26
27
|
value: number;
|
|
@@ -1,42 +1,40 @@
|
|
|
1
1
|
import { getArrowKeys } from '../../services/navigation.js';
|
|
2
|
+
import { getMaximumFractionDigits, normalizeStep } from '../../services/number.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Geometry and keyboard logic behind `<Slider>`, kept apart from the component so the value
|
|
5
6
|
* calculations can be tested without a rendered track.
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
|
-
/**
|
|
9
|
-
* Count the fraction digits of a number, including one written in exponential notation, such as
|
|
10
|
-
* `1e-7`.
|
|
11
|
-
* @param {number} num Number.
|
|
12
|
-
* @returns {number} Number of fraction digits, `0` for an integer.
|
|
13
|
-
*/
|
|
14
|
-
const countFractionDigits = (num) => {
|
|
15
|
-
const [mantissa, exponent = '0'] = String(num).split('e');
|
|
16
|
-
|
|
17
|
-
return Math.min(Math.max((mantissa.split('.')[1] ?? '').length - Number(exponent), 0), 100);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
9
|
/**
|
|
21
10
|
* Get the values a thumb can take and where each of them sits along the track.
|
|
22
11
|
* @param {object} options Options.
|
|
23
12
|
* @param {number} options.min Minimum value.
|
|
24
13
|
* @param {number} options.max Maximum value.
|
|
25
|
-
* @param {number} options.step Distance between two values.
|
|
14
|
+
* @param {number} options.step Distance between two values. `1` is used instead if it isn’t a
|
|
15
|
+
* positive number.
|
|
26
16
|
* @param {number} options.barWidth Width of the track in pixels.
|
|
27
17
|
* @returns {{ valueList: number[], positionList: number[] }} Values from `min` to `max` in `step`
|
|
28
18
|
* increments, and the matching pixel offsets from the logical start of the track.
|
|
29
19
|
*/
|
|
30
|
-
export const getSliderSteps = ({ min, max, step, barWidth }) => {
|
|
20
|
+
export const getSliderSteps = ({ min, max, step: _step, barWidth }) => {
|
|
21
|
+
// Fall back to `1` for a step that isn’t a positive number: `0` would make the step count
|
|
22
|
+
// infinite, while a negative step would leave no values at all
|
|
23
|
+
const step = normalizeStep(_step);
|
|
31
24
|
const stepRatio = (max - min) / step;
|
|
32
25
|
// Tolerate floating point errors, e.g. `0.3 / 0.1` is `2.9999999999999996`, which would otherwise
|
|
33
26
|
// drop the maximum
|
|
34
27
|
const stepCount = Math.floor(stepRatio + 1e-9) + 1;
|
|
35
28
|
const stepWidth = barWidth / stepRatio;
|
|
36
29
|
const emptyArray = Array.from({ length: stepCount });
|
|
30
|
+
|
|
37
31
|
// Round the values to the precision of the minimum and the step, e.g. `3 * 0.1` is
|
|
38
|
-
// `0.30000000000000004`, which would otherwise never match the `0.3` value
|
|
39
|
-
|
|
32
|
+
// `0.30000000000000004`, which would otherwise never match the `0.3` value. `toFixed()` accepts
|
|
33
|
+
// up to 100 digits
|
|
34
|
+
const decimals = Math.min(
|
|
35
|
+
Math.max(getMaximumFractionDigits(min), getMaximumFractionDigits(step)),
|
|
36
|
+
100,
|
|
37
|
+
);
|
|
40
38
|
|
|
41
39
|
return {
|
|
42
40
|
valueList: emptyArray.map((_, index) => Number((index * step + min).toFixed(decimals))),
|
|
@@ -146,17 +144,24 @@ export const getSliderKeyTargetIndex = ({ key, rtl, currentIndex, length }) => {
|
|
|
146
144
|
};
|
|
147
145
|
|
|
148
146
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
147
|
+
* Clamp the step a thumb of a multi-thumb slider moves to, so it stops one step short of the other
|
|
148
|
+
* thumb instead of crossing or landing on it. A move that overshoots, like Home on the second thumb
|
|
149
|
+
* or a fast drag past the other thumb, still brings the thumb as close as it can get.
|
|
151
150
|
* @param {object} options Options.
|
|
152
151
|
* @param {number} options.valueIndex Index of the thumb being moved, `0` or `1`.
|
|
153
|
-
* @param {number} options.
|
|
152
|
+
* @param {number} options.index Index of the step the thumb would move to.
|
|
153
|
+
* @param {number[]} options.positionList Pixel offset of each step, in ascending order.
|
|
154
154
|
* @param {number[]} options.sliderPositions Current position of each thumb, in pixels.
|
|
155
|
-
* @returns {
|
|
155
|
+
* @returns {number} Index of the step the thumb can move to, or `-1` if there’s no room for it.
|
|
156
156
|
*/
|
|
157
|
-
export const
|
|
158
|
-
(valueIndex === 0
|
|
159
|
-
|
|
157
|
+
export const clampThumbIndex = ({ valueIndex, index, positionList, sliderPositions }) => {
|
|
158
|
+
const otherIndex = findNearestStepIndex(positionList, sliderPositions[valueIndex === 0 ? 1 : 0]);
|
|
159
|
+
|
|
160
|
+
const clampedIndex =
|
|
161
|
+
valueIndex === 0 ? Math.min(index, otherIndex - 1) : Math.max(index, otherIndex + 1);
|
|
162
|
+
|
|
163
|
+
return clampedIndex < 0 || clampedIndex >= positionList.length ? -1 : clampedIndex;
|
|
164
|
+
};
|
|
160
165
|
|
|
161
166
|
/**
|
|
162
167
|
* Get the step index a key press starts from. A value that sits between two steps, such as `55`
|