@molecule/app-margin-notes-react 1.0.1 → 1.0.7

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/LICENSE CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  Apache License
2
3
  Version 2.0, January 2004
3
4
  http://www.apache.org/licenses/
@@ -34,21 +35,33 @@
34
35
 
35
36
  "Work" shall mean the work of authorship, whether in Source or
36
37
  Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work.
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
38
40
 
39
41
  "Derivative Works" shall mean any work, whether in Source or Object
40
42
  form, that is based on (or derived from) the Work and for which the
41
43
  editorial revisions, annotations, elaborations, or other modifications
42
- represent, as a whole, an original work of authorship.
43
-
44
- "Contribution" shall mean any work of authorship, including the
45
- original version of the Work and any modifications or additions
46
- to that Work, that is intentionally submitted to the Licensor for
47
- inclusion in the Work by the copyright owner or by an individual or
48
- Legal Entity authorized to submit on behalf of the copyright owner.
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
49
62
 
50
63
  "Contributor" shall mean Licensor and any individual or Legal Entity
51
- on behalf of whom a Contribution has been received by the Licensor and
64
+ on behalf of whom a Contribution has been received by Licensor and
52
65
  subsequently incorporated within the Work.
53
66
 
54
67
  2. Grant of Copyright License. Subject to the terms and conditions of
@@ -61,8 +74,18 @@
61
74
  3. Grant of Patent License. Subject to the terms and conditions of
62
75
  this License, each Contributor hereby grants to You a perpetual,
63
76
  worldwide, non-exclusive, no-charge, royalty-free, irrevocable
64
- patent license to make, have made, use, offer to sell, sell, import,
65
- and otherwise transfer the Work.
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
66
89
 
67
90
  4. Redistribution. You may reproduce and distribute copies of the
68
91
  Work or Derivative Works thereof in any medium, with or without
@@ -84,23 +107,87 @@
84
107
  (d) If the Work includes a "NOTICE" text file as part of its
85
108
  distribution, then any Derivative Works that You distribute must
86
109
  include a readable copy of the attribution notices contained
87
- within such NOTICE file.
88
-
89
- 5. Submission of Contributions.
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
90
138
 
91
139
  6. Trademarks. This License does not grant permission to use the trade
92
- names, trademarks, service marks, or product names of the Licensor.
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
93
143
 
94
144
  7. Disclaimer of Warranty. Unless required by applicable law or
95
- agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
96
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
97
-
98
- 8. Limitation of Liability. In no event and under no legal theory shall
99
- any Contributor be liable to You for damages.
100
-
101
- 9. Accepting Warranty or Additional Liability.
102
-
103
- Copyright 2026 Molecule Dev, Inc.
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
104
191
 
105
192
  Licensed under the Apache License, Version 2.0 (the "License");
106
193
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -3,15 +3,11 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-09-24T07:19:29.276Z
6
+ Generated: 2026-10-16T23:36:45.302Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-margin-notes-react
10
10
 
11
- > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
12
- > It is written to be read by coding agents as much as by people, and is generated from this
13
- > package's source — edit `src/index.ts` JSDoc, not this file.
14
-
15
11
  Margin notes: long-form text with notes beside each paragraph — annotated
16
12
  essays, commentary, and posts that show which paragraphs an AI wrote and the
17
13
  prompt behind each.
@@ -25,29 +21,127 @@ carry a small mark in its left margin. Note kinds (say, "Summaries" and
25
21
  fixed to the bottom that shows the notes for the section being read and
26
22
  follows the reader; tapping a paragraph pins its notes, tapping again lets
27
23
  go; the switches live in the bar. A document with no notes renders centred
28
- prose at full measure with no notes column.
24
+ prose at full measure with no notes column, no switches and no bar.
25
+
26
+ The example is a complete static-site post body: it takes the post's
27
+ `provenance.json` (written at build time by `@molecule/api-text-provenance`,
28
+ whose example produces exactly this shape) and a TL;DR per section, and
29
+ renders every block with a summary beside its section (switch ON), the prompt
30
+ beside the AI paragraphs it wrote (switch OFF), a margin mark on each AI
31
+ paragraph, the AI-share line, and the phone bar — all correct in the
32
+ prerendered HTML before any JavaScript runs.
33
+
34
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
35
+ > It is written to be read by coding agents as much as by people, and is generated from this
36
+ > package's source — edit `src/index.ts` JSDoc, not this file.
29
37
 
30
38
  ## Quick Start
31
39
 
32
40
  ```tsx
33
- import { MarginNotes } from '@molecule/app-margin-notes-react'
41
+ // PostBody.tsx — a post's body with notes beside it, rendered from the post's provenance.json
42
+ // (written at build time by @molecule/api-text-provenance) and its section summaries.
43
+ import type { JSX } from 'react'
44
+
45
+ import {
46
+ type MarginNote,
47
+ type MarginNoteKind,
48
+ MarginNotes,
49
+ type MarginNotesBlock,
50
+ } from '@molecule/app-margin-notes-react'
51
+ import { requireProvider } from '@molecule/app-markdown'
52
+ import { useTranslation } from '@molecule/app-react'
53
+ import { getClassMap } from '@molecule/app-ui'
54
+
55
+ // One entry of provenance.json's `spans`: a block of the post's markdown, in page order.
56
+ export interface PostSpan {
57
+ text: string
58
+ origin: 'human' | 'ai'
59
+ prompt?: string
60
+ model?: string
61
+ }
34
62
 
35
- // blocks: your rendered paragraphs, in order; notes: what goes beside them.
36
- ;<MarginNotes
37
- blocks={[
38
- { id: 'p1', content: <p>Every post carries a map of who wrote what.</p>, noteIds: ['s1'] },
39
- {
40
- id: 'p2',
41
- content: <p>The map is built from the session export.</p>,
42
- noteIds: ['s1', 'q1'],
43
- marked: true,
44
- },
45
- ]}
46
- notes={[
47
- { id: 's1', kind: 'summary', content: <p>How the map is made.</p> },
48
- { id: 'q1', kind: 'prompt', content: <p>“explain the map” — claude-opus-4</p> },
49
- ]}
50
- kinds={[
63
+ // provenance.json, as the build wrote it.
64
+ export interface PostProvenance {
65
+ aiShare: number
66
+ prompts: string[]
67
+ spans: PostSpan[]
68
+ }
69
+
70
+ // The span indexes that start a section: 0 (the lead), then every heading at the post's
71
+ // shallowest heading level. Key your summaries by these indexes.
72
+ export function sectionStarts(spans: PostSpan[]): number[] {
73
+ const level = (text: string): number => text.match(/^#{1,6}(?=\s)/)?.[0].length ?? 0
74
+ const top = Math.min(...spans.map((span) => level(span.text) || 7))
75
+ return spans.flatMap((span, i) => (i === 0 || level(span.text) === top ? [i] : []))
76
+ }
77
+
78
+ // summaries: TL;DR text per section, keyed by the section's start index from sectionStarts().
79
+ export function PostBody({
80
+ provenance,
81
+ summaries = {},
82
+ }: {
83
+ provenance: PostProvenance
84
+ summaries?: Record<number, string>
85
+ }): JSX.Element {
86
+ const cm = getClassMap()
87
+ const { t } = useTranslation()
88
+ const markdown = requireProvider()
89
+ const label = cm.cn(cm.textSize('xs'), cm.uppercase, cm.trackingWide, cm.fontWeight('semibold'))
90
+ const starts = new Set(sectionStarts(provenance.spans))
91
+ const notes: MarginNote[] = []
92
+ const promptNoteIds = new Map<string, string>()
93
+ let summaryId: string | undefined
94
+
95
+ const blocks: MarginNotesBlock[] = provenance.spans.map((span, i) => {
96
+ if (starts.has(i)) {
97
+ summaryId = summaries[i] ? `summary-${i}` : undefined
98
+ if (summaryId) {
99
+ notes.push({
100
+ id: summaryId,
101
+ kind: 'summary',
102
+ content: (
103
+ <>
104
+ <p className={label}>{t('post.tldr', undefined, { defaultValue: 'TL;DR' })}</p>
105
+ <p>{summaries[i]}</p>
106
+ </>
107
+ ),
108
+ })
109
+ }
110
+ }
111
+ const noteIds = summaryId ? [summaryId] : []
112
+ if (span.origin === 'ai' && span.prompt) {
113
+ let id = promptNoteIds.get(span.prompt)
114
+ if (!id) {
115
+ id = `prompt-${promptNoteIds.size}`
116
+ promptNoteIds.set(span.prompt, id)
117
+ notes.push({
118
+ id,
119
+ kind: 'prompt',
120
+ content: (
121
+ <>
122
+ <p className={cm.cn(label, cm.textPrimary)}>
123
+ {t(
124
+ 'post.promptBy',
125
+ { model: span.model ?? '' },
126
+ { defaultValue: 'Prompt · {{model}}' },
127
+ )}
128
+ </p>
129
+ <p className={cm.textPrimary}>{span.prompt}</p>
130
+ </>
131
+ ),
132
+ })
133
+ }
134
+ noteIds.push(id)
135
+ }
136
+ return {
137
+ id: `block-${i}`,
138
+ content: <div dangerouslySetInnerHTML={{ __html: markdown.render(span.text).html }} />,
139
+ noteIds,
140
+ marked: span.origin === 'ai',
141
+ }
142
+ })
143
+
144
+ const kinds: MarginNoteKind[] = [
51
145
  {
52
146
  id: 'summary',
53
147
  label: t('post.summaries', undefined, { defaultValue: 'Summaries' }),
@@ -59,9 +153,45 @@ import { MarginNotes } from '@molecule/app-margin-notes-react'
59
153
  defaultOn: false,
60
154
  panel: 'tap',
61
155
  },
62
- ]}
63
- markLabel={t('post.aiWritten', undefined, { defaultValue: 'Written with AI' })}
64
- />
156
+ ]
157
+ const percent = Math.round(provenance.aiShare * 100)
158
+ const count = provenance.prompts.length
159
+ const share =
160
+ count === 0
161
+ ? t('post.allHuman', undefined, {
162
+ defaultValue: 'Every word of this post was written by a person.',
163
+ })
164
+ : t(
165
+ count === 1 ? 'post.aiShareOne' : 'post.aiShare',
166
+ { percent, count },
167
+ {
168
+ defaultValue:
169
+ count === 1
170
+ ? '{{percent}}% of the words were written by an AI, from 1 prompt'
171
+ : '{{percent}}% of the words were written by an AI, from {{count}} prompts',
172
+ },
173
+ )
174
+
175
+ return (
176
+ <div className={cm.prose}>
177
+ <p
178
+ className={cm.cn(cm.textCenter, cm.textMuted, cm.textSize('sm'))}
179
+ data-mol-id="post-ai-share"
180
+ >
181
+ {share}
182
+ </p>
183
+ <MarginNotes
184
+ blocks={blocks}
185
+ notes={notes}
186
+ kinds={kinds}
187
+ markLabel={t('post.aiWritten', undefined, { defaultValue: 'Written with AI' })}
188
+ />
189
+ </div>
190
+ )
191
+ }
192
+
193
+ // In the Post page, in place of the single dangerouslySetInnerHTML body:
194
+ // <PostBody provenance={post.provenance} summaries={post.summaries} />
65
195
  ```
66
196
 
67
197
  ## Type
@@ -79,6 +209,27 @@ npm install -D @types/react
79
209
 
80
210
  ### Interfaces
81
211
 
212
+ #### `MarginNotesBlock`
213
+
214
+ One block of the text — usually a paragraph or heading from your markdown
215
+ renderer. Blocks render in order, in the prose column.
216
+
217
+ ```typescript
218
+ interface MarginNotesBlock {
219
+ /** Stable id, unique within the document (used as the DOM anchor). */
220
+ id: string
221
+ /** The rendered block (e.g. `<p>…</p>`). */
222
+ content: ReactNode
223
+ /** Ids of the notes that belong to this block (see {@link MarginNote}). */
224
+ noteIds?: string[]
225
+ /**
226
+ * Draw a small mark in this block's left margin — the one permanent sign on
227
+ * the prose itself (e.g. "written with AI"). Unmarked blocks carry none.
228
+ */
229
+ marked?: boolean
230
+ }
231
+ ```
232
+
82
233
  #### `MarginNote`
83
234
 
84
235
  A note shown beside the block(s) it belongs to.
@@ -110,33 +261,13 @@ interface MarginNoteKind {
110
261
  * How this kind reaches the phone panel. `'follow'` (default): the panel
111
262
  * shows it for the section being read, following the reader. `'tap'`: only
112
263
  * when the reader taps a block it belongs to (and gone on the second tap) —
113
- * for notes about one paragraph rather than the section.
264
+ * for notes about one paragraph rather than the section. A tap shows the
265
+ * note even while its switch is off: on a phone the tap is how it is found.
114
266
  */
115
267
  panel?: 'follow' | 'tap'
116
268
  }
117
269
  ```
118
270
 
119
- #### `MarginNotesBlock`
120
-
121
- One block of the text — usually a paragraph or heading from your markdown
122
- renderer. Blocks render in order, in the prose column.
123
-
124
- ```typescript
125
- interface MarginNotesBlock {
126
- /** Stable id, unique within the document (used as the DOM anchor). */
127
- id: string
128
- /** The rendered block (e.g. `<p>…</p>`). */
129
- content: ReactNode
130
- /** Ids of the notes that belong to this block (see {@link MarginNote}). */
131
- noteIds?: string[]
132
- /**
133
- * Draw a small mark in this block's left margin — the one permanent sign on
134
- * the prose itself (e.g. "written with AI"). Unmarked blocks carry none.
135
- */
136
- marked?: boolean
137
- }
138
- ```
139
-
140
271
  #### `MarginNotesProps`
141
272
 
142
273
  `<MarginNotes>` props.
@@ -181,15 +312,41 @@ interface MarginNotesRow {
181
312
 
182
313
  ### Functions
183
314
 
315
+ #### `MarginNotes(props)`
316
+
317
+ Long-form text with notes beside each paragraph.
318
+
319
+ Desktop: a prose column and, to its right, a narrower notes column; each
320
+ note lines up with the block(s) it belongs to and appears once. Phone: the
321
+ notes column disappears and a bar fixed to the bottom shows the notes for
322
+ the section being read (tap a block to pin its notes, tap again to let go),
323
+ with the kind switches in the bar. Every default — which kinds show, which
324
+ surface a width gets — is decided in the first render and by CSS, so
325
+ server-rendered or prerendered HTML is right before any JavaScript runs.
326
+
327
+ ```typescript
328
+ function MarginNotes(props: MarginNotesProps): JSX.Element
329
+ ```
330
+
331
+ - `props` — See {@link MarginNotesProps}.
332
+
333
+ **Returns:** The layout.
334
+
184
335
  #### `buildRows(blocks, notes)`
185
336
 
186
337
  Group blocks into layout rows and place each note once.
187
338
 
188
- A row is a run of consecutive blocks that refer to exactly the same set of
189
- notes (a paragraph run sharing one note), or a run of consecutive blocks
190
- with no notes. Each note is shown beside the FIRST row that refers to it and
191
- never again, so a note covering several paragraphs — even ones that are not
192
- next to each other — appears once on the page.
339
+ A row runs for as long as its blocks are covered by a note it OPENED with: a
340
+ section's summary (every block of the section refers to it) keeps the whole
341
+ section in one row, and a note that first appears mid-row — a prompt behind
342
+ one of the section's paragraphs — joins that row's gutter but does not
343
+ extend the row. (A prompt that produced paragraphs in several sections once
344
+ carried a row across the next heading, and that section's summary was drawn
345
+ beside the previous section.) A sticky note is
346
+ bounded by its row, so this is what keeps a summary pinned until its section
347
+ ends; splitting the row wherever the note set changed released it after the
348
+ first paragraph. A run of blocks with no notes is a row of its own. Each note
349
+ is shown once, in the first row that refers to it.
193
350
 
194
351
  ```typescript
195
352
  function buildRows(blocks: MarginNotesBlock[], notes?: MarginNote[]): MarginNotesRow[]
@@ -200,37 +357,36 @@ function buildRows(blocks: MarginNotesBlock[], notes?: MarginNote[]): MarginNote
200
357
 
201
358
  **Returns:** The rows, in reading order.
202
359
 
203
- #### `defaultShownKinds(kinds)`
360
+ #### `mergeRepeatedNotes(blocks, notes)`
204
361
 
205
- The kinds shown before the reader touches a switch.
362
+ One note per act of writing: when consecutive blocks each carry their own
363
+ note with the same kind and the same plain-text content (one prompt that produced three
364
+ paragraphs, recorded as three notes), every later block is pointed at the
365
+ first block's note instead. {@link buildRows} places each note once, so the
366
+ prompt is shown once, beside the first paragraph it produced, and hovering
367
+ any of those paragraphs highlights that one note. The same text appearing
368
+ again after a block without it is a new act, and keeps its own note.
206
369
 
207
370
  ```typescript
208
- function defaultShownKinds(kinds?: { id: string; defaultOn?: boolean }[]): string[]
371
+ function mergeRepeatedNotes(blocks: MarginNotesBlock[], notes?: MarginNote[]): MarginNotesBlock[]
209
372
  ```
210
373
 
211
- - `kinds` — The switchable kinds.
212
-
213
- **Returns:** The ids of the kinds that default on.
374
+ - `blocks` — The text, in reading order.
375
+ - `notes` — Every note the blocks refer to.
214
376
 
215
- #### `MarginNotes(props)`
377
+ **Returns:** The blocks, with repeated notes pointed at the first copy.
216
378
 
217
- Long-form text with notes beside each paragraph.
379
+ #### `defaultShownKinds(kinds)`
218
380
 
219
- Desktop: a prose column and, to its right, a narrower notes column; each
220
- note lines up with the block(s) it belongs to and appears once. Phone: the
221
- notes column disappears and a bar fixed to the bottom shows the notes for
222
- the section being read (tap a block to pin its notes, tap again to let go),
223
- with the kind switches in the bar. Every default — which kinds show, which
224
- surface a width gets — is decided in the first render and by CSS, so
225
- server-rendered or prerendered HTML is right before any JavaScript runs.
381
+ The kinds shown before the reader touches a switch.
226
382
 
227
383
  ```typescript
228
- function MarginNotes(props: MarginNotesProps): JSX.Element
384
+ function defaultShownKinds(kinds?: { id: string; defaultOn?: boolean }[]): string[]
229
385
  ```
230
386
 
231
- - `props` — See {@link MarginNotesProps}.
387
+ - `kinds` — The switchable kinds.
232
388
 
233
- **Returns:** The layout.
389
+ **Returns:** The ids of the kinds that default on.
234
390
 
235
391
  ## Injection Notes
236
392
 
@@ -250,33 +406,46 @@ Peer dependencies:
250
406
  - `@molecule/app-ui-react`
251
407
  - `react`
252
408
 
253
- - **Defaults are right before JavaScript runs.** Which kinds show comes from
254
- `kinds[].defaultOn` in the FIRST render (a hidden note carries the HTML
255
- `hidden` attribute), and the desktop/phone split is CSS
256
- (`cm.hiddenBelow('md')` / `cm.hiddenFrom('md')`). Prerender the page with
257
- `renderToString` and a kind that defaults off is already absent; do NOT
258
- toggle defaults in a `useEffect` of your own.
259
- - **One note, one place.** A note shows beside the FIRST row that refers to
260
- it. Give consecutive paragraphs that share a note the same `noteIds` and
261
- they form one row with the note beside them once. A paragraph whose
262
- `noteIds` differ from its neighbour's starts a new row.
263
- - **The mark is drawn on the block**, as an absolutely-placed dot inside the
264
- block's own wrapper (hidden on phones, where there is no margin). At rest a
265
- marked block is typeset exactly like an unmarked one.
266
- - **Pass rendered blocks, not markdown.** Split your renderer's output into
267
- top-level blocks (one per paragraph/heading/list) and give each a stable
268
- `id`; the component adds no markup inside them.
269
- - **Section notes follow the reader; paragraph notes wait for a tap.** On a
409
+ - **Do NOT hand-build an annotator** — no grid of your own, no hover or
410
+ scroll script, no margin dots, no bottom bar, no toggle state. This
411
+ component is all of it: pass `blocks`, `notes` and `kinds`.
412
+ - **Do NOT set the defaults in a `useEffect` or hide notes with your own
413
+ CSS.** `kinds[].defaultOn` is read in the FIRST render, so
414
+ `renderToString`/prerender already ships a default-off kind with the HTML
415
+ `hidden` attribute and its switch reading off; the desktop/phone split is
416
+ CSS (`cm.hiddenBelow('md')` / `cm.hiddenFrom('md')`).
417
+ - **Do NOT render the body as one HTML string.** Pass one block per
418
+ top-level markdown block (paragraph, heading, list, code), each with a
419
+ stable `id` — the example renders each provenance span with
420
+ `@molecule/app-markdown`. The component adds no markup inside a block.
421
+ - **Do NOT make one note per paragraph.** Make ONE note per prompt (or per
422
+ section summary) and put its id in the `noteIds` of every block it covers:
423
+ it shows once, beside the first. Consecutive blocks with the same
424
+ `noteIds` form one row.
425
+ - **Do NOT add a second copy of the notes for phones** (inline between
426
+ paragraphs, a popover). The bar is the phone's copy.
427
+ - **Do NOT import `@molecule/api-*` packages into the page** — they are
428
+ server-only. The page reads what the build wrote (`provenance.json`, or
429
+ spans passed to the prerender).
430
+ - The example needs `@molecule/app-markdown` and a markdown bond
431
+ (`@molecule/app-markdown-marked`), bonded once at startup:
432
+ `setProvider(provider)`.
433
+ - Section notes follow the reader; paragraph notes wait for a tap. On a
270
434
  phone the panel shows the kinds with `panel: 'follow'` (the default) for
271
- the section in view. Give a kind that is about ONE paragraph (a prompt, a
272
- citation) `panel: 'tap'`: it shows when that paragraph is tapped and goes
273
- on the second tap.
274
- - **Controlled or not.** Pass `shownKinds` + `onShownKindsChange` to own the
435
+ the section in view. A kind about ONE paragraph (a prompt, a citation)
436
+ gets `panel: 'tap'`: while its switch is off it shows only when that
437
+ paragraph is tapped (and goes on the second tap); once its switch is ON it
438
+ follows the section in view like a `'follow'` kind, so the switch always
439
+ shows something.
440
+ - The mark is drawn on the block, as an absolutely-placed dot inside the
441
+ block's own wrapper (hidden on phones). At rest a marked block is typeset
442
+ exactly like an unmarked one.
443
+ - Controlled or not: pass `shownKinds` + `onShownKindsChange` to own the
275
444
  switches' state (e.g. to remember it); otherwise the component does.
276
445
  - The phone bar reserves space at the end of the text so it never covers the
277
446
  last paragraph. UI strings come from the companion locale bond
278
- `@molecule/app-locales-margin-notes`; kind labels and `markLabel` are yours
279
- to translate.
447
+ `@molecule/app-locales-margin-notes`; kind labels and `markLabel` are
448
+ yours to translate.
280
449
 
281
450
  ## Translations
282
451
 
@@ -1 +1 @@
1
- {"version":3,"file":"MarginNotes.d.ts","sourceRoot":"","sources":["../src/MarginNotes.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,GAAG,EAAE,MAAM,OAAO,CAAA;AAQ/C,OAAO,KAAK,EAAc,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAQ9D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,GAAG,CAAC,OAAO,CAsShE"}
1
+ {"version":3,"file":"MarginNotes.d.ts","sourceRoot":"","sources":["../src/MarginNotes.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,GAAG,EAAE,MAAM,OAAO,CAAA;AAQ/C,OAAO,KAAK,EAAc,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAQ9D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,GAAG,CAAC,OAAO,CAgThE"}