@universal-material/data-grid 0.0.0-stage → 0.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.
- package/LICENSE +21 -0
- package/README.md +172 -2
- package/custom-elements.json +4652 -0
- package/dist/attribute-converters.d.ts +53 -0
- package/dist/attribute-converters.js +98 -0
- package/dist/attribute-converters.js.map +1 -0
- package/dist/change-source.d.ts +3 -0
- package/dist/change-source.js +2 -0
- package/dist/change-source.js.map +1 -0
- package/dist/data/data-source.d.ts +164 -0
- package/dist/data/data-source.js +75 -0
- package/dist/data/data-source.js.map +1 -0
- package/dist/data/local-source.d.ts +20 -0
- package/dist/data/local-source.js +94 -0
- package/dist/data/local-source.js.map +1 -0
- package/dist/data/remote-loader.d.ts +190 -0
- package/dist/data/remote-loader.js +608 -0
- package/dist/data/remote-loader.js.map +1 -0
- package/dist/export/csv.d.ts +28 -0
- package/dist/export/csv.js +61 -0
- package/dist/export/csv.js.map +1 -0
- package/dist/export/download.d.ts +7 -0
- package/dist/export/download.js +17 -0
- package/dist/export/download.js.map +1 -0
- package/dist/export/rows.d.ts +75 -0
- package/dist/export/rows.js +134 -0
- package/dist/export/rows.js.map +1 -0
- package/dist/export/slice.d.ts +15 -0
- package/dist/export/slice.js +35 -0
- package/dist/export/slice.js.map +1 -0
- package/dist/export/types.d.ts +155 -0
- package/dist/export/types.js +2 -0
- package/dist/export/types.js.map +1 -0
- package/dist/export/write.d.ts +38 -0
- package/dist/export/write.js +178 -0
- package/dist/export/write.js.map +1 -0
- package/dist/export-pdf/client.d.ts +75 -0
- package/dist/export-pdf/client.js +155 -0
- package/dist/export-pdf/client.js.map +1 -0
- package/dist/export-pdf/engine.d.ts +73 -0
- package/dist/export-pdf/engine.js +131 -0
- package/dist/export-pdf/engine.js.map +1 -0
- package/dist/export-pdf/grid-pdf.wasm +0 -0
- package/dist/export-pdf/index.d.ts +27 -0
- package/dist/export-pdf/index.js +566 -0
- package/dist/export-pdf/index.js.map +1 -0
- package/dist/export-pdf/serialize.d.ts +23 -0
- package/dist/export-pdf/serialize.js +127 -0
- package/dist/export-pdf/serialize.js.map +1 -0
- package/dist/export-pdf/types.d.ts +150 -0
- package/dist/export-pdf/types.js +2 -0
- package/dist/export-pdf/types.js.map +1 -0
- package/dist/export-pdf/worker.d.ts +2 -0
- package/dist/export-pdf/worker.js +81 -0
- package/dist/export-pdf/worker.js.map +1 -0
- package/dist/export-xlsx/formats.d.ts +14 -0
- package/dist/export-xlsx/formats.js +40 -0
- package/dist/export-xlsx/formats.js.map +1 -0
- package/dist/export-xlsx/index.d.ts +74 -0
- package/dist/export-xlsx/index.js +137 -0
- package/dist/export-xlsx/index.js.map +1 -0
- package/dist/features/adaptive.d.ts +25 -0
- package/dist/features/adaptive.js +47 -0
- package/dist/features/adaptive.js.map +1 -0
- package/dist/features/cell-content-focus.d.ts +29 -0
- package/dist/features/cell-content-focus.js +95 -0
- package/dist/features/cell-content-focus.js.map +1 -0
- package/dist/features/cell-range.d.ts +97 -0
- package/dist/features/cell-range.js +75 -0
- package/dist/features/cell-range.js.map +1 -0
- package/dist/features/clipboard.d.ts +28 -0
- package/dist/features/clipboard.js +48 -0
- package/dist/features/clipboard.js.map +1 -0
- package/dist/features/column-chooser.d.ts +91 -0
- package/dist/features/column-chooser.js +451 -0
- package/dist/features/column-chooser.js.map +1 -0
- package/dist/features/column-dnd.d.ts +10 -0
- package/dist/features/column-dnd.js +126 -0
- package/dist/features/column-dnd.js.map +1 -0
- package/dist/features/context-menu.d.ts +122 -0
- package/dist/features/context-menu.js +153 -0
- package/dist/features/context-menu.js.map +1 -0
- package/dist/features/drag-helper.d.ts +39 -0
- package/dist/features/drag-helper.js +108 -0
- package/dist/features/drag-helper.js.map +1 -0
- package/dist/features/drop-position.d.ts +15 -0
- package/dist/features/drop-position.js +24 -0
- package/dist/features/drop-position.js.map +1 -0
- package/dist/features/editing.d.ts +111 -0
- package/dist/features/editing.js +244 -0
- package/dist/features/editing.js.map +1 -0
- package/dist/features/filter-row.d.ts +80 -0
- package/dist/features/filter-row.js +538 -0
- package/dist/features/filter-row.js.map +1 -0
- package/dist/features/filtering.d.ts +55 -0
- package/dist/features/filtering.js +209 -0
- package/dist/features/filtering.js.map +1 -0
- package/dist/features/group-dnd.d.ts +11 -0
- package/dist/features/group-dnd.js +119 -0
- package/dist/features/group-dnd.js.map +1 -0
- package/dist/features/header-filter.d.ts +100 -0
- package/dist/features/header-filter.js +588 -0
- package/dist/features/header-filter.js.map +1 -0
- package/dist/features/host-label.d.ts +36 -0
- package/dist/features/host-label.js +184 -0
- package/dist/features/host-label.js.map +1 -0
- package/dist/features/keyboard.d.ts +59 -0
- package/dist/features/keyboard.js +127 -0
- package/dist/features/keyboard.js.map +1 -0
- package/dist/features/menu.d.ts +113 -0
- package/dist/features/menu.js +491 -0
- package/dist/features/menu.js.map +1 -0
- package/dist/features/resize.d.ts +82 -0
- package/dist/features/resize.js +214 -0
- package/dist/features/resize.js.map +1 -0
- package/dist/features/scroll-port.d.ts +51 -0
- package/dist/features/scroll-port.js +329 -0
- package/dist/features/scroll-port.js.map +1 -0
- package/dist/features/search.d.ts +45 -0
- package/dist/features/search.js +123 -0
- package/dist/features/search.js.map +1 -0
- package/dist/features/selection.d.ts +37 -0
- package/dist/features/selection.js +103 -0
- package/dist/features/selection.js.map +1 -0
- package/dist/features/sorting.d.ts +39 -0
- package/dist/features/sorting.js +53 -0
- package/dist/features/sorting.js.map +1 -0
- package/dist/features/toolbar.d.ts +125 -0
- package/dist/features/toolbar.js +135 -0
- package/dist/features/toolbar.js.map +1 -0
- package/dist/features/tree.d.ts +53 -0
- package/dist/features/tree.js +94 -0
- package/dist/features/tree.js.map +1 -0
- package/dist/features/validation.d.ts +48 -0
- package/dist/features/validation.js +172 -0
- package/dist/features/validation.js.map +1 -0
- package/dist/grid-column-def.d.ts +521 -0
- package/dist/grid-column-def.js +32 -0
- package/dist/grid-column-def.js.map +1 -0
- package/dist/grid-column.d.ts +173 -0
- package/dist/grid-column.js +382 -0
- package/dist/grid-column.js.map +1 -0
- package/dist/grid-i18n.d.ts +469 -0
- package/dist/grid-i18n.js +3222 -0
- package/dist/grid-i18n.js.map +1 -0
- package/dist/grid.d.ts +1510 -0
- package/dist/grid.js +15972 -0
- package/dist/grid.js.map +1 -0
- package/dist/grid.min.js +3966 -0
- package/dist/grid.styles.d.ts +2 -0
- package/dist/grid.styles.js +2849 -0
- package/dist/grid.styles.js.map +1 -0
- package/dist/render/cell.d.ts +16 -0
- package/dist/render/cell.js +78 -0
- package/dist/render/cell.js.map +1 -0
- package/dist/render/column-window.d.ts +18 -0
- package/dist/render/column-window.js +50 -0
- package/dist/render/column-window.js.map +1 -0
- package/dist/render/content.d.ts +45 -0
- package/dist/render/content.js +140 -0
- package/dist/render/content.js.map +1 -0
- package/dist/render/editors.d.ts +28 -0
- package/dist/render/editors.js +41 -0
- package/dist/render/editors.js.map +1 -0
- package/dist/render/footer.d.ts +61 -0
- package/dist/render/footer.js +61 -0
- package/dist/render/footer.js.map +1 -0
- package/dist/render/group-row.d.ts +35 -0
- package/dist/render/group-row.js +60 -0
- package/dist/render/group-row.js.map +1 -0
- package/dist/render/header.d.ts +108 -0
- package/dist/render/header.js +124 -0
- package/dist/render/header.js.map +1 -0
- package/dist/render/keyed-rows.d.ts +25 -0
- package/dist/render/keyed-rows.js +98 -0
- package/dist/render/keyed-rows.js.map +1 -0
- package/dist/render/virtualizer.d.ts +158 -0
- package/dist/render/virtualizer.js +721 -0
- package/dist/render/virtualizer.js.map +1 -0
- package/dist/row-model/added-rows.d.ts +32 -0
- package/dist/row-model/added-rows.js +95 -0
- package/dist/row-model/added-rows.js.map +1 -0
- package/dist/row-model/cell-range.d.ts +71 -0
- package/dist/row-model/cell-range.js +187 -0
- package/dist/row-model/cell-range.js.map +1 -0
- package/dist/row-model/columns.d.ts +102 -0
- package/dist/row-model/columns.js +222 -0
- package/dist/row-model/columns.js.map +1 -0
- package/dist/row-model/compare.d.ts +40 -0
- package/dist/row-model/compare.js +590 -0
- package/dist/row-model/compare.js.map +1 -0
- package/dist/row-model/distinct.d.ts +39 -0
- package/dist/row-model/distinct.js +105 -0
- package/dist/row-model/distinct.js.map +1 -0
- package/dist/row-model/filter.d.ts +80 -0
- package/dist/row-model/filter.js +582 -0
- package/dist/row-model/filter.js.map +1 -0
- package/dist/row-model/flatten.d.ts +129 -0
- package/dist/row-model/flatten.js +511 -0
- package/dist/row-model/flatten.js.map +1 -0
- package/dist/row-model/fold.d.ts +25 -0
- package/dist/row-model/fold.js +104 -0
- package/dist/row-model/fold.js.map +1 -0
- package/dist/row-model/format.d.ts +58 -0
- package/dist/row-model/format.js +239 -0
- package/dist/row-model/format.js.map +1 -0
- package/dist/row-model/group.d.ts +30 -0
- package/dist/row-model/group.js +173 -0
- package/dist/row-model/group.js.map +1 -0
- package/dist/row-model/lru.d.ts +19 -0
- package/dist/row-model/lru.js +48 -0
- package/dist/row-model/lru.js.map +1 -0
- package/dist/row-model/sort.d.ts +30 -0
- package/dist/row-model/sort.js +107 -0
- package/dist/row-model/sort.js.map +1 -0
- package/dist/row-model/summary.d.ts +64 -0
- package/dist/row-model/summary.js +213 -0
- package/dist/row-model/summary.js.map +1 -0
- package/dist/row-model/tree.d.ts +116 -0
- package/dist/row-model/tree.js +478 -0
- package/dist/row-model/tree.js.map +1 -0
- package/dist/row-model/types.d.ts +109 -0
- package/dist/row-model/types.js +5 -0
- package/dist/row-model/types.js.map +1 -0
- package/dist/row-model/value.d.ts +20 -0
- package/dist/row-model/value.js +57 -0
- package/dist/row-model/value.js.map +1 -0
- package/dist/state/grid-state.d.ts +147 -0
- package/dist/state/grid-state.js +295 -0
- package/dist/state/grid-state.js.map +1 -0
- package/dist/state/storage.d.ts +33 -0
- package/dist/state/storage.js +62 -0
- package/dist/state/storage.js.map +1 -0
- package/dist/state/versioned.d.ts +18 -0
- package/dist/state/versioned.js +56 -0
- package/dist/state/versioned.js.map +1 -0
- package/package.json +145 -6
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comparação de texto que ignora caixa e acento (o equivalente a
|
|
3
|
+
* `Intl.Collator` com `sensitivity: 'base'` para busca de trecho, que o
|
|
4
|
+
* `Collator` não faz).
|
|
5
|
+
*
|
|
6
|
+
* Para não alocar uma cópia "dobrada" de cada célula a cada tecla (1 milhão
|
|
7
|
+
* de linhas × colunas visíveis), a busca vira uma `RegExp` sobre o texto
|
|
8
|
+
* ORIGINAL: cada letra do termo vira a classe das suas variantes (`e` →
|
|
9
|
+
* `[eéèêë…]`), seguida de marcas combinantes opcionais (texto em NFD).
|
|
10
|
+
*/
|
|
11
|
+
const MARKS = /\p{M}/gu;
|
|
12
|
+
/** Algum caractere fora do ASCII (só então vale normalizar). */
|
|
13
|
+
const NON_ASCII = /[^\t\n\r -~]/u;
|
|
14
|
+
/** Texto sem acento e em minúsculas (`ς` final vira `σ`, como na busca). */
|
|
15
|
+
export const foldText = (text) => {
|
|
16
|
+
if (!NON_ASCII.test(text)) {
|
|
17
|
+
return text.toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
const lower = text.normalize('NFD').replace(MARKS, '')
|
|
20
|
+
.toLowerCase();
|
|
21
|
+
return lower.replace(/ς/g, 'σ');
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Variantes de cada caractere dobrado de 1 caractere: `e` → `éèêëēĕėęě…`.
|
|
25
|
+
* Construída uma vez, sob demanda (≈ 8 mil code points: Latin-1 a Latin
|
|
26
|
+
* Extended Additional, grego e cirílico).
|
|
27
|
+
*/
|
|
28
|
+
let variants;
|
|
29
|
+
const RANGES = [
|
|
30
|
+
[0x41, 0x5a],
|
|
31
|
+
[0xc0, 0x24f],
|
|
32
|
+
[0x370, 0x4ff],
|
|
33
|
+
[0x1e00, 0x1fff],
|
|
34
|
+
];
|
|
35
|
+
const getVariants = () => {
|
|
36
|
+
if (variants) {
|
|
37
|
+
return variants;
|
|
38
|
+
}
|
|
39
|
+
variants = new Map();
|
|
40
|
+
for (const [start, end] of RANGES) {
|
|
41
|
+
for (let code = start; code <= end; code++) {
|
|
42
|
+
const char = String.fromCodePoint(code);
|
|
43
|
+
const folded = foldText(char);
|
|
44
|
+
if (folded.length !== 1 || folded === char) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
variants.set(folded, (variants.get(folded) ?? '') + char);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return variants;
|
|
51
|
+
};
|
|
52
|
+
const escapeClassChar = (char) => (/[\\\]^-]/).test(char) ? `\\${char}` : char;
|
|
53
|
+
const escapeRegExp = (char) => (/[.*+?^${}()|[\]\\/-]/).test(char) ? `\\${char}` : char;
|
|
54
|
+
/**
|
|
55
|
+
* `RegExp` que acha `term` em qualquer texto ignorando caixa e acento.
|
|
56
|
+
* `null` para termo vazio (casa com tudo). `term` é texto do usuário: todo
|
|
57
|
+
* caractere especial é escapado.
|
|
58
|
+
*/
|
|
59
|
+
export const createTextMatcher = (term, mode = 'contains') => {
|
|
60
|
+
const folded = foldText(term);
|
|
61
|
+
if (!folded) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
const table = getVariants();
|
|
65
|
+
let source = '';
|
|
66
|
+
for (const char of folded) {
|
|
67
|
+
const extra = table.get(char);
|
|
68
|
+
const upper = char.toUpperCase();
|
|
69
|
+
const own = upper !== char && upper.length === 1 ? char + upper : char;
|
|
70
|
+
source += extra || own.length > 1
|
|
71
|
+
? `[${[...new Set(own + (extra ?? ''))].map(escapeClassChar).join('')}]`
|
|
72
|
+
: escapeRegExp(char);
|
|
73
|
+
source += '\\p{M}*';
|
|
74
|
+
}
|
|
75
|
+
if (mode === 'startswith' || mode === 'equals') {
|
|
76
|
+
source = `^${source}`;
|
|
77
|
+
}
|
|
78
|
+
if (mode === 'endswith' || mode === 'equals') {
|
|
79
|
+
source = `${source}$`;
|
|
80
|
+
}
|
|
81
|
+
return new RegExp(source, 'u');
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Trechos de `text` que casam com `matcher` (para o destaque da busca):
|
|
85
|
+
* lista alternada [fora, dentro, fora, …], sempre começando por "fora".
|
|
86
|
+
*/
|
|
87
|
+
export const splitMatches = (text, matcher) => {
|
|
88
|
+
if (!matcher || !text) {
|
|
89
|
+
return [text];
|
|
90
|
+
}
|
|
91
|
+
const global = new RegExp(matcher.source, 'gu');
|
|
92
|
+
const parts = [];
|
|
93
|
+
let last = 0;
|
|
94
|
+
for (const match of text.matchAll(global)) {
|
|
95
|
+
if (!match[0]) {
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
parts.push(text.slice(last, match.index), match[0]);
|
|
99
|
+
last = match.index + match[0].length;
|
|
100
|
+
}
|
|
101
|
+
parts.push(text.slice(last));
|
|
102
|
+
return parts;
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=fold.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fold.js","sourceRoot":"","sources":["../../src/row-model/fold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,KAAK,GAAG,SAAS,CAAC;AACxB,gEAAgE;AAChE,MAAM,SAAS,GAAG,eAAe,CAAC;AAElC,4EAA4E;AAC5E,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAU,EAAE;IAC/C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;SACnD,WAAW,EAAE,CAAC;IAEjB,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC,CAAC;AAEF;;;;GAIG;AACH,IAAI,QAAyC,CAAC;AAE9C,MAAM,MAAM,GAAgC;IA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,CAAC,CAAC;AACjC,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,OAAsB,EAAY,EAAE;IAC7E,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;QACtB,OAAO,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAChD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,IAAI,GAAG,CAAC,CAAC;IAEb,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1C,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACd,MAAM;QACR,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD,IAAI,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAE7B,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["/**\n * Comparação de texto que ignora caixa e acento (o equivalente a\n * `Intl.Collator` com `sensitivity: 'base'` para busca de trecho, que o\n * `Collator` não faz).\n *\n * Para não alocar uma cópia \"dobrada\" de cada célula a cada tecla (1 milhão\n * de linhas × colunas visíveis), a busca vira uma `RegExp` sobre o texto\n * ORIGINAL: cada letra do termo vira a classe das suas variantes (`e` →\n * `[eéèêë…]`), seguida de marcas combinantes opcionais (texto em NFD).\n */\n\nconst MARKS = /\\p{M}/gu;\n/** Algum caractere fora do ASCII (só então vale normalizar). */\nconst NON_ASCII = /[^\\t\\n\\r -~]/u;\n\n/** Texto sem acento e em minúsculas (`ς` final vira `σ`, como na busca). */\nexport const foldText = (text: string): string => {\n if (!NON_ASCII.test(text)) {\n return text.toLowerCase();\n }\n\n const lower = text.normalize('NFD').replace(MARKS, '')\n .toLowerCase();\n\n return lower.replace(/ς/g, 'σ');\n};\n\n/**\n * Variantes de cada caractere dobrado de 1 caractere: `e` → `éèêëēĕėęě…`.\n * Construída uma vez, sob demanda (≈ 8 mil code points: Latin-1 a Latin\n * Extended Additional, grego e cirílico).\n */\nlet variants: Map<string, string> | undefined;\n\nconst RANGES: readonly [number, number][] = [\n [0x41, 0x5a],\n [0xc0, 0x24f],\n [0x370, 0x4ff],\n [0x1e00, 0x1fff],\n];\n\nconst getVariants = (): Map<string, string> => {\n if (variants) {\n return variants;\n }\n\n variants = new Map();\n\n for (const [start, end] of RANGES) {\n for (let code = start; code <= end; code++) {\n const char = String.fromCodePoint(code);\n const folded = foldText(char);\n\n if (folded.length !== 1 || folded === char) {\n continue;\n }\n\n variants.set(folded, (variants.get(folded) ?? '') + char);\n }\n }\n\n return variants;\n};\n\nconst escapeClassChar = (char: string): string =>\n (/[\\\\\\]^-]/).test(char) ? `\\\\${char}` : char;\n\nconst escapeRegExp = (char: string): string =>\n (/[.*+?^${}()|[\\]\\\\/-]/).test(char) ? `\\\\${char}` : char;\n\nexport type TextMatchMode = 'contains' | 'startswith' | 'endswith' | 'equals';\n\n/**\n * `RegExp` que acha `term` em qualquer texto ignorando caixa e acento.\n * `null` para termo vazio (casa com tudo). `term` é texto do usuário: todo\n * caractere especial é escapado.\n */\nexport const createTextMatcher = (term: string, mode: TextMatchMode = 'contains'): RegExp | null => {\n const folded = foldText(term);\n\n if (!folded) {\n return null;\n }\n\n const table = getVariants();\n let source = '';\n\n for (const char of folded) {\n const extra = table.get(char);\n const upper = char.toUpperCase();\n const own = upper !== char && upper.length === 1 ? char + upper : char;\n\n source += extra || own.length > 1\n ? `[${[...new Set(own + (extra ?? ''))].map(escapeClassChar).join('')}]`\n : escapeRegExp(char);\n source += '\\\\p{M}*';\n }\n\n if (mode === 'startswith' || mode === 'equals') {\n source = `^${source}`;\n }\n\n if (mode === 'endswith' || mode === 'equals') {\n source = `${source}$`;\n }\n\n return new RegExp(source, 'u');\n};\n\n/**\n * Trechos de `text` que casam com `matcher` (para o destaque da busca):\n * lista alternada [fora, dentro, fora, …], sempre começando por \"fora\".\n */\nexport const splitMatches = (text: string, matcher: RegExp | null): string[] => {\n if (!matcher || !text) {\n return [text];\n }\n\n const global = new RegExp(matcher.source, 'gu');\n const parts: string[] = [];\n let last = 0;\n\n for (const match of text.matchAll(global)) {\n if (!match[0]) {\n break;\n }\n\n parts.push(text.slice(last, match.index), match[0]);\n last = match.index + match[0].length;\n }\n\n parts.push(text.slice(last));\n\n return parts;\n};\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { GridColumnAlignment, GridColumnDataType, GridColumnDef } from '../grid-column-def.js';
|
|
2
|
+
/**
|
|
3
|
+
* Converte para `Date`: `Date` válida, número (epoch em ms) ou string ISO.
|
|
4
|
+
* Data sem hora (`2024-03-05`) é meia-noite LOCAL — `new Date()` a leria
|
|
5
|
+
* como UTC e o dia "andaria" a oeste de Greenwich. Datas que transbordam
|
|
6
|
+
* (`2024-02-30`) são inválidas, não 1º de março.
|
|
7
|
+
*/
|
|
8
|
+
export declare const toDate: (value: unknown) => Date | undefined;
|
|
9
|
+
/** Número de `number`/`bigint` ou de string numérica; senão `undefined`. */
|
|
10
|
+
export declare const toNumber: (value: unknown) => number | bigint | undefined;
|
|
11
|
+
/** Valor no tipo da coluna (para comparar); o original quando não converte. */
|
|
12
|
+
export declare const coerceValue: (value: unknown, dataType: GridColumnDataType | null | undefined) => unknown;
|
|
13
|
+
/**
|
|
14
|
+
* `dataType` da coluna: o informado ou o tipo do 1º valor não nulo (como o
|
|
15
|
+
* DevExtreme). String ISO não vira data por inferência — só com `dataType`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const resolveDataType: (items: readonly unknown[], column: GridColumnDef) => GridColumnDataType | undefined;
|
|
18
|
+
export declare const resolveAlignment: (column: GridColumnDef, dataType: GridColumnDataType | undefined) => GridColumnAlignment;
|
|
19
|
+
export declare const DEFAULT_DATE: Intl.DateTimeFormatOptions;
|
|
20
|
+
export declare const DEFAULT_DATETIME: Intl.DateTimeFormatOptions;
|
|
21
|
+
/**
|
|
22
|
+
* Limite do cache de formatadores (spec 14): a chave inclui idioma e opções
|
|
23
|
+
* do hospedeiro, então sem limite cresceria com cada combinação nova.
|
|
24
|
+
*/
|
|
25
|
+
export declare const FORMATTER_CACHE_LIMIT = 128;
|
|
26
|
+
/** Diagnóstico/testes de vazamento. */
|
|
27
|
+
export declare const _formatterCacheSize: () => number;
|
|
28
|
+
export declare const getNumberFormat: (language: string | undefined, options?: Intl.NumberFormatOptions) => Intl.NumberFormat;
|
|
29
|
+
export declare const getDateTimeFormat: (language: string | undefined, options: Intl.DateTimeFormatOptions, fallback?: Intl.DateTimeFormatOptions) => Intl.DateTimeFormat;
|
|
30
|
+
export interface FormatContext {
|
|
31
|
+
language: string | undefined;
|
|
32
|
+
dataType: GridColumnDataType | undefined;
|
|
33
|
+
trueText: string;
|
|
34
|
+
falseText: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Texto exibido de um valor, na ordem: `displayValue` → vazio (`emptyText`)
|
|
38
|
+
* → `format` função → `format` `Intl` / padrão do tipo. Valor que não
|
|
39
|
+
* converte no tipo (string que não é data) sai como texto bruto.
|
|
40
|
+
*/
|
|
41
|
+
export declare const formatCellValue: (value: unknown, item: unknown, column: GridColumnDef, context: FormatContext) => string;
|
|
42
|
+
/**
|
|
43
|
+
* Valor a desenhar como ícone (coluna `boolean` com `booleanDisplay:
|
|
44
|
+
* 'icon'`), ou `undefined` para exibir texto. `displayValue` e `format`
|
|
45
|
+
* função continuam mandando no texto; vazio segue `emptyText`.
|
|
46
|
+
*/
|
|
47
|
+
export declare const booleanIconValue: (value: unknown, column: GridColumnDef, context: FormatContext) => boolean | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Caracteres (sem caixa/acento, por `fold`) que o texto formatado de um valor
|
|
50
|
+
* do tipo da coluna pode ter: amostras do formatador cobrem dígitos,
|
|
51
|
+
* separadores, sinais, símbolos, nomes de meses e AM/PM. `undefined` quando o
|
|
52
|
+
* texto depende do item (`displayValue`, `format` função) ou é texto livre.
|
|
53
|
+
* Usado pela busca para pular colunas de número/data em termos com letras.
|
|
54
|
+
*/
|
|
55
|
+
export declare const displayAlphabet: (column: GridColumnDef, context: FormatContext, fold: (text: string) => string) => Set<string> | undefined;
|
|
56
|
+
/** Texto exibido da célula de `item` na coluna. */
|
|
57
|
+
export declare const formatCell: (item: unknown, column: GridColumnDef, context: FormatContext) => string;
|
|
58
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { LruCache } from './lru.js';
|
|
2
|
+
import { getCellValue, toDisplayText } from './value.js';
|
|
3
|
+
// ------------------------------------------------------------------ valores
|
|
4
|
+
const ISO_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
5
|
+
const ISO_DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$/i;
|
|
6
|
+
const daysInMonth = (year, month) => new Date(year, month, 0).getDate();
|
|
7
|
+
const validParts = (year, month, day) => month >= 1 && month <= 12 && day >= 1 && day <= daysInMonth(year, month);
|
|
8
|
+
/**
|
|
9
|
+
* Converte para `Date`: `Date` válida, número (epoch em ms) ou string ISO.
|
|
10
|
+
* Data sem hora (`2024-03-05`) é meia-noite LOCAL — `new Date()` a leria
|
|
11
|
+
* como UTC e o dia "andaria" a oeste de Greenwich. Datas que transbordam
|
|
12
|
+
* (`2024-02-30`) são inválidas, não 1º de março.
|
|
13
|
+
*/
|
|
14
|
+
export const toDate = (value) => {
|
|
15
|
+
if (value instanceof Date) {
|
|
16
|
+
return Number.isNaN(value.getTime()) ? undefined : value;
|
|
17
|
+
}
|
|
18
|
+
if (typeof value === 'number') {
|
|
19
|
+
return Number.isFinite(value) ? new Date(value) : undefined;
|
|
20
|
+
}
|
|
21
|
+
if (typeof value !== 'string') {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const text = value.trim();
|
|
25
|
+
const dateOnly = ISO_DATE.exec(text);
|
|
26
|
+
if (dateOnly) {
|
|
27
|
+
const [year, month, day] = dateOnly.slice(1).map(Number);
|
|
28
|
+
return validParts(year, month, day) ? new Date(year, month - 1, day) : undefined;
|
|
29
|
+
}
|
|
30
|
+
const dateTime = ISO_DATE_TIME.exec(text);
|
|
31
|
+
if (!dateTime) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const [year, month, day, hour, minute, second = 0] = dateTime.slice(1).map(part => Number(part ?? 0));
|
|
35
|
+
if (!validParts(year, month, day) || hour > 23 || minute > 59 || second > 59) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const date = new Date(text.replace(' ', 'T'));
|
|
39
|
+
return Number.isNaN(date.getTime()) ? undefined : date;
|
|
40
|
+
};
|
|
41
|
+
/** Número de `number`/`bigint` ou de string numérica; senão `undefined`. */
|
|
42
|
+
export const toNumber = (value) => {
|
|
43
|
+
if (typeof value === 'bigint') {
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
if (typeof value === 'number') {
|
|
47
|
+
return Number.isNaN(value) ? undefined : value;
|
|
48
|
+
}
|
|
49
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
50
|
+
const numeric = Number(value);
|
|
51
|
+
return Number.isNaN(numeric) ? undefined : numeric;
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
};
|
|
55
|
+
/** Valor no tipo da coluna (para comparar); o original quando não converte. */
|
|
56
|
+
export const coerceValue = (value, dataType) => {
|
|
57
|
+
if (value === null || value === undefined || !dataType) {
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
switch (dataType) {
|
|
61
|
+
case 'number':
|
|
62
|
+
return toNumber(value) ?? value;
|
|
63
|
+
case 'date':
|
|
64
|
+
case 'datetime':
|
|
65
|
+
return toDate(value) ?? value;
|
|
66
|
+
case 'boolean':
|
|
67
|
+
return typeof value === 'boolean' ? value : value === 'true' ? true : value === 'false' ? false : value;
|
|
68
|
+
case 'string':
|
|
69
|
+
return toDisplayText(value);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
// ----------------------------------------------------------------- inferência
|
|
73
|
+
const typeOfValue = (value) => {
|
|
74
|
+
switch (typeof value) {
|
|
75
|
+
case 'number':
|
|
76
|
+
case 'bigint':
|
|
77
|
+
return 'number';
|
|
78
|
+
case 'boolean':
|
|
79
|
+
return 'boolean';
|
|
80
|
+
case 'string':
|
|
81
|
+
return 'string';
|
|
82
|
+
default:
|
|
83
|
+
return value instanceof Date ? 'date' : undefined;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* `dataType` da coluna: o informado ou o tipo do 1º valor não nulo (como o
|
|
88
|
+
* DevExtreme). String ISO não vira data por inferência — só com `dataType`.
|
|
89
|
+
*/
|
|
90
|
+
export const resolveDataType = (items, column) => {
|
|
91
|
+
if (column.dataType) {
|
|
92
|
+
return column.dataType;
|
|
93
|
+
}
|
|
94
|
+
if (!column.path && !column.valueGetter) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
for (const item of items) {
|
|
98
|
+
const value = getCellValue(item, column);
|
|
99
|
+
if (value !== null && value !== undefined) {
|
|
100
|
+
return typeOfValue(value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return undefined;
|
|
104
|
+
};
|
|
105
|
+
export const resolveAlignment = (column, dataType) => column.alignment
|
|
106
|
+
?? (dataType === 'number' ? 'end' : dataType === 'boolean' ? 'center' : 'start');
|
|
107
|
+
// ---------------------------------------------------------------- formatadores
|
|
108
|
+
const DEFAULT_NUMBER = { useGrouping: false, maximumFractionDigits: 20 };
|
|
109
|
+
export const DEFAULT_DATE = { year: 'numeric', month: 'numeric', day: 'numeric' };
|
|
110
|
+
export const DEFAULT_DATETIME = { ...DEFAULT_DATE, hour: 'numeric', minute: '2-digit' };
|
|
111
|
+
/**
|
|
112
|
+
* Limite do cache de formatadores (spec 14): a chave inclui idioma e opções
|
|
113
|
+
* do hospedeiro, então sem limite cresceria com cada combinação nova.
|
|
114
|
+
*/
|
|
115
|
+
export const FORMATTER_CACHE_LIMIT = 128;
|
|
116
|
+
const formatters = new LruCache(FORMATTER_CACHE_LIMIT);
|
|
117
|
+
/** Diagnóstico/testes de vazamento. */
|
|
118
|
+
export const _formatterCacheSize = () => formatters.size;
|
|
119
|
+
/**
|
|
120
|
+
* Formatador `Intl` em cache por (idioma, opções). Idioma ou opções
|
|
121
|
+
* inválidos caem no padrão em vez de lançar no meio do render.
|
|
122
|
+
*/
|
|
123
|
+
const getFormatter = (kind, language, options, fallback) => {
|
|
124
|
+
const key = `${kind}|${language ?? ''}|${JSON.stringify(options)}`;
|
|
125
|
+
let formatter = formatters.get(key);
|
|
126
|
+
if (!formatter) {
|
|
127
|
+
const create = (locale, opts) => kind === 'number'
|
|
128
|
+
? new Intl.NumberFormat(locale, opts)
|
|
129
|
+
: new Intl.DateTimeFormat(locale, opts);
|
|
130
|
+
try {
|
|
131
|
+
formatter = create(language, options);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
try {
|
|
135
|
+
formatter = create(language, fallback);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
formatter = create(undefined, fallback);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
formatters.set(key, formatter);
|
|
142
|
+
}
|
|
143
|
+
return formatter;
|
|
144
|
+
};
|
|
145
|
+
export const getNumberFormat = (language, options = DEFAULT_NUMBER) => getFormatter('number', language, options, DEFAULT_NUMBER);
|
|
146
|
+
export const getDateTimeFormat = (language, options, fallback = DEFAULT_DATE) => getFormatter('date', language, options, fallback);
|
|
147
|
+
const isBlank = (value) => value === null
|
|
148
|
+
|| value === undefined
|
|
149
|
+
|| (typeof value === 'number' && Number.isNaN(value))
|
|
150
|
+
|| (value instanceof Date && Number.isNaN(value.getTime()));
|
|
151
|
+
/**
|
|
152
|
+
* Texto exibido de um valor, na ordem: `displayValue` → vazio (`emptyText`)
|
|
153
|
+
* → `format` função → `format` `Intl` / padrão do tipo. Valor que não
|
|
154
|
+
* converte no tipo (string que não é data) sai como texto bruto.
|
|
155
|
+
*/
|
|
156
|
+
export const formatCellValue = (value, item, column, context) => {
|
|
157
|
+
if (column.displayValue) {
|
|
158
|
+
return toDisplayText(column.displayValue(value, item));
|
|
159
|
+
}
|
|
160
|
+
if (isBlank(value)) {
|
|
161
|
+
return column.emptyText ?? '';
|
|
162
|
+
}
|
|
163
|
+
const { format } = column;
|
|
164
|
+
if (typeof format === 'function') {
|
|
165
|
+
return toDisplayText(format(value, item));
|
|
166
|
+
}
|
|
167
|
+
const { dataType } = context;
|
|
168
|
+
if (dataType === 'number') {
|
|
169
|
+
const numeric = toNumber(value);
|
|
170
|
+
return numeric === undefined
|
|
171
|
+
? toDisplayText(value)
|
|
172
|
+
: getNumberFormat(context.language, format ?? undefined).format(numeric);
|
|
173
|
+
}
|
|
174
|
+
if (dataType === 'date' || dataType === 'datetime') {
|
|
175
|
+
const date = toDate(value);
|
|
176
|
+
const fallback = dataType === 'date' ? DEFAULT_DATE : DEFAULT_DATETIME;
|
|
177
|
+
return date
|
|
178
|
+
? getDateTimeFormat(context.language, format ?? fallback, fallback).format(date)
|
|
179
|
+
: toDisplayText(value);
|
|
180
|
+
}
|
|
181
|
+
if (dataType === 'boolean' && typeof value === 'boolean') {
|
|
182
|
+
return value ? context.trueText : context.falseText;
|
|
183
|
+
}
|
|
184
|
+
return toDisplayText(value);
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Valor a desenhar como ícone (coluna `boolean` com `booleanDisplay:
|
|
188
|
+
* 'icon'`), ou `undefined` para exibir texto. `displayValue` e `format`
|
|
189
|
+
* função continuam mandando no texto; vazio segue `emptyText`.
|
|
190
|
+
*/
|
|
191
|
+
export const booleanIconValue = (value, column, context) => {
|
|
192
|
+
if (column.booleanDisplay !== 'icon' || context.dataType !== 'boolean' || column.displayValue || typeof column.format === 'function') {
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
const coerced = coerceValue(value, 'boolean');
|
|
196
|
+
return typeof coerced === 'boolean' ? coerced : undefined;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Caracteres (sem caixa/acento, por `fold`) que o texto formatado de um valor
|
|
200
|
+
* do tipo da coluna pode ter: amostras do formatador cobrem dígitos,
|
|
201
|
+
* separadores, sinais, símbolos, nomes de meses e AM/PM. `undefined` quando o
|
|
202
|
+
* texto depende do item (`displayValue`, `format` função) ou é texto livre.
|
|
203
|
+
* Usado pela busca para pular colunas de número/data em termos com letras.
|
|
204
|
+
*/
|
|
205
|
+
export const displayAlphabet = (column, context, fold) => {
|
|
206
|
+
if (column.displayValue || typeof column.format === 'function') {
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
const samples = [column.emptyText ?? ''];
|
|
210
|
+
const { dataType, language } = context;
|
|
211
|
+
if (dataType === 'number') {
|
|
212
|
+
const formatter = getNumberFormat(language, column.format ?? undefined);
|
|
213
|
+
for (const sample of [-1234567890.125, 0.5, 9.87e21, -0.000001234, 0]) {
|
|
214
|
+
samples.push(formatter.format(sample));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else if (dataType === 'date' || dataType === 'datetime') {
|
|
218
|
+
const fallback = dataType === 'date' ? DEFAULT_DATE : DEFAULT_DATETIME;
|
|
219
|
+
const formatter = getDateTimeFormat(language, column.format ?? fallback, fallback);
|
|
220
|
+
for (let month = 0; month < 12; month++) {
|
|
221
|
+
for (const day of [1, 10, 20, 28]) {
|
|
222
|
+
for (const hour of [0, 13]) {
|
|
223
|
+
samples.push(formatter.format(new Date(2024, month, day, hour, 5, 7)));
|
|
224
|
+
samples.push(formatter.format(new Date(1999, month, day + 1, hour + 9, 48, 59)));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else if (dataType === 'boolean') {
|
|
230
|
+
samples.push(context.trueText, context.falseText);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
return new Set(Array.from(fold(samples.join(''))));
|
|
236
|
+
};
|
|
237
|
+
/** Texto exibido da célula de `item` na coluna. */
|
|
238
|
+
export const formatCell = (item, column, context) => formatCellValue(getCellValue(item, column), item, column, context);
|
|
239
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/row-model/format.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEzD,6EAA6E;AAE7E,MAAM,QAAQ,GAAG,2BAA2B,CAAC;AAC7C,MAAM,aAAa,GAAG,6FAA6F,CAAC;AAEpH,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,KAAa,EAAU,EAAE,CAC1D,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AAErC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW,EAAW,EAAE,CACvE,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAE3E;;;;;GAKG;AACH,MAAM,CAAC,MAA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CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;oBACvE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;gBACnF,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;SAAM,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;SAAM,CAAC;QACN,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF,mDAAmD;AACnD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAa,EAAE,MAAqB,EAAE,OAAsB,EAAU,EAAE,CACjG,eAAe,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC","sourcesContent":["import type { GridColumnAlignment, GridColumnDataType, GridColumnDef } from '../grid-column-def.js';\r\nimport { LruCache } from './lru.js';\r\nimport { getCellValue, toDisplayText } from './value.js';\r\n\r\n// ------------------------------------------------------------------ valores\r\n\r\nconst ISO_DATE = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\r\nconst ISO_DATE_TIME = /^(\\d{4})-(\\d{2})-(\\d{2})[T ](\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:?\\d{2})?$/i;\r\n\r\nconst daysInMonth = (year: number, month: number): number =>\r\n new Date(year, month, 0).getDate();\r\n\r\nconst validParts = (year: number, month: number, day: number): boolean =>\r\n month >= 1 && month <= 12 && day >= 1 && day <= daysInMonth(year, month);\r\n\r\n/**\r\n * Converte para `Date`: `Date` válida, número (epoch em ms) ou string ISO.\r\n * Data sem hora (`2024-03-05`) é meia-noite LOCAL — `new Date()` a leria\r\n * como UTC e o dia \"andaria\" a oeste de Greenwich. Datas que transbordam\r\n * (`2024-02-30`) são inválidas, não 1º de março.\r\n */\r\nexport const toDate = (value: unknown): Date | undefined => {\r\n\r\n if (value instanceof Date) {\r\n return Number.isNaN(value.getTime()) ? undefined : value;\r\n }\r\n\r\n if (typeof value === 'number') {\r\n return Number.isFinite(value) ? new Date(value) : undefined;\r\n }\r\n\r\n if (typeof value !== 'string') {\r\n return undefined;\r\n }\r\n\r\n const text = value.trim();\r\n const dateOnly = ISO_DATE.exec(text);\r\n\r\n if (dateOnly) {\r\n const [year, month, day] = dateOnly.slice(1).map(Number);\r\n return validParts(year, month, day) ? new Date(year, month - 1, day) : undefined;\r\n }\r\n\r\n const dateTime = ISO_DATE_TIME.exec(text);\r\n\r\n if (!dateTime) {\r\n return undefined;\r\n }\r\n\r\n const [year, month, day, hour, minute, second = 0] = dateTime.slice(1).map(part => Number(part ?? 0));\r\n\r\n if (!validParts(year, month, day) || hour > 23 || minute > 59 || second > 59) {\r\n return undefined;\r\n }\r\n\r\n const date = new Date(text.replace(' ', 'T'));\r\n\r\n return Number.isNaN(date.getTime()) ? undefined : date;\r\n};\r\n\r\n/** Número de `number`/`bigint` ou de string numérica; senão `undefined`. */\r\nexport const toNumber = (value: unknown): number | bigint | undefined => {\r\n\r\n if (typeof value === 'bigint') {\r\n return value;\r\n }\r\n\r\n if (typeof value === 'number') {\r\n return Number.isNaN(value) ? undefined : value;\r\n }\r\n\r\n if (typeof value === 'string' && value.trim() !== '') {\r\n const numeric = Number(value);\r\n return Number.isNaN(numeric) ? undefined : numeric;\r\n }\r\n\r\n return undefined;\r\n};\r\n\r\n/** Valor no tipo da coluna (para comparar); o original quando não converte. */\r\nexport const coerceValue = (value: unknown, dataType: GridColumnDataType | null | undefined): unknown => {\r\n\r\n if (value === null || value === undefined || !dataType) {\r\n return value;\r\n }\r\n\r\n switch (dataType) {\r\n case 'number':\r\n return toNumber(value) ?? value;\r\n case 'date':\r\n case 'datetime':\r\n return toDate(value) ?? value;\r\n case 'boolean':\r\n return typeof value === 'boolean' ? value : value === 'true' ? true : value === 'false' ? false : value;\r\n case 'string':\r\n return toDisplayText(value);\r\n }\r\n};\r\n\r\n// ----------------------------------------------------------------- inferência\r\n\r\nconst typeOfValue = (value: unknown): GridColumnDataType | undefined => {\r\n switch (typeof value) {\r\n case 'number':\r\n case 'bigint':\r\n return 'number';\r\n case 'boolean':\r\n return 'boolean';\r\n case 'string':\r\n return 'string';\r\n default:\r\n return value instanceof Date ? 'date' : undefined;\r\n }\r\n};\r\n\r\n/**\r\n * `dataType` da coluna: o informado ou o tipo do 1º valor não nulo (como o\r\n * DevExtreme). String ISO não vira data por inferência — só com `dataType`.\r\n */\r\nexport const resolveDataType = (items: readonly unknown[], column: GridColumnDef): GridColumnDataType | undefined => {\r\n\r\n if (column.dataType) {\r\n return column.dataType;\r\n }\r\n\r\n if (!column.path && !column.valueGetter) {\r\n return undefined;\r\n }\r\n\r\n for (const item of items) {\r\n const value = getCellValue(item, column);\r\n\r\n if (value !== null && value !== undefined) {\r\n return typeOfValue(value);\r\n }\r\n }\r\n\r\n return undefined;\r\n};\r\n\r\nexport const resolveAlignment = (column: GridColumnDef, dataType: GridColumnDataType | undefined): GridColumnAlignment =>\r\n column.alignment\r\n ?? (dataType === 'number' ? 'end' : dataType === 'boolean' ? 'center' : 'start');\r\n\r\n// ---------------------------------------------------------------- formatadores\r\n\r\nconst DEFAULT_NUMBER: Intl.NumberFormatOptions = { useGrouping: false, maximumFractionDigits: 20 };\r\nexport const DEFAULT_DATE: Intl.DateTimeFormatOptions = { year: 'numeric', month: 'numeric', day: 'numeric' };\r\nexport const DEFAULT_DATETIME: Intl.DateTimeFormatOptions = { ...DEFAULT_DATE, hour: 'numeric', minute: '2-digit' };\r\n\r\n/**\r\n * Limite do cache de formatadores (spec 14): a chave inclui idioma e opções\r\n * do hospedeiro, então sem limite cresceria com cada combinação nova.\r\n */\r\nexport const FORMATTER_CACHE_LIMIT = 128;\r\n\r\nconst formatters = new LruCache<string, Intl.NumberFormat | Intl.DateTimeFormat>(FORMATTER_CACHE_LIMIT);\r\n\r\n/** Diagnóstico/testes de vazamento. */\r\nexport const _formatterCacheSize = (): number => formatters.size;\r\n\r\n/**\r\n * Formatador `Intl` em cache por (idioma, opções). Idioma ou opções\r\n * inválidos caem no padrão em vez de lançar no meio do render.\r\n */\r\nconst getFormatter = (\r\n kind: 'number' | 'date',\r\n language: string | undefined,\r\n options: object,\r\n fallback: object,\r\n): Intl.NumberFormat | Intl.DateTimeFormat => {\r\n\r\n const key = `${kind}|${language ?? ''}|${JSON.stringify(options)}`;\r\n let formatter = formatters.get(key);\r\n\r\n if (!formatter) {\r\n const create = (locale: string | undefined, opts: object) =>\r\n kind === 'number'\r\n ? new Intl.NumberFormat(locale, opts)\r\n : new Intl.DateTimeFormat(locale, opts);\r\n\r\n try {\r\n formatter = create(language, options);\r\n } catch {\r\n try {\r\n formatter = create(language, fallback);\r\n } catch {\r\n formatter = create(undefined, fallback);\r\n }\r\n }\r\n\r\n formatters.set(key, formatter);\r\n }\r\n\r\n return formatter;\r\n};\r\n\r\nexport const getNumberFormat = (language: string | undefined, options: Intl.NumberFormatOptions = DEFAULT_NUMBER): Intl.NumberFormat =>\r\n getFormatter('number', language, options, DEFAULT_NUMBER) as Intl.NumberFormat;\r\n\r\nexport const getDateTimeFormat = (\r\n language: string | undefined,\r\n options: Intl.DateTimeFormatOptions,\r\n fallback: Intl.DateTimeFormatOptions = DEFAULT_DATE,\r\n): Intl.DateTimeFormat =>\r\n getFormatter('date', language, options, fallback) as Intl.DateTimeFormat;\r\n\r\n// ------------------------------------------------------------------- exibição\r\n\r\nexport interface FormatContext {\r\n language: string | undefined;\r\n dataType: GridColumnDataType | undefined;\r\n trueText: string;\r\n falseText: string;\r\n}\r\n\r\nconst isBlank = (value: unknown): boolean =>\r\n value === null\r\n || value === undefined\r\n || (typeof value === 'number' && Number.isNaN(value))\r\n || (value instanceof Date && Number.isNaN(value.getTime()));\r\n\r\n/**\r\n * Texto exibido de um valor, na ordem: `displayValue` → vazio (`emptyText`)\r\n * → `format` função → `format` `Intl` / padrão do tipo. Valor que não\r\n * converte no tipo (string que não é data) sai como texto bruto.\r\n */\r\nexport const formatCellValue = (\r\n value: unknown,\r\n item: unknown,\r\n column: GridColumnDef,\r\n context: FormatContext,\r\n): string => {\r\n\r\n if (column.displayValue) {\r\n return toDisplayText(column.displayValue(value, item));\r\n }\r\n\r\n if (isBlank(value)) {\r\n return column.emptyText ?? '';\r\n }\r\n\r\n const { format } = column;\r\n\r\n if (typeof format === 'function') {\r\n return toDisplayText(format(value, item));\r\n }\r\n\r\n const { dataType } = context;\r\n\r\n if (dataType === 'number') {\r\n const numeric = toNumber(value);\r\n\r\n return numeric === undefined\r\n ? toDisplayText(value)\r\n : getNumberFormat(context.language, format ?? undefined).format(numeric);\r\n }\r\n\r\n if (dataType === 'date' || dataType === 'datetime') {\r\n const date = toDate(value);\r\n const fallback = dataType === 'date' ? DEFAULT_DATE : DEFAULT_DATETIME;\r\n\r\n return date\r\n ? getDateTimeFormat(context.language, format ?? fallback, fallback).format(date)\r\n : toDisplayText(value);\r\n }\r\n\r\n if (dataType === 'boolean' && typeof value === 'boolean') {\r\n return value ? context.trueText : context.falseText;\r\n }\r\n\r\n return toDisplayText(value);\r\n};\r\n\r\n/**\r\n * Valor a desenhar como ícone (coluna `boolean` com `booleanDisplay:\r\n * 'icon'`), ou `undefined` para exibir texto. `displayValue` e `format`\r\n * função continuam mandando no texto; vazio segue `emptyText`.\r\n */\r\nexport const booleanIconValue = (value: unknown, column: GridColumnDef, context: FormatContext): boolean | undefined => {\r\n\r\n if (column.booleanDisplay !== 'icon' || context.dataType !== 'boolean' || column.displayValue || typeof column.format === 'function') {\r\n return undefined;\r\n }\r\n\r\n const coerced = coerceValue(value, 'boolean');\r\n\r\n return typeof coerced === 'boolean' ? coerced : undefined;\r\n};\r\n\r\n/**\r\n * Caracteres (sem caixa/acento, por `fold`) que o texto formatado de um valor\r\n * do tipo da coluna pode ter: amostras do formatador cobrem dígitos,\r\n * separadores, sinais, símbolos, nomes de meses e AM/PM. `undefined` quando o\r\n * texto depende do item (`displayValue`, `format` função) ou é texto livre.\r\n * Usado pela busca para pular colunas de número/data em termos com letras.\r\n */\r\nexport const displayAlphabet = (\r\n column: GridColumnDef,\r\n context: FormatContext,\r\n fold: (text: string) => string,\r\n): Set<string> | undefined => {\r\n\r\n if (column.displayValue || typeof column.format === 'function') {\r\n return undefined;\r\n }\r\n\r\n const samples: string[] = [column.emptyText ?? ''];\r\n const { dataType, language } = context;\r\n\r\n if (dataType === 'number') {\r\n const formatter = getNumberFormat(language, column.format ?? undefined);\r\n\r\n for (const sample of [-1234567890.125, 0.5, 9.87e21, -0.000001234, 0]) {\r\n samples.push(formatter.format(sample));\r\n }\r\n } else if (dataType === 'date' || dataType === 'datetime') {\r\n const fallback = dataType === 'date' ? DEFAULT_DATE : DEFAULT_DATETIME;\r\n const formatter = getDateTimeFormat(language, column.format ?? fallback, fallback);\r\n\r\n for (let month = 0; month < 12; month++) {\r\n for (const day of [1, 10, 20, 28]) {\r\n for (const hour of [0, 13]) {\r\n samples.push(formatter.format(new Date(2024, month, day, hour, 5, 7)));\r\n samples.push(formatter.format(new Date(1999, month, day + 1, hour + 9, 48, 59)));\r\n }\r\n }\r\n }\r\n } else if (dataType === 'boolean') {\r\n samples.push(context.trueText, context.falseText);\r\n } else {\r\n return undefined;\r\n }\r\n\r\n return new Set(Array.from(fold(samples.join(''))));\r\n};\r\n\r\n/** Texto exibido da célula de `item` na coluna. */\r\nexport const formatCell = (item: unknown, column: GridColumnDef, context: FormatContext): string =>\r\n formatCellValue(getCellValue(item, column), item, column, context);\r\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { GridColumnDef, GridSortOrder } from '../grid-column-def.js';
|
|
2
|
+
import type { Comparer } from './compare.js';
|
|
3
|
+
import { type SummarySpec } from './summary.js';
|
|
4
|
+
import type { GroupNode } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Chave de expansão do grupo de valores `path` (um por nível), a mesma de
|
|
7
|
+
* `GroupNode.key`; `undefined` se o caminho for vazio ou mais fundo que o
|
|
8
|
+
* agrupamento.
|
|
9
|
+
*/
|
|
10
|
+
export declare const groupKeyOf: (path: readonly unknown[], groupColumns: readonly GridColumnDef[]) => string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Agrupa `items` pelas colunas de grupo, em todos os níveis. Não depende da
|
|
13
|
+
* ordem de entrada (usa mapa, não "valores consecutivos") e não muta nada.
|
|
14
|
+
* O valor é o de `getCellValue` (`valueGetter`/`path`); com `dataType`
|
|
15
|
+
* informado, valores equivalentes no tipo (`10` e `"10"` numa coluna
|
|
16
|
+
* `number`) caem no mesmo grupo. Grupos de cada nível em ordem do
|
|
17
|
+
* comparador da coluna (`compareFor`, ou o `comparator` dela), na direção
|
|
18
|
+
* de `orders[nível]` (padrão `asc`); itens na ordem de entrada — por isso o
|
|
19
|
+
* grid ordena os itens ANTES de agrupar.
|
|
20
|
+
*
|
|
21
|
+
* Com `groupValueGetter` o grupo é a faixa devolvida: identidade e ordem
|
|
22
|
+
* pelo próprio valor (o `compareFor` do grid já vem sem `dataType`), sem o
|
|
23
|
+
* `comparator` da coluna.
|
|
24
|
+
*
|
|
25
|
+
* Resumos de grupo (`summaries`) na mesma passada: no último nível cada item
|
|
26
|
+
* é acumulado no balde do seu valor cru enquanto é distribuído; valores
|
|
27
|
+
* equivalentes juntam os acumuladores, e os pais juntam os filhos.
|
|
28
|
+
*/
|
|
29
|
+
export declare const buildGroups: (items: readonly unknown[], groupColumns: readonly GridColumnDef[], compareFor: (column: GridColumnDef) => Comparer, orders?: readonly (GridSortOrder | undefined)[], summaries?: readonly SummarySpec[]) => GroupNode[];
|
|
30
|
+
//# sourceMappingURL=group.d.ts.map
|