@akhil-saxena/design-system 1.2.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/LICENSE +21 -0
- package/README.md +122 -0
- package/dist/Icon-XUp5t4PQ.d.ts +10 -0
- package/dist/chunk-FUXR6QZ3.js +108 -0
- package/dist/chunk-FUXR6QZ3.js.map +1 -0
- package/dist/chunk-TG25XACB.js +65 -0
- package/dist/chunk-TG25XACB.js.map +1 -0
- package/dist/hooks/index.d.ts +145 -0
- package/dist/hooks/index.js +177 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/icons/index.d.ts +39 -0
- package/dist/icons/index.js +3 -0
- package/dist/icons/index.js.map +1 -0
- package/dist/index.d.ts +2091 -0
- package/dist/index.js +9200 -0
- package/dist/index.js.map +1 -0
- package/dist/primitives.css +4775 -0
- package/dist/tokens.css +180 -0
- package/dist/utilities.css +200 -0
- package/package.json +104 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
export { useClickOutside, useComposedRefs, useFocusTrap, useMatchMedia, useReducedMotion } from '../chunk-FUXR6QZ3.js';
|
|
2
|
+
import { useEffect, useState, useCallback, useMemo, useRef } from 'react';
|
|
3
|
+
|
|
4
|
+
var isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform);
|
|
5
|
+
function parseCombo(combo) {
|
|
6
|
+
const parts = combo.toLowerCase().split("+").map((p) => p.trim());
|
|
7
|
+
const out = {
|
|
8
|
+
key: "",
|
|
9
|
+
mod: false,
|
|
10
|
+
ctrl: false,
|
|
11
|
+
shift: false,
|
|
12
|
+
alt: false
|
|
13
|
+
};
|
|
14
|
+
for (const p of parts) {
|
|
15
|
+
if (p === "mod") out.mod = true;
|
|
16
|
+
else if (p === "ctrl") out.ctrl = true;
|
|
17
|
+
else if (p === "shift") out.shift = true;
|
|
18
|
+
else if (p === "alt" || p === "opt") out.alt = true;
|
|
19
|
+
else out.key = p;
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
function matches(e, combo) {
|
|
24
|
+
if (e.key.toLowerCase() !== combo.key.toLowerCase()) return false;
|
|
25
|
+
const modPressed = isMac ? e.metaKey : e.ctrlKey;
|
|
26
|
+
if (combo.mod && !modPressed) return false;
|
|
27
|
+
if (combo.ctrl && !e.ctrlKey) return false;
|
|
28
|
+
if (combo.shift !== e.shiftKey) return false;
|
|
29
|
+
if (combo.alt !== e.altKey) return false;
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
function useKeyboardShortcut(combo, handler, options = {}) {
|
|
33
|
+
const { enabled = true, preventDefault = false, target } = options;
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!enabled) return;
|
|
36
|
+
const combos = (Array.isArray(combo) ? combo : [combo]).map(parseCombo);
|
|
37
|
+
const t = target ?? (typeof window !== "undefined" ? window : {});
|
|
38
|
+
function listener(ev) {
|
|
39
|
+
const e = ev;
|
|
40
|
+
if (combos.some((c) => matches(e, c))) {
|
|
41
|
+
if (preventDefault) e.preventDefault();
|
|
42
|
+
handler(e);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
t.addEventListener("keydown", listener);
|
|
46
|
+
return () => {
|
|
47
|
+
t.removeEventListener("keydown", listener);
|
|
48
|
+
};
|
|
49
|
+
}, [combo, handler, enabled, preventDefault, target]);
|
|
50
|
+
}
|
|
51
|
+
function useSortableTable(rows, options) {
|
|
52
|
+
const [sortCol, setSortCol] = useState(options?.defaultCol ?? null);
|
|
53
|
+
const [sortDir, setSortDir] = useState(options?.defaultDir ?? "asc");
|
|
54
|
+
const toggleSort = useCallback((col) => {
|
|
55
|
+
setSortCol((prev) => {
|
|
56
|
+
if (prev === col) {
|
|
57
|
+
setSortDir((d) => d === "asc" ? "desc" : "asc");
|
|
58
|
+
return prev;
|
|
59
|
+
}
|
|
60
|
+
setSortDir("asc");
|
|
61
|
+
return col;
|
|
62
|
+
});
|
|
63
|
+
}, []);
|
|
64
|
+
const customComparator = options?.comparator;
|
|
65
|
+
const sorted = useMemo(() => {
|
|
66
|
+
if (sortCol == null) return rows;
|
|
67
|
+
const cmp = customComparator ?? ((a, b, col) => {
|
|
68
|
+
const av = a[col];
|
|
69
|
+
const bv = b[col];
|
|
70
|
+
if (av == null && bv == null) return 0;
|
|
71
|
+
if (av == null) return -1;
|
|
72
|
+
if (bv == null) return 1;
|
|
73
|
+
if (av < bv) return -1;
|
|
74
|
+
if (av > bv) return 1;
|
|
75
|
+
return 0;
|
|
76
|
+
});
|
|
77
|
+
const dirMul = sortDir === "asc" ? 1 : -1;
|
|
78
|
+
return [...rows].sort((a, b) => cmp(a, b, sortCol) * dirMul);
|
|
79
|
+
}, [rows, sortCol, sortDir, customComparator]);
|
|
80
|
+
return { sorted, sortCol, sortDir, toggleSort };
|
|
81
|
+
}
|
|
82
|
+
function useTableSelection(ids, options) {
|
|
83
|
+
const mode = options?.mode ?? "multi";
|
|
84
|
+
const isControlled = options?.selectedIds !== void 0;
|
|
85
|
+
const [uncontrolled, setUncontrolled] = useState(options?.defaultSelected ?? []);
|
|
86
|
+
const selectedIds = isControlled ? options.selectedIds : uncontrolled;
|
|
87
|
+
const setSelected = useCallback(
|
|
88
|
+
(next) => {
|
|
89
|
+
if (!isControlled) setUncontrolled(next);
|
|
90
|
+
options?.onSelectionChange?.(next);
|
|
91
|
+
},
|
|
92
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
93
|
+
[isControlled, options?.onSelectionChange]
|
|
94
|
+
);
|
|
95
|
+
const isSelected = useCallback((id) => selectedIds.includes(id), [selectedIds]);
|
|
96
|
+
const toggle = useCallback(
|
|
97
|
+
(id) => {
|
|
98
|
+
if (mode === "single") {
|
|
99
|
+
setSelected(selectedIds.includes(id) ? [] : [id]);
|
|
100
|
+
} else {
|
|
101
|
+
setSelected(
|
|
102
|
+
selectedIds.includes(id) ? selectedIds.filter((x) => x !== id) : [...selectedIds, id]
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
[mode, selectedIds, setSelected]
|
|
107
|
+
);
|
|
108
|
+
const toggleAll = useCallback(() => {
|
|
109
|
+
if (mode === "single") return;
|
|
110
|
+
if (selectedIds.length === ids.length) {
|
|
111
|
+
setSelected([]);
|
|
112
|
+
} else {
|
|
113
|
+
setSelected([...ids]);
|
|
114
|
+
}
|
|
115
|
+
}, [mode, selectedIds, ids, setSelected]);
|
|
116
|
+
const clear = useCallback(() => setSelected([]), [setSelected]);
|
|
117
|
+
const isAllSelected = useMemo(
|
|
118
|
+
() => selectedIds.length === ids.length && ids.length > 0,
|
|
119
|
+
[selectedIds.length, ids.length]
|
|
120
|
+
);
|
|
121
|
+
const isIndeterminate = useMemo(
|
|
122
|
+
() => selectedIds.length > 0 && !isAllSelected,
|
|
123
|
+
[selectedIds.length, isAllSelected]
|
|
124
|
+
);
|
|
125
|
+
return { selectedIds, isAllSelected, isIndeterminate, isSelected, toggle, toggleAll, clear };
|
|
126
|
+
}
|
|
127
|
+
function useResizableColumns(initialWidths, options) {
|
|
128
|
+
const minWidth = options?.minWidth ?? 60;
|
|
129
|
+
const [widths, setWidths] = useState(initialWidths);
|
|
130
|
+
const widthsRef = useRef(widths);
|
|
131
|
+
widthsRef.current = widths;
|
|
132
|
+
const onWidthsChangeRef = useRef(options?.onWidthsChange);
|
|
133
|
+
onWidthsChangeRef.current = options?.onWidthsChange;
|
|
134
|
+
const setWidth = useCallback(
|
|
135
|
+
(col, w) => {
|
|
136
|
+
const clamped = Math.max(minWidth, w);
|
|
137
|
+
setWidths((prev) => {
|
|
138
|
+
const next = { ...prev, [col]: clamped };
|
|
139
|
+
widthsRef.current = next;
|
|
140
|
+
return next;
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
[minWidth]
|
|
144
|
+
);
|
|
145
|
+
const startResize = useCallback(
|
|
146
|
+
(col, e) => {
|
|
147
|
+
const startX = e.clientX;
|
|
148
|
+
const startW = widthsRef.current[col] ?? 0;
|
|
149
|
+
try {
|
|
150
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
151
|
+
} catch {
|
|
152
|
+
}
|
|
153
|
+
const onMove = (ev) => {
|
|
154
|
+
const delta = ev.clientX - startX;
|
|
155
|
+
const next = Math.max(minWidth, startW + delta);
|
|
156
|
+
setWidths((prev) => {
|
|
157
|
+
const updated = { ...prev, [col]: next };
|
|
158
|
+
widthsRef.current = updated;
|
|
159
|
+
return updated;
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
const onUp = () => {
|
|
163
|
+
document.removeEventListener("pointermove", onMove);
|
|
164
|
+
document.removeEventListener("pointerup", onUp);
|
|
165
|
+
onWidthsChangeRef.current?.({ ...widthsRef.current });
|
|
166
|
+
};
|
|
167
|
+
document.addEventListener("pointermove", onMove);
|
|
168
|
+
document.addEventListener("pointerup", onUp);
|
|
169
|
+
},
|
|
170
|
+
[minWidth]
|
|
171
|
+
);
|
|
172
|
+
return { widths, setWidth, startResize };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export { useKeyboardShortcut, useResizableColumns, useSortableTable, useTableSelection };
|
|
176
|
+
//# sourceMappingURL=index.js.map
|
|
177
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useKeyboardShortcut.ts","../../src/hooks/useSortableTable.ts","../../src/hooks/useTableSelection.ts","../../src/hooks/useResizableColumns.ts"],"names":["useState","useCallback","useMemo"],"mappings":";;;AAQA,IAAM,QAAQ,OAAO,SAAA,KAAc,eAAe,iBAAA,CAAkB,IAAA,CAAK,UAAU,QAAQ,CAAA;AAU3F,SAAS,WAAW,KAAA,EAA4B;AAC/C,EAAA,MAAM,KAAA,GAAQ,KAAA,CACZ,WAAA,EAAY,CACZ,KAAA,CAAM,GAAG,CAAA,CACT,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,IAAA,EAAM,CAAA;AACrB,EAAA,MAAM,GAAA,GAAmB;A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,MAAM;AAClB,QAAA,QAAA,CAAS,mBAAA,CAAoB,eAAe,MAAM,CAAA;AAClD,QAAA,QAAA,CAAS,mBAAA,CAAoB,aAAa,IAAI,CAAA;AAC9C,QAAA,iBAAA,CAAkB,OAAA,GAAU,EAAE,GAAG,SAAA,CAAU,SAAS,CAAA;AAAA,MACrD,CAAA;AAEA,MAAA,QAAA,CAAS,gBAAA,CAAiB,eAAe,MAAM,CAAA;AAC/C,MAAA,QAAA,CAAS,gBAAA,CAAiB,aAAa,IAAI,CAAA;AAAA,IAC5C,CAAA;AAAA,IACA,CAAC,QAAQ;AAAA,GACV;AAEA,EAAA,OAAO,EAAE,MAAA,EAAQ,QAAA,EAAU,WAAA,EAAY;AACxC","file":"index.js","sourcesContent":["import { useEffect } from \"react\";\n\ninterface ShortcutOptions {\n\tenabled?: boolean;\n\tpreventDefault?: boolean;\n\ttarget?: HTMLElement | Window;\n}\n\nconst isMac = typeof navigator !== \"undefined\" && /Mac|iPhone|iPad/.test(navigator.platform);\n\ninterface ParsedCombo {\n\tkey: string;\n\tmod: boolean;\n\tctrl: boolean;\n\tshift: boolean;\n\talt: boolean;\n}\n\nfunction parseCombo(combo: string): ParsedCombo {\n\tconst parts = combo\n\t\t.toLowerCase()\n\t\t.split(\"+\")\n\t\t.map((p) => p.trim());\n\tconst out: ParsedCombo = {\n\t\tkey: \"\",\n\t\tmod: false,\n\t\tctrl: false,\n\t\tshift: false,\n\t\talt: false,\n\t};\n\tfor (const p of parts) {\n\t\tif (p === \"mod\") out.mod = true;\n\t\telse if (p === \"ctrl\") out.ctrl = true;\n\t\telse if (p === \"shift\") out.shift = true;\n\t\telse if (p === \"alt\" || p === \"opt\") out.alt = true;\n\t\telse out.key = p;\n\t}\n\treturn out;\n}\n\nfunction matches(e: KeyboardEvent, combo: ParsedCombo): boolean {\n\tif (e.key.toLowerCase() !== combo.key.toLowerCase()) return false;\n\tconst modPressed = isMac ? e.metaKey : e.ctrlKey;\n\tif (combo.mod && !modPressed) return false;\n\tif (combo.ctrl && !e.ctrlKey) return false;\n\tif (combo.shift !== e.shiftKey) return false;\n\tif (combo.alt !== e.altKey) return false;\n\treturn true;\n}\n\n/**\n * Bind a keyboard shortcut. Use \"mod+k\" for Cmd-on-Mac, Ctrl-on-Win/Linux.\n * Used by CommandPalette (Phase 17 - ⌘K), Modal Esc-to-close (Phase 14).\n */\nexport function useKeyboardShortcut(\n\tcombo: string | string[],\n\thandler: (e: KeyboardEvent) => void,\n\toptions: ShortcutOptions = {},\n): void {\n\tconst { enabled = true, preventDefault = false, target } = options;\n\tuseEffect(() => {\n\t\tif (!enabled) return;\n\t\tconst combos = (Array.isArray(combo) ? combo : [combo]).map(parseCombo);\n\t\tconst t: EventTarget = target ?? (typeof window !== \"undefined\" ? window : ({} as EventTarget));\n\t\tfunction listener(ev: Event) {\n\t\t\tconst e = ev as KeyboardEvent;\n\t\t\tif (combos.some((c) => matches(e, c))) {\n\t\t\t\tif (preventDefault) e.preventDefault();\n\t\t\t\thandler(e);\n\t\t\t}\n\t\t}\n\t\tt.addEventListener(\"keydown\", listener);\n\t\treturn () => {\n\t\t\tt.removeEventListener(\"keydown\", listener);\n\t\t};\n\t}, [combo, handler, enabled, preventDefault, target]);\n}\n","import { useCallback, useMemo, useState } from \"react\";\n\nexport interface SortState<T> {\n\tcol: keyof T | null;\n\tdir: \"asc\" | \"desc\";\n}\n\n/**\n * Sortable table state + derived sorted rows.\n * Used by Table primitive (DS-61, D-17-07) header click handlers.\n * Stable sort via Array.prototype.sort (ES2019 guarantee).\n *\n * Usage:\n * const { sorted, sortCol, sortDir, toggleSort } = useSortableTable(rows, { defaultCol: \"name\" });\n * <Table.HeaderCell sortable sortDir={sortCol === \"name\" ? sortDir : null} onToggleSort={() => toggleSort(\"name\")}>\n * Name\n * </Table.HeaderCell>\n *\n * @param rows - The source data array (reference-stable recommended for memo perf).\n * @param options.defaultCol - Initial sort column (default: null = unsorted).\n * @param options.defaultDir - Initial sort direction (default: \"asc\").\n * @param options.comparator - Custom compare fn `(a, b, col) => number`.\n */\nexport function useSortableTable<T>(\n\trows: T[],\n\toptions?: {\n\t\tdefaultCol?: keyof T;\n\t\tdefaultDir?: \"asc\" | \"desc\";\n\t\tcomparator?: (a: T, b: T, col: keyof T) => number;\n\t},\n): {\n\tsorted: T[];\n\tsortCol: keyof T | null;\n\tsortDir: \"asc\" | \"desc\";\n\ttoggleSort: (col: keyof T) => void;\n} {\n\tconst [sortCol, setSortCol] = useState<keyof T | null>(options?.defaultCol ?? null);\n\tconst [sortDir, setSortDir] = useState<\"asc\" | \"desc\">(options?.defaultDir ?? \"asc\");\n\n\tconst toggleSort = useCallback((col: keyof T) => {\n\t\tsetSortCol((prev) => {\n\t\t\tif (prev === col) {\n\t\t\t\tsetSortDir((d) => (d === \"asc\" ? \"desc\" : \"asc\"));\n\t\t\t\treturn prev;\n\t\t\t}\n\t\t\tsetSortDir(\"asc\");\n\t\t\treturn col;\n\t\t});\n\t}, []);\n\n\tconst customComparator = options?.comparator;\n\n\tconst sorted = useMemo(() => {\n\t\tif (sortCol == null) return rows;\n\t\tconst cmp =\n\t\t\tcustomComparator ??\n\t\t\t((a: T, b: T, col: keyof T) => {\n\t\t\t\tconst av = a[col];\n\t\t\t\tconst bv = b[col];\n\t\t\t\tif (av == null && bv == null) return 0;\n\t\t\t\tif (av == null) return -1;\n\t\t\t\tif (bv == null) return 1;\n\t\t\t\tif (av < bv) return -1;\n\t\t\t\tif (av > bv) return 1;\n\t\t\t\treturn 0;\n\t\t\t});\n\t\tconst dirMul = sortDir === \"asc\" ? 1 : -1;\n\t\treturn [...rows].sort((a, b) => cmp(a, b, sortCol) * dirMul);\n\t}, [rows, sortCol, sortDir, customComparator]);\n\n\treturn { sorted, sortCol, sortDir, toggleSort };\n}\n","import { useCallback, useMemo, useState } from \"react\";\n\nexport type SelectionMode = \"single\" | \"multi\";\n\n/**\n * Selection state for Table.SelectAllCell + Table.SelectCell (DS-61, D-17-09).\n * Modes: \"single\" (at most 1 selected) | \"multi\" (default).\n * Controlled via selectedIds + onSelectionChange; uncontrolled via defaultSelected.\n *\n * @example\n * const { selectedIds, isAllSelected, isIndeterminate, toggle, toggleAll, clear } =\n * useTableSelection(rowIds, { mode: \"multi\", defaultSelected: [] });\n */\nexport function useTableSelection<Id extends string | number>(\n\tids: Id[],\n\toptions?: {\n\t\tmode?: SelectionMode;\n\t\tdefaultSelected?: Id[];\n\t\t/** Controlled selected ids - takes priority over internal state. */\n\t\tselectedIds?: Id[];\n\t\tonSelectionChange?: (ids: Id[]) => void;\n\t},\n): {\n\tselectedIds: Id[];\n\tisAllSelected: boolean;\n\tisIndeterminate: boolean;\n\tisSelected: (id: Id) => boolean;\n\ttoggle: (id: Id) => void;\n\ttoggleAll: () => void;\n\tclear: () => void;\n} {\n\tconst mode = options?.mode ?? \"multi\";\n\tconst isControlled = options?.selectedIds !== undefined;\n\tconst [uncontrolled, setUncontrolled] = useState<Id[]>(options?.defaultSelected ?? []);\n\tconst selectedIds = isControlled ? (options!.selectedIds as Id[]) : uncontrolled;\n\n\tconst setSelected = useCallback(\n\t\t(next: Id[]) => {\n\t\t\tif (!isControlled) setUncontrolled(next);\n\t\t\toptions?.onSelectionChange?.(next);\n\t\t},\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t[isControlled, options?.onSelectionChange],\n\t);\n\n\tconst isSelected = useCallback((id: Id) => selectedIds.includes(id), [selectedIds]);\n\n\tconst toggle = useCallback(\n\t\t(id: Id) => {\n\t\t\tif (mode === \"single\") {\n\t\t\t\tsetSelected(selectedIds.includes(id) ? [] : [id]);\n\t\t\t} else {\n\t\t\t\tsetSelected(\n\t\t\t\t\tselectedIds.includes(id) ? selectedIds.filter((x) => x !== id) : [...selectedIds, id],\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[mode, selectedIds, setSelected],\n\t);\n\n\tconst toggleAll = useCallback(() => {\n\t\tif (mode === \"single\") return; // no-op in single mode\n\t\tif (selectedIds.length === ids.length) {\n\t\t\tsetSelected([]);\n\t\t} else {\n\t\t\tsetSelected([...ids]);\n\t\t}\n\t}, [mode, selectedIds, ids, setSelected]);\n\n\tconst clear = useCallback(() => setSelected([]), [setSelected]);\n\n\tconst isAllSelected = useMemo(\n\t\t() => selectedIds.length === ids.length && ids.length > 0,\n\t\t[selectedIds.length, ids.length],\n\t);\n\n\tconst isIndeterminate = useMemo(\n\t\t() => selectedIds.length > 0 && !isAllSelected,\n\t\t[selectedIds.length, isAllSelected],\n\t);\n\n\treturn { selectedIds, isAllSelected, isIndeterminate, isSelected, toggle, toggleAll, clear };\n}\n","import { useCallback, useRef, useState } from \"react\";\nimport type React from \"react\";\n\n/**\n * Column-resize state + Pointer Events drag handle (DS-61, D-17-10).\n *\n * Attach `startResize(col, event)` to a drag handle element's onPointerDown.\n * Pointer is captured via setPointerCapture for reliable tracking on fast drags.\n * onWidthsChange fires on pointerup with the final widths snapshot.\n * Consumer owns persistence (e.g. localStorage) - this hook only emits the event.\n *\n * @example\n * const { widths, startResize } = useResizableColumns({ name: 120, role: 100 });\n * <Table.HeaderCell width={widths.name}>\n * Name\n * <span onPointerDown={(e) => startResize(\"name\", e)} />\n * </Table.HeaderCell>\n */\nexport function useResizableColumns(\n\tinitialWidths: Record<string, number>,\n\toptions?: {\n\t\t/** Minimum column width in px. Default: 60. */\n\t\tminWidth?: number;\n\t\t/** Called on pointerup with the final widths record. */\n\t\tonWidthsChange?: (widths: Record<string, number>) => void;\n\t},\n): {\n\twidths: Record<string, number>;\n\tsetWidth: (col: string, w: number) => void;\n\tstartResize: (col: string, e: React.PointerEvent) => void;\n} {\n\tconst minWidth = options?.minWidth ?? 60;\n\tconst [widths, setWidths] = useState<Record<string, number>>(initialWidths);\n\n\t// Ref mirrors widths state so closure-captured handlers always see fresh value.\n\tconst widthsRef = useRef(widths);\n\twidthsRef.current = widths;\n\n\tconst onWidthsChangeRef = useRef(options?.onWidthsChange);\n\tonWidthsChangeRef.current = options?.onWidthsChange;\n\n\tconst setWidth = useCallback(\n\t\t(col: string, w: number) => {\n\t\t\tconst clamped = Math.max(minWidth, w);\n\t\t\tsetWidths((prev) => {\n\t\t\t\tconst next = { ...prev, [col]: clamped };\n\t\t\t\twidthsRef.current = next;\n\t\t\t\treturn next;\n\t\t\t});\n\t\t},\n\t\t[minWidth],\n\t);\n\n\tconst startResize = useCallback(\n\t\t(col: string, e: React.PointerEvent) => {\n\t\t\tconst startX = e.clientX;\n\t\t\tconst startW = widthsRef.current[col] ?? 0;\n\n\t\t\t// Capture pointer so we track movement even if cursor leaves the element.\n\t\t\ttry {\n\t\t\t\t(e.currentTarget as HTMLElement).setPointerCapture?.(e.pointerId);\n\t\t\t} catch {\n\t\t\t\t// jsdom and some older browsers may throw; safe to ignore.\n\t\t\t}\n\n\t\t\tconst onMove = (ev: PointerEvent) => {\n\t\t\t\tconst delta = ev.clientX - startX;\n\t\t\t\tconst next = Math.max(minWidth, startW + delta);\n\t\t\t\tsetWidths((prev) => {\n\t\t\t\t\tconst updated = { ...prev, [col]: next };\n\t\t\t\t\twidthsRef.current = updated;\n\t\t\t\t\treturn updated;\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst onUp = () => {\n\t\t\t\tdocument.removeEventListener(\"pointermove\", onMove);\n\t\t\t\tdocument.removeEventListener(\"pointerup\", onUp);\n\t\t\t\tonWidthsChangeRef.current?.({ ...widthsRef.current });\n\t\t\t};\n\n\t\t\tdocument.addEventListener(\"pointermove\", onMove);\n\t\t\tdocument.addEventListener(\"pointerup\", onUp);\n\t\t},\n\t\t[minWidth],\n\t);\n\n\treturn { widths, setWidth, startResize };\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { a as IconProps } from '../Icon-XUp5t4PQ.js';
|
|
3
|
+
import 'lucide-react';
|
|
4
|
+
|
|
5
|
+
declare const AlertTriangle: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
6
|
+
declare const Check: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
7
|
+
declare const CheckCircle2: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
8
|
+
declare const ChevronDown: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
9
|
+
declare const ChevronLeft: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
10
|
+
declare const ChevronRight: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
11
|
+
declare const Clock: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
12
|
+
declare const Copy: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
13
|
+
declare const Info: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
14
|
+
declare const Link: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
15
|
+
declare const Minus: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
16
|
+
declare const Plus: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
17
|
+
declare const Search: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
18
|
+
declare const Star: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
19
|
+
declare const Trash: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
20
|
+
declare const Trash2: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
21
|
+
declare const X: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
22
|
+
declare const XCircle: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
23
|
+
declare const Bold: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
24
|
+
declare const ChevronUp: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
25
|
+
declare const Code: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
26
|
+
declare const Heading2: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
27
|
+
declare const Heading3: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
28
|
+
declare const Italic: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
29
|
+
declare const Link2: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
30
|
+
declare const List: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
31
|
+
declare const ListOrdered: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
32
|
+
declare const Moon: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
33
|
+
declare const MoreHorizontal: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
34
|
+
declare const Sun: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
35
|
+
declare const Quote: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
36
|
+
declare const Strikethrough: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
37
|
+
declare const Underline: react.ForwardRefExoticComponent<Omit<IconProps, "icon"> & react.RefAttributes<SVGSVGElement>>;
|
|
38
|
+
|
|
39
|
+
export { AlertTriangle, Bold, Check, CheckCircle2, ChevronDown, ChevronLeft, ChevronRight, ChevronUp, Clock, Code, Copy, Heading2, Heading3, Info, Italic, Link, Link2, List, ListOrdered, Minus, Moon, MoreHorizontal, Plus, Quote, Search, Star, Strikethrough, Sun, Trash, Trash2, Underline, X, XCircle };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { AlertTriangle, Bold, Check, CheckCircle2, ChevronDown, ChevronLeft, ChevronRight, ChevronUp, Clock, Code, Copy, Heading2, Heading3, Info, Italic, Link, Link2, List, ListOrdered, Minus, Moon, MoreHorizontal, Plus, Quote, Search, Star, Strikethrough, Sun, Trash, Trash2, Underline, X, XCircle } from '../chunk-TG25XACB.js';
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|