{"version":3,"sources":["../../../src/components/SpinButton/useSpinButton.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { mergeCallbacks, useControllableState, useTimeout, slot, useMergedRefs } from '@fluentui/react-utilities';\nimport { ArrowUp, ArrowDown, End, Enter, Escape, Home, PageDown, PageUp } from '@fluentui/keyboard-keys';\nimport type {\n  SpinButtonBaseProps,\n  SpinButtonBaseState,\n  SpinButtonProps,\n  SpinButtonState,\n  SpinButtonSpinState,\n  SpinButtonChangeEvent,\n  SpinButtonBounds,\n} from './SpinButton.types';\nimport { calculatePrecision, precisionRound, getBound, clamp } from '../../utils/index';\nimport { ChevronUp16Regular, ChevronDown16Regular } from '@fluentui/react-icons';\nimport { useOverrides_unstable as useOverrides } from '@fluentui/react-shared-contexts';\n\ntype InternalState = {\n  value: number | null;\n  spinState: SpinButtonSpinState;\n  spinTime: number;\n  spinDelay: number;\n  previousTextValue?: string;\n  atBound: SpinButtonBounds;\n};\n\n// A single tap on a trackpad can take ~200-250ms before mouseup fires. Keep the initial\n// repeat delay above that range so a tap is treated as one click while a true hold still\n// triggers repeat behavior.\nconst DEFAULT_SPIN_DELAY_MS = 300;\nconst MIN_SPIN_DELAY_MS = 80;\nconst MAX_SPIN_TIME_MS = 1000;\n\n// This is here to give an ease for the mouse held down case.\n// Exact easing it to be defined. Once it is we'll likely\n// pull this out into a util function in the SpinButton package.\nconst lerp = (start: number, end: number, percent: number): number => start + (end - start) * percent;\n\n/**\n * Create the base state required to render SpinButton without design-specific props.\n *\n * @param props - props from this instance of SpinButton (without appearance/size)\n * @param ref - reference to root HTMLElement of SpinButton\n */\nexport const useSpinButtonBase_unstable = (\n  props: SpinButtonBaseProps,\n  ref: React.Ref<HTMLInputElement>,\n): SpinButtonBaseState => {\n  // Merge props from surrounding <Field>, if any\n  props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });\n\n  // `className` and `style` go to the root slot, all other native props go to the primary `input` slot.\n  const {\n    className,\n    style,\n    value,\n    displayValue,\n    defaultValue,\n    min,\n    max,\n    stepPage = 1,\n    precision: precisionFromProps,\n    onChange,\n    root,\n    input,\n    incrementButton,\n    decrementButton,\n    ...inputProps\n  } = props;\n  // `step` is also a native input attribute, so it keeps reaching the `input` slot.\n  const step = props.step ?? 1;\n\n  const precision = React.useMemo(() => {\n    return precisionFromProps ?? Math.max(calculatePrecision(step), 0);\n  }, [precisionFromProps, step]);\n\n  const [currentValue, setCurrentValue] = useControllableState({\n    state: value,\n    defaultState: defaultValue,\n    initialState: 0,\n  });\n\n  const inputRef = React.useRef<HTMLInputElement>(null);\n\n  const isControlled = value !== undefined;\n\n  const [textValue, setTextValue] = React.useState<string | undefined>(undefined);\n  const [keyboardSpinState, setKeyboardSpinState] = React.useState<SpinButtonSpinState>('rest');\n\n  const internalState = React.useRef<InternalState>({\n    value: currentValue,\n    spinState: 'rest',\n    spinTime: 0,\n    spinDelay: DEFAULT_SPIN_DELAY_MS,\n    atBound: currentValue !== null ? getBound(precisionRound(currentValue, precision), min, max) : 'none',\n  });\n\n  const [setStepTimeout, clearStepTimeout] = useTimeout();\n\n  const stepValue = (\n    e: SpinButtonChangeEvent,\n    direction: 'up' | 'down' | 'upPage' | 'downPage',\n    startFrom?: string,\n  ) => {\n    let startValue = internalState.current.value;\n    if (startFrom) {\n      const num = parseFloat(startFrom);\n      if (!isNaN(num)) {\n        startValue = num;\n      }\n    }\n    const val = startValue;\n    const dir = direction === 'up' || direction === 'upPage' ? 1 : -1;\n    const stepSize = direction === 'upPage' || direction === 'downPage' ? stepPage : step;\n\n    if (val === null) {\n      const stepStart = min === undefined ? 0 : min;\n      const nullStep = clamp(stepStart + stepSize * dir, min, max);\n      commit(e, nullStep);\n      return;\n    }\n\n    let newValue = val + stepSize * dir;\n    if (!Number.isNaN(newValue)) {\n      newValue = clamp(newValue, min, max);\n    }\n\n    commit(e, newValue);\n\n    if (internalState.current.spinState !== 'rest') {\n      setStepTimeout(() => {\n        // Ease the step speed a bit\n        internalState.current.spinTime += internalState.current.spinDelay;\n        internalState.current.spinDelay = lerp(\n          DEFAULT_SPIN_DELAY_MS,\n          MIN_SPIN_DELAY_MS,\n          internalState.current.spinTime / MAX_SPIN_TIME_MS,\n        );\n        stepValue(e, direction);\n      }, internalState.current.spinDelay);\n    }\n  };\n\n  const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n    if (!internalState.current.previousTextValue) {\n      internalState.current.previousTextValue = textValue ?? String(currentValue);\n    }\n    const newValue = e.target.value;\n    setTextValue(newValue);\n    if (inputRef.current) {\n      // we need to set this here using the IDL attribute directly, because otherwise the timing of the ARIA value update\n      // is not in sync with the user-entered native input value, and some screen readers end up reading the wrong value.\n      inputRef.current.ariaValueNow = newValue;\n    }\n  };\n\n  const handleIncrementMouseDown = (e: React.MouseEvent<HTMLButtonElement>) => {\n    commit(e, currentValue, textValue);\n    internalState.current.spinState = 'up';\n    stepValue(e, 'up');\n  };\n\n  const handleDecrementMouseDown = (e: React.MouseEvent<HTMLButtonElement>) => {\n    commit(e, currentValue, textValue);\n    internalState.current.spinState = 'down';\n    stepValue(e, 'down');\n  };\n\n  const handleStepMouseUpOrLeave = (e: React.MouseEvent<HTMLButtonElement>) => {\n    clearStepTimeout();\n    internalState.current.spinState = 'rest';\n    internalState.current.spinDelay = DEFAULT_SPIN_DELAY_MS;\n    internalState.current.spinTime = 0;\n  };\n\n  const handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {\n    commit(e, currentValue, textValue);\n    internalState.current.previousTextValue = undefined;\n  };\n\n  const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n    let nextKeyboardSpinState: SpinButtonSpinState = 'rest';\n\n    if (e.currentTarget.readOnly) {\n      return;\n    }\n\n    if (e.key === ArrowUp) {\n      stepValue(e, 'up', textValue);\n      nextKeyboardSpinState = 'up';\n    } else if (e.key === ArrowDown) {\n      stepValue(e, 'down', textValue);\n      nextKeyboardSpinState = 'down';\n    } else if (e.key === PageUp) {\n      e.preventDefault();\n      stepValue(e, 'upPage', textValue);\n      nextKeyboardSpinState = 'up';\n    } else if (e.key === PageDown) {\n      e.preventDefault();\n      stepValue(e, 'downPage', textValue);\n      nextKeyboardSpinState = 'down';\n    } else if (!e.shiftKey && e.key === Home && min !== undefined) {\n      commit(e, min);\n      nextKeyboardSpinState = 'down';\n    } else if (!e.shiftKey && e.key === End && max !== undefined) {\n      commit(e, max);\n      nextKeyboardSpinState = 'up';\n    } else if (e.key === Enter) {\n      commit(e, currentValue, textValue);\n      internalState.current.previousTextValue = undefined;\n    } else if (e.key === Escape) {\n      if (internalState.current.previousTextValue) {\n        setTextValue(undefined);\n        internalState.current.previousTextValue = undefined;\n      }\n    }\n\n    if (keyboardSpinState !== nextKeyboardSpinState) {\n      setKeyboardSpinState(nextKeyboardSpinState);\n    }\n  };\n\n  const handleKeyUp = (e: React.KeyboardEvent<HTMLInputElement>) => {\n    if (keyboardSpinState !== 'rest') {\n      setKeyboardSpinState('rest');\n      internalState.current.spinState = 'rest';\n    }\n  };\n\n  const commit = (e: SpinButtonChangeEvent, newValue?: number | null, newDisplayValue?: string) => {\n    const valueChanged = newValue !== undefined && currentValue !== newValue;\n    const displayValueChanged =\n      newDisplayValue !== undefined &&\n      internalState.current.previousTextValue !== undefined &&\n      internalState.current.previousTextValue !== newDisplayValue;\n\n    let roundedValue;\n    if (valueChanged) {\n      roundedValue = precisionRound(newValue!, precision);\n      setCurrentValue(roundedValue);\n      internalState.current.value = roundedValue;\n    } else if (displayValueChanged && !isControlled) {\n      const nextValue = parseFloat(newDisplayValue as string);\n      if (!isNaN(nextValue)) {\n        setCurrentValue(precisionRound(nextValue, precision));\n        internalState.current.value = precisionRound(nextValue, precision);\n      }\n    }\n\n    if (valueChanged || displayValueChanged) {\n      onChange?.(e, { value: roundedValue, displayValue: newDisplayValue });\n    }\n\n    setTextValue(undefined);\n  };\n\n  let valueToDisplay;\n  if (textValue !== undefined) {\n    valueToDisplay = textValue;\n  } else if (value === null || currentValue === null) {\n    valueToDisplay = displayValue ?? '';\n    // eslint-disable-next-line react-hooks/refs\n    internalState.current.value = null;\n    // eslint-disable-next-line react-hooks/refs\n    internalState.current.atBound = 'none';\n  } else {\n    const roundedValue = precisionRound(currentValue, precision);\n    // eslint-disable-next-line react-hooks/refs\n    internalState.current.value = roundedValue;\n    // eslint-disable-next-line react-hooks/refs\n    internalState.current.atBound = getBound(roundedValue, min, max);\n    if (isControlled) {\n      valueToDisplay = displayValue ?? String(roundedValue);\n    } else {\n      valueToDisplay = String(roundedValue);\n    }\n  }\n\n  const state: SpinButtonBaseState = {\n    spinState: keyboardSpinState,\n    // eslint-disable-next-line react-hooks/refs\n    atBound: internalState.current.atBound,\n\n    components: {\n      root: 'span',\n      input: 'input',\n      incrementButton: 'button',\n      decrementButton: 'button',\n    },\n    root: slot.always(root, {\n      defaultProps: { className, style },\n      elementType: 'span',\n    }),\n    input: slot.always(input, {\n      defaultProps: {\n        autoComplete: 'off',\n        role: 'spinbutton',\n        type: 'text',\n        ...inputProps,\n      },\n      elementType: 'input',\n    }),\n    incrementButton: slot.always(incrementButton, {\n      defaultProps: {\n        tabIndex: -1,\n        disabled:\n          inputProps.readOnly ||\n          inputProps.disabled ||\n          // eslint-disable-next-line react-hooks/refs\n          internalState.current.atBound === 'max' ||\n          // eslint-disable-next-line react-hooks/refs\n          internalState.current.atBound === 'both',\n        'aria-label': 'Increment value',\n        type: 'button',\n      },\n      elementType: 'button',\n    }),\n    decrementButton: slot.always(decrementButton, {\n      defaultProps: {\n        tabIndex: -1,\n        disabled:\n          inputProps.readOnly ||\n          inputProps.disabled ||\n          // eslint-disable-next-line react-hooks/refs\n          internalState.current.atBound === 'min' ||\n          // eslint-disable-next-line react-hooks/refs\n          internalState.current.atBound === 'both',\n        'aria-label': 'Decrement value',\n        type: 'button',\n      },\n      elementType: 'button',\n    }),\n  };\n\n  // eslint-disable-next-line react-hooks/refs\n  state.input.value = valueToDisplay;\n  // eslint-disable-next-line react-hooks/refs\n  state.input.ref = useMergedRefs(inputRef, ref);\n  // eslint-disable-next-line react-hooks/refs\n  state.input['aria-valuemin'] = min;\n  // eslint-disable-next-line react-hooks/refs\n  state.input['aria-valuemax'] = max;\n  // eslint-disable-next-line react-hooks/refs\n  state.input['aria-valuenow'] = internalState.current.value ?? undefined;\n  // eslint-disable-next-line react-hooks/refs\n  state.input['aria-valuetext'] = state.input['aria-valuetext'] ?? ((value !== undefined && displayValue) || undefined);\n  // eslint-disable-next-line react-hooks/refs\n  state.input.onChange = mergeCallbacks(state.input.onChange, handleInputChange);\n  // eslint-disable-next-line react-hooks/refs\n  state.input.onInput = mergeCallbacks(state.input.onInput, handleInputChange);\n  // eslint-disable-next-line react-hooks/refs\n  state.input.onBlur = mergeCallbacks(state.input.onBlur, handleBlur);\n  // eslint-disable-next-line react-hooks/refs\n  state.input.onKeyDown = mergeCallbacks(state.input.onKeyDown, handleKeyDown);\n  // eslint-disable-next-line react-hooks/refs\n  state.input.onKeyUp = mergeCallbacks(state.input.onKeyUp, handleKeyUp);\n\n  // eslint-disable-next-line react-hooks/refs\n  state.incrementButton.onMouseDown = mergeCallbacks(handleIncrementMouseDown, state.incrementButton.onMouseDown);\n  // eslint-disable-next-line react-hooks/refs\n  state.incrementButton.onMouseUp = mergeCallbacks(state.incrementButton.onMouseUp, handleStepMouseUpOrLeave);\n  // eslint-disable-next-line react-hooks/refs\n  state.incrementButton.onMouseLeave = mergeCallbacks(state.incrementButton.onMouseLeave, handleStepMouseUpOrLeave);\n\n  // eslint-disable-next-line react-hooks/refs\n  state.decrementButton.onMouseDown = mergeCallbacks(handleDecrementMouseDown, state.decrementButton.onMouseDown);\n  // eslint-disable-next-line react-hooks/refs\n  state.decrementButton.onMouseUp = mergeCallbacks(state.decrementButton.onMouseUp, handleStepMouseUpOrLeave);\n  // eslint-disable-next-line react-hooks/refs\n  state.decrementButton.onMouseLeave = mergeCallbacks(state.decrementButton.onMouseLeave, handleStepMouseUpOrLeave);\n\n  // eslint-disable-next-line react-hooks/refs\n  return state;\n};\n\n/**\n * Create the state required to render SpinButton.\n *\n * The returned state can be modified with hooks such as useSpinButtonStyles_unstable,\n * before being passed to renderSpinButton_unstable.\n *\n * @param props - props from this instance of SpinButton\n * @param ref - reference to root HTMLElement of SpinButton\n */\nexport const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HTMLInputElement>): SpinButtonState => {\n  const overrides = useOverrides();\n\n  const { appearance = overrides.inputDefaultAppearance ?? 'outline', size = 'medium', ...baseProps } = props;\n\n  const state = useSpinButtonBase_unstable(baseProps, ref);\n\n  state.incrementButton.children ??= <ChevronUp16Regular />;\n  state.decrementButton.children ??= <ChevronDown16Regular />;\n\n  return { ...state, appearance, size };\n};\n"],"names":["React","useFieldControlProps_unstable","mergeCallbacks","useControllableState","useTimeout","slot","useMergedRefs","ArrowUp","ArrowDown","End","Enter","Escape","Home","PageDown","PageUp","calculatePrecision","precisionRound","getBound","clamp","ChevronUp16Regular","ChevronDown16Regular","useOverrides_unstable","useOverrides","DEFAULT_SPIN_DELAY_MS","MIN_SPIN_DELAY_MS","MAX_SPIN_TIME_MS","lerp","start","end","percent","useSpinButtonBase_unstable","props","ref","supportsLabelFor","supportsRequired","className","style","value","displayValue","defaultValue","min","max","stepPage","precision","precisionFromProps","onChange","root","input","incrementButton","decrementButton","inputProps","step","useMemo","Math","currentValue","setCurrentValue","state","defaultState","initialState","inputRef","useRef","isControlled","undefined","textValue","setTextValue","useState","keyboardSpinState","setKeyboardSpinState","internalState","spinState","spinTime","spinDelay","atBound","setStepTimeout","clearStepTimeout","stepValue","e","direction","startFrom","startValue","current","num","parseFloat","isNaN","val","dir","stepSize","stepStart","nullStep","commit","newValue","Number","handleInputChange","previousTextValue","String","target","ariaValueNow","handleIncrementMouseDown","handleDecrementMouseDown","handleStepMouseUpOrLeave","handleBlur","handleKeyDown","nextKeyboardSpinState","currentTarget","readOnly","key","preventDefault","shiftKey","handleKeyUp","newDisplayValue","valueChanged","displayValueChanged","roundedValue","nextValue","valueToDisplay","components","always","defaultProps","elementType","autoComplete","role","type","tabIndex","disabled","onInput","onBlur","onKeyDown","onKeyUp","onMouseDown","onMouseUp","onMouseLeave","useSpinButton_unstable","overrides","appearance","inputDefaultAppearance","size","baseProps","children"],"mappings":"AAAA;;;;;;;;;;;;QA8Ca8B;;;QAoVAqG;;;;;iEAhYU,QAAQ;4BACe,wBAAwB;gCACgB,4BAA4B;8BACnC,0BAA0B;uBAUrC,uBAAoB;4BAC/B,wBAAwB;qCAC3B,kCAAkC;AAWxF,wFAAwF;AACxF,yFAAyF;AACzF,4BAA4B;AAC5B,MAAM5G,wBAAwB;AAC9B,MAAMC,oBAAoB;AAC1B,MAAMC,mBAAmB;AAEzB,6DAA6D;AAC7D,yDAAyD;AACzD,gEAAgE;AAChE,MAAMC,OAAO,CAACC,OAAeC,KAAaC,UAA4BF,QAASC,CAAAA,MAAMD,KAAAA,CAAI,GAAKE;AAQvF,mCAAmC,CACxCE,OACAC;IAEA,+CAA+C;IAC/CD,YAAQ9B,yCAAAA,EAA8B8B,OAAO;QAAEE,kBAAkB;QAAMC,kBAAkB;IAAK;IAE9F,sGAAsG;IACtG,MAAM,EACJC,SAAS,EACTC,KAAK,EACLC,KAAK,EACLC,YAAY,EACZC,YAAY,EACZC,GAAG,EACHC,GAAG,EACHC,WAAW,CAAC,EACZC,WAAWC,kBAAkB,EAC7BC,QAAQ,EACRC,IAAI,EACJC,KAAK,EACLC,eAAe,EACfC,eAAe,EACf,GAAGC,YACJ,GAAGnB;IACJ,kFAAkF;IAClF,MAAMoB,OAAOpB,MAAMoB,IAAI,IAAI;IAE3B,MAAMR,YAAY3C,OAAMoD,OAAO,CAAC;QAC9B,OAAOR,sBAAsBS,KAAKZ,GAAG,KAAC1B,yBAAAA,EAAmBoC,OAAO;IAClE,GAAG;QAACP;QAAoBO;KAAK;IAE7B,MAAM,CAACG,cAAcC,gBAAgB,GAAGpD,wCAAAA,EAAqB;QAC3Dq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