@assistant-ui/react-markdown 0.11.8 → 0.11.10
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.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -11
- package/dist/index.js.map +1 -1
- package/dist/memoization.d.ts +2 -2
- package/dist/memoization.d.ts.map +1 -1
- package/dist/memoization.js +27 -30
- package/dist/memoization.js.map +1 -1
- package/dist/overrides/CodeBlock.d.ts +2 -2
- package/dist/overrides/CodeBlock.d.ts.map +1 -1
- package/dist/overrides/CodeBlock.js +5 -25
- package/dist/overrides/CodeBlock.js.map +1 -1
- package/dist/overrides/CodeOverride.d.ts +1 -1
- package/dist/overrides/CodeOverride.d.ts.map +1 -1
- package/dist/overrides/CodeOverride.js +31 -72
- package/dist/overrides/CodeOverride.js.map +1 -1
- package/dist/overrides/PreOverride.js +8 -19
- package/dist/overrides/PreOverride.js.map +1 -1
- package/dist/overrides/defaultComponents.d.ts +2 -2
- package/dist/overrides/defaultComponents.d.ts.map +1 -1
- package/dist/overrides/defaultComponents.js +5 -12
- package/dist/overrides/defaultComponents.js.map +1 -1
- package/dist/overrides/types.d.ts +1 -1
- package/dist/overrides/types.d.ts.map +1 -1
- package/dist/overrides/types.js +1 -0
- package/dist/overrides/types.js.map +1 -1
- package/dist/overrides/withDefaults.js +6 -13
- package/dist/overrides/withDefaults.js.map +1 -1
- package/dist/primitives/MarkdownText.d.ts +1 -1
- package/dist/primitives/MarkdownText.d.ts.map +1 -1
- package/dist/primitives/MarkdownText.js +38 -86
- package/dist/primitives/MarkdownText.js.map +1 -1
- package/package.json +24 -13
- package/src/memoization.tsx +1 -1
- package/src/overrides/CodeBlock.tsx +1 -1
- package/src/overrides/defaultComponents.tsx +1 -1
- package/src/overrides/types.ts +1 -1
- package/dist/memoization.test.d.ts +0 -2
- package/dist/memoization.test.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { MarkdownTextPrimitive, type MarkdownTextPrimitiveProps, } from "./primitives/MarkdownText";
|
|
2
|
-
export type { CodeHeaderProps, SyntaxHighlighterProps, } from "./overrides/types";
|
|
3
|
-
export { useIsMarkdownCodeBlock } from "./overrides/PreOverride";
|
|
4
|
-
export { memoizeMarkdownComponents as unstable_memoizeMarkdownComponents } from "./memoization";
|
|
1
|
+
export { MarkdownTextPrimitive, type MarkdownTextPrimitiveProps, } from "./primitives/MarkdownText.js";
|
|
2
|
+
export type { CodeHeaderProps, SyntaxHighlighterProps, } from "./overrides/types.js";
|
|
3
|
+
export { useIsMarkdownCodeBlock } from "./overrides/PreOverride.js";
|
|
4
|
+
export { memoizeMarkdownComponents as unstable_memoizeMarkdownComponents } from "./memoization.js";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,KAAK,0BAA0B,GAChC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,KAAK,0BAA0B,GAChC,qCAAkC;AAEnC,YAAY,EACV,eAAe,EACf,sBAAsB,GACvB,6BAA0B;AAE3B,OAAO,EAAE,sBAAsB,EAAE,mCAAgC;AACjE,OAAO,EAAE,yBAAyB,IAAI,kCAAkC,EAAE,yBAAsB"}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./primitives/MarkdownText.js";
|
|
5
|
-
import { useIsMarkdownCodeBlock } from "./overrides/PreOverride.js";
|
|
6
|
-
import { memoizeMarkdownComponents } from "./memoization.js";
|
|
7
|
-
export {
|
|
8
|
-
MarkdownTextPrimitive,
|
|
9
|
-
memoizeMarkdownComponents as unstable_memoizeMarkdownComponents,
|
|
10
|
-
useIsMarkdownCodeBlock
|
|
11
|
-
};
|
|
1
|
+
export { MarkdownTextPrimitive, } from "./primitives/MarkdownText.js";
|
|
2
|
+
export { useIsMarkdownCodeBlock } from "./overrides/PreOverride.js";
|
|
3
|
+
export { memoizeMarkdownComponents as unstable_memoizeMarkdownComponents } from "./memoization.js";
|
|
12
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,GAEtB,qCAAkC;AAOnC,OAAO,EAAE,sBAAsB,EAAE,mCAAgC;AACjE,OAAO,EAAE,yBAAyB,IAAI,kCAAkC,EAAE,yBAAsB"}
|
package/dist/memoization.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Element } from "hast";
|
|
1
|
+
import type { Element } from "hast";
|
|
2
2
|
import { ComponentProps, ComponentType, ElementType } from "react";
|
|
3
|
-
import { CodeHeaderProps, SyntaxHighlighterProps } from "./overrides/types";
|
|
3
|
+
import { CodeHeaderProps, SyntaxHighlighterProps } from "./overrides/types.js";
|
|
4
4
|
type Components = {
|
|
5
5
|
[Key in Extract<ElementType, string>]?: ComponentType<ComponentProps<Key>>;
|
|
6
6
|
} & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoization.d.ts","sourceRoot":"","sources":["../src/memoization.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"memoization.d.ts","sourceRoot":"","sources":["../src/memoization.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,WAAW,EAAQ,MAAM,OAAO,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,6BAA0B;AAE5E,KAAK,UAAU,GAAG;KACf,GAAG,IAAI,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;CAC3E,GAAG;IACF,iBAAiB,CAAC,EACd,aAAa,CAAC,IAAI,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC,GACnD,SAAS,CAAC;IACd,UAAU,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;CACvE,CAAC;AAOF,eAAO,MAAM,aAAa,GACxB,MAAM,OAAO,GAAG,SAAS,EACzB,MAAM,OAAO,GAAG,SAAS,YAe1B,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC3B,MAAM;IAAE,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,EACpC,MAAM;IAAE,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,YAGrC,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,aAAY,UAAe;0EAMtB;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE;CAMhE,CAAC"}
|
package/dist/memoization.js
CHANGED
|
@@ -1,36 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { memo } from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const areChildrenEqual = (prev, next) => {
|
|
4
|
+
if (typeof prev === "string")
|
|
5
|
+
return prev === next;
|
|
6
|
+
return JSON.stringify(prev) === JSON.stringify(next);
|
|
7
7
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
export const areNodesEqual = (prev, next) => {
|
|
9
|
+
if (!prev || !next)
|
|
10
|
+
return false;
|
|
11
|
+
const excludeMetadata = (props) => {
|
|
12
|
+
const { position, data, ...rest } = props || {};
|
|
13
|
+
return rest;
|
|
14
|
+
};
|
|
15
|
+
return (JSON.stringify(excludeMetadata(prev.properties)) ===
|
|
16
|
+
JSON.stringify(excludeMetadata(next.properties)) &&
|
|
17
|
+
areChildrenEqual(prev.children, next.children));
|
|
15
18
|
};
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
export const memoCompareNodes = (prev, next) => {
|
|
20
|
+
return areNodesEqual(prev.node, next.node);
|
|
18
21
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
29
|
-
);
|
|
30
|
-
};
|
|
31
|
-
export {
|
|
32
|
-
areNodesEqual,
|
|
33
|
-
memoCompareNodes,
|
|
34
|
-
memoizeMarkdownComponents
|
|
22
|
+
export const memoizeMarkdownComponents = (components = {}) => {
|
|
23
|
+
return Object.fromEntries(Object.entries(components ?? {}).map(([key, value]) => {
|
|
24
|
+
if (!value)
|
|
25
|
+
return [key, value];
|
|
26
|
+
const Component = value;
|
|
27
|
+
const WithoutNode = ({ node, ...props }) => {
|
|
28
|
+
return _jsx(Component, { ...props });
|
|
29
|
+
};
|
|
30
|
+
return [key, memo(WithoutNode, memoCompareNodes)];
|
|
31
|
+
}));
|
|
35
32
|
};
|
|
36
33
|
//# sourceMappingURL=memoization.js.map
|
package/dist/memoization.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"memoization.js","sourceRoot":"","sources":["../src/memoization.tsx"],"names":[],"mappings":";AACA,OAAO,EAA8C,IAAI,EAAE,MAAM,OAAO,CAAC;AAYzE,MAAM,gBAAgB,GAAG,CAAC,IAAsB,EAA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,GAAG,EAAE,KAAK,CAAC,CAAC;QAEhC,MAAM,SAAS,GAAG,KAAsB,CAAC;QACzC,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,EAAE,GAAG,KAAK,EAAsB,EAAE,EAAE;YAC7D,OAAO,KAAC,SAAS,OAAK,KAAK,GAAI,CAAC;QAClC,CAAC,CAAC;QACF,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC,CACH,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentType, FC } from "react";
|
|
2
|
-
import { CodeComponent, CodeHeaderProps, PreComponent, SyntaxHighlighterProps } from "./types";
|
|
3
|
-
import { Element } from "hast";
|
|
2
|
+
import { CodeComponent, CodeHeaderProps, PreComponent, SyntaxHighlighterProps } from "./types.js";
|
|
3
|
+
import type { Element } from "hast";
|
|
4
4
|
export type CodeBlockProps = {
|
|
5
5
|
node: Element | undefined;
|
|
6
6
|
language: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeBlock.d.ts","sourceRoot":"","sources":["../../src/overrides/CodeBlock.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,EAAE,EAAW,MAAM,OAAO,CAAC;AAEnD,OAAO,EACL,aAAa,EACb,eAAe,EACf,YAAY,EACZ,sBAAsB,EACvB,
|
|
1
|
+
{"version":3,"file":"CodeBlock.d.ts","sourceRoot":"","sources":["../../src/overrides/CodeBlock.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,EAAE,EAAW,MAAM,OAAO,CAAC;AAEnD,OAAO,EACL,aAAa,EACb,eAAe,EACf,YAAY,EACZ,sBAAsB,EACvB,mBAAgB;AAEjB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE;QACV,GAAG,EAAE,YAAY,CAAC;QAClB,IAAI,EAAE,aAAa,CAAC;QACpB,UAAU,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;QAC3C,iBAAiB,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;KAC1D,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC,cAAc,CAqB/C,CAAC"}
|
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { DefaultCodeBlockContent } from "./defaultComponents.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
language,
|
|
9
|
-
code
|
|
10
|
-
}) => {
|
|
11
|
-
const components = useMemo(() => ({ Pre, Code }), [Pre, Code]);
|
|
12
|
-
const SH = language ? SyntaxHighlighter : DefaultCodeBlockContent;
|
|
13
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
14
|
-
/* @__PURE__ */ jsx(CodeHeader, { node, language, code }),
|
|
15
|
-
/* @__PURE__ */ jsx(
|
|
16
|
-
SH,
|
|
17
|
-
{
|
|
18
|
-
node,
|
|
19
|
-
components,
|
|
20
|
-
language: language ?? "unknown",
|
|
21
|
-
code
|
|
22
|
-
}
|
|
23
|
-
)
|
|
24
|
-
] });
|
|
25
|
-
};
|
|
26
|
-
export {
|
|
27
|
-
DefaultCodeBlock
|
|
4
|
+
export const DefaultCodeBlock = ({ node, components: { Pre, Code, SyntaxHighlighter, CodeHeader }, language, code, }) => {
|
|
5
|
+
const components = useMemo(() => ({ Pre, Code }), [Pre, Code]);
|
|
6
|
+
const SH = language ? SyntaxHighlighter : DefaultCodeBlockContent;
|
|
7
|
+
return (_jsxs(_Fragment, { children: [_jsx(CodeHeader, { node: node, language: language, code: code }), _jsx(SH, { node: node, components: components, language: language ?? "unknown", code: code })] }));
|
|
28
8
|
};
|
|
29
9
|
//# sourceMappingURL=CodeBlock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/overrides/CodeBlock.tsx"],"
|
|
1
|
+
{"version":3,"file":"CodeBlock.js","sourceRoot":"","sources":["../../src/overrides/CodeBlock.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,OAAO,EAAE,MAAM,OAAO,CAAC;AAQnD,OAAO,EAAE,uBAAuB,EAAE,+BAA4B;AAe9D,MAAM,CAAC,MAAM,gBAAgB,GAAuB,CAAC,EACnD,IAAI,EACJ,UAAU,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,iBAAiB,EAAE,UAAU,EAAE,EACxD,QAAQ,EACR,IAAI,GACL,EAAE,EAAE;IACH,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;IAE/D,MAAM,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,uBAAuB,CAAC;IAElE,OAAO,CACL,8BACE,KAAC,UAAU,IAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,GAAI,EAC1D,KAAC,EAAE,IACD,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,QAAQ,IAAI,SAAS,EAC/B,IAAI,EAAE,IAAI,GACV,IACD,CACJ,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentPropsWithoutRef, ComponentType } from "react";
|
|
2
|
-
import { CodeComponent, CodeHeaderProps, PreComponent, SyntaxHighlighterProps } from "./types";
|
|
2
|
+
import { CodeComponent, CodeHeaderProps, PreComponent, SyntaxHighlighterProps } from "./types.js";
|
|
3
3
|
export type CodeOverrideProps = ComponentPropsWithoutRef<CodeComponent> & {
|
|
4
4
|
components: {
|
|
5
5
|
Pre: PreComponent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeOverride.d.ts","sourceRoot":"","sources":["../../src/overrides/CodeOverride.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,aAAa,EAId,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,aAAa,EACb,eAAe,EACf,YAAY,EACZ,sBAAsB,EACvB,
|
|
1
|
+
{"version":3,"file":"CodeOverride.d.ts","sourceRoot":"","sources":["../../src/overrides/CodeOverride.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,aAAa,EAId,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,aAAa,EACb,eAAe,EACf,YAAY,EACZ,sBAAsB,EACvB,mBAAgB;AAiEjB,MAAM,MAAM,iBAAiB,GAAG,wBAAwB,CAAC,aAAa,CAAC,GAAG;IACxE,UAAU,EAAE;QACV,GAAG,EAAE,YAAY,CAAC;QAClB,IAAI,EAAE,aAAa,CAAC;QACpB,UAAU,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;QAC3C,iBAAiB,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;KAC1D,CAAC;IACF,oBAAoB,CAAC,EACjB,MAAM,CACJ,MAAM,EACN;QACE,UAAU,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;QAC5C,iBAAiB,CAAC,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;KAC3D,CACF,GACD,SAAS,CAAC;CACf,CAAC;AAoBF,eAAO,MAAM,YAAY,yDAMvB,CAAC"}
|
|
@@ -1,83 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
memo,
|
|
4
|
-
useContext
|
|
5
|
-
} from "react";
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useContext, } from "react";
|
|
6
3
|
import { PreContext, useIsMarkdownCodeBlock } from "./PreOverride.js";
|
|
7
4
|
import { DefaultCodeBlock } from "./CodeBlock.js";
|
|
8
5
|
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
|
|
9
6
|
import { withDefaultProps } from "./withDefaults.js";
|
|
10
7
|
import { DefaultCodeBlockContent } from "./defaultComponents.js";
|
|
11
8
|
import { memoCompareNodes } from "../memoization.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Code,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
children,
|
|
23
|
-
...codeProps
|
|
24
|
-
}) => {
|
|
25
|
-
const preProps = useContext(PreContext);
|
|
26
|
-
const getPreProps = withDefaultProps(preProps);
|
|
27
|
-
const WrappedPre = useCallbackRef((props) => /* @__PURE__ */ jsx(Pre, { ...getPreProps(props) }));
|
|
28
|
-
const getCodeProps = withDefaultProps(codeProps);
|
|
29
|
-
const WrappedCode = useCallbackRef((props) => /* @__PURE__ */ jsx(Code, { ...getCodeProps(props) }));
|
|
30
|
-
const language = /language-(\w+)/.exec(codeProps.className || "")?.[1] ?? "";
|
|
31
|
-
if (typeof children !== "string") {
|
|
32
|
-
return /* @__PURE__ */ jsx(
|
|
33
|
-
DefaultCodeBlockContent,
|
|
34
|
-
{
|
|
35
|
-
node,
|
|
36
|
-
components: { Pre: WrappedPre, Code: WrappedCode },
|
|
37
|
-
code: children
|
|
38
|
-
}
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
const SyntaxHighlighter = componentsByLanguage[language]?.SyntaxHighlighter ?? FallbackSyntaxHighlighter;
|
|
42
|
-
const CodeHeader = componentsByLanguage[language]?.CodeHeader ?? FallbackCodeHeader;
|
|
43
|
-
return /* @__PURE__ */ jsx(
|
|
44
|
-
DefaultCodeBlock,
|
|
45
|
-
{
|
|
46
|
-
node,
|
|
47
|
-
components: {
|
|
48
|
-
Pre: WrappedPre,
|
|
49
|
-
Code: WrappedCode,
|
|
50
|
-
SyntaxHighlighter,
|
|
51
|
-
CodeHeader
|
|
52
|
-
},
|
|
53
|
-
language: language || "unknown",
|
|
54
|
-
code: children
|
|
9
|
+
const CodeBlockOverride = ({ node, components: { Pre, Code, SyntaxHighlighter: FallbackSyntaxHighlighter, CodeHeader: FallbackCodeHeader, }, componentsByLanguage = {}, children, ...codeProps }) => {
|
|
10
|
+
const preProps = useContext(PreContext);
|
|
11
|
+
const getPreProps = withDefaultProps(preProps);
|
|
12
|
+
const WrappedPre = useCallbackRef((props) => (_jsx(Pre, { ...getPreProps(props) })));
|
|
13
|
+
const getCodeProps = withDefaultProps(codeProps);
|
|
14
|
+
const WrappedCode = useCallbackRef((props) => (_jsx(Code, { ...getCodeProps(props) })));
|
|
15
|
+
const language = /language-(\w+)/.exec(codeProps.className || "")?.[1] ?? "";
|
|
16
|
+
// if the code content is not string (due to rehype plugins), return a default code block
|
|
17
|
+
if (typeof children !== "string") {
|
|
18
|
+
return (_jsx(DefaultCodeBlockContent, { node: node, components: { Pre: WrappedPre, Code: WrappedCode }, code: children }));
|
|
55
19
|
}
|
|
56
|
-
|
|
20
|
+
const SyntaxHighlighter = componentsByLanguage[language]?.SyntaxHighlighter ??
|
|
21
|
+
FallbackSyntaxHighlighter;
|
|
22
|
+
const CodeHeader = componentsByLanguage[language]?.CodeHeader ?? FallbackCodeHeader;
|
|
23
|
+
return (_jsx(DefaultCodeBlock, { node: node, components: {
|
|
24
|
+
Pre: WrappedPre,
|
|
25
|
+
Code: WrappedCode,
|
|
26
|
+
SyntaxHighlighter,
|
|
27
|
+
CodeHeader,
|
|
28
|
+
}, language: language || "unknown", code: children }));
|
|
57
29
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}) => {
|
|
64
|
-
const isCodeBlock = useIsMarkdownCodeBlock();
|
|
65
|
-
if (!isCodeBlock) return /* @__PURE__ */ jsx(components.Code, { ...props });
|
|
66
|
-
return /* @__PURE__ */ jsx(
|
|
67
|
-
CodeBlockOverride,
|
|
68
|
-
{
|
|
69
|
-
node,
|
|
70
|
-
components,
|
|
71
|
-
componentsByLanguage,
|
|
72
|
-
...props
|
|
73
|
-
}
|
|
74
|
-
);
|
|
30
|
+
const CodeOverrideImpl = ({ node, components, componentsByLanguage, ...props }) => {
|
|
31
|
+
const isCodeBlock = useIsMarkdownCodeBlock();
|
|
32
|
+
if (!isCodeBlock)
|
|
33
|
+
return _jsx(components.Code, { ...props });
|
|
34
|
+
return (_jsx(CodeBlockOverride, { node: node, components: components, componentsByLanguage: componentsByLanguage, ...props }));
|
|
75
35
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
36
|
+
export const CodeOverride = memo(CodeOverrideImpl, (prev, next) => {
|
|
37
|
+
const isEqual = prev.components === next.components &&
|
|
38
|
+
prev.componentsByLanguage === next.componentsByLanguage &&
|
|
39
|
+
memoCompareNodes(prev, next);
|
|
40
|
+
return isEqual;
|
|
79
41
|
});
|
|
80
|
-
export {
|
|
81
|
-
CodeOverride
|
|
82
|
-
};
|
|
83
42
|
//# sourceMappingURL=CodeOverride.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"CodeOverride.js","sourceRoot":"","sources":["../../src/overrides/CodeOverride.tsx"],"names":[],"mappings":";AAAA,OAAO,EAIL,IAAI,EACJ,UAAU,GACX,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,yBAAsB;AAOnE,OAAO,EAAE,gBAAgB,EAAE,uBAAoB;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,0BAAuB;AAClD,OA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oBAAoB,CAAC,QAAQ,CAAC,EAAE,UAAU,IAAI,kBAAkB,CAAC;IAEnE,OAAO,CACL,KAAC,gBAAgB,IACf,IAAI,EAAE,IAAI,EACV,UAAU,EAAE;YACV,GAAG,EAAE,UAAU;YACf,IAAI,EAAE,WAAW;YACjB,iBAAiB;YACjB,UAAU;SACX,EACD,QAAQ,EAAE,QAAQ,IAAI,SAAS,EAC/B,IAAI,EAAE,QAAQ,GACd,CACH,CAAC;AACJ,CAAC,CAAC;AAoBF,MAAM,gBAAgB,GAA0B,CAAC,EAC/C,IAAI,EACJ,UAAU,EACV,oBAAoB,EACpB,GAAG,KAAK,EACT,EAAE,EAAE;IACH,MAAM,WAAW,GAAG,sBAAsB,EAAE,CAAC;IAC7C,IAAI,CAAC,WAAW;QAAE,OAAO,KAAC,UAAU,CAAC,IAAI,OAAK,KAAK,GAAI,CAAC;IACxD,OAAO,CACL,KAAC,iBAAiB,IAChB,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,UAAU,EACtB,oBAAoB,EAAE,oBAAoB,KACtC,KAAK,GACT,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;IAChE,MAAM,OAAO,GACX,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU;QACnC,IAAI,CAAC,oBAAoB,KAAK,IAAI,CAAC,oBAAoB;QACvD,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/B,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC,CAAC"}
|
|
@@ -1,24 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
createContext,
|
|
6
|
-
useContext,
|
|
7
|
-
memo
|
|
8
|
-
} from "react";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, memo, } from "react";
|
|
9
4
|
import { memoCompareNodes } from "../memoization.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return useContext(PreContext) !== null;
|
|
5
|
+
export const PreContext = createContext(null);
|
|
6
|
+
export const useIsMarkdownCodeBlock = () => {
|
|
7
|
+
return useContext(PreContext) !== null;
|
|
14
8
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
var PreOverride = memo(PreOverrideImpl, memoCompareNodes);
|
|
19
|
-
export {
|
|
20
|
-
PreContext,
|
|
21
|
-
PreOverride,
|
|
22
|
-
useIsMarkdownCodeBlock
|
|
9
|
+
const PreOverrideImpl = ({ children, ...rest }) => {
|
|
10
|
+
return _jsx(PreContext.Provider, { value: rest, children: children });
|
|
23
11
|
};
|
|
12
|
+
export const PreOverride = memo(PreOverrideImpl, memoCompareNodes);
|
|
24
13
|
//# sourceMappingURL=PreOverride.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/overrides/PreOverride.tsx"],"
|
|
1
|
+
{"version":3,"file":"PreOverride.js","sourceRoot":"","sources":["../../src/overrides/PreOverride.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,aAAa,EAEb,UAAU,EACV,IAAI,GACL,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,gBAAgB,EAAE,0BAAuB;AAElD,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAG7B,IAAI,CAAC,CAAC;AAEhB,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,OAAO,UAAU,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;AACzC,CAAC,CAAC;AAEF,MAAM,eAAe,GAAiB,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE;IAC9D,OAAO,KAAC,UAAU,CAAC,QAAQ,IAAC,KAAK,EAAE,IAAI,YAAG,QAAQ,GAAuB,CAAC;AAC5E,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ComponentType, ReactNode } from "react";
|
|
2
|
-
import { PreComponent, CodeComponent, CodeHeaderProps } from "./types";
|
|
3
|
-
import { Element } from "hast";
|
|
2
|
+
import { PreComponent, CodeComponent, CodeHeaderProps } from "./types.js";
|
|
3
|
+
import type { Element } from "hast";
|
|
4
4
|
export declare const DefaultPre: PreComponent;
|
|
5
5
|
export declare const DefaultCode: CodeComponent;
|
|
6
6
|
export declare const DefaultCodeBlockContent: ComponentType<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultComponents.d.ts","sourceRoot":"","sources":["../../src/overrides/defaultComponents.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"defaultComponents.d.ts","sourceRoot":"","sources":["../../src/overrides/defaultComponents.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,mBAAgB;AACvE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,eAAO,MAAM,UAAU,EAAE,YAExB,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,aAEzB,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,aAAa,CAAC;IAClD,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B,UAAU,EAAE;QAAE,GAAG,EAAE,YAAY,CAAC;QAAC,IAAI,EAAE,aAAa,CAAA;KAAE,CAAC;IACvD,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;CACtC,CAIA,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAAC,eAAe,CAAc,CAAC"}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var DefaultCodeHeader = () => null;
|
|
7
|
-
export {
|
|
8
|
-
DefaultCode,
|
|
9
|
-
DefaultCodeBlockContent,
|
|
10
|
-
DefaultCodeHeader,
|
|
11
|
-
DefaultPre
|
|
12
|
-
};
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export const DefaultPre = ({ node, ...rest }) => (_jsx("pre", { ...rest }));
|
|
3
|
+
export const DefaultCode = ({ node, ...rest }) => (_jsx("code", { ...rest }));
|
|
4
|
+
export const DefaultCodeBlockContent = ({ node, components: { Pre, Code }, code }) => (_jsx(Pre, { children: _jsx(Code, { node: node, children: code }) }));
|
|
5
|
+
export const DefaultCodeHeader = () => null;
|
|
13
6
|
//# sourceMappingURL=defaultComponents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/overrides/defaultComponents.tsx"],"
|
|
1
|
+
{"version":3,"file":"defaultComponents.js","sourceRoot":"","sources":["../../src/overrides/defaultComponents.tsx"],"names":[],"mappings":";AAIA,MAAM,CAAC,MAAM,UAAU,GAAiB,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,CAC7D,iBAAS,IAAI,GAAI,CAClB,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAkB,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,CAC/D,kBAAU,IAAI,GAAI,CACnB,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAI/B,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAClD,KAAC,GAAG,cACF,KAAC,IAAI,IAAC,IAAI,EAAE,IAAI,YAAG,IAAI,GAAQ,GAC3B,CACP,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAmC,GAAG,EAAE,CAAC,IAAI,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/overrides/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/overrides/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEhE,MAAM,MAAM,YAAY,GAAG,aAAa,CACtC,wBAAwB,CAAC,KAAK,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,CACjE,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,aAAa,CACvC,wBAAwB,CAAC,MAAM,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,CAClE,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,UAAU,EAAE;QACV,GAAG,EAAE,YAAY,CAAC;QAClB,IAAI,EAAE,aAAa,CAAC;KACrB,CAAC;IACF,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
|
package/dist/overrides/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/overrides/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
// src/overrides/withDefaults.tsx
|
|
2
1
|
import classNames from "classnames";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
...defaultProps,
|
|
10
|
-
...props
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
export {
|
|
14
|
-
withDefaultProps
|
|
2
|
+
export const withDefaultProps = ({ className, ...defaultProps }) => ({ className: classNameProp, ...props }) => {
|
|
3
|
+
return {
|
|
4
|
+
className: classNames(className, classNameProp),
|
|
5
|
+
...defaultProps,
|
|
6
|
+
...props,
|
|
7
|
+
};
|
|
15
8
|
};
|
|
16
9
|
//# sourceMappingURL=withDefaults.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/overrides/withDefaults.tsx"],"
|
|
1
|
+
{"version":3,"file":"withDefaults.js","sourceRoot":"","sources":["../../src/overrides/withDefaults.tsx"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,MAAM,CAAC,MAAM,gBAAgB,GAC3B,CAAoD,EAClD,SAAS,EACT,GAAG,YAAY,EACC,EAAE,EAAE,CACtB,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,KAAK,EAAU,EAAE,EAAE;IACjD,OAAO;QACL,SAAS,EAAE,UAAU,CAAC,SAAS,EAAE,aAAa,CAAC;QAC/C,GAAG,YAAY;QACf,GAAG,KAAK;KACC,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ElementType, ForwardRefExoticComponent, RefAttributes, type ComponentPropsWithoutRef, type ComponentType } from "react";
|
|
2
2
|
import { type Options } from "react-markdown";
|
|
3
|
-
import { SyntaxHighlighterProps, CodeHeaderProps } from "../overrides/types";
|
|
3
|
+
import { SyntaxHighlighterProps, CodeHeaderProps } from "../overrides/types.js";
|
|
4
4
|
import { Primitive } from "@radix-ui/react-primitive";
|
|
5
5
|
type PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;
|
|
6
6
|
export type MarkdownTextPrimitiveProps = Omit<Options, "components" | "children"> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownText.d.ts","sourceRoot":"","sources":["../../src/primitives/MarkdownText.tsx"],"names":[],"mappings":"AAGA,OAAO,EAEL,WAAW,EAGX,yBAAyB,EACzB,aAAa,EAEb,KAAK,wBAAwB,EAC7B,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AACf,OAAsB,EAAE,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"MarkdownText.d.ts","sourceRoot":"","sources":["../../src/primitives/MarkdownText.tsx"],"names":[],"mappings":"AAGA,OAAO,EAEL,WAAW,EAGX,yBAAyB,EACzB,aAAa,EAEb,KAAK,wBAAwB,EAC7B,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AACf,OAAsB,EAAE,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,8BAA2B;AAU7E,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAMtD,KAAK,iBAAiB,GAAG,wBAAwB,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;AAExE,MAAM,MAAM,0BAA0B,GAAG,IAAI,CAC3C,OAAO,EACP,YAAY,GAAG,UAAU,CAC1B,GAAG;IACF,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,cAAc,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,UAAU,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;IAC7E,kBAAkB,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAC7C,UAAU,CAAC,EACP,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,GAAG;QACpC,iBAAiB,CAAC,EAAE,aAAa,CAAC,sBAAsB,CAAC,GAAG,SAAS,CAAC;QACtE,UAAU,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,GAAG,SAAS,CAAC;KACzD,CAAC,GACF,SAAS,CAAC;IACd;;;OAGG;IACH,oBAAoB,CAAC,EACjB,MAAM,CACJ,MAAM,EACN;QACE,UAAU,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,GAAG,SAAS,CAAC;QACxD,iBAAiB,CAAC,EAAE,aAAa,CAAC,sBAAsB,CAAC,GAAG,SAAS,CAAC;KACvE,CACF,GACD,SAAS,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B;;OAEG;IACH,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACvC,CAAC;AA2FF,eAAO,MAAM,qBAAqB,uFAEjC,CAAC"}
|
|
@@ -1,97 +1,49 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
// src/primitives/MarkdownText.tsx
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
3
|
import { INTERNAL, useMessagePartText } from "@assistant-ui/react";
|
|
5
|
-
import {
|
|
6
|
-
forwardRef,
|
|
7
|
-
useMemo
|
|
8
|
-
} from "react";
|
|
4
|
+
import { forwardRef, useMemo, } from "react";
|
|
9
5
|
import ReactMarkdown from "react-markdown";
|
|
10
6
|
import { PreOverride } from "../overrides/PreOverride.js";
|
|
11
|
-
import {
|
|
12
|
-
DefaultPre,
|
|
13
|
-
DefaultCode,
|
|
14
|
-
DefaultCodeBlockContent,
|
|
15
|
-
DefaultCodeHeader
|
|
16
|
-
} from "../overrides/defaultComponents.js";
|
|
7
|
+
import { DefaultPre, DefaultCode, DefaultCodeBlockContent, DefaultCodeHeader, } from "../overrides/defaultComponents.js";
|
|
17
8
|
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
|
|
18
9
|
import { CodeOverride } from "../overrides/CodeOverride.js";
|
|
19
10
|
import classNames from "classnames";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
code
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
};
|
|
51
|
-
}, [pre, code, SyntaxHighlighter, CodeHeader]);
|
|
52
|
-
const CodeComponent = useCallbackRef((props) => /* @__PURE__ */ jsx(
|
|
53
|
-
CodeOverride,
|
|
54
|
-
{
|
|
55
|
-
components: useCodeOverrideComponents,
|
|
56
|
-
componentsByLanguage,
|
|
57
|
-
...props
|
|
58
|
-
}
|
|
59
|
-
));
|
|
60
|
-
const components = useMemo(() => {
|
|
61
|
-
const { pre: pre2, code: code2, SyntaxHighlighter: SyntaxHighlighter2, CodeHeader: CodeHeader2, ...componentsRest } = userComponents ?? {};
|
|
62
|
-
return {
|
|
63
|
-
...componentsRest,
|
|
64
|
-
pre: PreOverride,
|
|
65
|
-
code: CodeComponent
|
|
66
|
-
};
|
|
67
|
-
}, [CodeComponent, userComponents]);
|
|
68
|
-
return /* @__PURE__ */ jsx(ReactMarkdown, { components, ...rest, children: text });
|
|
11
|
+
const { useSmooth, useSmoothStatus, withSmoothContextProvider } = INTERNAL;
|
|
12
|
+
const MarkdownTextInner = ({ components: userComponents, componentsByLanguage, smooth = true, preprocess, ...rest }) => {
|
|
13
|
+
const messagePartText = useMessagePartText();
|
|
14
|
+
const processedMessagePart = useMemo(() => {
|
|
15
|
+
if (!preprocess)
|
|
16
|
+
return messagePartText;
|
|
17
|
+
return {
|
|
18
|
+
...messagePartText,
|
|
19
|
+
text: preprocess(messagePartText.text),
|
|
20
|
+
};
|
|
21
|
+
}, [messagePartText, preprocess]);
|
|
22
|
+
const { text } = useSmooth(processedMessagePart, smooth);
|
|
23
|
+
const { pre = DefaultPre, code = DefaultCode, SyntaxHighlighter = DefaultCodeBlockContent, CodeHeader = DefaultCodeHeader, } = userComponents ?? {};
|
|
24
|
+
const useCodeOverrideComponents = useMemo(() => {
|
|
25
|
+
return {
|
|
26
|
+
Pre: pre,
|
|
27
|
+
Code: code,
|
|
28
|
+
SyntaxHighlighter,
|
|
29
|
+
CodeHeader,
|
|
30
|
+
};
|
|
31
|
+
}, [pre, code, SyntaxHighlighter, CodeHeader]);
|
|
32
|
+
const CodeComponent = useCallbackRef((props) => (_jsx(CodeOverride, { components: useCodeOverrideComponents, componentsByLanguage: componentsByLanguage, ...props })));
|
|
33
|
+
const components = useMemo(() => {
|
|
34
|
+
const { pre, code, SyntaxHighlighter, CodeHeader, ...componentsRest } = userComponents ?? {};
|
|
35
|
+
return {
|
|
36
|
+
...componentsRest,
|
|
37
|
+
pre: PreOverride,
|
|
38
|
+
code: CodeComponent,
|
|
39
|
+
};
|
|
40
|
+
}, [CodeComponent, userComponents]);
|
|
41
|
+
return (_jsx(ReactMarkdown, { components: components, ...rest, children: text }));
|
|
69
42
|
};
|
|
70
|
-
|
|
71
|
-
({
|
|
72
|
-
className,
|
|
73
|
-
containerProps,
|
|
74
|
-
containerComponent: Container = "div",
|
|
75
|
-
...rest
|
|
76
|
-
}, forwardedRef) => {
|
|
43
|
+
const MarkdownTextPrimitiveImpl = forwardRef(({ className, containerProps, containerComponent: Container = "div", ...rest }, forwardedRef) => {
|
|
77
44
|
const status = useSmoothStatus();
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
{
|
|
81
|
-
"data-status": status.type,
|
|
82
|
-
...containerProps,
|
|
83
|
-
className: classNames(className, containerProps?.className),
|
|
84
|
-
ref: forwardedRef,
|
|
85
|
-
children: /* @__PURE__ */ jsx(MarkdownTextInner, { ...rest })
|
|
86
|
-
}
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
);
|
|
45
|
+
return (_jsx(Container, { "data-status": status.type, ...containerProps, className: classNames(className, containerProps?.className), ref: forwardedRef, children: _jsx(MarkdownTextInner, { ...rest }) }));
|
|
46
|
+
});
|
|
90
47
|
MarkdownTextPrimitiveImpl.displayName = "MarkdownTextPrimitive";
|
|
91
|
-
|
|
92
|
-
MarkdownTextPrimitiveImpl
|
|
93
|
-
);
|
|
94
|
-
export {
|
|
95
|
-
MarkdownTextPrimitive
|
|
96
|
-
};
|
|
48
|
+
export const MarkdownTextPrimitive = withSmoothContextProvider(MarkdownTextPrimitiveImpl);
|
|
97
49
|
//# sourceMappingURL=MarkdownText.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/primitives/MarkdownText.tsx"],"
|
|
1
|
+
{"version":3,"file":"MarkdownText.js","sourceRoot":"","sources":["../../src/primitives/MarkdownText.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAIL,UAAU,EAGV,OAAO,GAGR,MAAM,OAAO,CAAC;AACf,OAAO,aAA+B,MAAM,gBAAgB,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,oCAAiC;AACvD,OAAO,EACL,UAAU,EACV,WAAW,EACX,uBAAuB,EACvB,iBAAiB,GAClB,0CAAuC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,qCAAkC;AAEzD,OAAO,UAA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QACrD,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,iBAAiB,EAAE,UAAU,EAAE,GAAG,cAAc,EAAE,GACnE,cAAc,IAAI,EAAE,CAAC;QACvB,OAAO;YACL,GAAG,cAAc;YACjB,GAAG,EAAE,WAAW;YAChB,IAAI,EAAE,aAAa;SACpB,CAAC;IACJ,CAAC,EAAE,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC,CAAC;IAEpC,OAAO,CACL,KAAC,aAAa,IAAC,UAAU,EAAE,UAAU,KAAM,IAAI,YAC5C,IAAI,GACS,CACjB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,yBAAyB,GACiB,UAAU,CAIxD,CACE,EACE,SAAS,EACT,cAAc,EACd,kBAAkB,EAAE,SAAS,GAAG,KAAK,EACrC,GAAG,IAAI,EACR,EACD,YAAY,EACZ,EAAE;IACF,MAAM,MAAM,GAAG,eAAe,EAAE,CAAC;IACjC,OAAO,CACL,KAAC,SAAS,mBACK,MAAM,CAAC,IAAI,KACpB,cAAc,EAClB,SAAS,EAAE,UAAU,CAAC,SAAS,EAAE,cAAc,EAAE,SAAS,CAAC,EAC3D,GAAG,EAAE,YAAY,YAEjB,KAAC,iBAAiB,OAAK,IAAI,GAAsB,GACvC,CACb,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,yBAAyB,CAAC,WAAW,GAAG,uBAAuB,CAAC;AAEhE,MAAM,CAAC,MAAM,qBAAqB,GAAG,yBAAyB,CAC5D,yBAAyB,CAC1B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/react-markdown",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.10",
|
|
4
|
+
"description": "Markdown rendering for assistant-ui",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"markdown",
|
|
7
|
+
"react-markdown",
|
|
8
|
+
"assistant-ui",
|
|
9
|
+
"react",
|
|
10
|
+
"ai",
|
|
11
|
+
"chat",
|
|
12
|
+
"rendering"
|
|
13
|
+
],
|
|
14
|
+
"author": "AgentbaseAI Inc.",
|
|
4
15
|
"license": "MIT",
|
|
5
16
|
"type": "module",
|
|
6
17
|
"exports": {
|
|
7
18
|
".": {
|
|
19
|
+
"aui-source": "./src/index.ts",
|
|
8
20
|
"types": "./dist/index.d.ts",
|
|
9
21
|
"default": "./dist/index.js"
|
|
10
22
|
},
|
|
@@ -12,7 +24,6 @@
|
|
|
12
24
|
"default": "./styles/dot.css"
|
|
13
25
|
}
|
|
14
26
|
},
|
|
15
|
-
"source": "./src/index.ts",
|
|
16
27
|
"main": "./dist/index.js",
|
|
17
28
|
"types": "./dist/index.d.ts",
|
|
18
29
|
"files": [
|
|
@@ -25,14 +36,13 @@
|
|
|
25
36
|
"dependencies": {
|
|
26
37
|
"@radix-ui/react-primitive": "^2.1.4",
|
|
27
38
|
"@radix-ui/react-use-callback-ref": "^1.1.1",
|
|
28
|
-
"@types/hast": "^3.0.4",
|
|
29
39
|
"classnames": "^2.5.1",
|
|
30
40
|
"react-markdown": "^10.1.0"
|
|
31
41
|
},
|
|
32
42
|
"peerDependencies": {
|
|
33
|
-
"@assistant-ui/react": "^0.11.
|
|
43
|
+
"@assistant-ui/react": "^0.11.58",
|
|
34
44
|
"@types/react": "*",
|
|
35
|
-
"react": "^18 || ^19
|
|
45
|
+
"react": "^18 || ^19"
|
|
36
46
|
},
|
|
37
47
|
"peerDependenciesMeta": {
|
|
38
48
|
"@types/react": {
|
|
@@ -40,12 +50,12 @@
|
|
|
40
50
|
}
|
|
41
51
|
},
|
|
42
52
|
"devDependencies": {
|
|
43
|
-
"@types/
|
|
44
|
-
"react": "19.2.
|
|
45
|
-
"react
|
|
46
|
-
"
|
|
47
|
-
"vitest": "^4.0.
|
|
48
|
-
"@assistant-ui/react": "0.11.
|
|
53
|
+
"@types/hast": "^3.0.4",
|
|
54
|
+
"@types/react": "^19.2.9",
|
|
55
|
+
"react": "^19.2.3",
|
|
56
|
+
"react-dom": "^19.2.3",
|
|
57
|
+
"vitest": "^4.0.17",
|
|
58
|
+
"@assistant-ui/react": "0.11.58",
|
|
49
59
|
"@assistant-ui/x-buildutils": "0.0.1"
|
|
50
60
|
},
|
|
51
61
|
"publishConfig": {
|
|
@@ -55,13 +65,14 @@
|
|
|
55
65
|
"homepage": "https://www.assistant-ui.com/",
|
|
56
66
|
"repository": {
|
|
57
67
|
"type": "git",
|
|
58
|
-
"url": "https://github.com/assistant-ui/assistant-ui
|
|
68
|
+
"url": "git+https://github.com/assistant-ui/assistant-ui.git",
|
|
69
|
+
"directory": "packages/react-markdown"
|
|
59
70
|
},
|
|
60
71
|
"bugs": {
|
|
61
72
|
"url": "https://github.com/assistant-ui/assistant-ui/issues"
|
|
62
73
|
},
|
|
63
74
|
"scripts": {
|
|
64
|
-
"build": "
|
|
75
|
+
"build": "aui-build",
|
|
65
76
|
"test": "vitest run",
|
|
66
77
|
"test:watch": "vitest"
|
|
67
78
|
}
|
package/src/memoization.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ComponentType, ReactNode } from "react";
|
|
2
2
|
import { PreComponent, CodeComponent, CodeHeaderProps } from "./types";
|
|
3
|
-
import { Element } from "hast";
|
|
3
|
+
import type { Element } from "hast";
|
|
4
4
|
|
|
5
5
|
export const DefaultPre: PreComponent = ({ node, ...rest }) => (
|
|
6
6
|
<pre {...rest} />
|
package/src/overrides/types.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memoization.test.d.ts","sourceRoot":"","sources":["../src/memoization.test.tsx"],"names":[],"mappings":""}
|