{"version":3,"file":"Spotlight.cjs","names":["spotlightStore","defaultSpotlightFilter","limitActions","isActionsGroup","SpotlightAction","SpotlightActionsGroup","SpotlightRoot","SpotlightSearch","SpotlightActionsList","SpotlightEmpty","classes","SpotlightFooter","spotlight"],"sources":["../src/Spotlight.tsx"],"sourcesContent":["import {\n  factory,\n  Factory,\n  getDefaultZIndex,\n  ScrollAreaAutosizeProps,\n  useProps,\n} from '@mantine/core';\nimport { useUncontrolled } from '@mantine/hooks';\nimport { defaultSpotlightFilter } from './default-spotlight-filter';\nimport { isActionsGroup } from './is-actions-group';\nimport { limitActions } from './limit-actions';\nimport { spotlight, spotlightStore } from './spotlight.store';\nimport {\n  SpotlightAction,\n  SpotlightActionProps,\n  type SpotlightActionStylesNames,\n} from './SpotlightAction';\nimport {\n  SpotlightActionsGroup,\n  type SpotlightActionsGroupProps,\n  type SpotlightActionsGroupStylesNames,\n} from './SpotlightActionsGroup';\nimport {\n  SpotlightActionsList,\n  type SpotlightActionsListProps,\n  type SpotlightActionsListStylesNames,\n} from './SpotlightActionsList';\nimport {\n  SpotlightEmpty,\n  type SpotlightEmptyProps,\n  type SpotlightEmptyStylesNames,\n} from './SpotlightEmpty';\nimport {\n  SpotlightFooter,\n  type SpotlightFooterProps,\n  type SpotlightFooterStylesNames,\n} from './SpotlightFooter';\nimport { SpotlightRoot, SpotlightRootProps, SpotlightRootStylesNames } from './SpotlightRoot';\nimport {\n  SpotlightSearch,\n  SpotlightSearchProps,\n  type SpotlightSearchStylesNames,\n} from './SpotlightSearch';\nimport classes from './Spotlight.module.css';\n\nexport type SpotlightFilterFunction = (\n  query: string,\n  actions: SpotlightActions[]\n) => SpotlightActions[];\n\nexport interface SpotlightActionData extends SpotlightActionProps {\n  id: string;\n  group?: string;\n}\n\nexport interface SpotlightActionGroupData {\n  group: string;\n  actions: SpotlightActionData[];\n}\n\nexport type SpotlightActions = SpotlightActionData | SpotlightActionGroupData;\n\nexport type SpotlightStylesNames = SpotlightRootStylesNames;\n\nexport interface SpotlightProps extends SpotlightRootProps {\n  /** Props passed down to the `Spotlight.Search` */\n  searchProps?: SpotlightSearchProps;\n\n  /** Actions data, passed down to `Spotlight.Action` component */\n  actions: SpotlightActions[];\n\n  /** Function to filter actions data based on search query, by default actions are filtered by title, description and keywords */\n  filter?: SpotlightFilterFunction;\n\n  /** Message displayed when none of the actions match given `filter` */\n  nothingFound?: React.ReactNode;\n\n  /** Determines whether search query should be highlighted in action label @default false */\n  highlightQuery?: boolean;\n\n  /** Maximum number of actions displayed at a time @default Infinity */\n  limit?: number;\n\n  /** Props passed down to the `ScrollArea` component */\n  scrollAreaProps?: Partial<ScrollAreaAutosizeProps>;\n}\n\nexport type SpotlightFactory = Factory<{\n  props: SpotlightProps;\n  ref: HTMLDivElement;\n  stylesNames: SpotlightStylesNames;\n  staticComponents: {\n    Search: typeof SpotlightSearch;\n    ActionsList: typeof SpotlightActionsList;\n    Action: typeof SpotlightAction;\n    Empty: typeof SpotlightEmpty;\n    Footer: typeof SpotlightFooter;\n    ActionsGroup: typeof SpotlightActionsGroup;\n    Root: typeof SpotlightRoot;\n    open: typeof spotlight.open;\n    close: typeof spotlight.close;\n    toggle: typeof spotlight.toggle;\n  };\n}>;\n\nconst defaultProps = {\n  size: 600,\n  yOffset: 80,\n  limit: Infinity,\n  zIndex: getDefaultZIndex('max'),\n  overlayProps: { backgroundOpacity: 0.35, blur: 7 },\n  transitionProps: { duration: 200, transition: 'pop' },\n  store: spotlightStore,\n  filter: defaultSpotlightFilter,\n  clearQueryOnClose: true,\n  closeOnActionTrigger: true,\n  shortcut: 'mod + K',\n} satisfies Partial<SpotlightProps>;\n\nexport const Spotlight = factory<SpotlightFactory>((_props) => {\n  const props = useProps('Spotlight', defaultProps, _props);\n  const {\n    searchProps,\n    filter,\n    query,\n    onQueryChange,\n    actions,\n    nothingFound,\n    highlightQuery,\n    limit,\n    scrollAreaProps,\n    ...others\n  } = props;\n\n  const [_query, setQuery] = useUncontrolled({\n    value: query,\n    defaultValue: '',\n    finalValue: '',\n    onChange: onQueryChange,\n  });\n\n  const filteredActions = limitActions(filter(_query, actions), limit).map((item) => {\n    if (isActionsGroup(item)) {\n      const items = item.actions.map(({ id, ...actionData }) => (\n        <SpotlightAction key={id} highlightQuery={highlightQuery} {...actionData} />\n      ));\n\n      return (\n        <SpotlightActionsGroup key={item.group} label={item.group}>\n          {items}\n        </SpotlightActionsGroup>\n      );\n    }\n\n    return <SpotlightAction key={item.id} highlightQuery={highlightQuery} {...item} />;\n  });\n\n  return (\n    <SpotlightRoot {...others} query={_query} onQueryChange={setQuery}>\n      <SpotlightSearch {...searchProps} />\n      {filteredActions.length > 0 && (\n        <SpotlightActionsList {...(scrollAreaProps as any)}>{filteredActions}</SpotlightActionsList>\n      )}\n      {filteredActions.length === 0 && nothingFound && (\n        <SpotlightEmpty>{nothingFound}</SpotlightEmpty>\n      )}\n    </SpotlightRoot>\n  );\n});\n\nSpotlight.classes = classes;\nSpotlight.displayName = '@mantine/spotlight/Spotlight';\nSpotlight.Search = SpotlightSearch;\nSpotlight.ActionsList = SpotlightActionsList;\nSpotlight.Action = SpotlightAction;\nSpotlight.Empty = SpotlightEmpty;\nSpotlight.ActionsGroup = SpotlightActionsGroup;\nSpotlight.Footer = SpotlightFooter;\nSpotlight.Root = SpotlightRoot;\nSpotlight.open = spotlight.open;\nSpotlight.close = spotlight.close;\nSpotlight.toggle = spotlight.toggle;\n\nexport namespace Spotlight {\n  export type Props = SpotlightProps;\n  export type StylesNames = SpotlightStylesNames;\n  export type Factory = SpotlightFactory;\n  export type FilterFunction = SpotlightFilterFunction;\n  export type ActionData = SpotlightActionData;\n  export type ActionGroupData = SpotlightActionGroupData;\n\n  export namespace Action {\n    export type Props = SpotlightActionProps;\n    export type StylesNames = SpotlightActionStylesNames;\n  }\n\n  export namespace ActionsGroup {\n    export type Props = SpotlightActionsGroupProps;\n    export type StylesNames = SpotlightActionsGroupStylesNames;\n  }\n\n  export namespace ActionsList {\n    export type Props = SpotlightActionsListProps;\n    export type StylesNames = SpotlightActionsListStylesNames;\n  }\n\n  export namespace Empty {\n    export type Props = SpotlightEmptyProps;\n    export type StylesNames = SpotlightEmptyStylesNames;\n  }\n\n  export namespace Footer {\n    export type Props = SpotlightFooterProps;\n    export type StylesNames = SpotlightFooterStylesNames;\n  }\n\n  export namespace Search {\n    export type Props = SpotlightSearchProps;\n    export type StylesNames = SpotlightSearchStylesNames;\n  }\n\n  export namespace Root {\n    export type Props = SpotlightRootProps;\n    export type StylesNames = SpotlightRootStylesNames;\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyGA,MAAM,eAAe;CACnB,MAAM;CACN,SAAS;CACT,OAAO;CACP,SAAA,GAAA,cAAA,kBAAyB,KAAK;CAC9B,cAAc;EAAE,mBAAmB;EAAM,MAAM;CAAE;CACjD,iBAAiB;EAAE,UAAU;EAAK,YAAY;CAAM;CACpD,OAAOA,wBAAAA;CACP,QAAQC,iCAAAA;CACR,mBAAmB;CACnB,sBAAsB;CACtB,UAAU;AACZ;AAEA,MAAa,aAAA,GAAA,cAAA,UAAuC,WAAW;CAE7D,MAAM,EACJ,aACA,QACA,OACA,eACA,SACA,cACA,gBACA,OACA,iBACA,GAAG,YAAA,GAAA,cAAA,UAXkB,aAAa,cAAc,MAY1C;CAER,MAAM,CAAC,QAAQ,aAAA,GAAA,eAAA,iBAA4B;EACzC,OAAO;EACP,cAAc;EACd,YAAY;EACZ,UAAU;CACZ,CAAC;CAED,MAAM,kBAAkBC,sBAAAA,aAAa,OAAO,QAAQ,OAAO,GAAG,KAAK,EAAE,KAAK,SAAS;EACjF,IAAIC,yBAAAA,eAAe,IAAI,GAAG;GACxB,MAAM,QAAQ,KAAK,QAAQ,KAAK,EAAE,IAAI,GAAG,iBACvC,iBAAA,GAAA,kBAAA,KAACC,wBAAAA,iBAAD;IAA0C;IAAgB,GAAI;GAAa,GAArD,EAAqD,CAC5E;GAED,OACE,iBAAA,GAAA,kBAAA,KAACC,8BAAAA,uBAAD;I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