@mk-kit/ui 0.41.0 → 0.42.0

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.
@@ -1001,12 +1001,22 @@ class MkTable {
1001
1001
  }
1002
1002
  // --- Export -----------------------------------------------------------------
1003
1003
  /**
1004
- * The table's rows as CSV: current column order, column formatters applied,
1005
- * sorted the way they are shown, tree children flattened under their parent
1006
- * whether or not they are expanded. Downloads the file (default name
1007
- * `table.csv`) and returns the text.
1004
+ * The rows and columns an export writes exactly what {@link exportCsv}
1005
+ * serialises, for other formats (XLSX, PDF, the clipboard, …): rows in
1006
+ * display order with the current sort applied and tree children
1007
+ * (`childrenKey`) flattened under their parent whether or not they are
1008
+ * expanded, optionally only the selected ones; columns in the table's
1009
+ * current order, restricted to `options.columns` when given, each carrying
1010
+ * its header and `format` so what the user saw is what gets written.
1011
+ *
1012
+ * ```ts
1013
+ * const { rows, columns } = table.getExportRows({ selectedOnly: true });
1014
+ * const sheet = rows.map((row) =>
1015
+ * Object.fromEntries(columns.map((c) => [c.header ?? c.key, c.format ? c.format(row[c.key], row) : row[c.key]])),
1016
+ * );
1017
+ * ```
1008
1018
  */
1009
- exportCsv(options = {}) {
1019
+ getExportRows(options = {}) {
1010
1020
  let rows = this.allRows();
1011
1021
  if (options.selectedOnly) {
1012
1022
  const keys = this.selectedKeys();
@@ -1016,7 +1026,17 @@ class MkTable {
1016
1026
  const columns = this.orderedColumns()
1017
1027
  .filter((c) => !only || only.has(c.key))
1018
1028
  .map((c) => ({ key: c.key, header: c.header, format: c.format }));
1019
- // `allRows` is already flat, so no childrenKey is passed through.
1029
+ return { rows, columns };
1030
+ }
1031
+ /**
1032
+ * The table's rows as CSV: current column order, column formatters applied,
1033
+ * sorted the way they are shown, tree children flattened under their parent
1034
+ * whether or not they are expanded. Downloads the file (default name
1035
+ * `table.csv`) and returns the text. Built on {@link getExportRows}.
1036
+ */
1037
+ exportCsv(options = {}) {
1038
+ const { rows, columns } = this.getExportRows(options);
1039
+ // The rows are already flat, so no childrenKey is passed through.
1020
1040
  const csv = mkToCsv(rows, columns, { ...options, childrenKey: undefined });
1021
1041
  if (options.download !== false) {
1022
1042
  let filename = options.filename ?? 'table.csv';