Files
writingkit/dist/react/SuggestionCard.js
T
CatoandClaude Opus 5.5 0f3f481a3b feat: charts in articles and suggestions the writer accepts or rejects (0.3.0) (#14)
* feat: charts in articles and suggestions the writer accepts or rejects (0.3.0)

- ```chart blocks (JSON or CSV spec): parseChartBlock, splitChartBlocks,
  table fallbacks for RSS/share cards (chartsToTables), chartValuesNotInText
  so a proposed chart draws only the writer's own numbers
- @bitbaum/writingkit/react/chart: ArticleChart / ArticleChartBlock drawn by
  @bitbaum/chartkit (new optional peer)
- Suggestion, applySuggestion (refuses stale text), wordDiff, SuggestionCard
- suggestMedia: a chart beside the paragraph with figures, else an illustration
- ArticleComposer: renderChart in Preview; draft-from-brief is a suggestion

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvT2nQyPBK4EfWf3Rn

* feat(chart): read bip-kit's series-line format too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvT2nQyPBK4EfWf3Rn

* fix(suggestions): show a rewrite whole; keep Publish the one primary action

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvT2nQyPBK4EfWf3Rn

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-15 02:26:30 +01:00

33 lines
2.7 KiB
JavaScript

"use client";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useState } from "react";
import { isRewrite, wordDiff } from "../suggest.js";
export const DEFAULT_SUGGESTION_LABELS = {
heading: (label) => `Suggestion: ${label}`,
accept: "Use this",
reject: "Keep mine",
pick: "Pick one",
replaces: "Replaces your text:",
added: "added",
removed: "removed",
};
/**
* A proposal from writing help, shown as what changes (or, when most of the
* text changes, as the new text whole). Both buttons are equal cells: the
* screen's one primary action stays Publish. Nothing reaches the
* text until the writer taps "Use this"; "Keep mine" drops it. Options (a few
* titles) are one list of equal rows, the first chosen. The host applies the
* choice with `applySuggestion`, which refuses when the text moved on.
*/
export function SuggestionCard({ suggestion, onAccept, onReject, busy = false, labels: overrides, }) {
const labels = { ...DEFAULT_SUGGESTION_LABELS, ...overrides };
const options = suggestion.options?.length
? suggestion.options
: [suggestion.after];
const [chosen, setChosen] = useState(0);
const after = options[chosen] ?? suggestion.after;
const parts = wordDiff(suggestion.before, after);
const whole = suggestion.before === "" || isRewrite(parts);
return (_jsxs("section", { className: "wk-suggestion", "aria-label": labels.heading(suggestion.label), children: [_jsx("h2", { className: "wk-panel-title", children: labels.heading(suggestion.label) }), options.length > 1 ? (_jsxs("fieldset", { className: "wk-options", children: [_jsx("legend", { className: "wk-meta", children: labels.pick }), options.map((option, i) => (_jsxs("label", { className: "wk-option", children: [_jsx("input", { type: "radio", name: `wk-suggestion-${suggestion.id}`, checked: chosen === i, onChange: () => setChosen(i) }), _jsx("span", { children: option })] }, `${i}-${option}`)))] })) : (_jsx("div", { className: "wk-diff", children: whole ? (_jsxs(_Fragment, { children: [suggestion.before !== "" && (_jsxs("span", { className: "wk-meta wk-replaces", children: [labels.replaces, " "] })), _jsx("ins", { children: after })] })) : (parts.map((part, i) => part.kind === "same" ? (_jsx("span", { children: part.text }, i)) : part.kind === "added" ? (_jsx("ins", { title: labels.added, children: part.text }, i)) : (_jsx("del", { title: labels.removed, children: part.text }, i)))) })), _jsxs("div", { className: "wk-actions-row", children: [_jsx("button", { type: "button", className: "wk-btn", disabled: busy, onClick: () => onAccept(after), children: labels.accept }), _jsx("button", { type: "button", className: "wk-btn", disabled: busy, onClick: onReject, children: labels.reject })] })] }));
}