@finedesign/cli 0.2.0-rc.0 → 0.3.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 +20 -0
- package/README.md +68 -155
- package/data/1.24.9/catalog.json +1 -1
- package/data/1.24.9/manifest.json +2 -2
- package/data/1.25.0/catalog.json +1 -1
- package/data/1.25.0/manifest.json +7 -8
- package/package.json +2 -1
- package/skills/fine-design/SKILL.md +2 -2
- package/skills/fine-design/references/component-guide.md +1 -1
- package/skills/fine-design/references/imports-and-setup.md +8 -8
- package/src/cli.mjs +165 -10
- package/src/core/catalog.mjs +300 -19
- package/src/core/contracts.mjs +8 -1
- package/src/core/html.cjs +152 -0
- package/src/core/lint.mjs +302 -0
- package/src/core/runtime.mjs +62 -0
- package/src/mcp.mjs +7 -3
- package/skills/fine-design/references/browser-runtime-legacy.json +0 -71
package/src/core/catalog.mjs
CHANGED
|
@@ -4,20 +4,147 @@ import { sha256 } from './data.mjs';
|
|
|
4
4
|
|
|
5
5
|
const MAX_INLINE_JSON_BYTES = 16 * 1024;
|
|
6
6
|
const CHART_QUERY_PATTERN = /chart|vanchart|图表|折线|柱状|饼图|散点|雷达|漏斗|仪表盘|热力图|词云/i;
|
|
7
|
+
const PREFERRED_COMPONENTS = new Set(['next-table', 'm-cascader']);
|
|
8
|
+
const API_SECTION_PATTERN = /API|属性|Props|事件|方法|Ref|参数|配置|Column|Cell|HeaderCell|Rule|Option|Theme|统一弹层/i;
|
|
9
|
+
const NON_API_SECTION_NAMES = new Set(['何时使用', '代码演示', '代码展示', '设计变量', '内置图标列表']);
|
|
7
10
|
|
|
8
|
-
export function
|
|
9
|
-
|
|
10
|
-
if (
|
|
11
|
-
|
|
11
|
+
export function levenshtein(a, b) {
|
|
12
|
+
if (a === b) return 0;
|
|
13
|
+
if (!a.length) return b.length;
|
|
14
|
+
if (!b.length) return a.length;
|
|
15
|
+
const prev = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
16
|
+
const curr = new Array(b.length + 1);
|
|
17
|
+
for (let i = 0; i < a.length; i++) {
|
|
18
|
+
curr[0] = i + 1;
|
|
19
|
+
for (let j = 0; j < b.length; j++) {
|
|
20
|
+
const cost = a[i] === b[j] ? 0 : 1;
|
|
21
|
+
curr[j + 1] = Math.min(curr[j] + 1, prev[j + 1] + 1, prev[j] + cost);
|
|
22
|
+
}
|
|
23
|
+
for (let j = 0; j <= b.length; j++) prev[j] = curr[j];
|
|
24
|
+
}
|
|
25
|
+
return prev[b.length];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function suggestSimilarComponents(catalog, rawQuery, limit = 3) {
|
|
29
|
+
const q = (rawQuery || '').trim().toLowerCase().replace(/[-_.\s]+/g, '');
|
|
30
|
+
if (!q) return [];
|
|
31
|
+
const isIconQuery = /(?:outlined|filled|icon)$/i.test(rawQuery.trim());
|
|
32
|
+
const candidates = [];
|
|
33
|
+
|
|
34
|
+
if (isIconQuery) {
|
|
35
|
+
const svgIcon = catalog.components.find((c) => c.id === 'svg-icon');
|
|
36
|
+
const stem = q.replace(/(?:outlined|filled|icon)$/i, '');
|
|
37
|
+
for (const icon of svgIcon?.aliases || []) {
|
|
38
|
+
const iconNorm = icon.toLowerCase();
|
|
39
|
+
const iconStem = iconNorm.replace(/(?:outlined|filled)$/i, '');
|
|
40
|
+
const dist = levenshtein(stem || q, iconStem);
|
|
41
|
+
const substr = (stem && (iconStem.includes(stem) || stem.includes(iconStem))) || iconNorm.includes(q);
|
|
42
|
+
const firstMatch = (stem || q)[0] === iconStem[0];
|
|
43
|
+
if (substr || dist <= Math.max(2, Math.floor((stem || q).length * 0.45))) {
|
|
44
|
+
const score = (substr ? 100 : 0) + (firstMatch ? 25 : 0) - dist * 10;
|
|
45
|
+
candidates.push({ label: icon, score });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (const component of catalog.components) {
|
|
51
|
+
const names = [component.exports[0], component.id, component.title, ...component.exports.slice(1), ...component.aliases.filter((a) => !/(?:Outlined|Filled)$/.test(a))];
|
|
52
|
+
let bestScore = -Infinity;
|
|
53
|
+
for (const name of names) {
|
|
54
|
+
if (!name) continue;
|
|
55
|
+
const norm = name.toLowerCase().replace(/[-_.\s]+/g, '');
|
|
56
|
+
if (!norm) continue;
|
|
57
|
+
const dist = levenshtein(q, norm);
|
|
58
|
+
const maxAllowed = Math.max(2, Math.floor(Math.max(q.length, norm.length) * 0.4));
|
|
59
|
+
const substr = norm.includes(q) || q.includes(norm);
|
|
60
|
+
if (!substr && dist > maxAllowed) continue;
|
|
61
|
+
const firstMatch = q[0] === norm[0];
|
|
62
|
+
const score = (substr ? 120 : 0) + (firstMatch ? 30 : 0) - dist * 15 - Math.abs(norm.length - q.length) * 2;
|
|
63
|
+
if (score > bestScore) bestScore = score;
|
|
64
|
+
}
|
|
65
|
+
if (bestScore > -Infinity) {
|
|
66
|
+
candidates.push({ label: `${component.exports[0]} (${component.id})`, score: bestScore });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return candidates
|
|
71
|
+
.sort((a, b) => b.score - a.score || a.label.localeCompare(b.label))
|
|
72
|
+
.slice(0, limit)
|
|
73
|
+
.map((item) => item.label);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function sourceMetadata(catalog) {
|
|
77
|
+
return {
|
|
12
78
|
version: catalog.version,
|
|
13
79
|
sourceRevision: catalog.sourceRevision,
|
|
14
80
|
sourceDirty: catalog.sourceDirty,
|
|
15
81
|
contentHash: catalog.contentHash,
|
|
16
82
|
sourceKind: catalog.sourceKind
|
|
17
83
|
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function resolveComponentOrThrow(catalog, rawComponent) {
|
|
87
|
+
const targetName = rawComponent.toLowerCase();
|
|
88
|
+
const component =
|
|
89
|
+
catalog.components.find((item) =>
|
|
90
|
+
[item.id, ...item.exports].some((name) => name.toLowerCase() === targetName)
|
|
91
|
+
) ||
|
|
92
|
+
catalog.components.find((item) =>
|
|
93
|
+
item.aliases.some((name) => name.toLowerCase() === targetName)
|
|
94
|
+
);
|
|
95
|
+
if (!component) {
|
|
96
|
+
const similar = suggestSimilarComponents(catalog, rawComponent, 3);
|
|
97
|
+
const suggestions = [
|
|
98
|
+
...(similar.length ? [`Did you mean: ${similar.join(', ')}?`] : []),
|
|
99
|
+
'Use search to find a component.'
|
|
100
|
+
];
|
|
101
|
+
throw new ToolError('COMPONENT_NOT_FOUND', `Unknown component: ${rawComponent}.`, 4, { suggestions });
|
|
102
|
+
}
|
|
103
|
+
return component;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function scoreComponent(component, terms, rawQuery) {
|
|
107
|
+
const q = rawQuery.toLowerCase().trim();
|
|
108
|
+
const primary = [component.id, component.title, ...component.exports].map((s) => s.toLowerCase());
|
|
109
|
+
const secondary = [component.subtitle, ...component.aliases].filter(Boolean).map((s) => s.toLowerCase());
|
|
110
|
+
const headings = [
|
|
111
|
+
...(component.sections || []).map((s) => s.heading.toLowerCase()),
|
|
112
|
+
...component.examples.map((e) => e.title.toLowerCase())
|
|
113
|
+
];
|
|
114
|
+
const desc = (component.description || '').toLowerCase();
|
|
115
|
+
|
|
116
|
+
let score = 0;
|
|
117
|
+
if (primary.some((s) => s === q)) score += 1000;
|
|
118
|
+
else if (primary.some((s) => s.startsWith(q))) score += 600;
|
|
119
|
+
else if (primary.some((s) => s.includes(q))) score += 400;
|
|
120
|
+
|
|
121
|
+
if (secondary.some((s) => s === q)) score += 800;
|
|
122
|
+
else if (secondary.some((s) => s.startsWith(q))) score += 500;
|
|
123
|
+
else if (secondary.some((s) => s.includes(q))) score += 300;
|
|
124
|
+
|
|
125
|
+
for (const term of terms) {
|
|
126
|
+
if (primary.some((s) => s === term)) score += 200;
|
|
127
|
+
else if (primary.some((s) => s.includes(term))) score += 120;
|
|
128
|
+
if (secondary.some((s) => s === term)) score += 160;
|
|
129
|
+
else if (secondary.some((s) => s.includes(term))) score += 90;
|
|
130
|
+
if (headings.some((s) => s.includes(term))) score += 30;
|
|
131
|
+
if (desc.includes(term)) score += 15;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (component.docsAvailable) score += 100;
|
|
135
|
+
if (PREFERRED_COMPONENTS.has(component.id)) score += 40;
|
|
136
|
+
return score;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function queryCatalog(catalog, tool, args) {
|
|
140
|
+
args = validateInput(tool, args);
|
|
141
|
+
if (args.version !== catalog.version) throw new ToolError('VERSION_NOT_SUPPORTED', 'Requested Fine Design version is not available.', 3, { requestedVersion: args.version, availableVersions: [catalog.version] });
|
|
142
|
+
const source = sourceMetadata(catalog);
|
|
18
143
|
if (tool === 'search_components') {
|
|
144
|
+
const pageSize = args.limit || 20;
|
|
145
|
+
const offset = args.offset || 0;
|
|
19
146
|
const terms = args.query.toLowerCase().trim().split(/\s+/).filter(Boolean);
|
|
20
|
-
const
|
|
147
|
+
const filtered = catalog.components.filter((component) => {
|
|
21
148
|
const text = [
|
|
22
149
|
component.id,
|
|
23
150
|
component.title,
|
|
@@ -25,20 +152,30 @@ export function queryCatalog(catalog, tool, args) {
|
|
|
25
152
|
...component.exports,
|
|
26
153
|
...component.aliases,
|
|
27
154
|
component.description,
|
|
155
|
+
...(component.sections || []).map((item) => item.heading),
|
|
28
156
|
...component.examples.map((item) => item.title)
|
|
29
157
|
]
|
|
30
158
|
.join(' ')
|
|
31
159
|
.toLowerCase();
|
|
32
160
|
return terms.every((term) => text.includes(term));
|
|
33
161
|
});
|
|
34
|
-
const
|
|
35
|
-
? [
|
|
36
|
-
:
|
|
162
|
+
const matches = terms.length > 0
|
|
163
|
+
? [...filtered].sort((a, b) => scoreComponent(b, terms, args.query) - scoreComponent(a, terms, args.query) || a.id.localeCompare(b.id))
|
|
164
|
+
: filtered;
|
|
165
|
+
let suggestions;
|
|
166
|
+
if (matches.length === 0) {
|
|
167
|
+
if (CHART_QUERY_PATTERN.test(args.query)) {
|
|
168
|
+
suggestions = ['Charts are provided by the standalone VanChart skill (/van-chart) and @van/analysis runtime; see /docs/chart/skills-cn.'];
|
|
169
|
+
} else {
|
|
170
|
+
const similar = suggestSimilarComponents(catalog, args.query, 3);
|
|
171
|
+
if (similar.length) suggestions = [`Did you mean: ${similar.join(', ')}?`];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
37
174
|
return {
|
|
38
175
|
...source,
|
|
39
176
|
total: matches.length,
|
|
40
177
|
components: matches
|
|
41
|
-
.slice(
|
|
178
|
+
.slice(offset, offset + pageSize)
|
|
42
179
|
.map(
|
|
43
180
|
({
|
|
44
181
|
id,
|
|
@@ -60,17 +197,11 @@ export function queryCatalog(catalog, tool, args) {
|
|
|
60
197
|
examples: examples.map(({ id, title }) => ({ id, title }))
|
|
61
198
|
})
|
|
62
199
|
),
|
|
63
|
-
nextOffset: matches.length >
|
|
64
|
-
...(
|
|
200
|
+
nextOffset: matches.length > offset + pageSize ? offset + pageSize : null,
|
|
201
|
+
...(suggestions ? { suggestions } : {})
|
|
65
202
|
};
|
|
66
203
|
}
|
|
67
|
-
const component = catalog.
|
|
68
|
-
[item.id, ...item.exports, ...item.aliases].some(
|
|
69
|
-
(name) => name.toLowerCase() === args.component.toLowerCase()
|
|
70
|
-
)
|
|
71
|
-
);
|
|
72
|
-
if (!component)
|
|
73
|
-
throw new ToolError('COMPONENT_NOT_FOUND', `Unknown component: ${args.component}.`, 4, { suggestions: ['Use search to find a component.'] });
|
|
204
|
+
const component = resolveComponentOrThrow(catalog, args.component);
|
|
74
205
|
if (tool === 'get_component_doc') {
|
|
75
206
|
if (args.section && args.summary) {
|
|
76
207
|
throw new ToolError('INVALID_ARGUMENT', 'Cannot combine section and summary.', 2);
|
|
@@ -120,13 +251,14 @@ export function queryCatalog(catalog, tool, args) {
|
|
|
120
251
|
component: component.id,
|
|
121
252
|
sourcePath: component.sourcePath,
|
|
122
253
|
...section,
|
|
123
|
-
examples
|
|
254
|
+
examples: component.examples.map(({ id, title }) => ({ id, title }))
|
|
124
255
|
};
|
|
125
256
|
}
|
|
126
257
|
return {
|
|
127
258
|
...source,
|
|
128
259
|
component: component.id,
|
|
129
260
|
exports: component.exports,
|
|
261
|
+
aliases: component.aliases,
|
|
130
262
|
docsAvailable: component.docsAvailable,
|
|
131
263
|
sourcePath: component.sourcePath,
|
|
132
264
|
sections: component.sections.map(({ heading }) => heading),
|
|
@@ -166,3 +298,152 @@ export function queryCatalog(catalog, tool, args) {
|
|
|
166
298
|
}
|
|
167
299
|
throw new Error(`Unknown tool: ${tool}`);
|
|
168
300
|
}
|
|
301
|
+
|
|
302
|
+
export function getComponentInfo(catalog, { component: rawComponent }) {
|
|
303
|
+
const source = sourceMetadata(catalog);
|
|
304
|
+
const component = resolveComponentOrThrow(catalog, rawComponent);
|
|
305
|
+
const topLevelApiSections = component.sections.filter((s) => s.markdown.startsWith('## ') && API_SECTION_PATTERN.test(s.heading));
|
|
306
|
+
const apiSections = topLevelApiSections.length > 0
|
|
307
|
+
? topLevelApiSections
|
|
308
|
+
: component.sections.filter((s) => API_SECTION_PATTERN.test(s.heading) && !NON_API_SECTION_NAMES.has(s.heading));
|
|
309
|
+
const selectedSections = apiSections.length > 0
|
|
310
|
+
? apiSections
|
|
311
|
+
: component.sections.filter((s) => !NON_API_SECTION_NAMES.has(s.heading));
|
|
312
|
+
return {
|
|
313
|
+
...source,
|
|
314
|
+
component: component.id,
|
|
315
|
+
title: component.title,
|
|
316
|
+
subtitle: component.subtitle,
|
|
317
|
+
description: component.description,
|
|
318
|
+
exports: component.exports,
|
|
319
|
+
aliases: component.aliases,
|
|
320
|
+
docsAvailable: component.docsAvailable,
|
|
321
|
+
sourcePath: component.sourcePath,
|
|
322
|
+
sections: selectedSections.map((s) => s.heading),
|
|
323
|
+
markdown: selectedSections.map((s) => s.markdown).join('\n\n'),
|
|
324
|
+
examples: component.examples.map(({ id, title }) => ({ id, title }))
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function parseTokenSection(markdown) {
|
|
329
|
+
const parseTable = (block) => {
|
|
330
|
+
if (!block) return [];
|
|
331
|
+
const rows = [];
|
|
332
|
+
for (const line of block.split(/\r?\n/)) {
|
|
333
|
+
const match = line.trim().match(/^\|\s*`(--fd-[^`]+)`\s*\|\s*`([^`]*)`\s*\|$/);
|
|
334
|
+
if (match) rows.push({ name: match[1], value: match[2] });
|
|
335
|
+
}
|
|
336
|
+
return rows;
|
|
337
|
+
};
|
|
338
|
+
const compMatch = markdown.match(/####\s*组件\s*Token([\s\S]*?)(?=####\s*全局\s*Token|$)/);
|
|
339
|
+
const globalMatch = markdown.match(/####\s*全局\s*Token([\s\S]*)$/);
|
|
340
|
+
return {
|
|
341
|
+
componentTokens: parseTable(compMatch?.[1]),
|
|
342
|
+
globalTokens: parseTable(globalMatch?.[1])
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export function getComponentTokens(catalog, { component: rawComponent, query = '' } = {}) {
|
|
347
|
+
const source = sourceMetadata(catalog);
|
|
348
|
+
const q = query.trim().toLowerCase();
|
|
349
|
+
if (rawComponent) {
|
|
350
|
+
const component = resolveComponentOrThrow(catalog, rawComponent);
|
|
351
|
+
const tokenSection = component.sections.find((s) => s.heading === '设计变量');
|
|
352
|
+
const filterFn = (t) => !q || t.name.toLowerCase().includes(q) || t.value.toLowerCase().includes(q);
|
|
353
|
+
const parsed = parseTokenSection(tokenSection?.markdown || '');
|
|
354
|
+
const componentTokens = parsed.componentTokens.filter(filterFn);
|
|
355
|
+
const globalTokens = parsed.globalTokens.filter(filterFn);
|
|
356
|
+
const markdown = q ? [
|
|
357
|
+
'## 设计变量',
|
|
358
|
+
...[['组件 Token', componentTokens], ['全局 Token', globalTokens]].map(([heading, tokens]) => [
|
|
359
|
+
`#### ${heading}`,
|
|
360
|
+
tokens.length ? [
|
|
361
|
+
'| Token 名称 | 默认值 |',
|
|
362
|
+
'| --- | --- |',
|
|
363
|
+
...tokens.map((token) => `| \`${token.name}\` | \`${token.value}\` |`)
|
|
364
|
+
].join('\n') : '无匹配 Token。'
|
|
365
|
+
].join('\n\n'))
|
|
366
|
+
].join('\n\n') : tokenSection?.markdown || '未收录设计变量。';
|
|
367
|
+
return {
|
|
368
|
+
...source,
|
|
369
|
+
component: component.id,
|
|
370
|
+
title: component.title,
|
|
371
|
+
exports: component.exports,
|
|
372
|
+
componentTokens,
|
|
373
|
+
globalTokens,
|
|
374
|
+
markdown
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
const globalMap = new Map();
|
|
378
|
+
const componentsWithTokens = [];
|
|
379
|
+
for (const component of catalog.components) {
|
|
380
|
+
const tokenSection = component.sections.find((s) => s.heading === '设计变量');
|
|
381
|
+
if (!tokenSection) continue;
|
|
382
|
+
const { componentTokens, globalTokens } = parseTokenSection(tokenSection.markdown);
|
|
383
|
+
if (componentTokens.length > 0) {
|
|
384
|
+
componentsWithTokens.push({
|
|
385
|
+
id: component.id,
|
|
386
|
+
exports: component.exports,
|
|
387
|
+
componentTokenCount: componentTokens.length,
|
|
388
|
+
globalTokenCount: globalTokens.length
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
for (const token of globalTokens) {
|
|
392
|
+
if (!globalMap.has(token.name)) globalMap.set(token.name, token.value);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
const allGlobalTokens = [...globalMap.entries()]
|
|
396
|
+
.map(([name, value]) => ({ name, value }))
|
|
397
|
+
.filter((t) => !q || t.name.toLowerCase().includes(q) || t.value.toLowerCase().includes(q))
|
|
398
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
399
|
+
return {
|
|
400
|
+
...source,
|
|
401
|
+
query,
|
|
402
|
+
totalGlobalTokens: allGlobalTokens.length,
|
|
403
|
+
globalTokens: allGlobalTokens,
|
|
404
|
+
componentsWithTokens
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export function diffCatalogs(fromCatalog, toCatalog) {
|
|
409
|
+
const fromMap = new Map(fromCatalog.components.map((c) => [c.id, c]));
|
|
410
|
+
const toMap = new Map(toCatalog.components.map((c) => [c.id, c]));
|
|
411
|
+
const addedComponents = [];
|
|
412
|
+
const removedComponents = [];
|
|
413
|
+
const updatedComponents = [];
|
|
414
|
+
|
|
415
|
+
for (const [id, comp] of toMap) {
|
|
416
|
+
if (!fromMap.has(id)) {
|
|
417
|
+
addedComponents.push({ id, exports: comp.exports, description: comp.description });
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
const prev = fromMap.get(id);
|
|
421
|
+
const prevSections = new Set(prev.sections.map((s) => s.heading));
|
|
422
|
+
const addedSections = comp.sections.map((s) => s.heading).filter((h) => !prevSections.has(h));
|
|
423
|
+
const prevExamples = new Set(prev.examples.map((e) => e.id));
|
|
424
|
+
const addedExamples = comp.examples.filter((e) => !prevExamples.has(e.id)).map((e) => ({ id: e.id, title: e.title }));
|
|
425
|
+
const prevAliases = new Set(prev.aliases || []);
|
|
426
|
+
const addedAliases = (comp.aliases || []).filter((a) => !prevAliases.has(a));
|
|
427
|
+
if (addedSections.length > 0 || addedExamples.length > 0 || addedAliases.length > 0) {
|
|
428
|
+
updatedComponents.push({ id, exports: comp.exports, addedSections, addedExamples, addedAliases });
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
for (const [id, comp] of fromMap) {
|
|
432
|
+
if (!toMap.has(id)) {
|
|
433
|
+
removedComponents.push({ id, exports: comp.exports });
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return {
|
|
438
|
+
fromVersion: fromCatalog.version,
|
|
439
|
+
toVersion: toCatalog.version,
|
|
440
|
+
addedComponents,
|
|
441
|
+
removedComponents,
|
|
442
|
+
updatedComponents,
|
|
443
|
+
migrations: [
|
|
444
|
+
{ legacy: 'Table / DataTable', recommended: 'NextTable', note: 'Use <NextTable> with declarative <NextTable.Column>, <NextTable.HeaderCell>, and <NextTable.Cell dataKey="..."> children.' },
|
|
445
|
+
{ legacy: 'Cascader', recommended: 'MCascader', note: 'Legacy Cascader has no online docs page; prefer MCascader for new pages.' },
|
|
446
|
+
{ legacy: 'Dialog.onCloseBtnClick', recommended: 'Dialog.onCancel', note: 'onCloseBtnClick is deprecated and fires alongside onCancel when clicking the close button.' }
|
|
447
|
+
]
|
|
448
|
+
};
|
|
449
|
+
}
|
package/src/core/contracts.mjs
CHANGED
|
@@ -4,13 +4,20 @@ import { ToolError } from './errors.mjs';
|
|
|
4
4
|
const version = z.string().min(1).max(80);
|
|
5
5
|
const component = z.string().min(1).max(100);
|
|
6
6
|
export const schemas = {
|
|
7
|
-
search_components: z.object({
|
|
7
|
+
search_components: z.object({
|
|
8
|
+
version,
|
|
9
|
+
query: z.string().max(200),
|
|
10
|
+
offset: z.number().int().min(0).max(10000).optional(),
|
|
11
|
+
limit: z.number().int().min(1).max(200).optional()
|
|
12
|
+
}).strict(),
|
|
8
13
|
get_component_doc: z.object({
|
|
9
14
|
version,
|
|
10
15
|
component,
|
|
11
16
|
section: z.string().min(1).max(200).optional(),
|
|
12
17
|
summary: z.boolean().optional().describe('Return only metadata, section headings and example IDs without full markdown.')
|
|
13
18
|
}).strict(),
|
|
19
|
+
list_browser_runtimes: z.object({ runtimeURL: z.string().max(2048).optional() }).strict(),
|
|
20
|
+
get_browser_runtime: z.object({ version, runtimeURL: z.string().max(2048).optional() }).strict(),
|
|
14
21
|
get_component_example: z.object({
|
|
15
22
|
version,
|
|
16
23
|
component,
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
function exampleHTML(resources, prefix) {
|
|
2
|
+
const url = (entry) => entry.url || `${prefix}${entry.path}`;
|
|
3
|
+
const escape = (value) => String(value).replace(/[&<>"']/g, (char) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[char]);
|
|
4
|
+
const css = resources.fineDesignCss;
|
|
5
|
+
const entries = [['fineDesignCss', '组件样式'], ['react', 'React'], ['reactDOM', 'ReactDOM'], ['fineDesign', 'Fine Design']];
|
|
6
|
+
const events = (name) => `onload="window.runtimeResourceState('${name}', true)" onerror="window.runtimeResourceState('${name}', false, this.src || this.href)"`;
|
|
7
|
+
const scripts = ['react', 'reactDOM', 'fineDesign'].map((name) => {
|
|
8
|
+
const entry = resources[name];
|
|
9
|
+
return `<script defer src="${escape(url(entry))}" integrity="${escape(entry.integrity)}" crossorigin="anonymous" ${events(name)}></script>`;
|
|
10
|
+
}).join('\n');
|
|
11
|
+
return `<!doctype html>
|
|
12
|
+
<html lang="zh-CN">
|
|
13
|
+
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
14
|
+
<title>Fine Design Playground</title>
|
|
15
|
+
<style>
|
|
16
|
+
* { box-sizing: border-box; }
|
|
17
|
+
[hidden] { display: none !important; }
|
|
18
|
+
body { margin: 0; color: #182c35; background: #f5f7f8; font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
|
|
19
|
+
button, a { -webkit-tap-highlight-color: transparent; }
|
|
20
|
+
button:focus-visible { outline: 2px solid #087c76; outline-offset: 4px; }
|
|
21
|
+
.shell { width: min(1080px, calc(100% - 64px)); margin: 0 auto; }
|
|
22
|
+
.site-header { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 32px 0; border-bottom: 1px solid #dde5e7; }
|
|
23
|
+
.wordmark { font-size: 20px; font-weight: 700; letter-spacing: -.6px; }
|
|
24
|
+
.wordmark span { margin-left: 14px; padding-left: 14px; border-left: 1px solid #cfdadd; color: #61747d; font-size: 11px; font-weight: 500; letter-spacing: 1.8px; }
|
|
25
|
+
.status { display: inline-flex; align-items: center; gap: 9px; color: #526970; font-size: 12px; }
|
|
26
|
+
.status::before { width: 7px; height: 7px; border-radius: 50%; background: #248b85; box-shadow: 0 0 0 4px #248b8514; content: ''; animation: pulse 1.8s ease-in-out infinite; }
|
|
27
|
+
.intro { padding: 58px 0 36px; }
|
|
28
|
+
.eyebrow { margin: 0 0 12px; color: #087c76; font-size: 11px; font-weight: 600; letter-spacing: 2.2px; }
|
|
29
|
+
h1 { margin: 0 0 16px; font-size: clamp(32px, 4vw, 46px); font-weight: 600; letter-spacing: -1.5px; line-height: 1.3; }
|
|
30
|
+
.intro > p:last-child { margin: 0; color: #61747d; font-size: 15px; }
|
|
31
|
+
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 20px; }
|
|
32
|
+
.preview, .runtime { min-width: 0; background: #fff; border: 1px solid #dde5e7; border-radius: 16px; box-shadow: 0 8px 32px #233c4510; }
|
|
33
|
+
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 24px; border-bottom: 1px solid #edf1f2; }
|
|
34
|
+
.panel-header h2, .runtime h2 { margin: 0; font-size: 13px; font-weight: 600; }
|
|
35
|
+
.panel-label { color: #61747d; font: 10px/1.5 ui-monospace, monospace; letter-spacing: 1px; }
|
|
36
|
+
#root { min-height: 334px; }
|
|
37
|
+
.loading, .demo { display: flex; min-height: 334px; padding: 32px 24px; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
|
|
38
|
+
.loading-orbit { width: 52px; height: 52px; margin-bottom: 22px; border: 1px solid #dce8e8; border-top: 2px solid #15938a; border-radius: 50%; animation: orbit 1.4s linear infinite; box-shadow: inset 0 0 0 10px #f5fafa; }
|
|
39
|
+
.loading h3 { margin: 0 0 8px; font-size: 15px; font-weight: 500; }
|
|
40
|
+
.loading p, .demo p { margin: 0; color: #61747d; font-size: 12px; }
|
|
41
|
+
.demo-count { display: block; margin: 4px 0 8px; color: #153b3c; font-size: 76px; font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -4px; line-height: 1.2; }
|
|
42
|
+
.demo-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 28px; }
|
|
43
|
+
.demo-actions > button { min-width: 112px; }
|
|
44
|
+
.runtime { padding: 24px; }
|
|
45
|
+
.runtime-heading { display: flex; align-items: center; justify-content: space-between; }
|
|
46
|
+
#load-count { color: #61747d; font: 11px/1.6 ui-monospace, monospace; }
|
|
47
|
+
progress { display: block; width: 100%; height: 3px; margin: 20px 0 22px; overflow: hidden; appearance: none; border: 0; border-radius: 4px; background: #e8efef; }
|
|
48
|
+
progress::-webkit-progress-bar { background: #e8efef; }
|
|
49
|
+
progress::-webkit-progress-value { background: #14867f; transition: width .25s; }
|
|
50
|
+
progress::-moz-progress-bar { background: #14867f; }
|
|
51
|
+
.resources { margin: 0; padding: 0; list-style: none; }
|
|
52
|
+
.resources li { display: flex; gap: 10px; align-items: center; padding: 13px 0; border-bottom: 1px solid #edf1f2; }
|
|
53
|
+
.resource-dot { flex: 0 0 auto; width: 6px; height: 6px; border: 1px solid #b0bfc3; border-radius: 50%; }
|
|
54
|
+
.resource-name { flex: 1; color: #425c64; font-size: 12px; }
|
|
55
|
+
.resource-name small { display: block; color: #61747d; font: 10px/1.6 ui-monospace, monospace; }
|
|
56
|
+
.resource-status { color: #61747d; font-size: 10px; }
|
|
57
|
+
[data-state="ready"] > .resource-dot { border-color: #16867e; background: #16867e; }
|
|
58
|
+
[data-state="ready"] > .resource-status { color: #087c76; }
|
|
59
|
+
.integrity-note { margin: 20px 0 0; color: #61747d; font-size: 11px; }
|
|
60
|
+
.error { margin-top: 20px; padding: 16px 20px; color: #a33030; background: #fff5f4; border: 1px solid #f0d3d0; border-radius: 12px; overflow-wrap: anywhere; }
|
|
61
|
+
.error p { margin: 0; }
|
|
62
|
+
#retry { margin-top: 14px; padding: 7px 18px; color: #425c64; font: inherit; cursor: pointer; background: #fff; border: 1px solid #d5dfe2; border-radius: 6px; }
|
|
63
|
+
footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 24px 0 40px; color: #61747d; font-size: 11px; }
|
|
64
|
+
body[data-state="ready"] .status { color: #087c76; }
|
|
65
|
+
body[data-state="ready"] .status::before { animation: none; }
|
|
66
|
+
body[data-state="error"] .status, [data-state="error"] > .resource-status { color: #a33030; }
|
|
67
|
+
body[data-state="error"] .status::before, [data-state="error"] > .resource-dot { background: #c45555; border-color: #c45555; animation: none; }
|
|
68
|
+
body[data-state="error"] .loading-orbit { border-color: #e9cdca; animation: none; }
|
|
69
|
+
@keyframes orbit { to { transform: rotate(360deg); } }
|
|
70
|
+
@keyframes pulse { 50% { box-shadow: 0 0 0 6px #248b8508; } }
|
|
71
|
+
@media (max-width: 760px) { .shell { width: calc(100% - 32px); } .site-header { padding: 24px 0; } .wordmark span { display: none; } .intro { padding: 40px 0 28px; } .workspace { grid-template-columns: minmax(0, 1fr); } .runtime { padding: 20px 24px; } }
|
|
72
|
+
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }
|
|
73
|
+
</style></head>
|
|
74
|
+
<body data-state="loading"><div class="shell">
|
|
75
|
+
<header class="site-header"><div class="wordmark">Fine Design<span>PLAYGROUND</span></div><div class="status" role="status" aria-live="polite" id="runtime-status">正在加载运行时</div></header>
|
|
76
|
+
<main>
|
|
77
|
+
<section class="intro"><p class="eyebrow">DESIGN MEETS CODE</p><h1>打开浏览器,即刻开始。</h1><p>无需安装与构建,直接体验 Fine Design 的真实组件。</p></section>
|
|
78
|
+
<div class="workspace">
|
|
79
|
+
<section class="preview" aria-labelledby="preview-title"><div class="panel-header"><h2 id="preview-title">组件交互</h2><span class="panel-label">LIVE COMPONENT</span></div>
|
|
80
|
+
<div id="root" aria-busy="true"><div class="loading"><span class="loading-orbit" aria-hidden="true"></span><h3 id="loading-title">正在连接组件世界</h3><p id="loading-caption">资源就绪后,即可开始交互。</p><button id="retry" type="button" onclick="location.reload()" hidden>重新加载</button></div></div>
|
|
81
|
+
</section>
|
|
82
|
+
<aside class="runtime" aria-label="资源加载状态"><div class="runtime-heading"><h2>运行时状态</h2><span id="load-count">0 / 4</span></div><progress id="load-progress" max="4" value="0" aria-label="已加载资源"></progress>
|
|
83
|
+
<ol class="resources">${entries.map(([name, label]) => `<li id="resource-${name}" data-state="loading"><span class="resource-dot" aria-hidden="true"></span><span class="resource-name">${label}<small>${escape(resources[name].version)}</small></span><span class="resource-status">加载中</span></li>`).join('')}</ol>
|
|
84
|
+
<p class="integrity-note">版本固定 · SRI 完整性校验</p>
|
|
85
|
+
</aside>
|
|
86
|
+
</div>
|
|
87
|
+
<section class="error" id="error-panel" hidden><p id="error" role="alert" hidden></p></section>
|
|
88
|
+
</main>
|
|
89
|
+
<footer><span>Fine Design ${escape(resources.fineDesign.version)} / React ${escape(resources.react.version)}</span><span>组件通过 window.FineDesign 提供</span></footer>
|
|
90
|
+
</div>
|
|
91
|
+
<script>
|
|
92
|
+
(() => {
|
|
93
|
+
const loaded = new Set();
|
|
94
|
+
const status = document.getElementById('runtime-status');
|
|
95
|
+
function fail(message) {
|
|
96
|
+
document.body.dataset.state = 'error';
|
|
97
|
+
document.getElementById('root').setAttribute('aria-busy', 'false');
|
|
98
|
+
status.textContent = '运行时加载失败';
|
|
99
|
+
document.getElementById('loading-title').textContent = '暂时无法加载组件';
|
|
100
|
+
document.getElementById('loading-caption').textContent = '请检查网络后重试。';
|
|
101
|
+
document.getElementById('retry').hidden = false;
|
|
102
|
+
document.getElementById('error-panel').hidden = false;
|
|
103
|
+
const error = document.getElementById('error');
|
|
104
|
+
error.hidden = false;
|
|
105
|
+
error.textContent = message;
|
|
106
|
+
}
|
|
107
|
+
function mount() {
|
|
108
|
+
if (!window.React || !window.FineDesign || !window.ReactDOM || typeof ReactDOM.createRoot !== 'function') throw new Error('Missing runtime');
|
|
109
|
+
const h = React.createElement;
|
|
110
|
+
function App() {
|
|
111
|
+
const [count, setCount] = React.useState(0);
|
|
112
|
+
React.useEffect(() => {
|
|
113
|
+
document.body.dataset.state = 'ready';
|
|
114
|
+
document.getElementById('root').setAttribute('aria-busy', 'false');
|
|
115
|
+
status.textContent = '运行时已就绪';
|
|
116
|
+
}, []);
|
|
117
|
+
return h('div', { className: 'demo' },
|
|
118
|
+
h('p', null, '每一次交互,都由真实组件驱动'),
|
|
119
|
+
h('output', { className: 'demo-count', 'aria-live': 'polite' }, String(count).padStart(2, '0')),
|
|
120
|
+
h('p', null, '试着点击按钮,开始你的第一次交互。'),
|
|
121
|
+
h('div', { className: 'demo-actions' },
|
|
122
|
+
h(FineDesign.Button, { type: 'primary', onClick: () => setCount(count + 1) }, '已点击 ' + count + ' 次'),
|
|
123
|
+
h(FineDesign.Button, { type: 'normal', onClick: () => setCount(0) }, '重置')));
|
|
124
|
+
}
|
|
125
|
+
ReactDOM.createRoot(document.getElementById('root')).render(h(App));
|
|
126
|
+
}
|
|
127
|
+
window.runtimeResourceState = (name, ok, url) => {
|
|
128
|
+
const row = document.getElementById('resource-' + name);
|
|
129
|
+
row.dataset.state = ok ? 'ready' : 'error';
|
|
130
|
+
row.querySelector('.resource-status').textContent = ok ? '已就绪' : '加载失败';
|
|
131
|
+
if (!ok) {
|
|
132
|
+
(window.runtimeLoadErrors ||= []).push(url);
|
|
133
|
+
fail('资源加载失败:' + window.runtimeLoadErrors.join(','));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
loaded.add(name);
|
|
137
|
+
document.getElementById('load-count').textContent = loaded.size + ' / 4';
|
|
138
|
+
document.getElementById('load-progress').value = loaded.size;
|
|
139
|
+
if (document.body.dataset.state === 'error') return;
|
|
140
|
+
status.textContent = '正在加载运行时 · ' + loaded.size + ' / 4';
|
|
141
|
+
if (loaded.size === 4) {
|
|
142
|
+
try { mount(); } catch (error) { fail('页面启动失败:' + error.message); }
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
})();
|
|
146
|
+
</script>
|
|
147
|
+
<link rel="stylesheet" href="${escape(url(css))}" integrity="${escape(css.integrity)}" crossorigin="anonymous" ${events('fineDesignCss')}>
|
|
148
|
+
${scripts}
|
|
149
|
+
</body></html>\n`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
module.exports = { exampleHTML };
|