@1doc/1ds-vue 2.25.0 → 2.26.1
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/CHANGELOG.md +82 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +115 -1
- package/dist/index.mjs +8741 -8386
- package/dist/index.umd.js +4 -4
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/teste/checkbox-pedidos-7.test.mjs +67 -0
- package/src/teste/modal-pedidos-7.test.mjs +54 -0
- package/src/utils/camadas.ts +52 -0
- package/src/utils/overlay-stack.ts +50 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1doc/1ds-vue",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.26.1",
|
|
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.
|
|
37
|
+
"@1doc/1ds-core": "2.26.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@1doc/1ds-tokens": ">=0.8.0",
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,8 @@ export * from "./utils/density";
|
|
|
9
9
|
export * from "./utils/paleta-de-cores";
|
|
10
10
|
// Padrões globais do Tooltip (variant e delayDuration), como o setTheme
|
|
11
11
|
export * from "./utils/tooltip";
|
|
12
|
+
// Camadas (z-index) do DS lidas dos tokens, para alinhar outra biblioteca (PrimeVue)
|
|
13
|
+
export * from "./utils/camadas";
|
|
12
14
|
// FontAwesome
|
|
13
15
|
export { library } from "@fortawesome/fontawesome-svg-core";
|
|
14
16
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checkbox no Vue GERADO (DOM do jsdom): o input nativo segue o `checked` da
|
|
3
|
+
* prop. Pedido de quem migra o 1Doc: "selecionar todos" numa página sem item
|
|
4
|
+
* selecionável continuava marcado no input nativo, porque a prop não mudava e
|
|
5
|
+
* o Vue não repunha nada. E, sem `checked`, o Checkbox volta a ser não
|
|
6
|
+
* controlado (o boolean casting do Vue fazia `checked` ausente virar `false`).
|
|
7
|
+
*/
|
|
8
|
+
import { test, after } from "node:test";
|
|
9
|
+
import assert from "node:assert/strict";
|
|
10
|
+
import { montar, clicar, proximoTick } from "./dom.mjs";
|
|
11
|
+
|
|
12
|
+
const montados = [];
|
|
13
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
14
|
+
const abrir = async (props) => {
|
|
15
|
+
const m = await montar("Checkbox/Checkbox.vue", props);
|
|
16
|
+
montados.push(m);
|
|
17
|
+
await proximoTick();
|
|
18
|
+
return m;
|
|
19
|
+
};
|
|
20
|
+
const input = (m) => m.raiz.querySelector("input[type=checkbox]");
|
|
21
|
+
const marcadoNaTela = (m) => m.raiz.querySelector("label").classList.contains("umds-checkbox--checked");
|
|
22
|
+
|
|
23
|
+
test("controlado sem mudar o checked: o clique pede, mas o input nativo fica desmarcado", async () => {
|
|
24
|
+
const pedidos = [];
|
|
25
|
+
const m = await abrir({ label: "Selecionar todos", checked: false, onChange: (v) => pedidos.push(v) });
|
|
26
|
+
await clicar(input(m));
|
|
27
|
+
assert.deepEqual(pedidos, [true]);
|
|
28
|
+
assert.equal(input(m).checked, false);
|
|
29
|
+
assert.equal(marcadoNaTela(m), false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("controlado: o app aceita o pedido e o input acompanha nos dois sentidos", async () => {
|
|
33
|
+
const { ref } = await import("vue");
|
|
34
|
+
const marcado = ref(false);
|
|
35
|
+
const m = await abrir(() => ({
|
|
36
|
+
label: "Selecionar todos",
|
|
37
|
+
checked: marcado.value,
|
|
38
|
+
onChange: (v) => (marcado.value = v),
|
|
39
|
+
}));
|
|
40
|
+
await clicar(input(m));
|
|
41
|
+
await proximoTick();
|
|
42
|
+
assert.equal(input(m).checked, true);
|
|
43
|
+
assert.equal(marcadoNaTela(m), true);
|
|
44
|
+
await clicar(input(m));
|
|
45
|
+
await proximoTick();
|
|
46
|
+
assert.equal(input(m).checked, false);
|
|
47
|
+
assert.equal(marcadoNaTela(m), false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("indeterminate que não muda depois do clique continua no input", async () => {
|
|
51
|
+
const m = await abrir({ label: "Selecionar todos", checked: false, indeterminate: true, onChange: () => {} });
|
|
52
|
+
assert.equal(input(m).indeterminate, true);
|
|
53
|
+
await clicar(input(m));
|
|
54
|
+
assert.equal(input(m).indeterminate, true);
|
|
55
|
+
assert.equal(input(m).checked, false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("sem checked, é não controlado: defaultChecked marca e o clique muda a caixa", async () => {
|
|
59
|
+
const pedidos = [];
|
|
60
|
+
const m = await abrir({ label: "Aceito", defaultChecked: true, onChange: (v) => pedidos.push(v) });
|
|
61
|
+
assert.equal(input(m).checked, true);
|
|
62
|
+
assert.equal(marcadoNaTela(m), true);
|
|
63
|
+
await clicar(input(m));
|
|
64
|
+
assert.equal(input(m).checked, false);
|
|
65
|
+
assert.equal(marcadoNaTela(m), false);
|
|
66
|
+
assert.deepEqual(pedidos, [false]);
|
|
67
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modal no Vue GERADO (DOM do jsdom): trava a rolagem da página por padrão.
|
|
3
|
+
* `lockScroll` é `any` no core justamente para o Vue não converter a prop
|
|
4
|
+
* ausente em `false`: aqui se confere que, sem a prop, a página trava.
|
|
5
|
+
*/
|
|
6
|
+
import { test, after, beforeEach } from "node:test";
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { montar, proximoTick, documento } from "./dom.mjs";
|
|
9
|
+
|
|
10
|
+
const montados = [];
|
|
11
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
documento.body.style.overflow = "";
|
|
14
|
+
documento.body.style.paddingRight = "";
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const abrir = async (props) => {
|
|
18
|
+
const m = await montar("Modal/Modal.vue", props);
|
|
19
|
+
montados.push(m);
|
|
20
|
+
await proximoTick();
|
|
21
|
+
return m;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
test("sem lockScroll, aberto trava o body; fechado, devolve o overflow de antes", async () => {
|
|
25
|
+
const { ref } = await import("vue");
|
|
26
|
+
documento.body.style.overflow = "auto";
|
|
27
|
+
const aberto = ref(false);
|
|
28
|
+
const m = await abrir(() => ({ open: aberto.value, title: "Filtrar processos" }));
|
|
29
|
+
assert.equal(documento.body.style.overflow, "auto");
|
|
30
|
+
aberto.value = true;
|
|
31
|
+
await proximoTick();
|
|
32
|
+
assert.equal(documento.body.style.overflow, "hidden");
|
|
33
|
+
aberto.value = false;
|
|
34
|
+
await proximoTick();
|
|
35
|
+
assert.equal(documento.body.style.overflow, "auto");
|
|
36
|
+
m.desmontar();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test(":lockScroll=\"false\" deixa a página rolando", async () => {
|
|
40
|
+
const m = await abrir({ open: true, title: "Filtrar processos", lockScroll: false });
|
|
41
|
+
assert.ok(m.raiz.querySelector("[role=dialog]"));
|
|
42
|
+
assert.equal(documento.body.style.overflow, "");
|
|
43
|
+
m.desmontar();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("inline não trava; desmontar aberto destrava", async () => {
|
|
47
|
+
const inline = await abrir({ open: true, inline: true, title: "Documentação" });
|
|
48
|
+
assert.equal(documento.body.style.overflow, "");
|
|
49
|
+
inline.desmontar();
|
|
50
|
+
const m = await abrir({ open: true, title: "Aberto" });
|
|
51
|
+
assert.equal(documento.body.style.overflow, "hidden");
|
|
52
|
+
m.desmontar();
|
|
53
|
+
assert.equal(documento.body.style.overflow, "");
|
|
54
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Camadas (z-index) do 1DS, para alinhar outra biblioteca de componentes na
|
|
3
|
+
* mesma tela. O DS empilha por tokens semânticos `--umds-semantic-layer-*`:
|
|
4
|
+
*
|
|
5
|
+
* | Camada | Valor | Quem usa |
|
|
6
|
+
* |-----------|-------|---------------------------------------------------------|
|
|
7
|
+
* | `modal` | 1300 | Modal, Drawer, BottomSheet (o ConfirmDialog fica em +1) |
|
|
8
|
+
* | `popover` | 1400 | Select, MultiSelect, Dropdown, DatePicker, TimePicker |
|
|
9
|
+
* | `toast` | 1500 | Toast, Alert fixo |
|
|
10
|
+
* | `tooltip` | 1600 | Tooltip, sempre a mais alta |
|
|
11
|
+
*
|
|
12
|
+
* O PrimeVue começa em 1100: um Toast ou um Dialog dele abertos com um Modal
|
|
13
|
+
* do DS na tela ficam por baixo. Configure o PrimeVue a partir destas camadas:
|
|
14
|
+
*
|
|
15
|
+
* app.use(PrimeVue, {
|
|
16
|
+
* zIndex: {
|
|
17
|
+
* modal: getLayer("modal"),
|
|
18
|
+
* overlay: getLayer("popover"),
|
|
19
|
+
* menu: getLayer("popover"),
|
|
20
|
+
* tooltip: getLayer("tooltip"),
|
|
21
|
+
* },
|
|
22
|
+
* });
|
|
23
|
+
* // <Toast :baseZIndex="getLayer('toast')" />
|
|
24
|
+
*/
|
|
25
|
+
export type Layer = "modal" | "popover" | "toast" | "tooltip";
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* Os valores dos tokens em `packages/tokens/src/semantic/layer.json`. Servem
|
|
29
|
+
* só quando o CSS dos tokens ainda não carregou ou não há `document` (SSR).
|
|
30
|
+
* O teste unitário confere que continuam iguais ao token.
|
|
31
|
+
*/
|
|
32
|
+
const valoresDosTokens: Record<Layer, number> = {
|
|
33
|
+
modal: 1300,
|
|
34
|
+
popover: 1400,
|
|
35
|
+
toast: 1500,
|
|
36
|
+
tooltip: 1600
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Valor da camada do DS, lido do token `--umds-semantic-layer-<camada>` no
|
|
41
|
+
* `:root` (ou no `elemento`, se passado). Sem o CSS dos tokens ou fora do
|
|
42
|
+
* navegador, devolve o valor do token publicado.
|
|
43
|
+
*/
|
|
44
|
+
export const getLayer = (camada: Layer, elemento?: Element): number => {
|
|
45
|
+
const padrao = valoresDosTokens[camada];
|
|
46
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
47
|
+
return padrao;
|
|
48
|
+
}
|
|
49
|
+
const alvo = elemento || document.documentElement;
|
|
50
|
+
const lido = parseInt(window.getComputedStyle(alvo).getPropertyValue("--umds-semantic-layer-" + camada), 10);
|
|
51
|
+
return isNaN(lido) ? padrao : lido;
|
|
52
|
+
}
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* apenas o overlay do TOPO reage ao Esc.
|
|
8
8
|
*
|
|
9
9
|
* Singleton por bundle (estado de módulo), compartilhado entre os
|
|
10
|
-
* componentes gerados React e Vue.
|
|
10
|
+
* componentes gerados React e Vue. O mesmo módulo guarda a trava de rolagem
|
|
11
|
+
* do body (`lockBodyScroll`/`unlockBodyScroll`), mais abaixo.
|
|
11
12
|
*/
|
|
12
13
|
const stack: string[] = [];
|
|
13
14
|
|
|
@@ -23,4 +24,51 @@ export const removeOverlay = (id: string): void => {
|
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
/** true se o overlay é o do topo — o único que deve reagir ao Esc. */
|
|
26
|
-
export const isTopOverlay = (id: string): boolean => stack.length > 0 && stack[stack.length - 1] === id
|
|
27
|
+
export const isTopOverlay = (id: string): boolean => stack.length > 0 && stack[stack.length - 1] === id;
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* Trava de rolagem da página (Modal). Uma lista de donos, separada da pilha
|
|
31
|
+
* acima porque nem todo overlay trava (ConfirmDialog, Drawer e BottomSheet
|
|
32
|
+
* não travam hoje). O primeiro dono guarda o `overflow` e o `padding-right`
|
|
33
|
+
* que o body tinha no estilo inline e trava; só o último a sair devolve os
|
|
34
|
+
* dois. Dois Modais abertos: fechar o de cima não destrava a página.
|
|
35
|
+
*/
|
|
36
|
+
const donosDaTrava: string[] = [];
|
|
37
|
+
let overflowOriginal = "";
|
|
38
|
+
let paddingOriginal = "";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Trava a rolagem do body em nome de `id` (idempotente). Compensa a largura
|
|
42
|
+
* da barra de rolagem no `padding-right`, para a página não pular para o
|
|
43
|
+
* lado quando a barra some. Sem `document` (SSR), não faz nada.
|
|
44
|
+
*/
|
|
45
|
+
export const lockBodyScroll = (id: string): void => {
|
|
46
|
+
if (typeof document === "undefined" || !document.body) return;
|
|
47
|
+
if (donosDaTrava.includes(id)) return;
|
|
48
|
+
donosDaTrava.push(id);
|
|
49
|
+
if (donosDaTrava.length > 1) return;
|
|
50
|
+
const body = document.body;
|
|
51
|
+
// Sem layout (clientWidth 0, como no jsdom), não há barra para medir.
|
|
52
|
+
const larguraDoConteudo = document.documentElement.clientWidth;
|
|
53
|
+
const larguraDaBarra = typeof window !== "undefined" && larguraDoConteudo > 0 ? window.innerWidth - larguraDoConteudo : 0;
|
|
54
|
+
overflowOriginal = body.style.overflow;
|
|
55
|
+
paddingOriginal = body.style.paddingRight;
|
|
56
|
+
if (larguraDaBarra > 0) {
|
|
57
|
+
const paddingAtual = parseFloat(window.getComputedStyle(body).paddingRight) || 0;
|
|
58
|
+
body.style.paddingRight = paddingAtual + larguraDaBarra + "px";
|
|
59
|
+
}
|
|
60
|
+
body.style.overflow = "hidden";
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** Solta a trava de `id`. A página só volta a rolar quando o último dono sai. */
|
|
64
|
+
export const unlockBodyScroll = (id: string): void => {
|
|
65
|
+
const index = donosDaTrava.indexOf(id);
|
|
66
|
+
if (index === -1) return;
|
|
67
|
+
donosDaTrava.splice(index, 1);
|
|
68
|
+
if (donosDaTrava.length > 0) return;
|
|
69
|
+
if (typeof document === "undefined" || !document.body) return;
|
|
70
|
+
document.body.style.overflow = overflowOriginal;
|
|
71
|
+
document.body.style.paddingRight = paddingOriginal;
|
|
72
|
+
overflowOriginal = "";
|
|
73
|
+
paddingOriginal = "";
|
|
74
|
+
}
|