@prunellejs/ui 0.1.1 → 0.7.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 (79) hide show
  1. package/LICENSE +21 -0
  2. package/llms.txt +19 -11
  3. package/package.json +2 -2
  4. package/src/CommandPalette.tsx +130 -75
  5. package/src/DataTable.tsx +131 -58
  6. package/src/Dialog.tsx +30 -14
  7. package/src/Menu.tsx +10 -8
  8. package/src/Select.tsx +19 -8
  9. package/src/Tabs.tsx +2 -1
  10. package/src/Toaster.tsx +79 -5
  11. package/src/behaviors.ts +104 -6
  12. package/src/fold.ts +7 -0
  13. package/src/index.ts +1 -1
  14. package/src/labels/dialog.ts +3 -0
  15. package/src/labels/fr/dialog.ts +3 -0
  16. package/src/labels/fr/palette.ts +8 -0
  17. package/src/labels/fr/select.ts +1 -0
  18. package/src/labels/fr/table.ts +13 -0
  19. package/src/labels/fr/toaster.ts +1 -0
  20. package/src/labels/palette.ts +8 -0
  21. package/src/labels/select.ts +1 -0
  22. package/src/labels/table.ts +13 -0
  23. package/src/labels/toaster.ts +1 -0
  24. package/src/plugin.ts +114 -31
  25. package/src/primitives.tsx +3 -2
  26. package/src/static.tsx +11 -6
  27. package/src/styles/bare.css +22 -312
  28. package/src/styles/base.css +61 -0
  29. package/src/styles/components/accordion.css +10 -0
  30. package/src/styles/components/badge.css +6 -0
  31. package/src/styles/components/button.css +11 -0
  32. package/src/styles/components/card.css +5 -0
  33. package/src/styles/components/checkbox.css +11 -0
  34. package/src/styles/components/command.css +25 -0
  35. package/src/styles/components/consent.css +38 -0
  36. package/src/styles/components/datatable.css +9 -0
  37. package/src/styles/components/dialog.css +16 -0
  38. package/src/styles/components/drawer.css +29 -0
  39. package/src/styles/components/field.css +8 -0
  40. package/src/styles/components/layout.css +69 -0
  41. package/src/styles/components/menu.css +21 -0
  42. package/src/styles/components/notice.css +5 -0
  43. package/src/styles/components/popover.css +8 -0
  44. package/src/styles/components/progress.css +14 -0
  45. package/src/styles/components/radio-group.css +11 -0
  46. package/src/styles/components/select.css +25 -0
  47. package/src/styles/components/switch.css +42 -0
  48. package/src/styles/components/tabs.css +4 -0
  49. package/src/styles/components/toast.css +28 -0
  50. package/src/styles/grammars/console.css +114 -256
  51. package/src/styles/grammars/editorial.css +101 -271
  52. package/src/styles/grammars/orbit.css +121 -390
  53. package/src/styles/grammars/prunelle.css +157 -360
  54. package/src/styles/grammars/soft.css +106 -240
  55. package/src/styles/grammars/workshop.css +110 -251
  56. package/src/styles/scan.ts +144 -0
  57. package/src/styles/split.ts +429 -0
  58. package/src/styles/theme.css +22 -0
  59. package/src/styles/themed/accordion.css +20 -0
  60. package/src/styles/themed/badge.css +20 -0
  61. package/src/styles/themed/button.css +24 -0
  62. package/src/styles/themed/card.css +23 -0
  63. package/src/styles/themed/checkbox.css +4 -0
  64. package/src/styles/themed/command.css +33 -0
  65. package/src/styles/themed/consent.css +33 -0
  66. package/src/styles/themed/datatable.css +28 -0
  67. package/src/styles/themed/dialog.css +13 -0
  68. package/src/styles/themed/drawer.css +13 -0
  69. package/src/styles/themed/field.css +22 -0
  70. package/src/styles/themed/menu.css +21 -0
  71. package/src/styles/themed/notice.css +17 -0
  72. package/src/styles/themed/popover.css +11 -0
  73. package/src/styles/themed/radio-group.css +12 -0
  74. package/src/styles/themed/select.css +32 -0
  75. package/src/styles/themed/switch.css +23 -0
  76. package/src/styles/themed/tabs.css +20 -0
  77. package/src/styles/themed/toast.css +18 -0
  78. package/src/table-state.ts +53 -16
  79. package/src/toast.ts +50 -8
package/src/Dialog.tsx CHANGED
@@ -6,6 +6,7 @@ import type { PrunelleChild, Signal } from 'prunelle'
6
6
  import type { ButtonVariant } from './static'
7
7
  import { effect } from 'prunelle'
8
8
  import { nextUiId, syncDialogOpen } from './behaviors'
9
+ import * as DIALOG_LABELS from './labels/dialog'
9
10
 
10
11
  export interface DialogProps {
11
12
  id?: string | undefined
@@ -55,11 +56,24 @@ function dialogAttrs(props: Shared, kind: Kind, ids: DialogIds) {
55
56
  'data-side': kind === 'drawer' ? (props.side ?? 'right') : undefined,
56
57
  'data-part': 'content',
57
58
  'aria-labelledby': props.title ? ids.titleId : undefined,
58
- 'aria-label': !props.title ? (props.ariaLabel ?? (kind === 'drawer' ? 'Drawer' : 'Dialog')) : undefined,
59
+ 'aria-label': !props.title ? (props.ariaLabel ?? (kind === 'drawer' ? DIALOG_LABELS.drawer : DIALOG_LABELS.dialog)) : undefined,
59
60
  'aria-describedby': props.description ? ids.descId : undefined,
60
61
  }
61
62
  }
62
63
 
64
+ function closeButtonAttrs(dialog: Shared, ids: DialogIds) {
65
+ return {
66
+ 'data-ui': 'button',
67
+ 'data-variant': 'ghost',
68
+ 'data-size': 'sm',
69
+ 'data-part': 'close',
70
+ 'type': 'button' as const,
71
+ 'commandfor': ids.baseId,
72
+ 'command': 'close' as const,
73
+ 'aria-label': dialog.closeLabel ?? DIALOG_LABELS.close,
74
+ }
75
+ }
76
+
63
77
  // Takes `props` without spreading so lazy `get children()` getters evaluate strictly inside `<div data-part="body">`.
64
78
  function DialogPanel(props: { dialog: Shared, ids: DialogIds }) {
65
79
  const { dialog, ids } = props
@@ -67,18 +81,20 @@ function DialogPanel(props: { dialog: Shared, ids: DialogIds }) {
67
81
  <div data-part="panel">
68
82
  <header data-part="header" data-layout="split">
69
83
  {dialog.title && <h2 id={ids.titleId} data-part="title">{dialog.title}</h2>}
70
- <button
71
- data-ui="button"
72
- data-variant="ghost"
73
- data-size="sm"
74
- data-part="close"
75
- type="button"
76
- commandfor={ids.baseId}
77
- command="close"
78
- aria-label={dialog.closeLabel ?? 'Close'}
79
- >
80
- ✕
81
- </button>
84
+ <button {...closeButtonAttrs(dialog, ids)}>✕</button>
85
+ </header>
86
+ {dialog.description && <p id={ids.descId} data-part="description">{dialog.description}</p>}
87
+ <div data-part="body">{dialog.children}</div>
88
+ </div>
89
+ )
90
+ }
91
+
92
+ function ControlledDialogPanel({ dialog, ids, onClose }: { dialog: Shared, ids: DialogIds, onClose: () => void }) {
93
+ return (
94
+ <div data-part="panel">
95
+ <header data-part="header" data-layout="split">
96
+ {dialog.title && <h2 id={ids.titleId} data-part="title">{dialog.title}</h2>}
97
+ <button {...closeButtonAttrs(dialog, ids)} onClick={onClose}>✕</button>
82
98
  </header>
83
99
  {dialog.description && <p id={ids.descId} data-part="description">{dialog.description}</p>}
84
100
  <div data-part="body">{dialog.children}</div>
@@ -142,7 +158,7 @@ function renderControlledDialog(props: ControlledDrawerProps, kind: Kind) {
142
158
  }}
143
159
  onClose={() => { isOpen.value = false }}
144
160
  >
145
- <DialogPanel dialog={props} ids={ids} />
161
+ <ControlledDialogPanel dialog={props} ids={ids} onClose={() => { isOpen.value = false }} />
146
162
  </dialog>
147
163
  </div>
148
164
  )
package/src/Menu.tsx CHANGED
@@ -2,7 +2,7 @@
2
2
  // Accessible dropdown Menu primitive with roving menuitem focus, link items, ArrowDown/Up trigger open, Escape/Tab close & click-outside dismiss.
3
3
 
4
4
  import type { ButtonVariant } from './static'
5
- import { createListPopup, nextUiId } from './behaviors'
5
+ import { createListPopup, navigateSafeHref, nextUiId, safeHref } from './behaviors'
6
6
 
7
7
  export interface MenuItemDef {
8
8
  id: string
@@ -33,9 +33,10 @@ export function Menu(props: MenuProps) {
33
33
  return
34
34
  item.onSelect?.()
35
35
  props.onSelect?.(item.id)
36
- popup.close(item.href === undefined)
37
- if (navigateHref && item.href !== undefined && typeof location !== 'undefined')
38
- location.assign(item.href)
36
+ const href = safeHref(item.href)
37
+ popup.close(href === undefined)
38
+ if (navigateHref && href !== undefined)
39
+ navigateSafeHref(href)
39
40
  }
40
41
 
41
42
  const popup = createListPopup<MenuItemDef>({
@@ -75,8 +76,9 @@ export function Menu(props: MenuProps) {
75
76
  popover="auto"
76
77
  ref={popup.mountPopup}
77
78
  >
78
- {props.items.map((item, idx) => (
79
- item.href !== undefined && !item.disabled
79
+ {props.items.map((item, idx) => {
80
+ const href = safeHref(item.href)
81
+ return href !== undefined && !item.disabled
80
82
  ? (
81
83
  <a
82
84
  key={item.id}
@@ -84,7 +86,7 @@ export function Menu(props: MenuProps) {
84
86
  data-part="item"
85
87
  data-highlighted={popup.highlighted.value === idx ? 'true' : undefined}
86
88
  role="menuitem"
87
- href={item.href}
89
+ href={href}
88
90
  tabindex={-1}
89
91
  onClick={() => activate(item, false)}
90
92
  >
@@ -107,7 +109,7 @@ export function Menu(props: MenuProps) {
107
109
  {item.label}
108
110
  </button>
109
111
  )
110
- ))}
112
+ })}
111
113
  </div>
112
114
  )}
113
115
  </div>
package/src/Select.tsx CHANGED
@@ -2,8 +2,9 @@
2
2
  // Accessible custom Select (listbox) primitive with aria-activedescendant navigation + hidden input for native <form> submission.
3
3
 
4
4
  import type { Signal } from 'prunelle'
5
- import { signal } from 'prunelle'
5
+ import { onMount, signal } from 'prunelle'
6
6
  import { createListPopup, nextUiId, useFieldContext } from './behaviors'
7
+ import * as SELECT_LABELS from './labels/select'
7
8
 
8
9
  export interface SelectOption {
9
10
  value: string
@@ -25,14 +26,14 @@ export interface SelectProps {
25
26
  export function Select(props: SelectProps) {
26
27
  const field = useFieldContext()
27
28
  const baseId = props.id ?? field?.id ?? nextUiId('kui-select')
28
- let triggerId = props.id ?? field?.id ?? `${baseId}-trigger`
29
+ const triggerId = signal(props.id ?? field?.id ?? `${baseId}-trigger`)
29
30
  const listboxId = `${baseId}-listbox`
30
31
  const optionId = (idx: number) => `${baseId}-opt-${idx}`
31
32
  const name = props.name
32
- const placeholder = props.placeholder ?? 'Select…'
33
+ const placeholder = props.placeholder ?? SELECT_LABELS.placeholder
33
34
  const ariaLabel = props.ariaLabel
34
35
 
35
- const selected = props.value ?? signal(props.defaultValue ?? props.options[0]?.value ?? '')
36
+ const selected = props.value ?? signal(props.defaultValue ?? '')
36
37
  const currentLabel = () => props.options.find(o => o.value === selected.value)?.label ?? placeholder
37
38
 
38
39
  const pick = (opt: SelectOption) => {
@@ -51,19 +52,29 @@ export function Select(props: SelectProps) {
51
52
  initialIndex: () => props.options.findIndex(o => o.value === selected.value && !o.disabled),
52
53
  })
53
54
 
55
+ let rootEl: HTMLElement | undefined
56
+ const syncFieldLabel = (el: HTMLElement | undefined) => {
57
+ if (!el || props.id || field)
58
+ return
59
+ const labelFor = el.closest('[data-ui="field"]')?.querySelector('label')?.htmlFor
60
+ if (labelFor)
61
+ triggerId.value = labelFor
62
+ }
63
+ onMount(() => { syncFieldLabel(rootEl) })
64
+
54
65
  return (
55
66
  <div
56
67
  data-ui="select"
57
68
  data-state={popup.open.value ? 'open' : 'closed'}
58
69
  ref={(el) => {
70
+ rootEl = el
59
71
  popup.setRoot(el)
60
- if (!props.id && !field)
61
- triggerId = el.closest('[data-ui="field"]')?.querySelector('label')?.htmlFor || triggerId
72
+ syncFieldLabel(el)
62
73
  }}
63
74
  >
64
75
  {name && <input type="hidden" name={name} value={selected.value} />}
65
76
  <button
66
- id={triggerId}
77
+ id={triggerId.value}
67
78
  data-part="trigger"
68
79
  type="button"
69
80
  role="combobox"
@@ -84,7 +95,7 @@ export function Select(props: SelectProps) {
84
95
  data-part="listbox"
85
96
  role="listbox"
86
97
  aria-label={ariaLabel}
87
- aria-labelledby={ariaLabel ? undefined : triggerId}
98
+ aria-labelledby={ariaLabel ? undefined : triggerId.value}
88
99
  popover="auto"
89
100
  ref={popup.mountPopup}
90
101
  >
package/src/Tabs.tsx CHANGED
@@ -19,7 +19,7 @@ export interface TabsProps {
19
19
  class?: string | undefined
20
20
  }
21
21
 
22
- export function Tabs({ id, items, defaultValue, label = 'Tabs', class: cls }: TabsProps) {
22
+ export function Tabs({ id, items, defaultValue, label, class: cls }: TabsProps) {
23
23
  const baseId = id ?? nextUiId('kui-tabs')
24
24
  const ids = items.map(i => i.id)
25
25
  const tabs = createTabs(defaultValue ?? items[0]?.id ?? '')
@@ -53,6 +53,7 @@ export function Tabs({ id, items, defaultValue, label = 'Tabs', class: cls }: Ta
53
53
  data-state={tabs.isActive(item.id) ? 'active' : 'inactive'}
54
54
  role="tabpanel"
55
55
  aria-labelledby={`${baseId}-tab-${item.id}`}
56
+ tabIndex={0}
56
57
  hidden={!tabs.isActive(item.id)}
57
58
  >
58
59
  {item.content}
package/src/Toaster.tsx CHANGED
@@ -1,17 +1,91 @@
1
1
  /** @jsxImportSource prunelle */
2
2
  // Live-region Toast stack driven by the reactive `toast` store.
3
3
 
4
- import { toast } from './toast'
4
+ import { effect } from 'prunelle'
5
+ import { dismiss } from './labels/toaster'
6
+ import { pauseToasts, resumeToasts, toast } from './toast'
5
7
 
6
8
  export interface ToasterProps {
7
9
  dismissLabel?: string | undefined
8
10
  }
9
11
 
10
- export function Toaster({ dismissLabel = 'Dismiss' }: ToasterProps = {}) {
12
+ export function Toaster({ dismissLabel = dismiss }: ToasterProps = {}) {
13
+ let hovered = false
14
+ let focused = false
15
+ // Where focus was before it entered the toaster, given back when the last toast closes.
16
+ let returnTo: HTMLElement | null = null
17
+
18
+ const resume = () => {
19
+ if (!hovered && !focused)
20
+ resumeToasts()
21
+ }
22
+
23
+ // A toast pushed while the stack is hovered or focused waits too.
24
+ effect(() => {
25
+ if (toast.items.value.length > 0 && (hovered || focused))
26
+ pauseToasts()
27
+ })
28
+
29
+ // Closing the focused toast moves focus to the next one, else the previous one, else back where it came from.
30
+ const close = (item: HTMLElement) => {
31
+ const root = item.closest<HTMLElement>('[data-ui="toaster"]')
32
+ const hadFocus = item.contains(document.activeElement)
33
+ const sibling = (item.nextElementSibling ?? item.previousElementSibling)?.querySelector<HTMLElement>('[data-part="close"]')
34
+ toast.dismiss(item.getAttribute('data-toast-id') ?? '')
35
+ if (!hadFocus)
36
+ return
37
+ const target = sibling ?? returnTo
38
+ if (target?.isConnected)
39
+ target.focus()
40
+ if (root !== null && !root.contains(document.activeElement)) {
41
+ focused = false
42
+ returnTo = null
43
+ resume()
44
+ }
45
+ }
46
+
11
47
  return (
12
- <div data-ui="toaster" aria-live="polite" aria-atomic="false">
48
+ <div
49
+ data-ui="toaster"
50
+ onMouseEnter={() => {
51
+ hovered = true
52
+ pauseToasts()
53
+ }}
54
+ onMouseLeave={() => {
55
+ hovered = false
56
+ resume()
57
+ }}
58
+ onFocusIn={(e) => {
59
+ const from = e.relatedTarget
60
+ if (from instanceof HTMLElement && !e.currentTarget.contains(from))
61
+ returnTo = from
62
+ focused = true
63
+ pauseToasts()
64
+ }}
65
+ onFocusOut={(e) => {
66
+ const next = e.relatedTarget as Node | null
67
+ if (next === null || !e.currentTarget.contains(next)) {
68
+ focused = false
69
+ returnTo = null
70
+ resume()
71
+ }
72
+ }}
73
+ >
13
74
  {toast.items.value.map(item => (
14
- <div key={item.id} data-ui="toast" data-tone={item.tone} role="status">
75
+ <div
76
+ key={item.id}
77
+ data-ui="toast"
78
+ data-toast-id={item.id}
79
+ data-tone={item.tone}
80
+ role={item.tone === 'danger' ? 'alert' : 'status'}
81
+ aria-atomic="true"
82
+ onKeyDown={(e) => {
83
+ if (e.key !== 'Escape' || e.defaultPrevented)
84
+ return
85
+ e.preventDefault()
86
+ close(e.currentTarget)
87
+ }}
88
+ >
15
89
  <div>
16
90
  <strong data-part="title">{item.title}</strong>
17
91
  {item.description && <p data-part="description">{item.description}</p>}
@@ -20,7 +94,7 @@ export function Toaster({ dismissLabel = 'Dismiss' }: ToasterProps = {}) {
20
94
  data-part="close"
21
95
  type="button"
22
96
  aria-label={dismissLabel}
23
- onClick={() => toast.dismiss(item.id)}
97
+ onClick={e => close(e.currentTarget.closest<HTMLElement>('[data-ui="toast"]')!)}
24
98
  >
25
99
  ✕
26
100
  </button>
package/src/behaviors.ts CHANGED
@@ -13,6 +13,49 @@ export { toast } from './toast'
13
13
  export type { ToastItem } from './toast'
14
14
  export { useFieldContext }
15
15
 
16
+ // ---- Safe href validation & SPA-friendly navigation ----
17
+
18
+ const UNSAFE_HREF_RE = /^(?:javascript|vbscript|data):/i
19
+
20
+ /** Returns a safe navigable URL (rejecting `javascript:`, `vbscript:`, and `data:` schemes even with control-char obfuscation), or `undefined`. */
21
+ export function safeHref(href: string | undefined): string | undefined {
22
+ if (href === undefined)
23
+ return undefined
24
+ const trimmed = href.trim()
25
+ if (trimmed.length === 0)
26
+ return undefined
27
+ let cleaned = ''
28
+ for (let i = 0; i < trimmed.length; i++) {
29
+ const code = trimmed.charCodeAt(i)
30
+ if (code > 0x20 && code !== 0x7F)
31
+ cleaned += trimmed[i]
32
+ }
33
+ return UNSAFE_HREF_RE.test(cleaned) ? undefined : trimmed
34
+ }
35
+
36
+ /** Navigates to a safe href with one synthetic anchor click, which `@prunellejs/spa` can intercept and the browser follows otherwise; `location.assign` only when there is no body to hold the anchor. */
37
+ export function navigateSafeHref(href: string | undefined): boolean {
38
+ const safe = safeHref(href)
39
+ if (safe === undefined)
40
+ return false
41
+ if (typeof document !== 'undefined' && document.body !== null) {
42
+ const a = document.createElement('a')
43
+ a.href = safe
44
+ a.hidden = true
45
+ document.body.appendChild(a)
46
+ try {
47
+ a.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, button: 0 }))
48
+ }
49
+ finally {
50
+ a.remove()
51
+ }
52
+ return true
53
+ }
54
+ if (typeof location !== 'undefined')
55
+ location.assign(safe)
56
+ return true
57
+ }
58
+
16
59
  // ---- Stable hydration-safe unique IDs for ARIA wiring ----
17
60
 
18
61
  export function nextUiId(prefix: string): string {
@@ -117,8 +160,14 @@ export interface ListPopupState {
117
160
 
118
161
  // In the top layer no overflow ancestor clips the popup, and the trigger as its `source` is the anchor CSS places it against and a click the browser does not count as outside.
119
162
  function showAnchored(el: HTMLElement, trigger: HTMLElement): void {
120
- if (el.isConnected && !el.matches(':popover-open'))
121
- el.showPopover({ source: trigger })
163
+ if (el.isConnected && !el.matches(':popover-open')) {
164
+ try {
165
+ el.showPopover({ source: trigger })
166
+ }
167
+ catch {
168
+ el.showPopover()
169
+ }
170
+ }
122
171
  }
123
172
 
124
173
  /** Shared popup open/close and keyboard list navigation for Menu and Select; the browser dismisses the popup on an outside click. */
@@ -127,6 +176,20 @@ export function createListPopup<T>(opts: ListPopupOptions<T>): ListPopupState {
127
176
  const highlighted = signal(findFirstEnabledIndex(opts.items(), opts.isDisabled))
128
177
  let rootEl: HTMLElement | undefined
129
178
  let lastOpenEvent: Event | undefined
179
+ // On browsers without `showPopover({ source })`, clicking the trigger light-dismisses the popover before `click` fires; suppress that click so it stays closed.
180
+ let pointerDownOnTrigger = false
181
+ let pointerDown = false
182
+ let suppressNextClick = false
183
+ let clearSuppressTimer: ReturnType<typeof setTimeout> | undefined
184
+
185
+ const scheduleSuppressReset = () => {
186
+ clearTimeout(clearSuppressTimer)
187
+ clearSuppressTimer = setTimeout(() => {
188
+ clearSuppressTimer = undefined
189
+ pointerDownOnTrigger = false
190
+ suppressNextClick = false
191
+ }, 50)
192
+ }
130
193
 
131
194
  const activeDescendantId = (): string | undefined => {
132
195
  const idx = highlighted.value
@@ -163,6 +226,22 @@ export function createListPopup<T>(opts: ListPopupOptions<T>): ListPopupState {
163
226
  effect(() => {
164
227
  if (!open.value)
165
228
  return
229
+ const onPointerDown = (e: Event) => {
230
+ const trigger = rootEl?.querySelector('[data-part="trigger"]')
231
+ pointerDownOnTrigger = trigger !== null && trigger !== undefined && trigger.contains(e.target as Node)
232
+ if (!pointerDownOnTrigger)
233
+ return
234
+ pointerDown = true
235
+ suppressNextClick = false
236
+ const onUp = () => {
237
+ pointerDown = false
238
+ document.removeEventListener('pointerup', onUp, true)
239
+ document.removeEventListener('pointercancel', onUp, true)
240
+ scheduleSuppressReset()
241
+ }
242
+ document.addEventListener('pointerup', onUp, true)
243
+ document.addEventListener('pointercancel', onUp, true)
244
+ }
166
245
  const onKey = (e: KeyboardEvent) => {
167
246
  if (e === lastOpenEvent)
168
247
  return
@@ -178,8 +257,12 @@ export function createListPopup<T>(opts: ListPopupOptions<T>): ListPopupState {
178
257
  if (open.peek() && highlighted.peek() !== prev)
179
258
  focusActive()
180
259
  }
260
+ document.addEventListener('pointerdown', onPointerDown, true)
181
261
  document.addEventListener('keydown', onKey)
182
- onCleanup(() => document.removeEventListener('keydown', onKey))
262
+ onCleanup(() => {
263
+ document.removeEventListener('pointerdown', onPointerDown, true)
264
+ document.removeEventListener('keydown', onKey)
265
+ })
183
266
  })
184
267
 
185
268
  return {
@@ -189,10 +272,16 @@ export function createListPopup<T>(opts: ListPopupOptions<T>): ListPopupState {
189
272
  close,
190
273
  toggle(e) {
191
274
  e.stopPropagation()
192
- if (open.value)
275
+ if (open.value) {
193
276
  close()
194
- else
277
+ }
278
+ else if (suppressNextClick) {
279
+ suppressNextClick = false
280
+ pointerDownOnTrigger = false
281
+ }
282
+ else {
195
283
  openWith(false)
284
+ }
196
285
  },
197
286
  onTriggerKeyDown(e) {
198
287
  if (!open.value && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) {
@@ -207,7 +296,16 @@ export function createListPopup<T>(opts: ListPopupOptions<T>): ListPopupState {
207
296
  mountPopup(el) {
208
297
  if (el === undefined)
209
298
  return
210
- el.addEventListener('toggle', e => (e as ToggleEvent).newState === 'closed' && close())
299
+ el.addEventListener('toggle', (e) => {
300
+ if ((e as ToggleEvent).newState !== 'closed')
301
+ return
302
+ if (open.peek() && pointerDownOnTrigger) {
303
+ suppressNextClick = true
304
+ if (!pointerDown)
305
+ scheduleSuppressReset()
306
+ }
307
+ close()
308
+ })
211
309
  queueMicrotask(() => {
212
310
  showAnchored(el, rootEl!.querySelector<HTMLElement>('[data-part="trigger"]')!)
213
311
  focusActive()
package/src/fold.ts ADDED
@@ -0,0 +1,7 @@
1
+ // Case and diacritic folding shared by the DataTable search and the CommandPalette filter, so "emile" finds "Émile".
2
+
3
+ const MARKS_RE = /\p{M}/gu
4
+
5
+ export function foldText(text: string): string {
6
+ return text.normalize('NFD').replace(MARKS_RE, '').toLowerCase()
7
+ }
package/src/index.ts CHANGED
@@ -17,7 +17,7 @@ export type { DataTableOptions, DataTableState, DialogBehavior, ListNavigationOp
17
17
  export { toast } from './toast'
18
18
  export type { ToastItem } from './toast'
19
19
  export { CommandPalette } from './CommandPalette'
20
- export type { CommandItem, CommandPaletteProps } from './CommandPalette'
20
+ export type { CommandItem, CommandPaletteProps, CommandSource } from './CommandPalette'
21
21
  export { DataTable } from './DataTable'
22
22
  export type { DataTableColumn, DataTableProps } from './DataTable'
23
23
  export { ControlledDialog, Dialog } from './Dialog'
@@ -0,0 +1,3 @@
1
+ export const close = 'Close'
2
+ export const dialog = 'Dialog'
3
+ export const drawer = 'Drawer'
@@ -0,0 +1,3 @@
1
+ export const close = 'Fermer'
2
+ export const dialog = 'Boîte de dialogue'
3
+ export const drawer = 'Panneau'
@@ -0,0 +1,8 @@
1
+ export const placeholder = 'Tapez une commande ou cherchez…'
2
+ export const input = 'Rechercher une commande'
3
+ export const palette = 'Palette de commandes'
4
+ export const trigger = 'Rechercher (⌘K)'
5
+ export const empty = 'Aucune commande ne correspond.'
6
+ export const noResults = 'Aucun résultat'
7
+ export const result = 'résultat'
8
+ export const results = 'résultats'
@@ -0,0 +1 @@
1
+ export const placeholder = 'Choisir…'
@@ -0,0 +1,13 @@
1
+ export const placeholder = 'Filtrer les lignes…'
2
+ export const search = 'Rechercher'
3
+ export const selectColumn = 'Sélection'
4
+ export const selectRow = 'Sélectionner la ligne'
5
+ export const selectAll = 'Sélectionner toutes les lignes'
6
+ export const ascending = 'croissant'
7
+ export const descending = 'décroissant'
8
+ export const rows = 'lignes'
9
+ export const selected = 'sélectionnées'
10
+ export const page = 'Page'
11
+ export const prev = 'Précédente'
12
+ export const next = 'Suivante'
13
+ export const empty = 'Aucune ligne ne correspond.'
@@ -0,0 +1 @@
1
+ export const dismiss = 'Fermer'
@@ -0,0 +1,8 @@
1
+ export const placeholder = 'Type a command or search...'
2
+ export const input = 'Search commands'
3
+ export const palette = 'Command palette'
4
+ export const trigger = 'Search (⌘K)'
5
+ export const empty = 'No matching commands.'
6
+ export const noResults = 'No results'
7
+ export const result = 'result'
8
+ export const results = 'results'
@@ -0,0 +1 @@
1
+ export const placeholder = 'Select…'
@@ -0,0 +1,13 @@
1
+ export const placeholder = 'Filter rows...'
2
+ export const search = 'Search'
3
+ export const selectColumn = 'Select'
4
+ export const selectRow = 'Select row'
5
+ export const selectAll = 'Select all rows'
6
+ export const ascending = 'ascending'
7
+ export const descending = 'descending'
8
+ export const rows = 'rows'
9
+ export const selected = 'selected'
10
+ export const page = 'Page'
11
+ export const prev = 'Prev'
12
+ export const next = 'Next'
13
+ export const empty = 'No matching rows.'
@@ -0,0 +1 @@
1
+ export const dismiss = 'Dismiss'