{"version":3,"file":"useResizingState.cjs","sources":["../../../../src/components/Grid/useResizingState.ts"],"sourcesContent":["import { useState, useCallback } from 'react';\nimport { ResizerPosition } from './types';\n\n/**\n * Defines the type for pointer information used in resizing.\n * @typedef {Object} PointerType\n * @property {number} width - The width of the pointer component.\n * @property {number} pointerId - Unique identifier for the pointer from a touch event.\n * @property {number} initialClientX - The initial X coordinate of the pointer when resizing started.\n */\nexport type PointerType = {\n  width: number;\n  pointerId: number;\n  initialClientX: number;\n};\n\n/**\n * Defines the state and methods used for managing the column resizing.\n * @typedef {Object} ResizingState\n * @property {PointerType | null} pointer - The current pointer data, or null if no pointer is active.\n * @property {(pointer: PointerType | null) => void} setPointer - Setter to update the pointer.\n * @property {(columnIndex: number) => boolean} getIsPressed - Indicates if a resizer for the given column is currently pressed/dragged.\n * @property {(columnIndex: number, pressed: boolean) => void} setIsPressed - Sets the pressed state for a given column.\n * @property {(columnIndex: number) => ResizerPosition} getPosition - Gets the position of the resizer for the specified column.\n * @property {(position: ResizerPosition) => void} setPosition - Updates the position of the resizer.\n * @property {number} lastPressedTimestamp - Timestamp of the last time a column was pressed, used to detect double-clicks.\n */\nexport interface ResizingState {\n  pointer: PointerType | null;\n  setPointer: (pointer: PointerType | null) => void;\n  getIsPressed: (columnIndex: number) => boolean;\n  setIsPressed: (columnIndex: number, pressed: boolean) => void;\n  getPosition: (columnIndex: number) => ResizerPosition;\n  setPosition: (position: ResizerPosition) => void;\n  lastPressedTimestamp: number;\n}\n\n/**\n * The initial position of the resizer element.\n * @type {ResizerPosition}\n */\nexport const initialPosition = {\n  left: 'calc(100% - 4px)',\n  top: '0',\n};\n\n/**\n * Custom hook that provides the state and methods needed to manage a resizing operation on columns.\n * @returns {ResizingState} The resizing state and methods for controlling resizing behavior.\n */\nconst useResizingState = (): ResizingState => {\n  const [pressedColumnIndex, setPressedColumnIndex] = useState<number>(-1);\n  const [pointer, setPointer] = useState<PointerType | null>(null);\n  const [position, setPosition] = useState<ResizerPosition>(initialPosition);\n  const [lastPressedTimestamp, setLastPressedTimestamp] = useState<number>(0);\n\n  /**\n   * Checks if the specified column index is currently in a pressed state.\n   * @param {number} columnIndex - The index of the column to check.\n   * @returns {boolean} True if the column is pressed, false otherwise.\n   */\n  const getIsPressed = useCallback(\n    (columnIndex: number) => {\n      return pressedColumnIndex === columnIndex;\n    },\n    [pressedColumnIndex]\n  );\n\n  /**\n   * Updates the pressed state for a specified column.\n   * @param {number} columnIndex - The index of the column.\n   * @param {boolean} pressed - True to set the column as pressed, false to release it.\n   */\n  const setIsPressed = useCallback((columnIndex: number, pressed: boolean) => {\n    if (pressed) {\n      setPressedColumnIndex(columnIndex);\n      setLastPressedTimestamp(Date.now());\n    } else {\n      setPressedColumnIndex(-1);\n    }\n  }, []);\n\n  /**\n   * Gets the position of the resizer for the specified column index.\n   * @param {number} columnIndex - The index of the column to retrieve the position for.\n   * @returns {ResizerPosition} The position of the resizer.\n   */\n  const getPosition = useCallback(\n    (columnIndex: number) => {\n      if (pressedColumnIndex !== columnIndex) {\n        return initialPosition;\n      }\n      return position;\n    },\n    [position, pressedColumnIndex]\n  );\n\n  return {\n    pointer,\n    setPointer,\n    getIsPressed,\n    setIsPressed,\n    getPosition,\n    setPosition,\n    lastPressedTimestamp,\n  };\n};\n\nexport default useResizingState;\n"],"names":["useState","useCallback"],"mappings":";;;;;;AAyCO,MAAM,eAAA,GAAkB;AAAA,EAC7B,IAAA,EAAM,kBAAA;AAAA,EACN,GAAA,EAAK;AACP;AAMA,MAAM,mBAAmB,MAAqB;AAC5C,EAAA,MAAM,CAAC,kBAAA,EAAoB,qBAAqB,CAAA,GAAIA,eAAiB,EAAE,CAAA;AACvE,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAIA,eAA6B,IAAI,CAAA;AAC/D,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAIA,eAA0B,eAAe,CAAA;AACzE,EAAA,MAAM,CAAC,oBAAA,EAAsB,uBAAuB,CAAA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