@mantine/hooks 9.0.0-alpha.6 → 9.0.0-alpha.7
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/cjs/use-local-storage/use-local-storage.cjs.map +1 -1
- package/cjs/use-session-storage/use-session-storage.cjs.map +1 -1
- package/esm/use-focus-trap/use-focus-trap.mjs +2 -0
- package/esm/use-focus-trap/use-focus-trap.mjs.map +1 -1
- package/esm/use-local-storage/use-local-storage.mjs.map +1 -1
- package/esm/use-session-storage/use-session-storage.mjs.map +1 -1
- package/lib/use-local-storage/use-local-storage.d.ts +13 -3
- package/lib/use-session-storage/use-session-storage.d.ts +13 -3
- package/package.json +1 -1
- package/cjs/use-drag/use-drag.cjs +0 -266
- package/cjs/use-drag/use-drag.cjs.map +0 -1
- package/cjs/use-mask/use-mask.cjs +0 -457
- package/cjs/use-mask/use-mask.cjs.map +0 -1
- package/cjs/use-roving-index/use-roving-index.cjs +0 -200
- package/cjs/use-roving-index/use-roving-index.cjs.map +0 -1
- package/cjs/use-splitter/use-splitter.cjs +0 -433
- package/cjs/use-splitter/use-splitter.cjs.map +0 -1
- package/esm/use-drag/use-drag.mjs +0 -266
- package/esm/use-drag/use-drag.mjs.map +0 -1
- package/esm/use-mask/use-mask.mjs +0 -453
- package/esm/use-mask/use-mask.mjs.map +0 -1
- package/esm/use-roving-index/use-roving-index.mjs +0 -200
- package/esm/use-roving-index/use-roving-index.mjs.map +0 -1
- package/esm/use-splitter/use-splitter.mjs +0 -433
- package/esm/use-splitter/use-splitter.mjs.map +0 -1
- package/lib/use-drag/use-drag.d.ts +0 -60
- package/lib/use-mask/use-mask.d.ts +0 -60
- package/lib/use-roving-index/use-roving-index.d.ts +0 -49
- package/lib/use-splitter/use-splitter.d.ts +0 -94
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useUncontrolled } from "../use-uncontrolled/use-uncontrolled.mjs";
|
|
3
|
-
import { useCallback, useEffect, useRef } from "react";
|
|
4
|
-
//#region packages/@mantine/hooks/src/use-roving-index/use-roving-index.ts
|
|
5
|
-
function findNextEnabled(current, total, isItemDisabled, loop) {
|
|
6
|
-
for (let i = current + 1; i < total; i += 1) if (!isItemDisabled(i)) return i;
|
|
7
|
-
if (loop) {
|
|
8
|
-
for (let i = 0; i < current; i += 1) if (!isItemDisabled(i)) return i;
|
|
9
|
-
}
|
|
10
|
-
return current;
|
|
11
|
-
}
|
|
12
|
-
function findPreviousEnabled(current, total, isItemDisabled, loop) {
|
|
13
|
-
for (let i = current - 1; i >= 0; i -= 1) if (!isItemDisabled(i)) return i;
|
|
14
|
-
if (loop) {
|
|
15
|
-
for (let i = total - 1; i > current; i -= 1) if (!isItemDisabled(i)) return i;
|
|
16
|
-
}
|
|
17
|
-
return current;
|
|
18
|
-
}
|
|
19
|
-
function findFirstEnabled(total, isItemDisabled) {
|
|
20
|
-
for (let i = 0; i < total; i += 1) if (!isItemDisabled(i)) return i;
|
|
21
|
-
return 0;
|
|
22
|
-
}
|
|
23
|
-
function findLastEnabled(total, isItemDisabled) {
|
|
24
|
-
for (let i = total - 1; i >= 0; i -= 1) if (!isItemDisabled(i)) return i;
|
|
25
|
-
return 0;
|
|
26
|
-
}
|
|
27
|
-
const defaultIsItemDisabled = () => false;
|
|
28
|
-
function useRovingIndex(input) {
|
|
29
|
-
const { total, orientation = "horizontal", loop = true, dir = "ltr", activateOnFocus = false, columns, focusedIndex, initialIndex, onFocusChange, isItemDisabled = defaultIsItemDisabled } = input;
|
|
30
|
-
const itemRefs = useRef(/* @__PURE__ */ new Map());
|
|
31
|
-
const isGrid = typeof columns === "number" && columns > 0;
|
|
32
|
-
const [activeIndex, setActiveIndex] = useUncontrolled({
|
|
33
|
-
value: focusedIndex,
|
|
34
|
-
defaultValue: initialIndex !== void 0 ? initialIndex : findFirstEnabled(total, isItemDisabled),
|
|
35
|
-
finalValue: 0,
|
|
36
|
-
onChange: onFocusChange
|
|
37
|
-
});
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (total === 0) return;
|
|
40
|
-
if (activeIndex >= total) setActiveIndex(findLastEnabled(total, isItemDisabled));
|
|
41
|
-
else if (isItemDisabled(activeIndex)) setActiveIndex(findFirstEnabled(total, isItemDisabled));
|
|
42
|
-
}, [
|
|
43
|
-
total,
|
|
44
|
-
activeIndex,
|
|
45
|
-
isItemDisabled
|
|
46
|
-
]);
|
|
47
|
-
const focusItem = useCallback((index) => {
|
|
48
|
-
setActiveIndex(index);
|
|
49
|
-
const element = itemRefs.current.get(index);
|
|
50
|
-
if (element) {
|
|
51
|
-
element.focus();
|
|
52
|
-
if (activateOnFocus) element.click();
|
|
53
|
-
}
|
|
54
|
-
}, [activateOnFocus, setActiveIndex]);
|
|
55
|
-
const handleGridKeyDown = useCallback((event, currentIndex) => {
|
|
56
|
-
const row = Math.floor(currentIndex / columns);
|
|
57
|
-
const col = currentIndex % columns;
|
|
58
|
-
const totalRows = Math.ceil(total / columns);
|
|
59
|
-
let nextIndex = null;
|
|
60
|
-
const isRtl = dir === "rtl";
|
|
61
|
-
switch (event.key) {
|
|
62
|
-
case "ArrowRight": {
|
|
63
|
-
const targetCol = isRtl ? col - 1 : col + 1;
|
|
64
|
-
if (targetCol >= 0 && targetCol < columns && row * columns + targetCol < total) {
|
|
65
|
-
const candidate = row * columns + targetCol;
|
|
66
|
-
if (!isItemDisabled(candidate)) nextIndex = candidate;
|
|
67
|
-
}
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
case "ArrowLeft": {
|
|
71
|
-
const targetCol = isRtl ? col + 1 : col - 1;
|
|
72
|
-
if (targetCol >= 0 && targetCol < columns && row * columns + targetCol < total) {
|
|
73
|
-
const candidate = row * columns + targetCol;
|
|
74
|
-
if (!isItemDisabled(candidate)) nextIndex = candidate;
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
case "ArrowDown":
|
|
79
|
-
for (let r = row + 1; r < totalRows; r += 1) {
|
|
80
|
-
const candidate = r * columns + col;
|
|
81
|
-
if (candidate < total && !isItemDisabled(candidate)) {
|
|
82
|
-
nextIndex = candidate;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
break;
|
|
87
|
-
case "ArrowUp":
|
|
88
|
-
for (let r = row - 1; r >= 0; r -= 1) {
|
|
89
|
-
const candidate = r * columns + col;
|
|
90
|
-
if (candidate < total && !isItemDisabled(candidate)) {
|
|
91
|
-
nextIndex = candidate;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
break;
|
|
96
|
-
case "Home":
|
|
97
|
-
if (event.ctrlKey) nextIndex = findFirstEnabled(total, isItemDisabled);
|
|
98
|
-
else {
|
|
99
|
-
const rowStart = row * columns;
|
|
100
|
-
for (let i = rowStart; i < rowStart + columns && i < total; i += 1) if (!isItemDisabled(i)) {
|
|
101
|
-
nextIndex = i;
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
break;
|
|
106
|
-
case "End":
|
|
107
|
-
if (event.ctrlKey) nextIndex = findLastEnabled(total, isItemDisabled);
|
|
108
|
-
else {
|
|
109
|
-
const rowStart = row * columns;
|
|
110
|
-
const rowEnd = Math.min(rowStart + columns, total) - 1;
|
|
111
|
-
for (let i = rowEnd; i >= rowStart; i -= 1) if (!isItemDisabled(i)) {
|
|
112
|
-
nextIndex = i;
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
if (nextIndex !== null && nextIndex !== currentIndex) {
|
|
119
|
-
event.preventDefault();
|
|
120
|
-
event.stopPropagation();
|
|
121
|
-
focusItem(nextIndex);
|
|
122
|
-
}
|
|
123
|
-
}, [
|
|
124
|
-
total,
|
|
125
|
-
columns,
|
|
126
|
-
dir,
|
|
127
|
-
isItemDisabled,
|
|
128
|
-
focusItem
|
|
129
|
-
]);
|
|
130
|
-
const handleListKeyDown = useCallback((event, currentIndex) => {
|
|
131
|
-
const isRtl = dir === "rtl";
|
|
132
|
-
let nextIndex = null;
|
|
133
|
-
switch (event.key) {
|
|
134
|
-
case "ArrowRight":
|
|
135
|
-
if (orientation === "horizontal" || orientation === "both") nextIndex = isRtl ? findPreviousEnabled(currentIndex, total, isItemDisabled, loop) : findNextEnabled(currentIndex, total, isItemDisabled, loop);
|
|
136
|
-
break;
|
|
137
|
-
case "ArrowLeft":
|
|
138
|
-
if (orientation === "horizontal" || orientation === "both") nextIndex = isRtl ? findNextEnabled(currentIndex, total, isItemDisabled, loop) : findPreviousEnabled(currentIndex, total, isItemDisabled, loop);
|
|
139
|
-
break;
|
|
140
|
-
case "ArrowDown":
|
|
141
|
-
if (orientation === "vertical" || orientation === "both") nextIndex = findNextEnabled(currentIndex, total, isItemDisabled, loop);
|
|
142
|
-
break;
|
|
143
|
-
case "ArrowUp":
|
|
144
|
-
if (orientation === "vertical" || orientation === "both") nextIndex = findPreviousEnabled(currentIndex, total, isItemDisabled, loop);
|
|
145
|
-
break;
|
|
146
|
-
case "Home":
|
|
147
|
-
nextIndex = findFirstEnabled(total, isItemDisabled);
|
|
148
|
-
break;
|
|
149
|
-
case "End":
|
|
150
|
-
nextIndex = findLastEnabled(total, isItemDisabled);
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
if (nextIndex !== null && nextIndex !== currentIndex) {
|
|
154
|
-
event.preventDefault();
|
|
155
|
-
event.stopPropagation();
|
|
156
|
-
focusItem(nextIndex);
|
|
157
|
-
}
|
|
158
|
-
}, [
|
|
159
|
-
total,
|
|
160
|
-
orientation,
|
|
161
|
-
loop,
|
|
162
|
-
dir,
|
|
163
|
-
isItemDisabled,
|
|
164
|
-
focusItem
|
|
165
|
-
]);
|
|
166
|
-
return {
|
|
167
|
-
getItemProps: useCallback((options) => {
|
|
168
|
-
const { index, onClick, onKeyDown } = options;
|
|
169
|
-
return {
|
|
170
|
-
tabIndex: index === activeIndex ? 0 : -1,
|
|
171
|
-
ref: (node) => {
|
|
172
|
-
if (node) itemRefs.current.set(index, node);
|
|
173
|
-
else itemRefs.current.delete(index);
|
|
174
|
-
},
|
|
175
|
-
onKeyDown: (event) => {
|
|
176
|
-
onKeyDown?.(event);
|
|
177
|
-
if (event.defaultPrevented) return;
|
|
178
|
-
if (isGrid) handleGridKeyDown(event, index);
|
|
179
|
-
else handleListKeyDown(event, index);
|
|
180
|
-
},
|
|
181
|
-
onClick: (event) => {
|
|
182
|
-
onClick?.(event);
|
|
183
|
-
setActiveIndex(index);
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
}, [
|
|
187
|
-
activeIndex,
|
|
188
|
-
isGrid,
|
|
189
|
-
handleGridKeyDown,
|
|
190
|
-
handleListKeyDown,
|
|
191
|
-
setActiveIndex
|
|
192
|
-
]),
|
|
193
|
-
focusedIndex: activeIndex,
|
|
194
|
-
setFocusedIndex: setActiveIndex
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
//#endregion
|
|
198
|
-
export { useRovingIndex };
|
|
199
|
-
|
|
200
|
-
//# sourceMappingURL=use-roving-index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-roving-index.mjs","names":[],"sources":["../../src/use-roving-index/use-roving-index.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport { useUncontrolled } from '../use-uncontrolled/use-uncontrolled';\n\nexport interface UseRovingIndexInput {\n /** Total number of items in the group */\n total: number;\n\n /** Which arrow keys navigate, `'horizontal'` by default */\n orientation?: 'horizontal' | 'vertical' | 'both';\n\n /** Whether navigation wraps at boundaries, `true` by default */\n loop?: boolean;\n\n /** Text direction, `'ltr'` by default */\n dir?: 'rtl' | 'ltr';\n\n /** Whether to click element when it receives focus via keyboard, `false` by default */\n activateOnFocus?: boolean;\n\n /** Number of columns for grid (2D) navigation. When set, enables grid mode */\n columns?: number;\n\n /** Controlled focused index */\n focusedIndex?: number;\n\n /** Initial focused index for uncontrolled mode, first non-disabled item by default */\n initialIndex?: number;\n\n /** Called when focused index changes */\n onFocusChange?: (index: number) => void;\n\n /** Function to check if item at given index is disabled, `() => false` by default */\n isItemDisabled?: (index: number) => boolean;\n}\n\nexport interface UseRovingIndexGetItemPropsInput {\n /** Index of the item in the group */\n index: number;\n\n /** Called when item is clicked */\n onClick?: React.MouseEventHandler;\n\n /** Called when keydown event fires on item */\n onKeyDown?: React.KeyboardEventHandler;\n}\n\nexport interface UseRovingIndexReturnValue {\n /** Get props to spread on each navigable item */\n getItemProps: (options: UseRovingIndexGetItemPropsInput) => {\n tabIndex: 0 | -1;\n onKeyDown: React.KeyboardEventHandler;\n onClick: React.MouseEventHandler;\n ref: React.RefCallback<HTMLElement>;\n };\n\n /** Currently focused index */\n focusedIndex: number;\n\n /** Programmatically set focused index */\n setFocusedIndex: (index: number) => void;\n}\n\nfunction findNextEnabled(\n current: number,\n total: number,\n isItemDisabled: (index: number) => boolean,\n loop: boolean\n): number {\n for (let i = current + 1; i < total; i += 1) {\n if (!isItemDisabled(i)) {\n return i;\n }\n }\n\n if (loop) {\n for (let i = 0; i < current; i += 1) {\n if (!isItemDisabled(i)) {\n return i;\n }\n }\n }\n\n return current;\n}\n\nfunction findPreviousEnabled(\n current: number,\n total: number,\n isItemDisabled: (index: number) => boolean,\n loop: boolean\n): number {\n for (let i = current - 1; i >= 0; i -= 1) {\n if (!isItemDisabled(i)) {\n return i;\n }\n }\n\n if (loop) {\n for (let i = total - 1; i > current; i -= 1) {\n if (!isItemDisabled(i)) {\n return i;\n }\n }\n }\n\n return current;\n}\n\nfunction findFirstEnabled(total: number, isItemDisabled: (index: number) => boolean): number {\n for (let i = 0; i < total; i += 1) {\n if (!isItemDisabled(i)) {\n return i;\n }\n }\n\n return 0;\n}\n\nfunction findLastEnabled(total: number, isItemDisabled: (index: number) => boolean): number {\n for (let i = total - 1; i >= 0; i -= 1) {\n if (!isItemDisabled(i)) {\n return i;\n }\n }\n\n return 0;\n}\n\nconst defaultIsItemDisabled = () => false;\n\nexport function useRovingIndex(input: UseRovingIndexInput): UseRovingIndexReturnValue {\n const {\n total,\n orientation = 'horizontal',\n loop = true,\n dir = 'ltr',\n activateOnFocus = false,\n columns,\n focusedIndex,\n initialIndex,\n onFocusChange,\n isItemDisabled = defaultIsItemDisabled,\n } = input;\n\n const itemRefs = useRef<Map<number, HTMLElement>>(new Map());\n const isGrid = typeof columns === 'number' && columns > 0;\n\n const resolvedInitialIndex =\n initialIndex !== undefined ? initialIndex : findFirstEnabled(total, isItemDisabled);\n\n const [activeIndex, setActiveIndex] = useUncontrolled({\n value: focusedIndex,\n defaultValue: resolvedInitialIndex,\n finalValue: 0,\n onChange: onFocusChange,\n });\n\n useEffect(() => {\n if (total === 0) {\n return;\n }\n\n if (activeIndex >= total) {\n setActiveIndex(findLastEnabled(total, isItemDisabled));\n } else if (isItemDisabled(activeIndex)) {\n setActiveIndex(findFirstEnabled(total, isItemDisabled));\n }\n }, [total, activeIndex, isItemDisabled]);\n\n const focusItem = useCallback(\n (index: number) => {\n setActiveIndex(index);\n const element = itemRefs.current.get(index);\n if (element) {\n element.focus();\n if (activateOnFocus) {\n element.click();\n }\n }\n },\n [activateOnFocus, setActiveIndex]\n );\n\n const handleGridKeyDown = useCallback(\n (event: React.KeyboardEvent, currentIndex: number) => {\n const row = Math.floor(currentIndex / columns!);\n const col = currentIndex % columns!;\n const totalRows = Math.ceil(total / columns!);\n let nextIndex: number | null = null;\n\n const isRtl = dir === 'rtl';\n\n switch (event.key) {\n case 'ArrowRight': {\n const targetCol = isRtl ? col - 1 : col + 1;\n if (targetCol >= 0 && targetCol < columns! && row * columns! + targetCol < total) {\n const candidate = row * columns! + targetCol;\n if (!isItemDisabled(candidate)) {\n nextIndex = candidate;\n }\n }\n break;\n }\n\n case 'ArrowLeft': {\n const targetCol = isRtl ? col + 1 : col - 1;\n if (targetCol >= 0 && targetCol < columns! && row * columns! + targetCol < total) {\n const candidate = row * columns! + targetCol;\n if (!isItemDisabled(candidate)) {\n nextIndex = candidate;\n }\n }\n break;\n }\n\n case 'ArrowDown': {\n for (let r = row + 1; r < totalRows; r += 1) {\n const candidate = r * columns! + col;\n if (candidate < total && !isItemDisabled(candidate)) {\n nextIndex = candidate;\n break;\n }\n }\n break;\n }\n\n case 'ArrowUp': {\n for (let r = row - 1; r >= 0; r -= 1) {\n const candidate = r * columns! + col;\n if (candidate < total && !isItemDisabled(candidate)) {\n nextIndex = candidate;\n break;\n }\n }\n break;\n }\n\n case 'Home': {\n if (event.ctrlKey) {\n nextIndex = findFirstEnabled(total, isItemDisabled);\n } else {\n const rowStart = row * columns!;\n for (let i = rowStart; i < rowStart + columns! && i < total; i += 1) {\n if (!isItemDisabled(i)) {\n nextIndex = i;\n break;\n }\n }\n }\n break;\n }\n\n case 'End': {\n if (event.ctrlKey) {\n nextIndex = findLastEnabled(total, isItemDisabled);\n } else {\n const rowStart = row * columns!;\n const rowEnd = Math.min(rowStart + columns!, total) - 1;\n for (let i = rowEnd; i >= rowStart; i -= 1) {\n if (!isItemDisabled(i)) {\n nextIndex = i;\n break;\n }\n }\n }\n break;\n }\n }\n\n if (nextIndex !== null && nextIndex !== currentIndex) {\n event.preventDefault();\n event.stopPropagation();\n focusItem(nextIndex);\n }\n },\n [total, columns, dir, isItemDisabled, focusItem]\n );\n\n const handleListKeyDown = useCallback(\n (event: React.KeyboardEvent, currentIndex: number) => {\n const isRtl = dir === 'rtl';\n let nextIndex: number | null = null;\n\n switch (event.key) {\n case 'ArrowRight': {\n if (orientation === 'horizontal' || orientation === 'both') {\n nextIndex = isRtl\n ? findPreviousEnabled(currentIndex, total, isItemDisabled, loop)\n : findNextEnabled(currentIndex, total, isItemDisabled, loop);\n }\n break;\n }\n\n case 'ArrowLeft': {\n if (orientation === 'horizontal' || orientation === 'both') {\n nextIndex = isRtl\n ? findNextEnabled(currentIndex, total, isItemDisabled, loop)\n : findPreviousEnabled(currentIndex, total, isItemDisabled, loop);\n }\n break;\n }\n\n case 'ArrowDown': {\n if (orientation === 'vertical' || orientation === 'both') {\n nextIndex = findNextEnabled(currentIndex, total, isItemDisabled, loop);\n }\n break;\n }\n\n case 'ArrowUp': {\n if (orientation === 'vertical' || orientation === 'both') {\n nextIndex = findPreviousEnabled(currentIndex, total, isItemDisabled, loop);\n }\n break;\n }\n\n case 'Home': {\n nextIndex = findFirstEnabled(total, isItemDisabled);\n break;\n }\n\n case 'End': {\n nextIndex = findLastEnabled(total, isItemDisabled);\n break;\n }\n }\n\n if (nextIndex !== null && nextIndex !== currentIndex) {\n event.preventDefault();\n event.stopPropagation();\n focusItem(nextIndex);\n }\n },\n [total, orientation, loop, dir, isItemDisabled, focusItem]\n );\n\n const getItemProps = useCallback(\n (options: UseRovingIndexGetItemPropsInput) => {\n const { index, onClick, onKeyDown } = options;\n\n return {\n tabIndex: (index === activeIndex ? 0 : -1) as 0 | -1,\n\n ref: (node: HTMLElement | null) => {\n if (node) {\n itemRefs.current.set(index, node);\n } else {\n itemRefs.current.delete(index);\n }\n },\n\n onKeyDown: (event: React.KeyboardEvent) => {\n onKeyDown?.(event);\n\n if (event.defaultPrevented) {\n return;\n }\n\n if (isGrid) {\n handleGridKeyDown(event, index);\n } else {\n handleListKeyDown(event, index);\n }\n },\n\n onClick: (event: React.MouseEvent) => {\n onClick?.(event);\n setActiveIndex(index);\n },\n };\n },\n [activeIndex, isGrid, handleGridKeyDown, handleListKeyDown, setActiveIndex]\n );\n\n return {\n getItemProps,\n focusedIndex: activeIndex,\n setFocusedIndex: setActiveIndex,\n };\n}\n\nexport namespace useRovingIndex {\n export type Input = UseRovingIndexInput;\n export type GetItemPropsInput = UseRovingIndexGetItemPropsInput;\n export type ReturnValue = UseRovingIndexReturnValue;\n}\n"],"mappings":";;;;AA8DA,SAAS,gBACP,SACA,OACA,gBACA,MACQ;AACR,MAAK,IAAI,IAAI,UAAU,GAAG,IAAI,OAAO,KAAK,EACxC,KAAI,CAAC,eAAe,EAAE,CACpB,QAAO;AAIX,KAAI;OACG,IA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;AACH,gBAAY,gBAAgB,OAAO,eAAe;AAClD;;AAIJ,MAAI,cAAc,QAAQ,cAAc,cAAc;AACpD,SAAM,gBAAgB;AACtB,SAAM,iBAAiB;AACvB,aAAU,UAAU;;IAGxB;EAAC;EAAO;EAAa;EAAM;EAAK;EAAgB;EAAU,CAC3D;AAwCD,QAAO;EACL,cAvCmB,aAClB,YAA6C;GAC5C,MAAM,EAAE,OAAO,SAAS,cAAc;AAEtC,UAAO;IACL,UAAW,UAAU,cAAc,IAAI;IAEvC,MAAM,SAA6B;AACjC,SAAI,KACF,UAAS,QAAQ,IAAI,OAAO,KAAK;SAEjC,UAAS,QAAQ,OAAO,MAAM;;IAIlC,YAAY,UAA+B;AACzC,iBAAY,MAAM;AAElB,SAAI,MAAM,iBACR;AAGF,SAAI,OACF,mBAAkB,OAAO,MAAM;SAE/B,mBAAkB,OAAO,MAAM;;IAInC,UAAU,UAA4B;AACpC,eAAU,MAAM;AAChB,oBAAe,MAAM;;IAExB;KAEH;GAAC;GAAa;GAAQ;GAAmB;GAAmB;GAAe,CAC5E;EAIC,cAAc;EACd,iBAAiB;EAClB"}
|
|
@@ -1,433 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useUncontrolled } from "../use-uncontrolled/use-uncontrolled.mjs";
|
|
3
|
-
import { useCallback, useRef, useState } from "react";
|
|
4
|
-
//#region packages/@mantine/hooks/src/use-splitter/use-splitter.ts
|
|
5
|
-
function clamp(value, min, max) {
|
|
6
|
-
return Math.min(Math.max(value, min), max);
|
|
7
|
-
}
|
|
8
|
-
function getMin(panel) {
|
|
9
|
-
return panel.min ?? 0;
|
|
10
|
-
}
|
|
11
|
-
function getMax(panel) {
|
|
12
|
-
return panel.max ?? 100;
|
|
13
|
-
}
|
|
14
|
-
function getCollapseThreshold(panel) {
|
|
15
|
-
return panel.collapseThreshold ?? getMin(panel);
|
|
16
|
-
}
|
|
17
|
-
function createInitialInternalState() {
|
|
18
|
-
return {
|
|
19
|
-
isDragging: false,
|
|
20
|
-
handleIndex: -1,
|
|
21
|
-
startPointer: 0,
|
|
22
|
-
containerSize: 0,
|
|
23
|
-
startSizes: [],
|
|
24
|
-
preCollapseSizes: []
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function checkCollapse(sizes, panels, handleIndex, delta) {
|
|
28
|
-
const beforeIdx = handleIndex;
|
|
29
|
-
const afterIdx = handleIndex + 1;
|
|
30
|
-
const beforePanel = panels[beforeIdx];
|
|
31
|
-
const afterPanel = panels[afterIdx];
|
|
32
|
-
const rawBefore = sizes[beforeIdx] + delta;
|
|
33
|
-
const rawAfter = sizes[afterIdx] - delta;
|
|
34
|
-
if (beforePanel.collapsible && rawBefore < getCollapseThreshold(beforePanel) && rawBefore < sizes[beforeIdx]) {
|
|
35
|
-
const result = [...sizes];
|
|
36
|
-
result[afterIdx] += result[beforeIdx];
|
|
37
|
-
result[beforeIdx] = 0;
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
if (afterPanel.collapsible && rawAfter < getCollapseThreshold(afterPanel) && rawAfter < sizes[afterIdx]) {
|
|
41
|
-
const result = [...sizes];
|
|
42
|
-
result[beforeIdx] += result[afterIdx];
|
|
43
|
-
result[afterIdx] = 0;
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
function applyAdjacentOnly(sizes, panels, handleIndex, delta) {
|
|
49
|
-
const result = [...sizes];
|
|
50
|
-
const beforeIdx = handleIndex;
|
|
51
|
-
const afterIdx = handleIndex + 1;
|
|
52
|
-
const total = result[beforeIdx] + result[afterIdx];
|
|
53
|
-
const effectiveBeforeMax = Math.min(getMax(panels[beforeIdx]), total - getMin(panels[afterIdx]));
|
|
54
|
-
const effectiveBeforeMin = Math.max(getMin(panels[beforeIdx]), total - getMax(panels[afterIdx]));
|
|
55
|
-
const newBefore = clamp(result[beforeIdx] + delta, effectiveBeforeMin, effectiveBeforeMax);
|
|
56
|
-
result[beforeIdx] = newBefore;
|
|
57
|
-
result[afterIdx] = total - newBefore;
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
function redistributeNearest(sizes, panels, handleIndex, delta) {
|
|
61
|
-
const result = [...sizes];
|
|
62
|
-
if (delta > 0) {
|
|
63
|
-
const growIdx = handleIndex;
|
|
64
|
-
const maxGrow = getMax(panels[growIdx]) - result[growIdx];
|
|
65
|
-
const wantedGrow = Math.min(delta, maxGrow);
|
|
66
|
-
let taken = 0;
|
|
67
|
-
for (let i = handleIndex + 1; i < result.length && taken < wantedGrow; i += 1) {
|
|
68
|
-
const canGive = result[i] - getMin(panels[i]);
|
|
69
|
-
const take = Math.min(canGive, wantedGrow - taken);
|
|
70
|
-
result[i] -= take;
|
|
71
|
-
taken += take;
|
|
72
|
-
}
|
|
73
|
-
result[growIdx] += taken;
|
|
74
|
-
} else if (delta < 0) {
|
|
75
|
-
const growIdx = handleIndex + 1;
|
|
76
|
-
const maxGrow = getMax(panels[growIdx]) - result[growIdx];
|
|
77
|
-
const wantedGrow = Math.min(Math.abs(delta), maxGrow);
|
|
78
|
-
let taken = 0;
|
|
79
|
-
for (let i = handleIndex; i >= 0 && taken < wantedGrow; i -= 1) {
|
|
80
|
-
const canGive = result[i] - getMin(panels[i]);
|
|
81
|
-
const take = Math.min(canGive, wantedGrow - taken);
|
|
82
|
-
result[i] -= take;
|
|
83
|
-
taken += take;
|
|
84
|
-
}
|
|
85
|
-
result[growIdx] += taken;
|
|
86
|
-
}
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
function redistributeEqual(sizes, panels, handleIndex, delta) {
|
|
90
|
-
const result = [...sizes];
|
|
91
|
-
if (delta > 0) {
|
|
92
|
-
const growIdx = handleIndex;
|
|
93
|
-
const maxGrow = getMax(panels[growIdx]) - result[growIdx];
|
|
94
|
-
const wantedGrow = Math.min(delta, maxGrow);
|
|
95
|
-
const donors = [];
|
|
96
|
-
for (let i = handleIndex + 1; i < result.length; i += 1) if (result[i] > getMin(panels[i])) donors.push(i);
|
|
97
|
-
let remaining = wantedGrow;
|
|
98
|
-
while (remaining > .001 && donors.length > 0) {
|
|
99
|
-
const perDonor = remaining / donors.length;
|
|
100
|
-
const exhausted = [];
|
|
101
|
-
for (let d = 0; d < donors.length; d += 1) {
|
|
102
|
-
const idx = donors[d];
|
|
103
|
-
const canGive = result[idx] - getMin(panels[idx]);
|
|
104
|
-
const take = Math.min(canGive, perDonor);
|
|
105
|
-
result[idx] -= take;
|
|
106
|
-
remaining -= take;
|
|
107
|
-
if (canGive <= perDonor + .001) exhausted.push(d);
|
|
108
|
-
}
|
|
109
|
-
for (let i = exhausted.length - 1; i >= 0; i -= 1) donors.splice(exhausted[i], 1);
|
|
110
|
-
if (exhausted.length === 0) break;
|
|
111
|
-
}
|
|
112
|
-
result[growIdx] += wantedGrow - remaining;
|
|
113
|
-
} else if (delta < 0) {
|
|
114
|
-
const growIdx = handleIndex + 1;
|
|
115
|
-
const maxGrow = getMax(panels[growIdx]) - result[growIdx];
|
|
116
|
-
const wantedGrow = Math.min(Math.abs(delta), maxGrow);
|
|
117
|
-
const donors = [];
|
|
118
|
-
for (let i = handleIndex; i >= 0; i -= 1) if (result[i] > getMin(panels[i])) donors.push(i);
|
|
119
|
-
let remaining = wantedGrow;
|
|
120
|
-
while (remaining > .001 && donors.length > 0) {
|
|
121
|
-
const perDonor = remaining / donors.length;
|
|
122
|
-
const exhausted = [];
|
|
123
|
-
for (let d = 0; d < donors.length; d += 1) {
|
|
124
|
-
const idx = donors[d];
|
|
125
|
-
const canGive = result[idx] - getMin(panels[idx]);
|
|
126
|
-
const take = Math.min(canGive, perDonor);
|
|
127
|
-
result[idx] -= take;
|
|
128
|
-
remaining -= take;
|
|
129
|
-
if (canGive <= perDonor + .001) exhausted.push(d);
|
|
130
|
-
}
|
|
131
|
-
for (let i = exhausted.length - 1; i >= 0; i -= 1) donors.splice(exhausted[i], 1);
|
|
132
|
-
if (exhausted.length === 0) break;
|
|
133
|
-
}
|
|
134
|
-
result[growIdx] += wantedGrow - remaining;
|
|
135
|
-
}
|
|
136
|
-
return result;
|
|
137
|
-
}
|
|
138
|
-
function applyConstraints(sizes, panels, handleIndex, delta, redistribute) {
|
|
139
|
-
if (typeof redistribute === "function") return redistribute({
|
|
140
|
-
sizes: [...sizes],
|
|
141
|
-
panels,
|
|
142
|
-
handleIndex,
|
|
143
|
-
delta
|
|
144
|
-
});
|
|
145
|
-
if (redistribute === "nearest" || redistribute === "equal") {
|
|
146
|
-
const result = (redistribute === "nearest" ? redistributeNearest : redistributeEqual)(sizes, panels, handleIndex, delta);
|
|
147
|
-
const beforeIdx = handleIndex;
|
|
148
|
-
const afterIdx = handleIndex + 1;
|
|
149
|
-
const beforePanel = panels[beforeIdx];
|
|
150
|
-
const afterPanel = panels[afterIdx];
|
|
151
|
-
if (beforePanel.collapsible && result[beforeIdx] < getCollapseThreshold(beforePanel) && result[beforeIdx] < sizes[beforeIdx]) {
|
|
152
|
-
const freed = result[beforeIdx];
|
|
153
|
-
result[afterIdx] += freed;
|
|
154
|
-
result[beforeIdx] = 0;
|
|
155
|
-
} else if (afterPanel.collapsible && result[afterIdx] < getCollapseThreshold(afterPanel) && result[afterIdx] < sizes[afterIdx]) {
|
|
156
|
-
const freed = result[afterIdx];
|
|
157
|
-
result[beforeIdx] += freed;
|
|
158
|
-
result[afterIdx] = 0;
|
|
159
|
-
}
|
|
160
|
-
return result;
|
|
161
|
-
}
|
|
162
|
-
const collapsed = checkCollapse(sizes, panels, handleIndex, delta);
|
|
163
|
-
if (collapsed) return collapsed;
|
|
164
|
-
return applyAdjacentOnly(sizes, panels, handleIndex, delta);
|
|
165
|
-
}
|
|
166
|
-
function useSplitter(options) {
|
|
167
|
-
const { panels, orientation = "horizontal", sizes: controlledSizes, onSizeChange, onCollapseChange, redistribute, step = 1, shiftStep = 10, dir = "ltr", enabled = true } = options;
|
|
168
|
-
const defaultSizes = panels.map((p) => p.defaultSize);
|
|
169
|
-
const [currentSizes, setCurrentSizes] = useUncontrolled({
|
|
170
|
-
value: controlledSizes,
|
|
171
|
-
defaultValue: defaultSizes,
|
|
172
|
-
finalValue: defaultSizes,
|
|
173
|
-
onChange: onSizeChange
|
|
174
|
-
});
|
|
175
|
-
const [activeHandle, setActiveHandle] = useState(-1);
|
|
176
|
-
const optionsRef = useRef(options);
|
|
177
|
-
optionsRef.current = options;
|
|
178
|
-
const internalStateRef = useRef(createInitialInternalState());
|
|
179
|
-
const containerRef = useRef(null);
|
|
180
|
-
const documentControllerRef = useRef(null);
|
|
181
|
-
const frameRef = useRef(0);
|
|
182
|
-
const currentSizesRef = useRef(currentSizes);
|
|
183
|
-
currentSizesRef.current = currentSizes;
|
|
184
|
-
const preCollapseSizesRef = useRef(defaultSizes);
|
|
185
|
-
const collapsed = currentSizes.map((size) => size === 0);
|
|
186
|
-
const updateSizes = useCallback((newSizes) => {
|
|
187
|
-
currentSizesRef.current = newSizes;
|
|
188
|
-
setCurrentSizes(newSizes);
|
|
189
|
-
}, [setCurrentSizes]);
|
|
190
|
-
const collapsePanel = useCallback((panelIndex) => {
|
|
191
|
-
if (!panels[panelIndex]?.collapsible) return;
|
|
192
|
-
const sizes = currentSizesRef.current;
|
|
193
|
-
if (sizes[panelIndex] === 0) return;
|
|
194
|
-
preCollapseSizesRef.current = [...sizes];
|
|
195
|
-
const newSizes = [...sizes];
|
|
196
|
-
const freedSize = newSizes[panelIndex];
|
|
197
|
-
newSizes[panelIndex] = 0;
|
|
198
|
-
const neighbor = panelIndex === 0 ? 1 : panelIndex - 1;
|
|
199
|
-
newSizes[neighbor] += freedSize;
|
|
200
|
-
updateSizes(newSizes);
|
|
201
|
-
onCollapseChange?.(panelIndex, true);
|
|
202
|
-
}, [
|
|
203
|
-
panels,
|
|
204
|
-
updateSizes,
|
|
205
|
-
onCollapseChange
|
|
206
|
-
]);
|
|
207
|
-
const expandPanel = useCallback((panelIndex) => {
|
|
208
|
-
if (!panels[panelIndex]?.collapsible) return;
|
|
209
|
-
const sizes = currentSizesRef.current;
|
|
210
|
-
if (sizes[panelIndex] !== 0) return;
|
|
211
|
-
const restoreSize = preCollapseSizesRef.current[panelIndex] || panels[panelIndex].defaultSize;
|
|
212
|
-
const newSizes = [...sizes];
|
|
213
|
-
const neighbor = panelIndex === 0 ? 1 : panelIndex - 1;
|
|
214
|
-
const available = newSizes[neighbor] - getMin(panels[neighbor]);
|
|
215
|
-
const actualRestore = Math.min(restoreSize, available);
|
|
216
|
-
newSizes[panelIndex] = actualRestore;
|
|
217
|
-
newSizes[neighbor] -= actualRestore;
|
|
218
|
-
updateSizes(newSizes);
|
|
219
|
-
onCollapseChange?.(panelIndex, false);
|
|
220
|
-
}, [
|
|
221
|
-
panels,
|
|
222
|
-
updateSizes,
|
|
223
|
-
onCollapseChange
|
|
224
|
-
]);
|
|
225
|
-
const toggleCollapsePanel = useCallback((panelIndex) => {
|
|
226
|
-
if (currentSizesRef.current[panelIndex] === 0) expandPanel(panelIndex);
|
|
227
|
-
else collapsePanel(panelIndex);
|
|
228
|
-
}, [collapsePanel, expandPanel]);
|
|
229
|
-
const containerRefCallback = useCallback((node) => {
|
|
230
|
-
containerRef.current = node;
|
|
231
|
-
}, []);
|
|
232
|
-
const handleRefCallbacks = useRef(/* @__PURE__ */ new Map());
|
|
233
|
-
const handleElementControllers = useRef(/* @__PURE__ */ new Map());
|
|
234
|
-
const getHandleRefCallback = useCallback((handleIndex) => {
|
|
235
|
-
if (handleRefCallbacks.current.has(handleIndex)) return handleRefCallbacks.current.get(handleIndex);
|
|
236
|
-
const callback = (node) => {
|
|
237
|
-
const existingController = handleElementControllers.current.get(handleIndex);
|
|
238
|
-
if (existingController) {
|
|
239
|
-
existingController.abort();
|
|
240
|
-
handleElementControllers.current.delete(handleIndex);
|
|
241
|
-
}
|
|
242
|
-
if (!node) return;
|
|
243
|
-
const elementController = new AbortController();
|
|
244
|
-
handleElementControllers.current.set(handleIndex, elementController);
|
|
245
|
-
const onPointerDown = (event) => {
|
|
246
|
-
if (optionsRef.current.enabled === false) return;
|
|
247
|
-
if (event.button !== 0) return;
|
|
248
|
-
const container = containerRef.current;
|
|
249
|
-
if (!container) return;
|
|
250
|
-
const rect = container.getBoundingClientRect();
|
|
251
|
-
const isHorizontal = (optionsRef.current.orientation ?? "horizontal") === "horizontal";
|
|
252
|
-
const containerSize = isHorizontal ? rect.width : rect.height;
|
|
253
|
-
const pointerPos = isHorizontal ? event.clientX : event.clientY;
|
|
254
|
-
const s = internalStateRef.current;
|
|
255
|
-
s.isDragging = true;
|
|
256
|
-
s.handleIndex = handleIndex;
|
|
257
|
-
s.startPointer = pointerPos;
|
|
258
|
-
s.containerSize = containerSize;
|
|
259
|
-
s.startSizes = [...currentSizesRef.current];
|
|
260
|
-
s.preCollapseSizes = [...preCollapseSizesRef.current];
|
|
261
|
-
setActiveHandle(handleIndex);
|
|
262
|
-
document.body.style.userSelect = "none";
|
|
263
|
-
document.body.style.webkitUserSelect = "none";
|
|
264
|
-
document.body.style.cursor = isHorizontal ? "col-resize" : "row-resize";
|
|
265
|
-
optionsRef.current.onResizeStart?.(handleIndex);
|
|
266
|
-
documentControllerRef.current?.abort();
|
|
267
|
-
documentControllerRef.current = new AbortController();
|
|
268
|
-
const sig = documentControllerRef.current.signal;
|
|
269
|
-
document.addEventListener("pointermove", onPointerMove, { signal: sig });
|
|
270
|
-
document.addEventListener("pointerup", onPointerUp, { signal: sig });
|
|
271
|
-
document.addEventListener("pointercancel", onPointerUp, { signal: sig });
|
|
272
|
-
};
|
|
273
|
-
const flushResize = (pointerEvent) => {
|
|
274
|
-
const s = internalStateRef.current;
|
|
275
|
-
const percentDelta = (((optionsRef.current.orientation ?? "horizontal") === "horizontal" ? pointerEvent.clientX : pointerEvent.clientY) - s.startPointer) / s.containerSize * 100;
|
|
276
|
-
const opts = optionsRef.current;
|
|
277
|
-
const newSizes = applyConstraints(s.startSizes, opts.panels, s.handleIndex, percentDelta, opts.redistribute);
|
|
278
|
-
const prevSizes = currentSizesRef.current;
|
|
279
|
-
const beforeWasCollapsed = prevSizes[s.handleIndex] === 0;
|
|
280
|
-
const afterWasCollapsed = prevSizes[s.handleIndex + 1] === 0;
|
|
281
|
-
const beforeNowCollapsed = newSizes[s.handleIndex] === 0;
|
|
282
|
-
const afterNowCollapsed = newSizes[s.handleIndex + 1] === 0;
|
|
283
|
-
if (!beforeWasCollapsed && beforeNowCollapsed) {
|
|
284
|
-
preCollapseSizesRef.current = [...s.startSizes];
|
|
285
|
-
opts.onCollapseChange?.(s.handleIndex, true);
|
|
286
|
-
} else if (beforeWasCollapsed && !beforeNowCollapsed) opts.onCollapseChange?.(s.handleIndex, false);
|
|
287
|
-
if (!afterWasCollapsed && afterNowCollapsed) {
|
|
288
|
-
preCollapseSizesRef.current = [...s.startSizes];
|
|
289
|
-
opts.onCollapseChange?.(s.handleIndex + 1, true);
|
|
290
|
-
} else if (afterWasCollapsed && !afterNowCollapsed) opts.onCollapseChange?.(s.handleIndex + 1, false);
|
|
291
|
-
currentSizesRef.current = newSizes;
|
|
292
|
-
setCurrentSizes(newSizes);
|
|
293
|
-
};
|
|
294
|
-
const onPointerMove = (event) => {
|
|
295
|
-
if (!internalStateRef.current.isDragging) return;
|
|
296
|
-
cancelAnimationFrame(frameRef.current);
|
|
297
|
-
frameRef.current = requestAnimationFrame(() => {
|
|
298
|
-
flushResize(event);
|
|
299
|
-
});
|
|
300
|
-
};
|
|
301
|
-
const onPointerUp = (event) => {
|
|
302
|
-
const s = internalStateRef.current;
|
|
303
|
-
if (!s.isDragging) return;
|
|
304
|
-
cancelAnimationFrame(frameRef.current);
|
|
305
|
-
flushResize(event);
|
|
306
|
-
s.isDragging = false;
|
|
307
|
-
const finishedHandle = s.handleIndex;
|
|
308
|
-
s.handleIndex = -1;
|
|
309
|
-
setActiveHandle(-1);
|
|
310
|
-
document.body.style.userSelect = "";
|
|
311
|
-
document.body.style.webkitUserSelect = "";
|
|
312
|
-
document.body.style.cursor = "";
|
|
313
|
-
documentControllerRef.current?.abort();
|
|
314
|
-
documentControllerRef.current = null;
|
|
315
|
-
optionsRef.current.onResizeEnd?.(finishedHandle, [...currentSizesRef.current]);
|
|
316
|
-
};
|
|
317
|
-
node.addEventListener("pointerdown", onPointerDown, { signal: elementController.signal });
|
|
318
|
-
};
|
|
319
|
-
handleRefCallbacks.current.set(handleIndex, callback);
|
|
320
|
-
return callback;
|
|
321
|
-
}, [setCurrentSizes]);
|
|
322
|
-
return {
|
|
323
|
-
ref: containerRefCallback,
|
|
324
|
-
sizes: currentSizes,
|
|
325
|
-
collapsed,
|
|
326
|
-
activeHandle,
|
|
327
|
-
getHandleProps: useCallback((input) => {
|
|
328
|
-
const { index } = input;
|
|
329
|
-
const orient = orientation;
|
|
330
|
-
const beforeSize = currentSizes[index] ?? 0;
|
|
331
|
-
const beforePanel = panels[index];
|
|
332
|
-
const afterPanel = panels[index + 1];
|
|
333
|
-
return {
|
|
334
|
-
ref: getHandleRefCallback(index),
|
|
335
|
-
role: "separator",
|
|
336
|
-
"aria-orientation": orient,
|
|
337
|
-
"aria-valuenow": Math.round(beforeSize),
|
|
338
|
-
"aria-valuemin": Math.round(getMin(beforePanel)),
|
|
339
|
-
"aria-valuemax": Math.round(getMax(beforePanel)),
|
|
340
|
-
tabIndex: 0,
|
|
341
|
-
onKeyDown: (event) => {
|
|
342
|
-
if (!enabled) return;
|
|
343
|
-
const isHorizontal = orient === "horizontal";
|
|
344
|
-
const isRtl = dir === "rtl";
|
|
345
|
-
let delta = 0;
|
|
346
|
-
const currentStep = event.shiftKey ? shiftStep : step;
|
|
347
|
-
switch (event.key) {
|
|
348
|
-
case "ArrowLeft":
|
|
349
|
-
if (isHorizontal) delta = isRtl ? currentStep : -currentStep;
|
|
350
|
-
break;
|
|
351
|
-
case "ArrowRight":
|
|
352
|
-
if (isHorizontal) delta = isRtl ? -currentStep : currentStep;
|
|
353
|
-
break;
|
|
354
|
-
case "ArrowUp":
|
|
355
|
-
if (!isHorizontal) delta = -currentStep;
|
|
356
|
-
break;
|
|
357
|
-
case "ArrowDown":
|
|
358
|
-
if (!isHorizontal) delta = currentStep;
|
|
359
|
-
break;
|
|
360
|
-
case "Home":
|
|
361
|
-
delta = -(currentSizes[index] - getMin(beforePanel));
|
|
362
|
-
break;
|
|
363
|
-
case "End":
|
|
364
|
-
delta = getMax(beforePanel) - currentSizes[index];
|
|
365
|
-
break;
|
|
366
|
-
case "Enter": {
|
|
367
|
-
const beforeCollapsible = beforePanel?.collapsible;
|
|
368
|
-
const afterCollapsible = afterPanel?.collapsible;
|
|
369
|
-
if (beforeCollapsible && currentSizes[index] <= currentSizes[index + 1]) {
|
|
370
|
-
toggleCollapsePanel(index);
|
|
371
|
-
event.preventDefault();
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
if (afterCollapsible) {
|
|
375
|
-
toggleCollapsePanel(index + 1);
|
|
376
|
-
event.preventDefault();
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
if (beforeCollapsible) {
|
|
380
|
-
toggleCollapsePanel(index);
|
|
381
|
-
event.preventDefault();
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
default: return;
|
|
387
|
-
}
|
|
388
|
-
event.preventDefault();
|
|
389
|
-
if (delta !== 0) {
|
|
390
|
-
const newSizes = applyConstraints(currentSizes, panels, index, delta, redistribute);
|
|
391
|
-
const beforeWas = currentSizes[index] === 0;
|
|
392
|
-
const afterWas = currentSizes[index + 1] === 0;
|
|
393
|
-
const beforeNow = newSizes[index] === 0;
|
|
394
|
-
const afterNow = newSizes[index + 1] === 0;
|
|
395
|
-
if (!beforeWas && beforeNow) {
|
|
396
|
-
preCollapseSizesRef.current = [...currentSizes];
|
|
397
|
-
onCollapseChange?.(index, true);
|
|
398
|
-
} else if (beforeWas && !beforeNow) onCollapseChange?.(index, false);
|
|
399
|
-
if (!afterWas && afterNow) {
|
|
400
|
-
preCollapseSizesRef.current = [...currentSizes];
|
|
401
|
-
onCollapseChange?.(index + 1, true);
|
|
402
|
-
} else if (afterWas && !afterNow) onCollapseChange?.(index + 1, false);
|
|
403
|
-
updateSizes(newSizes);
|
|
404
|
-
}
|
|
405
|
-
},
|
|
406
|
-
"data-active": activeHandle === index || void 0,
|
|
407
|
-
"data-orientation": orient
|
|
408
|
-
};
|
|
409
|
-
}, [
|
|
410
|
-
orientation,
|
|
411
|
-
currentSizes,
|
|
412
|
-
panels,
|
|
413
|
-
enabled,
|
|
414
|
-
dir,
|
|
415
|
-
step,
|
|
416
|
-
shiftStep,
|
|
417
|
-
activeHandle,
|
|
418
|
-
redistribute,
|
|
419
|
-
getHandleRefCallback,
|
|
420
|
-
toggleCollapsePanel,
|
|
421
|
-
updateSizes,
|
|
422
|
-
onCollapseChange
|
|
423
|
-
]),
|
|
424
|
-
setSizes: updateSizes,
|
|
425
|
-
collapse: collapsePanel,
|
|
426
|
-
expand: expandPanel,
|
|
427
|
-
toggleCollapse: toggleCollapsePanel
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
//#endregion
|
|
431
|
-
export { useSplitter };
|
|
432
|
-
|
|
433
|
-
//# sourceMappingURL=use-splitter.mjs.map
|