@soroush.design/cli 0.2.0-alpha.2 → 0.2.0-alpha.4
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 +9 -112
- package/dist/bin.mjs +1 -1
- package/dist/index.d.mts +14 -3
- package/dist/index.mjs +1 -1
- package/dist/{io-uDtjQuG6.mjs → io-C_8_JerZ.mjs} +579 -643
- package/package.json +26 -5
- package/templates/astro/js/base/README.md +93 -0
- package/templates/astro/js/base/_gitignore +5 -0
- package/templates/astro/js/base/astro.config.mjs +23 -0
- package/templates/astro/js/base/src/components/About.jsx +24 -0
- package/templates/astro/js/base/src/components/Counter.jsx +26 -0
- package/templates/astro/js/base/src/components/Greeting.jsx +60 -0
- package/templates/astro/js/base/src/components/Header.jsx +99 -0
- package/templates/astro/js/base/src/components/Home.jsx +32 -0
- package/templates/astro/js/base/src/components/Home.test.jsx +39 -0
- package/templates/astro/js/base/src/components/NotFound.jsx +17 -0
- package/templates/astro/js/base/src/data/api.js +84 -0
- package/templates/astro/js/base/src/layouts/Layout.astro +52 -0
- package/templates/astro/js/base/src/pages/404.astro +12 -0
- package/templates/astro/js/base/src/pages/about.astro +12 -0
- package/templates/astro/js/base/src/pages/index.astro +23 -0
- package/templates/astro/js/base/src/theme/Island.jsx +89 -0
- package/templates/astro/js/base/src/theme/scheme.js +32 -0
- package/templates/astro/js/base/vitest.config.js +12 -0
- package/templates/astro/js/sample-data/src/components/ItemDetails.jsx +64 -0
- package/templates/astro/js/sample-data/src/components/ItemList.jsx +100 -0
- package/templates/astro/js/sample-data/src/components/StatusChip.jsx +8 -0
- package/templates/astro/js/sample-data/src/data/items.js +65 -0
- package/templates/astro/js/sample-data/src/pages/items/[id].astro +37 -0
- package/templates/astro/js/sample-data/src/pages/items/index.astro +20 -0
- package/templates/astro/js/with/jotai/src/components/Counter.jsx +26 -0
- package/templates/astro/js/with/jotai/src/state/counter.js +4 -0
- package/templates/astro/js/with/msw/_env +3 -0
- package/templates/astro/js/with/msw/src/mocks/browser.js +5 -0
- package/templates/astro/js/with/msw/src/mocks/handlers.js +24 -0
- package/templates/astro/js/with/msw/src/mocks/server.js +5 -0
- package/templates/astro/js/with/msw/src/mocks/setupTests.js +7 -0
- package/templates/astro/js/with/msw/src/mocks/start.js +14 -0
- package/templates/astro/js/with/react-hook-form/src/components/Form.jsx +313 -0
- package/templates/astro/js/with/react-hook-form/src/pages/form.astro +8 -0
- package/templates/astro/js/with/redux-toolkit/src/components/Counter.jsx +27 -0
- package/templates/astro/js/with/redux-toolkit/src/state/store.js +18 -0
- package/templates/astro/js/with/tanstack-query/src/data/queryClient.js +13 -0
- package/templates/astro/js/with/zustand/src/components/Counter.jsx +24 -0
- package/templates/astro/js/with/zustand/src/state/counter.js +14 -0
- package/templates/astro/ts/base/README.md +93 -0
- package/templates/astro/ts/base/_gitignore +5 -0
- package/templates/astro/ts/base/astro.config.mjs +23 -0
- package/templates/astro/ts/base/src/components/About.tsx +24 -0
- package/templates/astro/ts/base/src/components/Counter.tsx +26 -0
- package/templates/astro/ts/base/src/components/Greeting.tsx +61 -0
- package/templates/astro/ts/base/src/components/Header.tsx +99 -0
- package/templates/astro/ts/base/src/components/Home.test.tsx +39 -0
- package/templates/astro/ts/base/src/components/Home.tsx +33 -0
- package/templates/astro/ts/base/src/components/NotFound.tsx +17 -0
- package/templates/astro/ts/base/src/data/api.ts +92 -0
- package/templates/astro/ts/base/src/layouts/Layout.astro +52 -0
- package/templates/astro/ts/base/src/pages/404.astro +12 -0
- package/templates/astro/ts/base/src/pages/about.astro +12 -0
- package/templates/astro/ts/base/src/pages/index.astro +23 -0
- package/templates/astro/ts/base/src/theme/Island.tsx +90 -0
- package/templates/astro/ts/base/src/theme/scheme.ts +34 -0
- package/templates/astro/ts/base/tsconfig.json +9 -0
- package/templates/astro/ts/base/vitest.config.ts +12 -0
- package/templates/astro/ts/sample-data/src/components/ItemDetails.tsx +65 -0
- package/templates/astro/ts/sample-data/src/components/ItemList.tsx +109 -0
- package/templates/astro/ts/sample-data/src/components/StatusChip.tsx +9 -0
- package/templates/astro/ts/sample-data/src/data/items.ts +71 -0
- package/templates/astro/ts/sample-data/src/pages/items/[id].astro +39 -0
- package/templates/astro/ts/sample-data/src/pages/items/index.astro +20 -0
- package/templates/astro/ts/with/jotai/src/components/Counter.tsx +26 -0
- package/templates/astro/ts/with/jotai/src/state/counter.ts +4 -0
- package/templates/astro/ts/with/msw/_env +3 -0
- package/templates/astro/ts/with/msw/src/mocks/browser.ts +5 -0
- package/templates/astro/ts/with/msw/src/mocks/handlers.ts +24 -0
- package/templates/astro/ts/with/msw/src/mocks/server.ts +5 -0
- package/templates/astro/ts/with/msw/src/mocks/setupTests.ts +7 -0
- package/templates/astro/ts/with/msw/src/mocks/start.ts +14 -0
- package/templates/astro/ts/with/react-hook-form/src/components/Form.tsx +317 -0
- package/templates/astro/ts/with/react-hook-form/src/pages/form.astro +8 -0
- package/templates/astro/ts/with/redux-toolkit/src/components/Counter.tsx +27 -0
- package/templates/astro/ts/with/redux-toolkit/src/state/store.ts +19 -0
- package/templates/astro/ts/with/tanstack-query/src/data/queryClient.ts +13 -0
- package/templates/astro/ts/with/zustand/src/components/Counter.tsx +24 -0
- package/templates/astro/ts/with/zustand/src/state/counter.ts +19 -0
- package/templates/templates.md +66 -0
- package/templates/vike/js/base/README.md +87 -0
- package/templates/vike/js/base/_gitignore +4 -0
- package/templates/vike/js/base/src/data/api.js +76 -0
- package/templates/vike/js/base/src/pages/+Layout.jsx +183 -0
- package/templates/vike/js/base/src/pages/+config.js +12 -0
- package/templates/vike/js/base/src/pages/+onRenderClient.jsx +39 -0
- package/templates/vike/js/base/src/pages/+onRenderHtml.jsx +27 -0
- package/templates/vike/js/base/src/pages/PageShell.jsx +47 -0
- package/templates/vike/js/base/src/pages/_error/+Page.jsx +14 -0
- package/templates/vike/js/base/src/pages/about/+Page.jsx +14 -0
- package/templates/vike/js/base/src/pages/index/+Page.jsx +33 -0
- package/templates/vike/js/base/src/pages/index/Counter.jsx +20 -0
- package/templates/vike/js/base/src/pages/index/Greeting.jsx +48 -0
- package/templates/vike/js/base/src/pages/index/Page.test.jsx +67 -0
- package/templates/vike/js/base/src/pages/usePageContext.jsx +20 -0
- package/templates/vike/js/base/vite.config.js +14 -0
- package/templates/vike/js/base/vitest.config.js +13 -0
- package/templates/vike/js/sample-data/src/data/items.js +58 -0
- package/templates/vike/js/sample-data/src/pages/items/+Page.jsx +49 -0
- package/templates/vike/js/sample-data/src/pages/items/+data.js +26 -0
- package/templates/vike/js/sample-data/src/pages/items/@id/+Page.jsx +40 -0
- package/templates/vike/js/sample-data/src/pages/items/@id/+data.js +33 -0
- package/templates/vike/js/sample-data/src/pages/items/@id/+onBeforePrerenderStart.js +8 -0
- package/templates/vike/js/sample-data/src/pages/items/StatusChip.jsx +8 -0
- package/templates/vike/js/spa/src/pages/+config.js +12 -0
- package/templates/vike/js/spa/src/pages/+onRenderClient.jsx +25 -0
- package/templates/vike/js/spa/src/pages/+onRenderHtml.jsx +16 -0
- package/templates/vike/js/spa/src/pages/about/+Page.jsx +14 -0
- package/templates/vike/js/ssg/src/pages/+config.js +11 -0
- package/templates/vike/js/ssg/src/pages/about/+Page.jsx +13 -0
- package/templates/vike/js/ssr/src/pages/+config.js +12 -0
- package/templates/vike/js/ssr/src/pages/+onRenderHtml.jsx +27 -0
- package/templates/vike/js/ssr/src/pages/about/+Page.jsx +14 -0
- package/templates/vike/js/with/jotai/src/pages/index/Counter.jsx +19 -0
- package/templates/vike/js/with/jotai/src/state/counter.js +4 -0
- package/templates/vike/js/with/jotai/src/state/scheme.js +4 -0
- package/templates/vike/js/with/msw/_env +3 -0
- package/templates/vike/js/with/msw/src/mocks/browser.js +5 -0
- package/templates/vike/js/with/msw/src/mocks/handlers.js +24 -0
- package/templates/vike/js/with/msw/src/mocks/server.js +5 -0
- package/templates/vike/js/with/msw/src/mocks/setupTests.js +7 -0
- package/templates/vike/js/with/msw/src/mocks/start.js +10 -0
- package/templates/vike/js/with/react-hook-form/src/pages/form/+Page.jsx +294 -0
- package/templates/vike/js/with/redux-toolkit/src/pages/index/Counter.jsx +20 -0
- package/templates/vike/js/with/redux-toolkit/src/state/store.js +27 -0
- package/templates/vike/js/with/zustand/src/pages/index/Counter.jsx +17 -0
- package/templates/vike/js/with/zustand/src/state/counter.js +14 -0
- package/templates/vike/js/with/zustand/src/state/scheme.js +14 -0
- package/templates/vike/ts/base/README.md +87 -0
- package/templates/vike/ts/base/_gitignore +4 -0
- package/templates/vike/ts/base/src/data/api.ts +84 -0
- package/templates/vike/ts/base/src/pages/+Layout.tsx +184 -0
- package/templates/vike/ts/base/src/pages/+config.ts +14 -0
- package/templates/vike/ts/base/src/pages/+onRenderClient.tsx +41 -0
- package/templates/vike/ts/base/src/pages/+onRenderHtml.tsx +28 -0
- package/templates/vike/ts/base/src/pages/PageShell.tsx +48 -0
- package/templates/vike/ts/base/src/pages/_error/+Page.tsx +14 -0
- package/templates/vike/ts/base/src/pages/about/+Page.tsx +14 -0
- package/templates/vike/ts/base/src/pages/index/+Page.tsx +33 -0
- package/templates/vike/ts/base/src/pages/index/Counter.tsx +20 -0
- package/templates/vike/ts/base/src/pages/index/Greeting.tsx +49 -0
- package/templates/vike/ts/base/src/pages/index/Page.test.tsx +67 -0
- package/templates/vike/ts/base/src/pages/usePageContext.tsx +27 -0
- package/templates/vike/ts/base/src/vike.d.ts +20 -0
- package/templates/vike/ts/base/tsconfig.json +18 -0
- package/templates/vike/ts/base/vite.config.ts +14 -0
- package/templates/vike/ts/base/vitest.config.ts +13 -0
- package/templates/vike/ts/sample-data/src/data/items.ts +64 -0
- package/templates/vike/ts/sample-data/src/pages/items/+Page.tsx +50 -0
- package/templates/vike/ts/sample-data/src/pages/items/+data.ts +28 -0
- package/templates/vike/ts/sample-data/src/pages/items/@id/+Page.tsx +41 -0
- package/templates/vike/ts/sample-data/src/pages/items/@id/+data.ts +37 -0
- package/templates/vike/ts/sample-data/src/pages/items/@id/+onBeforePrerenderStart.ts +8 -0
- package/templates/vike/ts/sample-data/src/pages/items/StatusChip.tsx +9 -0
- package/templates/vike/ts/spa/src/pages/+config.ts +14 -0
- package/templates/vike/ts/spa/src/pages/+onRenderClient.tsx +27 -0
- package/templates/vike/ts/spa/src/pages/+onRenderHtml.tsx +17 -0
- package/templates/vike/ts/spa/src/pages/about/+Page.tsx +14 -0
- package/templates/vike/ts/ssg/src/pages/+config.ts +13 -0
- package/templates/vike/ts/ssg/src/pages/about/+Page.tsx +13 -0
- package/templates/vike/ts/ssr/src/pages/+config.ts +14 -0
- package/templates/vike/ts/ssr/src/pages/+onRenderHtml.tsx +28 -0
- package/templates/vike/ts/ssr/src/pages/about/+Page.tsx +14 -0
- package/templates/vike/ts/with/jotai/src/pages/index/Counter.tsx +19 -0
- package/templates/vike/ts/with/jotai/src/state/counter.ts +4 -0
- package/templates/vike/ts/with/jotai/src/state/scheme.ts +4 -0
- package/templates/vike/ts/with/msw/_env +3 -0
- package/templates/vike/ts/with/msw/src/mocks/browser.ts +5 -0
- package/templates/vike/ts/with/msw/src/mocks/handlers.ts +24 -0
- package/templates/vike/ts/with/msw/src/mocks/server.ts +5 -0
- package/templates/vike/ts/with/msw/src/mocks/setupTests.ts +7 -0
- package/templates/vike/ts/with/msw/src/mocks/start.ts +10 -0
- package/templates/vike/ts/with/react-hook-form/src/pages/form/+Page.tsx +298 -0
- package/templates/vike/ts/with/redux-toolkit/src/pages/index/Counter.tsx +20 -0
- package/templates/vike/ts/with/redux-toolkit/src/state/store.ts +29 -0
- package/templates/vike/ts/with/zustand/src/pages/index/Counter.tsx +17 -0
- package/templates/vike/ts/with/zustand/src/state/counter.ts +19 -0
- package/templates/vike/ts/with/zustand/src/state/scheme.ts +19 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soroush.design/cli",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.4",
|
|
4
4
|
"description": "The command line of the @soroush.tech design system: init sets it up in an existing React app, and create starts a new one, each showing every change first.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"type": "module",
|
|
24
24
|
"sideEffects": false,
|
|
25
25
|
"files": [
|
|
26
|
-
"dist"
|
|
26
|
+
"dist",
|
|
27
|
+
"templates"
|
|
27
28
|
],
|
|
28
29
|
"bin": {
|
|
29
30
|
"soroush-design": "./dist/bin.mjs"
|
|
@@ -39,29 +40,49 @@
|
|
|
39
40
|
"access": "public"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
43
|
+
"@astrojs/check": "^0.9.12",
|
|
44
|
+
"@astrojs/node": "^11.1.13",
|
|
45
|
+
"@astrojs/react": "^7.1.9",
|
|
42
46
|
"@emotion/server": "^11.11.0",
|
|
47
|
+
"@hookform/resolvers": "^7.0.6",
|
|
48
|
+
"@reduxjs/toolkit": "^2.14.0",
|
|
49
|
+
"@tanstack/react-query": "^5.107.1",
|
|
50
|
+
"@testing-library/dom": "^10.4.2",
|
|
51
|
+
"@testing-library/react": "^16.3.3",
|
|
43
52
|
"@types/node": "^26.6.6",
|
|
44
53
|
"@types/react": "^19.3.0",
|
|
45
54
|
"@types/react-dom": "^19.3.0",
|
|
46
55
|
"@vitejs/plugin-react": "^6.3.0",
|
|
47
56
|
"@vitest/coverage-v8": "^5.1.0",
|
|
57
|
+
"astro": "^7.4.12",
|
|
58
|
+
"jotai": "^3.0.2",
|
|
59
|
+
"jsdom": "^31.0.1",
|
|
60
|
+
"msw": "^3.0.5",
|
|
48
61
|
"oxlint": "^1.93.0",
|
|
49
62
|
"react": "^19.3.1",
|
|
50
63
|
"react-dom": "^19.3.1",
|
|
64
|
+
"react-hook-form": "^7.92.0",
|
|
65
|
+
"react-redux": "^9.3.1",
|
|
66
|
+
"swr": "^2.5.1",
|
|
67
|
+
"ts-blank-space": "^0.9.0",
|
|
51
68
|
"tsdown": "^0.23.7",
|
|
52
69
|
"typescript": "~7.0.2",
|
|
70
|
+
"typescript-astro": "npm:typescript@^6.0.3",
|
|
53
71
|
"vike": "0.4.270",
|
|
54
72
|
"vite": "~8.3.8",
|
|
55
73
|
"vitest": "^5.1.0",
|
|
74
|
+
"zod": "^4.6.7",
|
|
75
|
+
"zustand": "^5.1.0",
|
|
56
76
|
"@soroush.tech/eslint-config": "0.0.0"
|
|
57
77
|
},
|
|
58
78
|
"scripts": {
|
|
59
|
-
"build": "tsdown",
|
|
60
|
-
"lint": "oxlint --deny-warnings",
|
|
79
|
+
"build": "node scripts/gen-templates.mjs && tsdown",
|
|
80
|
+
"lint": "oxlint --deny-warnings --ignore-pattern=templates/**",
|
|
61
81
|
"typecheck": "tsc --noEmit",
|
|
62
82
|
"test": "vitest run",
|
|
63
83
|
"test:coverage": "vitest run --coverage",
|
|
64
|
-
"test:types": "pnpm --filter @soroush.tech/design-system build && tsc -p type-tests/init/tsconfig.json && tsc -p type-tests/tsconfig.create-vike.json && tsc -p type-tests/tsconfig.create-vike-spa.json && tsc -p type-tests/tsconfig.create-vike-ssg.json"
|
|
84
|
+
"test:types": "pnpm --filter @soroush.tech/design-system build && tsc -p type-tests/init/tsconfig.json && tsc -p type-tests/tsconfig.create-vike.json && tsc -p type-tests/tsconfig.create-vike-spa.json && tsc -p type-tests/tsconfig.create-vike-ssg.json && tsc -p type-tests/tsconfig.create-vike-ssr.json && tsc -p type-tests/tsconfig.create-vike-libraries.json && tsc -p type-tests/tsconfig.create-vike-jotai.json && tsc -p type-tests/tsconfig.create-vike-more.json && tsc -p type-tests/tsconfig.create-astro.json && tsc -p type-tests/tsconfig.create-astro-ssg.json && tsc -p type-tests/tsconfig.create-astro-ssr.json && tsc -p type-tests/tsconfig.create-astro-libraries.json && tsc -p type-tests/tsconfig.create-astro-more.json",
|
|
85
|
+
"gen:templates": "node scripts/gen-templates.mjs"
|
|
65
86
|
},
|
|
66
87
|
"module": "./dist/index.mjs"
|
|
67
88
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# __TITLE__
|
|
2
|
+
|
|
3
|
+
An [Astro](https://astro.build) app on the [@soroush.tech design system](https://docs.soroush.tech):
|
|
4
|
+
<!-- @if isomorphic -->
|
|
5
|
+
every page is HTML from the build, with its styles, and its parts are React islands
|
|
6
|
+
that hydrate in the browser. Astro's client router moves between pages with no reload.
|
|
7
|
+
<!-- @elif ssr -->
|
|
8
|
+
every page is rendered on the server, on each request, with its styles, and its parts are
|
|
9
|
+
React islands that hydrate in the browser. Astro's client router moves between pages with no
|
|
10
|
+
reload.
|
|
11
|
+
<!-- @else -->
|
|
12
|
+
every page is HTML from the build, with its styles, and no JavaScript in the browser: its
|
|
13
|
+
React parts render at build time only.
|
|
14
|
+
<!-- @endif -->
|
|
15
|
+
|
|
16
|
+
- `npm run dev` starts it, `npm run build` builds it, and `npm run preview` serves the build.
|
|
17
|
+
<!-- @if ssr -->
|
|
18
|
+
- `npm start` runs the server the build wrote, on `HOST` and `PORT` (4321 by default), on any
|
|
19
|
+
Node host.
|
|
20
|
+
<!-- @endif -->
|
|
21
|
+
- `src/pages/` holds the pages: an `.astro` file per route, which renders a component of
|
|
22
|
+
`src/components/` in `src/layouts/Layout.astro`.
|
|
23
|
+
- `src/components/Header.jsx` draws the header, inside the app's providers, which draw the base
|
|
24
|
+
styles once a page.
|
|
25
|
+
<!-- @if ssg -->
|
|
26
|
+
- Each React part of a page renders inside `Island`, at build time.
|
|
27
|
+
<!-- @else -->
|
|
28
|
+
- Each React part of a page is an island, a React root of its own: it renders inside
|
|
29
|
+
`Island` (`src/theme/Island.jsx`), and the islands share the color scheme through
|
|
30
|
+
`src/theme/scheme.js`, not context.
|
|
31
|
+
- The home page's counter is an island of its own, which renders in the browser only
|
|
32
|
+
(`client:only`), so the count it shows is the one in memory, not the build's.
|
|
33
|
+
- `src/layouts/Layout.astro` keeps the design system's styles as the client router moves
|
|
34
|
+
between pages.
|
|
35
|
+
<!-- @endif -->
|
|
36
|
+
- `src/theme/themes.js` holds the light and the dark theme: make them your own.
|
|
37
|
+
<!-- @if sample-data && ssr -->
|
|
38
|
+
- `src/pages/items/` lists the sample items of `src/data/items.js`, with a page for each,
|
|
39
|
+
read on each request: make them fetch your own.
|
|
40
|
+
<!-- @elif sample-data -->
|
|
41
|
+
- `src/pages/items/` lists the sample items of `src/data/items.js`, with a page for each,
|
|
42
|
+
read at build time: make them fetch your own.
|
|
43
|
+
<!-- @endif -->
|
|
44
|
+
<!-- @if tanstack-query && react-hook-form -->
|
|
45
|
+
- [TanStack Query](https://tanstack.com/query): every island's `Island` provides one query client,
|
|
46
|
+
`src/data/queryClient.js`. The home page's `Greeting` reads `src/data/api.js` with a query,
|
|
47
|
+
and the form sends its values with a mutation.
|
|
48
|
+
<!-- @elif tanstack-query -->
|
|
49
|
+
- [TanStack Query](https://tanstack.com/query): every island's `Island` provides one query client,
|
|
50
|
+
`src/data/queryClient.js`. The home page's `Greeting` reads `src/data/api.js` with a query.
|
|
51
|
+
<!-- @endif -->
|
|
52
|
+
<!-- @if swr && react-hook-form -->
|
|
53
|
+
- [SWR](https://swr.vercel.app): the home page's `Greeting` reads `src/data/api.js` with SWR,
|
|
54
|
+
and the form sends its values with a mutation.
|
|
55
|
+
<!-- @elif swr -->
|
|
56
|
+
- [SWR](https://swr.vercel.app): the home page's `Greeting` reads `src/data/api.js` with SWR.
|
|
57
|
+
<!-- @endif -->
|
|
58
|
+
<!-- @if (tanstack-query || swr) && sample-data -->
|
|
59
|
+
The items pages start on the items they were rendered with, then fetch them again in the
|
|
60
|
+
browser.
|
|
61
|
+
<!-- @endif -->
|
|
62
|
+
<!-- @if msw -->
|
|
63
|
+
- [msw](https://mswjs.io): `src/mocks/handlers.js` is a mock API, which answers the requests of
|
|
64
|
+
`src/data/api.js` in the browser while `PUBLIC_MSW` in `.env` is true, and in the tests
|
|
65
|
+
through msw's Node server, `src/mocks/server.js`.
|
|
66
|
+
<!-- @endif -->
|
|
67
|
+
<!-- @if zustand -->
|
|
68
|
+
- [zustand](https://zustand.docs.pmnd.rs): `src/state/counter.js` holds the home page's count, in
|
|
69
|
+
a store every island shares.
|
|
70
|
+
<!-- @elif jotai -->
|
|
71
|
+
- [Jotai](https://jotai.org): `src/state/counter.js` holds the home page's count, in an atom
|
|
72
|
+
every island shares.
|
|
73
|
+
<!-- @elif redux-toolkit -->
|
|
74
|
+
- [Redux Toolkit](https://redux-toolkit.js.org): `src/state/store.js` holds the home page's
|
|
75
|
+
count, in a slice of the store every island's `Island` provides.
|
|
76
|
+
<!-- @endif -->
|
|
77
|
+
<!-- @if react-hook-form -->
|
|
78
|
+
- [React Hook Form](https://react-hook-form.com) and [Zod](https://zod.dev): `/form` is a form
|
|
79
|
+
whose values a Zod schema checks.
|
|
80
|
+
<!-- @endif -->
|
|
81
|
+
<!-- @if ssg -->
|
|
82
|
+
- [Vitest](https://vitest.dev) and [Testing Library](https://testing-library.com): `npm run test`
|
|
83
|
+
runs `src/components/Home.test.jsx`, which checks the title.
|
|
84
|
+
<!-- @elif msw -->
|
|
85
|
+
- [Vitest](https://vitest.dev) and [Testing Library](https://testing-library.com): `npm run test`
|
|
86
|
+
runs `src/components/Home.test.jsx`, which checks the title, the counter and the greeting.
|
|
87
|
+
<!-- @else -->
|
|
88
|
+
- [Vitest](https://vitest.dev) and [Testing Library](https://testing-library.com): `npm run test`
|
|
89
|
+
runs `src/components/Home.test.jsx`, which checks the title and the counter.
|
|
90
|
+
<!-- @endif -->
|
|
91
|
+
|
|
92
|
+
Fonts: the theme names Space Grotesk and JetBrains Mono, and does not load them. See
|
|
93
|
+
https://docs.soroush.tech/design-system/getting-started/installation/#fonts
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @if ssr
|
|
2
|
+
import node from '@astrojs/node'
|
|
3
|
+
// @endif
|
|
4
|
+
import react from '@astrojs/react'
|
|
5
|
+
// @if msw
|
|
6
|
+
import { msw } from 'msw/vite'
|
|
7
|
+
// @endif
|
|
8
|
+
import { defineConfig } from 'astro/config'
|
|
9
|
+
|
|
10
|
+
// The settings of the app: https://docs.astro.build/en/reference/configuration-reference/
|
|
11
|
+
export default defineConfig({
|
|
12
|
+
// @if ssr
|
|
13
|
+
// SSR: every page is rendered on the server, on each request, by the Node server the build
|
|
14
|
+
// writes: npm start.
|
|
15
|
+
output: 'server',
|
|
16
|
+
adapter: node({ mode: 'standalone' }),
|
|
17
|
+
// @endif
|
|
18
|
+
integrations: [react()],
|
|
19
|
+
// @if msw
|
|
20
|
+
// msw's plugin serves the mock API's worker, in development and in the build.
|
|
21
|
+
vite: { plugins: [msw({ mode: 'worker-only' })] },
|
|
22
|
+
// @endif
|
|
23
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
2
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
3
|
+
import { withIsland } from '../theme/Island'
|
|
4
|
+
|
|
5
|
+
function About() {
|
|
6
|
+
return (
|
|
7
|
+
<Flex gap={2} px={3} py={4}>
|
|
8
|
+
<Typography variant="h2">About</Typography>
|
|
9
|
+
<Typography color="secondary">
|
|
10
|
+
{/* @if ssr */}
|
|
11
|
+
A second page: the server renders it, with its styles, and the app moves to it without a
|
|
12
|
+
reload.
|
|
13
|
+
{/* @elif ssg */}
|
|
14
|
+
A second page: it is HTML with its styles from the build, and a link loads it as a new page.
|
|
15
|
+
{/* @else */}
|
|
16
|
+
A second page: it is HTML with its styles from the build, and the app moves to it without a
|
|
17
|
+
reload.
|
|
18
|
+
{/* @endif */}
|
|
19
|
+
</Typography>
|
|
20
|
+
</Flex>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default withIsland(About)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @if !ssg
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import { Button } from '@soroush.tech/design-system/Button'
|
|
4
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
5
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
6
|
+
import { withIsland } from '../theme/Island'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A count, held in the component's own state, and the button that adds to it. An island of its
|
|
10
|
+
* own, which renders in the browser only.
|
|
11
|
+
*/
|
|
12
|
+
function Counter() {
|
|
13
|
+
const [count, setCount] = useState(0)
|
|
14
|
+
const increment = () => setCount(count + 1)
|
|
15
|
+
return (
|
|
16
|
+
<Flex flexDirection="row" alignItems="center" gap={2}>
|
|
17
|
+
<Button size="sm" variant="outlined" onClick={increment}>
|
|
18
|
+
Count
|
|
19
|
+
</Button>
|
|
20
|
+
<Typography>Count: {count}</Typography>
|
|
21
|
+
</Flex>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default withIsland(Counter)
|
|
26
|
+
// @endif
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// @if tanstack-query || swr || msw
|
|
2
|
+
// @if tanstack-query
|
|
3
|
+
import { useQuery } from '@tanstack/react-query'
|
|
4
|
+
// @elif swr
|
|
5
|
+
import useSWR from 'swr'
|
|
6
|
+
// @else
|
|
7
|
+
import { useEffect, useState } from 'react'
|
|
8
|
+
// @endif
|
|
9
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
10
|
+
// @if !tanstack-query && !swr
|
|
11
|
+
// @endif
|
|
12
|
+
import { fetchGreeting } from '../data/api'
|
|
13
|
+
import { withIsland } from '../theme/Island'
|
|
14
|
+
|
|
15
|
+
// @if tanstack-query
|
|
16
|
+
/**
|
|
17
|
+
* What the API says, read with a query of TanStack Query. An island of its own, which renders in
|
|
18
|
+
* the browser only, where the query runs.
|
|
19
|
+
*/
|
|
20
|
+
function Greeting() {
|
|
21
|
+
const { data } = useQuery({ queryKey: ['greeting'], queryFn: fetchGreeting })
|
|
22
|
+
return (
|
|
23
|
+
<Typography color="secondary">
|
|
24
|
+
{data ? data.message : 'Asking the API for a greeting...'}
|
|
25
|
+
</Typography>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
// @elif swr
|
|
29
|
+
/**
|
|
30
|
+
* What the API says, read with SWR. An island of its own, which renders in the browser only,
|
|
31
|
+
* where SWR runs.
|
|
32
|
+
*/
|
|
33
|
+
function Greeting() {
|
|
34
|
+
const { data } = useSWR('greeting', fetchGreeting)
|
|
35
|
+
return (
|
|
36
|
+
<Typography color="secondary">
|
|
37
|
+
{data ? data.message : 'Asking the API for a greeting...'}
|
|
38
|
+
</Typography>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
// @else
|
|
42
|
+
/**
|
|
43
|
+
* What the API says, read with fetch, as the island loads. An island of its own, which renders in
|
|
44
|
+
* the browser only.
|
|
45
|
+
*/
|
|
46
|
+
function Greeting() {
|
|
47
|
+
const [data, setData] = useState()
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
fetchGreeting().then(setData, () => setData({ message: 'The API did not answer.' }))
|
|
50
|
+
}, [])
|
|
51
|
+
return (
|
|
52
|
+
<Typography color="secondary">
|
|
53
|
+
{data ? data.message : 'Asking the API for a greeting...'}
|
|
54
|
+
</Typography>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
// @endif
|
|
58
|
+
|
|
59
|
+
export default withIsland(Greeting)
|
|
60
|
+
// @endif
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// @if !ssg
|
|
2
|
+
import { Button } from '@soroush.tech/design-system/Button'
|
|
3
|
+
// @endif
|
|
4
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
5
|
+
import { Link } from '@soroush.tech/design-system/Link'
|
|
6
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
7
|
+
import { Providers } from '../theme/Providers'
|
|
8
|
+
// @if !ssg
|
|
9
|
+
import { setScheme, useScheme } from '../theme/scheme'
|
|
10
|
+
// @endif
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
// @if ssg
|
|
14
|
+
* The header of every page. Its Providers draw the base styles, once a
|
|
15
|
+
* page.
|
|
16
|
+
// @else
|
|
17
|
+
* The header of every page, an island of its own. Its Providers draw the base styles, once a
|
|
18
|
+
* page, and its button switches the scheme of every island.
|
|
19
|
+
// @endif
|
|
20
|
+
*/
|
|
21
|
+
// @if ssg
|
|
22
|
+
export default function Header() {
|
|
23
|
+
return (
|
|
24
|
+
<Providers>
|
|
25
|
+
<Flex
|
|
26
|
+
as="header"
|
|
27
|
+
flexDirection="row"
|
|
28
|
+
alignItems="center"
|
|
29
|
+
justifyContent="space-between"
|
|
30
|
+
gap={2}
|
|
31
|
+
px={3}
|
|
32
|
+
py={2}
|
|
33
|
+
bg="paper"
|
|
34
|
+
>
|
|
35
|
+
<Typography variant="h6" as="span">
|
|
36
|
+
__TITLE__
|
|
37
|
+
</Typography>
|
|
38
|
+
<Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
|
|
39
|
+
<Link href="/" underline="hover">
|
|
40
|
+
Home
|
|
41
|
+
</Link>
|
|
42
|
+
<Link href="/about" underline="hover">
|
|
43
|
+
About
|
|
44
|
+
</Link>
|
|
45
|
+
{/* @if sample-data */}
|
|
46
|
+
<Link href="/items" underline="hover">
|
|
47
|
+
Items
|
|
48
|
+
</Link>
|
|
49
|
+
{/* @endif */}
|
|
50
|
+
</Flex>
|
|
51
|
+
</Flex>
|
|
52
|
+
</Providers>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
// @else
|
|
56
|
+
export default function Header() {
|
|
57
|
+
const scheme = useScheme()
|
|
58
|
+
const otherScheme = scheme === 'light' ? 'dark' : 'light'
|
|
59
|
+
return (
|
|
60
|
+
<Providers scheme={scheme}>
|
|
61
|
+
<Flex
|
|
62
|
+
as="header"
|
|
63
|
+
flexDirection="row"
|
|
64
|
+
alignItems="center"
|
|
65
|
+
justifyContent="space-between"
|
|
66
|
+
gap={2}
|
|
67
|
+
px={3}
|
|
68
|
+
py={2}
|
|
69
|
+
bg="paper"
|
|
70
|
+
>
|
|
71
|
+
<Typography variant="h6" as="span">
|
|
72
|
+
__TITLE__
|
|
73
|
+
</Typography>
|
|
74
|
+
<Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
|
|
75
|
+
<Link href="/" underline="hover">
|
|
76
|
+
Home
|
|
77
|
+
</Link>
|
|
78
|
+
<Link href="/about" underline="hover">
|
|
79
|
+
About
|
|
80
|
+
</Link>
|
|
81
|
+
{/* @if sample-data */}
|
|
82
|
+
<Link href="/items" underline="hover">
|
|
83
|
+
Items
|
|
84
|
+
</Link>
|
|
85
|
+
{/* @endif */}
|
|
86
|
+
{/* @if react-hook-form */}
|
|
87
|
+
<Link href="/form" underline="hover">
|
|
88
|
+
Form
|
|
89
|
+
</Link>
|
|
90
|
+
{/* @endif */}
|
|
91
|
+
<Button size="sm" variant="outlined" onClick={() => setScheme(otherScheme)}>
|
|
92
|
+
{otherScheme}
|
|
93
|
+
</Button>
|
|
94
|
+
</Flex>
|
|
95
|
+
</Flex>
|
|
96
|
+
</Providers>
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
// @endif
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Button } from '@soroush.tech/design-system/Button'
|
|
2
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
3
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
4
|
+
import { withIsland } from '../theme/Island'
|
|
5
|
+
|
|
6
|
+
// @if ssg
|
|
7
|
+
/** The home page. */
|
|
8
|
+
// @elif tanstack-query || swr || msw
|
|
9
|
+
/** The home page. Its children are the islands of its greeting and its counter. */
|
|
10
|
+
// @else
|
|
11
|
+
/** The home page. Its child is the island of its counter. */
|
|
12
|
+
// @endif
|
|
13
|
+
function Home({ children }) {
|
|
14
|
+
return (
|
|
15
|
+
<Flex gap={2} alignItems="flex-start" px={3} py={4}>
|
|
16
|
+
<Typography variant="h2">__TITLE__</Typography>
|
|
17
|
+
<Typography color="secondary">
|
|
18
|
+
An Astro app on the design system. Edit src/components/Home.jsx, and make the themes your
|
|
19
|
+
own in src/theme/themes.js.
|
|
20
|
+
</Typography>
|
|
21
|
+
{children}
|
|
22
|
+
<Flex flexDirection="row" gap={1}>
|
|
23
|
+
<Button href="https://docs.soroush.tech">Components</Button>
|
|
24
|
+
<Button href="https://astro.build" variant="outlined">
|
|
25
|
+
Astro
|
|
26
|
+
</Button>
|
|
27
|
+
</Flex>
|
|
28
|
+
</Flex>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default withIsland(Home)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// @if ssg
|
|
2
|
+
import { cleanup, render, screen } from '@testing-library/react'
|
|
3
|
+
// @else
|
|
4
|
+
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
|
5
|
+
// @endif
|
|
6
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
7
|
+
// @if !ssg
|
|
8
|
+
import Counter from './Counter'
|
|
9
|
+
// @endif
|
|
10
|
+
// @if msw
|
|
11
|
+
import Greeting from './Greeting'
|
|
12
|
+
// @endif
|
|
13
|
+
import Home from './Home'
|
|
14
|
+
|
|
15
|
+
// Each island renders inside its own providers, so a test renders it as it is.
|
|
16
|
+
describe('the home page', () => {
|
|
17
|
+
// Vitest has no globals here, so Testing Library cannot clean up on its own.
|
|
18
|
+
afterEach(cleanup)
|
|
19
|
+
|
|
20
|
+
it('shows the app title', () => {
|
|
21
|
+
render(<Home />)
|
|
22
|
+
expect(screen.getByRole('heading', { name: '__TITLE_STRING__' })).toBeTruthy()
|
|
23
|
+
})
|
|
24
|
+
// @if !ssg
|
|
25
|
+
|
|
26
|
+
it('counts each press of its button', () => {
|
|
27
|
+
render(<Counter />)
|
|
28
|
+
fireEvent.click(screen.getByRole('button', { name: 'Count' }))
|
|
29
|
+
expect(screen.getByText('Count: 1')).toBeTruthy()
|
|
30
|
+
})
|
|
31
|
+
// @endif
|
|
32
|
+
// @if msw
|
|
33
|
+
|
|
34
|
+
it('shows the greeting the mock API answers', async () => {
|
|
35
|
+
render(<Greeting />)
|
|
36
|
+
expect(await screen.findByText('Hello from the mock API')).toBeTruthy()
|
|
37
|
+
})
|
|
38
|
+
// @endif
|
|
39
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
2
|
+
import { Link } from '@soroush.tech/design-system/Link'
|
|
3
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
4
|
+
import { withIsland } from '../theme/Island'
|
|
5
|
+
|
|
6
|
+
/** Shown for a page that does not exist. */
|
|
7
|
+
function NotFound() {
|
|
8
|
+
return (
|
|
9
|
+
<Flex gap={2} alignItems="flex-start" px={3} py={4}>
|
|
10
|
+
<Typography variant="h2">Page not found</Typography>
|
|
11
|
+
<Typography color="secondary">This page does not exist.</Typography>
|
|
12
|
+
<Link href="/">Back home</Link>
|
|
13
|
+
</Flex>
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default withIsland(NotFound)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// @if tanstack-query || swr || msw
|
|
2
|
+
// @if ts && sample-data && msw && (tanstack-query || swr)
|
|
3
|
+
|
|
4
|
+
// @elif sample-data && !msw && (tanstack-query || swr)
|
|
5
|
+
import { items } from './items'
|
|
6
|
+
|
|
7
|
+
// @endif
|
|
8
|
+
// @if msw
|
|
9
|
+
import { mocks } from '../mocks/start'
|
|
10
|
+
|
|
11
|
+
// @endif
|
|
12
|
+
// @if ts
|
|
13
|
+
/** What the API says to the app. */
|
|
14
|
+
// @if react-hook-form
|
|
15
|
+
|
|
16
|
+
/** What the form sends. */
|
|
17
|
+
// @endif
|
|
18
|
+
|
|
19
|
+
// @endif
|
|
20
|
+
// @if msw
|
|
21
|
+
/** A greeting, from the API: while VITE_MSW is true, the mock API of src/mocks answers. */
|
|
22
|
+
export async function fetchGreeting() {
|
|
23
|
+
await mocks
|
|
24
|
+
const response = await fetch('/api/greeting')
|
|
25
|
+
if (!response.ok) throw new Error(`GET /api/greeting answered ${response.status}`)
|
|
26
|
+
return response.json()
|
|
27
|
+
}
|
|
28
|
+
// @else
|
|
29
|
+
/** A greeting, as an API would answer: make it fetch from yours. */
|
|
30
|
+
export function fetchGreeting() {
|
|
31
|
+
return Promise.resolve({ message: 'Hello from src/data/api: make it fetch from your API.' })
|
|
32
|
+
}
|
|
33
|
+
// @endif
|
|
34
|
+
// @if react-hook-form && msw
|
|
35
|
+
|
|
36
|
+
/** Sends the form's values to the API, which answers what it made of them. */
|
|
37
|
+
export async function sendMessage(message) {
|
|
38
|
+
await mocks
|
|
39
|
+
const response = await fetch('/api/messages', {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
headers: { 'Content-Type': 'application/json' },
|
|
42
|
+
body: JSON.stringify(message),
|
|
43
|
+
})
|
|
44
|
+
if (!response.ok) throw new Error(`POST /api/messages answered ${response.status}`)
|
|
45
|
+
return response.json()
|
|
46
|
+
}
|
|
47
|
+
// @elif react-hook-form
|
|
48
|
+
|
|
49
|
+
/** Sends the form's values, as an API would take them: make it post to yours. */
|
|
50
|
+
export function sendMessage(message) {
|
|
51
|
+
return Promise.resolve({ message: `Thanks, ${message.name}: your message was sent.` })
|
|
52
|
+
}
|
|
53
|
+
// @endif
|
|
54
|
+
// @if sample-data && msw && (tanstack-query || swr)
|
|
55
|
+
|
|
56
|
+
/** The items, from the API: while VITE_MSW is true, the mock API of src/mocks answers. */
|
|
57
|
+
export async function fetchItems() {
|
|
58
|
+
await mocks
|
|
59
|
+
const response = await fetch('/api/items')
|
|
60
|
+
if (!response.ok) throw new Error(`GET /api/items answered ${response.status}`)
|
|
61
|
+
return response.json()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** One item, from the API. */
|
|
65
|
+
export async function fetchItem(id) {
|
|
66
|
+
await mocks
|
|
67
|
+
const response = await fetch(`/api/items/${id}`)
|
|
68
|
+
if (!response.ok) throw new Error(`GET /api/items/${id} answered ${response.status}`)
|
|
69
|
+
return response.json()
|
|
70
|
+
}
|
|
71
|
+
// @elif sample-data && (tanstack-query || swr)
|
|
72
|
+
|
|
73
|
+
/** The items, as an API would answer: make it fetch from yours. */
|
|
74
|
+
export function fetchItems() {
|
|
75
|
+
return Promise.resolve(items.map(({ id, title, status }) => ({ id, title, status })))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** One item, as an API would answer: make it fetch from yours. */
|
|
79
|
+
export function fetchItem(id) {
|
|
80
|
+
const item = items.find((candidate) => candidate.id === id)
|
|
81
|
+
return item ? Promise.resolve(item) : Promise.reject(new Error(`There is no item ${id}.`))
|
|
82
|
+
}
|
|
83
|
+
// @endif
|
|
84
|
+
// @endif
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
// @if !ssg
|
|
3
|
+
import { ClientRouter } from 'astro:transitions'
|
|
4
|
+
// @endif
|
|
5
|
+
import Header from '../components/Header'
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
<html lang="en">
|
|
9
|
+
<head>
|
|
10
|
+
<meta charset="UTF-8" />
|
|
11
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
12
|
+
<title>__TITLE__</title>
|
|
13
|
+
{/* @if !ssg */}
|
|
14
|
+
<ClientRouter />
|
|
15
|
+
{/* @endif */}
|
|
16
|
+
</head>
|
|
17
|
+
<body>
|
|
18
|
+
{/* @if ssg */}
|
|
19
|
+
<Header />
|
|
20
|
+
{/* @else */}
|
|
21
|
+
<Header client:load transition:persist />
|
|
22
|
+
{/* @endif */}
|
|
23
|
+
<main>
|
|
24
|
+
<slot />
|
|
25
|
+
</main>
|
|
26
|
+
{/* @if !ssg */}
|
|
27
|
+
<script>
|
|
28
|
+
// Astro's client router replaces the head on each move between pages, and with it the
|
|
29
|
+
// styles the design system keeps there. Each of them gets an id the router keeps. The next
|
|
30
|
+
// page's own styles, which its HTML holds next to each island, move into its head, where
|
|
31
|
+
// the islands expect them as they hydrate - but not its base styles: the header, which
|
|
32
|
+
// the router keeps, draws those in the scheme picked.
|
|
33
|
+
document.addEventListener('astro:before-swap', ({ newDocument }) => {
|
|
34
|
+
const kept = new Set()
|
|
35
|
+
document.head.querySelectorAll('style[data-emotion]').forEach((style, index) => {
|
|
36
|
+
const id = `soroush-styles-${index}`
|
|
37
|
+
style.setAttribute('data-astro-transition-persist', id)
|
|
38
|
+
const placeholder = newDocument.createElement('style')
|
|
39
|
+
placeholder.setAttribute('data-astro-transition-persist', id)
|
|
40
|
+
newDocument.head.append(placeholder)
|
|
41
|
+
kept.add(style.getAttribute('data-emotion'))
|
|
42
|
+
})
|
|
43
|
+
newDocument.body.querySelectorAll('style[data-emotion]').forEach((style) => {
|
|
44
|
+
const name = style.getAttribute('data-emotion') ?? ''
|
|
45
|
+
if (kept.has(name) || name.includes('-global')) style.remove()
|
|
46
|
+
else newDocument.head.append(style)
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
</script>
|
|
50
|
+
{/* @endif */}
|
|
51
|
+
</body>
|
|
52
|
+
</html>
|