@gridkitjs/forms-dom 0.0.0-dev-20261206092422
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/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/index.d.ts +811 -0
- package/dist/index.js +2326 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+
import { WritingDirection, VisibleRange, Schedule, StepDirection, StepSize, FieldController, SegmentContext, FormsMessages, SegmentState } from '@gridkitjs/forms-core';
|
|
2
|
+
|
|
3
|
+
/** A live region to report changes through. */
|
|
4
|
+
interface LiveAnnouncer {
|
|
5
|
+
/**
|
|
6
|
+
* Has assistive technology read `text` out, politely — after whatever it is
|
|
7
|
+
* already saying. The same text twice in a row is read twice.
|
|
8
|
+
*/
|
|
9
|
+
readonly announce: (text: string) => void;
|
|
10
|
+
/** Removes the live region. */
|
|
11
|
+
readonly destroy: () => void;
|
|
12
|
+
}
|
|
13
|
+
interface LiveAnnouncerOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The class on the live region, which the stylesheet clips to nothing
|
|
16
|
+
* while leaving it in the accessibility tree. Defaults to
|
|
17
|
+
* `"gridkit-forms-sr-only"`, which forms.css defines.
|
|
18
|
+
*/
|
|
19
|
+
readonly className?: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates a live region to report through — a reorder, a resize, a bulk
|
|
23
|
+
* selection, anything no visual cue can carry to a screen reader — as the
|
|
24
|
+
* last child of `container`.
|
|
25
|
+
*
|
|
26
|
+
* Polite rather than assertive, so an announcement waits for a pause instead
|
|
27
|
+
* of cutting across what the user is already hearing. The element carries
|
|
28
|
+
* `options.className`, a visually hidden class.
|
|
29
|
+
*
|
|
30
|
+
* A live region speaks only when its text changes, so a message identical to
|
|
31
|
+
* the last would go unheard. A no-break space, added and dropped in turn,
|
|
32
|
+
* makes the repeat a change without changing what is read.
|
|
33
|
+
*/
|
|
34
|
+
declare function createLiveAnnouncer(container?: HTMLElement, options?: LiveAnnouncerOptions): LiveAnnouncer;
|
|
35
|
+
|
|
36
|
+
interface FocusGroupOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Focus left the group: by Tab or Shift+Tab (`"tab"`), or any other way
|
|
39
|
+
* (`"blur"`), the window losing focus included.
|
|
40
|
+
*/
|
|
41
|
+
readonly onLeave: (by: "tab" | "blur", nativeEvent: FocusEvent) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Whether `node`, outside the group's root, still counts as inside the
|
|
44
|
+
* group: a popup the input opened, portalled to the body. Focus moving
|
|
45
|
+
* there is not a leave; focus moving on from there to anywhere that is
|
|
46
|
+
* neither the root nor inside is.
|
|
47
|
+
*/
|
|
48
|
+
readonly isInside?: ((node: Node) => boolean) | undefined;
|
|
49
|
+
}
|
|
50
|
+
interface AttachedFocusGroup {
|
|
51
|
+
/** Replaces the options, from the next event on. */
|
|
52
|
+
readonly setOptions: (options: FocusGroupOptions) => void;
|
|
53
|
+
/** Removes every listener. */
|
|
54
|
+
readonly detach: () => void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Tells focus moving between the controls inside `root` (the two ends of
|
|
58
|
+
* a range) from focus leaving it, which a control's own blur cannot: a
|
|
59
|
+
* `focusout` whose `relatedTarget` is outside `root`, or none, leaves the
|
|
60
|
+
* group. A Tab that nothing prevented, pressed in the group just before,
|
|
61
|
+
* makes it a leave by Tab.
|
|
62
|
+
*
|
|
63
|
+
* Focus moving to a node `isInside` names (a popup outside `root`) is not
|
|
64
|
+
* a leave. While focus is out there, the group follows it on the document:
|
|
65
|
+
* back into `root` it is home again, and anywhere else that is not inside
|
|
66
|
+
* leaves the group.
|
|
67
|
+
*
|
|
68
|
+
* It holds whether the last key pressed in the group was such a Tab,
|
|
69
|
+
* cleared by the next `focusout`, key or pointer press, and, while focus
|
|
70
|
+
* is in a node `isInside` names, the document listeners that follow it.
|
|
71
|
+
*/
|
|
72
|
+
declare function attachFocusGroup(root: HTMLElement, initialOptions: FocusGroupOptions): AttachedFocusGroup;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The first control of `form`, in document order, that holds an invalid
|
|
76
|
+
* value: a field showing an error, which forms sets as the control's
|
|
77
|
+
* custom validity, or a native constraint of the app's own control such as
|
|
78
|
+
* `required`. `null` when every control is valid. A disabled or read-only
|
|
79
|
+
* control is never invalid, as for the browser's own validation.
|
|
80
|
+
*/
|
|
81
|
+
declare function findFirstInvalidControl(form: HTMLFormElement): HTMLElement | null;
|
|
82
|
+
/**
|
|
83
|
+
* The control a link to `target` should focus: `target` itself when it can
|
|
84
|
+
* take focus, else the first control inside it, as for a group of inputs.
|
|
85
|
+
*/
|
|
86
|
+
declare function focusTargetIn(target: HTMLElement): HTMLElement | null;
|
|
87
|
+
/**
|
|
88
|
+
* Makes Enter in a single-line text field, a checkbox or a switch of
|
|
89
|
+
* `form` move focus to the next control a user can change, in document
|
|
90
|
+
* order, rather than submit the form. From the last one, Enter submits as
|
|
91
|
+
* it would without this. Enter with a modifier, while an input method is
|
|
92
|
+
* composing, or already handled (a field refusing its commit prevents it)
|
|
93
|
+
* is left alone, as are a textarea, a select, a button and a link.
|
|
94
|
+
* `detach` removes the listener.
|
|
95
|
+
*/
|
|
96
|
+
declare function attachEnterNavigation(form: HTMLFormElement): {
|
|
97
|
+
readonly detach: () => void;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Orders two elements as they come in the document, for sorting: negative
|
|
101
|
+
* when `a` comes first.
|
|
102
|
+
*/
|
|
103
|
+
declare function compareDocumentOrder(a: Node, b: Node): number;
|
|
104
|
+
|
|
105
|
+
interface FitCountOptions {
|
|
106
|
+
/** The most items wanted side by side. */
|
|
107
|
+
readonly max: number;
|
|
108
|
+
/** Called with the count now, and again whenever it changes. */
|
|
109
|
+
readonly onCount: (count: number) => void;
|
|
110
|
+
}
|
|
111
|
+
interface AttachedFitCount {
|
|
112
|
+
/** Stops watching. */
|
|
113
|
+
readonly detach: () => void;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Counts how many items as wide as `root`'s first child fit side by side
|
|
117
|
+
* in the element around `root`, `root`'s column gap between them, from 1
|
|
118
|
+
* to `max`: how many months a range calendar shows. It recounts whenever
|
|
119
|
+
* that element or the item changes width (a `ResizeObserver`), and calls
|
|
120
|
+
* `onCount` only when the count changes.
|
|
121
|
+
*
|
|
122
|
+
* It holds the observer and the last count; `detach` disconnects it.
|
|
123
|
+
*/
|
|
124
|
+
declare function attachFitCount(root: HTMLElement, { max, onCount }: FitCountOptions): AttachedFitCount;
|
|
125
|
+
|
|
126
|
+
interface ChecklistOptions {
|
|
127
|
+
/**
|
|
128
|
+
* The item at `index` — its place in the whole list — asks to be checked
|
|
129
|
+
* or unchecked: Space on it, or a click. The caller flips it in its own
|
|
130
|
+
* state and draws the new `aria-checked`.
|
|
131
|
+
*/
|
|
132
|
+
readonly onToggle: (index: number) => void;
|
|
133
|
+
/** Focus moved to the item at `index`, by a key, a click or a script. */
|
|
134
|
+
readonly onFocusChange?: ((index: number) => void) | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Bring the item at `index` into view, mounting it if the list's window
|
|
137
|
+
* does not hold it. A virtualized renderer forwards this to its
|
|
138
|
+
* virtualizer's `scrollToIndex`, with `{ block: "nearest" }` so a move of
|
|
139
|
+
* one item scrolls by one item.
|
|
140
|
+
*/
|
|
141
|
+
readonly scrollToIndex: (index: number) => void;
|
|
142
|
+
}
|
|
143
|
+
interface AttachedChecklist {
|
|
144
|
+
/**
|
|
145
|
+
* How many items the whole list holds, mounted or not. Starts at 0, so a
|
|
146
|
+
* renderer calls this straight after attaching, and again whenever the
|
|
147
|
+
* list changes — a search narrowing it, say. A focused place past the new
|
|
148
|
+
* end moves back to the last item, and so does a move still waiting for
|
|
149
|
+
* an item past it.
|
|
150
|
+
*/
|
|
151
|
+
readonly setCount: (count: number) => void;
|
|
152
|
+
/**
|
|
153
|
+
* Focuses the item at `index`, clamped to the list, scrolling to it first.
|
|
154
|
+
* An item outside the mounted window is focused once it mounts.
|
|
155
|
+
*/
|
|
156
|
+
readonly focusItem: (index: number) => void;
|
|
157
|
+
/**
|
|
158
|
+
* Removes every listener and observer. The list and its items keep their
|
|
159
|
+
* `tabindex`.
|
|
160
|
+
* After it, `setCount` and `focusItem` do nothing: they neither scroll
|
|
161
|
+
* nor focus, and a move still waiting for its item is dropped.
|
|
162
|
+
*/
|
|
163
|
+
readonly detach: () => void;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Makes `list` — a `role="listbox"` the renderer drew, usually virtualized
|
|
167
|
+
* so that only a window of a long list is mounted — behave as a
|
|
168
|
+
* multi-select checklist with one tab stop: the arrow keys, Home, End,
|
|
169
|
+
* PageUp and PageDown move focus among its items, and Space or a click asks
|
|
170
|
+
* for the focused item to be toggled. It decides; the caller is told through
|
|
171
|
+
* the callbacks and draws the outcome, `aria-checked` included.
|
|
172
|
+
*
|
|
173
|
+
* Items are the list's descendants with `data-gridkit-checklist-item` and a
|
|
174
|
+
* `data-gridkit-checklist-index`: their place in the whole list rather than
|
|
175
|
+
* in the window, since an item's place is all that survives it being
|
|
176
|
+
* unmounted and mounted again. The list is the element that scrolls: PageUp
|
|
177
|
+
* and PageDown move by as many items as it shows whole.
|
|
178
|
+
*
|
|
179
|
+
* One item at a time has `tabindex="0"` — the focused one, or the first
|
|
180
|
+
* mounted while the focused one is scrolled away — and the rest `-1`, kept
|
|
181
|
+
* so as items mount by an observer of the list's children rather than by
|
|
182
|
+
* the renderer. The list itself gets `tabindex="-1"`: a browser may make an
|
|
183
|
+
* element that scrolls a tab stop of its own, as Firefox does, which would
|
|
184
|
+
* put a second stop before the items' one, on an element the keys do not
|
|
185
|
+
* move from. A move to an item outside the window asks `scrollToIndex`
|
|
186
|
+
* for it and focuses it once it mounts, unless focus has gone somewhere
|
|
187
|
+
* else in the meantime.
|
|
188
|
+
*
|
|
189
|
+
* Enter is not handled, so a form around the list hears it and applies;
|
|
190
|
+
* Escape is the overlay stack's.
|
|
191
|
+
*/
|
|
192
|
+
declare function attachChecklist(list: HTMLElement, options: ChecklistOptions): AttachedChecklist;
|
|
193
|
+
|
|
194
|
+
/** Which side of its anchor an overlay opens on. */
|
|
195
|
+
type OverlaySide = "top" | "bottom" | "left" | "right";
|
|
196
|
+
/**
|
|
197
|
+
* Which edge of the anchor the overlay lines up with along that side: its
|
|
198
|
+
* left edge (`start`) or right edge (`end`) for `top`/`bottom`, its top or
|
|
199
|
+
* bottom edge for `left`/`right`.
|
|
200
|
+
*/
|
|
201
|
+
type OverlayAlign = "start" | "end";
|
|
202
|
+
type OverlayPlacement = `${OverlaySide}-${OverlayAlign}`;
|
|
203
|
+
/** A box in viewport coordinates, as `getBoundingClientRect` reports one. */
|
|
204
|
+
interface OverlayRect {
|
|
205
|
+
readonly top: number;
|
|
206
|
+
readonly left: number;
|
|
207
|
+
readonly width: number;
|
|
208
|
+
readonly height: number;
|
|
209
|
+
}
|
|
210
|
+
interface OverlaySize {
|
|
211
|
+
readonly width: number;
|
|
212
|
+
readonly height: number;
|
|
213
|
+
}
|
|
214
|
+
interface OverlayPlacementOptions {
|
|
215
|
+
/** Where the overlay would rather open. Defaults to `"bottom-start"`. */
|
|
216
|
+
readonly placement?: OverlayPlacement | undefined;
|
|
217
|
+
/** Space between the anchor and the overlay, in pixels. Defaults to `0`. */
|
|
218
|
+
readonly gap?: number | undefined;
|
|
219
|
+
/**
|
|
220
|
+
* Pixels to shift the overlay along the anchor's edge — down beside a
|
|
221
|
+
* `left`/`right` side, right beside `top`/`bottom`; negative goes the other
|
|
222
|
+
* way. A submenu opened `right-start` takes its own top padding, negated,
|
|
223
|
+
* so its first item lines up with the item that opened it. The overlay is
|
|
224
|
+
* still kept on screen. Defaults to `0`.
|
|
225
|
+
*/
|
|
226
|
+
readonly offset?: number | undefined;
|
|
227
|
+
/**
|
|
228
|
+
* The writing direction the placement is read in. `"rtl"` mirrors it, as
|
|
229
|
+
* a right-to-left page is mirrored: `left` and `right` swap, `start` and
|
|
230
|
+
* `end` beside `top` or `bottom` are the anchor's right and left edges, an
|
|
231
|
+
* `offset` along those sides runs leftward, and an overlay wider than the
|
|
232
|
+
* viewport keeps its right edge in view. The placement it ends up with is
|
|
233
|
+
* reported in the same mirrored terms, so `"bottom-start"` lines up with
|
|
234
|
+
* the anchor's inline start and `"right-start"` opens a submenu toward
|
|
235
|
+
* the inline end in either direction. Defaults to `"ltr"`.
|
|
236
|
+
*/
|
|
237
|
+
readonly direction?: WritingDirection | undefined;
|
|
238
|
+
}
|
|
239
|
+
/** Where an overlay goes: its top-left corner, and the placement it ended up with. */
|
|
240
|
+
interface OverlayPosition {
|
|
241
|
+
readonly top: number;
|
|
242
|
+
readonly left: number;
|
|
243
|
+
readonly placement: OverlayPlacement;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Where an overlay of size `panel` goes beside `anchor` so that it stays in
|
|
247
|
+
* `viewport`: on the preferred side unless only the opposite one has room,
|
|
248
|
+
* lined up with the preferred edge unless that runs it off screen and the
|
|
249
|
+
* other edge does not, and finally pushed back inside if it still overflows.
|
|
250
|
+
* Pure, so the rules are testable without a browser; `attachOverlay` feeds it
|
|
251
|
+
* the measurements.
|
|
252
|
+
*
|
|
253
|
+
* A point — a context menu opened where the pointer is — is an anchor with
|
|
254
|
+
* no width or height, which is what makes `start`/`end` mean "after" and
|
|
255
|
+
* "before" it.
|
|
256
|
+
*
|
|
257
|
+
* In `"rtl"` the anchor is mirrored across the viewport, placed as in
|
|
258
|
+
* left-to-right, and the result mirrored back, so every rule above holds
|
|
259
|
+
* with left and right exchanged.
|
|
260
|
+
*/
|
|
261
|
+
declare function placeOverlay(anchor: OverlayRect, panel: OverlaySize, viewport: OverlaySize, options?: OverlayPlacementOptions): OverlayPosition;
|
|
262
|
+
|
|
263
|
+
/** What an overlay opens beside: an element, or a point in viewport coordinates. */
|
|
264
|
+
type OverlayAnchor = Element | {
|
|
265
|
+
readonly x: number;
|
|
266
|
+
readonly y: number;
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* Where focus goes when an overlay attaches: its first focusable descendant,
|
|
270
|
+
* the panel itself, nowhere — focus stays where it was — or a given element.
|
|
271
|
+
*/
|
|
272
|
+
type OverlayInitialFocus = "first" | "panel" | "none" | HTMLElement;
|
|
273
|
+
/** Why an overlay asked to close. */
|
|
274
|
+
type OverlayDismissReason = "escape" | "outside" | "scroll" | "resize" | "blur" | "parent";
|
|
275
|
+
interface OverlayOptions extends OverlayPlacementOptions {
|
|
276
|
+
/**
|
|
277
|
+
* The overlay asks to close: Escape was pressed while it was the topmost
|
|
278
|
+
* overlay, a pointer went down outside it, something outside it scrolled,
|
|
279
|
+
* the window resized or lost focus, focus moved outside it, or the overlay
|
|
280
|
+
* it was opened above detached. The caller closes it — removes the panel
|
|
281
|
+
* and detaches — or keeps it open by doing nothing, except after
|
|
282
|
+
* `"parent"`, which detaches it regardless.
|
|
283
|
+
*/
|
|
284
|
+
readonly onDismiss: (reason: OverlayDismissReason) => void;
|
|
285
|
+
/**
|
|
286
|
+
* Where focus goes on attaching. Defaults to `"first"`: a menu focuses its
|
|
287
|
+
* first item. A panel whose first control is not where the user starts — a
|
|
288
|
+
* filter editor's operator picker before its value box — passes that
|
|
289
|
+
* element, or `"panel"` to land on the panel itself; `"none"` leaves focus
|
|
290
|
+
* where it was, as a suggestion list does while typing goes on in the
|
|
291
|
+
* field that opened it.
|
|
292
|
+
*/
|
|
293
|
+
readonly initialFocus?: OverlayInitialFocus | undefined;
|
|
294
|
+
/**
|
|
295
|
+
* Where focus goes when the overlay detaches. Defaults to the element that
|
|
296
|
+
* had focus when it attached; `null` leaves focus alone, unless
|
|
297
|
+
* `returnFocusFallback` names somewhere.
|
|
298
|
+
*/
|
|
299
|
+
readonly returnFocusTo?: HTMLElement | null | undefined;
|
|
300
|
+
/**
|
|
301
|
+
* Where focus goes when there is nothing to return it to as the overlay
|
|
302
|
+
* detaches: `returnFocusTo` is `null`, or has left the page — the button a
|
|
303
|
+
* menu opened from, taken away by what the menu ran. Called then, so it
|
|
304
|
+
* can name what is on the page by that time; returning `null` leaves focus
|
|
305
|
+
* alone. Like the return itself, it applies only while focus is still in
|
|
306
|
+
* the panel, in an overlay above it, or nowhere.
|
|
307
|
+
*/
|
|
308
|
+
readonly returnFocusFallback?: (() => HTMLElement | null) | undefined;
|
|
309
|
+
/**
|
|
310
|
+
* Whether a scroll outside the panel just after input inside it — an
|
|
311
|
+
* `input` or `change` event, in the two animation frames that follow it —
|
|
312
|
+
* leaves it open. A panel whose controls change the page under it opts
|
|
313
|
+
* in: a column chooser hiding a column narrows the grid it opened from,
|
|
314
|
+
* and the browser scrolls that grid back within its narrower content.
|
|
315
|
+
* Defaults to `false`, where every scroll outside the panel dismisses it.
|
|
316
|
+
*/
|
|
317
|
+
readonly ignoreScrollAfterInput?: boolean | undefined;
|
|
318
|
+
/**
|
|
319
|
+
* Whether Tab and Shift+Tab stay inside the panel: from its last tabbable
|
|
320
|
+
* element Tab moves to its first, and Shift+Tab from its first to its last,
|
|
321
|
+
* as a dialog keeps them. Defaults to `false`, where tabbing out of the
|
|
322
|
+
* panel moves focus outside it, which dismisses it with `"blur"`. Only
|
|
323
|
+
* the keys are kept: a pointer down outside still dismisses it, and so
|
|
324
|
+
* does focus moved out by any other route.
|
|
325
|
+
*/
|
|
326
|
+
readonly trapFocus?: boolean | undefined;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Shows `panel` as an overlay beside `anchor` — a menu, a popover, a filter
|
|
330
|
+
* editor — and returns the function that ends it. The caller renders the
|
|
331
|
+
* panel, usually as a child of `document.body` so no scrolling ancestor clips
|
|
332
|
+
* it; this positions it, moves focus into it, and reports through
|
|
333
|
+
* `onDismiss` when the user is done with it.
|
|
334
|
+
*
|
|
335
|
+
* The panel is positioned `fixed`, at the place `placeOverlay` picks from the
|
|
336
|
+
* anchor's and the panel's measured boxes, and carries that placement in
|
|
337
|
+
* `data-gridkit-placement` (`"top-start"` once flipped above, say) for a
|
|
338
|
+
* stylesheet to point an arrow by. Whenever the panel's size changes — a list
|
|
339
|
+
* that shrinks under a search — it is placed again beside the anchor, so a
|
|
340
|
+
* panel flipped above its anchor keeps its bottom edge there — or beside
|
|
341
|
+
* where the anchor was, once it has left the page. Focus moves
|
|
342
|
+
* where `initialFocus` says.
|
|
343
|
+
*
|
|
344
|
+
* The placement is read in the panel's own writing direction unless
|
|
345
|
+
* `direction` names one, so a panel laid out right to left — given
|
|
346
|
+
* `dir="rtl"`, or rendered into a right-to-left page — opens toward the
|
|
347
|
+
* inline end of what it is drawn in. A renderer portalling the panel out of
|
|
348
|
+
* a right-to-left grid in a left-to-right page sets `dir` on it from the
|
|
349
|
+
* grid, which mirrors its content and its placement together.
|
|
350
|
+
*
|
|
351
|
+
* Nothing that happens on or in the anchor dismisses the overlay, so a button
|
|
352
|
+
* that toggles it can close it with its own click rather than having the
|
|
353
|
+
* overlay close and the click reopen it.
|
|
354
|
+
*
|
|
355
|
+
* Overlays stack in the order they attach. Escape belongs to the topmost
|
|
356
|
+
* alone, which takes it: it closes a submenu without closing the menu under
|
|
357
|
+
* it, and nothing else on the page — a grid that clears its selection on
|
|
358
|
+
* Escape — hears it. An overlay counts everything in the overlays above it
|
|
359
|
+
* as inside itself, so a click in a submenu keeps its menu open while a click
|
|
360
|
+
* elsewhere in the menu closes only the submenu.
|
|
361
|
+
*
|
|
362
|
+
* Detaching removes every listener and returns focus, but only when focus is
|
|
363
|
+
* still in the panel, in an overlay above it, or nowhere — a click that
|
|
364
|
+
* dismissed it by landing on another control leaves focus on that control.
|
|
365
|
+
* Focus goes to `returnFocusFallback` instead when the element it would
|
|
366
|
+
* return to has left the page.
|
|
367
|
+
* Any overlay still above it is dismissed with `"parent"` and detached first.
|
|
368
|
+
*/
|
|
369
|
+
declare function attachOverlay(anchor: OverlayAnchor, panel: HTMLElement, options: OverlayOptions): () => void;
|
|
370
|
+
|
|
371
|
+
interface RowVirtualizerOptions {
|
|
372
|
+
/** The height assumed for a row not yet measured. */
|
|
373
|
+
readonly estimatedRowHeight: number;
|
|
374
|
+
/** Rows rendered beyond each edge of the visible area. */
|
|
375
|
+
readonly overscan: number;
|
|
376
|
+
/**
|
|
377
|
+
* The window of rows to render moved: called whenever a scroll, a resize
|
|
378
|
+
* of the scroll element, a measured row height or a change of rows moves
|
|
379
|
+
* it, and never with a window equal to the last.
|
|
380
|
+
*/
|
|
381
|
+
readonly onRange: (range: VisibleRange) => void;
|
|
382
|
+
}
|
|
383
|
+
interface RowVirtualizer {
|
|
384
|
+
/** How many rows there are. Measured heights of the rows that remain are kept. */
|
|
385
|
+
readonly setRowCount: (count: number) => void;
|
|
386
|
+
/**
|
|
387
|
+
* Forgets every measured height, for rows that are no longer the ones
|
|
388
|
+
* measured. A `scrollToIndex` still waiting for its row is dropped too:
|
|
389
|
+
* the row it asked for is no longer at that index.
|
|
390
|
+
*/
|
|
391
|
+
readonly resetHeights: () => void;
|
|
392
|
+
/**
|
|
393
|
+
* A ref callback for the element of row `index` (its place among all the
|
|
394
|
+
* rows, not among those rendered): measured while mounted, forgotten once
|
|
395
|
+
* called with `null`. The same function for the same index every time, so
|
|
396
|
+
* a renderer re-attaching it on every render costs nothing.
|
|
397
|
+
*/
|
|
398
|
+
readonly measureRow: (index: number) => (element: HTMLElement | null) => void;
|
|
399
|
+
/**
|
|
400
|
+
* Reads the heights of rows already laid out, each paired with its index
|
|
401
|
+
* among all the rows, and works out the window once for all of them: for
|
|
402
|
+
* rows drawn before this virtualizer existed, so its first window is the
|
|
403
|
+
* one on screen rather than one placed by `estimatedRowHeight`. Indices
|
|
404
|
+
* past the row count are skipped. It does not observe the rows;
|
|
405
|
+
* `measureRow` does that once the renderer hands them over.
|
|
406
|
+
*/
|
|
407
|
+
readonly measureRows: (rows: Iterable<readonly [index: number, element: Element]>) => void;
|
|
408
|
+
/**
|
|
409
|
+
* Scrolls so row `index` is in view. A mounted row is scrolled to directly;
|
|
410
|
+
* one outside the window is jumped to at its estimated offset, then
|
|
411
|
+
* scrolled to properly once it mounts and can be measured. A later call
|
|
412
|
+
* replaces one still waiting for its row; a row count that no longer holds
|
|
413
|
+
* that row, or `resetHeights`, drops it.
|
|
414
|
+
*/
|
|
415
|
+
readonly scrollToIndex: (index: number, options?: ScrollIntoViewOptions) => void;
|
|
416
|
+
/**
|
|
417
|
+
* Stops listening, measuring and scrolling, for good: every method does
|
|
418
|
+
* nothing after it.
|
|
419
|
+
*/
|
|
420
|
+
readonly destroy: () => void;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Windows a long list of rows inside `scrollElement` down to those near its
|
|
424
|
+
* scroll position, measuring each rendered row's real height rather than
|
|
425
|
+
* assuming a uniform one — rows are not uniform (`.is-wrapped` cells, group
|
|
426
|
+
* header and summary rows), so a fixed-height virtualizer would either break
|
|
427
|
+
* wrapping or rule it out. The renderer draws `onRange`'s window, with
|
|
428
|
+
* spacers of `offsetBefore`/`offsetAfter` around it, and hands each row's
|
|
429
|
+
* element to `measureRow`.
|
|
430
|
+
*
|
|
431
|
+
* The heights are a mutable array, not a structure rebuilt per measurement:
|
|
432
|
+
* one can arrive many times a second while scrolling. The pure arithmetic
|
|
433
|
+
* over them is `@gridkitjs/core`'s `visibleRange`; this owns only the
|
|
434
|
+
* mutability around it and the listeners that feed it — the scroll position,
|
|
435
|
+
* the scroll element's height, and one `ResizeObserver` shared by every
|
|
436
|
+
* mounted row.
|
|
437
|
+
*/
|
|
438
|
+
declare function createRowVirtualizer(scrollElement: HTMLElement, options: RowVirtualizerOptions): RowVirtualizer;
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* The browser's timers as a forms-core `Schedule`: runs `callback` once
|
|
442
|
+
* after `delay` milliseconds, and the function it returns clears the timer.
|
|
443
|
+
* Clearing after the callback has run does nothing.
|
|
444
|
+
*/
|
|
445
|
+
declare const scheduleTimeout: Schedule;
|
|
446
|
+
|
|
447
|
+
interface HoldRepeatOptions {
|
|
448
|
+
/** One step; false when it changed nothing (a limit), which ends the hold. */
|
|
449
|
+
readonly onRepeat: (nativeEvent: PointerEvent) => boolean;
|
|
450
|
+
/** Milliseconds from the press to the first repeat; 400 by default. */
|
|
451
|
+
readonly delay?: number | undefined;
|
|
452
|
+
/** Milliseconds between repeats; 60 by default. */
|
|
453
|
+
readonly interval?: number | undefined;
|
|
454
|
+
/** Milliseconds between repeats once `fastAfter` have been taken; 30 by default. */
|
|
455
|
+
readonly fastInterval?: number | undefined;
|
|
456
|
+
/** Repeats before they speed up; 20 by default. */
|
|
457
|
+
readonly fastAfter?: number | undefined;
|
|
458
|
+
}
|
|
459
|
+
interface AttachedHoldRepeat {
|
|
460
|
+
/** Replaces the options, from the next step on. */
|
|
461
|
+
readonly setOptions: (options: HoldRepeatOptions) => void;
|
|
462
|
+
/** Ends a hold in progress, as letting go would. */
|
|
463
|
+
readonly cancel: () => void;
|
|
464
|
+
/** Ends a hold in progress and removes every listener. */
|
|
465
|
+
readonly detach: () => void;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Where a press of the button is:
|
|
469
|
+
*
|
|
470
|
+
* - `idle`: not pressed.
|
|
471
|
+
* - `waiting`: pressed, one step taken, waiting `delay` to repeat.
|
|
472
|
+
* - `repeating`: stepping every `interval`, then every `fastInterval`.
|
|
473
|
+
* - `detached`: every listener is gone.
|
|
474
|
+
*
|
|
475
|
+
* `waiting` and `repeating` hold the pointer's capture and a timer, which
|
|
476
|
+
* every way out of them releases.
|
|
477
|
+
*/
|
|
478
|
+
type HoldRepeatState = {
|
|
479
|
+
readonly kind: "idle";
|
|
480
|
+
} | {
|
|
481
|
+
readonly kind: "waiting";
|
|
482
|
+
readonly pointerId: number;
|
|
483
|
+
readonly press: PointerEvent;
|
|
484
|
+
readonly cancel: () => void;
|
|
485
|
+
} | {
|
|
486
|
+
readonly kind: "repeating";
|
|
487
|
+
readonly pointerId: number;
|
|
488
|
+
readonly press: PointerEvent;
|
|
489
|
+
readonly count: number;
|
|
490
|
+
readonly cancel: () => void;
|
|
491
|
+
} | {
|
|
492
|
+
readonly kind: "detached";
|
|
493
|
+
};
|
|
494
|
+
/**
|
|
495
|
+
* Makes a stepper button step once when pressed and repeat while held: after
|
|
496
|
+
* `delay` it steps every `interval`, and faster once `fastAfter` steps have
|
|
497
|
+
* been taken. The hold ends when the pointer is let go or cancelled, loses
|
|
498
|
+
* capture or leaves the button, when a step changes nothing, on `cancel`
|
|
499
|
+
* and on `detach`, and every end clears the timer and releases the
|
|
500
|
+
* pointer's capture.
|
|
501
|
+
*
|
|
502
|
+
* Only the primary button of a mouse, or a touch or pen, presses it. A long
|
|
503
|
+
* touch opens no context menu. The renderer keeps focus where it is (on a
|
|
504
|
+
* `mousedown`, so a tap still clicks) and draws the button's disabled
|
|
505
|
+
* state; `onRepeat` returning false when it cannot step ends the hold.
|
|
506
|
+
*/
|
|
507
|
+
declare function attachHoldRepeat(button: HTMLElement, initialOptions: HoldRepeatOptions): AttachedHoldRepeat;
|
|
508
|
+
|
|
509
|
+
interface StepKeysOptions {
|
|
510
|
+
/** A key or a wheel tick asked for a step. */
|
|
511
|
+
readonly onStep: (direction: StepDirection, size: StepSize, nativeEvent: KeyboardEvent | WheelEvent) => void;
|
|
512
|
+
/** Home and End step to an edge only when that limit is set; otherwise they move the caret. */
|
|
513
|
+
readonly edges?: {
|
|
514
|
+
readonly min: boolean;
|
|
515
|
+
readonly max: boolean;
|
|
516
|
+
} | undefined;
|
|
517
|
+
/** The wheel steps while the control has focus and the pointer is over it. */
|
|
518
|
+
readonly wheel?: boolean | undefined;
|
|
519
|
+
}
|
|
520
|
+
interface AttachedStepKeys {
|
|
521
|
+
/** Replaces the options, from the next event on. */
|
|
522
|
+
readonly setOptions: (options: StepKeysOptions) => void;
|
|
523
|
+
/** Removes every listener. */
|
|
524
|
+
readonly detach: () => void;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Steps a number control from the keyboard, as the WAI-ARIA spinbutton
|
|
528
|
+
* pattern does: ArrowUp and ArrowDown one step, PageUp and PageDown a
|
|
529
|
+
* large step, Home and End to a limit that is set. With `options.wheel`,
|
|
530
|
+
* the mouse wheel steps too while the control has focus and the pointer is
|
|
531
|
+
* over it, one step per 50 pixels of travel (or per line or page), and
|
|
532
|
+
* the page does not scroll meanwhile.
|
|
533
|
+
*
|
|
534
|
+
* Keys it steps on are taken (`preventDefault`); keys held with Ctrl, Alt
|
|
535
|
+
* or Meta, keys an input method is using and keys another listener took
|
|
536
|
+
* are left alone. A held arrow repeats by the keyboard's own repeat. It
|
|
537
|
+
* holds its listeners and the wheel travel not yet stepped on; `detach`
|
|
538
|
+
* removes them.
|
|
539
|
+
*/
|
|
540
|
+
declare function attachStepKeys(control: HTMLInputElement, initialOptions: StepKeysOptions): AttachedStepKeys;
|
|
541
|
+
|
|
542
|
+
/** How many lines of text a growing `<textarea>` shows. */
|
|
543
|
+
interface AutoGrowOptions {
|
|
544
|
+
/** The lines it shows when empty. */
|
|
545
|
+
readonly minRows: number;
|
|
546
|
+
/** The lines it grows to, before it scrolls. */
|
|
547
|
+
readonly maxRows: number;
|
|
548
|
+
}
|
|
549
|
+
interface AttachedAutoGrow {
|
|
550
|
+
/**
|
|
551
|
+
* Sets the height for the text there is now. The renderer calls it after
|
|
552
|
+
* it writes text from code, which fires no `input`.
|
|
553
|
+
*/
|
|
554
|
+
readonly update: () => void;
|
|
555
|
+
/** Replaces the row range, and sets the height for it. */
|
|
556
|
+
readonly setOptions: (options: AutoGrowOptions) => void;
|
|
557
|
+
/** Stops listening, and leaves the height as it is. */
|
|
558
|
+
readonly detach: () => void;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Grows a `<textarea>` with its text, from `minRows` lines to `maxRows`,
|
|
562
|
+
* then lets it scroll. The height follows every `input` and every change
|
|
563
|
+
* of the textarea's width, which rewraps the text (a `ResizeObserver`),
|
|
564
|
+
* and is worked out from `scrollHeight`, the computed line height,
|
|
565
|
+
* padding and borders. CSS `field-sizing: content` would do this, but not
|
|
566
|
+
* every browser the forms support has it.
|
|
567
|
+
*/
|
|
568
|
+
declare function attachAutoGrow(textarea: HTMLTextAreaElement, initialOptions: AutoGrowOptions): AttachedAutoGrow;
|
|
569
|
+
|
|
570
|
+
/** The native controls a text input draws. */
|
|
571
|
+
type TextControl = HTMLInputElement | HTMLTextAreaElement;
|
|
572
|
+
/**
|
|
573
|
+
* What `attachTextInput` asks of the field it drives: a forms-core
|
|
574
|
+
* `FieldController`, or one part of a composite input.
|
|
575
|
+
*/
|
|
576
|
+
type TextInputController<V, D extends object> = Pick<FieldController<V, D, Event>, "getState" | "getText" | "getMessages" | "subscribe" | "beforeInput" | "input" | "endComposition" | "filterComposition" | "focus" | "commit" | "blur" | "revert" | "clear" | "reset">;
|
|
577
|
+
/** What a renderer can change about the pipeline while it is attached. */
|
|
578
|
+
interface TextInputOptions {
|
|
579
|
+
/**
|
|
580
|
+
* Selects all the text when the control gains focus from the keyboard or
|
|
581
|
+
* from code. A press of a pointer places the caret as usual.
|
|
582
|
+
*/
|
|
583
|
+
readonly selectOnFocus?: boolean | undefined;
|
|
584
|
+
/**
|
|
585
|
+
* What Escape does: puts back the last committed text (`"revert"`, the
|
|
586
|
+
* default), empties the field (`"clear"`, for a search box), or nothing.
|
|
587
|
+
* It takes the key only when it changed something.
|
|
588
|
+
*/
|
|
589
|
+
readonly escape?: "revert" | "clear" | "none" | undefined;
|
|
590
|
+
/** Called just before Escape empties the field, for the renderer's `onClear`. */
|
|
591
|
+
readonly onClear?: ((nativeEvent: Event) => void) | undefined;
|
|
592
|
+
/**
|
|
593
|
+
* Where the caret goes when the field's text is written into the focused
|
|
594
|
+
* control: given the text before, the caret in it and the text after.
|
|
595
|
+
* By default it keeps its distance from the end of the text.
|
|
596
|
+
*/
|
|
597
|
+
readonly mapCaret?: ((previousText: string, caret: number, nextText: string) => number) | undefined;
|
|
598
|
+
/**
|
|
599
|
+
* What the keypad's decimal key types, whatever the keyboard layout
|
|
600
|
+
* gives: a number field's decimal separator, so the keypad "." of a US
|
|
601
|
+
* keyboard types "," in a German field.
|
|
602
|
+
*/
|
|
603
|
+
readonly decimalKey?: string | undefined;
|
|
604
|
+
/**
|
|
605
|
+
* The furthest a click may leave the caret in the text: a mask's first
|
|
606
|
+
* empty slot. A click that places the caret past it moves it there; a
|
|
607
|
+
* selection is left alone.
|
|
608
|
+
*/
|
|
609
|
+
readonly lastCaret?: ((text: string) => number) | undefined;
|
|
610
|
+
/**
|
|
611
|
+
* Who starts and ends the edit. `"own"` (the default): the control's
|
|
612
|
+
* focus and blur do, and Tab commits. `"group"`: the control is one of
|
|
613
|
+
* several that edit one field (a segmented date's free-text box), so the
|
|
614
|
+
* group around it does, and the control calls neither `focus` nor `blur`
|
|
615
|
+
* and leaves Tab alone.
|
|
616
|
+
*/
|
|
617
|
+
readonly focus?: "own" | "group" | undefined;
|
|
618
|
+
}
|
|
619
|
+
interface AttachedTextInput {
|
|
620
|
+
/** Replaces the options, from the next event on. */
|
|
621
|
+
readonly setOptions: (options: TextInputOptions) => void;
|
|
622
|
+
/**
|
|
623
|
+
* Removes every listener and clears the control's custom validity. The
|
|
624
|
+
* controller is left as it is, so another control can be attached to it.
|
|
625
|
+
*/
|
|
626
|
+
readonly detach: () => void;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Connects a native text control to a forms-core field controller, so the
|
|
630
|
+
* controller decides what the control's text means and the control shows
|
|
631
|
+
* what the controller holds. The renderer draws the control and calls
|
|
632
|
+
* this once it is in the page.
|
|
633
|
+
*
|
|
634
|
+
* Reads the control's events into the controller's requests, each with the
|
|
635
|
+
* browser event as its `nativeEvent`:
|
|
636
|
+
*
|
|
637
|
+
* - `focus` and `blur` start and end the edit; the blur commits it, unless
|
|
638
|
+
* Tab did. With `options.focus` set to `"group"`, the group around the
|
|
639
|
+
* control does all three instead.
|
|
640
|
+
* - `beforeinput` asks `onBeforeInput`, then the field's own
|
|
641
|
+
* `filterInput`, with the text the edit would leave, then lets the edit
|
|
642
|
+
* happen, prevents it, inserts the handler's data in its place, or
|
|
643
|
+
* replaces the whole text and places the caret as the filter says.
|
|
644
|
+
* `input` reports the text the edit left. Where it came from (`typing`,
|
|
645
|
+
* `paste`, `drop`, `undo`) is read from its `inputType`; text that
|
|
646
|
+
* changes while the field is not being edited is `autofill`.
|
|
647
|
+
* - With `options.decimalKey`, the keypad's decimal key types that text,
|
|
648
|
+
* judged as any other typing, in place of what the layout gives.
|
|
649
|
+
* - While an input method composes, every `input` reports `isComposing`
|
|
650
|
+
* and the text is read once `compositionend` arrives. Then the field's
|
|
651
|
+
* `filterInput` judges the composed text as one insert over the range
|
|
652
|
+
* the composition replaced (`filterComposition`), and its replacement,
|
|
653
|
+
* rewrite or refusal is written as for any edit.
|
|
654
|
+
* - With `options.lastCaret`, a click that leaves the caret past it moves
|
|
655
|
+
* the caret there.
|
|
656
|
+
* - Enter commits (in a `<textarea>`, Ctrl+Enter or Cmd+Enter, since Enter
|
|
657
|
+
* is a new line); Tab commits and, when `onBeforeCommit` refuses at once,
|
|
658
|
+
* keeps focus by preventing the key; Escape puts back the last committed
|
|
659
|
+
* text, or empties the field, as `options.escape` says, and takes the key
|
|
660
|
+
* when it changed something. Keys an input method is using, and keys
|
|
661
|
+
* another listener prevented, are left alone.
|
|
662
|
+
* - With `options.selectOnFocus`, focus from the keyboard or from code
|
|
663
|
+
* selects all the text.
|
|
664
|
+
* - A `reset` of the control's form that nobody prevented resets the
|
|
665
|
+
* field, with `source: "api"`.
|
|
666
|
+
*
|
|
667
|
+
* After every change of the field it writes the controller's text into
|
|
668
|
+
* the control when the two differ, never while an input method composes.
|
|
669
|
+
* On a focused control a refused change is put back with the selection it
|
|
670
|
+
* had before the edit, and any other write places the selection by
|
|
671
|
+
* `options.mapCaret`, by default at its distance from the end of the
|
|
672
|
+
* text, so separators a formatter adds before the caret do not move it. A
|
|
673
|
+
* write to an unfocused control leaves the selection alone. The control's
|
|
674
|
+
* custom validity holds the field's first error, shown or not yet, so a
|
|
675
|
+
* plain `<form>` refuses to submit it.
|
|
676
|
+
*
|
|
677
|
+
* Inserting the handler's data, and replacing the text, go through the
|
|
678
|
+
* browser's editing commands where the browser allows it, so they can be
|
|
679
|
+
* undone; elsewhere the text is set directly. Setting the text from code
|
|
680
|
+
* (a refused change put back, a commit normalizing the text, a value from
|
|
681
|
+
* the app) cannot be undone.
|
|
682
|
+
*/
|
|
683
|
+
declare function attachTextInput<V, D extends object>(control: TextControl, controller: TextInputController<V, D>, initialOptions?: TextInputOptions): AttachedTextInput;
|
|
684
|
+
|
|
685
|
+
/** What a renderer can change about a toggle while it is attached. */
|
|
686
|
+
interface ToggleOptions {
|
|
687
|
+
/** A flip can set `null` (indeterminate): `false` → `true` → `null` → `false`. */
|
|
688
|
+
readonly threeState?: boolean | undefined;
|
|
689
|
+
/**
|
|
690
|
+
* Refuses every flip and stays focusable. A native checkbox ignores the
|
|
691
|
+
* `readonly` attribute, so the renderer says so here.
|
|
692
|
+
*/
|
|
693
|
+
readonly readOnly?: boolean | undefined;
|
|
694
|
+
}
|
|
695
|
+
interface AttachedToggle {
|
|
696
|
+
/** Replaces the options, from the next event on. */
|
|
697
|
+
readonly setOptions: (options: ToggleOptions) => void;
|
|
698
|
+
/**
|
|
699
|
+
* Removes every listener and clears the control's custom validity. The
|
|
700
|
+
* controller is left as it is, so another control can be attached to it.
|
|
701
|
+
*/
|
|
702
|
+
readonly detach: () => void;
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Connects a native `<input type="checkbox">`, a checkbox or a
|
|
706
|
+
* `role="switch"`, to a forms-core field controller holding a boolean, so
|
|
707
|
+
* the controller decides what each flip means and the control shows what
|
|
708
|
+
* the controller holds.
|
|
709
|
+
*
|
|
710
|
+
* - The browser's `click`, from a pointer, a label or <kbd>Space</kbd>,
|
|
711
|
+
* flips the field to `nextCheckedValue` of what it holds, through
|
|
712
|
+
* `controller.pick` with `source` and `trigger` `"toggle"`: the change
|
|
713
|
+
* events, then the commit. A flip by Space carries the Space `keydown`
|
|
714
|
+
* as its `nativeEvent`, a press the `click`.
|
|
715
|
+
* - With `options.readOnly` the click is prevented, so nothing changes.
|
|
716
|
+
* - `focus` and `blur` start and end the edit; leaving commits nothing
|
|
717
|
+
* more, so the controller should have `commitOnLeave: false`.
|
|
718
|
+
* - A `reset` of the control's form that nobody prevented resets the
|
|
719
|
+
* field, with `source: "api"`.
|
|
720
|
+
*
|
|
721
|
+
* After every change of the field it writes `checked` (the value is
|
|
722
|
+
* `true`) and `indeterminate` (it is `null`), over whatever the browser
|
|
723
|
+
* did with the click, and holds the field's first error as the control's
|
|
724
|
+
* custom validity, so a plain `<form>` refuses to submit it.
|
|
725
|
+
*/
|
|
726
|
+
declare function attachToggle<D extends object>(control: HTMLInputElement, controller: FieldController<boolean, D, Event>, initialOptions?: ToggleOptions): AttachedToggle;
|
|
727
|
+
|
|
728
|
+
/** What `attachSegments` asks of the field it drives: a controller, or a part of a composite. */
|
|
729
|
+
type SegmentsController<V, D extends object> = TextInputController<V, D>;
|
|
730
|
+
/** What a renderer can change about the segments while they are attached. */
|
|
731
|
+
interface SegmentsOptions {
|
|
732
|
+
/** The field's layout and how it reads, for the segment reducer. */
|
|
733
|
+
readonly context: SegmentContext;
|
|
734
|
+
/** The locale a month's name is read in, for its `aria-valuetext`. */
|
|
735
|
+
readonly locale: Intl.LocalesArgument;
|
|
736
|
+
/** For an empty segment's `aria-valuetext`. */
|
|
737
|
+
readonly messages: FormsMessages;
|
|
738
|
+
/** What Escape in a segment does: puts back the last committed value (`"revert"`, the default), or nothing. */
|
|
739
|
+
readonly escape?: "revert" | "none" | undefined;
|
|
740
|
+
/**
|
|
741
|
+
* Whether `node`, outside the group, counts as inside the field: the
|
|
742
|
+
* picker popup it opened, so focus moving there neither commits nor
|
|
743
|
+
* blurs the field.
|
|
744
|
+
*/
|
|
745
|
+
readonly isInside?: ((node: Node) => boolean) | undefined;
|
|
746
|
+
/** F4 or Alt+ArrowDown in a segment: the renderer opens its picker. */
|
|
747
|
+
readonly onOpenPicker?: ((nativeEvent: KeyboardEvent) => void) | undefined;
|
|
748
|
+
}
|
|
749
|
+
interface AttachedSegments {
|
|
750
|
+
/** Replaces the options, from the next event on, and redraws the segments. */
|
|
751
|
+
readonly setOptions: (options: SegmentsOptions) => void;
|
|
752
|
+
/** Focuses a segment, or the first empty one (the free-text box while it shows), as a click in the box does. */
|
|
753
|
+
readonly focus: (segment?: number | "firstEmpty") => void;
|
|
754
|
+
/** Where typing stands (the segment typed in, or the free-text box with the segments' text it opened over) and the text it holds. */
|
|
755
|
+
readonly getState: () => SegmentState;
|
|
756
|
+
/** Removes every listener, the free-text box's pipeline included. */
|
|
757
|
+
readonly detach: () => void;
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Drives a segmented date, time or date-time field: one native input per
|
|
761
|
+
* segment (each marked `data-gridkit-forms-segment`, in typing order)
|
|
762
|
+
* inside `group`, the segments' wrapper marked
|
|
763
|
+
* `data-gridkit-forms-segments`, and a free-text box marked
|
|
764
|
+
* `data-gridkit-forms-segment-text` for shortcuts and text that is not
|
|
765
|
+
* segments. forms-core's `segmentReducer` decides every transition; this
|
|
766
|
+
* turns the browser's events into its actions and applies what it returns:
|
|
767
|
+
*
|
|
768
|
+
* - `beforeinput` on a segment (typing, Android's keys, a cut, a drop),
|
|
769
|
+
* its `paste` and its composition events are actions. Every cancelable
|
|
770
|
+
* edit is prevented and each segment's text is written here, so a
|
|
771
|
+
* segment never holds what the reducer did not put there.
|
|
772
|
+
* - Backspace and Delete, the arrows, PageUp and PageDown, Home and End are
|
|
773
|
+
* read from `keydown`. ArrowLeft and ArrowRight move by the segments'
|
|
774
|
+
* order on screen, so they follow a right-to-left field.
|
|
775
|
+
* - A text change is reported to the controller as an edit: `onBeforeInput`
|
|
776
|
+
* first (refused, nothing changes), then `onInput` with the segment's
|
|
777
|
+
* place in the field's text as the edit's selection, from which the
|
|
778
|
+
* field's `details` names the segment. Steps report `source: "step"`.
|
|
779
|
+
* - Focus entering the group starts the edit; moving between segments and
|
|
780
|
+
* the free-text box fires nothing; leaving finishes the segment (pads it,
|
|
781
|
+
* pivots a short year) and blurs the field, which commits. Enter
|
|
782
|
+
* finishes and commits; Tab finishes and commits, kept in the field when
|
|
783
|
+
* `onBeforeCommit` refuses; Escape reverts, or in the free-text box goes
|
|
784
|
+
* back to the segments.
|
|
785
|
+
* - A press in the box outside a segment focuses the first empty segment;
|
|
786
|
+
* a press on the focused day period flips it.
|
|
787
|
+
* - The free-text box runs forms-dom's text pipeline in group focus mode;
|
|
788
|
+
* its edits go through the reducer, which applies a one-letter shortcut
|
|
789
|
+
* at once and goes back to the segments when the box is emptied.
|
|
790
|
+
*
|
|
791
|
+
* After every change of the field it writes each segment's text, its
|
|
792
|
+
* `aria-valuenow`, `aria-valuemin`, `aria-valuemax` and `aria-valuetext`,
|
|
793
|
+
* and, while focus is outside the group, shows the free-text box in place
|
|
794
|
+
* of the segments when the text is not segments.
|
|
795
|
+
*
|
|
796
|
+
* It holds the reducer's `SegmentEntry`, its listeners (one
|
|
797
|
+
* `AbortController`), the focus group and the free-text box's pipeline;
|
|
798
|
+
* `detach` releases all of them.
|
|
799
|
+
*/
|
|
800
|
+
declare function attachSegments<V, D extends object>(group: HTMLElement, controller: SegmentsController<V, D>, initialOptions: SegmentsOptions): AttachedSegments;
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* The way `element`'s lines run, from its computed `direction`: what it
|
|
804
|
+
* inherits from a `dir` attribute on it or an ancestor, or from the CSS
|
|
805
|
+
* `direction` property. Read afresh on every call, never kept, so a page
|
|
806
|
+
* whose direction changes is followed from the next key press, gesture or
|
|
807
|
+
* overlay on.
|
|
808
|
+
*/
|
|
809
|
+
declare function writingDirection(element: Element): WritingDirection;
|
|
810
|
+
|
|
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 };
|