@mantine/hooks 9.3.0 → 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.
- package/cjs/use-id/use-id.cjs +3 -0
- package/cjs/use-id/use-id.cjs.map +1 -1
- package/cjs/use-long-press/use-long-press.cjs +45 -9
- package/cjs/use-long-press/use-long-press.cjs.map +1 -1
- package/cjs/use-mask/use-mask.cjs +43 -12
- package/cjs/use-mask/use-mask.cjs.map +1 -1
- package/cjs/use-splitter/use-splitter.cjs +36 -27
- package/cjs/use-splitter/use-splitter.cjs.map +1 -1
- package/esm/use-id/use-id.mjs +4 -1
- package/esm/use-id/use-id.mjs.map +1 -1
- package/esm/use-long-press/use-long-press.mjs +45 -9
- package/esm/use-long-press/use-long-press.mjs.map +1 -1
- package/esm/use-mask/use-mask.mjs +43 -12
- package/esm/use-mask/use-mask.mjs.map +1 -1
- package/esm/use-splitter/use-splitter.mjs +36 -27
- package/esm/use-splitter/use-splitter.mjs.map +1 -1
- package/lib/index.d.mts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/use-long-press/use-long-press.d.ts +13 -6
- package/lib/use-splitter/use-splitter.d.ts +6 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mask.mjs","names":[],"sources":["../../src/use-mask/use-mask.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nconst DEFAULT_TOKENS: Record<string, RegExp> = {\n '9': /[0-9]/,\n a: /[A-Za-z]/,\n A: /[A-Z]/,\n '*': /[A-Za-z0-9]/,\n '#': /[-+0-9]/,\n};\n\nexport interface UseMaskOptions {\n /** Mask pattern string or array of string literals and RegExp objects */\n mask: string | Array<string | RegExp>;\n\n /** Override or extend the default token map */\n tokens?: Record<string, RegExp>;\n\n /** Called before masking on each keystroke, can return overrides for mask options */\n modify?: (\n value: string\n ) => Partial<Pick<UseMaskOptions, 'mask' | 'tokens' | 'slotChar' | 'separate'>> | undefined;\n\n /** When true, raw and display values are decoupled */\n separate?: boolean;\n\n /** Character displayed in unfilled slots, `\"_\"` by default */\n slotChar?: string | null;\n\n /** Show mask pattern even when field is empty and unfocused */\n alwaysShowMask?: boolean;\n\n /** Show mask placeholder on focus, `true` by default */\n showMaskOnFocus?: boolean;\n\n /** Transform each character before validation and insertion */\n transform?: (char: string) => string;\n\n /** Clear value on blur when mask is incomplete, `false` by default */\n autoClear?: boolean;\n\n /** Sets aria-invalid on the input */\n invalid?: boolean;\n\n /** Called on every change with raw and masked values */\n onChangeRaw?: (rawValue: string, maskedValue: string) => void;\n\n /** Called when all required mask slots are filled */\n onComplete?: (maskedValue: string, rawValue: string) => void;\n\n /** Escape hatch for advanced cursor/value manipulation */\n beforeMaskedStateChange?: (states: {\n previousState: MaskState;\n currentState: MaskState;\n nextState: MaskState;\n }) => MaskState;\n}\n\nexport interface MaskState {\n value: string;\n selection: { start: number; end: number } | null;\n}\n\nexport interface UseMaskReturnValue {\n /** Ref to attach to the input element */\n ref: React.RefCallback<HTMLInputElement>;\n\n /** Current masked display value */\n value: string;\n\n /** Current raw unmasked value */\n rawValue: string;\n\n /** Whether all required mask slots are filled */\n isComplete: boolean;\n\n /** Clear the input value and reset state */\n reset: () => void;\n}\n\ninterface MaskSlot {\n type: 'token' | 'literal';\n char: string;\n pattern?: RegExp;\n optional?: boolean;\n}\n\ninterface UndoState {\n rawValue: string;\n selectionStart: number;\n}\n\nconst MAX_UNDO_HISTORY = 100;\n\nfunction parseMask(\n mask: string | Array<string | RegExp>,\n tokens: Record<string, RegExp>\n): MaskSlot[] {\n if (Array.isArray(mask)) {\n return mask.map((item) => {\n if (item instanceof RegExp) {\n return { type: 'token', char: '_', pattern: item };\n }\n return { type: 'literal', char: item };\n });\n }\n\n const slots: MaskSlot[] = [];\n let optional = false;\n\n for (let i = 0; i < mask.length; i++) {\n const char = mask[i];\n\n if (char === '\\\\' && i + 1 < mask.length) {\n i++;\n slots.push({ type: 'literal', char: mask[i] });\n continue;\n }\n\n if (char === '?') {\n optional = true;\n continue;\n }\n\n if (tokens[char]) {\n slots.push({ type: 'token', char, pattern: tokens[char], optional });\n } else {\n slots.push({ type: 'literal', char, optional });\n }\n }\n\n return slots;\n}\n\nfunction getSlotChar(slotCharOption: string | null | undefined, index: number): string {\n if (slotCharOption === null || slotCharOption === '' || slotCharOption === undefined) {\n return '';\n }\n if (slotCharOption.length > 1) {\n return slotCharOption[index] || '_';\n }\n return slotCharOption;\n}\n\nfunction applyMaskToRaw(\n raw: string,\n slots: MaskSlot[],\n _slotCharOption: string | null | undefined,\n transform?: (char: string) => string\n): string {\n let result = '';\n let rawIndex = 0;\n let slotIndex = 0;\n\n for (slotIndex = 0; slotIndex < slots.length; slotIndex++) {\n const slot = slots[slotIndex];\n if (slot.type === 'literal') {\n result += slot.char;\n } else if (rawIndex < raw.length) {\n const ch = transform ? transform(raw[rawIndex]) : raw[rawIndex];\n if (slot.pattern && slot.pattern.test(ch)) {\n result += ch;\n rawIndex++;\n } else {\n rawIndex++;\n slotIndex--;\n }\n } else {\n break;\n }\n }\n\n return result;\n}\n\nfunction buildDisplayValue(\n value: string,\n slots: MaskSlot[],\n slotCharOption: string | null | undefined,\n showSlots: boolean\n): string {\n if (!showSlots) {\n return value;\n }\n\n let display = value;\n\n for (let i = value.length; i < slots.length; i++) {\n const slot = slots[i];\n if (slot.type === 'literal') {\n display += slot.char;\n } else {\n const sc = getSlotChar(slotCharOption, i);\n if (!sc) {\n break;\n }\n display += sc;\n }\n }\n\n return display;\n}\n\nfunction extractRaw(masked: string, slots: MaskSlot[]): string {\n let raw = '';\n for (let i = 0; i < masked.length && i < slots.length; i++) {\n if (slots[i].type === 'token') {\n raw += masked[i];\n }\n }\n return raw;\n}\n\nfunction checkComplete(masked: string, slots: MaskSlot[]): boolean {\n for (let i = 0; i < slots.length; i++) {\n if (slots[i].type === 'token' && !slots[i].optional) {\n if (i >= masked.length) {\n return false;\n }\n if (!slots[i].pattern!.test(masked[i])) {\n return false;\n }\n }\n }\n return true;\n}\n\nfunction findNextTokenIndex(slots: MaskSlot[], from: number): number {\n for (let i = from; i < slots.length; i++) {\n if (slots[i].type === 'token') {\n return i;\n }\n }\n return slots.length;\n}\n\nfunction findPrevTokenIndex(slots: MaskSlot[], from: number): number {\n for (let i = from; i >= 0; i--) {\n if (slots[i].type === 'token') {\n return i;\n }\n }\n return -1;\n}\n\nfunction processInput(\n inputValue: string,\n slots: MaskSlot[],\n _slotCharOption: string | null | undefined\n): string {\n let result = '';\n let inputIndex = 0;\n\n for (\n let slotIndex = 0;\n slotIndex < slots.length && inputIndex <= inputValue.length;\n slotIndex++\n ) {\n const slot = slots[slotIndex];\n\n if (slot.type === 'literal') {\n result += slot.char;\n if (inputIndex < inputValue.length && inputValue[inputIndex] === slot.char) {\n inputIndex++;\n }\n continue;\n }\n\n if (inputIndex >= inputValue.length) {\n break;\n }\n\n while (inputIndex < inputValue.length) {\n const ch = inputValue[inputIndex];\n inputIndex++;\n\n if (slot.pattern!.test(ch)) {\n result += ch;\n break;\n }\n }\n\n if (result.length <= slotIndex) {\n break;\n }\n }\n\n return result;\n}\n\nfunction getResolvedOptions(options: UseMaskOptions, rawValue: string) {\n const tokens = { ...DEFAULT_TOKENS, ...options.tokens };\n let mask = options.mask;\n let slotChar: string | null | undefined = options.slotChar === undefined ? '_' : options.slotChar;\n let separate = options.separate ?? false;\n\n if (options.modify) {\n const overrides = options.modify(rawValue);\n if (overrides) {\n if (overrides.mask !== undefined) {\n mask = overrides.mask;\n }\n if (overrides.tokens !== undefined) {\n Object.assign(tokens, overrides.tokens);\n }\n if (overrides.slotChar !== undefined) {\n slotChar = overrides.slotChar;\n }\n if (overrides.separate !== undefined) {\n separate = overrides.separate;\n }\n }\n }\n\n const slots = parseMask(mask, tokens);\n return { slots, slotChar, separate, tokens, transform: options.transform };\n}\n\nexport function formatMask(raw: string, options: UseMaskOptions): string {\n const { slots, slotChar, transform } = getResolvedOptions(options, raw);\n return applyMaskToRaw(raw, slots, slotChar, transform);\n}\n\nexport function unformatMask(masked: string, options: UseMaskOptions): string {\n const { slots } = getResolvedOptions(options, '');\n return extractRaw(masked, slots);\n}\n\nexport function isMaskComplete(masked: string, options: UseMaskOptions): boolean {\n const { slots } = getResolvedOptions(options, '');\n return checkComplete(masked, slots);\n}\n\nexport function generatePattern(mode: 'full' | 'full-inexact', options: UseMaskOptions): string {\n const { slots } = getResolvedOptions(options, '');\n let pattern = '';\n\n for (const slot of slots) {\n if (slot.type === 'literal') {\n pattern += slot.char.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n } else {\n const src = slot.pattern!.source;\n if (mode === 'full-inexact') {\n pattern += slot.optional ? `${src}?` : src;\n } else {\n pattern += slot.optional ? `(${src})?` : `(${src})`;\n }\n }\n }\n\n return pattern;\n}\n\nexport function useMask(options: UseMaskOptions): UseMaskReturnValue {\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n const inputRef = useRef<HTMLInputElement | null>(null);\n const [maskedValue, setMaskedValue] = useState('');\n const [rawValue, setRawValue] = useState('');\n const processedRef = useRef('');\n const displayValueRef = useRef('');\n const rawValueRef = useRef('');\n const wasCompleteRef = useRef(false);\n const isFocusedRef = useRef(false);\n const undoStackRef = useRef<UndoState[]>([]);\n const redoStackRef = useRef<UndoState[]>([]);\n\n const getOptions = useCallback(() => {\n const opts = optionsRef.current;\n return getResolvedOptions(opts, rawValue);\n }, [rawValue]);\n\n const updateValue = useCallback(\n (newMasked: string, cursorPos?: number) => {\n const opts = optionsRef.current;\n const { slots } = getResolvedOptions(\n opts,\n extractRaw(newMasked, getResolvedOptions(opts, '').slots)\n );\n const raw = extractRaw(newMasked, slots);\n\n const { slots: resolvedSlots, slotChar } = getResolvedOptions(opts, raw);\n\n const reprocessed = processInput(newMasked, resolvedSlots, slotChar);\n const newRaw = extractRaw(reprocessed, resolvedSlots);\n\n const showSlots = opts.alwaysShowMask || isFocusedRef.current;\n const showOnFocus = opts.showMaskOnFocus !== false;\n const shouldShowSlots = showSlots && (showOnFocus || reprocessed.length > 0);\n\n const displayValue = buildDisplayValue(reprocessed, resolvedSlots, slotChar, shouldShowSlots);\n\n processedRef.current = reprocessed;\n displayValueRef.current = displayValue;\n rawValueRef.current = newRaw;\n setMaskedValue(displayValue);\n setRawValue(newRaw);\n\n if (inputRef.current) {\n inputRef.current.value = displayValue;\n if (cursorPos !== undefined && document.activeElement === inputRef.current) {\n const pos = Math.min(cursorPos, reprocessed.length);\n inputRef.current.setSelectionRange(pos, pos);\n }\n }\n\n if (opts.onChangeRaw) {\n opts.onChangeRaw(newRaw, displayValue);\n }\n\n const complete = checkComplete(reprocessed, resolvedSlots);\n if (complete && !wasCompleteRef.current && opts.onComplete) {\n opts.onComplete(displayValue, newRaw);\n }\n wasCompleteRef.current = complete;\n\n return { displayValue, newRaw, reprocessed, resolvedSlots };\n },\n [getOptions]\n );\n\n const pushUndoState = useCallback(() => {\n const input = inputRef.current;\n const selectionStart = input?.selectionStart ?? rawValueRef.current.length;\n const state: UndoState = {\n rawValue: rawValueRef.current,\n selectionStart,\n };\n const stack = undoStackRef.current;\n const top = stack[stack.length - 1];\n if (top && top.rawValue === state.rawValue && top.selectionStart === state.selectionStart) {\n return;\n }\n stack.push(state);\n if (stack.length > MAX_UNDO_HISTORY) {\n stack.shift();\n }\n redoStackRef.current = [];\n }, []);\n\n const applyHistoryState = useCallback(\n (target: UndoState) => {\n const opts = optionsRef.current;\n const { slots, slotChar, transform } = getResolvedOptions(opts, target.rawValue);\n const newMasked = applyMaskToRaw(target.rawValue, slots, slotChar, transform);\n updateValue(newMasked, target.selectionStart);\n },\n [updateValue]\n );\n\n const handleInput = useCallback(\n (e: Event) => {\n const input = e.target as HTMLInputElement;\n const opts = optionsRef.current;\n\n const { slots: resolvedSlots, slotChar, transform } = getResolvedOptions(opts, '');\n const prev = displayValueRef.current;\n const curr = input.value;\n\n let prefixLen = 0;\n const maxPrefix = Math.min(prev.length, curr.length);\n while (prefixLen < maxPrefix && prev[prefixLen] === curr[prefixLen]) {\n prefixLen++;\n }\n\n let suffixLen = 0;\n const maxSuffix = Math.min(prev.length - prefixLen, curr.length - prefixLen);\n while (\n suffixLen < maxSuffix &&\n prev[prev.length - 1 - suffixLen] === curr[curr.length - 1 - suffixLen]\n ) {\n suffixLen++;\n }\n\n const insertedText = curr.slice(prefixLen, curr.length - suffixLen);\n const removedEnd = prev.length - suffixLen;\n\n const beforeRaw = extractRaw(prev.slice(0, prefixLen), resolvedSlots.slice(0, prefixLen));\n const afterRaw = extractRaw(prev.slice(removedEnd), resolvedSlots.slice(removedEnd));\n const reformatted = applyMaskToRaw(\n beforeRaw + insertedText + afterRaw,\n resolvedSlots,\n slotChar,\n transform\n );\n const maskedPrefix = applyMaskToRaw(\n beforeRaw + insertedText,\n resolvedSlots,\n slotChar,\n transform\n );\n\n if (reformatted !== prev) {\n pushUndoState();\n }\n updateValue(reformatted, maskedPrefix.length);\n },\n [pushUndoState, updateValue]\n );\n\n const clampCursorToProcessed = useCallback((input: HTMLInputElement) => {\n const start = input.selectionStart ?? 0;\n const end = input.selectionEnd ?? 0;\n if (start !== end) {\n return;\n }\n\n const opts = optionsRef.current;\n const { slots } = getResolvedOptions(opts, '');\n const processed = processedRef.current;\n const endPos =\n processed.length > 0\n ? findNextEditablePosition(processed.length, slots, processed)\n : findNextTokenIndex(slots, 0);\n const startPos = findNextTokenIndex(slots, 0);\n\n if (start > endPos || start < startPos) {\n input.setSelectionRange(endPos, endPos);\n }\n }, []);\n\n const handleFocus = useCallback(() => {\n isFocusedRef.current = true;\n const opts = optionsRef.current;\n const input = inputRef.current;\n\n if (!input) {\n return;\n }\n\n const { slots, slotChar } = getResolvedOptions(opts, '');\n const showOnFocus = opts.showMaskOnFocus !== false;\n const processed = processedRef.current;\n\n if (showOnFocus || opts.alwaysShowMask) {\n const display = buildDisplayValue(processed, slots, slotChar, true);\n input.value = display;\n displayValueRef.current = display;\n setMaskedValue(display);\n }\n\n requestAnimationFrame(() => {\n if (input === document.activeElement) {\n clampCursorToProcessed(input);\n }\n });\n }, [clampCursorToProcessed]);\n\n const handleMouseUp = useCallback(() => {\n const input = inputRef.current;\n if (!input || input !== document.activeElement) {\n return;\n }\n\n clampCursorToProcessed(input);\n }, [clampCursorToProcessed]);\n\n const handleMouseDown = useCallback(() => {\n const input = inputRef.current;\n if (!input) {\n return;\n }\n\n requestAnimationFrame(() => {\n if (input !== document.activeElement) {\n return;\n }\n\n const start = input.selectionStart ?? 0;\n const end = input.selectionEnd ?? 0;\n if (start !== end) {\n return;\n }\n\n const opts = optionsRef.current;\n const { slots } = getResolvedOptions(opts, '');\n const processed = processedRef.current;\n const endPos =\n processed.length > 0\n ? findNextEditablePosition(processed.length, slots, processed)\n : findNextTokenIndex(slots, 0);\n\n if (start > endPos) {\n input.setSelectionRange(endPos, endPos);\n }\n });\n }, []);\n\n const handleBlur = useCallback(() => {\n isFocusedRef.current = false;\n const opts = optionsRef.current;\n const input = inputRef.current;\n\n if (!input) {\n return;\n }\n\n const { slots, slotChar } = getResolvedOptions(opts, rawValue);\n const expectedFocusDisplay = buildDisplayValue(processedRef.current, slots, slotChar, true);\n const processed =\n input.value === expectedFocusDisplay\n ? processedRef.current\n : processInput(input.value, slots, slotChar);\n const complete = checkComplete(processed, slots);\n\n if (opts.autoClear && !complete && processed.length > 0) {\n input.value = '';\n processedRef.current = '';\n displayValueRef.current = '';\n rawValueRef.current = '';\n setMaskedValue('');\n setRawValue('');\n wasCompleteRef.current = false;\n\n if (opts.onChangeRaw) {\n opts.onChangeRaw('', '');\n }\n\n if (opts.alwaysShowMask) {\n const emptyDisplay = buildDisplayValue('', slots, slotChar, true);\n input.value = emptyDisplay;\n displayValueRef.current = emptyDisplay;\n setMaskedValue(emptyDisplay);\n }\n return;\n }\n\n if (!opts.alwaysShowMask && !complete) {\n if (extractRaw(processed, slots).length === 0) {\n input.value = '';\n processedRef.current = '';\n displayValueRef.current = '';\n rawValueRef.current = '';\n setMaskedValue('');\n setRawValue('');\n wasCompleteRef.current = false;\n\n if (opts.onChangeRaw) {\n opts.onChangeRaw('', '');\n }\n return;\n }\n\n const display = buildDisplayValue(processed, slots, slotChar, false);\n input.value = display;\n displayValueRef.current = display;\n setMaskedValue(display);\n }\n }, [rawValue]);\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n const input = e.target as HTMLInputElement;\n const opts = optionsRef.current;\n\n const { slots, slotChar, transform } = getResolvedOptions(opts, rawValue);\n const start = input.selectionStart ?? 0;\n const end = input.selectionEnd ?? 0;\n const processed = processedRef.current;\n\n const modifier = e.metaKey || (e.ctrlKey && !e.altKey);\n const key = e.key.toLowerCase();\n\n if (modifier && key === 'z' && !e.shiftKey) {\n e.preventDefault();\n const prev = undoStackRef.current.pop();\n if (!prev) {\n return;\n }\n redoStackRef.current.push({\n rawValue: rawValueRef.current,\n selectionStart: input.selectionStart ?? 0,\n });\n applyHistoryState(prev);\n return;\n }\n\n if (modifier && ((key === 'z' && e.shiftKey) || (key === 'y' && !e.shiftKey))) {\n e.preventDefault();\n const next = redoStackRef.current.pop();\n if (!next) {\n return;\n }\n undoStackRef.current.push({\n rawValue: rawValueRef.current,\n selectionStart: input.selectionStart ?? 0,\n });\n applyHistoryState(next);\n return;\n }\n\n if (e.key === 'Backspace') {\n e.preventDefault();\n\n if (e.metaKey || (e.ctrlKey && !e.altKey)) {\n const clampedStart = Math.min(start, processed.length);\n const afterRaw = extractRaw(processed.slice(clampedStart), slots.slice(clampedStart));\n const newValue = applyMaskToRaw(afterRaw, slots, slotChar, transform);\n pushUndoState();\n updateValue(newValue, 0);\n return;\n }\n\n if (start !== end) {\n const clampedEnd = Math.min(end, processed.length);\n const before = processed.slice(0, start);\n const afterRaw = extractRaw(processed.slice(clampedEnd), slots.slice(clampedEnd));\n const newValue = applyMaskToRaw(\n extractRaw(before, slots) + afterRaw,\n slots,\n slotChar,\n transform\n );\n pushUndoState();\n updateValue(newValue, start);\n return;\n }\n\n if (start === 0) {\n return;\n }\n\n let deletePos = start - 1;\n while (deletePos >= 0 && slots[deletePos] && slots[deletePos].type === 'literal') {\n deletePos--;\n }\n\n if (deletePos < 0) {\n return;\n }\n\n const beforeRaw = extractRaw(processed.slice(0, deletePos), slots.slice(0, deletePos));\n const afterRaw = extractRaw(processed.slice(deletePos + 1), slots.slice(deletePos + 1));\n const newValue = applyMaskToRaw(beforeRaw + afterRaw, slots, slotChar, transform);\n pushUndoState();\n updateValue(newValue, deletePos);\n } else if (e.key === 'Delete') {\n e.preventDefault();\n\n if (start !== end) {\n const clampedEnd = Math.min(end, processed.length);\n const before = processed.slice(0, start);\n const afterRaw = extractRaw(processed.slice(clampedEnd), slots.slice(clampedEnd));\n const newValue = applyMaskToRaw(\n extractRaw(before, slots) + afterRaw,\n slots,\n slotChar,\n transform\n );\n pushUndoState();\n updateValue(newValue, start);\n return;\n }\n\n let deletePos = start;\n while (\n deletePos < slots.length &&\n slots[deletePos] &&\n slots[deletePos].type === 'literal'\n ) {\n deletePos++;\n }\n\n if (deletePos >= processed.length) {\n return;\n }\n\n const beforeRaw = extractRaw(processed.slice(0, start), slots.slice(0, start));\n const afterRaw = extractRaw(processed.slice(deletePos + 1), slots.slice(deletePos + 1));\n const newValue = applyMaskToRaw(beforeRaw + afterRaw, slots, slotChar, transform);\n pushUndoState();\n updateValue(newValue, start);\n } else if (e.key === 'ArrowRight' && !e.shiftKey) {\n const nextPos = findNextEditablePosition(start + 1, slots, input.value);\n if (nextPos !== start + 1) {\n e.preventDefault();\n input.setSelectionRange(nextPos, nextPos);\n }\n } else if (e.key === 'ArrowLeft' && !e.shiftKey) {\n if (start > 0) {\n const prevToken = findPrevTokenIndex(slots, start - 1);\n if (prevToken >= 0 && prevToken !== start - 1) {\n e.preventDefault();\n input.setSelectionRange(prevToken + 1, prevToken + 1);\n }\n }\n } else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {\n e.preventDefault();\n\n let insertPos = Math.min(start, processed.length);\n while (\n insertPos < slots.length &&\n slots[insertPos] &&\n slots[insertPos].type === 'literal'\n ) {\n insertPos++;\n }\n\n if (insertPos >= slots.length) {\n return;\n }\n\n const slot = slots[insertPos];\n const ch = transform ? transform(e.key) : e.key;\n if (!slot.pattern!.test(ch)) {\n return;\n }\n\n const beforeRaw = extractRaw(processed.slice(0, insertPos), slots.slice(0, insertPos));\n const afterRaw =\n start < end\n ? extractRaw(\n processed.slice(Math.min(end, processed.length)),\n slots.slice(Math.min(end, processed.length))\n )\n : extractRaw(processed.slice(insertPos), slots.slice(insertPos));\n const newValue = applyMaskToRaw(beforeRaw + ch + afterRaw, slots, slotChar, transform);\n const newCursorPos = findNextEditablePosition(insertPos + 1, slots, newValue);\n pushUndoState();\n updateValue(newValue, newCursorPos);\n }\n },\n [applyHistoryState, pushUndoState, rawValue, updateValue]\n );\n\n const handlePaste = useCallback(\n (e: ClipboardEvent) => {\n e.preventDefault();\n const input = e.target as HTMLInputElement;\n const opts = optionsRef.current;\n\n const pastedText = e.clipboardData?.getData('text') ?? '';\n const start = input.selectionStart ?? 0;\n const end = input.selectionEnd ?? 0;\n const processed = processedRef.current;\n\n const { slots, slotChar, transform } = getResolvedOptions(opts, '');\n const clampedStart = Math.min(start, processed.length);\n const clampedEnd = Math.min(end, processed.length);\n const beforeRaw = extractRaw(processed.slice(0, clampedStart), slots.slice(0, clampedStart));\n const afterRaw = extractRaw(processed.slice(clampedEnd), slots.slice(clampedEnd));\n const newValue = applyMaskToRaw(\n beforeRaw + pastedText + afterRaw,\n slots,\n slotChar,\n transform\n );\n\n pushUndoState();\n updateValue(newValue);\n\n const maskedPrefix = applyMaskToRaw(beforeRaw + pastedText, slots, slotChar, transform);\n const pasteEndPos = Math.min(maskedPrefix.length, slots.length);\n if (input === document.activeElement) {\n input.setSelectionRange(pasteEndPos, pasteEndPos);\n }\n },\n [pushUndoState, updateValue]\n );\n\n const setAriaAttributes = useCallback((input: HTMLInputElement) => {\n const opts = optionsRef.current;\n\n if (opts.invalid) {\n input.setAttribute('aria-invalid', 'true');\n } else {\n input.removeAttribute('aria-invalid');\n }\n }, []);\n\n const refCallback = useCallback(\n (node: HTMLInputElement | null) => {\n const prevInput = inputRef.current;\n\n if (prevInput) {\n prevInput.removeEventListener('input', handleInput);\n prevInput.removeEventListener('focus', handleFocus);\n prevInput.removeEventListener('blur', handleBlur);\n prevInput.removeEventListener('mousedown', handleMouseDown);\n prevInput.removeEventListener('mouseup', handleMouseUp);\n prevInput.removeEventListener('keydown', handleKeyDown as EventListener);\n prevInput.removeEventListener('paste', handlePaste as EventListener);\n }\n\n inputRef.current = node;\n\n if (node) {\n node.addEventListener('input', handleInput);\n node.addEventListener('focus', handleFocus);\n node.addEventListener('blur', handleBlur);\n node.addEventListener('mousedown', handleMouseDown);\n node.addEventListener('mouseup', handleMouseUp);\n node.addEventListener('keydown', handleKeyDown as EventListener);\n node.addEventListener('paste', handlePaste as EventListener);\n\n setAriaAttributes(node);\n\n if (options.alwaysShowMask && !node.value) {\n const { slots, slotChar } = getResolvedOptions(options, '');\n const display = buildDisplayValue('', slots, slotChar, true);\n node.value = display;\n displayValueRef.current = display;\n setMaskedValue(display);\n }\n }\n },\n [\n handleInput,\n handleFocus,\n handleBlur,\n handleMouseDown,\n handleMouseUp,\n handleKeyDown,\n handlePaste,\n setAriaAttributes,\n options,\n ]\n );\n\n useEffect(() => {\n const input = inputRef.current;\n if (!input) {\n return;\n }\n\n setAriaAttributes(input);\n }, [options.invalid, setAriaAttributes]);\n\n const isComplete = (() => {\n const { slots } = getOptions();\n return checkComplete(processedRef.current, slots);\n })();\n\n const reset = useCallback(() => {\n const opts = optionsRef.current;\n const input = inputRef.current;\n\n processedRef.current = '';\n displayValueRef.current = '';\n rawValueRef.current = '';\n undoStackRef.current = [];\n redoStackRef.current = [];\n setMaskedValue('');\n setRawValue('');\n wasCompleteRef.current = false;\n\n if (input) {\n if (opts.alwaysShowMask) {\n const { slots, slotChar } = getResolvedOptions(opts, '');\n const display = buildDisplayValue('', slots, slotChar, true);\n input.value = display;\n displayValueRef.current = display;\n setMaskedValue(display);\n } else {\n input.value = '';\n }\n }\n\n if (opts.onChangeRaw) {\n opts.onChangeRaw('', '');\n }\n }, []);\n\n return {\n ref: refCallback,\n value: maskedValue,\n rawValue,\n isComplete,\n reset,\n };\n}\n\nfunction findNextEditablePosition(from: number, slots: MaskSlot[], value: string): number {\n let pos = from;\n while (pos < slots.length && pos < value.length && slots[pos] && slots[pos].type === 'literal') {\n pos++;\n }\n return pos;\n}\n\nexport namespace useMask {\n export type Options = UseMaskOptions;\n export type ReturnValue = UseMaskReturnValue;\n}\n"],"mappings":";;;AAEA,MAAM,iBAAyC;CAC7C,KAAK;CACL,GAAG;CACH,GAAG;CACH,KAAK;CACL,KAAK;AACP;AAmFA,MAAM,mBAAmB;AAEzB,SAAS,UACP,MACA,QACY;CACZ,IAAI,MAAM,QAAQ,IAAI,GACpB,OAAO,KAAK,KAAK,SAAS;EACxB,IAAI,gBAAgB,QAClB,OAAO;GAAE,MAAM;GAAS,MAAM;GAAK,SAAS;EAAK;EAEnD,OAAO;GAAE,MAAM;GAAW,MAAM;EAAK;CACvC,CAAC;CAGH,MAAM,QAAoB,CAAC;CAC3B,IAAI,WAAW;CAEf,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,OAAO,KAAK;EAElB,IAAI,SAAS,QAAQ,IAAI,IAAI,KAAK,QAAQ;GACxC;GACA,MAAM,KAAK;IAAE,MAAM;IAAW,MAAM,KAAK;GAAG,CAAC;GAC7C;EACF;EAEA,IAAI,SAAS,KAAK;GAChB,WAAW;GACX;EACF;EAEA,IAAI,OAAO,OACT,MAAM,KAAK;GAAE,MAAM;GAAS;GAAM,SAAS,OAAO;GAAO;EAAS,CAAC;OAEnE,MAAM,KAAK;GAAE,MAAM;GAAW;GAAM;EAAS,CAAC;CAElD;CAEA,OAAO;AACT;AAEA,SAAS,YAAY,gBAA2C,OAAuB;CACrF,IAAI,mBAAmB,QAAQ,mBAAmB,MAAM,mBA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Ae,OAAO;GACxB;EACF;CACF,GACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAEA,gBAAgB;EACd,MAAM,QAAQ,SAAS;EACvB,IAAI,CAAC,OACH;EAGF,kBAAkB,KAAK;CACzB,GAAG,CAAC,QAAQ,SAAS,iBAAiB,CAAC;CAqCvC,OAAO;EACL,KAAK;EACL,OAAO;EACP;EACA,mBAvCwB;GACxB,MAAM,EAAE,UAAU,WAAW;GAC7B,OAAO,cAAc,aAAa,SAAS,KAAK;EAClD,GAoCW;EACT,OAnCY,kBAAkB;GAC9B,MAAM,OAAO,WAAW;GACxB,MAAM,QAAQ,SAAS;GAEvB,aAAa,UAAU;GACvB,gBAAgB,UAAU;GAC1B,YAAY,UAAU;GACtB,aAAa,UAAU,CAAC;GACxB,aAAa,UAAU,CAAC;GACxB,eAAe,EAAE;GACjB,YAAY,EAAE;GACd,eAAe,UAAU;GAEzB,IAAI,OACF,IAAI,KAAK,gBAAgB;IACvB,MAAM,EAAE,OAAO,aAAa,mBAAmB,MAAM,EAAE;IACvD,MAAM,UAAU,kBAAkB,IAAI,OAAO,UAAU,IAAI;IAC3D,MAAM,QAAQ;IACd,gBAAgB,UAAU;IAC1B,eAAe,OAAO;GACxB,OACE,MAAM,QAAQ;GAIlB,IAAI,KAAK,aACP,KAAK,YAAY,IAAI,EAAE;EAE3B,GAAG,CAAC,CAOE;CACN;AACF;AAEA,SAAS,yBAAyB,MAAc,OAAmB,OAAuB;CACxF,IAAI,MAAM;CACV,OAAO,MAAM,MAAM,UAAU,MAAM,MAAM,UAAU,MAAM,QAAQ,MAAM,KAAK,SAAS,WACnF;CAEF,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"use-mask.mjs","names":[],"sources":["../../src/use-mask/use-mask.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nconst DEFAULT_TOKENS: Record<string, RegExp> = {\n '9': /[0-9]/,\n a: /[A-Za-z]/,\n A: /[A-Z]/,\n '*': /[A-Za-z0-9]/,\n '#': /[-+0-9]/,\n};\n\nexport interface UseMaskOptions {\n /** Mask pattern string or array of string literals and RegExp objects */\n mask: string | Array<string | RegExp>;\n\n /** Override or extend the default token map */\n tokens?: Record<string, RegExp>;\n\n /** Called before masking on each keystroke, can return overrides for mask options */\n modify?: (\n value: string\n ) => Partial<Pick<UseMaskOptions, 'mask' | 'tokens' | 'slotChar' | 'separate'>> | undefined;\n\n /** When true, raw and display values are decoupled */\n separate?: boolean;\n\n /** Character displayed in unfilled slots, `\"_\"` by default */\n slotChar?: string | null;\n\n /** Show mask pattern even when field is empty and unfocused */\n alwaysShowMask?: boolean;\n\n /** Show mask placeholder on focus, `true` by default */\n showMaskOnFocus?: boolean;\n\n /** Transform each character before validation and insertion */\n transform?: (char: string) => string;\n\n /** Clear value on blur when mask is incomplete, `false` by default */\n autoClear?: boolean;\n\n /** Sets aria-invalid on the input */\n invalid?: boolean;\n\n /** Called on every change with raw and masked values */\n onChangeRaw?: (rawValue: string, maskedValue: string) => void;\n\n /** Called when all required mask slots are filled */\n onComplete?: (maskedValue: string, rawValue: string) => void;\n\n /** Escape hatch for advanced cursor/value manipulation */\n beforeMaskedStateChange?: (states: {\n previousState: MaskState;\n currentState: MaskState;\n nextState: MaskState;\n }) => MaskState;\n}\n\nexport interface MaskState {\n value: string;\n selection: { start: number; end: number } | null;\n}\n\nexport interface UseMaskReturnValue {\n /** Ref to attach to the input element */\n ref: React.RefCallback<HTMLInputElement>;\n\n /** Current masked display value */\n value: string;\n\n /** Current raw unmasked value */\n rawValue: string;\n\n /** Whether all required mask slots are filled */\n isComplete: boolean;\n\n /** Clear the input value and reset state */\n reset: () => void;\n}\n\ninterface MaskSlot {\n type: 'token' | 'literal';\n char: string;\n pattern?: RegExp;\n optional?: boolean;\n}\n\ninterface UndoState {\n rawValue: string;\n selectionStart: number;\n}\n\nconst MAX_UNDO_HISTORY = 100;\n\nfunction parseMask(\n mask: string | Array<string | RegExp>,\n tokens: Record<string, RegExp>\n): MaskSlot[] {\n if (Array.isArray(mask)) {\n return mask.map((item) => {\n if (item instanceof RegExp) {\n return { type: 'token', char: '_', pattern: item };\n }\n return { type: 'literal', char: item };\n });\n }\n\n const slots: MaskSlot[] = [];\n let optional = false;\n\n for (let i = 0; i < mask.length; i++) {\n const char = mask[i];\n\n if (char === '\\\\' && i + 1 < mask.length) {\n i++;\n slots.push({ type: 'literal', char: mask[i] });\n continue;\n }\n\n if (char === '?') {\n optional = true;\n continue;\n }\n\n if (tokens[char]) {\n slots.push({ type: 'token', char, pattern: tokens[char], optional });\n } else {\n slots.push({ type: 'literal', char, optional });\n }\n }\n\n return slots;\n}\n\nfunction getSlotChar(slotCharOption: string | null | undefined, index: number): string {\n if (slotCharOption === null || slotCharOption === '' || slotCharOption === undefined) {\n return '';\n }\n if (slotCharOption.length > 1) {\n return slotCharOption[index] || '_';\n }\n return slotCharOption;\n}\n\nfunction applyMaskToRaw(\n raw: string,\n slots: MaskSlot[],\n _slotCharOption: string | null | undefined,\n transform?: (char: string) => string\n): string {\n let result = '';\n let rawIndex = 0;\n let slotIndex = 0;\n\n for (slotIndex = 0; slotIndex < slots.length; slotIndex++) {\n const slot = slots[slotIndex];\n if (slot.type === 'literal') {\n result += slot.char;\n } else if (rawIndex < raw.length) {\n const ch = transform ? transform(raw[rawIndex]) : raw[rawIndex];\n if (slot.pattern && slot.pattern.test(ch)) {\n result += ch;\n rawIndex++;\n } else {\n rawIndex++;\n slotIndex--;\n }\n } else {\n break;\n }\n }\n\n return result;\n}\n\nfunction buildDisplayValue(\n value: string,\n slots: MaskSlot[],\n slotCharOption: string | null | undefined,\n showSlots: boolean\n): string {\n if (!showSlots) {\n return value;\n }\n\n let display = value;\n\n for (let i = value.length; i < slots.length; i++) {\n const slot = slots[i];\n if (slot.type === 'literal') {\n display += slot.char;\n } else {\n const sc = getSlotChar(slotCharOption, i);\n if (!sc) {\n break;\n }\n display += sc;\n }\n }\n\n return display;\n}\n\nfunction extractRaw(masked: string, slots: MaskSlot[]): string {\n let raw = '';\n for (let i = 0; i < masked.length && i < slots.length; i++) {\n if (slots[i].type === 'token') {\n raw += masked[i];\n }\n }\n return raw;\n}\n\nfunction checkComplete(masked: string, slots: MaskSlot[]): boolean {\n for (let i = 0; i < slots.length; i++) {\n if (slots[i].type === 'token' && !slots[i].optional) {\n if (i >= masked.length) {\n return false;\n }\n if (!slots[i].pattern!.test(masked[i])) {\n return false;\n }\n }\n }\n return true;\n}\n\nfunction findNextTokenIndex(slots: MaskSlot[], from: number): number {\n for (let i = from; i < slots.length; i++) {\n if (slots[i].type === 'token') {\n return i;\n }\n }\n return slots.length;\n}\n\nfunction findPrevTokenIndex(slots: MaskSlot[], from: number): number {\n for (let i = from; i >= 0; i--) {\n if (slots[i].type === 'token') {\n return i;\n }\n }\n return -1;\n}\n\nfunction processInput(\n inputValue: string,\n slots: MaskSlot[],\n _slotCharOption: string | null | undefined\n): string {\n let result = '';\n let inputIndex = 0;\n\n for (\n let slotIndex = 0;\n slotIndex < slots.length && inputIndex <= inputValue.length;\n slotIndex++\n ) {\n const slot = slots[slotIndex];\n\n if (slot.type === 'literal') {\n result += slot.char;\n if (inputIndex < inputValue.length && inputValue[inputIndex] === slot.char) {\n inputIndex++;\n }\n continue;\n }\n\n if (inputIndex >= inputValue.length) {\n break;\n }\n\n while (inputIndex < inputValue.length) {\n const ch = inputValue[inputIndex];\n inputIndex++;\n\n if (slot.pattern!.test(ch)) {\n result += ch;\n break;\n }\n }\n\n if (result.length <= slotIndex) {\n break;\n }\n }\n\n return result;\n}\n\nfunction getResolvedOptions(options: UseMaskOptions, rawValue: string) {\n const tokens = { ...DEFAULT_TOKENS, ...options.tokens };\n let mask = options.mask;\n let slotChar: string | null | undefined = options.slotChar === undefined ? '_' : options.slotChar;\n let separate = options.separate ?? false;\n\n if (options.modify) {\n const overrides = options.modify(rawValue);\n if (overrides) {\n if (overrides.mask !== undefined) {\n mask = overrides.mask;\n }\n if (overrides.tokens !== undefined) {\n Object.assign(tokens, overrides.tokens);\n }\n if (overrides.slotChar !== undefined) {\n slotChar = overrides.slotChar;\n }\n if (overrides.separate !== undefined) {\n separate = overrides.separate;\n }\n }\n }\n\n const slots = parseMask(mask, tokens);\n return { slots, slotChar, separate, tokens, transform: options.transform };\n}\n\nexport function formatMask(raw: string, options: UseMaskOptions): string {\n const { slots, slotChar, transform } = getResolvedOptions(options, raw);\n return applyMaskToRaw(raw, slots, slotChar, transform);\n}\n\nexport function unformatMask(masked: string, options: UseMaskOptions): string {\n const { slots } = getResolvedOptions(options, '');\n return extractRaw(masked, slots);\n}\n\nexport function isMaskComplete(masked: string, options: UseMaskOptions): boolean {\n const { slots } = getResolvedOptions(options, '');\n return checkComplete(masked, slots);\n}\n\nexport function generatePattern(mode: 'full' | 'full-inexact', options: UseMaskOptions): string {\n const { slots } = getResolvedOptions(options, '');\n let pattern = '';\n\n for (const slot of slots) {\n if (slot.type === 'literal') {\n pattern += slot.char.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n } else {\n const src = slot.pattern!.source;\n if (mode === 'full-inexact') {\n pattern += slot.optional ? `${src}?` : src;\n } else {\n pattern += slot.optional ? `(${src})?` : `(${src})`;\n }\n }\n }\n\n return pattern;\n}\n\nexport function useMask(options: UseMaskOptions): UseMaskReturnValue {\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n const inputRef = useRef<HTMLInputElement | null>(null);\n const [maskedValue, setMaskedValue] = useState('');\n const [rawValue, setRawValue] = useState('');\n const processedRef = useRef('');\n const displayValueRef = useRef('');\n const rawValueRef = useRef('');\n const wasCompleteRef = useRef(false);\n const isFocusedRef = useRef(false);\n const undoStackRef = useRef<UndoState[]>([]);\n const redoStackRef = useRef<UndoState[]>([]);\n\n const getOptions = useCallback(() => {\n const opts = optionsRef.current;\n return getResolvedOptions(opts, rawValue);\n }, [rawValue]);\n\n const applyValue = useCallback(\n ({\n reprocessed,\n newRaw,\n displayValue,\n resolvedSlots,\n cursorPos,\n notifyChange,\n }: {\n reprocessed: string;\n newRaw: string;\n displayValue: string;\n resolvedSlots: MaskSlot[];\n cursorPos?: number;\n notifyChange: boolean;\n }) => {\n const opts = optionsRef.current;\n\n processedRef.current = reprocessed;\n displayValueRef.current = displayValue;\n rawValueRef.current = newRaw;\n setMaskedValue(displayValue);\n setRawValue(newRaw);\n\n if (inputRef.current) {\n inputRef.current.value = displayValue;\n if (cursorPos !== undefined && document.activeElement === inputRef.current) {\n const pos = Math.min(cursorPos, reprocessed.length);\n inputRef.current.setSelectionRange(pos, pos);\n }\n }\n\n if (notifyChange && opts.onChangeRaw) {\n opts.onChangeRaw(newRaw, displayValue);\n }\n\n const complete = checkComplete(reprocessed, resolvedSlots);\n if (notifyChange && complete && !wasCompleteRef.current && opts.onComplete) {\n opts.onComplete(displayValue, newRaw);\n }\n wasCompleteRef.current = complete;\n },\n []\n );\n\n const updateValue = useCallback(\n (newMasked: string, cursorPos?: number) => {\n const opts = optionsRef.current;\n const { slots } = getResolvedOptions(\n opts,\n extractRaw(newMasked, getResolvedOptions(opts, '').slots)\n );\n const raw = extractRaw(newMasked, slots);\n\n const { slots: resolvedSlots, slotChar } = getResolvedOptions(opts, raw);\n\n const reprocessed = processInput(newMasked, resolvedSlots, slotChar);\n const newRaw = extractRaw(reprocessed, resolvedSlots);\n\n const showSlots = opts.alwaysShowMask || isFocusedRef.current;\n const showOnFocus = opts.showMaskOnFocus !== false;\n const shouldShowSlots = showSlots && (showOnFocus || reprocessed.length > 0);\n\n const displayValue = buildDisplayValue(reprocessed, resolvedSlots, slotChar, shouldShowSlots);\n\n applyValue({\n reprocessed,\n newRaw,\n displayValue,\n resolvedSlots,\n cursorPos,\n notifyChange: true,\n });\n\n return { displayValue, newRaw, reprocessed, resolvedSlots };\n },\n [applyValue, getOptions]\n );\n\n const initializeInputValue = useCallback(\n (node: HTMLInputElement) => {\n const opts = optionsRef.current;\n\n if (!node.value) {\n return false;\n }\n\n const { slots: initialSlots, slotChar: initialSlotChar } = getResolvedOptions(opts, '');\n const initialProcessed = processInput(node.value, initialSlots, initialSlotChar);\n const initialRaw = extractRaw(initialProcessed, initialSlots);\n const { slots: resolvedSlots, slotChar } = getResolvedOptions(opts, initialRaw);\n const reprocessed = processInput(node.value, resolvedSlots, slotChar);\n const newRaw = extractRaw(reprocessed, resolvedSlots);\n const showSlots = opts.alwaysShowMask || isFocusedRef.current;\n const showOnFocus = opts.showMaskOnFocus !== false;\n const shouldShowSlots = showSlots && (showOnFocus || reprocessed.length > 0);\n const displayValue = buildDisplayValue(reprocessed, resolvedSlots, slotChar, shouldShowSlots);\n\n applyValue({\n reprocessed,\n newRaw,\n displayValue,\n resolvedSlots,\n notifyChange: false,\n });\n\n return true;\n },\n [applyValue]\n );\n\n const pushUndoState = useCallback(() => {\n const input = inputRef.current;\n const selectionStart = input?.selectionStart ?? rawValueRef.current.length;\n const state: UndoState = {\n rawValue: rawValueRef.current,\n selectionStart,\n };\n const stack = undoStackRef.current;\n const top = stack[stack.length - 1];\n if (top && top.rawValue === state.rawValue && top.selectionStart === state.selectionStart) {\n return;\n }\n stack.push(state);\n if (stack.length > MAX_UNDO_HISTORY) {\n stack.shift();\n }\n redoStackRef.current = [];\n }, []);\n\n const applyHistoryState = useCallback(\n (target: UndoState) => {\n const opts = optionsRef.current;\n const { slots, slotChar, transform } = getResolvedOptions(opts, target.rawValue);\n const newMasked = applyMaskToRaw(target.rawValue, slots, slotChar, transform);\n updateValue(newMasked, target.selectionStart);\n },\n [updateValue]\n );\n\n const handleInput = useCallback(\n (e: Event) => {\n const input = e.target as HTMLInputElement;\n const opts = optionsRef.current;\n\n const { slots: resolvedSlots, slotChar, transform } = getResolvedOptions(opts, '');\n const prev = displayValueRef.current;\n const curr = input.value;\n\n let prefixLen = 0;\n const maxPrefix = Math.min(prev.length, curr.length);\n while (prefixLen < maxPrefix && prev[prefixLen] === curr[prefixLen]) {\n prefixLen++;\n }\n\n let suffixLen = 0;\n const maxSuffix = Math.min(prev.length - prefixLen, curr.length - prefixLen);\n while (\n suffixLen < maxSuffix &&\n prev[prev.length - 1 - suffixLen] === curr[curr.length - 1 - suffixLen]\n ) {\n suffixLen++;\n }\n\n const insertedText = curr.slice(prefixLen, curr.length - suffixLen);\n const removedEnd = prev.length - suffixLen;\n\n const beforeRaw = extractRaw(prev.slice(0, prefixLen), resolvedSlots.slice(0, prefixLen));\n const afterRaw = extractRaw(prev.slice(removedEnd), resolvedSlots.slice(removedEnd));\n const reformatted = applyMaskToRaw(\n beforeRaw + insertedText + afterRaw,\n resolvedSlots,\n slotChar,\n transform\n );\n const maskedPrefix = applyMaskToRaw(\n beforeRaw + insertedText,\n resolvedSlots,\n slotChar,\n transform\n );\n\n if (reformatted !== prev) {\n pushUndoState();\n }\n updateValue(reformatted, maskedPrefix.length);\n },\n [pushUndoState, updateValue]\n );\n\n const clampCursorToProcessed = useCallback((input: HTMLInputElement) => {\n const start = input.selectionStart ?? 0;\n const end = input.selectionEnd ?? 0;\n if (start !== end) {\n return;\n }\n\n const opts = optionsRef.current;\n const { slots } = getResolvedOptions(opts, '');\n const processed = processedRef.current;\n const endPos =\n processed.length > 0\n ? findNextEditablePosition(processed.length, slots, processed)\n : findNextTokenIndex(slots, 0);\n const startPos = findNextTokenIndex(slots, 0);\n\n if (start > endPos || start < startPos) {\n input.setSelectionRange(endPos, endPos);\n }\n }, []);\n\n const handleFocus = useCallback(() => {\n isFocusedRef.current = true;\n const opts = optionsRef.current;\n const input = inputRef.current;\n\n if (!input) {\n return;\n }\n\n const { slots, slotChar } = getResolvedOptions(opts, '');\n const showOnFocus = opts.showMaskOnFocus !== false;\n const processed = processedRef.current;\n\n if (showOnFocus || opts.alwaysShowMask) {\n const display = buildDisplayValue(processed, slots, slotChar, true);\n input.value = display;\n displayValueRef.current = display;\n setMaskedValue(display);\n }\n\n requestAnimationFrame(() => {\n if (input === document.activeElement) {\n clampCursorToProcessed(input);\n }\n });\n }, [clampCursorToProcessed]);\n\n const handleMouseUp = useCallback(() => {\n const input = inputRef.current;\n if (!input || input !== document.activeElement) {\n return;\n }\n\n clampCursorToProcessed(input);\n }, [clampCursorToProcessed]);\n\n const handleMouseDown = useCallback(() => {\n const input = inputRef.current;\n if (!input) {\n return;\n }\n\n requestAnimationFrame(() => {\n if (input !== document.activeElement) {\n return;\n }\n\n const start = input.selectionStart ?? 0;\n const end = input.selectionEnd ?? 0;\n if (start !== end) {\n return;\n }\n\n const opts = optionsRef.current;\n const { slots } = getResolvedOptions(opts, '');\n const processed = processedRef.current;\n const endPos =\n processed.length > 0\n ? findNextEditablePosition(processed.length, slots, processed)\n : findNextTokenIndex(slots, 0);\n\n if (start > endPos) {\n input.setSelectionRange(endPos, endPos);\n }\n });\n }, []);\n\n const handleBlur = useCallback(() => {\n isFocusedRef.current = false;\n const opts = optionsRef.current;\n const input = inputRef.current;\n\n if (!input) {\n return;\n }\n\n const { slots, slotChar } = getResolvedOptions(opts, rawValue);\n const expectedFocusDisplay = buildDisplayValue(processedRef.current, slots, slotChar, true);\n const processed =\n input.value === expectedFocusDisplay\n ? processedRef.current\n : processInput(input.value, slots, slotChar);\n const complete = checkComplete(processed, slots);\n\n if (opts.autoClear && !complete && processed.length > 0) {\n input.value = '';\n processedRef.current = '';\n displayValueRef.current = '';\n rawValueRef.current = '';\n setMaskedValue('');\n setRawValue('');\n wasCompleteRef.current = false;\n\n if (opts.onChangeRaw) {\n opts.onChangeRaw('', '');\n }\n\n if (opts.alwaysShowMask) {\n const emptyDisplay = buildDisplayValue('', slots, slotChar, true);\n input.value = emptyDisplay;\n displayValueRef.current = emptyDisplay;\n setMaskedValue(emptyDisplay);\n }\n return;\n }\n\n if (!opts.alwaysShowMask && !complete) {\n if (extractRaw(processed, slots).length === 0) {\n input.value = '';\n processedRef.current = '';\n displayValueRef.current = '';\n rawValueRef.current = '';\n setMaskedValue('');\n setRawValue('');\n wasCompleteRef.current = false;\n\n if (opts.onChangeRaw) {\n opts.onChangeRaw('', '');\n }\n return;\n }\n\n const display = buildDisplayValue(processed, slots, slotChar, false);\n input.value = display;\n displayValueRef.current = display;\n setMaskedValue(display);\n }\n }, [rawValue]);\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n const input = e.target as HTMLInputElement;\n const opts = optionsRef.current;\n\n const { slots, slotChar, transform } = getResolvedOptions(opts, rawValue);\n const start = input.selectionStart ?? 0;\n const end = input.selectionEnd ?? 0;\n const processed = processedRef.current;\n\n const modifier = e.metaKey || (e.ctrlKey && !e.altKey);\n const key = e.key.toLowerCase();\n\n if (modifier && key === 'z' && !e.shiftKey) {\n e.preventDefault();\n const prev = undoStackRef.current.pop();\n if (!prev) {\n return;\n }\n redoStackRef.current.push({\n rawValue: rawValueRef.current,\n selectionStart: input.selectionStart ?? 0,\n });\n applyHistoryState(prev);\n return;\n }\n\n if (modifier && ((key === 'z' && e.shiftKey) || (key === 'y' && !e.shiftKey))) {\n e.preventDefault();\n const next = redoStackRef.current.pop();\n if (!next) {\n return;\n }\n undoStackRef.current.push({\n rawValue: rawValueRef.current,\n selectionStart: input.selectionStart ?? 0,\n });\n applyHistoryState(next);\n return;\n }\n\n if (e.key === 'Backspace') {\n e.preventDefault();\n\n if (e.metaKey || (e.ctrlKey && !e.altKey)) {\n const clampedStart = Math.min(start, processed.length);\n const afterRaw = extractRaw(processed.slice(clampedStart), slots.slice(clampedStart));\n const newValue = applyMaskToRaw(afterRaw, slots, slotChar, transform);\n pushUndoState();\n updateValue(newValue, 0);\n return;\n }\n\n if (start !== end) {\n const clampedEnd = Math.min(end, processed.length);\n const before = processed.slice(0, start);\n const afterRaw = extractRaw(processed.slice(clampedEnd), slots.slice(clampedEnd));\n const newValue = applyMaskToRaw(\n extractRaw(before, slots) + afterRaw,\n slots,\n slotChar,\n transform\n );\n pushUndoState();\n updateValue(newValue, start);\n return;\n }\n\n if (start === 0) {\n return;\n }\n\n let deletePos = start - 1;\n while (deletePos >= 0 && slots[deletePos] && slots[deletePos].type === 'literal') {\n deletePos--;\n }\n\n if (deletePos < 0) {\n return;\n }\n\n const beforeRaw = extractRaw(processed.slice(0, deletePos), slots.slice(0, deletePos));\n const afterRaw = extractRaw(processed.slice(deletePos + 1), slots.slice(deletePos + 1));\n const newValue = applyMaskToRaw(beforeRaw + afterRaw, slots, slotChar, transform);\n pushUndoState();\n updateValue(newValue, deletePos);\n } else if (e.key === 'Delete') {\n e.preventDefault();\n\n if (start !== end) {\n const clampedEnd = Math.min(end, processed.length);\n const before = processed.slice(0, start);\n const afterRaw = extractRaw(processed.slice(clampedEnd), slots.slice(clampedEnd));\n const newValue = applyMaskToRaw(\n extractRaw(before, slots) + afterRaw,\n slots,\n slotChar,\n transform\n );\n pushUndoState();\n updateValue(newValue, start);\n return;\n }\n\n let deletePos = start;\n while (\n deletePos < slots.length &&\n slots[deletePos] &&\n slots[deletePos].type === 'literal'\n ) {\n deletePos++;\n }\n\n if (deletePos >= processed.length) {\n return;\n }\n\n const beforeRaw = extractRaw(processed.slice(0, start), slots.slice(0, start));\n const afterRaw = extractRaw(processed.slice(deletePos + 1), slots.slice(deletePos + 1));\n const newValue = applyMaskToRaw(beforeRaw + afterRaw, slots, slotChar, transform);\n pushUndoState();\n updateValue(newValue, start);\n } else if (e.key === 'ArrowRight' && !e.shiftKey) {\n const nextPos = findNextEditablePosition(start + 1, slots, input.value);\n if (nextPos !== start + 1) {\n e.preventDefault();\n input.setSelectionRange(nextPos, nextPos);\n }\n } else if (e.key === 'ArrowLeft' && !e.shiftKey) {\n if (start > 0) {\n const prevToken = findPrevTokenIndex(slots, start - 1);\n if (prevToken >= 0 && prevToken !== start - 1) {\n e.preventDefault();\n input.setSelectionRange(prevToken + 1, prevToken + 1);\n }\n }\n } else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {\n e.preventDefault();\n\n let insertPos = Math.min(start, processed.length);\n while (\n insertPos < slots.length &&\n slots[insertPos] &&\n slots[insertPos].type === 'literal'\n ) {\n insertPos++;\n }\n\n if (insertPos >= slots.length) {\n return;\n }\n\n const slot = slots[insertPos];\n const ch = transform ? transform(e.key) : e.key;\n if (!slot.pattern!.test(ch)) {\n return;\n }\n\n const beforeRaw = extractRaw(processed.slice(0, insertPos), slots.slice(0, insertPos));\n const afterRaw =\n start < end\n ? extractRaw(\n processed.slice(Math.min(end, processed.length)),\n slots.slice(Math.min(end, processed.length))\n )\n : extractRaw(processed.slice(insertPos), slots.slice(insertPos));\n const newValue = applyMaskToRaw(beforeRaw + ch + afterRaw, slots, slotChar, transform);\n const newCursorPos = findNextEditablePosition(insertPos + 1, slots, newValue);\n pushUndoState();\n updateValue(newValue, newCursorPos);\n }\n },\n [applyHistoryState, pushUndoState, rawValue, updateValue]\n );\n\n const handlePaste = useCallback(\n (e: ClipboardEvent) => {\n e.preventDefault();\n const input = e.target as HTMLInputElement;\n const opts = optionsRef.current;\n\n const pastedText = e.clipboardData?.getData('text') ?? '';\n const start = input.selectionStart ?? 0;\n const end = input.selectionEnd ?? 0;\n const processed = processedRef.current;\n\n const { slots, slotChar, transform } = getResolvedOptions(opts, '');\n const clampedStart = Math.min(start, processed.length);\n const clampedEnd = Math.min(end, processed.length);\n const beforeRaw = extractRaw(processed.slice(0, clampedStart), slots.slice(0, clampedStart));\n const afterRaw = extractRaw(processed.slice(clampedEnd), slots.slice(clampedEnd));\n const newValue = applyMaskToRaw(\n beforeRaw + pastedText + afterRaw,\n slots,\n slotChar,\n transform\n );\n\n pushUndoState();\n updateValue(newValue);\n\n const maskedPrefix = applyMaskToRaw(beforeRaw + pastedText, slots, slotChar, transform);\n const pasteEndPos = Math.min(maskedPrefix.length, slots.length);\n if (input === document.activeElement) {\n input.setSelectionRange(pasteEndPos, pasteEndPos);\n }\n },\n [pushUndoState, updateValue]\n );\n\n const setAriaAttributes = useCallback((input: HTMLInputElement) => {\n const opts = optionsRef.current;\n\n if (opts.invalid) {\n input.setAttribute('aria-invalid', 'true');\n } else {\n input.removeAttribute('aria-invalid');\n }\n }, []);\n\n const refCallback = useCallback(\n (node: HTMLInputElement | null) => {\n const prevInput = inputRef.current;\n\n if (prevInput) {\n prevInput.removeEventListener('input', handleInput);\n prevInput.removeEventListener('focus', handleFocus);\n prevInput.removeEventListener('blur', handleBlur);\n prevInput.removeEventListener('mousedown', handleMouseDown);\n prevInput.removeEventListener('mouseup', handleMouseUp);\n prevInput.removeEventListener('keydown', handleKeyDown as EventListener);\n prevInput.removeEventListener('paste', handlePaste as EventListener);\n }\n\n inputRef.current = node;\n\n if (node) {\n node.addEventListener('input', handleInput);\n node.addEventListener('focus', handleFocus);\n node.addEventListener('blur', handleBlur);\n node.addEventListener('mousedown', handleMouseDown);\n node.addEventListener('mouseup', handleMouseUp);\n node.addEventListener('keydown', handleKeyDown as EventListener);\n node.addEventListener('paste', handlePaste as EventListener);\n\n setAriaAttributes(node);\n\n const hasInitialValue = initializeInputValue(node);\n\n if (options.alwaysShowMask && !hasInitialValue) {\n const { slots, slotChar } = getResolvedOptions(options, '');\n const display = buildDisplayValue('', slots, slotChar, true);\n node.value = display;\n displayValueRef.current = display;\n setMaskedValue(display);\n }\n }\n },\n [\n handleInput,\n handleFocus,\n handleBlur,\n handleMouseDown,\n handleMouseUp,\n handleKeyDown,\n handlePaste,\n initializeInputValue,\n setAriaAttributes,\n options,\n ]\n );\n\n useEffect(() => {\n const input = inputRef.current;\n if (!input) {\n return;\n }\n\n setAriaAttributes(input);\n }, [options.invalid, setAriaAttributes]);\n\n const isComplete = (() => {\n const { slots } = getOptions();\n return checkComplete(processedRef.current, slots);\n })();\n\n const reset = useCallback(() => {\n const opts = optionsRef.current;\n const input = inputRef.current;\n\n processedRef.current = '';\n displayValueRef.current = '';\n rawValueRef.current = '';\n undoStackRef.current = [];\n redoStackRef.current = [];\n setMaskedValue('');\n setRawValue('');\n wasCompleteRef.current = false;\n\n if (input) {\n if (opts.alwaysShowMask) {\n const { slots, slotChar } = getResolvedOptions(opts, '');\n const display = buildDisplayValue('', slots, slotChar, true);\n input.value = display;\n displayValueRef.current = display;\n setMaskedValue(display);\n } else {\n input.value = '';\n }\n }\n\n if (opts.onChangeRaw) {\n opts.onChangeRaw('', '');\n }\n }, []);\n\n return {\n ref: refCallback,\n value: maskedValue,\n rawValue,\n isComplete,\n reset,\n };\n}\n\nfunction findNextEditablePosition(from: number, slots: MaskSlot[], value: string): number {\n let pos = from;\n while (pos < slots.length && pos < value.length && slots[pos] && slots[pos].type === 'literal') {\n pos++;\n }\n return pos;\n}\n\nexport namespace useMask {\n export type Options = UseMaskOptions;\n export type ReturnValue = UseMaskReturnValue;\n}\n"],"mappings":";;;AAEA,MAAM,iBAAyC;CAC7C,KAAK;CACL,GAAG;CACH,GAAG;CACH,KAAK;CACL,KAAK;AACP;AAmFA,MAAM,mBAAmB;AAEzB,SAAS,UACP,MACA,QACY;CACZ,IAAI,MAAM,QAAQ,IAAI,GACpB,OAAO,KAAK,KAAK,SAAS;EACxB,IAAI,gBAAgB,QAClB,OAAO;GAAE,MAAM;GAAS,MAAM;GAAK,SAAS;EAAK;EAEnD,OAAO;GAAE,MAAM;GAAW,MAAM;EAAK;CACvC,CAAC;CAGH,MAAM,QAAoB,CAAC;CAC3B,IAAI,WAAW;CAEf,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,OAAO,KAAK;EAElB,IAAI,SAAS,QAAQ,IAAI,IAAI,KAAK,QAAQ;GACxC;GACA,MAAM,KAAK;IAAE,MAAM;IAAW,MAAM,KAAK;GAAG,CAAC;GAC7C;EACF;EAEA,IAAI,SAAS,KAAK;GAChB,WAAW;GACX;EACF;EAEA,IAAI,OAAO,OACT,MAAM,KAAK;GAAE,MAAM;GAAS;GAAM,SAAS,OAAO;GAAO;EAAS,CAAC;OAEnE,MAAM,KAAK;GAAE,MAAM;GAAW;GAAM;EAAS,CAAC;CAElD;CAEA,OAAO;AACT;AAEA,SAAS,YAAY,gBAA2C,OAAuB;CACrF,IAAI,mBAAmB,QAAQ,mBAAmB,MAAM,mBAAmB,KAAA,GACzE,OAAO;CAET,IAAI,eAAe,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B,YAAY,UAAU;GACtB,aAAa,UAAU,CAAC;GACxB,aAAa,UAAU,CAAC;GACxB,eAAe,EAAE;GACjB,YAAY,EAAE;GACd,eAAe,UAAU;GAEzB,IAAI,OACF,IAAI,KAAK,gBAAgB;IACvB,MAAM,EAAE,OAAO,aAAa,mBAAmB,MAAM,EAAE;IACvD,MAAM,UAAU,kBAAkB,IAAI,OAAO,UAAU,IAAI;IAC3D,MAAM,QAAQ;IACd,gBAAgB,UAAU;IAC1B,eAAe,OAAO;GACxB,OACE,MAAM,QAAQ;GAIlB,IAAI,KAAK,aACP,KAAK,YAAY,IAAI,EAAE;EAE3B,GAAG,CAAC,CAOE;CACN;AACF;AAEA,SAAS,yBAAyB,MAAc,OAAmB,OAAuB;CACxF,IAAI,MAAM;CACV,OAAO,MAAM,MAAM,UAAU,MAAM,MAAM,UAAU,MAAM,QAAQ,MAAM,KAAK,SAAS,WACnF;CAEF,OAAO;AACT"}
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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"],"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P;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,CAAC;CACrB;AACF;AAEA,SAAS,cACP,OACA,QACA,aACA,OACiB;CACjB,MAAM,YAAY;CACl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ACE;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"}
|
package/lib/index.d.mts
CHANGED
|
@@ -124,7 +124,7 @@ export type { UseToggleReturnValue } from './use-toggle/use-toggle';
|
|
|
124
124
|
export type { UseUncontrolledOptions, UseUncontrolledReturnValue, } from './use-uncontrolled/use-uncontrolled';
|
|
125
125
|
export type { UseValidatedStateValue, UseValidatedStateReturnValue, } from './use-validated-state/use-validated-state';
|
|
126
126
|
export type { UseWindowScrollPosition, UseWindowScrollTo, UseWindowScrollReturnValue, } from './use-window-scroll/use-window-scroll';
|
|
127
|
-
export type { UseLongPressOptions, UseLongPressReturnValue } from './use-long-press/use-long-press';
|
|
127
|
+
export type { UseLongPressEvent, UseLongPressOptions, UseLongPressReturnValue, } from './use-long-press/use-long-press';
|
|
128
128
|
export type { SetFloatingWindowPosition, UseFloatingWindowOptions, UseFloatingWindowReturnValue, } from './use-floating-window/use-floating-window';
|
|
129
129
|
export type { UseSelectionHandlers, UseSelectionInput, UseSelectionReturnValue, } from './use-selection/use-selection';
|
|
130
130
|
export type { UseElementSizeReturnValue, UseResizeObserverReturnValue, ObserverRect, } from './use-resize-observer/use-resize-observer';
|
package/lib/index.d.ts
CHANGED
|
@@ -124,7 +124,7 @@ export type { UseToggleReturnValue } from './use-toggle/use-toggle';
|
|
|
124
124
|
export type { UseUncontrolledOptions, UseUncontrolledReturnValue, } from './use-uncontrolled/use-uncontrolled';
|
|
125
125
|
export type { UseValidatedStateValue, UseValidatedStateReturnValue, } from './use-validated-state/use-validated-state';
|
|
126
126
|
export type { UseWindowScrollPosition, UseWindowScrollTo, UseWindowScrollReturnValue, } from './use-window-scroll/use-window-scroll';
|
|
127
|
-
export type { UseLongPressOptions, UseLongPressReturnValue } from './use-long-press/use-long-press';
|
|
127
|
+
export type { UseLongPressEvent, UseLongPressOptions, UseLongPressReturnValue, } from './use-long-press/use-long-press';
|
|
128
128
|
export type { SetFloatingWindowPosition, UseFloatingWindowOptions, UseFloatingWindowReturnValue, } from './use-floating-window/use-floating-window';
|
|
129
129
|
export type { UseSelectionHandlers, UseSelectionInput, UseSelectionReturnValue, } from './use-selection/use-selection';
|
|
130
130
|
export type { UseElementSizeReturnValue, UseResizeObserverReturnValue, ObserverRect, } from './use-resize-observer/use-resize-observer';
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
export type UseLongPressEvent = 'mouse' | 'touch';
|
|
2
3
|
export interface UseLongPressOptions {
|
|
3
4
|
/** Time in milliseconds to trigger the long press, default is 400ms */
|
|
4
5
|
threshold?: number;
|
|
6
|
+
/** Input types that can trigger the long press, `['mouse', 'touch']` by default */
|
|
7
|
+
events?: UseLongPressEvent[];
|
|
8
|
+
/** If set, the long press is canceled when the pointer moves further than the given distance in px from the start position. `true` uses a 10px threshold, a number sets a custom threshold. `false` by default */
|
|
9
|
+
cancelOnMove?: boolean | number;
|
|
5
10
|
/** Callback triggered when the long press starts */
|
|
6
11
|
onStart?: (event: React.MouseEvent | React.TouchEvent) => void;
|
|
7
12
|
/** Callback triggered when the long press finishes */
|
|
@@ -10,12 +15,14 @@ export interface UseLongPressOptions {
|
|
|
10
15
|
onCancel?: (event: React.MouseEvent | React.TouchEvent) => void;
|
|
11
16
|
}
|
|
12
17
|
export interface UseLongPressReturnValue {
|
|
13
|
-
onMouseDown
|
|
14
|
-
onMouseUp
|
|
15
|
-
onMouseLeave
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
onMouseDown?: (event: React.MouseEvent) => void;
|
|
19
|
+
onMouseUp?: (event: React.MouseEvent) => void;
|
|
20
|
+
onMouseLeave?: (event: React.MouseEvent) => void;
|
|
21
|
+
onMouseMove?: (event: React.MouseEvent) => void;
|
|
22
|
+
onTouchStart?: (event: React.TouchEvent) => void;
|
|
23
|
+
onTouchEnd?: (event: React.TouchEvent) => void;
|
|
24
|
+
onTouchCancel?: (event: React.TouchEvent) => void;
|
|
25
|
+
onTouchMove?: (event: React.TouchEvent) => void;
|
|
19
26
|
}
|
|
20
27
|
export declare function useLongPress(onLongPress: (event: React.MouseEvent | React.TouchEvent) => void, options?: UseLongPressOptions): UseLongPressReturnValue;
|
|
21
28
|
export declare namespace useLongPress {
|
|
@@ -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 {
|