@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,53 @@
|
|
|
1
|
+
import type { ComplexAttributeConverter } from 'lit';
|
|
2
|
+
import type { GridExportFormat } from './export/types.js';
|
|
3
|
+
import type { GridFilterOperation } from './grid-column-def.js';
|
|
4
|
+
/**
|
|
5
|
+
* Booleano de atributo que também desliga (spec 15): sem atributo = padrão;
|
|
6
|
+
* `"false"` = `false`; qualquer outro valor (inclusive vazio) = `true`.
|
|
7
|
+
* Necessário para os booleanos com padrão `true`, que um atributo de
|
|
8
|
+
* presença não conseguiria desligar.
|
|
9
|
+
*/
|
|
10
|
+
export declare const booleanAttribute: (defaultValue: boolean) => ComplexAttributeConverter<boolean>;
|
|
11
|
+
/** Tri-estado: sem atributo = `null` (padrão calculado); `"false"` desliga; outro valor liga. */
|
|
12
|
+
export declare const optionalBooleanAttribute: ComplexAttributeConverter<boolean | null>;
|
|
13
|
+
/**
|
|
14
|
+
* Número opcional (`hiding-priority`): sem atributo, vazio ou não numérico =
|
|
15
|
+
* `null` (o `type: Number` do Lit daria `0` para vazio e `NaN` para texto).
|
|
16
|
+
*/
|
|
17
|
+
export declare const optionalNumberAttribute: ComplexAttributeConverter<number | null>;
|
|
18
|
+
/**
|
|
19
|
+
* Atributos renomeados (antigo → novo). O elemento observa os antigos e os
|
|
20
|
+
* repassa ao novo com aviso de deprecação uma vez por instância.
|
|
21
|
+
*/
|
|
22
|
+
export type LegacyAttributes = Readonly<Record<string, string>>;
|
|
23
|
+
/** Uma operação (`default-filter-operation`); desconhecida avisa e vira `null`. */
|
|
24
|
+
export declare const filterOperationAttribute: {
|
|
25
|
+
fromAttribute: (value: string | null) => GridFilterOperation | null;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Lista de operações separada por espaço (`filter-operations="contains ="`),
|
|
29
|
+
* à moda de `DOMTokenList`. Só lê (não reflete); token desconhecido é
|
|
30
|
+
* ignorado com aviso.
|
|
31
|
+
*/
|
|
32
|
+
export declare const filterOperationsAttribute: {
|
|
33
|
+
fromAttribute: (value: string | null) => GridFilterOperation[] | null;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Lista de números separada por vírgula ou espaço (`page-size-options="10, 20, 50"`).
|
|
37
|
+
* Só lê (não reflete); valores que não são inteiros positivos são ignorados;
|
|
38
|
+
* sem atributo = `defaultValue` (vazio = lista vazia). Exceção registrada à
|
|
39
|
+
* regra "array = `attribute: false`" (spec 15, frente 08).
|
|
40
|
+
*/
|
|
41
|
+
export declare const numberListAttribute: (defaultValue: readonly number[]) => {
|
|
42
|
+
fromAttribute: (value: string | null) => readonly number[];
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Formatos da exportação pela interface (`export-formats="csv xlsx pdf"`, frentes
|
|
46
|
+
* 18 e 26): palavras separadas por espaço ou vírgula; desconhecida avisa e é
|
|
47
|
+
* ignorada; repetidas contam uma vez. Só lê (não reflete); sem atributo =
|
|
48
|
+
* lista vazia. Exceção registrada à regra "array = `attribute: false`".
|
|
49
|
+
*/
|
|
50
|
+
export declare const exportFormatsAttribute: {
|
|
51
|
+
fromAttribute: (value: string | null) => readonly GridExportFormat[];
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=attribute-converters.d.ts.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Booleano de atributo que também desliga (spec 15): sem atributo = padrão;
|
|
3
|
+
* `"false"` = `false`; qualquer outro valor (inclusive vazio) = `true`.
|
|
4
|
+
* Necessário para os booleanos com padrão `true`, que um atributo de
|
|
5
|
+
* presença não conseguiria desligar.
|
|
6
|
+
*/
|
|
7
|
+
export const booleanAttribute = (defaultValue) => ({
|
|
8
|
+
fromAttribute: (value) => value === null ? defaultValue : value !== 'false',
|
|
9
|
+
toAttribute: (value) => value ? '' : null,
|
|
10
|
+
});
|
|
11
|
+
/** Tri-estado: sem atributo = `null` (padrão calculado); `"false"` desliga; outro valor liga. */
|
|
12
|
+
export const optionalBooleanAttribute = {
|
|
13
|
+
fromAttribute: (value) => value === null ? null : value !== 'false',
|
|
14
|
+
toAttribute: (value) => value === null ? null : String(value),
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Número opcional (`hiding-priority`): sem atributo, vazio ou não numérico =
|
|
18
|
+
* `null` (o `type: Number` do Lit daria `0` para vazio e `NaN` para texto).
|
|
19
|
+
*/
|
|
20
|
+
export const optionalNumberAttribute = {
|
|
21
|
+
fromAttribute: (value) => {
|
|
22
|
+
if (value === null || value.trim() === '') {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const parsed = Number(value);
|
|
26
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
27
|
+
},
|
|
28
|
+
toAttribute: (value) => value === null || value === undefined ? null : String(value),
|
|
29
|
+
};
|
|
30
|
+
const FILTER_OPERATION_TOKENS = new Set('= <> < <= > >= contains notcontains startswith endswith between anyof noneof isblank isnotblank'.split(' '));
|
|
31
|
+
/** Uma operação (`default-filter-operation`); desconhecida avisa e vira `null`. */
|
|
32
|
+
export const filterOperationAttribute = {
|
|
33
|
+
fromAttribute: (value) => {
|
|
34
|
+
if (value === null) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
if (!FILTER_OPERATION_TOKENS.has(value)) {
|
|
38
|
+
console.warn(`<u-grid-column>: unknown filter operation ignored: ${value}.`);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Lista de operações separada por espaço (`filter-operations="contains ="`),
|
|
46
|
+
* à moda de `DOMTokenList`. Só lê (não reflete); token desconhecido é
|
|
47
|
+
* ignorado com aviso.
|
|
48
|
+
*/
|
|
49
|
+
export const filterOperationsAttribute = {
|
|
50
|
+
fromAttribute: (value) => {
|
|
51
|
+
if (value === null) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const tokens = value.split(/\s+/).filter(Boolean);
|
|
55
|
+
const unknown = tokens.filter(token => !FILTER_OPERATION_TOKENS.has(token));
|
|
56
|
+
if (unknown.length) {
|
|
57
|
+
console.warn(`<u-grid-column>: unknown filter operation(s) ignored: ${unknown.join(', ')}.`);
|
|
58
|
+
}
|
|
59
|
+
return tokens.filter(token => FILTER_OPERATION_TOKENS.has(token));
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Lista de números separada por vírgula ou espaço (`page-size-options="10, 20, 50"`).
|
|
64
|
+
* Só lê (não reflete); valores que não são inteiros positivos são ignorados;
|
|
65
|
+
* sem atributo = `defaultValue` (vazio = lista vazia). Exceção registrada à
|
|
66
|
+
* regra "array = `attribute: false`" (spec 15, frente 08).
|
|
67
|
+
*/
|
|
68
|
+
export const numberListAttribute = (defaultValue) => ({
|
|
69
|
+
fromAttribute: (value) => {
|
|
70
|
+
if (value === null) {
|
|
71
|
+
return defaultValue;
|
|
72
|
+
}
|
|
73
|
+
return value.split(/[\s,]+/).filter(Boolean)
|
|
74
|
+
.map(Number)
|
|
75
|
+
.filter(size => Number.isInteger(size) && size > 0);
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
const EXPORT_FORMAT_TOKENS = new Set(['csv', 'xlsx', 'pdf']);
|
|
79
|
+
/**
|
|
80
|
+
* Formatos da exportação pela interface (`export-formats="csv xlsx pdf"`, frentes
|
|
81
|
+
* 18 e 26): palavras separadas por espaço ou vírgula; desconhecida avisa e é
|
|
82
|
+
* ignorada; repetidas contam uma vez. Só lê (não reflete); sem atributo =
|
|
83
|
+
* lista vazia. Exceção registrada à regra "array = `attribute: false`".
|
|
84
|
+
*/
|
|
85
|
+
export const exportFormatsAttribute = {
|
|
86
|
+
fromAttribute: (value) => {
|
|
87
|
+
if (value === null) {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
const tokens = value.split(/[\s,]+/).filter(Boolean);
|
|
91
|
+
const unknown = tokens.filter(token => !EXPORT_FORMAT_TOKENS.has(token));
|
|
92
|
+
if (unknown.length) {
|
|
93
|
+
console.warn(`<u-grid>: unknown export format(s) ignored: ${unknown.join(', ')}.`);
|
|
94
|
+
}
|
|
95
|
+
return [...new Set(tokens.filter(token => EXPORT_FORMAT_TOKENS.has(token)))];
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=attribute-converters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribute-converters.js","sourceRoot":"","sources":["../src/attribute-converters.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,YAAqB,EAAsC,EAAE,CAAC,CAAC;IAC9F,aAAa,EAAE,CAAC,KAAoB,EAAW,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,KAAK,OAAO;IACnG,WAAW,EAAE,CAAC,KAAc,EAAiB,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI;CAClE,CAAC,CAAC;AAEH,iGAAiG;AACjG,MAAM,CAAC,MAAM,wBAAwB,GAA8C;IACjF,aAAa,EAAE,CAAC,KAAoB,EAAkB,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK,OAAO;IAClG,WAAW,EAAE,CAAC,KAAqB,EAAiB,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;CAC7F,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAA6C;IAC/E,aAAa,EAAE,CAAC,KAAoB,EAAiB,EAAE;QACrD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,C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C,MAAM,EAAE,CAAC;YACnB,OAAO,CAAC,IAAI,CAAC,+CAA+C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrF,CAAC;QAED,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAuB,CAAC;IACrG,CAAC;CACF,CAAC","sourcesContent":["import type { ComplexAttributeConverter } from 'lit';\n\nimport type { GridExportFormat } from './export/types.js';\nimport type { GridFilterOperation } from './grid-column-def.js';\n\n/**\n * Booleano de atributo que também desliga (spec 15): sem atributo = padrão;\n * `\"false\"` = `false`; qualquer outro valor (inclusive vazio) = `true`.\n * Necessário para os booleanos com padrão `true`, que um atributo de\n * presença não conseguiria desligar.\n */\nexport const booleanAttribute = (defaultValue: boolean): ComplexAttributeConverter<boolean> => ({\n fromAttribute: (value: string | null): boolean => value === null ? defaultValue : value !== 'false',\n toAttribute: (value: boolean): string | null => value ? '' : null,\n});\n\n/** Tri-estado: sem atributo = `null` (padrão calculado); `\"false\"` desliga; outro valor liga. */\nexport const optionalBooleanAttribute: ComplexAttributeConverter<boolean | null> = {\n fromAttribute: (value: string | null): boolean | null => value === null ? null : value !== 'false',\n toAttribute: (value: boolean | null): string | null => value === null ? null : String(value),\n};\n\n/**\n * Número opcional (`hiding-priority`): sem atributo, vazio ou não numérico =\n * `null` (o `type: Number` do Lit daria `0` para vazio e `NaN` para texto).\n */\nexport const optionalNumberAttribute: ComplexAttributeConverter<number | null> = {\n fromAttribute: (value: string | null): number | null => {\n if (value === null || value.trim() === '') {\n return null;\n }\n\n const parsed = Number(value);\n return Number.isFinite(parsed) ? parsed : null;\n },\n toAttribute: (value: number | null): string | null => value === null || value === undefined ? null : String(value),\n};\n\n/**\n * Atributos renomeados (antigo → novo). O elemento observa os antigos e os\n * repassa ao novo com aviso de deprecação uma vez por instância.\n */\nexport type LegacyAttributes = Readonly<Record<string, string>>;\n\nconst FILTER_OPERATION_TOKENS = new Set(\n '= <> < <= > >= contains notcontains startswith endswith between anyof noneof isblank isnotblank'.split(' '),\n);\n\n/** Uma operação (`default-filter-operation`); desconhecida avisa e vira `null`. */\nexport const filterOperationAttribute = {\n fromAttribute: (value: string | null): GridFilterOperation | null => {\n if (value === null) {\n return null;\n }\n\n if (!FILTER_OPERATION_TOKENS.has(value)) {\n console.warn(`<u-grid-column>: unknown filter operation ignored: ${value}.`);\n return null;\n }\n\n return value as GridFilterOperation;\n },\n};\n\n/**\n * Lista de operações separada por espaço (`filter-operations=\"contains =\"`),\n * à moda de `DOMTokenList`. Só lê (não reflete); token desconhecido é\n * ignorado com aviso.\n */\nexport const filterOperationsAttribute = {\n fromAttribute: (value: string | null): GridFilterOperation[] | null => {\n if (value === null) {\n return null;\n }\n\n const tokens = value.split(/\\s+/).filter(Boolean);\n const unknown = tokens.filter(token => !FILTER_OPERATION_TOKENS.has(token));\n\n if (unknown.length) {\n console.warn(`<u-grid-column>: unknown filter operation(s) ignored: ${unknown.join(', ')}.`);\n }\n\n return tokens.filter(token => FILTER_OPERATION_TOKENS.has(token)) as GridFilterOperation[];\n },\n};\n\n/**\n * Lista de números separada por vírgula ou espaço (`page-size-options=\"10, 20, 50\"`).\n * Só lê (não reflete); valores que não são inteiros positivos são ignorados;\n * sem atributo = `defaultValue` (vazio = lista vazia). Exceção registrada à\n * regra \"array = `attribute: false`\" (spec 15, frente 08).\n */\nexport const numberListAttribute = (defaultValue: readonly number[]) => ({\n fromAttribute: (value: string | null): readonly number[] => {\n if (value === null) {\n return defaultValue;\n }\n\n return value.split(/[\\s,]+/).filter(Boolean)\n .map(Number)\n .filter(size => Number.isInteger(size) && size > 0);\n },\n});\n\nconst EXPORT_FORMAT_TOKENS = new Set(['csv', 'xlsx', 'pdf']);\n\n/**\n * Formatos da exportação pela interface (`export-formats=\"csv xlsx pdf\"`, frentes\n * 18 e 26): palavras separadas por espaço ou vírgula; desconhecida avisa e é\n * ignorada; repetidas contam uma vez. Só lê (não reflete); sem atributo =\n * lista vazia. Exceção registrada à regra \"array = `attribute: false`\".\n */\nexport const exportFormatsAttribute = {\n fromAttribute: (value: string | null): readonly GridExportFormat[] => {\n if (value === null) {\n return [];\n }\n\n const tokens = value.split(/[\\s,]+/).filter(Boolean);\n const unknown = tokens.filter(token => !EXPORT_FORMAT_TOKENS.has(token));\n\n if (unknown.length) {\n console.warn(`<u-grid>: unknown export format(s) ignored: ${unknown.join(', ')}.`);\n }\n\n return [...new Set(tokens.filter(token => EXPORT_FORMAT_TOKENS.has(token)))] as GridExportFormat[];\n },\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change-source.js","sourceRoot":"","sources":["../src/change-source.ts"],"names":[],"mappings":"","sourcesContent":["/** Who changed the state: a user gesture or a method call. */\nexport type GridChangeSource = 'user' | 'api';\n"]}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { GridFilterExpression, GridGroupPath, GridSortOrder, GridSummaryType } from '../grid-column-def.js';
|
|
2
|
+
/** Key of a row read by `keyExpr`. */
|
|
3
|
+
export type GridRowKey = string | number;
|
|
4
|
+
/** `keyExpr` of `<u-grid>`: a property `path` (dots allowed) or a function that returns the key of an item. */
|
|
5
|
+
export type GridKeyExpr<TItem = any> = string | ((item: TItem) => GridRowKey);
|
|
6
|
+
/** How rows scroll: `virtual` (all rows, rendered on demand) or `infinite` (the next block loads at the end; `dataSource` only). */
|
|
7
|
+
export type GridScrollMode = 'virtual' | 'infinite';
|
|
8
|
+
/** A column of `GridLoadOptions.sort`. */
|
|
9
|
+
export interface GridLoadSort {
|
|
10
|
+
/** Column `path`. */
|
|
11
|
+
readonly path: string;
|
|
12
|
+
/** Direction. */
|
|
13
|
+
readonly order: GridSortOrder;
|
|
14
|
+
}
|
|
15
|
+
/** A grouping level of `GridLoadOptions.group`, outermost first. */
|
|
16
|
+
export interface GridLoadGroup {
|
|
17
|
+
/** Column `path`. */
|
|
18
|
+
readonly path: string;
|
|
19
|
+
/** Order of the group keys. */
|
|
20
|
+
readonly order: GridSortOrder;
|
|
21
|
+
/** `false`: return only the keys, counts and summaries of the level (`items: null`). The grid always asks `false`. */
|
|
22
|
+
readonly expanded: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** A summary the server computes (`totalSummary`, `groupSummary`). */
|
|
25
|
+
export interface GridLoadSummary {
|
|
26
|
+
/** Column `path`. */
|
|
27
|
+
readonly path: string;
|
|
28
|
+
/** Aggregate (custom aggregate functions are never sent). */
|
|
29
|
+
readonly type: GridSummaryType;
|
|
30
|
+
/** The `name` of the summary item, when it has one. */
|
|
31
|
+
readonly name?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* What the grid asks the data source. Frozen data: the host builds the
|
|
35
|
+
* request from it — the grid never builds URLs or queries. `filter`,
|
|
36
|
+
* `filterValue`, `searchText` and the paths come from the user and must be
|
|
37
|
+
* validated by the server (allow-list of paths and operations).
|
|
38
|
+
*/
|
|
39
|
+
export interface GridLoadOptions {
|
|
40
|
+
/** Rows to skip (absent = from the start). */
|
|
41
|
+
readonly skip?: number;
|
|
42
|
+
/** Rows to return (absent = all). */
|
|
43
|
+
readonly take?: number;
|
|
44
|
+
/** Sorting, in priority order (grouped columns included, with the direction of their groups). */
|
|
45
|
+
readonly sort: readonly GridLoadSort[];
|
|
46
|
+
/** Column filter `and` search — the same as `getCombinedFilter()`; `null` without filter. */
|
|
47
|
+
readonly filter: GridFilterExpression | null;
|
|
48
|
+
/** Column filter only (the `filterValue` property). */
|
|
49
|
+
readonly filterValue: GridFilterExpression | null;
|
|
50
|
+
/** Raw search text (already part of `filter`), for servers with their own text search. */
|
|
51
|
+
readonly searchText: string;
|
|
52
|
+
/**
|
|
53
|
+
* All grouping levels, outermost first (empty = not grouped). Return groups
|
|
54
|
+
* (`GridLoadGroupResult[]`) of level `groupPath.length` while it is less than
|
|
55
|
+
* `group.length`; items when it is equal.
|
|
56
|
+
*/
|
|
57
|
+
readonly group: readonly GridLoadGroup[];
|
|
58
|
+
/** Values of the open group, outermost first: only rows of that group (exact equality). `null` = all rows. */
|
|
59
|
+
readonly groupPath: GridGroupPath | null;
|
|
60
|
+
/** Return `totalCount`. */
|
|
61
|
+
readonly requireTotalCount: boolean;
|
|
62
|
+
/** Return `groupCount` (number of groups of the level). */
|
|
63
|
+
readonly requireGroupCount: boolean;
|
|
64
|
+
/** Summaries over all matching rows, returned in `GridLoadResult.summary` in this order. */
|
|
65
|
+
readonly totalSummary: readonly GridLoadSummary[];
|
|
66
|
+
/** Summaries of each returned group, in `GridLoadGroupResult.summary` in this order. */
|
|
67
|
+
readonly groupSummary: readonly GridLoadSummary[];
|
|
68
|
+
/** Tree data (`treeMode="flat"`): which nodes to return; absent or `null` = a plain list. */
|
|
69
|
+
readonly tree?: GridLoadTree | null;
|
|
70
|
+
}
|
|
71
|
+
/** `GridLoadOptions.tree`: what a tree asks the data source (items with their `parentKeyExpr`). */
|
|
72
|
+
export interface GridLoadTree {
|
|
73
|
+
/**
|
|
74
|
+
* Return the children of these nodes (`[rootParentKey]` = the root nodes;
|
|
75
|
+
* keys as set — text when `root-parent-key` came from the attribute).
|
|
76
|
+
* `null` = a remote filter is active: return the matching nodes AND all
|
|
77
|
+
* their ancestors, at once.
|
|
78
|
+
*/
|
|
79
|
+
readonly parentKeys: readonly (GridRowKey | null)[] | null;
|
|
80
|
+
}
|
|
81
|
+
/** A group returned when `GridLoadOptions.group` is not empty. */
|
|
82
|
+
export interface GridLoadGroupResult<TItem = any> {
|
|
83
|
+
/** Group value. */
|
|
84
|
+
key: unknown;
|
|
85
|
+
/** Number of data rows in the group. */
|
|
86
|
+
count: number;
|
|
87
|
+
/** `null` (the grid always asks collapsed groups); items or subgroups are accepted and ignored. */
|
|
88
|
+
items: readonly TItem[] | readonly GridLoadGroupResult<TItem>[] | null;
|
|
89
|
+
/** Values of `groupSummary`, in its order. */
|
|
90
|
+
summary?: readonly unknown[];
|
|
91
|
+
}
|
|
92
|
+
/** What `GridDataSource.load` resolves to. */
|
|
93
|
+
export interface GridLoadResult<TItem = any> {
|
|
94
|
+
/** Items, or groups when `group` was not empty. */
|
|
95
|
+
data: readonly TItem[] | readonly GridLoadGroupResult<TItem>[];
|
|
96
|
+
/** Number of matching rows (when `requireTotalCount`). */
|
|
97
|
+
totalCount?: number;
|
|
98
|
+
/** Number of groups of the level (when `requireGroupCount`). */
|
|
99
|
+
groupCount?: number;
|
|
100
|
+
/** Values of `totalSummary`, in its order. */
|
|
101
|
+
summary?: readonly unknown[];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Data source of `<u-grid>`: the grid calls `load` and the host fetches the
|
|
105
|
+
* data. `signal` aborts when the request is no longer needed (sorting,
|
|
106
|
+
* filtering or grouping changed, `refresh()`, grid removed).
|
|
107
|
+
*/
|
|
108
|
+
export interface GridDataSource<TItem = any> {
|
|
109
|
+
load(options: GridLoadOptions, signal: AbortSignal): Promise<GridLoadResult<TItem>>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Operations done by the server (`remoteOperations`). Remote `paging` or
|
|
113
|
+
* `grouping` also turn on `filtering`, `sorting` and `summary`, and `paging`
|
|
114
|
+
* turns on `grouping` (console warning); `summary` alone is ignored (the
|
|
115
|
+
* grid has every row and computes it).
|
|
116
|
+
*/
|
|
117
|
+
export interface GridRemoteOperations {
|
|
118
|
+
/** The server applies `filter` (or `filterValue` + `searchText`). */
|
|
119
|
+
filtering?: boolean;
|
|
120
|
+
/** The server applies `sort`. */
|
|
121
|
+
sorting?: boolean;
|
|
122
|
+
/** The server applies `skip`/`take` (rows load in blocks of `pageSize`). */
|
|
123
|
+
paging?: boolean;
|
|
124
|
+
/** The server returns groups (`group`, `groupPath`). */
|
|
125
|
+
grouping?: boolean;
|
|
126
|
+
/** The server computes `totalSummary`/`groupSummary` (with remote paging or grouping). */
|
|
127
|
+
summary?: boolean;
|
|
128
|
+
}
|
|
129
|
+
/** Changes for `applyChanges()`: `update` and `remove` find rows by key (`keyExpr`). */
|
|
130
|
+
export interface GridDataChanges<TItem = any> {
|
|
131
|
+
/** New items (appended to the loaded rows, or at their sorted place with `reshapeOnChanges`; with remote paging the rows reload). */
|
|
132
|
+
add?: readonly TItem[];
|
|
133
|
+
/** New versions of items (same key). */
|
|
134
|
+
update?: readonly TItem[];
|
|
135
|
+
/** Keys of the rows to remove. */
|
|
136
|
+
remove?: readonly unknown[];
|
|
137
|
+
}
|
|
138
|
+
/** Operações remotas já normalizadas (dependências aplicadas). */
|
|
139
|
+
export interface RemoteFlags {
|
|
140
|
+
filtering: boolean;
|
|
141
|
+
sorting: boolean;
|
|
142
|
+
paging: boolean;
|
|
143
|
+
grouping: boolean;
|
|
144
|
+
summary: boolean;
|
|
145
|
+
}
|
|
146
|
+
export declare const NO_REMOTE: RemoteFlags;
|
|
147
|
+
/**
|
|
148
|
+
* Normaliza `remoteOperations`: paginação ou agrupamento no servidor exigem
|
|
149
|
+
* filtrar e ordenar lá; paginar no servidor exige agrupar lá (os grupos
|
|
150
|
+
* precisam de todas as linhas); resumo remoto só existe com paginação ou
|
|
151
|
+
* agrupamento remotos (senão o grid tem todas as linhas e calcula).
|
|
152
|
+
* `forced` lista o que foi ligado por dependência (para o aviso).
|
|
153
|
+
*/
|
|
154
|
+
export declare const normalizeRemoteOperations: (value: boolean | GridRemoteOperations | null | undefined) => {
|
|
155
|
+
flags: RemoteFlags;
|
|
156
|
+
forced: string[];
|
|
157
|
+
};
|
|
158
|
+
/** Leitor da chave de linha: `keyExpr` ou, sem ela, o próprio item. */
|
|
159
|
+
export declare const keyReader: (keyExpr: GridKeyExpr | null | undefined) => (item: unknown) => unknown;
|
|
160
|
+
/** Texto da chave para o `key` das linhas renderizadas (`1` e `"1"` são chaves diferentes). */
|
|
161
|
+
export declare const keyText: (key: unknown) => string;
|
|
162
|
+
/** Congela opções em profundidade (arrays e objetos simples). */
|
|
163
|
+
export declare const deepFreeze: <T>(value: T) => T;
|
|
164
|
+
//# sourceMappingURL=data-source.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { getValueByPath } from '../row-model/value.js';
|
|
2
|
+
export const NO_REMOTE = Object.freeze({
|
|
3
|
+
filtering: false,
|
|
4
|
+
sorting: false,
|
|
5
|
+
paging: false,
|
|
6
|
+
grouping: false,
|
|
7
|
+
summary: false,
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Normaliza `remoteOperations`: paginação ou agrupamento no servidor exigem
|
|
11
|
+
* filtrar e ordenar lá; paginar no servidor exige agrupar lá (os grupos
|
|
12
|
+
* precisam de todas as linhas); resumo remoto só existe com paginação ou
|
|
13
|
+
* agrupamento remotos (senão o grid tem todas as linhas e calcula).
|
|
14
|
+
* `forced` lista o que foi ligado por dependência (para o aviso).
|
|
15
|
+
*/
|
|
16
|
+
export const normalizeRemoteOperations = (value) => {
|
|
17
|
+
if (!value) {
|
|
18
|
+
return { flags: NO_REMOTE, forced: [] };
|
|
19
|
+
}
|
|
20
|
+
if (value === true) {
|
|
21
|
+
return { flags: { filtering: true, sorting: true, paging: true, grouping: true, summary: true }, forced: [] };
|
|
22
|
+
}
|
|
23
|
+
const forced = [];
|
|
24
|
+
const flags = {
|
|
25
|
+
filtering: !!value.filtering,
|
|
26
|
+
sorting: !!value.sorting,
|
|
27
|
+
paging: !!value.paging,
|
|
28
|
+
grouping: !!value.grouping,
|
|
29
|
+
summary: !!value.summary,
|
|
30
|
+
};
|
|
31
|
+
const force = (name) => {
|
|
32
|
+
if (!flags[name]) {
|
|
33
|
+
flags[name] = true;
|
|
34
|
+
forced.push(name);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
if (flags.paging) {
|
|
38
|
+
force('grouping');
|
|
39
|
+
}
|
|
40
|
+
if (flags.paging || flags.grouping) {
|
|
41
|
+
force('filtering');
|
|
42
|
+
force('sorting');
|
|
43
|
+
force('summary');
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
flags.summary = false;
|
|
47
|
+
}
|
|
48
|
+
return { flags, forced };
|
|
49
|
+
};
|
|
50
|
+
/** Leitor da chave de linha: `keyExpr` ou, sem ela, o próprio item. */
|
|
51
|
+
export const keyReader = (keyExpr) => {
|
|
52
|
+
if (typeof keyExpr === 'function') {
|
|
53
|
+
return keyExpr;
|
|
54
|
+
}
|
|
55
|
+
if (typeof keyExpr === 'string' && keyExpr) {
|
|
56
|
+
if (!keyExpr.includes('.')) {
|
|
57
|
+
return item => item === null || item === undefined ? undefined : item[keyExpr];
|
|
58
|
+
}
|
|
59
|
+
return item => getValueByPath(item, keyExpr);
|
|
60
|
+
}
|
|
61
|
+
return item => item;
|
|
62
|
+
};
|
|
63
|
+
/** Texto da chave para o `key` das linhas renderizadas (`1` e `"1"` são chaves diferentes). */
|
|
64
|
+
export const keyText = (key) => typeof key === 'string' ? `s${key}` : typeof key === 'number' ? `n${key}` : `${typeof key}:${String(key)}`;
|
|
65
|
+
/** Congela opções em profundidade (arrays e objetos simples). */
|
|
66
|
+
export const deepFreeze = (value) => {
|
|
67
|
+
if (value && typeof value === 'object' && !Object.isFrozen(value) && !(value instanceof Date)) {
|
|
68
|
+
Object.freeze(value);
|
|
69
|
+
for (const entry of Object.values(value)) {
|
|
70
|
+
deepFreeze(entry);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return value;
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=data-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-source.js","sourceRoot":"","sources":["../../src/data/data-source.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAgKvD,MAAM,CAAC,MAAM,SAAS,GAAgB,MAAM,CAAC,MAAM,CAAC;IAClD,SAAS,EAAE,KAAK;IAChB,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,KAAK;IACb,QAAQ,EAAE,KAAK;IACf,OA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K,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,EAAE,CAAC;QAC9F,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAErB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACzC,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["import type {\n GridFilterExpression,\n GridGroupPath,\n GridSortOrder,\n GridSummaryType,\n} from '../grid-column-def.js';\nimport { getValueByPath } from '../row-model/value.js';\n\n/** Key of a row read by `keyExpr`. */\nexport type GridRowKey = string | number;\n\n/** `keyExpr` of `<u-grid>`: a property `path` (dots allowed) or a function that returns the key of an item. */\nexport type GridKeyExpr<TItem = any> = string | ((item: TItem) => GridRowKey);\n\n/** How rows scroll: `virtual` (all rows, rendered on demand) or `infinite` (the next block loads at the end; `dataSource` only). */\nexport type GridScrollMode = 'virtual' | 'infinite';\n\n/** A column of `GridLoadOptions.sort`. */\nexport interface GridLoadSort {\n /** Column `path`. */\n readonly path: string;\n /** Direction. */\n readonly order: GridSortOrder;\n}\n\n/** A grouping level of `GridLoadOptions.group`, outermost first. */\nexport interface GridLoadGroup {\n /** Column `path`. */\n readonly path: string;\n /** Order of the group keys. */\n readonly order: GridSortOrder;\n /** `false`: return only the keys, counts and summaries of the level (`items: null`). The grid always asks `false`. */\n readonly expanded: boolean;\n}\n\n/** A summary the server computes (`totalSummary`, `groupSummary`). */\nexport interface GridLoadSummary {\n /** Column `path`. */\n readonly path: string;\n /** Aggregate (custom aggregate functions are never sent). */\n readonly type: GridSummaryType;\n /** The `name` of the summary item, when it has one. */\n readonly name?: string;\n}\n\n/**\n * What the grid asks the data source. Frozen data: the host builds the\n * request from it — the grid never builds URLs or queries. `filter`,\n * `filterValue`, `searchText` and the paths come from the user and must be\n * validated by the server (allow-list of paths and operations).\n */\nexport interface GridLoadOptions {\n /** Rows to skip (absent = from the start). */\n readonly skip?: number;\n /** Rows to return (absent = all). */\n readonly take?: number;\n /** Sorting, in priority order (grouped columns included, with the direction of their groups). */\n readonly sort: readonly GridLoadSort[];\n /** Column filter `and` search — the same as `getCombinedFilter()`; `null` without filter. */\n readonly filter: GridFilterExpression | null;\n /** Column filter only (the `filterValue` property). */\n readonly filterValue: GridFilterExpression | null;\n /** Raw search text (already part of `filter`), for servers with their own text search. */\n readonly searchText: string;\n /**\n * All grouping levels, outermost first (empty = not grouped). Return groups\n * (`GridLoadGroupResult[]`) of level `groupPath.length` while it is less than\n * `group.length`; items when it is equal.\n */\n readonly group: readonly GridLoadGroup[];\n /** Values of the open group, outermost first: only rows of that group (exact equality). `null` = all rows. */\n readonly groupPath: GridGroupPath | null;\n /** Return `totalCount`. */\n readonly requireTotalCount: boolean;\n /** Return `groupCount` (number of groups of the level). */\n readonly requireGroupCount: boolean;\n /** Summaries over all matching rows, returned in `GridLoadResult.summary` in this order. */\n readonly totalSummary: readonly GridLoadSummary[];\n /** Summaries of each returned group, in `GridLoadGroupResult.summary` in this order. */\n readonly groupSummary: readonly GridLoadSummary[];\n /** Tree data (`treeMode=\"flat\"`): which nodes to return; absent or `null` = a plain list. */\n readonly tree?: GridLoadTree | null;\n}\n\n/** `GridLoadOptions.tree`: what a tree asks the data source (items with their `parentKeyExpr`). */\nexport interface GridLoadTree {\n /**\n * Return the children of these nodes (`[rootParentKey]` = the root nodes;\n * keys as set — text when `root-parent-key` came from the attribute).\n * `null` = a remote filter is active: return the matching nodes AND all\n * their ancestors, at once.\n */\n readonly parentKeys: readonly (GridRowKey | null)[] | null;\n}\n\n/** A group returned when `GridLoadOptions.group` is not empty. */\nexport interface GridLoadGroupResult<TItem = any> {\n /** Group value. */\n key: unknown;\n /** Number of data rows in the group. */\n count: number;\n /** `null` (the grid always asks collapsed groups); items or subgroups are accepted and ignored. */\n items: readonly TItem[] | readonly GridLoadGroupResult<TItem>[] | null;\n /** Values of `groupSummary`, in its order. */\n summary?: readonly unknown[];\n}\n\n/** What `GridDataSource.load` resolves to. */\nexport interface GridLoadResult<TItem = any> {\n /** Items, or groups when `group` was not empty. */\n data: readonly TItem[] | readonly GridLoadGroupResult<TItem>[];\n /** Number of matching rows (when `requireTotalCount`). */\n totalCount?: number;\n /** Number of groups of the level (when `requireGroupCount`). */\n groupCount?: number;\n /** Values of `totalSummary`, in its order. */\n summary?: readonly unknown[];\n}\n\n/**\n * Data source of `<u-grid>`: the grid calls `load` and the host fetches the\n * data. `signal` aborts when the request is no longer needed (sorting,\n * filtering or grouping changed, `refresh()`, grid removed).\n */\nexport interface GridDataSource<TItem = any> {\n load(options: GridLoadOptions, signal: AbortSignal): Promise<GridLoadResult<TItem>>;\n}\n\n/**\n * Operations done by the server (`remoteOperations`). Remote `paging` or\n * `grouping` also turn on `filtering`, `sorting` and `summary`, and `paging`\n * turns on `grouping` (console warning); `summary` alone is ignored (the\n * grid has every row and computes it).\n */\nexport interface GridRemoteOperations {\n /** The server applies `filter` (or `filterValue` + `searchText`). */\n filtering?: boolean;\n /** The server applies `sort`. */\n sorting?: boolean;\n /** The server applies `skip`/`take` (rows load in blocks of `pageSize`). */\n paging?: boolean;\n /** The server returns groups (`group`, `groupPath`). */\n grouping?: boolean;\n /** The server computes `totalSummary`/`groupSummary` (with remote paging or grouping). */\n summary?: boolean;\n}\n\n/** Changes for `applyChanges()`: `update` and `remove` find rows by key (`keyExpr`). */\nexport interface GridDataChanges<TItem = any> {\n /** New items (appended to the loaded rows, or at their sorted place with `reshapeOnChanges`; with remote paging the rows reload). */\n add?: readonly TItem[];\n /** New versions of items (same key). */\n update?: readonly TItem[];\n /** Keys of the rows to remove. */\n remove?: readonly unknown[];\n}\n\n/** Operações remotas já normalizadas (dependências aplicadas). */\nexport interface RemoteFlags {\n filtering: boolean;\n sorting: boolean;\n paging: boolean;\n grouping: boolean;\n summary: boolean;\n}\n\nexport const NO_REMOTE: RemoteFlags = Object.freeze({\n filtering: false,\n sorting: false,\n paging: false,\n grouping: false,\n summary: false,\n});\n\n/**\n * Normaliza `remoteOperations`: paginação ou agrupamento no servidor exigem\n * filtrar e ordenar lá; paginar no servidor exige agrupar lá (os grupos\n * precisam de todas as linhas); resumo remoto só existe com paginação ou\n * agrupamento remotos (senão o grid tem todas as linhas e calcula).\n * `forced` lista o que foi ligado por dependência (para o aviso).\n */\nexport const normalizeRemoteOperations = (\n value: boolean | GridRemoteOperations | null | undefined,\n): { flags: RemoteFlags; forced: string[] } => {\n if (!value) {\n return { flags: NO_REMOTE, forced: [] };\n }\n\n if (value === true) {\n return { flags: { filtering: true, sorting: true, paging: true, grouping: true, summary: true }, forced: [] };\n }\n\n const forced: string[] = [];\n const flags: RemoteFlags = {\n filtering: !!value.filtering,\n sorting: !!value.sorting,\n paging: !!value.paging,\n grouping: !!value.grouping,\n summary: !!value.summary,\n };\n\n const force = (name: keyof RemoteFlags) => {\n if (!flags[name]) {\n flags[name] = true;\n forced.push(name);\n }\n };\n\n if (flags.paging) {\n force('grouping');\n }\n\n if (flags.paging || flags.grouping) {\n force('filtering');\n force('sorting');\n force('summary');\n } else {\n flags.summary = false;\n }\n\n return { flags, forced };\n};\n\n/** Leitor da chave de linha: `keyExpr` ou, sem ela, o próprio item. */\nexport const keyReader = (keyExpr: GridKeyExpr | null | undefined): (item: unknown) => unknown => {\n if (typeof keyExpr === 'function') {\n return keyExpr as (item: unknown) => unknown;\n }\n\n if (typeof keyExpr === 'string' && keyExpr) {\n if (!keyExpr.includes('.')) {\n return item => item === null || item === undefined ? undefined : (item as Record<string, unknown>)[keyExpr];\n }\n\n return item => getValueByPath(item, keyExpr);\n }\n\n return item => item;\n};\n\n/** Texto da chave para o `key` das linhas renderizadas (`1` e `\"1\"` são chaves diferentes). */\nexport const keyText = (key: unknown): string =>\n typeof key === 'string' ? `s${key}` : typeof key === 'number' ? `n${key}` : `${typeof key}:${String(key)}`;\n\n/** Congela opções em profundidade (arrays e objetos simples). */\nexport const deepFreeze = <T>(value: T): T => {\n if (value && typeof value === 'object' && !Object.isFrozen(value) && !(value instanceof Date)) {\n Object.freeze(value);\n\n for (const entry of Object.values(value)) {\n deepFreeze(entry);\n }\n }\n\n return value;\n};\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GridDataSource, GridLoadOptions, GridLoadResult } from './data-source.js';
|
|
2
|
+
/**
|
|
3
|
+
* Fonte de dados sobre um array, no mesmo contrato da remota: aplica
|
|
4
|
+
* `filter`, `groupPath`, `sort`, `group`, resumos e `skip`/`take` com as
|
|
5
|
+
* funções do row model. É a referência executável do contrato (o "servidor"
|
|
6
|
+
* dos testes) e mostra ao hospedeiro o que cada campo de `GridLoadOptions`
|
|
7
|
+
* significa. Não muta o array.
|
|
8
|
+
*/
|
|
9
|
+
export declare class LocalDataSource<TItem = unknown> implements GridDataSource<TItem> {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(items: readonly TItem[], options?: {
|
|
12
|
+
language?: string;
|
|
13
|
+
});
|
|
14
|
+
load(options: GridLoadOptions, signal?: AbortSignal): Promise<GridLoadResult<TItem>>;
|
|
15
|
+
/** O mesmo de `load`, síncrono. */
|
|
16
|
+
query(options: GridLoadOptions): GridLoadResult<TItem>;
|
|
17
|
+
}
|
|
18
|
+
/** Igualdade exata do `groupPath` (datas pelo tempo; `null` e `undefined` são o grupo vazio). */
|
|
19
|
+
export declare const sameValue: (a: unknown, b: unknown) => boolean;
|
|
20
|
+
//# sourceMappingURL=local-source.d.ts.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { createComparer } from '../row-model/compare.js';
|
|
2
|
+
import { compileFilter, filterItems } from '../row-model/filter.js';
|
|
3
|
+
import { buildGroups } from '../row-model/group.js';
|
|
4
|
+
import { sortItems } from '../row-model/sort.js';
|
|
5
|
+
import { summarize } from '../row-model/summary.js';
|
|
6
|
+
import { getValueByPath } from '../row-model/value.js';
|
|
7
|
+
/**
|
|
8
|
+
* Fonte de dados sobre um array, no mesmo contrato da remota: aplica
|
|
9
|
+
* `filter`, `groupPath`, `sort`, `group`, resumos e `skip`/`take` com as
|
|
10
|
+
* funções do row model. É a referência executável do contrato (o "servidor"
|
|
11
|
+
* dos testes) e mostra ao hospedeiro o que cada campo de `GridLoadOptions`
|
|
12
|
+
* significa. Não muta o array.
|
|
13
|
+
*/
|
|
14
|
+
export class LocalDataSource {
|
|
15
|
+
#items;
|
|
16
|
+
#columns = new Map();
|
|
17
|
+
#language;
|
|
18
|
+
constructor(items, options = {}) {
|
|
19
|
+
this.#items = items;
|
|
20
|
+
this.#language = options.language;
|
|
21
|
+
}
|
|
22
|
+
#column(path) {
|
|
23
|
+
let column = this.#columns.get(path);
|
|
24
|
+
if (!column) {
|
|
25
|
+
column = { path };
|
|
26
|
+
this.#columns.set(path, column);
|
|
27
|
+
}
|
|
28
|
+
return column;
|
|
29
|
+
}
|
|
30
|
+
#summaries(list) {
|
|
31
|
+
return list.map(({ path, type }) => ({ column: this.#column(path), type }));
|
|
32
|
+
}
|
|
33
|
+
load(options, signal) {
|
|
34
|
+
signal?.throwIfAborted();
|
|
35
|
+
return Promise.resolve(this.query(options));
|
|
36
|
+
}
|
|
37
|
+
/** O mesmo de `load`, síncrono. */
|
|
38
|
+
query(options) {
|
|
39
|
+
let items = this.#items;
|
|
40
|
+
const predicate = compileFilter(options.filter, {
|
|
41
|
+
language: this.#language,
|
|
42
|
+
columns: [],
|
|
43
|
+
dataTypeOf: () => undefined,
|
|
44
|
+
textOf: (item, column) => {
|
|
45
|
+
const value = getValueByPath(item, column.path);
|
|
46
|
+
return value === null || value === undefined ? '' : String(value);
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
items = filterItems(items, predicate);
|
|
50
|
+
const groupPath = options.groupPath ?? [];
|
|
51
|
+
const levels = options.group;
|
|
52
|
+
if (groupPath.length) {
|
|
53
|
+
items = items.filter(item => groupPath.every((value, level) => sameValue(getValueByPath(item, levels[level]?.path), value)));
|
|
54
|
+
}
|
|
55
|
+
items = sortItems(items, options.sort.map(({ path, order }) => ({ column: this.#column(path), order })), this.#language);
|
|
56
|
+
const result = { data: [] };
|
|
57
|
+
const level = groupPath.length;
|
|
58
|
+
if (options.requireTotalCount) {
|
|
59
|
+
result.totalCount = items.length;
|
|
60
|
+
}
|
|
61
|
+
if (options.totalSummary.length) {
|
|
62
|
+
result.summary = summarize(items, this.#summaries(options.totalSummary));
|
|
63
|
+
}
|
|
64
|
+
if (level < levels.length) {
|
|
65
|
+
const { path, order } = levels[level];
|
|
66
|
+
const nodes = buildGroups(items, [this.#column(path)], () => createComparer(this.#language), [order], this.#summaries(options.groupSummary));
|
|
67
|
+
const groups = nodes.map(node => ({
|
|
68
|
+
key: node.value,
|
|
69
|
+
count: node.items.length,
|
|
70
|
+
items: null,
|
|
71
|
+
summary: options.groupSummary.length ? node.summaries : undefined,
|
|
72
|
+
}));
|
|
73
|
+
if (options.requireGroupCount) {
|
|
74
|
+
result.groupCount = groups.length;
|
|
75
|
+
}
|
|
76
|
+
result.data = slice(groups, options.skip, options.take);
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
result.data = slice(items, options.skip, options.take);
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const slice = (list, skip = 0, take) => skip || take !== undefined ? list.slice(skip, take === undefined ? undefined : skip + take) : list;
|
|
84
|
+
/** Igualdade exata do `groupPath` (datas pelo tempo; `null` e `undefined` são o grupo vazio). */
|
|
85
|
+
export const sameValue = (a, b) => {
|
|
86
|
+
if (a === null || a === undefined) {
|
|
87
|
+
return b === null || b === undefined;
|
|
88
|
+
}
|
|
89
|
+
if (a instanceof Date && b instanceof Date) {
|
|
90
|
+
return a.getTime() === b.getTime();
|
|
91
|
+
}
|
|
92
|
+
return Object.is(a, b);
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=local-source.js.map
|
|
@@ -0,0 +1 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grid-column-def.js';\nimport { createComparer } from '../row-model/compare.js';\nimport { compileFilter, filterItems } from '../row-model/filter.js';\nimport { buildGroups } from '../row-model/group.js';\nimport { sortItems } from '../row-model/sort.js';\nimport { summarize, type SummarySpec } from '../row-model/summary.js';\nimport { getValueByPath } from '../row-model/value.js';\nimport type {\n GridDataSource,\n GridLoadGroupResult,\n GridLoadOptions,\n GridLoadResult,\n GridLoadSummary,\n} from './data-source.js';\n\n/**\n * Fonte de dados sobre um array, no mesmo contrato da remota: aplica\n * `filter`, `groupPath`, `sort`, `group`, resumos e `skip`/`take` com as\n * funções do row model. É a referência executável do contrato (o \"servidor\"\n * dos testes) e mostra ao hospedeiro o que cada campo de `GridLoadOptions`\n * significa. Não muta o array.\n */\nexport class LocalDataSource<TItem = unknown> implements GridDataSource<TItem> {\n readonly #items: readonly TItem[];\n readonly #columns = new Map<string, GridColumnDef>();\n readonly #language: string | undefined;\n\n constructor(items: readonly TItem[], options: { language?: string } = {}) {\n this.#items = items;\n this.#language = options.language;\n }\n\n #column(path: string): GridColumnDef {\n let column = this.#columns.get(path);\n\n if (!column) {\n column = { path };\n this.#columns.set(path, column);\n }\n\n return column;\n }\n\n #summaries(list: readonly GridLoadSummary[]): SummarySpec[] {\n return list.map(({ path, type }) => ({ column: this.#column(path), type }));\n }\n\n load(options: GridLoadOptions, signal?: AbortSignal): Promise<GridLoadResult<TItem>> {\n signal?.throwIfAborted();\n return Promise.resolve(this.query(options));\n }\n\n /** O mesmo de `load`, síncrono. */\n query(options: GridLoadOptions): GridLoadResult<TItem> {\n let items = this.#items;\n\n const predicate = compileFilter(options.filter, {\n language: this.#language,\n columns: [],\n dataTypeOf: () => undefined,\n textOf: (item, column) => {\n const value = getValueByPath(item, column.path);\n return value === null || value === undefined ? '' : String(value);\n },\n });\n\n items = filterItems(items, predicate);\n\n const groupPath = options.groupPath ?? [];\n const levels = options.group;\n\n if (groupPath.length) {\n items = items.filter(item => groupPath.every((value, level) =>\n sameValue(getValueByPath(item, levels[level]?.path), value)));\n }\n\n items = sortItems(items, options.sort.map(({ path, order }) => ({ column: this.#column(path), order })), this.#language);\n\n const result: GridLoadResult<TItem> = { data: [] };\n const level = groupPath.length;\n\n if (options.requireTotalCount) {\n result.totalCount = items.length;\n }\n\n if (options.totalSummary.length) {\n result.summary = summarize(items, this.#summaries(options.totalSummary));\n }\n\n if (level < levels.length) {\n const { path, order } = levels[level];\n const nodes = buildGroups(\n items,\n [this.#column(path)],\n () => createComparer(this.#language),\n [order],\n this.#summaries(options.groupSummary),\n );\n const groups: GridLoadGroupResult<TItem>[] = nodes.map(node => ({\n key: node.value,\n count: node.items.length,\n items: null,\n summary: options.groupSummary.length ? node.summaries : undefined,\n }));\n\n if (options.requireGroupCount) {\n result.groupCount = groups.length;\n }\n\n result.data = slice(groups, options.skip, options.take);\n return result;\n }\n\n result.data = slice(items, options.skip, options.take);\n return result;\n }\n}\n\nconst slice = <T>(list: readonly T[], skip = 0, take?: number): readonly T[] =>\n skip || take !== undefined ? list.slice(skip, take === undefined ? undefined : skip + take) : list;\n\n/** Igualdade exata do `groupPath` (datas pelo tempo; `null` e `undefined` são o grupo vazio). */\nexport const sameValue = (a: unknown, b: unknown): boolean => {\n if (a === null || a === undefined) {\n return b === null || b === undefined;\n }\n\n if (a instanceof Date && b instanceof Date) {\n return a.getTime() === b.getTime();\n }\n\n return Object.is(a, b);\n};\n"]}
|