@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.
@@ -121,17 +121,26 @@ export function MarginNotes(props) {
121
121
  if (pinnedBlock)
122
122
  return blocks.find((b) => b.id === pinnedBlock)?.noteIds ?? [];
123
123
  const ids = rows.find((r) => r.id === readingRow)?.noteIds ?? [];
124
- return ids.filter((id) => !tapOnly.has(notesById.get(id)?.kind ?? ''));
125
- }, [pinnedBlock, readingRow, blocks, rows, tapOnly, notesById]);
124
+ // A tap kind follows the reader too once its switch is ON: turning the
125
+ // switch on must show something on a phone, not wait for a tap.
126
+ return ids.filter((id) => {
127
+ const note = notesById.get(id);
128
+ return !!note && (!tapOnly.has(note.kind) || isShown(note));
129
+ });
130
+ }, [pinnedBlock, readingRow, blocks, rows, tapOnly, notesById, isShown]);
131
+ // A tapped block's tap-kind notes show whatever their switch says: on a phone
132
+ // the tap is the only way to reach a note about one paragraph (a prompt that
133
+ // defaults off). Follow-kind notes keep obeying their switch.
134
+ const inPanel = (note) => isShown(note) || (pinnedBlock !== null && tapOnly.has(note.kind));
126
135
  const panelNotes = panelNoteIds
127
136
  .map((id) => notesById.get(id))
128
- .filter((n) => !!n && isShown(n));
137
+ .filter((n) => !!n && inPanel(n));
129
138
  const switches = (placement) => kinds.length === 0 ? null : (_jsx("div", { role: "group", "aria-label": t('marginNotes.aria.toggles', undefined, {
130
139
  defaultValue: 'Show or hide notes',
131
140
  }), className: cm.flex({ direction: 'row', wrap: 'wrap', gap: 'md', align: 'center' }), "data-mol-id": `margin-notes-switches-${placement}`, children: kinds.map((kind) => (_jsx(Switch, { label: kind.label, checked: shown.includes(kind.id), onChange: (event) => setShown(kind.id, event.target.checked), className: placement === 'bar' ? cm.touchTarget : cm.touchTargetCompact, "data-mol-id": `margin-notes-switch-${placement}-${kind.id}` }, kind.id))) }));
132
141
  const noteView = (note, where) => {
133
142
  const emphasised = activeBlockNotes.has(note.id) || activeNote === note.id;
134
- return (_jsx("aside", { hidden: !isShown(note), tabIndex: where === 'gutter' ? 0 : -1, "data-note-kind": note.kind, "data-note-emphasis": emphasised ? 'true' : undefined, "data-mol-id": `margin-note-${where}-${note.id}`, onMouseEnter: where === 'gutter' ? () => setActiveNote(note.id) : undefined, onMouseLeave: where === 'gutter' ? () => setActiveNote(null) : undefined, onFocus: where === 'gutter' ? () => setActiveNote(note.id) : undefined, onBlur: where === 'gutter' ? () => setActiveNote(null) : undefined, className: cm.cn(cm.sp('p', 3), cm.textSize('sm'), cm.textMuted, emphasised && cm.bgPrimarySubtle, emphasised && cm.shadowLifted), children: note.content }, note.id));
143
+ return (_jsx("aside", { hidden: where === 'panel' ? !inPanel(note) : !isShown(note), tabIndex: where === 'gutter' ? 0 : -1, "data-note-kind": note.kind, "data-note-emphasis": emphasised ? 'true' : undefined, "data-mol-id": `margin-note-${where}-${note.id}`, onMouseEnter: where === 'gutter' ? () => setActiveNote(note.id) : undefined, onMouseLeave: where === 'gutter' ? () => setActiveNote(null) : undefined, onFocus: where === 'gutter' ? () => setActiveNote(note.id) : undefined, onBlur: where === 'gutter' ? () => setActiveNote(null) : undefined, className: cm.cn(cm.sp('p', 3), cm.textSize('sm'), cm.textMuted, emphasised && cm.bgPrimarySubtle, emphasised && cm.shadowLifted), children: note.content }, note.id));
135
144
  };
136
145
  const containerStyle = {
137
146
  ...style,
package/dist/index.d.ts CHANGED
@@ -12,58 +12,215 @@
12
12
  * fixed to the bottom that shows the notes for the section being read and
13
13
  * follows the reader; tapping a paragraph pins its notes, tapping again lets
14
14
  * go; the switches live in the bar. A document with no notes renders centred
15
- * prose at full measure with no notes column.
15
+ * prose at full measure with no notes column, no switches and no bar.
16
+ *
17
+ * The example is a complete static-site post body: it takes the post's
18
+ * `provenance.json` (written at build time by `@molecule/api-text-provenance`,
19
+ * whose example produces exactly this shape) and a TL;DR per section, and
20
+ * renders every block with a summary beside its section (switch ON), the prompt
21
+ * beside the AI paragraphs it wrote (switch OFF), a margin mark on each AI
22
+ * paragraph, the AI-share line, and the phone bar — all correct in the
23
+ * prerendered HTML before any JavaScript runs.
16
24
  *
17
25
  * @example
18
26
  * ```tsx
19
- * import { MarginNotes } from '@molecule/app-margin-notes-react'
27
+ * // PostBody.tsx — a post's body with notes beside it, rendered from the post's provenance.json
28
+ * // (written at build time by @molecule/api-text-provenance) and its section summaries.
29
+ * import type { JSX } from 'react'
30
+ *
31
+ * import {
32
+ * type MarginNote,
33
+ * type MarginNoteKind,
34
+ * MarginNotes,
35
+ * type MarginNotesBlock,
36
+ * } from '@molecule/app-margin-notes-react'
37
+ * import { requireProvider } from '@molecule/app-markdown'
38
+ * import { useTranslation } from '@molecule/app-react'
39
+ * import { getClassMap } from '@molecule/app-ui'
40
+ *
41
+ * // One entry of provenance.json's `spans`: a block of the post's markdown, in page order.
42
+ * export interface PostSpan {
43
+ * text: string
44
+ * origin: 'human' | 'ai'
45
+ * prompt?: string
46
+ * model?: string
47
+ * }
48
+ *
49
+ * // provenance.json, as the build wrote it.
50
+ * export interface PostProvenance {
51
+ * aiShare: number
52
+ * prompts: string[]
53
+ * spans: PostSpan[]
54
+ * }
55
+ *
56
+ * // The span indexes that start a section: 0 (the lead), then every heading at the post's
57
+ * // shallowest heading level. Key your summaries by these indexes.
58
+ * export function sectionStarts(spans: PostSpan[]): number[] {
59
+ * const level = (text: string): number => text.match(/^#{1,6}(?=\s)/)?.[0].length ?? 0
60
+ * const top = Math.min(...spans.map((span) => level(span.text) || 7))
61
+ * return spans.flatMap((span, i) => (i === 0 || level(span.text) === top ? [i] : []))
62
+ * }
63
+ *
64
+ * // summaries: TL;DR text per section, keyed by the section's start index from sectionStarts().
65
+ * export function PostBody({
66
+ * provenance,
67
+ * summaries = {},
68
+ * }: {
69
+ * provenance: PostProvenance
70
+ * summaries?: Record<number, string>
71
+ * }): JSX.Element {
72
+ * const cm = getClassMap()
73
+ * const { t } = useTranslation()
74
+ * const markdown = requireProvider()
75
+ * const label = cm.cn(cm.textSize('xs'), cm.uppercase, cm.trackingWide, cm.fontWeight('semibold'))
76
+ * const starts = new Set(sectionStarts(provenance.spans))
77
+ * const notes: MarginNote[] = []
78
+ * const promptNoteIds = new Map<string, string>()
79
+ * let summaryId: string | undefined
80
+ *
81
+ * const blocks: MarginNotesBlock[] = provenance.spans.map((span, i) => {
82
+ * if (starts.has(i)) {
83
+ * summaryId = summaries[i] ? `summary-${i}` : undefined
84
+ * if (summaryId) {
85
+ * notes.push({
86
+ * id: summaryId,
87
+ * kind: 'summary',
88
+ * content: (
89
+ * <>
90
+ * <p className={label}>{t('post.tldr', undefined, { defaultValue: 'TL;DR' })}</p>
91
+ * <p>{summaries[i]}</p>
92
+ * </>
93
+ * ),
94
+ * })
95
+ * }
96
+ * }
97
+ * const noteIds = summaryId ? [summaryId] : []
98
+ * if (span.origin === 'ai' && span.prompt) {
99
+ * let id = promptNoteIds.get(span.prompt)
100
+ * if (!id) {
101
+ * id = `prompt-${promptNoteIds.size}`
102
+ * promptNoteIds.set(span.prompt, id)
103
+ * notes.push({
104
+ * id,
105
+ * kind: 'prompt',
106
+ * content: (
107
+ * <>
108
+ * <p className={cm.cn(label, cm.textPrimary)}>
109
+ * {t(
110
+ * 'post.promptBy',
111
+ * { model: span.model ?? '' },
112
+ * { defaultValue: 'Prompt · {{model}}' },
113
+ * )}
114
+ * </p>
115
+ * <p className={cm.textPrimary}>{span.prompt}</p>
116
+ * </>
117
+ * ),
118
+ * })
119
+ * }
120
+ * noteIds.push(id)
121
+ * }
122
+ * return {
123
+ * id: `block-${i}`,
124
+ * content: <div dangerouslySetInnerHTML={{ __html: markdown.render(span.text).html }} />,
125
+ * noteIds,
126
+ * marked: span.origin === 'ai',
127
+ * }
128
+ * })
129
+ *
130
+ * const kinds: MarginNoteKind[] = [
131
+ * {
132
+ * id: 'summary',
133
+ * label: t('post.summaries', undefined, { defaultValue: 'Summaries' }),
134
+ * defaultOn: true,
135
+ * },
136
+ * {
137
+ * id: 'prompt',
138
+ * label: t('post.prompts', undefined, { defaultValue: 'Prompts' }),
139
+ * defaultOn: false,
140
+ * panel: 'tap',
141
+ * },
142
+ * ]
143
+ * const percent = Math.round(provenance.aiShare * 100)
144
+ * const count = provenance.prompts.length
145
+ * const share =
146
+ * count === 0
147
+ * ? t('post.allHuman', undefined, {
148
+ * defaultValue: 'Every word of this post was written by a person.',
149
+ * })
150
+ * : t(
151
+ * count === 1 ? 'post.aiShareOne' : 'post.aiShare',
152
+ * { percent, count },
153
+ * {
154
+ * defaultValue:
155
+ * count === 1
156
+ * ? '{{percent}}% of the words were written by an AI, from 1 prompt'
157
+ * : '{{percent}}% of the words were written by an AI, from {{count}} prompts',
158
+ * },
159
+ * )
160
+ *
161
+ * return (
162
+ * <div className={cm.prose}>
163
+ * <p
164
+ * className={cm.cn(cm.textCenter, cm.textMuted, cm.textSize('sm'))}
165
+ * data-mol-id="post-ai-share"
166
+ * >
167
+ * {share}
168
+ * </p>
169
+ * <MarginNotes
170
+ * blocks={blocks}
171
+ * notes={notes}
172
+ * kinds={kinds}
173
+ * markLabel={t('post.aiWritten', undefined, { defaultValue: 'Written with AI' })}
174
+ * />
175
+ * </div>
176
+ * )
177
+ * }
20
178
  *
21
- * // blocks: your rendered paragraphs, in order; notes: what goes beside them.
22
- * <MarginNotes
23
- * blocks={[
24
- * { id: 'p1', content: <p>Every post carries a map of who wrote what.</p>, noteIds: ['s1'] },
25
- * { id: 'p2', content: <p>The map is built from the session export.</p>, noteIds: ['s1', 'q1'], marked: true },
26
- * ]}
27
- * notes={[
28
- * { id: 's1', kind: 'summary', content: <p>How the map is made.</p> },
29
- * { id: 'q1', kind: 'prompt', content: <p>“explain the map” — claude-opus-4</p> },
30
- * ]}
31
- * kinds={[
32
- * { id: 'summary', label: t('post.summaries', undefined, { defaultValue: 'Summaries' }), defaultOn: true },
33
- * { id: 'prompt', label: t('post.prompts', undefined, { defaultValue: 'Prompts' }), defaultOn: false, panel: 'tap' },
34
- * ]}
35
- * markLabel={t('post.aiWritten', undefined, { defaultValue: 'Written with AI' })}
36
- * />
179
+ * // In the Post page, in place of the single dangerouslySetInnerHTML body:
180
+ * // <PostBody provenance={post.provenance} summaries={post.summaries} />
37
181
  * ```
38
182
  *
39
183
  * @remarks
40
- * - **Defaults are right before JavaScript runs.** Which kinds show comes from
41
- * `kinds[].defaultOn` in the FIRST render (a hidden note carries the HTML
42
- * `hidden` attribute), and the desktop/phone split is CSS
43
- * (`cm.hiddenBelow('md')` / `cm.hiddenFrom('md')`). Prerender the page with
44
- * `renderToString` and a kind that defaults off is already absent; do NOT
45
- * toggle defaults in a `useEffect` of your own.
46
- * - **One note, one place.** A note shows beside the FIRST row that refers to
47
- * it. Give consecutive paragraphs that share a note the same `noteIds` and
48
- * they form one row with the note beside them once. A paragraph whose
49
- * `noteIds` differ from its neighbour's starts a new row.
50
- * - **The mark is drawn on the block**, as an absolutely-placed dot inside the
51
- * block's own wrapper (hidden on phones, where there is no margin). At rest a
52
- * marked block is typeset exactly like an unmarked one.
53
- * - **Pass rendered blocks, not markdown.** Split your renderer's output into
54
- * top-level blocks (one per paragraph/heading/list) and give each a stable
55
- * `id`; the component adds no markup inside them.
56
- * - **Section notes follow the reader; paragraph notes wait for a tap.** On a
184
+ * - **Do NOT hand-build an annotator** — no grid of your own, no hover or
185
+ * scroll script, no margin dots, no bottom bar, no toggle state. This
186
+ * component is all of it: pass `blocks`, `notes` and `kinds`.
187
+ * - **Do NOT set the defaults in a `useEffect` or hide notes with your own
188
+ * CSS.** `kinds[].defaultOn` is read in the FIRST render, so
189
+ * `renderToString`/prerender already ships a default-off kind with the HTML
190
+ * `hidden` attribute and its switch reading off; the desktop/phone split is
191
+ * CSS (`cm.hiddenBelow('md')` / `cm.hiddenFrom('md')`).
192
+ * - **Do NOT render the body as one HTML string.** Pass one block per
193
+ * top-level markdown block (paragraph, heading, list, code), each with a
194
+ * stable `id` — the example renders each provenance span with
195
+ * `@molecule/app-markdown`. The component adds no markup inside a block.
196
+ * - **Do NOT make one note per paragraph.** Make ONE note per prompt (or per
197
+ * section summary) and put its id in the `noteIds` of every block it covers:
198
+ * it shows once, beside the first. Consecutive blocks with the same
199
+ * `noteIds` form one row.
200
+ * - **Do NOT add a second copy of the notes for phones** (inline between
201
+ * paragraphs, a popover). The bar is the phone's copy.
202
+ * - **Do NOT import `@molecule/api-*` packages into the page** — they are
203
+ * server-only. The page reads what the build wrote (`provenance.json`, or
204
+ * spans passed to the prerender).
205
+ * - The example needs `@molecule/app-markdown` and a markdown bond
206
+ * (`@molecule/app-markdown-marked`), bonded once at startup:
207
+ * `setProvider(provider)`.
208
+ * - Section notes follow the reader; paragraph notes wait for a tap. On a
57
209
  * phone the panel shows the kinds with `panel: 'follow'` (the default) for
58
- * the section in view. Give a kind that is about ONE paragraph (a prompt, a
59
- * citation) `panel: 'tap'`: it shows when that paragraph is tapped and goes
60
- * on the second tap.
61
- * - **Controlled or not.** Pass `shownKinds` + `onShownKindsChange` to own the
210
+ * the section in view. A kind about ONE paragraph (a prompt, a citation)
211
+ * gets `panel: 'tap'`: while its switch is off it shows only when that
212
+ * paragraph is tapped (and goes on the second tap); once its switch is ON it
213
+ * follows the section in view like a `'follow'` kind, so the switch always
214
+ * shows something.
215
+ * - The mark is drawn on the block, as an absolutely-placed dot inside the
216
+ * block's own wrapper (hidden on phones). At rest a marked block is typeset
217
+ * exactly like an unmarked one.
218
+ * - Controlled or not: pass `shownKinds` + `onShownKindsChange` to own the
62
219
  * switches' state (e.g. to remember it); otherwise the component does.
63
220
  * - The phone bar reserves space at the end of the text so it never covers the
64
221
  * last paragraph. UI strings come from the companion locale bond
65
- * `@molecule/app-locales-margin-notes`; kind labels and `markLabel` are yours
66
- * to translate.
222
+ * `@molecule/app-locales-margin-notes`; kind labels and `markLabel` are
223
+ * yours to translate.
67
224
  *
68
225
  * @module
69
226
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AAEH,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiOG;AAEH,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -12,58 +12,215 @@
12
12
  * fixed to the bottom that shows the notes for the section being read and
13
13
  * follows the reader; tapping a paragraph pins its notes, tapping again lets
14
14
  * go; the switches live in the bar. A document with no notes renders centred
15
- * prose at full measure with no notes column.
15
+ * prose at full measure with no notes column, no switches and no bar.
16
+ *
17
+ * The example is a complete static-site post body: it takes the post's
18
+ * `provenance.json` (written at build time by `@molecule/api-text-provenance`,
19
+ * whose example produces exactly this shape) and a TL;DR per section, and
20
+ * renders every block with a summary beside its section (switch ON), the prompt
21
+ * beside the AI paragraphs it wrote (switch OFF), a margin mark on each AI
22
+ * paragraph, the AI-share line, and the phone bar — all correct in the
23
+ * prerendered HTML before any JavaScript runs.
16
24
  *
17
25
  * @example
18
26
  * ```tsx
19
- * import { MarginNotes } from '@molecule/app-margin-notes-react'
27
+ * // PostBody.tsx — a post's body with notes beside it, rendered from the post's provenance.json
28
+ * // (written at build time by @molecule/api-text-provenance) and its section summaries.
29
+ * import type { JSX } from 'react'
30
+ *
31
+ * import {
32
+ * type MarginNote,
33
+ * type MarginNoteKind,
34
+ * MarginNotes,
35
+ * type MarginNotesBlock,
36
+ * } from '@molecule/app-margin-notes-react'
37
+ * import { requireProvider } from '@molecule/app-markdown'
38
+ * import { useTranslation } from '@molecule/app-react'
39
+ * import { getClassMap } from '@molecule/app-ui'
40
+ *
41
+ * // One entry of provenance.json's `spans`: a block of the post's markdown, in page order.
42
+ * export interface PostSpan {
43
+ * text: string
44
+ * origin: 'human' | 'ai'
45
+ * prompt?: string
46
+ * model?: string
47
+ * }
48
+ *
49
+ * // provenance.json, as the build wrote it.
50
+ * export interface PostProvenance {
51
+ * aiShare: number
52
+ * prompts: string[]
53
+ * spans: PostSpan[]
54
+ * }
55
+ *
56
+ * // The span indexes that start a section: 0 (the lead), then every heading at the post's
57
+ * // shallowest heading level. Key your summaries by these indexes.
58
+ * export function sectionStarts(spans: PostSpan[]): number[] {
59
+ * const level = (text: string): number => text.match(/^#{1,6}(?=\s)/)?.[0].length ?? 0
60
+ * const top = Math.min(...spans.map((span) => level(span.text) || 7))
61
+ * return spans.flatMap((span, i) => (i === 0 || level(span.text) === top ? [i] : []))
62
+ * }
63
+ *
64
+ * // summaries: TL;DR text per section, keyed by the section's start index from sectionStarts().
65
+ * export function PostBody({
66
+ * provenance,
67
+ * summaries = {},
68
+ * }: {
69
+ * provenance: PostProvenance
70
+ * summaries?: Record<number, string>
71
+ * }): JSX.Element {
72
+ * const cm = getClassMap()
73
+ * const { t } = useTranslation()
74
+ * const markdown = requireProvider()
75
+ * const label = cm.cn(cm.textSize('xs'), cm.uppercase, cm.trackingWide, cm.fontWeight('semibold'))
76
+ * const starts = new Set(sectionStarts(provenance.spans))
77
+ * const notes: MarginNote[] = []
78
+ * const promptNoteIds = new Map<string, string>()
79
+ * let summaryId: string | undefined
80
+ *
81
+ * const blocks: MarginNotesBlock[] = provenance.spans.map((span, i) => {
82
+ * if (starts.has(i)) {
83
+ * summaryId = summaries[i] ? `summary-${i}` : undefined
84
+ * if (summaryId) {
85
+ * notes.push({
86
+ * id: summaryId,
87
+ * kind: 'summary',
88
+ * content: (
89
+ * <>
90
+ * <p className={label}>{t('post.tldr', undefined, { defaultValue: 'TL;DR' })}</p>
91
+ * <p>{summaries[i]}</p>
92
+ * </>
93
+ * ),
94
+ * })
95
+ * }
96
+ * }
97
+ * const noteIds = summaryId ? [summaryId] : []
98
+ * if (span.origin === 'ai' && span.prompt) {
99
+ * let id = promptNoteIds.get(span.prompt)
100
+ * if (!id) {
101
+ * id = `prompt-${promptNoteIds.size}`
102
+ * promptNoteIds.set(span.prompt, id)
103
+ * notes.push({
104
+ * id,
105
+ * kind: 'prompt',
106
+ * content: (
107
+ * <>
108
+ * <p className={cm.cn(label, cm.textPrimary)}>
109
+ * {t(
110
+ * 'post.promptBy',
111
+ * { model: span.model ?? '' },
112
+ * { defaultValue: 'Prompt · {{model}}' },
113
+ * )}
114
+ * </p>
115
+ * <p className={cm.textPrimary}>{span.prompt}</p>
116
+ * </>
117
+ * ),
118
+ * })
119
+ * }
120
+ * noteIds.push(id)
121
+ * }
122
+ * return {
123
+ * id: `block-${i}`,
124
+ * content: <div dangerouslySetInnerHTML={{ __html: markdown.render(span.text).html }} />,
125
+ * noteIds,
126
+ * marked: span.origin === 'ai',
127
+ * }
128
+ * })
129
+ *
130
+ * const kinds: MarginNoteKind[] = [
131
+ * {
132
+ * id: 'summary',
133
+ * label: t('post.summaries', undefined, { defaultValue: 'Summaries' }),
134
+ * defaultOn: true,
135
+ * },
136
+ * {
137
+ * id: 'prompt',
138
+ * label: t('post.prompts', undefined, { defaultValue: 'Prompts' }),
139
+ * defaultOn: false,
140
+ * panel: 'tap',
141
+ * },
142
+ * ]
143
+ * const percent = Math.round(provenance.aiShare * 100)
144
+ * const count = provenance.prompts.length
145
+ * const share =
146
+ * count === 0
147
+ * ? t('post.allHuman', undefined, {
148
+ * defaultValue: 'Every word of this post was written by a person.',
149
+ * })
150
+ * : t(
151
+ * count === 1 ? 'post.aiShareOne' : 'post.aiShare',
152
+ * { percent, count },
153
+ * {
154
+ * defaultValue:
155
+ * count === 1
156
+ * ? '{{percent}}% of the words were written by an AI, from 1 prompt'
157
+ * : '{{percent}}% of the words were written by an AI, from {{count}} prompts',
158
+ * },
159
+ * )
160
+ *
161
+ * return (
162
+ * <div className={cm.prose}>
163
+ * <p
164
+ * className={cm.cn(cm.textCenter, cm.textMuted, cm.textSize('sm'))}
165
+ * data-mol-id="post-ai-share"
166
+ * >
167
+ * {share}
168
+ * </p>
169
+ * <MarginNotes
170
+ * blocks={blocks}
171
+ * notes={notes}
172
+ * kinds={kinds}
173
+ * markLabel={t('post.aiWritten', undefined, { defaultValue: 'Written with AI' })}
174
+ * />
175
+ * </div>
176
+ * )
177
+ * }
20
178
  *
21
- * // blocks: your rendered paragraphs, in order; notes: what goes beside them.
22
- * <MarginNotes
23
- * blocks={[
24
- * { id: 'p1', content: <p>Every post carries a map of who wrote what.</p>, noteIds: ['s1'] },
25
- * { id: 'p2', content: <p>The map is built from the session export.</p>, noteIds: ['s1', 'q1'], marked: true },
26
- * ]}
27
- * notes={[
28
- * { id: 's1', kind: 'summary', content: <p>How the map is made.</p> },
29
- * { id: 'q1', kind: 'prompt', content: <p>“explain the map” — claude-opus-4</p> },
30
- * ]}
31
- * kinds={[
32
- * { id: 'summary', label: t('post.summaries', undefined, { defaultValue: 'Summaries' }), defaultOn: true },
33
- * { id: 'prompt', label: t('post.prompts', undefined, { defaultValue: 'Prompts' }), defaultOn: false, panel: 'tap' },
34
- * ]}
35
- * markLabel={t('post.aiWritten', undefined, { defaultValue: 'Written with AI' })}
36
- * />
179
+ * // In the Post page, in place of the single dangerouslySetInnerHTML body:
180
+ * // <PostBody provenance={post.provenance} summaries={post.summaries} />
37
181
  * ```
38
182
  *
39
183
  * @remarks
40
- * - **Defaults are right before JavaScript runs.** Which kinds show comes from
41
- * `kinds[].defaultOn` in the FIRST render (a hidden note carries the HTML
42
- * `hidden` attribute), and the desktop/phone split is CSS
43
- * (`cm.hiddenBelow('md')` / `cm.hiddenFrom('md')`). Prerender the page with
44
- * `renderToString` and a kind that defaults off is already absent; do NOT
45
- * toggle defaults in a `useEffect` of your own.
46
- * - **One note, one place.** A note shows beside the FIRST row that refers to
47
- * it. Give consecutive paragraphs that share a note the same `noteIds` and
48
- * they form one row with the note beside them once. A paragraph whose
49
- * `noteIds` differ from its neighbour's starts a new row.
50
- * - **The mark is drawn on the block**, as an absolutely-placed dot inside the
51
- * block's own wrapper (hidden on phones, where there is no margin). At rest a
52
- * marked block is typeset exactly like an unmarked one.
53
- * - **Pass rendered blocks, not markdown.** Split your renderer's output into
54
- * top-level blocks (one per paragraph/heading/list) and give each a stable
55
- * `id`; the component adds no markup inside them.
56
- * - **Section notes follow the reader; paragraph notes wait for a tap.** On a
184
+ * - **Do NOT hand-build an annotator** — no grid of your own, no hover or
185
+ * scroll script, no margin dots, no bottom bar, no toggle state. This
186
+ * component is all of it: pass `blocks`, `notes` and `kinds`.
187
+ * - **Do NOT set the defaults in a `useEffect` or hide notes with your own
188
+ * CSS.** `kinds[].defaultOn` is read in the FIRST render, so
189
+ * `renderToString`/prerender already ships a default-off kind with the HTML
190
+ * `hidden` attribute and its switch reading off; the desktop/phone split is
191
+ * CSS (`cm.hiddenBelow('md')` / `cm.hiddenFrom('md')`).
192
+ * - **Do NOT render the body as one HTML string.** Pass one block per
193
+ * top-level markdown block (paragraph, heading, list, code), each with a
194
+ * stable `id` — the example renders each provenance span with
195
+ * `@molecule/app-markdown`. The component adds no markup inside a block.
196
+ * - **Do NOT make one note per paragraph.** Make ONE note per prompt (or per
197
+ * section summary) and put its id in the `noteIds` of every block it covers:
198
+ * it shows once, beside the first. Consecutive blocks with the same
199
+ * `noteIds` form one row.
200
+ * - **Do NOT add a second copy of the notes for phones** (inline between
201
+ * paragraphs, a popover). The bar is the phone's copy.
202
+ * - **Do NOT import `@molecule/api-*` packages into the page** — they are
203
+ * server-only. The page reads what the build wrote (`provenance.json`, or
204
+ * spans passed to the prerender).
205
+ * - The example needs `@molecule/app-markdown` and a markdown bond
206
+ * (`@molecule/app-markdown-marked`), bonded once at startup:
207
+ * `setProvider(provider)`.
208
+ * - Section notes follow the reader; paragraph notes wait for a tap. On a
57
209
  * phone the panel shows the kinds with `panel: 'follow'` (the default) for
58
- * the section in view. Give a kind that is about ONE paragraph (a prompt, a
59
- * citation) `panel: 'tap'`: it shows when that paragraph is tapped and goes
60
- * on the second tap.
61
- * - **Controlled or not.** Pass `shownKinds` + `onShownKindsChange` to own the
210
+ * the section in view. A kind about ONE paragraph (a prompt, a citation)
211
+ * gets `panel: 'tap'`: while its switch is off it shows only when that
212
+ * paragraph is tapped (and goes on the second tap); once its switch is ON it
213
+ * follows the section in view like a `'follow'` kind, so the switch always
214
+ * shows something.
215
+ * - The mark is drawn on the block, as an absolutely-placed dot inside the
216
+ * block's own wrapper (hidden on phones). At rest a marked block is typeset
217
+ * exactly like an unmarked one.
218
+ * - Controlled or not: pass `shownKinds` + `onShownKindsChange` to own the
62
219
  * switches' state (e.g. to remember it); otherwise the component does.
63
220
  * - The phone bar reserves space at the end of the text so it never covers the
64
221
  * last paragraph. UI strings come from the companion locale bond
65
- * `@molecule/app-locales-margin-notes`; kind labels and `markLabel` are yours
66
- * to translate.
222
+ * `@molecule/app-locales-margin-notes`; kind labels and `markLabel` are
223
+ * yours to translate.
67
224
  *
68
225
  * @module
69
226
  */
package/dist/rows.d.ts CHANGED
@@ -2,17 +2,37 @@ import type { MarginNote, MarginNotesBlock, MarginNotesRow } from './types.js';
2
2
  /**
3
3
  * Group blocks into layout rows and place each note once.
4
4
  *
5
- * A row is a run of consecutive blocks that refer to exactly the same set of
6
- * notes (a paragraph run sharing one note), or a run of consecutive blocks
7
- * with no notes. Each note is shown beside the FIRST row that refers to it and
8
- * never again, so a note covering several paragraphs — even ones that are not
9
- * next to each other — appears once on the page.
5
+ * A row runs for as long as its blocks are covered by a note it OPENED with: a
6
+ * section's summary (every block of the section refers to it) keeps the whole
7
+ * section in one row, and a note that first appears mid-row — a prompt behind
8
+ * one of the section's paragraphs — joins that row's gutter but does not
9
+ * extend the row. (A prompt that produced paragraphs in several sections once
10
+ * carried a row across the next heading, and that section's summary was drawn
11
+ * beside the previous section.) A sticky note is
12
+ * bounded by its row, so this is what keeps a summary pinned until its section
13
+ * ends; splitting the row wherever the note set changed released it after the
14
+ * first paragraph. A run of blocks with no notes is a row of its own. Each note
15
+ * is shown once, in the first row that refers to it.
10
16
  *
11
17
  * @param blocks - The text, in reading order.
12
18
  * @param notes - Every note the blocks refer to; ids with no note are ignored.
13
19
  * @returns The rows, in reading order.
14
20
  */
15
21
  export declare function buildRows(blocks: MarginNotesBlock[], notes?: MarginNote[]): MarginNotesRow[];
22
+ /**
23
+ * One note per act of writing: when consecutive blocks each carry their own
24
+ * note with the same kind and the same plain-text content (one prompt that produced three
25
+ * paragraphs, recorded as three notes), every later block is pointed at the
26
+ * first block's note instead. {@link buildRows} places each note once, so the
27
+ * prompt is shown once, beside the first paragraph it produced, and hovering
28
+ * any of those paragraphs highlights that one note. The same text appearing
29
+ * again after a block without it is a new act, and keeps its own note.
30
+ *
31
+ * @param blocks - The text, in reading order.
32
+ * @param notes - Every note the blocks refer to.
33
+ * @returns The blocks, with repeated notes pointed at the first copy.
34
+ */
35
+ export declare function mergeRepeatedNotes(blocks: MarginNotesBlock[], notes?: MarginNote[]): MarginNotesBlock[];
16
36
  /**
17
37
  * The kinds shown before the reader touches a switch.
18
38
  *
@@ -1 +1 @@
1
- {"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE9E;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,KAAK,GAAE,UAAU,EAAO,GAAG,cAAc,EAAE,CA0BhG;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,GAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,EAAO,GAAG,MAAM,EAAE,CAE7F"}
1
+ {"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE9E;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,KAAK,GAAE,UAAU,EAAO,GAAG,cAAc,EAAE,CAoChG;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,gBAAgB,EAAE,EAC1B,KAAK,GAAE,UAAU,EAAO,GACvB,gBAAgB,EAAE,CAyBpB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,GAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,EAAO,GAAG,MAAM,EAAE,CAE7F"}