foldkit-mixins-surface 0.3.0 → 0.4.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 (2) hide show
  1. package/README.md +20 -9
  2. package/package.json +13 -12
package/README.md CHANGED
@@ -43,7 +43,7 @@ dependencies.
43
43
  ## Usage
44
44
 
45
45
  ```ts
46
- import { Schema } from 'effect'
46
+ import { Option, Schema } from 'effect'
47
47
  import { defineMessageUnion } from 'foldkit/message'
48
48
  import { Behavior, Capability, Event, Slot, Slots, Style } from 'foldkit-mixins'
49
49
  import { SurfaceView } from 'foldkit-mixins-surface'
@@ -51,7 +51,7 @@ import { Surface } from 'foldkit-surface'
51
51
 
52
52
  const Model = Schema.Struct({
53
53
  todos: Schema.Array(Schema.Struct({ id: Schema.String, title: Schema.String })),
54
- selectedId: Schema.NullOr(Schema.String),
54
+ selectedId: Schema.Option(Schema.String),
55
55
  secret: Schema.String,
56
56
  })
57
57
 
@@ -79,7 +79,7 @@ const TodoStyle = Style.forSlots(TodoSlots)({ root: Style.class('todo-list') })
79
79
  /** What the Surface projects — the input every attachment sees. */
80
80
  type ProjectedTodos = {
81
81
  readonly todos: ReadonlyArray<{ readonly id: string; readonly title: string }>
82
- readonly selectedId: string | null
82
+ readonly selectedId: Option.Option<string>
83
83
  }
84
84
 
85
85
  // `input` is the projection, so `input.secret` does not type-check; `h` builds
@@ -91,21 +91,32 @@ const TodoBehavior = Behavior.forSlots(TodoSlots)<
91
91
  archive: Behavior.slot({
92
92
  requires: { events: [Event.Click] },
93
93
  attributes: ({ input, h }) =>
94
- input.selectedId === null ? [] : [h.OnClick(Message.ArchivedTodo({ id: input.selectedId }))],
94
+ Option.match(input.selectedId, {
95
+ onNone: () => [],
96
+ onSome: id => [h.OnClick(Message.ArchivedTodo({ id }))],
97
+ }),
95
98
  }),
96
99
  })
97
100
 
98
101
  const TodoListView = SurfaceView.define(TodoList, TodoSlots, (model, slots, h) =>
99
- h.ul(
100
- slots.root.attrs(),
101
- model.todos.map(todo => h.li([], [todo.title])),
102
- ),
102
+ h.section(slots.root.attrs(), [
103
+ h.ul([], model.todos.map(todo => h.li([], [todo.title]))),
104
+ h.button(
105
+ slots.archive.attrs([h.Disabled(Option.isNone(model.selectedId))]),
106
+ ['Archive selected'],
107
+ ),
108
+ ]),
103
109
  ).pipe(Style.attach(TodoStyle), Behavior.attach(TodoBehavior))
104
110
 
105
111
  // `toRenderer` adapts a SlotView to what `Surface.view`/`Surface.rootView` take.
106
112
  const renderer = Surface.view(TodoList, SurfaceView.toRenderer(TodoListView))
107
113
  ```
108
114
 
115
+ `slots.archive.attrs(...)` is where the attached click behavior reaches a
116
+ real element. Declaring a slot or attaching a Behavior alone renders nothing.
117
+ With no selection the button is disabled; with a selection its click emits
118
+ `ArchivedTodo`, and the application's reducer performs the transition.
119
+
109
120
  The useful part is what the render callback does **not** repeat: no type
110
121
  annotation on `model` or `h`, no second Message union, and no root-Model input
111
122
  type. `SurfaceView.define` gets those from the Surface.
@@ -156,7 +167,7 @@ dispatched. It is for tests, demos, and static output, not a replacement for
156
167
  ```ts
157
168
  const html = SurfaceView.render(TodoListView, TodoList, undefined, {
158
169
  todos: [{ id: 't1', title: 'Write docs' }],
159
- selectedId: 't1',
170
+ selectedId: Option.some('t1'),
160
171
  secret: 'not projected',
161
172
  })
162
173
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foldkit-mixins-surface",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Bridge foldkit-surface's projected Model and Message subset to foldkit-mixins SlotViews.",
5
5
  "keywords": [
6
6
  "foldkit",
@@ -37,20 +37,21 @@
37
37
  "LICENSE"
38
38
  ],
39
39
  "peerDependencies": {
40
- "effect": "^4.0.0-rc.112",
41
- "foldkit": "^0.158.2",
42
- "foldkit-mixins": "^0.3.0",
43
- "foldkit-surface": "^0.2.0"
40
+ "effect": "^4.0.0-rc.116",
41
+ "foldkit": "^0.163.0",
42
+ "foldkit-mixins": "^0.4.0",
43
+ "foldkit-surface": "^0.5.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@foldkit/ui": "0.158.2",
47
- "effect": "4.0.0-rc.112",
48
- "foldkit": "0.158.2",
46
+ "@effect/platform-browser": "4.0.0-rc.116",
47
+ "@foldkit/ui": "0.163.0",
48
+ "effect": "4.0.0-rc.116",
49
+ "foldkit": "0.163.0",
49
50
  "tsdown": "^0.23.0",
50
- "typescript": "^5.7.2",
51
- "foldkit-mixins": "0.3.0",
52
- "foldkit-mixins-ui": "0.3.0",
53
- "foldkit-surface": "0.2.0"
51
+ "typescript": "5.9.3",
52
+ "foldkit-mixins": "0.4.0",
53
+ "foldkit-surface": "0.5.0",
54
+ "foldkit-mixins-ui": "0.4.0"
54
55
  },
55
56
  "scripts": {
56
57
  "build": "tsdown",