@1doc/1ds-vue 2.9.0 → 2.11.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/CHANGELOG.md +653 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +164 -10
- package/dist/index.mjs +9734 -8309
- package/dist/index.umd.js +4 -4
- package/package.json +3 -3
- package/src/teste/accordion-controlado.test.mjs +75 -0
- package/src/teste/accordion-titulo-neutro.test.mjs +32 -0
- package/src/teste/appsubheader-regiao.test.mjs +18 -0
- package/src/teste/attachmentcard-lista.test.mjs +39 -0
- package/src/teste/attachmentcard-sm.test.mjs +28 -0
- package/src/teste/badge-attached-tom-padding.test.mjs +49 -0
- package/src/teste/badge-neutro-colado.test.mjs +30 -0
- package/src/teste/badge-tag.test.mjs +8 -0
- package/src/teste/button-densidade.test.mjs +33 -0
- package/src/teste/calendar-compacto.test.mjs +37 -0
- package/src/teste/calendar-slots-cabecalho.test.mjs +46 -0
- package/src/teste/coachmark-sem-veu.test.mjs +70 -0
- package/src/teste/coachmark-um-passo.test.mjs +47 -0
- package/src/teste/color-picker-xs.test.mjs +28 -0
- package/src/teste/datatable-arvore-variantes.test.mjs +194 -0
- package/src/teste/datatable-compacta-tom.test.mjs +70 -0
- package/src/teste/descriptionlist-compacta.test.mjs +32 -0
- package/src/teste/dom.mjs +2 -0
- package/src/teste/empty-state-titulo-rico.test.mjs +39 -0
- package/src/teste/input-agrupado.test.mjs +44 -0
- package/src/teste/input-ghost.test.mjs +37 -0
- package/src/teste/list-item-standalone.test.mjs +75 -0
- package/src/teste/list.test.mjs +2 -1
- package/src/teste/modal-proporcoes-1doc.test.mjs +38 -0
- package/src/teste/rich-text-editor-alinha-imagem-tabela.test.mjs +164 -0
- package/src/teste/rich-text-editor-estilo-de-texto.test.mjs +87 -0
- package/src/teste/segmented-contador.test.mjs +39 -0
- package/src/teste/segmented-superficie.test.mjs +40 -0
- package/src/teste/select-aberto-controlado-flutuante.test.mjs +120 -0
- package/src/teste/select-filtro-cor-tamanho.test.mjs +62 -0
- package/src/teste/select-item-com-escopo.test.mjs +68 -0
- package/src/teste/select-lista-filtro.test.mjs +112 -0
- package/src/teste/statcard-secundaria-tom.test.mjs +41 -0
- package/src/teste/statcard-tamanho-sm.test.mjs +34 -0
- package/src/teste/tabs-compacta-css.test.mjs +23 -0
- package/src/teste/tabs-compacta.test.mjs +27 -0
- package/src/teste/tag-positivo-tingido.test.mjs +56 -0
- package/src/teste/toast-acao-detalhes.test.mjs +48 -0
- package/src/teste/token-primary-lighter.test.mjs +48 -0
- package/src/utils/html-seguro.ts +105 -2
- package/src/utils/toast.ts +12 -2
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/** Select filtro: largura mínima da lista configurável e lista que não passa da janela, no Vue (DOM do jsdom). */
|
|
2
|
+
import { test, after } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { resolve } from "node:path";
|
|
6
|
+
import { montar, clicar, janela, proximoTick } from "./dom.mjs";
|
|
7
|
+
|
|
8
|
+
const montados = [];
|
|
9
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
10
|
+
|
|
11
|
+
const OPCOES = [
|
|
12
|
+
{ label: "Urgente", value: "urgente" },
|
|
13
|
+
{ label: "Revisão", value: "revisao" },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const abrir = async (props) => {
|
|
17
|
+
const m = await montar("Select/Select.vue", { ariaLabel: "x", options: OPCOES, ...props });
|
|
18
|
+
montados.push(m);
|
|
19
|
+
await clicar(m.raiz.querySelector(".umds-select__trigger"));
|
|
20
|
+
return m;
|
|
21
|
+
};
|
|
22
|
+
const lista = (m) => m.raiz.querySelector(".umds-select__dropdown");
|
|
23
|
+
|
|
24
|
+
/** jsdom não tem layout: só a lista "mede" o que o teste mandar. */
|
|
25
|
+
function medirLista(direita, larguraDaJanela) {
|
|
26
|
+
const original = janela.HTMLElement.prototype.getBoundingClientRect;
|
|
27
|
+
janela.HTMLElement.prototype.getBoundingClientRect = function () {
|
|
28
|
+
const eLista = this.classList.contains("umds-select__dropdown");
|
|
29
|
+
return { top: 0, bottom: 0, left: 0, right: eLista ? direita : 0, width: 0, height: 0, x: 0, y: 0 };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(janela, "innerWidth", { value: larguraDaJanela, configurable: true });
|
|
32
|
+
return () => (janela.HTMLElement.prototype.getBoundingClientRect = original);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
test("listMinWidth em número vira px; a lista nunca fica mais estreita que o gatilho", async () => {
|
|
36
|
+
const m = await abrir({ variant: "filter", listMinWidth: 220 });
|
|
37
|
+
assert.equal(lista(m).style.minWidth, "max(100%, 220px)");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("listMinWidth em medida CSS vale como veio", async () => {
|
|
41
|
+
const m = await abrir({ variant: "filter", listMinWidth: "18rem" });
|
|
42
|
+
assert.equal(lista(m).style.minWidth, "max(100%, 18rem)");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("listMinWidth 0 é um valor, não ausência", async () => {
|
|
46
|
+
const m = await abrir({ variant: "filter", listMinWidth: 0 });
|
|
47
|
+
assert.equal(lista(m).style.minWidth, "max(100%, 0px)");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("sem a prop o mínimo é o do CSS, sem estilo inline; o Select padrão ignora a prop", async () => {
|
|
51
|
+
assert.equal(lista(await abrir({ variant: "filter" })).style.minWidth, "");
|
|
52
|
+
assert.equal(lista(await abrir({ listMinWidth: 220 })).style.minWidth, "");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("a lista que estoura a borda direita se alinha ao fim do gatilho", async () => {
|
|
56
|
+
const restaurar = medirLista(1457, 1440);
|
|
57
|
+
try {
|
|
58
|
+
const m = await abrir({ variant: "filter" });
|
|
59
|
+
await proximoTick();
|
|
60
|
+
assert.ok(m.raiz.querySelector(".umds-select--list-end"));
|
|
61
|
+
} finally {
|
|
62
|
+
restaurar();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("a lista que cabe fica onde está, e o Select padrão não é movido", async () => {
|
|
67
|
+
const restaurar = medirLista(900, 1440);
|
|
68
|
+
try {
|
|
69
|
+
const m = await abrir({ variant: "filter" });
|
|
70
|
+
await proximoTick();
|
|
71
|
+
assert.equal(m.raiz.querySelector(".umds-select--list-end"), null);
|
|
72
|
+
} finally {
|
|
73
|
+
restaurar();
|
|
74
|
+
}
|
|
75
|
+
const restaurar2 = medirLista(1457, 1440);
|
|
76
|
+
try {
|
|
77
|
+
const m = await abrir({});
|
|
78
|
+
await proximoTick();
|
|
79
|
+
assert.equal(m.raiz.querySelector(".umds-select--list-end"), null);
|
|
80
|
+
} finally {
|
|
81
|
+
restaurar2();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("fechar desliga o alinhamento", async () => {
|
|
86
|
+
const restaurar = medirLista(1457, 1440);
|
|
87
|
+
try {
|
|
88
|
+
const m = await abrir({ variant: "filter" });
|
|
89
|
+
await proximoTick();
|
|
90
|
+
assert.ok(m.raiz.querySelector(".umds-select--list-end"));
|
|
91
|
+
await clicar(m.raiz.querySelector(".umds-select__trigger"));
|
|
92
|
+
await proximoTick();
|
|
93
|
+
assert.equal(m.raiz.querySelector(".umds-select--list-end"), null);
|
|
94
|
+
} finally {
|
|
95
|
+
restaurar();
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const css = readFileSync(resolve(process.cwd(), "../core/src/components/Select/Select.css"), "utf8").replace(/\r\n/g, "\n");
|
|
100
|
+
const bloco = (seletor) => {
|
|
101
|
+
const inicio = css.indexOf(seletor + " {");
|
|
102
|
+
return css.slice(inicio, css.indexOf("}", inicio));
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
test("CSS: wrapper fit-content, busca fora da conta da largura e alinhamento pela direita", () => {
|
|
106
|
+
assert.match(bloco(".umds-select--filter"), /width:\s*fit-content/);
|
|
107
|
+
assert.match(bloco(".umds-select--filter .umds-select__search-container"), /contain:\s*inline-size/);
|
|
108
|
+
assert.match(bloco(".umds-select__search-input"), /min-width:\s*0/);
|
|
109
|
+
const fim = bloco(".umds-select--filter.umds-select--list-end .umds-select__dropdown");
|
|
110
|
+
assert.match(fim, /left:\s*auto/);
|
|
111
|
+
assert.match(fim, /right:\s*0/);
|
|
112
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** StatCard: segunda medida e valueTone no Vue (DOM do jsdom). */
|
|
2
|
+
import { test, after } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { montar } from "./dom.mjs";
|
|
5
|
+
|
|
6
|
+
const montados = [];
|
|
7
|
+
const abrir = async (props) => {
|
|
8
|
+
const m = await montar("StatCard/StatCard.vue", props);
|
|
9
|
+
montados.push(m);
|
|
10
|
+
return m;
|
|
11
|
+
};
|
|
12
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
13
|
+
|
|
14
|
+
test("secondaryValue e secondaryLabel vêm depois do corpo, e o número principal segue antes do rótulo", async () => {
|
|
15
|
+
const m = await abrir({ value: "22,31%", label: "Eficiência", description: "Meu Setor", secondaryValue: "14,11%", secondaryLabel: "Geral", labelPosition: "top" });
|
|
16
|
+
const raiz = m.raiz.querySelector(".umds-stat-card");
|
|
17
|
+
assert.ok(raiz.classList.contains("umds-stat-card--com-secundaria"));
|
|
18
|
+
assert.equal(raiz.lastElementChild.className, "umds-stat-card__secundaria");
|
|
19
|
+
assert.equal(raiz.querySelector(".umds-stat-card__valor-secundario").textContent.trim(), "14,11%");
|
|
20
|
+
assert.equal(raiz.querySelector(".umds-stat-card__rotulo-secundario").textContent.trim(), "Geral");
|
|
21
|
+
const texto = raiz.textContent;
|
|
22
|
+
assert.ok(texto.indexOf("22,31%") < texto.indexOf("Eficiência"));
|
|
23
|
+
assert.ok(texto.indexOf("Eficiência") < texto.indexOf("14,11%"));
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("secondaryValue 0 aparece; vazio e ausente não", async () => {
|
|
27
|
+
const zero = await abrir({ value: "5", label: "x", secondaryValue: 0 });
|
|
28
|
+
assert.equal(zero.raiz.querySelector(".umds-stat-card__valor-secundario").textContent.trim(), "0");
|
|
29
|
+
const vazio = await abrir({ value: "5", label: "x", secondaryValue: "" });
|
|
30
|
+
assert.equal(vazio.raiz.querySelector(".umds-stat-card__secundaria"), null);
|
|
31
|
+
const sem = await abrir({ value: "5", label: "x" });
|
|
32
|
+
assert.equal(sem.raiz.querySelector(".umds-stat-card__secundaria"), null);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("valueTone escreve a classe do tom; default e ausente não; a variant do ícone fica", async () => {
|
|
36
|
+
const n = await abrir({ value: "5", label: "x", valueTone: "negative", variant: "positive" });
|
|
37
|
+
const c = n.raiz.querySelector(".umds-stat-card").classList;
|
|
38
|
+
assert.ok(c.contains("umds-stat-card--valor-negative") && c.contains("umds-stat-card--positive"));
|
|
39
|
+
const d = await abrir({ value: "5", label: "x", valueTone: "default" });
|
|
40
|
+
assert.doesNotMatch(d.raiz.querySelector(".umds-stat-card").className, /valor-/);
|
|
41
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** StatCard size="sm" no Vue (DOM do jsdom). */
|
|
2
|
+
import { test, after } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { resolve } from "node:path";
|
|
6
|
+
import { montar } from "./dom.mjs";
|
|
7
|
+
|
|
8
|
+
const montados = [];
|
|
9
|
+
const abrir = async (props) => {
|
|
10
|
+
const m = await montar("StatCard/StatCard.vue", { value: 44, label: "Não lidos", ...props });
|
|
11
|
+
montados.push(m);
|
|
12
|
+
return m.raiz.querySelector(".umds-stat-card");
|
|
13
|
+
};
|
|
14
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
15
|
+
|
|
16
|
+
const css = readFileSync(resolve(process.cwd(), "../core/src/components/StatCard/StatCard.css"), "utf8").replace(/\r\n/g, "\n");
|
|
17
|
+
const bloco = (seletor) => {
|
|
18
|
+
const inicio = css.indexOf(seletor + " {");
|
|
19
|
+
return css.slice(inicio, css.indexOf("}", inicio));
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
test("sm escreve a classe; sem a prop e com md o cartão é o de antes", async () => {
|
|
23
|
+
assert.ok((await abrir({ size: "sm" })).classList.contains("umds-stat-card--sm"));
|
|
24
|
+
assert.ok(!(await abrir({})).classList.contains("umds-stat-card--sm"));
|
|
25
|
+
assert.ok(!(await abrir({ size: "md" })).classList.contains("umds-stat-card--sm"));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("o número do sm é 18px/800 e a regra vence o 32/800 do rótulo no topo", async () => {
|
|
29
|
+
const regra = bloco(".umds-stat-card.umds-stat-card--sm .umds-stat-card__valor");
|
|
30
|
+
assert.match(regra, /font-size:\s*1\.125rem/);
|
|
31
|
+
assert.match(regra, /font-weight:\s*var\(--umds-primitive-font-weight-extrabold\)/);
|
|
32
|
+
const c = (await abrir({ size: "sm", labelPosition: "top" })).classList;
|
|
33
|
+
assert.ok(c.contains("umds-stat-card--sm") && c.contains("umds-stat-card--rotulo-topo"));
|
|
34
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Tabs no Vue (classes no DOM e regras de CSS na fonte). */
|
|
2
|
+
import { test, after } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { resolve } from "node:path";
|
|
6
|
+
|
|
7
|
+
const css = (componente) =>
|
|
8
|
+
readFileSync(resolve(process.cwd(), `../core/src/components/${componente}/${componente}.css`), "utf8").replace(/\r\n/g, "\n");
|
|
9
|
+
const bloco = (texto, seletor) => {
|
|
10
|
+
const inicio = texto.indexOf(seletor + " {");
|
|
11
|
+
assert.ok(inicio >= 0, seletor);
|
|
12
|
+
return texto.slice(inicio, texto.indexOf("}", inicio));
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
test("Tabs CSS: compacta de 40px com padding vertical de 8px; padrão em 48px; pílula cinza na inativa e azul só na ativa", () => {
|
|
16
|
+
const t = css("Tabs");
|
|
17
|
+
const compacta = bloco(t, ".umds-tabs--compact .umds-tabs__tab");
|
|
18
|
+
assert.match(compacta, /min-height:\s*var\(--umds-primitive-spacing-sm\)/);
|
|
19
|
+
assert.match(compacta, /padding-block:\s*var\(--umds-primitive-spacing-nano\)/);
|
|
20
|
+
assert.match(bloco(t, ".umds-tabs__tab"), /min-height:\s*48px/);
|
|
21
|
+
assert.match(bloco(t, ".umds-tabs__count"), /background-color:\s*var\(--umds-semantic-color-neutral-light-medium\)/);
|
|
22
|
+
assert.match(bloco(t, ".umds-tabs__tab--selected .umds-tabs__count"), /background-color:\s*var\(--umds-semantic-color-primary-pure\)/);
|
|
23
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Tabs density compact, conferido no HTML que o Vue GERADO escreve. */
|
|
2
|
+
import { test, before, after } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { h } from "vue";
|
|
5
|
+
import { abrir, fechar, carregar, renderizar } from "./renderizar.mjs";
|
|
6
|
+
|
|
7
|
+
let Tabs, Tab;
|
|
8
|
+
|
|
9
|
+
before(async () => {
|
|
10
|
+
await abrir();
|
|
11
|
+
Tabs = await carregar("Tabs/Tabs.vue");
|
|
12
|
+
Tab = await carregar("Tabs/Tab.vue");
|
|
13
|
+
});
|
|
14
|
+
after(fechar);
|
|
15
|
+
|
|
16
|
+
const comAbas = (propsDoTabs) =>
|
|
17
|
+
renderizar(Tabs, propsDoTabs, { default: () => [h(Tab, { label: "Fluxos", index: "0", count: 56 })] });
|
|
18
|
+
|
|
19
|
+
test("density compact escreve a classe na raiz; sem a prop e com default, não", async () => {
|
|
20
|
+
assert.match(await comAbas({ value: "0", density: "compact" }), /class="umds-tabs umds-tabs--compact"/);
|
|
21
|
+
assert.doesNotMatch(await comAbas({ value: "0" }), /umds-tabs--compact/);
|
|
22
|
+
assert.doesNotMatch(await comAbas({ value: "0", density: "default" }), /umds-tabs--compact/);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("o contador segue escrito na densidade compacta", async () => {
|
|
26
|
+
assert.match(await comAbas({ value: "0", density: "compact" }), /umds-tabs__count[^>]*>56</);
|
|
27
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** Tag positive outlined sobre fundo tingido, no Vue: as classes no DOM, a regra de CSS e o contraste dos tokens. */
|
|
2
|
+
import { test, after } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { resolve } from "node:path";
|
|
6
|
+
import { montar } from "./dom.mjs";
|
|
7
|
+
|
|
8
|
+
const montados = [];
|
|
9
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
10
|
+
|
|
11
|
+
const css = readFileSync(resolve(process.cwd(), "../core/src/components/Tag/Tag.css"), "utf8").replace(/\r\n/g, "\n");
|
|
12
|
+
const bloco = (seletor) => {
|
|
13
|
+
const inicio = css.indexOf(seletor + " {");
|
|
14
|
+
return css.slice(inicio, css.indexOf("}", inicio));
|
|
15
|
+
};
|
|
16
|
+
const tema = (arquivo) => {
|
|
17
|
+
const texto = readFileSync(resolve(process.cwd(), "../tokens/dist/css/" + arquivo), "utf8");
|
|
18
|
+
return (nome) => texto.match(new RegExp("--umds-theme-" + nome + ":\\s*(#[0-9A-Fa-f]{6})"))[1];
|
|
19
|
+
};
|
|
20
|
+
const luz = (hex) => {
|
|
21
|
+
const c = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255).map((v) => (v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4));
|
|
22
|
+
return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
|
|
23
|
+
};
|
|
24
|
+
const contraste = (a, b) => {
|
|
25
|
+
const [x, y] = [luz(a), luz(b)].sort((m, n) => n - m);
|
|
26
|
+
return (x + 0.05) / (y + 0.05);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
test("escreve as classes que a regra de CSS escolhe", async () => {
|
|
30
|
+
const m = await montar("Tag/Tag.vue", { label: "Entregue", variant: "positive", appearance: "outlined" });
|
|
31
|
+
montados.push(m);
|
|
32
|
+
const c = m.raiz.querySelector(".umds-tag").classList;
|
|
33
|
+
assert.ok(c.contains("umds-tag--outlined") && c.contains("umds-tag--positive"));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("CSS: texto positive-dark e contorno positive-pure", () => {
|
|
37
|
+
const regra = bloco(".umds-tag--outlined.umds-tag--positive");
|
|
38
|
+
assert.match(regra, /color:\s*var\(--umds-semantic-color-feedback-positive-dark\)/);
|
|
39
|
+
assert.match(regra, /border-color:\s*var\(--umds-semantic-color-feedback-positive-pure\)/);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("tema 1doc: sobre o azul-claro do card o pure dava menos de 4,5:1 e o dark passa", () => {
|
|
43
|
+
const cor = tema("theme-1doc.css");
|
|
44
|
+
const fundo = cor("primary-light");
|
|
45
|
+
assert.ok(contraste(cor("feedback-positive-pure"), fundo) < 4.5);
|
|
46
|
+
assert.ok(contraste(cor("feedback-positive-dark"), fundo) >= 4.5);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("temas escuro e de alto contraste: o texto passa de 4,5:1 sobre o fundo tingido e sobre a página", () => {
|
|
50
|
+
for (const arquivo of ["theme-1doc-dark.css", "theme-1doc-high-contrast.css"]) {
|
|
51
|
+
const cor = tema(arquivo);
|
|
52
|
+
for (const fundo of [cor("primary-light"), cor("background-white")]) {
|
|
53
|
+
assert.ok(contraste(cor("feedback-positive-dark"), fundo) >= 4.5, arquivo);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Toast com ação e detalhes no Vue (DOM do jsdom; o Toast vai por Teleport para o body). */
|
|
2
|
+
import { test, after } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { montar, documento, clicar, proximoTick } from "./dom.mjs";
|
|
5
|
+
|
|
6
|
+
const montados = [];
|
|
7
|
+
const abrir = async (props) => {
|
|
8
|
+
const m = await montar("Toast/Toast.vue", props);
|
|
9
|
+
montados.push(m);
|
|
10
|
+
await proximoTick();
|
|
11
|
+
return m;
|
|
12
|
+
};
|
|
13
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
14
|
+
|
|
15
|
+
const botao = (nome) => [...documento.querySelectorAll(".umds-toast button")].find((b) => b.textContent.trim() === nome || b.getAttribute("aria-label") === nome);
|
|
16
|
+
|
|
17
|
+
test("actionLabel com onAction desenha o botão; acionar chama onAction e depois fecha", async () => {
|
|
18
|
+
const ordem = [];
|
|
19
|
+
const m = await abrir({ open: true, message: "Despacho enviado", actionLabel: "Desfazer", onAction: () => ordem.push("acao"), onClose: () => ordem.push("fechar") });
|
|
20
|
+
await clicar(botao("Desfazer"));
|
|
21
|
+
assert.deepEqual(ordem, ["acao", "fechar"]);
|
|
22
|
+
m.desmontar();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("sem onAction (ou sem actionLabel) não há botão de ação", async () => {
|
|
26
|
+
const a = await abrir({ open: true, message: "x", actionLabel: "Desfazer" });
|
|
27
|
+
assert.equal(documento.querySelector(".umds-toast__action"), null);
|
|
28
|
+
a.desmontar();
|
|
29
|
+
const b = await abrir({ open: true, message: "x", onAction: () => {} });
|
|
30
|
+
assert.equal(documento.querySelector(".umds-toast__action"), null);
|
|
31
|
+
b.desmontar();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("details vira uma lista de linhas; sem details não há lista", async () => {
|
|
35
|
+
const m = await abrir({ open: true, message: "3 anexos não enviados", details: ["Anexo 1 acima de 10 MB", "Anexo 2 sem assunto"] });
|
|
36
|
+
const itens = [...documento.querySelectorAll(".umds-toast__details li")].map((l) => l.textContent.trim());
|
|
37
|
+
assert.deepEqual(itens, ["Anexo 1 acima de 10 MB", "Anexo 2 sem assunto"]);
|
|
38
|
+
m.desmontar();
|
|
39
|
+
const sem = await abrir({ open: true, message: "Salvo" });
|
|
40
|
+
assert.equal(documento.querySelector(".umds-toast__details"), null);
|
|
41
|
+
sem.desmontar();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("o botão de fechar continua ao lado da ação", async () => {
|
|
45
|
+
const m = await abrir({ open: true, message: "x", actionLabel: "Desfazer", onAction: () => {} });
|
|
46
|
+
assert.ok(botao("Fechar notificação"));
|
|
47
|
+
m.desmontar();
|
|
48
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Token primary-lighter (o fundo azul bem claro do CrisDoc): existe no semântico e em todos os temas, e o texto passa nele. */
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
5
|
+
import { resolve } from "node:path";
|
|
6
|
+
|
|
7
|
+
const css = resolve(process.cwd(), "../tokens/dist/css");
|
|
8
|
+
const ler = (arquivo) => readFileSync(resolve(css, arquivo), "utf8");
|
|
9
|
+
const cor = (texto, nome) => texto.match(new RegExp("--umds-theme-" + nome + ":\\s*(#[0-9A-Fa-f]{6})"))[1];
|
|
10
|
+
const luz = (hex) => {
|
|
11
|
+
const c = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255).map((v) => (v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4));
|
|
12
|
+
return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
|
|
13
|
+
};
|
|
14
|
+
const contraste = (a, b) => {
|
|
15
|
+
const [x, y] = [luz(a), luz(b)].sort((m, n) => n - m);
|
|
16
|
+
return (x + 0.05) / (y + 0.05);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
test("o semântico aponta para o token do tema", () => {
|
|
20
|
+
assert.match(ler("semantic.css"), /--umds-semantic-color-primary-lighter:\s*var\(--umds-theme-primary-lighter\)/);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("o tema claro 1doc é o #EDF2FF do CrisDoc, e o escuro tem o seu", () => {
|
|
24
|
+
assert.equal(cor(ler("theme-1doc.css"), "primary-lighter").toUpperCase(), "#EDF2FF");
|
|
25
|
+
assert.ok(cor(ler("theme-1doc-dark.css"), "primary-lighter"));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("todo tema tem o primary-lighter (sem ele a cor herdaria a do tema azul)", () => {
|
|
29
|
+
const temas = readdirSync(css).filter((f) => /^theme-.*\.css$/.test(f));
|
|
30
|
+
assert.ok(temas.length >= 13, "esperava os 13 temas");
|
|
31
|
+
for (const f of temas) assert.ok(cor(ler(f), "primary-lighter"), f);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("é mais claro que o primary-light nos temas claros e o texto escuro passa de 4,5:1 sobre ele", () => {
|
|
35
|
+
for (const f of ["theme-1doc.css"]) {
|
|
36
|
+
const t = ler(f);
|
|
37
|
+
assert.ok(luz(cor(t, "primary-lighter")) > luz(cor(t, "primary-light")), f);
|
|
38
|
+
assert.ok(contraste(cor(t, "neutral-dark-pure"), cor(t, "primary-lighter")) >= 4.5, f);
|
|
39
|
+
assert.ok(contraste(cor(t, "primary-dark"), cor(t, "primary-lighter")) >= 4.5, f);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("nos temas escuro e de alto contraste o texto do tema passa de 4,5:1 sobre ele", () => {
|
|
44
|
+
for (const f of ["theme-1doc-dark.css", "theme-1doc-high-contrast.css"]) {
|
|
45
|
+
const t = ler(f);
|
|
46
|
+
assert.ok(contraste(cor(t, "neutral-dark-pure"), cor(t, "primary-lighter")) >= 4.5, f);
|
|
47
|
+
}
|
|
48
|
+
});
|
package/src/utils/html-seguro.ts
CHANGED
|
@@ -5,14 +5,20 @@
|
|
|
5
5
|
* fora (um valor guardado, um texto colado) pode trazer `<img onerror>`,
|
|
6
6
|
* `<a href="javascript:...">`, `<script>`, `style` e classes de outro site. Este
|
|
7
7
|
* módulo reduz o HTML ao que o editor sabe escrever: negrito, itálico,
|
|
8
|
-
* sublinhado, tachado, listas, parágrafos, quebras, títulos, citação
|
|
8
|
+
* sublinhado, tachado, listas, parágrafos, quebras, títulos, citação, link,
|
|
9
|
+
* estilo de texto por token (`color`, `font-size`, `font-family` em `<span>`),
|
|
10
|
+
* alinhamento de bloco (`text-align`), imagem (`http(s)`, caminho ou `data:image`
|
|
11
|
+
* em PNG, JPEG, GIF e WebP) e tabela simples.
|
|
9
12
|
*
|
|
10
13
|
* Roda no navegador (precisa de DOM). Dentro de um `<template>` o HTML é inerte:
|
|
11
14
|
* nada executa e nenhuma imagem carrega enquanto se higieniza. Sem DOM
|
|
12
15
|
* (servidor), devolve o texto escapado.
|
|
13
16
|
*/
|
|
14
17
|
|
|
15
|
-
const PERMITIDAS = ["A", "B", "STRONG", "I", "EM", "U", "S", "STRIKE", "DEL", "UL", "OL", "LI", "P", "BR", "DIV", "SPAN", "H1", "H2", "H3", "H4", "BLOCKQUOTE"];
|
|
18
|
+
const PERMITIDAS = ["A", "B", "STRONG", "I", "EM", "U", "S", "STRIKE", "DEL", "UL", "OL", "LI", "P", "BR", "DIV", "SPAN", "H1", "H2", "H3", "H4", "BLOCKQUOTE", "IMG", "TABLE", "THEAD", "TBODY", "TR", "TH", "TD"];
|
|
19
|
+
/** Blocos que aceitam `text-align`. */
|
|
20
|
+
const ALINHAVEIS = ["P", "DIV", "H1", "H2", "H3", "H4", "LI", "BLOCKQUOTE", "TH", "TD"];
|
|
21
|
+
const ALINHAMENTOS = ["left", "center", "right", "justify"];
|
|
16
22
|
const DESCARTADAS = ["SCRIPT", "STYLE", "IFRAME", "OBJECT", "EMBED", "LINK", "META", "TEMPLATE", "NOSCRIPT", "SVG", "MATH", "FORM", "INPUT", "BUTTON", "TEXTAREA", "SELECT"];
|
|
17
23
|
const escapar = (texto: string): string => texto.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
18
24
|
|
|
@@ -41,6 +47,66 @@ export const normalizarEndereco = (bruto: string): string => {
|
|
|
41
47
|
if (/^[a-z][a-z0-9+.-]*:/i.test(semControle)) return "";
|
|
42
48
|
return "https://" + texto;
|
|
43
49
|
};
|
|
50
|
+
|
|
51
|
+
/** Cor, tamanho e família de fonte só valem como TOKEN do DS: `var(--umds-...)`. Cor em hex, rgb ou nome sai. */
|
|
52
|
+
const COR_TOKEN = /^var\(--umds-(?:primitive|semantic)-[a-z0-9-]+\)$/;
|
|
53
|
+
const TAMANHO_TOKEN = /^var\(--umds-primitive-font-size-[a-z0-9]+\)$/;
|
|
54
|
+
const FAMILIA_TOKEN = /^var\(--umds-(?:primitive|semantic)-font-family-(?:base|mono)\)$/;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Declaração de estilo de texto que o editor aceita: `color`, `font-size` e `font-family`,
|
|
58
|
+
* cada uma só com um token do DS. Devolve a declaração limpa ("color: var(--x);") ou "".
|
|
59
|
+
*/
|
|
60
|
+
export const estiloDeTexto = (propriedade: string, valor: string): string => {
|
|
61
|
+
const prop = String(propriedade || "").trim().toLowerCase();
|
|
62
|
+
const val = String(valor || "").trim();
|
|
63
|
+
if (prop === "color" && COR_TOKEN.test(val)) return "color: " + val + ";";
|
|
64
|
+
if (prop === "font-size" && TAMANHO_TOKEN.test(val)) return "font-size: " + val + ";";
|
|
65
|
+
if (prop === "font-family" && FAMILIA_TOKEN.test(val)) return "font-family: " + val + ";";
|
|
66
|
+
return "";
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/** As declarações válidas de um atributo `style` (só color, font-size e font-family por token). */
|
|
70
|
+
const estiloDoSpan = (estilo: string): string => {
|
|
71
|
+
const partes = String(estilo || "").split(";");
|
|
72
|
+
let saida = "";
|
|
73
|
+
for (let i = 0; i < partes.length; i++) {
|
|
74
|
+
const corte = partes[i].indexOf(":");
|
|
75
|
+
if (corte === -1) continue;
|
|
76
|
+
const decl = estiloDeTexto(partes[i].slice(0, corte), partes[i].slice(corte + 1));
|
|
77
|
+
if (decl) saida += (saida ? " " : "") + decl;
|
|
78
|
+
}
|
|
79
|
+
return saida;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Endereço de imagem que o editor aceita: `http(s)`, caminho (`/x`, `./x`, `../x`) ou
|
|
84
|
+
* `data:image` em base64 de PNG, JPEG, GIF ou WebP (SVG fica de fora: carrega script).
|
|
85
|
+
* Devolve o endereço limpo, ou "" se for perigoso ou vazio.
|
|
86
|
+
*/
|
|
87
|
+
export const imagemSegura = (bruto: string): string => {
|
|
88
|
+
const texto = (bruto || "").trim();
|
|
89
|
+
if (!texto) return "";
|
|
90
|
+
const semControle = texto.replace(/[\u0000-\u001f\u007f\s]+/g, "");
|
|
91
|
+
if (/^data:image\/(png|jpe?g|gif|webp);base64,[a-z0-9+/]+=*$/i.test(semControle)) return semControle;
|
|
92
|
+
// `//host/x` (sem esquema) carregaria de outro site sem o autor ter pedido: fica de fora.
|
|
93
|
+
if (/^(https?:\/\/|\/(?!\/)|\.\.?\/)/i.test(semControle)) return texto;
|
|
94
|
+
return "";
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** O `text-align` de um elemento, pelo `style` ou pelo atributo `align`: left, center, right, justify ou "". */
|
|
98
|
+
const alinhamentoDe = (elemento: any): string => {
|
|
99
|
+
const estilo = String(elemento.getAttribute("style") || "");
|
|
100
|
+
const achado = /(?:^|;)\s*text-align\s*:\s*([a-z]+)\s*(?:;|$)/i.exec(estilo);
|
|
101
|
+
const valor = (achado ? achado[1] : String(elemento.getAttribute("align") || "")).toLowerCase();
|
|
102
|
+
return ALINHAMENTOS.indexOf(valor) !== -1 ? valor : "";
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/** Número inteiro de 2 a 99 em `colspan`/`rowspan`; o resto some. */
|
|
106
|
+
const vao = (valor: any): string => {
|
|
107
|
+
const n = parseInt(String(valor || ""), 10);
|
|
108
|
+
return n >= 2 && n <= 99 ? String(n) : "";
|
|
109
|
+
};
|
|
44
110
|
const limparNo = (no: any, saida: any, documento: any): void => {
|
|
45
111
|
const filhos = Array.prototype.slice.call(no.childNodes);
|
|
46
112
|
for (let i = 0; i < filhos.length; i++) {
|
|
@@ -57,7 +123,31 @@ const limparNo = (no: any, saida: any, documento: any): void => {
|
|
|
57
123
|
limparNo(filho, saida, documento);
|
|
58
124
|
continue;
|
|
59
125
|
}
|
|
126
|
+
if (tag === "IMG") {
|
|
127
|
+
// Imagem sem endereço seguro some inteira (não deixa um <img> quebrado nem carregando de fora).
|
|
128
|
+
const origem = imagemSegura(filho.getAttribute("src") || "");
|
|
129
|
+
if (!origem) continue;
|
|
130
|
+
const imagem = documento.createElement("img");
|
|
131
|
+
imagem.setAttribute("src", origem);
|
|
132
|
+
imagem.setAttribute("alt", String(filho.getAttribute("alt") || ""));
|
|
133
|
+
saida.appendChild(imagem);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
60
136
|
const novo = documento.createElement(tag.toLowerCase());
|
|
137
|
+
if (ALINHAVEIS.indexOf(tag) !== -1) {
|
|
138
|
+
const alinhamento = alinhamentoDe(filho);
|
|
139
|
+
if (alinhamento) novo.setAttribute("style", "text-align: " + alinhamento + ";");
|
|
140
|
+
}
|
|
141
|
+
if (tag === "SPAN") {
|
|
142
|
+
const estiloValido = estiloDoSpan(filho.getAttribute("style") || "");
|
|
143
|
+
if (estiloValido) novo.setAttribute("style", estiloValido);
|
|
144
|
+
}
|
|
145
|
+
if (tag === "TD" || tag === "TH") {
|
|
146
|
+
const colunas = vao(filho.getAttribute("colspan"));
|
|
147
|
+
const linhas = vao(filho.getAttribute("rowspan"));
|
|
148
|
+
if (colunas) novo.setAttribute("colspan", colunas);
|
|
149
|
+
if (linhas) novo.setAttribute("rowspan", linhas);
|
|
150
|
+
}
|
|
61
151
|
if (tag === "A") {
|
|
62
152
|
const href = enderecoSeguro(filho.getAttribute("href") || "");
|
|
63
153
|
if (href) {
|
|
@@ -81,8 +171,21 @@ export const sanitizarHtml = (html: string): string => {
|
|
|
81
171
|
return saida.innerHTML;
|
|
82
172
|
};
|
|
83
173
|
|
|
174
|
+
/** A tabela vazia que o editor insere: `linhas` × `colunas` células com uma quebra, para o cursor entrar. */
|
|
175
|
+
export const htmlDaTabela = (linhas: number, colunas: number): string => {
|
|
176
|
+
let celulas = "";
|
|
177
|
+
for (let c = 0; c < colunas; c++) celulas += "<td><br></td>";
|
|
178
|
+
let corpo = "";
|
|
179
|
+
for (let l = 0; l < linhas; l++) corpo += "<tr>" + celulas + "</tr>";
|
|
180
|
+
return "<table><tbody>" + corpo + "</tbody></table><p><br></p>";
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/** O `<img>` que o editor insere (endereço já seguro). */
|
|
184
|
+
export const htmlDaImagem = (endereco: string, alt: string): string => '<img src="' + escapar(endereco) + '" alt="' + escapar(alt || "") + '">';
|
|
185
|
+
|
|
84
186
|
/** O editor está "vazio": sem texto, sem lista e sem quebra solta (o `<br>` que o navegador deixa). */
|
|
85
187
|
export const htmlVazio = (html: string): boolean => {
|
|
188
|
+
if (/<(img|table)[\s>]/i.test(html || "")) return false;
|
|
86
189
|
const texto = (html || "").replace(/<br\s*\/?>/gi, "").replace(/<\/?(div|p|span)[^>]*>/gi, "").trim();
|
|
87
190
|
return texto === "";
|
|
88
191
|
};
|
package/src/utils/toast.ts
CHANGED
|
@@ -22,7 +22,13 @@ export interface ToastOptions {
|
|
|
22
22
|
description?: string;
|
|
23
23
|
/** Variante semântica @default 'info' */
|
|
24
24
|
variant?: ToastVariant;
|
|
25
|
-
/**
|
|
25
|
+
/** Linhas de detalhe abaixo da descrição */
|
|
26
|
+
details?: string[];
|
|
27
|
+
/** Rótulo do botão de ação ("Desfazer"); só aparece com `onAction` */
|
|
28
|
+
actionLabel?: string;
|
|
29
|
+
/** Chamado ao acionar o botão de ação; depois dele o toast fecha */
|
|
30
|
+
onAction?: (event?: any) => void;
|
|
31
|
+
/** Auto-dismiss em ms; 0 = não fecha sozinho @default 5000 (0 quando há ação: dá tempo de agir, WCAG 2.2.1) */
|
|
26
32
|
duration?: number;
|
|
27
33
|
/** Exibe o botão de fechar @default true */
|
|
28
34
|
closable?: boolean;
|
|
@@ -31,6 +37,9 @@ export interface ToastData {
|
|
|
31
37
|
id: number;
|
|
32
38
|
message: string;
|
|
33
39
|
description?: string;
|
|
40
|
+
details?: string[];
|
|
41
|
+
actionLabel?: string;
|
|
42
|
+
onAction?: (event?: any) => void;
|
|
34
43
|
variant: ToastVariant;
|
|
35
44
|
duration: number;
|
|
36
45
|
closable: boolean;
|
|
@@ -50,7 +59,8 @@ export const toast = (options: ToastOptions): number => {
|
|
|
50
59
|
const id = sequence;
|
|
51
60
|
items = [...items, {
|
|
52
61
|
variant: "info",
|
|
53
|
-
|
|
62
|
+
// Toast com ação não some antes de dar tempo de agir.
|
|
63
|
+
duration: options.actionLabel && options.onAction ? 0 : 5000,
|
|
54
64
|
closable: true,
|
|
55
65
|
...options,
|
|
56
66
|
id
|