react-glide-table 2.0.2 → 2.1.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/README.md +35 -0
- package/dist/compound.cjs +511 -116
- package/dist/compound.d.cts +3 -3
- package/dist/compound.d.ts +3 -3
- package/dist/compound.js +492 -92
- package/dist/core.cjs +367 -1
- package/dist/core.d.cts +40 -6
- package/dist/core.d.ts +40 -6
- package/dist/core.js +366 -1
- package/dist/index.cjs +430 -23
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +413 -7
- package/dist/{types-bgEceyRV.d.cts → types-CMUGtH-c.d.cts} +24 -1
- package/dist/{types-bgEceyRV.d.ts → types-CMUGtH-c.d.ts} +24 -1
- package/package.json +1 -1
package/dist/compound.js
CHANGED
|
@@ -21,6 +21,7 @@ var DATA_TABLE_VIRTUAL_OVERSCAN = 8;
|
|
|
21
21
|
var DATA_TABLE_COLUMN_SIZE = 150;
|
|
22
22
|
var DATA_TABLE_COLUMN_MIN_SIZE = 40;
|
|
23
23
|
var DATA_TABLE_COLUMN_MAX_SIZE = 800;
|
|
24
|
+
var DATA_TABLE_COLUMN_REORDER_THRESHOLD = 4;
|
|
24
25
|
|
|
25
26
|
// src/components/ui/table/DataTableContext.tsx
|
|
26
27
|
import { createContext, use } from "react";
|
|
@@ -1757,6 +1758,348 @@ function getMergedHeaderGroups(headerGroups) {
|
|
|
1757
1758
|
}));
|
|
1758
1759
|
}
|
|
1759
1760
|
|
|
1761
|
+
// src/components/ui/table/features/column-reorder/columnReorder.ts
|
|
1762
|
+
function getColumnDefId(column) {
|
|
1763
|
+
if (column.id != null && column.id !== "") return column.id;
|
|
1764
|
+
if ("accessorKey" in column && column.accessorKey != null) {
|
|
1765
|
+
return String(column.accessorKey);
|
|
1766
|
+
}
|
|
1767
|
+
return void 0;
|
|
1768
|
+
}
|
|
1769
|
+
function getColumnDefChildren(column) {
|
|
1770
|
+
if (!("columns" in column) || !Array.isArray(column.columns)) return void 0;
|
|
1771
|
+
if (column.columns.length === 0) return void 0;
|
|
1772
|
+
return column.columns;
|
|
1773
|
+
}
|
|
1774
|
+
function collectLeafColumnIds(columns) {
|
|
1775
|
+
const ids = [];
|
|
1776
|
+
for (const column of columns) {
|
|
1777
|
+
const children = getColumnDefChildren(column);
|
|
1778
|
+
if (children) {
|
|
1779
|
+
ids.push(...collectLeafColumnIds(children));
|
|
1780
|
+
continue;
|
|
1781
|
+
}
|
|
1782
|
+
const id = getColumnDefId(column);
|
|
1783
|
+
if (id) ids.push(id);
|
|
1784
|
+
}
|
|
1785
|
+
return ids;
|
|
1786
|
+
}
|
|
1787
|
+
function areColumnOrdersEqual(left, right) {
|
|
1788
|
+
if (left.length !== right.length) return false;
|
|
1789
|
+
return left.every((id, index) => id === right[index]);
|
|
1790
|
+
}
|
|
1791
|
+
function resolveLeafColumnOrder(columns, order) {
|
|
1792
|
+
const leafIds = collectLeafColumnIds(columns);
|
|
1793
|
+
if (!order?.length) return leafIds;
|
|
1794
|
+
const leafSet = new Set(leafIds);
|
|
1795
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1796
|
+
const next = order.filter((id) => {
|
|
1797
|
+
if (!leafSet.has(id) || seen.has(id)) return false;
|
|
1798
|
+
seen.add(id);
|
|
1799
|
+
return true;
|
|
1800
|
+
});
|
|
1801
|
+
for (const id of leafIds) {
|
|
1802
|
+
if (!seen.has(id)) next.push(id);
|
|
1803
|
+
}
|
|
1804
|
+
return next;
|
|
1805
|
+
}
|
|
1806
|
+
function flattenColumnSlots(columns, group) {
|
|
1807
|
+
const slots = [];
|
|
1808
|
+
for (const column of columns) {
|
|
1809
|
+
const id = getColumnDefId(column);
|
|
1810
|
+
const children = getColumnDefChildren(column);
|
|
1811
|
+
if (children) {
|
|
1812
|
+
const nestedGroup = id ? { id, def: column } : group;
|
|
1813
|
+
slots.push(...flattenColumnSlots(children, nestedGroup));
|
|
1814
|
+
continue;
|
|
1815
|
+
}
|
|
1816
|
+
if (!id) continue;
|
|
1817
|
+
slots.push({ id, def: column, group });
|
|
1818
|
+
}
|
|
1819
|
+
return slots;
|
|
1820
|
+
}
|
|
1821
|
+
function rebuildColumnTree(slots) {
|
|
1822
|
+
const result = [];
|
|
1823
|
+
let index = 0;
|
|
1824
|
+
while (index < slots.length) {
|
|
1825
|
+
const slot = slots[index];
|
|
1826
|
+
if (!slot.group) {
|
|
1827
|
+
result.push(slot.def);
|
|
1828
|
+
index += 1;
|
|
1829
|
+
continue;
|
|
1830
|
+
}
|
|
1831
|
+
const groupId = slot.group.id;
|
|
1832
|
+
const children = [];
|
|
1833
|
+
while (index < slots.length && slots[index]?.group?.id === groupId) {
|
|
1834
|
+
children.push(slots[index].def);
|
|
1835
|
+
index += 1;
|
|
1836
|
+
}
|
|
1837
|
+
const firstChildId = children[0] ? getColumnDefId(children[0]) : groupId;
|
|
1838
|
+
result.push({
|
|
1839
|
+
...slot.group.def,
|
|
1840
|
+
id: `${groupId}::${firstChildId}`,
|
|
1841
|
+
columns: children
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
return result;
|
|
1845
|
+
}
|
|
1846
|
+
function applyLeafColumnOrder(columns, order) {
|
|
1847
|
+
const resolved = resolveLeafColumnOrder(columns, order);
|
|
1848
|
+
const defaultOrder = collectLeafColumnIds(columns);
|
|
1849
|
+
if (areColumnOrdersEqual(resolved, defaultOrder)) {
|
|
1850
|
+
return columns;
|
|
1851
|
+
}
|
|
1852
|
+
const byId = new Map(
|
|
1853
|
+
flattenColumnSlots(columns).map((slot) => [
|
|
1854
|
+
slot.id,
|
|
1855
|
+
slot
|
|
1856
|
+
])
|
|
1857
|
+
);
|
|
1858
|
+
const ordered = [];
|
|
1859
|
+
for (const id of resolved) {
|
|
1860
|
+
const slot = byId.get(id);
|
|
1861
|
+
if (slot) ordered.push(slot);
|
|
1862
|
+
}
|
|
1863
|
+
return rebuildColumnTree(ordered);
|
|
1864
|
+
}
|
|
1865
|
+
function moveColumnIds(order, fromIds, targetIds, edge) {
|
|
1866
|
+
if (fromIds.length === 0 || targetIds.length === 0) return [...order];
|
|
1867
|
+
const fromSet = new Set(fromIds);
|
|
1868
|
+
if (targetIds.some((id) => fromSet.has(id))) return [...order];
|
|
1869
|
+
const rest = order.filter((id) => !fromSet.has(id));
|
|
1870
|
+
const anchorId = edge === "before" ? targetIds[0] : targetIds[targetIds.length - 1];
|
|
1871
|
+
const anchorIndex = rest.indexOf(anchorId);
|
|
1872
|
+
if (anchorIndex < 0) return [...order];
|
|
1873
|
+
const insertAt = edge === "before" ? anchorIndex : anchorIndex + 1;
|
|
1874
|
+
return [...rest.slice(0, insertAt), ...fromIds, ...rest.slice(insertAt)];
|
|
1875
|
+
}
|
|
1876
|
+
function resolveDropEdge(clientX, rect) {
|
|
1877
|
+
return clientX < rect.left + rect.width / 2 ? "before" : "after";
|
|
1878
|
+
}
|
|
1879
|
+
function parseReorderIds(value) {
|
|
1880
|
+
if (!value) return [];
|
|
1881
|
+
return value.split(",").filter(Boolean);
|
|
1882
|
+
}
|
|
1883
|
+
function serializeReorderIds(ids) {
|
|
1884
|
+
return ids.join(",");
|
|
1885
|
+
}
|
|
1886
|
+
function isColumnReorderable(meta) {
|
|
1887
|
+
return meta?.reorderable !== false;
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
// src/components/ui/table/features/column-reorder/useColumnReorder.ts
|
|
1891
|
+
import {
|
|
1892
|
+
useCallback,
|
|
1893
|
+
useEffect as useEffect3,
|
|
1894
|
+
useRef as useRef3,
|
|
1895
|
+
useState
|
|
1896
|
+
} from "react";
|
|
1897
|
+
function hitTestReorderHeader(table, clientX, clientY) {
|
|
1898
|
+
const headers = Array.from(
|
|
1899
|
+
table.querySelectorAll(
|
|
1900
|
+
"thead th[data-column-id][data-reorder-ids]"
|
|
1901
|
+
)
|
|
1902
|
+
);
|
|
1903
|
+
const containing = headers.find((element) => {
|
|
1904
|
+
const rect = element.getBoundingClientRect();
|
|
1905
|
+
return clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom;
|
|
1906
|
+
});
|
|
1907
|
+
if (containing) {
|
|
1908
|
+
return {
|
|
1909
|
+
columnId: containing.dataset.columnId ?? "",
|
|
1910
|
+
edge: resolveDropEdge(clientX, containing.getBoundingClientRect())
|
|
1911
|
+
};
|
|
1912
|
+
}
|
|
1913
|
+
const leaves = headers.filter(
|
|
1914
|
+
(element) => element.hasAttribute("data-reorder-leaf")
|
|
1915
|
+
);
|
|
1916
|
+
let match;
|
|
1917
|
+
for (const element of leaves) {
|
|
1918
|
+
const rect = element.getBoundingClientRect();
|
|
1919
|
+
if (clientX >= rect.left && clientX <= rect.right) {
|
|
1920
|
+
match = element;
|
|
1921
|
+
break;
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
if (!match && leaves.length > 0) {
|
|
1925
|
+
const first = leaves[0].getBoundingClientRect();
|
|
1926
|
+
const last = leaves[leaves.length - 1].getBoundingClientRect();
|
|
1927
|
+
if (clientX < first.left) match = leaves[0];
|
|
1928
|
+
else if (clientX > last.right) match = leaves[leaves.length - 1];
|
|
1929
|
+
}
|
|
1930
|
+
if (!match) return null;
|
|
1931
|
+
return {
|
|
1932
|
+
columnId: match.dataset.columnId ?? "",
|
|
1933
|
+
edge: resolveDropEdge(clientX, match.getBoundingClientRect())
|
|
1934
|
+
};
|
|
1935
|
+
}
|
|
1936
|
+
function readTargetIds(table, columnId) {
|
|
1937
|
+
const element = table.querySelector(
|
|
1938
|
+
`thead th[data-column-id="${CSS.escape(columnId)}"]`
|
|
1939
|
+
);
|
|
1940
|
+
return parseReorderIds(element?.getAttribute("data-reorder-ids"));
|
|
1941
|
+
}
|
|
1942
|
+
function useColumnReorder(options) {
|
|
1943
|
+
const { enabled, columnOrder, onColumnOrderChange } = options;
|
|
1944
|
+
const sessionRef = useRef3(null);
|
|
1945
|
+
const columnOrderRef = useRef3(columnOrder);
|
|
1946
|
+
const onColumnOrderChangeRef = useRef3(onColumnOrderChange);
|
|
1947
|
+
const [draggingColumnId, setDraggingColumnId] = useState(null);
|
|
1948
|
+
const [dropTarget, setDropTarget] = useState(
|
|
1949
|
+
null
|
|
1950
|
+
);
|
|
1951
|
+
const dropTargetRef = useRef3(dropTarget);
|
|
1952
|
+
const previousUserSelectRef = useRef3(null);
|
|
1953
|
+
columnOrderRef.current = columnOrder;
|
|
1954
|
+
onColumnOrderChangeRef.current = onColumnOrderChange;
|
|
1955
|
+
dropTargetRef.current = dropTarget;
|
|
1956
|
+
const resetDrag = useCallback(() => {
|
|
1957
|
+
sessionRef.current = null;
|
|
1958
|
+
setDraggingColumnId(null);
|
|
1959
|
+
setDropTarget(null);
|
|
1960
|
+
const backup = previousUserSelectRef.current;
|
|
1961
|
+
previousUserSelectRef.current = null;
|
|
1962
|
+
if (backup) {
|
|
1963
|
+
if (backup.value) {
|
|
1964
|
+
document.body.style.setProperty("user-select", backup.value, backup.priority);
|
|
1965
|
+
} else {
|
|
1966
|
+
document.body.style.removeProperty("user-select");
|
|
1967
|
+
}
|
|
1968
|
+
return;
|
|
1969
|
+
}
|
|
1970
|
+
document.body.style.removeProperty("user-select");
|
|
1971
|
+
}, []);
|
|
1972
|
+
useEffect3(() => {
|
|
1973
|
+
if (!enabled) resetDrag();
|
|
1974
|
+
}, [enabled, resetDrag]);
|
|
1975
|
+
useEffect3(() => {
|
|
1976
|
+
return () => {
|
|
1977
|
+
resetDrag();
|
|
1978
|
+
};
|
|
1979
|
+
}, [resetDrag]);
|
|
1980
|
+
const onHeaderPointerDown = useCallback(
|
|
1981
|
+
(event, meta) => {
|
|
1982
|
+
if (!enabled || !meta.canDrag) return;
|
|
1983
|
+
if (event.button !== 0) return;
|
|
1984
|
+
if (event.pointerType === "mouse" && event.ctrlKey) return;
|
|
1985
|
+
const target = event.target;
|
|
1986
|
+
if (target instanceof Element && target.closest("[data-table-disable-cell-selection]")) {
|
|
1987
|
+
return;
|
|
1988
|
+
}
|
|
1989
|
+
const table = event.currentTarget.closest("table");
|
|
1990
|
+
if (!(table instanceof HTMLTableElement)) return;
|
|
1991
|
+
sessionRef.current = {
|
|
1992
|
+
pointerId: event.pointerId,
|
|
1993
|
+
startX: event.clientX,
|
|
1994
|
+
startY: event.clientY,
|
|
1995
|
+
columnId: meta.columnId,
|
|
1996
|
+
fromIds: meta.leafIds,
|
|
1997
|
+
table,
|
|
1998
|
+
active: false
|
|
1999
|
+
};
|
|
2000
|
+
},
|
|
2001
|
+
[enabled]
|
|
2002
|
+
);
|
|
2003
|
+
useEffect3(() => {
|
|
2004
|
+
if (!enabled) return;
|
|
2005
|
+
const onPointerMove = (event) => {
|
|
2006
|
+
const session = sessionRef.current;
|
|
2007
|
+
if (!session || event.pointerId !== session.pointerId) return;
|
|
2008
|
+
const deltaX = event.clientX - session.startX;
|
|
2009
|
+
const deltaY = event.clientY - session.startY;
|
|
2010
|
+
const distance = Math.hypot(deltaX, deltaY);
|
|
2011
|
+
if (!session.active) {
|
|
2012
|
+
if (distance < DATA_TABLE_COLUMN_REORDER_THRESHOLD) return;
|
|
2013
|
+
session.active = true;
|
|
2014
|
+
if (!previousUserSelectRef.current) {
|
|
2015
|
+
previousUserSelectRef.current = {
|
|
2016
|
+
value: document.body.style.getPropertyValue("user-select"),
|
|
2017
|
+
priority: document.body.style.getPropertyPriority("user-select")
|
|
2018
|
+
};
|
|
2019
|
+
}
|
|
2020
|
+
document.body.style.setProperty("user-select", "none");
|
|
2021
|
+
setDraggingColumnId(session.columnId);
|
|
2022
|
+
}
|
|
2023
|
+
event.preventDefault();
|
|
2024
|
+
const nextTarget = hitTestReorderHeader(
|
|
2025
|
+
session.table,
|
|
2026
|
+
event.clientX,
|
|
2027
|
+
event.clientY
|
|
2028
|
+
);
|
|
2029
|
+
if (!nextTarget || !nextTarget.columnId) {
|
|
2030
|
+
setDropTarget(null);
|
|
2031
|
+
return;
|
|
2032
|
+
}
|
|
2033
|
+
const targetIds = readTargetIds(session.table, nextTarget.columnId);
|
|
2034
|
+
const fromSet = new Set(session.fromIds);
|
|
2035
|
+
if (targetIds.some((id) => fromSet.has(id))) {
|
|
2036
|
+
setDropTarget(null);
|
|
2037
|
+
return;
|
|
2038
|
+
}
|
|
2039
|
+
setDropTarget((previous) => {
|
|
2040
|
+
if (previous?.columnId === nextTarget.columnId && previous.edge === nextTarget.edge) {
|
|
2041
|
+
return previous;
|
|
2042
|
+
}
|
|
2043
|
+
return nextTarget;
|
|
2044
|
+
});
|
|
2045
|
+
};
|
|
2046
|
+
const onPointerUp = (event) => {
|
|
2047
|
+
const session = sessionRef.current;
|
|
2048
|
+
if (!session || event.pointerId !== session.pointerId) {
|
|
2049
|
+
return;
|
|
2050
|
+
}
|
|
2051
|
+
if (session.active) {
|
|
2052
|
+
event.preventDefault();
|
|
2053
|
+
const target = dropTargetRef.current;
|
|
2054
|
+
if (target) {
|
|
2055
|
+
const targetIds = readTargetIds(session.table, target.columnId);
|
|
2056
|
+
const next = moveColumnIds(
|
|
2057
|
+
columnOrderRef.current,
|
|
2058
|
+
session.fromIds,
|
|
2059
|
+
targetIds,
|
|
2060
|
+
target.edge
|
|
2061
|
+
);
|
|
2062
|
+
onColumnOrderChangeRef.current(next);
|
|
2063
|
+
}
|
|
2064
|
+
const suppressClick = (clickEvent) => {
|
|
2065
|
+
clickEvent.preventDefault();
|
|
2066
|
+
clickEvent.stopPropagation();
|
|
2067
|
+
document.removeEventListener("click", suppressClick, true);
|
|
2068
|
+
};
|
|
2069
|
+
document.addEventListener("click", suppressClick, true);
|
|
2070
|
+
window.setTimeout(() => {
|
|
2071
|
+
document.removeEventListener("click", suppressClick, true);
|
|
2072
|
+
}, 0);
|
|
2073
|
+
}
|
|
2074
|
+
resetDrag();
|
|
2075
|
+
};
|
|
2076
|
+
const onPointerCancel = (event) => {
|
|
2077
|
+
const session = sessionRef.current;
|
|
2078
|
+
if (!session || event.pointerId !== session.pointerId) {
|
|
2079
|
+
return;
|
|
2080
|
+
}
|
|
2081
|
+
if (session.active) {
|
|
2082
|
+
event.preventDefault();
|
|
2083
|
+
}
|
|
2084
|
+
resetDrag();
|
|
2085
|
+
};
|
|
2086
|
+
document.addEventListener("pointermove", onPointerMove);
|
|
2087
|
+
document.addEventListener("pointerup", onPointerUp);
|
|
2088
|
+
document.addEventListener("pointercancel", onPointerCancel);
|
|
2089
|
+
return () => {
|
|
2090
|
+
document.removeEventListener("pointermove", onPointerMove);
|
|
2091
|
+
document.removeEventListener("pointerup", onPointerUp);
|
|
2092
|
+
document.removeEventListener("pointercancel", onPointerCancel);
|
|
2093
|
+
};
|
|
2094
|
+
}, [enabled, resetDrag]);
|
|
2095
|
+
return {
|
|
2096
|
+
isReordering: draggingColumnId != null,
|
|
2097
|
+
draggingColumnId,
|
|
2098
|
+
dropTarget,
|
|
2099
|
+
onHeaderPointerDown
|
|
2100
|
+
};
|
|
2101
|
+
}
|
|
2102
|
+
|
|
1760
2103
|
// src/core/useGlideTable.ts
|
|
1761
2104
|
import {
|
|
1762
2105
|
getCoreRowModel,
|
|
@@ -1766,15 +2109,15 @@ import {
|
|
|
1766
2109
|
useVirtualizer
|
|
1767
2110
|
} from "@tanstack/react-virtual";
|
|
1768
2111
|
import {
|
|
1769
|
-
useCallback as
|
|
1770
|
-
useEffect as
|
|
2112
|
+
useCallback as useCallback5,
|
|
2113
|
+
useEffect as useEffect7,
|
|
1771
2114
|
useMemo as useMemo3,
|
|
1772
|
-
useRef as
|
|
1773
|
-
useState as
|
|
2115
|
+
useRef as useRef7,
|
|
2116
|
+
useState as useState5
|
|
1774
2117
|
} from "react";
|
|
1775
2118
|
|
|
1776
2119
|
// src/components/ui/table/features/cell-edit/useCellEdit.ts
|
|
1777
|
-
import { useCallback, useEffect as
|
|
2120
|
+
import { useCallback as useCallback2, useEffect as useEffect4, useRef as useRef4, useState as useState2 } from "react";
|
|
1778
2121
|
|
|
1779
2122
|
// src/components/ui/table/features/cell-render/commitCellValue.ts
|
|
1780
2123
|
function commitCellValue({
|
|
@@ -1814,21 +2157,21 @@ function useCellEdit({
|
|
|
1814
2157
|
onDataChange,
|
|
1815
2158
|
onCellChange
|
|
1816
2159
|
}) {
|
|
1817
|
-
const [editingCell, setEditingCell] =
|
|
1818
|
-
const [draftValue, setDraftValue] =
|
|
1819
|
-
const draftValueRef =
|
|
1820
|
-
const editingCellRef =
|
|
1821
|
-
|
|
2160
|
+
const [editingCell, setEditingCell] = useState2(null);
|
|
2161
|
+
const [draftValue, setDraftValue] = useState2("");
|
|
2162
|
+
const draftValueRef = useRef4(draftValue);
|
|
2163
|
+
const editingCellRef = useRef4(editingCell);
|
|
2164
|
+
useEffect4(() => {
|
|
1822
2165
|
draftValueRef.current = draftValue;
|
|
1823
2166
|
}, [draftValue]);
|
|
1824
|
-
|
|
2167
|
+
useEffect4(() => {
|
|
1825
2168
|
editingCellRef.current = editingCell;
|
|
1826
2169
|
}, [editingCell]);
|
|
1827
|
-
const cancelEdit =
|
|
2170
|
+
const cancelEdit = useCallback2(() => {
|
|
1828
2171
|
setEditingCell(null);
|
|
1829
2172
|
setDraftValue("");
|
|
1830
2173
|
}, []);
|
|
1831
|
-
const commitEdit =
|
|
2174
|
+
const commitEdit = useCallback2(
|
|
1832
2175
|
(raw) => {
|
|
1833
2176
|
const current = editingCellRef.current;
|
|
1834
2177
|
if (!current) return true;
|
|
@@ -1864,7 +2207,7 @@ function useCellEdit({
|
|
|
1864
2207
|
},
|
|
1865
2208
|
[cancelEdit, data, onCellChange, onDataChange, rows]
|
|
1866
2209
|
);
|
|
1867
|
-
const startEdit =
|
|
2210
|
+
const startEdit = useCallback2(
|
|
1868
2211
|
(rowIndex, colIndex) => {
|
|
1869
2212
|
const cell = rows[rowIndex]?.getVisibleCells()[colIndex];
|
|
1870
2213
|
if (!cell || !isColumnEditable(cell.column.columnDef)) return;
|
|
@@ -2100,7 +2443,7 @@ function formatDefaultCellValue(value) {
|
|
|
2100
2443
|
}
|
|
2101
2444
|
|
|
2102
2445
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
2103
|
-
import { useCallback as
|
|
2446
|
+
import { useCallback as useCallback3, useEffect as useEffect5, useRef as useRef5, useState as useState3 } from "react";
|
|
2104
2447
|
|
|
2105
2448
|
// src/components/ui/table/features/cell-selection/copyData.ts
|
|
2106
2449
|
function formatPrimitive(value) {
|
|
@@ -2379,15 +2722,15 @@ function useCellSelection({
|
|
|
2379
2722
|
onRowsPaste,
|
|
2380
2723
|
onCellNavigate
|
|
2381
2724
|
}) {
|
|
2382
|
-
const [dragState, setDragState] =
|
|
2383
|
-
const pendingPasteModeRef =
|
|
2384
|
-
const dragStateRef =
|
|
2385
|
-
const onCellNavigateRef =
|
|
2725
|
+
const [dragState, setDragState] = useState3(INITIAL_DRAG_STATE);
|
|
2726
|
+
const pendingPasteModeRef = useRef5(null);
|
|
2727
|
+
const dragStateRef = useRef5(dragState);
|
|
2728
|
+
const onCellNavigateRef = useRef5(onCellNavigate);
|
|
2386
2729
|
dragStateRef.current = dragState;
|
|
2387
2730
|
onCellNavigateRef.current = onCellNavigate;
|
|
2388
2731
|
const cellSelectionBounds = getCellSelectionBounds(dragState.start, dragState.end);
|
|
2389
2732
|
const activeSelectionBounds = enabled ? getActiveSelectionBounds(dragState, cellSelectionBounds) : null;
|
|
2390
|
-
const handleCellMouseDown =
|
|
2733
|
+
const handleCellMouseDown = useCallback3(
|
|
2391
2734
|
(rowIndex, colIndex, options) => {
|
|
2392
2735
|
if (!enabled) return;
|
|
2393
2736
|
setDragState((prev) => {
|
|
@@ -2413,7 +2756,7 @@ function useCellSelection({
|
|
|
2413
2756
|
},
|
|
2414
2757
|
[enabled]
|
|
2415
2758
|
);
|
|
2416
|
-
const handleCellMouseEnter =
|
|
2759
|
+
const handleCellMouseEnter = useCallback3(
|
|
2417
2760
|
(rowIndex, colIndex) => {
|
|
2418
2761
|
if (!enabled) return;
|
|
2419
2762
|
setDragState((prev) => {
|
|
@@ -2428,7 +2771,7 @@ function useCellSelection({
|
|
|
2428
2771
|
},
|
|
2429
2772
|
[enabled]
|
|
2430
2773
|
);
|
|
2431
|
-
const handleFillHandleMouseDown =
|
|
2774
|
+
const handleFillHandleMouseDown = useCallback3(
|
|
2432
2775
|
(rowIndex, colIndex) => {
|
|
2433
2776
|
if (!enabled) return;
|
|
2434
2777
|
setDragState((prev) => {
|
|
@@ -2445,12 +2788,12 @@ function useCellSelection({
|
|
|
2445
2788
|
},
|
|
2446
2789
|
[enabled]
|
|
2447
2790
|
);
|
|
2448
|
-
|
|
2791
|
+
useEffect5(() => {
|
|
2449
2792
|
if (!enabled) {
|
|
2450
2793
|
setDragState(INITIAL_DRAG_STATE);
|
|
2451
2794
|
}
|
|
2452
2795
|
}, [enabled]);
|
|
2453
|
-
|
|
2796
|
+
useEffect5(() => {
|
|
2454
2797
|
if (!enabled) return;
|
|
2455
2798
|
const handleKeyDown = (e) => {
|
|
2456
2799
|
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
@@ -2497,7 +2840,7 @@ function useCellSelection({
|
|
|
2497
2840
|
window.addEventListener("keydown", handleKeyDown);
|
|
2498
2841
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
2499
2842
|
}, [columnCount, enabled, rows]);
|
|
2500
|
-
const copySelection =
|
|
2843
|
+
const copySelection = useCallback3(
|
|
2501
2844
|
async (options) => {
|
|
2502
2845
|
if (!enabled || !activeSelectionBounds) return false;
|
|
2503
2846
|
const mode = options?.includeDescendants && enableSubtreeCopy ? "subtree" : "visible";
|
|
@@ -2505,7 +2848,7 @@ function useCellSelection({
|
|
|
2505
2848
|
},
|
|
2506
2849
|
[activeSelectionBounds, enableSubtreeCopy, enabled, rows]
|
|
2507
2850
|
);
|
|
2508
|
-
|
|
2851
|
+
useEffect5(() => {
|
|
2509
2852
|
if (!enabled) return;
|
|
2510
2853
|
const handleKeyDown = (e) => {
|
|
2511
2854
|
if (!activeSelectionBounds) return;
|
|
@@ -2519,7 +2862,7 @@ function useCellSelection({
|
|
|
2519
2862
|
window.addEventListener("keydown", handleKeyDown);
|
|
2520
2863
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
2521
2864
|
}, [activeSelectionBounds, copySelection, enableSubtreeCopy, enabled]);
|
|
2522
|
-
const emitRowsPaste =
|
|
2865
|
+
const emitRowsPaste = useCallback3(
|
|
2523
2866
|
(text, mode) => {
|
|
2524
2867
|
if (!onRowsPaste || !activeSelectionBounds) return false;
|
|
2525
2868
|
const payload = buildRowsPastePayload(
|
|
@@ -2536,7 +2879,7 @@ function useCellSelection({
|
|
|
2536
2879
|
},
|
|
2537
2880
|
[activeSelectionBounds, onRowsPaste, rows]
|
|
2538
2881
|
);
|
|
2539
|
-
|
|
2882
|
+
useEffect5(() => {
|
|
2540
2883
|
if (!enabled || !onRowsPaste) return;
|
|
2541
2884
|
const pasteHandledRef = { current: false };
|
|
2542
2885
|
const ignoreNextPasteRef = { current: false };
|
|
@@ -2604,7 +2947,7 @@ function useCellSelection({
|
|
|
2604
2947
|
enabled,
|
|
2605
2948
|
onRowsPaste
|
|
2606
2949
|
]);
|
|
2607
|
-
|
|
2950
|
+
useEffect5(() => {
|
|
2608
2951
|
if (!enabled) return;
|
|
2609
2952
|
const handleMouseUp = () => {
|
|
2610
2953
|
setDragState((prev) => {
|
|
@@ -2656,12 +2999,12 @@ function useCellSelection({
|
|
|
2656
2999
|
|
|
2657
3000
|
// src/components/ui/table/features/inline-search/useInlineSearch.ts
|
|
2658
3001
|
import {
|
|
2659
|
-
useCallback as
|
|
2660
|
-
useEffect as
|
|
3002
|
+
useCallback as useCallback4,
|
|
3003
|
+
useEffect as useEffect6,
|
|
2661
3004
|
useId,
|
|
2662
3005
|
useMemo as useMemo2,
|
|
2663
|
-
useRef as
|
|
2664
|
-
useState as
|
|
3006
|
+
useRef as useRef6,
|
|
3007
|
+
useState as useState4
|
|
2665
3008
|
} from "react";
|
|
2666
3009
|
var EMPTY_MATCH_KEYS = /* @__PURE__ */ new Set();
|
|
2667
3010
|
function useInlineSearch({
|
|
@@ -2680,45 +3023,45 @@ function useInlineSearch({
|
|
|
2680
3023
|
rootRef
|
|
2681
3024
|
}) {
|
|
2682
3025
|
const searchInputId = useId();
|
|
2683
|
-
const searchInputRef =
|
|
2684
|
-
const [internalShowSearch, setInternalShowSearch] =
|
|
2685
|
-
const [internalSearchValue, setInternalSearchValue] =
|
|
2686
|
-
const [internalResults, setInternalResults] =
|
|
3026
|
+
const searchInputRef = useRef6(null);
|
|
3027
|
+
const [internalShowSearch, setInternalShowSearch] = useState4(false);
|
|
3028
|
+
const [internalSearchValue, setInternalSearchValue] = useState4("");
|
|
3029
|
+
const [internalResults, setInternalResults] = useState4(
|
|
2687
3030
|
[]
|
|
2688
3031
|
);
|
|
2689
|
-
const [searchStatus, setSearchStatus] =
|
|
2690
|
-
const searchStatusRef =
|
|
3032
|
+
const [searchStatus, setSearchStatus] = useState4();
|
|
3033
|
+
const searchStatusRef = useRef6(searchStatus);
|
|
2691
3034
|
searchStatusRef.current = searchStatus;
|
|
2692
|
-
const abortControllerRef =
|
|
2693
|
-
const searchHandleRef =
|
|
2694
|
-
const initialStartRowRef =
|
|
3035
|
+
const abortControllerRef = useRef6(null);
|
|
3036
|
+
const searchHandleRef = useRef6(void 0);
|
|
3037
|
+
const initialStartRowRef = useRef6(initialStartRow);
|
|
2695
3038
|
initialStartRowRef.current = initialStartRow;
|
|
2696
|
-
const getCellValueRef =
|
|
3039
|
+
const getCellValueRef = useRef6(getCellValue);
|
|
2697
3040
|
getCellValueRef.current = getCellValue;
|
|
2698
3041
|
const showSearch = controlledShowSearch ?? internalShowSearch;
|
|
2699
3042
|
const searchValue = controlledSearchValue ?? internalSearchValue;
|
|
2700
3043
|
const searchResults = controlledSearchResults ?? internalResults;
|
|
2701
|
-
const setSearchValue =
|
|
3044
|
+
const setSearchValue = useCallback4(
|
|
2702
3045
|
(value) => {
|
|
2703
3046
|
setInternalSearchValue(value);
|
|
2704
3047
|
onSearchValueChange?.(value);
|
|
2705
3048
|
},
|
|
2706
3049
|
[onSearchValueChange]
|
|
2707
3050
|
);
|
|
2708
|
-
const cancelSearch =
|
|
3051
|
+
const cancelSearch = useCallback4(() => {
|
|
2709
3052
|
if (searchHandleRef.current !== void 0) {
|
|
2710
3053
|
window.cancelAnimationFrame(searchHandleRef.current);
|
|
2711
3054
|
searchHandleRef.current = void 0;
|
|
2712
3055
|
}
|
|
2713
3056
|
abortControllerRef.current?.abort();
|
|
2714
3057
|
}, []);
|
|
2715
|
-
const emitResultsChanged =
|
|
3058
|
+
const emitResultsChanged = useCallback4(
|
|
2716
3059
|
(results, navIndex) => {
|
|
2717
3060
|
onSearchResultsChanged?.(results, navIndex);
|
|
2718
3061
|
},
|
|
2719
3062
|
[onSearchResultsChanged]
|
|
2720
3063
|
);
|
|
2721
|
-
const navigateToIndex =
|
|
3064
|
+
const navigateToIndex = useCallback4(
|
|
2722
3065
|
(results, navIndex) => {
|
|
2723
3066
|
if (onSearchResultsChanged) return;
|
|
2724
3067
|
if (navIndex < 0 || navIndex >= results.length) return;
|
|
@@ -2728,7 +3071,7 @@ function useInlineSearch({
|
|
|
2728
3071
|
},
|
|
2729
3072
|
[onNavigateToResult, onSearchResultsChanged]
|
|
2730
3073
|
);
|
|
2731
|
-
const beginSearch =
|
|
3074
|
+
const beginSearch = useCallback4(
|
|
2732
3075
|
(query) => {
|
|
2733
3076
|
if (controlledSearchResults !== void 0) return;
|
|
2734
3077
|
const totalRows = rowCount;
|
|
@@ -2800,12 +3143,12 @@ function useInlineSearch({
|
|
|
2800
3143
|
rowCount
|
|
2801
3144
|
]
|
|
2802
3145
|
);
|
|
2803
|
-
const openSearch =
|
|
3146
|
+
const openSearch = useCallback4(() => {
|
|
2804
3147
|
if (controlledShowSearch === void 0) {
|
|
2805
3148
|
setInternalShowSearch(true);
|
|
2806
3149
|
}
|
|
2807
3150
|
}, [controlledShowSearch]);
|
|
2808
|
-
const closeSearch =
|
|
3151
|
+
const closeSearch = useCallback4(() => {
|
|
2809
3152
|
if (controlledShowSearch === void 0) {
|
|
2810
3153
|
setInternalShowSearch(false);
|
|
2811
3154
|
}
|
|
@@ -2820,7 +3163,7 @@ function useInlineSearch({
|
|
|
2820
3163
|
emitResultsChanged,
|
|
2821
3164
|
onSearchClose
|
|
2822
3165
|
]);
|
|
2823
|
-
const goToNext =
|
|
3166
|
+
const goToNext = useCallback4(() => {
|
|
2824
3167
|
if (!searchStatus || searchStatus.results === 0) return;
|
|
2825
3168
|
const newIndex = nextSearchIndex(
|
|
2826
3169
|
searchStatus.selectedIndex,
|
|
@@ -2830,7 +3173,7 @@ function useInlineSearch({
|
|
|
2830
3173
|
emitResultsChanged(searchResults, newIndex);
|
|
2831
3174
|
navigateToIndex(searchResults, newIndex);
|
|
2832
3175
|
}, [emitResultsChanged, navigateToIndex, searchResults, searchStatus]);
|
|
2833
|
-
const goToPrevious =
|
|
3176
|
+
const goToPrevious = useCallback4(() => {
|
|
2834
3177
|
if (!searchStatus || searchStatus.results === 0) return;
|
|
2835
3178
|
const newIndex = previousSearchIndex(
|
|
2836
3179
|
searchStatus.selectedIndex,
|
|
@@ -2840,7 +3183,7 @@ function useInlineSearch({
|
|
|
2840
3183
|
emitResultsChanged(searchResults, newIndex);
|
|
2841
3184
|
navigateToIndex(searchResults, newIndex);
|
|
2842
3185
|
}, [emitResultsChanged, navigateToIndex, searchResults, searchStatus]);
|
|
2843
|
-
|
|
3186
|
+
useEffect6(() => {
|
|
2844
3187
|
if (controlledSearchResults === void 0) return;
|
|
2845
3188
|
if (controlledSearchResults.length > 0) {
|
|
2846
3189
|
setSearchStatus((current) => ({
|
|
@@ -2852,7 +3195,7 @@ function useInlineSearch({
|
|
|
2852
3195
|
setSearchStatus(void 0);
|
|
2853
3196
|
}
|
|
2854
3197
|
}, [controlledSearchResults, rowCount]);
|
|
2855
|
-
|
|
3198
|
+
useEffect6(() => {
|
|
2856
3199
|
if (!enabled) return;
|
|
2857
3200
|
setSearchStatus(void 0);
|
|
2858
3201
|
setInternalResults([]);
|
|
@@ -2865,7 +3208,7 @@ function useInlineSearch({
|
|
|
2865
3208
|
cancelSearch();
|
|
2866
3209
|
}
|
|
2867
3210
|
}, [enabled, showSearch]);
|
|
2868
|
-
|
|
3211
|
+
useEffect6(() => {
|
|
2869
3212
|
if (!enabled || !showSearch) return;
|
|
2870
3213
|
if (controlledSearchResults !== void 0) return;
|
|
2871
3214
|
if (searchValue.trim() === "") {
|
|
@@ -2885,7 +3228,7 @@ function useInlineSearch({
|
|
|
2885
3228
|
searchValue,
|
|
2886
3229
|
showSearch
|
|
2887
3230
|
]);
|
|
2888
|
-
|
|
3231
|
+
useEffect6(() => {
|
|
2889
3232
|
if (!enabled) return;
|
|
2890
3233
|
const handleKeyDown = (event) => {
|
|
2891
3234
|
if (!(event.ctrlKey || event.metaKey)) return;
|
|
@@ -2912,7 +3255,7 @@ function useInlineSearch({
|
|
|
2912
3255
|
window.addEventListener("keydown", handleKeyDown, true);
|
|
2913
3256
|
return () => window.removeEventListener("keydown", handleKeyDown, true);
|
|
2914
3257
|
}, [controlledShowSearch, enabled, rootRef, showSearch]);
|
|
2915
|
-
|
|
3258
|
+
useEffect6(() => () => cancelSearch(), [cancelSearch]);
|
|
2916
3259
|
const searchMatchKeys = useMemo2(
|
|
2917
3260
|
() => buildSearchMatchKeys(searchResults),
|
|
2918
3261
|
[searchResults]
|
|
@@ -2982,6 +3325,7 @@ var DEFAULT_DATA_TABLE_LABELS = {
|
|
|
2982
3325
|
expandRow: "Expand row",
|
|
2983
3326
|
collapseRow: "Collapse row",
|
|
2984
3327
|
resizeColumn: "Resize column",
|
|
3328
|
+
reorderColumn: "Reorder column",
|
|
2985
3329
|
searchPlaceholder: "Search\u2026",
|
|
2986
3330
|
searchResultHint: "Type to search",
|
|
2987
3331
|
searchPrevious: "Previous result",
|
|
@@ -3039,6 +3383,9 @@ function useGlideTable(options) {
|
|
|
3039
3383
|
columnSizing: controlledColumnSizing,
|
|
3040
3384
|
onColumnSizingChange,
|
|
3041
3385
|
columnResizeMode = "onChange",
|
|
3386
|
+
enableColumnReorder = false,
|
|
3387
|
+
columnOrder: controlledColumnOrder,
|
|
3388
|
+
onColumnOrderChange,
|
|
3042
3389
|
enableColumnFreeze = false,
|
|
3043
3390
|
enableInlineSearch = false,
|
|
3044
3391
|
showSearch,
|
|
@@ -3059,16 +3406,17 @@ function useGlideTable(options) {
|
|
|
3059
3406
|
}, [labelsProp, emptyText, loadingText, selectionLabel]);
|
|
3060
3407
|
const enableExpand = Boolean(toggleField);
|
|
3061
3408
|
const resolvedEnableSubtreeCopy = enableSubtreeCopy ?? enableExpand;
|
|
3062
|
-
const [internalRowSelection, setInternalRowSelection] =
|
|
3063
|
-
const [internalColumnSizing, setInternalColumnSizing] =
|
|
3064
|
-
const [
|
|
3409
|
+
const [internalRowSelection, setInternalRowSelection] = useState5({});
|
|
3410
|
+
const [internalColumnSizing, setInternalColumnSizing] = useState5({});
|
|
3411
|
+
const [internalColumnOrder, setInternalColumnOrder] = useState5([]);
|
|
3412
|
+
const [internalExpandedRows, setInternalExpandedRows] = useState5(
|
|
3065
3413
|
() => /* @__PURE__ */ new Set()
|
|
3066
3414
|
);
|
|
3067
|
-
const [hoveredRowIndex, setHoveredRowIndex] =
|
|
3068
|
-
const scrollRef =
|
|
3069
|
-
const rootRef =
|
|
3415
|
+
const [hoveredRowIndex, setHoveredRowIndex] = useState5(null);
|
|
3416
|
+
const scrollRef = useRef7(null);
|
|
3417
|
+
const rootRef = useRef7(null);
|
|
3070
3418
|
const shouldVirtualize = enableVirtualization && !enableRowSpan;
|
|
3071
|
-
|
|
3419
|
+
useEffect7(() => {
|
|
3072
3420
|
if (enableVirtualization && enableRowSpan) {
|
|
3073
3421
|
console.warn(
|
|
3074
3422
|
"[useGlideTable] enableRowSpan is on; virtualization is disabled to preserve cell merges."
|
|
@@ -3081,8 +3429,23 @@ function useGlideTable(options) {
|
|
|
3081
3429
|
internalRowSelection
|
|
3082
3430
|
);
|
|
3083
3431
|
const columnSizing = controlledColumnSizing ?? internalColumnSizing;
|
|
3432
|
+
const columnOrder = controlledColumnOrder ?? internalColumnOrder;
|
|
3433
|
+
const tableColumns = useMemo3(() => {
|
|
3434
|
+
if (!enableColumnReorder) return columns;
|
|
3435
|
+
return applyLeafColumnOrder(columns, columnOrder);
|
|
3436
|
+
}, [columnOrder, columns, enableColumnReorder]);
|
|
3437
|
+
const setColumnOrder = useCallback5(
|
|
3438
|
+
(next) => {
|
|
3439
|
+
if (onColumnOrderChange) {
|
|
3440
|
+
onColumnOrderChange(next);
|
|
3441
|
+
return;
|
|
3442
|
+
}
|
|
3443
|
+
setInternalColumnOrder(next);
|
|
3444
|
+
},
|
|
3445
|
+
[onColumnOrderChange]
|
|
3446
|
+
);
|
|
3084
3447
|
const expandedRows = controlledExpandedRows ?? internalExpandedRows;
|
|
3085
|
-
const handleExpandedRowsChange =
|
|
3448
|
+
const handleExpandedRowsChange = useCallback5(
|
|
3086
3449
|
(next) => {
|
|
3087
3450
|
if (onExpandedRowsChange) {
|
|
3088
3451
|
onExpandedRowsChange(next);
|
|
@@ -3105,7 +3468,7 @@ function useGlideTable(options) {
|
|
|
3105
3468
|
});
|
|
3106
3469
|
const table = useReactTable({
|
|
3107
3470
|
data: tableData,
|
|
3108
|
-
columns,
|
|
3471
|
+
columns: tableColumns,
|
|
3109
3472
|
...enableColumnResize ? {
|
|
3110
3473
|
defaultColumn: {
|
|
3111
3474
|
minSize: DATA_TABLE_COLUMN_MIN_SIZE,
|
|
@@ -3185,7 +3548,7 @@ function useGlideTable(options) {
|
|
|
3185
3548
|
}
|
|
3186
3549
|
return indices;
|
|
3187
3550
|
}, [selectedRows]);
|
|
3188
|
-
const scrollCellIntoView =
|
|
3551
|
+
const scrollCellIntoView = useCallback5(
|
|
3189
3552
|
(rowIndex, colIndex, options2) => {
|
|
3190
3553
|
const align = options2?.align ?? "nearest";
|
|
3191
3554
|
const blockAlign = align === "center" ? "center" : "nearest";
|
|
@@ -3212,7 +3575,7 @@ function useGlideTable(options) {
|
|
|
3212
3575
|
},
|
|
3213
3576
|
[rowVirtualizer, shouldVirtualize]
|
|
3214
3577
|
);
|
|
3215
|
-
const handleCellNavigate =
|
|
3578
|
+
const handleCellNavigate = useCallback5(
|
|
3216
3579
|
(position) => {
|
|
3217
3580
|
scrollCellIntoView(position.row, position.col, { align: "nearest" });
|
|
3218
3581
|
},
|
|
@@ -3249,7 +3612,7 @@ function useGlideTable(options) {
|
|
|
3249
3612
|
() => createCellRendererRegistry(cellRenderers),
|
|
3250
3613
|
[cellRenderers]
|
|
3251
3614
|
);
|
|
3252
|
-
const commitRenderedCellValue =
|
|
3615
|
+
const commitRenderedCellValue = useCallback5(
|
|
3253
3616
|
(rowId, columnId, value) => commitCellValue({
|
|
3254
3617
|
data: tableData,
|
|
3255
3618
|
rows,
|
|
@@ -3261,11 +3624,11 @@ function useGlideTable(options) {
|
|
|
3261
3624
|
}),
|
|
3262
3625
|
[onCellChange, onDataChange, rows, tableData]
|
|
3263
3626
|
);
|
|
3264
|
-
const getCellContext =
|
|
3627
|
+
const getCellContext = useCallback5(
|
|
3265
3628
|
(cell) => withCellUpdate(cell.getContext(), commitRenderedCellValue),
|
|
3266
3629
|
[commitRenderedCellValue]
|
|
3267
3630
|
);
|
|
3268
|
-
const handleCellMouseDownWithCommit =
|
|
3631
|
+
const handleCellMouseDownWithCommit = useCallback5(
|
|
3269
3632
|
(rowIndex, colIndex, options2) => {
|
|
3270
3633
|
const isSameEditingCell = editingCell?.rowIndex === rowIndex && editingCell?.colIndex === colIndex;
|
|
3271
3634
|
if (editingCell && !isSameEditingCell && !commitEdit()) {
|
|
@@ -3275,7 +3638,7 @@ function useGlideTable(options) {
|
|
|
3275
3638
|
},
|
|
3276
3639
|
[commitEdit, editingCell, handleCellMouseDown]
|
|
3277
3640
|
);
|
|
3278
|
-
const navigateToSearchResult =
|
|
3641
|
+
const navigateToSearchResult = useCallback5(
|
|
3279
3642
|
(item) => {
|
|
3280
3643
|
const [colIndex, rowIndex] = item;
|
|
3281
3644
|
handleCellMouseDownWithCommit(rowIndex, colIndex);
|
|
@@ -3283,7 +3646,7 @@ function useGlideTable(options) {
|
|
|
3283
3646
|
},
|
|
3284
3647
|
[handleCellMouseDownWithCommit, scrollCellIntoView]
|
|
3285
3648
|
);
|
|
3286
|
-
const resolveSearchRowId =
|
|
3649
|
+
const resolveSearchRowId = useCallback5(
|
|
3287
3650
|
(row, index) => {
|
|
3288
3651
|
if (getRowId) return getRowId(row, index);
|
|
3289
3652
|
if (enableExpand) {
|
|
@@ -3323,7 +3686,7 @@ function useGlideTable(options) {
|
|
|
3323
3686
|
tableData,
|
|
3324
3687
|
toggleField
|
|
3325
3688
|
]);
|
|
3326
|
-
const searchCorpusRef =
|
|
3689
|
+
const searchCorpusRef = useRef7(searchCorpus);
|
|
3327
3690
|
searchCorpusRef.current = searchCorpus;
|
|
3328
3691
|
const visibleRowIndexById = useMemo3(() => {
|
|
3329
3692
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -3332,7 +3695,7 @@ function useGlideTable(options) {
|
|
|
3332
3695
|
}
|
|
3333
3696
|
return map;
|
|
3334
3697
|
}, [resolveSearchRowId, rows]);
|
|
3335
|
-
const getSearchCellValue =
|
|
3698
|
+
const getSearchCellValue = useCallback5(
|
|
3336
3699
|
(rowIndex, colIndex) => {
|
|
3337
3700
|
const corpusRow = searchCorpusRef.current[rowIndex];
|
|
3338
3701
|
const column = visibleLeafColumns[colIndex];
|
|
@@ -3355,14 +3718,14 @@ function useGlideTable(options) {
|
|
|
3355
3718
|
},
|
|
3356
3719
|
[rows, visibleLeafColumns, visibleRowIndexById]
|
|
3357
3720
|
);
|
|
3358
|
-
const pendingSearchNavRef =
|
|
3359
|
-
const focusSearchResult =
|
|
3721
|
+
const pendingSearchNavRef = useRef7(null);
|
|
3722
|
+
const focusSearchResult = useCallback5(
|
|
3360
3723
|
(colIndex, visibleRowIndex) => {
|
|
3361
3724
|
navigateToSearchResult([colIndex, visibleRowIndex]);
|
|
3362
3725
|
},
|
|
3363
3726
|
[navigateToSearchResult]
|
|
3364
3727
|
);
|
|
3365
|
-
const navigateToCorpusSearchResult =
|
|
3728
|
+
const navigateToCorpusSearchResult = useCallback5(
|
|
3366
3729
|
(item) => {
|
|
3367
3730
|
const [colIndex, corpusRowIndex] = item;
|
|
3368
3731
|
const corpusRow = searchCorpusRef.current[corpusRowIndex];
|
|
@@ -3395,7 +3758,7 @@ function useGlideTable(options) {
|
|
|
3395
3758
|
visibleRowIndexById
|
|
3396
3759
|
]
|
|
3397
3760
|
);
|
|
3398
|
-
|
|
3761
|
+
useEffect7(() => {
|
|
3399
3762
|
const pending = pendingSearchNavRef.current;
|
|
3400
3763
|
if (!pending) return;
|
|
3401
3764
|
const visibleRowIndex = visibleRowIndexById.get(pending.rowId);
|
|
@@ -3445,13 +3808,13 @@ function useGlideTable(options) {
|
|
|
3445
3808
|
searchCorpus,
|
|
3446
3809
|
visibleRowIndexById
|
|
3447
3810
|
]);
|
|
3448
|
-
const clearHover =
|
|
3811
|
+
const clearHover = useCallback5(() => {
|
|
3449
3812
|
setHoveredRowIndex(null);
|
|
3450
3813
|
}, []);
|
|
3451
|
-
const handleRowHover =
|
|
3814
|
+
const handleRowHover = useCallback5((rowIndex, _rowData) => {
|
|
3452
3815
|
setHoveredRowIndex(rowIndex);
|
|
3453
3816
|
}, []);
|
|
3454
|
-
const handleToggleSelect =
|
|
3817
|
+
const handleToggleSelect = useCallback5(
|
|
3455
3818
|
(row) => {
|
|
3456
3819
|
if (!row.getCanSelect()) return;
|
|
3457
3820
|
if (preserveRowSelection && row.getIsSelected()) {
|
|
@@ -3461,7 +3824,7 @@ function useGlideTable(options) {
|
|
|
3461
3824
|
},
|
|
3462
3825
|
[preserveRowSelection]
|
|
3463
3826
|
);
|
|
3464
|
-
const handleToggleExpand =
|
|
3827
|
+
const handleToggleExpand = useCallback5(
|
|
3465
3828
|
(rowKey) => {
|
|
3466
3829
|
if (preventExpand) return;
|
|
3467
3830
|
handleExpandedRowsChange(toggleExpandedRowId(rowKey, expandedRows));
|
|
@@ -3567,12 +3930,12 @@ function useGlideTable(options) {
|
|
|
3567
3930
|
visibleSearchMatchKeys,
|
|
3568
3931
|
visibleActiveMatch
|
|
3569
3932
|
]);
|
|
3570
|
-
const copySelectionRef =
|
|
3571
|
-
|
|
3933
|
+
const copySelectionRef = useRef7(copySelection);
|
|
3934
|
+
useEffect7(() => {
|
|
3572
3935
|
copySelectionRef.current = copySelection;
|
|
3573
3936
|
}, [copySelection]);
|
|
3574
|
-
const stableCopySelection =
|
|
3575
|
-
|
|
3937
|
+
const stableCopySelection = useCallback5((options2) => copySelectionRef.current(options2), []);
|
|
3938
|
+
useEffect7(() => {
|
|
3576
3939
|
onCopyActionsReady?.({ copySelection: stableCopySelection });
|
|
3577
3940
|
}, [onCopyActionsReady, stableCopySelection]);
|
|
3578
3941
|
return {
|
|
@@ -3587,6 +3950,7 @@ function useGlideTable(options) {
|
|
|
3587
3950
|
selectionLabel: labels.selection,
|
|
3588
3951
|
enableCellSelection,
|
|
3589
3952
|
enableColumnResize,
|
|
3953
|
+
enableColumnReorder,
|
|
3590
3954
|
enableColumnFreeze,
|
|
3591
3955
|
enableInlineSearch,
|
|
3592
3956
|
shouldVirtualize,
|
|
@@ -3600,6 +3964,7 @@ function useGlideTable(options) {
|
|
|
3600
3964
|
getCellContext,
|
|
3601
3965
|
handleToggleSelect,
|
|
3602
3966
|
clearHover,
|
|
3967
|
+
setColumnOrder,
|
|
3603
3968
|
copySelection: stableCopySelection,
|
|
3604
3969
|
inlineSearch: {
|
|
3605
3970
|
showSearch: inlineSearch.showSearch,
|
|
@@ -3683,6 +4048,7 @@ function DataTable({
|
|
|
3683
4048
|
selectionLabel,
|
|
3684
4049
|
enableCellSelection,
|
|
3685
4050
|
enableColumnResize,
|
|
4051
|
+
enableColumnReorder,
|
|
3686
4052
|
enableColumnFreeze,
|
|
3687
4053
|
enableInlineSearch,
|
|
3688
4054
|
shouldVirtualize,
|
|
@@ -3695,6 +4061,7 @@ function DataTable({
|
|
|
3695
4061
|
rowContextValue,
|
|
3696
4062
|
handleToggleSelect,
|
|
3697
4063
|
clearHover,
|
|
4064
|
+
setColumnOrder,
|
|
3698
4065
|
inlineSearch
|
|
3699
4066
|
} = useGlideTable(glideOptions);
|
|
3700
4067
|
const ToolbarSlot = slots?.Toolbar ?? DataTableToolbar;
|
|
@@ -3704,6 +4071,12 @@ function DataTable({
|
|
|
3704
4071
|
const EmptySlot = slots?.Empty ?? DefaultEmpty;
|
|
3705
4072
|
const freezeOffsets = rowContextValue.columnFreeze.offsets;
|
|
3706
4073
|
const headerGroups = getMergedHeaderGroups(table.getHeaderGroups());
|
|
4074
|
+
const leafColumnIds = table.getVisibleLeafColumns().map((column) => column.id);
|
|
4075
|
+
const { isReordering, draggingColumnId, dropTarget, onHeaderPointerDown } = useColumnReorder({
|
|
4076
|
+
enabled: enableColumnReorder,
|
|
4077
|
+
columnOrder: leafColumnIds,
|
|
4078
|
+
onColumnOrderChange: setColumnOrder
|
|
4079
|
+
});
|
|
3707
4080
|
const contextValue = useMemo4(
|
|
3708
4081
|
() => ({ ...rowContextValue, classNames }),
|
|
3709
4082
|
[rowContextValue, classNames]
|
|
@@ -3726,6 +4099,8 @@ function DataTable({
|
|
|
3726
4099
|
"DataTableJSX",
|
|
3727
4100
|
!enableCellSelection && "DataTableJSX--no-cell-selection",
|
|
3728
4101
|
enableColumnResize && "DataTableJSX--column-resize",
|
|
4102
|
+
enableColumnReorder && "DataTableJSX--column-reorder",
|
|
4103
|
+
isReordering && "DataTableJSX--column-reordering",
|
|
3729
4104
|
enableColumnFreeze && "DataTableJSX--column-freeze",
|
|
3730
4105
|
enableInlineSearch && "DataTableJSX--inline-search",
|
|
3731
4106
|
classNames?.root,
|
|
@@ -3794,20 +4169,43 @@ function DataTable({
|
|
|
3794
4169
|
...sizeStyle,
|
|
3795
4170
|
...freezeStyle
|
|
3796
4171
|
};
|
|
4172
|
+
const isPlaceholder = header.isPlaceholder;
|
|
4173
|
+
const leafColumns = header.column.getLeafColumns();
|
|
4174
|
+
const leafIds = leafColumns.map((leafColumn) => leafColumn.id);
|
|
4175
|
+
const isLeafHeader = !isPlaceholder && header.subHeaders.length === 0;
|
|
4176
|
+
const canDrag = enableColumnReorder && !isPlaceholder && leafIds.length > 0 && leafColumns.every(
|
|
4177
|
+
(leafColumn) => isColumnReorderable(leafColumn.columnDef.meta)
|
|
4178
|
+
);
|
|
4179
|
+
const isDragging = draggingColumnId === header.column.id;
|
|
4180
|
+
const dropEdge = !isPlaceholder && dropTarget?.columnId === header.column.id ? dropTarget.edge : void 0;
|
|
3797
4181
|
return /* @__PURE__ */ jsxs6(
|
|
3798
4182
|
"th",
|
|
3799
4183
|
{
|
|
3800
4184
|
colSpan: header.colSpan,
|
|
3801
4185
|
rowSpan: header.mergedRowSpan,
|
|
4186
|
+
"data-column-id": enableColumnReorder && !isPlaceholder ? header.column.id : void 0,
|
|
4187
|
+
"data-reorder-ids": enableColumnReorder && !isPlaceholder ? serializeReorderIds(leafIds) : void 0,
|
|
4188
|
+
"data-reorder-leaf": enableColumnReorder && isLeafHeader ? "" : void 0,
|
|
4189
|
+
"data-reorderable": canDrag ? "" : void 0,
|
|
4190
|
+
"data-reordering": isDragging ? "" : void 0,
|
|
4191
|
+
"data-drop-edge": dropEdge,
|
|
3802
4192
|
"data-resizing": header.column.getIsResizing() ? "" : void 0,
|
|
3803
4193
|
"data-frozen": freezeOffset?.side,
|
|
3804
4194
|
"data-freeze-edge": getColumnFreezeEdgeAttr(freezeOffset),
|
|
4195
|
+
"aria-grabbed": isDragging ? true : void 0,
|
|
4196
|
+
title: canDrag ? labels.reorderColumn : void 0,
|
|
4197
|
+
onPointerDown: enableColumnReorder ? (event) => onHeaderPointerDown(event, {
|
|
4198
|
+
columnId: header.column.id,
|
|
4199
|
+
leafIds,
|
|
4200
|
+
canDrag
|
|
4201
|
+
}) : void 0,
|
|
3805
4202
|
style: Object.keys(headerStyle).length > 0 ? headerStyle : void 0,
|
|
3806
4203
|
className: cn(
|
|
3807
4204
|
"data-table-head-cell",
|
|
3808
4205
|
freezeOffset && `data-table-head-cell--frozen-${freezeOffset.side}`,
|
|
3809
4206
|
CELL_ALIGN_CLASS[align],
|
|
3810
4207
|
classNames?.headCell,
|
|
4208
|
+
dropEdge && classNames?.dropEdge,
|
|
3811
4209
|
headerClassName
|
|
3812
4210
|
),
|
|
3813
4211
|
children: [
|
|
@@ -3929,10 +4327,10 @@ function DataTable({
|
|
|
3929
4327
|
}
|
|
3930
4328
|
|
|
3931
4329
|
// src/components/ui/table/components/Table/Table.tsx
|
|
3932
|
-
import { useCallback as
|
|
4330
|
+
import { useCallback as useCallback7, useMemo as useMemo5, useState as useState6 } from "react";
|
|
3933
4331
|
|
|
3934
4332
|
// src/components/ui/table/features/cell-render/ResolvedTableCell.tsx
|
|
3935
|
-
import { useCallback as
|
|
4333
|
+
import { useCallback as useCallback6 } from "react";
|
|
3936
4334
|
function ResolvedTableCell({
|
|
3937
4335
|
info
|
|
3938
4336
|
}) {
|
|
@@ -3941,7 +4339,7 @@ function ResolvedTableCell({
|
|
|
3941
4339
|
const meta = column.columnDef.meta;
|
|
3942
4340
|
const value = getValue();
|
|
3943
4341
|
const columnId = column.id;
|
|
3944
|
-
const update =
|
|
4342
|
+
const update = useCallback6(
|
|
3945
4343
|
(next) => {
|
|
3946
4344
|
cellRender.commitValue(row.id, columnId, next);
|
|
3947
4345
|
},
|
|
@@ -4001,6 +4399,7 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
4001
4399
|
minWidth,
|
|
4002
4400
|
maxWidth,
|
|
4003
4401
|
resizable,
|
|
4402
|
+
reorderable,
|
|
4004
4403
|
frozen,
|
|
4005
4404
|
align,
|
|
4006
4405
|
rowSpan,
|
|
@@ -4046,6 +4445,7 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
4046
4445
|
cellProps,
|
|
4047
4446
|
cellRender: render,
|
|
4048
4447
|
frozen,
|
|
4448
|
+
reorderable,
|
|
4049
4449
|
className,
|
|
4050
4450
|
headerClassName
|
|
4051
4451
|
}
|
|
@@ -4293,8 +4693,8 @@ function TableRoot({
|
|
|
4293
4693
|
() => parseTableChildren(children),
|
|
4294
4694
|
[children]
|
|
4295
4695
|
);
|
|
4296
|
-
const [sort, setSort] =
|
|
4297
|
-
const handleSort =
|
|
4696
|
+
const [sort, setSort] = useState6(null);
|
|
4697
|
+
const handleSort = useCallback7((field) => {
|
|
4298
4698
|
setSort((previous) => {
|
|
4299
4699
|
if (previous?.field !== field) {
|
|
4300
4700
|
return { field, direction: "asc" };
|