@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.
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 +33 -14
  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 +2 -2
  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
@@ -1,15 +1,10 @@
1
1
  import { isRTL } from '@sveltia/i18n';
2
2
  import { generateElementId } from '@sveltia/utils/element';
3
+ import { CompositeWidget, createWidgetAttachment } from './composite-widget.svelte.js';
3
4
  import { getArrowKeys } from './navigation.js';
4
5
  import { scrollIntoViewIfNeeded } from './scroll.js';
5
- import { normalize } from './text.js';
6
- import { getSelectedItemDetail } from './select.svelte.js';
7
- import { findTypeAheadMatch, TypeAhead } from './type-ahead.js';
8
- import { activateBefore, activateLater } from './widget.js';
9
-
10
- /**
11
- * @import { Attachment } from 'svelte/attachments';
12
- */
6
+ import { getItemLabel } from './text.js';
7
+ import { isPrintableKey } from './type-ahead.js';
13
8
 
14
9
  /**
15
10
  * CSS selector to retrieve the tree items.
@@ -23,13 +18,7 @@ const ITEM_SELECTOR = '[role="treeitem"]';
23
18
  * expanding and collapsing parent nodes.
24
19
  * @see https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
25
20
  */
26
- export class Tree {
27
- /**
28
- * Keystroke buffer for type-ahead.
29
- * @type {TypeAhead}
30
- */
31
- #typeAhead = new TypeAhead();
32
-
21
+ export class Tree extends CompositeWidget {
33
22
  /**
34
23
  * Initialize a new `Tree` instance.
35
24
  * @param {HTMLElement} parent Parent element.
@@ -40,44 +29,36 @@ export class Tree {
40
29
  * @param {boolean} [options.expandOnSelect] Whether to expand or collapse a parent item when the
41
30
  * item itself, rather than its chevron, is clicked or activated.
42
31
  */
43
- constructor(parent, { clickToSelect = true, selectionFollowsFocus, expandOnSelect = true } = {}) {
44
- parent.dispatchEvent(new CustomEvent('Initializing'));
32
+ constructor(parent, options = {}) {
33
+ super(parent);
45
34
 
46
- this.parent = parent;
47
35
  this.id = generateElementId('tree');
48
- this.clickToSelect = clickToSelect;
49
- this.expandOnSelect = expandOnSelect;
50
36
 
51
37
  /**
52
- * Whether the selection follows the focus. `undefined` means auto detect.
53
- * @type {boolean | undefined}
38
+ * Whether to select an item by clicking on it.
39
+ * @type {boolean}
54
40
  */
55
- this.selectionFollowsFocusOption = selectionFollowsFocus;
41
+ this.clickToSelect = true;
56
42
 
57
43
  /**
58
- * Item used as the starting point of a range selection.
59
- * @type {HTMLElement | undefined}
44
+ * Whether to expand or collapse a parent item when the item itself is clicked or activated.
45
+ * @type {boolean}
60
46
  */
61
- this.anchor = undefined;
47
+ this.expandOnSelect = true;
62
48
 
63
49
  /**
64
- * Whether {@link activate} has run.
65
- * @type {boolean}
50
+ * Whether the selection follows the focus. `undefined` means auto detect.
51
+ * @type {boolean | undefined}
66
52
  */
67
- this.activated = false;
53
+ this.selectionFollowsFocusOption = undefined;
54
+
55
+ this.onUpdate(options);
68
56
 
69
57
  /**
70
- * Whether {@link destroy} has run, so a pending {@link activate} must not set anything up.
71
- * @type {boolean}
58
+ * Item used as the starting point of a range selection.
59
+ * @type {HTMLElement | undefined}
72
60
  */
73
- this.destroyed = false;
74
-
75
- /** @type {(event: MouseEvent) => void} */
76
- this._onClick = activateBefore(this, (event) => this.onClick(event));
77
- /** @type {(event: KeyboardEvent) => void} */
78
- this._onKeyDown = activateBefore(this, (event) => this.onKeyDown(event));
79
- /** @type {(event: FocusEvent) => void} */
80
- this._onFocusIn = activateBefore(this, (event) => this.onFocusIn(event));
61
+ this.anchor = undefined;
81
62
 
82
63
  // The items can be added or removed at any time, e.g. when a subtree is lazily rendered, and
83
64
  // collapsed, hidden or disabled from outside, e.g. with a “collapse all” button, which can take
@@ -91,34 +72,40 @@ export class Tree {
91
72
 
92
73
  // Listen right away: a click, a key press or a focus that comes before the activation below
93
74
  // activates the items first, rather than being lost
94
- parent.addEventListener('click', this._onClick);
95
- parent.addEventListener('keydown', this._onKeyDown);
96
- parent.addEventListener('focusin', this._onFocusIn);
97
-
98
- // Wait a bit before the child components are mounted. If the widget is unmounted in the
99
- // meantime, the observer set up by `activate()` would never be disconnected.
100
- activateLater(this, () => this.destroyed);
75
+ this.listen('click', (event) => this.onClick(event));
76
+ this.listen('keydown', (event) => this.onKeyDown(event));
77
+ this.listen('focusin', (event) => this.onFocusIn(event));
101
78
  }
102
79
 
103
80
  /**
104
- * Activate the items, unless they already are.
81
+ * Set up the items on activation. The observer is only connected here, rather than in the
82
+ * constructor, so a widget unmounted before its activation leaves nothing to disconnect.
83
+ * @override
105
84
  */
106
- activate() {
107
- if (this.activated) {
108
- return;
109
- }
110
-
111
- const { parent } = this;
112
-
113
- this.activated = true;
85
+ setUp() {
114
86
  this.update();
115
- this.observer.observe(parent, {
87
+ this.observer.observe(this.parent, {
116
88
  childList: true,
117
89
  subtree: true,
118
90
  attributes: true,
119
91
  attributeFilter: ['hidden', 'aria-hidden', 'aria-disabled', 'aria-expanded'],
120
92
  });
121
- parent.dispatchEvent(new CustomEvent('Initialized'));
93
+ }
94
+
95
+ /**
96
+ * Called whenever the params are updated, as well as on creation. Apply the options.
97
+ * @override
98
+ * @param {object} params Updated params.
99
+ * @param {boolean} [params.clickToSelect] Whether to select an item by clicking on it.
100
+ * @param {boolean} [params.selectionFollowsFocus] Whether to select an item as soon as it
101
+ * receives focus. Default: `true` on a single-select tree, `false` on a multi-select tree.
102
+ * @param {boolean} [params.expandOnSelect] Whether to expand or collapse a parent item when the
103
+ * item itself, rather than its chevron, is clicked or activated.
104
+ */
105
+ onUpdate({ clickToSelect = true, selectionFollowsFocus, expandOnSelect = true }) {
106
+ this.clickToSelect = clickToSelect;
107
+ this.selectionFollowsFocusOption = selectionFollowsFocus;
108
+ this.expandOnSelect = expandOnSelect;
122
109
  }
123
110
 
124
111
  /**
@@ -137,22 +124,6 @@ export class Tree {
137
124
  return this.selectionFollowsFocusOption ?? !this.multi;
138
125
  }
139
126
 
140
- /**
141
- * Whether the widget is disabled.
142
- * @type {boolean}
143
- */
144
- get isDisabled() {
145
- return this.parent.matches('[aria-disabled="true"]');
146
- }
147
-
148
- /**
149
- * Whether the widget is read-only.
150
- * @type {boolean}
151
- */
152
- get isReadOnly() {
153
- return this.parent.matches('[aria-readonly="true"]');
154
- }
155
-
156
127
  /**
157
128
  * List of all the items, including the ones within a collapsed parent, in document order.
158
129
  * @type {HTMLElement[]}
@@ -329,7 +300,7 @@ export class Tree {
329
300
  * @returns {string} Label.
330
301
  */
331
302
  getLabel(item) {
332
- return item.dataset.label ?? item.querySelector('.label')?.textContent ?? '';
303
+ return getItemLabel(item, { textFallback: false });
333
304
  }
334
305
 
335
306
  /**
@@ -371,14 +342,6 @@ export class Tree {
371
342
  this.setTabStop(current);
372
343
  }
373
344
 
374
- /**
375
- * Scroll the given element into view if needed.
376
- * @param {HTMLElement} element Element to be scrolled into view.
377
- */
378
- scrollIntoView(element) {
379
- scrollIntoViewIfNeeded(element);
380
- }
381
-
382
345
  /**
383
346
  * Put exactly one item in the tab order. Only the items actually in it are touched: writing a
384
347
  * `tabindex` to every item costs a pass over the whole widget on each arrow key, and all but one
@@ -411,7 +374,7 @@ export class Tree {
411
374
  this.setTabStop(item);
412
375
  item.focus();
413
376
  item.dispatchEvent(new CustomEvent('Focus'));
414
- this.scrollIntoView(item);
377
+ scrollIntoViewIfNeeded(item);
415
378
 
416
379
  if (select) {
417
380
  this.selectItem(item);
@@ -481,7 +444,7 @@ export class Tree {
481
444
  this.anchor = item;
482
445
  }
483
446
 
484
- this.parent.dispatchEvent(new CustomEvent('Change', { detail: getSelectedItemDetail(item) }));
447
+ this.dispatchChange(item);
485
448
  }
486
449
 
487
450
  /**
@@ -497,7 +460,7 @@ export class Tree {
497
460
  this.setSelected(element, true);
498
461
  });
499
462
 
500
- this.parent.dispatchEvent(new CustomEvent('Change', { detail: getSelectedItemDetail(item) }));
463
+ this.dispatchChange(item);
501
464
  }
502
465
 
503
466
  /**
@@ -549,9 +512,9 @@ export class Tree {
549
512
  typeAhead(char, currentItem) {
550
513
  const items = this.activeItems;
551
514
 
552
- const index = findTypeAheadMatch(
553
- items.map((item) => normalize(this.getLabel(item))),
554
- this.#typeAhead.push(char),
515
+ const index = this.typeAheadBuffer.match(
516
+ items.map((item) => this.getLabel(item)),
517
+ char,
555
518
  items.indexOf(currentItem),
556
519
  );
557
520
 
@@ -751,33 +714,23 @@ export class Tree {
751
714
  return;
752
715
  }
753
716
 
754
- if (key.length === 1 && key.trim()) {
717
+ if (isPrintableKey(event)) {
755
718
  this.typeAhead(key, currentItem);
756
719
  }
757
720
  }
758
721
 
759
722
  /**
760
- * Clean up event listeners.
723
+ * Clean up event listeners and the observer.
724
+ * @override
761
725
  */
762
726
  destroy() {
763
- this.destroyed = true;
764
- this.#typeAhead.reset();
727
+ super.destroy();
765
728
  this.observer.disconnect();
766
- this.parent.removeEventListener('click', this._onClick);
767
- this.parent.removeEventListener('keydown', this._onKeyDown);
768
- this.parent.removeEventListener('focusin', this._onFocusIn);
769
729
  }
770
730
  }
771
731
 
772
732
  /**
773
- * Activate a new tree.
774
- * @param {object} [params] Params to be passed to the `Tree` constructor.
775
- * @returns {Attachment} Attachment.
733
+ * Activate a new tree. Takes the params to be passed to the `Tree` constructor, or a getter
734
+ * function for reactive params, and returns an attachment.
776
735
  */
777
- export const activateTree = (params) => (parent) => {
778
- const tree = new Tree(/** @type {HTMLElement} */ (parent), params);
779
-
780
- return () => {
781
- tree.destroy();
782
- };
783
- };
736
+ export const activateTree = createWidgetAttachment(Tree);
@@ -2,6 +2,8 @@
2
2
  * How long, in milliseconds, successive keystrokes keep adding up to one type-ahead prefix.
3
3
  */
4
4
  export const TYPE_AHEAD_TIMEOUT: 500;
5
+ export function isPrintableKey({ key, altKey, ctrlKey, metaKey }: KeyboardEvent): boolean;
6
+ export function findTypeAheadMatch(labels: string[], prefix: string, currentIndex: number): number;
5
7
  /**
6
8
  * Keystroke buffer behind type-ahead: printable keys typed in quick succession make up a prefix,
7
9
  * which is dropped again after a short pause.
@@ -13,10 +15,17 @@ export class TypeAhead {
13
15
  * @returns {string} Current prefix.
14
16
  */
15
17
  push(key: string): string;
18
+ /**
19
+ * Add a keystroke to the prefix, and find the item it lands on. See {@link findTypeAheadMatch}.
20
+ * @param {string[]} labels Item labels, in order. They’re normalized here.
21
+ * @param {string} key Printable key.
22
+ * @param {number} currentIndex Index of the current item, or `-1` if there is none.
23
+ * @returns {number} Index of the matching item, or `-1` if nothing matches.
24
+ */
25
+ match(labels: string[], key: string, currentIndex: number): number;
16
26
  /**
17
27
  * Drop the prefix.
18
28
  */
19
29
  reset(): void;
20
30
  #private;
21
31
  }
22
- export function findTypeAheadMatch(labels: string[], prefix: string, currentIndex: number): number;
@@ -3,13 +3,57 @@
3
3
  * listbox and menu groups.
4
4
  */
5
5
 
6
- import { fold } from './text.js';
6
+ import { fold, normalize } from './text.js';
7
7
 
8
8
  /**
9
9
  * How long, in milliseconds, successive keystrokes keep adding up to one type-ahead prefix.
10
10
  */
11
11
  export const TYPE_AHEAD_TIMEOUT = 500;
12
12
 
13
+ /**
14
+ * Check whether a key press types a character that type-ahead goes by: a single printable
15
+ * character other than whitespace, typed with Shift at most. A shortcut, with Alt, Control or Meta
16
+ * held down, is left alone, and so is Space, which selects. Callers that ignore Shift as well check
17
+ * for it themselves beforehand.
18
+ * @param {KeyboardEvent} event `keydown` event.
19
+ * @returns {boolean} Result.
20
+ */
21
+ export const isPrintableKey = ({ key, altKey, ctrlKey, metaKey }) =>
22
+ key.length === 1 && !!key.trim() && !altKey && !ctrlKey && !metaKey;
23
+
24
+ /**
25
+ * Find the item that a type-ahead prefix lands on, the way a native `<select>` does. A single
26
+ * character moves to the next item after the current one whose label starts with it, wrapping
27
+ * around, and a repeated character (“aa”, …) keeps cycling through those. A longer prefix refines
28
+ * the match from the current item, which is where the first character landed.
29
+ * @param {string[]} labels Normalized item labels, in order.
30
+ * @param {string} prefix Normalized prefix typed so far.
31
+ * @param {number} currentIndex Index of the current item, or `-1` if there is none.
32
+ * @returns {number} Index of the matching item, or `-1` if nothing matches.
33
+ */
34
+ export const findTypeAheadMatch = (labels, prefix, currentIndex) => {
35
+ if (!prefix) {
36
+ return -1;
37
+ }
38
+
39
+ const cycling = prefix.length > 1 && [...prefix].every((char) => char === prefix[0]);
40
+ const needle = cycling ? prefix[0] : prefix;
41
+ // A single or repeated character is a request to move on, so the search starts after the current
42
+ // item; a longer prefix is refining what the first character found, so it starts there
43
+ const start = prefix.length === 1 || cycling ? currentIndex + 1 : Math.max(currentIndex, 0);
44
+ const { length } = labels;
45
+
46
+ for (let i = 0; i < length; i += 1) {
47
+ const index = (start + i) % length;
48
+
49
+ if (labels[index].startsWith(needle)) {
50
+ return index;
51
+ }
52
+ }
53
+
54
+ return -1;
55
+ };
56
+
13
57
  /**
14
58
  * Keystroke buffer behind type-ahead: printable keys typed in quick succession make up a prefix,
15
59
  * which is dropped again after a short pause.
@@ -40,6 +84,17 @@ export class TypeAhead {
40
84
  return this.#prefix;
41
85
  }
42
86
 
87
+ /**
88
+ * Add a keystroke to the prefix, and find the item it lands on. See {@link findTypeAheadMatch}.
89
+ * @param {string[]} labels Item labels, in order. They’re normalized here.
90
+ * @param {string} key Printable key.
91
+ * @param {number} currentIndex Index of the current item, or `-1` if there is none.
92
+ * @returns {number} Index of the matching item, or `-1` if nothing matches.
93
+ */
94
+ match(labels, key, currentIndex) {
95
+ return findTypeAheadMatch(labels.map(normalize), this.push(key), currentIndex);
96
+ }
97
+
43
98
  /**
44
99
  * Drop the prefix.
45
100
  */
@@ -48,36 +103,3 @@ export class TypeAhead {
48
103
  this.#prefix = '';
49
104
  }
50
105
  }
51
-
52
- /**
53
- * Find the item that a type-ahead prefix lands on, the way a native `<select>` does. A single
54
- * character moves to the next item after the current one whose label starts with it, wrapping
55
- * around, and a repeated character (“aa”, …) keeps cycling through those. A longer prefix refines
56
- * the match from the current item, which is where the first character landed.
57
- * @param {string[]} labels Normalized item labels, in order.
58
- * @param {string} prefix Normalized prefix typed so far.
59
- * @param {number} currentIndex Index of the current item, or `-1` if there is none.
60
- * @returns {number} Index of the matching item, or `-1` if nothing matches.
61
- */
62
- export const findTypeAheadMatch = (labels, prefix, currentIndex) => {
63
- if (!prefix) {
64
- return -1;
65
- }
66
-
67
- const cycling = prefix.length > 1 && [...prefix].every((char) => char === prefix[0]);
68
- const needle = cycling ? prefix[0] : prefix;
69
- // A single or repeated character is a request to move on, so the search starts after the current
70
- // item; a longer prefix is refining what the first character found, so it starts there
71
- const start = prefix.length === 1 || cycling ? currentIndex + 1 : Math.max(currentIndex, 0);
72
- const { length } = labels;
73
-
74
- for (let i = 0; i < length; i += 1) {
75
- const index = (start + i) % length;
76
-
77
- if (labels[index].startsWith(needle)) {
78
- return index;
79
- }
80
- }
81
-
82
- return -1;
83
- };
@@ -1,3 +1,41 @@
1
+ export type ContainerProps = {
2
+ /**
3
+ * The `class` attribute on the wrapper element.
4
+ */
5
+ class?: string | undefined;
6
+ /**
7
+ * Primary slot content.
8
+ */
9
+ children?: Snippet<[]> | undefined;
10
+ };
11
+ export type WidgetStateProps = {
12
+ /**
13
+ * Whether to hide the widget.
14
+ */
15
+ hidden?: boolean | undefined;
16
+ /**
17
+ * Whether to disable the widget. An alias of the `aria-disabled`
18
+ * attribute.
19
+ */
20
+ disabled?: boolean | undefined;
21
+ };
22
+ export type FormFieldStateProps = {
23
+ /**
24
+ * Whether to make the widget read-only. An alias of the
25
+ * `aria-readonly` attribute.
26
+ */
27
+ readonly?: boolean | undefined;
28
+ /**
29
+ * Whether to mark the widget required. An alias of the
30
+ * `aria-required` attribute.
31
+ */
32
+ required?: boolean | undefined;
33
+ /**
34
+ * Whether to mark the widget invalid. An alias of the `aria-invalid`
35
+ * attribute.
36
+ */
37
+ invalid?: boolean | undefined;
38
+ };
1
39
  export type ButtonProps = {
2
40
  /**
3
41
  * Reference to the `<button>` element.
@@ -212,17 +250,30 @@ export type ModalProps = {
212
250
  */
213
251
  onClose?: ((event: CustomEvent) => void) | undefined;
214
252
  };
215
- export type DialogProps = {
253
+ /**
254
+ * Props labelling a modal with a header, like `<Dialog>` and `<Drawer>`.
255
+ */
256
+ export type ModalLabelProps = {
216
257
  /**
217
- * Text label displayed on the header. Required. With a custom `header`
218
- * snippet, it’s used as the dialog’s `aria-label` instead.
258
+ * Text label displayed on the header. Either this or `ariaLabelledby` is
259
+ * required for the modal to have an accessible name. With a custom `header` snippet, it’s used as
260
+ * the modal’s `aria-label` instead.
219
261
  */
220
262
  title?: string | undefined;
221
263
  /**
222
- * ID of the element that labels the dialog, typically a heading
264
+ * ID of the element that labels the modal, typically a heading
223
265
  * inside a custom `header` snippet. Takes precedence over `title` for the accessible name.
224
266
  */
225
267
  ariaLabelledby?: string | undefined;
268
+ };
269
+ /**
270
+ * Props of `<Dialog>`, including those labelling it.
271
+ */
272
+ export type DialogProps = ModalLabelProps & DialogOwnProps;
273
+ /**
274
+ * Props of `<Dialog>` other than those labelling it; see {@link DialogProps}.
275
+ */
276
+ export type DialogOwnProps = {
226
277
  /**
227
278
  * The `role` attribute on the `<dialog>` element.
228
279
  */
@@ -482,6 +533,12 @@ export type ComboboxProps = {
482
533
  * Use `-1` to always hide the filter.
483
534
  */
484
535
  filterThreshold?: number | undefined;
536
+ /**
537
+ * Whether typing on the collapsed, non-editable combobox
538
+ * selects the matching option. If `false`, it opens the dropdown and carries the typed characters
539
+ * over to the filter instead. Default: `true`.
540
+ */
541
+ selectOnTypeAhead?: boolean | undefined;
485
542
  /**
486
543
  * The `aria-label` attribute on the wrapper element.
487
544
  */
@@ -845,6 +902,37 @@ export type TextEditorConfig = {
845
902
  */
846
903
  multiline?: boolean | undefined;
847
904
  };
905
+ /**
906
+ * Props shared by `<TextEditor>` and `<CodeEditor>`.
907
+ */
908
+ export type EditorCommonProps = {
909
+ /**
910
+ * Make the text input container flexible.
911
+ */
912
+ flex?: boolean | undefined;
913
+ /**
914
+ * The `class` attribute on the wrapper element.
915
+ */
916
+ class?: string | undefined;
917
+ /**
918
+ * The `aria-label` attribute on the editable text box. Either this
919
+ * or `ariaLabelledby` is required for the editor to have an accessible name.
920
+ */
921
+ ariaLabel?: string | undefined;
922
+ /**
923
+ * The `aria-labelledby` attribute on the editable text box.
924
+ */
925
+ ariaLabelledby?: string | undefined;
926
+ /**
927
+ * The `aria-describedby` attribute on the editable text box.
928
+ */
929
+ ariaDescribedby?: string | undefined;
930
+ /**
931
+ * Primary slot content. Not rendered, as the editor has no room for
932
+ * it; kept for compatibility.
933
+ */
934
+ children?: Snippet<[]> | undefined;
935
+ };
848
936
  export type EmojiEntry = {
849
937
  /**
850
938
  * Emoji character, e.g. `🎉`.
@@ -1136,6 +1224,17 @@ export type TextEditorStore = {
1136
1224
  * only that value written in the editor’s own Markdown or HTML style, e.g. `_text_` for `*text*`.
1137
1225
  */
1138
1226
  getImportedValue: (value: string) => string | undefined;
1227
+ /**
1228
+ * Function to set
1229
+ * {@link TextEditorStore.inputValue} to the value exported from the Lexical editor, without
1230
+ * importing it back into the editor, which would reset its nodes and selection.
1231
+ */
1232
+ setExportedValue: (value: string) => void;
1233
+ /**
1234
+ * Function to export the content of the Lexical editor right
1235
+ * away, if it’s scheduled to be exported. The editor root sets this while the editor is there.
1236
+ */
1237
+ flushExport: () => void;
1139
1238
  };
1140
1239
  export type SelectedItemDetail = {
1141
1240
  /**
package/dist/typedefs.js CHANGED
@@ -4,6 +4,29 @@
4
4
  * @import { LexicalEditor, LexicalNode } from 'lexical';
5
5
  */
6
6
 
7
+ /**
8
+ * @typedef {object} ContainerProps
9
+ * @property {string} [class] The `class` attribute on the wrapper element.
10
+ * @property {Snippet} [children] Primary slot content.
11
+ */
12
+
13
+ /**
14
+ * @typedef {object} WidgetStateProps
15
+ * @property {boolean} [hidden] Whether to hide the widget.
16
+ * @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
17
+ * attribute.
18
+ */
19
+
20
+ /**
21
+ * @typedef {object} FormFieldStateProps
22
+ * @property {boolean} [readonly] Whether to make the widget read-only. An alias of the
23
+ * `aria-readonly` attribute.
24
+ * @property {boolean} [required] Whether to mark the widget required. An alias of the
25
+ * `aria-required` attribute.
26
+ * @property {boolean} [invalid] Whether to mark the widget invalid. An alias of the `aria-invalid`
27
+ * attribute.
28
+ */
29
+
7
30
  /**
8
31
  * @typedef {object} ButtonProps
9
32
  * @property {HTMLButtonElement} [element] Reference to the `<button>` element.
@@ -82,11 +105,23 @@
82
105
  */
83
106
 
84
107
  /**
85
- * @typedef {object} DialogProps
86
- * @property {string} [title] Text label displayed on the header. Required. With a custom `header`
87
- * snippet, it’s used as the dialog’s `aria-label` instead.
88
- * @property {string} [ariaLabelledby] ID of the element that labels the dialog, typically a heading
108
+ * Props labelling a modal with a header, like `<Dialog>` and `<Drawer>`.
109
+ * @typedef {object} ModalLabelProps
110
+ * @property {string} [title] Text label displayed on the header. Either this or `ariaLabelledby` is
111
+ * required for the modal to have an accessible name. With a custom `header` snippet, it’s used as
112
+ * the modal’s `aria-label` instead.
113
+ * @property {string} [ariaLabelledby] ID of the element that labels the modal, typically a heading
89
114
  * inside a custom `header` snippet. Takes precedence over `title` for the accessible name.
115
+ */
116
+
117
+ /**
118
+ * Props of `<Dialog>`, including those labelling it.
119
+ * @typedef {ModalLabelProps & DialogOwnProps} DialogProps
120
+ */
121
+
122
+ /**
123
+ * Props of `<Dialog>` other than those labelling it; see {@link DialogProps}.
124
+ * @typedef {object} DialogOwnProps
90
125
  * @property {'dialog' | 'alertdialog'} [role] The `role` attribute on the `<dialog>` element.
91
126
  * @property {'x-small' | 'small' | 'medium' | 'large' | 'x-large'} [size] Width of the dialog.
92
127
  * @property {string} [class] The `class` attribute on the `<dialog>` element.
@@ -182,6 +217,9 @@
182
217
  * @property {PopupPosition} [position] Where to show the dropdown menu.
183
218
  * @property {number} [filterThreshold] Number of items to start showing the filter. Default: `5`.
184
219
  * Use `-1` to always hide the filter.
220
+ * @property {boolean} [selectOnTypeAhead] Whether typing on the collapsed, non-editable combobox
221
+ * selects the matching option. If `false`, it opens the dropdown and carries the typed characters
222
+ * over to the filter instead. Default: `true`.
185
223
  * @property {string} [ariaLabel] The `aria-label` attribute on the wrapper element.
186
224
  * @property {Snippet} [children] Primary slot content.
187
225
  * @property {Snippet} [chevronIcon] Chevron icon slot content.
@@ -367,6 +405,19 @@
367
405
  * `false`, it’s kept in a single paragraph without line breaks. Default: `true`.
368
406
  */
369
407
 
408
+ /**
409
+ * Props shared by `<TextEditor>` and `<CodeEditor>`.
410
+ * @typedef {object} EditorCommonProps
411
+ * @property {boolean} [flex] Make the text input container flexible.
412
+ * @property {string} [class] The `class` attribute on the wrapper element.
413
+ * @property {string} [ariaLabel] The `aria-label` attribute on the editable text box. Either this
414
+ * or `ariaLabelledby` is required for the editor to have an accessible name.
415
+ * @property {string} [ariaLabelledby] The `aria-labelledby` attribute on the editable text box.
416
+ * @property {string} [ariaDescribedby] The `aria-describedby` attribute on the editable text box.
417
+ * @property {Snippet} [children] Primary slot content. Not rendered, as the editor has no room for
418
+ * it; kept for compatibility.
419
+ */
420
+
370
421
  /**
371
422
  * @typedef {object} EmojiEntry
372
423
  * @property {string} emoji Emoji character, e.g. `🎉`.
@@ -496,6 +547,11 @@
496
547
  * @property {(value: string) => string | undefined} getImportedValue Function to get the
497
548
  * {@link TextEditorStore.inputValue} last imported if the given value, exported by the editor, is
498
549
  * only that value written in the editor’s own Markdown or HTML style, e.g. `_text_` for `*text*`.
550
+ * @property {(value: string) => void} setExportedValue Function to set
551
+ * {@link TextEditorStore.inputValue} to the value exported from the Lexical editor, without
552
+ * importing it back into the editor, which would reset its nodes and selection.
553
+ * @property {() => void} flushExport Function to export the content of the Lexical editor right
554
+ * away, if it’s scheduled to be exported. The editor root sets this while the editor is there.
499
555
  */
500
556
 
501
557
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.91.0",
3
+ "version": "0.92.1",
4
4
  "description": "A collection of Svelte components and utilities for building user interfaces.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -81,7 +81,7 @@
81
81
  "eslint-config-airbnb-extended": "^3.3.0",
82
82
  "eslint-config-prettier": "^10.1.8",
83
83
  "eslint-plugin-import": "^2.32.0",
84
- "eslint-plugin-jsdoc": "^65.4.7",
84
+ "eslint-plugin-jsdoc": "^65.4.8",
85
85
  "eslint-plugin-package-json": "^1.14.0",
86
86
  "eslint-plugin-svelte": "^3.24.1",
87
87
  "globals": "^17.14.0",