{"version":3,"file":"SpotlightRoot.mjs","names":["classes"],"sources":["../src/SpotlightRoot.tsx"],"sourcesContent":["import {\n  factory,\n  Factory,\n  getDefaultZIndex,\n  Modal,\n  ModalProps,\n  ModalStylesNames,\n  rem,\n  StylesApiProps,\n  useProps,\n  useResolvedStylesApi,\n  useStyles,\n} from '@mantine/core';\nimport { useDidUpdate, useHotkeys } from '@mantine/hooks';\nimport { getHotkeys } from './get-hotkeys';\nimport { SpotlightProvider } from './Spotlight.context';\nimport { spotlightActions, SpotlightStore, spotlightStore, useSpotlight } from './spotlight.store';\nimport classes from './Spotlight.module.css';\n\nexport type SpotlightRootStylesNames =\n  | ModalStylesNames\n  | 'search'\n  | 'actionsList'\n  | 'action'\n  | 'empty'\n  | 'footer'\n  | 'actionBody'\n  | 'actionLabel'\n  | 'actionDescription'\n  | 'actionSection'\n  | 'actionsGroup';\n\nexport interface SpotlightRootProps\n  extends\n    StylesApiProps<SpotlightRootFactory>,\n    Omit<\n      ModalProps,\n      | 'styles'\n      | 'classNames'\n      | 'vars'\n      | 'variant'\n      | 'opened'\n      | 'onClose'\n      | 'closeButtonProps'\n      | 'withCloseButton'\n    > {\n  /** Spotlight store, can be used to create multiple instances of spotlight */\n  store?: SpotlightStore;\n\n  /** Controlled Spotlight search query */\n  query?: string;\n\n  /** Called when query changes */\n  onQueryChange?: (query: string) => void;\n\n  /** Determines whether the search query should be cleared when the spotlight is closed @default true */\n  clearQueryOnClose?: boolean;\n\n  /** Keyboard shortcut or a list of shortcuts to trigger spotlight @default 'mod + K' */\n  shortcut?: string | string[] | null;\n\n  /** A list of tags which when focused will be ignored by shortcut @default ['input', 'textarea', 'select'] */\n  tagsToIgnore?: string[];\n\n  /** Determines whether shortcut should trigger based in contentEditable @default false */\n  triggerOnContentEditable?: boolean;\n\n  /** If set, spotlight will not be rendered */\n  disabled?: boolean;\n\n  /** Called when spotlight opens */\n  onSpotlightOpen?: () => void;\n\n  /** Called when spotlight closes */\n  onSpotlightClose?: () => void;\n\n  /** Forces opened state, useful for tests */\n  forceOpened?: boolean;\n\n  /** Determines whether spotlight should be closed when one of the actions is triggered @default true */\n  closeOnActionTrigger?: boolean;\n\n  /** Spotlight content max-height. Ignored unless `scrollable` prop is set. @default 400 */\n  maxHeight?: React.CSSProperties['maxHeight'];\n\n  /** Determines whether the actions list should be scrollable. If not set, `maxHeight` is ignored @default false */\n  scrollable?: boolean;\n}\n\nexport type SpotlightRootFactory = Factory<{\n  props: SpotlightRootProps;\n  ref: HTMLDivElement;\n  stylesNames: SpotlightRootStylesNames;\n  compound: true;\n}>;\n\nconst defaultProps = {\n  size: 600,\n  yOffset: 80,\n  zIndex: getDefaultZIndex('max'),\n  overlayProps: { backgroundOpacity: 0.35, blur: 7 },\n  transitionProps: { duration: 200, transition: 'pop' },\n  store: spotlightStore,\n  clearQueryOnClose: true,\n  closeOnActionTrigger: true,\n  shortcut: 'mod + K',\n  maxHeight: 400,\n} satisfies Partial<SpotlightRootProps>;\n\nexport const SpotlightRoot = factory<SpotlightRootFactory>((_props) => {\n  const props = useProps('SpotlightRoot', defaultProps, _props);\n  const {\n    classNames,\n    className,\n    style,\n    styles,\n    unstyled,\n    vars,\n    store,\n    children,\n    query,\n    onQueryChange,\n    transitionProps,\n    clearQueryOnClose,\n    shortcut,\n    tagsToIgnore,\n    triggerOnContentEditable,\n    disabled,\n    onSpotlightOpen,\n    onSpotlightClose,\n    forceOpened,\n    closeOnActionTrigger,\n    maxHeight,\n    scrollable,\n    attributes,\n    ...others\n  } = props;\n\n  const { opened, query: storeQuery } = useSpotlight(store);\n  const _query = typeof query === 'string' ? query : storeQuery;\n  const setQuery = (q: string) => {\n    onQueryChange?.(q);\n    spotlightActions.setQuery(q, store);\n  };\n\n  const getStyles = useStyles<SpotlightRootFactory>({\n    name: 'Spotlight',\n    classes,\n    props,\n    className,\n    style,\n    classNames,\n    styles,\n    unstyled,\n    attributes,\n  });\n\n  const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<SpotlightRootFactory>({\n    classNames,\n    styles,\n    props,\n  });\n\n  useHotkeys(getHotkeys(shortcut, store), tagsToIgnore, triggerOnContentEditable);\n\n  useDidUpdate(() => {\n    opened ? onSpotlightOpen?.() : onSpotlightClose?.();\n  }, [opened]);\n\n  if (disabled) {\n    return null;\n  }\n\n  return (\n    <SpotlightProvider\n      value={{\n        getStyles,\n        query: _query,\n        setQuery,\n        store,\n        closeOnActionTrigger,\n      }}\n    >\n      <Modal\n        {...others}\n        withCloseButton={false}\n        opened={opened || !!forceOpened}\n        padding={0}\n        onClose={() => spotlightActions.close(store)}\n        className={className}\n        style={style}\n        classNames={resolvedClassNames}\n        styles={resolvedStyles}\n        attributes={attributes}\n        transitionProps={{\n          ...transitionProps,\n          onExited: () => {\n            clearQueryOnClose && setQuery('');\n            spotlightActions.clearSpotlightState({ clearQuery: clearQueryOnClose }, store);\n            transitionProps?.onExited?.();\n          },\n        }}\n        __vars={{ '--spotlight-max-height': scrollable ? rem(maxHeight) : undefined }}\n        __staticSelector=\"Spotlight\"\n        data-scrollable={scrollable || undefined}\n      >\n        {children}\n      </Modal>\n    </SpotlightProvider>\n  );\n});\n\nSpotlightRoot.classes = classes;\nSpotlightRoot.displayName = '@mantine/spotlight/SpotlightRoot';\n"],"mappings":";;;;;;;;;AAgGA,MAAM,eAAe;CACnB,MAAM;CACN,SAAS;CACT,QAAQ,iBAAiB,KAAK;CAC9B,cAAc;EAAE,mBAAmB;EAAM,MAAM;CAAE;CACjD,iBAAiB;EAAE,UAAU;EAAK,YAAY;CAAM;CACpD,OAAO;CACP,mBAAmB;CACnB,sBAAsB;CACtB,UAAU;CACV,WAAW;AACb;AAEA,MAAa,gBAAgB,SAA+B,WAAW;CACrE,MAAM,QAAQ,SAAS,iBAAiB,cAAc,MAAM;CAC5D,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,OACA,UACA,OACA,eACA,iBACA,mBACA,UACA,cACA,0BACA,UACA,iBACA,kBACA,aACA,sBACA,WACA,YACA,YACA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