@praxisui/core 10.0.0-rc.4 → 10.0.0-rc.40
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/README.md +273 -5
- package/ai/component-registry.json +64 -45
- package/fesm2022/praxisui-core-schema.mjs +4012 -0
- package/fesm2022/praxisui-core.mjs +21485 -7649
- package/package.json +5 -1
- package/theme-bridge.css +81 -0
- package/theming/_theming.scss +175 -1
- package/types/praxisui-core-schema.d.ts +4609 -0
- package/types/praxisui-core.d.ts +15909 -12825
|
@@ -0,0 +1,4012 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
function normalizeFieldAccessMetadata(value) {
|
|
4
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
const source = value;
|
|
8
|
+
const visibleForAuthorities = normalizeAuthorityList(source['visibleForAuthorities']);
|
|
9
|
+
const editableForAuthorities = normalizeAuthorityList(source['editableForAuthorities']);
|
|
10
|
+
const reason = typeof source['reason'] === 'string' && source['reason'].trim()
|
|
11
|
+
? source['reason'].trim()
|
|
12
|
+
: undefined;
|
|
13
|
+
if (!visibleForAuthorities && !editableForAuthorities) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
...(visibleForAuthorities ? { visibleForAuthorities } : {}),
|
|
18
|
+
...(editableForAuthorities ? { editableForAuthorities } : {}),
|
|
19
|
+
...(reason ? { reason } : {}),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function evaluateFieldAccess(fieldOrAccess, context = {}) {
|
|
23
|
+
const fieldAccess = normalizeFieldAccessMetadata(isFieldAccessMetadata(fieldOrAccess)
|
|
24
|
+
? fieldOrAccess
|
|
25
|
+
: fieldOrAccess?.fieldAccess);
|
|
26
|
+
if (!fieldAccess) {
|
|
27
|
+
return { evaluated: false, visible: true, editable: true };
|
|
28
|
+
}
|
|
29
|
+
const authorities = normalizeAuthoritySet(context.authorities);
|
|
30
|
+
if (!authorities) {
|
|
31
|
+
return {
|
|
32
|
+
evaluated: false,
|
|
33
|
+
visible: true,
|
|
34
|
+
editable: true,
|
|
35
|
+
...(fieldAccess.reason ? { reason: fieldAccess.reason } : {}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const hasExplicitEditablePolicy = !!fieldAccess.editableForAuthorities?.length;
|
|
39
|
+
const editableAllowed = hasExplicitEditablePolicy
|
|
40
|
+
? matchesAuthority(fieldAccess.editableForAuthorities, authorities)
|
|
41
|
+
: false;
|
|
42
|
+
const visibleAllowed = matchesAuthority(fieldAccess.visibleForAuthorities, authorities) ||
|
|
43
|
+
editableAllowed;
|
|
44
|
+
return {
|
|
45
|
+
evaluated: true,
|
|
46
|
+
visible: visibleAllowed,
|
|
47
|
+
editable: editableAllowed || !hasExplicitEditablePolicy,
|
|
48
|
+
...(fieldAccess.reason ? { reason: fieldAccess.reason } : {}),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function isFieldAccessMetadata(value) {
|
|
52
|
+
return !!value && ('visibleForAuthorities' in value ||
|
|
53
|
+
'editableForAuthorities' in value ||
|
|
54
|
+
'reason' in value);
|
|
55
|
+
}
|
|
56
|
+
function normalizeAuthorityList(value) {
|
|
57
|
+
if (!Array.isArray(value)) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
const normalized = Array.from(new Set(value
|
|
61
|
+
.filter((item) => typeof item === 'string')
|
|
62
|
+
.map((item) => item.trim())
|
|
63
|
+
.filter(Boolean)));
|
|
64
|
+
return normalized.length ? normalized : undefined;
|
|
65
|
+
}
|
|
66
|
+
function normalizeAuthoritySet(authorities) {
|
|
67
|
+
if (!Array.isArray(authorities)) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return new Set(authorities
|
|
71
|
+
.filter((item) => typeof item === 'string')
|
|
72
|
+
.map((item) => item.trim())
|
|
73
|
+
.filter(Boolean));
|
|
74
|
+
}
|
|
75
|
+
function matchesAuthority(required, actual) {
|
|
76
|
+
if (!required || required.length === 0) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
return required.some((authority) => actual.has(authority));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const VISUALIZATION_KINDS = new Set([
|
|
83
|
+
'line',
|
|
84
|
+
'area',
|
|
85
|
+
'column',
|
|
86
|
+
'comparison',
|
|
87
|
+
'stackedBar',
|
|
88
|
+
'radial',
|
|
89
|
+
'harveyBall',
|
|
90
|
+
'bullet',
|
|
91
|
+
'delta',
|
|
92
|
+
'processFlow',
|
|
93
|
+
]);
|
|
94
|
+
const VISUALIZATION_SURFACES = new Set([
|
|
95
|
+
'table-cell',
|
|
96
|
+
'list-item',
|
|
97
|
+
'object-header',
|
|
98
|
+
'card-summary',
|
|
99
|
+
'form-presentation',
|
|
100
|
+
]);
|
|
101
|
+
const VISUALIZATION_SIZES = new Set([
|
|
102
|
+
'xs',
|
|
103
|
+
'sm',
|
|
104
|
+
'md',
|
|
105
|
+
'lg',
|
|
106
|
+
'responsive',
|
|
107
|
+
]);
|
|
108
|
+
const VISUALIZATION_TONES = new Set([
|
|
109
|
+
'neutral',
|
|
110
|
+
'info',
|
|
111
|
+
'success',
|
|
112
|
+
'warning',
|
|
113
|
+
'danger',
|
|
114
|
+
'critical',
|
|
115
|
+
]);
|
|
116
|
+
const VISUALIZATION_SCALE_SCOPES = new Set([
|
|
117
|
+
'row',
|
|
118
|
+
'page',
|
|
119
|
+
]);
|
|
120
|
+
const TABLE_SAFE_KINDS = new Set([
|
|
121
|
+
'line',
|
|
122
|
+
'area',
|
|
123
|
+
'column',
|
|
124
|
+
'comparison',
|
|
125
|
+
'stackedBar',
|
|
126
|
+
'radial',
|
|
127
|
+
'harveyBall',
|
|
128
|
+
'bullet',
|
|
129
|
+
'delta',
|
|
130
|
+
'processFlow',
|
|
131
|
+
]);
|
|
132
|
+
const TABLE_CELL_RECOMMENDED_KINDS = new Set([
|
|
133
|
+
'delta',
|
|
134
|
+
'bullet',
|
|
135
|
+
'radial',
|
|
136
|
+
'harveyBall',
|
|
137
|
+
'stackedBar',
|
|
138
|
+
]);
|
|
139
|
+
/**
|
|
140
|
+
* Returns the compact-table suitability of a supported visualization kind.
|
|
141
|
+
* Trend and workflow-heavy kinds are conditional because they require enough
|
|
142
|
+
* column width and a clear decision-making purpose to remain legible.
|
|
143
|
+
*/
|
|
144
|
+
function getPraxisTableCellVisualizationGuidance(kind) {
|
|
145
|
+
return TABLE_CELL_RECOMMENDED_KINDS.has(kind) ? 'recommended' : 'conditional';
|
|
146
|
+
}
|
|
147
|
+
function getPraxisTableCellVisualizationConstraint(kind) {
|
|
148
|
+
if (kind === 'comparison')
|
|
149
|
+
return 'row-density';
|
|
150
|
+
if (kind === 'processFlow')
|
|
151
|
+
return 'step-labels';
|
|
152
|
+
if (kind === 'line' || kind === 'area' || kind === 'column') {
|
|
153
|
+
return 'horizontal-space';
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Resolucao pura e canonica de tom semantico e rotulo acessivel para micro-visualizacoes.
|
|
159
|
+
*
|
|
160
|
+
* Precedencia de avaliacao:
|
|
161
|
+
* 1. Correspondencia discreta (`equals`), tolerante a numeros e strings.
|
|
162
|
+
* 2. Faixa numerica continua (`min` e `max`, inclusiva).
|
|
163
|
+
* 3. Faixa aberta a direita (`min` ate infinito).
|
|
164
|
+
* 4. Faixa aberta a esquerda (menos infinito ate `max`).
|
|
165
|
+
* 5. Limiar de corte progressivo (`value`).
|
|
166
|
+
* 6. Fallback estatico (`fallbackTone`).
|
|
167
|
+
*/
|
|
168
|
+
function resolvePraxisMicroVisualizationTone(value, thresholds, fallbackTone) {
|
|
169
|
+
if (value === undefined || value === null || !Array.isArray(thresholds) || thresholds.length === 0) {
|
|
170
|
+
return fallbackTone ? { tone: fallbackTone } : undefined;
|
|
171
|
+
}
|
|
172
|
+
const num = toFiniteNumber(value);
|
|
173
|
+
const isNum = num !== undefined;
|
|
174
|
+
// 1. Pass 1: Correspondencia discreta (equals) tem prioridade maxima
|
|
175
|
+
for (const t of thresholds) {
|
|
176
|
+
if (!t || !t.tone || t.equals === undefined) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (t.equals === value || String(t.equals) === String(value)) {
|
|
180
|
+
return { tone: t.tone, label: t.label, matchedThreshold: t };
|
|
181
|
+
}
|
|
182
|
+
const eqNum = toFiniteNumber(t.equals);
|
|
183
|
+
if (isNum && eqNum !== undefined && eqNum === num) {
|
|
184
|
+
return { tone: t.tone, label: t.label, matchedThreshold: t };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// 2. Pass 2: Faixas continuas ou limiares de corte
|
|
188
|
+
if (isNum) {
|
|
189
|
+
for (const t of thresholds) {
|
|
190
|
+
if (!t || !t.tone) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const hasMin = t.min !== undefined && Number.isFinite(t.min);
|
|
194
|
+
const hasMax = t.max !== undefined && Number.isFinite(t.max);
|
|
195
|
+
if (hasMin && hasMax) {
|
|
196
|
+
if (num >= t.min && num <= t.max) {
|
|
197
|
+
return { tone: t.tone, label: t.label, matchedThreshold: t };
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else if (hasMin) {
|
|
201
|
+
if (num >= t.min) {
|
|
202
|
+
return { tone: t.tone, label: t.label, matchedThreshold: t };
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else if (hasMax) {
|
|
206
|
+
if (num <= t.max) {
|
|
207
|
+
return { tone: t.tone, label: t.label, matchedThreshold: t };
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else if (t.value !== undefined && Number.isFinite(t.value) && num >= t.value) {
|
|
211
|
+
return { tone: t.tone, label: t.label, matchedThreshold: t };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return fallbackTone ? { tone: fallbackTone } : undefined;
|
|
216
|
+
}
|
|
217
|
+
function normalizePraxisPresentationVisualization(value) {
|
|
218
|
+
if (!value || typeof value !== 'object') {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
const kind = normalizeEnum$1(value.kind, VISUALIZATION_KINDS);
|
|
222
|
+
const fallbackText = normalizeText$1(value.fallbackText);
|
|
223
|
+
if (!kind || !fallbackText) {
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
const surface = normalizeEnum$1(value.surface, VISUALIZATION_SURFACES);
|
|
227
|
+
const size = normalizeEnum$1(value.size, VISUALIZATION_SIZES);
|
|
228
|
+
const scaleScope = normalizeEnum$1(value.scaleScope, VISUALIZATION_SCALE_SCOPES);
|
|
229
|
+
const tone = normalizeEnum$1(value.tone, VISUALIZATION_TONES);
|
|
230
|
+
const ariaLabel = normalizeText$1(value.ariaLabel);
|
|
231
|
+
const valueSuffix = normalizeText$1(value.valueSuffix);
|
|
232
|
+
const thresholdsObj = normalizeThresholds(value.thresholds);
|
|
233
|
+
let resolvedTone = tone;
|
|
234
|
+
let resolvedAriaLabel = ariaLabel;
|
|
235
|
+
if (!resolvedTone && thresholdsObj?.thresholds?.length) {
|
|
236
|
+
let evalVal = value.value;
|
|
237
|
+
if (evalVal === undefined && Array.isArray(value.points) && value.points.length > 0) {
|
|
238
|
+
const last = value.points[value.points.length - 1];
|
|
239
|
+
if (typeof last === 'number' && Number.isFinite(last)) {
|
|
240
|
+
evalVal = last;
|
|
241
|
+
}
|
|
242
|
+
else if (last && typeof last === 'object' && Number.isFinite(last.value)) {
|
|
243
|
+
evalVal = last.value;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
else if (Array.isArray(evalVal) && evalVal.length > 0) {
|
|
247
|
+
const last = evalVal[evalVal.length - 1];
|
|
248
|
+
evalVal = typeof last === 'object' && last !== null && 'value' in last ? last.value : last;
|
|
249
|
+
}
|
|
250
|
+
if (evalVal !== undefined && evalVal !== null) {
|
|
251
|
+
const resolution = resolvePraxisMicroVisualizationTone(evalVal, thresholdsObj.thresholds);
|
|
252
|
+
if (resolution?.tone) {
|
|
253
|
+
resolvedTone = resolution.tone;
|
|
254
|
+
}
|
|
255
|
+
if (resolution?.label && !resolvedAriaLabel) {
|
|
256
|
+
resolvedAriaLabel = `${fallbackText}: ${resolution.label}`;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
kind,
|
|
262
|
+
fallbackText,
|
|
263
|
+
...(surface ? { surface } : {}),
|
|
264
|
+
...(size ? { size } : {}),
|
|
265
|
+
...(scaleScope ? { scaleScope } : {}),
|
|
266
|
+
...(resolvedTone ? { tone: resolvedTone } : {}),
|
|
267
|
+
...(resolvedAriaLabel ? { ariaLabel: resolvedAriaLabel } : {}),
|
|
268
|
+
...(valueSuffix ? { valueSuffix } : {}),
|
|
269
|
+
...(typeof value.compactValue === 'boolean' ? { compactValue: value.compactValue } : {}),
|
|
270
|
+
...(Object.prototype.hasOwnProperty.call(value, 'value') ? { value: value.value } : {}),
|
|
271
|
+
...(normalizeExpression(value.valueExpr, 'valueExpr') ?? {}),
|
|
272
|
+
...(normalizeExpression(value.valueSuffixExpr, 'valueSuffixExpr') ?? {}),
|
|
273
|
+
...(normalizeNumber(value.min, 'min') ?? {}),
|
|
274
|
+
...(normalizeExpression(value.minExpr, 'minExpr') ?? {}),
|
|
275
|
+
...(normalizeNumber(value.max, 'max') ?? {}),
|
|
276
|
+
...(normalizeExpression(value.maxExpr, 'maxExpr') ?? {}),
|
|
277
|
+
...(normalizeNumber(value.total, 'total') ?? {}),
|
|
278
|
+
...(normalizeExpression(value.totalExpr, 'totalExpr') ?? {}),
|
|
279
|
+
...(normalizeNumber(value.target, 'target') ?? {}),
|
|
280
|
+
...(normalizeExpression(value.targetExpr, 'targetExpr') ?? {}),
|
|
281
|
+
...(normalizeNumber(value.baseline, 'baseline') ?? {}),
|
|
282
|
+
...(normalizeExpression(value.baselineExpr, 'baselineExpr') ?? {}),
|
|
283
|
+
...(normalizePoints(value.points) ?? {}),
|
|
284
|
+
...(normalizeExpression(value.pointsExpr, 'pointsExpr') ?? {}),
|
|
285
|
+
...(normalizeSegments(value.segments) ?? {}),
|
|
286
|
+
...(normalizeExpression(value.segmentsExpr, 'segmentsExpr') ?? {}),
|
|
287
|
+
...(normalizeThresholds(value.thresholds) ?? {}),
|
|
288
|
+
...(normalizeExpression(value.thresholdsExpr, 'thresholdsExpr') ?? {}),
|
|
289
|
+
...(normalizeItems(value.items) ?? {}),
|
|
290
|
+
...(normalizeExpression(value.itemsExpr, 'itemsExpr') ?? {}),
|
|
291
|
+
...(normalizeExpression(value.toneExpr, 'toneExpr') ?? {}),
|
|
292
|
+
...(value.stepLabelWidth !== undefined && (typeof value.stepLabelWidth === 'number' || typeof value.stepLabelWidth === 'string')
|
|
293
|
+
? { stepLabelWidth: value.stepLabelWidth }
|
|
294
|
+
: {}),
|
|
295
|
+
...(typeof value.stepLabelLineClamp === 'number' && Number.isFinite(value.stepLabelLineClamp)
|
|
296
|
+
? { stepLabelLineClamp: value.stepLabelLineClamp }
|
|
297
|
+
: {}),
|
|
298
|
+
...(normalizeExpression(value.ariaLabelExpr, 'ariaLabelExpr') ?? {}),
|
|
299
|
+
...(normalizeExpression(value.fallbackTextExpr, 'fallbackTextExpr') ?? {}),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
function isPraxisPresentationVisualizationTableSafe(value) {
|
|
303
|
+
const normalized = normalizePraxisPresentationVisualization(value);
|
|
304
|
+
return !!normalized && TABLE_SAFE_KINDS.has(normalized.kind);
|
|
305
|
+
}
|
|
306
|
+
function renderPraxisPresentationVisualizationHtml(value, options = {}) {
|
|
307
|
+
const visualization = normalizePraxisPresentationVisualization(value);
|
|
308
|
+
if (!visualization) {
|
|
309
|
+
return '';
|
|
310
|
+
}
|
|
311
|
+
switch (visualization.kind) {
|
|
312
|
+
case 'comparison':
|
|
313
|
+
return renderComparisonVisualizationHtml(visualization, options);
|
|
314
|
+
case 'stackedBar':
|
|
315
|
+
return renderStackedBarVisualizationHtml(visualization, options);
|
|
316
|
+
case 'bullet':
|
|
317
|
+
return renderBulletVisualizationHtml(visualization, options);
|
|
318
|
+
case 'delta':
|
|
319
|
+
return renderDeltaVisualizationHtml(visualization, options);
|
|
320
|
+
case 'radial':
|
|
321
|
+
return renderRadialVisualizationHtml(visualization, options);
|
|
322
|
+
case 'harveyBall':
|
|
323
|
+
return renderHarveyBallVisualizationHtml(visualization, options);
|
|
324
|
+
case 'line':
|
|
325
|
+
return renderLineVisualizationHtml(visualization, options);
|
|
326
|
+
case 'area':
|
|
327
|
+
return renderAreaVisualizationHtml(visualization, options);
|
|
328
|
+
case 'column':
|
|
329
|
+
return renderColumnVisualizationHtml(visualization, options);
|
|
330
|
+
case 'processFlow':
|
|
331
|
+
return renderProcessFlowVisualizationHtml(visualization, options);
|
|
332
|
+
default:
|
|
333
|
+
return `<span class="pfx-micro-viz__fallback">${escapeHtml(visualization.fallbackText)}</span>`;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function renderComparisonVisualizationHtml(visualization, options) {
|
|
337
|
+
let points = visualization.points ?? [];
|
|
338
|
+
if (points.length === 0) {
|
|
339
|
+
const primaryValue = toFiniteNumber(visualization.value);
|
|
340
|
+
const referenceValue = toFiniteNumber(visualization.baseline) ?? toFiniteNumber(visualization.target);
|
|
341
|
+
if (primaryValue !== undefined) {
|
|
342
|
+
points = [
|
|
343
|
+
{ value: primaryValue, tone: visualization.tone ?? 'info' },
|
|
344
|
+
...(referenceValue !== undefined
|
|
345
|
+
? [{ value: referenceValue, tone: 'neutral' }]
|
|
346
|
+
: []),
|
|
347
|
+
];
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (points.length === 0) {
|
|
351
|
+
return renderFallbackVisualizationHtml(visualization, visualization.tone ?? 'neutral');
|
|
352
|
+
}
|
|
353
|
+
const explicitCeiling = Math.max(toFiniteNumber(visualization.max) ?? 0, toFiniteNumber(visualization.total) ?? 0);
|
|
354
|
+
const max = Math.max(1, explicitCeiling, ...points.map((point) => Math.max(0, point.value)));
|
|
355
|
+
const suffix = visualization.valueSuffix ?? '';
|
|
356
|
+
const useCompact = visualization.compactValue === true;
|
|
357
|
+
const rows = points
|
|
358
|
+
.map((point) => {
|
|
359
|
+
const width = percent(point.value, max);
|
|
360
|
+
const formattedVal = formatVisualizationMetricValue(point.value, options, useCompact, suffix);
|
|
361
|
+
const readout = `${point.label ? `${point.label}: ` : ''}${formattedVal} (${Math.round(Number(width))}%)`;
|
|
362
|
+
return `
|
|
363
|
+
<span class="pfx-micro-viz__row" data-tone="${escapeHtml(point.tone ?? visualization.tone ?? 'info')}" data-micro-readout="${escapeHtml(readout)}">
|
|
364
|
+
<span class="pfx-micro-viz__label">${escapeHtml(point.label ?? '')}</span>
|
|
365
|
+
<span class="pfx-micro-viz__track">
|
|
366
|
+
<span class="pfx-micro-viz__bar" style="width:${width}%"></span>
|
|
367
|
+
</span>
|
|
368
|
+
<span class="pfx-micro-viz__value">${escapeHtml(formattedVal)}</span>
|
|
369
|
+
</span>`;
|
|
370
|
+
})
|
|
371
|
+
.join('');
|
|
372
|
+
return `<span class="pfx-micro-viz pfx-micro-viz__comparison" role="img" aria-label="${escapeHtml(visualization.ariaLabel ?? visualization.fallbackText)}">${rows}</span>`;
|
|
373
|
+
}
|
|
374
|
+
function renderStackedBarVisualizationHtml(visualization, options) {
|
|
375
|
+
const segments = visualization.segments?.length
|
|
376
|
+
? visualization.segments
|
|
377
|
+
: (visualization.items?.filter((item) => typeof item?.value === 'number' && Number.isFinite(item.value)) ?? []);
|
|
378
|
+
if (segments.length === 0) {
|
|
379
|
+
return renderFallbackVisualizationHtml(visualization, visualization.tone ?? 'neutral');
|
|
380
|
+
}
|
|
381
|
+
const total = visualization.total && visualization.total > 0
|
|
382
|
+
? visualization.total
|
|
383
|
+
: Math.max(1, segments.reduce((sum, segment) => sum + Math.max(0, segment.value), 0));
|
|
384
|
+
const suffix = visualization.valueSuffix ?? '';
|
|
385
|
+
const useCompact = visualization.compactValue === true;
|
|
386
|
+
const bars = segments
|
|
387
|
+
.map((segment) => {
|
|
388
|
+
const pctStr = percent(segment.value, total);
|
|
389
|
+
const formattedVal = formatVisualizationMetricValue(segment.value, options, useCompact, suffix);
|
|
390
|
+
const readout = `${segment.label ? `${segment.label}: ` : ''}${formattedVal} (${Math.round(Number(pctStr))}%)`;
|
|
391
|
+
return `
|
|
392
|
+
<span
|
|
393
|
+
class="pfx-micro-viz__segment"
|
|
394
|
+
data-tone="${escapeHtml(segment.tone ?? visualization.tone ?? 'info')}"
|
|
395
|
+
data-micro-readout="${escapeHtml(readout)}"
|
|
396
|
+
style="width:${pctStr}%"
|
|
397
|
+
title="${escapeHtml(`${segment.label ?? ''} ${formattedVal}`.trim())}"
|
|
398
|
+
></span>`;
|
|
399
|
+
})
|
|
400
|
+
.join('');
|
|
401
|
+
const meta = segments
|
|
402
|
+
.slice(0, 3)
|
|
403
|
+
.map((segment) => `<span>${escapeHtml(segment.label ?? '')}: ${escapeHtml(formatVisualizationMetricValue(segment.value, options, useCompact, suffix))}</span>`)
|
|
404
|
+
.join('');
|
|
405
|
+
return `
|
|
406
|
+
<span class="pfx-micro-viz pfx-micro-viz__stacked" role="img" aria-label="${escapeHtml(visualization.ariaLabel ?? visualization.fallbackText)}">
|
|
407
|
+
<span class="pfx-micro-viz__segments">${bars}</span>
|
|
408
|
+
<span class="pfx-micro-viz__meta">${meta}</span>
|
|
409
|
+
</span>`;
|
|
410
|
+
}
|
|
411
|
+
function resolveBulletMax(visualization) {
|
|
412
|
+
const thresholds = visualization.thresholds ?? [];
|
|
413
|
+
const thresholdValues = thresholds
|
|
414
|
+
.map(t => t.value ?? t.max ?? t.min ?? 0)
|
|
415
|
+
.filter((v) => Number.isFinite(v) && v > 0);
|
|
416
|
+
const values = [
|
|
417
|
+
toFiniteNumber(visualization.value) ?? 0,
|
|
418
|
+
visualization.target ?? 0,
|
|
419
|
+
visualization.total ?? 0,
|
|
420
|
+
visualization.max ?? 0,
|
|
421
|
+
...thresholdValues
|
|
422
|
+
].filter((v) => Number.isFinite(v) && v > 0);
|
|
423
|
+
const fallbackCeiling = visualization.total && visualization.total > 0
|
|
424
|
+
? visualization.total
|
|
425
|
+
: visualization.max && visualization.max > 0
|
|
426
|
+
? visualization.max
|
|
427
|
+
: 100;
|
|
428
|
+
return Math.max(...values, fallbackCeiling);
|
|
429
|
+
}
|
|
430
|
+
function renderBulletVisualizationHtml(visualization, options) {
|
|
431
|
+
const currentValue = toFiniteNumber(visualization.value);
|
|
432
|
+
if (currentValue === undefined) {
|
|
433
|
+
return renderFallbackVisualizationHtml(visualization, visualization.tone ?? 'neutral');
|
|
434
|
+
}
|
|
435
|
+
const max = resolveBulletMax(visualization);
|
|
436
|
+
const target = toFiniteNumber(visualization.target);
|
|
437
|
+
const targetLeft = target === undefined ? null : percent(target, max);
|
|
438
|
+
const isTable = visualization.surface === 'table-cell';
|
|
439
|
+
const suffix = visualization.valueSuffix ?? '';
|
|
440
|
+
// thresholds: sort ascending by boundary value so bands draw continuously regardless of declaration order
|
|
441
|
+
const thresholds = visualization.thresholds ?? [];
|
|
442
|
+
const sortedThresholds = [...thresholds].sort((a, b) => {
|
|
443
|
+
const aVal = a.value ?? a.max ?? a.min ?? 0;
|
|
444
|
+
const bVal = b.value ?? b.max ?? b.min ?? 0;
|
|
445
|
+
return aVal - bVal;
|
|
446
|
+
});
|
|
447
|
+
let previous = 0;
|
|
448
|
+
const bands = sortedThresholds.map(t => {
|
|
449
|
+
const tVal = t.value ?? t.max ?? t.min ?? 0;
|
|
450
|
+
const current = Math.max(tVal, previous);
|
|
451
|
+
const left = max > 0 ? percent(previous, max) : '0';
|
|
452
|
+
const width = max > 0 ? percent(current - previous, max) : '0';
|
|
453
|
+
previous = current;
|
|
454
|
+
return { left, width, tone: t.tone ?? 'info' };
|
|
455
|
+
}).filter(b => parseFloat(b.width) > 0);
|
|
456
|
+
const bandsHtml = bands.map(b => `<span class="pfx-micro-bullet__range" data-tone="${escapeHtml(b.tone)}" style="left: ${b.left}%; width: ${b.width}%;"></span>`).join('');
|
|
457
|
+
const topHtml = isTable ? '' : `
|
|
458
|
+
<div class="pfx-micro-bullet__top">
|
|
459
|
+
<span class="pfx-micro-bullet__label">${escapeHtml(visualization.fallbackText)}</span>
|
|
460
|
+
<span class="pfx-micro-bullet__value">
|
|
461
|
+
${escapeHtml(formatVisualizationMetricValue(currentValue, options, false, suffix))}
|
|
462
|
+
${target === undefined ? '' : `<span class="pfx-micro-bullet__target-val">/ Target: ${escapeHtml(formatVisualizationMetricValue(target, options, false, suffix))}</span>`}
|
|
463
|
+
</span>
|
|
464
|
+
</div>`;
|
|
465
|
+
const bottomHtml = isTable ? '' : `
|
|
466
|
+
<div class="pfx-micro-bullet__bottom">
|
|
467
|
+
<span>${escapeHtml(formatVisualizationMetricValue(visualization.baseline ?? 0, options, false, suffix))}</span>
|
|
468
|
+
<span>${escapeHtml(formatVisualizationMetricValue(max, options, false, suffix))}</span>
|
|
469
|
+
</div>`;
|
|
470
|
+
const showCompactValue = isTable && visualization.compactValue !== false;
|
|
471
|
+
const useCompactNotation = visualization.compactValue === true;
|
|
472
|
+
const compactValueHtml = showCompactValue
|
|
473
|
+
? `<span class="pfx-micro-bullet__compact-value">${escapeHtml(formatVisualizationMetricValue(currentValue, options, useCompactNotation, suffix))}</span>`
|
|
474
|
+
: '';
|
|
475
|
+
const currentStr = formatVisualizationMetricValue(currentValue, options, false, suffix);
|
|
476
|
+
const diff = target !== undefined ? currentValue - target : undefined;
|
|
477
|
+
const diffSign = diff !== undefined && diff > 0 ? '+' : '';
|
|
478
|
+
const bulletReadout = target !== undefined && diff !== undefined
|
|
479
|
+
? `${currentStr} / Target ${formatVisualizationMetricValue(target, options, false, suffix)} (${diffSign}${formatVisualizationMetricValue(diff, options, false, suffix)})`
|
|
480
|
+
: `${currentStr} / ${formatVisualizationMetricValue(max, options, false, suffix)}`;
|
|
481
|
+
const tabIndexAttr = isTable ? '' : ' tabindex="0"';
|
|
482
|
+
return `
|
|
483
|
+
<span class="pfx-micro-viz pfx-micro-viz__bullet"${tabIndexAttr} data-tone="${escapeHtml(visualization.tone ?? 'info')}" data-micro-readout="${escapeHtml(bulletReadout)}" role="img" aria-label="${escapeHtml(visualization.ariaLabel ?? visualization.fallbackText)}">
|
|
484
|
+
${topHtml}
|
|
485
|
+
<span class="pfx-micro-bullet__track">
|
|
486
|
+
${bandsHtml}
|
|
487
|
+
<span class="pfx-micro-bullet__actual" data-tone="${escapeHtml(visualization.tone ?? 'info')}" style="width: ${percent(currentValue, max)}%;"></span>
|
|
488
|
+
${targetLeft === null ? '' : `<span class="pfx-micro-bullet__target" style="left: ${targetLeft}%;"></span>`}
|
|
489
|
+
</span>
|
|
490
|
+
${bottomHtml}
|
|
491
|
+
${compactValueHtml}
|
|
492
|
+
</span>`;
|
|
493
|
+
}
|
|
494
|
+
function renderDeltaVisualizationHtml(visualization, options) {
|
|
495
|
+
const value = toFiniteNumber(visualization.value);
|
|
496
|
+
const direction = value === undefined ? 'neutral' : value < 0 ? 'down' : value > 0 ? 'up' : 'neutral';
|
|
497
|
+
const symbol = direction === 'up' ? '▲' : direction === 'down' ? '▼' : '→';
|
|
498
|
+
const tone = visualization.tone ??
|
|
499
|
+
(value === undefined
|
|
500
|
+
? 'neutral'
|
|
501
|
+
: value < 0
|
|
502
|
+
? 'danger'
|
|
503
|
+
: value > 0
|
|
504
|
+
? 'success'
|
|
505
|
+
: 'neutral');
|
|
506
|
+
const valueSuffix = visualization.valueSuffix ?? '';
|
|
507
|
+
const text = value === undefined
|
|
508
|
+
? visualization.fallbackText
|
|
509
|
+
: formatVisualizationMetricValue(Math.abs(value), options, visualization.compactValue === true, valueSuffix);
|
|
510
|
+
const directionLabel = direction === 'up'
|
|
511
|
+
? 'up'
|
|
512
|
+
: direction === 'down'
|
|
513
|
+
? 'down'
|
|
514
|
+
: 'stable';
|
|
515
|
+
const aria = visualization.ariaLabel ?? `${visualization.fallbackText}: ${directionLabel} ${text}`;
|
|
516
|
+
const target = toFiniteNumber(visualization.target);
|
|
517
|
+
const baseline = toFiniteNumber(visualization.baseline);
|
|
518
|
+
const isTable = visualization.surface === 'table-cell';
|
|
519
|
+
const deltaReadout = target !== undefined
|
|
520
|
+
? `Target ${formatVisualizationMetricValue(target, options, false, valueSuffix)}`
|
|
521
|
+
: baseline !== undefined
|
|
522
|
+
? `Base ${formatVisualizationMetricValue(baseline, options, false, valueSuffix)}`
|
|
523
|
+
: null;
|
|
524
|
+
const readoutAttr = deltaReadout
|
|
525
|
+
? `${isTable ? '' : ' tabindex="0"'} data-micro-readout="${escapeHtml(deltaReadout)}"`
|
|
526
|
+
: '';
|
|
527
|
+
return `
|
|
528
|
+
<span class="pfx-micro-viz pfx-micro-viz__delta" data-tone="${escapeHtml(tone)}" data-direction="${escapeHtml(direction)}"${readoutAttr} role="img" aria-label="${escapeHtml(aria)}">
|
|
529
|
+
<span class="pfx-micro-viz__delta-symbol" aria-hidden="true">${symbol}</span>
|
|
530
|
+
<span>${escapeHtml(text)}</span>
|
|
531
|
+
</span>`;
|
|
532
|
+
}
|
|
533
|
+
function percent(value, total) {
|
|
534
|
+
if (!Number.isFinite(value) || !Number.isFinite(total) || total <= 0) {
|
|
535
|
+
return '0';
|
|
536
|
+
}
|
|
537
|
+
return Math.max(0, Math.min(100, (value / total) * 100)).toFixed(2);
|
|
538
|
+
}
|
|
539
|
+
function toFiniteNumber(value) {
|
|
540
|
+
if (typeof value === 'number') {
|
|
541
|
+
return Number.isFinite(value) ? value : undefined;
|
|
542
|
+
}
|
|
543
|
+
if (typeof value === 'string') {
|
|
544
|
+
const trimmed = value.trim();
|
|
545
|
+
if (!trimmed) {
|
|
546
|
+
return undefined;
|
|
547
|
+
}
|
|
548
|
+
const parsed = Number(trimmed);
|
|
549
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
550
|
+
}
|
|
551
|
+
return undefined;
|
|
552
|
+
}
|
|
553
|
+
function formatVisualizationMetricValue(value, options, compactValue = false, suffix = '') {
|
|
554
|
+
if (typeof options.formatValue === 'function') {
|
|
555
|
+
const custom = options.formatValue(value, compactValue);
|
|
556
|
+
if (typeof custom === 'string' && custom.trim().length > 0) {
|
|
557
|
+
return suffix && !custom.endsWith(suffix) ? `${custom}${suffix}` : custom;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return `${formatMicroNumber(value, options.locale, compactValue)}${suffix}`;
|
|
561
|
+
}
|
|
562
|
+
function formatMicroNumber(value, locale, compactValue = false) {
|
|
563
|
+
if (compactValue && Math.abs(value) >= 1000) {
|
|
564
|
+
return new Intl.NumberFormat(locale || undefined, {
|
|
565
|
+
notation: 'compact',
|
|
566
|
+
compactDisplay: 'short',
|
|
567
|
+
maximumFractionDigits: 1,
|
|
568
|
+
}).format(value);
|
|
569
|
+
}
|
|
570
|
+
return new Intl.NumberFormat(locale || undefined, {
|
|
571
|
+
maximumFractionDigits: Math.abs(value) < 10 ? 2 : 0,
|
|
572
|
+
}).format(value);
|
|
573
|
+
}
|
|
574
|
+
function escapeHtml(value) {
|
|
575
|
+
return String(value ?? '')
|
|
576
|
+
.replace(/&/g, '&')
|
|
577
|
+
.replace(/</g, '<')
|
|
578
|
+
.replace(/>/g, '>')
|
|
579
|
+
.replace(/"/g, '"')
|
|
580
|
+
.replace(/'/g, ''');
|
|
581
|
+
}
|
|
582
|
+
function normalizePoints(value) {
|
|
583
|
+
const points = normalizeNumericEntries(value);
|
|
584
|
+
return points.length ? { points } : undefined;
|
|
585
|
+
}
|
|
586
|
+
function normalizeSegments(value) {
|
|
587
|
+
const segments = normalizeNumericEntries(value);
|
|
588
|
+
return segments.length ? { segments } : undefined;
|
|
589
|
+
}
|
|
590
|
+
function normalizeThresholds(value) {
|
|
591
|
+
if (!Array.isArray(value)) {
|
|
592
|
+
return undefined;
|
|
593
|
+
}
|
|
594
|
+
const thresholds = value
|
|
595
|
+
.map((item) => {
|
|
596
|
+
if (!item || typeof item !== 'object')
|
|
597
|
+
return undefined;
|
|
598
|
+
const numVal = toFiniteNumber(item.value);
|
|
599
|
+
const minVal = toFiniteNumber(item.min);
|
|
600
|
+
const maxVal = toFiniteNumber(item.max);
|
|
601
|
+
const tone = normalizeEnum$1(item.tone, VISUALIZATION_TONES);
|
|
602
|
+
const label = normalizeText$1(item.label);
|
|
603
|
+
const hasCondition = numVal !== undefined || minVal !== undefined || maxVal !== undefined || item.equals !== undefined;
|
|
604
|
+
if (!hasCondition) {
|
|
605
|
+
return undefined;
|
|
606
|
+
}
|
|
607
|
+
return {
|
|
608
|
+
...(label ? { label } : {}),
|
|
609
|
+
...(numVal !== undefined ? { value: numVal } : {}),
|
|
610
|
+
...(minVal !== undefined ? { min: minVal } : {}),
|
|
611
|
+
...(maxVal !== undefined ? { max: maxVal } : {}),
|
|
612
|
+
...(item.equals !== undefined ? { equals: item.equals } : {}),
|
|
613
|
+
...(tone ? { tone } : {}),
|
|
614
|
+
};
|
|
615
|
+
})
|
|
616
|
+
.filter((item) => !!item);
|
|
617
|
+
return thresholds.length ? { thresholds } : undefined;
|
|
618
|
+
}
|
|
619
|
+
function normalizeItems(value) {
|
|
620
|
+
if (!Array.isArray(value)) {
|
|
621
|
+
return undefined;
|
|
622
|
+
}
|
|
623
|
+
const items = value
|
|
624
|
+
.map((item) => normalizeVisualizationItem(item))
|
|
625
|
+
.filter((item) => !!item);
|
|
626
|
+
return items.length ? { items } : undefined;
|
|
627
|
+
}
|
|
628
|
+
function normalizeExpression(value, key) {
|
|
629
|
+
if (typeof value === 'string') {
|
|
630
|
+
const normalized = value.trim();
|
|
631
|
+
return normalized ? { [key]: normalized } : undefined;
|
|
632
|
+
}
|
|
633
|
+
if (value && typeof value === 'object') {
|
|
634
|
+
return { [key]: value };
|
|
635
|
+
}
|
|
636
|
+
return undefined;
|
|
637
|
+
}
|
|
638
|
+
function normalizeNumericEntries(value) {
|
|
639
|
+
if (!Array.isArray(value)) {
|
|
640
|
+
return [];
|
|
641
|
+
}
|
|
642
|
+
return value
|
|
643
|
+
.map((item) => {
|
|
644
|
+
if (typeof item === 'number' || typeof item === 'string') {
|
|
645
|
+
const num = toFiniteNumber(item);
|
|
646
|
+
return num !== undefined ? { value: num } : null;
|
|
647
|
+
}
|
|
648
|
+
if (!item || typeof item !== 'object') {
|
|
649
|
+
return null;
|
|
650
|
+
}
|
|
651
|
+
const num = toFiniteNumber(item.value);
|
|
652
|
+
if (num === undefined) {
|
|
653
|
+
return null;
|
|
654
|
+
}
|
|
655
|
+
const label = normalizeText$1(item.label);
|
|
656
|
+
const tone = normalizeEnum$1(item.tone, VISUALIZATION_TONES);
|
|
657
|
+
return {
|
|
658
|
+
value: num,
|
|
659
|
+
...(label ? { label } : {}),
|
|
660
|
+
...(tone ? { tone } : {}),
|
|
661
|
+
};
|
|
662
|
+
})
|
|
663
|
+
.filter((item) => !!item);
|
|
664
|
+
}
|
|
665
|
+
function normalizeVisualizationItem(item) {
|
|
666
|
+
if (!item || typeof item !== 'object') {
|
|
667
|
+
return null;
|
|
668
|
+
}
|
|
669
|
+
const id = normalizeText$1(item.id);
|
|
670
|
+
const label = normalizeText$1(item.label);
|
|
671
|
+
const icon = normalizeText$1(item.icon);
|
|
672
|
+
const state = normalizeText$1(item.state);
|
|
673
|
+
const tone = normalizeEnum$1(item.tone, VISUALIZATION_TONES);
|
|
674
|
+
const normalizedValue = toFiniteNumber(item.value);
|
|
675
|
+
if (!id && !label && normalizedValue === undefined && !icon && !state && !tone) {
|
|
676
|
+
return null;
|
|
677
|
+
}
|
|
678
|
+
return {
|
|
679
|
+
...(id ? { id } : {}),
|
|
680
|
+
...(label ? { label } : {}),
|
|
681
|
+
...(normalizedValue !== undefined ? { value: normalizedValue } : {}),
|
|
682
|
+
...(icon ? { icon } : {}),
|
|
683
|
+
...(state ? { state } : {}),
|
|
684
|
+
...(tone ? { tone } : {}),
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
function normalizeNumber(value, key) {
|
|
688
|
+
const num = toFiniteNumber(value);
|
|
689
|
+
return num !== undefined ? { [key]: num } : undefined;
|
|
690
|
+
}
|
|
691
|
+
function normalizeEnum$1(value, allowed) {
|
|
692
|
+
if (typeof value !== 'string') {
|
|
693
|
+
return undefined;
|
|
694
|
+
}
|
|
695
|
+
const normalized = value.trim();
|
|
696
|
+
return allowed.has(normalized) ? normalized : undefined;
|
|
697
|
+
}
|
|
698
|
+
function normalizeText$1(value) {
|
|
699
|
+
if (typeof value !== 'string') {
|
|
700
|
+
return undefined;
|
|
701
|
+
}
|
|
702
|
+
const trimmed = value.trim();
|
|
703
|
+
return trimmed.length ? trimmed : undefined;
|
|
704
|
+
}
|
|
705
|
+
function renderRadialVisualizationHtml(visualization, options) {
|
|
706
|
+
const value = toFiniteNumber(visualization.value);
|
|
707
|
+
if (value === undefined) {
|
|
708
|
+
return renderFallbackVisualizationHtml(visualization, visualization.tone ?? 'neutral');
|
|
709
|
+
}
|
|
710
|
+
const total = visualization.total && visualization.total > 0 ? visualization.total : 100;
|
|
711
|
+
const pct = Math.max(0, Math.min(100, (value / total) * 100));
|
|
712
|
+
const tone = visualization.tone ?? 'info';
|
|
713
|
+
const suffix = visualization.valueSuffix ?? '';
|
|
714
|
+
const dashArray = `${pct.toFixed(1)}, 100`;
|
|
715
|
+
const pctText = `${Math.round(pct)}%`;
|
|
716
|
+
const aria = visualization.ariaLabel ?? `${visualization.fallbackText} (${pctText})`;
|
|
717
|
+
const isTable = visualization.surface === 'table-cell';
|
|
718
|
+
const svgText = isTable
|
|
719
|
+
? ''
|
|
720
|
+
: `<text x="18" y="21" class="pfx-micro-radial-svg__text">${escapeHtml(pctText)}</text>`;
|
|
721
|
+
const externalText = isTable
|
|
722
|
+
? `<span class="pfx-micro-radial-value">${escapeHtml(pctText)}</span>`
|
|
723
|
+
: '';
|
|
724
|
+
const radialReadout = `${formatVisualizationMetricValue(value, options, false, suffix)} / ${formatVisualizationMetricValue(total, options, false, suffix)} (${pctText})`;
|
|
725
|
+
const tabIndexAttr = isTable ? '' : ' tabindex="0"';
|
|
726
|
+
return `
|
|
727
|
+
<span class="pfx-micro-viz pfx-micro-viz__radial"${tabIndexAttr} data-tone="${escapeHtml(tone)}" data-micro-readout="${escapeHtml(radialReadout)}" role="img" aria-label="${escapeHtml(aria)}">
|
|
728
|
+
<svg class="pfx-micro-radial-svg" viewBox="0 0 36 36">
|
|
729
|
+
<circle class="pfx-micro-radial-svg__track" cx="18" cy="18" r="15.9155" />
|
|
730
|
+
<circle class="pfx-micro-radial-svg__bar" cx="18" cy="18" r="15.9155" stroke-dasharray="${dashArray}" transform="rotate(-90 18 18)" />
|
|
731
|
+
${svgText}
|
|
732
|
+
</svg>
|
|
733
|
+
${externalText}
|
|
734
|
+
</span>`;
|
|
735
|
+
}
|
|
736
|
+
function renderHarveyBallVisualizationHtml(visualization, options) {
|
|
737
|
+
const value = toFiniteNumber(visualization.value);
|
|
738
|
+
if (value === undefined) {
|
|
739
|
+
return renderFallbackVisualizationHtml(visualization, visualization.tone ?? 'neutral');
|
|
740
|
+
}
|
|
741
|
+
const total = visualization.total && visualization.total > 0 ? visualization.total : 100;
|
|
742
|
+
const pct = Math.max(0, Math.min(100, (value / total) * 100));
|
|
743
|
+
const tone = visualization.tone ?? 'info';
|
|
744
|
+
const isTable = visualization.surface === 'table-cell';
|
|
745
|
+
const tabIndexAttr = isTable ? '' : ' tabindex="0"';
|
|
746
|
+
const suffix = visualization.valueSuffix ?? '';
|
|
747
|
+
const strokeLength = pct * 0.50265;
|
|
748
|
+
const dashArray = `${strokeLength.toFixed(3)} 50.265`;
|
|
749
|
+
const aria = visualization.ariaLabel ?? `${visualization.fallbackText} (${Math.round(pct)}%)`;
|
|
750
|
+
const formattedValue = formatVisualizationMetricValue(value, options, false, suffix);
|
|
751
|
+
const formattedTotal = formatVisualizationMetricValue(total, options, false, suffix);
|
|
752
|
+
const harveyReadout = `${formattedValue}/${formattedTotal} (${Math.round(pct)}%)`;
|
|
753
|
+
return `
|
|
754
|
+
<span class="pfx-micro-viz pfx-micro-viz__harvey"${tabIndexAttr} data-tone="${escapeHtml(tone)}" data-micro-readout="${escapeHtml(harveyReadout)}" role="img" aria-label="${escapeHtml(aria)}">
|
|
755
|
+
<svg class="pfx-micro-harvey-svg" viewBox="0 0 36 36">
|
|
756
|
+
<circle class="pfx-micro-harvey-svg__track" cx="18" cy="18" r="16" />
|
|
757
|
+
<circle class="pfx-micro-harvey-svg__bar" cx="18" cy="18" r="8" stroke-dasharray="${dashArray}" transform="rotate(-90 18 18)" />
|
|
758
|
+
</svg>
|
|
759
|
+
<span class="pfx-micro-harvey-fraction">
|
|
760
|
+
<strong>${escapeHtml(formattedValue)}</strong>
|
|
761
|
+
<span class="pfx-separator">/</span>
|
|
762
|
+
<span class="pfx-total">${escapeHtml(formattedTotal)}</span>
|
|
763
|
+
</span>
|
|
764
|
+
</span>`;
|
|
765
|
+
}
|
|
766
|
+
function resolveTrendBounds(points, visualization, anchorZero = false) {
|
|
767
|
+
const values = points.map((p) => p.value);
|
|
768
|
+
const refValue = toFiniteNumber(visualization?.target) ?? toFiniteNumber(visualization?.baseline);
|
|
769
|
+
const explicitMin = toFiniteNumber(visualization?.min);
|
|
770
|
+
const explicitMax = toFiniteNumber(visualization?.max);
|
|
771
|
+
const baseCandidates = anchorZero ? [...values, 0] : [...values];
|
|
772
|
+
if (refValue !== undefined) {
|
|
773
|
+
baseCandidates.push(refValue);
|
|
774
|
+
}
|
|
775
|
+
const minVal = explicitMin !== undefined ? Math.min(explicitMin, ...baseCandidates) : Math.min(...baseCandidates);
|
|
776
|
+
const maxVal = explicitMax !== undefined ? Math.max(explicitMax, ...baseCandidates) : Math.max(...baseCandidates);
|
|
777
|
+
const valRange = maxVal - minVal === 0 ? 1 : maxVal - minVal;
|
|
778
|
+
return { minVal, maxVal, valRange, refValue };
|
|
779
|
+
}
|
|
780
|
+
function getPointsCoordinates(points, width, height, padding, visualization) {
|
|
781
|
+
if (points.length < 2)
|
|
782
|
+
return [];
|
|
783
|
+
const { minVal, valRange } = resolveTrendBounds(points, visualization, false);
|
|
784
|
+
return points.map((p, index) => {
|
|
785
|
+
const x = padding + (index / (points.length - 1)) * (width - 2 * padding);
|
|
786
|
+
const y = height - padding - ((p.value - minVal) / valRange) * (height - 2 * padding);
|
|
787
|
+
return { x, y };
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
function renderTrendReferenceLineHtml(points, width, height, padding, visualization, anchorZero = false) {
|
|
791
|
+
const { minVal, valRange, refValue } = resolveTrendBounds(points, visualization, anchorZero);
|
|
792
|
+
if (refValue === undefined) {
|
|
793
|
+
return '';
|
|
794
|
+
}
|
|
795
|
+
const refY = height - padding - ((refValue - minVal) / valRange) * (height - 2 * padding);
|
|
796
|
+
return `<line class="pfx-micro-trend__ref-line" x1="${padding}" y1="${refY.toFixed(1)}" x2="${width - padding}" y2="${refY.toFixed(1)}" stroke="currentColor" stroke-opacity="0.38" stroke-width="1" stroke-dasharray="2 2" />`;
|
|
797
|
+
}
|
|
798
|
+
function renderTrendScrubLayerHtml(points, coords, width, height, visualization, options) {
|
|
799
|
+
const defaultTone = visualization.tone ?? 'info';
|
|
800
|
+
const suffix = visualization.valueSuffix ?? '';
|
|
801
|
+
const slicesHtml = points
|
|
802
|
+
.map((point, index) => {
|
|
803
|
+
const coord = coords[index] ?? { x: 50, y: 15 };
|
|
804
|
+
const xPct = ((coord.x / width) * 100).toFixed(1);
|
|
805
|
+
const yPct = ((coord.y / height) * 100).toFixed(1);
|
|
806
|
+
const pointTone = point.tone ??
|
|
807
|
+
(visualization.thresholds?.length
|
|
808
|
+
? resolvePraxisMicroVisualizationTone(point.value, visualization.thresholds)?.tone ?? defaultTone
|
|
809
|
+
: defaultTone);
|
|
810
|
+
const labelPrefix = point.label ? `${point.label}: ` : `#${index + 1}: `;
|
|
811
|
+
const readout = `${labelPrefix}${formatVisualizationMetricValue(point.value, options, visualization.compactValue === true, suffix)}`;
|
|
812
|
+
return `<span class="pfx-micro-trend__scrub-slice" data-tone="${escapeHtml(pointTone)}" data-micro-readout="${escapeHtml(readout)}" style="--pfx-scrub-x:${xPct}%;--pfx-scrub-y:${yPct}%;"></span>`;
|
|
813
|
+
})
|
|
814
|
+
.join('');
|
|
815
|
+
return `<span class="pfx-micro-trend__scrub-layer" aria-hidden="true">${slicesHtml}</span>`;
|
|
816
|
+
}
|
|
817
|
+
function renderLineVisualizationHtml(visualization, options) {
|
|
818
|
+
const points = visualization.points ?? [];
|
|
819
|
+
const tone = visualization.tone ?? 'info';
|
|
820
|
+
if (points.length < 2) {
|
|
821
|
+
return renderFallbackVisualizationHtml(visualization, tone);
|
|
822
|
+
}
|
|
823
|
+
const width = 100;
|
|
824
|
+
const height = 30;
|
|
825
|
+
const padding = 4;
|
|
826
|
+
const coords = getPointsCoordinates(points, width, height, padding, visualization);
|
|
827
|
+
const pathD = coords.map((c, i) => `${i === 0 ? 'M' : 'L'} ${c.x.toFixed(1)} ${c.y.toFixed(1)}`).join(' ');
|
|
828
|
+
const refLineHtml = renderTrendReferenceLineHtml(points, width, height, padding, visualization, false);
|
|
829
|
+
// Highlight extreme/boundary values
|
|
830
|
+
let minIdx = 0;
|
|
831
|
+
let maxIdx = 0;
|
|
832
|
+
for (let i = 1; i < points.length; i++) {
|
|
833
|
+
if (points[i].value < points[minIdx].value)
|
|
834
|
+
minIdx = i;
|
|
835
|
+
if (points[i].value > points[maxIdx].value)
|
|
836
|
+
maxIdx = i;
|
|
837
|
+
}
|
|
838
|
+
const markers = [
|
|
839
|
+
{ x: coords[0].x, y: coords[0].y, tone: points[0].tone ?? tone },
|
|
840
|
+
{ x: coords[coords.length - 1].x, y: coords[coords.length - 1].y, tone: points[points.length - 1].tone ?? tone }
|
|
841
|
+
];
|
|
842
|
+
if (minIdx !== 0 && minIdx !== coords.length - 1) {
|
|
843
|
+
markers.push({ x: coords[minIdx].x, y: coords[minIdx].y, tone: points[minIdx].tone ?? 'danger' });
|
|
844
|
+
}
|
|
845
|
+
if (maxIdx !== 0 && maxIdx !== coords.length - 1) {
|
|
846
|
+
markers.push({ x: coords[maxIdx].x, y: coords[maxIdx].y, tone: points[maxIdx].tone ?? 'success' });
|
|
847
|
+
}
|
|
848
|
+
const circlesHtml = markers.map(c => `<circle cx="${c.x.toFixed(1)}" cy="${c.y.toFixed(1)}" r="2.5" class="pfx-micro-trend__marker" data-tone="${escapeHtml(c.tone)}" />`).join('');
|
|
849
|
+
const scrubLayerHtml = renderTrendScrubLayerHtml(points, coords, width, height, visualization, options);
|
|
850
|
+
const isTable = visualization.surface === 'table-cell';
|
|
851
|
+
const firstPoint = points[0];
|
|
852
|
+
const lastPoint = points[points.length - 1];
|
|
853
|
+
const suffix = visualization.valueSuffix ?? '';
|
|
854
|
+
const leftHtml = isTable ? '' : `
|
|
855
|
+
<div class="pfx-micro-trend__label-col pfx-micro-trend__label-col--start">
|
|
856
|
+
<span class="pfx-micro-trend__value">${escapeHtml(formatVisualizationMetricValue(firstPoint.value, options, visualization.compactValue === true, suffix))}</span>
|
|
857
|
+
${firstPoint.label ? `<span class="pfx-micro-trend__label">${escapeHtml(firstPoint.label)}</span>` : ''}
|
|
858
|
+
</div>`;
|
|
859
|
+
const rightHtml = isTable ? '' : `
|
|
860
|
+
<div class="pfx-micro-trend__label-col pfx-micro-trend__label-col--end">
|
|
861
|
+
<span class="pfx-micro-trend__value">${escapeHtml(formatVisualizationMetricValue(lastPoint.value, options, visualization.compactValue === true, suffix))}</span>
|
|
862
|
+
${lastPoint.label ? `<span class="pfx-micro-trend__label">${escapeHtml(lastPoint.label)}</span>` : ''}
|
|
863
|
+
</div>`;
|
|
864
|
+
return `
|
|
865
|
+
<span class="pfx-micro-viz-container">
|
|
866
|
+
${leftHtml}
|
|
867
|
+
<span class="pfx-micro-viz pfx-micro-viz__line" data-tone="${escapeHtml(tone)}" role="img" aria-label="${escapeHtml(visualization.ariaLabel ?? visualization.fallbackText)}">
|
|
868
|
+
<svg class="pfx-micro-line__svg" viewBox="0 0 100 30">
|
|
869
|
+
${refLineHtml}
|
|
870
|
+
<path class="pfx-micro-line__path" d="${pathD}" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
|
|
871
|
+
${circlesHtml}
|
|
872
|
+
</svg>
|
|
873
|
+
${scrubLayerHtml}
|
|
874
|
+
</span>
|
|
875
|
+
${rightHtml}
|
|
876
|
+
</span>`;
|
|
877
|
+
}
|
|
878
|
+
function renderAreaVisualizationHtml(visualization, options) {
|
|
879
|
+
const points = visualization.points ?? [];
|
|
880
|
+
const tone = visualization.tone ?? 'info';
|
|
881
|
+
if (points.length < 2) {
|
|
882
|
+
return renderFallbackVisualizationHtml(visualization, tone);
|
|
883
|
+
}
|
|
884
|
+
const width = 100;
|
|
885
|
+
const height = 30;
|
|
886
|
+
const padding = 4;
|
|
887
|
+
const coords = getPointsCoordinates(points, width, height, padding, visualization);
|
|
888
|
+
const lineD = coords.map((c, i) => `${i === 0 ? 'M' : 'L'} ${c.x.toFixed(1)} ${c.y.toFixed(1)}`).join(' ');
|
|
889
|
+
const refLineHtml = renderTrendReferenceLineHtml(points, width, height, padding, visualization, false);
|
|
890
|
+
const firstX = coords[0].x.toFixed(1);
|
|
891
|
+
const lastX = coords[coords.length - 1].x.toFixed(1);
|
|
892
|
+
const areaD = `${lineD} L ${lastX} ${height} L ${firstX} ${height} Z`;
|
|
893
|
+
// Highlight extreme/boundary values
|
|
894
|
+
let minIdx = 0;
|
|
895
|
+
let maxIdx = 0;
|
|
896
|
+
for (let i = 1; i < points.length; i++) {
|
|
897
|
+
if (points[i].value < points[minIdx].value)
|
|
898
|
+
minIdx = i;
|
|
899
|
+
if (points[i].value > points[maxIdx].value)
|
|
900
|
+
maxIdx = i;
|
|
901
|
+
}
|
|
902
|
+
const markers = [
|
|
903
|
+
{ x: coords[0].x, y: coords[0].y, tone: points[0].tone ?? tone },
|
|
904
|
+
{ x: coords[coords.length - 1].x, y: coords[coords.length - 1].y, tone: points[points.length - 1].tone ?? tone }
|
|
905
|
+
];
|
|
906
|
+
if (minIdx !== 0 && minIdx !== coords.length - 1) {
|
|
907
|
+
markers.push({ x: coords[minIdx].x, y: coords[minIdx].y, tone: points[minIdx].tone ?? 'danger' });
|
|
908
|
+
}
|
|
909
|
+
if (maxIdx !== 0 && maxIdx !== coords.length - 1) {
|
|
910
|
+
markers.push({ x: coords[maxIdx].x, y: coords[maxIdx].y, tone: points[maxIdx].tone ?? 'success' });
|
|
911
|
+
}
|
|
912
|
+
const circlesHtml = markers.map(c => `<circle cx="${c.x.toFixed(1)}" cy="${c.y.toFixed(1)}" r="2.5" class="pfx-micro-trend__marker" data-tone="${escapeHtml(c.tone)}" />`).join('');
|
|
913
|
+
const scrubLayerHtml = renderTrendScrubLayerHtml(points, coords, width, height, visualization, options);
|
|
914
|
+
const isTable = visualization.surface === 'table-cell';
|
|
915
|
+
const firstPoint = points[0];
|
|
916
|
+
const lastPoint = points[points.length - 1];
|
|
917
|
+
const suffix = visualization.valueSuffix ?? '';
|
|
918
|
+
const leftHtml = isTable ? '' : `
|
|
919
|
+
<div class="pfx-micro-trend__label-col pfx-micro-trend__label-col--start">
|
|
920
|
+
<span class="pfx-micro-trend__value">${escapeHtml(formatVisualizationMetricValue(firstPoint.value, options, visualization.compactValue === true, suffix))}</span>
|
|
921
|
+
${firstPoint.label ? `<span class="pfx-micro-trend__label">${escapeHtml(firstPoint.label)}</span>` : ''}
|
|
922
|
+
</div>`;
|
|
923
|
+
const rightHtml = isTable ? '' : `
|
|
924
|
+
<div class="pfx-micro-trend__label-col pfx-micro-trend__label-col--end">
|
|
925
|
+
<span class="pfx-micro-trend__value">${escapeHtml(formatVisualizationMetricValue(lastPoint.value, options, visualization.compactValue === true, suffix))}</span>
|
|
926
|
+
${lastPoint.label ? `<span class="pfx-micro-trend__label">${escapeHtml(lastPoint.label)}</span>` : ''}
|
|
927
|
+
</div>`;
|
|
928
|
+
return `
|
|
929
|
+
<span class="pfx-micro-viz-container">
|
|
930
|
+
${leftHtml}
|
|
931
|
+
<span class="pfx-micro-viz pfx-micro-viz__area" data-tone="${escapeHtml(tone)}" role="img" aria-label="${escapeHtml(visualization.ariaLabel ?? visualization.fallbackText)}">
|
|
932
|
+
<svg class="pfx-micro-area__svg" viewBox="0 0 100 30">
|
|
933
|
+
${refLineHtml}
|
|
934
|
+
<path class="pfx-micro-area__fill" d="${areaD}" fill="currentColor" fill-opacity="0.15" />
|
|
935
|
+
<path class="pfx-micro-area__path" d="${lineD}" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
|
|
936
|
+
${circlesHtml}
|
|
937
|
+
</svg>
|
|
938
|
+
${scrubLayerHtml}
|
|
939
|
+
</span>
|
|
940
|
+
${rightHtml}
|
|
941
|
+
</span>`;
|
|
942
|
+
}
|
|
943
|
+
function renderColumnVisualizationHtml(visualization, options) {
|
|
944
|
+
const points = visualization.points ?? [];
|
|
945
|
+
const tone = visualization.tone ?? 'info';
|
|
946
|
+
if (points.length === 0) {
|
|
947
|
+
return renderFallbackVisualizationHtml(visualization, tone);
|
|
948
|
+
}
|
|
949
|
+
const width = 100;
|
|
950
|
+
const height = 30;
|
|
951
|
+
const padding = 4;
|
|
952
|
+
const { minVal, valRange } = resolveTrendBounds(points, visualization, true);
|
|
953
|
+
const refLineHtml = renderTrendReferenceLineHtml(points, width, height, padding, visualization, true);
|
|
954
|
+
const colWidth = Math.max(2, (width - 2 * padding) / points.length - 2);
|
|
955
|
+
const colCoords = [];
|
|
956
|
+
const columnsHtml = points.map((p, i) => {
|
|
957
|
+
const x = padding + i * ((width - 2 * padding) / points.length) + 1;
|
|
958
|
+
const rectHeight = Math.max(2, ((p.value - minVal) / valRange) * (height - 2 * padding));
|
|
959
|
+
const rectY = height - padding - rectHeight;
|
|
960
|
+
colCoords.push({ x: x + colWidth / 2, y: rectY });
|
|
961
|
+
const itemTone = p.tone ??
|
|
962
|
+
(visualization.thresholds?.length
|
|
963
|
+
? resolvePraxisMicroVisualizationTone(p.value, visualization.thresholds)?.tone ?? tone
|
|
964
|
+
: tone);
|
|
965
|
+
return `<rect class="pfx-micro-column__bar" x="${x.toFixed(1)}" y="${rectY.toFixed(1)}" width="${colWidth.toFixed(1)}" height="${rectHeight.toFixed(1)}" rx="1" fill="currentColor" data-tone="${escapeHtml(itemTone)}" />`;
|
|
966
|
+
}).join('');
|
|
967
|
+
const scrubLayerHtml = renderTrendScrubLayerHtml(points, colCoords, width, height, visualization, options);
|
|
968
|
+
const isTable = visualization.surface === 'table-cell';
|
|
969
|
+
const firstPoint = points[0];
|
|
970
|
+
const lastPoint = points[points.length - 1];
|
|
971
|
+
const suffix = visualization.valueSuffix ?? '';
|
|
972
|
+
const leftHtml = isTable ? '' : `
|
|
973
|
+
<div class="pfx-micro-trend__label-col pfx-micro-trend__label-col--start">
|
|
974
|
+
<span class="pfx-micro-trend__value">${escapeHtml(formatVisualizationMetricValue(firstPoint.value, options, visualization.compactValue === true, suffix))}</span>
|
|
975
|
+
${firstPoint.label ? `<span class="pfx-micro-trend__label">${escapeHtml(firstPoint.label)}</span>` : ''}
|
|
976
|
+
</div>`;
|
|
977
|
+
const rightHtml = isTable ? '' : `
|
|
978
|
+
<div class="pfx-micro-trend__label-col pfx-micro-trend__label-col--end">
|
|
979
|
+
<span class="pfx-micro-trend__value">${escapeHtml(formatVisualizationMetricValue(lastPoint.value, options, visualization.compactValue === true, suffix))}</span>
|
|
980
|
+
${lastPoint.label ? `<span class="pfx-micro-trend__label">${escapeHtml(lastPoint.label)}</span>` : ''}
|
|
981
|
+
</div>`;
|
|
982
|
+
return `
|
|
983
|
+
<span class="pfx-micro-viz-container">
|
|
984
|
+
${leftHtml}
|
|
985
|
+
<span class="pfx-micro-viz pfx-micro-viz__column" data-tone="${escapeHtml(tone)}" role="img" aria-label="${escapeHtml(visualization.ariaLabel ?? visualization.fallbackText)}">
|
|
986
|
+
<svg class="pfx-micro-column__svg" viewBox="0 0 100 30">
|
|
987
|
+
${columnsHtml}
|
|
988
|
+
${refLineHtml}
|
|
989
|
+
</svg>
|
|
990
|
+
${scrubLayerHtml}
|
|
991
|
+
</span>
|
|
992
|
+
${rightHtml}
|
|
993
|
+
</span>`;
|
|
994
|
+
}
|
|
995
|
+
function renderProcessFlowVisualizationHtml(visualization, options) {
|
|
996
|
+
const items = visualization.items ?? [];
|
|
997
|
+
if (items.length === 0) {
|
|
998
|
+
return renderFallbackVisualizationHtml(visualization, visualization.tone ?? 'neutral');
|
|
999
|
+
}
|
|
1000
|
+
const isTable = visualization.surface === 'table-cell';
|
|
1001
|
+
const stepLabels = items.map((item, index) => item.label ?? item.id ?? `${index + 1}`);
|
|
1002
|
+
const aria = visualization.ariaLabel ?? `${visualization.fallbackText}: ${stepLabels.join(' > ')}`;
|
|
1003
|
+
const labelStyleAttr = [];
|
|
1004
|
+
if (visualization.stepLabelWidth !== undefined) {
|
|
1005
|
+
const widthVal = typeof visualization.stepLabelWidth === 'number'
|
|
1006
|
+
? `${visualization.stepLabelWidth}px`
|
|
1007
|
+
: String(visualization.stepLabelWidth);
|
|
1008
|
+
labelStyleAttr.push(`inline-size: ${escapeHtml(widthVal)}; max-width: ${escapeHtml(widthVal)};`);
|
|
1009
|
+
}
|
|
1010
|
+
if (visualization.stepLabelLineClamp !== undefined) {
|
|
1011
|
+
labelStyleAttr.push(`-webkit-line-clamp: ${visualization.stepLabelLineClamp};`);
|
|
1012
|
+
}
|
|
1013
|
+
const labelInlineStyle = labelStyleAttr.length ? ` style="${labelStyleAttr.join(' ')}"` : '';
|
|
1014
|
+
const stepsHtml = items.map((item, index) => {
|
|
1015
|
+
const itemTone = item.tone ?? 'neutral';
|
|
1016
|
+
const itemState = item.state ?? '';
|
|
1017
|
+
const isLast = index === items.length - 1;
|
|
1018
|
+
const itemLabel = stepLabels[index];
|
|
1019
|
+
const normalizedIcon = item.icon ? item.icon.replace(/-/g, '_') : undefined;
|
|
1020
|
+
const label = !isTable && item.label ? `<span class="pfx-micro-step__label"${labelInlineStyle}>${escapeHtml(item.label)}</span>` : '';
|
|
1021
|
+
const isActiveStep = itemState === 'active' ||
|
|
1022
|
+
itemState === 'current' ||
|
|
1023
|
+
itemState === 'in_progress' ||
|
|
1024
|
+
normalizedIcon === 'sync' ||
|
|
1025
|
+
normalizedIcon === 'pending' ||
|
|
1026
|
+
normalizedIcon === 'pending_actions' ||
|
|
1027
|
+
normalizedIcon === 'schedule' ||
|
|
1028
|
+
(!itemState && itemTone === 'warning');
|
|
1029
|
+
const stepReadout = `${index + 1}/${items.length} · ${itemLabel}`;
|
|
1030
|
+
const connector = !isLast ? `<span class="pfx-micro-step__connector" data-tone="${escapeHtml(itemTone)}"></span>` : '';
|
|
1031
|
+
const stepCircle = `
|
|
1032
|
+
<span class="pfx-micro-step__node" data-tone="${escapeHtml(itemTone)}"${isActiveStep ? ' data-active="true"' : ''} aria-hidden="true">
|
|
1033
|
+
${normalizedIcon ? `<span class="material-icons pfx-micro-step__icon" aria-hidden="true">${escapeHtml(normalizedIcon)}</span>` : `${index + 1}`}
|
|
1034
|
+
</span>`;
|
|
1035
|
+
return `
|
|
1036
|
+
<div class="pfx-micro-step" data-state="${escapeHtml(itemState)}" data-tone="${escapeHtml(itemTone)}">
|
|
1037
|
+
<div class="pfx-micro-step__node-wrapper" data-micro-readout="${escapeHtml(stepReadout)}" title="${escapeHtml(itemLabel)}">
|
|
1038
|
+
${stepCircle}
|
|
1039
|
+
${label}
|
|
1040
|
+
</div>
|
|
1041
|
+
${connector}
|
|
1042
|
+
</div>`;
|
|
1043
|
+
}).join('');
|
|
1044
|
+
return `
|
|
1045
|
+
<span class="pfx-micro-viz pfx-micro-viz__process" role="img" aria-label="${escapeHtml(aria)}">
|
|
1046
|
+
${stepsHtml}
|
|
1047
|
+
</span>`;
|
|
1048
|
+
}
|
|
1049
|
+
function renderFallbackVisualizationHtml(visualization, tone) {
|
|
1050
|
+
return `
|
|
1051
|
+
<span
|
|
1052
|
+
class="pfx-micro-viz pfx-micro-viz__fallback"
|
|
1053
|
+
data-tone="${escapeHtml(tone)}"
|
|
1054
|
+
role="img"
|
|
1055
|
+
aria-label="${escapeHtml(visualization.ariaLabel ?? visualization.fallbackText)}"
|
|
1056
|
+
>${escapeHtml(visualization.fallbackText)}</span>`;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
const PRAXIS_QUICK_VIEW_PRESENTER = new InjectionToken('PRAXIS_QUICK_VIEW_PRESENTER');
|
|
1060
|
+
const PRAXIS_QUICK_VIEW_BODY_RENDERER = new InjectionToken('PRAXIS_QUICK_VIEW_BODY_RENDERER');
|
|
1061
|
+
const FORBIDDEN_BINDING_KEYS = new Set([
|
|
1062
|
+
'element',
|
|
1063
|
+
'nativeElement',
|
|
1064
|
+
'anchor',
|
|
1065
|
+
'hostElement',
|
|
1066
|
+
'focusOrigin',
|
|
1067
|
+
'getViewportRect',
|
|
1068
|
+
'nodes',
|
|
1069
|
+
'document',
|
|
1070
|
+
'action',
|
|
1071
|
+
'actions',
|
|
1072
|
+
'ctaAction',
|
|
1073
|
+
'overrideAction',
|
|
1074
|
+
'route',
|
|
1075
|
+
'href',
|
|
1076
|
+
'payload',
|
|
1077
|
+
'hostCapabilities',
|
|
1078
|
+
]);
|
|
1079
|
+
const RESOURCE_KEY_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,199}$/;
|
|
1080
|
+
/**
|
|
1081
|
+
* Detecta se um valor candidato à serialização contém referências efêmeras de DOM ou funções.
|
|
1082
|
+
*/
|
|
1083
|
+
function containsEphemeralQuickViewRuntimeValue(value, visited = new Set()) {
|
|
1084
|
+
if (!value || typeof value !== 'object') {
|
|
1085
|
+
return typeof value === 'function';
|
|
1086
|
+
}
|
|
1087
|
+
if (visited.has(value)) {
|
|
1088
|
+
return false;
|
|
1089
|
+
}
|
|
1090
|
+
visited.add(value);
|
|
1091
|
+
if (typeof Element !== 'undefined' && value instanceof Element) {
|
|
1092
|
+
return true;
|
|
1093
|
+
}
|
|
1094
|
+
if (typeof value.nodeType === 'number' &&
|
|
1095
|
+
typeof value.nodeName === 'string') {
|
|
1096
|
+
return true;
|
|
1097
|
+
}
|
|
1098
|
+
if (Array.isArray(value)) {
|
|
1099
|
+
return value.some((item) => containsEphemeralQuickViewRuntimeValue(item, visited));
|
|
1100
|
+
}
|
|
1101
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
1102
|
+
if (key === 'element' ||
|
|
1103
|
+
key === 'nativeElement' ||
|
|
1104
|
+
key === 'hostElement' ||
|
|
1105
|
+
key === 'focusOrigin' ||
|
|
1106
|
+
typeof entry === 'function') {
|
|
1107
|
+
return true;
|
|
1108
|
+
}
|
|
1109
|
+
if (containsEphemeralQuickViewRuntimeValue(entry, visited)) {
|
|
1110
|
+
return true;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
return false;
|
|
1114
|
+
}
|
|
1115
|
+
function normalizeResourceRecordOpenReference(candidate) {
|
|
1116
|
+
if (!candidate || typeof candidate !== 'object' || Array.isArray(candidate)) {
|
|
1117
|
+
return null;
|
|
1118
|
+
}
|
|
1119
|
+
const record = candidate;
|
|
1120
|
+
const target = record['target'] && typeof record['target'] === 'object' && !Array.isArray(record['target'])
|
|
1121
|
+
? record['target']
|
|
1122
|
+
: null;
|
|
1123
|
+
const sourceIdentityField = typeof record['sourceIdentityField'] === 'string'
|
|
1124
|
+
? record['sourceIdentityField'].trim()
|
|
1125
|
+
: '';
|
|
1126
|
+
const resourceKey = typeof target?.['resourceKey'] === 'string'
|
|
1127
|
+
? target['resourceKey'].trim()
|
|
1128
|
+
: '';
|
|
1129
|
+
const surfaceId = typeof target?.['surfaceId'] === 'string'
|
|
1130
|
+
? target['surfaceId'].trim()
|
|
1131
|
+
: '';
|
|
1132
|
+
if (!sourceIdentityField ||
|
|
1133
|
+
sourceIdentityField.length > 200 ||
|
|
1134
|
+
!RESOURCE_KEY_PATTERN.test(resourceKey) ||
|
|
1135
|
+
!surfaceId ||
|
|
1136
|
+
surfaceId.length > 200) {
|
|
1137
|
+
return null;
|
|
1138
|
+
}
|
|
1139
|
+
return {
|
|
1140
|
+
sourceIdentityField,
|
|
1141
|
+
target: {
|
|
1142
|
+
resourceKey,
|
|
1143
|
+
surfaceId,
|
|
1144
|
+
},
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Valida e normaliza um `ResourceQuickViewBinding` de forma fail-closed.
|
|
1149
|
+
*/
|
|
1150
|
+
function validateResourceQuickViewBinding(value) {
|
|
1151
|
+
const diagnostics = [];
|
|
1152
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
1153
|
+
return {
|
|
1154
|
+
valid: false,
|
|
1155
|
+
binding: null,
|
|
1156
|
+
diagnostics: ['Quick View binding must be a non-null object.'],
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
const record = value;
|
|
1160
|
+
for (const forbiddenKey of FORBIDDEN_BINDING_KEYS) {
|
|
1161
|
+
if (forbiddenKey in record && record[forbiddenKey] !== undefined) {
|
|
1162
|
+
diagnostics.push(`Quick View binding cannot contain runtime, inline document or action override property "${forbiddenKey}".`);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
if (containsEphemeralQuickViewRuntimeValue(record)) {
|
|
1166
|
+
diagnostics.push('Quick View binding cannot contain DOM elements or functions.');
|
|
1167
|
+
}
|
|
1168
|
+
const rawRecordOpen = record['recordOpen'];
|
|
1169
|
+
if (!rawRecordOpen || typeof rawRecordOpen !== 'object' || Array.isArray(rawRecordOpen)) {
|
|
1170
|
+
diagnostics.push('Quick View binding requires a valid "recordOpen" object.');
|
|
1171
|
+
}
|
|
1172
|
+
else {
|
|
1173
|
+
const recordOpenObj = rawRecordOpen;
|
|
1174
|
+
for (const forbiddenKey of FORBIDDEN_BINDING_KEYS) {
|
|
1175
|
+
if (forbiddenKey in recordOpenObj && recordOpenObj[forbiddenKey] !== undefined) {
|
|
1176
|
+
diagnostics.push(`Quick View recordOpen cannot contain override property "${forbiddenKey}".`);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
if ('presentation' in recordOpenObj && recordOpenObj['presentation'] === 'popover') {
|
|
1180
|
+
diagnostics.push('Quick View recordOpen cannot declare "popover" presentation.');
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
let detailPresentation;
|
|
1184
|
+
const rawDetailPresentation = record['detailPresentation'];
|
|
1185
|
+
if (rawDetailPresentation !== undefined && rawDetailPresentation !== null) {
|
|
1186
|
+
if (rawDetailPresentation === 'drawer' || rawDetailPresentation === 'modal') {
|
|
1187
|
+
detailPresentation = rawDetailPresentation;
|
|
1188
|
+
}
|
|
1189
|
+
else {
|
|
1190
|
+
diagnostics.push(`Quick View detailPresentation must be "drawer" or "modal"; received "${String(rawDetailPresentation)}".`);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
const normalizedRecordOpen = normalizeResourceRecordOpenReference(rawRecordOpen);
|
|
1194
|
+
if (!normalizedRecordOpen) {
|
|
1195
|
+
diagnostics.push('Quick View recordOpen must declare non-empty sourceIdentityField and target.{resourceKey, surfaceId}.');
|
|
1196
|
+
}
|
|
1197
|
+
let normalizedContentRef;
|
|
1198
|
+
const rawContentRef = record['contentRef'];
|
|
1199
|
+
if (rawContentRef !== undefined && rawContentRef !== null) {
|
|
1200
|
+
if (typeof rawContentRef !== 'object' || Array.isArray(rawContentRef)) {
|
|
1201
|
+
diagnostics.push('Quick View contentRef must be an object reference to a rich-block preset.');
|
|
1202
|
+
}
|
|
1203
|
+
else {
|
|
1204
|
+
const refObj = rawContentRef;
|
|
1205
|
+
const kind = typeof refObj['kind'] === 'string' ? refObj['kind'].trim() : '';
|
|
1206
|
+
const namespace = typeof refObj['namespace'] === 'string' ? refObj['namespace'].trim() : '';
|
|
1207
|
+
const presetId = typeof refObj['presetId'] === 'string' ? refObj['presetId'].trim() : '';
|
|
1208
|
+
const version = typeof refObj['version'] === 'string' ? refObj['version'].trim() : '';
|
|
1209
|
+
if (kind !== 'rich-block') {
|
|
1210
|
+
diagnostics.push(`Quick View contentRef.kind must be "rich-block"; received "${kind || 'empty'}".`);
|
|
1211
|
+
}
|
|
1212
|
+
if (!namespace) {
|
|
1213
|
+
diagnostics.push('Quick View contentRef.namespace must be a non-empty string.');
|
|
1214
|
+
}
|
|
1215
|
+
if (!presetId) {
|
|
1216
|
+
diagnostics.push('Quick View contentRef.presetId must be a non-empty string.');
|
|
1217
|
+
}
|
|
1218
|
+
if (!version) {
|
|
1219
|
+
diagnostics.push('Quick View contentRef.version must be explicitly declared.');
|
|
1220
|
+
}
|
|
1221
|
+
if ('nodes' in refObj || 'inputs' in refObj || 'action' in refObj) {
|
|
1222
|
+
diagnostics.push('Quick View contentRef cannot embed inline nodes, inputs or actions.');
|
|
1223
|
+
}
|
|
1224
|
+
if (kind === 'rich-block' &&
|
|
1225
|
+
namespace &&
|
|
1226
|
+
presetId &&
|
|
1227
|
+
version &&
|
|
1228
|
+
!('nodes' in refObj || 'inputs' in refObj || 'action' in refObj)) {
|
|
1229
|
+
normalizedContentRef = {
|
|
1230
|
+
kind: 'rich-block',
|
|
1231
|
+
namespace,
|
|
1232
|
+
presetId,
|
|
1233
|
+
version,
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
if (diagnostics.length > 0 || !normalizedRecordOpen) {
|
|
1239
|
+
return {
|
|
1240
|
+
valid: false,
|
|
1241
|
+
binding: null,
|
|
1242
|
+
diagnostics,
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1245
|
+
return {
|
|
1246
|
+
valid: true,
|
|
1247
|
+
binding: {
|
|
1248
|
+
recordOpen: normalizedRecordOpen,
|
|
1249
|
+
...(normalizedContentRef ? { contentRef: normalizedContentRef } : {}),
|
|
1250
|
+
...(detailPresentation ? { detailPresentation } : {}),
|
|
1251
|
+
},
|
|
1252
|
+
diagnostics: [],
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
function normalizeResourceQuickViewBinding(value) {
|
|
1256
|
+
return validateResourceQuickViewBinding(value).binding;
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* Verifica se a âncora efêmera de runtime permanece conectada e visível na viewport.
|
|
1260
|
+
*/
|
|
1261
|
+
function isResourceQuickViewAnchorValid(anchor) {
|
|
1262
|
+
if (!anchor || typeof anchor !== 'object') {
|
|
1263
|
+
return false;
|
|
1264
|
+
}
|
|
1265
|
+
if (typeof anchor.isValid === 'function' && !anchor.isValid()) {
|
|
1266
|
+
return false;
|
|
1267
|
+
}
|
|
1268
|
+
const viewportWidth = typeof window !== 'undefined' && Number.isFinite(window.innerWidth) && window.innerWidth > 0
|
|
1269
|
+
? window.innerWidth
|
|
1270
|
+
: 1920;
|
|
1271
|
+
const viewportHeight = typeof window !== 'undefined' && Number.isFinite(window.innerHeight) && window.innerHeight > 0
|
|
1272
|
+
? window.innerHeight
|
|
1273
|
+
: 1080;
|
|
1274
|
+
if (anchor.kind === 'element') {
|
|
1275
|
+
const el = anchor.element;
|
|
1276
|
+
if (!el || typeof el.getBoundingClientRect !== 'function' || el.isConnected === false) {
|
|
1277
|
+
return false;
|
|
1278
|
+
}
|
|
1279
|
+
const rect = el.getBoundingClientRect();
|
|
1280
|
+
if (!Number.isFinite(rect.left) || !Number.isFinite(rect.top)) {
|
|
1281
|
+
return false;
|
|
1282
|
+
}
|
|
1283
|
+
if (rect.width === 0 && rect.height === 0) {
|
|
1284
|
+
return false;
|
|
1285
|
+
}
|
|
1286
|
+
return (rect.bottom >= 0 &&
|
|
1287
|
+
rect.right >= 0 &&
|
|
1288
|
+
rect.top <= viewportHeight &&
|
|
1289
|
+
rect.left <= viewportWidth);
|
|
1290
|
+
}
|
|
1291
|
+
if (anchor.kind === 'virtual-rect') {
|
|
1292
|
+
if (!anchor.anchorKey || !anchor.anchorKey.trim()) {
|
|
1293
|
+
return false;
|
|
1294
|
+
}
|
|
1295
|
+
if (anchor.hostElement && anchor.hostElement.isConnected === false) {
|
|
1296
|
+
return false;
|
|
1297
|
+
}
|
|
1298
|
+
if (typeof anchor.getViewportRect !== 'function') {
|
|
1299
|
+
return false;
|
|
1300
|
+
}
|
|
1301
|
+
const rect = anchor.getViewportRect();
|
|
1302
|
+
if (!rect ||
|
|
1303
|
+
!Number.isFinite(rect.x) ||
|
|
1304
|
+
!Number.isFinite(rect.y) ||
|
|
1305
|
+
!Number.isFinite(rect.width) ||
|
|
1306
|
+
!Number.isFinite(rect.height) ||
|
|
1307
|
+
rect.width < 0 ||
|
|
1308
|
+
rect.height < 0) {
|
|
1309
|
+
return false;
|
|
1310
|
+
}
|
|
1311
|
+
const right = rect.right ?? rect.x + rect.width;
|
|
1312
|
+
const bottom = rect.bottom ?? rect.y + rect.height;
|
|
1313
|
+
const left = rect.left ?? rect.x;
|
|
1314
|
+
const top = rect.top ?? rect.y;
|
|
1315
|
+
return (bottom >= 0 &&
|
|
1316
|
+
right >= 0 &&
|
|
1317
|
+
top <= viewportHeight &&
|
|
1318
|
+
left <= viewportWidth);
|
|
1319
|
+
}
|
|
1320
|
+
return false;
|
|
1321
|
+
}
|
|
1322
|
+
function resolveQuickViewAnchorKey(anchor) {
|
|
1323
|
+
if (anchor.kind === 'virtual-rect') {
|
|
1324
|
+
return anchor.anchorKey.trim();
|
|
1325
|
+
}
|
|
1326
|
+
const explicit = anchor.anchorKey?.trim();
|
|
1327
|
+
if (explicit) {
|
|
1328
|
+
return explicit;
|
|
1329
|
+
}
|
|
1330
|
+
const focusKey = anchor.element?.getAttribute?.('data-praxis-focus-key')?.trim();
|
|
1331
|
+
if (focusKey) {
|
|
1332
|
+
return focusKey;
|
|
1333
|
+
}
|
|
1334
|
+
const id = anchor.element?.id?.trim();
|
|
1335
|
+
if (id) {
|
|
1336
|
+
return `element:${id}`;
|
|
1337
|
+
}
|
|
1338
|
+
return 'element:anonymous';
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
const TONES = new Set([
|
|
1342
|
+
'neutral',
|
|
1343
|
+
'info',
|
|
1344
|
+
'success',
|
|
1345
|
+
'warning',
|
|
1346
|
+
'danger',
|
|
1347
|
+
]);
|
|
1348
|
+
const APPEARANCES = new Set([
|
|
1349
|
+
'plain',
|
|
1350
|
+
'soft',
|
|
1351
|
+
'outlined',
|
|
1352
|
+
'filled',
|
|
1353
|
+
]);
|
|
1354
|
+
const PRESENTERS = new Set([
|
|
1355
|
+
'text',
|
|
1356
|
+
'badge',
|
|
1357
|
+
'chip',
|
|
1358
|
+
'status',
|
|
1359
|
+
'iconValue',
|
|
1360
|
+
'progress',
|
|
1361
|
+
'rating',
|
|
1362
|
+
'microVisualization',
|
|
1363
|
+
]);
|
|
1364
|
+
/**
|
|
1365
|
+
* Resolves readonly field presentation from a base semantic config plus ordered
|
|
1366
|
+
* Json Logic rules. Later matching rules override earlier presentation values.
|
|
1367
|
+
*/
|
|
1368
|
+
function resolveFieldPresentation(base, rules, context = {}, options = {}) {
|
|
1369
|
+
let resolved = normalizeFieldPresentation(base);
|
|
1370
|
+
let matchedRule = false;
|
|
1371
|
+
if (!Array.isArray(rules) || !options.jsonLogic) {
|
|
1372
|
+
return resolved;
|
|
1373
|
+
}
|
|
1374
|
+
for (const rule of rules) {
|
|
1375
|
+
if (!rule?.when || !matchesPresentationRule(rule, context, options.jsonLogic)) {
|
|
1376
|
+
continue;
|
|
1377
|
+
}
|
|
1378
|
+
const effect = normalizeFieldPresentation(rule.set ?? rule.effect);
|
|
1379
|
+
resolved = {
|
|
1380
|
+
...resolved,
|
|
1381
|
+
...effect,
|
|
1382
|
+
};
|
|
1383
|
+
matchedRule = true;
|
|
1384
|
+
}
|
|
1385
|
+
return matchedRule ? { ...resolved, matchedRule } : resolved;
|
|
1386
|
+
}
|
|
1387
|
+
function normalizeFieldPresentation(value) {
|
|
1388
|
+
if (!value || typeof value !== 'object') {
|
|
1389
|
+
return {};
|
|
1390
|
+
}
|
|
1391
|
+
const presenter = normalizePresenter(value.presenter ?? value.variant);
|
|
1392
|
+
const tone = normalizeTone(value.tone);
|
|
1393
|
+
const appearance = normalizeAppearance(value.appearance);
|
|
1394
|
+
const icon = normalizeText(value.icon);
|
|
1395
|
+
const label = normalizeText(value.label);
|
|
1396
|
+
const badge = normalizeText(value.badge);
|
|
1397
|
+
const tooltip = normalizeText(value.tooltip);
|
|
1398
|
+
const prefix = normalizeText(value.prefix);
|
|
1399
|
+
const suffix = normalizeText(value.suffix);
|
|
1400
|
+
const iconTrue = normalizeText(value.iconTrue);
|
|
1401
|
+
const iconFalse = normalizeText(value.iconFalse);
|
|
1402
|
+
const toneTrue = normalizeTone(value.toneTrue);
|
|
1403
|
+
const toneFalse = normalizeTone(value.toneFalse);
|
|
1404
|
+
const labelTrue = normalizeText(value.labelTrue);
|
|
1405
|
+
const labelFalse = normalizeText(value.labelFalse);
|
|
1406
|
+
const visualization = normalizePraxisPresentationVisualization(value.visualization);
|
|
1407
|
+
return {
|
|
1408
|
+
...(presenter ? { presenter } : {}),
|
|
1409
|
+
...(tone ? { tone } : {}),
|
|
1410
|
+
...(appearance ? { appearance } : {}),
|
|
1411
|
+
...(icon ? { icon } : {}),
|
|
1412
|
+
...(label ? { label } : {}),
|
|
1413
|
+
...(badge ? { badge } : {}),
|
|
1414
|
+
...(tooltip ? { tooltip } : {}),
|
|
1415
|
+
...(prefix ? { prefix } : {}),
|
|
1416
|
+
...(suffix ? { suffix } : {}),
|
|
1417
|
+
...(iconTrue ? { iconTrue } : {}),
|
|
1418
|
+
...(iconFalse ? { iconFalse } : {}),
|
|
1419
|
+
...(toneTrue ? { toneTrue } : {}),
|
|
1420
|
+
...(toneFalse ? { toneFalse } : {}),
|
|
1421
|
+
...(labelTrue ? { labelTrue } : {}),
|
|
1422
|
+
...(labelFalse ? { labelFalse } : {}),
|
|
1423
|
+
...(value.valuePresentation && typeof value.valuePresentation === 'object'
|
|
1424
|
+
? { valuePresentation: value.valuePresentation }
|
|
1425
|
+
: {}),
|
|
1426
|
+
...(visualization ? { visualization } : {}),
|
|
1427
|
+
...(value.interactions && typeof value.interactions === 'object'
|
|
1428
|
+
? { interactions: normalizeInteractions(value.interactions) }
|
|
1429
|
+
: {}),
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
function matchesPresentationRule(rule, context, jsonLogic) {
|
|
1433
|
+
try {
|
|
1434
|
+
const result = jsonLogic.evaluate(rule.when, context);
|
|
1435
|
+
return typeof jsonLogic.truthy === 'function'
|
|
1436
|
+
? jsonLogic.truthy(result)
|
|
1437
|
+
: Boolean(result);
|
|
1438
|
+
}
|
|
1439
|
+
catch {
|
|
1440
|
+
return false;
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
function normalizePresenter(value) {
|
|
1444
|
+
return normalizeEnum(value, PRESENTERS);
|
|
1445
|
+
}
|
|
1446
|
+
function normalizeTone(value) {
|
|
1447
|
+
return normalizeEnum(value, TONES);
|
|
1448
|
+
}
|
|
1449
|
+
function normalizeAppearance(value) {
|
|
1450
|
+
return normalizeEnum(value, APPEARANCES);
|
|
1451
|
+
}
|
|
1452
|
+
function normalizeEnum(value, allowed) {
|
|
1453
|
+
if (typeof value !== 'string') {
|
|
1454
|
+
return undefined;
|
|
1455
|
+
}
|
|
1456
|
+
const normalized = value.trim();
|
|
1457
|
+
return allowed.has(normalized) ? normalized : undefined;
|
|
1458
|
+
}
|
|
1459
|
+
function normalizeText(value) {
|
|
1460
|
+
if (typeof value !== 'string') {
|
|
1461
|
+
return undefined;
|
|
1462
|
+
}
|
|
1463
|
+
const trimmed = value.trim();
|
|
1464
|
+
return trimmed.length ? trimmed : undefined;
|
|
1465
|
+
}
|
|
1466
|
+
function normalizeInteractions(value) {
|
|
1467
|
+
const quickView = normalizeResourceQuickViewBinding(value.quickView);
|
|
1468
|
+
return {
|
|
1469
|
+
...(value.copy === true ? { copy: true } : {}),
|
|
1470
|
+
...(value.details === true ? { details: true } : {}),
|
|
1471
|
+
...(value.expand === true ? { expand: true } : {}),
|
|
1472
|
+
...(value.link === true ? { link: true } : {}),
|
|
1473
|
+
...(quickView ? { quickView } : {}),
|
|
1474
|
+
};
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
const VALUE_PRESENTATION_TYPES = new Set([
|
|
1478
|
+
'string',
|
|
1479
|
+
'number',
|
|
1480
|
+
'currency',
|
|
1481
|
+
'percentage',
|
|
1482
|
+
'date',
|
|
1483
|
+
'datetime',
|
|
1484
|
+
'time',
|
|
1485
|
+
'boolean',
|
|
1486
|
+
]);
|
|
1487
|
+
const VALUE_PRESENTATION_STYLES = new Set([
|
|
1488
|
+
'default',
|
|
1489
|
+
'short',
|
|
1490
|
+
'medium',
|
|
1491
|
+
'long',
|
|
1492
|
+
'full',
|
|
1493
|
+
'compact',
|
|
1494
|
+
]);
|
|
1495
|
+
const OPTION_SOURCE_TYPES = new Set([
|
|
1496
|
+
'RESOURCE_ENTITY',
|
|
1497
|
+
'DISTINCT_DIMENSION',
|
|
1498
|
+
'CATEGORICAL_BUCKET',
|
|
1499
|
+
'LIGHT_LOOKUP',
|
|
1500
|
+
'STATIC_CANONICAL',
|
|
1501
|
+
]);
|
|
1502
|
+
const OPTION_SOURCE_SEARCH_MODES = new Set([
|
|
1503
|
+
'none',
|
|
1504
|
+
'starts-with',
|
|
1505
|
+
'contains',
|
|
1506
|
+
'exact',
|
|
1507
|
+
]);
|
|
1508
|
+
const OPTION_SOURCE_SELECTED_RELOAD_POLICIES = new Set([
|
|
1509
|
+
'required',
|
|
1510
|
+
'supported',
|
|
1511
|
+
'unsupported-with-waiver',
|
|
1512
|
+
'not-applicable',
|
|
1513
|
+
]);
|
|
1514
|
+
const OPTION_SOURCE_INVALID_SORT_POLICIES = new Set([
|
|
1515
|
+
'reject',
|
|
1516
|
+
'ignore',
|
|
1517
|
+
'unsupported',
|
|
1518
|
+
]);
|
|
1519
|
+
const LOOKUP_SEARCH_STRATEGY_KINDS = new Set([
|
|
1520
|
+
'business-code',
|
|
1521
|
+
'descriptive-text',
|
|
1522
|
+
'normalized-document',
|
|
1523
|
+
]);
|
|
1524
|
+
const LOOKUP_OPEN_DETAIL_MODES = new Set([
|
|
1525
|
+
'samePage',
|
|
1526
|
+
'newTab',
|
|
1527
|
+
'drawer',
|
|
1528
|
+
'modal',
|
|
1529
|
+
'route',
|
|
1530
|
+
]);
|
|
1531
|
+
const LOOKUP_FILTER_FIELD_TYPES = new Set([
|
|
1532
|
+
'text',
|
|
1533
|
+
'enum',
|
|
1534
|
+
'date',
|
|
1535
|
+
'number',
|
|
1536
|
+
'reference',
|
|
1537
|
+
]);
|
|
1538
|
+
const LOOKUP_FILTER_OPERATORS = new Set([
|
|
1539
|
+
'contains',
|
|
1540
|
+
'startsWith',
|
|
1541
|
+
'equals',
|
|
1542
|
+
'in',
|
|
1543
|
+
'before',
|
|
1544
|
+
'after',
|
|
1545
|
+
'between',
|
|
1546
|
+
'gt',
|
|
1547
|
+
'gte',
|
|
1548
|
+
'lt',
|
|
1549
|
+
'lte',
|
|
1550
|
+
]);
|
|
1551
|
+
/**
|
|
1552
|
+
* SchemaNormalizationKernel (internal)
|
|
1553
|
+
* -----------------------
|
|
1554
|
+
* Cálculo compartilhado pelo serviço Angular, sem DI ou export público, que converte
|
|
1555
|
+
* um esquema bruto (OpenAPI + x-ui) em uma
|
|
1556
|
+
* lista tipada de FieldDefinition consumida pelo restante do sistema
|
|
1557
|
+
* (mapeadores de metadata, criador de FormGroup, carregador de campos dinâmicos, etc.).
|
|
1558
|
+
*
|
|
1559
|
+
* Entrada esperada
|
|
1560
|
+
* - Objeto JSON no formato OpenAPI/JSON Schema contendo:
|
|
1561
|
+
* - properties: { [name: string]: { type, title, description, ... , 'x-ui': { ... } } }
|
|
1562
|
+
* - Em cada propriedade, o objeto 'x-ui' define aspectos de UI/validação.
|
|
1563
|
+
*
|
|
1564
|
+
* Saída (FieldDefinition[])
|
|
1565
|
+
* - Tipagem forte de campos com funções reais (nunca strings) para regras condicionais e validadores customizados.
|
|
1566
|
+
* - Todas as propriedades de validação e comportamento consolidadas no mesmo objeto do campo.
|
|
1567
|
+
*
|
|
1568
|
+
* Segurança e observações
|
|
1569
|
+
* - Este serviço aceita funções em formato string dentro do x-ui (ex.: uniqueValidator, conditionalValidation),
|
|
1570
|
+
* e as converte via new Function. Isso exige backend confiável e controlado.
|
|
1571
|
+
* Em ambientes não confiáveis, evite funções como string ou implemente um sandbox/whitelist.
|
|
1572
|
+
* - Valores booleanos/numéricos são normalizados para tipos nativos.
|
|
1573
|
+
* - Arrays de opções são convertidos para pares { key, value } previsíveis.
|
|
1574
|
+
*
|
|
1575
|
+
* Exemplo mínimo de entrada
|
|
1576
|
+
* const schema = {
|
|
1577
|
+
* properties: {
|
|
1578
|
+
* email: {
|
|
1579
|
+
* type: 'string',
|
|
1580
|
+
* title: 'E-mail',
|
|
1581
|
+
* 'x-ui': { controlType: 'input', type: 'string', required: true, email: true }
|
|
1582
|
+
* }
|
|
1583
|
+
* }
|
|
1584
|
+
* };
|
|
1585
|
+
* const fields = normalizer.normalizeSchema(schema);
|
|
1586
|
+
* // fields: [{ name: 'email', label: 'E-mail', type: 'string', controlType: 'input', required: true, email: true }]
|
|
1587
|
+
*/
|
|
1588
|
+
class SchemaNormalizationKernel {
|
|
1589
|
+
clonePlain(value) {
|
|
1590
|
+
if (value === undefined || value === null) {
|
|
1591
|
+
return value;
|
|
1592
|
+
}
|
|
1593
|
+
if (typeof structuredClone === 'function') {
|
|
1594
|
+
try {
|
|
1595
|
+
return structuredClone(value);
|
|
1596
|
+
}
|
|
1597
|
+
catch {
|
|
1598
|
+
// Fall through to JSON clone for plain schema metadata.
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
return JSON.parse(JSON.stringify(value));
|
|
1602
|
+
}
|
|
1603
|
+
resolveSchemaRef(ref, rootSchema) {
|
|
1604
|
+
if (typeof ref !== 'string' || !ref.startsWith('#/')) {
|
|
1605
|
+
return undefined;
|
|
1606
|
+
}
|
|
1607
|
+
const segments = ref
|
|
1608
|
+
.slice(2)
|
|
1609
|
+
.split('/')
|
|
1610
|
+
.map((segment) => segment.replace(/~1/g, '/').replace(/~0/g, '~'));
|
|
1611
|
+
let cursor = rootSchema;
|
|
1612
|
+
for (const segment of segments) {
|
|
1613
|
+
if (!cursor || typeof cursor !== 'object') {
|
|
1614
|
+
return undefined;
|
|
1615
|
+
}
|
|
1616
|
+
cursor = cursor[segment];
|
|
1617
|
+
}
|
|
1618
|
+
return cursor && typeof cursor === 'object' ? cursor : undefined;
|
|
1619
|
+
}
|
|
1620
|
+
normalizeObjectSchema(schema, rootSchema) {
|
|
1621
|
+
if (!schema || typeof schema !== 'object' || Array.isArray(schema)) {
|
|
1622
|
+
return [];
|
|
1623
|
+
}
|
|
1624
|
+
return this.normalizeSchemaWithRoot(schema, rootSchema);
|
|
1625
|
+
}
|
|
1626
|
+
normalizeArrayConfig(ui, prop, rootSchema) {
|
|
1627
|
+
const source = ui.array && typeof ui.array === 'object' && !Array.isArray(ui.array)
|
|
1628
|
+
? this.clonePlain(ui.array)
|
|
1629
|
+
: {};
|
|
1630
|
+
const arrayConfig = source;
|
|
1631
|
+
arrayConfig.itemType = 'object';
|
|
1632
|
+
arrayConfig.mode = 'cards';
|
|
1633
|
+
arrayConfig.deleteMode = 'removeFromPayload';
|
|
1634
|
+
delete arrayConfig['sortable'];
|
|
1635
|
+
delete arrayConfig['itemStateTracking'];
|
|
1636
|
+
if (arrayConfig.operations) {
|
|
1637
|
+
delete arrayConfig.operations['duplicate'];
|
|
1638
|
+
delete arrayConfig.operations['reorder'];
|
|
1639
|
+
}
|
|
1640
|
+
if (prop?.minItems !== undefined && arrayConfig.minItems === undefined) {
|
|
1641
|
+
arrayConfig.minItems = Number(prop.minItems);
|
|
1642
|
+
}
|
|
1643
|
+
if (prop?.maxItems !== undefined && arrayConfig.maxItems === undefined) {
|
|
1644
|
+
arrayConfig.maxItems = Number(prop.maxItems);
|
|
1645
|
+
}
|
|
1646
|
+
const itemSchemaRef = arrayConfig.itemSchemaRef ?? prop?.items?.$ref;
|
|
1647
|
+
if (itemSchemaRef !== undefined) {
|
|
1648
|
+
arrayConfig.itemSchemaRef = String(itemSchemaRef);
|
|
1649
|
+
}
|
|
1650
|
+
const explicitItemSchema = arrayConfig.itemSchema && typeof arrayConfig.itemSchema === 'object'
|
|
1651
|
+
? arrayConfig.itemSchema
|
|
1652
|
+
: undefined;
|
|
1653
|
+
if (explicitItemSchema && Array.isArray(explicitItemSchema.fields)) {
|
|
1654
|
+
const inlineFields = this.normalizeInlineItemSchemaFields(explicitItemSchema.fields, rootSchema);
|
|
1655
|
+
if (inlineFields.length) {
|
|
1656
|
+
arrayConfig.itemSchema = {
|
|
1657
|
+
...explicitItemSchema,
|
|
1658
|
+
fields: inlineFields,
|
|
1659
|
+
};
|
|
1660
|
+
return this.finalizeArrayConfig(arrayConfig, ui);
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
const resolvedItemSchema = explicitItemSchema ??
|
|
1664
|
+
this.resolveSchemaRef(arrayConfig.itemSchemaRef, rootSchema) ??
|
|
1665
|
+
(prop?.items && typeof prop.items === 'object' ? prop.items : undefined);
|
|
1666
|
+
if (resolvedItemSchema && typeof resolvedItemSchema === 'object') {
|
|
1667
|
+
const fields = this.normalizeObjectSchema(resolvedItemSchema, rootSchema);
|
|
1668
|
+
if (fields.length) {
|
|
1669
|
+
arrayConfig.itemSchema = {
|
|
1670
|
+
...(explicitItemSchema ?? resolvedItemSchema),
|
|
1671
|
+
fields,
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
return this.finalizeArrayConfig(arrayConfig, ui);
|
|
1676
|
+
}
|
|
1677
|
+
finalizeArrayConfig(arrayConfig, ui) {
|
|
1678
|
+
const collectionValidation = arrayConfig.collectionValidation ??
|
|
1679
|
+
(ui.collectionValidation && typeof ui.collectionValidation === 'object'
|
|
1680
|
+
? this.clonePlain(ui.collectionValidation)
|
|
1681
|
+
: undefined);
|
|
1682
|
+
if (collectionValidation) {
|
|
1683
|
+
arrayConfig.collectionValidation = collectionValidation;
|
|
1684
|
+
}
|
|
1685
|
+
return Object.keys(arrayConfig).length ? arrayConfig : undefined;
|
|
1686
|
+
}
|
|
1687
|
+
normalizeInlineItemSchemaFields(fields, rootSchema) {
|
|
1688
|
+
return fields
|
|
1689
|
+
.map((field) => this.normalizeInlineItemSchemaField(field, rootSchema))
|
|
1690
|
+
.filter((field) => !!field);
|
|
1691
|
+
}
|
|
1692
|
+
normalizeInlineItemSchemaField(field, rootSchema) {
|
|
1693
|
+
if (!field || typeof field !== 'object' || Array.isArray(field)) {
|
|
1694
|
+
return undefined;
|
|
1695
|
+
}
|
|
1696
|
+
if (field.controlType || field.dataType || !field['x-ui']) {
|
|
1697
|
+
return this.clonePlain(field);
|
|
1698
|
+
}
|
|
1699
|
+
const name = typeof field.name === 'string' && field.name.trim() ? field.name : undefined;
|
|
1700
|
+
if (!name) {
|
|
1701
|
+
return undefined;
|
|
1702
|
+
}
|
|
1703
|
+
const { name: _name, ...schema } = field;
|
|
1704
|
+
const normalized = this.normalizeSchemaWithRoot({
|
|
1705
|
+
type: 'object',
|
|
1706
|
+
properties: {
|
|
1707
|
+
[name]: schema,
|
|
1708
|
+
},
|
|
1709
|
+
}, rootSchema);
|
|
1710
|
+
return normalized[0];
|
|
1711
|
+
}
|
|
1712
|
+
/** Convert value to boolean. Accepts boolean, string or number. */
|
|
1713
|
+
parseBoolean(value) {
|
|
1714
|
+
if (typeof value === 'boolean') {
|
|
1715
|
+
return value;
|
|
1716
|
+
}
|
|
1717
|
+
if (typeof value === 'string') {
|
|
1718
|
+
return value.toLowerCase() === 'true';
|
|
1719
|
+
}
|
|
1720
|
+
if (typeof value === 'number') {
|
|
1721
|
+
return value !== 0;
|
|
1722
|
+
}
|
|
1723
|
+
return false;
|
|
1724
|
+
}
|
|
1725
|
+
parseOptionalBoolean(value) {
|
|
1726
|
+
if (typeof value === 'boolean') {
|
|
1727
|
+
return value;
|
|
1728
|
+
}
|
|
1729
|
+
if (typeof value === 'string') {
|
|
1730
|
+
const normalized = value.trim().toLowerCase();
|
|
1731
|
+
if (normalized === 'true') {
|
|
1732
|
+
return true;
|
|
1733
|
+
}
|
|
1734
|
+
if (normalized === 'false') {
|
|
1735
|
+
return false;
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
return undefined;
|
|
1739
|
+
}
|
|
1740
|
+
parseOptionalFiniteNumber(value) {
|
|
1741
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
1742
|
+
return value;
|
|
1743
|
+
}
|
|
1744
|
+
if (typeof value === 'string' && value.trim().length > 0) {
|
|
1745
|
+
const parsed = Number(value);
|
|
1746
|
+
if (Number.isFinite(parsed)) {
|
|
1747
|
+
return parsed;
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
return undefined;
|
|
1751
|
+
}
|
|
1752
|
+
/** Ensure an array of strings from various inputs. */
|
|
1753
|
+
parseStringArray(value) {
|
|
1754
|
+
if (Array.isArray(value)) {
|
|
1755
|
+
return value.map((v) => String(v));
|
|
1756
|
+
}
|
|
1757
|
+
if (typeof value === 'string') {
|
|
1758
|
+
return [value];
|
|
1759
|
+
}
|
|
1760
|
+
return [];
|
|
1761
|
+
}
|
|
1762
|
+
parseNonBlankStringArray(value) {
|
|
1763
|
+
const normalized = this.parseStringArray(value)
|
|
1764
|
+
.map((v) => String(v).trim())
|
|
1765
|
+
.filter((v) => v.length > 0);
|
|
1766
|
+
return normalized.filter((v, index) => normalized.indexOf(v) === index);
|
|
1767
|
+
}
|
|
1768
|
+
parseStringRecord(value) {
|
|
1769
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
1770
|
+
return undefined;
|
|
1771
|
+
}
|
|
1772
|
+
const normalized = Object.entries(value)
|
|
1773
|
+
.reduce((acc, [key, mapValue]) => {
|
|
1774
|
+
const normalizedKey = String(key).trim();
|
|
1775
|
+
const normalizedValue = String(mapValue ?? '').trim();
|
|
1776
|
+
if (normalizedKey && normalizedValue) {
|
|
1777
|
+
acc[normalizedKey] = normalizedValue;
|
|
1778
|
+
}
|
|
1779
|
+
return acc;
|
|
1780
|
+
}, {});
|
|
1781
|
+
return Object.keys(normalized).length ? normalized : undefined;
|
|
1782
|
+
}
|
|
1783
|
+
parseSelectionPolicy(value) {
|
|
1784
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
1785
|
+
return undefined;
|
|
1786
|
+
}
|
|
1787
|
+
const policy = {};
|
|
1788
|
+
if (value.selectablePropertyPath !== undefined) {
|
|
1789
|
+
policy.selectablePropertyPath = String(value.selectablePropertyPath);
|
|
1790
|
+
}
|
|
1791
|
+
if (value.statusPropertyPath !== undefined) {
|
|
1792
|
+
policy.statusPropertyPath = String(value.statusPropertyPath);
|
|
1793
|
+
}
|
|
1794
|
+
if (value.allowedStatuses !== undefined) {
|
|
1795
|
+
policy.allowedStatuses = this.parseStringArray(value.allowedStatuses);
|
|
1796
|
+
}
|
|
1797
|
+
if (value.blockedStatuses !== undefined) {
|
|
1798
|
+
policy.blockedStatuses = this.parseStringArray(value.blockedStatuses);
|
|
1799
|
+
}
|
|
1800
|
+
if (value.allowRetainInvalidExistingValue !== undefined) {
|
|
1801
|
+
policy.allowRetainInvalidExistingValue = this.parseBoolean(value.allowRetainInvalidExistingValue);
|
|
1802
|
+
}
|
|
1803
|
+
if (value.disabledReasonTemplate !== undefined) {
|
|
1804
|
+
policy.disabledReasonTemplate = String(value.disabledReasonTemplate);
|
|
1805
|
+
}
|
|
1806
|
+
if (value.validationMessageTemplate !== undefined) {
|
|
1807
|
+
policy.validationMessageTemplate = String(value.validationMessageTemplate);
|
|
1808
|
+
}
|
|
1809
|
+
return Object.keys(policy).length ? policy : undefined;
|
|
1810
|
+
}
|
|
1811
|
+
parseLookupCapabilities(value) {
|
|
1812
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
1813
|
+
return undefined;
|
|
1814
|
+
}
|
|
1815
|
+
const booleanKeys = [
|
|
1816
|
+
'filter',
|
|
1817
|
+
'byIds',
|
|
1818
|
+
'detail',
|
|
1819
|
+
'create',
|
|
1820
|
+
'edit',
|
|
1821
|
+
'navigateToDetail',
|
|
1822
|
+
'multiSelect',
|
|
1823
|
+
'recent',
|
|
1824
|
+
'favorites',
|
|
1825
|
+
'auditSnapshot',
|
|
1826
|
+
];
|
|
1827
|
+
const capabilities = {};
|
|
1828
|
+
booleanKeys.forEach((key) => {
|
|
1829
|
+
if (value[key] !== undefined) {
|
|
1830
|
+
capabilities[key] = this.parseBoolean(value[key]);
|
|
1831
|
+
}
|
|
1832
|
+
});
|
|
1833
|
+
return Object.keys(capabilities).length ? capabilities : undefined;
|
|
1834
|
+
}
|
|
1835
|
+
parseLookupDetail(value) {
|
|
1836
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
1837
|
+
return undefined;
|
|
1838
|
+
}
|
|
1839
|
+
const detail = {};
|
|
1840
|
+
if (value.hrefTemplate !== undefined) {
|
|
1841
|
+
detail.hrefTemplate = String(value.hrefTemplate);
|
|
1842
|
+
}
|
|
1843
|
+
if (value.routeTemplate !== undefined) {
|
|
1844
|
+
detail.routeTemplate = String(value.routeTemplate);
|
|
1845
|
+
}
|
|
1846
|
+
if (value.openDetailMode !== undefined) {
|
|
1847
|
+
const openDetailMode = this.parseLookupOpenDetailMode(value.openDetailMode);
|
|
1848
|
+
if (openDetailMode) {
|
|
1849
|
+
detail.openDetailMode = openDetailMode;
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
if (value.kind !== undefined) {
|
|
1853
|
+
detail.kind = String(value.kind);
|
|
1854
|
+
}
|
|
1855
|
+
if (value.surfaceId !== undefined) {
|
|
1856
|
+
detail.surfaceId = String(value.surfaceId);
|
|
1857
|
+
}
|
|
1858
|
+
if (value.presentation !== undefined) {
|
|
1859
|
+
detail.presentation = String(value.presentation);
|
|
1860
|
+
}
|
|
1861
|
+
if (value.preferredWidget !== undefined) {
|
|
1862
|
+
detail.preferredWidget = String(value.preferredWidget);
|
|
1863
|
+
}
|
|
1864
|
+
if (value.mode !== undefined) {
|
|
1865
|
+
detail.mode = String(value.mode);
|
|
1866
|
+
}
|
|
1867
|
+
return Object.keys(detail).length ? detail : undefined;
|
|
1868
|
+
}
|
|
1869
|
+
parseLookupDisplay(value) {
|
|
1870
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
1871
|
+
return undefined;
|
|
1872
|
+
}
|
|
1873
|
+
const display = {};
|
|
1874
|
+
const stringKeys = [
|
|
1875
|
+
'preset',
|
|
1876
|
+
'usage',
|
|
1877
|
+
'density',
|
|
1878
|
+
'selectedLayout',
|
|
1879
|
+
'resultLayout',
|
|
1880
|
+
'primaryPropertyPath',
|
|
1881
|
+
'avatarPropertyPath',
|
|
1882
|
+
];
|
|
1883
|
+
stringKeys.forEach((key) => {
|
|
1884
|
+
if (value[key] !== undefined) {
|
|
1885
|
+
display[key] = String(value[key]);
|
|
1886
|
+
}
|
|
1887
|
+
});
|
|
1888
|
+
if (Array.isArray(value.fields)) {
|
|
1889
|
+
const fields = value.fields
|
|
1890
|
+
.map((field) => this.parseLookupDisplayField(field))
|
|
1891
|
+
.filter((field) => !!field);
|
|
1892
|
+
if (fields.length) {
|
|
1893
|
+
display.fields = fields;
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
if (value.secondaryPropertyPaths !== undefined) {
|
|
1897
|
+
display.secondaryPropertyPaths = this.parseStringArray(value.secondaryPropertyPaths);
|
|
1898
|
+
}
|
|
1899
|
+
if (value.badgePropertyPaths !== undefined) {
|
|
1900
|
+
display.badgePropertyPaths = this.parseStringArray(value.badgePropertyPaths);
|
|
1901
|
+
}
|
|
1902
|
+
const booleanKeys = [
|
|
1903
|
+
'showAvatar',
|
|
1904
|
+
'showCode',
|
|
1905
|
+
'showDescription',
|
|
1906
|
+
'showStatus',
|
|
1907
|
+
'showBadges',
|
|
1908
|
+
'showDisabledReason',
|
|
1909
|
+
'showResultCount',
|
|
1910
|
+
];
|
|
1911
|
+
booleanKeys.forEach((key) => {
|
|
1912
|
+
if (value[key] !== undefined) {
|
|
1913
|
+
display[key] = this.parseBoolean(value[key]);
|
|
1914
|
+
}
|
|
1915
|
+
});
|
|
1916
|
+
if (value.maxVisibleBadges !== undefined && !Number.isNaN(Number(value.maxVisibleBadges))) {
|
|
1917
|
+
display.maxVisibleBadges = Number(value.maxVisibleBadges);
|
|
1918
|
+
}
|
|
1919
|
+
return Object.keys(display).length ? display : undefined;
|
|
1920
|
+
}
|
|
1921
|
+
parseLookupDisplayField(value) {
|
|
1922
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
1923
|
+
return undefined;
|
|
1924
|
+
}
|
|
1925
|
+
const field = {};
|
|
1926
|
+
['key', 'propertyPath', 'label', 'icon', 'presentation', 'tone', 'format'].forEach((key) => {
|
|
1927
|
+
if (value[key] !== undefined && String(value[key]).trim().length) {
|
|
1928
|
+
field[key] = String(value[key]);
|
|
1929
|
+
}
|
|
1930
|
+
});
|
|
1931
|
+
return Object.keys(field).length ? field : undefined;
|
|
1932
|
+
}
|
|
1933
|
+
parseLookupCreate(value) {
|
|
1934
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
1935
|
+
return undefined;
|
|
1936
|
+
}
|
|
1937
|
+
const create = {};
|
|
1938
|
+
if (value.hrefTemplate !== undefined) {
|
|
1939
|
+
create.hrefTemplate = String(value.hrefTemplate);
|
|
1940
|
+
}
|
|
1941
|
+
if (value.routeTemplate !== undefined) {
|
|
1942
|
+
create.routeTemplate = String(value.routeTemplate);
|
|
1943
|
+
}
|
|
1944
|
+
if (value.openMode !== undefined) {
|
|
1945
|
+
const openMode = this.parseLookupOpenDetailMode(value.openMode);
|
|
1946
|
+
if (openMode) {
|
|
1947
|
+
create.openMode = openMode;
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
return Object.keys(create).length ? create : undefined;
|
|
1951
|
+
}
|
|
1952
|
+
parseLookupFilterOperatorArray(value) {
|
|
1953
|
+
if (!Array.isArray(value)) {
|
|
1954
|
+
return [];
|
|
1955
|
+
}
|
|
1956
|
+
const normalized = value.map((item) => String(item ?? '').trim());
|
|
1957
|
+
if (normalized.some((item) => !item || !LOOKUP_FILTER_OPERATORS.has(item))) {
|
|
1958
|
+
return [];
|
|
1959
|
+
}
|
|
1960
|
+
return normalized
|
|
1961
|
+
.filter((item, index) => normalized.indexOf(item) === index)
|
|
1962
|
+
.map((item) => item);
|
|
1963
|
+
}
|
|
1964
|
+
parseLookupSortDirection(value) {
|
|
1965
|
+
const normalized = String(value ?? '').trim().toLowerCase();
|
|
1966
|
+
if (normalized === 'asc' || normalized === 'desc') {
|
|
1967
|
+
return normalized;
|
|
1968
|
+
}
|
|
1969
|
+
return undefined;
|
|
1970
|
+
}
|
|
1971
|
+
parseLookupDialogSize(value) {
|
|
1972
|
+
const normalized = String(value ?? '').trim();
|
|
1973
|
+
if (normalized === 'sm' ||
|
|
1974
|
+
normalized === 'md' ||
|
|
1975
|
+
normalized === 'lg' ||
|
|
1976
|
+
normalized === 'xl' ||
|
|
1977
|
+
normalized === 'full') {
|
|
1978
|
+
return normalized;
|
|
1979
|
+
}
|
|
1980
|
+
return undefined;
|
|
1981
|
+
}
|
|
1982
|
+
parseLookupDialog(value) {
|
|
1983
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
1984
|
+
return undefined;
|
|
1985
|
+
}
|
|
1986
|
+
const dialog = {};
|
|
1987
|
+
if (value.enabled !== undefined) {
|
|
1988
|
+
dialog.enabled = this.parseBoolean(value.enabled);
|
|
1989
|
+
}
|
|
1990
|
+
if (value.title !== undefined) {
|
|
1991
|
+
const title = String(value.title).trim();
|
|
1992
|
+
if (title) {
|
|
1993
|
+
dialog.title = title;
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
if (value.size !== undefined) {
|
|
1997
|
+
const size = this.parseLookupDialogSize(value.size);
|
|
1998
|
+
if (size) {
|
|
1999
|
+
dialog.size = size;
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
if (value.previewPanel !== undefined) {
|
|
2003
|
+
dialog.previewPanel = this.parseBoolean(value.previewPanel);
|
|
2004
|
+
}
|
|
2005
|
+
if (value.allowColumnChooser !== undefined) {
|
|
2006
|
+
dialog.allowColumnChooser = this.parseBoolean(value.allowColumnChooser);
|
|
2007
|
+
}
|
|
2008
|
+
if (value.allowSavedViews !== undefined) {
|
|
2009
|
+
dialog.allowSavedViews = this.parseBoolean(value.allowSavedViews);
|
|
2010
|
+
}
|
|
2011
|
+
if (Array.isArray(value.resultColumns)) {
|
|
2012
|
+
const resultColumns = value.resultColumns
|
|
2013
|
+
.map((item) => this.parseLookupResultColumn(item))
|
|
2014
|
+
.filter((item) => !!item);
|
|
2015
|
+
if (resultColumns.length) {
|
|
2016
|
+
dialog.resultColumns = resultColumns;
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
if (value.openActionLabel !== undefined) {
|
|
2020
|
+
const openActionLabel = String(value.openActionLabel).trim();
|
|
2021
|
+
if (openActionLabel) {
|
|
2022
|
+
dialog.openActionLabel = openActionLabel;
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
if (value.applyActionLabel !== undefined) {
|
|
2026
|
+
const applyActionLabel = String(value.applyActionLabel).trim();
|
|
2027
|
+
if (applyActionLabel) {
|
|
2028
|
+
dialog.applyActionLabel = applyActionLabel;
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
if (value.cancelActionLabel !== undefined) {
|
|
2032
|
+
const cancelActionLabel = String(value.cancelActionLabel).trim();
|
|
2033
|
+
if (cancelActionLabel) {
|
|
2034
|
+
dialog.cancelActionLabel = cancelActionLabel;
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
return Object.keys(dialog).length ? dialog : undefined;
|
|
2038
|
+
}
|
|
2039
|
+
parseLookupResultColumn(value) {
|
|
2040
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
2041
|
+
return undefined;
|
|
2042
|
+
}
|
|
2043
|
+
const field = String(value.field ?? '').trim();
|
|
2044
|
+
if (!field) {
|
|
2045
|
+
return undefined;
|
|
2046
|
+
}
|
|
2047
|
+
const column = { field };
|
|
2048
|
+
if (value.label !== undefined) {
|
|
2049
|
+
const label = String(value.label).trim();
|
|
2050
|
+
if (label) {
|
|
2051
|
+
column.label = label;
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
if (value.kind !== undefined) {
|
|
2055
|
+
const kind = String(value.kind).trim();
|
|
2056
|
+
if (kind === 'code' ||
|
|
2057
|
+
kind === 'label' ||
|
|
2058
|
+
kind === 'description' ||
|
|
2059
|
+
kind === 'status' ||
|
|
2060
|
+
kind === 'disabledReason' ||
|
|
2061
|
+
kind === 'custom') {
|
|
2062
|
+
column.kind = kind;
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
if (value.width !== undefined) {
|
|
2066
|
+
const width = String(value.width).trim();
|
|
2067
|
+
if (width) {
|
|
2068
|
+
column.width = width;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
return column;
|
|
2072
|
+
}
|
|
2073
|
+
parseLookupFilterDefinition(value) {
|
|
2074
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
2075
|
+
return undefined;
|
|
2076
|
+
}
|
|
2077
|
+
const field = String(value.field ?? '').trim();
|
|
2078
|
+
const type = String(value.type ?? '').trim();
|
|
2079
|
+
if (!field || !LOOKUP_FILTER_FIELD_TYPES.has(type)) {
|
|
2080
|
+
return undefined;
|
|
2081
|
+
}
|
|
2082
|
+
const operators = this.parseLookupFilterOperatorArray(value.operators);
|
|
2083
|
+
if (!operators.length) {
|
|
2084
|
+
return undefined;
|
|
2085
|
+
}
|
|
2086
|
+
const definition = {
|
|
2087
|
+
field,
|
|
2088
|
+
type,
|
|
2089
|
+
operators,
|
|
2090
|
+
};
|
|
2091
|
+
if (value.label !== undefined) {
|
|
2092
|
+
definition.label = String(value.label);
|
|
2093
|
+
}
|
|
2094
|
+
const defaultOperator = String(value.defaultOperator ?? '').trim();
|
|
2095
|
+
if (defaultOperator && operators.includes(defaultOperator)) {
|
|
2096
|
+
definition.defaultOperator = defaultOperator;
|
|
2097
|
+
}
|
|
2098
|
+
if (value.optionsSource !== undefined) {
|
|
2099
|
+
const optionsSource = String(value.optionsSource).trim();
|
|
2100
|
+
if (optionsSource) {
|
|
2101
|
+
definition.optionsSource = optionsSource;
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
if (value.required !== undefined) {
|
|
2105
|
+
definition.required = this.parseBoolean(value.required);
|
|
2106
|
+
}
|
|
2107
|
+
if (value.hidden !== undefined) {
|
|
2108
|
+
definition.hidden = this.parseBoolean(value.hidden);
|
|
2109
|
+
}
|
|
2110
|
+
return definition;
|
|
2111
|
+
}
|
|
2112
|
+
parseDefaultFilters(value) {
|
|
2113
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
2114
|
+
return undefined;
|
|
2115
|
+
}
|
|
2116
|
+
const normalized = Object.entries(value).reduce((acc, [key, item]) => {
|
|
2117
|
+
const normalizedKey = String(key).trim();
|
|
2118
|
+
if (!normalizedKey) {
|
|
2119
|
+
return acc;
|
|
2120
|
+
}
|
|
2121
|
+
const values = Array.isArray(item)
|
|
2122
|
+
? item.filter((entry) => entry !== undefined)
|
|
2123
|
+
: item === undefined
|
|
2124
|
+
? []
|
|
2125
|
+
: [item];
|
|
2126
|
+
if (values.length) {
|
|
2127
|
+
acc[normalizedKey] = values;
|
|
2128
|
+
}
|
|
2129
|
+
return acc;
|
|
2130
|
+
}, {});
|
|
2131
|
+
return Object.keys(normalized).length ? normalized : undefined;
|
|
2132
|
+
}
|
|
2133
|
+
parseLookupFiltering(value) {
|
|
2134
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
2135
|
+
return undefined;
|
|
2136
|
+
}
|
|
2137
|
+
const filtering = {};
|
|
2138
|
+
if (value.availableFilters !== undefined) {
|
|
2139
|
+
const availableFilters = Array.isArray(value.availableFilters)
|
|
2140
|
+
? value.availableFilters
|
|
2141
|
+
.map((item) => this.parseLookupFilterDefinition(item))
|
|
2142
|
+
.filter((item) => !!item)
|
|
2143
|
+
: [];
|
|
2144
|
+
if (availableFilters.length) {
|
|
2145
|
+
filtering.availableFilters = availableFilters;
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
const defaultFilters = this.parseDefaultFilters(value.defaultFilters);
|
|
2149
|
+
if (defaultFilters) {
|
|
2150
|
+
filtering.defaultFilters = defaultFilters;
|
|
2151
|
+
}
|
|
2152
|
+
if (value.sortOptions !== undefined && Array.isArray(value.sortOptions)) {
|
|
2153
|
+
const sortOptions = value.sortOptions
|
|
2154
|
+
.map((item) => {
|
|
2155
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) {
|
|
2156
|
+
return undefined;
|
|
2157
|
+
}
|
|
2158
|
+
const key = String(item.key ?? '').trim();
|
|
2159
|
+
const field = String(item.field ?? '').trim();
|
|
2160
|
+
const direction = this.parseLookupSortDirection(item.direction);
|
|
2161
|
+
if (!key || !field || !direction) {
|
|
2162
|
+
return undefined;
|
|
2163
|
+
}
|
|
2164
|
+
return {
|
|
2165
|
+
key,
|
|
2166
|
+
field,
|
|
2167
|
+
direction,
|
|
2168
|
+
...(item.label !== undefined ? { label: String(item.label) } : {}),
|
|
2169
|
+
};
|
|
2170
|
+
})
|
|
2171
|
+
.filter((item) => !!item);
|
|
2172
|
+
if (sortOptions.length) {
|
|
2173
|
+
filtering.sortOptions = sortOptions;
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
if (value.defaultSort !== undefined) {
|
|
2177
|
+
const defaultSort = String(value.defaultSort).trim();
|
|
2178
|
+
if (defaultSort) {
|
|
2179
|
+
filtering.defaultSort = defaultSort;
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
if (value.quickFilterFields !== undefined) {
|
|
2183
|
+
const quickFilterFields = this.parseNonBlankStringArray(value.quickFilterFields);
|
|
2184
|
+
if (quickFilterFields.length) {
|
|
2185
|
+
filtering.quickFilterFields = quickFilterFields;
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
if (value.searchPlaceholder !== undefined) {
|
|
2189
|
+
const searchPlaceholder = String(value.searchPlaceholder).trim();
|
|
2190
|
+
if (searchPlaceholder) {
|
|
2191
|
+
filtering.searchPlaceholder = searchPlaceholder;
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
if (Array.isArray(value.searchStrategies)) {
|
|
2195
|
+
const seenKeys = new Set();
|
|
2196
|
+
const searchStrategies = value.searchStrategies
|
|
2197
|
+
.map((item) => {
|
|
2198
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) {
|
|
2199
|
+
return undefined;
|
|
2200
|
+
}
|
|
2201
|
+
const raw = item;
|
|
2202
|
+
const key = String(raw.key ?? '').trim();
|
|
2203
|
+
const kind = String(raw.kind ?? '').trim();
|
|
2204
|
+
const minSearchChars = Number(raw.minSearchChars);
|
|
2205
|
+
const inputFormat = String(raw.inputFormat ?? 'text').trim();
|
|
2206
|
+
if (!key ||
|
|
2207
|
+
seenKeys.has(key) ||
|
|
2208
|
+
!LOOKUP_SEARCH_STRATEGY_KINDS.has(kind) ||
|
|
2209
|
+
!['text', 'digits'].includes(inputFormat) ||
|
|
2210
|
+
!Number.isInteger(minSearchChars) ||
|
|
2211
|
+
minSearchChars < 1) {
|
|
2212
|
+
return undefined;
|
|
2213
|
+
}
|
|
2214
|
+
seenKeys.add(key);
|
|
2215
|
+
return {
|
|
2216
|
+
key,
|
|
2217
|
+
kind,
|
|
2218
|
+
minSearchChars,
|
|
2219
|
+
...(inputFormat === 'digits' ? { inputFormat } : {}),
|
|
2220
|
+
};
|
|
2221
|
+
})
|
|
2222
|
+
.filter((item) => !!item);
|
|
2223
|
+
if (searchStrategies.length) {
|
|
2224
|
+
filtering.searchStrategies = searchStrategies;
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
return Object.keys(filtering).length ? filtering : undefined;
|
|
2228
|
+
}
|
|
2229
|
+
/** Parse option arrays into `{ key, value }` objects with label preservation. */
|
|
2230
|
+
parseOptions(value) {
|
|
2231
|
+
if (!Array.isArray(value)) {
|
|
2232
|
+
return [];
|
|
2233
|
+
}
|
|
2234
|
+
return value.map((opt) => {
|
|
2235
|
+
if (typeof opt === 'object' && opt !== null) {
|
|
2236
|
+
const k = opt.key ?? opt.value ?? opt.id ?? opt.label ?? '';
|
|
2237
|
+
const display = opt.label ??
|
|
2238
|
+
opt.text ??
|
|
2239
|
+
opt.title ??
|
|
2240
|
+
(opt.key !== undefined && opt.value !== undefined && opt.key !== opt.value
|
|
2241
|
+
? opt.value
|
|
2242
|
+
: undefined);
|
|
2243
|
+
const v = display ?? opt.value ?? opt.key ?? '';
|
|
2244
|
+
const result = {
|
|
2245
|
+
...opt,
|
|
2246
|
+
key: String(k),
|
|
2247
|
+
value: String(v),
|
|
2248
|
+
};
|
|
2249
|
+
if (display !== undefined && display !== null) {
|
|
2250
|
+
result.label = String(display);
|
|
2251
|
+
}
|
|
2252
|
+
return result;
|
|
2253
|
+
}
|
|
2254
|
+
return { key: String(opt), value: String(opt) };
|
|
2255
|
+
});
|
|
2256
|
+
}
|
|
2257
|
+
parseOptionSource(value) {
|
|
2258
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
2259
|
+
return undefined;
|
|
2260
|
+
}
|
|
2261
|
+
const optionSource = {
|
|
2262
|
+
key: String(value.key ?? '').trim(),
|
|
2263
|
+
};
|
|
2264
|
+
if (!optionSource.key) {
|
|
2265
|
+
return undefined;
|
|
2266
|
+
}
|
|
2267
|
+
if (value.type !== undefined) {
|
|
2268
|
+
const optionSourceType = this.parseOptionSourceType(value.type);
|
|
2269
|
+
if (optionSourceType) {
|
|
2270
|
+
optionSource.type = optionSourceType;
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
if (value.resourcePath !== undefined) {
|
|
2274
|
+
optionSource.resourcePath = String(value.resourcePath);
|
|
2275
|
+
}
|
|
2276
|
+
if (value.filterField !== undefined) {
|
|
2277
|
+
optionSource.filterField = String(value.filterField);
|
|
2278
|
+
}
|
|
2279
|
+
if (value.propertyPath !== undefined) {
|
|
2280
|
+
optionSource.propertyPath = String(value.propertyPath);
|
|
2281
|
+
}
|
|
2282
|
+
if (value.labelPropertyPath !== undefined) {
|
|
2283
|
+
optionSource.labelPropertyPath = String(value.labelPropertyPath);
|
|
2284
|
+
}
|
|
2285
|
+
if (value.valuePropertyPath !== undefined) {
|
|
2286
|
+
optionSource.valuePropertyPath = String(value.valuePropertyPath);
|
|
2287
|
+
}
|
|
2288
|
+
if (value.entityKey !== undefined) {
|
|
2289
|
+
optionSource.entityKey = String(value.entityKey);
|
|
2290
|
+
}
|
|
2291
|
+
if (value.codePropertyPath !== undefined) {
|
|
2292
|
+
optionSource.codePropertyPath = String(value.codePropertyPath);
|
|
2293
|
+
}
|
|
2294
|
+
if (value.descriptionPropertyPaths !== undefined) {
|
|
2295
|
+
optionSource.descriptionPropertyPaths = this.parseStringArray(value.descriptionPropertyPaths);
|
|
2296
|
+
}
|
|
2297
|
+
if (value.statusPropertyPath !== undefined) {
|
|
2298
|
+
optionSource.statusPropertyPath = String(value.statusPropertyPath);
|
|
2299
|
+
}
|
|
2300
|
+
if (value.disabledPropertyPath !== undefined) {
|
|
2301
|
+
optionSource.disabledPropertyPath = String(value.disabledPropertyPath);
|
|
2302
|
+
}
|
|
2303
|
+
if (value.disabledReasonPropertyPath !== undefined) {
|
|
2304
|
+
optionSource.disabledReasonPropertyPath = String(value.disabledReasonPropertyPath);
|
|
2305
|
+
}
|
|
2306
|
+
if (value.searchPropertyPaths !== undefined) {
|
|
2307
|
+
optionSource.searchPropertyPaths = this.parseStringArray(value.searchPropertyPaths);
|
|
2308
|
+
}
|
|
2309
|
+
if (value.dependsOn !== undefined) {
|
|
2310
|
+
const dependsOn = this.parseNonBlankStringArray(value.dependsOn);
|
|
2311
|
+
if (dependsOn.length) {
|
|
2312
|
+
optionSource.dependsOn = dependsOn;
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
const dependencyFilterMap = this.parseStringRecord(value.dependencyFilterMap);
|
|
2316
|
+
if (dependencyFilterMap) {
|
|
2317
|
+
optionSource.dependencyFilterMap = dependencyFilterMap;
|
|
2318
|
+
}
|
|
2319
|
+
const selectionPolicy = this.parseSelectionPolicy(value.selectionPolicy);
|
|
2320
|
+
if (selectionPolicy) {
|
|
2321
|
+
optionSource.selectionPolicy = selectionPolicy;
|
|
2322
|
+
}
|
|
2323
|
+
const capabilities = this.parseLookupCapabilities(value.capabilities);
|
|
2324
|
+
if (capabilities) {
|
|
2325
|
+
optionSource.capabilities = capabilities;
|
|
2326
|
+
}
|
|
2327
|
+
const detail = this.parseLookupDetail(value.detail);
|
|
2328
|
+
if (detail) {
|
|
2329
|
+
optionSource.detail = detail;
|
|
2330
|
+
}
|
|
2331
|
+
const display = this.parseLookupDisplay(value.display);
|
|
2332
|
+
if (display) {
|
|
2333
|
+
optionSource.display = display;
|
|
2334
|
+
}
|
|
2335
|
+
const create = this.parseLookupCreate(value.create);
|
|
2336
|
+
if (create) {
|
|
2337
|
+
optionSource.create = create;
|
|
2338
|
+
}
|
|
2339
|
+
const filtering = this.parseLookupFiltering(value.filtering);
|
|
2340
|
+
if (filtering) {
|
|
2341
|
+
optionSource.filtering = filtering;
|
|
2342
|
+
}
|
|
2343
|
+
if (value.excludeSelfField !== undefined) {
|
|
2344
|
+
optionSource.excludeSelfField = this.parseBoolean(value.excludeSelfField);
|
|
2345
|
+
}
|
|
2346
|
+
if (value.searchMode !== undefined) {
|
|
2347
|
+
const searchMode = this.parseOptionSourceSearchMode(value.searchMode);
|
|
2348
|
+
if (searchMode) {
|
|
2349
|
+
optionSource.searchMode = searchMode;
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
if (value.pageSize !== undefined && !Number.isNaN(Number(value.pageSize))) {
|
|
2353
|
+
optionSource.pageSize = Number(value.pageSize);
|
|
2354
|
+
}
|
|
2355
|
+
if (value.includeIds !== undefined) {
|
|
2356
|
+
optionSource.includeIds = this.parseBoolean(value.includeIds);
|
|
2357
|
+
}
|
|
2358
|
+
if (value.selectedReloadPolicy !== undefined) {
|
|
2359
|
+
const selectedReloadPolicy = this.parseOptionSourceSelectedReloadPolicy(value.selectedReloadPolicy);
|
|
2360
|
+
if (selectedReloadPolicy) {
|
|
2361
|
+
optionSource.selectedReloadPolicy = selectedReloadPolicy;
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
if (value.invalidSortPolicy !== undefined) {
|
|
2365
|
+
const invalidSortPolicy = this.parseOptionSourceInvalidSortPolicy(value.invalidSortPolicy);
|
|
2366
|
+
if (invalidSortPolicy) {
|
|
2367
|
+
optionSource.invalidSortPolicy = invalidSortPolicy;
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
return optionSource;
|
|
2371
|
+
}
|
|
2372
|
+
parseOptionSourceType(value) {
|
|
2373
|
+
const normalized = String(value ?? '').trim().toUpperCase();
|
|
2374
|
+
return OPTION_SOURCE_TYPES.has(normalized) ? normalized : undefined;
|
|
2375
|
+
}
|
|
2376
|
+
parseOptionSourceSearchMode(value) {
|
|
2377
|
+
const normalized = String(value ?? '').trim();
|
|
2378
|
+
return OPTION_SOURCE_SEARCH_MODES.has(normalized) ? normalized : undefined;
|
|
2379
|
+
}
|
|
2380
|
+
parseOptionSourceSelectedReloadPolicy(value) {
|
|
2381
|
+
const normalized = String(value ?? '').trim();
|
|
2382
|
+
return OPTION_SOURCE_SELECTED_RELOAD_POLICIES.has(normalized) ? normalized : undefined;
|
|
2383
|
+
}
|
|
2384
|
+
parseOptionSourceInvalidSortPolicy(value) {
|
|
2385
|
+
const normalized = String(value ?? '').trim();
|
|
2386
|
+
return OPTION_SOURCE_INVALID_SORT_POLICIES.has(normalized) ? normalized : undefined;
|
|
2387
|
+
}
|
|
2388
|
+
parseLookupOpenDetailMode(value) {
|
|
2389
|
+
const normalized = String(value ?? '').trim();
|
|
2390
|
+
return LOOKUP_OPEN_DETAIL_MODES.has(normalized) ? normalized : undefined;
|
|
2391
|
+
}
|
|
2392
|
+
parseValuePresentation(value) {
|
|
2393
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
2394
|
+
return undefined;
|
|
2395
|
+
}
|
|
2396
|
+
const typeToken = String(value.type ?? '').trim();
|
|
2397
|
+
if (!typeToken || !VALUE_PRESENTATION_TYPES.has(typeToken)) {
|
|
2398
|
+
if (typeToken) {
|
|
2399
|
+
console.warn(`[SchemaNormalizer] Ignoring invalid x-ui.valuePresentation.type: ${typeToken}`);
|
|
2400
|
+
}
|
|
2401
|
+
return undefined;
|
|
2402
|
+
}
|
|
2403
|
+
const presentation = {
|
|
2404
|
+
type: typeToken,
|
|
2405
|
+
};
|
|
2406
|
+
const styleToken = String(value.style ?? '').trim();
|
|
2407
|
+
if (styleToken) {
|
|
2408
|
+
if (VALUE_PRESENTATION_STYLES.has(styleToken)) {
|
|
2409
|
+
presentation.style = styleToken;
|
|
2410
|
+
}
|
|
2411
|
+
else {
|
|
2412
|
+
console.warn(`[SchemaNormalizer] Ignoring invalid x-ui.valuePresentation.style: ${styleToken}`);
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
const formatToken = String(value.format ?? '').trim();
|
|
2416
|
+
if (formatToken) {
|
|
2417
|
+
presentation.format = formatToken;
|
|
2418
|
+
}
|
|
2419
|
+
if (value.currency && typeof value.currency === 'object') {
|
|
2420
|
+
presentation.currency = { ...value.currency };
|
|
2421
|
+
}
|
|
2422
|
+
if (value.number && typeof value.number === 'object') {
|
|
2423
|
+
presentation.number = { ...value.number };
|
|
2424
|
+
}
|
|
2425
|
+
return presentation;
|
|
2426
|
+
}
|
|
2427
|
+
/**
|
|
2428
|
+
* Converte string/Function em função real.
|
|
2429
|
+
* Atenção: usa `new Function` para avaliar strings – requer backend confiável.
|
|
2430
|
+
*/
|
|
2431
|
+
parseFunction(fn) {
|
|
2432
|
+
if (typeof fn === 'function') {
|
|
2433
|
+
return fn;
|
|
2434
|
+
}
|
|
2435
|
+
if (typeof fn === 'string' && fn.trim()) {
|
|
2436
|
+
try {
|
|
2437
|
+
// eslint-disable-next-line no-new-func
|
|
2438
|
+
return new Function(`return (${fn});`)();
|
|
2439
|
+
}
|
|
2440
|
+
catch {
|
|
2441
|
+
return undefined;
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
return undefined;
|
|
2445
|
+
}
|
|
2446
|
+
/** Parse a transform function: (val: any) => any */
|
|
2447
|
+
parseTransformFunction(fn) {
|
|
2448
|
+
const parsed = this.parseFunction(fn);
|
|
2449
|
+
if (!parsed)
|
|
2450
|
+
return undefined;
|
|
2451
|
+
return parsed;
|
|
2452
|
+
}
|
|
2453
|
+
parseConditionalValidationRules(value, fieldName) {
|
|
2454
|
+
if (value === undefined) {
|
|
2455
|
+
return undefined;
|
|
2456
|
+
}
|
|
2457
|
+
if (!Array.isArray(value)) {
|
|
2458
|
+
console.warn(`[SchemaNormalizer] Ignoring non-array x-ui.conditionalValidation for field "${fieldName}". Expected an array of declarative rules.`);
|
|
2459
|
+
return undefined;
|
|
2460
|
+
}
|
|
2461
|
+
const rules = [];
|
|
2462
|
+
value.forEach((candidate, index) => {
|
|
2463
|
+
if (!candidate || typeof candidate !== 'object' || Array.isArray(candidate)) {
|
|
2464
|
+
console.warn(`[SchemaNormalizer] Ignoring invalid x-ui.conditionalValidation[${index}] for field "${fieldName}". Expected an object rule.`);
|
|
2465
|
+
return;
|
|
2466
|
+
}
|
|
2467
|
+
const condition = this.parseJsonLogicExpression(candidate['condition'], fieldName, `x-ui.conditionalValidation[${index}].condition`);
|
|
2468
|
+
const validatorsSource = candidate['validators'];
|
|
2469
|
+
if (!validatorsSource || typeof validatorsSource !== 'object' || Array.isArray(validatorsSource)) {
|
|
2470
|
+
console.warn(`[SchemaNormalizer] Ignoring x-ui.conditionalValidation[${index}] for field "${fieldName}" because validators is missing or invalid.`);
|
|
2471
|
+
return;
|
|
2472
|
+
}
|
|
2473
|
+
rules.push({
|
|
2474
|
+
condition: condition ?? null,
|
|
2475
|
+
validators: this.parseValidators(validatorsSource),
|
|
2476
|
+
});
|
|
2477
|
+
});
|
|
2478
|
+
return rules.length ? rules : undefined;
|
|
2479
|
+
}
|
|
2480
|
+
/**
|
|
2481
|
+
* Extrai e normaliza propriedades de validação a partir do objeto x-ui.
|
|
2482
|
+
* Suporta: required, min/max, minLength/maxLength, pattern/regex, email, url,
|
|
2483
|
+
* matchField, uniqueValidator (+message), conditionalValidation, requiredChecked,
|
|
2484
|
+
* arquivos (allowedFileTypes, fileTypeMessage, maxFileSize), custom/async validators,
|
|
2485
|
+
* minWords e comportamento (validationTrigger(s), validationDebounce, showInlineErrors, errorPosition).
|
|
2486
|
+
*/
|
|
2487
|
+
parseValidators(ui, fieldName = 'unknown') {
|
|
2488
|
+
if (!ui || typeof ui !== 'object') {
|
|
2489
|
+
return {};
|
|
2490
|
+
}
|
|
2491
|
+
const out = {};
|
|
2492
|
+
// Basic validators and messages
|
|
2493
|
+
if (ui.required !== undefined)
|
|
2494
|
+
out.required = this.parseBoolean(ui.required);
|
|
2495
|
+
if (ui.requiredMessage !== undefined)
|
|
2496
|
+
out.requiredMessage = ui.requiredMessage;
|
|
2497
|
+
if (ui.minLength !== undefined)
|
|
2498
|
+
out.minLength = Number(ui.minLength);
|
|
2499
|
+
if (ui.minLengthMessage !== undefined)
|
|
2500
|
+
out.minLengthMessage = ui.minLengthMessage;
|
|
2501
|
+
if (ui.maxLength !== undefined)
|
|
2502
|
+
out.maxLength = Number(ui.maxLength);
|
|
2503
|
+
if (ui.maxLengthMessage !== undefined)
|
|
2504
|
+
out.maxLengthMessage = ui.maxLengthMessage;
|
|
2505
|
+
if (ui.min !== undefined) {
|
|
2506
|
+
const parsedMin = Number(ui.min);
|
|
2507
|
+
out.min = Number.isFinite(parsedMin) ? parsedMin : String(ui.min).trim();
|
|
2508
|
+
}
|
|
2509
|
+
if (ui.max !== undefined) {
|
|
2510
|
+
const parsedMax = Number(ui.max);
|
|
2511
|
+
out.max = Number.isFinite(parsedMax) ? parsedMax : String(ui.max).trim();
|
|
2512
|
+
}
|
|
2513
|
+
if (ui.minMessage !== undefined)
|
|
2514
|
+
out.minMessage = ui.minMessage;
|
|
2515
|
+
if (ui.maxMessage !== undefined)
|
|
2516
|
+
out.maxMessage = ui.maxMessage;
|
|
2517
|
+
// Range can define both min and max at once. Accept [min, max] or { min, max }
|
|
2518
|
+
if (ui.range !== undefined) {
|
|
2519
|
+
const r = ui.range;
|
|
2520
|
+
if (Array.isArray(r) && r.length >= 2) {
|
|
2521
|
+
if (out.min === undefined && r[0] != null)
|
|
2522
|
+
out.min = Number(r[0]);
|
|
2523
|
+
if (out.max === undefined && r[1] != null)
|
|
2524
|
+
out.max = Number(r[1]);
|
|
2525
|
+
}
|
|
2526
|
+
else if (typeof r === 'object' && r) {
|
|
2527
|
+
if (out.min === undefined && r.min != null)
|
|
2528
|
+
out.min = Number(r.min);
|
|
2529
|
+
if (out.max === undefined && r.max != null)
|
|
2530
|
+
out.max = Number(r.max);
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
if (ui.rangeMessage !== undefined)
|
|
2534
|
+
out.rangeMessage = ui.rangeMessage;
|
|
2535
|
+
// Pattern / Regex
|
|
2536
|
+
if (ui.pattern !== undefined)
|
|
2537
|
+
out.pattern = String(ui.pattern);
|
|
2538
|
+
if (ui.patternMessage !== undefined)
|
|
2539
|
+
out.patternMessage = ui.patternMessage;
|
|
2540
|
+
// Support alias keys: regex / regexMessage
|
|
2541
|
+
if (ui.regex !== undefined && out.pattern === undefined)
|
|
2542
|
+
out.pattern = String(ui.regex);
|
|
2543
|
+
if (ui.regexMessage !== undefined && out.patternMessage === undefined)
|
|
2544
|
+
out.patternMessage = ui.regexMessage;
|
|
2545
|
+
// Email and URL pattern helpers
|
|
2546
|
+
if (ui.email !== undefined)
|
|
2547
|
+
out.email = this.parseBoolean(ui.email);
|
|
2548
|
+
if (ui.emailMessage !== undefined)
|
|
2549
|
+
out.emailMessage = ui.emailMessage;
|
|
2550
|
+
if (ui.url !== undefined)
|
|
2551
|
+
out.url = this.parseBoolean(ui.url);
|
|
2552
|
+
if (ui.urlMessage !== undefined)
|
|
2553
|
+
out.urlMessage = ui.urlMessage;
|
|
2554
|
+
// Matching and unique validators
|
|
2555
|
+
if (ui.matchField !== undefined)
|
|
2556
|
+
out.matchField = String(ui.matchField);
|
|
2557
|
+
if (ui.matchFieldMessage !== undefined)
|
|
2558
|
+
out.matchFieldMessage = ui.matchFieldMessage;
|
|
2559
|
+
if (ui.uniqueMessage !== undefined)
|
|
2560
|
+
out.uniqueMessage = ui.uniqueMessage;
|
|
2561
|
+
if (ui.uniqueValidator !== undefined) {
|
|
2562
|
+
const uniq = this.parseFunction(ui.uniqueValidator);
|
|
2563
|
+
if (uniq)
|
|
2564
|
+
out.uniqueValidator = uniq;
|
|
2565
|
+
}
|
|
2566
|
+
// Conditional validation rules
|
|
2567
|
+
if (ui.conditionalValidation !== undefined) {
|
|
2568
|
+
const cond = this.parseConditionalValidationRules(ui.conditionalValidation, fieldName);
|
|
2569
|
+
if (cond)
|
|
2570
|
+
out.conditionalValidation = cond;
|
|
2571
|
+
}
|
|
2572
|
+
// Checkbox: required to be checked
|
|
2573
|
+
if (ui.requiredChecked !== undefined)
|
|
2574
|
+
out.requiredChecked = this.parseBoolean(ui.requiredChecked);
|
|
2575
|
+
// File validation
|
|
2576
|
+
if (ui.allowedFileTypes !== undefined)
|
|
2577
|
+
out.allowedFileTypes = this.parseStringArray(ui.allowedFileTypes);
|
|
2578
|
+
if (ui.fileTypeMessage !== undefined)
|
|
2579
|
+
out.fileTypeMessage = ui.fileTypeMessage;
|
|
2580
|
+
if (ui.maxFileSize !== undefined)
|
|
2581
|
+
out.maxFileSize = Number(ui.maxFileSize);
|
|
2582
|
+
// Custom validators (sync/async)
|
|
2583
|
+
if (ui.customValidator !== undefined) {
|
|
2584
|
+
const fn = this.parseFunction(ui.customValidator);
|
|
2585
|
+
if (fn)
|
|
2586
|
+
out.customValidator = fn;
|
|
2587
|
+
}
|
|
2588
|
+
if (ui.asyncValidator !== undefined) {
|
|
2589
|
+
const fn = this.parseFunction(ui.asyncValidator);
|
|
2590
|
+
if (fn)
|
|
2591
|
+
out.asyncValidator = fn;
|
|
2592
|
+
}
|
|
2593
|
+
// Word count
|
|
2594
|
+
if (ui.minWords !== undefined)
|
|
2595
|
+
out.minWords = Number(ui.minWords);
|
|
2596
|
+
// Validation behavior
|
|
2597
|
+
if (ui.validationTrigger !== undefined) {
|
|
2598
|
+
out.validationTriggers = Array.isArray(ui.validationTrigger)
|
|
2599
|
+
? ui.validationTrigger.map((t) => String(t))
|
|
2600
|
+
: [String(ui.validationTrigger)];
|
|
2601
|
+
}
|
|
2602
|
+
if (ui.validationTriggers !== undefined && out.validationTriggers === undefined) {
|
|
2603
|
+
out.validationTriggers = Array.isArray(ui.validationTriggers)
|
|
2604
|
+
? ui.validationTriggers.map((t) => String(t))
|
|
2605
|
+
: [String(ui.validationTriggers)];
|
|
2606
|
+
}
|
|
2607
|
+
if (ui.validationDebounce !== undefined)
|
|
2608
|
+
out.validationDebounce = Number(ui.validationDebounce);
|
|
2609
|
+
if (ui.showInlineErrors !== undefined)
|
|
2610
|
+
out.showInlineErrors = this.parseBoolean(ui.showInlineErrors);
|
|
2611
|
+
if (ui.errorPosition !== undefined)
|
|
2612
|
+
out.errorPosition = String(ui.errorPosition);
|
|
2613
|
+
return out;
|
|
2614
|
+
}
|
|
2615
|
+
/** Parse array of button definitions. */
|
|
2616
|
+
parseButtons(value) {
|
|
2617
|
+
if (!Array.isArray(value)) {
|
|
2618
|
+
return [];
|
|
2619
|
+
}
|
|
2620
|
+
return value.map((v) => ({ ...v }));
|
|
2621
|
+
}
|
|
2622
|
+
parseJsonLogicExpression(value, fieldName, sourceKey) {
|
|
2623
|
+
if (value === undefined) {
|
|
2624
|
+
return undefined;
|
|
2625
|
+
}
|
|
2626
|
+
if (value === null) {
|
|
2627
|
+
return null;
|
|
2628
|
+
}
|
|
2629
|
+
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
2630
|
+
return JSON.parse(JSON.stringify(value));
|
|
2631
|
+
}
|
|
2632
|
+
console.warn(`[SchemaNormalizer] Ignoring non-Json-Logic ${sourceKey} for field "${fieldName}". Expected object/null, received ${typeof value}.`);
|
|
2633
|
+
return undefined;
|
|
2634
|
+
}
|
|
2635
|
+
resolveNonEmptyStringToken(...values) {
|
|
2636
|
+
for (const value of values) {
|
|
2637
|
+
const text = String(value ?? '').trim();
|
|
2638
|
+
if (text.length) {
|
|
2639
|
+
return text;
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
return undefined;
|
|
2643
|
+
}
|
|
2644
|
+
isNumericSchemaType(type) {
|
|
2645
|
+
const token = String(type ?? '').trim().toLowerCase();
|
|
2646
|
+
return ['number', 'integer', 'int', 'float', 'double', 'decimal'].includes(token);
|
|
2647
|
+
}
|
|
2648
|
+
resolveNumericFormatToken(prop, ui, resolvedType) {
|
|
2649
|
+
if (ui?.numberFormat?.percentage === true || ui?.['numberFormat.percentage'] === true) {
|
|
2650
|
+
return 'percent';
|
|
2651
|
+
}
|
|
2652
|
+
const explicitUiFormat = this.resolveNonEmptyStringToken(ui?.numericFormat, ui?.numberFormat?.style, ui?.['numberFormat.style']);
|
|
2653
|
+
if (explicitUiFormat) {
|
|
2654
|
+
return explicitUiFormat;
|
|
2655
|
+
}
|
|
2656
|
+
const typeToken = resolvedType ?? prop?.type;
|
|
2657
|
+
if (!this.isNumericSchemaType(typeToken)) {
|
|
2658
|
+
return undefined;
|
|
2659
|
+
}
|
|
2660
|
+
const explicitFormat = this.resolveNonEmptyStringToken(ui?.format, prop?.format);
|
|
2661
|
+
if (explicitFormat) {
|
|
2662
|
+
return explicitFormat;
|
|
2663
|
+
}
|
|
2664
|
+
if (String(prop?.type ?? '').trim().toLowerCase() === 'integer') {
|
|
2665
|
+
return 'integer';
|
|
2666
|
+
}
|
|
2667
|
+
return undefined;
|
|
2668
|
+
}
|
|
2669
|
+
/**
|
|
2670
|
+
* Converte o schema bruto do backend (OpenAPI + x-ui) em FieldDefinition[] tipado.
|
|
2671
|
+
* Regras:
|
|
2672
|
+
* - Ignora propriedades sem x-ui.
|
|
2673
|
+
* - Garante ordenação por 'order' quando presente.
|
|
2674
|
+
* - Funções condicionais/transformações sempre viram funções reais.
|
|
2675
|
+
*
|
|
2676
|
+
* @param schema Objeto OpenAPI/JSON Schema com properties e x-ui por propriedade.
|
|
2677
|
+
* @returns FieldDefinition[] prontos para mapeamento/uso no restante do sistema.
|
|
2678
|
+
*/
|
|
2679
|
+
normalizeSchema(schema) {
|
|
2680
|
+
return this.normalizeSchemaWithRoot(schema, schema);
|
|
2681
|
+
}
|
|
2682
|
+
normalizeSchemaWithRoot(schema, rootSchema) {
|
|
2683
|
+
if (!schema || typeof schema !== 'object') {
|
|
2684
|
+
return [];
|
|
2685
|
+
}
|
|
2686
|
+
const properties = schema.properties ?? {};
|
|
2687
|
+
const requiredNames = new Set(Array.isArray(schema.required)
|
|
2688
|
+
? schema.required.filter((name) => typeof name === 'string')
|
|
2689
|
+
: []);
|
|
2690
|
+
const fields = [];
|
|
2691
|
+
for (const [name, prop] of Object.entries(properties)) {
|
|
2692
|
+
const ui = prop &&
|
|
2693
|
+
typeof prop === 'object' &&
|
|
2694
|
+
!Array.isArray(prop) &&
|
|
2695
|
+
prop['x-ui'] &&
|
|
2696
|
+
typeof prop['x-ui'] === 'object' &&
|
|
2697
|
+
!Array.isArray(prop['x-ui'])
|
|
2698
|
+
? prop['x-ui']
|
|
2699
|
+
: undefined;
|
|
2700
|
+
// Skip properties without x-ui metadata
|
|
2701
|
+
if (!ui || Object.keys(ui).length === 0) {
|
|
2702
|
+
continue;
|
|
2703
|
+
}
|
|
2704
|
+
const field = { name };
|
|
2705
|
+
// -------------------------------------------------------------------
|
|
2706
|
+
// Basic information
|
|
2707
|
+
// -------------------------------------------------------------------
|
|
2708
|
+
field.label = ui.label ?? prop.title ?? name;
|
|
2709
|
+
field.type = this.resolveFieldType(prop, ui);
|
|
2710
|
+
const numericFormat = this.resolveNumericFormatToken(prop, ui, field.type);
|
|
2711
|
+
if (numericFormat) {
|
|
2712
|
+
field.numericFormat = numericFormat;
|
|
2713
|
+
field.format = numericFormat;
|
|
2714
|
+
}
|
|
2715
|
+
const valuePresentation = this.parseValuePresentation(ui.valuePresentation);
|
|
2716
|
+
if (valuePresentation) {
|
|
2717
|
+
field.valuePresentation = valuePresentation;
|
|
2718
|
+
}
|
|
2719
|
+
const presentation = normalizeFieldPresentation(ui.presentation);
|
|
2720
|
+
if (Object.keys(presentation).length > 0) {
|
|
2721
|
+
field.presentation = presentation;
|
|
2722
|
+
}
|
|
2723
|
+
if (ui.controlType) {
|
|
2724
|
+
field.controlType = ui.controlType;
|
|
2725
|
+
}
|
|
2726
|
+
if (field.controlType === 'array' || ui.array !== undefined) {
|
|
2727
|
+
const arrayConfig = this.normalizeArrayConfig(ui, prop, rootSchema);
|
|
2728
|
+
if (arrayConfig) {
|
|
2729
|
+
field.array = arrayConfig;
|
|
2730
|
+
if (arrayConfig.collectionValidation) {
|
|
2731
|
+
field.collectionValidation = arrayConfig.collectionValidation;
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
if (ui.placeholder !== undefined) {
|
|
2736
|
+
field.placeholder = String(ui.placeholder);
|
|
2737
|
+
}
|
|
2738
|
+
if (ui.mode !== undefined) {
|
|
2739
|
+
field.mode = ui.mode;
|
|
2740
|
+
}
|
|
2741
|
+
if (ui.description || prop.description) {
|
|
2742
|
+
field.description = ui.description ?? prop.description;
|
|
2743
|
+
}
|
|
2744
|
+
if (ui.order !== undefined) {
|
|
2745
|
+
field.order = Number(ui.order);
|
|
2746
|
+
}
|
|
2747
|
+
if (ui.group !== undefined) {
|
|
2748
|
+
field.group = ui.group;
|
|
2749
|
+
}
|
|
2750
|
+
if (ui.selectionMode !== undefined) {
|
|
2751
|
+
field.selectionMode = String(ui.selectionMode);
|
|
2752
|
+
}
|
|
2753
|
+
if (ui.variant !== undefined) {
|
|
2754
|
+
field.variant = String(ui.variant);
|
|
2755
|
+
}
|
|
2756
|
+
if (ui.density !== undefined) {
|
|
2757
|
+
field.density = String(ui.density);
|
|
2758
|
+
}
|
|
2759
|
+
if (ui.layout !== undefined) {
|
|
2760
|
+
field.layout = String(ui.layout);
|
|
2761
|
+
}
|
|
2762
|
+
if (ui.isFlex !== undefined) {
|
|
2763
|
+
field.isFlex = this.parseBoolean(ui.isFlex);
|
|
2764
|
+
}
|
|
2765
|
+
if (ui.displayOrientation !== undefined) {
|
|
2766
|
+
field.displayOrientation = String(ui.displayOrientation);
|
|
2767
|
+
}
|
|
2768
|
+
// -------------------------------------------------------------------
|
|
2769
|
+
// Behaviour and validation
|
|
2770
|
+
// -------------------------------------------------------------------
|
|
2771
|
+
if (ui.readOnly !== undefined) {
|
|
2772
|
+
field.readOnly = this.parseBoolean(ui.readOnly);
|
|
2773
|
+
}
|
|
2774
|
+
if (ui.disabled !== undefined) {
|
|
2775
|
+
field.disabled = this.parseBoolean(ui.disabled);
|
|
2776
|
+
}
|
|
2777
|
+
if (ui.editable !== undefined) {
|
|
2778
|
+
field.editable = this.parseBoolean(ui.editable);
|
|
2779
|
+
}
|
|
2780
|
+
const fieldAccess = normalizeFieldAccessMetadata(ui.fieldAccess);
|
|
2781
|
+
if (fieldAccess) {
|
|
2782
|
+
field.fieldAccess = fieldAccess;
|
|
2783
|
+
}
|
|
2784
|
+
if (ui.inlineEditing !== undefined) {
|
|
2785
|
+
field.inlineEditing = this.parseBoolean(ui.inlineEditing);
|
|
2786
|
+
}
|
|
2787
|
+
if (ui.defaultValue !== undefined) {
|
|
2788
|
+
field.defaultValue = ui.defaultValue;
|
|
2789
|
+
}
|
|
2790
|
+
if (ui.validationMode !== undefined) {
|
|
2791
|
+
field.validationMode = String(ui.validationMode);
|
|
2792
|
+
}
|
|
2793
|
+
if (ui.unique !== undefined) {
|
|
2794
|
+
field.unique = this.parseBoolean(ui.unique);
|
|
2795
|
+
}
|
|
2796
|
+
if (ui.mask !== undefined) {
|
|
2797
|
+
field.mask = String(ui.mask);
|
|
2798
|
+
}
|
|
2799
|
+
if (ui.sortable !== undefined) {
|
|
2800
|
+
field.sortable = this.parseBoolean(ui.sortable);
|
|
2801
|
+
}
|
|
2802
|
+
if (ui.viewOnlyStyle !== undefined) {
|
|
2803
|
+
field.viewOnlyStyle = String(ui.viewOnlyStyle);
|
|
2804
|
+
}
|
|
2805
|
+
Object.assign(field, this.parseValidators(ui, name));
|
|
2806
|
+
// Required membership belongs to the canonical object schema. UI hints
|
|
2807
|
+
// can add validation but cannot make a required request field optional.
|
|
2808
|
+
if (requiredNames.has(name)) {
|
|
2809
|
+
field.required = true;
|
|
2810
|
+
}
|
|
2811
|
+
const condDisplay = this.parseJsonLogicExpression(ui.conditionalDisplay, name, 'x-ui.conditionalDisplay');
|
|
2812
|
+
if (condDisplay !== undefined) {
|
|
2813
|
+
field.conditionalDisplay = condDisplay;
|
|
2814
|
+
}
|
|
2815
|
+
const condRequired = this.parseJsonLogicExpression(ui.conditionalRequired, name, 'x-ui.conditionalRequired');
|
|
2816
|
+
if (condRequired !== undefined) {
|
|
2817
|
+
field.conditionalRequired = condRequired;
|
|
2818
|
+
}
|
|
2819
|
+
const transformFn = this.parseTransformFunction(ui.transformValueFunction);
|
|
2820
|
+
if (transformFn) {
|
|
2821
|
+
field.transformValueFunction = transformFn;
|
|
2822
|
+
}
|
|
2823
|
+
// -------------------------------------------------------------------
|
|
2824
|
+
// Layout and presentation
|
|
2825
|
+
// -------------------------------------------------------------------
|
|
2826
|
+
// Visibility flags (x-ui)
|
|
2827
|
+
if (ui.hidden !== undefined) {
|
|
2828
|
+
field.hidden = this.parseBoolean(ui.hidden);
|
|
2829
|
+
}
|
|
2830
|
+
if (ui.tableHidden !== undefined) {
|
|
2831
|
+
field.tableHidden = this.parseBoolean(ui.tableHidden);
|
|
2832
|
+
}
|
|
2833
|
+
if (ui.formHidden !== undefined) {
|
|
2834
|
+
field.formHidden = this.parseBoolean(ui.formHidden);
|
|
2835
|
+
}
|
|
2836
|
+
if (ui.width !== undefined) {
|
|
2837
|
+
field.width = ui.width;
|
|
2838
|
+
}
|
|
2839
|
+
if (ui.helpText !== undefined) {
|
|
2840
|
+
field.helpText = String(ui.helpText);
|
|
2841
|
+
}
|
|
2842
|
+
if (ui.tooltip !== undefined) {
|
|
2843
|
+
field.tooltip = String(ui.tooltip);
|
|
2844
|
+
}
|
|
2845
|
+
if (ui.hint !== undefined) {
|
|
2846
|
+
field.hint = ui.hint;
|
|
2847
|
+
}
|
|
2848
|
+
if (ui.hiddenCondition !== undefined) {
|
|
2849
|
+
const hiddenCondition = this.parseJsonLogicExpression(ui.hiddenCondition, name, 'x-ui.hiddenCondition');
|
|
2850
|
+
if (hiddenCondition !== undefined) {
|
|
2851
|
+
field.hiddenCondition = hiddenCondition;
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
if (ui.icon !== undefined) {
|
|
2855
|
+
field.icon = ui.icon;
|
|
2856
|
+
}
|
|
2857
|
+
if (ui.iconPosition !== undefined) {
|
|
2858
|
+
field.iconPosition = ui.iconPosition;
|
|
2859
|
+
}
|
|
2860
|
+
if (ui.iconSize !== undefined) {
|
|
2861
|
+
field.iconSize = ui.iconSize;
|
|
2862
|
+
}
|
|
2863
|
+
if (ui.iconColor !== undefined) {
|
|
2864
|
+
field.iconColor = String(ui.iconColor);
|
|
2865
|
+
}
|
|
2866
|
+
if (ui.iconClass !== undefined) {
|
|
2867
|
+
field.iconClass = String(ui.iconClass);
|
|
2868
|
+
}
|
|
2869
|
+
if (ui.iconStyle !== undefined) {
|
|
2870
|
+
field.iconStyle = String(ui.iconStyle);
|
|
2871
|
+
}
|
|
2872
|
+
if (ui.iconFontSize !== undefined) {
|
|
2873
|
+
field.iconFontSize = ui.iconFontSize;
|
|
2874
|
+
}
|
|
2875
|
+
if (ui.tooltipOnHover !== undefined) {
|
|
2876
|
+
field.tooltipOnHover = ui.tooltipOnHover;
|
|
2877
|
+
}
|
|
2878
|
+
if (ui.clearButton !== undefined) {
|
|
2879
|
+
if (typeof ui.clearButton === 'boolean') {
|
|
2880
|
+
field.clearButton = { enabled: this.parseBoolean(ui.clearButton) };
|
|
2881
|
+
}
|
|
2882
|
+
else if (typeof ui.clearButton === 'object') {
|
|
2883
|
+
field.clearButton = { ...ui.clearButton };
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
if (ui['clearButton.enabled'] !== undefined ||
|
|
2887
|
+
ui['clearButton.icon'] !== undefined ||
|
|
2888
|
+
ui['clearButton.iconColor'] !== undefined ||
|
|
2889
|
+
ui['clearButton.tooltip'] !== undefined ||
|
|
2890
|
+
ui['clearButton.ariaLabel'] !== undefined ||
|
|
2891
|
+
ui['clearButton.showOnlyWhenFilled'] !== undefined) {
|
|
2892
|
+
const clearButton = field.clearButton ?? {};
|
|
2893
|
+
if (ui['clearButton.enabled'] !== undefined) {
|
|
2894
|
+
clearButton.enabled = this.parseBoolean(ui['clearButton.enabled']);
|
|
2895
|
+
}
|
|
2896
|
+
if (ui['clearButton.icon'] !== undefined) {
|
|
2897
|
+
clearButton.icon = String(ui['clearButton.icon']);
|
|
2898
|
+
}
|
|
2899
|
+
if (ui['clearButton.iconColor'] !== undefined) {
|
|
2900
|
+
clearButton.iconColor = String(ui['clearButton.iconColor']);
|
|
2901
|
+
}
|
|
2902
|
+
if (ui['clearButton.tooltip'] !== undefined) {
|
|
2903
|
+
clearButton.tooltip = String(ui['clearButton.tooltip']);
|
|
2904
|
+
}
|
|
2905
|
+
if (ui['clearButton.ariaLabel'] !== undefined) {
|
|
2906
|
+
clearButton.ariaLabel = String(ui['clearButton.ariaLabel']);
|
|
2907
|
+
}
|
|
2908
|
+
if (ui['clearButton.showOnlyWhenFilled'] !== undefined) {
|
|
2909
|
+
clearButton.showOnlyWhenFilled = this.parseBoolean(ui['clearButton.showOnlyWhenFilled']);
|
|
2910
|
+
}
|
|
2911
|
+
field.clearButton = clearButton;
|
|
2912
|
+
}
|
|
2913
|
+
// -------------------------------------------------------------------
|
|
2914
|
+
// Options and dependencies
|
|
2915
|
+
// -------------------------------------------------------------------
|
|
2916
|
+
if (ui.options !== undefined) {
|
|
2917
|
+
field.options = this.parseOptions(ui.options);
|
|
2918
|
+
}
|
|
2919
|
+
if (Array.isArray(prop?.enum) && prop.enum.length > 0 && field.enumValues === undefined) {
|
|
2920
|
+
field.enumValues = [...prop.enum];
|
|
2921
|
+
}
|
|
2922
|
+
if (ui.optionGroups !== undefined) {
|
|
2923
|
+
field.optionGroups = this.parseOptions(ui.optionGroups);
|
|
2924
|
+
}
|
|
2925
|
+
if (ui.disabledOptions !== undefined) {
|
|
2926
|
+
field.disabledOptions = this.parseStringArray(ui.disabledOptions);
|
|
2927
|
+
}
|
|
2928
|
+
if (ui.endpoint !== undefined) {
|
|
2929
|
+
field.endpoint = ui.endpoint;
|
|
2930
|
+
}
|
|
2931
|
+
if (ui.resourcePath !== undefined) {
|
|
2932
|
+
field.resourcePath = ui.resourcePath;
|
|
2933
|
+
}
|
|
2934
|
+
if (ui.optionSource !== undefined) {
|
|
2935
|
+
const optionSource = this.parseOptionSource(ui.optionSource);
|
|
2936
|
+
if (optionSource) {
|
|
2937
|
+
// Java metadata publishes cascade context beside optionSource. Keep the
|
|
2938
|
+
// runtime contract canonical by materializing it inside optionSource.
|
|
2939
|
+
const dependsOn = this.parseNonBlankStringArray(ui.dependsOn);
|
|
2940
|
+
if (!optionSource.dependsOn?.length && dependsOn.length) {
|
|
2941
|
+
optionSource.dependsOn = dependsOn;
|
|
2942
|
+
}
|
|
2943
|
+
const dependencyFilterMap = this.parseStringRecord(ui.dependencyFilterMap);
|
|
2944
|
+
if (!optionSource.dependencyFilterMap &&
|
|
2945
|
+
dependencyFilterMap) {
|
|
2946
|
+
optionSource.dependencyFilterMap = dependencyFilterMap;
|
|
2947
|
+
}
|
|
2948
|
+
field.optionSource = optionSource;
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
if (ui.valueField !== undefined) {
|
|
2952
|
+
field.valueField = ui.valueField;
|
|
2953
|
+
}
|
|
2954
|
+
if (ui.displayField !== undefined) {
|
|
2955
|
+
field.displayField = ui.displayField;
|
|
2956
|
+
}
|
|
2957
|
+
if (ui.filterField !== undefined) {
|
|
2958
|
+
field.filterField = ui.filterField;
|
|
2959
|
+
}
|
|
2960
|
+
if (ui.multiple !== undefined) {
|
|
2961
|
+
field.multiple = this.parseBoolean(ui.multiple);
|
|
2962
|
+
}
|
|
2963
|
+
if (ui.filterable !== undefined) {
|
|
2964
|
+
field.filterable = this.parseBoolean(ui.filterable);
|
|
2965
|
+
}
|
|
2966
|
+
if (ui.emptyOptionText !== undefined) {
|
|
2967
|
+
field.emptyOptionText = ui.emptyOptionText;
|
|
2968
|
+
}
|
|
2969
|
+
if (ui.filter !== undefined) {
|
|
2970
|
+
field.filter = ui.filter;
|
|
2971
|
+
}
|
|
2972
|
+
if (ui.dialog !== undefined) {
|
|
2973
|
+
const dialog = this.parseLookupDialog(ui.dialog);
|
|
2974
|
+
if (dialog) {
|
|
2975
|
+
field.dialog = dialog;
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
if (ui.detailActionLabel !== undefined) {
|
|
2979
|
+
const detailActionLabel = String(ui.detailActionLabel).trim();
|
|
2980
|
+
if (detailActionLabel) {
|
|
2981
|
+
field.detailActionLabel = detailActionLabel;
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2984
|
+
if (ui.copyCodeActionLabel !== undefined) {
|
|
2985
|
+
const copyCodeActionLabel = String(ui.copyCodeActionLabel).trim();
|
|
2986
|
+
if (copyCodeActionLabel) {
|
|
2987
|
+
field.copyCodeActionLabel = copyCodeActionLabel;
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
if (ui.copyIdActionLabel !== undefined) {
|
|
2991
|
+
const copyIdActionLabel = String(ui.copyIdActionLabel).trim();
|
|
2992
|
+
if (copyIdActionLabel) {
|
|
2993
|
+
field.copyIdActionLabel = copyIdActionLabel;
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2996
|
+
if (ui.createActionLabel !== undefined) {
|
|
2997
|
+
const createActionLabel = String(ui.createActionLabel).trim();
|
|
2998
|
+
if (createActionLabel) {
|
|
2999
|
+
field.createActionLabel = createActionLabel;
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
if (ui.actions && typeof ui.actions === 'object' && !Array.isArray(ui.actions)) {
|
|
3003
|
+
const actions = {};
|
|
3004
|
+
if (ui.actions.showDetail !== undefined) {
|
|
3005
|
+
actions.showDetail = this.parseBoolean(ui.actions.showDetail);
|
|
3006
|
+
}
|
|
3007
|
+
if (ui.actions.showCopyCode !== undefined) {
|
|
3008
|
+
actions.showCopyCode = this.parseBoolean(ui.actions.showCopyCode);
|
|
3009
|
+
}
|
|
3010
|
+
if (ui.actions.showCopyId !== undefined) {
|
|
3011
|
+
actions.showCopyId = this.parseBoolean(ui.actions.showCopyId);
|
|
3012
|
+
}
|
|
3013
|
+
if (ui.actions.showCreate !== undefined) {
|
|
3014
|
+
actions.showCreate = this.parseBoolean(ui.actions.showCreate);
|
|
3015
|
+
}
|
|
3016
|
+
if (Object.keys(actions).length) {
|
|
3017
|
+
field.actions = actions;
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
3020
|
+
if (ui.filterOptions !== undefined) {
|
|
3021
|
+
field.filterOptions = Array.isArray(ui.filterOptions)
|
|
3022
|
+
? [...ui.filterOptions]
|
|
3023
|
+
: this.parseStringArray(ui.filterOptions);
|
|
3024
|
+
}
|
|
3025
|
+
if (ui.dependentField !== undefined) {
|
|
3026
|
+
field.dependentField = ui.dependentField;
|
|
3027
|
+
}
|
|
3028
|
+
if (ui.resetOnDependentChange !== undefined) {
|
|
3029
|
+
field.resetOnDependentChange = this.parseBoolean(ui.resetOnDependentChange);
|
|
3030
|
+
}
|
|
3031
|
+
if (ui.debounceTime !== undefined) {
|
|
3032
|
+
field.debounceTime = Number(ui.debounceTime);
|
|
3033
|
+
}
|
|
3034
|
+
if (ui.numericStep !== undefined) {
|
|
3035
|
+
field.numericStep = Number(ui.numericStep);
|
|
3036
|
+
}
|
|
3037
|
+
if (ui.numericMin !== undefined) {
|
|
3038
|
+
const parsedMin = Number(ui.numericMin);
|
|
3039
|
+
if (Number.isFinite(parsedMin)) {
|
|
3040
|
+
field.numericMin = parsedMin;
|
|
3041
|
+
}
|
|
3042
|
+
else if (field.min === undefined && String(ui.numericMin).trim().length > 0) {
|
|
3043
|
+
field.min = String(ui.numericMin).trim();
|
|
3044
|
+
}
|
|
3045
|
+
}
|
|
3046
|
+
if (ui.numericMax !== undefined) {
|
|
3047
|
+
const parsedMax = Number(ui.numericMax);
|
|
3048
|
+
if (Number.isFinite(parsedMax)) {
|
|
3049
|
+
field.numericMax = parsedMax;
|
|
3050
|
+
}
|
|
3051
|
+
else if (field.max === undefined && String(ui.numericMax).trim().length > 0) {
|
|
3052
|
+
field.max = String(ui.numericMax).trim();
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
if (ui.numericMaxLength !== undefined) {
|
|
3056
|
+
field.numericMaxLength = Number(ui.numericMaxLength);
|
|
3057
|
+
}
|
|
3058
|
+
if (ui.buttons !== undefined) {
|
|
3059
|
+
field.buttons = this.parseButtons(ui.buttons);
|
|
3060
|
+
}
|
|
3061
|
+
if (ui.valueLabelDisplay !== undefined) {
|
|
3062
|
+
const normalizedValueLabelDisplay = typeof ui.valueLabelDisplay === 'string'
|
|
3063
|
+
? ui.valueLabelDisplay.trim().toLowerCase()
|
|
3064
|
+
: '';
|
|
3065
|
+
if (normalizedValueLabelDisplay === 'off' ||
|
|
3066
|
+
normalizedValueLabelDisplay === 'auto' ||
|
|
3067
|
+
normalizedValueLabelDisplay === 'on') {
|
|
3068
|
+
field.valueLabelDisplay = normalizedValueLabelDisplay;
|
|
3069
|
+
}
|
|
3070
|
+
}
|
|
3071
|
+
const sliderBooleanKeys = [
|
|
3072
|
+
'thumbLabel',
|
|
3073
|
+
'discrete',
|
|
3074
|
+
'showInputs',
|
|
3075
|
+
'disableThumbSwap',
|
|
3076
|
+
'vertical',
|
|
3077
|
+
'invert',
|
|
3078
|
+
];
|
|
3079
|
+
for (const key of sliderBooleanKeys) {
|
|
3080
|
+
if (ui[key] !== undefined) {
|
|
3081
|
+
const parsed = this.parseOptionalBoolean(ui[key]);
|
|
3082
|
+
if (parsed !== undefined) {
|
|
3083
|
+
field[key] = parsed;
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
}
|
|
3087
|
+
if (ui.showTicks !== undefined) {
|
|
3088
|
+
const parsedTicks = this.parseOptionalBoolean(ui.showTicks);
|
|
3089
|
+
if (parsedTicks !== undefined) {
|
|
3090
|
+
field.showTicks = parsedTicks;
|
|
3091
|
+
}
|
|
3092
|
+
else if (typeof ui.showTicks === 'string' &&
|
|
3093
|
+
ui.showTicks.trim().toLowerCase() === 'auto') {
|
|
3094
|
+
field.showTicks = 'auto';
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
const sliderNumberKeys = [
|
|
3098
|
+
'shiftStep',
|
|
3099
|
+
'minDistance',
|
|
3100
|
+
'maxDistance',
|
|
3101
|
+
];
|
|
3102
|
+
for (const key of sliderNumberKeys) {
|
|
3103
|
+
if (ui[key] !== undefined) {
|
|
3104
|
+
const parsed = this.parseOptionalFiniteNumber(ui[key]);
|
|
3105
|
+
if (parsed !== undefined) {
|
|
3106
|
+
field[key] = parsed;
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3109
|
+
}
|
|
3110
|
+
// -------------------------------------------------------------------
|
|
3111
|
+
// Inline filter and specialized control metadata (x-ui)
|
|
3112
|
+
// -------------------------------------------------------------------
|
|
3113
|
+
const inlinePassThroughKeys = [
|
|
3114
|
+
'prefixIcon',
|
|
3115
|
+
'suffixIcon',
|
|
3116
|
+
'prefixIconColor',
|
|
3117
|
+
'suffixIconColor',
|
|
3118
|
+
'chipLeadingIcon',
|
|
3119
|
+
'chipTrailingIcon',
|
|
3120
|
+
'chipLeadingIconColor',
|
|
3121
|
+
'chipTrailingIconColor',
|
|
3122
|
+
'clearIcon',
|
|
3123
|
+
'clearIconColor',
|
|
3124
|
+
'showQuickClear',
|
|
3125
|
+
'clearable',
|
|
3126
|
+
'inlineAutoSize',
|
|
3127
|
+
'inlineAutoSizeMaxPx',
|
|
3128
|
+
'inlineAutoSizeMaxVw',
|
|
3129
|
+
'inlineOverlay',
|
|
3130
|
+
'inlineChipDisplay',
|
|
3131
|
+
'inlineChipSummaryTemplate',
|
|
3132
|
+
'inlineChipUnitLabel',
|
|
3133
|
+
'inlinePanelTitle',
|
|
3134
|
+
'inlineQuickPresets',
|
|
3135
|
+
'inlineQuickPresetsApplyMode',
|
|
3136
|
+
'inlineTexts',
|
|
3137
|
+
'shortcuts',
|
|
3138
|
+
'showShortcuts',
|
|
3139
|
+
'quickPresets',
|
|
3140
|
+
'quickPresetsAuto',
|
|
3141
|
+
'quickPresetsLabels',
|
|
3142
|
+
'granularity',
|
|
3143
|
+
'defaultGranularity',
|
|
3144
|
+
'selectionGrid',
|
|
3145
|
+
'showSlider',
|
|
3146
|
+
'minPeriod',
|
|
3147
|
+
'maxPeriod',
|
|
3148
|
+
'minYear',
|
|
3149
|
+
'maxYear',
|
|
3150
|
+
'minTime',
|
|
3151
|
+
'maxTime',
|
|
3152
|
+
'stepMinutes',
|
|
3153
|
+
'startField',
|
|
3154
|
+
'endField',
|
|
3155
|
+
'startLabel',
|
|
3156
|
+
'endLabel',
|
|
3157
|
+
'startPlaceholder',
|
|
3158
|
+
'endPlaceholder',
|
|
3159
|
+
'inputMinLabel',
|
|
3160
|
+
'inputMaxLabel',
|
|
3161
|
+
'maxVisibleChips',
|
|
3162
|
+
'maxVisibleBadges',
|
|
3163
|
+
'showSelectAll',
|
|
3164
|
+
'selectAllLabel',
|
|
3165
|
+
'clearSelectionLabel',
|
|
3166
|
+
'searchPlaceholder',
|
|
3167
|
+
'noResultsText',
|
|
3168
|
+
'allowSelectAll',
|
|
3169
|
+
'governedPaletteRef',
|
|
3170
|
+
'palette',
|
|
3171
|
+
'paletteColors',
|
|
3172
|
+
'paletteSettings',
|
|
3173
|
+
'documentType',
|
|
3174
|
+
'version',
|
|
3175
|
+
'nodes',
|
|
3176
|
+
'nodeIdField',
|
|
3177
|
+
'parentIdField',
|
|
3178
|
+
'childrenField',
|
|
3179
|
+
'lazyLoad',
|
|
3180
|
+
'marks',
|
|
3181
|
+
'semanticBands',
|
|
3182
|
+
'distribution',
|
|
3183
|
+
'inlineDistribution',
|
|
3184
|
+
'track',
|
|
3185
|
+
'trueLabel',
|
|
3186
|
+
'falseLabel',
|
|
3187
|
+
'labelTrue',
|
|
3188
|
+
'labelFalse',
|
|
3189
|
+
'iconTrue',
|
|
3190
|
+
'iconFalse',
|
|
3191
|
+
'tone',
|
|
3192
|
+
'toneTrue',
|
|
3193
|
+
'toneFalse',
|
|
3194
|
+
'booleanFormat',
|
|
3195
|
+
'displayFormat',
|
|
3196
|
+
'currency',
|
|
3197
|
+
'currencyCode',
|
|
3198
|
+
'locale',
|
|
3199
|
+
'precision',
|
|
3200
|
+
'decimalPlaces',
|
|
3201
|
+
'initialsField',
|
|
3202
|
+
'optionLabelKey',
|
|
3203
|
+
'optionValueKey',
|
|
3204
|
+
'extraProperties',
|
|
3205
|
+
'rangeMode',
|
|
3206
|
+
'maxRating',
|
|
3207
|
+
'allowHalf',
|
|
3208
|
+
'ratingIcon',
|
|
3209
|
+
'ratingEmptyIcon',
|
|
3210
|
+
'ratingHalfIcon',
|
|
3211
|
+
'ratingTone',
|
|
3212
|
+
'ratingToneColors',
|
|
3213
|
+
'ratingLabels',
|
|
3214
|
+
'distanceUnit',
|
|
3215
|
+
'distanceBaseUnit',
|
|
3216
|
+
'distanceUnits',
|
|
3217
|
+
'distanceAllowUnitToggle',
|
|
3218
|
+
'distanceUnitLabels',
|
|
3219
|
+
'distanceDisplayDecimals',
|
|
3220
|
+
'distanceDecimalsKm',
|
|
3221
|
+
'distanceDecimalsMi',
|
|
3222
|
+
'distancePresets',
|
|
3223
|
+
'distanceSubtitle',
|
|
3224
|
+
'distanceRadialRings',
|
|
3225
|
+
'distanceAccentColor',
|
|
3226
|
+
'distanceRingColor',
|
|
3227
|
+
'distanceTrackColor',
|
|
3228
|
+
'distanceGlowColor',
|
|
3229
|
+
'distanceGradientLowColor',
|
|
3230
|
+
'distanceGradientMidColor',
|
|
3231
|
+
'distanceGradientHighColor',
|
|
3232
|
+
'distanceRangeBandOpacity',
|
|
3233
|
+
'pipelineOptions',
|
|
3234
|
+
'pipelineColors',
|
|
3235
|
+
'pipelineTexts',
|
|
3236
|
+
'scoreBands',
|
|
3237
|
+
'priorityBands',
|
|
3238
|
+
'severityBands',
|
|
3239
|
+
'scorePalette',
|
|
3240
|
+
'scoreTexts',
|
|
3241
|
+
'relativePeriodOptions',
|
|
3242
|
+
'relativePeriodPresets',
|
|
3243
|
+
'relativePeriodTexts',
|
|
3244
|
+
'sentimentOptions',
|
|
3245
|
+
'sentimentPalette',
|
|
3246
|
+
'sentimentTexts',
|
|
3247
|
+
'colorLabelOptions',
|
|
3248
|
+
'colorLabelPalette',
|
|
3249
|
+
'colorLabelTexts',
|
|
3250
|
+
'timeOptions',
|
|
3251
|
+
'inlineTimeQuickPresets',
|
|
3252
|
+
'inlineVisualStyle',
|
|
3253
|
+
'percentPresets',
|
|
3254
|
+
'numberFormat',
|
|
3255
|
+
'valueLabelFormat',
|
|
3256
|
+
'scale',
|
|
3257
|
+
];
|
|
3258
|
+
for (const key of inlinePassThroughKeys) {
|
|
3259
|
+
if (ui[key] !== undefined && field[key] === undefined) {
|
|
3260
|
+
field[key] = ui[key];
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
fields.push(field);
|
|
3264
|
+
}
|
|
3265
|
+
if (fields.length === 0 &&
|
|
3266
|
+
properties['parameters'] &&
|
|
3267
|
+
typeof properties['parameters'] === 'object' &&
|
|
3268
|
+
!Array.isArray(properties['parameters'])) {
|
|
3269
|
+
const parametersProp = properties['parameters'];
|
|
3270
|
+
const resolvedParametersSchema = this.resolveSchemaRef(parametersProp.$ref, rootSchema) ?? parametersProp;
|
|
3271
|
+
if (resolvedParametersSchema &&
|
|
3272
|
+
typeof resolvedParametersSchema === 'object' &&
|
|
3273
|
+
resolvedParametersSchema !== schema &&
|
|
3274
|
+
resolvedParametersSchema.properties &&
|
|
3275
|
+
typeof resolvedParametersSchema.properties === 'object') {
|
|
3276
|
+
return this.normalizeObjectSchema(resolvedParametersSchema, rootSchema);
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3279
|
+
// Order by the optional 'order' property when present
|
|
3280
|
+
fields.sort((a, b) => {
|
|
3281
|
+
const orderA = a.order ?? Number.MAX_SAFE_INTEGER;
|
|
3282
|
+
const orderB = b.order ?? Number.MAX_SAFE_INTEGER;
|
|
3283
|
+
return orderA - orderB;
|
|
3284
|
+
});
|
|
3285
|
+
return fields;
|
|
3286
|
+
}
|
|
3287
|
+
resolveFieldType(prop, ui) {
|
|
3288
|
+
if (ui?.type !== undefined && ui?.type !== null && String(ui.type).trim() !== '') {
|
|
3289
|
+
return String(ui.type);
|
|
3290
|
+
}
|
|
3291
|
+
if (String(ui?.controlType ?? '').trim() === 'array') {
|
|
3292
|
+
return 'array';
|
|
3293
|
+
}
|
|
3294
|
+
if (prop?.type) {
|
|
3295
|
+
return String(prop.type);
|
|
3296
|
+
}
|
|
3297
|
+
const variants = [
|
|
3298
|
+
...(Array.isArray(prop?.oneOf) ? prop.oneOf : []),
|
|
3299
|
+
...(Array.isArray(prop?.anyOf) ? prop.anyOf : []),
|
|
3300
|
+
].filter((variant) => variant && typeof variant === 'object');
|
|
3301
|
+
const nonNullTypes = Array.from(new Set(variants
|
|
3302
|
+
.map((variant) => (typeof variant.type === 'string' ? variant.type.trim() : ''))
|
|
3303
|
+
.filter((type) => !!type && type !== 'null')));
|
|
3304
|
+
if (nonNullTypes.length === 1) {
|
|
3305
|
+
return nonNullTypes[0];
|
|
3306
|
+
}
|
|
3307
|
+
// Compatibilidade para schemas de range publicados como oneOf(array|object).
|
|
3308
|
+
const controlToken = String(ui?.controlType || '').trim().toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
3309
|
+
const isRangeControl = [
|
|
3310
|
+
'daterange',
|
|
3311
|
+
'datetimerange',
|
|
3312
|
+
'rangeslider',
|
|
3313
|
+
'pricerange',
|
|
3314
|
+
'inlinerange',
|
|
3315
|
+
'inlinecurrencyrange',
|
|
3316
|
+
'inlinedaterange',
|
|
3317
|
+
'inlineperiodrange',
|
|
3318
|
+
'inlineyearrange',
|
|
3319
|
+
'inlinemonthrange',
|
|
3320
|
+
'inlinetimerange',
|
|
3321
|
+
'inlinedistanceradius',
|
|
3322
|
+
'inlinescorepriority',
|
|
3323
|
+
].includes(controlToken);
|
|
3324
|
+
if (isRangeControl && nonNullTypes.includes('array')) {
|
|
3325
|
+
return 'array';
|
|
3326
|
+
}
|
|
3327
|
+
return undefined;
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
|
|
3331
|
+
/** Normalizes the exact schema/root object using the canonical Core calculation.
|
|
3332
|
+
* The caller must admit source, content and execution before invoking this function:
|
|
3333
|
+
* declared function expressions may execute during field construction.
|
|
3334
|
+
* This performs neither strict JSON parsing nor provenance/schema admission.
|
|
3335
|
+
*/
|
|
3336
|
+
function normalizeSchemaFields(schema) {
|
|
3337
|
+
return new SchemaNormalizationKernel().normalizeSchema(schema);
|
|
3338
|
+
}
|
|
3339
|
+
|
|
3340
|
+
function isObject(value) {
|
|
3341
|
+
return value != null && typeof value === 'object' && !Array.isArray(value);
|
|
3342
|
+
}
|
|
3343
|
+
/**
|
|
3344
|
+
* Deep merge that prefers values from `right` when defined.
|
|
3345
|
+
* - Objects are merged recursively
|
|
3346
|
+
* - Arrays are replaced by `right` when defined
|
|
3347
|
+
* - Primitive `undefined` on right keeps left's value
|
|
3348
|
+
*/
|
|
3349
|
+
function deepMerge(left, right) {
|
|
3350
|
+
if (right === undefined || right === null)
|
|
3351
|
+
return clone(left);
|
|
3352
|
+
if (Array.isArray(left)) {
|
|
3353
|
+
return (Array.isArray(right) ? right : clone(left));
|
|
3354
|
+
}
|
|
3355
|
+
if (!isObject(left) || !isObject(right)) {
|
|
3356
|
+
// Right wins when defined, else left
|
|
3357
|
+
return (right !== undefined ? right : left);
|
|
3358
|
+
}
|
|
3359
|
+
const out = { ...left };
|
|
3360
|
+
for (const key of Object.keys(right)) {
|
|
3361
|
+
const r = right[key];
|
|
3362
|
+
const l = left[key];
|
|
3363
|
+
if (r === undefined)
|
|
3364
|
+
continue; // keep left as-is
|
|
3365
|
+
if (Array.isArray(r)) {
|
|
3366
|
+
out[key] = r.map((v) => clone(v));
|
|
3367
|
+
}
|
|
3368
|
+
else if (isObject(r) && isObject(l)) {
|
|
3369
|
+
out[key] = deepMerge(l, r);
|
|
3370
|
+
}
|
|
3371
|
+
else {
|
|
3372
|
+
out[key] = clone(r);
|
|
3373
|
+
}
|
|
3374
|
+
}
|
|
3375
|
+
return out;
|
|
3376
|
+
}
|
|
3377
|
+
/**
|
|
3378
|
+
* Fill only undefined properties in `target` with values from `defaults`.
|
|
3379
|
+
* - Objects are traversed recursively
|
|
3380
|
+
* - Arrays defaulting replaces when target is undefined/null
|
|
3381
|
+
*/
|
|
3382
|
+
function fillUndefined(target, defaults) {
|
|
3383
|
+
if (defaults === undefined || defaults === null)
|
|
3384
|
+
return clone(target);
|
|
3385
|
+
if (!isObject(target) || !isObject(defaults)) {
|
|
3386
|
+
return (target === undefined || target === null ? defaults : target);
|
|
3387
|
+
}
|
|
3388
|
+
const out = { ...target };
|
|
3389
|
+
for (const key of Object.keys(defaults)) {
|
|
3390
|
+
const d = defaults[key];
|
|
3391
|
+
const t = target[key];
|
|
3392
|
+
if (t === undefined || t === null) {
|
|
3393
|
+
out[key] = clone(d);
|
|
3394
|
+
}
|
|
3395
|
+
else if (isObject(t) && isObject(d)) {
|
|
3396
|
+
out[key] = fillUndefined(t, d);
|
|
3397
|
+
}
|
|
3398
|
+
else {
|
|
3399
|
+
out[key] = t;
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
return out;
|
|
3403
|
+
}
|
|
3404
|
+
function clone(v) {
|
|
3405
|
+
if (v == null || typeof v !== 'object')
|
|
3406
|
+
return v;
|
|
3407
|
+
try {
|
|
3408
|
+
return JSON.parse(JSON.stringify(v));
|
|
3409
|
+
}
|
|
3410
|
+
catch {
|
|
3411
|
+
return v;
|
|
3412
|
+
}
|
|
3413
|
+
}
|
|
3414
|
+
|
|
3415
|
+
function buildBaseColumnFromDef(def) {
|
|
3416
|
+
const type = resolveColumnTypeFromFieldDefinition(def);
|
|
3417
|
+
const format = resolveFormatFromFieldDefinition(def, type);
|
|
3418
|
+
const valueMapping = resolveSchemaValueMappingFromFieldDefinition(def);
|
|
3419
|
+
const renderer = resolveRendererFromFieldDefinition(def);
|
|
3420
|
+
const quickView = resolveQuickViewFromFieldDefinition(def);
|
|
3421
|
+
const isAvatar = renderer?.type === 'avatar';
|
|
3422
|
+
const explicitWidth = firstNonEmptyString(def.width);
|
|
3423
|
+
return {
|
|
3424
|
+
field: def.name,
|
|
3425
|
+
header: def.label || def.name,
|
|
3426
|
+
type,
|
|
3427
|
+
visible: def.tableHidden === true ? false : true,
|
|
3428
|
+
sortable: def.sortable !== false,
|
|
3429
|
+
filterable: def.filterable === true,
|
|
3430
|
+
resizable: true,
|
|
3431
|
+
order: typeof def.order === 'number' ? def.order : undefined,
|
|
3432
|
+
...(explicitWidth ? { width: explicitWidth } : isAvatar ? { width: '56px' } : {}),
|
|
3433
|
+
...(isAvatar ? { align: 'center' } : {}),
|
|
3434
|
+
...(format ? { format } : {}),
|
|
3435
|
+
...(valueMapping ? { valueMapping } : {}),
|
|
3436
|
+
...(renderer ? { renderer } : {}),
|
|
3437
|
+
...(quickView ? { quickView } : {}),
|
|
3438
|
+
};
|
|
3439
|
+
}
|
|
3440
|
+
function applyLocalCustomizations(baseCol, localCol) {
|
|
3441
|
+
// Server-authoritative keys
|
|
3442
|
+
const result = {
|
|
3443
|
+
...baseCol,
|
|
3444
|
+
field: baseCol.field,
|
|
3445
|
+
header: baseCol.header, // label comes from server
|
|
3446
|
+
type: baseCol.type, // type comes from server (authoritative)
|
|
3447
|
+
sortable: baseCol.sortable,
|
|
3448
|
+
};
|
|
3449
|
+
// Merge presentation/customization from local, keeping user's preferences
|
|
3450
|
+
// and only cleaning conflicting ones if server type changed.
|
|
3451
|
+
const typeChanged = localCol.type && baseCol.type && localCol.type !== baseCol.type;
|
|
3452
|
+
result.width = localCol.width ?? baseCol.width;
|
|
3453
|
+
result.visible = localCol.visible ?? baseCol.visible;
|
|
3454
|
+
result.filterable = localCol.filterable ?? baseCol.filterable;
|
|
3455
|
+
result.resizable = localCol.resizable ?? baseCol.resizable;
|
|
3456
|
+
result.sticky = localCol.sticky ?? baseCol.sticky;
|
|
3457
|
+
result.align = localCol.align ?? baseCol.align;
|
|
3458
|
+
result.order = localCol.order ?? baseCol.order;
|
|
3459
|
+
result.sortField = localCol.sortField ?? baseCol.sortField;
|
|
3460
|
+
result.style = localCol.style ?? baseCol.style;
|
|
3461
|
+
result.headerStyle = localCol.headerStyle ?? baseCol.headerStyle;
|
|
3462
|
+
result.cssClass = localCol.cssClass ?? baseCol.cssClass;
|
|
3463
|
+
result.headerCssClass = localCol.headerCssClass ?? baseCol.headerCssClass;
|
|
3464
|
+
const resolvedQuickView = normalizeResourceQuickViewBinding(localCol.quickView) ??
|
|
3465
|
+
normalizeResourceQuickViewBinding(baseCol.quickView);
|
|
3466
|
+
if (resolvedQuickView) {
|
|
3467
|
+
result.quickView = resolvedQuickView;
|
|
3468
|
+
}
|
|
3469
|
+
else {
|
|
3470
|
+
delete result.quickView;
|
|
3471
|
+
}
|
|
3472
|
+
// If server type changed, drop potentially incompatible formatting/renderers.
|
|
3473
|
+
if (!typeChanged) {
|
|
3474
|
+
result.format = localCol.format ?? baseCol.format;
|
|
3475
|
+
result.valueMapping = localCol.valueMapping ?? baseCol.valueMapping;
|
|
3476
|
+
result.renderer = normalizeColumnRendererQuickView(localCol.renderer ?? baseCol.renderer);
|
|
3477
|
+
}
|
|
3478
|
+
else {
|
|
3479
|
+
// Drop local presentation that may be incompatible with the new server type,
|
|
3480
|
+
// but keep canonical server presentation for the resolved type.
|
|
3481
|
+
result.format = baseCol.format;
|
|
3482
|
+
result.valueMapping = baseCol.valueMapping;
|
|
3483
|
+
result.renderer = undefined;
|
|
3484
|
+
}
|
|
3485
|
+
return result;
|
|
3486
|
+
}
|
|
3487
|
+
function reconcileTableConfig(layout, serverDefs) {
|
|
3488
|
+
const local = layout || { columns: [] };
|
|
3489
|
+
const localByField = new Map((local.columns || []).map((c) => [c.field, c]));
|
|
3490
|
+
const baseColumns = serverDefs.map(buildBaseColumnFromDef);
|
|
3491
|
+
const mergedColumns = baseColumns.map((base) => {
|
|
3492
|
+
const localCol = localByField.get(base.field);
|
|
3493
|
+
return localCol ? applyLocalCustomizations(base, localCol) : base;
|
|
3494
|
+
});
|
|
3495
|
+
const serverFields = new Set(serverDefs.map((d) => d.name));
|
|
3496
|
+
const orphans = (local.columns || []).filter((c) => !serverFields.has(c.field));
|
|
3497
|
+
const hiddenOrphans = orphans.map((c) => ({ ...c, visible: false }));
|
|
3498
|
+
const next = {
|
|
3499
|
+
...local,
|
|
3500
|
+
columns: [...mergedColumns, ...hiddenOrphans],
|
|
3501
|
+
meta: {
|
|
3502
|
+
...local.meta,
|
|
3503
|
+
updatedAt: new Date().toISOString(),
|
|
3504
|
+
},
|
|
3505
|
+
};
|
|
3506
|
+
return next;
|
|
3507
|
+
}
|
|
3508
|
+
function resolveColumnTypeFromFieldDefinition(def, fallback) {
|
|
3509
|
+
const semanticType = resolveSemanticColumnTypeFromFieldDefinition(def);
|
|
3510
|
+
if (resolveTextMaskFormatFromFieldDefinition(def) &&
|
|
3511
|
+
shouldUseTextMaskForColumn(def, semanticType)) {
|
|
3512
|
+
return 'string';
|
|
3513
|
+
}
|
|
3514
|
+
if (semanticType)
|
|
3515
|
+
return semanticType;
|
|
3516
|
+
if (fallback)
|
|
3517
|
+
return fallback;
|
|
3518
|
+
return 'string';
|
|
3519
|
+
}
|
|
3520
|
+
function resolveSemanticColumnTypeFromFieldDefinition(def) {
|
|
3521
|
+
const controlType = normalizePresentationToken(def.controlType);
|
|
3522
|
+
const numericFormat = normalizePresentationToken(def.numericFormat ?? def.format);
|
|
3523
|
+
const valuePresentationType = normalizePresentationToken(def.valuePresentation?.type);
|
|
3524
|
+
const dataType = normalizePresentationToken(def.type);
|
|
3525
|
+
if (valuePresentationType === 'currency')
|
|
3526
|
+
return 'currency';
|
|
3527
|
+
if (valuePresentationType === 'percent' || valuePresentationType === 'percentage')
|
|
3528
|
+
return 'percentage';
|
|
3529
|
+
if (valuePresentationType === 'date' || valuePresentationType === 'datetime' || valuePresentationType === 'time')
|
|
3530
|
+
return 'date';
|
|
3531
|
+
if (valuePresentationType === 'boolean')
|
|
3532
|
+
return 'boolean';
|
|
3533
|
+
if (valuePresentationType === 'number')
|
|
3534
|
+
return 'number';
|
|
3535
|
+
if (valuePresentationType === 'string')
|
|
3536
|
+
return 'string';
|
|
3537
|
+
if (numericFormat === 'currency' || controlType === 'currency')
|
|
3538
|
+
return 'currency';
|
|
3539
|
+
if (numericFormat === 'percent' || numericFormat === 'percentage')
|
|
3540
|
+
return 'percentage';
|
|
3541
|
+
if (numericFormat === 'date' || numericFormat === 'datetime')
|
|
3542
|
+
return 'date';
|
|
3543
|
+
if (controlType === 'numerictextbox' || controlType === 'inlinenumber')
|
|
3544
|
+
return 'number';
|
|
3545
|
+
if (controlType === 'checkbox' || controlType === 'toggle' || controlType === 'inlinetoggle')
|
|
3546
|
+
return 'boolean';
|
|
3547
|
+
if (controlType.includes('date') || controlType === 'time' || controlType === 'timepicker')
|
|
3548
|
+
return 'date';
|
|
3549
|
+
if (isColumnType(dataType))
|
|
3550
|
+
return dataType;
|
|
3551
|
+
if (dataType === 'text' || dataType === 'email' || dataType === 'url' || dataType === 'password')
|
|
3552
|
+
return 'string';
|
|
3553
|
+
if (dataType.includes('date') || dataType === 'time')
|
|
3554
|
+
return 'date';
|
|
3555
|
+
if (dataType.includes('bool'))
|
|
3556
|
+
return 'boolean';
|
|
3557
|
+
if (dataType.includes('number') ||
|
|
3558
|
+
dataType.includes('int') ||
|
|
3559
|
+
dataType.includes('decimal') ||
|
|
3560
|
+
dataType.includes('double') ||
|
|
3561
|
+
dataType.includes('float')) {
|
|
3562
|
+
return 'number';
|
|
3563
|
+
}
|
|
3564
|
+
if (isTextualControlType(controlType))
|
|
3565
|
+
return 'string';
|
|
3566
|
+
return undefined;
|
|
3567
|
+
}
|
|
3568
|
+
function shouldUseTextMaskForColumn(def, semanticType) {
|
|
3569
|
+
if (!semanticType || semanticType === 'string')
|
|
3570
|
+
return true;
|
|
3571
|
+
const controlType = normalizePresentationToken(def.controlType);
|
|
3572
|
+
if (isTextualControlType(controlType))
|
|
3573
|
+
return true;
|
|
3574
|
+
if (['date', 'boolean', 'currency', 'percentage', 'custom'].includes(semanticType)) {
|
|
3575
|
+
return false;
|
|
3576
|
+
}
|
|
3577
|
+
const valuePresentationType = normalizePresentationToken(def.valuePresentation?.type);
|
|
3578
|
+
const numericFormat = normalizePresentationToken(def.numericFormat ?? def.format);
|
|
3579
|
+
return !valuePresentationType && !numericFormat;
|
|
3580
|
+
}
|
|
3581
|
+
function resolveTextMaskFormatFromFieldDefinition(def) {
|
|
3582
|
+
return resolveTextMaskFormat(def.mask ??
|
|
3583
|
+
def.displayMask ??
|
|
3584
|
+
def.inputMask ??
|
|
3585
|
+
def.extraProperties?.mask);
|
|
3586
|
+
}
|
|
3587
|
+
function resolveTextMaskFormat(value) {
|
|
3588
|
+
if (typeof value !== 'string')
|
|
3589
|
+
return undefined;
|
|
3590
|
+
const format = value.trim();
|
|
3591
|
+
if (!format)
|
|
3592
|
+
return undefined;
|
|
3593
|
+
const hasMaskTokens = /[0#9Xx]/.test(format);
|
|
3594
|
+
const hasInvalidMaskLetters = /[A-WYZa-wyz]/.test(format);
|
|
3595
|
+
return hasMaskTokens && !hasInvalidMaskLetters ? format : undefined;
|
|
3596
|
+
}
|
|
3597
|
+
function resolveFormatFromFieldDefinition(def, type) {
|
|
3598
|
+
if (type === 'string') {
|
|
3599
|
+
return resolveTextMaskFormatFromFieldDefinition(def);
|
|
3600
|
+
}
|
|
3601
|
+
if (type === 'currency') {
|
|
3602
|
+
return resolveSchemaCurrencyFormatFromFieldDefinition(def);
|
|
3603
|
+
}
|
|
3604
|
+
if (type === 'date') {
|
|
3605
|
+
return (firstNonEmptyString(def.displayFormat) ??
|
|
3606
|
+
firstNonEmptyString(def.extraProperties?.displayFormat));
|
|
3607
|
+
}
|
|
3608
|
+
if (type === 'boolean') {
|
|
3609
|
+
return resolveSchemaBooleanFormatFromFieldDefinition(def);
|
|
3610
|
+
}
|
|
3611
|
+
if (type === 'number') {
|
|
3612
|
+
const schemaDataType = normalizePresentationToken(def.type);
|
|
3613
|
+
const schemaFormat = normalizePresentationToken(def.format);
|
|
3614
|
+
const numericFormat = normalizePresentationToken(def.numericFormat ?? def.extraProperties?.numericFormat);
|
|
3615
|
+
if (schemaDataType === 'integer' ||
|
|
3616
|
+
schemaFormat === 'integer' ||
|
|
3617
|
+
schemaFormat === 'int32' ||
|
|
3618
|
+
schemaFormat === 'int64' ||
|
|
3619
|
+
numericFormat === 'integer' ||
|
|
3620
|
+
numericFormat === 'int32' ||
|
|
3621
|
+
numericFormat === 'int64') {
|
|
3622
|
+
return '1.0-0';
|
|
3623
|
+
}
|
|
3624
|
+
const explicitDecimals = firstFiniteNumber(def.decimalPlaces) ??
|
|
3625
|
+
firstFiniteNumber(def.extraProperties?.decimalPlaces);
|
|
3626
|
+
if (explicitDecimals !== undefined && explicitDecimals >= 0) {
|
|
3627
|
+
const decimals = Math.trunc(explicitDecimals);
|
|
3628
|
+
return `1.${decimals}-${decimals}`;
|
|
3629
|
+
}
|
|
3630
|
+
}
|
|
3631
|
+
return undefined;
|
|
3632
|
+
}
|
|
3633
|
+
function resolveSchemaCurrencyFormatFromFieldDefinition(def) {
|
|
3634
|
+
const currency = firstNonEmptyString(def.currency) ??
|
|
3635
|
+
firstNonEmptyString(def.extraProperties?.currency) ??
|
|
3636
|
+
'BRL';
|
|
3637
|
+
const decimalPlaces = firstFiniteNumber(def.decimalPlaces) ??
|
|
3638
|
+
firstFiniteNumber(def.extraProperties?.decimalPlaces) ??
|
|
3639
|
+
2;
|
|
3640
|
+
return `${currency}|symbol|${decimalPlaces}`;
|
|
3641
|
+
}
|
|
3642
|
+
function resolveSchemaBooleanFormatFromFieldDefinition(def) {
|
|
3643
|
+
const explicit = firstNonEmptyString(def.booleanFormat) ??
|
|
3644
|
+
firstNonEmptyString(def.extraProperties?.booleanFormat);
|
|
3645
|
+
if (explicit)
|
|
3646
|
+
return explicit;
|
|
3647
|
+
const trueLabel = firstNonEmptyString(def.trueLabel) ??
|
|
3648
|
+
firstNonEmptyString(def.labelTrue) ??
|
|
3649
|
+
firstNonEmptyString(def.extraProperties?.trueLabel) ??
|
|
3650
|
+
firstNonEmptyString(def.extraProperties?.labelTrue);
|
|
3651
|
+
const falseLabel = firstNonEmptyString(def.falseLabel) ??
|
|
3652
|
+
firstNonEmptyString(def.labelFalse) ??
|
|
3653
|
+
firstNonEmptyString(def.extraProperties?.falseLabel) ??
|
|
3654
|
+
firstNonEmptyString(def.extraProperties?.labelFalse);
|
|
3655
|
+
if (trueLabel && falseLabel) {
|
|
3656
|
+
const tNorm = normalizePresentationToken(trueLabel);
|
|
3657
|
+
const fNorm = normalizePresentationToken(falseLabel);
|
|
3658
|
+
if (tNorm === 'ativo' && fNorm === 'inativo')
|
|
3659
|
+
return 'active-inactive';
|
|
3660
|
+
if (tNorm === 'sim' && (fNorm === 'nao' || fNorm === 'não'))
|
|
3661
|
+
return 'yes-no';
|
|
3662
|
+
return `custom|${trueLabel}|${falseLabel}`;
|
|
3663
|
+
}
|
|
3664
|
+
const name = normalizePresentationToken(def.name);
|
|
3665
|
+
if (name === 'ativo' || name === 'active' || name.endsWith('ativo')) {
|
|
3666
|
+
return 'active-inactive';
|
|
3667
|
+
}
|
|
3668
|
+
return undefined;
|
|
3669
|
+
}
|
|
3670
|
+
function resolveSchemaValueMappingFromFieldDefinition(def) {
|
|
3671
|
+
const explicit = def.valueMapping;
|
|
3672
|
+
if (explicit && typeof explicit === 'object' && !Array.isArray(explicit)) {
|
|
3673
|
+
const normalized = Object.entries(explicit).reduce((acc, [key, value]) => {
|
|
3674
|
+
if (key && typeof value === 'string' && value.trim()) {
|
|
3675
|
+
acc[key] = value.trim();
|
|
3676
|
+
}
|
|
3677
|
+
return acc;
|
|
3678
|
+
}, {});
|
|
3679
|
+
if (Object.keys(normalized).length > 0)
|
|
3680
|
+
return normalized;
|
|
3681
|
+
}
|
|
3682
|
+
const options = Array.isArray(def.options) ? def.options : [];
|
|
3683
|
+
if (options.length > 0) {
|
|
3684
|
+
const valueKey = firstNonEmptyString(def.optionValueKey) ?? 'key';
|
|
3685
|
+
const labelKey = firstNonEmptyString(def.optionLabelKey) ?? 'value';
|
|
3686
|
+
const mapping = options.reduce((acc, option) => {
|
|
3687
|
+
if (!option || typeof option !== 'object')
|
|
3688
|
+
return acc;
|
|
3689
|
+
const record = option;
|
|
3690
|
+
const value = record[valueKey] ?? record.key ?? record.id ?? record.value;
|
|
3691
|
+
const label = record[labelKey] ?? record.label ?? record.value ?? record.name;
|
|
3692
|
+
if (value !== undefined && value !== null && label !== undefined && label !== null) {
|
|
3693
|
+
acc[String(value)] = String(label);
|
|
3694
|
+
}
|
|
3695
|
+
return acc;
|
|
3696
|
+
}, {});
|
|
3697
|
+
if (Object.keys(mapping).length > 0)
|
|
3698
|
+
return mapping;
|
|
3699
|
+
}
|
|
3700
|
+
const enumValues = Array.isArray(def.enumValues)
|
|
3701
|
+
? def.enumValues
|
|
3702
|
+
.map((v) => (v != null ? String(v).trim() : ''))
|
|
3703
|
+
.filter((v) => v.length > 0)
|
|
3704
|
+
: [];
|
|
3705
|
+
if (enumValues.length > 0) {
|
|
3706
|
+
return enumValues.reduce((acc, value) => {
|
|
3707
|
+
acc[value] = humanizeSchemaEnumValue(value);
|
|
3708
|
+
return acc;
|
|
3709
|
+
}, {});
|
|
3710
|
+
}
|
|
3711
|
+
return undefined;
|
|
3712
|
+
}
|
|
3713
|
+
function humanizeSchemaEnumValue(value) {
|
|
3714
|
+
return value
|
|
3715
|
+
.toLowerCase()
|
|
3716
|
+
.split(/[_\-\s]+/)
|
|
3717
|
+
.filter(Boolean)
|
|
3718
|
+
.map((part, index) => (index === 0 ? `${part.charAt(0).toUpperCase()}${part.slice(1)}` : part))
|
|
3719
|
+
.join(' ');
|
|
3720
|
+
}
|
|
3721
|
+
function resolveQuickViewFromFieldDefinition(def) {
|
|
3722
|
+
return (normalizeResourceQuickViewBinding(def.quickView) ??
|
|
3723
|
+
normalizeResourceQuickViewBinding(def.presentation?.interactions?.quickView) ??
|
|
3724
|
+
normalizeResourceQuickViewBinding(def['extraProperties'] && typeof def['extraProperties'] === 'object' ? def['extraProperties']['quickView'] : undefined) ??
|
|
3725
|
+
undefined);
|
|
3726
|
+
}
|
|
3727
|
+
function normalizeColumnRendererQuickView(renderer) {
|
|
3728
|
+
if (!renderer || typeof renderer !== 'object') {
|
|
3729
|
+
return renderer;
|
|
3730
|
+
}
|
|
3731
|
+
const next = { ...renderer };
|
|
3732
|
+
if (next.link && typeof next.link === 'object') {
|
|
3733
|
+
const qv = normalizeResourceQuickViewBinding(next.link.quickView);
|
|
3734
|
+
next.link = { ...next.link };
|
|
3735
|
+
if (qv) {
|
|
3736
|
+
next.link.quickView = qv;
|
|
3737
|
+
}
|
|
3738
|
+
else {
|
|
3739
|
+
delete next.link.quickView;
|
|
3740
|
+
}
|
|
3741
|
+
}
|
|
3742
|
+
if (next.badge && typeof next.badge === 'object') {
|
|
3743
|
+
const qv = normalizeResourceQuickViewBinding(next.badge.quickView);
|
|
3744
|
+
next.badge = { ...next.badge };
|
|
3745
|
+
if (qv) {
|
|
3746
|
+
next.badge.quickView = qv;
|
|
3747
|
+
}
|
|
3748
|
+
else {
|
|
3749
|
+
delete next.badge.quickView;
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
if (next.chip && typeof next.chip === 'object') {
|
|
3753
|
+
const qv = normalizeResourceQuickViewBinding(next.chip.quickView);
|
|
3754
|
+
next.chip = { ...next.chip };
|
|
3755
|
+
if (qv) {
|
|
3756
|
+
next.chip.quickView = qv;
|
|
3757
|
+
}
|
|
3758
|
+
else {
|
|
3759
|
+
delete next.chip.quickView;
|
|
3760
|
+
}
|
|
3761
|
+
}
|
|
3762
|
+
if (next.icon && typeof next.icon === 'object') {
|
|
3763
|
+
const qv = normalizeResourceQuickViewBinding(next.icon.quickView);
|
|
3764
|
+
next.icon = { ...next.icon };
|
|
3765
|
+
if (qv) {
|
|
3766
|
+
next.icon.quickView = qv;
|
|
3767
|
+
}
|
|
3768
|
+
else {
|
|
3769
|
+
delete next.icon.quickView;
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
if (next.compose && typeof next.compose === 'object' && Array.isArray(next.compose.items)) {
|
|
3773
|
+
next.compose = {
|
|
3774
|
+
...next.compose,
|
|
3775
|
+
items: next.compose.items.map((item) => {
|
|
3776
|
+
if (!item || typeof item !== 'object')
|
|
3777
|
+
return item;
|
|
3778
|
+
if (item.type === 'value') {
|
|
3779
|
+
const qv = normalizeResourceQuickViewBinding(item.quickView);
|
|
3780
|
+
const cloned = { ...item };
|
|
3781
|
+
if (qv)
|
|
3782
|
+
cloned.quickView = qv;
|
|
3783
|
+
else
|
|
3784
|
+
delete cloned.quickView;
|
|
3785
|
+
return cloned;
|
|
3786
|
+
}
|
|
3787
|
+
if (item.type === 'link' && item.link) {
|
|
3788
|
+
const qv = normalizeResourceQuickViewBinding(item.link.quickView);
|
|
3789
|
+
const link = { ...item.link };
|
|
3790
|
+
if (qv)
|
|
3791
|
+
link.quickView = qv;
|
|
3792
|
+
else
|
|
3793
|
+
delete link.quickView;
|
|
3794
|
+
return { ...item, link };
|
|
3795
|
+
}
|
|
3796
|
+
if (item.type === 'badge' && item.badge) {
|
|
3797
|
+
const qv = normalizeResourceQuickViewBinding(item.badge.quickView);
|
|
3798
|
+
const badge = { ...item.badge };
|
|
3799
|
+
if (qv)
|
|
3800
|
+
badge.quickView = qv;
|
|
3801
|
+
else
|
|
3802
|
+
delete badge.quickView;
|
|
3803
|
+
return { ...item, badge };
|
|
3804
|
+
}
|
|
3805
|
+
if (item.type === 'chip' && item.chip) {
|
|
3806
|
+
const qv = normalizeResourceQuickViewBinding(item.chip.quickView);
|
|
3807
|
+
const chip = { ...item.chip };
|
|
3808
|
+
if (qv)
|
|
3809
|
+
chip.quickView = qv;
|
|
3810
|
+
else
|
|
3811
|
+
delete chip.quickView;
|
|
3812
|
+
return { ...item, chip };
|
|
3813
|
+
}
|
|
3814
|
+
if (item.type === 'icon' && item.icon) {
|
|
3815
|
+
const qv = normalizeResourceQuickViewBinding(item.icon.quickView);
|
|
3816
|
+
const icon = { ...item.icon };
|
|
3817
|
+
if (qv)
|
|
3818
|
+
icon.quickView = qv;
|
|
3819
|
+
else
|
|
3820
|
+
delete icon.quickView;
|
|
3821
|
+
return { ...item, icon };
|
|
3822
|
+
}
|
|
3823
|
+
return item;
|
|
3824
|
+
}),
|
|
3825
|
+
};
|
|
3826
|
+
}
|
|
3827
|
+
return next;
|
|
3828
|
+
}
|
|
3829
|
+
function resolveRendererFromFieldDefinition(def) {
|
|
3830
|
+
const presentationRenderer = resolveRendererFromFieldPresentation(def);
|
|
3831
|
+
if (presentationRenderer)
|
|
3832
|
+
return presentationRenderer;
|
|
3833
|
+
if (normalizePresentationToken(def.controlType) === 'avatar') {
|
|
3834
|
+
const initialsField = firstNonEmptyString(def.initialsField) ??
|
|
3835
|
+
firstNonEmptyString(def.extraProperties?.initialsField) ??
|
|
3836
|
+
'nomeCompleto';
|
|
3837
|
+
return {
|
|
3838
|
+
type: 'avatar',
|
|
3839
|
+
avatar: {
|
|
3840
|
+
srcField: def.name,
|
|
3841
|
+
initialsField,
|
|
3842
|
+
shape: 'circle',
|
|
3843
|
+
size: 32,
|
|
3844
|
+
},
|
|
3845
|
+
};
|
|
3846
|
+
}
|
|
3847
|
+
return undefined;
|
|
3848
|
+
}
|
|
3849
|
+
function resolveRendererFromFieldPresentation(def) {
|
|
3850
|
+
const presentation = def.presentation;
|
|
3851
|
+
if (!presentation || typeof presentation !== 'object')
|
|
3852
|
+
return undefined;
|
|
3853
|
+
if (presentation.presenter === 'microVisualization' &&
|
|
3854
|
+
isPraxisPresentationVisualizationTableSafe(presentation.visualization)) {
|
|
3855
|
+
return {
|
|
3856
|
+
type: 'microVisualization',
|
|
3857
|
+
microVisualization: {
|
|
3858
|
+
visualization: presentation.visualization,
|
|
3859
|
+
},
|
|
3860
|
+
};
|
|
3861
|
+
}
|
|
3862
|
+
const presenter = normalizePresentationToken(presentation.presenter ?? presentation.variant);
|
|
3863
|
+
const color = resolveSemanticPresentationColor(presentation.tone);
|
|
3864
|
+
const variant = resolveSemanticPresentationVariant(presentation.appearance);
|
|
3865
|
+
const icon = firstNonEmptyString(presentation.icon);
|
|
3866
|
+
const tooltipText = firstNonEmptyString(presentation.tooltip);
|
|
3867
|
+
const tooltip = tooltipText ? { text: tooltipText } : undefined;
|
|
3868
|
+
const fixedText = firstNonEmptyString(presentation.label);
|
|
3869
|
+
if (presenter === 'chip') {
|
|
3870
|
+
return {
|
|
3871
|
+
type: 'chip',
|
|
3872
|
+
chip: {
|
|
3873
|
+
...(fixedText ? { text: fixedText } : { textField: def.name }),
|
|
3874
|
+
...(color ? { color } : {}),
|
|
3875
|
+
...(variant ? { variant } : {}),
|
|
3876
|
+
...(icon ? { icon } : {}),
|
|
3877
|
+
...(tooltip ? { tooltip } : {}),
|
|
3878
|
+
},
|
|
3879
|
+
};
|
|
3880
|
+
}
|
|
3881
|
+
if (presenter === 'badge' || presenter === 'status') {
|
|
3882
|
+
return {
|
|
3883
|
+
type: 'badge',
|
|
3884
|
+
badge: {
|
|
3885
|
+
...(fixedText ? { text: fixedText } : { textField: def.name }),
|
|
3886
|
+
...(color ? { color } : {}),
|
|
3887
|
+
...(variant ? { variant } : {}),
|
|
3888
|
+
...(icon ? { icon } : {}),
|
|
3889
|
+
...(tooltip ? { tooltip } : {}),
|
|
3890
|
+
},
|
|
3891
|
+
};
|
|
3892
|
+
}
|
|
3893
|
+
if (presenter === 'iconvalue') {
|
|
3894
|
+
const rendererIcon = icon || firstNonEmptyString(def.icon);
|
|
3895
|
+
const affixes = resolveSemanticPresentationAffixes(presentation);
|
|
3896
|
+
const hasAffixes = !!(affixes.prefix || affixes.suffix);
|
|
3897
|
+
if (!rendererIcon && !hasAffixes)
|
|
3898
|
+
return undefined;
|
|
3899
|
+
if (affixes.prefix || affixes.suffix || tooltipText) {
|
|
3900
|
+
return {
|
|
3901
|
+
type: 'icon',
|
|
3902
|
+
icon: {
|
|
3903
|
+
...(!hasAffixes && rendererIcon ? { name: rendererIcon } : {}),
|
|
3904
|
+
textField: def.name,
|
|
3905
|
+
...(tooltipText ? { ariaLabel: tooltipText } : {}),
|
|
3906
|
+
...affixes,
|
|
3907
|
+
},
|
|
3908
|
+
};
|
|
3909
|
+
}
|
|
3910
|
+
if (!rendererIcon)
|
|
3911
|
+
return undefined;
|
|
3912
|
+
return {
|
|
3913
|
+
type: 'compose',
|
|
3914
|
+
compose: {
|
|
3915
|
+
items: [
|
|
3916
|
+
{
|
|
3917
|
+
type: 'icon',
|
|
3918
|
+
icon: {
|
|
3919
|
+
name: rendererIcon,
|
|
3920
|
+
...(color ? { color } : {}),
|
|
3921
|
+
...(def.label ? { ariaLabel: def.label } : {}),
|
|
3922
|
+
},
|
|
3923
|
+
},
|
|
3924
|
+
{
|
|
3925
|
+
type: 'value',
|
|
3926
|
+
field: def.name,
|
|
3927
|
+
},
|
|
3928
|
+
],
|
|
3929
|
+
layout: {
|
|
3930
|
+
direction: 'row',
|
|
3931
|
+
gap: 6,
|
|
3932
|
+
align: 'center',
|
|
3933
|
+
},
|
|
3934
|
+
},
|
|
3935
|
+
};
|
|
3936
|
+
}
|
|
3937
|
+
return undefined;
|
|
3938
|
+
}
|
|
3939
|
+
function resolveSemanticPresentationColor(tone) {
|
|
3940
|
+
const normalized = normalizePresentationToken(tone);
|
|
3941
|
+
if (normalized === 'neutral')
|
|
3942
|
+
return 'basic';
|
|
3943
|
+
if (!normalized)
|
|
3944
|
+
return undefined;
|
|
3945
|
+
if (normalized === 'danger' || normalized === 'warning')
|
|
3946
|
+
return 'warn';
|
|
3947
|
+
return normalized;
|
|
3948
|
+
}
|
|
3949
|
+
function resolveSemanticPresentationVariant(appearance) {
|
|
3950
|
+
const normalized = normalizePresentationToken(appearance);
|
|
3951
|
+
return normalized === 'filled' ||
|
|
3952
|
+
normalized === 'outlined' ||
|
|
3953
|
+
normalized === 'soft' ||
|
|
3954
|
+
normalized === 'plain'
|
|
3955
|
+
? normalized
|
|
3956
|
+
: undefined;
|
|
3957
|
+
}
|
|
3958
|
+
function resolveSemanticPresentationAffixes(presentation) {
|
|
3959
|
+
const prefix = firstNonEmptyString(presentation.prefix);
|
|
3960
|
+
const suffix = firstNonEmptyString(presentation.suffix);
|
|
3961
|
+
return {
|
|
3962
|
+
...(prefix ? { prefix } : {}),
|
|
3963
|
+
...(suffix ? { suffix } : {}),
|
|
3964
|
+
};
|
|
3965
|
+
}
|
|
3966
|
+
function firstNonEmptyString(value) {
|
|
3967
|
+
if (typeof value !== 'string')
|
|
3968
|
+
return undefined;
|
|
3969
|
+
const trimmed = value.trim();
|
|
3970
|
+
return trimmed ? trimmed : undefined;
|
|
3971
|
+
}
|
|
3972
|
+
function firstFiniteNumber(value) {
|
|
3973
|
+
if (value === null || value === undefined || value === '')
|
|
3974
|
+
return undefined;
|
|
3975
|
+
const numeric = typeof value === 'number' ? value : Number(value);
|
|
3976
|
+
return Number.isFinite(numeric) ? numeric : undefined;
|
|
3977
|
+
}
|
|
3978
|
+
function normalizePresentationToken(value) {
|
|
3979
|
+
return String(value ?? '').trim().toLowerCase().replace(/[\s_-]+/g, '');
|
|
3980
|
+
}
|
|
3981
|
+
function isColumnType(value) {
|
|
3982
|
+
return [
|
|
3983
|
+
'string',
|
|
3984
|
+
'number',
|
|
3985
|
+
'date',
|
|
3986
|
+
'boolean',
|
|
3987
|
+
'currency',
|
|
3988
|
+
'percentage',
|
|
3989
|
+
'custom',
|
|
3990
|
+
].includes(value);
|
|
3991
|
+
}
|
|
3992
|
+
function isTextualControlType(value) {
|
|
3993
|
+
return [
|
|
3994
|
+
'input',
|
|
3995
|
+
'inlineinput',
|
|
3996
|
+
'textarea',
|
|
3997
|
+
'search',
|
|
3998
|
+
'email',
|
|
3999
|
+
'url',
|
|
4000
|
+
'phone',
|
|
4001
|
+
'cpfcnpjinput',
|
|
4002
|
+
'password',
|
|
4003
|
+
].includes(value);
|
|
4004
|
+
}
|
|
4005
|
+
|
|
4006
|
+
/** Owner-only schema calculation surface; admission must precede executable metadata. */
|
|
4007
|
+
|
|
4008
|
+
/**
|
|
4009
|
+
* Generated bundle index. Do not edit.
|
|
4010
|
+
*/
|
|
4011
|
+
|
|
4012
|
+
export { deepMerge, isPraxisPresentationVisualizationTableSafe, normalizeSchemaFields, resolveColumnTypeFromFieldDefinition, resolveTextMaskFormatFromFieldDefinition };
|