{"version":3,"sources":["../../../../src/components/Calendar/hooks/useCalendarGrid.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { ArrowDown, ArrowLeft, ArrowRight, ArrowUp, End, Enter, Home, Space } from '@fluentui/keyboard-keys';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport {\n  getRTLSafeKey,\n  isHTMLElement,\n  mergeCallbacks,\n  slot,\n  useEventCallback,\n  useMergedRefs,\n} from '@fluentui/react-utilities';\nimport type { SlotShorthandValue, ExtractSlotProps, Slot } from '@fluentui/react-utilities';\nimport { toDataAttributeValue } from '../../../utils';\n\ntype GridSlotProps = ExtractSlotProps<Slot<'div'>> & {\n  'data-fui-calendar-grid'?: string;\n};\ntype GridCellRootProps = React.ComponentProps<'div'> & {\n  'data-current'?: string;\n  'data-selected'?: string;\n  'data-outside-bounds'?: string;\n};\ntype GridCellProps = {\n  root: GridCellRootProps;\n  button: React.ComponentProps<'button'>;\n};\n\n/**\n * One row of the month or year grid.\n */\nexport type CalendarGridRow<TCell> = {\n  /** Stable key of the row. */\n  key: number;\n  /** Semantic cells in display order. */\n  cells: TCell[];\n};\n\nconst isElement = (target: EventTarget | null): target is Element => {\n  const element = target as Element | null;\n  const ElementConstructor = element?.ownerDocument?.defaultView?.Element;\n  return !!ElementConstructor && element instanceof ElementConstructor;\n};\n\n/** Whether paging keys belong to a nested widget rather than a Calendar-owned grid. */\nexport const isCalendarKeyboardEventFromNestedWidget = (target: EventTarget | null, root: HTMLElement): boolean => {\n  if (!isElement(target)) {\n    return false;\n  }\n  const owner = target.closest('[role=\"grid\"], [role=\"toolbar\"]');\n  if (!owner || !root.contains(owner)) {\n    return false;\n  }\n  return owner.getAttribute('role') === 'toolbar' || !owner.hasAttribute('data-fui-calendar-grid');\n};\n\n/** Whether content owns text editing rather than grid keyboard navigation. */\nexport const isCalendarKeyboardEditable = (target: EventTarget | null): boolean => {\n  if (!isElement(target)) {\n    return false;\n  }\n  if (target.closest('input, textarea, select')) {\n    return true;\n  }\n  let element: Element | null = target;\n  while (element) {\n    const contentEditable = element.getAttribute('contenteditable')?.trim().toLowerCase();\n    if (contentEditable === '' || contentEditable === 'true' || contentEditable === 'plaintext-only') {\n      return true;\n    }\n    if (contentEditable === 'false') {\n      return false;\n    }\n    element = element.parentElement;\n  }\n  return false;\n};\n\n/** Lists the cells owned by a grid, excluding nested grids. */\nconst getCalendarGridCells = (grid: Element): HTMLElement[] =>\n  Array.from(grid.querySelectorAll<HTMLElement>('[role=\"gridcell\"]')).filter(\n    cell => cell.closest('[role=\"grid\"]') === grid,\n  );\n\n/**\n * Resolves an event's cell, respecting nested grids, toolbars and editable content.\n * Range-hover events can originate from editable content.\n */\nexport const getCalendarGridCell = (event: React.SyntheticEvent<HTMLElement>): HTMLElement | undefined => {\n  const { currentTarget: grid, target } = event;\n  const isRangeHover = event.type === 'mouseover' || event.type === 'mouseout';\n  if (!isElement(target) || (!isRangeHover && isCalendarKeyboardEditable(target))) {\n    return undefined;\n  }\n  const cell = target.closest<HTMLElement>('[role=\"gridcell\"]');\n  const ownerSelector =\n    event.type.startsWith('key') || event.type === 'focus' ? '[role=\"grid\"], [role=\"toolbar\"]' : '[role=\"grid\"]';\n  return cell && cell.closest('[role=\"grid\"]') === grid && target.closest(ownerSelector) === grid ? cell : undefined;\n};\n\n/** Month and year grids always show twelve cells. */\nconst PICKER_CELL_COUNT = 12;\n\n/** Whether a key event is an unmodified arrow, Home or End key that a calendar grid moves focus with. */\nexport const isCalendarGridNavigationKey = (event: React.KeyboardEvent): boolean =>\n  !event.altKey &&\n  !event.ctrlKey &&\n  !event.metaKey &&\n  !event.shiftKey &&\n  (event.key === ArrowDown ||\n    event.key === ArrowLeft ||\n    event.key === ArrowRight ||\n    event.key === ArrowUp ||\n    event.key === Home ||\n    event.key === End);\n\n/**\n * Finds the cell that an arrow, Home or End key moves to in a grid of `columns` columns, skipping ineligible cells.\n * Vertical arrows keep the column. Without `wrapRows`, as in the month and year grids, horizontal arrows stay within the\n * row and Home/End reach the first/last eligible cell of the grid. With `wrapRows`, as in the day grid, horizontal\n * arrows continue into the adjacent week and Home/End stay within the week.\n *\n * @returns the target index, or `undefined` when no eligible cell lies in that direction\n * @internal\n */\nexport const getCalendarGridTargetIndex = (\n  key: string,\n  dir: 'ltr' | 'rtl',\n  index: number,\n  count: number,\n  columns: number,\n  isEligible: (index: number) => boolean,\n  wrapRows = false,\n): number | undefined => {\n  if (key === Home || key === End) {\n    const rowStart = wrapRows ? index - (index % columns) : 0;\n    const rowEnd = wrapRows ? Math.min(rowStart + columns, count) - 1 : count - 1;\n    // Home and End reach the first or last eligible cell in the grid (or row for the day grid).\n    const [from, to, step] = key === Home ? [rowStart, rowEnd, 1] : [rowEnd, rowStart, -1];\n    for (let candidate = from; candidate !== to + step; candidate += step) {\n      if (isEligible(candidate)) {\n        return candidate;\n      }\n    }\n    return undefined;\n  }\n\n  let step: number;\n  if (key === ArrowDown) {\n    step = columns;\n  } else if (key === ArrowUp) {\n    step = -columns;\n  } else if (key === getRTLSafeKey(ArrowRight, dir)) {\n    step = 1;\n  } else if (key === getRTLSafeKey(ArrowLeft, dir)) {\n    step = -1;\n  } else {\n    return undefined;\n  }\n\n  const row = Math.floor(index / columns);\n  for (let candidate = index + step; candidate >= 0 && candidate < count; candidate += step) {\n    if (!wrapRows && Math.abs(step) === 1 && Math.floor(candidate / columns) !== row) {\n      return undefined;\n    }\n    if (isEligible(candidate)) {\n      return candidate;\n    }\n  }\n  return undefined;\n};\n\n/**\n * Adds a roving tab stop, arrow, Home and End navigation, and delegated activation to the month and year grids.\n * Only the tab-stop cell has `tabIndex={0}`. Moving focus updates the tab stop without selecting or navigating, and the\n * last focused cell stays the tab stop until `resetKey` changes, such as when the grid's cells or columns change.\n *\n * @param grid - the consumer `grid` slot props\n * @param ariaLabel - the accessible name of the grid\n * @param isAvailable - whether the cell at an index can be selected\n * @param onSelect - selects the cell at an index\n * @param options - the column count, whether unavailable cells are focusable, the default tab stop and its reset key\n * @returns the grid slot, the cell lookup and the index of the tab-stop cell\n * @internal\n */\nexport function useCalendarPickerGrid(\n  grid: GridSlotProps | SlotShorthandValue | undefined,\n  ariaLabel: string,\n  isAvailable: (index: number) => boolean,\n  onSelect: (\n    event: React.MouseEvent<HTMLButtonElement> | React.KeyboardEvent<HTMLButtonElement>,\n    index: number,\n  ) => void,\n  options: { columns: number; allFocusable: boolean; defaultTabStop: number | undefined; resetKey: string },\n): [GridSlotProps, (index: number) => HTMLElement | undefined, number | undefined, number | undefined] {\n  const { columns, allFocusable, defaultTabStop, resetKey } = options;\n  const { dir } = useFluent();\n  const gridRef = React.useRef<HTMLDivElement>(null);\n  const getCell = (index: number) => (gridRef.current ? getCalendarGridCells(gridRef.current)[index] : undefined);\n  const isEligible = (index: number) => index >= 0 && index < PICKER_CELL_COUNT && (allFocusable || isAvailable(index));\n\n  // The focused cell keeps the tab stop until the grid shows different cells.\n  const [activeCell, setActiveCell] = React.useState<{ index: number; resetKey: string } | undefined>(undefined);\n  const tabStop =\n    activeCell && activeCell.resetKey === resetKey && activeCell.index >= 0 && activeCell.index < PICKER_CELL_COUNT\n      ? activeCell.index\n      : defaultTabStop !== undefined && isEligible(defaultTabStop)\n      ? defaultTabStop\n      : undefined;\n\n  const getEventIndex = (event: React.SyntheticEvent<HTMLElement>) => {\n    const cell = getCalendarGridCell(event);\n    if (!cell) {\n      return [undefined, -1] as const;\n    }\n    const index = getCalendarGridCells(event.currentTarget).indexOf(cell);\n    return [cell, index] as const;\n  };\n\n  const selectCell = (\n    event: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>,\n    cell: HTMLElement,\n    index: number,\n  ) => {\n    const button = cell.querySelector('button');\n    if (!isHTMLElement(button, { constructorName: 'HTMLButtonElement' })) {\n      return;\n    }\n    const gridElement = event.currentTarget;\n    try {\n      // Preserve the button-event contract while sharing cancellation with the delegated grid event.\n      onSelect(Object.assign(event, { currentTarget: button }), index);\n    } finally {\n      event.currentTarget = gridElement;\n    }\n  };\n\n  const gridSlot = slot.always(grid, {\n    defaultProps: {\n      'aria-label': ariaLabel,\n      role: 'grid',\n      'data-fui-calendar-grid': '',\n    },\n    elementType: 'div',\n  }) as GridSlotProps;\n  gridSlot.ref = useMergedRefs(gridSlot.ref, gridRef);\n  gridSlot.onFocus = mergeCallbacks(gridSlot.onFocus, (event: React.FocusEvent<HTMLElement>) => {\n    const [cell, index] = getEventIndex(event);\n    if (cell && event.target === cell && isEligible(index)) {\n      setActiveCell({ index, resetKey });\n    }\n  });\n  gridSlot.onClick = mergeCallbacks(gridSlot.onClick, (event: React.MouseEvent<HTMLElement>) => {\n    const [cell, index] = getEventIndex(event);\n    if (cell && index >= 0 && !event.isDefaultPrevented() && isAvailable(index)) {\n      cell.focus();\n      selectCell(event, cell, index);\n    }\n  });\n  // Reads the grid element to move focus, so it runs as an event callback.\n  const onGridKeyDown = useEventCallback((event: React.KeyboardEvent<HTMLElement>) => {\n    if (event.isDefaultPrevented()) {\n      return;\n    }\n    // Keys from content inside the cell, including its button, keep their native behavior.\n    const [cell, index] = getEventIndex(event);\n    if (!cell || index < 0 || event.target !== cell) {\n      return;\n    }\n\n    if (isCalendarGridNavigationKey(event)) {\n      // Boundary keys are owned too, so the page does not scroll when focus cannot move further.\n      event.preventDefault();\n      const targetIndex = getCalendarGridTargetIndex(event.key, dir, index, PICKER_CELL_COUNT, columns, isEligible);\n      if (targetIndex !== undefined) {\n        setActiveCell({ index: targetIndex, resetKey });\n        getCell(targetIndex)?.focus();\n      }\n      return;\n    }\n\n    if ((event.key === Enter || event.key === Space) && isAvailable(index)) {\n      selectCell(event, cell, index);\n      if (!event.isDefaultPrevented()) {\n        event.preventDefault();\n      }\n    }\n  });\n  gridSlot.onKeyDown = mergeCallbacks(gridSlot.onKeyDown, onGridKeyDown);\n\n  return [gridSlot, getCell, tabStop, activeCell?.index];\n}\n\n/**\n * Groups semantic month or year cells into rows.\n *\n * @param cells - the cells in grid order\n * @param columns - number of columns in each row\n * @internal\n */\nexport const getCalendarPickerRows = <TCell>(cells: TCell[], columns: 3 | 4): CalendarGridRow<TCell>[] => {\n  if (columns !== 3 && columns !== 4) {\n    throw new RangeError('Calendar picker columns must be 3 or 4.');\n  }\n  const rows: CalendarGridRow<TCell>[] = [];\n  cells.forEach((cell, index) => {\n    const rowIndex = Math.floor(index / columns);\n    (rows[rowIndex] ??= { key: rowIndex, cells: [] }).cells.push(cell);\n  });\n  return rows;\n};\n\n/** Resolves the shared button state for a month or year cell. */\nexport const getCalendarPickerCellProps = (\n  allFocusable: boolean,\n  isDisabled: boolean,\n  isSelected: boolean,\n  isCurrent: boolean,\n  isTabStop: boolean,\n  isActive: boolean,\n): GridCellProps => {\n  return {\n    root: {\n      role: 'gridcell',\n      'aria-disabled': isDisabled,\n      'aria-selected': isSelected,\n      'aria-current': isCurrent ? 'date' : undefined,\n      // Keep the last focused cell programmatically focusable if the grid changes while it is focused.\n      tabIndex: isTabStop ? 0 : allFocusable || !isDisabled || isActive ? -1 : undefined,\n      'data-current': toDataAttributeValue(isCurrent),\n      'data-selected': toDataAttributeValue(isSelected),\n      'data-outside-bounds': toDataAttributeValue(isDisabled),\n    },\n    button: {\n      type: 'button',\n      disabled: isDisabled && !allFocusable,\n      tabIndex: -1,\n    },\n  };\n};\n"],"names":["getCalendarGridCell","getCalendarGridTargetIndex","getCalendarPickerCellProps","getCalendarPickerRows","isCalendarGridNavigationKey","isCalendarKeyboardEditable","isCalendarKeyboardEventFromNestedWidget","useCalendarPickerGrid","isElement","target","element","ElementConstructor","ownerDocument","defaultView","Element","root","owner","closest","contains","getAttribute","hasAttribute","contentEditable","trim","toLowerCase","parentElement","getCalendarGridCells","grid","Array","from","querySelectorAll","filter","cell","event","currentTarget","isRangeHover","type","undefined","ownerSelector","startsWith","PICKER_CELL_COUNT","altKey","ctrlKey","metaKey","shiftKey","key","ArrowDown","ArrowLeft","ArrowRight","ArrowUp","Home","End","dir","index","count","columns","isEligible","wrapRows","rowStart","rowEnd","Math","min","to","step","candidate","getRTLSafeKey","row","floor","abs","ariaLabel","isAvailable","onSelect","options","allFocusable","defaultTabStop","resetKey","useFluent","gridRef","React","useRef","getCell","current","activeCell","setActiveCell","useState","tabStop","getEventIndex","indexOf","selectCell","button","querySelector","isHTMLElement","constructorName","gridElement","Object","assign","gridSlot","slot","always","defaultProps","role","elementType","ref","useMergedRefs","onFocus","mergeCallbacks","onClick","isDefaultPrevented","focus","onGridKeyDown","useEventCallback","preventDefault","targetIndex","Enter","Space","onKeyDown","cells","RangeError","rows","forEach","rowIndex","push","isDisabled","isSelected","isCurrent","isTabStop","isActive","tabIndex","toDataAttributeValue","disabled"],"mappings":"AAAA;;;;;;;;;;;;QAyFaA;eAAAA;;QAqCAC;eAAAA;;QA4LAC;eAAAA;;QAbAC;eAAAA;;QApMAC;eAAAA;;QA/CAC;eAAAA;;QAZAC;eAAAA;;QA4IGC;eAAAA;;;;iEAxLO;8BAC4D;qCACnC;gCAQzC;uBAE8B;AAyBrC,MAAMC,YAAY,CAACC;IACjB,MAAMC,UAAUD;IAChB,MAAME,qBAAqBD,SAASE,eAAeC,aAAaC;IAChE,OAAO,CAAC,CAACH,sBAAsBD,mBAAmBC;AACpD;AAGO,MAAML,0CAA0C,CAACG,QAA4BM;IAClF,IAAI,CAACP,UAAUC,SAAS;QACtB,OAAO;IACT;IACA,MAAMO,QAAQP,OAAOQ,OAAO,CAAC;IAC7B,IAAI,CAACD,SAAS,CAACD,KAAKG,QAAQ,CAACF,QAAQ;QACnC,OAAO;IACT;IACA,OAAOA,MAAMG,YAAY,CAAC,YAAY,aAAa,CAACH,MAAMI,YAAY,CAAC;AACzE;AAGO,MAAMf,6BAA6B,CAACI;IACzC,IAAI,CAACD,UAAUC,SAAS;QACtB,OAAO;IACT;IACA,IAAIA,OAAOQ,OAAO,CAAC,4BAA4B;QAC7C,OAAO;IACT;IACA,IAAIP,UAA0BD;IAC9B,MAAOC,QAAS;QACd,MAAMW,kBAAkBX,QAAQS,YAAY,CAAC,oBAAoBG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