@1doc/1ds-vue 2.21.0 → 2.22.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1doc/1ds-vue",
3
- "version": "2.21.0",
3
+ "version": "2.22.0",
4
4
  "main": "dist/index.umd.js",
5
5
  "sideEffects": [
6
6
  "**/*.css"
@@ -34,7 +34,7 @@
34
34
  "vue": "^3.0.0",
35
35
  "vue-tsc": "^2.0.0",
36
36
  "@1doc/1ds-tokens": "0.9.0",
37
- "@1doc/1ds-core": "2.21.0"
37
+ "@1doc/1ds-core": "2.22.0"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@1doc/1ds-tokens": ">=0.8.0",
package/src/index.ts CHANGED
@@ -7,6 +7,8 @@ export * from "./utils/toast";
7
7
  export * from "./utils/density";
8
8
  // Paleta de cor categórica (primitivos) do ColorPicker
9
9
  export * from "./utils/paleta-de-cores";
10
+ // Padrões globais do Tooltip (variant e delayDuration), como o setTheme
11
+ export * from "./utils/tooltip";
10
12
  // FontAwesome
11
13
  export { library } from "@fortawesome/fontawesome-svg-core";
12
14
 
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Registro dos tooltips abertos (estado de módulo, compartilhado entre os
3
+ * componentes gerados React e Vue). Uso interno do Tooltip; não sai no index.
4
+ * - Tooltips vizinhos: depois que um fecha, o próximo abre sem espera durante
5
+ * `skipDelayDuration`, e quem percorre uma lista não espera o atraso a cada item.
6
+ * - Tooltips aninhados: quando um descendente abre, o ancestral fecha. Fica
7
+ * um balão só, o de dentro.
8
+ */
9
+ import { getTooltipDefaults } from "./tooltip";
10
+ interface TooltipAberto {
11
+ gatilho: HTMLElement;
12
+ fechar: () => void;
13
+ }
14
+ const abertos: TooltipAberto[] = [];
15
+ let ultimoFechamento = 0;
16
+
17
+ /** Espera efetiva: zero quando outro tooltip está aberto ou acabou de fechar. */
18
+ export const atrasoDoTooltip = (atraso: number): number => {
19
+ if (atraso <= 0) return 0;
20
+ if (abertos.length > 0) return 0;
21
+ if (Date.now() - ultimoFechamento < getTooltipDefaults().skipDelayDuration) return 0;
22
+ return atraso;
23
+ };
24
+
25
+ /** true se um tooltip DENTRO deste gatilho está aberto (o de dentro vence). */
26
+ export const temTooltipDescendenteAberto = (gatilho: HTMLElement): boolean => abertos.some(item => item.gatilho !== gatilho && gatilho.contains(item.gatilho));
27
+
28
+ /** Registra o tooltip aberto e fecha os ancestrais dele. */
29
+ export const registrarTooltipAberto = (gatilho: HTMLElement, fechar: () => void): void => {
30
+ abertos.filter(item => item.gatilho !== gatilho && item.gatilho.contains(gatilho)).forEach(item => item.fechar());
31
+ if (!abertos.some(item => item.gatilho === gatilho)) abertos.push({
32
+ gatilho,
33
+ fechar
34
+ });
35
+ };
36
+
37
+ /** Tira o tooltip do registro (ao fechar ou desmontar). */
38
+ export const removerTooltipAberto = (gatilho: HTMLElement | null): void => {
39
+ if (!gatilho) return;
40
+ const indice = abertos.findIndex(item => item.gatilho === gatilho);
41
+ if (indice === -1) return;
42
+ abertos.splice(indice, 1);
43
+ ultimoFechamento = Date.now();
44
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Padrões globais do Tooltip, para não repetir `variant` e `delayDuration` em
3
+ * cada uso. Chame uma vez na entrada do app, como o `setTheme`:
4
+ *
5
+ * setTooltipDefaults({ variant: "dark", delayDuration: 300 });
6
+ *
7
+ * A prop do Tooltip sempre vence o padrão global.
8
+ *
9
+ * O registro de quem está aberto (vizinhos e aninhados) fica em
10
+ * `tooltip-abertos.ts`, de uso interno (fora do index).
11
+ */
12
+ export type TooltipDefaultVariant = "default" | "dark";
13
+ export interface TooltipDefaults {
14
+ /** Aparência padrão do balão. @default 'default' */
15
+ variant?: TooltipDefaultVariant;
16
+ /** Espera, em ms, entre o hover/foco e o balão abrir. @default 0 */
17
+ delayDuration?: number;
18
+ /** Janela, em ms, em que o próximo tooltip abre sem espera depois de outro fechar. @default 300 */
19
+ skipDelayDuration?: number;
20
+ }
21
+ const padroes: Required<TooltipDefaults> = {
22
+ variant: "default",
23
+ delayDuration: 0,
24
+ skipDelayDuration: 300
25
+ };
26
+
27
+ /** Define os padrões globais do Tooltip. Só muda as chaves passadas. */
28
+ export const setTooltipDefaults = (opcoes: TooltipDefaults): void => {
29
+ if (opcoes.variant !== undefined) padroes.variant = opcoes.variant;
30
+ if (opcoes.delayDuration !== undefined) padroes.delayDuration = opcoes.delayDuration;
31
+ if (opcoes.skipDelayDuration !== undefined) padroes.skipDelayDuration = opcoes.skipDelayDuration;
32
+ };
33
+
34
+ /** Padrões globais atuais do Tooltip. */
35
+ export const getTooltipDefaults = (): Required<TooltipDefaults> => ({
36
+ ...padroes
37
+ })