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

47 lines
2.5 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { applySuggestion, isRewrite, suggestMedia, wordDiff, proseParagraphs } from '@bitbaum/writingkit';
const fields = { title: 'Old', excerpt: '', body: 'One two three. Four five.' };
test('a whole-field suggestion applies only to the text it was made from', () => {
const s = { id: '1', field: 'title', label: 'Title', before: 'Old', after: 'New' };
assert.equal(applySuggestion(fields, s).title, 'New');
assert.equal(applySuggestion({ ...fields, title: 'Edited' }, s), null);
const options = { ...s, options: ['A', 'B'], after: 'A' };
assert.equal(applySuggestion(fields, options, 'B').title, 'B');
});
test('a selection suggestion replaces only its range, and refuses when the range moved', () => {
const s = { id: '2', field: 'body', label: 'Tighten', before: 'Four five.', after: 'Five.', start: 15, end: 25 };
assert.equal(applySuggestion(fields, s).body, 'One two three. Five.');
assert.equal(applySuggestion({ ...fields, body: 'X' + fields.body }, s), null);
const insert = { id: '3', field: 'body', label: 'Chart', before: '', after: '[c]', start: 14, end: 14 };
assert.equal(applySuggestion(fields, insert).body, 'One two three.[c] Four five.');
});
test('the diff rebuilds both sides exactly', () => {
const before = 'The quick brown fox jumps.';
const after = 'The fast brown fox leaps high.';
const parts = wordDiff(before, after);
const side = (skip) => parts.filter((p) => p.kind !== skip).map((p) => p.text).join('');
assert.equal(side('added'), before);
assert.equal(side('removed'), after);
assert.ok(parts.some((p) => p.kind === 'added' && /fast/.test(p.text)));
});
test('numbers in a paragraph propose a chart beside it; prose proposes an illustration', () => {
const body = 'A story about a river.\n\nIn 2024 we sold 120 boxes, 340 in spring and 95 in winter.\n\n```chart\n{}\n```';
const hint = suggestMedia(body);
assert.equal(hint.kind, 'chart');
assert.match(hint.paragraph.text, /120 boxes/);
assert.equal(body.slice(0, hint.paragraph.end).endsWith('winter.'), true);
assert.equal(suggestMedia('Only words here.\n\nMore words, since 2019.').kind, 'illustration');
assert.equal(proseParagraphs('## Head\n\n![a](b)\n\nText').length, 1);
});
test('a diff where most of the text goes is a rewrite', () => {
assert.equal(isRewrite(wordDiff('a b c d', 'a b c e')), false);
assert.equal(isRewrite(wordDiff('one two three', 'something else entirely')), true);
});