@cellaware/utils 8.1.12 → 8.2.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.
@@ -124,5 +124,8 @@ export declare function codifyCondition(condition: DatagridCondition): string;
124
124
  */
125
125
  export declare function stripNumericValueFormat(value: string | number | undefined): any;
126
126
  export declare function transformDatagrid(rows: any[], datagridState: DatagridStateBase, locale: string, condition?: DatagridCondition): DatagridState;
127
- export declare function datagridToHtml(datagridState: DatagridState): string;
127
+ export declare function datagridToString(datagridState: DatagridState): {
128
+ html: string;
129
+ markdown: string;
130
+ };
128
131
  export {};
@@ -723,6 +723,8 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
723
723
  rows = filterRows(rows, filterModel);
724
724
  const chartRowData = [];
725
725
  // IMPORTANT: we evaluate the datagrid condition AFTER we are done with all transformations.
726
+ // NOTE: we do not need any pivot columns for pivot mode to be valid.
727
+ // https://chatwms.io/user-manual/chatwms/faq#q-do-i-have-to-have-a-group-column-to-just-display-a-count-in-the-datagrid
726
728
  if (isPivotMode && valueCols.length > 0) {
727
729
  const pivotOutput = pivotData(rows, rowGroupCols, pivotCols, valueCols);
728
730
  rows = pivotOutput.rows;
@@ -806,32 +808,45 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
806
808
  }
807
809
  return { ...datagridState, adjRowData: rows, chartRowData };
808
810
  }
809
- export function datagridToHtml(datagridState) {
810
- let buf = '';
811
+ export function datagridToString(datagridState) {
812
+ let htmlBuf = '';
813
+ let markdownBuf = '';
811
814
  if (datagridState.adjRowData.length === 0) {
812
- return buf;
815
+ return {
816
+ html: htmlBuf,
817
+ markdown: markdownBuf
818
+ };
813
819
  }
814
820
  const columnFormats = datagridState.columnFormats ?? [];
815
821
  if (columnFormats.length === 0) {
816
- return buf;
822
+ return {
823
+ html: htmlBuf,
824
+ markdown: markdownBuf
825
+ };
817
826
  }
818
827
  // Header:
819
- buf += '<table>\n\t<thead>\n\t\t<tr>';
828
+ htmlBuf += '<table>\n\t<thead>\n\t\t<tr>';
820
829
  let columns = [];
821
830
  for (const key in datagridState.adjRowData[0]) {
822
831
  columns.push(key);
823
- buf += `\n\t\t\t<th>${key}</th>`;
832
+ htmlBuf += `\n\t\t\t<th>${key}</th>`;
833
+ markdownBuf += `| ${key} `;
834
+ }
835
+ markdownBuf += '|\n';
836
+ for (const _ of columns) {
837
+ markdownBuf += `| ----- `;
824
838
  }
825
- buf += '\n\t\t</tr>\n\t</thead>';
839
+ markdownBuf += '|\n';
840
+ htmlBuf += '\n\t\t</tr>\n\t</thead>';
826
841
  // Rows:
827
- buf += '\n\t<tbody>';
842
+ htmlBuf += '\n\t<tbody>';
828
843
  let rowIdx = 0;
829
844
  for (const row of datagridState.adjRowData) {
830
845
  let colIdx = 0;
831
846
  const rowStyles = [];
832
847
  const colStyles = [];
833
848
  let cellValues = [];
834
- // Extract cell values and row/column styles first, then write to html.
849
+ // Extract cell values and row/column styles first, then write to html & markdown.
835
850
  for (const key in row) {
836
851
  let val = row[key];
837
852
  if (val instanceof Date) {
@@ -864,25 +879,30 @@ export function datagridToHtml(datagridState) {
864
879
  }
865
880
  // Apply row styles.
866
881
  if (rowStyles.length > 0) {
867
- buf += `\n\t\t<tr class="${rowStyles.join(' ')}">`;
882
+ htmlBuf += `\n\t\t<tr class="${rowStyles.join(' ')}">`;
868
883
  }
869
884
  else {
870
- buf += '\n\t\t<tr>';
885
+ htmlBuf += '\n\t\t<tr>';
871
886
  }
872
887
  // Write cell values with styles.
873
888
  colIdx = 0;
874
889
  for (const rowValue of cellValues) {
875
890
  if (colStyles[colIdx].styles.length > 0) {
876
- buf += `\n\t\t\t<td class="${colStyles[colIdx].styles.join(' ')}">${rowValue}</td>`;
891
+ htmlBuf += `\n\t\t\t<td class="${colStyles[colIdx].styles.join(' ')}">${rowValue}</td>`;
877
892
  }
878
893
  else {
879
- buf += `\n\t\t\t<td>${rowValue}</td>`;
894
+ htmlBuf += `\n\t\t\t<td>${rowValue}</td>`;
880
895
  }
896
+ markdownBuf += `| ${rowValue} `;
881
897
  colIdx++;
882
898
  }
883
- buf += '\n\t\t</tr>';
899
+ htmlBuf += '\n\t\t</tr>';
900
+ markdownBuf += '|\n';
884
901
  rowIdx++;
885
902
  }
886
- buf += '\n\t</tbody>\n</table>';
887
- return buf;
903
+ htmlBuf += '\n\t</tbody>\n</table>';
904
+ return {
905
+ html: htmlBuf,
906
+ markdown: markdownBuf
907
+ };
888
908
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cellaware/utils",
3
- "version": "8.1.12",
3
+ "version": "8.2.0",
4
4
  "description": "Cellaware Utilities for Node.js",
5
5
  "author": "Cellaware Technologies",
6
6
  "type": "module",