@promptbook/components 0.112.0-101 → 0.112.0-103
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/esm/index.es.js +39 -4
- package/esm/index.es.js.map +1 -1
- package/esm/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +1 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +39 -4
- package/umd/index.umd.js.map +1 -1
- package/umd/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +1 -0
- package/umd/src/version.d.ts +1 -1
package/esm/index.es.js
CHANGED
|
@@ -42,7 +42,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
42
42
|
* @generated
|
|
43
43
|
* @see https://github.com/webgptorg/promptbook
|
|
44
44
|
*/
|
|
45
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
45
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-103';
|
|
46
46
|
/**
|
|
47
47
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
48
48
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -22187,6 +22187,23 @@ styleInject(css_248z$b);
|
|
|
22187
22187
|
* @private utility of `MarkdownContent` component
|
|
22188
22188
|
*/
|
|
22189
22189
|
const DETAILS_SUMMARY_SELECTOR = 'summary';
|
|
22190
|
+
/**
|
|
22191
|
+
* Resolves the active document theme when a host application does not pass an explicit theme.
|
|
22192
|
+
*
|
|
22193
|
+
* @private utility of `MarkdownContent` component
|
|
22194
|
+
*/
|
|
22195
|
+
function resolveMarkdownContentTheme(explicitTheme) {
|
|
22196
|
+
if (explicitTheme) {
|
|
22197
|
+
return explicitTheme;
|
|
22198
|
+
}
|
|
22199
|
+
if (typeof document !== 'undefined') {
|
|
22200
|
+
const resolvedTheme = document.documentElement.dataset.themeResolved;
|
|
22201
|
+
if (resolvedTheme === 'dark' || document.documentElement.classList.contains('dark')) {
|
|
22202
|
+
return 'DARK';
|
|
22203
|
+
}
|
|
22204
|
+
}
|
|
22205
|
+
return 'LIGHT';
|
|
22206
|
+
}
|
|
22190
22207
|
/**
|
|
22191
22208
|
* Returns a stable key for a `<details>` element based on its `<summary>` text.
|
|
22192
22209
|
* Used to identify and restore open state across re-renders.
|
|
@@ -22242,16 +22259,34 @@ function resolveClickedDetailsElement(target, container) {
|
|
|
22242
22259
|
* @public exported from `@promptbook/components`
|
|
22243
22260
|
*/
|
|
22244
22261
|
const MarkdownContent = memo(function MarkdownContent(props) {
|
|
22245
|
-
const { content, className, onCreateAgent } = props;
|
|
22262
|
+
const { content, className, onCreateAgent, theme } = props;
|
|
22246
22263
|
const htmlContent = useMemo(() => renderMarkdown(content, {
|
|
22247
22264
|
citationReferenceClassName: styles$b.citationRef,
|
|
22248
22265
|
}), [content]);
|
|
22266
|
+
const [resolvedTheme, setResolvedTheme] = useState(() => resolveMarkdownContentTheme(theme));
|
|
22249
22267
|
const containerRef = useRef(null);
|
|
22250
22268
|
const rootsRef = useRef([]);
|
|
22251
22269
|
/** Tracks which `<details>` elements (by summary key) are currently open */
|
|
22252
22270
|
const openDetailsKeysRef = useRef(new Set());
|
|
22253
22271
|
const onCreateAgentRef = useRef(onCreateAgent);
|
|
22254
22272
|
onCreateAgentRef.current = onCreateAgent;
|
|
22273
|
+
useEffect(() => {
|
|
22274
|
+
if (theme) {
|
|
22275
|
+
setResolvedTheme(theme);
|
|
22276
|
+
return;
|
|
22277
|
+
}
|
|
22278
|
+
const updateTheme = () => setResolvedTheme(resolveMarkdownContentTheme());
|
|
22279
|
+
updateTheme();
|
|
22280
|
+
if (typeof document === 'undefined' || typeof MutationObserver === 'undefined') {
|
|
22281
|
+
return;
|
|
22282
|
+
}
|
|
22283
|
+
const observer = new MutationObserver(updateTheme);
|
|
22284
|
+
observer.observe(document.documentElement, {
|
|
22285
|
+
attributes: true,
|
|
22286
|
+
attributeFilter: ['class', 'data-theme-resolved'],
|
|
22287
|
+
});
|
|
22288
|
+
return () => observer.disconnect();
|
|
22289
|
+
}, [theme]);
|
|
22255
22290
|
useEffect(() => {
|
|
22256
22291
|
// Cleanup previous roots
|
|
22257
22292
|
rootsRef.current.forEach((root) => root.unmount());
|
|
@@ -22324,7 +22359,7 @@ const MarkdownContent = memo(function MarkdownContent(props) {
|
|
|
22324
22359
|
pre.appendChild(mountPoint);
|
|
22325
22360
|
// Render CodeBlock
|
|
22326
22361
|
const root = createRoot(mountPoint);
|
|
22327
|
-
root.render(jsx(CodeBlock, { code: code, language: language, onCreateAgent: onCreateAgentRef.current }));
|
|
22362
|
+
root.render(jsx(CodeBlock, { code: code, language: language, onCreateAgent: onCreateAgentRef.current, theme: resolvedTheme }));
|
|
22328
22363
|
rootsRef.current.push(root);
|
|
22329
22364
|
});
|
|
22330
22365
|
return () => {
|
|
@@ -22335,7 +22370,7 @@ const MarkdownContent = memo(function MarkdownContent(props) {
|
|
|
22335
22370
|
rootsRef.current.forEach((root) => root.unmount());
|
|
22336
22371
|
rootsRef.current = [];
|
|
22337
22372
|
};
|
|
22338
|
-
}, [htmlContent]);
|
|
22373
|
+
}, [htmlContent, resolvedTheme]);
|
|
22339
22374
|
return (jsx("div", { ref: containerRef, className: classNames(styles$b.MarkdownContent, className), dangerouslySetInnerHTML: {
|
|
22340
22375
|
__html: htmlContent,
|
|
22341
22376
|
} }));
|