@seed-ship/mcp-ui-solid 6.22.0 → 6.24.0
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/CHANGELOG.md +219 -0
- package/README.md +209 -2
- package/dist/components/ChartJSRenderer.cjs +192 -66
- package/dist/components/ChartJSRenderer.cjs.map +1 -1
- package/dist/components/ChartJSRenderer.d.ts.map +1 -1
- package/dist/components/ChartJSRenderer.js +192 -66
- package/dist/components/ChartJSRenderer.js.map +1 -1
- package/dist/components/DegradedFallback.cjs +34 -2
- package/dist/components/DegradedFallback.cjs.map +1 -1
- package/dist/components/DegradedFallback.d.ts +7 -0
- package/dist/components/DegradedFallback.d.ts.map +1 -1
- package/dist/components/DegradedFallback.js +34 -2
- package/dist/components/DegradedFallback.js.map +1 -1
- package/dist/components/MissingValue.cjs +43 -0
- package/dist/components/MissingValue.cjs.map +1 -0
- package/dist/components/MissingValue.d.ts +27 -0
- package/dist/components/MissingValue.d.ts.map +1 -0
- package/dist/components/MissingValue.js +43 -0
- package/dist/components/MissingValue.js.map +1 -0
- package/dist/components/UIResourceRenderer.cjs +250 -202
- package/dist/components/UIResourceRenderer.cjs.map +1 -1
- package/dist/components/UIResourceRenderer.d.ts +2 -1
- package/dist/components/UIResourceRenderer.d.ts.map +1 -1
- package/dist/components/UIResourceRenderer.js +250 -202
- package/dist/components/UIResourceRenderer.js.map +1 -1
- package/dist/components/chart-data-table.cjs +30 -5
- package/dist/components/chart-data-table.cjs.map +1 -1
- package/dist/components/chart-data-table.d.ts +18 -1
- package/dist/components/chart-data-table.d.ts.map +1 -1
- package/dist/components/chart-data-table.js +30 -5
- package/dist/components/chart-data-table.js.map +1 -1
- package/dist/components/chart-missing-plugin.cjs +194 -0
- package/dist/components/chart-missing-plugin.cjs.map +1 -0
- package/dist/components/chart-missing-plugin.d.ts +127 -0
- package/dist/components/chart-missing-plugin.d.ts.map +1 -0
- package/dist/components/chart-missing-plugin.js +194 -0
- package/dist/components/chart-missing-plugin.js.map +1 -0
- package/dist/context/MCPUIConfigContext.cjs.map +1 -1
- package/dist/context/MCPUIConfigContext.d.ts +57 -28
- package/dist/context/MCPUIConfigContext.d.ts.map +1 -1
- package/dist/context/MCPUIConfigContext.js.map +1 -1
- package/dist/context/MCPUIMathContext.cjs +19 -0
- package/dist/context/MCPUIMathContext.cjs.map +1 -0
- package/dist/context/MCPUIMathContext.d.ts +18 -0
- package/dist/context/MCPUIMathContext.d.ts.map +1 -0
- package/dist/context/MCPUIMathContext.js +19 -0
- package/dist/context/MCPUIMathContext.js.map +1 -0
- package/dist/context/MCPUIStringsContext.cjs +12 -1
- package/dist/context/MCPUIStringsContext.cjs.map +1 -1
- package/dist/context/MCPUIStringsContext.d.ts +62 -0
- package/dist/context/MCPUIStringsContext.d.ts.map +1 -1
- package/dist/context/MCPUIStringsContext.js +12 -1
- package/dist/context/MCPUIStringsContext.js.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/plugins/katex.cjs +23 -0
- package/dist/plugins/katex.cjs.map +1 -0
- package/dist/plugins/katex.d.cts +7 -0
- package/dist/plugins/katex.d.ts +7 -0
- package/dist/plugins/katex.d.ts.map +1 -0
- package/dist/plugins/katex.js +23 -0
- package/dist/plugins/katex.js.map +1 -0
- package/dist/services/component-registry.cjs +9 -2
- package/dist/services/component-registry.cjs.map +1 -1
- package/dist/services/component-registry.d.ts.map +1 -1
- package/dist/services/component-registry.js +9 -2
- package/dist/services/component-registry.js.map +1 -1
- package/dist/services/validation.cjs +31 -8
- package/dist/services/validation.cjs.map +1 -1
- package/dist/services/validation.d.ts.map +1 -1
- package/dist/services/validation.js +31 -8
- package/dist/services/validation.js.map +1 -1
- package/dist/types/index.d.ts +14 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/degraded-projections.cjs +19 -3
- package/dist/utils/degraded-projections.cjs.map +1 -1
- package/dist/utils/degraded-projections.d.ts +22 -2
- package/dist/utils/degraded-projections.d.ts.map +1 -1
- package/dist/utils/degraded-projections.js +19 -3
- package/dist/utils/degraded-projections.js.map +1 -1
- package/dist/utils/iframe-coep.cjs.map +1 -1
- package/dist/utils/iframe-coep.d.ts +7 -6
- package/dist/utils/iframe-coep.d.ts.map +1 -1
- package/dist/utils/iframe-coep.js.map +1 -1
- package/dist/utils/math-markdown.cjs +240 -0
- package/dist/utils/math-markdown.cjs.map +1 -0
- package/dist/utils/math-markdown.d.ts +16 -0
- package/dist/utils/math-markdown.d.ts.map +1 -0
- package/dist/utils/math-markdown.js +240 -0
- package/dist/utils/math-markdown.js.map +1 -0
- package/dist/utils/missing-value.cjs +60 -0
- package/dist/utils/missing-value.cjs.map +1 -0
- package/dist/utils/missing-value.d.ts +79 -0
- package/dist/utils/missing-value.d.ts.map +1 -0
- package/dist/utils/missing-value.js +60 -0
- package/dist/utils/missing-value.js.map +1 -0
- package/package.json +23 -4
- package/src/components/ChartJSRenderer.tsx +159 -6
- package/src/components/DegradedFallback.tsx +24 -2
- package/src/components/MissingValue.tsx +61 -0
- package/src/components/UIResourceRenderer.tsx +64 -10
- package/src/components/chart-data-table.ts +50 -6
- package/src/components/chart-missing-plugin.ts +334 -0
- package/src/context/MCPUIConfigContext.tsx +57 -28
- package/src/context/MCPUIMathContext.tsx +32 -0
- package/src/context/MCPUIStringsContext.tsx +76 -0
- package/src/index.ts +4 -0
- package/src/plugins/katex.ts +25 -0
- package/src/services/component-registry.ts +10 -2
- package/src/services/validation.ts +44 -9
- package/src/types/index.ts +13 -1
- package/src/utils/degraded-projections.ts +44 -4
- package/src/utils/iframe-coep.ts +7 -6
- package/src/utils/math-markdown.ts +222 -0
- package/src/utils/missing-value.ts +127 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Missing values in a Chart.js chart (v6.24.0) — everything the renderer adds
|
|
3
|
+
* to its Chart.js config when a payload says a value is MISSING (`null`).
|
|
4
|
+
*
|
|
5
|
+
* The rule: absence is never zero. Chart.js already keeps the slot of a `null`
|
|
6
|
+
* (no label dropped) and draws nothing for it; what it does not do is make the
|
|
7
|
+
* absence READABLE. A null bar is a zero-height bar that is skipped when
|
|
8
|
+
* drawn, a null line point is a hole the line may bridge (`spanGaps`), and the
|
|
9
|
+
* legend, tooltip and axis know nothing of either. This module supplies:
|
|
10
|
+
*
|
|
11
|
+
* - {@link createMissingValuesPlugin} — a PER-CHART plugin (never
|
|
12
|
+
* `Chart.register`ed, so it can leak into no other chart) that outlines a
|
|
13
|
+
* dashed stub where a bar should have been (not on stacked or overlaid
|
|
14
|
+
* bars, whose baseline belongs to another series), and says "no data" on a
|
|
15
|
+
* chart with nothing to draw;
|
|
16
|
+
* - {@link createMissingLegendGenerator} — marks a fully-missing series in the
|
|
17
|
+
* legend;
|
|
18
|
+
* - {@link createTooltipLabel} — names a missing value, and appends the unit;
|
|
19
|
+
* - {@link withDatasetsNoGapSpan} — the shallow-cloned data with
|
|
20
|
+
* `spanGaps: false`;
|
|
21
|
+
* - {@link applyUnitAxisTitle} — the unit as the value axis title.
|
|
22
|
+
*
|
|
23
|
+
* Runtime-free on purpose (no `solid-js`, no `chart.js` import): the renderer
|
|
24
|
+
* hands in the Chart.js pieces it loaded and the chrome strings (lazily, as
|
|
25
|
+
* getters, so a late locale change is honoured at draw time). Every function
|
|
26
|
+
* is defensive — a drawing hook that throws would blank the whole chart.
|
|
27
|
+
*
|
|
28
|
+
* Chart.js 4.5.1 facts this relies on (verified in `dist/chart.js`):
|
|
29
|
+
* - a bar whose parsed value is `null` gets `base = head = vScale.getBasePixel()`
|
|
30
|
+
* and no `skip` flag (BarController.updateElements), and `BarController.draw`
|
|
31
|
+
* skips it (`getParsed(i)[vScale.axis] !== null`) — so nothing is painted;
|
|
32
|
+
* - the bar element still carries its true index-axis thickness (`width` for a
|
|
33
|
+
* vertical bar, `height` for a horizontal one).
|
|
34
|
+
*/
|
|
35
|
+
import type { MCPUIStrings } from '../context/MCPUIStringsContext';
|
|
36
|
+
type Strings = Required<MCPUIStrings>;
|
|
37
|
+
/** Length, in px along the value axis, of the dashed stub of a missing bar. */
|
|
38
|
+
export declare const MISSING_BAR_STUB_LENGTH = 12;
|
|
39
|
+
/** Stroke of the stub when the dataset names no border colour. */
|
|
40
|
+
export declare const MISSING_BAR_FALLBACK_COLOR = "#9ca3af";
|
|
41
|
+
/** Colour of the centred "no data" text. */
|
|
42
|
+
export declare const NO_DATA_TEXT_COLOR = "#6b7280";
|
|
43
|
+
/**
|
|
44
|
+
* The category of convention line a chart shows under its canvas:
|
|
45
|
+
* `'gaps'` (a line breaks), `'bars'` (a dashed outline stands in for the
|
|
46
|
+
* bar) or `'omitted'` (nothing is drawn: scatter, bubble, stacked bars).
|
|
47
|
+
*/
|
|
48
|
+
export type MissingNoteKind = 'gaps' | 'bars' | 'omitted';
|
|
49
|
+
/**
|
|
50
|
+
* Whether a bar chart's bars are stacked or overlaid (`stacked` on either
|
|
51
|
+
* axis). A missing bar there has no slot of its own at the baseline — the
|
|
52
|
+
* baseline belongs to the series below — so no dashed outline is drawn.
|
|
53
|
+
*/
|
|
54
|
+
export declare function isStackedChart(options: any): boolean;
|
|
55
|
+
/** Which convention note a chart gets: how ITS missing values are drawn. */
|
|
56
|
+
export declare function missingNoteKind(chartType: string | undefined, options?: any): MissingNoteKind;
|
|
57
|
+
/**
|
|
58
|
+
* Chart.js data with every dataset shallow-cloned and `spanGaps: false`, so a
|
|
59
|
+
* line breaks at a missing value instead of joining its neighbours. Never
|
|
60
|
+
* mutates its input; `labels` and every other key are carried by reference.
|
|
61
|
+
*/
|
|
62
|
+
export declare function withDatasetsNoGapSpan<D extends {
|
|
63
|
+
datasets?: unknown;
|
|
64
|
+
}>(data: D): D;
|
|
65
|
+
type LegendGenerator = (chart: any) => any[];
|
|
66
|
+
/**
|
|
67
|
+
* Wraps a Chart.js legend label generator so a fully-missing dataset reads
|
|
68
|
+
* `"{series} (no data)"` (`strings.chartLegendNoData`). Every other item is
|
|
69
|
+
* passed through untouched.
|
|
70
|
+
*/
|
|
71
|
+
export declare function createMissingLegendGenerator(base: LegendGenerator, fullyMissing: readonly boolean[], getStrings: () => Strings): LegendGenerator;
|
|
72
|
+
/** Whether a Chart.js tooltip item stands for a missing value. */
|
|
73
|
+
export declare function isMissingTooltipItem(item: any): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Tooltip `label` callback: names a missing value (`"{series}: Missing
|
|
76
|
+
* value"`) and, with a `unit`, appends it to a present one. Otherwise it is
|
|
77
|
+
* Chart.js's default composition (dataset label, `": "`, formatted value) —
|
|
78
|
+
* including its `mode: 'dataset'` branch, which prefixes the CATEGORY label
|
|
79
|
+
* instead, since every item of that tooltip belongs to the same dataset.
|
|
80
|
+
* Hence a regular function: Chart.js calls it with the tooltip as `this`.
|
|
81
|
+
*
|
|
82
|
+
* `unit` is left off scatter and bubble tooltips: their formatted value is the
|
|
83
|
+
* pair `(x, y)`, to which one unit does not belong.
|
|
84
|
+
*/
|
|
85
|
+
export declare function createTooltipLabel(getStrings: () => Strings, unit: string | undefined, chartType: string | undefined): (this: any, item: any) => string;
|
|
86
|
+
/**
|
|
87
|
+
* Sets the chart's `unit` as the title of its value axis, in place on the
|
|
88
|
+
* `options` object the renderer just built (never on the payload's).
|
|
89
|
+
*
|
|
90
|
+
* Only bar, line, scatter and bubble have a value axis to title. The value
|
|
91
|
+
* axis is `y`, or `x` when the index axis is `y` (a horizontal bar or line).
|
|
92
|
+
* An existing `scales[axis].title` is the payload's own word and is kept; the
|
|
93
|
+
* rest of the scale config (a `timeAxis` block sets `scales.x`) is kept too.
|
|
94
|
+
*/
|
|
95
|
+
export declare function applyUnitAxisTitle(options: any, chartType: string | undefined, unit: string | undefined): void;
|
|
96
|
+
export interface MissingValuesPluginOptions {
|
|
97
|
+
/** At least one dataset and every one of them has no observed value. */
|
|
98
|
+
allMissing: boolean;
|
|
99
|
+
/** Lazy: read at draw time. */
|
|
100
|
+
getNoDataText: () => string;
|
|
101
|
+
/** Lazy: `Chart.defaults.font.family`, when the build exposes it. */
|
|
102
|
+
getFontFamily?: () => string | undefined;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Draws a dashed outline stub for every missing bar of every visible,
|
|
106
|
+
* non-stacked bar dataset, so a missing value is a visible mark, not a bar
|
|
107
|
+
* that "is" zero.
|
|
108
|
+
*
|
|
109
|
+
* The stub sits on the value-axis base, as thick as the bar would have been,
|
|
110
|
+
* and runs {@link MISSING_BAR_STUB_LENGTH}px toward the middle of the chart
|
|
111
|
+
* area (up from a bottom baseline, down from a top one, right from a left
|
|
112
|
+
* one). Clipped to the chart area.
|
|
113
|
+
*/
|
|
114
|
+
export declare function drawMissingBarStubs(chart: any): void;
|
|
115
|
+
/** Draws `text` centred in the chart area (a chart with nothing to plot). */
|
|
116
|
+
export declare function drawNoDataText(chart: any, text: string, fontFamily?: string): void;
|
|
117
|
+
/**
|
|
118
|
+
* The per-chart plugin object. Passed as `config.plugins = [plugin]`: Chart.js
|
|
119
|
+
* scopes it to that one chart. Both hooks swallow their own errors — a
|
|
120
|
+
* decoration must never take the chart down.
|
|
121
|
+
*/
|
|
122
|
+
export declare function createMissingValuesPlugin(options: MissingValuesPluginOptions): {
|
|
123
|
+
id: string;
|
|
124
|
+
afterDatasetsDraw(chart: any): void;
|
|
125
|
+
};
|
|
126
|
+
export {};
|
|
127
|
+
//# sourceMappingURL=chart-missing-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-missing-plugin.d.ts","sourceRoot":"","sources":["../../src/components/chart-missing-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAInE,KAAK,OAAO,GAAG,QAAQ,CAAC,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,IAAI,EAAE,MAAM,GAAG,SAAS,GACvB,IAAI,CAYN;AAID,MAAM,WAAW,0BAA0B;IACzC,wEAAwE;IACxE,UAAU,EAAE,OAAO,CAAC;IACpB,+BAA+B;IAC/B,aAAa,EAAE,MAAM,MAAM,CAAC;IAC5B,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;CAC1C;AAYD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI,CA+DpD;AAED,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAalF;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,0BAA0B;;6BAGhD,GAAG;EAW/B"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { formatMCPUIString } from "../utils/format-string.js";
|
|
2
|
+
import { isMissingChartValue } from "../utils/missing-value.js";
|
|
3
|
+
const MISSING_BAR_STUB_LENGTH = 12;
|
|
4
|
+
const MISSING_BAR_FALLBACK_COLOR = "#9ca3af";
|
|
5
|
+
const NO_DATA_TEXT_COLOR = "#6b7280";
|
|
6
|
+
const STUB_DASH = [4, 3];
|
|
7
|
+
const POINT_CHART_TYPES = /* @__PURE__ */ new Set(["scatter", "bubble"]);
|
|
8
|
+
function isStackedChart(options) {
|
|
9
|
+
var _a, _b, _c, _d;
|
|
10
|
+
return Boolean(((_b = (_a = options == null ? void 0 : options.scales) == null ? void 0 : _a.x) == null ? void 0 : _b.stacked) || ((_d = (_c = options == null ? void 0 : options.scales) == null ? void 0 : _c.y) == null ? void 0 : _d.stacked));
|
|
11
|
+
}
|
|
12
|
+
function missingNoteKind(chartType, options) {
|
|
13
|
+
if (chartType === "bar") return isStackedChart(options) ? "omitted" : "bars";
|
|
14
|
+
if (chartType === "scatter" || chartType === "bubble") return "omitted";
|
|
15
|
+
return "gaps";
|
|
16
|
+
}
|
|
17
|
+
function withDatasetsNoGapSpan(data) {
|
|
18
|
+
const datasets = Array.isArray(data == null ? void 0 : data.datasets) ? data.datasets : null;
|
|
19
|
+
if (!datasets) return data;
|
|
20
|
+
return {
|
|
21
|
+
...data,
|
|
22
|
+
datasets: datasets.map(
|
|
23
|
+
(dataset) => dataset !== null && typeof dataset === "object" ? { ...dataset, spanGaps: false } : dataset
|
|
24
|
+
)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function createMissingLegendGenerator(base, fullyMissing, getStrings) {
|
|
28
|
+
return function generateLabels(chart) {
|
|
29
|
+
const items = base.call(this, chart);
|
|
30
|
+
if (!Array.isArray(items)) return items;
|
|
31
|
+
return items.map((item) => {
|
|
32
|
+
const index = item == null ? void 0 : item.datasetIndex;
|
|
33
|
+
if (typeof index !== "number" || !fullyMissing[index]) return item;
|
|
34
|
+
const text = typeof item.text === "string" ? item.text : String(item.text ?? "");
|
|
35
|
+
return {
|
|
36
|
+
...item,
|
|
37
|
+
text: formatMCPUIString(getStrings().chartLegendNoData, { series: text })
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function isMissingTooltipItem(item) {
|
|
43
|
+
var _a, _b, _c, _d;
|
|
44
|
+
if (item === null || item === void 0) return false;
|
|
45
|
+
if (item.raw === null || item.raw === void 0 || isMissingChartValue(item.raw)) return true;
|
|
46
|
+
const parsed = item.parsed;
|
|
47
|
+
if (parsed !== null && typeof parsed === "object") {
|
|
48
|
+
const chartType = (_b = (_a = item.chart) == null ? void 0 : _a.config) == null ? void 0 : _b.type;
|
|
49
|
+
const valueKey = chartType === "radar" ? "r" : ((_d = (_c = item.chart) == null ? void 0 : _c.options) == null ? void 0 : _d.indexAxis) === "y" ? "x" : "y";
|
|
50
|
+
if (valueKey in parsed && parsed[valueKey] === null) return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
function createTooltipLabel(getStrings, unit, chartType) {
|
|
55
|
+
const applyUnit = unit !== void 0 && !POINT_CHART_TYPES.has(chartType ?? "");
|
|
56
|
+
return function label(item) {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
const strings = getStrings();
|
|
59
|
+
const prefixLabel = ((_a = this == null ? void 0 : this.options) == null ? void 0 : _a.mode) === "dataset" ? item == null ? void 0 : item.label : (_b = item == null ? void 0 : item.dataset) == null ? void 0 : _b.label;
|
|
60
|
+
const prefix = typeof prefixLabel === "string" && prefixLabel !== "" ? `${prefixLabel}: ` : "";
|
|
61
|
+
if (isMissingTooltipItem(item)) return `${prefix}${strings.missingValue}`;
|
|
62
|
+
const formatted = item == null ? void 0 : item.formattedValue;
|
|
63
|
+
if (formatted === null || formatted === void 0) return prefix;
|
|
64
|
+
const value = applyUnit ? formatMCPUIString(strings.chartValueWithUnit, { value: formatted, unit }) : String(formatted);
|
|
65
|
+
return `${prefix}${value}`;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function applyUnitAxisTitle(options, chartType, unit) {
|
|
69
|
+
var _a, _b, _c;
|
|
70
|
+
if (unit === void 0) return;
|
|
71
|
+
if (chartType !== "bar" && chartType !== "line" && !POINT_CHART_TYPES.has(chartType ?? "")) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const horizontal = (chartType === "bar" || chartType === "line") && (options == null ? void 0 : options.indexAxis) === "y";
|
|
75
|
+
const axis = horizontal ? "x" : "y";
|
|
76
|
+
if (((_b = (_a = options.scales) == null ? void 0 : _a[axis]) == null ? void 0 : _b.title) !== void 0) return;
|
|
77
|
+
options.scales = {
|
|
78
|
+
...options.scales,
|
|
79
|
+
[axis]: { ...(_c = options.scales) == null ? void 0 : _c[axis], title: { display: true, text: unit } }
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function colorAt(color, index) {
|
|
83
|
+
if (typeof color === "string" && color !== "") return color;
|
|
84
|
+
if (Array.isArray(color) && color.length > 0) {
|
|
85
|
+
const picked = color[index % color.length];
|
|
86
|
+
return typeof picked === "string" && picked !== "" ? picked : void 0;
|
|
87
|
+
}
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
function drawMissingBarStubs(chart) {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
const ctx = chart == null ? void 0 : chart.ctx;
|
|
93
|
+
const area = chart == null ? void 0 : chart.chartArea;
|
|
94
|
+
const datasets = (_a = chart == null ? void 0 : chart.data) == null ? void 0 : _a.datasets;
|
|
95
|
+
if (!ctx || !area || !Array.isArray(datasets)) return;
|
|
96
|
+
const left = area.left;
|
|
97
|
+
const top = area.top;
|
|
98
|
+
const right = area.right ?? left + (area.width ?? 0);
|
|
99
|
+
const bottom = area.bottom ?? top + (area.height ?? 0);
|
|
100
|
+
let saved = false;
|
|
101
|
+
datasets.forEach((dataset, datasetIndex) => {
|
|
102
|
+
var _a2, _b2, _c, _d, _e, _f, _g;
|
|
103
|
+
const meta = (_a2 = chart.getDatasetMeta) == null ? void 0 : _a2.call(chart, datasetIndex);
|
|
104
|
+
if (!meta) return;
|
|
105
|
+
const isBar = meta.type === "bar" || ((_c = (_b2 = meta.controller) == null ? void 0 : _b2.constructor) == null ? void 0 : _c.id) === "bar";
|
|
106
|
+
if (!isBar) return;
|
|
107
|
+
if (((_e = (_d = meta.vScale) == null ? void 0 : _d.options) == null ? void 0 : _e.stacked) || ((_g = (_f = meta.iScale) == null ? void 0 : _f.options) == null ? void 0 : _g.stacked)) return;
|
|
108
|
+
if (typeof chart.isDatasetVisible === "function" && !chart.isDatasetVisible(datasetIndex)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const values = Array.isArray(dataset == null ? void 0 : dataset.data) ? dataset.data : [];
|
|
112
|
+
const elements = Array.isArray(meta.data) ? meta.data : [];
|
|
113
|
+
values.forEach((value, index) => {
|
|
114
|
+
var _a3;
|
|
115
|
+
if (!isMissingChartValue(value)) return;
|
|
116
|
+
const element = elements[index];
|
|
117
|
+
if (!element) return;
|
|
118
|
+
const props = ((_a3 = element.getProps) == null ? void 0 : _a3.call(element, ["x", "y", "base", "width", "height"], true)) ?? element;
|
|
119
|
+
const { x, y, base, width, height } = props;
|
|
120
|
+
if (![x, y, base].every((n) => Number.isFinite(n))) return;
|
|
121
|
+
const horizontal = element.horizontal === true;
|
|
122
|
+
const thickness = horizontal ? height : width;
|
|
123
|
+
if (!Number.isFinite(thickness) || thickness <= 0) return;
|
|
124
|
+
let rect;
|
|
125
|
+
if (horizontal) {
|
|
126
|
+
const dir = base < (left + right) / 2 ? 1 : -1;
|
|
127
|
+
rect = [Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), y - thickness / 2, MISSING_BAR_STUB_LENGTH, thickness];
|
|
128
|
+
} else {
|
|
129
|
+
const dir = base > (top + bottom) / 2 ? -1 : 1;
|
|
130
|
+
rect = [x - thickness / 2, Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), thickness, MISSING_BAR_STUB_LENGTH];
|
|
131
|
+
}
|
|
132
|
+
if (!saved) {
|
|
133
|
+
ctx.save();
|
|
134
|
+
ctx.beginPath();
|
|
135
|
+
ctx.rect(left, top, right - left, bottom - top);
|
|
136
|
+
ctx.clip();
|
|
137
|
+
saved = true;
|
|
138
|
+
}
|
|
139
|
+
ctx.strokeStyle = colorAt(dataset == null ? void 0 : dataset.borderColor, index) ?? MISSING_BAR_FALLBACK_COLOR;
|
|
140
|
+
ctx.lineWidth = 1;
|
|
141
|
+
ctx.setLineDash(STUB_DASH);
|
|
142
|
+
ctx.strokeRect(...rect);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
if (saved) {
|
|
146
|
+
(_b = ctx.setLineDash) == null ? void 0 : _b.call(ctx, []);
|
|
147
|
+
ctx.restore();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function drawNoDataText(chart, text, fontFamily) {
|
|
151
|
+
const ctx = chart == null ? void 0 : chart.ctx;
|
|
152
|
+
const area = chart == null ? void 0 : chart.chartArea;
|
|
153
|
+
if (!ctx || !area || !text) return;
|
|
154
|
+
const cx = (area.left + (area.right ?? area.left + (area.width ?? 0))) / 2;
|
|
155
|
+
const cy = (area.top + (area.bottom ?? area.top + (area.height ?? 0))) / 2;
|
|
156
|
+
ctx.save();
|
|
157
|
+
ctx.font = `12px ${fontFamily || "sans-serif"}`;
|
|
158
|
+
ctx.fillStyle = NO_DATA_TEXT_COLOR;
|
|
159
|
+
ctx.textAlign = "center";
|
|
160
|
+
ctx.textBaseline = "middle";
|
|
161
|
+
ctx.fillText(text, cx, cy);
|
|
162
|
+
ctx.restore();
|
|
163
|
+
}
|
|
164
|
+
function createMissingValuesPlugin(options) {
|
|
165
|
+
return {
|
|
166
|
+
id: "mcpuiMissingValues",
|
|
167
|
+
afterDatasetsDraw(chart) {
|
|
168
|
+
var _a;
|
|
169
|
+
try {
|
|
170
|
+
drawMissingBarStubs(chart);
|
|
171
|
+
if (options.allMissing) {
|
|
172
|
+
drawNoDataText(chart, options.getNoDataText(), (_a = options.getFontFamily) == null ? void 0 : _a.call(options));
|
|
173
|
+
}
|
|
174
|
+
} catch {
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
export {
|
|
180
|
+
MISSING_BAR_FALLBACK_COLOR,
|
|
181
|
+
MISSING_BAR_STUB_LENGTH,
|
|
182
|
+
NO_DATA_TEXT_COLOR,
|
|
183
|
+
applyUnitAxisTitle,
|
|
184
|
+
createMissingLegendGenerator,
|
|
185
|
+
createMissingValuesPlugin,
|
|
186
|
+
createTooltipLabel,
|
|
187
|
+
drawMissingBarStubs,
|
|
188
|
+
drawNoDataText,
|
|
189
|
+
isMissingTooltipItem,
|
|
190
|
+
isStackedChart,
|
|
191
|
+
missingNoteKind,
|
|
192
|
+
withDatasetsNoGapSpan
|
|
193
|
+
};
|
|
194
|
+
//# sourceMappingURL=chart-missing-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-missing-plugin.js","sources":["../../src/components/chart-missing-plugin.ts"],"sourcesContent":["/**\n * Missing values in a Chart.js chart (v6.24.0) — everything the renderer adds\n * to its Chart.js config when a payload says a value is MISSING (`null`).\n *\n * The rule: absence is never zero. Chart.js already keeps the slot of a `null`\n * (no label dropped) and draws nothing for it; what it does not do is make the\n * absence READABLE. A null bar is a zero-height bar that is skipped when\n * drawn, a null line point is a hole the line may bridge (`spanGaps`), and the\n * legend, tooltip and axis know nothing of either. This module supplies:\n *\n * - {@link createMissingValuesPlugin} — a PER-CHART plugin (never\n * `Chart.register`ed, so it can leak into no other chart) that outlines a\n * dashed stub where a bar should have been (not on stacked or overlaid\n * bars, whose baseline belongs to another series), and says \"no data\" on a\n * chart with nothing to draw;\n * - {@link createMissingLegendGenerator} — marks a fully-missing series in the\n * legend;\n * - {@link createTooltipLabel} — names a missing value, and appends the unit;\n * - {@link withDatasetsNoGapSpan} — the shallow-cloned data with\n * `spanGaps: false`;\n * - {@link applyUnitAxisTitle} — the unit as the value axis title.\n *\n * Runtime-free on purpose (no `solid-js`, no `chart.js` import): the renderer\n * hands in the Chart.js pieces it loaded and the chrome strings (lazily, as\n * getters, so a late locale change is honoured at draw time). Every function\n * is defensive — a drawing hook that throws would blank the whole chart.\n *\n * Chart.js 4.5.1 facts this relies on (verified in `dist/chart.js`):\n * - a bar whose parsed value is `null` gets `base = head = vScale.getBasePixel()`\n * and no `skip` flag (BarController.updateElements), and `BarController.draw`\n * skips it (`getParsed(i)[vScale.axis] !== null`) — so nothing is painted;\n * - the bar element still carries its true index-axis thickness (`width` for a\n * vertical bar, `height` for a horizontal one).\n */\n\nimport type { MCPUIStrings } from '../context/MCPUIStringsContext';\nimport { formatMCPUIString } from '../utils/format-string';\nimport { isMissingChartValue } from '../utils/missing-value';\n\ntype Strings = Required<MCPUIStrings>;\n\n/** Length, in px along the value axis, of the dashed stub of a missing bar. */\nexport const MISSING_BAR_STUB_LENGTH = 12;\n/** Stroke of the stub when the dataset names no border colour. */\nexport const MISSING_BAR_FALLBACK_COLOR = '#9ca3af';\n/** Colour of the centred \"no data\" text. */\nexport const NO_DATA_TEXT_COLOR = '#6b7280';\nconst STUB_DASH = [4, 3];\n\n/** Chart types whose value axis is `y` and whose points are `{x, y}`. */\nconst POINT_CHART_TYPES = new Set(['scatter', 'bubble']);\n\n/**\n * The category of convention line a chart shows under its canvas:\n * `'gaps'` (a line breaks), `'bars'` (a dashed outline stands in for the\n * bar) or `'omitted'` (nothing is drawn: scatter, bubble, stacked bars).\n */\nexport type MissingNoteKind = 'gaps' | 'bars' | 'omitted';\n\n/**\n * Whether a bar chart's bars are stacked or overlaid (`stacked` on either\n * axis). A missing bar there has no slot of its own at the baseline — the\n * baseline belongs to the series below — so no dashed outline is drawn.\n */\nexport function isStackedChart(options: any): boolean {\n return Boolean(options?.scales?.x?.stacked || options?.scales?.y?.stacked);\n}\n\n/** Which convention note a chart gets: how ITS missing values are drawn. */\nexport function missingNoteKind(chartType: string | undefined, options?: any): MissingNoteKind {\n if (chartType === 'bar') return isStackedChart(options) ? 'omitted' : 'bars';\n if (chartType === 'scatter' || chartType === 'bubble') return 'omitted';\n return 'gaps';\n}\n\n// ─── Data ──────────────────────────────────────────────────────────────────\n\n/**\n * Chart.js data with every dataset shallow-cloned and `spanGaps: false`, so a\n * line breaks at a missing value instead of joining its neighbours. Never\n * mutates its input; `labels` and every other key are carried by reference.\n */\nexport function withDatasetsNoGapSpan<D extends { datasets?: unknown }>(data: D): D {\n const datasets = Array.isArray(data?.datasets) ? data.datasets : null;\n if (!datasets) return data;\n return {\n ...data,\n datasets: datasets.map((dataset: unknown) =>\n dataset !== null && typeof dataset === 'object'\n ? { ...(dataset as object), spanGaps: false }\n : dataset\n ),\n };\n}\n\n// ─── Legend ────────────────────────────────────────────────────────────────\n\ntype LegendGenerator = (chart: any) => any[];\n\n/**\n * Wraps a Chart.js legend label generator so a fully-missing dataset reads\n * `\"{series} (no data)\"` (`strings.chartLegendNoData`). Every other item is\n * passed through untouched.\n */\nexport function createMissingLegendGenerator(\n base: LegendGenerator,\n fullyMissing: readonly boolean[],\n getStrings: () => Strings\n): LegendGenerator {\n return function generateLabels(this: unknown, chart: any) {\n const items = base.call(this, chart);\n if (!Array.isArray(items)) return items;\n return items.map((item) => {\n const index = item?.datasetIndex;\n if (typeof index !== 'number' || !fullyMissing[index]) return item;\n const text = typeof item.text === 'string' ? item.text : String(item.text ?? '');\n return {\n ...item,\n text: formatMCPUIString(getStrings().chartLegendNoData, { series: text }),\n };\n });\n };\n}\n\n// ─── Tooltip ───────────────────────────────────────────────────────────────\n\n/** Whether a Chart.js tooltip item stands for a missing value. */\nexport function isMissingTooltipItem(item: any): boolean {\n if (item === null || item === undefined) return false;\n if (item.raw === null || item.raw === undefined || isMissingChartValue(item.raw)) return true;\n const parsed = item.parsed;\n if (parsed !== null && typeof parsed === 'object') {\n const chartType = item.chart?.config?.type;\n const valueKey =\n chartType === 'radar' ? 'r' : item.chart?.options?.indexAxis === 'y' ? 'x' : 'y';\n if (valueKey in parsed && parsed[valueKey] === null) return true;\n }\n return false;\n}\n\n/**\n * Tooltip `label` callback: names a missing value (`\"{series}: Missing\n * value\"`) and, with a `unit`, appends it to a present one. Otherwise it is\n * Chart.js's default composition (dataset label, `\": \"`, formatted value) —\n * including its `mode: 'dataset'` branch, which prefixes the CATEGORY label\n * instead, since every item of that tooltip belongs to the same dataset.\n * Hence a regular function: Chart.js calls it with the tooltip as `this`.\n *\n * `unit` is left off scatter and bubble tooltips: their formatted value is the\n * pair `(x, y)`, to which one unit does not belong.\n */\nexport function createTooltipLabel(\n getStrings: () => Strings,\n unit: string | undefined,\n chartType: string | undefined\n): (this: any, item: any) => string {\n const applyUnit = unit !== undefined && !POINT_CHART_TYPES.has(chartType ?? '');\n return function label(this: any, item: any) {\n const strings = getStrings();\n const prefixLabel = this?.options?.mode === 'dataset' ? item?.label : item?.dataset?.label;\n const prefix = typeof prefixLabel === 'string' && prefixLabel !== '' ? `${prefixLabel}: ` : '';\n\n if (isMissingTooltipItem(item)) return `${prefix}${strings.missingValue}`;\n\n const formatted = item?.formattedValue;\n if (formatted === null || formatted === undefined) return prefix;\n const value = applyUnit\n ? formatMCPUIString(strings.chartValueWithUnit, { value: formatted, unit: unit as string })\n : String(formatted);\n return `${prefix}${value}`;\n };\n}\n\n// ─── Axis ──────────────────────────────────────────────────────────────────\n\n/**\n * Sets the chart's `unit` as the title of its value axis, in place on the\n * `options` object the renderer just built (never on the payload's).\n *\n * Only bar, line, scatter and bubble have a value axis to title. The value\n * axis is `y`, or `x` when the index axis is `y` (a horizontal bar or line).\n * An existing `scales[axis].title` is the payload's own word and is kept; the\n * rest of the scale config (a `timeAxis` block sets `scales.x`) is kept too.\n */\nexport function applyUnitAxisTitle(\n options: any,\n chartType: string | undefined,\n unit: string | undefined\n): void {\n if (unit === undefined) return;\n if (chartType !== 'bar' && chartType !== 'line' && !POINT_CHART_TYPES.has(chartType ?? '')) {\n return;\n }\n const horizontal = (chartType === 'bar' || chartType === 'line') && options?.indexAxis === 'y';\n const axis = horizontal ? 'x' : 'y';\n if (options.scales?.[axis]?.title !== undefined) return;\n options.scales = {\n ...options.scales,\n [axis]: { ...options.scales?.[axis], title: { display: true, text: unit } },\n };\n}\n\n// ─── Plugin ────────────────────────────────────────────────────────────────\n\nexport interface MissingValuesPluginOptions {\n /** At least one dataset and every one of them has no observed value. */\n allMissing: boolean;\n /** Lazy: read at draw time. */\n getNoDataText: () => string;\n /** Lazy: `Chart.defaults.font.family`, when the build exposes it. */\n getFontFamily?: () => string | undefined;\n}\n\n/** A dataset colour for entry `index`, as a string, or `undefined`. */\nfunction colorAt(color: unknown, index: number): string | undefined {\n if (typeof color === 'string' && color !== '') return color;\n if (Array.isArray(color) && color.length > 0) {\n const picked = color[index % color.length];\n return typeof picked === 'string' && picked !== '' ? picked : undefined;\n }\n return undefined;\n}\n\n/**\n * Draws a dashed outline stub for every missing bar of every visible,\n * non-stacked bar dataset, so a missing value is a visible mark, not a bar\n * that \"is\" zero.\n *\n * The stub sits on the value-axis base, as thick as the bar would have been,\n * and runs {@link MISSING_BAR_STUB_LENGTH}px toward the middle of the chart\n * area (up from a bottom baseline, down from a top one, right from a left\n * one). Clipped to the chart area.\n */\nexport function drawMissingBarStubs(chart: any): void {\n const ctx = chart?.ctx;\n const area = chart?.chartArea;\n const datasets = chart?.data?.datasets;\n if (!ctx || !area || !Array.isArray(datasets)) return;\n\n const left = area.left;\n const top = area.top;\n const right = area.right ?? left + (area.width ?? 0);\n const bottom = area.bottom ?? top + (area.height ?? 0);\n\n let saved = false;\n datasets.forEach((dataset: any, datasetIndex: number) => {\n const meta = chart.getDatasetMeta?.(datasetIndex);\n if (!meta) return;\n const isBar = meta.type === 'bar' || meta.controller?.constructor?.id === 'bar';\n if (!isBar) return;\n // Stacked or overlaid bars: the baseline under a missing segment is the\n // series below, so an outline there would point at the wrong series.\n if (meta.vScale?.options?.stacked || meta.iScale?.options?.stacked) return;\n if (typeof chart.isDatasetVisible === 'function' && !chart.isDatasetVisible(datasetIndex)) {\n return;\n }\n const values: unknown[] = Array.isArray(dataset?.data) ? dataset.data : [];\n const elements: any[] = Array.isArray(meta.data) ? meta.data : [];\n\n values.forEach((value, index) => {\n if (!isMissingChartValue(value)) return;\n const element = elements[index];\n if (!element) return;\n const props = element.getProps?.(['x', 'y', 'base', 'width', 'height'], true) ?? element;\n const { x, y, base, width, height } = props;\n if (![x, y, base].every((n) => Number.isFinite(n))) return;\n const horizontal = element.horizontal === true;\n const thickness = horizontal ? height : width;\n if (!Number.isFinite(thickness) || thickness <= 0) return;\n\n let rect: [number, number, number, number];\n if (horizontal) {\n const dir = base < (left + right) / 2 ? 1 : -1;\n rect = [Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), y - thickness / 2, MISSING_BAR_STUB_LENGTH, thickness];\n } else {\n const dir = base > (top + bottom) / 2 ? -1 : 1;\n rect = [x - thickness / 2, Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), thickness, MISSING_BAR_STUB_LENGTH];\n }\n\n if (!saved) {\n ctx.save();\n ctx.beginPath();\n ctx.rect(left, top, right - left, bottom - top);\n ctx.clip();\n saved = true;\n }\n ctx.strokeStyle = colorAt(dataset?.borderColor, index) ?? MISSING_BAR_FALLBACK_COLOR;\n ctx.lineWidth = 1;\n ctx.setLineDash(STUB_DASH);\n ctx.strokeRect(...rect);\n });\n });\n if (saved) {\n ctx.setLineDash?.([]);\n ctx.restore();\n }\n}\n\n/** Draws `text` centred in the chart area (a chart with nothing to plot). */\nexport function drawNoDataText(chart: any, text: string, fontFamily?: string): void {\n const ctx = chart?.ctx;\n const area = chart?.chartArea;\n if (!ctx || !area || !text) return;\n const cx = (area.left + (area.right ?? area.left + (area.width ?? 0))) / 2;\n const cy = (area.top + (area.bottom ?? area.top + (area.height ?? 0))) / 2;\n ctx.save();\n ctx.font = `12px ${fontFamily || 'sans-serif'}`;\n ctx.fillStyle = NO_DATA_TEXT_COLOR;\n ctx.textAlign = 'center';\n ctx.textBaseline = 'middle';\n ctx.fillText(text, cx, cy);\n ctx.restore();\n}\n\n/**\n * The per-chart plugin object. Passed as `config.plugins = [plugin]`: Chart.js\n * scopes it to that one chart. Both hooks swallow their own errors — a\n * decoration must never take the chart down.\n */\nexport function createMissingValuesPlugin(options: MissingValuesPluginOptions) {\n return {\n id: 'mcpuiMissingValues',\n afterDatasetsDraw(chart: any) {\n try {\n drawMissingBarStubs(chart);\n if (options.allMissing) {\n drawNoDataText(chart, options.getNoDataText(), options.getFontFamily?.());\n }\n } catch {\n // Cosmetic layer: never break the chart.\n }\n },\n };\n}\n"],"names":["_a","_b"],"mappings":";;AA0CO,MAAM,0BAA0B;AAEhC,MAAM,6BAA6B;AAEnC,MAAM,qBAAqB;AAClC,MAAM,YAAY,CAAC,GAAG,CAAC;AAGvB,MAAM,oBAAoB,oBAAI,IAAI,CAAC,WAAW,QAAQ,CAAC;AAchD,SAAS,eAAe,SAAuB;;A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,CAAC;AACD,MAAI,OAAO;AACT,cAAI,gBAAJ,6BAAkB;AAClB,QAAI,QAAA;AAAA,EACN;AACF;AAGO,SAAS,eAAe,OAAY,MAAc,YAA2B;AAClF,QAAM,MAAM,+BAAO;AACnB,QAAM,OAAO,+BAAO;AACpB,MAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAM;AAC5B,QAAM,MAAM,KAAK,QAAQ,KAAK,SAAS,KAAK,QAAQ,KAAK,SAAS,OAAO;AACzE,QAAM,MAAM,KAAK,OAAO,KAAK,UAAU,KAAK,OAAO,KAAK,UAAU,OAAO;AACzE,MAAI,KAAA;AACJ,MAAI,OAAO,QAAQ,cAAc,YAAY;AAC7C,MAAI,YAAY;AAChB,MAAI,YAAY;AAChB,MAAI,eAAe;AACnB,MAAI,SAAS,MAAM,IAAI,EAAE;AACzB,MAAI,QAAA;AACN;AAOO,SAAS,0BAA0B,SAAqC;AAC7E,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,kBAAkB,OAAY;;AAC5B,UAAI;AACF,4BAAoB,KAAK;AACzB,YAAI,QAAQ,YAAY;AACtB,yBAAe,OAAO,QAAQ,cAAA,IAAiB,aAAQ,kBAAR,gCAAyB;AAAA,QAC1E;AAAA,MACF,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MCPUIConfigContext.cjs","sources":["../../src/context/MCPUIConfigContext.tsx"],"sourcesContent":["/**\n * MCPUIConfigContext — host-level rendering policy: the library's iframes\n * (v6.21.0) and, since v6.22.0, where a chart may capture the wheel.\n *\n * @since v6.21.0\n *\n * ## Why\n *\n * A host that serves `Cross-Origin-Embedder-Policy: credentialless` makes the\n * browser refuse every cross-origin iframe whose own document does not send a\n * COEP header — which is YouTube, Vimeo, Google Docs, Notion and nearly all of\n * `DEFAULT_IFRAME_DOMAINS`. The escape hatch is the boolean HTML attribute\n * `credentialless` on the `<iframe>` itself: the document then loads, but\n * without access to the cookies and storage of its own origin.\n *\n * That trade-off is free for a public video or chart and fatal for an\n * authenticated embed, so the library keys it on the distinction it already\n * makes: `TRUSTED_IFRAME_DOMAINS` (the hosts that receive `allow-same-origin`\n * because they need their own cookies) do NOT get the attribute; everything\n * else does. This context lets a host override that, add its own trusted\n * hosts, and control the \"open in a new tab\" fallback link.\n *\n * ## Scope — policy only, NOT strings\n *\n * Text lives in `MCPUIStrings` (`MCPUIStringsContext`). This context carries\n * only behavioural switches, and like the strings context every renderer works\n * standalone: with no provider mounted, `DEFAULT_MCPUI_CONFIG` applies.\n *\n * @example\n * ```tsx\n * import { MCPUIConfigProvider } from '@seed-ship/mcp-ui-solid'\n *\n * <MCPUIConfigProvider config={{ customTrustedIframeDomains: ['embed.acme.com'] }}>\n * <App />\n * </MCPUIConfigProvider>\n * ```\n */\n\nimport { createContext, mergeProps, useContext, type JSX } from 'solid-js'\nimport type { IframePolicy } from '../types'\n\n/**\n * Host-level rendering policy. Every field has a default — a provider passes\n * a partial override.\n *\n * ## Why every field is optional\n *\n * This interface grows a key every time the library gains a policy switch,\n * and those releases are MINOR. Were the fields required, adding one would\n * break the build of any consumer holding a COMPLETE `MCPUIConfig` value —\n * a typed constant, a helper that returns one, or a direct\n * `<MCPUIConfigContext.Provider value={…}>` — because their object would\n * suddenly miss a key. Nothing about their behaviour changed; only `tsc`\n * would fail. Optional fields make each new key additive.\n *\n * The completeness guarantee moves from the type to the two values that\n * actually need it, exactly as `MCPUIStrings` does it:\n * `DEFAULT_MCPUI_CONFIG` is `Required<MCPUIConfig>`, so forgetting a default\n * is a compile error HERE, and {@link useMCPUIConfig} returns\n * `Required<MCPUIConfig>`, so every renderer still reads a fully resolved\n * value and never has to null-check a policy.\n */\nexport interface MCPUIConfig {\n /**\n * When the library puts the boolean `credentialless` attribute on an\n * `<iframe>` it renders.\n *\n * - `'auto'` (default) — on every iframe whose host is NOT in\n * `TRUSTED_IFRAME_DOMAINS` (plus `customTrustedIframeDomains`). Those\n * hosts already ran without cookies, since their sandbox has no\n * `allow-same-origin`; the attribute is what unblocks them under COEP.\n * - `'always'` — on every iframe, trusted hosts included. An authenticated\n * embed will then render its login screen.\n * - `'never'` — never. The right value for a host that sends no COEP header\n * and does not want its embeds to lose their cookies.\n *\n * Chrome/Edge 110+ honour the attribute; Firefox ignores it (iframes stay\n * blocked while the host sends COEP); Safari ignores the COEP value itself,\n * so nothing is blocked there in the first place.\n */\n iframeCredentialless?: 'auto' | 'always' | 'never'\n\n /**\n * Extra hosts treated as trusted, on top of `TRUSTED_IFRAME_DOMAINS`:\n * no `credentialless` attribute, and `allow-same-origin` in the sandbox.\n * A subdomain of a listed host matches too.\n *\n * This only RECLASSIFIES a host the allow-list already accepts. To render an\n * iframe whose host is outside `DEFAULT_IFRAME_DOMAINS`, add it to\n * {@link MCPUIConfig.customIframeDomains} with `iframePolicy: 'extend'`.\n */\n customTrustedIframeDomains?: string[]\n\n /**\n * How `UIResourceRenderer` validates an `iframe` component's host:\n * `'strict'` (default) accepts `DEFAULT_IFRAME_DOMAINS` only, `'extend'`\n * also accepts {@link MCPUIConfig.customIframeDomains}.\n */\n iframePolicy?: IframePolicy\n\n /**\n * Extra hosts the allow-list accepts when `iframePolicy` is `'extend'`.\n * Without this, a component pointing at an unlisted host is replaced by the\n * validation card before any renderer runs.\n */\n customIframeDomains?: string[]\n\n /**\n * When the library renders an \"open in a new tab\" link under an embed\n * (`strings.iframeOpenInNewTab`).\n *\n * A COEP-blocked iframe fires no event the parent page can observe, so\n * without this the user sees an unexplained blank frame.\n *\n * - `'auto'` (default) — only when the page is cross-origin isolated\n * (`window.crossOriginIsolated`). That flag needs COOP `same-origin` AND\n * COEP, so a host that sends COEP alone still blocks embeds while the\n * flag is false: set `'always'` there. Read after mount, never during\n * render, so SSR markup and hydration agree.\n * - `'always'` / `'never'` — unconditional.\n */\n iframeFallbackLink?: 'auto' | 'always' | 'never'\n\n /**\n * Where `ChartJSRenderer` enables wheel-zoom / drag-pan / pinch on a chart\n * (through the optional `chartjs-plugin-zoom` peer dependency — absent, the\n * chart renders exactly as it does without this setting).\n *\n * Hijacking the mouse wheel on a component sitting inline in a scrolling\n * chat feed is hostile: the user scrolls the conversation and the chart eats\n * the gesture. So zoom belongs to a surface that OWNS its viewport, which\n * here is `ExpandableWrapper`'s fullscreen modal.\n *\n * - `'expanded'` (default) — only inside the fullscreen modal.\n * - `'always'` — inline as well. For a host that lays charts out in a\n * dashboard rather than in a feed, where the wheel has nothing to steal.\n * - `'never'` — off everywhere; the plugin is never registered.\n *\n * @since 6.22.0\n */\n chartZoom?: 'expanded' | 'always' | 'never'\n}\n\n/**\n * Defaults. Chosen so a host that sends no COEP header sees no change from\n * 6.20.0 apart from the fallback link, which `'auto'` keeps hidden there —\n * and, since 6.22.0, so no inline component ever captures the wheel\n * (`chartZoom: 'expanded'`).\n *\n * Typed `Required<MCPUIConfig>`: the interface's fields are optional so that\n * adding one stays backward compatible, and this annotation is what keeps a\n * new key from shipping without a default.\n */\nexport const DEFAULT_MCPUI_CONFIG: Required<MCPUIConfig> = {\n iframeCredentialless: 'auto',\n customTrustedIframeDomains: [],\n iframePolicy: 'strict',\n customIframeDomains: [],\n iframeFallbackLink: 'auto',\n chartZoom: 'expanded',\n}\n\n/**\n * Deliberately typed with the PARTIAL `MCPUIConfig`, not `Required<…>`: a\n * host that bypasses `MCPUIConfigProvider` and feeds this provider directly\n * may pass whichever keys it cares about, and `useMCPUIConfig` fills the\n * rest. Widening it this way only ever accepts more than before.\n */\nexport const MCPUIConfigContext = createContext<MCPUIConfig>(DEFAULT_MCPUI_CONFIG)\n\n/**\n * Reads the active host config, resolved: every key is present, whether it\n * came from the provider or from `DEFAULT_MCPUI_CONFIG`. Returns the defaults\n * outright when no `<MCPUIConfigProvider>` is mounted above.\n */\nexport function useMCPUIConfig(): Required<MCPUIConfig> {\n return mergeProps(DEFAULT_MCPUI_CONFIG, useContext(MCPUIConfigContext))\n}\n\nexport interface MCPUIConfigProviderProps {\n /**\n * Partial override of the host config. Any key left unset falls back to\n * `DEFAULT_MCPUI_CONFIG`.\n */\n config?: Partial<MCPUIConfig>\n children: JSX.Element\n}\n\n/**\n * Provides the host config to every MCP-UI renderer below it.\n * Merges the partial `config` override over the defaults.\n */\nexport function MCPUIConfigProvider(props: MCPUIConfigProviderProps): JSX.Element {\n // The function source keeps replacement `config` objects reactive while\n // mergeProps fills any omitted key without taking a one-time snapshot.\n const value = mergeProps(DEFAULT_MCPUI_CONFIG, () => props.config)\n return (\n <MCPUIConfigContext.Provider value={value}>\n {props.children}\n </MCPUIConfigContext.Provider>\n )\n}\n"],"names":["DEFAULT_MCPUI_CONFIG","iframeCredentialless","customTrustedIframeDomains","iframePolicy","customIframeDomains","iframeFallbackLink","chartZoom","MCPUIConfigContext","createContext","useMCPUIConfig","mergeProps","useContext","MCPUIConfigProvider","props","value","config","_$createComponent","Provider","children"],"mappings":";;;;AAyJO,MAAMA,uBAA8C;AAAA,EACzDC,sBAAsB;AAAA,EACtBC,4BAA4B,CAAA;AAAA,EAC5BC,cAAc;AAAA,EACdC,qBAAqB,CAAA;AAAA,EACrBC,oBAAoB;AAAA,EACpBC,WAAW;AACb;AAQO,MAAMC,qBAAqBC,QAAAA,cAA2BR,oBAAoB;AAO1E,SAASS,iBAAwC;AACtD,SAAOC,mBAAWV,sBAAsBW,QAAAA,WAAWJ,kBAAkB,CAAC;AACxE;AAeO,SAASK,oBAAoBC,OAA8C;AAGhF,QAAMC,QAAQJ,QAAAA,WAAWV,sBAAsB,MAAMa,MAAME,MAAM;AACjE,SAAAC,IAAAA,gBACGT,mBAAmBU,UAAQ;AAAA,IAACH;AAAAA,IAAY,IAAAI,WAAA;AAAA,aACtCL,MAAMK;AAAAA,IAAQ;AAAA,EAAA,CAAA;AAGrB;;;;;"}
|
|
1
|
+
{"version":3,"file":"MCPUIConfigContext.cjs","sources":["../../src/context/MCPUIConfigContext.tsx"],"sourcesContent":["/**\n * MCPUIConfigContext — host-level rendering policy: the library's iframes\n * (v6.21.0) and, since v6.22.0, where a chart may capture the wheel.\n *\n * @since v6.21.0\n *\n * ## Why\n *\n * A host that serves `Cross-Origin-Embedder-Policy: credentialless` makes the\n * browser refuse every cross-origin iframe whose own document does not send a\n * COEP header — which is YouTube, Vimeo, Google Docs, Notion and nearly all of\n * `DEFAULT_IFRAME_DOMAINS`. The escape hatch is the boolean HTML attribute\n * `credentialless` on the `<iframe>` itself: the document then loads, but\n * without access to the cookies and storage of its own origin.\n *\n * That trade-off is free for a public video or chart and fatal for an\n * authenticated embed, so the library keys it on the distinction it already\n * makes: `TRUSTED_IFRAME_DOMAINS` (the hosts that receive `allow-same-origin`\n * because they need their own cookies) do NOT get the attribute; everything\n * else does. This context lets a host override that, add its own trusted\n * hosts, and control the \"open in a new tab\" fallback link.\n *\n * ## Scope — policy only, NOT strings\n *\n * Text lives in `MCPUIStrings` (`MCPUIStringsContext`). This context carries\n * only behavioural switches, and like the strings context every renderer works\n * standalone: with no provider mounted, `DEFAULT_MCPUI_CONFIG` applies.\n *\n * @example\n * ```tsx\n * import { MCPUIConfigProvider } from '@seed-ship/mcp-ui-solid'\n *\n * <MCPUIConfigProvider config={{ customTrustedIframeDomains: ['embed.acme.com'] }}>\n * <App />\n * </MCPUIConfigProvider>\n * ```\n */\n\nimport { createContext, mergeProps, useContext, type JSX } from 'solid-js'\nimport type { IframePolicy } from '../types'\n\n/**\n * Host-level rendering policy. Every field has a default — a provider passes\n * a partial override.\n *\n * ## Two names, because there are two jobs\n *\n * This type grows a key every time the library gains a policy switch, and\n * those releases are MINOR — so neither AUTHORING a config nor READING one\n * may break when a key appears. Those two demands pull in opposite\n * directions, and one name cannot serve both:\n *\n * - an author must be allowed to omit the new key, so the fields they write\n * have to be OPTIONAL;\n * - a reader assigning `const p: IframePolicy = config.iframePolicy` must not\n * suddenly face `undefined`, so the fields they read have to be REQUIRED.\n *\n * Hence {@link MCPUIConfigInput} (what a host writes — every field optional)\n * and {@link MCPUIConfig} (what the library hands back — every field\n * resolved). `MCPUIConfig` is derived from the input type, so the two can\n * never drift and a key is declared exactly once.\n *\n * Which one you name depends on the surface:\n *\n * - `<MCPUIConfigProvider config={…}>` takes `MCPUIConfigInput` — name that\n * type for a partial you build, and it merges the rest;\n * - `<MCPUIConfigContext.Provider value={…}>` takes the RESOLVED\n * `MCPUIConfig`, because that context is read as well as written, so a\n * direct provider hands over `{ ...DEFAULT_MCPUI_CONFIG, ...mine }`;\n * - anything you RECEIVE is `MCPUIConfig`, which is what\n * {@link useMCPUIConfig} returns.\n */\nexport interface MCPUIConfigInput {\n /**\n * When the library puts the boolean `credentialless` attribute on an\n * `<iframe>` it renders.\n *\n * - `'auto'` (default) — on every iframe whose host is NOT in\n * `TRUSTED_IFRAME_DOMAINS` (plus `customTrustedIframeDomains`). Those\n * hosts already ran without cookies, since their sandbox has no\n * `allow-same-origin`; the attribute is what unblocks them under COEP.\n * - `'always'` — on every iframe, trusted hosts included. An authenticated\n * embed will then render its login screen.\n * - `'never'` — never. The right value for a host that sends no COEP header\n * and does not want its embeds to lose their cookies.\n *\n * Chrome/Edge 110+ honour the attribute; Firefox ignores it (iframes stay\n * blocked while the host sends COEP); Safari ignores the COEP value itself,\n * so nothing is blocked there in the first place.\n */\n iframeCredentialless?: 'auto' | 'always' | 'never'\n\n /**\n * Extra hosts treated as trusted, on top of `TRUSTED_IFRAME_DOMAINS`:\n * no `credentialless` attribute, and `allow-same-origin` in the sandbox.\n * A subdomain of a listed host matches too.\n *\n * This only RECLASSIFIES a host the allow-list already accepts. To render an\n * iframe whose host is outside `DEFAULT_IFRAME_DOMAINS`, add it to\n * {@link MCPUIConfigInput.customIframeDomains} with `iframePolicy: 'extend'`.\n */\n customTrustedIframeDomains?: string[]\n\n /**\n * How `UIResourceRenderer` validates an `iframe` component's host:\n * `'strict'` (default) accepts `DEFAULT_IFRAME_DOMAINS` only, `'extend'`\n * also accepts {@link MCPUIConfigInput.customIframeDomains}.\n */\n iframePolicy?: IframePolicy\n\n /**\n * Extra hosts the allow-list accepts when `iframePolicy` is `'extend'`.\n * Without this, a component pointing at an unlisted host is replaced by the\n * validation card before any renderer runs.\n */\n customIframeDomains?: string[]\n\n /**\n * When the library renders an \"open in a new tab\" link under an embed\n * (`strings.iframeOpenInNewTab`).\n *\n * A COEP-blocked iframe fires no event the parent page can observe, so\n * without this the user sees an unexplained blank frame.\n *\n * - `'auto'` (default) — only when the page is cross-origin isolated\n * (`window.crossOriginIsolated`). That flag needs COOP `same-origin` AND\n * COEP, so a host that sends COEP alone still blocks embeds while the\n * flag is false: set `'always'` there. Read after mount, never during\n * render, so SSR markup and hydration agree.\n * - `'always'` / `'never'` — unconditional.\n */\n iframeFallbackLink?: 'auto' | 'always' | 'never'\n\n /**\n * Where `ChartJSRenderer` enables wheel-zoom / drag-pan / pinch on a chart\n * (through the optional `chartjs-plugin-zoom` peer dependency — absent, the\n * chart renders exactly as it does without this setting).\n *\n * Hijacking the mouse wheel on a component sitting inline in a scrolling\n * chat feed is hostile: the user scrolls the conversation and the chart eats\n * the gesture. So zoom belongs to a surface that OWNS its viewport, which\n * here is `ExpandableWrapper`'s fullscreen modal.\n *\n * - `'expanded'` (default) — only inside the fullscreen modal.\n * - `'always'` — inline as well. For a host that lays charts out in a\n * dashboard rather than in a feed, where the wheel has nothing to steal.\n * - `'never'` — off everywhere; the plugin is never registered.\n *\n * @since 6.22.0\n */\n chartZoom?: 'expanded' | 'always' | 'never'\n}\n\n/**\n * The resolved host policy: every key present. This is what the library hands\n * back, so a reader never null-checks a policy.\n *\n * Extends `Required<`{@link MCPUIConfigInput}`>` rather than declaring the\n * fields again, so a key exists in exactly one place and the two views cannot\n * drift. It remains an interface so existing consumers can extend or augment\n * the public contract as they could before 6.22.0.\n */\nexport interface MCPUIConfig extends Required<MCPUIConfigInput> {}\n\n/**\n * Defaults. Chosen so a host that sends no COEP header sees no change from\n * 6.20.0 apart from the fallback link, which `'auto'` keeps hidden there —\n * and, since 6.22.0, so no inline component ever captures the wheel\n * (`chartZoom: 'expanded'`).\n *\n * Typed `MCPUIConfig` (i.e. resolved): that annotation is what stops a new\n * key from shipping without a default.\n */\nexport const DEFAULT_MCPUI_CONFIG: MCPUIConfig = {\n iframeCredentialless: 'auto',\n customTrustedIframeDomains: [],\n iframePolicy: 'strict',\n customIframeDomains: [],\n iframeFallbackLink: 'auto',\n chartZoom: 'expanded',\n}\n\n/**\n * Typed with the RESOLVED view, because this context is read as well as\n * written: it is exported, so a consumer may call\n * `useContext(MCPUIConfigContext)` directly, and typing it as the input view\n * would hand them `IframePolicy | undefined` — exactly the regression this\n * whole split exists to undo.\n *\n * The cost lands on the rarer side: a host feeding this context directly\n * passes a COMPLETE value, `{ ...DEFAULT_MCPUI_CONFIG, ...mine }`. Anyone who\n * wants to pass only the keys they care about uses `MCPUIConfigProvider`,\n * whose `config` prop takes `Partial<`{@link MCPUIConfig}`>` and does that\n * merge. That preserves optional properties added through declaration\n * merging; {@link MCPUIConfigInput} remains the unaugmented built-in input\n * shape a host can name for ordinary authored configs.\n */\nexport const MCPUIConfigContext = createContext<MCPUIConfig>(DEFAULT_MCPUI_CONFIG)\n\n/**\n * Reads the active host config, resolved: every key is present, whether it\n * came from the provider or from `DEFAULT_MCPUI_CONFIG`. Returns the defaults\n * outright when no `<MCPUIConfigProvider>` is mounted above.\n */\nexport function useMCPUIConfig(): MCPUIConfig {\n return mergeProps(DEFAULT_MCPUI_CONFIG, useContext(MCPUIConfigContext))\n}\n\nexport interface MCPUIConfigProviderProps {\n /**\n * Partial override of the host config. Any key left unset falls back to\n * `DEFAULT_MCPUI_CONFIG`.\n */\n config?: Partial<MCPUIConfig>\n children: JSX.Element\n}\n\n/**\n * Provides the host config to every MCP-UI renderer below it.\n * Merges the partial `config` override over the defaults.\n */\nexport function MCPUIConfigProvider(props: MCPUIConfigProviderProps): JSX.Element {\n // The function source keeps replacement `config` objects reactive while\n // mergeProps fills any omitted key without taking a one-time snapshot.\n const value = mergeProps(DEFAULT_MCPUI_CONFIG, () => props.config)\n return (\n <MCPUIConfigContext.Provider value={value}>\n {props.children}\n </MCPUIConfigContext.Provider>\n )\n}\n"],"names":["DEFAULT_MCPUI_CONFIG","iframeCredentialless","customTrustedIframeDomains","iframePolicy","customIframeDomains","iframeFallbackLink","chartZoom","MCPUIConfigContext","createContext","useMCPUIConfig","mergeProps","useContext","MCPUIConfigProvider","props","value","config","_$createComponent","Provider","children"],"mappings":";;;;AA6KO,MAAMA,uBAAoC;AAAA,EAC/CC,sBAAsB;AAAA,EACtBC,4BAA4B,CAAA;AAAA,EAC5BC,cAAc;AAAA,EACdC,qBAAqB,CAAA;AAAA,EACrBC,oBAAoB;AAAA,EACpBC,WAAW;AACb;AAiBO,MAAMC,qBAAqBC,QAAAA,cAA2BR,oBAAoB;AAO1E,SAASS,iBAA8B;AAC5C,SAAOC,mBAAWV,sBAAsBW,QAAAA,WAAWJ,kBAAkB,CAAC;AACxE;AAeO,SAASK,oBAAoBC,OAA8C;AAGhF,QAAMC,QAAQJ,QAAAA,WAAWV,sBAAsB,MAAMa,MAAME,MAAM;AACjE,SAAAC,IAAAA,gBACGT,mBAAmBU,UAAQ;AAAA,IAACH;AAAAA,IAAY,IAAAI,WAAA;AAAA,aACtCL,MAAMK;AAAAA,IAAQ;AAAA,EAAA,CAAA;AAGrB;;;;;"}
|
|
@@ -41,24 +41,34 @@ import type { IframePolicy } from '../types';
|
|
|
41
41
|
* Host-level rendering policy. Every field has a default — a provider passes
|
|
42
42
|
* a partial override.
|
|
43
43
|
*
|
|
44
|
-
* ##
|
|
45
|
-
*
|
|
46
|
-
* This
|
|
47
|
-
*
|
|
48
|
-
* break
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* `
|
|
59
|
-
*
|
|
44
|
+
* ## Two names, because there are two jobs
|
|
45
|
+
*
|
|
46
|
+
* This type grows a key every time the library gains a policy switch, and
|
|
47
|
+
* those releases are MINOR — so neither AUTHORING a config nor READING one
|
|
48
|
+
* may break when a key appears. Those two demands pull in opposite
|
|
49
|
+
* directions, and one name cannot serve both:
|
|
50
|
+
*
|
|
51
|
+
* - an author must be allowed to omit the new key, so the fields they write
|
|
52
|
+
* have to be OPTIONAL;
|
|
53
|
+
* - a reader assigning `const p: IframePolicy = config.iframePolicy` must not
|
|
54
|
+
* suddenly face `undefined`, so the fields they read have to be REQUIRED.
|
|
55
|
+
*
|
|
56
|
+
* Hence {@link MCPUIConfigInput} (what a host writes — every field optional)
|
|
57
|
+
* and {@link MCPUIConfig} (what the library hands back — every field
|
|
58
|
+
* resolved). `MCPUIConfig` is derived from the input type, so the two can
|
|
59
|
+
* never drift and a key is declared exactly once.
|
|
60
|
+
*
|
|
61
|
+
* Which one you name depends on the surface:
|
|
62
|
+
*
|
|
63
|
+
* - `<MCPUIConfigProvider config={…}>` takes `MCPUIConfigInput` — name that
|
|
64
|
+
* type for a partial you build, and it merges the rest;
|
|
65
|
+
* - `<MCPUIConfigContext.Provider value={…}>` takes the RESOLVED
|
|
66
|
+
* `MCPUIConfig`, because that context is read as well as written, so a
|
|
67
|
+
* direct provider hands over `{ ...DEFAULT_MCPUI_CONFIG, ...mine }`;
|
|
68
|
+
* - anything you RECEIVE is `MCPUIConfig`, which is what
|
|
69
|
+
* {@link useMCPUIConfig} returns.
|
|
60
70
|
*/
|
|
61
|
-
export interface
|
|
71
|
+
export interface MCPUIConfigInput {
|
|
62
72
|
/**
|
|
63
73
|
* When the library puts the boolean `credentialless` attribute on an
|
|
64
74
|
* `<iframe>` it renders.
|
|
@@ -84,13 +94,13 @@ export interface MCPUIConfig {
|
|
|
84
94
|
*
|
|
85
95
|
* This only RECLASSIFIES a host the allow-list already accepts. To render an
|
|
86
96
|
* iframe whose host is outside `DEFAULT_IFRAME_DOMAINS`, add it to
|
|
87
|
-
* {@link
|
|
97
|
+
* {@link MCPUIConfigInput.customIframeDomains} with `iframePolicy: 'extend'`.
|
|
88
98
|
*/
|
|
89
99
|
customTrustedIframeDomains?: string[];
|
|
90
100
|
/**
|
|
91
101
|
* How `UIResourceRenderer` validates an `iframe` component's host:
|
|
92
102
|
* `'strict'` (default) accepts `DEFAULT_IFRAME_DOMAINS` only, `'extend'`
|
|
93
|
-
* also accepts {@link
|
|
103
|
+
* also accepts {@link MCPUIConfigInput.customIframeDomains}.
|
|
94
104
|
*/
|
|
95
105
|
iframePolicy?: IframePolicy;
|
|
96
106
|
/**
|
|
@@ -133,22 +143,41 @@ export interface MCPUIConfig {
|
|
|
133
143
|
*/
|
|
134
144
|
chartZoom?: 'expanded' | 'always' | 'never';
|
|
135
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* The resolved host policy: every key present. This is what the library hands
|
|
148
|
+
* back, so a reader never null-checks a policy.
|
|
149
|
+
*
|
|
150
|
+
* Extends `Required<`{@link MCPUIConfigInput}`>` rather than declaring the
|
|
151
|
+
* fields again, so a key exists in exactly one place and the two views cannot
|
|
152
|
+
* drift. It remains an interface so existing consumers can extend or augment
|
|
153
|
+
* the public contract as they could before 6.22.0.
|
|
154
|
+
*/
|
|
155
|
+
export interface MCPUIConfig extends Required<MCPUIConfigInput> {
|
|
156
|
+
}
|
|
136
157
|
/**
|
|
137
158
|
* Defaults. Chosen so a host that sends no COEP header sees no change from
|
|
138
159
|
* 6.20.0 apart from the fallback link, which `'auto'` keeps hidden there —
|
|
139
160
|
* and, since 6.22.0, so no inline component ever captures the wheel
|
|
140
161
|
* (`chartZoom: 'expanded'`).
|
|
141
162
|
*
|
|
142
|
-
* Typed `
|
|
143
|
-
*
|
|
144
|
-
* new key from shipping without a default.
|
|
163
|
+
* Typed `MCPUIConfig` (i.e. resolved): that annotation is what stops a new
|
|
164
|
+
* key from shipping without a default.
|
|
145
165
|
*/
|
|
146
|
-
export declare const DEFAULT_MCPUI_CONFIG:
|
|
166
|
+
export declare const DEFAULT_MCPUI_CONFIG: MCPUIConfig;
|
|
147
167
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
168
|
+
* Typed with the RESOLVED view, because this context is read as well as
|
|
169
|
+
* written: it is exported, so a consumer may call
|
|
170
|
+
* `useContext(MCPUIConfigContext)` directly, and typing it as the input view
|
|
171
|
+
* would hand them `IframePolicy | undefined` — exactly the regression this
|
|
172
|
+
* whole split exists to undo.
|
|
173
|
+
*
|
|
174
|
+
* The cost lands on the rarer side: a host feeding this context directly
|
|
175
|
+
* passes a COMPLETE value, `{ ...DEFAULT_MCPUI_CONFIG, ...mine }`. Anyone who
|
|
176
|
+
* wants to pass only the keys they care about uses `MCPUIConfigProvider`,
|
|
177
|
+
* whose `config` prop takes `Partial<`{@link MCPUIConfig}`>` and does that
|
|
178
|
+
* merge. That preserves optional properties added through declaration
|
|
179
|
+
* merging; {@link MCPUIConfigInput} remains the unaugmented built-in input
|
|
180
|
+
* shape a host can name for ordinary authored configs.
|
|
152
181
|
*/
|
|
153
182
|
export declare const MCPUIConfigContext: import("solid-js").Context<MCPUIConfig>;
|
|
154
183
|
/**
|
|
@@ -156,7 +185,7 @@ export declare const MCPUIConfigContext: import("solid-js").Context<MCPUIConfig>
|
|
|
156
185
|
* came from the provider or from `DEFAULT_MCPUI_CONFIG`. Returns the defaults
|
|
157
186
|
* outright when no `<MCPUIConfigProvider>` is mounted above.
|
|
158
187
|
*/
|
|
159
|
-
export declare function useMCPUIConfig():
|
|
188
|
+
export declare function useMCPUIConfig(): MCPUIConfig;
|
|
160
189
|
export interface MCPUIConfigProviderProps {
|
|
161
190
|
/**
|
|
162
191
|
* Partial override of the host config. Any key left unset falls back to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MCPUIConfigContext.d.ts","sourceRoot":"","sources":["../../src/context/MCPUIConfigContext.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EAAyC,KAAK,GAAG,EA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CAAC,CAAA;IAC7B,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAA;CACtB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,GAAG,CAAC,OAAO,CAShF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MCPUIConfigContext.js","sources":["../../src/context/MCPUIConfigContext.tsx"],"sourcesContent":["/**\n * MCPUIConfigContext — host-level rendering policy: the library's iframes\n * (v6.21.0) and, since v6.22.0, where a chart may capture the wheel.\n *\n * @since v6.21.0\n *\n * ## Why\n *\n * A host that serves `Cross-Origin-Embedder-Policy: credentialless` makes the\n * browser refuse every cross-origin iframe whose own document does not send a\n * COEP header — which is YouTube, Vimeo, Google Docs, Notion and nearly all of\n * `DEFAULT_IFRAME_DOMAINS`. The escape hatch is the boolean HTML attribute\n * `credentialless` on the `<iframe>` itself: the document then loads, but\n * without access to the cookies and storage of its own origin.\n *\n * That trade-off is free for a public video or chart and fatal for an\n * authenticated embed, so the library keys it on the distinction it already\n * makes: `TRUSTED_IFRAME_DOMAINS` (the hosts that receive `allow-same-origin`\n * because they need their own cookies) do NOT get the attribute; everything\n * else does. This context lets a host override that, add its own trusted\n * hosts, and control the \"open in a new tab\" fallback link.\n *\n * ## Scope — policy only, NOT strings\n *\n * Text lives in `MCPUIStrings` (`MCPUIStringsContext`). This context carries\n * only behavioural switches, and like the strings context every renderer works\n * standalone: with no provider mounted, `DEFAULT_MCPUI_CONFIG` applies.\n *\n * @example\n * ```tsx\n * import { MCPUIConfigProvider } from '@seed-ship/mcp-ui-solid'\n *\n * <MCPUIConfigProvider config={{ customTrustedIframeDomains: ['embed.acme.com'] }}>\n * <App />\n * </MCPUIConfigProvider>\n * ```\n */\n\nimport { createContext, mergeProps, useContext, type JSX } from 'solid-js'\nimport type { IframePolicy } from '../types'\n\n/**\n * Host-level rendering policy. Every field has a default — a provider passes\n * a partial override.\n *\n * ## Why every field is optional\n *\n * This interface grows a key every time the library gains a policy switch,\n * and those releases are MINOR. Were the fields required, adding one would\n * break the build of any consumer holding a COMPLETE `MCPUIConfig` value —\n * a typed constant, a helper that returns one, or a direct\n * `<MCPUIConfigContext.Provider value={…}>` — because their object would\n * suddenly miss a key. Nothing about their behaviour changed; only `tsc`\n * would fail. Optional fields make each new key additive.\n *\n * The completeness guarantee moves from the type to the two values that\n * actually need it, exactly as `MCPUIStrings` does it:\n * `DEFAULT_MCPUI_CONFIG` is `Required<MCPUIConfig>`, so forgetting a default\n * is a compile error HERE, and {@link useMCPUIConfig} returns\n * `Required<MCPUIConfig>`, so every renderer still reads a fully resolved\n * value and never has to null-check a policy.\n */\nexport interface MCPUIConfig {\n /**\n * When the library puts the boolean `credentialless` attribute on an\n * `<iframe>` it renders.\n *\n * - `'auto'` (default) — on every iframe whose host is NOT in\n * `TRUSTED_IFRAME_DOMAINS` (plus `customTrustedIframeDomains`). Those\n * hosts already ran without cookies, since their sandbox has no\n * `allow-same-origin`; the attribute is what unblocks them under COEP.\n * - `'always'` — on every iframe, trusted hosts included. An authenticated\n * embed will then render its login screen.\n * - `'never'` — never. The right value for a host that sends no COEP header\n * and does not want its embeds to lose their cookies.\n *\n * Chrome/Edge 110+ honour the attribute; Firefox ignores it (iframes stay\n * blocked while the host sends COEP); Safari ignores the COEP value itself,\n * so nothing is blocked there in the first place.\n */\n iframeCredentialless?: 'auto' | 'always' | 'never'\n\n /**\n * Extra hosts treated as trusted, on top of `TRUSTED_IFRAME_DOMAINS`:\n * no `credentialless` attribute, and `allow-same-origin` in the sandbox.\n * A subdomain of a listed host matches too.\n *\n * This only RECLASSIFIES a host the allow-list already accepts. To render an\n * iframe whose host is outside `DEFAULT_IFRAME_DOMAINS`, add it to\n * {@link MCPUIConfig.customIframeDomains} with `iframePolicy: 'extend'`.\n */\n customTrustedIframeDomains?: string[]\n\n /**\n * How `UIResourceRenderer` validates an `iframe` component's host:\n * `'strict'` (default) accepts `DEFAULT_IFRAME_DOMAINS` only, `'extend'`\n * also accepts {@link MCPUIConfig.customIframeDomains}.\n */\n iframePolicy?: IframePolicy\n\n /**\n * Extra hosts the allow-list accepts when `iframePolicy` is `'extend'`.\n * Without this, a component pointing at an unlisted host is replaced by the\n * validation card before any renderer runs.\n */\n customIframeDomains?: string[]\n\n /**\n * When the library renders an \"open in a new tab\" link under an embed\n * (`strings.iframeOpenInNewTab`).\n *\n * A COEP-blocked iframe fires no event the parent page can observe, so\n * without this the user sees an unexplained blank frame.\n *\n * - `'auto'` (default) — only when the page is cross-origin isolated\n * (`window.crossOriginIsolated`). That flag needs COOP `same-origin` AND\n * COEP, so a host that sends COEP alone still blocks embeds while the\n * flag is false: set `'always'` there. Read after mount, never during\n * render, so SSR markup and hydration agree.\n * - `'always'` / `'never'` — unconditional.\n */\n iframeFallbackLink?: 'auto' | 'always' | 'never'\n\n /**\n * Where `ChartJSRenderer` enables wheel-zoom / drag-pan / pinch on a chart\n * (through the optional `chartjs-plugin-zoom` peer dependency — absent, the\n * chart renders exactly as it does without this setting).\n *\n * Hijacking the mouse wheel on a component sitting inline in a scrolling\n * chat feed is hostile: the user scrolls the conversation and the chart eats\n * the gesture. So zoom belongs to a surface that OWNS its viewport, which\n * here is `ExpandableWrapper`'s fullscreen modal.\n *\n * - `'expanded'` (default) — only inside the fullscreen modal.\n * - `'always'` — inline as well. For a host that lays charts out in a\n * dashboard rather than in a feed, where the wheel has nothing to steal.\n * - `'never'` — off everywhere; the plugin is never registered.\n *\n * @since 6.22.0\n */\n chartZoom?: 'expanded' | 'always' | 'never'\n}\n\n/**\n * Defaults. Chosen so a host that sends no COEP header sees no change from\n * 6.20.0 apart from the fallback link, which `'auto'` keeps hidden there —\n * and, since 6.22.0, so no inline component ever captures the wheel\n * (`chartZoom: 'expanded'`).\n *\n * Typed `Required<MCPUIConfig>`: the interface's fields are optional so that\n * adding one stays backward compatible, and this annotation is what keeps a\n * new key from shipping without a default.\n */\nexport const DEFAULT_MCPUI_CONFIG: Required<MCPUIConfig> = {\n iframeCredentialless: 'auto',\n customTrustedIframeDomains: [],\n iframePolicy: 'strict',\n customIframeDomains: [],\n iframeFallbackLink: 'auto',\n chartZoom: 'expanded',\n}\n\n/**\n * Deliberately typed with the PARTIAL `MCPUIConfig`, not `Required<…>`: a\n * host that bypasses `MCPUIConfigProvider` and feeds this provider directly\n * may pass whichever keys it cares about, and `useMCPUIConfig` fills the\n * rest. Widening it this way only ever accepts more than before.\n */\nexport const MCPUIConfigContext = createContext<MCPUIConfig>(DEFAULT_MCPUI_CONFIG)\n\n/**\n * Reads the active host config, resolved: every key is present, whether it\n * came from the provider or from `DEFAULT_MCPUI_CONFIG`. Returns the defaults\n * outright when no `<MCPUIConfigProvider>` is mounted above.\n */\nexport function useMCPUIConfig(): Required<MCPUIConfig> {\n return mergeProps(DEFAULT_MCPUI_CONFIG, useContext(MCPUIConfigContext))\n}\n\nexport interface MCPUIConfigProviderProps {\n /**\n * Partial override of the host config. Any key left unset falls back to\n * `DEFAULT_MCPUI_CONFIG`.\n */\n config?: Partial<MCPUIConfig>\n children: JSX.Element\n}\n\n/**\n * Provides the host config to every MCP-UI renderer below it.\n * Merges the partial `config` override over the defaults.\n */\nexport function MCPUIConfigProvider(props: MCPUIConfigProviderProps): JSX.Element {\n // The function source keeps replacement `config` objects reactive while\n // mergeProps fills any omitted key without taking a one-time snapshot.\n const value = mergeProps(DEFAULT_MCPUI_CONFIG, () => props.config)\n return (\n <MCPUIConfigContext.Provider value={value}>\n {props.children}\n </MCPUIConfigContext.Provider>\n )\n}\n"],"names":["DEFAULT_MCPUI_CONFIG","iframeCredentialless","customTrustedIframeDomains","iframePolicy","customIframeDomains","iframeFallbackLink","chartZoom","MCPUIConfigContext","createContext","useMCPUIConfig","mergeProps","useContext","MCPUIConfigProvider","props","value","config","_$createComponent","Provider","children"],"mappings":";;AAyJO,MAAMA,uBAA8C;AAAA,EACzDC,sBAAsB;AAAA,EACtBC,4BAA4B,CAAA;AAAA,EAC5BC,cAAc;AAAA,EACdC,qBAAqB,CAAA;AAAA,EACrBC,oBAAoB;AAAA,EACpBC,WAAW;AACb;AAQO,MAAMC,qBAAqBC,cAA2BR,oBAAoB;AAO1E,SAASS,iBAAwC;AACtD,SAAOC,WAAWV,sBAAsBW,WAAWJ,kBAAkB,CAAC;AACxE;AAeO,SAASK,oBAAoBC,OAA8C;AAGhF,QAAMC,QAAQJ,WAAWV,sBAAsB,MAAMa,MAAME,MAAM;AACjE,SAAAC,gBACGT,mBAAmBU,UAAQ;AAAA,IAACH;AAAAA,IAAY,IAAAI,WAAA;AAAA,aACtCL,MAAMK;AAAAA,IAAQ;AAAA,EAAA,CAAA;AAGrB;"}
|
|
1
|
+
{"version":3,"file":"MCPUIConfigContext.js","sources":["../../src/context/MCPUIConfigContext.tsx"],"sourcesContent":["/**\n * MCPUIConfigContext — host-level rendering policy: the library's iframes\n * (v6.21.0) and, since v6.22.0, where a chart may capture the wheel.\n *\n * @since v6.21.0\n *\n * ## Why\n *\n * A host that serves `Cross-Origin-Embedder-Policy: credentialless` makes the\n * browser refuse every cross-origin iframe whose own document does not send a\n * COEP header — which is YouTube, Vimeo, Google Docs, Notion and nearly all of\n * `DEFAULT_IFRAME_DOMAINS`. The escape hatch is the boolean HTML attribute\n * `credentialless` on the `<iframe>` itself: the document then loads, but\n * without access to the cookies and storage of its own origin.\n *\n * That trade-off is free for a public video or chart and fatal for an\n * authenticated embed, so the library keys it on the distinction it already\n * makes: `TRUSTED_IFRAME_DOMAINS` (the hosts that receive `allow-same-origin`\n * because they need their own cookies) do NOT get the attribute; everything\n * else does. This context lets a host override that, add its own trusted\n * hosts, and control the \"open in a new tab\" fallback link.\n *\n * ## Scope — policy only, NOT strings\n *\n * Text lives in `MCPUIStrings` (`MCPUIStringsContext`). This context carries\n * only behavioural switches, and like the strings context every renderer works\n * standalone: with no provider mounted, `DEFAULT_MCPUI_CONFIG` applies.\n *\n * @example\n * ```tsx\n * import { MCPUIConfigProvider } from '@seed-ship/mcp-ui-solid'\n *\n * <MCPUIConfigProvider config={{ customTrustedIframeDomains: ['embed.acme.com'] }}>\n * <App />\n * </MCPUIConfigProvider>\n * ```\n */\n\nimport { createContext, mergeProps, useContext, type JSX } from 'solid-js'\nimport type { IframePolicy } from '../types'\n\n/**\n * Host-level rendering policy. Every field has a default — a provider passes\n * a partial override.\n *\n * ## Two names, because there are two jobs\n *\n * This type grows a key every time the library gains a policy switch, and\n * those releases are MINOR — so neither AUTHORING a config nor READING one\n * may break when a key appears. Those two demands pull in opposite\n * directions, and one name cannot serve both:\n *\n * - an author must be allowed to omit the new key, so the fields they write\n * have to be OPTIONAL;\n * - a reader assigning `const p: IframePolicy = config.iframePolicy` must not\n * suddenly face `undefined`, so the fields they read have to be REQUIRED.\n *\n * Hence {@link MCPUIConfigInput} (what a host writes — every field optional)\n * and {@link MCPUIConfig} (what the library hands back — every field\n * resolved). `MCPUIConfig` is derived from the input type, so the two can\n * never drift and a key is declared exactly once.\n *\n * Which one you name depends on the surface:\n *\n * - `<MCPUIConfigProvider config={…}>` takes `MCPUIConfigInput` — name that\n * type for a partial you build, and it merges the rest;\n * - `<MCPUIConfigContext.Provider value={…}>` takes the RESOLVED\n * `MCPUIConfig`, because that context is read as well as written, so a\n * direct provider hands over `{ ...DEFAULT_MCPUI_CONFIG, ...mine }`;\n * - anything you RECEIVE is `MCPUIConfig`, which is what\n * {@link useMCPUIConfig} returns.\n */\nexport interface MCPUIConfigInput {\n /**\n * When the library puts the boolean `credentialless` attribute on an\n * `<iframe>` it renders.\n *\n * - `'auto'` (default) — on every iframe whose host is NOT in\n * `TRUSTED_IFRAME_DOMAINS` (plus `customTrustedIframeDomains`). Those\n * hosts already ran without cookies, since their sandbox has no\n * `allow-same-origin`; the attribute is what unblocks them under COEP.\n * - `'always'` — on every iframe, trusted hosts included. An authenticated\n * embed will then render its login screen.\n * - `'never'` — never. The right value for a host that sends no COEP header\n * and does not want its embeds to lose their cookies.\n *\n * Chrome/Edge 110+ honour the attribute; Firefox ignores it (iframes stay\n * blocked while the host sends COEP); Safari ignores the COEP value itself,\n * so nothing is blocked there in the first place.\n */\n iframeCredentialless?: 'auto' | 'always' | 'never'\n\n /**\n * Extra hosts treated as trusted, on top of `TRUSTED_IFRAME_DOMAINS`:\n * no `credentialless` attribute, and `allow-same-origin` in the sandbox.\n * A subdomain of a listed host matches too.\n *\n * This only RECLASSIFIES a host the allow-list already accepts. To render an\n * iframe whose host is outside `DEFAULT_IFRAME_DOMAINS`, add it to\n * {@link MCPUIConfigInput.customIframeDomains} with `iframePolicy: 'extend'`.\n */\n customTrustedIframeDomains?: string[]\n\n /**\n * How `UIResourceRenderer` validates an `iframe` component's host:\n * `'strict'` (default) accepts `DEFAULT_IFRAME_DOMAINS` only, `'extend'`\n * also accepts {@link MCPUIConfigInput.customIframeDomains}.\n */\n iframePolicy?: IframePolicy\n\n /**\n * Extra hosts the allow-list accepts when `iframePolicy` is `'extend'`.\n * Without this, a component pointing at an unlisted host is replaced by the\n * validation card before any renderer runs.\n */\n customIframeDomains?: string[]\n\n /**\n * When the library renders an \"open in a new tab\" link under an embed\n * (`strings.iframeOpenInNewTab`).\n *\n * A COEP-blocked iframe fires no event the parent page can observe, so\n * without this the user sees an unexplained blank frame.\n *\n * - `'auto'` (default) — only when the page is cross-origin isolated\n * (`window.crossOriginIsolated`). That flag needs COOP `same-origin` AND\n * COEP, so a host that sends COEP alone still blocks embeds while the\n * flag is false: set `'always'` there. Read after mount, never during\n * render, so SSR markup and hydration agree.\n * - `'always'` / `'never'` — unconditional.\n */\n iframeFallbackLink?: 'auto' | 'always' | 'never'\n\n /**\n * Where `ChartJSRenderer` enables wheel-zoom / drag-pan / pinch on a chart\n * (through the optional `chartjs-plugin-zoom` peer dependency — absent, the\n * chart renders exactly as it does without this setting).\n *\n * Hijacking the mouse wheel on a component sitting inline in a scrolling\n * chat feed is hostile: the user scrolls the conversation and the chart eats\n * the gesture. So zoom belongs to a surface that OWNS its viewport, which\n * here is `ExpandableWrapper`'s fullscreen modal.\n *\n * - `'expanded'` (default) — only inside the fullscreen modal.\n * - `'always'` — inline as well. For a host that lays charts out in a\n * dashboard rather than in a feed, where the wheel has nothing to steal.\n * - `'never'` — off everywhere; the plugin is never registered.\n *\n * @since 6.22.0\n */\n chartZoom?: 'expanded' | 'always' | 'never'\n}\n\n/**\n * The resolved host policy: every key present. This is what the library hands\n * back, so a reader never null-checks a policy.\n *\n * Extends `Required<`{@link MCPUIConfigInput}`>` rather than declaring the\n * fields again, so a key exists in exactly one place and the two views cannot\n * drift. It remains an interface so existing consumers can extend or augment\n * the public contract as they could before 6.22.0.\n */\nexport interface MCPUIConfig extends Required<MCPUIConfigInput> {}\n\n/**\n * Defaults. Chosen so a host that sends no COEP header sees no change from\n * 6.20.0 apart from the fallback link, which `'auto'` keeps hidden there —\n * and, since 6.22.0, so no inline component ever captures the wheel\n * (`chartZoom: 'expanded'`).\n *\n * Typed `MCPUIConfig` (i.e. resolved): that annotation is what stops a new\n * key from shipping without a default.\n */\nexport const DEFAULT_MCPUI_CONFIG: MCPUIConfig = {\n iframeCredentialless: 'auto',\n customTrustedIframeDomains: [],\n iframePolicy: 'strict',\n customIframeDomains: [],\n iframeFallbackLink: 'auto',\n chartZoom: 'expanded',\n}\n\n/**\n * Typed with the RESOLVED view, because this context is read as well as\n * written: it is exported, so a consumer may call\n * `useContext(MCPUIConfigContext)` directly, and typing it as the input view\n * would hand them `IframePolicy | undefined` — exactly the regression this\n * whole split exists to undo.\n *\n * The cost lands on the rarer side: a host feeding this context directly\n * passes a COMPLETE value, `{ ...DEFAULT_MCPUI_CONFIG, ...mine }`. Anyone who\n * wants to pass only the keys they care about uses `MCPUIConfigProvider`,\n * whose `config` prop takes `Partial<`{@link MCPUIConfig}`>` and does that\n * merge. That preserves optional properties added through declaration\n * merging; {@link MCPUIConfigInput} remains the unaugmented built-in input\n * shape a host can name for ordinary authored configs.\n */\nexport const MCPUIConfigContext = createContext<MCPUIConfig>(DEFAULT_MCPUI_CONFIG)\n\n/**\n * Reads the active host config, resolved: every key is present, whether it\n * came from the provider or from `DEFAULT_MCPUI_CONFIG`. Returns the defaults\n * outright when no `<MCPUIConfigProvider>` is mounted above.\n */\nexport function useMCPUIConfig(): MCPUIConfig {\n return mergeProps(DEFAULT_MCPUI_CONFIG, useContext(MCPUIConfigContext))\n}\n\nexport interface MCPUIConfigProviderProps {\n /**\n * Partial override of the host config. Any key left unset falls back to\n * `DEFAULT_MCPUI_CONFIG`.\n */\n config?: Partial<MCPUIConfig>\n children: JSX.Element\n}\n\n/**\n * Provides the host config to every MCP-UI renderer below it.\n * Merges the partial `config` override over the defaults.\n */\nexport function MCPUIConfigProvider(props: MCPUIConfigProviderProps): JSX.Element {\n // The function source keeps replacement `config` objects reactive while\n // mergeProps fills any omitted key without taking a one-time snapshot.\n const value = mergeProps(DEFAULT_MCPUI_CONFIG, () => props.config)\n return (\n <MCPUIConfigContext.Provider value={value}>\n {props.children}\n </MCPUIConfigContext.Provider>\n )\n}\n"],"names":["DEFAULT_MCPUI_CONFIG","iframeCredentialless","customTrustedIframeDomains","iframePolicy","customIframeDomains","iframeFallbackLink","chartZoom","MCPUIConfigContext","createContext","useMCPUIConfig","mergeProps","useContext","MCPUIConfigProvider","props","value","config","_$createComponent","Provider","children"],"mappings":";;AA6KO,MAAMA,uBAAoC;AAAA,EAC/CC,sBAAsB;AAAA,EACtBC,4BAA4B,CAAA;AAAA,EAC5BC,cAAc;AAAA,EACdC,qBAAqB,CAAA;AAAA,EACrBC,oBAAoB;AAAA,EACpBC,WAAW;AACb;AAiBO,MAAMC,qBAAqBC,cAA2BR,oBAAoB;AAO1E,SAASS,iBAA8B;AAC5C,SAAOC,WAAWV,sBAAsBW,WAAWJ,kBAAkB,CAAC;AACxE;AAeO,SAASK,oBAAoBC,OAA8C;AAGhF,QAAMC,QAAQJ,WAAWV,sBAAsB,MAAMa,MAAME,MAAM;AACjE,SAAAC,gBACGT,mBAAmBU,UAAQ;AAAA,IAACH;AAAAA,IAAY,IAAAI,WAAA;AAAA,aACtCL,MAAMK;AAAAA,IAAQ;AAAA,EAAA,CAAA;AAGrB;"}
|