@cognitap/radiant 0.0.38 → 0.0.40

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 (60) hide show
  1. package/CHANGELOG.md +12 -4
  2. package/dist/library/Combobox.d.ts +31 -7
  3. package/dist/library/Combobox.d.ts.map +1 -1
  4. package/dist/library/Combobox.js +162 -42
  5. package/dist/library/Combobox.js.map +1 -1
  6. package/dist/library/Drawer.js +3 -3
  7. package/dist/library/Drawer.js.map +1 -1
  8. package/dist/library/Input.d.ts +6 -1
  9. package/dist/library/Input.d.ts.map +1 -1
  10. package/dist/library/Input.js +6 -2
  11. package/dist/library/Input.js.map +1 -1
  12. package/dist/library/MultiSelect.d.ts +30 -0
  13. package/dist/library/MultiSelect.d.ts.map +1 -0
  14. package/dist/library/MultiSelect.js +49 -0
  15. package/dist/library/MultiSelect.js.map +1 -0
  16. package/dist/library/Tag.d.ts +17 -0
  17. package/dist/library/Tag.d.ts.map +1 -0
  18. package/dist/library/Tag.js +13 -0
  19. package/dist/library/Tag.js.map +1 -0
  20. package/dist/library/TagsInput.d.ts +21 -0
  21. package/dist/library/TagsInput.d.ts.map +1 -0
  22. package/dist/library/TagsInput.js +183 -0
  23. package/dist/library/TagsInput.js.map +1 -0
  24. package/dist/library/cn.d.ts.map +1 -1
  25. package/dist/library/cn.js +4 -1
  26. package/dist/library/cn.js.map +1 -1
  27. package/dist/library/index.d.ts +8 -0
  28. package/dist/library/index.d.ts.map +1 -1
  29. package/dist/library/index.js +4 -0
  30. package/dist/library/index.js.map +1 -1
  31. package/dist/library/internal/tags.d.ts +7 -0
  32. package/dist/library/internal/tags.d.ts.map +1 -0
  33. package/dist/library/internal/tags.js +30 -0
  34. package/dist/library/internal/tags.js.map +1 -0
  35. package/dist/library/react/useArrayFormBridge.d.ts +13 -0
  36. package/dist/library/react/useArrayFormBridge.d.ts.map +1 -0
  37. package/dist/library/react/useArrayFormBridge.js +52 -0
  38. package/dist/library/react/useArrayFormBridge.js.map +1 -0
  39. package/dist/library/react/useComboboxPopup.d.ts.map +1 -1
  40. package/dist/library/react/useComboboxPopup.js +9 -2
  41. package/dist/library/react/useComboboxPopup.js.map +1 -1
  42. package/dist/library/styles.css +1 -1
  43. package/dist/library/themes/components.d.ts +9 -0
  44. package/dist/library/themes/components.d.ts.map +1 -1
  45. package/dist/library/themes/components.js +3 -0
  46. package/dist/library/themes/components.js.map +1 -1
  47. package/docs/architecture.md +11 -4
  48. package/package.json +1 -1
  49. package/src/Combobox.tsx +302 -91
  50. package/src/Drawer.tsx +3 -3
  51. package/src/Input.tsx +17 -3
  52. package/src/MultiSelect.tsx +93 -0
  53. package/src/Tag.tsx +59 -0
  54. package/src/TagsInput.tsx +302 -0
  55. package/src/cn.ts +4 -1
  56. package/src/index.ts +33 -0
  57. package/src/internal/tags.ts +31 -0
  58. package/src/react/useArrayFormBridge.ts +60 -0
  59. package/src/react/useComboboxPopup.ts +9 -2
  60. package/src/themes/components.ts +3 -0
package/src/Input.tsx CHANGED
@@ -48,7 +48,20 @@ export type InputProps = Omit<ComponentProps<'input'>, 'value' | 'defaultValue'
48
48
  }
49
49
 
50
50
  /** Native editing, selection, events and ref; Field supplies owned form relationships. */
51
- export function Input({
51
+ export function Input(props: InputProps) {
52
+ return (
53
+ <InputRoot
54
+ {...props}
55
+ family={undefined}
56
+ nativeRequired={undefined}
57
+ />
58
+ )
59
+ }
60
+
61
+ /** Private composition seam: hosted families keep Input's actual native control. */
62
+ export function InputRoot({
63
+ family,
64
+ nativeRequired,
52
65
  className,
53
66
  controlSize = 'medium',
54
67
  type = 'text',
@@ -59,7 +72,7 @@ export function Input({
59
72
  'aria-invalid': ariaInvalid,
60
73
  'aria-required': ariaRequired,
61
74
  ...props
62
- }: InputProps) {
75
+ }: InputProps & { family?: 'tags-input'; nativeRequired?: false }) {
63
76
  const ownsValue = !['checkbox', 'radio', 'file'].includes(type)
64
77
  useNativeOwner('Input', props.value, props.defaultValue, ownsValue)
65
78
  if (ownsValue && props.value === null)
@@ -77,9 +90,10 @@ export function Input({
77
90
  <input
78
91
  {...props}
79
92
  {...control}
93
+ required={nativeRequired === false ? false : control.required}
80
94
  className={cn(inputVariants(), controlMetrics({ controlSize }), className)}
81
95
  data-control-size={controlSize}
82
- data-slot="input"
96
+ data-slot={family ? `input ${family}` : 'input'}
83
97
  type={type}
84
98
  />
85
99
  )
@@ -0,0 +1,93 @@
1
+ 'use client'
2
+
3
+ import type { ComponentProps } from 'react'
4
+ import {
5
+ Combobox,
6
+ ComboboxInput,
7
+ ComboboxTrigger,
8
+ ComboboxClear,
9
+ ComboboxPortal,
10
+ ComboboxContent,
11
+ ComboboxItem,
12
+ ComboboxStatus,
13
+ ComboboxTags,
14
+ useCombobox,
15
+ type ComboboxMultipleProps,
16
+ type ComboboxMultipleState,
17
+ type ComboboxOption,
18
+ type ComboboxInputProps,
19
+ type ComboboxTriggerProps,
20
+ type ComboboxClearProps,
21
+ type ComboboxContentProps,
22
+ type ComboboxItemProps,
23
+ type ComboboxStatusProps,
24
+ type ComboboxTagsProps
25
+ } from './Combobox.js'
26
+ import type { ButtonRenderProps } from './Button.js'
27
+ import type { DistributiveOmit } from './internal/types.js'
28
+
29
+ export type MultiSelectProps = DistributiveOmit<ComboboxMultipleProps, 'multiple'> & {
30
+ multiple?: never
31
+ }
32
+ export type MultiSelectState = ComboboxMultipleState
33
+ export type MultiSelectOption = ComboboxOption
34
+ export type MultiSelectInputProps = ComboboxInputProps
35
+ export type MultiSelectTriggerProps = ComboboxTriggerProps
36
+ export type MultiSelectClearProps = ComboboxClearProps
37
+ export type MultiSelectPortalProps = ComponentProps<typeof ComboboxPortal>
38
+ export type MultiSelectContentProps = ComboboxContentProps
39
+ export type MultiSelectItemProps = ComboboxItemProps
40
+ export type MultiSelectStatusProps = ComboboxStatusProps
41
+ export type MultiSelectTagsProps = ComboboxTagsProps
42
+ export type MultiSelectRenderProps = ButtonRenderProps
43
+
44
+ export function useMultiSelect(): MultiSelectState | null {
45
+ return useCombobox({ multiple: true })
46
+ }
47
+ function useMultiSelectContext() {
48
+ const state = useMultiSelect()
49
+ if (!state)
50
+ throw new Error('MultiSelect parts must render inside MultiSelect or a multiple Combobox.')
51
+ return state
52
+ }
53
+ /** Array selection is the real Combobox multiple mode, including its native form bridge. */
54
+ export function MultiSelect(props: MultiSelectProps) {
55
+ return (
56
+ <Combobox
57
+ {...props}
58
+ multiple
59
+ />
60
+ )
61
+ }
62
+ export function MultiSelectInput(props: MultiSelectInputProps) {
63
+ useMultiSelectContext()
64
+ return <ComboboxInput {...props} />
65
+ }
66
+ export function MultiSelectTrigger(props: MultiSelectTriggerProps) {
67
+ useMultiSelectContext()
68
+ return <ComboboxTrigger {...props} />
69
+ }
70
+ export function MultiSelectClear(props: MultiSelectClearProps) {
71
+ useMultiSelectContext()
72
+ return <ComboboxClear {...props} />
73
+ }
74
+ export function MultiSelectPortal(props: MultiSelectPortalProps) {
75
+ useMultiSelectContext()
76
+ return <ComboboxPortal {...props} />
77
+ }
78
+ export function MultiSelectContent(props: MultiSelectContentProps) {
79
+ useMultiSelectContext()
80
+ return <ComboboxContent {...props} />
81
+ }
82
+ export function MultiSelectItem(props: MultiSelectItemProps) {
83
+ useMultiSelectContext()
84
+ return <ComboboxItem {...props} />
85
+ }
86
+ export function MultiSelectStatus(props: MultiSelectStatusProps) {
87
+ useMultiSelectContext()
88
+ return <ComboboxStatus {...props} />
89
+ }
90
+ export function MultiSelectTags(props: MultiSelectTagsProps) {
91
+ useMultiSelectContext()
92
+ return <ComboboxTags {...props} />
93
+ }
package/src/Tag.tsx ADDED
@@ -0,0 +1,59 @@
1
+ 'use client'
2
+
3
+ import type { MouseEvent, ReactNode } from 'react'
4
+ import { Badge, type BadgeProps } from './Badge.js'
5
+ import { Button } from './Button.js'
6
+ import { cn } from './cn.js'
7
+ import { joinIds } from './internal/ids.js'
8
+ import { requireAccessibleName } from './internal/accessibleName.js'
9
+ import type { PartStyle } from './presentation.js'
10
+
11
+ export type TagProps = Omit<BadgeProps, 'decorative' | 'children'> & {
12
+ children: ReactNode
13
+ /** Name the actual removal Button, including when the content is rich. */
14
+ removeLabel: string
15
+ onRemove(event: MouseEvent<HTMLButtonElement>): void
16
+ disabled?: boolean
17
+ pending?: boolean
18
+ parts?: { remove?: PartStyle }
19
+ }
20
+ /** Removable content uses the real Badge span and a real, named Button. */
21
+ export function Tag({
22
+ removeLabel,
23
+ onRemove,
24
+ disabled = false,
25
+ pending = false,
26
+ parts,
27
+ className,
28
+ children,
29
+ ...props
30
+ }: TagProps) {
31
+ requireAccessibleName('Tag removal', { 'aria-label': removeLabel })
32
+ return (
33
+ <Badge
34
+ {...props}
35
+ decorative={false}
36
+ data-slot={joinIds('tag', props['data-slot'])}
37
+ className={cn('gap-[var(--rad-tag-gap,0.25rem)]', className)}
38
+ >
39
+ <span className="min-w-0 break-words">{children}</span>
40
+ <Button
41
+ type="button"
42
+ variant="ghost"
43
+ tone={props.tone ?? 'neutral'}
44
+ controlSize="small"
45
+ motion="off"
46
+ iconOnly
47
+ aria-label={removeLabel}
48
+ disabled={disabled}
49
+ pending={pending}
50
+ data-slot="tag-remove"
51
+ className={cn('size-6 min-h-0 shrink-0 p-0', parts?.remove?.className)}
52
+ style={parts?.remove?.style}
53
+ onClick={onRemove}
54
+ >
55
+ <span aria-hidden="true">×</span>
56
+ </Button>
57
+ </Badge>
58
+ )
59
+ }
@@ -0,0 +1,302 @@
1
+ 'use client'
2
+
3
+ import { useId, useLayoutEffect, useRef, useState } from 'react'
4
+ import { InputRoot, type InputProps } from './Input.js'
5
+ import { Tag } from './Tag.js'
6
+ import { useFieldControl } from './Field.js'
7
+ import { cn } from './cn.js'
8
+ import { joinIds } from './internal/ids.js'
9
+ import { sameSelection } from './internal/selection.js'
10
+ import { splitTags, tagSeparators, validateTags } from './internal/tags.js'
11
+ import type { DistributiveOmit } from './internal/types.js'
12
+ import { useControllableState } from './react/useControllableState.js'
13
+ import { useComposedRefs } from './react/useComposedRefs.js'
14
+ import { useArrayFormBridge } from './react/useArrayFormBridge.js'
15
+ import type { ValueOwner } from './react/useNativeOwner.js'
16
+ import type { PartStyle } from './presentation.js'
17
+
18
+ export type TagsInputProps = DistributiveOmit<
19
+ InputProps,
20
+ 'value' | 'defaultValue' | 'type' | 'children'
21
+ > &
22
+ ValueOwner<string[]> & {
23
+ onValueChange?: (values: string[]) => void
24
+ /** Single-character separators; line breaks in pasted text also separate tags. */
25
+ separators?: readonly string[]
26
+ /** True accepts; false or an error message rejects. Values are trimmed before validation. */
27
+ validate?: (value: string) => boolean | string
28
+ maxCount?: number
29
+ parts?: { wrapper?: PartStyle; tag?: PartStyle; remove?: PartStyle; message?: PartStyle }
30
+ }
31
+ const defaultSeparators = [','] as const
32
+
33
+ /** Native text editing and Tag removal; only committed array values are submitted. */
34
+ export function TagsInput({
35
+ value,
36
+ defaultValue,
37
+ onValueChange,
38
+ separators = defaultSeparators,
39
+ validate,
40
+ maxCount,
41
+ parts,
42
+ name,
43
+ form,
44
+ disabled,
45
+ required,
46
+ readOnly,
47
+ className,
48
+ ref,
49
+ onChange,
50
+ onKeyDown,
51
+ onPaste,
52
+ onCompositionStart,
53
+ onCompositionEnd,
54
+ ...props
55
+ }: TagsInputProps) {
56
+ const control = useFieldControl({
57
+ id: props.id,
58
+ disabled,
59
+ required,
60
+ 'aria-describedby': props['aria-describedby'],
61
+ 'aria-invalid': props['aria-invalid'],
62
+ 'aria-required': props['aria-required']
63
+ })
64
+ const selection = useControllableState({
65
+ name: 'TagsInput',
66
+ value,
67
+ defaultValue: defaultValue ? [...defaultValue] : undefined,
68
+ initialValue: [] as string[],
69
+ equal: sameSelection,
70
+ onChange: (next: string[]) => onValueChange?.([...next])
71
+ })
72
+ validateTags(selection.value)
73
+ if (selection.value.some(value => !value.trim() || value !== value.trim()))
74
+ throw new TypeError('TagsInput values must be nonempty trimmed strings.')
75
+ if (maxCount !== undefined && (!Number.isInteger(maxCount) || maxCount < 0))
76
+ throw new TypeError('TagsInput maxCount must be a nonnegative integer.')
77
+ const delimiters = tagSeparators(separators)
78
+ const [draft, setDraft] = useState(''),
79
+ [error, setError] = useState('')
80
+ const input = useRef<HTMLInputElement>(null),
81
+ composed = useComposedRefs(input, ref),
82
+ composing = useRef(false)
83
+ const message = useId(),
84
+ pending = useRef<string[] | null>(null)
85
+ const draftRequest = useRef<{ values: string[]; remainder: string; error: string } | null>(null)
86
+ const maximum = maxCount === undefined ? Infinity : maxCount
87
+ const limitMessage = `Use at most ${maxCount} tags.`
88
+ const feedback = selection.value.length > maximum ? limitMessage : error
89
+ const unavailable = () => control.disabled || readOnly || !!input.current?.matches(':disabled')
90
+ const request = (next: string[]) => {
91
+ if (unavailable() || sameSelection(next, selection.value)) return
92
+ pending.current = next
93
+ selection.request(next)
94
+ queueMicrotask(() => {
95
+ pending.current = null
96
+ })
97
+ }
98
+ const remove = (value: string) => {
99
+ if (unavailable()) return
100
+ draftRequest.current = null
101
+ request(selection.value.filter(item => item !== value))
102
+ setError('')
103
+ input.current?.focus({ preventScroll: true })
104
+ }
105
+ function add(text: string, final: boolean) {
106
+ if (unavailable()) return
107
+ const { segments, remainder } = splitTags(text, delimiters, final)
108
+ if (!segments.length) return
109
+ const next = [...selection.value],
110
+ rejected: string[] = []
111
+ let reason = ''
112
+ for (const segment of segments) {
113
+ const candidate = segment.trim()
114
+ if (!candidate) continue
115
+ const verdict = validate?.(candidate) ?? true
116
+ const failure = next.includes(candidate)
117
+ ? 'This tag is already added.'
118
+ : next.length >= maximum
119
+ ? limitMessage
120
+ : verdict === true
121
+ ? ''
122
+ : typeof verdict === 'string' && verdict
123
+ ? verdict
124
+ : 'Enter a valid tag.'
125
+ if (failure) {
126
+ rejected.push(segment)
127
+ reason ||= failure
128
+ } else next.push(candidate)
129
+ }
130
+ const rest = [...rejected, ...(remainder ? [remainder] : [])].join(separators[0] ?? ',')
131
+ setError(reason)
132
+ if (sameSelection(next, selection.value)) {
133
+ draftRequest.current = null
134
+ setDraft(rest)
135
+ setError(reason)
136
+ return
137
+ }
138
+ draftRequest.current = { values: next, remainder: rest, error: reason }
139
+ request(next)
140
+ }
141
+ useLayoutEffect(() => {
142
+ const change = draftRequest.current
143
+ if (change && sameSelection(change.values, selection.value)) {
144
+ draftRequest.current = null
145
+ setDraft(change.remainder)
146
+ setError(change.error)
147
+ }
148
+ }, [selection.value])
149
+ const bridgeRef = useArrayFormBridge({
150
+ values: selection.value,
151
+ controlled: selection.controlled,
152
+ pending,
153
+ form,
154
+ validity:
155
+ feedback ||
156
+ (control.required && !selection.value.length ? 'Please enter at least one tag.' : ''),
157
+ reset() {
158
+ selection.reset()
159
+ draftRequest.current = null
160
+ setDraft('')
161
+ setError('')
162
+ }
163
+ })
164
+ const edit = (text: string) => {
165
+ draftRequest.current = null
166
+ setDraft(text)
167
+ setError('')
168
+ if (!composing.current) add(text, false)
169
+ }
170
+ return (
171
+ <div
172
+ data-slot="tags-input-control"
173
+ className={cn(
174
+ 'flex min-w-0 flex-wrap items-center gap-[var(--rad-tags-input-gap,0.5rem)]',
175
+ parts?.wrapper?.className
176
+ )}
177
+ style={parts?.wrapper?.style}
178
+ >
179
+ {selection.value.map(value => (
180
+ <Tag
181
+ key={value}
182
+ removeLabel={`Remove ${value}`}
183
+ disabled={!!(control.disabled || readOnly)}
184
+ className={parts?.tag?.className}
185
+ style={parts?.tag?.style}
186
+ parts={{ remove: parts?.remove }}
187
+ onRemove={() => remove(value)}
188
+ >
189
+ {value}
190
+ </Tag>
191
+ ))}
192
+ <InputRoot
193
+ {...props}
194
+ {...control}
195
+ family="tags-input"
196
+ nativeRequired={false}
197
+ type="text"
198
+ name={undefined}
199
+ form={form}
200
+ ref={composed}
201
+ readOnly={readOnly}
202
+ value={draft}
203
+ autoComplete={props.autoComplete ?? 'off'}
204
+ aria-invalid={feedback ? true : control['aria-invalid']}
205
+ aria-describedby={joinIds(control['aria-describedby'], message)}
206
+ className={cn('w-auto min-w-[8ch] flex-1', className)}
207
+ onChange={event => {
208
+ onChange?.(event)
209
+ edit(event.currentTarget.value)
210
+ }}
211
+ onCompositionStart={event => {
212
+ onCompositionStart?.(event)
213
+ composing.current = true
214
+ }}
215
+ onCompositionEnd={event => {
216
+ onCompositionEnd?.(event)
217
+ composing.current = false
218
+ edit(event.currentTarget.value)
219
+ }}
220
+ onPaste={event => {
221
+ onPaste?.(event)
222
+ if (event.defaultPrevented || unavailable() || composing.current) return
223
+ const text = event.clipboardData.getData('text')
224
+ if (![...text].some(character => delimiters.includes(character))) return
225
+ event.preventDefault()
226
+ const node = event.currentTarget
227
+ const next =
228
+ draft.slice(0, node.selectionStart ?? draft.length) +
229
+ text +
230
+ draft.slice(node.selectionEnd ?? draft.length)
231
+ draftRequest.current = null
232
+ setDraft(next)
233
+ setError('')
234
+ add(next, true)
235
+ }}
236
+ onKeyDown={event => {
237
+ onKeyDown?.(event)
238
+ if (
239
+ event.defaultPrevented ||
240
+ unavailable() ||
241
+ composing.current ||
242
+ event.nativeEvent.isComposing ||
243
+ event.keyCode === 229 ||
244
+ event.ctrlKey ||
245
+ event.metaKey ||
246
+ event.altKey
247
+ )
248
+ return
249
+ if (event.key === 'Enter' && draft.trim()) {
250
+ event.preventDefault()
251
+ add(draft, true)
252
+ } else if (event.key === 'Backspace' && !draft && selection.value.length) {
253
+ event.preventDefault()
254
+ remove(selection.value.at(-1)!)
255
+ }
256
+ }}
257
+ />
258
+ <span
259
+ id={message}
260
+ data-slot="tags-input-message"
261
+ aria-live="polite"
262
+ aria-atomic="true"
263
+ className={cn(
264
+ 'w-full empty:hidden text-[length:var(--rad-typography-roles-ui-supporting-size,0.8125rem)] [color:var(--rad-color-invalid,oklch(0.56_0.19_25))]',
265
+ parts?.message?.className
266
+ )}
267
+ style={parts?.message?.style}
268
+ >
269
+ {feedback}
270
+ </span>
271
+ <input
272
+ ref={bridgeRef}
273
+ type="text"
274
+ className="sr-only"
275
+ data-slot="tags-input-native"
276
+ form={form}
277
+ disabled={control.disabled}
278
+ readOnly={readOnly}
279
+ aria-hidden="true"
280
+ tabIndex={-1}
281
+ autoComplete="off"
282
+ defaultValue={JSON.stringify(selection.value)}
283
+ onFocus={() => input.current?.focus()}
284
+ onInvalid={event => {
285
+ event.preventDefault()
286
+ input.current?.focus()
287
+ }}
288
+ />
289
+ {selection.value.map(value => (
290
+ <input
291
+ key={value}
292
+ data-slot="tags-input-value"
293
+ type="hidden"
294
+ name={name}
295
+ form={form}
296
+ disabled={control.disabled}
297
+ value={value}
298
+ />
299
+ ))}
300
+ </div>
301
+ )
302
+ }
package/src/cn.ts CHANGED
@@ -88,8 +88,11 @@ export const cn: CnFunction = createCn({
88
88
  'size-(--rad-slider-thumb-size)',
89
89
  'size-(--rad-slider-track-size)'
90
90
  ],
91
- mb: ['mb-(--rad-fieldset-gap)'],
91
+ mb: ['mb-(--rad-multi-select-gap)', 'mb-(--rad-fieldset-gap)'],
92
92
  gap: [
93
+ 'gap-(--rad-tag-gap)',
94
+ 'gap-(--rad-multi-select-gap)',
95
+ 'gap-(--rad-tags-input-gap)',
93
96
  'gap-(--rad-menubar-gap)',
94
97
  'gap-(--rad-toolbar-gap)',
95
98
  'gap-(--rad-toggle-group-gap)',
package/src/index.ts CHANGED
@@ -530,3 +530,36 @@ export type {
530
530
  DrawerSide,
531
531
  DrawerState
532
532
  } from './Drawer.js'
533
+
534
+ export { Tag } from './Tag.js'
535
+ export type { TagProps } from './Tag.js'
536
+ export { TagsInput } from './TagsInput.js'
537
+ export type { TagsInputProps } from './TagsInput.js'
538
+ export { ComboboxTags } from './Combobox.js'
539
+ export type { ComboboxMultipleProps, ComboboxMultipleState, ComboboxTagsProps } from './Combobox.js'
540
+ export {
541
+ MultiSelect,
542
+ MultiSelectInput,
543
+ MultiSelectTrigger,
544
+ MultiSelectClear,
545
+ MultiSelectPortal,
546
+ MultiSelectContent,
547
+ MultiSelectItem,
548
+ MultiSelectStatus,
549
+ MultiSelectTags,
550
+ useMultiSelect
551
+ } from './MultiSelect.js'
552
+ export type {
553
+ MultiSelectProps,
554
+ MultiSelectState,
555
+ MultiSelectOption,
556
+ MultiSelectInputProps,
557
+ MultiSelectTriggerProps,
558
+ MultiSelectClearProps,
559
+ MultiSelectPortalProps,
560
+ MultiSelectContentProps,
561
+ MultiSelectItemProps,
562
+ MultiSelectStatusProps,
563
+ MultiSelectTagsProps,
564
+ MultiSelectRenderProps
565
+ } from './MultiSelect.js'
@@ -0,0 +1,31 @@
1
+ export function validateTags(values: readonly string[]) {
2
+ if (
3
+ !Array.isArray(values) ||
4
+ values.some(value => typeof value !== 'string') ||
5
+ new Set(values).size !== values.length
6
+ )
7
+ throw new TypeError('Tag values must be an array of distinct strings.')
8
+ }
9
+ export function tagSeparators(separators: readonly string[]) {
10
+ if (
11
+ !Array.isArray(separators) ||
12
+ separators.some(value => typeof value !== 'string' || value.length !== 1)
13
+ )
14
+ throw new TypeError('TagsInput separators must be single characters.')
15
+ return [...new Set([...separators, '\n', '\r'])]
16
+ }
17
+ export function splitTags(text: string, separators: readonly string[], final: boolean) {
18
+ const segments: string[] = []
19
+ let current = ''
20
+ for (const character of text) {
21
+ if (separators.includes(character)) {
22
+ segments.push(current)
23
+ current = ''
24
+ } else current += character
25
+ }
26
+ if (final) {
27
+ segments.push(current)
28
+ current = ''
29
+ }
30
+ return { segments, remainder: current }
31
+ }
@@ -0,0 +1,60 @@
1
+ 'use client'
2
+
3
+ import { useEffect, useLayoutEffect, useRef, type RefObject } from 'react'
4
+ import { sameSelection } from '../internal/selection.js'
5
+
6
+ type Options = {
7
+ values: string[]
8
+ controlled: boolean
9
+ pending: RefObject<string[] | null>
10
+ validity: string
11
+ form?: string
12
+ reset(): void
13
+ }
14
+ /** A nameless JSON carrier emits array changes; named hidden controls submit each original string. */
15
+ export function useArrayFormBridge({ pending: pendingRef, ...options }: Options) {
16
+ const ref = useRef<HTMLInputElement>(null),
17
+ latest = useRef(options)
18
+ useLayoutEffect(() => {
19
+ latest.current = options
20
+ const node = ref.current
21
+ if (!node) return
22
+ const value = JSON.stringify(options.values)
23
+ const user = pendingRef.current !== null && sameSelection(pendingRef.current, options.values)
24
+ if (user) {
25
+ Object.getOwnPropertyDescriptor(
26
+ node.ownerDocument.defaultView!.HTMLInputElement.prototype,
27
+ 'value'
28
+ )!.set!.call(node, value)
29
+ } else node.value = value
30
+ if (options.controlled) node.defaultValue = value
31
+ node.setCustomValidity(options.validity)
32
+ if (user) {
33
+ pendingRef.current = null
34
+ const EventType = node.ownerDocument.defaultView!.Event
35
+ node.dispatchEvent(new EventType('input', { bubbles: true }))
36
+ node.dispatchEvent(new EventType('change', { bubbles: true }))
37
+ }
38
+ })
39
+ useEffect(() => {
40
+ const node = ref.current,
41
+ owner = node?.form
42
+ if (!node || !owner) return
43
+ const view = node.ownerDocument.defaultView!
44
+ let timer: number | undefined
45
+ const reset = (event: Event) => {
46
+ view.clearTimeout(timer)
47
+ timer = view.setTimeout(() => {
48
+ if (event.defaultPrevented || !node.isConnected) return
49
+ pendingRef.current = null
50
+ latest.current.reset()
51
+ }, 0)
52
+ }
53
+ owner.addEventListener('reset', reset)
54
+ return () => {
55
+ owner.removeEventListener('reset', reset)
56
+ view.clearTimeout(timer)
57
+ }
58
+ }, [options.form, pendingRef])
59
+ return ref
60
+ }
@@ -13,6 +13,7 @@ export function useComboboxPopup(
13
13
  collisionPadding: number
14
14
  ) {
15
15
  const latest = useRef(dismiss)
16
+ const reposition = useRef<() => void>(() => {})
16
17
  useLayoutEffect(() => {
17
18
  latest.current = dismiss
18
19
  })
@@ -42,8 +43,8 @@ export function useComboboxPopup(
42
43
  const css = win.getComputedStyle(node)
43
44
  const anchor = input.getBoundingClientRect()
44
45
  const padding = Math.max(0, collisionPadding)
45
- const list = node.querySelector<HTMLElement>('[data-slot="combobox-listbox"]')
46
- const status = node.querySelector<HTMLElement>('[data-slot="combobox-status"]')
46
+ const list = node.querySelector<HTMLElement>('[data-slot~="combobox-listbox"]')
47
+ const status = node.querySelector<HTMLElement>('[data-slot~="combobox-status"]')
47
48
  const naturalHeight =
48
49
  (list?.scrollHeight ?? node.scrollHeight) +
49
50
  (status?.offsetHeight ?? 0) +
@@ -85,6 +86,7 @@ export function useComboboxPopup(
85
86
  node.style.setProperty(property, `${value}px`)
86
87
  }
87
88
  }
89
+ reposition.current = place
88
90
  place()
89
91
  let frame = 0
90
92
  const schedule = () => {
@@ -115,6 +117,7 @@ export function useComboboxPopup(
115
117
  win.visualViewport?.addEventListener('resize', schedule)
116
118
  win.visualViewport?.addEventListener('scroll', schedule)
117
119
  return () => {
120
+ reposition.current = () => {}
118
121
  observer.disconnect()
119
122
  mutations.disconnect()
120
123
  win.cancelAnimationFrame(frame)
@@ -127,4 +130,8 @@ export function useComboboxPopup(
127
130
  if (node.matches(':popover-open')) node.hidePopover()
128
131
  }
129
132
  }, [nodeRef, input, open, sideOffset, collisionPadding])
133
+ // Selected tags can move an unchanged-size input without a resize event.
134
+ useLayoutEffect(() => {
135
+ reposition.current()
136
+ })
130
137
  }
@@ -2,6 +2,9 @@ import { kebabCase } from './tokens.js'
2
2
 
3
3
  /** Explicit component slots; omitted slots reset to CSS fallback semantics. */
4
4
  export const componentRegistry = {
5
+ tag: { gap: 'css' },
6
+ multiSelect: { gap: 'css' },
7
+ tagsInput: { gap: 'css' },
5
8
  drawer: { size: 'css' },
6
9
  menubar: { gap: 'css', padding: 'css', radius: 'css', background: 'css' },
7
10
  contextMenu: { width: 'css' },