@praxisui/table 10.0.0-rc.7 → 10.0.0-rc.71

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.
Files changed (22) hide show
  1. package/README.md +157 -12
  2. package/ai/component-registry.json +4420 -354
  3. package/docs/adr/2026-07-table-rich-cells-governance.md +5 -4
  4. package/docs/column-resize-reorder-implementation-plan.md +3 -3
  5. package/docs/column-resize-reorder-review-prompt.md +1 -1
  6. package/docs/dynamic-filter-host-integration-guide.md +49 -2
  7. package/docs/dynamic-filter-payload-contract.md +29 -6
  8. package/docs/dynamic-filter-range-filters-guide.md +125 -13
  9. package/docs/governed-page-widget-adapter.md +55 -0
  10. package/docs/local-data-mode-precedence.md +21 -0
  11. package/docs/performance-hardening-v2-implementation-plan.md +20 -20
  12. package/docs/table-bottom-detail-progress.md +2 -2
  13. package/fesm2022/praxisui-table-authoring.mjs +848 -161
  14. package/fesm2022/{praxisui-table-filter-form-dialog-host.component-DANYIQs6.mjs → praxisui-table-filter-form-dialog-host.component-CmqK_WBK.mjs} +61 -11
  15. package/fesm2022/{praxisui-table-praxisui-table-BIRFv2S8.mjs → praxisui-table-praxisui-table-BFyjUHDv.mjs} +22144 -2775
  16. package/fesm2022/{praxisui-table-table-agentic-authoring-turn-flow-DtOwXgFW.mjs → praxisui-table-table-agentic-authoring-turn-flow-CxAJUZzG.mjs} +2 -2
  17. package/fesm2022/{praxisui-table-table-ai.adapter-25xtoiWq.mjs → praxisui-table-table-ai.adapter-DG81dbBu.mjs} +13 -7
  18. package/fesm2022/praxisui-table.mjs +1 -1
  19. package/package.json +10 -10
  20. package/src/lib/praxis-table.json-api.md +58 -18
  21. package/types/praxisui-table-authoring.d.ts +30 -2
  22. package/types/praxisui-table.d.ts +1223 -129
@@ -1,10 +1,12 @@
1
+ import { normalizePraxisResourcePath, uiLayoutJsonIdentity, cloneBoundedUiLayoutJsonDocument, derivePageChildRuntimeId } from '@praxisui/core';
1
2
  import { validateRichContentDocument, isSafeRichContentClassName } from '@praxisui/rich-content';
2
- import { resolveColumnTypeFromFieldDefinition, deepMerge, isPraxisPresentationVisualizationTableSafe, resolveTextMaskFormatFromFieldDefinition } from '@praxisui/core/schema';
3
+ import { resolveColumnTypeFromFieldDefinition, deepMerge, isPraxisPresentationVisualizationTableSafe, resolveTextMaskFormatFromFieldDefinition, buildSchemaSemanticColumnRenderer, resolveSchemaConditionalRenderers } from '@praxisui/core/schema';
3
4
 
4
5
  const ORIGIN = '__praxisAuthoredDisabled';
5
- const hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
6
+ const hasOwn$1 = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
6
7
  const isAction = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
7
8
  const hasRuntimeState = (action) => Object.keys(action).some(key => key.startsWith('__praxis'));
9
+ const isRuntimeDiscoveredOnly = (action) => Boolean(action['__praxisDiscoveredAction']) || Boolean(action['__praxisBulkSyncAction']);
8
10
  function authoredDisabled(action) {
9
11
  const origin = action[ORIGIN];
10
12
  if (isAction(origin) && typeof origin['present'] === 'boolean'
@@ -32,18 +34,30 @@ function identity(action) {
32
34
  }
33
35
  /** Projects only canonical action slots, never arbitrary business payloads or callback values. */
34
36
  function projectTableActionAuthoring(config, authored, report) {
37
+ const hasAuthoredBaseline = authored !== undefined && authored !== null;
35
38
  function actions(value, original, path) {
36
39
  if (!Array.isArray(value))
37
40
  return value;
38
- const originals = Array.isArray(original) ? original.filter(isAction) : [];
39
- return value.map((item, index) => {
40
- if (!isAction(item))
41
- return item;
41
+ const originals = Array.isArray(original)
42
+ ? original.filter((candidate) => isAction(candidate) && !isRuntimeDiscoveredOnly(candidate))
43
+ : [];
44
+ const projected = [];
45
+ value.forEach((item, index) => {
46
+ if (!isAction(item)) {
47
+ projected.push(item);
48
+ return;
49
+ }
42
50
  const key = identity(item);
43
51
  const matches = key ? originals.filter(candidate => identity(candidate) === key) : [];
44
52
  // No label matching, positional matching or guessing across duplicate identities.
45
53
  const source = matches.length === 1 && value.filter(candidate => isAction(candidate) && identity(candidate) === key).length === 1
46
54
  ? matches[0] : undefined;
55
+ const isRuntimeSynthesizedOnly = Boolean(item['__praxisDiscoveredAction']) ||
56
+ Boolean(item['__praxisBulkSyncAction']) ||
57
+ (hasAuthoredBaseline && Boolean(item['__praxisCollectionCreateAction']));
58
+ if (isRuntimeSynthesizedOnly && !source) {
59
+ return;
60
+ }
47
61
  const result = { ...item };
48
62
  if (hasRuntimeState(item)) {
49
63
  const origin = source && !hasRuntimeState(source) ? authoredDisabled(source) : authoredDisabled(item);
@@ -61,16 +75,17 @@ function projectTableActionAuthoring(config, authored, report) {
61
75
  if (name.startsWith('__praxis'))
62
76
  delete result[name];
63
77
  }
64
- if (hasOwn(item, 'children'))
78
+ if (hasOwn$1(item, 'children'))
65
79
  result['children'] = actions(item['children'], source?.['children'], `${path}[${index}].children`);
66
- return result;
80
+ projected.push(result);
67
81
  });
82
+ return projected;
68
83
  }
69
84
  const result = { ...config };
70
85
  if (config?.toolbar)
71
86
  result.toolbar = {
72
87
  ...config.toolbar,
73
- ...(hasOwn(config.toolbar, 'actions') ? { actions: actions(config.toolbar.actions, authored?.toolbar?.actions, 'config.toolbar.actions') } : {}),
88
+ ...(hasOwn$1(config.toolbar, 'actions') ? { actions: actions(config.toolbar.actions, authored?.toolbar?.actions, 'config.toolbar.actions') } : {}),
74
89
  };
75
90
  if (config?.actions) {
76
91
  result.actions = { ...config.actions };
@@ -79,7 +94,7 @@ function projectTableActionAuthoring(config, authored, report) {
79
94
  if (group)
80
95
  result.actions[slot] = {
81
96
  ...group,
82
- ...(hasOwn(group, 'actions') ? { actions: actions(group.actions, authored?.actions?.[slot]?.actions, `config.actions.${slot}.actions`) } : {}),
97
+ ...(hasOwn$1(group, 'actions') ? { actions: actions(group.actions, authored?.actions?.[slot]?.actions, `config.actions.${slot}.actions`) } : {}),
83
98
  };
84
99
  }
85
100
  }
@@ -295,7 +310,7 @@ function tableDetailAuthoringIssues(config) {
295
310
  || (detail.presentation?.initiallyCollapsed !== undefined && typeof detail.presentation.initiallyCollapsed !== 'boolean')
296
311
  || (detail.presentation?.bottomStackPosition !== undefined && !['beforeControls', 'afterControls'].includes(detail.presentation.bottomStackPosition))
297
312
  || (detail.presentation?.emptyBehavior !== undefined && !['message', 'hide'].includes(detail.presentation.emptyBehavior))
298
- || (detail.source?.mode !== undefined && !['inline', 'resource', 'resourcePath', 'hypermedia'].includes(detail.source.mode))
313
+ || (detail.source?.mode !== undefined && !['inline', 'resource', 'resourcePath', 'hypermedia', 'schema'].includes(detail.source.mode))
299
314
  || (detail.source?.inlineSchema !== undefined && !isObject(detail.source.inlineSchema))
300
315
  || (detail.source?.inlineSchema?.items !== undefined && !Array.isArray(detail.source.inlineSchema.items))
301
316
  || (resource !== undefined && !isObject(resource))
@@ -389,8 +404,197 @@ function inspectInlineDetailSchema(schema, config) {
389
404
  Object.values(node).forEach(visit);
390
405
  };
391
406
  visit(schema);
407
+ const offContract = hasOffContractRichChildren([schema]);
408
+ if (offContract.cardGrid)
409
+ issues.push('cardGridContent');
410
+ if (offContract.compose)
411
+ issues.push('composeContent');
392
412
  return issues;
393
413
  }
414
+ /** Rich node types accepted as `cardGrid` card content by the canonical `TableDetailCardGridCardNode` contract. */
415
+ const TABLE_DETAIL_CARD_GRID_PRESENTER_TYPES = new Set([
416
+ 'text', 'icon', 'image', 'badge', 'avatar', 'metric', 'progress', 'progressBar',
417
+ 'microVisualization', 'link', 'chip', 'button', 'rating',
418
+ ]);
419
+ /** `RichComposeNode.items` accepts presenters only (no nested compose). */
420
+ function isTableDetailComposeItemNode(node) {
421
+ if (!node || typeof node !== 'object' || Array.isArray(node))
422
+ return false;
423
+ return TABLE_DETAIL_CARD_GRID_PRESENTER_TYPES.has(String(node['type'] || '').trim());
424
+ }
425
+ function isTableDetailCardGridContentNode(node) {
426
+ if (!node || typeof node !== 'object' || Array.isArray(node))
427
+ return false;
428
+ const type = String(node['type'] || '').trim();
429
+ return type === 'compose' || TABLE_DETAIL_CARD_GRID_PRESENTER_TYPES.has(type);
430
+ }
431
+ /**
432
+ * Projects an authored node into canonical `cardGrid` card content (`RichPresenterNode | RichComposeNode`).
433
+ * Table-detail `value` fields become `metric` (labelled) or `text` presenters; structural blocks that
434
+ * cannot live inside a rich card (stack, tabs, card, timeline, chartRef, richContent) return `null`.
435
+ */
436
+ function toTableDetailCardGridContentNode(node) {
437
+ if (isTableDetailCardGridContentNode(node))
438
+ return node;
439
+ const type = String(node?.['type'] || '').trim();
440
+ if (type === 'cardGrid') {
441
+ const firstCard = Array.isArray(node['cards']) ? node['cards'][0] : undefined;
442
+ const firstList = Array.isArray(firstCard?.content)
443
+ ? firstCard.content
444
+ : Array.isArray(firstCard?.items)
445
+ ? firstCard.items
446
+ : undefined;
447
+ const first = firstList?.[0];
448
+ return first ? toTableDetailCardGridContentNode(structuredClone(first)) : null;
449
+ }
450
+ if (type !== 'value')
451
+ return null;
452
+ const field = String(node['field'] || node['valueField'] || '').trim();
453
+ const authoredExpr = typeof node['valueExpr'] === 'string' ? node['valueExpr'].trim().replace(/^=\s*/, '') : '';
454
+ const valueExpr = authoredExpr || (field ? `row.${field}` : '');
455
+ const label = typeof node['label'] === 'string' && node['label'].trim()
456
+ ? node['label'].trim()
457
+ : typeof node['title'] === 'string' && node['title'].trim()
458
+ ? node['title'].trim()
459
+ : '';
460
+ if (valueExpr) {
461
+ return {
462
+ ...(node['id'] ? { id: node['id'] } : {}),
463
+ ...(label ? { type: 'metric', label, valueExpr } : { type: 'text', textExpr: valueExpr }),
464
+ ...(node['visibleWhen'] !== undefined && node['visibleWhen'] !== null ? { visibleWhen: node['visibleWhen'] } : {}),
465
+ };
466
+ }
467
+ if (Object.prototype.hasOwnProperty.call(node, 'value') && node['value'] !== undefined && node['value'] !== null) {
468
+ const literalText = String(node['value']);
469
+ if (label) {
470
+ return {
471
+ type: 'compose',
472
+ ...(node['id'] ? { id: node['id'] } : {}),
473
+ className: 'pfx-expansion-node pfx-expansion-node-value',
474
+ direction: 'column',
475
+ gap: 'xs',
476
+ items: [
477
+ { type: 'text', className: 'pfx-expansion-node-value__label', text: label },
478
+ { type: 'text', className: 'pfx-expansion-node-value__content', text: literalText },
479
+ ],
480
+ ...(node['visibleWhen'] !== undefined && node['visibleWhen'] !== null ? { visibleWhen: node['visibleWhen'] } : {}),
481
+ };
482
+ }
483
+ return {
484
+ type: 'text',
485
+ ...(node['id'] ? { id: node['id'] } : {}),
486
+ text: literalText,
487
+ ...(node['visibleWhen'] !== undefined && node['visibleWhen'] !== null ? { visibleWhen: node['visibleWhen'] } : {}),
488
+ };
489
+ }
490
+ return null;
491
+ }
492
+ /** Projects an authored node into a canonical compose item (presenter); a compose result yields its first presenter. */
493
+ function toTableDetailComposeItemNode(node) {
494
+ if (node &&
495
+ typeof node === 'object' &&
496
+ node['type'] === 'value' &&
497
+ !node['field'] &&
498
+ !node['valueField'] &&
499
+ !node['valueExpr'] &&
500
+ Object.prototype.hasOwnProperty.call(node, 'value') &&
501
+ node['value'] !== undefined &&
502
+ node['value'] !== null) {
503
+ const label = typeof node['label'] === 'string' && node['label'].trim()
504
+ ? node['label'].trim()
505
+ : typeof node['title'] === 'string' && node['title'].trim()
506
+ ? node['title'].trim()
507
+ : '';
508
+ return {
509
+ type: 'text',
510
+ ...(node['id'] ? { id: node['id'] } : {}),
511
+ text: label ? `${label}: ${String(node['value'])}` : String(node['value']),
512
+ ...(node['visibleWhen'] !== undefined && node['visibleWhen'] !== null ? { visibleWhen: node['visibleWhen'] } : {}),
513
+ };
514
+ }
515
+ const projected = toTableDetailCardGridContentNode(node);
516
+ if (!projected)
517
+ return null;
518
+ if (projected['type'] !== 'compose')
519
+ return projected;
520
+ const first = Array.isArray(projected['items'])
521
+ ? projected['items'].find((item) => isTableDetailComposeItemNode(item))
522
+ : undefined;
523
+ return first ? structuredClone(first) : null;
524
+ }
525
+ /** True when a cardGrid card or a compose (outside richContent documents) holds off-contract children. */
526
+ function hasOffContractRichChildren(nodes) {
527
+ const result = { cardGrid: false, compose: false };
528
+ const visit = (value) => {
529
+ if (!Array.isArray(value))
530
+ return;
531
+ for (const node of value) {
532
+ if (!node || typeof node !== 'object' || Array.isArray(node))
533
+ continue;
534
+ const record = node;
535
+ if (record['type'] === 'richContent')
536
+ continue;
537
+ if (record['type'] === 'cardGrid' && Array.isArray(record['cards'])) {
538
+ for (const card of record['cards']) {
539
+ const content = Array.isArray(card?.['content']) ? card?.['content'] : card?.['items'];
540
+ if (Array.isArray(content) && content.some((item) => !isTableDetailCardGridContentNode(item))) {
541
+ result.cardGrid = true;
542
+ }
543
+ }
544
+ }
545
+ if (record['type'] === 'compose' && Array.isArray(record['items'])
546
+ && record['items'].some((item) => !isTableDetailComposeItemNode(item))) {
547
+ result.compose = true;
548
+ }
549
+ visit(record['items']);
550
+ visit(record['content']);
551
+ visit(record['cards']);
552
+ }
553
+ };
554
+ visit(nodes);
555
+ return result;
556
+ }
557
+ /**
558
+ * Losslessly rewrites legacy table-detail `value` fields that sit inside cardGrid cards or compose items
559
+ * into canonical presenters. Structural blocks are left untouched (still reported) to avoid data loss.
560
+ * Returns the number of rewritten nodes.
561
+ */
562
+ function normalizeTableDetailRichChildren(schema) {
563
+ let rewritten = 0;
564
+ const rewrite = (list, project, accepts) => {
565
+ if (!Array.isArray(list))
566
+ return;
567
+ list.forEach((item, index) => {
568
+ if (accepts(item) || item?.['type'] !== 'value')
569
+ return;
570
+ const projected = project(item);
571
+ if (projected) {
572
+ list[index] = projected;
573
+ rewritten += 1;
574
+ }
575
+ });
576
+ };
577
+ const visit = (value) => {
578
+ if (!Array.isArray(value))
579
+ return;
580
+ for (const node of value) {
581
+ if (!node || typeof node !== 'object' || Array.isArray(node) || node['type'] === 'richContent')
582
+ continue;
583
+ if (node['type'] === 'cardGrid' && Array.isArray(node['cards'])) {
584
+ for (const card of node['cards']) {
585
+ rewrite(Array.isArray(card?.['content']) ? card?.['content'] : card?.['items'], toTableDetailCardGridContentNode, isTableDetailCardGridContentNode);
586
+ }
587
+ }
588
+ if (node['type'] === 'compose')
589
+ rewrite(node['items'], toTableDetailComposeItemNode, isTableDetailComposeItemNode);
590
+ visit(node['items']);
591
+ visit(node['content']);
592
+ visit(node['cards']);
593
+ }
594
+ };
595
+ visit([schema]);
596
+ return rewritten;
597
+ }
394
598
  /** Edits the original authoring tree; keys exist only in the editor's WeakMap. */
395
599
  class TableDetailTreeDraft {
396
600
  keys = new WeakMap();
@@ -449,17 +653,71 @@ class TableDetailTreeDraft {
449
653
  entry.siblings.splice(next, 0, entry.node);
450
654
  }
451
655
  add(node, nested = false) {
452
- const selected = this.selected()?.node;
453
- const childKey = selected?.type === 'card' || selected?.type === 'tab' ? 'content' : 'items';
656
+ const selectedEntry = this.selected();
657
+ const selected = selectedEntry?.node;
658
+ const isCardLike = selected?.type === 'card' || (!selected?.type && (Array.isArray(selected?.content) || Array.isArray(selected?.items)));
659
+ // Cards stored in `cardGrid.cards` follow TableDetailCardGridCardNode: rich presenters/compose only.
660
+ const isCardGridCard = !!selectedEntry && isCardLike && this.entries().some((entry) => entry.node['type'] === 'cardGrid' && entry.node['cards'] === selectedEntry.siblings);
661
+ const childKey = selected?.type === 'cardGrid'
662
+ ? 'cards'
663
+ : (isCardLike || selected?.type === 'tab')
664
+ ? (!Array.isArray(selected?.content) && Array.isArray(selected?.items) ? 'items' : 'content')
665
+ : 'items';
454
666
  const parent = nested && selected ? selected : this.schema;
455
667
  const key = nested && selected ? childKey : 'items';
456
668
  if (!nested && this.schema.layout === 'tabs' && node.type !== 'tab') {
457
669
  node = { type: 'tab', title: node.title || node.label || node.type, content: [node] };
458
670
  }
671
+ else if (nested && selected?.type === 'cardGrid') {
672
+ if (node.type === 'cardGrid' && Array.isArray(node.cards) && node.cards.length > 0) {
673
+ node = structuredClone(node.cards[0]);
674
+ }
675
+ else if (node.type === 'card') {
676
+ const rawCardChildren = Array.isArray(node.content) ? node.content : Array.isArray(node.items) ? node.items : [];
677
+ const content = rawCardChildren
678
+ .map((child) => toTableDetailCardGridContentNode(child))
679
+ .filter((child) => !!child);
680
+ node = {
681
+ ...(node.id ? { id: node.id } : {}),
682
+ title: node.title ?? '',
683
+ ...(node.subtitle !== undefined ? { subtitle: node.subtitle } : {}),
684
+ content: content.length ? content : [{ type: 'text', text: node.title || 'Detalhe' }],
685
+ };
686
+ }
687
+ else if (!Array.isArray(node.content) && !Array.isArray(node.items)) {
688
+ const content = toTableDetailCardGridContentNode(node);
689
+ if (!content)
690
+ return null;
691
+ node = {
692
+ title: node.title || node.label || '',
693
+ content: [content],
694
+ };
695
+ }
696
+ }
697
+ else if (nested && isCardGridCard) {
698
+ const content = toTableDetailCardGridContentNode(node);
699
+ if (!content)
700
+ return null;
701
+ node = content;
702
+ }
703
+ else if (nested && selected?.type === 'compose') {
704
+ // RichComposeNode.items accepts presenters only; the runtime drops anything else silently.
705
+ const item = toTableDetailComposeItemNode(node);
706
+ if (!item)
707
+ return null;
708
+ node = item;
709
+ }
710
+ else if (nested && isCardLike && node.type === 'cardGrid' && Array.isArray(node.cards)) {
711
+ const firstCardContent = node.cards[0]?.content ?? node.cards[0]?.items;
712
+ if (Array.isArray(firstCardContent) && firstCardContent.length > 0) {
713
+ node = structuredClone(firstCardContent[0]);
714
+ }
715
+ }
459
716
  if (!Array.isArray(parent[key]))
460
717
  parent[key] = [];
461
718
  parent[key].push(node);
462
719
  this.selectedKey = this.entries().find(entry => entry.node === node)?.key ?? null;
720
+ return node;
463
721
  }
464
722
  }
465
723
 
@@ -546,7 +804,7 @@ function validateTableAuthoringDocument(doc, context) {
546
804
  }
547
805
  const rawColumns = Array.isArray(rawConfig.columns)
548
806
  ? rawConfig.columns
549
- : normalized.config.columns;
807
+ : (normalized.config.columns || []);
550
808
  const columnFields = new Set();
551
809
  rawColumns.forEach((column, index) => {
552
810
  const field = trimString(column?.field);
@@ -789,8 +1047,14 @@ function deriveBindingsDiff(next, current) {
789
1047
  }
790
1048
  const normalizedNext = normalizeBindings(next) || {};
791
1049
  const normalizedCurrent = normalizeBindings(current) || {};
792
- const resourcePathChanged = normalizeResourcePath(normalizedNext.resourcePath) !==
793
- normalizeResourcePath(normalizedCurrent.resourcePath);
1050
+ const resourcePathChanged = normalizePraxisResourcePath(normalizedNext.resourcePath, {
1051
+ style: 'relative',
1052
+ stripApiPrefix: true,
1053
+ }).toLowerCase() !==
1054
+ normalizePraxisResourcePath(normalizedCurrent.resourcePath, {
1055
+ style: 'relative',
1056
+ stripApiPrefix: true,
1057
+ }).toLowerCase();
794
1058
  const horizontalScrollChanged = normalizeHorizontalScroll(normalizedNext.horizontalScroll) !==
795
1059
  normalizeHorizontalScroll(normalizedCurrent.horizontalScroll);
796
1060
  return {
@@ -916,13 +1180,15 @@ function infoDiagnostic(code, message, path) {
916
1180
  class TableSchemaColumnProjector {
917
1181
  convertFieldToColumn(field) {
918
1182
  const apiType = resolveColumnTypeFromFieldDefinition(field, this.inferFieldTypeFromFieldName(field.name));
1183
+ const sticky = field.pinned ?? field.sticky;
919
1184
  const col = {
920
1185
  field: field.name,
921
1186
  header: field.label ?? field.name,
922
- order: field.order,
1187
+ order: field.tableOrder ?? field.order,
923
1188
  width: field.width ?? undefined,
924
1189
  sortable: field.sortable,
925
1190
  visible: field.tableHidden || field.hidden ? false : true,
1191
+ ...(sticky === 'start' || sticky === 'end' || sticky === true ? { sticky } : {}),
926
1192
  type: apiType,
927
1193
  _originalApiType: apiType,
928
1194
  _isApiField: true,
@@ -946,26 +1212,40 @@ class TableSchemaColumnProjector {
946
1212
  const includeOrder = new Map(include.map((field, index) => [field, index]));
947
1213
  const order = Array.isArray(projection?.order) ? projection.order : include;
948
1214
  const presentationOrder = new Map(order.map((field, index) => [field, index]));
1215
+ const fieldsByName = new Map();
1216
+ for (const field of Array.isArray(fields) ? fields : []) {
1217
+ const name = typeof field?.name === 'string' ? field.name.trim() : '';
1218
+ if (name)
1219
+ fieldsByName.set(name, field);
1220
+ }
949
1221
  const schemaColumns = (Array.isArray(fields) ? fields : [])
950
1222
  .filter((field) => !field.tableHidden && !field.hidden)
951
1223
  .filter((field) => include.length === 0 || includeOrder.has(field.name))
952
1224
  .sort((left, right) => {
953
- return (presentationOrder.get(left.name) ?? Number.MAX_SAFE_INTEGER)
1225
+ const orderDiff = (presentationOrder.get(left.name) ?? Number.MAX_SAFE_INTEGER)
954
1226
  - (presentationOrder.get(right.name) ?? Number.MAX_SAFE_INTEGER);
1227
+ if (orderDiff !== 0) {
1228
+ return orderDiff;
1229
+ }
1230
+ return (left.tableOrder ?? left.order ?? Number.MAX_SAFE_INTEGER)
1231
+ - (right.tableOrder ?? right.order ?? Number.MAX_SAFE_INTEGER);
955
1232
  })
956
1233
  .map((field) => {
957
1234
  const base = this.convertFieldToColumn(field);
958
1235
  const override = overrides[field.name];
959
1236
  if (!override || typeof override !== 'object' || Array.isArray(override)) {
1237
+ this.applySchemaComposeItemsQuickView(base, fieldsByName);
960
1238
  return base;
961
1239
  }
962
1240
  const merged = deepMerge(base, override);
963
- return {
1241
+ const projected = {
964
1242
  ...merged,
965
1243
  field: base.field,
966
1244
  _isApiField: base._isApiField,
967
1245
  _originalApiType: base._originalApiType,
968
1246
  };
1247
+ this.applySchemaComposeItemsQuickView(projected, fieldsByName);
1248
+ return projected;
969
1249
  });
970
1250
  const canonicalFields = new Set((Array.isArray(fields) ? fields : [])
971
1251
  .map((field) => String(field?.name || '').trim())
@@ -982,82 +1262,129 @@ class TableSchemaColumnProjector {
982
1262
  // It never admits hidden fields, overrides field identity, or selects membership.
983
1263
  const combined = [...schemaColumns, ...additions];
984
1264
  if (Array.isArray(projection?.order) && projection.order.length > 0) {
1265
+ const additionFields = new Set(additions.map((col) => col.field));
985
1266
  combined.sort((left, right) => {
986
1267
  return (presentationOrder.get(left.field) ?? Number.MAX_SAFE_INTEGER)
987
1268
  - (presentationOrder.get(right.field) ?? Number.MAX_SAFE_INTEGER);
988
1269
  });
989
- return combined.map((column) => {
990
- const explicitOrder = presentationOrder.get(column.field);
991
- return explicitOrder !== undefined ? { ...column, order: explicitOrder } : column;
1270
+ return combined.map((column, index) => {
1271
+ if (!additionFields.has(column.field) || presentationOrder.has(column.field)) {
1272
+ return { ...column, order: index };
1273
+ }
1274
+ return column;
992
1275
  });
993
1276
  }
994
1277
  return combined;
995
1278
  }
996
1279
  inferFieldTypeFromFieldName(fieldName) {
997
1280
  const lowercaseName = fieldName.toLowerCase();
998
- // Date/time patterns - more specific patterns first
1281
+ // Date/time patterns - more specific patterns first (EN + PT-BR)
999
1282
  if (lowercaseName.endsWith('date') ||
1000
1283
  lowercaseName.endsWith('time') ||
1001
1284
  lowercaseName.endsWith('at') ||
1002
1285
  lowercaseName.startsWith('date') ||
1286
+ lowercaseName.startsWith('data') ||
1287
+ lowercaseName.startsWith('dt_') ||
1288
+ lowercaseName.startsWith('dt') ||
1289
+ lowercaseName.endsWith('_em') ||
1003
1290
  lowercaseName === 'created' ||
1004
1291
  lowercaseName === 'updated' ||
1005
1292
  lowercaseName === 'modified' ||
1293
+ lowercaseName === 'nascimento' ||
1294
+ lowercaseName === 'admissao' ||
1295
+ lowercaseName === 'demissao' ||
1296
+ lowercaseName === 'vencimento' ||
1006
1297
  lowercaseName.includes('timestamp')) {
1007
1298
  return 'date';
1008
1299
  }
1009
- // Boolean patterns - most specific first to avoid conflicts
1300
+ // Boolean patterns - most specific first to avoid conflicts (EN + PT-BR)
1010
1301
  if (lowercaseName.startsWith('is_') ||
1011
1302
  lowercaseName.startsWith('has_') ||
1012
1303
  lowercaseName.startsWith('can_') ||
1013
1304
  lowercaseName.startsWith('should_') ||
1305
+ lowercaseName.startsWith('fl_') ||
1306
+ lowercaseName.startsWith('ind_') ||
1014
1307
  lowercaseName === 'active' ||
1308
+ lowercaseName === 'ativo' ||
1309
+ lowercaseName === 'inativo' ||
1015
1310
  lowercaseName === 'enabled' ||
1311
+ lowercaseName === 'habilitado' ||
1016
1312
  lowercaseName === 'visible' ||
1313
+ lowercaseName === 'visivel' ||
1017
1314
  lowercaseName === 'deleted' ||
1315
+ lowercaseName === 'excluido' ||
1018
1316
  lowercaseName === 'archived' ||
1317
+ lowercaseName === 'arquivado' ||
1019
1318
  lowercaseName.endsWith('_flag') ||
1020
1319
  lowercaseName.endsWith('_enabled') ||
1021
- lowercaseName.endsWith('_active')) {
1320
+ lowercaseName.endsWith('_active') ||
1321
+ lowercaseName.endsWith('_ativo')) {
1022
1322
  return 'boolean';
1023
1323
  }
1024
- // Currency/money patterns - exclude common false positives
1324
+ // Currency/money patterns - exclude common false positives (EN + PT-BR)
1025
1325
  if ((lowercaseName.includes('price') ||
1326
+ lowercaseName.includes('preco') ||
1026
1327
  lowercaseName.includes('amount') ||
1027
1328
  lowercaseName.includes('cost') ||
1329
+ lowercaseName.includes('custo') ||
1028
1330
  lowercaseName.includes('salary') ||
1331
+ lowercaseName.includes('salario') ||
1332
+ lowercaseName.includes('remuneracao') ||
1333
+ lowercaseName.includes('orcamento') ||
1334
+ lowercaseName.includes('indenizacao') ||
1335
+ lowercaseName.includes('multa') ||
1336
+ lowercaseName.includes('desconto') ||
1337
+ lowercaseName.includes('liquido') ||
1338
+ lowercaseName.includes('bruto') ||
1029
1339
  lowercaseName.includes('wage') ||
1030
1340
  lowercaseName.includes('fee') ||
1031
- (lowercaseName.includes('value') &&
1341
+ ((lowercaseName.includes('value') || lowercaseName.includes('valor') || lowercaseName.startsWith('vl_')) &&
1032
1342
  !lowercaseName.includes('id') &&
1033
1343
  !lowercaseName.includes('key'))) &&
1034
1344
  !lowercaseName.includes('count') &&
1035
- !lowercaseName.includes('type')) {
1345
+ !lowercaseName.includes('type') &&
1346
+ !lowercaseName.includes('tipo')) {
1036
1347
  return 'currency';
1037
1348
  }
1038
- // Percentage patterns - be more specific
1349
+ // Percentage patterns - be more specific (EN + PT-BR)
1039
1350
  if (lowercaseName.includes('percent') ||
1351
+ lowercaseName.includes('percentual') ||
1352
+ lowercaseName.includes('aliquota') ||
1353
+ lowercaseName.includes('margem') ||
1354
+ lowercaseName.startsWith('pct_') ||
1040
1355
  lowercaseName.endsWith('_rate') ||
1041
1356
  lowercaseName.endsWith('_ratio') ||
1042
1357
  lowercaseName.endsWith('_pct') ||
1043
- (lowercaseName.includes('rate') &&
1358
+ lowercaseName.endsWith('_taxa') ||
1359
+ ((lowercaseName.includes('rate') || lowercaseName.includes('taxa')) &&
1044
1360
  !lowercaseName.includes('created') &&
1045
1361
  !lowercaseName.includes('updated')) ||
1046
1362
  lowercaseName.endsWith('_score')) {
1047
1363
  return 'percentage';
1048
1364
  }
1049
- // Number patterns - exclude common false positives like string IDs
1365
+ // Number patterns - exclude common false positives like string IDs (EN + PT-BR)
1050
1366
  if ((lowercaseName.endsWith('_id') && lowercaseName !== 'id') || // composite IDs might be strings
1051
1367
  lowercaseName === 'id' ||
1052
1368
  lowercaseName.includes('count') ||
1053
1369
  lowercaseName.includes('quantity') ||
1370
+ lowercaseName.includes('quantidade') ||
1371
+ lowercaseName.includes('qtd') ||
1054
1372
  lowercaseName.includes('number') ||
1373
+ lowercaseName.includes('numero') ||
1055
1374
  lowercaseName.includes('total') ||
1056
1375
  lowercaseName.includes('sum') ||
1376
+ lowercaseName.includes('soma') ||
1057
1377
  lowercaseName.includes('age') ||
1378
+ lowercaseName.includes('idade') ||
1058
1379
  lowercaseName.includes('weight') ||
1380
+ lowercaseName.includes('peso') ||
1059
1381
  lowercaseName.includes('height') ||
1382
+ lowercaseName.includes('altura') ||
1060
1383
  lowercaseName.includes('size') ||
1384
+ lowercaseName.includes('tamanho') ||
1385
+ lowercaseName.includes('pontuacao') ||
1386
+ lowercaseName.includes('score') ||
1387
+ lowercaseName.includes('nota') ||
1061
1388
  lowercaseName.endsWith('_num') ||
1062
1389
  lowercaseName.endsWith('_number')) {
1063
1390
  return 'number';
@@ -1065,32 +1392,66 @@ class TableSchemaColumnProjector {
1065
1392
  // Default to string for ambiguous cases
1066
1393
  return 'string';
1067
1394
  }
1395
+ applySchemaComposeItemsQuickView(col, fieldsByName) {
1396
+ const renderer = col?.renderer;
1397
+ if (renderer?.type !== 'compose' || !Array.isArray(renderer?.compose?.items)) {
1398
+ return;
1399
+ }
1400
+ for (const item of renderer.compose.items) {
1401
+ if (!item || typeof item !== 'object')
1402
+ continue;
1403
+ const itemType = typeof item.type === 'string' ? item.type.trim() : 'value';
1404
+ if (itemType !== 'value' || item.quickView !== undefined)
1405
+ continue;
1406
+ const itemFieldName = typeof item.field === 'string' ? item.field.trim() : '';
1407
+ if (!itemFieldName)
1408
+ continue;
1409
+ const itemField = fieldsByName.get(itemFieldName);
1410
+ if (itemField?.quickView) {
1411
+ item.quickView = this.clonePlainObject(itemField.quickView);
1412
+ }
1413
+ }
1414
+ }
1068
1415
  applySchemaFieldPresentation(field, col) {
1069
1416
  if (!field || !col)
1070
1417
  return;
1418
+ if (field.quickView && !col.quickView) {
1419
+ col.quickView = this.clonePlainObject(field.quickView);
1420
+ }
1071
1421
  const controlType = this.normalizePresentationToken(field.controlType);
1072
1422
  const numericFormat = this.normalizePresentationToken(field.numericFormat ?? field.format);
1073
1423
  const valuePresentationType = this.normalizePresentationToken(field.valuePresentation?.type);
1074
1424
  const displayFormat = this.firstNonEmptyString(field.displayFormat, field.extraProperties?.displayFormat);
1075
1425
  const valueMapping = this.resolveSchemaValueMapping(field);
1076
- if (valueMapping) {
1426
+ if (valueMapping && (!col.valueMapping || Object.keys(col.valueMapping).length === 0)) {
1077
1427
  col.valueMapping = valueMapping;
1078
1428
  }
1079
1429
  const presentation = field.presentation;
1080
- if (presentation?.presenter === 'microVisualization' &&
1081
- isPraxisPresentationVisualizationTableSafe(presentation?.visualization)) {
1430
+ const resolvedMicroViz = presentation?.presenter === 'microVisualization' &&
1431
+ isPraxisPresentationVisualizationTableSafe(presentation?.visualization)
1432
+ ? presentation.visualization
1433
+ : isPraxisPresentationVisualizationTableSafe(field.microVisualization)
1434
+ ? field.microVisualization
1435
+ : null;
1436
+ if (resolvedMicroViz && !col.renderer?.type) {
1082
1437
  col.renderer = {
1083
1438
  ...(col.renderer || {}),
1084
1439
  type: 'microVisualization',
1085
1440
  microVisualization: {
1086
- visualization: presentation.visualization,
1441
+ visualization: resolvedMicroViz,
1087
1442
  },
1088
1443
  };
1089
1444
  }
1445
+ if (col.sticky === undefined && (field.pinned === 'start' || field.pinned === 'end')) {
1446
+ col.sticky = field.pinned;
1447
+ }
1090
1448
  this.applySchemaSemanticCellPresentation(field, col, presentation);
1091
1449
  if (numericFormat === 'currency' || controlType === 'currency' || col.type === 'currency') {
1450
+ const wasCurrency = col.type === 'currency';
1092
1451
  col.type = 'currency';
1093
- col.format = this.resolveSchemaCurrencyFormat(field);
1452
+ if (!col.format || (!wasCurrency && !String(col.format).includes('|'))) {
1453
+ col.format = this.resolveSchemaCurrencyFormat(field);
1454
+ }
1094
1455
  return;
1095
1456
  }
1096
1457
  if (numericFormat === 'date' ||
@@ -1103,13 +1464,29 @@ class TableSchemaColumnProjector {
1103
1464
  controlType === 'date' ||
1104
1465
  controlType === 'datetime') {
1105
1466
  col.type = 'date';
1106
- col.format = displayFormat || (numericFormat === 'datetime' ||
1107
- valuePresentationType === 'datetime' ||
1108
- controlType === 'datetimepicker' ||
1109
- controlType === 'datetimelocal' ||
1110
- controlType === 'datetime'
1111
- ? 'dd/MM/yyyy HH:mm'
1112
- : 'dd/MM/yyyy');
1467
+ if (!col.format) {
1468
+ col.format = displayFormat || (numericFormat === 'datetime' ||
1469
+ valuePresentationType === 'datetime' ||
1470
+ controlType === 'datetimepicker' ||
1471
+ controlType === 'datetimelocal' ||
1472
+ controlType === 'datetime'
1473
+ ? 'dd/MM/yyyy HH:mm'
1474
+ : 'dd/MM/yyyy');
1475
+ }
1476
+ return;
1477
+ }
1478
+ if (numericFormat === 'percent' ||
1479
+ numericFormat === 'percentage' ||
1480
+ numericFormat === 'fraction' ||
1481
+ valuePresentationType === 'percent' ||
1482
+ valuePresentationType === 'percentage' ||
1483
+ col.type === 'percentage') {
1484
+ col.type = 'percentage';
1485
+ if (!col.format) {
1486
+ col.format =
1487
+ displayFormat ||
1488
+ (numericFormat === 'fraction' ? '1.0-2|x100' : '1.0-2|raw');
1489
+ }
1113
1490
  return;
1114
1491
  }
1115
1492
  if (col.type === 'boolean' && !col.format) {
@@ -1117,10 +1494,26 @@ class TableSchemaColumnProjector {
1117
1494
  }
1118
1495
  const schemaDataType = this.normalizePresentationToken(field.type);
1119
1496
  const schemaFormat = this.normalizePresentationToken(field.format);
1120
- if (col.type === 'number' &&
1121
- !col.format &&
1122
- (schemaDataType === 'integer' || schemaFormat === 'int32' || schemaFormat === 'int64')) {
1123
- col.format = '1.0-0';
1497
+ if (col.type === 'number' && !col.format) {
1498
+ if (displayFormat) {
1499
+ col.format = displayFormat;
1500
+ }
1501
+ else if (schemaDataType === 'integer' ||
1502
+ schemaFormat === 'integer' ||
1503
+ schemaFormat === 'int32' ||
1504
+ schemaFormat === 'int64' ||
1505
+ numericFormat === 'integer' ||
1506
+ numericFormat === 'int32' ||
1507
+ numericFormat === 'int64') {
1508
+ col.format = '1.0-0';
1509
+ }
1510
+ else {
1511
+ const explicitDecimals = this.firstFiniteNumber(field.decimalPlaces, field.extraProperties?.decimalPlaces);
1512
+ if (explicitDecimals !== undefined && explicitDecimals >= 0) {
1513
+ const decimals = Math.trunc(explicitDecimals);
1514
+ col.format = `1.${decimals}-${decimals}`;
1515
+ }
1516
+ }
1124
1517
  }
1125
1518
  const textMaskFormat = resolveTextMaskFormatFromFieldDefinition(field);
1126
1519
  const maskResolvedType = resolveColumnTypeFromFieldDefinition(field, col.type);
@@ -1137,22 +1530,24 @@ class TableSchemaColumnProjector {
1137
1530
  return;
1138
1531
  const ctl = (field.controlType || '').toString().trim().toLowerCase();
1139
1532
  const fname = (field.name || '').toString();
1140
- const lname = fname.toLowerCase();
1141
1533
  const isAvatarByControl = ctl === 'avatar';
1142
1534
  if (isAvatarByControl) {
1535
+ const initialsField = this.firstNonEmptyString(field.initialsField, field.extraProperties?.initialsField) || 'nomeCompleto';
1143
1536
  col.renderer = {
1144
1537
  type: 'avatar',
1145
1538
  avatar: {
1146
1539
  srcField: fname,
1147
- initialsField: 'nomeCompleto',
1540
+ initialsField,
1148
1541
  shape: 'circle',
1149
1542
  size: 32,
1150
1543
  },
1151
1544
  };
1152
- // Sensible defaults for avatar column
1545
+ // Sensible defaults for avatar column (84px prevents header truncation when centered with sort/resize gutters; not sortable by default)
1153
1546
  col.align = col.align || 'center';
1547
+ if (col.sortable === undefined)
1548
+ col.sortable = false;
1154
1549
  if (!col.width)
1155
- col.width = '56px';
1550
+ col.width = '84px';
1156
1551
  return;
1157
1552
  }
1158
1553
  }
@@ -1203,90 +1598,22 @@ class TableSchemaColumnProjector {
1203
1598
  return undefined;
1204
1599
  }
1205
1600
  applySchemaSemanticCellPresentation(field, col, presentation) {
1206
- if (!presentation || typeof presentation !== 'object')
1207
- return;
1208
- if (col.renderer?.type)
1209
- return;
1210
- const presenter = this.normalizePresentationToken(presentation.presenter ?? presentation.variant);
1211
- const textField = field.name;
1212
- const color = this.resolveSemanticPresentationColor(presentation.tone);
1213
- const variant = this.resolveSemanticPresentationVariant(presentation.appearance);
1214
- const icon = this.firstNonEmptyString(presentation.icon);
1215
- const tooltipText = this.firstNonEmptyString(presentation.tooltip);
1216
- const tooltip = tooltipText ? { text: tooltipText } : undefined;
1217
- const fixedText = this.firstNonEmptyString(presentation.label);
1218
- if (presenter === 'chip') {
1219
- col.renderer = {
1220
- type: 'chip',
1221
- chip: {
1222
- text: fixedText,
1223
- textField: fixedText ? undefined : textField,
1224
- color,
1225
- icon,
1226
- variant,
1227
- tooltip,
1228
- },
1229
- };
1230
- return;
1231
- }
1232
- if (presenter === 'badge' || presenter === 'status') {
1233
- col.renderer = {
1234
- type: 'badge',
1235
- badge: {
1236
- text: fixedText,
1237
- textField: fixedText ? undefined : textField,
1238
- color,
1239
- icon,
1240
- variant,
1241
- tooltip,
1242
- },
1243
- };
1244
- return;
1601
+ const options = {
1602
+ includeUndefinedBadgeChipFields: true,
1603
+ includeUndefinedBadgeChipText: true,
1604
+ allowTextPresenterAsIconValue: true,
1605
+ };
1606
+ if (presentation && typeof presentation === 'object' && !col.renderer?.type) {
1607
+ const renderer = buildSchemaSemanticColumnRenderer(field, presentation, options);
1608
+ if (renderer) {
1609
+ col.renderer = renderer;
1610
+ }
1245
1611
  }
1246
- if (presenter === 'iconvalue') {
1247
- const rendererIcon = icon || this.firstNonEmptyString(field.icon);
1248
- const affixes = this.resolveSemanticPresentationAffixes(presentation);
1249
- const hasAffixes = !!(affixes.prefix || affixes.suffix);
1250
- if (!rendererIcon && !hasAffixes)
1251
- return;
1252
- if (affixes.prefix || affixes.suffix || tooltipText) {
1253
- col.renderer = {
1254
- type: 'icon',
1255
- icon: {
1256
- ...(!hasAffixes && rendererIcon ? { name: rendererIcon } : {}),
1257
- textField,
1258
- ...(tooltipText ? { ariaLabel: tooltipText } : {}),
1259
- ...affixes,
1260
- },
1261
- };
1262
- return;
1612
+ if (!col.conditionalRenderers?.length) {
1613
+ const conditionalRenderers = resolveSchemaConditionalRenderers(field, options);
1614
+ if (conditionalRenderers?.length) {
1615
+ col.conditionalRenderers = conditionalRenderers;
1263
1616
  }
1264
- if (!rendererIcon)
1265
- return;
1266
- col.renderer = {
1267
- type: 'compose',
1268
- compose: {
1269
- items: [
1270
- {
1271
- type: 'icon',
1272
- icon: {
1273
- name: rendererIcon,
1274
- ...(color ? { color } : {}),
1275
- ...(field.label ? { ariaLabel: field.label } : {}),
1276
- },
1277
- },
1278
- {
1279
- type: 'value',
1280
- field: textField,
1281
- },
1282
- ],
1283
- layout: {
1284
- direction: 'row',
1285
- gap: 6,
1286
- align: 'center',
1287
- },
1288
- },
1289
- };
1290
1617
  }
1291
1618
  }
1292
1619
  resolveSchemaCurrencyFormat(field) {
@@ -1298,6 +1625,19 @@ class TableSchemaColumnProjector {
1298
1625
  const explicit = this.firstNonEmptyString(field.booleanFormat, field.extraProperties?.booleanFormat);
1299
1626
  if (explicit)
1300
1627
  return explicit;
1628
+ const trueLabel = this.firstNonEmptyString(field.trueLabel, field.labelTrue, field.presentation?.labelTrue, field.extraProperties?.trueLabel, field.extraProperties?.labelTrue);
1629
+ const falseLabel = this.firstNonEmptyString(field.falseLabel, field.labelFalse, field.presentation?.labelFalse, field.extraProperties?.falseLabel, field.extraProperties?.labelFalse);
1630
+ if (trueLabel || falseLabel) {
1631
+ const effectiveTrue = trueLabel || 'Sim';
1632
+ const effectiveFalse = falseLabel || 'Não';
1633
+ const tNorm = this.normalizePresentationToken(effectiveTrue);
1634
+ const fNorm = this.normalizePresentationToken(effectiveFalse);
1635
+ if (tNorm === 'ativo' && fNorm === 'inativo')
1636
+ return 'active-inactive';
1637
+ if (tNorm === 'sim' && (fNorm === 'nao' || fNorm === 'não'))
1638
+ return 'yes-no';
1639
+ return `custom|${effectiveTrue}|${effectiveFalse}`;
1640
+ }
1301
1641
  const name = this.normalizePresentationToken(field.name);
1302
1642
  if (name === 'ativo' || name === 'active' || name.endsWith('ativo')) {
1303
1643
  return 'active-inactive';
@@ -1352,33 +1692,6 @@ class TableSchemaColumnProjector {
1352
1692
  .map((part, index) => index === 0 ? this.capitalizeSchemaEnumPart(part) : part)
1353
1693
  .join(' ');
1354
1694
  }
1355
- resolveSemanticPresentationColor(tone) {
1356
- const normalized = this.normalizePresentationToken(tone);
1357
- if (normalized === 'neutral')
1358
- return 'basic';
1359
- if (!normalized)
1360
- return undefined;
1361
- if (normalized === 'danger')
1362
- return 'warn';
1363
- if (normalized === 'warning')
1364
- return 'warn';
1365
- return normalized;
1366
- }
1367
- resolveSemanticPresentationVariant(appearance) {
1368
- const normalized = this.normalizePresentationToken(appearance);
1369
- if (normalized === 'filled' || normalized === 'outlined' || normalized === 'soft' || normalized === 'plain') {
1370
- return normalized;
1371
- }
1372
- return undefined;
1373
- }
1374
- resolveSemanticPresentationAffixes(presentation) {
1375
- const prefix = this.firstNonEmptyString(presentation.prefix);
1376
- const suffix = this.firstNonEmptyString(presentation.suffix);
1377
- return {
1378
- ...(prefix ? { prefix } : {}),
1379
- ...(suffix ? { suffix } : {}),
1380
- };
1381
- }
1382
1695
  firstFiniteNumber(...values) {
1383
1696
  for (const value of values) {
1384
1697
  const numeric = typeof value === 'number' ? value : Number(value);
@@ -1456,8 +1769,382 @@ function deriveTableEditorDocument(input) {
1456
1769
  });
1457
1770
  }
1458
1771
 
1772
+ /** Shared presentation ordering; hidden columns must not shift visible fallback positions. */
1773
+ function orderTableColumns(columns) {
1774
+ if (!columns.some(column => Number.isFinite(column.order)))
1775
+ return [...columns];
1776
+ let visibleIndex = 0;
1777
+ return columns.map((column, originalIndex) => {
1778
+ const fallback = column.visible === false ? originalIndex : visibleIndex++;
1779
+ return { column, originalIndex, explicit: Number.isFinite(column.order), order: Number.isFinite(column.order) ? Number(column.order) : fallback };
1780
+ }).sort((left, right) => left.order - right.order
1781
+ || Number(right.explicit) - Number(left.explicit)
1782
+ || left.originalIndex - right.originalIndex).map(entry => entry.column);
1783
+ }
1784
+
1785
+ const hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
1786
+ /** Preserve authored values; runtime/schema defaults remain transient unless explicitly edited. */
1787
+ function applyTableAuthoringChanges(authored, baseline, edited) {
1788
+ return projectChanges(authored, baseline, edited, true);
1789
+ }
1790
+ function projectChanges(authored, baseline, edited, tableConfigRoot) {
1791
+ if (sameAuthoringValue(baseline, edited))
1792
+ return authored;
1793
+ if (!edited || typeof edited !== 'object' || Array.isArray(edited))
1794
+ return edited;
1795
+ const original = authored && typeof authored === 'object' ? authored : {};
1796
+ const before = baseline && typeof baseline === 'object' ? baseline : {};
1797
+ const after = edited;
1798
+ const result = { ...original };
1799
+ for (const key of new Set([...Object.keys(before), ...Object.keys(after)])) {
1800
+ if (sameAuthoringValue(before[key], after[key]))
1801
+ continue;
1802
+ if (!hasOwn(after, key))
1803
+ delete result[key];
1804
+ else
1805
+ Object.defineProperty(result, key, {
1806
+ value: projectChanges(hasOwn(original, key) ? original[key] : undefined, hasOwn(before, key) ? before[key] : undefined, after[key], false),
1807
+ enumerable: true, configurable: true, writable: true,
1808
+ });
1809
+ }
1810
+ if (tableConfigRoot && isRecord(original['columnProjection']) && original['columnProjection']['source'] === 'schema'
1811
+ && isRecord(result['columnProjection']) && result['columnProjection']['source'] === 'schema'
1812
+ && Array.isArray(after['columns']) && JSON.stringify(before['columns']) !== JSON.stringify(after['columns'])) {
1813
+ result['columns'] = [];
1814
+ result['columnProjection'] = projectSchemaColumnChanges(result['columnProjection'], before['columns'], after['columns'], isRecord(before['columnProjection']) ? before['columnProjection'] : original['columnProjection'], after['columnProjection']);
1815
+ }
1816
+ return result;
1817
+ }
1818
+ /** Write the existing compact schema projection, never a partial columns snapshot. */
1819
+ function projectSchemaColumnChanges(authored, baseline, edited, baselineProjection, editedProjection) {
1820
+ if (!isRecord(authored) || authored['source'] !== 'schema') {
1821
+ throw new Error('Table schema authorship requires its canonical columnProjection.');
1822
+ }
1823
+ const projection = structuredClone(authored);
1824
+ const overrides = Object.assign(Object.create(null), isRecord(projection['overrides']) ? projection['overrides'] : {});
1825
+ const additions = columnsByField(Array.isArray(projection['additions']) ? projection['additions'] : []);
1826
+ const before = columnsByField(Array.isArray(baseline) ? baseline : []);
1827
+ const after = columnsByField(edited);
1828
+ const nextAdditions = [...additions].filter(([field]) => !before.has(field) && !after.has(field))
1829
+ .map(([, column]) => structuredClone(column));
1830
+ for (const [field, column] of after) {
1831
+ if (additions.has(field) || !before.has(field)) {
1832
+ nextAdditions.push(structuredClone(column));
1833
+ continue;
1834
+ }
1835
+ const previousOverride = isRecord(overrides[field]) ? overrides[field] : {};
1836
+ if (hasOwn(previousOverride, 'field')) {
1837
+ throw new Error('Table schema overrides cannot replace canonical field identity.');
1838
+ }
1839
+ const projected = projectChanges({ field, ...previousOverride }, before.get(field), column, false);
1840
+ const override = isRecord(projected) ? { ...projected } : {};
1841
+ // A direct edit of native intent is stronger evidence than a rematerialized snapshot.
1842
+ const baselineOverrides = isRecord(baselineProjection) && isRecord(baselineProjection['overrides'])
1843
+ ? baselineProjection['overrides'] : {};
1844
+ const editedOverrides = isRecord(editedProjection) && isRecord(editedProjection['overrides'])
1845
+ ? editedProjection['overrides'] : {};
1846
+ const oldIntent = isRecord(baselineOverrides[field]) ? baselineOverrides[field] : {};
1847
+ const newIntent = isRecord(editedOverrides[field]) ? editedOverrides[field] : {};
1848
+ if (isRecord(editedProjection)) {
1849
+ for (const key of new Set([...Object.keys(oldIntent), ...Object.keys(newIntent)])) {
1850
+ if (!changedNativeValue(oldIntent, newIntent, key))
1851
+ continue;
1852
+ if (hasOwn(previousOverride, key))
1853
+ override[key] = structuredClone(previousOverride[key]);
1854
+ else
1855
+ delete override[key];
1856
+ }
1857
+ }
1858
+ delete override['field'];
1859
+ delete override['order']; // Ordering has a dedicated projection field.
1860
+ if (Object.keys(override).length)
1861
+ overrides[field] = override;
1862
+ else
1863
+ delete overrides[field];
1864
+ }
1865
+ // Missing fields do not erase their overrides; membership and intent are separate.
1866
+ const previousOrder = orderedFields(before, additions);
1867
+ const nextOrder = orderedFields(after, additions).filter(field => before.has(field));
1868
+ if (!changedNativeValue(baselineProjection, editedProjection, 'include')
1869
+ && previousOrder.some(field => !nextOrder.includes(field))) {
1870
+ const include = Array.isArray(projection['include']) ? projection['include'] : [];
1871
+ projection['include'] = [...nextOrder, ...include.filter(field => !before.has(field))];
1872
+ }
1873
+ if (!changedNativeValue(baselineProjection, editedProjection, 'order')
1874
+ && JSON.stringify(previousOrder) !== JSON.stringify(nextOrder)) {
1875
+ const order = Array.isArray(projection['order']) ? projection['order'] : [];
1876
+ projection['order'] = [...nextOrder, ...order.filter(field => !before.has(field) && !nextOrder.includes(field))];
1877
+ }
1878
+ if (Object.keys(overrides).length)
1879
+ projection['overrides'] = overrides;
1880
+ else
1881
+ delete projection['overrides'];
1882
+ if (nextAdditions.length)
1883
+ projection['additions'] = nextAdditions;
1884
+ else
1885
+ delete projection['additions'];
1886
+ return projection;
1887
+ }
1888
+ function changedNativeValue(before, after, key) {
1889
+ if (!isRecord(after))
1890
+ return false;
1891
+ const previous = isRecord(before) ? before : {};
1892
+ return hasOwn(previous, key) !== hasOwn(after, key)
1893
+ || !sameAuthoringValue(previous[key], after[key]);
1894
+ }
1895
+ function orderedFields(columns, additions) {
1896
+ return orderTableColumns([...columns].map(([field, column]) => ({
1897
+ field, order: typeof column['order'] === 'number' ? column['order'] : undefined,
1898
+ visible: typeof column['visible'] === 'boolean' ? column['visible'] : undefined,
1899
+ }))).map(column => column.field).filter(field => !additions.has(field));
1900
+ }
1901
+ function columnsByField(columns) {
1902
+ const result = new Map();
1903
+ for (const column of columns) {
1904
+ if (!isRecord(column) || typeof column['field'] !== 'string' || !column['field'].trim()) {
1905
+ throw new Error('Table authoring requires a non-empty column field identity.');
1906
+ }
1907
+ const identity = column['field'].trim();
1908
+ if (result.has(identity))
1909
+ throw new Error('Table authoring requires unique column field identities.');
1910
+ result.set(identity, column);
1911
+ }
1912
+ return result;
1913
+ }
1914
+ function isRecord(value) {
1915
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
1916
+ }
1917
+ /** Object insertion order is not authored intent; undefined is an internal absence sentinel. */
1918
+ function sameAuthoringValue(left, right) {
1919
+ if (left === undefined || right === undefined)
1920
+ return left === right;
1921
+ try {
1922
+ return uiLayoutJsonIdentity(left) === uiLayoutJsonIdentity(right);
1923
+ }
1924
+ catch {
1925
+ if (Array.isArray(left) || Array.isArray(right))
1926
+ return Array.isArray(left) && Array.isArray(right)
1927
+ && left.length === right.length && left.every((value, index) => sameAuthoringValue(value, right[index]));
1928
+ if (!isRecord(left) || !isRecord(right))
1929
+ return left === right;
1930
+ const keys = Object.keys(left).filter(key => left[key] !== undefined);
1931
+ const otherKeys = Object.keys(right).filter(key => right[key] !== undefined);
1932
+ return keys.length === otherKeys.length && keys.every(key => Object.prototype.hasOwnProperty.call(right, key)
1933
+ && sameAuthoringValue(left[key], right[key]));
1934
+ }
1935
+ }
1936
+
1937
+ const BINDINGS = ['resourcePath', 'horizontalScroll'];
1938
+ const INPUTS = ['config', ...BINDINGS];
1939
+ /** Raw compact schema authorship only; native normalization remains an editor/runtime projection. */
1940
+ function decodeTablePageInputs(value) {
1941
+ let inputs;
1942
+ try {
1943
+ inputs = cloneBoundedUiLayoutJsonDocument(value);
1944
+ }
1945
+ catch {
1946
+ return { document: null, diagnostics: [problem('table.page.json.invalid', '/definition/inputs')] };
1947
+ }
1948
+ const diagnostics = [];
1949
+ extras(inputs, INPUTS, '/definition/inputs', diagnostics);
1950
+ const config = inputs['config'];
1951
+ if (!record(config) || !Array.isArray(config['columns']) || config['columns'].length !== 0
1952
+ || !record(config['columnProjection']) || config['columnProjection']['source'] !== 'schema')
1953
+ diagnostics.push(problem('table.page.config.schema-required', '/definition/inputs/config'));
1954
+ if (record(config))
1955
+ nulls(config, '/definition/inputs/config', diagnostics);
1956
+ if (Object.prototype.hasOwnProperty.call(inputs, 'resourcePath') && inputs['resourcePath'] !== null && (typeof inputs['resourcePath'] !== 'string' || [...inputs['resourcePath']].length > 1024))
1957
+ diagnostics.push(problem('table.page.resourcePath.invalid', '/definition/inputs/resourcePath'));
1958
+ if (Object.prototype.hasOwnProperty.call(inputs, 'horizontalScroll') && !['auto', 'wrap', 'none'].includes(inputs['horizontalScroll']))
1959
+ diagnostics.push(problem('table.page.horizontalScroll.invalid', '/definition/inputs/horizontalScroll'));
1960
+ const bindings = Object.fromEntries(BINDINGS.filter(key => Object.prototype.hasOwnProperty.call(inputs, key)).map(key => [key, inputs[key]]));
1961
+ const document = { kind: 'praxis.table.editor', version: 1, config, ...(Object.keys(bindings).length ? { bindings } : {}) };
1962
+ if (!diagnostics.length) {
1963
+ try {
1964
+ diagnostics.push(...validateTableAuthoringDocument(document).filter(d => d.level === 'error').map(d => ({ ...d, path: nativePath(d.path) })));
1965
+ }
1966
+ catch {
1967
+ diagnostics.push(problem('table.page.native.invalid', '/definition/inputs/config'));
1968
+ }
1969
+ }
1970
+ if (!diagnostics.length) {
1971
+ try {
1972
+ cloneBoundedUiLayoutJsonDocument(document);
1973
+ }
1974
+ catch {
1975
+ diagnostics.push(problem('table.page.json.invalid', '/definition/inputs'));
1976
+ }
1977
+ }
1978
+ return { document: diagnostics.length ? null : document, diagnostics };
1979
+ }
1980
+ /** Core prefixes these widget-relative JSON Pointers; this callback never resolves a source/latest. */
1981
+ function validateTablePageWidget(widget) {
1982
+ if (widget.definition.id !== 'praxis-table')
1983
+ return [{ code: 'table.page.component.invalid', path: '/definition/id' }];
1984
+ return decodeTablePageInputs(widget.definition.inputs).diagnostics.map(d => ({ code: d.code, path: d.path ?? '/definition/inputs' }));
1985
+ }
1986
+ function encodeTablePageInputs(value) {
1987
+ let document;
1988
+ try {
1989
+ document = cloneBoundedUiLayoutJsonDocument(value);
1990
+ }
1991
+ catch {
1992
+ return { inputs: null, diagnostics: [problem('table.page.json.invalid', '/')] };
1993
+ }
1994
+ const diagnostics = [];
1995
+ extras(document, ['kind', 'version', 'config', 'bindings'], '', diagnostics);
1996
+ if (document['kind'] !== 'praxis.table.editor' || document['version'] !== 1)
1997
+ diagnostics.push(problem('table.page.native.invalid', '/'));
1998
+ const inputs = { config: document['config'] };
1999
+ if (Object.prototype.hasOwnProperty.call(document, 'bindings')) {
2000
+ const bindings = document['bindings'];
2001
+ if (!record(bindings) || !Object.keys(bindings).length)
2002
+ diagnostics.push(problem('table.page.envelope.unrepresentable', '/bindings'));
2003
+ else {
2004
+ extras(bindings, BINDINGS, '/bindings', diagnostics);
2005
+ Object.assign(inputs, bindings);
2006
+ }
2007
+ }
2008
+ const decoded = diagnostics.length ? null : decodeTablePageInputs(inputs);
2009
+ return { inputs: diagnostics.length || decoded?.diagnostics.length ? null : inputs, diagnostics: [...diagnostics, ...(decoded?.diagnostics ?? [])] };
2010
+ }
2011
+ /** No-change values in a materialized native editor cannot author defaults or erase absent keys. */
2012
+ function projectTablePageEditorChanges(authoredInputs, editorBaseline, editorValue) {
2013
+ const original = decodeTablePageInputs(authoredInputs);
2014
+ if (!original.document)
2015
+ return { inputs: null, diagnostics: original.diagnostics };
2016
+ let baseline;
2017
+ let edited;
2018
+ try {
2019
+ baseline = cloneBoundedUiLayoutJsonDocument(editorBaseline);
2020
+ edited = cloneBoundedUiLayoutJsonDocument(editorValue);
2021
+ }
2022
+ catch {
2023
+ return { inputs: null, diagnostics: [problem('table.page.json.invalid', '/')] };
2024
+ }
2025
+ const authored = original.document;
2026
+ // Native config delta has schema-column projection semantics; envelope delta is plain JSON.
2027
+ let candidate;
2028
+ try {
2029
+ candidate = applyTableAuthoringChanges(authored, baseline, edited);
2030
+ candidate['config'] = applyTableAuthoringChanges(authored['config'], baseline['config'], edited['config']);
2031
+ }
2032
+ catch {
2033
+ return { inputs: null, diagnostics: [problem('table.page.editor.invalid', '/definition/inputs/config')] };
2034
+ }
2035
+ const before = { ...authored };
2036
+ const after = { ...candidate };
2037
+ delete before['config'];
2038
+ delete after['config'];
2039
+ if (uiLayoutJsonIdentity(before) !== uiLayoutJsonIdentity(after))
2040
+ return { inputs: null, diagnostics: [problem('table.page.seed.replacement-required', '/definition/inputs')] };
2041
+ return encodeTablePageInputs(candidate);
2042
+ }
2043
+ function extras(source, allowed, path, diagnostics) {
2044
+ for (const key of Object.keys(source))
2045
+ if (!allowed.includes(key))
2046
+ diagnostics.push(problem('table.page.profile.unsupported', path + '/' + pointer(key)));
2047
+ }
2048
+ function nulls(value, path, diagnostics) {
2049
+ if (value === null)
2050
+ diagnostics.push(problem('table.page.config.null', path));
2051
+ else if (Array.isArray(value))
2052
+ value.forEach((item, index) => nulls(item, path + '/' + index, diagnostics));
2053
+ else if (record(value))
2054
+ Object.entries(value).forEach(([key, item]) => nulls(item, path + '/' + pointer(key), diagnostics));
2055
+ }
2056
+ function pointer(key) { return key.replace(/~/g, '~0').replace(/\//g, '~1'); }
2057
+ function record(value) { return value !== null && typeof value === 'object' && !Array.isArray(value); }
2058
+ function problem(code, path) { return { level: 'error', code, path, message: code }; }
2059
+ /** Derive execution-only identity and disable independent preferences. Never persist this projection. */
2060
+ function materializeTablePageRuntimeInputs(value, pageId, widgetKey, options) {
2061
+ const decoded = decodeTablePageInputs(value);
2062
+ if (!decoded.document)
2063
+ return { inputs: null, diagnostics: decoded.diagnostics };
2064
+ let id;
2065
+ try {
2066
+ id = derivePageChildRuntimeId(pageId, widgetKey);
2067
+ }
2068
+ catch {
2069
+ return { inputs: null, diagnostics: [problem('table.page.identity.invalid', '/key')] };
2070
+ }
2071
+ const cloned = cloneBoundedUiLayoutJsonDocument(value);
2072
+ if (options?.preview && record(cloned['config'])) {
2073
+ const previewConfig = { ...cloned['config'] };
2074
+ if (record(previewConfig['actions'])) {
2075
+ const actions = { ...previewConfig['actions'] };
2076
+ if (record(actions['row'])) {
2077
+ actions['row'] = {
2078
+ ...actions['row'],
2079
+ edit: false,
2080
+ delete: false,
2081
+ duplicate: false,
2082
+ custom: [],
2083
+ };
2084
+ }
2085
+ if (record(actions['toolbar'])) {
2086
+ actions['toolbar'] = {
2087
+ ...actions['toolbar'],
2088
+ add: false,
2089
+ create: false,
2090
+ delete: false,
2091
+ import: false,
2092
+ custom: [],
2093
+ };
2094
+ }
2095
+ if (record(actions['bulk'])) {
2096
+ actions['bulk'] = {
2097
+ ...actions['bulk'],
2098
+ enabled: false,
2099
+ actions: [],
2100
+ };
2101
+ }
2102
+ previewConfig['actions'] = actions;
2103
+ }
2104
+ if (record(previewConfig['editing'])) {
2105
+ previewConfig['editing'] = {
2106
+ ...previewConfig['editing'],
2107
+ enabled: false,
2108
+ };
2109
+ }
2110
+ cloned['config'] = previewConfig;
2111
+ }
2112
+ return {
2113
+ inputs: {
2114
+ ...cloned,
2115
+ tableId: id,
2116
+ componentInstanceId: id,
2117
+ configPersistenceStrategy: 'volatile',
2118
+ enableCustomization: false,
2119
+ },
2120
+ diagnostics: [],
2121
+ };
2122
+ }
2123
+ const TABLE_GOVERNED_PAGE_PREVIEW_ADAPTER = {
2124
+ widgetDefinitionId: 'praxis-table',
2125
+ certifiedForInteractivePreview: true,
2126
+ validate: validateTablePageWidget,
2127
+ materializePreviewInputs: (widget, pageId) => {
2128
+ const materialized = materializeTablePageRuntimeInputs(widget.definition.inputs, pageId, widget.key, { preview: true });
2129
+ if (!materialized.inputs) {
2130
+ throw new Error(materialized.diagnostics[0]?.code ?? 'table.page.preview.invalid');
2131
+ }
2132
+ return materialized.inputs;
2133
+ },
2134
+ };
2135
+ function nativePath(value) {
2136
+ // The native dot-path protocol does not escape dynamic field identities. Its
2137
+ // overrides ancestor is precise; splitting that field would invent a pointer.
2138
+ if (value?.startsWith('config.columnProjection.overrides.'))
2139
+ return '/definition/inputs/config/columnProjection/overrides';
2140
+ const parts = (value ?? 'config').replace(/\[(\d+)\]/g, '.$1').split('.');
2141
+ if (parts[0] === 'bindings')
2142
+ parts.shift();
2143
+ return '/definition/inputs/' + parts.map(pointer).join('/');
2144
+ }
2145
+
1459
2146
  /**
1460
2147
  * Generated bundle index. Do not edit.
1461
2148
  */
1462
2149
 
1463
- export { buildTableApplyPlan, createTableAuthoringDocument, deriveTableEditorDocument, normalizeTableAuthoringDocument, parseLegacyOrTableDocument, serializeTableAuthoringDocument, toCanonicalTableConfig, validateTableAuthoringDocument };
2150
+ export { TABLE_GOVERNED_PAGE_PREVIEW_ADAPTER, buildTableApplyPlan, createTableAuthoringDocument, decodeTablePageInputs, deriveTableEditorDocument, encodeTablePageInputs, materializeTablePageRuntimeInputs, normalizeTableAuthoringDocument, parseLegacyOrTableDocument, projectTablePageEditorChanges, serializeTableAuthoringDocument, toCanonicalTableConfig, validateTableAuthoringDocument, validateTablePageWidget };