UNPKG

@assistant-ui/react

Version:

Typescript/React library for AI Chat

1 lines 1.67 kB
{"version":3,"sources":["../../../src/context/react/ContentPartContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { createContextHook } from \"./utils/createContextHook\";\nimport { UseBoundStore } from \"zustand\";\nimport { ContentPartRuntime } from \"../../api/ContentPartRuntime\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\n\nexport type ContentPartContextValue = {\n useContentPartRuntime: UseBoundStore<ReadonlyStore<ContentPartRuntime>>;\n};\n\nexport const ContentPartContext = createContext<ContentPartContextValue | null>(\n null,\n);\n\nconst useContentPartContext = createContextHook(\n ContentPartContext,\n \"a component passed to <MessagePrimitive.Content components={...}>\",\n);\n\nexport function useContentPartRuntime(options?: {\n optional?: false | undefined;\n}): ContentPartRuntime;\nexport function useContentPartRuntime(options?: {\n optional?: boolean | undefined;\n}): ContentPartRuntime | null;\nexport function useContentPartRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const context = useContentPartContext(options);\n if (!context) return null;\n return context.useContentPartRuntime();\n}\n\nexport const useContentPart = createStateHookForRuntime(useContentPartRuntime);\n"],"mappings":";;;AAEA,SAAS,qBAAqB;AAE9B,SAAS,yBAAyB;AAGlC,SAAS,iCAAiC;AAMnC,IAAM,qBAAqB;AAAA,EAChC;AACF;AAEA,IAAM,wBAAwB;AAAA,EAC5B;AAAA,EACA;AACF;AAQO,SAAS,sBAAsB,SAEnC;AACD,QAAM,UAAU,sBAAsB,OAAO;AAC7C,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,sBAAsB;AACvC;AAEO,IAAM,iBAAiB,0BAA0B,qBAAqB;","names":[]}