create-foldkit-app 0.35.1 → 0.35.2
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/templates/base/FOLDKIT.md +2 -2
- package/dist/templates/examples/api-cache/package.json +2 -2
- package/dist/templates/examples/api-cache/src/main.fixture.ts +4 -4
- package/dist/templates/examples/api-cache/src/main.ts +12 -12
- package/dist/templates/examples/api-cache/src/story.test.ts +6 -6
- package/dist/templates/examples/auth/package.json +2 -2
- package/dist/templates/examples/auth/src/page/loggedOut/page/login.scene.test.ts +2 -2
- package/dist/templates/examples/auth/src/page/loggedOut/page/login.story.test.ts +2 -2
- package/dist/templates/examples/auth/src/page/loggedOut/page/login.ts +5 -5
- package/dist/templates/examples/auth/src/page/loggedOut/update.ts +2 -2
- package/dist/templates/examples/auth/src/scene.test.ts +2 -2
- package/dist/templates/examples/auth/src/update.ts +3 -3
- package/dist/templates/examples/canvas-art/package.json +2 -2
- package/dist/templates/examples/canvas-art/src/main.ts +6 -6
- package/dist/templates/examples/canvas-art/src/scene.test.ts +3 -3
- package/dist/templates/examples/canvas-art/src/story.test.ts +3 -3
- package/dist/templates/examples/charting/package.json +2 -2
- package/dist/templates/examples/charting/src/main.fixture.ts +2 -2
- package/dist/templates/examples/charting/src/scene.test.ts +3 -3
- package/dist/templates/examples/charting/src/story.test.ts +2 -2
- package/dist/templates/examples/charting/src/update.ts +18 -16
- package/dist/templates/examples/counter/package.json +2 -2
- package/dist/templates/examples/counter/src/main.ts +4 -4
- package/dist/templates/examples/counters/package.json +2 -2
- package/dist/templates/examples/counters/src/counter.ts +3 -3
- package/dist/templates/examples/counters/src/main.ts +7 -5
- package/dist/templates/examples/crash-view/package.json +2 -2
- package/dist/templates/examples/embedding/package.json +2 -2
- package/dist/templates/examples/embedding/src/main.ts +5 -3
- package/dist/templates/examples/embedding/src/scene.test.ts +2 -2
- package/dist/templates/examples/embedding/src/story.test.ts +2 -2
- package/dist/templates/examples/form/package.json +2 -2
- package/dist/templates/examples/form/src/main.ts +9 -9
- package/dist/templates/examples/form/src/scene.test.ts +5 -5
- package/dist/templates/examples/form/src/story.test.ts +4 -4
- package/dist/templates/examples/generative-art/package.json +2 -2
- package/dist/templates/examples/generative-art/src/scene.test.ts +2 -2
- package/dist/templates/examples/generative-art/src/story.test.ts +3 -3
- package/dist/templates/examples/generative-art/src/update.ts +11 -11
- package/dist/templates/examples/interrupting-commands/package.json +2 -2
- package/dist/templates/examples/interrupting-commands/src/main.ts +8 -6
- package/dist/templates/examples/job-application/package.json +2 -2
- package/dist/templates/examples/job-application/src/main.fixture.ts +9 -9
- package/dist/templates/examples/job-application/src/scene.test.ts +13 -13
- package/dist/templates/examples/job-application/src/step/attachments/attachments.ts +7 -7
- package/dist/templates/examples/job-application/src/step/coverLetter/coverLetter.ts +2 -2
- package/dist/templates/examples/job-application/src/step/education/education.ts +6 -6
- package/dist/templates/examples/job-application/src/step/education/entry/entry.ts +14 -8
- package/dist/templates/examples/job-application/src/step/personalInfo/personalInfo.ts +20 -15
- package/dist/templates/examples/job-application/src/step/personalInfo/story.test.ts +2 -2
- package/dist/templates/examples/job-application/src/step/skills/entry/entry.ts +7 -5
- package/dist/templates/examples/job-application/src/step/skills/skills.ts +6 -6
- package/dist/templates/examples/job-application/src/step/workHistory/entry/entry.ts +13 -12
- package/dist/templates/examples/job-application/src/step/workHistory/workHistory.ts +6 -6
- package/dist/templates/examples/job-application/src/story.test.ts +10 -10
- package/dist/templates/examples/job-application/src/update.ts +25 -18
- package/dist/templates/examples/kanban/package.json +2 -2
- package/dist/templates/examples/kanban/src/domain/column.ts +9 -6
- package/dist/templates/examples/kanban/src/update.ts +8 -8
- package/dist/templates/examples/managed-resource-layer/package.json +2 -2
- package/dist/templates/examples/managed-resource-layer/src/main.ts +11 -7
- package/dist/templates/examples/managed-resource-layer/src/story.test.ts +3 -3
- package/dist/templates/examples/map/package.json +2 -2
- package/dist/templates/examples/map/src/main.fixture.ts +2 -2
- package/dist/templates/examples/map/src/main.ts +11 -11
- package/dist/templates/examples/map/src/scene.test.ts +4 -4
- package/dist/templates/examples/map/src/story.test.ts +4 -4
- package/dist/templates/examples/pixel-art/package.json +2 -2
- package/dist/templates/examples/pixel-art/src/comparison.bench.test.ts +2 -2
- package/dist/templates/examples/pixel-art/src/main.bench.ts +7 -3
- package/dist/templates/examples/pixel-art/src/scene.test.ts +5 -5
- package/dist/templates/examples/pixel-art/src/story.test.ts +4 -4
- package/dist/templates/examples/pixel-art/src/subscription.ts +2 -2
- package/dist/templates/examples/pixel-art/src/update.ts +49 -33
- package/dist/templates/examples/query-sync/package.json +2 -2
- package/dist/templates/examples/query-sync/src/main.ts +4 -4
- package/dist/templates/examples/query-sync/src/scene.test.ts +4 -4
- package/dist/templates/examples/query-sync/src/story.test.ts +2 -2
- package/dist/templates/examples/route-transitions/package.json +2 -2
- package/dist/templates/examples/route-transitions/src/main.ts +10 -10
- package/dist/templates/examples/route-transitions/src/story.test.ts +10 -6
- package/dist/templates/examples/routing/package.json +2 -2
- package/dist/templates/examples/routing/src/main.ts +13 -17
- package/dist/templates/examples/routing/src/page/people.ts +4 -4
- package/dist/templates/examples/shopping-cart/package.json +2 -2
- package/dist/templates/examples/shopping-cart/src/domain/cart.ts +4 -4
- package/dist/templates/examples/shopping-cart/src/main.ts +12 -12
- package/dist/templates/examples/shopping-cart/src/page/products.ts +2 -2
- package/dist/templates/examples/shopping-cart/src/scene.test.ts +10 -8
- package/dist/templates/examples/shopping-cart/src/story.test.ts +7 -7
- package/dist/templates/examples/slow-warnings/package.json +2 -2
- package/dist/templates/examples/slow-warnings/src/handleSlow.test.ts +2 -2
- package/dist/templates/examples/slow-warnings/src/main.ts +8 -8
- package/dist/templates/examples/slow-warnings/src/scene.test.ts +2 -2
- package/dist/templates/examples/slow-warnings/src/story.test.ts +2 -2
- package/dist/templates/examples/snake/package.json +2 -2
- package/dist/templates/examples/snake/src/main.ts +10 -10
- package/dist/templates/examples/snake/src/scene.test.ts +10 -5
- package/dist/templates/examples/snake/src/story.test.ts +6 -6
- package/dist/templates/examples/ssg/package.json +2 -2
- package/dist/templates/examples/ssg/src/main.ts +3 -3
- package/dist/templates/examples/ssr/package.json +4 -4
- package/dist/templates/examples/ssr/src/main.ts +3 -3
- package/dist/templates/examples/state-machine/package.json +2 -2
- package/dist/templates/examples/state-machine/src/main.ts +14 -10
- package/dist/templates/examples/stopwatch/package.json +2 -2
- package/dist/templates/examples/stopwatch/src/main.ts +5 -5
- package/dist/templates/examples/stopwatch/src/story.test.ts +2 -2
- package/dist/templates/examples/todo/package.json +2 -2
- package/dist/templates/examples/todo/src/main.ts +17 -17
- package/dist/templates/examples/todo/src/scene.test.ts +4 -4
- package/dist/templates/examples/todo/src/story.test.ts +22 -16
- package/dist/templates/examples/ui-showcase/package.json +2 -2
- package/dist/templates/examples/ui-showcase/src/main.ts +8 -5
- package/dist/templates/examples/ui-showcase/src/story.test.ts +3 -3
- package/dist/templates/examples/ui-showcase/src/ui/init.ts +4 -1
- package/dist/templates/examples/ui-showcase/src/ui/subscriptions.ts +10 -0
- package/dist/templates/examples/ui-showcase/src/ui/update.ts +119 -91
- package/dist/templates/examples/ui-showcase/src/ui/view/toast.ts +20 -3
- package/dist/templates/examples/view-transitions/package.json +2 -2
- package/dist/templates/examples/view-transitions/src/main.ts +3 -3
- package/dist/templates/examples/weather/package.json +2 -2
- package/dist/templates/examples/weather/src/main.ts +5 -5
- package/dist/templates/examples/web-components/package.json +2 -2
- package/dist/templates/examples/web-components/src/main.ts +4 -4
- package/dist/templates/examples/websocket-chat/package.json +2 -2
- package/dist/templates/examples/websocket-chat/src/main.ts +8 -8
- package/dist/templates/examples/websocket-chat/src/scene.test.ts +18 -6
- package/dist/templates/examples/websocket-chat/src/story.test.ts +15 -9
- package/dist/templates/release.json +13 -13
- package/dist/templates/rendering/ssg/src/main.ts +3 -3
- package/dist/templates/rendering/ssr/scripts/serve.ts +2 -2
- package/dist/templates/rendering/ssr/src/main.ts +3 -3
- package/package.json +5 -5
|
@@ -14,7 +14,7 @@ import { Command, Runtime, type Update } from 'foldkit'
|
|
|
14
14
|
import { Document, Html, HtmlBuilder } from 'foldkit/html'
|
|
15
15
|
import { defineMessageUnion } from 'foldkit/message'
|
|
16
16
|
import { defineTaggedUnion } from 'foldkit/schema'
|
|
17
|
-
import {
|
|
17
|
+
import { modifyFields } from 'foldkit/struct'
|
|
18
18
|
|
|
19
19
|
import { BrowserKeyValueStore } from '@effect/platform-browser'
|
|
20
20
|
import { Button, Checkbox, Input } from '@foldkit/ui'
|
|
@@ -104,13 +104,13 @@ type UpdateReturn = Update.Return<Model, Message>
|
|
|
104
104
|
export const update = (model: Model, message: Message) =>
|
|
105
105
|
Message.match<UpdateReturn>(message, {
|
|
106
106
|
UpdatedNewTodo: ({ text }) => ({
|
|
107
|
-
model:
|
|
107
|
+
model: modifyFields(model, {
|
|
108
108
|
newTodoText: () => text,
|
|
109
109
|
}),
|
|
110
110
|
}),
|
|
111
111
|
|
|
112
112
|
UpdatedEditingTodo: ({ text }) => ({
|
|
113
|
-
model:
|
|
113
|
+
model: modifyFields(model, {
|
|
114
114
|
editing: () =>
|
|
115
115
|
EditingState.match(model.editing, {
|
|
116
116
|
NotEditing: () => model.editing,
|
|
@@ -141,7 +141,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
141
141
|
const updatedTodos = [...model.todos, newTodo]
|
|
142
142
|
|
|
143
143
|
return {
|
|
144
|
-
model:
|
|
144
|
+
model: modifyFields(model, {
|
|
145
145
|
todos: () => updatedTodos,
|
|
146
146
|
newTodoText: () => '',
|
|
147
147
|
}),
|
|
@@ -153,7 +153,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
153
153
|
const updatedTodos = Array.filter(model.todos, todo => todo.id !== id)
|
|
154
154
|
|
|
155
155
|
return {
|
|
156
|
-
model:
|
|
156
|
+
model: modifyFields(model, {
|
|
157
157
|
todos: () => updatedTodos,
|
|
158
158
|
}),
|
|
159
159
|
commands: [SaveTodos({ todos: updatedTodos })],
|
|
@@ -163,12 +163,12 @@ export const update = (model: Model, message: Message) =>
|
|
|
163
163
|
ToggledTodo: ({ id }) => {
|
|
164
164
|
const updatedTodos = Array.map(model.todos, todo =>
|
|
165
165
|
todo.id === id
|
|
166
|
-
?
|
|
166
|
+
? modifyFields(todo, { completed: completed => !completed })
|
|
167
167
|
: todo,
|
|
168
168
|
)
|
|
169
169
|
|
|
170
170
|
return {
|
|
171
|
-
model:
|
|
171
|
+
model: modifyFields(model, {
|
|
172
172
|
todos: () => updatedTodos,
|
|
173
173
|
}),
|
|
174
174
|
commands: [SaveTodos({ todos: updatedTodos })],
|
|
@@ -178,7 +178,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
178
178
|
StartedEditing: ({ id }) => {
|
|
179
179
|
const maybeTodo = Array.findFirst(model.todos, todo => todo.id === id)
|
|
180
180
|
return {
|
|
181
|
-
model:
|
|
181
|
+
model: modifyFields(model, {
|
|
182
182
|
editing: () =>
|
|
183
183
|
EditingState.Editing({
|
|
184
184
|
id,
|
|
@@ -198,7 +198,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
198
198
|
Editing: ({ id, text }) => {
|
|
199
199
|
if (String.isEmpty(String.trim(text))) {
|
|
200
200
|
return {
|
|
201
|
-
model:
|
|
201
|
+
model: modifyFields(model, {
|
|
202
202
|
editing: () => EditingState.NotEditing(),
|
|
203
203
|
}),
|
|
204
204
|
}
|
|
@@ -206,12 +206,12 @@ export const update = (model: Model, message: Message) =>
|
|
|
206
206
|
|
|
207
207
|
const updatedTodos = Array.map(model.todos, todo =>
|
|
208
208
|
todo.id === id
|
|
209
|
-
?
|
|
209
|
+
? modifyFields(todo, { text: () => String.trim(text) })
|
|
210
210
|
: todo,
|
|
211
211
|
)
|
|
212
212
|
|
|
213
213
|
return {
|
|
214
|
-
model:
|
|
214
|
+
model: modifyFields(model, {
|
|
215
215
|
todos: () => updatedTodos,
|
|
216
216
|
editing: () => EditingState.NotEditing(),
|
|
217
217
|
}),
|
|
@@ -221,7 +221,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
221
221
|
}),
|
|
222
222
|
|
|
223
223
|
CancelledEdit: () => ({
|
|
224
|
-
model:
|
|
224
|
+
model: modifyFields(model, {
|
|
225
225
|
editing: () => EditingState.NotEditing(),
|
|
226
226
|
}),
|
|
227
227
|
}),
|
|
@@ -229,13 +229,13 @@ export const update = (model: Model, message: Message) =>
|
|
|
229
229
|
ToggledAll: () => {
|
|
230
230
|
const allCompleted = Array.every(model.todos, todo => todo.completed)
|
|
231
231
|
const updatedTodos = Array.map(model.todos, todo =>
|
|
232
|
-
|
|
232
|
+
modifyFields(todo, {
|
|
233
233
|
completed: () => !allCompleted,
|
|
234
234
|
}),
|
|
235
235
|
)
|
|
236
236
|
|
|
237
237
|
return {
|
|
238
|
-
model:
|
|
238
|
+
model: modifyFields(model, {
|
|
239
239
|
todos: () => updatedTodos,
|
|
240
240
|
}),
|
|
241
241
|
commands: [SaveTodos({ todos: updatedTodos })],
|
|
@@ -246,7 +246,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
246
246
|
const updatedTodos = Array.filter(model.todos, todo => !todo.completed)
|
|
247
247
|
|
|
248
248
|
return {
|
|
249
|
-
model:
|
|
249
|
+
model: modifyFields(model, {
|
|
250
250
|
todos: () => updatedTodos,
|
|
251
251
|
}),
|
|
252
252
|
commands: [SaveTodos({ todos: updatedTodos })],
|
|
@@ -254,13 +254,13 @@ export const update = (model: Model, message: Message) =>
|
|
|
254
254
|
},
|
|
255
255
|
|
|
256
256
|
SelectedFilter: ({ filter }) => ({
|
|
257
|
-
model:
|
|
257
|
+
model: modifyFields(model, {
|
|
258
258
|
filter: () => filter,
|
|
259
259
|
}),
|
|
260
260
|
}),
|
|
261
261
|
|
|
262
262
|
SucceededSaveTodos: ({ todos }) => ({
|
|
263
|
-
model:
|
|
263
|
+
model: modifyFields(model, {
|
|
264
264
|
todos: () => todos,
|
|
265
265
|
}),
|
|
266
266
|
}),
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
text,
|
|
11
11
|
type,
|
|
12
12
|
} from 'foldkit/scene'
|
|
13
|
-
import {
|
|
13
|
+
import { modifyFields } from 'foldkit/struct'
|
|
14
14
|
import { describe, test } from 'vitest'
|
|
15
15
|
|
|
16
16
|
import {
|
|
@@ -30,7 +30,7 @@ const emptyModel: Model = {
|
|
|
30
30
|
editing: EditingState.NotEditing(),
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
const modelWithTodos: Model =
|
|
33
|
+
const modelWithTodos: Model = modifyFields(emptyModel, {
|
|
34
34
|
todos: () => [
|
|
35
35
|
{ id: 'abc', text: 'Buy milk', completed: false, createdAt: 1000 },
|
|
36
36
|
{ id: 'def', text: 'Walk the dog', completed: false, createdAt: 2000 },
|
|
@@ -93,7 +93,7 @@ describe('view', () => {
|
|
|
93
93
|
|
|
94
94
|
test('toggle a todo by clicking its checkbox', () => {
|
|
95
95
|
const toggledTodos = modelWithTodos.todos.map(todo =>
|
|
96
|
-
todo.id === 'abc' ?
|
|
96
|
+
todo.id === 'abc' ? modifyFields(todo, { completed: () => true }) : todo,
|
|
97
97
|
)
|
|
98
98
|
|
|
99
99
|
scene(
|
|
@@ -147,7 +147,7 @@ describe('view', () => {
|
|
|
147
147
|
|
|
148
148
|
test('mark all complete toggles all todos', () => {
|
|
149
149
|
const allCompletedTodos = modelWithTodos.todos.map(todo =>
|
|
150
|
-
|
|
150
|
+
modifyFields(todo, { completed: () => true }),
|
|
151
151
|
)
|
|
152
152
|
|
|
153
153
|
scene(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Array, Option } from 'effect'
|
|
2
2
|
import { Command, given, message, model, story } from 'foldkit/story'
|
|
3
|
-
import {
|
|
3
|
+
import { modifyFields } from 'foldkit/struct'
|
|
4
4
|
import { describe, expect, test } from 'vitest'
|
|
5
5
|
|
|
6
6
|
import {
|
|
@@ -40,7 +40,7 @@ const doneTask = {
|
|
|
40
40
|
createdAt: 3000,
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
const modelWithTodos: Model =
|
|
43
|
+
const modelWithTodos: Model = modifyFields(emptyModel, {
|
|
44
44
|
todos: () => [buyMilk, walkDog, doneTask],
|
|
45
45
|
})
|
|
46
46
|
|
|
@@ -49,7 +49,7 @@ describe('update', () => {
|
|
|
49
49
|
test('AddedTodo with text produces a GenerateTodo Command', () => {
|
|
50
50
|
story(
|
|
51
51
|
update,
|
|
52
|
-
given(
|
|
52
|
+
given(modifyFields(emptyModel, { newTodoText: () => 'Buy milk' })),
|
|
53
53
|
message(Message.AddedTodo()),
|
|
54
54
|
Command.expectHas(GenerateTodo),
|
|
55
55
|
Command.resolve(
|
|
@@ -85,7 +85,7 @@ describe('update', () => {
|
|
|
85
85
|
test('AddedTodo with empty text is ignored', () => {
|
|
86
86
|
story(
|
|
87
87
|
update,
|
|
88
|
-
given(
|
|
88
|
+
given(modifyFields(emptyModel, { newTodoText: () => '' })),
|
|
89
89
|
message(Message.AddedTodo()),
|
|
90
90
|
Command.expectNone(),
|
|
91
91
|
)
|
|
@@ -94,7 +94,7 @@ describe('update', () => {
|
|
|
94
94
|
test('AddedTodo with whitespace-only text is ignored', () => {
|
|
95
95
|
story(
|
|
96
96
|
update,
|
|
97
|
-
given(
|
|
97
|
+
given(modifyFields(emptyModel, { newTodoText: () => ' ' })),
|
|
98
98
|
message(Message.AddedTodo()),
|
|
99
99
|
Command.expectNone(),
|
|
100
100
|
)
|
|
@@ -115,7 +115,9 @@ describe('update', () => {
|
|
|
115
115
|
describe('toggle and delete', () => {
|
|
116
116
|
test('ToggledTodo flips the completed state', () => {
|
|
117
117
|
const toggledTodos = modelWithTodos.todos.map(todo =>
|
|
118
|
-
todo.id === 'abc'
|
|
118
|
+
todo.id === 'abc'
|
|
119
|
+
? modifyFields(todo, { completed: () => true })
|
|
120
|
+
: todo,
|
|
119
121
|
)
|
|
120
122
|
|
|
121
123
|
story(
|
|
@@ -137,7 +139,9 @@ describe('update', () => {
|
|
|
137
139
|
|
|
138
140
|
test('ToggledTodo on completed todo marks it active', () => {
|
|
139
141
|
const toggledTodos = modelWithTodos.todos.map(todo =>
|
|
140
|
-
todo.id === 'ghi'
|
|
142
|
+
todo.id === 'ghi'
|
|
143
|
+
? modifyFields(todo, { completed: () => false })
|
|
144
|
+
: todo,
|
|
141
145
|
)
|
|
142
146
|
|
|
143
147
|
story(
|
|
@@ -195,7 +199,7 @@ describe('update', () => {
|
|
|
195
199
|
})
|
|
196
200
|
|
|
197
201
|
test('UpdatedEditingTodo updates the editing text', () => {
|
|
198
|
-
const editingModel: Model =
|
|
202
|
+
const editingModel: Model = modifyFields(modelWithTodos, {
|
|
199
203
|
editing: () => EditingState.Editing({ id: 'abc', text: 'Buy milk' }),
|
|
200
204
|
})
|
|
201
205
|
|
|
@@ -212,13 +216,15 @@ describe('update', () => {
|
|
|
212
216
|
})
|
|
213
217
|
|
|
214
218
|
test('SavedEdit updates the todo text and exits editing', () => {
|
|
215
|
-
const editingModel: Model =
|
|
219
|
+
const editingModel: Model = modifyFields(modelWithTodos, {
|
|
216
220
|
editing: () =>
|
|
217
221
|
EditingState.Editing({ id: 'abc', text: 'Buy oat milk' }),
|
|
218
222
|
})
|
|
219
223
|
|
|
220
224
|
const editedTodos = modelWithTodos.todos.map(todo =>
|
|
221
|
-
todo.id === 'abc'
|
|
225
|
+
todo.id === 'abc'
|
|
226
|
+
? modifyFields(todo, { text: () => 'Buy oat milk' })
|
|
227
|
+
: todo,
|
|
222
228
|
)
|
|
223
229
|
|
|
224
230
|
story(
|
|
@@ -240,7 +246,7 @@ describe('update', () => {
|
|
|
240
246
|
})
|
|
241
247
|
|
|
242
248
|
test('SavedEdit with empty text exits editing without saving', () => {
|
|
243
|
-
const editingModel: Model =
|
|
249
|
+
const editingModel: Model = modifyFields(modelWithTodos, {
|
|
244
250
|
editing: () => EditingState.Editing({ id: 'abc', text: ' ' }),
|
|
245
251
|
})
|
|
246
252
|
|
|
@@ -260,7 +266,7 @@ describe('update', () => {
|
|
|
260
266
|
})
|
|
261
267
|
|
|
262
268
|
test('CancelledEdit exits editing without changes', () => {
|
|
263
|
-
const editingModel: Model =
|
|
269
|
+
const editingModel: Model = modifyFields(modelWithTodos, {
|
|
264
270
|
editing: () =>
|
|
265
271
|
EditingState.Editing({ id: 'abc', text: 'Changed text' }),
|
|
266
272
|
})
|
|
@@ -283,7 +289,7 @@ describe('update', () => {
|
|
|
283
289
|
describe('bulk operations', () => {
|
|
284
290
|
test('ToggledAll marks all todos completed when some are active', () => {
|
|
285
291
|
const allCompletedTodos = modelWithTodos.todos.map(todo =>
|
|
286
|
-
|
|
292
|
+
modifyFields(todo, { completed: () => true }),
|
|
287
293
|
)
|
|
288
294
|
|
|
289
295
|
story(
|
|
@@ -303,15 +309,15 @@ describe('update', () => {
|
|
|
303
309
|
})
|
|
304
310
|
|
|
305
311
|
test('ToggledAll marks all todos active when all are completed', () => {
|
|
306
|
-
const allCompletedModel: Model =
|
|
312
|
+
const allCompletedModel: Model = modifyFields(emptyModel, {
|
|
307
313
|
todos: () =>
|
|
308
314
|
modelWithTodos.todos.map(todo =>
|
|
309
|
-
|
|
315
|
+
modifyFields(todo, { completed: () => true }),
|
|
310
316
|
),
|
|
311
317
|
})
|
|
312
318
|
|
|
313
319
|
const allActiveTodos = allCompletedModel.todos.map(todo =>
|
|
314
|
-
|
|
320
|
+
modifyFields(todo, { completed: () => false }),
|
|
315
321
|
)
|
|
316
322
|
|
|
317
323
|
story(
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
"test": "vitest run"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@effect/platform-browser": "4.0.0-rc.
|
|
12
|
+
"@effect/platform-browser": "4.0.0-rc.116",
|
|
13
13
|
"@foldkit/ui": "workspace:*",
|
|
14
14
|
"clsx": "^2.1.1",
|
|
15
|
-
"effect": "4.0.0-rc.
|
|
15
|
+
"effect": "4.0.0-rc.116",
|
|
16
16
|
"foldkit": "workspace:*"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
@@ -13,7 +13,7 @@ import { Document, Html, HtmlBuilder } from 'foldkit/html'
|
|
|
13
13
|
import { defineMessageUnion } from 'foldkit/message'
|
|
14
14
|
import { UrlRequest, load, pushUrl } from 'foldkit/navigation'
|
|
15
15
|
import { defineRouteUnion, literal } from 'foldkit/route'
|
|
16
|
-
import {
|
|
16
|
+
import { modifyFields } from 'foldkit/struct'
|
|
17
17
|
import { Url, toString as urlToString } from 'foldkit/url'
|
|
18
18
|
|
|
19
19
|
import { Dialog, Nav } from '@foldkit/ui'
|
|
@@ -211,21 +211,24 @@ const toUiMessage = (message: UiMessage): Message =>
|
|
|
211
211
|
const foldUi = Update.foldChild({
|
|
212
212
|
update: uiUpdate,
|
|
213
213
|
read: (model: Model) => Option.some(model.uiModel),
|
|
214
|
-
write: (model, nextUiModel) =>
|
|
214
|
+
write: (model, nextUiModel) =>
|
|
215
|
+
modifyFields(model, { uiModel: () => nextUiModel }),
|
|
215
216
|
toParentMessage: toUiMessage,
|
|
216
217
|
})
|
|
217
218
|
|
|
218
219
|
const foldUiOpenMobileMenu = Update.foldChildStep({
|
|
219
220
|
update: openMobileMenu,
|
|
220
221
|
read: (model: Model) => Option.some(model.uiModel),
|
|
221
|
-
write: (model, nextUiModel) =>
|
|
222
|
+
write: (model, nextUiModel) =>
|
|
223
|
+
modifyFields(model, { uiModel: () => nextUiModel }),
|
|
222
224
|
toParentMessage: toUiMessage,
|
|
223
225
|
})
|
|
224
226
|
|
|
225
227
|
const foldUiCloseMobileMenu = Update.foldChildStep({
|
|
226
228
|
update: closeMobileMenu,
|
|
227
229
|
read: (model: Model) => Option.some(model.uiModel),
|
|
228
|
-
write: (model, nextUiModel) =>
|
|
230
|
+
write: (model, nextUiModel) =>
|
|
231
|
+
modifyFields(model, { uiModel: () => nextUiModel }),
|
|
229
232
|
toParentMessage: toUiMessage,
|
|
230
233
|
})
|
|
231
234
|
|
|
@@ -251,7 +254,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
251
254
|
ChangedUrl: ({ url }) =>
|
|
252
255
|
Update.combine(model, [
|
|
253
256
|
stepModel => ({
|
|
254
|
-
model:
|
|
257
|
+
model: modifyFields(stepModel, { route: () => urlToAppRoute(url) }),
|
|
255
258
|
}),
|
|
256
259
|
foldUiCloseMobileMenu,
|
|
257
260
|
]),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Option } from 'effect'
|
|
2
2
|
import { Calendar } from 'foldkit'
|
|
3
3
|
import { Command, given, message, model, story } from 'foldkit/story'
|
|
4
|
-
import {
|
|
4
|
+
import { modifyFields } from 'foldkit/struct'
|
|
5
5
|
import { fromString } from 'foldkit/url'
|
|
6
6
|
import { describe, expect, test } from 'vitest'
|
|
7
7
|
|
|
@@ -98,8 +98,8 @@ describe('update', () => {
|
|
|
98
98
|
|
|
99
99
|
describe('mobile menu', () => {
|
|
100
100
|
test('navigating to a new URL closes the mobile menu dialog', () => {
|
|
101
|
-
const modelWithOpenMenu: Model =
|
|
102
|
-
uiModel:
|
|
101
|
+
const modelWithOpenMenu: Model = modifyFields(initialModel, {
|
|
102
|
+
uiModel: modifyFields({
|
|
103
103
|
mobileMenuDialog: () =>
|
|
104
104
|
Dialog.boot({
|
|
105
105
|
id: 'mobile-menu',
|
|
@@ -167,7 +167,10 @@ export const uiInit = (today: Calendar.CalendarDate): InitReturn => ({
|
|
|
167
167
|
id: 'vertical-tabs-demo',
|
|
168
168
|
}),
|
|
169
169
|
verticalTabsDemoTab: 'Foldkit',
|
|
170
|
-
toastDemo: Toast.init({
|
|
170
|
+
toastDemo: Toast.init({
|
|
171
|
+
id: 'toast-demo',
|
|
172
|
+
swipeToDismiss: {},
|
|
173
|
+
}),
|
|
171
174
|
tooltipBasicDemo: Tooltip.init({ id: 'tooltip-basic-demo' }),
|
|
172
175
|
tooltipNoDelayDemo: Tooltip.init({
|
|
173
176
|
id: 'tooltip-no-delay-demo',
|
|
@@ -4,6 +4,7 @@ import { DragAndDrop, Slider, VirtualList } from '@foldkit/ui'
|
|
|
4
4
|
|
|
5
5
|
import { Message as UiMessage } from './message'
|
|
6
6
|
import type { UiModel } from './model'
|
|
7
|
+
import { Toast } from './toast'
|
|
7
8
|
|
|
8
9
|
const dragAndDropSubscriptions = Subscription.lift({
|
|
9
10
|
dragPointer: DragAndDrop.subscriptions.documentPointer,
|
|
@@ -46,10 +47,19 @@ const virtualListVariableDemoSubscriptions = Subscription.lift({
|
|
|
46
47
|
UiMessage.GotVirtualListVariableDemoMessage({ message }),
|
|
47
48
|
})
|
|
48
49
|
|
|
50
|
+
const toastDemoSubscriptions = Subscription.lift(Toast.subscriptions)<
|
|
51
|
+
UiModel,
|
|
52
|
+
UiMessage
|
|
53
|
+
>({
|
|
54
|
+
toChildModel: model => model.toastDemo,
|
|
55
|
+
toParentMessage: message => UiMessage.GotToastDemoMessage({ message }),
|
|
56
|
+
})
|
|
57
|
+
|
|
49
58
|
export const subscriptions = Subscription.aggregate(
|
|
50
59
|
dragAndDropSubscriptions,
|
|
51
60
|
sliderRatingSubscriptions,
|
|
52
61
|
sliderVolumeSubscriptions,
|
|
53
62
|
virtualListDemoSubscriptions,
|
|
54
63
|
virtualListVariableDemoSubscriptions,
|
|
64
|
+
toastDemoSubscriptions,
|
|
55
65
|
)
|