@proef/common-ui 2.6.29 → 2.6.30

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.
@@ -1,10 +1,33 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
- import { useState, useRef, useEffect, useMemo, useCallback, useLayoutEffect, Fragment as Fragment$1 } from "react";
2
+ import { useState, useRef, useEffect, useMemo, useCallback, useLayoutEffect, useSyncExternalStore, Fragment as Fragment$1, memo } from "react";
3
3
  import { CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, LayersIcon, CloseIcon, ChevronUpIcon, ChevronsUpDownIcon, FilterIcon } from "../../../foundations/icons/icons.js";
4
4
  import { ColumnFilter } from "./ColumnFilter.js";
5
5
  import { OverlayScrollbar } from "./OverlayScrollbar.js";
6
6
  import { DEFAULT_TABLE_LABELS } from "./labels.js";
7
7
  const comparador = new Intl.Collator();
8
+ const JANELA_MINIMO_LINHAS = 24;
9
+ const JANELA_MARGEM_LINHAS = 30;
10
+ const JANELA_PASSO_LINHAS = 30;
11
+ const JANELA_PREENCHER_LINHAS = 15;
12
+ const ECRA_ESTREITO = "(max-width: 1023.98px)";
13
+ const temMatchMedia = () => typeof window !== "undefined" && typeof window.matchMedia === "function";
14
+ const subscreverEcraEstreito = (aviso) => {
15
+ if (!temMatchMedia()) return () => {
16
+ };
17
+ const m = window.matchMedia(ECRA_ESTREITO);
18
+ m.addEventListener("change", aviso);
19
+ return () => m.removeEventListener("change", aviso);
20
+ };
21
+ const ecraEstreitoAgora = () => temMatchMedia() && window.matchMedia(ECRA_ESTREITO).matches;
22
+ function useEcraEstreito() {
23
+ return useSyncExternalStore(subscreverEcraEstreito, ecraEstreitoAgora, () => false);
24
+ }
25
+ const LinhaCorpo = memo(
26
+ function LinhaCorpo2({ conteudo }) {
27
+ return /* @__PURE__ */ jsx(Fragment, { children: conteudo() });
28
+ },
29
+ (antes, depois) => antes.dados === depois.dados && antes.seleccionada === depois.seleccionada && antes.versao === depois.versao && antes.colunas === depois.colunas && antes.classeExtra === depois.classeExtra
30
+ );
8
31
  const MOLA_RIGIDEZ = 1200;
9
32
  const MOLA_AMORTECIMENTO = 2 * Math.sqrt(MOLA_RIGIDEZ);
10
33
  const PERTO_DE_ASSENTAR = 6;
@@ -41,10 +64,16 @@ function TableBase({
41
64
  clearSelectionTrigger,
42
65
  onAllDataNeeded: onDataNeeded,
43
66
  alwaysClient,
67
+ serverSide: noServidor = false,
68
+ onStateChange: onEstadoMudou,
44
69
  defaultSortColumn: defaultSortCol,
45
70
  defaultSortDirection: defaultSortDir,
46
71
  viewRef,
47
72
  fillHeight: preencheAltura = false,
73
+ filterableColumns: colunasFiltraveis,
74
+ onFiltersChange: onFiltros,
75
+ hideFilterChips: semFaixaFiltros = false,
76
+ clientPage: paginaCliente,
48
77
  onVisibleChange: onVista,
49
78
  frozenColumns: colunasFixas = 0,
50
79
  onMoveColumn: onMoverColuna,
@@ -106,7 +135,16 @@ function TableBase({
106
135
  });
107
136
  const [groupByKeys, setGroupByKeys] = useState([]);
108
137
  const [collapsedGroups, setCollapsedGroups] = useState(/* @__PURE__ */ new Set());
109
- const [internalPage, setInternalPage] = useState(1);
138
+ const [paginaPropria, setPaginaPropria] = useState(1);
139
+ const internalPage = paginaCliente ? paginaCliente.page : paginaPropria;
140
+ const setInternalPage = (p) => {
141
+ if (!paginaCliente) {
142
+ setPaginaPropria(p);
143
+ return;
144
+ }
145
+ const nova = typeof p === "function" ? p(paginaCliente.page) : p;
146
+ if (nova !== paginaCliente.page) paginaCliente.onPageChange(nova);
147
+ };
110
148
  const [openFilterCol, setOpenFilterCol] = useState(null);
111
149
  const [ancoraFiltro, setAncoraFiltro] = useState(null);
112
150
  const [selectedKeys, setSelectedKeys] = useState(/* @__PURE__ */ new Set());
@@ -119,15 +157,19 @@ function TableBase({
119
157
  sessionStorage.setItem(`dt_numfilters_${storageKey}`, JSON.stringify(numFilters));
120
158
  }, [columnFilters, dateFilters, numFilters, storageKey]);
121
159
  const resolveValueFn = (colKey) => {
122
- const col = columns.find((c) => c.key === colKey);
160
+ const fonte = colunasFiltraveis ?? columns;
161
+ const col = fonte.find((c) => c.key === colKey);
123
162
  if (col?.value) return col.value;
124
- for (const c of columns) {
163
+ for (const c of fonte) {
125
164
  const ef = c.extraFilters?.find((f) => f.key === colKey);
126
165
  if (ef) return ef.value;
127
166
  }
128
167
  return void 0;
129
168
  };
130
169
  const getUniqueValues = (colKey) => {
170
+ if (noServidor) {
171
+ return columns.find((c) => c.key === colKey)?.filterOptions ?? [];
172
+ }
131
173
  const valueFn = resolveValueFn(colKey);
132
174
  if (!valueFn) return [];
133
175
  let source = allData ?? data;
@@ -171,7 +213,7 @@ function TableBase({
171
213
  () => Object.values(columnFilters).some((s) => s?.size > 0) || Object.values(dateFilters).some(dateFilterActive) || Object.values(numFilters).some(numFilterActive),
172
214
  [columnFilters, dateFilters, numFilters]
173
215
  );
174
- const isClientMode = !!allData && (alwaysClient || hasActiveFilters || !!sortCol || isGrouped);
216
+ const isClientMode = !noServidor && !!allData && (alwaysClient || hasActiveFilters || !!sortCol || isGrouped);
175
217
  const effectiveData = isClientMode ? allData : data;
176
218
  useEffect(() => {
177
219
  setInternalPage(1);
@@ -188,7 +230,7 @@ function TableBase({
188
230
  onSelectionChange?.(/* @__PURE__ */ new Set());
189
231
  }, [chaveFiltrosCol]);
190
232
  useEffect(() => {
191
- if (!allData && (hasActiveFilters || sortCol || isGrouped)) onDataNeeded?.();
233
+ if (!noServidor && !allData && (hasActiveFilters || sortCol || isGrouped)) onDataNeeded?.();
192
234
  }, [allData, hasActiveFilters, sortCol, isGrouped]);
193
235
  const sortColAtual = sortCol, sortDirAtual = sortDir;
194
236
  const filtrosDeColuna = columnFilters, filtrosDeData = dateFilters, filtrosNumericos = numFilters;
@@ -244,8 +286,37 @@ function TableBase({
244
286
  }
245
287
  return result;
246
288
  };
247
- const sortedData = useMemo(() => sortRows(effectiveData), [effectiveData, sortCol, sortDir, colunasBase]);
248
- const filteredData = useMemo(() => filterRows(sortedData), [sortedData, columnFilters, dateFilters, numFilters]);
289
+ const sortedData = useMemo(
290
+ () => noServidor ? effectiveData : sortRows(effectiveData),
291
+ [effectiveData, sortCol, sortDir, colunasBase, noServidor]
292
+ );
293
+ const filteredData = useMemo(
294
+ () => noServidor ? sortedData : filterRows(sortedData),
295
+ [sortedData, columnFilters, dateFilters, numFilters, noServidor]
296
+ );
297
+ const linhasDosTotais = isClientMode ? filteredData : allData ?? filteredData;
298
+ const estadoDaVista = () => ({
299
+ columnFilters: Object.fromEntries(
300
+ Object.entries(columnFilters).filter(([, v]) => v?.size).map(([k, v]) => [k, [...v]])
301
+ ),
302
+ dateFilters: Object.fromEntries(Object.entries(dateFilters).filter(([, r]) => dateFilterActive(r))),
303
+ numFilters: Object.fromEntries(Object.entries(numFilters).filter(([, r]) => numFilterActive(r))),
304
+ sortCol,
305
+ sortDir,
306
+ groupBy: groupByKeys
307
+ });
308
+ const estadoAnterior = useRef(null);
309
+ useEffect(() => {
310
+ if (!onEstadoMudou) return;
311
+ const actual = JSON.stringify(estadoDaVista());
312
+ if (estadoAnterior.current === null) {
313
+ estadoAnterior.current = actual;
314
+ return;
315
+ }
316
+ if (estadoAnterior.current === actual) return;
317
+ estadoAnterior.current = actual;
318
+ onEstadoMudou(estadoDaVista());
319
+ }, [columnFilters, dateFilters, numFilters, sortCol, sortDir, groupByKeys]);
249
320
  useEffect(() => {
250
321
  if (!viewRef) return;
251
322
  viewRef.current = {
@@ -259,16 +330,7 @@ function TableBase({
259
330
  rows: filteredData,
260
331
  hasFilters: hasActiveFilters,
261
332
  needsAllData: hasActiveFilters || !!sortCol || isGrouped,
262
- getState: () => ({
263
- columnFilters: Object.fromEntries(
264
- Object.entries(columnFilters).filter(([, v]) => v?.size).map(([k, v]) => [k, [...v]])
265
- ),
266
- dateFilters: Object.fromEntries(Object.entries(dateFilters).filter(([, r]) => dateFilterActive(r))),
267
- numFilters: Object.fromEntries(Object.entries(numFilters).filter(([, r]) => numFilterActive(r))),
268
- sortCol,
269
- sortDir,
270
- groupBy: groupByKeys
271
- }),
333
+ getState: estadoDaVista,
272
334
  restore: (e) => {
273
335
  setColumnFilters(Object.fromEntries(Object.entries(e?.columnFilters ?? {}).map(([k, v]) => [k, new Set(v)])));
274
336
  setDateFilters(e?.dateFilters ?? {});
@@ -278,12 +340,28 @@ function TableBase({
278
340
  setGroupByKeys(e?.groupBy ?? []);
279
341
  setCollapsedGroups(/* @__PURE__ */ new Set());
280
342
  const precisaTudo = !!e?.sortCol || !!e?.groupBy?.length || Object.keys(e?.columnFilters ?? {}).length > 0 || Object.keys(e?.dateFilters ?? {}).length > 0;
281
- if (precisaTudo && !allData) onDataNeeded?.();
343
+ if (!noServidor && precisaTudo && !allData) onDataNeeded?.();
344
+ },
345
+ setFilters: (f) => {
346
+ setColumnFilters(Object.fromEntries(Object.entries(f.columnFilters ?? {}).filter(([, v]) => v?.length).map(([k, v]) => [k, new Set(v)])));
347
+ setDateFilters(Object.fromEntries(Object.entries(f.dateFilters ?? {}).filter(([, r]) => dateFilterActive(r))));
348
+ setNumFilters(Object.fromEntries(Object.entries(f.numFilters ?? {}).filter(([, r]) => numFilterActive(r))));
349
+ const algum = Object.values(f.columnFilters ?? {}).some((v) => v?.length) || Object.values(f.dateFilters ?? {}).some(dateFilterActive) || Object.values(f.numFilters ?? {}).some(numFilterActive);
350
+ if (algum && !allData) onDataNeeded?.();
282
351
  }
283
352
  };
284
353
  });
354
+ const onFiltrosRef = useRef(onFiltros);
355
+ onFiltrosRef.current = onFiltros;
356
+ useEffect(() => {
357
+ onFiltrosRef.current?.({
358
+ columnFilters: Object.fromEntries(Object.entries(columnFilters).filter(([, v]) => v?.size).map(([k, v]) => [k, [...v]])),
359
+ dateFilters: Object.fromEntries(Object.entries(dateFilters).filter(([, r]) => dateFilterActive(r))),
360
+ numFilters: Object.fromEntries(Object.entries(numFilters).filter(([, r]) => numFilterActive(r)))
361
+ });
362
+ }, [columnFilters, dateFilters, numFilters]);
285
363
  const toggleGroup = (colKey) => {
286
- if (!allData) onDataNeeded?.();
364
+ if (!noServidor && !allData) onDataNeeded?.();
287
365
  setGroupByKeys(
288
366
  (prev) => prev.includes(colKey) ? prev.filter((k) => k !== colKey) : [...prev, colKey]
289
367
  );
@@ -666,24 +744,28 @@ function TableBase({
666
744
  ] }, node.path);
667
745
  });
668
746
  };
669
- const aCarregar = isLoading || (isAllDataLoading || !allData) && (hasActiveFilters || !!sortCol || isGrouped);
747
+ const aCarregar = isLoading || !noServidor && (isAllDataLoading || !allData) && (hasActiveFilters || !!sortCol || isGrouped);
670
748
  const internalTotalPages = pageSize && isClientMode && !isGrouped ? Math.max(1, Math.ceil(filteredData.length / pageSize)) : 1;
671
749
  useEffect(() => {
672
750
  setInternalPage((p) => Math.min(Math.max(1, p), internalTotalPages));
673
751
  }, [internalTotalPages]);
674
- const paginatedData = pageSize && isClientMode && !isGrouped ? filteredData.slice((internalPage - 1) * pageSize, internalPage * pageSize) : filteredData;
752
+ const paginatedData = useMemo(
753
+ () => pageSize && isClientMode && !isGrouped ? filteredData.slice((internalPage - 1) * pageSize, internalPage * pageSize) : filteredData,
754
+ [pageSize, isClientMode, isGrouped, filteredData, internalPage]
755
+ );
675
756
  const onVistaRef = useRef(onVista);
676
757
  onVistaRef.current = onVista;
677
758
  useEffect(() => {
678
759
  onVistaRef.current?.({
679
760
  visible: filteredData.length,
680
761
  filtered: isClientMode && hasActiveFilters,
681
- selfPaginated: isClientMode
762
+ selfPaginated: isClientMode,
763
+ pages: internalTotalPages
682
764
  });
683
- }, [filteredData.length, isClientMode, hasActiveFilters]);
765
+ }, [filteredData.length, isClientMode, hasActiveFilters, internalTotalPages]);
684
766
  const semLinhas = aCarregar || (isGrouped ? groups.length === 0 : paginatedData.length === 0);
685
767
  const setDateFilter = (colKey, part, val) => {
686
- if (!allData) onDataNeeded?.();
768
+ if (!noServidor && !allData) onDataNeeded?.();
687
769
  setDateFilters((prev) => {
688
770
  const cur = { ...prev[colKey] ?? {} };
689
771
  if (val) cur[part] = val;
@@ -717,7 +799,7 @@ function TableBase({
717
799
  setNumFilters({});
718
800
  };
719
801
  const setNumFilter = (colKey, min, max) => {
720
- if (!allData) onDataNeeded?.();
802
+ if (!noServidor && !allData) onDataNeeded?.();
721
803
  setColumnFilters((prev) => {
722
804
  if (!(colKey in prev)) return prev;
723
805
  const n = { ...prev };
@@ -732,7 +814,7 @@ function TableBase({
732
814
  });
733
815
  };
734
816
  const aplicarValores = (colKey, vals) => {
735
- if (!allData) onDataNeeded?.();
817
+ if (!noServidor && !allData) onDataNeeded?.();
736
818
  setNumFilters((prev) => {
737
819
  if (!(colKey in prev)) return prev;
738
820
  const n = { ...prev };
@@ -798,7 +880,8 @@ function TableBase({
798
880
  if (aCarregar && esqueletoAoCarregar) return;
799
881
  const ths = Array.from(cabecalhoRef.current?.children ?? []);
800
882
  const fonte = peloConjunto ? medidaRef.current : corpoRef.current;
801
- const tds = Array.from(fonte?.rows?.[0]?.cells ?? []);
883
+ const primeiraLinha = Array.from(fonte?.rows ?? []).find((r) => !r.hasAttribute("data-espaco"));
884
+ const tds = Array.from(primeiraLinha?.cells ?? []);
802
885
  if (!ths.length || !tds.length) return;
803
886
  const novas = Object.fromEntries(ths.map((th, i) => [
804
887
  chavesVista[i] ?? String(i),
@@ -857,20 +940,131 @@ function TableBase({
857
940
  useEffect(() => {
858
941
  const c = caixaCorpo;
859
942
  if (!esbaterDireita || !c) return;
943
+ let quadro = 0;
944
+ let ultimaEsquerda = -1;
945
+ let mudouTamanho = true;
860
946
  const ver = () => {
861
- const resta = c.scrollLeft + c.clientWidth < c.scrollWidth - 1;
947
+ quadro = 0;
948
+ const esquerda = c.scrollLeft;
949
+ if (esquerda === ultimaEsquerda && !mudouTamanho) return;
950
+ ultimaEsquerda = esquerda;
951
+ mudouTamanho = false;
952
+ const resta = esquerda + c.clientWidth < c.scrollWidth - 1;
862
953
  setRestaDireita((prev) => prev === resta ? prev : resta);
863
954
  };
955
+ const agendar = () => {
956
+ if (!quadro) quadro = requestAnimationFrame(ver);
957
+ };
958
+ const aoMudarTamanho = () => {
959
+ mudouTamanho = true;
960
+ agendar();
961
+ };
864
962
  ver();
865
- c.addEventListener("scroll", ver, { passive: true });
866
- const ro = new ResizeObserver(ver);
963
+ c.addEventListener("scroll", agendar, { passive: true });
964
+ const ro = new ResizeObserver(aoMudarTamanho);
867
965
  ro.observe(c);
868
966
  if (c.firstElementChild) ro.observe(c.firstElementChild);
869
967
  return () => {
870
- c.removeEventListener("scroll", ver);
968
+ c.removeEventListener("scroll", agendar);
871
969
  ro.disconnect();
970
+ cancelAnimationFrame(quadro);
872
971
  };
873
972
  }, [esbaterDireita, caixaCorpo]);
973
+ const accoesLinha = useRef({ onRowClick, onRowDoubleClick, toggleRow });
974
+ useLayoutEffect(() => {
975
+ accoesLinha.current = { onRowClick, onRowDoubleClick, toggleRow };
976
+ });
977
+ const ecraEstreito = useEcraEstreito();
978
+ const janelaAtiva = preencheAltura && ecraEstreito && !isGrouped && !aCarregar && paginatedData.length > JANELA_MINIMO_LINHAS;
979
+ const fundoPorPintar = janelaAtiva && !rowClassName;
980
+ const versaoLinhas = `${realcada ?? ""}|${esquerdas.join(",")}|${nFixas}|${selectable ? 1 : 0}|${barraSobreposta ? 1 : 0}|${transicaoRealce}|${onRowClick || onRowDoubleClick ? 1 : 0}|${fundoPorPintar ? 1 : 0}`;
981
+ const [janela, setJanela] = useState({ inicio: 0, fim: JANELA_MINIMO_LINHAS });
982
+ const [dadosDaJanela, setDadosDaJanela] = useState(paginatedData);
983
+ if (dadosDaJanela !== paginatedData) {
984
+ setDadosDaJanela(paginatedData);
985
+ setJanela({ inicio: 0, fim: JANELA_MINIMO_LINHAS });
986
+ }
987
+ const linhasAVista = useRef({ inicio: 0, fim: JANELA_MINIMO_LINHAS });
988
+ const [colunasDaJanela, setColunasDaJanela] = useState(chaveColunas);
989
+ if (colunasDaJanela !== chaveColunas) {
990
+ setColunasDaJanela(chaveColunas);
991
+ if (janelaAtiva) setJanela(linhasAVista.current);
992
+ }
993
+ const [alturaLinha, setAlturaLinha] = useState(36);
994
+ useEffect(() => {
995
+ const c = caixaCorpo;
996
+ if (!janelaAtiva || !c) return;
997
+ let quadro = 0;
998
+ const calcular = () => {
999
+ quadro = 0;
1000
+ const tabela = corpoRef.current;
1001
+ if (!tabela) return;
1002
+ const reais = Array.from(tabela.tBodies[0]?.rows ?? []).filter((r) => !r.hasAttribute("data-espaco")).slice(0, 20);
1003
+ const media = reais.length ? reais.reduce((s, r) => s + r.getBoundingClientRect().height, 0) / reais.length : 0;
1004
+ const altura = media > 0 ? media : alturaLinha;
1005
+ if (media > 0) setAlturaLinha((prev) => Math.abs(prev - media) < 0.5 ? prev : media);
1006
+ const topo2 = c.getBoundingClientRect().top - tabela.getBoundingClientRect().top;
1007
+ const primeira = Math.max(0, Math.floor(topo2 / altura) - JANELA_MARGEM_LINHAS);
1008
+ const ultima = Math.ceil((topo2 + c.clientHeight) / altura) + JANELA_MARGEM_LINHAS;
1009
+ const inicio = Math.floor(primeira / JANELA_PASSO_LINHAS) * JANELA_PASSO_LINHAS;
1010
+ const fim = Math.min(paginatedData.length, Math.ceil(ultima / JANELA_PASSO_LINHAS) * JANELA_PASSO_LINHAS);
1011
+ linhasAVista.current = { inicio, fim };
1012
+ setJanela((prev) => {
1013
+ const novoInicio = Math.min(prev.inicio, inicio);
1014
+ const novoFim = Math.max(prev.fim, fim);
1015
+ return prev.inicio === novoInicio && prev.fim === novoFim ? prev : { inicio: novoInicio, fim: novoFim };
1016
+ });
1017
+ };
1018
+ const agendar = () => {
1019
+ if (!quadro) quadro = requestAnimationFrame(calcular);
1020
+ };
1021
+ c.addEventListener("scroll", agendar, { passive: true });
1022
+ const ro = new ResizeObserver(agendar);
1023
+ ro.observe(c);
1024
+ return () => {
1025
+ c.removeEventListener("scroll", agendar);
1026
+ ro.disconnect();
1027
+ cancelAnimationFrame(quadro);
1028
+ };
1029
+ }, [janelaAtiva, caixaCorpo, paginatedData.length, alturaLinha]);
1030
+ useEffect(() => {
1031
+ if (!janelaAtiva || janela.inicio <= 0 && janela.fim >= paginatedData.length) return;
1032
+ const crescer = () => setJanela((prev) => ({
1033
+ inicio: Math.max(0, prev.inicio - JANELA_PREENCHER_LINHAS),
1034
+ fim: Math.min(paginatedData.length, prev.fim + JANELA_PREENCHER_LINHAS)
1035
+ }));
1036
+ if (typeof window.requestIdleCallback === "function") {
1037
+ const id2 = window.requestIdleCallback(crescer, { timeout: 1e3 });
1038
+ return () => window.cancelIdleCallback(id2);
1039
+ }
1040
+ const id = window.setTimeout(crescer, 80);
1041
+ return () => window.clearTimeout(id);
1042
+ }, [janelaAtiva, janela, paginatedData.length]);
1043
+ const fimJanela = Math.min(janela.fim, paginatedData.length);
1044
+ const inicioJanela = Math.min(janela.inicio, fimJanela);
1045
+ const linhasDesenhadas = janelaAtiva ? paginatedData.slice(inicioJanela, fimJanela) : paginatedData;
1046
+ const espacoAntes = janelaAtiva ? inicioJanela * alturaLinha : 0;
1047
+ const espacoDepois = janelaAtiva ? (paginatedData.length - fimJanela) * alturaLinha : 0;
1048
+ const estiloLinhasPorDesenhar = (() => {
1049
+ if (!janelaAtiva || !largurasVista) return void 0;
1050
+ let x = 0;
1051
+ const paragens = [];
1052
+ for (const k of chavesVista) {
1053
+ const largura = largurasVista[k] ?? 0;
1054
+ const a = x + 12;
1055
+ const b = x + Math.max(20, Math.round(largura * 0.55));
1056
+ paragens.push(`transparent ${a}px`, `#000 ${a}px`, `#000 ${b}px`, `transparent ${b}px`);
1057
+ x += largura;
1058
+ }
1059
+ const meio = alturaLinha / 2;
1060
+ const mascara = `linear-gradient(to right, transparent 0px, ${paragens.join(", ")}, transparent ${x}px)`;
1061
+ return {
1062
+ backgroundImage: `repeating-linear-gradient(to bottom, transparent 0px, transparent ${meio - 4}px, currentColor ${meio - 4}px, currentColor ${meio + 4}px, transparent ${meio + 4}px, transparent ${alturaLinha}px)`,
1063
+ maskImage: mascara,
1064
+ WebkitMaskImage: mascara
1065
+ };
1066
+ })();
1067
+ const classeLinhasPorDesenhar = "text-slate-200 dark:text-slate-700 animate-pulse motion-reduce:animate-none";
874
1068
  const mascaraDireita = "linear-gradient(to right, #000 calc(100% - 48px), transparent)";
875
1069
  const [barra, setBarra] = useState(0);
876
1070
  useLayoutEffect(() => {
@@ -925,10 +1119,10 @@ function TableBase({
925
1119
  const grupoColunas = largurasVista ? /* @__PURE__ */ jsx("colgroup", { children: chavesVista.map((k) => /* @__PURE__ */ jsx("col", { style: { width: largurasVista[k] } }, k)) }) : null;
926
1120
  const estiloTabela = largurasVista ? { tableLayout: "fixed", width: chavesVista.reduce((a, k) => a + (largurasVista[k] ?? 0), 0), minWidth: "100%" } : { width: "max-content" };
927
1121
  const cabecalho = (fixoNoTopo) => /* @__PURE__ */ jsx("thead", { className: fixoNoTopo ? "sticky top-0 z-20" : void 0, children: /* @__PURE__ */ jsxs("tr", { ref: cabecalhoRef, className: `text-[11.5px] font-semibold uppercase text-slate-500 dark:text-slate-400 tracking-wide ${!bordasSeparadas ? "border-b border-slate-200 dark:border-slate-700 bg-slate-50 dark:bg-slate-900" : fundoNosTitulos ? "[&>th]:border-b [&>th]:border-slate-200 dark:[&>th]:border-slate-700" : "shadow-[inset_0_-1px_0_0_var(--tbl-s200)]"}`, children: [
928
- selectable && /* @__PURE__ */ jsx("th", { style: cabecaFixa(0).style, className: `px-4 py-2.5 w-10 ${fundoNosTitulos ? "bg-slate-50 dark:bg-slate-900" : ""} ${cabecaFixa(0).className}`, children: /* @__PURE__ */ jsx("button", { onClick: toggleAll, className: `w-4 h-4 flex items-center justify-center rounded-sm border transition-colors ${allVisibleSelected ? "bg-primary border-primary" : someVisibleSelected ? "bg-slate-300 dark:bg-slate-600 border-slate-300 dark:border-slate-600" : "border-slate-300 dark:border-slate-600 hover:border-slate-400 dark:hover:border-slate-500"}`, children: (allVisibleSelected || someVisibleSelected) && /* @__PURE__ */ jsx(CheckIcon, { size: 9, strokeWidth: 3, className: "text-white" }) }) }),
1122
+ selectable && /* @__PURE__ */ jsx("th", { style: cabecaFixa(0).style, className: `px-4 py-2.5 max-lg:[@media(max-height:500px)]:py-1 w-10 ${fundoNosTitulos ? "bg-slate-50 dark:bg-slate-900" : ""} ${cabecaFixa(0).className}`, children: /* @__PURE__ */ jsx("button", { onClick: toggleAll, className: `w-4 h-4 flex items-center justify-center rounded-sm border transition-colors ${allVisibleSelected ? "bg-primary border-primary" : someVisibleSelected ? "bg-slate-300 dark:bg-slate-600 border-slate-300 dark:border-slate-600" : "border-slate-300 dark:border-slate-600 hover:border-slate-400 dark:hover:border-slate-500"}`, children: (allVisibleSelected || someVisibleSelected) && /* @__PURE__ */ jsx(CheckIcon, { size: 9, strokeWidth: 3, className: "text-white" }) }) }),
929
1123
  columns.map((col, i) => {
930
- const canSort = col.sortable !== false && !!col.value;
931
- const canFilter = col.filterable !== false && !!col.value;
1124
+ const canSort = noServidor ? col.sortable === true : col.sortable !== false && !!col.value;
1125
+ const canFilter = noServidor ? col.filterable === true : col.filterable !== false && !!col.value;
932
1126
  const canGroup = col.groupable === true && !!col.value;
933
1127
  const isSortActive = sortCol === col.key;
934
1128
  const isFiltered = hasActiveFilter(col.key);
@@ -940,7 +1134,7 @@ function TableBase({
940
1134
  {
941
1135
  style: cabecaFixa(i + (selectable ? 1 : 0)).style,
942
1136
  onPointerDown: arrastavel ? (e) => premirTitulo(e, col.key) : void 0,
943
- className: `px-4 py-2.5 ${cabecaFixa(i + (selectable ? 1 : 0)).style ? "" : "relative"} ${col.headerClassName ?? ""} ${cabecaFixa(i + (selectable ? 1 : 0)).className} ${arrastavel ? "cursor-grab" : ""} ${realce(col.key, true)} ${transicaoRealce}`,
1137
+ className: `px-4 py-2.5 max-lg:[@media(max-height:500px)]:py-1 ${cabecaFixa(i + (selectable ? 1 : 0)).style ? "" : "relative"} ${col.headerClassName ?? ""} ${cabecaFixa(i + (selectable ? 1 : 0)).className} ${arrastavel ? "cursor-grab" : ""} ${realce(col.key, true)} ${transicaoRealce}`,
944
1138
  "data-col": col.key,
945
1139
  children: [
946
1140
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 group/hdr whitespace-nowrap select-none", children: [
@@ -948,7 +1142,7 @@ function TableBase({
948
1142
  "button",
949
1143
  {
950
1144
  onClick: () => {
951
- if (!allData) onDataNeeded?.();
1145
+ if (!noServidor && !allData) onDataNeeded?.();
952
1146
  if (sortCol === col.key && sortDir === "desc") {
953
1147
  setSortCol(defaultSortCol ?? null);
954
1148
  setSortDir(defaultSortDir ?? "asc");
@@ -986,7 +1180,7 @@ function TableBase({
986
1180
  if (isFilterOpen) {
987
1181
  fechaFiltro();
988
1182
  } else {
989
- if (!allData) onDataNeeded?.();
1183
+ if (!noServidor && !allData) onDataNeeded?.();
990
1184
  setAncoraFiltro(r);
991
1185
  setOpenFilterCol(col.key);
992
1186
  }
@@ -1010,7 +1204,7 @@ function TableBase({
1010
1204
  intervalo: dateFilters[col.key] ?? {},
1011
1205
  numero: numFilters[col.key] ?? {},
1012
1206
  ordenadaPor: sortCol === col.key ? sortDir : null,
1013
- aCarregar: !allData && !!isAllDataLoading,
1207
+ aCarregar: noServidor ? !!isLoading : !allData && (!!isAllDataLoading || !!onDataNeeded),
1014
1208
  onOrdenar: (dir) => {
1015
1209
  if (sortCol === col.key && sortDir === dir) {
1016
1210
  setSortCol(defaultSortCol ?? null);
@@ -1076,7 +1270,7 @@ function TableBase({
1076
1270
  intervalo: dateFilters[sf.key] ?? {},
1077
1271
  numero: numFilters[sf.key] ?? {},
1078
1272
  ordenadaPor: null,
1079
- aCarregar: !allData && !!isAllDataLoading,
1273
+ aCarregar: noServidor ? !!isLoading : !allData && (!!isAllDataLoading || !!onDataNeeded),
1080
1274
  onAplicar: (vals) => {
1081
1275
  aplicarValores(sf.key, vals);
1082
1276
  fechaFiltro();
@@ -1100,7 +1294,7 @@ function TableBase({
1100
1294
  ] }, sf.key);
1101
1295
  })
1102
1296
  ] }),
1103
- col.headerExtra && /* @__PURE__ */ jsx("div", { className: "mt-0.5 normal-case font-normal tracking-normal", children: col.headerExtra(filteredData) }),
1297
+ col.headerExtra && /* @__PURE__ */ jsx("div", { className: "mt-0.5 max-lg:[@media(max-height:500px)]:mt-0 max-lg:[@media(max-height:500px)]:leading-tight normal-case font-normal tracking-normal", children: col.headerExtra(linhasDosTotais) }),
1104
1298
  pegaRedimensionar(col.key)
1105
1299
  ]
1106
1300
  },
@@ -1110,31 +1304,39 @@ function TableBase({
1110
1304
  ] }) });
1111
1305
  const LARGURAS_ESQUELETO = ["w-3/4", "w-1/2", "w-2/3", "w-5/6", "w-2/5"];
1112
1306
  const linhasEsqueleto = Array.from({ length: 20 }, (_, r) => /* @__PURE__ */ jsxs("tr", { "aria-hidden": true, className: "animate-pulse motion-reduce:animate-none", children: [
1113
- selectable && /* @__PURE__ */ jsx("td", { style: fixa(0, "bg-white dark:bg-slate-950").style, className: `px-4 py-3 ${fixa(0, "bg-white dark:bg-slate-950").className}`, children: /* @__PURE__ */ jsx("div", { className: "w-4 h-4 rounded-sm border border-slate-200 dark:border-slate-700 bg-slate-50 dark:bg-slate-900" }) }),
1307
+ selectable && /* @__PURE__ */ jsx("td", { style: fixa(0, "bg-white dark:bg-slate-950").style, className: `px-4 py-3 max-lg:py-1 ${fixa(0, "bg-white dark:bg-slate-950").className}`, children: /* @__PURE__ */ jsx("div", { className: "w-4 h-4 rounded-sm border border-slate-200 dark:border-slate-700 bg-slate-50 dark:bg-slate-900" }) }),
1114
1308
  columns.map((col, i) => {
1115
1309
  const f = fixa(i + (selectable ? 1 : 0), "bg-white dark:bg-slate-950");
1116
1310
  return /* @__PURE__ */ jsx("td", { style: f.style, className: `px-3 py-2.5 ${f.className} ${recuoFim(i)}`, children: /* @__PURE__ */ jsx("div", { className: `h-2 bg-slate-200 dark:bg-slate-700 ${LARGURAS_ESQUELETO[(r + i) % LARGURAS_ESQUELETO.length]} ${/text-right/.test(col.cellClassName ?? "") ? "ml-auto" : /text-center/.test(col.cellClassName ?? "") ? "mx-auto" : ""}` }) }, col.key);
1117
1311
  })
1118
1312
  ] }, `esqueleto-${r}`));
1119
- const corpo = /* @__PURE__ */ jsx("tbody", { className: bordasSeparadas ? "[&>tr+tr]:shadow-[inset_0_1px_0_0_var(--tbl-s100)]" : "divide-y divide-slate-100 dark:divide-slate-800", children: aCarregar ? esqueletoAoCarregar ? linhasEsqueleto : null : isGrouped ? /* @__PURE__ */ jsx(Fragment, { children: renderGroupNodes(groups, 0) }) : paginatedData.map((row) => /* @__PURE__ */ jsxs(
1120
- "tr",
1121
- {
1122
- onClick: () => onRowClick?.(row),
1123
- onDoubleClick: () => onRowDoubleClick?.(row),
1124
- className: `group/linha hover:bg-slate-50 dark:hover:bg-slate-900 transition-colors ${onRowClick || onRowDoubleClick ? "cursor-pointer" : ""} ${selectable && selectedKeys.has(rowKey(row)) ? "bg-proef-turquoise/5" : ""} ${rowClassName?.(row) ?? ""}`,
1125
- children: [
1126
- selectable && /* @__PURE__ */ jsx("td", { style: fixa(0, fundoLinha(rowKey(row))).style, className: `px-4 py-3 ${fixa(0, fundoLinha(rowKey(row))).className}`, onClick: (e) => {
1127
- e.stopPropagation();
1128
- toggleRow(rowKey(row));
1129
- }, children: /* @__PURE__ */ jsx("div", { className: `w-4 h-4 flex items-center justify-center rounded-sm border transition-colors ${selectedKeys.has(rowKey(row)) ? "bg-primary border-primary" : "border-slate-300 dark:border-slate-600 hover:border-slate-400 dark:hover:border-slate-500"}`, children: selectedKeys.has(rowKey(row)) && /* @__PURE__ */ jsx(CheckIcon, { size: 9, strokeWidth: 3, className: "text-white" }) }) }),
1130
- columns.map((col, i) => {
1131
- const f = fixa(i + (selectable ? 1 : 0), fundoLinha(rowKey(row)));
1132
- return /* @__PURE__ */ jsx("td", { style: f.style, className: `px-3 py-1.5 ${col.cellClassName ?? ""} ${f.className} ${recuoFim(i)} ${realce(col.key)} ${transicaoRealce}`, "data-col": col.key, children: col.render(row) }, col.key);
1133
- })
1134
- ]
1135
- },
1136
- rowKey(row)
1137
- )) });
1313
+ const corpo = /* @__PURE__ */ jsx("tbody", { className: bordasSeparadas ? "[&>tr+tr]:shadow-[inset_0_1px_0_0_var(--tbl-s100)]" : "divide-y divide-slate-100 dark:divide-slate-800", children: aCarregar ? esqueletoAoCarregar ? linhasEsqueleto : null : isGrouped ? /* @__PURE__ */ jsx(Fragment, { children: renderGroupNodes(groups, 0) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1314
+ espacoAntes > 0 && /* @__PURE__ */ jsx("tr", { "data-espaco": true, "aria-hidden": true, style: { height: espacoAntes }, children: /* @__PURE__ */ jsx("td", { colSpan: chavesVista.length, className: `p-0 ${classeLinhasPorDesenhar}`, style: estiloLinhasPorDesenhar }) }),
1315
+ linhasDesenhadas.map((row) => {
1316
+ const chave = rowKey(row);
1317
+ const seleccionada = !!selectable && selectedKeys.has(chave);
1318
+ const classeExtra = rowClassName?.(row) ?? "";
1319
+ return /* @__PURE__ */ jsx(LinhaCorpo, { dados: row, seleccionada, versao: versaoLinhas, colunas: columns, classeExtra, conteudo: () => /* @__PURE__ */ jsxs(
1320
+ "tr",
1321
+ {
1322
+ onClick: () => accoesLinha.current.onRowClick?.(row),
1323
+ onDoubleClick: () => accoesLinha.current.onRowDoubleClick?.(row),
1324
+ className: `group/linha hover:bg-slate-50 dark:hover:bg-slate-900 transition-colors ${onRowClick || onRowDoubleClick ? "cursor-pointer" : ""} ${seleccionada ? fundoPorPintar ? "bg-[#f2fdf9] dark:bg-[#062a20]" : "bg-proef-turquoise/5" : fundoPorPintar ? "bg-white dark:bg-slate-950" : ""} ${classeExtra}`,
1325
+ children: [
1326
+ selectable && /* @__PURE__ */ jsx("td", { style: fixa(0, fundoLinha(chave)).style, className: `px-4 py-3 max-lg:py-1 ${fixa(0, fundoLinha(chave)).className}`, onClick: (e) => {
1327
+ e.stopPropagation();
1328
+ accoesLinha.current.toggleRow(chave);
1329
+ }, children: /* @__PURE__ */ jsx("div", { className: `w-4 h-4 flex items-center justify-center rounded-sm border transition-colors ${seleccionada ? "bg-primary border-primary" : "border-slate-300 dark:border-slate-600 hover:border-slate-400 dark:hover:border-slate-500"}`, children: seleccionada && /* @__PURE__ */ jsx(CheckIcon, { size: 9, strokeWidth: 3, className: "text-white" }) }) }),
1330
+ columns.map((col, i) => {
1331
+ const f = fixa(i + (selectable ? 1 : 0), fundoLinha(chave));
1332
+ return /* @__PURE__ */ jsx("td", { style: f.style, className: `px-3 py-1.5 max-lg:py-1 ${col.cellClassName ?? ""} ${f.className} ${recuoFim(i)} ${realce(col.key)} ${transicaoRealce}`, "data-col": col.key, children: col.render(row) }, col.key);
1333
+ })
1334
+ ]
1335
+ }
1336
+ ) }, chave);
1337
+ }),
1338
+ espacoDepois > 0 && /* @__PURE__ */ jsx("tr", { "data-espaco": true, "aria-hidden": true, style: { height: espacoDepois }, children: /* @__PURE__ */ jsx("td", { colSpan: chavesVista.length, className: `p-0 ${classeLinhasPorDesenhar}`, style: estiloLinhasPorDesenhar }) })
1339
+ ] }) });
1138
1340
  const aviso = aCarregar && esqueletoAoCarregar ? (
1139
1341
  // O esqueleto já diz que está a carregar; o texto fica para leitores de ecrã.
1140
1342
  loadingLabel ? /* @__PURE__ */ jsx("span", { role: "status", className: "sr-only", children: loadingLabel }) : null
@@ -1145,7 +1347,7 @@ function TableBase({
1145
1347
  /* @__PURE__ */ jsx("p", { className: "text-slate-600 dark:text-slate-300 font-bold text-sm", children: vazio }),
1146
1348
  emptySubLabel && /* @__PURE__ */ jsx("p", { className: "text-slate-400 dark:text-slate-500 text-xs -mt-1", children: emptySubLabel })
1147
1349
  ] }) }) : null;
1148
- const temRodape = !paginacaoNoTopo && isClientMode && !isGrouped && !!pageSize && internalTotalPages > 1;
1350
+ const temRodape = !paginacaoNoTopo && !paginaCliente && isClientMode && !isGrouped && !!pageSize && internalTotalPages > 1;
1149
1351
  const topo = paginacaoNoTopo;
1150
1352
  const peloServidor = !!topo?.onPageChange && topo.page !== void 0 && !isClientMode;
1151
1353
  const paginaTopo = peloServidor ? topo.page : internalPage;
@@ -1175,7 +1377,7 @@ function TableBase({
1175
1377
  // Os intervalos Mín/Máx também levam chip: sem ele, um filtro de números
1176
1378
  // escondia linhas sem nada à vista que o dissesse.
1177
1379
  ...Object.entries(numFilters).filter(([, r]) => numFilterActive(r)).map(([k, r]) => itemChip(`n-${k}`, "filtro", nomeDoFiltro(k), textoNum(r), () => clearColumnFilter(k)))
1178
- ];
1380
+ ].filter((i) => !semFaixaFiltros || i.tipo === "grupo");
1179
1381
  const chip = (it, focavel = true) => /* @__PURE__ */ jsxs("div", { className: "shrink-0 whitespace-nowrap h-7 flex items-center gap-1.5 pl-2.5 pr-1 rounded-md border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-950 text-caption", children: [
1180
1382
  it.tipo === "grupo" && /* @__PURE__ */ jsx(LayersIcon, { size: 12, className: "text-slate-400 dark:text-slate-500" }),
1181
1383
  /* @__PURE__ */ jsx("span", { className: "text-slate-500 dark:text-slate-400", children: it.rotulo }),
@@ -1197,7 +1399,7 @@ function TableBase({
1197
1399
  itensChips.filter((i) => i.tipo === "grupo").map((i) => chip(i)),
1198
1400
  /* @__PURE__ */ jsx("button", { type: "button", onClick: clearAllGroups, className: classeLimpar, children: L.clearGroups })
1199
1401
  ] }) : null;
1200
- const chipsFiltro = totalActiveFilters > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
1402
+ const chipsFiltro = totalActiveFilters > 0 && !semFaixaFiltros ? /* @__PURE__ */ jsxs(Fragment, { children: [
1201
1403
  itensChips.filter((i) => i.tipo === "filtro").map((i) => chip(i)),
1202
1404
  /* @__PURE__ */ jsx("button", { type: "button", onClick: clearAllFilters, className: classeLimpar, children: L.clearAll })
1203
1405
  ] }) : null;
@@ -1345,7 +1547,7 @@ function TableBase({
1345
1547
  /* @__PURE__ */ jsxs("div", { ref: raizRef, className: `v1-reset text-control text-slate-800 dark:text-slate-100 ${preencheAltura ? "h-full min-h-0 flex flex-col" : ""} ${comCaixa ? "rounded-xl border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-950 overflow-hidden" : ""}`, children: [
1346
1548
  barraTopo,
1347
1549
  !topo && isGrouped && /* @__PURE__ */ jsx("div", { className: "px-4 py-2 bg-slate-50 dark:bg-slate-900 border-b border-slate-200 dark:border-slate-700 flex items-center gap-1.5 flex-wrap", children: chipsGrupo }),
1348
- !topo && totalActiveFilters > 0 && /* @__PURE__ */ jsx("div", { className: "px-4 py-2 bg-slate-50 dark:bg-slate-900 border-b border-slate-200 dark:border-slate-700 flex items-center gap-1.5 flex-wrap", children: chipsFiltro }),
1550
+ !topo && totalActiveFilters > 0 && !semFaixaFiltros && /* @__PURE__ */ jsx("div", { className: "px-4 py-2 bg-slate-50 dark:bg-slate-900 border-b border-slate-200 dark:border-slate-700 flex items-center gap-1.5 flex-wrap", children: chipsFiltro }),
1349
1551
  preencheAltura ? /* @__PURE__ */ jsxs(Fragment, { children: [
1350
1552
  !barraSobreposta && /* @__PURE__ */ jsx(
1351
1553
  "div",
@@ -1360,6 +1562,14 @@ function TableBase({
1360
1562
  }
1361
1563
  ),
1362
1564
  /* @__PURE__ */ jsxs("div", { className: `relative flex-1 min-h-0 flex flex-col ${barraSobreposta && barraHorizontalFora ? "pb-3" : ""}`, children: [
1565
+ fundoPorPintar && /* @__PURE__ */ jsx(
1566
+ "div",
1567
+ {
1568
+ "aria-hidden": true,
1569
+ className: `pointer-events-none absolute left-0 top-0 ${classeLinhasPorDesenhar} ${esbaterDireita && restaDireita ? "right-12" : "right-0"} ${barraSobreposta && barraHorizontalFora ? "bottom-3" : "bottom-0"}`,
1570
+ style: estiloLinhasPorDesenhar
1571
+ }
1572
+ ),
1363
1573
  /* @__PURE__ */ jsx(
1364
1574
  "div",
1365
1575
  {
@@ -1368,7 +1578,7 @@ function TableBase({
1368
1578
  const cab = caixaCabecalhoRef.current;
1369
1579
  if (cab) cab.scrollLeft = e.currentTarget.scrollLeft;
1370
1580
  },
1371
- className: `overflow-auto flex-1 min-h-0 ${barraSobreposta ? "scrollbar-none" : ""}`,
1581
+ className: `overflow-auto flex-1 min-h-0 ${fundoPorPintar ? "relative z-[1]" : ""} ${barraSobreposta ? "scrollbar-none" : ""}`,
1372
1582
  style: esbaterDireita && restaDireita ? { maskImage: mascaraDireita, WebkitMaskImage: mascaraDireita } : void 0,
1373
1583
  children: /* @__PURE__ */ jsxs("div", { className: semLinhas ? "min-h-full flex flex-col" : void 0, children: [
1374
1584
  barraSobreposta && /* @__PURE__ */ jsx("div", { "data-barra-cabecalho": true, className: `sticky top-0 z-20 w-max min-w-full ${bordasSeparadas ? classeCabecalho : ""}`, children: /* @__PURE__ */ jsxs("table", { className: classeTabela, style: estiloTabela, children: [
@@ -1397,7 +1607,7 @@ function TableBase({
1397
1607
  selectable && /* @__PURE__ */ jsx("td", { className: "px-4 py-3 w-10", children: /* @__PURE__ */ jsx("div", { className: "w-4 h-4" }) }),
1398
1608
  columns.map((col, i) => {
1399
1609
  const row = exemplares.porColuna[i][r];
1400
- return /* @__PURE__ */ jsx("td", { className: `px-3 py-1.5 ${col.cellClassName ?? ""} ${recuoFim(i)}`, children: row !== void 0 ? col.render(row) : null }, col.key);
1610
+ return /* @__PURE__ */ jsx("td", { className: `px-3 py-1.5 max-lg:py-1 ${col.cellClassName ?? ""} ${recuoFim(i)}`, children: row !== void 0 ? col.render(row) : null }, col.key);
1401
1611
  })
1402
1612
  ] }, r)) })
1403
1613
  }