@polymorphism-tech/morph-spec 10.10.1 → 10.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.
@@ -28,9 +28,14 @@ const NOT_APPLICABLE_RE = /^(nao se aplica|n\/a)\b/;
28
28
 
29
29
  const SCREEN_HEADING_RE = /^##\s+tela\s*[:—–-]\s*(.+?)\s*#*\s*$/i;
30
30
  const CHECKLIST_HEADING_RE = /^(#{3,6})\s+checklist\b/i;
31
+ const COMPONENTS_HEADING_RE = /^(#{3,6})\s+componentes\b/i;
32
+ const REGISTRY_ITEM_RE = /@[\w-]+\/[\w-]+/;
31
33
  const PROTOTYPE_LINE_RE = /prot[oó]tipo/i;
32
34
  const PROTOTYPE_PATH_RE = /(?:1-design\/)?(prototipos\/[^\s`|)\]]+\.html)/i;
33
35
 
36
+ /** De onde vem cada componente da tela: já existe no projeto, vem de um registry do shadcn, ou é escrito agora. */
37
+ export const COMPONENT_ORIGINS = ['projeto', 'registry', 'novo'];
38
+
34
39
  /** As larguras dos prints que o laço de autocrítica deixa ao lado do protótipo. */
35
40
  export const PROTOTYPE_WIDTHS = [1280, 390];
36
41
 
@@ -68,6 +73,15 @@ function checklistRow(line) {
68
73
  return [bullet[1].slice(0, colon), bullet[1].slice(colon + 1).trim()];
69
74
  }
70
75
 
76
+ function componentRow(line) {
77
+ const trimmed = line.trim();
78
+ if (!trimmed.startsWith('|')) return null;
79
+ const cells = tableCells(trimmed);
80
+ if (cells.every((c) => /^:?-{2,}:?$/.test(c) || c === '')) return null;
81
+ if (normalizeLabel(cells[0]) === 'componente') return null;
82
+ return { name: cells[0], origin: normalizeLabel(cells[1]), source: cells.slice(2).join(' ').trim() };
83
+ }
84
+
71
85
  export function tableCells(line) {
72
86
  const inner = line.trim().replace(/^\|/, '').replace(/\|$/, '');
73
87
  return inner.split(/(?<!\\)\|/).map((cell) => cell.trim());
@@ -87,7 +101,7 @@ function proseLines(markdown) {
87
101
  export function parseScreens(markdown) {
88
102
  const screens = [];
89
103
  let screen = null;
90
- let checklistLevel = 0;
104
+ let section = null;
91
105
 
92
106
  for (const line of proseLines(markdown)) {
93
107
  const heading = /^(#{1,6})\s/.exec(line);
@@ -95,24 +109,32 @@ export function parseScreens(markdown) {
95
109
  const level = heading[1].length;
96
110
  const named = SCREEN_HEADING_RE.exec(line);
97
111
  if (level <= 2) {
98
- screen = named && named[1].trim() ? { name: named[1].trim(), hasChecklist: false, answers: new Map(), prototype: null } : null;
112
+ screen = named && named[1].trim() ? { name: named[1].trim(), hasChecklist: false, answers: new Map(), components: [], prototype: null } : null;
99
113
  if (screen) screens.push(screen);
100
- checklistLevel = 0;
114
+ section = null;
101
115
  continue;
102
116
  }
103
117
  const checklist = CHECKLIST_HEADING_RE.exec(line);
118
+ const components = COMPONENTS_HEADING_RE.exec(line);
104
119
  if (screen && checklist) {
105
120
  screen.hasChecklist = true;
106
- checklistLevel = checklist[1].length;
107
- } else if (checklistLevel && level <= checklistLevel) {
108
- checklistLevel = 0;
121
+ section = { kind: 'checklist', level: checklist[1].length };
122
+ } else if (screen && components) {
123
+ section = { kind: 'components', level: components[1].length };
124
+ } else if (section && level <= section.level) {
125
+ section = null;
109
126
  }
110
127
  continue;
111
128
  }
112
129
  if (screen && !screen.prototype && PROTOTYPE_LINE_RE.test(line)) {
113
130
  screen.prototype = PROTOTYPE_PATH_RE.exec(line)?.[1] ?? null;
114
131
  }
115
- if (!screen || !checklistLevel) continue;
132
+ if (!screen || !section) continue;
133
+ if (section.kind === 'components') {
134
+ const component = componentRow(line);
135
+ if (component) screen.components.push(component);
136
+ continue;
137
+ }
116
138
  const row = checklistRow(line);
117
139
  if (!row) continue;
118
140
  for (const id of itemsOf(row[0])) {
@@ -154,11 +176,37 @@ export function auditScreenChecklist(markdown) {
154
176
  if (missing.length) problems.push(`tela "${screen.name}": falta ${missing.map(labelOf).join(', ')}`);
155
177
  if (unanswered.length) problems.push(`tela "${screen.name}": sem resposta em ${unanswered.map(labelOf).join(', ')}`);
156
178
  }
157
- return { name: screen.name, hasChecklist: screen.hasChecklist, missing, unanswered, prototype: screen.prototype, states: statesOf(screen) };
179
+ return { name: screen.name, hasChecklist: screen.hasChecklist, missing, unanswered, prototype: screen.prototype, states: statesOf(screen), components: screen.components };
158
180
  });
159
181
  return { legacy: false, screens, problems };
160
182
  }
161
183
 
184
+ const MISSING_SOURCE = {
185
+ projeto: 'sem o caminho do componente que já existe',
186
+ registry: 'sem o item do registry (`@registry/item`)',
187
+ novo: 'sem o que foi buscado e por que não serve',
188
+ };
189
+
190
+ // Componente novo só depois da busca: a linha diz de onde ele vem, e `novo` carrega o motivo.
191
+ export function auditComponents(screens) {
192
+ const problems = [];
193
+ for (const screen of screens) {
194
+ const rows = screen.components ?? [];
195
+ if (rows.length === 0) {
196
+ problems.push(`tela "${screen.name}" sem a tabela \`### Componentes\` (Componente | Origem | Fonte ou motivo)`);
197
+ continue;
198
+ }
199
+ for (const { name, origin, source } of rows) {
200
+ if (!COMPONENT_ORIGINS.includes(origin)) {
201
+ problems.push(`tela "${screen.name}": componente "${name}" sem origem válida (${COMPONENT_ORIGINS.join(', ')})`);
202
+ } else if (isPlaceholder(source) || (origin === 'registry' && !REGISTRY_ITEM_RE.test(source))) {
203
+ problems.push(`tela "${screen.name}": componente "${name}" ${MISSING_SOURCE[origin]}`);
204
+ }
205
+ }
206
+ }
207
+ return problems;
208
+ }
209
+
162
210
  /** The states the prototype must switch to, by the checklist items that apply to the screen. */
163
211
  export const PROTOTYPE_STATES = { estados: ['vazio', 'carregando'], erro: ['erro'] };
164
212
  export const STATE_PRINT_WIDTH = 390;
@@ -206,6 +254,7 @@ export function collectScreenChecklist(cwd, featureName, gateName) {
206
254
  if (audit.legacy) signal.exempt = LEGACY_MOCKUP_EXEMPTION;
207
255
  if (gateName === 'uiux' && !audit.legacy) {
208
256
  const designDir = dirname(getAbsoluteOutputPath(cwd, featureName, 'uiMockups'));
257
+ signal.components = auditComponents(audit.screens);
209
258
  signal.prototypes = auditPrototypes(audit.screens, designDir);
210
259
  }
211
260
  if (gateName === 'review') {
@@ -180,8 +180,9 @@ function auditNextjs(root, read) {
180
180
  if (pagesRouter && !appRouter) add('Médio', 'Pages Router em vez de App Router', [next.file], 'migrar as rotas para `app/`');
181
181
  rows.push({ layer: 'Estilo', detected: next.deps.tailwindcss ? 'Tailwind' : 'ausente', expected: 'Tailwind', ok: Boolean(next.deps.tailwindcss) });
182
182
  const motionPackages = ['motion', 'framer-motion'].filter((p) => next.deps[p]);
183
- rows.push({ layer: 'Motion', detected: motionPackages.join(' + ') || 'ausente', expected: 'motion (`motion/react`)', ok: motionPackages.length < 2 });
183
+ rows.push({ layer: 'Motion', detected: motionPackages.join(' + ') || 'ausente', expected: 'motion (`motion/react`)', ok: motionPackages.length < 2 && motionPackages[0] !== 'framer-motion' });
184
184
  if (motionPackages.length === 2) add('Baixo', '`motion` e `framer-motion` instalados juntos', [next.file], 'remover `framer-motion`; o import é `motion/react`');
185
+ else if (motionPackages[0] === 'framer-motion') add('Baixo', '`framer-motion` em vez de `motion`', [next.file], '`npm uninstall framer-motion && npm install motion`; o import passa a ser `motion/react`');
185
186
  const shadcn = existsSync(join(root, base, 'components.json'));
186
187
  const otherUi = UI_LIBRARIES.filter((lib) => next.deps[lib]);
187
188
  rows.push({ layer: 'UI', detected: otherUi.join(', ') || (shadcn ? 'shadcn' : 'ausente'), expected: 'shadcn', ok: otherUi.length === 0 });
@@ -190,6 +191,17 @@ function auditNextjs(root, read) {
190
191
  if (!eslintConfig || !/no-restricted-imports/.test(read(eslintConfig) ?? '')) {
191
192
  add('Médio', 'ESLint do stack ausente (o lint não barra import proibido nem fetch em `useEffect`)', eslintConfig ? [eslintConfig] : [],
192
193
  '`eslint.config.mjs` na raiz do app: `morph-spec standards --show frontend-nextjs-lint#files`');
194
+ } else if (shadcn && !/forbid-elements/.test(read(eslintConfig) ?? '')) {
195
+ add('Baixo', 'ESLint sem `react/forbid-elements` (o `verify` cobra elemento cru; o editor não avisa)', [eslintConfig],
196
+ 'copiar `RAW_ELEMENTS` e o bloco da regra: `morph-spec standards --show frontend-nextjs-lint#files`');
197
+ }
198
+ if (shadcn) {
199
+ let registries = null;
200
+ try { registries = JSON.parse(read(`${base}components.json`)).registries; } catch { registries = null; }
201
+ if (!registries || Object.keys(registries).length === 0) {
202
+ add('Médio', '`components.json` sem `registries` (o catálogo de blocos prontos não entra na busca)', [`${base}components.json`],
203
+ '`morph-spec update` acrescenta os do stack (`morph-spec standards --show frontend-nextjs-components#catalog-first`)');
204
+ }
193
205
  }
194
206
  return { rows, deviations };
195
207
  }