@economic/taco 2.58.2-EC-64961.0 → 2.58.2-EC-64961.2

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
@@ -3146,22 +3146,29 @@ export declare type TableColumnAlignment = 'left' | 'center' | 'right';
3146
3146
 
3147
3147
  export declare type TableColumnClassNameHandler<TType = unknown> = string | ((row: TType) => string | undefined);
3148
3148
 
3149
- export declare type TableColumnDataType = 'text' | 'number' | 'datetime' | 'boolean' | 'amount';
3149
+ export declare type TableColumnDataType = 'text' | 'number' | 'datetime' | 'boolean' | 'amount' | 'percentage';
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'>>;
3165
+ } | {
3166
+ dataType?: 'percentage';
3167
+ dataTypeOptions?: TableColumnDataTypeOptionsHandler<TType, Pick<TableColumnDataTypeOptions, 'decimals' | 'useGrouping'>>;
3161
3168
  } | {
3162
3169
  dataType?: Omit<TableColumnDataType, 'number' | 'amount'>;
3163
3170
  dataTypeOptions?: never;
3164
- });
3171
+ };
3165
3172
 
3166
3173
  export declare type TableColumnFilter = ColumnFilter;
3167
3174
 
@@ -3181,7 +3188,7 @@ export declare type TableColumnIdentifierProps<TType = unknown> = {
3181
3188
 
3182
3189
  export declare type TableColumnMenu = ((columnId: string) => React.ReactNode | null)[];
3183
3190
 
3184
- export declare type TableColumnProps<TType = unknown> = TableColumnIdentifierProps<TType> & TableColumnDataTypeProps & {
3191
+ export declare type TableColumnProps<TType = unknown> = TableColumnIdentifierProps<TType> & TableColumnDataTypeProps<TType> & {
3185
3192
  control?: TableColumnRendererControl<TType> | undefined;
3186
3193
  footer?: TableColumnRendererFooter<TType> | undefined;
3187
3194
  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,14 @@ 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
+ percentage: createNumberDataType("right", { useGrouping: true, percent: true })
33065
+ };
33066
+ function createNumberDataType(align, defaultOptions2) {
33067
+ return {
33068
+ align,
33088
33069
  sortingFn: "basic",
33089
33070
  filterComparators: [
33090
33071
  TableFilterComparator.IsEqualTo,
@@ -33097,28 +33078,39 @@ const dataTypes = {
33097
33078
  TableFilterComparator.IsEmpty,
33098
33079
  TableFilterComparator.IsNotEmpty
33099
33080
  ],
33100
- getDisplayValue: (value, options) => {
33101
- var _a, _b, _c, _d, _e, _f;
33081
+ getDisplayValue: (value, row, options) => {
33082
+ var _a, _b;
33102
33083
  if (value === void 0) {
33103
33084
  return "";
33104
33085
  }
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;
33086
+ const dataTypeOptions = typeof (options == null ? void 0 : options.dataTypeOptions) === "function" ? options == null ? void 0 : options.dataTypeOptions(row) : options == null ? void 0 : options.dataTypeOptions;
33107
33087
  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
33088
+ // format
33089
+ useGrouping: (dataTypeOptions == null ? void 0 : dataTypeOptions.useGrouping) ?? (defaultOptions2 == null ? void 0 : defaultOptions2.useGrouping) ?? false,
33090
+ // decimals
33091
+ minimumFractionDigits: (dataTypeOptions == null ? void 0 : dataTypeOptions.decimals) ?? (defaultOptions2 == null ? void 0 : defaultOptions2.decimals),
33092
+ maximumFractionDigits: (dataTypeOptions == null ? void 0 : dataTypeOptions.decimals) ?? (defaultOptions2 == null ? void 0 : defaultOptions2.decimals)
33111
33093
  };
33112
- return formatNumber(value, (_f = options == null ? void 0 : options.localization) == null ? void 0 : _f.locale, numberFormatOptions);
33094
+ if (defaultOptions2 == null ? void 0 : defaultOptions2.percent) {
33095
+ numberFormatOptions.style = "percent";
33096
+ } else if (dataTypeOptions == null ? void 0 : dataTypeOptions.currency) {
33097
+ numberFormatOptions.style = "currency";
33098
+ numberFormatOptions.currency = dataTypeOptions.currency;
33099
+ numberFormatOptions.currencyDisplay = "code";
33100
+ }
33101
+ const localisedValue = new Intl.NumberFormat((_a = options == null ? void 0 : options.localization) == null ? void 0 : _a.locale, numberFormatOptions).format(
33102
+ Number(value)
33103
+ );
33104
+ if (!numberFormatOptions.useGrouping) {
33105
+ return localisedValue;
33106
+ }
33107
+ const localisedValueWithoutThousandsSeperator = new Intl.NumberFormat((_b = options == null ? void 0 : options.localization) == null ? void 0 : _b.locale, {
33108
+ ...numberFormatOptions,
33109
+ useGrouping: false
33110
+ }).format(Number(value));
33111
+ return [localisedValue, localisedValueWithoutThousandsSeperator];
33113
33112
  }
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];
33113
+ };
33122
33114
  }
33123
33115
  function getDataTypeProperties(dataType) {
33124
33116
  return dataTypes[dataType ?? "text"] ?? dataTypes.text;
@@ -33241,7 +33233,7 @@ function columnFilterFn(value, filter2) {
33241
33233
  const flattenCellValue = (cellValue) => {
33242
33234
  return typeof cellValue === "object" ? Object.values(cellValue).map(flattenCellValue) : cellValue;
33243
33235
  };
33244
- function isMatched(searchQuery, cellValue, dataType, dataTypeOptions, localization) {
33236
+ function isMatched(searchQuery, cellValue, rowValue, dataType, dataTypeOptions, localization) {
33245
33237
  if (typeof cellValue === "object") {
33246
33238
  return flattenCellValue(cellValue).flat(Infinity).find((y4) => isWeakContains(y4, searchQuery));
33247
33239
  } else {
@@ -33251,7 +33243,10 @@ function isMatched(searchQuery, cellValue, dataType, dataTypeOptions, localizati
33251
33243
  } else {
33252
33244
  const dataTypeProperties = getDataTypeProperties(dataType);
33253
33245
  if (dataTypeProperties.getDisplayValue) {
33254
- const cellDisplayValue = dataTypeProperties.getDisplayValue(cellValue, { dataTypeOptions, localization });
33246
+ const cellDisplayValue = dataTypeProperties.getDisplayValue(cellValue, rowValue, {
33247
+ dataTypeOptions,
33248
+ localization
33249
+ });
33255
33250
  if (Array.isArray(cellDisplayValue)) {
33256
33251
  for (const displayValue of cellDisplayValue) {
33257
33252
  if (isWeakContains(displayValue, searchQuery)) {
@@ -33272,7 +33267,14 @@ function globalFilterFn(row, columnId, searchQuery, localization) {
33272
33267
  if (row.original) {
33273
33268
  const cellValue = row.original[columnId];
33274
33269
  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);
33270
+ return isMatched(
33271
+ searchQuery,
33272
+ cellValue,
33273
+ row.original,
33274
+ columnMeta == null ? void 0 : columnMeta.dataType,
33275
+ columnMeta == null ? void 0 : columnMeta.dataTypeOptions,
33276
+ localization
33277
+ );
33276
33278
  }
33277
33279
  } catch {
33278
33280
  }
@@ -33301,7 +33303,7 @@ function resetHighlightedColumnIndexes(searchQuery, table, localization) {
33301
33303
  const cellValue = get(row.original, column.id);
33302
33304
  const dataType = (_a = column.columnDef.meta) == null ? void 0 : _a.dataType;
33303
33305
  const dataTypeOptions = (_b = column.columnDef.meta) == null ? void 0 : _b.dataTypeOptions;
33304
- if (isMatched(searchQuery, cellValue, dataType, dataTypeOptions, localization)) {
33306
+ if (isMatched(searchQuery, cellValue, row.original, dataType, dataTypeOptions, localization)) {
33305
33307
  indexes.push([rowIndex, columnIndex]);
33306
33308
  }
33307
33309
  }
@@ -33540,9 +33542,9 @@ function processChildren(child, columns, defaultSizing, defaultSorting, defaultV
33540
33542
  header
33541
33543
  }
33542
33544
  };
33543
- const formattedValueRenderer = (value) => {
33545
+ const formattedValueRenderer = (value, row) => {
33544
33546
  var _a;
33545
- const displayValue = (_a = dataTypeProperties.getDisplayValue) == null ? void 0 : _a.call(dataTypeProperties, value, {
33547
+ const displayValue = (_a = dataTypeProperties.getDisplayValue) == null ? void 0 : _a.call(dataTypeProperties, value, row, {
33546
33548
  dataTypeOptions: meta.dataTypeOptions,
33547
33549
  localization
33548
33550
  });
@@ -33553,14 +33555,14 @@ function processChildren(child, columns, defaultSizing, defaultSorting, defaultV
33553
33555
  return displayValue ?? safeValue;
33554
33556
  };
33555
33557
  const rendererArgs = (info) => ({
33556
- formattedValue: formattedValueRenderer(info.getValue()),
33558
+ formattedValue: formattedValueRenderer(info.getValue(), info.row.original),
33557
33559
  row: info.row.original,
33558
33560
  value: info.getValue()
33559
33561
  });
33560
33562
  if (typeof renderer2 === "function") {
33561
33563
  column.cell = (info) => renderer2(rendererArgs(info));
33562
33564
  } else {
33563
- column.cell = (info) => formattedValueRenderer(info.getValue());
33565
+ column.cell = (info) => formattedValueRenderer(info.getValue(), info.row.original);
33564
33566
  }
33565
33567
  if (typeof footer === "function") {
33566
33568
  column.footer = (info) => footer(info.table.getRowModel().rows.flatMap((row) => row.original !== void 0 ? row.original : []));