@economic/taco 2.58.2-EC-64962.1 → 2.58.2-EC-64961.1

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.
package/dist/taco.d.ts CHANGED
@@ -3148,6 +3148,25 @@ export declare type TableColumnClassNameHandler<TType = unknown> = string | ((ro
3148
3148
 
3149
3149
  export declare type TableColumnDataType = 'text' | 'number' | 'datetime' | 'boolean' | 'amount';
3150
3150
 
3151
+ export declare type TableColumnDataTypeOptions = {
3152
+ currency?: string;
3153
+ decimals?: number;
3154
+ useGrouping?: boolean;
3155
+ };
3156
+
3157
+ export declare type TableColumnDataTypeOptionsHandler<TType = unknown, TOptions = TableColumnDataTypeOptions> = TOptions | ((row: TType) => TOptions);
3158
+
3159
+ export declare type TableColumnDataTypeProps<TType = unknown> = {
3160
+ dataType?: 'number';
3161
+ dataTypeOptions?: TableColumnDataTypeOptionsHandler<TType, Pick<TableColumnDataTypeOptions, 'currency' | 'decimals' | 'useGrouping'>>;
3162
+ } | {
3163
+ dataType?: 'amount';
3164
+ dataTypeOptions?: TableColumnDataTypeOptionsHandler<TType, Pick<TableColumnDataTypeOptions, 'currency'>>;
3165
+ } | {
3166
+ dataType?: Omit<TableColumnDataType, 'number' | 'amount'>;
3167
+ dataTypeOptions?: never;
3168
+ };
3169
+
3151
3170
  export declare type TableColumnFilter = ColumnFilter;
3152
3171
 
3153
3172
  export declare type TableColumnIdentifierProps<TType = unknown> = {
@@ -3166,7 +3185,7 @@ export declare type TableColumnIdentifierProps<TType = unknown> = {
3166
3185
 
3167
3186
  export declare type TableColumnMenu = ((columnId: string) => React.ReactNode | null)[];
3168
3187
 
3169
- export declare type TableColumnProps<TType = unknown> = TableColumnIdentifierProps<TType> & {
3188
+ export declare type TableColumnProps<TType = unknown> = TableColumnIdentifierProps<TType> & TableColumnDataTypeProps<TType> & {
3170
3189
  control?: TableColumnRendererControl<TType> | undefined;
3171
3190
  footer?: TableColumnRendererFooter<TType> | undefined;
3172
3191
  header: TableColumnRendererHeader;
@@ -3375,7 +3394,7 @@ export declare type TableRowActionRenderer<TType = unknown> = (row: TType, inter
3375
3394
 
3376
3395
  export declare type TableRowClickHandler<TType = unknown> = (row: TType) => void;
3377
3396
 
3378
- export declare type TableRowDragHandler<TType = unknown> = (rows: TType[], showPlaceholder: (string: any) => void, setDataTransfer: (data: string) => void) => void;
3397
+ export declare type TableRowDragHandler<TType = unknown> = (rows: TType[], showPlaceholder: (text: string) => void, setDataTransfer: (data: string) => void) => void;
3379
3398
 
3380
3399
  export declare type TableRowDropHandler<TType = unknown> = (event: React.DragEvent, row: TType) => void;
3381
3400
 
@@ -4046,6 +4065,7 @@ declare module '@tanstack/table-core' {
4046
4065
  className?: TableColumnClassNameHandler<TData>;
4047
4066
  control?: TableColumnRendererControl<TData>;
4048
4067
  dataType?: TableColumnDataType;
4068
+ dataTypeOptions?: TableColumnDataTypeOptions;
4049
4069
  defaultWidth?: number;
4050
4070
  enableEditing?: boolean;
4051
4071
  enableOrdering?: boolean;
package/dist/taco.js CHANGED
@@ -33036,20 +33036,6 @@ const dataTypes = {
33036
33036
  TableFilterComparator.IsNotEmpty
33037
33037
  ]
33038
33038
  },
33039
- number: {
33040
- sortingFn: "basic",
33041
- filterComparators: [
33042
- TableFilterComparator.IsEqualTo,
33043
- TableFilterComparator.IsNotEqualTo,
33044
- TableFilterComparator.IsGreaterThan,
33045
- TableFilterComparator.IsLessThan,
33046
- TableFilterComparator.IsGreaterThanOrEqualTo,
33047
- TableFilterComparator.IsLessThanOrEqualTo,
33048
- TableFilterComparator.IsBetween,
33049
- TableFilterComparator.IsEmpty,
33050
- TableFilterComparator.IsNotEmpty
33051
- ]
33052
- },
33053
33039
  datetime: {
33054
33040
  sortingFn: "datetime",
33055
33041
  filterComparators: [
@@ -33063,7 +33049,7 @@ const dataTypes = {
33063
33049
  TableFilterComparator.IsEmpty,
33064
33050
  TableFilterComparator.IsNotEmpty
33065
33051
  ],
33066
- getDisplayValue: (value, options) => {
33052
+ getDisplayValue: (value, _1, options) => {
33067
33053
  var _a;
33068
33054
  return format$1(value, (_a = options == null ? void 0 : options.localization) == null ? void 0 : _a.formatting.date) ?? "";
33069
33055
  }
@@ -33072,9 +33058,13 @@ const dataTypes = {
33072
33058
  sortingFn: "basic",
33073
33059
  filterComparators: [TableFilterComparator.IsEqualTo, TableFilterComparator.IsNotEqualTo]
33074
33060
  },
33075
- // advanced
33076
- amount: {
33077
- align: "right",
33061
+ // numbers
33062
+ number: createNumberDataType("left"),
33063
+ amount: createNumberDataType("right", { decimals: 2, useGrouping: true })
33064
+ };
33065
+ function createNumberDataType(align, defaultOptions2) {
33066
+ return {
33067
+ align,
33078
33068
  sortingFn: "basic",
33079
33069
  filterComparators: [
33080
33070
  TableFilterComparator.IsEqualTo,
@@ -33087,19 +33077,38 @@ const dataTypes = {
33087
33077
  TableFilterComparator.IsEmpty,
33088
33078
  TableFilterComparator.IsNotEmpty
33089
33079
  ],
33090
- getDisplayValue: (value, options) => {
33091
- var _a;
33080
+ getDisplayValue: (value, row, options) => {
33081
+ var _a, _b;
33092
33082
  if (value === void 0) {
33093
33083
  return "";
33094
33084
  }
33095
- const formatter = new Intl.NumberFormat((_a = options == null ? void 0 : options.localization) == null ? void 0 : _a.locale, { minimumFractionDigits: 2 });
33096
- const decimalSeperator = formatter.format(1.1).substring(1, 2);
33097
- const localisedValue = formatter.format(Number(value));
33098
- const localisedValueWithoutThousandsSeperator = decimalSeperator === "." ? localisedValue.replace(",", "") : localisedValue.replace(".", "");
33085
+ const dataTypeOptions = typeof (options == null ? void 0 : options.dataTypeOptions) === "function" ? options == null ? void 0 : options.dataTypeOptions(row) : options == null ? void 0 : options.dataTypeOptions;
33086
+ const numberFormatOptions = {
33087
+ // format
33088
+ useGrouping: (dataTypeOptions == null ? void 0 : dataTypeOptions.useGrouping) ?? (defaultOptions2 == null ? void 0 : defaultOptions2.useGrouping) ?? false,
33089
+ // decimals
33090
+ minimumFractionDigits: (dataTypeOptions == null ? void 0 : dataTypeOptions.decimals) ?? (defaultOptions2 == null ? void 0 : defaultOptions2.decimals),
33091
+ maximumFractionDigits: (dataTypeOptions == null ? void 0 : dataTypeOptions.decimals) ?? (defaultOptions2 == null ? void 0 : defaultOptions2.decimals)
33092
+ };
33093
+ if (dataTypeOptions == null ? void 0 : dataTypeOptions.currency) {
33094
+ numberFormatOptions.style = "currency";
33095
+ numberFormatOptions.currency = dataTypeOptions.currency;
33096
+ numberFormatOptions.currencyDisplay = "code";
33097
+ }
33098
+ const localisedValue = new Intl.NumberFormat((_a = options == null ? void 0 : options.localization) == null ? void 0 : _a.locale, numberFormatOptions).format(
33099
+ Number(value)
33100
+ );
33101
+ if (!numberFormatOptions.useGrouping) {
33102
+ return localisedValue;
33103
+ }
33104
+ const localisedValueWithoutThousandsSeperator = new Intl.NumberFormat((_b = options == null ? void 0 : options.localization) == null ? void 0 : _b.locale, {
33105
+ ...numberFormatOptions,
33106
+ useGrouping: false
33107
+ }).format(Number(value));
33099
33108
  return [localisedValue, localisedValueWithoutThousandsSeperator];
33100
33109
  }
33101
- }
33102
- };
33110
+ };
33111
+ }
33103
33112
  function getDataTypeProperties(dataType) {
33104
33113
  return dataTypes[dataType ?? "text"] ?? dataTypes.text;
33105
33114
  }
@@ -33221,7 +33230,7 @@ function columnFilterFn(value, filter2) {
33221
33230
  const flattenCellValue = (cellValue) => {
33222
33231
  return typeof cellValue === "object" ? Object.values(cellValue).map(flattenCellValue) : cellValue;
33223
33232
  };
33224
- function isMatched(searchQuery, cellValue, dataType, localization) {
33233
+ function isMatched(searchQuery, cellValue, rowValue, dataType, dataTypeOptions, localization) {
33225
33234
  if (typeof cellValue === "object") {
33226
33235
  return flattenCellValue(cellValue).flat(Infinity).find((y4) => isWeakContains(y4, searchQuery));
33227
33236
  } else {
@@ -33231,7 +33240,10 @@ function isMatched(searchQuery, cellValue, dataType, localization) {
33231
33240
  } else {
33232
33241
  const dataTypeProperties = getDataTypeProperties(dataType);
33233
33242
  if (dataTypeProperties.getDisplayValue) {
33234
- const cellDisplayValue = dataTypeProperties.getDisplayValue(cellValue, { localization });
33243
+ const cellDisplayValue = dataTypeProperties.getDisplayValue(cellValue, rowValue, {
33244
+ dataTypeOptions,
33245
+ localization
33246
+ });
33235
33247
  if (Array.isArray(cellDisplayValue)) {
33236
33248
  for (const displayValue of cellDisplayValue) {
33237
33249
  if (isWeakContains(displayValue, searchQuery)) {
@@ -33247,12 +33259,19 @@ function isMatched(searchQuery, cellValue, dataType, localization) {
33247
33259
  return false;
33248
33260
  }
33249
33261
  function globalFilterFn(row, columnId, searchQuery, localization) {
33250
- var _a, _b;
33262
+ var _a;
33251
33263
  try {
33252
33264
  if (row.original) {
33253
33265
  const cellValue = row.original[columnId];
33254
- const dataType = (_b = (_a = row._getAllCellsByColumnId()[columnId]) == null ? void 0 : _a.column.columnDef.meta) == null ? void 0 : _b.dataType;
33255
- return isMatched(searchQuery, cellValue, dataType, localization);
33266
+ const columnMeta = (_a = row._getAllCellsByColumnId()[columnId]) == null ? void 0 : _a.column.columnDef.meta;
33267
+ return isMatched(
33268
+ searchQuery,
33269
+ cellValue,
33270
+ row.original,
33271
+ columnMeta == null ? void 0 : columnMeta.dataType,
33272
+ columnMeta == null ? void 0 : columnMeta.dataTypeOptions,
33273
+ localization
33274
+ );
33256
33275
  }
33257
33276
  } catch {
33258
33277
  }
@@ -33267,7 +33286,7 @@ function resetHighlightedColumnIndexes(searchQuery, table, localization) {
33267
33286
  const rowGrouping = table.getState().grouping;
33268
33287
  table.getRowModel().rows.forEach((row, rowIndex) => {
33269
33288
  columns.forEach((column, columnIndex) => {
33270
- var _a;
33289
+ var _a, _b;
33271
33290
  try {
33272
33291
  let allowSearch = true;
33273
33292
  if (rowGrouping == null ? void 0 : rowGrouping.length) {
@@ -33280,7 +33299,8 @@ function resetHighlightedColumnIndexes(searchQuery, table, localization) {
33280
33299
  if (column.getIsVisible() && column.columnDef.enableGlobalFilter && allowSearch) {
33281
33300
  const cellValue = get(row.original, column.id);
33282
33301
  const dataType = (_a = column.columnDef.meta) == null ? void 0 : _a.dataType;
33283
- if (isMatched(searchQuery, cellValue, dataType, localization)) {
33302
+ const dataTypeOptions = (_b = column.columnDef.meta) == null ? void 0 : _b.dataTypeOptions;
33303
+ if (isMatched(searchQuery, cellValue, row.original, dataType, dataTypeOptions, localization)) {
33284
33304
  indexes.push([rowIndex, columnIndex]);
33285
33305
  }
33286
33306
  }
@@ -33519,9 +33539,12 @@ function processChildren(child, columns, defaultSizing, defaultSorting, defaultV
33519
33539
  header
33520
33540
  }
33521
33541
  };
33522
- const formattedValueRenderer = (value) => {
33542
+ const formattedValueRenderer = (value, row) => {
33523
33543
  var _a;
33524
- const displayValue = (_a = dataTypeProperties.getDisplayValue) == null ? void 0 : _a.call(dataTypeProperties, value, { localization });
33544
+ const displayValue = (_a = dataTypeProperties.getDisplayValue) == null ? void 0 : _a.call(dataTypeProperties, value, row, {
33545
+ dataTypeOptions: meta.dataTypeOptions,
33546
+ localization
33547
+ });
33525
33548
  const safeValue = value !== void 0 && value !== null ? String(value) : value;
33526
33549
  if (Array.isArray(displayValue)) {
33527
33550
  return displayValue[0] ?? safeValue;
@@ -33529,14 +33552,14 @@ function processChildren(child, columns, defaultSizing, defaultSorting, defaultV
33529
33552
  return displayValue ?? safeValue;
33530
33553
  };
33531
33554
  const rendererArgs = (info) => ({
33532
- formattedValue: formattedValueRenderer(info.getValue()),
33555
+ formattedValue: formattedValueRenderer(info.getValue(), info.row.original),
33533
33556
  row: info.row.original,
33534
33557
  value: info.getValue()
33535
33558
  });
33536
33559
  if (typeof renderer2 === "function") {
33537
33560
  column.cell = (info) => renderer2(rendererArgs(info));
33538
33561
  } else {
33539
- column.cell = (info) => formattedValueRenderer(info.getValue());
33562
+ column.cell = (info) => formattedValueRenderer(info.getValue(), info.row.original);
33540
33563
  }
33541
33564
  if (typeof footer === "function") {
33542
33565
  column.footer = (info) => footer(info.table.getRowModel().rows.flatMap((row) => row.original !== void 0 ? row.original : []));