@gridkitjs/dom 0.2.1 → 0.3.1

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 CHANGED
@@ -57,7 +57,7 @@ Overlays stack in the order they attach: Escape and outside clicks reach the
57
57
  topmost first, and detaching one closes every overlay opened above it, so a
58
58
  submenu never outlives its menu.
59
59
 
60
- Full documentation: [github.com/blagojablazhevski/gridkit](https://github.com/blagojablazhevski/gridkit#readme)
60
+ Full documentation: [github.com/gridkitjs/gridkitjs](https://github.com/gridkitjs/gridkitjs#readme)
61
61
 
62
62
  ## License
63
63
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ColumnResizeSession, ColumnOrderState, GroupByState, GridFocus, NavigationModifiers, VisibleRange, ResolvedToolbarItem } from '@gridkitjs/core';
1
+ import { ColumnResizeSession, ColumnOrderState, GroupByState, GridFocus, NavigationModifiers, VisibleRange, ResolvedToolbarItem, PrintPage } from '@gridkitjs/core';
2
2
 
3
3
  /** A live region to report changes through. */
4
4
  interface LiveAnnouncer {
@@ -65,6 +65,65 @@ declare function groupRowFrom(target: EventTarget | null): GroupRowTarget | null
65
65
  */
66
66
  declare function bodyRowFrom(target: EventTarget | null): BodyRowTarget | null;
67
67
 
68
+ interface ChecklistOptions {
69
+ /**
70
+ * The item at `index` — its place in the whole list — asks to be checked
71
+ * or unchecked: Space on it, or a click. The caller flips it in its own
72
+ * state and draws the new `aria-checked`.
73
+ */
74
+ readonly onToggle: (index: number) => void;
75
+ /** Focus moved to the item at `index`, by a key, a click or a script. */
76
+ readonly onFocusChange?: ((index: number) => void) | undefined;
77
+ /**
78
+ * Bring the item at `index` into view, mounting it if the list's window
79
+ * does not hold it. A virtualized renderer forwards this to its
80
+ * virtualizer's `scrollToIndex`, with `{ block: "nearest" }` so a move of
81
+ * one item scrolls by one item.
82
+ */
83
+ readonly scrollToIndex: (index: number) => void;
84
+ }
85
+ interface AttachedChecklist {
86
+ /**
87
+ * How many items the whole list holds, mounted or not. Starts at 0, so a
88
+ * renderer calls this straight after attaching, and again whenever the
89
+ * list changes — a search narrowing it, say. A focused place past the new
90
+ * end moves back to the last item.
91
+ */
92
+ readonly setCount: (count: number) => void;
93
+ /**
94
+ * Focuses the item at `index`, clamped to the list, scrolling to it first.
95
+ * An item outside the mounted window is focused once it mounts.
96
+ */
97
+ readonly focusItem: (index: number) => void;
98
+ /** Removes every listener and observer. The items keep their `tabindex`. */
99
+ readonly detach: () => void;
100
+ }
101
+ /**
102
+ * Makes `list` — a `role="listbox"` the renderer drew, usually virtualized
103
+ * so that only a window of a long list is mounted — behave as a
104
+ * multi-select checklist with one tab stop: the arrow keys, Home, End,
105
+ * PageUp and PageDown move focus among its items, and Space or a click asks
106
+ * for the focused item to be toggled. It decides; the caller is told through
107
+ * the callbacks and draws the outcome, `aria-checked` included.
108
+ *
109
+ * Items are the list's descendants with `data-gridkit-checklist-item` and a
110
+ * `data-gridkit-checklist-index`: their place in the whole list rather than
111
+ * in the window, since an item's place is all that survives it being
112
+ * unmounted and mounted again. The list is the element that scrolls: PageUp
113
+ * and PageDown move by as many items as it shows whole.
114
+ *
115
+ * One item at a time has `tabindex="0"` — the focused one, or the first
116
+ * mounted while the focused one is scrolled away — and the rest `-1`, kept
117
+ * so as items mount by an observer of the list's children rather than by
118
+ * the renderer. A move to an item outside the window asks `scrollToIndex`
119
+ * for it and focuses it once it mounts, unless focus has gone somewhere
120
+ * else in the meantime.
121
+ *
122
+ * Enter is not handled, so a form around the list hears it and applies;
123
+ * Escape is the overlay stack's.
124
+ */
125
+ declare function attachChecklist(list: HTMLElement, options: ChecklistOptions): AttachedChecklist;
126
+
68
127
  /**
69
128
  * How a context menu was asked for: by a pointer — a right-click, or a touch
70
129
  * held still — or by the keyboard.
@@ -168,6 +227,44 @@ declare function startColumnResizeGesture(handle: HTMLElement, press: PointerPre
168
227
  */
169
228
  declare function measureColumnContent(table: HTMLTableElement, columnId: string): number | null;
170
229
 
230
+ /** What `writeClipboard` puts on the clipboard: the same copy as plain text and as HTML. */
231
+ interface ClipboardContent {
232
+ readonly text: string;
233
+ readonly html: string;
234
+ }
235
+ /**
236
+ * Whether a copy key pressed at `target` belongs to the browser: pressed in a
237
+ * text field, or with text highlighted anywhere on the page. Either way the
238
+ * user means the text in front of them, and a grid copying its own cell
239
+ * instead would take that from them.
240
+ */
241
+ declare function isNativeCopy(target: EventTarget | null): boolean;
242
+ /**
243
+ * Puts `content` on the clipboard as both `text/plain` and `text/html`, so a
244
+ * paste into a spreadsheet splits into cells and one into a word processor
245
+ * keeps its table. Call it from a user's gesture — a key press, a menu
246
+ * choice — as browsers allow the clipboard only then.
247
+ *
248
+ * Tries each way a browser offers, best first: the async Clipboard API with
249
+ * a `ClipboardItem` holding both types; then its `writeText`, plain text
250
+ * alone, where `ClipboardItem` is missing or refused; then the legacy `copy`
251
+ * event, for a page outside a secure context, where the async API is not
252
+ * there at all. Rejects only when every one fails.
253
+ */
254
+ declare function writeClipboard(content: ClipboardContent): Promise<void>;
255
+
256
+ /**
257
+ * Saves `blob` as a file named `fileName` — the browser's own download, as a
258
+ * link with a `download` attribute starts one, so nothing is opened or
259
+ * navigated to.
260
+ *
261
+ * The link is put in the document for the click, as Firefox has needed, and
262
+ * taken out straight after. Its object URL is revoked a task later rather
263
+ * than at once: Safari starts the download from the URL after the click
264
+ * returns, and a URL revoked synchronously is gone before it does.
265
+ */
266
+ declare function downloadBlob(blob: Blob, fileName: string): void;
267
+
171
268
  /** What a renderer draws while a reorder drag is open. */
172
269
  interface DragReorderState<Target> {
173
270
  /** The item being dragged, once the press has become a drag. */
@@ -591,6 +688,15 @@ interface OverlayOptions extends OverlayPlacementOptions {
591
688
  * Defaults to `false`, where every scroll outside the panel dismisses it.
592
689
  */
593
690
  readonly ignoreScrollAfterInput?: boolean | undefined;
691
+ /**
692
+ * Whether Tab and Shift+Tab stay inside the panel: from its last tabbable
693
+ * element Tab moves to its first, and Shift+Tab from its first to its last,
694
+ * as a dialog keeps them. Defaults to `false`, where tabbing out of the
695
+ * panel moves focus outside it, which dismisses it with `"blur"`. Only
696
+ * the keys are kept: a pointer down outside still dismisses it, and so
697
+ * does focus moved out by any other route.
698
+ */
699
+ readonly trapFocus?: boolean | undefined;
594
700
  }
595
701
  /**
596
702
  * Shows `panel` as an overlay beside `anchor` — a menu, a popover, a filter
@@ -752,4 +858,44 @@ interface ToolbarOverflow {
752
858
  */
753
859
  declare function observeToolbarOverflow(toolbar: HTMLElement, options: ToolbarOverflowOptions): ToolbarOverflow;
754
860
 
755
- export { type AttachedMenu, type BodyCellTarget, type BodyRowTarget, type ColumnDropContext, type ColumnDropTarget, type ColumnResizeGestureHandlers, type ContextMenuRequest, type ContextMenuSource, type ContextMenuTriggerOptions, type DragReorderHandlers, type DragReorderState, type FocusVirtualRange, type GridFocusController, type GridFocusOptions, type GridFocusRows, type GroupByDropTarget, type GroupRowTarget, type InfiniteScroll, type InfiniteScrollOptions, type LiveAnnouncer, type MenuCloseReason, type MenuOptions, type MenuSubmenuFocus, NO_DRAG, type OverlayAlign, type OverlayAnchor, type OverlayDismissReason, type OverlayInitialFocus, type OverlayOptions, type OverlayPlacement, type OverlayPlacementOptions, type OverlayPosition, type OverlayRect, type OverlaySide, type OverlaySize, type PointerPress, type RowVirtualizer, type RowVirtualizerOptions, type ToolbarOverflow, type ToolbarOverflowItem, type ToolbarOverflowOptions, attachContextMenuTrigger, attachInfiniteScroll, attachMenu, attachOverlay, attachToolbar, bodyCellFrom, bodyRowFrom, createGridFocus, createLiveAnnouncer, createRowVirtualizer, findBodyRow, groupRowFrom, measureColumnContent, measurePageSize, observeElementWidth, observeToolbarOverflow, placeOverlay, resolveColumnDropTarget, resolveGroupByDropTarget, startColumnResizeGesture, startDragReorder };
861
+ /** What `printDocument` prints: a document's title, its body's markup and its stylesheet. */
862
+ interface PrintDocumentOptions {
863
+ /** The document's title, as text — what the browser puts in a page's header and names a saved PDF. */
864
+ readonly title: string;
865
+ /** The `<body>`'s markup, as `buildPrintDocument` writes it. */
866
+ readonly bodyHtml: string;
867
+ /** The document's whole stylesheet — `printStyles(page)`, and anything added after it. */
868
+ readonly styles: string;
869
+ }
870
+ /**
871
+ * Prints a document through a hidden frame: its own page, holding only
872
+ * `bodyHtml` under `styles`, so what is printed is what was built — every
873
+ * row, not the slice of them a virtualised grid has drawn — and nothing of
874
+ * the page around it. The frame loads, waits for its fonts, opens the
875
+ * print dialog, and is removed once the dialog closes, when the promise
876
+ * resolves; focus goes back where it was. A frame rather than a new window,
877
+ * which a popup blocker would stop.
878
+ *
879
+ * One print at a time: a call while a print is open resolves at once
880
+ * without printing.
881
+ */
882
+ declare function printDocument(options: PrintDocumentOptions): Promise<void>;
883
+
884
+ /**
885
+ * The stylesheet a print of `buildPrintDocument`'s markup needs, for `page`.
886
+ * A print frame sees none of the page's CSS, so this carries what makes the
887
+ * table read on paper and nothing of a theme: the paper's size and
888
+ * orientation; a header row repeated at the top of every page; rows kept
889
+ * whole across a page break; neutral one-pixel borders; group headers
890
+ * stepped in by depth; backgrounds printed as they are rather than dropped
891
+ * to save ink; page numbers in the bottom-right margin, where the browser
892
+ * draws `@page` margin boxes; and for `fitToWidth`, a smaller font in fixed
893
+ * columns that wrap their text.
894
+ *
895
+ * The grand total prints once, after the last row — not repeated at the
896
+ * foot of every page, where browsers repeat a `<tfoot>`, as a total of
897
+ * rows the page does not hold would mislead. Add CSS after it to restyle.
898
+ */
899
+ declare function printStyles(page: PrintPage): string;
900
+
901
+ export { type AttachedChecklist, type AttachedMenu, type BodyCellTarget, type BodyRowTarget, type ChecklistOptions, type ClipboardContent, type ColumnDropContext, type ColumnDropTarget, type ColumnResizeGestureHandlers, type ContextMenuRequest, type ContextMenuSource, type ContextMenuTriggerOptions, type DragReorderHandlers, type DragReorderState, type FocusVirtualRange, type GridFocusController, type GridFocusOptions, type GridFocusRows, type GroupByDropTarget, type GroupRowTarget, type InfiniteScroll, type InfiniteScrollOptions, type LiveAnnouncer, type MenuCloseReason, type MenuOptions, type MenuSubmenuFocus, NO_DRAG, type OverlayAlign, type OverlayAnchor, type OverlayDismissReason, type OverlayInitialFocus, type OverlayOptions, type OverlayPlacement, type OverlayPlacementOptions, type OverlayPosition, type OverlayRect, type OverlaySide, type OverlaySize, type PointerPress, type PrintDocumentOptions, type RowVirtualizer, type RowVirtualizerOptions, type ToolbarOverflow, type ToolbarOverflowItem, type ToolbarOverflowOptions, attachChecklist, attachContextMenuTrigger, attachInfiniteScroll, attachMenu, attachOverlay, attachToolbar, bodyCellFrom, bodyRowFrom, createGridFocus, createLiveAnnouncer, createRowVirtualizer, downloadBlob, findBodyRow, groupRowFrom, isNativeCopy, measureColumnContent, measurePageSize, observeElementWidth, observeToolbarOverflow, placeOverlay, printDocument, printStyles, resolveColumnDropTarget, resolveGroupByDropTarget, startColumnResizeGesture, startDragReorder, writeClipboard };