@masterteam/components 0.0.256 → 0.0.258

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.
@@ -166,6 +166,7 @@ class TableValueResolver {
166
166
  'Currency',
167
167
  'Checkbox',
168
168
  'User',
169
+ 'MultiUser',
169
170
  'Lookup',
170
171
  'LookupMatrix',
171
172
  'PhaseGate',
@@ -184,6 +185,7 @@ class TableValueResolver {
184
185
  'Currency',
185
186
  'Checkbox',
186
187
  'User',
188
+ 'MultiUser',
187
189
  'Lookup',
188
190
  'LookupMatrix',
189
191
  'PhaseGate',
@@ -193,7 +195,9 @@ class TableValueResolver {
193
195
  * meaningful date-range filter, and the stored value is a full instant, so a
194
196
  * date picker would silently filter by day instead of by clock time.
195
197
  */
196
- static FILTERABLE_ENTITY_VIEW_TYPES = new Set(TableValueResolver.ALL_ENTITY_VIEW_TYPES.filter((viewType) => viewType !== 'Attachment' && viewType !== 'Time'));
198
+ static FILTERABLE_ENTITY_VIEW_TYPES = new Set(TableValueResolver.ALL_ENTITY_VIEW_TYPES.filter((viewType) => viewType !== 'Attachment' &&
199
+ viewType !== 'Time' &&
200
+ viewType !== 'MultiUser'));
197
201
  /**
198
202
  * Sentinel `key` value that resolves to the whole row instead of a property
199
203
  * path. Use it when a cell renderer (e.g. `type: 'user'`) needs the full
@@ -681,6 +685,15 @@ class TableValueResolver {
681
685
  // Rich-text value holds HTML (rendered via [innerHTML] on screen).
682
686
  // Strip tags so the export shows clean text instead of <p>…</p> markup.
683
687
  return TableValueResolver.stripHtml(TableValueResolver.resolveDisplayValue(entityData.value));
688
+ case 'MultiUser': {
689
+ const users = Array.isArray(entityData.value)
690
+ ? entityData.value
691
+ : [];
692
+ const names = users
693
+ .map((user) => user.displayName ?? user.name ?? user.userName)
694
+ .filter((name) => typeof name === 'string' && name.trim().length > 0);
695
+ return names.length ? names.join(', ') : null;
696
+ }
684
697
  case 'Status':
685
698
  case 'Lookup':
686
699
  case 'PhaseGate':
@@ -1330,27 +1343,48 @@ class TableExportService {
1330
1343
  static PRINT_ROOT_CLASS = 'mt-printing';
1331
1344
  static PRINT_REGION_CLASS = 'mt-print-region';
1332
1345
  static PRINT_STYLE_ID = 'mt-table-print-style';
1333
- static PRINT_CSS = `
1334
- @media print {
1335
- html.mt-printing body > *:not(.mt-print-region) { display: none !important; }
1336
- html.mt-printing, html.mt-printing body { background: #ffffff !important; }
1337
- .mt-print-region { display: block !important; padding: 16px; color: #111827;
1338
- font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
1339
- .mt-print-region h1 { font-size: 18px; font-weight: 600; margin: 0 0 12px; }
1340
- .mt-print-region table { width: 100%; border-collapse: collapse; font-size: 12px; }
1341
- .mt-print-region th, .mt-print-region td { text-align: start; padding: 6px 8px;
1342
- border: 1px solid #e5e7eb; vertical-align: top; }
1343
- .mt-print-region thead th { background: #f3f4f6; font-weight: 600; }
1344
- .mt-print-region tbody tr { break-inside: avoid; page-break-inside: avoid; }
1345
- }
1346
- .mt-print-region { display: none; }
1346
+ static MAX_PRINT_COLUMNS_PER_TABLE = 8;
1347
+ static RTL_LANGUAGES = /^(ar|fa|he|ur)(?:-|$)/i;
1348
+ transloco = inject(TranslocoService);
1349
+ static PRINT_CSS = `
1350
+ @media print {
1351
+ html.mt-printing body > *:not(.mt-print-region) { display: none !important; }
1352
+ html.mt-printing, html.mt-printing body { width: 100% !important; height: auto !important;
1353
+ overflow: visible !important; background: #ffffff !important; }
1354
+ .mt-print-region { display: block !important; width: 100%; max-width: 100%;
1355
+ box-sizing: border-box; overflow: visible !important; padding: 16px; color: #111827;
1356
+ font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
1357
+ .mt-print-region h1 { font-size: 18px; font-weight: 600; margin: 0 0 12px; }
1358
+ .mt-print-region table { width: 100%; max-width: 100%; table-layout: fixed;
1359
+ border-collapse: collapse; font-size: 12px; }
1360
+ .mt-print-region table + table { margin-top: 16px; }
1361
+ .mt-print-region th, .mt-print-region td { text-align: start; padding: 6px 8px;
1362
+ border: 1px solid #e5e7eb; vertical-align: top; white-space: normal;
1363
+ overflow-wrap: anywhere; word-break: break-word; }
1364
+ .mt-print-region thead th { background: #f3f4f6; font-weight: 600; }
1365
+ .mt-print-region tbody tr { break-inside: avoid; page-break-inside: avoid; }
1366
+ }
1367
+ .mt-print-region { display: none; }
1347
1368
  `;
1348
1369
  exportToExcel(config) {
1349
- const columns = this.getExportableColumns(config.columns);
1370
+ const workbook = this.buildExcelWorkbook(config);
1371
+ XLSX.writeFileXLSX(workbook, `${this.normalizeFilename(config.filename)}.xlsx`);
1372
+ }
1373
+ buildExcelWorkbook(config) {
1374
+ const columns = this.getExcelExportableColumns(config.columns, config.rows);
1375
+ const labeledRows = this.buildLabeledRows(config.rows, columns, config.resolveValue);
1376
+ const worksheet = XLSX.utils.json_to_sheet(labeledRows, {
1377
+ header: columns.map((column) => column.label),
1378
+ });
1379
+ this.configureWorksheet(worksheet, columns, labeledRows);
1350
1380
  const workbook = XLSX.utils.book_new();
1351
- const worksheet = XLSX.utils.json_to_sheet(this.buildLabeledRows(config.rows, columns, config.resolveValue));
1352
1381
  XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
1353
- XLSX.writeFileXLSX(workbook, `${this.normalizeFilename(config.filename)}.xlsx`);
1382
+ if (this.isRtlExport()) {
1383
+ workbook.Workbook = {
1384
+ Views: [{ RTL: true }],
1385
+ };
1386
+ }
1387
+ return workbook;
1354
1388
  }
1355
1389
  printPdf(config) {
1356
1390
  if (typeof document === 'undefined' || typeof window === 'undefined') {
@@ -1384,30 +1418,37 @@ class TableExportService {
1384
1418
  column.exportable === true ||
1385
1419
  !!column.exportValue));
1386
1420
  }
1421
+ getExcelExportableColumns(columns, rows) {
1422
+ return this.getExportableColumns(columns).filter((column) => {
1423
+ if (column.type !== 'entity')
1424
+ return true;
1425
+ const sampleRow = rows.find((row) => TableValueResolver.getProperty(row, column.key) !== null &&
1426
+ TableValueResolver.getProperty(row, column.key) !== undefined);
1427
+ return (TableValueResolver.getEntityViewType(column, sampleRow) !== 'Attachment');
1428
+ });
1429
+ }
1387
1430
  /**
1388
1431
  * Resolves a single cell's exported/printed scalar. A column-level
1389
- * `exportValue` always wins; entity columns use the dedicated entity
1390
- * resolver; everything else defers to the caller-supplied `resolveValue`.
1432
+ * `exportValue` always wins; everything else defers to the caller-supplied
1433
+ * resolver. The caller owns entity formatting too so Date/DateTime/Time can
1434
+ * use the configured MT formats instead of leaking raw ISO strings.
1391
1435
  */
1392
1436
  resolveCellValue(row, column, resolveValue) {
1393
1437
  if (column.exportValue) {
1394
1438
  return column.exportValue(row);
1395
1439
  }
1396
- if (column.type === 'entity') {
1397
- return TableValueResolver.getEntityValueByType(TableValueResolver.getProperty(row, column.key), 'export');
1398
- }
1399
1440
  return resolveValue(row, column);
1400
1441
  }
1401
1442
  /**
1402
1443
  * Produces rows keyed by column label (Excel header row).
1403
- * Entity columns use the dedicated entity resolver for a clean export value.
1444
+ * Values already passed through the caller's type-aware resolver.
1404
1445
  */
1405
1446
  buildLabeledRows(rows, columns, resolveValue) {
1406
1447
  return rows.map((row) => {
1407
1448
  const labeledRow = {};
1408
1449
  columns.forEach((column) => {
1409
1450
  const cellValue = this.resolveCellValue(row, column, resolveValue);
1410
- labeledRow[column.label] = this.toPlainExportValue(cellValue);
1451
+ labeledRow[column.label] = this.toPlainExportValue(cellValue, true);
1411
1452
  });
1412
1453
  return labeledRow;
1413
1454
  });
@@ -1415,11 +1456,18 @@ class TableExportService {
1415
1456
  buildPrintRegion(config, columns) {
1416
1457
  const region = document.createElement('section');
1417
1458
  region.className = TableExportService.PRINT_REGION_CLASS;
1459
+ region.dir = this.isRtlExport() ? 'rtl' : 'ltr';
1418
1460
  if (config.title) {
1419
1461
  const heading = document.createElement('h1');
1420
1462
  heading.textContent = config.title;
1421
1463
  region.appendChild(heading);
1422
1464
  }
1465
+ this.getPrintColumnGroups(columns).forEach((columnGroup) => {
1466
+ region.appendChild(this.buildPrintTable(config, columnGroup));
1467
+ });
1468
+ return region;
1469
+ }
1470
+ buildPrintTable(config, columns) {
1423
1471
  const table = document.createElement('table');
1424
1472
  const thead = document.createElement('thead');
1425
1473
  const headerRow = document.createElement('tr');
@@ -1436,15 +1484,34 @@ class TableExportService {
1436
1484
  columns.forEach((column) => {
1437
1485
  const td = document.createElement('td');
1438
1486
  const cellValue = this.resolveCellValue(row, column, config.resolveValue);
1439
- const plainValue = this.toPlainExportValue(cellValue);
1487
+ const plainValue = this.toPlainExportValue(cellValue, true);
1440
1488
  td.textContent = plainValue === null ? '' : String(plainValue);
1441
1489
  tr.appendChild(td);
1442
1490
  });
1443
1491
  tbody.appendChild(tr);
1444
1492
  });
1445
1493
  table.appendChild(tbody);
1446
- region.appendChild(table);
1447
- return region;
1494
+ return table;
1495
+ }
1496
+ /**
1497
+ * A browser cannot paginate a table horizontally. Keep wide exports inside
1498
+ * the printable page by splitting them into readable tables and repeating
1499
+ * the first (normally identifying) column in every continuation group.
1500
+ */
1501
+ getPrintColumnGroups(columns) {
1502
+ if (columns.length <= TableExportService.MAX_PRINT_COLUMNS_PER_TABLE) {
1503
+ return [columns];
1504
+ }
1505
+ const [identityColumn, ...remainingColumns] = columns;
1506
+ const continuationSize = TableExportService.MAX_PRINT_COLUMNS_PER_TABLE - 1;
1507
+ const groups = [];
1508
+ for (let index = 0; index < remainingColumns.length; index += continuationSize) {
1509
+ groups.push([
1510
+ identityColumn,
1511
+ ...remainingColumns.slice(index, index + continuationSize),
1512
+ ]);
1513
+ }
1514
+ return groups;
1448
1515
  }
1449
1516
  /**
1450
1517
  * Normalises a resolved cell value for export. Rich-text columns surface their
@@ -1452,11 +1519,34 @@ class TableExportService {
1452
1519
  * removed, entities decoded) before they reach an Excel cell or a PDF table
1453
1520
  * cell. Non-string values (numbers, booleans, dates) pass through untouched.
1454
1521
  */
1455
- toPlainExportValue(value) {
1522
+ toPlainExportValue(value, localizeBoolean) {
1523
+ if (localizeBoolean &&
1524
+ typeof value === 'boolean' &&
1525
+ this.isArabicExport()) {
1526
+ return this.transloco.translate(value ? 'components.table.yes' : 'components.table.no');
1527
+ }
1456
1528
  return typeof value === 'string'
1457
1529
  ? stripHtmlToPlainText(value)
1458
1530
  : (value ?? null);
1459
1531
  }
1532
+ configureWorksheet(worksheet, columns, rows) {
1533
+ if (worksheet['!ref']) {
1534
+ worksheet['!autofilter'] = { ref: worksheet['!ref'] };
1535
+ }
1536
+ worksheet['!cols'] = columns.map((column) => {
1537
+ const contentWidth = rows.reduce((width, row) => Math.max(width, String(row[column.label] ?? '').length), column.label.length);
1538
+ return { wch: Math.min(50, Math.max(10, contentWidth + 2)) };
1539
+ });
1540
+ }
1541
+ isArabicExport() {
1542
+ return /^ar(?:-|$)/i.test(this.transloco.getActiveLang());
1543
+ }
1544
+ isRtlExport() {
1545
+ const language = this.transloco.getActiveLang();
1546
+ const documentIsRtl = typeof document !== 'undefined' &&
1547
+ document.documentElement.dir.toLowerCase() === 'rtl';
1548
+ return TableExportService.RTL_LANGUAGES.test(language) || documentIsRtl;
1549
+ }
1460
1550
  normalizeFilename(value) {
1461
1551
  const sanitized = (value ?? '').trim().replace(/[\\/:*?"<>|]+/g, '-');
1462
1552
  return sanitized.length ? sanitized : 'download';
@@ -2814,7 +2904,7 @@ class Table {
2814
2904
  return null;
2815
2905
  }
2816
2906
  if (column.type === 'entity') {
2817
- return TableValueResolver.getEntityValueByType(cellValue, 'sort');
2907
+ return TableValueResolver.getEntityValueByType(cellValue, 'export');
2818
2908
  }
2819
2909
  if (column.type === 'boolean') {
2820
2910
  return this.getBooleanProperty(row, column.key);