@wwchen/stack 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/blocks/AGENTS.md +3 -1
- package/blocks/CLAUDE.md +2 -0
- package/configs/biome.json +2 -1
- package/dist/storybook/index.d.ts +98 -0
- package/dist/storybook/index.js +72 -0
- package/package.json +16 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Shared building blocks for Next.js 16 apps on Neon, Better Auth, Resend and lew-ds. Apps are normally created from the Copier template in [wwchen/bootstrap-stack](https://github.com/wwchen/bootstrap-stack), which wires everything below; this README is the package's reference.
|
|
4
4
|
|
|
5
|
-
Requires Node 24. The peer dependencies are exact pins: `next`, `react`, `react-dom`, `drizzle-orm`, `@lew-ds/lds`, `@lew-ds/lds-react`, `@lew-ds/open-icons`. `@electric-sql/pglite` and `@electric-sql/pglite-socket` are optional peers for tests and local development.
|
|
5
|
+
Requires Node 24. The peer dependencies are exact pins: `next`, `react`, `react-dom`, `drizzle-orm`, `@lew-ds/lds`, `@lew-ds/lds-react`, `@lew-ds/open-icons`. `@electric-sql/pglite` and `@electric-sql/pglite-socket` are optional peers for tests and local development, and `storybook` and `@storybook/nextjs-vite` for an app's Storybook.
|
|
6
6
|
|
|
7
7
|
## Entry points
|
|
8
8
|
|
|
@@ -19,6 +19,7 @@ Requires Node 24. The peer dependencies are exact pins: `next`, `react`, `react-
|
|
|
19
19
|
| `@wwchen/stack/connections` | connected accounts (not sign-in): `connectionTable`, `createConnections` (start and callback route handlers, `token`, `list`, `connected`, `disconnect`), the `foursquare` provider, AES-256-GCM token encryption under `TOKEN_ENCRYPTION_KEY` |
|
|
20
20
|
| `@wwchen/stack/jobs` | multi-person scheduled jobs: `failingSince` and `isNewFailure` (alert on a failure's first 24 hours only), `mapLimit` |
|
|
21
21
|
| `@wwchen/stack/ui`, `/ui/icons`, `/ui/globals.css`, `/ui/app.css` | lew-ds wiring, theme cookie, icon sprite and its usage check, and the CSS partials |
|
|
22
|
+
| `@wwchen/stack/storybook` | an app's Storybook set up as its root layout sets up a page: `stackPreview({ icons, fontVariable, bodyClassName })` (the `<html>` theme classes with a light/dark toolbar, the icon sprite, a logging stand-in for the App Router's `useRouter()`, the viewports), and `PHONE` and `SMALL_PHONE` story globals |
|
|
22
23
|
| `@wwchen/stack/configs/tsconfig.next.json`, `/configs/biome.json`, `/configs/vitest` | shared tool configs, consumed with `extends` or an import |
|
|
23
24
|
| `@wwchen/stack/testing/next` | tests only: `inServerAction` runs a function in a real Next server-action scope, `thrownBy` reads a `redirect()`/`notFound()` |
|
|
24
25
|
|
package/blocks/AGENTS.md
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
| Typecheck | `pnpm typecheck` |
|
|
14
14
|
| Lint / format | `pnpm lint` · `pnpm lint:fix` |
|
|
15
15
|
| Tests | `pnpm test` · one file: `pnpm test tests/unit/<name>.test.ts` |
|
|
16
|
+
| Storybook | `pnpm storybook` (http://localhost:6006) · every story built, as CI does: `pnpm storybook:build` |
|
|
16
17
|
| Migrate | `pnpm db:migrate` (your dev branch) |
|
|
17
18
|
| Rebuild the `seed` branch (fake data; every dev and preview branch is cut from it) | `pnpm exec stack neon seed` |
|
|
18
19
|
| Add a user | `stack user:create <email> [--admin]` (on your dev branch; production: the runbook's "First admin") |
|
|
@@ -45,7 +46,8 @@ The design system is LDS (Lew Design System), product theme: `@lew-ds/lds`, `@le
|
|
|
45
46
|
- Never hand-roll a pill, button, input, table or banner. If LDS lacks something, fix it upstream in LDS, never at a call site.
|
|
46
47
|
- LDS paints through its own class names; the app never restyles them. The app's own `app.css` is the only place it fills a gap.
|
|
47
48
|
- Tailwind is for layout only. Its colour, type, radius and shadow utilities resolve to LDS roles through the stack's `globals.css`. No raw hex or px in a component.
|
|
48
|
-
- A design change lands in the component and its stories in the same change.
|
|
49
|
+
- A design change lands in the component and its stories (narrow and wide) in the same change, and carries to every component that shows the same thing.
|
|
50
|
+
- Stories live beside their component as `*.stories.tsx` and render the real components from fixture data; a story never hand-builds a look. `PHONE` (390px) and `SMALL_PHONE` (320px) from `@wwchen/stack/storybook` open a story narrow, and the toolbar switches light and dark.
|
|
49
51
|
|
|
50
52
|
## Database
|
|
51
53
|
|
package/blocks/CLAUDE.md
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
| Typecheck | `pnpm typecheck` |
|
|
14
14
|
| Lint / format | `pnpm lint` · `pnpm lint:fix` |
|
|
15
15
|
| Tests | `pnpm test` · one file: `pnpm test tests/unit/<name>.test.ts` |
|
|
16
|
+
| Storybook | `pnpm storybook` (http://localhost:6006) · every story built, as CI does: `pnpm storybook:build` |
|
|
16
17
|
| DB generate / apply migration | `pnpm db:generate` · `pnpm db:migrate` |
|
|
17
18
|
| Seed the shared `seed` branch | `stack neon seed` (runs the app's `db/seed.ts`) |
|
|
18
19
|
| Reset the shared preview branch | `stack neon reset-preview` (`--set-vercel` also writes its URLs into Vercel's Preview variables) |
|
|
@@ -55,6 +56,7 @@ The design system is LDS (Lew Design System), product theme: `@lew-ds/lds`, `@le
|
|
|
55
56
|
- Layouts respond to the width a component has (container queries), never to the device.
|
|
56
57
|
- Theme is a cookie (`theme-product mode-*`) read and written through the stack's `/ui` helpers.
|
|
57
58
|
- A design change lands in the component and its stories (narrow and wide) in the same change, and carries to every component that shows the same thing.
|
|
59
|
+
- Stories live beside their component as `*.stories.tsx` and render the real components from fixture data; a story never hand-builds a look. `PHONE` (390px) and `SMALL_PHONE` (320px) from `@wwchen/stack/storybook` open a story narrow, and the toolbar switches light and dark.
|
|
58
60
|
|
|
59
61
|
## Database rules
|
|
60
62
|
|
package/configs/biome.json
CHANGED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { Preview } from "@storybook/nextjs-vite";
|
|
2
|
+
import { type AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime.js";
|
|
3
|
+
import { type Theme } from "../ui/theme.ts";
|
|
4
|
+
/**
|
|
5
|
+
* An app's Storybook, set up the way its root layout sets up a page: the same classes on `<html>` (theme, mode and font), the same inline icon sprite, and a router for `useRouter()`. An app's `.storybook/preview.tsx` imports its own stylesheet and font and spreads `stackPreview(...)`.
|
|
6
|
+
*
|
|
7
|
+
* Storybook's packages are optional peers: only an app's Storybook imports this module.
|
|
8
|
+
*/
|
|
9
|
+
export type StackPreviewOptions = {
|
|
10
|
+
/** The app's `APP_ICONS`: the glyphs its components name, inlined as the root layout does. */
|
|
11
|
+
icons: readonly string[];
|
|
12
|
+
/** The `next/font` class the root layout passes to `htmlClassName` (`inter.variable`). */
|
|
13
|
+
fontVariable?: string;
|
|
14
|
+
/** The classes the root layout puts on `<body>`, added to Storybook's own `<body>` beside its layout classes. */
|
|
15
|
+
bodyClassName?: string;
|
|
16
|
+
};
|
|
17
|
+
/** The toolbar's light/dark switch, as a story global. Anything but `"dark"` is light. */
|
|
18
|
+
export declare function storyTheme(value: unknown): Theme;
|
|
19
|
+
/**
|
|
20
|
+
* Writes what the root layout writes on the server. Storybook has no request, so the theme comes from the toolbar instead of the cookie, and the classes are set on the live document. `<html>` is the stack's alone; `<body>` also carries Storybook's layout classes, so the app's are added beside them.
|
|
21
|
+
*/
|
|
22
|
+
export declare function applyStoryTheme(document: {
|
|
23
|
+
documentElement: {
|
|
24
|
+
className: string;
|
|
25
|
+
};
|
|
26
|
+
body: {
|
|
27
|
+
classList: {
|
|
28
|
+
add(...tokens: string[]): void;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}, theme: Theme, options?: Pick<StackPreviewOptions, "fontVariable" | "bodyClassName">): void;
|
|
32
|
+
/**
|
|
33
|
+
* The router `useRouter()` reads in a story. Storybook's own app-router mode does not render under Next 16.4 (its RedirectBoundary reads a context it never sets), so stories get Next's context directly. A navigation or refresh is logged to the browser console instead of happening.
|
|
34
|
+
*/
|
|
35
|
+
export declare const storyRouter: AppRouterInstance;
|
|
36
|
+
/**
|
|
37
|
+
* The viewport toolbar: a current phone (390 × 844, the width phone layouts are checked at), the 320px floor every page must fit with no horizontal scroll, then Storybook's minimal set. Storybook's own 320px entry is the stack's `smallPhone`, so it is listed once, under a name the stack owns.
|
|
38
|
+
*/
|
|
39
|
+
export declare const STORY_VIEWPORTS: {
|
|
40
|
+
readonly mobile2: {
|
|
41
|
+
readonly name: "Large mobile";
|
|
42
|
+
readonly styles: {
|
|
43
|
+
readonly height: "896px";
|
|
44
|
+
readonly width: "414px";
|
|
45
|
+
};
|
|
46
|
+
readonly type: "mobile";
|
|
47
|
+
};
|
|
48
|
+
readonly tablet: {
|
|
49
|
+
readonly name: "Tablet";
|
|
50
|
+
readonly styles: {
|
|
51
|
+
readonly height: "1112px";
|
|
52
|
+
readonly width: "834px";
|
|
53
|
+
};
|
|
54
|
+
readonly type: "tablet";
|
|
55
|
+
};
|
|
56
|
+
readonly desktop: {
|
|
57
|
+
readonly name: "Desktop";
|
|
58
|
+
readonly styles: {
|
|
59
|
+
readonly height: "1024px";
|
|
60
|
+
readonly width: "1280px";
|
|
61
|
+
};
|
|
62
|
+
readonly type: "desktop";
|
|
63
|
+
};
|
|
64
|
+
readonly phone: {
|
|
65
|
+
readonly name: "Phone";
|
|
66
|
+
readonly styles: {
|
|
67
|
+
readonly width: "390px";
|
|
68
|
+
readonly height: "844px";
|
|
69
|
+
};
|
|
70
|
+
readonly type: "mobile";
|
|
71
|
+
};
|
|
72
|
+
readonly smallPhone: {
|
|
73
|
+
readonly name: "Small phone";
|
|
74
|
+
readonly styles: {
|
|
75
|
+
readonly height: "568px";
|
|
76
|
+
readonly width: "320px";
|
|
77
|
+
};
|
|
78
|
+
readonly type: "mobile";
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
/** A story's `globals` that open it at a phone's width: `export const Narrow = { globals: PHONE }`. */
|
|
82
|
+
export declare const PHONE: {
|
|
83
|
+
readonly viewport: {
|
|
84
|
+
readonly value: "phone";
|
|
85
|
+
readonly isRotated: false;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
/** A story's `globals` that open it at the 320px floor: `export const Narrowest = { globals: SMALL_PHONE }`. */
|
|
89
|
+
export declare const SMALL_PHONE: {
|
|
90
|
+
readonly viewport: {
|
|
91
|
+
readonly value: "smallPhone";
|
|
92
|
+
readonly isRotated: false;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* The stack's part of an app's `.storybook/preview.tsx`: the theme toolbar (light and dark), the viewports, and a decorator that renders every story inside the root layout's set-up. Spread it, then add the app's own parameters or decorators.
|
|
97
|
+
*/
|
|
98
|
+
export declare function stackPreview(options: StackPreviewOptions): Preview;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { AppRouterContext, } from "next/dist/shared/lib/app-router-context.shared-runtime.js";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import { MINIMAL_VIEWPORTS } from "storybook/viewport";
|
|
5
|
+
import { StackRoot } from "../ui/index.js";
|
|
6
|
+
import { htmlClassName } from "../ui/theme.js";
|
|
7
|
+
/** The toolbar's light/dark switch, as a story global. Anything but `"dark"` is light. */
|
|
8
|
+
export function storyTheme(value) {
|
|
9
|
+
return value === "dark" ? "dark" : "light";
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Writes what the root layout writes on the server. Storybook has no request, so the theme comes from the toolbar instead of the cookie, and the classes are set on the live document. `<html>` is the stack's alone; `<body>` also carries Storybook's layout classes, so the app's are added beside them.
|
|
13
|
+
*/
|
|
14
|
+
export function applyStoryTheme(document, theme, options = {}) {
|
|
15
|
+
document.documentElement.className = htmlClassName(theme, options.fontVariable);
|
|
16
|
+
const body = options.bodyClassName?.split(/\s+/).filter(Boolean) ?? [];
|
|
17
|
+
if (body.length > 0)
|
|
18
|
+
document.body.classList.add(...body);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The router `useRouter()` reads in a story. Storybook's own app-router mode does not render under Next 16.4 (its RedirectBoundary reads a context it never sets), so stories get Next's context directly. A navigation or refresh is logged to the browser console instead of happening.
|
|
22
|
+
*/
|
|
23
|
+
export const storyRouter = {
|
|
24
|
+
refresh: () => console.info("[storybook] router.refresh()"),
|
|
25
|
+
push: (href) => console.info("[storybook] router.push", href),
|
|
26
|
+
replace: (href) => console.info("[storybook] router.replace", href),
|
|
27
|
+
back: () => console.info("[storybook] router.back()"),
|
|
28
|
+
forward: () => console.info("[storybook] router.forward()"),
|
|
29
|
+
prefetch: () => { },
|
|
30
|
+
bfcacheId: "story",
|
|
31
|
+
};
|
|
32
|
+
const { mobile1, ...minimalViewports } = MINIMAL_VIEWPORTS;
|
|
33
|
+
/**
|
|
34
|
+
* The viewport toolbar: a current phone (390 × 844, the width phone layouts are checked at), the 320px floor every page must fit with no horizontal scroll, then Storybook's minimal set. Storybook's own 320px entry is the stack's `smallPhone`, so it is listed once, under a name the stack owns.
|
|
35
|
+
*/
|
|
36
|
+
export const STORY_VIEWPORTS = {
|
|
37
|
+
phone: { name: "Phone", styles: { width: "390px", height: "844px" }, type: "mobile" },
|
|
38
|
+
smallPhone: { name: "Small phone", styles: mobile1.styles, type: "mobile" },
|
|
39
|
+
...minimalViewports,
|
|
40
|
+
};
|
|
41
|
+
/** A story's `globals` that open it at a phone's width: `export const Narrow = { globals: PHONE }`. */
|
|
42
|
+
export const PHONE = { viewport: { value: "phone", isRotated: false } };
|
|
43
|
+
/** A story's `globals` that open it at the 320px floor: `export const Narrowest = { globals: SMALL_PHONE }`. */
|
|
44
|
+
export const SMALL_PHONE = { viewport: { value: "smallPhone", isRotated: false } };
|
|
45
|
+
function StoryRoot({ theme, options, children, }) {
|
|
46
|
+
const { fontVariable, bodyClassName } = options;
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
applyStoryTheme(document, theme, { fontVariable, bodyClassName });
|
|
49
|
+
}, [theme, fontVariable, bodyClassName]);
|
|
50
|
+
return (_jsx(AppRouterContext.Provider, { value: storyRouter, children: _jsx(StackRoot, { icons: options.icons, children: children }) }));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The stack's part of an app's `.storybook/preview.tsx`: the theme toolbar (light and dark), the viewports, and a decorator that renders every story inside the root layout's set-up. Spread it, then add the app's own parameters or decorators.
|
|
54
|
+
*/
|
|
55
|
+
export function stackPreview(options) {
|
|
56
|
+
return {
|
|
57
|
+
parameters: {
|
|
58
|
+
layout: "padded",
|
|
59
|
+
viewport: { options: STORY_VIEWPORTS },
|
|
60
|
+
},
|
|
61
|
+
globalTypes: {
|
|
62
|
+
theme: {
|
|
63
|
+
description: "Light or dark",
|
|
64
|
+
toolbar: { title: "Theme", icon: "mirror", items: ["light", "dark"], dynamicTitle: true },
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
initialGlobals: { theme: "light" },
|
|
68
|
+
decorators: [
|
|
69
|
+
(Story, context) => (_jsx(StoryRoot, { theme: storyTheme(context.globals.theme), options: options, children: _jsx(Story, {}) })),
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wwchen/stack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Shared Next.js, Neon, Better Auth, Resend and lew-ds building blocks.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -79,6 +79,10 @@
|
|
|
79
79
|
},
|
|
80
80
|
"./ui/globals.css": "./dist/ui/globals.css",
|
|
81
81
|
"./ui/app.css": "./dist/ui/app.css",
|
|
82
|
+
"./storybook": {
|
|
83
|
+
"types": "./dist/storybook/index.d.ts",
|
|
84
|
+
"default": "./dist/storybook/index.js"
|
|
85
|
+
},
|
|
82
86
|
"./configs/tsconfig.next.json": "./configs/tsconfig.next.json",
|
|
83
87
|
"./configs/biome.json": "./configs/biome.json",
|
|
84
88
|
"./configs/vitest": {
|
|
@@ -108,10 +112,12 @@
|
|
|
108
112
|
"@lew-ds/lds": "1.2.0",
|
|
109
113
|
"@lew-ds/lds-react": "2.0.0",
|
|
110
114
|
"@lew-ds/open-icons": "1.1.0",
|
|
115
|
+
"@storybook/nextjs-vite": "10.6.2",
|
|
111
116
|
"drizzle-orm": "0.45.4",
|
|
112
117
|
"next": "16.4.6",
|
|
113
118
|
"react": "19.3.1",
|
|
114
|
-
"react-dom": "19.3.1"
|
|
119
|
+
"react-dom": "19.3.1",
|
|
120
|
+
"storybook": "10.6.2"
|
|
115
121
|
},
|
|
116
122
|
"peerDependenciesMeta": {
|
|
117
123
|
"@electric-sql/pglite": {
|
|
@@ -119,16 +125,24 @@
|
|
|
119
125
|
},
|
|
120
126
|
"@electric-sql/pglite-socket": {
|
|
121
127
|
"optional": true
|
|
128
|
+
},
|
|
129
|
+
"@storybook/nextjs-vite": {
|
|
130
|
+
"optional": true
|
|
131
|
+
},
|
|
132
|
+
"storybook": {
|
|
133
|
+
"optional": true
|
|
122
134
|
}
|
|
123
135
|
},
|
|
124
136
|
"devDependencies": {
|
|
125
137
|
"@electric-sql/pglite": "0.5.10",
|
|
126
138
|
"@electric-sql/pglite-socket": "0.2.13",
|
|
139
|
+
"@storybook/nextjs-vite": "10.6.2",
|
|
127
140
|
"@types/node": "^24.19.2",
|
|
128
141
|
"@types/pg": "^8.23.1",
|
|
129
142
|
"@types/react": "19.3.0",
|
|
130
143
|
"@types/react-dom": "19.3.0",
|
|
131
144
|
"drizzle-kit": "0.31.11",
|
|
145
|
+
"storybook": "10.6.2",
|
|
132
146
|
"tailwindcss": "4.3.3",
|
|
133
147
|
"typescript": "~6.0.3",
|
|
134
148
|
"vitest": "5.0.5"
|