@foldkit/markdown 0.14.3-canary.d8b5fc47e803 → 0.14.3-canary.e1bac2b2ac98
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/README.md +35 -11
- package/dist/view/view.d.ts +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -111,21 +111,45 @@ import { islandAttributes } from './src/islands'
|
|
|
111
111
|
markdown({ islands: islandAttributes })
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
`islandsFor` pairs the same definitions with typed views: attributes arrive decoded through each island's schema, and the record must cover every declared name. State stays in your Model; the markdown only decides placement. The third argument is the zero-based occurrence of that island name in the document, for identifiers that must be unique per instance, like an `h.
|
|
114
|
+
`islandsFor` pairs the same definitions with typed views: attributes arrive decoded through each island's schema, and the record must cover every declared name. State stays in your Model; the markdown only decides placement. The third argument is the zero-based occurrence of that island name in the document, for identifiers that must be unique per instance, like an `h.block` slotId:
|
|
115
115
|
|
|
116
116
|
```typescript
|
|
117
|
-
import {
|
|
117
|
+
import { Schema } from 'effect'
|
|
118
|
+
import { Block } from 'foldkit'
|
|
119
|
+
import { defineApplication } from 'foldkit'
|
|
120
|
+
import type { Html } from 'foldkit/html'
|
|
121
|
+
import { defineMessageUnion } from 'foldkit/message'
|
|
118
122
|
|
|
119
123
|
import * as Markdown from '@foldkit/markdown'
|
|
120
124
|
|
|
121
|
-
import
|
|
125
|
+
import * as Counter from './counter'
|
|
122
126
|
import { islandAttributes } from './islands'
|
|
123
|
-
|
|
127
|
+
|
|
128
|
+
const Model = Schema.Struct({ counter: Counter.Model })
|
|
129
|
+
type Model = typeof Model.Type
|
|
130
|
+
|
|
131
|
+
const Message = defineMessageUnion({
|
|
132
|
+
GotCounterMessage: { message: Counter.Message },
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
export const Application = defineApplication({ Model, Message })
|
|
136
|
+
|
|
137
|
+
const CounterBinding = Application.bindChild(Counter.block, {
|
|
138
|
+
field: 'counter',
|
|
139
|
+
parentMessage: Message.GotCounterMessage,
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
export const ApplicationComposition = Application.makeComposition({
|
|
143
|
+
childBindings: [CounterBinding],
|
|
144
|
+
})
|
|
145
|
+
type ApplicationViewBuilder = Block.ViewBuilderFor<
|
|
146
|
+
typeof ApplicationComposition
|
|
147
|
+
>
|
|
124
148
|
|
|
125
149
|
const postView = (
|
|
126
150
|
model: Model,
|
|
127
151
|
post: Markdown.MarkdownDocument,
|
|
128
|
-
h:
|
|
152
|
+
h: ApplicationViewBuilder,
|
|
129
153
|
): Html =>
|
|
130
154
|
Markdown.view(post, {
|
|
131
155
|
islands: Markdown.islandsFor(islandAttributes, {
|
|
@@ -134,12 +158,12 @@ const postView = (
|
|
|
134
158
|
[],
|
|
135
159
|
[
|
|
136
160
|
h.span([], [label ?? 'Counter']),
|
|
137
|
-
h.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
161
|
+
h.block(
|
|
162
|
+
counter.embedView({
|
|
163
|
+
slotId: `counter-${occurrenceIndex}`,
|
|
164
|
+
model: model.counter,
|
|
165
|
+
}),
|
|
166
|
+
),
|
|
143
167
|
],
|
|
144
168
|
),
|
|
145
169
|
Note: (_attributes, content) =>
|
package/dist/view/view.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type InlineContent = ReadonlyArray<Html | string>;
|
|
|
8
8
|
* rendered nested blocks (empty for leaf directives), and the zero-based
|
|
9
9
|
* occurrence of this island name in the document, in document order. Use the
|
|
10
10
|
* occurrence index to derive identifiers that must be unique per instance,
|
|
11
|
-
* such as an `h.
|
|
11
|
+
* such as an `h.block` slotId.
|
|
12
12
|
*/
|
|
13
13
|
export type IslandView = (attributes: Readonly<globalThis.Record<string, string>>, content: ReadonlyArray<Html>, occurrenceIndex: number) => Html;
|
|
14
14
|
/** Island views by directive name. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foldkit/markdown",
|
|
3
|
-
"version": "0.14.3-canary.
|
|
3
|
+
"version": "0.14.3-canary.e1bac2b2ac98",
|
|
4
4
|
"description": "Write markdown files, get Foldkit views with live islands.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"effect": "4.0.0",
|
|
29
|
-
"foldkit": "0.168.0-canary.
|
|
29
|
+
"foldkit": "0.168.0-canary.e1bac2b2ac98",
|
|
30
30
|
"vite": "^8.0.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@types/mdast": "^4.0.4",
|
|
41
41
|
"@types/unist": "^3.0.3",
|
|
42
42
|
"effect": "4.0.0",
|
|
43
|
-
"foldkit": "0.168.0-canary.
|
|
43
|
+
"foldkit": "0.168.0-canary.e1bac2b2ac98",
|
|
44
44
|
"happy-dom": "^20.14.5",
|
|
45
45
|
"mdast-util-directive": "^3.1.0",
|
|
46
46
|
"rimraf": "^6.1.3",
|