@economic/taco 17.0.0-EC-00123-table3-bundle.1 → 17.0.0-alpha-rules.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.
- package/dist/charts/components/types.d.ts +1 -1
- package/dist/charts/components/useChartData.cjs +1 -2
- package/dist/charts/components/useChartData.js +1 -2
- package/dist/components/Datepicker/useDatepicker.cjs +3 -3
- package/dist/components/Datepicker/useDatepicker.js +3 -3
- package/dist/components/Provider/Localization.cjs +2 -18
- package/dist/components/Provider/Localization.d.ts +7 -14
- package/dist/components/Provider/Localization.js +2 -18
- package/dist/components/Table3/components/Columns/Cell/EditingControlCell.cjs +17 -16
- package/dist/components/Table3/components/Columns/Cell/EditingControlCell.js +18 -17
- package/dist/index.cjs +0 -4
- package/dist/index.js +1 -5
- package/dist/primitives/Table/Core/components/Body/Body.cjs +1 -1
- package/dist/primitives/Table/Core/components/Body/Body.js +1 -1
- package/dist/primitives/Table/Core/components/Footer/Summary.cjs +4 -6
- package/dist/primitives/Table/Core/components/Footer/Summary.js +4 -6
- package/dist/primitives/Table/Core/components/Header/Header.cjs +3 -7
- package/dist/primitives/Table/Core/components/Header/Header.d.ts +2 -4
- package/dist/primitives/Table/Core/components/Header/Header.js +4 -8
- package/dist/primitives/Table/Core/components/Header/components/Resizer.cjs +3 -11
- package/dist/primitives/Table/Core/components/Header/components/Resizer.d.ts +4 -6
- package/dist/primitives/Table/Core/components/Header/components/Resizer.js +3 -11
- package/dist/primitives/Table/Core/components/Header/util.d.ts +2 -3
- package/dist/primitives/Table/Core/components/Toolbar/components/Filters/ManageFiltersPopover.cjs +4 -7
- package/dist/primitives/Table/Core/components/Toolbar/components/Filters/ManageFiltersPopover.js +4 -7
- package/dist/primitives/Table/Core/features/useTableRenderer.cjs +0 -10
- package/dist/primitives/Table/Core/features/useTableRenderer.js +0 -10
- package/dist/primitives/Table/Core/features/useTableStyleGrid.cjs +2 -7
- package/dist/primitives/Table/Core/features/useTableStyleGrid.js +3 -8
- package/dist/primitives/Table/types.d.ts +2 -5
- package/dist/primitives/Table/useTableManager/listeners/useTableFontSizeListener.cjs +0 -3
- package/dist/primitives/Table/useTableManager/listeners/useTableFontSizeListener.js +0 -3
- package/dist/primitives/Table/useTableManager/useTableManager.cjs +0 -3
- package/dist/primitives/Table/useTableManager/useTableManager.d.ts +2 -4
- package/dist/primitives/Table/useTableManager/useTableManager.js +0 -3
- package/dist/primitives/Table/useTableManager/util/columns.cjs +0 -8
- package/dist/primitives/Table/useTableManager/util/columns.d.ts +2 -5
- package/dist/primitives/Table/useTableManager/util/columns.js +0 -8
- package/dist/primitives/Table/useTableManager/util/dataTypes.cjs +10 -29
- package/dist/primitives/Table/useTableManager/util/dataTypes.d.ts +2 -5
- package/dist/primitives/Table/useTableManager/util/dataTypes.js +12 -31
- package/dist/primitives/Table/useTableManager/util/filtering.cjs +1 -1
- package/dist/primitives/Table/useTableManager/util/filtering.js +2 -2
- package/dist/primitives/Table/useTableManager/util/rows.cjs +2 -10
- package/dist/primitives/Table/useTableManager/util/rows.d.ts +4 -1
- package/dist/primitives/Table/useTableManager/util/rows.js +2 -10
- package/dist/primitives/Table/useTableManager/util/search.cjs +1 -1
- package/dist/primitives/Table/useTableManager/util/search.js +1 -1
- package/dist/primitives/Table/useTableManager/util/settings.cjs +1 -1
- package/dist/primitives/Table/useTableManager/util/settings.d.ts +3 -4
- package/dist/primitives/Table/useTableManager/util/settings.js +1 -1
- package/dist/primitives/Table/useTableManager/util/setup.cjs +0 -1
- package/dist/primitives/Table/useTableManager/util/setup.d.ts +4 -4
- package/dist/primitives/Table/useTableManager/util/setup.js +0 -1
- package/dist/utils/dataTypes.cjs +34 -84
- package/dist/utils/dataTypes.d.ts +4 -28
- package/dist/utils/dataTypes.js +22 -72
- package/dist/utils/date.cjs +4 -47
- package/dist/utils/date.d.ts +0 -5
- package/dist/utils/date.js +4 -47
- package/package.json +4 -4
- package/dist/components/Table3/components/Columns/Cell/Editing/NumberInput.cjs +0 -39
- package/dist/components/Table3/components/Columns/Cell/Editing/NumberInput.d.ts +0 -10
- package/dist/components/Table3/components/Columns/Cell/Editing/NumberInput.js +0 -39
- package/dist/primitives/Table/useTableManager/features/useTableColumnSizing.cjs +0 -32
- package/dist/primitives/Table/useTableManager/features/useTableColumnSizing.d.ts +0 -5
- package/dist/primitives/Table/useTableManager/features/useTableColumnSizing.js +0 -32
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const rows = require("../../Core/util/rows.cjs");
|
|
4
3
|
function getTableMeta(table) {
|
|
5
4
|
if (!table.options.meta) {
|
|
6
5
|
throw new Error("Table requires table meta");
|
|
@@ -9,15 +8,8 @@ function getTableMeta(table) {
|
|
|
9
8
|
}
|
|
10
9
|
function getReachableRowCount(table) {
|
|
11
10
|
const tableMeta = getTableMeta(table);
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
if (tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2) {
|
|
15
|
-
if (table.getState().grouping?.length) {
|
|
16
|
-
return rows.getGroupedServerRowLayout(rows$1, tableMeta.server.pages ?? [], tableMeta.server.pageSize, tableMeta.length).count + bottomRowCount;
|
|
17
|
-
}
|
|
18
|
-
return tableMeta.length + bottomRowCount;
|
|
19
|
-
}
|
|
20
|
-
return rows$1.length + bottomRowCount;
|
|
11
|
+
const isFilteringActive = table.options.enableGlobalFilter && table.getState().globalFilter;
|
|
12
|
+
return isFilteringActive ? table.getRowModel().rows.length + table.getBottomRows().length : tableMeta.length + table.getBottomRows().length;
|
|
21
13
|
}
|
|
22
14
|
exports.getReachableRowCount = getReachableRowCount;
|
|
23
15
|
exports.getTableMeta = getTableMeta;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';
|
|
2
2
|
export declare function getTableMeta<TType = unknown>(table: ReactTable<TType>): ReactTableMeta<TType>;
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Returns the number of reachable rows. Uses filtered count when search filtering is active,
|
|
5
|
+
* otherwise uses total dataset length to support virtualization. Includes bottom rows.
|
|
6
|
+
*/
|
|
4
7
|
export declare function getReachableRowCount<TType = unknown>(table: ReactTable<TType>): number;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getGroupedServerRowLayout } from "../../Core/util/rows.js";
|
|
2
1
|
function getTableMeta(table) {
|
|
3
2
|
if (!table.options.meta) {
|
|
4
3
|
throw new Error("Table requires table meta");
|
|
@@ -7,15 +6,8 @@ function getTableMeta(table) {
|
|
|
7
6
|
}
|
|
8
7
|
function getReachableRowCount(table) {
|
|
9
8
|
const tableMeta = getTableMeta(table);
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
if (tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2) {
|
|
13
|
-
if (table.getState().grouping?.length) {
|
|
14
|
-
return getGroupedServerRowLayout(rows, tableMeta.server.pages ?? [], tableMeta.server.pageSize, tableMeta.length).count + bottomRowCount;
|
|
15
|
-
}
|
|
16
|
-
return tableMeta.length + bottomRowCount;
|
|
17
|
-
}
|
|
18
|
-
return rows.length + bottomRowCount;
|
|
9
|
+
const isFilteringActive = table.options.enableGlobalFilter && table.getState().globalFilter;
|
|
10
|
+
return isFilteringActive ? table.getRowModel().rows.length + table.getBottomRows().length : tableMeta.length + table.getBottomRows().length;
|
|
19
11
|
}
|
|
20
12
|
export {
|
|
21
13
|
getReachableRowCount,
|
|
@@ -29,7 +29,7 @@ function isMatched(query, cellValue, rowValue, dataType, dataTypeOptions, locali
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
if (typeof query !== typeof cellValue && dataTypeProperties.parse) {
|
|
32
|
-
const parsedQuery = dataTypeProperties.parse(query, localization);
|
|
32
|
+
const parsedQuery = dataTypeProperties.parse(query, localization.locale);
|
|
33
33
|
if (parsedQuery !== void 0 && matcher(cellValue, parsedQuery)) {
|
|
34
34
|
return true;
|
|
35
35
|
}
|
|
@@ -27,7 +27,7 @@ function isMatched(query, cellValue, rowValue, dataType, dataTypeOptions, locali
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
if (typeof query !== typeof cellValue && dataTypeProperties.parse) {
|
|
30
|
-
const parsedQuery = dataTypeProperties.parse(query, localization);
|
|
30
|
+
const parsedQuery = dataTypeProperties.parse(query, localization.locale);
|
|
31
31
|
if (parsedQuery !== void 0 && matcher(cellValue, parsedQuery)) {
|
|
32
32
|
return true;
|
|
33
33
|
}
|
|
@@ -10,7 +10,7 @@ function getSettings(table) {
|
|
|
10
10
|
//columnFilters: table.options.enableColumnFilters ? state.columnFilters : undefined,
|
|
11
11
|
columnOrder: meta.columnOrdering.isEnabled ? state.columnOrder : void 0,
|
|
12
12
|
columnPinning: state.columnPinning,
|
|
13
|
-
columnSizing:
|
|
13
|
+
columnSizing: ignoreInternalColumns(state.columnSizing),
|
|
14
14
|
columnVisibility: table.options.enableHiding ? state.columnVisibility : void 0,
|
|
15
15
|
excludeUnmatchedRecordsInSearch: table.options.enableGlobalFilter,
|
|
16
16
|
fontSize: meta.fontSize.isEnabled ? meta.fontSize.size : void 0,
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { Table as ReactTable } from '@tanstack/react-table';
|
|
2
|
-
import { TableColumnSizingState } from '../../types';
|
|
1
|
+
import { ColumnSizingState, Table as ReactTable } from '@tanstack/react-table';
|
|
3
2
|
export declare function getSettings<TType = unknown>(table: ReactTable<TType>): {
|
|
4
3
|
columnOrder: import('@tanstack/table-core').ColumnOrderState | undefined;
|
|
5
4
|
columnPinning: import('@tanstack/table-core').ColumnPinningState;
|
|
6
|
-
columnSizing:
|
|
5
|
+
columnSizing: {};
|
|
7
6
|
columnVisibility: import('@tanstack/table-core').VisibilityState | undefined;
|
|
8
7
|
excludeUnmatchedRecordsInSearch: boolean | undefined;
|
|
9
8
|
fontSize: "small" | "medium" | "large" | undefined;
|
|
10
9
|
rowHeight: import('../../types').TableRowHeight | undefined;
|
|
11
10
|
sorting: import('@tanstack/table-core').SortingState;
|
|
12
11
|
};
|
|
13
|
-
export declare function ignoreInternalColumns(data:
|
|
12
|
+
export declare function ignoreInternalColumns(data: ColumnSizingState): {};
|
|
@@ -8,7 +8,7 @@ function getSettings(table) {
|
|
|
8
8
|
//columnFilters: table.options.enableColumnFilters ? state.columnFilters : undefined,
|
|
9
9
|
columnOrder: meta.columnOrdering.isEnabled ? state.columnOrder : void 0,
|
|
10
10
|
columnPinning: state.columnPinning,
|
|
11
|
-
columnSizing:
|
|
11
|
+
columnSizing: ignoreInternalColumns(state.columnSizing),
|
|
12
12
|
columnVisibility: table.options.enableHiding ? state.columnVisibility : void 0,
|
|
13
13
|
excludeUnmatchedRecordsInSearch: table.options.enableGlobalFilter,
|
|
14
14
|
fontSize: meta.fontSize.isEnabled ? meta.fontSize.size : void 0,
|
|
@@ -335,7 +335,6 @@ function useReactTableInitialState(props, columns$1, persistedSettings, defaults
|
|
|
335
335
|
columnFilters: persistedSettings.columnFilters ?? props.defaultSettings?.columnFilters ?? [],
|
|
336
336
|
columnOrder,
|
|
337
337
|
columnPinning,
|
|
338
|
-
// cast because 'grow' is a valid width for us, but TanStack Table types the state as numbers
|
|
339
338
|
columnSizing: settings.ignoreInternalColumns(columnSizing),
|
|
340
339
|
columnVisibility: persistedSettings.columnVisibility ?? props.defaultSettings?.columnVisibility ?? defaults.defaultVisibility ?? {},
|
|
341
340
|
globalFilter: persistedSettings.searchQuery ?? props.defaultSettings?.searchQuery,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { TableOptions as ReactTableOptions, ColumnDef as ReactTableColumnDef, ColumnSort as ReactTableColumnSort, TableState as ReactTableState, VisibilityState as ReactTableVisibilityState } from '@tanstack/react-table';
|
|
1
|
+
import { TableOptions as ReactTableOptions, ColumnDef as ReactTableColumnDef, ColumnSizingState as ReactTableColumnSizingState, ColumnSort as ReactTableColumnSort, TableState as ReactTableState, VisibilityState as ReactTableVisibilityState } from '@tanstack/react-table';
|
|
2
2
|
import { Localization } from '../../../../components';
|
|
3
|
-
import {
|
|
3
|
+
import { TableFeatureProps, TableProps, TableSettings } from '../../types';
|
|
4
4
|
import { useTableManagerInternalColumns } from '../types';
|
|
5
5
|
export declare function mapTableChildrenToColumns<TType = unknown>(props: TableProps<TType>, settings: TableSettings, options: TableFeatureProps<TType>, internalColumns: useTableManagerInternalColumns<TType> | undefined, localization: Localization): {
|
|
6
6
|
columns: ReactTableColumnDef<TType>[];
|
|
7
|
-
defaultSizing:
|
|
7
|
+
defaultSizing: ReactTableColumnSizingState;
|
|
8
8
|
defaultSorting: ReactTableColumnSort[];
|
|
9
9
|
defaultVisibility: ReactTableVisibilityState;
|
|
10
10
|
};
|
|
11
11
|
export declare function configureReactTableOptions<TType = unknown>(options: TableFeatureProps<TType>, props: TableProps<TType>, localization: Localization): Partial<ReactTableOptions<TType>>;
|
|
12
12
|
export declare function useReactTableInitialState<TType = unknown>(props: TableProps<TType>, columns: ReactTableColumnDef<TType>[], persistedSettings: TableSettings, defaults: {
|
|
13
|
-
defaultSizing:
|
|
13
|
+
defaultSizing: ReactTableColumnSizingState;
|
|
14
14
|
defaultSorting: ReactTableColumnSort[];
|
|
15
15
|
defaultVisibility: ReactTableVisibilityState;
|
|
16
16
|
}): Partial<ReactTableState>;
|
|
@@ -333,7 +333,6 @@ function useReactTableInitialState(props, columns, persistedSettings, defaults)
|
|
|
333
333
|
columnFilters: persistedSettings.columnFilters ?? props.defaultSettings?.columnFilters ?? [],
|
|
334
334
|
columnOrder,
|
|
335
335
|
columnPinning,
|
|
336
|
-
// cast because 'grow' is a valid width for us, but TanStack Table types the state as numbers
|
|
337
336
|
columnSizing: ignoreInternalColumns(columnSizing),
|
|
338
337
|
columnVisibility: persistedSettings.columnVisibility ?? props.defaultSettings?.columnVisibility ?? defaults.defaultVisibility ?? {},
|
|
339
338
|
globalFilter: persistedSettings.searchQuery ?? props.defaultSettings?.searchQuery,
|
package/dist/utils/dataTypes.cjs
CHANGED
|
@@ -1,49 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const dateFns = require("date-fns");
|
|
4
|
-
const date = require("./date.cjs");
|
|
5
4
|
class DataType {
|
|
6
5
|
}
|
|
7
6
|
const localeNumberSeparators = /* @__PURE__ */ new Map();
|
|
8
|
-
const numberFormatters = /* @__PURE__ */ new Map();
|
|
9
|
-
const dateTimeFormatters = /* @__PURE__ */ new Map();
|
|
10
|
-
const getCached = (cache, key, create) => {
|
|
11
|
-
let value = cache.get(key);
|
|
12
|
-
if (value === void 0) {
|
|
13
|
-
value = create();
|
|
14
|
-
cache.set(key, value);
|
|
15
|
-
}
|
|
16
|
-
return value;
|
|
17
|
-
};
|
|
18
|
-
const formatterCacheKey = (locale, options) => `${String(locale)}|${JSON.stringify(options ?? {})}`;
|
|
19
|
-
const getNumberFormatter = (locale, options) => getCached(numberFormatters, formatterCacheKey(locale, options), () => new Intl.NumberFormat(locale, options));
|
|
20
|
-
const getDateTimeFormatter = (locale, options) => getCached(dateTimeFormatters, formatterCacheKey(locale, options), () => new Intl.DateTimeFormat(locale, options));
|
|
21
|
-
const escapeForCharacterClass = (value) => value.replaceAll(/[\]\\^-]/gu, String.raw`\$&`);
|
|
22
7
|
class NumericDataType extends DataType {
|
|
23
|
-
static format(value, locale, options
|
|
8
|
+
static format(value, locale, options) {
|
|
24
9
|
if (value === void 0 || typeof value !== "number" || Number.isNaN(value)) {
|
|
25
10
|
return "";
|
|
26
11
|
}
|
|
27
|
-
const
|
|
28
|
-
const replacements = separators ?? {};
|
|
29
|
-
const localisedValue = replacements.decimal === void 0 && replacements.group === void 0 ? formatter.format(value) : formatter.formatToParts(value).map((part) => replacements[part.type] ?? part.value).join("");
|
|
12
|
+
const localisedValue = new Intl.NumberFormat(locale, options).format(value);
|
|
30
13
|
return localisedValue.replaceAll(/[\u00A0\u202F]/gu, " ");
|
|
31
14
|
}
|
|
32
|
-
static parse(value, locale
|
|
15
|
+
static parse(value, locale) {
|
|
33
16
|
if (value === void 0 || value === null || typeof value !== "string") {
|
|
34
17
|
return void 0;
|
|
35
18
|
}
|
|
36
19
|
if (value === "Infinity" || value === "-Infinity") {
|
|
37
20
|
return Number(value);
|
|
38
21
|
}
|
|
39
|
-
let
|
|
40
|
-
if (value.includes(".") && value.includes(",")) {
|
|
41
|
-
decimalSeparator = value.lastIndexOf(".") > value.lastIndexOf(",") ? "." : ",";
|
|
42
|
-
}
|
|
43
|
-
const sanitizedValue = value.replaceAll(" ", "").replaceAll(new RegExp(String.raw`[^0-9\-${escapeForCharacterClass(decimalSeparator)}]+`, "gu"), "").replace(decimalSeparator, ".");
|
|
22
|
+
let sanitizedValue = value.replaceAll(" ", "").replaceAll(/[^0-9.,-]+/gu, "");
|
|
44
23
|
if (!sanitizedValue.length) {
|
|
45
24
|
return void 0;
|
|
46
25
|
}
|
|
26
|
+
const decimalSeparator = this.getSeparator(locale);
|
|
27
|
+
if (decimalSeparator === ",") {
|
|
28
|
+
sanitizedValue = sanitizedValue.replaceAll(".", "").replace(",", ".");
|
|
29
|
+
} else {
|
|
30
|
+
sanitizedValue = sanitizedValue.replaceAll(",", "");
|
|
31
|
+
}
|
|
47
32
|
const output = Number(sanitizedValue);
|
|
48
33
|
if (Number.isNaN(output)) {
|
|
49
34
|
return void 0;
|
|
@@ -54,50 +39,28 @@ class NumericDataType extends DataType {
|
|
|
54
39
|
if (localeNumberSeparators.has(locale)) {
|
|
55
40
|
return localeNumberSeparators.get(locale);
|
|
56
41
|
}
|
|
57
|
-
const decimalSeparator =
|
|
42
|
+
const decimalSeparator = new Intl.NumberFormat(locale).formatToParts(1.1).find((part) => part.type === "decimal")?.value ?? ".";
|
|
58
43
|
localeNumberSeparators.set(locale, decimalSeparator);
|
|
59
44
|
return decimalSeparator;
|
|
60
45
|
}
|
|
61
46
|
}
|
|
62
|
-
const getNumberSeparators = (formatting) => ({
|
|
63
|
-
decimal: formatting?.numberDecimalSeparator,
|
|
64
|
-
group: formatting?.numberGroupSeparator
|
|
65
|
-
});
|
|
66
|
-
const formatNumber = (value, localization, options) => NumericDataType.format(value, localization?.locale, options, getNumberSeparators(localization?.formatting));
|
|
67
|
-
const parseNumber = (value, localization) => NumericDataType.parse(value, localization.locale, getNumberSeparators(localization.formatting));
|
|
68
|
-
const stripNonNumericCharacters = (value, localization) => {
|
|
69
|
-
const { decimal = "", group = "" } = getNumberSeparators(localization.formatting);
|
|
70
|
-
return value.replaceAll(new RegExp(String.raw`[^0-9\-.,${escapeForCharacterClass(decimal + group)}]`, "gu"), "");
|
|
71
|
-
};
|
|
72
47
|
const localeDateMasks = /* @__PURE__ */ new Map();
|
|
73
|
-
const toDateFnsMask = (masks) => {
|
|
74
|
-
const date$1 = masks.date?.replaceAll("mm", "MM");
|
|
75
|
-
if (date$1 && masks.time) {
|
|
76
|
-
return `${date$1}${date.DATETIME_SEPARATOR}${masks.time}`;
|
|
77
|
-
}
|
|
78
|
-
return date$1 ?? masks.time;
|
|
79
|
-
};
|
|
80
48
|
class DateTimeDataType extends DataType {
|
|
81
|
-
static format(value, locale, options
|
|
82
|
-
let date
|
|
49
|
+
static format(value, locale, options) {
|
|
50
|
+
let date;
|
|
83
51
|
if (typeof value === "string") {
|
|
84
|
-
date
|
|
52
|
+
date = new Date(value);
|
|
85
53
|
} else if (value instanceof Date) {
|
|
86
|
-
date
|
|
54
|
+
date = value;
|
|
87
55
|
} else {
|
|
88
56
|
return "";
|
|
89
57
|
}
|
|
90
|
-
if (Number.isNaN(date
|
|
58
|
+
if (Number.isNaN(date.getTime())) {
|
|
91
59
|
return "";
|
|
92
60
|
}
|
|
93
|
-
|
|
94
|
-
const formattedDate = masks.date ? date.format(date$1, masks.date) : void 0;
|
|
95
|
-
const formattedTime = masks.time ? date.formatTime(date$1, masks.time) : void 0;
|
|
96
|
-
return [formattedDate, formattedTime].filter(Boolean).join(date.DATETIME_SEPARATOR);
|
|
97
|
-
}
|
|
98
|
-
return getDateTimeFormatter(locale, options).format(date$1).replaceAll(/[\u00A0\u202F]/gu, " ");
|
|
61
|
+
return new Intl.DateTimeFormat(locale, options).format(date).replaceAll(/[\u00A0\u202F]/gu, " ");
|
|
99
62
|
}
|
|
100
|
-
static parse(value, locale
|
|
63
|
+
static parse(value, locale) {
|
|
101
64
|
if (value === void 0 || value === null || typeof value !== "string") {
|
|
102
65
|
return void 0;
|
|
103
66
|
}
|
|
@@ -105,43 +68,39 @@ class DateTimeDataType extends DataType {
|
|
|
105
68
|
if (!sanitizedValue?.length) {
|
|
106
69
|
return void 0;
|
|
107
70
|
}
|
|
108
|
-
const setHoursToMidday = (
|
|
109
|
-
|
|
71
|
+
const setHoursToMidday = (date) => {
|
|
72
|
+
date.setHours(12 - date.getTimezoneOffset() / 60);
|
|
110
73
|
};
|
|
111
74
|
try {
|
|
112
|
-
const
|
|
113
|
-
if (dateFns.isValid(
|
|
75
|
+
const date = dateFns.parseISO(sanitizedValue);
|
|
76
|
+
if (dateFns.isValid(date)) {
|
|
114
77
|
const timeRegex = /^\d{2}:\d{2}(?::\d{2}\.\d+|:\d{2})?(?:Z)?$/u;
|
|
115
78
|
const time = sanitizedValue.split("T")[1];
|
|
116
79
|
if (!time || !timeRegex.test(time)) {
|
|
117
|
-
setHoursToMidday(
|
|
80
|
+
setHoursToMidday(date);
|
|
118
81
|
}
|
|
119
|
-
return
|
|
82
|
+
return date;
|
|
120
83
|
}
|
|
121
84
|
} catch {
|
|
122
85
|
}
|
|
123
|
-
const mask =
|
|
124
|
-
const maskHasTime = Boolean(masks?.time ?? (options?.hour || options?.minute || options?.second || options?.timeStyle));
|
|
86
|
+
const mask = this.getMask(locale);
|
|
125
87
|
if (mask) {
|
|
126
88
|
try {
|
|
127
|
-
const
|
|
128
|
-
if (dateFns.isValid(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
return date2;
|
|
89
|
+
const date = dateFns.parse(sanitizedValue, mask, /* @__PURE__ */ new Date());
|
|
90
|
+
if (dateFns.isValid(date)) {
|
|
91
|
+
setHoursToMidday(date);
|
|
92
|
+
return date;
|
|
133
93
|
}
|
|
134
94
|
} catch {
|
|
135
95
|
}
|
|
136
96
|
}
|
|
137
97
|
return void 0;
|
|
138
98
|
}
|
|
139
|
-
static getMask(locale
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return localeDateMasks.get(cacheKey);
|
|
99
|
+
static getMask(locale) {
|
|
100
|
+
if (localeDateMasks.has(locale)) {
|
|
101
|
+
return localeDateMasks.get(locale);
|
|
143
102
|
}
|
|
144
|
-
const parts = new Intl.DateTimeFormat(locale
|
|
103
|
+
const parts = new Intl.DateTimeFormat(locale).formatToParts(/* @__PURE__ */ new Date());
|
|
145
104
|
const mask = parts.reduce((mask2, part) => {
|
|
146
105
|
switch (part.type) {
|
|
147
106
|
case "literal":
|
|
@@ -152,22 +111,13 @@ class DateTimeDataType extends DataType {
|
|
|
152
111
|
return mask2 + "MM";
|
|
153
112
|
case "year":
|
|
154
113
|
return mask2 + "yyyy";
|
|
155
|
-
case "hour":
|
|
156
|
-
return mask2 + "HH";
|
|
157
|
-
case "minute":
|
|
158
|
-
return mask2 + "mm";
|
|
159
|
-
case "second":
|
|
160
|
-
return mask2 + "ss";
|
|
161
114
|
default:
|
|
162
115
|
return mask2;
|
|
163
116
|
}
|
|
164
117
|
}, "");
|
|
165
|
-
localeDateMasks.set(
|
|
118
|
+
localeDateMasks.set(locale, mask);
|
|
166
119
|
return mask;
|
|
167
120
|
}
|
|
168
121
|
}
|
|
169
122
|
exports.DateTimeDataType = DateTimeDataType;
|
|
170
123
|
exports.NumericDataType = NumericDataType;
|
|
171
|
-
exports.formatNumber = formatNumber;
|
|
172
|
-
exports.parseNumber = parseNumber;
|
|
173
|
-
exports.stripNonNumericCharacters = stripNonNumericCharacters;
|
|
@@ -2,38 +2,14 @@ declare abstract class DataType<TValue = unknown> {
|
|
|
2
2
|
abstract format(value: TValue, locale: Intl.LocalesArgument): string;
|
|
3
3
|
abstract parse(value: string, locale: Intl.LocalesArgument): TValue | undefined;
|
|
4
4
|
}
|
|
5
|
-
/** Consumer separators, they take precedence over the locale */
|
|
6
|
-
export type NumberSeparators = {
|
|
7
|
-
decimal?: string;
|
|
8
|
-
group?: string;
|
|
9
|
-
};
|
|
10
|
-
/** The part of a localization that number formatting reads */
|
|
11
|
-
export type NumberLocalization = {
|
|
12
|
-
locale: string;
|
|
13
|
-
formatting?: {
|
|
14
|
-
numberDecimalSeparator?: string;
|
|
15
|
-
numberGroupSeparator?: string;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
5
|
export declare abstract class NumericDataType extends DataType<number> {
|
|
19
|
-
static format(value: number, locale: Intl.LocalesArgument, options?: Intl.NumberFormatOptions
|
|
20
|
-
static parse(value: string, locale: Intl.LocalesArgument
|
|
6
|
+
static format(value: number, locale: Intl.LocalesArgument, options?: Intl.NumberFormatOptions): string;
|
|
7
|
+
static parse(value: string, locale: Intl.LocalesArgument): number | undefined;
|
|
21
8
|
private static getSeparator;
|
|
22
9
|
}
|
|
23
|
-
/** Formats with the localization's separators, the locale fills in the rest */
|
|
24
|
-
export declare const formatNumber: (value: number, localization?: NumberLocalization, options?: Intl.NumberFormatOptions) => string;
|
|
25
|
-
/** Parses a value written with the localization's separators */
|
|
26
|
-
export declare const parseNumber: (value: string, localization: NumberLocalization) => number | undefined;
|
|
27
|
-
/** Drops what cannot be part of a typed number, such as a pasted currency symbol */
|
|
28
|
-
export declare const stripNonNumericCharacters: (value: string, localization: NumberLocalization) => string;
|
|
29
|
-
/** Consumer masks, they take precedence over the locale */
|
|
30
|
-
export type DateTimeMasks = {
|
|
31
|
-
date?: string;
|
|
32
|
-
time?: string;
|
|
33
|
-
};
|
|
34
10
|
export declare abstract class DateTimeDataType extends DataType<Date> {
|
|
35
|
-
static format(value: Date | string, locale: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions
|
|
36
|
-
static parse(value: string, locale: Intl.LocalesArgument
|
|
11
|
+
static format(value: Date | string, locale: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
|
|
12
|
+
static parse(value: string, locale: Intl.LocalesArgument): Date | undefined;
|
|
37
13
|
private static getMask;
|
|
38
14
|
}
|
|
39
15
|
export {};
|
package/dist/utils/dataTypes.js
CHANGED
|
@@ -1,47 +1,32 @@
|
|
|
1
1
|
import { parseISO, isValid, parse } from "date-fns";
|
|
2
|
-
import { format, formatTime, DATETIME_SEPARATOR } from "./date.js";
|
|
3
2
|
class DataType {
|
|
4
3
|
}
|
|
5
4
|
const localeNumberSeparators = /* @__PURE__ */ new Map();
|
|
6
|
-
const numberFormatters = /* @__PURE__ */ new Map();
|
|
7
|
-
const dateTimeFormatters = /* @__PURE__ */ new Map();
|
|
8
|
-
const getCached = (cache, key, create) => {
|
|
9
|
-
let value = cache.get(key);
|
|
10
|
-
if (value === void 0) {
|
|
11
|
-
value = create();
|
|
12
|
-
cache.set(key, value);
|
|
13
|
-
}
|
|
14
|
-
return value;
|
|
15
|
-
};
|
|
16
|
-
const formatterCacheKey = (locale, options) => `${String(locale)}|${JSON.stringify(options ?? {})}`;
|
|
17
|
-
const getNumberFormatter = (locale, options) => getCached(numberFormatters, formatterCacheKey(locale, options), () => new Intl.NumberFormat(locale, options));
|
|
18
|
-
const getDateTimeFormatter = (locale, options) => getCached(dateTimeFormatters, formatterCacheKey(locale, options), () => new Intl.DateTimeFormat(locale, options));
|
|
19
|
-
const escapeForCharacterClass = (value) => value.replaceAll(/[\]\\^-]/gu, String.raw`\$&`);
|
|
20
5
|
class NumericDataType extends DataType {
|
|
21
|
-
static format(value, locale, options
|
|
6
|
+
static format(value, locale, options) {
|
|
22
7
|
if (value === void 0 || typeof value !== "number" || Number.isNaN(value)) {
|
|
23
8
|
return "";
|
|
24
9
|
}
|
|
25
|
-
const
|
|
26
|
-
const replacements = separators ?? {};
|
|
27
|
-
const localisedValue = replacements.decimal === void 0 && replacements.group === void 0 ? formatter.format(value) : formatter.formatToParts(value).map((part) => replacements[part.type] ?? part.value).join("");
|
|
10
|
+
const localisedValue = new Intl.NumberFormat(locale, options).format(value);
|
|
28
11
|
return localisedValue.replaceAll(/[\u00A0\u202F]/gu, " ");
|
|
29
12
|
}
|
|
30
|
-
static parse(value, locale
|
|
13
|
+
static parse(value, locale) {
|
|
31
14
|
if (value === void 0 || value === null || typeof value !== "string") {
|
|
32
15
|
return void 0;
|
|
33
16
|
}
|
|
34
17
|
if (value === "Infinity" || value === "-Infinity") {
|
|
35
18
|
return Number(value);
|
|
36
19
|
}
|
|
37
|
-
let
|
|
38
|
-
if (value.includes(".") && value.includes(",")) {
|
|
39
|
-
decimalSeparator = value.lastIndexOf(".") > value.lastIndexOf(",") ? "." : ",";
|
|
40
|
-
}
|
|
41
|
-
const sanitizedValue = value.replaceAll(" ", "").replaceAll(new RegExp(String.raw`[^0-9\-${escapeForCharacterClass(decimalSeparator)}]+`, "gu"), "").replace(decimalSeparator, ".");
|
|
20
|
+
let sanitizedValue = value.replaceAll(" ", "").replaceAll(/[^0-9.,-]+/gu, "");
|
|
42
21
|
if (!sanitizedValue.length) {
|
|
43
22
|
return void 0;
|
|
44
23
|
}
|
|
24
|
+
const decimalSeparator = this.getSeparator(locale);
|
|
25
|
+
if (decimalSeparator === ",") {
|
|
26
|
+
sanitizedValue = sanitizedValue.replaceAll(".", "").replace(",", ".");
|
|
27
|
+
} else {
|
|
28
|
+
sanitizedValue = sanitizedValue.replaceAll(",", "");
|
|
29
|
+
}
|
|
45
30
|
const output = Number(sanitizedValue);
|
|
46
31
|
if (Number.isNaN(output)) {
|
|
47
32
|
return void 0;
|
|
@@ -52,31 +37,14 @@ class NumericDataType extends DataType {
|
|
|
52
37
|
if (localeNumberSeparators.has(locale)) {
|
|
53
38
|
return localeNumberSeparators.get(locale);
|
|
54
39
|
}
|
|
55
|
-
const decimalSeparator =
|
|
40
|
+
const decimalSeparator = new Intl.NumberFormat(locale).formatToParts(1.1).find((part) => part.type === "decimal")?.value ?? ".";
|
|
56
41
|
localeNumberSeparators.set(locale, decimalSeparator);
|
|
57
42
|
return decimalSeparator;
|
|
58
43
|
}
|
|
59
44
|
}
|
|
60
|
-
const getNumberSeparators = (formatting) => ({
|
|
61
|
-
decimal: formatting?.numberDecimalSeparator,
|
|
62
|
-
group: formatting?.numberGroupSeparator
|
|
63
|
-
});
|
|
64
|
-
const formatNumber = (value, localization, options) => NumericDataType.format(value, localization?.locale, options, getNumberSeparators(localization?.formatting));
|
|
65
|
-
const parseNumber = (value, localization) => NumericDataType.parse(value, localization.locale, getNumberSeparators(localization.formatting));
|
|
66
|
-
const stripNonNumericCharacters = (value, localization) => {
|
|
67
|
-
const { decimal = "", group = "" } = getNumberSeparators(localization.formatting);
|
|
68
|
-
return value.replaceAll(new RegExp(String.raw`[^0-9\-.,${escapeForCharacterClass(decimal + group)}]`, "gu"), "");
|
|
69
|
-
};
|
|
70
45
|
const localeDateMasks = /* @__PURE__ */ new Map();
|
|
71
|
-
const toDateFnsMask = (masks) => {
|
|
72
|
-
const date = masks.date?.replaceAll("mm", "MM");
|
|
73
|
-
if (date && masks.time) {
|
|
74
|
-
return `${date}${DATETIME_SEPARATOR}${masks.time}`;
|
|
75
|
-
}
|
|
76
|
-
return date ?? masks.time;
|
|
77
|
-
};
|
|
78
46
|
class DateTimeDataType extends DataType {
|
|
79
|
-
static format(value, locale, options
|
|
47
|
+
static format(value, locale, options) {
|
|
80
48
|
let date;
|
|
81
49
|
if (typeof value === "string") {
|
|
82
50
|
date = new Date(value);
|
|
@@ -88,14 +56,9 @@ class DateTimeDataType extends DataType {
|
|
|
88
56
|
if (Number.isNaN(date.getTime())) {
|
|
89
57
|
return "";
|
|
90
58
|
}
|
|
91
|
-
|
|
92
|
-
const formattedDate = masks.date ? format(date, masks.date) : void 0;
|
|
93
|
-
const formattedTime = masks.time ? formatTime(date, masks.time) : void 0;
|
|
94
|
-
return [formattedDate, formattedTime].filter(Boolean).join(DATETIME_SEPARATOR);
|
|
95
|
-
}
|
|
96
|
-
return getDateTimeFormatter(locale, options).format(date).replaceAll(/[\u00A0\u202F]/gu, " ");
|
|
59
|
+
return new Intl.DateTimeFormat(locale, options).format(date).replaceAll(/[\u00A0\u202F]/gu, " ");
|
|
97
60
|
}
|
|
98
|
-
static parse(value, locale
|
|
61
|
+
static parse(value, locale) {
|
|
99
62
|
if (value === void 0 || value === null || typeof value !== "string") {
|
|
100
63
|
return void 0;
|
|
101
64
|
}
|
|
@@ -118,15 +81,12 @@ class DateTimeDataType extends DataType {
|
|
|
118
81
|
}
|
|
119
82
|
} catch {
|
|
120
83
|
}
|
|
121
|
-
const mask =
|
|
122
|
-
const maskHasTime = Boolean(masks?.time ?? (options?.hour || options?.minute || options?.second || options?.timeStyle));
|
|
84
|
+
const mask = this.getMask(locale);
|
|
123
85
|
if (mask) {
|
|
124
86
|
try {
|
|
125
87
|
const date = parse(sanitizedValue, mask, /* @__PURE__ */ new Date());
|
|
126
88
|
if (isValid(date)) {
|
|
127
|
-
|
|
128
|
-
setHoursToMidday(date);
|
|
129
|
-
}
|
|
89
|
+
setHoursToMidday(date);
|
|
130
90
|
return date;
|
|
131
91
|
}
|
|
132
92
|
} catch {
|
|
@@ -134,12 +94,11 @@ class DateTimeDataType extends DataType {
|
|
|
134
94
|
}
|
|
135
95
|
return void 0;
|
|
136
96
|
}
|
|
137
|
-
static getMask(locale
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return localeDateMasks.get(cacheKey);
|
|
97
|
+
static getMask(locale) {
|
|
98
|
+
if (localeDateMasks.has(locale)) {
|
|
99
|
+
return localeDateMasks.get(locale);
|
|
141
100
|
}
|
|
142
|
-
const parts = new Intl.DateTimeFormat(locale
|
|
101
|
+
const parts = new Intl.DateTimeFormat(locale).formatToParts(/* @__PURE__ */ new Date());
|
|
143
102
|
const mask = parts.reduce((mask2, part) => {
|
|
144
103
|
switch (part.type) {
|
|
145
104
|
case "literal":
|
|
@@ -150,24 +109,15 @@ class DateTimeDataType extends DataType {
|
|
|
150
109
|
return mask2 + "MM";
|
|
151
110
|
case "year":
|
|
152
111
|
return mask2 + "yyyy";
|
|
153
|
-
case "hour":
|
|
154
|
-
return mask2 + "HH";
|
|
155
|
-
case "minute":
|
|
156
|
-
return mask2 + "mm";
|
|
157
|
-
case "second":
|
|
158
|
-
return mask2 + "ss";
|
|
159
112
|
default:
|
|
160
113
|
return mask2;
|
|
161
114
|
}
|
|
162
115
|
}, "");
|
|
163
|
-
localeDateMasks.set(
|
|
116
|
+
localeDateMasks.set(locale, mask);
|
|
164
117
|
return mask;
|
|
165
118
|
}
|
|
166
119
|
}
|
|
167
120
|
export {
|
|
168
121
|
DateTimeDataType,
|
|
169
|
-
NumericDataType
|
|
170
|
-
formatNumber,
|
|
171
|
-
parseNumber,
|
|
172
|
-
stripNonNumericCharacters
|
|
122
|
+
NumericDataType
|
|
173
123
|
};
|
package/dist/utils/date.cjs
CHANGED
|
@@ -16,13 +16,7 @@ function parse(date) {
|
|
|
16
16
|
}
|
|
17
17
|
return value;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
const MASK_TIME = "HH:mm";
|
|
21
|
-
const DATETIME_SEPARATOR = ", ";
|
|
22
|
-
const DATE_MASK_TOKENS = /yyyy|yy|dd|mm/gu;
|
|
23
|
-
const TIME_MASK_TOKENS = /HH|mm|ss/gu;
|
|
24
|
-
const pad = (value) => String(value).padStart(2, "0");
|
|
25
|
-
function format(date, mask = MASK_DATE) {
|
|
19
|
+
function format(date, mask = "dd.mm.yy") {
|
|
26
20
|
if (date === void 0) {
|
|
27
21
|
return void 0;
|
|
28
22
|
}
|
|
@@ -30,43 +24,10 @@ function format(date, mask = MASK_DATE) {
|
|
|
30
24
|
if (!dateFns.isValid(value) || value === void 0) {
|
|
31
25
|
return void 0;
|
|
32
26
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
case "yyyy":
|
|
36
|
-
return String(value.getFullYear());
|
|
37
|
-
case "yy":
|
|
38
|
-
return String(value.getFullYear()).slice(2);
|
|
39
|
-
case "dd":
|
|
40
|
-
return pad(value.getDate());
|
|
41
|
-
case "mm":
|
|
42
|
-
return pad(value.getMonth() + 1);
|
|
43
|
-
default:
|
|
44
|
-
return token;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function formatTime(date, mask = MASK_TIME) {
|
|
49
|
-
if (date === void 0) {
|
|
50
|
-
return void 0;
|
|
51
|
-
}
|
|
52
|
-
const value = dateFns.isDate(date) ? date : new Date(date);
|
|
53
|
-
if (!dateFns.isValid(value)) {
|
|
54
|
-
return void 0;
|
|
55
|
-
}
|
|
56
|
-
return mask.replaceAll(TIME_MASK_TOKENS, (token) => {
|
|
57
|
-
switch (token) {
|
|
58
|
-
case "HH":
|
|
59
|
-
return pad(value.getHours());
|
|
60
|
-
case "ss":
|
|
61
|
-
return pad(value.getSeconds());
|
|
62
|
-
case "mm":
|
|
63
|
-
return pad(value.getMinutes());
|
|
64
|
-
default:
|
|
65
|
-
return token;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
27
|
+
const pad = (v) => String(v).padStart(2, "0");
|
|
28
|
+
return mask.replace("dd", pad(value.getDate())).replace("mm", pad(value.getMonth() + 1)).replace("yy", String(value.getFullYear()).slice(2));
|
|
68
29
|
}
|
|
69
|
-
const parseFromCustomString = (date = "", mask =
|
|
30
|
+
const parseFromCustomString = (date = "", mask = "dd.mm.yy", defaultMonth = void 0, defaultYear = void 0) => {
|
|
70
31
|
if (!date || !date.length) {
|
|
71
32
|
return void 0;
|
|
72
33
|
}
|
|
@@ -118,11 +79,7 @@ const parseFromISOString = (date) => {
|
|
|
118
79
|
const tempDate = new Date(date);
|
|
119
80
|
return dateFns.isValid(tempDate) ? parseFromCustomString(format(tempDate)) : void 0;
|
|
120
81
|
};
|
|
121
|
-
exports.DATETIME_SEPARATOR = DATETIME_SEPARATOR;
|
|
122
|
-
exports.MASK_DATE = MASK_DATE;
|
|
123
|
-
exports.MASK_TIME = MASK_TIME;
|
|
124
82
|
exports.format = format;
|
|
125
|
-
exports.formatTime = formatTime;
|
|
126
83
|
exports.isWeakEqual = isWeakEqual;
|
|
127
84
|
exports.parse = parse;
|
|
128
85
|
exports.parseFromCustomString = parseFromCustomString;
|