@1doc/1ds-vue 2.8.0 → 2.9.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 +1115 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1016 -28
- package/dist/index.mjs +10524 -7523
- package/dist/index.umd.js +4 -4
- package/package.json +5 -4
- package/src/index.ts +26 -0
- package/src/teste/accordion-conteudo-livre.test.mjs +44 -0
- package/src/teste/atributos.test.mjs +91 -0
- package/src/teste/attachmentcard-ia.test.mjs +48 -0
- package/src/teste/avatargroup-overlap.test.mjs +45 -0
- package/src/teste/badge-tag.test.mjs +45 -0
- package/src/teste/box-item-flex.test.mjs +84 -0
- package/src/teste/box-layout.test.mjs +57 -0
- package/src/teste/button.test.mjs +34 -0
- package/src/teste/calendar.test.mjs +179 -0
- package/src/teste/chips-xs.test.mjs +33 -0
- package/src/teste/coachmark.test.mjs +119 -0
- package/src/teste/color-picker.test.mjs +79 -0
- package/src/teste/datatable-documento.test.mjs +106 -0
- package/src/teste/datatable-slots.test.mjs +105 -0
- package/src/teste/dom.mjs +168 -0
- package/src/teste/fileinput-trigger.test.mjs +36 -0
- package/src/teste/icon-picker.test.mjs +98 -0
- package/src/teste/input-mascara-afins.test.mjs +64 -0
- package/src/teste/kbd-code-block.test.mjs +76 -0
- package/src/teste/list.test.mjs +162 -0
- package/src/teste/modal-variantes.test.mjs +79 -0
- package/src/teste/org-chart.test.mjs +131 -0
- package/src/teste/otp-input.test.mjs +130 -0
- package/src/teste/popover-maxheight.test.mjs +26 -0
- package/src/teste/renderizar.mjs +64 -0
- package/src/teste/rich-text-editor.test.mjs +210 -0
- package/src/teste/select-placement-filtro.test.mjs +49 -0
- package/src/teste/stack-box-raiz-unica.test.mjs +134 -0
- package/src/teste/stack.test.mjs +80 -0
- package/src/teste/statcard-rotulo-topo.test.mjs +34 -0
- package/src/teste/tabs-contador-fechavel.test.mjs +60 -0
- package/src/teste/tooltip-dark.test.mjs +28 -0
- package/src/utils/calendario.ts +78 -0
- package/src/utils/html-seguro.ts +94 -0
- package/src/utils/paleta-de-cores.ts +34 -0
- package/src/utils/texto.ts +5 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Select: variant filter e footer, conferidos no HTML que o Vue GERADO escreve (a lista só existe aberta, então o que o SSR mostra é o gatilho). */
|
|
2
|
+
import { test, before, after } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { abrir, fechar, carregar, renderizar } from "./renderizar.mjs";
|
|
5
|
+
|
|
6
|
+
let Select;
|
|
7
|
+
|
|
8
|
+
before(async () => {
|
|
9
|
+
await abrir();
|
|
10
|
+
Select = await carregar("Select/Select.vue");
|
|
11
|
+
});
|
|
12
|
+
after(fechar);
|
|
13
|
+
|
|
14
|
+
const opcoes = [
|
|
15
|
+
{ label: "Urgente", value: "urgente" },
|
|
16
|
+
{ label: "Revisão", value: "revisao" },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
test("variant filter escreve a classe; sem variant não escreve", async () => {
|
|
20
|
+
assert.match(await renderizar(Select, { ariaLabel: "x", options: opcoes, variant: "filter" }), /umds-select--filter/);
|
|
21
|
+
assert.doesNotMatch(await renderizar(Select, { ariaLabel: "x", options: opcoes }), /umds-select--filter/);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("sem placement a lista não leva a classe de abrir para cima", async () => {
|
|
25
|
+
assert.doesNotMatch(await renderizar(Select, { ariaLabel: "x", options: opcoes }), /umds-select--placement-top/);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("com emptyOptionLabel e valor vazio o gatilho mostra o placeholder (nome do filtro)", async () => {
|
|
29
|
+
const html = await renderizar(Select, {
|
|
30
|
+
ariaLabel: "Marcadores",
|
|
31
|
+
placeholder: "Marcadores",
|
|
32
|
+
options: opcoes,
|
|
33
|
+
emptyOptionLabel: "Todos os marcadores",
|
|
34
|
+
value: "",
|
|
35
|
+
});
|
|
36
|
+
assert.match(html, /umds-select__placeholder[^>]*>(?:<!--[^>]*-->)*Marcadores</);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("com emptyOptionLabel e um valor escolhido o gatilho mostra a opção", async () => {
|
|
40
|
+
const html = await renderizar(Select, {
|
|
41
|
+
ariaLabel: "Marcadores",
|
|
42
|
+
placeholder: "Marcadores",
|
|
43
|
+
options: opcoes,
|
|
44
|
+
emptyOptionLabel: "Todos os marcadores",
|
|
45
|
+
value: "urgente",
|
|
46
|
+
});
|
|
47
|
+
assert.match(html, />Urgente</);
|
|
48
|
+
assert.doesNotMatch(html, /umds-select__placeholder/);
|
|
49
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stack e Box no Vue: raiz ÚNICA e o que o consumidor passa chega ao elemento.
|
|
3
|
+
*
|
|
4
|
+
* O defeito: o gerado tinha raiz em fragmento (um `<template v-if>` por tag) e
|
|
5
|
+
* só repassava uma lista fixa de atributos. `@click`, `@keydown`, `draggable`,
|
|
6
|
+
* `tabindex` e o `ref` do componente sumiam em silêncio. Aqui o componente é
|
|
7
|
+
* montado num DOM (jsdom) e o teste dispara o evento de verdade.
|
|
8
|
+
*/
|
|
9
|
+
import { test, after } from "node:test";
|
|
10
|
+
import assert from "node:assert/strict";
|
|
11
|
+
import { montar, janela, proximoTick } from "./dom.mjs";
|
|
12
|
+
|
|
13
|
+
const montados = [];
|
|
14
|
+
const abrir = async (...args) => {
|
|
15
|
+
const m = await montar(...args);
|
|
16
|
+
montados.push(m);
|
|
17
|
+
return m;
|
|
18
|
+
};
|
|
19
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
20
|
+
|
|
21
|
+
for (const [nome, caminho, classe] of [
|
|
22
|
+
["Stack", "Stack/Stack.vue", "umds-stack"],
|
|
23
|
+
["Box", "Box/Box.vue", "umds-box"],
|
|
24
|
+
]) {
|
|
25
|
+
for (const as of [undefined, "section", "ul"]) {
|
|
26
|
+
const rotulo = `${nome}${as ? ` as="${as}"` : ""}`;
|
|
27
|
+
const props = (extra = {}) => ({ ...(as ? { as } : {}), ...extra });
|
|
28
|
+
|
|
29
|
+
test(`${rotulo}: tem UM nó raiz, o elemento (sem fragmento)`, async () => {
|
|
30
|
+
const m = await abrir(caminho, props());
|
|
31
|
+
assert.equal(m.raiz.childNodes.length, 1);
|
|
32
|
+
const el = m.raiz.firstElementChild;
|
|
33
|
+
assert.equal(el.tagName.toLowerCase(), as || "div");
|
|
34
|
+
assert.ok(el.classList.contains(classe));
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test(`${rotulo}: o ouvinte de clique chega ao elemento`, async () => {
|
|
38
|
+
let cliques = 0;
|
|
39
|
+
const m = await abrir(caminho, props({ onClick: () => cliques++ }));
|
|
40
|
+
m.raiz.firstElementChild.dispatchEvent(new janela.MouseEvent("click", { bubbles: true }));
|
|
41
|
+
assert.equal(cliques, 1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test(`${rotulo}: keydown, dragstart, drop, paste e mousedown chegam ao elemento`, async () => {
|
|
45
|
+
const vistos = [];
|
|
46
|
+
const m = await abrir(
|
|
47
|
+
caminho,
|
|
48
|
+
props({
|
|
49
|
+
onKeydown: () => vistos.push("keydown"),
|
|
50
|
+
onDragstart: () => vistos.push("dragstart"),
|
|
51
|
+
onDrop: () => vistos.push("drop"),
|
|
52
|
+
onPaste: () => vistos.push("paste"),
|
|
53
|
+
onMousedown: () => vistos.push("mousedown"),
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
const el = m.raiz.firstElementChild;
|
|
57
|
+
for (const tipo of ["keydown", "dragstart", "drop", "paste", "mousedown"]) {
|
|
58
|
+
el.dispatchEvent(new janela.Event(tipo, { bubbles: true }));
|
|
59
|
+
}
|
|
60
|
+
assert.deepEqual(vistos, ["keydown", "dragstart", "drop", "paste", "mousedown"]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test(`${rotulo}: tabindex, draggable, data-*, aria-*, title e role chegam ao elemento`, async () => {
|
|
64
|
+
const m = await abrir(
|
|
65
|
+
caminho,
|
|
66
|
+
props({ tabindex: "0", draggable: "true", "data-x": "1", "aria-label": "Região", title: "dica", role: "group" }),
|
|
67
|
+
);
|
|
68
|
+
const el = m.raiz.firstElementChild;
|
|
69
|
+
assert.equal(el.getAttribute("tabindex"), "0");
|
|
70
|
+
assert.equal(el.getAttribute("draggable"), "true");
|
|
71
|
+
assert.equal(el.getAttribute("data-x"), "1");
|
|
72
|
+
assert.equal(el.getAttribute("aria-label"), "Região");
|
|
73
|
+
assert.equal(el.getAttribute("title"), "dica");
|
|
74
|
+
assert.equal(el.getAttribute("role"), "group");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test(`${rotulo}: class e style do consumidor se somam aos do componente`, async () => {
|
|
78
|
+
const m = await abrir(caminho, props({ class: "minha", style: "margin-top: 4px", className: "outra" }));
|
|
79
|
+
const el = m.raiz.firstElementChild;
|
|
80
|
+
assert.ok(el.classList.contains(classe));
|
|
81
|
+
assert.ok(el.classList.contains("minha"));
|
|
82
|
+
assert.ok(el.classList.contains("outra"));
|
|
83
|
+
assert.match(el.getAttribute("style"), /margin-top:\s*4px/);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test(`${rotulo}: o ref do componente aponta para o elemento ($el)`, async () => {
|
|
87
|
+
const m = await abrir(caminho, props());
|
|
88
|
+
assert.equal(m.instancia.$el, m.raiz.firstElementChild);
|
|
89
|
+
assert.equal(m.instancia.$el.nodeType, 1);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test(`${rotulo}: o conteúdo padrão entra dentro do elemento`, async () => {
|
|
93
|
+
const m = await abrir(caminho, props(), { default: () => "conteúdo" });
|
|
94
|
+
assert.equal(m.raiz.firstElementChild.textContent, "conteúdo");
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
test(`${nome} as="ul" e as="ol" mantêm role="list", que o consumidor pode trocar`, async () => {
|
|
99
|
+
const ul = await abrir(caminho, { as: "ul" });
|
|
100
|
+
assert.equal(ul.raiz.firstElementChild.getAttribute("role"), "list");
|
|
101
|
+
const ol = await abrir(caminho, { as: "ol" });
|
|
102
|
+
assert.equal(ol.raiz.firstElementChild.getAttribute("role"), "list");
|
|
103
|
+
const outro = await abrir(caminho, { as: "ul", role: "menu" });
|
|
104
|
+
assert.equal(outro.raiz.firstElementChild.getAttribute("role"), "menu");
|
|
105
|
+
const div = await abrir(caminho, {});
|
|
106
|
+
assert.equal(div.raiz.firstElementChild.getAttribute("role"), null);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test(`${nome} as="form" chama onSubmit e o elemento é um form`, async () => {
|
|
110
|
+
let eventos = 0;
|
|
111
|
+
const m = await abrir(caminho, { as: "form", onSubmit: () => eventos++ });
|
|
112
|
+
const form = m.raiz.firstElementChild;
|
|
113
|
+
assert.equal(form.tagName, "FORM");
|
|
114
|
+
form.dispatchEvent(new janela.Event("submit", { bubbles: true, cancelable: true }));
|
|
115
|
+
assert.equal(eventos, 1);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test(`${nome}: v-show (display none) funciona na raiz`, async () => {
|
|
119
|
+
const { createApp, h, withDirectives, vShow, ref } = await import("vue");
|
|
120
|
+
const mod = await import(`./dom.mjs`);
|
|
121
|
+
const Comp = (await import(new URL(`../components/${caminho}`, import.meta.url).href)).default;
|
|
122
|
+
const visivel = ref(true);
|
|
123
|
+
const alvo = janela.document.createElement("div");
|
|
124
|
+
janela.document.body.append(alvo);
|
|
125
|
+
const app = createApp({ render: () => withDirectives(h(Comp), [[vShow, visivel.value]]) });
|
|
126
|
+
app.mount(alvo);
|
|
127
|
+
assert.notEqual(alvo.firstElementChild.style.display, "none");
|
|
128
|
+
visivel.value = false;
|
|
129
|
+
await proximoTick();
|
|
130
|
+
assert.equal(alvo.firstElementChild.style.display, "none");
|
|
131
|
+
app.unmount();
|
|
132
|
+
void mod;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stack (as, gap="none", props de item flex, atributos),
|
|
3
|
+
* conferidos no HTML que o Vue GERADO escreve.
|
|
4
|
+
*/
|
|
5
|
+
import { test, before, after } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import { abrir, fechar, carregar, renderizar } from "./renderizar.mjs";
|
|
8
|
+
|
|
9
|
+
let Stack;
|
|
10
|
+
|
|
11
|
+
before(async () => {
|
|
12
|
+
await abrir();
|
|
13
|
+
Stack = await carregar("Stack/Stack.vue");
|
|
14
|
+
});
|
|
15
|
+
after(fechar);
|
|
16
|
+
|
|
17
|
+
test("Stack sem props continua um div vertical com gap xxxs", async () => {
|
|
18
|
+
const html = await renderizar(Stack, {}, { default: "x" });
|
|
19
|
+
assert.match(html, /<div class="umds-stack umds-stack--vertical umds-stack--gap-xxxs"/);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("Stack aceita gap none", async () => {
|
|
23
|
+
const html = await renderizar(Stack, { gap: "none" }, { default: "x" });
|
|
24
|
+
assert.match(html, /umds-stack--gap-none/);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
for (const tag of ["div", "span", "ul", "ol", "li", "section", "nav", "header", "footer", "form"]) {
|
|
28
|
+
test(`Stack as="${tag}" renderiza <${tag}> e só ele`, async () => {
|
|
29
|
+
const html = await renderizar(Stack, { as: tag }, { default: "x" });
|
|
30
|
+
assert.match(html, new RegExp(`<${tag}[ >]`));
|
|
31
|
+
const outras = ["div", "span", "ul", "ol", "li", "section", "nav", "header", "footer", "form"].filter((t) => t !== tag);
|
|
32
|
+
for (const o of outras) assert.doesNotMatch(html, new RegExp(`<${o}[ >]`));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
test("Stack ul/ol mantém a semântica de lista (role=list)", async () => {
|
|
37
|
+
assert.match(await renderizar(Stack, { as: "ul" }, { default: "x" }), /<ul[^>]*role="list"/);
|
|
38
|
+
assert.match(await renderizar(Stack, { as: "ol" }, { default: "x" }), /<ol[^>]*role="list"/);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("Stack repassa id, aria-label, title e style", async () => {
|
|
42
|
+
const html = await renderizar(
|
|
43
|
+
Stack,
|
|
44
|
+
{ as: "nav", id: "menu", "aria-label": "Principal", title: "Dica", style: "margin-top: 4px" },
|
|
45
|
+
{ default: "x" },
|
|
46
|
+
);
|
|
47
|
+
assert.match(html, /<nav/);
|
|
48
|
+
assert.match(html, /id="menu"/);
|
|
49
|
+
assert.match(html, /aria-label="Principal"/);
|
|
50
|
+
assert.match(html, /title="Dica"/);
|
|
51
|
+
assert.match(html, /margin-top:\s*4px/);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("Stack escreve as classes de item flex", async () => {
|
|
55
|
+
const html = await renderizar(
|
|
56
|
+
Stack,
|
|
57
|
+
{
|
|
58
|
+
grow: true,
|
|
59
|
+
shrink: "0",
|
|
60
|
+
basis: "50",
|
|
61
|
+
minWidth: "auto",
|
|
62
|
+
overflow: "hidden",
|
|
63
|
+
overflowY: "auto",
|
|
64
|
+
fullHeight: true,
|
|
65
|
+
},
|
|
66
|
+
{ default: "x" },
|
|
67
|
+
);
|
|
68
|
+
for (const c of [
|
|
69
|
+
"umds-stack--grow",
|
|
70
|
+
"umds-stack--shrink-0",
|
|
71
|
+
"umds-stack--basis-50",
|
|
72
|
+
"umds-stack--min-w-auto",
|
|
73
|
+
"umds-stack--overflow-hidden",
|
|
74
|
+
"umds-stack--overflow-y-auto",
|
|
75
|
+
"umds-stack--full-height",
|
|
76
|
+
]) {
|
|
77
|
+
assert.ok(html.includes(c), `faltou ${c} em ${html}`);
|
|
78
|
+
}
|
|
79
|
+
assert.doesNotMatch(html, /full-width/);
|
|
80
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** StatCard: labelPosition e infoTooltip, conferidos no HTML que o Vue GERADO escreve. */
|
|
2
|
+
import { test, before, after } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { abrir, fechar, carregar, renderizar } from "./renderizar.mjs";
|
|
5
|
+
|
|
6
|
+
let StatCard;
|
|
7
|
+
|
|
8
|
+
before(async () => {
|
|
9
|
+
await abrir();
|
|
10
|
+
StatCard = await carregar("StatCard/StatCard.vue");
|
|
11
|
+
});
|
|
12
|
+
after(fechar);
|
|
13
|
+
|
|
14
|
+
test("labelPosition top escreve a classe; sem a prop não", async () => {
|
|
15
|
+
assert.match(await renderizar(StatCard, { value: 44, label: "Não lidos", labelPosition: "top" }), /umds-stat-card--rotulo-topo/);
|
|
16
|
+
assert.doesNotMatch(await renderizar(StatCard, { value: 44, label: "Não lidos" }), /umds-stat-card--rotulo-topo/);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("o número vem antes do rótulo no HTML", async () => {
|
|
20
|
+
const html = await renderizar(StatCard, { value: 44, label: "Não lidos", labelPosition: "top" });
|
|
21
|
+
assert.ok(html.indexOf("umds-stat-card__valor") < html.indexOf("umds-stat-card__rotulo"));
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("infoTooltip escreve o ⓘ como botão nomeado; infoLabel traduz", async () => {
|
|
25
|
+
const html = await renderizar(StatCard, { value: 1, label: "Não lidos", infoTooltip: "Ainda não abertos." });
|
|
26
|
+
assert.match(html, /<button[^>]*umds-stat-card__info/);
|
|
27
|
+
assert.match(html, /aria-label="Mais informações"/);
|
|
28
|
+
assert.match(html, /Ainda não abertos\./);
|
|
29
|
+
assert.match(await renderizar(StatCard, { value: 1, label: "Unread", infoTooltip: "x", infoLabel: "More info" }), /aria-label="More info"/);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("sem infoTooltip não há botão", async () => {
|
|
33
|
+
assert.doesNotMatch(await renderizar(StatCard, { value: 1, label: "x" }), /<button/);
|
|
34
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Tab (count, closable) e Tabs (onAdd), conferidos 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
|
+
/** Tabs com as abas dadas como filhas (cada uma é `[props]`). */
|
|
17
|
+
const comAbas = (propsDoTabs, abas) =>
|
|
18
|
+
renderizar(Tabs, propsDoTabs, { default: () => abas.map((p) => h(Tab, p)) });
|
|
19
|
+
|
|
20
|
+
test("count escreve a pílula; o 0 aparece; sem count não há pílula", async () => {
|
|
21
|
+
const html = await comAbas({ value: "0" }, [
|
|
22
|
+
{ label: "Todas", index: "0", count: 31 },
|
|
23
|
+
{ label: "Concluídas", index: "1", count: 0 },
|
|
24
|
+
{ label: "Sem", index: "2" },
|
|
25
|
+
]);
|
|
26
|
+
assert.equal((html.match(/umds-tabs__count/g) || []).length, 2);
|
|
27
|
+
assert.match(html, /umds-tabs__count[^>]*>31</);
|
|
28
|
+
assert.match(html, /umds-tabs__count[^>]*>0</);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("closable escreve o × como botão próprio com o nome 'Fechar <aba>'", async () => {
|
|
32
|
+
const html = await comAbas({ value: "0" }, [{ label: "Documento 1", index: "0", closable: true }]);
|
|
33
|
+
assert.match(html, /umds-tabs__close/);
|
|
34
|
+
assert.match(html, /aria-label="Fechar Documento 1"/);
|
|
35
|
+
// o × não está dentro do botão da aba (sem botão aninhado)
|
|
36
|
+
assert.doesNotMatch(html, /role="tab"[^>]*>(?:(?!<\/button>).)*umds-tabs__close/s);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("closeLabel traduz o nome do ×", async () => {
|
|
40
|
+
const html = await comAbas({ value: "0" }, [{ label: "Doc 1", index: "0", closable: true, closeLabel: "Close" }]);
|
|
41
|
+
assert.match(html, /aria-label="Close Doc 1"/);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("sem closable não há ×", async () => {
|
|
45
|
+
const html = await comAbas({ value: "0" }, [{ label: "Fixa", index: "0" }]);
|
|
46
|
+
assert.doesNotMatch(html, /umds-tabs__close/);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("onAdd escreve o + fora do tablist; addLabel traduz", async () => {
|
|
50
|
+
const html = await comAbas({ value: "0", onAdd: () => {}, addLabel: "New tab" }, [{ label: "A", index: "0" }]);
|
|
51
|
+
assert.match(html, /umds-tabs__add/);
|
|
52
|
+
assert.match(html, /aria-label="New tab"/);
|
|
53
|
+
const lista = html.match(/role="tablist"[\s\S]*?<\/div><button[^>]*umds-tabs__add/);
|
|
54
|
+
assert.ok(lista, "o + vem depois do fechamento do tablist");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("sem onAdd não há +", async () => {
|
|
58
|
+
const html = await comAbas({ value: "0" }, [{ label: "A", index: "0" }]);
|
|
59
|
+
assert.doesNotMatch(html, /umds-tabs__add/);
|
|
60
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tooltip variant dark e maxWidth no Vue GERADO. A bolha vive num Portal e só
|
|
3
|
+
* monta no navegador, então o SSR não a mostra: o que dá para conferir aqui é
|
|
4
|
+
* que o componente declara as props novas e que renderiza com elas sem quebrar.
|
|
5
|
+
*/
|
|
6
|
+
import { test, before, after } from "node:test";
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { abrir, fechar, carregar, renderizar } from "./renderizar.mjs";
|
|
9
|
+
|
|
10
|
+
let Tooltip;
|
|
11
|
+
|
|
12
|
+
before(async () => {
|
|
13
|
+
await abrir();
|
|
14
|
+
Tooltip = await carregar("Tooltip/Tooltip.vue");
|
|
15
|
+
});
|
|
16
|
+
after(fechar);
|
|
17
|
+
|
|
18
|
+
test("declara variant e maxWidth", () => {
|
|
19
|
+
const props = Object.keys(Tooltip.props || {});
|
|
20
|
+
assert.ok(props.includes("variant"), "variant");
|
|
21
|
+
assert.ok(props.includes("maxWidth"), "maxWidth");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("renderiza com variant dark e maxWidth, e a descrição acessível continua no DOM", async () => {
|
|
25
|
+
const html = await renderizar(Tooltip, { content: "Atualizar", variant: "dark", maxWidth: "140px" }, { default: "<button>Atualizar</button>" });
|
|
26
|
+
assert.match(html, /umds-tooltip__descricao/);
|
|
27
|
+
assert.match(html, /Atualizar/);
|
|
28
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Datas do `Calendar`, em ISO local (`YYYY-MM-DD`) e sem biblioteca.
|
|
3
|
+
*
|
|
4
|
+
* Tudo aqui trabalha com o DIA como texto: `"2026-05-15"`. O `Date` só aparece
|
|
5
|
+
* por dentro, sempre à meia-noite LOCAL (`new Date(ano, mes, dia)`), nunca
|
|
6
|
+
* `new Date("2026-05-15")`, que o JavaScript lê como UTC e, no fuso do Brasil,
|
|
7
|
+
* devolve o dia anterior.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const doisDigitos = (n: number): string => n < 10 ? "0" + n : String(n);
|
|
11
|
+
|
|
12
|
+
/** `Date` local → `YYYY-MM-DD`. */
|
|
13
|
+
export const toIso = (data: Date): string => data.getFullYear() + "-" + doisDigitos(data.getMonth() + 1) + "-" + doisDigitos(data.getDate());
|
|
14
|
+
|
|
15
|
+
/** `YYYY-MM-DD` → `Date` à meia-noite local. */
|
|
16
|
+
export const parseIso = (iso: string): Date => {
|
|
17
|
+
const partes = iso.slice(0, 10).split("-");
|
|
18
|
+
return new Date(Number(partes[0]), Number(partes[1]) - 1, Number(partes[2]));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Aceita `Date` ou texto (`2026-05-15` e `2026-05-15T10:00`) e devolve `YYYY-MM-DD`; "" se não der. */
|
|
22
|
+
export const normalizeIso = (valor: any): string => {
|
|
23
|
+
if (!valor) return "";
|
|
24
|
+
if (typeof valor === "string") return /^\d{4}-\d{2}-\d{2}/.test(valor) ? valor.slice(0, 10) : "";
|
|
25
|
+
if (valor instanceof Date && !isNaN(valor.getTime())) return toIso(valor);
|
|
26
|
+
return "";
|
|
27
|
+
};
|
|
28
|
+
export const addDays = (iso: string, dias: number): string => {
|
|
29
|
+
const data = parseIso(iso);
|
|
30
|
+
data.setDate(data.getDate() + dias);
|
|
31
|
+
return toIso(data);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Soma meses mantendo o dia, ou o último dia do mês de chegada (31/01 + 1 mês = 28/02). */
|
|
35
|
+
export const addMonths = (iso: string, meses: number): string => {
|
|
36
|
+
const data = parseIso(iso);
|
|
37
|
+
const dia = data.getDate();
|
|
38
|
+
data.setDate(1);
|
|
39
|
+
data.setMonth(data.getMonth() + meses);
|
|
40
|
+
const ultimo = new Date(data.getFullYear(), data.getMonth() + 1, 0).getDate();
|
|
41
|
+
data.setDate(Math.min(dia, ultimo));
|
|
42
|
+
return toIso(data);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** Dia da semana: 0 = domingo. */
|
|
46
|
+
export const weekdayOf = (iso: string): number => parseIso(iso).getDay();
|
|
47
|
+
|
|
48
|
+
/** Primeiro dia da semana que contém `iso`, dado o dia em que a semana começa (0 = domingo, 1 = segunda). */
|
|
49
|
+
export const startOfWeek = (iso: string, comecaEm: number): string => {
|
|
50
|
+
const recuo = (weekdayOf(iso) - comecaEm + 7) % 7;
|
|
51
|
+
return addDays(iso, -recuo);
|
|
52
|
+
};
|
|
53
|
+
export const startOfMonth = (iso: string): string => iso.slice(0, 8) + "01";
|
|
54
|
+
export const endOfMonth = (iso: string): string => {
|
|
55
|
+
const data = parseIso(iso);
|
|
56
|
+
return toIso(new Date(data.getFullYear(), data.getMonth() + 1, 0));
|
|
57
|
+
};
|
|
58
|
+
export const isSameMonth = (a: string, b: string): boolean => a.slice(0, 7) === b.slice(0, 7);
|
|
59
|
+
|
|
60
|
+
/** Os sete dias da semana que contém `iso`. */
|
|
61
|
+
export const weekDays = (iso: string, comecaEm: number): string[] => {
|
|
62
|
+
const inicio = startOfWeek(iso, comecaEm);
|
|
63
|
+
const dias: string[] = [];
|
|
64
|
+
for (let i = 0; i < 7; i++) dias.push(addDays(inicio, i));
|
|
65
|
+
return dias;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** O mês de `iso` em semanas inteiras (de 4 a 6 linhas), com os dias dos meses vizinhos que completam as pontas. */
|
|
69
|
+
export const monthMatrix = (iso: string, comecaEm: number): string[][] => {
|
|
70
|
+
const ultimo = endOfMonth(iso);
|
|
71
|
+
let cursor = startOfWeek(startOfMonth(iso), comecaEm);
|
|
72
|
+
const semanas: string[][] = [];
|
|
73
|
+
while (cursor <= ultimo) {
|
|
74
|
+
semanas.push(weekDays(cursor, comecaEm));
|
|
75
|
+
cursor = addDays(cursor, 7);
|
|
76
|
+
}
|
|
77
|
+
return semanas;
|
|
78
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML seguro para o `RichTextEditor`.
|
|
3
|
+
*
|
|
4
|
+
* O editor devolve HTML (`onChange`) e recebe HTML (`value`). HTML que vem de
|
|
5
|
+
* fora (um valor guardado, um texto colado) pode trazer `<img onerror>`,
|
|
6
|
+
* `<a href="javascript:...">`, `<script>`, `style` e classes de outro site. Este
|
|
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 e link.
|
|
9
|
+
*
|
|
10
|
+
* Roda no navegador (precisa de DOM). Dentro de um `<template>` o HTML é inerte:
|
|
11
|
+
* nada executa e nenhuma imagem carrega enquanto se higieniza. Sem DOM
|
|
12
|
+
* (servidor), devolve o texto escapado.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const PERMITIDAS = ["A", "B", "STRONG", "I", "EM", "U", "S", "STRIKE", "DEL", "UL", "OL", "LI", "P", "BR", "DIV", "SPAN", "H1", "H2", "H3", "H4", "BLOCKQUOTE"];
|
|
16
|
+
const DESCARTADAS = ["SCRIPT", "STYLE", "IFRAME", "OBJECT", "EMBED", "LINK", "META", "TEMPLATE", "NOSCRIPT", "SVG", "MATH", "FORM", "INPUT", "BUTTON", "TEXTAREA", "SELECT"];
|
|
17
|
+
const escapar = (texto: string): string => texto.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Endereço de link que o editor aceita: `http:`, `https:`, `mailto:`, `tel:`,
|
|
21
|
+
* caminho (`/x`, `./x`, `../x`) ou âncora (`#x`). Devolve o endereço limpo, ou ""
|
|
22
|
+
* se for perigoso (`javascript:`, `data:`, `vbscript:`...).
|
|
23
|
+
*/
|
|
24
|
+
export const enderecoSeguro = (bruto: string): string => {
|
|
25
|
+
const texto = (bruto || "").trim();
|
|
26
|
+
if (!texto) return "";
|
|
27
|
+
// Caracteres de controle e espaços no meio do esquema são o truque clássico (`java\nscript:`).
|
|
28
|
+
const semControle = texto.replace(/[\u0000-\u001f\u007f\s]+/g, "");
|
|
29
|
+
if (/^(https?:\/\/|mailto:|tel:|\/|\.\.?\/|#)/i.test(semControle)) return texto;
|
|
30
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(semControle)) return "";
|
|
31
|
+
return "";
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Devolve o endereço pronto para `href`: o seguro como veio, ou `https://` + o texto quando não tem esquema. "" se perigoso ou vazio. */
|
|
35
|
+
export const normalizarEndereco = (bruto: string): string => {
|
|
36
|
+
const texto = (bruto || "").trim();
|
|
37
|
+
if (!texto) return "";
|
|
38
|
+
const seguro = enderecoSeguro(texto);
|
|
39
|
+
if (seguro) return seguro;
|
|
40
|
+
const semControle = texto.replace(/[\u0000-\u001f\u007f\s]+/g, "");
|
|
41
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(semControle)) return "";
|
|
42
|
+
return "https://" + texto;
|
|
43
|
+
};
|
|
44
|
+
const limparNo = (no: any, saida: any, documento: any): void => {
|
|
45
|
+
const filhos = Array.prototype.slice.call(no.childNodes);
|
|
46
|
+
for (let i = 0; i < filhos.length; i++) {
|
|
47
|
+
const filho = filhos[i];
|
|
48
|
+
if (filho.nodeType === 3) {
|
|
49
|
+
saida.appendChild(documento.createTextNode(filho.nodeValue));
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (filho.nodeType !== 1) continue;
|
|
53
|
+
const tag = String(filho.tagName).toUpperCase();
|
|
54
|
+
if (DESCARTADAS.indexOf(tag) !== -1) continue;
|
|
55
|
+
if (PERMITIDAS.indexOf(tag) === -1) {
|
|
56
|
+
// Tag desconhecida: some a tag, fica o conteúdo.
|
|
57
|
+
limparNo(filho, saida, documento);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const novo = documento.createElement(tag.toLowerCase());
|
|
61
|
+
if (tag === "A") {
|
|
62
|
+
const href = enderecoSeguro(filho.getAttribute("href") || "");
|
|
63
|
+
if (href) {
|
|
64
|
+
novo.setAttribute("href", href);
|
|
65
|
+
novo.setAttribute("rel", "noopener noreferrer");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
limparNo(filho, novo, documento);
|
|
69
|
+
saida.appendChild(novo);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/** Reduz `html` ao que o editor escreve. Sem DOM, devolve o texto escapado. */
|
|
74
|
+
export const sanitizarHtml = (html: string): string => {
|
|
75
|
+
const bruto = html || "";
|
|
76
|
+
if (typeof document === "undefined") return escapar(bruto);
|
|
77
|
+
const molde: any = document.createElement("template");
|
|
78
|
+
molde.innerHTML = bruto;
|
|
79
|
+
const saida: any = document.createElement("div");
|
|
80
|
+
limparNo(molde.content, saida, document);
|
|
81
|
+
return saida.innerHTML;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** O editor está "vazio": sem texto, sem lista e sem quebra solta (o `<br>` que o navegador deixa). */
|
|
85
|
+
export const htmlVazio = (html: string): boolean => {
|
|
86
|
+
const texto = (html || "").replace(/<br\s*\/?>/gi, "").replace(/<\/?(div|p|span)[^>]*>/gi, "").trim();
|
|
87
|
+
return texto === "";
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** O `<a>` que o editor escreve quando o link não tem texto escolhido: o endereço (já seguro) é o href e o texto. */
|
|
91
|
+
export const htmlDoLink = (endereco: string): string => {
|
|
92
|
+
const seguro = escapar(endereco);
|
|
93
|
+
return '<a href="' + seguro + '">' + seguro + "</a>";
|
|
94
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paleta de cor categórica do 1DS: os primitivos `--umds-primitive-<família>-<tom>`.
|
|
3
|
+
*
|
|
4
|
+
* É a lista que o `ColorPicker` mostra por padrão. Ela existe como constante
|
|
5
|
+
* exportada para o app mapear o valor guardado (o nome do token) de volta para
|
|
6
|
+
* um rótulo, ou montar a própria lista a partir dela (`COLOR_PALETTE.filter(...)`).
|
|
7
|
+
*
|
|
8
|
+
* Primitivo não muda com o tema: é o certo para cor de DADO (marcador, tipo de
|
|
9
|
+
* documento, setor), que precisa ser a mesma no claro e no escuro. Para cor com
|
|
10
|
+
* PAPEL (primário, erro, sucesso) use os semânticos `--umds-semantic-color-*`,
|
|
11
|
+
* que não entram aqui.
|
|
12
|
+
*/
|
|
13
|
+
export type PaletteColor = {
|
|
14
|
+
/** Nome da variável CSS, ex.: `--umds-primitive-blue-pure`. Use como `var(${value})`. */
|
|
15
|
+
value: string;
|
|
16
|
+
/** Nome em português, ex.: "Azul escuro". */
|
|
17
|
+
label: string;
|
|
18
|
+
/** Família: blue, red, green, orange, yellow, purple ou gray. */
|
|
19
|
+
family: string;
|
|
20
|
+
/** Tom claro o bastante para o ícone de marcação sair escuro (contraste mínimo de 3:1). */
|
|
21
|
+
onLight: boolean;
|
|
22
|
+
};
|
|
23
|
+
const cor = (family: string, tone: string, label: string, onLight: boolean): PaletteColor => ({
|
|
24
|
+
value: "--umds-primitive-" + family + "-" + tone,
|
|
25
|
+
label,
|
|
26
|
+
family,
|
|
27
|
+
onLight
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
/** Os 31 primitivos de cor (6 famílias x 4 tons + 7 cinzas), do mais escuro ao mais claro. */
|
|
31
|
+
export const COLOR_PALETTE: PaletteColor[] = [cor("blue", "dark", "Azul escuro", false), cor("blue", "pure", "Azul", false), cor("blue", "medium", "Azul médio", false), cor("blue", "light", "Azul claro", true), cor("red", "dark", "Vermelho escuro", false), cor("red", "pure", "Vermelho", false), cor("red", "medium", "Vermelho médio", false), cor("red", "light", "Vermelho claro", true), cor("green", "dark", "Verde escuro", false), cor("green", "pure", "Verde", false), cor("green", "medium", "Verde médio", false), cor("green", "light", "Verde claro", true), cor("orange", "dark", "Laranja escuro", false), cor("orange", "pure", "Laranja", false), cor("orange", "medium", "Laranja médio", true), cor("orange", "light", "Laranja claro", true), cor("yellow", "dark", "Amarelo escuro", false), cor("yellow", "pure", "Amarelo", true), cor("yellow", "medium", "Amarelo médio", true), cor("yellow", "light", "Amarelo claro", true), cor("purple", "dark", "Roxo escuro", false), cor("purple", "pure", "Roxo", false), cor("purple", "medium", "Roxo médio", false), cor("purple", "light", "Roxo claro", true), cor("gray", "darkest", "Cinza muito escuro", false), cor("gray", "darker", "Cinza escuro", false), cor("gray", "dark", "Cinza", false), cor("gray", "medium", "Cinza médio", true), cor("gray", "light", "Cinza claro", true), cor("gray", "lighter", "Cinza mais claro", true), cor("gray", "lightest", "Cinza muito claro", true)];
|
|
32
|
+
|
|
33
|
+
/** `#RRGGBB` completo (o `#` é opcional). Hexadecimal curto (`#FFF`) não vale. */
|
|
34
|
+
export const isHexColor = (texto: string): boolean => /^#?[0-9a-fA-F]{6}$/.test((texto || "").trim())
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Texto para comparar: minúsculo, sem acento e sem espaço nas pontas. É o que a
|
|
3
|
+
* busca do `IconPicker` usa para achar "usuario" em "Usuário".
|
|
4
|
+
*/
|
|
5
|
+
export const semAcento = (texto: string): string => String(texto || "").normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().trim()
|