@masterteam/components 0.0.351 → 0.0.352

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.
@@ -739,6 +739,7 @@
739
739
  "uploadUnavailable": "رفع الملفات غير متاح حالياً.",
740
740
  "uploadFailed": "تعذّر رفع الملف. يرجى المحاولة مرة أخرى.",
741
741
  "invalidFileType": "يُسمح فقط بأنواع الملفات التالية: {{types}}",
742
+ "invalidImage": "الملف المحدد ليس صورة صالحة",
742
743
  "invalid": "حقل غير صحيح: {{key}}"
743
744
  },
744
745
  "clientComponents": {
@@ -739,6 +739,7 @@
739
739
  "uploadUnavailable": "File upload is currently unavailable.",
740
740
  "uploadFailed": "File upload failed. Please try again.",
741
741
  "invalidFileType": "Only the following file types are allowed: {{types}}",
742
+ "invalidImage": "The selected file is not a valid image",
742
743
  "invalid": "Invalid field: {{key}}"
743
744
  },
744
745
  "clientComponents": {
@@ -14,7 +14,7 @@ import { Avatar } from '@masterteam/components/avatar';
14
14
  import * as i1 from 'primeng/tieredmenu';
15
15
  import { TieredMenuModule } from 'primeng/tieredmenu';
16
16
  import { Drawer } from '@masterteam/components/drawer';
17
- import { resolvePerformanceScoreStatus, parsePerformanceScore, EntityPreview } from '@masterteam/components/entities';
17
+ import { resolvePerformanceScoreStatus, parsePerformanceScore, normalizeNumerals, EntityPreview } from '@masterteam/components/entities';
18
18
  import { parseClockTime, clockTimeToSeconds, toClockTimeParts, MTDateFormatPipe } from '@masterteam/components';
19
19
  import { DateField } from '@masterteam/components/date-field';
20
20
  import { NumberField } from '@masterteam/components/number-field';
@@ -772,6 +772,22 @@ class TableValueResolver {
772
772
  }
773
773
  return String(value);
774
774
  }
775
+ /**
776
+ * The entity as its cell shows it: a submitted ChangeRequest's "after" side
777
+ * replaces `value`. `rawValue` is left as it was, so a caller that reads it
778
+ * must skip it for a comparison cell (it still holds the pre-change figure).
779
+ */
780
+ static unwrapComparison(entityData) {
781
+ if (entityData.comparison?.kind !== 'Value') {
782
+ return entityData;
783
+ }
784
+ const after = entityData.comparison.newValue;
785
+ return {
786
+ ...entityData,
787
+ value: (after.display ?? after.value ?? ''),
788
+ comparison: undefined,
789
+ };
790
+ }
775
791
  static getEntityValueByType(value, usage) {
776
792
  if (value === null || value === undefined) {
777
793
  return null;
@@ -785,12 +801,7 @@ class TableValueResolver {
785
801
  // export/sort/filter must resolve that same new value — not `entityData.value`,
786
802
  // which is the pre-change base and would export identically for every row.
787
803
  if (entityData.comparison?.kind === 'Value') {
788
- const after = entityData.comparison.newValue;
789
- return TableValueResolver.getEntityValueByType({
790
- ...entityData,
791
- value: (after.display ?? after.value ?? ''),
792
- comparison: undefined,
793
- }, usage);
804
+ return TableValueResolver.getEntityValueByType(TableValueResolver.unwrapComparison(entityData), usage);
794
805
  }
795
806
  if (usage === 'sort' &&
796
807
  TableValueResolver.UNSORTABLE_ENTITY_VIEW_TYPES.has(entityData.viewType)) {
@@ -1542,6 +1553,105 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
1542
1553
  ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<mt-button\r\n (onClick)=\"open(popover, $event)\"\r\n [icon]=\"\r\n hasActiveValue() ? 'general.filter-funnel-02' : 'general.filter-funnel-01'\r\n \"\r\n [severity]=\"hasActiveValue() ? 'primary' : 'secondary'\"\r\n variant=\"text\"\r\n size=\"small\"\r\n [tooltip]=\"'components.table.filter' | transloco\"\r\n styleClass=\"!p-1 !text-sm\"\r\n/>\r\n\r\n<p-popover #popover [style]=\"{ width: '280px' }\" appendTo=\"body\">\r\n <div class=\"flex flex-col gap-3\" (keydown.enter)=\"apply(popover)\">\r\n <h4\r\n class=\"text-sm font-semibold text-gray-700 dark:text-gray-300 truncate\"\r\n [title]=\"column().filterConfig?.label || column().label\"\r\n >\r\n {{ column().filterConfig?.label || column().label }}\r\n </h4>\r\n\r\n <mt-table-filter-field\r\n [column]=\"column()\"\r\n [value]=\"pendingValue()\"\r\n (valueChange)=\"pendingValue.set($event)\"\r\n />\r\n\r\n <div\r\n class=\"flex justify-end gap-2 pt-2 border-t border-surface-200 dark:border-surface-700\"\r\n >\r\n <mt-button\r\n variant=\"outlined\"\r\n size=\"small\"\r\n (onClick)=\"clear(popover)\"\r\n [label]=\"'components.table.reset' | transloco\"\r\n />\r\n <mt-button\r\n size=\"small\"\r\n (onClick)=\"apply(popover)\"\r\n [disabled]=\"hasReversedDateRange()\"\r\n [label]=\"'components.table.apply' | transloco\"\r\n />\r\n </div>\r\n </div>\r\n</p-popover>\r\n" }]
1543
1554
  }], ctorParameters: () => [], propDecorators: { column: [{ type: i0.Input, args: [{ isSignal: true, alias: "column", required: true }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }], filterChange: [{ type: i0.Output, args: ["filterChange"] }], popoverRef: [{ type: i0.ViewChild, args: ['popover', { isSignal: true }] }] } });
1544
1555
 
1556
+ const NUMERIC_VIEW_TYPES = new Set(['Number', 'Percentage', 'Currency']);
1557
+ const MAX_FORMAT_DECIMALS = 6;
1558
+ const NUMBER_TOKEN = /[+-]?\d[\d,]*(?:\.\d+)?/;
1559
+ function parseNumber(source) {
1560
+ if (typeof source === 'number') {
1561
+ return Number.isFinite(source)
1562
+ ? { value: source, prefix: '', suffix: '', decimals: 0, grouped: false }
1563
+ : null;
1564
+ }
1565
+ if (typeof source !== 'string') {
1566
+ return null;
1567
+ }
1568
+ const text = normalizeNumerals(source);
1569
+ const match = NUMBER_TOKEN.exec(text);
1570
+ if (!match) {
1571
+ return null;
1572
+ }
1573
+ const prefix = text.slice(0, match.index).trimStart();
1574
+ const suffix = text.slice(match.index + match[0].length).trimEnd();
1575
+ // A second number ('1-2', '10 / 20') is not one figure: leave it as text.
1576
+ if (/\d/.test(prefix) || /\d/.test(suffix)) {
1577
+ return null;
1578
+ }
1579
+ const value = Number.parseFloat(match[0].replace(/,/g, ''));
1580
+ if (!Number.isFinite(value)) {
1581
+ return null;
1582
+ }
1583
+ return {
1584
+ value,
1585
+ prefix,
1586
+ suffix,
1587
+ decimals: /\.(\d+)/.exec(match[0])?.[1]?.length ?? 0,
1588
+ grouped: match[0].includes(','),
1589
+ };
1590
+ }
1591
+ /** A unit as an Excel literal. `"` cannot be escaped inside one, so drop it. */
1592
+ function literal(unit) {
1593
+ const clean = unit.replace(/"/g, '');
1594
+ return clean ? `"${clean}"` : '';
1595
+ }
1596
+ function numberFormat(display) {
1597
+ const digits = Math.min(display.decimals, MAX_FORMAT_DECIMALS);
1598
+ const body = (display.grouped ? '#,##0' : '0') +
1599
+ (digits ? `.${'0'.repeat(digits)}` : '');
1600
+ const format = `${literal(display.prefix)}${body}${literal(display.suffix)}`;
1601
+ return format === '0' ? null : format;
1602
+ }
1603
+ /** points / 100 without binary noise (78.3 / 100 → 0.783, not 0.7829999…). */
1604
+ function toFraction(points) {
1605
+ return Number((points / 100).toPrecision(15));
1606
+ }
1607
+ /**
1608
+ * The Excel cell for a Number / Percentage / Currency entity, or `null` when
1609
+ * the entity is not one of those or holds no single figure (text stays text).
1610
+ *
1611
+ * The number comes from `rawValue` (the same source the on-screen percentage
1612
+ * reads), falling back to `value`; the display form decides the unit and
1613
+ * decimals, so the sheet reads like the screen while SUM stays exact.
1614
+ */
1615
+ function resolveEntityExcelCell(entity) {
1616
+ if (!entity || typeof entity !== 'object') {
1617
+ return null;
1618
+ }
1619
+ const source = entity;
1620
+ if (!NUMERIC_VIEW_TYPES.has(source.viewType)) {
1621
+ return null;
1622
+ }
1623
+ const isComparison = source.comparison?.kind === 'Value';
1624
+ const resolved = TableValueResolver.unwrapComparison(source);
1625
+ const display = parseNumber(resolved.value);
1626
+ const raw = isComparison ? null : parseNumber(resolved.rawValue);
1627
+ const figure = raw ?? display;
1628
+ if (!figure) {
1629
+ return null;
1630
+ }
1631
+ if (source.viewType === 'Percentage') {
1632
+ return {
1633
+ value: toFraction(figure.value),
1634
+ format: '0.0%',
1635
+ text: `${Number(figure.value.toFixed(1))}%`,
1636
+ };
1637
+ }
1638
+ const format = display ? numberFormat(display) : null;
1639
+ return {
1640
+ value: figure.value,
1641
+ format,
1642
+ text: typeof resolved.value === 'string'
1643
+ ? resolved.value
1644
+ : String(figure.value),
1645
+ };
1646
+ }
1647
+ /** `TableExportConfig.resolveExcelCell` for tables whose entity columns export. */
1648
+ function resolveEntityColumnExcelCell(row, column) {
1649
+ if (column.type !== 'entity') {
1650
+ return null;
1651
+ }
1652
+ return resolveEntityExcelCell(TableValueResolver.getProperty(row, column.key));
1653
+ }
1654
+
1545
1655
  function stripHtmlToPlainText(value) {
1546
1656
  if (value === null || value === undefined) {
1547
1657
  return '';
@@ -1635,7 +1745,8 @@ class TableExportService {
1635
1745
  const worksheet = XLSX.utils.json_to_sheet(labeledRows, {
1636
1746
  header: columns.map((column) => column.label),
1637
1747
  });
1638
- this.configureWorksheet(worksheet, columns, labeledRows);
1748
+ const numericCells = this.writeNumericCells(XLSX, worksheet, config, columns);
1749
+ this.configureWorksheet(worksheet, columns, labeledRows, numericCells);
1639
1750
  const workbook = XLSX.utils.book_new();
1640
1751
  XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
1641
1752
  if (this.isRtlExport()) {
@@ -1788,12 +1899,40 @@ class TableExportService {
1788
1899
  ? stripHtmlToPlainText(value)
1789
1900
  : (value ?? null);
1790
1901
  }
1791
- configureWorksheet(worksheet, columns, rows) {
1902
+ /**
1903
+ * Replaces the cells whose caller offered a numeric form with real number
1904
+ * cells carrying their format. A column-level `exportValue` always wins, and
1905
+ * a cell the hook declines (`null`) is left exactly as `json_to_sheet` wrote
1906
+ * it. Returns the cells by row then column so widths can measure their text.
1907
+ */
1908
+ writeNumericCells(XLSX, worksheet, config, columns) {
1909
+ const resolve = config.resolveExcelCell;
1910
+ if (!resolve) {
1911
+ return [];
1912
+ }
1913
+ return config.rows.map((row, rowIndex) => columns.map((column, columnIndex) => {
1914
+ if (column.exportValue) {
1915
+ return null;
1916
+ }
1917
+ const cell = resolve(row, column);
1918
+ if (!cell) {
1919
+ return null;
1920
+ }
1921
+ worksheet[XLSX.utils.encode_cell({ r: rowIndex + 1, c: columnIndex })] =
1922
+ cell.format
1923
+ ? { t: 'n', v: cell.value, z: cell.format }
1924
+ : { t: 'n', v: cell.value };
1925
+ return cell;
1926
+ }));
1927
+ }
1928
+ configureWorksheet(worksheet, columns, rows, numericCells = []) {
1792
1929
  if (worksheet['!ref']) {
1793
1930
  worksheet['!autofilter'] = { ref: worksheet['!ref'] };
1794
1931
  }
1795
1932
  worksheet['!cols'] = columns.map((column) => {
1796
- const contentWidth = rows.reduce((width, row) => Math.max(width, String(row[column.label] ?? '').length), column.label.length);
1933
+ const columnIndex = columns.indexOf(column);
1934
+ const contentWidth = rows.reduce((width, row, rowIndex) => Math.max(width, (numericCells[rowIndex]?.[columnIndex]?.text ??
1935
+ String(row[column.label] ?? '')).length), column.label.length);
1797
1936
  return { wch: Math.min(50, Math.max(10, contentWidth + 2)) };
1798
1937
  });
1799
1938
  }
@@ -2873,6 +3012,7 @@ class Table {
2873
3012
  columns: this.columns(),
2874
3013
  filename: this.exportFilename(),
2875
3014
  resolveValue: (row, column) => this.getColumnExportValue(row, column),
3015
+ resolveExcelCell: resolveEntityColumnExcelCell,
2876
3016
  });
2877
3017
  }
2878
3018
  printPdf() {
@@ -3642,5 +3782,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
3642
3782
  * Generated bundle index. Do not edit.
3643
3783
  */
3644
3784
 
3645
- export { EMPTY_GROUP_KEY, Table, TableActionsMenu, TableCaption, TableColumnFilter, TableExportService, TableFilter, TableFilterField, TableGroupingController, TableValueResolver };
3785
+ export { EMPTY_GROUP_KEY, Table, TableActionsMenu, TableCaption, TableColumnFilter, TableExportService, TableFilter, TableFilterField, TableGroupingController, TableValueResolver, resolveEntityColumnExcelCell, resolveEntityExcelCell };
3646
3786
  //# sourceMappingURL=masterteam-components-table.mjs.map