@foldkit/markdown 0.14.3-canary.76fa0d1ee2a5 → 0.14.3-canary.bfd880b1e6ca
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 +38 -11
- package/dist/view/view.d.ts +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -111,21 +111,48 @@ 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 { makeApplicationDefinition } 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 ApplicationDefinition = makeApplicationDefinition({
|
|
136
|
+
Model,
|
|
137
|
+
Message,
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
const CounterBinding = ApplicationDefinition.bindChild(Counter.block, {
|
|
141
|
+
field: 'counter',
|
|
142
|
+
parentMessage: Message.GotCounterMessage,
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
export const ApplicationComposition = ApplicationDefinition.makeComposition({
|
|
146
|
+
bindings: [CounterBinding],
|
|
147
|
+
})
|
|
148
|
+
type ApplicationViewBuilder = Block.ViewBuilderFor<
|
|
149
|
+
typeof ApplicationComposition
|
|
150
|
+
>
|
|
124
151
|
|
|
125
152
|
const postView = (
|
|
126
153
|
model: Model,
|
|
127
154
|
post: Markdown.MarkdownDocument,
|
|
128
|
-
h:
|
|
155
|
+
h: ApplicationViewBuilder,
|
|
129
156
|
): Html =>
|
|
130
157
|
Markdown.view(post, {
|
|
131
158
|
islands: Markdown.islandsFor(islandAttributes, {
|
|
@@ -134,12 +161,12 @@ const postView = (
|
|
|
134
161
|
[],
|
|
135
162
|
[
|
|
136
163
|
h.span([], [label ?? 'Counter']),
|
|
137
|
-
h.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
164
|
+
h.block(
|
|
165
|
+
counter.embedView({
|
|
166
|
+
slotId: `counter-${occurrenceIndex}`,
|
|
167
|
+
model: model.counter,
|
|
168
|
+
}),
|
|
169
|
+
),
|
|
143
170
|
],
|
|
144
171
|
),
|
|
145
172
|
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.bfd880b1e6ca",
|
|
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.bfd880b1e6ca",
|
|
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.bfd880b1e6ca",
|
|
44
44
|
"happy-dom": "^20.14.5",
|
|
45
45
|
"mdast-util-directive": "^3.1.0",
|
|
46
46
|
"rimraf": "^6.1.3",
|