@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,213 @@
|
|
|
1
|
+
import { coerceValue, DEFAULT_DATE, DEFAULT_DATETIME, getDateTimeFormat, getNumberFormat, toDate, toNumber } from './format.js';
|
|
2
|
+
import { cellValueReader, toDisplayText } from './value.js';
|
|
3
|
+
/** Solta os caches de uma passada (não seguram os textos dos itens). */
|
|
4
|
+
export const releaseSummaryCaches = (specs) => {
|
|
5
|
+
for (const spec of specs) {
|
|
6
|
+
spec.keys = undefined;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
export const createAccumulators = (specs) => specs.map(() => ({ rows: 0, count: 0, sum: 0, min: undefined, max: undefined, minKey: undefined, maxKey: undefined }));
|
|
10
|
+
const isEmpty = (value) => value === null
|
|
11
|
+
|| value === undefined
|
|
12
|
+
|| value === ''
|
|
13
|
+
|| (typeof value === 'number' && Number.isNaN(value))
|
|
14
|
+
|| (value instanceof Date && Number.isNaN(value.getTime()));
|
|
15
|
+
/** Ordem natural de `min`/`max` quando não há comparador: números, datas e textos. */
|
|
16
|
+
const naturalCompare = (a, b) => {
|
|
17
|
+
const left = a instanceof Date ? a.getTime() : a;
|
|
18
|
+
const right = b instanceof Date ? b.getTime() : b;
|
|
19
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Chave numérica de um valor cru para `min`/`max` no tipo da coluna, ou
|
|
23
|
+
* `undefined` quando só o comparador decide (texto, booleano); `NaN` =
|
|
24
|
+
* vazio/inválido.
|
|
25
|
+
*/
|
|
26
|
+
const numericKey = (spec, raw) => {
|
|
27
|
+
const { dataType } = spec;
|
|
28
|
+
if (dataType === 'string' || dataType === 'boolean') {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
if (typeof raw === 'number') {
|
|
32
|
+
return raw;
|
|
33
|
+
}
|
|
34
|
+
if (raw instanceof Date) {
|
|
35
|
+
return raw.getTime();
|
|
36
|
+
}
|
|
37
|
+
if (typeof raw !== 'string' || (dataType !== 'number' && dataType !== 'date' && dataType !== 'datetime')) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
spec.keys ??= new Map();
|
|
41
|
+
let key = spec.keys.get(raw);
|
|
42
|
+
if (key === undefined) {
|
|
43
|
+
const value = dataType === 'number' ? toNumber(raw) : toDate(raw)?.getTime();
|
|
44
|
+
key = value === undefined ? Number.NaN : Number(value);
|
|
45
|
+
spec.keys.set(raw, key);
|
|
46
|
+
}
|
|
47
|
+
return key;
|
|
48
|
+
};
|
|
49
|
+
/** `a` vem antes de `b`? Pelas chaves quando as duas existem; senão pelo comparador. */
|
|
50
|
+
const before = (spec, a, aKey, b, bKey) => aKey !== undefined && bKey !== undefined && !Number.isNaN(aKey) && !Number.isNaN(bKey)
|
|
51
|
+
? aKey < bKey
|
|
52
|
+
: (spec.compare ?? naturalCompare)(coerceValue(a, spec.dataType), coerceValue(b, spec.dataType)) < 0;
|
|
53
|
+
/** Soma `item` em cada acumulador (uma leitura de valor por resumo). */
|
|
54
|
+
export const accumulate = (accumulators, specs, item) => {
|
|
55
|
+
for (let i = 0; i < specs.length; i++) {
|
|
56
|
+
const spec = specs[i];
|
|
57
|
+
const acc = accumulators[i];
|
|
58
|
+
acc.rows++;
|
|
59
|
+
if (typeof spec.type === 'function' || spec.type === 'count' || !spec.column) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
spec.read ??= cellValueReader(spec.column);
|
|
63
|
+
const raw = spec.read(item);
|
|
64
|
+
if (spec.type === 'sum' || spec.type === 'avg') {
|
|
65
|
+
const amount = typeof raw === 'number' ? raw : Number(toNumber(raw));
|
|
66
|
+
if (Number.isFinite(amount)) {
|
|
67
|
+
acc.sum += amount;
|
|
68
|
+
acc.count++;
|
|
69
|
+
}
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (raw === null || raw === undefined || raw === '') {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
let key = numericKey(spec, raw);
|
|
76
|
+
if (key === undefined) {
|
|
77
|
+
// Só o comparador decide: confere se o valor é válido no tipo.
|
|
78
|
+
if (isEmpty(coerceValue(raw, spec.dataType))) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
key = Number.NaN;
|
|
82
|
+
}
|
|
83
|
+
else if (Number.isNaN(key)) {
|
|
84
|
+
// Número/data que não converte no tipo da coluna: fora de min/max.
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (spec.type === 'min') {
|
|
88
|
+
if (acc.min === undefined || before(spec, raw, key, acc.min, acc.minKey)) {
|
|
89
|
+
acc.min = raw;
|
|
90
|
+
acc.minKey = key;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (acc.max === undefined || before(spec, acc.max, acc.maxKey, raw, key)) {
|
|
94
|
+
acc.max = raw;
|
|
95
|
+
acc.maxKey = key;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
/** Junta `source` em `target` (grupo pai a partir dos filhos). */
|
|
100
|
+
export const mergeAccumulators = (target, source, specs) => {
|
|
101
|
+
for (let i = 0; i < specs.length; i++) {
|
|
102
|
+
const into = target[i];
|
|
103
|
+
const from = source[i];
|
|
104
|
+
const spec = specs[i];
|
|
105
|
+
into.rows += from.rows;
|
|
106
|
+
into.count += from.count;
|
|
107
|
+
into.sum += from.sum;
|
|
108
|
+
if (from.min !== undefined && (into.min === undefined || before(spec, from.min, from.minKey, into.min, into.minKey))) {
|
|
109
|
+
into.min = from.min;
|
|
110
|
+
into.minKey = from.minKey;
|
|
111
|
+
}
|
|
112
|
+
if (from.max !== undefined && (into.max === undefined || before(spec, into.max, into.maxKey, from.max, from.maxKey))) {
|
|
113
|
+
into.max = from.max;
|
|
114
|
+
into.maxKey = from.maxKey;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Valores finais. `items` é o conjunto do grupo (ou todos), usado só pelas
|
|
120
|
+
* funções próprias. Sem valores: `sum` = 0, `avg`/`min`/`max` = `null`.
|
|
121
|
+
*/
|
|
122
|
+
export const finishAccumulators = (accumulators, specs, items) => specs.map((spec, i) => {
|
|
123
|
+
const acc = accumulators[i];
|
|
124
|
+
if (typeof spec.type === 'function') {
|
|
125
|
+
const { column } = spec;
|
|
126
|
+
const read = column ? cellValueReader(column) : undefined;
|
|
127
|
+
const values = read ? items.map(read) : [];
|
|
128
|
+
// O agregador do hospedeiro não pode mudar os dados (cópia só se ainda não congelado).
|
|
129
|
+
return spec.type(Object.freeze(values), Object.isFrozen(items) ? items : Object.freeze([...items]));
|
|
130
|
+
}
|
|
131
|
+
switch (spec.type) {
|
|
132
|
+
case 'count':
|
|
133
|
+
return acc.rows;
|
|
134
|
+
case 'sum':
|
|
135
|
+
return acc.sum;
|
|
136
|
+
case 'avg':
|
|
137
|
+
return acc.count ? acc.sum / acc.count : null;
|
|
138
|
+
case 'min':
|
|
139
|
+
return acc.min === undefined ? null : coerceValue(acc.min, spec.dataType);
|
|
140
|
+
case 'max':
|
|
141
|
+
return acc.max === undefined ? null : coerceValue(acc.max, spec.dataType);
|
|
142
|
+
default:
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
/** Resumos de uma lista inteira (totais), numa passada. */
|
|
147
|
+
export const summarize = (items, specs) => {
|
|
148
|
+
if (!specs.length) {
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
const accumulators = createAccumulators(specs);
|
|
152
|
+
for (const item of items) {
|
|
153
|
+
accumulate(accumulators, specs, item);
|
|
154
|
+
}
|
|
155
|
+
releaseSummaryCaches(specs);
|
|
156
|
+
return finishAccumulators(accumulators, specs, items);
|
|
157
|
+
};
|
|
158
|
+
/** Número de resumo sem `format`: separador de milhar do idioma e até 2 casas (a média raramente é exata). */
|
|
159
|
+
const SUMMARY_NUMBER = { maximumFractionDigits: 2 };
|
|
160
|
+
/**
|
|
161
|
+
* `min`/`max` são valores de célula: sem `format`, saem como a célula (sem
|
|
162
|
+
* separador de milhar — um ano 2021 não vira "2,021"); os demais, como resumo.
|
|
163
|
+
*/
|
|
164
|
+
const defaultNumberFormat = (spec) => spec.type === 'min' || spec.type === 'max' ? undefined : SUMMARY_NUMBER;
|
|
165
|
+
/** Tipo de dado do VALOR do resumo (soma de datas não existe: é número). */
|
|
166
|
+
const resultTypeOf = (spec, value) => {
|
|
167
|
+
if (spec.type === 'count' || spec.type === 'sum' || spec.type === 'avg') {
|
|
168
|
+
return 'number';
|
|
169
|
+
}
|
|
170
|
+
if (spec.type === 'min' || spec.type === 'max') {
|
|
171
|
+
return spec.dataType;
|
|
172
|
+
}
|
|
173
|
+
if (typeof value === 'number' || typeof value === 'bigint') {
|
|
174
|
+
return 'number';
|
|
175
|
+
}
|
|
176
|
+
return value instanceof Date ? 'date' : undefined;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Texto do valor de um resumo: `format` do item → `format` `Intl` da coluna
|
|
180
|
+
* (não o de função: ele espera o valor de uma célula) → padrão do tipo.
|
|
181
|
+
* `count` só usa o `format` do próprio item.
|
|
182
|
+
*/
|
|
183
|
+
export const formatSummaryValue = (value, spec, itemFormat, context) => {
|
|
184
|
+
if (isEmpty(value)) {
|
|
185
|
+
return '';
|
|
186
|
+
}
|
|
187
|
+
const columnFormat = spec.type === 'count' || typeof spec.column?.format === 'function'
|
|
188
|
+
? undefined
|
|
189
|
+
: spec.column?.format;
|
|
190
|
+
const format = itemFormat ?? columnFormat;
|
|
191
|
+
if (typeof format === 'function') {
|
|
192
|
+
return toDisplayText(format(value));
|
|
193
|
+
}
|
|
194
|
+
const dataType = resultTypeOf(spec, value);
|
|
195
|
+
if (dataType === 'number') {
|
|
196
|
+
const numeric = toNumber(value);
|
|
197
|
+
return numeric === undefined
|
|
198
|
+
? toDisplayText(value)
|
|
199
|
+
: getNumberFormat(context.language, format ?? defaultNumberFormat(spec)).format(numeric);
|
|
200
|
+
}
|
|
201
|
+
if (dataType === 'date' || dataType === 'datetime') {
|
|
202
|
+
const date = toDate(value);
|
|
203
|
+
const fallback = dataType === 'date' ? DEFAULT_DATE : DEFAULT_DATETIME;
|
|
204
|
+
return date
|
|
205
|
+
? getDateTimeFormat(context.language, format ?? fallback, fallback).format(date)
|
|
206
|
+
: toDisplayText(value);
|
|
207
|
+
}
|
|
208
|
+
if (typeof value === 'boolean') {
|
|
209
|
+
return value ? context.trueText : context.falseText;
|
|
210
|
+
}
|
|
211
|
+
return toDisplayText(value);
|
|
212
|
+
};
|
|
213
|
+
//# sourceMappingURL=summary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summary.js","sourceRoot":"","sources":["../../src/row-model/summary.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAChI,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAsB5D,wEAAwE;AACxE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAA6B,EAAQ,EAAE;IAC1E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IACxB,CAAC;AACH,CAAC,CAAC;AAoBF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAA6B,EAAiB,EAAE,CACjF,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;AAEzH,MAAM,OAAO,GAAG,CAAC,KAAc,EAAW,EAAE,CAC1C,KAAK,KAAK,IAAI;OACX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E,MAAM,IAAI,QAAQ,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;YAChF,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;IACtD,CAAC;IAED,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC,CAAC","sourcesContent":["import type {\n GridColumnDataType,\n GridColumnDef,\n GridSummaryAggregator,\n GridSummaryFormat,\n GridSummaryType,\n} from '../grid-column-def.js';\nimport type { Comparer } from './compare.js';\nimport { coerceValue, DEFAULT_DATE, DEFAULT_DATETIME, getDateTimeFormat, getNumberFormat, toDate, toNumber } from './format.js';\nimport { cellValueReader, toDisplayText } from './value.js';\n\n/**\n * Resumo pronto para calcular: coluna já resolvida (`undefined` quando a\n * referência não achou coluna — só `count` e função fazem sentido), tipo de\n * dado efetivo e comparador (para `min`/`max`).\n */\nexport interface SummarySpec {\n column: GridColumnDef | undefined;\n type: GridSummaryType | GridSummaryAggregator;\n dataType?: GridColumnDataType;\n compare?: Comparer;\n /** Leitor do valor da coluna, criado no 1º uso (spec 16: `path` quebrado uma vez). */\n read?: (item: unknown) => unknown;\n /**\n * Chave numérica de `min`/`max` por texto cru (data ISO, número em texto):\n * converte cada valor distinto uma vez. Só durante uma passada\n * ({@link releaseSummaryCaches} solta no fim).\n */\n keys?: Map<string, number>;\n}\n\n/** Solta os caches de uma passada (não seguram os textos dos itens). */\nexport const releaseSummaryCaches = (specs: readonly SummarySpec[]): void => {\n for (const spec of specs) {\n spec.keys = undefined;\n }\n};\n\n/** Estado parcial de UM resumo; combinável entre grupos irmãos (sum/min/max/avg/count). */\nexport interface Accumulator {\n /** Linhas vistas (`count`). */\n rows: number;\n /** Valores numéricos somados (`sum`/`avg`). */\n count: number;\n sum: number;\n /** Menor/maior valor não vazio, cru (convertido no fim). */\n min: unknown;\n max: unknown;\n /**\n * Chave numérica de `min`/`max` (número, tempo da data) para comparar sem\n * converter de novo; `NaN` = comparar pelo comparador (texto, booleano).\n */\n minKey: number | undefined;\n maxKey: number | undefined;\n}\n\nexport const createAccumulators = (specs: readonly SummarySpec[]): Accumulator[] =>\n specs.map(() => ({ rows: 0, count: 0, sum: 0, min: undefined, max: undefined, minKey: undefined, maxKey: undefined }));\n\nconst isEmpty = (value: unknown): boolean =>\n value === null\n || value === undefined\n || value === ''\n || (typeof value === 'number' && Number.isNaN(value))\n || (value instanceof Date && Number.isNaN(value.getTime()));\n\n/** Ordem natural de `min`/`max` quando não há comparador: números, datas e textos. */\nconst naturalCompare: Comparer = (a, b) => {\n const left = a instanceof Date ? a.getTime() : a as number;\n const right = b instanceof Date ? b.getTime() : b as number;\n\n return left < right ? -1 : left > right ? 1 : 0;\n};\n\n/**\n * Chave numérica de um valor cru para `min`/`max` no tipo da coluna, ou\n * `undefined` quando só o comparador decide (texto, booleano); `NaN` =\n * vazio/inválido.\n */\nconst numericKey = (spec: SummarySpec, raw: unknown): number | undefined => {\n const { dataType } = spec;\n\n if (dataType === 'string' || dataType === 'boolean') {\n return undefined;\n }\n\n if (typeof raw === 'number') {\n return raw;\n }\n\n if (raw instanceof Date) {\n return raw.getTime();\n }\n\n if (typeof raw !== 'string' || (dataType !== 'number' && dataType !== 'date' && dataType !== 'datetime')) {\n return undefined;\n }\n\n spec.keys ??= new Map();\n let key = spec.keys.get(raw);\n\n if (key === undefined) {\n const value = dataType === 'number' ? toNumber(raw) : toDate(raw)?.getTime();\n key = value === undefined ? Number.NaN : Number(value);\n spec.keys.set(raw, key);\n }\n\n return key;\n};\n\n/** `a` vem antes de `b`? Pelas chaves quando as duas existem; senão pelo comparador. */\nconst before = (spec: SummarySpec, a: unknown, aKey: number | undefined, b: unknown, bKey: number | undefined): boolean =>\n aKey !== undefined && bKey !== undefined && !Number.isNaN(aKey) && !Number.isNaN(bKey)\n ? aKey < bKey\n : (spec.compare ?? naturalCompare)(coerceValue(a, spec.dataType), coerceValue(b, spec.dataType)) < 0;\n\n/** Soma `item` em cada acumulador (uma leitura de valor por resumo). */\nexport const accumulate = (accumulators: Accumulator[], specs: readonly SummarySpec[], item: unknown): void => {\n for (let i = 0; i < specs.length; i++) {\n const spec = specs[i];\n const acc = accumulators[i];\n acc.rows++;\n\n if (typeof spec.type === 'function' || spec.type === 'count' || !spec.column) {\n continue;\n }\n\n spec.read ??= cellValueReader(spec.column);\n const raw = spec.read(item);\n\n if (spec.type === 'sum' || spec.type === 'avg') {\n const amount = typeof raw === 'number' ? raw : Number(toNumber(raw));\n\n if (Number.isFinite(amount)) {\n acc.sum += amount;\n acc.count++;\n }\n\n continue;\n }\n\n if (raw === null || raw === undefined || raw === '') {\n continue;\n }\n\n let key = numericKey(spec, raw);\n\n if (key === undefined) {\n // Só o comparador decide: confere se o valor é válido no tipo.\n if (isEmpty(coerceValue(raw, spec.dataType))) {\n continue;\n }\n\n key = Number.NaN;\n } else if (Number.isNaN(key)) {\n // Número/data que não converte no tipo da coluna: fora de min/max.\n continue;\n }\n\n if (spec.type === 'min') {\n if (acc.min === undefined || before(spec, raw, key, acc.min, acc.minKey)) {\n acc.min = raw;\n acc.minKey = key;\n }\n } else if (acc.max === undefined || before(spec, acc.max, acc.maxKey, raw, key)) {\n acc.max = raw;\n acc.maxKey = key;\n }\n }\n};\n\n/** Junta `source` em `target` (grupo pai a partir dos filhos). */\nexport const mergeAccumulators = (target: Accumulator[], source: readonly Accumulator[], specs: readonly SummarySpec[]): void => {\n for (let i = 0; i < specs.length; i++) {\n const into = target[i];\n const from = source[i];\n const spec = specs[i];\n\n into.rows += from.rows;\n into.count += from.count;\n into.sum += from.sum;\n\n if (from.min !== undefined && (into.min === undefined || before(spec, from.min, from.minKey, into.min, into.minKey))) {\n into.min = from.min;\n into.minKey = from.minKey;\n }\n\n if (from.max !== undefined && (into.max === undefined || before(spec, into.max, into.maxKey, from.max, from.maxKey))) {\n into.max = from.max;\n into.maxKey = from.maxKey;\n }\n }\n};\n\n/**\n * Valores finais. `items` é o conjunto do grupo (ou todos), usado só pelas\n * funções próprias. Sem valores: `sum` = 0, `avg`/`min`/`max` = `null`.\n */\nexport const finishAccumulators = (\n accumulators: readonly Accumulator[],\n specs: readonly SummarySpec[],\n items: readonly unknown[],\n): unknown[] =>\n specs.map((spec, i) => {\n const acc = accumulators[i];\n\n if (typeof spec.type === 'function') {\n const { column } = spec;\n const read = column ? cellValueReader(column) : undefined;\n const values = read ? items.map(read) : [];\n\n // O agregador do hospedeiro não pode mudar os dados (cópia só se ainda não congelado).\n return spec.type(Object.freeze(values), Object.isFrozen(items) ? items : Object.freeze([...items]));\n }\n\n switch (spec.type) {\n case 'count':\n return acc.rows;\n case 'sum':\n return acc.sum;\n case 'avg':\n return acc.count ? acc.sum / acc.count : null;\n case 'min':\n return acc.min === undefined ? null : coerceValue(acc.min, spec.dataType);\n case 'max':\n return acc.max === undefined ? null : coerceValue(acc.max, spec.dataType);\n default:\n return null;\n }\n });\n\n/** Resumos de uma lista inteira (totais), numa passada. */\nexport const summarize = (items: readonly unknown[], specs: readonly SummarySpec[]): unknown[] => {\n if (!specs.length) {\n return [];\n }\n\n const accumulators = createAccumulators(specs);\n\n for (const item of items) {\n accumulate(accumulators, specs, item);\n }\n\n releaseSummaryCaches(specs);\n return finishAccumulators(accumulators, specs, items);\n};\n\n// ------------------------------------------------------------------ exibição\n\nexport interface SummaryFormatContext {\n language: string | undefined;\n trueText: string;\n falseText: string;\n}\n\n/** Número de resumo sem `format`: separador de milhar do idioma e até 2 casas (a média raramente é exata). */\nconst SUMMARY_NUMBER: Intl.NumberFormatOptions = { maximumFractionDigits: 2 };\n\n/**\n * `min`/`max` são valores de célula: sem `format`, saem como a célula (sem\n * separador de milhar — um ano 2021 não vira \"2,021\"); os demais, como resumo.\n */\nconst defaultNumberFormat = (spec: SummarySpec): Intl.NumberFormatOptions | undefined =>\n spec.type === 'min' || spec.type === 'max' ? undefined : SUMMARY_NUMBER;\n\n/** Tipo de dado do VALOR do resumo (soma de datas não existe: é número). */\nconst resultTypeOf = (spec: SummarySpec, value: unknown): GridColumnDataType | undefined => {\n if (spec.type === 'count' || spec.type === 'sum' || spec.type === 'avg') {\n return 'number';\n }\n\n if (spec.type === 'min' || spec.type === 'max') {\n return spec.dataType;\n }\n\n if (typeof value === 'number' || typeof value === 'bigint') {\n return 'number';\n }\n\n return value instanceof Date ? 'date' : undefined;\n};\n\n/**\n * Texto do valor de um resumo: `format` do item → `format` `Intl` da coluna\n * (não o de função: ele espera o valor de uma célula) → padrão do tipo.\n * `count` só usa o `format` do próprio item.\n */\nexport const formatSummaryValue = (\n value: unknown,\n spec: SummarySpec,\n itemFormat: GridSummaryFormat | null | undefined,\n context: SummaryFormatContext,\n): string => {\n\n if (isEmpty(value)) {\n return '';\n }\n\n const columnFormat = spec.type === 'count' || typeof spec.column?.format === 'function'\n ? undefined\n : spec.column?.format as Intl.NumberFormatOptions | Intl.DateTimeFormatOptions | undefined;\n const format = itemFormat ?? columnFormat;\n\n if (typeof format === 'function') {\n return toDisplayText(format(value));\n }\n\n const dataType = resultTypeOf(spec, value);\n\n if (dataType === 'number') {\n const numeric = toNumber(value);\n\n return numeric === undefined\n ? toDisplayText(value)\n : getNumberFormat(context.language, format ?? defaultNumberFormat(spec)).format(numeric);\n }\n\n if (dataType === 'date' || dataType === 'datetime') {\n const date = toDate(value);\n const fallback = dataType === 'date' ? DEFAULT_DATE : DEFAULT_DATETIME;\n\n return date\n ? getDateTimeFormat(context.language, format ?? fallback, fallback).format(date)\n : toDisplayText(value);\n }\n\n if (typeof value === 'boolean') {\n return value ? context.trueText : context.falseText;\n }\n\n return toDisplayText(value);\n};\n"]}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type BlockDetails, RowList, type RowKeyOf } from './flatten.js';
|
|
2
|
+
/**
|
|
3
|
+
* Dados em árvore (frente 25): funções puras, sem DOM. Nada por nó além de
|
|
4
|
+
* arrays tipados (`Int32Array`) e, quando precisa, do mapa chave → índice:
|
|
5
|
+
* nenhum objeto por nó (spec 16). O row model guarda a árvore como
|
|
6
|
+
* "compressed sparse rows": `childStart[p]..childStart[p + 1]` em
|
|
7
|
+
* `children` são os filhos (visíveis, na ordem) do nó `p`; o nó virtual
|
|
8
|
+
* `n` é a raiz.
|
|
9
|
+
*/
|
|
10
|
+
/** Chave → índice do nó (1ª ocorrência). */
|
|
11
|
+
export interface KeyLookup {
|
|
12
|
+
get(key: unknown): number | undefined;
|
|
13
|
+
has(key: unknown): boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Índice estrutural: muda só com `items` ou com as expressões. */
|
|
16
|
+
export interface TreeIndex {
|
|
17
|
+
/** Todos os nós. Plana: o próprio `items`; aninhada: pré-ordem. */
|
|
18
|
+
readonly nodes: readonly unknown[];
|
|
19
|
+
/** Índice do pai (`-1` = raiz). */
|
|
20
|
+
readonly parent: Int32Array;
|
|
21
|
+
/** Profundidade estrutural (0 = raiz). */
|
|
22
|
+
readonly level: Int32Array;
|
|
23
|
+
/** Ordem em que todo pai vem antes dos filhos (`null` = a própria ordem de `nodes`). */
|
|
24
|
+
readonly topo: Int32Array | null;
|
|
25
|
+
/** Chave → índice (1ª ocorrência). */
|
|
26
|
+
readonly keyIndex: KeyLookup;
|
|
27
|
+
/** Nós com pai inexistente (viraram raiz). */
|
|
28
|
+
readonly orphans: number;
|
|
29
|
+
/** Nós que fechavam um ciclo (viraram raiz) ou repetidos na entrada aninhada (ignorados). */
|
|
30
|
+
readonly cycles: number;
|
|
31
|
+
/** Chaves repetidas (a 1ª ocorrência vale no mapa). */
|
|
32
|
+
readonly duplicates: number;
|
|
33
|
+
}
|
|
34
|
+
export type TreeKeyOf = (item: unknown) => unknown;
|
|
35
|
+
export type ChildrenOf = (item: unknown) => readonly unknown[] | null | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Entrada plana: cada item diz a chave do pai. `rootValue`, `null`,
|
|
38
|
+
* `undefined` ou pai inexistente = raiz. Um ciclo é cortado no nó em que a
|
|
39
|
+
* subida volta (ele vira raiz).
|
|
40
|
+
*/
|
|
41
|
+
export declare const buildFlatIndex: (items: readonly unknown[], keyOf: TreeKeyOf, parentOf: TreeKeyOf, rootValue: unknown) => TreeIndex;
|
|
42
|
+
/**
|
|
43
|
+
* Entrada aninhada: `roots` e os filhos de cada item por `childrenOf`. Os
|
|
44
|
+
* nós saem em pré-ordem (pai antes dos filhos). Sem `keyOf`, a chave é o
|
|
45
|
+
* próprio item; um item que aparece de novo (ciclo ou repetido) é
|
|
46
|
+
* ignorado.
|
|
47
|
+
*/
|
|
48
|
+
export declare const buildNestedIndex: (roots: readonly unknown[], childrenOf: ChildrenOf, keyOf?: TreeKeyOf) => TreeIndex;
|
|
49
|
+
/** Lê os filhos por caminho (`a.b`) ou função; não-array = sem filhos. */
|
|
50
|
+
export declare const childrenReader: (expr: string | ((item: any) => readonly unknown[] | null | undefined)) => ChildrenOf;
|
|
51
|
+
/** O que o filtro mostra (`treeFilterMode`). */
|
|
52
|
+
export type TreeFilterMode = 'with-ancestors' | 'full-branch' | 'match-only';
|
|
53
|
+
/** Visão da árvore depois de filtrar e ordenar. */
|
|
54
|
+
export interface TreeView {
|
|
55
|
+
/** Nós visíveis (`null` = todos). */
|
|
56
|
+
readonly visible: Uint8Array | null;
|
|
57
|
+
/** Quantos nós visíveis. */
|
|
58
|
+
readonly count: number;
|
|
59
|
+
/** Início dos filhos de cada nó em `children` (`n` = raiz virtual; tamanho n + 2). */
|
|
60
|
+
readonly childStart: Int32Array;
|
|
61
|
+
/** Filhos visíveis, agrupados por pai, na ordem da ordenação. */
|
|
62
|
+
readonly children: Int32Array;
|
|
63
|
+
/** Pai efetivo (`match-only`: o ancestral visível mais próximo); `-1` = raiz. */
|
|
64
|
+
readonly parent: Int32Array;
|
|
65
|
+
/** Profundidade efetiva (0 = raiz). */
|
|
66
|
+
readonly level: Int32Array;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Nós visíveis pelo filtro (`match[i]` = o nó passa; `null` = sem filtro)
|
|
70
|
+
* conforme o modo: `with-ancestors` acrescenta os ancestrais dos que
|
|
71
|
+
* passam; `full-branch`, também os descendentes; `match-only`, só os que
|
|
72
|
+
* passam (pendurados no ancestral visível mais próximo).
|
|
73
|
+
*/
|
|
74
|
+
export declare const treeVisibility: (index: TreeIndex, match: Uint8Array | null, mode: TreeFilterMode) => Uint8Array | null;
|
|
75
|
+
/**
|
|
76
|
+
* Monta a visão: filhos visíveis de cada nó, na ordem `order` (índices de
|
|
77
|
+
* `nodes` ordenados; `null` = a ordem de `nodes`, que na aninhada é a dos
|
|
78
|
+
* filhos e na plana a de `items`). Uma passada para contar, outra para
|
|
79
|
+
* preencher: O(n).
|
|
80
|
+
*/
|
|
81
|
+
export declare const buildTreeView: (index: TreeIndex, visible: Uint8Array | null, order: Int32Array | null, mode: TreeFilterMode) => TreeView;
|
|
82
|
+
/** Quantos filhos visíveis o nó tem. */
|
|
83
|
+
export declare const childCount: (view: TreeView, node: number) => number;
|
|
84
|
+
/**
|
|
85
|
+
* Ancestrais (estruturais) dos nós que passam no filtro — os que expandem
|
|
86
|
+
* quando o filtro muda (como `expandNodesOnFiltering` do DevExtreme).
|
|
87
|
+
*/
|
|
88
|
+
export declare const ancestorsOfMatches: (index: TreeIndex, match: Uint8Array) => Uint8Array;
|
|
89
|
+
/**
|
|
90
|
+
* Linhas visíveis da árvore: em pré-ordem, descendo nos nós expandidos.
|
|
91
|
+
* Cada trecho de irmãos entre dois nós expandidos é um segmento da
|
|
92
|
+
* `RowList` (nada por linha). `expanded(node)` só é perguntado para nós
|
|
93
|
+
* com filhos; `extra(node)` acrescenta linhas avulsas depois dos filhos de
|
|
94
|
+
* um nó expandido (rodapé de resumo, esqueleto de carga).
|
|
95
|
+
*/
|
|
96
|
+
export declare const flattenTree: (index: TreeIndex, view: TreeView, expanded: (node: number) => boolean, keyOf: RowKeyOf, hasChildren?: (node: number) => boolean, after?: (node: number, rows: RowList) => void, detailsOf?: (children: Int32Array, from: number, to: number) => BlockDetails | undefined) => RowList;
|
|
97
|
+
/** Estrutura sem filtro (todos os filhos, na ordem de `nodes`), para a seleção recursiva. */
|
|
98
|
+
export declare const structuralView: (index: TreeIndex) => TreeView;
|
|
99
|
+
/**
|
|
100
|
+
* Seleção recursiva: marcar um nó marca todos os descendentes e cada
|
|
101
|
+
* ancestral cujos filhos ficaram todos marcados; desmarcar desmarca os
|
|
102
|
+
* descendentes e todos os ancestrais. Devolve os nós que mudam (sem
|
|
103
|
+
* repetir), O(subárvore + profundidade).
|
|
104
|
+
*/
|
|
105
|
+
export declare const recursiveSelectionChange: (index: TreeIndex, structure: TreeView, node: number, select: boolean, isSelected: (node: number) => boolean) => number[];
|
|
106
|
+
/**
|
|
107
|
+
* Nós com algum descendente marcado (caixa mista quando o próprio nó não
|
|
108
|
+
* está marcado). Uma passada de baixo para cima: O(n).
|
|
109
|
+
*/
|
|
110
|
+
export declare const partialSelection: (index: TreeIndex, isSelected: (node: number) => boolean) => Uint8Array;
|
|
111
|
+
/**
|
|
112
|
+
* Descendentes visíveis de `node` (sem ele), em pré-ordem — base dos
|
|
113
|
+
* resumos por nó. Calculado sob demanda para os nós que aparecem: O(subárvore).
|
|
114
|
+
*/
|
|
115
|
+
export declare const visibleDescendants: (index: TreeIndex, view: TreeView, node: number) => unknown[];
|
|
116
|
+
//# sourceMappingURL=tree.d.ts.map
|