@universal-material/data-grid 0.0.0-stage → 0.1.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 +155 -2
- package/custom-elements.json +4624 -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 +450 -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 +537 -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 +96 -0
- package/dist/features/header-filter.js +579 -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/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 +509 -0
- package/dist/grid-column-def.js +32 -0
- package/dist/grid-column-def.js.map +1 -0
- package/dist/grid-column.d.ts +167 -0
- package/dist/grid-column.js +376 -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 +1484 -0
- package/dist/grid.js +15579 -0
- package/dist/grid.js.map +1 -0
- package/dist/grid.min.js +3858 -0
- package/dist/grid.styles.d.ts +2 -0
- package/dist/grid.styles.js +2747 -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 +59 -0
- package/dist/render/group-row.js.map +1 -0
- package/dist/render/header.d.ts +92 -0
- package/dist/render/header.js +103 -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 +110 -0
- package/dist/render/virtualizer.js +509 -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 +80 -0
- package/dist/row-model/columns.js +207 -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 +141 -6
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
import { html, nothing, svg } from 'lit';
|
|
2
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
+
import { live } from 'lit/directives/live.js';
|
|
4
|
+
import { map } from 'lit/directives/map.js';
|
|
5
|
+
import { findColumnCondition, hasColumnCondition } from '../row-model/filter.js';
|
|
6
|
+
import { createTextMatcher } from '../row-model/fold.js';
|
|
7
|
+
import { columnKeyOf } from './filter-row.js';
|
|
8
|
+
import { Debouncer } from './search.js';
|
|
9
|
+
import { formatMessage } from './sorting.js';
|
|
10
|
+
/** Itens desenhados na lista plana; acima disso, a busca do popover estreita. */
|
|
11
|
+
export const HEADER_FILTER_RENDER_LIMIT = 500;
|
|
12
|
+
const BLANK_KEY = '\u0000blank';
|
|
13
|
+
/** Chave de um valor distinto no conjunto de marcados. */
|
|
14
|
+
const keyOf = (value) => value === null || value === undefined ? BLANK_KEY : `${typeof value}:${String(value)}`;
|
|
15
|
+
/**
|
|
16
|
+
* Popover do filtro do cabeçalho: valores distintos (com contagem), busca,
|
|
17
|
+
* "selecionar tudo", datas em ano → mês → dia. OK aplica `anyof`/`noneof`
|
|
18
|
+
* (o menor dos dois); Cancelar, Esc e clique fora fecham sem aplicar. Foco
|
|
19
|
+
* preso no popover e devolvido ao botão do funil. O estado (valores, listener
|
|
20
|
+
* do documento) é solto ao fechar e no `hostDisconnected`.
|
|
21
|
+
*/
|
|
22
|
+
export class HeaderFilterController {
|
|
23
|
+
#host;
|
|
24
|
+
#state;
|
|
25
|
+
#shown;
|
|
26
|
+
#restoreFocusTo;
|
|
27
|
+
/** Item da árvore com \`tabindex="0"\` (roving; spec 17, A10). */
|
|
28
|
+
#activeItem;
|
|
29
|
+
/** Itens do último render (o teclado acha nível, pai e estado por eles). */
|
|
30
|
+
#items;
|
|
31
|
+
/** Contagem anunciada depois da busca (região \`status\` do popover). */
|
|
32
|
+
#searchAnnouncement;
|
|
33
|
+
#announcer;
|
|
34
|
+
constructor(host) {
|
|
35
|
+
this.#shown = false;
|
|
36
|
+
/** Itens do último render (o teclado acha nível, pai e estado por eles). */
|
|
37
|
+
this.#items = [];
|
|
38
|
+
/** Contagem anunciada depois da busca (região \`status\` do popover). */
|
|
39
|
+
this.#searchAnnouncement = '';
|
|
40
|
+
/** Busca do popover: ↓ vai à árvore; Enter = OK. */
|
|
41
|
+
this.onSearchKeyDown = (event) => {
|
|
42
|
+
// Enter que confirma a composição (ja/zh/ko) não aplica.
|
|
43
|
+
if (event.isComposing || event.keyCode === 229) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (event.key === 'ArrowDown') {
|
|
47
|
+
const item = event.currentTarget.closest('.header-filter')?.querySelector('[role=treeitem][tabindex="0"]');
|
|
48
|
+
if (item) {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
item.focus();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (event.key === 'Enter') {
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
this.apply();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Árvore (APG Tree View, um ponto de Tab): ↑/↓/Home/End movem; →/←
|
|
60
|
+
* (invertidas em RTL) expandem/recolhem ou vão ao filho/pai; Espaço marca;
|
|
61
|
+
* Enter = OK; uma letra vai para a busca.
|
|
62
|
+
*/
|
|
63
|
+
this.onTreeKeyDown = (event) => {
|
|
64
|
+
const tree = event.currentTarget;
|
|
65
|
+
const nodes = [...tree.querySelectorAll('[role=treeitem]')];
|
|
66
|
+
const current = event.target;
|
|
67
|
+
const index = nodes.indexOf(current);
|
|
68
|
+
const item = this.#items.find(entry => entry.key === current.getAttribute('data-key'));
|
|
69
|
+
if (index < 0 || !item) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
let key = event.key;
|
|
73
|
+
if (this.#host._isRtl() && (key === 'ArrowLeft' || key === 'ArrowRight')) {
|
|
74
|
+
key = key === 'ArrowLeft' ? 'ArrowRight' : 'ArrowLeft';
|
|
75
|
+
}
|
|
76
|
+
let next;
|
|
77
|
+
switch (key) {
|
|
78
|
+
case 'ArrowDown':
|
|
79
|
+
next = nodes[index + 1];
|
|
80
|
+
break;
|
|
81
|
+
case 'ArrowUp':
|
|
82
|
+
next = nodes[index - 1];
|
|
83
|
+
break;
|
|
84
|
+
case 'Home':
|
|
85
|
+
next = nodes[0];
|
|
86
|
+
break;
|
|
87
|
+
case 'End':
|
|
88
|
+
next = nodes[nodes.length - 1];
|
|
89
|
+
break;
|
|
90
|
+
case 'ArrowRight':
|
|
91
|
+
if (item.expanded === false) {
|
|
92
|
+
this.toggleExpanded(item.key.slice(2));
|
|
93
|
+
}
|
|
94
|
+
else if (item.expanded) {
|
|
95
|
+
next = nodes[index + 1];
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
case 'ArrowLeft':
|
|
99
|
+
if (item.expanded) {
|
|
100
|
+
this.toggleExpanded(item.key.slice(2));
|
|
101
|
+
}
|
|
102
|
+
else if (item.parent) {
|
|
103
|
+
next = nodes.find(node => node.getAttribute('data-key') === item.parent);
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
case ' ':
|
|
107
|
+
this.setSelected(item.values, this.stateOf(item.values) !== true);
|
|
108
|
+
break;
|
|
109
|
+
case 'Enter':
|
|
110
|
+
event.preventDefault();
|
|
111
|
+
this.apply();
|
|
112
|
+
return;
|
|
113
|
+
default:
|
|
114
|
+
// Digitar: o foco vai para a busca e a letra vai junto (não some).
|
|
115
|
+
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
|
116
|
+
tree.closest('.header-filter')?.querySelector('.header-filter-search')
|
|
117
|
+
?.focus();
|
|
118
|
+
}
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
next?.focus();
|
|
123
|
+
};
|
|
124
|
+
this.#outsidePointerDown = (event) => {
|
|
125
|
+
const keep = event.composedPath().some(target => target instanceof HTMLElement
|
|
126
|
+
&& (target.classList.contains('header-filter') || target.classList.contains('header-filter-button')));
|
|
127
|
+
if (!keep) {
|
|
128
|
+
this.close();
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
/** Esc cancela; Tab circula dentro do popover (foco preso). */
|
|
132
|
+
this.onKeyDown = (event) => {
|
|
133
|
+
if (event.isComposing || event.keyCode === 229) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (event.key === 'Escape') {
|
|
137
|
+
event.preventDefault();
|
|
138
|
+
event.stopPropagation();
|
|
139
|
+
this.close(true);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (event.key !== 'Tab') {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const popover = event.currentTarget;
|
|
146
|
+
const focusable = [...popover.querySelectorAll('input, button, [tabindex="0"]')]
|
|
147
|
+
.filter(element => !element.hasAttribute('disabled'));
|
|
148
|
+
const root = popover.getRootNode();
|
|
149
|
+
const active = root.activeElement;
|
|
150
|
+
const first = focusable[0];
|
|
151
|
+
const last = focusable[focusable.length - 1];
|
|
152
|
+
if (event.shiftKey && active === first) {
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
last?.focus();
|
|
155
|
+
}
|
|
156
|
+
else if (!event.shiftKey && active === last) {
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
first?.focus();
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
this.#host = host;
|
|
162
|
+
host.addController(this);
|
|
163
|
+
this.#announcer = new Debouncer(host);
|
|
164
|
+
}
|
|
165
|
+
get activeItem() {
|
|
166
|
+
return this.#activeItem;
|
|
167
|
+
}
|
|
168
|
+
get searchAnnouncement() {
|
|
169
|
+
return this.#searchAnnouncement;
|
|
170
|
+
}
|
|
171
|
+
/** Timers do popover (diagnóstico de memória). */
|
|
172
|
+
get timers() {
|
|
173
|
+
return this.#announcer.size;
|
|
174
|
+
}
|
|
175
|
+
setActiveItem(key) {
|
|
176
|
+
if (this.#activeItem !== key) {
|
|
177
|
+
this.#activeItem = key;
|
|
178
|
+
this.#host.requestUpdate();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/** Linhas da árvore: "(Vazios)", depois as datas expandidas ou os valores (até o limite). */
|
|
182
|
+
treeItems(translation) {
|
|
183
|
+
const state = this.#state;
|
|
184
|
+
if (!state) {
|
|
185
|
+
return this.#items = [];
|
|
186
|
+
}
|
|
187
|
+
const searching = !!state.search.trim();
|
|
188
|
+
const blank = state.distinct.blanks > 0 && !searching;
|
|
189
|
+
const offset = blank ? 1 : 0;
|
|
190
|
+
const items = [];
|
|
191
|
+
const flat = state.distinct.tree && !searching ? undefined : this.visibleValues().slice(0, HEADER_FILTER_RENDER_LIMIT);
|
|
192
|
+
const setSize = (flat?.length ?? state.distinct.tree.length) + offset;
|
|
193
|
+
if (blank) {
|
|
194
|
+
items.push({ key: keyOf(null), text: translation.filterBlanks, count: state.distinct.blanks, values: [null], level: 1, setSize, posInSet: 1 });
|
|
195
|
+
}
|
|
196
|
+
if (flat) {
|
|
197
|
+
flat.forEach((value, index) => items.push({
|
|
198
|
+
key: keyOf(value.value),
|
|
199
|
+
text: value.text,
|
|
200
|
+
count: value.count,
|
|
201
|
+
values: [value.value],
|
|
202
|
+
level: 1,
|
|
203
|
+
setSize,
|
|
204
|
+
posInSet: index + 1 + offset,
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
flattenDates(state.distinct.tree, state.expanded, 1, undefined, offset, items);
|
|
209
|
+
}
|
|
210
|
+
return this.#items = items;
|
|
211
|
+
}
|
|
212
|
+
get open() {
|
|
213
|
+
return !!this.#state;
|
|
214
|
+
}
|
|
215
|
+
get column() {
|
|
216
|
+
return this.#state?.column;
|
|
217
|
+
}
|
|
218
|
+
get state() {
|
|
219
|
+
return this.#state;
|
|
220
|
+
}
|
|
221
|
+
toggle(column) {
|
|
222
|
+
if (this.#state?.column === column) {
|
|
223
|
+
this.close(true);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
this.close();
|
|
227
|
+
const distinct = this.#host._distinctValues(column);
|
|
228
|
+
const all = [...distinct.blanks ? [null] : [], ...distinct.values.map(value => value.value)];
|
|
229
|
+
const condition = findColumnCondition(this.#host.filterValue, column, 'header');
|
|
230
|
+
const listed = new Set((Array.isArray(condition?.[1]) ? condition[1] : []).map(keyOf));
|
|
231
|
+
const selected = new Set();
|
|
232
|
+
for (const value of all) {
|
|
233
|
+
const key = keyOf(value);
|
|
234
|
+
const inList = listed.has(key);
|
|
235
|
+
if (!condition || (condition[0] === 'anyof' ? inList : !inList)) {
|
|
236
|
+
selected.add(key);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
this.#state = { column, distinct, all, selected, search: '', expanded: new Set() };
|
|
240
|
+
this.#shown = false;
|
|
241
|
+
this.#host.requestUpdate();
|
|
242
|
+
}
|
|
243
|
+
close(restoreFocus = false) {
|
|
244
|
+
if (!this.#state) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
this.#restoreFocusTo = restoreFocus ? this.#state.column : undefined;
|
|
248
|
+
this.#popover?.hidePopover?.();
|
|
249
|
+
this.#state = undefined;
|
|
250
|
+
this.#activeItem = undefined;
|
|
251
|
+
this.#items = [];
|
|
252
|
+
this.#searchAnnouncement = '';
|
|
253
|
+
this.#announcer.cancel('search');
|
|
254
|
+
document.removeEventListener('pointerdown', this.#outsidePointerDown, true);
|
|
255
|
+
this.#host.requestUpdate();
|
|
256
|
+
}
|
|
257
|
+
/** A coluna do popover saiu das definições: fecha (não segura a coluna). */
|
|
258
|
+
closeIfRemoved(columns) {
|
|
259
|
+
if (this.#state && !columns.has(this.#state.column)) {
|
|
260
|
+
this.close();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/** Marca/desmarca valores (folhas). */
|
|
264
|
+
setSelected(values, selected) {
|
|
265
|
+
const state = this.#state;
|
|
266
|
+
if (!state) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
for (const value of values) {
|
|
270
|
+
if (selected) {
|
|
271
|
+
state.selected.add(keyOf(value));
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
state.selected.delete(keyOf(value));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
this.#host.requestUpdate();
|
|
278
|
+
}
|
|
279
|
+
isSelected(value) {
|
|
280
|
+
return !!this.#state?.selected.has(keyOf(value));
|
|
281
|
+
}
|
|
282
|
+
/** `true`/`false`/`'mixed'` de um grupo de valores (ano, mês, "selecionar tudo"). */
|
|
283
|
+
stateOf(values) {
|
|
284
|
+
let checked = 0;
|
|
285
|
+
for (const value of values) {
|
|
286
|
+
if (this.isSelected(value)) {
|
|
287
|
+
checked++;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return checked === 0 ? false : checked === values.length ? true : 'mixed';
|
|
291
|
+
}
|
|
292
|
+
setSearch(text, translation) {
|
|
293
|
+
if (!this.#state) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
this.#state.search = text;
|
|
297
|
+
// A lista mudou: o roving volta ao 1º item visível (no render).
|
|
298
|
+
this.#activeItem = undefined;
|
|
299
|
+
this.#host.requestUpdate();
|
|
300
|
+
if (translation) {
|
|
301
|
+
// Quantos valores restaram, depois de parar de digitar (spec 17, A10).
|
|
302
|
+
this.#announcer.run('search', () => {
|
|
303
|
+
const state = this.#state;
|
|
304
|
+
if (state) {
|
|
305
|
+
const count = this.visibleValues().length + (state.distinct.blanks > 0 && !state.search.trim() ? 1 : 0);
|
|
306
|
+
this.#searchAnnouncement = formatMessage(translation.headerFilterSearchAnnouncement, { count: String(count) });
|
|
307
|
+
this.#host.requestUpdate();
|
|
308
|
+
}
|
|
309
|
+
}, 500);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
toggleExpanded(key) {
|
|
313
|
+
const expanded = this.#state?.expanded;
|
|
314
|
+
if (!expanded) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (!expanded.delete(key)) {
|
|
318
|
+
expanded.add(key);
|
|
319
|
+
}
|
|
320
|
+
this.#host.requestUpdate();
|
|
321
|
+
}
|
|
322
|
+
/** Valores que a busca do popover deixa ver (texto exibido, sem caixa/acento). */
|
|
323
|
+
visibleValues() {
|
|
324
|
+
const state = this.#state;
|
|
325
|
+
if (!state) {
|
|
326
|
+
return [];
|
|
327
|
+
}
|
|
328
|
+
const matcher = createTextMatcher(state.search);
|
|
329
|
+
return matcher ? state.distinct.values.filter(value => matcher.test(value.text)) : state.distinct.values;
|
|
330
|
+
}
|
|
331
|
+
/** OK: todos marcados tira a condição; senão o menor entre `anyof` e `noneof`. */
|
|
332
|
+
apply() {
|
|
333
|
+
const state = this.#state;
|
|
334
|
+
if (!state) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const { column, all, selected } = state;
|
|
338
|
+
const checked = all.filter(value => selected.has(keyOf(value)));
|
|
339
|
+
const unchecked = all.filter(value => !selected.has(keyOf(value)));
|
|
340
|
+
let condition = null;
|
|
341
|
+
if (unchecked.length) {
|
|
342
|
+
condition = checked.length <= unchecked.length
|
|
343
|
+
? [column.path, 'anyof', checked]
|
|
344
|
+
: [column.path, 'noneof', unchecked];
|
|
345
|
+
}
|
|
346
|
+
this.close(true);
|
|
347
|
+
this.#host._userFilterColumn(column, 'header', condition);
|
|
348
|
+
}
|
|
349
|
+
/** "Limpar filtro": tira todas as condições da coluna (linha e cabeçalho). */
|
|
350
|
+
clearColumn() {
|
|
351
|
+
const column = this.#state?.column;
|
|
352
|
+
if (column) {
|
|
353
|
+
this.close(true);
|
|
354
|
+
this.#host._userFilterColumn(column, 'all', null);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
get #popover() {
|
|
358
|
+
return this.#host.renderRoot.querySelector('.header-filter');
|
|
359
|
+
}
|
|
360
|
+
#buttonOf(column) {
|
|
361
|
+
return this.#host.renderRoot.querySelector(`.header-filter-button[data-column="${columnKeyOf(column)}"]`);
|
|
362
|
+
}
|
|
363
|
+
hostUpdated() {
|
|
364
|
+
if (!this.#state) {
|
|
365
|
+
if (this.#restoreFocusTo) {
|
|
366
|
+
this.#buttonOf(this.#restoreFocusTo)?.focus();
|
|
367
|
+
this.#restoreFocusTo = undefined;
|
|
368
|
+
}
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const popover = this.#popover;
|
|
372
|
+
if (!popover || this.#shown) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
this.#shown = true;
|
|
376
|
+
if (typeof popover.showPopover === 'function' && !popover.matches(':popover-open')) {
|
|
377
|
+
popover.showPopover();
|
|
378
|
+
}
|
|
379
|
+
this.#position(popover, this.#buttonOf(this.#state.column));
|
|
380
|
+
document.addEventListener('pointerdown', this.#outsidePointerDown, true);
|
|
381
|
+
popover.querySelector('.header-filter-search')?.focus();
|
|
382
|
+
}
|
|
383
|
+
hostDisconnected() {
|
|
384
|
+
document.removeEventListener('pointerdown', this.#outsidePointerDown, true);
|
|
385
|
+
this.#state = undefined;
|
|
386
|
+
this.#shown = false;
|
|
387
|
+
this.#restoreFocusTo = undefined;
|
|
388
|
+
this.#items = [];
|
|
389
|
+
this.#searchAnnouncement = '';
|
|
390
|
+
}
|
|
391
|
+
#position(popover, anchor) {
|
|
392
|
+
if (!anchor) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
const rect = anchor.getBoundingClientRect();
|
|
396
|
+
const width = popover.offsetWidth;
|
|
397
|
+
const margin = 8;
|
|
398
|
+
const viewport = document.documentElement.clientWidth;
|
|
399
|
+
// Abre para dentro da tabela: da borda final do botão em LTR, inicial em RTL.
|
|
400
|
+
const left = this.#host._isRtl() ? rect.left : rect.right - width;
|
|
401
|
+
popover.style.top = `${Math.round(rect.bottom + 4)}px`;
|
|
402
|
+
popover.style.left = `${Math.round(Math.max(margin, Math.min(left, viewport - width - margin)))}px`;
|
|
403
|
+
}
|
|
404
|
+
#outsidePointerDown;
|
|
405
|
+
}
|
|
406
|
+
/** Funil; com filtro ganha um ponto no canto (o estado não fica só na cor; spec 17, A5). */
|
|
407
|
+
const funnelIcon = (active) => html `
|
|
408
|
+
<svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 -960 960 960" fill="currentColor" aria-hidden="true">
|
|
409
|
+
<path d="M400-240v-80h160v80H400ZM240-440v-80h480v80H240ZM120-640v-80h${active ? 520 : 720}v80H120Z"/>
|
|
410
|
+
${active ? svg `<circle class="header-filter-badge" cx="800" cy="-760" r="110"/>` : nothing}
|
|
411
|
+
</svg>`;
|
|
412
|
+
/** Botão de funil no cabeçalho; ativo quando a coluna tem alguma condição. */
|
|
413
|
+
export const renderHeaderFilterButton = (controller, column, filterValue, translation,
|
|
414
|
+
/** Descrição do cabeçalho (traz "Filtrada"); spec 17, A5. */
|
|
415
|
+
describedBy) => {
|
|
416
|
+
const active = hasColumnCondition(filterValue, column);
|
|
417
|
+
const label = formatMessage(translation.headerFilterLabel, { column: column.label || column.path || '' });
|
|
418
|
+
return html `
|
|
419
|
+
<button
|
|
420
|
+
class="header-filter-button ${active ? 'active' : ''}"
|
|
421
|
+
part="header-filter-button"
|
|
422
|
+
type="button"
|
|
423
|
+
tabindex="-1"
|
|
424
|
+
aria-label=${label}
|
|
425
|
+
title=${label}
|
|
426
|
+
aria-haspopup="dialog"
|
|
427
|
+
aria-expanded=${controller.column === column ? 'true' : 'false'}
|
|
428
|
+
aria-describedby=${ifDefined(active ? describedBy : undefined)}
|
|
429
|
+
data-column=${columnKeyOf(column)}
|
|
430
|
+
@pointerdown=${(event) => event.stopPropagation()}
|
|
431
|
+
@click=${(event) => {
|
|
432
|
+
event.stopPropagation();
|
|
433
|
+
controller.toggle(column);
|
|
434
|
+
}}
|
|
435
|
+
@keydown=${(event) => {
|
|
436
|
+
// Enter/Espaço no funil não podem ordenar a coluna. Fora da ordem de
|
|
437
|
+
// Tab (o grid tem um ponto só): F2 ou Alt+↓ no cabeçalho chegam aqui.
|
|
438
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
439
|
+
event.stopPropagation();
|
|
440
|
+
}
|
|
441
|
+
}}>${funnelIcon(active)}</button>`;
|
|
442
|
+
};
|
|
443
|
+
const checkbox = (state, label, count, onChange) => html `
|
|
444
|
+
<label class="header-filter-check">
|
|
445
|
+
<input
|
|
446
|
+
type="checkbox"
|
|
447
|
+
.checked=${live(state === true)}
|
|
448
|
+
.indeterminate=${live(state === 'mixed')}
|
|
449
|
+
@change=${(event) => onChange(event.target.checked)}>
|
|
450
|
+
<span class="header-filter-text">${label}</span>
|
|
451
|
+
${count === undefined ? nothing : html `<span class="header-filter-count">${count}</span>`}
|
|
452
|
+
</label>`;
|
|
453
|
+
const leavesOf = (node) => 'children' in node ? node.children.flatMap(leavesOf) : [node.value];
|
|
454
|
+
/** Achata a árvore de datas expandida em itens com nível e posição (spec 17, A10). */
|
|
455
|
+
const flattenDates = (nodes, expanded, level, parent, offset, out) => {
|
|
456
|
+
nodes.forEach((node, index) => {
|
|
457
|
+
const isGroup = 'children' in node;
|
|
458
|
+
const key = isGroup ? `d:${node.key}` : keyOf(node.value);
|
|
459
|
+
const open = isGroup && expanded.has(node.key);
|
|
460
|
+
out.push({
|
|
461
|
+
key,
|
|
462
|
+
text: node.text,
|
|
463
|
+
count: node.count,
|
|
464
|
+
values: leavesOf(node),
|
|
465
|
+
level,
|
|
466
|
+
setSize: nodes.length + offset,
|
|
467
|
+
posInSet: index + 1 + offset,
|
|
468
|
+
expanded: isGroup ? open : undefined,
|
|
469
|
+
parent,
|
|
470
|
+
});
|
|
471
|
+
if (isGroup && open) {
|
|
472
|
+
flattenDates(node.children, expanded, level + 1, key, 0, out);
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
};
|
|
476
|
+
const boxIcon = (state) => html `
|
|
477
|
+
<span class="header-filter-box" aria-hidden="true">${state
|
|
478
|
+
? html `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" width="18" height="18" fill="currentColor">
|
|
479
|
+
<path d=${state === 'mixed' ? 'M200-440v-80h560v80H200Z' : 'M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z'}/>
|
|
480
|
+
</svg>`
|
|
481
|
+
: nothing}</span>`;
|
|
482
|
+
const renderTreeItem = (controller, item, active) => {
|
|
483
|
+
const state = controller.stateOf(item.values);
|
|
484
|
+
return html `
|
|
485
|
+
<li
|
|
486
|
+
class="header-filter-item"
|
|
487
|
+
role="treeitem"
|
|
488
|
+
style="--_level: ${item.level - 1}"
|
|
489
|
+
tabindex=${active ? 0 : -1}
|
|
490
|
+
data-key=${item.key}
|
|
491
|
+
aria-level=${item.level}
|
|
492
|
+
aria-setsize=${item.setSize}
|
|
493
|
+
aria-posinset=${item.posInSet}
|
|
494
|
+
aria-checked=${state === 'mixed' ? 'mixed' : state ? 'true' : 'false'}
|
|
495
|
+
aria-expanded=${ifDefined(item.expanded === undefined ? undefined : item.expanded ? 'true' : 'false')}
|
|
496
|
+
@focus=${() => controller.setActiveItem(item.key)}
|
|
497
|
+
@click=${() => controller.setSelected(item.values, state !== true)}>
|
|
498
|
+
${item.expanded === undefined
|
|
499
|
+
? nothing
|
|
500
|
+
: html `<span
|
|
501
|
+
class="header-filter-expand ${item.expanded ? 'expanded' : ''}"
|
|
502
|
+
aria-hidden="true"
|
|
503
|
+
@click=${(event) => {
|
|
504
|
+
// Só ponteiro: pelo teclado, →/← no item (o estado está no aria-expanded do item).
|
|
505
|
+
event.stopPropagation();
|
|
506
|
+
controller.toggleExpanded(item.key.slice(2));
|
|
507
|
+
}}>
|
|
508
|
+
<svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 -960 960 960" fill="currentColor">
|
|
509
|
+
<path d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z"/>
|
|
510
|
+
</svg>
|
|
511
|
+
</span>`}
|
|
512
|
+
${boxIcon(state)}
|
|
513
|
+
<span class="header-filter-text">${item.text}</span>
|
|
514
|
+
<span class="header-filter-count">${item.count}</span>
|
|
515
|
+
</li>`;
|
|
516
|
+
};
|
|
517
|
+
/** O popover (quando aberto). */
|
|
518
|
+
export const renderHeaderFilter = (controller, translation) => {
|
|
519
|
+
const state = controller.state;
|
|
520
|
+
if (!state) {
|
|
521
|
+
return nothing;
|
|
522
|
+
}
|
|
523
|
+
const { distinct, column } = state;
|
|
524
|
+
const searching = !!state.search.trim();
|
|
525
|
+
const useTree = !!distinct.tree && !searching;
|
|
526
|
+
const visible = controller.visibleValues();
|
|
527
|
+
const shown = visible.slice(0, HEADER_FILTER_RENDER_LIMIT);
|
|
528
|
+
const blankVisible = distinct.blanks > 0 && !searching;
|
|
529
|
+
const scope = [...blankVisible ? [null] : [], ...visible.map(value => value.value)];
|
|
530
|
+
const title = formatMessage(translation.headerFilterLabel, { column: column.label || column.path || '' });
|
|
531
|
+
const items = controller.treeItems(translation);
|
|
532
|
+
const activeKey = items.some(item => item.key === controller.activeItem) ? controller.activeItem : items[0]?.key;
|
|
533
|
+
const truncated = !useTree && visible.length > shown.length;
|
|
534
|
+
return html `
|
|
535
|
+
<div
|
|
536
|
+
class="header-filter"
|
|
537
|
+
part="header-filter"
|
|
538
|
+
.popover=${'manual'}
|
|
539
|
+
role="dialog"
|
|
540
|
+
aria-modal="true"
|
|
541
|
+
aria-label=${title}
|
|
542
|
+
@keydown=${controller.onKeyDown}>
|
|
543
|
+
<input
|
|
544
|
+
class="header-filter-search"
|
|
545
|
+
type="search"
|
|
546
|
+
autocomplete="off"
|
|
547
|
+
placeholder=${translation.searchPlaceholder}
|
|
548
|
+
aria-label=${translation.headerFilterSearchLabel}
|
|
549
|
+
.value=${live(state.search)}
|
|
550
|
+
@keydown=${controller.onSearchKeyDown}
|
|
551
|
+
@input=${(event) => controller.setSearch(event.target.value, translation)}>
|
|
552
|
+
<div class="header-filter-select-all">
|
|
553
|
+
${checkbox(controller.stateOf(scope), searching ? formatMessage(translation.selectAllResults, { count: String(scope.length) }) : translation.selectAll, undefined, checked => controller.setSelected(scope, checked))}
|
|
554
|
+
</div>
|
|
555
|
+
<ul
|
|
556
|
+
class="header-filter-list"
|
|
557
|
+
role="tree"
|
|
558
|
+
aria-multiselectable="true"
|
|
559
|
+
aria-label=${title}
|
|
560
|
+
aria-describedby=${truncated ? 'header-filter-note' : nothing}
|
|
561
|
+
@keydown=${controller.onTreeKeyDown}>
|
|
562
|
+
${map(items, item => renderTreeItem(controller, item, item.key === activeKey))}
|
|
563
|
+
</ul>
|
|
564
|
+
${truncated
|
|
565
|
+
? html `<p class="header-filter-note" id="header-filter-note">${formatMessage(translation.headerFilterTruncated, {
|
|
566
|
+
shown: String(shown.length),
|
|
567
|
+
count: String(visible.length),
|
|
568
|
+
})}</p>`
|
|
569
|
+
: nothing}
|
|
570
|
+
<div class="visually-hidden" role="status" aria-live="polite">${controller.searchAnnouncement}</div>
|
|
571
|
+
<div class="header-filter-actions">
|
|
572
|
+
<button class="header-filter-clear" type="button" @click=${() => controller.clearColumn()}>${translation.filterClear}</button>
|
|
573
|
+
<span class="header-filter-spacer"></span>
|
|
574
|
+
<button class="header-filter-ok" type="button" @click=${() => controller.apply()}>${translation.ok}</button>
|
|
575
|
+
<button class="header-filter-cancel" type="button" @click=${() => controller.close(true)}>${translation.cancel}</button>
|
|
576
|
+
</div>
|
|
577
|
+
</div>`;
|
|
578
|
+
};
|
|
579
|
+
//# sourceMappingURL=header-filter.js.map
|