@lemonriver/core 0.4.0 → 0.5.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/README.md +14 -4
- package/dist/{build-Nl7EeJ6x.js → build-CS1goZxt.js} +1 -1
- package/dist/cli/bin.js +4 -4
- package/dist/{config-CpC0nM3r.js → config-BpbcCbUv.js} +3673 -2065
- package/dist/{dev-BB3THd5I.js → dev-BpYnfgLL.js} +2 -2
- package/dist/{preview-BGjgTg7H.js → preview-HSzPPkSs.js} +1 -1
- package/dist/{update-DsxZBtwv.js → update-CMRxtTc9.js} +18 -8
- package/dist/vite/index.js +1 -1
- package/package.json +2 -2
- package/src/agent/types.ts +14 -2
- package/src/app/components/agent/agent-panel.tsx +17 -5
- package/src/app/components/agent/connect-view.tsx +1 -1
- package/src/app/components/agent/provider-logo.tsx +10 -1
- package/src/app/lemonriver/agent/provider-marks.tsx +53 -0
- package/src/app/lemonriver/agent-providers/section.tsx +75 -0
- package/src/app/lemonriver/agent-providers/use-providers.ts +61 -0
- package/src/app/lemonriver/board/blocks/block-panel.tsx +666 -0
- package/src/app/lemonriver/board/blocks/cache.ts +28 -0
- package/src/app/lemonriver/board/blocks/change-list.tsx +189 -0
- package/src/app/lemonriver/board/blocks/classify.test.ts +204 -0
- package/src/app/lemonriver/board/blocks/classify.ts +125 -0
- package/src/app/lemonriver/board/blocks/snapshot.ts +86 -0
- package/src/app/lemonriver/board/board-canvas.tsx +627 -104
- package/src/app/lemonriver/board/board-page.tsx +1687 -91
- package/src/app/lemonriver/board/board.css +58 -7
- package/src/app/lemonriver/board/layout.test.ts +84 -0
- package/src/app/lemonriver/board/layout.ts +112 -11
- package/src/app/lemonriver/board/model/agent-tasks.test.ts +200 -0
- package/src/app/lemonriver/board/model/agent-tasks.ts +191 -0
- package/src/app/lemonriver/board/model/apply-prompt.test.ts +121 -0
- package/src/app/lemonriver/board/model/apply-prompt.ts +115 -0
- package/src/app/lemonriver/board/model/apply.ts +71 -0
- package/src/app/lemonriver/board/model/cards.test.ts +95 -2
- package/src/app/lemonriver/board/model/cards.ts +88 -20
- package/src/app/lemonriver/board/model/changes.test.ts +244 -0
- package/src/app/lemonriver/board/model/changes.ts +268 -0
- package/src/app/lemonriver/board/model/filter.test.ts +50 -0
- package/src/app/lemonriver/board/model/filter.ts +42 -0
- package/src/app/lemonriver/board/model/history.test.ts +71 -0
- package/src/app/lemonriver/board/model/history.ts +51 -0
- package/src/app/lemonriver/board/model/restructure.test.ts +205 -0
- package/src/app/lemonriver/board/model/restructure.ts +169 -0
- package/src/app/lemonriver/board/model/structure.test.ts +249 -0
- package/src/app/lemonriver/board/model/structure.ts +209 -0
- package/src/app/lemonriver/board/model/timing.test.ts +113 -0
- package/src/app/lemonriver/board/model/timing.ts +117 -0
- package/src/app/lemonriver/board/page-node.tsx +236 -55
- package/src/app/lemonriver/board/status-style.ts +25 -0
- package/src/app/lemonriver/board/use-board-apply.ts +206 -0
- package/src/app/lemonriver/board/use-board-cards.ts +108 -5
- package/src/app/lemonriver/board/use-board-changes.ts +108 -0
- package/src/app/lemonriver/board/use-board-columns.ts +37 -56
- package/src/app/lemonriver/board/use-board-comments.ts +36 -0
- package/src/app/lemonriver/board/use-board-restructures.ts +107 -0
- package/src/app/lemonriver/board/use-history.ts +86 -0
- package/src/app/lemonriver/board/use-page-order.ts +65 -38
- package/src/app/lemonriver/board/use-target-minutes.ts +47 -0
- package/src/app/lemonriver/board/views/block-readings.tsx +46 -0
- package/src/app/lemonriver/board/views/list-view.tsx +356 -0
- package/src/app/lemonriver/board/views/progress.tsx +32 -0
- package/src/app/lemonriver/board/views/timeline-view.tsx +341 -0
- package/src/app/lemonriver/outline/model.test.ts +39 -0
- package/src/app/lemonriver/outline/model.ts +12 -0
- package/src/app/lemonriver/outline/outline-page.tsx +34 -1
- package/src/app/lemonriver/settings/settings-page.tsx +3 -0
- package/src/app/lemonriver/slide-extensions.tsx +14 -2
- package/src/app/lemonriver/text/en.ts +171 -0
- package/src/app/lemonriver/text/es.ts +163 -0
- package/src/app/lemonriver/text/ja.ts +163 -0
- package/src/app/lemonriver/text/types.ts +170 -0
- package/src/app/lemonriver/text/zh-cn.ts +161 -0
- package/src/app/lemonriver/text/zh-tw.ts +161 -0
- package/src/app/lemonriver/theme/lemon-icon.tsx +6 -0
- package/src/app/lemonriver/theme/theme-menu.tsx +3 -2
- package/src/app/lemonriver/theme/use-theme.tsx +2 -2
- package/src/app/lib/agent/use-agent.ts +4 -3
- package/src/app/routes/slide.tsx +1 -1
- package/src/app/assets/open-slide.svg +0 -39
- package/src/app/favicon.ico +0 -0
- package/src/app/favicon.svg +0 -39
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import type { Block, BlockKind } from '../blocks/classify.ts';
|
|
2
|
+
|
|
3
|
+
/** What the board remembers about a block it is about to move. */
|
|
4
|
+
export type BlockInfo = { kind: BlockKind; text: string; loc: string | null };
|
|
5
|
+
/**
|
|
6
|
+
* A place a block can sit: after `before`, or last when that is null.
|
|
7
|
+
* `beforeInfo` is the block at that place, so the prompt can name it.
|
|
8
|
+
*/
|
|
9
|
+
export type Spot = { page: string; before: string | null; beforeInfo?: BlockInfo };
|
|
10
|
+
export type Placement = {
|
|
11
|
+
origin: Spot & { block: string };
|
|
12
|
+
block: BlockInfo;
|
|
13
|
+
to: Spot | 'parked';
|
|
14
|
+
code?: string;
|
|
15
|
+
/** Set when the block left the holding area and is now on a page. */
|
|
16
|
+
fromParking?: true;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const MAX_CHANGES = 200;
|
|
20
|
+
const TEXT_MAX = 80;
|
|
21
|
+
const CODE_MAX = 4000;
|
|
22
|
+
|
|
23
|
+
export function sameSpot(a: Spot, b: Spot): boolean {
|
|
24
|
+
return a.page === b.page && a.before === b.before;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** One entry per block: moving it again replaces where it was going. */
|
|
28
|
+
export function placeBlock(
|
|
29
|
+
changes: Placement[],
|
|
30
|
+
origin: Spot & { block: string },
|
|
31
|
+
block: BlockInfo,
|
|
32
|
+
to: Spot | 'parked',
|
|
33
|
+
code?: string,
|
|
34
|
+
): Placement[] {
|
|
35
|
+
const kept = changes.filter(
|
|
36
|
+
(item) => !(item.origin.page === origin.page && item.origin.block === origin.block),
|
|
37
|
+
);
|
|
38
|
+
if (to !== 'parked' && sameSpot(to, origin)) return kept;
|
|
39
|
+
const placement: Placement = { origin, block, to };
|
|
40
|
+
if (code !== undefined) placement.code = code;
|
|
41
|
+
return [...kept, placement];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function removeChange(changes: Placement[], origin: Spot & { block: string }): Placement[] {
|
|
45
|
+
return changes.filter(
|
|
46
|
+
(item) => !(item.origin.page === origin.page && item.origin.block === origin.block),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A block taken out of the holding area and put back on a page. */
|
|
51
|
+
export function unparkBlock(changes: Placement[], parked: Placement, to: Spot): Placement[] {
|
|
52
|
+
const kept = changes.filter((item) => item !== parked);
|
|
53
|
+
if (sameSpot(to, parked.origin)) return kept;
|
|
54
|
+
const placement: Placement = {
|
|
55
|
+
origin: parked.origin,
|
|
56
|
+
block: parked.block,
|
|
57
|
+
to,
|
|
58
|
+
fromParking: true,
|
|
59
|
+
};
|
|
60
|
+
if (parked.code !== undefined) placement.code = parked.code;
|
|
61
|
+
return [...kept, placement];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type EffectiveBlock = Omit<Block, 'box'> & {
|
|
65
|
+
box: Block['box'] | null;
|
|
66
|
+
pending?: true;
|
|
67
|
+
from?: string;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* What a page shows right now: its own blocks with the ones moved away taken
|
|
72
|
+
* out, then the ones moved in, each sitting where its `before` says.
|
|
73
|
+
*/
|
|
74
|
+
export function effectiveBlocks(
|
|
75
|
+
page: string,
|
|
76
|
+
original: Block[],
|
|
77
|
+
changes: Placement[],
|
|
78
|
+
): EffectiveBlock[] {
|
|
79
|
+
const leaving = new Set(
|
|
80
|
+
changes.filter((item) => item.origin.page === page).map((item) => item.origin.block),
|
|
81
|
+
);
|
|
82
|
+
const blocks: EffectiveBlock[] = original.filter((block) => !leaving.has(block.id));
|
|
83
|
+
|
|
84
|
+
for (const item of changes) {
|
|
85
|
+
const to = item.to;
|
|
86
|
+
if (to === 'parked' || to.page !== page) continue;
|
|
87
|
+
const at = to.before === null ? -1 : blocks.findIndex((block) => block.id === to.before);
|
|
88
|
+
// A block that only changed place on its own page is still that page's own
|
|
89
|
+
// content, so it is drawn as the page has it now rather than as it was
|
|
90
|
+
// remembered when the move was made.
|
|
91
|
+
const own =
|
|
92
|
+
item.origin.page === page
|
|
93
|
+
? original.find((block) => block.id === item.origin.block)
|
|
94
|
+
: undefined;
|
|
95
|
+
const arriving: EffectiveBlock = {
|
|
96
|
+
id: item.origin.block,
|
|
97
|
+
kind: own?.kind ?? item.block.kind,
|
|
98
|
+
text: own?.text ?? item.block.text,
|
|
99
|
+
loc: own?.loc ?? item.block.loc,
|
|
100
|
+
box: own?.box ?? null,
|
|
101
|
+
...(own ? {} : { pending: true as const, from: item.origin.page }),
|
|
102
|
+
};
|
|
103
|
+
if (at < 0) blocks.push(arriving);
|
|
104
|
+
else blocks.splice(at, 0, arriving);
|
|
105
|
+
}
|
|
106
|
+
return blocks;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function parkedBlocks(changes: Placement[]): Placement[] {
|
|
110
|
+
return changes.filter((item) => item.to === 'parked');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Pages that are a source or a target of at least one change. */
|
|
114
|
+
export function changedPages(changes: Placement[]): Set<string> {
|
|
115
|
+
const pages = new Set<string>();
|
|
116
|
+
for (const item of changes) {
|
|
117
|
+
pages.add(item.origin.page);
|
|
118
|
+
if (item.to !== 'parked') pages.add(item.to.page);
|
|
119
|
+
}
|
|
120
|
+
return pages;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Follows a page operation the board made: keys are renamed the way cards are,
|
|
125
|
+
* and a change whose source or destination page is gone is dropped — the block
|
|
126
|
+
* simply stays where it is.
|
|
127
|
+
*/
|
|
128
|
+
export function carryChanges(
|
|
129
|
+
changes: Placement[],
|
|
130
|
+
before: string[],
|
|
131
|
+
after: string[],
|
|
132
|
+
origin: number[],
|
|
133
|
+
): Placement[] {
|
|
134
|
+
const rename = new Map<string, string>();
|
|
135
|
+
const created = new Set<string>();
|
|
136
|
+
origin.forEach((from, i) => {
|
|
137
|
+
if (from >= 0 && from < before.length) rename.set(before[from], after[i]);
|
|
138
|
+
else created.add(after[i]);
|
|
139
|
+
});
|
|
140
|
+
const live = new Set(before);
|
|
141
|
+
const resolve = (key: string): string | null => {
|
|
142
|
+
const next = live.has(key) ? (rename.get(key) ?? null) : key;
|
|
143
|
+
return next !== null && !created.has(next) ? next : null;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const kept: Placement[] = [];
|
|
147
|
+
for (const item of changes) {
|
|
148
|
+
const page = resolve(item.origin.page);
|
|
149
|
+
if (page === null) continue;
|
|
150
|
+
if (item.to === 'parked') {
|
|
151
|
+
kept.push({ ...item, origin: { ...item.origin, page } });
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const target = resolve(item.to.page);
|
|
155
|
+
if (target === null) continue;
|
|
156
|
+
kept.push({
|
|
157
|
+
...item,
|
|
158
|
+
origin: { ...item.origin, page },
|
|
159
|
+
to: { ...item.to, page: target },
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return kept;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* A page the user edited since the change was made no longer has the block we
|
|
167
|
+
* remembered, so the change can no longer be applied there. A page that cannot
|
|
168
|
+
* be read at all is left alone: nothing says the block is gone.
|
|
169
|
+
*/
|
|
170
|
+
export function staleChanges(
|
|
171
|
+
changes: Placement[],
|
|
172
|
+
readOf: (page: string) => Block[] | null,
|
|
173
|
+
): Set<number> {
|
|
174
|
+
const stale = new Set<number>();
|
|
175
|
+
const cache = new Map<string, Block[] | null>();
|
|
176
|
+
changes.forEach((item, index) => {
|
|
177
|
+
const page = item.origin.page;
|
|
178
|
+
if (!cache.has(page)) cache.set(page, readOf(page));
|
|
179
|
+
const blocks = cache.get(page) ?? null;
|
|
180
|
+
if (blocks === null) return;
|
|
181
|
+
const block = blocks.find((candidate) => candidate.id === item.origin.block);
|
|
182
|
+
if (!block || block.text !== item.block.text) stale.add(index);
|
|
183
|
+
});
|
|
184
|
+
return stale;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const KIND_SET = new Set<BlockKind>([
|
|
188
|
+
'title',
|
|
189
|
+
'point',
|
|
190
|
+
'text',
|
|
191
|
+
'image',
|
|
192
|
+
'chart',
|
|
193
|
+
'quote',
|
|
194
|
+
'number',
|
|
195
|
+
]);
|
|
196
|
+
|
|
197
|
+
function cleanInfo(raw: unknown): BlockInfo | null {
|
|
198
|
+
if (!raw || typeof raw !== 'object') return null;
|
|
199
|
+
const info = raw as Record<string, unknown>;
|
|
200
|
+
if (typeof info.kind !== 'string' || !KIND_SET.has(info.kind as BlockKind)) return null;
|
|
201
|
+
if (typeof info.text !== 'string') return null;
|
|
202
|
+
return {
|
|
203
|
+
kind: info.kind as BlockKind,
|
|
204
|
+
text: info.text.slice(0, TEXT_MAX),
|
|
205
|
+
loc: typeof info.loc === 'string' ? info.loc : null,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function cleanSpot(raw: unknown): Spot | null {
|
|
210
|
+
if (!raw || typeof raw !== 'object') return null;
|
|
211
|
+
const { page, before, beforeInfo } = raw as {
|
|
212
|
+
page?: unknown;
|
|
213
|
+
before?: unknown;
|
|
214
|
+
beforeInfo?: unknown;
|
|
215
|
+
};
|
|
216
|
+
if (typeof page !== 'string' || !page) return null;
|
|
217
|
+
if (before !== null && typeof before !== 'string') return null;
|
|
218
|
+
const spot: Spot = { page, before: before ?? null };
|
|
219
|
+
const info = cleanInfo(beforeInfo);
|
|
220
|
+
if (info) spot.beforeInfo = info;
|
|
221
|
+
return spot;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function cleanPlacement(raw: unknown): Placement | null {
|
|
225
|
+
if (!raw || typeof raw !== 'object') return null;
|
|
226
|
+
const item = raw as Record<string, unknown>;
|
|
227
|
+
const origin = cleanSpot(item.origin);
|
|
228
|
+
const block = item.block as Record<string, unknown> | undefined;
|
|
229
|
+
if (!origin || !block || typeof block !== 'object') return null;
|
|
230
|
+
const id = (item.origin as { block?: unknown } | undefined)?.block;
|
|
231
|
+
if (typeof id !== 'string' || !id) return null;
|
|
232
|
+
if (typeof block.kind !== 'string' || !KIND_SET.has(block.kind as BlockKind)) return null;
|
|
233
|
+
if (typeof block.text !== 'string') return null;
|
|
234
|
+
const loc = typeof block.loc === 'string' ? block.loc : null;
|
|
235
|
+
|
|
236
|
+
let to: Spot | 'parked';
|
|
237
|
+
if (item.to === 'parked') to = 'parked';
|
|
238
|
+
else {
|
|
239
|
+
const spot = cleanSpot(item.to);
|
|
240
|
+
if (!spot) return null;
|
|
241
|
+
to = spot;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const placement: Placement = {
|
|
245
|
+
origin: { page: origin.page, before: origin.before, block: id },
|
|
246
|
+
block: { kind: block.kind as BlockKind, text: block.text.slice(0, TEXT_MAX), loc },
|
|
247
|
+
to,
|
|
248
|
+
};
|
|
249
|
+
if (typeof item.code === 'string' && item.code) placement.code = item.code.slice(0, CODE_MAX);
|
|
250
|
+
if (item.fromParking === true) placement.fromParking = true;
|
|
251
|
+
return placement;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function sanitizeChanges(raw: unknown): Placement[] {
|
|
255
|
+
if (!Array.isArray(raw)) return [];
|
|
256
|
+
const changes: Placement[] = [];
|
|
257
|
+
for (const entry of raw) {
|
|
258
|
+
if (changes.length >= MAX_CHANGES) break;
|
|
259
|
+
const placement = cleanPlacement(entry);
|
|
260
|
+
if (!placement) continue;
|
|
261
|
+
const duplicate = changes.some(
|
|
262
|
+
(item) =>
|
|
263
|
+
item.origin.page === placement.origin.page && item.origin.block === placement.origin.block,
|
|
264
|
+
);
|
|
265
|
+
if (!duplicate) changes.push(placement);
|
|
266
|
+
}
|
|
267
|
+
return changes;
|
|
268
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { BoardCard, CardStatus } from './cards';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Filters never remove a card: a card that does not match stays where it is and
|
|
5
|
+
* is drawn faint, so the deck's order and the board's shape stay readable while
|
|
6
|
+
* a subset is picked out.
|
|
7
|
+
*/
|
|
8
|
+
export type BoardFilter = {
|
|
9
|
+
/** Statuses to keep. Empty keeps every status. */
|
|
10
|
+
statuses: CardStatus[];
|
|
11
|
+
/** Keep only cards carrying a work memo. */
|
|
12
|
+
memo: boolean;
|
|
13
|
+
/** Keep only cards carrying an unhandled comment. */
|
|
14
|
+
comments: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const EMPTY_FILTER: BoardFilter = { statuses: [], memo: false, comments: false };
|
|
18
|
+
|
|
19
|
+
export function isFilterActive(filter: BoardFilter): boolean {
|
|
20
|
+
return filter.statuses.length > 0 || filter.memo || filter.comments;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function matchesFilter(
|
|
24
|
+
card: BoardCard | undefined,
|
|
25
|
+
hasComments: boolean,
|
|
26
|
+
filter: BoardFilter,
|
|
27
|
+
): boolean {
|
|
28
|
+
if (!isFilterActive(filter)) return true;
|
|
29
|
+
if (filter.statuses.length > 0 && !(card?.status && filter.statuses.includes(card.status))) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (filter.memo && !card?.memo) return false;
|
|
33
|
+
if (filter.comments && !hasComments) return false;
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function toggleStatus(filter: BoardFilter, status: CardStatus): BoardFilter {
|
|
38
|
+
const statuses = filter.statuses.includes(status)
|
|
39
|
+
? filter.statuses.filter((value) => value !== status)
|
|
40
|
+
: [...filter.statuses, status];
|
|
41
|
+
return { ...filter, statuses };
|
|
42
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Undo and redo for the board. Each step remembers only an operation and its
|
|
3
|
+
* opposite; a step whose `undo` is null can still be recorded (a page deleted
|
|
4
|
+
* from a deck whose source could not be read back) but cannot be reverted.
|
|
5
|
+
*/
|
|
6
|
+
export type HistoryStep = {
|
|
7
|
+
undo: (() => void | Promise<void>) | null;
|
|
8
|
+
redo: () => void | Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type History = { past: HistoryStep[]; future: HistoryStep[] };
|
|
12
|
+
|
|
13
|
+
export const HISTORY_LIMIT = 50;
|
|
14
|
+
|
|
15
|
+
export const emptyHistory = (): History => ({ past: [], future: [] });
|
|
16
|
+
|
|
17
|
+
export const canUndo = (history: History) => history.past.length > 0;
|
|
18
|
+
export const canRedo = (history: History) => history.future.length > 0;
|
|
19
|
+
|
|
20
|
+
/** The step the undo button would take next, so its tooltip can say why not. */
|
|
21
|
+
export const nextUndo = (history: History): HistoryStep | null =>
|
|
22
|
+
history.past[history.past.length - 1] ?? null;
|
|
23
|
+
|
|
24
|
+
/** A new operation retires the redo stack: the future it led to no longer exists. */
|
|
25
|
+
export function recordStep(history: History, step: HistoryStep, limit = HISTORY_LIMIT): History {
|
|
26
|
+
const past = [...history.past, step];
|
|
27
|
+
return { past: past.slice(Math.max(0, past.length - limit)), future: [] };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function undoStep(history: History): { history: History; step: HistoryStep } | null {
|
|
31
|
+
const step = history.past[history.past.length - 1];
|
|
32
|
+
if (!step) return null;
|
|
33
|
+
return {
|
|
34
|
+
history: { past: history.past.slice(0, -1), future: [step, ...history.future] },
|
|
35
|
+
step,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function redoStep(history: History): { history: History; step: HistoryStep } | null {
|
|
40
|
+
const [step, ...future] = history.future;
|
|
41
|
+
if (!step) return null;
|
|
42
|
+
return { history: { past: [...history.past, step], future }, step };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Drops the newest step without running it, for a step that cannot be undone.
|
|
47
|
+
* The rest of the stack stays, so the next undo reaches an earlier operation.
|
|
48
|
+
*/
|
|
49
|
+
export function dropStep(history: History): History {
|
|
50
|
+
return { past: history.past.slice(0, -1), future: history.future };
|
|
51
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
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
|
+
});
|