@react-consulting/rc-kit 0.0.0-stage → 0.13.1
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/LICENSE +21 -0
- package/README.md +93 -2
- package/devkit/README.md +301 -0
- package/devkit/cli.test.ts +211 -0
- package/devkit/cli.ts +120 -0
- package/devkit/commands/build.ts +127 -0
- package/devkit/commands/checks.ts +123 -0
- package/devkit/commands/context.ts +47 -0
- package/devkit/commands/db.ts +154 -0
- package/devkit/commands/deploy.ts +46 -0
- package/devkit/commands/dev.ts +191 -0
- package/devkit/commands/doctor.ts +25 -0
- package/devkit/commands/kit.ts +45 -0
- package/devkit/commands/new.ts +81 -0
- package/devkit/commands/registry.ts +20 -0
- package/devkit/commands/secrets.ts +254 -0
- package/devkit/lib/args.ts +65 -0
- package/devkit/lib/audit.test.ts +405 -0
- package/devkit/lib/audit.ts +813 -0
- package/devkit/lib/config.test.ts +203 -0
- package/devkit/lib/config.ts +417 -0
- package/devkit/lib/database/index.test.ts +223 -0
- package/devkit/lib/database/index.ts +314 -0
- package/devkit/lib/database/neon.test.ts +233 -0
- package/devkit/lib/database/neon.ts +357 -0
- package/devkit/lib/database/prepare.ts +54 -0
- package/devkit/lib/deploy-config.test.ts +217 -0
- package/devkit/lib/deploy-config.ts +133 -0
- package/devkit/lib/deploy.test.ts +275 -0
- package/devkit/lib/deploy.ts +177 -0
- package/devkit/lib/dev-gateway.test.ts +128 -0
- package/devkit/lib/dev-gateway.ts +162 -0
- package/devkit/lib/dev-menu.test.ts +114 -0
- package/devkit/lib/dev-menu.ts +332 -0
- package/devkit/lib/dev-secrets.test.ts +156 -0
- package/devkit/lib/dev-secrets.ts +97 -0
- package/devkit/lib/dev.test.ts +194 -0
- package/devkit/lib/dev.ts +119 -0
- package/devkit/lib/doctor.test.ts +144 -0
- package/devkit/lib/doctor.ts +264 -0
- package/devkit/lib/env-file.test.ts +102 -0
- package/devkit/lib/env-file.ts +96 -0
- package/devkit/lib/glob.ts +31 -0
- package/devkit/lib/infisical.test.ts +208 -0
- package/devkit/lib/infisical.ts +139 -0
- package/devkit/lib/json-schema.ts +220 -0
- package/devkit/lib/jsonc.test.ts +53 -0
- package/devkit/lib/jsonc.ts +93 -0
- package/devkit/lib/kit-migrate.test.ts +215 -0
- package/devkit/lib/kit-migrate.ts +624 -0
- package/devkit/lib/kit-package.test.ts +83 -0
- package/devkit/lib/kit-package.ts +57 -0
- package/devkit/lib/kit-version.ts +22 -0
- package/devkit/lib/naming.test.ts +547 -0
- package/devkit/lib/naming.ts +796 -0
- package/devkit/lib/paths.ts +7 -0
- package/devkit/lib/process.ts +78 -0
- package/devkit/lib/project-checks.ts +86 -0
- package/devkit/lib/scaffold.test.ts +302 -0
- package/devkit/lib/scaffold.ts +315 -0
- package/devkit/lib/secrets.test.ts +101 -0
- package/devkit/lib/secrets.ts +125 -0
- package/devkit/lib/sourcemaps.test.ts +86 -0
- package/devkit/lib/sourcemaps.ts +98 -0
- package/devkit/lib/test-utils.ts +68 -0
- package/devkit/lib/workspace.ts +87 -0
- package/devkit/lib/wrangler.ts +231 -0
- package/docs/rc-config.md +93 -0
- package/package.json +86 -4
- package/presets/build.d.ts +15 -0
- package/presets/build.js +53 -0
- package/presets/vite-plus.d.ts +28 -0
- package/presets/vite-plus.js +153 -0
- package/registry/README.md +294 -0
- package/registry/public/r/avatar-stack.json +18 -0
- package/registry/public/r/avatar.json +20 -0
- package/registry/public/r/back-link.json +21 -0
- package/registry/public/r/badge.json +17 -0
- package/registry/public/r/button.json +18 -0
- package/registry/public/r/calendar-days.json +14 -0
- package/registry/public/r/calendar-popover.json +24 -0
- package/registry/public/r/calendar.json +23 -0
- package/registry/public/r/callout.json +20 -0
- package/registry/public/r/card.json +18 -0
- package/registry/public/r/character-counter.json +17 -0
- package/registry/public/r/checkbox.json +22 -0
- package/registry/public/r/choice-cards.json +22 -0
- package/registry/public/r/color-tag.json +17 -0
- package/registry/public/r/combobox.json +24 -0
- package/registry/public/r/confirm-button.json +24 -0
- package/registry/public/r/confirm-dialog.json +23 -0
- package/registry/public/r/copy-button.json +24 -0
- package/registry/public/r/date-picker.json +24 -0
- package/registry/public/r/date-range-picker.json +28 -0
- package/registry/public/r/detail-header.json +17 -0
- package/registry/public/r/detail-row.json +17 -0
- package/registry/public/r/dev-inbox-api.json +33 -0
- package/registry/public/r/dev-toolbar.json +109 -0
- package/registry/public/r/dev-tools-contract.json +15 -0
- package/registry/public/r/dialog.json +23 -0
- package/registry/public/r/empty-state.json +20 -0
- package/registry/public/r/error-state.json +23 -0
- package/registry/public/r/eyebrow.json +17 -0
- package/registry/public/r/fab.json +20 -0
- package/registry/public/r/field-error.json +17 -0
- package/registry/public/r/field-grid.json +17 -0
- package/registry/public/r/field.json +19 -0
- package/registry/public/r/file-picker.json +22 -0
- package/registry/public/r/filter-chips.json +17 -0
- package/registry/public/r/form-section.json +17 -0
- package/registry/public/r/form-sheet.json +22 -0
- package/registry/public/r/icon-button.json +23 -0
- package/registry/public/r/input.json +18 -0
- package/registry/public/r/label.json +18 -0
- package/registry/public/r/list-row.json +17 -0
- package/registry/public/r/loading-state.json +18 -0
- package/registry/public/r/localized-field.json +23 -0
- package/registry/public/r/markdown-text.json +17 -0
- package/registry/public/r/menu.json +21 -0
- package/registry/public/r/money-input.json +17 -0
- package/registry/public/r/month-day-select.json +18 -0
- package/registry/public/r/numbered-step.json +20 -0
- package/registry/public/r/page-actions.json +14 -0
- package/registry/public/r/page-header.json +17 -0
- package/registry/public/r/pending.json +17 -0
- package/registry/public/r/person-option.json +21 -0
- package/registry/public/r/popover.json +20 -0
- package/registry/public/r/progress-bar.json +17 -0
- package/registry/public/r/query-view.json +22 -0
- package/registry/public/r/registry.json +1352 -0
- package/registry/public/r/retry-button.json +21 -0
- package/registry/public/r/rich-text-editor.json +32 -0
- package/registry/public/r/save-bar.json +22 -0
- package/registry/public/r/search-input.json +23 -0
- package/registry/public/r/search-select.json +24 -0
- package/registry/public/r/section-tabs.json +17 -0
- package/registry/public/r/segmented.json +18 -0
- package/registry/public/r/select.json +23 -0
- package/registry/public/r/sheet.json +24 -0
- package/registry/public/r/skeleton.json +17 -0
- package/registry/public/r/spinner.json +20 -0
- package/registry/public/r/stale-notice.json +23 -0
- package/registry/public/r/stat-tile.json +23 -0
- package/registry/public/r/stepper.json +23 -0
- package/registry/public/r/suggestion-strip.json +21 -0
- package/registry/public/r/swatch-picker.json +22 -0
- package/registry/public/r/switch.json +21 -0
- package/registry/public/r/tabs.json +20 -0
- package/registry/public/r/textarea.json +18 -0
- package/registry/public/r/theme.json +15 -0
- package/registry/public/r/timezone-select.json +19 -0
- package/registry/public/r/toaster.json +21 -0
- package/registry/public/r/tooltip.json +17 -0
- package/registry/public/r/ui-labels.json +14 -0
- package/registry/public/r/use-copy-to-clipboard.json +20 -0
- package/registry/public/r/use-online.json +14 -0
- package/registry/public/r/use-stale-queries.json +17 -0
- package/registry/public/r/utils.json +18 -0
- package/registry/public/r/weekday-picker.json +19 -0
- package/registry/public/r/yes-no.json +20 -0
- package/registry/serve.ts +29 -0
- package/rules/architecture.md +47 -0
- package/rules/cloudflare.md +74 -0
- package/rules/code.md +12 -0
- package/rules/git.md +10 -0
- package/rules/index.md +14 -0
- package/rules/observability.md +13 -0
- package/rules/performance.md +39 -0
- package/rules/runtime.md +9 -0
- package/rules/secrets.md +11 -0
- package/rules/stack.md +33 -0
- package/rules/ui.md +23 -0
- package/runtime/ai.test.ts +106 -0
- package/runtime/ai.ts +125 -0
- package/runtime/observability/allowlists.ts +42 -0
- package/runtime/observability/anonymize.test.ts +111 -0
- package/runtime/observability/anonymize.ts +249 -0
- package/runtime/observability/browser.test.ts +46 -0
- package/runtime/observability/browser.ts +126 -0
- package/runtime/observability/server.test.ts +84 -0
- package/runtime/observability/server.ts +152 -0
- package/runtime/observability/tunnel.test.ts +276 -0
- package/runtime/observability/tunnel.ts +360 -0
- package/runtime/observability/user-agent.ts +51 -0
- package/schema/rc.config.schema.json +333 -0
- package/template/.gitattributes +1 -0
- package/template/.github/workflows/ci.yml +64 -0
- package/template/CLAUDE.md +48 -0
- package/template/README.md +50 -0
- package/template/apps/admin/.dev.vars.example +5 -0
- package/template/apps/admin/components.json +24 -0
- package/template/apps/admin/package.json +48 -0
- package/template/apps/admin/public/favicon.svg +1 -0
- package/template/apps/admin/src/components/app-shell.tsx +41 -0
- package/template/apps/admin/src/components/dev-sign-in-links.tsx +57 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-context.ts +13 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-environment-panel.tsx +105 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-list.tsx +54 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-message.tsx +104 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-panel.tsx +130 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-launcher.tsx +45 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-panel.tsx +90 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-types.ts +11 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar.tsx +61 -0
- package/template/apps/admin/src/components/dev-toolbar/development-devtools.tsx +32 -0
- package/template/apps/admin/src/components/login-form.tsx +115 -0
- package/template/apps/admin/src/components/login-sent.tsx +23 -0
- package/template/apps/admin/src/components/message-list.tsx +44 -0
- package/template/apps/admin/src/components/turnstile-challenge.tsx +140 -0
- package/template/apps/admin/src/components/ui/button.tsx +87 -0
- package/template/apps/admin/src/components/ui/callout.tsx +84 -0
- package/template/apps/admin/src/components/ui/card.tsx +48 -0
- package/template/apps/admin/src/components/ui/eyebrow.tsx +33 -0
- package/template/apps/admin/src/components/ui/field-error.tsx +24 -0
- package/template/apps/admin/src/components/ui/field.tsx +100 -0
- package/template/apps/admin/src/components/ui/input.tsx +73 -0
- package/template/apps/admin/src/components/ui/label.tsx +39 -0
- package/template/apps/admin/src/components/ui/skeleton.tsx +225 -0
- package/template/apps/admin/src/components/ui/spinner.tsx +12 -0
- package/template/apps/admin/src/components/ui/toaster.tsx +33 -0
- package/template/apps/admin/src/components/ui/tooltip.tsx +51 -0
- package/template/apps/admin/src/hooks/use-dev-inbox.ts +25 -0
- package/template/apps/admin/src/hooks/use-dev-toolbar-state.ts +48 -0
- package/template/apps/admin/src/lib/api.ts +39 -0
- package/template/apps/admin/src/lib/auth-client.ts +7 -0
- package/template/apps/admin/src/lib/dev-inbox-links.ts +66 -0
- package/template/apps/admin/src/lib/dev-tools-client.ts +54 -0
- package/template/apps/admin/src/lib/dev-tools-contract.ts +52 -0
- package/template/apps/admin/src/lib/messages.ts +5 -0
- package/template/apps/admin/src/lib/query-keys.ts +3 -0
- package/template/apps/admin/src/lib/security-headers.ts +18 -0
- package/template/apps/admin/src/lib/session.ts +27 -0
- package/template/apps/admin/src/lib/site-url.ts +7 -0
- package/template/apps/admin/src/lib/turnstile.ts +70 -0
- package/template/apps/admin/src/lib/ui-labels.tsx +182 -0
- package/template/apps/admin/src/lib/utils.ts +6 -0
- package/template/apps/admin/src/routeTree.gen.ts +109 -0
- package/template/apps/admin/src/router.tsx +29 -0
- package/template/apps/admin/src/routes/__root.tsx +56 -0
- package/template/apps/admin/src/routes/_app/index.tsx +38 -0
- package/template/apps/admin/src/routes/_app.tsx +26 -0
- package/template/apps/admin/src/routes/login.tsx +48 -0
- package/template/apps/admin/src/styles/app.css +11 -0
- package/template/apps/admin/src/worker.ts +88 -0
- package/template/apps/admin/tsconfig.json +19 -0
- package/template/apps/admin/vite.config.ts +69 -0
- package/template/apps/admin/wrangler.jsonc +92 -0
- package/template/apps/web/.env.example +1 -0
- package/template/apps/web/astro.config.ts +46 -0
- package/template/apps/web/package.json +33 -0
- package/template/apps/web/public/favicon.svg +1 -0
- package/template/apps/web/src/components/ContactForm.astro +78 -0
- package/template/apps/web/src/env.d.ts +11 -0
- package/template/apps/web/src/layouts/BaseLayout.astro +32 -0
- package/template/apps/web/src/lib/api.ts +8 -0
- package/template/apps/web/src/pages/api/messages.ts +32 -0
- package/template/apps/web/src/pages/index.astro +26 -0
- package/template/apps/web/src/pages/media/[...key].ts +4 -0
- package/template/apps/web/src/scripts/contact-form.ts +105 -0
- package/template/apps/web/src/scripts/error-reporting.ts +4 -0
- package/template/apps/web/src/scripts/turnstile.ts +177 -0
- package/template/apps/web/src/styles/global.css +11 -0
- package/template/apps/web/src/worker.ts +34 -0
- package/template/apps/web/tsconfig.json +11 -0
- package/template/apps/web/wrangler.jsonc +45 -0
- package/template/bun.lock +1925 -0
- package/template/bunfig.toml +2 -0
- package/template/gitignore +23 -0
- package/template/package.json +74 -0
- package/template/packages/api/components.json +21 -0
- package/template/packages/api/package.json +30 -0
- package/template/packages/api/src/client.ts +13 -0
- package/template/packages/api/src/cloudflare-env.d.ts +26 -0
- package/template/packages/api/src/emails/escape-html.ts +13 -0
- package/template/packages/api/src/emails/layout.ts +22 -0
- package/template/packages/api/src/emails/magic-link.ts +32 -0
- package/template/packages/api/src/emails/new-message.ts +32 -0
- package/template/packages/api/src/emails/send.ts +14 -0
- package/template/packages/api/src/lib/auth-guard.ts +16 -0
- package/template/packages/api/src/lib/auth.ts +108 -0
- package/template/packages/api/src/lib/context.ts +7 -0
- package/template/packages/api/src/lib/dev-inbox/routes.ts +77 -0
- package/template/packages/api/src/lib/dev-inbox/send.ts +57 -0
- package/template/packages/api/src/lib/dev-inbox/store.ts +185 -0
- package/template/packages/api/src/lib/dev-inbox.ts +6 -0
- package/template/packages/api/src/lib/dev-tools-contract.ts +52 -0
- package/template/packages/api/src/lib/environment.ts +17 -0
- package/template/packages/api/src/lib/turnstile.ts +33 -0
- package/template/packages/api/src/media.ts +45 -0
- package/template/packages/api/src/routes/admin-messages.ts +21 -0
- package/template/packages/api/src/routes/dev.ts +31 -0
- package/template/packages/api/src/routes/health.ts +7 -0
- package/template/packages/api/src/routes/messages.ts +58 -0
- package/template/packages/api/src/schemas.ts +18 -0
- package/template/packages/api/src/server.ts +29 -0
- package/template/packages/api/tsconfig.json +10 -0
- package/template/packages/db/migrations/0001_init.sql +79 -0
- package/template/packages/db/package.json +34 -0
- package/template/packages/db/prisma/schema.prisma +95 -0
- package/template/packages/db/prisma.config.ts +9 -0
- package/template/packages/db/scripts/migrate.ts +15 -0
- package/template/packages/db/scripts/new-migration.ts +185 -0
- package/template/packages/db/scripts/reset.ts +54 -0
- package/template/packages/db/scripts/seed.ts +44 -0
- package/template/packages/db/scripts/wrangler.ts +35 -0
- package/template/packages/db/src/d1.ts +7 -0
- package/template/packages/db/src/migration-guard.test.ts +43 -0
- package/template/packages/db/src/migration-guard.ts +51 -0
- package/template/packages/db/src/new-migration.test.ts +16 -0
- package/template/packages/db/src/scope.ts +38 -0
- package/template/packages/db/src/seed.ts +30 -0
- package/template/packages/db/src/sql.ts +42 -0
- package/template/packages/db/tsconfig.json +8 -0
- package/template/packages/shared/components.json +21 -0
- package/template/packages/shared/package.json +33 -0
- package/template/packages/shared/src/edge/origins.ts +20 -0
- package/template/packages/shared/src/edge/turnstile.ts +11 -0
- package/template/packages/shared/src/locales.ts +13 -0
- package/template/packages/shared/src/message-rules.ts +16 -0
- package/template/packages/shared/src/messages.test.ts +26 -0
- package/template/packages/shared/src/messages.ts +30 -0
- package/template/packages/shared/src/observability/build-release.ts +9 -0
- package/template/packages/shared/src/observability/error-reporting.ts +31 -0
- package/template/packages/shared/src/observability/error-tunnel.ts +20 -0
- package/template/packages/shared/src/observability/sentry-browser.ts +1 -0
- package/template/packages/shared/src/observability/server-errors.ts +74 -0
- package/template/packages/shared/src/project.ts +1 -0
- package/template/packages/shared/src/styles/rc-theme.css +138 -0
- package/template/packages/shared/src/styles/theme.css +9 -0
- package/template/packages/shared/tsconfig.json +10 -0
- package/template/rc.config.json +25 -0
- package/template/scripts/bootstrap-local.ts +42 -0
- package/template/tsconfig.base.json +20 -0
- package/template/tsconfig.json +8 -0
- package/template/tsconfig.worker.json +7 -0
- package/template/turbo.json +40 -0
- package/template/vite.config.ts +8 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "calendar-days",
|
|
4
|
+
"title": "Calendar Days",
|
|
5
|
+
"description": "Calcul sur des jours ISO `YYYY-MM-DD` sans décalage de fuseau : mois, semaines commençant le lundi, bornes, format `Intl`.",
|
|
6
|
+
"files": [
|
|
7
|
+
{
|
|
8
|
+
"path": "src/lib/calendar-days.ts",
|
|
9
|
+
"content": "const DAY_MS = 86_400_000\n\nfunction utcDay(day: string): Date {\n return new Date(`${day}T12:00:00Z`)\n}\n\nfunction isoDay(date: Date): string {\n return date.toISOString().slice(0, 10)\n}\n\nfunction pad(value: number): string {\n return String(value).padStart(2, \"0\")\n}\n\nexport function todayIso(now: Date = new Date()): string {\n return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`\n}\n\nexport function monthStart(day: string): string {\n return `${day.slice(0, 7)}-01`\n}\n\nexport function addDays(day: string, count: number): string {\n return isoDay(new Date(utcDay(day).getTime() + count * DAY_MS))\n}\n\nexport function addMonths(day: string, count: number): string {\n const date = utcDay(day)\n const year = date.getUTCFullYear()\n const month = date.getUTCMonth() + count\n const lastDay = new Date(Date.UTC(year, month + 1, 0)).getUTCDate()\n\n return isoDay(\n new Date(Date.UTC(year, month, Math.min(date.getUTCDate(), lastDay)))\n )\n}\n\nexport function weekStart(day: string): string {\n return addDays(day, -((utcDay(day).getUTCDay() + 6) % 7))\n}\n\nexport function monthWeeks(month: string): string[][] {\n const nextMonth = addMonths(month, 1)\n const weeks: string[][] = []\n\n for (\n let start = weekStart(month);\n start < nextMonth;\n start = addDays(start, 7)\n ) {\n weeks.push(Array.from({ length: 7 }, (_, index) => addDays(start, index)))\n }\n\n return weeks\n}\n\nexport function clampDay(day: string, min?: string, max?: string): string {\n if (min && day < min) {\n return min\n }\n\n return max && day > max ? max : day\n}\n\nexport function formatDay(\n day: string,\n locale: string,\n format: Intl.DateTimeFormatOptions\n): string {\n return new Intl.DateTimeFormat(locale, { ...format, timeZone: \"UTC\" }).format(\n utcDay(day)\n )\n}\n\nexport function weekdayNames(\n locale: string\n): { long: string; short: string }[] {\n const long = new Intl.DateTimeFormat(locale, {\n timeZone: \"UTC\",\n weekday: \"long\",\n })\n const short = new Intl.DateTimeFormat(locale, {\n timeZone: \"UTC\",\n weekday: \"short\",\n })\n\n return [1, 2, 3, 4, 5, 6, 7].map((day) => {\n const date = new Date(Date.UTC(2024, 0, day))\n\n return { long: long.format(date), short: short.format(date).slice(0, 2) }\n })\n}\n",
|
|
10
|
+
"type": "registry:lib"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"type": "registry:lib"
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "calendar-popover",
|
|
4
|
+
"title": "Calendar Popover",
|
|
5
|
+
"description": "Champ déclencheur et popover d'un calendrier, en feuille basse sur mobile, focus posé sur le jour actif : la base de `date-picker` et `date-range-picker`.",
|
|
6
|
+
"dependencies": [
|
|
7
|
+
"@base-ui/react@^1.9.0",
|
|
8
|
+
"lucide-react@^1.71.0"
|
|
9
|
+
],
|
|
10
|
+
"registryDependencies": [
|
|
11
|
+
"@rc/calendar",
|
|
12
|
+
"@rc/input",
|
|
13
|
+
"@rc/select",
|
|
14
|
+
"@rc/utils"
|
|
15
|
+
],
|
|
16
|
+
"files": [
|
|
17
|
+
{
|
|
18
|
+
"path": "src/ui/calendar-popover.tsx",
|
|
19
|
+
"content": "import { Popover } from \"@base-ui/react/popover\"\nimport type { LucideIcon } from \"lucide-react\"\nimport { type ReactNode, useRef } from \"react\"\nimport { CALENDAR_ACTIVE_DAY_SELECTOR } from \"@/components/ui/calendar\"\nimport { CONTROL_CLASS_NAME, useControlAria } from \"@/components/ui/input\"\nimport {\n SHEET_BACKDROP_CLASS_NAME,\n SHEET_POPUP_CLASS_NAME,\n SHEET_POSITIONER_CLASS_NAME,\n} from \"@/components/ui/select\"\nimport { cn } from \"@/lib/utils\"\n\nexport interface CalendarControlProps {\n \"aria-describedby\"?: string\n \"aria-invalid\"?: boolean\n \"aria-label\"?: string\n className?: string\n disabled?: boolean\n id?: string\n placeholder?: string\n}\n\nexport function CalendarPopover({\n \"aria-label\": ariaLabel,\n children,\n className,\n disabled,\n icon: Icon,\n id,\n onOpenChange,\n open,\n placeholder,\n summary,\n ...ariaProps\n}: CalendarControlProps & {\n children: ReactNode\n icon: LucideIcon\n onOpenChange: (\n open: boolean,\n details: Popover.Root.ChangeEventDetails\n ) => void\n open: boolean\n summary: string | null\n}) {\n const aria = useControlAria({ id, ...ariaProps })\n const popupRef = useRef<HTMLDivElement>(null)\n\n const shown = summary ?? placeholder\n\n return (\n <Popover.Root onOpenChange={onOpenChange} open={open}>\n <Popover.Trigger\n {...aria}\n aria-label={\n ariaLabel && summary ? `${ariaLabel} : ${summary}` : ariaLabel\n }\n className={cn(\n CONTROL_CLASS_NAME,\n \"flex cursor-pointer items-center gap-2.5 px-3 text-left data-[popup-open]:border-accent\",\n className\n )}\n disabled={disabled}\n >\n <Icon aria-hidden=\"true\" className=\"size-4 shrink-0 text-ink-3\" />\n <span\n className={cn(\n \"min-w-0 flex-1 truncate tabular-nums\",\n !summary && \"text-ink-3\"\n )}\n >\n {shown}\n </span>\n </Popover.Trigger>\n <Popover.Portal>\n <Popover.Backdrop className={SHEET_BACKDROP_CLASS_NAME} />\n <Popover.Positioner\n align=\"start\"\n className={cn(\"z-70\", SHEET_POSITIONER_CLASS_NAME)}\n collisionPadding={12}\n sideOffset={6}\n >\n <Popover.Popup\n className={cn(\n \"w-[min(20rem,calc(100vw-1.5rem))] origin-(--transform-origin) overflow-y-auto rounded-lg border border-line bg-surface p-3 shadow-lg outline-none transition-[opacity,transform] duration-150 ease-out-expo data-[ending-style]:opacity-0 data-[starting-style]:-translate-y-1 data-[starting-style]:opacity-0 motion-reduce:transition-none\",\n SHEET_POPUP_CLASS_NAME\n )}\n initialFocus={() =>\n popupRef.current?.querySelector<HTMLElement>(\n CALENDAR_ACTIVE_DAY_SELECTOR\n ) ?? true\n }\n ref={popupRef}\n >\n {children}\n </Popover.Popup>\n </Popover.Positioner>\n </Popover.Portal>\n </Popover.Root>\n )\n}\n",
|
|
20
|
+
"type": "registry:ui"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"type": "registry:ui"
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "calendar",
|
|
4
|
+
"title": "Calendar",
|
|
5
|
+
"description": "Grille de calendrier commune : navigation clavier, vue des mois, bornes `min` / `max`, aperçu d'une période au survol.",
|
|
6
|
+
"dependencies": [
|
|
7
|
+
"lucide-react@^1.71.0"
|
|
8
|
+
],
|
|
9
|
+
"registryDependencies": [
|
|
10
|
+
"@rc/calendar-days",
|
|
11
|
+
"@rc/icon-button",
|
|
12
|
+
"@rc/ui-labels",
|
|
13
|
+
"@rc/utils"
|
|
14
|
+
],
|
|
15
|
+
"files": [
|
|
16
|
+
{
|
|
17
|
+
"path": "src/ui/calendar.tsx",
|
|
18
|
+
"content": "import { ChevronLeft, ChevronRight } from \"lucide-react\"\nimport { type KeyboardEvent, useEffect, useRef, useState } from \"react\"\nimport { IconButton } from \"@/components/ui/icon-button\"\nimport { useUiLabels } from \"@/lib/ui-labels\"\nimport {\n addDays,\n addMonths,\n clampDay,\n formatDay,\n monthStart,\n monthWeeks,\n todayIso,\n weekStart,\n weekdayNames,\n} from \"@/lib/calendar-days\"\nimport { cn } from \"@/lib/utils\"\n\nexport interface CalendarSelection {\n from: string\n to: string\n}\n\nexport interface CalendarProps {\n initialMonth: string\n max?: string\n min?: string\n onPick: (day: string) => void\n previewFrom?: string | null\n selection: CalendarSelection\n}\n\nconst DAY_LABEL_FORMAT: Intl.DateTimeFormatOptions = {\n day: \"numeric\",\n month: \"long\",\n weekday: \"long\",\n year: \"numeric\",\n}\n\nexport const CALENDAR_ACTIVE_DAY_SELECTOR = '[data-day][tabindex=\"0\"]'\n\nconst KEY_MOVES: Record<string, (day: string) => string> = {\n ArrowDown: (day) => addDays(day, 7),\n ArrowLeft: (day) => addDays(day, -1),\n ArrowRight: (day) => addDays(day, 1),\n ArrowUp: (day) => addDays(day, -7),\n End: (day) => addDays(weekStart(day), 6),\n Home: weekStart,\n PageDown: (day) => addMonths(day, 1),\n PageUp: (day) => addMonths(day, -1),\n}\n\nfunction sortedDays(first: string, second: string): [string, string] {\n return first <= second ? [first, second] : [second, first]\n}\n\nfunction CalendarDays({\n max,\n min,\n month,\n onMonthChange,\n onPick,\n previewFrom,\n selection,\n}: Omit<CalendarProps, \"initialMonth\"> & {\n month: string\n onMonthChange: (month: string) => void\n}) {\n const { locale } = useUiLabels()\n const gridRef = useRef<HTMLDivElement>(null)\n const moveFocus = useRef(false)\n const [focusedDay, setFocusedDay] = useState<string | null>(null)\n const [hoveredDay, setHoveredDay] = useState<string | null>(null)\n\n const today = todayIso()\n const weeks = monthWeeks(month)\n const isDisabled = (day: string) => clampDay(day, min, max) !== day\n const selectable = weeks\n .flat()\n .filter((day) => monthStart(day) === month && !isDisabled(day))\n const activeDay = [\n focusedDay,\n previewFrom,\n selection.from,\n selection.to,\n today,\n ].find((day) => day && selectable.includes(day))\n const tabbableDay = activeDay ?? selectable[0]\n\n const previewTo = hoveredDay ?? focusedDay ?? previewFrom\n const [start, end] =\n previewFrom && previewTo\n ? sortedDays(previewFrom, previewTo)\n : [selection.from, selection.to]\n\n useEffect(() => {\n if (!moveFocus.current) {\n return\n }\n\n moveFocus.current = false\n gridRef.current\n ?.querySelector<HTMLElement>(CALENDAR_ACTIVE_DAY_SELECTOR)\n ?.focus()\n }, [tabbableDay])\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n const move = KEY_MOVES[event.key]\n\n if (!move || !tabbableDay) {\n return\n }\n\n event.preventDefault()\n\n const next = clampDay(move(tabbableDay), min, max)\n\n moveFocus.current = true\n setFocusedDay(next)\n onMonthChange(monthStart(next))\n }\n\n return (\n <div\n aria-label={formatDay(month, locale, { month: \"long\", year: \"numeric\" })}\n className=\"flex flex-col gap-y-0.5\"\n onKeyDown={handleKeyDown}\n onPointerLeave={() => setHoveredDay(null)}\n ref={gridRef}\n role=\"grid\"\n tabIndex={-1}\n >\n <div className=\"grid grid-cols-7\" role=\"row\">\n {weekdayNames(locale).map((weekday) => (\n <span\n aria-label={weekday.long}\n className=\"py-1 text-center text-xs font-medium text-ink-3\"\n key={weekday.long}\n role=\"columnheader\"\n >\n {weekday.short}\n </span>\n ))}\n </div>\n {weeks.map((week) => (\n <div className=\"grid grid-cols-7\" key={week[0]} role=\"row\">\n {week.map((day) => {\n const outside = monthStart(day) !== month\n const disabled = isDisabled(day)\n const isStart = day === start\n const isEnd = day === end\n const isEdge = isStart || isEnd\n const inBand = Boolean(start && end && day >= start && day <= end)\n\n return (\n <div\n aria-selected={isEdge || inBand}\n className={cn(\n inBand && start !== end && \"bg-accent-soft\",\n isStart && \"rounded-l-sm\",\n isEnd && \"rounded-r-sm\"\n )}\n key={day}\n role=\"gridcell\"\n >\n <button\n aria-current={day === today ? \"date\" : undefined}\n aria-label={formatDay(day, locale, DAY_LABEL_FORMAT)}\n className={cn(\n \"h-9 w-full rounded-sm text-sm font-medium tabular-nums transition-colors duration-150 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-accent pointer-coarse:h-11\",\n outside ? \"text-ink-3\" : \"text-ink\",\n day === today && \"underline underline-offset-4\",\n disabled && \"cursor-not-allowed opacity-30\",\n isEdge && \"bg-accent text-accent-ink\",\n !isEdge && !disabled && \"hover:bg-ink/5\"\n )}\n data-day={day}\n disabled={disabled}\n onClick={() => {\n setFocusedDay(day)\n onMonthChange(monthStart(day))\n onPick(day)\n }}\n onFocus={() => setFocusedDay(day)}\n onPointerEnter={() => setHoveredDay(day)}\n tabIndex={day === tabbableDay ? 0 : -1}\n type=\"button\"\n >\n {Number(day.slice(8))}\n </button>\n </div>\n )\n })}\n </div>\n ))}\n </div>\n )\n}\n\nfunction CalendarMonths({\n max,\n min,\n month,\n onMonthChange,\n year,\n}: {\n max?: string\n min?: string\n month: string\n onMonthChange: (month: string) => void\n year: string\n}) {\n const { locale } = useUiLabels()\n\n return (\n <div className=\"grid grid-cols-3 gap-1\">\n {Array.from({ length: 12 }, (_, index) => {\n const candidate = `${year}-${String(index + 1).padStart(2, \"0\")}-01`\n const disabled = Boolean(\n (max && candidate > max) || (min && addMonths(candidate, 1) <= min)\n )\n const selected = candidate === month\n\n return (\n <button\n aria-pressed={selected}\n className={cn(\n \"h-11 rounded-sm text-sm font-medium capitalize text-ink transition-colors duration-150 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-accent\",\n disabled && \"cursor-not-allowed opacity-30\",\n selected && \"bg-accent text-accent-ink\",\n !selected && !disabled && \"hover:bg-ink/5\"\n )}\n disabled={disabled}\n key={candidate}\n onClick={() => onMonthChange(candidate)}\n type=\"button\"\n >\n {formatDay(candidate, locale, { month: \"short\" })}\n </button>\n )\n })}\n </div>\n )\n}\n\nexport function Calendar({ initialMonth, ...props }: CalendarProps) {\n const labels = useUiLabels()\n const [month, setMonth] = useState(initialMonth)\n const [choosingMonth, setChoosingMonth] = useState(false)\n\n const step = choosingMonth ? 12 : 1\n const title = formatDay(\n month,\n labels.locale,\n choosingMonth ? { year: \"numeric\" } : { month: \"long\", year: \"numeric\" }\n )\n\n return (\n <div>\n <div className=\"mb-2 flex items-center justify-between\">\n <IconButton\n icon={ChevronLeft}\n label={choosingMonth ? labels.previousYear : labels.previousMonth}\n onClick={() => setMonth(addMonths(month, -step))}\n />\n <button\n aria-expanded={choosingMonth}\n aria-label={`${labels.chooseMonth} : ${title}`}\n className=\"min-h-9 rounded-sm px-3 text-sm font-semibold capitalize text-ink transition-colors duration-150 hover:bg-ink/5 focus-visible:outline-2 focus-visible:outline-accent\"\n onClick={() => setChoosingMonth(!choosingMonth)}\n type=\"button\"\n >\n {title}\n </button>\n <IconButton\n icon={ChevronRight}\n label={choosingMonth ? labels.nextYear : labels.nextMonth}\n onClick={() => setMonth(addMonths(month, step))}\n />\n </div>\n {choosingMonth ? (\n <CalendarMonths\n max={props.max}\n min={props.min}\n month={month}\n onMonthChange={(next) => {\n setMonth(next)\n setChoosingMonth(false)\n }}\n year={month.slice(0, 4)}\n />\n ) : (\n <CalendarDays {...props} month={month} onMonthChange={setMonth} />\n )}\n </div>\n )\n}\n",
|
|
19
|
+
"type": "registry:ui"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"type": "registry:ui"
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "callout",
|
|
4
|
+
"title": "Callout",
|
|
5
|
+
"description": "Encadré d'alerte ou d'information (danger, warn, success, info) avec titre, texte et action.",
|
|
6
|
+
"dependencies": [
|
|
7
|
+
"lucide-react@^1.71.0"
|
|
8
|
+
],
|
|
9
|
+
"registryDependencies": [
|
|
10
|
+
"@rc/utils"
|
|
11
|
+
],
|
|
12
|
+
"files": [
|
|
13
|
+
{
|
|
14
|
+
"path": "src/ui/callout.tsx",
|
|
15
|
+
"content": "import {\n CircleAlert,\n CircleCheck,\n Info,\n type LucideIcon,\n TriangleAlert,\n} from \"lucide-react\"\nimport type { ReactNode } from \"react\"\nimport { cn } from \"@/lib/utils\"\n\nexport type CalloutTone = \"danger\" | \"success\" | \"warn\" | \"info\"\n\nconst TONES: Record<\n CalloutTone,\n { box: string; icon: LucideIcon; iconClassName: string }\n> = {\n danger: {\n box: \"border-danger bg-danger-soft\",\n icon: CircleAlert,\n iconClassName: \"text-danger\",\n },\n info: {\n box: \"border-accent bg-accent-soft\",\n icon: Info,\n iconClassName: \"text-accent\",\n },\n success: {\n box: \"border-success bg-success-soft\",\n icon: CircleCheck,\n iconClassName: \"text-success\",\n },\n warn: {\n box: \"border-warn bg-warn-soft\",\n icon: TriangleAlert,\n iconClassName: \"text-warn\",\n },\n}\n\nexport interface CalloutProps {\n /** Sits under the text: a link or a small button that resolves the situation. */\n action?: ReactNode\n children?: ReactNode\n className?: string\n icon?: LucideIcon\n title: string\n tone?: CalloutTone\n}\n\nexport function Callout({\n tone = \"danger\",\n title,\n icon,\n action,\n className,\n children,\n}: CalloutProps) {\n const look = TONES[tone]\n const Icon = icon ?? look.icon\n\n return (\n <div\n className={cn(\n \"reveal flex gap-3 rounded-md border-l-4 px-4 py-3 text-sm\",\n look.box,\n className\n )}\n role={tone === \"danger\" ? \"alert\" : \"status\"}\n >\n <Icon\n aria-hidden=\"true\"\n className={cn(\"mt-0.5 size-4 shrink-0\", look.iconClassName)}\n />\n <div className=\"flex min-w-0 flex-col gap-1\">\n <p className=\"font-semibold leading-snug text-ink\">{title}</p>\n {children ? (\n <div className=\"leading-snug text-ink-2\">{children}</div>\n ) : null}\n {action ? (\n <div className=\"mt-1 flex flex-wrap gap-2\">{action}</div>\n ) : null}\n </div>\n </div>\n )\n}\n",
|
|
16
|
+
"type": "registry:ui"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"type": "registry:ui"
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "card",
|
|
4
|
+
"title": "Card",
|
|
5
|
+
"description": "Surface bordée avec en-tête optionnel (surtitre, titre, description, actions) et corps paddé ou `flush`.",
|
|
6
|
+
"registryDependencies": [
|
|
7
|
+
"@rc/eyebrow",
|
|
8
|
+
"@rc/utils"
|
|
9
|
+
],
|
|
10
|
+
"files": [
|
|
11
|
+
{
|
|
12
|
+
"path": "src/ui/card.tsx",
|
|
13
|
+
"content": "import type { ReactNode } from \"react\"\nimport { Eyebrow } from \"@/components/ui/eyebrow\"\nimport { cn } from \"@/lib/utils\"\n\nexport interface CardProps {\n actions?: ReactNode\n children: ReactNode\n className?: string\n description?: string\n eyebrow?: string\n /** No padding around the body: for a `List`, a table or a picture. */\n flush?: boolean\n title?: string\n}\n\nexport function Card({\n title,\n eyebrow,\n description,\n actions,\n flush = false,\n children,\n className,\n}: CardProps) {\n return (\n <section\n className={cn(\"rounded-lg border border-line bg-surface\", className)}\n >\n {title ? (\n <header className=\"flex flex-wrap items-start justify-between gap-x-6 gap-y-3 border-b border-line px-5 py-4 sm:px-6\">\n <div className=\"flex min-w-0 flex-col gap-1\">\n {eyebrow ? <Eyebrow tone=\"accent\">{eyebrow}</Eyebrow> : null}\n <h2 className=\"font-display text-lg font-semibold leading-tight text-ink\">\n {title}\n </h2>\n {description ? (\n <p className=\"text-sm leading-snug text-ink-2\">{description}</p>\n ) : null}\n </div>\n {actions ? (\n <div className=\"flex shrink-0 items-center gap-2\">{actions}</div>\n ) : null}\n </header>\n ) : null}\n <div className={flush ? undefined : \"px-5 py-5 sm:px-6\"}>{children}</div>\n </section>\n )\n}\n",
|
|
14
|
+
"type": "registry:ui"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"type": "registry:ui"
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "character-counter",
|
|
4
|
+
"title": "Character Counter",
|
|
5
|
+
"description": "Jauge de longueur avec zone idéale (titres et meta descriptions SEO), statut court/idéal/long.",
|
|
6
|
+
"registryDependencies": [
|
|
7
|
+
"@rc/utils"
|
|
8
|
+
],
|
|
9
|
+
"files": [
|
|
10
|
+
{
|
|
11
|
+
"path": "src/ui/character-counter.tsx",
|
|
12
|
+
"content": "import { cn } from \"@/lib/utils\"\n\nexport interface LengthLimits {\n idealMax: number\n idealMin: number\n max: number\n}\n\nexport type LengthStatus = \"empty\" | \"short\" | \"ideal\" | \"long\"\n\nexport const SEO_TITLE_LIMITS: LengthLimits = {\n idealMin: 50,\n idealMax: 60,\n max: 70,\n}\n\nexport const SEO_DESCRIPTION_LIMITS: LengthLimits = {\n idealMin: 140,\n idealMax: 160,\n max: 170,\n}\n\nexport function lengthStatus(\n length: number,\n limits: LengthLimits\n): LengthStatus {\n if (length === 0) {\n return \"empty\"\n }\n\n if (length < limits.idealMin) {\n return \"short\"\n }\n\n return length <= limits.idealMax ? \"ideal\" : \"long\"\n}\n\nconst STATUS_STYLES: Record<LengthStatus, { bar: string; text: string }> = {\n empty: { bar: \"bg-line-strong\", text: \"text-ink-3\" },\n short: { bar: \"bg-warn\", text: \"text-warn\" },\n ideal: { bar: \"bg-success\", text: \"text-success\" },\n long: { bar: \"bg-danger\", text: \"text-danger\" },\n}\n\nexport const FRENCH_LENGTH_LABELS: Record<LengthStatus, string> = {\n empty: \"automatique\",\n short: \"un peu court\",\n ideal: \"idéal\",\n long: \"risque d'être coupé\",\n}\n\nexport interface CharacterCounterProps {\n className?: string\n id?: string\n /** Words for each status; French by default. */\n labels?: Record<LengthStatus, string>\n length: number\n limits: LengthLimits\n}\n\n/** A length gauge with its ideal band, for a title or a meta description; link it to the field with `aria-describedby`. */\nexport function CharacterCounter({\n length,\n limits,\n labels = FRENCH_LENGTH_LABELS,\n className,\n id,\n}: CharacterCounterProps) {\n const status = lengthStatus(length, limits)\n const style = STATUS_STYLES[status]\n\n return (\n <span\n className={cn(\"mt-1.5 flex items-center gap-2.5 text-xs\", className)}\n id={id}\n >\n <span\n aria-hidden=\"true\"\n className=\"relative h-1 flex-1 overflow-hidden rounded-full bg-line\"\n >\n <span\n className=\"absolute inset-y-0 bg-success-soft\"\n style={{\n left: `${(limits.idealMin / limits.max) * 100}%`,\n width: `${((limits.idealMax - limits.idealMin) / limits.max) * 100}%`,\n }}\n />\n <span\n className={cn(\n \"absolute inset-y-0 left-0 rounded-full transition-[width,background-color] duration-300\",\n style.bar\n )}\n style={{ width: `${Math.min(100, (length / limits.max) * 100)}%` }}\n />\n </span>\n <span className={cn(\"shrink-0 font-medium tabular-nums\", style.text)}>\n {length} / {limits.max} · {labels[status]}\n </span>\n </span>\n )\n}\n",
|
|
13
|
+
"type": "registry:ui"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"type": "registry:ui"
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "checkbox",
|
|
4
|
+
"title": "Checkbox",
|
|
5
|
+
"description": "Case à cocher Base UI avec libellé et aide cliquables sur toute la ligne ; `CheckboxBox` pour la case seule.",
|
|
6
|
+
"dependencies": [
|
|
7
|
+
"@base-ui/react@^1.9.0",
|
|
8
|
+
"lucide-react@^1.71.0"
|
|
9
|
+
],
|
|
10
|
+
"registryDependencies": [
|
|
11
|
+
"@rc/field",
|
|
12
|
+
"@rc/utils"
|
|
13
|
+
],
|
|
14
|
+
"files": [
|
|
15
|
+
{
|
|
16
|
+
"path": "src/ui/checkbox.tsx",
|
|
17
|
+
"content": "import { Checkbox as BaseCheckbox } from \"@base-ui/react/checkbox\"\nimport { Check, Minus } from \"lucide-react\"\nimport type { ReactNode } from \"react\"\nimport { joinIds } from \"@/components/ui/field\"\nimport { cn } from \"@/lib/utils\"\n\nexport const CHOICE_ROW_CLASS_NAME =\n \"flex min-h-11 cursor-pointer items-start gap-3 py-2.5 has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-55 has-data-[disabled]:cursor-not-allowed has-data-[disabled]:opacity-55\"\n\nexport const CHOICE_TEXT_CLASS_NAME = \"text-sm font-medium leading-6 text-ink\"\n\nexport const CHOICE_HINT_CLASS_NAME = \"text-sm leading-snug text-ink-3\"\n\nexport interface CheckboxBoxProps {\n \"aria-describedby\"?: string\n \"aria-invalid\"?: boolean\n \"aria-label\"?: string\n checked?: boolean\n className?: string\n defaultChecked?: boolean\n disabled?: boolean\n id?: string\n indeterminate?: boolean\n name?: string\n onCheckedChange?: (checked: boolean) => void\n required?: boolean\n value?: string\n}\n\n/** The bare box, for a table row or a custom layout; give it an `aria-label` when no label wraps it. */\nexport function CheckboxBox({\n className,\n onCheckedChange,\n indeterminate,\n ...props\n}: CheckboxBoxProps) {\n return (\n <BaseCheckbox.Root\n className={cn(\n \"grid size-5 shrink-0 place-items-center rounded-sm border-2 border-line-strong bg-surface text-transparent\",\n \"transition-[background-color,border-color,color] duration-150 ease-out-expo\",\n \"data-[checked]:border-accent data-[checked]:bg-accent data-[checked]:text-accent-ink\",\n \"data-[indeterminate]:border-accent data-[indeterminate]:bg-accent data-[indeterminate]:text-accent-ink\",\n \"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent\",\n \"aria-invalid:border-danger\",\n className\n )}\n indeterminate={indeterminate}\n onCheckedChange={(checked) => onCheckedChange?.(checked)}\n {...props}\n >\n <BaseCheckbox.Indicator keepMounted>\n {indeterminate ? (\n <Minus aria-hidden=\"true\" className=\"size-3.5\" strokeWidth={3.5} />\n ) : (\n <Check aria-hidden=\"true\" className=\"size-3.5\" strokeWidth={3.5} />\n )}\n </BaseCheckbox.Indicator>\n </BaseCheckbox.Root>\n )\n}\n\nexport interface CheckboxProps extends Omit<CheckboxBoxProps, \"aria-label\"> {\n hint?: ReactNode\n label: ReactNode\n}\n\n/** A box centred on the first line of its label; the whole row toggles it. */\nexport function Checkbox({\n label,\n hint,\n className,\n id,\n \"aria-describedby\": describedBy,\n ...props\n}: CheckboxProps) {\n const hintId = hint && id ? `${id}-hint` : undefined\n\n return (\n <label\n className={cn(CHOICE_ROW_CLASS_NAME, className)}\n data-inline-control=\"\"\n htmlFor={id}\n >\n <span className=\"flex h-6 shrink-0 items-center\">\n <CheckboxBox\n aria-describedby={joinIds(describedBy, hintId)}\n id={id}\n {...props}\n />\n </span>\n <span className=\"flex min-w-0 flex-col gap-0.5\">\n <span className={CHOICE_TEXT_CLASS_NAME}>{label}</span>\n {hint ? (\n <span className={CHOICE_HINT_CLASS_NAME} id={hintId}>\n {hint}\n </span>\n ) : null}\n </span>\n </label>\n )\n}\n",
|
|
18
|
+
"type": "registry:ui"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"type": "registry:ui"
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "choice-cards",
|
|
4
|
+
"title": "Choice Cards",
|
|
5
|
+
"description": "Choix unique parmi quelques options qui méritent une phrase : boutons radio en grandes cartes.",
|
|
6
|
+
"dependencies": [
|
|
7
|
+
"lucide-react@^1.71.0"
|
|
8
|
+
],
|
|
9
|
+
"registryDependencies": [
|
|
10
|
+
"@rc/checkbox",
|
|
11
|
+
"@rc/label",
|
|
12
|
+
"@rc/utils"
|
|
13
|
+
],
|
|
14
|
+
"files": [
|
|
15
|
+
{
|
|
16
|
+
"path": "src/ui/choice-cards.tsx",
|
|
17
|
+
"content": "import type { LucideIcon } from \"lucide-react\"\nimport { type ReactNode, useId } from \"react\"\nimport { CHOICE_HINT_CLASS_NAME } from \"@/components/ui/checkbox\"\nimport { LABEL_CLASS_NAME } from \"@/components/ui/label\"\nimport { cn } from \"@/lib/utils\"\n\nexport interface ChoiceOption<Value extends string> {\n /** A short tag after the label, usually a `Badge`. */\n badge?: ReactNode\n disabled?: boolean\n hint?: ReactNode\n icon?: LucideIcon\n label: string\n value: Value\n}\n\nexport interface ChoiceCardsProps<Value extends string> {\n className?: string\n columns?: 1 | 2 | 3\n hideLabel?: boolean\n hint?: ReactNode\n label: string\n onChange: (value: Value) => void\n options: readonly ChoiceOption<Value>[]\n value: Value\n}\n\nconst COLUMNS = {\n 1: \"grid-cols-1\",\n 2: \"sm:grid-cols-2\",\n 3: \"sm:grid-cols-3\",\n} as const\n\n/** One choice among a few that each deserve a sentence: radio buttons as big tappable cards. */\nexport function ChoiceCards<Value extends string>({\n label,\n hint,\n options,\n value,\n onChange,\n columns = 2,\n hideLabel = false,\n className,\n}: ChoiceCardsProps<Value>) {\n const name = useId()\n const hintId = hint ? `${name}-hint` : undefined\n\n return (\n <fieldset aria-describedby={hintId} className={cn(\"min-w-0\", className)}>\n <legend className={hideLabel ? \"sr-only\" : cn(LABEL_CLASS_NAME, \"mb-2\")}>\n {label}\n </legend>\n <div className={cn(\"grid gap-2\", COLUMNS[columns])}>\n {options.map((option) => {\n const Icon = option.icon\n const optionHintId = option.hint\n ? `${name}-${option.value}-hint`\n : undefined\n\n return (\n <label\n className={cn(\n \"relative flex min-h-14 cursor-pointer items-start gap-3 rounded-md border border-line bg-surface px-3.5 py-3\",\n \"transition-[border-color,box-shadow,background-color] duration-200 ease-out-expo hover:border-line-strong\",\n \"has-checked:border-accent has-checked:bg-accent-soft has-checked:ring-1 has-checked:ring-accent\",\n \"has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-accent\",\n \"has-disabled:cursor-not-allowed has-disabled:opacity-55\"\n )}\n key={option.value}\n >\n <span className=\"relative flex h-6 shrink-0 items-center\">\n <input\n aria-describedby={optionHintId}\n checked={option.value === value}\n className=\"peer sr-only\"\n disabled={option.disabled}\n name={name}\n onChange={() => onChange(option.value)}\n type=\"radio\"\n value={option.value}\n />\n <span\n aria-hidden=\"true\"\n className=\"grid size-5 place-items-center rounded-full border-2 border-line-strong bg-surface transition-colors duration-150 peer-checked:border-accent [&>span]:scale-0 [&>span]:transition-transform [&>span]:duration-200 [&>span]:ease-out-expo peer-checked:[&>span]:scale-100\"\n >\n <span className=\"size-2.5 rounded-full bg-accent\" />\n </span>\n </span>\n <span className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n <span className=\"flex items-center gap-2 text-sm font-medium leading-6 text-ink\">\n {Icon ? (\n <Icon\n aria-hidden=\"true\"\n className=\"size-4 shrink-0 text-ink-3\"\n />\n ) : null}\n {option.label}\n {option.badge ? (\n <span className=\"ml-auto flex shrink-0\">\n {option.badge}\n </span>\n ) : null}\n </span>\n {option.hint ? (\n <span className={CHOICE_HINT_CLASS_NAME} id={optionHintId}>\n {option.hint}\n </span>\n ) : null}\n </span>\n </label>\n )\n })}\n </div>\n {hint ? (\n <p className={cn(CHOICE_HINT_CLASS_NAME, \"mt-2\")} id={hintId}>\n {hint}\n </p>\n ) : null}\n </fieldset>\n )\n}\n",
|
|
18
|
+
"type": "registry:ui"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"type": "registry:ui"
|
|
22
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "color-tag",
|
|
4
|
+
"title": "Color Tag",
|
|
5
|
+
"description": "Pastille de couleur choisie par l'utilisateur devant un libellé (catégorie, équipe), en ligne ou en puce.",
|
|
6
|
+
"registryDependencies": [
|
|
7
|
+
"@rc/utils"
|
|
8
|
+
],
|
|
9
|
+
"files": [
|
|
10
|
+
{
|
|
11
|
+
"path": "src/ui/color-tag.tsx",
|
|
12
|
+
"content": "import type { ReactNode } from \"react\"\nimport { cn } from \"@/lib/utils\"\n\n/** A user-chosen colour next to what it marks: a category, a team, a season. */\nexport function ColorTag({\n color,\n children,\n chip = false,\n className,\n}: {\n /** A stored colour value or a `var(--color-…)` token. */\n color: string\n children: ReactNode\n /** Framed like a badge, for a tag among other tags. */\n chip?: boolean\n className?: string\n}) {\n return (\n <span\n className={cn(\n \"inline-flex min-w-0 items-center gap-2\",\n chip &&\n \"h-7 rounded-sm border border-line bg-surface px-2 text-xs font-medium\",\n className\n )}\n >\n <span\n aria-hidden=\"true\"\n className=\"size-3 shrink-0 rounded-full\"\n style={{ backgroundColor: color }}\n />\n <span className=\"min-w-0 truncate\">{children}</span>\n </span>\n )\n}\n",
|
|
13
|
+
"type": "registry:ui"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"type": "registry:ui"
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "combobox",
|
|
4
|
+
"title": "Combobox",
|
|
5
|
+
"description": "Champ texte libre avec suggestions groupées (Base UI Autocomplete), filtre insensible aux accents, correspondance surlignée.",
|
|
6
|
+
"dependencies": [
|
|
7
|
+
"@base-ui/react@^1.9.0",
|
|
8
|
+
"lucide-react@^1.71.0"
|
|
9
|
+
],
|
|
10
|
+
"registryDependencies": [
|
|
11
|
+
"@rc/input",
|
|
12
|
+
"@rc/select",
|
|
13
|
+
"@rc/ui-labels",
|
|
14
|
+
"@rc/utils"
|
|
15
|
+
],
|
|
16
|
+
"files": [
|
|
17
|
+
{
|
|
18
|
+
"path": "src/ui/combobox.tsx",
|
|
19
|
+
"content": "import { Autocomplete } from \"@base-ui/react/autocomplete\"\nimport { ChevronDown } from \"lucide-react\"\nimport { type ReactNode, useMemo } from \"react\"\nimport { CONTROL_CLASS_NAME, useControlAria } from \"@/components/ui/input\"\nimport {\n SELECT_GROUP_LABEL_CLASS_NAME,\n SELECT_ITEM_CLASS_NAME,\n SELECT_POPUP_CLASS_NAME,\n} from \"@/components/ui/select\"\nimport { useUiLabels } from \"@/lib/ui-labels\"\nimport { cn } from \"@/lib/utils\"\n\nexport interface ComboboxGroup {\n label: string\n options: readonly string[]\n}\n\ninterface SuggestionGroup {\n items: readonly string[]\n label: string\n}\n\nexport interface ComboboxProps {\n \"aria-describedby\"?: string\n \"aria-invalid\"?: boolean\n \"aria-label\"?: string\n className?: string\n disabled?: boolean\n /** Shown when nothing matches; free text stays valid anyway. */\n emptyLabel?: string\n icon?: ReactNode\n id?: string\n maxLength?: number\n name?: string\n onValueChange: (value: string) => void\n placeholder?: string\n required?: boolean\n suggestions: readonly string[] | readonly ComboboxGroup[]\n value: string\n}\n\nexport function foldText(text: string): string {\n return text.normalize(\"NFD\").replace(/\\p{M}/gu, \"\").toLowerCase()\n}\n\nfunction isGroupedSuggestions(\n suggestions: ComboboxProps[\"suggestions\"]\n): suggestions is readonly ComboboxGroup[] {\n const [first] = suggestions\n\n return typeof first === \"object\"\n}\n\nfunction HighlightedMatch({ text, query }: { text: string; query: string }) {\n const start = query ? foldText(text).indexOf(foldText(query)) : -1\n\n if (start < 0) {\n return <>{text}</>\n }\n\n const end = start + query.length\n\n return (\n <>\n {text.slice(0, start)}\n <mark className=\"bg-transparent font-semibold text-accent-deep\">\n {text.slice(start, end)}\n </mark>\n {text.slice(end)}\n </>\n )\n}\n\n/** A text input with autocompletion: suggestions narrow while typing, accents ignored, any free text stays valid. */\nexport function Combobox({\n suggestions,\n value,\n onValueChange,\n placeholder,\n emptyLabel,\n icon,\n id,\n name,\n disabled,\n required,\n maxLength,\n className,\n \"aria-label\": ariaLabel,\n ...ariaProps\n}: ComboboxProps) {\n const labels = useUiLabels()\n const aria = useControlAria({ id, ...ariaProps })\n const grouped = isGroupedSuggestions(suggestions)\n const query = value.trim()\n\n const groups = useMemo(\n (): SuggestionGroup[] =>\n isGroupedSuggestions(suggestions)\n ? suggestions.map((group) => ({\n items: group.options,\n label: group.label,\n }))\n : [{ items: suggestions, label: \"\" }],\n [suggestions]\n )\n\n const renderItem = (option: string) => (\n <Autocomplete.Item\n className={SELECT_ITEM_CLASS_NAME}\n key={option}\n value={option}\n >\n <span className=\"min-w-0 flex-1 truncate\">\n <HighlightedMatch query={query} text={option} />\n </span>\n </Autocomplete.Item>\n )\n\n return (\n <Autocomplete.Root\n disabled={disabled}\n items={groups}\n locale={labels.locale}\n name={name}\n onValueChange={(next) => onValueChange(next)}\n openOnInputClick\n required={required}\n value={value}\n >\n <div className={cn(\"relative\", className)}>\n {icon ? (\n <span\n aria-hidden=\"true\"\n className=\"pointer-events-none absolute top-1/2 left-3 flex -translate-y-1/2 text-ink-4\"\n >\n {icon}\n </span>\n ) : null}\n <Autocomplete.Input\n aria-label={ariaLabel}\n autoComplete=\"off\"\n className={cn(\n CONTROL_CLASS_NAME,\n \"pr-10 placeholder:text-ink-3\",\n icon ? \"pl-9\" : \"pl-3\"\n )}\n maxLength={maxLength}\n placeholder={placeholder}\n spellCheck={false}\n {...aria}\n />\n <Autocomplete.Trigger\n aria-label={labels.showSuggestions}\n className=\"group/trigger absolute top-1/2 right-1 grid size-8 -translate-y-1/2 place-items-center rounded-sm text-ink-3 hover:bg-ink/5 hover:text-ink\"\n >\n <ChevronDown\n aria-hidden=\"true\"\n className=\"size-4 transition-transform duration-200 group-data-[popup-open]/trigger:rotate-180\"\n />\n </Autocomplete.Trigger>\n </div>\n <Autocomplete.Portal>\n <Autocomplete.Positioner\n align=\"start\"\n className=\"z-70 outline-none\"\n collisionPadding={12}\n sideOffset={6}\n >\n <Autocomplete.Popup className={SELECT_POPUP_CLASS_NAME}>\n {emptyLabel ? (\n <Autocomplete.Empty className=\"px-3 py-3 text-sm text-ink-3 empty:hidden\">\n {emptyLabel}\n </Autocomplete.Empty>\n ) : null}\n <Autocomplete.List className=\"overflow-y-auto overscroll-contain py-1 empty:hidden\">\n {(group: SuggestionGroup) => (\n <Autocomplete.Group items={group.items} key={group.label}>\n {grouped ? (\n <Autocomplete.GroupLabel\n className={SELECT_GROUP_LABEL_CLASS_NAME}\n >\n {group.label}\n </Autocomplete.GroupLabel>\n ) : null}\n <Autocomplete.Collection>\n {(option: string) => renderItem(option)}\n </Autocomplete.Collection>\n </Autocomplete.Group>\n )}\n </Autocomplete.List>\n </Autocomplete.Popup>\n </Autocomplete.Positioner>\n </Autocomplete.Portal>\n </Autocomplete.Root>\n )\n}\n",
|
|
20
|
+
"type": "registry:ui"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"type": "registry:ui"
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "confirm-button",
|
|
4
|
+
"title": "Confirm Button",
|
|
5
|
+
"description": "Action destructive confirmée par un second clic dans les 4 s, sans boîte de dialogue ; texte ou icône seule.",
|
|
6
|
+
"dependencies": [
|
|
7
|
+
"lucide-react@^1.71.0"
|
|
8
|
+
],
|
|
9
|
+
"registryDependencies": [
|
|
10
|
+
"@rc/button",
|
|
11
|
+
"@rc/icon-button",
|
|
12
|
+
"@rc/tooltip",
|
|
13
|
+
"@rc/ui-labels",
|
|
14
|
+
"@rc/utils"
|
|
15
|
+
],
|
|
16
|
+
"files": [
|
|
17
|
+
{
|
|
18
|
+
"path": "src/ui/confirm-button.tsx",
|
|
19
|
+
"content": "import { Check, type LucideIcon } from \"lucide-react\"\nimport { type ReactNode, useEffect, useState } from \"react\"\nimport { Button, type ButtonProps } from \"@/components/ui/button\"\nimport { iconButtonSizeClassName } from \"@/components/ui/icon-button\"\nimport { Tooltip } from \"@/components/ui/tooltip\"\nimport { useUiLabels } from \"@/lib/ui-labels\"\nimport { cn } from \"@/lib/utils\"\n\nconst CONFIRM_WINDOW_MS = 4000\n\ninterface ConfirmButtonBaseProps extends Omit<\n ButtonProps,\n \"aria-label\" | \"children\" | \"onClick\"\n> {\n confirmLabel?: string\n /** What the second tap will do, shown while the button waits for it. */\n description?: string\n onConfirm: () => void\n}\n\nexport type ConfirmButtonProps = ConfirmButtonBaseProps &\n (\n | { children: ReactNode; icon?: never; label?: never }\n | { children?: never; icon: LucideIcon; label: string }\n )\n\n/** A destructive action asks for a second tap instead of a browser dialog. */\nexport function ConfirmButton({\n onConfirm,\n confirmLabel,\n description,\n children,\n icon: Icon,\n label,\n className,\n size = \"md\",\n variant = \"danger\",\n ...props\n}: ConfirmButtonProps) {\n const labels = useUiLabels()\n const [armed, setArmed] = useState(false)\n const confirmText = confirmLabel ?? labels.confirm\n const announced = description ? `${confirmText}. ${description}` : confirmText\n\n useEffect(() => {\n if (!armed) {\n return\n }\n\n const timer = setTimeout(() => setArmed(false), CONFIRM_WINDOW_MS)\n\n return () => clearTimeout(timer)\n }, [armed])\n\n const iconOnly = Icon !== undefined && label !== undefined\n\n let content: ReactNode = children ?? null\n\n if (iconOnly) {\n content = armed ? (\n <Check aria-hidden=\"true\" className=\"size-4\" />\n ) : (\n <Icon aria-hidden=\"true\" className=\"size-4\" />\n )\n } else if (armed) {\n content = confirmText\n }\n\n const button = (\n <Button\n {...props}\n className={cn(\n iconOnly && iconButtonSizeClassName(size === \"sm\" ? \"sm\" : \"md\"),\n className\n )}\n onClick={() => {\n if (armed) {\n setArmed(false)\n onConfirm()\n } else {\n setArmed(true)\n }\n }}\n size={size}\n variant={armed ? \"destructive\" : variant}\n >\n {content}\n </Button>\n )\n\n const status = (\n <span className=\"sr-only\" role=\"status\">\n {armed ? announced : \"\"}\n </span>\n )\n\n if (iconOnly) {\n return (\n <>\n <Tooltip label={armed ? announced : label}>{button}</Tooltip>\n {status}\n </>\n )\n }\n\n if (!description) {\n return (\n <>\n {button}\n {status}\n </>\n )\n }\n\n return (\n <span className=\"inline-flex flex-wrap items-center gap-x-3 gap-y-1\">\n {button}\n {armed ? (\n <span aria-hidden=\"true\" className=\"text-sm text-ink-2\">\n {description}\n </span>\n ) : null}\n {status}\n </span>\n )\n}\n",
|
|
20
|
+
"type": "registry:ui"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"type": "registry:ui"
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "confirm-dialog",
|
|
4
|
+
"title": "Confirm Dialog",
|
|
5
|
+
"description": "Boîte de confirmation Base UI AlertDialog (danger ou neutre) qui attend un `onConfirm` asynchrone avant de se fermer.",
|
|
6
|
+
"dependencies": [
|
|
7
|
+
"@base-ui/react@^1.9.0",
|
|
8
|
+
"lucide-react@^1.71.0"
|
|
9
|
+
],
|
|
10
|
+
"registryDependencies": [
|
|
11
|
+
"@rc/button",
|
|
12
|
+
"@rc/ui-labels",
|
|
13
|
+
"@rc/utils"
|
|
14
|
+
],
|
|
15
|
+
"files": [
|
|
16
|
+
{
|
|
17
|
+
"path": "src/ui/confirm-dialog.tsx",
|
|
18
|
+
"content": "import { AlertDialog } from \"@base-ui/react/alert-dialog\"\nimport { TriangleAlert } from \"lucide-react\"\nimport { type ReactElement, type ReactNode, useState } from \"react\"\nimport { Button } from \"@/components/ui/button\"\nimport { useUiLabels } from \"@/lib/ui-labels\"\nimport { cn } from \"@/lib/utils\"\n\nexport interface ConfirmDialogProps {\n cancelLabel?: string\n /** Extra content between the description and the buttons: a reason field, a summary. */\n children?: ReactNode\n confirmLabel?: string\n description: ReactNode\n /** Awaited before closing; a rejected promise keeps the dialog open (report the error yourself). */\n onConfirm: () => unknown\n onOpenChange?: (open: boolean) => void\n open?: boolean\n title: string\n /** Opens the dialog; leave it out and drive `open` yourself. */\n trigger?: ReactElement<Record<string, unknown>>\n /** `danger` for what cannot be undone. */\n tone?: \"danger\" | \"neutral\"\n}\n\n/** Asks before an action that deserves a sentence of warning; for a quick delete in a row, prefer `ConfirmButton`. */\nexport function ConfirmDialog({\n trigger,\n title,\n description,\n confirmLabel,\n cancelLabel,\n tone = \"danger\",\n open,\n onOpenChange,\n onConfirm,\n children,\n}: ConfirmDialogProps) {\n const labels = useUiLabels()\n const [innerOpen, setInnerOpen] = useState(false)\n const [busy, setBusy] = useState(false)\n const isOpen = open ?? innerOpen\n\n const setOpen = (next: boolean) => {\n if (busy) {\n return\n }\n\n setInnerOpen(next)\n onOpenChange?.(next)\n }\n\n const confirm = async () => {\n setBusy(true)\n\n try {\n await onConfirm()\n setInnerOpen(false)\n onOpenChange?.(false)\n } catch {\n // The caller reported the failure; the dialog stays open for another try.\n } finally {\n setBusy(false)\n }\n }\n\n return (\n <AlertDialog.Root onOpenChange={setOpen} open={isOpen}>\n {trigger ? <AlertDialog.Trigger render={trigger} /> : null}\n <AlertDialog.Portal>\n <AlertDialog.Backdrop className=\"fixed inset-0 z-40 bg-night/50 backdrop-blur-xs transition-opacity duration-200 data-[ending-style]:opacity-0 data-[starting-style]:opacity-0\" />\n <AlertDialog.Popup className=\"fixed top-1/2 left-1/2 z-50 flex w-[calc(100vw-2rem)] max-w-md -translate-x-1/2 -translate-y-1/2 flex-col gap-4 rounded-lg bg-surface p-5 shadow-2xl outline-none transition-[opacity,transform] duration-200 ease-out-expo data-[ending-style]:scale-96 data-[ending-style]:opacity-0 data-[starting-style]:scale-96 data-[starting-style]:opacity-0\">\n <div className=\"flex gap-4\">\n {tone === \"danger\" ? (\n <span className=\"grid size-10 shrink-0 place-items-center rounded-full bg-danger-soft text-danger\">\n <TriangleAlert aria-hidden=\"true\" className=\"size-5\" />\n </span>\n ) : null}\n <div className=\"flex min-w-0 flex-col gap-1.5\">\n <AlertDialog.Title className=\"font-display text-lg font-semibold leading-tight text-ink\">\n {title}\n </AlertDialog.Title>\n <AlertDialog.Description className=\"text-sm leading-snug text-ink-2\">\n {description}\n </AlertDialog.Description>\n </div>\n </div>\n {children}\n <div\n className={cn(\n \"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end\",\n tone === \"danger\" && \"sm:pl-14\"\n )}\n >\n <AlertDialog.Close\n disabled={busy}\n render={<Button variant=\"ghost\" />}\n >\n {cancelLabel ?? labels.cancel}\n </AlertDialog.Close>\n <Button\n loading={busy}\n onClick={confirm}\n variant={tone === \"danger\" ? \"destructive\" : \"primary\"}\n >\n {confirmLabel ?? labels.confirm}\n </Button>\n </div>\n </AlertDialog.Popup>\n </AlertDialog.Portal>\n </AlertDialog.Root>\n )\n}\n",
|
|
19
|
+
"type": "registry:ui"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"type": "registry:ui"
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "copy-button",
|
|
4
|
+
"title": "Copy Button",
|
|
5
|
+
"description": "Copie une valeur dans le presse-papiers et l'indique deux secondes ; bouton texte ou icône seule.",
|
|
6
|
+
"dependencies": [
|
|
7
|
+
"lucide-react@^1.71.0"
|
|
8
|
+
],
|
|
9
|
+
"registryDependencies": [
|
|
10
|
+
"@rc/button",
|
|
11
|
+
"@rc/icon-button",
|
|
12
|
+
"@rc/ui-labels",
|
|
13
|
+
"@rc/use-copy-to-clipboard",
|
|
14
|
+
"@rc/utils"
|
|
15
|
+
],
|
|
16
|
+
"files": [
|
|
17
|
+
{
|
|
18
|
+
"path": "src/ui/copy-button.tsx",
|
|
19
|
+
"content": "import { Check, Copy } from \"lucide-react\"\nimport {\n Button,\n type ButtonSize,\n type ButtonVariant,\n} from \"@/components/ui/button\"\nimport { IconButton } from \"@/components/ui/icon-button\"\nimport { useCopyToClipboard } from \"@/hooks/use-copy-to-clipboard\"\nimport { useUiLabels } from \"@/lib/ui-labels\"\nimport { cn } from \"@/lib/utils\"\n\nexport interface CopyButtonProps {\n className?: string\n copiedLabel?: string\n /** Icon only, the label in a tooltip: for a value already shown next to it. */\n iconOnly?: boolean\n label?: string\n onCopied?: () => void\n size?: ButtonSize\n value: string\n variant?: ButtonVariant\n}\n\nexport function CopyButton({\n value,\n label,\n copiedLabel,\n iconOnly = false,\n onCopied,\n size = \"sm\",\n variant = iconOnly ? \"ghost\" : \"secondary\",\n className,\n}: CopyButtonProps) {\n const labels = useUiLabels()\n const { copied, copy } = useCopyToClipboard()\n const idleText = label ?? labels.copy\n const doneText = copiedLabel ?? labels.copied\n\n const handleCopy = async () => {\n if (await copy(value)) {\n onCopied?.()\n }\n }\n\n if (iconOnly) {\n return (\n <IconButton\n className={cn(copied && \"text-success hover:text-success\", className)}\n icon={copied ? Check : Copy}\n label={copied ? doneText : idleText}\n onClick={handleCopy}\n size={size === \"sm\" ? \"sm\" : \"md\"}\n variant={variant}\n />\n )\n }\n\n const Icon = copied ? Check : Copy\n\n return (\n <Button\n aria-live=\"polite\"\n className={className}\n onClick={handleCopy}\n size={size}\n variant={variant}\n >\n <Icon\n aria-hidden=\"true\"\n className={cn(\"size-4\", copied && \"text-success\")}\n />\n {copied ? doneText : idleText}\n </Button>\n )\n}\n",
|
|
20
|
+
"type": "registry:ui"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"type": "registry:ui"
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "date-picker",
|
|
4
|
+
"title": "Date Picker",
|
|
5
|
+
"description": "Choix d'un jour dans le calendrier commun, valeur ISO, bornes `min` / `max`, effacement optionnel, feuille basse sur mobile.",
|
|
6
|
+
"dependencies": [
|
|
7
|
+
"lucide-react@^1.71.0"
|
|
8
|
+
],
|
|
9
|
+
"registryDependencies": [
|
|
10
|
+
"@rc/button",
|
|
11
|
+
"@rc/calendar",
|
|
12
|
+
"@rc/calendar-days",
|
|
13
|
+
"@rc/calendar-popover",
|
|
14
|
+
"@rc/ui-labels"
|
|
15
|
+
],
|
|
16
|
+
"files": [
|
|
17
|
+
{
|
|
18
|
+
"path": "src/ui/date-picker.tsx",
|
|
19
|
+
"content": "import { CalendarDays } from \"lucide-react\"\nimport { useState } from \"react\"\nimport { Button } from \"@/components/ui/button\"\nimport { Calendar } from \"@/components/ui/calendar\"\nimport {\n type CalendarControlProps,\n CalendarPopover,\n} from \"@/components/ui/calendar-popover\"\nimport { useUiLabels } from \"@/lib/ui-labels\"\nimport { clampDay, formatDay, monthStart, todayIso } from \"@/lib/calendar-days\"\n\nexport const DEFAULT_DAY_FORMAT: Intl.DateTimeFormatOptions = {\n day: \"numeric\",\n month: \"short\",\n year: \"numeric\",\n}\n\nexport interface DatePickerProps extends CalendarControlProps {\n clearable?: boolean\n format?: Intl.DateTimeFormatOptions\n max?: string\n min?: string\n onValueChange: (value: string) => void\n value: string\n}\n\nexport function DatePicker({\n clearable = false,\n format = DEFAULT_DAY_FORMAT,\n max,\n min,\n onValueChange,\n placeholder,\n value,\n ...control\n}: DatePickerProps) {\n const labels = useUiLabels()\n const [open, setOpen] = useState(false)\n\n const choose = (day: string) => {\n onValueChange(day)\n setOpen(false)\n }\n\n return (\n <CalendarPopover\n {...control}\n icon={CalendarDays}\n onOpenChange={setOpen}\n open={open}\n placeholder={placeholder ?? labels.pickDate}\n summary={value ? formatDay(value, labels.locale, format) : null}\n >\n <Calendar\n initialMonth={monthStart(clampDay(value || todayIso(), min, max))}\n max={max}\n min={min}\n onPick={choose}\n selection={{ from: value, to: value }}\n />\n {clearable && value ? (\n <div className=\"mt-3 flex justify-end border-t border-line pt-3\">\n <Button onClick={() => choose(\"\")} size=\"sm\" variant=\"ghost\">\n {labels.clearDate}\n </Button>\n </div>\n ) : null}\n </CalendarPopover>\n )\n}\n",
|
|
20
|
+
"type": "registry:ui"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"type": "registry:ui"
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "date-range-picker",
|
|
4
|
+
"title": "Date Range Picker",
|
|
5
|
+
"description": "Choix d'une période dans le calendrier commun (`onValueChange`, valeur vide possible, nom accessible par `aria-label` ou `Field`), heures, fin ouverte et effacement optionnels, feuille basse sur mobile.",
|
|
6
|
+
"dependencies": [
|
|
7
|
+
"@base-ui/react@^1.9.0",
|
|
8
|
+
"lucide-react@^1.71.0"
|
|
9
|
+
],
|
|
10
|
+
"registryDependencies": [
|
|
11
|
+
"@rc/button",
|
|
12
|
+
"@rc/calendar",
|
|
13
|
+
"@rc/calendar-days",
|
|
14
|
+
"@rc/calendar-popover",
|
|
15
|
+
"@rc/checkbox",
|
|
16
|
+
"@rc/date-picker",
|
|
17
|
+
"@rc/input",
|
|
18
|
+
"@rc/ui-labels"
|
|
19
|
+
],
|
|
20
|
+
"files": [
|
|
21
|
+
{
|
|
22
|
+
"path": "src/ui/date-range-picker.tsx",
|
|
23
|
+
"content": "import type { Popover } from \"@base-ui/react/popover\"\nimport { CalendarRange } from \"lucide-react\"\nimport { useId, useState } from \"react\"\nimport { Button } from \"@/components/ui/button\"\nimport { Calendar } from \"@/components/ui/calendar\"\nimport {\n type CalendarControlProps,\n CalendarPopover,\n} from \"@/components/ui/calendar-popover\"\nimport { Checkbox } from \"@/components/ui/checkbox\"\nimport { DEFAULT_DAY_FORMAT } from \"@/components/ui/date-picker\"\nimport { Input } from \"@/components/ui/input\"\nimport { useUiLabels } from \"@/lib/ui-labels\"\nimport { clampDay, formatDay, monthStart, todayIso } from \"@/lib/calendar-days\"\n\nexport interface DateRange {\n /** An ISO day, YYYY-MM-DD, or empty while nothing is picked. */\n from: string\n /** Null when the period has no end yet. */\n to: string | null\n}\n\nexport interface RangeTimes {\n from: string\n to: string\n}\n\nexport interface DateRangePickerProps extends CalendarControlProps {\n allowOpenEnd?: boolean\n clearable?: boolean\n max?: string\n min?: string\n onTimesChange?: (times: RangeTimes) => void\n onValueChange: (range: DateRange) => void\n summaryFormat?: Intl.DateTimeFormatOptions\n times?: RangeTimes\n value: DateRange\n}\n\nexport const EMPTY_DATE_RANGE: DateRange = { from: \"\", to: null }\n\nfunction rangeSummary(\n { from, to }: DateRange,\n format: (day: string) => string,\n times: RangeTimes | undefined\n): string | null {\n if (!from && !to) {\n return null\n }\n\n if (from === to && !times) {\n return format(from)\n }\n\n const start = from ? format(from) : \"…\"\n const end = to ? format(to) : \"…\"\n\n return times\n ? `${start} · ${times.from} → ${end} · ${times.to}`\n : `${start} → ${end}`\n}\n\n/** One control for a whole period: the first tap sets the start, the second the end. */\nexport function DateRangePicker({\n allowOpenEnd = false,\n clearable = false,\n max,\n min,\n onTimesChange,\n onValueChange,\n placeholder,\n summaryFormat = DEFAULT_DAY_FORMAT,\n times,\n value,\n ...control\n}: DateRangePickerProps) {\n const labels = useUiLabels()\n const baseId = useId()\n const [open, setOpen] = useState(false)\n const [anchor, setAnchor] = useState<string | null>(null)\n const [openEnd, setOpenEnd] = useState(false)\n\n const hasValue = Boolean(value.from || value.to)\n const firstDay = value.from || value.to || todayIso()\n\n const handleOpenChange = (\n next: boolean,\n details: Popover.Root.ChangeEventDetails\n ) => {\n setOpen(next)\n\n if (next) {\n setOpenEnd(Boolean(value.from) && value.to === null)\n\n return\n }\n\n if (anchor && details.reason !== \"escape-key\") {\n onValueChange({ from: anchor, to: anchor })\n }\n\n setAnchor(null)\n }\n\n const commit = (range: DateRange) => {\n onValueChange(range)\n setAnchor(null)\n\n if (!times) {\n setOpen(false)\n }\n }\n\n const pick = (day: string) => {\n if (openEnd) {\n commit({ from: day, to: null })\n\n return\n }\n\n if (!anchor) {\n setAnchor(day)\n\n return\n }\n\n commit(day < anchor ? { from: day, to: anchor } : { from: anchor, to: day })\n }\n\n const toggleOpenEnd = (checked: boolean) => {\n const from = anchor ?? value.from\n\n setOpenEnd(checked)\n setAnchor(null)\n\n if (from) {\n onValueChange({ from, to: checked ? null : from })\n }\n }\n\n const confirm = () => {\n if (anchor) {\n onValueChange({ from: anchor, to: anchor })\n setAnchor(null)\n }\n\n setOpen(false)\n }\n\n const clear = () => {\n onValueChange(EMPTY_DATE_RANGE)\n setAnchor(null)\n setOpen(false)\n }\n\n return (\n <CalendarPopover\n {...control}\n icon={CalendarRange}\n onOpenChange={handleOpenChange}\n open={open}\n placeholder={placeholder ?? labels.pickPeriod}\n summary={rangeSummary(\n value,\n (day) => formatDay(day, labels.locale, summaryFormat),\n times\n )}\n >\n <Calendar\n initialMonth={monthStart(clampDay(firstDay, min, max))}\n max={max}\n min={min}\n onPick={pick}\n previewFrom={anchor}\n selection={{ from: value.from, to: value.to ?? \"\" }}\n />\n {times && onTimesChange ? (\n <div className=\"mt-3 grid grid-cols-2 gap-2 border-t border-line pt-3\">\n <label\n className=\"flex flex-col gap-1.5 text-sm font-medium text-ink-2\"\n htmlFor={`${baseId}-start-time`}\n >\n {labels.startTime}\n <Input\n id={`${baseId}-start-time`}\n onChange={(event) =>\n onTimesChange({ ...times, from: event.target.value })\n }\n type=\"time\"\n value={times.from}\n />\n </label>\n <label\n className=\"flex flex-col gap-1.5 text-sm font-medium text-ink-2\"\n htmlFor={`${baseId}-end-time`}\n >\n {labels.endTime}\n <Input\n disabled={!value.to}\n id={`${baseId}-end-time`}\n onChange={(event) =>\n onTimesChange({ ...times, to: event.target.value })\n }\n type=\"time\"\n value={times.to}\n />\n </label>\n </div>\n ) : null}\n <div className=\"mt-3 flex flex-col gap-2 border-t border-line pt-3\">\n {allowOpenEnd ? (\n <Checkbox\n checked={openEnd}\n className=\"py-0\"\n id={`${baseId}-open-end`}\n label={labels.openEnd}\n onCheckedChange={toggleOpenEnd}\n />\n ) : null}\n <div className=\"flex min-h-9 items-center justify-between gap-2\">\n <span aria-live=\"polite\" className=\"text-xs text-ink-3\">\n {anchor ? labels.pickEnd : labels.pickStart}\n </span>\n <div className=\"flex shrink-0 items-center gap-1\">\n {clearable && (hasValue || anchor) ? (\n <Button onClick={clear} size=\"sm\" variant=\"ghost\">\n {labels.clearDate}\n </Button>\n ) : null}\n {times || allowOpenEnd ? (\n <Button onClick={confirm} size=\"sm\" variant=\"primary\">\n {labels.ok}\n </Button>\n ) : null}\n </div>\n </div>\n </div>\n </CalendarPopover>\n )\n}\n",
|
|
24
|
+
"type": "registry:ui"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"type": "registry:ui"
|
|
28
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "detail-header",
|
|
4
|
+
"title": "Detail Header",
|
|
5
|
+
"description": "En-tête de page de détail : surtitre, badges, titre, sous-titre, média et actions (deux par ligne sur mobile).",
|
|
6
|
+
"registryDependencies": [
|
|
7
|
+
"@rc/eyebrow"
|
|
8
|
+
],
|
|
9
|
+
"files": [
|
|
10
|
+
{
|
|
11
|
+
"path": "src/ui/detail-header.tsx",
|
|
12
|
+
"content": "import type { ReactNode } from \"react\"\nimport { Eyebrow } from \"@/components/ui/eyebrow\"\n\n/** The top of a detail page: tags, the thing's name, a line about it, its actions (two per row on a phone). */\nexport function DetailHeader({\n eyebrow,\n badges,\n title,\n subtitle,\n media,\n actions,\n}: {\n actions?: ReactNode\n badges?: ReactNode\n eyebrow?: string\n /** A photo or an avatar before the text. */\n media?: ReactNode\n subtitle?: ReactNode\n title: string\n}) {\n return (\n <header className=\"reveal mb-6 flex flex-col gap-5 sm:mb-8 lg:flex-row lg:items-end lg:justify-between\">\n <div className=\"flex min-w-0 items-start gap-4 sm:gap-5\">\n {media ? <div className=\"shrink-0\">{media}</div> : null}\n <div className=\"flex min-w-0 flex-col gap-2\">\n {eyebrow || badges ? (\n <div className=\"flex flex-wrap items-center gap-2\">\n {eyebrow ? <Eyebrow>{eyebrow}</Eyebrow> : null}\n {badges}\n </div>\n ) : null}\n <h1 className=\"break-words font-display text-3xl font-semibold leading-tight tracking-tight text-ink\">\n {title}\n </h1>\n {subtitle ? (\n <div className=\"leading-snug text-ink-2\">{subtitle}</div>\n ) : null}\n </div>\n </div>\n {actions ? (\n <div className=\"grid shrink-0 grid-cols-2 gap-2 sm:flex sm:flex-wrap sm:justify-end [&>*:last-child:nth-child(odd)]:col-span-2\">\n {actions}\n </div>\n ) : null}\n </header>\n )\n}\n",
|
|
13
|
+
"type": "registry:ui"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"type": "registry:ui"
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "detail-row",
|
|
4
|
+
"title": "Detail Row",
|
|
5
|
+
"description": "Ligne libellé / valeur alignée pour les faits d'une carte.",
|
|
6
|
+
"registryDependencies": [
|
|
7
|
+
"@rc/utils"
|
|
8
|
+
],
|
|
9
|
+
"files": [
|
|
10
|
+
{
|
|
11
|
+
"path": "src/ui/detail-row.tsx",
|
|
12
|
+
"content": "import type { ReactNode } from \"react\"\nimport { cn } from \"@/lib/utils\"\n\nexport function DetailRow({\n label,\n children,\n className,\n}: {\n children: ReactNode\n className?: string\n label: string\n}) {\n return (\n <div\n className={cn(\n \"flex items-baseline justify-between gap-4 py-1.5 text-sm\",\n className\n )}\n >\n <span className=\"text-ink-3\">{label}</span>\n <span className=\"text-right font-medium text-ink\">{children}</span>\n </div>\n )\n}\n",
|
|
13
|
+
"type": "registry:ui"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"type": "registry:ui"
|
|
17
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "dev-inbox-api",
|
|
4
|
+
"title": "Dev Inbox API",
|
|
5
|
+
"description": "Côté serveur : plugin Elysia `devRoutes()` (404 hors ENVIRONMENT=local), boîte mail de dev sur R2 `dev-inbox/` et expéditeur qui capture les e-mails au lieu de les envoyer.",
|
|
6
|
+
"dependencies": [
|
|
7
|
+
"elysia@^1.4.31"
|
|
8
|
+
],
|
|
9
|
+
"registryDependencies": [
|
|
10
|
+
"@rc/dev-tools-contract"
|
|
11
|
+
],
|
|
12
|
+
"files": [
|
|
13
|
+
{
|
|
14
|
+
"path": "src/lib/dev-inbox/store.ts",
|
|
15
|
+
"content": "import {\n DEV_INBOX_KEY_PREFIX,\n type DevInboxMessage,\n type DevInboxSummary,\n type OutgoingEmail,\n} from \"../dev-tools-contract\"\n\nexport interface DevInboxStore {\n clear: () => Promise<void>\n list: () => Promise<DevInboxSummary[]>\n markRead: (id: string) => Promise<void>\n read: (id: string) => Promise<DevInboxMessage | null>\n record: (message: OutgoingEmail) => Promise<DevInboxSummary>\n}\n\n/** The slice of an R2 bucket the inbox uses, so this file needs no Workers types; an `R2Bucket` fits it. */\nexport interface DevInboxBucket {\n delete(keys: string | string[]): Promise<void>\n get(key: string): Promise<{ text(): Promise<string> } | null>\n list(options: {\n cursor?: string\n include?: (\"customMetadata\" | \"httpMetadata\")[]\n prefix: string\n }): Promise<{\n cursor?: string\n objects: { customMetadata?: Record<string, string>; key: string }[]\n truncated: boolean\n }>\n put(\n key: string,\n value: string,\n options?: {\n customMetadata?: Record<string, string>\n httpMetadata?: { contentType?: string }\n }\n ): Promise<unknown>\n}\n\nconst MAX_MESSAGES = 100\n\nfunction summaryOf(message: DevInboxMessage): DevInboxSummary {\n const { id, readAt, receivedAt, subject, to } = message\n\n return { id, readAt, receivedAt, subject, to }\n}\n\nfunction newestFirst(a: DevInboxSummary, b: DevInboxSummary): number {\n return b.receivedAt.localeCompare(a.receivedAt)\n}\n\nfunction toMessage(email: OutgoingEmail): DevInboxMessage {\n return {\n html: email.html ?? null,\n id: crypto.randomUUID(),\n readAt: null,\n receivedAt: new Date().toISOString(),\n subject: email.subject,\n text: email.text,\n to: email.to,\n }\n}\n\nfunction isSummary(value: unknown): value is DevInboxSummary {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as DevInboxSummary).id === \"string\" &&\n typeof (value as DevInboxSummary).receivedAt === \"string\"\n )\n}\n\nfunction parseSummary(raw: string | undefined): DevInboxSummary | null {\n if (!raw) {\n return null\n }\n\n try {\n const parsed: unknown = JSON.parse(raw)\n\n return isSummary(parsed) ? parsed : null\n } catch {\n return null\n }\n}\n\n/** Local R2 (miniflare) survives dev-server restarts; the `dev-inbox/` prefix never exists outside a dev machine. */\nexport function createR2DevInbox(bucket: DevInboxBucket): DevInboxStore {\n const keyOf = (id: string) => `${DEV_INBOX_KEY_PREFIX}${id}.json`\n\n const write = (message: DevInboxMessage) =>\n bucket.put(keyOf(message.id), JSON.stringify(message), {\n customMetadata: { summary: JSON.stringify(summaryOf(message)) },\n httpMetadata: { contentType: \"application/json\" },\n })\n\n const list = async (): Promise<DevInboxSummary[]> => {\n const summaries: DevInboxSummary[] = []\n let cursor: string | undefined\n\n do {\n const page = await bucket.list({\n cursor,\n include: [\"customMetadata\"],\n prefix: DEV_INBOX_KEY_PREFIX,\n })\n\n for (const object of page.objects) {\n const summary = parseSummary(object.customMetadata?.summary)\n\n if (summary) {\n summaries.push(summary)\n }\n }\n\n cursor = page.truncated ? page.cursor : undefined\n } while (cursor)\n\n return summaries.sort(newestFirst)\n }\n\n const read = async (id: string): Promise<DevInboxMessage | null> => {\n const object = await bucket.get(keyOf(id))\n\n return object ? (JSON.parse(await object.text()) as DevInboxMessage) : null\n }\n\n const remove = async (summaries: DevInboxSummary[]) => {\n if (summaries.length > 0) {\n await bucket.delete(summaries.map((summary) => keyOf(summary.id)))\n }\n }\n\n return {\n clear: async () => remove(await list()),\n list,\n markRead: async (id) => {\n const message = await read(id)\n\n if (message && !message.readAt) {\n await write({ ...message, readAt: new Date().toISOString() })\n }\n },\n read,\n record: async (email) => {\n const message = toMessage(email)\n\n await write(message)\n await remove((await list()).slice(MAX_MESSAGES))\n\n return summaryOf(message)\n },\n }\n}\n\n/** For `bun test` and scripts run outside workerd. */\nexport function createMemoryDevInbox(): DevInboxStore {\n const messages = new Map<string, DevInboxMessage>()\n\n const list = async () =>\n [...messages.values()].map(summaryOf).sort(newestFirst)\n\n return {\n clear: async () => messages.clear(),\n list,\n markRead: async (id) => {\n const message = messages.get(id)\n\n if (message && !message.readAt) {\n messages.set(id, { ...message, readAt: new Date().toISOString() })\n }\n },\n read: async (id) => messages.get(id) ?? null,\n record: async (email) => {\n const message = toMessage(email)\n\n messages.set(message.id, message)\n\n for (const stale of (await list()).slice(MAX_MESSAGES)) {\n messages.delete(stale.id)\n }\n\n return summaryOf(message)\n },\n }\n}\n",
|
|
16
|
+
"type": "registry:lib",
|
|
17
|
+
"target": "~/src/lib/dev-inbox/store.ts"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"path": "src/lib/dev-inbox/routes.ts",
|
|
21
|
+
"content": "import { Elysia } from \"elysia\"\nimport type { DevInboxStore } from \"./store\"\nimport {\n DEV_ROUTES,\n type DevEnvironment,\n type DevOk,\n} from \"../dev-tools-contract\"\n\nconst HTML_ESCAPES: Record<string, string> = {\n '\"': \""\",\n \"&\": \"&\",\n \"'\": \"'\",\n \"<\": \"<\",\n \">\": \">\",\n}\n\nfunction escapeHtml(text: string): string {\n return text.replace(/[&<>\"']/g, (char) => HTML_ESCAPES[char] ?? char)\n}\n\nexport interface DevRoutesOptions {\n /** Gets the request, so labels can follow its language. */\n environment: (request: Request) => DevEnvironment | Promise<DevEnvironment>\n inbox: () => DevInboxStore | Promise<DevInboxStore>\n /** True only when `ENVIRONMENT=local`; read per request so a deployed Worker never answers. */\n isLocal: () => boolean\n /** Mounted under the API's own prefix: \"/dev\" under \"/api\" gives \"/api/dev\". */\n prefix?: string\n}\n\nconst OK: DevOk = { ok: true }\n\n/** The `/api/dev/*` routes the dev toolbar reads; outside local they do not exist, not even as a refusal. */\nexport function devRoutes({\n environment,\n inbox,\n isLocal,\n prefix = \"/dev\",\n}: DevRoutesOptions) {\n return new Elysia({ aot: false, name: \"rc-dev-routes\", prefix })\n .onBeforeHandle(({ status }) => {\n if (!isLocal()) {\n return status(404, { message: \"Not Found\" })\n }\n })\n .get(DEV_ROUTES.environment, ({ request }) => environment(request))\n .get(DEV_ROUTES.inbox, async () => (await inbox()).list())\n .delete(DEV_ROUTES.inbox, async () => {\n await (await inbox()).clear()\n\n return OK\n })\n .get(\"/inbox/:id\", async ({ params, status }) => {\n const message = await (await inbox()).read(params.id)\n\n return message ?? status(404, { message: \"Not Found\" })\n })\n .get(\"/inbox/:id/html\", async ({ params, status }) => {\n const message = await (await inbox()).read(params.id)\n\n if (!message) {\n return status(404, \"Not Found\")\n }\n\n const html =\n message.html ??\n `<pre style=\"font-family:ui-monospace,monospace;white-space:pre-wrap;padding:1rem\">${escapeHtml(message.text)}</pre>`\n\n return new Response(html, {\n headers: { \"content-type\": \"text/html; charset=utf-8\" },\n })\n })\n .post(\"/inbox/:id/read\", async ({ params }) => {\n await (await inbox()).markRead(params.id)\n\n return OK\n })\n}\n",
|
|
22
|
+
"type": "registry:lib",
|
|
23
|
+
"target": "~/src/lib/dev-inbox/routes.ts"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"path": "src/lib/dev-inbox/send.ts",
|
|
27
|
+
"content": "import type { DevInboxStore } from \"./store\"\nimport type { OutgoingEmail } from \"../dev-tools-contract\"\n\nexport type SendEmail = (email: OutgoingEmail) => Promise<void>\n\n/** The slice of the Cloudflare Email Service binding (`send_email`) a sender needs. */\nexport interface EmailBinding {\n send(message: {\n from: { email: string; name: string }\n html?: string\n subject: string\n text: string\n to: string\n }): Promise<unknown>\n}\n\nexport interface DevAwareSenderOptions {\n /** Sends for real: usually `bindingDeliver(env.EMAIL, { email, name })`. */\n deliver: SendEmail\n inbox: () => DevInboxStore | Promise<DevInboxStore>\n isLocal: () => boolean\n log?: (line: string) => void\n}\n\n/** Locally nothing leaves the machine: each e-mail lands in the dev inbox (R2 `dev-inbox/`) and the log. */\nexport function createDevAwareSender({\n deliver,\n inbox,\n isLocal,\n log = console.info,\n}: DevAwareSenderOptions): SendEmail {\n return async (email) => {\n if (isLocal()) {\n await (await inbox()).record(email)\n log(`[email] to=${email.to} subject=\"${email.subject}\" → dev inbox`)\n\n return\n }\n\n await deliver(email)\n }\n}\n\nexport function bindingDeliver(\n binding: EmailBinding,\n from: { email: string; name: string }\n): SendEmail {\n return async (email) => {\n await binding.send({\n from,\n html: email.html,\n subject: email.subject,\n text: email.text,\n to: email.to,\n })\n }\n}\n",
|
|
28
|
+
"type": "registry:lib",
|
|
29
|
+
"target": "~/src/lib/dev-inbox/send.ts"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"type": "registry:lib"
|
|
33
|
+
}
|