Files
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

48 lines
2.7 KiB
JavaScript

import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
* `@bitbaum/writingkit/react/chart` — a ` ```chart ` block drawn by
* `@bitbaum/chartkit`, on the server or in the browser (no effect, no
* measurement). Its own entry so a product without chartkit can still use the
* composer; such a product passes nothing and readers get the table.
*
* import { ArticleChart, ArticleChartBlock } from "@bitbaum/writingkit/react/chart";
* import "@bitbaum/chartkit/styles.css";
*/
import { BarChart, ColumnChart, LineChart } from "@bitbaum/chartkit/react";
import { chartTable, drawnKind, parseChartBlock, } from "../chart.js";
export function ArticleChart({ chart, locale, height = 220, }) {
// chartkit prints the unit on the axis; the caption names and sources it.
const caption = chart.source
? `${chart.title}. Source: ${chart.source}`
: chart.title;
const kind = drawnKind(chart);
const drawing = kind === "ranking" ? (_jsx(BarChart, { rows: (chart.series[0]?.points ?? []).map(([label, value]) => ({
label,
value,
})), caption: caption, ...(chart.unit ? { unit: chart.unit } : {}), ...(locale ? { locale } : {}) })) : kind === "bar" ? (_jsx(ColumnChart, { series: chart.series.map((s, i) => ({
id: `s${i}`,
label: s.name,
points: s.points.map(([x, y]) => ({ x, y })),
})), caption: caption, height: height, ...(chart.unit ? { unit: chart.unit } : {}), ...(locale ? { locale } : {}) })) : (_jsx(LineChart, { series: chart.series.map((s, i) => ({
id: `s${i}`,
label: s.name,
points: s.points
.filter((p) => p[1] !== null)
.map(([x, y]) => ({ x: /^-?\d+(\.\d+)?$/.test(x) && !/^\d{4}$/.test(x) ? Number(x) : x, y })),
})), caption: caption, height: height, area: kind === "area", markers: "auto", ...(chart.unit ? { unit: chart.unit } : {}), ...(locale ? { locale } : {}) }));
// chartkit's own caption carries the title and the source: one caption,
// under the drawing, with the table behind it for screen readers.
return _jsx("div", { className: "wk-chart", children: drawing });
}
/**
* The text inside a ` ```chart ` fence, drawn; or, when it does not parse, the
* problem in words for the writer (`showProblem`) and nothing for a reader.
*/
export function ArticleChartBlock({ source, locale, showProblem = false, }) {
const parsed = parseChartBlock(source);
if (parsed.ok)
return _jsx(ArticleChart, { chart: parsed.chart, ...(locale ? { locale } : {}) });
return showProblem ? (_jsxs("p", { className: "wk-chart-problem", role: "note", children: ["This chart cannot be drawn yet: ", parsed.problem] })) : null;
}
export { chartTable };