@temmo/cli 0.0.0-stage → 0.19.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/.claude-plugin/marketplace.json +14 -0
- package/.claude-plugin/plugin.json +16 -0
- package/.codex-plugin/plugin.json +30 -0
- package/.cursor-plugin/plugin.json +22 -0
- package/.mcp.json +18 -0
- package/LICENSE +202 -0
- package/README.md +82 -2
- package/THIRD_PARTY_NOTICES +32 -0
- package/commands/afk.md +17 -0
- package/deploy/build-ui.mjs +65 -0
- package/deploy/claude/README.md +16 -0
- package/deploy/claude/auto-mode.json +31 -0
- package/deploy/postgres/compose.yaml +26 -0
- package/deploy/temmo-runner.service +24 -0
- package/deploy/verify-ui.mjs +15 -0
- package/harness-core/README.md +27 -0
- package/harness-core/bin/harness.mjs +17 -0
- package/harness-core/package.json +10 -0
- package/harness-core/stage.mjs +108 -0
- package/harness-core/stages/commit.md +7 -0
- package/harness-core/stages/pr.md +7 -0
- package/harness-core/stages/push.md +7 -0
- package/hooks/codex-hooks.json +14 -0
- package/hooks/cursor-hooks.json +17 -0
- package/hooks/hooks.json +27 -0
- package/lib/acp/permission.js +72 -0
- package/lib/acp/sessionConfig.js +109 -0
- package/lib/activity.js +244 -0
- package/lib/agent-guard.js +72 -0
- package/lib/agents-route.js +55 -0
- package/lib/agents.js +213 -0
- package/lib/agui.js +255 -0
- package/lib/alerts.js +36 -0
- package/lib/analyze-otlp.js +46 -0
- package/lib/analyze-run-code.js +397 -0
- package/lib/analyze-sources.js +372 -0
- package/lib/approval-card.js +54 -0
- package/lib/approval-cli.js +53 -0
- package/lib/approval-request.js +81 -0
- package/lib/approval-signer.js +48 -0
- package/lib/approvals.js +295 -0
- package/lib/attachment-cache.js +236 -0
- package/lib/attachment.js +63 -0
- package/lib/blocked.js +20 -0
- package/lib/build-review.js +90 -0
- package/lib/builder/cli.js +90 -0
- package/lib/builder/policy.js +176 -0
- package/lib/builder/recover.js +189 -0
- package/lib/builder/run.js +240 -0
- package/lib/builder/settle.js +198 -0
- package/lib/builder/stage.js +240 -0
- package/lib/builder/state.js +73 -0
- package/lib/builder/supervisor.js +289 -0
- package/lib/builder-clean.js +223 -0
- package/lib/builder-code.cjs +67 -0
- package/lib/builder.js +9 -0
- package/lib/bus-postgres.js +281 -0
- package/lib/bus.js +349 -0
- package/lib/catalog/author.js +278 -0
- package/lib/catalog/dot.js +426 -0
- package/lib/catalog/pattern-model.js +193 -0
- package/lib/catalog/patterns.js +324 -0
- package/lib/catalog/projects.js +83 -0
- package/lib/catalog/records.js +2 -0
- package/lib/catalog/roster.js +70 -0
- package/lib/catalog/team-files.js +49 -0
- package/lib/catalog/teams.js +109 -0
- package/lib/claude-socket.js +333 -0
- package/lib/cli.js +741 -0
- package/lib/code-mode.js +45 -0
- package/lib/code-read-policy.yaml +9 -0
- package/lib/code-run.js +461 -0
- package/lib/codex-compact.js +141 -0
- package/lib/compaction.js +21 -0
- package/lib/config.js +424 -0
- package/lib/cursor-trace.js +248 -0
- package/lib/deep-link.js +20 -0
- package/lib/deliver-push.js +120 -0
- package/lib/delivery.js +28 -0
- package/lib/deploy-tree.js +227 -0
- package/lib/durable.js +404 -0
- package/lib/factory-tick.js +32 -0
- package/lib/family.js +63 -0
- package/lib/fetch-origin.js +53 -0
- package/lib/format.js +133 -0
- package/lib/harness-surface-cli.js +153 -0
- package/lib/harness-surface.js +486 -0
- package/lib/harness.js +271 -0
- package/lib/hook.mjs +291 -0
- package/lib/idle.js +40 -0
- package/lib/install-cursor.js +115 -0
- package/lib/install-opencode.js +105 -0
- package/lib/job.js +82 -0
- package/lib/land-cli.js +319 -0
- package/lib/land-member.js +64 -0
- package/lib/land.js +320 -0
- package/lib/lessons.js +223 -0
- package/lib/limit-alert.js +423 -0
- package/lib/limits.js +284 -0
- package/lib/machine-prompt.js +19 -0
- package/lib/merge-sweep.js +149 -0
- package/lib/messaging.js +1002 -0
- package/lib/mission-cli.js +103 -0
- package/lib/mission.js +241 -0
- package/lib/mode.js +215 -0
- package/lib/models.js +114 -0
- package/lib/names.js +86 -0
- package/lib/opencode-api.js +57 -0
- package/lib/opencode-plugin.mjs +313 -0
- package/lib/operator-token.js +78 -0
- package/lib/operator.js +187 -0
- package/lib/pad-activity.js +143 -0
- package/lib/pad-fresh.js +44 -0
- package/lib/pad.js +198 -0
- package/lib/pattern-cli.js +120 -0
- package/lib/pattern-compiler.js +68 -0
- package/lib/pattern-runs.js +795 -0
- package/lib/pattern-stall.js +58 -0
- package/lib/pattern-tick.js +45 -0
- package/lib/pattern-workflow.js +69 -0
- package/lib/pi-extension.mjs +98 -0
- package/lib/pi.js +57 -0
- package/lib/plugin-copy.js +76 -0
- package/lib/pm-review.js +32 -0
- package/lib/pm-workspace.js +87 -0
- package/lib/postgres.js +115 -0
- package/lib/pr-card.js +34 -0
- package/lib/probe.js +295 -0
- package/lib/process.js +67 -0
- package/lib/project-pause.js +23 -0
- package/lib/prune.js +793 -0
- package/lib/questions.js +250 -0
- package/lib/receipts.js +63 -0
- package/lib/reflect.js +962 -0
- package/lib/rename-migration.js +118 -0
- package/lib/run-terminal.js +437 -0
- package/lib/runner-request.js +33 -0
- package/lib/sandbox-app.js +120 -0
- package/lib/sandbox-claims.js +258 -0
- package/lib/sandbox-cli.js +188 -0
- package/lib/sandbox-hosts-cli.js +68 -0
- package/lib/sandbox-hosts.js +94 -0
- package/lib/sandbox-pr.js +102 -0
- package/lib/sandbox-proposal.js +367 -0
- package/lib/sandbox-tools.js +143 -0
- package/lib/sandbox.js +501 -0
- package/lib/schedule-session.js +68 -0
- package/lib/session-activity.js +67 -0
- package/lib/session-events.js +94 -0
- package/lib/sessions/control.js +244 -0
- package/lib/sessions/git-refs.js +265 -0
- package/lib/sessions/launch.js +359 -0
- package/lib/sessions/registry.js +450 -0
- package/lib/sessions/scope.js +111 -0
- package/lib/setup.js +377 -0
- package/lib/signed-approval.js +225 -0
- package/lib/slash.js +167 -0
- package/lib/spawn-cli.js +45 -0
- package/lib/spawn.js +107 -0
- package/lib/start-limit.js +58 -0
- package/lib/state.js +24 -0
- package/lib/stop.js +308 -0
- package/lib/store-read.js +62 -0
- package/lib/store.js +252 -0
- package/lib/subagent-guard.js +240 -0
- package/lib/surfaces/channel-post.js +43 -0
- package/lib/surfaces/instructions.js +15 -0
- package/lib/surfaces/mcp-reload.js +144 -0
- package/lib/surfaces/ops.js +629 -0
- package/lib/surfaces/render-mcp.js +33 -0
- package/lib/surfaces/run-terminal-ops.js +40 -0
- package/lib/surfaces/sandbox-ops.js +36 -0
- package/lib/surfaces/schema.js +7 -0
- package/lib/surfaces/task-view.js +90 -0
- package/lib/surfaces/types.js +4 -0
- package/lib/task-cli.js +274 -0
- package/lib/task-order.js +34 -0
- package/lib/task-order.mjs +2 -0
- package/lib/task-route.js +125 -0
- package/lib/tasks.js +631 -0
- package/lib/team-permission.js +34 -0
- package/lib/team-templates/blitz/team.dot +9 -0
- package/lib/team-templates/factory/team.dot +26 -0
- package/lib/team-templates/feature/team.dot +14 -0
- package/lib/team-templates/fix-and-review/team.dot +12 -0
- package/lib/team-templates/product/team.dot +16 -0
- package/lib/team-templates/release/team.dot +7 -0
- package/lib/team-templates/review/team.dot +6 -0
- package/lib/terminal-draft.js +42 -0
- package/lib/thread-branch.js +82 -0
- package/lib/thread-channel-store.js +181 -0
- package/lib/thread-channels.js +116 -0
- package/lib/thread-listening.js +20 -0
- package/lib/thread-routes.js +91 -0
- package/lib/threads.js +441 -0
- package/lib/tool-api.js +33 -0
- package/lib/transcript.js +98 -0
- package/lib/ui-build-output.js +19 -0
- package/lib/ui-capabilities.js +90 -0
- package/lib/usage.js +182 -0
- package/lib/vendor/mcp-sdk.d.mts +4 -0
- package/lib/vendor/mcp-sdk.mjs +17046 -0
- package/lib/waiter.js +127 -0
- package/lib/workflows.js +546 -0
- package/lib/worktree-setup.js +86 -0
- package/package.json +110 -4
- package/runner/adapters/claude.js +465 -0
- package/runner/adapters/cli-sandbox.js +277 -0
- package/runner/adapters/codex.js +675 -0
- package/runner/adapters/cursor.mjs +937 -0
- package/runner/adapters/fake.js +119 -0
- package/runner/adapters/opencode-sandbox.js +370 -0
- package/runner/adapters/opencode.js +486 -0
- package/runner/adapters/pi-sandbox.js +134 -0
- package/runner/adapters/pi.js +364 -0
- package/runner/client.js +40 -0
- package/runner/contract.js +129 -0
- package/runner/control.js +178 -0
- package/runner/delivery.js +184 -0
- package/runner/factory-tick.mjs +10 -0
- package/runner/lock.js +41 -0
- package/runner/main.mjs +118 -0
- package/runner/pattern-tick.mjs +16 -0
- package/runner/publish.js +113 -0
- package/runner/runner.js +2612 -0
- package/runner/sandbox-run.mjs +239 -0
- package/runner/schedules.js +294 -0
- package/runner/task-wake.js +59 -0
- package/scripts/ai-collab +3 -0
- package/scripts/ai-collab-bus.mjs +4 -0
- package/scripts/ai-collab-code-mcp.mjs +3 -0
- package/scripts/ai-collab-hook +3 -0
- package/scripts/ai-collab-hook.mjs +3 -0
- package/scripts/ai-collab-mcp-tools.mjs +2 -0
- package/scripts/ai-collab-mcp.mjs +3 -0
- package/scripts/ai-collab.mjs +3 -0
- package/scripts/install-cursor.mjs +11 -0
- package/scripts/install-opencode.mjs +10 -0
- package/scripts/temmo +3 -0
- package/scripts/temmo-bus.mjs +151 -0
- package/scripts/temmo-code-mcp.mjs +63 -0
- package/scripts/temmo-hook +3 -0
- package/scripts/temmo-hook.mjs +201 -0
- package/scripts/temmo-mcp-tools.mjs +22 -0
- package/scripts/temmo-mcp.mjs +27 -0
- package/scripts/temmo.mjs +4 -0
- package/skills/antislop/SKILL.md +701 -0
- package/skills/antislop/VERSION +1 -0
- package/skills/antislop-code/SKILL.md +128 -0
- package/skills/antislop-human/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-human/SKILL.md +204 -0
- package/skills/antislop-human/contrast-check.py +168 -0
- package/skills/antislop-human/contrast-mcp.py +125 -0
- package/skills/antislop-human/references/A11Y-PATTERNS.md +249 -0
- package/skills/antislop-human/references/WCAG.md +127 -0
- package/skills/antislop-layoutmobile/SKILL.md +170 -0
- package/skills/antislop-ui/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-ui/SKILL.md +351 -0
- package/skills/antislop-ui/references/CORE-WEB-VITALS.md +181 -0
- package/skills/antislop-ui/references/WEB-BASELINE.md +28 -0
- package/skills/harness-surface/SKILL.md +42 -0
- package/skills/land/SKILL.md +32 -0
- package/skills/memory-file/SKILL.md +39 -0
- package/skills/temmo/SKILL.md +101 -0
- package/skills/temmo/references/role-programs.md +47 -0
- package/skills/ui-sdk/SKILL.md +56 -0
- package/skills/ui-sdk/references/agent-ready.md +136 -0
- package/skills/ui-sdk/references/build-interface.md +187 -0
- package/skills/ui-sdk/references/create-component.md +88 -0
- package/skills/ui-sdk/references/patterns.md +246 -0
- package/skills/ui-sdk/references/styles.md +66 -0
- package/skills/ui-sdk/references/testing.md +172 -0
- package/skills/ui-sdk/references/web-components.md +78 -0
- package/tools/screen-state.mjs +119 -0
- package/tools/smoke-ui.mjs +540 -0
- package/web/app/activity.jsx +251 -0
- package/web/app/agent-mark.tsx +43 -0
- package/web/app/alert-level.jsx +16 -0
- package/web/app/api/[action]/route.js +8 -0
- package/web/app/api/auth/[step]/route.js +12 -0
- package/web/app/api/events/route.js +8 -0
- package/web/app/api/file/[name]/route.js +8 -0
- package/web/app/api/land/route.js +12 -0
- package/web/app/api/lessons/route.js +8 -0
- package/web/app/api/push/key/route.js +8 -0
- package/web/app/api/push/subscribe/route.js +12 -0
- package/web/app/api/push/test/route.js +8 -0
- package/web/app/api/refs/route.js +8 -0
- package/web/app/api/review-diff/route.js +8 -0
- package/web/app/api/schedules/route.js +8 -0
- package/web/app/api/thread-diff/route.js +8 -0
- package/web/app/api/version/route.js +6 -0
- package/web/app/cards.jsx +189 -0
- package/web/app/chat-api.js +82 -0
- package/web/app/chat-composer.jsx +313 -0
- package/web/app/chat-console.jsx +691 -0
- package/web/app/chat-image.tsx +61 -0
- package/web/app/chat-message.jsx +122 -0
- package/web/app/chat-shared.jsx +59 -0
- package/web/app/chat-sidebar.jsx +25 -0
- package/web/app/chat-stream.js +127 -0
- package/web/app/chat.jsx +31 -0
- package/web/app/compactions.jsx +57 -0
- package/web/app/composer-actions.tsx +87 -0
- package/web/app/decisions.jsx +53 -0
- package/web/app/fonts/OFL-hanken-grotesk.txt +93 -0
- package/web/app/fonts/OFL-ibm-plex-mono.txt +93 -0
- package/web/app/fonts/hanken-grotesk-latin-wght-normal.woff2 +0 -0
- package/web/app/fonts/ibm-plex-mono-latin-400-normal.woff2 +0 -0
- package/web/app/fonts/ibm-plex-mono-latin-500-normal.woff2 +0 -0
- package/web/app/globals.css +199 -0
- package/web/app/home.jsx +246 -0
- package/web/app/icon.svg +1 -0
- package/web/app/land-panel.jsx +63 -0
- package/web/app/land-reviews.jsx +20 -0
- package/web/app/layout.jsx +17 -0
- package/web/app/lessons.tsx +76 -0
- package/web/app/logo.tsx +13 -0
- package/web/app/logos.jsx +16 -0
- package/web/app/manifest.js +8 -0
- package/web/app/mode-menu.tsx +46 -0
- package/web/app/new-session.jsx +275 -0
- package/web/app/notify.jsx +180 -0
- package/web/app/outcomes.tsx +94 -0
- package/web/app/page.jsx +9 -0
- package/web/app/pattern-graph.jsx +75 -0
- package/web/app/patterns-page.jsx +293 -0
- package/web/app/phone-nav.tsx +36 -0
- package/web/app/progress-feed.tsx +33 -0
- package/web/app/providers.tsx +27 -0
- package/web/app/quote.jsx +15 -0
- package/web/app/run-card.tsx +200 -0
- package/web/app/run-requests.tsx +148 -0
- package/web/app/scheduled.jsx +105 -0
- package/web/app/session-panel.tsx +174 -0
- package/web/app/session-toolbar.tsx +180 -0
- package/web/app/shadcn.css +638 -0
- package/web/app/shipped.jsx +49 -0
- package/web/app/subagent-runs.jsx +31 -0
- package/web/app/task-graph.jsx +67 -0
- package/web/app/tasks-strip.tsx +36 -0
- package/web/app/tasks.jsx +375 -0
- package/web/app/team-author.jsx +145 -0
- package/web/app/team-editor.jsx +88 -0
- package/web/app/thread-agents.tsx +32 -0
- package/web/app/thread-place.tsx +9 -0
- package/web/app/thread-sessions.tsx +149 -0
- package/web/app/thread-sidebar.tsx +418 -0
- package/web/app/thread-switcher.tsx +27 -0
- package/web/app/tool-diff.jsx +94 -0
- package/web/components/a2ui/controls.jsx +36 -0
- package/web/components/a2ui/option-picker.jsx +23 -0
- package/web/components/a2ui/script.tsx +121 -0
- package/web/components/a2ui/surface.jsx +81 -0
- package/web/components/chat/thread.jsx +50 -0
- package/web/components/script-text.tsx +42 -0
- package/web/components/ui/avatar.jsx +115 -0
- package/web/components/ui/badge.jsx +47 -0
- package/web/components/ui/button.jsx +63 -0
- package/web/components/ui/chat-container.jsx +52 -0
- package/web/components/ui/choice-list.tsx +72 -0
- package/web/components/ui/code-block.jsx +60 -0
- package/web/components/ui/copy-button.tsx +41 -0
- package/web/components/ui/dropdown-menu.jsx +257 -0
- package/web/components/ui/markdown.jsx +84 -0
- package/web/components/ui/message.jsx +28 -0
- package/web/components/ui/popover.jsx +33 -0
- package/web/components/ui/scroll-button.jsx +34 -0
- package/web/components/ui/select.jsx +189 -0
- package/web/components/ui/sheet.jsx +152 -0
- package/web/components/ui/sonner.jsx +10 -0
- package/web/components/ui/tabs.jsx +88 -0
- package/web/components/ui/textarea.jsx +20 -0
- package/web/components/ui/tooltip.jsx +56 -0
- package/web/components.json +24 -0
- package/web/instrumentation.js +8 -0
- package/web/lib/a2ui-catalog.js +34 -0
- package/web/lib/a2ui-pr.js +76 -0
- package/web/lib/a2ui-run-catalog.js +18 -0
- package/web/lib/a2ui-run.js +93 -0
- package/web/lib/a2ui.js +262 -0
- package/web/lib/activity-rows.js +275 -0
- package/web/lib/agent-detail.js +5 -0
- package/web/lib/alert-level.js +44 -0
- package/web/lib/approval-mode.js +22 -0
- package/web/lib/chat-turns.js +174 -0
- package/web/lib/child-subagents.js +16 -0
- package/web/lib/compaction-view.js +48 -0
- package/web/lib/composer-actions.js +40 -0
- package/web/lib/context-view.js +57 -0
- package/web/lib/fuzzy.js +26 -0
- package/web/lib/highlight.js +44 -0
- package/web/lib/lessons-view.js +23 -0
- package/web/lib/mentions.js +16 -0
- package/web/lib/message-routing.js +105 -0
- package/web/lib/new-session.js +85 -0
- package/web/lib/operator-messages.js +28 -0
- package/web/lib/pattern-graph.js +165 -0
- package/web/lib/pattern-view.js +33 -0
- package/web/lib/pending-summary.js +18 -0
- package/web/lib/permission-modes.js +30 -0
- package/web/lib/project-feed.js +107 -0
- package/web/lib/quote.js +7 -0
- package/web/lib/reply-quote.js +31 -0
- package/web/lib/scheduled.js +79 -0
- package/web/lib/selection.js +110 -0
- package/web/lib/send-confirmation.js +22 -0
- package/web/lib/session-dead.js +10 -0
- package/web/lib/session-state.js +132 -0
- package/web/lib/sidebar.js +15 -0
- package/web/lib/slash-commands.js +164 -0
- package/web/lib/start-default.js +35 -0
- package/web/lib/start-mode.js +35 -0
- package/web/lib/stream-views.js +49 -0
- package/web/lib/subagent-state.js +20 -0
- package/web/lib/task-board.js +54 -0
- package/web/lib/task-graph.js +183 -0
- package/web/lib/task-tags.js +41 -0
- package/web/lib/team-editor.js +10 -0
- package/web/lib/thread-groups.js +86 -0
- package/web/lib/threads.js +28 -0
- package/web/lib/tool-diff.js +273 -0
- package/web/lib/ui-events.js +58 -0
- package/web/lib/utils.js +5 -0
- package/web/lib/view-memory.js +25 -0
- package/web/next.config.mjs +37 -0
- package/web/postcss.config.mjs +1 -0
- package/web/proxy.js +25 -0
- package/web/public/sw.js +39 -0
- package/web/server/auth.js +178 -0
- package/web/server/dispatch.js +293 -0
- package/web/server/history.js +56 -0
- package/web/server/hosted.js +58 -0
- package/web/server/hub.js +126 -0
- package/web/server/instance.js +5 -0
- package/web/server/land-reviews.js +64 -0
- package/web/server/push.js +148 -0
- package/web/server/run-terminal.js +79 -0
- package/web/server/schedules.js +38 -0
- package/web/server/shipped.js +51 -0
- package/web/server/task-board.js +71 -0
- package/web/server/threads.js +209 -0
- package/web/server/ui.js +2937 -0
- package/web/tsconfig.base.json +16 -0
- package/web/tsconfig.json +9 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Build a component from @ui-sdk/core
|
|
2
|
+
|
|
3
|
+
ui-sdk ships its behavior layer as public API. A component it doesn't have is one primitive, written once with `definePrimitive`, and one small file per framework that renders it. It gets the same keyboard handling, focus, server rendering and right to left layout as ui-sdk's own components.
|
|
4
|
+
|
|
5
|
+
## Read first
|
|
6
|
+
|
|
7
|
+
1. **The Core docs.** Every package ships them in `docs/`: `docs/core.md` is the whole Core section in one file, the same in every package, since no framework changes it. Each framework's package adds `docs/rendering.md`, how its adapter renders a primitive, and `docs/components/<name>.md` and `docs/utilities/<name>.md` (React's are `docs/hooks/<name>.md`) for the rest. Read `docs/core.md` and `docs/rendering.md` from the package of the framework you render in, like `node_modules/@ui-sdk/react/docs/`. In `core.md`, read the overview, "Build a Component" (a mute button), "Compose Behaviors" (a star rating, the template to copy), "Popups and Layers" under Behaviors if anything opens, and the Behaviors page for each one you use. Search it by heading rather than reading it top to bottom. For another framework, see [Other frameworks](#other-frameworks).
|
|
8
|
+
2. **The types.** Every export has JSDoc in `node_modules/@ui-sdk/core/dist/**/*.d.ts` and in each framework's `.d.ts`. A component entry's types point into its folder, like `dist/components/input/input.d.ts`. Read them there. Those JSDoc blocks document the library; your primitive gets none.
|
|
9
|
+
3. **What ui-sdk already has.** List the entries in `node_modules/@ui-sdk/<framework>/package.json`. If one covers part of what you're building, compose it (see [Compose ours](#compose-ours)) rather than rewriting its behavior. If the user named the blocks to use, build from those blocks.
|
|
10
|
+
|
|
11
|
+
Don't read compiled JavaScript in `dist/*.js`. When the docs and types don't say how something of ours behaves, probe it instead (below), and mention the missing docs in your report.
|
|
12
|
+
|
|
13
|
+
### Probe what the docs don't say
|
|
14
|
+
|
|
15
|
+
Write a throwaway test that renders our component in jsdom, fires events, and logs the DOM and the callbacks' arguments. Run it with `--silent=false` to see the logs, then delete it. This is how to learn, for example, whether a part hides when it's empty, which reason a change reports, where focus goes, or which tag names a web components entry defines. Two things every probe needs:
|
|
16
|
+
|
|
17
|
+
- **Wait a tick after mounting.** Some state, like an input group's `filled`, arrives after mount: `await act(() => new Promise((r) => setTimeout(r, 0)))`.
|
|
18
|
+
- **Stub what jsdom lacks before anything opens:** see [testing.md](testing.md#jsdom).
|
|
19
|
+
|
|
20
|
+
## Steps
|
|
21
|
+
|
|
22
|
+
### 1. Write the spec before any code
|
|
23
|
+
|
|
24
|
+
Pick the WAI-ARIA pattern from the Authoring Practices (https://www.w3.org/WAI/ARIA/apg/patterns/) and write down its roles, states and keys. Then decide each of these in writing, since they're where components go wrong:
|
|
25
|
+
|
|
26
|
+
- **Focus on open and on Tab.** Where does focus land when the component opens or is tabbed into? Is the group one tab stop?
|
|
27
|
+
- **Selection and focus.** Does selection follow focus (radio group, single-select listbox), or do arrows only move focus and Space selects (multi-select listbox, data grid)?
|
|
28
|
+
- **Escape.** Who owns it? Inside a popup, the popup closes on it. A field that clears on Escape should only claim it when there's something to clear.
|
|
29
|
+
- **Parts that leave.** When the focused part is removed or moves out, where does focus go? Use `createFocusRecovery`.
|
|
30
|
+
- **Pick the pattern.** [patterns.md](patterns.md) has the roles for common shapes: a set of choices in two dimensions is a `grid`, a stepper is buttons with `aria-current="step"`.
|
|
31
|
+
- **Declare it on the slots.** Each part's role goes on its slot (`role: "option"`), never in `attrs`. TypeScript then requires what the role needs: `focus` for roles that take it, `press` for roles that activate, `keys` with an `on.keydown` for roles that move with keys, or `{ none: "why" }` when another element does it. Its `attrs` returns the role's required states, like `aria-checked`, and only the ARIA the role takes. Don't cast past these errors; set `globalThis.__UI_SDK_STRICT__ = true` in tests so development warnings fail them (declare it first: `declare global { var __UI_SDK_STRICT__: boolean | undefined }`).
|
|
32
|
+
- **Controls that stop applying.** A button that can't act right now should be `aria-disabled`, not `disabled`, if it may hold focus at the time. `disabled` drops focus to the page.
|
|
33
|
+
- **Keys with no APG rule.** Like Enter to move items between lists. Pick one, and say which in your report.
|
|
34
|
+
- **What an agent may call.** Which api methods are actions a person takes, like `rate` or `moveToTarget`? They go in `agent.actions` (step 2).
|
|
35
|
+
|
|
36
|
+
### 2. Write the primitive in `<name>.ts`
|
|
37
|
+
|
|
38
|
+
- **Options:** controlled keys as `<key>`, `default<Key>` and `on<Key>Change(value, details: ChangeDetails<Reason>)`.
|
|
39
|
+
- **Schema:** `options` names every option with its kind, and each slot's `props` every prop: `"string"`, `"number"`, `"boolean"`, `"list"`, `"value"` (any other value), `"callback"`, `"action"` (a callback whose return value counts, like a Promise), `"id"` (made when left out), `"key"` (a list item's value of any type, which keys the part and reaches nested parts as that key), or `{ kind, from: "item" }` for a prop a nested part takes from its parent, with `required: true` when it must sit inside it. Renderers read it to tell the primitive's props from the element's. TypeScript checks it names every key.
|
|
40
|
+
- **State:** `state` reads the default. `sync` maps controlled options onto state, or they're silently ignored. Copy any option a part renders into state.
|
|
41
|
+
- **Changes:** `api` builds `change` with `createChange(context)` and returns the api. Every change a user sees goes through `change` with a reason. Internal state, like a selection that starts over, can use `store.set`.
|
|
42
|
+
- **Reasons:** use the shared vocabulary (`ReasonVocabulary` in `@ui-sdk/core`) when one fits. When none does, like "select all" or "move to the other list", declare your own in the `on<Key>Change` type.
|
|
43
|
+
- **Slots:** `attrs` for ARIA and `data-*` (pure, server safe), `press` for activation, `on` for other events, `bind` for anything that touches the DOM (return a cleanup).
|
|
44
|
+
- **`press` hears only clicks on parts that aren't buttons.** For a `div` or `td` part, handle Space and Enter in `on.keydown`.
|
|
45
|
+
- **Every element gets its `data-slot` from a slot.** The adapter never sets one directly. Wrappers, like a row of buttons, get a slot of their own.
|
|
46
|
+
- **Agents:** end the definition with `agent: { actions: [...] }`, the api methods an agent may call. Keep it after `slots`. Give the root a name, with `aria-label` or a label part: the bridge names the component after it. [agent-ready.md](agent-ready.md) covers `closed`, `items`, `reveals`, `shown` and `secret`.
|
|
47
|
+
|
|
48
|
+
### 3. Use the blocks, don't rewrite them
|
|
49
|
+
|
|
50
|
+
`createRovingFocus` for one tab stop and arrow keys (`move` for grids and trees), `createListbox` for a highlight that moves through options and filters them as someone types (a search box over a list, a picker of your own), `createGridFocus` for cells by row and column, `createCellRange` for a spreadsheet's block of cells with `cellsToText` and `textToCells` to copy and paste it, `createSelection`, `createTypeahead`, `createInputHistory` for ArrowUp and ArrowDown through earlier messages in a chat box or a command line, `createFocusRecovery`, `bindPanel`, `announce` for screen reader messages, `createReorder` for reordering by drag and keyboard, `bindScrollPicker` for a listbox you scroll to pick from, like a time wheel or a strip of pages, with `--picker-offset` on each option to draw it in CSS, `bindDrag` for a drag of your own, `createPopup` with `popupState`, `popupTrigger` and `popupContent` for anything that opens, `elements`, `selects`, `isRTL`, `idPart`, `@ui-sdk/core/text-match`, `@ui-sdk/core/date`, `createTreeCollection`. The tables under "All Behaviors" map jobs to them, with a demo for each. [patterns.md](patterns.md) has tested snippets for what the blocks leave to you: grid `move`, derived state, internal selection, a `createFocusRecovery` fallback, and more.
|
|
51
|
+
|
|
52
|
+
### A new behavior
|
|
53
|
+
|
|
54
|
+
When the same interaction repeats across several components, like a "press and hold to repeat" or a "drag to select a range", write it once as a behavior shaped like ours instead of copying it into each primitive: a `create<Thing>(context, options)` function that returns what the api needs, and binds to elements through a slot's `bind` with a cleanup. Read two of ours on the Behaviors pages first and copy their shape: options in, an object of methods and slot pieces out, no framework code. Give it its own tests with `mount`.
|
|
55
|
+
|
|
56
|
+
### 4. Render it
|
|
57
|
+
|
|
58
|
+
`createParts(primitive, { root: "div", item: "div" })` from `@ui-sdk/<framework>/primitive` returns `Root` and one part per tagged slot, typed from the primitive (`@ui-sdk/web` has `createParts`). Write your own part with `usePart` only when it renders something of its own, like a list from data, and a root with `usePrimitive`. The adapter only renders: no key handlers, focus moves, ARIA or `data-slot` in it. In React, the file that calls `createParts` starts with `"use client"`.
|
|
59
|
+
|
|
60
|
+
### 5. Make it agent-ready and test it
|
|
61
|
+
|
|
62
|
+
Follow [agent-ready.md](agent-ready.md), then [testing.md](testing.md). The mutation check there is not optional for a new component.
|
|
63
|
+
|
|
64
|
+
## Compose ours
|
|
65
|
+
|
|
66
|
+
Two seams, both public:
|
|
67
|
+
|
|
68
|
+
- **Render ours inside yours, controlled from your state.** For a picker that opens in a Popover, your primitive owns `open`, ours renders with `open={state.open}`, and its `onOpenChange` forwards `reason`, `event` and `source` into your `change`. Use its props for the rest, like `initialFocus` on `PopoverContent`. Pass `initialFocus` explicitly when a specific field should take focus: in jsdom, the default focused the popup itself. See "Popups and layers" under Behaviors.
|
|
69
|
+
- **Wrap ours and add behavior from outside.** For an input that clears on Escape, render our Input inside a root slot of yours that hears keydown as it bubbles, and change ours through its public controller (`createInputController()`, or the element's `.api` in web components). Check `event.target` so only the part you mean counts.
|
|
70
|
+
|
|
71
|
+
Never bind a slot of yours to an element one of ours already binds. In React our attributes win, but in web components two owners write `data-slot` onto the same element.
|
|
72
|
+
|
|
73
|
+
## Rules
|
|
74
|
+
|
|
75
|
+
- Import only `@ui-sdk/core`, `@ui-sdk/core/<entry>`, each framework's primitive entry, and component entries. Never `@ui-sdk/core/internal/*`: only the ui-sdk repo resolves it. A type you can see only under `dist/foundation/<layer>/*.d.ts` and not in an entry, like `fuzzyFilter` in `foundation/text/fuzzy`, isn't public: rewrite it and record it as a gap.
|
|
76
|
+
- Key collection parts by a string `value` or `id` prop, never an index. Composite keys, like a grid cell's, join ids with a separator ids can't contain. Structural parts, like rows, need keys too.
|
|
77
|
+
- Expose state as ARIA and `data-*` attributes, never inline styles.
|
|
78
|
+
- No direction provider: read `isRTL(el)` when a key is pressed. `createRovingFocus` passes `rtl` to `move`.
|
|
79
|
+
|
|
80
|
+
## Other frameworks
|
|
81
|
+
|
|
82
|
+
Each needs its own adapter package at the same version as `@ui-sdk/core`. Install it if it's missing, and say so. Its `docs/rendering.md` shows how that adapter renders a primitive.
|
|
83
|
+
|
|
84
|
+
**Web components** have no `primitive` entry. `createParts` comes from `@ui-sdk/web` itself. [web-components.md](web-components.md) covers what the types don't: component entries define their elements on import, how to find tag names and required inner markup, and how hidden parts differ from React.
|
|
85
|
+
|
|
86
|
+
## When you're done
|
|
87
|
+
|
|
88
|
+
Besides SKILL.md's checklist, say in your report what you needed that only `@ui-sdk/core/internal/*` or `dist/*.js` had, and any behavior you wrote yourself that a block should have covered.
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# Patterns the blocks leave to you
|
|
2
|
+
|
|
3
|
+
Each snippet comes from a component that passes its tests. Adapt the names. When a block grows to cover one of these, delete the pattern.
|
|
4
|
+
|
|
5
|
+
## Grid arrows with `createRovingFocus` and `move`
|
|
6
|
+
|
|
7
|
+
A set of choices in two dimensions, like emoji, colors or dates, is a `grid` of `row`s and `gridcell`s, and the root has a name. Use `createGridFocus` only when every row has the same columns, like a calendar. A spreadsheet adds `createCellRange` for a block of cells, and copies and pastes it with `range.text`, `cellsToText` and `textToCells` rather than its own tab-separated parser. Emoji, swatches and other lists that wrap into rows are a flowing grid: `createRovingFocus` with the `move` below. A set in one dimension is a `listbox` of `option`s. Don't use plain buttons for the cells.
|
|
8
|
+
|
|
9
|
+
For a grid whose rows and columns are in state. Keys find cells by id, not by index. Past an edge, return `from.key` so the arrow is handled and the page doesn't scroll.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
type CellProps = { value: string; row: string; column: string }
|
|
13
|
+
const cellKey = (row: string, column: string) => `${row}\u001f${column}`
|
|
14
|
+
|
|
15
|
+
const roving = createRovingFocus<State, CellProps>(context, {
|
|
16
|
+
slot: "cell",
|
|
17
|
+
key: "focused",
|
|
18
|
+
move: (event, { from, rtl }) => {
|
|
19
|
+
const { rows, columns } = store.get()
|
|
20
|
+
const row = rows.findIndex((r) => r.id === from.props.row)
|
|
21
|
+
const column = columns.findIndex((c) => c.id === from.props.column)
|
|
22
|
+
const corner = event.ctrlKey || event.metaKey
|
|
23
|
+
const lastRow = rows.length - 1
|
|
24
|
+
const lastColumn = columns.length - 1
|
|
25
|
+
const to = (
|
|
26
|
+
{
|
|
27
|
+
ArrowRight: [row, column + (rtl ? -1 : 1)],
|
|
28
|
+
ArrowLeft: [row, column + (rtl ? 1 : -1)],
|
|
29
|
+
ArrowDown: [row + 1, column],
|
|
30
|
+
ArrowUp: [row - 1, column],
|
|
31
|
+
Home: corner ? [0, 0] : [row, 0],
|
|
32
|
+
End: corner ? [lastRow, lastColumn] : [row, lastColumn],
|
|
33
|
+
} as Record<string, [number, number]>
|
|
34
|
+
)[event.key]
|
|
35
|
+
if (!to) return undefined
|
|
36
|
+
return rows[to[0]] && columns[to[1]]
|
|
37
|
+
? cellKey(rows[to[0]].id, columns[to[1]].id)
|
|
38
|
+
: from.key
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
For a grid that flows items into rows, like an emoji or swatch grid, work from the index in `items` and a `columns` count instead. Down from a column the short last row lacks should land on its last item.
|
|
44
|
+
|
|
45
|
+
Shift is never swallowed, so a grid that selects rows extends from what `roving.keydown` returns:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const moved = roving.keydown(event, el)
|
|
49
|
+
if (moved?.shift && rowOf(moved.key) !== rowOf(moved.from)) {
|
|
50
|
+
selection.extend(rowOf(moved.key), {
|
|
51
|
+
from: rowOf(moved.from),
|
|
52
|
+
reason: "list-navigation",
|
|
53
|
+
event,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## `createRovingFocus`: `remember: false`
|
|
59
|
+
|
|
60
|
+
With `remember: false`, the stop stays on the `preferred` item even while focus moves elsewhere in the group, so the focused item can have `tabindex="-1"`. That's right for a radio group, where selection follows focus. Anywhere else, keep the default and move focus explicitly with `roving.focus(key)`.
|
|
61
|
+
|
|
62
|
+
## State derived from options and state
|
|
63
|
+
|
|
64
|
+
`sync` sees only options. When derived state depends on both, like lists split by an option (`items`) and a value that may be controlled, recompute in a store subscription that compares references. That covers every way either input changes:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
let derivedFrom = { items: store.get().items, value: store.get().value }
|
|
68
|
+
context.onDestroy(
|
|
69
|
+
store.subscribe(() => {
|
|
70
|
+
const { items, value } = store.get()
|
|
71
|
+
if (items === derivedFrom.items && value === derivedFrom.value) return
|
|
72
|
+
derivedFrom = { items, value }
|
|
73
|
+
store.set(split(items, value))
|
|
74
|
+
})
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Storing the derived arrays, rather than computing them in a slot's `state`, is the safe choice: whether a part compares arrays by value isn't documented.
|
|
79
|
+
|
|
80
|
+
## Selection in internal state
|
|
81
|
+
|
|
82
|
+
`createSelection` infers its reasons from an `on<Key>Change` option. Internal state has none, so spell out the generics, and write with `store.set`:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
type SelectionReason = "item-press" | "list-navigation" | "select-all"
|
|
86
|
+
const selection = createSelection<Options, State, "selected", SelectionReason>(
|
|
87
|
+
context,
|
|
88
|
+
{
|
|
89
|
+
key: "selected",
|
|
90
|
+
set: (selected) => (store.set({ selected }), true),
|
|
91
|
+
order: () => store.get().ids,
|
|
92
|
+
multiple: () => true,
|
|
93
|
+
selectable: (id) => !itemById(id)?.disabled,
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Clicks map to it like this. `press` gets the click, so read its modifiers:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
const mouse = event as MouseEvent | undefined
|
|
102
|
+
if (mouse?.shiftKey)
|
|
103
|
+
selection.extend(id, {
|
|
104
|
+
from: store.get().focused,
|
|
105
|
+
reason: "item-press",
|
|
106
|
+
event: mouse,
|
|
107
|
+
})
|
|
108
|
+
else if (mouse?.ctrlKey || mouse?.metaKey)
|
|
109
|
+
selection.toggle(id, { reason: "item-press", event: mouse })
|
|
110
|
+
else selection.choose(id, { reason: "item-press", event: mouse })
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`selects` on an array key takes an array of values: `selects({ selected: ({ key }) => [key] })`. On a scalar key, a value or a pair: `selects({ focused: ({ key }) => [key, null] })`.
|
|
114
|
+
|
|
115
|
+
## Typeahead in a roving group
|
|
116
|
+
|
|
117
|
+
`createTypeahead()` returns the search function itself, with `reset()` and `active()` on it. Let Space continue a query in progress, else let it toggle:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
if (isTypeaheadKey(event) && (event.key !== " " || typeahead.active())) {
|
|
121
|
+
const items = roving.items()
|
|
122
|
+
const index = typeahead(
|
|
123
|
+
event.key,
|
|
124
|
+
items.map((item) => labelOf(item.el)),
|
|
125
|
+
items.findIndex((item) => item.el === el)
|
|
126
|
+
)
|
|
127
|
+
if (index !== -1) {
|
|
128
|
+
event.preventDefault()
|
|
129
|
+
roving.focus(items[index].key)
|
|
130
|
+
}
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## A search box over options with `createListbox`
|
|
136
|
+
|
|
137
|
+
Keep focus in the input and highlight options with `aria-activedescendant`. The input is a `combobox`, each option an `option`, and choosing is a value you write with `createChange`:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
const listbox = createListbox(context, {
|
|
141
|
+
key: "highlighted",
|
|
142
|
+
focus: "virtual",
|
|
143
|
+
query: () => context.store.get().query,
|
|
144
|
+
})
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
input: slot({
|
|
149
|
+
attrs: (state, { id, api }) => ({
|
|
150
|
+
role: "combobox",
|
|
151
|
+
"aria-expanded": "true",
|
|
152
|
+
"aria-controls": `${id}-list`,
|
|
153
|
+
"aria-activedescendant": api.listbox.activeId(state),
|
|
154
|
+
}),
|
|
155
|
+
on: {
|
|
156
|
+
input: (event, { api }) => api.search((event.target as HTMLInputElement).value),
|
|
157
|
+
keydown: (event, { api }) => api.keydown(event),
|
|
158
|
+
},
|
|
159
|
+
}),
|
|
160
|
+
option: slot<{ value: string }>({
|
|
161
|
+
role: "option",
|
|
162
|
+
focus: "active-descendant",
|
|
163
|
+
props: { value: "string" },
|
|
164
|
+
selects: selects({ highlighted: ({ key }) => [key, null] }),
|
|
165
|
+
present: (_state, part) => part.api.listbox.shows(part),
|
|
166
|
+
attrs: (state, part) => ({
|
|
167
|
+
...part.api.listbox.attrs(state, part),
|
|
168
|
+
"aria-selected": String(state.value === part.key),
|
|
169
|
+
}),
|
|
170
|
+
press: ({ key, api }, event) => api.choose(key, event),
|
|
171
|
+
on: {
|
|
172
|
+
pointerdown: (event) => event.preventDefault(),
|
|
173
|
+
pointermove: (event, { key, api }) => api.listbox.highlight(key, { event }),
|
|
174
|
+
},
|
|
175
|
+
bind: (el, part) => part.api.listbox.bind(el, part),
|
|
176
|
+
}),
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
`api.search` writes the query and calls `listbox.move("first")`, and `api.keydown` chooses the highlighted key on Enter before passing other keys to `listbox.keydown`. `pointerdown` keeps focus in the input. For options from data, pass `items` and render `listbox.items()`.
|
|
180
|
+
|
|
181
|
+
## A `createFocusRecovery` fallback
|
|
182
|
+
|
|
183
|
+
`fallback` runs after the state change, so the part that left is already gone from your lists. Walk a stable order from its key to find the neighbor that's still there, the next one first:
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
const recovery = createFocusRecovery<{ value: string; list: string }>({
|
|
187
|
+
fallback: (lost) => {
|
|
188
|
+
const { items } = store.get()
|
|
189
|
+
const list = store.get()[lost.props.list]
|
|
190
|
+
const at = items.findIndex((item) => item.id === lost.key)
|
|
191
|
+
const next =
|
|
192
|
+
items.slice(at + 1).find((item) => list.includes(item.id)) ??
|
|
193
|
+
items
|
|
194
|
+
.slice(0, Math.max(at, 0))
|
|
195
|
+
.reverse()
|
|
196
|
+
.find((item) => list.includes(item.id))
|
|
197
|
+
// `slotOf` maps a list to its option slot. Return nothing to let focus go.
|
|
198
|
+
return next ? context.element(slotOf(lost.props.list), next.id) : undefined
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
// Bind it next to the roving group in the item slot:
|
|
202
|
+
bind: (el, part) => {
|
|
203
|
+
const cleanups = [
|
|
204
|
+
part.api.roving.bind(el, part),
|
|
205
|
+
part.api.recovery.bind(el, part),
|
|
206
|
+
]
|
|
207
|
+
return () => cleanups.forEach((cleanup) => cleanup())
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Two groups of the same kind
|
|
212
|
+
|
|
213
|
+
Two lists side by side need two `createRovingFocus` groups, and a group is one slot. So give each list its own option slot, built by one function inside `slots`, and keep each block on the api by side:
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
slots: (slot) => {
|
|
217
|
+
const option = (side: Side) =>
|
|
218
|
+
slot<OptionProps>({
|
|
219
|
+
role: "option",
|
|
220
|
+
props: { value: "string" },
|
|
221
|
+
attrs: (state, part) => ({
|
|
222
|
+
tabindex: part.api.blocks[side].roving.tabIndex(state, part),
|
|
223
|
+
}),
|
|
224
|
+
// …
|
|
225
|
+
})
|
|
226
|
+
return { available: option("available"), chosen: option("chosen") /* … */ }
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Focus into a field from a grid
|
|
231
|
+
|
|
232
|
+
To let typing in a grid go back to its search field, focus the field on keydown and don't prevent the default. The browser types the character into the newly focused field. jsdom doesn't, so check this one in a real browser.
|
|
233
|
+
|
|
234
|
+
## Reasons the vocabulary lacks
|
|
235
|
+
|
|
236
|
+
Declare them in the callback's type, with a one-line comment naming which aren't shared:
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
// "select-all" isn't in the shared vocabulary.
|
|
240
|
+
export type DataGridValueChangeReason =
|
|
241
|
+
"item-press" | "list-navigation" | "select-all"
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Stepper
|
|
245
|
+
|
|
246
|
+
A stepper is a list of buttons with one tab stop, and the current step has `aria-current="step"`. Don't use radio or tab roles for it. A step a person can't go to yet is `aria-disabled`.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Style it
|
|
2
|
+
|
|
3
|
+
Components render no styles of their own. `@ui-sdk/core/web.css` is an optional stylesheet that gives every component a default look. The setup prompt imports it, so most apps start with it.
|
|
4
|
+
|
|
5
|
+
## web.css
|
|
6
|
+
|
|
7
|
+
- Everything in it sits in `@layer ui-sdk`, so any rule outside a layer wins. With Tailwind, don't import it from a script: Tailwind's base styles reset it. Import it in the global stylesheet after Tailwind, with `@import "@ui-sdk/core/web.css" layer(components);`. That nests it as `components.ui-sdk`, above the base styles and below the utilities, while ui-sdk's behavior CSS stays in the top-level `ui-sdk` layer.
|
|
8
|
+
- Work one of two ways: theme it by setting its `--ui-*` tokens on `:root`, or restyle a part with your own CSS on top. Don't fight it with `!important`.
|
|
9
|
+
- It sets `color-scheme: light dark` and writes colors with `light-dark()`, so it follows the system theme. A light-only design sets `color-scheme: light` on `:root`.
|
|
10
|
+
- Read `node_modules/@ui-sdk/core/dist/web.css`, or https://ui-sdk.dev/web.css on a page with no build step, when a part looks wrong. It's the only place its sizes and icons are written down.
|
|
11
|
+
|
|
12
|
+
### Tokens
|
|
13
|
+
|
|
14
|
+
| Token | What it drives |
|
|
15
|
+
| ------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------- |
|
|
16
|
+
| `--ui-background`, `--ui-foreground` | Page, field and popup surfaces, and their text |
|
|
17
|
+
| `--ui-muted`, `--ui-muted-foreground` | Hover and selected fills; hints, placeholders and secondary text |
|
|
18
|
+
| `--ui-border` | Dividers and popup edges |
|
|
19
|
+
| `--ui-input` | Borders of inputs, selects, checkboxes, buttons and the empty part of a track or rating |
|
|
20
|
+
| `--ui-primary`, `--ui-primary-foreground` | Checked, pressed and filled states, and the text on them |
|
|
21
|
+
| `--ui-destructive` | Errors and invalid borders |
|
|
22
|
+
| `--ui-ring`, `--ui-ring-border` | The focus outline, and a field's border while it has focus |
|
|
23
|
+
| `--ui-overlay`, `--ui-shadow` | A modal's backdrop, and popup shadows |
|
|
24
|
+
| `--ui-radius` | Corners. Above 0, switch and slider thumbs turn fully round |
|
|
25
|
+
| `--ui-spacing` | The unit every height, padding and gap is a multiple of |
|
|
26
|
+
| `--ui-font-size`, `--ui-line-height` | Control text |
|
|
27
|
+
| `--ui-font-sans`, `--ui-font-mono` | Fonts |
|
|
28
|
+
| `--ui-icon-chevron`, `-check`, `-minus`, `-plus`, `-x`, `-eye`, `-eye-off`, `-calendar`, `-pipette`, `-star` | The default icons below, as `url()` images used as masks |
|
|
29
|
+
|
|
30
|
+
### Icons it draws
|
|
31
|
+
|
|
32
|
+
These parts draw an icon in `::before` or `::after` unless they hold an `<svg>` of their own. A text glyph like `−` doesn't count, so you get two. Either render an `<svg>`, keep the default, swap it through its `--ui-icon-*` token, or set `content: none`.
|
|
33
|
+
|
|
34
|
+
- Chevrons: `select-trigger`, `combobox-trigger`, `navigation-menu-trigger`, `accordion-trigger`, `collapsible-trigger`, a submenu's `menu-trigger`.
|
|
35
|
+
- Checks: `checkbox-indicator` (a minus while indeterminate), `select-item-indicator`, `combobox-item-indicator`, `listbox-item-indicator`, `menu-item-indicator`.
|
|
36
|
+
- Minus and plus: `number-input-decrement`, `number-input-increment`.
|
|
37
|
+
- Others: `calendar-previous` and `-next`, `carousel-previous` and `-next`, `pagination-previous` and `-next`, `tree-indicator`, `password-input-toggle`, `date-picker-trigger`, `date-picker-clear`, `color-picker-eye-dropper`, `file-input-item-remove`, `token-input-token-remove`, `toast-close`, `otp-input-separator`.
|
|
38
|
+
- `rating-item` draws its star in `::before`. Draw your own star on the item, not on its radio, which is a transparent hit area.
|
|
39
|
+
|
|
40
|
+
### Sizes it sets
|
|
41
|
+
|
|
42
|
+
Reset these when a design needs other sizes:
|
|
43
|
+
|
|
44
|
+
- Buttons, triggers, inputs and select triggers: `height: calc(var(--ui-spacing) * 8)`. Set `height: auto` for a taller one.
|
|
45
|
+
- Textarea: `min-height: calc(var(--ui-spacing) * 20)`.
|
|
46
|
+
- Slider, Progress and Meter: `min-width: 12rem`.
|
|
47
|
+
- Accordion, Carousel and Image Cropper: `max-width: 28rem`. Carousel is also a three-column grid.
|
|
48
|
+
- `resizable-panel`: `padding: calc(var(--ui-spacing) * 4)`.
|
|
49
|
+
- `field`: a column. A checkbox beside its label inside a Field needs `flex-direction: row`.
|
|
50
|
+
- A button with `aria-label` and only an `<svg>` inside is sized as a square icon button. Don't put `aria-label` on a button with visible text: its name should be that text.
|
|
51
|
+
|
|
52
|
+
## Slots
|
|
53
|
+
|
|
54
|
+
- A root's `data-slot` is the component's name, like `switch`, `slider` or `button`. A part's is `<component>-<part>`, like `switch-thumb` or `select-trigger`.
|
|
55
|
+
- Some don't follow that, like a submenu's trigger, which is `menu-trigger`, and a part rendered as another component through `render`, which can carry that component's slot. Read the slot from the rendered DOM before you write a selector.
|
|
56
|
+
|
|
57
|
+
## State
|
|
58
|
+
|
|
59
|
+
- Style `data-selected`, `data-highlighted`, `data-checked` and the rest so the state reads on its own, at 3:1 against what's around it: a fill change, a full outline or a weight change. A faint tint alone doesn't. Don't default to a stripe down one edge.
|
|
60
|
+
|
|
61
|
+
## Color
|
|
62
|
+
|
|
63
|
+
- Text needs 4.5:1 against what's behind it, and 3:1 when it's large (WCAG 1.4.3). That includes placeholders, `::before` and `::after` text, and text over gradients or images.
|
|
64
|
+
- Control edges, focus indicators and state fills need 3:1 (WCAG 1.4.11).
|
|
65
|
+
- When you set tokens, check these pairs: `--ui-foreground` on `--ui-background`; `--ui-muted-foreground` on `--ui-background` and on `--ui-muted`; `--ui-primary-foreground` on `--ui-primary`; `--ui-input`, `--ui-ring` and `--ui-ring-border` on `--ui-background`.
|
|
66
|
+
- jsdom can't measure color. Check contrast in a real browser, as [testing.md](testing.md#contrast) says.
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Test it
|
|
2
|
+
|
|
3
|
+
`@ui-sdk/core/testing` checks keyboard behavior, focus, ARIA, server output and reading direction. The full page is "Testing" in `docs/core.md`, or https://ui-sdk.dev/docs/core/testing.
|
|
4
|
+
|
|
5
|
+
Test what you built, not what ui-sdk already tests: for an interface, check that the right components are wired with names, values and callbacks; for a new component, check every key and state.
|
|
6
|
+
|
|
7
|
+
Wiring includes what a person does with the keyboard: press Space on every switch or checkbox you placed, not just one, and check that closing a dialog or menu returns focus where it should. Press each button in every dialog, Cancel as well as the confirming one, and check what happened. Submit each required field empty. Assert every button's name in the page's own markup, not in a fixture, and assert that state attributes you don't set, like `aria-disabled`, are absent. The same goes when you're asked to add tests to existing code: tests that pass on a broken page don't count.
|
|
8
|
+
|
|
9
|
+
## Set up tests
|
|
10
|
+
|
|
11
|
+
For React with Vite and Vitest. Other frameworks swap the testing library, like `@testing-library/vue`:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm i -D vitest jsdom @testing-library/react @testing-library/dom @testing-library/user-event
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`vitest.config.ts`:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { defineConfig, mergeConfig } from "vitest/config"
|
|
21
|
+
import viteConfig from "./vite.config.ts"
|
|
22
|
+
|
|
23
|
+
export default mergeConfig(
|
|
24
|
+
viteConfig,
|
|
25
|
+
defineConfig({
|
|
26
|
+
test: {
|
|
27
|
+
environment: "jsdom",
|
|
28
|
+
setupFiles: ["./src/test/setup.ts"],
|
|
29
|
+
css: false,
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`src/test/setup.ts` holds the [jsdom stubs](#jsdom), strict mode and cleanup:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { cleanup } from "@testing-library/react"
|
|
39
|
+
import { afterEach } from "vitest"
|
|
40
|
+
|
|
41
|
+
declare global {
|
|
42
|
+
var __UI_SDK_STRICT__: boolean | undefined
|
|
43
|
+
}
|
|
44
|
+
globalThis.__UI_SDK_STRICT__ = true
|
|
45
|
+
|
|
46
|
+
// The jsdom stubs below go here.
|
|
47
|
+
|
|
48
|
+
afterEach(cleanup)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Which tool for what
|
|
52
|
+
|
|
53
|
+
| You built | Test with |
|
|
54
|
+
| ----------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
55
|
+
| An interface from our components | The framework's testing library for what you wired (names, values, callbacks, what submits), and the [agent test](agent-ready.md#prove-it-with-a-test). Our components are tested already: don't run `checkPattern` on them. |
|
|
56
|
+
| A primitive | `mount` with `keys`, `type`, `click`, `hover` and `drag`, then `checkPattern`, `checkServer` and `checkDirection`. If a page in the app uses it, also render that page: press its keys there, click each of its buttons that moves between steps (Next, Back), assert where focus lands after each, and assert its name in the page's markup |
|
|
57
|
+
| Anything with popups, layout or focus moving between fields | Also a real browser |
|
|
58
|
+
|
|
59
|
+
## Check a pattern
|
|
60
|
+
|
|
61
|
+
`checkPattern(element, pattern)` checks roles, names, states, references between parts and the keyboard interactions of a WAI-ARIA pattern, and throws one error that lists every problem:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { checkPattern } from "@ui-sdk/core/testing"
|
|
65
|
+
|
|
66
|
+
await checkPattern(screen.getByRole("tablist").parentElement!, "tabs")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Patterns: `listbox`, `menu`, `menubar`, `tabs`, `radio-group`, `toolbar`, `tree`, `dialog`, `alertdialog`, `disclosure`, `accordion`, `combobox`, `slider`, `switch`, `checkbox`. Open a menu or dialog before checking it. A menu check activates an item, so use safe actions in tests.
|
|
70
|
+
|
|
71
|
+
## Test a primitive
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { checkDirection, checkServer, mount } from "@ui-sdk/core/testing"
|
|
75
|
+
import { expect, test } from "vitest"
|
|
76
|
+
import { stepper } from "./stepper"
|
|
77
|
+
|
|
78
|
+
test("arrows move between steps and Enter opens one", async () => {
|
|
79
|
+
const view = mount(
|
|
80
|
+
stepper,
|
|
81
|
+
{},
|
|
82
|
+
`<root><step value="a">A</step><step value="b">B</step></root>`
|
|
83
|
+
)
|
|
84
|
+
try {
|
|
85
|
+
await view.keys("Tab", "ArrowRight", "Enter")
|
|
86
|
+
expect(view.state.value).toBe("b")
|
|
87
|
+
expect(view.changes.at(-1)).toMatchObject({
|
|
88
|
+
key: "value",
|
|
89
|
+
source: "keyboard",
|
|
90
|
+
})
|
|
91
|
+
} finally {
|
|
92
|
+
view.unmount()
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test("renders on the server and works in both directions", async () => {
|
|
97
|
+
checkServer(stepper, {}, `<root><step value="a">A</step></root>`)
|
|
98
|
+
await checkDirection(
|
|
99
|
+
stepper,
|
|
100
|
+
{},
|
|
101
|
+
`<root><step value="a">A</step><step value="b">B</step></root>`
|
|
102
|
+
)
|
|
103
|
+
})
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- In `mount`'s markup, tags named after slots become parts and their attributes become part props. `root` is the first element; `view.part("step", "b")` finds another.
|
|
107
|
+
- Focus an input before `type`. `keys` takes `Tab`, `Shift+Tab`, `Space` and combinations.
|
|
108
|
+
- `view.announced` holds what screen readers heard. Call `await view.settle()` before reading delayed work.
|
|
109
|
+
- Always `unmount`.
|
|
110
|
+
- Set `globalThis.__UI_SDK_STRICT__ = true` in the test setup so development warnings fail the test. Declare it first: `declare global { var __UI_SDK_STRICT__: boolean | undefined }`.
|
|
111
|
+
|
|
112
|
+
## Break it on purpose
|
|
113
|
+
|
|
114
|
+
For each key behavior of a new component, break it (return early, skip a call), run the tests, confirm one fails, then restore the file. A test that still passes is testing nothing. Report how many breaks your tests caught. When a page uses the component, break the page too, like a Back button that no longer moves focus, or the component's name.
|
|
115
|
+
|
|
116
|
+
For a composite widget, test both arrow directions, that exactly one item is tabbable, Space and Enter, and every state attribute you set, like `aria-current` or `aria-disabled`.
|
|
117
|
+
|
|
118
|
+
## jsdom
|
|
119
|
+
|
|
120
|
+
Framework renderers don't fill jsdom's gaps. Before anything opens, add these to the test setup:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
HTMLElement.prototype.showPopover = function () {}
|
|
124
|
+
HTMLElement.prototype.hidePopover = function () {}
|
|
125
|
+
Element.prototype.getAnimations = () => []
|
|
126
|
+
Element.prototype.scrollIntoView = function () {}
|
|
127
|
+
Element.prototype.checkVisibility = () => true
|
|
128
|
+
Element.prototype.getClientRects = () => [] as unknown as DOMRectList
|
|
129
|
+
document.elementFromPoint = () => null
|
|
130
|
+
document.elementsFromPoint = () => []
|
|
131
|
+
globalThis.ResizeObserver ??= class {
|
|
132
|
+
observe() {}
|
|
133
|
+
unobserve() {}
|
|
134
|
+
disconnect() {}
|
|
135
|
+
}
|
|
136
|
+
document.head.append(
|
|
137
|
+
Object.assign(document.createElement("style"), {
|
|
138
|
+
textContent: "[popover] { display: block !important }",
|
|
139
|
+
})
|
|
140
|
+
)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Assign these rather than using `??=`: jsdom has some of them without the parts that matter. Web components in jsdom also need `ElementInternals`: jsdom's `attachInternals` lacks `setFormValue`, `setValidity`, `checkValidity`, `reportValidity` and `states`, so wrap `HTMLElement.prototype.attachInternals` and add them (no-ops, `() => true` for the checks, a `Set` for `states`). jsdom also never calls `formResetCallback`, and its `FormData` leaves custom elements out, so check form reset and submitted values in a real browser. Stub `URL.createObjectURL` for file previews. File Input's native input has `pointer-events: none`, so upload with `userEvent.setup({ pointerEventsCheck: 0 })`. Some parts render a status region of their own, like `SliderValue`'s `<output>`, so name yours and query by name: `getByRole("status", { name: "Total" })`. `mount` already does the popover and animation stubs, and it keeps a part that isn't present as a detached node, so `view.part()` still returns it: check `isConnected` to tell whether it's on the page. Some state arrives a moment after a render or an event, like an icon-only button's name from its tooltip, or focus moving into a menu that opened on a press: wait with `await settle()` from `@ui-sdk/core/testing` (inside `act` in React), or query with `findByRole`.
|
|
144
|
+
|
|
145
|
+
## WebMCP
|
|
146
|
+
|
|
147
|
+
`registerTools` calls `document.modelContext.registerTool` once per tool and expects a Promise back. A mock:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
const tools = new Map<string, { execute: (input: object) => unknown }>()
|
|
151
|
+
Object.assign(document, {
|
|
152
|
+
modelContext: {
|
|
153
|
+
registerTool: async (tool: {
|
|
154
|
+
name: string
|
|
155
|
+
execute: (input: object) => unknown
|
|
156
|
+
}) => {
|
|
157
|
+
tools.set(tool.name, tool)
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
})
|
|
161
|
+
const unregister = registerTools(agent, { allow: () => true })
|
|
162
|
+
expect(await tools.get("snapshot")!.execute({})).toBeInstanceOf(Array)
|
|
163
|
+
unregister()
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## A real browser
|
|
167
|
+
|
|
168
|
+
Check what jsdom can't show: top layer popups and their placement, layout, a key that moves focus so the next typed character lands in another field, typeahead timing. A browser tool's "type" may insert text without key events, so press real keys to test keyboard handling. Tab through the whole interface once and confirm every control is reachable and named.
|
|
169
|
+
|
|
170
|
+
### Contrast
|
|
171
|
+
|
|
172
|
+
Measure the color pairs in [styles.md](styles.md#color) in every state a person can reach: hover, focus, selected, disabled, open, invalid, and each theme. Read the colors that are painted, not the ones you set: a tint over another fill, a gradient or a sliding indicator changes what's behind the text. Measure in a visible window with a size, after animations finish: a hidden tab paints nothing and runs no animations, so it gives wrong numbers.
|