{
  "version": 3,
  "sources": ["../../src/hooks/use-selected-items.ts"],
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { View } from '../types';\n\n/**\n * Hook to get selected items, with support for infinite scroll.\n *\n * When infinite scroll is enabled, items that scroll out of view are cached\n * so they remain available for bulk actions even when not in the current data set.\n *\n * @param view      The current view configuration.\n * @param data      The current page of data items.\n * @param selection Array of selected item IDs.\n * @param getItemId Function to get the ID of an item.\n * @param filterFn  Optional filter function to apply to selected items (e.g., for selectability).\n * @return Array of selected items.\n */\nexport default function useSelectedItems< Item >(\n\tview: View,\n\tdata: Item[],\n\tselection: string[],\n\tgetItemId: ( item: Item ) => string,\n\tfilterFn?: ( item: Item ) => boolean\n): Item[] {\n\t// With infinite scroll enabled items scroll out of view, but we want to keep the selection unaltered,\n\t// unlike page-based navigation where we might clear selection upon navigating to a different page.\n\tconst selectedItemsCacheRef = useRef< Map< string, Item > >( new Map() );\n\n\treturn useMemo( () => {\n\t\tconst selectionSet = new Set( selection );\n\n\t\tif ( view.infiniteScrollEnabled ) {\n\t\t\t// Selection array contains selected item IDs\n\t\t\t// Cache selected items so they remain available when scrolled out of view\n\t\t\tdata.forEach( ( item ) => {\n\t\t\t\tconst id = getItemId( item );\n\t\t\t\tif ( selectionSet.has( id ) ) {\n\t\t\t\t\tconst passesFilter = filterFn ? filterFn( item ) : true;\n\t\t\t\t\tif ( passesFilter ) {\n\t\t\t\t\t\tselectedItemsCacheRef.current.set( id, item );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\t// Remove items from cache that are no longer selected\n\t\t\tselectedItemsCacheRef.current.forEach( ( _, id ) => {\n\t\t\t\tif ( ! selectionSet.has( id ) ) {\n\t\t\t\t\tselectedItemsCacheRef.current.delete( id );\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\t// Return all cached selected items\n\t\t\treturn Array.from( selectedItemsCacheRef.current.values() );\n\t\t}\n\n\t\t// Non-infinite scroll mode\n\t\treturn data.filter( ( item ) => {\n\t\t\tconst id = getItemId( item );\n\t\t\tif ( ! selectionSet.has( id ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t// Apply optional filter (e.g., selectability check for bulk actions)\n\t\t\treturn filterFn ? filterFn( item ) : true;\n\t\t} );\n\t}, [ view.infiniteScrollEnabled, selection, getItemId, data, filterFn ] );\n}\n"],
  "mappings": ";AAGA,SAAS,SAAS,cAAc;AAoBjB,SAAR,iBACN,MACA,MACA,WACA,WACA,UACS;AAGT,QAAM,wBAAwB,OAA+B,oBAAI,IAAI,CAAE;AAEvE,SAAO,QAAS,MAAM;AACrB,UAAM,eAAe,IAAI,IAAK,SAAU;AAExC,QAAK,KAAK,uBAAwB;AAGjC,WAAK,QAAS,CAAE,SAAU;AACzB,cAAM,KAAK,UAAW,IAAK;AAC3B,YAAK,aAAa,IAAK,EAAG,GAAI;AAC7B,gBAAM,eAAe,WAAW,SAAU,IAAK,IAAI;AACnD,cAAK,cAAe;AACnB,kCAAsB,QAAQ,IAAK,IAAI,IAAK;AAAA,UAC7C;AAAA,QACD;AAAA,MACD,CAAE;AAGF,4BAAsB,QAAQ,QAAS,CAAE,GAAG,OAAQ;AACnD,YAAK,CAAE,aAAa,IAAK,EAAG,GAAI;AAC/B,gCAAsB,QAAQ,OAAQ,EAAG;AAAA,QAC1C;AAAA,MACD,CAAE;AAGF,aAAO,MAAM,KAAM,sBAAsB,QAAQ,OAAO,CAAE;AAAA,IAC3D;AAGA,WAAO,KAAK,OAAQ,CAAE,SAAU;AAC/B,YAAM,KAAK,UAAW,IAAK;AAC3B,UAAK,CAAE,aAAa,IAAK,EAAG,GAAI;AAC/B,eAAO;AAAA,MACR;AAEA,aAAO,WAAW,SAAU,IAAK,IAAI;AAAA,IACtC,CAAE;AAAA,EACH,GAAG,CAAE,KAAK,uBAAuB,WAAW,WAAW,MAAM,QAAS,CAAE;AACzE;",
  "names": []
}
