@guiexpert/table 1.1.114 → 1.1.116

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.
@@ -0,0 +1,81 @@
1
+ /**
2
+ * A keyboard move in a grid of tiles ({@link TileLayoutIf}): the tiles are **one sequence** of items, so `previous`
3
+ * and `next` wrap over the end of a row. `first`/`last` are the first and last item.
4
+ *
5
+ * @category Keyboard
6
+ * @since 1.1.115
7
+ */
8
+ export type TileNavigationAction = "previous" | "next" | "up" | "down" | "first" | "last" | "pageUp" | "pageDown";
9
+ /**
10
+ * The geometry {@link navigateTiles} computes with.
11
+ *
12
+ * @category Keyboard
13
+ * @since 1.1.115
14
+ */
15
+ export interface TileNavigationLayoutIf {
16
+ /** Number of shown items. */
17
+ count: number;
18
+ /** Tiles per row (values below 1 count as 1). */
19
+ perRow: number;
20
+ /** Rows of a page for `pageUp`/`pageDown` (values below 1 count as 1). */
21
+ pageRows: number;
22
+ /** Where a move starts without a focused item (default 0): the first item of the first visible row. */
23
+ firstVisible?: number;
24
+ }
25
+ /**
26
+ * The item a keyboard move in a grid of tiles leads to – index arithmetic only, O(1) for any number of items.
27
+ *
28
+ * - `previous` / `next`: one item back / forward, wrapping over the end of a row; the focus stays on the first and
29
+ * on the last item.
30
+ * - `up` / `down`: one row, same column. `down` without an item below goes to the last item if there is an
31
+ * (incomplete) row below, otherwise the focus stays.
32
+ * - `first` / `last`: the first / last item.
33
+ * - `pageUp` / `pageDown`: `pageRows` rows, same column; beyond the start the same column of the first row, beyond
34
+ * the end the same column of the last row (the last item if that tile is empty).
35
+ * - Without a focused item (`index` outside `0 … count - 1`) a move starts at `firstVisible`.
36
+ *
37
+ * @param {number} index - index of the focused item, `-1` if none
38
+ * @param {TileNavigationAction} action - the move
39
+ * @param {TileNavigationLayoutIf} layout - item count, tiles per row, rows per page
40
+ * @returns {number} index of the target item (always inside the items), `-1` without items
41
+ *
42
+ * @example
43
+ * // 5 items, 2 per row: [0 1] [2 3] [4 ·]
44
+ * const layout = { count: 5, perRow: 2, pageRows: 1 };
45
+ * navigateTiles(1, "next", layout); // 2 – wraps into the next row
46
+ * navigateTiles(3, "down", layout); // 4 – no item below: the last item
47
+ * navigateTiles(4, "next", layout); // 4 – stays on the last item
48
+ *
49
+ * @category Keyboard
50
+ * @since 1.1.115
51
+ */
52
+ export declare function navigateTiles(index: number, action: TileNavigationAction, layout: TileNavigationLayoutIf): number;
53
+ /**
54
+ * Row and column of a tile.
55
+ *
56
+ * @param {number} index - index of the item
57
+ * @param {number} perRow - tiles per row (values below 1 count as 1)
58
+ * @returns {[number, number]} `[rowIndex, columnIndex]`, `[-1, -1]` for a negative index
59
+ *
60
+ * @example
61
+ * tileIndexToCell(4, 3); // [1, 1]
62
+ *
63
+ * @category Keyboard
64
+ * @since 1.1.115
65
+ */
66
+ export declare function tileIndexToCell(index: number, perRow: number): [number, number];
67
+ /**
68
+ * The index of the tile in a cell (`rowIndex * perRow + columnIndex`).
69
+ *
70
+ * @param {number} rowIndex - row of the cell
71
+ * @param {number} columnIndex - column of the cell
72
+ * @param {number} perRow - tiles per row (values below 1 count as 1)
73
+ * @returns {number} the index, `-1` for a cell outside the grid (negative, or a column behind the row)
74
+ *
75
+ * @example
76
+ * cellToTileIndex(1, 1, 3); // 4
77
+ *
78
+ * @category Keyboard
79
+ * @since 1.1.115
80
+ */
81
+ export declare function cellToTileIndex(rowIndex: number, columnIndex: number, perRow: number): number;
package/llms.txt CHANGED
@@ -128,6 +128,8 @@ const unsubscribe = tableApi.subscribe({ onMouseClicked: e => console.log("secon
128
128
  focus frame – it only selects nothing.
129
129
  - A double click arrives as a click with `clickCount: 1`, then one with `clickCount: 2`. On a header cell a double click
130
130
  sorts (sortable columns), on an editable body cell it opens the editor.
131
+ - "Open this row" for mouse **and** keyboard: `listener.onCellActivated = evt => open(evt.row)` (since 1.1.115) – a
132
+ double click and Enter on the focused cell report the same event (R20). Prefer it to `clickCount === 2`.
131
133
  - Since 1.1.108 a click is reported even if your code renders between `mousedown` and `mouseup` (live data).
132
134
  - There is no built-in context menu – `onContextmenu` + your own HTML. `onMouseMoved` fires per mouse move (keep it cheap).
133
135
  → instructions.md 6.5, training "events-and-context-menu"
@@ -162,7 +164,8 @@ tableApi.triggerAction("NAVIGATE_DOWN");
162
164
  `getActiveCell()` works without configuration. To keep a reference, pass `getFocusModel: () => focusModel`
163
165
  (`new FocusModel("cell")`) and read `focusModel.getFocus()`; `onFocusChanged` reports moves.
164
166
  - Your `keydown` listener and the table's own handler both run (both listen on the host); the table does not stop the
165
- event. Enter also triggers the built-in `ACTIVATE_CELL` (toggles a row checkbox / tree node, else nothing); with
167
+ event. Enter also triggers the built-in `ACTIVATE_CELL` (toggles a row checkbox / tree node / detail row, else it
168
+ reports `onCellActivated` since 1.1.115 – R20; the key is not consumed); with
166
169
  `editing` (Excel-style) Delete also clears the selected cells – remap or disable those keys
167
170
  (`shortcutActionIdMapping`, `shortcutActionsDisabled: true` switches all built-in keys off).
168
171
  - `removeRows(rows, predicate?)` works on a `TableFactory.createTableModel({ rows })` body: O(n) (filters all rows into a
@@ -534,6 +537,52 @@ More (short): tree + checkboxes `TreeFactory` (instructions.md 6.6), master/deta
534
537
  `RowGroupFactory` (5.6), pivot `PivotFactory` (5.7), calculated columns `valueGetter`/`formula` (5.2, 5.9), spreadsheet
535
538
  `SpreadsheetFactory.create` (6.25), cover grid (5.10), totals footer `footerAggregates` (5.4), row numbers (5.2).
536
539
 
540
+ ### R20 – Open a row or a cover with Enter and double click; cover grid with the keyboard (since 1.1.115)
541
+
542
+ ```ts
543
+ import {
544
+ AreaIdent, AreaModelIf, CellRendererIf, CoverGridFactory, EventAdapter, GeCellActivateEvent, SimpleDomService,
545
+ TableScope
546
+ } from "@guiexpert/table";
547
+
548
+ interface Book { title: string; coverUrl: string }
549
+ declare const host: HTMLDivElement;
550
+ declare const books: Book[];
551
+ declare function openBook(book: Book): void;
552
+
553
+ const renderer: CellRendererIf = {
554
+ render(cellDiv: HTMLDivElement, _r: number, _c: number, _a: AreaIdent, _m: AreaModelIf, book: any) {
555
+ if (!book) return undefined; // the tiles after the last item are empty
556
+ const img = document.createElement("img");
557
+ img.src = (book as Book).coverUrl;
558
+ img.alt = (book as Book).title; // the accessible name of the tile
559
+ cellDiv.append(img);
560
+ return undefined;
561
+ }
562
+ };
563
+ const tableModel = CoverGridFactory.createCoverGridModel(books, renderer, 160, 240);
564
+ const tableOptions = CoverGridFactory.createCoverGridDefaultOptions(240, () => "books");
565
+ const listener = new EventAdapter();
566
+ listener.onCellActivated = (evt: GeCellActivateEvent) => openBook(evt.value as Book); // Enter AND double click
567
+ const tableApi = new TableScope(host, tableModel, new SimpleDomService(), tableOptions, listener).firstInit().getApi();
568
+ ```
569
+
570
+ - `onCellActivated` works in **every** table: in a list `evt.row` is the row object (`evt.value` the cell value; in a
571
+ tree, row grouping or pivot `evt.row` is a `TreeRow` – your object is `evt.row.data`), in a cover grid `evt.value`
572
+ is the item. `evt.source` = `"keyboard"` | `"mouse"` | `"api"`. Wrappers: `cellActivated`
573
+ (React/Preact/Solid prop, Vue `@cellActivated`, Svelte `on:cellActivated`, Angular `(cellActivated)`, Web Component
574
+ `CustomEvent`).
575
+ - It is reported only if the gesture did nothing else: Enter first toggles a row checkbox, a detail row, a tree node
576
+ and (Excel-style editing) edits or moves down; a double click on an editable cell opens the editor, on the tree
577
+ column it toggles the node. Never on resize/drag handles, on a button/link/input of your renderer, on empty tiles
578
+ or under a loading overlay. A held Enter key reports once.
579
+ - The Enter key is not consumed: a dialog around the table still sees it – `evt.originalEvent?.stopPropagation()`.
580
+ - Cover grid keys (built in, no code): ← → previous/next item with wrap over the end of a row, ↑ ↓ one row,
581
+ Home/End first/last item, Page Up/Down, Tab focuses the first visible item. The focus follows the **item** after
582
+ `sort()`, filter and resize. Do not set `shortcutActionsDisabled: true` (older examples did).
583
+ - Focus frame: `tableOptions.focusFrame: "always"` (default) | `"keyboard"` (cover grid default, like `:focus-visible`)
584
+ | `"never"`. → instructions.md 5.10
585
+
537
586
  ## Pitfalls
538
587
 
539
588
  Symptom → cause → fix.
@@ -572,7 +621,15 @@ Symptom → cause → fix.
572
621
  - **`instanceof AreaModelTree` is false** → two copies of the core in the bundle → `isAreaModelTree(x)`, `isTreeRow(x)`;
573
622
  dedupe `@guiexpert/table`.
574
623
  - **TypeScript: unknown option** → "corrected" a misspelled API → use `showCheckboxWihoutExtraColumn`, `isHeaderVisibe`,
575
- `emmitDataKey`, `createCoverGrisDefaultOptions` as they are.
624
+ `emmitDataKey` as they are. (`createCoverGrisDefaultOptions` has a correctly spelled alias since 1.1.115:
625
+ `createCoverGridDefaultOptions`.)
626
+ - **The focus frame is hidden with CSS (`.ge-table-focus-border { display: none }`) or `new FocusModel("none")`** → CSS
627
+ takes the frame from keyboard users, the focus model type is not evaluated → `tableOptions.focusFrame: "keyboard"`
628
+ (only after keys) or `"never"` (since 1.1.115, R20).
629
+ - **A cover grid cannot be used with the keyboard / arrow keys stop at the end of a row** → `shortcutActionsDisabled:
630
+ true` from old examples, or a version before 1.1.115 → remove the option; the grid navigates item by item (R20).
631
+ - **A double click opens the item, Enter does nothing** → only `onMouseClicked` with `clickCount === 2` is handled →
632
+ `onCellActivated` (R20).
576
633
  - **Own `mousedown`/`mouseup`/`dblclick` listeners on the header** (to save widths, lock a column, fit on double click)
577
634
  → the table had no column events before 1.1.110 → `onColumnResizeEnd` / `onColumnMoveEnd` (R18),
578
635
  `ColumnDef.resizable: false` / `movable: false`, the built-in double click (`columnAutoWidth`).
@@ -596,6 +653,11 @@ Full answers: instructions.md section 6.26 (https://github.com/guiexperttable/mo
596
653
  - Variable row heights: implement `getRowHeight(i)`; `getConstantRowHeight()` only if all rows are equally high. `defaultRowHeights` only applies to models the factory builds or whose `getRowHeight()` returns 0.
597
654
  - Save the column layout when the user resizes or moves a column: `onColumnResizeEnd` / `onColumnMoveEnd` (wrappers `columnResizeEnd`, `columnMoveEnd`, since 1.1.110) – once per drag, after the change; read `tableApi.getState(["columns"])` there. Lock a column: `ColumnDef.resizable: false`, `movable: false`. Double click on the column border fits the width (`columnAutoWidth`, `tableApi.autoResizeColumn(column)`).
598
655
  - Built-in column filters, Excel value checklist and column chooser: `filterRow: true`, `columnFilterMenu: true`, `tableApi.showColumnChooser(btn)` (since 1.1.114); events `onFilterChanged` (wrapper `filterChanged`); state part `"filters"` (`autoRestoreFilterState: true`); server-side via `columnFilter: { managed: false }`. → R19, instructions.md 6.28.
656
+ - Open a row or a cover with Enter or a double click: `listener.onCellActivated = evt => open(evt.row ?? evt.value)` (wrappers `cellActivated`, since 1.1.115) – one handler for keyboard and mouse; only if the gesture did nothing else (checkbox, tree node, detail row, editor); the Enter key is not consumed. → R20
657
+ - Hide the focus frame: `tableOptions.focusFrame: "never"`; only while the keyboard is used: `"keyboard"` (default of a cover grid, since 1.1.115). Not with CSS, not with `new FocusModel("none")`.
658
+ - Cover grid with the keyboard (since 1.1.115): built in – arrows move from item to item (wrap at the end of a row), Home/End first/last item, Enter opens, the focus follows the item after sort/filter/resize. → R20
659
+ - Cover grid warns "the body model has no row objects": fixed in 1.1.116 – its scroll state stores the first visible item (`id`/`uuid` or `getRowId(item, index)`), no warning; a resize or a new tile size keeps that item at the top. Never `getRowId: (_row, rowIndex) => rowIndex` for a cover grid (a row holds other items after a resize).
660
+ - `@guiexpert/demo-table-models` makes the bundle ~600 kB bigger: fixed in 1.1.116 (nothing computed on import, `"sideEffects": false`); an app with only `BookCoverRenderer` ≈ 11 kB minified.
599
661
  - Empty table: the host div needs a fixed height and the stylesheet `@guiexpert/table/css/main.css`.
600
662
 
601
663
  ## Feature reference
@@ -633,6 +695,7 @@ What the table can do – one line per feature, details in instructions.md (each
633
695
  - Column drag (since 1.1.110): events EventListenerIf.onColumnResizeStart/End (GeColumnResizeEvent: type "start" | "end" | "cancel", source "mouse" | "dblclick", columnIndex, columnDef, property, oldWidth, newWidth) and onColumnMoveStart/End (GeColumnMoveEvent: type, fromIndex, toIndex, columnDef, property, columnOrder, moved) – only user actions, once per drag, the end after the change, start after 4 px, Escape / tableApi.cancelColumnDrag() = "cancel", tableApi.isColumnDragging(); wrappers columnResizeStart/End, columnMoveStart/End. Locks: ColumnDef.resizable: false (no handle, no double click, no auto width), movable: false (fixed place, applyState keeps it); RowNumberColumnDef has both false; a column stays in its area (west/center/east). Double click on the resize handle fits the width (no sorting): tableOptions.columnAutoWidth: { doubleClick (true), maxRows (10,000: all body rows, above only the rendered rows), getWidth(ctx: ColumnAutoWidthContextIf { columnIndex, columnDef, property, source, firstRenderedRow, lastRenderedRow, measureText(text), getDefaultWidth() }) => number | undefined }, limited by minWidth/maxWidth; tableApi.autoResizeColumn(index | property | ColumnDef) → width | undefined.
634
696
  - Column filters, filter menu and column chooser (since 1.1.114): opt-in persistent filter row `tableOptions.filterRow: true | FilterRowOptionsIf` (visible, debounce, placeholder, height, clearButtonVisible, minInputWidthInPx), Excel-style per-column filter menu `tableOptions.columnFilterMenu: true | ColumnFilterMenuOptionsIf` (showCondition, showValues, applyOnChange, maxValues, virtualized unique-value checklist, async `ColumnDef.filter.getValues`), global `tableOptions.columnFilter: ColumnFilterOptionsIf` (`managed: true | false`, `caseSensitive`, `locale`, `maxValues`), `tableOptions.columnFilterTexts: ColumnFilterTextsIf`; per-column `ColumnDef.filter: false | "text" | "number" | "date" | "boolean" | ColumnFilterColumnOptionsIf` (type, valueGetter, caseSensitive, placeholder, getValues) and `ColumnDef.hideable: false`; shorthand syntax in filter row (`>100`, `10..20`, `=x`, `!=x`, `^a`, `z$`, `""`, `2026-01..2026-03`, tri-state boolean); `TableApi`: `setColumnFilter`, `setColumnFilters`, `clearColumnFilters`, `getColumnFilter`, `getColumnFilters`, `isColumnFiltered`, `setFilterRowVisible`, `isFilterRowVisible`, `showColumnFilterMenu`, `hideColumnFilterMenu`, `showColumnChooser`, `hideColumnChooser`; event `EventListenerIf.onFilterChanged(GeFilterEvent: filters, property, source, rowCount, unfilteredRowCount)` (wrappers: `filterChanged`); composes with `externalFilterFunction` (AND) and live `appendRows` (input focus/caret/IME preserved); state part `"filters"` (`TableStateIf.filters`, `filterRowVisible`, `autoRestoreOptions.autoRestoreFilterState`); keyboard `FOCUS_COLUMN_FILTER` (Ctrl/⌘+Shift+F), `OPEN_COLUMN_FILTER_MENU` (Alt+ArrowDown); top-layer popups (`popover="manual"` with fullscreen/Shadow DOM fallback), RTL & fixed columns; DOM-free engine `parseFilterInput`, `formatFilterCondition`, `compileSingleColumnFilter`, `compileColumnFilterPredicate`, `inferColumnFilterType`, `collectDistinctValues`; CSS `ge-table-filter-row*`, `ge-table-filter-menu*`, `ge-table-column-chooser*`, `--ge-table-filter-*`. Showcase `columnfilter`, demo `apps/table-demo/column-filter.html`.
635
697
  - Live data / log tail (since 1.1.108): tableApi.appendRows(rows, { follow?: "auto" (default: stays at the end if it was at the end, else the first visible row stays) | true (always the end) | false (freeze), maxRows?: ring buffer – oldest rows removed from the start in blocks of ≥ 1 % }) → AppendRowsResultIf { added, shown, removed, following } | false (tree, row groups, pivot, spreadsheet, cell formulas) – AreaModelObjectArray body only, IN PLACE (pushes to your array, no copy), O(k): externalFilterFunction only for the new rows, sorted column / sort(fn) → merged in (binary search, behind equal rows); selection, focus, Shift+arrow anchor and checked rows stay at their rows (RowIndexShift, SelectionModel/FocusModel.adjustForRowChanges – no onSelectionChanged unless a selected row left the buffer); one render pass, none when only rows below the view came in (cells not rebuilt). Held mouse button: "auto" keeps the rows under the pointer and follows again after release. Own AreaModel: append yourself, then tableApi.rowsAppended(count, { follow, removedAtStart }). Not addRows() (copies all rows, resets filter and sort). Showcase logtail, demo apps/table-demo/log-tail.html, LogTailController + createLogTailModelAndOptions in @guiexpert/demo-table-models.
698
+ - Open a cell, tile navigation, focus frame (since 1.1.115): EventListenerIf.onCellActivated(GeCellActivateEvent: areaIdent "body", rowIndex, columnIndex, value, row, source "keyboard" | "mouse" | "api", originalEvent) – Enter on the focused body cell or a double click, in every table, after the built-in jobs (row checkbox, detail row, tree node, editing.enterKey; double click: editor of an editable cell, tree node), not on handles, empty tiles or under a blocking overlay; the Enter key is not consumed; wrappers cellActivated. Cover grid keyboard: AreaModelIf.getTileLayout?(): TileLayoutIf { getTileCount, getTilesPerRow, getTileAt(index), indexOfTile(item) } (CoverGridBodyModel implements it) → the items are one sequence: ←/→ previous/next with wrap (RTL mirrored), ↑/↓ one row (↓ without a tile below: last item), Home/End and Ctrl/⌘+Home/End first/last item, Page Up/Down; empty tiles never focused (keys and mouse); one render per key; the focus follows the item (sort, filter, resize, new items; filtered out → tile at the same index). DOM-free: navigateTiles(index, action, { count, perRow, pageRows, firstVisible }), tileIndexToCell, cellToTileIndex. tableOptions.focusFrame: "always" (default) | "keyboard" (only while the keyboard is used, default of CoverGridFactory.createCoverGridDefaultOptions) | "never"; FocusModel("none") does not hide the frame. CoverGridFactory.createCoverGridDefaultOptions (alias, the old createCoverGrisDefaultOptions is deprecated). Cover grid fixes: at least one column (was 0 → Infinity rows), no empty extra row, sort()/doSort() sort a copy (the app's items array keeps its order).
636
699
  - Custom filtering
637
700
  - In-place cell editing
638
701
  - User-defined key and mouse events
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guiexpert/table",
3
- "version": "1.1.114",
3
+ "version": "1.1.116",
4
4
  "license": "MIT",
5
5
  "author": "Dr. Marc Kronberg <info@gui.expert> (https://gui.expert)",
6
6
  "repository": {