@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,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CAPTCHA_HEADER,
|
|
3
|
+
TURNSTILE_DUMMY_TOKEN,
|
|
4
|
+
} from "@tpl/shared/edge/turnstile"
|
|
5
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query"
|
|
6
|
+
import { Send } from "lucide-react"
|
|
7
|
+
import { toast } from "sonner"
|
|
8
|
+
import { useDevToolsClient } from "@/components/dev-toolbar/dev-toolbar-context"
|
|
9
|
+
import { DEV_ACTION_CLASS_NAME } from "@/components/dev-toolbar/dev-toolbar-environment-panel"
|
|
10
|
+
import { api, unwrap } from "@/lib/api"
|
|
11
|
+
import { authClient } from "@/lib/auth-client"
|
|
12
|
+
|
|
13
|
+
const ACCOUNTS_QUERY_KEY = ["dev-tools", "accounts"] as const
|
|
14
|
+
|
|
15
|
+
export function DevSignInLinks() {
|
|
16
|
+
const client = useDevToolsClient()
|
|
17
|
+
const queryClient = useQueryClient()
|
|
18
|
+
|
|
19
|
+
const accounts = useQuery({
|
|
20
|
+
queryKey: ACCOUNTS_QUERY_KEY,
|
|
21
|
+
queryFn: () => unwrap(api.dev.accounts.get()),
|
|
22
|
+
throwOnError: false,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
async function sendSignInLink(email: string) {
|
|
26
|
+
const { error } = await authClient.signIn.magicLink({
|
|
27
|
+
email,
|
|
28
|
+
callbackURL: "/",
|
|
29
|
+
errorCallbackURL: "/login",
|
|
30
|
+
fetchOptions: { headers: { [CAPTCHA_HEADER]: TURNSTILE_DUMMY_TOKEN } },
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
if (error) {
|
|
34
|
+
toast.error(error.message ?? "Envoi impossible.")
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
toast.success(`Lien envoyé à ${email} : ouvrez la boîte mail.`)
|
|
39
|
+
await queryClient.invalidateQueries({ queryKey: client.queryKeys.inbox })
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<>
|
|
44
|
+
{accounts.data?.adminEmails.map((email) => (
|
|
45
|
+
<button
|
|
46
|
+
key={email}
|
|
47
|
+
type="button"
|
|
48
|
+
onClick={() => void sendSignInLink(email)}
|
|
49
|
+
className={DEV_ACTION_CLASS_NAME}
|
|
50
|
+
>
|
|
51
|
+
<Send aria-hidden="true" className="size-4" />
|
|
52
|
+
Lien de connexion · {email}
|
|
53
|
+
</button>
|
|
54
|
+
))}
|
|
55
|
+
</>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createContext, useContext } from "react"
|
|
2
|
+
import {
|
|
3
|
+
createDevToolsClient,
|
|
4
|
+
type DevToolsClient,
|
|
5
|
+
} from "@/lib/dev-tools-client"
|
|
6
|
+
|
|
7
|
+
export const DevToolsClientContext = createContext<DevToolsClient>(
|
|
8
|
+
createDevToolsClient()
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
export function useDevToolsClient(): DevToolsClient {
|
|
12
|
+
return useContext(DevToolsClientContext)
|
|
13
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query"
|
|
2
|
+
import { DatabaseZap, ExternalLink } from "lucide-react"
|
|
3
|
+
import type { ReactNode } from "react"
|
|
4
|
+
import { useDevToolsClient } from "@/components/dev-toolbar/dev-toolbar-context"
|
|
5
|
+
import { Skeleton } from "@/components/ui/skeleton"
|
|
6
|
+
|
|
7
|
+
export const DEV_ACTION_CLASS_NAME =
|
|
8
|
+
"inline-flex min-h-10 items-center gap-2 rounded-md border border-night-line px-3 text-sm font-medium text-chalk transition-colors hover:bg-chalk hover:text-ink focus-visible:outline-2 focus-visible:outline-chalk disabled:opacity-50"
|
|
9
|
+
|
|
10
|
+
function Row({ label, children }: { children: ReactNode; label: string }) {
|
|
11
|
+
return (
|
|
12
|
+
<div className="flex items-baseline justify-between gap-4 border-b border-night-line py-2.5 text-sm">
|
|
13
|
+
<dt className="shrink-0 text-xs font-semibold uppercase tracking-wider text-chalk-2">
|
|
14
|
+
{label}
|
|
15
|
+
</dt>
|
|
16
|
+
<dd className="min-w-0 truncate text-right font-mono text-xs">
|
|
17
|
+
{children}
|
|
18
|
+
</dd>
|
|
19
|
+
</div>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const ROW_PLACEHOLDERS = ["a", "b", "c", "d", "e"]
|
|
24
|
+
|
|
25
|
+
export function DevToolbarEnvironmentPanel({
|
|
26
|
+
actions,
|
|
27
|
+
}: {
|
|
28
|
+
actions?: ReactNode
|
|
29
|
+
}) {
|
|
30
|
+
const client = useDevToolsClient()
|
|
31
|
+
const queryClient = useQueryClient()
|
|
32
|
+
const environment = useQuery({
|
|
33
|
+
queryFn: client.environment,
|
|
34
|
+
queryKey: client.queryKeys.environment,
|
|
35
|
+
retry: false,
|
|
36
|
+
throwOnError: false,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
if (environment.isError) {
|
|
40
|
+
return (
|
|
41
|
+
<p className="p-6 text-center text-sm text-chalk-2">
|
|
42
|
+
Les routes {client.base} ne répondent pas : vérifiez que
|
|
43
|
+
ENVIRONMENT=local et que le plugin de dev est monté.
|
|
44
|
+
</p>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!environment.data) {
|
|
49
|
+
return (
|
|
50
|
+
<div className="flex flex-col p-4">
|
|
51
|
+
{ROW_PLACEHOLDERS.map((key) => (
|
|
52
|
+
<div
|
|
53
|
+
className="flex items-center justify-between gap-4 border-b border-night-line py-3"
|
|
54
|
+
key={key}
|
|
55
|
+
>
|
|
56
|
+
<Skeleton className="h-3 w-24" tone="dark" />
|
|
57
|
+
<Skeleton className="h-3.5 w-40 max-w-[50%]" tone="dark" />
|
|
58
|
+
</div>
|
|
59
|
+
))}
|
|
60
|
+
</div>
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const env = environment.data
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div className="flex h-full min-h-0 flex-col gap-6 overflow-y-auto p-4">
|
|
68
|
+
<dl>
|
|
69
|
+
<Row label="Environnement">
|
|
70
|
+
<span className="rounded-sm bg-accent px-1.5 py-0.5 text-accent-ink">
|
|
71
|
+
{env.environment}
|
|
72
|
+
</span>
|
|
73
|
+
</Row>
|
|
74
|
+
{env.entries.map((entry) => (
|
|
75
|
+
<Row key={entry.label} label={entry.label}>
|
|
76
|
+
{entry.value}
|
|
77
|
+
</Row>
|
|
78
|
+
))}
|
|
79
|
+
</dl>
|
|
80
|
+
<div className="flex flex-wrap gap-2">
|
|
81
|
+
{actions}
|
|
82
|
+
<button
|
|
83
|
+
className={DEV_ACTION_CLASS_NAME}
|
|
84
|
+
onClick={() => queryClient.clear()}
|
|
85
|
+
type="button"
|
|
86
|
+
>
|
|
87
|
+
<DatabaseZap aria-hidden="true" className="size-4" />
|
|
88
|
+
Vider le cache
|
|
89
|
+
</button>
|
|
90
|
+
{env.links.map((link) => (
|
|
91
|
+
<a
|
|
92
|
+
className={DEV_ACTION_CLASS_NAME}
|
|
93
|
+
href={link.href}
|
|
94
|
+
key={link.href}
|
|
95
|
+
rel="noopener"
|
|
96
|
+
target="_blank"
|
|
97
|
+
>
|
|
98
|
+
<ExternalLink aria-hidden="true" className="size-4" />
|
|
99
|
+
{link.label}
|
|
100
|
+
</a>
|
|
101
|
+
))}
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
)
|
|
105
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { DevInboxSummary } from "@/lib/dev-tools-contract"
|
|
2
|
+
import { cn } from "@/lib/utils"
|
|
3
|
+
|
|
4
|
+
const TIME_FORMAT = new Intl.DateTimeFormat("fr-FR", {
|
|
5
|
+
hour: "2-digit",
|
|
6
|
+
minute: "2-digit",
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
export interface DevToolbarInboxListProps {
|
|
10
|
+
messages: DevInboxSummary[]
|
|
11
|
+
onSelectMessage: (id: string) => void
|
|
12
|
+
selectedMessageId: string | null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function DevToolbarInboxList({
|
|
16
|
+
messages,
|
|
17
|
+
onSelectMessage,
|
|
18
|
+
selectedMessageId,
|
|
19
|
+
}: DevToolbarInboxListProps) {
|
|
20
|
+
return (
|
|
21
|
+
<ul className="min-h-0 flex-1 overflow-y-auto">
|
|
22
|
+
{messages.map((message) => (
|
|
23
|
+
<li key={message.id}>
|
|
24
|
+
<button
|
|
25
|
+
className={cn(
|
|
26
|
+
"flex w-full flex-col gap-1 border-b border-night-line px-4 py-3 text-left transition-colors hover:bg-night-2 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-chalk",
|
|
27
|
+
message.id === selectedMessageId && "bg-night-2"
|
|
28
|
+
)}
|
|
29
|
+
onClick={() => onSelectMessage(message.id)}
|
|
30
|
+
type="button"
|
|
31
|
+
>
|
|
32
|
+
<span className="flex w-full items-center gap-2">
|
|
33
|
+
{message.readAt ? null : (
|
|
34
|
+
<span
|
|
35
|
+
aria-hidden="true"
|
|
36
|
+
className="size-1.5 shrink-0 rounded-full bg-accent"
|
|
37
|
+
/>
|
|
38
|
+
)}
|
|
39
|
+
<span className="min-w-0 flex-1 truncate text-sm font-semibold">
|
|
40
|
+
{message.subject}
|
|
41
|
+
</span>
|
|
42
|
+
<span className="shrink-0 text-xs tabular-nums text-chalk-2">
|
|
43
|
+
{TIME_FORMAT.format(new Date(message.receivedAt))}
|
|
44
|
+
</span>
|
|
45
|
+
</span>
|
|
46
|
+
<span className="w-full truncate text-xs text-chalk-2">
|
|
47
|
+
{message.to}
|
|
48
|
+
</span>
|
|
49
|
+
</button>
|
|
50
|
+
</li>
|
|
51
|
+
))}
|
|
52
|
+
</ul>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query"
|
|
2
|
+
import { ArrowLeft, ExternalLink } from "lucide-react"
|
|
3
|
+
import { useEffect, useMemo } from "react"
|
|
4
|
+
import { useDevToolsClient } from "@/components/dev-toolbar/dev-toolbar-context"
|
|
5
|
+
import { Skeleton } from "@/components/ui/skeleton"
|
|
6
|
+
import { Tooltip } from "@/components/ui/tooltip"
|
|
7
|
+
import { extractActionLinks } from "@/lib/dev-inbox-links"
|
|
8
|
+
|
|
9
|
+
const TIME_FORMAT = new Intl.DateTimeFormat("fr-FR", {
|
|
10
|
+
dateStyle: "short",
|
|
11
|
+
timeStyle: "short",
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export interface DevToolbarInboxMessageProps {
|
|
15
|
+
id: string
|
|
16
|
+
onClose: () => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function DevToolbarInboxMessage({
|
|
20
|
+
id,
|
|
21
|
+
onClose,
|
|
22
|
+
}: DevToolbarInboxMessageProps) {
|
|
23
|
+
const client = useDevToolsClient()
|
|
24
|
+
const queryClient = useQueryClient()
|
|
25
|
+
const message = useQuery({
|
|
26
|
+
queryFn: () => client.inboxMessage(id),
|
|
27
|
+
queryKey: client.queryKeys.inboxMessage(id),
|
|
28
|
+
retry: false,
|
|
29
|
+
throwOnError: false,
|
|
30
|
+
})
|
|
31
|
+
const mail = message.data
|
|
32
|
+
const actionLinks = useMemo(
|
|
33
|
+
() => (mail ? extractActionLinks(mail.html, mail.text) : []),
|
|
34
|
+
[mail]
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (mail && !mail.readAt) {
|
|
39
|
+
void client
|
|
40
|
+
.markRead(mail.id)
|
|
41
|
+
.then(() =>
|
|
42
|
+
queryClient.invalidateQueries({ queryKey: client.queryKeys.inbox })
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
}, [mail, client, queryClient])
|
|
46
|
+
|
|
47
|
+
if (!mail) {
|
|
48
|
+
return (
|
|
49
|
+
<div className="flex flex-col">
|
|
50
|
+
<div className="flex flex-col gap-2 border-b border-night-line p-3">
|
|
51
|
+
<Skeleton className="h-3.5 w-56 max-w-full" tone="dark" />
|
|
52
|
+
<Skeleton className="h-3 w-40 max-w-full" tone="dark" />
|
|
53
|
+
</div>
|
|
54
|
+
<div className="flex flex-col gap-2 p-4">
|
|
55
|
+
<Skeleton className="h-3 w-full" tone="dark" />
|
|
56
|
+
<Skeleton className="h-3 w-11/12" tone="dark" />
|
|
57
|
+
<Skeleton className="h-3 w-2/3" tone="dark" />
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<article className="flex min-h-0 flex-col">
|
|
65
|
+
<header className="flex items-start gap-2 border-b border-night-line p-3">
|
|
66
|
+
<Tooltip label="Retour à la liste">
|
|
67
|
+
<button
|
|
68
|
+
className="grid size-9 shrink-0 place-items-center rounded-sm text-chalk-2 hover:text-chalk md:hidden"
|
|
69
|
+
onClick={onClose}
|
|
70
|
+
type="button"
|
|
71
|
+
>
|
|
72
|
+
<ArrowLeft aria-hidden="true" className="size-4" />
|
|
73
|
+
</button>
|
|
74
|
+
</Tooltip>
|
|
75
|
+
<div className="flex min-w-0 flex-1 flex-col gap-0.5">
|
|
76
|
+
<h3 className="truncate text-sm font-semibold">{mail.subject}</h3>
|
|
77
|
+
<p className="truncate text-xs text-chalk-2">
|
|
78
|
+
À {mail.to} · {TIME_FORMAT.format(new Date(mail.receivedAt))}
|
|
79
|
+
</p>
|
|
80
|
+
</div>
|
|
81
|
+
</header>
|
|
82
|
+
{actionLinks.length > 0 ? (
|
|
83
|
+
<div className="flex flex-wrap gap-2 border-b border-night-line p-3">
|
|
84
|
+
{actionLinks.map((link) => (
|
|
85
|
+
<a
|
|
86
|
+
className="inline-flex min-h-9 items-center gap-2 rounded-md bg-accent px-3 text-sm font-medium text-accent-ink transition-colors hover:bg-accent-deep"
|
|
87
|
+
href={link.href}
|
|
88
|
+
key={link.href}
|
|
89
|
+
>
|
|
90
|
+
<ExternalLink aria-hidden="true" className="size-4" />
|
|
91
|
+
{link.label}
|
|
92
|
+
</a>
|
|
93
|
+
))}
|
|
94
|
+
</div>
|
|
95
|
+
) : null}
|
|
96
|
+
<iframe
|
|
97
|
+
className="min-h-0 w-full flex-1 bg-surface"
|
|
98
|
+
sandbox="allow-popups allow-popups-to-escape-sandbox"
|
|
99
|
+
src={client.inboxMessageHtmlUrl(mail.id)}
|
|
100
|
+
title={mail.subject}
|
|
101
|
+
/>
|
|
102
|
+
</article>
|
|
103
|
+
)
|
|
104
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
|
2
|
+
import { Inbox, Trash2 } from "lucide-react"
|
|
3
|
+
import { toast } from "sonner"
|
|
4
|
+
import { useDevToolsClient } from "@/components/dev-toolbar/dev-toolbar-context"
|
|
5
|
+
import { DevToolbarInboxList } from "@/components/dev-toolbar/dev-toolbar-inbox-list"
|
|
6
|
+
import { DevToolbarInboxMessage } from "@/components/dev-toolbar/dev-toolbar-inbox-message"
|
|
7
|
+
import { Skeleton } from "@/components/ui/skeleton"
|
|
8
|
+
import { Spinner } from "@/components/ui/spinner"
|
|
9
|
+
import { Tooltip } from "@/components/ui/tooltip"
|
|
10
|
+
import type { DevInbox } from "@/hooks/use-dev-inbox"
|
|
11
|
+
import { cn } from "@/lib/utils"
|
|
12
|
+
|
|
13
|
+
const MESSAGE_PLACEHOLDERS = ["a", "b", "c", "d"]
|
|
14
|
+
|
|
15
|
+
export interface DevToolbarInboxPanelProps {
|
|
16
|
+
inbox: DevInbox
|
|
17
|
+
onSelectMessage: (id: string | null) => void
|
|
18
|
+
selectedMessageId: string | null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function DevToolbarInboxPanel({
|
|
22
|
+
inbox,
|
|
23
|
+
onSelectMessage,
|
|
24
|
+
selectedMessageId,
|
|
25
|
+
}: DevToolbarInboxPanelProps) {
|
|
26
|
+
const client = useDevToolsClient()
|
|
27
|
+
const queryClient = useQueryClient()
|
|
28
|
+
const clear = useMutation({
|
|
29
|
+
mutationFn: client.clearInbox,
|
|
30
|
+
onError: () => toast.error("Impossible de vider la boîte."),
|
|
31
|
+
onSuccess: async () => {
|
|
32
|
+
onSelectMessage(null)
|
|
33
|
+
await queryClient.invalidateQueries({ queryKey: client.queryKeys.inbox })
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
const visibleId = inbox.messages.some(
|
|
37
|
+
(message) => message.id === selectedMessageId
|
|
38
|
+
)
|
|
39
|
+
? selectedMessageId
|
|
40
|
+
: null
|
|
41
|
+
|
|
42
|
+
if (inbox.query.isError) {
|
|
43
|
+
return (
|
|
44
|
+
<p className="p-6 text-center text-sm text-chalk-2">
|
|
45
|
+
La boîte de dev ne répond pas ({client.base}/inbox) : vérifiez que
|
|
46
|
+
ENVIRONMENT=local et que le plugin de dev est monté.
|
|
47
|
+
</p>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (inbox.query.isPending) {
|
|
52
|
+
return (
|
|
53
|
+
<div className="flex flex-col md:w-72 md:border-r md:border-night-line">
|
|
54
|
+
{MESSAGE_PLACEHOLDERS.map((key) => (
|
|
55
|
+
<div
|
|
56
|
+
className="flex flex-col gap-2 border-b border-night-line px-4 py-3"
|
|
57
|
+
key={key}
|
|
58
|
+
>
|
|
59
|
+
<Skeleton className="h-3.5 w-44 max-w-full" tone="dark" />
|
|
60
|
+
<Skeleton className="h-3 w-28" tone="dark" />
|
|
61
|
+
</div>
|
|
62
|
+
))}
|
|
63
|
+
</div>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (inbox.messages.length === 0) {
|
|
68
|
+
return (
|
|
69
|
+
<div className="flex h-full flex-col items-center justify-center gap-3 p-6 text-center">
|
|
70
|
+
<span className="grid size-12 place-items-center rounded-md border border-dashed border-night-line text-chalk-2">
|
|
71
|
+
<Inbox aria-hidden="true" className="size-5" />
|
|
72
|
+
</span>
|
|
73
|
+
<p className="text-base font-semibold">Aucun e-mail</p>
|
|
74
|
+
<p className="max-w-xs text-sm text-chalk-2">
|
|
75
|
+
En local, rien ne part vraiment : chaque e-mail envoyé par l'API (lien
|
|
76
|
+
de connexion, invitation…) arrive ici.
|
|
77
|
+
</p>
|
|
78
|
+
</div>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const count = inbox.messages.length
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<div className="grid h-full min-h-0 md:grid-cols-[18rem_minmax(0,1fr)]">
|
|
86
|
+
<section
|
|
87
|
+
className={cn(
|
|
88
|
+
"flex min-h-0 flex-col md:border-r md:border-night-line",
|
|
89
|
+
visibleId && "hidden md:flex"
|
|
90
|
+
)}
|
|
91
|
+
>
|
|
92
|
+
<header className="flex h-11 shrink-0 items-center justify-between gap-2 border-b border-night-line pr-1 pl-4">
|
|
93
|
+
<span className="text-xs font-semibold uppercase tracking-wider text-chalk-2">
|
|
94
|
+
{count} e-mail{count > 1 ? "s" : ""}
|
|
95
|
+
</span>
|
|
96
|
+
<Tooltip label="Vider la boîte">
|
|
97
|
+
<button
|
|
98
|
+
className="grid size-9 place-items-center rounded-sm text-chalk-2 transition-colors hover:text-danger focus-visible:outline-2 focus-visible:outline-chalk"
|
|
99
|
+
disabled={clear.isPending}
|
|
100
|
+
onClick={() => clear.mutate()}
|
|
101
|
+
type="button"
|
|
102
|
+
>
|
|
103
|
+
{clear.isPending ? (
|
|
104
|
+
<Spinner />
|
|
105
|
+
) : (
|
|
106
|
+
<Trash2 aria-hidden="true" className="size-4" />
|
|
107
|
+
)}
|
|
108
|
+
</button>
|
|
109
|
+
</Tooltip>
|
|
110
|
+
</header>
|
|
111
|
+
<DevToolbarInboxList
|
|
112
|
+
messages={inbox.messages}
|
|
113
|
+
onSelectMessage={onSelectMessage}
|
|
114
|
+
selectedMessageId={visibleId}
|
|
115
|
+
/>
|
|
116
|
+
</section>
|
|
117
|
+
{visibleId ? (
|
|
118
|
+
<DevToolbarInboxMessage
|
|
119
|
+
id={visibleId}
|
|
120
|
+
key={visibleId}
|
|
121
|
+
onClose={() => onSelectMessage(null)}
|
|
122
|
+
/>
|
|
123
|
+
) : (
|
|
124
|
+
<p className="hidden items-center justify-center p-6 text-sm text-chalk-2 md:flex">
|
|
125
|
+
Sélectionnez un e-mail.
|
|
126
|
+
</p>
|
|
127
|
+
)}
|
|
128
|
+
</div>
|
|
129
|
+
)
|
|
130
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Wrench, X } from "lucide-react"
|
|
2
|
+
import type { ReactNode } from "react"
|
|
3
|
+
import { cn } from "@/lib/utils"
|
|
4
|
+
|
|
5
|
+
export interface DevToolbarLauncherProps {
|
|
6
|
+
addon?: ReactNode
|
|
7
|
+
onOpenChange: (open: boolean) => void
|
|
8
|
+
open: boolean
|
|
9
|
+
unreadCount: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function DevToolbarLauncher({
|
|
13
|
+
addon,
|
|
14
|
+
onOpenChange,
|
|
15
|
+
open,
|
|
16
|
+
unreadCount,
|
|
17
|
+
}: DevToolbarLauncherProps) {
|
|
18
|
+
return (
|
|
19
|
+
<div className="pointer-events-auto flex max-w-full items-center gap-2">
|
|
20
|
+
{addon}
|
|
21
|
+
<button
|
|
22
|
+
aria-expanded={open}
|
|
23
|
+
aria-label={open ? "Fermer la barre de dev" : "Ouvrir la barre de dev"}
|
|
24
|
+
className={cn(
|
|
25
|
+
"relative flex min-h-11 items-center gap-2 rounded-full bg-night px-4 text-sm font-semibold text-chalk shadow-lg transition-colors hover:bg-night-2 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent",
|
|
26
|
+
open && "bg-accent text-accent-ink hover:bg-accent-deep"
|
|
27
|
+
)}
|
|
28
|
+
onClick={() => onOpenChange(!open)}
|
|
29
|
+
type="button"
|
|
30
|
+
>
|
|
31
|
+
{open ? (
|
|
32
|
+
<X aria-hidden="true" className="size-4" />
|
|
33
|
+
) : (
|
|
34
|
+
<Wrench aria-hidden="true" className="size-4" />
|
|
35
|
+
)}
|
|
36
|
+
Dev
|
|
37
|
+
{unreadCount > 0 && !open ? (
|
|
38
|
+
<span className="grid min-w-5 place-items-center rounded-full bg-accent px-1.5 text-xs leading-5 text-accent-ink">
|
|
39
|
+
{unreadCount}
|
|
40
|
+
</span>
|
|
41
|
+
) : null}
|
|
42
|
+
</button>
|
|
43
|
+
</div>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Inbox, Settings2 } from "lucide-react"
|
|
2
|
+
import type { ReactNode } from "react"
|
|
3
|
+
import { DevToolbarEnvironmentPanel } from "@/components/dev-toolbar/dev-toolbar-environment-panel"
|
|
4
|
+
import { DevToolbarInboxPanel } from "@/components/dev-toolbar/dev-toolbar-inbox-panel"
|
|
5
|
+
import type { DevToolbarExtension } from "@/components/dev-toolbar/dev-toolbar-types"
|
|
6
|
+
import type { DevInbox } from "@/hooks/use-dev-inbox"
|
|
7
|
+
import { cn } from "@/lib/utils"
|
|
8
|
+
|
|
9
|
+
export interface DevToolbarPanelProps {
|
|
10
|
+
environmentActions?: ReactNode
|
|
11
|
+
extensions: readonly DevToolbarExtension[]
|
|
12
|
+
inbox: DevInbox
|
|
13
|
+
onSelectMessage: (id: string | null) => void
|
|
14
|
+
onTabChange: (tab: string) => void
|
|
15
|
+
selectedMessageId: string | null
|
|
16
|
+
tab: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function DevToolbarPanel({
|
|
20
|
+
environmentActions,
|
|
21
|
+
extensions,
|
|
22
|
+
inbox,
|
|
23
|
+
onSelectMessage,
|
|
24
|
+
onTabChange,
|
|
25
|
+
selectedMessageId,
|
|
26
|
+
tab,
|
|
27
|
+
}: DevToolbarPanelProps) {
|
|
28
|
+
const tabs: DevToolbarExtension[] = [
|
|
29
|
+
{
|
|
30
|
+
count: inbox.unreadCount,
|
|
31
|
+
icon: Inbox,
|
|
32
|
+
id: "inbox",
|
|
33
|
+
label: "Boîte mail",
|
|
34
|
+
panel: (
|
|
35
|
+
<DevToolbarInboxPanel
|
|
36
|
+
inbox={inbox}
|
|
37
|
+
onSelectMessage={onSelectMessage}
|
|
38
|
+
selectedMessageId={selectedMessageId}
|
|
39
|
+
/>
|
|
40
|
+
),
|
|
41
|
+
},
|
|
42
|
+
...extensions,
|
|
43
|
+
{
|
|
44
|
+
icon: Settings2,
|
|
45
|
+
id: "environment",
|
|
46
|
+
label: "Environnement",
|
|
47
|
+
panel: <DevToolbarEnvironmentPanel actions={environmentActions} />,
|
|
48
|
+
},
|
|
49
|
+
]
|
|
50
|
+
const active = tabs.find((entry) => entry.id === tab) ?? tabs[0]
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<section
|
|
54
|
+
aria-label="Barre de dev"
|
|
55
|
+
className="reveal pointer-events-auto flex h-[70dvh] max-h-176 w-full flex-col overflow-hidden rounded-lg border border-night-line bg-night text-chalk shadow-2xl"
|
|
56
|
+
>
|
|
57
|
+
<div className="flex border-b border-night-line" role="tablist">
|
|
58
|
+
{tabs.map((entry) => {
|
|
59
|
+
const selected = entry.id === active?.id
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<button
|
|
63
|
+
aria-selected={selected}
|
|
64
|
+
className={cn(
|
|
65
|
+
"relative flex min-h-11 flex-1 items-center justify-center gap-2 text-xs font-semibold uppercase tracking-wider text-chalk-2 transition-colors hover:text-chalk focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-chalk",
|
|
66
|
+
selected &&
|
|
67
|
+
"text-chalk after:absolute after:inset-x-0 after:bottom-0 after:h-0.5 after:bg-accent"
|
|
68
|
+
)}
|
|
69
|
+
key={entry.id}
|
|
70
|
+
onClick={() => onTabChange(entry.id)}
|
|
71
|
+
role="tab"
|
|
72
|
+
type="button"
|
|
73
|
+
>
|
|
74
|
+
<entry.icon aria-hidden="true" className="size-4" />
|
|
75
|
+
<span className="max-sm:sr-only">{entry.label}</span>
|
|
76
|
+
{entry.count ? (
|
|
77
|
+
<span className="grid min-w-5 place-items-center rounded-full bg-accent px-1 text-xs leading-5 tracking-normal text-accent-ink">
|
|
78
|
+
{entry.count}
|
|
79
|
+
</span>
|
|
80
|
+
) : null}
|
|
81
|
+
</button>
|
|
82
|
+
)
|
|
83
|
+
})}
|
|
84
|
+
</div>
|
|
85
|
+
<div className="min-h-0 flex-1" role="tabpanel">
|
|
86
|
+
{active?.panel}
|
|
87
|
+
</div>
|
|
88
|
+
</section>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LucideIcon } from "lucide-react"
|
|
2
|
+
import type { ReactNode } from "react"
|
|
3
|
+
|
|
4
|
+
/** A project-specific tab: account switching, simulated inbound messages, a job runner. */
|
|
5
|
+
export interface DevToolbarExtension {
|
|
6
|
+
count?: number
|
|
7
|
+
icon: LucideIcon
|
|
8
|
+
id: string
|
|
9
|
+
label: string
|
|
10
|
+
panel: ReactNode
|
|
11
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type ReactNode, useMemo, useState } from "react"
|
|
2
|
+
import { DevToolsClientContext } from "@/components/dev-toolbar/dev-toolbar-context"
|
|
3
|
+
import { DevToolbarLauncher } from "@/components/dev-toolbar/dev-toolbar-launcher"
|
|
4
|
+
import { DevToolbarPanel } from "@/components/dev-toolbar/dev-toolbar-panel"
|
|
5
|
+
import type { DevToolbarExtension } from "@/components/dev-toolbar/dev-toolbar-types"
|
|
6
|
+
import { useDevInbox } from "@/hooks/use-dev-inbox"
|
|
7
|
+
import { useDevToolbarState } from "@/hooks/use-dev-toolbar-state"
|
|
8
|
+
import { createDevToolsClient } from "@/lib/dev-tools-client"
|
|
9
|
+
import { DEV_API_PREFIX } from "@/lib/dev-tools-contract"
|
|
10
|
+
|
|
11
|
+
export interface DevToolbarProps {
|
|
12
|
+
/** Where the `/api/dev/*` routes live; "/api/v1/dev" for a versioned API. */
|
|
13
|
+
apiBase?: string
|
|
14
|
+
/** Buttons under the environment table: send a sign-in link, run the crons. */
|
|
15
|
+
environmentActions?: ReactNode
|
|
16
|
+
extensions?: readonly DevToolbarExtension[]
|
|
17
|
+
/** Sits left of the launcher: a "stop impersonating" button, a role badge. */
|
|
18
|
+
launcherAddon?: ReactNode
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The floating dev toolbox: the mailbox every local e-mail lands in, the environment, and project tabs. Local only. */
|
|
22
|
+
export function DevToolbar({
|
|
23
|
+
apiBase = DEV_API_PREFIX,
|
|
24
|
+
environmentActions,
|
|
25
|
+
extensions = [],
|
|
26
|
+
launcherAddon,
|
|
27
|
+
}: DevToolbarProps) {
|
|
28
|
+
const client = useMemo(() => createDevToolsClient(apiBase), [apiBase])
|
|
29
|
+
const { open, setOpen, setTab, tab } = useDevToolbarState()
|
|
30
|
+
const [selectedMessageId, setSelectedMessageId] = useState<string | null>(
|
|
31
|
+
null
|
|
32
|
+
)
|
|
33
|
+
const inbox = useDevInbox(client)
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<DevToolsClientContext.Provider value={client}>
|
|
37
|
+
<div
|
|
38
|
+
className="pointer-events-none fixed inset-x-3 bottom-[calc(env(safe-area-inset-bottom)+0.75rem)] z-30 flex flex-col items-end gap-2 sm:inset-x-auto sm:right-4 sm:bottom-4 sm:w-[min(56rem,calc(100vw-2rem))]"
|
|
39
|
+
data-dev-toolbar=""
|
|
40
|
+
>
|
|
41
|
+
{open ? (
|
|
42
|
+
<DevToolbarPanel
|
|
43
|
+
environmentActions={environmentActions}
|
|
44
|
+
extensions={extensions}
|
|
45
|
+
inbox={inbox}
|
|
46
|
+
onSelectMessage={setSelectedMessageId}
|
|
47
|
+
onTabChange={setTab}
|
|
48
|
+
selectedMessageId={selectedMessageId}
|
|
49
|
+
tab={tab}
|
|
50
|
+
/>
|
|
51
|
+
) : null}
|
|
52
|
+
<DevToolbarLauncher
|
|
53
|
+
addon={launcherAddon}
|
|
54
|
+
onOpenChange={setOpen}
|
|
55
|
+
open={open}
|
|
56
|
+
unreadCount={inbox.unreadCount}
|
|
57
|
+
/>
|
|
58
|
+
</div>
|
|
59
|
+
</DevToolsClientContext.Provider>
|
|
60
|
+
)
|
|
61
|
+
}
|