@1doc/1ds-vue 2.11.0 → 2.12.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 +22 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +16 -0
- package/dist/index.mjs +3763 -3741
- package/dist/index.umd.js +4 -4
- package/package.json +3 -3
- package/src/teste/rich-text-editor-estilo-de-texto.test.mjs +4 -4
- package/src/teste/timeline-vazio.test.mjs +150 -0
- package/src/utils/html-seguro.ts +1 -1
- package/src/teste/token-primary-lighter.test.mjs +0 -48
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1doc/1ds-vue",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"main": "dist/index.umd.js",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"**/*.css"
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"vite": "^7.3.1",
|
|
31
31
|
"vue": "^3.0.0",
|
|
32
32
|
"vue-tsc": "^2.0.0",
|
|
33
|
-
"@1doc/1ds-tokens": "0.
|
|
34
|
-
"@1doc/1ds-core": "2.
|
|
33
|
+
"@1doc/1ds-tokens": "0.7.0",
|
|
34
|
+
"@1doc/1ds-core": "2.12.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@1doc/1ds-tokens": ">=0.1.0",
|
|
@@ -51,14 +51,14 @@ test("cada ferramenta abre um painel nomeado; Fechar fecha", async () => {
|
|
|
51
51
|
assert.equal(m.raiz.querySelector('[role="group"]'), null);
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
test("a fonte
|
|
54
|
+
test("a fonte do DS embrulha o texto selecionado num span com o token", async () => {
|
|
55
55
|
const m = await abrir({ toolbar: ["fontFamily"] });
|
|
56
56
|
selecionar(m);
|
|
57
57
|
await clicar(botao(m, "Fonte"));
|
|
58
58
|
await clicar(m.raiz.querySelector('[role="combobox"]'));
|
|
59
|
-
const
|
|
60
|
-
await clicar(
|
|
61
|
-
assert.deepEqual(chamadas.at(-1), ["insertHTML", false, '<span style="font-family: var(--umds-semantic-font-family-
|
|
59
|
+
const base = [...m.raiz.querySelectorAll('[role="option"]')].find((o) => o.textContent.includes("Padrão"));
|
|
60
|
+
await clicar(base);
|
|
61
|
+
assert.deepEqual(chamadas.at(-1), ["insertHTML", false, '<span style="font-family: var(--umds-semantic-font-family-base);">Parecer</span>']);
|
|
62
62
|
assert.equal(m.raiz.querySelector('[role="group"]'), null, "o painel fecha");
|
|
63
63
|
});
|
|
64
64
|
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timeline com estado vazio no Vue (DOM do jsdom): isEmpty, o vazio por
|
|
3
|
+
* `items` vazio, o slot `empty` e o entorno que não desmonta.
|
|
4
|
+
*
|
|
5
|
+
* Mora no jsdom e não no SSR porque o que importa aqui é distinguir `isEmpty`
|
|
6
|
+
* AUSENTE de `isEmpty: false` (o Vue transforma boolean ausente em `false`; o
|
|
7
|
+
* postbuild devolve `undefined`) e ver a troca reagir a um `ref`.
|
|
8
|
+
*/
|
|
9
|
+
import { test, after } from "node:test";
|
|
10
|
+
import assert from "node:assert/strict";
|
|
11
|
+
import { montar, clicar, proximoTick } from "./dom.mjs";
|
|
12
|
+
|
|
13
|
+
// O Vue lê o `document` global ao carregar: só depois do dom.mjs.
|
|
14
|
+
const { h, ref } = await import("vue");
|
|
15
|
+
|
|
16
|
+
const montados = [];
|
|
17
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
18
|
+
const abrir = async (props, slots) => {
|
|
19
|
+
const m = await montar("Timeline/Timeline.vue", props, slots);
|
|
20
|
+
montados.push(m);
|
|
21
|
+
await proximoTick();
|
|
22
|
+
return m;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const EVENTOS = [
|
|
26
|
+
{ title: "Criado", timestamp: "18/09 09:12" },
|
|
27
|
+
{ title: "Em análise", timestamp: "19/09 10:05" },
|
|
28
|
+
{ title: "Concluído", timestamp: "22/09 08:30" },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const status = (m) => m.raiz.querySelector('[role="status"]');
|
|
32
|
+
const trilha = (m) => m.raiz.querySelector("ol");
|
|
33
|
+
const itens = (m) => m.raiz.querySelectorAll("li").length;
|
|
34
|
+
|
|
35
|
+
/** Espera `condicao` ficar verdadeira (o Vue aplica a mudança no próximo tick). */
|
|
36
|
+
const esperar = async (condicao, mensagem) => {
|
|
37
|
+
for (let i = 0; i < 20; i++) {
|
|
38
|
+
if (condicao()) return;
|
|
39
|
+
await proximoTick();
|
|
40
|
+
}
|
|
41
|
+
assert.fail(mensagem);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
test("isEmpty troca a trilha pelo vazio, com role status e o título padrão", async () => {
|
|
45
|
+
const m = await abrir({ items: EVENTOS, isEmpty: true });
|
|
46
|
+
assert.ok(status(m));
|
|
47
|
+
assert.match(status(m).textContent, /Nenhum evento registrado/);
|
|
48
|
+
assert.equal(trilha(m), null);
|
|
49
|
+
assert.equal(itens(m), 0);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("título, descrição e ícone do vazio vêm das props", async () => {
|
|
53
|
+
const { faCheck } = await import("@fortawesome/free-solid-svg-icons");
|
|
54
|
+
const m = await abrir({
|
|
55
|
+
items: [],
|
|
56
|
+
isEmpty: true,
|
|
57
|
+
emptyTitle: "Nenhum despacho registrado",
|
|
58
|
+
emptyDescription: "O histórico aparece aqui.",
|
|
59
|
+
emptyIcon: faCheck,
|
|
60
|
+
});
|
|
61
|
+
assert.match(status(m).textContent, /Nenhum despacho registrado/);
|
|
62
|
+
assert.match(status(m).textContent, /O histórico aparece aqui\./);
|
|
63
|
+
assert.ok(status(m).querySelector(".umds-empty-state svg"));
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("isEmpty ausente: items vazio com emptyTitle mostra o vazio", async () => {
|
|
67
|
+
const m = await abrir({ items: [], emptyTitle: "Nada por aqui" });
|
|
68
|
+
assert.ok(status(m));
|
|
69
|
+
assert.match(status(m).textContent, /Nada por aqui/);
|
|
70
|
+
assert.equal(trilha(m), null);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("isEmpty ausente: items vazio com o slot empty mostra o conteúdo próprio", async () => {
|
|
74
|
+
const m = await abrir({ items: [] }, { empty: () => h("b", { class: "proprio" }, "Sem despachos") });
|
|
75
|
+
assert.ok(status(m));
|
|
76
|
+
assert.ok(status(m).querySelector("b.proprio"));
|
|
77
|
+
assert.doesNotMatch(status(m).textContent, /Nenhum evento registrado/);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("isEmpty ausente, sem emptyTitle nem slot: items vazio segue sendo a trilha vazia", async () => {
|
|
81
|
+
const m = await abrir({ items: [] });
|
|
82
|
+
assert.equal(status(m), null);
|
|
83
|
+
assert.ok(trilha(m));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("isEmpty false manda: items vazio com emptyTitle mantém a trilha", async () => {
|
|
87
|
+
const m = await abrir({ items: [], isEmpty: false, emptyTitle: "Nada por aqui" });
|
|
88
|
+
assert.equal(status(m), null);
|
|
89
|
+
assert.ok(trilha(m));
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("items com eventos e emptyTitle, sem isEmpty, mostra a trilha", async () => {
|
|
93
|
+
const m = await abrir({ items: EVENTOS, emptyTitle: "Nada por aqui" });
|
|
94
|
+
assert.equal(status(m), null);
|
|
95
|
+
assert.equal(itens(m), 3);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("isEmpty true com o slot empty mostra o slot, não o EmptyState", async () => {
|
|
99
|
+
const m = await abrir({ items: EVENTOS, isEmpty: true }, { empty: () => h("b", { class: "proprio" }, "Tudo feito") });
|
|
100
|
+
assert.ok(status(m).querySelector("b.proprio"));
|
|
101
|
+
assert.equal(status(m).querySelector(".umds-empty-state"), null);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("o botão do vazio só aparece com rótulo e callback, e chama o callback", async () => {
|
|
105
|
+
const sem = await abrir({ items: [], isEmpty: true, emptyActionLabel: "Limpar filtro" });
|
|
106
|
+
assert.equal(sem.raiz.querySelector("button"), null);
|
|
107
|
+
|
|
108
|
+
const chamadas = [];
|
|
109
|
+
const com = await abrir({
|
|
110
|
+
items: [],
|
|
111
|
+
isEmpty: true,
|
|
112
|
+
emptyActionLabel: "Limpar filtro",
|
|
113
|
+
onEmptyAction: () => chamadas.push(1),
|
|
114
|
+
});
|
|
115
|
+
const botao = com.raiz.querySelector("button");
|
|
116
|
+
assert.ok(botao);
|
|
117
|
+
assert.match(botao.textContent, /Limpar filtro/);
|
|
118
|
+
await clicar(botao);
|
|
119
|
+
assert.equal(chamadas.length, 1);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("o entorno não desmonta: só o miolo troca ao esvaziar e ao voltar", async () => {
|
|
123
|
+
const eventos = ref(EVENTOS);
|
|
124
|
+
const m = await abrir(() => ({ items: eventos.value, isEmpty: eventos.value.length === 0, emptyTitle: "Sem eventos" }));
|
|
125
|
+
const pai = m.raiz;
|
|
126
|
+
const marcador = pai.ownerDocument.createElement("h3");
|
|
127
|
+
marcador.textContent = "Histórico";
|
|
128
|
+
pai.prepend(marcador);
|
|
129
|
+
assert.equal(itens(m), 3);
|
|
130
|
+
|
|
131
|
+
eventos.value = [];
|
|
132
|
+
await esperar(() => status(m), "o vazio não apareceu");
|
|
133
|
+
assert.equal(trilha(m), null);
|
|
134
|
+
assert.ok(pai.contains(marcador));
|
|
135
|
+
|
|
136
|
+
eventos.value = EVENTOS;
|
|
137
|
+
await esperar(() => itens(m) === 3, "a trilha não voltou");
|
|
138
|
+
assert.equal(status(m), null);
|
|
139
|
+
assert.ok(pai.contains(marcador));
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("class e atributos do consumidor caem no elemento que está na tela", async () => {
|
|
143
|
+
const comTrilha = await abrir({ items: EVENTOS, class: "meu", "data-teste": "t1" });
|
|
144
|
+
assert.ok(trilha(comTrilha).classList.contains("meu"));
|
|
145
|
+
assert.equal(trilha(comTrilha).getAttribute("data-teste"), "t1");
|
|
146
|
+
|
|
147
|
+
const vazio = await abrir({ items: [], isEmpty: true, class: "meu", "data-teste": "t2" });
|
|
148
|
+
assert.ok(status(vazio).classList.contains("meu"));
|
|
149
|
+
assert.equal(status(vazio).getAttribute("data-teste"), "t2");
|
|
150
|
+
});
|
package/src/utils/html-seguro.ts
CHANGED
|
@@ -51,7 +51,7 @@ export const normalizarEndereco = (bruto: string): string => {
|
|
|
51
51
|
/** Cor, tamanho e família de fonte só valem como TOKEN do DS: `var(--umds-...)`. Cor em hex, rgb ou nome sai. */
|
|
52
52
|
const COR_TOKEN = /^var\(--umds-(?:primitive|semantic)-[a-z0-9-]+\)$/;
|
|
53
53
|
const TAMANHO_TOKEN = /^var\(--umds-primitive-font-size-[a-z0-9]+\)$/;
|
|
54
|
-
const FAMILIA_TOKEN = /^var\(--umds-(?:primitive|semantic)-font-family-
|
|
54
|
+
const FAMILIA_TOKEN = /^var\(--umds-(?:primitive|semantic)-font-family-base\)$/;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* Declaração de estilo de texto que o editor aceita: `color`, `font-size` e `font-family`,
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
});
|