@lemonriver/core 1.1.0 → 1.2.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/dist/{build-Dm7gVRhb.js → build-CSkdswfd.js} +1 -1
- package/dist/cli/bin.js +5 -5
- package/dist/{config-CubOIzrs.js → config-C5-myPY6.js} +129 -2
- package/dist/{dev-DgLeXPqp.js → dev-DHtYH8sw.js} +2 -2
- package/dist/{mcp-CjYDzcJa.js → mcp-B2UeO1un.js} +1 -1
- package/dist/{preview-CxXQpPk5.js → preview-C1B6-umF.js} +1 -1
- package/dist/{update-b1dSg_FW.js → update-DzL8fpcI.js} +1 -1
- package/dist/vite/index.js +1 -1
- package/package.json +5 -2
- package/release-notes.json +19 -0
- package/src/app/lemonriver/chrome/app-chrome.tsx +52 -0
- package/src/app/lemonriver/chrome/sidebar-extras.tsx +8 -1
- package/src/app/lemonriver/feedback/dialog.tsx +222 -0
- package/src/app/lemonriver/feedback/export.ts +21 -2
- package/src/app/lemonriver/feedback/first-success.ts +30 -0
- package/src/app/lemonriver/feedback/install.ts +18 -0
- package/src/app/lemonriver/feedback/model.ts +88 -0
- package/src/app/lemonriver/help/help-page.tsx +16 -1
- package/src/app/lemonriver/links.ts +16 -0
- package/src/app/lemonriver/settings/backup-section.tsx +13 -0
- package/src/app/lemonriver/settings/settings-page.tsx +20 -0
- package/src/app/lemonriver/share/editor-share.tsx +6 -3
- package/src/app/lemonriver/share/share-dialog.tsx +2 -0
- package/src/app/lemonriver/text/en.ts +45 -0
- package/src/app/lemonriver/text/es.ts +42 -0
- package/src/app/lemonriver/text/ja.ts +41 -0
- package/src/app/lemonriver/text/types.ts +44 -0
- package/src/app/lemonriver/text/zh-cn.ts +45 -0
- package/src/app/lemonriver/text/zh-tw.ts +45 -0
- package/src/app/lemonriver/theme/pages.ts +4 -0
- package/src/app/lemonriver/update/release-notes.ts +22 -0
- package/src/app/lemonriver/update/update-prompt.tsx +28 -4
- package/src/app/components/note-markdown.test.tsx +0 -42
- package/src/app/components/thumbnail-rail-scroll.test.ts +0 -60
- package/src/app/lemonriver/agent-prefs/prefs.test.ts +0 -173
- package/src/app/lemonriver/backup/guide.test.ts +0 -45
- package/src/app/lemonriver/backup/model.test.ts +0 -108
- package/src/app/lemonriver/backup/places.test.ts +0 -154
- package/src/app/lemonriver/board/blocks/classify.test.ts +0 -209
- package/src/app/lemonriver/board/layout.test.ts +0 -245
- package/src/app/lemonriver/board/model/agent-tasks.test.ts +0 -200
- package/src/app/lemonriver/board/model/apply-prompt.test.ts +0 -121
- package/src/app/lemonriver/board/model/cards.test.ts +0 -332
- package/src/app/lemonriver/board/model/changes.test.ts +0 -244
- package/src/app/lemonriver/board/model/filter.test.ts +0 -50
- package/src/app/lemonriver/board/model/history.test.ts +0 -71
- package/src/app/lemonriver/board/model/restructure.test.ts +0 -205
- package/src/app/lemonriver/board/model/self-check.test.ts +0 -329
- package/src/app/lemonriver/board/model/structure.test.ts +0 -350
- package/src/app/lemonriver/board/model/timing.test.ts +0 -113
- package/src/app/lemonriver/features.test.ts +0 -49
- package/src/app/lemonriver/feedback/pending-toast.test.ts +0 -44
- package/src/app/lemonriver/feedback/upload.test.ts +0 -26
- package/src/app/lemonriver/help/model.test.ts +0 -179
- package/src/app/lemonriver/home/brief.test.ts +0 -38
- package/src/app/lemonriver/home/drafts.test.ts +0 -23
- package/src/app/lemonriver/home/sorting.test.ts +0 -24
- package/src/app/lemonriver/home/time.test.ts +0 -33
- package/src/app/lemonriver/outline/files.test.ts +0 -90
- package/src/app/lemonriver/outline/model.test.ts +0 -751
- package/src/app/lemonriver/public-links.test.ts +0 -32
- package/src/app/lemonriver/routes.test.tsx +0 -54
- package/src/app/lemonriver/share/codes.test.ts +0 -49
- package/src/app/lemonriver/share/compare.test.ts +0 -199
- package/src/app/lemonriver/share/folder.test.ts +0 -42
- package/src/app/lemonriver/share/guide.test.ts +0 -78
- package/src/app/lemonriver/share/naming.test.ts +0 -70
- package/src/app/lemonriver/share/paths.test.ts +0 -116
- package/src/app/lemonriver/share/pdf.test.ts +0 -79
- package/src/app/lemonriver/templates/knobs.test.ts +0 -62
- package/src/app/lemonriver/templates/model.test.ts +0 -175
- package/src/app/lemonriver/templates/preview-content.test.ts +0 -117
- package/src/app/lemonriver/templates/recommend.test.ts +0 -71
- package/src/app/lemonriver/text/text.test.ts +0 -90
- package/src/app/lemonriver/theme/pages.test.ts +0 -74
- package/src/app/lemonriver/theme/themes.test.ts +0 -18
- package/src/app/lemonriver/trash/api.test.ts +0 -19
- package/src/app/lemonriver/update/prompt.test.ts +0 -84
- package/src/app/lemonriver/update/version.test.ts +0 -14
- package/src/app/lib/asset-filter.test.ts +0 -176
- package/src/app/lib/inspector/fiber.test.ts +0 -154
- package/src/app/lib/inspector/geometry.test.ts +0 -324
- package/src/app/lib/inspector/text-edit-timeline.test.ts +0 -121
- package/src/app/lib/note-markdown.test.ts +0 -147
- package/src/app/lib/pptx/css.test.ts +0 -205
- package/src/app/lib/pptx/ooxml.test.ts +0 -199
- package/src/app/lib/pptx/text-lines.test.ts +0 -82
- package/src/app/lib/print-ready.test.ts +0 -32
- package/src/app/lib/sdk.test.ts +0 -13
- package/src/app/lib/transition.test.ts +0 -31
- package/src/app/lib/use-document-title.test.ts +0 -14
- package/src/app/lib/utils.test.ts +0 -49
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
chapterPlanPrompt,
|
|
4
|
-
chapterWritePrompt,
|
|
5
|
-
pageTaskPrompt,
|
|
6
|
-
parseChapterBlock,
|
|
7
|
-
sanitizeTask,
|
|
8
|
-
stripChapterBlock,
|
|
9
|
-
} from './agent-tasks.ts';
|
|
10
|
-
|
|
11
|
-
const page = { n: 3, title: 'Revenue by quarter' };
|
|
12
|
-
|
|
13
|
-
describe('pageTaskPrompt', () => {
|
|
14
|
-
const prompt = (action: 'rewrite' | 'chart' | 'memo' | 'expand', memo?: string) =>
|
|
15
|
-
pageTaskPrompt({ slideId: 'deck', page: { ...page, memo }, action, lang: 'en' });
|
|
16
|
-
|
|
17
|
-
it('names only the page it works on', () => {
|
|
18
|
-
expect(prompt('rewrite')).toContain(
|
|
19
|
-
'Work on page 3 "Revenue by quarter" of slides/deck/index.tsx only. Leave every other page, the theme and the speaker notes of other pages as they are.',
|
|
20
|
-
);
|
|
21
|
-
expect(prompt('rewrite')).toContain(
|
|
22
|
-
'Rewrite this page: keep what it says, make it clearer and better laid out.',
|
|
23
|
-
);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('asks for a chart that keeps the point', () => {
|
|
27
|
-
expect(prompt('chart')).toContain(
|
|
28
|
-
'Turn the main numbers on this page into a chart. Keep the title and the point it makes.',
|
|
29
|
-
);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('follows the card note', () => {
|
|
33
|
-
expect(prompt('memo', 'lead with the number')).toContain(
|
|
34
|
-
'Change this page as the note says: "lead with the number"',
|
|
35
|
-
);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('keeps a note’s quotes and newlines as one quoted string', () => {
|
|
39
|
-
const memo = 'Say "first"\nthen stop';
|
|
40
|
-
expect(prompt('memo', memo)).toContain(
|
|
41
|
-
`Change this page as the note says: ${JSON.stringify(memo)}`,
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('has nothing to say for a note action without a note', () => {
|
|
46
|
-
expect(prompt('memo')).toBeNull();
|
|
47
|
-
expect(prompt('memo', ' ')).toBeNull();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('asks for a second page right after this one', () => {
|
|
51
|
-
expect(prompt('expand')).toContain(
|
|
52
|
-
'Expand this page into two pages: keep this one, and add one more right after it that goes deeper. Add a speaker note for the new page.',
|
|
53
|
-
);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('ends with the language and one sentence back', () => {
|
|
57
|
-
expect(
|
|
58
|
-
prompt('rewrite')?.endsWith(
|
|
59
|
-
'Write in the language "en". When you are done, reply with one short sentence saying what changed.',
|
|
60
|
-
),
|
|
61
|
-
).toBe(true);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('leaves out the quotes when the page has no title', () => {
|
|
65
|
-
expect(
|
|
66
|
-
pageTaskPrompt({ slideId: 'd', page: { n: 2, title: '' }, action: 'rewrite', lang: 'en' }),
|
|
67
|
-
).toContain('Work on page 2 of slides/d/index.tsx only.');
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe('chapterPlanPrompt', () => {
|
|
72
|
-
it('plans without writing, and says what the chapter has', () => {
|
|
73
|
-
const prompt = chapterPlanPrompt({
|
|
74
|
-
slideId: 'deck',
|
|
75
|
-
chapter: 1,
|
|
76
|
-
title: 'Why now',
|
|
77
|
-
brief: 'the market moved',
|
|
78
|
-
count: 3,
|
|
79
|
-
pages: [
|
|
80
|
-
{ n: 4, title: 'The shift' },
|
|
81
|
-
{ n: 5, title: '' },
|
|
82
|
-
],
|
|
83
|
-
lang: 'zh-CN',
|
|
84
|
-
});
|
|
85
|
-
expect(prompt).toContain(
|
|
86
|
-
'Plan new pages for chapter 2 "Why now" of slides/deck/index.tsx. This turn is planning only: do not write, edit or create any file.',
|
|
87
|
-
);
|
|
88
|
-
expect(prompt).toContain('The chapter should cover: the market moved');
|
|
89
|
-
expect(prompt).toContain('It has these pages now: page 4 "The shift", page 5.');
|
|
90
|
-
expect(prompt).toContain('Plan 3 new pages that come after them.');
|
|
91
|
-
expect(prompt).toContain('<lemonriver-chapter> and </lemonriver-chapter>');
|
|
92
|
-
expect(prompt).toContain('Write in the language "zh-CN".');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('says so when the chapter is empty', () => {
|
|
96
|
-
const prompt = chapterPlanPrompt({
|
|
97
|
-
slideId: 'deck',
|
|
98
|
-
chapter: 0,
|
|
99
|
-
title: '',
|
|
100
|
-
brief: 'open',
|
|
101
|
-
count: 1,
|
|
102
|
-
pages: [],
|
|
103
|
-
lang: 'en',
|
|
104
|
-
});
|
|
105
|
-
expect(prompt).toContain('It has no pages yet.');
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('chapterWritePrompt', () => {
|
|
110
|
-
const items = [
|
|
111
|
-
{ id: 'a', title: 'First', kind: 'page' as const },
|
|
112
|
-
{ id: 'b', title: 'Second', kind: 'chart' as const },
|
|
113
|
-
];
|
|
114
|
-
|
|
115
|
-
it('places the pages after one page', () => {
|
|
116
|
-
const prompt = chapterWritePrompt({
|
|
117
|
-
slideId: 'deck',
|
|
118
|
-
chapter: 1,
|
|
119
|
-
title: 'Why now',
|
|
120
|
-
items,
|
|
121
|
-
anchor: { n: 4, title: 'The shift' },
|
|
122
|
-
lang: 'en',
|
|
123
|
-
});
|
|
124
|
-
expect(prompt).toContain(
|
|
125
|
-
'Add these pages to chapter 2 "Why now" of slides/deck/index.tsx, right after page 4 "The shift".',
|
|
126
|
-
);
|
|
127
|
-
expect(prompt).toContain('1. "First" (page)');
|
|
128
|
-
expect(prompt).toContain('2. "Second" (chart)');
|
|
129
|
-
expect(prompt).toContain(
|
|
130
|
-
"Follow the deck's existing theme and layout. Add a speaker note for each new page. Do not change any other page.",
|
|
131
|
-
);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('places them at the very start when there is nothing in front', () => {
|
|
135
|
-
const prompt = chapterWritePrompt({
|
|
136
|
-
slideId: 'deck',
|
|
137
|
-
chapter: 0,
|
|
138
|
-
title: '',
|
|
139
|
-
items,
|
|
140
|
-
anchor: null,
|
|
141
|
-
lang: 'en',
|
|
142
|
-
});
|
|
143
|
-
expect(prompt).toContain('of slides/deck/index.tsx, at the start of the deck.');
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe('chapter block', () => {
|
|
148
|
-
const block = (items: unknown) =>
|
|
149
|
-
`Planned.\n<lemonriver-chapter>${JSON.stringify(items)}</lemonriver-chapter>`;
|
|
150
|
-
|
|
151
|
-
it('reads the titles the agent planned', () => {
|
|
152
|
-
expect(parseChapterBlock(block([{ title: 'A', kind: 'page' }]))?.map((i) => i.title)).toEqual([
|
|
153
|
-
'A',
|
|
154
|
-
]);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('takes the last block, so a retried answer wins', () => {
|
|
158
|
-
const text = `${block([{ title: 'Old', kind: 'page' }])}\n${block([
|
|
159
|
-
{ title: 'New', kind: 'page' },
|
|
160
|
-
])}`;
|
|
161
|
-
expect(parseChapterBlock(text)?.map((i) => i.title)).toEqual(['New']);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('keeps no more than eight', () => {
|
|
165
|
-
const items = Array.from({ length: 10 }, (_, i) => ({ title: `P${i}`, kind: 'page' }));
|
|
166
|
-
expect(parseChapterBlock(block(items))).toHaveLength(8);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('reads nothing when there is no block, or the block is still streaming', () => {
|
|
170
|
-
expect(parseChapterBlock('no block here')).toBeNull();
|
|
171
|
-
expect(parseChapterBlock('Planning… <lemonriver-chapter>[{"title":')).toBeNull();
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('takes the block out of what the transcript shows', () => {
|
|
175
|
-
expect(stripChapterBlock(block([{ title: 'A', kind: 'page' }]))).toBe('Planned.');
|
|
176
|
-
expect(stripChapterBlock('Planning <lemonriver-chapter>[{"ti')).toBe('Planning');
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
describe('sanitizeTask', () => {
|
|
181
|
-
it('reads each kind of task', () => {
|
|
182
|
-
expect(sanitizeTask({ kind: 'changes' })).toEqual({ kind: 'changes' });
|
|
183
|
-
expect(sanitizeTask({ kind: 'page', page: 'Two', action: 'expand' })).toEqual({
|
|
184
|
-
kind: 'page',
|
|
185
|
-
page: 'Two',
|
|
186
|
-
action: 'expand',
|
|
187
|
-
});
|
|
188
|
-
expect(sanitizeTask({ kind: 'chapter-write', chapter: 1, title: 'Why now' })).toMatchObject({
|
|
189
|
-
kind: 'chapter-write',
|
|
190
|
-
chapter: 1,
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('refuses what it cannot run', () => {
|
|
195
|
-
expect(sanitizeTask(null)).toBeNull();
|
|
196
|
-
expect(sanitizeTask({ kind: 'page', page: 'Two', action: 'delete' })).toBeNull();
|
|
197
|
-
expect(sanitizeTask({ kind: 'chapter-plan', chapter: 0, count: 9 })).toBeNull();
|
|
198
|
-
expect(sanitizeTask({ kind: 'chapter-write', chapter: -1 })).toBeNull();
|
|
199
|
-
});
|
|
200
|
-
});
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { applyPrompt, type PromptPage } from './apply-prompt.ts';
|
|
3
|
-
import type { Placement, Spot } from './changes.ts';
|
|
4
|
-
import type { Restructure } from './restructure.ts';
|
|
5
|
-
|
|
6
|
-
const PAGES: PromptPage[] = [
|
|
7
|
-
{ key: 'a', n: 1, title: 'Cover' },
|
|
8
|
-
{ key: 'b', n: 2, title: 'Ask' },
|
|
9
|
-
{ key: 'c', n: 3, title: '' },
|
|
10
|
-
];
|
|
11
|
-
|
|
12
|
-
const spot = (page: string, before: string | null = null, beforeInfo?: Spot['beforeInfo']): Spot =>
|
|
13
|
-
beforeInfo ? { page, before, beforeInfo } : { page, before };
|
|
14
|
-
|
|
15
|
-
const move = (to: Spot | 'parked', extra: Partial<Placement> = {}): Placement => ({
|
|
16
|
-
origin: { page: 'a', before: null, block: 'x' },
|
|
17
|
-
block: { kind: 'chart', text: 'Revenue by quarter', loc: null },
|
|
18
|
-
to,
|
|
19
|
-
...extra,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
function prompt(changes: Placement[], restructures: Restructure[] = []): string {
|
|
23
|
-
return applyPrompt({ slideId: 'deck', pages: PAGES, changes, restructures });
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const lines = (changes: Placement[], restructures: Restructure[] = []): string[] =>
|
|
27
|
-
prompt(changes, restructures).split('\n');
|
|
28
|
-
|
|
29
|
-
describe('applyPrompt', () => {
|
|
30
|
-
it('opens with the file and the one rule, and closes with the speaker notes', () => {
|
|
31
|
-
const text = prompt([]);
|
|
32
|
-
expect(text.startsWith('Rearrange the deck slides/deck/index.tsx as listed below.')).toBe(true);
|
|
33
|
-
expect(text).toContain('keep every other page, the wording, the styles and the speaker notes');
|
|
34
|
-
expect(text.endsWith('reply with one short sentence saying what changed.')).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('names the block, both pages and the block it goes before', () => {
|
|
38
|
-
const [line] = lines([
|
|
39
|
-
move(spot('c', 'y', { kind: 'point', text: 'Margins held', loc: null })),
|
|
40
|
-
]).slice(1);
|
|
41
|
-
expect(line).toBe(
|
|
42
|
-
'Move the chart "Revenue by quarter" from page 1 "Cover" to page 3, before the point "Margins held".',
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('says where a block at the end goes', () => {
|
|
47
|
-
const [line] = lines([move(spot('b'))]).slice(1);
|
|
48
|
-
expect(line).toBe(
|
|
49
|
-
'Move the chart "Revenue by quarter" from page 1 "Cover" to page 2 "Ask", at the end.',
|
|
50
|
-
);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('removes a block the user set aside', () => {
|
|
54
|
-
const [line] = lines([move('parked')]).slice(1);
|
|
55
|
-
expect(line).toBe('Remove the chart "Revenue by quarter" from page 1 "Cover".');
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('hands back the code of a block coming out of the holding area', () => {
|
|
59
|
-
const text = prompt([
|
|
60
|
-
move(spot('b', 'y', { kind: 'point', text: 'Ask first', loc: null }), {
|
|
61
|
-
fromParking: true,
|
|
62
|
-
code: '<p>Saved</p>',
|
|
63
|
-
}),
|
|
64
|
-
]);
|
|
65
|
-
expect(text).toContain(
|
|
66
|
-
'Add this block to page 2 "Ask", before the point "Ask first". Its code, taken from the deck before it was set aside:',
|
|
67
|
-
);
|
|
68
|
-
expect(text).toContain('```tsx\n<p>Saved</p>\n```');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('splits a page by the blocks that leave it', () => {
|
|
72
|
-
const [line] = lines(
|
|
73
|
-
[],
|
|
74
|
-
[
|
|
75
|
-
{
|
|
76
|
-
kind: 'split',
|
|
77
|
-
page: 'c',
|
|
78
|
-
blocks: ['t', 'p'],
|
|
79
|
-
blockInfo: [
|
|
80
|
-
{ id: 't', kind: 'title', text: 'Plan' },
|
|
81
|
-
{ id: 'p', kind: 'point', text: 'Costs' },
|
|
82
|
-
],
|
|
83
|
-
},
|
|
84
|
-
],
|
|
85
|
-
).slice(1);
|
|
86
|
-
expect(line).toBe(
|
|
87
|
-
'Split page 3: move the title "Plan" and the point "Costs" onto a new page right after it.',
|
|
88
|
-
);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('merges a page into the one before it', () => {
|
|
92
|
-
const [line] = lines([], [{ kind: 'merge', pages: ['b', 'c'] }]).slice(1);
|
|
93
|
-
expect(line).toBe(
|
|
94
|
-
'Merge page 3 into page 2 "Ask": put the content of page 3 at the end of page 2 and remove page 3.',
|
|
95
|
-
);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('names a block that has no words of its own by its kind', () => {
|
|
99
|
-
const [line] = lines([
|
|
100
|
-
move(spot('b'), { block: { kind: 'image', text: '', loc: '9:4' } }),
|
|
101
|
-
]).slice(1);
|
|
102
|
-
expect(line).toBe('Move the image from page 1 "Cover" to page 2 "Ask", at the end.');
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('skips a change whose page is no longer in the deck', () => {
|
|
106
|
-
const text = prompt([
|
|
107
|
-
{
|
|
108
|
-
origin: { page: 'gone', before: null, block: 'x' },
|
|
109
|
-
block: { kind: 'text', text: 'Old', loc: null },
|
|
110
|
-
to: spot('b'),
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
origin: { page: 'a', before: null, block: 'z' },
|
|
114
|
-
block: { kind: 'text', text: 'Still here', loc: null },
|
|
115
|
-
to: 'parked',
|
|
116
|
-
},
|
|
117
|
-
]);
|
|
118
|
-
expect(text).not.toContain('Old');
|
|
119
|
-
expect(text).toContain('Still here');
|
|
120
|
-
});
|
|
121
|
-
});
|
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
adoptEntries,
|
|
4
|
-
type CardState,
|
|
5
|
-
carryCards,
|
|
6
|
-
entriesAfter,
|
|
7
|
-
isSettledKey,
|
|
8
|
-
linkCards,
|
|
9
|
-
linkedPairs,
|
|
10
|
-
originAfter,
|
|
11
|
-
type PageOp,
|
|
12
|
-
pageKeys,
|
|
13
|
-
patchCard,
|
|
14
|
-
sanitizeCards,
|
|
15
|
-
sanitizeLinks,
|
|
16
|
-
setLinkKind,
|
|
17
|
-
unlinkCards,
|
|
18
|
-
} from './cards.ts';
|
|
19
|
-
|
|
20
|
-
/** Runs one board operation the way the board does, entries and all. */
|
|
21
|
-
function run(state: CardState, entries: string[], op: PageOp) {
|
|
22
|
-
const count = entries.length;
|
|
23
|
-
const next = entriesAfter(op, entries, count);
|
|
24
|
-
const nextCount =
|
|
25
|
-
op.kind === 'delete'
|
|
26
|
-
? count - 1
|
|
27
|
-
: op.kind === 'deleteMany'
|
|
28
|
-
? count - op.indices.length
|
|
29
|
-
: op.kind === 'move' || op.kind === 'moveMany' || op.kind === 'reorder'
|
|
30
|
-
? count
|
|
31
|
-
: count + 1;
|
|
32
|
-
const carried = carryCards(
|
|
33
|
-
state,
|
|
34
|
-
pageKeys(entries, count),
|
|
35
|
-
pageKeys(next, nextCount),
|
|
36
|
-
originAfter(op, count),
|
|
37
|
-
);
|
|
38
|
-
return { state: carried, entries: next };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** The memo each position shows, which is what a user actually sees. */
|
|
42
|
-
const memos = (state: CardState, entries: string[] | null | undefined, count: number) =>
|
|
43
|
-
pageKeys(entries, count).map((key) => state.cards[key]?.memo ?? null);
|
|
44
|
-
|
|
45
|
-
const deck = ['Cover', 'Agenda', 'Q3', 'Close'];
|
|
46
|
-
|
|
47
|
-
describe('pageKeys', () => {
|
|
48
|
-
it('keys pages by their entry in the deck', () => {
|
|
49
|
-
expect(pageKeys(deck, 4)).toEqual(deck);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('tells repeated entries apart, so a duplicated page gets its own card', () => {
|
|
53
|
-
expect(pageKeys(['A', 'B', 'A', 'A'], 4)).toEqual(['A', 'B', 'A#2', 'A#3']);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('falls back to positions when the entries cannot be read one per page', () => {
|
|
57
|
-
expect(pageKeys(null, 3)).toEqual(['@0', '@1', '@2']);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('gives a deck caught mid-reload keys that match no card', () => {
|
|
61
|
-
const keys = pageKeys(['A', 'B'], 3);
|
|
62
|
-
expect(keys.every(isSettledKey)).toBe(false);
|
|
63
|
-
expect(pageKeys(undefined, 2).some(isSettledKey)).toBe(false);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('carryCards', () => {
|
|
68
|
-
const withMemo: CardState = { cards: { Q3: { memo: 'Q3 numbers missing' } }, links: [] };
|
|
69
|
-
|
|
70
|
-
it('keeps a memo on its page when the page moves', () => {
|
|
71
|
-
const after = run(withMemo, deck, { kind: 'move', from: 2, to: 0 });
|
|
72
|
-
expect(memos(after.state, after.entries, 4)).toEqual(['Q3 numbers missing', null, null, null]);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('keeps a memo on its page when the deck is reordered outside the board', () => {
|
|
76
|
-
// No operation runs: the thumbnail rail rewrote the file and the entries reload.
|
|
77
|
-
expect(memos(withMemo, ['Q3', 'Cover', 'Agenda', 'Close'], 4)[0]).toBe('Q3 numbers missing');
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('never shifts a memo onto the neighbour when a page is added before it', () => {
|
|
81
|
-
const after = run(withMemo, deck, { kind: 'insert', index: 1 });
|
|
82
|
-
expect(memos(after.state, after.entries, 5)).toEqual([
|
|
83
|
-
null,
|
|
84
|
-
null,
|
|
85
|
-
null,
|
|
86
|
-
'Q3 numbers missing',
|
|
87
|
-
null,
|
|
88
|
-
]);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('starts a duplicated page with a card of its own', () => {
|
|
92
|
-
const after = run(withMemo, deck, { kind: 'duplicate', index: 2 });
|
|
93
|
-
expect(memos(after.state, after.entries, 5)).toEqual([
|
|
94
|
-
null,
|
|
95
|
-
null,
|
|
96
|
-
'Q3 numbers missing',
|
|
97
|
-
null,
|
|
98
|
-
null,
|
|
99
|
-
]);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('lets the copy keep its own memo while the original moves around it', () => {
|
|
103
|
-
let state: CardState = {
|
|
104
|
-
cards: { A: { memo: 'first' }, 'A#2': { memo: 'second' } },
|
|
105
|
-
links: [],
|
|
106
|
-
};
|
|
107
|
-
let entries = ['A', 'B', 'A'];
|
|
108
|
-
({ state, entries } = run(state, entries, { kind: 'move', from: 0, to: 2 }));
|
|
109
|
-
expect(memos(state, entries, 3)).toEqual([null, 'second', 'first']);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('takes a deleted page’s card and links with it', () => {
|
|
113
|
-
const state: CardState = {
|
|
114
|
-
cards: { Q3: { memo: 'gone' }, Close: { memo: 'kept' } },
|
|
115
|
-
links: [{ a: 'Q3', b: 'Cover' }],
|
|
116
|
-
};
|
|
117
|
-
const after = run(state, deck, { kind: 'delete', index: 2 });
|
|
118
|
-
expect(after.state.cards).toEqual({ Close: { memo: 'kept' } });
|
|
119
|
-
expect(after.state.links).toEqual([]);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('does not hand a deleted copy’s memo to the original', () => {
|
|
123
|
-
const state: CardState = { cards: { 'A#2': { memo: 'copy only' } }, links: [] };
|
|
124
|
-
const after = run(state, ['A', 'A'], { kind: 'delete', index: 1 });
|
|
125
|
-
expect(memos(after.state, after.entries, 1)).toEqual([null]);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('re-keys every page when the deck is keyed by position', () => {
|
|
129
|
-
const state: CardState = { cards: { '@2': { memo: 'third page' } }, links: [] };
|
|
130
|
-
const op: PageOp = { kind: 'move', from: 2, to: 0 };
|
|
131
|
-
const carried = carryCards(state, pageKeys(null, 4), pageKeys(null, 4), originAfter(op, 4));
|
|
132
|
-
expect(memos(carried, null, 4)).toEqual(['third page', null, null, null]);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('leaves data for a page the deck does not have right now where it is', () => {
|
|
136
|
-
const state: CardState = { cards: { Gone: { memo: 'parked' } }, links: [] };
|
|
137
|
-
const after = run(state, deck, { kind: 'move', from: 0, to: 3 });
|
|
138
|
-
expect(after.state.cards.Gone).toEqual({ memo: 'parked' });
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('starts a new copy clean even when an earlier copy left data under the same key', () => {
|
|
142
|
-
// The first copy was deleted from the thumbnail rail, so its card was never cleared.
|
|
143
|
-
const state: CardState = {
|
|
144
|
-
cards: { 'A#2': { memo: 'old copy' } },
|
|
145
|
-
links: [{ a: 'A#2', b: 'B' }],
|
|
146
|
-
};
|
|
147
|
-
const after = run(state, ['A', 'B'], { kind: 'duplicate', index: 0 });
|
|
148
|
-
expect(memos(after.state, after.entries, 3)).toEqual([null, null, null]);
|
|
149
|
-
expect(after.state.links).toEqual([]);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('keeps a page’s own card when it is pushed onto a position that holds leftover data', () => {
|
|
153
|
-
// A deck keyed by position that once had five pages: "@4" is left over.
|
|
154
|
-
const state: CardState = {
|
|
155
|
-
cards: { '@3': { memo: 'last page' }, '@4': { memo: 'leftover' } },
|
|
156
|
-
links: [],
|
|
157
|
-
};
|
|
158
|
-
const op: PageOp = { kind: 'insert', index: 1 };
|
|
159
|
-
const carried = carryCards(state, pageKeys(null, 4), pageKeys(null, 5), originAfter(op, 4));
|
|
160
|
-
expect(memos(carried, null, 5)).toEqual([null, null, null, null, 'last page']);
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
describe('adoptEntries', () => {
|
|
165
|
-
it('moves a blank page’s memo onto the name the deck gave it', () => {
|
|
166
|
-
let state: CardState = { cards: {}, links: [] };
|
|
167
|
-
let entries: string[] = ['Cover', 'Close'];
|
|
168
|
-
({ state, entries } = run(state, entries, { kind: 'insert', index: 1 }));
|
|
169
|
-
const blankKey = pageKeys(entries, 3)[1];
|
|
170
|
-
state = { ...state, cards: { [blankKey]: { memo: 'draft me' } } };
|
|
171
|
-
|
|
172
|
-
const named = ['Cover', 'NewPage1', 'Close'];
|
|
173
|
-
const adopted = adoptEntries(state, entries, named);
|
|
174
|
-
expect(memos(adopted, named, 3)).toEqual([null, 'draft me', null]);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it('clears leftovers from an older page that used the same name', () => {
|
|
178
|
-
const state: CardState = {
|
|
179
|
-
cards: { NewPage1: { memo: 'stale' } },
|
|
180
|
-
links: [{ a: 'NewPage1', b: 'Cover' }],
|
|
181
|
-
};
|
|
182
|
-
const { entries } = run(state, ['Cover', 'Close'], { kind: 'insert', index: 1 });
|
|
183
|
-
const adopted = adoptEntries(state, entries, ['Cover', 'NewPage1', 'Close']);
|
|
184
|
-
expect(adopted.cards).toEqual({});
|
|
185
|
-
expect(adopted.links).toEqual([]);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('changes nothing when no blank page is waiting for a name', () => {
|
|
189
|
-
const state: CardState = { cards: { Cover: { memo: 'x' } }, links: [] };
|
|
190
|
-
expect(adoptEntries(state, deck, deck)).toBe(state);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
describe('links', () => {
|
|
195
|
-
it('records a link once, whichever way it is drawn', () => {
|
|
196
|
-
const links = linkCards(linkCards([], 'A', 'B'), 'B', 'A');
|
|
197
|
-
expect(links).toEqual([{ a: 'A', b: 'B' }]);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it('never links a card to itself', () => {
|
|
201
|
-
expect(linkCards([], 'A', 'A')).toEqual([]);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('removes a link drawn the other way round', () => {
|
|
205
|
-
expect(unlinkCards([{ a: 'A', b: 'B' }], 'B', 'A')).toEqual([]);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('follows both pages when the deck is reordered', () => {
|
|
209
|
-
const keys = ['Close', 'Cover', 'Q3', 'Agenda'];
|
|
210
|
-
expect(linkedPairs(keys, [{ a: 'Cover', b: 'Close' }])).toEqual([{ a: 1, b: 0 }]);
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it('hides a link whose page is not in the deck', () => {
|
|
214
|
-
expect(linkedPairs(deck, [{ a: 'Cover', b: 'Gone' }])).toEqual([]);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it('carries what two pages have to do with each other', () => {
|
|
218
|
-
const keys = ['Close', 'Cover'];
|
|
219
|
-
expect(linkedPairs(keys, [{ a: 'Cover', b: 'Close', kind: 'cause' }])).toEqual([
|
|
220
|
-
{ a: 1, b: 0, kind: 'cause' },
|
|
221
|
-
]);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('names a link without making a second one', () => {
|
|
225
|
-
const links = setLinkKind([{ a: 'A', b: 'B' }], 'B', 'A', 'cause');
|
|
226
|
-
expect(links).toEqual([{ a: 'A', b: 'B', kind: 'cause' }]);
|
|
227
|
-
expect(setLinkKind(links, 'A', 'B', null)).toEqual([{ a: 'A', b: 'B' }]);
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('keeps the kind when a page it points at moves', () => {
|
|
231
|
-
const after = run(
|
|
232
|
-
{ cards: {}, links: [{ a: 'Cover', b: 'Q3', kind: 'contrast' }] },
|
|
233
|
-
['Cover', 'Q3', 'Close'],
|
|
234
|
-
{ kind: 'move', from: 1, to: 0 },
|
|
235
|
-
);
|
|
236
|
-
expect(after.state.links).toEqual([{ a: 'Cover', b: 'Q3', kind: 'contrast' }]);
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
describe('patchCard', () => {
|
|
241
|
-
it('sets and clears fields one at a time', () => {
|
|
242
|
-
let cards = patchCard({}, 'A', { title: 'Market', status: 'doing' });
|
|
243
|
-
expect(cards).toEqual({ A: { title: 'Market', status: 'doing' } });
|
|
244
|
-
cards = patchCard(cards, 'A', { status: null });
|
|
245
|
-
expect(cards).toEqual({ A: { title: 'Market' } });
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it('drops a card once nothing is left on it', () => {
|
|
249
|
-
expect(patchCard({ A: { memo: 'x' } }, 'A', { memo: '' })).toEqual({});
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
describe('sanitize', () => {
|
|
254
|
-
it('keeps only the fields and statuses the board knows', () => {
|
|
255
|
-
expect(
|
|
256
|
-
sanitizeCards({
|
|
257
|
-
A: { title: ' Intro ', status: 'doing', extra: 1 },
|
|
258
|
-
B: { status: 'bogus' },
|
|
259
|
-
C: 'nope',
|
|
260
|
-
}),
|
|
261
|
-
).toEqual({ A: { title: 'Intro', status: 'doing' } });
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it('drops malformed and duplicate links', () => {
|
|
265
|
-
expect(sanitizeLinks([{ a: 'A', b: 'B' }, { a: 'B', b: 'A' }, { a: 'A' }, null])).toEqual([
|
|
266
|
-
{ a: 'A', b: 'B' },
|
|
267
|
-
]);
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
it('keeps a kind it knows and drops one it does not', () => {
|
|
271
|
-
expect(
|
|
272
|
-
sanitizeLinks([
|
|
273
|
-
{ a: 'A', b: 'B', kind: 'echo' },
|
|
274
|
-
{ a: 'B', b: 'C', kind: 'because' },
|
|
275
|
-
{ a: 'C', b: 'D' },
|
|
276
|
-
]),
|
|
277
|
-
).toEqual([
|
|
278
|
-
{ a: 'A', b: 'B', kind: 'echo' },
|
|
279
|
-
{ a: 'B', b: 'C' },
|
|
280
|
-
{ a: 'C', b: 'D' },
|
|
281
|
-
]);
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
describe('batch and structural operations', () => {
|
|
286
|
-
const state: CardState = {
|
|
287
|
-
cards: { Cover: { memo: 'one' }, Q3: { memo: 'two' }, Close: { memo: 'three' } },
|
|
288
|
-
links: [{ a: 'Q3', b: 'Close' }],
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
it('carries every card through a whole-deck reorder', () => {
|
|
292
|
-
const order = [3, 1, 0, 2];
|
|
293
|
-
const { state: next, entries } = run(state, deck, { kind: 'reorder', order });
|
|
294
|
-
expect(entries).toEqual(['Close', 'Agenda', 'Cover', 'Q3']);
|
|
295
|
-
expect(memos(next, entries, 4)).toEqual(['three', null, 'one', 'two']);
|
|
296
|
-
expect(next.links).toEqual([{ a: 'Q3', b: 'Close' }]);
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
it('keeps the relative order of several pages moved at once', () => {
|
|
300
|
-
const { state: next, entries } = run(state, deck, { kind: 'moveMany', moving: [0, 2], to: 3 });
|
|
301
|
-
expect(entries).toEqual(['Agenda', 'Close', 'Cover', 'Q3']);
|
|
302
|
-
expect(memos(next, entries, 4)).toEqual([null, 'three', 'one', 'two']);
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
it('drops the cards of every page removed at once', () => {
|
|
306
|
-
const { state: next, entries } = run(state, deck, { kind: 'deleteMany', indices: [0, 2] });
|
|
307
|
-
expect(entries).toEqual(['Agenda', 'Close']);
|
|
308
|
-
expect(memos(next, entries, 2)).toEqual([null, 'three']);
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
describe('restore', () => {
|
|
313
|
-
it('puts the page back under its own name, not a blank the deck must explain', () => {
|
|
314
|
-
const { entries } = run({ cards: {}, links: [] }, ['Cover', 'Q3', 'Close'], {
|
|
315
|
-
kind: 'restore',
|
|
316
|
-
index: 1,
|
|
317
|
-
entry: 'Agenda',
|
|
318
|
-
});
|
|
319
|
-
expect(entries).toEqual(deck);
|
|
320
|
-
expect(pageKeys(entries, 4).every(isSettledKey)).toBe(true);
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
it('lets a card written back under that name show up again', () => {
|
|
324
|
-
const { entries } = run({ cards: {}, links: [] }, ['Cover', 'Q3', 'Close'], {
|
|
325
|
-
kind: 'restore',
|
|
326
|
-
index: 1,
|
|
327
|
-
entry: 'Agenda',
|
|
328
|
-
});
|
|
329
|
-
const state = { cards: { Agenda: { memo: 'back' } }, links: [] };
|
|
330
|
-
expect(memos(state, entries, 4)).toEqual([null, 'back', null, null]);
|
|
331
|
-
});
|
|
332
|
-
});
|