UNPKG

@assistant-ui/react

Version:

Typescript/React library for AI Chat

1 lines 1.97 kB
{"version":3,"sources":["../../../src/context/providers/ContentPartRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport { ContentPartContext } from \"../react/ContentPartContext\";\nimport type { ContentPartContextValue } from \"../react/ContentPartContext\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { ContentPartRuntime } from \"../../api/ContentPartRuntime\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\n\nexport namespace ContentPartRuntimeProvider {\n export type Props = PropsWithChildren<{\n runtime: ContentPartRuntime;\n }>;\n}\n\nconst useContentPartRuntimeStore = (runtime: ContentPartRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const ContentPartRuntimeProvider: FC<\n ContentPartRuntimeProvider.Props\n> = ({ runtime, children }) => {\n const useContentPartRuntime = useContentPartRuntimeStore(runtime);\n const [context] = useState<ContentPartContextValue>(() => {\n return { useContentPartRuntime };\n });\n\n return (\n <ContentPartContext.Provider value={context}>\n {children}\n </ContentPartContext.Provider>\n );\n};\n"],"mappings":";;;AAEA,SAA0C,WAAW,gBAAgB;AACrE,SAAS,cAAc;AACvB,SAAS,0BAA0B;AAEnC,SAAS,qBAAqB;AAE9B,SAAS,qBAAqB;AA6B1B;AArBJ,IAAM,6BAA6B,CAAC,YAAgC;AAClE,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,OAAO,CAAC;AAEpD,YAAU,MAAM;AACd,kBAAc,OAAO;AAErB,kBAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,6BAET,CAAC,EAAE,SAAS,SAAS,MAAM;AAC7B,QAAM,wBAAwB,2BAA2B,OAAO;AAChE,QAAM,CAAC,OAAO,IAAI,SAAkC,MAAM;AACxD,WAAO,EAAE,sBAAsB;AAAA,EACjC,CAAC;AAED,SACE,oBAAC,mBAAmB,UAAnB,EAA4B,OAAO,SACjC,UACH;AAEJ;","names":[]}