@trismegisto/primitives 4.0.1 → 4.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.
Files changed (142) hide show
  1. package/MIGRATION.md +14 -0
  2. package/dist/calendar-selection.d.ts +46 -0
  3. package/dist/calendar-selection.js +78 -0
  4. package/dist/calendar-selection.js.map +1 -0
  5. package/dist/command-palette.d.ts +2 -19
  6. package/dist/command-palette.js +4 -80
  7. package/dist/command-palette.js.map +1 -1
  8. package/dist/data-grid-aggregate.d.ts +46 -1
  9. package/dist/data-grid-aggregate.js +87 -22
  10. package/dist/data-grid-aggregate.js.map +1 -1
  11. package/dist/data-grid-cell-dom.d.ts +136 -0
  12. package/dist/data-grid-cell-dom.js +1054 -0
  13. package/dist/data-grid-cell-dom.js.map +1 -0
  14. package/dist/data-grid-cell-nav.d.ts +260 -0
  15. package/dist/data-grid-cell-nav.js +369 -0
  16. package/dist/data-grid-cell-nav.js.map +1 -0
  17. package/dist/data-grid-clipboard.d.ts +35 -1
  18. package/dist/data-grid-clipboard.js +155 -0
  19. package/dist/data-grid-clipboard.js.map +1 -1
  20. package/dist/data-grid-edit-history-controller.d.ts +96 -0
  21. package/dist/data-grid-edit-history-controller.js +257 -0
  22. package/dist/data-grid-edit-history-controller.js.map +1 -0
  23. package/dist/data-grid-edit-history.d.ts +77 -0
  24. package/dist/data-grid-edit-history.js +152 -0
  25. package/dist/data-grid-edit-history.js.map +1 -0
  26. package/dist/data-grid-group-levels.d.ts +234 -0
  27. package/dist/data-grid-group-levels.js +426 -0
  28. package/dist/data-grid-group-levels.js.map +1 -0
  29. package/dist/data-grid-live-controller.d.ts +96 -0
  30. package/dist/data-grid-live-controller.js +290 -0
  31. package/dist/data-grid-live-controller.js.map +1 -0
  32. package/dist/data-grid-live-dom.d.ts +38 -0
  33. package/dist/data-grid-live-dom.js +125 -0
  34. package/dist/data-grid-live-dom.js.map +1 -0
  35. package/dist/data-grid-live.d.ts +181 -0
  36. package/dist/data-grid-live.js +377 -0
  37. package/dist/data-grid-live.js.map +1 -0
  38. package/dist/data-grid-measure.d.ts +4 -1
  39. package/dist/data-grid-measure.js +5 -2
  40. package/dist/data-grid-measure.js.map +1 -1
  41. package/dist/data-grid-paste.d.ts +86 -0
  42. package/dist/data-grid-paste.js +97 -0
  43. package/dist/data-grid-paste.js.map +1 -0
  44. package/dist/data-grid-persist.d.ts +2 -0
  45. package/dist/data-grid-persist.js +10 -1
  46. package/dist/data-grid-persist.js.map +1 -1
  47. package/dist/data-grid-spreadsheet-job.d.ts +60 -0
  48. package/dist/data-grid-spreadsheet-job.js +73 -0
  49. package/dist/data-grid-spreadsheet-job.js.map +1 -0
  50. package/dist/data-grid-spreadsheet.d.ts +141 -0
  51. package/dist/data-grid-spreadsheet.js +546 -0
  52. package/dist/data-grid-spreadsheet.js.map +1 -0
  53. package/dist/data-grid.d.ts +11 -0
  54. package/dist/data-grid.js.map +1 -1
  55. package/dist/date.d.ts +6 -0
  56. package/dist/date.js +24 -14
  57. package/dist/date.js.map +1 -1
  58. package/dist/expandable-text.d.ts +93 -0
  59. package/dist/expandable-text.js +224 -0
  60. package/dist/expandable-text.js.map +1 -0
  61. package/dist/highlight.d.ts +140 -0
  62. package/dist/highlight.js +578 -0
  63. package/dist/highlight.js.map +1 -0
  64. package/dist/index.d.ts +17 -0
  65. package/dist/index.js +17 -0
  66. package/dist/index.js.map +1 -1
  67. package/dist/inline-edit.d.ts +138 -0
  68. package/dist/inline-edit.js +271 -0
  69. package/dist/inline-edit.js.map +1 -0
  70. package/dist/messages-calendar-selection.d.ts +37 -0
  71. package/dist/messages-calendar-selection.js +60 -0
  72. package/dist/messages-calendar-selection.js.map +1 -0
  73. package/dist/messages-data-grid.d.ts +119 -1
  74. package/dist/messages-data-grid.js +225 -0
  75. package/dist/messages-data-grid.js.map +1 -1
  76. package/dist/messages-expandable-text.d.ts +23 -0
  77. package/dist/messages-expandable-text.js +23 -0
  78. package/dist/messages-expandable-text.js.map +1 -0
  79. package/dist/messages-highlight.d.ts +17 -0
  80. package/dist/messages-highlight.js +16 -0
  81. package/dist/messages-highlight.js.map +1 -0
  82. package/dist/messages-inline-edit.d.ts +32 -0
  83. package/dist/messages-inline-edit.js +37 -0
  84. package/dist/messages-inline-edit.js.map +1 -0
  85. package/dist/messages-multi-date-picker.d.ts +26 -0
  86. package/dist/messages-multi-date-picker.js +42 -0
  87. package/dist/messages-multi-date-picker.js.map +1 -0
  88. package/dist/messages-phone-field.d.ts +45 -0
  89. package/dist/messages-phone-field.js +82 -0
  90. package/dist/messages-phone-field.js.map +1 -0
  91. package/dist/messages-week-picker.d.ts +22 -0
  92. package/dist/messages-week-picker.js +34 -0
  93. package/dist/messages-week-picker.js.map +1 -0
  94. package/dist/messages-year-picker.d.ts +15 -0
  95. package/dist/messages-year-picker.js +25 -0
  96. package/dist/messages-year-picker.js.map +1 -0
  97. package/dist/multi-date.d.ts +52 -0
  98. package/dist/multi-date.js +81 -0
  99. package/dist/multi-date.js.map +1 -0
  100. package/dist/phone-country-index.generated.d.ts +11 -0
  101. package/dist/phone-country-index.generated.js +313 -0
  102. package/dist/phone-country-index.generated.js.map +1 -0
  103. package/dist/phone-number.d.ts +227 -0
  104. package/dist/phone-number.js +551 -0
  105. package/dist/phone-number.js.map +1 -0
  106. package/dist/phone-plan-br.generated.d.ts +2 -0
  107. package/dist/phone-plan-br.generated.js +66 -0
  108. package/dist/phone-plan-br.generated.js.map +1 -0
  109. package/dist/phone-plan-types.d.ts +61 -0
  110. package/dist/phone-plan-types.js +10 -0
  111. package/dist/phone-plan-types.js.map +1 -0
  112. package/dist/phone-plans/africa.d.ts +2 -0
  113. package/dist/phone-plans/africa.js +712 -0
  114. package/dist/phone-plans/africa.js.map +1 -0
  115. package/dist/phone-plans/americas.d.ts +2 -0
  116. package/dist/phone-plans/americas.js +1724 -0
  117. package/dist/phone-plans/americas.js.map +1 -0
  118. package/dist/phone-plans/asia.d.ts +2 -0
  119. package/dist/phone-plans/asia.js +664 -0
  120. package/dist/phone-plans/asia.js.map +1 -0
  121. package/dist/phone-plans/europe.d.ts +2 -0
  122. package/dist/phone-plans/europe.js +1020 -0
  123. package/dist/phone-plans/europe.js.map +1 -0
  124. package/dist/phone-plans/oceania.d.ts +2 -0
  125. package/dist/phone-plans/oceania.js +274 -0
  126. package/dist/phone-plans/oceania.js.map +1 -0
  127. package/dist/phone-plans.d.ts +5 -0
  128. package/dist/phone-plans.js +42 -0
  129. package/dist/phone-plans.js.map +1 -0
  130. package/dist/secret.d.ts +5 -1
  131. package/dist/secret.js +7 -2
  132. package/dist/secret.js.map +1 -1
  133. package/dist/week.d.ts +102 -0
  134. package/dist/week.js +244 -0
  135. package/dist/week.js.map +1 -0
  136. package/dist/year-picker.d.ts +43 -0
  137. package/dist/year-picker.js +88 -0
  138. package/dist/year-picker.js.map +1 -0
  139. package/dist/zip-writer.d.ts +53 -0
  140. package/dist/zip-writer.js +227 -0
  141. package/dist/zip-writer.js.map +1 -0
  142. package/package.json +5 -4
@@ -0,0 +1,152 @@
1
+ import { gridEditInitialValue, sameGridEditValue } from './data-grid-edit';
2
+ /** Sem alteração pendente na célula (antes ou depois do passo). */
3
+ export const GRID_HISTORY_UNSET = Symbol('hm-grid-history-unset');
4
+ /** Limite de passos (os mais antigos saem). */
5
+ export const GRID_EDIT_HISTORY_LIMIT = 100;
6
+ export const EMPTY_GRID_EDIT_HISTORY = { undo: [], redo: [] };
7
+ /**
8
+ * As células cuja alteração pendente mudou entre `prev` e `next` (valor novo, pendência que entrou ou saiu), com o antes
9
+ * e o depois. Linhas com o mesmo mapa nos dois lados são puladas sem custo.
10
+ */
11
+ export function gridPendingDiff(prev, next) {
12
+ if (prev === next)
13
+ return [];
14
+ const cells = [];
15
+ for (const [rowId, after] of next) {
16
+ const before = prev.get(rowId);
17
+ if (before === after)
18
+ continue;
19
+ for (const [key, value] of after) {
20
+ const had = before?.has(key) ?? false;
21
+ const old = had ? before.get(key) : GRID_HISTORY_UNSET;
22
+ if (!had || !sameGridEditValue(old, value))
23
+ cells.push({ rowId, key, before: old, after: value });
24
+ }
25
+ if (before)
26
+ for (const [key, value] of before)
27
+ if (!after.has(key))
28
+ cells.push({ rowId, key, before: value, after: GRID_HISTORY_UNSET });
29
+ }
30
+ for (const [rowId, before] of prev) {
31
+ if (next.has(rowId))
32
+ continue;
33
+ for (const [key, value] of before)
34
+ cells.push({ rowId, key, before: value, after: GRID_HISTORY_UNSET });
35
+ }
36
+ return cells;
37
+ }
38
+ /**
39
+ * Monta o passo das células (`null` sem nenhuma), guardando a origem de cada uma: `find` dá a linha em `rows` e
40
+ * `column` a coluna (sem ela, a célula não é conferida na invalidação).
41
+ */
42
+ export function createGridHistoryStep(cells, find, column, first) {
43
+ if (cells.length === 0)
44
+ return null;
45
+ const rows = new Map();
46
+ const origins = new Map();
47
+ for (const cell of cells) {
48
+ let row = rows.get(cell.rowId);
49
+ if (!rows.has(cell.rowId)) {
50
+ row = find(cell.rowId);
51
+ rows.set(cell.rowId, row);
52
+ }
53
+ const col = column(cell.key);
54
+ if (!col || row === null || row === undefined)
55
+ continue;
56
+ let byKey = origins.get(cell.rowId);
57
+ if (!byKey)
58
+ origins.set(cell.rowId, (byKey = new Map()));
59
+ if (!byKey.has(cell.key))
60
+ byKey.set(cell.key, gridEditInitialValue(col, row));
61
+ }
62
+ return { cells, first: first ?? { rowId: cells[0].rowId, key: cells[0].key }, rows, origins };
63
+ }
64
+ /** Empilha um passo (o refazer se esvazia), mantendo no máximo `limit` passos. */
65
+ export function pushGridHistoryStep(history, step, limit = GRID_EDIT_HISTORY_LIMIT) {
66
+ const undo = history.undo.length >= limit ? history.undo.slice(history.undo.length - limit + 1) : history.undo.slice();
67
+ undo.push(step);
68
+ return { undo, redo: [] };
69
+ }
70
+ /** Aplica um lado do passo às alterações pendentes (uma cópia por linha tocada, não por célula). */
71
+ export function applyGridHistoryCells(pending, cells, side) {
72
+ const next = new Map(pending);
73
+ const copied = new Map();
74
+ for (const cell of cells) {
75
+ let row = copied.get(cell.rowId);
76
+ if (!row) {
77
+ row = new Map(next.get(cell.rowId) ?? []);
78
+ copied.set(cell.rowId, row);
79
+ }
80
+ const value = side === 'before' ? cell.before : cell.after;
81
+ if (value === GRID_HISTORY_UNSET)
82
+ row.delete(cell.key);
83
+ else
84
+ row.set(cell.key, value);
85
+ }
86
+ for (const [rowId, row] of copied) {
87
+ if (row.size > 0)
88
+ next.set(rowId, row);
89
+ else
90
+ next.delete(rowId);
91
+ }
92
+ return next;
93
+ }
94
+ /** Desfaz o último passo: as células voltam ao pendente de antes; o passo vai para o refazer. `null` sem passo. */
95
+ export function undoGridHistory(history, pending) {
96
+ const step = history.undo.at(-1);
97
+ if (!step)
98
+ return null;
99
+ return {
100
+ step,
101
+ pending: applyGridHistoryCells(pending, step.cells, 'before'),
102
+ history: { undo: history.undo.slice(0, -1), redo: [...history.redo, step] },
103
+ };
104
+ }
105
+ /** Refaz o último passo desfeito. `null` sem passo. */
106
+ export function redoGridHistory(history, pending) {
107
+ const step = history.redo.at(-1);
108
+ if (!step)
109
+ return null;
110
+ return {
111
+ step,
112
+ pending: applyGridHistoryCells(pending, step.cells, 'after'),
113
+ history: { undo: [...history.undo, step], redo: history.redo.slice(0, -1) },
114
+ };
115
+ }
116
+ /** Conta as células de um passo. */
117
+ export function gridHistoryStepSize(step) {
118
+ return step.cells.length;
119
+ }
120
+ /** A origem de alguma célula do passo mudou (ou a linha saiu de `rows`)? Linha com o mesmo objeto é pulada. */
121
+ function stepIsStale(step, find, column) {
122
+ for (const [rowId, before] of step.rows) {
123
+ const row = find(rowId);
124
+ if (row === before)
125
+ continue;
126
+ if (row === null || row === undefined)
127
+ return true;
128
+ const origins = step.origins.get(rowId);
129
+ if (!origins)
130
+ continue;
131
+ for (const [key, origin] of origins) {
132
+ const col = column(key);
133
+ if (col && !sameGridEditValue(gridEditInitialValue(col, row), origin))
134
+ return true;
135
+ }
136
+ }
137
+ return false;
138
+ }
139
+ /**
140
+ * Tira dos dois lados do histórico os passos com alguma célula cuja origem mudou na remessa nova de `rows` (ou cuja linha
141
+ * saiu). `removed` = quantos passos saíram; o histórico volta o mesmo objeto quando nada mudou.
142
+ */
143
+ export function staleGridHistory(history, find, column) {
144
+ if (history.undo.length === 0 && history.redo.length === 0)
145
+ return { history, removed: 0 };
146
+ const keep = (step) => !stepIsStale(step, find, column);
147
+ const undo = history.undo.filter(keep);
148
+ const redo = history.redo.filter(keep);
149
+ const removed = history.undo.length - undo.length + history.redo.length - redo.length;
150
+ return removed === 0 ? { history, removed } : { history: { undo, redo }, removed };
151
+ }
152
+ //# sourceMappingURL=data-grid-edit-history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-grid-edit-history.js","sourceRoot":"","sources":["../src/data-grid-edit-history.ts"],"names":[],"mappings":"AAWA,OAAO,EAAwB,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAEjG,mEAAmE;AACnE,MAAM,CAAC,MAAM,kBAAkB,GAAkB,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAEjF,+CAA+C;AAC/C,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AA0B3C,MAAM,CAAC,MAAM,uBAAuB,GAAoB,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AAE/E;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAqB,EAAE,IAAqB;IAC1E,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAsB,EAAE,CAAC;IACpC,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;QAClC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC/B,IAAI,MAAM,KAAK,KAAK;YAAE,SAAS;QAC/B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,KAAK,EAAE,CAAC;Y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,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACzE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACvC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACtF,OAAO,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC;AACrF,CAAC"}
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Agrupamento em vários níveis do `hm-data-grid` (`groupLevels`, até 4), a parte pura: a árvore de grupos (uma passada
3
+ * por nível, ordem estável), a ordem dos grupos (a direção da ordenação ativa da coluna do nível, ou crescente pelo
4
+ * `raw`, com o grupo vazio sempre por último), o que a página desenha (cabeçalhos, linhas e subtotais, com a
5
+ * continuação do grupo que veio da página anterior), o recolhido por caminho, a navegação do modo grade e o esboço de
6
+ * tópicos da planilha. Sem DOM nem framework; fora do barrel raiz (importe `@trismegisto/primitives/data-grid-group-levels`).
7
+ *
8
+ * As funções de um nível (`data-grid-group`) não mudam: o `groupBy` sozinho continua por elas.
9
+ */
10
+ import { type GridColumn, type GridSort } from './data-grid';
11
+ import { type GridCellGroups } from './data-grid-cell-nav';
12
+ import type { GridSummaryCell } from './data-grid-aggregate';
13
+ import { type PluralMessage } from './i18n';
14
+ /** Máximo de níveis (decisão 4 da especificação). */
15
+ export declare const GRID_GROUP_MAX_LEVELS = 4;
16
+ /** Um grupo de um nível, com os filhos (vazio no último nível) e todas as linhas dele, na ordem da tela. */
17
+ export interface GridGroupNode<T> {
18
+ /** Identidade estável: os valores dos níveis até este (`gridGroupPath`). Sobrevive a remessas novas. */
19
+ readonly path: string;
20
+ readonly keys: readonly string[];
21
+ /** 1 = primeiro nível. */
22
+ readonly level: number;
23
+ readonly column: GridColumn<T>;
24
+ /** Chave do valor neste nível (`gridGroupKey` do `raw`). */
25
+ readonly key: string;
26
+ /** Texto do valor (o `value` da primeira linha); vazio no grupo "(vazio)". */
27
+ readonly label: string;
28
+ readonly empty: boolean;
29
+ readonly rows: readonly T[];
30
+ /** Posição da primeira linha do grupo na lista achatada (`GridGroupTree.rows`). */
31
+ readonly start: number;
32
+ readonly children: readonly GridGroupNode<T>[];
33
+ readonly parent: GridGroupNode<T> | null;
34
+ /** Posição entre os irmãos (1…) e quantos irmãos há (`aria-posinset`/`aria-setsize`). */
35
+ readonly posinset: number;
36
+ readonly setsize: number;
37
+ }
38
+ export interface GridGroupTree<T> {
39
+ readonly levels: readonly GridColumn<T>[];
40
+ readonly roots: readonly GridGroupNode<T>[];
41
+ /** Todas as linhas na ordem dos grupos (o que a paginação corta). */
42
+ readonly rows: readonly T[];
43
+ /** Grupo mais interno de cada linha, pela posição em `rows`. */
44
+ readonly leaves: readonly GridGroupNode<T>[];
45
+ /** Posição de uma linha em `rows` (o índice é montado no primeiro uso). */
46
+ positionOf(row: T): number | undefined;
47
+ readonly byPath: ReadonlyMap<string, GridGroupNode<T>>;
48
+ }
49
+ /** Árvore sem níveis: as linhas como vieram, sem grupos. */
50
+ export declare function emptyGridGroupTree<T>(rows?: readonly T[]): GridGroupTree<T>;
51
+ /** Caminho de um grupo: os valores dos níveis, do primeiro até ele. É o que `groupCollapsed` guarda. */
52
+ export declare function gridGroupPath(keys: readonly string[]): string;
53
+ export type GridGroupWarning = 'levels-win' | 'too-many-levels' | 'custom-wins';
54
+ /** Texto dos avisos de desenvolvimento (uma vez por instância). */
55
+ export declare const GRID_GROUP_WARNING_TEXT: Readonly<Record<GridGroupWarning, string>>;
56
+ /** As colunas dos níveis (chaves desconhecidas e repetidas saem; no máximo 4) e os avisos da combinação de opções. */
57
+ export declare function gridGroupLevelColumns<T>(levels: readonly string[], columns: readonly GridColumn<T>[], groupBy?: string | null): {
58
+ readonly columns: readonly GridColumn<T>[];
59
+ readonly warnings: readonly GridGroupWarning[];
60
+ };
61
+ export interface GridGroupTreeOptions {
62
+ /** Ordenação ativa: um nível cuja coluna está nela segue a direção dela. */
63
+ readonly sort?: readonly GridSort[];
64
+ /** Idioma da comparação de texto. */
65
+ readonly locale?: string;
66
+ }
67
+ /**
68
+ * Agrupa `rows` (já filtradas e ordenadas) pelos níveis: o primeiro divide as linhas, cada grupo é dividido pelo
69
+ * segundo, e assim por diante. Dentro do último nível as linhas mantêm a ordem recebida (a ordenação ativa). Uma
70
+ * passada por nível, com uma ordenação dos grupos de cada divisão.
71
+ */
72
+ export declare function groupGridRowsByLevels<T>(rows: readonly T[], levels: readonly GridColumn<T>[], options?: GridGroupTreeOptions): GridGroupTree<T>;
73
+ /** Grupos do nível `level` (1…), na ordem da tela. */
74
+ export declare function gridGroupNodesAt<T>(tree: GridGroupTree<T>, level: number): GridGroupNode<T>[];
75
+ /** Do primeiro nível até o grupo. */
76
+ export declare function gridGroupChain<T>(node: GridGroupNode<T>): GridGroupNode<T>[];
77
+ export declare function toggleGridGroupPath(collapsed: readonly string[], path: string, expand?: boolean): readonly string[];
78
+ /** Recolhe todos os grupos de todos os níveis. */
79
+ export declare function collapseAllGridGroupPaths<T>(tree: GridGroupTree<T>): readonly string[];
80
+ /** Recolhe os grupos de um nível inteiro (os outros ficam como estão). */
81
+ export declare function collapseGridGroupLevel<T>(tree: GridGroupTree<T>, level: number, collapsed: readonly string[]): readonly string[];
82
+ /** Expande os caminhos dados (o `*` sobre os irmãos). */
83
+ export declare function expandGridGroupPaths(collapsed: readonly string[], paths: readonly string[]): readonly string[];
84
+ /** Uma linha desenhada do corpo agrupado. `index` = posição da linha de dados na página (a seleção com Shift usa). */
85
+ export type GridGroupLine<T> = {
86
+ readonly kind: 'group';
87
+ readonly node: GridGroupNode<T>;
88
+ readonly collapsed: boolean;
89
+ readonly continued: boolean;
90
+ } | {
91
+ readonly kind: 'row';
92
+ readonly row: T;
93
+ readonly index: number;
94
+ readonly node: GridGroupNode<T>;
95
+ } | {
96
+ readonly kind: 'subtotal';
97
+ readonly node: GridGroupNode<T>;
98
+ };
99
+ export interface GridGroupLinesOptions {
100
+ /** Subtotais no fim de cada grupo (`groupTotals="footer"`); no cabeçalho, não há linha própria. */
101
+ readonly footer?: boolean;
102
+ /** Posição provável da primeira linha da página em `tree.rows` (a página corta a lista achatada); conferida. */
103
+ readonly offset?: number;
104
+ }
105
+ /**
106
+ * As linhas que a página desenha, na ordem: o cabeçalho de cada grupo antes das linhas dele (o primeiro grupo de uma
107
+ * página que continua da anterior vem com `continued`), as linhas dos grupos abertos e, com `footer`, a linha de
108
+ * subtotal no fim de cada grupo que termina nesta página. Um grupo recolhido mostra só o cabeçalho.
109
+ */
110
+ export declare function gridGroupLines<T>(tree: GridGroupTree<T>, pageRows: readonly T[], collapsed: ReadonlySet<string>, options?: GridGroupLinesOptions): GridGroupLine<T>[];
111
+ /** Chave estável de cada linha (`g:` grupo, `r:` dado, `s:` subtotal): a da rolagem virtual e do `track`. */
112
+ export declare function gridGroupLineKey<T>(line: GridGroupLine<T>, rowId: (row: T) => string): string;
113
+ /** Linhas de dados desenhadas, na ordem da tela (o que o modo grade percorre). */
114
+ export declare function gridGroupLineRows<T>(lines: readonly GridGroupLine<T>[]): T[];
115
+ /** Um `<tbody>` por grupo do primeiro nível: as linhas dele (já montadas por `map`). */
116
+ export interface GridGroupBody<L> {
117
+ /** Caminho do grupo do primeiro nível. */
118
+ readonly key: string;
119
+ readonly collapsed: boolean;
120
+ readonly lines: L[];
121
+ }
122
+ /**
123
+ * Reparte as linhas em `<tbody>` pelo grupo do primeiro nível. `range` (rolagem virtual) limita às linhas da janela:
124
+ * um grupo cortado pela janela traz só o trecho dela.
125
+ */
126
+ export declare function gridGroupBodies<T, L>(lines: readonly GridGroupLine<T>[], collapsed: ReadonlySet<string>, map: (line: GridGroupLine<T>, position: number) => L, range?: {
127
+ readonly start: number;
128
+ readonly end: number;
129
+ } | null): GridGroupBody<L>[];
130
+ /** Textos do agrupamento em níveis (do `HERMES_MESSAGES.dataGrid` e do catálogo da pasta). */
131
+ export interface GridGroupLevelTexts {
132
+ /** `{column}`, `{group}` (o rótulo de um nível). */
133
+ readonly groupLabel: string;
134
+ readonly groupEmpty: string;
135
+ readonly groupCount: PluralMessage;
136
+ /** `{level}`, `{levels}`. */
137
+ readonly groupLevel: string;
138
+ /** `{parent}`, `{label}`: junta os rótulos dos níveis no caminho. */
139
+ readonly groupPath: string;
140
+ /** `{label}`: o grupo que continua da página anterior. */
141
+ readonly groupContinued: string;
142
+ /** `{count}`: contagem com dado parcial (`hasMore`). */
143
+ readonly groupPartial: string;
144
+ /** Nome do botão: `{path}`, `{count}`. */
145
+ readonly groupCollapse: string;
146
+ readonly groupExpand: string;
147
+ /** Rótulo da linha de subtotal: `{group}`. */
148
+ readonly subtotal: string;
149
+ }
150
+ export interface GridGroupViewContext<T> {
151
+ readonly texts: GridGroupLevelTexts;
152
+ readonly locale: string;
153
+ /** Quantos níveis há. */
154
+ readonly levels: number;
155
+ /** Dado parcial (`hasMore`): a contagem ganha a marca. */
156
+ readonly partial: boolean;
157
+ /** Subtotais no rodapé de cada grupo (`groupTotals="footer"`). */
158
+ readonly footer: boolean;
159
+ /** Resumos de um grupo (com cache por grupo). */
160
+ readonly summaries: (node: GridGroupNode<T>) => ReadonlyMap<string, GridSummaryCell>;
161
+ }
162
+ /** Cabeçalho de grupo pronto para desenhar. */
163
+ export interface GridGroupHeaderView {
164
+ readonly kind: 'group';
165
+ readonly key: string;
166
+ /** `rowId` da linha nas referências do modo grade. */
167
+ readonly navId: string;
168
+ readonly path: string;
169
+ readonly level: number;
170
+ /** Recuo (níveis acima deste), para `--hm-data-grid-group-level`. */
171
+ readonly indent: number;
172
+ readonly posinset: number;
173
+ readonly setsize: number;
174
+ readonly collapsed: boolean;
175
+ /** "Coluna: valor", com a marca de continuação. */
176
+ readonly label: string;
177
+ readonly countText: string;
178
+ /** Texto oculto: "nível {level} de {levels}". */
179
+ readonly levelText: string;
180
+ /** Nome do botão: "Recolher grupo {path}, {count}". */
181
+ readonly toggleLabel: string;
182
+ /** Subtotais no cabeçalho (`groupTotals="header"`, ou o grupo recolhido); `null` = sem. */
183
+ readonly summaries: ReadonlyMap<string, GridSummaryCell> | null;
184
+ }
185
+ /** Linha de subtotal no fim do grupo (`groupTotals="footer"`). */
186
+ export interface GridGroupSubtotalView {
187
+ readonly kind: 'subtotal';
188
+ readonly key: string;
189
+ readonly path: string;
190
+ readonly indent: number;
191
+ readonly label: string;
192
+ readonly summaries: ReadonlyMap<string, GridSummaryCell>;
193
+ }
194
+ /** "Região: Sul, Estado: PR": os rótulos do primeiro nível até o grupo. */
195
+ export declare function gridGroupPathText<T>(node: GridGroupNode<T>, texts: GridGroupLevelTexts): string;
196
+ export declare function gridGroupHeaderView<T>(line: Extract<GridGroupLine<T>, {
197
+ kind: 'group';
198
+ }>, context: GridGroupViewContext<T>): GridGroupHeaderView;
199
+ export declare function gridGroupSubtotalView<T>(line: Extract<GridGroupLine<T>, {
200
+ kind: 'subtotal';
201
+ }>, context: GridGroupViewContext<T>): GridGroupSubtotalView;
202
+ /** Uma entrada da navegação: cabeçalho de grupo ou linha de dados, na ordem da tela. */
203
+ export type GridGroupNavEntry = {
204
+ readonly kind: 'group';
205
+ readonly path: string;
206
+ readonly level: number;
207
+ readonly expanded: boolean;
208
+ readonly parent: string | null;
209
+ } | {
210
+ readonly kind: 'row';
211
+ readonly id: string;
212
+ readonly group: string;
213
+ };
214
+ /**
215
+ * A estrutura que o controlador do modo grade usa para as linhas de grupo (`treegrid`). `levels` = quantos níveis
216
+ * (as linhas de dados ficam com `aria-level` = níveis + 1).
217
+ */
218
+ export declare function gridGroupNav(entries: readonly GridGroupNavEntry[], levels: number, actions: Pick<GridCellGroups, 'toggle' | 'expandSiblings'>): GridCellGroups;
219
+ /** Entradas da navegação a partir das linhas desenhadas (os subtotais não entram). */
220
+ export declare function gridGroupNavEntries<T>(lines: readonly GridGroupLine<T>[], rowId: (row: T) => string): GridGroupNavEntry[];
221
+ /** Um cabeçalho de grupo na planilha: entra antes da linha de dados `before` (posição em `rows`). */
222
+ export interface GridGroupSheetHeader {
223
+ readonly before: number;
224
+ readonly level: number;
225
+ readonly label: string;
226
+ readonly totals?: ReadonlyMap<string, {
227
+ readonly value: number | null;
228
+ readonly text?: string;
229
+ }>;
230
+ }
231
+ /** Os cabeçalhos de grupo da planilha (todos os grupos, abertos ou recolhidos na tela), na ordem. */
232
+ export declare function gridGroupSheetHeaders<T>(tree: GridGroupTree<T>, label: (node: GridGroupNode<T>) => string, totals?: (node: GridGroupNode<T>) => GridGroupSheetHeader['totals']): GridGroupSheetHeader[];
233
+ /** O rótulo de um grupo na planilha: "Coluna: valor" (a contagem a planilha mostra pelos tópicos). */
234
+ export declare function gridGroupSheetLabel<T>(node: GridGroupNode<T>, texts: Pick<GridGroupLevelTexts, 'groupLabel' | 'groupEmpty'>): string;