create-foldkit-app 0.27.3 → 0.28.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/dist/index.js +1 -5
- package/{templates → dist/templates}/base/AGENTS.md +17 -19
- package/dist/templates/examples/api-cache/package.json +29 -0
- package/dist/templates/examples/api-cache/src/data.test.ts +28 -0
- package/dist/templates/examples/api-cache/src/data.ts +126 -0
- package/dist/templates/examples/api-cache/src/entry.ts +17 -0
- package/dist/templates/examples/api-cache/src/main.fixtures.ts +70 -0
- package/dist/templates/examples/api-cache/src/main.ts +744 -0
- package/dist/templates/examples/api-cache/src/scene.test.ts +120 -0
- package/dist/templates/examples/api-cache/src/story.test.ts +288 -0
- package/dist/templates/examples/api-cache/src/styles.css +1 -0
- package/dist/templates/examples/api-cache/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/auth/package.json +30 -0
- package/dist/templates/examples/auth/src/command.ts +49 -0
- package/dist/templates/examples/auth/src/constant.ts +1 -0
- package/dist/templates/examples/auth/src/domain/session.ts +9 -0
- package/dist/templates/examples/auth/src/entry.ts +25 -0
- package/dist/templates/examples/auth/src/main.ts +75 -0
- package/dist/templates/examples/auth/src/message.ts +22 -0
- package/dist/templates/examples/auth/src/model.ts +9 -0
- package/dist/templates/examples/auth/src/notFoundView.ts +25 -0
- package/dist/templates/examples/auth/src/page/index.ts +2 -0
- package/dist/templates/examples/auth/src/page/loggedIn/index.ts +4 -0
- package/dist/templates/examples/auth/src/page/loggedIn/message.ts +17 -0
- package/dist/templates/examples/auth/src/page/loggedIn/model.ts +21 -0
- package/dist/templates/examples/auth/src/page/loggedIn/page/dashboard.ts +40 -0
- package/dist/templates/examples/auth/src/page/loggedIn/page/settings.ts +71 -0
- package/dist/templates/examples/auth/src/page/loggedIn/update.ts +16 -0
- package/dist/templates/examples/auth/src/page/loggedIn/view.ts +87 -0
- package/dist/templates/examples/auth/src/page/loggedOut/index.ts +4 -0
- package/dist/templates/examples/auth/src/page/loggedOut/message.ts +20 -0
- package/dist/templates/examples/auth/src/page/loggedOut/model.ts +21 -0
- package/dist/templates/examples/auth/src/page/loggedOut/page/home.ts +68 -0
- package/dist/templates/examples/auth/src/page/loggedOut/page/login.scene.test.ts +116 -0
- package/dist/templates/examples/auth/src/page/loggedOut/page/login.story.test.ts +112 -0
- package/dist/templates/examples/auth/src/page/loggedOut/page/login.ts +346 -0
- package/dist/templates/examples/auth/src/page/loggedOut/update.ts +32 -0
- package/dist/templates/examples/auth/src/page/loggedOut/view.ts +31 -0
- package/dist/templates/examples/auth/src/route.ts +56 -0
- package/dist/templates/examples/auth/src/scene.test.ts +61 -0
- package/dist/templates/examples/auth/src/styles.css +1 -0
- package/dist/templates/examples/auth/src/update.ts +179 -0
- package/dist/templates/examples/auth/src/view.ts +40 -0
- package/dist/templates/examples/auth/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/canvas-art/package.json +29 -0
- package/dist/templates/examples/canvas-art/src/entry.ts +17 -0
- package/dist/templates/examples/canvas-art/src/main.ts +274 -0
- package/dist/templates/examples/canvas-art/src/scene.test.ts +70 -0
- package/dist/templates/examples/canvas-art/src/story.test.ts +155 -0
- package/dist/templates/examples/canvas-art/src/styles.css +1 -0
- package/dist/templates/examples/canvas-art/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/charting/package.json +31 -0
- package/dist/templates/examples/charting/src/chartHost.ts +20 -0
- package/dist/templates/examples/charting/src/command.ts +62 -0
- package/dist/templates/examples/charting/src/domain.ts +175 -0
- package/dist/templates/examples/charting/src/echarts.ts +408 -0
- package/dist/templates/examples/charting/src/entry.ts +25 -0
- package/dist/templates/examples/charting/src/githubApi.ts +271 -0
- package/dist/templates/examples/charting/src/http.ts +50 -0
- package/dist/templates/examples/charting/src/init.test.ts +14 -0
- package/dist/templates/examples/charting/src/init.ts +29 -0
- package/dist/templates/examples/charting/src/main.fixtures.ts +162 -0
- package/dist/templates/examples/charting/src/message.ts +23 -0
- package/dist/templates/examples/charting/src/model.ts +22 -0
- package/dist/templates/examples/charting/src/npmApi.ts +75 -0
- package/dist/templates/examples/charting/src/radioGroups.ts +11 -0
- package/dist/templates/examples/charting/src/scene.test.ts +103 -0
- package/dist/templates/examples/charting/src/story.test.ts +145 -0
- package/dist/templates/examples/charting/src/styles.css +1 -0
- package/dist/templates/examples/charting/src/subscription.ts +70 -0
- package/dist/templates/examples/charting/src/telemetry.test.ts +64 -0
- package/dist/templates/examples/charting/src/telemetry.ts +432 -0
- package/dist/templates/examples/charting/src/update.ts +217 -0
- package/dist/templates/examples/charting/src/view/chart.ts +129 -0
- package/dist/templates/examples/charting/src/view/format.ts +23 -0
- package/dist/templates/examples/charting/src/view/index.ts +1 -0
- package/dist/templates/examples/charting/src/view/layout.ts +175 -0
- package/dist/templates/examples/charting/src/view/sidebar.ts +309 -0
- package/dist/templates/examples/charting/src/view/view.ts +23 -0
- package/dist/templates/examples/charting/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/charting/src/weeks.ts +105 -0
- package/dist/templates/examples/counter/package.json +29 -0
- package/dist/templates/examples/counter/src/entry.ts +16 -0
- package/dist/templates/examples/counter/src/main.ts +95 -0
- package/dist/templates/examples/counter/src/scene.test.ts +57 -0
- package/dist/templates/examples/counter/src/story.test.ts +71 -0
- package/dist/templates/examples/counter/src/styles.css +1 -0
- package/dist/templates/examples/counter/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/counters/package.json +29 -0
- package/dist/templates/examples/counters/src/counter.ts +70 -0
- package/dist/templates/examples/counters/src/entry.ts +16 -0
- package/dist/templates/examples/counters/src/main.ts +171 -0
- package/dist/templates/examples/counters/src/scene.test.ts +90 -0
- package/dist/templates/examples/counters/src/story.test.ts +127 -0
- package/dist/templates/examples/counters/src/styles.css +1 -0
- package/dist/templates/examples/counters/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/crash-view/package.json +29 -0
- package/dist/templates/examples/crash-view/src/entry.ts +28 -0
- package/dist/templates/examples/crash-view/src/main.ts +104 -0
- package/dist/templates/examples/crash-view/src/scene.test.ts +14 -0
- package/dist/templates/examples/crash-view/src/story.test.ts +11 -0
- package/dist/templates/examples/crash-view/src/styles.css +1 -0
- package/dist/templates/examples/crash-view/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/embedding/package.json +29 -0
- package/dist/templates/examples/embedding/src/entry.ts +3 -0
- package/dist/templates/examples/embedding/src/host.ts +108 -0
- package/dist/templates/examples/embedding/src/main.ts +144 -0
- package/dist/templates/examples/embedding/src/scene.test.ts +28 -0
- package/dist/templates/examples/embedding/src/story.test.ts +64 -0
- package/dist/templates/examples/embedding/src/styles.css +1 -0
- package/dist/templates/examples/embedding/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/form/package.json +30 -0
- package/dist/templates/examples/form/src/entry.ts +16 -0
- package/dist/templates/examples/form/src/main.ts +493 -0
- package/dist/templates/examples/form/src/scene.test.ts +165 -0
- package/dist/templates/examples/form/src/story.test.ts +190 -0
- package/dist/templates/examples/form/src/styles.css +1 -0
- package/dist/templates/examples/form/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/generative-art/package.json +29 -0
- package/dist/templates/examples/generative-art/src/command.ts +109 -0
- package/dist/templates/examples/generative-art/src/constant.ts +68 -0
- package/dist/templates/examples/generative-art/src/entry.ts +22 -0
- package/dist/templates/examples/generative-art/src/main.ts +59 -0
- package/dist/templates/examples/generative-art/src/message.ts +35 -0
- package/dist/templates/examples/generative-art/src/model.ts +33 -0
- package/dist/templates/examples/generative-art/src/noise.ts +93 -0
- package/dist/templates/examples/generative-art/src/scene.test.ts +103 -0
- package/dist/templates/examples/generative-art/src/story.test.ts +203 -0
- package/dist/templates/examples/generative-art/src/styles.css +1 -0
- package/dist/templates/examples/generative-art/src/subscription.ts +35 -0
- package/dist/templates/examples/generative-art/src/update.ts +319 -0
- package/dist/templates/examples/generative-art/src/view.ts +451 -0
- package/dist/templates/examples/generative-art/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/interrupting-commands/package.json +29 -0
- package/dist/templates/examples/interrupting-commands/src/entry.ts +16 -0
- package/dist/templates/examples/interrupting-commands/src/main.ts +354 -0
- package/dist/templates/examples/interrupting-commands/src/scene.test.ts +89 -0
- package/dist/templates/examples/interrupting-commands/src/story.test.ts +224 -0
- package/dist/templates/examples/interrupting-commands/src/styles.css +1 -0
- package/dist/templates/examples/interrupting-commands/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/job-application/package.json +30 -0
- package/dist/templates/examples/job-application/src/command.ts +23 -0
- package/dist/templates/examples/job-application/src/domain/index.ts +3 -0
- package/dist/templates/examples/job-application/src/domain/proficiencyLevel.ts +11 -0
- package/dist/templates/examples/job-application/src/domain/pronounOption.ts +13 -0
- package/dist/templates/examples/job-application/src/domain/step.ts +28 -0
- package/dist/templates/examples/job-application/src/entry.ts +17 -0
- package/dist/templates/examples/job-application/src/main.ts +69 -0
- package/dist/templates/examples/job-application/src/message.ts +44 -0
- package/dist/templates/examples/job-application/src/model.ts +47 -0
- package/dist/templates/examples/job-application/src/scene.test.ts +269 -0
- package/dist/templates/examples/job-application/src/step/attachments.ts +111 -0
- package/dist/templates/examples/job-application/src/step/coverLetter.ts +34 -0
- package/dist/templates/examples/job-application/src/step/education/education.ts +121 -0
- package/dist/templates/examples/job-application/src/step/education/entry.ts +168 -0
- package/dist/templates/examples/job-application/src/step/education/index.ts +2 -0
- package/dist/templates/examples/job-application/src/step/index.ts +6 -0
- package/dist/templates/examples/job-application/src/step/personalInfo.ts +305 -0
- package/dist/templates/examples/job-application/src/step/skills/entry.ts +126 -0
- package/dist/templates/examples/job-application/src/step/skills/index.ts +2 -0
- package/dist/templates/examples/job-application/src/step/skills/skills.ts +118 -0
- package/dist/templates/examples/job-application/src/step/validation.ts +6 -0
- package/dist/templates/examples/job-application/src/step/workHistory/entry.ts +206 -0
- package/dist/templates/examples/job-application/src/step/workHistory/index.ts +2 -0
- package/dist/templates/examples/job-application/src/step/workHistory/workHistory.ts +121 -0
- package/dist/templates/examples/job-application/src/story.test.ts +775 -0
- package/dist/templates/examples/job-application/src/styles.css +1 -0
- package/dist/templates/examples/job-application/src/update.ts +183 -0
- package/dist/templates/examples/job-application/src/view/attachments.ts +215 -0
- package/dist/templates/examples/job-application/src/view/coverLetter.ts +73 -0
- package/dist/templates/examples/job-application/src/view/datePicker.ts +207 -0
- package/dist/templates/examples/job-application/src/view/education.ts +63 -0
- package/dist/templates/examples/job-application/src/view/educationEntry.ts +165 -0
- package/dist/templates/examples/job-application/src/view/field.ts +183 -0
- package/dist/templates/examples/job-application/src/view/format.ts +50 -0
- package/dist/templates/examples/job-application/src/view/icon.ts +21 -0
- package/dist/templates/examples/job-application/src/view/index.ts +352 -0
- package/dist/templates/examples/job-application/src/view/personalInfo.ts +224 -0
- package/dist/templates/examples/job-application/src/view/preview.ts +265 -0
- package/dist/templates/examples/job-application/src/view/review.ts +388 -0
- package/dist/templates/examples/job-application/src/view/skillEntry.ts +102 -0
- package/dist/templates/examples/job-application/src/view/skills.ts +49 -0
- package/dist/templates/examples/job-application/src/view/stepNav.ts +181 -0
- package/dist/templates/examples/job-application/src/view/workEntry.ts +159 -0
- package/dist/templates/examples/job-application/src/view/workHistory.ts +55 -0
- package/dist/templates/examples/job-application/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/kanban/package.json +31 -0
- package/dist/templates/examples/kanban/src/command.ts +46 -0
- package/dist/templates/examples/kanban/src/constant.ts +149 -0
- package/dist/templates/examples/kanban/src/domain/card.ts +10 -0
- package/dist/templates/examples/kanban/src/domain/column.ts +115 -0
- package/dist/templates/examples/kanban/src/domain/index.ts +2 -0
- package/dist/templates/examples/kanban/src/entry.ts +27 -0
- package/dist/templates/examples/kanban/src/main.ts +56 -0
- package/dist/templates/examples/kanban/src/message.ts +21 -0
- package/dist/templates/examples/kanban/src/model.ts +21 -0
- package/dist/templates/examples/kanban/src/scene.test.ts +161 -0
- package/dist/templates/examples/kanban/src/story.test.ts +461 -0
- package/dist/templates/examples/kanban/src/styles.css +1 -0
- package/dist/templates/examples/kanban/src/subscription.ts +16 -0
- package/dist/templates/examples/kanban/src/update.ts +205 -0
- package/dist/templates/examples/kanban/src/view/card.ts +79 -0
- package/dist/templates/examples/kanban/src/view/column.ts +283 -0
- package/dist/templates/examples/kanban/src/view/index.ts +71 -0
- package/dist/templates/examples/kanban/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/managed-resource-layer/package.json +29 -0
- package/dist/templates/examples/managed-resource-layer/src/entry.ts +17 -0
- package/dist/templates/examples/managed-resource-layer/src/main.ts +309 -0
- package/dist/templates/examples/managed-resource-layer/src/scene.test.ts +117 -0
- package/dist/templates/examples/managed-resource-layer/src/story.test.ts +118 -0
- package/dist/templates/examples/managed-resource-layer/src/styles.css +1 -0
- package/dist/templates/examples/managed-resource-layer/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/map/package.json +31 -0
- package/dist/templates/examples/map/src/entry.ts +17 -0
- package/dist/templates/examples/map/src/locations.ts +69 -0
- package/dist/templates/examples/map/src/main.fixtures.ts +28 -0
- package/dist/templates/examples/map/src/main.ts +781 -0
- package/dist/templates/examples/map/src/mapHost.ts +23 -0
- package/dist/templates/examples/map/src/scene.test.ts +136 -0
- package/dist/templates/examples/map/src/story.test.ts +190 -0
- package/dist/templates/examples/map/src/styles.css +2 -0
- package/dist/templates/examples/map/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/pixel-art/package.json +31 -0
- package/dist/templates/examples/pixel-art/src/command.ts +87 -0
- package/dist/templates/examples/pixel-art/src/comparison.bench.test.ts +204 -0
- package/dist/templates/examples/pixel-art/src/constant.ts +21 -0
- package/dist/templates/examples/pixel-art/src/entry.ts +27 -0
- package/dist/templates/examples/pixel-art/src/grid.ts +134 -0
- package/dist/templates/examples/pixel-art/src/main.bench.ts +133 -0
- package/dist/templates/examples/pixel-art/src/main.ts +85 -0
- package/dist/templates/examples/pixel-art/src/message.ts +36 -0
- package/dist/templates/examples/pixel-art/src/model.ts +79 -0
- package/dist/templates/examples/pixel-art/src/palette.ts +134 -0
- package/dist/templates/examples/pixel-art/src/scene.test.ts +250 -0
- package/dist/templates/examples/pixel-art/src/story.test.ts +482 -0
- package/dist/templates/examples/pixel-art/src/styles.css +1 -0
- package/dist/templates/examples/pixel-art/src/subscription.ts +61 -0
- package/dist/templates/examples/pixel-art/src/update.ts +469 -0
- package/dist/templates/examples/pixel-art/src/view/canvas.ts +134 -0
- package/dist/templates/examples/pixel-art/src/view/dialog.ts +152 -0
- package/dist/templates/examples/pixel-art/src/view/history.ts +214 -0
- package/dist/templates/examples/pixel-art/src/view/index.ts +1 -0
- package/dist/templates/examples/pixel-art/src/view/toolbar.ts +452 -0
- package/dist/templates/examples/pixel-art/src/view/view.ts +183 -0
- package/dist/templates/examples/pixel-art/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/query-sync/package.json +30 -0
- package/dist/templates/examples/query-sync/src/data.ts +166 -0
- package/dist/templates/examples/query-sync/src/entry.ts +20 -0
- package/dist/templates/examples/query-sync/src/main.ts +898 -0
- package/dist/templates/examples/query-sync/src/scene.test.ts +89 -0
- package/dist/templates/examples/query-sync/src/story.test.ts +151 -0
- package/dist/templates/examples/query-sync/src/styles.css +1 -0
- package/dist/templates/examples/query-sync/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/route-transitions/package.json +28 -0
- package/dist/templates/examples/route-transitions/src/data.ts +61 -0
- package/dist/templates/examples/route-transitions/src/entry.ts +20 -0
- package/dist/templates/examples/route-transitions/src/main.ts +798 -0
- package/dist/templates/examples/route-transitions/src/route.ts +48 -0
- package/dist/templates/examples/route-transitions/src/story.test.ts +225 -0
- package/dist/templates/examples/route-transitions/src/styles.css +1 -0
- package/dist/templates/examples/route-transitions/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/routing/package.json +29 -0
- package/dist/templates/examples/routing/src/entry.ts +20 -0
- package/dist/templates/examples/routing/src/fileTree.ts +98 -0
- package/dist/templates/examples/routing/src/main.ts +573 -0
- package/dist/templates/examples/routing/src/page/index.ts +1 -0
- package/dist/templates/examples/routing/src/page/people.ts +349 -0
- package/dist/templates/examples/routing/src/route.ts +82 -0
- package/dist/templates/examples/routing/src/scene.test.ts +180 -0
- package/dist/templates/examples/routing/src/story.test.ts +242 -0
- package/dist/templates/examples/routing/src/styles.css +1 -0
- package/dist/templates/examples/routing/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/shopping-cart/package.json +29 -0
- package/dist/templates/examples/shopping-cart/src/data/products.ts +10 -0
- package/dist/templates/examples/shopping-cart/src/domain/cart.ts +77 -0
- package/dist/templates/examples/shopping-cart/src/domain/index.ts +2 -0
- package/dist/templates/examples/shopping-cart/src/domain/item.ts +16 -0
- package/dist/templates/examples/shopping-cart/src/entry.ts +20 -0
- package/dist/templates/examples/shopping-cart/src/main.ts +307 -0
- package/dist/templates/examples/shopping-cart/src/page/cart.ts +203 -0
- package/dist/templates/examples/shopping-cart/src/page/checkout.ts +205 -0
- package/dist/templates/examples/shopping-cart/src/page/index.ts +3 -0
- package/dist/templates/examples/shopping-cart/src/page/products.ts +267 -0
- package/dist/templates/examples/shopping-cart/src/route.ts +43 -0
- package/dist/templates/examples/shopping-cart/src/scene.test.ts +138 -0
- package/dist/templates/examples/shopping-cart/src/story.test.ts +233 -0
- package/dist/templates/examples/shopping-cart/src/styles.css +1 -0
- package/dist/templates/examples/shopping-cart/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/slow-warnings/package.json +28 -0
- package/dist/templates/examples/slow-warnings/src/entry.ts +29 -0
- package/dist/templates/examples/slow-warnings/src/handleSlow.test.ts +43 -0
- package/dist/templates/examples/slow-warnings/src/main.ts +574 -0
- package/dist/templates/examples/slow-warnings/src/scene.test.ts +57 -0
- package/dist/templates/examples/slow-warnings/src/story.test.ts +118 -0
- package/dist/templates/examples/slow-warnings/src/styles.css +1 -0
- package/dist/templates/examples/slow-warnings/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/snake/package.json +28 -0
- package/dist/templates/examples/snake/src/constants.ts +11 -0
- package/dist/templates/examples/snake/src/domain/apple.ts +22 -0
- package/dist/templates/examples/snake/src/domain/direction.ts +17 -0
- package/dist/templates/examples/snake/src/domain/index.ts +4 -0
- package/dist/templates/examples/snake/src/domain/position.ts +32 -0
- package/dist/templates/examples/snake/src/domain/snake.ts +43 -0
- package/dist/templates/examples/snake/src/entry.ts +17 -0
- package/dist/templates/examples/snake/src/main.ts +345 -0
- package/dist/templates/examples/snake/src/scene.test.ts +77 -0
- package/dist/templates/examples/snake/src/story.test.ts +165 -0
- package/dist/templates/examples/snake/src/styles.css +1 -0
- package/dist/templates/examples/snake/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/ssg/package.json +29 -0
- package/dist/templates/examples/ssg/src/entry.server.ts +14 -0
- package/{templates/rendering → dist/templates/examples}/ssg/src/entry.ts +3 -11
- package/dist/templates/examples/ssg/src/main.ts +163 -0
- package/dist/templates/examples/ssg/src/styles.css +1 -0
- package/dist/templates/examples/ssr/package.json +33 -0
- package/dist/templates/examples/ssr/src/cookie.ts +13 -0
- package/dist/templates/examples/ssr/src/entry.server.ts +51 -0
- package/dist/templates/examples/ssr/src/main.ts +170 -0
- package/{templates/rendering → dist/templates/examples}/ssr/src/scene.test.ts +5 -8
- package/dist/templates/examples/ssr/src/styles.css +1 -0
- package/dist/templates/examples/ssr/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/state-machine/package.json +30 -0
- package/dist/templates/examples/state-machine/src/entry.ts +17 -0
- package/dist/templates/examples/state-machine/src/icon.ts +51 -0
- package/dist/templates/examples/state-machine/src/main.ts +420 -0
- package/dist/templates/examples/state-machine/src/scene.test.ts +85 -0
- package/dist/templates/examples/state-machine/src/story.test.ts +199 -0
- package/dist/templates/examples/state-machine/src/styles.css +53 -0
- package/dist/templates/examples/state-machine/src/view.ts +1675 -0
- package/dist/templates/examples/state-machine/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/stopwatch/package.json +29 -0
- package/dist/templates/examples/stopwatch/src/entry.ts +17 -0
- package/dist/templates/examples/stopwatch/src/main.ts +237 -0
- package/dist/templates/examples/stopwatch/src/scene.test.ts +124 -0
- package/dist/templates/examples/stopwatch/src/story.test.ts +126 -0
- package/dist/templates/examples/stopwatch/src/styles.css +1 -0
- package/dist/templates/examples/stopwatch/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/todo/package.json +30 -0
- package/dist/templates/examples/todo/src/entry.ts +17 -0
- package/dist/templates/examples/todo/src/main.ts +682 -0
- package/dist/templates/examples/todo/src/scene.test.ts +177 -0
- package/dist/templates/examples/todo/src/story.test.ts +374 -0
- package/dist/templates/examples/todo/src/styles.css +1 -0
- package/dist/templates/examples/todo/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/ui-showcase/package.json +30 -0
- package/dist/templates/examples/ui-showcase/src/entry.ts +31 -0
- package/dist/templates/examples/ui-showcase/src/icon.ts +64 -0
- package/dist/templates/examples/ui-showcase/src/main.ts +673 -0
- package/dist/templates/examples/ui-showcase/src/scene.test.ts +102 -0
- package/dist/templates/examples/ui-showcase/src/story.test.ts +128 -0
- package/dist/templates/examples/ui-showcase/src/styles.css +21 -0
- package/dist/templates/examples/ui-showcase/src/ui/init.ts +185 -0
- package/dist/templates/examples/ui-showcase/src/ui/message.ts +164 -0
- package/dist/templates/examples/ui-showcase/src/ui/model.ts +138 -0
- package/dist/templates/examples/ui-showcase/src/ui/subscriptions.ts +55 -0
- package/dist/templates/examples/ui-showcase/src/ui/toast.ts +13 -0
- package/dist/templates/examples/ui-showcase/src/ui/update.ts +1234 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/animation.ts +58 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/button.ts +64 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/calendar.ts +202 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/checkbox.ts +185 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/combobox.ts +326 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/datePicker.ts +263 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/dialog.ts +427 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/disclosure.ts +142 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/dragAndDrop.ts +230 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/fieldset.ts +284 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/fileDrop.ts +119 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/index.ts +24 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/input.ts +90 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/listbox.ts +263 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/menu.ts +172 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/popover.ts +262 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/radioGroup.ts +192 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/select.ts +129 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/slider.ts +135 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/switch.ts +82 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/tabs.ts +187 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/textarea.ts +99 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/toast.ts +165 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/tooltip.ts +123 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/virtualList.ts +361 -0
- package/dist/templates/examples/ui-showcase/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/view-transitions/package.json +28 -0
- package/dist/templates/examples/view-transitions/src/artwork.ts +80 -0
- package/dist/templates/examples/view-transitions/src/entry.ts +21 -0
- package/dist/templates/examples/view-transitions/src/main.ts +348 -0
- package/dist/templates/examples/view-transitions/src/route.ts +29 -0
- package/dist/templates/examples/view-transitions/src/scene.test.ts +130 -0
- package/dist/templates/examples/view-transitions/src/styles.css +66 -0
- package/dist/templates/examples/view-transitions/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/weather/package.json +29 -0
- package/dist/templates/examples/weather/src/entry.ts +16 -0
- package/dist/templates/examples/weather/src/main.fixtures.ts +59 -0
- package/dist/templates/examples/weather/src/main.ts +356 -0
- package/dist/templates/examples/weather/src/scene.test.ts +109 -0
- package/dist/templates/examples/weather/src/story.test.ts +125 -0
- package/dist/templates/examples/weather/src/styles.css +1 -0
- package/dist/templates/examples/weather/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/web-components/package.json +32 -0
- package/dist/templates/examples/web-components/src/entry.ts +16 -0
- package/dist/templates/examples/web-components/src/main.ts +327 -0
- package/dist/templates/examples/web-components/src/scene.test.ts +90 -0
- package/dist/templates/examples/web-components/src/story.test.ts +90 -0
- package/dist/templates/examples/web-components/src/styles.css +1 -0
- package/dist/templates/examples/web-components/src/vitest-setup.ts +3 -0
- package/dist/templates/examples/websocket-chat/package.json +29 -0
- package/dist/templates/examples/websocket-chat/src/entry.ts +26 -0
- package/dist/templates/examples/websocket-chat/src/main.ts +626 -0
- package/dist/templates/examples/websocket-chat/src/scene.test.ts +166 -0
- package/dist/templates/examples/websocket-chat/src/story.test.ts +183 -0
- package/dist/templates/examples/websocket-chat/src/styles.css +1 -0
- package/dist/templates/examples/websocket-chat/src/vitest-setup.ts +3 -0
- package/dist/templates/release.json +27 -0
- package/dist/templates/rendering/ssg/src/entry.ts +20 -0
- package/{templates → dist/templates}/rendering/ssg/src/main.ts +36 -43
- package/dist/templates/rendering/ssg/src/route.ts +20 -0
- package/dist/templates/rendering/ssg/src/vite-env.d.ts +19 -0
- package/dist/templates/rendering/ssr/src/entry.ts +17 -0
- package/{templates → dist/templates}/rendering/ssr/src/main.ts +17 -25
- package/dist/templates/rendering/ssr/src/scene.test.ts +40 -0
- package/dist/templates/rendering/ssr/src/vite-env.d.ts +19 -0
- package/dist/utils/files.js +23 -71
- package/dist/utils/packages.js +63 -44
- package/package.json +3 -4
- /package/{templates → dist/templates}/base/.mcp.json +0 -0
- /package/{templates → dist/templates}/base/.oxlintrc.json +0 -0
- /package/{templates → dist/templates}/base/.prettierignore +0 -0
- /package/{templates → dist/templates}/base/.prettierrc +0 -0
- /package/{templates → dist/templates}/base/README.md +0 -0
- /package/{templates → dist/templates}/base/gitignore +0 -0
- /package/{templates → dist/templates}/base/ignore +0 -0
- /package/{templates → dist/templates}/base/index.html +0 -0
- /package/{templates → dist/templates}/base/package.json +0 -0
- /package/{templates → dist/templates}/base/src/styles.css +0 -0
- /package/{templates → dist/templates}/base/src/vitest-setup.ts +0 -0
- /package/{templates → dist/templates}/base/tsconfig.json +0 -0
- /package/{templates → dist/templates}/base/vite.config.ts +0 -0
- /package/{templates → dist/templates}/base/vitest.config.ts +0 -0
- /package/{templates/rendering → dist/templates/examples}/ssg/src/route.ts +0 -0
- /package/{templates/rendering → dist/templates/examples}/ssg/src/vite-env.d.ts +0 -0
- /package/{templates/rendering → dist/templates/examples}/ssr/src/entry.ts +0 -0
- /package/{templates/rendering → dist/templates/examples}/ssr/src/vite-env.d.ts +0 -0
- /package/{templates → dist/templates}/package-managers/pnpm/pnpm-workspace.yaml +0 -0
- /package/{templates → dist/templates}/rendering/ssg/README.md +0 -0
- /package/{templates → dist/templates}/rendering/ssg/package.json +0 -0
- /package/{templates → dist/templates}/rendering/ssg/scripts/build.mjs +0 -0
- /package/{templates → dist/templates}/rendering/ssg/scripts/prerender.ts +0 -0
- /package/{templates → dist/templates}/rendering/ssg/src/entry.server.ts +0 -0
- /package/{templates → dist/templates}/rendering/ssg/src/scene.test.ts +0 -0
- /package/{templates → dist/templates}/rendering/ssg/tsconfig.json +0 -0
- /package/{templates → dist/templates}/rendering/ssg/vite.config.ts +0 -0
- /package/{templates → dist/templates}/rendering/ssr/README.md +0 -0
- /package/{templates → dist/templates}/rendering/ssr/package.json +0 -0
- /package/{templates → dist/templates}/rendering/ssr/scripts/build.mjs +0 -0
- /package/{templates → dist/templates}/rendering/ssr/server/main.ts +0 -0
- /package/{templates → dist/templates}/rendering/ssr/src/cookie.ts +0 -0
- /package/{templates → dist/templates}/rendering/ssr/src/entry.server.ts +0 -0
- /package/{templates → dist/templates}/rendering/ssr/tsconfig.json +0 -0
- /package/{templates → dist/templates}/rendering/ssr/vite.config.ts +0 -0
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
import clsx from 'clsx'
|
|
2
|
+
import {
|
|
3
|
+
Array,
|
|
4
|
+
Duration,
|
|
5
|
+
Effect,
|
|
6
|
+
Match as M,
|
|
7
|
+
Random,
|
|
8
|
+
Schema as S,
|
|
9
|
+
} from 'effect'
|
|
10
|
+
import { Command, Runtime } from 'foldkit'
|
|
11
|
+
import {
|
|
12
|
+
Field,
|
|
13
|
+
Invalid,
|
|
14
|
+
NotValidated,
|
|
15
|
+
Rule,
|
|
16
|
+
Valid,
|
|
17
|
+
Validating,
|
|
18
|
+
allValid,
|
|
19
|
+
makeRules,
|
|
20
|
+
validate,
|
|
21
|
+
} from 'foldkit/fieldValidation'
|
|
22
|
+
import { type Attribute, Document, Html, HtmlBuilder } from 'foldkit/html'
|
|
23
|
+
import { defineMessageUnion } from 'foldkit/message'
|
|
24
|
+
import { ts } from 'foldkit/schema'
|
|
25
|
+
import { evo } from 'foldkit/struct'
|
|
26
|
+
|
|
27
|
+
import { Button, Input, Textarea } from '@foldkit/ui'
|
|
28
|
+
|
|
29
|
+
const nameRules = makeRules({
|
|
30
|
+
rules: [Rule.minLength(2, 'Name must be at least 2 characters')],
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const emailRules = makeRules({
|
|
34
|
+
required: 'Email is required',
|
|
35
|
+
rules: [Rule.email('Please enter a valid email address')],
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
// MODEL
|
|
39
|
+
|
|
40
|
+
const NotSubmitted = ts('NotSubmitted')
|
|
41
|
+
const Submitting = ts('Submitting')
|
|
42
|
+
const SubmitSuccess = ts('SubmitSuccess', { confirmationText: S.String })
|
|
43
|
+
const SubmitError = ts('SubmitError', { error: S.String })
|
|
44
|
+
|
|
45
|
+
const Submission = S.Union([
|
|
46
|
+
NotSubmitted,
|
|
47
|
+
Submitting,
|
|
48
|
+
SubmitSuccess,
|
|
49
|
+
SubmitError,
|
|
50
|
+
])
|
|
51
|
+
|
|
52
|
+
type NotSubmitted = typeof NotSubmitted.Type
|
|
53
|
+
type Submitting = typeof Submitting.Type
|
|
54
|
+
type SubmitSuccess = typeof SubmitSuccess.Type
|
|
55
|
+
type SubmitError = typeof SubmitError.Type
|
|
56
|
+
type Submission = typeof Submission.Type
|
|
57
|
+
|
|
58
|
+
export const Model = S.Struct({
|
|
59
|
+
name: Field(S.String),
|
|
60
|
+
email: Field(S.String),
|
|
61
|
+
messageText: Field(S.String),
|
|
62
|
+
submission: Submission,
|
|
63
|
+
})
|
|
64
|
+
export type Model = typeof Model.Type
|
|
65
|
+
|
|
66
|
+
// MESSAGE
|
|
67
|
+
|
|
68
|
+
export const Message = defineMessageUnion({
|
|
69
|
+
UpdatedName: { value: S.String },
|
|
70
|
+
UpdatedEmail: { value: S.String },
|
|
71
|
+
CompletedValidateEmail: { field: Field(S.String) },
|
|
72
|
+
UpdatedMessageText: { value: S.String },
|
|
73
|
+
ClickedFormSubmit: {},
|
|
74
|
+
SucceededSubmitForm: { name: S.String },
|
|
75
|
+
FailedSubmitForm: {},
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
export type Message = typeof Message.Type
|
|
79
|
+
|
|
80
|
+
// INIT
|
|
81
|
+
|
|
82
|
+
export const initialModel: Model = {
|
|
83
|
+
name: NotValidated({ value: '' }),
|
|
84
|
+
email: NotValidated({ value: '' }),
|
|
85
|
+
messageText: NotValidated({ value: '' }),
|
|
86
|
+
submission: NotSubmitted(),
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const init: Runtime.ApplicationInit<Model, Message> = () => [
|
|
90
|
+
initialModel,
|
|
91
|
+
[],
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
// FIELD VALIDATION
|
|
95
|
+
|
|
96
|
+
const EMAILS_ON_WAITLIST = [
|
|
97
|
+
'test@example.com',
|
|
98
|
+
'demo@email.com',
|
|
99
|
+
'admin@test.com',
|
|
100
|
+
]
|
|
101
|
+
|
|
102
|
+
const isEmailOnWaitlist = (email: string): Effect.Effect<boolean> =>
|
|
103
|
+
Effect.gen(function* () {
|
|
104
|
+
yield* Effect.sleep(Duration.millis(FAKE_API_DELAY_MS))
|
|
105
|
+
return Array.contains(EMAILS_ON_WAITLIST, email.toLowerCase())
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
export const ValidateEmail = Command.define('ValidateEmail', {
|
|
109
|
+
args: { email: S.String },
|
|
110
|
+
messages: [Message.CompletedValidateEmail],
|
|
111
|
+
execute: ({ email }) =>
|
|
112
|
+
Effect.gen(function* () {
|
|
113
|
+
if (yield* isEmailOnWaitlist(email)) {
|
|
114
|
+
return Message.CompletedValidateEmail({
|
|
115
|
+
field: Invalid({
|
|
116
|
+
value: email,
|
|
117
|
+
errors: ['This email is already on our waitlist'],
|
|
118
|
+
}),
|
|
119
|
+
})
|
|
120
|
+
} else {
|
|
121
|
+
return Message.CompletedValidateEmail({
|
|
122
|
+
field: Valid({ value: email }),
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
}),
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
const validateName = validate(nameRules)
|
|
129
|
+
const validateEmail = validate(emailRules)
|
|
130
|
+
|
|
131
|
+
const isFormValid = (model: Model): boolean =>
|
|
132
|
+
allValid([
|
|
133
|
+
[model.name, nameRules],
|
|
134
|
+
[model.email, emailRules],
|
|
135
|
+
])
|
|
136
|
+
|
|
137
|
+
// UPDATE
|
|
138
|
+
|
|
139
|
+
export const update = (model: Model, message: Message) =>
|
|
140
|
+
Message.match<readonly [Model, ReadonlyArray<Command.Command<Message>>]>(
|
|
141
|
+
message,
|
|
142
|
+
{
|
|
143
|
+
UpdatedName: ({ value }) => [
|
|
144
|
+
evo(model, {
|
|
145
|
+
name: () => validateName(value),
|
|
146
|
+
}),
|
|
147
|
+
[],
|
|
148
|
+
],
|
|
149
|
+
|
|
150
|
+
UpdatedEmail: ({ value }) => {
|
|
151
|
+
const validateEmailResult = validateEmail(value)
|
|
152
|
+
|
|
153
|
+
if (validateEmailResult._tag === 'Valid') {
|
|
154
|
+
return [
|
|
155
|
+
evo(model, {
|
|
156
|
+
email: () => Validating({ value }),
|
|
157
|
+
}),
|
|
158
|
+
[ValidateEmail({ email: value })],
|
|
159
|
+
]
|
|
160
|
+
} else {
|
|
161
|
+
return [
|
|
162
|
+
evo(model, {
|
|
163
|
+
email: () => validateEmailResult,
|
|
164
|
+
}),
|
|
165
|
+
[],
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
CompletedValidateEmail: ({ field }) => {
|
|
171
|
+
if (field.value === model.email.value) {
|
|
172
|
+
return [
|
|
173
|
+
evo(model, {
|
|
174
|
+
email: () => field,
|
|
175
|
+
}),
|
|
176
|
+
[],
|
|
177
|
+
]
|
|
178
|
+
} else {
|
|
179
|
+
return [model, []]
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
UpdatedMessageText: ({ value }) => [
|
|
184
|
+
evo(model, {
|
|
185
|
+
messageText: () => Valid({ value }),
|
|
186
|
+
}),
|
|
187
|
+
[],
|
|
188
|
+
],
|
|
189
|
+
|
|
190
|
+
ClickedFormSubmit: () => {
|
|
191
|
+
if (model.submission._tag === 'Submitting') {
|
|
192
|
+
return [model, []]
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (!isFormValid(model)) {
|
|
196
|
+
return [model, []]
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return [
|
|
200
|
+
evo(model, {
|
|
201
|
+
submission: () => Submitting(),
|
|
202
|
+
}),
|
|
203
|
+
[
|
|
204
|
+
SubmitForm({
|
|
205
|
+
name: model.name.value,
|
|
206
|
+
email: model.email.value,
|
|
207
|
+
messageText: model.messageText.value,
|
|
208
|
+
}),
|
|
209
|
+
],
|
|
210
|
+
]
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
SucceededSubmitForm: ({ name }) => [
|
|
214
|
+
evo(model, {
|
|
215
|
+
submission: () =>
|
|
216
|
+
SubmitSuccess({
|
|
217
|
+
confirmationText: `Welcome to the waitlist, ${name}! We'll be in touch soon.`,
|
|
218
|
+
}),
|
|
219
|
+
}),
|
|
220
|
+
[],
|
|
221
|
+
],
|
|
222
|
+
|
|
223
|
+
FailedSubmitForm: () => [
|
|
224
|
+
evo(model, {
|
|
225
|
+
submission: () =>
|
|
226
|
+
SubmitError({
|
|
227
|
+
error:
|
|
228
|
+
'Sorry, there was an error adding you to the waitlist. Please try again.',
|
|
229
|
+
}),
|
|
230
|
+
}),
|
|
231
|
+
[],
|
|
232
|
+
],
|
|
233
|
+
},
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
// COMMAND
|
|
237
|
+
|
|
238
|
+
const FAKE_API_DELAY_MS = 500
|
|
239
|
+
|
|
240
|
+
export const SubmitForm = Command.define('SubmitForm', {
|
|
241
|
+
args: { name: S.String, email: S.String, messageText: S.String },
|
|
242
|
+
messages: [Message.SucceededSubmitForm, Message.FailedSubmitForm],
|
|
243
|
+
execute: ({ name }) =>
|
|
244
|
+
Effect.gen(function* () {
|
|
245
|
+
yield* Effect.sleep(`${FAKE_API_DELAY_MS} millis`)
|
|
246
|
+
|
|
247
|
+
const isSuccess = yield* Random.nextBoolean
|
|
248
|
+
if (isSuccess) {
|
|
249
|
+
return Message.SucceededSubmitForm({ name })
|
|
250
|
+
} else {
|
|
251
|
+
return Message.FailedSubmitForm()
|
|
252
|
+
}
|
|
253
|
+
}),
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
// VIEW
|
|
257
|
+
|
|
258
|
+
const LABEL_CLASS = 'text-sm font-medium text-gray-700'
|
|
259
|
+
const DESCRIPTION_CLASS = 'text-sm mt-1'
|
|
260
|
+
|
|
261
|
+
const borderClass = (field: Field<string>): string =>
|
|
262
|
+
M.value(field).pipe(
|
|
263
|
+
M.tagsExhaustive({
|
|
264
|
+
NotValidated: () => 'border-gray-300',
|
|
265
|
+
Validating: () => 'border-blue-300',
|
|
266
|
+
Valid: () => 'border-green-500',
|
|
267
|
+
Invalid: () => 'border-red-500',
|
|
268
|
+
}),
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
const inputClassName = (field: Field<string>): string =>
|
|
272
|
+
clsx(
|
|
273
|
+
'w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500',
|
|
274
|
+
borderClass(field),
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
const statusIndicator = (field: Field<string>, h: HtmlBuilder<Message>): Html =>
|
|
278
|
+
M.value(field).pipe(
|
|
279
|
+
M.tagsExhaustive({
|
|
280
|
+
NotValidated: () => h.empty,
|
|
281
|
+
Validating: () =>
|
|
282
|
+
h.span([h.Class('text-blue-600 text-sm animate-spin')], ['◐']),
|
|
283
|
+
Valid: () => h.span([h.Class('text-green-600 text-sm')], ['✓']),
|
|
284
|
+
Invalid: () => h.empty,
|
|
285
|
+
}),
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
const descriptionView = (
|
|
289
|
+
field: Field<string>,
|
|
290
|
+
descriptionAttributes: ReadonlyArray<Attribute<Message>>,
|
|
291
|
+
h: HtmlBuilder<Message>,
|
|
292
|
+
): Html =>
|
|
293
|
+
M.value(field).pipe(
|
|
294
|
+
M.tagsExhaustive({
|
|
295
|
+
NotValidated: () => h.empty,
|
|
296
|
+
Validating: () =>
|
|
297
|
+
h.span(
|
|
298
|
+
[
|
|
299
|
+
...descriptionAttributes,
|
|
300
|
+
h.Class(clsx(DESCRIPTION_CLASS, 'text-blue-600')),
|
|
301
|
+
],
|
|
302
|
+
['Checking...'],
|
|
303
|
+
),
|
|
304
|
+
Valid: () => h.empty,
|
|
305
|
+
Invalid: ({ errors }) =>
|
|
306
|
+
h.span(
|
|
307
|
+
[
|
|
308
|
+
...descriptionAttributes,
|
|
309
|
+
h.Class(clsx(DESCRIPTION_CLASS, 'text-red-600')),
|
|
310
|
+
],
|
|
311
|
+
[Array.headNonEmpty(errors)],
|
|
312
|
+
),
|
|
313
|
+
}),
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
const inputFieldView = (
|
|
317
|
+
id: string,
|
|
318
|
+
labelText: string,
|
|
319
|
+
field: Field<string>,
|
|
320
|
+
onUpdate: (value: string) => Message,
|
|
321
|
+
type: string,
|
|
322
|
+
h: HtmlBuilder<Message>,
|
|
323
|
+
): Html =>
|
|
324
|
+
Input.view(
|
|
325
|
+
{
|
|
326
|
+
id,
|
|
327
|
+
value: field.value,
|
|
328
|
+
onInput: onUpdate,
|
|
329
|
+
isInvalid: field._tag === 'Invalid',
|
|
330
|
+
type,
|
|
331
|
+
toView: attributes =>
|
|
332
|
+
h.div(
|
|
333
|
+
[h.Class('mb-4')],
|
|
334
|
+
[
|
|
335
|
+
h.div(
|
|
336
|
+
[h.Class('flex items-center gap-2 mb-2')],
|
|
337
|
+
[
|
|
338
|
+
h.label(
|
|
339
|
+
[...attributes.label, h.Class(LABEL_CLASS)],
|
|
340
|
+
[labelText],
|
|
341
|
+
),
|
|
342
|
+
statusIndicator(field, h),
|
|
343
|
+
],
|
|
344
|
+
),
|
|
345
|
+
h.input([...attributes.input, h.Class(inputClassName(field))]),
|
|
346
|
+
descriptionView(field, attributes.description, h),
|
|
347
|
+
],
|
|
348
|
+
),
|
|
349
|
+
},
|
|
350
|
+
h,
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
const textareaFieldView = (
|
|
354
|
+
id: string,
|
|
355
|
+
labelText: string,
|
|
356
|
+
field: Field<string>,
|
|
357
|
+
onUpdate: (value: string) => Message,
|
|
358
|
+
h: HtmlBuilder<Message>,
|
|
359
|
+
): Html =>
|
|
360
|
+
Textarea.view(
|
|
361
|
+
{
|
|
362
|
+
id,
|
|
363
|
+
value: field.value,
|
|
364
|
+
onInput: onUpdate,
|
|
365
|
+
isInvalid: field._tag === 'Invalid',
|
|
366
|
+
toView: attributes =>
|
|
367
|
+
h.div(
|
|
368
|
+
[h.Class('mb-4')],
|
|
369
|
+
[
|
|
370
|
+
h.div(
|
|
371
|
+
[h.Class('flex items-center gap-2 mb-2')],
|
|
372
|
+
[
|
|
373
|
+
h.label(
|
|
374
|
+
[...attributes.label, h.Class(LABEL_CLASS)],
|
|
375
|
+
[labelText],
|
|
376
|
+
),
|
|
377
|
+
statusIndicator(field, h),
|
|
378
|
+
],
|
|
379
|
+
),
|
|
380
|
+
h.textarea([
|
|
381
|
+
...attributes.textarea,
|
|
382
|
+
h.Class(inputClassName(field)),
|
|
383
|
+
]),
|
|
384
|
+
descriptionView(field, attributes.description, h),
|
|
385
|
+
],
|
|
386
|
+
),
|
|
387
|
+
},
|
|
388
|
+
h,
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
export const view = (model: Model, h: HtmlBuilder<Message>): Document => {
|
|
392
|
+
const canSubmit = isFormValid(model) && model.submission._tag !== 'Submitting'
|
|
393
|
+
|
|
394
|
+
const body = h.div(
|
|
395
|
+
[h.Class('min-h-screen bg-gray-100 py-8')],
|
|
396
|
+
[
|
|
397
|
+
h.div(
|
|
398
|
+
[h.Class('max-w-md mx-auto bg-white rounded-xl shadow-lg p-6')],
|
|
399
|
+
[
|
|
400
|
+
h.h1(
|
|
401
|
+
[h.Class('text-3xl font-bold text-gray-800 text-center mb-8')],
|
|
402
|
+
['Join Our Waitlist'],
|
|
403
|
+
),
|
|
404
|
+
|
|
405
|
+
h.form(
|
|
406
|
+
[h.Class('space-y-4'), h.OnSubmit(Message.ClickedFormSubmit())],
|
|
407
|
+
[
|
|
408
|
+
inputFieldView(
|
|
409
|
+
'name',
|
|
410
|
+
'Name',
|
|
411
|
+
model.name,
|
|
412
|
+
value => Message.UpdatedName({ value }),
|
|
413
|
+
'text',
|
|
414
|
+
h,
|
|
415
|
+
),
|
|
416
|
+
inputFieldView(
|
|
417
|
+
'email',
|
|
418
|
+
'Email',
|
|
419
|
+
model.email,
|
|
420
|
+
value => Message.UpdatedEmail({ value }),
|
|
421
|
+
'email',
|
|
422
|
+
h,
|
|
423
|
+
),
|
|
424
|
+
textareaFieldView(
|
|
425
|
+
'message',
|
|
426
|
+
"Anything you'd like to share with us?",
|
|
427
|
+
model.messageText,
|
|
428
|
+
value => Message.UpdatedMessageText({ value }),
|
|
429
|
+
h,
|
|
430
|
+
),
|
|
431
|
+
|
|
432
|
+
Button.view(
|
|
433
|
+
{
|
|
434
|
+
type: 'submit',
|
|
435
|
+
isDisabled: !canSubmit,
|
|
436
|
+
toView: attributes =>
|
|
437
|
+
h.button(
|
|
438
|
+
[
|
|
439
|
+
...attributes.button,
|
|
440
|
+
h.Class(
|
|
441
|
+
clsx(
|
|
442
|
+
'w-full py-2 px-4 rounded-md transition',
|
|
443
|
+
canSubmit
|
|
444
|
+
? 'bg-blue-500 text-white hover:bg-blue-600'
|
|
445
|
+
: 'bg-gray-300 text-gray-500 cursor-not-allowed',
|
|
446
|
+
),
|
|
447
|
+
),
|
|
448
|
+
],
|
|
449
|
+
[
|
|
450
|
+
model.submission._tag === 'Submitting'
|
|
451
|
+
? 'Joining...'
|
|
452
|
+
: 'Join Waitlist',
|
|
453
|
+
],
|
|
454
|
+
),
|
|
455
|
+
},
|
|
456
|
+
h,
|
|
457
|
+
),
|
|
458
|
+
],
|
|
459
|
+
),
|
|
460
|
+
|
|
461
|
+
M.value(model.submission).pipe(
|
|
462
|
+
M.tagsExhaustive({
|
|
463
|
+
NotSubmitted: () => h.empty,
|
|
464
|
+
Submitting: () => h.empty,
|
|
465
|
+
SubmitSuccess: ({ confirmationText }) =>
|
|
466
|
+
h.div(
|
|
467
|
+
[
|
|
468
|
+
h.Role('status'),
|
|
469
|
+
h.Class(
|
|
470
|
+
'mt-4 p-3 bg-green-100 border border-green-400 text-green-700 rounded-lg',
|
|
471
|
+
),
|
|
472
|
+
],
|
|
473
|
+
[confirmationText],
|
|
474
|
+
),
|
|
475
|
+
SubmitError: ({ error }) =>
|
|
476
|
+
h.div(
|
|
477
|
+
[
|
|
478
|
+
h.Role('alert'),
|
|
479
|
+
h.Class(
|
|
480
|
+
'mt-4 p-3 bg-red-100 border border-red-400 text-red-700 rounded-lg',
|
|
481
|
+
),
|
|
482
|
+
],
|
|
483
|
+
[error],
|
|
484
|
+
),
|
|
485
|
+
}),
|
|
486
|
+
),
|
|
487
|
+
],
|
|
488
|
+
),
|
|
489
|
+
],
|
|
490
|
+
)
|
|
491
|
+
|
|
492
|
+
return { title: 'Foldkit Form Example', body }
|
|
493
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { FieldValidation } from 'foldkit'
|
|
2
|
+
import {
|
|
3
|
+
Command,
|
|
4
|
+
click,
|
|
5
|
+
expect,
|
|
6
|
+
given,
|
|
7
|
+
label,
|
|
8
|
+
role,
|
|
9
|
+
scene,
|
|
10
|
+
submit,
|
|
11
|
+
type,
|
|
12
|
+
} from 'foldkit/scene'
|
|
13
|
+
import { describe, test } from 'vitest'
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
Message,
|
|
17
|
+
SubmitForm,
|
|
18
|
+
ValidateEmail,
|
|
19
|
+
initialModel,
|
|
20
|
+
update,
|
|
21
|
+
view,
|
|
22
|
+
} from './main'
|
|
23
|
+
|
|
24
|
+
describe('view', () => {
|
|
25
|
+
test('initial view shows all fields and a disabled submit button', () => {
|
|
26
|
+
scene(
|
|
27
|
+
{ update, view },
|
|
28
|
+
given(initialModel),
|
|
29
|
+
expect(role('heading', { name: 'Join Our Waitlist' })).toExist(),
|
|
30
|
+
expect(label('Name')).toExist(),
|
|
31
|
+
expect(label('Email')).toExist(),
|
|
32
|
+
expect(label("Anything you'd like to share with us?")).toExist(),
|
|
33
|
+
expect(role('button', { name: 'Join Waitlist' })).toBeDisabled(),
|
|
34
|
+
)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('typing a short name shows a validation error via accessible description', () => {
|
|
38
|
+
scene(
|
|
39
|
+
{ update, view },
|
|
40
|
+
given(initialModel),
|
|
41
|
+
type(label('Name'), 'A'),
|
|
42
|
+
expect(label('Name')).toHaveAccessibleDescription(
|
|
43
|
+
'Name must be at least 2 characters',
|
|
44
|
+
),
|
|
45
|
+
)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('typing a malformed email surfaces a synchronous validation error', () => {
|
|
49
|
+
scene(
|
|
50
|
+
{ update, view },
|
|
51
|
+
given(initialModel),
|
|
52
|
+
type(label('Email'), 'not-an-email'),
|
|
53
|
+
expect(label('Email')).toHaveAccessibleDescription(
|
|
54
|
+
'Please enter a valid email address',
|
|
55
|
+
),
|
|
56
|
+
)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('typing a well-formed email triggers async validation', () => {
|
|
60
|
+
const modelWithValidName = {
|
|
61
|
+
...initialModel,
|
|
62
|
+
name: FieldValidation.Valid({ value: 'Alice' }),
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
scene(
|
|
66
|
+
{ update, view },
|
|
67
|
+
given(modelWithValidName),
|
|
68
|
+
type(label('Email'), 'alice@example.com'),
|
|
69
|
+
expect(label('Email')).toHaveAccessibleDescription('Checking...'),
|
|
70
|
+
expect(role('button', { name: 'Join Waitlist' })).toBeDisabled(),
|
|
71
|
+
Command.expectExact(ValidateEmail),
|
|
72
|
+
Command.resolve(
|
|
73
|
+
ValidateEmail,
|
|
74
|
+
Message.CompletedValidateEmail({
|
|
75
|
+
field: FieldValidation.Valid({ value: 'alice@example.com' }),
|
|
76
|
+
}),
|
|
77
|
+
),
|
|
78
|
+
expect(role('button', { name: 'Join Waitlist' })).toBeEnabled(),
|
|
79
|
+
)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test('async validation can flag an email as taken', () => {
|
|
83
|
+
scene(
|
|
84
|
+
{ update, view },
|
|
85
|
+
given(initialModel),
|
|
86
|
+
type(label('Email'), 'test@example.com'),
|
|
87
|
+
Command.expectExact(ValidateEmail),
|
|
88
|
+
Command.resolve(
|
|
89
|
+
ValidateEmail,
|
|
90
|
+
Message.CompletedValidateEmail({
|
|
91
|
+
field: FieldValidation.Invalid({
|
|
92
|
+
value: 'test@example.com',
|
|
93
|
+
errors: ['This email is already on our waitlist'],
|
|
94
|
+
}),
|
|
95
|
+
}),
|
|
96
|
+
),
|
|
97
|
+
expect(label('Email')).toHaveAccessibleDescription(
|
|
98
|
+
'This email is already on our waitlist',
|
|
99
|
+
),
|
|
100
|
+
)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test('submit becomes enabled once name and email are valid', () => {
|
|
104
|
+
const validModel = {
|
|
105
|
+
...initialModel,
|
|
106
|
+
name: FieldValidation.Valid({ value: 'Alice' }),
|
|
107
|
+
email: FieldValidation.Valid({ value: 'alice@example.com' }),
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
scene(
|
|
111
|
+
{ update, view },
|
|
112
|
+
given(validModel),
|
|
113
|
+
expect(role('button', { name: 'Join Waitlist' })).toBeEnabled(),
|
|
114
|
+
)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
test('submitting a valid form shows the loading label then a success banner', () => {
|
|
118
|
+
const validModel = {
|
|
119
|
+
...initialModel,
|
|
120
|
+
name: FieldValidation.Valid({ value: 'Alice' }),
|
|
121
|
+
email: FieldValidation.Valid({ value: 'alice@example.com' }),
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
scene(
|
|
125
|
+
{ update, view },
|
|
126
|
+
given(validModel),
|
|
127
|
+
click(role('button', { name: 'Join Waitlist' })),
|
|
128
|
+
expect(role('button', { name: 'Joining...' })).toBeDisabled(),
|
|
129
|
+
Command.expectExact(SubmitForm),
|
|
130
|
+
Command.resolve(
|
|
131
|
+
SubmitForm,
|
|
132
|
+
Message.SucceededSubmitForm({ name: 'Alice' }),
|
|
133
|
+
),
|
|
134
|
+
expect(role('status')).toContainText('Welcome to the waitlist, Alice!'),
|
|
135
|
+
expect(role('button', { name: 'Join Waitlist' })).toExist(),
|
|
136
|
+
)
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
test('a failed submission renders an error banner', () => {
|
|
140
|
+
const validModel = {
|
|
141
|
+
...initialModel,
|
|
142
|
+
name: FieldValidation.Valid({ value: 'Alice' }),
|
|
143
|
+
email: FieldValidation.Valid({ value: 'alice@example.com' }),
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
scene(
|
|
147
|
+
{ update, view },
|
|
148
|
+
given(validModel),
|
|
149
|
+
submit(role('form')),
|
|
150
|
+
Command.expectExact(SubmitForm),
|
|
151
|
+
Command.resolve(SubmitForm, Message.FailedSubmitForm()),
|
|
152
|
+
expect(role('alert')).toContainText('Sorry, there was an error'),
|
|
153
|
+
)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
test('submitting an invalid form (e.g. via Enter key) is rejected by update', () => {
|
|
157
|
+
scene(
|
|
158
|
+
{ update, view },
|
|
159
|
+
given(initialModel),
|
|
160
|
+
expect(role('button', { name: 'Join Waitlist' })).toBeDisabled(),
|
|
161
|
+
submit(role('form')),
|
|
162
|
+
expect(role('button', { name: 'Join Waitlist' })).toBeDisabled(),
|
|
163
|
+
)
|
|
164
|
+
})
|
|
165
|
+
})
|