@fuentis/phoenix-ui 0.0.9-alpha.367 → 0.0.9-alpha.368

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.
@@ -2667,7 +2667,8 @@ function formatDateValue(val, pattern, locale) {
2667
2667
  * Converts raw row values into human-readable strings for export.
2668
2668
  * Handles various column types: DATE, LIST, BOOLEAN, etc.
2669
2669
  */
2670
- function getDisplayValue(row, col, columnTypeMap, columnTypeEnum, t, locale = 'en-US') {
2670
+ function getDisplayValue(row, col, columnTypeMap, columnTypeEnum, t, locale = 'en-US', forCsv = false // 👈 NEW
2671
+ ) {
2671
2672
  const field = col.field;
2672
2673
  const type = columnTypeMap[field] || col.columnType;
2673
2674
  const val = getNestedValue(row, field);
@@ -2681,14 +2682,16 @@ function getDisplayValue(row, col, columnTypeMap, columnTypeEnum, t, locale = 'e
2681
2682
  case columnTypeEnum.TAG:
2682
2683
  return (val?.name ?? val)?.toString();
2683
2684
  case columnTypeEnum.LIST_TAG:
2684
- case columnTypeEnum.LIST:
2685
- return Array.isArray(val)
2686
- ? val.map((x) => (x?.name ?? x)).join(', ')
2687
- : String(val);
2685
+ case columnTypeEnum.LIST: {
2686
+ if (!Array.isArray(val))
2687
+ return String(val);
2688
+ const items = val.map((x) => (x?.name ?? x));
2689
+ // CSV: multi-line in one cell - for Excel
2690
+ return forCsv ? items.join('\n') : items.join(', ');
2691
+ }
2688
2692
  case columnTypeEnum.OBJ_TAG:
2689
2693
  return (val?.value ?? val)?.toString();
2690
2694
  case columnTypeEnum.BOOLEAN: {
2691
- // Translate YES/NO if translation function is provided
2692
2695
  const yes = t ? t('ACTION.YES') : 'Yes';
2693
2696
  const no = t ? t('ACTION.NO') : 'No';
2694
2697
  return (val === true || val === 'true') ? yes : no;
@@ -2706,9 +2709,16 @@ function getDisplayValue(row, col, columnTypeMap, columnTypeEnum, t, locale = 'e
2706
2709
  }
2707
2710
  function trimExcelLineBreaks(s) {
2708
2711
  return s
2709
- .replace(/^[\r\n]+/, '') // remove leading line breaks
2710
- .replace(/[\r\n]+$/, '') // remove trailing line breaks
2711
- .replace(/(\r?\n){2,}/g, '\n'); // collapse multiple to a single
2712
+ // remove leading newlines + spaces
2713
+ .replace(/^[\r\n\s]+/, '')
2714
+ // remove trailing newlines + spaces
2715
+ .replace(/[\r\n\s]+$/, '')
2716
+ // collapse multiple line breaks (with spaces in between) into a single \n
2717
+ .replace(/(\r?\n\s*){2,}/g, '\n')
2718
+ // normalize spaces at the start of lines (trim each line)
2719
+ .split('\n')
2720
+ .map(line => line.trim())
2721
+ .join('\n');
2712
2722
  }
2713
2723
  /**
2714
2724
  * Exports table rows to a PDF file.
@@ -2746,7 +2756,7 @@ function exportRowsToCsv(columns, rows, columnTypeMap, columnTypeEnum, t, fileNa
2746
2756
  const delimiter = options.delimiter || ',';
2747
2757
  const headers = columns.map(c => sanitizeText(t(c.header)));
2748
2758
  const lines = (rows ?? []).map(row => columns.map(col => {
2749
- const raw = getDisplayValue(row, col, columnTypeMap, columnTypeEnum, t, locale);
2759
+ const raw = getDisplayValue(row, col, columnTypeMap, columnTypeEnum, t, locale, true);
2750
2760
  // keep multiline, but remove useless blank line at start/end
2751
2761
  const v = trimExcelLineBreaks(sanitizeText(raw));
2752
2762
  const safe = v.replace(/"/g, '""'); // escape double quotes