create-signet-app 0.4.2 → 0.4.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-signet-app",
3
- "version": "0.4.2",
3
+ "version": "0.4.6",
4
4
  "license": "MIT",
5
5
  "description": "Scaffold a Vite + React + Tailwind app wired to Signet.",
6
6
  "keywords": [
package/src/index.ts CHANGED
@@ -163,7 +163,8 @@ const DEPS = {
163
163
  // links the local copies, because the range matches the workspace version.
164
164
  "@dapplelight/signet-lib": "^0.4.0",
165
165
  "@dapplelight/signet-tokens": "^0.4.0",
166
- "@dapplelight/signet-ui": "^0.3.0",
166
+ // ^0.3.2: LabelsProvider (src/components/signet-labels.tsx).
167
+ "@dapplelight/signet-ui": "^0.3.2",
167
168
  "@tanstack/react-query": "^5.103.2",
168
169
  "@tanstack/react-router": "^1.170.39",
169
170
  "class-variance-authority": "^0.7.1",
@@ -175,6 +176,20 @@ const DEPS = {
175
176
  "tailwind-merge": "^3.7.0",
176
177
  }
177
178
 
179
+ // The web template's i18n: src/lib/i18n.ts + src/locales/*.json.
180
+ const I18N_DEPS = {
181
+ i18next: "^26.4.2",
182
+ "react-i18next": "^17.0.15",
183
+ }
184
+
185
+ // The web template's PWA: vite-plugin-pwa builds src/sw.ts with Workbox.
186
+ const PWA_DEV_DEPS = {
187
+ "vite-plugin-pwa": "^1.3.0",
188
+ "workbox-precaching": "^7.4.0",
189
+ "workbox-routing": "^7.4.0",
190
+ "workbox-window": "^7.4.0",
191
+ }
192
+
178
193
  const DEV_DEPS = {
179
194
  "@biomejs/biome": "^2.5.14",
180
195
  "@tailwindcss/vite": "^4.3.3",
@@ -493,13 +508,13 @@ async function main() {
493
508
  ? { ...API_DEPS, ...(mcp ? MCP_DEPS : {}) }
494
509
  : template === "full"
495
510
  ? { ...FULL_DEPS, ...(mcp ? MCP_DEPS : {}) }
496
- : DEPS,
511
+ : { ...DEPS, ...I18N_DEPS },
497
512
  devDependencies:
498
513
  template === "api"
499
514
  ? { ...API_DEV_DEPS, ...API_TARGETS[target].devDeps }
500
515
  : template === "full"
501
516
  ? FULL_DEV_DEPS
502
- : DEV_DEPS,
517
+ : { ...DEV_DEPS, ...PWA_DEV_DEPS },
503
518
  ...(template === "api" && API_TARGETS[target].engines
504
519
  ? { engines: API_TARGETS[target].engines }
505
520
  : {}),
@@ -0,0 +1,20 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Offline · __APP_NAME__</title>
7
+ <style>
8
+ :root { color-scheme: light dark; font-family: system-ui, sans-serif; }
9
+ body { margin: 0; min-height: 100vh; display: grid; place-items: center; text-align: center; padding: 24px; }
10
+ button { font: inherit; padding: 8px 16px; border-radius: 8px; border: 1px solid currentColor; background: none; color: inherit; cursor: pointer; }
11
+ </style>
12
+ </head>
13
+ <body>
14
+ <main>
15
+ <h1>You're offline</h1>
16
+ <p>__APP_NAME__ will load again when you're back online.</p>
17
+ <button type="button" onclick="location.reload()">Try again</button>
18
+ </main>
19
+ </body>
20
+ </html>
@@ -0,0 +1,23 @@
1
+ // Signet's components say a few words by themselves ("Close", "Search…", table
2
+ // headers, aria labels). This passes them through t(), so they live in
3
+ // src/locales/*.json under "signet" with the rest of the app's text.
4
+ import { defaultLabels, type Labels, LabelsProvider } from "@dapplelight/signet-ui"
5
+ import { useMemo } from "react"
6
+ import { useTranslation } from "react-i18next"
7
+
8
+ export function SignetLabels({ children }: { children: React.ReactNode }) {
9
+ const { t } = useTranslation()
10
+ const labels = useMemo(
11
+ () =>
12
+ Object.fromEntries(
13
+ Object.entries(defaultLabels).map(([key, en]) => [
14
+ key,
15
+ typeof en === "function"
16
+ ? (value: string) => t(`signet.${key}`, { value })
17
+ : t(`signet.${key}`),
18
+ ]),
19
+ ) as Labels,
20
+ [t],
21
+ )
22
+ return <LabelsProvider labels={labels}>{children}</LabelsProvider>
23
+ }
@@ -0,0 +1,16 @@
1
+ import { expect, test } from "bun:test"
2
+ import en from "../locales/en.json"
3
+ import i18n, { pseudo } from "./i18n"
4
+
5
+ test("t() reads src/locales/en.json", () => {
6
+ expect(i18n.t("login.title")).toBe(en.login.title)
7
+ })
8
+
9
+ test("pseudo accents letters and pads ~35%", () => {
10
+ expect(pseudo("Sign in")).toBe("[Sîgñ îñ~~~]")
11
+ })
12
+
13
+ test("Signet's own labels are in en.json, with {{value}} for the ones that take one", () => {
14
+ expect(i18n.t("signet.close")).toBe("Close")
15
+ expect(i18n.t("signet.deleteView", { value: "Q3" })).toBe("Delete view Q3")
16
+ })
@@ -0,0 +1,31 @@
1
+ // Every string the app shows lives in src/locales/<language>.json; components
2
+ // call t("…") from useTranslation(). A new language = a new file + an entry in
3
+ // `resources`. The browser's language picks the file, English is the fallback.
4
+ // Money and dates: Intl via @dapplelight/signet-lib/format, not here.
5
+ import i18n from "i18next"
6
+ import { initReactI18next } from "react-i18next"
7
+ import en from "../locales/en.json"
8
+
9
+ // Pseudo-locale for review screenshots, dev only: open the app with ?pseudo=1
10
+ // and every string comes out accented and ~35% longer in brackets, so text that
11
+ // skipped t() (plain letters) and text that gets cut off both show at a glance.
12
+ const PLAIN = "aeiouycnAEIOUYCN"
13
+ const ACCENTED = [..."åéîöüýçñÅÉÎÖÜÝÇÑ"]
14
+ export const pseudo = (s: string) =>
15
+ `[${s.replace(/[a-zA-Z]/g, (c) => ACCENTED[PLAIN.indexOf(c)] ?? c)}${"~".repeat(Math.ceil(s.length * 0.35))}]`
16
+
17
+ const usePseudo =
18
+ import.meta.env.DEV && new URLSearchParams(globalThis.location?.search).has("pseudo")
19
+
20
+ i18n
21
+ .use({ type: "postProcessor", name: "pseudo", process: (v: string) => pseudo(v) })
22
+ .use(initReactI18next)
23
+ .init({
24
+ resources: { en: { translation: en } },
25
+ lng: globalThis.navigator?.language?.split("-")[0] ?? "en",
26
+ fallbackLng: "en",
27
+ interpolation: { escapeValue: false },
28
+ ...(usePseudo ? { postProcess: ["pseudo"] } : {}),
29
+ })
30
+
31
+ export default i18n
@@ -0,0 +1,59 @@
1
+ // Keeps the installed app on the latest deploy. An installed PWA that stays
2
+ // open rarely re-checks its service worker (browsers do it on navigation), so:
3
+ // - check for an update when the app returns to the foreground, and every 30 min;
4
+ // - when one is waiting, show a "Reload" toast, and apply it by itself once every
5
+ // tab of the app is in the background, so nothing reloads under someone mid-task.
6
+
7
+ import { registerSW } from "virtual:pwa-register"
8
+ import { toast } from "sonner"
9
+ import i18n from "./i18n"
10
+
11
+ const CHECK_EVERY_MS = 30 * 60 * 1000
12
+
13
+ type Doc = Pick<Document, "visibilityState" | "addEventListener" | "removeEventListener">
14
+
15
+ export function wireUpdateChecks(
16
+ registration: { update: () => Promise<unknown> },
17
+ doc: Doc = document,
18
+ everyMs = CHECK_EVERY_MS,
19
+ ): () => void {
20
+ // A failed check (offline) is harmless; the next one retries.
21
+ const check = () => void registration.update().catch(() => {})
22
+ const onVisible = () => doc.visibilityState === "visible" && check()
23
+ doc.addEventListener("visibilitychange", onVisible)
24
+ const timer = setInterval(check, everyMs)
25
+ return () => {
26
+ doc.removeEventListener("visibilitychange", onVisible)
27
+ clearInterval(timer)
28
+ }
29
+ }
30
+
31
+ /** Run `apply` each time the page is hidden (now, if it already is). */
32
+ export function whenHidden(apply: () => void, doc: Doc = document): () => void {
33
+ const maybe = () => {
34
+ if (doc.visibilityState === "hidden") apply()
35
+ }
36
+ maybe()
37
+ doc.addEventListener("visibilitychange", maybe)
38
+ return () => doc.removeEventListener("visibilitychange", maybe)
39
+ }
40
+
41
+ export function registerPwa(): void {
42
+ // `bun run dev` has no service worker; only built and previewed apps do.
43
+ if (!import.meta.env.PROD || !("serviceWorker" in navigator)) return
44
+ let reg: ServiceWorkerRegistration | undefined
45
+ const update = registerSW({
46
+ onRegisteredSW(_url, registration) {
47
+ reg = registration
48
+ if (registration) wireUpdateChecks(registration)
49
+ },
50
+ onNeedRefresh() {
51
+ toast(i18n.t("update.available"), {
52
+ duration: Number.POSITIVE_INFINITY,
53
+ action: { label: i18n.t("update.reload"), onClick: () => void update(true) },
54
+ })
55
+ // The worker applies it only if every tab is hidden; the last one to hide does it.
56
+ whenHidden(() => reg?.waiting?.postMessage({ type: "SKIP_WAITING_IF_HIDDEN" }))
57
+ },
58
+ })
59
+ }
@@ -0,0 +1,65 @@
1
+ {
2
+ "home": {
3
+ "title": "Running on the __THEME__ theme",
4
+ "showToast": "Show a toast",
5
+ "saved": "Saved",
6
+ "outline": "Outline",
7
+ "badge": "Badge",
8
+ "themeHint": "Swap the theme import in src/app.css and everything here reshapes: colour, radius, type scale and motion. No component changes."
9
+ },
10
+ "login": {
11
+ "title": "Sign in",
12
+ "body": "Your session has ended or you are not signed in. Replace this page with your sign-in flow."
13
+ },
14
+ "update": {
15
+ "available": "A new version is available.",
16
+ "reload": "Reload"
17
+ },
18
+ "signet": {
19
+ "close": "Close",
20
+ "somethingWentWrong": "Something went wrong",
21
+ "tryAgain": "Try again",
22
+ "previousPage": "Previous page",
23
+ "nextPage": "Next page",
24
+ "theme": "Theme",
25
+ "themeLight": "Light",
26
+ "themeDark": "Dark",
27
+ "themeSystem": "System",
28
+ "search": "Search",
29
+ "searchPlaceholder": "Search…",
30
+ "selectAllRows": "Select all rows",
31
+ "noValues": "No values",
32
+ "toggleColumns": "Toggle columns",
33
+ "savedViews": "Saved views",
34
+ "noSavedViews": "No saved views",
35
+ "viewName": "View name",
36
+ "saveViewPlaceholder": "Save current view as…",
37
+ "deleteView": "Delete view {{value}}",
38
+ "otherEmoji": "Other emoji",
39
+ "otherEmojiPlaceholder": "Other…",
40
+ "actions": "Actions",
41
+ "upload": "Upload",
42
+ "uploading": "Uploading {{value}}",
43
+ "noData": "No data.",
44
+ "clear": "Clear",
45
+ "reset": "Reset",
46
+ "columns": "Columns",
47
+ "views": "Views",
48
+ "save": "Save",
49
+ "selectRow": "Select row {{value}}",
50
+ "resizeColumn": "Resize column {{value}}",
51
+ "filterBy": "Filter {{value}}",
52
+ "switchToLight": "Switch to light theme",
53
+ "switchToDark": "Switch to dark theme",
54
+ "linkToSection": "Link to {{value}}",
55
+ "job": "Job",
56
+ "status": "Status",
57
+ "attempts": "Attempts",
58
+ "progress": "Progress",
59
+ "error": "Error",
60
+ "retry": "Retry",
61
+ "cancel": "Cancel",
62
+ "retryItem": "Retry {{value}}",
63
+ "cancelItem": "Cancel {{value}}"
64
+ }
65
+ }
@@ -4,7 +4,10 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
4
4
  import { RouterProvider } from "@tanstack/react-router"
5
5
  import { StrictMode } from "react"
6
6
  import { createRoot } from "react-dom/client"
7
+ import { SignetLabels } from "./components/signet-labels"
7
8
  import { Toaster } from "./components/toaster"
9
+ import "./lib/i18n"
10
+ import { registerPwa } from "./lib/pwa"
8
11
  import { createAppRouter } from "./router"
9
12
  import "./app.css"
10
13
 
@@ -21,16 +24,20 @@ onAuthErrorRedirect(queryClient, () => {
21
24
  window.location.assign(router.buildLocation({ to: "/login" }).href)
22
25
  })
23
26
 
27
+ registerPwa()
28
+
24
29
  const rootElement = document.getElementById("root")
25
30
  if (!rootElement) throw new Error("Root element #root not found in index.html")
26
31
 
27
32
  createRoot(rootElement).render(
28
33
  <StrictMode>
29
34
  <ThemeProvider>
30
- <QueryClientProvider client={queryClient}>
31
- <RouterProvider router={router} />
32
- <Toaster />
33
- </QueryClientProvider>
35
+ <SignetLabels>
36
+ <QueryClientProvider client={queryClient}>
37
+ <RouterProvider router={router} />
38
+ <Toaster />
39
+ </QueryClientProvider>
40
+ </SignetLabels>
34
41
  </ThemeProvider>
35
42
  </StrictMode>,
36
43
  )
@@ -2,6 +2,7 @@ import { Badge } from "@dapplelight/signet-ui/components/badge"
2
2
  import { Button } from "@dapplelight/signet-ui/components/button"
3
3
  import { Card, CardContent, CardHeader, CardTitle } from "@dapplelight/signet-ui/components/card"
4
4
  import { createFileRoute } from "@tanstack/react-router"
5
+ import { useTranslation } from "react-i18next"
5
6
  import { toast } from "sonner"
6
7
 
7
8
  export const Route = createFileRoute("/")({
@@ -9,19 +10,17 @@ export const Route = createFileRoute("/")({
9
10
  })
10
11
 
11
12
  function Home() {
13
+ const { t } = useTranslation()
12
14
  return (
13
15
  <Card>
14
16
  <CardHeader>
15
- <CardTitle>Running on the __THEME__ theme</CardTitle>
17
+ <CardTitle>{t("home.title")}</CardTitle>
16
18
  </CardHeader>
17
19
  <CardContent className="flex flex-wrap items-center gap-3">
18
- <Button onClick={() => toast.success("Saved")}>Show a toast</Button>
19
- <Button variant="outline">Outline</Button>
20
- <Badge>Badge</Badge>
21
- <p className="w-full text-sm text-muted-foreground">
22
- Swap the theme import in <code>src/app.css</code> and everything here reshapes — colour,
23
- radius, type scale and motion. No component changes.
24
- </p>
20
+ <Button onClick={() => toast.success(t("home.saved"))}>{t("home.showToast")}</Button>
21
+ <Button variant="outline">{t("home.outline")}</Button>
22
+ <Badge>{t("home.badge")}</Badge>
23
+ <p className="w-full text-sm text-muted-foreground">{t("home.themeHint")}</p>
25
24
  </CardContent>
26
25
  </Card>
27
26
  )
@@ -1,5 +1,6 @@
1
1
  import { Card, CardContent, CardHeader, CardTitle } from "@dapplelight/signet-ui/components/card"
2
2
  import { createFileRoute } from "@tanstack/react-router"
3
+ import { useTranslation } from "react-i18next"
3
4
 
4
5
  // Where the 401 handler in main.tsx sends the user. A placeholder: wire it to
5
6
  // your own auth (a form posting to your API, an OAuth button) — the template
@@ -9,15 +10,14 @@ export const Route = createFileRoute("/login")({
9
10
  })
10
11
 
11
12
  function Login() {
13
+ const { t } = useTranslation()
12
14
  return (
13
15
  <Card className="mx-auto max-w-sm">
14
16
  <CardHeader>
15
- <CardTitle>Sign in</CardTitle>
17
+ <CardTitle>{t("login.title")}</CardTitle>
16
18
  </CardHeader>
17
19
  <CardContent>
18
- <p className="text-sm text-muted-foreground">
19
- Your session has ended or you are not signed in. Replace this page with your sign-in flow.
20
- </p>
20
+ <p className="text-sm text-muted-foreground">{t("login.body")}</p>
21
21
  </CardContent>
22
22
  </Card>
23
23
  )
@@ -0,0 +1,79 @@
1
+ /// <reference lib="webworker" />
2
+ // The service worker vite-plugin-pwa builds from this file (injectManifest).
3
+ // It precaches the built app, serves public/offline.html for a page load with
4
+ // no network, applies an update when the "Reload" toast is tapped, and shows
5
+ // web push notifications. Authenticated API responses are never cached here:
6
+ // /api/* always goes to the network, so nothing private outlives sign-out.
7
+ import { cleanupOutdatedCaches, precacheAndRoute } from "workbox-precaching"
8
+ import { NavigationRoute, registerRoute } from "workbox-routing"
9
+
10
+ declare const self: ServiceWorkerGlobalScope
11
+
12
+ precacheAndRoute(self.__WB_MANIFEST)
13
+ cleanupOutdatedCaches()
14
+
15
+ const OFFLINE_CACHE = "offline-fallback"
16
+
17
+ registerRoute(
18
+ new NavigationRoute(
19
+ async ({ request }) => {
20
+ try {
21
+ return await fetch(request)
22
+ } catch {
23
+ return (
24
+ (await caches.match("/offline.html", { cacheName: OFFLINE_CACHE })) ?? Response.error()
25
+ )
26
+ }
27
+ },
28
+ // OAuth callbacks and API navigations never get the app shell or the offline page.
29
+ { denylist: [/^\/api\//] },
30
+ ),
31
+ )
32
+
33
+ self.addEventListener("install", (event) => {
34
+ event.waitUntil(caches.open(OFFLINE_CACHE).then((c) => c.add("/offline.html")))
35
+ })
36
+
37
+ // registerType "prompt": the page posts SKIP_WAITING when the person taps Reload,
38
+ // and SKIP_WAITING_IF_HIDDEN when a tab goes to the background. Activating
39
+ // reloads every open tab, so the second applies only when no window is visible.
40
+ self.addEventListener("message", (event) => {
41
+ const type = event.data?.type
42
+ if (type === "SKIP_WAITING") self.skipWaiting()
43
+ if (type === "SKIP_WAITING_IF_HIDDEN")
44
+ event.waitUntil(
45
+ self.clients.matchAll({ type: "window", includeUncontrolled: true }).then((all) => {
46
+ if (all.every((c) => c.visibilityState === "hidden")) return self.skipWaiting()
47
+ }),
48
+ )
49
+ })
50
+ self.addEventListener("activate", (event) => event.waitUntil(self.clients.claim()))
51
+
52
+ // Web push: { title, message, url, tag } as JSON; plain text also works.
53
+ self.addEventListener("push", (event) => {
54
+ let p: { title?: string; message?: string; url?: string; tag?: string } = {}
55
+ try {
56
+ p = event.data?.json() ?? {}
57
+ } catch {
58
+ p = { message: event.data?.text() ?? "" }
59
+ }
60
+ event.waitUntil(
61
+ self.registration.showNotification(p.title ?? "__APP_NAME__", {
62
+ body: p.message ?? "",
63
+ tag: p.tag,
64
+ data: { url: p.url ?? "/" },
65
+ }),
66
+ )
67
+ })
68
+
69
+ self.addEventListener("notificationclick", (event) => {
70
+ event.notification.close()
71
+ const url = (event.notification.data?.url as string | undefined) ?? "/"
72
+ event.waitUntil(
73
+ self.clients.matchAll({ type: "window", includeUncontrolled: true }).then((clients) => {
74
+ const open = clients.find((c) => "focus" in c) as WindowClient | undefined
75
+ if (open) return open.navigate(url).then(() => open.focus())
76
+ return self.clients.openWindow(url)
77
+ }),
78
+ )
79
+ })
@@ -19,7 +19,7 @@
19
19
  "paths": {
20
20
  "@/*": ["./src/*"]
21
21
  },
22
- "types": ["vite/client"]
22
+ "types": ["vite/client", "vite-plugin-pwa/client"]
23
23
  },
24
24
  "include": ["src"],
25
25
  "exclude": ["src/**/*.test.ts", "src/**/*.test.tsx"]
@@ -3,6 +3,7 @@ import tailwindcss from "@tailwindcss/vite"
3
3
  import { tanstackRouter } from "@tanstack/router-plugin/vite"
4
4
  import react from "@vitejs/plugin-react"
5
5
  import { defineConfig } from "vite"
6
+ import { VitePWA } from "vite-plugin-pwa"
6
7
 
7
8
  export default defineConfig({
8
9
  plugins: [
@@ -11,6 +12,23 @@ export default defineConfig({
11
12
  tanstackRouter({ target: "react", autoCodeSplitting: true, quoteStyle: "double" }),
12
13
  react(),
13
14
  tailwindcss(),
15
+ // Installable app + offline: src/sw.ts is the service worker (precache,
16
+ // public/offline.html fallback, update on "Reload", web push). Add icons
17
+ // (192 and 512 px PNGs in public/) to the manifest for the install prompt.
18
+ VitePWA({
19
+ registerType: "prompt",
20
+ strategies: "injectManifest",
21
+ srcDir: "src",
22
+ filename: "sw.ts",
23
+ manifest: {
24
+ name: "__APP_NAME__",
25
+ short_name: "__APP_NAME__",
26
+ display: "standalone",
27
+ start_url: "/",
28
+ scope: "/",
29
+ icons: [],
30
+ },
31
+ }),
14
32
  ],
15
33
  resolve: {
16
34
  alias: { "@": path.resolve(import.meta.dirname, "./src") },