gbs-add-block 1.2.7 → 1.2.8

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.
Files changed (41) hide show
  1. package/README.md +3 -3
  2. package/index.cjs +9 -9
  3. package/package.json +1 -1
  4. package/source/components/datagridbeta/README.md +232 -0
  5. package/source/components/datagridbeta/__tests__/core.test.ts +341 -0
  6. package/source/components/datagridbeta/__tests__/export.test.ts +70 -0
  7. package/source/components/datagridbeta/core/columnHelper.ts +21 -0
  8. package/source/components/datagridbeta/core/columns.ts +288 -0
  9. package/source/components/datagridbeta/core/filtering.ts +237 -0
  10. package/source/components/datagridbeta/core/grid.ts +616 -0
  11. package/source/components/datagridbeta/core/index.ts +14 -0
  12. package/source/components/datagridbeta/core/rows.ts +64 -0
  13. package/source/components/datagridbeta/core/sorting.ts +111 -0
  14. package/source/components/datagridbeta/core/state.ts +82 -0
  15. package/source/components/datagridbeta/core/store.ts +52 -0
  16. package/source/components/datagridbeta/core/types.ts +266 -0
  17. package/source/components/datagridbeta/core/values.ts +98 -0
  18. package/source/components/datagridbeta/core/virtual.ts +85 -0
  19. package/source/components/datagridbeta/export/csv.ts +32 -0
  20. package/source/components/datagridbeta/export/download.ts +12 -0
  21. package/source/components/datagridbeta/export/pdf.ts +61 -0
  22. package/source/components/datagridbeta/export/table.ts +73 -0
  23. package/source/components/datagridbeta/export/xlsx.ts +145 -0
  24. package/source/components/datagridbeta/export/zip.ts +87 -0
  25. package/source/components/datagridbeta/index.ts +7 -0
  26. package/source/components/datagridbeta/react/Cell.tsx +282 -0
  27. package/source/components/datagridbeta/react/ColumnMenu.tsx +135 -0
  28. package/source/components/datagridbeta/react/DataGrid.tsx +296 -0
  29. package/source/components/datagridbeta/react/FilterForm.tsx +142 -0
  30. package/source/components/datagridbeta/react/HeaderRow.tsx +306 -0
  31. package/source/components/datagridbeta/react/Pagination.tsx +107 -0
  32. package/source/components/datagridbeta/react/Popover.tsx +79 -0
  33. package/source/components/datagridbeta/react/Row.tsx +85 -0
  34. package/source/components/datagridbeta/react/Toolbar.tsx +266 -0
  35. package/source/components/datagridbeta/react/Viewport.tsx +167 -0
  36. package/source/components/datagridbeta/react/context.ts +57 -0
  37. package/source/components/datagridbeta/react/hooks.ts +80 -0
  38. package/source/components/datagridbeta/react/icons.tsx +72 -0
  39. package/source/components/datagridbeta/react/keyboard.ts +110 -0
  40. package/source/components/datagridbeta/react/locale.ts +128 -0
  41. package/source/components/datagridbeta/styles.css +717 -0
@@ -0,0 +1,110 @@
1
+ import type { KeyboardEvent } from "react";
2
+ import type { GridEngine } from "../core/grid";
3
+
4
+ const INTERACTIVE = "input, select, textarea, button, a[href], [contenteditable]";
5
+
6
+ /**
7
+ * WAI-ARIA grid keyboard model: arrows, Home/End, Ctrl+Home/End, PageUp/Down,
8
+ * Enter/F2 to edit (or sort on a header), Space to select, Ctrl+A, Ctrl+C.
9
+ */
10
+ export function handleGridKeyDown<T>(event: KeyboardEvent<HTMLElement>, engine: GridEngine<T>): void {
11
+ const model = engine.getModel();
12
+ const target = event.target as HTMLElement;
13
+ const cell = target.closest<HTMLElement>("[data-col-index]");
14
+ if (!model || !cell) return;
15
+
16
+ // Focus is inside the cell: an editor or a custom widget handles its own keys.
17
+ if (cell !== target) {
18
+ if (event.key === "Escape" && !target.closest(".dg-editor")) {
19
+ event.preventDefault();
20
+ cell.focus();
21
+ }
22
+ return;
23
+ }
24
+
25
+ const rowIndex = Number(cell.closest<HTMLElement>("[data-row-index]")?.dataset.rowIndex ?? -1);
26
+ const colIndex = Number(cell.dataset.colIndex);
27
+ const lastRow = model.page.rows.length - 1;
28
+ const lastCol = model.layout.columns.length - 1;
29
+ const rtl = getComputedStyle(cell).direction === "rtl";
30
+ const mod = event.ctrlKey || event.metaKey;
31
+ const options = engine.getOptions();
32
+ const visibleRows = Math.max(
33
+ 1,
34
+ Math.floor((engine.viewport.getSnapshot().height - model.headerHeight) / model.rowHeight) - 1,
35
+ );
36
+ const item = model.layout.columns[colIndex];
37
+ const row = rowIndex >= 0 ? model.page.rows[rowIndex] : undefined;
38
+ const { api } = engine;
39
+ const go = (r: number, c: number) => engine.setActiveCell(r, c);
40
+
41
+ switch (event.key) {
42
+ case "ArrowUp":
43
+ go(rowIndex - 1, colIndex);
44
+ break;
45
+ case "ArrowDown":
46
+ go(rowIndex + 1, colIndex);
47
+ break;
48
+ case "ArrowLeft":
49
+ go(rowIndex, colIndex + (rtl ? 1 : -1));
50
+ break;
51
+ case "ArrowRight":
52
+ go(rowIndex, colIndex + (rtl ? -1 : 1));
53
+ break;
54
+ case "Home":
55
+ go(mod ? -1 : rowIndex, 0);
56
+ break;
57
+ case "End":
58
+ go(mod ? lastRow : rowIndex, lastCol);
59
+ break;
60
+ case "PageUp":
61
+ go(rowIndex === -1 ? -1 : Math.max(0, rowIndex - visibleRows), colIndex);
62
+ break;
63
+ case "PageDown":
64
+ go(Math.min(lastRow, Math.max(0, rowIndex + visibleRows)), colIndex);
65
+ break;
66
+ case "Enter":
67
+ case "F2": {
68
+ if (!item) return;
69
+ if (rowIndex === -1) {
70
+ if (event.key !== "Enter" || !item.column.sortable || options.enableSorting === false) return;
71
+ api.toggleSort(item.column.id, event.shiftKey);
72
+ } else if (row && !item.column.internal && engine.isCellEditable(row.original, item.column)) {
73
+ api.startEditing(row.id, item.column.id);
74
+ } else {
75
+ const inner = cell.querySelector<HTMLElement>(INTERACTIVE);
76
+ if (!inner) return;
77
+ inner.focus();
78
+ }
79
+ break;
80
+ }
81
+ case " ": {
82
+ if (rowIndex === -1 && item?.column.internal) {
83
+ const selection = api.getState().rowSelection;
84
+ const allSelected = model.sortedRows.every(
85
+ (r) => !engine.isRowSelectable(r.original) || selection[r.id],
86
+ );
87
+ api.toggleAllRowsSelected(!allSelected);
88
+ } else if (row && engine.isRowSelectable(row.original)) {
89
+ api.toggleRowSelected(row.id, { range: event.shiftKey });
90
+ } else {
91
+ return;
92
+ }
93
+ break;
94
+ }
95
+ case "a":
96
+ case "A":
97
+ if (!mod || !options.enableRowSelection || options.selectionMode === "single") return;
98
+ api.toggleAllRowsSelected(true);
99
+ break;
100
+ case "c":
101
+ case "C":
102
+ if (!mod || window.getSelection()?.toString()) return;
103
+ void api.copyToClipboard();
104
+ break;
105
+ default:
106
+ return;
107
+ }
108
+
109
+ event.preventDefault();
110
+ }
@@ -0,0 +1,128 @@
1
+ import type { FilterOperator } from "../core/types";
2
+
3
+ export interface LocaleText {
4
+ gridLabel: string;
5
+ search: string;
6
+ searchPlaceholder: string;
7
+ columns: string;
8
+ resetColumns: string;
9
+ export: string;
10
+ exportCsv: string;
11
+ exportExcel: string;
12
+ exportPdf: string;
13
+ density: string;
14
+ densityCompact: string;
15
+ densityStandard: string;
16
+ densityComfortable: string;
17
+ selected(count: string): string;
18
+ clearSelection: string;
19
+ clearFilters: string;
20
+ removeFilter(label: string): string;
21
+ filtered: string;
22
+ noRows: string;
23
+ noResults: string;
24
+ loading: string;
25
+ pagination: string;
26
+ rowsPerPage: string;
27
+ pageRange(from: string, to: string, total: string): string;
28
+ page: string;
29
+ pageOf(total: string): string;
30
+ firstPage: string;
31
+ previousPage: string;
32
+ nextPage: string;
33
+ lastPage: string;
34
+ columnMenu(header: string): string;
35
+ sortAscending: string;
36
+ sortDescending: string;
37
+ clearSort: string;
38
+ pinLeft: string;
39
+ pinRight: string;
40
+ unpin: string;
41
+ hideColumn: string;
42
+ moveLeft: string;
43
+ moveRight: string;
44
+ filter: string;
45
+ filterValue: string;
46
+ filterFrom: string;
47
+ filterTo: string;
48
+ filterOperator: string;
49
+ applyFilter: string;
50
+ clearFilter: string;
51
+ operators: Record<FilterOperator, string>;
52
+ yes: string;
53
+ no: string;
54
+ selectRow: string;
55
+ selectAllRows: string;
56
+ }
57
+
58
+ export const defaultLocaleText: LocaleText = {
59
+ gridLabel: "Data grid",
60
+ search: "Search",
61
+ searchPlaceholder: "Search…",
62
+ columns: "Columns",
63
+ resetColumns: "Reset columns",
64
+ export: "Export",
65
+ exportCsv: "CSV",
66
+ exportExcel: "Excel (.xlsx)",
67
+ exportPdf: "PDF (print)",
68
+ density: "Density",
69
+ densityCompact: "Compact",
70
+ densityStandard: "Standard",
71
+ densityComfortable: "Comfortable",
72
+ selected: (count) => `${count} selected`,
73
+ clearSelection: "Clear",
74
+ clearFilters: "Clear all",
75
+ removeFilter: (label) => `Remove filter: ${label}`,
76
+ filtered: "Filtered",
77
+ noRows: "No rows",
78
+ noResults: "No rows match the current filters",
79
+ loading: "Loading…",
80
+ pagination: "Pagination",
81
+ rowsPerPage: "Rows per page",
82
+ pageRange: (from, to, total) => `${from}–${to} of ${total}`,
83
+ page: "Page",
84
+ pageOf: (total) => `of ${total}`,
85
+ firstPage: "First page",
86
+ previousPage: "Previous page",
87
+ nextPage: "Next page",
88
+ lastPage: "Last page",
89
+ columnMenu: (header) => `${header} column options`,
90
+ sortAscending: "Sort ascending",
91
+ sortDescending: "Sort descending",
92
+ clearSort: "Clear sort",
93
+ pinLeft: "Pin to start",
94
+ pinRight: "Pin to end",
95
+ unpin: "Unpin",
96
+ hideColumn: "Hide column",
97
+ moveLeft: "Move earlier",
98
+ moveRight: "Move later",
99
+ filter: "Filter",
100
+ filterValue: "Value",
101
+ filterFrom: "From",
102
+ filterTo: "To",
103
+ filterOperator: "Condition",
104
+ applyFilter: "Apply",
105
+ clearFilter: "Clear",
106
+ operators: {
107
+ contains: "contains",
108
+ notContains: "does not contain",
109
+ equals: "is",
110
+ notEquals: "is not",
111
+ startsWith: "starts with",
112
+ endsWith: "ends with",
113
+ gt: ">",
114
+ gte: "≥",
115
+ lt: "<",
116
+ lte: "≤",
117
+ between: "between",
118
+ before: "before",
119
+ after: "after",
120
+ in: "is any of",
121
+ isEmpty: "is empty",
122
+ isNotEmpty: "is not empty",
123
+ },
124
+ yes: "Yes",
125
+ no: "No",
126
+ selectRow: "Select row",
127
+ selectAllRows: "Select all rows",
128
+ };