@assistant-ui/react
Version:
Typescript/React library for AI Chat
1 lines • 2.37 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/context/providers/ThreadViewportProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useState } from \"react\";\nimport { makeThreadViewportStore } from \"../stores/ThreadViewport\";\nimport {\n ThreadViewportContext,\n ThreadViewportContextValue,\n useThreadViewportStore,\n} from \"../react/ThreadViewportContext\";\nimport { writableStore } from \"../ReadonlyStore\";\n\nconst useThreadViewportStoreValue = () => {\n const outerViewport = useThreadViewportStore({ optional: true });\n const [store] = useState(() => makeThreadViewportStore());\n\n useEffect(() => {\n return outerViewport?.getState().onScrollToBottom(() => {\n store.getState().scrollToBottom();\n });\n }, [outerViewport, store]);\n\n useEffect(() => {\n if (!outerViewport) return;\n return store.subscribe((state) => {\n if (outerViewport.getState().isAtBottom !== state.isAtBottom) {\n writableStore(outerViewport).setState({ isAtBottom: state.isAtBottom });\n }\n });\n }, [store, outerViewport]);\n\n return store;\n};\n\nexport const ThreadViewportProvider: FC<PropsWithChildren> = ({ children }) => {\n const useThreadViewport = useThreadViewportStoreValue();\n\n const [context] = useState<ThreadViewportContextValue>(() => {\n return {\n useThreadViewport,\n };\n });\n\n return (\n <ThreadViewportContext.Provider value={context}>\n {children}\n </ThreadViewportContext.Provider>\n );\n};\n"],"mappings":";;;AAGA,SAAS,WAAW,gBAAgB;AACpC,SAAS,+BAA+B;AACxC;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,qBAAqB;AAkC1B;AAhCJ,IAAM,8BAA8B,MAAM;AACxC,QAAM,gBAAgB,uBAAuB,EAAE,UAAU,KAAK,CAAC;AAC/D,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,wBAAwB,CAAC;AAExD,YAAU,MAAM;AACd,WAAO,eAAe,SAAS,EAAE,iBAAiB,MAAM;AACtD,YAAM,SAAS,EAAE,eAAe;AAAA,IAClC,CAAC;AAAA,EACH,GAAG,CAAC,eAAe,KAAK,CAAC;AAEzB,YAAU,MAAM;AACd,QAAI,CAAC,cAAe;AACpB,WAAO,MAAM,UAAU,CAAC,UAAU;AAChC,UAAI,cAAc,SAAS,EAAE,eAAe,MAAM,YAAY;AAC5D,sBAAc,aAAa,EAAE,SAAS,EAAE,YAAY,MAAM,WAAW,CAAC;AAAA,MACxE;AAAA,IACF,CAAC;AAAA,EACH,GAAG,CAAC,OAAO,aAAa,CAAC;AAEzB,SAAO;AACT;AAEO,IAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AAC7E,QAAM,oBAAoB,4BAA4B;AAEtD,QAAM,CAAC,OAAO,IAAI,SAAqC,MAAM;AAC3D,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF,CAAC;AAED,SACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAAO,SACpC,UACH;AAEJ;","names":[]}