@brucesantos/design-space 0.13.0 → 0.14.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 +45 -0
- package/README.md +40 -14
- package/bin/design-space-pr.mjs +231 -0
- package/dist/index-BobUYxei.js +95 -0
- package/dist/index-BobUYxei.js.map +1 -0
- package/dist/index-CaxlsfFr.js +423 -0
- package/dist/index-CaxlsfFr.js.map +1 -0
- package/dist/index.js +1138 -1776
- package/dist/index.js.map +1 -1
- package/dist/labels-BlpcrSph.js +520 -0
- package/dist/labels-BlpcrSph.js.map +1 -0
- package/dist/pr/index.d.ts +64 -0
- package/dist/pr.js +126 -0
- package/dist/pr.js.map +1 -0
- package/dist/shell/Panel.d.ts +0 -5
- package/dist/shell/labels.d.ts +43 -12
- package/dist/testing.js +14 -13
- package/dist/testing.js.map +1 -1
- package/dist/types/index.d.ts +5 -5
- package/package.json +9 -1
- package/dist/index-CLox5DuH.js +0 -515
- package/dist/index-CLox5DuH.js.map +0 -1
- package/dist/shell/prMarkdown.d.ts +0 -43
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ScreenNode } from '../registry/index.js';
|
|
2
|
+
import { ProductDefinition, Scenario } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Marcas do bloco gerado. Tudo entre elas é reescrito a cada push; tudo fora
|
|
5
|
+
* delas é de quem escreveu o PR e nunca é tocado.
|
|
6
|
+
*/
|
|
7
|
+
export declare const PR_MARKERS: {
|
|
8
|
+
readonly start: "<!-- design-space:pr:start -->";
|
|
9
|
+
readonly end: "<!-- design-space:pr:end -->";
|
|
10
|
+
};
|
|
11
|
+
export type PrChange = "new" | "changed";
|
|
12
|
+
export type PrScreen = {
|
|
13
|
+
screen: ScreenNode;
|
|
14
|
+
/** O que mudou em cada variação neste PR, por id. Ausente: sem mudança. */
|
|
15
|
+
changes: Map<string, PrChange>;
|
|
16
|
+
/** Variações que a base tinha nesta tela e o PR removeu. */
|
|
17
|
+
removed: Scenario[];
|
|
18
|
+
};
|
|
19
|
+
export type PrDiff = {
|
|
20
|
+
/** `false` quando não houve base para comparar: aí todas as telas entram. */
|
|
21
|
+
compared: boolean;
|
|
22
|
+
/** Telas que o PR cria ou altera, na ordem do produto. */
|
|
23
|
+
screens: PrScreen[];
|
|
24
|
+
/** Telas que existiam na base e o PR removeu. */
|
|
25
|
+
removedScreens: {
|
|
26
|
+
name: string;
|
|
27
|
+
path: string;
|
|
28
|
+
}[];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Compara o registro do PR com o da base.
|
|
32
|
+
*
|
|
33
|
+
* Uma tela entra quando é nova, quando a rota mudou ou quando algum cenário
|
|
34
|
+
* dela foi criado, alterado ou removido. Mudança no enunciado de uma regra
|
|
35
|
+
* conta como mudança dos cenários que a citam. Mudança só no código da tela,
|
|
36
|
+
* sem tocar no registro, não muda critério e não entra.
|
|
37
|
+
*/
|
|
38
|
+
export declare function diffProducts(head: ProductDefinition, base?: ProductDefinition): PrDiff;
|
|
39
|
+
export type PrSectionInput = {
|
|
40
|
+
/** O produto como está no PR. */
|
|
41
|
+
head: ProductDefinition;
|
|
42
|
+
/** O produto na base do PR. Sem ela, todas as telas entram. */
|
|
43
|
+
base?: ProductDefinition;
|
|
44
|
+
/** Origem absoluta do preview deste PR. Sem ela, o bloco sai sem links. */
|
|
45
|
+
origin?: string;
|
|
46
|
+
/** Commit do PR que gerou o bloco. */
|
|
47
|
+
commit?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Tamanho máximo do bloco, em caracteres. As telas que não couberem saem só
|
|
50
|
+
* pelo nome. A descrição de PR tem limite, e um bloco cortado no meio de um
|
|
51
|
+
* critério é pior que um que diz o que ficou de fora.
|
|
52
|
+
*/
|
|
53
|
+
maxLength?: number;
|
|
54
|
+
};
|
|
55
|
+
/** O bloco gerado, com as marcas. */
|
|
56
|
+
export declare function buildPrSection({ head, base, origin, commit, maxLength }: PrSectionInput): string;
|
|
57
|
+
/**
|
|
58
|
+
* A descrição nova do PR.
|
|
59
|
+
*
|
|
60
|
+
* Com as marcas, troca só o que está entre elas. Sem as marcas, acrescenta o
|
|
61
|
+
* bloco ao fim do que já houver. Em branco, a descrição é só o bloco: o PR não
|
|
62
|
+
* tem seção para preencher à mão, e o formato é o mesmo em todo produto.
|
|
63
|
+
*/
|
|
64
|
+
export declare function mergePrBody(body: string | null | undefined, section: string): string;
|
package/dist/pr.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { s as C } from "./index-CaxlsfFr.js";
|
|
2
|
+
import { a as w, r as M } from "./labels-BlpcrSph.js";
|
|
3
|
+
const v = {
|
|
4
|
+
start: "<!-- design-space:pr:start -->",
|
|
5
|
+
end: "<!-- design-space:pr:end -->"
|
|
6
|
+
};
|
|
7
|
+
function R(n, r) {
|
|
8
|
+
const e = w(n);
|
|
9
|
+
if (!r)
|
|
10
|
+
return {
|
|
11
|
+
compared: !1,
|
|
12
|
+
screens: e.screens.map((s) => ({ screen: s, changes: /* @__PURE__ */ new Map(), removed: [] })),
|
|
13
|
+
removedScreens: []
|
|
14
|
+
};
|
|
15
|
+
const u = w(r), c = new Map(
|
|
16
|
+
(r.scenarios ?? []).map((s) => [s.id, x(u, s)])
|
|
17
|
+
), o = new Map(u.screens.map((s) => [s.route.path, s])), p = new Set((n.scenarios ?? []).map((s) => s.id)), a = [];
|
|
18
|
+
for (const s of e.screens) {
|
|
19
|
+
const d = o.get(s.route.path), h = /* @__PURE__ */ new Map();
|
|
20
|
+
for (const m of s.variations) {
|
|
21
|
+
const b = c.get(m.id);
|
|
22
|
+
b === void 0 ? h.set(m.id, "new") : b !== x(e, m) && h.set(m.id, "changed");
|
|
23
|
+
}
|
|
24
|
+
const f = d?.variations.filter((m) => !p.has(m.id)) ?? [];
|
|
25
|
+
(!d || k(d) !== k(s) || h.size > 0 || f.length > 0) && a.push({ screen: s, changes: h, removed: f });
|
|
26
|
+
}
|
|
27
|
+
const t = new Set(e.screens.map((s) => s.route.path)), i = u.screens.filter((s) => !t.has(s.route.path)).map((s) => ({ name: s.name, path: s.route.path }));
|
|
28
|
+
return { compared: !0, screens: a, removedScreens: i };
|
|
29
|
+
}
|
|
30
|
+
function x(n, r) {
|
|
31
|
+
return JSON.stringify({ scenario: r, rules: n.rulesOf(r) });
|
|
32
|
+
}
|
|
33
|
+
function k(n) {
|
|
34
|
+
return JSON.stringify(n.route);
|
|
35
|
+
}
|
|
36
|
+
function N({ head: n, base: r, origin: e, commit: u, maxLength: c }) {
|
|
37
|
+
const o = w(n), p = R(n, r), a = M(n.theme?.labels).pr, t = e?.replace(/\/+$/, "") || void 0, i = [v.start, `## ${a.title}`, "", `> ${a.notice(u?.slice(0, 7))}`, ""];
|
|
38
|
+
t && i.push(`${a.preview}: ${t}`, ""), p.screens.length === 0 && p.removedScreens.length === 0 ? i.push(a.nothingChanged, "") : i.push(p.compared ? a.scopeChanged : a.scopeAll, "");
|
|
39
|
+
const s = [];
|
|
40
|
+
if (p.removedScreens.length > 0) {
|
|
41
|
+
const f = p.removedScreens.map((l) => `${g(l.name)} (\`${l.path}\`)`);
|
|
42
|
+
s.push(`**${a.removedScreens}:** ${f.join(", ")}`, "");
|
|
43
|
+
}
|
|
44
|
+
s.push(v.end);
|
|
45
|
+
const d = c === void 0 ? 1 / 0 : c - S(s) - 2e3, h = [];
|
|
46
|
+
for (const f of p.screens) {
|
|
47
|
+
const l = j(f, o, a, t);
|
|
48
|
+
h.length === 0 && S(i) + S(l) <= d ? i.push(...l) : h.push(`${g(f.screen.name)} (\`${f.screen.route.path}\`)`);
|
|
49
|
+
}
|
|
50
|
+
return h.length > 0 && i.push(`**${a.truncated}:** ${h.join(", ")}`, ""), i.push(...s), `${i.join(`
|
|
51
|
+
`)}
|
|
52
|
+
`;
|
|
53
|
+
}
|
|
54
|
+
function S(n) {
|
|
55
|
+
return n.reduce((r, e) => r + e.length + 1, 0);
|
|
56
|
+
}
|
|
57
|
+
function j(n, r, e, u) {
|
|
58
|
+
const { screen: c } = n, o = [`### ${g(c.name)}`, ""], p = u && c.variations.length === 0 ? ` · [${e.open}](${new URL(c.href, u).toString()})` : "";
|
|
59
|
+
o.push(`\`${c.route.path}\`${p}`, ""), c.description && o.push($(c.description), ""), c.route.expected?.length && o.push(`**${e.screenExpected}**`, "", ...y(c.route.expected), "");
|
|
60
|
+
for (const t of c.variations) {
|
|
61
|
+
const i = n.changes.get(t.id), s = i === "new" ? e.statusNew : i === "changed" ? e.statusChanged : void 0;
|
|
62
|
+
o.push(
|
|
63
|
+
`#### ${g(t.title)} · \`${t.id}\`${s ? ` · ${s}` : ""}`,
|
|
64
|
+
""
|
|
65
|
+
);
|
|
66
|
+
const d = [];
|
|
67
|
+
u && d.push(`[${e.open}](${C(t, { origin: u })})`);
|
|
68
|
+
const h = r.persona(t.persona);
|
|
69
|
+
h && d.push(`${e.persona}: ${g(h.name)}`), t.ticket && d.push(`${e.ticket}: ${t.ticket}`), d.length > 0 && o.push(d.join(" · "), ""), t.intent && o.push($(t.intent), ""), t.preconditions?.length && o.push(`**${e.preconditions}**`, "", ...O(t.preconditions), ""), t.actions?.length && o.push(`**${e.actions}**`, "", ...O(t.actions), ""), o.push(`**${e.expected}**`, ""), o.push(...t.expected?.length ? y(t.expected) : [e.noExpected], "");
|
|
70
|
+
const f = r.rulesOf(t);
|
|
71
|
+
if (f.length > 0) {
|
|
72
|
+
o.push(`**${e.rules}**`, "");
|
|
73
|
+
for (const l of f) o.push(`- \`${l.id}\` — ${$(l.statement)}`);
|
|
74
|
+
o.push("");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const a = r.componentsOfScreen(c);
|
|
78
|
+
if (a.length > 0) {
|
|
79
|
+
o.push(`**${e.components}**`, "", `| ${e.component} | ${e.source} |`, "| --- | --- |");
|
|
80
|
+
for (const t of a) {
|
|
81
|
+
const i = t.source ? `\`${P(t.source)}\`` : e.empty;
|
|
82
|
+
o.push(`| ${P(t.name)} (\`${t.id}\`) | ${i} |`);
|
|
83
|
+
}
|
|
84
|
+
o.push("");
|
|
85
|
+
}
|
|
86
|
+
if (n.removed.length > 0) {
|
|
87
|
+
const t = n.removed.map((i) => `${g(i.title)} (\`${i.id}\`)`);
|
|
88
|
+
o.push(`**${e.removedScenarios}:** ${t.join(", ")}`, "");
|
|
89
|
+
}
|
|
90
|
+
return o;
|
|
91
|
+
}
|
|
92
|
+
function z(n, r) {
|
|
93
|
+
const e = (n ?? "").replace(/\r\n/g, `
|
|
94
|
+
`), u = r.trim(), c = e.indexOf(v.start);
|
|
95
|
+
if (c !== -1) {
|
|
96
|
+
const o = e.indexOf(v.end, c), p = o === -1 ? "" : e.slice(o + v.end.length);
|
|
97
|
+
return `${e.slice(0, c)}${u}${p}`;
|
|
98
|
+
}
|
|
99
|
+
return e.trim() ? `${e.trimEnd()}
|
|
100
|
+
|
|
101
|
+
${u}
|
|
102
|
+
` : `${u}
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
function y(n) {
|
|
106
|
+
return n.map((r, e) => `${e + 1}. ${$(r)}`);
|
|
107
|
+
}
|
|
108
|
+
function O(n) {
|
|
109
|
+
return n.map((r) => `- ${$(r)}`);
|
|
110
|
+
}
|
|
111
|
+
function $(n) {
|
|
112
|
+
return n.replace(/\s*\n\s*/g, " ").trim();
|
|
113
|
+
}
|
|
114
|
+
function P(n) {
|
|
115
|
+
return $(n).replace(/\|/g, "\\|");
|
|
116
|
+
}
|
|
117
|
+
function g(n) {
|
|
118
|
+
return $(n).replace(/([*_[\]`])/g, "\\$1");
|
|
119
|
+
}
|
|
120
|
+
export {
|
|
121
|
+
v as PR_MARKERS,
|
|
122
|
+
N as buildPrSection,
|
|
123
|
+
R as diffProducts,
|
|
124
|
+
z as mergePrBody
|
|
125
|
+
};
|
|
126
|
+
//# sourceMappingURL=pr.js.map
|
package/dist/pr.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pr.js","sources":["../src/pr/index.ts"],"sourcesContent":["/**\n * `@brucesantos/design-space/pr`\n *\n * A descrição do PR gerada do registro do produto. O critério de aceite é\n * escrito uma vez, no cenário (`intent`, `preconditions`, `actions`,\n * `expected`, `rules`), e chega ao PR por aqui, reescrito a cada push. Ninguém\n * copia nada à mão: cópia diverge na primeira mudança, e quem valida a entrega,\n * gente ou agente, precisa de uma fonte só. Ver a decisão 0018.\n *\n * Funções puras, sem Node nem DOM. Quem lê o produto do disco e fala com o\n * repositório é o comando `design-space-pr`.\n */\n\nimport { scenarioUrl } from \"../deploy/index.js\";\nimport { createRegistry, type Registry, type ScreenNode } from \"../registry/index.js\";\nimport { resolveLabels, type Labels } from \"../shell/labels.js\";\nimport type { ProductDefinition, Scenario } from \"../types/index.js\";\n\n/**\n * Marcas do bloco gerado. Tudo entre elas é reescrito a cada push; tudo fora\n * delas é de quem escreveu o PR e nunca é tocado.\n */\nexport const PR_MARKERS = {\n start: \"<!-- design-space:pr:start -->\",\n end: \"<!-- design-space:pr:end -->\",\n} as const;\n\nexport type PrChange = \"new\" | \"changed\";\n\nexport type PrScreen = {\n screen: ScreenNode;\n /** O que mudou em cada variação neste PR, por id. Ausente: sem mudança. */\n changes: Map<string, PrChange>;\n /** Variações que a base tinha nesta tela e o PR removeu. */\n removed: Scenario[];\n};\n\nexport type PrDiff = {\n /** `false` quando não houve base para comparar: aí todas as telas entram. */\n compared: boolean;\n /** Telas que o PR cria ou altera, na ordem do produto. */\n screens: PrScreen[];\n /** Telas que existiam na base e o PR removeu. */\n removedScreens: { name: string; path: string }[];\n};\n\n/**\n * Compara o registro do PR com o da base.\n *\n * Uma tela entra quando é nova, quando a rota mudou ou quando algum cenário\n * dela foi criado, alterado ou removido. Mudança no enunciado de uma regra\n * conta como mudança dos cenários que a citam. Mudança só no código da tela,\n * sem tocar no registro, não muda critério e não entra.\n */\nexport function diffProducts(head: ProductDefinition, base?: ProductDefinition): PrDiff {\n const registry = createRegistry(head);\n if (!base) {\n return {\n compared: false,\n screens: registry.screens.map((screen) => ({ screen, changes: new Map(), removed: [] })),\n removedScreens: [],\n };\n }\n\n const baseRegistry = createRegistry(base);\n const baseScenarios = new Map(\n (base.scenarios ?? []).map((scenario) => [scenario.id, scenarioPrint(baseRegistry, scenario)]),\n );\n const baseScreens = new Map(baseRegistry.screens.map((screen) => [screen.route.path, screen]));\n const headIds = new Set((head.scenarios ?? []).map((scenario) => scenario.id));\n\n const screens: PrScreen[] = [];\n for (const screen of registry.screens) {\n const before = baseScreens.get(screen.route.path);\n const changes = new Map<string, PrChange>();\n for (const variation of screen.variations) {\n const print = baseScenarios.get(variation.id);\n if (print === undefined) changes.set(variation.id, \"new\");\n else if (print !== scenarioPrint(registry, variation)) changes.set(variation.id, \"changed\");\n }\n const removed = before?.variations.filter((variation) => !headIds.has(variation.id)) ?? [];\n const routeChanged = !before || routePrint(before) !== routePrint(screen);\n if (routeChanged || changes.size > 0 || removed.length > 0) screens.push({ screen, changes, removed });\n }\n\n const headPaths = new Set(registry.screens.map((screen) => screen.route.path));\n const removedScreens = baseRegistry.screens\n .filter((screen) => !headPaths.has(screen.route.path))\n .map((screen) => ({ name: screen.name, path: screen.route.path }));\n\n return { compared: true, screens, removedScreens };\n}\n\n// Função não serializa: o componente da tela fica de fora, e o que sobra é o\n// que o registro declara.\nfunction scenarioPrint(registry: Registry, scenario: Scenario): string {\n return JSON.stringify({ scenario, rules: registry.rulesOf(scenario) });\n}\n\nfunction routePrint(screen: ScreenNode): string {\n return JSON.stringify(screen.route);\n}\n\nexport type PrSectionInput = {\n /** O produto como está no PR. */\n head: ProductDefinition;\n /** O produto na base do PR. Sem ela, todas as telas entram. */\n base?: ProductDefinition;\n /** Origem absoluta do preview deste PR. Sem ela, o bloco sai sem links. */\n origin?: string;\n /** Commit do PR que gerou o bloco. */\n commit?: string;\n /**\n * Tamanho máximo do bloco, em caracteres. As telas que não couberem saem só\n * pelo nome. A descrição de PR tem limite, e um bloco cortado no meio de um\n * critério é pior que um que diz o que ficou de fora.\n */\n maxLength?: number;\n};\n\n/** O bloco gerado, com as marcas. */\nexport function buildPrSection({ head, base, origin, commit, maxLength }: PrSectionInput): string {\n const registry = createRegistry(head);\n const diff = diffProducts(head, base);\n const pr = resolveLabels(head.theme?.labels).pr;\n const root = origin?.replace(/\\/+$/, \"\") || undefined;\n\n const lines: string[] = [PR_MARKERS.start, `## ${pr.title}`, \"\", `> ${pr.notice(commit?.slice(0, 7))}`, \"\"];\n if (root) lines.push(`${pr.preview}: ${root}`, \"\");\n\n if (diff.screens.length === 0 && diff.removedScreens.length === 0) {\n lines.push(pr.nothingChanged, \"\");\n } else {\n lines.push(diff.compared ? pr.scopeChanged : pr.scopeAll, \"\");\n }\n\n const tail: string[] = [];\n if (diff.removedScreens.length > 0) {\n const names = diff.removedScreens.map((screen) => `${escapeMarkdown(screen.name)} (\\`${screen.path}\\`)`);\n tail.push(`**${pr.removedScreens}:** ${names.join(\", \")}`, \"\");\n }\n tail.push(PR_MARKERS.end);\n\n // Folga para a linha das telas que ficarem de fora.\n const budget = maxLength === undefined ? Infinity : maxLength - size(tail) - 2000;\n const left: string[] = [];\n for (const item of diff.screens) {\n const chunk = screenLines(item, registry, pr, root);\n if (left.length === 0 && size(lines) + size(chunk) <= budget) lines.push(...chunk);\n else left.push(`${escapeMarkdown(item.screen.name)} (\\`${item.screen.route.path}\\`)`);\n }\n if (left.length > 0) lines.push(`**${pr.truncated}:** ${left.join(\", \")}`, \"\");\n\n lines.push(...tail);\n return `${lines.join(\"\\n\")}\\n`;\n}\n\nfunction size(lines: string[]): number {\n return lines.reduce((total, line) => total + line.length + 1, 0);\n}\n\nfunction screenLines(item: PrScreen, registry: Registry, pr: Labels[\"pr\"], origin: string | undefined): string[] {\n const { screen } = item;\n const lines = [`### ${escapeMarkdown(screen.name)}`, \"\"];\n // Com cenário, cada um tem o seu link; o da tela só faz falta quando não há\n // nenhum, e aí abre o caminho de exemplo (`params`).\n const link =\n origin && screen.variations.length === 0\n ? ` · [${pr.open}](${new URL(screen.href, origin).toString()})`\n : \"\";\n lines.push(`\\`${screen.route.path}\\`${link}`, \"\");\n if (screen.description) lines.push(oneLine(screen.description), \"\");\n if (screen.route.expected?.length) lines.push(`**${pr.screenExpected}**`, \"\", ...numbered(screen.route.expected), \"\");\n\n for (const variation of screen.variations) {\n const change = item.changes.get(variation.id);\n const status = change === \"new\" ? pr.statusNew : change === \"changed\" ? pr.statusChanged : undefined;\n lines.push(\n `#### ${escapeMarkdown(variation.title)} · \\`${variation.id}\\`${status ? ` · ${status}` : \"\"}`,\n \"\",\n );\n\n const meta: string[] = [];\n if (origin) meta.push(`[${pr.open}](${scenarioUrl(variation, { origin })})`);\n const persona = registry.persona(variation.persona);\n if (persona) meta.push(`${pr.persona}: ${escapeMarkdown(persona.name)}`);\n if (variation.ticket) meta.push(`${pr.ticket}: ${variation.ticket}`);\n if (meta.length > 0) lines.push(meta.join(\" · \"), \"\");\n\n if (variation.intent) lines.push(oneLine(variation.intent), \"\");\n if (variation.preconditions?.length) lines.push(`**${pr.preconditions}**`, \"\", ...bullets(variation.preconditions), \"\");\n if (variation.actions?.length) lines.push(`**${pr.actions}**`, \"\", ...bullets(variation.actions), \"\");\n lines.push(`**${pr.expected}**`, \"\");\n lines.push(...(variation.expected?.length ? numbered(variation.expected) : [pr.noExpected]), \"\");\n\n const rules = registry.rulesOf(variation);\n if (rules.length > 0) {\n lines.push(`**${pr.rules}**`, \"\");\n for (const rule of rules) lines.push(`- \\`${rule.id}\\` — ${oneLine(rule.statement)}`);\n lines.push(\"\");\n }\n }\n\n const components = registry.componentsOfScreen(screen);\n if (components.length > 0) {\n lines.push(`**${pr.components}**`, \"\", `| ${pr.component} | ${pr.source} |`, \"| --- | --- |\");\n for (const component of components) {\n const source = component.source ? `\\`${escapeCell(component.source)}\\`` : pr.empty;\n lines.push(`| ${escapeCell(component.name)} (\\`${component.id}\\`) | ${source} |`);\n }\n lines.push(\"\");\n }\n\n if (item.removed.length > 0) {\n const names = item.removed.map((variation) => `${escapeMarkdown(variation.title)} (\\`${variation.id}\\`)`);\n lines.push(`**${pr.removedScenarios}:** ${names.join(\", \")}`, \"\");\n }\n\n return lines;\n}\n\n/**\n * A descrição nova do PR.\n *\n * Com as marcas, troca só o que está entre elas. Sem as marcas, acrescenta o\n * bloco ao fim do que já houver. Em branco, a descrição é só o bloco: o PR não\n * tem seção para preencher à mão, e o formato é o mesmo em todo produto.\n */\nexport function mergePrBody(body: string | null | undefined, section: string): string {\n const current = (body ?? \"\").replace(/\\r\\n/g, \"\\n\");\n const block = section.trim();\n const start = current.indexOf(PR_MARKERS.start);\n if (start !== -1) {\n const end = current.indexOf(PR_MARKERS.end, start);\n // Marca de fim apagada à mão: o bloco vai até o fim da descrição.\n const after = end === -1 ? \"\" : current.slice(end + PR_MARKERS.end.length);\n return `${current.slice(0, start)}${block}${after}`;\n }\n return current.trim() ? `${current.trimEnd()}\\n\\n${block}\\n` : `${block}\\n`;\n}\n\nfunction numbered(items: string[]): string[] {\n return items.map((item, index) => `${index + 1}. ${oneLine(item)}`);\n}\n\nfunction bullets(items: string[]): string[] {\n return items.map((item) => `- ${oneLine(item)}`);\n}\n\nfunction oneLine(value: string): string {\n return value.replace(/\\s*\\n\\s*/g, \" \").trim();\n}\n\nfunction escapeCell(value: string): string {\n return oneLine(value).replace(/\\|/g, \"\\\\|\");\n}\n\nfunction escapeMarkdown(value: string): string {\n return oneLine(value).replace(/([*_[\\]`])/g, \"\\\\$1\");\n}\n"],"names":["PR_MARKERS","diffProducts","head","base","registry","createRegistry","screen","baseRegistry","baseScenarios","scenario","scenarioPrint","baseScreens","headIds","screens","before","changes","variation","print","removed","routePrint","headPaths","removedScreens","buildPrSection","origin","commit","maxLength","diff","pr","resolveLabels","root","lines","tail","names","escapeMarkdown","budget","size","left","item","chunk","screenLines","total","line","link","oneLine","numbered","change","status","meta","scenarioUrl","persona","bullets","rules","rule","components","component","source","escapeCell","mergePrBody","body","section","current","block","start","end","after","items","index","value"],"mappings":";;AAsBO,MAAMA,IAAa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
|
2
|
-
import { DeployContext } from '../deploy/index.js';
|
|
3
|
-
import { DesignSpaceLocation } from '../controls/state.js';
|
|
4
2
|
import { ComponentPreview, Control, ControlsState, PanelTab, Scenario } from '../types/index.js';
|
|
5
3
|
export type PanelProps = {
|
|
6
4
|
registry: Registry;
|
|
7
5
|
controls: ControlsState;
|
|
8
|
-
deploy: DeployContext;
|
|
9
|
-
/** Endereço aberto: é o link da tela aberta no "Copiar para o PR". */
|
|
10
|
-
location: DesignSpaceLocation;
|
|
11
6
|
screen: ScreenNode | undefined;
|
|
12
7
|
/** Cenário ativo quando ele é variação da tela aberta. */
|
|
13
8
|
variation: Scenario | undefined;
|
package/dist/shell/labels.d.ts
CHANGED
|
@@ -100,9 +100,12 @@ export type Labels = {
|
|
|
100
100
|
ticket: string;
|
|
101
101
|
flow: string;
|
|
102
102
|
controls: string;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
/** @deprecated Sem uso desde a 0.14: o PR passou a ser escrito por `design-space-pr`. */
|
|
104
|
+
copyForPr?: string;
|
|
105
|
+
/** @deprecated Sem uso desde a 0.14. */
|
|
106
|
+
copiedForPr?: string;
|
|
107
|
+
/** @deprecated Sem uso desde a 0.14. */
|
|
108
|
+
copyPrompt?: string;
|
|
106
109
|
};
|
|
107
110
|
diagnostics: {
|
|
108
111
|
title: string;
|
|
@@ -113,21 +116,49 @@ export type Labels = {
|
|
|
113
116
|
invalidControl: (id: string, value: string, fallback: string) => string;
|
|
114
117
|
unknownControl: (id: string, value: string) => string;
|
|
115
118
|
};
|
|
116
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* Texto da descrição do PR que `design-space-pr` escreve: o bloco gerado do
|
|
121
|
+
* registro e as seções que só uma pessoa sabe preencher. Ver a decisão 0018.
|
|
122
|
+
*/
|
|
117
123
|
pr: {
|
|
118
|
-
|
|
124
|
+
title: string;
|
|
125
|
+
/** Recado para quem implementa ou valida, inclusive agentes. */
|
|
126
|
+
notice: (shortCommit: string | undefined) => string;
|
|
127
|
+
preview: string;
|
|
128
|
+
scopeChanged: string;
|
|
129
|
+
scopeAll: string;
|
|
130
|
+
nothingChanged: string;
|
|
131
|
+
open: string;
|
|
132
|
+
screenExpected: string;
|
|
133
|
+
persona: string;
|
|
134
|
+
ticket: string;
|
|
135
|
+
preconditions: string;
|
|
136
|
+
actions: string;
|
|
137
|
+
expected: string;
|
|
138
|
+
rules: string;
|
|
119
139
|
components: string;
|
|
120
140
|
component: string;
|
|
121
141
|
source: string;
|
|
122
|
-
expected: string;
|
|
123
|
-
commit: (shortCommit: string) => string;
|
|
124
|
-
immutableLink: string;
|
|
125
142
|
noExpected: string;
|
|
126
143
|
empty: string;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
144
|
+
statusNew: string;
|
|
145
|
+
statusChanged: string;
|
|
146
|
+
removedScenarios: string;
|
|
147
|
+
removedScreens: string;
|
|
148
|
+
/** Telas que não couberam no limite de tamanho da descrição. */
|
|
149
|
+
truncated: string;
|
|
150
|
+
/** @deprecated Sem uso desde a 0.14, junto com o "Copiar para o PR". */
|
|
151
|
+
variations?: string;
|
|
152
|
+
/** @deprecated Sem uso desde a 0.14. */
|
|
153
|
+
commit?: (shortCommit: string) => string;
|
|
154
|
+
/** @deprecated Sem uso desde a 0.14. */
|
|
155
|
+
immutableLink?: string;
|
|
156
|
+
/** @deprecated Sem uso desde a 0.14. */
|
|
157
|
+
controls?: string;
|
|
158
|
+
/** @deprecated Sem uso desde a 0.14. */
|
|
159
|
+
shortcuts?: string;
|
|
160
|
+
/** @deprecated Sem uso desde a 0.14. */
|
|
161
|
+
defaultOption?: string;
|
|
131
162
|
};
|
|
132
163
|
shell: {
|
|
133
164
|
restoreChrome: string;
|
package/dist/testing.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { v as s, m as t, l as i, s as n } from "./index-CaxlsfFr.js";
|
|
2
|
+
import { c as a } from "./index-BobUYxei.js";
|
|
2
3
|
function c(o = "http://localhost:5173") {
|
|
3
4
|
const r = typeof process < "u" ? process.env : {};
|
|
4
5
|
return (r.PREVIEW_URL || r.BASE_URL || o).replace(/\/$/, "");
|
|
@@ -6,26 +7,26 @@ function c(o = "http://localhost:5173") {
|
|
|
6
7
|
function d(o, r = {}) {
|
|
7
8
|
return n(o, { origin: r.origin ?? c(), overrides: r.overrides });
|
|
8
9
|
}
|
|
9
|
-
function
|
|
10
|
+
function f(o, r = {}) {
|
|
10
11
|
const e = new URL(n(o, { origin: "http://design-space.invalid", overrides: r }));
|
|
11
12
|
return `${e.pathname}${e.search}`;
|
|
12
13
|
}
|
|
13
|
-
const
|
|
14
|
-
function
|
|
15
|
-
const r =
|
|
16
|
-
if (
|
|
14
|
+
const p = `iframe[${a}]`;
|
|
15
|
+
function E(o) {
|
|
16
|
+
const r = s(o);
|
|
17
|
+
if (t(r))
|
|
17
18
|
throw new Error(`Contrato de cenário inválido:
|
|
18
|
-
${
|
|
19
|
+
${i(r)}`);
|
|
19
20
|
}
|
|
20
21
|
export {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
p as FRAME_SELECTOR,
|
|
23
|
+
E as assertValidProduct,
|
|
24
|
+
i as formatIssues,
|
|
25
|
+
t as hasErrors,
|
|
26
|
+
f as pathFor,
|
|
26
27
|
n as scenarioUrl,
|
|
27
28
|
c as testOrigin,
|
|
28
29
|
d as urlFor,
|
|
29
|
-
|
|
30
|
+
s as validateProduct
|
|
30
31
|
};
|
|
31
32
|
//# sourceMappingURL=testing.js.map
|
package/dist/testing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","sources":["../src/testing/index.ts"],"sourcesContent":["/**\n * `@brucesantos/design-space/testing`\n *\n * Utilitários para os testes do produto. Vive num entrypoint separado porque\n * nada aqui deve chegar ao bundle do preview.\n *\n * O que este módulo assume: o preview é público, sem proteção de acesso (D-11).\n * Como não há segredo de bypass nem header de automação a emitir, o Playwright\n * aponta direto para a URL do preview — e é por isso que estas funções só\n * precisam de uma origem.\n */\n\nimport { scenarioUrl } from \"../deploy/index.js\";\nimport { FRAME_ATTRIBUTE } from \"../frame/index.js\";\nimport { validateProduct, hasErrors, formatIssues } from \"../registry/validate.js\";\nimport type { ControlsState, ProductDefinition, Scenario } from \"../types/index.js\";\n\n/**\n * Origem contra a qual os testes rodam.\n *\n * `PREVIEW_URL` é o que o gatilho `deployment_status` do GitHub Actions entrega\n * pronto (§10.6), o que dispensa qualquer lógica de descobrir onde o preview foi\n * publicado. Sem ela, cai no dev server local.\n */\nexport function testOrigin(fallback = \"http://localhost:5173\"): string {\n const env = typeof process !== \"undefined\" ? process.env : {};\n const url = env.PREVIEW_URL || env.BASE_URL || fallback;\n return url.replace(/\\/$/, \"\");\n}\n\n/** URL absoluta de um cenário para uso em `page.goto`. */\nexport function urlFor(\n scenario: Scenario,\n options: { origin?: string; overrides?: Partial<ControlsState> } = {},\n): string {\n return scenarioUrl(scenario, { origin: options.origin ?? testOrigin(), overrides: options.overrides });\n}\n\n/**\n * Caminho relativo de um cenário: `/rota?scenario=…`.\n *\n * É a forma preferida em Playwright, porque deixa o `baseURL` da configuração\n * decidir se o teste roda contra o preview ou contra o dev server. Um teste que\n * embute a origem passa a existir em duas versões, e a versão local é a que\n * ninguém roda.\n */\nexport function pathFor(\n scenario: Scenario,\n overrides: Partial<ControlsState> = {},\n): string {\n const url = new URL(scenarioUrl(scenario, { origin: \"http://design-space.invalid\", overrides }));\n return `${url.pathname}${url.search}`;\n}\n\n/**\n * Seletor do `<iframe>` onde a UI do produto roda desde a 0.8. Em Playwright:\n *\n * ```ts\n * await page.goto(pathFor(scenario));\n * const app = page.frameLocator(FRAME_SELECTOR);\n * await expect(app.getByRole(\"heading\", { name: \"Fila\" })).toBeVisible();\n * ```\n */\nexport const FRAME_SELECTOR = `iframe[${FRAME_ATTRIBUTE}]`;\n\n/**\n * Falha o teste quando o contrato de cenário do produto tem erro.\n *\n * É o equivalente do typecheck para o que o TypeScript não alcança: fixture\n * inexistente, persona escrita errada, rota que não casa com nada.\n */\nexport function assertValidProduct(product: ProductDefinition): void {\n const issues = validateProduct(product);\n if (hasErrors(issues)) {\n throw new Error(`Contrato de cenário inválido:\\n${formatIssues(issues)}`);\n }\n}\n\nexport {\n formatIssues,\n hasErrors,\n validateProduct,\n};\nexport { scenarioUrl } from \"../deploy/index.js\";\n"],"names":["testOrigin","fallback","env","urlFor","scenario","options","scenarioUrl","pathFor","overrides","url","FRAME_SELECTOR","FRAME_ATTRIBUTE","assertValidProduct","product","issues","validateProduct","hasErrors","formatIssues"],"mappings":"
|
|
1
|
+
{"version":3,"file":"testing.js","sources":["../src/testing/index.ts"],"sourcesContent":["/**\n * `@brucesantos/design-space/testing`\n *\n * Utilitários para os testes do produto. Vive num entrypoint separado porque\n * nada aqui deve chegar ao bundle do preview.\n *\n * O que este módulo assume: o preview é público, sem proteção de acesso (D-11).\n * Como não há segredo de bypass nem header de automação a emitir, o Playwright\n * aponta direto para a URL do preview — e é por isso que estas funções só\n * precisam de uma origem.\n */\n\nimport { scenarioUrl } from \"../deploy/index.js\";\nimport { FRAME_ATTRIBUTE } from \"../frame/index.js\";\nimport { validateProduct, hasErrors, formatIssues } from \"../registry/validate.js\";\nimport type { ControlsState, ProductDefinition, Scenario } from \"../types/index.js\";\n\n/**\n * Origem contra a qual os testes rodam.\n *\n * `PREVIEW_URL` é o que o gatilho `deployment_status` do GitHub Actions entrega\n * pronto (§10.6), o que dispensa qualquer lógica de descobrir onde o preview foi\n * publicado. Sem ela, cai no dev server local.\n */\nexport function testOrigin(fallback = \"http://localhost:5173\"): string {\n const env = typeof process !== \"undefined\" ? process.env : {};\n const url = env.PREVIEW_URL || env.BASE_URL || fallback;\n return url.replace(/\\/$/, \"\");\n}\n\n/** URL absoluta de um cenário para uso em `page.goto`. */\nexport function urlFor(\n scenario: Scenario,\n options: { origin?: string; overrides?: Partial<ControlsState> } = {},\n): string {\n return scenarioUrl(scenario, { origin: options.origin ?? testOrigin(), overrides: options.overrides });\n}\n\n/**\n * Caminho relativo de um cenário: `/rota?scenario=…`.\n *\n * É a forma preferida em Playwright, porque deixa o `baseURL` da configuração\n * decidir se o teste roda contra o preview ou contra o dev server. Um teste que\n * embute a origem passa a existir em duas versões, e a versão local é a que\n * ninguém roda.\n */\nexport function pathFor(\n scenario: Scenario,\n overrides: Partial<ControlsState> = {},\n): string {\n const url = new URL(scenarioUrl(scenario, { origin: \"http://design-space.invalid\", overrides }));\n return `${url.pathname}${url.search}`;\n}\n\n/**\n * Seletor do `<iframe>` onde a UI do produto roda desde a 0.8. Em Playwright:\n *\n * ```ts\n * await page.goto(pathFor(scenario));\n * const app = page.frameLocator(FRAME_SELECTOR);\n * await expect(app.getByRole(\"heading\", { name: \"Fila\" })).toBeVisible();\n * ```\n */\nexport const FRAME_SELECTOR = `iframe[${FRAME_ATTRIBUTE}]`;\n\n/**\n * Falha o teste quando o contrato de cenário do produto tem erro.\n *\n * É o equivalente do typecheck para o que o TypeScript não alcança: fixture\n * inexistente, persona escrita errada, rota que não casa com nada.\n */\nexport function assertValidProduct(product: ProductDefinition): void {\n const issues = validateProduct(product);\n if (hasErrors(issues)) {\n throw new Error(`Contrato de cenário inválido:\\n${formatIssues(issues)}`);\n }\n}\n\nexport {\n formatIssues,\n hasErrors,\n validateProduct,\n};\nexport { scenarioUrl } from \"../deploy/index.js\";\n"],"names":["testOrigin","fallback","env","urlFor","scenario","options","scenarioUrl","pathFor","overrides","url","FRAME_SELECTOR","FRAME_ATTRIBUTE","assertValidProduct","product","issues","validateProduct","hasErrors","formatIssues"],"mappings":";;AAwBO,SAASA,EAAWC,IAAW,yBAAiC;AACrE,QAAMC,IAAM,OAAO,UAAY,MAAc,QAAQ,MAAM,CAAA;AAE3D,UADYA,EAAI,eAAeA,EAAI,YAAYD,GACpC,QAAQ,OAAO,EAAE;AAC9B;AAGO,SAASE,EACdC,GACAC,IAAmE,IAC3D;AACR,SAAOC,EAAYF,GAAU,EAAE,QAAQC,EAAQ,UAAUL,KAAc,WAAWK,EAAQ,UAAA,CAAW;AACvG;AAUO,SAASE,EACdH,GACAI,IAAoC,IAC5B;AACR,QAAMC,IAAM,IAAI,IAAIH,EAAYF,GAAU,EAAE,QAAQ,+BAA+B,WAAAI,EAAA,CAAW,CAAC;AAC/F,SAAO,GAAGC,EAAI,QAAQ,GAAGA,EAAI,MAAM;AACrC;AAWO,MAAMC,IAAiB,UAAUC,CAAe;AAQhD,SAASC,EAAmBC,GAAkC;AACnE,QAAMC,IAASC,EAAgBF,CAAO;AACtC,MAAIG,EAAUF,CAAM;AAClB,UAAM,IAAI,MAAM;AAAA,EAAkCG,EAAaH,CAAM,CAAC,EAAE;AAE5E;"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -90,8 +90,8 @@ export type Scenario = {
|
|
|
90
90
|
ticket?: string;
|
|
91
91
|
/**
|
|
92
92
|
* Ids de `ComponentPreview` usados na tela. Alimentam "Componentes usados" no
|
|
93
|
-
* painel de informações, o "Usado em" de cada componente e a tabela
|
|
94
|
-
*
|
|
93
|
+
* painel de informações, o "Usado em" de cada componente e a tabela de
|
|
94
|
+
* componentes da descrição do PR.
|
|
95
95
|
*/
|
|
96
96
|
components?: string[];
|
|
97
97
|
/**
|
|
@@ -153,7 +153,7 @@ export type RouteDefinition = {
|
|
|
153
153
|
/** Controles por componente, exibidos no painel Variações. */
|
|
154
154
|
controls?: ControlGroup[];
|
|
155
155
|
/**
|
|
156
|
-
* Comportamento esperado da tela, para Informações e
|
|
156
|
+
* Comportamento esperado da tela, para Informações e a descrição do PR
|
|
157
157
|
* quando não há cenário ativo.
|
|
158
158
|
*/
|
|
159
159
|
expected?: string[];
|
|
@@ -163,7 +163,7 @@ export type RouteDefinition = {
|
|
|
163
163
|
* Valores de exemplo dos parâmetros do `path` (`{ id: "REQ-1" }` para
|
|
164
164
|
* `/requests/:id`), e de `*` quando houver. O motor usa sempre que precisa
|
|
165
165
|
* abrir a tela sem cenário — lateral, variação padrão, links de Informações e
|
|
166
|
-
*
|
|
166
|
+
* a descrição do PR. Sem eles, o caminho abre literal (`/requests/:id`).
|
|
167
167
|
*/
|
|
168
168
|
params?: Record<string, string>;
|
|
169
169
|
};
|
|
@@ -210,7 +210,7 @@ export type ComponentPreview<T = unknown> = {
|
|
|
210
210
|
description?: string;
|
|
211
211
|
/**
|
|
212
212
|
* Origem no sistema real, em texto livre: `components/button.ex → button/1`.
|
|
213
|
-
* Aparece em Informações e na tabela
|
|
213
|
+
* Aparece em Informações e na tabela de componentes da descrição do PR.
|
|
214
214
|
*/
|
|
215
215
|
source?: string;
|
|
216
216
|
/** Composição visual fornecida e mantida pelo produto. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brucesantos/design-space",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Motor neutro do Bananas Design Space: telas como rotas com variações, catálogo de componentes, chrome em preto e branco com a UI do produto num iframe, deep links e controles de persona/viewport/rede. Não contém UI de cliente.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,9 +39,17 @@
|
|
|
39
39
|
"types": "./dist/devtools-hook.d.ts",
|
|
40
40
|
"default": "./dist/devtools-hook.js"
|
|
41
41
|
},
|
|
42
|
+
"./pr": {
|
|
43
|
+
"types": "./dist/pr/index.d.ts",
|
|
44
|
+
"default": "./dist/pr.js"
|
|
45
|
+
},
|
|
42
46
|
"./styles.css": "./dist/design-space.css"
|
|
43
47
|
},
|
|
48
|
+
"bin": {
|
|
49
|
+
"design-space-pr": "./bin/design-space-pr.mjs"
|
|
50
|
+
},
|
|
44
51
|
"files": [
|
|
52
|
+
"bin",
|
|
45
53
|
"dist",
|
|
46
54
|
"README.md",
|
|
47
55
|
"CHANGELOG.md"
|