@mantine/hooks 9.3.1 → 9.3.2

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.
@@ -164,7 +164,7 @@ function applyConstraints(sizes, panels, handleIndex, delta, redistribute) {
164
164
  return applyAdjacentOnly(sizes, panels, handleIndex, delta);
165
165
  }
166
166
  function useSplitter(options) {
167
- const { panels, orientation = "horizontal", sizes: controlledSizes, onSizeChange, onCollapseChange, redistribute, step = 1, shiftStep = 10, dir = "ltr", enabled = true } = options;
167
+ const { panels, orientation = "horizontal", sizes: controlledSizes, onSizeChange, onCollapseChange, redistribute, step = 1, shiftStep = 10, dir = "ltr", resetOnDoubleClick = true, enabled = true } = options;
168
168
  const defaultSizes = panels.map((p) => p.defaultSize);
169
169
  const [currentSizes, setCurrentSizes] = require_use_uncontrolled.useUncontrolled({
170
170
  value: controlledSizes,
@@ -227,6 +227,30 @@ function useSplitter(options) {
227
227
  if (currentSizesRef.current[panelIndex] === 0) expandPanel(panelIndex);
228
228
  else collapsePanel(panelIndex);
229
229
  }, [collapsePanel, expandPanel]);
230
+ const emitCollapseTransitions = (0, react.useCallback)((prev, next, indices, preCollapseSnapshot) => {
231
+ const onChange = optionsRef.current.onCollapseChange;
232
+ for (const idx of indices) {
233
+ const wasCollapsed = prev[idx] === 0;
234
+ const nowCollapsed = next[idx] === 0;
235
+ if (!wasCollapsed && nowCollapsed) {
236
+ preCollapseSizesRef.current = [...preCollapseSnapshot];
237
+ onChange?.(idx, true);
238
+ } else if (wasCollapsed && !nowCollapsed) onChange?.(idx, false);
239
+ }
240
+ }, []);
241
+ const reset = (0, react.useCallback)((handleIndex) => {
242
+ const prev = currentSizesRef.current;
243
+ const currentPanels = optionsRef.current.panels;
244
+ const beforeIdx = handleIndex;
245
+ const afterIdx = handleIndex + 1;
246
+ if (beforeIdx < 0 || afterIdx >= prev.length) return;
247
+ const total = prev[beforeIdx] + prev[afterIdx];
248
+ const defBefore = currentPanels[beforeIdx].defaultSize;
249
+ const defTotal = defBefore + currentPanels[afterIdx].defaultSize;
250
+ const next = applyAdjacentOnly(prev, currentPanels, beforeIdx, (defTotal === 0 ? total / 2 : total * (defBefore / defTotal)) - prev[beforeIdx]);
251
+ emitCollapseTransitions(prev, next, [beforeIdx, afterIdx], prev);
252
+ updateSizes(next);
253
+ }, [emitCollapseTransitions, updateSizes]);
230
254
  const containerRefCallback = (0, react.useCallback)((node) => {
231
255
  containerRef.current = node;
232
256
  }, []);
@@ -281,18 +305,7 @@ function useSplitter(options) {
281
305
  const opts = optionsRef.current;
282
306
  const newSizes = applyConstraints(s.startSizes, opts.panels, s.handleIndex, percentDelta, opts.redistribute);
283
307
  const prevSizes = currentSizesRef.current;
284
- const beforeWasCollapsed = prevSizes[s.handleIndex] === 0;
285
- const afterWasCollapsed = prevSizes[s.handleIndex + 1] === 0;
286
- const beforeNowCollapsed = newSizes[s.handleIndex] === 0;
287
- const afterNowCollapsed = newSizes[s.handleIndex + 1] === 0;
288
- if (!beforeWasCollapsed && beforeNowCollapsed) {
289
- preCollapseSizesRef.current = [...s.startSizes];
290
- opts.onCollapseChange?.(s.handleIndex, true);
291
- } else if (beforeWasCollapsed && !beforeNowCollapsed) opts.onCollapseChange?.(s.handleIndex, false);
292
- if (!afterWasCollapsed && afterNowCollapsed) {
293
- preCollapseSizesRef.current = [...s.startSizes];
294
- opts.onCollapseChange?.(s.handleIndex + 1, true);
295
- } else if (afterWasCollapsed && !afterNowCollapsed) opts.onCollapseChange?.(s.handleIndex + 1, false);
308
+ emitCollapseTransitions(prevSizes, newSizes, [s.handleIndex, s.handleIndex + 1], s.startSizes);
296
309
  currentSizesRef.current = newSizes;
297
310
  setCurrentSizes(newSizes);
298
311
  };
@@ -392,21 +405,14 @@ function useSplitter(options) {
392
405
  event.preventDefault();
393
406
  if (delta !== 0) {
394
407
  const newSizes = applyConstraints(currentSizes, panels, index, delta, redistribute);
395
- const beforeWas = currentSizes[index] === 0;
396
- const afterWas = currentSizes[index + 1] === 0;
397
- const beforeNow = newSizes[index] === 0;
398
- const afterNow = newSizes[index + 1] === 0;
399
- if (!beforeWas && beforeNow) {
400
- preCollapseSizesRef.current = [...currentSizes];
401
- onCollapseChange?.(index, true);
402
- } else if (beforeWas && !beforeNow) onCollapseChange?.(index, false);
403
- if (!afterWas && afterNow) {
404
- preCollapseSizesRef.current = [...currentSizes];
405
- onCollapseChange?.(index + 1, true);
406
- } else if (afterWas && !afterNow) onCollapseChange?.(index + 1, false);
408
+ emitCollapseTransitions(currentSizes, newSizes, [index, index + 1], currentSizes);
407
409
  updateSizes(newSizes);
408
410
  }
409
411
  },
412
+ onDoubleClick: () => {
413
+ if (!enabled || !resetOnDoubleClick) return;
414
+ reset(index);
415
+ },
410
416
  "data-active": activeHandle === index || void 0,
411
417
  "data-orientation": orient
412
418
  };
@@ -418,12 +424,14 @@ function useSplitter(options) {
418
424
  dir,
419
425
  step,
420
426
  shiftStep,
427
+ resetOnDoubleClick,
421
428
  activeHandle,
422
429
  redistribute,
423
430
  getHandleRefCallback,
424
431
  toggleCollapsePanel,
425
432
  updateSizes,
426
- onCollapseChange
433
+ emitCollapseTransitions,
434
+ reset
427
435
  ]);
428
436
  (0, react.useEffect)(() => () => {
429
437
  documentControllerRef.current?.abort();
@@ -447,7 +455,8 @@ function useSplitter(options) {
447
455
  setSizes: updateSizes,
448
456
  collapse: collapsePanel,
449
457
  expand: expandPanel,
450
- toggleCollapse: toggleCollapsePanel
458
+ toggleCollapse: toggleCollapsePanel,
459
+ reset
451
460
  };
452
461
  }
453
462
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"use-splitter.cjs","names":["useUncontrolled"],"sources":["../../src/use-splitter/use-splitter.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-deprecated */\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { useUncontrolled } from '../use-uncontrolled/use-uncontrolled';\n\nexport interface UseSplitterPanel {\n /** Initial size as percentage (0-100). All panels must sum to 100. */\n defaultSize: number;\n /** Minimum size percentage, `0` by default */\n min?: number;\n /** Maximum size percentage, `100` by default */\n max?: number;\n /** Whether this panel can be collapsed, `false` by default */\n collapsible?: boolean;\n /** Size below which the panel snaps to collapsed (percentage), defaults to `min` */\n collapseThreshold?: number;\n}\n\nexport interface UseSplitterRedistributeInput {\n /** Current sizes before applying delta */\n sizes: number[];\n /** Panel configurations */\n panels: UseSplitterPanel[];\n /** Index of the handle being dragged */\n handleIndex: number;\n /** Requested size change in percentage (positive = grow before-panel) */\n delta: number;\n}\n\nexport type UseSplitterRedistributeFn = (input: UseSplitterRedistributeInput) => number[];\n\nexport interface UseSplitterOptions {\n /** Panel configuration array (minimum 2 panels) */\n panels: UseSplitterPanel[];\n /** Layout direction, `'horizontal'` by default */\n orientation?: 'horizontal' | 'vertical';\n /** Controlled sizes (percentages summing to 100) */\n sizes?: number[];\n /** Called during resize with updated sizes */\n onSizeChange?: (sizes: number[]) => void;\n /** Called when drag starts */\n onResizeStart?: (handleIndex: number) => void;\n /** Called when drag ends */\n onResizeEnd?: (handleIndex: number, sizes: number[]) => void;\n /** Called when a panel collapses or expands */\n onCollapseChange?: (panelIndex: number, collapsed: boolean) => void;\n /** How to borrow space from non-adjacent panels when the immediate neighbor is at its min/max.\n * `'nearest'` takes from the nearest panel in the drag direction first.\n * `'equal'` distributes equally among all panels in the drag direction.\n * A function receives sizes, panels, handleIndex and delta, and returns new sizes.\n * When not set, only the two adjacent panels are affected. */\n redistribute?: 'nearest' | 'equal' | UseSplitterRedistributeFn;\n /** Keyboard step size in percentage, `1` by default */\n step?: number;\n /** Shift+arrow step size in percentage, `10` by default */\n shiftStep?: number;\n /** Text direction for keyboard nav, `'ltr'` by default */\n dir?: 'ltr' | 'rtl';\n /** Enable/disable the hook, `true` by default */\n enabled?: boolean;\n}\n\nexport interface UseSplitterReturnValue<T extends HTMLElement = any> {\n /** Ref callback for the container element */\n ref: React.RefCallback<T | null>;\n /** Current panel sizes as percentages */\n sizes: number[];\n /** Which panels are currently collapsed */\n collapsed: boolean[];\n /** Index of handle being dragged, or -1 */\n activeHandle: number;\n /** Get props to spread on each resize handle */\n getHandleProps: (input: { index: number }) => {\n ref: React.RefCallback<HTMLElement>;\n role: 'separator';\n 'aria-orientation': 'horizontal' | 'vertical';\n 'aria-valuenow': number;\n 'aria-valuemin': number;\n 'aria-valuemax': number;\n tabIndex: number;\n onKeyDown: React.KeyboardEventHandler;\n 'data-active': boolean | undefined;\n 'data-orientation': 'horizontal' | 'vertical';\n };\n /** Programmatically set sizes */\n setSizes: (sizes: number[]) => void;\n /** Collapse a panel */\n collapse: (panelIndex: number) => void;\n /** Expand a collapsed panel */\n expand: (panelIndex: number) => void;\n /** Toggle collapse of a panel */\n toggleCollapse: (panelIndex: number) => void;\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\nfunction getMin(panel: UseSplitterPanel): number {\n return panel.min ?? 0;\n}\n\nfunction getMax(panel: UseSplitterPanel): number {\n return panel.max ?? 100;\n}\n\nfunction getCollapseThreshold(panel: UseSplitterPanel): number {\n return panel.collapseThreshold ?? getMin(panel);\n}\n\ninterface SplitterInternalState {\n isDragging: boolean;\n handleIndex: number;\n startPointer: number;\n containerSize: number;\n startSizes: number[];\n preCollapseSizes: number[];\n}\n\nfunction createInitialInternalState(): SplitterInternalState {\n return {\n isDragging: false,\n handleIndex: -1,\n startPointer: 0,\n containerSize: 0,\n startSizes: [],\n preCollapseSizes: [],\n };\n}\n\nfunction checkCollapse(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] | null {\n const beforeIdx = handleIndex;\n const afterIdx = handleIndex + 1;\n const beforePanel = panels[beforeIdx];\n const afterPanel = panels[afterIdx];\n\n const rawBefore = sizes[beforeIdx] + delta;\n const rawAfter = sizes[afterIdx] - delta;\n\n if (\n beforePanel.collapsible &&\n rawBefore < getCollapseThreshold(beforePanel) &&\n rawBefore < sizes[beforeIdx]\n ) {\n const result = [...sizes];\n result[afterIdx] += result[beforeIdx];\n result[beforeIdx] = 0;\n return result;\n }\n\n if (\n afterPanel.collapsible &&\n rawAfter < getCollapseThreshold(afterPanel) &&\n rawAfter < sizes[afterIdx]\n ) {\n const result = [...sizes];\n result[beforeIdx] += result[afterIdx];\n result[afterIdx] = 0;\n return result;\n }\n\n return null;\n}\n\nfunction applyAdjacentOnly(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] {\n const result = [...sizes];\n const beforeIdx = handleIndex;\n const afterIdx = handleIndex + 1;\n\n const total = result[beforeIdx] + result[afterIdx];\n const effectiveBeforeMax = Math.min(getMax(panels[beforeIdx]), total - getMin(panels[afterIdx]));\n const effectiveBeforeMin = Math.max(getMin(panels[beforeIdx]), total - getMax(panels[afterIdx]));\n const newBefore = clamp(result[beforeIdx] + delta, effectiveBeforeMin, effectiveBeforeMax);\n result[beforeIdx] = newBefore;\n result[afterIdx] = total - newBefore;\n return result;\n}\n\nfunction redistributeNearest(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] {\n const result = [...sizes];\n\n if (delta > 0) {\n const growIdx = handleIndex;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(delta, maxGrow);\n\n let taken = 0;\n for (let i = handleIndex + 1; i < result.length && taken < wantedGrow; i += 1) {\n const canGive = result[i] - getMin(panels[i]);\n const take = Math.min(canGive, wantedGrow - taken);\n result[i] -= take;\n taken += take;\n }\n\n result[growIdx] += taken;\n } else if (delta < 0) {\n const growIdx = handleIndex + 1;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(Math.abs(delta), maxGrow);\n\n let taken = 0;\n for (let i = handleIndex; i >= 0 && taken < wantedGrow; i -= 1) {\n const canGive = result[i] - getMin(panels[i]);\n const take = Math.min(canGive, wantedGrow - taken);\n result[i] -= take;\n taken += take;\n }\n\n result[growIdx] += taken;\n }\n\n return result;\n}\n\nfunction redistributeEqual(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] {\n const result = [...sizes];\n\n if (delta > 0) {\n const growIdx = handleIndex;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(delta, maxGrow);\n\n const donors: number[] = [];\n for (let i = handleIndex + 1; i < result.length; i += 1) {\n if (result[i] > getMin(panels[i])) {\n donors.push(i);\n }\n }\n\n let remaining = wantedGrow;\n while (remaining > 0.001 && donors.length > 0) {\n const perDonor = remaining / donors.length;\n const exhausted: number[] = [];\n\n for (let d = 0; d < donors.length; d += 1) {\n const idx = donors[d];\n const canGive = result[idx] - getMin(panels[idx]);\n const take = Math.min(canGive, perDonor);\n result[idx] -= take;\n remaining -= take;\n if (canGive <= perDonor + 0.001) {\n exhausted.push(d);\n }\n }\n\n for (let i = exhausted.length - 1; i >= 0; i -= 1) {\n donors.splice(exhausted[i], 1);\n }\n\n if (exhausted.length === 0) {\n break;\n }\n }\n\n result[growIdx] += wantedGrow - remaining;\n } else if (delta < 0) {\n const growIdx = handleIndex + 1;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(Math.abs(delta), maxGrow);\n\n const donors: number[] = [];\n for (let i = handleIndex; i >= 0; i -= 1) {\n if (result[i] > getMin(panels[i])) {\n donors.push(i);\n }\n }\n\n let remaining = wantedGrow;\n while (remaining > 0.001 && donors.length > 0) {\n const perDonor = remaining / donors.length;\n const exhausted: number[] = [];\n\n for (let d = 0; d < donors.length; d += 1) {\n const idx = donors[d];\n const canGive = result[idx] - getMin(panels[idx]);\n const take = Math.min(canGive, perDonor);\n result[idx] -= take;\n remaining -= take;\n if (canGive <= perDonor + 0.001) {\n exhausted.push(d);\n }\n }\n\n for (let i = exhausted.length - 1; i >= 0; i -= 1) {\n donors.splice(exhausted[i], 1);\n }\n\n if (exhausted.length === 0) {\n break;\n }\n }\n\n result[growIdx] += wantedGrow - remaining;\n }\n\n return result;\n}\n\nfunction applyConstraints(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number,\n redistribute?: 'nearest' | 'equal' | UseSplitterRedistributeFn\n): number[] {\n if (typeof redistribute === 'function') {\n return redistribute({ sizes: [...sizes], panels, handleIndex, delta });\n }\n\n if (redistribute === 'nearest' || redistribute === 'equal') {\n const strategy = redistribute === 'nearest' ? redistributeNearest : redistributeEqual;\n const result = strategy(sizes, panels, handleIndex, delta);\n\n const beforeIdx = handleIndex;\n const afterIdx = handleIndex + 1;\n const beforePanel = panels[beforeIdx];\n const afterPanel = panels[afterIdx];\n\n if (\n beforePanel.collapsible &&\n result[beforeIdx] < getCollapseThreshold(beforePanel) &&\n result[beforeIdx] < sizes[beforeIdx]\n ) {\n const freed = result[beforeIdx];\n result[afterIdx] += freed;\n result[beforeIdx] = 0;\n } else if (\n afterPanel.collapsible &&\n result[afterIdx] < getCollapseThreshold(afterPanel) &&\n result[afterIdx] < sizes[afterIdx]\n ) {\n const freed = result[afterIdx];\n result[beforeIdx] += freed;\n result[afterIdx] = 0;\n }\n\n return result;\n }\n\n const collapsed = checkCollapse(sizes, panels, handleIndex, delta);\n if (collapsed) {\n return collapsed;\n }\n\n return applyAdjacentOnly(sizes, panels, handleIndex, delta);\n}\n\nexport function useSplitter<T extends HTMLElement = any>(\n options: UseSplitterOptions\n): UseSplitterReturnValue<T> {\n const {\n panels,\n orientation = 'horizontal',\n sizes: controlledSizes,\n onSizeChange,\n onCollapseChange,\n redistribute,\n step = 1,\n shiftStep = 10,\n dir = 'ltr',\n enabled = true,\n } = options;\n\n const defaultSizes = panels.map((p) => p.defaultSize);\n\n const [currentSizes, setCurrentSizes] = useUncontrolled({\n value: controlledSizes,\n defaultValue: defaultSizes,\n finalValue: defaultSizes,\n onChange: onSizeChange,\n });\n\n const [activeHandle, setActiveHandle] = useState(-1);\n\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n const internalStateRef = useRef<SplitterInternalState>(createInitialInternalState());\n const containerRef = useRef<T | null>(null);\n const documentControllerRef = useRef<AbortController | null>(null);\n const frameRef = useRef(0);\n const currentSizesRef = useRef(currentSizes);\n currentSizesRef.current = currentSizes;\n\n const preCollapseSizesRef = useRef<number[]>(defaultSizes);\n\n const collapsed = currentSizes.map((size) => size === 0);\n\n const updateSizes = useCallback(\n (newSizes: number[]) => {\n currentSizesRef.current = newSizes;\n setCurrentSizes(newSizes);\n },\n [setCurrentSizes]\n );\n\n const collapsePanel = useCallback(\n (panelIndex: number) => {\n if (!panels[panelIndex]?.collapsible) {\n return;\n }\n const sizes = currentSizesRef.current;\n if (sizes[panelIndex] === 0) {\n return;\n }\n\n preCollapseSizesRef.current = [...sizes];\n const newSizes = [...sizes];\n const freedSize = newSizes[panelIndex];\n newSizes[panelIndex] = 0;\n\n const neighbor = panelIndex === 0 ? 1 : panelIndex - 1;\n newSizes[neighbor] += freedSize;\n\n updateSizes(newSizes);\n onCollapseChange?.(panelIndex, true);\n },\n [panels, updateSizes, onCollapseChange]\n );\n\n const expandPanel = useCallback(\n (panelIndex: number) => {\n if (!panels[panelIndex]?.collapsible) {\n return;\n }\n const sizes = currentSizesRef.current;\n if (sizes[panelIndex] !== 0) {\n return;\n }\n\n const preCollapse = preCollapseSizesRef.current;\n const restoreSize = preCollapse[panelIndex] || panels[panelIndex].defaultSize;\n const newSizes = [...sizes];\n\n const neighbor = panelIndex === 0 ? 1 : panelIndex - 1;\n const available = Math.max(0, newSizes[neighbor] - getMin(panels[neighbor]));\n const actualRestore = Math.min(restoreSize, available);\n\n if (actualRestore <= 0) {\n return;\n }\n\n newSizes[panelIndex] = actualRestore;\n newSizes[neighbor] -= actualRestore;\n\n updateSizes(newSizes);\n onCollapseChange?.(panelIndex, false);\n },\n [panels, updateSizes, onCollapseChange]\n );\n\n const toggleCollapsePanel = useCallback(\n (panelIndex: number) => {\n if (currentSizesRef.current[panelIndex] === 0) {\n expandPanel(panelIndex);\n } else {\n collapsePanel(panelIndex);\n }\n },\n [collapsePanel, expandPanel]\n );\n\n const containerRefCallback: React.RefCallback<T | null> = useCallback((node) => {\n containerRef.current = node;\n }, []);\n\n const handleRefCallbacks = useRef<Map<number, (node: HTMLElement | null) => void>>(new Map());\n const handleElementControllers = useRef<Map<number, AbortController>>(new Map());\n\n const getHandleRefCallback = useCallback(\n (handleIndex: number): React.RefCallback<HTMLElement> => {\n if (handleRefCallbacks.current.has(handleIndex)) {\n return handleRefCallbacks.current.get(handleIndex)!;\n }\n\n const callback = (node: HTMLElement | null) => {\n const existingController = handleElementControllers.current.get(handleIndex);\n if (existingController) {\n existingController.abort();\n handleElementControllers.current.delete(handleIndex);\n }\n\n if (!node) {\n return;\n }\n\n const elementController = new AbortController();\n handleElementControllers.current.set(handleIndex, elementController);\n\n const onPointerDown = (event: PointerEvent) => {\n if (optionsRef.current.enabled === false) {\n return;\n }\n if (event.button !== 0) {\n return;\n }\n\n const container = containerRef.current;\n if (!container) {\n return;\n }\n\n const rect = container.getBoundingClientRect();\n const isHorizontal = (optionsRef.current.orientation ?? 'horizontal') === 'horizontal';\n const containerSize = isHorizontal ? rect.width : rect.height;\n const pointerPos = isHorizontal ? event.clientX : event.clientY;\n\n const s = internalStateRef.current;\n s.isDragging = true;\n s.handleIndex = handleIndex;\n s.startPointer = pointerPos;\n s.containerSize = containerSize;\n s.startSizes = [...currentSizesRef.current];\n s.preCollapseSizes = [...preCollapseSizesRef.current];\n\n setActiveHandle(handleIndex);\n document.body.style.userSelect = 'none';\n document.body.style.webkitUserSelect = 'none';\n document.body.style.cursor = isHorizontal ? 'col-resize' : 'row-resize';\n\n optionsRef.current.onResizeStart?.(handleIndex);\n\n documentControllerRef.current?.abort();\n documentControllerRef.current = new AbortController();\n const sig = documentControllerRef.current.signal;\n\n document.addEventListener('pointermove', onPointerMove, { signal: sig });\n document.addEventListener('pointerup', onPointerUp, { signal: sig });\n document.addEventListener('pointercancel', onPointerUp, { signal: sig });\n };\n\n const flushResize = (pointerEvent: PointerEvent) => {\n const s = internalStateRef.current;\n if (!s.containerSize) {\n return;\n }\n const isHorizontal = (optionsRef.current.orientation ?? 'horizontal') === 'horizontal';\n const isRtl = isHorizontal && optionsRef.current.dir === 'rtl';\n const pointerPos = isHorizontal ? pointerEvent.clientX : pointerEvent.clientY;\n const pixelDelta = pointerPos - s.startPointer;\n const percentDelta = ((isRtl ? -pixelDelta : pixelDelta) / s.containerSize) * 100;\n\n const opts = optionsRef.current;\n const newSizes = applyConstraints(\n s.startSizes,\n opts.panels,\n s.handleIndex,\n percentDelta,\n opts.redistribute\n );\n\n const prevSizes = currentSizesRef.current;\n const beforeWasCollapsed = prevSizes[s.handleIndex] === 0;\n const afterWasCollapsed = prevSizes[s.handleIndex + 1] === 0;\n const beforeNowCollapsed = newSizes[s.handleIndex] === 0;\n const afterNowCollapsed = newSizes[s.handleIndex + 1] === 0;\n\n if (!beforeWasCollapsed && beforeNowCollapsed) {\n preCollapseSizesRef.current = [...s.startSizes];\n opts.onCollapseChange?.(s.handleIndex, true);\n } else if (beforeWasCollapsed && !beforeNowCollapsed) {\n opts.onCollapseChange?.(s.handleIndex, false);\n }\n\n if (!afterWasCollapsed && afterNowCollapsed) {\n preCollapseSizesRef.current = [...s.startSizes];\n opts.onCollapseChange?.(s.handleIndex + 1, true);\n } else if (afterWasCollapsed && !afterNowCollapsed) {\n opts.onCollapseChange?.(s.handleIndex + 1, false);\n }\n\n currentSizesRef.current = newSizes;\n setCurrentSizes(newSizes);\n };\n\n const onPointerMove = (event: PointerEvent) => {\n const s = internalStateRef.current;\n if (!s.isDragging) {\n return;\n }\n\n cancelAnimationFrame(frameRef.current);\n frameRef.current = requestAnimationFrame(() => {\n flushResize(event);\n });\n };\n\n const onPointerUp = (event: PointerEvent) => {\n const s = internalStateRef.current;\n if (!s.isDragging) {\n return;\n }\n\n cancelAnimationFrame(frameRef.current);\n flushResize(event);\n\n s.isDragging = false;\n const finishedHandle = s.handleIndex;\n s.handleIndex = -1;\n\n setActiveHandle(-1);\n document.body.style.userSelect = '';\n document.body.style.webkitUserSelect = '';\n document.body.style.cursor = '';\n\n documentControllerRef.current?.abort();\n documentControllerRef.current = null;\n\n optionsRef.current.onResizeEnd?.(finishedHandle, [...currentSizesRef.current]);\n };\n\n node.addEventListener('pointerdown', onPointerDown, {\n signal: elementController.signal,\n });\n };\n\n handleRefCallbacks.current.set(handleIndex, callback);\n return callback;\n },\n [setCurrentSizes]\n );\n\n const getHandleProps = useCallback(\n (input: { index: number }) => {\n const { index } = input;\n const orient = orientation;\n const beforeSize = currentSizes[index] ?? 0;\n const beforePanel = panels[index];\n const afterPanel = panels[index + 1];\n\n return {\n ref: getHandleRefCallback(index),\n role: 'separator' as const,\n 'aria-orientation': orient,\n 'aria-valuenow': Math.round(beforeSize),\n 'aria-valuemin': Math.round(getMin(beforePanel)),\n 'aria-valuemax': Math.round(getMax(beforePanel)),\n tabIndex: 0,\n onKeyDown: (event: React.KeyboardEvent) => {\n if (!enabled) {\n return;\n }\n\n const isHorizontal = orient === 'horizontal';\n const isRtl = dir === 'rtl';\n\n let delta = 0;\n const currentStep = event.shiftKey ? shiftStep : step;\n\n switch (event.key) {\n case 'ArrowLeft': {\n if (!isHorizontal) {\n return;\n }\n delta = isRtl ? currentStep : -currentStep;\n break;\n }\n case 'ArrowRight': {\n if (!isHorizontal) {\n return;\n }\n delta = isRtl ? -currentStep : currentStep;\n break;\n }\n case 'ArrowUp': {\n if (isHorizontal) {\n return;\n }\n delta = -currentStep;\n break;\n }\n case 'ArrowDown': {\n if (isHorizontal) {\n return;\n }\n delta = currentStep;\n break;\n }\n case 'Home': {\n delta = -(currentSizes[index] - getMin(beforePanel));\n break;\n }\n case 'End': {\n delta = getMax(beforePanel) - currentSizes[index];\n break;\n }\n case 'Enter': {\n const beforeCollapsible = beforePanel?.collapsible;\n const afterCollapsible = afterPanel?.collapsible;\n\n if (beforeCollapsible && currentSizes[index] <= currentSizes[index + 1]) {\n toggleCollapsePanel(index);\n event.preventDefault();\n return;\n }\n if (afterCollapsible) {\n toggleCollapsePanel(index + 1);\n event.preventDefault();\n return;\n }\n if (beforeCollapsible) {\n toggleCollapsePanel(index);\n event.preventDefault();\n return;\n }\n return;\n }\n default:\n return;\n }\n\n event.preventDefault();\n\n if (delta !== 0) {\n const newSizes = applyConstraints(currentSizes, panels, index, delta, redistribute);\n const beforeWas = currentSizes[index] === 0;\n const afterWas = currentSizes[index + 1] === 0;\n const beforeNow = newSizes[index] === 0;\n const afterNow = newSizes[index + 1] === 0;\n\n if (!beforeWas && beforeNow) {\n preCollapseSizesRef.current = [...currentSizes];\n onCollapseChange?.(index, true);\n } else if (beforeWas && !beforeNow) {\n onCollapseChange?.(index, false);\n }\n\n if (!afterWas && afterNow) {\n preCollapseSizesRef.current = [...currentSizes];\n onCollapseChange?.(index + 1, true);\n } else if (afterWas && !afterNow) {\n onCollapseChange?.(index + 1, false);\n }\n\n updateSizes(newSizes);\n }\n },\n 'data-active': activeHandle === index || undefined,\n 'data-orientation': orient,\n };\n },\n [\n orientation,\n currentSizes,\n panels,\n enabled,\n dir,\n step,\n shiftStep,\n activeHandle,\n redistribute,\n getHandleRefCallback,\n toggleCollapsePanel,\n updateSizes,\n onCollapseChange,\n ]\n );\n\n useEffect(\n () => () => {\n documentControllerRef.current?.abort();\n documentControllerRef.current = null;\n handleElementControllers.current.forEach((controller) => controller.abort());\n handleElementControllers.current.clear();\n cancelAnimationFrame(frameRef.current);\n\n if (internalStateRef.current.isDragging) {\n internalStateRef.current.isDragging = false;\n document.body.style.userSelect = '';\n document.body.style.webkitUserSelect = '';\n document.body.style.cursor = '';\n }\n },\n []\n );\n\n return {\n ref: containerRefCallback,\n sizes: currentSizes,\n collapsed,\n activeHandle,\n getHandleProps,\n setSizes: updateSizes,\n collapse: collapsePanel,\n expand: expandPanel,\n toggleCollapse: toggleCollapsePanel,\n };\n}\n\nexport namespace useSplitter {\n export type Panel = UseSplitterPanel;\n export type Options = UseSplitterOptions;\n export type RedistributeInput = UseSplitterRedistributeInput;\n export type RedistributeFn = UseSplitterRedistributeFn;\n export type ReturnValue<T extends HTMLElement = any> = UseSplitterReturnValue<T>;\n}\n"],"mappings":";;;;AA6FA,SAAS,MAAM,OAAe,KAAa,KAAqB;CAC9D,OAAO,KAAK,IAAI,KAAK,IAAI,OAAO,GAAG,GAAG,GAAG;AAC3C;AAEA,SAAS,OAAO,OAAiC;CAC/C,OAAO,MAAM,OAAO;AACtB;AAEA,SAAS,OAAO,OAAiC;CAC/C,OAAO,MAAM,OAAO;AACtB;AAEA,SAAS,qBAAqB,OAAiC;CAC7D,OAAO,MAAM,qBAAqB,OAAO,KAAK;AAChD;AAWA,SAAS,6BAAoD;CAC3D,OAAO;EACL,YAAY;EACZ,aAAa;EACb,cAAc;EACd,eAAe;EACf,YAAY,CAAC;EACb,kBAAkB,CAAC;CACrB;AACF;AAEA,SAAS,cACP,OACA,QACA,aACA,OACiB;CACjB,MAAM,YAAY;CAClB,MAAM,WAAW,cAAc;CAC/B,MAAM,cAAc,OAAO;CAC3B,MAAM,aAAa,OAAO;CAE1B,MAAM,YAAY,MAAM,aAAa;CACrC,MAAM,WAAW,MAAM,YAAY;CAEnC,IACE,YAAY,eACZ,YAAY,qBAAqB,WAAW,KAC5C,YAAY,MAAM,YAClB;EACA,MAAM,SAAS,CAAC,GAAG,KAAK;EACxB,OAAO,aAAa,OAAO;EAC3B,OAAO,aAAa;EACpB,OAAO;CACT;CAEA,IACE,WAAW,eACX,WAAW,qBAAqB,UAAU,KAC1C,WAAW,MAAM,WACjB;EACA,MAAM,SAAS,CAAC,GAAG,KAAK;EACxB,OAAO,cAAc,OAAO;EAC5B,OAAO,YAAY;EACnB,OAAO;CACT;CAEA,OAAO;AACT;AAEA,SAAS,kBACP,OACA,QACA,aACA,OACU;CACV,MAAM,SAAS,CAAC,GAAG,KAAK;CACxB,MAAM,YAAY;CAClB,MAAM,WAAW,cAAc;CAE/B,MAAM,QAAQ,OAAO,aAAa,OAAO;CACzC,MAAM,qBAAqB,KAAK,IAAI,OAAO,OAAO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AW,MAAM,CAAC;EAC3E,yBAAyB,QAAQ,MAAM;EACvC,qBAAqB,SAAS,OAAO;EAErC,IAAI,iBAAiB,QAAQ,YAAY;GACvC,iBAAiB,QAAQ,aAAa;GACtC,SAAS,KAAK,MAAM,aAAa;GACjC,SAAS,KAAK,MAAM,mBAAmB;GACvC,SAAS,KAAK,MAAM,SAAS;EAC/B;CACF,GACA,CAAC,CACH;CAEA,OAAO;EACL,KAAK;EACL,OAAO;EACP;EACA;EACA;EACA,UAAU;EACV,UAAU;EACV,QAAQ;EACR,gBAAgB;CAClB;AACF"}
1
+ {"version":3,"file":"use-splitter.cjs","names":["useUncontrolled"],"sources":["../../src/use-splitter/use-splitter.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-deprecated */\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { useUncontrolled } from '../use-uncontrolled/use-uncontrolled';\n\nexport interface UseSplitterPanel {\n /** Initial size as percentage (0-100). All panels must sum to 100. */\n defaultSize: number;\n /** Minimum size percentage, `0` by default */\n min?: number;\n /** Maximum size percentage, `100` by default */\n max?: number;\n /** Whether this panel can be collapsed, `false` by default */\n collapsible?: boolean;\n /** Size below which the panel snaps to collapsed (percentage), defaults to `min` */\n collapseThreshold?: number;\n}\n\nexport interface UseSplitterRedistributeInput {\n /** Current sizes before applying delta */\n sizes: number[];\n /** Panel configurations */\n panels: UseSplitterPanel[];\n /** Index of the handle being dragged */\n handleIndex: number;\n /** Requested size change in percentage (positive = grow before-panel) */\n delta: number;\n}\n\nexport type UseSplitterRedistributeFn = (input: UseSplitterRedistributeInput) => number[];\n\nexport interface UseSplitterOptions {\n /** Panel configuration array (minimum 2 panels) */\n panels: UseSplitterPanel[];\n /** Layout direction, `'horizontal'` by default */\n orientation?: 'horizontal' | 'vertical';\n /** Controlled sizes (percentages summing to 100) */\n sizes?: number[];\n /** Called during resize with updated sizes */\n onSizeChange?: (sizes: number[]) => void;\n /** Called when drag starts */\n onResizeStart?: (handleIndex: number) => void;\n /** Called when drag ends */\n onResizeEnd?: (handleIndex: number, sizes: number[]) => void;\n /** Called when a panel collapses or expands */\n onCollapseChange?: (panelIndex: number, collapsed: boolean) => void;\n /** How to borrow space from non-adjacent panels when the immediate neighbor is at its min/max.\n * `'nearest'` takes from the nearest panel in the drag direction first.\n * `'equal'` distributes equally among all panels in the drag direction.\n * A function receives sizes, panels, handleIndex and delta, and returns new sizes.\n * When not set, only the two adjacent panels are affected. */\n redistribute?: 'nearest' | 'equal' | UseSplitterRedistributeFn;\n /** Keyboard step size in percentage, `1` by default */\n step?: number;\n /** Shift+arrow step size in percentage, `10` by default */\n shiftStep?: number;\n /** Text direction for keyboard nav, `'ltr'` by default */\n dir?: 'ltr' | 'rtl';\n /** Restore the two panels adjacent to a handle to their default ratio (preserving their combined size) when the handle is double-clicked, `true` by default */\n resetOnDoubleClick?: boolean;\n /** Enable/disable the hook, `true` by default */\n enabled?: boolean;\n}\n\nexport interface UseSplitterReturnValue<T extends HTMLElement = any> {\n /** Ref callback for the container element */\n ref: React.RefCallback<T | null>;\n /** Current panel sizes as percentages */\n sizes: number[];\n /** Which panels are currently collapsed */\n collapsed: boolean[];\n /** Index of handle being dragged, or -1 */\n activeHandle: number;\n /** Get props to spread on each resize handle */\n getHandleProps: (input: { index: number }) => {\n ref: React.RefCallback<HTMLElement>;\n role: 'separator';\n 'aria-orientation': 'horizontal' | 'vertical';\n 'aria-valuenow': number;\n 'aria-valuemin': number;\n 'aria-valuemax': number;\n tabIndex: number;\n onKeyDown: React.KeyboardEventHandler;\n onDoubleClick: React.MouseEventHandler;\n 'data-active': boolean | undefined;\n 'data-orientation': 'horizontal' | 'vertical';\n };\n /** Programmatically set sizes */\n setSizes: (sizes: number[]) => void;\n /** Collapse a panel */\n collapse: (panelIndex: number) => void;\n /** Expand a collapsed panel */\n expand: (panelIndex: number) => void;\n /** Toggle collapse of a panel */\n toggleCollapse: (panelIndex: number) => void;\n /** Reset the two panels adjacent to a handle to their default ratio, preserving\n * their combined size */\n reset: (handleIndex: number) => void;\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\nfunction getMin(panel: UseSplitterPanel): number {\n return panel.min ?? 0;\n}\n\nfunction getMax(panel: UseSplitterPanel): number {\n return panel.max ?? 100;\n}\n\nfunction getCollapseThreshold(panel: UseSplitterPanel): number {\n return panel.collapseThreshold ?? getMin(panel);\n}\n\ninterface SplitterInternalState {\n isDragging: boolean;\n handleIndex: number;\n startPointer: number;\n containerSize: number;\n startSizes: number[];\n preCollapseSizes: number[];\n}\n\nfunction createInitialInternalState(): SplitterInternalState {\n return {\n isDragging: false,\n handleIndex: -1,\n startPointer: 0,\n containerSize: 0,\n startSizes: [],\n preCollapseSizes: [],\n };\n}\n\nfunction checkCollapse(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] | null {\n const beforeIdx = handleIndex;\n const afterIdx = handleIndex + 1;\n const beforePanel = panels[beforeIdx];\n const afterPanel = panels[afterIdx];\n\n const rawBefore = sizes[beforeIdx] + delta;\n const rawAfter = sizes[afterIdx] - delta;\n\n if (\n beforePanel.collapsible &&\n rawBefore < getCollapseThreshold(beforePanel) &&\n rawBefore < sizes[beforeIdx]\n ) {\n const result = [...sizes];\n result[afterIdx] += result[beforeIdx];\n result[beforeIdx] = 0;\n return result;\n }\n\n if (\n afterPanel.collapsible &&\n rawAfter < getCollapseThreshold(afterPanel) &&\n rawAfter < sizes[afterIdx]\n ) {\n const result = [...sizes];\n result[beforeIdx] += result[afterIdx];\n result[afterIdx] = 0;\n return result;\n }\n\n return null;\n}\n\nfunction applyAdjacentOnly(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] {\n const result = [...sizes];\n const beforeIdx = handleIndex;\n const afterIdx = handleIndex + 1;\n\n const total = result[beforeIdx] + result[afterIdx];\n const effectiveBeforeMax = Math.min(getMax(panels[beforeIdx]), total - getMin(panels[afterIdx]));\n const effectiveBeforeMin = Math.max(getMin(panels[beforeIdx]), total - getMax(panels[afterIdx]));\n const newBefore = clamp(result[beforeIdx] + delta, effectiveBeforeMin, effectiveBeforeMax);\n result[beforeIdx] = newBefore;\n result[afterIdx] = total - newBefore;\n return result;\n}\n\nfunction redistributeNearest(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] {\n const result = [...sizes];\n\n if (delta > 0) {\n const growIdx = handleIndex;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(delta, maxGrow);\n\n let taken = 0;\n for (let i = handleIndex + 1; i < result.length && taken < wantedGrow; i += 1) {\n const canGive = result[i] - getMin(panels[i]);\n const take = Math.min(canGive, wantedGrow - taken);\n result[i] -= take;\n taken += take;\n }\n\n result[growIdx] += taken;\n } else if (delta < 0) {\n const growIdx = handleIndex + 1;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(Math.abs(delta), maxGrow);\n\n let taken = 0;\n for (let i = handleIndex; i >= 0 && taken < wantedGrow; i -= 1) {\n const canGive = result[i] - getMin(panels[i]);\n const take = Math.min(canGive, wantedGrow - taken);\n result[i] -= take;\n taken += take;\n }\n\n result[growIdx] += taken;\n }\n\n return result;\n}\n\nfunction redistributeEqual(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] {\n const result = [...sizes];\n\n if (delta > 0) {\n const growIdx = handleIndex;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(delta, maxGrow);\n\n const donors: number[] = [];\n for (let i = handleIndex + 1; i < result.length; i += 1) {\n if (result[i] > getMin(panels[i])) {\n donors.push(i);\n }\n }\n\n let remaining = wantedGrow;\n while (remaining > 0.001 && donors.length > 0) {\n const perDonor = remaining / donors.length;\n const exhausted: number[] = [];\n\n for (let d = 0; d < donors.length; d += 1) {\n const idx = donors[d];\n const canGive = result[idx] - getMin(panels[idx]);\n const take = Math.min(canGive, perDonor);\n result[idx] -= take;\n remaining -= take;\n if (canGive <= perDonor + 0.001) {\n exhausted.push(d);\n }\n }\n\n for (let i = exhausted.length - 1; i >= 0; i -= 1) {\n donors.splice(exhausted[i], 1);\n }\n\n if (exhausted.length === 0) {\n break;\n }\n }\n\n result[growIdx] += wantedGrow - remaining;\n } else if (delta < 0) {\n const growIdx = handleIndex + 1;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(Math.abs(delta), maxGrow);\n\n const donors: number[] = [];\n for (let i = handleIndex; i >= 0; i -= 1) {\n if (result[i] > getMin(panels[i])) {\n donors.push(i);\n }\n }\n\n let remaining = wantedGrow;\n while (remaining > 0.001 && donors.length > 0) {\n const perDonor = remaining / donors.length;\n const exhausted: number[] = [];\n\n for (let d = 0; d < donors.length; d += 1) {\n const idx = donors[d];\n const canGive = result[idx] - getMin(panels[idx]);\n const take = Math.min(canGive, perDonor);\n result[idx] -= take;\n remaining -= take;\n if (canGive <= perDonor + 0.001) {\n exhausted.push(d);\n }\n }\n\n for (let i = exhausted.length - 1; i >= 0; i -= 1) {\n donors.splice(exhausted[i], 1);\n }\n\n if (exhausted.length === 0) {\n break;\n }\n }\n\n result[growIdx] += wantedGrow - remaining;\n }\n\n return result;\n}\n\nfunction applyConstraints(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number,\n redistribute?: 'nearest' | 'equal' | UseSplitterRedistributeFn\n): number[] {\n if (typeof redistribute === 'function') {\n return redistribute({ sizes: [...sizes], panels, handleIndex, delta });\n }\n\n if (redistribute === 'nearest' || redistribute === 'equal') {\n const strategy = redistribute === 'nearest' ? redistributeNearest : redistributeEqual;\n const result = strategy(sizes, panels, handleIndex, delta);\n\n const beforeIdx = handleIndex;\n const afterIdx = handleIndex + 1;\n const beforePanel = panels[beforeIdx];\n const afterPanel = panels[afterIdx];\n\n if (\n beforePanel.collapsible &&\n result[beforeIdx] < getCollapseThreshold(beforePanel) &&\n result[beforeIdx] < sizes[beforeIdx]\n ) {\n const freed = result[beforeIdx];\n result[afterIdx] += freed;\n result[beforeIdx] = 0;\n } else if (\n afterPanel.collapsible &&\n result[afterIdx] < getCollapseThreshold(afterPanel) &&\n result[afterIdx] < sizes[afterIdx]\n ) {\n const freed = result[afterIdx];\n result[beforeIdx] += freed;\n result[afterIdx] = 0;\n }\n\n return result;\n }\n\n const collapsed = checkCollapse(sizes, panels, handleIndex, delta);\n if (collapsed) {\n return collapsed;\n }\n\n return applyAdjacentOnly(sizes, panels, handleIndex, delta);\n}\n\nexport function useSplitter<T extends HTMLElement = any>(\n options: UseSplitterOptions\n): UseSplitterReturnValue<T> {\n const {\n panels,\n orientation = 'horizontal',\n sizes: controlledSizes,\n onSizeChange,\n onCollapseChange,\n redistribute,\n step = 1,\n shiftStep = 10,\n dir = 'ltr',\n resetOnDoubleClick = true,\n enabled = true,\n } = options;\n\n const defaultSizes = panels.map((p) => p.defaultSize);\n\n const [currentSizes, setCurrentSizes] = useUncontrolled({\n value: controlledSizes,\n defaultValue: defaultSizes,\n finalValue: defaultSizes,\n onChange: onSizeChange,\n });\n\n const [activeHandle, setActiveHandle] = useState(-1);\n\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n const internalStateRef = useRef<SplitterInternalState>(createInitialInternalState());\n const containerRef = useRef<T | null>(null);\n const documentControllerRef = useRef<AbortController | null>(null);\n const frameRef = useRef(0);\n const currentSizesRef = useRef(currentSizes);\n currentSizesRef.current = currentSizes;\n\n const preCollapseSizesRef = useRef<number[]>(defaultSizes);\n\n const collapsed = currentSizes.map((size) => size === 0);\n\n const updateSizes = useCallback(\n (newSizes: number[]) => {\n currentSizesRef.current = newSizes;\n setCurrentSizes(newSizes);\n },\n [setCurrentSizes]\n );\n\n const collapsePanel = useCallback(\n (panelIndex: number) => {\n if (!panels[panelIndex]?.collapsible) {\n return;\n }\n const sizes = currentSizesRef.current;\n if (sizes[panelIndex] === 0) {\n return;\n }\n\n preCollapseSizesRef.current = [...sizes];\n const newSizes = [...sizes];\n const freedSize = newSizes[panelIndex];\n newSizes[panelIndex] = 0;\n\n const neighbor = panelIndex === 0 ? 1 : panelIndex - 1;\n newSizes[neighbor] += freedSize;\n\n updateSizes(newSizes);\n onCollapseChange?.(panelIndex, true);\n },\n [panels, updateSizes, onCollapseChange]\n );\n\n const expandPanel = useCallback(\n (panelIndex: number) => {\n if (!panels[panelIndex]?.collapsible) {\n return;\n }\n const sizes = currentSizesRef.current;\n if (sizes[panelIndex] !== 0) {\n return;\n }\n\n const preCollapse = preCollapseSizesRef.current;\n const restoreSize = preCollapse[panelIndex] || panels[panelIndex].defaultSize;\n const newSizes = [...sizes];\n\n const neighbor = panelIndex === 0 ? 1 : panelIndex - 1;\n const available = Math.max(0, newSizes[neighbor] - getMin(panels[neighbor]));\n const actualRestore = Math.min(restoreSize, available);\n\n if (actualRestore <= 0) {\n return;\n }\n\n newSizes[panelIndex] = actualRestore;\n newSizes[neighbor] -= actualRestore;\n\n updateSizes(newSizes);\n onCollapseChange?.(panelIndex, false);\n },\n [panels, updateSizes, onCollapseChange]\n );\n\n const toggleCollapsePanel = useCallback(\n (panelIndex: number) => {\n if (currentSizesRef.current[panelIndex] === 0) {\n expandPanel(panelIndex);\n } else {\n collapsePanel(panelIndex);\n }\n },\n [collapsePanel, expandPanel]\n );\n\n const emitCollapseTransitions = useCallback(\n (prev: number[], next: number[], indices: number[], preCollapseSnapshot: number[]) => {\n const onChange = optionsRef.current.onCollapseChange;\n for (const idx of indices) {\n const wasCollapsed = prev[idx] === 0;\n const nowCollapsed = next[idx] === 0;\n if (!wasCollapsed && nowCollapsed) {\n preCollapseSizesRef.current = [...preCollapseSnapshot];\n onChange?.(idx, true);\n } else if (wasCollapsed && !nowCollapsed) {\n onChange?.(idx, false);\n }\n }\n },\n []\n );\n\n const reset = useCallback(\n (handleIndex: number) => {\n const prev = currentSizesRef.current;\n const currentPanels = optionsRef.current.panels;\n\n const beforeIdx = handleIndex;\n const afterIdx = handleIndex + 1;\n if (beforeIdx < 0 || afterIdx >= prev.length) {\n return;\n }\n\n const total = prev[beforeIdx] + prev[afterIdx];\n const defBefore = currentPanels[beforeIdx].defaultSize;\n const defAfter = currentPanels[afterIdx].defaultSize;\n const defTotal = defBefore + defAfter;\n const targetBefore = defTotal === 0 ? total / 2 : total * (defBefore / defTotal);\n\n const next = applyAdjacentOnly(\n prev,\n currentPanels,\n beforeIdx,\n targetBefore - prev[beforeIdx]\n );\n emitCollapseTransitions(prev, next, [beforeIdx, afterIdx], prev);\n updateSizes(next);\n },\n [emitCollapseTransitions, updateSizes]\n );\n\n const containerRefCallback: React.RefCallback<T | null> = useCallback((node) => {\n containerRef.current = node;\n }, []);\n\n const handleRefCallbacks = useRef<Map<number, (node: HTMLElement | null) => void>>(new Map());\n const handleElementControllers = useRef<Map<number, AbortController>>(new Map());\n\n const getHandleRefCallback = useCallback(\n (handleIndex: number): React.RefCallback<HTMLElement> => {\n if (handleRefCallbacks.current.has(handleIndex)) {\n return handleRefCallbacks.current.get(handleIndex)!;\n }\n\n const callback = (node: HTMLElement | null) => {\n const existingController = handleElementControllers.current.get(handleIndex);\n if (existingController) {\n existingController.abort();\n handleElementControllers.current.delete(handleIndex);\n }\n\n if (!node) {\n return;\n }\n\n const elementController = new AbortController();\n handleElementControllers.current.set(handleIndex, elementController);\n\n const onPointerDown = (event: PointerEvent) => {\n if (optionsRef.current.enabled === false) {\n return;\n }\n if (event.button !== 0) {\n return;\n }\n\n const container = containerRef.current;\n if (!container) {\n return;\n }\n\n const rect = container.getBoundingClientRect();\n const isHorizontal = (optionsRef.current.orientation ?? 'horizontal') === 'horizontal';\n const containerSize = isHorizontal ? rect.width : rect.height;\n const pointerPos = isHorizontal ? event.clientX : event.clientY;\n\n const s = internalStateRef.current;\n s.isDragging = true;\n s.handleIndex = handleIndex;\n s.startPointer = pointerPos;\n s.containerSize = containerSize;\n s.startSizes = [...currentSizesRef.current];\n s.preCollapseSizes = [...preCollapseSizesRef.current];\n\n setActiveHandle(handleIndex);\n document.body.style.userSelect = 'none';\n document.body.style.webkitUserSelect = 'none';\n document.body.style.cursor = isHorizontal ? 'col-resize' : 'row-resize';\n\n optionsRef.current.onResizeStart?.(handleIndex);\n\n documentControllerRef.current?.abort();\n documentControllerRef.current = new AbortController();\n const sig = documentControllerRef.current.signal;\n\n document.addEventListener('pointermove', onPointerMove, { signal: sig });\n document.addEventListener('pointerup', onPointerUp, { signal: sig });\n document.addEventListener('pointercancel', onPointerUp, { signal: sig });\n };\n\n const flushResize = (pointerEvent: PointerEvent) => {\n const s = internalStateRef.current;\n if (!s.containerSize) {\n return;\n }\n const isHorizontal = (optionsRef.current.orientation ?? 'horizontal') === 'horizontal';\n const isRtl = isHorizontal && optionsRef.current.dir === 'rtl';\n const pointerPos = isHorizontal ? pointerEvent.clientX : pointerEvent.clientY;\n const pixelDelta = pointerPos - s.startPointer;\n const percentDelta = ((isRtl ? -pixelDelta : pixelDelta) / s.containerSize) * 100;\n\n const opts = optionsRef.current;\n const newSizes = applyConstraints(\n s.startSizes,\n opts.panels,\n s.handleIndex,\n percentDelta,\n opts.redistribute\n );\n\n const prevSizes = currentSizesRef.current;\n emitCollapseTransitions(\n prevSizes,\n newSizes,\n [s.handleIndex, s.handleIndex + 1],\n s.startSizes\n );\n\n currentSizesRef.current = newSizes;\n setCurrentSizes(newSizes);\n };\n\n const onPointerMove = (event: PointerEvent) => {\n const s = internalStateRef.current;\n if (!s.isDragging) {\n return;\n }\n\n cancelAnimationFrame(frameRef.current);\n frameRef.current = requestAnimationFrame(() => {\n flushResize(event);\n });\n };\n\n const onPointerUp = (event: PointerEvent) => {\n const s = internalStateRef.current;\n if (!s.isDragging) {\n return;\n }\n\n cancelAnimationFrame(frameRef.current);\n flushResize(event);\n\n s.isDragging = false;\n const finishedHandle = s.handleIndex;\n s.handleIndex = -1;\n\n setActiveHandle(-1);\n document.body.style.userSelect = '';\n document.body.style.webkitUserSelect = '';\n document.body.style.cursor = '';\n\n documentControllerRef.current?.abort();\n documentControllerRef.current = null;\n\n optionsRef.current.onResizeEnd?.(finishedHandle, [...currentSizesRef.current]);\n };\n\n node.addEventListener('pointerdown', onPointerDown, {\n signal: elementController.signal,\n });\n };\n\n handleRefCallbacks.current.set(handleIndex, callback);\n return callback;\n },\n [setCurrentSizes]\n );\n\n const getHandleProps = useCallback(\n (input: { index: number }) => {\n const { index } = input;\n const orient = orientation;\n const beforeSize = currentSizes[index] ?? 0;\n const beforePanel = panels[index];\n const afterPanel = panels[index + 1];\n\n return {\n ref: getHandleRefCallback(index),\n role: 'separator' as const,\n 'aria-orientation': orient,\n 'aria-valuenow': Math.round(beforeSize),\n 'aria-valuemin': Math.round(getMin(beforePanel)),\n 'aria-valuemax': Math.round(getMax(beforePanel)),\n tabIndex: 0,\n onKeyDown: (event: React.KeyboardEvent) => {\n if (!enabled) {\n return;\n }\n\n const isHorizontal = orient === 'horizontal';\n const isRtl = dir === 'rtl';\n\n let delta = 0;\n const currentStep = event.shiftKey ? shiftStep : step;\n\n switch (event.key) {\n case 'ArrowLeft': {\n if (!isHorizontal) {\n return;\n }\n delta = isRtl ? currentStep : -currentStep;\n break;\n }\n case 'ArrowRight': {\n if (!isHorizontal) {\n return;\n }\n delta = isRtl ? -currentStep : currentStep;\n break;\n }\n case 'ArrowUp': {\n if (isHorizontal) {\n return;\n }\n delta = -currentStep;\n break;\n }\n case 'ArrowDown': {\n if (isHorizontal) {\n return;\n }\n delta = currentStep;\n break;\n }\n case 'Home': {\n delta = -(currentSizes[index] - getMin(beforePanel));\n break;\n }\n case 'End': {\n delta = getMax(beforePanel) - currentSizes[index];\n break;\n }\n case 'Enter': {\n const beforeCollapsible = beforePanel?.collapsible;\n const afterCollapsible = afterPanel?.collapsible;\n\n if (beforeCollapsible && currentSizes[index] <= currentSizes[index + 1]) {\n toggleCollapsePanel(index);\n event.preventDefault();\n return;\n }\n if (afterCollapsible) {\n toggleCollapsePanel(index + 1);\n event.preventDefault();\n return;\n }\n if (beforeCollapsible) {\n toggleCollapsePanel(index);\n event.preventDefault();\n return;\n }\n return;\n }\n default:\n return;\n }\n\n event.preventDefault();\n\n if (delta !== 0) {\n const newSizes = applyConstraints(currentSizes, panels, index, delta, redistribute);\n emitCollapseTransitions(currentSizes, newSizes, [index, index + 1], currentSizes);\n updateSizes(newSizes);\n }\n },\n onDoubleClick: () => {\n if (!enabled || !resetOnDoubleClick) {\n return;\n }\n reset(index);\n },\n 'data-active': activeHandle === index || undefined,\n 'data-orientation': orient,\n };\n },\n [\n orientation,\n currentSizes,\n panels,\n enabled,\n dir,\n step,\n shiftStep,\n resetOnDoubleClick,\n activeHandle,\n redistribute,\n getHandleRefCallback,\n toggleCollapsePanel,\n updateSizes,\n emitCollapseTransitions,\n reset,\n ]\n );\n\n useEffect(\n () => () => {\n documentControllerRef.current?.abort();\n documentControllerRef.current = null;\n handleElementControllers.current.forEach((controller) => controller.abort());\n handleElementControllers.current.clear();\n cancelAnimationFrame(frameRef.current);\n\n if (internalStateRef.current.isDragging) {\n internalStateRef.current.isDragging = false;\n document.body.style.userSelect = '';\n document.body.style.webkitUserSelect = '';\n document.body.style.cursor = '';\n }\n },\n []\n );\n\n return {\n ref: containerRefCallback,\n sizes: currentSizes,\n collapsed,\n activeHandle,\n getHandleProps,\n setSizes: updateSizes,\n collapse: collapsePanel,\n expand: expandPanel,\n toggleCollapse: toggleCollapsePanel,\n reset,\n };\n}\n\nexport namespace useSplitter {\n export type Panel = UseSplitterPanel;\n export type Options = UseSplitterOptions;\n export type RedistributeInput = UseSplitterRedistributeInput;\n export type RedistributeFn = UseSplitterRedistributeFn;\n export type ReturnValue<T extends HTMLElement = any> = UseSplitterReturnValue<T>;\n}\n"],"mappings":";;;;AAmGA,SAAS,MAAM,OAAe,KAAa,KAAqB;CAC9D,OAAO,KAAK,IAAI,KAAK,IAAI,OAAO,GAAG,GAAG,GAAG;AAC3C;AAEA,SAAS,OAAO,OAAiC;CAC/C,OAAO,MAAM,OAAO;AACtB;AAEA,SAAS,OAAO,OAAi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;GACvC,SAAS,KAAK,MAAM,SAAS;EAC/B;CACF,GACA,CAAC,CACH;CAEA,OAAO;EACL,KAAK;EACL,OAAO;EACP;EACA;EACA;EACA,UAAU;EACV,UAAU;EACV,QAAQ;EACR,gBAAgB;EAChB;CACF;AACF"}
@@ -164,7 +164,7 @@ function applyConstraints(sizes, panels, handleIndex, delta, redistribute) {
164
164
  return applyAdjacentOnly(sizes, panels, handleIndex, delta);
165
165
  }
166
166
  function useSplitter(options) {
167
- const { panels, orientation = "horizontal", sizes: controlledSizes, onSizeChange, onCollapseChange, redistribute, step = 1, shiftStep = 10, dir = "ltr", enabled = true } = options;
167
+ const { panels, orientation = "horizontal", sizes: controlledSizes, onSizeChange, onCollapseChange, redistribute, step = 1, shiftStep = 10, dir = "ltr", resetOnDoubleClick = true, enabled = true } = options;
168
168
  const defaultSizes = panels.map((p) => p.defaultSize);
169
169
  const [currentSizes, setCurrentSizes] = useUncontrolled({
170
170
  value: controlledSizes,
@@ -227,6 +227,30 @@ function useSplitter(options) {
227
227
  if (currentSizesRef.current[panelIndex] === 0) expandPanel(panelIndex);
228
228
  else collapsePanel(panelIndex);
229
229
  }, [collapsePanel, expandPanel]);
230
+ const emitCollapseTransitions = useCallback((prev, next, indices, preCollapseSnapshot) => {
231
+ const onChange = optionsRef.current.onCollapseChange;
232
+ for (const idx of indices) {
233
+ const wasCollapsed = prev[idx] === 0;
234
+ const nowCollapsed = next[idx] === 0;
235
+ if (!wasCollapsed && nowCollapsed) {
236
+ preCollapseSizesRef.current = [...preCollapseSnapshot];
237
+ onChange?.(idx, true);
238
+ } else if (wasCollapsed && !nowCollapsed) onChange?.(idx, false);
239
+ }
240
+ }, []);
241
+ const reset = useCallback((handleIndex) => {
242
+ const prev = currentSizesRef.current;
243
+ const currentPanels = optionsRef.current.panels;
244
+ const beforeIdx = handleIndex;
245
+ const afterIdx = handleIndex + 1;
246
+ if (beforeIdx < 0 || afterIdx >= prev.length) return;
247
+ const total = prev[beforeIdx] + prev[afterIdx];
248
+ const defBefore = currentPanels[beforeIdx].defaultSize;
249
+ const defTotal = defBefore + currentPanels[afterIdx].defaultSize;
250
+ const next = applyAdjacentOnly(prev, currentPanels, beforeIdx, (defTotal === 0 ? total / 2 : total * (defBefore / defTotal)) - prev[beforeIdx]);
251
+ emitCollapseTransitions(prev, next, [beforeIdx, afterIdx], prev);
252
+ updateSizes(next);
253
+ }, [emitCollapseTransitions, updateSizes]);
230
254
  const containerRefCallback = useCallback((node) => {
231
255
  containerRef.current = node;
232
256
  }, []);
@@ -281,18 +305,7 @@ function useSplitter(options) {
281
305
  const opts = optionsRef.current;
282
306
  const newSizes = applyConstraints(s.startSizes, opts.panels, s.handleIndex, percentDelta, opts.redistribute);
283
307
  const prevSizes = currentSizesRef.current;
284
- const beforeWasCollapsed = prevSizes[s.handleIndex] === 0;
285
- const afterWasCollapsed = prevSizes[s.handleIndex + 1] === 0;
286
- const beforeNowCollapsed = newSizes[s.handleIndex] === 0;
287
- const afterNowCollapsed = newSizes[s.handleIndex + 1] === 0;
288
- if (!beforeWasCollapsed && beforeNowCollapsed) {
289
- preCollapseSizesRef.current = [...s.startSizes];
290
- opts.onCollapseChange?.(s.handleIndex, true);
291
- } else if (beforeWasCollapsed && !beforeNowCollapsed) opts.onCollapseChange?.(s.handleIndex, false);
292
- if (!afterWasCollapsed && afterNowCollapsed) {
293
- preCollapseSizesRef.current = [...s.startSizes];
294
- opts.onCollapseChange?.(s.handleIndex + 1, true);
295
- } else if (afterWasCollapsed && !afterNowCollapsed) opts.onCollapseChange?.(s.handleIndex + 1, false);
308
+ emitCollapseTransitions(prevSizes, newSizes, [s.handleIndex, s.handleIndex + 1], s.startSizes);
296
309
  currentSizesRef.current = newSizes;
297
310
  setCurrentSizes(newSizes);
298
311
  };
@@ -392,21 +405,14 @@ function useSplitter(options) {
392
405
  event.preventDefault();
393
406
  if (delta !== 0) {
394
407
  const newSizes = applyConstraints(currentSizes, panels, index, delta, redistribute);
395
- const beforeWas = currentSizes[index] === 0;
396
- const afterWas = currentSizes[index + 1] === 0;
397
- const beforeNow = newSizes[index] === 0;
398
- const afterNow = newSizes[index + 1] === 0;
399
- if (!beforeWas && beforeNow) {
400
- preCollapseSizesRef.current = [...currentSizes];
401
- onCollapseChange?.(index, true);
402
- } else if (beforeWas && !beforeNow) onCollapseChange?.(index, false);
403
- if (!afterWas && afterNow) {
404
- preCollapseSizesRef.current = [...currentSizes];
405
- onCollapseChange?.(index + 1, true);
406
- } else if (afterWas && !afterNow) onCollapseChange?.(index + 1, false);
408
+ emitCollapseTransitions(currentSizes, newSizes, [index, index + 1], currentSizes);
407
409
  updateSizes(newSizes);
408
410
  }
409
411
  },
412
+ onDoubleClick: () => {
413
+ if (!enabled || !resetOnDoubleClick) return;
414
+ reset(index);
415
+ },
410
416
  "data-active": activeHandle === index || void 0,
411
417
  "data-orientation": orient
412
418
  };
@@ -418,12 +424,14 @@ function useSplitter(options) {
418
424
  dir,
419
425
  step,
420
426
  shiftStep,
427
+ resetOnDoubleClick,
421
428
  activeHandle,
422
429
  redistribute,
423
430
  getHandleRefCallback,
424
431
  toggleCollapsePanel,
425
432
  updateSizes,
426
- onCollapseChange
433
+ emitCollapseTransitions,
434
+ reset
427
435
  ]);
428
436
  useEffect(() => () => {
429
437
  documentControllerRef.current?.abort();
@@ -447,7 +455,8 @@ function useSplitter(options) {
447
455
  setSizes: updateSizes,
448
456
  collapse: collapsePanel,
449
457
  expand: expandPanel,
450
- toggleCollapse: toggleCollapsePanel
458
+ toggleCollapse: toggleCollapsePanel,
459
+ reset
451
460
  };
452
461
  }
453
462
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"use-splitter.mjs","names":[],"sources":["../../src/use-splitter/use-splitter.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-deprecated */\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { useUncontrolled } from '../use-uncontrolled/use-uncontrolled';\n\nexport interface UseSplitterPanel {\n /** Initial size as percentage (0-100). All panels must sum to 100. */\n defaultSize: number;\n /** Minimum size percentage, `0` by default */\n min?: number;\n /** Maximum size percentage, `100` by default */\n max?: number;\n /** Whether this panel can be collapsed, `false` by default */\n collapsible?: boolean;\n /** Size below which the panel snaps to collapsed (percentage), defaults to `min` */\n collapseThreshold?: number;\n}\n\nexport interface UseSplitterRedistributeInput {\n /** Current sizes before applying delta */\n sizes: number[];\n /** Panel configurations */\n panels: UseSplitterPanel[];\n /** Index of the handle being dragged */\n handleIndex: number;\n /** Requested size change in percentage (positive = grow before-panel) */\n delta: number;\n}\n\nexport type UseSplitterRedistributeFn = (input: UseSplitterRedistributeInput) => number[];\n\nexport interface UseSplitterOptions {\n /** Panel configuration array (minimum 2 panels) */\n panels: UseSplitterPanel[];\n /** Layout direction, `'horizontal'` by default */\n orientation?: 'horizontal' | 'vertical';\n /** Controlled sizes (percentages summing to 100) */\n sizes?: number[];\n /** Called during resize with updated sizes */\n onSizeChange?: (sizes: number[]) => void;\n /** Called when drag starts */\n onResizeStart?: (handleIndex: number) => void;\n /** Called when drag ends */\n onResizeEnd?: (handleIndex: number, sizes: number[]) => void;\n /** Called when a panel collapses or expands */\n onCollapseChange?: (panelIndex: number, collapsed: boolean) => void;\n /** How to borrow space from non-adjacent panels when the immediate neighbor is at its min/max.\n * `'nearest'` takes from the nearest panel in the drag direction first.\n * `'equal'` distributes equally among all panels in the drag direction.\n * A function receives sizes, panels, handleIndex and delta, and returns new sizes.\n * When not set, only the two adjacent panels are affected. */\n redistribute?: 'nearest' | 'equal' | UseSplitterRedistributeFn;\n /** Keyboard step size in percentage, `1` by default */\n step?: number;\n /** Shift+arrow step size in percentage, `10` by default */\n shiftStep?: number;\n /** Text direction for keyboard nav, `'ltr'` by default */\n dir?: 'ltr' | 'rtl';\n /** Enable/disable the hook, `true` by default */\n enabled?: boolean;\n}\n\nexport interface UseSplitterReturnValue<T extends HTMLElement = any> {\n /** Ref callback for the container element */\n ref: React.RefCallback<T | null>;\n /** Current panel sizes as percentages */\n sizes: number[];\n /** Which panels are currently collapsed */\n collapsed: boolean[];\n /** Index of handle being dragged, or -1 */\n activeHandle: number;\n /** Get props to spread on each resize handle */\n getHandleProps: (input: { index: number }) => {\n ref: React.RefCallback<HTMLElement>;\n role: 'separator';\n 'aria-orientation': 'horizontal' | 'vertical';\n 'aria-valuenow': number;\n 'aria-valuemin': number;\n 'aria-valuemax': number;\n tabIndex: number;\n onKeyDown: React.KeyboardEventHandler;\n 'data-active': boolean | undefined;\n 'data-orientation': 'horizontal' | 'vertical';\n };\n /** Programmatically set sizes */\n setSizes: (sizes: number[]) => void;\n /** Collapse a panel */\n collapse: (panelIndex: number) => void;\n /** Expand a collapsed panel */\n expand: (panelIndex: number) => void;\n /** Toggle collapse of a panel */\n toggleCollapse: (panelIndex: number) => void;\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\nfunction getMin(panel: UseSplitterPanel): number {\n return panel.min ?? 0;\n}\n\nfunction getMax(panel: UseSplitterPanel): number {\n return panel.max ?? 100;\n}\n\nfunction getCollapseThreshold(panel: UseSplitterPanel): number {\n return panel.collapseThreshold ?? getMin(panel);\n}\n\ninterface SplitterInternalState {\n isDragging: boolean;\n handleIndex: number;\n startPointer: number;\n containerSize: number;\n startSizes: number[];\n preCollapseSizes: number[];\n}\n\nfunction createInitialInternalState(): SplitterInternalState {\n return {\n isDragging: false,\n handleIndex: -1,\n startPointer: 0,\n containerSize: 0,\n startSizes: [],\n preCollapseSizes: [],\n };\n}\n\nfunction checkCollapse(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] | null {\n const beforeIdx = handleIndex;\n const afterIdx = handleIndex + 1;\n const beforePanel = panels[beforeIdx];\n const afterPanel = panels[afterIdx];\n\n const rawBefore = sizes[beforeIdx] + delta;\n const rawAfter = sizes[afterIdx] - delta;\n\n if (\n beforePanel.collapsible &&\n rawBefore < getCollapseThreshold(beforePanel) &&\n rawBefore < sizes[beforeIdx]\n ) {\n const result = [...sizes];\n result[afterIdx] += result[beforeIdx];\n result[beforeIdx] = 0;\n return result;\n }\n\n if (\n afterPanel.collapsible &&\n rawAfter < getCollapseThreshold(afterPanel) &&\n rawAfter < sizes[afterIdx]\n ) {\n const result = [...sizes];\n result[beforeIdx] += result[afterIdx];\n result[afterIdx] = 0;\n return result;\n }\n\n return null;\n}\n\nfunction applyAdjacentOnly(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] {\n const result = [...sizes];\n const beforeIdx = handleIndex;\n const afterIdx = handleIndex + 1;\n\n const total = result[beforeIdx] + result[afterIdx];\n const effectiveBeforeMax = Math.min(getMax(panels[beforeIdx]), total - getMin(panels[afterIdx]));\n const effectiveBeforeMin = Math.max(getMin(panels[beforeIdx]), total - getMax(panels[afterIdx]));\n const newBefore = clamp(result[beforeIdx] + delta, effectiveBeforeMin, effectiveBeforeMax);\n result[beforeIdx] = newBefore;\n result[afterIdx] = total - newBefore;\n return result;\n}\n\nfunction redistributeNearest(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] {\n const result = [...sizes];\n\n if (delta > 0) {\n const growIdx = handleIndex;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(delta, maxGrow);\n\n let taken = 0;\n for (let i = handleIndex + 1; i < result.length && taken < wantedGrow; i += 1) {\n const canGive = result[i] - getMin(panels[i]);\n const take = Math.min(canGive, wantedGrow - taken);\n result[i] -= take;\n taken += take;\n }\n\n result[growIdx] += taken;\n } else if (delta < 0) {\n const growIdx = handleIndex + 1;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(Math.abs(delta), maxGrow);\n\n let taken = 0;\n for (let i = handleIndex; i >= 0 && taken < wantedGrow; i -= 1) {\n const canGive = result[i] - getMin(panels[i]);\n const take = Math.min(canGive, wantedGrow - taken);\n result[i] -= take;\n taken += take;\n }\n\n result[growIdx] += taken;\n }\n\n return result;\n}\n\nfunction redistributeEqual(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] {\n const result = [...sizes];\n\n if (delta > 0) {\n const growIdx = handleIndex;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(delta, maxGrow);\n\n const donors: number[] = [];\n for (let i = handleIndex + 1; i < result.length; i += 1) {\n if (result[i] > getMin(panels[i])) {\n donors.push(i);\n }\n }\n\n let remaining = wantedGrow;\n while (remaining > 0.001 && donors.length > 0) {\n const perDonor = remaining / donors.length;\n const exhausted: number[] = [];\n\n for (let d = 0; d < donors.length; d += 1) {\n const idx = donors[d];\n const canGive = result[idx] - getMin(panels[idx]);\n const take = Math.min(canGive, perDonor);\n result[idx] -= take;\n remaining -= take;\n if (canGive <= perDonor + 0.001) {\n exhausted.push(d);\n }\n }\n\n for (let i = exhausted.length - 1; i >= 0; i -= 1) {\n donors.splice(exhausted[i], 1);\n }\n\n if (exhausted.length === 0) {\n break;\n }\n }\n\n result[growIdx] += wantedGrow - remaining;\n } else if (delta < 0) {\n const growIdx = handleIndex + 1;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(Math.abs(delta), maxGrow);\n\n const donors: number[] = [];\n for (let i = handleIndex; i >= 0; i -= 1) {\n if (result[i] > getMin(panels[i])) {\n donors.push(i);\n }\n }\n\n let remaining = wantedGrow;\n while (remaining > 0.001 && donors.length > 0) {\n const perDonor = remaining / donors.length;\n const exhausted: number[] = [];\n\n for (let d = 0; d < donors.length; d += 1) {\n const idx = donors[d];\n const canGive = result[idx] - getMin(panels[idx]);\n const take = Math.min(canGive, perDonor);\n result[idx] -= take;\n remaining -= take;\n if (canGive <= perDonor + 0.001) {\n exhausted.push(d);\n }\n }\n\n for (let i = exhausted.length - 1; i >= 0; i -= 1) {\n donors.splice(exhausted[i], 1);\n }\n\n if (exhausted.length === 0) {\n break;\n }\n }\n\n result[growIdx] += wantedGrow - remaining;\n }\n\n return result;\n}\n\nfunction applyConstraints(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number,\n redistribute?: 'nearest' | 'equal' | UseSplitterRedistributeFn\n): number[] {\n if (typeof redistribute === 'function') {\n return redistribute({ sizes: [...sizes], panels, handleIndex, delta });\n }\n\n if (redistribute === 'nearest' || redistribute === 'equal') {\n const strategy = redistribute === 'nearest' ? redistributeNearest : redistributeEqual;\n const result = strategy(sizes, panels, handleIndex, delta);\n\n const beforeIdx = handleIndex;\n const afterIdx = handleIndex + 1;\n const beforePanel = panels[beforeIdx];\n const afterPanel = panels[afterIdx];\n\n if (\n beforePanel.collapsible &&\n result[beforeIdx] < getCollapseThreshold(beforePanel) &&\n result[beforeIdx] < sizes[beforeIdx]\n ) {\n const freed = result[beforeIdx];\n result[afterIdx] += freed;\n result[beforeIdx] = 0;\n } else if (\n afterPanel.collapsible &&\n result[afterIdx] < getCollapseThreshold(afterPanel) &&\n result[afterIdx] < sizes[afterIdx]\n ) {\n const freed = result[afterIdx];\n result[beforeIdx] += freed;\n result[afterIdx] = 0;\n }\n\n return result;\n }\n\n const collapsed = checkCollapse(sizes, panels, handleIndex, delta);\n if (collapsed) {\n return collapsed;\n }\n\n return applyAdjacentOnly(sizes, panels, handleIndex, delta);\n}\n\nexport function useSplitter<T extends HTMLElement = any>(\n options: UseSplitterOptions\n): UseSplitterReturnValue<T> {\n const {\n panels,\n orientation = 'horizontal',\n sizes: controlledSizes,\n onSizeChange,\n onCollapseChange,\n redistribute,\n step = 1,\n shiftStep = 10,\n dir = 'ltr',\n enabled = true,\n } = options;\n\n const defaultSizes = panels.map((p) => p.defaultSize);\n\n const [currentSizes, setCurrentSizes] = useUncontrolled({\n value: controlledSizes,\n defaultValue: defaultSizes,\n finalValue: defaultSizes,\n onChange: onSizeChange,\n });\n\n const [activeHandle, setActiveHandle] = useState(-1);\n\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n const internalStateRef = useRef<SplitterInternalState>(createInitialInternalState());\n const containerRef = useRef<T | null>(null);\n const documentControllerRef = useRef<AbortController | null>(null);\n const frameRef = useRef(0);\n const currentSizesRef = useRef(currentSizes);\n currentSizesRef.current = currentSizes;\n\n const preCollapseSizesRef = useRef<number[]>(defaultSizes);\n\n const collapsed = currentSizes.map((size) => size === 0);\n\n const updateSizes = useCallback(\n (newSizes: number[]) => {\n currentSizesRef.current = newSizes;\n setCurrentSizes(newSizes);\n },\n [setCurrentSizes]\n );\n\n const collapsePanel = useCallback(\n (panelIndex: number) => {\n if (!panels[panelIndex]?.collapsible) {\n return;\n }\n const sizes = currentSizesRef.current;\n if (sizes[panelIndex] === 0) {\n return;\n }\n\n preCollapseSizesRef.current = [...sizes];\n const newSizes = [...sizes];\n const freedSize = newSizes[panelIndex];\n newSizes[panelIndex] = 0;\n\n const neighbor = panelIndex === 0 ? 1 : panelIndex - 1;\n newSizes[neighbor] += freedSize;\n\n updateSizes(newSizes);\n onCollapseChange?.(panelIndex, true);\n },\n [panels, updateSizes, onCollapseChange]\n );\n\n const expandPanel = useCallback(\n (panelIndex: number) => {\n if (!panels[panelIndex]?.collapsible) {\n return;\n }\n const sizes = currentSizesRef.current;\n if (sizes[panelIndex] !== 0) {\n return;\n }\n\n const preCollapse = preCollapseSizesRef.current;\n const restoreSize = preCollapse[panelIndex] || panels[panelIndex].defaultSize;\n const newSizes = [...sizes];\n\n const neighbor = panelIndex === 0 ? 1 : panelIndex - 1;\n const available = Math.max(0, newSizes[neighbor] - getMin(panels[neighbor]));\n const actualRestore = Math.min(restoreSize, available);\n\n if (actualRestore <= 0) {\n return;\n }\n\n newSizes[panelIndex] = actualRestore;\n newSizes[neighbor] -= actualRestore;\n\n updateSizes(newSizes);\n onCollapseChange?.(panelIndex, false);\n },\n [panels, updateSizes, onCollapseChange]\n );\n\n const toggleCollapsePanel = useCallback(\n (panelIndex: number) => {\n if (currentSizesRef.current[panelIndex] === 0) {\n expandPanel(panelIndex);\n } else {\n collapsePanel(panelIndex);\n }\n },\n [collapsePanel, expandPanel]\n );\n\n const containerRefCallback: React.RefCallback<T | null> = useCallback((node) => {\n containerRef.current = node;\n }, []);\n\n const handleRefCallbacks = useRef<Map<number, (node: HTMLElement | null) => void>>(new Map());\n const handleElementControllers = useRef<Map<number, AbortController>>(new Map());\n\n const getHandleRefCallback = useCallback(\n (handleIndex: number): React.RefCallback<HTMLElement> => {\n if (handleRefCallbacks.current.has(handleIndex)) {\n return handleRefCallbacks.current.get(handleIndex)!;\n }\n\n const callback = (node: HTMLElement | null) => {\n const existingController = handleElementControllers.current.get(handleIndex);\n if (existingController) {\n existingController.abort();\n handleElementControllers.current.delete(handleIndex);\n }\n\n if (!node) {\n return;\n }\n\n const elementController = new AbortController();\n handleElementControllers.current.set(handleIndex, elementController);\n\n const onPointerDown = (event: PointerEvent) => {\n if (optionsRef.current.enabled === false) {\n return;\n }\n if (event.button !== 0) {\n return;\n }\n\n const container = containerRef.current;\n if (!container) {\n return;\n }\n\n const rect = container.getBoundingClientRect();\n const isHorizontal = (optionsRef.current.orientation ?? 'horizontal') === 'horizontal';\n const containerSize = isHorizontal ? rect.width : rect.height;\n const pointerPos = isHorizontal ? event.clientX : event.clientY;\n\n const s = internalStateRef.current;\n s.isDragging = true;\n s.handleIndex = handleIndex;\n s.startPointer = pointerPos;\n s.containerSize = containerSize;\n s.startSizes = [...currentSizesRef.current];\n s.preCollapseSizes = [...preCollapseSizesRef.current];\n\n setActiveHandle(handleIndex);\n document.body.style.userSelect = 'none';\n document.body.style.webkitUserSelect = 'none';\n document.body.style.cursor = isHorizontal ? 'col-resize' : 'row-resize';\n\n optionsRef.current.onResizeStart?.(handleIndex);\n\n documentControllerRef.current?.abort();\n documentControllerRef.current = new AbortController();\n const sig = documentControllerRef.current.signal;\n\n document.addEventListener('pointermove', onPointerMove, { signal: sig });\n document.addEventListener('pointerup', onPointerUp, { signal: sig });\n document.addEventListener('pointercancel', onPointerUp, { signal: sig });\n };\n\n const flushResize = (pointerEvent: PointerEvent) => {\n const s = internalStateRef.current;\n if (!s.containerSize) {\n return;\n }\n const isHorizontal = (optionsRef.current.orientation ?? 'horizontal') === 'horizontal';\n const isRtl = isHorizontal && optionsRef.current.dir === 'rtl';\n const pointerPos = isHorizontal ? pointerEvent.clientX : pointerEvent.clientY;\n const pixelDelta = pointerPos - s.startPointer;\n const percentDelta = ((isRtl ? -pixelDelta : pixelDelta) / s.containerSize) * 100;\n\n const opts = optionsRef.current;\n const newSizes = applyConstraints(\n s.startSizes,\n opts.panels,\n s.handleIndex,\n percentDelta,\n opts.redistribute\n );\n\n const prevSizes = currentSizesRef.current;\n const beforeWasCollapsed = prevSizes[s.handleIndex] === 0;\n const afterWasCollapsed = prevSizes[s.handleIndex + 1] === 0;\n const beforeNowCollapsed = newSizes[s.handleIndex] === 0;\n const afterNowCollapsed = newSizes[s.handleIndex + 1] === 0;\n\n if (!beforeWasCollapsed && beforeNowCollapsed) {\n preCollapseSizesRef.current = [...s.startSizes];\n opts.onCollapseChange?.(s.handleIndex, true);\n } else if (beforeWasCollapsed && !beforeNowCollapsed) {\n opts.onCollapseChange?.(s.handleIndex, false);\n }\n\n if (!afterWasCollapsed && afterNowCollapsed) {\n preCollapseSizesRef.current = [...s.startSizes];\n opts.onCollapseChange?.(s.handleIndex + 1, true);\n } else if (afterWasCollapsed && !afterNowCollapsed) {\n opts.onCollapseChange?.(s.handleIndex + 1, false);\n }\n\n currentSizesRef.current = newSizes;\n setCurrentSizes(newSizes);\n };\n\n const onPointerMove = (event: PointerEvent) => {\n const s = internalStateRef.current;\n if (!s.isDragging) {\n return;\n }\n\n cancelAnimationFrame(frameRef.current);\n frameRef.current = requestAnimationFrame(() => {\n flushResize(event);\n });\n };\n\n const onPointerUp = (event: PointerEvent) => {\n const s = internalStateRef.current;\n if (!s.isDragging) {\n return;\n }\n\n cancelAnimationFrame(frameRef.current);\n flushResize(event);\n\n s.isDragging = false;\n const finishedHandle = s.handleIndex;\n s.handleIndex = -1;\n\n setActiveHandle(-1);\n document.body.style.userSelect = '';\n document.body.style.webkitUserSelect = '';\n document.body.style.cursor = '';\n\n documentControllerRef.current?.abort();\n documentControllerRef.current = null;\n\n optionsRef.current.onResizeEnd?.(finishedHandle, [...currentSizesRef.current]);\n };\n\n node.addEventListener('pointerdown', onPointerDown, {\n signal: elementController.signal,\n });\n };\n\n handleRefCallbacks.current.set(handleIndex, callback);\n return callback;\n },\n [setCurrentSizes]\n );\n\n const getHandleProps = useCallback(\n (input: { index: number }) => {\n const { index } = input;\n const orient = orientation;\n const beforeSize = currentSizes[index] ?? 0;\n const beforePanel = panels[index];\n const afterPanel = panels[index + 1];\n\n return {\n ref: getHandleRefCallback(index),\n role: 'separator' as const,\n 'aria-orientation': orient,\n 'aria-valuenow': Math.round(beforeSize),\n 'aria-valuemin': Math.round(getMin(beforePanel)),\n 'aria-valuemax': Math.round(getMax(beforePanel)),\n tabIndex: 0,\n onKeyDown: (event: React.KeyboardEvent) => {\n if (!enabled) {\n return;\n }\n\n const isHorizontal = orient === 'horizontal';\n const isRtl = dir === 'rtl';\n\n let delta = 0;\n const currentStep = event.shiftKey ? shiftStep : step;\n\n switch (event.key) {\n case 'ArrowLeft': {\n if (!isHorizontal) {\n return;\n }\n delta = isRtl ? currentStep : -currentStep;\n break;\n }\n case 'ArrowRight': {\n if (!isHorizontal) {\n return;\n }\n delta = isRtl ? -currentStep : currentStep;\n break;\n }\n case 'ArrowUp': {\n if (isHorizontal) {\n return;\n }\n delta = -currentStep;\n break;\n }\n case 'ArrowDown': {\n if (isHorizontal) {\n return;\n }\n delta = currentStep;\n break;\n }\n case 'Home': {\n delta = -(currentSizes[index] - getMin(beforePanel));\n break;\n }\n case 'End': {\n delta = getMax(beforePanel) - currentSizes[index];\n break;\n }\n case 'Enter': {\n const beforeCollapsible = beforePanel?.collapsible;\n const afterCollapsible = afterPanel?.collapsible;\n\n if (beforeCollapsible && currentSizes[index] <= currentSizes[index + 1]) {\n toggleCollapsePanel(index);\n event.preventDefault();\n return;\n }\n if (afterCollapsible) {\n toggleCollapsePanel(index + 1);\n event.preventDefault();\n return;\n }\n if (beforeCollapsible) {\n toggleCollapsePanel(index);\n event.preventDefault();\n return;\n }\n return;\n }\n default:\n return;\n }\n\n event.preventDefault();\n\n if (delta !== 0) {\n const newSizes = applyConstraints(currentSizes, panels, index, delta, redistribute);\n const beforeWas = currentSizes[index] === 0;\n const afterWas = currentSizes[index + 1] === 0;\n const beforeNow = newSizes[index] === 0;\n const afterNow = newSizes[index + 1] === 0;\n\n if (!beforeWas && beforeNow) {\n preCollapseSizesRef.current = [...currentSizes];\n onCollapseChange?.(index, true);\n } else if (beforeWas && !beforeNow) {\n onCollapseChange?.(index, false);\n }\n\n if (!afterWas && afterNow) {\n preCollapseSizesRef.current = [...currentSizes];\n onCollapseChange?.(index + 1, true);\n } else if (afterWas && !afterNow) {\n onCollapseChange?.(index + 1, false);\n }\n\n updateSizes(newSizes);\n }\n },\n 'data-active': activeHandle === index || undefined,\n 'data-orientation': orient,\n };\n },\n [\n orientation,\n currentSizes,\n panels,\n enabled,\n dir,\n step,\n shiftStep,\n activeHandle,\n redistribute,\n getHandleRefCallback,\n toggleCollapsePanel,\n updateSizes,\n onCollapseChange,\n ]\n );\n\n useEffect(\n () => () => {\n documentControllerRef.current?.abort();\n documentControllerRef.current = null;\n handleElementControllers.current.forEach((controller) => controller.abort());\n handleElementControllers.current.clear();\n cancelAnimationFrame(frameRef.current);\n\n if (internalStateRef.current.isDragging) {\n internalStateRef.current.isDragging = false;\n document.body.style.userSelect = '';\n document.body.style.webkitUserSelect = '';\n document.body.style.cursor = '';\n }\n },\n []\n );\n\n return {\n ref: containerRefCallback,\n sizes: currentSizes,\n collapsed,\n activeHandle,\n getHandleProps,\n setSizes: updateSizes,\n collapse: collapsePanel,\n expand: expandPanel,\n toggleCollapse: toggleCollapsePanel,\n };\n}\n\nexport namespace useSplitter {\n export type Panel = UseSplitterPanel;\n export type Options = UseSplitterOptions;\n export type RedistributeInput = UseSplitterRedistributeInput;\n export type RedistributeFn = UseSplitterRedistributeFn;\n export type ReturnValue<T extends HTMLElement = any> = UseSplitterReturnValue<T>;\n}\n"],"mappings":";;;;AA6FA,SAAS,MAAM,OAAe,KAAa,KAAqB;CAC9D,OAAO,KAAK,IAAI,KAAK,IAAI,OAAO,GAAG,GAAG,GAAG;AAC3C;AAEA,SAAS,OAAO,OAAiC;CAC/C,OAAO,MAAM,OAAO;AACtB;AAEA,SAAS,OAAO,OAAiC;CAC/C,OAAO,MAAM,OAAO;AACtB;AAEA,SAAS,qBAAqB,OAAiC;CAC7D,OAAO,MAAM,qBAAqB,OAAO,KAAK;AAChD;AAWA,SAAS,6BAAoD;CAC3D,OAAO;EACL,YAAY;EACZ,aAAa;EACb,cAAc;EACd,eAAe;EACf,YAAY,CAAC;EACb,kBAAkB,CAAC;CACrB;AACF;AAEA,SAAS,cACP,OACA,QACA,aACA,OACiB;CACjB,MAAM,YAAY;CAClB,MAAM,WAAW,cAAc;CAC/B,MAAM,cAAc,OAAO;CAC3B,MAAM,aAAa,OAAO;CAE1B,MAAM,YAAY,MAAM,aAAa;CACrC,MAAM,WAAW,MAAM,YAAY;CAEnC,IACE,YAAY,eACZ,YAAY,qBAAqB,WAAW,KAC5C,YAAY,MAAM,YAClB;EACA,MAAM,SAAS,CAAC,GAAG,KAAK;EACxB,OAAO,aAAa,OAAO;EAC3B,OAAO,aAAa;EACpB,OAAO;CACT;CAEA,IACE,WAAW,eACX,WAAW,qBAAqB,UAAU,KAC1C,WAAW,MAAM,WACjB;EACA,MAAM,SAAS,CAAC,GAAG,KAAK;EACxB,OAAO,cAAc,OAAO;EAC5B,OAAO,YAAY;EACnB,OAAO;CACT;CAEA,OAAO;AACT;AAEA,SAAS,kBACP,OACA,QACA,aACA,OACU;CACV,MAAM,SAAS,CAAC,GAAG,KAAK;CACxB,MAAM,YAAY;CAClB,MAAM,WAAW,cAAc;CAE/B,MAAM,QAAQ,OAAO,aAAa,OAAO;CACzC,MAAM,qBAAqB,KAAK,IAAI,O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KAAK,MAAM,SAAS;EAC/B;CACF,GACA,CAAC,CACH;CAEA,OAAO;EACL,KAAK;EACL,OAAO;EACP;EACA;EACA;EACA,UAAU;EACV,UAAU;EACV,QAAQ;EACR,gBAAgB;CAClB;AACF"}
1
+ {"version":3,"file":"use-splitter.mjs","names":[],"sources":["../../src/use-splitter/use-splitter.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-deprecated */\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { useUncontrolled } from '../use-uncontrolled/use-uncontrolled';\n\nexport interface UseSplitterPanel {\n /** Initial size as percentage (0-100). All panels must sum to 100. */\n defaultSize: number;\n /** Minimum size percentage, `0` by default */\n min?: number;\n /** Maximum size percentage, `100` by default */\n max?: number;\n /** Whether this panel can be collapsed, `false` by default */\n collapsible?: boolean;\n /** Size below which the panel snaps to collapsed (percentage), defaults to `min` */\n collapseThreshold?: number;\n}\n\nexport interface UseSplitterRedistributeInput {\n /** Current sizes before applying delta */\n sizes: number[];\n /** Panel configurations */\n panels: UseSplitterPanel[];\n /** Index of the handle being dragged */\n handleIndex: number;\n /** Requested size change in percentage (positive = grow before-panel) */\n delta: number;\n}\n\nexport type UseSplitterRedistributeFn = (input: UseSplitterRedistributeInput) => number[];\n\nexport interface UseSplitterOptions {\n /** Panel configuration array (minimum 2 panels) */\n panels: UseSplitterPanel[];\n /** Layout direction, `'horizontal'` by default */\n orientation?: 'horizontal' | 'vertical';\n /** Controlled sizes (percentages summing to 100) */\n sizes?: number[];\n /** Called during resize with updated sizes */\n onSizeChange?: (sizes: number[]) => void;\n /** Called when drag starts */\n onResizeStart?: (handleIndex: number) => void;\n /** Called when drag ends */\n onResizeEnd?: (handleIndex: number, sizes: number[]) => void;\n /** Called when a panel collapses or expands */\n onCollapseChange?: (panelIndex: number, collapsed: boolean) => void;\n /** How to borrow space from non-adjacent panels when the immediate neighbor is at its min/max.\n * `'nearest'` takes from the nearest panel in the drag direction first.\n * `'equal'` distributes equally among all panels in the drag direction.\n * A function receives sizes, panels, handleIndex and delta, and returns new sizes.\n * When not set, only the two adjacent panels are affected. */\n redistribute?: 'nearest' | 'equal' | UseSplitterRedistributeFn;\n /** Keyboard step size in percentage, `1` by default */\n step?: number;\n /** Shift+arrow step size in percentage, `10` by default */\n shiftStep?: number;\n /** Text direction for keyboard nav, `'ltr'` by default */\n dir?: 'ltr' | 'rtl';\n /** Restore the two panels adjacent to a handle to their default ratio (preserving their combined size) when the handle is double-clicked, `true` by default */\n resetOnDoubleClick?: boolean;\n /** Enable/disable the hook, `true` by default */\n enabled?: boolean;\n}\n\nexport interface UseSplitterReturnValue<T extends HTMLElement = any> {\n /** Ref callback for the container element */\n ref: React.RefCallback<T | null>;\n /** Current panel sizes as percentages */\n sizes: number[];\n /** Which panels are currently collapsed */\n collapsed: boolean[];\n /** Index of handle being dragged, or -1 */\n activeHandle: number;\n /** Get props to spread on each resize handle */\n getHandleProps: (input: { index: number }) => {\n ref: React.RefCallback<HTMLElement>;\n role: 'separator';\n 'aria-orientation': 'horizontal' | 'vertical';\n 'aria-valuenow': number;\n 'aria-valuemin': number;\n 'aria-valuemax': number;\n tabIndex: number;\n onKeyDown: React.KeyboardEventHandler;\n onDoubleClick: React.MouseEventHandler;\n 'data-active': boolean | undefined;\n 'data-orientation': 'horizontal' | 'vertical';\n };\n /** Programmatically set sizes */\n setSizes: (sizes: number[]) => void;\n /** Collapse a panel */\n collapse: (panelIndex: number) => void;\n /** Expand a collapsed panel */\n expand: (panelIndex: number) => void;\n /** Toggle collapse of a panel */\n toggleCollapse: (panelIndex: number) => void;\n /** Reset the two panels adjacent to a handle to their default ratio, preserving\n * their combined size */\n reset: (handleIndex: number) => void;\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\nfunction getMin(panel: UseSplitterPanel): number {\n return panel.min ?? 0;\n}\n\nfunction getMax(panel: UseSplitterPanel): number {\n return panel.max ?? 100;\n}\n\nfunction getCollapseThreshold(panel: UseSplitterPanel): number {\n return panel.collapseThreshold ?? getMin(panel);\n}\n\ninterface SplitterInternalState {\n isDragging: boolean;\n handleIndex: number;\n startPointer: number;\n containerSize: number;\n startSizes: number[];\n preCollapseSizes: number[];\n}\n\nfunction createInitialInternalState(): SplitterInternalState {\n return {\n isDragging: false,\n handleIndex: -1,\n startPointer: 0,\n containerSize: 0,\n startSizes: [],\n preCollapseSizes: [],\n };\n}\n\nfunction checkCollapse(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] | null {\n const beforeIdx = handleIndex;\n const afterIdx = handleIndex + 1;\n const beforePanel = panels[beforeIdx];\n const afterPanel = panels[afterIdx];\n\n const rawBefore = sizes[beforeIdx] + delta;\n const rawAfter = sizes[afterIdx] - delta;\n\n if (\n beforePanel.collapsible &&\n rawBefore < getCollapseThreshold(beforePanel) &&\n rawBefore < sizes[beforeIdx]\n ) {\n const result = [...sizes];\n result[afterIdx] += result[beforeIdx];\n result[beforeIdx] = 0;\n return result;\n }\n\n if (\n afterPanel.collapsible &&\n rawAfter < getCollapseThreshold(afterPanel) &&\n rawAfter < sizes[afterIdx]\n ) {\n const result = [...sizes];\n result[beforeIdx] += result[afterIdx];\n result[afterIdx] = 0;\n return result;\n }\n\n return null;\n}\n\nfunction applyAdjacentOnly(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] {\n const result = [...sizes];\n const beforeIdx = handleIndex;\n const afterIdx = handleIndex + 1;\n\n const total = result[beforeIdx] + result[afterIdx];\n const effectiveBeforeMax = Math.min(getMax(panels[beforeIdx]), total - getMin(panels[afterIdx]));\n const effectiveBeforeMin = Math.max(getMin(panels[beforeIdx]), total - getMax(panels[afterIdx]));\n const newBefore = clamp(result[beforeIdx] + delta, effectiveBeforeMin, effectiveBeforeMax);\n result[beforeIdx] = newBefore;\n result[afterIdx] = total - newBefore;\n return result;\n}\n\nfunction redistributeNearest(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] {\n const result = [...sizes];\n\n if (delta > 0) {\n const growIdx = handleIndex;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(delta, maxGrow);\n\n let taken = 0;\n for (let i = handleIndex + 1; i < result.length && taken < wantedGrow; i += 1) {\n const canGive = result[i] - getMin(panels[i]);\n const take = Math.min(canGive, wantedGrow - taken);\n result[i] -= take;\n taken += take;\n }\n\n result[growIdx] += taken;\n } else if (delta < 0) {\n const growIdx = handleIndex + 1;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(Math.abs(delta), maxGrow);\n\n let taken = 0;\n for (let i = handleIndex; i >= 0 && taken < wantedGrow; i -= 1) {\n const canGive = result[i] - getMin(panels[i]);\n const take = Math.min(canGive, wantedGrow - taken);\n result[i] -= take;\n taken += take;\n }\n\n result[growIdx] += taken;\n }\n\n return result;\n}\n\nfunction redistributeEqual(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number\n): number[] {\n const result = [...sizes];\n\n if (delta > 0) {\n const growIdx = handleIndex;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(delta, maxGrow);\n\n const donors: number[] = [];\n for (let i = handleIndex + 1; i < result.length; i += 1) {\n if (result[i] > getMin(panels[i])) {\n donors.push(i);\n }\n }\n\n let remaining = wantedGrow;\n while (remaining > 0.001 && donors.length > 0) {\n const perDonor = remaining / donors.length;\n const exhausted: number[] = [];\n\n for (let d = 0; d < donors.length; d += 1) {\n const idx = donors[d];\n const canGive = result[idx] - getMin(panels[idx]);\n const take = Math.min(canGive, perDonor);\n result[idx] -= take;\n remaining -= take;\n if (canGive <= perDonor + 0.001) {\n exhausted.push(d);\n }\n }\n\n for (let i = exhausted.length - 1; i >= 0; i -= 1) {\n donors.splice(exhausted[i], 1);\n }\n\n if (exhausted.length === 0) {\n break;\n }\n }\n\n result[growIdx] += wantedGrow - remaining;\n } else if (delta < 0) {\n const growIdx = handleIndex + 1;\n const maxGrow = getMax(panels[growIdx]) - result[growIdx];\n const wantedGrow = Math.min(Math.abs(delta), maxGrow);\n\n const donors: number[] = [];\n for (let i = handleIndex; i >= 0; i -= 1) {\n if (result[i] > getMin(panels[i])) {\n donors.push(i);\n }\n }\n\n let remaining = wantedGrow;\n while (remaining > 0.001 && donors.length > 0) {\n const perDonor = remaining / donors.length;\n const exhausted: number[] = [];\n\n for (let d = 0; d < donors.length; d += 1) {\n const idx = donors[d];\n const canGive = result[idx] - getMin(panels[idx]);\n const take = Math.min(canGive, perDonor);\n result[idx] -= take;\n remaining -= take;\n if (canGive <= perDonor + 0.001) {\n exhausted.push(d);\n }\n }\n\n for (let i = exhausted.length - 1; i >= 0; i -= 1) {\n donors.splice(exhausted[i], 1);\n }\n\n if (exhausted.length === 0) {\n break;\n }\n }\n\n result[growIdx] += wantedGrow - remaining;\n }\n\n return result;\n}\n\nfunction applyConstraints(\n sizes: number[],\n panels: UseSplitterPanel[],\n handleIndex: number,\n delta: number,\n redistribute?: 'nearest' | 'equal' | UseSplitterRedistributeFn\n): number[] {\n if (typeof redistribute === 'function') {\n return redistribute({ sizes: [...sizes], panels, handleIndex, delta });\n }\n\n if (redistribute === 'nearest' || redistribute === 'equal') {\n const strategy = redistribute === 'nearest' ? redistributeNearest : redistributeEqual;\n const result = strategy(sizes, panels, handleIndex, delta);\n\n const beforeIdx = handleIndex;\n const afterIdx = handleIndex + 1;\n const beforePanel = panels[beforeIdx];\n const afterPanel = panels[afterIdx];\n\n if (\n beforePanel.collapsible &&\n result[beforeIdx] < getCollapseThreshold(beforePanel) &&\n result[beforeIdx] < sizes[beforeIdx]\n ) {\n const freed = result[beforeIdx];\n result[afterIdx] += freed;\n result[beforeIdx] = 0;\n } else if (\n afterPanel.collapsible &&\n result[afterIdx] < getCollapseThreshold(afterPanel) &&\n result[afterIdx] < sizes[afterIdx]\n ) {\n const freed = result[afterIdx];\n result[beforeIdx] += freed;\n result[afterIdx] = 0;\n }\n\n return result;\n }\n\n const collapsed = checkCollapse(sizes, panels, handleIndex, delta);\n if (collapsed) {\n return collapsed;\n }\n\n return applyAdjacentOnly(sizes, panels, handleIndex, delta);\n}\n\nexport function useSplitter<T extends HTMLElement = any>(\n options: UseSplitterOptions\n): UseSplitterReturnValue<T> {\n const {\n panels,\n orientation = 'horizontal',\n sizes: controlledSizes,\n onSizeChange,\n onCollapseChange,\n redistribute,\n step = 1,\n shiftStep = 10,\n dir = 'ltr',\n resetOnDoubleClick = true,\n enabled = true,\n } = options;\n\n const defaultSizes = panels.map((p) => p.defaultSize);\n\n const [currentSizes, setCurrentSizes] = useUncontrolled({\n value: controlledSizes,\n defaultValue: defaultSizes,\n finalValue: defaultSizes,\n onChange: onSizeChange,\n });\n\n const [activeHandle, setActiveHandle] = useState(-1);\n\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n const internalStateRef = useRef<SplitterInternalState>(createInitialInternalState());\n const containerRef = useRef<T | null>(null);\n const documentControllerRef = useRef<AbortController | null>(null);\n const frameRef = useRef(0);\n const currentSizesRef = useRef(currentSizes);\n currentSizesRef.current = currentSizes;\n\n const preCollapseSizesRef = useRef<number[]>(defaultSizes);\n\n const collapsed = currentSizes.map((size) => size === 0);\n\n const updateSizes = useCallback(\n (newSizes: number[]) => {\n currentSizesRef.current = newSizes;\n setCurrentSizes(newSizes);\n },\n [setCurrentSizes]\n );\n\n const collapsePanel = useCallback(\n (panelIndex: number) => {\n if (!panels[panelIndex]?.collapsible) {\n return;\n }\n const sizes = currentSizesRef.current;\n if (sizes[panelIndex] === 0) {\n return;\n }\n\n preCollapseSizesRef.current = [...sizes];\n const newSizes = [...sizes];\n const freedSize = newSizes[panelIndex];\n newSizes[panelIndex] = 0;\n\n const neighbor = panelIndex === 0 ? 1 : panelIndex - 1;\n newSizes[neighbor] += freedSize;\n\n updateSizes(newSizes);\n onCollapseChange?.(panelIndex, true);\n },\n [panels, updateSizes, onCollapseChange]\n );\n\n const expandPanel = useCallback(\n (panelIndex: number) => {\n if (!panels[panelIndex]?.collapsible) {\n return;\n }\n const sizes = currentSizesRef.current;\n if (sizes[panelIndex] !== 0) {\n return;\n }\n\n const preCollapse = preCollapseSizesRef.current;\n const restoreSize = preCollapse[panelIndex] || panels[panelIndex].defaultSize;\n const newSizes = [...sizes];\n\n const neighbor = panelIndex === 0 ? 1 : panelIndex - 1;\n const available = Math.max(0, newSizes[neighbor] - getMin(panels[neighbor]));\n const actualRestore = Math.min(restoreSize, available);\n\n if (actualRestore <= 0) {\n return;\n }\n\n newSizes[panelIndex] = actualRestore;\n newSizes[neighbor] -= actualRestore;\n\n updateSizes(newSizes);\n onCollapseChange?.(panelIndex, false);\n },\n [panels, updateSizes, onCollapseChange]\n );\n\n const toggleCollapsePanel = useCallback(\n (panelIndex: number) => {\n if (currentSizesRef.current[panelIndex] === 0) {\n expandPanel(panelIndex);\n } else {\n collapsePanel(panelIndex);\n }\n },\n [collapsePanel, expandPanel]\n );\n\n const emitCollapseTransitions = useCallback(\n (prev: number[], next: number[], indices: number[], preCollapseSnapshot: number[]) => {\n const onChange = optionsRef.current.onCollapseChange;\n for (const idx of indices) {\n const wasCollapsed = prev[idx] === 0;\n const nowCollapsed = next[idx] === 0;\n if (!wasCollapsed && nowCollapsed) {\n preCollapseSizesRef.current = [...preCollapseSnapshot];\n onChange?.(idx, true);\n } else if (wasCollapsed && !nowCollapsed) {\n onChange?.(idx, false);\n }\n }\n },\n []\n );\n\n const reset = useCallback(\n (handleIndex: number) => {\n const prev = currentSizesRef.current;\n const currentPanels = optionsRef.current.panels;\n\n const beforeIdx = handleIndex;\n const afterIdx = handleIndex + 1;\n if (beforeIdx < 0 || afterIdx >= prev.length) {\n return;\n }\n\n const total = prev[beforeIdx] + prev[afterIdx];\n const defBefore = currentPanels[beforeIdx].defaultSize;\n const defAfter = currentPanels[afterIdx].defaultSize;\n const defTotal = defBefore + defAfter;\n const targetBefore = defTotal === 0 ? total / 2 : total * (defBefore / defTotal);\n\n const next = applyAdjacentOnly(\n prev,\n currentPanels,\n beforeIdx,\n targetBefore - prev[beforeIdx]\n );\n emitCollapseTransitions(prev, next, [beforeIdx, afterIdx], prev);\n updateSizes(next);\n },\n [emitCollapseTransitions, updateSizes]\n );\n\n const containerRefCallback: React.RefCallback<T | null> = useCallback((node) => {\n containerRef.current = node;\n }, []);\n\n const handleRefCallbacks = useRef<Map<number, (node: HTMLElement | null) => void>>(new Map());\n const handleElementControllers = useRef<Map<number, AbortController>>(new Map());\n\n const getHandleRefCallback = useCallback(\n (handleIndex: number): React.RefCallback<HTMLElement> => {\n if (handleRefCallbacks.current.has(handleIndex)) {\n return handleRefCallbacks.current.get(handleIndex)!;\n }\n\n const callback = (node: HTMLElement | null) => {\n const existingController = handleElementControllers.current.get(handleIndex);\n if (existingController) {\n existingController.abort();\n handleElementControllers.current.delete(handleIndex);\n }\n\n if (!node) {\n return;\n }\n\n const elementController = new AbortController();\n handleElementControllers.current.set(handleIndex, elementController);\n\n const onPointerDown = (event: PointerEvent) => {\n if (optionsRef.current.enabled === false) {\n return;\n }\n if (event.button !== 0) {\n return;\n }\n\n const container = containerRef.current;\n if (!container) {\n return;\n }\n\n const rect = container.getBoundingClientRect();\n const isHorizontal = (optionsRef.current.orientation ?? 'horizontal') === 'horizontal';\n const containerSize = isHorizontal ? rect.width : rect.height;\n const pointerPos = isHorizontal ? event.clientX : event.clientY;\n\n const s = internalStateRef.current;\n s.isDragging = true;\n s.handleIndex = handleIndex;\n s.startPointer = pointerPos;\n s.containerSize = containerSize;\n s.startSizes = [...currentSizesRef.current];\n s.preCollapseSizes = [...preCollapseSizesRef.current];\n\n setActiveHandle(handleIndex);\n document.body.style.userSelect = 'none';\n document.body.style.webkitUserSelect = 'none';\n document.body.style.cursor = isHorizontal ? 'col-resize' : 'row-resize';\n\n optionsRef.current.onResizeStart?.(handleIndex);\n\n documentControllerRef.current?.abort();\n documentControllerRef.current = new AbortController();\n const sig = documentControllerRef.current.signal;\n\n document.addEventListener('pointermove', onPointerMove, { signal: sig });\n document.addEventListener('pointerup', onPointerUp, { signal: sig });\n document.addEventListener('pointercancel', onPointerUp, { signal: sig });\n };\n\n const flushResize = (pointerEvent: PointerEvent) => {\n const s = internalStateRef.current;\n if (!s.containerSize) {\n return;\n }\n const isHorizontal = (optionsRef.current.orientation ?? 'horizontal') === 'horizontal';\n const isRtl = isHorizontal && optionsRef.current.dir === 'rtl';\n const pointerPos = isHorizontal ? pointerEvent.clientX : pointerEvent.clientY;\n const pixelDelta = pointerPos - s.startPointer;\n const percentDelta = ((isRtl ? -pixelDelta : pixelDelta) / s.containerSize) * 100;\n\n const opts = optionsRef.current;\n const newSizes = applyConstraints(\n s.startSizes,\n opts.panels,\n s.handleIndex,\n percentDelta,\n opts.redistribute\n );\n\n const prevSizes = currentSizesRef.current;\n emitCollapseTransitions(\n prevSizes,\n newSizes,\n [s.handleIndex, s.handleIndex + 1],\n s.startSizes\n );\n\n currentSizesRef.current = newSizes;\n setCurrentSizes(newSizes);\n };\n\n const onPointerMove = (event: PointerEvent) => {\n const s = internalStateRef.current;\n if (!s.isDragging) {\n return;\n }\n\n cancelAnimationFrame(frameRef.current);\n frameRef.current = requestAnimationFrame(() => {\n flushResize(event);\n });\n };\n\n const onPointerUp = (event: PointerEvent) => {\n const s = internalStateRef.current;\n if (!s.isDragging) {\n return;\n }\n\n cancelAnimationFrame(frameRef.current);\n flushResize(event);\n\n s.isDragging = false;\n const finishedHandle = s.handleIndex;\n s.handleIndex = -1;\n\n setActiveHandle(-1);\n document.body.style.userSelect = '';\n document.body.style.webkitUserSelect = '';\n document.body.style.cursor = '';\n\n documentControllerRef.current?.abort();\n documentControllerRef.current = null;\n\n optionsRef.current.onResizeEnd?.(finishedHandle, [...currentSizesRef.current]);\n };\n\n node.addEventListener('pointerdown', onPointerDown, {\n signal: elementController.signal,\n });\n };\n\n handleRefCallbacks.current.set(handleIndex, callback);\n return callback;\n },\n [setCurrentSizes]\n );\n\n const getHandleProps = useCallback(\n (input: { index: number }) => {\n const { index } = input;\n const orient = orientation;\n const beforeSize = currentSizes[index] ?? 0;\n const beforePanel = panels[index];\n const afterPanel = panels[index + 1];\n\n return {\n ref: getHandleRefCallback(index),\n role: 'separator' as const,\n 'aria-orientation': orient,\n 'aria-valuenow': Math.round(beforeSize),\n 'aria-valuemin': Math.round(getMin(beforePanel)),\n 'aria-valuemax': Math.round(getMax(beforePanel)),\n tabIndex: 0,\n onKeyDown: (event: React.KeyboardEvent) => {\n if (!enabled) {\n return;\n }\n\n const isHorizontal = orient === 'horizontal';\n const isRtl = dir === 'rtl';\n\n let delta = 0;\n const currentStep = event.shiftKey ? shiftStep : step;\n\n switch (event.key) {\n case 'ArrowLeft': {\n if (!isHorizontal) {\n return;\n }\n delta = isRtl ? currentStep : -currentStep;\n break;\n }\n case 'ArrowRight': {\n if (!isHorizontal) {\n return;\n }\n delta = isRtl ? -currentStep : currentStep;\n break;\n }\n case 'ArrowUp': {\n if (isHorizontal) {\n return;\n }\n delta = -currentStep;\n break;\n }\n case 'ArrowDown': {\n if (isHorizontal) {\n return;\n }\n delta = currentStep;\n break;\n }\n case 'Home': {\n delta = -(currentSizes[index] - getMin(beforePanel));\n break;\n }\n case 'End': {\n delta = getMax(beforePanel) - currentSizes[index];\n break;\n }\n case 'Enter': {\n const beforeCollapsible = beforePanel?.collapsible;\n const afterCollapsible = afterPanel?.collapsible;\n\n if (beforeCollapsible && currentSizes[index] <= currentSizes[index + 1]) {\n toggleCollapsePanel(index);\n event.preventDefault();\n return;\n }\n if (afterCollapsible) {\n toggleCollapsePanel(index + 1);\n event.preventDefault();\n return;\n }\n if (beforeCollapsible) {\n toggleCollapsePanel(index);\n event.preventDefault();\n return;\n }\n return;\n }\n default:\n return;\n }\n\n event.preventDefault();\n\n if (delta !== 0) {\n const newSizes = applyConstraints(currentSizes, panels, index, delta, redistribute);\n emitCollapseTransitions(currentSizes, newSizes, [index, index + 1], currentSizes);\n updateSizes(newSizes);\n }\n },\n onDoubleClick: () => {\n if (!enabled || !resetOnDoubleClick) {\n return;\n }\n reset(index);\n },\n 'data-active': activeHandle === index || undefined,\n 'data-orientation': orient,\n };\n },\n [\n orientation,\n currentSizes,\n panels,\n enabled,\n dir,\n step,\n shiftStep,\n resetOnDoubleClick,\n activeHandle,\n redistribute,\n getHandleRefCallback,\n toggleCollapsePanel,\n updateSizes,\n emitCollapseTransitions,\n reset,\n ]\n );\n\n useEffect(\n () => () => {\n documentControllerRef.current?.abort();\n documentControllerRef.current = null;\n handleElementControllers.current.forEach((controller) => controller.abort());\n handleElementControllers.current.clear();\n cancelAnimationFrame(frameRef.current);\n\n if (internalStateRef.current.isDragging) {\n internalStateRef.current.isDragging = false;\n document.body.style.userSelect = '';\n document.body.style.webkitUserSelect = '';\n document.body.style.cursor = '';\n }\n },\n []\n );\n\n return {\n ref: containerRefCallback,\n sizes: currentSizes,\n collapsed,\n activeHandle,\n getHandleProps,\n setSizes: updateSizes,\n collapse: collapsePanel,\n expand: expandPanel,\n toggleCollapse: toggleCollapsePanel,\n reset,\n };\n}\n\nexport namespace useSplitter {\n export type Panel = UseSplitterPanel;\n export type Options = UseSplitterOptions;\n export type RedistributeInput = UseSplitterRedistributeInput;\n export type RedistributeFn = UseSplitterRedistributeFn;\n export type ReturnValue<T extends HTMLElement = any> = UseSplitterReturnValue<T>;\n}\n"],"mappings":";;;;AAmGA,SAAS,MAAM,OAAe,KAAa,KAAqB;CAC9D,OAAO,KAAK,IAAI,KAAK,IAAI,OAAO,GAAG,GAAG,GAAG;AAC3C;AAEA,SAAS,OAAO,OAAiC;CAC/C,OAAO,MAAM,OAAO;AACtB;AAEA,SAAS,OAAO,OAAiC;CAC/C,OAAO,MAAM,OAAO;AACtB;AAEA,SAAS,qBAAqB,OAAiC;CAC7D,OAAO,MAAM,qBAAqB,OAAO,KAAK;AAChD;AAWA,SAAS,6BAAoD;CAC3D,OAAO;EACL,YAAY;EACZ,aAAa;EACb,cAAc;EACd,eAAe;EACf,YAAY,CAAC;EACb,kBAAkB,C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,mBAAmB;OACrB,oBAAoB,KAAK;OACzB,MAAM,eAAe;OACrB;MACF;MACA;KACF;KACA,SACE;IACJ;IAEA,MAAM,eAAe;IAErB,IAAI,UAAU,GAAG;KACf,MAAM,WAAW,iBAAiB,cAAc,QAAQ,OAAO,OAAO,YAAY;KAClF,wBAAwB,cAAc,UAAU,CAAC,OAAO,QAAQ,CAAC,GAAG,YAAY;KAChF,YAAY,QAAQ;IACtB;GACF;GACA,qBAAqB;IACnB,IAAI,CAAC,WAAW,CAAC,oBACf;IAEF,MAAM,KAAK;GACb;GACA,eAAe,iBAAiB,SAAS,KAAA;GACzC,oBAAoB;EACtB;CACF,GACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAEA,sBACc;EACV,sBAAsB,SAAS,MAAM;EACrC,sBAAsB,UAAU;EAChC,yBAAyB,QAAQ,SAAS,eAAe,WAAW,MAAM,CAAC;EAC3E,yBAAyB,QAAQ,MAAM;EACvC,qBAAqB,SAAS,OAAO;EAErC,IAAI,iBAAiB,QAAQ,YAAY;GACvC,iBAAiB,QAAQ,aAAa;GACtC,SAAS,KAAK,MAAM,aAAa;GACjC,SAAS,KAAK,MAAM,mBAAmB;GACvC,SAAS,KAAK,MAAM,SAAS;EAC/B;CACF,GACA,CAAC,CACH;CAEA,OAAO;EACL,KAAK;EACL,OAAO;EACP;EACA;EACA;EACA,UAAU;EACV,UAAU;EACV,QAAQ;EACR,gBAAgB;EAChB;CACF;AACF"}
@@ -48,6 +48,8 @@ export interface UseSplitterOptions {
48
48
  shiftStep?: number;
49
49
  /** Text direction for keyboard nav, `'ltr'` by default */
50
50
  dir?: 'ltr' | 'rtl';
51
+ /** Restore the two panels adjacent to a handle to their default ratio (preserving their combined size) when the handle is double-clicked, `true` by default */
52
+ resetOnDoubleClick?: boolean;
51
53
  /** Enable/disable the hook, `true` by default */
52
54
  enabled?: boolean;
53
55
  }
@@ -72,6 +74,7 @@ export interface UseSplitterReturnValue<T extends HTMLElement = any> {
72
74
  'aria-valuemax': number;
73
75
  tabIndex: number;
74
76
  onKeyDown: React.KeyboardEventHandler;
77
+ onDoubleClick: React.MouseEventHandler;
75
78
  'data-active': boolean | undefined;
76
79
  'data-orientation': 'horizontal' | 'vertical';
77
80
  };
@@ -83,6 +86,9 @@ export interface UseSplitterReturnValue<T extends HTMLElement = any> {
83
86
  expand: (panelIndex: number) => void;
84
87
  /** Toggle collapse of a panel */
85
88
  toggleCollapse: (panelIndex: number) => void;
89
+ /** Reset the two panels adjacent to a handle to their default ratio, preserving
90
+ * their combined size */
91
+ reset: (handleIndex: number) => void;
86
92
  }
87
93
  export declare function useSplitter<T extends HTMLElement = any>(options: UseSplitterOptions): UseSplitterReturnValue<T>;
88
94
  export declare namespace useSplitter {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantine/hooks",
3
- "version": "9.3.1",
3
+ "version": "9.3.2",
4
4
  "description": "A collection of 50+ hooks for state and UI management",
5
5
  "homepage": "https://mantine.dev",
6
6
  "license": "MIT",