@praxisui/table 10.0.0-rc.5 → 10.0.0-rc.51

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