foldkit 0.111.1 → 0.112.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 (222) hide show
  1. package/README.md +2 -2
  2. package/dist/devTools/host.d.ts +6 -0
  3. package/dist/devTools/host.d.ts.map +1 -0
  4. package/dist/devTools/host.js +4 -0
  5. package/dist/dom/dom.d.ts +6 -1
  6. package/dist/dom/dom.d.ts.map +1 -1
  7. package/dist/dom/dom.js +24 -1
  8. package/dist/html/index.d.ts +4 -3
  9. package/dist/html/index.d.ts.map +1 -1
  10. package/dist/html/index.js +4 -3
  11. package/dist/html/submodel.d.ts +2 -2
  12. package/dist/html/submodel.d.ts.map +1 -1
  13. package/dist/index.d.ts +0 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +0 -1
  16. package/dist/runtime/public.d.ts +1 -1
  17. package/dist/runtime/public.d.ts.map +1 -1
  18. package/dist/runtime/runtime.d.ts +14 -1
  19. package/dist/runtime/runtime.d.ts.map +1 -1
  20. package/dist/runtime/runtime.js +7 -4
  21. package/dist/runtime/subscription.d.ts +1 -1
  22. package/dist/subscription/public.d.ts +1 -1
  23. package/dist/subscription/public.d.ts.map +1 -1
  24. package/package.json +12 -93
  25. package/dist/devTools/overlay-styles.d.ts +0 -3
  26. package/dist/devTools/overlay-styles.d.ts.map +0 -1
  27. package/dist/devTools/overlay-styles.js +0 -706
  28. package/dist/devTools/overlay.d.ts +0 -63
  29. package/dist/devTools/overlay.d.ts.map +0 -1
  30. package/dist/devTools/overlay.js +0 -1244
  31. package/dist/test/apps/disabledButton.d.ts +0 -38
  32. package/dist/test/apps/disabledButton.d.ts.map +0 -1
  33. package/dist/test/apps/disabledButton.js +0 -71
  34. package/dist/ui/anchor.d.ts +0 -38
  35. package/dist/ui/anchor.d.ts.map +0 -1
  36. package/dist/ui/anchor.js +0 -142
  37. package/dist/ui/animation/index.d.ts +0 -49
  38. package/dist/ui/animation/index.d.ts.map +0 -1
  39. package/dist/ui/animation/index.js +0 -74
  40. package/dist/ui/animation/public.d.ts +0 -3
  41. package/dist/ui/animation/public.d.ts.map +0 -1
  42. package/dist/ui/animation/public.js +0 -1
  43. package/dist/ui/animation/schema.d.ts +0 -43
  44. package/dist/ui/animation/schema.d.ts.map +0 -1
  45. package/dist/ui/animation/schema.js +0 -41
  46. package/dist/ui/animation/update.d.ts +0 -24
  47. package/dist/ui/animation/update.d.ts.map +0 -1
  48. package/dist/ui/animation/update.js +0 -67
  49. package/dist/ui/button/index.d.ts +0 -17
  50. package/dist/ui/button/index.d.ts.map +0 -1
  51. package/dist/ui/button/index.js +0 -22
  52. package/dist/ui/button/public.d.ts +0 -3
  53. package/dist/ui/button/public.d.ts.map +0 -1
  54. package/dist/ui/button/public.js +0 -1
  55. package/dist/ui/calendar/index.d.ts +0 -462
  56. package/dist/ui/calendar/index.d.ts.map +0 -1
  57. package/dist/ui/calendar/index.js +0 -824
  58. package/dist/ui/calendar/public.d.ts +0 -3
  59. package/dist/ui/calendar/public.d.ts.map +0 -1
  60. package/dist/ui/calendar/public.js +0 -1
  61. package/dist/ui/checkbox/index.d.ts +0 -119
  62. package/dist/ui/checkbox/index.d.ts.map +0 -1
  63. package/dist/ui/checkbox/index.js +0 -110
  64. package/dist/ui/checkbox/public.d.ts +0 -3
  65. package/dist/ui/checkbox/public.d.ts.map +0 -1
  66. package/dist/ui/checkbox/public.js +0 -1
  67. package/dist/ui/combobox/multi.d.ts +0 -184
  68. package/dist/ui/combobox/multi.d.ts.map +0 -1
  69. package/dist/ui/combobox/multi.js +0 -81
  70. package/dist/ui/combobox/multiPublic.d.ts +0 -3
  71. package/dist/ui/combobox/multiPublic.d.ts.map +0 -1
  72. package/dist/ui/combobox/multiPublic.js +0 -1
  73. package/dist/ui/combobox/public.d.ts +0 -7
  74. package/dist/ui/combobox/public.d.ts.map +0 -1
  75. package/dist/ui/combobox/public.js +0 -3
  76. package/dist/ui/combobox/shared.d.ts +0 -422
  77. package/dist/ui/combobox/shared.d.ts.map +0 -1
  78. package/dist/ui/combobox/shared.js +0 -707
  79. package/dist/ui/combobox/single.d.ts +0 -199
  80. package/dist/ui/combobox/single.d.ts.map +0 -1
  81. package/dist/ui/combobox/single.js +0 -106
  82. package/dist/ui/datePicker/index.d.ts +0 -457
  83. package/dist/ui/datePicker/index.d.ts.map +0 -1
  84. package/dist/ui/datePicker/index.js +0 -317
  85. package/dist/ui/datePicker/public.d.ts +0 -3
  86. package/dist/ui/datePicker/public.d.ts.map +0 -1
  87. package/dist/ui/datePicker/public.js +0 -1
  88. package/dist/ui/dialog/index.d.ts +0 -155
  89. package/dist/ui/dialog/index.d.ts.map +0 -1
  90. package/dist/ui/dialog/index.js +0 -208
  91. package/dist/ui/dialog/public.d.ts +0 -3
  92. package/dist/ui/dialog/public.d.ts.map +0 -1
  93. package/dist/ui/dialog/public.js +0 -1
  94. package/dist/ui/disclosure/index.d.ts +0 -110
  95. package/dist/ui/disclosure/index.d.ts.map +0 -1
  96. package/dist/ui/disclosure/index.js +0 -110
  97. package/dist/ui/disclosure/public.d.ts +0 -3
  98. package/dist/ui/disclosure/public.d.ts.map +0 -1
  99. package/dist/ui/disclosure/public.js +0 -1
  100. package/dist/ui/dragAndDrop/index.d.ts +0 -540
  101. package/dist/ui/dragAndDrop/index.d.ts.map +0 -1
  102. package/dist/ui/dragAndDrop/index.js +0 -535
  103. package/dist/ui/dragAndDrop/public.d.ts +0 -3
  104. package/dist/ui/dragAndDrop/public.d.ts.map +0 -1
  105. package/dist/ui/dragAndDrop/public.js +0 -1
  106. package/dist/ui/fieldset/index.d.ts +0 -21
  107. package/dist/ui/fieldset/index.d.ts.map +0 -1
  108. package/dist/ui/fieldset/index.js +0 -25
  109. package/dist/ui/fieldset/public.d.ts +0 -3
  110. package/dist/ui/fieldset/public.d.ts.map +0 -1
  111. package/dist/ui/fieldset/public.js +0 -1
  112. package/dist/ui/fileDrop/index.d.ts +0 -109
  113. package/dist/ui/fileDrop/index.d.ts.map +0 -1
  114. package/dist/ui/fileDrop/index.js +0 -126
  115. package/dist/ui/fileDrop/public.d.ts +0 -3
  116. package/dist/ui/fileDrop/public.d.ts.map +0 -1
  117. package/dist/ui/fileDrop/public.js +0 -1
  118. package/dist/ui/group.d.ts +0 -8
  119. package/dist/ui/group.d.ts.map +0 -1
  120. package/dist/ui/group.js +0 -13
  121. package/dist/ui/index.d.ts +0 -25
  122. package/dist/ui/index.d.ts.map +0 -1
  123. package/dist/ui/index.js +0 -24
  124. package/dist/ui/input/index.d.ts +0 -26
  125. package/dist/ui/input/index.d.ts.map +0 -1
  126. package/dist/ui/input/index.js +0 -43
  127. package/dist/ui/input/public.d.ts +0 -3
  128. package/dist/ui/input/public.d.ts.map +0 -1
  129. package/dist/ui/input/public.js +0 -1
  130. package/dist/ui/keyboard.d.ts +0 -6
  131. package/dist/ui/keyboard.d.ts.map +0 -1
  132. package/dist/ui/keyboard.js +0 -9
  133. package/dist/ui/listbox/multi.d.ts +0 -190
  134. package/dist/ui/listbox/multi.d.ts.map +0 -1
  135. package/dist/ui/listbox/multi.js +0 -65
  136. package/dist/ui/listbox/multiPublic.d.ts +0 -3
  137. package/dist/ui/listbox/multiPublic.d.ts.map +0 -1
  138. package/dist/ui/listbox/multiPublic.js +0 -1
  139. package/dist/ui/listbox/public.d.ts +0 -7
  140. package/dist/ui/listbox/public.d.ts.map +0 -1
  141. package/dist/ui/listbox/public.js +0 -3
  142. package/dist/ui/listbox/shared.d.ts +0 -431
  143. package/dist/ui/listbox/shared.d.ts.map +0 -1
  144. package/dist/ui/listbox/shared.js +0 -669
  145. package/dist/ui/listbox/single.d.ts +0 -208
  146. package/dist/ui/listbox/single.d.ts.map +0 -1
  147. package/dist/ui/listbox/single.js +0 -73
  148. package/dist/ui/menu/index.d.ts +0 -367
  149. package/dist/ui/menu/index.d.ts.map +0 -1
  150. package/dist/ui/menu/index.js +0 -681
  151. package/dist/ui/menu/public.d.ts +0 -4
  152. package/dist/ui/menu/public.d.ts.map +0 -1
  153. package/dist/ui/menu/public.js +0 -1
  154. package/dist/ui/popover/index.d.ts +0 -267
  155. package/dist/ui/popover/index.d.ts.map +0 -1
  156. package/dist/ui/popover/index.js +0 -345
  157. package/dist/ui/popover/public.d.ts +0 -4
  158. package/dist/ui/popover/public.d.ts.map +0 -1
  159. package/dist/ui/popover/public.js +0 -1
  160. package/dist/ui/radioGroup/index.d.ts +0 -169
  161. package/dist/ui/radioGroup/index.d.ts.map +0 -1
  162. package/dist/ui/radioGroup/index.js +0 -196
  163. package/dist/ui/radioGroup/public.d.ts +0 -3
  164. package/dist/ui/radioGroup/public.d.ts.map +0 -1
  165. package/dist/ui/radioGroup/public.js +0 -1
  166. package/dist/ui/select/index.d.ts +0 -24
  167. package/dist/ui/select/index.d.ts.map +0 -1
  168. package/dist/ui/select/index.js +0 -40
  169. package/dist/ui/select/public.d.ts +0 -3
  170. package/dist/ui/select/public.d.ts.map +0 -1
  171. package/dist/ui/select/public.js +0 -1
  172. package/dist/ui/slider/index.d.ts +0 -318
  173. package/dist/ui/slider/index.d.ts.map +0 -1
  174. package/dist/ui/slider/index.js +0 -336
  175. package/dist/ui/slider/public.d.ts +0 -3
  176. package/dist/ui/slider/public.d.ts.map +0 -1
  177. package/dist/ui/slider/public.js +0 -1
  178. package/dist/ui/switch/index.d.ts +0 -99
  179. package/dist/ui/switch/index.d.ts.map +0 -1
  180. package/dist/ui/switch/index.js +0 -106
  181. package/dist/ui/switch/public.d.ts +0 -3
  182. package/dist/ui/switch/public.d.ts.map +0 -1
  183. package/dist/ui/switch/public.js +0 -1
  184. package/dist/ui/tabs/index.d.ts +0 -155
  185. package/dist/ui/tabs/index.d.ts.map +0 -1
  186. package/dist/ui/tabs/index.js +0 -184
  187. package/dist/ui/tabs/public.d.ts +0 -3
  188. package/dist/ui/tabs/public.d.ts.map +0 -1
  189. package/dist/ui/tabs/public.js +0 -1
  190. package/dist/ui/textarea/index.d.ts +0 -26
  191. package/dist/ui/textarea/index.d.ts.map +0 -1
  192. package/dist/ui/textarea/index.js +0 -44
  193. package/dist/ui/textarea/public.d.ts +0 -3
  194. package/dist/ui/textarea/public.d.ts.map +0 -1
  195. package/dist/ui/textarea/public.js +0 -1
  196. package/dist/ui/toast/index.d.ts +0 -608
  197. package/dist/ui/toast/index.d.ts.map +0 -1
  198. package/dist/ui/toast/index.js +0 -145
  199. package/dist/ui/toast/public.d.ts +0 -4
  200. package/dist/ui/toast/public.d.ts.map +0 -1
  201. package/dist/ui/toast/public.js +0 -1
  202. package/dist/ui/toast/schema.d.ts +0 -154
  203. package/dist/ui/toast/schema.d.ts.map +0 -1
  204. package/dist/ui/toast/schema.js +0 -93
  205. package/dist/ui/toast/update.d.ts +0 -510
  206. package/dist/ui/toast/update.d.ts.map +0 -1
  207. package/dist/ui/toast/update.js +0 -225
  208. package/dist/ui/tooltip/index.d.ts +0 -170
  209. package/dist/ui/tooltip/index.d.ts.map +0 -1
  210. package/dist/ui/tooltip/index.js +0 -252
  211. package/dist/ui/tooltip/public.d.ts +0 -4
  212. package/dist/ui/tooltip/public.d.ts.map +0 -1
  213. package/dist/ui/tooltip/public.js +0 -1
  214. package/dist/ui/typeahead.d.ts +0 -4
  215. package/dist/ui/typeahead.d.ts.map +0 -1
  216. package/dist/ui/typeahead.js +0 -14
  217. package/dist/ui/virtualList/index.d.ts +0 -202
  218. package/dist/ui/virtualList/index.d.ts.map +0 -1
  219. package/dist/ui/virtualList/index.js +0 -391
  220. package/dist/ui/virtualList/public.d.ts +0 -3
  221. package/dist/ui/virtualList/public.d.ts.map +0 -1
  222. package/dist/ui/virtualList/public.js +0 -1
@@ -1,707 +0,0 @@
1
- import { Array, Effect, Match as M, Option, Predicate, Result, Schema as S, pipe, } from 'effect';
2
- import * as Command from '../../command/index.js';
3
- import * as Dom from '../../dom/index.js';
4
- import { OptionExt } from '../../effectExtensions/index.js';
5
- import { defineView, html, } from '../../html/index.js';
6
- import { m } from '../../message/index.js';
7
- import * as Mount from '../../mount/index.js';
8
- import { makeConstrainedEvo } from '../../struct/index.js';
9
- import { AnchorConfig, anchorSetup, portalToBody } from '../anchor.js';
10
- // NOTE: Animation imports are split across schema + update to avoid a circular
11
- // dependency: animation → html → runtime → devtools → combobox → animation.
12
- // The barrel (../animation) imports from html, which starts the cycle.
13
- import { EndedAnimation as AnimationEndedAnimation, Hid as AnimationHid, Message as AnimationMessage, Model as AnimationModel, Showed as AnimationShowed, init as animationInit, } from '../animation/schema.js';
14
- import { update as animationUpdate } from '../animation/update.js';
15
- import { groupContiguous } from '../group.js';
16
- import { findFirstEnabledIndex, keyToIndex } from '../keyboard.js';
17
- export { groupContiguous };
18
- // MODEL
19
- /** Schema for the activation trigger: whether the user interacted via mouse or keyboard. */
20
- export const ActivationTrigger = S.Literals(['Pointer', 'Keyboard']);
21
- /** Schema fields shared by all combobox variants (single-select and multi-select). Spread into each variant's `S.Struct` to avoid duplicating field definitions. */
22
- export const BaseModel = S.Struct({
23
- id: S.String,
24
- isOpen: S.Boolean,
25
- isAnimated: S.Boolean,
26
- isModal: S.Boolean,
27
- nullable: S.Boolean,
28
- immediate: S.Boolean,
29
- selectInputOnFocus: S.Boolean,
30
- animation: AnimationModel,
31
- maybeActiveItemIndex: S.Option(S.Number),
32
- activationTrigger: ActivationTrigger,
33
- inputValue: S.String,
34
- maybeLastPointerPosition: S.Option(S.Struct({ screenX: S.Number, screenY: S.Number })),
35
- });
36
- /** Creates the shared base fields for a combobox model from a config. Each variant spreads this and adds its selection fields. */
37
- export const baseInit = (config) => ({
38
- id: config.id,
39
- isOpen: false,
40
- isAnimated: config.isAnimated ?? false,
41
- isModal: config.isModal ?? false,
42
- nullable: config.nullable ?? false,
43
- immediate: config.immediate ?? false,
44
- selectInputOnFocus: config.selectInputOnFocus ?? false,
45
- animation: animationInit({ id: `${config.id}-items` }),
46
- maybeActiveItemIndex: Option.none(),
47
- activationTrigger: 'Keyboard',
48
- inputValue: '',
49
- maybeLastPointerPosition: Option.none(),
50
- });
51
- // MESSAGE
52
- /** Sent when the combobox popup opens. Contains an optional initial active item index. */
53
- export const Opened = m('Opened', {
54
- maybeActiveItemIndex: S.Option(S.Number),
55
- });
56
- /** Sent when the combobox closes via Escape key or backdrop click. */
57
- export const Closed = m('Closed');
58
- /** Sent when the combobox input loses focus. */
59
- export const BlurredInput = m('BlurredInput');
60
- /** Sent when an item is highlighted via arrow keys or mouse hover. Includes activation trigger and optional immediate selection info. */
61
- export const ActivatedItem = m('ActivatedItem', {
62
- index: S.Number,
63
- activationTrigger: ActivationTrigger,
64
- maybeImmediateSelection: S.Option(S.Struct({ item: S.String, displayText: S.String })),
65
- });
66
- /** Sent when the mouse leaves an enabled item. */
67
- export const DeactivatedItem = m('DeactivatedItem');
68
- /** Sent when an item is selected via Enter or click. Includes display text for restoring input value on close. */
69
- export const SelectedItem = m('SelectedItem', {
70
- item: S.String,
71
- displayText: S.String,
72
- });
73
- /** Sent when the pointer moves over a combobox item. */
74
- export const MovedPointerOverItem = m('MovedPointerOverItem', {
75
- index: S.Number,
76
- screenX: S.Number,
77
- screenY: S.Number,
78
- });
79
- /** Sent when Enter or Space is pressed on the active item, triggering a programmatic click. */
80
- export const RequestedItemClick = m('RequestedItemClick', {
81
- index: S.Number,
82
- });
83
- /** Sent when the scroll lock command completes. */
84
- export const CompletedLockScroll = m('CompletedLockScroll');
85
- /** Sent when the scroll unlock command completes. */
86
- export const CompletedUnlockScroll = m('CompletedUnlockScroll');
87
- /** Sent when the inert-others command completes. */
88
- export const CompletedInertOthers = m('CompletedInertOthers');
89
- /** Sent when the restore-inert command completes. */
90
- export const CompletedRestoreInert = m('CompletedRestoreInert');
91
- /** Sent when the focus-input command completes. */
92
- export const CompletedFocusInput = m('CompletedFocusInput');
93
- /** Sent when the scroll-into-view command completes after keyboard activation. */
94
- export const CompletedScrollIntoView = m('CompletedScrollIntoView');
95
- /** Sent when the programmatic item click command completes. */
96
- export const CompletedClickItem = m('CompletedClickItem');
97
- /** Sent when the items panel mounts and Floating UI has positioned it. Update no-ops; surfaces the positioning side effect for DevTools. */
98
- export const CompletedAnchorCombobox = m('CompletedAnchorCombobox');
99
- /** Sent when the items panel mounts and the capture-phase pointerdown listener is attached (with or without anchor). Update no-ops; surfaces the listener-attach side effect for DevTools. */
100
- export const CompletedAttachComboboxPreventBlur = m('CompletedAttachComboboxPreventBlur');
101
- /** Sent when the input mounts and the focus listener that auto-selects on focus is attached. Update no-ops; surfaces the listener-attach side effect for DevTools. */
102
- export const CompletedAttachComboboxSelectOnFocus = m('CompletedAttachComboboxSelectOnFocus');
103
- /** Sent when the combobox backdrop mounts and is portaled to the document body. Update no-ops; surfaces the portal side effect for DevTools. */
104
- export const CompletedPortalComboboxBackdrop = m('CompletedPortalComboboxBackdrop');
105
- /** Wraps an Animation submodel message for delegation. */
106
- export const GotAnimationMessage = m('GotAnimationMessage', {
107
- message: AnimationMessage,
108
- });
109
- /** Sent when the user types in the input. */
110
- export const UpdatedInputValue = m('UpdatedInputValue', {
111
- value: S.String,
112
- });
113
- /** Sent when the optional toggle button is clicked. */
114
- export const PressedToggleButton = m('PressedToggleButton');
115
- /** Union of all messages the combobox component can produce. */
116
- export const Message = S.Union([
117
- Opened,
118
- Closed,
119
- BlurredInput,
120
- ActivatedItem,
121
- DeactivatedItem,
122
- SelectedItem,
123
- MovedPointerOverItem,
124
- RequestedItemClick,
125
- CompletedLockScroll,
126
- CompletedUnlockScroll,
127
- CompletedInertOthers,
128
- CompletedRestoreInert,
129
- CompletedFocusInput,
130
- CompletedScrollIntoView,
131
- CompletedClickItem,
132
- CompletedAnchorCombobox,
133
- CompletedAttachComboboxPreventBlur,
134
- CompletedAttachComboboxSelectOnFocus,
135
- CompletedPortalComboboxBackdrop,
136
- GotAnimationMessage,
137
- UpdatedInputValue,
138
- PressedToggleButton,
139
- ]);
140
- // OUT MESSAGE
141
- /** Sent when a single-select combobox commits a selection, or when a multi-select combobox toggles an item on. The `value` is the string key; consumers that need a richer domain type should look it up from their own state or, in the multi case, branch on `wasAdded` to distinguish add vs remove. */
142
- export const Selected = m('Selected', {
143
- value: S.String,
144
- wasAdded: S.Boolean,
145
- });
146
- /** Union of out-messages the combobox component can produce. Single-select comboboxes always emit `wasAdded: true`. Multi-select comboboxes emit `wasAdded: true` when adding to the selection and `wasAdded: false` when toggling off. */
147
- export const OutMessage = S.Union([Selected]);
148
- // SELECTORS
149
- export const inputSelector = (id) => `#${id}-input`;
150
- export const inputWrapperSelector = (id) => `#${id}-input-wrapper`;
151
- export const itemsSelector = (id) => `#${id}-items`;
152
- export const itemSelector = (id, index) => `#${id}-item-${index}`;
153
- export const itemId = (id, index) => `${id}-item-${index}`;
154
- // HELPERS
155
- const constrainedEvo = makeConstrainedEvo();
156
- /** Resets only shared base fields to their closed state. Does not touch inputValue or selection. Those are variant-specific. */
157
- export const closedBaseModel = (model) => constrainedEvo(model, {
158
- isOpen: () => false,
159
- maybeActiveItemIndex: () => Option.none(),
160
- activationTrigger: () => 'Keyboard',
161
- maybeLastPointerPosition: () => Option.none(),
162
- });
163
- /** Prevents page scrolling while the combobox popup is open in modal mode. */
164
- export const LockScroll = Command.define('LockScroll', CompletedLockScroll)(Dom.lockScroll.pipe(Effect.as(CompletedLockScroll())));
165
- /** Re-enables page scrolling after the combobox popup closes. */
166
- export const UnlockScroll = Command.define('UnlockScroll', CompletedUnlockScroll)(Dom.unlockScroll.pipe(Effect.as(CompletedUnlockScroll())));
167
- /** Marks all elements outside the combobox as inert for modal behavior. */
168
- export const InertOthers = Command.define('InertOthers', { id: S.String }, CompletedInertOthers)(({ id }) => Dom.inertOthers(id, [inputWrapperSelector(id), itemsSelector(id)]).pipe(Effect.as(CompletedInertOthers())));
169
- /** Removes the inert attribute from elements outside the combobox. */
170
- export const RestoreInert = Command.define('RestoreInert', { id: S.String }, CompletedRestoreInert)(({ id }) => Dom.restoreInert(id).pipe(Effect.as(CompletedRestoreInert())));
171
- /** Moves focus to the combobox input after selection or close. */
172
- export const FocusInput = Command.define('FocusInput', { id: S.String }, CompletedFocusInput)(({ id }) => Dom.focus(inputSelector(id)).pipe(Effect.ignore, Effect.as(CompletedFocusInput())));
173
- /** Scrolls the active combobox item into view after keyboard navigation. */
174
- export const ScrollIntoView = Command.define('ScrollIntoView', { id: S.String, index: S.Number }, CompletedScrollIntoView)(({ id, index }) => Dom.scrollIntoView(itemSelector(id, index)).pipe(Effect.ignore, Effect.as(CompletedScrollIntoView())));
175
- /** Programmatically clicks the active combobox item's DOM element. */
176
- export const ClickItem = Command.define('ClickItem', { id: S.String, index: S.Number }, CompletedClickItem)(({ id, index }) => Dom.clickElement(itemSelector(id, index)).pipe(Effect.ignore, Effect.as(CompletedClickItem())));
177
- /** Detects whether the combobox input wrapper moved or the leave animation ended. Whichever comes first; both outcomes signal the Animation submodel that leave is complete. */
178
- export const DetectMovementOrAnimationEnd = Command.define('DetectMovementOrAnimationEnd', { id: S.String }, GotAnimationMessage)(({ id }) => Effect.raceFirst(Dom.detectElementMovement(inputWrapperSelector(id)).pipe(Effect.as(GotAnimationMessage({ message: AnimationEndedAnimation() }))), Dom.waitForAnimationSettled(itemsSelector(id)).pipe(Effect.as(GotAnimationMessage({ message: AnimationEndedAnimation() })))));
179
- const delegateToAnimation = (model, animationMessage) => {
180
- const [nextAnimation, animationCommands, maybeOutMessage] = animationUpdate(model.animation, animationMessage);
181
- const mappedCommands = Command.mapMessages(animationCommands, message => GotAnimationMessage({ message }));
182
- const additionalCommands = Option.match(maybeOutMessage, {
183
- onNone: () => [],
184
- onSome: M.type().pipe(M.tagsExhaustive({
185
- StartedLeaveAnimating: () => [
186
- DetectMovementOrAnimationEnd({ id: model.id }),
187
- ],
188
- TransitionedOut: () => [],
189
- })),
190
- });
191
- return [
192
- constrainedEvo(model, { animation: () => nextAnimation }),
193
- [...mappedCommands, ...additionalCommands],
194
- Option.none(),
195
- ];
196
- };
197
- /** Creates a combobox update function from variant-specific handlers. Shared logic (open, close, activate, transition) is handled internally; only close, selection, and immediate-activation behavior varies by variant. */
198
- export const makeUpdate = (handlers) => {
199
- const withUpdateReturn = M.withReturnType();
200
- const internalUpdate = (model, message) => {
201
- const maybeLockScroll = OptionExt.when(model.isModal, LockScroll());
202
- const maybeUnlockScroll = OptionExt.when(model.isModal, UnlockScroll());
203
- const maybeInertOthers = OptionExt.when(model.isModal, InertOthers({ id: model.id }));
204
- const maybeRestoreInert = OptionExt.when(model.isModal, RestoreInert({ id: model.id }));
205
- const focusInput = FocusInput({ id: model.id });
206
- const openCombobox = (baseModel) => {
207
- if (model.isAnimated) {
208
- const [nextModel, animationCommands] = delegateToAnimation(baseModel, AnimationShowed());
209
- return [
210
- constrainedEvo(nextModel, { isOpen: () => true }),
211
- [
212
- ...Array.getSomes([maybeLockScroll, maybeInertOthers]),
213
- ...animationCommands,
214
- ],
215
- Option.none(),
216
- ];
217
- }
218
- return [
219
- constrainedEvo(baseModel, { isOpen: () => true }),
220
- Array.getSomes([maybeLockScroll, maybeInertOthers]),
221
- Option.none(),
222
- ];
223
- };
224
- const closeCombobox = (baseModel, commands, maybeOutMessage = Option.none()) => {
225
- const closed = handlers.handleClose(baseModel);
226
- if (model.isAnimated) {
227
- const [nextModel, animationCommands] = delegateToAnimation(closed, AnimationHid());
228
- return [nextModel, [...commands, ...animationCommands], maybeOutMessage];
229
- }
230
- return [closed, commands, maybeOutMessage];
231
- };
232
- return M.value(message).pipe(withUpdateReturn, M.tag('CompletedLockScroll', 'CompletedUnlockScroll', 'CompletedInertOthers', 'CompletedRestoreInert', 'CompletedFocusInput', 'CompletedScrollIntoView', 'CompletedClickItem', 'CompletedAnchorCombobox', 'CompletedAttachComboboxPreventBlur', 'CompletedAttachComboboxSelectOnFocus', 'CompletedPortalComboboxBackdrop', () => [model, [], Option.none()]), M.tagsExhaustive({
233
- Opened: ({ maybeActiveItemIndex }) => openCombobox(constrainedEvo(model, {
234
- maybeActiveItemIndex: () => maybeActiveItemIndex,
235
- activationTrigger: () => Option.match(maybeActiveItemIndex, {
236
- onNone: () => 'Pointer',
237
- onSome: () => 'Keyboard',
238
- }),
239
- maybeLastPointerPosition: () => Option.none(),
240
- })),
241
- Closed: () => closeCombobox(model, [focusInput]),
242
- BlurredInput: () => closeCombobox(model, []),
243
- ActivatedItem: ({ index, activationTrigger, maybeImmediateSelection, }) => {
244
- const highlightedModel = constrainedEvo(model, {
245
- maybeActiveItemIndex: () => Option.some(index),
246
- activationTrigger: () => activationTrigger,
247
- });
248
- const nextModel = Option.match(maybeImmediateSelection, {
249
- onNone: () => highlightedModel,
250
- onSome: ({ item, displayText }) => handlers.handleImmediateActivation(highlightedModel, item, displayText),
251
- });
252
- return [
253
- nextModel,
254
- activationTrigger === 'Keyboard'
255
- ? [ScrollIntoView({ id: model.id, index })]
256
- : [],
257
- Option.none(),
258
- ];
259
- },
260
- MovedPointerOverItem: ({ index, screenX, screenY }) => {
261
- const isSamePosition = Option.exists(model.maybeLastPointerPosition, position => position.screenX === screenX && position.screenY === screenY);
262
- if (isSamePosition) {
263
- return [model, [], Option.none()];
264
- }
265
- return [
266
- constrainedEvo(model, {
267
- maybeActiveItemIndex: () => Option.some(index),
268
- activationTrigger: () => 'Pointer',
269
- maybeLastPointerPosition: () => Option.some({ screenX, screenY }),
270
- }),
271
- [],
272
- Option.none(),
273
- ];
274
- },
275
- DeactivatedItem: () => model.activationTrigger === 'Pointer'
276
- ? [
277
- constrainedEvo(model, {
278
- maybeActiveItemIndex: () => Option.none(),
279
- }),
280
- [],
281
- Option.none(),
282
- ]
283
- : [model, [], Option.none()],
284
- SelectedItem: ({ item, displayText }) => {
285
- const [nextModel, commands, maybeOutMessage] = handlers.handleSelectedItem(model, item, displayText, {
286
- focusInput,
287
- maybeUnlockScroll,
288
- maybeRestoreInert,
289
- });
290
- if (model.isOpen && !nextModel.isOpen && model.isAnimated) {
291
- const [transitionedModel, animationCommands] = delegateToAnimation(nextModel, AnimationHid());
292
- return [
293
- transitionedModel,
294
- [...commands, ...animationCommands],
295
- maybeOutMessage,
296
- ];
297
- }
298
- return [nextModel, commands, maybeOutMessage];
299
- },
300
- RequestedItemClick: ({ index }) => [
301
- model,
302
- [ClickItem({ id: model.id, index })],
303
- Option.none(),
304
- ],
305
- UpdatedInputValue: ({ value }) => {
306
- if (model.isOpen) {
307
- return [
308
- constrainedEvo(model, {
309
- inputValue: () => value,
310
- maybeActiveItemIndex: () => Option.some(0),
311
- activationTrigger: () => 'Keyboard',
312
- }),
313
- [],
314
- Option.none(),
315
- ];
316
- }
317
- return openCombobox(constrainedEvo(model, {
318
- inputValue: () => value,
319
- maybeActiveItemIndex: () => Option.some(0),
320
- activationTrigger: () => 'Keyboard',
321
- maybeLastPointerPosition: () => Option.none(),
322
- }));
323
- },
324
- PressedToggleButton: () => {
325
- if (model.isOpen) {
326
- return closeCombobox(model, [focusInput]);
327
- }
328
- const [nextModel, commands] = openCombobox(constrainedEvo(model, {
329
- maybeActiveItemIndex: () => Option.none(),
330
- activationTrigger: () => 'Pointer',
331
- maybeLastPointerPosition: () => Option.none(),
332
- }));
333
- return [nextModel, [focusInput, ...commands], Option.none()];
334
- },
335
- GotAnimationMessage: ({ message: animationMessage }) => delegateToAnimation(model, animationMessage),
336
- }));
337
- };
338
- return internalUpdate;
339
- };
340
- /** The anchor-positioning Mount this Combobox renders on its items panel.
341
- * The panel is always anchored to the input wrapper via Floating UI and
342
- * portaled to the document body (opt out of portaling with
343
- * `anchor.portal: false`), so it escapes ancestor stacking contexts and
344
- * overflow clipping. The Mount also installs the `pointerdown`-cancelling
345
- * capture listener that prevents input blur on item presses. Exposed so
346
- * Scene tests can call
347
- * `Scene.Mount.resolve(AnchorCombobox, CompletedAnchorCombobox())`. */
348
- export const AnchorCombobox = Mount.define('AnchorCombobox', { buttonId: S.String, anchor: AnchorConfig }, CompletedAnchorCombobox)(({ buttonId, anchor }) => element => Effect.gen(function* () {
349
- yield* Effect.acquireRelease(Effect.sync(() => {
350
- const preventBlur = (event) => {
351
- event.preventDefault();
352
- };
353
- element.addEventListener('pointerdown', preventBlur, {
354
- capture: true,
355
- });
356
- const teardownAnchor = anchorSetup({
357
- buttonId,
358
- anchor,
359
- interceptTab: false,
360
- })(element);
361
- return () => {
362
- element.removeEventListener('pointerdown', preventBlur, {
363
- capture: true,
364
- });
365
- teardownAnchor();
366
- };
367
- }), cleanup => Effect.sync(cleanup));
368
- return CompletedAnchorCombobox();
369
- }));
370
- /** The Mount this Combobox renders to install a `pointerdown`-cancelling
371
- * capture listener that prevents blur on item presses. Exposed so Scene
372
- * tests can call
373
- * `Scene.Mount.resolve(AttachComboboxPreventBlur, CompletedAttachComboboxPreventBlur())`. */
374
- export const AttachComboboxPreventBlur = Mount.define('AttachComboboxPreventBlur', CompletedAttachComboboxPreventBlur)(element => Effect.gen(function* () {
375
- yield* Effect.acquireRelease(Effect.sync(() => {
376
- const handler = (event) => {
377
- event.preventDefault();
378
- };
379
- element.addEventListener('pointerdown', handler, { capture: true });
380
- return handler;
381
- }), handler => Effect.sync(() => element.removeEventListener('pointerdown', handler, {
382
- capture: true,
383
- })));
384
- return CompletedAttachComboboxPreventBlur();
385
- }));
386
- /** The Mount this Combobox renders to install the input's select-on-focus
387
- * behavior. Exposed so Scene tests can call
388
- * `Scene.Mount.resolve(AttachComboboxSelectOnFocus, CompletedAttachComboboxSelectOnFocus())`. */
389
- export const AttachComboboxSelectOnFocus = Mount.define('AttachComboboxSelectOnFocus', CompletedAttachComboboxSelectOnFocus)(element => Effect.gen(function* () {
390
- yield* Effect.acquireRelease(Effect.sync(() => {
391
- const handler = () => {
392
- if (element instanceof HTMLInputElement) {
393
- element.select();
394
- }
395
- };
396
- element.addEventListener('focus', handler);
397
- return handler;
398
- }), handler => Effect.sync(() => element.removeEventListener('focus', handler)));
399
- return CompletedAttachComboboxSelectOnFocus();
400
- }));
401
- /** The backdrop-portaling Mount this Combobox renders. Exposed so Scene tests can
402
- * call `Scene.Mount.resolve(PortalComboboxBackdrop, CompletedPortalComboboxBackdrop())` to
403
- * acknowledge the mount produced by the rendered backdrop. */
404
- export const PortalComboboxBackdrop = Mount.define('PortalComboboxBackdrop', CompletedPortalComboboxBackdrop)(element => Effect.gen(function* () {
405
- yield* Effect.acquireRelease(Effect.sync(() => portalToBody(element)), cleanup => Effect.sync(cleanup));
406
- return CompletedPortalComboboxBackdrop();
407
- }));
408
- /** Creates a combobox view function from variant-specific behavior. Shared rendering logic (input, items, transitions, keyboard navigation) is handled internally; only selection display varies by variant. */
409
- export const makeView = (behavior) => {
410
- const impl = defineView((model, viewInputs) => {
411
- const h = html();
412
- const { id, isOpen, immediate, animation: { transitionState }, maybeActiveItemIndex, } = model;
413
- const { items, itemToConfig, itemToValue, itemToDisplayText, isItemDisabled, inputClassName, inputAttributes = [], inputPlaceholder, inputWrapperClassName, inputWrapperAttributes = [], itemsClassName, itemsAttributes = [], itemsScrollClassName, itemsScrollAttributes = [], backdropClassName, backdropAttributes = [], className, attributes = [], buttonContent, buttonClassName, buttonAttributes = [], formName, isDisabled, isInvalid, openOnFocus, itemGroupKey, groupToHeading, groupClassName, groupAttributes = [], separatorClassName, separatorAttributes = [], anchor = {}, } = viewInputs;
414
- const isLeaving = transitionState === 'LeaveStart' || transitionState === 'LeaveAnimating';
415
- const isVisible = isOpen || isLeaving;
416
- const animationAttributes = M.value(transitionState).pipe(M.when('EnterStart', () => [
417
- h.DataAttribute('closed', ''),
418
- h.DataAttribute('enter', ''),
419
- h.DataAttribute('transition', ''),
420
- ]), M.when('EnterAnimating', () => [
421
- h.DataAttribute('enter', ''),
422
- h.DataAttribute('transition', ''),
423
- ]), M.when('LeaveStart', () => [
424
- h.DataAttribute('leave', ''),
425
- h.DataAttribute('transition', ''),
426
- ]), M.when('LeaveAnimating', () => [
427
- h.DataAttribute('closed', ''),
428
- h.DataAttribute('leave', ''),
429
- h.DataAttribute('transition', ''),
430
- ]), M.orElse(() => []));
431
- const isDisabledAtIndex = (index) => Predicate.isNotUndefined(isItemDisabled) &&
432
- pipe(items, Array.get(index), Option.exists(item => isItemDisabled(item, index)));
433
- const firstEnabledIndex = findFirstEnabledIndex(items.length, 0, isDisabledAtIndex)(0, 1);
434
- const lastEnabledIndex = findFirstEnabledIndex(items.length, 0, isDisabledAtIndex)(items.length - 1, -1);
435
- const resolveActiveIndex = keyToIndex('ArrowDown', 'ArrowUp', items.length, Option.getOrElse(maybeActiveItemIndex, () => -1), isDisabledAtIndex);
436
- const resolveImmediateSelection = (targetIndex) => OptionExt.when(immediate, pipe(items, Array.get(targetIndex), Option.match({
437
- onNone: () => ({ item: '', displayText: '' }),
438
- onSome: targetItem => ({
439
- item: itemToValue(targetItem, targetIndex),
440
- displayText: itemToDisplayText(targetItem, targetIndex),
441
- }),
442
- })));
443
- const handleInputKeyDown = (key) => M.value(key).pipe(M.when('ArrowDown', () => {
444
- if (!isOpen) {
445
- return Option.some(Opened({
446
- maybeActiveItemIndex: Option.some(firstEnabledIndex),
447
- }));
448
- }
449
- const targetIndex = resolveActiveIndex('ArrowDown');
450
- return Option.some(ActivatedItem({
451
- index: targetIndex,
452
- activationTrigger: 'Keyboard',
453
- maybeImmediateSelection: resolveImmediateSelection(targetIndex),
454
- }));
455
- }), M.when('ArrowUp', () => {
456
- if (!isOpen) {
457
- return Option.some(Opened({
458
- maybeActiveItemIndex: Option.some(lastEnabledIndex),
459
- }));
460
- }
461
- const targetIndex = resolveActiveIndex('ArrowUp');
462
- return Option.some(ActivatedItem({
463
- index: targetIndex,
464
- activationTrigger: 'Keyboard',
465
- maybeImmediateSelection: resolveImmediateSelection(targetIndex),
466
- }));
467
- }), M.when('Enter', () => {
468
- if (!isOpen) {
469
- return Option.none();
470
- }
471
- return Option.map(maybeActiveItemIndex, index => RequestedItemClick({ index }));
472
- }), M.when('Escape', () => {
473
- if (!isOpen) {
474
- return Option.none();
475
- }
476
- return Option.some(Closed());
477
- }), M.whenOr('Home', 'End', () => {
478
- if (!isOpen) {
479
- return Option.none();
480
- }
481
- const targetIndex = resolveActiveIndex(key);
482
- return Option.some(ActivatedItem({
483
- index: targetIndex,
484
- activationTrigger: 'Keyboard',
485
- maybeImmediateSelection: resolveImmediateSelection(targetIndex),
486
- }));
487
- }), M.orElse(() => Option.none()));
488
- const maybeActiveDescendant = Option.match(maybeActiveItemIndex, {
489
- onNone: () => [],
490
- onSome: index => [h.AriaActiveDescendant(itemId(id, index))],
491
- });
492
- const resolvedInputAttributes = [
493
- h.Id(`${id}-input`),
494
- h.Role('combobox'),
495
- h.AriaExpanded(isVisible),
496
- h.AriaControls(`${id}-items`),
497
- h.Attribute('aria-autocomplete', 'list'),
498
- h.Attribute('aria-haspopup', 'listbox'),
499
- h.Autocomplete('off'),
500
- h.Value(model.inputValue),
501
- ...maybeActiveDescendant,
502
- ...(inputPlaceholder ? [h.Placeholder(inputPlaceholder)] : []),
503
- ...(isDisabled
504
- ? [h.AriaDisabled(true), h.DataAttribute('disabled', '')]
505
- : [
506
- h.OnInput(value => UpdatedInputValue({ value })),
507
- h.OnKeyDownPreventDefault(handleInputKeyDown),
508
- h.OnBlur(BlurredInput()),
509
- ...(openOnFocus
510
- ? [h.OnFocus(Opened({ maybeActiveItemIndex: Option.none() }))]
511
- : []),
512
- ]),
513
- ...(isInvalid
514
- ? [h.AriaInvalid(true), h.DataAttribute('invalid', '')]
515
- : []),
516
- ...(isVisible ? [h.DataAttribute('open', '')] : []),
517
- ...(model.selectInputOnFocus
518
- ? [h.OnMount(AttachComboboxSelectOnFocus())]
519
- : []),
520
- ...(inputClassName ? [h.Class(inputClassName)] : []),
521
- ...inputAttributes,
522
- ];
523
- const anchorAttributes = [
524
- h.Style({
525
- position: 'absolute',
526
- margin: '0',
527
- visibility: 'hidden',
528
- }),
529
- h.OnMount(AnchorCombobox({
530
- buttonId: `${id}-input-wrapper`,
531
- anchor,
532
- })),
533
- ];
534
- const itemsContainerAttributes = [
535
- h.Id(`${id}-items`),
536
- h.Role('listbox'),
537
- ...(behavior.ariaMultiSelectable ? [h.AriaMultiSelectable(true)] : []),
538
- h.AriaLabelledBy(`${id}-input`),
539
- h.Tabindex(-1),
540
- ...anchorAttributes,
541
- ...animationAttributes,
542
- ...(itemsClassName ? [h.Class(itemsClassName)] : []),
543
- ...itemsAttributes,
544
- ];
545
- const comboboxItems = Array.map(items, (item, index) => {
546
- const isActiveItem = Option.exists(maybeActiveItemIndex, activeIndex => activeIndex === index);
547
- const isDisabledItem = isDisabledAtIndex(index);
548
- const isSelectedItem = behavior.isItemSelected(model, itemToValue(item, index));
549
- const itemConfig = itemToConfig(item, {
550
- isActive: isActiveItem,
551
- isDisabled: isDisabledItem,
552
- isSelected: isSelectedItem,
553
- });
554
- const isInteractive = !isDisabledItem && !isLeaving;
555
- return h.keyed('div')(itemId(id, index), [
556
- h.Id(itemId(id, index)),
557
- h.Role('option'),
558
- h.AriaSelected(isSelectedItem),
559
- ...(isActiveItem ? [h.DataAttribute('active', '')] : []),
560
- ...(isSelectedItem ? [h.DataAttribute('selected', '')] : []),
561
- ...(isDisabledItem
562
- ? [h.AriaDisabled(true), h.DataAttribute('disabled', '')]
563
- : []),
564
- ...(isInteractive
565
- ? [
566
- h.OnClick(SelectedItem({
567
- item: itemToValue(item, index),
568
- displayText: itemToDisplayText(item, index),
569
- })),
570
- ...(isActiveItem
571
- ? []
572
- : [
573
- h.OnPointerMove((screenX, screenY, pointerType) => OptionExt.when(pointerType !== 'touch', MovedPointerOverItem({ index, screenX, screenY }))),
574
- ]),
575
- h.OnPointerLeave(pointerType => OptionExt.when(pointerType !== 'touch', DeactivatedItem())),
576
- ]
577
- : []),
578
- ...(itemConfig.className ? [h.Class(itemConfig.className)] : []),
579
- ], [itemConfig.content]);
580
- });
581
- const renderGroupedItems = () => {
582
- if (!itemGroupKey) {
583
- return comboboxItems;
584
- }
585
- const segments = groupContiguous(comboboxItems, (_, index) => Array.get(items, index).pipe(Option.match({
586
- onNone: () => '',
587
- onSome: item => itemGroupKey(item, index),
588
- })));
589
- return Array.flatMap(segments, (segment, segmentIndex) => {
590
- const maybeHeading = Option.fromNullishOr(groupToHeading && groupToHeading(segment.key));
591
- const headingId = `${id}-heading-${segment.key}`;
592
- const headingElement = Option.match(maybeHeading, {
593
- onNone: () => [],
594
- onSome: heading => [
595
- h.keyed('div')(headingId, [
596
- h.Id(headingId),
597
- h.Role('presentation'),
598
- ...(heading.className ? [h.Class(heading.className)] : []),
599
- ], [heading.content]),
600
- ],
601
- });
602
- const groupContent = [...headingElement, ...segment.items];
603
- const groupElement = h.keyed('div')(`${id}-group-${segment.key}`, [
604
- h.Role('group'),
605
- ...(Option.isSome(maybeHeading)
606
- ? [h.AriaLabelledBy(headingId)]
607
- : []),
608
- ...(groupClassName ? [h.Class(groupClassName)] : []),
609
- ...groupAttributes,
610
- ], groupContent);
611
- const separator = segmentIndex > 0 &&
612
- (separatorClassName ||
613
- Array.isReadonlyArrayNonEmpty(separatorAttributes))
614
- ? [
615
- h.keyed('div')(`${id}-separator-${segmentIndex}`, [
616
- h.Role('separator'),
617
- ...(separatorClassName
618
- ? [h.Class(separatorClassName)]
619
- : []),
620
- ...separatorAttributes,
621
- ], []),
622
- ]
623
- : [];
624
- return [...separator, groupElement];
625
- });
626
- };
627
- const backdrop = h.keyed('div')(`${id}-backdrop`, [
628
- h.OnMount(PortalComboboxBackdrop()),
629
- ...(isLeaving ? [] : [h.OnClick(Closed())]),
630
- ...(backdropClassName ? [h.Class(backdropClassName)] : []),
631
- ...backdropAttributes,
632
- ], []);
633
- const renderedItems = renderGroupedItems();
634
- const scrollableItems = itemsScrollClassName ||
635
- Array.isReadonlyArrayNonEmpty(itemsScrollAttributes)
636
- ? [
637
- h.div([
638
- ...(itemsScrollClassName
639
- ? [h.Class(itemsScrollClassName)]
640
- : []),
641
- ...itemsScrollAttributes,
642
- ], renderedItems),
643
- ]
644
- : renderedItems;
645
- const visibleContent = [
646
- backdrop,
647
- h.keyed('div')(`${id}-items-container`, itemsContainerAttributes, scrollableItems),
648
- ];
649
- const resolvedInputWrapperAttributes = [
650
- h.Id(`${id}-input-wrapper`),
651
- ...(inputWrapperClassName ? [h.Class(inputWrapperClassName)] : []),
652
- ...inputWrapperAttributes,
653
- ];
654
- const toggleButton = buttonContent
655
- ? [
656
- h.keyed('button')(`${id}-button`, [
657
- h.Id(`${id}-button`),
658
- h.Type('button'),
659
- h.Tabindex(-1),
660
- h.AriaControls(`${id}-items`),
661
- h.AriaExpanded(isVisible),
662
- h.Attribute('aria-haspopup', 'listbox'),
663
- ...(isDisabled
664
- ? [h.AriaDisabled(true), h.DataAttribute('disabled', '')]
665
- : [h.OnClick(PressedToggleButton())]),
666
- h.OnMount(AttachComboboxPreventBlur()),
667
- ...(buttonClassName ? [h.Class(buttonClassName)] : []),
668
- ...buttonAttributes,
669
- ], [buttonContent]),
670
- ]
671
- : [];
672
- const selectedValues = pipe(items, Array.filterMap((item, index) => {
673
- const value = itemToValue(item, index);
674
- return Result.fromOption(OptionExt.when(behavior.isItemSelected(model, value), value), () => undefined);
675
- }));
676
- const hiddenInputs = formName
677
- ? Array.match(selectedValues, {
678
- onEmpty: () => [h.input([h.Type('hidden'), h.Name(formName)])],
679
- onNonEmpty: Array.map(selectedValue => h.input([
680
- h.Type('hidden'),
681
- h.Name(formName),
682
- h.Value(selectedValue),
683
- ])),
684
- })
685
- : [];
686
- const wrapperAttributes = [
687
- ...(className ? [h.Class(className)] : []),
688
- ...attributes,
689
- ...(isVisible ? [h.DataAttribute('open', '')] : []),
690
- ...(isDisabled ? [h.DataAttribute('disabled', '')] : []),
691
- ...(isInvalid ? [h.DataAttribute('invalid', '')] : []),
692
- ];
693
- return h.div(wrapperAttributes, [
694
- h.div(resolvedInputWrapperAttributes, [
695
- h.input(resolvedInputAttributes),
696
- ...toggleButton,
697
- ]),
698
- ...(isVisible && Array.isReadonlyArrayNonEmpty(items)
699
- ? visibleContent
700
- : []),
701
- ...hiddenInputs,
702
- ]);
703
- });
704
- return () =>
705
- /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions */
706
- impl;
707
- };