@plannotator/ui 0.47.0 → 0.49.0
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/HANDOFF.md +79 -0
- package/README.md +33 -1
- package/components/AnnotationPanel.tsx +44 -3
- package/components/BlockRenderer.tsx +55 -1
- package/components/CompletionOverlay.tsx +23 -1
- package/components/PRPlatformIcon.tsx +22 -0
- package/components/QuestionProgressChip.tsx +66 -0
- package/components/QuestionsPanelSection.tsx +121 -0
- package/components/Settings.tsx +25 -1
- package/components/Viewer.tsx +169 -6
- package/components/ai/AIProviderBar.tsx +3 -3
- package/components/blocks/QuestionBlock.tsx +591 -0
- package/config/settings.ts +17 -0
- package/hooks/useAnnotationHighlighter.ts +4 -0
- package/hooks/usePinpoint.ts +10 -0
- package/hooks/useScrollKeyRouting.ts +157 -0
- package/hooks/useUndoHistory.ts +17 -0
- package/hooks/useVimDocumentFocus.ts +2 -1
- package/package.json +2 -2
- package/styles.css +1 -1
- package/types.ts +3 -0
- package/utils/autoUpdateNotice.ts +59 -0
- package/utils/parser.ts +125 -563
- package/utils/questionAnswers.ts +227 -0
package/HANDOFF.md
CHANGED
|
@@ -189,6 +189,8 @@ We deliberately did **not** restructure the exports map in this PR (move-don't-r
|
|
|
189
189
|
| `theme` / `styles.css` | Theme tokens + precompiled stylesheet. **Prefer `styles.css`.** The raw `theme` export still `@import`s KaTeX (re-acquiring the fonts `styles.css` deliberately excludes, as separate lazy files) and contains Tailwind v4 `@theme` at-rules, so it's inert without Tailwind processing. |
|
|
190
190
|
| `types` | `Annotation`, `Block`, `AnnotationType`, etc. |
|
|
191
191
|
| `utils/parser` (`parseMarkdownToBlocks`, `exportAnnotations`) | Pure — no backend. |
|
|
192
|
+
| `utils/questionAnswers` (`upsertQuestionAnswerAnnotation`, `collectQuestionAnswers`, `resolveQuestionAnswers`, `questionAnswerToAnnotation`, `buildQuestionPanelRows`, `questionProgress`, `nextOpenQuestionKey`, `focusQuestionCard`) | Pure (except `focusQuestionCard`, which scrolls and focuses a card in the DOM). Applies `Viewer`'s `onAnswerQuestion` to your annotation list and derives the panel rows and progress (0.48.0; see "Questions in documents"). |
|
|
193
|
+
| `components/QuestionProgressChip`, `components/QuestionsPanelSection` | The header "N/M answered" chip and the panel's Questions section (0.48.0). `AnnotationPanel` renders the section itself when you pass `questionRows`. |
|
|
192
194
|
| `components/BlockRenderer` + the block components it renders (`TableBlock`, `HtmlBlock`, `Callout`, `MermaidBlock`, `MathBlock`, …) | Pure rendering. |
|
|
193
195
|
| `components/InlineMarkdown` | Code-file hover previews route through the `docPreviewFetcher` seam. Wiki-link rendering takes the sync `resolveLinkedDoc` prop (live labels + deleted-doc treatment; see "Wiki-link seams (0.27.0)"). |
|
|
194
196
|
| `components/Viewer` | The full annotatable document. Required props: `markdown` and `taterMode` (pass `false`). **Pass `disableCodePathValidation` unless you implement `/api/doc/exists`** — code-path validation is a prop-level opt-out, not a `configure` seam. `annotationHeader={{ onInputMethodChange, onModeChange, hideQuickLabel? }}` opts into one Viewer-owned, in-flow header containing the compact annotation controls and existing document actions. It reserves its measured responsive height, preserves all document badges, and follows `stickyActions` as one unit; omit it for the legacy action bar. Compact mode contains no help link. `hideQuickLabel` still requires the host to clamp restored mode state away from `'quickLabel'`. A host-owned scroll element must be supplied through `ScrollViewportProvider` (`hooks/useScrollViewport`) so stuck chrome and anchor clearance use the real scroller. |
|
|
@@ -1556,8 +1558,85 @@ Required by ui 0.47.0 (`components/ModelSourceHint` and `hooks/useModelCatalogs`
|
|
|
1556
1558
|
|
|
1557
1559
|
Minor rather than patch because of the new exports (`cliVersionFrom`, `ModelsSource`).
|
|
1558
1560
|
|
|
1561
|
+
## Questions in documents (0.48.0, core 0.25.8)
|
|
1562
|
+
|
|
1563
|
+
Additive. An agent can ask the reviewer questions inside a markdown document with a `:::question` directive, and the reviewer answers in place. The approved design is the "Card" variant: an eyebrow ("Question 2 of 4", "· pick any" on multi), a status tag (Open / ✓ Answered / Skipped / ✓ Settled), the prompt, its context, the choices, and a footer with Add note · Skip · a right-aligned **Accept recommended**.
|
|
1564
|
+
|
|
1565
|
+
```markdown
|
|
1566
|
+
:::question
|
|
1567
|
+
Where should losing conflict versions be kept?
|
|
1568
|
+
|
|
1569
|
+
Last-write-wins silently drops the loser unless we keep it somewhere.
|
|
1570
|
+
|
|
1571
|
+
- [ ] Local only, purged after 30 days — cheap, no server change
|
|
1572
|
+
- [ ] Server-side per user — survives reinstall, needs a retention policy
|
|
1573
|
+
|
|
1574
|
+
Recommended: Local only, purged after 30 days
|
|
1575
|
+
:::
|
|
1576
|
+
```
|
|
1577
|
+
|
|
1578
|
+
**`@plannotator/core/question-block` (new subpath, pure):**
|
|
1579
|
+
|
|
1580
|
+
- `parseQuestionBlock(directiveKind, body)` returns a `ParsedQuestion` or **null** when the block is not a question (no prompt, wrong kind, over `MAX_QUESTION_BODY_CHARS`). It never throws. It is tolerant: tight or spaced markdown, `-`/`*`/`+`/`1.` markers, plain bullets as choices when there are no task-list items, indented continuation lines, `Recommended:` / `**Recommended:**` / `Recommendation:` / `➡️` / `->` / `=>` / `→`, a `label — reason` recommendation, and a `,` / `;` / `and` list on multi questions. `- [x]` means **settled** (already decided), not recommended.
|
|
1581
|
+
- `indexQuestionBlocks(blocks)` numbers the document's question blocks, gives the prompt's document line, and de-duplicates keys (`-2`, `-3`…). It takes a structural block shape, so it works on your own block list.
|
|
1582
|
+
- `questionKey(kind, prompt)` = `q-` + an 8-hex FNV-1a hash of the kind and the normalized prompt. It is stable across versions while the prompt is unchanged. A reworded prompt is a new question.
|
|
1583
|
+
- `QuestionAnswer` (`{ v: 1, key, kind, prompt, selected: labels[], other?, text?, note?, skipped?, sourceLine? }`), `parseQuestionAnswer` (fail-closed: wrong types return null, strings are truncated to the caps), `isQuestionAnswered`, `isQuestionAnswerEmpty`, `recommendedQuestionAnswer`, `buildQuestionAnswerAnnotation` (structural record, `type: 'COMMENT'`).
|
|
1584
|
+
- `formatQuestionAnswersSection(items, answers, { headingLevel })`, `questionExportItems(index)`, `formatQuestionAnswerLines`, `formatQuestionAnswerText`.
|
|
1585
|
+
- `QUESTION_AUTHORING_GUIDE`: the syntax reference as one markdown string. Put it in your own agent prompts. Plannotator's `plannotator` skill carries the same text byte for byte (a test keeps them equal).
|
|
1586
|
+
|
|
1587
|
+
**`@plannotator/ui`:**
|
|
1588
|
+
|
|
1589
|
+
- `Annotation.questionAnswer?: QuestionAnswer`. An answer is ONE annotation, id `ann-question-<key>`, `blockId` = the question block, `originalText` = the prompt, `text` = a one-line answer (`Answer: Local only — note: …`), offsets 0. A consumer that does not know the field still reads it as a comment. Your annotation store and `draftTransport` carry it as opaque JSON. Nothing new to persist.
|
|
1590
|
+
- `Viewer` `onAnswerQuestion?(blockId, answer | null, key)`: the only new prop. The Viewer derives every card's state from its `annotations` prop (matched by key, so an answer follows its question across re-parses). On a change it calls the handler with the next answer, or `null` when the answer became empty. Apply it with `upsertQuestionAnswerAnnotation(annotations, blockId, answer, key)` (`utils/questionAnswers`; replaces in place and keeps `createdA`, appends when new, removes on null/empty). With no handler, or `readOnly`, the cards render disabled and still show stored answers.
|
|
1591
|
+
- `BlockRenderer` takes optional `question` / `questionTotal` / `questionAnswer` / `onAnswerQuestion`. Without them (plan diff, `RenderedMarkdown`) a question block is parsed alone and renders read-only and unnumbered.
|
|
1592
|
+
- `components/blocks/QuestionBlock` is exported for a host that renders blocks itself.
|
|
1593
|
+
- The highlighter skips rows carrying `questionAnswer` (neither painted nor attempted nor unanchored), the same rule `diagramAnchor` rows follow.
|
|
1594
|
+
- Exporters: `exportAnnotations` prints `## Answers to your questions` right after the title (before reference images and the numbered feedback): `N of M questions answered.`, one `### Q<n>. <prompt> (line L)` entry per answered, skipped or noted question (`Answer: X (your recommendation)`, a bullet list for several picks, a blockquote for free text, `Skipped`, `Note: …`), an `### Unanswered` list, and answers whose question is no longer in the document. Answers are not counted in "I've reviewed this plan and have N pieces of feedback". Questions the agent settled with `[x]` and the reviewer left alone are neither counted nor listed as unanswered. `exportLinkedDocAnnotations` prints the same section per document one level deeper; `exportAnnotationEntry` prints one answer. A row whose `questionAnswer` fails validation exports as an ordinary comment. A document with questions but no answers and no feedback still exports `No changes detected.`
|
|
1595
|
+
- Interaction: native `<input type=radio|checkbox>` inside a `<label>`. A click on a row picks only when the pointer moved less than 4 px (10 px touch) and no text is selected, so a drag across option text is an annotation, never a pick. The eyebrow, tags and footer are `annotation-exclude` / `select-none` / `data-pinpoint-ignore`; the prompt, context and choice text are not. "Other…" is always offered. There are no required questions and no new keyboard shortcuts.
|
|
1596
|
+
- Fallback: an unparseable block renders through the existing directive `Callout`; a ui older than 0.48.0 renders every `:::question` that way (the prompt and the task list as text).
|
|
1597
|
+
|
|
1598
|
+
**Progress, the panel and history (also 0.48.0, the editor PR):**
|
|
1599
|
+
|
|
1600
|
+
- `AnnotationPanel` `questionRows?` + `onSelectQuestion?`: pass `buildQuestionPanelRows(blocks, annotations)` and the panel renders a **Questions** section (progress, one row per question with its answer or "Not answered yet" and an Open / answered / Skipped state) above a **Comments** heading, and stops listing answer rows as comment cards. A row whose question is no longer in the document shows the Unanchored chip and a "Remove answer" link that calls your `onDelete(annotationId)`; it still exports. Without `questionRows` the panel is unchanged (answers list as comment cards, as in the first 0.48.0 cut).
|
|
1601
|
+
- `QuestionProgressChip` (`done`, `total`, `hasOpen`, `onJump`): the header "N/M answered" chip. `questionProgress(rows)` counts answered and settled questions; `nextOpenQuestionKey(rows, afterKey)` walks the open ones in document order and wraps; `focusQuestionCard(key)` scrolls the card to the centre and focuses its first control.
|
|
1602
|
+
- Core: `questionStatus(question, answer)` is the one status rule (answered / skipped / settled / open) the card, the rows and the chip share. The export counts a settled `[x]` question the reviewer only added a note to as answered, printing its settled choice with the note, and a multi-line note keeps its line breaks as a blockquote.
|
|
1603
|
+
- Card fixes: a double-click on a word in an option selects the word and takes back the pick its first click made; in pinpoint input mode a click on option text pins the text and does not pick the option (a click on the radio itself answers and does not pin); the free-text, "Other…" and note fields are `annotation-exclude`, so a text-search restore never lands inside typed text.
|
|
1604
|
+
- History: `useUndoHistory` gains `replaceLast(expected, next)` (fold into the newest entry while it is still the one you recorded). Plannotator records one entry per answer change and folds a typing burst into one; a host with its own history can do the same.
|
|
1605
|
+
|
|
1606
|
+
**No `configurePlannotatorUI` seam** is involved. Plannotator's server does not change.
|
|
1607
|
+
|
|
1608
|
+
**guides.show:** the viewer JS is unchanged, but the shared stylesheet gained the card's utility classes, so `guide-viewer-manifest.ts` pins a new CSS hash. Deploy guides.show before a release that ships this manifest.
|
|
1609
|
+
|
|
1610
|
+
## Question host seams (ui 0.49.0, core 0.25.9)
|
|
1611
|
+
|
|
1612
|
+
Additive. What a host that keeps question answers ITSELF needs (Workspaces stores answers beside the document as structured records, not as Plannotator annotations, and turns some answers into project decisions). Plannotator passes none of the new props: its cards render exactly as in 0.48.0, except that a block carrying a `Decision:` line now shows it (below).
|
|
1613
|
+
|
|
1614
|
+
**`@plannotator/core/question-block`:**
|
|
1615
|
+
|
|
1616
|
+
- **Decision lines.** A `Decision:` line after the prompt, at the start of a line (no indentation), is read once per block and kept out of `context`:
|
|
1617
|
+
- `Decision: when answered` (case-insensitive, trailing period allowed) sets `ParsedQuestion.decisionOnAnswer: true`: the asker flags that the answer should become a recorded decision.
|
|
1618
|
+
- `Decision: [statement](url)` (exactly one markdown link, absolute `http:`/`https:` only) sets `ParsedQuestion.decision: { statement, url }` (`QuestionDecisionLink`): the decision exists. When both lines are present the link wins and `decisionOnAnswer` is absent.
|
|
1619
|
+
- Any other `Decision:` value (a relative or `javascript:` link, prose around the link, a second flag line) stays context prose. A `Decision:` line BEFORE the prompt is the prompt, as before. Neither form changes `questionKey`, so adding, removing or replacing the line never orphans an answer.
|
|
1620
|
+
- An older Plannotator shows both lines as one line of context, which still reads correctly.
|
|
1621
|
+
- **`findQuestionBlocks(markdown, { frontmatter? })`** returns `QuestionBlockLocation[]`: `{ key, directiveKind, startLine, endLine, text }` per parseable question block in document order. Lines are 1-based lines of the original text (frontmatter counted); `endLine` is the closing `:::`, or the last line when the block is never closed (it then runs to the end, as it renders); `text` is the exact source of those lines. Keys are de-duplicated exactly like `indexQuestionBlocks` (`-2`, `-3`… for repeated prompts; one shared helper), so **always address a block by the returned key**. For a server that has to find or verify a question without the UI parser.
|
|
1622
|
+
- **`@plannotator/core/markdown-structure`** (new subpath): the block splitter's structural rules, moved out of `@plannotator/ui/utils/parser` so `findQuestionBlocks` and `parseMarkdownToBlocks` share one copy: `splitFrontmatter`, `resolveReferenceLinks`, `markProtectedLines`, `htmlBlockEndAt` / `findHtmlBlockEnd` / `HTML_BLOCK_TAGS`, `codeFenceCloseIndex`, `scanDisplayMath`, `DIRECTIVE_OPEN_RE` / `directiveCloseIndex`. `utils/parser` still exports `HTML_BLOCK_TAGS`, `resolveReferenceLinks` and `extractFrontmatter`, unchanged. A parity test (`packages/ui/utils/questionBlockParity.test.ts`) runs both over fenced, nested, quoted, HTML, math, frontmatter, reference-link, CRLF and unclosed cases and asserts the same keys and lines.
|
|
1623
|
+
|
|
1624
|
+
**`@plannotator/ui` (`Viewer`, forwarded through `BlockRenderer` to `QuestionBlock`):**
|
|
1625
|
+
|
|
1626
|
+
- **`questionAnswers?: ReadonlyMap<string, QuestionAnswer> | Record<string, QuestionAnswer>`**, keyed by the de-duplicated question key. When given, the cards read their answers from it and NEVER from `annotations` (an empty map means "no answers"); entries that fail `parseQuestionAnswer` are dropped. Absent: the annotation path, unchanged. The pure resolver is `resolveQuestionAnswers(annotations, hostAnswers?)` in `utils/questionAnswers`.
|
|
1627
|
+
- **`onSaveQuestionAnswer?(key, answer | null) => void | Promise<unknown>`**: explicit save mode, taking precedence over `onAnswerQuestion`. Edits stay a draft inside the card; while the draft differs from the host's answer the footer shows **Save answer** and **Cancel**, and **Skip is not offered** (skip is a live-mode draft state that a save never writes). Save calls the handler once with the key and the answer (null when the draft is empty); return a promise to keep the draft on screen until it settles, and a rejection keeps the draft for a retry (report the error yourself). Cancel returns to the host's `answer`. Ignored under `readOnly`.
|
|
1628
|
+
- **`saveQuestionAnswerLabel?: string | ((question: ParsedQuestion) => string)`**: the Save button's label in explicit save mode (e.g. "Save and record decision" for a flagged question). Default "Save answer". The card never picks a label from `decisionOnAnswer` itself: the host does the recording, so only the host may claim it.
|
|
1629
|
+
- **`renderQuestionFooter?(question: IndexedQuestion, answer: QuestionAnswer | undefined) => ReactNode`**: host actions at the right end of a card's footer (e.g. "Mark as decision"), given the SAVED answer, never the draft. Rendered in read-only cards too (return null for nothing). To make that work, read-only cards now disable each input instead of the whole `<fieldset>` (a disabled fieldset disables every button inside it); the fieldset carries `aria-disabled` instead.
|
|
1630
|
+
- **Decision display.** A flagged question shows a "Records a decision" tag in the eyebrow and a row under the prompt reading "Answering this records a decision"; a linked one shows a "Decision" tag and a row with the statement as a link to the URL (new tab, `noopener noreferrer`). The card carries `data-question-decision="on-answer" | "recorded"` and the row `data-question-decision-row`. The banner's "Don't record a decision" toggle and the guest/no-project variants in the Workspaces frames are host UI: put them in the footer slot.
|
|
1631
|
+
|
|
1632
|
+
**guides.show:** the viewer JS is unchanged, but the shared stylesheet gained the decision row's utility classes, so `guide-viewer-manifest.ts` pins a new CSS hash. Deploy guides.show before a release that ships this manifest.
|
|
1633
|
+
|
|
1634
|
+
Not here (dropped with the owner's Q2 answer): record lines inside the block (`Other:`, `Answer:`, `Note:`, `Answered:`) and a `writeQuestionAnswer` byte rewriter.
|
|
1635
|
+
|
|
1559
1636
|
## Publishing & versioning
|
|
1560
1637
|
|
|
1638
|
+
- **core 0.25.9 / ui 0.49.0 (question host seams): both change. Publish `core` first**: ui imports the new `@plannotator/core/markdown-structure` subpath and the new `findQuestionBlocks` / decision fields, so a ui on a published core 0.25.8 fails to compile in a consumer. See "Question host seams (ui 0.49.0, core 0.25.9)".
|
|
1639
|
+
- **core 0.25.8 / ui 0.48.0 (questions in documents): both change. Publish `core` 0.25.8 first, then `ui` 0.48.0**, which pins core `0.25.8` exactly and imports the new `@plannotator/core/question-block` subpath. Core is a patch bump because its change is additive and pre-1.0 caret ranges would not accept a minor. See "Questions in documents (0.48.0, core 0.25.8)".
|
|
1561
1640
|
- **core 0.25.7 / ui 0.47.0 (host link widgets + model source hint + `persistViewedFiles`): both packages change, and both need unpublished upstream packages first.** Order: `@plannotator/atomic-editor` 0.9.0, then `@plannotator/markdown-editor` 0.5.0, then `bun install` here to refresh `bun.lock`, then publish `core` 0.25.7, then `ui` 0.47.0. ui pins core `0.25.7` exactly, `@plannotator/atomic-editor` `^0.9.0` and `@plannotator/markdown-editor` `^0.5.0`. See "Host link widgets (0.47.0, core 0.25.7)".
|
|
1562
1641
|
- **ui 0.46.1 (fix, ui only, core pin unchanged at `0.25.6`):** `useVimSelection` (mounted by every `Viewer`) now only clears a page selection whose anchor or focus lies inside the viewer's own container; with vim off it used to clear the WHOLE page's selection on every mount and `contentVersion` change, so a selection in another host panel vanished whenever the document behind it loaded or changed.
|
|
1563
1642
|
- **ui 0.45.0 (annotation card header slot + mentions on the card's edit box): `@plannotator/ui` only — `@plannotator/core` is UNCHANGED at `0.25.5`, so this publishes alone** (core 0.25.5 must already be published). Purely additive over 0.44.0, both props on `AnnotationPanel`: `renderCardHeader` (the header-row twin of `renderCardFooter`, wrapper `[data-annotation-card-header]`, renders under `readOnly`, open-document cards only in the All-files view) and `mentionSource` (the 0.43.0 type, applied to the card's EDIT box, saving `onEdit(id, { text, mentions })` only when a source was supplied and a pick survived). Nothing is removed, no new supported imports (`components/MentionAutocomplete` is internal glue), no export-, share- or archive-visible change, and Plannotator passes neither — `packages/editor` and `packages/review-editor` have zero source diff, and the panel is byte-identical to 0.44.0. Known difference from `CommentPopover`: no chips in the card's edit box (follow-up named in the section). See "Annotation card header slot and mentions on the edit box (0.45.0)".
|
package/README.md
CHANGED
|
@@ -213,6 +213,14 @@ common case) applies inside the header too and pulls the action cluster out of
|
|
|
213
213
|
its row. Scope such rules away from the header, e.g.
|
|
214
214
|
`[data-viewer-document-header] [data-sticky-actions] { margin-top: 0; margin-right: 0; }`.
|
|
215
215
|
|
|
216
|
+
With `stickyActions` on, the legacy bar's `[data-sticky-actions]` cluster is no
|
|
217
|
+
longer the sticky element or a float: it pins inside a zero-height
|
|
218
|
+
`[data-sticky-actions-lane]`, beside a static float that reserves the title's
|
|
219
|
+
wrap space. Both copy the cluster's measured size and margins, so margin
|
|
220
|
+
overrides on `[data-sticky-actions]` still apply. Do not give the cluster
|
|
221
|
+
`position: sticky` and a float together: Firefox narrows float-avoiding blocks
|
|
222
|
+
such as table and code wrappers around a sticky float's stuck position.
|
|
223
|
+
|
|
216
224
|
The config is intentionally typed rather than a React-node slot. Viewer reuses
|
|
217
225
|
its existing `mode`, `inputMethod`, and `taterMode`; the config supplies only
|
|
218
226
|
the state-change callbacks and optional `hideQuickLabel`. Compact toolstrips
|
|
@@ -351,6 +359,30 @@ The engine that lets a browser-integrated agent (Chrome/Edge WebMCP, `document.m
|
|
|
351
359
|
|
|
352
360
|
The one additive data-model change that rides with it: `Annotation.inReplyTo` (threaded replies; the panel indents them under the parent, the export nests them, share links drop them).
|
|
353
361
|
|
|
362
|
+
### Questions in documents (`:::question`; 0.48.0, core 0.25.8)
|
|
363
|
+
|
|
364
|
+
An agent writes `:::question` (pick one), `:::question-multi` (pick any) or `:::question-text` (free text) blocks in a markdown document; `Viewer` renders each as an answer card (`components/blocks/QuestionBlock`) with native radios / checkboxes, an always-present "Other…", Add note · Skip · Accept recommended. Question and choice text stay selectable and annotatable; a drag across option text never picks it.
|
|
365
|
+
|
|
366
|
+
- **Grammar, key, answer shape, export section, authoring guide:** `@plannotator/core/question-block` (`parseQuestionBlock`, `indexQuestionBlocks`, `questionKey`, `QuestionAnswer`, `parseQuestionAnswer`, `formatQuestionAnswersSection`, `QUESTION_AUTHORING_GUIDE` — the syntax reference to put in your own agent prompts).
|
|
367
|
+
- **Storage is an annotation.** An answer is one row with `Annotation.questionAnswer` (id `ann-question-<key>`). The Viewer draws answers from its existing `annotations` prop, so your annotation persistence and `draftTransport` carry them unchanged.
|
|
368
|
+
- **One new optional prop:** `Viewer` `onAnswerQuestion?(blockId, answer | null, key)`. Apply it with `upsertQuestionAnswerAnnotation(annotations, blockId, answer, key)` from `utils/questionAnswers` and store the result. Without the prop (or under `readOnly`) the cards render read-only, still showing stored answers.
|
|
369
|
+
- **Export:** `exportAnnotations` / `exportLinkedDocAnnotations` / `exportAnnotationEntry` print answers in an "Answers to your questions" section before the numbered feedback, with no host action.
|
|
370
|
+
- An unparseable block (no prompt) renders as the ordinary directive callout; a ui older than 0.48.0 renders every `:::question` that way.
|
|
371
|
+
- **Progress and panel (optional):** pass `questionRows={buildQuestionPanelRows(blocks, annotations)}` to `AnnotationPanel` for the Questions section (answers then leave the comment timeline), and mount `QuestionProgressChip` with `questionProgress(rows)` / `nextOpenQuestionKey(rows)` / `focusQuestionCard(key)` for the "N/M answered" chip.
|
|
372
|
+
|
|
373
|
+
See HANDOFF.md § "Questions in documents (0.48.0, core 0.25.8)".
|
|
374
|
+
|
|
375
|
+
**A host that keeps answers itself (ui 0.49.0, core 0.25.9).** All optional on `Viewer`; Plannotator passes none of them:
|
|
376
|
+
|
|
377
|
+
- `questionAnswers` (Map or object keyed by the de-duplicated question key): the cards read answers from here instead of from `annotations`.
|
|
378
|
+
- `onSaveQuestionAnswer(key, answer | null)`: explicit save mode. Edits stay a draft in the card, which shows Save answer and Cancel (no Skip); return a promise to hold the draft until the save settles.
|
|
379
|
+
- `saveQuestionAnswerLabel` (string, or `(question) => string`): the Save button's label in explicit save mode. Default "Save answer"; never derived from `Decision: when answered`, since only the host knows whether its save records a decision.
|
|
380
|
+
- `renderQuestionFooter(question, savedAnswer)`: host actions at the right of the card's footer (e.g. "Mark as decision"), live in read-only cards too.
|
|
381
|
+
- Core reads a `Decision: when answered` line after the prompt as `ParsedQuestion.decisionOnAnswer` and a `Decision: [statement](https://…)` line as `ParsedQuestion.decision`; the card shows either. Neither changes the key.
|
|
382
|
+
- `findQuestionBlocks(markdown)` (core) locates each question block by key, line range and exact text, without the UI parser; it shares the block splitter's rules through the new `@plannotator/core/markdown-structure` subpath, so it agrees with what renders.
|
|
383
|
+
|
|
384
|
+
See HANDOFF.md § "Question host seams (ui 0.49.0, core 0.25.9)".
|
|
385
|
+
|
|
354
386
|
## Consuming it (e.g. from Workspaces)
|
|
355
387
|
|
|
356
388
|
```bash
|
|
@@ -374,7 +406,7 @@ npm install @plannotator/ui @plannotator/core
|
|
|
374
406
|
- `@plannotator/core` — pure utils + types, zero deps, browser-safe (CI enforces no `node:` imports). Published.
|
|
375
407
|
- `@plannotator/ui` — React components/hooks + theme + `configure()`. Depends on an exact published `@plannotator/core` version. Published.
|
|
376
408
|
- `@plannotator/shared`, `@plannotator/ai` — stay private to the monorepo; `shared` re-exports `core`'s modules via shims so Plannotator's internals are untouched.
|
|
377
|
-
- Currently `@plannotator/ui` 0.
|
|
409
|
+
- Currently `@plannotator/ui` 0.48.0 depends exactly on `@plannotator/core` 0.25.8. `core` is bumped only when something under `packages/core` changes, so `ui` can advance alone. Keep the published core version exact in `packages/ui/package.json`; do not use a `workspace:` protocol there, because a directly published manifest must remain installable outside this monorepo. Bun still links the matching local workspace during development. When both packages change, publish `core` first, then build and publish the UI tarball. See HANDOFF.md "Publishing & versioning" for the verification command.
|
|
378
410
|
|
|
379
411
|
## The one rule
|
|
380
412
|
|
|
@@ -13,6 +13,8 @@ import { cn } from '../lib/utils';
|
|
|
13
13
|
import { resolveReplyParents, resolveThreadRootTimestamps } from '@plannotator/core/annotation-threads';
|
|
14
14
|
import { ROOT_DOCUMENT_GROUP_KEY } from '../utils/annotationScope';
|
|
15
15
|
import type { AnnotationScope, AnnotationDocumentGroup } from '../utils/annotationScope';
|
|
16
|
+
import type { QuestionPanelRow } from '../utils/questionAnswers';
|
|
17
|
+
import { QuestionsPanelSection } from './QuestionsPanelSection';
|
|
16
18
|
|
|
17
19
|
// Card type-word colors. Deletion uses `destructive` (reliably red on every
|
|
18
20
|
// theme, matching the in-document .deletion highlight). Comment uses the
|
|
@@ -177,6 +179,16 @@ interface PanelProps {
|
|
|
177
179
|
onDeleteInDocument?: (path: string, id: string) => void;
|
|
178
180
|
/** Edit an annotation in its owning document's store. */
|
|
179
181
|
onEditInDocument?: (path: string, id: string, updates: Partial<Annotation>) => void;
|
|
182
|
+
/**
|
|
183
|
+
* `:::question` rows for the open document (`buildQuestionPanelRows`).
|
|
184
|
+
* Supplied, a Questions section renders above a Comments section and the
|
|
185
|
+
* answer annotations (rows carrying `questionAnswer`) leave the comment
|
|
186
|
+
* timeline; a row whose question is gone offers Remove through `onDelete`.
|
|
187
|
+
* Absent, the panel is unchanged and answers list as comment cards.
|
|
188
|
+
*/
|
|
189
|
+
questionRows?: readonly QuestionPanelRow[];
|
|
190
|
+
/** A Questions row was clicked (the host scrolls to the card). */
|
|
191
|
+
onSelectQuestion?: (row: QuestionPanelRow) => void;
|
|
180
192
|
}
|
|
181
193
|
|
|
182
194
|
export const AnnotationPanel: React.FC<PanelProps> = ({
|
|
@@ -212,13 +224,20 @@ export const AnnotationPanel: React.FC<PanelProps> = ({
|
|
|
212
224
|
onSelectInDocument,
|
|
213
225
|
onDeleteInDocument,
|
|
214
226
|
onEditInDocument,
|
|
227
|
+
questionRows,
|
|
228
|
+
onSelectQuestion,
|
|
215
229
|
}) => {
|
|
216
230
|
const isMobile = useIsMobile();
|
|
217
231
|
const embedded = presentation === 'embedded';
|
|
218
232
|
const mobilePanel = isMobile && !embedded;
|
|
219
233
|
const [copiedText, setCopiedText] = useState(false);
|
|
220
234
|
const listRef = useRef<HTMLDivElement>(null);
|
|
221
|
-
|
|
235
|
+
// With a Questions section, answers are listed there, not as comments.
|
|
236
|
+
const showQuestions = questionRows !== undefined && questionRows.length > 0;
|
|
237
|
+
const timelineAnnotations = questionRows !== undefined
|
|
238
|
+
? annotations.filter((a) => a.questionAnswer == null)
|
|
239
|
+
: annotations;
|
|
240
|
+
const sortedAnnotations = [...timelineAnnotations].sort((a, b) => a.createdA - b.createdA);
|
|
222
241
|
const sortedCodeAnnotations = [...codeAnnotations].sort((a, b) => a.createdAt - b.createdAt);
|
|
223
242
|
// Replies (`inReplyTo`) thread under their parent: each reply is lifted to
|
|
224
243
|
// sit right after its parent (and the parent's earlier replies) at the
|
|
@@ -237,6 +256,7 @@ export const AnnotationPanel: React.FC<PanelProps> = ({
|
|
|
237
256
|
return a.ts - b.ts;
|
|
238
257
|
});
|
|
239
258
|
const totalCount = annotations.length + codeAnnotations.length + (editorAnnotations?.length ?? 0);
|
|
259
|
+
const timelineCount = timelineAnnotations.length + codeAnnotations.length + (editorAnnotations?.length ?? 0);
|
|
240
260
|
|
|
241
261
|
// --- Cross-file scope (opt-in: a host that passes neither prop is unchanged) ---
|
|
242
262
|
const scopeEnabled = annotationScope !== undefined && onAnnotationScopeChange !== undefined;
|
|
@@ -383,11 +403,28 @@ export const AnnotationPanel: React.FC<PanelProps> = ({
|
|
|
383
403
|
{directEdits?.map((item) => (
|
|
384
404
|
<DirectEditsCard key={item.id} {...item} onDiscard={readOnly ? undefined : item.onDiscard} />
|
|
385
405
|
))}
|
|
406
|
+
{showQuestions && (
|
|
407
|
+
<>
|
|
408
|
+
<QuestionsPanelSection
|
|
409
|
+
rows={questionRows!}
|
|
410
|
+
onSelect={onSelectQuestion}
|
|
411
|
+
onRemoveOrphan={readOnly ? undefined : (row) => { if (row.annotationId) onDelete(row.annotationId); }}
|
|
412
|
+
/>
|
|
413
|
+
<div className="mx-0.5 mt-1 flex items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.07em] text-muted-foreground">
|
|
414
|
+
<span className="flex-1">Comments</span>
|
|
415
|
+
<span className="tabular-nums">{showGroups ? groupedTotal : timelineCount}</span>
|
|
416
|
+
</div>
|
|
417
|
+
</>
|
|
418
|
+
)}
|
|
386
419
|
{showGroups ? (
|
|
387
420
|
<>
|
|
388
421
|
{groups.map((group) => {
|
|
389
422
|
const collapsed = collapsedGroups.has(group.path);
|
|
390
|
-
|
|
423
|
+
// The open document's answers are in the Questions section.
|
|
424
|
+
const groupAnnotations = group.isCurrent && questionRows !== undefined
|
|
425
|
+
? group.annotations.filter((a) => a.questionAnswer == null)
|
|
426
|
+
: group.annotations;
|
|
427
|
+
const sorted = [...groupAnnotations].sort((a, b) => a.createdA - b.createdA);
|
|
391
428
|
const threaded = threadReplies(sorted);
|
|
392
429
|
return (
|
|
393
430
|
<section key={group.path} data-annotation-group={group.path}>
|
|
@@ -509,7 +546,11 @@ export const AnnotationPanel: React.FC<PanelProps> = ({
|
|
|
509
546
|
</button>
|
|
510
547
|
)}
|
|
511
548
|
</>
|
|
512
|
-
) :
|
|
549
|
+
) : timelineCount === 0 && showQuestions ? (
|
|
550
|
+
<p className="px-1 py-2.5 text-[12.5px] text-muted-foreground">
|
|
551
|
+
Select text in the document to comment. Question and option text is selectable too.
|
|
552
|
+
</p>
|
|
553
|
+
) : timelineCount === 0 ? (
|
|
513
554
|
(!directEdits || directEdits.length === 0) && (
|
|
514
555
|
<div className="flex flex-col items-center justify-center px-4 py-16 text-center">
|
|
515
556
|
<p className="text-xs text-muted-foreground/60">
|
|
@@ -8,6 +8,20 @@ import { Callout } from "./blocks/Callout";
|
|
|
8
8
|
import { AlertBlock } from "./blocks/AlertBlock";
|
|
9
9
|
import { TableBlock } from "./blocks/TableBlock";
|
|
10
10
|
import { MathBlock } from "./blocks/MathBlock";
|
|
11
|
+
import { QuestionBlock, type QuestionBlockProps } from "./blocks/QuestionBlock";
|
|
12
|
+
import {
|
|
13
|
+
indexQuestionBlocks,
|
|
14
|
+
isQuestionDirectiveKind,
|
|
15
|
+
type IndexedQuestion,
|
|
16
|
+
type QuestionAnswer,
|
|
17
|
+
} from "@plannotator/core/question-block";
|
|
18
|
+
|
|
19
|
+
/** A question block rendered outside a Viewer's document index (plan diff,
|
|
20
|
+
* other markdown surfaces): parsed alone, unnumbered. */
|
|
21
|
+
const standaloneQuestion = (block: Block): IndexedQuestion | undefined => {
|
|
22
|
+
const [indexed] = indexQuestionBlocks([block]);
|
|
23
|
+
return indexed ? { ...indexed, number: 0 } : undefined;
|
|
24
|
+
};
|
|
11
25
|
|
|
12
26
|
export const BlockRenderer: React.FC<{
|
|
13
27
|
block: Block;
|
|
@@ -22,7 +36,22 @@ export const BlockRenderer: React.FC<{
|
|
|
22
36
|
repoHost?: string;
|
|
23
37
|
headingAnchorId?: string;
|
|
24
38
|
onNavigateAnchor?: (hash: string) => void;
|
|
25
|
-
|
|
39
|
+
/** `:::question` blocks: this block's entry in the document's question
|
|
40
|
+
* index (numbering, key, prompt line) and the document's question count.
|
|
41
|
+
* Absent, a question block is parsed on its own and shows no "N of M". */
|
|
42
|
+
question?: IndexedQuestion;
|
|
43
|
+
questionTotal?: number;
|
|
44
|
+
/** The answer to draw (from the annotation carrying `questionAnswer`). */
|
|
45
|
+
questionAnswer?: QuestionAnswer;
|
|
46
|
+
/** Absent: question blocks render read-only. */
|
|
47
|
+
onAnswerQuestion?: (blockId: string, answer: QuestionAnswer | null, key: string) => void;
|
|
48
|
+
/** Explicit save mode for question cards (see `QuestionBlock`). */
|
|
49
|
+
onSaveQuestionAnswer?: QuestionBlockProps['onSaveAnswer'];
|
|
50
|
+
/** Label of the explicit-save-mode Save button (see `QuestionBlock`). */
|
|
51
|
+
saveQuestionAnswerLabel?: QuestionBlockProps['saveLabel'];
|
|
52
|
+
/** Host actions in a question card's footer (see `QuestionBlock`). */
|
|
53
|
+
renderQuestionFooter?: QuestionBlockProps['renderFooter'];
|
|
54
|
+
}> = ({ block, onOpenLinkedDoc, onOpenCodeFile, imageBaseDir, onImageClick, onToggleCheckbox, checkboxOverrides, orderedIndex, githubRepo, repoHost, headingAnchorId, onNavigateAnchor, question, questionTotal, questionAnswer, onAnswerQuestion, onSaveQuestionAnswer, saveQuestionAnswerLabel, renderQuestionFooter }) => {
|
|
26
55
|
switch (block.type) {
|
|
27
56
|
case 'heading': {
|
|
28
57
|
const Tag = `h${block.level || 1}` as React.ElementType;
|
|
@@ -135,6 +164,31 @@ export const BlockRenderer: React.FC<{
|
|
|
135
164
|
|
|
136
165
|
case 'directive': {
|
|
137
166
|
const kind = block.directiveKind || 'note';
|
|
167
|
+
if (isQuestionDirectiveKind(kind)) {
|
|
168
|
+
// An unparseable question (no prompt) falls through to the callout.
|
|
169
|
+
const indexed = question ?? standaloneQuestion(block);
|
|
170
|
+
if (indexed) {
|
|
171
|
+
return (
|
|
172
|
+
<QuestionBlock
|
|
173
|
+
blockId={block.id}
|
|
174
|
+
indexed={indexed}
|
|
175
|
+
total={questionTotal ?? 0}
|
|
176
|
+
answer={questionAnswer}
|
|
177
|
+
onAnswer={onAnswerQuestion}
|
|
178
|
+
onSaveAnswer={onSaveQuestionAnswer}
|
|
179
|
+
saveLabel={saveQuestionAnswerLabel}
|
|
180
|
+
renderFooter={renderQuestionFooter}
|
|
181
|
+
onOpenLinkedDoc={onOpenLinkedDoc}
|
|
182
|
+
onOpenCodeFile={onOpenCodeFile}
|
|
183
|
+
imageBaseDir={imageBaseDir}
|
|
184
|
+
onImageClick={onImageClick}
|
|
185
|
+
githubRepo={githubRepo}
|
|
186
|
+
repoHost={repoHost}
|
|
187
|
+
onNavigateAnchor={onNavigateAnchor}
|
|
188
|
+
/>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
138
192
|
return (
|
|
139
193
|
<Callout
|
|
140
194
|
blockId={block.id}
|
|
@@ -29,9 +29,15 @@ interface CompletionOverlayProps {
|
|
|
29
29
|
title: string;
|
|
30
30
|
subtitle: string;
|
|
31
31
|
agentLabel: string;
|
|
32
|
+
/**
|
|
33
|
+
* Optional destinations shown under the subtitle as ordinary links (opened
|
|
34
|
+
* in a new tab by a real click, so no popup blocker applies) — e.g. the PR
|
|
35
|
+
* a platform review was just posted to. Omitted or empty renders nothing.
|
|
36
|
+
*/
|
|
37
|
+
links?: ReadonlyArray<{ href: string; label: string }>;
|
|
32
38
|
}
|
|
33
39
|
|
|
34
|
-
export function CompletionOverlay({ submitted, title, subtitle, agentLabel }: CompletionOverlayProps) {
|
|
40
|
+
export function CompletionOverlay({ submitted, title, subtitle, agentLabel, links }: CompletionOverlayProps) {
|
|
35
41
|
const { state, enableAndStart } = useAutoClose(!!submitted);
|
|
36
42
|
|
|
37
43
|
if (!submitted) return null;
|
|
@@ -52,6 +58,22 @@ export function CompletionOverlay({ submitted, title, subtitle, agentLabel }: Co
|
|
|
52
58
|
<div className="space-y-2">
|
|
53
59
|
<h2 className="text-xl font-semibold text-foreground">{title}</h2>
|
|
54
60
|
<p className="text-muted-foreground">{subtitle}</p>
|
|
61
|
+
{links && links.length > 0 && (
|
|
62
|
+
<div className="flex flex-col items-center gap-1 pt-1">
|
|
63
|
+
{links.map((link) => (
|
|
64
|
+
<a
|
|
65
|
+
key={link.href}
|
|
66
|
+
href={link.href}
|
|
67
|
+
target="_blank"
|
|
68
|
+
rel="noopener noreferrer"
|
|
69
|
+
data-completion-link
|
|
70
|
+
className="text-sm font-medium text-primary underline-offset-4 hover:underline break-all"
|
|
71
|
+
>
|
|
72
|
+
{link.label}
|
|
73
|
+
</a>
|
|
74
|
+
))}
|
|
75
|
+
</div>
|
|
76
|
+
)}
|
|
55
77
|
</div>
|
|
56
78
|
|
|
57
79
|
<div className="pt-4 border-t border-border space-y-2">
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { GitHubIcon } from "./GitHubIcon";
|
|
3
|
+
import { GitLabIcon } from "./GitLabIcon";
|
|
4
|
+
|
|
5
|
+
/** Bitbucket bucket mark (simple-icons, CC0). Uses currentColor. */
|
|
6
|
+
export const BitbucketIcon: React.FC<{ className?: string }> = ({ className }) => (
|
|
7
|
+
<svg
|
|
8
|
+
className={className}
|
|
9
|
+
viewBox="0 0 24 24"
|
|
10
|
+
fill="currentColor"
|
|
11
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
12
|
+
>
|
|
13
|
+
<path d="M.778 1.213a.768.768 0 00-.768.892l3.263 19.81c.084.5.515.868 1.022.873H19.95a.772.772 0 00.77-.646l3.27-20.03a.768.768 0 00-.768-.891zM14.52 15.53H9.522L8.17 8.466h7.561z" />
|
|
14
|
+
</svg>
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
/** The mark of the platform a PR/MR lives on. Unknown platforms get GitHub's. */
|
|
18
|
+
export const PRPlatformIcon: React.FC<{ platform: string; className?: string }> = ({ platform, className }) => {
|
|
19
|
+
if (platform === "gitlab") return <GitLabIcon className={className} />;
|
|
20
|
+
if (platform === "bitbucket") return <BitbucketIcon className={className} />;
|
|
21
|
+
return <GitHubIcon className={className} />;
|
|
22
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { cn } from '../lib/utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The header "N/M answered" chip for documents with `:::question` blocks
|
|
6
|
+
* (the approved Card mock): a progress ring and the count. It is a button:
|
|
7
|
+
* a click jumps to the next open question. With no open question left it
|
|
8
|
+
* still reads the progress but has nothing to jump to.
|
|
9
|
+
*/
|
|
10
|
+
export interface QuestionProgressChipProps {
|
|
11
|
+
/** Answered or settled questions. */
|
|
12
|
+
done: number;
|
|
13
|
+
total: number;
|
|
14
|
+
/** Whether a question is still open (not answered, settled or skipped). */
|
|
15
|
+
hasOpen: boolean;
|
|
16
|
+
onJump: () => void;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const Ring: React.FC<{ done: number; total: number }> = ({ done, total }) => {
|
|
21
|
+
const r = 6;
|
|
22
|
+
const c = 2 * Math.PI * r;
|
|
23
|
+
const f = total > 0 ? done / total : 0;
|
|
24
|
+
const complete = total > 0 && done === total;
|
|
25
|
+
return (
|
|
26
|
+
<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" className="shrink-0">
|
|
27
|
+
<circle cx="8" cy="8" r={r} fill="none" stroke="var(--border)" strokeWidth="2.2" />
|
|
28
|
+
<circle
|
|
29
|
+
cx="8"
|
|
30
|
+
cy="8"
|
|
31
|
+
r={r}
|
|
32
|
+
fill="none"
|
|
33
|
+
stroke={complete ? 'var(--success)' : 'var(--primary)'}
|
|
34
|
+
strokeWidth="2.2"
|
|
35
|
+
strokeDasharray={`${c * f} ${c}`}
|
|
36
|
+
transform="rotate(-90 8 8)"
|
|
37
|
+
strokeLinecap="round"
|
|
38
|
+
/>
|
|
39
|
+
</svg>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const QuestionProgressChip: React.FC<QuestionProgressChipProps> = ({ done, total, hasOpen, onJump, className }) => {
|
|
44
|
+
if (total <= 0) return null;
|
|
45
|
+
const label = `${done} of ${total} question${total === 1 ? '' : 's'} answered.${hasOpen ? ' Go to next unanswered.' : ''}`;
|
|
46
|
+
return (
|
|
47
|
+
<button
|
|
48
|
+
type="button"
|
|
49
|
+
data-question-progress="true"
|
|
50
|
+
onClick={onJump}
|
|
51
|
+
aria-label={label}
|
|
52
|
+
title={hasOpen ? 'Go to the next open question' : done >= total ? 'All questions answered' : 'No open questions'}
|
|
53
|
+
className={cn(
|
|
54
|
+
'inline-flex h-7 shrink-0 items-center gap-[7px] whitespace-nowrap rounded-full border border-border bg-card pl-[7px] pr-2.5 text-xs text-muted-foreground transition-colors',
|
|
55
|
+
'hover:border-primary/50 hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring',
|
|
56
|
+
className,
|
|
57
|
+
)}
|
|
58
|
+
>
|
|
59
|
+
<Ring done={done} total={total} />
|
|
60
|
+
<span>
|
|
61
|
+
<b className="font-semibold text-foreground">{done}/{total}</b>
|
|
62
|
+
<span className="hidden md:inline"> answered</span>
|
|
63
|
+
</span>
|
|
64
|
+
</button>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { cn } from '../lib/utils';
|
|
3
|
+
import { questionProgress, type QuestionPanelRow } from '../utils/questionAnswers';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The annotations panel's Questions section (the approved Card mock): a
|
|
7
|
+
* header with the progress count, a thin progress bar, and one row per
|
|
8
|
+
* `:::question` block with its answer or "Not answered yet" and an
|
|
9
|
+
* Open / answered state. A row whose question is no longer in the document
|
|
10
|
+
* carries the Unanchored chip; its answer still exports.
|
|
11
|
+
*/
|
|
12
|
+
const CheckIcon = () => (
|
|
13
|
+
<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="2.2" aria-hidden="true" className="text-success">
|
|
14
|
+
<path d="m3.5 8.5 3 3 6-7" strokeLinecap="round" strokeLinejoin="round" />
|
|
15
|
+
</svg>
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const StateTag: React.FC<{ row: QuestionPanelRow }> = ({ row }) => {
|
|
19
|
+
if (row.orphaned) {
|
|
20
|
+
return (
|
|
21
|
+
<span
|
|
22
|
+
data-annotation-unanchored="true"
|
|
23
|
+
className="whitespace-nowrap rounded px-1.5 py-0.5 text-[9px] font-medium bg-muted text-muted-foreground"
|
|
24
|
+
title="This question is no longer in the document. The answer is still sent."
|
|
25
|
+
>
|
|
26
|
+
Unanchored
|
|
27
|
+
</span>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
if (row.status === 'answered' || row.status === 'settled') {
|
|
31
|
+
return (
|
|
32
|
+
<span className="inline-flex" title={row.status === 'settled' ? 'Settled' : 'Answered'}>
|
|
33
|
+
<CheckIcon />
|
|
34
|
+
<span className="sr-only">{row.status === 'settled' ? 'Settled' : 'Answered'}</span>
|
|
35
|
+
</span>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
if (row.status === 'skipped') {
|
|
39
|
+
return <span className="whitespace-nowrap rounded bg-muted px-1.5 py-px text-[10px] font-semibold text-muted-foreground">Skipped</span>;
|
|
40
|
+
}
|
|
41
|
+
return (
|
|
42
|
+
<span className="whitespace-nowrap rounded border border-dashed border-border px-1.5 py-px text-[10px] font-semibold text-muted-foreground">
|
|
43
|
+
Open
|
|
44
|
+
</span>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export interface QuestionsPanelSectionProps {
|
|
49
|
+
rows: readonly QuestionPanelRow[];
|
|
50
|
+
onSelect?: (row: QuestionPanelRow) => void;
|
|
51
|
+
/** Remove an orphaned answer (its card is gone, so the panel is the only
|
|
52
|
+
* place to drop it). Absent: no remove control. */
|
|
53
|
+
onRemoveOrphan?: (row: QuestionPanelRow) => void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const QuestionsPanelSection: React.FC<QuestionsPanelSectionProps> = ({ rows, onSelect, onRemoveOrphan }) => {
|
|
57
|
+
const { done, total } = questionProgress(rows);
|
|
58
|
+
const complete = total > 0 && done === total;
|
|
59
|
+
return (
|
|
60
|
+
<section data-questions-panel="true" aria-label="Questions" className="mb-2">
|
|
61
|
+
<div className="mx-0.5 mb-2 mt-1 flex items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.07em] text-muted-foreground">
|
|
62
|
+
<span className="flex-1">Questions</span>
|
|
63
|
+
{total > 0 && <span className="tabular-nums">{done}/{total}</span>}
|
|
64
|
+
</div>
|
|
65
|
+
{total > 0 && (
|
|
66
|
+
<div className="mx-0.5 mb-2.5 h-1 overflow-hidden rounded-sm bg-muted" aria-hidden="true">
|
|
67
|
+
<i
|
|
68
|
+
className={cn('block h-full rounded-sm', complete ? 'bg-success' : 'bg-primary')}
|
|
69
|
+
style={{ width: `${(done / total) * 100}%` }}
|
|
70
|
+
/>
|
|
71
|
+
</div>
|
|
72
|
+
)}
|
|
73
|
+
<div className="flex flex-col">
|
|
74
|
+
{rows.map((row) => {
|
|
75
|
+
const ok = !row.orphaned && (row.status === 'answered' || row.status === 'settled');
|
|
76
|
+
const summary = row.answerText ?? 'Not answered yet';
|
|
77
|
+
const clickable = !!onSelect && !row.orphaned;
|
|
78
|
+
const body = (
|
|
79
|
+
<>
|
|
80
|
+
<span className={cn('font-mono text-[10.5px] font-semibold leading-[1.6]', ok ? 'text-success' : 'text-muted-foreground')}>
|
|
81
|
+
{row.number ? `Q${row.number}` : 'Q'}
|
|
82
|
+
</span>
|
|
83
|
+
<span className="min-w-0 text-[12.5px] leading-[1.4] text-foreground">{row.prompt}</span>
|
|
84
|
+
<StateTag row={row} />
|
|
85
|
+
<span className={cn('col-start-2 col-end-4 text-xs', row.answerText && row.status !== 'skipped' ? 'text-foreground' : 'text-muted-foreground')}>
|
|
86
|
+
{summary}
|
|
87
|
+
{row.hasNote ? ' · has note' : ''}
|
|
88
|
+
</span>
|
|
89
|
+
</>
|
|
90
|
+
);
|
|
91
|
+
const rowClass = 'grid w-full grid-cols-[auto_1fr_auto] items-start gap-x-2 gap-y-0.5 rounded-[7px] px-2 py-2 text-left';
|
|
92
|
+
return clickable ? (
|
|
93
|
+
<button
|
|
94
|
+
key={row.key}
|
|
95
|
+
type="button"
|
|
96
|
+
data-question-row={row.key}
|
|
97
|
+
data-question-row-status={row.status}
|
|
98
|
+
onClick={() => onSelect!(row)}
|
|
99
|
+
className={cn(rowClass, 'cursor-pointer transition-colors hover:bg-muted focus-visible:outline-2 focus-visible:outline-ring')}
|
|
100
|
+
>
|
|
101
|
+
{body}
|
|
102
|
+
</button>
|
|
103
|
+
) : (
|
|
104
|
+
<div key={row.key} data-question-row={row.key} data-question-row-status={row.status} className={rowClass}>
|
|
105
|
+
{body}
|
|
106
|
+
{row.orphaned && onRemoveOrphan && (
|
|
107
|
+
<button
|
|
108
|
+
type="button"
|
|
109
|
+
onClick={() => onRemoveOrphan(row)}
|
|
110
|
+
className="col-start-2 col-end-4 justify-self-start text-[11px] text-muted-foreground underline-offset-2 hover:text-destructive hover:underline"
|
|
111
|
+
>
|
|
112
|
+
Remove answer
|
|
113
|
+
</button>
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
})}
|
|
118
|
+
</div>
|
|
119
|
+
</section>
|
|
120
|
+
);
|
|
121
|
+
};
|