@cssints/headless 0.15.0 → 0.17.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.
- package/README.md +87 -1
- package/dist/index.d.mts +292 -1
- package/dist/index.mjs +386 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ A primitive that has a seam honours an optional `prefs` entry (a `Partial<Prefs>
|
|
|
65
65
|
- **menu / menubar** — `typeaheadDelayMs` (the typeahead buffer timeout).
|
|
66
66
|
- **tooltip** — `tooltipShowDelayMs` / `tooltipHideDelayMs`, exposed as `showDelayMs()` / `hideDelayMs()` for the host to wire its `setTimeout` from (the spec keeps timers as events).
|
|
67
67
|
|
|
68
|
-
Everything else **ignores** prefs: accordion, alert, alertdialog, breadcrumb, button, carousel, checkbox, checkbox-group, combobox, confirm, dialog-modal, disclosure, feed, field, grid, link, listbox, meter, player, popover, radio, resizable-panels, slider, slider-multithumb, spinbutton, switch, tabs, timeline, toolbar, treegrid, treeview, windowsplitter — they expose no timing / motion / live-region / camera seam. `listbox` / `treeview` / `timeline` typeahead timeouts are host-driven via their reset methods, so they take no delay here either.
|
|
68
|
+
Everything else **ignores** prefs: accordion, alert, alertdialog, breadcrumb, button, carousel, checkbox, checkbox-group, combobox, confirm, dialog-modal, disclosure, feed, field, grid, link, listbox, meter, player, popover, radio, resizable-panels, slider, slider-multithumb, spinbutton, switch, table, tabs, timeline, toolbar, treegrid, treeview, windowsplitter — they expose no timing / motion / live-region / camera seam. `listbox` / `treeview` / `timeline` typeahead timeouts are host-driven via their reset methods, so they take no delay here either.
|
|
69
69
|
|
|
70
70
|
`motionDurationMs` is **not consumed**: canvas tweens are tick-driven, not millisecond-driven, and the look layer owns durations. It stays in `Prefs` only so a host's preference record fits the type.
|
|
71
71
|
|
|
@@ -189,6 +189,70 @@ const pages = createPagination({ page: 3, pageCount: 12, hrefFor: (page) => `/is
|
|
|
189
189
|
- **`hrefFor` is what makes it work without JS**: with it every page is a real link; without it they are buttons and the host owns navigation.
|
|
190
190
|
- **Target size is the skin's job**: 24x24 CSS px at AA, 44x44 at AAA.
|
|
191
191
|
|
|
192
|
+
## Table
|
|
193
|
+
|
|
194
|
+
`createTable` is sortable column headers and row selection on a **native `<table>`**: a `<caption>`, `<thead>`, `<tbody>`, `<th scope="col">` and `<td>` carry the semantics, so the primitive adds no `role` and no `aria-rowindex`, only what the elements cannot say themselves (`aria-sort` on the sorted column, `aria-selected` on a row, the mixed select-all state, and the totals a windowed table hides). It is a grid with a header row but **without the grid's navigation**: the cells keep their own focus, and `createGrid` stays the widget for roving cell focus. There is no spec of its own — it composes the two state models the package already has, `grid-sort.qnt` and `grid-selection.qnt` — so `test/table.browser.test.tsx` is its oracle.
|
|
195
|
+
|
|
196
|
+
```tsx
|
|
197
|
+
const table = createTable({
|
|
198
|
+
columns: [
|
|
199
|
+
{ key: "title", abbr: "Title" },
|
|
200
|
+
{ key: "status", sortable: false },
|
|
201
|
+
{ key: "count", numeric: true },
|
|
202
|
+
],
|
|
203
|
+
rows, // the host's ids, in the host's order: it sorts its data from the descriptor
|
|
204
|
+
selection: "multiple",
|
|
205
|
+
defaultSort: { key: "title", direction: "ascending" },
|
|
206
|
+
labels: { table: "Open issues", selectRow: (id) => `Select ${nameOf(id)}` },
|
|
207
|
+
onSortChange: (sort) => setSort(sort), // the host re-sorts its data and passes `rows` again
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
<table {...table.tableProps}>
|
|
211
|
+
<caption {...table.captionProps}>Open issues</caption>
|
|
212
|
+
<thead>
|
|
213
|
+
<tr>
|
|
214
|
+
{table.selectAllProps && (
|
|
215
|
+
<th>
|
|
216
|
+
<span {...table.selectAllProps} />
|
|
217
|
+
</th>
|
|
218
|
+
)}
|
|
219
|
+
{columns.map((column) => {
|
|
220
|
+
const sortButton = table.headerButtonProps(column.key); // undefined when not sortable
|
|
221
|
+
return (
|
|
222
|
+
<th {...table.headerCellProps(column.key)}>
|
|
223
|
+
{sortButton ? <button {...sortButton}>{column.key}</button> : column.key}
|
|
224
|
+
</th>
|
|
225
|
+
);
|
|
226
|
+
})}
|
|
227
|
+
</tr>
|
|
228
|
+
</thead>
|
|
229
|
+
<tbody>
|
|
230
|
+
{rows.map((id) => (
|
|
231
|
+
<tr {...table.rowProps(id)}>
|
|
232
|
+
{table.selectAllProps && (
|
|
233
|
+
<td>
|
|
234
|
+
<span {...table.rowCheckboxProps(id)} />
|
|
235
|
+
</td>
|
|
236
|
+
)}
|
|
237
|
+
{columns.map((column) => (
|
|
238
|
+
<td {...table.cellProps(id, column.key)}>{cellOf(id, column.key)}</td>
|
|
239
|
+
))}
|
|
240
|
+
</tr>
|
|
241
|
+
))}
|
|
242
|
+
</tbody>
|
|
243
|
+
</table>;
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
- **Sorting is the host's data.** The primitive carries the descriptor (`sort()`) and announces it; it never reorders anything. The host maps the descriptor onto its own array and renders `rows` again.
|
|
247
|
+
- **`aria-sort` is on the sorted column only.** A sortable header that is not sorted carries nothing (ARIA's default is "not sorted"), and a `sortable: false` column is fully inert: no `aria-sort`, and `headerButtonProps` is `undefined`, so the host renders no button and it is not a tab stop.
|
|
248
|
+
- **The cycle is tri-state by default** (`ascending` -> `descending` -> unsorted), so a table can be put back in its own order; `sortCycle: "toggle"` gives `ascending` <-> `descending` and never returns to unsorted, which is what the APG grid example does. A new column always starts `ascending`, and only one column is ever sorted.
|
|
249
|
+
- **Rows are ids, not a count.** The host sorts its data, so an id keeps naming the same row across a re-sort while an index would not; the primitive never learns the row's content.
|
|
250
|
+
- **Selection** is `"none"` (the default), `"single"` or `"multiple"`, over ids: `selected()` is the list, `rowProps(id)` carries `aria-selected` and a click that selects, and `toggleRow` / `toggleAll` are the programmatic path. The row's checkbox stops its own click from reaching the row, so the two controls never toggle the same row twice.
|
|
251
|
+
- **Select-all exists only for `"multiple"`** (`selectAllProps` and `rowCheckboxProps` are `undefined` otherwise: one control over one selection is meaningless). It is a `role="checkbox"`, not a native `input`: the mixed state of a native checkbox is a DOM property (`indeterminate`), and what a screen reader must hear is `aria-checked="mixed"`. It toggles the rows the table renders — a windowed table therefore toggles its window and keeps the rest of the selection.
|
|
252
|
+
- **Windowed rows or columns** pass `rowCount` / `columnCount`: then `aria-rowcount` and `aria-colcount` are carried, and every cell gets its `aria-colindex`. A table that renders all of them carries neither (it would only repeat what the markup says).
|
|
253
|
+
- **`numeric` is a layout hint** for the host's skin (right alignment, tabular figures): HTML has no attribute for it, so the primitive carries nothing.
|
|
254
|
+
- Solid 2 arrives through delegated events; a host that reads the DOM right after a click waits a tick.
|
|
255
|
+
|
|
192
256
|
## Confirm
|
|
193
257
|
|
|
194
258
|
`createConfirm` is a promise-based confirmation over `createDialogModal({ role: "alertdialog" })`. Like the field it is not checked against a spec (the dialog is; `test/confirm.browser.test.tsx` covers the promise around it, in Chromium).
|
|
@@ -296,6 +360,28 @@ onMount(() => {
|
|
|
296
360
|
- **Not a menu.** No roving focus, no arrow keys between items: it is the base for `createMenu` in a popover, and for the filterable menu, which own their own item focus.
|
|
297
361
|
- Absent on purpose: hover open (that is `createTooltipGroup`), submenus and item navigation (the menu), a scroll lock and `inert` (the modal dialog), and a vertical shift when neither side fits (the caller sees the requested placement).
|
|
298
362
|
|
|
363
|
+
## Drawer
|
|
364
|
+
|
|
365
|
+
`createDrawer` is the drawer / sheet shell: an edge-anchored panel over the Dialog (Modal) semantics, with the same focus, Escape, scroll-lock and backdrop behaviour as `createConfirm`. **No APG pattern exists for a drawer or a bottom sheet**, and [docs/bottom-sheet.md](docs/bottom-sheet.md) settled that the library composes rather than adding a sheet primitive: the semantics are Dialog (Modal), the position, the slide and the snap points are the host's native CSS, and this is the panel both were missing. `test/drawer.browser.test.tsx` is the oracle.
|
|
366
|
+
|
|
367
|
+
```tsx
|
|
368
|
+
const drawer = createDrawer({ side: "right", labelledby: "nav-title" });
|
|
369
|
+
|
|
370
|
+
<button {...drawer.triggerProps}>Menu</button>;
|
|
371
|
+
<div {...drawer.backdropProps} />;
|
|
372
|
+
<div {...drawer.contentProps}>
|
|
373
|
+
<h2 id="nav-title">Site</h2>
|
|
374
|
+
<nav>{/* links */}</nav>
|
|
375
|
+
</div>;
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
- **`side` is presentation only**, `"right"` (the default), `"left"` or `"bottom"`: a sheet is `{ side: "bottom" }`, a side rail is `{ side: "left" }`, and it is one API either way. The primitive lays out nothing; the host's CSS anchors the panel, and `handleProps` is the grab handle of a sheet.
|
|
379
|
+
- **`modal` is the breakpoint switch.** It is read on every attribute read, so a host may flip it while the drawer is open (crossing the breakpoint) and `aria-modal`, the backdrop and the lock follow. `breakpoint` is a px number the primitive **does not read**: it has no viewport, so the host watches `matchMedia` and passes `side` and `modal`. A sheet below a breakpoint is modal; a side rail above it may not be.
|
|
380
|
+
- **Modal** (the default): `aria-modal="true"`, a backdrop, focus into the panel's first focusable on open (else the panel, which is `tabindex="-1"`) and back to the trigger on close, Tab and Shift+Tab cycling inside, `overflow: hidden` on `document.documentElement` counted (as in `createConfirm`, and shared with it: a confirm over a drawer nests), and Escape read from the document in the capture phase, so it closes wherever the focus is. **Non-modal**: no `aria-modal`, no backdrop, no lock and no Tab trap, so the page keeps its scroll and its clicks; an outside `pointerdown` still dismisses it when `dismissable`, and Escape still closes it.
|
|
381
|
+
- **The trigger toggles** (a hamburger), and Enter / Space open it. `dismissable: false` keeps the backdrop and an outside `pointerdown` from closing the drawer; Escape still closes it, because there is no way out otherwise.
|
|
382
|
+
- **No drag-to-dismiss.** A drag is not a dialog interaction: it is a scroll snap the platform runs off the main thread, and it is the host's CSS (`scroll-snap-type: y mandatory`, snap markers, `scrollsnapchange`; see [docs/bottom-sheet.md](docs/bottom-sheet.md)). Re-implementing a native snap in pointer events would be the gesture duplication that research forbids, and the handle would drag on top of the snap that already moved the panel. So `handleProps` is decoration (`aria-hidden`, no pointer handlers) and the ways out are the backdrop, Escape, a close control the host puts in the panel, and the trigger. Swipe-to-dismiss, if it is ever wanted, is a separate decision with its own oracle.
|
|
383
|
+
- **No `attach`.** The panel is edge-anchored: nothing is measured and no placement is computed, so focus and the Tab cycle find the panel through `contentProps.id` and the host only spreads attributes onto its own elements. Give the panel a name: pass `labelledby`, or set `aria-labelledby` / `aria-label` after the spread.
|
|
384
|
+
|
|
299
385
|
## Commands
|
|
300
386
|
|
|
301
387
|
```sh
|
package/dist/index.d.mts
CHANGED
|
@@ -1374,7 +1374,9 @@ export declare class ConfirmPendingError extends Error {
|
|
|
1374
1374
|
* Nesting: confirms from different `createConfirm` calls may be open together;
|
|
1375
1375
|
* only the last one opened gets Escape and Tab (and Escape does not reach a
|
|
1376
1376
|
* dialog it sits in), and the scroll lock is counted: the first takes it, the
|
|
1377
|
-
* last to close restores what `overflow` was.
|
|
1377
|
+
* last to close restores what `overflow` was. `createDrawer` claims the same
|
|
1378
|
+
* page-wide stack and lock, so a confirm over a drawer (or the reverse) nests
|
|
1379
|
+
* the same way. One confirm still has one request.
|
|
1378
1380
|
*
|
|
1379
1381
|
* One request at a time: a second `confirm()` while one is pending is rejected,
|
|
1380
1382
|
* not queued. Queued, a double click on "Delete" would ask twice and a stale
|
|
@@ -1382,6 +1384,119 @@ export declare class ConfirmPendingError extends Error {
|
|
|
1382
1384
|
* answered `false` when the owner is disposed.
|
|
1383
1385
|
*/
|
|
1384
1386
|
export declare const createConfirm: (options?: ConfirmOptions) => Confirm;
|
|
1387
|
+
/** The edge a drawer occupies. `side()` reads the option at call time. */
|
|
1388
|
+
export type DrawerSide = "left" | "right" | "bottom";
|
|
1389
|
+
export interface DrawerOptions {
|
|
1390
|
+
/** Base for the generated trigger / content / backdrop ids. */
|
|
1391
|
+
readonly id?: string | undefined;
|
|
1392
|
+
/** Controlled: the host owns the open state and this is the only thing that changes it. */
|
|
1393
|
+
readonly open?: boolean | undefined;
|
|
1394
|
+
/** Uncontrolled starting state; ignored while `open` is set. */
|
|
1395
|
+
readonly defaultOpen?: boolean | undefined;
|
|
1396
|
+
/**
|
|
1397
|
+
* The edge the panel is anchored to. @default "right"
|
|
1398
|
+
*
|
|
1399
|
+
* Presentation only: a `bottom` panel is a sheet, `left` / `right` is a side
|
|
1400
|
+
* rail, and the same drawer is one API either way.
|
|
1401
|
+
*/
|
|
1402
|
+
readonly side?: DrawerSide | undefined;
|
|
1403
|
+
/**
|
|
1404
|
+
* Whether the panel is modal: `aria-modal`, the Tab cycle, the scroll lock and
|
|
1405
|
+
* the backdrop. @default true
|
|
1406
|
+
*
|
|
1407
|
+
* This is the switch a breakpoint flips: below it a panel is a sheet and
|
|
1408
|
+
* modal, above it a side rail may not be. It is read on every attribute read,
|
|
1409
|
+
* so the host may change it while the drawer is open (crossing the
|
|
1410
|
+
* breakpoint) and the backdrop, `aria-modal` and the lock follow.
|
|
1411
|
+
*/
|
|
1412
|
+
readonly modal?: boolean | undefined;
|
|
1413
|
+
/**
|
|
1414
|
+
* The width in px at which the host switches `side` and `modal` (a sheet
|
|
1415
|
+
* below it, a dialog above). **Not read here**: the primitive has no viewport
|
|
1416
|
+
* to measure and no `matchMedia`, so it only documents the pattern, and the
|
|
1417
|
+
* host watches the breakpoint and passes `modal` / `side`. A host that wants
|
|
1418
|
+
* the sheet drag behaviour composes CSS scroll snap around this, as
|
|
1419
|
+
* [docs/bottom-sheet.md](../docs/bottom-sheet.md) lays out.
|
|
1420
|
+
*/
|
|
1421
|
+
readonly breakpoint?: number | undefined;
|
|
1422
|
+
/** A backdrop click or an outside `pointerdown` closes the drawer. @default true */
|
|
1423
|
+
readonly dismissable?: boolean | undefined;
|
|
1424
|
+
/** Id of the element naming the panel (`aria-labelledby`); a dialog without a name is unusable. */
|
|
1425
|
+
readonly labelledby?: string | undefined;
|
|
1426
|
+
/** A request to change the open state, called when the intent differs. */
|
|
1427
|
+
readonly onOpenChange?: ((open: boolean) => void) | undefined;
|
|
1428
|
+
}
|
|
1429
|
+
export interface DrawerTriggerProps {
|
|
1430
|
+
readonly id: string;
|
|
1431
|
+
readonly "aria-haspopup": "dialog";
|
|
1432
|
+
readonly "aria-expanded": "true" | "false";
|
|
1433
|
+
readonly "aria-controls": string;
|
|
1434
|
+
readonly onClick: () => void;
|
|
1435
|
+
readonly onKeyDown: (event: KeyboardEvent) => void;
|
|
1436
|
+
}
|
|
1437
|
+
export interface DrawerBackdropProps {
|
|
1438
|
+
readonly id: string;
|
|
1439
|
+
/** Always hidden when the drawer is closed or not modal: a non-modal drawer keeps the page clickable. */
|
|
1440
|
+
readonly hidden: boolean;
|
|
1441
|
+
readonly onClick: () => void;
|
|
1442
|
+
}
|
|
1443
|
+
export interface DrawerContentProps {
|
|
1444
|
+
readonly id: string;
|
|
1445
|
+
readonly role: "dialog";
|
|
1446
|
+
readonly "aria-modal": "true" | undefined;
|
|
1447
|
+
readonly "aria-labelledby": string | undefined;
|
|
1448
|
+
readonly tabindex: -1;
|
|
1449
|
+
readonly hidden: boolean;
|
|
1450
|
+
readonly onKeyDown: (event: KeyboardEvent) => void;
|
|
1451
|
+
}
|
|
1452
|
+
/** A bottom sheet's grab handle. Decorative: there is no drag, so it says nothing. */
|
|
1453
|
+
export interface DrawerHandleProps {
|
|
1454
|
+
readonly "aria-hidden": "true";
|
|
1455
|
+
}
|
|
1456
|
+
export interface Drawer {
|
|
1457
|
+
readonly open: Accessor<boolean>;
|
|
1458
|
+
readonly side: Accessor<DrawerSide>;
|
|
1459
|
+
readonly triggerProps: DrawerTriggerProps;
|
|
1460
|
+
readonly backdropProps: DrawerBackdropProps;
|
|
1461
|
+
readonly contentProps: DrawerContentProps;
|
|
1462
|
+
readonly handleProps: DrawerHandleProps;
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* The shell for a drawer / bottom sheet: an edge-anchored panel over the
|
|
1466
|
+
* Dialog (Modal) semantics (https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/),
|
|
1467
|
+
* with the same shell as `createConfirm` — focus into the panel on open and back
|
|
1468
|
+
* to the trigger on close, Tab cycling while modal, Escape read from the
|
|
1469
|
+
* document (so it closes wherever focus is), a counted scroll lock and an
|
|
1470
|
+
* outside dismissal.
|
|
1471
|
+
*
|
|
1472
|
+
* **Compose, do not add a sheet primitive.** [docs/bottom-sheet.md](../docs/bottom-sheet.md)
|
|
1473
|
+
* settled it: the semantics are Dialog (Modal), the position, the slide and the
|
|
1474
|
+
* snap points are the host's CSS (native scroll snap), and the panel that both
|
|
1475
|
+
* need is this shell. `side` and `modal` are the whole presentation API: a sheet
|
|
1476
|
+
* is `{ side: "bottom", modal: true }`, a side rail is `{ side: "right" }` and a
|
|
1477
|
+
* non-modal rail is `{ side: "right", modal: false }`.
|
|
1478
|
+
*
|
|
1479
|
+
* **No drag-to-dismiss.** A drag is not a dialog interaction, it is a scroll
|
|
1480
|
+
* snap the platform runs off the main thread, and it belongs to the host's
|
|
1481
|
+
* scroll-snap CSS (see bottom-sheet.md: `scroll-snap-type: y mandatory`, snap
|
|
1482
|
+
* markers, `scrollsnapchange`). Mirroring a native snap in JS would be the
|
|
1483
|
+
* gesture re-implementation that the platform research forbids, and a pointer
|
|
1484
|
+
* gesture would exist on top of the snap that already moved the panel. So the
|
|
1485
|
+
* handle is decoration (`aria-hidden`, no pointer handlers): the ways out are
|
|
1486
|
+
* the backdrop, Escape, the close control the host puts in the panel, and the
|
|
1487
|
+
* trigger. Swipe-to-dismiss is a separate decision with its own oracle.
|
|
1488
|
+
*
|
|
1489
|
+
* The panel is edge-anchored, so there is **no `attach`**: nothing is measured
|
|
1490
|
+
* and no placement is computed. Focus and Tab find the panel through
|
|
1491
|
+
* `contentProps.id`, like `createConfirm` does, so the host only spreads
|
|
1492
|
+
* attributes onto its own elements.
|
|
1493
|
+
*
|
|
1494
|
+
* Not checked against a Quint spec: the dialog is, and this is its shell, so
|
|
1495
|
+
* `test/drawer.browser.test.tsx` is the oracle. A pointerdown outside the panel
|
|
1496
|
+
* closes it when `dismissable` (that is the backdrop click too, and the only
|
|
1497
|
+
* dismissal a non-modal drawer has); closing returns focus to the trigger.
|
|
1498
|
+
*/
|
|
1499
|
+
export declare const createDrawer: (options?: DrawerOptions) => Drawer;
|
|
1385
1500
|
/**
|
|
1386
1501
|
* Options are read lazily (getters); pass a component's `props`.
|
|
1387
1502
|
*/
|
|
@@ -2797,6 +2912,182 @@ export interface Switch {
|
|
|
2797
2912
|
* pass `value` + `onValueChange` to own the state.
|
|
2798
2913
|
*/
|
|
2799
2914
|
export declare const createSwitch: (options?: SwitchOptions) => Switch;
|
|
2915
|
+
/**
|
|
2916
|
+
* A data table on Solid 2: sortable column headers and row selection, as state
|
|
2917
|
+
* plus getter-backed attribute objects; no elements, no styling.
|
|
2918
|
+
*
|
|
2919
|
+
* **The host renders a native `<table>`**: `<caption>`, `<thead>`, `<tbody>`,
|
|
2920
|
+
* `<th scope="col">` and `<td>` carry the semantics, so the primitive adds no
|
|
2921
|
+
* `role` and no `aria-rowindex` — only what a native table cannot say itself
|
|
2922
|
+
* (which column is sorted, whether a row is selected, the mixed select-all
|
|
2923
|
+
* state, and the totals a windowed table hides).
|
|
2924
|
+
*
|
|
2925
|
+
* **Sorting is the host's data.** The primitive carries the sort descriptor and
|
|
2926
|
+
* announces it (`aria-sort`); it never sorts. The host maps `sort()` onto its
|
|
2927
|
+
* own array before rendering `rows`.
|
|
2928
|
+
*
|
|
2929
|
+
* Composes the two state models the package already has — `grid-sort.qnt` and
|
|
2930
|
+
* `grid-selection.qnt` — without their navigation: a table is a grid with a
|
|
2931
|
+
* `th[scope]` header row, and the cells keep their own focus.
|
|
2932
|
+
*
|
|
2933
|
+
* Request/commit (map ticket `rt1p`): the sort and the selection are
|
|
2934
|
+
* uncontrolled by default (`defaultSort` / `defaultSelected`) and can be owned
|
|
2935
|
+
* by the host with `sort` + `onSortChange` / `selected` + `onSelectionChange`.
|
|
2936
|
+
* `null` as `sort` is "no column sorted" (in a controlled host); `undefined` is
|
|
2937
|
+
* "uncontrolled". `toggleRow`, `toggleAll` and the header button are requests:
|
|
2938
|
+
* a controlled host may ignore them.
|
|
2939
|
+
*/
|
|
2940
|
+
export type TableSortDirection = "ascending" | "descending";
|
|
2941
|
+
export type TableSelectionMode = "none" | "single" | "multiple";
|
|
2942
|
+
/**
|
|
2943
|
+
* `"tri-state"`: ascending -> descending -> unsorted, so a table can be put back
|
|
2944
|
+
* in its own order (the bean's requirement). `"toggle"`: ascending <-> descending,
|
|
2945
|
+
* never unsorted, which is what the APG grid example (and `grid-sort.qnt`) does.
|
|
2946
|
+
*/
|
|
2947
|
+
export type TableSortCycle = "tri-state" | "toggle";
|
|
2948
|
+
export interface TableSort {
|
|
2949
|
+
readonly key: string;
|
|
2950
|
+
readonly direction: TableSortDirection;
|
|
2951
|
+
}
|
|
2952
|
+
export interface TableColumn {
|
|
2953
|
+
/** Identity of the column: what `cellProps` and `headerCellProps` are asked for. */
|
|
2954
|
+
readonly key: string;
|
|
2955
|
+
/** Defaults to `true`; `false` makes the header inert (no sort button, no `aria-sort`). */
|
|
2956
|
+
readonly sortable?: boolean | undefined;
|
|
2957
|
+
/**
|
|
2958
|
+
* A layout hint for the host's skin (right-aligned, tabular figures). HTML has
|
|
2959
|
+
* no attribute for it, so the primitive carries nothing.
|
|
2960
|
+
*/
|
|
2961
|
+
readonly numeric?: boolean | undefined;
|
|
2962
|
+
/** The `abbr` of the header cell: the short form a screen reader uses. */
|
|
2963
|
+
readonly abbr?: string | undefined;
|
|
2964
|
+
}
|
|
2965
|
+
export interface TableLabels {
|
|
2966
|
+
/** The table's accessible name; a host that renders a `<caption>` leaves it out. */
|
|
2967
|
+
readonly table?: string | undefined;
|
|
2968
|
+
/** Defaults to "Select all rows". */
|
|
2969
|
+
readonly selectAll?: string | undefined;
|
|
2970
|
+
/** Defaults to `Select row <id>`. */
|
|
2971
|
+
readonly selectRow?: ((id: string) => string) | undefined;
|
|
2972
|
+
}
|
|
2973
|
+
export interface TableOptions {
|
|
2974
|
+
readonly columns: ReadonlyArray<TableColumn>;
|
|
2975
|
+
/**
|
|
2976
|
+
* The row ids the host renders, in render order. Ids, not a count: the sort
|
|
2977
|
+
* reorders the host's data and a selection must survive that, while an index
|
|
2978
|
+
* would then name a different row. The row's visible content stays the host's.
|
|
2979
|
+
*/
|
|
2980
|
+
readonly rows: ReadonlyArray<string>;
|
|
2981
|
+
readonly selection?: TableSelectionMode | undefined;
|
|
2982
|
+
readonly sortCycle?: TableSortCycle | undefined;
|
|
2983
|
+
/** Controlled: the host owns the sort and this is the only thing that changes it; `null` is "unsorted". */
|
|
2984
|
+
readonly sort?: TableSort | null | undefined;
|
|
2985
|
+
/** Uncontrolled starting sort; ignored while `sort` is set. */
|
|
2986
|
+
readonly defaultSort?: TableSort | undefined;
|
|
2987
|
+
/** A request to re-sort (`undefined` = unsorted); uncontrolled it is accepted. */
|
|
2988
|
+
readonly onSortChange?: ((sort: TableSort | undefined) => void) | undefined;
|
|
2989
|
+
/** Controlled: the host owns the selected row ids and this is the only thing that changes them. */
|
|
2990
|
+
readonly selected?: ReadonlyArray<string> | undefined;
|
|
2991
|
+
/** Uncontrolled starting selection; ignored while `selected` is set. */
|
|
2992
|
+
readonly defaultSelected?: ReadonlyArray<string> | undefined;
|
|
2993
|
+
/** A request to change the selection; uncontrolled it is accepted. */
|
|
2994
|
+
readonly onSelectionChange?: ((selected: ReadonlyArray<string>) => void) | undefined;
|
|
2995
|
+
/**
|
|
2996
|
+
* The total row count when the host renders a window of `rows`
|
|
2997
|
+
* (`aria-rowcount`); absent on a table that renders all of them.
|
|
2998
|
+
*/
|
|
2999
|
+
readonly rowCount?: number | undefined;
|
|
3000
|
+
/**
|
|
3001
|
+
* The total column count when the host renders a window of `columns`
|
|
3002
|
+
* (`aria-colcount` and `aria-colindex`); absent on a table that renders all.
|
|
3003
|
+
*/
|
|
3004
|
+
readonly columnCount?: number | undefined;
|
|
3005
|
+
readonly labels?: TableLabels | undefined;
|
|
3006
|
+
/** Base for generated ids. */
|
|
3007
|
+
readonly id?: string | undefined;
|
|
3008
|
+
}
|
|
3009
|
+
/** Spread onto `<table>`; the host renders the table, the head and the body. */
|
|
3010
|
+
export interface TableProps {
|
|
3011
|
+
/** `labels.table`; leave it out when the host renders a caption. */
|
|
3012
|
+
readonly "aria-label": string | undefined;
|
|
3013
|
+
/** Only while the host windows its rows. */
|
|
3014
|
+
readonly "aria-rowcount": number | undefined;
|
|
3015
|
+
/** Only while the host windows its columns. */
|
|
3016
|
+
readonly "aria-colcount": number | undefined;
|
|
3017
|
+
}
|
|
3018
|
+
/** Spread onto `<caption>`. */
|
|
3019
|
+
export interface TableCaptionProps {
|
|
3020
|
+
readonly id: string;
|
|
3021
|
+
}
|
|
3022
|
+
/** Spread onto `<th scope="col">` in the header row. */
|
|
3023
|
+
export interface TableHeaderCellProps {
|
|
3024
|
+
readonly scope: "col";
|
|
3025
|
+
/** The sorted column only; an unsorted one carries nothing (ARIA's default). */
|
|
3026
|
+
readonly "aria-sort": TableSortDirection | undefined;
|
|
3027
|
+
readonly abbr: string | undefined;
|
|
3028
|
+
}
|
|
3029
|
+
/** Spread onto the `<button type="button">` inside a sortable `<th>`. */
|
|
3030
|
+
export interface TableHeaderButtonProps {
|
|
3031
|
+
readonly type: "button";
|
|
3032
|
+
readonly onClick: () => void;
|
|
3033
|
+
}
|
|
3034
|
+
/** Spread onto `<tr>` in the body. */
|
|
3035
|
+
export interface TableRowProps {
|
|
3036
|
+
readonly "aria-selected": "true" | "false" | undefined;
|
|
3037
|
+
/** Selects the row; `undefined` when nothing is selectable. */
|
|
3038
|
+
readonly onClick: (() => void) | undefined;
|
|
3039
|
+
}
|
|
3040
|
+
/** Spread onto a `<td>`; `aria-colindex` only while the host windows its columns. */
|
|
3041
|
+
export interface TableCellProps {
|
|
3042
|
+
readonly "aria-colindex": number | undefined;
|
|
3043
|
+
}
|
|
3044
|
+
/**
|
|
3045
|
+
* Spread onto the select-all control: a `role=checkbox` element (not a native
|
|
3046
|
+
* `input`, which spells the mixed state as a DOM property, not an attribute).
|
|
3047
|
+
*/
|
|
3048
|
+
export interface TableSelectAllProps {
|
|
3049
|
+
readonly role: "checkbox";
|
|
3050
|
+
readonly "aria-checked": "true" | "false" | "mixed";
|
|
3051
|
+
readonly "aria-label": string;
|
|
3052
|
+
readonly tabindex: 0;
|
|
3053
|
+
readonly onClick: () => void;
|
|
3054
|
+
readonly onKeyDown: (event: KeyboardEvent) => void;
|
|
3055
|
+
}
|
|
3056
|
+
/** Spread onto a row's selection control. */
|
|
3057
|
+
export interface TableRowCheckboxProps {
|
|
3058
|
+
readonly role: "checkbox";
|
|
3059
|
+
readonly "aria-checked": "true" | "false";
|
|
3060
|
+
readonly "aria-label": string;
|
|
3061
|
+
readonly tabindex: 0;
|
|
3062
|
+
/** Selects the row and stops there: the control sits inside the row, whose click would select again. */
|
|
3063
|
+
readonly onClick: (event: MouseEvent) => void;
|
|
3064
|
+
readonly onKeyDown: (event: KeyboardEvent) => void;
|
|
3065
|
+
}
|
|
3066
|
+
export interface Table {
|
|
3067
|
+
readonly selectionMode: Accessor<TableSelectionMode>;
|
|
3068
|
+
/** The sort descriptor, or `undefined` when nothing is sorted. */
|
|
3069
|
+
readonly sort: Accessor<TableSort | undefined>;
|
|
3070
|
+
readonly selected: Accessor<ReadonlyArray<string>>;
|
|
3071
|
+
readonly isSelected: (id: string) => boolean;
|
|
3072
|
+
readonly tableProps: TableProps;
|
|
3073
|
+
readonly captionProps: TableCaptionProps;
|
|
3074
|
+
readonly headerCellProps: (key: string) => TableHeaderCellProps;
|
|
3075
|
+
/** `undefined` for a column that is not sortable — render no button there. */
|
|
3076
|
+
readonly headerButtonProps: (key: string) => TableHeaderButtonProps | undefined;
|
|
3077
|
+
readonly rowProps: (id: string) => TableRowProps;
|
|
3078
|
+
readonly cellProps: (rowId: string, key: string) => TableCellProps;
|
|
3079
|
+
/** `undefined` unless `selection` is `"multiple"`: one control over one selection is meaningless. */
|
|
3080
|
+
readonly selectAllProps: TableSelectAllProps | undefined;
|
|
3081
|
+
/** `undefined` while `selection` is `"none"`. */
|
|
3082
|
+
readonly rowCheckboxProps: (id: string) => TableRowCheckboxProps | undefined;
|
|
3083
|
+
readonly toggleAll: () => void;
|
|
3084
|
+
readonly toggleRow: (id: string) => void;
|
|
3085
|
+
}
|
|
3086
|
+
/**
|
|
3087
|
+
* Every option is read when an attribute is read, so pass props/getters, never a
|
|
3088
|
+
* destructured snapshot. `id` is captured once: it is the base of the caption id.
|
|
3089
|
+
*/
|
|
3090
|
+
export declare const createTable: (options: TableOptions) => Table;
|
|
2800
3091
|
/** The HTML `autocomplete` tokens worth naming; the attribute also takes an arbitrary token. */
|
|
2801
3092
|
export type AutoCompleteToken = "off" | "on" | "name" | "given-name" | "family-name" | "username" | "email" | "tel" | "url" | "organization" | "street-address" | "postal-code" | "current-password" | "new-password" | "one-time-code" | "nickname";
|
|
2802
3093
|
export interface TextInputOptions extends FieldOptions {
|
package/dist/index.mjs
CHANGED
|
@@ -54,7 +54,7 @@ const toggled = (a, index) => {
|
|
|
54
54
|
else next.add(index);
|
|
55
55
|
return next;
|
|
56
56
|
};
|
|
57
|
-
const sameSet = (a, b) => a.size === b.size && [...a].every((index) => b.has(index));
|
|
57
|
+
const sameSet$1 = (a, b) => a.size === b.size && [...a].every((index) => b.has(index));
|
|
58
58
|
/** The only member, or -1. */
|
|
59
59
|
const sole = (a) => a.size === 1 ? [...a][0] ?? -1 : -1;
|
|
60
60
|
const at = (values, index) => values[index] ?? 0;
|
|
@@ -477,7 +477,7 @@ const createCanvas = (options) => {
|
|
|
477
477
|
annSel: ann,
|
|
478
478
|
annText: prefs.announce ? messages().selection([...ann].sort((a, b) => a - b).map((i) => labelAt(s, i))) : ""
|
|
479
479
|
});
|
|
480
|
-
const announced = (s, sel) => sameSet(sel, s.annSel) ? {
|
|
480
|
+
const announced = (s, sel) => sameSet$1(sel, s.annSel) ? {
|
|
481
481
|
...s,
|
|
482
482
|
sel
|
|
483
483
|
} : announcing({
|
|
@@ -1296,7 +1296,7 @@ const createPlayer = (options) => {
|
|
|
1296
1296
|
const HEADING_LEVELS = 6;
|
|
1297
1297
|
const count = (expanded) => expanded.filter(Boolean).length;
|
|
1298
1298
|
/** Re-establish the mode's constraints, exactly as the spec's `normExpanded`. */
|
|
1299
|
-
const normalize$
|
|
1299
|
+
const normalize$2 = (expanded, multiple, collapsible) => {
|
|
1300
1300
|
if (!collapsible && count(expanded) === 0) return expanded.map((_, index) => index === 0);
|
|
1301
1301
|
if (multiple) return expanded;
|
|
1302
1302
|
const first = expanded.findIndex(Boolean);
|
|
@@ -1328,7 +1328,7 @@ const createAccordion = (options = {}) => {
|
|
|
1328
1328
|
const controlled = () => options.value !== void 0;
|
|
1329
1329
|
const [indices, request] = createControllable({
|
|
1330
1330
|
value: () => options.value,
|
|
1331
|
-
initial: indicesOf(normalize$
|
|
1331
|
+
initial: indicesOf(normalize$2(Array.from({ length: items }, (_, index) => (options.defaultValue ?? []).includes(index)), multiple(), collapsible())),
|
|
1332
1332
|
onChange: () => options.onValueChange
|
|
1333
1333
|
});
|
|
1334
1334
|
const expanded = () => Array.from({ length: items }, (_, index) => indices().includes(index));
|
|
@@ -1361,11 +1361,11 @@ const createAccordion = (options = {}) => {
|
|
|
1361
1361
|
toggle,
|
|
1362
1362
|
setMultiple: (value) => {
|
|
1363
1363
|
setMultipleOverride(value);
|
|
1364
|
-
if (!controlled()) commit(normalize$
|
|
1364
|
+
if (!controlled()) commit(normalize$2(expanded(), value, collapsible()));
|
|
1365
1365
|
},
|
|
1366
1366
|
setCollapsible: (value) => {
|
|
1367
1367
|
setCollapsibleOverride(value);
|
|
1368
|
-
if (!controlled()) commit(normalize$
|
|
1368
|
+
if (!controlled()) commit(normalize$2(expanded(), multiple(), value));
|
|
1369
1369
|
},
|
|
1370
1370
|
setHeadingLevel: (level) => {
|
|
1371
1371
|
setHeadingLevelSignal(Math.min(Math.max(level, 1), HEADING_LEVELS));
|
|
@@ -2584,28 +2584,85 @@ const createDialogModal = (options = {}) => {
|
|
|
2584
2584
|
}
|
|
2585
2585
|
};
|
|
2586
2586
|
};
|
|
2587
|
-
// src/
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2587
|
+
// src/overlay-shell.ts
|
|
2588
|
+
/**
|
|
2589
|
+
* The page-wide half of a modal overlay: one scroll lock, one stack of open
|
|
2590
|
+
* overlays, the tabbables of a panel and the Tab cycle over them. Shared by
|
|
2591
|
+
* `createConfirm` and `createDrawer` so that a confirm opened over a drawer (or
|
|
2592
|
+
* the reverse) takes Escape and Tab first, and the scroll lock outlives the
|
|
2593
|
+
* first of them to close.
|
|
2594
|
+
*/
|
|
2595
|
+
const TABBABLE = "a[href], button, input, select, textarea, [tabindex], [contenteditable]";
|
|
2596
|
+
/** The visible, tabbable elements of `root`, in document order. */
|
|
2597
|
+
const tabbables = (root) => Array.from(root.querySelectorAll(TABBABLE)).filter((element) => element.tabIndex >= 0 && !element.matches(":disabled") && element.getClientRects().length > 0);
|
|
2598
|
+
/** The first tabbable element of `root`, if any. */
|
|
2599
|
+
const firstFocusable$1 = (root) => tabbables(root)[0];
|
|
2600
|
+
/**
|
|
2601
|
+
* Wraps Tab / Shift+Tab inside `root` and pulls a focus that escaped back in
|
|
2602
|
+
* on the next Tab. With nothing tabbable the panel itself (which is
|
|
2603
|
+
* `tabindex="-1"`) keeps the focus.
|
|
2604
|
+
*/
|
|
2605
|
+
const cycleFocus = (event, root) => {
|
|
2606
|
+
const items = tabbables(root);
|
|
2607
|
+
const first = items[0];
|
|
2608
|
+
const last = items.at(-1);
|
|
2609
|
+
const active = document.activeElement;
|
|
2610
|
+
const inside = root.contains(active);
|
|
2611
|
+
if (first === void 0 || last === void 0) {
|
|
2612
|
+
event.preventDefault();
|
|
2613
|
+
root.focus();
|
|
2614
|
+
} else if (event.shiftKey && (!inside || active === first || active === root)) {
|
|
2615
|
+
event.preventDefault();
|
|
2616
|
+
last.focus();
|
|
2617
|
+
} else if (!event.shiftKey && (!inside || active === last)) {
|
|
2618
|
+
event.preventDefault();
|
|
2619
|
+
first.focus();
|
|
2592
2620
|
}
|
|
2593
2621
|
};
|
|
2594
|
-
const openDialogs = [];
|
|
2595
2622
|
let scrollLocks = 0;
|
|
2596
2623
|
let scrollBefore = "";
|
|
2624
|
+
/**
|
|
2625
|
+
* `overflow: hidden` on the document element, counted: the first holder takes
|
|
2626
|
+
* it, the last to release restores what `overflow` was. The returned release is
|
|
2627
|
+
* idempotent.
|
|
2628
|
+
*/
|
|
2597
2629
|
const lockScroll = () => {
|
|
2598
2630
|
const root = document.documentElement;
|
|
2599
2631
|
if (scrollLocks++ === 0) {
|
|
2600
2632
|
scrollBefore = root.style.overflow;
|
|
2601
2633
|
root.style.overflow = "hidden";
|
|
2602
2634
|
}
|
|
2635
|
+
let released = false;
|
|
2603
2636
|
return () => {
|
|
2637
|
+
if (released) return;
|
|
2638
|
+
released = true;
|
|
2604
2639
|
if (--scrollLocks === 0) root.style.overflow = scrollBefore;
|
|
2605
2640
|
};
|
|
2606
2641
|
};
|
|
2607
|
-
const
|
|
2608
|
-
|
|
2642
|
+
const openOverlays = [];
|
|
2643
|
+
/**
|
|
2644
|
+
* Joins the open overlays; the last one to claim takes Escape and Tab. Returns
|
|
2645
|
+
* the release (idempotent), which may be called in any order.
|
|
2646
|
+
*/
|
|
2647
|
+
const claimOverlay = (self) => {
|
|
2648
|
+
openOverlays.push(self);
|
|
2649
|
+
let claimed = true;
|
|
2650
|
+
return () => {
|
|
2651
|
+
if (!claimed) return;
|
|
2652
|
+
claimed = false;
|
|
2653
|
+
const at = openOverlays.indexOf(self);
|
|
2654
|
+
if (at !== -1) openOverlays.splice(at, 1);
|
|
2655
|
+
};
|
|
2656
|
+
};
|
|
2657
|
+
/** Whether `self` is the overlay that takes Escape and Tab (the one opened last). */
|
|
2658
|
+
const isTopOverlay = (self) => openOverlays.at(-1) === self;
|
|
2659
|
+
// src/confirm.ts
|
|
2660
|
+
var ConfirmPendingError = class extends Error {
|
|
2661
|
+
name = "ConfirmPendingError";
|
|
2662
|
+
constructor() {
|
|
2663
|
+
super("a confirmation is already pending");
|
|
2664
|
+
}
|
|
2665
|
+
};
|
|
2609
2666
|
/**
|
|
2610
2667
|
* A promise-based confirmation over `createDialogModal({ role: "alertdialog" })`
|
|
2611
2668
|
* (APG Alert Dialog: https://www.w3.org/WAI/ARIA/apg/patterns/alertdialog/).
|
|
@@ -2627,7 +2684,9 @@ const tabbables = (root) => Array.from(root.querySelectorAll(TABBABLE)).filter((
|
|
|
2627
2684
|
* Nesting: confirms from different `createConfirm` calls may be open together;
|
|
2628
2685
|
* only the last one opened gets Escape and Tab (and Escape does not reach a
|
|
2629
2686
|
* dialog it sits in), and the scroll lock is counted: the first takes it, the
|
|
2630
|
-
* last to close restores what `overflow` was.
|
|
2687
|
+
* last to close restores what `overflow` was. `createDrawer` claims the same
|
|
2688
|
+
* page-wide stack and lock, so a confirm over a drawer (or the reverse) nests
|
|
2689
|
+
* the same way. One confirm still has one request.
|
|
2631
2690
|
*
|
|
2632
2691
|
* One request at a time: a second `confirm()` while one is pending is rejected,
|
|
2633
2692
|
* not queued. Queued, a double click on "Delete" would ask twice and a stale
|
|
@@ -2661,7 +2720,7 @@ const createConfirm = (options = {}) => {
|
|
|
2661
2720
|
});
|
|
2662
2721
|
const self = Symbol(base);
|
|
2663
2722
|
const onDocumentKeyDown = (event) => {
|
|
2664
|
-
if (
|
|
2723
|
+
if (!isTopOverlay(self)) return;
|
|
2665
2724
|
if (event.key === "Escape") {
|
|
2666
2725
|
event.preventDefault();
|
|
2667
2726
|
event.stopPropagation();
|
|
@@ -2670,31 +2729,17 @@ const createConfirm = (options = {}) => {
|
|
|
2670
2729
|
}
|
|
2671
2730
|
const root = document.getElementById(dialog.dialogProps.id);
|
|
2672
2731
|
if (event.key !== "Tab" || root === null) return;
|
|
2673
|
-
|
|
2674
|
-
const first = items[0];
|
|
2675
|
-
const last = items.at(-1);
|
|
2676
|
-
const active = document.activeElement;
|
|
2677
|
-
const inside = root.contains(active);
|
|
2678
|
-
if (first === void 0 || last === void 0) {
|
|
2679
|
-
event.preventDefault();
|
|
2680
|
-
root.focus();
|
|
2681
|
-
} else if (event.shiftKey && (!inside || active === first || active === root)) {
|
|
2682
|
-
event.preventDefault();
|
|
2683
|
-
last.focus();
|
|
2684
|
-
} else if (!event.shiftKey && (!inside || active === last)) {
|
|
2685
|
-
event.preventDefault();
|
|
2686
|
-
first.focus();
|
|
2687
|
-
}
|
|
2732
|
+
cycleFocus(event, root);
|
|
2688
2733
|
};
|
|
2689
2734
|
createEffect(() => dialog.open(), (isOpen) => {
|
|
2690
2735
|
if (!isOpen) return;
|
|
2691
2736
|
document.getElementById(cancelId)?.focus();
|
|
2692
2737
|
const unlock = lockScroll();
|
|
2693
|
-
|
|
2738
|
+
const release = claimOverlay(self);
|
|
2694
2739
|
document.addEventListener("keydown", onDocumentKeyDown, true);
|
|
2695
2740
|
return () => {
|
|
2696
2741
|
document.removeEventListener("keydown", onDocumentKeyDown, true);
|
|
2697
|
-
|
|
2742
|
+
release();
|
|
2698
2743
|
unlock();
|
|
2699
2744
|
};
|
|
2700
2745
|
});
|
|
@@ -2752,6 +2797,148 @@ const createConfirm = (options = {}) => {
|
|
|
2752
2797
|
}
|
|
2753
2798
|
};
|
|
2754
2799
|
};
|
|
2800
|
+
// src/drawer.ts
|
|
2801
|
+
/**
|
|
2802
|
+
* The shell for a drawer / bottom sheet: an edge-anchored panel over the
|
|
2803
|
+
* Dialog (Modal) semantics (https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/),
|
|
2804
|
+
* with the same shell as `createConfirm` — focus into the panel on open and back
|
|
2805
|
+
* to the trigger on close, Tab cycling while modal, Escape read from the
|
|
2806
|
+
* document (so it closes wherever focus is), a counted scroll lock and an
|
|
2807
|
+
* outside dismissal.
|
|
2808
|
+
*
|
|
2809
|
+
* **Compose, do not add a sheet primitive.** [docs/bottom-sheet.md](../docs/bottom-sheet.md)
|
|
2810
|
+
* settled it: the semantics are Dialog (Modal), the position, the slide and the
|
|
2811
|
+
* snap points are the host's CSS (native scroll snap), and the panel that both
|
|
2812
|
+
* need is this shell. `side` and `modal` are the whole presentation API: a sheet
|
|
2813
|
+
* is `{ side: "bottom", modal: true }`, a side rail is `{ side: "right" }` and a
|
|
2814
|
+
* non-modal rail is `{ side: "right", modal: false }`.
|
|
2815
|
+
*
|
|
2816
|
+
* **No drag-to-dismiss.** A drag is not a dialog interaction, it is a scroll
|
|
2817
|
+
* snap the platform runs off the main thread, and it belongs to the host's
|
|
2818
|
+
* scroll-snap CSS (see bottom-sheet.md: `scroll-snap-type: y mandatory`, snap
|
|
2819
|
+
* markers, `scrollsnapchange`). Mirroring a native snap in JS would be the
|
|
2820
|
+
* gesture re-implementation that the platform research forbids, and a pointer
|
|
2821
|
+
* gesture would exist on top of the snap that already moved the panel. So the
|
|
2822
|
+
* handle is decoration (`aria-hidden`, no pointer handlers): the ways out are
|
|
2823
|
+
* the backdrop, Escape, the close control the host puts in the panel, and the
|
|
2824
|
+
* trigger. Swipe-to-dismiss is a separate decision with its own oracle.
|
|
2825
|
+
*
|
|
2826
|
+
* The panel is edge-anchored, so there is **no `attach`**: nothing is measured
|
|
2827
|
+
* and no placement is computed. Focus and Tab find the panel through
|
|
2828
|
+
* `contentProps.id`, like `createConfirm` does, so the host only spreads
|
|
2829
|
+
* attributes onto its own elements.
|
|
2830
|
+
*
|
|
2831
|
+
* Not checked against a Quint spec: the dialog is, and this is its shell, so
|
|
2832
|
+
* `test/drawer.browser.test.tsx` is the oracle. A pointerdown outside the panel
|
|
2833
|
+
* closes it when `dismissable` (that is the backdrop click too, and the only
|
|
2834
|
+
* dismissal a non-modal drawer has); closing returns focus to the trigger.
|
|
2835
|
+
*/
|
|
2836
|
+
const createDrawer = (options = {}) => {
|
|
2837
|
+
const base = options.id ?? createUniqueId();
|
|
2838
|
+
const triggerId = `${base}-trigger`;
|
|
2839
|
+
const contentId = `${base}-content`;
|
|
2840
|
+
const backdropId = `${base}-backdrop`;
|
|
2841
|
+
const self = Symbol(base);
|
|
2842
|
+
let wasOpen = false;
|
|
2843
|
+
const isModal = () => options.modal ?? true;
|
|
2844
|
+
const dismissable = () => options.dismissable ?? true;
|
|
2845
|
+
const content = () => document.getElementById(contentId);
|
|
2846
|
+
const trigger = () => document.getElementById(triggerId);
|
|
2847
|
+
const [open, requestOpen] = createControllable({
|
|
2848
|
+
value: () => options.open,
|
|
2849
|
+
initial: options.defaultOpen ?? false,
|
|
2850
|
+
onChange: () => options.onOpenChange
|
|
2851
|
+
});
|
|
2852
|
+
const onDocumentKeyDown = (event) => {
|
|
2853
|
+
if (!isTopOverlay(self) || !open()) return;
|
|
2854
|
+
if (event.key === "Escape") {
|
|
2855
|
+
event.preventDefault();
|
|
2856
|
+
event.stopPropagation();
|
|
2857
|
+
requestOpen(false);
|
|
2858
|
+
return;
|
|
2859
|
+
}
|
|
2860
|
+
if (event.key !== "Tab" || !isModal()) return;
|
|
2861
|
+
const panel = content();
|
|
2862
|
+
if (panel !== null) cycleFocus(event, panel);
|
|
2863
|
+
};
|
|
2864
|
+
createEffect(() => open(), (isOpen) => {
|
|
2865
|
+
if (isOpen) {
|
|
2866
|
+
wasOpen = true;
|
|
2867
|
+
const panel = content();
|
|
2868
|
+
if (panel !== null) (firstFocusable$1(panel) ?? panel).focus();
|
|
2869
|
+
const release = claimOverlay(self);
|
|
2870
|
+
document.addEventListener("keydown", onDocumentKeyDown, true);
|
|
2871
|
+
return () => {
|
|
2872
|
+
document.removeEventListener("keydown", onDocumentKeyDown, true);
|
|
2873
|
+
release();
|
|
2874
|
+
};
|
|
2875
|
+
}
|
|
2876
|
+
if (wasOpen) {
|
|
2877
|
+
wasOpen = false;
|
|
2878
|
+
const back = trigger();
|
|
2879
|
+
if (back !== null && back.isConnected) back.focus();
|
|
2880
|
+
}
|
|
2881
|
+
});
|
|
2882
|
+
createEffect(() => open() && isModal(), (locked) => {
|
|
2883
|
+
if (locked) return lockScroll();
|
|
2884
|
+
});
|
|
2885
|
+
const onPointerDown = (event) => {
|
|
2886
|
+
if (!open() || !dismissable()) return;
|
|
2887
|
+
const target = event.target;
|
|
2888
|
+
if (!(target instanceof Node)) return;
|
|
2889
|
+
if (content()?.contains(target) === true || trigger()?.contains(target) === true) return;
|
|
2890
|
+
requestOpen(false);
|
|
2891
|
+
};
|
|
2892
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
2893
|
+
onCleanup(() => document.removeEventListener("pointerdown", onPointerDown, true));
|
|
2894
|
+
return {
|
|
2895
|
+
open,
|
|
2896
|
+
side: () => options.side ?? "right",
|
|
2897
|
+
triggerProps: {
|
|
2898
|
+
id: triggerId,
|
|
2899
|
+
"aria-haspopup": "dialog",
|
|
2900
|
+
get "aria-expanded"() {
|
|
2901
|
+
return open() ? "true" : "false";
|
|
2902
|
+
},
|
|
2903
|
+
"aria-controls": contentId,
|
|
2904
|
+
onClick: () => requestOpen(!open()),
|
|
2905
|
+
onKeyDown: (event) => {
|
|
2906
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
2907
|
+
event.preventDefault();
|
|
2908
|
+
requestOpen(true);
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
},
|
|
2912
|
+
backdropProps: {
|
|
2913
|
+
id: backdropId,
|
|
2914
|
+
get hidden() {
|
|
2915
|
+
return !open() || !isModal();
|
|
2916
|
+
},
|
|
2917
|
+
onClick: () => {
|
|
2918
|
+
if (dismissable()) requestOpen(false);
|
|
2919
|
+
}
|
|
2920
|
+
},
|
|
2921
|
+
contentProps: {
|
|
2922
|
+
id: contentId,
|
|
2923
|
+
role: "dialog",
|
|
2924
|
+
get "aria-modal"() {
|
|
2925
|
+
return isModal() && open() ? "true" : void 0;
|
|
2926
|
+
},
|
|
2927
|
+
"aria-labelledby": options.labelledby,
|
|
2928
|
+
tabindex: -1,
|
|
2929
|
+
get hidden() {
|
|
2930
|
+
return !open();
|
|
2931
|
+
},
|
|
2932
|
+
onKeyDown: (event) => {
|
|
2933
|
+
if (event.key === "Escape" && open()) {
|
|
2934
|
+
event.preventDefault();
|
|
2935
|
+
requestOpen(false);
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
},
|
|
2939
|
+
handleProps: { "aria-hidden": "true" }
|
|
2940
|
+
};
|
|
2941
|
+
};
|
|
2755
2942
|
// src/feed.ts
|
|
2756
2943
|
/**
|
|
2757
2944
|
* APG Feed (https://www.w3.org/WAI/ARIA/apg/patterns/feed/): state plus prop
|
|
@@ -5822,6 +6009,171 @@ const createSwitch = (options = {}) => {
|
|
|
5822
6009
|
}
|
|
5823
6010
|
};
|
|
5824
6011
|
};
|
|
6012
|
+
// src/table.ts
|
|
6013
|
+
const normalize$1 = (ids) => [...new Set(ids)];
|
|
6014
|
+
const sameSet = (a, b) => a.length === b.length && a.every((id) => b.includes(id));
|
|
6015
|
+
const sameSort = (a, b) => a === null || b === null ? a === b : a.key === b.key && a.direction === b.direction;
|
|
6016
|
+
const isToggleKey = (event) => event.key === " " || event.key === "Spacebar" || event.key === "Enter";
|
|
6017
|
+
/**
|
|
6018
|
+
* Every option is read when an attribute is read, so pass props/getters, never a
|
|
6019
|
+
* destructured snapshot. `id` is captured once: it is the base of the caption id.
|
|
6020
|
+
*/
|
|
6021
|
+
const createTable = (options) => {
|
|
6022
|
+
const base = options.id ?? createUniqueId();
|
|
6023
|
+
const selectionMode = () => options.selection ?? "none";
|
|
6024
|
+
const selectable = () => selectionMode() !== "none";
|
|
6025
|
+
const columnOf = (key) => options.columns.find((column) => column.key === key);
|
|
6026
|
+
const isSortable = (key) => columnOf(key)?.sortable !== false;
|
|
6027
|
+
const [rawSort, requestSort] = createControllable({
|
|
6028
|
+
value: () => options.sort,
|
|
6029
|
+
initial: options.defaultSort ?? null,
|
|
6030
|
+
onChange: () => (next) => options.onSortChange?.(next ?? void 0),
|
|
6031
|
+
same: sameSort
|
|
6032
|
+
});
|
|
6033
|
+
const sort = () => rawSort() ?? void 0;
|
|
6034
|
+
const [rawSelected, requestSelection] = createControllable({
|
|
6035
|
+
value: () => options.selected,
|
|
6036
|
+
initial: normalize$1(options.defaultSelected ?? []),
|
|
6037
|
+
onChange: () => options.onSelectionChange,
|
|
6038
|
+
same: sameSet
|
|
6039
|
+
});
|
|
6040
|
+
const selected = () => normalize$1(rawSelected());
|
|
6041
|
+
const isSelected = (id) => selected().includes(id);
|
|
6042
|
+
const nextSort = (key) => {
|
|
6043
|
+
const current = rawSort();
|
|
6044
|
+
if (current === null || current.key !== key) return {
|
|
6045
|
+
key,
|
|
6046
|
+
direction: "ascending"
|
|
6047
|
+
};
|
|
6048
|
+
if (current.direction === "ascending") return {
|
|
6049
|
+
key,
|
|
6050
|
+
direction: "descending"
|
|
6051
|
+
};
|
|
6052
|
+
return (options.sortCycle ?? "tri-state") === "toggle" ? {
|
|
6053
|
+
key,
|
|
6054
|
+
direction: "ascending"
|
|
6055
|
+
} : null;
|
|
6056
|
+
};
|
|
6057
|
+
const toggleRow = (id) => {
|
|
6058
|
+
const mode = selectionMode();
|
|
6059
|
+
if (mode === "none") return;
|
|
6060
|
+
const current = selected();
|
|
6061
|
+
const has = current.includes(id);
|
|
6062
|
+
requestSelection(mode === "single" ? has ? [] : [id] : has ? current.filter((value) => value !== id) : [...current, id]);
|
|
6063
|
+
};
|
|
6064
|
+
const rows = () => options.rows;
|
|
6065
|
+
const allSelected = () => {
|
|
6066
|
+
const every = rows();
|
|
6067
|
+
return every.length > 0 && every.every(isSelected);
|
|
6068
|
+
};
|
|
6069
|
+
const someSelected = () => rows().some(isSelected);
|
|
6070
|
+
const toggleAll = () => {
|
|
6071
|
+
if (selectionMode() !== "multiple") return;
|
|
6072
|
+
const current = selected();
|
|
6073
|
+
if (allSelected()) {
|
|
6074
|
+
requestSelection(current.filter((id) => !rows().includes(id)));
|
|
6075
|
+
return;
|
|
6076
|
+
}
|
|
6077
|
+
requestSelection(normalize$1([...current, ...rows()]));
|
|
6078
|
+
};
|
|
6079
|
+
const keyedToggle = (toggle) => (event) => {
|
|
6080
|
+
if (!isToggleKey(event)) return;
|
|
6081
|
+
event.preventDefault();
|
|
6082
|
+
toggle();
|
|
6083
|
+
};
|
|
6084
|
+
const selectAll = () => {
|
|
6085
|
+
if (selectionMode() !== "multiple") return;
|
|
6086
|
+
return {
|
|
6087
|
+
role: "checkbox",
|
|
6088
|
+
get "aria-checked"() {
|
|
6089
|
+
return allSelected() ? "true" : someSelected() ? "mixed" : "false";
|
|
6090
|
+
},
|
|
6091
|
+
get "aria-label"() {
|
|
6092
|
+
return options.labels?.selectAll ?? "Select all rows";
|
|
6093
|
+
},
|
|
6094
|
+
tabindex: 0,
|
|
6095
|
+
onClick: () => {
|
|
6096
|
+
toggleAll();
|
|
6097
|
+
},
|
|
6098
|
+
onKeyDown: keyedToggle(toggleAll)
|
|
6099
|
+
};
|
|
6100
|
+
};
|
|
6101
|
+
const rowCheckbox = (id) => {
|
|
6102
|
+
if (!selectable()) return;
|
|
6103
|
+
return {
|
|
6104
|
+
role: "checkbox",
|
|
6105
|
+
get "aria-checked"() {
|
|
6106
|
+
return isSelected(id) ? "true" : "false";
|
|
6107
|
+
},
|
|
6108
|
+
get "aria-label"() {
|
|
6109
|
+
return options.labels?.selectRow?.(id) ?? `Select row ${id}`;
|
|
6110
|
+
},
|
|
6111
|
+
tabindex: 0,
|
|
6112
|
+
onClick: (event) => {
|
|
6113
|
+
event.stopPropagation();
|
|
6114
|
+
toggleRow(id);
|
|
6115
|
+
},
|
|
6116
|
+
onKeyDown: keyedToggle(() => toggleRow(id))
|
|
6117
|
+
};
|
|
6118
|
+
};
|
|
6119
|
+
return {
|
|
6120
|
+
selectionMode,
|
|
6121
|
+
sort,
|
|
6122
|
+
selected,
|
|
6123
|
+
isSelected,
|
|
6124
|
+
tableProps: {
|
|
6125
|
+
get "aria-label"() {
|
|
6126
|
+
return options.labels?.table;
|
|
6127
|
+
},
|
|
6128
|
+
get "aria-rowcount"() {
|
|
6129
|
+
return options.rowCount;
|
|
6130
|
+
},
|
|
6131
|
+
get "aria-colcount"() {
|
|
6132
|
+
return options.columnCount;
|
|
6133
|
+
}
|
|
6134
|
+
},
|
|
6135
|
+
captionProps: { id: `${base}-caption` },
|
|
6136
|
+
headerCellProps: (key) => ({
|
|
6137
|
+
scope: "col",
|
|
6138
|
+
get "aria-sort"() {
|
|
6139
|
+
const current = rawSort();
|
|
6140
|
+
return current !== null && current.key === key && isSortable(key) ? current.direction : void 0;
|
|
6141
|
+
},
|
|
6142
|
+
get abbr() {
|
|
6143
|
+
return columnOf(key)?.abbr;
|
|
6144
|
+
}
|
|
6145
|
+
}),
|
|
6146
|
+
headerButtonProps: (key) => {
|
|
6147
|
+
if (!isSortable(key)) return;
|
|
6148
|
+
return {
|
|
6149
|
+
type: "button",
|
|
6150
|
+
onClick: () => {
|
|
6151
|
+
requestSort(nextSort(key));
|
|
6152
|
+
}
|
|
6153
|
+
};
|
|
6154
|
+
},
|
|
6155
|
+
rowProps: (id) => ({
|
|
6156
|
+
get "aria-selected"() {
|
|
6157
|
+
if (!selectable()) return;
|
|
6158
|
+
return isSelected(id) ? "true" : "false";
|
|
6159
|
+
},
|
|
6160
|
+
get onClick() {
|
|
6161
|
+
return selectable() ? () => toggleRow(id) : void 0;
|
|
6162
|
+
}
|
|
6163
|
+
}),
|
|
6164
|
+
cellProps: (_rowId, key) => ({ get "aria-colindex"() {
|
|
6165
|
+
if (options.columnCount === void 0) return;
|
|
6166
|
+
const index = options.columns.findIndex((column) => column.key === key);
|
|
6167
|
+
return index < 0 ? void 0 : index + 1;
|
|
6168
|
+
} }),
|
|
6169
|
+
get selectAllProps() {
|
|
6170
|
+
return selectAll();
|
|
6171
|
+
},
|
|
6172
|
+
rowCheckboxProps: (id) => rowCheckbox(id),
|
|
6173
|
+
toggleAll,
|
|
6174
|
+
toggleRow
|
|
6175
|
+
};
|
|
6176
|
+
};
|
|
5825
6177
|
// src/textbox.ts
|
|
5826
6178
|
const control = (field, options) => ({
|
|
5827
6179
|
...field.controlProps,
|
|
@@ -8009,4 +8361,4 @@ const createRearrangeableListbox = (options) => {
|
|
|
8009
8361
|
})
|
|
8010
8362
|
};
|
|
8011
8363
|
};
|
|
8012
|
-
export { ConfirmPendingError, DEFAULT_PREFS, DRAG_PX, GRID, NO_POS, SNAP_PX, TONE, TREEVIEW_NODES, TWEEN_TICKS, WORLD_BOUND, YES_POS, ZMAX, ZMIN, ZONE, cellPart, createAccordion, createAlert, createAlertDialog, createBreadcrumb, createButton, createCanvas, createCarousel, createCheckbox, createCheckboxGroup, createCombobox, createConfirm, createDialogModal, createDisclosure, createFeed, createField, createGrid, createLink, createListbox, createMenu, createMenubar, createMeter, createPagination, createPlayer, createPopover, createRadioGroup, createRearrangeableListbox, createResizablePanels, createSlider, createSliderMultiThumb, createSpinbutton, createStatus, createSwitch, createTabs, createTextArea, createTextInput, createTimeline, createToast, createToolbar, createTooltipGroup, createTreegrid, createTreeview, createWindowSplitter, gridCandidates, headerPart, packSelection, packSort, rowPart, treegridCellPart, treegridFocusTargetPart, treegridRowPart, withPrefs };
|
|
8364
|
+
export { ConfirmPendingError, DEFAULT_PREFS, DRAG_PX, GRID, NO_POS, SNAP_PX, TONE, TREEVIEW_NODES, TWEEN_TICKS, WORLD_BOUND, YES_POS, ZMAX, ZMIN, ZONE, cellPart, createAccordion, createAlert, createAlertDialog, createBreadcrumb, createButton, createCanvas, createCarousel, createCheckbox, createCheckboxGroup, createCombobox, createConfirm, createDialogModal, createDisclosure, createDrawer, createFeed, createField, createGrid, createLink, createListbox, createMenu, createMenubar, createMeter, createPagination, createPlayer, createPopover, createRadioGroup, createRearrangeableListbox, createResizablePanels, createSlider, createSliderMultiThumb, createSpinbutton, createStatus, createSwitch, createTable, createTabs, createTextArea, createTextInput, createTimeline, createToast, createToolbar, createTooltipGroup, createTreegrid, createTreeview, createWindowSplitter, gridCandidates, headerPart, packSelection, packSort, rowPart, treegridCellPart, treegridFocusTargetPart, treegridRowPart, withPrefs };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cssints/headless",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Headless APG widgets on Solid 2: state plus attribute objects, no elements, no styling, each conformance-checked against its Quint spec",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|