@assistant-ui/react-markdown 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
- import { ComponentType, FC } from 'react';
2
+ import { ElementType, ComponentType, ForwardRefExoticComponent, RefAttributes, ElementRef, ComponentPropsWithoutRef, FC } from 'react';
3
3
  import { Options } from 'react-markdown';
4
- import { TextContentPartProps } from '@assistant-ui/react';
4
+ import { Primitive } from '@radix-ui/react-primitive';
5
5
 
6
6
  type PreComponent = NonNullable<NonNullable<Options["components"]>["pre"]>;
7
7
  type CodeComponent = NonNullable<NonNullable<Options["components"]>["code"]>;
@@ -18,7 +18,11 @@ type SyntaxHighlighterProps = {
18
18
  code: string;
19
19
  };
20
20
 
21
+ type MarkdownTextPrimitiveElement = ElementRef<typeof Primitive.div>;
22
+ type PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;
21
23
  type MarkdownTextPrimitiveProps = Omit<Options, "components" | "children"> & {
24
+ containerProps?: Omit<PrimitiveDivProps, "children" | "asChild">;
25
+ containerComponent?: ElementType;
22
26
  components?: NonNullable<Options["components"]> & {
23
27
  SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps>;
24
28
  CodeHeader?: ComponentType<CodeHeaderProps>;
@@ -29,11 +33,13 @@ type MarkdownTextPrimitiveProps = Omit<Options, "components" | "children"> & {
29
33
  };
30
34
  smooth?: boolean;
31
35
  };
32
- declare const MarkdownTextPrimitive: FC<MarkdownTextPrimitiveProps>;
36
+ declare const MarkdownTextPrimitive: ForwardRefExoticComponent<MarkdownTextPrimitiveProps> & RefAttributes<MarkdownTextPrimitiveElement>;
37
+
38
+ declare const useIsMarkdownCodeBlock: () => boolean;
33
39
 
34
40
  type MakeMarkdownTextProps = MarkdownTextPrimitiveProps;
35
- declare const makeMarkdownText: ({ className, components: userComponents, ...rest }?: MakeMarkdownTextProps) => react.NamedExoticComponent<TextContentPartProps>;
41
+ declare const makeMarkdownText: ({ className, components: userComponents, ...rest }?: MakeMarkdownTextProps) => react.NamedExoticComponent<{}>;
36
42
 
37
43
  declare const CodeHeader: FC<CodeHeaderProps>;
38
44
 
39
- export { CodeHeader, type CodeHeaderProps, type MakeMarkdownTextProps, MarkdownTextPrimitive, type MarkdownTextPrimitiveProps, type SyntaxHighlighterProps, makeMarkdownText };
45
+ export { CodeHeader, type CodeHeaderProps, type MakeMarkdownTextProps, MarkdownTextPrimitive, type MarkdownTextPrimitiveProps, type SyntaxHighlighterProps, makeMarkdownText, useIsMarkdownCodeBlock };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
- import { ComponentType, FC } from 'react';
2
+ import { ElementType, ComponentType, ForwardRefExoticComponent, RefAttributes, ElementRef, ComponentPropsWithoutRef, FC } from 'react';
3
3
  import { Options } from 'react-markdown';
4
- import { TextContentPartProps } from '@assistant-ui/react';
4
+ import { Primitive } from '@radix-ui/react-primitive';
5
5
 
6
6
  type PreComponent = NonNullable<NonNullable<Options["components"]>["pre"]>;
7
7
  type CodeComponent = NonNullable<NonNullable<Options["components"]>["code"]>;
@@ -18,7 +18,11 @@ type SyntaxHighlighterProps = {
18
18
  code: string;
19
19
  };
20
20
 
21
+ type MarkdownTextPrimitiveElement = ElementRef<typeof Primitive.div>;
22
+ type PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;
21
23
  type MarkdownTextPrimitiveProps = Omit<Options, "components" | "children"> & {
24
+ containerProps?: Omit<PrimitiveDivProps, "children" | "asChild">;
25
+ containerComponent?: ElementType;
22
26
  components?: NonNullable<Options["components"]> & {
23
27
  SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps>;
24
28
  CodeHeader?: ComponentType<CodeHeaderProps>;
@@ -29,11 +33,13 @@ type MarkdownTextPrimitiveProps = Omit<Options, "components" | "children"> & {
29
33
  };
30
34
  smooth?: boolean;
31
35
  };
32
- declare const MarkdownTextPrimitive: FC<MarkdownTextPrimitiveProps>;
36
+ declare const MarkdownTextPrimitive: ForwardRefExoticComponent<MarkdownTextPrimitiveProps> & RefAttributes<MarkdownTextPrimitiveElement>;
37
+
38
+ declare const useIsMarkdownCodeBlock: () => boolean;
33
39
 
34
40
  type MakeMarkdownTextProps = MarkdownTextPrimitiveProps;
35
- declare const makeMarkdownText: ({ className, components: userComponents, ...rest }?: MakeMarkdownTextProps) => react.NamedExoticComponent<TextContentPartProps>;
41
+ declare const makeMarkdownText: ({ className, components: userComponents, ...rest }?: MakeMarkdownTextProps) => react.NamedExoticComponent<{}>;
36
42
 
37
43
  declare const CodeHeader: FC<CodeHeaderProps>;
38
44
 
39
- export { CodeHeader, type CodeHeaderProps, type MakeMarkdownTextProps, MarkdownTextPrimitive, type MarkdownTextPrimitiveProps, type SyntaxHighlighterProps, makeMarkdownText };
45
+ export { CodeHeader, type CodeHeaderProps, type MakeMarkdownTextProps, MarkdownTextPrimitive, type MarkdownTextPrimitiveProps, type SyntaxHighlighterProps, makeMarkdownText, useIsMarkdownCodeBlock };
package/dist/index.js CHANGED
@@ -33,18 +33,23 @@ var src_exports = {};
33
33
  __export(src_exports, {
34
34
  CodeHeader: () => CodeHeader,
35
35
  MarkdownTextPrimitive: () => MarkdownTextPrimitive,
36
- makeMarkdownText: () => makeMarkdownText
36
+ makeMarkdownText: () => makeMarkdownText,
37
+ useIsMarkdownCodeBlock: () => useIsMarkdownCodeBlock
37
38
  });
38
39
  module.exports = __toCommonJS(src_exports);
39
40
 
40
41
  // src/primitives/MarkdownText.tsx
41
42
  var import_react4 = require("@assistant-ui/react");
43
+ var import_react5 = require("react");
42
44
  var import_react_markdown = __toESM(require("react-markdown"));
43
45
 
44
46
  // src/overrides/PreOverride.tsx
45
47
  var import_react = require("react");
46
48
  var import_jsx_runtime = require("react/jsx-runtime");
47
49
  var PreContext = (0, import_react.createContext)(null);
50
+ var useIsMarkdownCodeBlock = () => {
51
+ return (0, import_react.useContext)(PreContext) !== null;
52
+ };
48
53
  var PreOverride = ({ children, ...rest }) => {
49
54
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PreContext.Provider, { value: rest, children });
50
55
  };
@@ -155,58 +160,74 @@ var CodeOverride = ({
155
160
  };
156
161
 
157
162
  // src/primitives/MarkdownText.tsx
163
+ var import_internal = require("@assistant-ui/react/internal");
164
+ var import_classnames2 = __toESM(require("classnames"));
158
165
  var import_jsx_runtime5 = require("react/jsx-runtime");
159
- var { useSmooth } = import_react4.INTERNAL;
160
- var MarkdownTextPrimitive = ({
161
- smooth = true,
162
- components: userComponents,
163
- ...rest
164
- }) => {
165
- const {
166
- part: { text }
167
- } = (0, import_react4.useContentPartText)();
168
- const smoothText = useSmooth(text, smooth);
169
- const {
170
- pre = DefaultPre,
171
- code = DefaultCode,
172
- SyntaxHighlighter = DefaultCodeBlockContent,
173
- CodeHeader: CodeHeader2 = DefaultCodeHeader,
174
- by_language,
175
- ...componentsRest
176
- } = userComponents ?? {};
177
- const components = {
178
- ...componentsRest,
179
- pre: PreOverride,
180
- code: (0, import_react_use_callback_ref2.useCallbackRef)((props) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
181
- CodeOverride,
166
+ var MarkdownTextPrimitive = (0, import_react5.forwardRef)(
167
+ ({
168
+ components: userComponents,
169
+ className,
170
+ containerProps,
171
+ containerComponent: Container = "div",
172
+ ...rest
173
+ }, forwardedRef, smooth = true) => {
174
+ const {
175
+ part: { text },
176
+ status
177
+ } = (0, import_internal.useSmooth)((0, import_react4.useContentPartText)(), smooth);
178
+ const {
179
+ pre = DefaultPre,
180
+ code = DefaultCode,
181
+ SyntaxHighlighter = DefaultCodeBlockContent,
182
+ CodeHeader: CodeHeader2 = DefaultCodeHeader,
183
+ by_language,
184
+ ...componentsRest
185
+ } = userComponents ?? {};
186
+ const components = {
187
+ ...componentsRest,
188
+ pre: PreOverride,
189
+ code: (0, import_react_use_callback_ref2.useCallbackRef)((props) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
190
+ CodeOverride,
191
+ {
192
+ components: {
193
+ Pre: pre,
194
+ Code: code,
195
+ SyntaxHighlighter,
196
+ CodeHeader: CodeHeader2,
197
+ by_language
198
+ },
199
+ ...props
200
+ }
201
+ ))
202
+ };
203
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
204
+ Container,
182
205
  {
183
- components: {
184
- Pre: pre,
185
- Code: code,
186
- SyntaxHighlighter,
187
- CodeHeader: CodeHeader2,
188
- by_language
189
- },
190
- ...props
206
+ "data-status": status.type,
207
+ ...containerProps,
208
+ className: (0, import_classnames2.default)(className, containerProps?.className),
209
+ ref: forwardedRef,
210
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_markdown.default, { components, ...rest, children: text })
191
211
  }
192
- ))
193
- };
194
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_markdown.default, { components, ...rest, children: smoothText });
195
- };
212
+ );
213
+ }
214
+ );
215
+ MarkdownTextPrimitive.displayName = "MarkdownTextPrimitive";
196
216
 
197
217
  // src/ui/markdown-text.tsx
198
- var import_react7 = require("react");
218
+ var import_react8 = require("react");
199
219
 
200
220
  // src/ui/code-header.tsx
201
221
  var import_lucide_react = require("lucide-react");
202
- var import_react6 = require("@assistant-ui/react");
222
+ var import_react7 = require("@assistant-ui/react");
223
+ var import_internal2 = require("@assistant-ui/react/internal");
203
224
 
204
225
  // src/ui/useCopyToClipboard.tsx
205
- var import_react5 = require("react");
226
+ var import_react6 = require("react");
206
227
  var useCopyToClipboard = ({
207
228
  copiedDuration = 3e3
208
229
  } = {}) => {
209
- const [isCopied, setIsCopied] = (0, import_react5.useState)(false);
230
+ const [isCopied, setIsCopied] = (0, import_react6.useState)(false);
210
231
  const copyToClipboard = (value) => {
211
232
  if (!value) return;
212
233
  navigator.clipboard.writeText(value).then(() => {
@@ -219,13 +240,12 @@ var useCopyToClipboard = ({
219
240
 
220
241
  // src/ui/code-header.tsx
221
242
  var import_jsx_runtime6 = require("react/jsx-runtime");
222
- var { TooltipIconButton } = import_react6.INTERNAL;
223
243
  var CodeHeader = ({ language, code }) => {
224
244
  const {
225
245
  strings: {
226
246
  code: { header: { copy: { tooltip = "Copy" } = {} } = {} } = {}
227
247
  } = {}
228
- } = (0, import_react6.useThreadConfig)();
248
+ } = (0, import_react7.useThreadConfig)();
229
249
  const { isCopied, copyToClipboard } = useCopyToClipboard();
230
250
  const onCopy = () => {
231
251
  if (!code || isCopied) return;
@@ -233,7 +253,7 @@ var CodeHeader = ({ language, code }) => {
233
253
  };
234
254
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "aui-code-header-root", children: [
235
255
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "aui-code-header-language", children: language }),
236
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(TooltipIconButton, { tooltip, onClick: onCopy, children: [
256
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_internal2.TooltipIconButton, { tooltip, onClick: onCopy, children: [
237
257
  !isCopied && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react.CopyIcon, {}),
238
258
  isCopied && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react.CheckIcon, {})
239
259
  ] })
@@ -241,7 +261,8 @@ var CodeHeader = ({ language, code }) => {
241
261
  };
242
262
 
243
263
  // src/ui/markdown-text.tsx
244
- var import_classnames2 = __toESM(require("classnames"));
264
+ var import_classnames3 = __toESM(require("classnames"));
265
+ var import_internal3 = require("@assistant-ui/react/internal");
245
266
  var import_jsx_runtime7 = require("react/jsx-runtime");
246
267
  var makeMarkdownText = ({
247
268
  className,
@@ -252,29 +273,29 @@ var makeMarkdownText = ({
252
273
  ...userComponents,
253
274
  CodeHeader: userComponents?.CodeHeader ?? CodeHeader
254
275
  };
255
- const MarkdownTextImpl = ({ status }) => {
276
+ const MarkdownTextImpl = () => {
277
+ const status = (0, import_internal3.useSmoothStatus)();
256
278
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
257
- "div",
279
+ MarkdownTextPrimitive,
258
280
  {
259
- className: (0, import_classnames2.default)(
281
+ components,
282
+ ...rest,
283
+ className: (0, import_classnames3.default)(
260
284
  "aui-md-root",
261
- status.type === "running" && "aui-md-in-progress",
285
+ status.type === "running" && "aui-md-running",
262
286
  className
263
- ),
264
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MarkdownTextPrimitive, { components, ...rest })
287
+ )
265
288
  }
266
289
  );
267
290
  };
268
291
  MarkdownTextImpl.displayName = "MarkdownText";
269
- return (0, import_react7.memo)(
270
- MarkdownTextImpl,
271
- (prev, next) => prev.status.type === next.status.type
272
- );
292
+ return (0, import_react8.memo)((0, import_internal3.withSmoothContextProvider)(MarkdownTextImpl), () => true);
273
293
  };
274
294
  // Annotate the CommonJS export names for ESM import in node:
275
295
  0 && (module.exports = {
276
296
  CodeHeader,
277
297
  MarkdownTextPrimitive,
278
- makeMarkdownText
298
+ makeMarkdownText,
299
+ useIsMarkdownCodeBlock
279
300
  });
280
301
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/primitives/MarkdownText.tsx","../src/overrides/PreOverride.tsx","../src/overrides/defaultComponents.tsx","../src/overrides/CodeOverride.tsx","../src/overrides/CodeBlock.tsx","../src/overrides/withDefaults.tsx","../src/ui/markdown-text.tsx","../src/ui/code-header.tsx","../src/ui/useCopyToClipboard.tsx"],"sourcesContent":["export {\n MarkdownTextPrimitive,\n type MarkdownTextPrimitiveProps,\n} from \"./primitives/MarkdownText\";\n\nexport type {\n CodeHeaderProps,\n SyntaxHighlighterProps,\n} from \"./overrides/types\";\n\nexport {\n makeMarkdownText,\n type MakeMarkdownTextProps,\n} from \"./ui/markdown-text\";\n\nexport { CodeHeader } from \"./ui/code-header\";\n","\"use client\";\n\nimport { INTERNAL, useContentPartText } from \"@assistant-ui/react\";\nimport type { ComponentType, FC } from \"react\";\nimport ReactMarkdown, { type Options } from \"react-markdown\";\nimport { SyntaxHighlighterProps, CodeHeaderProps } from \"../overrides/types\";\nimport { PreOverride } from \"../overrides/PreOverride\";\nimport {\n DefaultPre,\n DefaultCode,\n DefaultCodeBlockContent,\n DefaultCodeHeader,\n} from \"../overrides/defaultComponents\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { CodeOverride } from \"../overrides/CodeOverride\";\n\nconst { useSmooth } = INTERNAL;\n\nexport type MarkdownTextPrimitiveProps = Omit<\n Options,\n \"components\" | \"children\"\n> & {\n components?: NonNullable<Options[\"components\"]> & {\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps>;\n CodeHeader?: ComponentType<CodeHeaderProps>;\n by_language?: Record<\n string,\n {\n CodeHeader?: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps>;\n }\n >;\n };\n smooth?: boolean;\n};\nexport const MarkdownTextPrimitive: FC<MarkdownTextPrimitiveProps> = ({\n smooth = true,\n components: userComponents,\n ...rest\n}) => {\n const {\n part: { text },\n } = useContentPartText();\n const smoothText = useSmooth(text, smooth); // TODO loading indicator disappears before smooth animation ends\n\n const {\n pre = DefaultPre,\n code = DefaultCode,\n SyntaxHighlighter = DefaultCodeBlockContent,\n CodeHeader = DefaultCodeHeader,\n by_language,\n ...componentsRest\n } = userComponents ?? {};\n const components: typeof userComponents = {\n ...componentsRest,\n pre: PreOverride,\n code: useCallbackRef((props) => (\n <CodeOverride\n components={{\n Pre: pre,\n Code: code,\n SyntaxHighlighter,\n CodeHeader,\n by_language,\n }}\n {...props}\n />\n )),\n };\n\n return (\n <ReactMarkdown components={components} {...rest}>\n {smoothText}\n </ReactMarkdown>\n );\n};\n","import { createContext, ComponentPropsWithoutRef } from \"react\";\nimport { PreComponent } from \"./types\";\n\nexport const PreContext = createContext<Omit<\n ComponentPropsWithoutRef<PreComponent>,\n \"children\"\n> | null>(null);\n\nexport const PreOverride: PreComponent = ({ children, ...rest }) => {\n return <PreContext.Provider value={rest}>{children}</PreContext.Provider>;\n};\n","import type { ComponentType, ReactNode } from \"react\";\nimport { PreComponent, CodeComponent, CodeHeaderProps } from \"./types\";\n\nexport const DefaultPre: PreComponent = ({ node, ...rest }) => (\n <pre {...rest} />\n);\n\nexport const DefaultCode: CodeComponent = ({ node, ...rest }) => (\n <code {...rest} />\n);\n\nexport const DefaultCodeBlockContent: ComponentType<{\n components: { Pre: PreComponent; Code: CodeComponent };\n code: string | ReactNode | undefined;\n}> = ({ components: { Pre, Code }, code }) => (\n <Pre>\n <Code>{code}</Code>\n </Pre>\n);\n\nexport const DefaultCodeHeader: ComponentType<CodeHeaderProps> = () => null;\n","import { ComponentPropsWithoutRef, ComponentType, FC, useContext } from \"react\";\nimport { PreContext } from \"./PreOverride\";\nimport {\n CodeComponent,\n CodeHeaderProps,\n PreComponent,\n SyntaxHighlighterProps,\n} from \"./types\";\nimport { DefaultCodeBlock } from \"./CodeBlock\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { withDefaultProps } from \"./withDefaults\";\nimport { DefaultCodeBlockContent } from \"./defaultComponents\";\n\nconst CodeBlockOverride: FC<CodeOverrideProps> = ({\n components: {\n Pre,\n Code,\n SyntaxHighlighter: FallbackSyntaxHighlighter,\n CodeHeader: FallbackCodeHeader,\n by_language = {},\n },\n children,\n ...codeProps\n}) => {\n const preProps = useContext(PreContext)!;\n const getPreProps = withDefaultProps<any>(preProps);\n const WrappedPre: PreComponent = useCallbackRef((props) => (\n <Pre {...getPreProps(props)} />\n ));\n\n const getCodeProps = withDefaultProps<any>(codeProps);\n const WrappedCode: CodeComponent = useCallbackRef((props) => (\n <Code {...getCodeProps(props)} />\n ));\n\n const language = /language-(\\w+)/.exec(codeProps.className || \"\")?.[1] ?? \"\";\n\n // if the code content is not string (due to rehype plugins), return a default code block\n if (typeof children !== \"string\") {\n return (\n <DefaultCodeBlockContent\n components={{ Pre: WrappedPre, Code: WrappedCode }}\n code={children}\n />\n );\n }\n\n const SyntaxHighlighter: ComponentType<SyntaxHighlighterProps> =\n by_language[language]?.SyntaxHighlighter ?? FallbackSyntaxHighlighter;\n\n const CodeHeader: ComponentType<CodeHeaderProps> =\n by_language[language]?.CodeHeader ?? FallbackCodeHeader;\n\n return (\n <DefaultCodeBlock\n components={{\n Pre: WrappedPre,\n Code: WrappedCode,\n SyntaxHighlighter,\n CodeHeader,\n }}\n language={language || \"unknown\"}\n code={children}\n />\n );\n};\n\nexport type CodeOverrideProps = ComponentPropsWithoutRef<CodeComponent> & {\n components: {\n Pre: PreComponent;\n Code: CodeComponent;\n CodeHeader: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter: ComponentType<SyntaxHighlighterProps>;\n by_language?: Record<\n string,\n {\n CodeHeader?: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps>;\n }\n >;\n };\n};\n\nexport const CodeOverride: FC<CodeOverrideProps> = ({\n components,\n ...props\n}) => {\n const preProps = useContext(PreContext);\n if (!preProps) return <components.Code {...(props as any)} />;\n return <CodeBlockOverride components={components} {...props} />;\n};\n","import { ComponentType, FC, useMemo } from \"react\";\n\nimport {\n CodeComponent,\n CodeHeaderProps,\n PreComponent,\n SyntaxHighlighterProps,\n} from \"./types\";\nimport { DefaultCodeBlockContent } from \"./defaultComponents\";\n\nexport type CodeBlockProps = {\n language: string;\n code: string;\n components: {\n Pre: PreComponent;\n Code: CodeComponent;\n CodeHeader: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter: ComponentType<SyntaxHighlighterProps>;\n };\n};\n\nexport const DefaultCodeBlock: FC<CodeBlockProps> = ({\n components: { Pre, Code, SyntaxHighlighter, CodeHeader },\n language,\n code,\n}) => {\n const components = useMemo(() => ({ Pre, Code }), [Pre, Code]);\n\n const SH = !!language ? SyntaxHighlighter : DefaultCodeBlockContent;\n\n return (\n <>\n <CodeHeader language={language} code={code} />\n <SH\n components={components}\n language={language ?? \"unknown\"}\n code={code}\n />\n </>\n );\n};\n","import classNames from \"classnames\";\n\nexport const withDefaultProps =\n <TProps extends { className?: string | undefined }>({\n className,\n ...defaultProps\n }: Partial<TProps>) =>\n ({ className: classNameProp, ...props }: TProps) => {\n return {\n className: classNames(className, classNameProp),\n ...defaultProps,\n ...props,\n } as TProps;\n };\n","import { TextContentPartProps } from \"@assistant-ui/react\";\nimport { FC, memo } from \"react\";\nimport { CodeHeader } from \"./code-header\";\nimport classNames from \"classnames\";\nimport {\n MarkdownTextPrimitive,\n MarkdownTextPrimitiveProps,\n} from \"../primitives/MarkdownText\";\n\nexport type MakeMarkdownTextProps = MarkdownTextPrimitiveProps;\n\nexport const makeMarkdownText = ({\n className,\n components: userComponents,\n ...rest\n}: MakeMarkdownTextProps = {}) => {\n const components = {\n ...userComponents,\n CodeHeader: userComponents?.CodeHeader ?? CodeHeader,\n };\n\n const MarkdownTextImpl: FC<TextContentPartProps> = ({ status }) => {\n return (\n <div\n className={classNames(\n \"aui-md-root\",\n status.type === \"running\" && \"aui-md-in-progress\",\n className,\n )}\n >\n <MarkdownTextPrimitive components={components} {...rest} />\n </div>\n );\n };\n MarkdownTextImpl.displayName = \"MarkdownText\";\n\n return memo(\n MarkdownTextImpl,\n (prev, next) => prev.status.type === next.status.type,\n );\n};\n","import { FC } from \"react\";\nimport { CheckIcon, CopyIcon } from \"lucide-react\";\nimport { useThreadConfig, INTERNAL } from \"@assistant-ui/react\";\n\nimport { CodeHeaderProps } from \"../overrides/types\";\nimport { useCopyToClipboard } from \"./useCopyToClipboard\";\n\nconst { TooltipIconButton } = INTERNAL;\n\nexport const CodeHeader: FC<CodeHeaderProps> = ({ language, code }) => {\n const {\n strings: {\n code: { header: { copy: { tooltip = \"Copy\" } = {} } = {} } = {},\n } = {},\n } = useThreadConfig();\n\n const { isCopied, copyToClipboard } = useCopyToClipboard();\n const onCopy = () => {\n if (!code || isCopied) return;\n copyToClipboard(code);\n };\n\n return (\n <div className=\"aui-code-header-root\">\n <span className=\"aui-code-header-language\">{language}</span>\n <TooltipIconButton tooltip={tooltip} onClick={onCopy}>\n {!isCopied && <CopyIcon />}\n {isCopied && <CheckIcon />}\n </TooltipIconButton>\n </div>\n );\n};\n","import { useState } from \"react\";\nimport { UseActionBarCopyProps } from \"@assistant-ui/react\";\n\nexport type useCopyToClipboardProps = UseActionBarCopyProps;\n\nexport const useCopyToClipboard = ({\n copiedDuration = 3000,\n}: useCopyToClipboardProps = {}) => {\n const [isCopied, setIsCopied] = useState<boolean>(false);\n\n const copyToClipboard = (value: string) => {\n if (!value) return;\n\n navigator.clipboard.writeText(value).then(() => {\n setIsCopied(true);\n setTimeout(() => setIsCopied(false), copiedDuration);\n });\n };\n\n return { isCopied, copyToClipboard };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAAA,gBAA6C;AAE7C,4BAA4C;;;ACJ5C,mBAAwD;AAS/C;AANF,IAAM,iBAAa,4BAGhB,IAAI;AAEP,IAAM,cAA4B,CAAC,EAAE,UAAU,GAAG,KAAK,MAAM;AAClE,SAAO,4CAAC,WAAW,UAAX,EAAoB,OAAO,MAAO,UAAS;AACrD;;;ACNE,IAAAC,sBAAA;AADK,IAAM,aAA2B,CAAC,EAAE,MAAM,GAAG,KAAK,MACvD,6CAAC,SAAK,GAAG,MAAM;AAGV,IAAM,cAA6B,CAAC,EAAE,MAAM,GAAG,KAAK,MACzD,6CAAC,UAAM,GAAG,MAAM;AAGX,IAAM,0BAGR,CAAC,EAAE,YAAY,EAAE,KAAK,KAAK,GAAG,KAAK,MACtC,6CAAC,OACC,uDAAC,QAAM,gBAAK,GACd;AAGK,IAAM,oBAAoD,MAAM;;;AFPvE,IAAAC,iCAA+B;;;AGb/B,IAAAC,gBAAwE;;;ACAxE,IAAAC,gBAA2C;AA+BvC,IAAAC,sBAAA;AAVG,IAAM,mBAAuC,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2Bf,IAAAC,sBAAA;AAnBD,IAAM,mBAAmB,CAAC;AAAA,EAC/B;AAAA,EACA,YAAY;AAAA,EACZ,GAAG;AACL,IAA2B,CAAC,MAAM;AAChC,QAAM,aAAa;AAAA,IACjB,GAAG;AAAA,IACH,YAAY,gBAAgB,cAAc;AAAA,EAC5C;AAEA,QAAM,mBAA6C,CAAC,EAAE,OAAO,MAAM;AACjE,WACE;AAAA,MAAC;AAAA;AAAA,QACC,eAAW,mBAAAC;AAAA,UACT;AAAA,UACA,OAAO,SAAS,aAAa;AAAA,UAC7B;AAAA,QACF;AAAA,QAEA,uDAAC,yBAAsB,YAAyB,GAAG,MAAM;AAAA;AAAA,IAC3D;AAAA,EAEJ;AACA,mBAAiB,cAAc;AAE/B,aAAO;AAAA,IACL;AAAA,IACA,CAAC,MAAM,SAAS,KAAK,OAAO,SAAS,KAAK,OAAO;AAAA,EACnD;AACF;","names":["import_react","import_jsx_runtime","import_react_use_callback_ref","import_react","import_react","import_jsx_runtime","CodeHeader","classNames","import_jsx_runtime","CodeHeader","import_jsx_runtime","CodeHeader","ReactMarkdown","import_react","import_react","import_react","import_jsx_runtime","import_classnames","import_jsx_runtime","classNames"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/primitives/MarkdownText.tsx","../src/overrides/PreOverride.tsx","../src/overrides/defaultComponents.tsx","../src/overrides/CodeOverride.tsx","../src/overrides/CodeBlock.tsx","../src/overrides/withDefaults.tsx","../src/ui/markdown-text.tsx","../src/ui/code-header.tsx","../src/ui/useCopyToClipboard.tsx"],"sourcesContent":["export {\n MarkdownTextPrimitive,\n type MarkdownTextPrimitiveProps,\n} from \"./primitives/MarkdownText\";\n\nexport type {\n CodeHeaderProps,\n SyntaxHighlighterProps,\n} from \"./overrides/types\";\n\nexport { useIsMarkdownCodeBlock } from \"./overrides/PreOverride\";\n\nexport {\n makeMarkdownText,\n type MakeMarkdownTextProps,\n} from \"./ui/markdown-text\";\n\nexport { CodeHeader } from \"./ui/code-header\";\n","\"use client\";\n\nimport { useContentPartText } from \"@assistant-ui/react\";\nimport {\n ElementRef,\n ElementType,\n forwardRef,\n ForwardRefExoticComponent,\n RefAttributes,\n type ComponentPropsWithoutRef,\n type ComponentType,\n} from \"react\";\nimport ReactMarkdown, { type Options } from \"react-markdown\";\nimport { SyntaxHighlighterProps, CodeHeaderProps } from \"../overrides/types\";\nimport { PreOverride } from \"../overrides/PreOverride\";\nimport {\n DefaultPre,\n DefaultCode,\n DefaultCodeBlockContent,\n DefaultCodeHeader,\n} from \"../overrides/defaultComponents\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { CodeOverride } from \"../overrides/CodeOverride\";\nimport { useSmooth } from \"@assistant-ui/react/internal\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport classNames from \"classnames\";\n\ntype MarkdownTextPrimitiveElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nexport type MarkdownTextPrimitiveProps = Omit<\n Options,\n \"components\" | \"children\"\n> & {\n containerProps?: Omit<PrimitiveDivProps, \"children\" | \"asChild\">;\n containerComponent?: ElementType;\n components?: NonNullable<Options[\"components\"]> & {\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps>;\n CodeHeader?: ComponentType<CodeHeaderProps>;\n by_language?: Record<\n string,\n {\n CodeHeader?: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps>;\n }\n >;\n };\n smooth?: boolean;\n};\n\nexport const MarkdownTextPrimitive: ForwardRefExoticComponent<MarkdownTextPrimitiveProps> &\n RefAttributes<MarkdownTextPrimitiveElement> = forwardRef<\n MarkdownTextPrimitiveElement,\n MarkdownTextPrimitiveProps\n>(\n (\n {\n components: userComponents,\n className,\n containerProps,\n containerComponent: Container = \"div\",\n ...rest\n },\n forwardedRef,\n smooth = true,\n ) => {\n const {\n part: { text },\n status,\n } = useSmooth(useContentPartText(), smooth);\n\n const {\n pre = DefaultPre,\n code = DefaultCode,\n SyntaxHighlighter = DefaultCodeBlockContent,\n CodeHeader = DefaultCodeHeader,\n by_language,\n ...componentsRest\n } = userComponents ?? {};\n const components: typeof userComponents = {\n ...componentsRest,\n pre: PreOverride,\n code: useCallbackRef((props) => (\n <CodeOverride\n components={{\n Pre: pre,\n Code: code,\n SyntaxHighlighter,\n CodeHeader,\n by_language,\n }}\n {...props}\n />\n )),\n };\n\n return (\n <Container\n data-status={status.type}\n {...containerProps}\n className={classNames(className, containerProps?.className)}\n ref={forwardedRef}\n >\n <ReactMarkdown components={components} {...rest}>\n {text}\n </ReactMarkdown>\n </Container>\n );\n },\n);\n\nMarkdownTextPrimitive.displayName = \"MarkdownTextPrimitive\";\n","import { createContext, ComponentPropsWithoutRef, useContext } from \"react\";\nimport { PreComponent } from \"./types\";\n\nexport const PreContext = createContext<Omit<\n ComponentPropsWithoutRef<PreComponent>,\n \"children\"\n> | null>(null);\n\nexport const useIsMarkdownCodeBlock = () => {\n return useContext(PreContext) !== null;\n};\n\nexport const PreOverride: PreComponent = ({ children, ...rest }) => {\n return <PreContext.Provider value={rest}>{children}</PreContext.Provider>;\n};\n","import type { ComponentType, ReactNode } from \"react\";\nimport { PreComponent, CodeComponent, CodeHeaderProps } from \"./types\";\n\nexport const DefaultPre: PreComponent = ({ node, ...rest }) => (\n <pre {...rest} />\n);\n\nexport const DefaultCode: CodeComponent = ({ node, ...rest }) => (\n <code {...rest} />\n);\n\nexport const DefaultCodeBlockContent: ComponentType<{\n components: { Pre: PreComponent; Code: CodeComponent };\n code: string | ReactNode | undefined;\n}> = ({ components: { Pre, Code }, code }) => (\n <Pre>\n <Code>{code}</Code>\n </Pre>\n);\n\nexport const DefaultCodeHeader: ComponentType<CodeHeaderProps> = () => null;\n","import { ComponentPropsWithoutRef, ComponentType, FC, useContext } from \"react\";\nimport { PreContext } from \"./PreOverride\";\nimport {\n CodeComponent,\n CodeHeaderProps,\n PreComponent,\n SyntaxHighlighterProps,\n} from \"./types\";\nimport { DefaultCodeBlock } from \"./CodeBlock\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { withDefaultProps } from \"./withDefaults\";\nimport { DefaultCodeBlockContent } from \"./defaultComponents\";\n\nconst CodeBlockOverride: FC<CodeOverrideProps> = ({\n components: {\n Pre,\n Code,\n SyntaxHighlighter: FallbackSyntaxHighlighter,\n CodeHeader: FallbackCodeHeader,\n by_language = {},\n },\n children,\n ...codeProps\n}) => {\n const preProps = useContext(PreContext)!;\n const getPreProps = withDefaultProps<any>(preProps);\n const WrappedPre: PreComponent = useCallbackRef((props) => (\n <Pre {...getPreProps(props)} />\n ));\n\n const getCodeProps = withDefaultProps<any>(codeProps);\n const WrappedCode: CodeComponent = useCallbackRef((props) => (\n <Code {...getCodeProps(props)} />\n ));\n\n const language = /language-(\\w+)/.exec(codeProps.className || \"\")?.[1] ?? \"\";\n\n // if the code content is not string (due to rehype plugins), return a default code block\n if (typeof children !== \"string\") {\n return (\n <DefaultCodeBlockContent\n components={{ Pre: WrappedPre, Code: WrappedCode }}\n code={children}\n />\n );\n }\n\n const SyntaxHighlighter: ComponentType<SyntaxHighlighterProps> =\n by_language[language]?.SyntaxHighlighter ?? FallbackSyntaxHighlighter;\n\n const CodeHeader: ComponentType<CodeHeaderProps> =\n by_language[language]?.CodeHeader ?? FallbackCodeHeader;\n\n return (\n <DefaultCodeBlock\n components={{\n Pre: WrappedPre,\n Code: WrappedCode,\n SyntaxHighlighter,\n CodeHeader,\n }}\n language={language || \"unknown\"}\n code={children}\n />\n );\n};\n\nexport type CodeOverrideProps = ComponentPropsWithoutRef<CodeComponent> & {\n components: {\n Pre: PreComponent;\n Code: CodeComponent;\n CodeHeader: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter: ComponentType<SyntaxHighlighterProps>;\n by_language?: Record<\n string,\n {\n CodeHeader?: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps>;\n }\n >;\n };\n};\n\nexport const CodeOverride: FC<CodeOverrideProps> = ({\n components,\n ...props\n}) => {\n const preProps = useContext(PreContext);\n if (!preProps) return <components.Code {...(props as any)} />;\n return <CodeBlockOverride components={components} {...props} />;\n};\n","import { ComponentType, FC, useMemo } from \"react\";\n\nimport {\n CodeComponent,\n CodeHeaderProps,\n PreComponent,\n SyntaxHighlighterProps,\n} from \"./types\";\nimport { DefaultCodeBlockContent } from \"./defaultComponents\";\n\nexport type CodeBlockProps = {\n language: string;\n code: string;\n components: {\n Pre: PreComponent;\n Code: CodeComponent;\n CodeHeader: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter: ComponentType<SyntaxHighlighterProps>;\n };\n};\n\nexport const DefaultCodeBlock: FC<CodeBlockProps> = ({\n components: { Pre, Code, SyntaxHighlighter, CodeHeader },\n language,\n code,\n}) => {\n const components = useMemo(() => ({ Pre, Code }), [Pre, Code]);\n\n const SH = !!language ? SyntaxHighlighter : DefaultCodeBlockContent;\n\n return (\n <>\n <CodeHeader language={language} code={code} />\n <SH\n components={components}\n language={language ?? \"unknown\"}\n code={code}\n />\n </>\n );\n};\n","import classNames from \"classnames\";\n\nexport const withDefaultProps =\n <TProps extends { className?: string | undefined }>({\n className,\n ...defaultProps\n }: Partial<TProps>) =>\n ({ className: classNameProp, ...props }: TProps) => {\n return {\n className: classNames(className, classNameProp),\n ...defaultProps,\n ...props,\n } as TProps;\n };\n","import { FC, memo } from \"react\";\nimport { CodeHeader } from \"./code-header\";\nimport classNames from \"classnames\";\nimport {\n MarkdownTextPrimitive,\n MarkdownTextPrimitiveProps,\n} from \"../primitives/MarkdownText\";\nimport {\n withSmoothContextProvider,\n useSmoothStatus,\n} from \"@assistant-ui/react/internal\";\n\nexport type MakeMarkdownTextProps = MarkdownTextPrimitiveProps;\n\nexport const makeMarkdownText = ({\n className,\n components: userComponents,\n ...rest\n}: MakeMarkdownTextProps = {}) => {\n const components = {\n ...userComponents,\n CodeHeader: userComponents?.CodeHeader ?? CodeHeader,\n };\n\n const MarkdownTextImpl: FC = () => {\n const status = useSmoothStatus();\n return (\n <MarkdownTextPrimitive\n components={components}\n {...rest}\n className={classNames(\n \"aui-md-root\",\n status.type === \"running\" && \"aui-md-running\",\n className,\n )}\n />\n );\n };\n MarkdownTextImpl.displayName = \"MarkdownText\";\n\n return memo(withSmoothContextProvider(MarkdownTextImpl), () => true);\n};\n","import { FC } from \"react\";\nimport { CheckIcon, CopyIcon } from \"lucide-react\";\nimport { useThreadConfig } from \"@assistant-ui/react\";\nimport { TooltipIconButton } from \"@assistant-ui/react/internal\";\n\nimport { CodeHeaderProps } from \"../overrides/types\";\nimport { useCopyToClipboard } from \"./useCopyToClipboard\";\n\nexport const CodeHeader: FC<CodeHeaderProps> = ({ language, code }) => {\n const {\n strings: {\n code: { header: { copy: { tooltip = \"Copy\" } = {} } = {} } = {},\n } = {},\n } = useThreadConfig();\n\n const { isCopied, copyToClipboard } = useCopyToClipboard();\n const onCopy = () => {\n if (!code || isCopied) return;\n copyToClipboard(code);\n };\n\n return (\n <div className=\"aui-code-header-root\">\n <span className=\"aui-code-header-language\">{language}</span>\n <TooltipIconButton tooltip={tooltip} onClick={onCopy}>\n {!isCopied && <CopyIcon />}\n {isCopied && <CheckIcon />}\n </TooltipIconButton>\n </div>\n );\n};\n","import { useState } from \"react\";\nimport { UseActionBarCopyProps } from \"@assistant-ui/react\";\n\nexport type useCopyToClipboardProps = UseActionBarCopyProps;\n\nexport const useCopyToClipboard = ({\n copiedDuration = 3000,\n}: useCopyToClipboardProps = {}) => {\n const [isCopied, setIsCopied] = useState<boolean>(false);\n\n const copyToClipboard = (value: string) => {\n if (!value) return;\n\n navigator.clipboard.writeText(value).then(() => {\n setIsCopied(true);\n setTimeout(() => setIsCopied(false), copiedDuration);\n });\n };\n\n return { isCopied, copyToClipboard };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAAA,g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AAgB;AAC/B,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACC,GAAG;AAAA,QACJ,eAAW,mBAAAC;AAAA,UACT;AAAA,UACA,OAAO,SAAS,aAAa;AAAA,UAC7B;AAAA,QACF;AAAA;AAAA,IACF;AAAA,EAEJ;AACA,mBAAiB,cAAc;AAE/B,aAAO,wBAAK,4CAA0B,gBAAgB,GAAG,MAAM,IAAI;AACrE;","names":["import_react","import_jsx_runtime","import_react_use_callback_ref","import_react","import_react","import_jsx_runtime","CodeHeader","classNames","import_jsx_runtime","CodeHeader","import_classnames","import_jsx_runtime","CodeHeader","classNames","ReactMarkdown","import_react","import_react","import_internal","import_react","import_jsx_runtime","import_classnames","import_internal","import_jsx_runtime","classNames"]}
package/dist/index.mjs CHANGED
@@ -1,13 +1,19 @@
1
1
  "use client";
2
2
 
3
3
  // src/primitives/MarkdownText.tsx
4
- import { INTERNAL, useContentPartText } from "@assistant-ui/react";
4
+ import { useContentPartText } from "@assistant-ui/react";
5
+ import {
6
+ forwardRef
7
+ } from "react";
5
8
  import ReactMarkdown from "react-markdown";
6
9
 
7
10
  // src/overrides/PreOverride.tsx
8
- import { createContext } from "react";
11
+ import { createContext, useContext } from "react";
9
12
  import { jsx } from "react/jsx-runtime";
10
13
  var PreContext = createContext(null);
14
+ var useIsMarkdownCodeBlock = () => {
15
+ return useContext(PreContext) !== null;
16
+ };
11
17
  var PreOverride = ({ children, ...rest }) => {
12
18
  return /* @__PURE__ */ jsx(PreContext.Provider, { value: rest, children });
13
19
  };
@@ -23,7 +29,7 @@ var DefaultCodeHeader = () => null;
23
29
  import { useCallbackRef as useCallbackRef2 } from "@radix-ui/react-use-callback-ref";
24
30
 
25
31
  // src/overrides/CodeOverride.tsx
26
- import { useContext } from "react";
32
+ import { useContext as useContext2 } from "react";
27
33
 
28
34
  // src/overrides/CodeBlock.tsx
29
35
  import { useMemo } from "react";
@@ -77,7 +83,7 @@ var CodeBlockOverride = ({
77
83
  children,
78
84
  ...codeProps
79
85
  }) => {
80
- const preProps = useContext(PreContext);
86
+ const preProps = useContext2(PreContext);
81
87
  const getPreProps = withDefaultProps(preProps);
82
88
  const WrappedPre = useCallbackRef((props) => /* @__PURE__ */ jsx4(Pre, { ...getPreProps(props) }));
83
89
  const getCodeProps = withDefaultProps(codeProps);
@@ -112,57 +118,73 @@ var CodeOverride = ({
112
118
  components,
113
119
  ...props
114
120
  }) => {
115
- const preProps = useContext(PreContext);
121
+ const preProps = useContext2(PreContext);
116
122
  if (!preProps) return /* @__PURE__ */ jsx4(components.Code, { ...props });
117
123
  return /* @__PURE__ */ jsx4(CodeBlockOverride, { components, ...props });
118
124
  };
119
125
 
120
126
  // src/primitives/MarkdownText.tsx
127
+ import { useSmooth } from "@assistant-ui/react/internal";
128
+ import classNames2 from "classnames";
121
129
  import { jsx as jsx5 } from "react/jsx-runtime";
122
- var { useSmooth } = INTERNAL;
123
- var MarkdownTextPrimitive = ({
124
- smooth = true,
125
- components: userComponents,
126
- ...rest
127
- }) => {
128
- const {
129
- part: { text }
130
- } = useContentPartText();
131
- const smoothText = useSmooth(text, smooth);
132
- const {
133
- pre = DefaultPre,
134
- code = DefaultCode,
135
- SyntaxHighlighter = DefaultCodeBlockContent,
136
- CodeHeader: CodeHeader2 = DefaultCodeHeader,
137
- by_language,
138
- ...componentsRest
139
- } = userComponents ?? {};
140
- const components = {
141
- ...componentsRest,
142
- pre: PreOverride,
143
- code: useCallbackRef2((props) => /* @__PURE__ */ jsx5(
144
- CodeOverride,
130
+ var MarkdownTextPrimitive = forwardRef(
131
+ ({
132
+ components: userComponents,
133
+ className,
134
+ containerProps,
135
+ containerComponent: Container = "div",
136
+ ...rest
137
+ }, forwardedRef, smooth = true) => {
138
+ const {
139
+ part: { text },
140
+ status
141
+ } = useSmooth(useContentPartText(), smooth);
142
+ const {
143
+ pre = DefaultPre,
144
+ code = DefaultCode,
145
+ SyntaxHighlighter = DefaultCodeBlockContent,
146
+ CodeHeader: CodeHeader2 = DefaultCodeHeader,
147
+ by_language,
148
+ ...componentsRest
149
+ } = userComponents ?? {};
150
+ const components = {
151
+ ...componentsRest,
152
+ pre: PreOverride,
153
+ code: useCallbackRef2((props) => /* @__PURE__ */ jsx5(
154
+ CodeOverride,
155
+ {
156
+ components: {
157
+ Pre: pre,
158
+ Code: code,
159
+ SyntaxHighlighter,
160
+ CodeHeader: CodeHeader2,
161
+ by_language
162
+ },
163
+ ...props
164
+ }
165
+ ))
166
+ };
167
+ return /* @__PURE__ */ jsx5(
168
+ Container,
145
169
  {
146
- components: {
147
- Pre: pre,
148
- Code: code,
149
- SyntaxHighlighter,
150
- CodeHeader: CodeHeader2,
151
- by_language
152
- },
153
- ...props
170
+ "data-status": status.type,
171
+ ...containerProps,
172
+ className: classNames2(className, containerProps?.className),
173
+ ref: forwardedRef,
174
+ children: /* @__PURE__ */ jsx5(ReactMarkdown, { components, ...rest, children: text })
154
175
  }
155
- ))
156
- };
157
- return /* @__PURE__ */ jsx5(ReactMarkdown, { components, ...rest, children: smoothText });
158
- };
176
+ );
177
+ }
178
+ );
179
+ MarkdownTextPrimitive.displayName = "MarkdownTextPrimitive";
159
180
 
160
181
  // src/ui/markdown-text.tsx
161
182
  import { memo } from "react";
162
183
 
163
184
  // src/ui/code-header.tsx
164
185
  import { CheckIcon, CopyIcon } from "lucide-react";
165
- import { useThreadConfig, INTERNAL as INTERNAL2 } from "@assistant-ui/react";
186
+ import { useThreadConfig } from "@assistant-ui/react";
187
+ import { TooltipIconButton } from "@assistant-ui/react/internal";
166
188
 
167
189
  // src/ui/useCopyToClipboard.tsx
168
190
  import { useState } from "react";
@@ -182,7 +204,6 @@ var useCopyToClipboard = ({
182
204
 
183
205
  // src/ui/code-header.tsx
184
206
  import { jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
185
- var { TooltipIconButton } = INTERNAL2;
186
207
  var CodeHeader = ({ language, code }) => {
187
208
  const {
188
209
  strings: {
@@ -204,7 +225,11 @@ var CodeHeader = ({ language, code }) => {
204
225
  };
205
226
 
206
227
  // src/ui/markdown-text.tsx
207
- import classNames2 from "classnames";
228
+ import classNames3 from "classnames";
229
+ import {
230
+ withSmoothContextProvider,
231
+ useSmoothStatus
232
+ } from "@assistant-ui/react/internal";
208
233
  import { jsx as jsx7 } from "react/jsx-runtime";
209
234
  var makeMarkdownText = ({
210
235
  className,
@@ -215,28 +240,28 @@ var makeMarkdownText = ({
215
240
  ...userComponents,
216
241
  CodeHeader: userComponents?.CodeHeader ?? CodeHeader
217
242
  };
218
- const MarkdownTextImpl = ({ status }) => {
243
+ const MarkdownTextImpl = () => {
244
+ const status = useSmoothStatus();
219
245
  return /* @__PURE__ */ jsx7(
220
- "div",
246
+ MarkdownTextPrimitive,
221
247
  {
222
- className: classNames2(
248
+ components,
249
+ ...rest,
250
+ className: classNames3(
223
251
  "aui-md-root",
224
- status.type === "running" && "aui-md-in-progress",
252
+ status.type === "running" && "aui-md-running",
225
253
  className
226
- ),
227
- children: /* @__PURE__ */ jsx7(MarkdownTextPrimitive, { components, ...rest })
254
+ )
228
255
  }
229
256
  );
230
257
  };
231
258
  MarkdownTextImpl.displayName = "MarkdownText";
232
- return memo(
233
- MarkdownTextImpl,
234
- (prev, next) => prev.status.type === next.status.type
235
- );
259
+ return memo(withSmoothContextProvider(MarkdownTextImpl), () => true);
236
260
  };
237
261
  export {
238
262
  CodeHeader,
239
263
  MarkdownTextPrimitive,
240
- makeMarkdownText
264
+ makeMarkdownText,
265
+ useIsMarkdownCodeBlock
241
266
  };
242
267
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/primitives/MarkdownText.tsx","../src/overrides/PreOverride.tsx","../src/overrides/defaultComponents.tsx","../src/overrides/CodeOverride.tsx","../src/overrides/CodeBlock.tsx","../src/overrides/withDefaults.tsx","../src/ui/markdown-text.tsx","../src/ui/code-header.tsx","../src/ui/useCopyToClipboard.tsx"],"sourcesContent":["\"use client\";\n\nimport { INTERNAL, useContentPartText } from \"@assistant-ui/react\";\nimport type { ComponentType, FC } from \"react\";\nimport ReactMarkdown, { type Options } from \"react-markdown\";\nimport { SyntaxHighlighterProps, CodeHeaderProps } from \"../overrides/types\";\nimport { PreOverride } from \"../overrides/PreOverride\";\nimport {\n DefaultPre,\n DefaultCode,\n DefaultCodeBlockContent,\n DefaultCodeHeader,\n} from \"../overrides/defaultComponents\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { CodeOverride } from \"../overrides/CodeOverride\";\n\nconst { useSmooth } = INTERNAL;\n\nexport type MarkdownTextPrimitiveProps = Omit<\n Options,\n \"components\" | \"children\"\n> & {\n components?: NonNullable<Options[\"components\"]> & {\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps>;\n CodeHeader?: ComponentType<CodeHeaderProps>;\n by_language?: Record<\n string,\n {\n CodeHeader?: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps>;\n }\n >;\n };\n smooth?: boolean;\n};\nexport const MarkdownTextPrimitive: FC<MarkdownTextPrimitiveProps> = ({\n smooth = true,\n components: userComponents,\n ...rest\n}) => {\n const {\n part: { text },\n } = useContentPartText();\n const smoothText = useSmooth(text, smooth); // TODO loading indicator disappears before smooth animation ends\n\n const {\n pre = DefaultPre,\n code = DefaultCode,\n SyntaxHighlighter = DefaultCodeBlockContent,\n CodeHeader = DefaultCodeHeader,\n by_language,\n ...componentsRest\n } = userComponents ?? {};\n const components: typeof userComponents = {\n ...componentsRest,\n pre: PreOverride,\n code: useCallbackRef((props) => (\n <CodeOverride\n components={{\n Pre: pre,\n Code: code,\n SyntaxHighlighter,\n CodeHeader,\n by_language,\n }}\n {...props}\n />\n )),\n };\n\n return (\n <ReactMarkdown components={components} {...rest}>\n {smoothText}\n </ReactMarkdown>\n );\n};\n","import { createContext, ComponentPropsWithoutRef } from \"react\";\nimport { PreComponent } from \"./types\";\n\nexport const PreContext = createContext<Omit<\n ComponentPropsWithoutRef<PreComponent>,\n \"children\"\n> | null>(null);\n\nexport const PreOverride: PreComponent = ({ children, ...rest }) => {\n return <PreContext.Provider value={rest}>{children}</PreContext.Provider>;\n};\n","import type { ComponentType, ReactNode } from \"react\";\nimport { PreComponent, CodeComponent, CodeHeaderProps } from \"./types\";\n\nexport const DefaultPre: PreComponent = ({ node, ...rest }) => (\n <pre {...rest} />\n);\n\nexport const DefaultCode: CodeComponent = ({ node, ...rest }) => (\n <code {...rest} />\n);\n\nexport const DefaultCodeBlockContent: ComponentType<{\n components: { Pre: PreComponent; Code: CodeComponent };\n code: string | ReactNode | undefined;\n}> = ({ components: { Pre, Code }, code }) => (\n <Pre>\n <Code>{code}</Code>\n </Pre>\n);\n\nexport const DefaultCodeHeader: ComponentType<CodeHeaderProps> = () => null;\n","import { ComponentPropsWithoutRef, ComponentType, FC, useContext } from \"react\";\nimport { PreContext } from \"./PreOverride\";\nimport {\n CodeComponent,\n CodeHeaderProps,\n PreComponent,\n SyntaxHighlighterProps,\n} from \"./types\";\nimport { DefaultCodeBlock } from \"./CodeBlock\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { withDefaultProps } from \"./withDefaults\";\nimport { DefaultCodeBlockContent } from \"./defaultComponents\";\n\nconst CodeBlockOverride: FC<CodeOverrideProps> = ({\n components: {\n Pre,\n Code,\n SyntaxHighlighter: FallbackSyntaxHighlighter,\n CodeHeader: FallbackCodeHeader,\n by_language = {},\n },\n children,\n ...codeProps\n}) => {\n const preProps = useContext(PreContext)!;\n const getPreProps = withDefaultProps<any>(preProps);\n const WrappedPre: PreComponent = useCallbackRef((props) => (\n <Pre {...getPreProps(props)} />\n ));\n\n const getCodeProps = withDefaultProps<any>(codeProps);\n const WrappedCode: CodeComponent = useCallbackRef((props) => (\n <Code {...getCodeProps(props)} />\n ));\n\n const language = /language-(\\w+)/.exec(codeProps.className || \"\")?.[1] ?? \"\";\n\n // if the code content is not string (due to rehype plugins), return a default code block\n if (typeof children !== \"string\") {\n return (\n <DefaultCodeBlockContent\n components={{ Pre: WrappedPre, Code: WrappedCode }}\n code={children}\n />\n );\n }\n\n const SyntaxHighlighter: ComponentType<SyntaxHighlighterProps> =\n by_language[language]?.SyntaxHighlighter ?? FallbackSyntaxHighlighter;\n\n const CodeHeader: ComponentType<CodeHeaderProps> =\n by_language[language]?.CodeHeader ?? FallbackCodeHeader;\n\n return (\n <DefaultCodeBlock\n components={{\n Pre: WrappedPre,\n Code: WrappedCode,\n SyntaxHighlighter,\n CodeHeader,\n }}\n language={language || \"unknown\"}\n code={children}\n />\n );\n};\n\nexport type CodeOverrideProps = ComponentPropsWithoutRef<CodeComponent> & {\n components: {\n Pre: PreComponent;\n Code: CodeComponent;\n CodeHeader: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter: ComponentType<SyntaxHighlighterProps>;\n by_language?: Record<\n string,\n {\n CodeHeader?: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps>;\n }\n >;\n };\n};\n\nexport const CodeOverride: FC<CodeOverrideProps> = ({\n components,\n ...props\n}) => {\n const preProps = useContext(PreContext);\n if (!preProps) return <components.Code {...(props as any)} />;\n return <CodeBlockOverride components={components} {...props} />;\n};\n","import { ComponentType, FC, useMemo } from \"react\";\n\nimport {\n CodeComponent,\n CodeHeaderProps,\n PreComponent,\n SyntaxHighlighterProps,\n} from \"./types\";\nimport { DefaultCodeBlockContent } from \"./defaultComponents\";\n\nexport type CodeBlockProps = {\n language: string;\n code: string;\n components: {\n Pre: PreComponent;\n Code: CodeComponent;\n CodeHeader: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter: ComponentType<SyntaxHighlighterProps>;\n };\n};\n\nexport const DefaultCodeBlock: FC<CodeBlockProps> = ({\n components: { Pre, Code, SyntaxHighlighter, CodeHeader },\n language,\n code,\n}) => {\n const components = useMemo(() => ({ Pre, Code }), [Pre, Code]);\n\n const SH = !!language ? SyntaxHighlighter : DefaultCodeBlockContent;\n\n return (\n <>\n <CodeHeader language={language} code={code} />\n <SH\n components={components}\n language={language ?? \"unknown\"}\n code={code}\n />\n </>\n );\n};\n","import classNames from \"classnames\";\n\nexport const withDefaultProps =\n <TProps extends { className?: string | undefined }>({\n className,\n ...defaultProps\n }: Partial<TProps>) =>\n ({ className: classNameProp, ...props }: TProps) => {\n return {\n className: classNames(className, classNameProp),\n ...defaultProps,\n ...props,\n } as TProps;\n };\n","import { TextContentPartProps } from \"@assistant-ui/react\";\nimport { FC, memo } from \"react\";\nimport { CodeHeader } from \"./code-header\";\nimport classNames from \"classnames\";\nimport {\n MarkdownTextPrimitive,\n MarkdownTextPrimitiveProps,\n} from \"../primitives/MarkdownText\";\n\nexport type MakeMarkdownTextProps = MarkdownTextPrimitiveProps;\n\nexport const makeMarkdownText = ({\n className,\n components: userComponents,\n ...rest\n}: MakeMarkdownTextProps = {}) => {\n const components = {\n ...userComponents,\n CodeHeader: userComponents?.CodeHeader ?? CodeHeader,\n };\n\n const MarkdownTextImpl: FC<TextContentPartProps> = ({ status }) => {\n return (\n <div\n className={classNames(\n \"aui-md-root\",\n status.type === \"running\" && \"aui-md-in-progress\",\n className,\n )}\n >\n <MarkdownTextPrimitive components={components} {...rest} />\n </div>\n );\n };\n MarkdownTextImpl.displayName = \"MarkdownText\";\n\n return memo(\n MarkdownTextImpl,\n (prev, next) => prev.status.type === next.status.type,\n );\n};\n","import { FC } from \"react\";\nimport { CheckIcon, CopyIcon } from \"lucide-react\";\nimport { useThreadConfig, INTERNAL } from \"@assistant-ui/react\";\n\nimport { CodeHeaderProps } from \"../overrides/types\";\nimport { useCopyToClipboard } from \"./useCopyToClipboard\";\n\nconst { TooltipIconButton } = INTERNAL;\n\nexport const CodeHeader: FC<CodeHeaderProps> = ({ language, code }) => {\n const {\n strings: {\n code: { header: { copy: { tooltip = \"Copy\" } = {} } = {} } = {},\n } = {},\n } = useThreadConfig();\n\n const { isCopied, copyToClipboard } = useCopyToClipboard();\n const onCopy = () => {\n if (!code || isCopied) return;\n copyToClipboard(code);\n };\n\n return (\n <div className=\"aui-code-header-root\">\n <span className=\"aui-code-header-language\">{language}</span>\n <TooltipIconButton tooltip={tooltip} onClick={onCopy}>\n {!isCopied && <CopyIcon />}\n {isCopied && <CheckIcon />}\n </TooltipIconButton>\n </div>\n );\n};\n","import { useState } from \"react\";\nimport { UseActionBarCopyProps } from \"@assistant-ui/react\";\n\nexport type useCopyToClipboardProps = UseActionBarCopyProps;\n\nexport const useCopyToClipboard = ({\n copiedDuration = 3000,\n}: useCopyToClipboardProps = {}) => {\n const [isCopied, setIsCopied] = useState<boolean>(false);\n\n const copyToClipboard = (value: string) => {\n if (!value) return;\n\n navigator.clipboard.writeText(value).then(() => {\n setIsCopied(true);\n setTimeout(() => setIsCopied(false), copiedDuration);\n });\n };\n\n return { isCopied, copyToClipboard };\n};\n"],"mappings":";;;AAEA,SAAS,UAAU,0BAA0B;AAE7C,OAAO,mBAAqC;;;ACJ5C,SAAS,qBAA+C;AAS/C;AANF,IAAM,aAAa,cAGhB,IAAI;AAEP,IAAM,cAA4B,CAAC,EAAE,UAAU,GAAG,KAAK,MAAM;AAClE,SAAO,oBAAC,WAAW,UAAX,EAAoB,OAAO,MAAO,UAAS;AACrD;;;ACNE,gBAAAA,YAAA;AADK,IAAM,aAA2B,CAAC,EAAE,MAAM,GAAG,KAAK,MACvD,gBAAAA,KAAC,SAAK,GAAG,MAAM;AAGV,IAAM,cAA6B,CAAC,EAAE,MAAM,GAAG,KAAK,MACzD,gBAAAA,KAAC,UAAM,GAAG,MAAM;AAGX,IAAM,0BAGR,CAAC,EAAE,YAAY,EAAE,KAAK,KAAK,GAAG,KAAK,MACtC,gBAAAA,KAAC,OACC,0BAAAA,KAAC,QAAM,gBAAK,GACd;AAGK,IAAM,oBAAoD,MAAM;;;AFPvE,SAAS,kBAAAC,uBAAsB;;;AGb/B,SAAsD,kBAAkB;;;ACAxE,SAA4B,eAAe;AA+BvC,mBACE,OAAAC,MADF;AAVG,IAAM,mBAAuC,CAAC;AAAA,EACnD,Y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C,YAAS;AAAA,MACvB,YAAY,gBAAAA,KAAC,aAAU;AAAA,OAC1B;AAAA,KACF;AAEJ;;;AD5BA,OAAOG,iBAAgB;AA2Bf,gBAAAC,YAAA;AAnBD,IAAM,mBAAmB,CAAC;AAAA,EAC/B;AAAA,EACA,YAAY;AAAA,EACZ,GAAG;AACL,IAA2B,CAAC,MAAM;AAChC,QAAM,aAAa;AAAA,IACjB,GAAG;AAAA,IACH,YAAY,gBAAgB,cAAc;AAAA,EAC5C;AAEA,QAAM,mBAA6C,CAAC,EAAE,OAAO,MAAM;AACjE,WACE,gBAAAA;AAAA,MAAC;AAAA;AAAA,QACC,WAAWC;AAAA,UACT;AAAA,UACA,OAAO,SAAS,aAAa;AAAA,UAC7B;AAAA,QACF;AAAA,QAEA,0BAAAD,KAAC,yBAAsB,YAAyB,GAAG,MAAM;AAAA;AAAA,IAC3D;AAAA,EAEJ;AACA,mBAAiB,cAAc;AAE/B,SAAO;AAAA,IACL;AAAA,IACA,CAAC,MAAM,SAAS,KAAK,OAAO,SAAS,KAAK,OAAO;AAAA,EACnD;AACF;","names":["jsx","useCallbackRef","jsx","CodeHeader","jsx","CodeHeader","jsx","CodeHeader","useCallbackRef","INTERNAL","jsx","jsxs","INTERNAL","classNames","jsx","classNames"]}
1
+ {"version":3,"sources":["../src/primitives/MarkdownText.tsx","../src/overrides/PreOverride.tsx","../src/overrides/defaultComponents.tsx","../src/overrides/CodeOverride.tsx","../src/overrides/CodeBlock.tsx","../src/overrides/withDefaults.tsx","../src/ui/markdown-text.tsx","../src/ui/code-header.tsx","../src/ui/useCopyToClipboard.tsx"],"sourcesContent":["\"use client\";\n\nimport { useContentPartText } from \"@assistant-ui/react\";\nimport {\n ElementRef,\n ElementType,\n forwardRef,\n ForwardRefExoticComponent,\n RefAttributes,\n type ComponentPropsWithoutRef,\n type ComponentType,\n} from \"react\";\nimport ReactMarkdown, { type Options } from \"react-markdown\";\nimport { SyntaxHighlighterProps, CodeHeaderProps } from \"../overrides/types\";\nimport { PreOverride } from \"../overrides/PreOverride\";\nimport {\n DefaultPre,\n DefaultCode,\n DefaultCodeBlockContent,\n DefaultCodeHeader,\n} from \"../overrides/defaultComponents\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { CodeOverride } from \"../overrides/CodeOverride\";\nimport { useSmooth } from \"@assistant-ui/react/internal\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport classNames from \"classnames\";\n\ntype MarkdownTextPrimitiveElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nexport type MarkdownTextPrimitiveProps = Omit<\n Options,\n \"components\" | \"children\"\n> & {\n containerProps?: Omit<PrimitiveDivProps, \"children\" | \"asChild\">;\n containerComponent?: ElementType;\n components?: NonNullable<Options[\"components\"]> & {\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps>;\n CodeHeader?: ComponentType<CodeHeaderProps>;\n by_language?: Record<\n string,\n {\n CodeHeader?: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps>;\n }\n >;\n };\n smooth?: boolean;\n};\n\nexport const MarkdownTextPrimitive: ForwardRefExoticComponent<MarkdownTextPrimitiveProps> &\n RefAttributes<MarkdownTextPrimitiveElement> = forwardRef<\n MarkdownTextPrimitiveElement,\n MarkdownTextPrimitiveProps\n>(\n (\n {\n components: userComponents,\n className,\n containerProps,\n containerComponent: Container = \"div\",\n ...rest\n },\n forwardedRef,\n smooth = true,\n ) => {\n const {\n part: { text },\n status,\n } = useSmooth(useContentPartText(), smooth);\n\n const {\n pre = DefaultPre,\n code = DefaultCode,\n SyntaxHighlighter = DefaultCodeBlockContent,\n CodeHeader = DefaultCodeHeader,\n by_language,\n ...componentsRest\n } = userComponents ?? {};\n const components: typeof userComponents = {\n ...componentsRest,\n pre: PreOverride,\n code: useCallbackRef((props) => (\n <CodeOverride\n components={{\n Pre: pre,\n Code: code,\n SyntaxHighlighter,\n CodeHeader,\n by_language,\n }}\n {...props}\n />\n )),\n };\n\n return (\n <Container\n data-status={status.type}\n {...containerProps}\n className={classNames(className, containerProps?.className)}\n ref={forwardedRef}\n >\n <ReactMarkdown components={components} {...rest}>\n {text}\n </ReactMarkdown>\n </Container>\n );\n },\n);\n\nMarkdownTextPrimitive.displayName = \"MarkdownTextPrimitive\";\n","import { createContext, ComponentPropsWithoutRef, useContext } from \"react\";\nimport { PreComponent } from \"./types\";\n\nexport const PreContext = createContext<Omit<\n ComponentPropsWithoutRef<PreComponent>,\n \"children\"\n> | null>(null);\n\nexport const useIsMarkdownCodeBlock = () => {\n return useContext(PreContext) !== null;\n};\n\nexport const PreOverride: PreComponent = ({ children, ...rest }) => {\n return <PreContext.Provider value={rest}>{children}</PreContext.Provider>;\n};\n","import type { ComponentType, ReactNode } from \"react\";\nimport { PreComponent, CodeComponent, CodeHeaderProps } from \"./types\";\n\nexport const DefaultPre: PreComponent = ({ node, ...rest }) => (\n <pre {...rest} />\n);\n\nexport const DefaultCode: CodeComponent = ({ node, ...rest }) => (\n <code {...rest} />\n);\n\nexport const DefaultCodeBlockContent: ComponentType<{\n components: { Pre: PreComponent; Code: CodeComponent };\n code: string | ReactNode | undefined;\n}> = ({ components: { Pre, Code }, code }) => (\n <Pre>\n <Code>{code}</Code>\n </Pre>\n);\n\nexport const DefaultCodeHeader: ComponentType<CodeHeaderProps> = () => null;\n","import { ComponentPropsWithoutRef, ComponentType, FC, useContext } from \"react\";\nimport { PreContext } from \"./PreOverride\";\nimport {\n CodeComponent,\n CodeHeaderProps,\n PreComponent,\n SyntaxHighlighterProps,\n} from \"./types\";\nimport { DefaultCodeBlock } from \"./CodeBlock\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { withDefaultProps } from \"./withDefaults\";\nimport { DefaultCodeBlockContent } from \"./defaultComponents\";\n\nconst CodeBlockOverride: FC<CodeOverrideProps> = ({\n components: {\n Pre,\n Code,\n SyntaxHighlighter: FallbackSyntaxHighlighter,\n CodeHeader: FallbackCodeHeader,\n by_language = {},\n },\n children,\n ...codeProps\n}) => {\n const preProps = useContext(PreContext)!;\n const getPreProps = withDefaultProps<any>(preProps);\n const WrappedPre: PreComponent = useCallbackRef((props) => (\n <Pre {...getPreProps(props)} />\n ));\n\n const getCodeProps = withDefaultProps<any>(codeProps);\n const WrappedCode: CodeComponent = useCallbackRef((props) => (\n <Code {...getCodeProps(props)} />\n ));\n\n const language = /language-(\\w+)/.exec(codeProps.className || \"\")?.[1] ?? \"\";\n\n // if the code content is not string (due to rehype plugins), return a default code block\n if (typeof children !== \"string\") {\n return (\n <DefaultCodeBlockContent\n components={{ Pre: WrappedPre, Code: WrappedCode }}\n code={children}\n />\n );\n }\n\n const SyntaxHighlighter: ComponentType<SyntaxHighlighterProps> =\n by_language[language]?.SyntaxHighlighter ?? FallbackSyntaxHighlighter;\n\n const CodeHeader: ComponentType<CodeHeaderProps> =\n by_language[language]?.CodeHeader ?? FallbackCodeHeader;\n\n return (\n <DefaultCodeBlock\n components={{\n Pre: WrappedPre,\n Code: WrappedCode,\n SyntaxHighlighter,\n CodeHeader,\n }}\n language={language || \"unknown\"}\n code={children}\n />\n );\n};\n\nexport type CodeOverrideProps = ComponentPropsWithoutRef<CodeComponent> & {\n components: {\n Pre: PreComponent;\n Code: CodeComponent;\n CodeHeader: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter: ComponentType<SyntaxHighlighterProps>;\n by_language?: Record<\n string,\n {\n CodeHeader?: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps>;\n }\n >;\n };\n};\n\nexport const CodeOverride: FC<CodeOverrideProps> = ({\n components,\n ...props\n}) => {\n const preProps = useContext(PreContext);\n if (!preProps) return <components.Code {...(props as any)} />;\n return <CodeBlockOverride components={components} {...props} />;\n};\n","import { ComponentType, FC, useMemo } from \"react\";\n\nimport {\n CodeComponent,\n CodeHeaderProps,\n PreComponent,\n SyntaxHighlighterProps,\n} from \"./types\";\nimport { DefaultCodeBlockContent } from \"./defaultComponents\";\n\nexport type CodeBlockProps = {\n language: string;\n code: string;\n components: {\n Pre: PreComponent;\n Code: CodeComponent;\n CodeHeader: ComponentType<CodeHeaderProps>;\n SyntaxHighlighter: ComponentType<SyntaxHighlighterProps>;\n };\n};\n\nexport const DefaultCodeBlock: FC<CodeBlockProps> = ({\n components: { Pre, Code, SyntaxHighlighter, CodeHeader },\n language,\n code,\n}) => {\n const components = useMemo(() => ({ Pre, Code }), [Pre, Code]);\n\n const SH = !!language ? SyntaxHighlighter : DefaultCodeBlockContent;\n\n return (\n <>\n <CodeHeader language={language} code={code} />\n <SH\n components={components}\n language={language ?? \"unknown\"}\n code={code}\n />\n </>\n );\n};\n","import classNames from \"classnames\";\n\nexport const withDefaultProps =\n <TProps extends { className?: string | undefined }>({\n className,\n ...defaultProps\n }: Partial<TProps>) =>\n ({ className: classNameProp, ...props }: TProps) => {\n return {\n className: classNames(className, classNameProp),\n ...defaultProps,\n ...props,\n } as TProps;\n };\n","import { FC, memo } from \"react\";\nimport { CodeHeader } from \"./code-header\";\nimport classNames from \"classnames\";\nimport {\n MarkdownTextPrimitive,\n MarkdownTextPrimitiveProps,\n} from \"../primitives/MarkdownText\";\nimport {\n withSmoothContextProvider,\n useSmoothStatus,\n} from \"@assistant-ui/react/internal\";\n\nexport type MakeMarkdownTextProps = MarkdownTextPrimitiveProps;\n\nexport const makeMarkdownText = ({\n className,\n components: userComponents,\n ...rest\n}: MakeMarkdownTextProps = {}) => {\n const components = {\n ...userComponents,\n CodeHeader: userComponents?.CodeHeader ?? CodeHeader,\n };\n\n const MarkdownTextImpl: FC = () => {\n const status = useSmoothStatus();\n return (\n <MarkdownTextPrimitive\n components={components}\n {...rest}\n className={classNames(\n \"aui-md-root\",\n status.type === \"running\" && \"aui-md-running\",\n className,\n )}\n />\n );\n };\n MarkdownTextImpl.displayName = \"MarkdownText\";\n\n return memo(withSmoothContextProvider(MarkdownTextImpl), () => true);\n};\n","import { FC } from \"react\";\nimport { CheckIcon, CopyIcon } from \"lucide-react\";\nimport { useThreadConfig } from \"@assistant-ui/react\";\nimport { TooltipIconButton } from \"@assistant-ui/react/internal\";\n\nimport { CodeHeaderProps } from \"../overrides/types\";\nimport { useCopyToClipboard } from \"./useCopyToClipboard\";\n\nexport const CodeHeader: FC<CodeHeaderProps> = ({ language, code }) => {\n const {\n strings: {\n code: { header: { copy: { tooltip = \"Copy\" } = {} } = {} } = {},\n } = {},\n } = useThreadConfig();\n\n const { isCopied, copyToClipboard } = useCopyToClipboard();\n const onCopy = () => {\n if (!code || isCopied) return;\n copyToClipboard(code);\n };\n\n return (\n <div className=\"aui-code-header-root\">\n <span className=\"aui-code-header-language\">{language}</span>\n <TooltipIconButton tooltip={tooltip} onClick={onCopy}>\n {!isCopied && <CopyIcon />}\n {isCopied && <CheckIcon />}\n </TooltipIconButton>\n </div>\n );\n};\n","import { useState } from \"react\";\nimport { UseActionBarCopyProps } from \"@assistant-ui/react\";\n\nexport type useCopyToClipboardProps = UseActionBarCopyProps;\n\nexport const useCopyToClipboard = ({\n copiedDuration = 3000,\n}: useCopyToClipboardProps = {}) => {\n const [isCopied, setIsCopied] = useState<boolean>(false);\n\n const copyToClipboard = (value: string) => {\n if (!value) return;\n\n navigator.clipboard.writeText(value).then(() => {\n setIsCopied(true);\n setTimeout(() => setIsCopied(false), copiedDuration);\n });\n };\n\n return { isCopied, copyToClipboard };\n};\n"],"mappings":";;;AAEA,SAAS,0BAA0B;AACnC;AAAA,EAGE;AAAA,OAKK;AACP,OAAO,mBAAqC;;;ACZ5C,SAAS,eAAyC,kBAAkB;AAa3D;AAVF,IAAM,aAAa,cAGhB,IAAI;AAEP,IAAM,yBAAyB,MAAM;AAC1C,SAAO,WAAW,UAAU,MAAM;AACpC;AAEO,IAAM,cAA4B,CAAC,EAAE,UAAU,GAAG,KAAK,MAAM;AAClE,SAAO,oBAAC,WAAW,UAAX,EAAoB,OAAO,MAAO,UAAS;AACrD;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,UACA,OAAO,SAAS,aAAa;AAAA,UAC7B;AAAA,QACF;AAAA;AAAA,IACF;AAAA,EAEJ;AACA,mBAAiB,cAAc;AAE/B,SAAO,KAAK,0BAA0B,gBAAgB,GAAG,MAAM,IAAI;AACrE;","names":["jsx","useCallbackRef","useContext","jsx","CodeHeader","jsx","useContext","CodeHeader","classNames","jsx","CodeHeader","useCallbackRef","jsx","jsxs","classNames","jsx","classNames"]}
@@ -4,12 +4,12 @@
4
4
  opacity: .5;
5
5
  }
6
6
  }
7
- :where(.aui-md-in-progress:empty)::after,
8
- :where(.aui-md-in-progress > :not(ol):not(ul):not(pre):last-child)::after,
9
- :where(.aui-md-in-progress > pre:last-child code)::after,
10
- :where(.aui-md-in-progress > :is(ol, ul):last-child > li:last-child:not(:has(* > li)))::after,
11
- :where(.aui-md-in-progress > :is(ol, ul):last-child > li:last-child > :is(ol, ul):last-child > li:last-child:not(:has(* > li)))::after,
12
- :where(.aui-md-in-progress > :is(ol, ul):last-child > li:last-child > :is(ol, ul):last-child > li:last-child > :is(ol, ul):last-child > li:last-child)::after {
7
+ :where(.aui-md-running):empty::after,
8
+ :where(.aui-md-running) > :where(:not(ol):not(ul):not(pre)):last-child::after,
9
+ :where(.aui-md-running) > pre:last-child code::after,
10
+ :where(.aui-md-running) > :where(:is(ol, ul):last-child) > :where(li:last-child:not(:has(* > li)))::after,
11
+ :where(.aui-md-running) > :where(:is(ol, ul):last-child) > :where(li:last-child) > :where(:is(ol, ul):last-child) > :where(li:last-child:not(:has(* > li)))::after,
12
+ :where(.aui-md-running) > :where(:is(ol, ul):last-child) > :where(li:last-child) > :where(:is(ol, ul):last-child) > :where(li:last-child) > :where(:is(ol, ul):last-child) > :where(li:last-child)::after {
13
13
  animation: aui-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
14
14
  font-family:
15
15
  ui-sans-serif,
@@ -22,23 +22,23 @@
22
22
  --aui-content: "\25cf";
23
23
  content: var(--aui-content);
24
24
  }
25
- :where(.aui-md-in-progress:empty):where([dir=ltr], [dir=ltr] *)::after,
26
- :where(.aui-md-in-progress > :not(ol):not(ul):not(pre):last-child):where([dir=ltr], [dir=ltr] *)::after,
27
- :where(.aui-md-in-progress > pre:last-child code):where([dir=ltr], [dir=ltr] *)::after,
28
- :where(.aui-md-in-progress > :is(ol, ul):last-child > li:last-child:not(:has(* > li))):where([dir=ltr], [dir=ltr] *)::after,
29
- :where(.aui-md-in-progress > :is(ol, ul):last-child > li:last-child > :is(ol, ul):last-child > li:last-child:not(:has(* > li))):where([dir=ltr], [dir=ltr] *)::after,
30
- :where(.aui-md-in-progress > :is(ol, ul):last-child > li:last-child > :is(ol, ul):last-child > li:last-child > :is(ol, ul):last-child > li:last-child):where([dir=ltr], [dir=ltr] *)::after {
25
+ :where(.aui-md-running):empty:where([dir=ltr], [dir=ltr] *)::after,
26
+ :where(.aui-md-running) > :where(:not(ol):not(ul):not(pre)):last-child:where([dir=ltr], [dir=ltr] *)::after,
27
+ :where(.aui-md-running) > pre:last-child code:where([dir=ltr], [dir=ltr] *)::after,
28
+ :where(.aui-md-running) > :where(:is(ol, ul):last-child) > :where(li:last-child:not(:has(* > li))):where([dir=ltr], [dir=ltr] *)::after,
29
+ :where(.aui-md-running) > :where(:is(ol, ul):last-child) > :where(li:last-child) > :where(:is(ol, ul):last-child) > :where(li:last-child:not(:has(* > li))):where([dir=ltr], [dir=ltr] *)::after,
30
+ :where(.aui-md-running) > :where(:is(ol, ul):last-child) > :where(li:last-child) > :where(:is(ol, ul):last-child) > :where(li:last-child) > :where(:is(ol, ul):last-child) > :where(li:last-child):where([dir=ltr], [dir=ltr] *)::after {
31
31
  margin-left: 0.25rem;
32
32
  }
33
- :where(.aui-md-in-progress:empty):where([dir=rtl], [dir=rtl] *)::after,
34
- :where(.aui-md-in-progress > :not(ol):not(ul):not(pre):last-child):where([dir=rtl], [dir=rtl] *)::after,
35
- :where(.aui-md-in-progress > pre:last-child code):where([dir=rtl], [dir=rtl] *)::after,
36
- :where(.aui-md-in-progress > :is(ol, ul):last-child > li:last-child:not(:has(* > li))):where([dir=rtl], [dir=rtl] *)::after,
37
- :where(.aui-md-in-progress > :is(ol, ul):last-child > li:last-child > :is(ol, ul):last-child > li:last-child:not(:has(* > li))):where([dir=rtl], [dir=rtl] *)::after,
38
- :where(.aui-md-in-progress > :is(ol, ul):last-child > li:last-child > :is(ol, ul):last-child > li:last-child > :is(ol, ul):last-child > li:last-child):where([dir=rtl], [dir=rtl] *)::after {
33
+ :where(.aui-md-running):empty:where([dir=rtl], [dir=rtl] *)::after,
34
+ :where(.aui-md-running) > :where(:not(ol):not(ul):not(pre)):last-child:where([dir=rtl], [dir=rtl] *)::after,
35
+ :where(.aui-md-running) > pre:last-child code:where([dir=rtl], [dir=rtl] *)::after,
36
+ :where(.aui-md-running) > :where(:is(ol, ul):last-child) > :where(li:last-child:not(:has(* > li))):where([dir=rtl], [dir=rtl] *)::after,
37
+ :where(.aui-md-running) > :where(:is(ol, ul):last-child) > :where(li:last-child) > :where(:is(ol, ul):last-child) > :where(li:last-child:not(:has(* > li))):where([dir=rtl], [dir=rtl] *)::after,
38
+ :where(.aui-md-running) > :where(:is(ol, ul):last-child) > :where(li:last-child) > :where(:is(ol, ul):last-child) > :where(li:last-child) > :where(:is(ol, ul):last-child) > :where(li:last-child):where([dir=rtl], [dir=rtl] *)::after {
39
39
  margin-right: 0.25rem;
40
40
  }
41
- :where(.aui-md-root) h1 {
41
+ .aui-md-root h1 {
42
42
  margin-bottom: 2rem;
43
43
  scroll-margin: 5rem;
44
44
  font-size: 2.25rem;
@@ -46,10 +46,10 @@
46
46
  font-weight: 800;
47
47
  letter-spacing: -0.025em;
48
48
  }
49
- :where(.aui-md-root) h1:last-child {
49
+ .aui-md-root h1:last-child {
50
50
  margin-bottom: 0px;
51
51
  }
52
- :where(.aui-md-root) h2 {
52
+ .aui-md-root h2 {
53
53
  margin-bottom: 1rem;
54
54
  margin-top: 2rem;
55
55
  scroll-margin: 5rem;
@@ -58,13 +58,13 @@
58
58
  font-weight: 600;
59
59
  letter-spacing: -0.025em;
60
60
  }
61
- :where(.aui-md-root) h2:first-child {
61
+ .aui-md-root h2:first-child {
62
62
  margin-top: 0px;
63
63
  }
64
- :where(.aui-md-root) h2:last-child {
64
+ .aui-md-root h2:last-child {
65
65
  margin-bottom: 0px;
66
66
  }
67
- :where(.aui-md-root) h3 {
67
+ .aui-md-root h3 {
68
68
  margin-bottom: 1rem;
69
69
  margin-top: 1.5rem;
70
70
  scroll-margin: 5rem;
@@ -73,13 +73,13 @@
73
73
  font-weight: 600;
74
74
  letter-spacing: -0.025em;
75
75
  }
76
- :where(.aui-md-root) h3:first-child {
76
+ .aui-md-root h3:first-child {
77
77
  margin-top: 0px;
78
78
  }
79
- :where(.aui-md-root) h3:last-child {
79
+ .aui-md-root h3:last-child {
80
80
  margin-bottom: 0px;
81
81
  }
82
- :where(.aui-md-root) h4 {
82
+ .aui-md-root h4 {
83
83
  margin-bottom: 1rem;
84
84
  margin-top: 1.5rem;
85
85
  scroll-margin: 5rem;
@@ -88,82 +88,82 @@
88
88
  font-weight: 600;
89
89
  letter-spacing: -0.025em;
90
90
  }
91
- :where(.aui-md-root) h4:first-child {
91
+ .aui-md-root h4:first-child {
92
92
  margin-top: 0px;
93
93
  }
94
- :where(.aui-md-root) h4:last-child {
94
+ .aui-md-root h4:last-child {
95
95
  margin-bottom: 0px;
96
96
  }
97
- :where(.aui-md-root) h5 {
97
+ .aui-md-root h5 {
98
98
  margin-top: 1rem;
99
99
  margin-bottom: 1rem;
100
100
  font-size: 1.125rem;
101
101
  line-height: 1.75rem;
102
102
  font-weight: 600;
103
103
  }
104
- :where(.aui-md-root) h5:first-child {
104
+ .aui-md-root h5:first-child {
105
105
  margin-top: 0px;
106
106
  }
107
- :where(.aui-md-root) h5:last-child {
107
+ .aui-md-root h5:last-child {
108
108
  margin-bottom: 0px;
109
109
  }
110
- :where(.aui-md-root) h6 {
110
+ .aui-md-root h6 {
111
111
  margin-top: 1rem;
112
112
  margin-bottom: 1rem;
113
113
  font-weight: 600;
114
114
  }
115
- :where(.aui-md-root) h6:first-child {
115
+ .aui-md-root h6:first-child {
116
116
  margin-top: 0px;
117
117
  }
118
- :where(.aui-md-root) h6:last-child {
118
+ .aui-md-root h6:last-child {
119
119
  margin-bottom: 0px;
120
120
  }
121
- :where(.aui-md-root) p {
121
+ .aui-md-root p {
122
122
  margin-bottom: 1.25rem;
123
123
  margin-top: 1.25rem;
124
124
  line-height: 1.75rem;
125
125
  }
126
- :where(.aui-md-root) p:first-child {
126
+ .aui-md-root p:first-child {
127
127
  margin-top: 0px;
128
128
  }
129
- :where(.aui-md-root) p:last-child {
129
+ .aui-md-root p:last-child {
130
130
  margin-bottom: 0px;
131
131
  }
132
- :where(.aui-md-root) a {
132
+ .aui-md-root a {
133
133
  font-weight: 500;
134
134
  color: hsl(var(--aui-primary));
135
135
  text-decoration-line: underline;
136
136
  text-underline-offset: 4px;
137
137
  }
138
- :where(.aui-md-root) blockquote {
138
+ .aui-md-root blockquote {
139
139
  border-left-width: 2px;
140
140
  padding-left: 1.5rem;
141
141
  font-style: italic;
142
142
  }
143
- :where(.aui-md-root) ul {
143
+ .aui-md-root ul {
144
144
  margin-top: 1.25rem;
145
145
  margin-bottom: 1.25rem;
146
146
  margin-left: 1.5rem;
147
147
  list-style-type: disc;
148
148
  }
149
- :where(.aui-md-root) ul > li {
149
+ .aui-md-root ul > li {
150
150
  margin-top: 0.5rem;
151
151
  }
152
- :where(.aui-md-root) ol {
152
+ .aui-md-root ol {
153
153
  margin-top: 1.25rem;
154
154
  margin-bottom: 1.25rem;
155
155
  margin-left: 1.5rem;
156
156
  list-style-type: decimal;
157
157
  }
158
- :where(.aui-md-root) ol > li {
158
+ .aui-md-root ol > li {
159
159
  margin-top: 0.5rem;
160
160
  }
161
- :where(.aui-md-root) hr {
161
+ .aui-md-root hr {
162
162
  margin-top: 1.25rem;
163
163
  margin-bottom: 1.25rem;
164
164
  border-bottom-width: 1px;
165
165
  }
166
- :where(.aui-md-root) table {
166
+ .aui-md-root table {
167
167
  margin-top: 1.25rem;
168
168
  margin-bottom: 1.25rem;
169
169
  width: 100%;
@@ -173,7 +173,7 @@
173
173
  border-spacing: var(--aui-border-spacing-x) var(--aui-border-spacing-y);
174
174
  overflow-y: auto;
175
175
  }
176
- :where(.aui-md-root) th {
176
+ .aui-md-root th {
177
177
  background-color: hsl(var(--aui-muted));
178
178
  padding-left: 1rem;
179
179
  padding-right: 1rem;
@@ -182,19 +182,19 @@
182
182
  text-align: left;
183
183
  font-weight: 700;
184
184
  }
185
- :where(.aui-md-root) th:first-child {
185
+ .aui-md-root th:first-child {
186
186
  border-top-left-radius: var(--aui-radius);
187
187
  }
188
- :where(.aui-md-root) th:last-child {
188
+ .aui-md-root th:last-child {
189
189
  border-top-right-radius: var(--aui-radius);
190
190
  }
191
- :where(.aui-md-root) th[align=center] {
191
+ .aui-md-root th[align=center] {
192
192
  text-align: center;
193
193
  }
194
- :where(.aui-md-root) th[align=right] {
194
+ .aui-md-root th[align=right] {
195
195
  text-align: right;
196
196
  }
197
- :where(.aui-md-root) td {
197
+ .aui-md-root td {
198
198
  border-bottom-width: 1px;
199
199
  border-left-width: 1px;
200
200
  padding-left: 1rem;
@@ -203,35 +203,35 @@
203
203
  padding-bottom: 0.5rem;
204
204
  text-align: left;
205
205
  }
206
- :where(.aui-md-root) td:last-child {
206
+ .aui-md-root td:last-child {
207
207
  border-right-width: 1px;
208
208
  }
209
- :where(.aui-md-root) td[align=center] {
209
+ .aui-md-root td[align=center] {
210
210
  text-align: center;
211
211
  }
212
- :where(.aui-md-root) td[align=right] {
212
+ .aui-md-root td[align=right] {
213
213
  text-align: right;
214
214
  }
215
- :where(.aui-md-root) tr {
215
+ .aui-md-root tr {
216
216
  margin: 0px;
217
217
  border-bottom-width: 1px;
218
218
  padding: 0px;
219
219
  }
220
- :where(.aui-md-root) tr:first-child {
220
+ .aui-md-root tr:first-child {
221
221
  border-top-width: 1px;
222
222
  }
223
- :where(.aui-md-root) tr:last-child > td:first-child {
223
+ .aui-md-root tr:last-child > td:first-child {
224
224
  border-bottom-left-radius: var(--aui-radius);
225
225
  }
226
- :where(.aui-md-root) tr:last-child > td:last-child {
226
+ .aui-md-root tr:last-child > td:last-child {
227
227
  border-bottom-right-radius: var(--aui-radius);
228
228
  }
229
- :where(.aui-md-root) sup > a {
229
+ .aui-md-root sup > a {
230
230
  font-size: 0.75rem;
231
231
  line-height: 1rem;
232
232
  text-decoration-line: none;
233
233
  }
234
- :where(.aui-md-root) pre {
234
+ .aui-md-root pre {
235
235
  overflow-x: auto;
236
236
  border-bottom-right-radius: var(--aui-radius);
237
237
  border-bottom-left-radius: var(--aui-radius);
@@ -240,8 +240,8 @@
240
240
  --aui-text-opacity: 1;
241
241
  color: rgb(255 255 255 / var(--aui-text-opacity));
242
242
  }
243
- :where(.aui-md-root) > code,
244
- :where(.aui-md-root) :not(:where(pre)) code {
243
+ .aui-md-root > code,
244
+ .aui-md-root :not(:where(pre)) code {
245
245
  border-radius: 0.25rem;
246
246
  border-width: 1px;
247
247
  background-color: hsl(var(--aui-muted));
@@ -1,107 +1,100 @@
1
- /* in progress indicator */
2
- :where(.aui-md-in-progress:empty)::after,
3
- :where(.aui-md-in-progress > :not(ol):not(ul):not(pre):last-child)::after,
4
- :where(.aui-md-in-progress > pre:last-child code)::after,
5
- :where(
6
- .aui-md-in-progress
7
- > :is(ol, ul):last-child
8
- > li:last-child:not(:has(* > li))
9
- )::after,
10
- :where(
11
- .aui-md-in-progress
12
- > :is(ol, ul):last-child
13
- > li:last-child
14
- > :is(ol, ul):last-child
15
- > li:last-child:not(:has(* > li))
16
- )::after,
17
- :where(
18
- .aui-md-in-progress
19
- > :is(ol, ul):last-child
20
- > li:last-child
21
- > :is(ol, ul):last-child
22
- > li:last-child
23
- > :is(ol, ul):last-child
24
- > li:last-child
25
- )::after {
1
+ /* running indicator */
2
+ :where(.aui-md-running):empty::after,
3
+ :where(.aui-md-running) > :where(:not(ol):not(ul):not(pre)):last-child::after,
4
+ :where(.aui-md-running) > pre:last-child code::after,
5
+ :where(.aui-md-running)
6
+ > :where(:is(ol, ul):last-child)
7
+ > :where(li:last-child:not(:has(* > li)))::after,
8
+ :where(.aui-md-running)
9
+ > :where(:is(ol, ul):last-child)
10
+ > :where(li:last-child)
11
+ > :where(:is(ol, ul):last-child)
12
+ > :where(li:last-child:not(:has(* > li)))::after,
13
+ :where(.aui-md-running)
14
+ > :where(:is(ol, ul):last-child)
15
+ > :where(li:last-child)
16
+ > :where(:is(ol, ul):last-child)
17
+ > :where(li:last-child)
18
+ > :where(:is(ol, ul):last-child)
19
+ > :where(li:last-child)::after {
26
20
  @apply animate-pulse font-sans content-['\25CF'] ltr:ml-1 rtl:mr-1;
27
21
  }
28
-
29
22
  /* typography */
30
23
 
31
- :where(.aui-md-root) h1 {
24
+ .aui-md-root h1 {
32
25
  @apply mb-8 scroll-m-20 text-4xl font-extrabold tracking-tight last:mb-0;
33
26
  }
34
27
 
35
- :where(.aui-md-root) h2 {
28
+ .aui-md-root h2 {
36
29
  @apply mb-4 mt-8 scroll-m-20 text-3xl font-semibold tracking-tight first:mt-0 last:mb-0;
37
30
  }
38
31
 
39
- :where(.aui-md-root) h3 {
32
+ .aui-md-root h3 {
40
33
  @apply mb-4 mt-6 scroll-m-20 text-2xl font-semibold tracking-tight first:mt-0 last:mb-0;
41
34
  }
42
35
 
43
- :where(.aui-md-root) h4 {
36
+ .aui-md-root h4 {
44
37
  @apply mb-4 mt-6 scroll-m-20 text-xl font-semibold tracking-tight first:mt-0 last:mb-0;
45
38
  }
46
39
 
47
- :where(.aui-md-root) h5 {
40
+ .aui-md-root h5 {
48
41
  @apply my-4 text-lg font-semibold first:mt-0 last:mb-0;
49
42
  }
50
43
 
51
- :where(.aui-md-root) h6 {
44
+ .aui-md-root h6 {
52
45
  @apply my-4 font-semibold first:mt-0 last:mb-0;
53
46
  }
54
47
 
55
- :where(.aui-md-root) p {
48
+ .aui-md-root p {
56
49
  @apply mb-5 mt-5 leading-7 first:mt-0 last:mb-0;
57
50
  }
58
51
 
59
- :where(.aui-md-root) a {
52
+ .aui-md-root a {
60
53
  @apply text-aui-primary font-medium underline underline-offset-4;
61
54
  }
62
55
 
63
- :where(.aui-md-root) blockquote {
56
+ .aui-md-root blockquote {
64
57
  @apply border-l-2 pl-6 italic;
65
58
  }
66
59
 
67
- :where(.aui-md-root) ul {
60
+ .aui-md-root ul {
68
61
  @apply my-5 ml-6 list-disc [&>li]:mt-2;
69
62
  }
70
63
 
71
- :where(.aui-md-root) ol {
64
+ .aui-md-root ol {
72
65
  @apply my-5 ml-6 list-decimal [&>li]:mt-2;
73
66
  }
74
67
 
75
- :where(.aui-md-root) hr {
68
+ .aui-md-root hr {
76
69
  @apply my-5 border-b;
77
70
  }
78
71
 
79
- :where(.aui-md-root) table {
72
+ .aui-md-root table {
80
73
  @apply my-5 w-full border-separate border-spacing-0 overflow-y-auto;
81
74
  }
82
75
 
83
- :where(.aui-md-root) th {
76
+ .aui-md-root th {
84
77
  @apply bg-aui-muted px-4 py-2 text-left font-bold first:rounded-tl-lg last:rounded-tr-lg [&[align=center]]:text-center [&[align=right]]:text-right;
85
78
  }
86
79
 
87
- :where(.aui-md-root) td {
80
+ .aui-md-root td {
88
81
  @apply border-b border-l px-4 py-2 text-left last:border-r [&[align=center]]:text-center [&[align=right]]:text-right;
89
82
  }
90
83
 
91
- :where(.aui-md-root) tr {
84
+ .aui-md-root tr {
92
85
  @apply m-0 border-b p-0 first:border-t [&:last-child>td:first-child]:rounded-bl-lg [&:last-child>td:last-child]:rounded-br-lg;
93
86
  }
94
87
 
95
- :where(.aui-md-root) sup {
88
+ .aui-md-root sup {
96
89
  @apply [&>a]:text-xs [&>a]:no-underline;
97
90
  }
98
91
 
99
- :where(.aui-md-root) pre {
92
+ .aui-md-root pre {
100
93
  @apply overflow-x-auto rounded-b-lg bg-black p-4 text-white;
101
94
  }
102
95
 
103
- :where(.aui-md-root) > code,
104
- :where(.aui-md-root) :not(:where(pre)) code {
96
+ .aui-md-root > code,
97
+ .aui-md-root :not(:where(pre)) code {
105
98
  @apply bg-aui-muted rounded border font-semibold;
106
99
  }
107
100
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assistant-ui/react-markdown",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": {
@@ -37,13 +37,14 @@
37
37
  ],
38
38
  "sideEffects": false,
39
39
  "dependencies": {
40
+ "@radix-ui/react-primitive": "^2.0.0",
40
41
  "@radix-ui/react-use-callback-ref": "^1.1.0",
41
42
  "classnames": "^2.5.1",
42
- "lucide-react": "^0.414.0",
43
+ "lucide-react": "^0.416.0",
43
44
  "react-markdown": "^9.0.1"
44
45
  },
45
46
  "peerDependencies": {
46
- "@assistant-ui/react": "^0.5.9",
47
+ "@assistant-ui/react": "^0.5.20",
47
48
  "@types/react": "*",
48
49
  "react": "^18",
49
50
  "tailwindcss": "^3.4.4"
@@ -61,10 +62,10 @@
61
62
  "autoprefixer": "^10.4.19",
62
63
  "eslint": "^8",
63
64
  "eslint-config-next": "14.2.5",
64
- "postcss": "^8.4.39",
65
- "tailwindcss": "^3.4.6",
65
+ "postcss": "^8.4.40",
66
+ "tailwindcss": "^3.4.7",
66
67
  "tailwindcss-animate": "^1.0.7",
67
- "tsup": "8.2.2",
68
+ "tsup": "8.2.3",
68
69
  "tsx": "^4.16.2",
69
70
  "@assistant-ui/tailwindcss-transformer": "^0.1.0",
70
71
  "@assistant-ui/tsconfig": "0.0.0"