@prunellejs/ui 0.7.3 → 0.7.6
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.
- package/llms.txt +2 -2
- package/package.json +2 -2
- package/src/CommandPalette.tsx +22 -9
- package/src/styles/components/command.css +14 -2
- package/src/styles/grammars/orbit.css +1 -1
- package/src/styles/grammars/soft.css +1 -1
- package/src/styles/scan.ts +9 -3
- package/src/styles/themed/command.css +1 -0
package/llms.txt
CHANGED
|
@@ -49,8 +49,8 @@ export default defineConfig({
|
|
|
49
49
|
- `Tabs`: `{ id?, items: Array<{ id, label, content }>, defaultValue?, label? }` (the tablist is named only when `label` is given; each panel takes `tabindex="0"` so Tab reaches a panel of plain text).
|
|
50
50
|
- `Menu`: `{ id?, label, items: Array<{ id, label, href?, disabled?, onSelect? }>, variant?, onSelect? }`.
|
|
51
51
|
- `Select`: `{ id?, options: Array<{ value, label, disabled? }>, value?: Signal<string>, defaultValue?, name?, placeholder?, ariaLabel?, onChange? }`. With no `value` or `defaultValue` it shows `placeholder` and submits `""` until the user picks. Outside a `Field` or `<label for>` it needs `ariaLabel`, or `prunelle check` warns `rgaa/form-label`.
|
|
52
|
-
- `CommandPalette`: `{ id?, items?: CommandItem[], source?: CommandSource, shortcutKey? ('k'), open?: Signal<boolean>, onSelect?, ...labels }` (`source` is a lazy search function or `{ search(query) }`, e.g. `createSearchSource()` from `@prunellejs/search/client`, invoked only once opened).
|
|
53
|
-
- `DataTable`: `{ rows, columns: Array<{ key, label, sortable? }>, rowKey? ('id'; every row needs a unique key, or the table throws), locale? (sort order; `<html lang>`), onSelect?(keys) (the selected keys, each time they change), rowLabelKey? (first column: names each row's checkbox), pageSize? (10), searchable? (true), selectable? (false), ...labels }`. With `selectable`, the header checkbox selects or clears every row the filter shows. A sort is announced (`ascendingLabel`, `descendingLabel`), and so is the page.
|
|
52
|
+
- `CommandPalette`: `{ id?, items?: CommandItem[], source?: CommandSource, shortcutKey? ('k'; Ctrl or Cmd, named in `aria-keyshortcuts`, so the palette opens on it even when hydrated on `interaction`), open?: Signal<boolean>, onSelect?, ...labels }` (`source` is a lazy search function or `{ search(query) }`, e.g. `createSearchSource()` from `@prunellejs/search/client`, invoked only once opened).
|
|
53
|
+
- `DataTable`: `{ rows, columns: Array<{ key, label, sortable? }>, rowKey? ('id'; every row needs a unique key, or the table throws), locale? (sort order; `<html lang>`), onSelect?(keys) (the selected keys, each time they change), rowLabelKey? (first column: names each row's checkbox), pageSize? (10), searchable? (true), selectable? (false), ...labels }`. With `selectable`, the header checkbox selects or clears every row the filter shows. A sort is announced (`ascendingLabel`, `descendingLabel`), and so is the page. Sort is numeric and accent-aware (`Intl.Collator`), search and `CommandPalette` ignore case and accents, and the selection drops rows that leave `rows`. `createDataTable()` also has `setSelected(keys, on)` and `onSelect`.
|
|
54
54
|
- `Toaster` + `toast`: mount `<Toaster dismissLabel? />` once in `_layout.tsx`; call `toast.show|info|success|warning|danger|error(title, description?, durationMs?)`, `toast.dismiss(id)`, `toast.clear()`. A `danger`/`error` toast stays until dismissed and the others stay 4.5 to 15 s by text length, unless `durationMs` is given (`0` keeps it). Hovering or focusing the stack pauses every timer, which then resumes with the time it had left; Escape closes the focused toast, and focus moves to the next toast, else back where it was.
|
|
55
55
|
|
|
56
56
|
## Example
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prunellejs/ui",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
4
4
|
"description": "Platform-first headless UI primitives and pure CSS @layer kui Style Grammars for Prunelle",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"directory": "packages/ui"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"prunelle": "^0.7.
|
|
32
|
+
"prunelle": "^0.7.6"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/CommandPalette.tsx
CHANGED
|
@@ -79,7 +79,8 @@ function createSourceLoader(
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
// Returns the shortcut as `aria-keyshortcuts` names it: on the trigger (the dialog without one) for screen readers, and so an `interaction` island hydrates on the shortcut itself.
|
|
83
|
+
function bindPaletteShortcut(shortcutKey: string, isOpen: Signal<boolean>): string {
|
|
83
84
|
onMount(() => {
|
|
84
85
|
const onKeyDown = (e: KeyboardEvent) => {
|
|
85
86
|
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === shortcutKey) {
|
|
@@ -90,6 +91,20 @@ function bindPaletteShortcut(shortcutKey: string, isOpen: Signal<boolean>): void
|
|
|
90
91
|
window.addEventListener('keydown', onKeyDown)
|
|
91
92
|
return () => window.removeEventListener('keydown', onKeyDown)
|
|
92
93
|
})
|
|
94
|
+
const key = shortcutKey.toUpperCase()
|
|
95
|
+
return `Control+${key} Meta+${key}`
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function keepActiveInView(isOpen: Signal<boolean>, activeIdx: Signal<number>, option: (idx: number) => Element | null | undefined): void {
|
|
99
|
+
effect(() => {
|
|
100
|
+
const idx = activeIdx.value
|
|
101
|
+
if (isOpen.value && idx >= 0)
|
|
102
|
+
option(idx)?.scrollIntoView({ block: 'nearest' })
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function countLabel(n: number, none: string, one: string, many: string): string {
|
|
107
|
+
return n === 0 ? none : n === 1 ? `1 ${one}` : `${n} ${many}`
|
|
93
108
|
}
|
|
94
109
|
|
|
95
110
|
function selectCommandItem(item: CommandItem, isOpen: Signal<boolean>, onSelect?: (id: string) => void): void {
|
|
@@ -139,12 +154,7 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
139
154
|
return !isOpen.value || idx < 0 || idx >= list.length || list[idx]?.disabled ? undefined : optionId(idx)
|
|
140
155
|
}
|
|
141
156
|
|
|
142
|
-
const statusText = () =>
|
|
143
|
-
if (!isOpen.value)
|
|
144
|
-
return ''
|
|
145
|
-
const n = filtered.value.length
|
|
146
|
-
return n === 0 ? noResultsLabel : n === 1 ? `1 ${resultLabel}` : `${n} ${resultsLabel}`
|
|
147
|
-
}
|
|
157
|
+
const statusText = () => isOpen.value ? countLabel(filtered.value.length, noResultsLabel, resultLabel, resultsLabel) : ''
|
|
148
158
|
|
|
149
159
|
const onOpened = () => {
|
|
150
160
|
query.value = ''
|
|
@@ -153,8 +163,9 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
153
163
|
queueMicrotask(() => inputEl?.focus())
|
|
154
164
|
}
|
|
155
165
|
|
|
156
|
-
bindPaletteShortcut((props.shortcutKey ?? 'k').toLowerCase(), isOpen)
|
|
166
|
+
const keyShortcuts = bindPaletteShortcut((props.shortcutKey ?? 'k').toLowerCase(), isOpen)
|
|
157
167
|
effect(() => { syncDialogOpen(dialogEl, isOpen, isOpen.value, onOpened) })
|
|
168
|
+
keepActiveInView(isOpen, activeIdx, idx => dialogEl?.ownerDocument.getElementById(optionId(idx)))
|
|
158
169
|
|
|
159
170
|
const runItem = (item: CommandItem) => selectCommandItem(item, isOpen, props.onSelect)
|
|
160
171
|
|
|
@@ -167,6 +178,7 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
167
178
|
data-part="trigger"
|
|
168
179
|
type="button"
|
|
169
180
|
aria-haspopup="dialog"
|
|
181
|
+
aria-keyshortcuts={keyShortcuts}
|
|
170
182
|
aria-expanded={isOpen.value ? 'true' : 'false'}
|
|
171
183
|
onClick={() => { isOpen.value = true }}
|
|
172
184
|
>
|
|
@@ -177,6 +189,7 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
177
189
|
data-ui="command"
|
|
178
190
|
data-part="content"
|
|
179
191
|
aria-label={ariaLabel}
|
|
192
|
+
aria-keyshortcuts={triggerLabel ? undefined : keyShortcuts}
|
|
180
193
|
ref={(el) => {
|
|
181
194
|
dialogEl = el
|
|
182
195
|
syncDialogOpen(dialogEl, isOpen, isOpen.peek(), onOpened)
|
|
@@ -192,7 +205,7 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
192
205
|
<input
|
|
193
206
|
ref={(el) => { inputEl = el }}
|
|
194
207
|
data-part="input"
|
|
195
|
-
type="
|
|
208
|
+
type="text"
|
|
196
209
|
role="combobox"
|
|
197
210
|
aria-label={inputLabel}
|
|
198
211
|
aria-expanded={isOpen.value ? 'true' : 'false'}
|
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
@layer kui {
|
|
2
2
|
html:has(dialog[data-ui]:modal) { overflow: hidden; }
|
|
3
|
+
/* The palette ends 1rem above the viewport's bottom; the input stays put and only the results scroll. */
|
|
3
4
|
dialog[data-ui="command"] {
|
|
4
5
|
padding: 0;
|
|
5
6
|
margin: auto;
|
|
6
7
|
max-inline-size: min(32rem, calc(100vw - 2rem));
|
|
7
|
-
max-block-size: calc(100dvh -
|
|
8
|
-
overflow:
|
|
8
|
+
max-block-size: calc(100dvh - min(14vh, 6rem) - 1rem);
|
|
9
|
+
overflow: hidden;
|
|
9
10
|
inline-size: min(34rem, calc(100vw - 2rem));
|
|
10
11
|
margin-block-start: min(14vh, 6rem);
|
|
11
12
|
}
|
|
13
|
+
dialog[data-ui="command"][open],
|
|
14
|
+
dialog[data-ui="command"] [data-part="panel"] {
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
min-block-size: 0;
|
|
18
|
+
}
|
|
19
|
+
dialog[data-ui="command"] [data-part="list"] {
|
|
20
|
+
min-block-size: 0;
|
|
21
|
+
overflow-y: auto;
|
|
22
|
+
overscroll-behavior: contain;
|
|
23
|
+
}
|
|
12
24
|
dialog[data-ui="command"]::backdrop { background: rgb(0 0 0 / 0.45); }
|
|
13
25
|
dialog[data-ui="command"] [data-part="input"] {
|
|
14
26
|
width: 100%;
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
--ui-btn-sm-pad: 0.36rem 0.65rem;
|
|
119
119
|
--ui-btn-lg-fs: 0.92rem;
|
|
120
120
|
--ui-btn-lg-pad: 0.68rem 1.2rem;
|
|
121
|
-
&:hover:not(:disabled, [aria-disabled="true"]) { background: var(--ui-surface-strong); border-color: color-mix(in srgb, var(--ui-accent) 55%, var(--ui-line-strong)); }
|
|
121
|
+
&:hover:not(:disabled, [aria-disabled="true"], [data-tone]) { background: var(--ui-surface-strong); border-color: color-mix(in srgb, var(--ui-accent) 55%, var(--ui-line-strong)); }
|
|
122
122
|
&[data-variant="ghost"] { color: var(--ui-subtext); &:hover:not(:disabled, [aria-disabled="true"]) { background: var(--ui-surface); color: var(--ui-ink); border-color: var(--ui-line); } }
|
|
123
123
|
&[data-tone="accent"] { font-weight: 600; &:hover:not(:disabled, [aria-disabled="true"]) { filter: brightness(1.06); } }
|
|
124
124
|
&[data-tone="danger"] { background: color-mix(in srgb, var(--ui-danger) 12%, var(--ui-surface)); border-color: color-mix(in srgb, var(--ui-danger) 55%, transparent); color: var(--ui-danger); &:hover:not(:disabled, [aria-disabled="true"]) { background: var(--ui-danger); border-color: var(--ui-danger); color: var(--ui-on-accent); } }
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
--ui-btn-r: var(--ui-pill);
|
|
30
30
|
--ui-btn-bd: 0;
|
|
31
31
|
--ui-btn-bg: var(--ui-surface-2);
|
|
32
|
-
&:hover:not(:disabled, [aria-disabled="true"]) { background: color-mix(in srgb, var(--ui-ink) 12%, var(--ui-surface-2)); }
|
|
32
|
+
&:hover:not(:disabled, [aria-disabled="true"], [data-tone]) { background: color-mix(in srgb, var(--ui-ink) 12%, var(--ui-surface-2)); }
|
|
33
33
|
&:active:not(:disabled, [aria-disabled="true"]) { transform: scale(0.98); }
|
|
34
34
|
&[data-tone="accent"]:hover:not(:disabled, [aria-disabled="true"]), &[data-tone="danger"]:hover:not(:disabled, [aria-disabled="true"]) { filter: brightness(1.06); }
|
|
35
35
|
&[data-variant="outline"] { box-shadow: inset 0 0 0 1.5px var(--ui-line-strong); }
|
package/src/styles/scan.ts
CHANGED
|
@@ -9,7 +9,13 @@ import { UI_COMPONENT_PARTS, UI_EXPORT_TO_PARTS } from './split'
|
|
|
9
9
|
const PART_SET = new Set<string>(UI_COMPONENT_PARTS)
|
|
10
10
|
const UI_SRC_DIR = resolve(import.meta.dir, '..')
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const COMMENT_SRC = '//[^\\n]*|/\\*[\\s\\S]*?\\*/'
|
|
13
|
+
const WS_SRC = `(?:\\s|${COMMENT_SRC})*`
|
|
14
|
+
const NAMED_LIST_SRC = `\\{(?:[^/{}]|${COMMENT_SRC}|/(?![/*]))*\\}`
|
|
15
|
+
const IMPORT_EXPORT_RE = new RegExp(
|
|
16
|
+
`\\b(?:import\\b${WS_SRC}((?!type\\b)[A-Za-z_$][\\w$]*(?:${WS_SRC},${WS_SRC}(?:\\*${WS_SRC}as${WS_SRC}[A-Za-z_$][\\w$]*|${NAMED_LIST_SRC}))?|\\*${WS_SRC}as${WS_SRC}[A-Za-z_$][\\w$]*|${NAMED_LIST_SRC})|export\\b${WS_SRC}(\\*(?:${WS_SRC}as${WS_SRC}[A-Za-z_$][\\w$]*)?|${NAMED_LIST_SRC}))${WS_SRC}\\bfrom${WS_SRC}['"]([^'"]+)['"]`,
|
|
17
|
+
'g',
|
|
18
|
+
)
|
|
13
19
|
const NAMED_LIST_RE = /\{([\s\S]*?)\}/
|
|
14
20
|
const NAMESPACE_RE = /^\s*\*(?:\s+as\s+[A-Za-z_$][\w$]*)?\s*$|,\s*\*\s+as\s+[A-Za-z_$][\w$]*/
|
|
15
21
|
const COMMENT_RE = /\/\/[^\n]*|\/\*[\s\S]*?\*\//g
|
|
@@ -69,7 +75,7 @@ function scanSingleFile(file: string): FileUiScan {
|
|
|
69
75
|
let all = false
|
|
70
76
|
|
|
71
77
|
for (const match of code.matchAll(IMPORT_EXPORT_RE)) {
|
|
72
|
-
const clause = (match[1] ?? match[2])!
|
|
78
|
+
const clause = ((match[1] ?? match[2])!).replace(COMMENT_RE, ' ')
|
|
73
79
|
const source = match[3]!
|
|
74
80
|
const fromPrunelle = source === 'prunelle'
|
|
75
81
|
if (!fromPrunelle && !isUiImportSource(source))
|
|
@@ -80,7 +86,7 @@ function scanSingleFile(file: string): FileUiScan {
|
|
|
80
86
|
}
|
|
81
87
|
const named = NAMED_LIST_RE.exec(clause)
|
|
82
88
|
if (named !== null) {
|
|
83
|
-
for (const rawSpec of named[1]!.
|
|
89
|
+
for (const rawSpec of named[1]!.split(',')) {
|
|
84
90
|
const spec = rawSpec.trim()
|
|
85
91
|
if (spec === '' || /^type\s+/.test(spec))
|
|
86
92
|
continue
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
font: var(--ui-cmd-mf, 500 0.88rem/1.3 var(--ui-font-body));
|
|
28
28
|
&[data-highlighted="true"] { background: var(--ui-cmd-hbg, var(--ui-surface)); color: var(--ui-cmd-hfg, inherit); box-shadow: var(--ui-cmd-hind, inset 2px 0 0 var(--ui-accent)); }
|
|
29
29
|
}
|
|
30
|
+
& [data-part="item-description"] { font-size: 0.74rem; color: var(--ui-muted); }
|
|
30
31
|
& [data-part="kbd"] { font-size: 0.74rem; color: var(--ui-muted); border: 1px solid var(--ui-line); border-radius: var(--ui-radius-inner, 0); padding: 0.1rem 0.35rem; }
|
|
31
32
|
& [data-part="empty"] { padding: 0.9rem 1rem; margin: 0; color: var(--ui-muted); }
|
|
32
33
|
}
|