@punica/components-mcp 0.2.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/custom-elements.json +1693 -702
- package/dist/guide.md +31 -2
- package/dist/server.mjs +42 -4
- package/package.json +1 -1
package/dist/guide.md
CHANGED
|
@@ -61,6 +61,18 @@ for a label, help text and an error message:
|
|
|
61
61
|
</form>
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
+
A value set from script (`control.value = 'x'`) reaches the form at the end
|
|
65
|
+
of the current microtask, as every property does. A script that submits in
|
|
66
|
+
the same turn awaits it first: `await control.updateComplete;
|
|
67
|
+
form.requestSubmit()`. Reading the control's `validity`,
|
|
68
|
+
`validationMessage` or `checkValidity()` also brings it up to date at once.
|
|
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
|
+
|
|
64
76
|
## Overlays
|
|
65
77
|
|
|
66
78
|
Dialogs, menus, popovers and drawers open in the browser's top layer: no
|
|
@@ -85,6 +97,14 @@ Restyle inside an element with `::part(name)` and `:state(name)`; each
|
|
|
85
97
|
element lists its parts, states and its own `--punica-<element>-*`
|
|
86
98
|
properties. Right-to-left works with `dir="rtl"` on any ancestor.
|
|
87
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
|
+
|
|
88
108
|
## Frameworks
|
|
89
109
|
|
|
90
110
|
- **React 19**: props that name a property are set as properties; listen
|
|
@@ -107,7 +127,9 @@ project has them, look their APIs up there instead of guessing.
|
|
|
107
127
|
- **Forms**: in a project that has `@punica/form-kit`, do not wire
|
|
108
128
|
`punica-field` and its controls by hand. Describe the form as a class
|
|
109
129
|
(`@TextField`, `@SelectField`, …) and render it with `KitForm`; the kit
|
|
110
|
-
draws these elements, validates and shows the errors.
|
|
130
|
+
draws these elements, validates and shows the errors. A form whose markup
|
|
131
|
+
is your own (no React) is bound to the engine with `bindForm` of
|
|
132
|
+
`@punica/form-kit/dom` (from form-kit 0.5).
|
|
111
133
|
- **Messages and confirmations**: `toast()` and `confirm()` are what an
|
|
112
134
|
application shows a failed request and asks before a deletion with.
|
|
113
135
|
|
|
@@ -127,10 +149,17 @@ audit has to find, use a native `<h1>`. Roles of native elements inside an
|
|
|
127
149
|
element (the `button` in a `punica-button`, the `dialog` in a
|
|
128
150
|
`punica-alert-dialog`) are found as usual.
|
|
129
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
|
+
|
|
130
158
|
## Check your work
|
|
131
159
|
|
|
132
160
|
`npx punica-components validate <files>` checks tags, attributes, values,
|
|
133
|
-
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.
|
|
134
163
|
`npx punica-components info <tag>` prints one element's whole API; with
|
|
135
164
|
`--brief` (in the MCP server: `get_component` with `brief: true`) it leaves
|
|
136
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
|
},
|