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