@gridkitjs/forms-dom 0.0.0-dev-20261206092422 → 0.0.0-dev-20261206115313
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/dist/index.d.ts +261 -2
- package/dist/index.js +771 -22
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import { WritingDirection, VisibleRange, Schedule, StepDirection, StepSize,
|
|
1
|
+
import { AbortFactory, TypeaheadRow, DisabledOptions, PopupOpenReason, PopupCloseReason, FieldController, FormsMessages, WritingDirection, VisibleRange, Schedule, StepDirection, StepSize, SegmentContext, SegmentState } from '@gridkitjs/forms-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The browser's `AbortController` as a forms-core `AbortFactory`: each call
|
|
5
|
+
* makes a fresh signal and the function that aborts it, for an option
|
|
6
|
+
* source controller to hand each request.
|
|
7
|
+
*/
|
|
8
|
+
declare const abortSignals: AbortFactory<AbortSignal>;
|
|
2
9
|
|
|
3
10
|
/** A live region to report changes through. */
|
|
4
11
|
interface LiveAnnouncer {
|
|
@@ -191,6 +198,258 @@ interface AttachedChecklist {
|
|
|
191
198
|
*/
|
|
192
199
|
declare function attachChecklist(list: HTMLElement, options: ChecklistOptions): AttachedChecklist;
|
|
193
200
|
|
|
201
|
+
/**
|
|
202
|
+
* How the active row is shown to assistive technology:
|
|
203
|
+
* `"active-descendant"` keeps focus on a combobox, whose
|
|
204
|
+
* `aria-activedescendant` points at the row; `"roving"` gives the active
|
|
205
|
+
* row focus, the list's one tab stop.
|
|
206
|
+
*/
|
|
207
|
+
type ListboxFocus = "active-descendant" | "roving";
|
|
208
|
+
/** What the listbox needs of each row, mounted or not. */
|
|
209
|
+
interface ListboxRow extends TypeaheadRow {
|
|
210
|
+
/**
|
|
211
|
+
* What identifies the row across changes of the list: an option's key
|
|
212
|
+
* as text, or the action's kind. The active row is kept by it.
|
|
213
|
+
*/
|
|
214
|
+
readonly key: string;
|
|
215
|
+
}
|
|
216
|
+
/** What a choice asks for. */
|
|
217
|
+
type ListboxChoice =
|
|
218
|
+
/** Enter or a click with one value; Space in a popup or with one value. */
|
|
219
|
+
{
|
|
220
|
+
readonly kind: "one";
|
|
221
|
+
}
|
|
222
|
+
/** Enter, Space or a click with several values; Ctrl or Cmd with a click. */
|
|
223
|
+
| {
|
|
224
|
+
readonly kind: "toggle";
|
|
225
|
+
}
|
|
226
|
+
/** Several values: every row from `anchor` to the chosen one. */
|
|
227
|
+
| {
|
|
228
|
+
readonly kind: "range";
|
|
229
|
+
readonly anchor: number;
|
|
230
|
+
}
|
|
231
|
+
/** Ctrl+A with several values. */
|
|
232
|
+
| {
|
|
233
|
+
readonly kind: "all";
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* What made a row active: a key, the mouse, the renderer as the search
|
|
237
|
+
* text changed (`"typing"`) or as the popup opened (`"open"`), or the list
|
|
238
|
+
* changing under the active row (`"list"`).
|
|
239
|
+
*/
|
|
240
|
+
type ListboxActivation = "keyboard" | "pointer" | "typing" | "open" | "list";
|
|
241
|
+
/** How a row is brought into view: by as little as it takes, or to the middle. */
|
|
242
|
+
type ListboxAlign = "nearest" | "center";
|
|
243
|
+
interface ListboxOptions {
|
|
244
|
+
readonly focus: ListboxFocus;
|
|
245
|
+
/** Several values: Space and clicks toggle, Shift ranges, Ctrl+A chooses all. */
|
|
246
|
+
readonly multiple: boolean;
|
|
247
|
+
/** Printable keys find a row by its label; off where a text box takes them. */
|
|
248
|
+
readonly typeahead: boolean;
|
|
249
|
+
/** The locale the typed text is folded in, as the rows' `typeahead` was. */
|
|
250
|
+
readonly locale?: Intl.LocalesArgument;
|
|
251
|
+
/** Whether the keys reach disabled options. Default `"skip"`. */
|
|
252
|
+
readonly disabledOptions?: DisabledOptions | undefined;
|
|
253
|
+
/** With one value, a key that moves the active row also chooses it. */
|
|
254
|
+
readonly selectionFollowsFocus?: boolean | undefined;
|
|
255
|
+
readonly onActiveChange: (index: number | null, by: ListboxActivation) => void;
|
|
256
|
+
/** A row is chosen. Never a header or a disabled row. */
|
|
257
|
+
readonly onChoose: (index: number, choice: ListboxChoice, nativeEvent: Event) => void;
|
|
258
|
+
/**
|
|
259
|
+
* Brings row `index` into view, mounting it if the list's window does
|
|
260
|
+
* not hold it: a virtualized renderer forwards this to its virtualizer's
|
|
261
|
+
* `scrollToIndex` with `block` set to `align`.
|
|
262
|
+
*/
|
|
263
|
+
readonly scrollToIndex: (index: number, align: ListboxAlign) => void;
|
|
264
|
+
/**
|
|
265
|
+
* One of the last five rows mounted or became active: time to load the
|
|
266
|
+
* next page. Called once for each length of the list.
|
|
267
|
+
*/
|
|
268
|
+
readonly onNearEnd?: (() => void) | undefined;
|
|
269
|
+
}
|
|
270
|
+
interface AttachedListbox {
|
|
271
|
+
/** The list element it was attached to. */
|
|
272
|
+
readonly element: HTMLElement;
|
|
273
|
+
/**
|
|
274
|
+
* Every row, mounted or not; call after each change of the list. The
|
|
275
|
+
* active row is kept by `key`, else it moves to the nearest row it can
|
|
276
|
+
* land on, and `onActiveChange` hears it with `"list"`.
|
|
277
|
+
*/
|
|
278
|
+
readonly setRows: (rows: readonly ListboxRow[]) => void;
|
|
279
|
+
/** Replaces the options, from the next event on. */
|
|
280
|
+
readonly setOptions: (options: ListboxOptions) => void;
|
|
281
|
+
/**
|
|
282
|
+
* Makes row `index` active and scrolls to it (to the middle when `by` is
|
|
283
|
+
* `"open"`, not at all when it is `"pointer"`); in roving mode it also
|
|
284
|
+
* takes focus, once mounted. `null` clears the active row.
|
|
285
|
+
*/
|
|
286
|
+
readonly activate: (index: number | null, by: ListboxActivation) => void;
|
|
287
|
+
/**
|
|
288
|
+
* Active-descendant mode: a key pressed in the combobox. True when the
|
|
289
|
+
* listbox acted on it, and then the key is prevented.
|
|
290
|
+
*/
|
|
291
|
+
readonly handleKey: (event: KeyboardEvent) => boolean;
|
|
292
|
+
/** Chooses the active row as Enter with one value would; false when none can be. */
|
|
293
|
+
readonly chooseActive: (nativeEvent: Event) => boolean;
|
|
294
|
+
readonly getActive: () => number | null;
|
|
295
|
+
/** The active row's `id` while it is mounted, else `null`: what `aria-activedescendant` holds. */
|
|
296
|
+
readonly activeId: () => string | null;
|
|
297
|
+
/** Calls `listener` whenever `activeId()` may have changed. */
|
|
298
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
299
|
+
/**
|
|
300
|
+
* Removes every listener, the observer and the type-ahead timer; every
|
|
301
|
+
* method does nothing after it. The rows keep their `tabindex`.
|
|
302
|
+
*/
|
|
303
|
+
readonly detach: () => void;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Makes `list`, a `role="listbox"` the renderer drew (usually virtualized,
|
|
307
|
+
* so only a window of a long list is mounted), behave as the WAI-ARIA
|
|
308
|
+
* listbox: the arrow keys, Home, End, PageUp and PageDown move the active
|
|
309
|
+
* row, stopping at the ends; printable keys find a row by its label; Enter,
|
|
310
|
+
* Space and clicks choose; with several values Shift ranges and Ctrl+A
|
|
311
|
+
* chooses all. It decides; the renderer is told through the callbacks and
|
|
312
|
+
* draws the outcome, `aria-selected` or `aria-checked` included.
|
|
313
|
+
*
|
|
314
|
+
* Rows are the list's descendants with `data-gridkit-forms-row` holding
|
|
315
|
+
* their place in the whole list, which is all that survives a row being
|
|
316
|
+
* unmounted and mounted again; `setRows` describes every row, mounted or
|
|
317
|
+
* not. Headers are never active, and disabled options only with
|
|
318
|
+
* `disabledOptions: "focus"`; neither is ever chosen. The list is the
|
|
319
|
+
* element that scrolls: PageUp and PageDown move by as many rows as it
|
|
320
|
+
* shows whole.
|
|
321
|
+
*
|
|
322
|
+
* In `"active-descendant"` mode focus stays in a combobox, which hands its
|
|
323
|
+
* keys to `handleKey` (`attachCombobox` does) and points
|
|
324
|
+
* `aria-activedescendant` at `activeId()`, so rows need an `id`. The mouse
|
|
325
|
+
* moving over a row makes it active (a touch does not, so nothing lights
|
|
326
|
+
* up before a tap), and a click chooses. A move key while the active row
|
|
327
|
+
* is scrolled out of the window first scrolls back to it.
|
|
328
|
+
*
|
|
329
|
+
* In `"roving"` mode the active row holds focus and is the one row with
|
|
330
|
+
* `tabindex="0"` (the first mounted row it can land on while none is
|
|
331
|
+
* active or the active one is scrolled away), kept so by an observer as
|
|
332
|
+
* rows mount. Enter is left for a form around the list. A click chooses
|
|
333
|
+
* and focuses, Ctrl or Cmd with a click toggles, Shift with a click
|
|
334
|
+
* ranges.
|
|
335
|
+
*
|
|
336
|
+
* The list itself gets `tabindex="-1"` in both modes: a browser may make
|
|
337
|
+
* an element that scrolls a tab stop of its own, as Firefox does.
|
|
338
|
+
*/
|
|
339
|
+
declare function attachListbox(list: HTMLElement, initialOptions: ListboxOptions): AttachedListbox;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* What `attachCombobox` asks of the field: a select-only control has no
|
|
343
|
+
* text pipeline, so it starts, commits, ends and reverts the edit itself.
|
|
344
|
+
*/
|
|
345
|
+
type ComboboxController<V, D extends object> = Pick<FieldController<V, D, Event>, "focus" | "blur" | "commit" | "revert">;
|
|
346
|
+
/** What a renderer can change about a combobox while it is attached. */
|
|
347
|
+
interface ComboboxOptions {
|
|
348
|
+
/** The open popup's listbox, attached in `"active-descendant"` mode; `null` while closed. */
|
|
349
|
+
readonly listbox: AttachedListbox | null;
|
|
350
|
+
/** The popup panel while open, so a press in it leaves focus in the control. */
|
|
351
|
+
readonly panel: HTMLElement | null;
|
|
352
|
+
/**
|
|
353
|
+
* A text box (a searchable select, an autocomplete, a tag input), which
|
|
354
|
+
* `attachTextInput` drives and keeps its typing, Home, End and Space; or
|
|
355
|
+
* a select-only button, whose keys all go to the list.
|
|
356
|
+
*/
|
|
357
|
+
readonly editable: boolean;
|
|
358
|
+
/** Several values: Shift with the arrows and Ctrl+A reach a select-only list. */
|
|
359
|
+
readonly multiple: boolean;
|
|
360
|
+
/** Tab with the popup open chooses the active row, with one value. */
|
|
361
|
+
readonly tabChooses: boolean;
|
|
362
|
+
/** Nothing opens the popup. */
|
|
363
|
+
readonly readOnly: boolean;
|
|
364
|
+
readonly onOpenRequest: (reason: PopupOpenReason, nativeEvent: Event) => void;
|
|
365
|
+
readonly onCloseRequest: (reason: PopupCloseReason, nativeEvent: Event) => void;
|
|
366
|
+
/**
|
|
367
|
+
* The chips before the text: the key toward them (←, or → right to left)
|
|
368
|
+
* at the start of the text, or Backspace with no text.
|
|
369
|
+
*/
|
|
370
|
+
readonly onChipKey?: ((key: "previous" | "remove-last", nativeEvent: KeyboardEvent) => void) | undefined;
|
|
371
|
+
}
|
|
372
|
+
interface AttachedCombobox {
|
|
373
|
+
/** Replaces the options: the latest listbox and panel, after each open and close. */
|
|
374
|
+
readonly setOptions: (options: ComboboxOptions) => void;
|
|
375
|
+
/**
|
|
376
|
+
* Removes every listener and the `aria-controls` and
|
|
377
|
+
* `aria-activedescendant` it wrote. The controller is left as it is.
|
|
378
|
+
*/
|
|
379
|
+
readonly detach: () => void;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Makes `control`, a `role="combobox"` the renderer drew (a text box or a
|
|
383
|
+
* select-only button), drive the popup listbox of the WAI-ARIA combobox:
|
|
384
|
+
* focus stays in the control, and its keys open the popup, move the list's
|
|
385
|
+
* active row and choose.
|
|
386
|
+
*
|
|
387
|
+
* - Closed, ↓, ↑, F4 and Alt+↓ ask to open it (`"keyboard"`); a
|
|
388
|
+
* select-only control also opens on Enter, Space, Home and End, and on a
|
|
389
|
+
* printable key (`"typing"`), which goes on to the list's type-ahead
|
|
390
|
+
* once it is open. A text box opens as it is typed in (`"typing"`), and
|
|
391
|
+
* either opens on a press (`"button"`).
|
|
392
|
+
* - Open, the keys go to `listbox.handleKey`: in a text box only ↓, ↑,
|
|
393
|
+
* PageDown, PageUp and Enter (Home and End move the caret and clear the
|
|
394
|
+
* active row, as the WAI-ARIA editable combobox does). Escape asks to
|
|
395
|
+
* close (`"escape"`), F4 and Alt+↑ too (`"button"`), and so does a press
|
|
396
|
+
* on a select-only control. Tab leaves, choosing the active row first
|
|
397
|
+
* with `tabChooses`, and asks to close (`"blur"`), as leaving does.
|
|
398
|
+
* - It listens in the capture phase, so a key it takes is prevented before
|
|
399
|
+
* `attachTextInput` sees it and skips it.
|
|
400
|
+
* - A select-only control calls the controller's `focus` and `blur`,
|
|
401
|
+
* commits on Tab (staying when the commit is refused), and reverts on
|
|
402
|
+
* Escape while closed. A text box leaves those to `attachTextInput`.
|
|
403
|
+
* - It prevents `mousedown` on the panel, which keeps focus in the control
|
|
404
|
+
* and still lets the click through (WebKit sends no click after a tap
|
|
405
|
+
* whose `pointerdown` was prevented).
|
|
406
|
+
*
|
|
407
|
+
* It writes `aria-expanded`, `aria-controls` (the listbox's `id`) and
|
|
408
|
+
* `aria-activedescendant` (the active row's `id` while it is mounted) on
|
|
409
|
+
* the control.
|
|
410
|
+
*/
|
|
411
|
+
declare function attachCombobox<V, D extends object>(control: HTMLElement, controller: ComboboxController<V, D>, initialOptions: ComboboxOptions): AttachedCombobox;
|
|
412
|
+
|
|
413
|
+
interface ChoiceAnnouncerOptions {
|
|
414
|
+
/** Where `resultCount`, `noMatches` and `selectedCount` come from. */
|
|
415
|
+
readonly messages: Pick<FormsMessages, "resultCount" | "noMatches" | "selectedCount">;
|
|
416
|
+
/**
|
|
417
|
+
* Milliseconds the results must stay unchanged before they are read,
|
|
418
|
+
* so typing hears one count when it pauses, not one per key. Default 500.
|
|
419
|
+
*/
|
|
420
|
+
readonly settleDelay?: number | undefined;
|
|
421
|
+
/** The live region's class, `"gridkit-forms-sr-only"` by default. */
|
|
422
|
+
readonly className?: string | undefined;
|
|
423
|
+
}
|
|
424
|
+
interface ChoiceAnnouncer {
|
|
425
|
+
/**
|
|
426
|
+
* The list shows `count` options for `query`: read as `resultCount` or
|
|
427
|
+
* `noMatches` once it has stayed so for `settleDelay`, unless it is
|
|
428
|
+
* what was read last for the same query.
|
|
429
|
+
*/
|
|
430
|
+
readonly results: (query: string, count: number) => void;
|
|
431
|
+
/** An option was ticked or unticked: `selectedCount`, read at once. */
|
|
432
|
+
readonly selected: (count: number) => void;
|
|
433
|
+
/** Any other text, read at once. */
|
|
434
|
+
readonly announce: (text: string) => void;
|
|
435
|
+
/**
|
|
436
|
+
* The list closed: drops results still settling, and forgets the last
|
|
437
|
+
* read, so the next open reads its count again.
|
|
438
|
+
*/
|
|
439
|
+
readonly cancel: () => void;
|
|
440
|
+
/** Replaces the options, from the next call on. */
|
|
441
|
+
readonly setOptions: (options: ChoiceAnnouncerOptions) => void;
|
|
442
|
+
/** Drops what is settling and removes the live region. */
|
|
443
|
+
readonly destroy: () => void;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* A polite live region in `container` for what a choice list says that no
|
|
447
|
+
* visual cue carries to a screen reader: how many options a search found,
|
|
448
|
+
* how many are ticked. The active option is not announced: the screen
|
|
449
|
+
* reader reads it from `aria-activedescendant` or focus.
|
|
450
|
+
*/
|
|
451
|
+
declare function createChoiceAnnouncer(container: HTMLElement, initialOptions: ChoiceAnnouncerOptions): ChoiceAnnouncer;
|
|
452
|
+
|
|
194
453
|
/** Which side of its anchor an overlay opens on. */
|
|
195
454
|
type OverlaySide = "top" | "bottom" | "left" | "right";
|
|
196
455
|
/**
|
|
@@ -808,4 +1067,4 @@ declare function attachSegments<V, D extends object>(group: HTMLElement, control
|
|
|
808
1067
|
*/
|
|
809
1068
|
declare function writingDirection(element: Element): WritingDirection;
|
|
810
1069
|
|
|
811
|
-
export { type AttachedAutoGrow, type AttachedChecklist, type AttachedFitCount, type AttachedFocusGroup, type AttachedHoldRepeat, type AttachedSegments, type AttachedStepKeys, type AttachedTextInput, type AttachedToggle, type AutoGrowOptions, type ChecklistOptions, type FitCountOptions, type FocusGroupOptions, type HoldRepeatOptions, type HoldRepeatState, type LiveAnnouncer, type LiveAnnouncerOptions, type OverlayAlign, type OverlayAnchor, type OverlayDismissReason, type OverlayInitialFocus, type OverlayOptions, type OverlayPlacement, type OverlayPlacementOptions, type OverlayPosition, type OverlayRect, type OverlaySide, type OverlaySize, type RowVirtualizer, type RowVirtualizerOptions, type SegmentsController, type SegmentsOptions, type StepKeysOptions, type TextControl, type TextInputController, type TextInputOptions, type ToggleOptions, attachAutoGrow, attachChecklist, attachEnterNavigation, attachFitCount, attachFocusGroup, attachHoldRepeat, attachOverlay, attachSegments, attachStepKeys, attachTextInput, attachToggle, compareDocumentOrder, createLiveAnnouncer, createRowVirtualizer, findFirstInvalidControl, focusTargetIn, placeOverlay, scheduleTimeout, writingDirection };
|
|
1070
|
+
export { type AttachedAutoGrow, type AttachedChecklist, type AttachedCombobox, type AttachedFitCount, type AttachedFocusGroup, type AttachedHoldRepeat, type AttachedListbox, type AttachedSegments, type AttachedStepKeys, type AttachedTextInput, type AttachedToggle, type AutoGrowOptions, type ChecklistOptions, type ChoiceAnnouncer, type ChoiceAnnouncerOptions, type ComboboxController, type ComboboxOptions, type FitCountOptions, type FocusGroupOptions, type HoldRepeatOptions, type HoldRepeatState, type ListboxActivation, type ListboxAlign, type ListboxChoice, type ListboxFocus, type ListboxOptions, type ListboxRow, type LiveAnnouncer, type LiveAnnouncerOptions, type OverlayAlign, type OverlayAnchor, type OverlayDismissReason, type OverlayInitialFocus, type OverlayOptions, type OverlayPlacement, type OverlayPlacementOptions, type OverlayPosition, type OverlayRect, type OverlaySide, type OverlaySize, type RowVirtualizer, type RowVirtualizerOptions, type SegmentsController, type SegmentsOptions, type StepKeysOptions, type TextControl, type TextInputController, type TextInputOptions, type ToggleOptions, abortSignals, attachAutoGrow, attachChecklist, attachCombobox, attachEnterNavigation, attachFitCount, attachFocusGroup, attachHoldRepeat, attachListbox, attachOverlay, attachSegments, attachStepKeys, attachTextInput, attachToggle, compareDocumentOrder, createChoiceAnnouncer, createLiveAnnouncer, createRowVirtualizer, findFirstInvalidControl, focusTargetIn, placeOverlay, scheduleTimeout, writingDirection };
|