@lemonriver/core 1.0.1 → 1.1.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 +2 -2
- package/dist/{build-CiT4CNey.js → build-Dm7gVRhb.js} +1 -1
- package/dist/cli/bin.js +3 -3
- package/dist/{config-BI3VRI2n.js → config-CubOIzrs.js} +1950 -1429
- package/dist/{dev-DpzBn_sf.js → dev-DgLeXPqp.js} +1 -1
- package/dist/{preview-Dro8hl5_.js → preview-CxXQpPk5.js} +1 -1
- package/dist/vite/index.js +1 -1
- package/package.json +3 -2
- package/src/app/components/command/slide-command-menu.tsx +0 -9
- package/src/app/lemonriver/backup/client.ts +25 -1
- package/src/app/lemonriver/backup/guide.test.ts +1 -1
- package/src/app/lemonriver/backup/guide.ts +1 -1
- package/src/app/lemonriver/backup/model.test.ts +19 -7
- package/src/app/lemonriver/backup/model.ts +63 -18
- package/src/app/lemonriver/board/board-page.tsx +2 -2
- package/src/app/lemonriver/help/model.test.ts +1 -1
- package/src/app/lemonriver/help/model.ts +1 -1
- package/src/app/lemonriver/home/drafts.test.ts +23 -0
- package/src/app/lemonriver/home/drafts.ts +57 -0
- package/src/app/lemonriver/home/home-page.tsx +94 -10
- package/src/app/lemonriver/home/organize-drafts.tsx +192 -0
- package/src/app/lemonriver/outline/outline-page.tsx +8 -1
- package/src/app/lemonriver/public-links.test.ts +32 -0
- package/src/app/lemonriver/settings/backup-restore-dialog.tsx +15 -1
- package/src/app/lemonriver/settings/backup-section.tsx +146 -28
- package/src/app/lemonriver/settings/settings-page.tsx +3 -0
- package/src/app/lemonriver/settings/workspace-card.tsx +53 -0
- package/src/app/lemonriver/settings/workspace.ts +37 -0
- package/src/app/lemonriver/share/editor-share.tsx +55 -0
- package/src/app/lemonriver/share/guide.test.ts +2 -2
- package/src/app/lemonriver/share/guide.ts +1 -1
- package/src/app/lemonriver/share/import-dialog.tsx +14 -0
- package/src/app/lemonriver/share/naming.test.ts +11 -0
- package/src/app/lemonriver/share/naming.ts +6 -1
- package/src/app/lemonriver/slide-extensions.tsx +37 -53
- package/src/app/lemonriver/text/en.ts +47 -12
- package/src/app/lemonriver/text/es.ts +39 -6
- package/src/app/lemonriver/text/ja.ts +39 -6
- package/src/app/lemonriver/text/types.ts +45 -6
- package/src/app/lemonriver/text/zh-cn.ts +48 -12
- package/src/app/lemonriver/text/zh-tw.ts +48 -12
- package/src/app/lemonriver/update/beta-badge.tsx +69 -0
- package/src/app/lib/export-html.ts +5 -3
- package/src/app/lib/export-pptx.ts +5 -4
- package/src/app/routes/slide.tsx +6 -57
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { V as PKG_NAMES } from "./update-b1dSg_FW.js";
|
|
2
2
|
import { a as printUrls, c as startupDuration, i as printShortcutsHint, n as formatError, r as printHeader, s as shortcutsEnabled, t as createCliLogger } from "./cli/bin.js";
|
|
3
|
-
import { n as DEV_SUPERVISED_ENV, t as createViteConfig } from "./config-
|
|
3
|
+
import { n as DEV_SUPERVISED_ENV, t as createViteConfig } from "./config-CubOIzrs.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { fork } from "node:child_process";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as printUrls, c as startupDuration, i as printShortcutsHint, r as printHeader, s as shortcutsEnabled, t as createCliLogger } from "./cli/bin.js";
|
|
2
|
-
import { t as createViteConfig } from "./config-
|
|
2
|
+
import { t as createViteConfig } from "./config-CubOIzrs.js";
|
|
3
3
|
import { mergeConfig, preview as preview$1 } from "vite";
|
|
4
4
|
//#region src/cli/preview.ts
|
|
5
5
|
async function preview(opts = {}) {
|
package/dist/vite/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createViteConfig } from "../config-
|
|
1
|
+
import { t as createViteConfig } from "../config-CubOIzrs.js";
|
|
2
2
|
export { createViteConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lemonriver/core",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "The LemonRiver runtime: deck viewer, story board, present mode, agent panel and export.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -59,8 +59,9 @@
|
|
|
59
59
|
"directory": "packages/core"
|
|
60
60
|
},
|
|
61
61
|
"bugs": {
|
|
62
|
-
"url": "https://github.com/SegawaBeer/lemonriver/issues"
|
|
62
|
+
"url": "https://github.com/SegawaBeer/lemonriver-slide/issues"
|
|
63
63
|
},
|
|
64
|
+
"homepage": "https://github.com/SegawaBeer/lemonriver-slide",
|
|
64
65
|
"publishConfig": {
|
|
65
66
|
"access": "public",
|
|
66
67
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
FileImage,
|
|
6
6
|
FileText,
|
|
7
7
|
Grid2x2,
|
|
8
|
-
Link2,
|
|
9
8
|
Maximize,
|
|
10
9
|
MonitorSpeaker,
|
|
11
10
|
Palette,
|
|
@@ -24,7 +23,6 @@ export type SlideCommandHandlers = {
|
|
|
24
23
|
onPresentWindow: () => void;
|
|
25
24
|
onPresentFullscreen: () => void;
|
|
26
25
|
onPresenterView: () => void;
|
|
27
|
-
onCopyLink: () => void;
|
|
28
26
|
onOverview: () => void;
|
|
29
27
|
onToggleDesignPanel: () => void;
|
|
30
28
|
onToggleAgentPanel: () => void;
|
|
@@ -82,13 +80,6 @@ export function SlideCommandMenu({
|
|
|
82
80
|
];
|
|
83
81
|
|
|
84
82
|
const deck: CommandSpec[] = [
|
|
85
|
-
{
|
|
86
|
-
id: 'copy-link',
|
|
87
|
-
label: t.slide.copyLink,
|
|
88
|
-
icon: <Link2 />,
|
|
89
|
-
keywords: ['copy', 'link', 'url', 'share'],
|
|
90
|
-
run: handlers.onCopyLink,
|
|
91
|
-
},
|
|
92
83
|
{
|
|
93
84
|
id: 'overview',
|
|
94
85
|
label: t.commandMenu.overview,
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
BackupPlace,
|
|
5
5
|
BackupPreview,
|
|
6
6
|
BackupSettings,
|
|
7
|
+
BackupSummary,
|
|
7
8
|
PrefsSnapshot,
|
|
8
9
|
} from './model';
|
|
9
10
|
|
|
@@ -28,7 +29,7 @@ export async function backupSettings(): Promise<{ settings: BackupSettings; dir:
|
|
|
28
29
|
export async function saveBackupSettings(patch: {
|
|
29
30
|
folder?: string | null;
|
|
30
31
|
auto?: boolean;
|
|
31
|
-
|
|
32
|
+
skipLargeVideos?: boolean;
|
|
32
33
|
}): Promise<{ ok: true; settings: BackupSettings } | { ok: false; code: string }> {
|
|
33
34
|
const response = await fetch('/__lr/backup/settings', {
|
|
34
35
|
method: 'POST',
|
|
@@ -77,6 +78,29 @@ export async function backupList(): Promise<BackupListItem[]> {
|
|
|
77
78
|
return data.backups;
|
|
78
79
|
}
|
|
79
80
|
|
|
81
|
+
export async function backupSummary(): Promise<BackupSummary> {
|
|
82
|
+
const data = await call<{ summary: BackupSummary }>('GET', '/__lr/backup/summary');
|
|
83
|
+
return data.summary;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type ExportAnswer =
|
|
87
|
+
| { ok: true; path: string; size: number }
|
|
88
|
+
| { cancelled: true }
|
|
89
|
+
| { unsupported: true };
|
|
90
|
+
|
|
91
|
+
export async function exportBackup(snapshot: string, locale: string): Promise<ExportAnswer> {
|
|
92
|
+
const response = await fetch('/__lr/backup/export', {
|
|
93
|
+
method: 'POST',
|
|
94
|
+
headers: { 'content-type': 'application/json' },
|
|
95
|
+
body: JSON.stringify({ snapshot, locale }),
|
|
96
|
+
});
|
|
97
|
+
const data = (await response.json().catch(() => ({}))) as ExportAnswer & { error?: string };
|
|
98
|
+
if (response.status === 501 || 'unsupported' in data) return { unsupported: true };
|
|
99
|
+
if ('cancelled' in data) return { cancelled: true };
|
|
100
|
+
if (!response.ok || !('path' in data)) throw new Error(data?.error ?? `HTTP ${response.status}`);
|
|
101
|
+
return data;
|
|
102
|
+
}
|
|
103
|
+
|
|
80
104
|
export type InspectAnswer =
|
|
81
105
|
| { ok: true; path: string; preview: BackupPreview }
|
|
82
106
|
| { ok: false; code: string; detail: string };
|
|
@@ -15,7 +15,7 @@ describe('the restore guide inside a backup', () => {
|
|
|
15
15
|
expect(zh).toContain('LemonRiver 备份 · 2026-11-01 21:30');
|
|
16
16
|
expect(zh).toContain('3 份演示 · 620 MB · 用 LemonRiver 0.8.0 备份');
|
|
17
17
|
expect(zh).toContain('从备份恢复');
|
|
18
|
-
expect(zh).toContain('https://github.com/SegawaBeer/lemonriver/releases');
|
|
18
|
+
expect(zh).toContain('https://github.com/SegawaBeer/lemonriver-slide/releases/latest');
|
|
19
19
|
expect(zh).not.toContain('<script');
|
|
20
20
|
|
|
21
21
|
const en = buildRestoreGuide({
|
|
@@ -13,7 +13,7 @@ export type RestoreGuideInput = {
|
|
|
13
13
|
locale: GuideLocale;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
const RELEASES_URL = 'https://github.com/SegawaBeer/lemonriver/releases';
|
|
16
|
+
const RELEASES_URL = 'https://github.com/SegawaBeer/lemonriver-slide/releases/latest';
|
|
17
17
|
|
|
18
18
|
export function restoreGuideFileName(locale: GuideLocale): string {
|
|
19
19
|
if (locale === 'zh-CN') return '怎么恢复.html';
|
|
@@ -3,29 +3,34 @@ import {
|
|
|
3
3
|
backupDue,
|
|
4
4
|
backupFileStem,
|
|
5
5
|
DAY_MS,
|
|
6
|
-
DEFAULT_KEEP,
|
|
7
6
|
isCompressedFile,
|
|
7
|
+
isLargeVideo,
|
|
8
|
+
LARGE_VIDEO_BYTES,
|
|
8
9
|
looksLikeBackupName,
|
|
9
10
|
PREFS_KEYS,
|
|
10
11
|
sanitizePrefs,
|
|
11
12
|
sanitizeSettings,
|
|
12
13
|
} from './model.ts';
|
|
13
14
|
|
|
14
|
-
const SETTINGS = { folder: '/Users/me/Backups', auto: true,
|
|
15
|
+
const SETTINGS = { folder: '/Users/me/Backups', auto: true, skipLargeVideos: false, last: null };
|
|
15
16
|
|
|
16
17
|
describe('backup settings', () => {
|
|
17
18
|
it('falls back to a usable default', () => {
|
|
18
19
|
expect(sanitizeSettings(null)).toEqual({
|
|
19
20
|
folder: null,
|
|
20
21
|
auto: false,
|
|
21
|
-
|
|
22
|
+
skipLargeVideos: false,
|
|
22
23
|
last: null,
|
|
23
|
-
written: [],
|
|
24
24
|
});
|
|
25
25
|
expect(sanitizeSettings({ folder: 'relative/path' }).folder).toBeNull();
|
|
26
|
-
expect(sanitizeSettings({
|
|
27
|
-
expect(sanitizeSettings({
|
|
28
|
-
expect(sanitizeSettings({ written: ['a.zip'
|
|
26
|
+
expect(sanitizeSettings({}).skipLargeVideos).toBe(false);
|
|
27
|
+
expect(sanitizeSettings({ skipLargeVideos: true }).skipLargeVideos).toBe(true);
|
|
28
|
+
expect(sanitizeSettings({ keep: 30, written: ['a.zip'] })).toEqual({
|
|
29
|
+
folder: null,
|
|
30
|
+
auto: false,
|
|
31
|
+
skipLargeVideos: false,
|
|
32
|
+
last: null,
|
|
33
|
+
});
|
|
29
34
|
});
|
|
30
35
|
|
|
31
36
|
it('knows when the daily backup is due', () => {
|
|
@@ -65,6 +70,13 @@ describe('backup settings', () => {
|
|
|
65
70
|
expect(isCompressedFile('notes.md')).toBe(false);
|
|
66
71
|
});
|
|
67
72
|
|
|
73
|
+
it('counts only videos past the size limit as large videos', () => {
|
|
74
|
+
expect(isLargeVideo('assets/team/clip.MP4', LARGE_VIDEO_BYTES + 1)).toBe(true);
|
|
75
|
+
expect(isLargeVideo('assets/team/clip.mov', LARGE_VIDEO_BYTES)).toBe(false);
|
|
76
|
+
expect(isLargeVideo('assets/team/huge.zip', LARGE_VIDEO_BYTES + 1)).toBe(false);
|
|
77
|
+
expect(isLargeVideo('assets/team/photo.png', LARGE_VIDEO_BYTES + 1)).toBe(false);
|
|
78
|
+
});
|
|
79
|
+
|
|
68
80
|
it('counts only its own file names as backups', () => {
|
|
69
81
|
expect(looksLikeBackupName('LemonRiver 备份 2026-11-01 2130.zip')).toBe(true);
|
|
70
82
|
expect(looksLikeBackupName('my stuff.zip')).toBe(false);
|
|
@@ -6,8 +6,9 @@ export const BACKUP_FOLDER_NAME = 'LemonRiver 备份';
|
|
|
6
6
|
export const BACKUP_SETTINGS_FILE = 'backup.json';
|
|
7
7
|
export const BACKUP_PARTIAL_SUFFIX = '.partial';
|
|
8
8
|
|
|
9
|
-
export const
|
|
10
|
-
export const
|
|
9
|
+
export const KEEP_DAYS = 30;
|
|
10
|
+
export const LARGE_VIDEO_BYTES = 100 * 1024 * 1024;
|
|
11
|
+
const VIDEO_EXTENSIONS = new Set(['mp4', 'mov', 'webm', 'm4v', 'avi', 'mkv']);
|
|
11
12
|
export const DAY_MS = 24 * 60 * 60 * 1000;
|
|
12
13
|
const MIN_RETRY_MS = 60 * 60 * 1000;
|
|
13
14
|
|
|
@@ -52,21 +53,59 @@ export function isCompressedFile(name: string): boolean {
|
|
|
52
53
|
return ALREADY_COMPRESSED.has(name.slice(dot + 1).toLowerCase());
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
/** A video big enough that copying it into every backup would matter. */
|
|
57
|
+
export function isLargeVideo(name: string, size: number): boolean {
|
|
58
|
+
if (size <= LARGE_VIDEO_BYTES) return false;
|
|
59
|
+
const dot = name.lastIndexOf('.');
|
|
60
|
+
if (dot <= 0) return false;
|
|
61
|
+
return VIDEO_EXTENSIONS.has(name.slice(dot + 1).toLowerCase());
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type BackupSkipped = { rel: string; size: number; reason: 'large-video' };
|
|
65
|
+
|
|
55
66
|
export type BackupLast = {
|
|
56
67
|
at: number;
|
|
57
68
|
path: string;
|
|
58
69
|
size: number;
|
|
70
|
+
addedBytes: number;
|
|
59
71
|
ok: boolean;
|
|
60
72
|
error: string | null;
|
|
61
73
|
warnings: string[];
|
|
74
|
+
skipped: BackupSkipped[];
|
|
62
75
|
};
|
|
63
76
|
|
|
64
77
|
export type BackupSettings = {
|
|
65
78
|
folder: string | null;
|
|
66
79
|
auto: boolean;
|
|
67
|
-
|
|
80
|
+
skipLargeVideos: boolean;
|
|
81
|
+
last: BackupLast | null;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** One file in a snapshot, addressed by the sha256 of its contents. */
|
|
85
|
+
export type BackupSnapshotFile = { sha256: string; size: number };
|
|
86
|
+
|
|
87
|
+
export const SNAPSHOT_FORMAT = 'lemonriver-backup';
|
|
88
|
+
export const SNAPSHOT_VERSION = 1;
|
|
89
|
+
|
|
90
|
+
export type BackupSnapshot = {
|
|
91
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
92
|
+
version: typeof SNAPSHOT_VERSION;
|
|
93
|
+
createdAt: number;
|
|
94
|
+
app: { name: string; version: string };
|
|
95
|
+
files: Record<string, BackupSnapshotFile>;
|
|
96
|
+
decks: ShareDeckEntry[];
|
|
97
|
+
folders: Record<string, unknown>;
|
|
98
|
+
prefs: PrefsSnapshot;
|
|
99
|
+
skipped: BackupSkipped[];
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export type BackupBiggestFile = { rel: string; size: number; deck: string | null };
|
|
103
|
+
|
|
104
|
+
export type BackupSummary = {
|
|
105
|
+
totalBytes: number;
|
|
68
106
|
last: BackupLast | null;
|
|
69
|
-
|
|
107
|
+
biggest: BackupBiggestFile[];
|
|
108
|
+
skipLargeVideos: boolean;
|
|
70
109
|
};
|
|
71
110
|
|
|
72
111
|
export type BackupPlaceKind =
|
|
@@ -95,6 +134,7 @@ export type BackupJob = {
|
|
|
95
134
|
size?: number;
|
|
96
135
|
error?: string;
|
|
97
136
|
warnings?: string[];
|
|
137
|
+
skipped?: BackupSkipped[];
|
|
98
138
|
restored?: string[];
|
|
99
139
|
assetsKept?: number;
|
|
100
140
|
themesKept?: number;
|
|
@@ -120,6 +160,7 @@ export type BackupPreview = {
|
|
|
120
160
|
prefs: boolean;
|
|
121
161
|
size: number;
|
|
122
162
|
executables: string[];
|
|
163
|
+
skipped?: BackupSkipped[];
|
|
123
164
|
};
|
|
124
165
|
|
|
125
166
|
export type BackupListItem = {
|
|
@@ -127,15 +168,15 @@ export type BackupListItem = {
|
|
|
127
168
|
path: string;
|
|
128
169
|
size: number;
|
|
129
170
|
at: number;
|
|
130
|
-
|
|
171
|
+
kind: 'snapshot' | 'zip';
|
|
172
|
+
decks: number | null;
|
|
131
173
|
};
|
|
132
174
|
|
|
133
175
|
const EMPTY_SETTINGS: BackupSettings = {
|
|
134
176
|
folder: null,
|
|
135
177
|
auto: false,
|
|
136
|
-
|
|
178
|
+
skipLargeVideos: false,
|
|
137
179
|
last: null,
|
|
138
|
-
written: [],
|
|
139
180
|
};
|
|
140
181
|
|
|
141
182
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
@@ -151,6 +192,18 @@ function readWarnings(raw: unknown): string[] {
|
|
|
151
192
|
return raw.filter((item): item is string => typeof item === 'string' && item !== '');
|
|
152
193
|
}
|
|
153
194
|
|
|
195
|
+
function readSkipped(raw: unknown): BackupSkipped[] {
|
|
196
|
+
if (!Array.isArray(raw)) return [];
|
|
197
|
+
const out: BackupSkipped[] = [];
|
|
198
|
+
for (const item of raw) {
|
|
199
|
+
if (!isRecord(item) || typeof item.rel !== 'string' || item.rel === '') continue;
|
|
200
|
+
if (typeof item.size !== 'number' || item.size < 0) continue;
|
|
201
|
+
if (item.reason !== 'large-video') continue;
|
|
202
|
+
out.push({ rel: item.rel, size: item.size, reason: item.reason });
|
|
203
|
+
}
|
|
204
|
+
return out;
|
|
205
|
+
}
|
|
206
|
+
|
|
154
207
|
function readLast(raw: unknown): BackupLast | null {
|
|
155
208
|
if (!isRecord(raw)) return null;
|
|
156
209
|
if (typeof raw.at !== 'number' || !Number.isFinite(raw.at)) return null;
|
|
@@ -158,9 +211,11 @@ function readLast(raw: unknown): BackupLast | null {
|
|
|
158
211
|
at: raw.at,
|
|
159
212
|
path: typeof raw.path === 'string' ? raw.path : '',
|
|
160
213
|
size: typeof raw.size === 'number' && raw.size >= 0 ? raw.size : 0,
|
|
214
|
+
addedBytes: typeof raw.addedBytes === 'number' && raw.addedBytes >= 0 ? raw.addedBytes : 0,
|
|
161
215
|
ok: raw.ok === true,
|
|
162
216
|
error: typeof raw.error === 'string' && raw.error !== '' ? raw.error : null,
|
|
163
217
|
warnings: readWarnings(raw.warnings),
|
|
218
|
+
skipped: readSkipped(raw.skipped),
|
|
164
219
|
};
|
|
165
220
|
}
|
|
166
221
|
|
|
@@ -170,21 +225,11 @@ export function sanitizeSettings(raw: unknown): BackupSettings {
|
|
|
170
225
|
typeof raw.folder === 'string' && isAbsolutePath(raw.folder)
|
|
171
226
|
? raw.folder.replace(/\/+$/, '')
|
|
172
227
|
: null;
|
|
173
|
-
const keep =
|
|
174
|
-
typeof raw.keep === 'number' && (KEEP_CHOICES as readonly number[]).includes(raw.keep)
|
|
175
|
-
? raw.keep
|
|
176
|
-
: DEFAULT_KEEP;
|
|
177
|
-
const written = Array.isArray(raw.written)
|
|
178
|
-
? raw.written.filter(
|
|
179
|
-
(name): name is string => typeof name === 'string' && name !== '' && !name.includes('/'),
|
|
180
|
-
)
|
|
181
|
-
: [];
|
|
182
228
|
return {
|
|
183
229
|
folder,
|
|
184
230
|
auto: raw.auto === true,
|
|
185
|
-
|
|
231
|
+
skipLargeVideos: raw.skipLargeVideos === true,
|
|
186
232
|
last: readLast(raw.last),
|
|
187
|
-
written: [...new Set(written)],
|
|
188
233
|
};
|
|
189
234
|
}
|
|
190
235
|
|
|
@@ -1096,7 +1096,7 @@ export function Board() {
|
|
|
1096
1096
|
|
|
1097
1097
|
const openPage = useCallback(
|
|
1098
1098
|
(index: number) => {
|
|
1099
|
-
navigate(`/s/${encodeURIComponent(slideId)}?p=${index + 1}
|
|
1099
|
+
navigate(`/s/${encodeURIComponent(slideId)}?p=${index + 1}`, { replace: true });
|
|
1100
1100
|
},
|
|
1101
1101
|
[navigate, slideId],
|
|
1102
1102
|
);
|
|
@@ -1147,7 +1147,7 @@ export function Board() {
|
|
|
1147
1147
|
variant="ghost"
|
|
1148
1148
|
size="icon-sm"
|
|
1149
1149
|
aria-label={lr.board.backToDeck}
|
|
1150
|
-
onClick={() => navigate(`/s/${encodeURIComponent(slideId)}
|
|
1150
|
+
onClick={() => navigate(`/s/${encodeURIComponent(slideId)}`, { replace: true })}
|
|
1151
1151
|
>
|
|
1152
1152
|
<ChevronLeft />
|
|
1153
1153
|
</Button>
|
|
@@ -78,7 +78,7 @@ describe('the help page', () => {
|
|
|
78
78
|
import: text.share.importAction,
|
|
79
79
|
backupNow: text.backup.runNow,
|
|
80
80
|
autoBackup: text.backup.auto,
|
|
81
|
-
|
|
81
|
+
skipVideos: text.backup.skipVideos,
|
|
82
82
|
restore: text.backup.restore,
|
|
83
83
|
restoreGo: text.backup.restoreGo,
|
|
84
84
|
chooseOtherFile: text.backup.chooseOtherFile,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { suggestsFolder } from './drafts.ts';
|
|
3
|
+
|
|
4
|
+
describe('draft folder suggestions', () => {
|
|
5
|
+
it('suggests a folder that shares a Chinese word, ignoring generic words', () => {
|
|
6
|
+
expect(suggestsFolder('商飞项目', '商飞本体进展汇报')).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('suggests a folder that shares an English word, whatever its case', () => {
|
|
10
|
+
expect(suggestsFolder('Acme', 'Acme launch review')).toBe(true);
|
|
11
|
+
expect(suggestsFolder('acme', 'ACME launch review')).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('leaves unrelated drafts alone', () => {
|
|
15
|
+
expect(suggestsFolder('产品培训', '季度经营汇报')).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('does not match on the generic words alone', () => {
|
|
19
|
+
expect(suggestsFolder('商飞项目', 'XX 项目进展')).toBe(false);
|
|
20
|
+
expect(suggestsFolder('产品培训', 'XX 项目进展')).toBe(false);
|
|
21
|
+
expect(suggestsFolder('项目', '商飞项目进展')).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Words that say what kind of thing a folder is, not which one, so they cannot
|
|
2
|
+
// be what a folder and a deck have in common.
|
|
3
|
+
const GENERIC = ['文件夹', '项目', '案例', '资料', 'project', 'projects', 'folder', 'folders'];
|
|
4
|
+
|
|
5
|
+
export function cleanedFolderName(name: string): string {
|
|
6
|
+
let out = name;
|
|
7
|
+
for (const word of GENERIC) {
|
|
8
|
+
out = out.replace(new RegExp(word, 'gi'), ' ');
|
|
9
|
+
}
|
|
10
|
+
return out.replace(/\s+/g, ' ').trim();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function chineseBigrams(text: string): string[] {
|
|
14
|
+
const runs = text.match(/[一-鿿]+/g) ?? [];
|
|
15
|
+
const grams = new Set<string>();
|
|
16
|
+
for (const run of runs) {
|
|
17
|
+
for (let i = 0; i + 2 <= run.length; i += 1) grams.add(run.slice(i, i + 2));
|
|
18
|
+
}
|
|
19
|
+
return [...grams];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function englishWords(text: string): string[] {
|
|
23
|
+
return (text.match(/[A-Za-z][A-Za-z0-9]*/g) ?? []).filter((word) => word.length >= 2);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function escapeRegExp(text: string): string {
|
|
27
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Whether the folder name and the deck title share enough to suggest the folder. */
|
|
31
|
+
export function suggestsFolder(folderName: string, deckTitle: string): boolean {
|
|
32
|
+
const cleaned = cleanedFolderName(folderName);
|
|
33
|
+
if (cleaned === '') return false;
|
|
34
|
+
const title = deckTitle.toLowerCase();
|
|
35
|
+
|
|
36
|
+
for (const gram of chineseBigrams(cleaned)) {
|
|
37
|
+
if (deckTitle.includes(gram)) return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
for (const word of englishWords(cleaned)) {
|
|
41
|
+
const pattern = new RegExp(`\\b${escapeRegExp(word.toLowerCase())}\\b`);
|
|
42
|
+
if (pattern.test(title)) return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The first folder that shares a word with the deck, or "leave it in drafts". */
|
|
49
|
+
export function suggestedFolder(
|
|
50
|
+
folders: { id: string; name: string }[],
|
|
51
|
+
deckTitle: string,
|
|
52
|
+
): string | null {
|
|
53
|
+
for (const folder of folders) {
|
|
54
|
+
if (suggestsFolder(folder.name, deckTitle)) return folder.id;
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChevronDown, Plus } from 'lucide-react';
|
|
2
|
-
import { type ReactNode, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { type ReactNode, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { Link, useNavigate, useOutletContext } from 'react-router-dom';
|
|
4
4
|
import { toast } from 'sonner';
|
|
5
5
|
import { Button } from '@/components/ui/button';
|
|
@@ -34,6 +34,7 @@ import { BriefCard } from './brief-card';
|
|
|
34
34
|
import { SearchInput, SortControl } from './controls';
|
|
35
35
|
import { DeckCard } from './deck-card';
|
|
36
36
|
import { MoveDialog, RenameDialog, TypedConfirmDialog } from './dialogs';
|
|
37
|
+
import { OrganizeDraftsDialog } from './organize-drafts';
|
|
37
38
|
import { filterDecks, sortDecks, useSortPref } from './sorting';
|
|
38
39
|
import { greetingFor } from './time';
|
|
39
40
|
import { useDeckTimes } from './use-deck-times';
|
|
@@ -77,6 +78,8 @@ export function LemonRiverHome() {
|
|
|
77
78
|
const [sharing, setSharing] = useState<{ slideId: string; title: string } | null>(null);
|
|
78
79
|
const [inspection, setInspection] = useState<InspectOk | null>(null);
|
|
79
80
|
const [inspecting, setInspecting] = useState(false);
|
|
81
|
+
const [organizing, setOrganizing] = useState(false);
|
|
82
|
+
const slidesBefore = useRef<Set<string> | null>(null);
|
|
80
83
|
|
|
81
84
|
const isAll = selectedId === ALL_SLIDES_ID;
|
|
82
85
|
const isDraft = selectedId === DRAFT_ID;
|
|
@@ -112,6 +115,44 @@ export function LemonRiverHome() {
|
|
|
112
115
|
evening: lr.home.greetingEvening,
|
|
113
116
|
}[greetingFor(new Date(now).getHours())];
|
|
114
117
|
|
|
118
|
+
const createDeckHere = async () => {
|
|
119
|
+
try {
|
|
120
|
+
const res = await fetch('/__slides', { method: 'POST' });
|
|
121
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
122
|
+
const { slideId } = (await res.json()) as { slideId?: unknown };
|
|
123
|
+
if (typeof slideId !== 'string') throw new Error('no slideId');
|
|
124
|
+
if (folder) await ctx.assign(slideId, folder.id);
|
|
125
|
+
window.location.assign(`/s/${encodeURIComponent(slideId)}`);
|
|
126
|
+
} catch {
|
|
127
|
+
toast.error(t.agent.toastCreateDeckFailed);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// A deck that first appears in the list while a folder is open (the agent
|
|
132
|
+
// just wrote it, or an import finished) belongs in that folder. A deck that
|
|
133
|
+
// was already listed and merely changed folders — moved back to drafts, say
|
|
134
|
+
// — is not new and stays where the user put it.
|
|
135
|
+
const folderId = folder?.id ?? null;
|
|
136
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: a new baseline per view
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
slidesBefore.current = new Set(slideIds);
|
|
139
|
+
}, [folderId]);
|
|
140
|
+
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (!folder || !slidesBefore.current) return;
|
|
143
|
+
const fresh = slideIds.filter(
|
|
144
|
+
(id) => !slidesBefore.current?.has(id) && !manifest.assignments[id],
|
|
145
|
+
);
|
|
146
|
+
if (fresh.length === 0) return;
|
|
147
|
+
for (const id of fresh) slidesBefore.current.add(id);
|
|
148
|
+
void (async () => {
|
|
149
|
+
try {
|
|
150
|
+
for (const id of fresh) await ctx.assign(id, folder.id);
|
|
151
|
+
toast.success(format(lr.home.newDeckFiled, { folder: folder.name }));
|
|
152
|
+
} catch {}
|
|
153
|
+
})();
|
|
154
|
+
}, [folder, manifest, ctx, lr.home.newDeckFiled]);
|
|
155
|
+
|
|
115
156
|
const duplicate = async (id: string) => {
|
|
116
157
|
try {
|
|
117
158
|
const copy = await ctx.duplicateSlide(id);
|
|
@@ -200,6 +241,19 @@ export function LemonRiverHome() {
|
|
|
200
241
|
</div>
|
|
201
242
|
</div>
|
|
202
243
|
|
|
244
|
+
{isDraft && (
|
|
245
|
+
<div data-lr-drafts-toolbar className="mb-4 flex flex-wrap items-center gap-3">
|
|
246
|
+
{draftSlides.length > 10 && (
|
|
247
|
+
<span data-lr-drafts-reminder className="text-[13px] text-muted-foreground">
|
|
248
|
+
{format(lr.home.draftReminder, { n: draftSlides.length })}
|
|
249
|
+
</span>
|
|
250
|
+
)}
|
|
251
|
+
<Button variant="outline" size="sm" onClick={() => setOrganizing(true)}>
|
|
252
|
+
{lr.home.organizeDrafts}
|
|
253
|
+
</Button>
|
|
254
|
+
</div>
|
|
255
|
+
)}
|
|
256
|
+
|
|
203
257
|
{!loading && library?.available === true && presentOccasions.length > 0 && (
|
|
204
258
|
<div
|
|
205
259
|
role="radiogroup"
|
|
@@ -228,7 +282,7 @@ export function LemonRiverHome() {
|
|
|
228
282
|
<GridSkeleton />
|
|
229
283
|
) : null
|
|
230
284
|
) : visible.length === 0 ? (
|
|
231
|
-
<EmptyHome isDraft={isAll || isDraft} folderName={folder?.name} />
|
|
285
|
+
<EmptyHome isDraft={isAll || isDraft} folderName={folder?.name} onCreate={createDeckHere} />
|
|
232
286
|
) : shown.length === 0 ? (
|
|
233
287
|
<LemonEmpty
|
|
234
288
|
state="thinking"
|
|
@@ -251,7 +305,9 @@ export function LemonRiverHome() {
|
|
|
251
305
|
</LemonEmpty>
|
|
252
306
|
) : (
|
|
253
307
|
<ul className="grid grid-cols-[repeat(auto-fill,minmax(230px,1fr))] gap-5">
|
|
254
|
-
{import.meta.env.DEV &&
|
|
308
|
+
{import.meta.env.DEV && !searching && (isAll || folder) && (
|
|
309
|
+
<NewDeckCard inFolder={folder !== null} onCreate={createDeckHere} />
|
|
310
|
+
)}
|
|
255
311
|
{sorted.map((id, i) => (
|
|
256
312
|
<li
|
|
257
313
|
key={id}
|
|
@@ -311,6 +367,14 @@ export function LemonRiverHome() {
|
|
|
311
367
|
setDialog(null);
|
|
312
368
|
}}
|
|
313
369
|
/>
|
|
370
|
+
<OrganizeDraftsDialog
|
|
371
|
+
open={organizing}
|
|
372
|
+
drafts={draftSlides}
|
|
373
|
+
titleOf={titleOf}
|
|
374
|
+
folders={manifest.folders}
|
|
375
|
+
onClose={() => setOrganizing(false)}
|
|
376
|
+
onAssign={ctx.assign}
|
|
377
|
+
/>
|
|
314
378
|
{shareOn && (
|
|
315
379
|
<>
|
|
316
380
|
<ShareDialog
|
|
@@ -322,7 +386,11 @@ export function LemonRiverHome() {
|
|
|
322
386
|
}}
|
|
323
387
|
/>
|
|
324
388
|
{inspection && (
|
|
325
|
-
<ImportDialog
|
|
389
|
+
<ImportDialog
|
|
390
|
+
inspection={inspection}
|
|
391
|
+
folderId={folder?.id ?? null}
|
|
392
|
+
onClose={() => setInspection(null)}
|
|
393
|
+
/>
|
|
326
394
|
)}
|
|
327
395
|
</>
|
|
328
396
|
)}
|
|
@@ -330,17 +398,18 @@ export function LemonRiverHome() {
|
|
|
330
398
|
);
|
|
331
399
|
}
|
|
332
400
|
|
|
333
|
-
function NewDeckCard() {
|
|
401
|
+
function NewDeckCard({ inFolder, onCreate }: { inFolder: boolean; onCreate: () => Promise<void> }) {
|
|
334
402
|
const lr = useLrText();
|
|
335
403
|
const navigate = useNavigate();
|
|
336
|
-
const createDeck = useCreateDeck();
|
|
337
404
|
const guide = useGuideFlags();
|
|
338
|
-
|
|
405
|
+
// The guided builder starts from the all-slides view; inside a folder the
|
|
406
|
+
// new deck goes straight into that folder instead.
|
|
407
|
+
const guided = !inFolder && guide?.guided === true && isFeatureEnabled('outline');
|
|
339
408
|
return (
|
|
340
409
|
<li>
|
|
341
410
|
<button
|
|
342
411
|
type="button"
|
|
343
|
-
onClick={() => (guided ? navigate('/new') : void
|
|
412
|
+
onClick={() => (guided ? navigate('/new') : void onCreate())}
|
|
344
413
|
className={cn(
|
|
345
414
|
'flex h-full min-h-[190px] w-full flex-col items-center justify-center gap-2 rounded-[16px]',
|
|
346
415
|
'border-[1.5px] border-dashed border-border text-[14px] font-semibold text-muted-foreground outline-none',
|
|
@@ -368,7 +437,15 @@ function GridSkeleton() {
|
|
|
368
437
|
);
|
|
369
438
|
}
|
|
370
439
|
|
|
371
|
-
function EmptyHome({
|
|
440
|
+
function EmptyHome({
|
|
441
|
+
isDraft,
|
|
442
|
+
folderName,
|
|
443
|
+
onCreate,
|
|
444
|
+
}: {
|
|
445
|
+
isDraft: boolean;
|
|
446
|
+
folderName?: string;
|
|
447
|
+
onCreate: () => Promise<void>;
|
|
448
|
+
}) {
|
|
372
449
|
const t = useLocale();
|
|
373
450
|
const lr = useLrText();
|
|
374
451
|
const { enabled, provider } = useAgentStatus();
|
|
@@ -376,7 +453,14 @@ function EmptyHome({ isDraft, folderName }: { isDraft: boolean; folderName?: str
|
|
|
376
453
|
const guide = useGuideFlags();
|
|
377
454
|
if (!isDraft) {
|
|
378
455
|
return (
|
|
379
|
-
<LemonEmpty
|
|
456
|
+
<LemonEmpty
|
|
457
|
+
title={t.home.folderEmptyTitle.replace('{name}', folderName ?? '')}
|
|
458
|
+
actions={
|
|
459
|
+
import.meta.env.DEV && (
|
|
460
|
+
<Button onClick={() => void onCreate()}>{lr.shell.newDeckCard}</Button>
|
|
461
|
+
)
|
|
462
|
+
}
|
|
463
|
+
>
|
|
380
464
|
{t.home.folderEmptyHint}
|
|
381
465
|
</LemonEmpty>
|
|
382
466
|
);
|