@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.
Files changed (226) hide show
  1. package/dist/components/bottom-navigation/bottom-navigation.svelte +3 -9
  2. package/dist/components/bottom-navigation/bottom-navigation.svelte.d.ts +4 -39
  3. package/dist/components/button/button-group.svelte +2 -4
  4. package/dist/components/button/button-group.svelte.d.ts +3 -19
  5. package/dist/components/button/select-button-group.svelte +2 -13
  6. package/dist/components/button/select-button-group.svelte.d.ts +5 -67
  7. package/dist/components/calendar/calendar.d.ts +9 -0
  8. package/dist/components/calendar/calendar.js +43 -0
  9. package/dist/components/calendar/calendar.svelte +26 -27
  10. package/dist/components/checkbox/checkbox-group.svelte +2 -8
  11. package/dist/components/checkbox/checkbox-group.svelte.d.ts +4 -39
  12. package/dist/components/dialog/alert-dialog.svelte.d.ts +2 -3
  13. package/dist/components/dialog/confirmation-dialog.svelte.d.ts +2 -3
  14. package/dist/components/dialog/dialog.svelte +6 -7
  15. package/dist/components/dialog/dialog.svelte.d.ts +2 -3
  16. package/dist/components/dialog/prompt-dialog.svelte +2 -2
  17. package/dist/components/dialog/prompt-dialog.svelte.d.ts +2 -3
  18. package/dist/components/disclosure/disclosure.svelte +14 -16
  19. package/dist/components/disclosure/disclosure.svelte.d.ts +4 -38
  20. package/dist/components/drawer/drawer.svelte +22 -39
  21. package/dist/components/drawer/drawer.svelte.d.ts +3 -24
  22. package/dist/components/grid/grid-body.svelte +2 -3
  23. package/dist/components/grid/grid-body.svelte.d.ts +3 -18
  24. package/dist/components/grid/grid-cell.svelte +2 -8
  25. package/dist/components/grid/grid-cell.svelte.d.ts +3 -22
  26. package/dist/components/grid/grid-col-header.svelte +2 -4
  27. package/dist/components/grid/grid-col-header.svelte.d.ts +3 -19
  28. package/dist/components/grid/grid-foot.svelte +4 -9
  29. package/dist/components/grid/grid-foot.svelte.d.ts +3 -22
  30. package/dist/components/grid/grid-head.svelte +4 -9
  31. package/dist/components/grid/grid-head.svelte.d.ts +3 -22
  32. package/dist/components/grid/grid-row-header.svelte +2 -8
  33. package/dist/components/grid/grid-row-header.svelte.d.ts +3 -22
  34. package/dist/components/grid/grid-row.svelte +4 -5
  35. package/dist/components/grid/grid-row.svelte.d.ts +3 -19
  36. package/dist/components/grid/grid.d.ts +10 -0
  37. package/dist/components/grid/grid.js +11 -0
  38. package/dist/components/grid/grid.svelte +6 -7
  39. package/dist/components/grid/grid.svelte.d.ts +5 -21
  40. package/dist/components/listbox/listbox.svelte +34 -15
  41. package/dist/components/listbox/listbox.svelte.d.ts +5 -69
  42. package/dist/components/listbox/option-group.svelte +2 -8
  43. package/dist/components/listbox/option-group.svelte.d.ts +4 -39
  44. package/dist/components/listbox/option.svelte +2 -1
  45. package/dist/components/menu/menu-item-group.svelte +2 -6
  46. package/dist/components/menu/menu-item-group.svelte.d.ts +3 -22
  47. package/dist/components/menu/menu-item.svelte +5 -1
  48. package/dist/components/menu/menu.svelte +2 -8
  49. package/dist/components/menu/menu.svelte.d.ts +4 -39
  50. package/dist/components/radio/radio-group.svelte +2 -17
  51. package/dist/components/radio/radio-group.svelte.d.ts +5 -67
  52. package/dist/components/radio/radio.svelte +19 -22
  53. package/dist/components/radio/radio.svelte.d.ts +10 -40
  54. package/dist/components/resizable-pane/resizable-handle.svelte +42 -49
  55. package/dist/components/resizable-pane/resizable-pane-group.svelte +44 -58
  56. package/dist/components/resizable-pane/resizable-pane-group.svelte.d.ts +3 -19
  57. package/dist/components/resizable-pane/resizable-pane.svelte +2 -5
  58. package/dist/components/resizable-pane/resizable-pane.svelte.d.ts +3 -19
  59. package/dist/components/resizable-pane/sizing.d.ts +24 -0
  60. package/dist/components/resizable-pane/sizing.js +83 -0
  61. package/dist/components/select/combobox.svelte +35 -39
  62. package/dist/components/select/select-tags.svelte +3 -13
  63. package/dist/components/select/select-tags.svelte.d.ts +5 -67
  64. package/dist/components/slider/slider.d.ts +5 -4
  65. package/dist/components/slider/slider.js +28 -23
  66. package/dist/components/slider/slider.svelte +64 -62
  67. package/dist/components/slider/slider.svelte.d.ts +4 -37
  68. package/dist/components/switch/switch.svelte +2 -13
  69. package/dist/components/switch/switch.svelte.d.ts +5 -67
  70. package/dist/components/table/table-body.svelte +2 -4
  71. package/dist/components/table/table-body.svelte.d.ts +3 -19
  72. package/dist/components/table/table-cell.svelte +2 -8
  73. package/dist/components/table/table-cell.svelte.d.ts +3 -22
  74. package/dist/components/table/table-col-header.svelte +2 -8
  75. package/dist/components/table/table-col-header.svelte.d.ts +3 -22
  76. package/dist/components/table/table-foot.svelte +2 -8
  77. package/dist/components/table/table-foot.svelte.d.ts +3 -22
  78. package/dist/components/table/table-head.svelte +2 -8
  79. package/dist/components/table/table-head.svelte.d.ts +3 -22
  80. package/dist/components/table/table-part.svelte +2 -4
  81. package/dist/components/table/table-part.svelte.d.ts +3 -19
  82. package/dist/components/table/table-row-header.svelte +2 -8
  83. package/dist/components/table/table-row-header.svelte.d.ts +3 -22
  84. package/dist/components/table/table-row.svelte +2 -8
  85. package/dist/components/table/table-row.svelte.d.ts +3 -22
  86. package/dist/components/table/table.svelte +2 -4
  87. package/dist/components/table/table.svelte.d.ts +3 -19
  88. package/dist/components/tabs/tab-box.svelte +2 -4
  89. package/dist/components/tabs/tab-box.svelte.d.ts +3 -19
  90. package/dist/components/tabs/tab-list.svelte +2 -7
  91. package/dist/components/tabs/tab-list.svelte.d.ts +4 -37
  92. package/dist/components/tabs/tab-panel.svelte +2 -8
  93. package/dist/components/tabs/tab-panel.svelte.d.ts +3 -22
  94. package/dist/components/tabs/tab-panels.svelte +2 -8
  95. package/dist/components/tabs/tab-panels.svelte.d.ts +3 -22
  96. package/dist/components/text-editor/code-editor.js +14 -7
  97. package/dist/components/text-editor/code-editor.svelte +14 -22
  98. package/dist/components/text-editor/code-editor.svelte.d.ts +5 -103
  99. package/dist/components/text-editor/config.d.ts +73 -0
  100. package/dist/components/text-editor/config.js +110 -0
  101. package/dist/components/text-editor/conversion/editor-components.js +4 -4
  102. package/dist/components/text-editor/conversion/html/export.js +1 -1
  103. package/dist/components/text-editor/conversion/import.js +32 -26
  104. package/dist/components/text-editor/conversion/markdown/block-conversion.d.ts +4 -0
  105. package/dist/components/text-editor/conversion/markdown/block-conversion.js +154 -0
  106. package/dist/components/text-editor/conversion/markdown/block-structure.d.ts +16 -0
  107. package/dist/components/text-editor/conversion/markdown/block-structure.js +254 -0
  108. package/dist/components/text-editor/conversion/markdown/code-blocks.d.ts +57 -0
  109. package/dist/components/text-editor/conversion/markdown/code-blocks.js +279 -0
  110. package/dist/components/text-editor/conversion/markdown/code-spans.d.ts +19 -0
  111. package/dist/components/text-editor/conversion/markdown/code-spans.js +71 -0
  112. package/dist/components/text-editor/conversion/markdown/formatting.d.ts +22 -0
  113. package/dist/components/text-editor/conversion/markdown/formatting.js +451 -0
  114. package/dist/components/text-editor/conversion/markdown/index.d.ts +10 -0
  115. package/dist/components/text-editor/conversion/markdown/index.js +55 -0
  116. package/dist/components/text-editor/conversion/markdown/placeholders.d.ts +2 -0
  117. package/dist/components/text-editor/conversion/markdown/placeholders.js +229 -0
  118. package/dist/components/text-editor/conversion/markdown/syntax.d.ts +99 -0
  119. package/dist/components/text-editor/conversion/markdown/syntax.js +206 -0
  120. package/dist/components/text-editor/conversion/placeholder-chars.d.ts +43 -0
  121. package/dist/components/text-editor/conversion/placeholder-chars.js +51 -0
  122. package/dist/components/text-editor/conversion/transformers/block-escape.d.ts +1 -0
  123. package/dist/components/text-editor/conversion/transformers/block-escape.js +53 -26
  124. package/dist/components/text-editor/conversion/transformers/code.d.ts +3 -14
  125. package/dist/components/text-editor/conversion/transformers/code.js +78 -16
  126. package/dist/components/text-editor/conversion/transformers/formatted-code.js +3 -18
  127. package/dist/components/text-editor/conversion/transformers/inline-code.js +3 -1
  128. package/dist/components/text-editor/conversion/transformers/link.js +3 -1
  129. package/dist/components/text-editor/conversion/transformers/raw-syntax.d.ts +0 -19
  130. package/dist/components/text-editor/conversion/transformers/raw-syntax.js +22 -93
  131. package/dist/components/text-editor/conversion/transformers/table.js +57 -16
  132. package/dist/components/text-editor/conversion/update.d.ts +19 -2
  133. package/dist/components/text-editor/conversion/update.js +63 -39
  134. package/dist/components/text-editor/core.d.ts +12 -51
  135. package/dist/components/text-editor/core.js +44 -66
  136. package/dist/components/text-editor/editing/raw-markdown.d.ts +3 -0
  137. package/dist/components/text-editor/editing/raw-markdown.js +46 -2
  138. package/dist/components/text-editor/lexical-root.svelte +49 -47
  139. package/dist/components/text-editor/lexical-root.svelte.d.ts +4 -67
  140. package/dist/components/text-editor/shiki/{facade.d.ts → engine.d.ts} +8 -8
  141. package/dist/components/text-editor/shiki/{facade.js → engine.js} +53 -156
  142. package/dist/components/text-editor/shiki/highlighter.js +5 -5
  143. package/dist/components/text-editor/shiki/lexical.d.ts +6 -0
  144. package/dist/components/text-editor/shiki/lexical.js +165 -0
  145. package/dist/components/text-editor/shiki/preload.js +1 -1
  146. package/dist/components/text-editor/shiki/source-highlight.svelte.d.ts +15 -0
  147. package/dist/components/text-editor/shiki/source-highlight.svelte.js +120 -0
  148. package/dist/components/text-editor/shiki/version.d.ts +1 -1
  149. package/dist/components/text-editor/shiki/version.js +1 -1
  150. package/dist/components/text-editor/store.svelte.js +65 -16
  151. package/dist/components/text-editor/text-editor.svelte +53 -145
  152. package/dist/components/text-editor/text-editor.svelte.d.ts +5 -103
  153. package/dist/components/text-editor/toolbar/actions.d.ts +25 -0
  154. package/dist/components/text-editor/toolbar/actions.js +107 -0
  155. package/dist/components/text-editor/toolbar/align-menu-button.svelte +16 -14
  156. package/dist/components/text-editor/toolbar/format-text-button.svelte +26 -24
  157. package/dist/components/text-editor/toolbar/insert-horizontal-rule-button.svelte +23 -23
  158. package/dist/components/text-editor/toolbar/insert-item-button.svelte +1 -1
  159. package/dist/components/text-editor/toolbar/insert-link-button.svelte +47 -51
  160. package/dist/components/text-editor/toolbar/insert-menu-button.svelte +1 -1
  161. package/dist/components/text-editor/toolbar/insert-table-button.svelte +35 -52
  162. package/dist/components/text-editor/toolbar/table-action-menu.svelte +19 -17
  163. package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte +16 -4
  164. package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte.d.ts +0 -8
  165. package/dist/components/text-editor/toolbar/toggle-block-menu-item.svelte +34 -33
  166. package/dist/components/text-editor/widgets/emoji-autocomplete.svelte +7 -6
  167. package/dist/components/text-editor/widgets/floating-link-editor.svelte +19 -32
  168. package/dist/components/text-editor/widgets/table-cell-menu-button.svelte +28 -32
  169. package/dist/components/text-field/date-time-input.svelte +7 -8
  170. package/dist/components/text-field/date-time-input.svelte.d.ts +3 -32
  171. package/dist/components/text-field/number-input.d.ts +0 -2
  172. package/dist/components/text-field/number-input.js +25 -25
  173. package/dist/components/text-field/number-input.svelte +18 -9
  174. package/dist/components/text-field/number-input.svelte.d.ts +1 -1
  175. package/dist/components/text-field/text-area.d.ts +2 -0
  176. package/dist/components/text-field/text-area.js +31 -0
  177. package/dist/components/text-field/text-area.svelte +12 -25
  178. package/dist/components/text-field/text-area.svelte.d.ts +5 -67
  179. package/dist/components/toast/toast.svelte +31 -8
  180. package/dist/components/toast/toast.svelte.d.ts +6 -6
  181. package/dist/components/toolbar/toolbar.svelte +2 -7
  182. package/dist/components/toolbar/toolbar.svelte.d.ts +4 -37
  183. package/dist/components/tree/tree-item.svelte +2 -6
  184. package/dist/components/tree/tree-item.svelte.d.ts +3 -22
  185. package/dist/components/tree/tree.svelte +3 -10
  186. package/dist/components/tree/tree.svelte.d.ts +4 -39
  187. package/dist/components/util/group.svelte +2 -7
  188. package/dist/components/util/group.svelte.d.ts +4 -37
  189. package/dist/components/util/modal.d.ts +9 -0
  190. package/dist/components/util/modal.js +30 -0
  191. package/dist/components/util/modal.svelte +16 -12
  192. package/dist/index.d.ts +1 -1
  193. package/dist/index.js +1 -1
  194. package/dist/locales/hu.yaml +176 -0
  195. package/dist/services/composite-widget.svelte.d.ts +76 -0
  196. package/dist/services/composite-widget.svelte.js +157 -0
  197. package/dist/services/focus.d.ts +2 -0
  198. package/dist/services/focus.js +68 -0
  199. package/dist/services/group.svelte.d.ts +17 -69
  200. package/dist/services/group.svelte.js +128 -391
  201. package/dist/services/label.d.ts +9 -0
  202. package/dist/services/label.js +22 -0
  203. package/dist/services/menu.d.ts +8 -0
  204. package/dist/services/menu.js +237 -0
  205. package/dist/services/navigation.d.ts +9 -0
  206. package/dist/services/navigation.js +13 -0
  207. package/dist/services/number.d.ts +2 -0
  208. package/dist/services/number.js +27 -0
  209. package/dist/services/pointer-drag.d.ts +14 -0
  210. package/dist/services/pointer-drag.js +89 -0
  211. package/dist/services/popup.svelte.js +123 -103
  212. package/dist/services/text.d.ts +3 -0
  213. package/dist/services/text.js +17 -0
  214. package/dist/services/tree.svelte.d.ts +29 -43
  215. package/dist/services/tree.svelte.js +58 -105
  216. package/dist/services/type-ahead.d.ts +10 -1
  217. package/dist/services/type-ahead.js +56 -34
  218. package/dist/typedefs.d.ts +103 -4
  219. package/dist/typedefs.js +60 -4
  220. package/package.json +1 -1
  221. package/dist/components/text-editor/conversion/markdown.d.ts +0 -56
  222. package/dist/components/text-editor/conversion/markdown.js +0 -949
  223. package/dist/components/text-editor/toolbar/code-editor-toolbar.svelte +0 -28
  224. package/dist/components/text-editor/toolbar/code-editor-toolbar.svelte.d.ts +0 -37
  225. package/dist/components/text-editor/toolbar/insert-component.d.ts +0 -3
  226. 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 { normalize } from '../../services/text.js';
11
+ import { setFocusedMember } from '../../services/group.svelte.js';
12
12
  import { createOptionRegistry, getSelectedItemDetail } from '../../services/select.svelte.js';
13
- import { findTypeAheadMatch, TypeAhead } from '../../services/type-ahead.js';
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
- * Update the {@link label} and selected option when the {@link value} is changed. A value that
106
- * matches no option, including `undefined`, clears both, so the previous option doesn’t stay
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 _onChange = () => {
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, ctrlKey, metaKey, altKey } = event;
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 = findTypeAheadMatch(
196
- entries.map((entry) => normalize(entry.label ?? '')),
197
- typeAhead.push(key),
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.classList.add('focused');
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
- void value;
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 { Snippet } from 'svelte';
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 { Snippet } from 'svelte';
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 wouldCrossThumbs({ valueIndex, targetPosition, sliderPositions }: {
19
+ export function clampThumbIndex({ valueIndex, index, positionList, sliderPositions }: {
20
20
  valueIndex: number;
21
- targetPosition: number;
21
+ index: number;
22
+ positionList: number[];
22
23
  sliderPositions: number[];
23
- }): boolean;
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
- const decimals = Math.max(countFractionDigits(min), countFractionDigits(step));
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
- * Whether moving one thumb of a multi-thumb slider to the given position would make it cross, or
150
- * land on, the other thumb.
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.targetPosition Position the thumb would move to, in pixels.
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 {boolean} `true` if the move would cross the other thumb.
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 wouldCrossThumbs = ({ valueIndex, targetPosition, sliderPositions }) =>
158
- (valueIndex === 0 && sliderPositions[1] <= targetPosition) ||
159
- (valueIndex === 1 && sliderPositions[0] >= targetPosition);
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`