Add way to pass fonts
This commit is contained in:
parent
c516cf0894
commit
6397ec1511
1 changed files with 323 additions and 4 deletions
|
|
@ -5,6 +5,7 @@ import {
|
|||
App,
|
||||
PostMessageTransport,
|
||||
applyHostStyleVariables,
|
||||
applyHostFonts,
|
||||
applyDocumentTheme,
|
||||
} from "@modelcontextprotocol/ext-apps";
|
||||
import { Chart, registerables } from "chart.js";
|
||||
|
|
@ -448,7 +449,7 @@ applyDocumentTheme(systemDark ? "dark" : "light");
|
|||
// Register handlers and connect
|
||||
app.onerror = log.error;
|
||||
|
||||
// Handle host context changes (theme and styles from host)
|
||||
// Handle host context changes (theme, styles, and fonts from host)
|
||||
app.onhostcontextchanged = (params) => {
|
||||
if (params.theme) {
|
||||
applyDocumentTheme(params.theme);
|
||||
|
|
@ -456,6 +457,9 @@ app.onhostcontextchanged = (params) => {
|
|||
if (params.styles?.variables) {
|
||||
applyHostStyleVariables(params.styles.variables);
|
||||
}
|
||||
if (params.styles?.css?.fonts) {
|
||||
applyHostFonts(params.styles.css.fonts);
|
||||
}
|
||||
// Recreate chart to pick up new colors
|
||||
if (state.chart && (params.theme || params.styles?.variables)) {
|
||||
state.chart.destroy();
|
||||
|
|
@ -472,6 +476,9 @@ app.connect(new PostMessageTransport(window.parent)).then(() => {
|
|||
if (ctx?.styles?.variables) {
|
||||
applyHostStyleVariables(ctx.styles.variables);
|
||||
}
|
||||
if (ctx?.styles?.css?.fonts) {
|
||||
applyHostFonts(ctx.styles.css.fonts);
|
||||
}
|
||||
});
|
||||
|
||||
// Fetch data after connection
|
||||
|
|
|
|||
Loading…
Reference in a new issue