@economic/taco 2.58.2-EC-64961.0 → 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
@@ -3149,19 +3149,23 @@ export declare type TableColumnClassNameHandler<TType = unknown> = string | ((ro
3149
3149
  export declare type TableColumnDataType = 'text' | 'number' | 'datetime' | 'boolean' | 'amount';
3150
3150
 
3151
3151
  export declare type TableColumnDataTypeOptions = {
3152
- numberFormatOptions?: Intl.NumberFormatOptions;
3152
+ currency?: string;
3153
+ decimals?: number;
3154
+ useGrouping?: boolean;
3153
3155
  };
3154
3156
 
3155
- export declare type TableColumnDataTypeProps = {
3156
- dataType?: TableColumnDataType;
3157
- dataTypeOptions?: TableColumnDataTypeOptions;
3158
- } & ({
3159
- dataType?: 'number' | 'amount';
3160
- dataTypeOptions?: Pick<TableColumnDataTypeOptions, 'numberFormatOptions'>;
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'>>;
3161
3165
  } | {
3162
3166
  dataType?: Omit<TableColumnDataType, 'number' | 'amount'>;
3163
3167
  dataTypeOptions?: never;
3164
- });
3168
+ };
3165
3169
 
3166
3170
  export declare type TableColumnFilter = ColumnFilter;
3167
3171
 
@@ -3181,7 +3185,7 @@ export declare type TableColumnIdentifierProps<TType = unknown> = {
3181
3185
 
3182
3186
  export declare type TableColumnMenu = ((columnId: string) => React.ReactNode | null)[];
3183
3187
 
3184
- export declare type TableColumnProps<TType = unknown> = TableColumnIdentifierProps<TType> & TableColumnDataTypeProps & {
3188
+ export declare type TableColumnProps<TType = unknown> = TableColumnIdentifierProps<TType> & TableColumnDataTypeProps<TType> & {
3185
3189
  control?: TableColumnRendererControl<TType> | undefined;
3186
3190
  footer?: TableColumnRendererFooter<TType> | undefined;
3187
3191
  header: TableColumnRendererHeader;
package/dist/taco.js CHANGED
@@ -33036,30 +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
- getDisplayValue: (value, options) => {
33053
- var _a, _b, _c;
33054
- if (value === void 0) {
33055
- return "";
33056
- }
33057
- if ((_a = options == null ? void 0 : options.dataTypeOptions) == null ? void 0 : _a.numberFormatOptions) {
33058
- return formatNumber(value, (_b = options == null ? void 0 : options.localization) == null ? void 0 : _b.locale, (_c = options == null ? void 0 : options.dataTypeOptions) == null ? void 0 : _c.numberFormatOptions);
33059
- }
33060
- return String(value);
33061
- }
33062
- },
33063
33039
  datetime: {
33064
33040
  sortingFn: "datetime",
33065
33041
  filterComparators: [
@@ -33073,7 +33049,7 @@ const dataTypes = {
33073
33049
  TableFilterComparator.IsEmpty,
33074
33050
  TableFilterComparator.IsNotEmpty
33075
33051
  ],
33076
- getDisplayValue: (value, options) => {
33052
+ getDisplayValue: (value, _1, options) => {
33077
33053
  var _a;
33078
33054
  return format$1(value, (_a = options == null ? void 0 : options.localization) == null ? void 0 : _a.formatting.date) ?? "";
33079
33055
  }
@@ -33082,9 +33058,13 @@ const dataTypes = {
33082
33058
  sortingFn: "basic",
33083
33059
  filterComparators: [TableFilterComparator.IsEqualTo, TableFilterComparator.IsNotEqualTo]
33084
33060
  },
33085
- // advanced
33086
- amount: {
33087
- 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,
33088
33068
  sortingFn: "basic",
33089
33069
  filterComparators: [
33090
33070
  TableFilterComparator.IsEqualTo,
@@ -33097,28 +33077,37 @@ const dataTypes = {
33097
33077
  TableFilterComparator.IsEmpty,
33098
33078
  TableFilterComparator.IsNotEmpty
33099
33079
  ],
33100
- getDisplayValue: (value, options) => {
33101
- var _a, _b, _c, _d, _e, _f;
33080
+ getDisplayValue: (value, row, options) => {
33081
+ var _a, _b;
33102
33082
  if (value === void 0) {
33103
33083
  return "";
33104
33084
  }
33105
- const min2 = ((_b = (_a = options == null ? void 0 : options.dataTypeOptions) == null ? void 0 : _a.numberFormatOptions) == null ? void 0 : _b.minimumFractionDigits) ?? 2;
33106
- const max2 = ((_d = (_c = options == null ? void 0 : options.dataTypeOptions) == null ? void 0 : _c.numberFormatOptions) == null ? void 0 : _d.maximumFractionDigits) ?? 2;
33085
+ const dataTypeOptions = typeof (options == null ? void 0 : options.dataTypeOptions) === "function" ? options == null ? void 0 : options.dataTypeOptions(row) : options == null ? void 0 : options.dataTypeOptions;
33107
33086
  const numberFormatOptions = {
33108
- minimumFractionDigits: Math.min(min2, max2),
33109
- maximumFractionDigits: Math.max(max2, min2),
33110
- ...(_e = options == null ? void 0 : options.dataTypeOptions) == null ? void 0 : _e.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)
33111
33092
  };
33112
- return formatNumber(value, (_f = options == null ? void 0 : options.localization) == null ? void 0 : _f.locale, numberFormatOptions);
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));
33108
+ return [localisedValue, localisedValueWithoutThousandsSeperator];
33113
33109
  }
33114
- }
33115
- };
33116
- function formatNumber(value, locale2, numberFormatOptions) {
33117
- const formatter = new Intl.NumberFormat(locale2, numberFormatOptions);
33118
- const decimalSeperator = new Intl.NumberFormat(String(locale2 ?? ""), { minimumFractionDigits: 2 }).format(1.1).substring(1, 2);
33119
- const localisedValue = formatter.format(Number(value));
33120
- const localisedValueWithoutThousandsSeperator = decimalSeperator === "." ? localisedValue.replace(",", "") : localisedValue.replace(".", "");
33121
- return [localisedValue, localisedValueWithoutThousandsSeperator];
33110
+ };
33122
33111
  }
33123
33112
  function getDataTypeProperties(dataType) {
33124
33113
  return dataTypes[dataType ?? "text"] ?? dataTypes.text;
@@ -33241,7 +33230,7 @@ function columnFilterFn(value, filter2) {
33241
33230
  const flattenCellValue = (cellValue) => {
33242
33231
  return typeof cellValue === "object" ? Object.values(cellValue).map(flattenCellValue) : cellValue;
33243
33232
  };
33244
- function isMatched(searchQuery, cellValue, dataType, dataTypeOptions, localization) {
33233
+ function isMatched(searchQuery, cellValue, rowValue, dataType, dataTypeOptions, localization) {
33245
33234
  if (typeof cellValue === "object") {
33246
33235
  return flattenCellValue(cellValue).flat(Infinity).find((y4) => isWeakContains(y4, searchQuery));
33247
33236
  } else {
@@ -33251,7 +33240,10 @@ function isMatched(searchQuery, cellValue, dataType, dataTypeOptions, localizati
33251
33240
  } else {
33252
33241
  const dataTypeProperties = getDataTypeProperties(dataType);
33253
33242
  if (dataTypeProperties.getDisplayValue) {
33254
- const cellDisplayValue = dataTypeProperties.getDisplayValue(cellValue, { dataTypeOptions, localization });
33243
+ const cellDisplayValue = dataTypeProperties.getDisplayValue(cellValue, rowValue, {
33244
+ dataTypeOptions,
33245
+ localization
33246
+ });
33255
33247
  if (Array.isArray(cellDisplayValue)) {
33256
33248
  for (const displayValue of cellDisplayValue) {
33257
33249
  if (isWeakContains(displayValue, searchQuery)) {
@@ -33272,7 +33264,14 @@ function globalFilterFn(row, columnId, searchQuery, localization) {
33272
33264
  if (row.original) {
33273
33265
  const cellValue = row.original[columnId];
33274
33266
  const columnMeta = (_a = row._getAllCellsByColumnId()[columnId]) == null ? void 0 : _a.column.columnDef.meta;
33275
- return isMatched(searchQuery, cellValue, columnMeta == null ? void 0 : columnMeta.dataType, columnMeta == null ? void 0 : columnMeta.dataTypeOptions, localization);
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
+ );
33276
33275
  }
33277
33276
  } catch {
33278
33277
  }
@@ -33301,7 +33300,7 @@ function resetHighlightedColumnIndexes(searchQuery, table, localization) {
33301
33300
  const cellValue = get(row.original, column.id);
33302
33301
  const dataType = (_a = column.columnDef.meta) == null ? void 0 : _a.dataType;
33303
33302
  const dataTypeOptions = (_b = column.columnDef.meta) == null ? void 0 : _b.dataTypeOptions;
33304
- if (isMatched(searchQuery, cellValue, dataType, dataTypeOptions, localization)) {
33303
+ if (isMatched(searchQuery, cellValue, row.original, dataType, dataTypeOptions, localization)) {
33305
33304
  indexes.push([rowIndex, columnIndex]);
33306
33305
  }
33307
33306
  }
@@ -33540,9 +33539,9 @@ function processChildren(child, columns, defaultSizing, defaultSorting, defaultV
33540
33539
  header
33541
33540
  }
33542
33541
  };
33543
- const formattedValueRenderer = (value) => {
33542
+ const formattedValueRenderer = (value, row) => {
33544
33543
  var _a;
33545
- const displayValue = (_a = dataTypeProperties.getDisplayValue) == null ? void 0 : _a.call(dataTypeProperties, value, {
33544
+ const displayValue = (_a = dataTypeProperties.getDisplayValue) == null ? void 0 : _a.call(dataTypeProperties, value, row, {
33546
33545
  dataTypeOptions: meta.dataTypeOptions,
33547
33546
  localization
33548
33547
  });
@@ -33553,14 +33552,14 @@ function processChildren(child, columns, defaultSizing, defaultSorting, defaultV
33553
33552
  return displayValue ?? safeValue;
33554
33553
  };
33555
33554
  const rendererArgs = (info) => ({
33556
- formattedValue: formattedValueRenderer(info.getValue()),
33555
+ formattedValue: formattedValueRenderer(info.getValue(), info.row.original),
33557
33556
  row: info.row.original,
33558
33557
  value: info.getValue()
33559
33558
  });
33560
33559
  if (typeof renderer2 === "function") {
33561
33560
  column.cell = (info) => renderer2(rendererArgs(info));
33562
33561
  } else {
33563
- column.cell = (info) => formattedValueRenderer(info.getValue());
33562
+ column.cell = (info) => formattedValueRenderer(info.getValue(), info.row.original);
33564
33563
  }
33565
33564
  if (typeof footer === "function") {
33566
33565
  column.footer = (info) => footer(info.table.getRowModel().rows.flatMap((row) => row.original !== void 0 ? row.original : []));