@vitavision/workbench 0.3.2 → 0.3.4
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 +2 -1
- package/dist/index.d.ts +118 -2
- package/dist/index.js +552 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/SequenceMatrix.tsx +499 -0
- package/src/components/matrixModel.ts +126 -0
- package/src/index.ts +9 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Button, Kbd, ReadoutStrip, Select, Slider, StatusDot, Toaster, Tooltip, byDensity, cn, createToastStore, defaultToastStore, focusRing, toast, toneColor, useDensity } from "@vitavision/ui";
|
|
2
|
-
import { cloneElement, createContext, isValidElement, use, useCallback, useEffect, useEffectEvent, useId, useRef, useState, useSyncExternalStore } from "react";
|
|
1
|
+
import { Button, Kbd, ReadoutStrip, Select, Slider, StatusDot, Toaster, Tooltip, byDensity, cn, createToastStore, defaultToastStore, focusRing, focusRingInset, toast, toneColor, useDensity } from "@vitavision/ui";
|
|
2
|
+
import { cloneElement, createContext, isValidElement, use, useCallback, useEffect, useEffectEvent, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
3
3
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
import { Check, ChevronFirst, ChevronLast, ChevronLeft, ChevronRight, FolderOpen, Lock, Pause, Play, Repeat, SkipBack, SkipForward, StepBack, StepForward } from "lucide-react";
|
|
5
5
|
//#region src/components/splitSize.ts
|
|
@@ -1645,6 +1645,555 @@ function isTypingTarget(target) {
|
|
|
1645
1645
|
return tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || target.isContentEditable;
|
|
1646
1646
|
}
|
|
1647
1647
|
//#endregion
|
|
1648
|
+
//#region src/components/matrixModel.ts
|
|
1649
|
+
const clamp = (value, low, high) => Math.min(high, Math.max(low, value));
|
|
1650
|
+
/**
|
|
1651
|
+
* Where a navigation key takes the cursor.
|
|
1652
|
+
*
|
|
1653
|
+
* - Arrows move one cell and stop at the edge.
|
|
1654
|
+
* - `Home` and `End` go to the first and last column of the row; with `ctrl`, to the first and
|
|
1655
|
+
* last cell of the grid.
|
|
1656
|
+
* - `PageUp` and `PageDown` move `page` rows.
|
|
1657
|
+
*
|
|
1658
|
+
* @param from - The cursor.
|
|
1659
|
+
* @param key - A `KeyboardEvent.key`.
|
|
1660
|
+
* @param size - The grid.
|
|
1661
|
+
* @param page - Rows in a page, at least 1.
|
|
1662
|
+
* @param ctrl - Whether Ctrl (or Cmd) is held.
|
|
1663
|
+
* @returns The new position, or `null` when the key is not a navigation key or the grid is empty.
|
|
1664
|
+
* The position is clamped, so it may equal `from`.
|
|
1665
|
+
*/
|
|
1666
|
+
function moveFocus(from, key, size, page, ctrl = false) {
|
|
1667
|
+
if (size.rows <= 0 || size.cols <= 0) return null;
|
|
1668
|
+
const lastRow = size.rows - 1;
|
|
1669
|
+
const lastCol = size.cols - 1;
|
|
1670
|
+
const step = Math.max(1, Math.floor(page));
|
|
1671
|
+
const at = (row, col) => ({
|
|
1672
|
+
row: clamp(row, 0, lastRow),
|
|
1673
|
+
col: clamp(col, 0, lastCol)
|
|
1674
|
+
});
|
|
1675
|
+
switch (key) {
|
|
1676
|
+
case "ArrowUp": return at(from.row - 1, from.col);
|
|
1677
|
+
case "ArrowDown": return at(from.row + 1, from.col);
|
|
1678
|
+
case "ArrowLeft": return at(from.row, from.col - 1);
|
|
1679
|
+
case "ArrowRight": return at(from.row, from.col + 1);
|
|
1680
|
+
case "Home": return ctrl ? at(0, 0) : at(from.row, 0);
|
|
1681
|
+
case "End": return ctrl ? at(lastRow, lastCol) : at(from.row, lastCol);
|
|
1682
|
+
case "PageUp": return at(from.row - step, from.col);
|
|
1683
|
+
case "PageDown": return at(from.row + step, from.col);
|
|
1684
|
+
default: return null;
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
/**
|
|
1688
|
+
* The items of one axis to render for a scroll position, plus a margin.
|
|
1689
|
+
*
|
|
1690
|
+
* @param scroll - The scroll offset along the axis, in pixels, from the start of the body.
|
|
1691
|
+
* @param viewport - The room the body has on that axis (the scroller's size less the sticky header).
|
|
1692
|
+
* @param size - One item's size in pixels.
|
|
1693
|
+
* @param count - The number of items.
|
|
1694
|
+
* @param overscan - Extra items on each side.
|
|
1695
|
+
* @returns `[start, end)`: indices to render. `[0, 0)` for no items or a non-positive size.
|
|
1696
|
+
*/
|
|
1697
|
+
function windowRange(scroll, viewport, size, count, overscan) {
|
|
1698
|
+
if (count <= 0 || !(size > 0)) return [0, 0];
|
|
1699
|
+
const first = Math.floor(Math.max(0, scroll) / size);
|
|
1700
|
+
const last = Math.ceil((Math.max(0, scroll) + Math.max(0, viewport)) / size);
|
|
1701
|
+
if (first >= count) return [Math.max(0, count - 1 - overscan), count];
|
|
1702
|
+
const start = clamp(first - overscan, 0, count);
|
|
1703
|
+
return [start, clamp(last + overscan, start, count)];
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* The scroll offset that brings an item fully into view, moving as little as possible.
|
|
1707
|
+
*
|
|
1708
|
+
* @param scroll - The current offset.
|
|
1709
|
+
* @param viewport - The room the body has on this axis.
|
|
1710
|
+
* @param index - The item.
|
|
1711
|
+
* @param size - One item's size.
|
|
1712
|
+
* @returns The offset: unchanged when the item is in view already, never negative.
|
|
1713
|
+
*/
|
|
1714
|
+
function revealScroll(scroll, viewport, index, size) {
|
|
1715
|
+
const start = index * size;
|
|
1716
|
+
const end = start + size;
|
|
1717
|
+
if (start < scroll) return Math.max(0, start);
|
|
1718
|
+
if (end > scroll + viewport) return Math.max(0, end - viewport);
|
|
1719
|
+
return scroll;
|
|
1720
|
+
}
|
|
1721
|
+
/** The rectangle between two cells, in whichever order they are given. */
|
|
1722
|
+
function rectBetween(a, b) {
|
|
1723
|
+
return {
|
|
1724
|
+
row0: Math.min(a.row, b.row),
|
|
1725
|
+
row1: Math.max(a.row, b.row),
|
|
1726
|
+
col0: Math.min(a.col, b.col),
|
|
1727
|
+
col1: Math.max(a.col, b.col)
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
/** Whether a cell is in a rectangle. */
|
|
1731
|
+
function inRect(rect, row, col) {
|
|
1732
|
+
return rect !== null && row >= rect.row0 && row <= rect.row1 && col >= rect.col0 && col <= rect.col1;
|
|
1733
|
+
}
|
|
1734
|
+
//#endregion
|
|
1735
|
+
//#region src/components/SequenceMatrix.tsx
|
|
1736
|
+
const DEFAULTS = {
|
|
1737
|
+
rowHeight: 36,
|
|
1738
|
+
colWidth: 72,
|
|
1739
|
+
headerHeight: 32,
|
|
1740
|
+
rowHeaderWidth: 96,
|
|
1741
|
+
overscan: 3
|
|
1742
|
+
};
|
|
1743
|
+
/** The room assumed before the scroller is measured, and on the server. */
|
|
1744
|
+
const INITIAL_VIEWPORT = {
|
|
1745
|
+
width: 640,
|
|
1746
|
+
height: 400
|
|
1747
|
+
};
|
|
1748
|
+
const sameWin = (a, b) => a.rows[0] === b.rows[0] && a.rows[1] === b.rows[1] && a.cols[0] === b.cols[0] && a.cols[1] === b.cols[1];
|
|
1749
|
+
const nameOf = (item) => item.name ?? (typeof item.label === "string" || typeof item.label === "number" ? String(item.label) : item.id);
|
|
1750
|
+
/** The grid cell, row header or column header an event came from, with its position. */
|
|
1751
|
+
function locate(target) {
|
|
1752
|
+
const element = target?.closest?.("[data-cell],[data-row-header],[data-col-header]");
|
|
1753
|
+
if (!element) return null;
|
|
1754
|
+
const row = Number(element.dataset["r"] ?? -1);
|
|
1755
|
+
const col = Number(element.dataset["c"] ?? -1);
|
|
1756
|
+
if (element.hasAttribute("data-cell")) return {
|
|
1757
|
+
kind: "cell",
|
|
1758
|
+
row,
|
|
1759
|
+
col,
|
|
1760
|
+
element
|
|
1761
|
+
};
|
|
1762
|
+
return element.hasAttribute("data-row-header") ? {
|
|
1763
|
+
kind: "row",
|
|
1764
|
+
row,
|
|
1765
|
+
col,
|
|
1766
|
+
element
|
|
1767
|
+
} : {
|
|
1768
|
+
kind: "col",
|
|
1769
|
+
row,
|
|
1770
|
+
col,
|
|
1771
|
+
element
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1774
|
+
/**
|
|
1775
|
+
* A windowed rows-by-columns grid with sticky headers and cell-level keyboard focus.
|
|
1776
|
+
*
|
|
1777
|
+
* - **Windowed in both axes**: only the cells in view (plus `overscan`, plus the focused cell) are
|
|
1778
|
+
* in the DOM, so ten columns by several hundred rows are a few dozen elements. Row height and
|
|
1779
|
+
* column width are uniform.
|
|
1780
|
+
* - **Keyboard**: the grid is one Tab stop (roving `tabindex` on the focused cell). Arrows move by
|
|
1781
|
+
* cell, Home/End to the ends of the row, Ctrl + Home/End to the corners, PageUp/PageDown by a
|
|
1782
|
+
* screenful of rows. Space or Enter selects the focused cell and Enter also calls `onCellAction`;
|
|
1783
|
+
* Shift + a move or Shift + click extends the selection to a rectangle; Shift + Space selects
|
|
1784
|
+
* the focused row, Ctrl + Space its column, Ctrl + A everything.
|
|
1785
|
+
* - **Selection**: one cell or a rectangle, controlled (`value`) or not. A click on a row or
|
|
1786
|
+
* column header selects that whole row or column.
|
|
1787
|
+
* - **Roles**: `grid` with `aria-rowcount` and `aria-colcount` (counting the headers), `row`s with
|
|
1788
|
+
* `aria-rowindex`, `columnheader`, `rowheader` and `gridcell`s with `aria-colindex` and
|
|
1789
|
+
* `aria-selected`; the whole rectangle is `aria-multiselectable`. Cells carry `data-selected`
|
|
1790
|
+
* and `data-focused`.
|
|
1791
|
+
* - **No listeners per cell**: clicks, keys and focus are handled once, on the scroller.
|
|
1792
|
+
*
|
|
1793
|
+
* Server rendering draws the first screenful of an assumed 640 by 400 px, without measuring.
|
|
1794
|
+
*/
|
|
1795
|
+
function SequenceMatrix({ rows, columns, renderCell, cellLabel, renderRowHeader, renderColumnHeader, corner, rowHeight = DEFAULTS.rowHeight, colWidth = DEFAULTS.colWidth, headerHeight = DEFAULTS.headerHeight, rowHeaderWidth = DEFAULTS.rowHeaderWidth, overscan = DEFAULTS.overscan, windowed = true, value: controlled, defaultValue = null, onValueChange, selectionFollowsFocus = false, multiple = true, onCellAction, "aria-label": ariaLabel, className, style }) {
|
|
1796
|
+
const scrollerRef = useRef(null);
|
|
1797
|
+
const [inner, setInner] = useState(defaultValue);
|
|
1798
|
+
const value = controlled === void 0 ? inner : controlled;
|
|
1799
|
+
const [focus, setFocus] = useState(null);
|
|
1800
|
+
const [hasFocus, setHasFocus] = useState(false);
|
|
1801
|
+
const focusPending = useRef(false);
|
|
1802
|
+
const rowIndex = useMemo(() => new Map(rows.map((row, i) => [row.id, i])), [rows]);
|
|
1803
|
+
const colIndex = useMemo(() => new Map(columns.map((column, i) => [column.id, i])), [columns]);
|
|
1804
|
+
const nRows = rows.length;
|
|
1805
|
+
const nCols = columns.length;
|
|
1806
|
+
const initialWin = () => windowed ? {
|
|
1807
|
+
rows: windowRange(0, INITIAL_VIEWPORT.height - headerHeight, rowHeight, nRows, overscan),
|
|
1808
|
+
cols: windowRange(0, INITIAL_VIEWPORT.width - rowHeaderWidth, colWidth, nCols, overscan)
|
|
1809
|
+
} : {
|
|
1810
|
+
rows: [0, nRows],
|
|
1811
|
+
cols: [0, nCols]
|
|
1812
|
+
};
|
|
1813
|
+
const [win, setWin] = useState(initialWin);
|
|
1814
|
+
const measure = useCallback(() => {
|
|
1815
|
+
const el = scrollerRef.current;
|
|
1816
|
+
if (!el) return;
|
|
1817
|
+
const next = windowed ? {
|
|
1818
|
+
rows: windowRange(el.scrollTop, el.clientHeight - headerHeight, rowHeight, nRows, overscan),
|
|
1819
|
+
cols: windowRange(el.scrollLeft, el.clientWidth - rowHeaderWidth, colWidth, nCols, overscan)
|
|
1820
|
+
} : {
|
|
1821
|
+
rows: [0, nRows],
|
|
1822
|
+
cols: [0, nCols]
|
|
1823
|
+
};
|
|
1824
|
+
setWin((prev) => sameWin(prev, next) ? prev : next);
|
|
1825
|
+
}, [
|
|
1826
|
+
windowed,
|
|
1827
|
+
headerHeight,
|
|
1828
|
+
rowHeight,
|
|
1829
|
+
nRows,
|
|
1830
|
+
overscan,
|
|
1831
|
+
rowHeaderWidth,
|
|
1832
|
+
colWidth,
|
|
1833
|
+
nCols
|
|
1834
|
+
]);
|
|
1835
|
+
useLayoutEffect(() => {
|
|
1836
|
+
measure();
|
|
1837
|
+
}, [measure]);
|
|
1838
|
+
useEffect(() => {
|
|
1839
|
+
const el = scrollerRef.current;
|
|
1840
|
+
if (!el || typeof ResizeObserver === "undefined") return;
|
|
1841
|
+
const observer = new ResizeObserver(() => measure());
|
|
1842
|
+
observer.observe(el);
|
|
1843
|
+
return () => observer.disconnect();
|
|
1844
|
+
}, [measure]);
|
|
1845
|
+
const range = useMemo(() => {
|
|
1846
|
+
if (!value) return null;
|
|
1847
|
+
const a = {
|
|
1848
|
+
row: rowIndex.get(value.row),
|
|
1849
|
+
col: colIndex.get(value.col)
|
|
1850
|
+
};
|
|
1851
|
+
const b = {
|
|
1852
|
+
row: rowIndex.get(value.rowTo ?? value.row),
|
|
1853
|
+
col: colIndex.get(value.colTo ?? value.col)
|
|
1854
|
+
};
|
|
1855
|
+
if (a.row === void 0 || a.col === void 0 || b.row === void 0 || b.col === void 0) return null;
|
|
1856
|
+
return rectBetween({
|
|
1857
|
+
row: a.row,
|
|
1858
|
+
col: a.col
|
|
1859
|
+
}, {
|
|
1860
|
+
row: b.row,
|
|
1861
|
+
col: b.col
|
|
1862
|
+
});
|
|
1863
|
+
}, [
|
|
1864
|
+
value,
|
|
1865
|
+
rowIndex,
|
|
1866
|
+
colIndex
|
|
1867
|
+
]);
|
|
1868
|
+
const anchor = useMemo(() => {
|
|
1869
|
+
if (!value) return null;
|
|
1870
|
+
const row = rowIndex.get(value.row);
|
|
1871
|
+
const col = colIndex.get(value.col);
|
|
1872
|
+
return row === void 0 || col === void 0 ? null : {
|
|
1873
|
+
row,
|
|
1874
|
+
col
|
|
1875
|
+
};
|
|
1876
|
+
}, [
|
|
1877
|
+
value,
|
|
1878
|
+
rowIndex,
|
|
1879
|
+
colIndex
|
|
1880
|
+
]);
|
|
1881
|
+
const clampPos = (pos) => ({
|
|
1882
|
+
row: Math.min(Math.max(0, pos.row), Math.max(0, nRows - 1)),
|
|
1883
|
+
col: Math.min(Math.max(0, pos.col), Math.max(0, nCols - 1))
|
|
1884
|
+
});
|
|
1885
|
+
const tabStop = clampPos(focus ?? anchor ?? {
|
|
1886
|
+
row: 0,
|
|
1887
|
+
col: 0
|
|
1888
|
+
});
|
|
1889
|
+
const commit = (next) => {
|
|
1890
|
+
if (controlled === void 0) setInner(next);
|
|
1891
|
+
onValueChange?.(next);
|
|
1892
|
+
};
|
|
1893
|
+
const selectRange = (from, to) => {
|
|
1894
|
+
const a = rows[from.row];
|
|
1895
|
+
const b = rows[to.row];
|
|
1896
|
+
const c = columns[from.col];
|
|
1897
|
+
const d = columns[to.col];
|
|
1898
|
+
if (!a || !b || !c || !d) return;
|
|
1899
|
+
const one = from.row === to.row && from.col === to.col;
|
|
1900
|
+
commit(one || !multiple ? {
|
|
1901
|
+
row: b.id,
|
|
1902
|
+
col: d.id
|
|
1903
|
+
} : {
|
|
1904
|
+
row: a.id,
|
|
1905
|
+
col: c.id,
|
|
1906
|
+
rowTo: b.id,
|
|
1907
|
+
colTo: d.id
|
|
1908
|
+
});
|
|
1909
|
+
};
|
|
1910
|
+
const bodyViewport = () => {
|
|
1911
|
+
const el = scrollerRef.current;
|
|
1912
|
+
return {
|
|
1913
|
+
height: (el?.clientHeight ?? INITIAL_VIEWPORT.height) - headerHeight,
|
|
1914
|
+
width: (el?.clientWidth ?? INITIAL_VIEWPORT.width) - rowHeaderWidth
|
|
1915
|
+
};
|
|
1916
|
+
};
|
|
1917
|
+
/** Moves the cursor to `pos`: scrolls it into view and gives it the DOM focus once rendered. */
|
|
1918
|
+
const moveTo = (pos) => {
|
|
1919
|
+
const el = scrollerRef.current;
|
|
1920
|
+
if (el) {
|
|
1921
|
+
const viewport = bodyViewport();
|
|
1922
|
+
el.scrollTop = revealScroll(el.scrollTop, viewport.height, pos.row, rowHeight);
|
|
1923
|
+
el.scrollLeft = revealScroll(el.scrollLeft, viewport.width, pos.col, colWidth);
|
|
1924
|
+
}
|
|
1925
|
+
focusPending.current = true;
|
|
1926
|
+
setFocus(pos);
|
|
1927
|
+
};
|
|
1928
|
+
useEffect(() => {
|
|
1929
|
+
if (!focusPending.current) return;
|
|
1930
|
+
const el = scrollerRef.current?.querySelector(`[data-cell][data-r="${tabStop.row}"][data-c="${tabStop.col}"]`);
|
|
1931
|
+
if (!el) return;
|
|
1932
|
+
focusPending.current = false;
|
|
1933
|
+
el.focus({ preventScroll: true });
|
|
1934
|
+
});
|
|
1935
|
+
const onKeyDown = (event) => {
|
|
1936
|
+
const hit = locate(event.target);
|
|
1937
|
+
if (!hit || hit.kind !== "cell" || hit.element !== event.target || nRows === 0 || nCols === 0) return;
|
|
1938
|
+
const here = {
|
|
1939
|
+
row: hit.row,
|
|
1940
|
+
col: hit.col
|
|
1941
|
+
};
|
|
1942
|
+
const ctrl = event.ctrlKey || event.metaKey;
|
|
1943
|
+
if (event.altKey) return;
|
|
1944
|
+
if (event.key === " ") {
|
|
1945
|
+
event.preventDefault();
|
|
1946
|
+
if (event.shiftKey && multiple) selectRange({
|
|
1947
|
+
row: here.row,
|
|
1948
|
+
col: 0
|
|
1949
|
+
}, {
|
|
1950
|
+
row: here.row,
|
|
1951
|
+
col: nCols - 1
|
|
1952
|
+
});
|
|
1953
|
+
else if (ctrl && multiple) selectRange({
|
|
1954
|
+
row: 0,
|
|
1955
|
+
col: here.col
|
|
1956
|
+
}, {
|
|
1957
|
+
row: nRows - 1,
|
|
1958
|
+
col: here.col
|
|
1959
|
+
});
|
|
1960
|
+
else selectRange(here, here);
|
|
1961
|
+
return;
|
|
1962
|
+
}
|
|
1963
|
+
if (event.key === "Enter") {
|
|
1964
|
+
event.preventDefault();
|
|
1965
|
+
selectRange(here, here);
|
|
1966
|
+
onCellAction?.(rows[here.row].id, columns[here.col].id);
|
|
1967
|
+
return;
|
|
1968
|
+
}
|
|
1969
|
+
if (ctrl && event.key.toLowerCase() === "a") {
|
|
1970
|
+
if (!multiple) return;
|
|
1971
|
+
event.preventDefault();
|
|
1972
|
+
selectRange({
|
|
1973
|
+
row: 0,
|
|
1974
|
+
col: 0
|
|
1975
|
+
}, {
|
|
1976
|
+
row: nRows - 1,
|
|
1977
|
+
col: nCols - 1
|
|
1978
|
+
});
|
|
1979
|
+
return;
|
|
1980
|
+
}
|
|
1981
|
+
const page = Math.max(1, Math.floor(bodyViewport().height / rowHeight) - 1);
|
|
1982
|
+
const next = moveFocus(here, event.key, {
|
|
1983
|
+
rows: nRows,
|
|
1984
|
+
cols: nCols
|
|
1985
|
+
}, page, ctrl);
|
|
1986
|
+
if (next === null) return;
|
|
1987
|
+
event.preventDefault();
|
|
1988
|
+
moveTo(next);
|
|
1989
|
+
if (event.shiftKey && multiple) selectRange(anchor ?? here, next);
|
|
1990
|
+
else if (selectionFollowsFocus) selectRange(next, next);
|
|
1991
|
+
};
|
|
1992
|
+
const onClick = (event) => {
|
|
1993
|
+
const hit = locate(event.target);
|
|
1994
|
+
if (!hit) return;
|
|
1995
|
+
if (hit.kind !== "cell" && event.target.closest("button,a,input,select,textarea,[role=menu]")) return;
|
|
1996
|
+
if (hit.kind === "cell") {
|
|
1997
|
+
setFocus({
|
|
1998
|
+
row: hit.row,
|
|
1999
|
+
col: hit.col
|
|
2000
|
+
});
|
|
2001
|
+
const here = {
|
|
2002
|
+
row: hit.row,
|
|
2003
|
+
col: hit.col
|
|
2004
|
+
};
|
|
2005
|
+
if (event.shiftKey && multiple && anchor) selectRange(anchor, here);
|
|
2006
|
+
else selectRange(here, here);
|
|
2007
|
+
} else if (multiple && hit.kind === "row") selectRange({
|
|
2008
|
+
row: hit.row,
|
|
2009
|
+
col: 0
|
|
2010
|
+
}, {
|
|
2011
|
+
row: hit.row,
|
|
2012
|
+
col: nCols - 1
|
|
2013
|
+
});
|
|
2014
|
+
else if (multiple && hit.kind === "col") selectRange({
|
|
2015
|
+
row: 0,
|
|
2016
|
+
col: hit.col
|
|
2017
|
+
}, {
|
|
2018
|
+
row: nRows - 1,
|
|
2019
|
+
col: hit.col
|
|
2020
|
+
});
|
|
2021
|
+
};
|
|
2022
|
+
const onDoubleClick = (event) => {
|
|
2023
|
+
const hit = locate(event.target);
|
|
2024
|
+
if (hit?.kind === "cell") onCellAction?.(rows[hit.row].id, columns[hit.col].id);
|
|
2025
|
+
};
|
|
2026
|
+
const withFocus = (window, at, count) => {
|
|
2027
|
+
const out = [];
|
|
2028
|
+
let placed = at < 0 || at >= count || at >= window[0] && at < window[1];
|
|
2029
|
+
for (let i = window[0]; i < window[1]; i++) {
|
|
2030
|
+
if (!placed && at < i) {
|
|
2031
|
+
out.push(at);
|
|
2032
|
+
placed = true;
|
|
2033
|
+
}
|
|
2034
|
+
out.push(i);
|
|
2035
|
+
}
|
|
2036
|
+
if (!placed) out.push(at);
|
|
2037
|
+
return out;
|
|
2038
|
+
};
|
|
2039
|
+
const clampWin = (w, count) => {
|
|
2040
|
+
const end = Math.min(w[1], count);
|
|
2041
|
+
return [Math.min(w[0], end), end];
|
|
2042
|
+
};
|
|
2043
|
+
const rowsShown = withFocus(clampWin(win.rows, nRows), tabStop.row, nRows);
|
|
2044
|
+
const colsShown = withFocus(clampWin(win.cols, nCols), tabStop.col, nCols);
|
|
2045
|
+
const totalWidth = rowHeaderWidth + nCols * colWidth;
|
|
2046
|
+
const totalHeight = headerHeight + nRows * rowHeight;
|
|
2047
|
+
const fullRow = (i) => range !== null && range.row0 <= i && i <= range.row1 && range.col0 === 0 && range.col1 === nCols - 1;
|
|
2048
|
+
const fullCol = (j) => range !== null && range.col0 <= j && j <= range.col1 && range.row0 === 0 && range.row1 === nRows - 1;
|
|
2049
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2050
|
+
ref: scrollerRef,
|
|
2051
|
+
role: "grid",
|
|
2052
|
+
"aria-label": ariaLabel,
|
|
2053
|
+
"aria-rowcount": nRows + 1,
|
|
2054
|
+
"aria-colcount": nCols + 1,
|
|
2055
|
+
"aria-multiselectable": multiple ? true : void 0,
|
|
2056
|
+
tabIndex: nRows === 0 || nCols === 0 ? 0 : void 0,
|
|
2057
|
+
onScroll: measure,
|
|
2058
|
+
onKeyDown,
|
|
2059
|
+
onClick,
|
|
2060
|
+
onDoubleClick,
|
|
2061
|
+
onFocus: (event) => {
|
|
2062
|
+
setHasFocus(true);
|
|
2063
|
+
const hit = locate(event.target);
|
|
2064
|
+
if (hit?.kind === "cell") setFocus({
|
|
2065
|
+
row: hit.row,
|
|
2066
|
+
col: hit.col
|
|
2067
|
+
});
|
|
2068
|
+
},
|
|
2069
|
+
onBlur: (event) => {
|
|
2070
|
+
if (!event.currentTarget.contains(event.relatedTarget)) setHasFocus(false);
|
|
2071
|
+
},
|
|
2072
|
+
style: {
|
|
2073
|
+
position: "relative",
|
|
2074
|
+
overflow: "auto",
|
|
2075
|
+
scrollPaddingTop: headerHeight,
|
|
2076
|
+
scrollPaddingLeft: rowHeaderWidth,
|
|
2077
|
+
...style
|
|
2078
|
+
},
|
|
2079
|
+
className: cn("rounded-control border border-line bg-surface text-fg select-none", className),
|
|
2080
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
2081
|
+
style: {
|
|
2082
|
+
position: "relative",
|
|
2083
|
+
width: totalWidth,
|
|
2084
|
+
height: totalHeight
|
|
2085
|
+
},
|
|
2086
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
2087
|
+
role: "row",
|
|
2088
|
+
"aria-rowindex": 1,
|
|
2089
|
+
style: {
|
|
2090
|
+
position: "sticky",
|
|
2091
|
+
top: 0,
|
|
2092
|
+
zIndex: 20,
|
|
2093
|
+
height: headerHeight,
|
|
2094
|
+
width: totalWidth
|
|
2095
|
+
},
|
|
2096
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
2097
|
+
role: "columnheader",
|
|
2098
|
+
"aria-colindex": 1,
|
|
2099
|
+
className: "flex items-center border-r border-b border-line bg-raised px-2 text-xs text-fg-muted",
|
|
2100
|
+
style: {
|
|
2101
|
+
position: "sticky",
|
|
2102
|
+
left: 0,
|
|
2103
|
+
zIndex: 30,
|
|
2104
|
+
width: rowHeaderWidth,
|
|
2105
|
+
height: headerHeight
|
|
2106
|
+
},
|
|
2107
|
+
children: corner ?? /* @__PURE__ */ jsx("span", {
|
|
2108
|
+
className: "sr-only",
|
|
2109
|
+
children: "Rows"
|
|
2110
|
+
})
|
|
2111
|
+
}), colsShown.map((j) => {
|
|
2112
|
+
const column = columns[j];
|
|
2113
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2114
|
+
role: "columnheader",
|
|
2115
|
+
"aria-colindex": j + 2,
|
|
2116
|
+
"aria-label": nameOf(column),
|
|
2117
|
+
"aria-selected": fullCol(j) ? true : void 0,
|
|
2118
|
+
"data-col-header": "",
|
|
2119
|
+
"data-c": j,
|
|
2120
|
+
"data-selected": fullCol(j) ? "" : void 0,
|
|
2121
|
+
className: cn("flex items-center justify-center overflow-hidden border-r border-b border-line px-1 text-xs", fullCol(j) ? "bg-signal/12 text-fg" : "bg-raised text-fg-muted"),
|
|
2122
|
+
style: {
|
|
2123
|
+
position: "absolute",
|
|
2124
|
+
top: 0,
|
|
2125
|
+
left: rowHeaderWidth + j * colWidth,
|
|
2126
|
+
width: colWidth,
|
|
2127
|
+
height: headerHeight
|
|
2128
|
+
},
|
|
2129
|
+
children: renderColumnHeader ? renderColumnHeader(column) : column.label
|
|
2130
|
+
}, column.id);
|
|
2131
|
+
})]
|
|
2132
|
+
}), rowsShown.map((i) => {
|
|
2133
|
+
const row = rows[i];
|
|
2134
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2135
|
+
role: "row",
|
|
2136
|
+
"aria-rowindex": i + 2,
|
|
2137
|
+
style: {
|
|
2138
|
+
position: "absolute",
|
|
2139
|
+
top: headerHeight + i * rowHeight,
|
|
2140
|
+
left: 0,
|
|
2141
|
+
height: rowHeight,
|
|
2142
|
+
width: totalWidth
|
|
2143
|
+
},
|
|
2144
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
2145
|
+
role: "rowheader",
|
|
2146
|
+
"aria-colindex": 1,
|
|
2147
|
+
"aria-label": nameOf(row),
|
|
2148
|
+
"aria-selected": fullRow(i) ? true : void 0,
|
|
2149
|
+
"data-row-header": "",
|
|
2150
|
+
"data-r": i,
|
|
2151
|
+
"data-selected": fullRow(i) ? "" : void 0,
|
|
2152
|
+
className: cn("flex items-center overflow-hidden border-r border-b border-line px-2 text-xs", fullRow(i) ? "bg-signal/12 text-fg" : "bg-raised text-fg-muted"),
|
|
2153
|
+
style: {
|
|
2154
|
+
position: "sticky",
|
|
2155
|
+
left: 0,
|
|
2156
|
+
zIndex: 10,
|
|
2157
|
+
width: rowHeaderWidth,
|
|
2158
|
+
height: rowHeight
|
|
2159
|
+
},
|
|
2160
|
+
children: renderRowHeader ? renderRowHeader(row) : row.label
|
|
2161
|
+
}), colsShown.map((j) => {
|
|
2162
|
+
const column = columns[j];
|
|
2163
|
+
const selected = inRect(range, i, j);
|
|
2164
|
+
const isStop = i === tabStop.row && j === tabStop.col;
|
|
2165
|
+
const focused = hasFocus && isStop;
|
|
2166
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2167
|
+
role: "gridcell",
|
|
2168
|
+
"aria-colindex": j + 2,
|
|
2169
|
+
"aria-selected": selected,
|
|
2170
|
+
"aria-label": cellLabel?.(row, column),
|
|
2171
|
+
tabIndex: isStop ? 0 : -1,
|
|
2172
|
+
"data-cell": "",
|
|
2173
|
+
"data-r": i,
|
|
2174
|
+
"data-c": j,
|
|
2175
|
+
"data-selected": selected ? "" : void 0,
|
|
2176
|
+
"data-focused": focused ? "" : void 0,
|
|
2177
|
+
className: cn("overflow-hidden border-r border-b border-line", selected ? "bg-signal/12" : "hover:bg-raised", focusRingInset),
|
|
2178
|
+
style: {
|
|
2179
|
+
position: "absolute",
|
|
2180
|
+
top: 0,
|
|
2181
|
+
left: rowHeaderWidth + j * colWidth,
|
|
2182
|
+
width: colWidth,
|
|
2183
|
+
height: rowHeight
|
|
2184
|
+
},
|
|
2185
|
+
children: renderCell(row, column, {
|
|
2186
|
+
focused,
|
|
2187
|
+
selected
|
|
2188
|
+
})
|
|
2189
|
+
}, column.id);
|
|
2190
|
+
})]
|
|
2191
|
+
}, row.id);
|
|
2192
|
+
})]
|
|
2193
|
+
})
|
|
2194
|
+
});
|
|
2195
|
+
}
|
|
2196
|
+
//#endregion
|
|
1648
2197
|
//#region src/components/stepperModel.ts
|
|
1649
2198
|
/**
|
|
1650
2199
|
* Each step's state, in order.
|
|
@@ -1743,6 +2292,6 @@ function StepMarker({ state, number }) {
|
|
|
1743
2292
|
});
|
|
1744
2293
|
}
|
|
1745
2294
|
//#endregion
|
|
1746
|
-
export { AppShell, DEFAULT_SPEEDS, FileDrop, NavRail, NavRailItem, PlaybackBar, SequenceNavigator, SplitPane, StatusBar, Stepper, Toaster, TreeView, acceptsFile, acceptsPath, advance, ancestorIds, clampIndex, clampSize, collectDroppedFiles, createPlayhead, createToastStore, defaultToastStore, formatSeconds, parentIds, resolveLimits, resolveSize, stepIndex, stepStates, toast, treeKeyAction, usePlaybackClock, usePlayhead, usePlayheadTimeline, visibleRows };
|
|
2295
|
+
export { AppShell, DEFAULT_SPEEDS, FileDrop, NavRail, NavRailItem, PlaybackBar, SequenceMatrix, SequenceNavigator, SplitPane, StatusBar, Stepper, Toaster, TreeView, acceptsFile, acceptsPath, advance, ancestorIds, clampIndex, clampSize, collectDroppedFiles, createPlayhead, createToastStore, defaultToastStore, formatSeconds, parentIds, resolveLimits, resolveSize, stepIndex, stepStates, toast, treeKeyAction, usePlaybackClock, usePlayhead, usePlayheadTimeline, visibleRows };
|
|
1747
2296
|
|
|
1748
2297
|
//# sourceMappingURL=index.js.map
|