@punica/components-mcp 0.1.0 → 0.2.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/dist/bundled.json +1 -1
- package/dist/custom-elements.json +715 -715
- package/dist/guide.md +34 -1
- package/dist/server.mjs +18 -8
- package/package.json +1 -1
package/dist/guide.md
CHANGED
|
@@ -97,9 +97,42 @@ properties. Right-to-left works with `dir="rtl"` on any ancestor.
|
|
|
97
97
|
elements (`compilerOptions.isCustomElement`).
|
|
98
98
|
- **Angular**: `CUSTOM_ELEMENTS_SCHEMA`, `(punica-change)="…"`, `[value]="…"`.
|
|
99
99
|
|
|
100
|
+
## With the other Punica libraries
|
|
101
|
+
|
|
102
|
+
`@punica/components` is one of three libraries made to be used together:
|
|
103
|
+
Punica Form (`@punica/form`, forms and their rules) and Punica Request
|
|
104
|
+
(`@punica/request`, the HTTP client). Each has an MCP server; when the
|
|
105
|
+
project has them, look their APIs up there instead of guessing.
|
|
106
|
+
|
|
107
|
+
- **Forms**: in a project that has `@punica/form-kit`, do not wire
|
|
108
|
+
`punica-field` and its controls by hand. Describe the form as a class
|
|
109
|
+
(`@TextField`, `@SelectField`, …) and render it with `KitForm`; the kit
|
|
110
|
+
draws these elements, validates and shows the errors.
|
|
111
|
+
- **Messages and confirmations**: `toast()` and `confirm()` are what an
|
|
112
|
+
application shows a failed request and asks before a deletion with.
|
|
113
|
+
|
|
114
|
+
A whole application on the three, with its tests:
|
|
115
|
+
https://github.com/punicalab/punica-starter (start with its `AGENTS.md`).
|
|
116
|
+
|
|
117
|
+
## Testing
|
|
118
|
+
|
|
119
|
+
Elements carry their role through `ElementInternals`: a `punica-heading` is
|
|
120
|
+
a heading and a `punica-table-row` a row to a screen reader, with no `role`
|
|
121
|
+
attribute in the markup. Tools that read the markup instead of the
|
|
122
|
+
accessibility tree do not see those roles yet: Playwright's `getByRole`,
|
|
123
|
+
Testing Library's `getByRole`, and rules of axe-core such as
|
|
124
|
+
`page-has-heading-one`. In tests, find such an element by its tag
|
|
125
|
+
(`page.locator('punica-table-row')`); for the one heading of a page that an
|
|
126
|
+
audit has to find, use a native `<h1>`. Roles of native elements inside an
|
|
127
|
+
element (the `button` in a `punica-button`, the `dialog` in a
|
|
128
|
+
`punica-alert-dialog`) are found as usual.
|
|
129
|
+
|
|
100
130
|
## Check your work
|
|
101
131
|
|
|
102
132
|
`npx punica-components validate <files>` checks tags, attributes, values,
|
|
103
133
|
slots, events and icon names against this version and exits 1 on an error.
|
|
104
|
-
`npx punica-components info <tag>` prints one element's whole API
|
|
134
|
+
`npx punica-components info <tag>` prints one element's whole API; with
|
|
135
|
+
`--brief` (in the MCP server: `get_component` with `brief: true`) it leaves
|
|
136
|
+
out CSS parts, custom properties and states. Ask for the brief form first
|
|
137
|
+
and for the whole one only when you style the inside of an element.
|
|
105
138
|
Documentation with live examples: https://components.punicalab.com
|
package/dist/server.mjs
CHANGED
|
@@ -255,7 +255,7 @@ function createKnowledge(manifest2) {
|
|
|
255
255
|
}
|
|
256
256
|
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
257
257
|
}
|
|
258
|
-
function formatMarkdown(tag) {
|
|
258
|
+
function formatMarkdown(tag, { brief = false } = {}) {
|
|
259
259
|
const e = get(tag);
|
|
260
260
|
if (!e) {
|
|
261
261
|
const old = legacy(normalizeTag(tag));
|
|
@@ -268,15 +268,22 @@ function createKnowledge(manifest2) {
|
|
|
268
268
|
if (!rows.length) return;
|
|
269
269
|
lines.push("", `### ${title}`, "", `| ${head.join(" | ")} |`, `|${head.map(() => "---").join("|")}|`, ...rows.map((r) => `| ${r.map(cell).join(" | ")} |`));
|
|
270
270
|
};
|
|
271
|
-
table("Attributes", ["Attribute", "
|
|
271
|
+
if (brief) table("Attributes", ["Attribute", "Type", "Description"], e.attributes.map((a) => [`\`${a.name}\``, `\`${a.type}\``, a.description]));
|
|
272
|
+
else table("Attributes", ["Attribute", "Property", "Type", "Description"], e.attributes.map((a) => [`\`${a.name}\``, `\`${a.property}\``, `\`${a.type}\``, a.description]));
|
|
272
273
|
table("Properties (no attribute)", ["Property", "Type", "Description"], e.properties.map((p) => [`\`${p.name}\``, p.type ? `\`${p.type}\`` : "", (p.readonly ? "Read-only. " : "") + p.description]));
|
|
273
274
|
table("Methods", ["Method", "Description"], e.methods.map((m) => [`\`${m.signature}\``, m.description]));
|
|
274
275
|
table("Events", ["Event", "Description"], e.events.map((ev) => [`\`${ev.name}\``, ev.description]));
|
|
275
276
|
table("Slots", ["Slot", "Description"], e.slots.map((s) => [s.name ? `\`${s.name}\`` : "(default)", s.description]));
|
|
276
|
-
|
|
277
|
-
|
|
277
|
+
if (!brief) {
|
|
278
|
+
table("CSS parts", ["Part", "Description"], e.parts.map((p) => [`\`${p.name}\``, p.description]));
|
|
279
|
+
table("CSS custom properties", ["Property", "Description"], e.cssProperties.map((p) => [`\`${p.name}\``, p.description]));
|
|
280
|
+
}
|
|
278
281
|
if (e.tag === "punica-icon") lines.push("", `### Icon names`, "", icons2.map((i) => `\`${i}\``).join(", ") + ". Any other name draws nothing: slot an `<svg>` instead.");
|
|
279
|
-
table("Custom states", ["State", "Description"], e.states.map((s) => [`\`:state(${s.name})\``, s.description]));
|
|
282
|
+
if (!brief) table("Custom states", ["State", "Description"], e.states.map((s) => [`\`:state(${s.name})\``, s.description]));
|
|
283
|
+
else if (e.parts.length || e.cssProperties.length || e.states.length) {
|
|
284
|
+
const left = [e.parts.length && `${e.parts.length} CSS parts`, e.cssProperties.length && `${e.cssProperties.length} custom properties`, e.states.length && `${e.states.length} states`].filter(Boolean);
|
|
285
|
+
lines.push("", `For styling: ${left.join(", ")}; ask for the whole API to see them.`);
|
|
286
|
+
}
|
|
280
287
|
return lines.join("\n");
|
|
281
288
|
}
|
|
282
289
|
return { elements, tags, allEvents, icons: icons2, list, get, search, legacy, formatMarkdown };
|
|
@@ -674,11 +681,14 @@ function createPunicaServer({ manifest: manifest2, guide: guide2, version: versi
|
|
|
674
681
|
"get_component",
|
|
675
682
|
{
|
|
676
683
|
title: "An element's API",
|
|
677
|
-
description: "The
|
|
678
|
-
inputSchema: {
|
|
684
|
+
description: "The API of one or more punica elements: attributes with their exact values, properties, methods, events, slots, CSS parts, custom properties and states. Pass brief: true when you write markup and do not style the inside of the element: it leaves out the parts, custom properties and states and is about a quarter shorter.",
|
|
685
|
+
inputSchema: {
|
|
686
|
+
tags: z.array(z.string()).min(1).max(12).describe("Tags such as punica-select, or bare names such as select"),
|
|
687
|
+
brief: z.boolean().optional().describe("Leave out CSS parts, custom properties and states")
|
|
688
|
+
},
|
|
679
689
|
annotations: { readOnlyHint: true }
|
|
680
690
|
},
|
|
681
|
-
async ({ tags }) => text(tags.map((tag) => knowledge.formatMarkdown(tag)).join("\n\n"))
|
|
691
|
+
async ({ tags, brief }) => text(tags.map((tag) => knowledge.formatMarkdown(tag, { brief })).join("\n\n"))
|
|
682
692
|
);
|
|
683
693
|
server2.registerTool(
|
|
684
694
|
"get_examples",
|