@vertesia/fusion-ux 1.3.0 → 1.4.0-dev.20260615.042033Z
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/LICENSE +198 -10
- package/lib/fusion-fragment/ChartRenderer.d.ts.map +1 -0
- package/lib/{esm/fusion-fragment → fusion-fragment}/ChartRenderer.js +8 -6
- package/lib/fusion-fragment/ChartRenderer.js.map +1 -0
- package/lib/{types/fusion-fragment → fusion-fragment}/FieldRenderer.d.ts +1 -1
- package/lib/fusion-fragment/FieldRenderer.d.ts.map +1 -0
- package/lib/{esm/fusion-fragment → fusion-fragment}/FieldRenderer.js +14 -8
- package/lib/fusion-fragment/FieldRenderer.js.map +1 -0
- package/lib/{types/fusion-fragment → fusion-fragment}/FusionFragmentContext.d.ts +3 -3
- package/lib/fusion-fragment/FusionFragmentContext.d.ts.map +1 -0
- package/lib/{esm/fusion-fragment → fusion-fragment}/FusionFragmentContext.js +2 -2
- package/lib/fusion-fragment/FusionFragmentContext.js.map +1 -0
- package/lib/fusion-fragment/FusionFragmentHandler.d.ts.map +1 -0
- package/lib/{esm/fusion-fragment → fusion-fragment}/FusionFragmentHandler.js +7 -14
- package/lib/fusion-fragment/FusionFragmentHandler.js.map +1 -0
- package/lib/fusion-fragment/FusionFragmentRenderer.d.ts.map +1 -0
- package/lib/{esm/fusion-fragment → fusion-fragment}/FusionFragmentRenderer.js +2 -2
- package/lib/fusion-fragment/FusionFragmentRenderer.js.map +1 -0
- package/lib/{types/fusion-fragment → fusion-fragment}/SectionRenderer.d.ts +1 -1
- package/lib/fusion-fragment/SectionRenderer.d.ts.map +1 -0
- package/lib/{esm/fusion-fragment → fusion-fragment}/SectionRenderer.js +12 -5
- package/lib/fusion-fragment/SectionRenderer.js.map +1 -0
- package/lib/fusion-fragment/TableRenderer.d.ts.map +1 -0
- package/lib/{esm/fusion-fragment → fusion-fragment}/TableRenderer.js +9 -7
- package/lib/fusion-fragment/TableRenderer.js.map +1 -0
- package/lib/{types/fusion-fragment → fusion-fragment}/index.d.ts +4 -4
- package/lib/fusion-fragment/index.d.ts.map +1 -0
- package/lib/{esm/fusion-fragment → fusion-fragment}/index.js +4 -4
- package/lib/fusion-fragment/index.js.map +1 -0
- package/lib/{types/index.d.ts → index.d.ts} +4 -4
- package/lib/index.d.ts.map +1 -0
- package/lib/{esm/index.js → index.js} +4 -4
- package/lib/index.js.map +1 -0
- package/lib/{types/render → render}/index.d.ts +1 -1
- package/lib/render/index.d.ts.map +1 -0
- package/lib/{esm/render → render}/index.js +1 -1
- package/lib/render/index.js.map +1 -0
- package/lib/render/textPreview.d.ts.map +1 -0
- package/lib/{esm/render → render}/textPreview.js +12 -9
- package/lib/render/textPreview.js.map +1 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js.map +1 -0
- package/lib/validation/formatErrors.d.ts.map +1 -0
- package/lib/{esm/validation → validation}/formatErrors.js +1 -1
- package/lib/validation/formatErrors.js.map +1 -0
- package/lib/validation/fuzzyMatch.d.ts.map +1 -0
- package/lib/{esm/validation → validation}/fuzzyMatch.js +3 -4
- package/lib/validation/fuzzyMatch.js.map +1 -0
- package/lib/validation/index.d.ts +8 -0
- package/lib/validation/index.d.ts.map +1 -0
- package/lib/validation/index.js +8 -0
- package/lib/validation/index.js.map +1 -0
- package/lib/{types/validation → validation}/schemas.d.ts +1 -1
- package/lib/validation/schemas.d.ts.map +1 -0
- package/lib/{esm/validation → validation}/schemas.js +25 -25
- package/lib/validation/schemas.js.map +1 -0
- package/lib/validation/validateTemplate.d.ts.map +1 -0
- package/lib/{esm/validation → validation}/validateTemplate.js +23 -21
- package/lib/validation/validateTemplate.js.map +1 -0
- package/lib/vertesia-fusion-ux.js +1 -1
- package/lib/vertesia-fusion-ux.js.map +1 -1
- package/package.json +23 -35
- package/src/fusion-fragment/ChartRenderer.tsx +95 -96
- package/src/fusion-fragment/FieldRenderer.tsx +173 -174
- package/src/fusion-fragment/FusionFragmentContext.tsx +31 -37
- package/src/fusion-fragment/FusionFragmentHandler.tsx +214 -223
- package/src/fusion-fragment/FusionFragmentRenderer.tsx +102 -107
- package/src/fusion-fragment/SectionRenderer.tsx +174 -169
- package/src/fusion-fragment/TableRenderer.tsx +175 -171
- package/src/fusion-fragment/index.ts +11 -11
- package/src/index.ts +42 -45
- package/src/render/index.ts +3 -3
- package/src/render/textPreview.ts +183 -186
- package/src/types.ts +174 -174
- package/src/validation/formatErrors.ts +86 -86
- package/src/validation/fuzzyMatch.ts +69 -77
- package/src/validation/index.ts +3 -3
- package/src/validation/schemas.ts +120 -120
- package/src/validation/validateTemplate.ts +225 -226
- package/lib/esm/fusion-fragment/ChartRenderer.js.map +0 -1
- package/lib/esm/fusion-fragment/FieldRenderer.js.map +0 -1
- package/lib/esm/fusion-fragment/FusionFragmentContext.js.map +0 -1
- package/lib/esm/fusion-fragment/FusionFragmentHandler.js.map +0 -1
- package/lib/esm/fusion-fragment/FusionFragmentRenderer.js.map +0 -1
- package/lib/esm/fusion-fragment/SectionRenderer.js.map +0 -1
- package/lib/esm/fusion-fragment/TableRenderer.js.map +0 -1
- package/lib/esm/fusion-fragment/index.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/render/index.js.map +0 -1
- package/lib/esm/render/textPreview.js.map +0 -1
- package/lib/esm/types.js.map +0 -1
- package/lib/esm/validation/formatErrors.js.map +0 -1
- package/lib/esm/validation/fuzzyMatch.js.map +0 -1
- package/lib/esm/validation/index.js +0 -8
- package/lib/esm/validation/index.js.map +0 -1
- package/lib/esm/validation/schemas.js.map +0 -1
- package/lib/esm/validation/validateTemplate.js.map +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/types/fusion-fragment/ChartRenderer.d.ts.map +0 -1
- package/lib/types/fusion-fragment/FieldRenderer.d.ts.map +0 -1
- package/lib/types/fusion-fragment/FusionFragmentContext.d.ts.map +0 -1
- package/lib/types/fusion-fragment/FusionFragmentHandler.d.ts.map +0 -1
- package/lib/types/fusion-fragment/FusionFragmentRenderer.d.ts.map +0 -1
- package/lib/types/fusion-fragment/SectionRenderer.d.ts.map +0 -1
- package/lib/types/fusion-fragment/TableRenderer.d.ts.map +0 -1
- package/lib/types/fusion-fragment/index.d.ts.map +0 -1
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/render/index.d.ts.map +0 -1
- package/lib/types/render/textPreview.d.ts.map +0 -1
- package/lib/types/types.d.ts.map +0 -1
- package/lib/types/validation/formatErrors.d.ts.map +0 -1
- package/lib/types/validation/fuzzyMatch.d.ts.map +0 -1
- package/lib/types/validation/index.d.ts +0 -8
- package/lib/types/validation/index.d.ts.map +0 -1
- package/lib/types/validation/schemas.d.ts.map +0 -1
- package/lib/types/validation/validateTemplate.d.ts.map +0 -1
- /package/lib/{types/fusion-fragment → fusion-fragment}/ChartRenderer.d.ts +0 -0
- /package/lib/{types/fusion-fragment → fusion-fragment}/FusionFragmentHandler.d.ts +0 -0
- /package/lib/{types/fusion-fragment → fusion-fragment}/FusionFragmentRenderer.d.ts +0 -0
- /package/lib/{types/fusion-fragment → fusion-fragment}/TableRenderer.d.ts +0 -0
- /package/lib/{types/render → render}/textPreview.d.ts +0 -0
- /package/lib/{types/types.d.ts → types.d.ts} +0 -0
- /package/lib/{esm/types.js → types.js} +0 -0
- /package/lib/{types/validation → validation}/formatErrors.d.ts +0 -0
- /package/lib/{types/validation → validation}/fuzzyMatch.d.ts +0 -0
- /package/lib/{types/validation → validation}/validateTemplate.d.ts +0 -0
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Two-stage validation: Schema (AJV) + Semantic (custom)
|
|
4
4
|
*/
|
|
5
5
|
import Ajv from 'ajv';
|
|
6
|
-
import { FragmentTemplateSchema } from './schemas.js';
|
|
7
6
|
import { findClosestKey } from './fuzzyMatch.js';
|
|
7
|
+
import { FragmentTemplateSchema } from './schemas.js';
|
|
8
8
|
// Create AJV instance with all errors enabled
|
|
9
9
|
const ajv = new Ajv({ allErrors: true, verbose: true });
|
|
10
10
|
// Compile the schema
|
|
@@ -53,14 +53,14 @@ export function validateTemplate(template, dataKeys) {
|
|
|
53
53
|
errors.push({
|
|
54
54
|
path: `${sectionPath}.columns`,
|
|
55
55
|
message: 'Table layout requires columns array',
|
|
56
|
-
suggestion: 'Add columns: [{ header: "...", key: "..." }]'
|
|
56
|
+
suggestion: 'Add columns: [{ header: "...", key: "..." }]',
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
if (!section.dataKey) {
|
|
60
60
|
errors.push({
|
|
61
61
|
path: `${sectionPath}.dataKey`,
|
|
62
62
|
message: 'Table layout requires dataKey to reference the data array',
|
|
63
|
-
suggestion: 'Add dataKey: "yourArrayKey"'
|
|
63
|
+
suggestion: 'Add dataKey: "yourArrayKey"',
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
else if (!dataKeys.includes(section.dataKey)) {
|
|
@@ -68,7 +68,7 @@ export function validateTemplate(template, dataKeys) {
|
|
|
68
68
|
errors.push({
|
|
69
69
|
path: `${sectionPath}.dataKey`,
|
|
70
70
|
message: `Unknown dataKey '${section.dataKey}'`,
|
|
71
|
-
suggestion: closest ? `Did you mean '${closest}'?` : undefined
|
|
71
|
+
suggestion: closest ? `Did you mean '${closest}'?` : undefined,
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
// Skip field validation for table sections
|
|
@@ -80,7 +80,7 @@ export function validateTemplate(template, dataKeys) {
|
|
|
80
80
|
errors.push({
|
|
81
81
|
path: `${sectionPath}.chart`,
|
|
82
82
|
message: 'Chart layout requires a chart specification',
|
|
83
|
-
suggestion: 'Add chart: { spec: { mark: "bar", encoding: {...} } }'
|
|
83
|
+
suggestion: 'Add chart: { spec: { mark: "bar", encoding: {...} } }',
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
@@ -89,7 +89,7 @@ export function validateTemplate(template, dataKeys) {
|
|
|
89
89
|
errors.push({
|
|
90
90
|
path: `${sectionPath}.chart.spec`,
|
|
91
91
|
message: 'Chart requires a Vega-Lite spec',
|
|
92
|
-
suggestion: 'Add spec: { mark: "bar", encoding: {...}, data: {...} }'
|
|
92
|
+
suggestion: 'Add spec: { mark: "bar", encoding: {...}, data: {...} }',
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
else {
|
|
@@ -100,7 +100,7 @@ export function validateTemplate(template, dataKeys) {
|
|
|
100
100
|
errors.push({
|
|
101
101
|
path: `${sectionPath}.chart.spec`,
|
|
102
102
|
message: 'Chart spec requires mark, layer, vconcat, or hconcat',
|
|
103
|
-
suggestion: 'Add mark: "bar" or mark: "line" etc.'
|
|
103
|
+
suggestion: 'Add mark: "bar" or mark: "line" etc.',
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
}
|
|
@@ -110,7 +110,7 @@ export function validateTemplate(template, dataKeys) {
|
|
|
110
110
|
errors.push({
|
|
111
111
|
path: `${sectionPath}.chart.dataKey`,
|
|
112
112
|
message: `Unknown dataKey '${section.chart.dataKey}'`,
|
|
113
|
-
suggestion: closest ? `Did you mean '${closest}'?` : undefined
|
|
113
|
+
suggestion: closest ? `Did you mean '${closest}'?` : undefined,
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
116
|
}
|
|
@@ -122,7 +122,7 @@ export function validateTemplate(template, dataKeys) {
|
|
|
122
122
|
errors.push({
|
|
123
123
|
path: `${sectionPath}.fields`,
|
|
124
124
|
message: 'Non-table/chart sections require fields array',
|
|
125
|
-
suggestion: 'Add fields: [{ label: "...", key: "..." }]'
|
|
125
|
+
suggestion: 'Add fields: [{ label: "...", key: "..." }]',
|
|
126
126
|
});
|
|
127
127
|
continue;
|
|
128
128
|
}
|
|
@@ -135,7 +135,7 @@ export function validateTemplate(template, dataKeys) {
|
|
|
135
135
|
errors.push({
|
|
136
136
|
path: `${path}.key`,
|
|
137
137
|
message: `Unknown key '${field.key}'`,
|
|
138
|
-
suggestion: closest ? `Did you mean '${closest}'?` : undefined
|
|
138
|
+
suggestion: closest ? `Did you mean '${closest}'?` : undefined,
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
141
|
// Check format compatibility (basic type checking)
|
|
@@ -148,7 +148,7 @@ export function validateTemplate(template, dataKeys) {
|
|
|
148
148
|
errors.push({
|
|
149
149
|
path: `${path}.options`,
|
|
150
150
|
message: 'Select input type requires options array',
|
|
151
|
-
suggestion: 'Add options: [{ label: "...", value: "..." }]'
|
|
151
|
+
suggestion: 'Add options: [{ label: "...", value: "..." }]',
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
154
|
// Check min/max for number inputs
|
|
@@ -156,14 +156,14 @@ export function validateTemplate(template, dataKeys) {
|
|
|
156
156
|
errors.push({
|
|
157
157
|
path: `${path}.min`,
|
|
158
158
|
message: `min (${field.min}) cannot be greater than max (${field.max})`,
|
|
159
|
-
suggestion: 'Swap min and max values'
|
|
159
|
+
suggestion: 'Swap min and max values',
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
return {
|
|
165
165
|
valid: errors.length === 0,
|
|
166
|
-
errors
|
|
166
|
+
errors,
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
169
|
/**
|
|
@@ -178,7 +178,7 @@ function validateFormatCompatibility(field, path) {
|
|
|
178
178
|
errors.push({
|
|
179
179
|
path: `${path}.decimals`,
|
|
180
180
|
message: `'decimals' only applies to number, currency, or percent formats`,
|
|
181
|
-
suggestion: `Remove 'decimals' or change format to one of: ${validFormats.join(', ')}
|
|
181
|
+
suggestion: `Remove 'decimals' or change format to one of: ${validFormats.join(', ')}`,
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
}
|
|
@@ -187,7 +187,7 @@ function validateFormatCompatibility(field, path) {
|
|
|
187
187
|
errors.push({
|
|
188
188
|
path: `${path}.currency`,
|
|
189
189
|
message: `'currency' only applies to currency format`,
|
|
190
|
-
suggestion: `Set format: 'currency' or remove 'currency' property
|
|
190
|
+
suggestion: `Set format: 'currency' or remove 'currency' property`,
|
|
191
191
|
});
|
|
192
192
|
}
|
|
193
193
|
// Check inputType compatibility with format
|
|
@@ -198,14 +198,14 @@ function validateFormatCompatibility(field, path) {
|
|
|
198
198
|
currency: ['number', 'text'],
|
|
199
199
|
percent: ['number', 'text'],
|
|
200
200
|
date: ['date', 'text'],
|
|
201
|
-
boolean: ['checkbox']
|
|
201
|
+
boolean: ['checkbox'],
|
|
202
202
|
};
|
|
203
203
|
const validInputs = compatMap[field.format];
|
|
204
204
|
if (validInputs && !validInputs.includes(field.inputType)) {
|
|
205
205
|
errors.push({
|
|
206
206
|
path: `${path}.inputType`,
|
|
207
207
|
message: `inputType '${field.inputType}' is not compatible with format '${field.format}'`,
|
|
208
|
-
suggestion: `Use one of: ${validInputs.join(', ')}
|
|
208
|
+
suggestion: `Use one of: ${validInputs.join(', ')}`,
|
|
209
209
|
});
|
|
210
210
|
}
|
|
211
211
|
}
|
|
@@ -227,11 +227,13 @@ export function parseAndValidateTemplate(jsonString, dataKeys) {
|
|
|
227
227
|
const message = err instanceof Error ? err.message : 'Invalid JSON';
|
|
228
228
|
return {
|
|
229
229
|
valid: false,
|
|
230
|
-
errors: [
|
|
230
|
+
errors: [
|
|
231
|
+
{
|
|
231
232
|
path: 'root',
|
|
232
233
|
message: `JSON parse error: ${message}`,
|
|
233
|
-
suggestion: 'Check JSON syntax (missing quotes, commas, brackets)'
|
|
234
|
-
}
|
|
234
|
+
suggestion: 'Check JSON syntax (missing quotes, commas, brackets)',
|
|
235
|
+
},
|
|
236
|
+
],
|
|
235
237
|
};
|
|
236
238
|
}
|
|
237
239
|
// Validate the parsed template
|
|
@@ -239,7 +241,7 @@ export function parseAndValidateTemplate(jsonString, dataKeys) {
|
|
|
239
241
|
if (result.valid) {
|
|
240
242
|
return {
|
|
241
243
|
...result,
|
|
242
|
-
template: parsed
|
|
244
|
+
template: parsed,
|
|
243
245
|
};
|
|
244
246
|
}
|
|
245
247
|
return result;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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MAAM,CAAC,KAAK,EAAE,CAAC;QACf,OAAO;YACH,GAAG,MAAM;YACT,QAAQ,EAAE,MAA0B;SACvC,CAAC;IACN,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useState as r,useMemo as n,useCallback as a,createContext as o,useContext as i}from"react";import s from"ajv";const l={type:"object",properties:{label:{type:"string"},key:{type:"string"},format:{type:"string",enum:["text","number","currency","percent","date","boolean"],nullable:!0},unit:{type:"string",nullable:!0},editable:{type:"boolean",nullable:!0},inputType:{type:"string",enum:["text","number","date","select","checkbox"],nullable:!0},options:{type:"array",items:{type:"object",properties:{label:{type:"string"},value:{type:"string"}},required:["label","value"],additionalProperties:!1},nullable:!0},min:{type:"number",nullable:!0},max:{type:"number",nullable:!0},highlight:{type:"string",enum:["success","warning","error","info"],nullable:!0},tooltip:{type:"string",nullable:!0},decimals:{type:"number",nullable:!0},currency:{type:"string",nullable:!0}},required:["label","key"],additionalProperties:!1},c={type:"object",properties:{title:{type:"string"},layout:{type:"string",enum:["grid-2","grid-3","grid-4","list","table","chart"],nullable:!0},collapsed:{type:"boolean",nullable:!0},fields:{type:"array",items:l,nullable:!0},columns:{type:"array",items:{type:"object",properties:{header:{type:"string"},key:{type:"string"},format:{type:"string",enum:["text","number","currency","percent","date","boolean"],nullable:!0},width:{type:"string",nullable:!0},align:{type:"string",enum:["left","center","right"],nullable:!0},currency:{type:"string",nullable:!0},decimals:{type:"number",nullable:!0},highlight:{type:"string",enum:["success","warning","error","info"],nullable:!0}},required:["header","key"],additionalProperties:!1},nullable:!0},dataKey:{type:"string",nullable:!0},chart:{...{type:"object",properties:{title:{type:"string",nullable:!0},description:{type:"string",nullable:!0},spec:{type:"object",additionalProperties:!0},height:{type:"number",nullable:!0},width:{type:"number",nullable:!0},dataKey:{type:"string",nullable:!0}},required:["spec"],additionalProperties:!1},nullable:!0}},required:["title"],additionalProperties:!1},d={type:"object",properties:{title:{type:"string",nullable:!0},entityType:{type:"string",enum:["fund","scenario","portfolio","transaction","custom"],nullable:!0},sections:{type:"array",items:c},footer:{type:"string",nullable:!0}},required:["sections"],additionalProperties:!1};function p(e,t){const r=[];for(let t=0;t<=e.length;t++)r[t]=[t];for(let e=0;e<=t.length;e++)r[0][e]=e;for(let n=1;n<=e.length;n++)for(let a=1;a<=t.length;a++){const o=e[n-1]===t[a-1]?0:1;r[n][a]=Math.min(r[n-1][a]+1,r[n][a-1]+1,r[n-1][a-1]+o)}return r[e.length][t.length]}function u(e,t,r=3){if(0===t.length)return;const n=e.toLowerCase();let a,o=1/0;for(const e of t){const t=e.toLowerCase();if(n===t)return e;if(n.includes(t)||t.includes(n)){const r=Math.abs(n.length-t.length);r<o&&(o=r,a=e);continue}const i=p(n,t);i<o&&i<=r&&(o=i,a=e)}return a}function g(e,t,r=3){if(0===t.length)return[];const n=e.toLowerCase();return t.map(e=>({key:e,distance:p(n,e.toLowerCase())})).filter(({distance:e})=>e<=4).sort((e,t)=>e.distance-t.distance).slice(0,r).map(({key:e})=>e)}const h=new s({allErrors:!0,verbose:!0}).compile(d);function m(e,t){const r=[];if(!h(e)&&h.errors){for(const e of h.errors){const t=e.instancePath.replace(/^\//,"").replace(/\//g,".")||"root";let n,a=e.message||"Invalid value";if("enum"===e.keyword){n=`Valid values: ${e.params.allowedValues.join(", ")}`}else if("required"===e.keyword){a=`Missing required property: ${e.params.missingProperty}`}else if("additionalProperties"===e.keyword){a=`Unknown property: ${e.params.additionalProperty}`,n="Remove this property or check spelling"}r.push({path:t,message:a,suggestion:n})}return{valid:!1,errors:r}}const n=e;for(let e=0;e<n.sections.length;e++){const a=n.sections[e],o=`sections[${e}]`;if("table"!==a.layout)if("chart"!==a.layout)if(a.fields&&0!==a.fields.length)for(let e=0;e<a.fields.length;e++){const n=a.fields[e],i=`${o}.fields[${e}]`;if(!t.includes(n.key)){const e=u(n.key,t);r.push({path:`${i}.key`,message:`Unknown key '${n.key}'`,suggestion:e?`Did you mean '${e}'?`:void 0})}if(n.format){const e=f(n,i);r.push(...e)}"select"!==n.inputType||n.options&&0!==n.options.length||r.push({path:`${i}.options`,message:"Select input type requires options array",suggestion:'Add options: [{ label: "...", value: "..." }]'}),void 0!==n.min&&void 0!==n.max&&n.min>n.max&&r.push({path:`${i}.min`,message:`min (${n.min}) cannot be greater than max (${n.max})`,suggestion:"Swap min and max values"})}else r.push({path:`${o}.fields`,message:"Non-table/chart sections require fields array",suggestion:'Add fields: [{ label: "...", key: "..." }]'});else if(a.chart){if(a.chart.spec){const e=a.chart.spec;e.mark||e.layer||e.vconcat||e.hconcat||r.push({path:`${o}.chart.spec`,message:"Chart spec requires mark, layer, vconcat, or hconcat",suggestion:'Add mark: "bar" or mark: "line" etc.'})}else r.push({path:`${o}.chart.spec`,message:"Chart requires a Vega-Lite spec",suggestion:'Add spec: { mark: "bar", encoding: {...}, data: {...} }'});if(a.chart.dataKey&&!t.includes(a.chart.dataKey)){const e=u(a.chart.dataKey,t);r.push({path:`${o}.chart.dataKey`,message:`Unknown dataKey '${a.chart.dataKey}'`,suggestion:e?`Did you mean '${e}'?`:void 0})}}else r.push({path:`${o}.chart`,message:"Chart layout requires a chart specification",suggestion:'Add chart: { spec: { mark: "bar", encoding: {...} } }'});else if(a.columns&&0!==a.columns.length||r.push({path:`${o}.columns`,message:"Table layout requires columns array",suggestion:'Add columns: [{ header: "...", key: "..." }]'}),a.dataKey){if(!t.includes(a.dataKey)){const e=u(a.dataKey,t);r.push({path:`${o}.dataKey`,message:`Unknown dataKey '${a.dataKey}'`,suggestion:e?`Did you mean '${e}'?`:void 0})}}else r.push({path:`${o}.dataKey`,message:"Table layout requires dataKey to reference the data array",suggestion:'Add dataKey: "yourArrayKey"'})}return{valid:0===r.length,errors:r}}function f(e,t){const r=[];if(void 0!==e.decimals){const n=["number","currency","percent"];e.format&&!n.includes(e.format)&&r.push({path:`${t}.decimals`,message:"'decimals' only applies to number, currency, or percent formats",suggestion:`Remove 'decimals' or change format to one of: ${n.join(", ")}`})}if(void 0!==e.currency&&"currency"!==e.format&&r.push({path:`${t}.currency`,message:"'currency' only applies to currency format",suggestion:"Set format: 'currency' or remove 'currency' property"}),e.inputType&&e.format){const n={text:["text"],number:["number","text"],currency:["number","text"],percent:["number","text"],date:["date","text"],boolean:["checkbox"]}[e.format];n&&!n.includes(e.inputType)&&r.push({path:`${t}.inputType`,message:`inputType '${e.inputType}' is not compatible with format '${e.format}'`,suggestion:`Use one of: ${n.join(", ")}`})}return r}function y(e,t){let r;try{r=JSON.parse(e)}catch(e){return{valid:!1,errors:[{path:"root",message:`JSON parse error: ${e instanceof Error?e.message:"Invalid JSON"}`,suggestion:"Check JSON syntax (missing quotes, commas, brackets)"}]}}const n=m(r,t);return n.valid?{...n,template:r}:n}const b={container:{display:"flex",flexDirection:"column",gap:"2px",minWidth:0},label:{fontSize:"11px",fontWeight:500,color:"var(--gray-11, #6b7280)",textTransform:"uppercase",letterSpacing:"0.5px"},value:{fontSize:"14px",fontWeight:500,color:"var(--gray-12, #1f2937)",fontFamily:"var(--font-mono, ui-monospace, monospace)",fontVariantNumeric:"tabular-nums",letterSpacing:"-0.02em"},unit:{fontSize:"12px",color:"var(--gray-10, #9ca3af)",marginLeft:"4px"},highlight:{success:{color:"var(--green-11, #15803d)"},warning:{color:"var(--yellow-11, #ca8a04)"},error:{color:"var(--red-11, #dc2626)"},info:{color:"var(--blue-11, #2563eb)"}},editable:{cursor:"pointer",padding:"2px 4px",borderRadius:"4px",transition:"background-color 0.15s"},nullValue:{color:"var(--gray-9, #9ca3af)",fontStyle:"italic"}};function v({field:o,value:i,onUpdate:s,agentMode:l}){const[c,d]=r(!1),p=n(()=>function(e,t){if(null==e)return"—";switch(t.format){case"number":{const r="number"==typeof e?e:parseFloat(String(e));if(isNaN(r))return String(e);const n={minimumFractionDigits:t.decimals??0,maximumFractionDigits:t.decimals??2};return new Intl.NumberFormat("en-US",n).format(r)}case"currency":{const r="number"==typeof e?e:parseFloat(String(e));if(isNaN(r))return String(e);const n={style:"currency",currency:t.currency||"USD",minimumFractionDigits:t.decimals??0,maximumFractionDigits:t.decimals??0};return new Intl.NumberFormat("en-US",n).format(r)}case"percent":{const r="number"==typeof e?e:parseFloat(String(e));if(isNaN(r))return String(e);const n=r<1&&r>-1&&0!==r?100*r:r,a=t.decimals??1;return`${n.toFixed(a)}%`}case"date":{if(!e)return"—";const t=e instanceof Date?e:new Date(String(e));return isNaN(t.getTime())?String(e):new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric"}).format(t)}case"boolean":return("boolean"==typeof e?e:"true"===e||"1"===e)?"Yes":"No";default:return String(e)}}(i,o),[i,o]),u=null==i,g=o.editable&&(s||l),h=a(()=>{g&&l?.enabled&&l.sendMessage&&l.sendMessage(`Please help me update the "${o.label}" field (key: ${o.key}). Current value: ${p}`)},[g,l,o,p]),m=n(()=>{const e={...b.value};return u?{...e,...b.nullValue}:o.highlight?{...e,...b.highlight[o.highlight]}:g?{...e,...b.editable,backgroundColor:c?"var(--gray-3, #f3f4f6)":"transparent"}:e},[u,o.highlight,g,c]);return e("div",{style:b.container,title:o.tooltip,onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),onClick:h,role:g?"button":void 0,tabIndex:g?0:void 0,children:[t("span",{style:b.label,children:o.label}),e("span",{style:m,children:[p,o.unit&&!u&&t("span",{style:b.unit,children:o.unit})]})]})}const x={container:{width:"100%",overflowX:"auto"},table:{width:"100%",borderCollapse:"collapse",fontSize:"13px"},thead:{backgroundColor:"var(--gray-3, #f3f4f6)"},th:{padding:"10px 12px",textAlign:"left",fontWeight:600,fontSize:"11px",textTransform:"uppercase",letterSpacing:"0.5px",color:"var(--gray-11, #6b7280)",borderBottom:"2px solid var(--gray-5, #e5e7eb)"},td:{padding:"10px 12px",borderBottom:"1px solid var(--gray-4, #e5e7eb)",fontFamily:"var(--font-mono, ui-monospace, monospace)",fontVariantNumeric:"tabular-nums"},empty:{padding:"20px",textAlign:"center",color:"var(--gray-10, #9ca3af)",fontStyle:"italic"},highlight:{success:{color:"var(--green-11, #15803d)"},warning:{color:"var(--yellow-11, #ca8a04)"},error:{color:"var(--red-11, #dc2626)"},info:{color:"var(--blue-11, #2563eb)"}}};function k({columns:r,rows:a}){const o=n(()=>r.reduce((e,t)=>(e[t.key]=t.align||("number"===t.format||"currency"===t.format||"percent"===t.format?"right":"left"),e),{}),[r]);return 0===a.length?t("div",{style:x.container,children:e("table",{style:x.table,children:[t("thead",{style:x.thead,children:t("tr",{children:r.map(e=>t("th",{style:{...x.th,textAlign:o[e.key],width:e.width},children:e.header},e.key))})}),t("tbody",{children:t("tr",{children:t("td",{colSpan:r.length,style:x.empty,children:"No data available"})})})]})}):t("div",{style:x.container,children:e("table",{style:x.table,children:[t("thead",{style:x.thead,children:t("tr",{children:r.map(e=>t("th",{style:{...x.th,textAlign:o[e.key],width:e.width},children:e.header},e.key))})}),t("tbody",{children:a.map((e,n)=>t("tr",{children:r.map(r=>{const n=function(e,t){if(null==e)return"—";switch(t.format){case"number":{const r="number"==typeof e?e:parseFloat(String(e));return isNaN(r)?String(e):new Intl.NumberFormat("en-US",{minimumFractionDigits:0,maximumFractionDigits:t.decimals??2}).format(r)}case"currency":{const r="number"==typeof e?e:parseFloat(String(e));return isNaN(r)?String(e):new Intl.NumberFormat("en-US",{style:"currency",currency:t.currency||"USD",minimumFractionDigits:t.decimals??0,maximumFractionDigits:t.decimals??0}).format(r)}case"percent":{const r="number"==typeof e?e:parseFloat(String(e));return isNaN(r)?String(e):`${(r<1&&r>-1&&0!==r?100*r:r).toFixed(t.decimals??1)}%`}case"date":{const t=e instanceof Date?e:new Date(String(e));return isNaN(t.getTime())?String(e):new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric"}).format(t)}case"boolean":return e?"Yes":"No";default:return String(e)}}(e[r.key],r),a={...x.td,textAlign:o[r.key],...r.highlight?x.highlight[r.highlight]:{}};return t("td",{style:a,children:n},r.key)})},n))})]})})}const $=o(null);function S({data:e,onUpdate:r,sendMessage:a,ChartComponent:o,artifactRunId:i,children:s}){const l=n(()=>({data:e,onUpdate:r,sendMessage:a,ChartComponent:o,artifactRunId:i}),[e,r,a,o,i]);return t($.Provider,{value:l,children:s})}function w(){const e=i($);if(!e)throw new Error("useFusionFragmentContext must be used within a FusionFragmentProvider");return e}function C(){return i($)}function N({chart:r,data:n,className:a}){const o=C(),i=o?.ChartComponent,s=o?.artifactRunId,l={...r.spec};if(r.dataKey&&n[r.dataKey]){const e=n[r.dataKey];Array.isArray(e)&&(l.data={values:e})}const c={library:"vega-lite",title:r.title,description:r.description,spec:l,options:{height:r.height}};return i?t("div",{className:a,children:t(i,{spec:c,artifactRunId:s})}):e("div",{className:a,style:{padding:"16px",backgroundColor:"var(--gray-2, #f9fafb)",border:"1px solid var(--gray-5, #e5e7eb)",borderRadius:"8px",minHeight:r.height||280},children:[r.title&&t("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"8px",color:"var(--gray-12, #111827)"},children:r.title}),r.description&&t("div",{style:{fontSize:"12px",color:"var(--gray-11, #6b7280)",marginBottom:"12px"},children:r.description}),t("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:(r.height||280)-60,backgroundColor:"var(--gray-3, #f3f4f6)",borderRadius:"4px",color:"var(--gray-11, #6b7280)",fontSize:"12px"},"data-vega-spec":JSON.stringify(c),children:e("div",{style:{textAlign:"center"},children:[e("div",{style:{marginBottom:"4px"},children:["Chart: ",l.mark?String("string"==typeof l.mark?l.mark:l.mark.type):"composite"]}),l.data?.values&&e("div",{style:{fontSize:"11px",opacity:.8},children:[l.data.values.length," data points"]})]})})]})}const T={"grid-2":{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"16px"},"grid-3":{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"16px"},"grid-4":{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:"16px"},list:{display:"flex",flexDirection:"column",gap:"12px"}},F={section:{marginBottom:"20px"},header:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"12px",cursor:"default"},headerCollapsible:{cursor:"pointer",userSelect:"none"},title:{fontSize:"11px",fontWeight:600,color:"var(--gray-11, #6b7280)",textTransform:"uppercase",letterSpacing:"0.5px"},chevron:{width:"14px",height:"14px",color:"var(--gray-10, #9ca3af)",transition:"transform 0.2s"},chevronCollapsed:{transform:"rotate(-90deg)"},content:{overflow:"hidden",transition:"max-height 0.2s ease-out"},contentCollapsed:{maxHeight:"0",opacity:0},contentExpanded:{maxHeight:"2000px",opacity:1}};function j({collapsed:e}){return t("svg",{style:{...F.chevron,...e?F.chevronCollapsed:{}},viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t("polyline",{points:"6 9 12 15 18 9"})})}function D({section:a,data:o,onUpdate:i,agentMode:s}){const[l,c]=r(a.collapsed??!1),d=a.layout||"grid-3",p="table"===d,u="chart"===d,g=void 0!==a.collapsed,h=n(()=>{if(!p||!a.dataKey)return[];const e=o[a.dataKey];return Array.isArray(e)?e:[]},[p,a.dataKey,o]),m=n(()=>({...F.header,...g?F.headerCollapsible:{}}),[g]),f=n(()=>({...F.content,...p||u?{}:T[d],...l?F.contentCollapsed:F.contentExpanded}),[l,p,u,d]);return e("div",{style:F.section,children:[e("div",{style:m,onClick:()=>{g&&c(!l)},role:g?"button":void 0,"aria-expanded":g?!l:void 0,children:[g&&t(j,{collapsed:l}),t("span",{style:F.title,children:a.title})]}),t("div",{style:f,children:p&&a.columns?t(k,{columns:a.columns,rows:h}):u&&a.chart?t(N,{chart:a.chart,data:o}):a.fields?.map((e,r)=>t(v,{field:e,value:o[e.key],onUpdate:i?t=>i(e.key,t):void 0,agentMode:s},e.key||r))})]})}const K={container:{backgroundColor:"var(--gray-2, #f9fafb)",border:"1px solid var(--gray-5, #e5e7eb)",borderRadius:"8px",padding:"16px 20px"},title:{fontSize:"16px",fontWeight:600,color:"var(--gray-12, #1f2937)",marginBottom:"16px",paddingBottom:"12px",borderBottom:"1px solid var(--gray-5, #e5e7eb)"},footer:{fontSize:"12px",color:"var(--gray-10, #9ca3af)",marginTop:"16px",paddingTop:"12px",borderTop:"1px solid var(--gray-5, #e5e7eb)"},error:{backgroundColor:"var(--red-2, #fef2f2)",border:"1px solid var(--red-6, #fca5a5)",borderRadius:"8px",padding:"16px"},errorTitle:{fontSize:"14px",fontWeight:600,color:"var(--red-11, #dc2626)",marginBottom:"12px"},errorList:{listStyle:"none",padding:0,margin:0},errorItem:{fontSize:"13px",color:"var(--red-11, #dc2626)",marginBottom:"8px",fontFamily:"var(--font-mono, ui-monospace, monospace)"},errorPath:{fontSize:"11px",color:"var(--red-9, #ef4444)",display:"block"},errorSuggestion:{fontSize:"12px",color:"var(--gray-11, #6b7280)",marginTop:"4px",fontStyle:"italic"}};function M({errors:r}){return e("div",{style:K.error,children:[e("div",{style:K.errorTitle,children:["Template Validation Failed (",r.length," error",r.length>1?"s":"",")"]}),t("ul",{style:K.errorList,children:r.map((r,n)=>e("li",{style:K.errorItem,children:[t("span",{children:r.message}),e("span",{style:K.errorPath,children:["at ",r.path]}),r.suggestion&&e("span",{style:K.errorSuggestion,children:["\\u2192 ",r.suggestion]})]},n))})]})}function U({template:r,data:a,onUpdate:o,agentMode:i,className:s}){const l=n(()=>{const e=Object.keys(a);return m(r,e)},[r,a]);return l.valid?e("div",{style:K.container,className:s,children:[r.title&&t("div",{style:K.title,children:r.title}),r.sections.map((e,r)=>t(D,{section:e,data:a,onUpdate:o,agentMode:i},e.title||r)),r.footer&&t("div",{style:K.footer,children:r.footer})]}):t(M,{errors:l.errors})}const I={error:{backgroundColor:"var(--red-2, #fef2f2)",border:"1px solid var(--red-6, #fca5a5)",borderRadius:"8px",padding:"16px",fontFamily:"var(--font-mono, ui-monospace, monospace)",fontSize:"13px"},errorTitle:{fontWeight:600,color:"var(--red-11, #dc2626)",marginBottom:"8px"},errorMessage:{color:"var(--red-10, #ef4444)",whiteSpace:"pre-wrap"},noContext:{backgroundColor:"var(--yellow-2, #fefce8)",border:"1px solid var(--yellow-6, #fde047)",borderRadius:"8px",padding:"16px"},noContextTitle:{fontSize:"14px",fontWeight:600,color:"var(--yellow-11, #ca8a04)",marginBottom:"8px"},noContextMessage:{fontSize:"13px",color:"var(--gray-11, #6b7280)"},loading:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"12px",minHeight:"150px",borderRadius:"8px",border:"1px solid var(--gray-6, #e5e7eb)",backgroundColor:"var(--gray-2, #f9fafb)"},loadingIcon:{width:"32px",height:"32px",color:"var(--gray-9, #9ca3af)"},loadingText:{fontSize:"14px",color:"var(--gray-9, #9ca3af)"},loadingDots:{display:"flex",gap:"4px"},loadingDot:{width:"8px",height:"8px",borderRadius:"50%",backgroundColor:"var(--gray-6, #d1d5db)",animation:"fusion-fragment-bounce 1s infinite"}};function A(){return e("div",{style:I.loading,children:[t("style",{children:"\n @keyframes fusion-fragment-bounce {\n 0%, 80%, 100% { transform: translateY(0); }\n 40% { transform: translateY(-6px); }\n }\n "}),e("svg",{style:I.loadingIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t("polyline",{points:"16 18 22 12 16 6"}),t("polyline",{points:"8 6 2 12 8 18"})]}),t("span",{style:I.loadingText,children:"Loading fragment..."}),t("div",{style:I.loadingDots,children:[0,1,2].map(e=>t("div",{style:{...I.loadingDot,animationDelay:150*e+"ms"}},e))})]})}function z({message:r}){return e("div",{style:I.error,children:[t("div",{style:I.errorTitle,children:"Failed to parse fusion-fragment"}),t("div",{style:I.errorMessage,children:r})]})}function P({template:r}){const n=r.sections.flatMap(e=>e.fields||[]).map(e=>e.key);return e("div",{style:I.noContext,children:[t("div",{style:I.noContextTitle,children:"No data context available"}),e("div",{style:I.noContextMessage,children:["This fusion-fragment requires data with keys: ",n.join(", "),".",t("br",{}),"Wrap this component in a FusionFragmentProvider with the required data."]})]})}function q({code:e,data:r,onUpdate:a}){const o=C(),i=r??o?.data,s=a??o?.onUpdate,l=o?.sendMessage,c=n(()=>function(e){const t=e.trim();if(t.length<2)return!0;if(!t.startsWith("{"))return!1;try{return JSON.parse(t),!1}catch(e){const r=["unexpected end","unterminated string","expected","unexpected token"],n=(e instanceof Error?e.message:"").toLowerCase();if(r.some(e=>n.includes(e))){let e=0,r=0,n=!1,a=!1;for(const o of t)a?a=!1:"\\"!==o?'"'!==o?n||("{"===o?e++:"}"===o?e--:"["===o?r++:"]"===o&&r--):n=!n:a=!0;return e>0||r>0||n}return!1}}(e),[e]),d=n(()=>{if(c)return{valid:!1,errors:[],template:void 0};const t=i?Object.keys(i):[];return y(e,t)},[e,i,c]);if(c)return t(A,{});if(!d.valid&&!d.template){const e=d.errors.find(e=>"root"===e.path&&e.message.includes("JSON"));if(e)return t(z,{message:e.message})}return d.template&&!i?t(P,{template:d.template}):d.template&&i?t(U,{template:d.template,data:i,onUpdate:s,agentMode:l?{enabled:!0,sendMessage:l}:void 0}):t(z,{message:d.errors.map(e=>`${e.path}: ${e.message}`).join("\n")})}function L(){return{language:"fusion-fragment",component:q}}function B(e){if(0===e.length)return"Template is valid.";return`Template validation failed with ${e.length} error${e.length>1?"s":""}:\n`+"\n"+e.map((e,t)=>{let r=`${t+1}. ${e.message}`;return r+=`\n Path: ${e.path}`,e.suggestion&&(r+=`\n → ${e.suggestion}`),r}).join("\n\n")}function R(e,t){const r=["Template valid. Preview:"];r.push(""),e.title&&(r.push(`**${e.title}**`),r.push(""));for(const n of e.sections){const e=n.fields.length;r.push(`[${n.title}] ${e} field${e>1?"s":""}:`);for(const e of n.fields){let n=`- ${e.label} (${e.key}`;e.format&&"text"!==e.format&&(n+=`, ${e.format}`),n+=")",t.includes(e.key)||(n+=" ⚠️ key not in data"),r.push(n)}r.push("")}return r.join("\n")}function W(e,t=!0){if(0===e.length)return"No data keys available.";if(!t||e.length<=10)return`Available keys: ${e.join(", ")}`;const r=new Map;for(const t of e){const e=t.indexOf(".");if(e>0){const n=t.substring(0,e),a=t.substring(e+1),o=r.get(n)||[];o.push(a),r.set(n,o)}else{const e=r.get("")||[];e.push(t),r.set("",e)}}const n=["Available keys:"],a=r.get("");a&&a.length>0&&n.push(` ${a.join(", ")}`);for(const[e,t]of r)""!==e&&(t.length<=3?n.push(` ${e}: ${t.join(", ")}`):n.push(` ${e}: ${t.slice(0,3).join(", ")}, ... (${t.length} total)`));return n.join("\n")}function O(e,t){const r={};for(const e of t)r[e]=`<${e}>`;for(const t of e.sections)if(t.fields)for(const e of t.fields)e.key in r&&(r[e.key]=V(e));return r}function V(e){switch(e.format){case"number":return 1234;case"currency":return 1e6;case"percent":return 25;case"date":return(new Date).toISOString().split("T")[0];case"boolean":return!0;default:return`Sample ${e.label}`}}function E(e,t){const r=[];r.push("Template structure preview:"),r.push(""),e.title&&(r.push(`## ${e.title}`),r.push(""));for(const n of e.sections){const e=n.layout||"grid-3";if(r.push(`### ${n.title}`),"table"===e){if(r.push("Layout: table"),n.dataKey&&r.push(`Data key: \`${n.dataKey}\``),r.push(""),n.columns){r.push("Columns:");for(const e of n.columns){let t=`- **${e.header}** → \`${e.key}\``;e.format&&"text"!==e.format&&(t+=` (${e.format})`),r.push(t)}}}else if("chart"===e){if(r.push("Layout: chart"),n.chart){const e=n.chart;e.title&&r.push(`Chart title: ${e.title}`),e.description&&r.push(`Description: ${e.description}`);const a=e.spec.mark?"string"==typeof e.spec.mark?e.spec.mark:e.spec.mark.type||"unknown":"composite";r.push(`Chart type: ${a}`),e.dataKey?(r.push(`Data key: \`${e.dataKey}\``),t.includes(e.dataKey)||r.push("⚠️ **dataKey not found in data**")):e.spec.data?.values&&r.push(`Inline data: ${e.spec.data.values.length} points`),e.height&&r.push(`Height: ${e.height}px`)}r.push("")}else{const a="list"===e?"vertical list":`${e.split("-")[1]}-column grid`;if(r.push(`Layout: ${a}${n.collapsed?" (collapsed by default)":""}`),r.push(""),n.fields)for(const e of n.fields){let n=`- **${e.label}** → \`${e.key}\``;const a=[];e.format&&"text"!==e.format&&a.push(e.format),e.unit&&a.push(`unit: "${e.unit}"`),e.editable&&a.push("editable"),e.highlight&&a.push(`highlight: ${e.highlight}`),a.length>0&&(n+=` (${a.join(", ")})`),t.includes(e.key)||(n+=" ⚠️ **key not found in data**"),r.push(n)}}r.push("")}e.footer&&(r.push("---"),r.push(`Footer: ${e.footer}`),r.push(""));const n=e.sections.reduce((e,t)=>e+(t.fields?.length||0)+(t.columns?.length||0),0),a=e.sections.flatMap(e=>e.fields||[]).filter(e=>!t.includes(e.key)).map(e=>e.key);return r.push("---"),r.push(`Summary: ${e.sections.length} section(s), ${n} field(s)/column(s)`),a.length>0?r.push(`⚠️ Missing keys: ${a.join(", ")}`):r.push("✅ All field keys found in data"),r.join("\n")}function J(e){const t=e.sections.map(e=>{if("table"===e.layout&&e.columns){const t=e.columns.slice(0,3).map(e=>e.header).join(", "),r=e.columns.length>3?`, +${e.columns.length-3} more`:"";return`${e.title} (table): ${t}${r}`}if("chart"===e.layout&&e.chart){const t=e.chart.spec.mark?"string"==typeof e.chart.spec.mark?e.chart.spec.mark:e.chart.spec.mark.type||"chart":"chart";return`${e.title} (${t} chart)`}if(e.fields){const t=e.fields.slice(0,3).map(e=>e.label).join(", "),r=e.fields.length>3?`, +${e.fields.length-3} more`:"";return`${e.title}: ${t}${r}`}return e.title});return`${e.title?`"${e.title}" - `:""}${t.join(" | ")}`}export{v as FieldRenderer,l as FieldTemplateSchema,d as FragmentTemplateSchema,q as FusionFragmentHandler,S as FusionFragmentProvider,U as FusionFragmentRenderer,D as SectionRenderer,c as SectionTemplateSchema,L as createFusionFragmentCodeBlockRenderer,u as findClosestKey,g as findSimilarKeys,W as formatAvailableKeys,B as formatValidationErrors,R as formatValidationSuccess,J as generateCompactPreview,O as generateSampleData,E as generateTextPreview,y as parseAndValidateTemplate,w as useFusionFragmentContext,C as useFusionFragmentContextSafe,m as validateTemplate};
|
|
1
|
+
import{jsx as e,jsxs as t}from"react/jsx-runtime";import{createContext as r,useMemo as n,useContext as a,useState as o,useCallback as i}from"react";import s from"ajv";const l=r(null);function c({data:t,onUpdate:r,sendMessage:a,ChartComponent:o,artifactRunId:i,children:s}){const c=n(()=>({data:t,onUpdate:r,sendMessage:a,ChartComponent:o,artifactRunId:i}),[t,r,a,o,i]);return e(l.Provider,{value:c,children:s})}function d(){const e=a(l);if(!e)throw new Error("useFusionFragmentContext must be used within a FusionFragmentProvider");return e}function u(){return a(l)}function p({chart:r,data:n,className:a}){const o=u(),i=o?.ChartComponent,s=o?.artifactRunId,l={...r.spec};if(r.dataKey&&n[r.dataKey]){const e=n[r.dataKey];Array.isArray(e)&&(l.data={values:e})}const c={library:"vega-lite",title:r.title,description:r.description,spec:l,options:{height:r.height}};return i?e("div",{className:a,children:e(i,{spec:c,artifactRunId:s})}):t("div",{className:a,style:{padding:"16px",backgroundColor:"var(--gray-2, #f9fafb)",border:"1px solid var(--gray-5, #e5e7eb)",borderRadius:"8px",minHeight:r.height||280},children:[r.title&&e("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"8px",color:"var(--gray-12, #111827)"},children:r.title}),r.description&&e("div",{style:{fontSize:"12px",color:"var(--gray-11, #6b7280)",marginBottom:"12px"},children:r.description}),e("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:(r.height||280)-60,backgroundColor:"var(--gray-3, #f3f4f6)",borderRadius:"4px",color:"var(--gray-11, #6b7280)",fontSize:"12px"},"data-vega-spec":JSON.stringify(c),children:t("div",{style:{textAlign:"center"},children:[t("div",{style:{marginBottom:"4px"},children:["Chart:"," ",l.mark?String("string"==typeof l.mark?l.mark:l.mark.type):"composite"]}),l.data?.values&&t("div",{style:{fontSize:"11px",opacity:.8},children:[l.data.values.length," data points"]})]})})]})}const g={container:{display:"flex",flexDirection:"column",gap:"2px",minWidth:0},label:{fontSize:"11px",fontWeight:500,color:"var(--gray-11, #6b7280)",textTransform:"uppercase",letterSpacing:"0.5px"},value:{fontSize:"14px",fontWeight:500,color:"var(--gray-12, #1f2937)",fontFamily:"var(--font-mono, ui-monospace, monospace)",fontVariantNumeric:"tabular-nums",letterSpacing:"-0.02em"},unit:{fontSize:"12px",color:"var(--gray-10, #9ca3af)",marginLeft:"4px"},highlight:{success:{color:"var(--green-11, #15803d)"},warning:{color:"var(--yellow-11, #ca8a04)"},error:{color:"var(--red-11, #dc2626)"},info:{color:"var(--blue-11, #2563eb)"}},editable:{cursor:"pointer",padding:"2px 4px",borderRadius:"4px",transition:"background-color 0.15s"},nullValue:{color:"var(--gray-9, #9ca3af)",fontStyle:"italic"}};function m({field:r,value:a,onUpdate:s,agentMode:l}){const[c,d]=o(!1),u=n(()=>function(e,t){if(null==e)return"—";switch(t.format){case"number":{const r="number"==typeof e?e:parseFloat(String(e));if(Number.isNaN(r))return String(e);const n={minimumFractionDigits:t.decimals??0,maximumFractionDigits:t.decimals??2};return new Intl.NumberFormat("en-US",n).format(r)}case"currency":{const r="number"==typeof e?e:parseFloat(String(e));if(Number.isNaN(r))return String(e);const n={style:"currency",currency:t.currency||"USD",minimumFractionDigits:t.decimals??0,maximumFractionDigits:t.decimals??0};return new Intl.NumberFormat("en-US",n).format(r)}case"percent":{const r="number"==typeof e?e:parseFloat(String(e));if(Number.isNaN(r))return String(e);const n=r<1&&r>-1&&0!==r?100*r:r,a=t.decimals??1;return`${n.toFixed(a)}%`}case"date":{if(!e)return"—";const t=e instanceof Date?e:new Date(String(e));return Number.isNaN(t.getTime())?String(e):new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric"}).format(t)}case"boolean":return("boolean"==typeof e?e:"true"===e||"1"===e)?"Yes":"No";default:return String(e)}}(a,r),[a,r]),p=null==a,m=r.editable&&(s||l),h=i(()=>{m&&l?.enabled&&l.sendMessage&&l.sendMessage(`Please help me update the "${r.label}" field (key: ${r.key}). Current value: ${u}`)},[m,l,r,u]),f=n(()=>{const e={...g.value};return p?{...e,...g.nullValue}:r.highlight?{...e,...g.highlight[r.highlight]}:m?{...e,...g.editable,backgroundColor:c?"var(--gray-3, #f3f4f6)":"transparent"}:e},[p,r.highlight,m,c]);return t("div",{style:g.container,title:r.tooltip,onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),onClick:h,onKeyDown:m?e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),h())}:void 0,role:m?"button":void 0,tabIndex:m?0:void 0,children:[e("span",{style:g.label,children:r.label}),t("span",{style:f,children:[u,r.unit&&!p&&e("span",{style:g.unit,children:r.unit})]})]})}function h(e,t){const r=[];for(let t=0;t<=e.length;t++)r[t]=[t];for(let e=0;e<=t.length;e++)r[0][e]=e;for(let n=1;n<=e.length;n++)for(let a=1;a<=t.length;a++){const o=e[n-1]===t[a-1]?0:1;r[n][a]=Math.min(r[n-1][a]+1,r[n][a-1]+1,r[n-1][a-1]+o)}return r[e.length][t.length]}function f(e,t,r=3){if(0===t.length)return;const n=e.toLowerCase();let a,o=1/0;for(const e of t){const t=e.toLowerCase();if(n===t)return e;if(n.includes(t)||t.includes(n)){const r=Math.abs(n.length-t.length);r<o&&(o=r,a=e);continue}const i=h(n,t);i<o&&i<=r&&(o=i,a=e)}return a}function y(e,t,r=3){if(0===t.length)return[];const n=e.toLowerCase();return t.map(e=>({key:e,distance:h(n,e.toLowerCase())})).filter(({distance:e})=>e<=4).sort((e,t)=>e.distance-t.distance).slice(0,r).map(({key:e})=>e)}const b={type:"object",properties:{label:{type:"string"},key:{type:"string"},format:{type:"string",enum:["text","number","currency","percent","date","boolean"],nullable:!0},unit:{type:"string",nullable:!0},editable:{type:"boolean",nullable:!0},inputType:{type:"string",enum:["text","number","date","select","checkbox"],nullable:!0},options:{type:"array",items:{type:"object",properties:{label:{type:"string"},value:{type:"string"}},required:["label","value"],additionalProperties:!1},nullable:!0},min:{type:"number",nullable:!0},max:{type:"number",nullable:!0},highlight:{type:"string",enum:["success","warning","error","info"],nullable:!0},tooltip:{type:"string",nullable:!0},decimals:{type:"number",nullable:!0},currency:{type:"string",nullable:!0}},required:["label","key"],additionalProperties:!1},v={type:"object",properties:{title:{type:"string"},layout:{type:"string",enum:["grid-2","grid-3","grid-4","list","table","chart"],nullable:!0},collapsed:{type:"boolean",nullable:!0},fields:{type:"array",items:b,nullable:!0},columns:{type:"array",items:{type:"object",properties:{header:{type:"string"},key:{type:"string"},format:{type:"string",enum:["text","number","currency","percent","date","boolean"],nullable:!0},width:{type:"string",nullable:!0},align:{type:"string",enum:["left","center","right"],nullable:!0},currency:{type:"string",nullable:!0},decimals:{type:"number",nullable:!0},highlight:{type:"string",enum:["success","warning","error","info"],nullable:!0}},required:["header","key"],additionalProperties:!1},nullable:!0},dataKey:{type:"string",nullable:!0},chart:{...{type:"object",properties:{title:{type:"string",nullable:!0},description:{type:"string",nullable:!0},spec:{type:"object",additionalProperties:!0},height:{type:"number",nullable:!0},width:{type:"number",nullable:!0},dataKey:{type:"string",nullable:!0}},required:["spec"],additionalProperties:!1},nullable:!0}},required:["title"],additionalProperties:!1},x={type:"object",properties:{title:{type:"string",nullable:!0},entityType:{type:"string",enum:["fund","scenario","portfolio","transaction","custom"],nullable:!0},sections:{type:"array",items:v},footer:{type:"string",nullable:!0}},required:["sections"],additionalProperties:!1},k=new s({allErrors:!0,verbose:!0}).compile(x);function $(e,t){const r=[];if(!k(e)&&k.errors){for(const e of k.errors){const t=e.instancePath.replace(/^\//,"").replace(/\//g,".")||"root";let n,a=e.message||"Invalid value";if("enum"===e.keyword){n=`Valid values: ${e.params.allowedValues.join(", ")}`}else if("required"===e.keyword){a=`Missing required property: ${e.params.missingProperty}`}else if("additionalProperties"===e.keyword){a=`Unknown property: ${e.params.additionalProperty}`,n="Remove this property or check spelling"}r.push({path:t,message:a,suggestion:n})}return{valid:!1,errors:r}}const n=e;for(let e=0;e<n.sections.length;e++){const a=n.sections[e],o=`sections[${e}]`;if("table"!==a.layout)if("chart"!==a.layout)if(a.fields&&0!==a.fields.length)for(let e=0;e<a.fields.length;e++){const n=a.fields[e],i=`${o}.fields[${e}]`;if(!t.includes(n.key)){const e=f(n.key,t);r.push({path:`${i}.key`,message:`Unknown key '${n.key}'`,suggestion:e?`Did you mean '${e}'?`:void 0})}if(n.format){const e=S(n,i);r.push(...e)}"select"!==n.inputType||n.options&&0!==n.options.length||r.push({path:`${i}.options`,message:"Select input type requires options array",suggestion:'Add options: [{ label: "...", value: "..." }]'}),void 0!==n.min&&void 0!==n.max&&n.min>n.max&&r.push({path:`${i}.min`,message:`min (${n.min}) cannot be greater than max (${n.max})`,suggestion:"Swap min and max values"})}else r.push({path:`${o}.fields`,message:"Non-table/chart sections require fields array",suggestion:'Add fields: [{ label: "...", key: "..." }]'});else if(a.chart){if(a.chart.spec){const e=a.chart.spec;e.mark||e.layer||e.vconcat||e.hconcat||r.push({path:`${o}.chart.spec`,message:"Chart spec requires mark, layer, vconcat, or hconcat",suggestion:'Add mark: "bar" or mark: "line" etc.'})}else r.push({path:`${o}.chart.spec`,message:"Chart requires a Vega-Lite spec",suggestion:'Add spec: { mark: "bar", encoding: {...}, data: {...} }'});if(a.chart.dataKey&&!t.includes(a.chart.dataKey)){const e=f(a.chart.dataKey,t);r.push({path:`${o}.chart.dataKey`,message:`Unknown dataKey '${a.chart.dataKey}'`,suggestion:e?`Did you mean '${e}'?`:void 0})}}else r.push({path:`${o}.chart`,message:"Chart layout requires a chart specification",suggestion:'Add chart: { spec: { mark: "bar", encoding: {...} } }'});else if(a.columns&&0!==a.columns.length||r.push({path:`${o}.columns`,message:"Table layout requires columns array",suggestion:'Add columns: [{ header: "...", key: "..." }]'}),a.dataKey){if(!t.includes(a.dataKey)){const e=f(a.dataKey,t);r.push({path:`${o}.dataKey`,message:`Unknown dataKey '${a.dataKey}'`,suggestion:e?`Did you mean '${e}'?`:void 0})}}else r.push({path:`${o}.dataKey`,message:"Table layout requires dataKey to reference the data array",suggestion:'Add dataKey: "yourArrayKey"'})}return{valid:0===r.length,errors:r}}function S(e,t){const r=[];if(void 0!==e.decimals){const n=["number","currency","percent"];e.format&&!n.includes(e.format)&&r.push({path:`${t}.decimals`,message:"'decimals' only applies to number, currency, or percent formats",suggestion:`Remove 'decimals' or change format to one of: ${n.join(", ")}`})}if(void 0!==e.currency&&"currency"!==e.format&&r.push({path:`${t}.currency`,message:"'currency' only applies to currency format",suggestion:"Set format: 'currency' or remove 'currency' property"}),e.inputType&&e.format){const n={text:["text"],number:["number","text"],currency:["number","text"],percent:["number","text"],date:["date","text"],boolean:["checkbox"]}[e.format];n&&!n.includes(e.inputType)&&r.push({path:`${t}.inputType`,message:`inputType '${e.inputType}' is not compatible with format '${e.format}'`,suggestion:`Use one of: ${n.join(", ")}`})}return r}function w(e,t){let r;try{r=JSON.parse(e)}catch(e){return{valid:!1,errors:[{path:"root",message:`JSON parse error: ${e instanceof Error?e.message:"Invalid JSON"}`,suggestion:"Check JSON syntax (missing quotes, commas, brackets)"}]}}const n=$(r,t);return n.valid?{...n,template:r}:n}const C={container:{width:"100%",overflowX:"auto"},table:{width:"100%",borderCollapse:"collapse",fontSize:"13px"},thead:{backgroundColor:"var(--gray-3, #f3f4f6)"},th:{padding:"10px 12px",textAlign:"left",fontWeight:600,fontSize:"11px",textTransform:"uppercase",letterSpacing:"0.5px",color:"var(--gray-11, #6b7280)",borderBottom:"2px solid var(--gray-5, #e5e7eb)"},td:{padding:"10px 12px",borderBottom:"1px solid var(--gray-4, #e5e7eb)",fontFamily:"var(--font-mono, ui-monospace, monospace)",fontVariantNumeric:"tabular-nums"},empty:{padding:"20px",textAlign:"center",color:"var(--gray-10, #9ca3af)",fontStyle:"italic"},highlight:{success:{color:"var(--green-11, #15803d)"},warning:{color:"var(--yellow-11, #ca8a04)"},error:{color:"var(--red-11, #dc2626)"},info:{color:"var(--blue-11, #2563eb)"}}};function N({columns:r,rows:a}){const o=n(()=>r.reduce((e,t)=>(e[t.key]=t.align||("number"===t.format||"currency"===t.format||"percent"===t.format?"right":"left"),e),{}),[r]);return 0===a.length?e("div",{style:C.container,children:t("table",{style:C.table,children:[e("thead",{style:C.thead,children:e("tr",{children:r.map(t=>e("th",{style:{...C.th,textAlign:o[t.key],width:t.width},children:t.header},t.key))})}),e("tbody",{children:e("tr",{children:e("td",{colSpan:r.length,style:C.empty,children:"No data available"})})})]})}):e("div",{style:C.container,children:t("table",{style:C.table,children:[e("thead",{style:C.thead,children:e("tr",{children:r.map(t=>e("th",{style:{...C.th,textAlign:o[t.key],width:t.width},children:t.header},t.key))})}),e("tbody",{children:a.map((t,n)=>e("tr",{children:r.map(r=>{const n=function(e,t){if(null==e)return"—";switch(t.format){case"number":{const r="number"==typeof e?e:parseFloat(String(e));return Number.isNaN(r)?String(e):new Intl.NumberFormat("en-US",{minimumFractionDigits:0,maximumFractionDigits:t.decimals??2}).format(r)}case"currency":{const r="number"==typeof e?e:parseFloat(String(e));return Number.isNaN(r)?String(e):new Intl.NumberFormat("en-US",{style:"currency",currency:t.currency||"USD",minimumFractionDigits:t.decimals??0,maximumFractionDigits:t.decimals??0}).format(r)}case"percent":{const r="number"==typeof e?e:parseFloat(String(e));return Number.isNaN(r)?String(e):`${(r<1&&r>-1&&0!==r?100*r:r).toFixed(t.decimals??1)}%`}case"date":{const t=e instanceof Date?e:new Date(String(e));return Number.isNaN(t.getTime())?String(e):new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric"}).format(t)}case"boolean":return e?"Yes":"No";default:return String(e)}}(t[r.key],r),a={...C.td,textAlign:o[r.key],...r.highlight?C.highlight[r.highlight]:{}};return e("td",{style:a,children:n},r.key)})},n))})]})})}const T={"grid-2":{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"16px"},"grid-3":{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"16px"},"grid-4":{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:"16px"},list:{display:"flex",flexDirection:"column",gap:"12px"}},D={section:{marginBottom:"20px"},header:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"12px",cursor:"default"},headerCollapsible:{cursor:"pointer",userSelect:"none"},title:{fontSize:"11px",fontWeight:600,color:"var(--gray-11, #6b7280)",textTransform:"uppercase",letterSpacing:"0.5px"},chevron:{width:"14px",height:"14px",color:"var(--gray-10, #9ca3af)",transition:"transform 0.2s"},chevronCollapsed:{transform:"rotate(-90deg)"},content:{overflow:"hidden",transition:"max-height 0.2s ease-out"},contentCollapsed:{maxHeight:"0",opacity:0},contentExpanded:{maxHeight:"2000px",opacity:1}};function F({collapsed:t}){return e("svg",{style:{...D.chevron,...t?D.chevronCollapsed:{}},viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e("polyline",{points:"6 9 12 15 18 9"})})}function j({section:r,data:a,onUpdate:i,agentMode:s}){const[l,c]=o(r.collapsed??!1),d=r.layout||"grid-3",u="table"===d,g="chart"===d,h=void 0!==r.collapsed,f=n(()=>{if(!u||!r.dataKey)return[];const e=a[r.dataKey];return Array.isArray(e)?e:[]},[u,r.dataKey,a]),y=n(()=>({...D.header,...h?D.headerCollapsible:{}}),[h]),b=n(()=>({...D.content,...u||g?{}:T[d],...l?D.contentCollapsed:D.contentExpanded}),[l,u,g,d]),v=()=>{h&&c(!l)};return t("div",{style:D.section,children:[t("div",{style:y,onClick:v,onKeyDown:h?e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),v())}:void 0,role:h?"button":void 0,tabIndex:h?0:void 0,"aria-expanded":h?!l:void 0,children:[h&&e(F,{collapsed:l}),e("span",{style:D.title,children:r.title})]}),e("div",{style:b,children:u&&r.columns?e(N,{columns:r.columns,rows:f}):g&&r.chart?e(p,{chart:r.chart,data:a}):r.fields?.map((t,r)=>e(m,{field:t,value:a[t.key],onUpdate:i?e=>i(t.key,e):void 0,agentMode:s},t.key||r))})]})}const K={container:{backgroundColor:"var(--gray-2, #f9fafb)",border:"1px solid var(--gray-5, #e5e7eb)",borderRadius:"8px",padding:"16px 20px"},title:{fontSize:"16px",fontWeight:600,color:"var(--gray-12, #1f2937)",marginBottom:"16px",paddingBottom:"12px",borderBottom:"1px solid var(--gray-5, #e5e7eb)"},footer:{fontSize:"12px",color:"var(--gray-10, #9ca3af)",marginTop:"16px",paddingTop:"12px",borderTop:"1px solid var(--gray-5, #e5e7eb)"},error:{backgroundColor:"var(--red-2, #fef2f2)",border:"1px solid var(--red-6, #fca5a5)",borderRadius:"8px",padding:"16px"},errorTitle:{fontSize:"14px",fontWeight:600,color:"var(--red-11, #dc2626)",marginBottom:"12px"},errorList:{listStyle:"none",padding:0,margin:0},errorItem:{fontSize:"13px",color:"var(--red-11, #dc2626)",marginBottom:"8px",fontFamily:"var(--font-mono, ui-monospace, monospace)"},errorPath:{fontSize:"11px",color:"var(--red-9, #ef4444)",display:"block"},errorSuggestion:{fontSize:"12px",color:"var(--gray-11, #6b7280)",marginTop:"4px",fontStyle:"italic"}};function M({errors:r}){return t("div",{style:K.error,children:[t("div",{style:K.errorTitle,children:["Template Validation Failed (",r.length," error",r.length>1?"s":"",")"]}),e("ul",{style:K.errorList,children:r.map((r,n)=>t("li",{style:K.errorItem,children:[e("span",{children:r.message}),t("span",{style:K.errorPath,children:["at ",r.path]}),r.suggestion&&t("span",{style:K.errorSuggestion,children:["\\u2192 ",r.suggestion]})]},n))})]})}function I({template:r,data:a,onUpdate:o,agentMode:i,className:s}){const l=n(()=>{const e=Object.keys(a);return $(r,e)},[r,a]);return l.valid?t("div",{style:K.container,className:s,children:[r.title&&e("div",{style:K.title,children:r.title}),r.sections.map((t,r)=>e(j,{section:t,data:a,onUpdate:o,agentMode:i},t.title||r)),r.footer&&e("div",{style:K.footer,children:r.footer})]}):e(M,{errors:l.errors})}const U={error:{backgroundColor:"var(--red-2, #fef2f2)",border:"1px solid var(--red-6, #fca5a5)",borderRadius:"8px",padding:"16px",fontFamily:"var(--font-mono, ui-monospace, monospace)",fontSize:"13px"},errorTitle:{fontWeight:600,color:"var(--red-11, #dc2626)",marginBottom:"8px"},errorMessage:{color:"var(--red-10, #ef4444)",whiteSpace:"pre-wrap"},noContext:{backgroundColor:"var(--yellow-2, #fefce8)",border:"1px solid var(--yellow-6, #fde047)",borderRadius:"8px",padding:"16px"},noContextTitle:{fontSize:"14px",fontWeight:600,color:"var(--yellow-11, #ca8a04)",marginBottom:"8px"},noContextMessage:{fontSize:"13px",color:"var(--gray-11, #6b7280)"},loading:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"12px",minHeight:"150px",borderRadius:"8px",border:"1px solid var(--gray-6, #e5e7eb)",backgroundColor:"var(--gray-2, #f9fafb)"},loadingIcon:{width:"32px",height:"32px",color:"var(--gray-9, #9ca3af)"},loadingText:{fontSize:"14px",color:"var(--gray-9, #9ca3af)"},loadingDots:{display:"flex",gap:"4px"},loadingDot:{width:"8px",height:"8px",borderRadius:"50%",backgroundColor:"var(--gray-6, #d1d5db)",animation:"fusion-fragment-bounce 1s infinite"}};function A(){return t("div",{style:U.loading,children:[e("style",{children:"\n @keyframes fusion-fragment-bounce {\n 0%, 80%, 100% { transform: translateY(0); }\n 40% { transform: translateY(-6px); }\n }\n "}),t("svg",{style:U.loadingIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",role:"img",children:[e("title",{children:"Loading"}),e("polyline",{points:"16 18 22 12 16 6"}),e("polyline",{points:"8 6 2 12 8 18"})]}),e("span",{style:U.loadingText,children:"Loading fragment..."}),e("div",{style:U.loadingDots,children:[0,1,2].map(t=>e("div",{style:{...U.loadingDot,animationDelay:150*t+"ms"}},t))})]})}function z({message:r}){return t("div",{style:U.error,children:[e("div",{style:U.errorTitle,children:"Failed to parse fusion-fragment"}),e("div",{style:U.errorMessage,children:r})]})}function L({template:r}){const n=r.sections.flatMap(e=>e.fields||[]).map(e=>e.key);return t("div",{style:U.noContext,children:[e("div",{style:U.noContextTitle,children:"No data context available"}),t("div",{style:U.noContextMessage,children:["This fusion-fragment requires data with keys: ",n.join(", "),".",e("br",{}),"Wrap this component in a FusionFragmentProvider with the required data."]})]})}function P({code:t,data:r,onUpdate:a}){const o=u(),i=r??o?.data,s=a??o?.onUpdate,l=o?.sendMessage,c=n(()=>function(e){const t=e.trim();if(t.length<2)return!0;if(!t.startsWith("{"))return!1;try{return JSON.parse(t),!1}catch(e){const r=["unexpected end","unterminated string","expected","unexpected token"],n=(e instanceof Error?e.message:"").toLowerCase();if(r.some(e=>n.includes(e))){let e=0,r=0,n=!1,a=!1;for(const o of t)a?a=!1:"\\"!==o?'"'!==o?n||("{"===o?e++:"}"===o?e--:"["===o?r++:"]"===o&&r--):n=!n:a=!0;return e>0||r>0||n}return!1}}(t),[t]),d=n(()=>{if(c)return{valid:!1,errors:[],template:void 0};const e=i?Object.keys(i):[];return w(t,e)},[t,i,c]);if(c)return e(A,{});if(!d.valid&&!d.template){const t=d.errors.find(e=>"root"===e.path&&e.message.includes("JSON"));if(t)return e(z,{message:t.message})}return d.template&&!i?e(L,{template:d.template}):d.template&&i?e(I,{template:d.template,data:i,onUpdate:s,agentMode:l?{enabled:!0,sendMessage:l}:void 0}):e(z,{message:d.errors.map(e=>`${e.path}: ${e.message}`).join("\n")})}function q(){return{language:"fusion-fragment",component:P}}function B(e,t){const r={};for(const e of t)r[e]=`<${e}>`;for(const t of e.sections)if(t.fields)for(const e of t.fields)e.key in r&&(r[e.key]=R(e));return r}function R(e){switch(e.format){case"number":return 1234;case"currency":return 1e6;case"percent":return 25;case"date":return(new Date).toISOString().split("T")[0];case"boolean":return!0;default:return`Sample ${e.label}`}}function W(e,t){const r=[];r.push("Template structure preview:"),r.push(""),e.title&&(r.push(`## ${e.title}`),r.push(""));for(const n of e.sections){const e=n.layout||"grid-3";if(r.push(`### ${n.title}`),"table"===e){if(r.push("Layout: table"),n.dataKey&&r.push(`Data key: \`${n.dataKey}\``),r.push(""),n.columns){r.push("Columns:");for(const e of n.columns){let t=`- **${e.header}** → \`${e.key}\``;e.format&&"text"!==e.format&&(t+=` (${e.format})`),r.push(t)}}}else if("chart"===e){if(r.push("Layout: chart"),n.chart){const e=n.chart;e.title&&r.push(`Chart title: ${e.title}`),e.description&&r.push(`Description: ${e.description}`);const a=e.spec.mark?"string"==typeof e.spec.mark?e.spec.mark:e.spec.mark.type||"unknown":"composite";r.push(`Chart type: ${a}`),e.dataKey?(r.push(`Data key: \`${e.dataKey}\``),t.includes(e.dataKey)||r.push("⚠️ **dataKey not found in data**")):e.spec.data?.values&&r.push(`Inline data: ${e.spec.data.values.length} points`),e.height&&r.push(`Height: ${e.height}px`)}r.push("")}else{const a="list"===e?"vertical list":`${e.split("-")[1]}-column grid`;if(r.push(`Layout: ${a}${n.collapsed?" (collapsed by default)":""}`),r.push(""),n.fields)for(const e of n.fields){let n=`- **${e.label}** → \`${e.key}\``;const a=[];e.format&&"text"!==e.format&&a.push(e.format),e.unit&&a.push(`unit: "${e.unit}"`),e.editable&&a.push("editable"),e.highlight&&a.push(`highlight: ${e.highlight}`),a.length>0&&(n+=` (${a.join(", ")})`),t.includes(e.key)||(n+=" ⚠️ **key not found in data**"),r.push(n)}}r.push("")}e.footer&&(r.push("---"),r.push(`Footer: ${e.footer}`),r.push(""));const n=e.sections.reduce((e,t)=>e+(t.fields?.length||0)+(t.columns?.length||0),0),a=e.sections.flatMap(e=>e.fields||[]).filter(e=>!t.includes(e.key)).map(e=>e.key);return r.push("---"),r.push(`Summary: ${e.sections.length} section(s), ${n} field(s)/column(s)`),a.length>0?r.push(`⚠️ Missing keys: ${a.join(", ")}`):r.push("✅ All field keys found in data"),r.join("\n")}function O(e){const t=e.sections.map(e=>{if("table"===e.layout&&e.columns){const t=e.columns.slice(0,3).map(e=>e.header).join(", "),r=e.columns.length>3?`, +${e.columns.length-3} more`:"";return`${e.title} (table): ${t}${r}`}if("chart"===e.layout&&e.chart){const t=e.chart.spec.mark?"string"==typeof e.chart.spec.mark?e.chart.spec.mark:e.chart.spec.mark.type||"chart":"chart";return`${e.title} (${t} chart)`}if(e.fields){const t=e.fields.slice(0,3).map(e=>e.label).join(", "),r=e.fields.length>3?`, +${e.fields.length-3} more`:"";return`${e.title}: ${t}${r}`}return e.title});return`${e.title?`"${e.title}" - `:""}${t.join(" | ")}`}function E(e){if(0===e.length)return"Template is valid.";return`${`Template validation failed with ${e.length} error${e.length>1?"s":""}:\n`}\n${e.map((e,t)=>{let r=`${t+1}. ${e.message}`;return r+=`\n Path: ${e.path}`,e.suggestion&&(r+=`\n → ${e.suggestion}`),r}).join("\n\n")}`}function V(e,t){const r=["Template valid. Preview:"];r.push(""),e.title&&(r.push(`**${e.title}**`),r.push(""));for(const n of e.sections){const e=n.fields.length;r.push(`[${n.title}] ${e} field${e>1?"s":""}:`);for(const e of n.fields){let n=`- ${e.label} (${e.key}`;e.format&&"text"!==e.format&&(n+=`, ${e.format}`),n+=")",t.includes(e.key)||(n+=" ⚠️ key not in data"),r.push(n)}r.push("")}return r.join("\n")}function J(e,t=!0){if(0===e.length)return"No data keys available.";if(!t||e.length<=10)return`Available keys: ${e.join(", ")}`;const r=new Map;for(const t of e){const e=t.indexOf(".");if(e>0){const n=t.substring(0,e),a=t.substring(e+1),o=r.get(n)||[];o.push(a),r.set(n,o)}else{const e=r.get("")||[];e.push(t),r.set("",e)}}const n=["Available keys:"],a=r.get("");a&&a.length>0&&n.push(` ${a.join(", ")}`);for(const[e,t]of r)""!==e&&(t.length<=3?n.push(` ${e}: ${t.join(", ")}`):n.push(` ${e}: ${t.slice(0,3).join(", ")}, ... (${t.length} total)`));return n.join("\n")}export{m as FieldRenderer,b as FieldTemplateSchema,x as FragmentTemplateSchema,P as FusionFragmentHandler,c as FusionFragmentProvider,I as FusionFragmentRenderer,j as SectionRenderer,v as SectionTemplateSchema,q as createFusionFragmentCodeBlockRenderer,f as findClosestKey,y as findSimilarKeys,J as formatAvailableKeys,E as formatValidationErrors,V as formatValidationSuccess,O as generateCompactPreview,B as generateSampleData,W as generateTextPreview,w as parseAndValidateTemplate,d as useFusionFragmentContext,u as useFusionFragmentContextSafe,$ as validateTemplate};
|
|
2
2
|
//# sourceMappingURL=vertesia-fusion-ux.js.map
|