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.
Files changed (460) hide show
  1. package/dist/index.js +1 -5
  2. package/{templates → dist/templates}/base/AGENTS.md +17 -19
  3. package/dist/templates/examples/api-cache/package.json +29 -0
  4. package/dist/templates/examples/api-cache/src/data.test.ts +28 -0
  5. package/dist/templates/examples/api-cache/src/data.ts +126 -0
  6. package/dist/templates/examples/api-cache/src/entry.ts +17 -0
  7. package/dist/templates/examples/api-cache/src/main.fixtures.ts +70 -0
  8. package/dist/templates/examples/api-cache/src/main.ts +744 -0
  9. package/dist/templates/examples/api-cache/src/scene.test.ts +120 -0
  10. package/dist/templates/examples/api-cache/src/story.test.ts +288 -0
  11. package/dist/templates/examples/api-cache/src/styles.css +1 -0
  12. package/dist/templates/examples/api-cache/src/vitest-setup.ts +3 -0
  13. package/dist/templates/examples/auth/package.json +30 -0
  14. package/dist/templates/examples/auth/src/command.ts +49 -0
  15. package/dist/templates/examples/auth/src/constant.ts +1 -0
  16. package/dist/templates/examples/auth/src/domain/session.ts +9 -0
  17. package/dist/templates/examples/auth/src/entry.ts +25 -0
  18. package/dist/templates/examples/auth/src/main.ts +75 -0
  19. package/dist/templates/examples/auth/src/message.ts +22 -0
  20. package/dist/templates/examples/auth/src/model.ts +9 -0
  21. package/dist/templates/examples/auth/src/notFoundView.ts +25 -0
  22. package/dist/templates/examples/auth/src/page/index.ts +2 -0
  23. package/dist/templates/examples/auth/src/page/loggedIn/index.ts +4 -0
  24. package/dist/templates/examples/auth/src/page/loggedIn/message.ts +17 -0
  25. package/dist/templates/examples/auth/src/page/loggedIn/model.ts +21 -0
  26. package/dist/templates/examples/auth/src/page/loggedIn/page/dashboard.ts +40 -0
  27. package/dist/templates/examples/auth/src/page/loggedIn/page/settings.ts +71 -0
  28. package/dist/templates/examples/auth/src/page/loggedIn/update.ts +16 -0
  29. package/dist/templates/examples/auth/src/page/loggedIn/view.ts +87 -0
  30. package/dist/templates/examples/auth/src/page/loggedOut/index.ts +4 -0
  31. package/dist/templates/examples/auth/src/page/loggedOut/message.ts +20 -0
  32. package/dist/templates/examples/auth/src/page/loggedOut/model.ts +21 -0
  33. package/dist/templates/examples/auth/src/page/loggedOut/page/home.ts +68 -0
  34. package/dist/templates/examples/auth/src/page/loggedOut/page/login.scene.test.ts +116 -0
  35. package/dist/templates/examples/auth/src/page/loggedOut/page/login.story.test.ts +112 -0
  36. package/dist/templates/examples/auth/src/page/loggedOut/page/login.ts +346 -0
  37. package/dist/templates/examples/auth/src/page/loggedOut/update.ts +32 -0
  38. package/dist/templates/examples/auth/src/page/loggedOut/view.ts +31 -0
  39. package/dist/templates/examples/auth/src/route.ts +56 -0
  40. package/dist/templates/examples/auth/src/scene.test.ts +61 -0
  41. package/dist/templates/examples/auth/src/styles.css +1 -0
  42. package/dist/templates/examples/auth/src/update.ts +179 -0
  43. package/dist/templates/examples/auth/src/view.ts +40 -0
  44. package/dist/templates/examples/auth/src/vitest-setup.ts +3 -0
  45. package/dist/templates/examples/canvas-art/package.json +29 -0
  46. package/dist/templates/examples/canvas-art/src/entry.ts +17 -0
  47. package/dist/templates/examples/canvas-art/src/main.ts +274 -0
  48. package/dist/templates/examples/canvas-art/src/scene.test.ts +70 -0
  49. package/dist/templates/examples/canvas-art/src/story.test.ts +155 -0
  50. package/dist/templates/examples/canvas-art/src/styles.css +1 -0
  51. package/dist/templates/examples/canvas-art/src/vitest-setup.ts +3 -0
  52. package/dist/templates/examples/charting/package.json +31 -0
  53. package/dist/templates/examples/charting/src/chartHost.ts +20 -0
  54. package/dist/templates/examples/charting/src/command.ts +62 -0
  55. package/dist/templates/examples/charting/src/domain.ts +175 -0
  56. package/dist/templates/examples/charting/src/echarts.ts +408 -0
  57. package/dist/templates/examples/charting/src/entry.ts +25 -0
  58. package/dist/templates/examples/charting/src/githubApi.ts +271 -0
  59. package/dist/templates/examples/charting/src/http.ts +50 -0
  60. package/dist/templates/examples/charting/src/init.test.ts +14 -0
  61. package/dist/templates/examples/charting/src/init.ts +29 -0
  62. package/dist/templates/examples/charting/src/main.fixtures.ts +162 -0
  63. package/dist/templates/examples/charting/src/message.ts +23 -0
  64. package/dist/templates/examples/charting/src/model.ts +22 -0
  65. package/dist/templates/examples/charting/src/npmApi.ts +75 -0
  66. package/dist/templates/examples/charting/src/radioGroups.ts +11 -0
  67. package/dist/templates/examples/charting/src/scene.test.ts +103 -0
  68. package/dist/templates/examples/charting/src/story.test.ts +145 -0
  69. package/dist/templates/examples/charting/src/styles.css +1 -0
  70. package/dist/templates/examples/charting/src/subscription.ts +70 -0
  71. package/dist/templates/examples/charting/src/telemetry.test.ts +64 -0
  72. package/dist/templates/examples/charting/src/telemetry.ts +432 -0
  73. package/dist/templates/examples/charting/src/update.ts +217 -0
  74. package/dist/templates/examples/charting/src/view/chart.ts +129 -0
  75. package/dist/templates/examples/charting/src/view/format.ts +23 -0
  76. package/dist/templates/examples/charting/src/view/index.ts +1 -0
  77. package/dist/templates/examples/charting/src/view/layout.ts +175 -0
  78. package/dist/templates/examples/charting/src/view/sidebar.ts +309 -0
  79. package/dist/templates/examples/charting/src/view/view.ts +23 -0
  80. package/dist/templates/examples/charting/src/vitest-setup.ts +3 -0
  81. package/dist/templates/examples/charting/src/weeks.ts +105 -0
  82. package/dist/templates/examples/counter/package.json +29 -0
  83. package/dist/templates/examples/counter/src/entry.ts +16 -0
  84. package/dist/templates/examples/counter/src/main.ts +95 -0
  85. package/dist/templates/examples/counter/src/scene.test.ts +57 -0
  86. package/dist/templates/examples/counter/src/story.test.ts +71 -0
  87. package/dist/templates/examples/counter/src/styles.css +1 -0
  88. package/dist/templates/examples/counter/src/vitest-setup.ts +3 -0
  89. package/dist/templates/examples/counters/package.json +29 -0
  90. package/dist/templates/examples/counters/src/counter.ts +70 -0
  91. package/dist/templates/examples/counters/src/entry.ts +16 -0
  92. package/dist/templates/examples/counters/src/main.ts +171 -0
  93. package/dist/templates/examples/counters/src/scene.test.ts +90 -0
  94. package/dist/templates/examples/counters/src/story.test.ts +127 -0
  95. package/dist/templates/examples/counters/src/styles.css +1 -0
  96. package/dist/templates/examples/counters/src/vitest-setup.ts +3 -0
  97. package/dist/templates/examples/crash-view/package.json +29 -0
  98. package/dist/templates/examples/crash-view/src/entry.ts +28 -0
  99. package/dist/templates/examples/crash-view/src/main.ts +104 -0
  100. package/dist/templates/examples/crash-view/src/scene.test.ts +14 -0
  101. package/dist/templates/examples/crash-view/src/story.test.ts +11 -0
  102. package/dist/templates/examples/crash-view/src/styles.css +1 -0
  103. package/dist/templates/examples/crash-view/src/vitest-setup.ts +3 -0
  104. package/dist/templates/examples/embedding/package.json +29 -0
  105. package/dist/templates/examples/embedding/src/entry.ts +3 -0
  106. package/dist/templates/examples/embedding/src/host.ts +108 -0
  107. package/dist/templates/examples/embedding/src/main.ts +144 -0
  108. package/dist/templates/examples/embedding/src/scene.test.ts +28 -0
  109. package/dist/templates/examples/embedding/src/story.test.ts +64 -0
  110. package/dist/templates/examples/embedding/src/styles.css +1 -0
  111. package/dist/templates/examples/embedding/src/vitest-setup.ts +3 -0
  112. package/dist/templates/examples/form/package.json +30 -0
  113. package/dist/templates/examples/form/src/entry.ts +16 -0
  114. package/dist/templates/examples/form/src/main.ts +493 -0
  115. package/dist/templates/examples/form/src/scene.test.ts +165 -0
  116. package/dist/templates/examples/form/src/story.test.ts +190 -0
  117. package/dist/templates/examples/form/src/styles.css +1 -0
  118. package/dist/templates/examples/form/src/vitest-setup.ts +3 -0
  119. package/dist/templates/examples/generative-art/package.json +29 -0
  120. package/dist/templates/examples/generative-art/src/command.ts +109 -0
  121. package/dist/templates/examples/generative-art/src/constant.ts +68 -0
  122. package/dist/templates/examples/generative-art/src/entry.ts +22 -0
  123. package/dist/templates/examples/generative-art/src/main.ts +59 -0
  124. package/dist/templates/examples/generative-art/src/message.ts +35 -0
  125. package/dist/templates/examples/generative-art/src/model.ts +33 -0
  126. package/dist/templates/examples/generative-art/src/noise.ts +93 -0
  127. package/dist/templates/examples/generative-art/src/scene.test.ts +103 -0
  128. package/dist/templates/examples/generative-art/src/story.test.ts +203 -0
  129. package/dist/templates/examples/generative-art/src/styles.css +1 -0
  130. package/dist/templates/examples/generative-art/src/subscription.ts +35 -0
  131. package/dist/templates/examples/generative-art/src/update.ts +319 -0
  132. package/dist/templates/examples/generative-art/src/view.ts +451 -0
  133. package/dist/templates/examples/generative-art/src/vitest-setup.ts +3 -0
  134. package/dist/templates/examples/interrupting-commands/package.json +29 -0
  135. package/dist/templates/examples/interrupting-commands/src/entry.ts +16 -0
  136. package/dist/templates/examples/interrupting-commands/src/main.ts +354 -0
  137. package/dist/templates/examples/interrupting-commands/src/scene.test.ts +89 -0
  138. package/dist/templates/examples/interrupting-commands/src/story.test.ts +224 -0
  139. package/dist/templates/examples/interrupting-commands/src/styles.css +1 -0
  140. package/dist/templates/examples/interrupting-commands/src/vitest-setup.ts +3 -0
  141. package/dist/templates/examples/job-application/package.json +30 -0
  142. package/dist/templates/examples/job-application/src/command.ts +23 -0
  143. package/dist/templates/examples/job-application/src/domain/index.ts +3 -0
  144. package/dist/templates/examples/job-application/src/domain/proficiencyLevel.ts +11 -0
  145. package/dist/templates/examples/job-application/src/domain/pronounOption.ts +13 -0
  146. package/dist/templates/examples/job-application/src/domain/step.ts +28 -0
  147. package/dist/templates/examples/job-application/src/entry.ts +17 -0
  148. package/dist/templates/examples/job-application/src/main.ts +69 -0
  149. package/dist/templates/examples/job-application/src/message.ts +44 -0
  150. package/dist/templates/examples/job-application/src/model.ts +47 -0
  151. package/dist/templates/examples/job-application/src/scene.test.ts +269 -0
  152. package/dist/templates/examples/job-application/src/step/attachments.ts +111 -0
  153. package/dist/templates/examples/job-application/src/step/coverLetter.ts +34 -0
  154. package/dist/templates/examples/job-application/src/step/education/education.ts +121 -0
  155. package/dist/templates/examples/job-application/src/step/education/entry.ts +168 -0
  156. package/dist/templates/examples/job-application/src/step/education/index.ts +2 -0
  157. package/dist/templates/examples/job-application/src/step/index.ts +6 -0
  158. package/dist/templates/examples/job-application/src/step/personalInfo.ts +305 -0
  159. package/dist/templates/examples/job-application/src/step/skills/entry.ts +126 -0
  160. package/dist/templates/examples/job-application/src/step/skills/index.ts +2 -0
  161. package/dist/templates/examples/job-application/src/step/skills/skills.ts +118 -0
  162. package/dist/templates/examples/job-application/src/step/validation.ts +6 -0
  163. package/dist/templates/examples/job-application/src/step/workHistory/entry.ts +206 -0
  164. package/dist/templates/examples/job-application/src/step/workHistory/index.ts +2 -0
  165. package/dist/templates/examples/job-application/src/step/workHistory/workHistory.ts +121 -0
  166. package/dist/templates/examples/job-application/src/story.test.ts +775 -0
  167. package/dist/templates/examples/job-application/src/styles.css +1 -0
  168. package/dist/templates/examples/job-application/src/update.ts +183 -0
  169. package/dist/templates/examples/job-application/src/view/attachments.ts +215 -0
  170. package/dist/templates/examples/job-application/src/view/coverLetter.ts +73 -0
  171. package/dist/templates/examples/job-application/src/view/datePicker.ts +207 -0
  172. package/dist/templates/examples/job-application/src/view/education.ts +63 -0
  173. package/dist/templates/examples/job-application/src/view/educationEntry.ts +165 -0
  174. package/dist/templates/examples/job-application/src/view/field.ts +183 -0
  175. package/dist/templates/examples/job-application/src/view/format.ts +50 -0
  176. package/dist/templates/examples/job-application/src/view/icon.ts +21 -0
  177. package/dist/templates/examples/job-application/src/view/index.ts +352 -0
  178. package/dist/templates/examples/job-application/src/view/personalInfo.ts +224 -0
  179. package/dist/templates/examples/job-application/src/view/preview.ts +265 -0
  180. package/dist/templates/examples/job-application/src/view/review.ts +388 -0
  181. package/dist/templates/examples/job-application/src/view/skillEntry.ts +102 -0
  182. package/dist/templates/examples/job-application/src/view/skills.ts +49 -0
  183. package/dist/templates/examples/job-application/src/view/stepNav.ts +181 -0
  184. package/dist/templates/examples/job-application/src/view/workEntry.ts +159 -0
  185. package/dist/templates/examples/job-application/src/view/workHistory.ts +55 -0
  186. package/dist/templates/examples/job-application/src/vitest-setup.ts +3 -0
  187. package/dist/templates/examples/kanban/package.json +31 -0
  188. package/dist/templates/examples/kanban/src/command.ts +46 -0
  189. package/dist/templates/examples/kanban/src/constant.ts +149 -0
  190. package/dist/templates/examples/kanban/src/domain/card.ts +10 -0
  191. package/dist/templates/examples/kanban/src/domain/column.ts +115 -0
  192. package/dist/templates/examples/kanban/src/domain/index.ts +2 -0
  193. package/dist/templates/examples/kanban/src/entry.ts +27 -0
  194. package/dist/templates/examples/kanban/src/main.ts +56 -0
  195. package/dist/templates/examples/kanban/src/message.ts +21 -0
  196. package/dist/templates/examples/kanban/src/model.ts +21 -0
  197. package/dist/templates/examples/kanban/src/scene.test.ts +161 -0
  198. package/dist/templates/examples/kanban/src/story.test.ts +461 -0
  199. package/dist/templates/examples/kanban/src/styles.css +1 -0
  200. package/dist/templates/examples/kanban/src/subscription.ts +16 -0
  201. package/dist/templates/examples/kanban/src/update.ts +205 -0
  202. package/dist/templates/examples/kanban/src/view/card.ts +79 -0
  203. package/dist/templates/examples/kanban/src/view/column.ts +283 -0
  204. package/dist/templates/examples/kanban/src/view/index.ts +71 -0
  205. package/dist/templates/examples/kanban/src/vitest-setup.ts +3 -0
  206. package/dist/templates/examples/managed-resource-layer/package.json +29 -0
  207. package/dist/templates/examples/managed-resource-layer/src/entry.ts +17 -0
  208. package/dist/templates/examples/managed-resource-layer/src/main.ts +309 -0
  209. package/dist/templates/examples/managed-resource-layer/src/scene.test.ts +117 -0
  210. package/dist/templates/examples/managed-resource-layer/src/story.test.ts +118 -0
  211. package/dist/templates/examples/managed-resource-layer/src/styles.css +1 -0
  212. package/dist/templates/examples/managed-resource-layer/src/vitest-setup.ts +3 -0
  213. package/dist/templates/examples/map/package.json +31 -0
  214. package/dist/templates/examples/map/src/entry.ts +17 -0
  215. package/dist/templates/examples/map/src/locations.ts +69 -0
  216. package/dist/templates/examples/map/src/main.fixtures.ts +28 -0
  217. package/dist/templates/examples/map/src/main.ts +781 -0
  218. package/dist/templates/examples/map/src/mapHost.ts +23 -0
  219. package/dist/templates/examples/map/src/scene.test.ts +136 -0
  220. package/dist/templates/examples/map/src/story.test.ts +190 -0
  221. package/dist/templates/examples/map/src/styles.css +2 -0
  222. package/dist/templates/examples/map/src/vitest-setup.ts +3 -0
  223. package/dist/templates/examples/pixel-art/package.json +31 -0
  224. package/dist/templates/examples/pixel-art/src/command.ts +87 -0
  225. package/dist/templates/examples/pixel-art/src/comparison.bench.test.ts +204 -0
  226. package/dist/templates/examples/pixel-art/src/constant.ts +21 -0
  227. package/dist/templates/examples/pixel-art/src/entry.ts +27 -0
  228. package/dist/templates/examples/pixel-art/src/grid.ts +134 -0
  229. package/dist/templates/examples/pixel-art/src/main.bench.ts +133 -0
  230. package/dist/templates/examples/pixel-art/src/main.ts +85 -0
  231. package/dist/templates/examples/pixel-art/src/message.ts +36 -0
  232. package/dist/templates/examples/pixel-art/src/model.ts +79 -0
  233. package/dist/templates/examples/pixel-art/src/palette.ts +134 -0
  234. package/dist/templates/examples/pixel-art/src/scene.test.ts +250 -0
  235. package/dist/templates/examples/pixel-art/src/story.test.ts +482 -0
  236. package/dist/templates/examples/pixel-art/src/styles.css +1 -0
  237. package/dist/templates/examples/pixel-art/src/subscription.ts +61 -0
  238. package/dist/templates/examples/pixel-art/src/update.ts +469 -0
  239. package/dist/templates/examples/pixel-art/src/view/canvas.ts +134 -0
  240. package/dist/templates/examples/pixel-art/src/view/dialog.ts +152 -0
  241. package/dist/templates/examples/pixel-art/src/view/history.ts +214 -0
  242. package/dist/templates/examples/pixel-art/src/view/index.ts +1 -0
  243. package/dist/templates/examples/pixel-art/src/view/toolbar.ts +452 -0
  244. package/dist/templates/examples/pixel-art/src/view/view.ts +183 -0
  245. package/dist/templates/examples/pixel-art/src/vitest-setup.ts +3 -0
  246. package/dist/templates/examples/query-sync/package.json +30 -0
  247. package/dist/templates/examples/query-sync/src/data.ts +166 -0
  248. package/dist/templates/examples/query-sync/src/entry.ts +20 -0
  249. package/dist/templates/examples/query-sync/src/main.ts +898 -0
  250. package/dist/templates/examples/query-sync/src/scene.test.ts +89 -0
  251. package/dist/templates/examples/query-sync/src/story.test.ts +151 -0
  252. package/dist/templates/examples/query-sync/src/styles.css +1 -0
  253. package/dist/templates/examples/query-sync/src/vitest-setup.ts +3 -0
  254. package/dist/templates/examples/route-transitions/package.json +28 -0
  255. package/dist/templates/examples/route-transitions/src/data.ts +61 -0
  256. package/dist/templates/examples/route-transitions/src/entry.ts +20 -0
  257. package/dist/templates/examples/route-transitions/src/main.ts +798 -0
  258. package/dist/templates/examples/route-transitions/src/route.ts +48 -0
  259. package/dist/templates/examples/route-transitions/src/story.test.ts +225 -0
  260. package/dist/templates/examples/route-transitions/src/styles.css +1 -0
  261. package/dist/templates/examples/route-transitions/src/vitest-setup.ts +3 -0
  262. package/dist/templates/examples/routing/package.json +29 -0
  263. package/dist/templates/examples/routing/src/entry.ts +20 -0
  264. package/dist/templates/examples/routing/src/fileTree.ts +98 -0
  265. package/dist/templates/examples/routing/src/main.ts +573 -0
  266. package/dist/templates/examples/routing/src/page/index.ts +1 -0
  267. package/dist/templates/examples/routing/src/page/people.ts +349 -0
  268. package/dist/templates/examples/routing/src/route.ts +82 -0
  269. package/dist/templates/examples/routing/src/scene.test.ts +180 -0
  270. package/dist/templates/examples/routing/src/story.test.ts +242 -0
  271. package/dist/templates/examples/routing/src/styles.css +1 -0
  272. package/dist/templates/examples/routing/src/vitest-setup.ts +3 -0
  273. package/dist/templates/examples/shopping-cart/package.json +29 -0
  274. package/dist/templates/examples/shopping-cart/src/data/products.ts +10 -0
  275. package/dist/templates/examples/shopping-cart/src/domain/cart.ts +77 -0
  276. package/dist/templates/examples/shopping-cart/src/domain/index.ts +2 -0
  277. package/dist/templates/examples/shopping-cart/src/domain/item.ts +16 -0
  278. package/dist/templates/examples/shopping-cart/src/entry.ts +20 -0
  279. package/dist/templates/examples/shopping-cart/src/main.ts +307 -0
  280. package/dist/templates/examples/shopping-cart/src/page/cart.ts +203 -0
  281. package/dist/templates/examples/shopping-cart/src/page/checkout.ts +205 -0
  282. package/dist/templates/examples/shopping-cart/src/page/index.ts +3 -0
  283. package/dist/templates/examples/shopping-cart/src/page/products.ts +267 -0
  284. package/dist/templates/examples/shopping-cart/src/route.ts +43 -0
  285. package/dist/templates/examples/shopping-cart/src/scene.test.ts +138 -0
  286. package/dist/templates/examples/shopping-cart/src/story.test.ts +233 -0
  287. package/dist/templates/examples/shopping-cart/src/styles.css +1 -0
  288. package/dist/templates/examples/shopping-cart/src/vitest-setup.ts +3 -0
  289. package/dist/templates/examples/slow-warnings/package.json +28 -0
  290. package/dist/templates/examples/slow-warnings/src/entry.ts +29 -0
  291. package/dist/templates/examples/slow-warnings/src/handleSlow.test.ts +43 -0
  292. package/dist/templates/examples/slow-warnings/src/main.ts +574 -0
  293. package/dist/templates/examples/slow-warnings/src/scene.test.ts +57 -0
  294. package/dist/templates/examples/slow-warnings/src/story.test.ts +118 -0
  295. package/dist/templates/examples/slow-warnings/src/styles.css +1 -0
  296. package/dist/templates/examples/slow-warnings/src/vitest-setup.ts +3 -0
  297. package/dist/templates/examples/snake/package.json +28 -0
  298. package/dist/templates/examples/snake/src/constants.ts +11 -0
  299. package/dist/templates/examples/snake/src/domain/apple.ts +22 -0
  300. package/dist/templates/examples/snake/src/domain/direction.ts +17 -0
  301. package/dist/templates/examples/snake/src/domain/index.ts +4 -0
  302. package/dist/templates/examples/snake/src/domain/position.ts +32 -0
  303. package/dist/templates/examples/snake/src/domain/snake.ts +43 -0
  304. package/dist/templates/examples/snake/src/entry.ts +17 -0
  305. package/dist/templates/examples/snake/src/main.ts +345 -0
  306. package/dist/templates/examples/snake/src/scene.test.ts +77 -0
  307. package/dist/templates/examples/snake/src/story.test.ts +165 -0
  308. package/dist/templates/examples/snake/src/styles.css +1 -0
  309. package/dist/templates/examples/snake/src/vitest-setup.ts +3 -0
  310. package/dist/templates/examples/ssg/package.json +29 -0
  311. package/dist/templates/examples/ssg/src/entry.server.ts +14 -0
  312. package/{templates/rendering → dist/templates/examples}/ssg/src/entry.ts +3 -11
  313. package/dist/templates/examples/ssg/src/main.ts +163 -0
  314. package/dist/templates/examples/ssg/src/styles.css +1 -0
  315. package/dist/templates/examples/ssr/package.json +33 -0
  316. package/dist/templates/examples/ssr/src/cookie.ts +13 -0
  317. package/dist/templates/examples/ssr/src/entry.server.ts +51 -0
  318. package/dist/templates/examples/ssr/src/main.ts +170 -0
  319. package/{templates/rendering → dist/templates/examples}/ssr/src/scene.test.ts +5 -8
  320. package/dist/templates/examples/ssr/src/styles.css +1 -0
  321. package/dist/templates/examples/ssr/src/vitest-setup.ts +3 -0
  322. package/dist/templates/examples/state-machine/package.json +30 -0
  323. package/dist/templates/examples/state-machine/src/entry.ts +17 -0
  324. package/dist/templates/examples/state-machine/src/icon.ts +51 -0
  325. package/dist/templates/examples/state-machine/src/main.ts +420 -0
  326. package/dist/templates/examples/state-machine/src/scene.test.ts +85 -0
  327. package/dist/templates/examples/state-machine/src/story.test.ts +199 -0
  328. package/dist/templates/examples/state-machine/src/styles.css +53 -0
  329. package/dist/templates/examples/state-machine/src/view.ts +1675 -0
  330. package/dist/templates/examples/state-machine/src/vitest-setup.ts +3 -0
  331. package/dist/templates/examples/stopwatch/package.json +29 -0
  332. package/dist/templates/examples/stopwatch/src/entry.ts +17 -0
  333. package/dist/templates/examples/stopwatch/src/main.ts +237 -0
  334. package/dist/templates/examples/stopwatch/src/scene.test.ts +124 -0
  335. package/dist/templates/examples/stopwatch/src/story.test.ts +126 -0
  336. package/dist/templates/examples/stopwatch/src/styles.css +1 -0
  337. package/dist/templates/examples/stopwatch/src/vitest-setup.ts +3 -0
  338. package/dist/templates/examples/todo/package.json +30 -0
  339. package/dist/templates/examples/todo/src/entry.ts +17 -0
  340. package/dist/templates/examples/todo/src/main.ts +682 -0
  341. package/dist/templates/examples/todo/src/scene.test.ts +177 -0
  342. package/dist/templates/examples/todo/src/story.test.ts +374 -0
  343. package/dist/templates/examples/todo/src/styles.css +1 -0
  344. package/dist/templates/examples/todo/src/vitest-setup.ts +3 -0
  345. package/dist/templates/examples/ui-showcase/package.json +30 -0
  346. package/dist/templates/examples/ui-showcase/src/entry.ts +31 -0
  347. package/dist/templates/examples/ui-showcase/src/icon.ts +64 -0
  348. package/dist/templates/examples/ui-showcase/src/main.ts +673 -0
  349. package/dist/templates/examples/ui-showcase/src/scene.test.ts +102 -0
  350. package/dist/templates/examples/ui-showcase/src/story.test.ts +128 -0
  351. package/dist/templates/examples/ui-showcase/src/styles.css +21 -0
  352. package/dist/templates/examples/ui-showcase/src/ui/init.ts +185 -0
  353. package/dist/templates/examples/ui-showcase/src/ui/message.ts +164 -0
  354. package/dist/templates/examples/ui-showcase/src/ui/model.ts +138 -0
  355. package/dist/templates/examples/ui-showcase/src/ui/subscriptions.ts +55 -0
  356. package/dist/templates/examples/ui-showcase/src/ui/toast.ts +13 -0
  357. package/dist/templates/examples/ui-showcase/src/ui/update.ts +1234 -0
  358. package/dist/templates/examples/ui-showcase/src/ui/view/animation.ts +58 -0
  359. package/dist/templates/examples/ui-showcase/src/ui/view/button.ts +64 -0
  360. package/dist/templates/examples/ui-showcase/src/ui/view/calendar.ts +202 -0
  361. package/dist/templates/examples/ui-showcase/src/ui/view/checkbox.ts +185 -0
  362. package/dist/templates/examples/ui-showcase/src/ui/view/combobox.ts +326 -0
  363. package/dist/templates/examples/ui-showcase/src/ui/view/datePicker.ts +263 -0
  364. package/dist/templates/examples/ui-showcase/src/ui/view/dialog.ts +427 -0
  365. package/dist/templates/examples/ui-showcase/src/ui/view/disclosure.ts +142 -0
  366. package/dist/templates/examples/ui-showcase/src/ui/view/dragAndDrop.ts +230 -0
  367. package/dist/templates/examples/ui-showcase/src/ui/view/fieldset.ts +284 -0
  368. package/dist/templates/examples/ui-showcase/src/ui/view/fileDrop.ts +119 -0
  369. package/dist/templates/examples/ui-showcase/src/ui/view/index.ts +24 -0
  370. package/dist/templates/examples/ui-showcase/src/ui/view/input.ts +90 -0
  371. package/dist/templates/examples/ui-showcase/src/ui/view/listbox.ts +263 -0
  372. package/dist/templates/examples/ui-showcase/src/ui/view/menu.ts +172 -0
  373. package/dist/templates/examples/ui-showcase/src/ui/view/popover.ts +262 -0
  374. package/dist/templates/examples/ui-showcase/src/ui/view/radioGroup.ts +192 -0
  375. package/dist/templates/examples/ui-showcase/src/ui/view/select.ts +129 -0
  376. package/dist/templates/examples/ui-showcase/src/ui/view/slider.ts +135 -0
  377. package/dist/templates/examples/ui-showcase/src/ui/view/switch.ts +82 -0
  378. package/dist/templates/examples/ui-showcase/src/ui/view/tabs.ts +187 -0
  379. package/dist/templates/examples/ui-showcase/src/ui/view/textarea.ts +99 -0
  380. package/dist/templates/examples/ui-showcase/src/ui/view/toast.ts +165 -0
  381. package/dist/templates/examples/ui-showcase/src/ui/view/tooltip.ts +123 -0
  382. package/dist/templates/examples/ui-showcase/src/ui/view/virtualList.ts +361 -0
  383. package/dist/templates/examples/ui-showcase/src/vitest-setup.ts +3 -0
  384. package/dist/templates/examples/view-transitions/package.json +28 -0
  385. package/dist/templates/examples/view-transitions/src/artwork.ts +80 -0
  386. package/dist/templates/examples/view-transitions/src/entry.ts +21 -0
  387. package/dist/templates/examples/view-transitions/src/main.ts +348 -0
  388. package/dist/templates/examples/view-transitions/src/route.ts +29 -0
  389. package/dist/templates/examples/view-transitions/src/scene.test.ts +130 -0
  390. package/dist/templates/examples/view-transitions/src/styles.css +66 -0
  391. package/dist/templates/examples/view-transitions/src/vitest-setup.ts +3 -0
  392. package/dist/templates/examples/weather/package.json +29 -0
  393. package/dist/templates/examples/weather/src/entry.ts +16 -0
  394. package/dist/templates/examples/weather/src/main.fixtures.ts +59 -0
  395. package/dist/templates/examples/weather/src/main.ts +356 -0
  396. package/dist/templates/examples/weather/src/scene.test.ts +109 -0
  397. package/dist/templates/examples/weather/src/story.test.ts +125 -0
  398. package/dist/templates/examples/weather/src/styles.css +1 -0
  399. package/dist/templates/examples/weather/src/vitest-setup.ts +3 -0
  400. package/dist/templates/examples/web-components/package.json +32 -0
  401. package/dist/templates/examples/web-components/src/entry.ts +16 -0
  402. package/dist/templates/examples/web-components/src/main.ts +327 -0
  403. package/dist/templates/examples/web-components/src/scene.test.ts +90 -0
  404. package/dist/templates/examples/web-components/src/story.test.ts +90 -0
  405. package/dist/templates/examples/web-components/src/styles.css +1 -0
  406. package/dist/templates/examples/web-components/src/vitest-setup.ts +3 -0
  407. package/dist/templates/examples/websocket-chat/package.json +29 -0
  408. package/dist/templates/examples/websocket-chat/src/entry.ts +26 -0
  409. package/dist/templates/examples/websocket-chat/src/main.ts +626 -0
  410. package/dist/templates/examples/websocket-chat/src/scene.test.ts +166 -0
  411. package/dist/templates/examples/websocket-chat/src/story.test.ts +183 -0
  412. package/dist/templates/examples/websocket-chat/src/styles.css +1 -0
  413. package/dist/templates/examples/websocket-chat/src/vitest-setup.ts +3 -0
  414. package/dist/templates/release.json +27 -0
  415. package/dist/templates/rendering/ssg/src/entry.ts +20 -0
  416. package/{templates → dist/templates}/rendering/ssg/src/main.ts +36 -43
  417. package/dist/templates/rendering/ssg/src/route.ts +20 -0
  418. package/dist/templates/rendering/ssg/src/vite-env.d.ts +19 -0
  419. package/dist/templates/rendering/ssr/src/entry.ts +17 -0
  420. package/{templates → dist/templates}/rendering/ssr/src/main.ts +17 -25
  421. package/dist/templates/rendering/ssr/src/scene.test.ts +40 -0
  422. package/dist/templates/rendering/ssr/src/vite-env.d.ts +19 -0
  423. package/dist/utils/files.js +23 -71
  424. package/dist/utils/packages.js +63 -44
  425. package/package.json +3 -4
  426. /package/{templates → dist/templates}/base/.mcp.json +0 -0
  427. /package/{templates → dist/templates}/base/.oxlintrc.json +0 -0
  428. /package/{templates → dist/templates}/base/.prettierignore +0 -0
  429. /package/{templates → dist/templates}/base/.prettierrc +0 -0
  430. /package/{templates → dist/templates}/base/README.md +0 -0
  431. /package/{templates → dist/templates}/base/gitignore +0 -0
  432. /package/{templates → dist/templates}/base/ignore +0 -0
  433. /package/{templates → dist/templates}/base/index.html +0 -0
  434. /package/{templates → dist/templates}/base/package.json +0 -0
  435. /package/{templates → dist/templates}/base/src/styles.css +0 -0
  436. /package/{templates → dist/templates}/base/src/vitest-setup.ts +0 -0
  437. /package/{templates → dist/templates}/base/tsconfig.json +0 -0
  438. /package/{templates → dist/templates}/base/vite.config.ts +0 -0
  439. /package/{templates → dist/templates}/base/vitest.config.ts +0 -0
  440. /package/{templates/rendering → dist/templates/examples}/ssg/src/route.ts +0 -0
  441. /package/{templates/rendering → dist/templates/examples}/ssg/src/vite-env.d.ts +0 -0
  442. /package/{templates/rendering → dist/templates/examples}/ssr/src/entry.ts +0 -0
  443. /package/{templates/rendering → dist/templates/examples}/ssr/src/vite-env.d.ts +0 -0
  444. /package/{templates → dist/templates}/package-managers/pnpm/pnpm-workspace.yaml +0 -0
  445. /package/{templates → dist/templates}/rendering/ssg/README.md +0 -0
  446. /package/{templates → dist/templates}/rendering/ssg/package.json +0 -0
  447. /package/{templates → dist/templates}/rendering/ssg/scripts/build.mjs +0 -0
  448. /package/{templates → dist/templates}/rendering/ssg/scripts/prerender.ts +0 -0
  449. /package/{templates → dist/templates}/rendering/ssg/src/entry.server.ts +0 -0
  450. /package/{templates → dist/templates}/rendering/ssg/src/scene.test.ts +0 -0
  451. /package/{templates → dist/templates}/rendering/ssg/tsconfig.json +0 -0
  452. /package/{templates → dist/templates}/rendering/ssg/vite.config.ts +0 -0
  453. /package/{templates → dist/templates}/rendering/ssr/README.md +0 -0
  454. /package/{templates → dist/templates}/rendering/ssr/package.json +0 -0
  455. /package/{templates → dist/templates}/rendering/ssr/scripts/build.mjs +0 -0
  456. /package/{templates → dist/templates}/rendering/ssr/server/main.ts +0 -0
  457. /package/{templates → dist/templates}/rendering/ssr/src/cookie.ts +0 -0
  458. /package/{templates → dist/templates}/rendering/ssr/src/entry.server.ts +0 -0
  459. /package/{templates → dist/templates}/rendering/ssr/tsconfig.json +0 -0
  460. /package/{templates → dist/templates}/rendering/ssr/vite.config.ts +0 -0
@@ -0,0 +1,744 @@
1
+ import {
2
+ Array,
3
+ Clock,
4
+ Duration,
5
+ Effect,
6
+ HashMap,
7
+ Match as M,
8
+ Option,
9
+ Schema as S,
10
+ Stream,
11
+ pipe,
12
+ } from 'effect'
13
+ import { AsyncData, Command, Runtime, Subscription, Update } from 'foldkit'
14
+ import { Document, Html, HtmlBuilder } from 'foldkit/html'
15
+ import { defineMessageUnion } from 'foldkit/message'
16
+ import { evo } from 'foldkit/struct'
17
+
18
+ import { Button, Tabs } from '@foldkit/ui'
19
+
20
+ import {
21
+ Post,
22
+ PostDetail,
23
+ Stats,
24
+ fetchPostDetail,
25
+ fetchPosts,
26
+ fetchStats,
27
+ } from './data'
28
+
29
+ const STATS_REFETCH_INTERVAL = Duration.seconds(5)
30
+
31
+ export const TABS_ID = 'api-cache-tabs'
32
+
33
+ // MODEL
34
+
35
+ const FetchedPosts = S.Struct({ posts: S.Array(Post), fetchedAt: S.Number })
36
+
37
+ const FetchedPostDetail = S.Struct({
38
+ detail: PostDetail,
39
+ fetchedAt: S.Number,
40
+ })
41
+
42
+ const FetchedStats = S.Struct({ stats: Stats, fetchedAt: S.Number })
43
+
44
+ export const PostsData = AsyncData.Schema(FetchedPosts, S.String)
45
+ export const PostDetailData = AsyncData.Schema(FetchedPostDetail, S.String)
46
+ export const StatsData = AsyncData.Schema(FetchedStats, S.String)
47
+
48
+ type PostsData = typeof PostsData.schema.Type
49
+ type PostDetailData = typeof PostDetailData.schema.Type
50
+ type StatsData = typeof StatsData.schema.Type
51
+
52
+ const Tab = S.Literals(['Posts', 'Stats'])
53
+ type Tab = typeof Tab.Type
54
+
55
+ const tabValues: ReadonlyArray<Tab> = Tab.literals
56
+
57
+ export const AppTabs = Tabs.create<Tab>()
58
+
59
+ export const Model = S.Struct({
60
+ tabs: Tabs.Model,
61
+ activeTab: Tab,
62
+ posts: PostsData.schema,
63
+ postDetailById: S.HashMap(S.String, PostDetailData.schema),
64
+ maybeSelectedPostId: S.Option(S.String),
65
+ stats: StatsData.schema,
66
+ })
67
+ export type Model = typeof Model.Type
68
+
69
+ // MESSAGE
70
+
71
+ export const Message = defineMessageUnion({
72
+ GotTabsMessage: { message: Tabs.Message },
73
+ ClickedPost: { postId: S.String },
74
+ ClickedBackToPosts: {},
75
+ ClickedInvalidatePosts: {},
76
+ ClickedRetryPosts: {},
77
+ ClickedRetryPostDetail: { postId: S.String },
78
+ ClickedRefreshStats: {},
79
+ ClickedRetryStats: {},
80
+ TickedRevalidateStats: {},
81
+ SettledFetchPosts: { result: S.Result(FetchedPosts, S.String) },
82
+ SettledFetchPostDetail: {
83
+ postId: S.String,
84
+ result: S.Result(FetchedPostDetail, S.String),
85
+ },
86
+ SettledFetchStats: { result: S.Result(FetchedStats, S.String) },
87
+ })
88
+
89
+ export type Message = typeof Message.Type
90
+
91
+ // UPDATE
92
+
93
+ type UpdateReturn = readonly [Model, ReadonlyArray<Command.Command<Message>>]
94
+
95
+ const applyPostsTransition = (
96
+ model: Model,
97
+ maybeNextPosts: Option.Option<PostsData>,
98
+ ): UpdateReturn =>
99
+ Option.match(maybeNextPosts, {
100
+ onNone: () => [model, []],
101
+ onSome: nextPosts => [
102
+ evo(model, { posts: () => nextPosts }),
103
+ [FetchPosts()],
104
+ ],
105
+ })
106
+
107
+ const applyStatsTransition = (
108
+ model: Model,
109
+ maybeNextStats: Option.Option<StatsData>,
110
+ ): UpdateReturn =>
111
+ Option.match(maybeNextStats, {
112
+ onNone: () => [model, []],
113
+ onSome: nextStats => [
114
+ evo(model, { stats: () => nextStats }),
115
+ [FetchStats()],
116
+ ],
117
+ })
118
+
119
+ const setPostDetail = (postId: string, postDetail: PostDetailData) =>
120
+ HashMap.set(postId, postDetail)
121
+
122
+ const activateTab = (model: Model, tab: Tab): UpdateReturn => {
123
+ const modelWithActiveTab = evo(model, { activeTab: () => tab })
124
+
125
+ return M.value(tab).pipe(
126
+ M.withReturnType<UpdateReturn>(),
127
+ M.when('Posts', () =>
128
+ applyPostsTransition(
129
+ modelWithActiveTab,
130
+ AsyncData.loadIfMissing(modelWithActiveTab.posts),
131
+ ),
132
+ ),
133
+ M.when('Stats', () =>
134
+ applyStatsTransition(
135
+ modelWithActiveTab,
136
+ AsyncData.loadIfMissing(modelWithActiveTab.stats),
137
+ ),
138
+ ),
139
+ M.exhaustive,
140
+ )
141
+ }
142
+
143
+ const foldTabsOutMessage = M.type<Tabs.OutMessage<Tab>>().pipe(
144
+ M.withReturnType<Update.Step<Model, Message>>(),
145
+ M.tagsExhaustive({
146
+ Selected:
147
+ ({ value }) =>
148
+ model =>
149
+ activateTab(model, value),
150
+ }),
151
+ )
152
+
153
+ const foldTabs = Update.foldChild({
154
+ update: AppTabs.update,
155
+ read: (model: Model) => Option.some(model.tabs),
156
+ write: (model, nextTabs) => evo(model, { tabs: () => nextTabs }),
157
+ toParentMessage: message => Message.GotTabsMessage({ message }),
158
+ foldOutMessage: foldTabsOutMessage,
159
+ })
160
+
161
+ export const update = (model: Model, message: Message) =>
162
+ Message.match<UpdateReturn>(message, {
163
+ GotTabsMessage: ({ message }) => foldTabs(model, message),
164
+
165
+ ClickedPost: ({ postId }) => {
166
+ const selectedModel = evo(model, {
167
+ maybeSelectedPostId: () => Option.some(postId),
168
+ })
169
+
170
+ return Option.match(HashMap.get(model.postDetailById, postId), {
171
+ onNone: () => [
172
+ evo(selectedModel, {
173
+ postDetailById: setPostDetail(postId, PostDetailData.Loading()),
174
+ }),
175
+ [FetchPostDetail({ postId })],
176
+ ],
177
+ onSome: () => [selectedModel, []],
178
+ })
179
+ },
180
+
181
+ ClickedBackToPosts: () => [
182
+ evo(model, { maybeSelectedPostId: () => Option.none() }),
183
+ [],
184
+ ],
185
+
186
+ ClickedInvalidatePosts: () =>
187
+ applyPostsTransition(model, AsyncData.revalidateOrLoad(model.posts)),
188
+
189
+ ClickedRetryPosts: () =>
190
+ applyPostsTransition(model, AsyncData.revalidateOrLoad(model.posts)),
191
+
192
+ ClickedRetryPostDetail: ({ postId }) => [
193
+ evo(model, {
194
+ postDetailById: setPostDetail(postId, PostDetailData.Loading()),
195
+ }),
196
+ [FetchPostDetail({ postId })],
197
+ ],
198
+
199
+ ClickedRefreshStats: () =>
200
+ applyStatsTransition(model, AsyncData.revalidateOrLoad(model.stats)),
201
+
202
+ ClickedRetryStats: () =>
203
+ applyStatsTransition(model, AsyncData.revalidateOrLoad(model.stats)),
204
+
205
+ TickedRevalidateStats: () =>
206
+ applyStatsTransition(model, AsyncData.revalidate(model.stats)),
207
+
208
+ SettledFetchPosts: ({ result }) => [
209
+ evo(model, { posts: AsyncData.settle(result) }),
210
+ [],
211
+ ],
212
+
213
+ SettledFetchPostDetail: ({ postId, result }) => [
214
+ evo(model, {
215
+ postDetailById: HashMap.modify(postId, AsyncData.settle(result)),
216
+ }),
217
+ [],
218
+ ],
219
+
220
+ SettledFetchStats: ({ result }) => [
221
+ evo(model, { stats: AsyncData.settle(result) }),
222
+ [],
223
+ ],
224
+ })
225
+
226
+ // INIT
227
+
228
+ export const init: Runtime.ApplicationInit<Model, Message> = () => [
229
+ {
230
+ tabs: Tabs.init({ id: TABS_ID }),
231
+ activeTab: 'Posts',
232
+ posts: PostsData.Loading(),
233
+ postDetailById: HashMap.empty(),
234
+ maybeSelectedPostId: Option.none(),
235
+ stats: StatsData.Idle(),
236
+ },
237
+ [FetchPosts()],
238
+ ]
239
+
240
+ // COMMAND
241
+
242
+ export const FetchPosts = Command.define('FetchPosts', {
243
+ messages: [Message.SettledFetchPosts],
244
+ execute: pipe(
245
+ Effect.gen(function* () {
246
+ const posts = yield* fetchPosts
247
+ const fetchedAt = yield* Clock.currentTimeMillis
248
+ return FetchedPosts.make({ posts, fetchedAt })
249
+ }),
250
+ Effect.result,
251
+ Effect.map(result => Message.SettledFetchPosts({ result })),
252
+ ),
253
+ })
254
+
255
+ export const FetchPostDetail = Command.define('FetchPostDetail', {
256
+ args: { postId: S.String },
257
+ messages: [Message.SettledFetchPostDetail],
258
+ execute: ({ postId }) =>
259
+ pipe(
260
+ Effect.gen(function* () {
261
+ const detail = yield* fetchPostDetail(postId)
262
+ const fetchedAt = yield* Clock.currentTimeMillis
263
+ return FetchedPostDetail.make({ detail, fetchedAt })
264
+ }),
265
+ Effect.result,
266
+ Effect.map(result => Message.SettledFetchPostDetail({ postId, result })),
267
+ ),
268
+ })
269
+
270
+ export const FetchStats = Command.define('FetchStats', {
271
+ messages: [Message.SettledFetchStats],
272
+ execute: pipe(
273
+ Effect.gen(function* () {
274
+ const stats = yield* fetchStats
275
+ const fetchedAt = yield* Clock.currentTimeMillis
276
+ return FetchedStats.make({ stats, fetchedAt })
277
+ }),
278
+ Effect.result,
279
+ Effect.map(result => Message.SettledFetchStats({ result })),
280
+ ),
281
+ })
282
+
283
+ // SUBSCRIPTION
284
+
285
+ export const subscriptions = Subscription.make<Model, Message>()(entry => ({
286
+ revalidateStats: entry(
287
+ { isObservingStats: S.Boolean },
288
+ {
289
+ modelToDependencies: model => ({
290
+ isObservingStats:
291
+ model.activeTab === 'Stats' && AsyncData.hasData(model.stats),
292
+ }),
293
+ dependenciesToStream: ({ isObservingStats }) =>
294
+ Stream.when(
295
+ // NOTE: Stream.tick emits once immediately. Drop that first
296
+ // emission so freshly loaded stats are not refetched instantly.
297
+ Stream.tick(STATS_REFETCH_INTERVAL).pipe(
298
+ Stream.drop(1),
299
+ Stream.map(Message.TickedRevalidateStats),
300
+ ),
301
+ Effect.sync(() => isObservingStats),
302
+ ),
303
+ },
304
+ ),
305
+ }))
306
+
307
+ // VIEW
308
+
309
+ const formatFetchedAt = (fetchedAt: number): string =>
310
+ new Date(fetchedAt).toLocaleTimeString()
311
+
312
+ const tabButtonClassName =
313
+ 'px-4 py-2 rounded-lg bg-white text-slate-600 font-semibold hover:bg-slate-50 transition cursor-pointer data-[selected]:bg-indigo-600 data-[selected]:text-white data-[selected]:hover:bg-indigo-600'
314
+
315
+ const toolbarButtonClassName =
316
+ 'px-3 py-1.5 bg-white text-slate-700 text-sm font-semibold rounded-md shadow hover:bg-slate-50 transition cursor-pointer data-[disabled]:opacity-50 data-[disabled]:cursor-default data-[disabled]:hover:bg-white'
317
+
318
+ export const view = (model: Model, h: HtmlBuilder<Message>): Document => ({
319
+ title: 'API Cache',
320
+ body: h.div(
321
+ [h.Class('min-h-screen bg-slate-100 flex justify-center p-6')],
322
+ [
323
+ h.div(
324
+ [h.Class('w-full max-w-2xl flex flex-col gap-6')],
325
+ [
326
+ headerView(h),
327
+ h.submodel({
328
+ slotId: TABS_ID,
329
+ model: model.tabs,
330
+ view: AppTabs.view,
331
+ viewInputs: {
332
+ tabs: tabValues,
333
+ selectedValue: model.activeTab,
334
+ ariaLabel: 'API cache sections',
335
+ toView: ({ tablist, tabs }) =>
336
+ h.div(
337
+ [h.Class('flex flex-col gap-6')],
338
+ [
339
+ h.div(
340
+ [...tablist, h.Class('flex gap-2')],
341
+ Array.map(tabs, tabInfo =>
342
+ h.keyed('button')(
343
+ tabInfo.value,
344
+ [...tabInfo.tab, h.Class(tabButtonClassName)],
345
+ [tabInfo.value],
346
+ ),
347
+ ),
348
+ ),
349
+ ...pipe(
350
+ tabs,
351
+ Array.filter(tabInfo => tabInfo.isActive),
352
+ Array.map(tabInfo =>
353
+ h.keyed('div')(
354
+ tabInfo.value,
355
+ [...tabInfo.panel, h.Class('flex flex-col gap-4')],
356
+ [
357
+ M.value(tabInfo.value).pipe(
358
+ M.when('Posts', () => postsTabView(model, h)),
359
+ M.when('Stats', () => statsTabView(model, h)),
360
+ M.exhaustive,
361
+ ),
362
+ ],
363
+ ),
364
+ ),
365
+ ),
366
+ ],
367
+ ),
368
+ },
369
+ toParentMessage: message => Message.GotTabsMessage({ message }),
370
+ }),
371
+ ],
372
+ ),
373
+ ],
374
+ ),
375
+ })
376
+
377
+ const headerView = (h: HtmlBuilder<Message>): Html =>
378
+ h.header(
379
+ [h.Class('flex flex-col gap-1')],
380
+ [
381
+ h.h1([h.Class('text-3xl font-bold text-slate-900')], ['API Cache']),
382
+ h.p(
383
+ [h.Class('text-slate-600')],
384
+ [
385
+ 'Query client patterns written as ordinary Model state, update logic, and one Subscription.',
386
+ ],
387
+ ),
388
+ ],
389
+ )
390
+
391
+ const postsTabView = (model: Model, h: HtmlBuilder<Message>): Html =>
392
+ Option.match(model.maybeSelectedPostId, {
393
+ onNone: () =>
394
+ h.section([h.Class('flex flex-col gap-4')], [postsListView(model, h)]),
395
+ onSome: postId =>
396
+ h.keyed('section')(
397
+ postId,
398
+ [h.Class('flex flex-col gap-4')],
399
+ [postDetailView(model, postId, h)],
400
+ ),
401
+ })
402
+
403
+ const postsListView = (model: Model, h: HtmlBuilder<Message>): Html => {
404
+ const isPending = AsyncData.isPending(model.posts)
405
+
406
+ return h.div(
407
+ [h.Class('flex flex-col gap-4')],
408
+ [
409
+ h.div(
410
+ [h.Class('flex items-center justify-between')],
411
+ [
412
+ h.h2([h.Class('text-xl font-bold text-slate-800')], ['Posts']),
413
+ Button.view(
414
+ {
415
+ onClick: Message.ClickedInvalidatePosts(),
416
+ isDisabled: isPending,
417
+ toView: attributes =>
418
+ h.button(
419
+ [...attributes.button, h.Class(toolbarButtonClassName)],
420
+ [
421
+ AsyncData.isRefreshing(model.posts)
422
+ ? 'Refreshing...'
423
+ : 'Invalidate',
424
+ ],
425
+ ),
426
+ },
427
+ h,
428
+ ),
429
+ ],
430
+ ),
431
+ h.p(
432
+ [h.Class('text-sm text-slate-500')],
433
+ [
434
+ 'Open a post, go back, and open it again. The second visit renders instantly from the Model. Invalidate marks the list stale and refetches it while the current list stays on screen.',
435
+ ],
436
+ ),
437
+ AsyncData.matchDataSplitEmpty(model.posts, {
438
+ onIdle: () => loadingPanel('Loading posts...', h),
439
+ onLoading: () => loadingPanel('Loading posts...', h),
440
+ onFailure: error => errorPanel(error, Message.ClickedRetryPosts(), h),
441
+ onData: ({ posts }) =>
442
+ h.div(
443
+ [h.Class('flex flex-col gap-4')],
444
+ [
445
+ ...Option.match(AsyncData.getError(model.posts), {
446
+ onNone: () => [],
447
+ onSome: error => [
448
+ staleView(error, Message.ClickedRetryPosts(), h),
449
+ ],
450
+ }),
451
+ h.ul(
452
+ [h.Class('flex flex-col gap-2')],
453
+ postListItems(posts, model.postDetailById, h),
454
+ ),
455
+ ],
456
+ ),
457
+ }),
458
+ ],
459
+ )
460
+ }
461
+
462
+ const isPostDetailCached = (
463
+ postDetailById: HashMap.HashMap<string, PostDetailData>,
464
+ postId: string,
465
+ ): boolean =>
466
+ Option.exists(HashMap.get(postDetailById, postId), AsyncData.hasData)
467
+
468
+ const postListItems = (
469
+ posts: ReadonlyArray<Post>,
470
+ postDetailById: HashMap.HashMap<string, PostDetailData>,
471
+ h: HtmlBuilder<Message>,
472
+ ): ReadonlyArray<Html> =>
473
+ Array.map(posts, post =>
474
+ h.keyed('li')(
475
+ post.id,
476
+ [],
477
+ [
478
+ Button.view(
479
+ {
480
+ onClick: Message.ClickedPost({ postId: post.id }),
481
+ toView: attributes =>
482
+ h.button(
483
+ [
484
+ ...attributes.button,
485
+ h.Class(
486
+ 'w-full text-left bg-white rounded-lg shadow px-4 py-3 hover:bg-slate-50 transition cursor-pointer flex items-center justify-between gap-4',
487
+ ),
488
+ ],
489
+ [
490
+ h.div(
491
+ [],
492
+ [
493
+ h.div(
494
+ [h.Class('font-semibold text-slate-800')],
495
+ [post.title],
496
+ ),
497
+ h.div(
498
+ [h.Class('text-sm text-slate-500')],
499
+ [post.excerpt],
500
+ ),
501
+ ],
502
+ ),
503
+ isPostDetailCached(postDetailById, post.id)
504
+ ? h.span(
505
+ [
506
+ h.Class(
507
+ 'shrink-0 text-xs font-semibold text-emerald-700 bg-emerald-100 rounded-full px-2 py-1',
508
+ ),
509
+ ],
510
+ ['Cached'],
511
+ )
512
+ : h.empty,
513
+ ],
514
+ ),
515
+ },
516
+ h,
517
+ ),
518
+ ],
519
+ ),
520
+ )
521
+
522
+ const postDetailView = (
523
+ model: Model,
524
+ postId: string,
525
+ h: HtmlBuilder<Message>,
526
+ ): Html => {
527
+ const postDetailData = Option.getOrElse(
528
+ HashMap.get(model.postDetailById, postId),
529
+ () => PostDetailData.Idle(),
530
+ )
531
+
532
+ return h.div(
533
+ [h.Class('flex flex-col gap-4')],
534
+ [
535
+ Button.view(
536
+ {
537
+ onClick: Message.ClickedBackToPosts(),
538
+ toView: attributes =>
539
+ h.button(
540
+ [
541
+ ...attributes.button,
542
+ h.Class(
543
+ 'self-start text-sm font-semibold text-indigo-600 hover:underline cursor-pointer',
544
+ ),
545
+ ],
546
+ ['Back to posts'],
547
+ ),
548
+ },
549
+ h,
550
+ ),
551
+ AsyncData.matchDataSplitEmpty(postDetailData, {
552
+ onIdle: () => loadingPanel('Loading post...', h),
553
+ onLoading: () => loadingPanel('Loading post...', h),
554
+ onFailure: error =>
555
+ errorPanel(error, Message.ClickedRetryPostDetail({ postId }), h),
556
+ onData: ({ detail, fetchedAt }) =>
557
+ h.div(
558
+ [h.Class('flex flex-col gap-4')],
559
+ [
560
+ ...Option.match(AsyncData.getError(postDetailData), {
561
+ onNone: () => [],
562
+ onSome: error => [
563
+ staleView(
564
+ error,
565
+ Message.ClickedRetryPostDetail({ postId }),
566
+ h,
567
+ ),
568
+ ],
569
+ }),
570
+ postDetailCard(detail, fetchedAt, h),
571
+ ],
572
+ ),
573
+ }),
574
+ ],
575
+ )
576
+ }
577
+
578
+ const postDetailCard = (
579
+ detail: PostDetail,
580
+ fetchedAt: number,
581
+ h: HtmlBuilder<Message>,
582
+ ): Html =>
583
+ h.article(
584
+ [h.Class('bg-white rounded-xl shadow p-6 flex flex-col gap-3')],
585
+ [
586
+ h.h2([h.Class('text-2xl font-bold text-slate-900')], [detail.title]),
587
+ h.p([h.Class('text-sm text-slate-500')], [`By ${detail.author}`]),
588
+ h.p([h.Class('text-slate-700 leading-relaxed')], [detail.body]),
589
+ h.p(
590
+ [h.Class('text-xs text-slate-400')],
591
+ [
592
+ `Fetched at ${formatFetchedAt(fetchedAt)}. Future visits render instantly from the Model.`,
593
+ ],
594
+ ),
595
+ ],
596
+ )
597
+
598
+ const statsTabView = (model: Model, h: HtmlBuilder<Message>): Html => {
599
+ const isPending = AsyncData.isPending(model.stats)
600
+
601
+ return h.div(
602
+ [h.Class('flex flex-col gap-4')],
603
+ [
604
+ h.div(
605
+ [h.Class('flex items-center justify-between')],
606
+ [
607
+ h.h2([h.Class('text-xl font-bold text-slate-800')], ['Stats']),
608
+ Button.view(
609
+ {
610
+ onClick: Message.ClickedRefreshStats(),
611
+ isDisabled: isPending,
612
+ toView: attributes =>
613
+ h.button(
614
+ [...attributes.button, h.Class(toolbarButtonClassName)],
615
+ [isPending ? 'Refreshing...' : 'Refresh'],
616
+ ),
617
+ },
618
+ h,
619
+ ),
620
+ ],
621
+ ),
622
+ h.p(
623
+ [h.Class('text-sm text-slate-500')],
624
+ [
625
+ 'Stats refetch every 5 seconds while this tab is open. The old numbers stay on screen while the new ones load.',
626
+ ],
627
+ ),
628
+ AsyncData.matchDataSplitEmpty(model.stats, {
629
+ onIdle: () => loadingPanel('Loading stats...', h),
630
+ onLoading: () => loadingPanel('Loading stats...', h),
631
+ onFailure: error => errorPanel(error, Message.ClickedRetryStats(), h),
632
+ onData: ({ stats, fetchedAt }) =>
633
+ h.div(
634
+ [h.Class('flex flex-col gap-4')],
635
+ [
636
+ ...Option.match(AsyncData.getError(model.stats), {
637
+ onNone: () => [],
638
+ onSome: error => [
639
+ staleView(error, Message.ClickedRetryStats(), h),
640
+ ],
641
+ }),
642
+ statsCards(
643
+ stats,
644
+ fetchedAt,
645
+ AsyncData.isRefreshing(model.stats),
646
+ h,
647
+ ),
648
+ ],
649
+ ),
650
+ }),
651
+ ],
652
+ )
653
+ }
654
+
655
+ const statsCards = (
656
+ stats: Stats,
657
+ fetchedAt: number,
658
+ isRefreshing: boolean,
659
+ h: HtmlBuilder<Message>,
660
+ ): Html =>
661
+ h.div(
662
+ [h.Class('flex flex-col gap-3')],
663
+ [
664
+ h.div(
665
+ [h.Class('grid grid-cols-3 gap-4')],
666
+ [
667
+ statCard('Active users', `${stats.activeUsers}`, h),
668
+ statCard('Requests per second', `${stats.requestsPerSecond}`, h),
669
+ statCard('Cache hit rate', `${stats.cacheHitRatePercent}%`, h),
670
+ ],
671
+ ),
672
+ h.div(
673
+ [h.Class('flex items-center gap-3 text-sm text-slate-500')],
674
+ [
675
+ h.span([], [`Updated at ${formatFetchedAt(fetchedAt)}`]),
676
+ ...(isRefreshing
677
+ ? [
678
+ h.span(
679
+ [h.Class('text-indigo-600 font-semibold')],
680
+ ['Refreshing'],
681
+ ),
682
+ ]
683
+ : []),
684
+ ],
685
+ ),
686
+ ],
687
+ )
688
+
689
+ const statCard = (
690
+ label: string,
691
+ value: string,
692
+ h: HtmlBuilder<Message>,
693
+ ): Html =>
694
+ h.div(
695
+ [h.Class('bg-white rounded-xl shadow p-4 flex flex-col gap-1')],
696
+ [
697
+ h.div([h.Class('text-sm text-slate-500')], [label]),
698
+ h.div([h.Class('text-2xl font-bold text-slate-900')], [value]),
699
+ ],
700
+ )
701
+
702
+ const loadingPanel = (text: string, h: HtmlBuilder<Message>): Html =>
703
+ h.div(
704
+ [h.Class('bg-white rounded-lg shadow p-6 text-center text-slate-500')],
705
+ [text],
706
+ )
707
+
708
+ const staleView = (
709
+ error: string,
710
+ retryMessage: Message,
711
+ h: HtmlBuilder<Message>,
712
+ ): Html => errorPanel(error, retryMessage, h)
713
+
714
+ const errorPanel = (
715
+ error: string,
716
+ retryMessage: Message,
717
+ h: HtmlBuilder<Message>,
718
+ ): Html =>
719
+ h.div(
720
+ [
721
+ h.Class(
722
+ 'bg-red-50 border border-red-200 text-red-700 rounded-lg p-4 flex items-center justify-between gap-4',
723
+ ),
724
+ ],
725
+ [
726
+ h.p([], [error]),
727
+ Button.view(
728
+ {
729
+ onClick: retryMessage,
730
+ toView: attributes =>
731
+ h.button(
732
+ [
733
+ ...attributes.button,
734
+ h.Class(
735
+ 'shrink-0 px-3 py-1.5 bg-red-600 text-white text-sm font-semibold rounded-md hover:bg-red-700 transition cursor-pointer',
736
+ ),
737
+ ],
738
+ ['Retry'],
739
+ ),
740
+ },
741
+ h,
742
+ ),
743
+ ],
744
+ )