UNPKG

@liveblocks/react-ui

Version:

A set of React pre-built components for the Liveblocks products. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.

1 lines 2.65 kB
{"version":3,"file":"contexts.cjs","sources":["../../../src/primitives/AiComposer/contexts.ts"],"sourcesContent":["import { type MessageId, nn } from \"@liveblocks/core\";\nimport {\n createContext,\n type Dispatch,\n type SetStateAction,\n useContext,\n} from \"react\";\nimport type {\n Descendant as SlateDescendant,\n Editor as SlateEditor,\n} from \"slate\";\n\nexport type AiComposerContext = {\n /**\n * Whether the composer is currently disabled.\n */\n isDisabled: boolean;\n\n /**\n * Whether the composer can currently be submitted.\n */\n canSubmit: boolean;\n\n /**\n * Whether the composer can currently abort a response in its related chat.\n */\n canAbort: boolean;\n\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 * Abort the composer's related response programmatically.\n */\n abort: () => void;\n\n /**\n * Clear the composer 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\nexport type AiComposerEditorContext = {\n onEditorValueChange: (value: SlateDescendant[]) => void;\n editor: SlateEditor;\n abortableMessageId: MessageId | undefined;\n setFocused: Dispatch<SetStateAction<boolean>>;\n};\n\nexport const AiComposerContext = createContext<AiComposerContext | null>(null);\nexport const AiComposerEditorContext =\n createContext<AiComposerEditorContext | null>(null);\n\nexport function useAiComposerEditorContext() {\n const composerEditorContext = useContext(AiComposerEditorContext);\n\n return nn(\n composerEditorContext,\n \"AiComposer.Form is missing from the React tree.\"\n );\n}\n\nexport function useAiComposer(): AiComposerContext {\n const composerContext = useContext(AiComposerContext);\n\n return nn(composerContext, \"AiComposer.Form is missing from the React tree.\");\n}\n"],"names":["createContext","useContext","nn"],"mappings":";;;;;AA4Ea,MAAA,iBAAA,GAAoBA,oBAAwC,IAAI,EAAA;AAChE,MAAA,uBAAA,GACXA,oBAA8C,IAAI,EAAA;AAE7C,SAAS,0BAA6B,GAAA;AAC3C,EAAM,MAAA,qBAAA,GAAwBC,iBAAW,uBAAuB,CAAA,CAAA;AAEhE,EAAO,OAAAC,OAAA;AAAA,IACL,qBAAA;AAAA,IACA,iDAAA;AAAA,GACF,CAAA;AACF,CAAA;AAEO,SAAS,aAAmC,GAAA;AACjD,EAAM,MAAA,eAAA,GAAkBD,iBAAW,iBAAiB,CAAA,CAAA;AAEpD,EAAO,OAAAC,OAAA,CAAG,iBAAiB,iDAAiD,CAAA,CAAA;AAC9E;;;;;;;"}