@seed-ship/mcp-ui-solid 6.23.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 +125 -0
- package/README.md +107 -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 +237 -199
- package/dist/components/UIResourceRenderer.cjs.map +1 -1
- package/dist/components/UIResourceRenderer.d.ts.map +1 -1
- package/dist/components/UIResourceRenderer.js +237 -199
- 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/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/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/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 +3 -3
- 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 +42 -9
- package/src/components/chart-data-table.ts +50 -6
- package/src/components/chart-missing-plugin.ts +334 -0
- package/src/context/MCPUIStringsContext.tsx +76 -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/missing-value.ts +127 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Missing values — one definition shared by tables, chart data views,
|
|
3
|
+
* degraded projections, chart validation and the chart renderer.
|
|
4
|
+
*
|
|
5
|
+
* @since v6.24.0
|
|
6
|
+
*
|
|
7
|
+
* A missing value is a value the payload says EXISTS but was not observed:
|
|
8
|
+
* `null` in a chart dataset (or as a point's `y`), `null` / `undefined` in a
|
|
9
|
+
* table cell. It is not a zero, and it is not the absence of a row or of a
|
|
10
|
+
* label: every view keeps its slot and marks it.
|
|
11
|
+
*
|
|
12
|
+
* Runtime-free on purpose (no `solid-js`): the pure projections in
|
|
13
|
+
* `chart-data-table.ts` and `degraded-projections.ts`, and `validation.ts`
|
|
14
|
+
* (published as the `/validation` subpath), import it.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** The glyph a table cell shows for a missing value — `renderCellValue`'s historical `-`. */
|
|
18
|
+
export const MISSING_VALUE_MARKER = '-'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Chart types that encode a value as a share of a whole (or, for polar area,
|
|
22
|
+
* as a wedge whose emptiness reads as zero). Chart.js parses a `null` share
|
|
23
|
+
* as `0`, so these types refuse missing values instead of drawing them.
|
|
24
|
+
*/
|
|
25
|
+
export const PART_TO_WHOLE_CHART_TYPES: ReadonlySet<string> = new Set([
|
|
26
|
+
'pie',
|
|
27
|
+
'doughnut',
|
|
28
|
+
'polarArea',
|
|
29
|
+
])
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Whether a raw TABLE cell value is displayed as {@link MISSING_VALUE_MARKER}.
|
|
33
|
+
*
|
|
34
|
+
* Mirrors the rules `renderCellValue` applies before any formatting — `null`,
|
|
35
|
+
* `undefined`, and a string that is empty or the word `undefined` once the
|
|
36
|
+
* backend's `"X – undefined"` debris is stripped — plus the literal marker
|
|
37
|
+
* itself (whitespace around it aside, which a table cell does not render),
|
|
38
|
+
* since it looks identical on screen and so must read identically.
|
|
39
|
+
*
|
|
40
|
+
* Objects are never missing here: `renderCellValue` renders them (link,
|
|
41
|
+
* name, or escaped JSON).
|
|
42
|
+
*/
|
|
43
|
+
export function isMissingCellValue(value: unknown): boolean {
|
|
44
|
+
if (value === null || value === undefined) return true
|
|
45
|
+
if (typeof value === 'object') return false
|
|
46
|
+
const cleaned = stripUndefinedDebris(String(value)).trim()
|
|
47
|
+
return cleaned === '' || cleaned === MISSING_VALUE_MARKER || cleaned.toLowerCase() === 'undefined'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Removes the `"Text – undefined"` / `"undefined – Text"` debris some
|
|
52
|
+
* backends concatenate. Shared with `renderCellValue` so both apply the very
|
|
53
|
+
* same cleanup.
|
|
54
|
+
*/
|
|
55
|
+
export function stripUndefinedDebris(value: string): string {
|
|
56
|
+
return value.replace(/\s*[–-]\s*undefined\s*$/gi, '').replace(/^undefined\s*[–-]\s*/gi, '')
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Whether one CHART data entry is missing: `null` / `undefined`, a non-finite
|
|
61
|
+
* number (Chart.js parses those to `null` too), or a point whose `y` is.
|
|
62
|
+
*/
|
|
63
|
+
export function isMissingChartValue(value: unknown): boolean {
|
|
64
|
+
if (value === null || value === undefined) return true
|
|
65
|
+
if (typeof value === 'number') return !Number.isFinite(value)
|
|
66
|
+
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
67
|
+
const y = (value as { y?: unknown }).y
|
|
68
|
+
return y === null || y === undefined || (typeof y === 'number' && !Number.isFinite(y))
|
|
69
|
+
}
|
|
70
|
+
return false
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* What a chart's missing values amount to.
|
|
75
|
+
*
|
|
76
|
+
* Only ENTRIES count: an explicit `null` (or non-finite number, or a point
|
|
77
|
+
* whose `y` is one). A dataset with no entry at all (`data: []`) is not
|
|
78
|
+
* "missing" — it is how 6.23.0 and earlier payloads said "nothing yet", e.g.
|
|
79
|
+
* while streaming, and it keeps rendering exactly as it did then.
|
|
80
|
+
*/
|
|
81
|
+
export interface ChartMissingSummary {
|
|
82
|
+
/** At least one entry of one dataset is missing. */
|
|
83
|
+
hasMissing: boolean
|
|
84
|
+
/** Per dataset, in order: it has entries and every one of them is missing. */
|
|
85
|
+
fullyMissing: boolean[]
|
|
86
|
+
/**
|
|
87
|
+
* Per dataset, in order: at least one observed value AND at least one
|
|
88
|
+
* missing entry — the series a reader actually sees broken.
|
|
89
|
+
*/
|
|
90
|
+
partiallyMissing: boolean[]
|
|
91
|
+
/** Something is missing and no dataset has a single observed value: nothing to plot. */
|
|
92
|
+
allMissing: boolean
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
interface ChartDataLike {
|
|
96
|
+
data?: {
|
|
97
|
+
datasets?: Array<{ data?: unknown[] } | null | undefined>
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Summarises the missing values of a chart payload. Never throws on a malformed payload. */
|
|
102
|
+
export function summarizeChartMissing(params: ChartDataLike | null | undefined): ChartMissingSummary {
|
|
103
|
+
const datasets = Array.isArray(params?.data?.datasets) ? params.data.datasets : []
|
|
104
|
+
const fullyMissing: boolean[] = []
|
|
105
|
+
const partiallyMissing: boolean[] = []
|
|
106
|
+
let anyMissing = false
|
|
107
|
+
let anyObserved = false
|
|
108
|
+
for (const dataset of datasets) {
|
|
109
|
+
const data = Array.isArray(dataset?.data) ? dataset.data : []
|
|
110
|
+
let observed = 0
|
|
111
|
+
let missing = 0
|
|
112
|
+
for (const value of data) {
|
|
113
|
+
if (isMissingChartValue(value)) missing += 1
|
|
114
|
+
else observed += 1
|
|
115
|
+
}
|
|
116
|
+
fullyMissing.push(missing > 0 && observed === 0)
|
|
117
|
+
partiallyMissing.push(observed > 0 && missing > 0)
|
|
118
|
+
anyMissing ||= missing > 0
|
|
119
|
+
anyObserved ||= observed > 0
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
hasMissing: anyMissing,
|
|
123
|
+
fullyMissing,
|
|
124
|
+
partiallyMissing,
|
|
125
|
+
allMissing: anyMissing && !anyObserved,
|
|
126
|
+
}
|
|
127
|
+
}
|