@gridkitjs/react 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +212 -5
- package/dist/index.js +700 -86
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
// src/DataGrid/DataGrid.tsx
|
|
2
2
|
import {
|
|
3
|
+
useEffect as useEffect2,
|
|
3
4
|
useImperativeHandle,
|
|
4
|
-
useMemo as
|
|
5
|
+
useMemo as useMemo4,
|
|
5
6
|
useRef as useRef4,
|
|
6
7
|
useState as useState5
|
|
7
8
|
} from "react";
|
|
8
9
|
import {
|
|
9
10
|
applyColumnOrder,
|
|
11
|
+
computeAggregates,
|
|
10
12
|
defineColumnsFromRows,
|
|
11
13
|
fitColumnsToWidth,
|
|
12
14
|
groupRows,
|
|
13
15
|
moveColumnBefore,
|
|
16
|
+
paginateRows as paginateRows2,
|
|
14
17
|
resolveColumnWidths,
|
|
15
18
|
resolveRowId,
|
|
16
19
|
resolveShownRows,
|
|
17
|
-
totalColumnWidth
|
|
20
|
+
totalColumnWidth,
|
|
21
|
+
withGroupAggregates
|
|
18
22
|
} from "@gridkitjs/core";
|
|
19
23
|
|
|
20
24
|
// src/DataGrid/components/GridHeader.tsx
|
|
@@ -34,6 +38,7 @@ function classNames(...values) {
|
|
|
34
38
|
// src/DataGrid/useGridNavigation.ts
|
|
35
39
|
import {
|
|
36
40
|
useEffect,
|
|
41
|
+
useMemo,
|
|
37
42
|
useRef,
|
|
38
43
|
useState
|
|
39
44
|
} from "react";
|
|
@@ -57,13 +62,17 @@ function cellAt(table, focus) {
|
|
|
57
62
|
function useGridNavigation({
|
|
58
63
|
tableRef,
|
|
59
64
|
rowCount,
|
|
60
|
-
columnCount
|
|
65
|
+
columnCount,
|
|
66
|
+
isSkippableRow
|
|
61
67
|
}) {
|
|
62
68
|
const [stored, setStored] = useState({
|
|
63
69
|
rowIndex: HEADER_ROW,
|
|
64
70
|
columnIndex: 0
|
|
65
71
|
});
|
|
66
|
-
const focus =
|
|
72
|
+
const focus = useMemo(
|
|
73
|
+
() => clampFocus(stored, rowCount, columnCount),
|
|
74
|
+
[stored, rowCount, columnCount]
|
|
75
|
+
);
|
|
67
76
|
const pending = useRef(false);
|
|
68
77
|
useEffect(() => {
|
|
69
78
|
if (!pending.current) {
|
|
@@ -108,7 +117,8 @@ function useGridNavigation({
|
|
|
108
117
|
focus,
|
|
109
118
|
rowCount,
|
|
110
119
|
columnCount,
|
|
111
|
-
pageSize()
|
|
120
|
+
pageSize(),
|
|
121
|
+
isSkippableRow
|
|
112
122
|
);
|
|
113
123
|
if (next === null) {
|
|
114
124
|
return;
|
|
@@ -129,7 +139,7 @@ function useGridNavigation({
|
|
|
129
139
|
|
|
130
140
|
// src/DataGrid/useGridSelection.ts
|
|
131
141
|
import {
|
|
132
|
-
useMemo,
|
|
142
|
+
useMemo as useMemo2,
|
|
133
143
|
useRef as useRef2
|
|
134
144
|
} from "react";
|
|
135
145
|
import {
|
|
@@ -169,16 +179,16 @@ function countMessage(count, noun) {
|
|
|
169
179
|
return count === 1 ? `1 ${noun} selected` : `${String(count)} ${noun}s selected`;
|
|
170
180
|
}
|
|
171
181
|
function useAsSet(values) {
|
|
172
|
-
return
|
|
182
|
+
return useMemo2(() => new Set(values), [values]);
|
|
173
183
|
}
|
|
174
184
|
function useIndexedBy(values, key) {
|
|
175
|
-
return
|
|
185
|
+
return useMemo2(
|
|
176
186
|
() => new Map(values.map((value) => [value[key], value])),
|
|
177
187
|
[values, key]
|
|
178
188
|
);
|
|
179
189
|
}
|
|
180
190
|
function useMappedArray(values, key) {
|
|
181
|
-
return
|
|
191
|
+
return useMemo2(() => values.map((value) => value[key]), [values, key]);
|
|
182
192
|
}
|
|
183
193
|
function useGridSelection({
|
|
184
194
|
rows,
|
|
@@ -604,11 +614,39 @@ function GridHeader({
|
|
|
604
614
|
}
|
|
605
615
|
|
|
606
616
|
// src/DataGrid/components/GridBody.tsx
|
|
607
|
-
import { useMemo as
|
|
608
|
-
import {
|
|
617
|
+
import { useMemo as useMemo3 } from "react";
|
|
618
|
+
import {
|
|
619
|
+
groupRowId,
|
|
620
|
+
intentOf as intentOf2
|
|
621
|
+
} from "@gridkitjs/core";
|
|
609
622
|
|
|
610
623
|
// src/DataGrid/components/GridGroupRow.tsx
|
|
611
624
|
import { memo } from "react";
|
|
625
|
+
|
|
626
|
+
// src/DataGrid/components/formatAggregateValue.ts
|
|
627
|
+
function formatAggregateValue(value) {
|
|
628
|
+
if (value === null || value === void 0) {
|
|
629
|
+
return "\u2014";
|
|
630
|
+
}
|
|
631
|
+
if (value instanceof Date) {
|
|
632
|
+
return value.toLocaleString();
|
|
633
|
+
}
|
|
634
|
+
switch (typeof value) {
|
|
635
|
+
case "string":
|
|
636
|
+
case "boolean":
|
|
637
|
+
case "bigint":
|
|
638
|
+
case "symbol":
|
|
639
|
+
return String(value);
|
|
640
|
+
case "number":
|
|
641
|
+
return value.toLocaleString();
|
|
642
|
+
case "function":
|
|
643
|
+
return "(function)";
|
|
644
|
+
default:
|
|
645
|
+
return JSON.stringify(value);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// src/DataGrid/components/GridGroupRow.tsx
|
|
612
650
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
613
651
|
function formatGroupValue(value) {
|
|
614
652
|
if (value === null || value === void 0) {
|
|
@@ -638,16 +676,20 @@ function GridGroupRowComponent({
|
|
|
638
676
|
value,
|
|
639
677
|
expanded,
|
|
640
678
|
count,
|
|
641
|
-
|
|
679
|
+
datasetIndex,
|
|
642
680
|
posinset,
|
|
643
681
|
setsize,
|
|
644
|
-
focused
|
|
682
|
+
focused,
|
|
683
|
+
aggregates,
|
|
684
|
+
results,
|
|
685
|
+
columns
|
|
645
686
|
}) {
|
|
687
|
+
const byId = new Map(columns.map((entry) => [entry.id, entry]));
|
|
646
688
|
return /* @__PURE__ */ jsx2(
|
|
647
689
|
"tr",
|
|
648
690
|
{
|
|
649
691
|
role: "row",
|
|
650
|
-
"aria-rowindex":
|
|
692
|
+
"aria-rowindex": datasetIndex + 2,
|
|
651
693
|
"aria-level": level + 1,
|
|
652
694
|
"aria-expanded": expanded,
|
|
653
695
|
"aria-setsize": setsize,
|
|
@@ -690,7 +732,22 @@ function GridGroupRowComponent({
|
|
|
690
732
|
"(",
|
|
691
733
|
count,
|
|
692
734
|
")"
|
|
693
|
-
] })
|
|
735
|
+
] }),
|
|
736
|
+
aggregates.length > 0 && /* @__PURE__ */ jsx2("span", { className: "group-aggregates", children: aggregates.map((spec) => {
|
|
737
|
+
const key = spec.id ?? spec.columnId;
|
|
738
|
+
const aggregateValue = results.get(key);
|
|
739
|
+
const column = byId.get(spec.columnId);
|
|
740
|
+
const rendered = column?.column.footerTemplate ? column.column.footerTemplate({
|
|
741
|
+
value: aggregateValue,
|
|
742
|
+
rows: []
|
|
743
|
+
}) : formatAggregateValue(aggregateValue);
|
|
744
|
+
const aggregateLabel = spec.id ?? column?.label ?? spec.columnId;
|
|
745
|
+
return /* @__PURE__ */ jsxs2("span", { className: "group-aggregate", children: [
|
|
746
|
+
aggregateLabel,
|
|
747
|
+
": ",
|
|
748
|
+
rendered
|
|
749
|
+
] }, key);
|
|
750
|
+
}) })
|
|
694
751
|
]
|
|
695
752
|
}
|
|
696
753
|
)
|
|
@@ -699,18 +756,82 @@ function GridGroupRowComponent({
|
|
|
699
756
|
}
|
|
700
757
|
);
|
|
701
758
|
}
|
|
702
|
-
var GridGroupRow = memo(
|
|
759
|
+
var GridGroupRow = memo(
|
|
760
|
+
GridGroupRowComponent
|
|
761
|
+
);
|
|
703
762
|
var GridGroupRow_default = GridGroupRow;
|
|
704
763
|
|
|
764
|
+
// src/DataGrid/components/GridGroupSummaryRow.tsx
|
|
765
|
+
import { memo as memo2 } from "react";
|
|
766
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
767
|
+
function GridGroupSummaryRowComponent({
|
|
768
|
+
groupId,
|
|
769
|
+
level,
|
|
770
|
+
datasetIndex,
|
|
771
|
+
results,
|
|
772
|
+
aggregates,
|
|
773
|
+
columns
|
|
774
|
+
}) {
|
|
775
|
+
return /* @__PURE__ */ jsx3(
|
|
776
|
+
"tr",
|
|
777
|
+
{
|
|
778
|
+
role: "row",
|
|
779
|
+
"aria-rowindex": datasetIndex + 2,
|
|
780
|
+
"data-gridkit-group-summary": groupId,
|
|
781
|
+
className: classNames(
|
|
782
|
+
"grid-group-summary-row",
|
|
783
|
+
`is-group-level-${String(level)}`
|
|
784
|
+
),
|
|
785
|
+
children: columns.map((entry) => {
|
|
786
|
+
const specs = aggregates.filter(
|
|
787
|
+
(candidate) => candidate.columnId === entry.id
|
|
788
|
+
);
|
|
789
|
+
const { column } = entry;
|
|
790
|
+
return /* @__PURE__ */ jsxs3(
|
|
791
|
+
"td",
|
|
792
|
+
{
|
|
793
|
+
role: "gridcell",
|
|
794
|
+
"data-gridkit-column": entry.id,
|
|
795
|
+
className: "grid-group-summary-cell",
|
|
796
|
+
style: { textAlign: specs[0]?.alignment ?? entry.alignment },
|
|
797
|
+
children: [
|
|
798
|
+
entry.id === columns[0]?.id && /* @__PURE__ */ jsx3(
|
|
799
|
+
"span",
|
|
800
|
+
{
|
|
801
|
+
className: "grid-group-summary-indent",
|
|
802
|
+
style: { width: `${String(level * 1.25 + 0.5)}rem` },
|
|
803
|
+
"aria-hidden": "true"
|
|
804
|
+
}
|
|
805
|
+
),
|
|
806
|
+
specs.map((spec) => {
|
|
807
|
+
const value = results.get(spec.id ?? spec.columnId);
|
|
808
|
+
return column.footerTemplate ? column.footerTemplate({ value, rows: [] }) : formatAggregateValue(value);
|
|
809
|
+
}).flatMap(
|
|
810
|
+
(rendered, index) => index === 0 ? [rendered] : [", ", rendered]
|
|
811
|
+
)
|
|
812
|
+
]
|
|
813
|
+
},
|
|
814
|
+
entry.id
|
|
815
|
+
);
|
|
816
|
+
})
|
|
817
|
+
}
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
var GridGroupSummaryRow = memo2(
|
|
821
|
+
GridGroupSummaryRowComponent
|
|
822
|
+
);
|
|
823
|
+
var GridGroupSummaryRow_default = GridGroupSummaryRow;
|
|
824
|
+
|
|
705
825
|
// src/DataGrid/components/GridRow.tsx
|
|
706
826
|
import { accessDotted } from "@gridkitjs/core";
|
|
707
|
-
import { memo as
|
|
708
|
-
import { jsx as
|
|
827
|
+
import { memo as memo3 } from "react";
|
|
828
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
709
829
|
function GridRowComponent({
|
|
710
830
|
columns,
|
|
711
831
|
rowId,
|
|
712
832
|
row,
|
|
713
833
|
rowIndex,
|
|
834
|
+
datasetIndex,
|
|
714
835
|
activeColumnId,
|
|
715
836
|
selectedColumnIds,
|
|
716
837
|
selected,
|
|
@@ -719,17 +840,17 @@ function GridRowComponent({
|
|
|
719
840
|
rowsSelectable,
|
|
720
841
|
cellsSelectable
|
|
721
842
|
}) {
|
|
722
|
-
return /* @__PURE__ */
|
|
843
|
+
return /* @__PURE__ */ jsx4(
|
|
723
844
|
"tr",
|
|
724
845
|
{
|
|
725
846
|
role: "row",
|
|
726
|
-
"aria-rowindex":
|
|
847
|
+
"aria-rowindex": datasetIndex + 2,
|
|
727
848
|
...ariaAttr(rowsSelectable, "aria-selected", selected),
|
|
728
849
|
className: classNames("grid-row", selected ? "is-selected" : ""),
|
|
729
850
|
children: columns.map(({ id, column, alignment }, columnIndex) => {
|
|
730
851
|
const value = accessDotted(row, column.field);
|
|
731
852
|
const cellSelected = id === selectedColumnId;
|
|
732
|
-
return /* @__PURE__ */
|
|
853
|
+
return /* @__PURE__ */ jsx4(
|
|
733
854
|
"td",
|
|
734
855
|
{
|
|
735
856
|
role: "gridcell",
|
|
@@ -746,7 +867,14 @@ function GridRowComponent({
|
|
|
746
867
|
column.cellClassName ?? ""
|
|
747
868
|
),
|
|
748
869
|
style: { textAlign: alignment },
|
|
749
|
-
children: column.cellTemplate ? column.cellTemplate({
|
|
870
|
+
children: column.cellTemplate ? column.cellTemplate({
|
|
871
|
+
value,
|
|
872
|
+
row,
|
|
873
|
+
rowIndex,
|
|
874
|
+
datasetIndex,
|
|
875
|
+
rowId,
|
|
876
|
+
selected
|
|
877
|
+
}) : value
|
|
750
878
|
},
|
|
751
879
|
id
|
|
752
880
|
);
|
|
@@ -754,11 +882,11 @@ function GridRowComponent({
|
|
|
754
882
|
}
|
|
755
883
|
);
|
|
756
884
|
}
|
|
757
|
-
var GridRow =
|
|
885
|
+
var GridRow = memo3(GridRowComponent);
|
|
758
886
|
var GridRow_default = GridRow;
|
|
759
887
|
|
|
760
888
|
// src/DataGrid/components/GridBody.tsx
|
|
761
|
-
import { jsx as
|
|
889
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
762
890
|
function cellFrom(target) {
|
|
763
891
|
if (!(target instanceof Element)) {
|
|
764
892
|
return null;
|
|
@@ -789,14 +917,14 @@ function groupRowFrom(target) {
|
|
|
789
917
|
function groupAriaMeta(rows) {
|
|
790
918
|
const totals = /* @__PURE__ */ new Map();
|
|
791
919
|
for (const entry of rows) {
|
|
792
|
-
if (!("kind" in entry)) continue;
|
|
920
|
+
if (!("kind" in entry) || entry.kind !== "group") continue;
|
|
793
921
|
const parentKey = groupRowId(entry.path.slice(0, -1));
|
|
794
922
|
totals.set(parentKey, (totals.get(parentKey) ?? 0) + 1);
|
|
795
923
|
}
|
|
796
924
|
const seen = /* @__PURE__ */ new Map();
|
|
797
925
|
const meta = /* @__PURE__ */ new Map();
|
|
798
926
|
for (const entry of rows) {
|
|
799
|
-
if (!("kind" in entry)) continue;
|
|
927
|
+
if (!("kind" in entry) || entry.kind !== "group") continue;
|
|
800
928
|
const parentKey = groupRowId(entry.path.slice(0, -1));
|
|
801
929
|
const posinset = (seen.get(parentKey) ?? 0) + 1;
|
|
802
930
|
seen.set(parentKey, posinset);
|
|
@@ -813,10 +941,12 @@ function GridBody({
|
|
|
813
941
|
activeColumnId,
|
|
814
942
|
nav,
|
|
815
943
|
selection,
|
|
816
|
-
grouping
|
|
944
|
+
grouping,
|
|
945
|
+
aggregates,
|
|
946
|
+
groupAggregateDisplay
|
|
817
947
|
}) {
|
|
818
948
|
const { selectedCell, rowMode, cellMode } = selection;
|
|
819
|
-
const ariaMeta =
|
|
949
|
+
const ariaMeta = useMemo3(() => groupAriaMeta(rows), [rows]);
|
|
820
950
|
function targetOf(target) {
|
|
821
951
|
const position = cellFrom(target);
|
|
822
952
|
const entry = position === null ? void 0 : rows[position.rowIndex];
|
|
@@ -834,7 +964,7 @@ function GridBody({
|
|
|
834
964
|
selection.selectCell({ rowId, columnId }, intent);
|
|
835
965
|
}
|
|
836
966
|
}
|
|
837
|
-
return /* @__PURE__ */
|
|
967
|
+
return /* @__PURE__ */ jsx5(
|
|
838
968
|
"tbody",
|
|
839
969
|
{
|
|
840
970
|
className: "grid-body",
|
|
@@ -886,8 +1016,42 @@ function GridBody({
|
|
|
886
1016
|
}
|
|
887
1017
|
nav.onKeyDown(event);
|
|
888
1018
|
},
|
|
889
|
-
children: rows.map(
|
|
890
|
-
(
|
|
1019
|
+
children: rows.map((entry) => {
|
|
1020
|
+
if (!("kind" in entry)) {
|
|
1021
|
+
return /* @__PURE__ */ jsx5(
|
|
1022
|
+
GridRow_default,
|
|
1023
|
+
{
|
|
1024
|
+
columns,
|
|
1025
|
+
rowId: entry.rowId,
|
|
1026
|
+
row: entry.row,
|
|
1027
|
+
rowIndex: entry.rowIndex,
|
|
1028
|
+
datasetIndex: entry.datasetIndex,
|
|
1029
|
+
activeColumnId,
|
|
1030
|
+
selectedColumnIds: selection.selectedColumnIds,
|
|
1031
|
+
selected: selection.selectedRowIds.has(entry.rowId),
|
|
1032
|
+
selectedColumnId: selectedCell?.rowId === entry.rowId ? selectedCell.columnId : null,
|
|
1033
|
+
focusedColumnIndex: nav.focus.rowIndex === entry.rowIndex ? nav.focus.columnIndex : null,
|
|
1034
|
+
rowsSelectable: rowMode !== false,
|
|
1035
|
+
cellsSelectable: cellMode !== false
|
|
1036
|
+
},
|
|
1037
|
+
entry.rowId
|
|
1038
|
+
);
|
|
1039
|
+
}
|
|
1040
|
+
if (entry.kind === "group-summary") {
|
|
1041
|
+
return /* @__PURE__ */ jsx5(
|
|
1042
|
+
GridGroupSummaryRow_default,
|
|
1043
|
+
{
|
|
1044
|
+
groupId: entry.groupId,
|
|
1045
|
+
level: entry.level,
|
|
1046
|
+
datasetIndex: entry.datasetIndex,
|
|
1047
|
+
results: entry.aggregates,
|
|
1048
|
+
aggregates,
|
|
1049
|
+
columns
|
|
1050
|
+
},
|
|
1051
|
+
`${entry.groupId}-summary`
|
|
1052
|
+
);
|
|
1053
|
+
}
|
|
1054
|
+
return /* @__PURE__ */ jsx5(
|
|
891
1055
|
GridGroupRow_default,
|
|
892
1056
|
{
|
|
893
1057
|
columnCount: columns.length,
|
|
@@ -897,34 +1061,133 @@ function GridBody({
|
|
|
897
1061
|
value: entry.value,
|
|
898
1062
|
expanded: entry.expanded,
|
|
899
1063
|
count: entry.count,
|
|
900
|
-
|
|
1064
|
+
datasetIndex: entry.datasetIndex,
|
|
901
1065
|
posinset: ariaMeta.get(entry.groupId)?.posinset ?? 1,
|
|
902
1066
|
setsize: ariaMeta.get(entry.groupId)?.setsize ?? 1,
|
|
1067
|
+
aggregates: groupAggregateDisplay === "inline" ? aggregates : [],
|
|
1068
|
+
results: entry.aggregates,
|
|
1069
|
+
columns,
|
|
903
1070
|
focused: nav.focus.rowIndex === entry.rowIndex
|
|
904
1071
|
},
|
|
905
1072
|
entry.groupId
|
|
906
|
-
)
|
|
907
|
-
|
|
908
|
-
{
|
|
909
|
-
columns,
|
|
910
|
-
rowId: entry.rowId,
|
|
911
|
-
row: entry.row,
|
|
912
|
-
rowIndex: entry.rowIndex,
|
|
913
|
-
activeColumnId,
|
|
914
|
-
selectedColumnIds: selection.selectedColumnIds,
|
|
915
|
-
selected: selection.selectedRowIds.has(entry.rowId),
|
|
916
|
-
selectedColumnId: selectedCell?.rowId === entry.rowId ? selectedCell.columnId : null,
|
|
917
|
-
focusedColumnIndex: nav.focus.rowIndex === entry.rowIndex ? nav.focus.columnIndex : null,
|
|
918
|
-
rowsSelectable: rowMode !== false,
|
|
919
|
-
cellsSelectable: cellMode !== false
|
|
920
|
-
},
|
|
921
|
-
entry.rowId
|
|
922
|
-
)
|
|
923
|
-
)
|
|
1073
|
+
);
|
|
1074
|
+
})
|
|
924
1075
|
}
|
|
925
1076
|
);
|
|
926
1077
|
}
|
|
927
1078
|
|
|
1079
|
+
// src/DataGrid/components/GridFooter.tsx
|
|
1080
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
1081
|
+
function GridFooter({
|
|
1082
|
+
columns,
|
|
1083
|
+
aggregates,
|
|
1084
|
+
results,
|
|
1085
|
+
rows
|
|
1086
|
+
}) {
|
|
1087
|
+
return /* @__PURE__ */ jsx6("tfoot", { children: /* @__PURE__ */ jsx6("tr", { className: "grid-footer", role: "row", children: columns.map((entry) => {
|
|
1088
|
+
const specs = aggregates.filter(
|
|
1089
|
+
(candidate) => candidate.columnId === entry.id
|
|
1090
|
+
);
|
|
1091
|
+
const { column } = entry;
|
|
1092
|
+
return /* @__PURE__ */ jsx6(
|
|
1093
|
+
"td",
|
|
1094
|
+
{
|
|
1095
|
+
role: "gridcell",
|
|
1096
|
+
"data-gridkit-column": entry.id,
|
|
1097
|
+
className: "grid-footer-cell",
|
|
1098
|
+
style: { textAlign: specs[0]?.alignment ?? entry.alignment },
|
|
1099
|
+
children: specs.map((spec) => {
|
|
1100
|
+
const value = results.get(spec.id ?? spec.columnId);
|
|
1101
|
+
return column.footerTemplate ? column.footerTemplate({ value, rows }) : formatAggregateValue(value);
|
|
1102
|
+
}).flatMap(
|
|
1103
|
+
(rendered, index) => index === 0 ? [rendered] : [", ", rendered]
|
|
1104
|
+
)
|
|
1105
|
+
},
|
|
1106
|
+
entry.id
|
|
1107
|
+
);
|
|
1108
|
+
}) }) });
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// src/DataGrid/components/GridPager.tsx
|
|
1112
|
+
import { paginationWindow } from "@gridkitjs/core";
|
|
1113
|
+
import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1114
|
+
function GridPager({ pager, config }) {
|
|
1115
|
+
const { pagination, pageCount, currentPage } = pager;
|
|
1116
|
+
const variant = config?.variant ?? "compact";
|
|
1117
|
+
const sizeOptions = config?.sizeOptions;
|
|
1118
|
+
return /* @__PURE__ */ jsxs4("div", { className: "gridkit-grid-pager", role: "group", "aria-label": "Pagination", children: [
|
|
1119
|
+
/* @__PURE__ */ jsx7(
|
|
1120
|
+
"button",
|
|
1121
|
+
{
|
|
1122
|
+
type: "button",
|
|
1123
|
+
className: "grid-pager-button",
|
|
1124
|
+
disabled: pagination.pageIndex <= 0,
|
|
1125
|
+
onClick: () => {
|
|
1126
|
+
pager.previousPage();
|
|
1127
|
+
},
|
|
1128
|
+
children: "Previous"
|
|
1129
|
+
}
|
|
1130
|
+
),
|
|
1131
|
+
variant === "numbered" ? paginationWindow(currentPage, pageCount, {
|
|
1132
|
+
boundaryCount: config?.boundaryCount,
|
|
1133
|
+
siblingCount: config?.siblingCount
|
|
1134
|
+
}).map(
|
|
1135
|
+
(entry, index) => entry === "ellipsis" ? /* @__PURE__ */ jsx7(
|
|
1136
|
+
"span",
|
|
1137
|
+
{
|
|
1138
|
+
className: "grid-pager-ellipsis",
|
|
1139
|
+
"aria-hidden": "true",
|
|
1140
|
+
children: "\u2026"
|
|
1141
|
+
},
|
|
1142
|
+
`ellipsis-${String(index)}`
|
|
1143
|
+
) : /* @__PURE__ */ jsx7(
|
|
1144
|
+
"button",
|
|
1145
|
+
{
|
|
1146
|
+
type: "button",
|
|
1147
|
+
className: "grid-pager-button",
|
|
1148
|
+
"aria-label": `Page ${String(entry)}`,
|
|
1149
|
+
"aria-current": entry === currentPage ? "page" : void 0,
|
|
1150
|
+
onClick: () => {
|
|
1151
|
+
pager.goToPage(entry - 1);
|
|
1152
|
+
},
|
|
1153
|
+
children: entry
|
|
1154
|
+
},
|
|
1155
|
+
entry
|
|
1156
|
+
)
|
|
1157
|
+
) : /* @__PURE__ */ jsxs4("span", { className: "grid-pager-status", children: [
|
|
1158
|
+
"Page ",
|
|
1159
|
+
pageCount === 0 ? 0 : currentPage,
|
|
1160
|
+
" of ",
|
|
1161
|
+
pageCount
|
|
1162
|
+
] }),
|
|
1163
|
+
/* @__PURE__ */ jsx7(
|
|
1164
|
+
"button",
|
|
1165
|
+
{
|
|
1166
|
+
type: "button",
|
|
1167
|
+
className: "grid-pager-button",
|
|
1168
|
+
disabled: pagination.pageIndex >= pageCount - 1,
|
|
1169
|
+
onClick: () => {
|
|
1170
|
+
pager.nextPage();
|
|
1171
|
+
},
|
|
1172
|
+
children: "Next"
|
|
1173
|
+
}
|
|
1174
|
+
),
|
|
1175
|
+
sizeOptions !== void 0 && sizeOptions.length > 0 && /* @__PURE__ */ jsxs4("label", { className: "grid-pager-page-size", children: [
|
|
1176
|
+
"Rows per page",
|
|
1177
|
+
/* @__PURE__ */ jsx7(
|
|
1178
|
+
"select",
|
|
1179
|
+
{
|
|
1180
|
+
value: pagination.pageSize,
|
|
1181
|
+
onChange: (event) => {
|
|
1182
|
+
pager.setPageSize(Number(event.target.value));
|
|
1183
|
+
},
|
|
1184
|
+
children: sizeOptions.map((size) => /* @__PURE__ */ jsx7("option", { value: size, children: size }, size))
|
|
1185
|
+
}
|
|
1186
|
+
)
|
|
1187
|
+
] })
|
|
1188
|
+
] });
|
|
1189
|
+
}
|
|
1190
|
+
|
|
928
1191
|
// src/DataGrid/components/GroupByBar.tsx
|
|
929
1192
|
import { createPortal as createPortal2 } from "react-dom";
|
|
930
1193
|
import { resolveKeyboardDropTarget } from "@gridkitjs/core";
|
|
@@ -1087,7 +1350,7 @@ function useGroupByDrag({
|
|
|
1087
1350
|
}
|
|
1088
1351
|
|
|
1089
1352
|
// src/DataGrid/components/GroupByBar.tsx
|
|
1090
|
-
import { jsx as
|
|
1353
|
+
import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1091
1354
|
function GroupByBar({
|
|
1092
1355
|
columns,
|
|
1093
1356
|
grouping,
|
|
@@ -1121,7 +1384,7 @@ function GroupByBar({
|
|
|
1121
1384
|
}
|
|
1122
1385
|
grouping.moveGroupBy(columnId, beforeColumnId);
|
|
1123
1386
|
}
|
|
1124
|
-
return /* @__PURE__ */
|
|
1387
|
+
return /* @__PURE__ */ jsxs5(
|
|
1125
1388
|
"div",
|
|
1126
1389
|
{
|
|
1127
1390
|
className: classNames(
|
|
@@ -1133,12 +1396,12 @@ function GroupByBar({
|
|
|
1133
1396
|
role: "group",
|
|
1134
1397
|
"aria-label": "Grouped by",
|
|
1135
1398
|
children: [
|
|
1136
|
-
showPlaceholder && /* @__PURE__ */
|
|
1399
|
+
showPlaceholder && /* @__PURE__ */ jsx8("span", { className: "group-by-bar-placeholder", children: "Drag a column here to group by it" }),
|
|
1137
1400
|
groupBy.map((entry, index) => {
|
|
1138
1401
|
const dropBefore = activeDropTarget?.beforeColumnId === entry.columnId;
|
|
1139
1402
|
const dropAfter = activeDropTarget?.beforeColumnId === null && index === groupBy.length - 1;
|
|
1140
1403
|
const dragging = chipDrag.draggedColumnId === entry.columnId;
|
|
1141
|
-
return /* @__PURE__ */
|
|
1404
|
+
return /* @__PURE__ */ jsxs5(
|
|
1142
1405
|
"span",
|
|
1143
1406
|
{
|
|
1144
1407
|
className: classNames(
|
|
@@ -1165,8 +1428,8 @@ function GroupByBar({
|
|
|
1165
1428
|
}
|
|
1166
1429
|
},
|
|
1167
1430
|
children: [
|
|
1168
|
-
/* @__PURE__ */
|
|
1169
|
-
/* @__PURE__ */
|
|
1431
|
+
/* @__PURE__ */ jsx8("span", { className: "group-by-chip-label", children: labelFor(entry.columnId) }),
|
|
1432
|
+
/* @__PURE__ */ jsx8(
|
|
1170
1433
|
"button",
|
|
1171
1434
|
{
|
|
1172
1435
|
type: "button",
|
|
@@ -1187,7 +1450,7 @@ function GroupByBar({
|
|
|
1187
1450
|
);
|
|
1188
1451
|
}),
|
|
1189
1452
|
chipDrag.draggedColumnId !== null && chipDrag.ghostTransform !== null && createPortal2(
|
|
1190
|
-
/* @__PURE__ */
|
|
1453
|
+
/* @__PURE__ */ jsx8(
|
|
1191
1454
|
"span",
|
|
1192
1455
|
{
|
|
1193
1456
|
className: "group-by-chip drag-ghost",
|
|
@@ -1421,6 +1684,52 @@ function useElementWidth(ref, enabled) {
|
|
|
1421
1684
|
return width;
|
|
1422
1685
|
}
|
|
1423
1686
|
|
|
1687
|
+
// src/DataGrid/usePagination.ts
|
|
1688
|
+
import {
|
|
1689
|
+
paginateRows
|
|
1690
|
+
} from "@gridkitjs/core";
|
|
1691
|
+
function usePagination({
|
|
1692
|
+
pagination,
|
|
1693
|
+
setPagination,
|
|
1694
|
+
rows,
|
|
1695
|
+
onPaginationChange
|
|
1696
|
+
}) {
|
|
1697
|
+
const { pageCount, pageIndex } = paginateRows(rows, pagination);
|
|
1698
|
+
function commit(next) {
|
|
1699
|
+
commitIfChanged(pagination, next, setPagination, (committed) => {
|
|
1700
|
+
const { pageCount: committedPageCount } = paginateRows(rows, committed);
|
|
1701
|
+
onPaginationChange?.({
|
|
1702
|
+
pagination: committed,
|
|
1703
|
+
pageCount: committedPageCount
|
|
1704
|
+
});
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
function goToPage(nextPageIndex) {
|
|
1708
|
+
const { pageIndex: clamped } = paginateRows(rows, {
|
|
1709
|
+
...pagination,
|
|
1710
|
+
pageIndex: nextPageIndex
|
|
1711
|
+
});
|
|
1712
|
+
commit({ ...pagination, pageIndex: clamped });
|
|
1713
|
+
}
|
|
1714
|
+
return {
|
|
1715
|
+
pagination,
|
|
1716
|
+
pageCount,
|
|
1717
|
+
currentPage: Math.min(pagination.pageIndex + 1, pageCount),
|
|
1718
|
+
goToPage,
|
|
1719
|
+
nextPage: () => {
|
|
1720
|
+
goToPage(pageIndex + 1);
|
|
1721
|
+
},
|
|
1722
|
+
previousPage: () => {
|
|
1723
|
+
goToPage(pageIndex - 1);
|
|
1724
|
+
},
|
|
1725
|
+
setPageSize: (pageSize) => {
|
|
1726
|
+
const next = { pageIndex: 0, pageSize };
|
|
1727
|
+
const { pageIndex: clamped } = paginateRows(rows, next);
|
|
1728
|
+
commit({ ...next, pageIndex: clamped });
|
|
1729
|
+
}
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1424
1733
|
// src/DataGrid/useRowGrouping.ts
|
|
1425
1734
|
import {
|
|
1426
1735
|
collapseAllGroups,
|
|
@@ -1476,7 +1785,9 @@ function useRowGrouping({
|
|
|
1476
1785
|
}
|
|
1477
1786
|
|
|
1478
1787
|
// src/DataGrid/DataGrid.tsx
|
|
1479
|
-
import { jsx as
|
|
1788
|
+
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1789
|
+
var DEFAULT_PAGE_SIZE = 25;
|
|
1790
|
+
var NO_AGGREGATES = [];
|
|
1480
1791
|
function DataGridComponent({
|
|
1481
1792
|
dataSource,
|
|
1482
1793
|
columns,
|
|
@@ -1507,6 +1818,12 @@ function DataGridComponent({
|
|
|
1507
1818
|
defaultGroupExpansion,
|
|
1508
1819
|
onGroupExpansionChange,
|
|
1509
1820
|
defaultFilter,
|
|
1821
|
+
paginated = false,
|
|
1822
|
+
defaultPagination,
|
|
1823
|
+
pager,
|
|
1824
|
+
onPaginationChange,
|
|
1825
|
+
aggregates,
|
|
1826
|
+
groupAggregateDisplay = "inline",
|
|
1510
1827
|
label,
|
|
1511
1828
|
labelledBy,
|
|
1512
1829
|
ref,
|
|
@@ -1518,6 +1835,7 @@ function DataGridComponent({
|
|
|
1518
1835
|
const viewportRef = useRef4(null);
|
|
1519
1836
|
const tableRef = useRef4(null);
|
|
1520
1837
|
const viewportWidth = useElementWidth(viewportRef, resizeMode === "fit");
|
|
1838
|
+
const subscribersRef = useRef4(/* @__PURE__ */ new Set());
|
|
1521
1839
|
const [sizing, setSizing] = useState5(
|
|
1522
1840
|
defaultColumnSizing ?? {}
|
|
1523
1841
|
);
|
|
@@ -1530,6 +1848,9 @@ function DataGridComponent({
|
|
|
1530
1848
|
defaultGroupExpansion ?? []
|
|
1531
1849
|
);
|
|
1532
1850
|
const [filter] = useState5(defaultFilter ?? []);
|
|
1851
|
+
const [pagination, setPagination] = useState5(
|
|
1852
|
+
defaultPagination ?? { pageIndex: 0, pageSize: DEFAULT_PAGE_SIZE }
|
|
1853
|
+
);
|
|
1533
1854
|
const [announcement, setAnnouncement] = useState5("");
|
|
1534
1855
|
const [rowSelection, setRowSelection] = useState5(
|
|
1535
1856
|
defaultRowSelection ?? []
|
|
@@ -1540,25 +1861,26 @@ function DataGridComponent({
|
|
|
1540
1861
|
const [cellSelection, setCellSelection] = useState5(
|
|
1541
1862
|
defaultCellSelection ?? null
|
|
1542
1863
|
);
|
|
1543
|
-
const rows =
|
|
1864
|
+
const rows = useMemo4(
|
|
1544
1865
|
() => dataSource?.map((row, rowIndex) => ({
|
|
1545
1866
|
rowId: resolveRowId(row, rowIndex, getRowId),
|
|
1546
1867
|
row,
|
|
1547
|
-
rowIndex
|
|
1868
|
+
rowIndex,
|
|
1869
|
+
datasetIndex: rowIndex
|
|
1548
1870
|
})) ?? [],
|
|
1549
1871
|
[dataSource, getRowId]
|
|
1550
1872
|
);
|
|
1551
|
-
const definedColumns =
|
|
1873
|
+
const definedColumns = useMemo4(() => {
|
|
1552
1874
|
if (columns && columns.length !== 0) return columns;
|
|
1553
1875
|
if (dataSource && dataSource.length > 0)
|
|
1554
1876
|
return defineColumnsFromRows(dataSource);
|
|
1555
1877
|
return [];
|
|
1556
1878
|
}, [columns, dataSource]);
|
|
1557
|
-
const orderedColumns =
|
|
1879
|
+
const orderedColumns = useMemo4(
|
|
1558
1880
|
() => applyColumnOrder(definedColumns, order),
|
|
1559
1881
|
[definedColumns, order]
|
|
1560
1882
|
);
|
|
1561
|
-
const resolved =
|
|
1883
|
+
const resolved = useMemo4(() => {
|
|
1562
1884
|
const widths = resolveColumnWidths(orderedColumns, sizing, {
|
|
1563
1885
|
sizes: columnSizeDefaults,
|
|
1564
1886
|
resizable: resizableColumns,
|
|
@@ -1576,19 +1898,57 @@ function DataGridComponent({
|
|
|
1576
1898
|
reorderableColumns,
|
|
1577
1899
|
groupByDraggableColumns
|
|
1578
1900
|
]);
|
|
1579
|
-
const shownRows =
|
|
1901
|
+
const shownRows = useMemo4(
|
|
1580
1902
|
() => resolveShownRows(rows, filter, sort, resolved),
|
|
1581
1903
|
[rows, filter, sort, resolved]
|
|
1582
1904
|
);
|
|
1583
|
-
const displayRows =
|
|
1905
|
+
const displayRows = useMemo4(
|
|
1584
1906
|
() => groupRows(shownRows, groupBy, expansion, resolved),
|
|
1585
1907
|
[shownRows, groupBy, expansion, resolved]
|
|
1586
1908
|
);
|
|
1587
|
-
const
|
|
1588
|
-
|
|
1909
|
+
const activeAggregates = aggregates ?? NO_AGGREGATES;
|
|
1910
|
+
const aggregatedRows = useMemo4(
|
|
1911
|
+
() => withGroupAggregates(
|
|
1912
|
+
displayRows,
|
|
1913
|
+
shownRows,
|
|
1914
|
+
groupBy,
|
|
1915
|
+
activeAggregates,
|
|
1916
|
+
resolved,
|
|
1917
|
+
groupAggregateDisplay
|
|
1918
|
+
),
|
|
1919
|
+
[
|
|
1920
|
+
displayRows,
|
|
1921
|
+
shownRows,
|
|
1922
|
+
groupBy,
|
|
1923
|
+
activeAggregates,
|
|
1924
|
+
resolved,
|
|
1925
|
+
groupAggregateDisplay
|
|
1926
|
+
]
|
|
1927
|
+
);
|
|
1928
|
+
const grandTotal = useMemo4(
|
|
1929
|
+
() => computeAggregates(
|
|
1930
|
+
shownRows.map((entry) => entry.row),
|
|
1931
|
+
activeAggregates,
|
|
1932
|
+
resolved
|
|
1933
|
+
),
|
|
1934
|
+
[shownRows, activeAggregates, resolved]
|
|
1935
|
+
);
|
|
1936
|
+
const paginatedRows = useMemo4(
|
|
1937
|
+
() => paginated ? paginateRows2(aggregatedRows, pagination) : { rows: aggregatedRows, pageCount: 1, pageIndex: 0 },
|
|
1938
|
+
[paginated, aggregatedRows, pagination]
|
|
1939
|
+
);
|
|
1940
|
+
const paginationSnapshot = useMemo4(
|
|
1941
|
+
() => ({
|
|
1942
|
+
pageIndex: paginatedRows.pageIndex,
|
|
1943
|
+
pageSize: pagination.pageSize
|
|
1944
|
+
}),
|
|
1945
|
+
[paginatedRows.pageIndex, pagination.pageSize]
|
|
1946
|
+
);
|
|
1947
|
+
const displayDataRows = useMemo4(
|
|
1948
|
+
() => groupBy.length === 0 && !paginated ? shownRows : paginatedRows.rows.filter(
|
|
1589
1949
|
(entry) => !("kind" in entry)
|
|
1590
1950
|
),
|
|
1591
|
-
[
|
|
1951
|
+
[paginatedRows, groupBy.length, paginated, shownRows]
|
|
1592
1952
|
);
|
|
1593
1953
|
function columnName(columnId) {
|
|
1594
1954
|
const entry = resolved.find((candidate) => candidate.id === columnId);
|
|
@@ -1652,15 +2012,26 @@ function DataGridComponent({
|
|
|
1652
2012
|
tableRef,
|
|
1653
2013
|
// Group headers are addressable rows too — the whole point of the flat
|
|
1654
2014
|
// `DisplayRow[]` shape is that they share one position space with data
|
|
1655
|
-
// rows, so navigation counts them the same way.
|
|
1656
|
-
|
|
1657
|
-
|
|
2015
|
+
// rows, so navigation counts them the same way. Page-relative
|
|
2016
|
+
// (`paginatedRows`, not `displayRows`): arrow keys operate on what's
|
|
2017
|
+
// actually in the DOM, which is the current page — a different "page"
|
|
2018
|
+
// concept than `useGridNavigation`'s own Page Up/Down viewport scrolling.
|
|
2019
|
+
rowCount: paginatedRows.rows.length,
|
|
2020
|
+
columnCount: resolved.length,
|
|
2021
|
+
// A group's own summary row (`groupAggregateDisplay: "row"`) occupies a
|
|
2022
|
+
// real slot in `rowCount` above — its DOM position has to line up with
|
|
2023
|
+
// everything else — but is presentational, never a tab stop: arrow-key
|
|
2024
|
+
// vertical movement steps over it rather than landing there.
|
|
2025
|
+
isSkippableRow: (rowIndex) => {
|
|
2026
|
+
const entry = paginatedRows.rows[rowIndex];
|
|
2027
|
+
return entry !== void 0 && "kind" in entry && entry.kind === "group-summary";
|
|
2028
|
+
}
|
|
1658
2029
|
});
|
|
1659
|
-
const displayedIds =
|
|
2030
|
+
const displayedIds = useMemo4(
|
|
1660
2031
|
() => orderedColumns.map((column) => column.id ?? column.field),
|
|
1661
2032
|
[orderedColumns]
|
|
1662
2033
|
);
|
|
1663
|
-
const groupByDraggableIds =
|
|
2034
|
+
const groupByDraggableIds = useMemo4(
|
|
1664
2035
|
() => new Set(
|
|
1665
2036
|
resolved.filter((entry) => entry.groupByDraggable).map((entry) => entry.id)
|
|
1666
2037
|
),
|
|
@@ -1712,6 +2083,25 @@ function DataGridComponent({
|
|
|
1712
2083
|
setSort,
|
|
1713
2084
|
onColumnSortChange: handleColumnSortChange
|
|
1714
2085
|
});
|
|
2086
|
+
function handlePaginationChange(event) {
|
|
2087
|
+
onPaginationChange?.(event);
|
|
2088
|
+
announce(
|
|
2089
|
+
`Page ${String(event.pagination.pageIndex + 1)} of ${String(event.pageCount)}`
|
|
2090
|
+
);
|
|
2091
|
+
}
|
|
2092
|
+
const paginationApi = usePagination({
|
|
2093
|
+
pagination,
|
|
2094
|
+
setPagination,
|
|
2095
|
+
rows: displayRows,
|
|
2096
|
+
onPaginationChange: handlePaginationChange
|
|
2097
|
+
});
|
|
2098
|
+
const [previous, setPrevious] = useState5({ filter, sort, groupBy });
|
|
2099
|
+
if (previous.filter !== filter || previous.sort !== sort || previous.groupBy !== groupBy) {
|
|
2100
|
+
setPrevious({ filter, sort, groupBy });
|
|
2101
|
+
if (pagination.pageIndex !== 0) {
|
|
2102
|
+
setPagination({ ...pagination, pageIndex: 0 });
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
1715
2105
|
const selection = useGridSelection({
|
|
1716
2106
|
rows: displayDataRows,
|
|
1717
2107
|
columns: resolved,
|
|
@@ -1727,6 +2117,27 @@ function DataGridComponent({
|
|
|
1727
2117
|
columnName
|
|
1728
2118
|
});
|
|
1729
2119
|
const multiselectable = selection.rowMode === "multiple" || selection.columnMode === "multiple";
|
|
2120
|
+
useEffect2(() => {
|
|
2121
|
+
for (const listener of subscribersRef.current) {
|
|
2122
|
+
listener();
|
|
2123
|
+
}
|
|
2124
|
+
}, [
|
|
2125
|
+
shownRows,
|
|
2126
|
+
aggregatedRows,
|
|
2127
|
+
resolved,
|
|
2128
|
+
sizing,
|
|
2129
|
+
order,
|
|
2130
|
+
sort,
|
|
2131
|
+
groupBy,
|
|
2132
|
+
expansion,
|
|
2133
|
+
paginationSnapshot,
|
|
2134
|
+
paginatedRows.pageCount,
|
|
2135
|
+
grandTotal,
|
|
2136
|
+
rowSelection,
|
|
2137
|
+
columnSelection,
|
|
2138
|
+
cellSelection,
|
|
2139
|
+
nav.focus
|
|
2140
|
+
]);
|
|
1730
2141
|
useImperativeHandle(ref, () => ({
|
|
1731
2142
|
get element() {
|
|
1732
2143
|
return viewportRef.current;
|
|
@@ -1735,13 +2146,20 @@ function DataGridComponent({
|
|
|
1735
2146
|
return tableRef.current;
|
|
1736
2147
|
},
|
|
1737
2148
|
getRows: () => shownRows,
|
|
1738
|
-
|
|
2149
|
+
// `aggregatedRows`, not the plain `displayRows` it's derived from: the
|
|
2150
|
+
// same array shape and content, except every group header's own
|
|
2151
|
+
// `aggregates` field is populated — the whole reason `getDisplayRows()`
|
|
2152
|
+
// is where a consumer reads a specific group's computed results from.
|
|
2153
|
+
getDisplayRows: () => aggregatedRows,
|
|
1739
2154
|
getColumns: () => resolved,
|
|
1740
2155
|
getColumnSizing: () => sizing,
|
|
1741
2156
|
getColumnOrder: () => order,
|
|
1742
2157
|
getColumnSort: () => sort,
|
|
1743
2158
|
getGroupBy: () => groupBy,
|
|
1744
2159
|
getGroupExpansion: () => expansion,
|
|
2160
|
+
getPagination: () => paginationSnapshot,
|
|
2161
|
+
getPageCount: () => paginatedRows.pageCount,
|
|
2162
|
+
getAggregates: () => grandTotal,
|
|
1745
2163
|
getRowSelection: () => rowSelection,
|
|
1746
2164
|
getColumnSelection: () => columnSelection,
|
|
1747
2165
|
getCellSelection: () => cellSelection,
|
|
@@ -1753,8 +2171,12 @@ function DataGridComponent({
|
|
|
1753
2171
|
collapseAllGroups: () => {
|
|
1754
2172
|
grouping.collapseAll(displayRows);
|
|
1755
2173
|
},
|
|
2174
|
+
goToPage: paginationApi.goToPage,
|
|
2175
|
+
nextPage: paginationApi.nextPage,
|
|
2176
|
+
previousPage: paginationApi.previousPage,
|
|
2177
|
+
setPageSize: paginationApi.setPageSize,
|
|
1756
2178
|
scrollToRow: (rowId, options) => {
|
|
1757
|
-
const index =
|
|
2179
|
+
const index = paginatedRows.rows.findIndex(
|
|
1758
2180
|
(entry) => !("kind" in entry) && entry.rowId === rowId
|
|
1759
2181
|
);
|
|
1760
2182
|
if (index === -1) return;
|
|
@@ -1766,10 +2188,16 @@ function DataGridComponent({
|
|
|
1766
2188
|
(entry) => entry.getAttribute("data-gridkit-column") === columnId
|
|
1767
2189
|
) : void 0;
|
|
1768
2190
|
cell?.scrollIntoView(options);
|
|
2191
|
+
},
|
|
2192
|
+
subscribe: (listener) => {
|
|
2193
|
+
subscribersRef.current.add(listener);
|
|
2194
|
+
return () => {
|
|
2195
|
+
subscribersRef.current.delete(listener);
|
|
2196
|
+
};
|
|
1769
2197
|
}
|
|
1770
2198
|
}));
|
|
1771
|
-
return /* @__PURE__ */
|
|
1772
|
-
showGroupByBar && /* @__PURE__ */
|
|
2199
|
+
return /* @__PURE__ */ jsxs6("div", { className: "gridkit-data-grid-viewport", ref: viewportRef, children: [
|
|
2200
|
+
showGroupByBar && /* @__PURE__ */ jsx9(
|
|
1773
2201
|
GroupByBar,
|
|
1774
2202
|
{
|
|
1775
2203
|
columns: resolved,
|
|
@@ -1780,12 +2208,12 @@ function DataGridComponent({
|
|
|
1780
2208
|
headerDropTarget: headerGroupByDropTarget
|
|
1781
2209
|
}
|
|
1782
2210
|
),
|
|
1783
|
-
/* @__PURE__ */
|
|
2211
|
+
/* @__PURE__ */ jsxs6(
|
|
1784
2212
|
"table",
|
|
1785
2213
|
{
|
|
1786
2214
|
ref: tableRef,
|
|
1787
2215
|
role: groupBy.length > 0 ? "treegrid" : "grid",
|
|
1788
|
-
"aria-rowcount":
|
|
2216
|
+
"aria-rowcount": aggregatedRows.length + 1,
|
|
1789
2217
|
"aria-colcount": resolved.length,
|
|
1790
2218
|
...ariaAttr(multiselectable, "aria-multiselectable", true),
|
|
1791
2219
|
...ariaAttr(labelledBy !== void 0, "aria-labelledby", labelledBy),
|
|
@@ -1822,8 +2250,8 @@ function DataGridComponent({
|
|
|
1822
2250
|
selection.cellMode === false ? "" : "selectable-cells"
|
|
1823
2251
|
),
|
|
1824
2252
|
children: [
|
|
1825
|
-
/* @__PURE__ */
|
|
1826
|
-
/* @__PURE__ */
|
|
2253
|
+
/* @__PURE__ */ jsx9("colgroup", { children: resolved.map((entry) => /* @__PURE__ */ jsx9("col", { style: { width: entry.width } }, entry.id)) }),
|
|
2254
|
+
/* @__PURE__ */ jsx9(
|
|
1827
2255
|
GridHeader,
|
|
1828
2256
|
{
|
|
1829
2257
|
columns: resolved,
|
|
@@ -1838,24 +2266,210 @@ function DataGridComponent({
|
|
|
1838
2266
|
selection
|
|
1839
2267
|
}
|
|
1840
2268
|
),
|
|
1841
|
-
/* @__PURE__ */
|
|
2269
|
+
/* @__PURE__ */ jsx9(
|
|
1842
2270
|
GridBody,
|
|
1843
2271
|
{
|
|
1844
2272
|
columns: resolved,
|
|
1845
|
-
rows:
|
|
2273
|
+
rows: paginatedRows.rows,
|
|
1846
2274
|
activeColumnId: resize.activeColumnId,
|
|
1847
2275
|
nav,
|
|
1848
2276
|
selection,
|
|
1849
|
-
grouping
|
|
2277
|
+
grouping,
|
|
2278
|
+
aggregates: activeAggregates,
|
|
2279
|
+
groupAggregateDisplay
|
|
2280
|
+
}
|
|
2281
|
+
),
|
|
2282
|
+
activeAggregates.length > 0 && /* @__PURE__ */ jsx9(
|
|
2283
|
+
GridFooter,
|
|
2284
|
+
{
|
|
2285
|
+
columns: resolved,
|
|
2286
|
+
aggregates: activeAggregates,
|
|
2287
|
+
results: grandTotal,
|
|
2288
|
+
rows: shownRows.map((entry) => entry.row)
|
|
1850
2289
|
}
|
|
1851
2290
|
)
|
|
1852
2291
|
]
|
|
1853
2292
|
}
|
|
1854
2293
|
),
|
|
1855
|
-
|
|
2294
|
+
paginated && (pager?.template ? pager.template({
|
|
2295
|
+
pagination: paginationApi.pagination,
|
|
2296
|
+
currentPage: paginationApi.currentPage,
|
|
2297
|
+
pageCount: paginationApi.pageCount,
|
|
2298
|
+
pageSizeOptions: pager.sizeOptions,
|
|
2299
|
+
goToPage: paginationApi.goToPage,
|
|
2300
|
+
nextPage: paginationApi.nextPage,
|
|
2301
|
+
previousPage: paginationApi.previousPage,
|
|
2302
|
+
setPageSize: paginationApi.setPageSize
|
|
2303
|
+
}) : /* @__PURE__ */ jsx9(GridPager, { pager: paginationApi, config: pager })),
|
|
2304
|
+
/* @__PURE__ */ jsx9("div", { className: "gridkit-sr-only", role: "status", "aria-live": "polite", children: announcement })
|
|
1856
2305
|
] });
|
|
1857
2306
|
}
|
|
2307
|
+
|
|
2308
|
+
// src/DataGrid/hooks/usePaginationState.ts
|
|
2309
|
+
import { useCallback as useCallback2 } from "react";
|
|
2310
|
+
|
|
2311
|
+
// src/DataGrid/hooks/useGridSnapshot.ts
|
|
2312
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
2313
|
+
function useGridSnapshot(gridRef, getSnapshot, fallback) {
|
|
2314
|
+
const subscribe = useCallback(
|
|
2315
|
+
(listener) => {
|
|
2316
|
+
const api = gridRef.current;
|
|
2317
|
+
if (api === null) {
|
|
2318
|
+
return () => {
|
|
2319
|
+
};
|
|
2320
|
+
}
|
|
2321
|
+
return api.subscribe(listener);
|
|
2322
|
+
},
|
|
2323
|
+
[gridRef]
|
|
2324
|
+
);
|
|
2325
|
+
return useSyncExternalStore(subscribe, () => {
|
|
2326
|
+
const api = gridRef.current;
|
|
2327
|
+
return api === null ? fallback : getSnapshot(api);
|
|
2328
|
+
});
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
// src/DataGrid/hooks/usePaginationState.ts
|
|
2332
|
+
var FALLBACK_PAGINATION = { pageIndex: 0, pageSize: 0 };
|
|
2333
|
+
function usePaginationState(gridRef) {
|
|
2334
|
+
const pagination = useGridSnapshot(
|
|
2335
|
+
gridRef,
|
|
2336
|
+
useCallback2((api) => api.getPagination(), []),
|
|
2337
|
+
FALLBACK_PAGINATION
|
|
2338
|
+
);
|
|
2339
|
+
const pageCount = useGridSnapshot(
|
|
2340
|
+
gridRef,
|
|
2341
|
+
useCallback2((api) => api.getPageCount(), []),
|
|
2342
|
+
0
|
|
2343
|
+
);
|
|
2344
|
+
return {
|
|
2345
|
+
pagination,
|
|
2346
|
+
pageCount,
|
|
2347
|
+
goToPage: (pageIndex) => {
|
|
2348
|
+
gridRef.current?.goToPage(pageIndex);
|
|
2349
|
+
},
|
|
2350
|
+
nextPage: () => {
|
|
2351
|
+
gridRef.current?.nextPage();
|
|
2352
|
+
},
|
|
2353
|
+
previousPage: () => {
|
|
2354
|
+
gridRef.current?.previousPage();
|
|
2355
|
+
},
|
|
2356
|
+
setPageSize: (pageSize) => {
|
|
2357
|
+
gridRef.current?.setPageSize(pageSize);
|
|
2358
|
+
}
|
|
2359
|
+
};
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
// src/DataGrid/hooks/useGroupByState.ts
|
|
2363
|
+
import { useCallback as useCallback3 } from "react";
|
|
2364
|
+
var FALLBACK_GROUP_BY = [];
|
|
2365
|
+
var FALLBACK_EXPANSION = [];
|
|
2366
|
+
function useGroupByState(gridRef) {
|
|
2367
|
+
const groupBy = useGridSnapshot(
|
|
2368
|
+
gridRef,
|
|
2369
|
+
useCallback3((api) => api.getGroupBy(), []),
|
|
2370
|
+
FALLBACK_GROUP_BY
|
|
2371
|
+
);
|
|
2372
|
+
const groupExpansion = useGridSnapshot(
|
|
2373
|
+
gridRef,
|
|
2374
|
+
useCallback3((api) => api.getGroupExpansion(), []),
|
|
2375
|
+
FALLBACK_EXPANSION
|
|
2376
|
+
);
|
|
2377
|
+
return {
|
|
2378
|
+
groupBy,
|
|
2379
|
+
groupExpansion,
|
|
2380
|
+
expandAllGroups: () => {
|
|
2381
|
+
gridRef.current?.expandAllGroups();
|
|
2382
|
+
},
|
|
2383
|
+
collapseAllGroups: () => {
|
|
2384
|
+
gridRef.current?.collapseAllGroups();
|
|
2385
|
+
}
|
|
2386
|
+
};
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
// src/DataGrid/hooks/useColumnSortState.ts
|
|
2390
|
+
import { useCallback as useCallback4 } from "react";
|
|
2391
|
+
var FALLBACK_SORT = [];
|
|
2392
|
+
function useColumnSortState(gridRef) {
|
|
2393
|
+
return useGridSnapshot(
|
|
2394
|
+
gridRef,
|
|
2395
|
+
useCallback4((api) => api.getColumnSort(), []),
|
|
2396
|
+
FALLBACK_SORT
|
|
2397
|
+
);
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2400
|
+
// src/DataGrid/hooks/useSelectionState.ts
|
|
2401
|
+
import { useCallback as useCallback5 } from "react";
|
|
2402
|
+
var FALLBACK_SELECTION = [];
|
|
2403
|
+
var FALLBACK_CELL_SELECTION = null;
|
|
2404
|
+
function useSelectionState(gridRef) {
|
|
2405
|
+
const rowSelection = useGridSnapshot(
|
|
2406
|
+
gridRef,
|
|
2407
|
+
useCallback5((api) => api.getRowSelection(), []),
|
|
2408
|
+
FALLBACK_SELECTION
|
|
2409
|
+
);
|
|
2410
|
+
const columnSelection = useGridSnapshot(
|
|
2411
|
+
gridRef,
|
|
2412
|
+
useCallback5((api) => api.getColumnSelection(), []),
|
|
2413
|
+
FALLBACK_SELECTION
|
|
2414
|
+
);
|
|
2415
|
+
const cellSelection = useGridSnapshot(
|
|
2416
|
+
gridRef,
|
|
2417
|
+
useCallback5((api) => api.getCellSelection(), []),
|
|
2418
|
+
FALLBACK_CELL_SELECTION
|
|
2419
|
+
);
|
|
2420
|
+
return {
|
|
2421
|
+
rowSelection,
|
|
2422
|
+
columnSelection,
|
|
2423
|
+
cellSelection,
|
|
2424
|
+
clearSelection: () => {
|
|
2425
|
+
gridRef.current?.clearSelection();
|
|
2426
|
+
},
|
|
2427
|
+
selectAllRows: () => {
|
|
2428
|
+
gridRef.current?.selectAllRows();
|
|
2429
|
+
}
|
|
2430
|
+
};
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
// src/DataGrid/hooks/useAggregateState.ts
|
|
2434
|
+
import { useCallback as useCallback6 } from "react";
|
|
2435
|
+
var FALLBACK_AGGREGATES = /* @__PURE__ */ new Map();
|
|
2436
|
+
function useAggregateState(gridRef) {
|
|
2437
|
+
return useGridSnapshot(
|
|
2438
|
+
gridRef,
|
|
2439
|
+
useCallback6((api) => api.getAggregates(), []),
|
|
2440
|
+
FALLBACK_AGGREGATES
|
|
2441
|
+
);
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
// src/DataGrid/hooks/useColumnSizingState.ts
|
|
2445
|
+
import { useCallback as useCallback7 } from "react";
|
|
2446
|
+
var FALLBACK_SIZING = {};
|
|
2447
|
+
function useColumnSizingState(gridRef) {
|
|
2448
|
+
return useGridSnapshot(
|
|
2449
|
+
gridRef,
|
|
2450
|
+
useCallback7((api) => api.getColumnSizing(), []),
|
|
2451
|
+
FALLBACK_SIZING
|
|
2452
|
+
);
|
|
2453
|
+
}
|
|
2454
|
+
|
|
2455
|
+
// src/DataGrid/hooks/useColumnOrderState.ts
|
|
2456
|
+
import { useCallback as useCallback8 } from "react";
|
|
2457
|
+
var FALLBACK_ORDER = [];
|
|
2458
|
+
function useColumnOrderState(gridRef) {
|
|
2459
|
+
return useGridSnapshot(
|
|
2460
|
+
gridRef,
|
|
2461
|
+
useCallback8((api) => api.getColumnOrder(), []),
|
|
2462
|
+
FALLBACK_ORDER
|
|
2463
|
+
);
|
|
2464
|
+
}
|
|
1858
2465
|
export {
|
|
1859
|
-
DataGridComponent
|
|
2466
|
+
DataGridComponent,
|
|
2467
|
+
useAggregateState,
|
|
2468
|
+
useColumnOrderState,
|
|
2469
|
+
useColumnSizingState,
|
|
2470
|
+
useColumnSortState,
|
|
2471
|
+
useGroupByState,
|
|
2472
|
+
usePaginationState,
|
|
2473
|
+
useSelectionState
|
|
1860
2474
|
};
|
|
1861
2475
|
//# sourceMappingURL=index.js.map
|