create-foldkit-app 0.31.1 → 0.32.0-canary.d902ee3d7d0b

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 (77) hide show
  1. package/dist/templates/base/FOLDKIT.md +1 -1
  2. package/dist/templates/examples/api-cache/package.json +7 -7
  3. package/dist/templates/examples/auth/package.json +7 -7
  4. package/dist/templates/examples/auth/src/page/loggedOut/page/login.ts +28 -35
  5. package/dist/templates/examples/auth/src/update.ts +10 -13
  6. package/dist/templates/examples/canvas-art/package.json +7 -7
  7. package/dist/templates/examples/charting/package.json +7 -7
  8. package/dist/templates/examples/charting/src/view/chart.ts +43 -45
  9. package/dist/templates/examples/counter/package.json +7 -7
  10. package/dist/templates/examples/counters/package.json +7 -7
  11. package/dist/templates/examples/crash-view/package.json +7 -7
  12. package/dist/templates/examples/embedding/package.json +7 -7
  13. package/dist/templates/examples/form/package.json +7 -7
  14. package/dist/templates/examples/form/src/main.ts +59 -74
  15. package/dist/templates/examples/generative-art/package.json +7 -7
  16. package/dist/templates/examples/interrupting-commands/package.json +7 -7
  17. package/dist/templates/examples/interrupting-commands/src/main.ts +6 -9
  18. package/dist/templates/examples/job-application/package.json +7 -7
  19. package/dist/templates/examples/job-application/src/view/education.ts +31 -32
  20. package/dist/templates/examples/job-application/src/view/field.ts +7 -8
  21. package/dist/templates/examples/job-application/src/view/workHistory.ts +40 -41
  22. package/dist/templates/examples/kanban/package.json +8 -8
  23. package/dist/templates/examples/managed-resource-layer/package.json +7 -7
  24. package/dist/templates/examples/managed-resource-layer/src/main.ts +10 -11
  25. package/dist/templates/examples/map/package.json +8 -8
  26. package/dist/templates/examples/map/src/main.ts +59 -63
  27. package/dist/templates/examples/map/src/vite-env.d.ts +1 -0
  28. package/dist/templates/examples/pixel-art/package.json +7 -7
  29. package/dist/templates/examples/pixel-art/src/scene.test.ts +3 -3
  30. package/dist/templates/examples/pixel-art/src/story.test.ts +3 -3
  31. package/dist/templates/examples/query-sync/package.json +7 -7
  32. package/dist/templates/examples/query-sync/src/main.ts +25 -37
  33. package/dist/templates/examples/route-transitions/package.json +7 -7
  34. package/dist/templates/examples/route-transitions/src/main.ts +24 -32
  35. package/dist/templates/examples/routing/package.json +7 -7
  36. package/dist/templates/examples/routing/src/main.ts +24 -30
  37. package/dist/templates/examples/routing/src/page/people.ts +80 -86
  38. package/dist/templates/examples/shopping-cart/package.json +7 -7
  39. package/dist/templates/examples/shopping-cart/src/main.ts +16 -22
  40. package/dist/templates/examples/slow-warnings/package.json +7 -7
  41. package/dist/templates/examples/snake/package.json +7 -7
  42. package/dist/templates/examples/ssg/package.json +6 -8
  43. package/dist/templates/examples/ssg/src/main.ts +65 -75
  44. package/dist/templates/examples/ssr/package.json +8 -9
  45. package/dist/templates/examples/state-machine/package.json +7 -7
  46. package/dist/templates/examples/state-machine/src/view.ts +50 -59
  47. package/dist/templates/examples/stopwatch/package.json +7 -7
  48. package/dist/templates/examples/todo/package.json +7 -7
  49. package/dist/templates/examples/todo/src/main.ts +29 -37
  50. package/dist/templates/examples/ui-showcase/package.json +7 -7
  51. package/dist/templates/examples/ui-showcase/src/main.ts +49 -42
  52. package/dist/templates/examples/ui-showcase/src/scene.test.ts +11 -0
  53. package/dist/templates/examples/ui-showcase/src/ui/init.ts +2 -0
  54. package/dist/templates/examples/ui-showcase/src/ui/message.ts +2 -0
  55. package/dist/templates/examples/ui-showcase/src/ui/model.ts +2 -0
  56. package/dist/templates/examples/ui-showcase/src/ui/update.ts +21 -0
  57. package/dist/templates/examples/ui-showcase/src/ui/view/hoverIntent.ts +89 -0
  58. package/dist/templates/examples/ui-showcase/src/ui/view/index.ts +1 -0
  59. package/dist/templates/examples/view-transitions/package.json +7 -7
  60. package/dist/templates/examples/view-transitions/src/main.ts +29 -40
  61. package/dist/templates/examples/weather/package.json +7 -7
  62. package/dist/templates/examples/web-components/package.json +7 -7
  63. package/dist/templates/examples/websocket-chat/package.json +7 -7
  64. package/dist/templates/examples/websocket-chat/src/main.ts +22 -32
  65. package/dist/templates/release.json +19 -19
  66. package/dist/templates/rendering/ssg/README.md +8 -7
  67. package/dist/templates/rendering/ssg/package.json +2 -2
  68. package/dist/templates/rendering/ssg/src/main.ts +61 -70
  69. package/dist/templates/rendering/ssg/tsconfig.json +1 -1
  70. package/dist/templates/rendering/ssg/vite.config.ts +22 -1
  71. package/dist/templates/rendering/ssr/README.md +10 -7
  72. package/dist/templates/rendering/ssr/package.json +2 -2
  73. package/dist/templates/rendering/ssr/vite.config.ts +22 -1
  74. package/package.json +5 -5
  75. package/dist/templates/rendering/ssg/scripts/build.mjs +0 -27
  76. package/dist/templates/rendering/ssg/scripts/prerender.ts +0 -120
  77. package/dist/templates/rendering/ssr/scripts/build.mjs +0 -23
@@ -74,7 +74,7 @@ Use `evo()` from `foldkit/struct` for immutable model updates. Never spread or `
74
74
 
75
75
  ### View
76
76
 
77
- Every view receives `h`, the typed Html builder, as its last parameter (`view: (model, h) => ...`; `Submodel.defineView` passes the child's own). Never construct a builder; reach for `h.div`, `h.OnClick`, etc. off the parameter, and give extracted view helpers an `h: HtmlBuilder<Message>` last parameter that callers thread through. Only where no builder is in scope, typically module scope, use `inertHtml` from `foldkit/html`, aliased `ih` so the two builders stay distinguishable. Use `h.empty` (not `null`) for conditional rendering, `M.value().pipe(M.tagsExhaustive({...}))` for discriminated unions, and `Array.match` for lists that may be empty.
77
+ Every view receives `h`, the typed Html builder, as its last parameter (`view: (model, h) => ...`; `Submodel.defineView` passes the child's own). Never construct a builder; reach for `h.div`, `h.OnClick`, etc. off the parameter, and give extracted view helpers an `h: HtmlBuilder<Message>` last parameter that callers thread through. Only where no builder is in scope, typically module scope, use `inertHtml` from `foldkit/html`, aliased `ih` so the two builders stay distinguishable. Use `h.empty` (not `null`) for conditional rendering, the union's own exhaustive `match` (`EditorMode.match(model.mode, {...})`) for discriminated unions, and `Array.match` for lists that may be empty.
78
78
 
79
79
  Keys are for mapped list items only: key each row by a stable Model identifier (`h.keyed('li')(item.id, [], [...])`), never by array position, and never derive a key from displayed data. Never key branches; the build gives each view function's output its own identity, so branch switches replace DOM automatically. When switching an inline same-tag ternary must reset DOM state, extract each arm into its own named view function.
80
80
 
@@ -17,13 +17,13 @@
17
17
  "devDependencies": {
18
18
  "@foldkit/devtools": "workspace:*",
19
19
  "@foldkit/vite-plugin": "workspace:*",
20
- "@tailwindcss/vite": "^4.3.1",
20
+ "@tailwindcss/vite": "^4.3.3",
21
21
  "@trivago/prettier-plugin-sort-imports": "^6.0.2",
22
- "happy-dom": "^20.10.4",
23
- "prettier": "^3.8.4",
24
- "tailwindcss": "^4.3.1",
25
- "typescript": "^6.0.3",
26
- "vite": "^8.0.16",
27
- "vitest": "^4.1.9"
22
+ "happy-dom": "^20.11.13",
23
+ "prettier": "^3.9.6",
24
+ "tailwindcss": "^4.3.3",
25
+ "typescript": "^7.0.2",
26
+ "vite": "^8.2.2",
27
+ "vitest": "^4.1.11"
28
28
  }
29
29
  }
@@ -18,13 +18,13 @@
18
18
  "devDependencies": {
19
19
  "@foldkit/devtools": "workspace:*",
20
20
  "@foldkit/vite-plugin": "workspace:*",
21
- "@tailwindcss/vite": "^4.3.1",
21
+ "@tailwindcss/vite": "^4.3.3",
22
22
  "@trivago/prettier-plugin-sort-imports": "^6.0.2",
23
- "happy-dom": "^20.10.4",
24
- "prettier": "^3.8.4",
25
- "tailwindcss": "^4.3.1",
26
- "typescript": "^6.0.3",
27
- "vite": "^8.0.16",
28
- "vitest": "^4.1.9"
23
+ "happy-dom": "^20.11.13",
24
+ "prettier": "^3.9.6",
25
+ "tailwindcss": "^4.3.3",
26
+ "typescript": "^7.0.2",
27
+ "vite": "^8.2.2",
28
+ "vitest": "^4.1.11"
29
29
  }
30
30
  }
@@ -3,13 +3,12 @@ import {
3
3
  Array,
4
4
  Duration,
5
5
  Effect,
6
- Match as M,
7
6
  Option,
8
7
  Schema as S,
9
8
  String,
10
9
  pipe,
11
10
  } from 'effect'
12
- import { Command, Submodel, type Update } from 'foldkit'
11
+ import { Command, FieldValidation, Submodel, type Update } from 'foldkit'
13
12
  import {
14
13
  Field,
15
14
  Invalid,
@@ -168,14 +167,12 @@ export const update = (model: Model, message: Message) =>
168
167
  // VIEW
169
168
 
170
169
  const fieldToBorderClass = (field: Field<string>) =>
171
- M.value(field).pipe(
172
- M.tagsExhaustive({
173
- NotValidated: () => 'border-gray-300',
174
- Validating: () => 'border-blue-300',
175
- Valid: () => 'border-green-500',
176
- Invalid: () => 'border-red-500',
177
- }),
178
- )
170
+ FieldValidation.match(field, {
171
+ onNotValidated: () => 'border-gray-300',
172
+ onValidating: () => 'border-blue-300',
173
+ onValid: () => 'border-green-500',
174
+ onInvalid: () => 'border-red-500',
175
+ })
179
176
 
180
177
  const fieldView = (
181
178
  id: string,
@@ -213,34 +210,30 @@ const fieldView = (
213
210
  ],
214
211
  [labelText],
215
212
  ),
216
- M.value(field).pipe(
217
- M.tagsExhaustive({
218
- NotValidated: () => h.empty,
219
- Validating: () =>
220
- h.span([h.Class('text-blue-600 text-sm')], ['...']),
221
- Valid: () =>
222
- h.span([h.Class('text-green-600 text-sm')], ['✓']),
223
- Invalid: () => h.empty,
224
- }),
225
- ),
213
+ FieldValidation.match(field, {
214
+ onNotValidated: () => h.empty,
215
+ onValidating: () =>
216
+ h.span([h.Class('text-blue-600 text-sm')], ['...']),
217
+ onValid: () =>
218
+ h.span([h.Class('text-green-600 text-sm')], ['✓']),
219
+ onInvalid: () => h.empty,
220
+ }),
226
221
  ],
227
222
  ),
228
223
  h.input([...attributes.input, h.Class(inputClass)]),
229
- M.value(field).pipe(
230
- M.tagsExhaustive({
231
- NotValidated: () => h.empty,
232
- Validating: () => h.empty,
233
- Valid: () => h.empty,
234
- Invalid: ({ errors }) =>
235
- h.div(
236
- [
237
- ...attributes.description,
238
- h.Class('text-red-600 text-sm mt-1'),
239
- ],
240
- [Array.headNonEmpty(errors)],
241
- ),
242
- }),
243
- ),
224
+ FieldValidation.match(field, {
225
+ onNotValidated: () => h.empty,
226
+ onValidating: () => h.empty,
227
+ onValid: () => h.empty,
228
+ onInvalid: ({ errors }) =>
229
+ h.div(
230
+ [
231
+ ...attributes.description,
232
+ h.Class('text-red-600 text-sm mt-1'),
233
+ ],
234
+ [Array.headNonEmpty(errors)],
235
+ ),
236
+ }),
244
237
  ],
245
238
  ),
246
239
  },
@@ -1,6 +1,6 @@
1
1
  import { Effect, Match as M, Option, Schema as S } from 'effect'
2
2
  import { Command, Update } from 'foldkit'
3
- import { load, pushUrl, replaceUrl } from 'foldkit/navigation'
3
+ import { UrlRequest, load, pushUrl, replaceUrl } from 'foldkit/navigation'
4
4
  import { evo } from 'foldkit/struct'
5
5
  import { toString as urlToString } from 'foldkit/url'
6
6
 
@@ -110,19 +110,16 @@ const foldLoggedIn = Update.foldChild({
110
110
  export const update = (model: Model, message: Message) =>
111
111
  Message.match<UpdateReturn>(message, {
112
112
  ClickedLink: ({ request }) =>
113
- M.value(request).pipe(
114
- withUpdateReturn,
115
- M.tagsExhaustive({
116
- Internal: ({ url }) => ({
117
- model,
118
- commands: [NavigateInternal({ url: urlToString(url) })],
119
- }),
120
- External: ({ href }) => ({
121
- model,
122
- commands: [LoadExternal({ href })],
123
- }),
113
+ UrlRequest.match<UpdateReturn>(request, {
114
+ Internal: ({ url }) => ({
115
+ model,
116
+ commands: [NavigateInternal({ url: urlToString(url) })],
124
117
  }),
125
- ),
118
+ External: ({ href }) => ({
119
+ model,
120
+ commands: [LoadExternal({ href })],
121
+ }),
122
+ }),
126
123
 
127
124
  ChangedUrl: ({ url }) => {
128
125
  const route = urlToAppRoute(url)
@@ -17,13 +17,13 @@
17
17
  "devDependencies": {
18
18
  "@foldkit/devtools": "workspace:*",
19
19
  "@foldkit/vite-plugin": "workspace:*",
20
- "@tailwindcss/vite": "^4.3.1",
20
+ "@tailwindcss/vite": "^4.3.3",
21
21
  "@trivago/prettier-plugin-sort-imports": "^6.0.2",
22
- "happy-dom": "^20.10.4",
23
- "prettier": "^3.8.4",
24
- "tailwindcss": "^4.3.1",
25
- "typescript": "^6.0.3",
26
- "vite": "^8.0.16",
27
- "vitest": "^4.1.9"
22
+ "happy-dom": "^20.11.13",
23
+ "prettier": "^3.9.6",
24
+ "tailwindcss": "^4.3.3",
25
+ "typescript": "^7.0.2",
26
+ "vite": "^8.2.2",
27
+ "vitest": "^4.1.11"
28
28
  }
29
29
  }
@@ -19,13 +19,13 @@
19
19
  "devDependencies": {
20
20
  "@foldkit/devtools": "workspace:*",
21
21
  "@foldkit/vite-plugin": "workspace:*",
22
- "@tailwindcss/vite": "^4.3.1",
22
+ "@tailwindcss/vite": "^4.3.3",
23
23
  "@trivago/prettier-plugin-sort-imports": "^6.0.2",
24
- "happy-dom": "^20.10.4",
25
- "prettier": "^3.8.4",
26
- "tailwindcss": "^4.3.1",
27
- "typescript": "^6.0.3",
28
- "vite": "^8.0.16",
29
- "vitest": "^4.1.9"
24
+ "happy-dom": "^20.11.13",
25
+ "prettier": "^3.9.6",
26
+ "tailwindcss": "^4.3.3",
27
+ "typescript": "^7.0.2",
28
+ "vite": "^8.2.2",
29
+ "vitest": "^4.1.11"
30
30
  }
31
31
  }
@@ -13,53 +13,51 @@ import { formatInteger } from './format'
13
13
 
14
14
  export const CHART_HOST_ID = 'charting-chart'
15
15
 
16
- export const MountChart = Mount.define(
17
- 'MountChart',
18
- { hostId: S.String },
19
- Message.SucceededMountChart,
20
- Message.FailedMountChart,
21
- )(
22
- ({ hostId }) =>
23
- element =>
24
- Effect.gen(function* () {
25
- if (!(element instanceof HTMLElement)) {
26
- return Message.FailedMountChart({
27
- reason: 'Chart host is not an HTMLElement.',
28
- })
29
- }
16
+ const mountChart = (element: Element, hostId: string) =>
17
+ Effect.gen(function* () {
18
+ if (!(element instanceof HTMLElement)) {
19
+ return Message.FailedMountChart({
20
+ reason: 'Chart host is not an HTMLElement.',
21
+ })
22
+ }
30
23
 
31
- return yield* Effect.acquireRelease(
32
- Effect.try({
33
- try: () => {
34
- const chart = echarts.init(element, undefined, {
35
- renderer: 'canvas',
36
- })
37
- const resizeObserver = new ResizeObserver(() => chart.resize())
38
- resizeObserver.observe(element)
39
- const onWindowResize = () => chart.resize()
40
- window.addEventListener('resize', onWindowResize)
41
- setChart(hostId, chart)
42
- return { resizeObserver, onWindowResize }
43
- },
44
- catch: error =>
45
- error instanceof Error
46
- ? error
47
- : new Error(`Failed to mount chart: ${error}`),
48
- }),
49
- ({ resizeObserver, onWindowResize }) =>
50
- Effect.sync(() => {
51
- resizeObserver.disconnect()
52
- window.removeEventListener('resize', onWindowResize)
53
- removeChart(hostId)
54
- }),
55
- ).pipe(
56
- Effect.map(() => Message.SucceededMountChart({ hostId })),
57
- Effect.catch(error =>
58
- Effect.succeed(Message.FailedMountChart({ reason: error.message })),
59
- ),
60
- )
24
+ return yield* Effect.acquireRelease(
25
+ Effect.try({
26
+ try: () => {
27
+ const chart = echarts.init(element, undefined, {
28
+ renderer: 'canvas',
29
+ })
30
+ const resizeObserver = new ResizeObserver(() => chart.resize())
31
+ resizeObserver.observe(element)
32
+ const onWindowResize = () => chart.resize()
33
+ window.addEventListener('resize', onWindowResize)
34
+ setChart(hostId, chart)
35
+ return { resizeObserver, onWindowResize }
36
+ },
37
+ catch: error =>
38
+ error instanceof Error
39
+ ? error
40
+ : new Error(`Failed to mount chart: ${error}`),
61
41
  }),
62
- )
42
+ ({ resizeObserver, onWindowResize }) =>
43
+ Effect.sync(() => {
44
+ resizeObserver.disconnect()
45
+ window.removeEventListener('resize', onWindowResize)
46
+ removeChart(hostId)
47
+ }),
48
+ ).pipe(
49
+ Effect.map(() => Message.SucceededMountChart({ hostId })),
50
+ Effect.catch(error =>
51
+ Effect.succeed(Message.FailedMountChart({ reason: error.message })),
52
+ ),
53
+ )
54
+ })
55
+
56
+ export const MountChart = Mount.define('MountChart', {
57
+ args: { hostId: S.String },
58
+ messages: [Message.SucceededMountChart, Message.FailedMountChart],
59
+ execute: ({ element, hostId }) => mountChart(element, hostId),
60
+ })
63
61
 
64
62
  export const chartPanelView = (
65
63
  model: Model,
@@ -17,13 +17,13 @@
17
17
  "devDependencies": {
18
18
  "@foldkit/devtools": "workspace:*",
19
19
  "@foldkit/vite-plugin": "workspace:*",
20
- "@tailwindcss/vite": "^4.3.1",
20
+ "@tailwindcss/vite": "^4.3.3",
21
21
  "@trivago/prettier-plugin-sort-imports": "^6.0.2",
22
- "happy-dom": "^20.10.4",
23
- "prettier": "^3.8.4",
24
- "tailwindcss": "^4.3.1",
25
- "typescript": "^6.0.3",
26
- "vite": "^8.0.16",
27
- "vitest": "^4.1.9"
22
+ "happy-dom": "^20.11.13",
23
+ "prettier": "^3.9.6",
24
+ "tailwindcss": "^4.3.3",
25
+ "typescript": "^7.0.2",
26
+ "vite": "^8.2.2",
27
+ "vitest": "^4.1.11"
28
28
  }
29
29
  }
@@ -17,13 +17,13 @@
17
17
  "devDependencies": {
18
18
  "@foldkit/devtools": "workspace:*",
19
19
  "@foldkit/vite-plugin": "workspace:*",
20
- "@tailwindcss/vite": "^4.3.1",
20
+ "@tailwindcss/vite": "^4.3.3",
21
21
  "@trivago/prettier-plugin-sort-imports": "^6.0.2",
22
- "happy-dom": "^20.10.4",
23
- "prettier": "^3.8.4",
24
- "tailwindcss": "^4.3.1",
25
- "typescript": "^6.0.3",
26
- "vite": "^8.0.16",
27
- "vitest": "^4.1.9"
22
+ "happy-dom": "^20.11.13",
23
+ "prettier": "^3.9.6",
24
+ "tailwindcss": "^4.3.3",
25
+ "typescript": "^7.0.2",
26
+ "vite": "^8.2.2",
27
+ "vitest": "^4.1.11"
28
28
  }
29
29
  }
@@ -17,13 +17,13 @@
17
17
  "devDependencies": {
18
18
  "@foldkit/devtools": "workspace:*",
19
19
  "@foldkit/vite-plugin": "workspace:*",
20
- "@tailwindcss/vite": "^4.3.1",
20
+ "@tailwindcss/vite": "^4.3.3",
21
21
  "@trivago/prettier-plugin-sort-imports": "^6.0.2",
22
- "happy-dom": "^20.10.4",
23
- "prettier": "^3.8.4",
24
- "tailwindcss": "^4.3.1",
25
- "typescript": "^6.0.3",
26
- "vite": "^8.0.16",
27
- "vitest": "^4.1.9"
22
+ "happy-dom": "^20.11.13",
23
+ "prettier": "^3.9.6",
24
+ "tailwindcss": "^4.3.3",
25
+ "typescript": "^7.0.2",
26
+ "vite": "^8.2.2",
27
+ "vitest": "^4.1.11"
28
28
  }
29
29
  }
@@ -17,13 +17,13 @@
17
17
  "devDependencies": {
18
18
  "@foldkit/devtools": "workspace:*",
19
19
  "@foldkit/vite-plugin": "workspace:*",
20
- "@tailwindcss/vite": "^4.3.1",
20
+ "@tailwindcss/vite": "^4.3.3",
21
21
  "@trivago/prettier-plugin-sort-imports": "^6.0.2",
22
- "happy-dom": "^20.10.4",
23
- "prettier": "^3.8.4",
24
- "tailwindcss": "^4.3.1",
25
- "typescript": "^6.0.3",
26
- "vite": "^8.0.16",
27
- "vitest": "^4.1.9"
22
+ "happy-dom": "^20.11.13",
23
+ "prettier": "^3.9.6",
24
+ "tailwindcss": "^4.3.3",
25
+ "typescript": "^7.0.2",
26
+ "vite": "^8.2.2",
27
+ "vitest": "^4.1.11"
28
28
  }
29
29
  }
@@ -18,13 +18,13 @@
18
18
  "devDependencies": {
19
19
  "@foldkit/devtools": "workspace:*",
20
20
  "@foldkit/vite-plugin": "workspace:*",
21
- "@tailwindcss/vite": "^4.3.1",
21
+ "@tailwindcss/vite": "^4.3.3",
22
22
  "@trivago/prettier-plugin-sort-imports": "^6.0.2",
23
- "happy-dom": "^20.10.4",
24
- "prettier": "^3.8.4",
25
- "tailwindcss": "^4.3.1",
26
- "typescript": "^6.0.3",
27
- "vite": "^8.0.16",
28
- "vitest": "^4.1.9"
23
+ "happy-dom": "^20.11.13",
24
+ "prettier": "^3.9.6",
25
+ "tailwindcss": "^4.3.3",
26
+ "typescript": "^7.0.2",
27
+ "vite": "^8.2.2",
28
+ "vitest": "^4.1.11"
29
29
  }
30
30
  }
@@ -1,13 +1,6 @@
1
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, type Update } from 'foldkit'
2
+ import { Array, Duration, Effect, Random, Schema as S } from 'effect'
3
+ import { Command, FieldValidation, Runtime, type Update } from 'foldkit'
11
4
  import {
12
5
  Field,
13
6
  Invalid,
@@ -240,14 +233,12 @@ const LABEL_CLASS = 'text-sm font-medium text-gray-700'
240
233
  const DESCRIPTION_CLASS = 'text-sm mt-1'
241
234
 
242
235
  const borderClass = (field: Field<string>): string =>
243
- M.value(field).pipe(
244
- M.tagsExhaustive({
245
- NotValidated: () => 'border-gray-300',
246
- Validating: () => 'border-blue-300',
247
- Valid: () => 'border-green-500',
248
- Invalid: () => 'border-red-500',
249
- }),
250
- )
236
+ FieldValidation.match(field, {
237
+ onNotValidated: () => 'border-gray-300',
238
+ onValidating: () => 'border-blue-300',
239
+ onValid: () => 'border-green-500',
240
+ onInvalid: () => 'border-red-500',
241
+ })
251
242
 
252
243
  const inputClassName = (field: Field<string>): string =>
253
244
  clsx(
@@ -256,43 +247,39 @@ const inputClassName = (field: Field<string>): string =>
256
247
  )
257
248
 
258
249
  const statusIndicator = (field: Field<string>, h: HtmlBuilder<Message>): Html =>
259
- M.value(field).pipe(
260
- M.tagsExhaustive({
261
- NotValidated: () => h.empty,
262
- Validating: () =>
263
- h.span([h.Class('text-blue-600 text-sm animate-spin')], ['◐']),
264
- Valid: () => h.span([h.Class('text-green-600 text-sm')], ['✓']),
265
- Invalid: () => h.empty,
266
- }),
267
- )
250
+ FieldValidation.match(field, {
251
+ onNotValidated: () => h.empty,
252
+ onValidating: () =>
253
+ h.span([h.Class('text-blue-600 text-sm animate-spin')], ['◐']),
254
+ onValid: () => h.span([h.Class('text-green-600 text-sm')], ['✓']),
255
+ onInvalid: () => h.empty,
256
+ })
268
257
 
269
258
  const descriptionView = (
270
259
  field: Field<string>,
271
260
  descriptionAttributes: ReadonlyArray<Attribute<Message>>,
272
261
  h: HtmlBuilder<Message>,
273
262
  ): Html =>
274
- M.value(field).pipe(
275
- M.tagsExhaustive({
276
- NotValidated: () => h.empty,
277
- Validating: () =>
278
- h.span(
279
- [
280
- ...descriptionAttributes,
281
- h.Class(clsx(DESCRIPTION_CLASS, 'text-blue-600')),
282
- ],
283
- ['Checking...'],
284
- ),
285
- Valid: () => h.empty,
286
- Invalid: ({ errors }) =>
287
- h.span(
288
- [
289
- ...descriptionAttributes,
290
- h.Class(clsx(DESCRIPTION_CLASS, 'text-red-600')),
291
- ],
292
- [Array.headNonEmpty(errors)],
293
- ),
294
- }),
295
- )
263
+ FieldValidation.match(field, {
264
+ onNotValidated: () => h.empty,
265
+ onValidating: () =>
266
+ h.span(
267
+ [
268
+ ...descriptionAttributes,
269
+ h.Class(clsx(DESCRIPTION_CLASS, 'text-blue-600')),
270
+ ],
271
+ ['Checking...'],
272
+ ),
273
+ onValid: () => h.empty,
274
+ onInvalid: ({ errors }) =>
275
+ h.span(
276
+ [
277
+ ...descriptionAttributes,
278
+ h.Class(clsx(DESCRIPTION_CLASS, 'text-red-600')),
279
+ ],
280
+ [Array.headNonEmpty(errors)],
281
+ ),
282
+ })
296
283
 
297
284
  const inputFieldView = (
298
285
  id: string,
@@ -439,32 +426,30 @@ export const view = (model: Model, h: HtmlBuilder<Message>): Document => {
439
426
  ],
440
427
  ),
441
428
 
442
- M.value(model.submission).pipe(
443
- M.tagsExhaustive({
444
- NotSubmitted: () => h.empty,
445
- Submitting: () => h.empty,
446
- SubmitSuccess: ({ confirmationText }) =>
447
- h.div(
448
- [
449
- h.Role('status'),
450
- h.Class(
451
- 'mt-4 p-3 bg-green-100 border border-green-400 text-green-700 rounded-lg',
452
- ),
453
- ],
454
- [confirmationText],
455
- ),
456
- SubmitError: ({ error }) =>
457
- h.div(
458
- [
459
- h.Role('alert'),
460
- h.Class(
461
- 'mt-4 p-3 bg-red-100 border border-red-400 text-red-700 rounded-lg',
462
- ),
463
- ],
464
- [error],
465
- ),
466
- }),
467
- ),
429
+ Submission.match(model.submission, {
430
+ NotSubmitted: () => h.empty,
431
+ Submitting: () => h.empty,
432
+ SubmitSuccess: ({ confirmationText }) =>
433
+ h.div(
434
+ [
435
+ h.Role('status'),
436
+ h.Class(
437
+ 'mt-4 p-3 bg-green-100 border border-green-400 text-green-700 rounded-lg',
438
+ ),
439
+ ],
440
+ [confirmationText],
441
+ ),
442
+ SubmitError: ({ error }) =>
443
+ h.div(
444
+ [
445
+ h.Role('alert'),
446
+ h.Class(
447
+ 'mt-4 p-3 bg-red-100 border border-red-400 text-red-700 rounded-lg',
448
+ ),
449
+ ],
450
+ [error],
451
+ ),
452
+ }),
468
453
  ],
469
454
  ),
470
455
  ],
@@ -17,13 +17,13 @@
17
17
  "devDependencies": {
18
18
  "@foldkit/devtools": "workspace:*",
19
19
  "@foldkit/vite-plugin": "workspace:*",
20
- "@tailwindcss/vite": "^4.3.1",
20
+ "@tailwindcss/vite": "^4.3.3",
21
21
  "@trivago/prettier-plugin-sort-imports": "^6.0.2",
22
- "happy-dom": "^20.10.4",
23
- "prettier": "^3.8.4",
24
- "tailwindcss": "^4.3.1",
25
- "typescript": "^6.0.3",
26
- "vite": "^8.0.16",
27
- "vitest": "^4.1.9"
22
+ "happy-dom": "^20.11.13",
23
+ "prettier": "^3.9.6",
24
+ "tailwindcss": "^4.3.3",
25
+ "typescript": "^7.0.2",
26
+ "vite": "^8.2.2",
27
+ "vitest": "^4.1.11"
28
28
  }
29
29
  }
@@ -17,13 +17,13 @@
17
17
  "devDependencies": {
18
18
  "@foldkit/devtools": "workspace:*",
19
19
  "@foldkit/vite-plugin": "workspace:*",
20
- "@tailwindcss/vite": "^4.3.1",
20
+ "@tailwindcss/vite": "^4.3.3",
21
21
  "@trivago/prettier-plugin-sort-imports": "^6.0.2",
22
- "happy-dom": "^20.10.4",
23
- "prettier": "^3.8.4",
24
- "tailwindcss": "^4.3.1",
25
- "typescript": "^6.0.3",
26
- "vite": "^8.0.16",
27
- "vitest": "^4.1.9"
22
+ "happy-dom": "^20.11.13",
23
+ "prettier": "^3.9.6",
24
+ "tailwindcss": "^4.3.3",
25
+ "typescript": "^7.0.2",
26
+ "vite": "^8.2.2",
27
+ "vitest": "^4.1.11"
28
28
  }
29
29
  }