{"version":3,"file":"gridContext.mjs","names":["React","useRouter","formatAdminURL","useDrawerDepth","useConfig","useListDrawerContext","useRouteTransition","useSelection","jsx","_jsx","Context","createContext","docs","clearSelections","onItemClick","undefined","onItemKeyPress","setFocusedItemIndex","focusedItemIndex","GridProvider","props","allowMultiSelection","children","config","drawerDepth","router","startRouteTransition","setSelection","selectedIDs","onSelect","isInDrawer","currentlySelectedIndexes","useRef","Set","useState","lastClickTime","totalCount","length","useCallback","current","getItem","id","find","doc","navigateAfterSelection","collectionSlug","docID","push","adminRoute","routes","admin","path","handleShiftSelection","targetIndex","existingIndexes","reduce","acc","item","idx","includes","firstSelectedIndex","Math","min","lastSelectedIndex","max","isWithinBounds","anchorIndex","distanceToFirst","abs","distanceToLast","startIndex","endIndex","newRangeIndexes","Array","from","_","i","mappedSet","updateSelections","indexes","newSelectedIDs","index","add","forEach","event","currentItem","code","ctrlKey","metaKey","shiftKey","isShiftPressed","isCtrlPressed","isCurrentlySelected","currentItemIndex","findIndex","preventDefault","isBackward","newItemIndex","selectedIndexes","relationTo","prevIndex","nextIndex","lastClickedItem","setLastClickedItem","clickedItem","doubleClicked","now","Date","value","useGrid","context","use","Error"],"sources":["../../../src/components/gridContext/gridContext.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\nimport { useRouter } from 'next/navigation'\nimport { formatAdminURL } from 'payload/shared'\n\nimport { useDrawerDepth } from '@payloadcms/ui/elements/Drawer'\nimport {\n  useConfig,\n  useListDrawerContext,\n  useRouteTransition,\n  useSelection,\n} from '@payloadcms/ui'\n\nimport type { FolderSortKeys } from 'payload'\nimport type { MappedDocument } from '../gridView/gridView'\ninterface OnItemClickArgs {\n  event: React.MouseEvent\n  index: number\n  item: MappedDocument\n}\n\ninterface OnItemKeyPressArgs {\n  event: React.KeyboardEvent\n  index: number\n  item: MappedDocument\n}\n\nexport type GridContextValue = {\n  docs?: MappedDocument[]\n  clearSelections: () => void\n  onItemClick: (args: OnItemClickArgs) => void\n  onItemKeyPress: (args: OnItemKeyPressArgs) => void\n  setFocusedItemIndex: React.Dispatch<React.SetStateAction<number>>\n  focusedItemIndex: number\n}\n\nconst Context = React.createContext<GridContextValue>({\n  docs: [],\n  clearSelections: () => {},\n  onItemClick: () => undefined,\n  onItemKeyPress: () => undefined,\n  setFocusedItemIndex: () => -1,\n  focusedItemIndex: -1,\n})\n\nexport type GridProviderProps = {\n  readonly allowMultiSelection?: boolean\n  /**\n   * Children to render inside the provider\n   */\n  readonly children: React.ReactNode\n  /**\n   * All documents in the current folder\n   */\n  readonly docs: MappedDocument[]\n  /**\n   * The intial search query\n   */\n  readonly search?: string\n  /**\n   * The sort order of the documents\n   *\n   * @example\n   * `name` for descending\n   * `-name` for ascending\n   */\n  readonly sort?: FolderSortKeys\n}\nexport function GridProvider(props: GridProviderProps) {\n  const { allowMultiSelection, children, docs } = props\n\n  const { config } = useConfig()\n  const drawerDepth = useDrawerDepth()\n  const router = useRouter()\n  const { startRouteTransition } = useRouteTransition()\n\n  const { setSelection, selectedIDs } = useSelection()\n  const { onSelect, isInDrawer } = useListDrawerContext()\n\n  const currentlySelectedIndexes = React.useRef(new Set<number>())\n\n  const [focusedItemIndex, setFocusedItemIndex] = React.useState(-1)\n  const lastClickTime = React.useRef<null | number>(null)\n  const totalCount = docs.length\n\n  const clearSelections = React.useCallback(() => {\n    setFocusedItemIndex(-1)\n\n    currentlySelectedIndexes.current = new Set()\n  }, [])\n\n  const getItem = React.useCallback(\n    (id: string | number) => {\n      return docs.find((doc) => doc.id === id)\n    },\n    [docs]\n  )\n\n  const navigateAfterSelection = React.useCallback(\n    ({\n      collectionSlug,\n      docID,\n    }: {\n      collectionSlug: string\n      docID?: number | string\n    }) => {\n      if (drawerDepth === 1) {\n        // not in a drawer (default is 1)\n        if (collectionSlug) {\n          // clicked on document, take the user to the documet view\n          startRouteTransition(() => {\n            router.push(\n              formatAdminURL({\n                adminRoute: config.routes.admin,\n                path: `/collections/${collectionSlug}/${docID}`,\n              })\n            )\n            clearSelections()\n          })\n        }\n      } else {\n        clearSelections()\n      }\n    },\n    [\n      clearSelections,\n      config.routes.admin,\n      drawerDepth,\n      getItem,\n      router,\n      startRouteTransition,\n    ]\n  )\n\n  const handleShiftSelection = React.useCallback(\n    (targetIndex: number) => {\n      // Find existing selection boundaries\n      const existingIndexes = docs.reduce((acc, item, idx) => {\n        if (selectedIDs.includes(item.id)) {\n          acc.push(idx)\n        }\n        return acc\n      }, [] as number[])\n\n      if (existingIndexes.length === 0) {\n        // No existing selection, just select target\n        return [targetIndex]\n      }\n\n      const firstSelectedIndex = Math.min(...existingIndexes)\n      const lastSelectedIndex = Math.max(...existingIndexes)\n      const isWithinBounds =\n        targetIndex >= firstSelectedIndex && targetIndex <= lastSelectedIndex\n\n      // Choose anchor based on whether we're contracting or extending\n      let anchorIndex = targetIndex\n      if (isWithinBounds) {\n        // Contracting: if target is at a boundary, use target as anchor\n        // Otherwise, use furthest boundary to maintain opposite edge\n        if (\n          targetIndex === firstSelectedIndex ||\n          targetIndex === lastSelectedIndex\n        ) {\n          anchorIndex = targetIndex\n        } else {\n          const distanceToFirst = Math.abs(targetIndex - firstSelectedIndex)\n          const distanceToLast = Math.abs(targetIndex - lastSelectedIndex)\n          anchorIndex =\n            distanceToFirst >= distanceToLast\n              ? firstSelectedIndex\n              : lastSelectedIndex\n        }\n      } else {\n        // Extending: use closest boundary\n        const distanceToFirst = Math.abs(targetIndex - firstSelectedIndex)\n        const distanceToLast = Math.abs(targetIndex - lastSelectedIndex)\n        anchorIndex =\n          distanceToFirst <= distanceToLast\n            ? firstSelectedIndex\n            : lastSelectedIndex\n      }\n\n      // Create range from anchor to target\n      const startIndex = Math.min(anchorIndex, targetIndex)\n      const endIndex = Math.max(anchorIndex, targetIndex)\n      const newRangeIndexes = Array.from(\n        { length: endIndex - startIndex + 1 },\n        (_, i) => startIndex + i\n      )\n\n      if (isWithinBounds) {\n        // Contracting: replace with new range\n        return newRangeIndexes\n      } else {\n        // Extending: union with existing\n        const mappedSet = new Set([...existingIndexes, ...newRangeIndexes])\n        return Array.from(mappedSet)\n      }\n    },\n    [docs, selectedIDs]\n  )\n\n  const updateSelections = React.useCallback(\n    ({ indexes }: { indexes: number[] }) => {\n      const { newSelectedIDs } = docs.reduce(\n        (acc, item, index) => {\n          if (indexes.includes(index)) {\n            acc.newSelectedIDs.add(item.id)\n          }\n          return acc\n        },\n        {\n          newSelectedIDs: new Set<string | number>(),\n        }\n      )\n\n      // Clear previous selection in global selection context\n      selectedIDs.forEach((id) => {\n        setSelection(id)\n      })\n\n      // Update selection in global selection context\n      newSelectedIDs.forEach((id) => {\n        const item = getItem(id)\n        if (item) {\n          setSelection(item.id)\n        }\n      })\n    },\n    [docs, getItem, setSelection]\n  )\n\n  const onItemKeyPress: GridContextValue['onItemKeyPress'] = React.useCallback(\n    ({ event, item: currentItem }) => {\n      const { code, ctrlKey, metaKey, shiftKey } = event\n\n      const isShiftPressed = shiftKey\n      const isCtrlPressed = ctrlKey || metaKey\n      const isCurrentlySelected = selectedIDs.includes(currentItem.id)\n      const currentItemIndex = docs.findIndex(\n        (item) => item.id === currentItem.id\n      )\n\n      switch (code) {\n        case 'ArrowDown':\n        case 'ArrowLeft':\n        case 'ArrowRight':\n        case 'ArrowUp': {\n          event.preventDefault()\n\n          if (currentItemIndex === -1) {\n            break\n          }\n\n          const isBackward = code === 'ArrowLeft' || code === 'ArrowUp'\n          const newItemIndex = isBackward\n            ? currentItemIndex - 1\n            : currentItemIndex + 1\n\n          if (newItemIndex < 0 || newItemIndex > totalCount - 1) {\n            // out of bounds, keep current selection\n            return\n          }\n\n          setFocusedItemIndex(newItemIndex)\n\n          if (isCtrlPressed) {\n            break\n          }\n\n          if (isShiftPressed && allowMultiSelection) {\n            const selectedIndexes = handleShiftSelection(newItemIndex)\n            updateSelections({ indexes: selectedIndexes })\n            return\n          }\n\n          // Single selection without shift\n          if (!isShiftPressed) {\n            updateSelections({ indexes: [newItemIndex] })\n          }\n\n          break\n        }\n        case 'Enter': {\n          if (selectedIDs.length === 1) {\n            if (isInDrawer && typeof onSelect === 'function') {\n              onSelect({\n                collectionSlug: currentItem.relationTo,\n                doc: currentItem,\n                docID: currentItem.id as string,\n              })\n              return\n            }\n\n            navigateAfterSelection({\n              collectionSlug: currentItem.relationTo,\n              docID: currentItem.id,\n            })\n            return\n          }\n          break\n        }\n        case 'Escape': {\n          clearSelections()\n          break\n        }\n        case 'KeyA': {\n          if (allowMultiSelection && isCtrlPressed) {\n            event.preventDefault()\n            setFocusedItemIndex(totalCount - 1)\n            updateSelections({\n              indexes: Array.from({ length: totalCount }, (_, i) => i),\n            })\n          }\n          break\n        }\n        case 'Space': {\n          if (allowMultiSelection && isShiftPressed) {\n            event.preventDefault()\n            updateSelections({\n              indexes: docs.reduce((acc, item, idx) => {\n                if (item.id === currentItem.id) {\n                  if (isCurrentlySelected) {\n                    return acc\n                  } else {\n                    acc.push(idx)\n                  }\n                } else if (selectedIDs.includes(item.id)) {\n                  acc.push(idx)\n                }\n                return acc\n              }, [] as number[]),\n            })\n          } else {\n            event.preventDefault()\n            updateSelections({\n              indexes: isCurrentlySelected ? [] : [currentItemIndex],\n            })\n          }\n          break\n        }\n        case 'Tab': {\n          if (allowMultiSelection && isShiftPressed) {\n            const prevIndex = currentItemIndex - 1\n            if (prevIndex < 0 && selectedIDs.length > 0) {\n              setFocusedItemIndex(prevIndex)\n            }\n          } else {\n            const nextIndex = currentItemIndex + 1\n            if (nextIndex === totalCount && selectedIDs.length > 0) {\n              setFocusedItemIndex(totalCount - 1)\n            }\n          }\n          break\n        }\n      }\n    },\n    [\n      selectedIDs,\n      docs,\n      allowMultiSelection,\n      handleShiftSelection,\n      updateSelections,\n      navigateAfterSelection,\n      clearSelections,\n      totalCount,\n    ]\n  )\n\n  // Track last clicked item for double-click detection\n  const [lastClickedItem, setLastClickedItem] = React.useState<\n    MappedDocument | undefined\n  >()\n\n  const onItemClick: GridContextValue['onItemClick'] = React.useCallback(\n    ({ event, item: clickedItem }) => {\n      let doubleClicked: boolean = false\n      const isCtrlPressed = event.ctrlKey || event.metaKey\n      const isShiftPressed = event.shiftKey\n      const isCurrentlySelected = selectedIDs.includes(clickedItem.id)\n      const currentItemIndex = docs.findIndex(\n        (item) => item.id === clickedItem.id\n      )\n\n      switch (true) {\n        case allowMultiSelection && isCtrlPressed: {\n          event.preventDefault()\n          const indexes = docs.reduce((acc, item, idx) => {\n            if (item.id === clickedItem.id) {\n              if (!isCurrentlySelected) {\n                acc.push(idx)\n              }\n            } else if (selectedIDs.includes(item.id)) {\n              acc.push(idx)\n            }\n            return acc\n          }, [] as number[])\n\n          updateSelections({ indexes })\n          break\n        }\n\n        case allowMultiSelection && isShiftPressed: {\n          if (currentItemIndex !== -1) {\n            const selectedIndexes = handleShiftSelection(currentItemIndex)\n            updateSelections({ indexes: selectedIndexes })\n          }\n          break\n        }\n\n        // In drawer, select single item if clicked and no other items are selected\n        case isInDrawer &&\n          typeof onSelect === 'function' &&\n          selectedIDs.length === 0: {\n          onSelect({\n            collectionSlug: clickedItem.relationTo,\n            doc: clickedItem,\n            docID: clickedItem.id as string,\n          })\n          break\n        }\n\n        default: {\n          const now = Date.now()\n          doubleClicked =\n            now - (lastClickTime.current ?? 0) < 400 &&\n            lastClickedItem?.id === clickedItem.id\n          lastClickTime.current = now\n\n          if (!doubleClicked) {\n            updateSelections({\n              indexes:\n                isCurrentlySelected && selectedIDs.length === 1\n                  ? []\n                  : [currentItemIndex],\n            })\n          }\n          break\n        }\n      }\n\n      // Update last clicked item to determine double clicks\n      setLastClickedItem(clickedItem)\n\n      if (doubleClicked && !isInDrawer) {\n        navigateAfterSelection({\n          collectionSlug: clickedItem.relationTo,\n          docID: clickedItem.id,\n        })\n      }\n    },\n    [\n      docs,\n      allowMultiSelection,\n      getItem,\n      updateSelections,\n      navigateAfterSelection,\n      handleShiftSelection,\n    ]\n  )\n\n  return (\n    <Context\n      value={{\n        clearSelections,\n        docs,\n        focusedItemIndex,\n        onItemClick,\n        onItemKeyPress,\n        setFocusedItemIndex,\n      }}\n    >\n      {children}\n    </Context>\n  )\n}\n\nexport function useGrid(): GridContextValue {\n  const context = React.use(Context)\n\n  if (context === undefined) {\n    throw new Error('useGrid must be used within a GridProvider')\n  }\n\n  return context\n}\n"],"mappings":";;;;;;;;;;AAqCA,MAAMU,UAAUV,sBAAMW,cAAgC;CACpDC,MAAM,EAAE;CACRC,uBAAuB;CACvBC,mBAAmBC;CACnBC,sBAAsBD;CACtBE,2BAA2B;CAC3BC,kBAAkB;CACnB,CAAC;AAyBF,SAAgBC,aAAaC,OAA0B;CACrD,MAAM,EAAEC,qBAAqBC,UAAUV,SAASQ;CAEhD,MAAM,EAAEG,WAAWnB,WAAW;CAC9B,MAAMoB,cAAcrB,gBAAgB;CACpC,MAAMsB,SAASxB,WAAW;CAC1B,MAAM,EAAEyB,yBAAyBpB,oBAAoB;CAErD,MAAM,EAAEqB,cAAcC,gBAAgBrB,cAAc;CACpD,MAAM,EAAEsB,UAAUC,eAAezB,sBAAsB;CAEvD,MAAM0B,2BAA2B/B,MAAMgC,uBAAO,IAAIC,KAAa,CAAC;CAEhE,MAAM,CAACf,kBAAkBD,uBAAuBjB,MAAMkC,SAAS,GAAG;CAClE,MAAMC,gBAAgBnC,MAAMgC,OAAsB,KAAK;CACvD,MAAMI,aAAaxB,KAAKyB;CAExB,MAAMxB,kBAAkBb,MAAMsC,kBAAkB;AAC9CrB,sBAAoB,GAAG;AAEvBc,2BAAyBQ,0BAAU,IAAIN,KAAK;IAC3C,EAAE,CAAC;CAEN,MAAMO,UAAUxC,MAAMsC,aACnBG,OAAwB;AACvB,SAAO7B,KAAK8B,MAAMC,QAAQA,IAAIF,OAAOA,GAAG;IAE1C,CAAC7B,KACH,CAAC;CAED,MAAMgC,yBAAyB5C,MAAMsC,aAClC,EACCO,gBACAC,YAII;AACJ,MAAItB,gBAAgB,GAElB;OAAIqB,eAEFnB,4BAA2B;AACzBD,WAAOsB,KACL7C,eAAe;KACb8C,YAAYzB,OAAO0B,OAA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