@punica/components-mcp 0.3.0 → 0.4.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/guide.md +22 -1
- package/dist/server.mjs +42 -4
- package/package.json +1 -1
package/dist/bundled.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"2.
|
|
1
|
+
{"version":"2.4.0"}
|
package/dist/guide.md
CHANGED
|
@@ -67,6 +67,12 @@ the same turn awaits it first: `await control.updateComplete;
|
|
|
67
67
|
form.requestSubmit()`. Reading the control's `validity`,
|
|
68
68
|
`validationMessage` or `checkValidity()` also brings it up to date at once.
|
|
69
69
|
|
|
70
|
+
An empty control holds `''` when it holds text (`punica-input`,
|
|
71
|
+
`punica-textarea`) and `null` when it holds a choice: the pickers
|
|
72
|
+
(`punica-date-picker`, `-time-picker`, `-month-picker`,
|
|
73
|
+
`-date-time-input`), `punica-select` with a placeholder, `punica-autocomplete`.
|
|
74
|
+
Test for nothing with `value == null` or `!value`, not `value === ''`.
|
|
75
|
+
|
|
70
76
|
## Overlays
|
|
71
77
|
|
|
72
78
|
Dialogs, menus, popovers and drawers open in the browser's top layer: no
|
|
@@ -91,6 +97,14 @@ Restyle inside an element with `::part(name)` and `:state(name)`; each
|
|
|
91
97
|
element lists its parts, states and its own `--punica-<element>-*`
|
|
92
98
|
properties. Right-to-left works with `dir="rtl"` on any ancestor.
|
|
93
99
|
|
|
100
|
+
Never give `display: contents` to a part that is the native control
|
|
101
|
+
(`punica-button::part(base)`, `punica-link::part(base)`,
|
|
102
|
+
`punica-side-nav-item::part(base)`, …): an element without a box takes no
|
|
103
|
+
focus, and the control leaves the Tab order with nothing on screen to show
|
|
104
|
+
it. To let a button lay out like its container, keep the box and pass the
|
|
105
|
+
layout on: `::part(base) { all: unset; display: inherit; }`. Parts that only
|
|
106
|
+
hold text, such as `label`, may take `display: contents`.
|
|
107
|
+
|
|
94
108
|
## Frameworks
|
|
95
109
|
|
|
96
110
|
- **React 19**: props that name a property are set as properties; listen
|
|
@@ -135,10 +149,17 @@ audit has to find, use a native `<h1>`. Roles of native elements inside an
|
|
|
135
149
|
element (the `button` in a `punica-button`, the `dialog` in a
|
|
136
150
|
`punica-alert-dialog`) are found as usual.
|
|
137
151
|
|
|
152
|
+
Playwright's CSS locators go into open shadow roots: `locator('input')`
|
|
153
|
+
also finds the native input inside every `punica-input`, picker and
|
|
154
|
+
`punica-checkbox`. Name the element instead (`locator('punica-input')`,
|
|
155
|
+
`locator('punica-field[label="Email"] punica-input')`), and read its value
|
|
156
|
+
with `evaluate((el) => el.value)` on that element (`inputValue()` takes only native controls).
|
|
157
|
+
|
|
138
158
|
## Check your work
|
|
139
159
|
|
|
140
160
|
`npx punica-components validate <files>` checks tags, attributes, values,
|
|
141
|
-
slots, events and icon names against this version and
|
|
161
|
+
slots, events and icon names against this version, and in CSS the
|
|
162
|
+
`::part()` rules that take an element's focus away; it exits 1 on an error.
|
|
142
163
|
`npx punica-components info <tag>` prints one element's whole API; with
|
|
143
164
|
`--brief` (in the MCP server: `get_component` with `brief: true`) it leaves
|
|
144
165
|
out CSS parts, custom properties and states. Ask for the brief form first
|
package/dist/server.mjs
CHANGED
|
@@ -346,10 +346,48 @@ function createValidator(knowledge) {
|
|
|
346
346
|
};
|
|
347
347
|
const report = (offset, severity, rule, message, fix) => findings.push({ ...where(offset), severity, rule, message, ...fix ? { fix } : {} });
|
|
348
348
|
const usesPunica = /punica-/.test(text2);
|
|
349
|
-
if (kind !== "
|
|
350
|
-
|
|
349
|
+
if (kind !== "css") {
|
|
350
|
+
if (kind !== "js") scanMarkup(text2, kind, report);
|
|
351
|
+
scanScript(text2, usesPunica, report);
|
|
352
|
+
}
|
|
353
|
+
scanStyles(text2, report);
|
|
351
354
|
return findings.sort((a, b) => a.line - b.line || a.column - b.column);
|
|
352
355
|
}
|
|
356
|
+
const FOCUS_PART = /native (?:button|anchor|input|text area|checkbox)|`button` or `a`|link or button|`<a>` or `<button>`|with the control|focusable/i;
|
|
357
|
+
const focusParts = /* @__PURE__ */ new Map();
|
|
358
|
+
for (const element of knowledge.elements.values()) {
|
|
359
|
+
for (const part of element.parts) {
|
|
360
|
+
if (!FOCUS_PART.test(part.description)) continue;
|
|
361
|
+
if (!focusParts.has(part.name)) focusParts.set(part.name, []);
|
|
362
|
+
focusParts.get(part.name).push(element.tag);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function scanStyles(text2, report) {
|
|
366
|
+
if (!text2.includes("::part(")) return;
|
|
367
|
+
const ruleRe = /([^{}]*)\{([^{}]*)\}/g;
|
|
368
|
+
let match;
|
|
369
|
+
while (match = ruleRe.exec(text2)) {
|
|
370
|
+
if (!/\bdisplay\s*:\s*contents\b/.test(match[2])) continue;
|
|
371
|
+
for (const found of match[1].matchAll(/::part\(\s*([\w-]+)\s*\)/g)) {
|
|
372
|
+
let tags = focusParts.get(found[1]);
|
|
373
|
+
if (!tags) continue;
|
|
374
|
+
const compound = match[1].slice(0, found.index).split(/[\s,>+~]/).pop();
|
|
375
|
+
const named = /^punica-[a-z0-9-]+/.exec(compound)?.[0];
|
|
376
|
+
if (named) {
|
|
377
|
+
if (!tags.includes(named)) continue;
|
|
378
|
+
tags = [named];
|
|
379
|
+
}
|
|
380
|
+
const shown = tags.length > 4 ? `${tags.slice(0, 4).map((t) => `<${t}>`).join(", ")} and ${tags.length - 4} more` : tags.map((t) => `<${t}>`).join(", ");
|
|
381
|
+
report(
|
|
382
|
+
match.index + found.index,
|
|
383
|
+
"warning",
|
|
384
|
+
"part-display-contents",
|
|
385
|
+
`\`display: contents\` on \`::part(${found[1]})\` takes the part's box away. In ${shown} that part is, or holds, the native control the element is focused through: without a box it takes no focus and leaves the Tab order. Keep a box (\`display: inherit\`, flex, grid or block).`,
|
|
386
|
+
"display: inherit"
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
353
391
|
function scanMarkup(text2, kind, report) {
|
|
354
392
|
const stack = [];
|
|
355
393
|
const tagRe = /<(\/?)([A-Za-z][\w.:-]*)/g;
|
|
@@ -718,10 +756,10 @@ ${knowledge.formatMarkdown(element.tag)}`);
|
|
|
718
756
|
"validate_markup",
|
|
719
757
|
{
|
|
720
758
|
title: "Check punica markup",
|
|
721
|
-
description: "Checks HTML, JSX, Vue or
|
|
759
|
+
description: "Checks HTML, JSX, Vue, script or CSS that uses punica elements: unknown tags and 1.x names, attributes, values, slots, events and icon names, and `::part()` rules that take an element's focus away. Returns each problem with its line and a fix.",
|
|
722
760
|
inputSchema: {
|
|
723
761
|
code: z.string().describe("The markup or script to check"),
|
|
724
|
-
kind: z.enum(["html", "jsx", "vue", "js"]).optional().describe("Guessed from the code when absent")
|
|
762
|
+
kind: z.enum(["html", "jsx", "vue", "js", "css"]).optional().describe("Guessed from the code when absent")
|
|
725
763
|
},
|
|
726
764
|
annotations: { readOnlyHint: true }
|
|
727
765
|
},
|