{"version":3,"file":"contexts.mjs","sources":["../../../src/primitives/Composer/contexts.ts"],"sourcesContent":["import type { Placement } from \"@floating-ui/react-dom\";\nimport { nn } from \"@liveblocks/core\";\nimport type { Direction } from \"@radix-ui/react-dropdown-menu\";\nimport type { Dispatch, Ref, SetStateAction } from \"react\";\nimport { createContext, useContext } from \"react\";\nimport type { Editor as SlateEditor, Element as SlateElement } from \"slate\";\n\nexport type ComposerContext = {\n  /**\n   * Whether the editor is currently focused.\n   */\n  isFocused: boolean;\n\n  /**\n   * Whether the editor is currently empty.\n   */\n  isEmpty: boolean;\n\n  /**\n   * Submit the composer programmatically.\n   */\n  submit: () => void;\n\n  /**\n   * Clear the editor programmatically.\n   */\n  clear: () => void;\n\n  /**\n   * Select the editor programmatically.\n   */\n  select: () => void;\n\n  /**\n   * Focus the editor programmatically.\n   */\n  focus: () => void;\n\n  /**\n   * Blur the editor programmatically.\n   */\n  blur: () => void;\n\n  /**\n   * Start creating a mention at the current selection.\n   */\n  createMention: () => void;\n\n  /**\n   * Insert text at the current selection.\n   */\n  insertText: (text: string) => void;\n};\n\nexport type ComposerEditorContext = {\n  validate: (value: SlateElement[]) => void;\n  editor: SlateEditor;\n  setFocused: Dispatch<SetStateAction<boolean>>;\n};\n\nexport type ComposerSuggestionsContext = {\n  dir?: Direction;\n  id: string;\n  itemId: (value?: string) => string | undefined;\n  placement: Placement;\n  selectedValue?: string;\n  setSelectedValue: (value: string) => void;\n  onItemSelect: (value: string) => void;\n  ref: Ref<HTMLDivElement>;\n};\n\nexport const ComposerContext = createContext<ComposerContext | null>(null);\nexport const ComposerEditorContext =\n  createContext<ComposerEditorContext | null>(null);\nexport const ComposerSuggestionsContext =\n  createContext<ComposerSuggestionsContext | null>(null);\n\nexport function useComposerEditorContext() {\n  const composerEditorContext = useContext(ComposerEditorContext);\n\n  return nn(\n    composerEditorContext,\n    \"Composer.Form is missing from the React tree.\"\n  );\n}\n\nexport function useComposer(): ComposerContext {\n  const composerContext = useContext(ComposerContext);\n\n  return nn(composerContext, \"Composer.Form is missing from the React tree.\");\n}\n\nexport function useComposerSuggestionsContext(\n  source = \"useComposerSuggestionsContext\"\n) {\n  const composerSuggestionsContext = useContext(ComposerSuggestionsContext);\n\n  return nn(\n    composerSuggestionsContext,\n    `${source} can’t be used outside of Composer.Editor.`\n  );\n}\n"],"names":[],"mappings":";;;AAuEa,MAAA,eAAA,GAAkB,cAAsC,IAAI,EAAA;AAC5D,MAAA,qBAAA,GACX,cAA4C,IAAI,EAAA;AACrC,MAAA,0BAAA,GACX,cAAiD,IAAI,EAAA;AAEhD,SAAS,wBAA2B,GAAA;AACzC,EAAM,MAAA,qBAAA,GAAwB,WAAW,qBAAqB,CAAA,CAAA;AAE9D,EAAO,OAAA,EAAA;AAAA,IACL,qBAAA;AAAA,IACA,+CAAA;AAAA,GACF,CAAA;AACF,CAAA;AAEO,SAAS,WAA+B,GAAA;AAC7C,EAAM,MAAA,eAAA,GAAkB,WAAW,eAAe,CAAA,CAAA;AAElD,EAAO,OAAA,EAAA,CAAG,iBAAiB,+CAA+C,CAAA,CAAA;AAC5E,CAAA;AAEgB,SAAA,6BAAA,CACd,SAAS,+BACT,EAAA;AACA,EAAM,MAAA,0BAAA,GAA6B,WAAW,0BAA0B,CAAA,CAAA;AAExE,EAAO,OAAA,EAAA;AAAA,IACL,0BAAA;AAAA,IACA,CAAG,EAAA,MAAA,CAAA,+CAAA,CAAA;AAAA,GACL,CAAA;AACF;;;;"}