@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.
Files changed (92) hide show
  1. package/dist/{build-Dm7gVRhb.js → build-CSkdswfd.js} +1 -1
  2. package/dist/cli/bin.js +5 -5
  3. package/dist/{config-CubOIzrs.js → config-C5-myPY6.js} +129 -2
  4. package/dist/{dev-DgLeXPqp.js → dev-DHtYH8sw.js} +2 -2
  5. package/dist/{mcp-CjYDzcJa.js → mcp-B2UeO1un.js} +1 -1
  6. package/dist/{preview-CxXQpPk5.js → preview-C1B6-umF.js} +1 -1
  7. package/dist/{update-b1dSg_FW.js → update-DzL8fpcI.js} +1 -1
  8. package/dist/vite/index.js +1 -1
  9. package/package.json +5 -2
  10. package/release-notes.json +19 -0
  11. package/src/app/lemonriver/chrome/app-chrome.tsx +52 -0
  12. package/src/app/lemonriver/chrome/sidebar-extras.tsx +8 -1
  13. package/src/app/lemonriver/feedback/dialog.tsx +222 -0
  14. package/src/app/lemonriver/feedback/export.ts +21 -2
  15. package/src/app/lemonriver/feedback/first-success.ts +30 -0
  16. package/src/app/lemonriver/feedback/install.ts +18 -0
  17. package/src/app/lemonriver/feedback/model.ts +88 -0
  18. package/src/app/lemonriver/help/help-page.tsx +16 -1
  19. package/src/app/lemonriver/links.ts +16 -0
  20. package/src/app/lemonriver/settings/backup-section.tsx +13 -0
  21. package/src/app/lemonriver/settings/settings-page.tsx +20 -0
  22. package/src/app/lemonriver/share/editor-share.tsx +6 -3
  23. package/src/app/lemonriver/share/share-dialog.tsx +2 -0
  24. package/src/app/lemonriver/text/en.ts +45 -0
  25. package/src/app/lemonriver/text/es.ts +42 -0
  26. package/src/app/lemonriver/text/ja.ts +41 -0
  27. package/src/app/lemonriver/text/types.ts +44 -0
  28. package/src/app/lemonriver/text/zh-cn.ts +45 -0
  29. package/src/app/lemonriver/text/zh-tw.ts +45 -0
  30. package/src/app/lemonriver/theme/pages.ts +4 -0
  31. package/src/app/lemonriver/update/release-notes.ts +22 -0
  32. package/src/app/lemonriver/update/update-prompt.tsx +28 -4
  33. package/src/app/components/note-markdown.test.tsx +0 -42
  34. package/src/app/components/thumbnail-rail-scroll.test.ts +0 -60
  35. package/src/app/lemonriver/agent-prefs/prefs.test.ts +0 -173
  36. package/src/app/lemonriver/backup/guide.test.ts +0 -45
  37. package/src/app/lemonriver/backup/model.test.ts +0 -108
  38. package/src/app/lemonriver/backup/places.test.ts +0 -154
  39. package/src/app/lemonriver/board/blocks/classify.test.ts +0 -209
  40. package/src/app/lemonriver/board/layout.test.ts +0 -245
  41. package/src/app/lemonriver/board/model/agent-tasks.test.ts +0 -200
  42. package/src/app/lemonriver/board/model/apply-prompt.test.ts +0 -121
  43. package/src/app/lemonriver/board/model/cards.test.ts +0 -332
  44. package/src/app/lemonriver/board/model/changes.test.ts +0 -244
  45. package/src/app/lemonriver/board/model/filter.test.ts +0 -50
  46. package/src/app/lemonriver/board/model/history.test.ts +0 -71
  47. package/src/app/lemonriver/board/model/restructure.test.ts +0 -205
  48. package/src/app/lemonriver/board/model/self-check.test.ts +0 -329
  49. package/src/app/lemonriver/board/model/structure.test.ts +0 -350
  50. package/src/app/lemonriver/board/model/timing.test.ts +0 -113
  51. package/src/app/lemonriver/features.test.ts +0 -49
  52. package/src/app/lemonriver/feedback/pending-toast.test.ts +0 -44
  53. package/src/app/lemonriver/feedback/upload.test.ts +0 -26
  54. package/src/app/lemonriver/help/model.test.ts +0 -179
  55. package/src/app/lemonriver/home/brief.test.ts +0 -38
  56. package/src/app/lemonriver/home/drafts.test.ts +0 -23
  57. package/src/app/lemonriver/home/sorting.test.ts +0 -24
  58. package/src/app/lemonriver/home/time.test.ts +0 -33
  59. package/src/app/lemonriver/outline/files.test.ts +0 -90
  60. package/src/app/lemonriver/outline/model.test.ts +0 -751
  61. package/src/app/lemonriver/public-links.test.ts +0 -32
  62. package/src/app/lemonriver/routes.test.tsx +0 -54
  63. package/src/app/lemonriver/share/codes.test.ts +0 -49
  64. package/src/app/lemonriver/share/compare.test.ts +0 -199
  65. package/src/app/lemonriver/share/folder.test.ts +0 -42
  66. package/src/app/lemonriver/share/guide.test.ts +0 -78
  67. package/src/app/lemonriver/share/naming.test.ts +0 -70
  68. package/src/app/lemonriver/share/paths.test.ts +0 -116
  69. package/src/app/lemonriver/share/pdf.test.ts +0 -79
  70. package/src/app/lemonriver/templates/knobs.test.ts +0 -62
  71. package/src/app/lemonriver/templates/model.test.ts +0 -175
  72. package/src/app/lemonriver/templates/preview-content.test.ts +0 -117
  73. package/src/app/lemonriver/templates/recommend.test.ts +0 -71
  74. package/src/app/lemonriver/text/text.test.ts +0 -90
  75. package/src/app/lemonriver/theme/pages.test.ts +0 -74
  76. package/src/app/lemonriver/theme/themes.test.ts +0 -18
  77. package/src/app/lemonriver/trash/api.test.ts +0 -19
  78. package/src/app/lemonriver/update/prompt.test.ts +0 -84
  79. package/src/app/lemonriver/update/version.test.ts +0 -14
  80. package/src/app/lib/asset-filter.test.ts +0 -176
  81. package/src/app/lib/inspector/fiber.test.ts +0 -154
  82. package/src/app/lib/inspector/geometry.test.ts +0 -324
  83. package/src/app/lib/inspector/text-edit-timeline.test.ts +0 -121
  84. package/src/app/lib/note-markdown.test.ts +0 -147
  85. package/src/app/lib/pptx/css.test.ts +0 -205
  86. package/src/app/lib/pptx/ooxml.test.ts +0 -199
  87. package/src/app/lib/pptx/text-lines.test.ts +0 -82
  88. package/src/app/lib/print-ready.test.ts +0 -32
  89. package/src/app/lib/sdk.test.ts +0 -13
  90. package/src/app/lib/transition.test.ts +0 -31
  91. package/src/app/lib/use-document-title.test.ts +0 -14
  92. package/src/app/lib/utils.test.ts +0 -49
@@ -1,244 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type { Block } from '../blocks/classify.ts';
3
- import {
4
- type BlockInfo,
5
- carryChanges,
6
- changedPages,
7
- effectiveBlocks,
8
- parkedBlocks,
9
- placeBlock,
10
- removeChange,
11
- sanitizeChanges,
12
- staleChanges,
13
- unparkBlock,
14
- } from './changes.ts';
15
-
16
- const block = (id: string, text = id): Block => ({
17
- id,
18
- kind: 'text',
19
- text,
20
- loc: null,
21
- box: { x: 0, y: 0, w: 10, h: 10 },
22
- });
23
-
24
- const info = (text: string): BlockInfo => ({ kind: 'text', text, loc: null });
25
- const at = (page: string, before: string | null, id: string) => ({ page, before, block: id });
26
-
27
- const A = [block('a1', 'Alpha page one'), block('a2', 'Opening content')];
28
- const B = [block('b1', 'Second page')];
29
-
30
- describe('placeBlock', () => {
31
- it('keeps one entry per block', () => {
32
- let changes = placeBlock([], at('p1', 'a2', 'a1'), info('Alpha page one'), {
33
- page: 'p2',
34
- before: null,
35
- });
36
- changes = placeBlock(changes, at('p1', 'a2', 'a1'), info('Alpha page one'), {
37
- page: 'p3',
38
- before: null,
39
- });
40
- expect(changes).toHaveLength(1);
41
- expect(changes[0].to).toEqual({ page: 'p3', before: null });
42
- });
43
-
44
- it('drops the entry when the block goes back where it was', () => {
45
- const changes = placeBlock([], at('p1', 'a2', 'a1'), info('Alpha page one'), {
46
- page: 'p1',
47
- before: 'a2',
48
- });
49
- expect(changes).toEqual([]);
50
- });
51
-
52
- it('keeps the code when parking', () => {
53
- const changes = placeBlock([], at('p1', 'a2', 'a1'), info('Alpha page one'), 'parked', '<h1/>');
54
- expect(changes[0].to).toBe('parked');
55
- expect(changes[0].code).toBe('<h1/>');
56
- });
57
- });
58
-
59
- describe('effectiveBlocks', () => {
60
- it('reorders inside a page', () => {
61
- const changes = placeBlock([], at('p1', 'a2', 'a2'), info('Opening content'), {
62
- page: 'p1',
63
- before: 'a1',
64
- });
65
- expect(effectiveBlocks('p1', A, changes).map((b) => b.id)).toEqual(['a2', 'a1']);
66
- });
67
-
68
- it('moves a block to the end of another page', () => {
69
- const changes = placeBlock([], at('p1', 'a2', 'a1'), info('Alpha page one'), {
70
- page: 'p2',
71
- before: null,
72
- });
73
- const one = effectiveBlocks('p1', A, changes);
74
- const two = effectiveBlocks('p2', B, changes);
75
- expect(one.map((b) => b.id)).toEqual(['a2']);
76
- expect(two.map((b) => b.id)).toEqual(['b1', 'a1']);
77
- expect(two[1]).toMatchObject({ pending: true, from: 'p1' });
78
- });
79
-
80
- it('puts the block last when its anchor is gone', () => {
81
- const changes = placeBlock([], at('p1', 'a2', 'a1'), info('Alpha page one'), {
82
- page: 'p2',
83
- before: 'gone',
84
- });
85
- expect(effectiveBlocks('p2', B, changes).map((b) => b.id)).toEqual(['b1', 'a1']);
86
- });
87
-
88
- it('inserts two blocks moved to the same page in order', () => {
89
- let changes = placeBlock([], at('p1', 'a2', 'a1'), info('a'), { page: 'p2', before: 'b1' });
90
- changes = placeBlock(changes, at('p3', null, 'c1'), info('c'), { page: 'p2', before: 'b1' });
91
- expect(effectiveBlocks('p2', B, changes).map((b) => b.id)).toEqual(['a1', 'c1', 'b1']);
92
- });
93
-
94
- it('takes a parked block off its page', () => {
95
- const changes = placeBlock([], at('p1', 'a2', 'a1'), info('a'), 'parked');
96
- expect(effectiveBlocks('p1', A, changes).map((b) => b.id)).toEqual(['a2']);
97
- });
98
- });
99
-
100
- describe('parkedBlocks and removeChange', () => {
101
- it('lists parked blocks in change order', () => {
102
- let changes = placeBlock([], at('p1', 'a2', 'a1'), info('a'), 'parked', 'x');
103
- changes = placeBlock(changes, at('p2', null, 'b1'), info('b'), 'parked', 'y');
104
- expect(parkedBlocks(changes).map((p) => p.origin.block)).toEqual(['a1', 'b1']);
105
- });
106
-
107
- it('removes one entry by its origin', () => {
108
- const changes = placeBlock([], at('p1', 'a2', 'a1'), info('a'), 'parked');
109
- expect(removeChange(changes, at('p1', 'a2', 'a1'))).toEqual([]);
110
- });
111
- });
112
-
113
- describe('carryChanges', () => {
114
- it('leaves a reorder alone, because a page key travels with its page', () => {
115
- const changes = placeBlock([], at('p1', 'a2', 'a1'), info('a'), { page: 'p2', before: null });
116
- const carried = carryChanges(changes, ['p1', 'p2'], ['p2', 'p1'], [1, 0]);
117
- expect(carried[0].origin.page).toBe('p1');
118
- expect(carried[0].to).toEqual({ page: 'p2', before: null });
119
- });
120
-
121
- it('follows a duplicated page, whose copy gets a key of its own', () => {
122
- const changes = placeBlock([], at('p1', 'a2', 'a1'), info('a'), 'parked', 'x');
123
- const carried = carryChanges(changes, ['p1'], ['p1', 'p1#2'], [0, -1]);
124
- expect(carried).toHaveLength(1);
125
- expect(carried[0].origin.page).toBe('p1');
126
- });
127
-
128
- it('drops a change whose source page was deleted', () => {
129
- const changes = placeBlock([], at('p1', 'a2', 'a1'), info('a'), { page: 'p2', before: null });
130
- expect(carryChanges(changes, ['p1', 'p2'], ['p2'], [1])).toEqual([]);
131
- });
132
-
133
- it('drops a change whose target page was deleted', () => {
134
- const changes = placeBlock([], at('p1', 'a2', 'a1'), info('a'), { page: 'p2', before: null });
135
- expect(carryChanges(changes, ['p1', 'p2'], ['p1'], [0])).toEqual([]);
136
- });
137
-
138
- it('keeps a parked change when its page survives elsewhere', () => {
139
- const changes = placeBlock([], at('p1', 'a2', 'a1'), info('a'), 'parked', 'x');
140
- const carried = carryChanges(changes, ['p0', 'p1'], ['p1', 'p9'], [1, 0]);
141
- expect(carried).toHaveLength(1);
142
- expect(carried[0].origin.page).toBe('p1');
143
- });
144
- });
145
-
146
- describe('staleChanges', () => {
147
- it('flags a block whose text changed on the page', () => {
148
- const changes = placeBlock([], at('p1', 'a2', 'a1'), info('Alpha page one'), {
149
- page: 'p2',
150
- before: null,
151
- });
152
- const readOf = (page: string) =>
153
- page === 'p1' ? [block('a1', 'Edited heading'), block('a2')] : null;
154
- expect([...staleChanges(changes, readOf)]).toEqual([0]);
155
- });
156
-
157
- it('flags a block that is no longer on the page', () => {
158
- const changes = placeBlock([], at('p1', 'a2', 'a1'), info('Alpha page one'), 'parked', 'x');
159
- expect([...staleChanges(changes, () => [block('a2')])]).toEqual([0]);
160
- });
161
-
162
- it('leaves a change alone when the page cannot be read', () => {
163
- const changes = placeBlock([], at('p1', 'a2', 'a1'), info('Alpha page one'), 'parked', 'x');
164
- expect([...staleChanges(changes, () => null)]).toEqual([]);
165
- });
166
- });
167
-
168
- describe('changedPages', () => {
169
- it('counts both ends of a move', () => {
170
- const changes = placeBlock([], at('p1', 'a2', 'a1'), info('a'), { page: 'p2', before: null });
171
- expect([...changedPages(changes)].sort()).toEqual(['p1', 'p2']);
172
- });
173
- });
174
-
175
- describe('sanitizeChanges', () => {
176
- it('drops malformed entries and keeps good ones', () => {
177
- const raw = [
178
- {
179
- origin: { page: 'p1', before: null, block: 'a1' },
180
- block: { kind: 'text', text: 'A', loc: null },
181
- to: 'parked',
182
- },
183
- { origin: { page: 'p1' }, block: { kind: 'nope', text: 'x' }, to: 'parked' },
184
- 'nonsense',
185
- null,
186
- ];
187
- const clean = sanitizeChanges(raw);
188
- expect(clean).toHaveLength(1);
189
- expect(clean[0].origin.block).toBe('a1');
190
- });
191
-
192
- it('clips long text and long code', () => {
193
- const clean = sanitizeChanges([
194
- {
195
- origin: { page: 'p1', before: null, block: 'a1' },
196
- block: { kind: 'text', text: 'x'.repeat(500), loc: null },
197
- to: 'parked',
198
- code: 'y'.repeat(9000),
199
- },
200
- ]);
201
- expect(clean[0].block.text).toHaveLength(80);
202
- expect(clean[0].code).toHaveLength(4000);
203
- });
204
-
205
- it('keeps at most 200 entries', () => {
206
- const raw = Array.from({ length: 250 }, (_, i) => ({
207
- origin: { page: 'p1', before: null, block: `b${i}` },
208
- block: { kind: 'text', text: `t${i}`, loc: null },
209
- to: 'parked',
210
- }));
211
- expect(sanitizeChanges(raw)).toHaveLength(200);
212
- });
213
- });
214
-
215
- describe('unparkBlock', () => {
216
- it('puts a parked block on a page, keeping its code and saying where it came from', () => {
217
- const parked = placeBlock(
218
- [],
219
- at('p1', 'a2', 'a1'),
220
- info('Alpha page one'),
221
- 'parked',
222
- '<h1>x</h1>',
223
- );
224
- expect(parked).toHaveLength(1);
225
-
226
- const moved = unparkBlock(parked, parked[0], { page: 'p2', before: null });
227
- expect(moved).toHaveLength(1);
228
- expect(moved[0].to).toEqual({ page: 'p2', before: null });
229
- expect(moved[0].fromParking).toBe(true);
230
- expect(moved[0].code).toBe('<h1>x</h1>');
231
- expect(parkedBlocks(moved)).toHaveLength(0);
232
- });
233
-
234
- it('drops the entry when the block goes back where it came from', () => {
235
- const parked = placeBlock([], at('p1', 'a2', 'a1'), info('Alpha page one'), 'parked', 'x');
236
- expect(unparkBlock(parked, parked[0], { page: 'p1', before: 'a2' })).toEqual([]);
237
- });
238
-
239
- it('survives a round trip through the stored form', () => {
240
- const parked = placeBlock([], at('p1', 'a2', 'a1'), info('Alpha page one'), 'parked', 'x');
241
- const moved = unparkBlock(parked, parked[0], { page: 'p2', before: null });
242
- expect(sanitizeChanges(JSON.parse(JSON.stringify(moved)))).toEqual(moved);
243
- });
244
- });
@@ -1,50 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type { BoardCard } from './cards';
3
- import { EMPTY_FILTER, isFilterActive, matchesFilter, toggleStatus } from './filter.ts';
4
-
5
- const card = (over: BoardCard = {}): BoardCard => over;
6
-
7
- describe('board filter', () => {
8
- it('keeps everything while no filter is set', () => {
9
- expect(isFilterActive(EMPTY_FILTER)).toBe(false);
10
- expect(matchesFilter(undefined, false, EMPTY_FILTER)).toBe(true);
11
- expect(matchesFilter(card({ status: 'todo' }), false, EMPTY_FILTER)).toBe(true);
12
- });
13
-
14
- it('keeps only the chosen statuses', () => {
15
- const filter = { ...EMPTY_FILTER, statuses: ['done' as const] };
16
- expect(matchesFilter(card({ status: 'done' }), false, filter)).toBe(true);
17
- expect(matchesFilter(card({ status: 'doing' }), false, filter)).toBe(false);
18
- expect(matchesFilter(card(), false, filter)).toBe(false);
19
- });
20
-
21
- it('accepts any of several chosen statuses', () => {
22
- const filter = { ...EMPTY_FILTER, statuses: ['done' as const, 'review' as const] };
23
- expect(matchesFilter(card({ status: 'review' }), false, filter)).toBe(true);
24
- });
25
-
26
- it('narrows to cards carrying a work memo', () => {
27
- const filter = { ...EMPTY_FILTER, memo: true };
28
- expect(matchesFilter(card({ memo: 'Q3 numbers' }), false, filter)).toBe(true);
29
- expect(matchesFilter(card({ title: 'Cover' }), false, filter)).toBe(false);
30
- });
31
-
32
- it('narrows to cards with an unhandled comment', () => {
33
- const filter = { ...EMPTY_FILTER, comments: true };
34
- expect(matchesFilter(card(), true, filter)).toBe(true);
35
- expect(matchesFilter(card(), false, filter)).toBe(false);
36
- });
37
-
38
- it('asks for every set condition at once', () => {
39
- const filter = { statuses: ['done' as const], memo: true, comments: true };
40
- expect(matchesFilter(card({ status: 'done', memo: 'x' }), true, filter)).toBe(true);
41
- expect(matchesFilter(card({ status: 'done', memo: 'x' }), false, filter)).toBe(false);
42
- expect(matchesFilter(card({ status: 'todo', memo: 'x' }), true, filter)).toBe(false);
43
- });
44
-
45
- it('toggles a status on and off again', () => {
46
- const on = toggleStatus(EMPTY_FILTER, 'done');
47
- expect(on.statuses).toEqual(['done']);
48
- expect(toggleStatus(on, 'done').statuses).toEqual([]);
49
- });
50
- });
@@ -1,71 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
- import {
3
- canRedo,
4
- canUndo,
5
- dropStep,
6
- emptyHistory,
7
- HISTORY_LIMIT,
8
- nextUndo,
9
- recordStep,
10
- redoStep,
11
- undoStep,
12
- } from './history.ts';
13
-
14
- const step = (name: string) => ({ undo: vi.fn(), redo: vi.fn(), name });
15
-
16
- describe('history', () => {
17
- it('starts with nothing to undo or redo', () => {
18
- const history = emptyHistory();
19
- expect(canUndo(history)).toBe(false);
20
- expect(canRedo(history)).toBe(false);
21
- expect(nextUndo(history)).toBeNull();
22
- });
23
-
24
- it('hands the newest step to undo and moves it onto the redo stack', () => {
25
- const first = step('first');
26
- const second = step('second');
27
- const history = recordStep(recordStep(emptyHistory(), first), second);
28
-
29
- const taken = undoStep(history);
30
- expect(taken?.step).toBe(second);
31
- expect(canUndo(taken?.history ?? history)).toBe(true);
32
- expect(canRedo(taken?.history ?? history)).toBe(true);
33
- expect(nextUndo(taken?.history ?? history)).toBe(first);
34
- });
35
-
36
- it('walks forward again after an undo, newest first', () => {
37
- const first = step('first');
38
- const second = step('second');
39
- const recorded = recordStep(recordStep(emptyHistory(), first), second);
40
- const once = undoStep(recorded)?.history ?? recorded;
41
- const undone = undoStep(once)?.history ?? once;
42
-
43
- const redone = redoStep(undone);
44
- expect(redone?.step).toBe(first);
45
- const again = redoStep(redone?.history ?? undone);
46
- expect(again?.step).toBe(second);
47
- expect(canRedo(again?.history ?? undone)).toBe(false);
48
- });
49
-
50
- it('retires the redo stack when a new operation is recorded', () => {
51
- const history = recordStep(emptyHistory(), step('first'));
52
- const undone = undoStep(history)?.history ?? history;
53
- expect(canRedo(undone)).toBe(true);
54
- expect(canRedo(recordStep(undone, step('other')))).toBe(false);
55
- });
56
-
57
- it('keeps only the newest fifty steps', () => {
58
- let history = emptyHistory();
59
- for (let i = 0; i < HISTORY_LIMIT + 4; i++) history = recordStep(history, step(`${i}`));
60
- expect(history.past).toHaveLength(HISTORY_LIMIT);
61
- expect(nextUndo(history)).toBe(history.past[HISTORY_LIMIT - 1]);
62
- });
63
-
64
- it('drops a step that cannot be undone and reaches the one before it', () => {
65
- const first = step('first');
66
- const blocked = { undo: null, redo: vi.fn() };
67
- const history = recordStep(recordStep(emptyHistory(), first), blocked);
68
- const dropped = dropStep(history);
69
- expect(nextUndo(dropped)).toBe(first);
70
- });
71
- });
@@ -1,205 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- addMerge,
4
- addSplit,
5
- carryRestructures,
6
- type Restructure,
7
- removeRestructure,
8
- restructuredPages,
9
- restructureReplaced,
10
- type SplitBlock,
11
- sanitizeRestructures,
12
- } from './restructure.ts';
13
-
14
- const P1 = '@0';
15
- const P2 = '@1';
16
- const P3 = '@2';
17
-
18
- const picked = (id: string, text = `Text of ${id}`): SplitBlock => ({ id, kind: 'text', text });
19
-
20
- describe('addSplit', () => {
21
- it('adds one record per page and replaces the page’s earlier split', () => {
22
- const once = addSplit([], P1, [picked('a'), picked('b')]);
23
- expect(once).toEqual([
24
- {
25
- kind: 'split',
26
- page: P1,
27
- blocks: ['a', 'b'],
28
- blockInfo: [
29
- { id: 'a', kind: 'text', text: 'Text of a' },
30
- { id: 'b', kind: 'text', text: 'Text of b' },
31
- ],
32
- },
33
- ]);
34
- const twice = addSplit(once, P1, [picked('c')]);
35
- expect(twice).toEqual([
36
- {
37
- kind: 'split',
38
- page: P1,
39
- blocks: ['c'],
40
- blockInfo: [{ id: 'c', kind: 'text', text: 'Text of c' }],
41
- },
42
- ]);
43
- });
44
-
45
- it('takes the place of a merge that involved the page', () => {
46
- const merged = addMerge([], P1, P2);
47
- expect(addSplit(merged, P2, [picked('a')])).toEqual([
48
- {
49
- kind: 'split',
50
- page: P2,
51
- blocks: ['a'],
52
- blockInfo: [{ id: 'a', kind: 'text', text: 'Text of a' }],
53
- },
54
- ]);
55
- });
56
-
57
- it('leaves the list alone when no block is named', () => {
58
- expect(addSplit([], P1, [])).toEqual([]);
59
- expect(addSplit([], P1, [picked('')])).toEqual([]);
60
- });
61
- });
62
-
63
- describe('addMerge', () => {
64
- it('records a pair once and replaces the earlier pair', () => {
65
- const once = addMerge([], P1, P2);
66
- expect(once).toEqual([{ kind: 'merge', pages: [P1, P2] }]);
67
- expect(addMerge(once, P1, P2)).toHaveLength(1);
68
- });
69
-
70
- it('takes the place of a split on either page', () => {
71
- const split = addSplit([], P2, [picked('a')]);
72
- expect(addMerge(split, P1, P2)).toEqual([{ kind: 'merge', pages: [P1, P2] }]);
73
- });
74
-
75
- it('drops a merge that shared a page', () => {
76
- const merged = addMerge(addMerge([], P1, P2), P2, P3);
77
- expect(merged).toEqual([{ kind: 'merge', pages: [P2, P3] }]);
78
- });
79
-
80
- it('refuses the same page twice', () => {
81
- expect(addMerge([], P1, P1)).toEqual([]);
82
- });
83
- });
84
-
85
- describe('restructureReplaced', () => {
86
- it('is true only when a record of the other kind is taken away', () => {
87
- const split = addSplit([], P1, [picked('a')]);
88
- expect(restructureReplaced(split, { kind: 'merge', pages: [P1, P2] })).toBe(true);
89
- expect(restructureReplaced(split, { kind: 'split', page: P1, blocks: ['b'] })).toBe(false);
90
- expect(restructureReplaced(split, { kind: 'split', page: P2, blocks: ['b'] })).toBe(false);
91
- });
92
- });
93
-
94
- describe('removeRestructure', () => {
95
- it('drops the record at that index', () => {
96
- const list: Restructure[] = [
97
- { kind: 'split', page: P1, blocks: ['a'] },
98
- { kind: 'merge', pages: [P2, P3] },
99
- ];
100
- expect(removeRestructure(list, 0)).toEqual([{ kind: 'merge', pages: [P2, P3] }]);
101
- });
102
- });
103
-
104
- describe('restructuredPages', () => {
105
- it('names every page a split or merge touches', () => {
106
- const list: Restructure[] = [
107
- { kind: 'split', page: P1, blocks: ['a'] },
108
- { kind: 'merge', pages: [P2, P3] },
109
- ];
110
- expect([...restructuredPages(list)].sort()).toEqual([P1, P2, P3].sort());
111
- });
112
- });
113
-
114
- describe('carryRestructures', () => {
115
- const before = [P1, P2, P3];
116
-
117
- it('renames the pages a reorder moved', () => {
118
- const list: Restructure[] = [
119
- { kind: 'split', page: P2, blocks: ['a'] },
120
- { kind: 'merge', pages: [P1, P3] },
121
- ];
122
- // Pages keyed by position: what was page 2 is now the first page.
123
- expect(carryRestructures(list, before, [P1, P2, P3], [1, 2, 0])).toEqual([
124
- { kind: 'split', page: P1, blocks: ['a'] },
125
- { kind: 'merge', pages: [P3, P2] },
126
- ]);
127
- });
128
-
129
- it('drops a record whose page is gone', () => {
130
- const list: Restructure[] = [
131
- { kind: 'split', page: P2, blocks: ['a'] },
132
- { kind: 'merge', pages: [P1, P3] },
133
- ];
134
- // Page 2 deleted: the pages left are the first and third, re-keyed.
135
- expect(carryRestructures(list, before, [P1, P2], [0, 2])).toEqual([
136
- { kind: 'merge', pages: [P1, P2] },
137
- ]);
138
- });
139
-
140
- it('renames a duplicate so the copy carries nothing', () => {
141
- const list: Restructure[] = [{ kind: 'split', page: P2, blocks: ['a'] }];
142
- // Page 2 duplicated: the copy takes the new key, the split stays on the original.
143
- expect(carryRestructures(list, before, [P1, P2, P3, '@3'], [0, 1, 2, -1])).toEqual([
144
- { kind: 'split', page: P2, blocks: ['a'] },
145
- ]);
146
- });
147
- });
148
-
149
- describe('sanitizeRestructures', () => {
150
- it('keeps only well-formed records', () => {
151
- expect(
152
- sanitizeRestructures([
153
- { kind: 'split', page: P1, blocks: ['a', '', 'a'] },
154
- { kind: 'merge', pages: [P1, P2] },
155
- { kind: 'merge', pages: [P1, P1] },
156
- { kind: 'split', page: '', blocks: ['a'] },
157
- { kind: 'split', page: P1, blocks: [] },
158
- { kind: 'move', page: P1 },
159
- null,
160
- ]),
161
- ).toEqual([
162
- {
163
- kind: 'split',
164
- page: P1,
165
- blocks: ['a'],
166
- blockInfo: [{ id: 'a', kind: 'text', text: '' }],
167
- },
168
- { kind: 'merge', pages: [P1, P2] },
169
- ]);
170
- });
171
-
172
- it('keeps the words stored beside a split’s blocks', () => {
173
- expect(
174
- sanitizeRestructures([
175
- {
176
- kind: 'split',
177
- page: P1,
178
- blocks: ['a'],
179
- blockInfo: [{ id: 'a', kind: 'chart', text: '' }],
180
- },
181
- ]),
182
- ).toEqual([
183
- {
184
- kind: 'split',
185
- page: P1,
186
- blocks: ['a'],
187
- blockInfo: [{ id: 'a', kind: 'chart', text: '' }],
188
- },
189
- ]);
190
- });
191
-
192
- it('caps the list at fifty', () => {
193
- const many = Array.from({ length: 60 }, (_, i) => ({
194
- kind: 'split',
195
- page: `@${i}`,
196
- blocks: ['a'],
197
- }));
198
- expect(sanitizeRestructures(many)).toHaveLength(50);
199
- });
200
-
201
- it('reads anything that is not a list as none', () => {
202
- expect(sanitizeRestructures(null)).toEqual([]);
203
- expect(sanitizeRestructures({ kind: 'split' })).toEqual([]);
204
- });
205
- });