ads-nuxt 0.6.5 → 0.6.6

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.
@@ -603,9 +603,25 @@
603
603
  /*
604
604
  * Tabela dentro do AdsCard: encosta nas laterais e a primeira coluna
605
605
  * usa o mesmo padding do card, alinhada ao título. Fora do card, não vale.
606
+ * O bleed vai no shell (barra sticky + tabela).
606
607
  * Fica fora de @layer para vencer o px da célula sem !important.
607
608
  */
608
- .ads-card .ads-table {
609
+ .ads-card .ads-table-shell {
610
+ /* max-width:none vence o max-w-full do shell — senão a largura fica em 100%
611
+ do padding-box e a margem negativa só empurra para a esquerda (vão à direita). */
612
+ width: calc(100% + 2 * var(--ads-card-bleed, 0px));
613
+ max-width: none;
614
+ margin-inline: calc(var(--ads-card-bleed, 0px) * -1);
615
+ }
616
+
617
+ .ads-card .ads-table-shell .ads-table {
618
+ /* Sem width:100% — anulava o w-max! do sticky-scrollbar. */
619
+ margin-inline: 0;
620
+ }
621
+
622
+ /* Compat: AdsTable antigo sem shell ainda sangra pelo .ads-table. */
623
+ .ads-card > .ads-table,
624
+ .ads-card .ads-card-body > .ads-table {
609
625
  width: calc(100% + 2 * var(--ads-card-bleed, 0px));
610
626
  margin-inline: calc(var(--ads-card-bleed, 0px) * -1);
611
627
  }
@@ -1,50 +1,66 @@
1
1
  <template>
2
2
  <div
3
3
  ref="shellEl"
4
- class="ads-table-shell relative min-w-0"
4
+ class="ads-table-shell relative w-full min-w-0"
5
+ :class="[
6
+ stickyScrollbar ? 'ads-table-shell--sticky-scroll' : undefined,
7
+ attrs.class,
8
+ ]"
5
9
  >
6
- <UTable
7
- :key="virtualize ? 'virtual' : 'static'"
8
- :data="data"
9
- :columns="columns"
10
- :loading="loading"
11
- :sticky="uTableSticky"
12
- :virtualize="virtualizeOptions"
13
- :ui="tableUi"
10
+ <!--
11
+ sticky-scrollbar: overflow-x-auto + overflow-y-clip no viewport — o Y da
12
+ página continua no main (thead sticky) e o X fica só aqui (barra fake).
13
+ -->
14
+ <div
15
+ ref="tableScroller"
16
+ class="w-full min-w-0"
17
+ :class="tableScrollerClass"
14
18
  >
15
- <template v-if="!$slots.loading" #loading>
16
- <AdsTableSkeleton
17
- :rows="skeletonRows"
18
- :variant="skeletonVariant"
19
- :columns="skeletonColumns"
20
- :cell-class="skeletonCellSize ?? adsTableCellSize(density)"
21
- />
22
- </template>
23
-
24
- <template v-if="!$slots.empty" #empty>
25
- <div class="flex flex-col items-center gap-2">
26
- <UIcon
27
- :name="emptyIcon"
28
- class="size-6 text-[var(--ads-border-icon-support)]"
29
- aria-hidden="true"
19
+ <UTable
20
+ v-bind="utableAttrs"
21
+ :key="virtualize ? 'virtual' : 'static'"
22
+ :data="data"
23
+ :columns="columns"
24
+ :loading="loading"
25
+ :sticky="uTableSticky"
26
+ :virtualize="virtualizeOptions"
27
+ :ui="tableUi"
28
+ >
29
+ <template v-if="!$slots.loading" #loading>
30
+ <AdsTableSkeleton
31
+ :rows="skeletonRows"
32
+ :variant="skeletonVariant"
33
+ :columns="skeletonColumns"
34
+ :cell-class="skeletonCellSize ?? adsTableCellSize(density)"
30
35
  />
31
- <p class="text-sm text-[var(--ads-text-secondary)]">{{ emptyLabel }}</p>
32
- </div>
33
- </template>
36
+ </template>
37
+
38
+ <template v-if="!$slots.empty" #empty>
39
+ <div class="flex flex-col items-center gap-2">
40
+ <UIcon
41
+ :name="emptyIcon"
42
+ class="size-6 text-[var(--ads-border-icon-support)]"
43
+ aria-hidden="true"
44
+ />
45
+ <p class="text-sm text-[var(--ads-text-secondary)]">{{ emptyLabel }}</p>
46
+ </div>
47
+ </template>
34
48
 
35
- <template v-for="(_, name) in $slots" #[name]="slotProps">
36
- <slot :name="name" v-bind="slotProps ?? {}" />
37
- </template>
38
- </UTable>
49
+ <template v-for="(_, name) in $slots" #[name]="slotProps">
50
+ <slot :name="name" v-bind="slotProps ?? {}" />
51
+ </template>
52
+ </UTable>
53
+ </div>
39
54
 
40
55
  <div
41
- v-show="stickyScrollbar && needsFakeScroll"
56
+ v-if="stickyScrollbar"
42
57
  ref="fakeScroller"
43
- class="sticky bottom-0 z-20 overflow-x-auto border-t border-[var(--ads-border-subtle)] bg-[var(--ads-surface-card)] [scrollbar-color:var(--ads-border-subtle)_transparent] [scrollbar-width:thin]"
58
+ class="sticky bottom-0 z-20 w-full overflow-x-auto overscroll-x-contain border-t border-[var(--ads-border-subtle)] bg-[var(--ads-surface-card)] [scrollbar-color:var(--ads-border-subtle)_transparent] [scrollbar-width:thin]"
59
+ :class="needsFakeScroll ? undefined : 'invisible pointer-events-none'"
44
60
  aria-hidden="true"
45
61
  >
46
62
  <div
47
- class="h-3"
63
+ class="h-3 min-w-full"
48
64
  :style="{ width: `${scrollContentWidth}px` }"
49
65
  />
50
66
  </div>
@@ -59,6 +75,7 @@ import AdsTableSkeleton, {
59
75
  type AdsTableSkeletonAlign,
60
76
  type AdsTableSkeletonVariant,
61
77
  } from "./AdsTableSkeleton.vue";
78
+ import { twMerge } from "tailwind-merge";
62
79
  import {
63
80
  adsTableCellSize,
64
81
  buildAdsTableUi,
@@ -69,6 +86,8 @@ import {
69
86
  type AdsTableUi,
70
87
  } from "../utils/ads-table";
71
88
 
89
+ defineOptions({ inheritAttrs: false });
90
+
72
91
  const props = withDefaults(
73
92
  defineProps<{
74
93
  data: T[];
@@ -103,8 +122,8 @@ const props = withDefaults(
103
122
  */
104
123
  sticky?: AdsTableSticky;
105
124
  /**
106
- * Barra de rolagem horizontal sticky no rodapé da viewport da tabela.
107
- * Sincroniza com o overflow do root; esconde a barra nativa horizontal.
125
+ * Barra de rolagem horizontal sticky no rodapé da viewport.
126
+ * Um único scroller (viewport) + trilho sticky; barra nativa escondida.
108
127
  * Padrão: desligado.
109
128
  */
110
129
  stickyScrollbar?: boolean;
@@ -115,6 +134,11 @@ const props = withDefaults(
115
134
  virtualize?: boolean;
116
135
  /** Linha de 1px na borda da coluna fixa. */
117
136
  pinnedEdge?: boolean;
137
+ /**
138
+ * Cabeçalho em dois níveis (colunas aninhadas): grupos brancos + folhas cinza.
139
+ * Padrão: desligado.
140
+ */
141
+ groupedHeader?: boolean;
118
142
  emptyLabel?: string;
119
143
  emptyIcon?: string;
120
144
  loadingLabel?: string;
@@ -135,6 +159,7 @@ const props = withDefaults(
135
159
  stickyScrollbar: false,
136
160
  virtualize: false,
137
161
  pinnedEdge: true,
162
+ groupedHeader: false,
138
163
  emptyLabel: "Nenhum registro encontrado",
139
164
  emptyIcon: "i-lucide-inbox",
140
165
  loadingLabel: undefined,
@@ -145,13 +170,20 @@ const props = withDefaults(
145
170
  const slots = useSlots();
146
171
  const attrs = useAttrs();
147
172
 
173
+ /** Repassa attrs do consumidor ao UTable (ex.: v-model:column-pinning). class/style ficam no shell. */
174
+ const utableAttrs = computed(() => {
175
+ const { class: _class, style: _style, ...rest } = attrs as Record<string, unknown>;
176
+ return rest;
177
+ });
178
+
148
179
  const shellEl = ref<HTMLElement | null>(null);
149
- const fakeScroller = ref<HTMLElement | null>(null);
150
180
  const tableScroller = ref<HTMLElement | null>(null);
181
+ const fakeScroller = ref<HTMLElement | null>(null);
151
182
  const scrollContentWidth = ref(0);
152
183
  const needsFakeScroll = ref(false);
153
184
 
154
- let isSyncingScroll = false;
185
+ let syncSource: "table" | "fake" | null = null;
186
+ let syncRaf = 0;
155
187
 
156
188
  /** UTable não conhece `all`; mapeia para cabeçalho fixo. */
157
189
  const uTableSticky = computed(() => {
@@ -166,6 +198,22 @@ const stickyHeaderEnabled = computed(
166
198
  props.sticky === "all",
167
199
  );
168
200
 
201
+ /**
202
+ * overflow-y-clip (não visible): o CSS não promove Y a auto, então o thead
203
+ * sticky continua grudado no main da página — sem max-h / scroll interno.
204
+ * overflow-x-auto: só o scroll horizontal fica neste viewport.
205
+ */
206
+ const tableScrollerClass = computed(() => {
207
+ if (!props.stickyScrollbar) return undefined;
208
+ const hideNative = needsFakeScroll.value
209
+ ? "[scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden"
210
+ : "[scrollbar-width:thin] [scrollbar-color:var(--ads-border-subtle)_transparent]";
211
+ return [
212
+ "overflow-x-auto overflow-y-clip overscroll-x-contain",
213
+ hideNative,
214
+ ];
215
+ });
216
+
169
217
  const leafColumns = (columns: TableColumn<T>[]): TableColumn<T>[] =>
170
218
  columns.flatMap((column) =>
171
219
  "columns" in column && column.columns?.length ? leafColumns(column.columns) : [column],
@@ -203,13 +251,25 @@ const tableUi = computed(() => {
203
251
  depth: props.depth,
204
252
  stickyHeader: stickyHeaderEnabled.value,
205
253
  pinnedEdge: props.pinnedEdge,
254
+ groupedHeader: props.groupedHeader,
206
255
  });
207
256
  // Marca para o CSS do AdsCard alinhar a primeira coluna. Fora do card, não faz nada.
208
257
  base.root = `${base.root} ads-table`.trim();
209
258
  if (props.stickyScrollbar) {
210
- // A barra fake assume o eixo X; a nativa horizontal some para não duplicar.
211
- base.root =
212
- `${base.root} [scrollbar-width:thin] [&::-webkit-scrollbar:horizontal]:h-0`.trim();
259
+ // Sem max-h: a página rola no Y; o viewport externo só rola no X.
260
+ // sticky do UTable (thead) gruda no main graças ao overflow-y-clip.
261
+ base.root = twMerge(
262
+ base.root.replace(/\boverflow-auto\b/g, "").replace(/\bmax-h-\S+/g, ""),
263
+ "w-full min-w-max max-w-none! overflow-visible max-h-none!",
264
+ );
265
+ base.base = twMerge(base.base, "w-full");
266
+ // Tira o bg-default/75 + blur do tema Nuxt no sticky; o th / groupedHeader definem o fundo.
267
+ if (stickyHeaderEnabled.value) {
268
+ base.thead = twMerge(base.thead, "backdrop-blur-none!");
269
+ if (!props.groupedHeader) {
270
+ base.thead = twMerge(base.thead, "bg-transparent!");
271
+ }
272
+ }
213
273
  }
214
274
  if (!slots.expanded) {
215
275
  // Árvore via getSubRows: o UTable sempre desenha a linha de detalhe da linha aberta.
@@ -227,17 +287,71 @@ const tableUi = computed(() => {
227
287
  return mergeAdsTableUi(base, props.ui);
228
288
  });
229
289
 
230
- const resolveTableScroller = () => {
231
- const root = shellEl.value?.querySelector<HTMLElement>(".ads-table");
232
- tableScroller.value = root ?? null;
233
- return tableScroller.value;
290
+ const maxScrollLeft = (el: HTMLElement) =>
291
+ Math.max(0, el.scrollWidth - el.clientWidth);
292
+
293
+ const setScrollLeft = (el: HTMLElement, value: number) => {
294
+ const max = maxScrollLeft(el);
295
+ const next = Math.min(max, Math.max(0, value));
296
+ if (el.scrollLeft !== next) el.scrollLeft = next;
234
297
  };
235
298
 
236
- const syncScrollLeft = (from: HTMLElement | null, to: HTMLElement | null) => {
237
- if (isSyncingScroll || !from || !to || from.scrollLeft === to.scrollLeft) return;
238
- isSyncingScroll = true;
239
- to.scrollLeft = from.scrollLeft;
240
- isSyncingScroll = false;
299
+ const mirrorScroll = (from: HTMLElement, to: HTMLElement) => {
300
+ const maxFrom = maxScrollLeft(from);
301
+ const maxTo = maxScrollLeft(to);
302
+ if (maxFrom <= 0 || maxTo <= 0) {
303
+ setScrollLeft(to, 0);
304
+ return;
305
+ }
306
+ // Mantém a mesma proporção — evita “travar” no início/fim por diferença de largura.
307
+ const ratio = from.scrollLeft / maxFrom;
308
+ setScrollLeft(to, ratio * maxTo);
309
+ };
310
+
311
+ const onTableScroll = () => {
312
+ if (!props.stickyScrollbar || syncSource === "fake") return;
313
+ const table = tableScroller.value;
314
+ const fake = fakeScroller.value;
315
+ if (!table || !fake) return;
316
+ syncSource = "table";
317
+ cancelAnimationFrame(syncRaf);
318
+ syncRaf = requestAnimationFrame(() => {
319
+ mirrorScroll(table, fake);
320
+ syncSource = null;
321
+ });
322
+ };
323
+
324
+ const onFakeScroll = () => {
325
+ if (!props.stickyScrollbar || syncSource === "table") return;
326
+ const table = tableScroller.value;
327
+ const fake = fakeScroller.value;
328
+ if (!table || !fake) return;
329
+ syncSource = "fake";
330
+ cancelAnimationFrame(syncRaf);
331
+ syncRaf = requestAnimationFrame(() => {
332
+ mirrorScroll(fake, table);
333
+ syncSource = null;
334
+ });
335
+ };
336
+
337
+ /** Shift+wheel / trackpad X: só a tabela, sem o main do layout. */
338
+ const onShellWheel = (event: WheelEvent) => {
339
+ if (!props.stickyScrollbar || !needsFakeScroll.value) return;
340
+ const table = tableScroller.value;
341
+ if (!table) return;
342
+
343
+ const horizontal =
344
+ event.shiftKey || Math.abs(event.deltaX) > Math.abs(event.deltaY);
345
+ if (!horizontal) return;
346
+
347
+ const delta = event.shiftKey && event.deltaX === 0 ? event.deltaY : event.deltaX;
348
+ if (delta === 0) return;
349
+
350
+ event.preventDefault();
351
+ syncSource = "table";
352
+ setScrollLeft(table, table.scrollLeft + delta);
353
+ if (fakeScroller.value) mirrorScroll(table, fakeScroller.value);
354
+ syncSource = null;
241
355
  };
242
356
 
243
357
  const measureFakeScroll = () => {
@@ -246,41 +360,54 @@ const measureFakeScroll = () => {
246
360
  needsFakeScroll.value = false;
247
361
  return;
248
362
  }
249
- const el = resolveTableScroller();
250
- if (!el) {
363
+ const table = tableScroller.value;
364
+ if (!table) {
251
365
  scrollContentWidth.value = 0;
252
366
  needsFakeScroll.value = false;
253
367
  return;
254
368
  }
255
- scrollContentWidth.value = el.scrollWidth;
256
- needsFakeScroll.value = el.scrollWidth > el.clientWidth + 1;
369
+ // Mede pelo conteúdo interno quando o scroller ainda reporta scrollWidth=client.
370
+ const content = table.firstElementChild as HTMLElement | null;
371
+ const contentOverflow = content
372
+ ? Math.max(0, content.scrollWidth - table.clientWidth)
373
+ : 0;
374
+ const max = Math.max(maxScrollLeft(table), contentOverflow);
375
+ needsFakeScroll.value = max > 1;
376
+ const fakeWidth = fakeScroller.value?.clientWidth || table.clientWidth;
377
+ scrollContentWidth.value = Math.max(fakeWidth + max, fakeWidth);
378
+ if (fakeScroller.value && needsFakeScroll.value) {
379
+ mirrorScroll(table, fakeScroller.value);
380
+ }
257
381
  };
258
382
 
259
- useEventListener(tableScroller, "scroll", () => {
260
- if (!props.stickyScrollbar) return;
261
- syncScrollLeft(tableScroller.value, fakeScroller.value);
262
- });
263
- useEventListener(fakeScroller, "scroll", () => {
264
- if (!props.stickyScrollbar) return;
265
- syncScrollLeft(fakeScroller.value, tableScroller.value);
266
- });
383
+ /** Conteúdo interno: ResizeObserver no scroller não vê mudança de scrollWidth. */
384
+ const scrollerContentEl = computed(
385
+ () => (tableScroller.value?.firstElementChild as HTMLElement | null) ?? null,
386
+ );
267
387
 
268
- useResizeObserver(shellEl, () => {
269
- void nextTick(measureFakeScroll);
270
- });
388
+ const scheduleMeasure = () => {
389
+ void nextTick(() => {
390
+ measureFakeScroll();
391
+ requestAnimationFrame(() => {
392
+ measureFakeScroll();
393
+ window.setTimeout(measureFakeScroll, 50);
394
+ window.setTimeout(measureFakeScroll, 200);
395
+ });
396
+ });
397
+ };
271
398
 
272
- onMounted(() => {
273
- resolveTableScroller();
274
- measureFakeScroll();
275
- });
399
+ useEventListener(tableScroller, "scroll", onTableScroll, { passive: true });
400
+ useEventListener(fakeScroller, "scroll", onFakeScroll, { passive: true });
401
+ useEventListener(shellEl, "wheel", onShellWheel, { passive: false });
402
+
403
+ useResizeObserver(shellEl, scheduleMeasure);
404
+ useResizeObserver(tableScroller, scheduleMeasure);
405
+ useResizeObserver(scrollerContentEl, scheduleMeasure);
406
+
407
+ onMounted(scheduleMeasure);
276
408
 
277
409
  watch(
278
410
  () => [props.data, props.columns, props.stickyScrollbar, props.sticky, props.ui] as const,
279
- () => {
280
- void nextTick(() => {
281
- resolveTableScroller();
282
- measureFakeScroll();
283
- });
284
- },
411
+ scheduleMeasure,
285
412
  );
286
413
  </script>
@@ -51,6 +51,12 @@ export interface AdsTableLook {
51
51
  stickyHeader?: boolean;
52
52
  /** Linha de 1px na borda da coluna fixa. A Heavy Table desenha a sua por divisória de período. */
53
53
  pinnedEdge?: boolean;
54
+ /**
55
+ * Cabeçalho em dois níveis (colunas com `columns`): 1ª linha (grupos) branca;
56
+ * 2ª (folhas) neutral-100. Mesma Body 14 Bold nas duas. Case (ex. uppercase)
57
+ * fica a cargo do consumidor.
58
+ */
59
+ groupedHeader?: boolean;
54
60
  }
55
61
 
56
62
  /**
@@ -111,14 +117,29 @@ export const buildAdsTableUi = ({
111
117
  depth = false,
112
118
  stickyHeader = false,
113
119
  pinnedEdge: showPinnedEdge = true,
120
+ groupedHeader = false,
114
121
  }: AdsTableLook = {}): AdsTableUi => {
115
122
  const size = CELL_SIZE[density];
116
123
  const grid = borders === "grid" ? GRID_BORDER : "";
117
124
  // Na grade a borda da direita já fecha a coluna fixa da esquerda; a da direita desenha a sua
118
125
  // por fora, em cima da borda da vizinha, para não somar 2px.
119
- const gridPinnedEdge = "data-[pinned=right]:shadow-[-1px_0_0_var(--ads-border-subtle)]";
126
+ // Grade: 1px na borda da coluna fixa (sem degradê). Lines: border-r/l.
127
+ const gridPinnedEdge =
128
+ "data-[pinned=left]:shadow-[1px_0_0_var(--ads-border-subtle)] data-[pinned=right]:shadow-[-1px_0_0_var(--ads-border-subtle)]";
120
129
  const linesPinnedEdge = "data-[pinned=left]:border-r data-[pinned=right]:border-l";
121
130
  const pinnedEdge = !showPinnedEdge ? "" : borders === "grid" ? gridPinnedEdge : linesPinnedEdge;
131
+ // Degradê só com pinnedEdge — senão tapa a borda da grade e “some” visualmente.
132
+ const pinFade = showPinnedEdge ? PIN_FADE : "";
133
+ // 1ª linha = grupos (incl. grupo com 1 coluna); 2ª = folhas. Evita seletor [colspan].
134
+ const groupedThead = groupedHeader
135
+ ? [
136
+ "bg-transparent",
137
+ "[&>tr:first-child>th]:bg-[var(--ads-surface-card)]",
138
+ "[&>tr:first-child>th]:text-center",
139
+ "[&>tr:first-child>th]:text-[var(--ads-text-secondary)]",
140
+ "[&>tr:nth-child(2)>th]:bg-neutral-100",
141
+ ].join(" ")
142
+ : "bg-neutral-100";
122
143
 
123
144
  return {
124
145
  root: [
@@ -130,7 +151,7 @@ export const buildAdsTableUi = ({
130
151
  framed ? "rounded-[var(--ads-radius-md)] border border-[var(--ads-border-subtle)]" : "",
131
152
  ].join(" "),
132
153
  base: "min-w-full border-separate border-spacing-0",
133
- thead: `z-[2] bg-neutral-100 backdrop-blur-none ${stickyHeader ? STICKY_HEADER_SHADOW : ""}`.trim(),
154
+ thead: `z-[2] backdrop-blur-none ${groupedThead} ${stickyHeader ? STICKY_HEADER_SHADOW : ""}`.trim(),
134
155
  tbody: [
135
156
  "divide-y-0 [&>tr:last-child>td]:border-b-0",
136
157
  striped ? "[&>tr:nth-child(even)>td:not(:has([data-cell-fill]))]:bg-[var(--ads-surface-main)]" : "",
@@ -153,10 +174,12 @@ export const buildAdsTableUi = ({
153
174
  // Depois da grade: o cabeçalho tem borda mais forte que a das células.
154
175
  "border-[var(--color-ads-neutro-claro-40)]",
155
176
  ADS_TABLE_HEADER_TEXT,
156
- "[&[colspan]]:text-center [&[colspan]]:text-[var(--ads-text-primary)]",
177
+ groupedHeader
178
+ ? "[&[colspan]]:text-center [&[colspan]]:text-[var(--ads-text-secondary)]"
179
+ : "[&[colspan]]:text-center [&[colspan]]:text-[var(--ads-text-primary)]",
157
180
  "data-[pinned=left]:z-[3] data-[pinned=right]:z-[3]",
158
181
  pinnedEdge,
159
- PIN_FADE,
182
+ pinFade,
160
183
  ].join(" "),
161
184
  td: [
162
185
  size.td,
@@ -164,7 +187,7 @@ export const buildAdsTableUi = ({
164
187
  grid,
165
188
  ADS_TABLE_CELL_TEXT,
166
189
  pinnedEdge,
167
- PIN_FADE,
190
+ pinFade,
168
191
  ].join(" "),
169
192
  separator: "hidden",
170
193
  empty: `py-10 text-center text-[var(--ads-text-secondary)] ${ADS_TABLE_CELL_TEXT}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ads-nuxt",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "license": "MIT",
5
5
  "description": "Alquimia Design System para Nuxt, construído sobre Nuxt UI",
6
6
  "repository": {