@open-slide/core 1.13.1 → 1.13.3

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.
@@ -1,4 +1,4 @@
1
- import { Locale } from "./types-CHmFPIG_.js";
1
+ import { Locale } from "./types-CXTTzrhF.js";
2
2
 
3
3
  //#region src/config.d.ts
4
4
  type OpenSlideBuildConfig = {
@@ -38,6 +38,8 @@ const en = {
38
38
  themes: "Themes",
39
39
  assets: "Assets",
40
40
  folders: "Folders",
41
+ slides: "Slides",
42
+ menu: "Menu",
41
43
  newFolder: "New folder",
42
44
  folderName: "Folder name",
43
45
  updateAvailable: "open-slide {version} is available — update the package to get the latest.",
@@ -436,6 +438,8 @@ const ja = {
436
438
  themes: "テーマ",
437
439
  assets: "アセット",
438
440
  folders: "フォルダ",
441
+ slides: "スライド",
442
+ menu: "メニュー",
439
443
  newFolder: "新規フォルダ",
440
444
  folderName: "フォルダ名",
441
445
  updateAvailable: "open-slide {version} が利用可能です — パッケージを更新して最新版を入手してください。",
@@ -834,6 +838,8 @@ const zhCN = {
834
838
  themes: "主题",
835
839
  assets: "素材",
836
840
  folders: "文件夹",
841
+ slides: "幻灯片",
842
+ menu: "菜单",
837
843
  newFolder: "新建文件夹",
838
844
  folderName: "文件夹名称",
839
845
  updateAvailable: "open-slide {version} 已发布,请更新软件包以获取最新版本。",
@@ -1232,6 +1238,8 @@ const zhTW = {
1232
1238
  themes: "主題",
1233
1239
  assets: "素材",
1234
1240
  folders: "資料夾",
1241
+ slides: "投影片",
1242
+ menu: "選單",
1235
1243
  newFolder: "新增資料夾",
1236
1244
  folderName: "資料夾名稱",
1237
1245
  updateAvailable: "open-slide {version} 已發布,請更新套件以取得最新版本。",
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { Locale, Plural } from "./types-CHmFPIG_.js";
2
- import { OpenSlideConfig } from "./config-x493taft.js";
1
+ import { Locale, Plural } from "./types-CXTTzrhF.js";
2
+ import { OpenSlideConfig } from "./config-BK_GvWH8.js";
3
3
  import { CSSProperties, ComponentType, HTMLAttributes, PropsWithChildren, ReactNode } from "react";
4
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
4
5
  import * as react_jsx_runtime1 from "react/jsx-runtime";
5
- import * as react_jsx_runtime2 from "react/jsx-runtime";
6
6
  import * as react_jsx_runtime4 from "react/jsx-runtime";
7
7
  import * as react_jsx_runtime5 from "react/jsx-runtime";
8
8
 
@@ -21,7 +21,7 @@ declare function ImagePlaceholder({
21
21
  style,
22
22
  className,
23
23
  ...rest
24
- }: ImagePlaceholderProps): react_jsx_runtime1.JSX.Element;
24
+ }: ImagePlaceholderProps): react_jsx_runtime0.JSX.Element;
25
25
 
26
26
  //#endregion
27
27
  //#region src/app/components/shared-element.d.ts
@@ -36,7 +36,7 @@ declare function unstable_SharedElement({
36
36
  children,
37
37
  className,
38
38
  style
39
- }: unstable_SharedElementProps): react_jsx_runtime2.JSX.Element;
39
+ }: unstable_SharedElementProps): react_jsx_runtime1.JSX.Element;
40
40
 
41
41
  //#endregion
42
42
  //#region src/app/lib/design.d.ts
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { en, ja, zhCN, zhTW } from "./format-7j0EzhuV.js";
1
+ import { en, ja, zhCN, zhTW } from "./format-sYcnWvKw.js";
2
2
  import { cssVarsToString, defaultDesign, designToCssVars } from "./design-cpzS8aud.js";
3
3
  import { Children, cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
4
4
  import { toast } from "sonner";
@@ -1,4 +1,4 @@
1
- import { Locale, Plural } from "../types-CHmFPIG_.js";
1
+ import { Locale, Plural } from "../types-CXTTzrhF.js";
2
2
 
3
3
  //#region src/locale/en.d.ts
4
4
  declare const en: Locale;
@@ -1,3 +1,3 @@
1
- import { en, format, ja, plural, zhCN, zhTW } from "../format-7j0EzhuV.js";
1
+ import { en, format, ja, plural, zhCN, zhTW } from "../format-sYcnWvKw.js";
2
2
 
3
3
  export { en, format, ja, plural, zhCN, zhTW };
@@ -42,6 +42,8 @@ type Locale = {
42
42
  themes: string;
43
43
  assets: string;
44
44
  folders: string;
45
+ slides: string;
46
+ menu: string;
45
47
  newFolder: string;
46
48
  folderName: string;
47
49
  updateAvailable: string;
@@ -1,5 +1,5 @@
1
- import "../types-CHmFPIG_.js";
2
- import { OpenSlideConfig } from "../config-x493taft.js";
1
+ import "../types-CXTTzrhF.js";
2
+ import { OpenSlideConfig } from "../config-BK_GvWH8.js";
3
3
  import { InlineConfig } from "vite";
4
4
 
5
5
  //#region src/vite/config.d.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-slide/core",
3
- "version": "1.13.1",
3
+ "version": "1.13.3",
4
4
  "description": "Runtime and CLI for open-slide — write slides in slides/, we handle the rest.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -16,13 +16,17 @@ const FRAME_MORPH_MS = 180;
16
16
  const LAYOUT_TRACK_MS = PANEL_TRANSITION_MS + FRAME_MORPH_MS;
17
17
 
18
18
  export function InspectOverlay() {
19
- const { active, activate, slideId, selected, setSelected, cancel, openCrop } = useInspector();
19
+ const { active, slideId, selected, setSelected, cancel, openCrop } = useInspector();
20
20
  const overlayRef = useRef<HTMLDivElement>(null);
21
21
  const [hover, setHover] = useState<Highlight | null>(null);
22
22
 
23
23
  useEffect(() => {
24
+ if (!active) {
25
+ setHover(null);
26
+ return;
27
+ }
28
+
24
29
  const onKey = (e: KeyboardEvent) => {
25
- if (!active) return;
26
30
  if (e.key === 'Escape') {
27
31
  e.preventDefault();
28
32
  e.stopPropagation();
@@ -31,66 +35,52 @@ export function InspectOverlay() {
31
35
  };
32
36
 
33
37
  const onMove = (e: PointerEvent) => {
34
- if (!active) return;
35
38
  if (e.target instanceof Element && e.target.closest('[data-inspector-ui]')) {
36
39
  return setHover(null);
37
40
  }
38
- const hit = findInspectorHitAtPoint(e.clientX, e.clientY, slideId);
41
+ const el = pickInspectorTarget(pickElement(e.clientX, e.clientY));
42
+ if (!el) return setHover(null);
43
+ const hit = findSlideSource(el, slideId, { hostOnly: true });
39
44
  if (!hit) return setHover(null);
40
45
  setHover({ hit });
41
46
  };
42
47
 
43
- const onMouseDown = (e: MouseEvent) => {
44
- if (!active && e.detail < 2) return;
45
- if (e.target instanceof Element && e.target.closest('[data-inspector-ui]')) return;
46
- const hit = findInspectorHitAtPoint(e.clientX, e.clientY, slideId);
47
- if (!hit) return;
48
- e.preventDefault();
49
- };
50
-
51
48
  const onClick = (e: MouseEvent) => {
52
- if (!active) return;
53
49
  if (e.target instanceof Element && e.target.closest('[data-inspector-ui]')) return;
54
- const hit = findInspectorHitAtPoint(e.clientX, e.clientY, slideId);
50
+ const el = pickInspectorTarget(pickElement(e.clientX, e.clientY));
51
+ if (!el) return;
52
+ const hit = findSlideSource(el, slideId, { hostOnly: true });
55
53
  if (!hit) return;
56
54
  e.preventDefault();
57
55
  e.stopPropagation();
58
- clearTextSelection();
59
- activate();
60
56
  setSelected({ line: hit.line, column: hit.column, anchor: hit.anchor });
61
57
  setHover({ hit });
62
58
  };
63
59
 
64
60
  const onDblClick = (e: MouseEvent) => {
65
61
  if (e.target instanceof Element && e.target.closest('[data-inspector-ui]')) return;
66
- const hit = findInspectorHitAtPoint(e.clientX, e.clientY, slideId);
62
+ const el = pickInspectorTarget(pickElement(e.clientX, e.clientY));
63
+ if (!el) return;
64
+ const hit = findSlideSource(el, slideId, { hostOnly: true });
67
65
  if (!hit) return;
66
+ if (!(hit.anchor instanceof HTMLImageElement)) return;
68
67
  e.preventDefault();
69
68
  e.stopPropagation();
70
- clearTextSelection();
71
- if (!active) activate();
72
69
  setSelected({ line: hit.line, column: hit.column, anchor: hit.anchor });
73
- setHover({ hit });
74
- if (active && hit.anchor instanceof HTMLImageElement) openCrop(hit.anchor);
70
+ openCrop(hit.anchor);
75
71
  };
76
72
 
77
73
  window.addEventListener('pointermove', onMove, true);
78
- window.addEventListener('mousedown', onMouseDown, true);
79
74
  window.addEventListener('click', onClick, true);
80
75
  window.addEventListener('dblclick', onDblClick, true);
81
76
  window.addEventListener('keydown', onKey, true);
82
77
  return () => {
83
78
  window.removeEventListener('pointermove', onMove, true);
84
- window.removeEventListener('mousedown', onMouseDown, true);
85
79
  window.removeEventListener('click', onClick, true);
86
80
  window.removeEventListener('dblclick', onDblClick, true);
87
81
  window.removeEventListener('keydown', onKey, true);
88
82
  };
89
- }, [active, activate, slideId, setSelected, cancel, openCrop]);
90
-
91
- useEffect(() => {
92
- if (!active) setHover(null);
93
- }, [active]);
83
+ }, [active, slideId, setSelected, cancel, openCrop]);
94
84
 
95
85
  const hoverAnchor = hover?.hit.anchor.isConnected ? hover.hit.anchor : null;
96
86
  const selectedAnchor = selected?.anchor.isConnected ? selected.anchor : null;
@@ -329,17 +319,6 @@ function pickElement(x: number, y: number): HTMLElement | null {
329
319
  return null;
330
320
  }
331
321
 
332
- function findInspectorHitAtPoint(x: number, y: number, slideId: string): SlideSourceHit | null {
333
- const el = pickInspectorTarget(pickElement(x, y));
334
- if (!el) return null;
335
- return findSlideSource(el, slideId, { hostOnly: true });
336
- }
337
-
338
- function clearTextSelection() {
339
- const selection = window.getSelection();
340
- if (selection && !selection.isCollapsed) selection.removeAllRanges();
341
- }
342
-
343
322
  const INLINE_TEXT_TAGS = new Set([
344
323
  'B',
345
324
  'CODE',
@@ -244,7 +244,6 @@ function replayDomTextRangeStyles(el: HTMLElement, html: string, ops: TextRangeS
244
244
  type InspectorCtx = {
245
245
  slideId: string;
246
246
  active: boolean;
247
- activate: () => void;
248
247
  toggle: () => void;
249
248
  cancel: () => void;
250
249
  comments: SlideComment[];
@@ -285,14 +284,11 @@ export function InspectorProvider({
285
284
  pageIndex: number;
286
285
  children: ReactNode;
287
286
  }) {
288
- const [manualActive, setManualActive] = useState(false);
289
- const [heldActive, setHeldActive] = useState(false);
287
+ const [active, setActive] = useState(false);
290
288
  const [selected, setSelected] = useState<SelectedTarget | null>(null);
291
289
  const { comments, error, refetch, add, remove } = useComments(slideId);
292
290
  const { applyEdit, applyEdits } = useEditor(slideId);
293
291
  const history = useHistory();
294
- const active = manualActive || heldActive;
295
- const manualActiveRef = useRef(manualActive);
296
292
 
297
293
  const pendingRef = useRef<Map<string, Bucket>>(new Map());
298
294
  const instanceCounterRef = useRef(0);
@@ -919,24 +915,15 @@ export function InspectorProvider({
919
915
  return () => observer.disconnect();
920
916
  }, [selected]);
921
917
 
922
- const activate = useCallback(() => {
923
- manualActiveRef.current = true;
924
- setManualActive(true);
925
- }, []);
926
-
927
918
  const toggle = useCallback(() => {
928
- setManualActive((a) => {
929
- if (a && !heldActive) setSelected(null);
930
- const next = !a;
931
- manualActiveRef.current = next;
932
- return next;
919
+ setActive((a) => {
920
+ if (a) setSelected(null);
921
+ return !a;
933
922
  });
934
- }, [heldActive]);
923
+ }, []);
935
924
 
936
925
  const cancel = useCallback(() => {
937
- manualActiveRef.current = false;
938
- setManualActive(false);
939
- setHeldActive(false);
926
+ setActive(false);
940
927
  setSelected(null);
941
928
  }, []);
942
929
 
@@ -961,39 +948,6 @@ export function InspectorProvider({
961
948
  return () => window.removeEventListener('keydown', onKey);
962
949
  }, [toggle]);
963
950
 
964
- useEffect(() => {
965
- if (import.meta.env.PROD) return;
966
-
967
- const isApplePlatform = /Mac|iPhone|iPad|iPod/.test(
968
- `${navigator.platform} ${navigator.userAgent}`,
969
- );
970
- const holdKey = isApplePlatform ? 'Meta' : 'Control';
971
-
972
- const onKeyDown = (e: KeyboardEvent) => {
973
- if (e.repeat) return;
974
- if (e.target instanceof HTMLElement && e.target.matches('input, textarea')) return;
975
- if (e.key !== holdKey) return;
976
- setHeldActive(true);
977
- };
978
-
979
- const releaseHeld = (e?: KeyboardEvent) => {
980
- if (e && e.key !== holdKey) return;
981
- setHeldActive(false);
982
- if (!manualActiveRef.current) setSelected(null);
983
- };
984
-
985
- const onBlur = () => releaseHeld();
986
-
987
- window.addEventListener('keydown', onKeyDown, true);
988
- window.addEventListener('keyup', releaseHeld, true);
989
- window.addEventListener('blur', onBlur, true);
990
- return () => {
991
- window.removeEventListener('keydown', onKeyDown, true);
992
- window.removeEventListener('keyup', releaseHeld, true);
993
- window.removeEventListener('blur', onBlur, true);
994
- };
995
- }, []);
996
-
997
951
  const openCrop = useCallback((anchor: HTMLImageElement) => {
998
952
  const loc = anchor.dataset.slideLoc;
999
953
  if (!loc) return;
@@ -1019,7 +973,6 @@ export function InspectorProvider({
1019
973
  () => ({
1020
974
  slideId,
1021
975
  active,
1022
- activate,
1023
976
  toggle,
1024
977
  cancel,
1025
978
  comments,
@@ -1042,7 +995,6 @@ export function InspectorProvider({
1042
995
  [
1043
996
  slideId,
1044
997
  active,
1045
- activate,
1046
998
  toggle,
1047
999
  cancel,
1048
1000
  comments,
@@ -65,6 +65,9 @@ type Row =
65
65
  onChangeIcon: (icon: FolderIcon) => void;
66
66
  onDelete: () => void;
67
67
  }
68
+ | {
69
+ kind: 'all';
70
+ }
68
71
  | {
69
72
  kind: 'draft';
70
73
  }
@@ -95,7 +98,7 @@ export function FolderItem({
95
98
  const slideDragActive = useSlideDragActive();
96
99
  const t = useLocale();
97
100
 
98
- const acceptsSlideDrop = row.kind !== 'themes' && row.kind !== 'assets';
101
+ const acceptsSlideDrop = row.kind === 'draft' || row.kind === 'folder';
99
102
  const isSlideDrag = (e: React.DragEvent) =>
100
103
  acceptsSlideDrop && e.dataTransfer.types.includes(SLIDE_DND_MIME);
101
104
  const handleDragEnter = (e: React.DragEvent) => {
@@ -124,21 +127,25 @@ export function FolderItem({
124
127
  };
125
128
 
126
129
  const icon: FolderIcon =
127
- row.kind === 'draft'
128
- ? { type: 'emoji', value: '📝' }
129
- : row.kind === 'themes'
130
- ? { type: 'emoji', value: '🎨' }
131
- : row.kind === 'assets'
132
- ? { type: 'emoji', value: '🗂️' }
133
- : row.folder.icon;
130
+ row.kind === 'all'
131
+ ? { type: 'emoji', value: '🎞️' }
132
+ : row.kind === 'draft'
133
+ ? { type: 'emoji', value: '📝' }
134
+ : row.kind === 'themes'
135
+ ? { type: 'emoji', value: '🎨' }
136
+ : row.kind === 'assets'
137
+ ? { type: 'emoji', value: '🗂️' }
138
+ : row.folder.icon;
134
139
  const label =
135
- row.kind === 'draft'
136
- ? t.home.draft
137
- : row.kind === 'themes'
138
- ? t.home.themes
139
- : row.kind === 'assets'
140
- ? t.home.assets
141
- : row.folder.name;
140
+ row.kind === 'all'
141
+ ? t.home.slides
142
+ : row.kind === 'draft'
143
+ ? t.home.draft
144
+ : row.kind === 'themes'
145
+ ? t.home.themes
146
+ : row.kind === 'assets'
147
+ ? t.home.assets
148
+ : row.folder.name;
142
149
 
143
150
  const commitRename = () => {
144
151
  if (row.kind !== 'folder') return;
@@ -11,6 +11,7 @@ import { FolderIconChip, FolderItem } from './folder-item';
11
11
  import { IconPicker, PRESET_COLORS } from './icon-picker';
12
12
  import { SidebarFooter } from './sidebar-footer';
13
13
 
14
+ export const ALL_SLIDES_ID = '__all__';
14
15
  export const DRAFT_ID = 'draft';
15
16
  export const THEMES_ID = '__themes__';
16
17
  export const ASSETS_ID = '__assets__';
@@ -20,6 +21,7 @@ export const FOLDER_DND_MIME = 'application/x-folder-id';
20
21
  export function Sidebar({
21
22
  folders,
22
23
  countFor,
24
+ allCount,
23
25
  themesCount,
24
26
  assetsCount,
25
27
  selectedId,
@@ -34,6 +36,7 @@ export function Sidebar({
34
36
  }: {
35
37
  folders: Folder[];
36
38
  countFor: (folderId: string | null) => number;
39
+ allCount: number;
37
40
  themesCount: number;
38
41
  assetsCount: number;
39
42
  selectedId: string;
@@ -134,11 +137,11 @@ export function Sidebar({
134
137
 
135
138
  <div className="px-2">
136
139
  <FolderItem
137
- row={{ kind: 'draft' }}
138
- count={countFor(null)}
139
- selected={selectedId === DRAFT_ID}
140
- onSelect={() => onSelect(DRAFT_ID)}
141
- onDropSlide={onDropToDraft}
140
+ row={{ kind: 'all' }}
141
+ count={allCount}
142
+ selected={selectedId === ALL_SLIDES_ID}
143
+ onSelect={() => onSelect(ALL_SLIDES_ID)}
144
+ onDropSlide={() => {}}
142
145
  />
143
146
  <FolderItem
144
147
  row={{ kind: 'themes' }}
@@ -162,6 +165,13 @@ export function Sidebar({
162
165
  </div>
163
166
 
164
167
  <div className="flex-1 overflow-y-auto px-2 pb-2">
168
+ <FolderItem
169
+ row={{ kind: 'draft' }}
170
+ count={countFor(null)}
171
+ selected={selectedId === DRAFT_ID}
172
+ onSelect={() => onSelect(DRAFT_ID)}
173
+ onDropSlide={onDropToDraft}
174
+ />
165
175
  {folders.map((folder) => {
166
176
  const isDropTarget = dropTarget?.id === folder.id;
167
177
  const before = isDropTarget && dropTarget.before;
@@ -16,7 +16,7 @@ import {
16
16
  } from '@dnd-kit/sortable';
17
17
  import { CSS } from '@dnd-kit/utilities';
18
18
  import { Copy, Grid2x2, ListOrdered, type LucideIcon, Sparkles, Trash2 } from 'lucide-react';
19
- import { Fragment, useCallback, useEffect, useRef, useState } from 'react';
19
+ import { Fragment, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
20
20
  import {
21
21
  ContextMenu,
22
22
  ContextMenuContent,
@@ -62,6 +62,11 @@ const DEFAULT_VERTICAL_THUMB_WIDTH = 184;
62
62
  const VERTICAL_RAIL_CHROME = 80;
63
63
  const MIN_VERTICAL_THUMB_WIDTH = 120;
64
64
  const HORIZONTAL_THUMB_HEIGHT = 64;
65
+ const HORIZONTAL_THUMB_GAP = 8;
66
+ const HORIZONTAL_RAIL_PADDING_X = 12;
67
+ const HORIZONTAL_RAIL_PADDING_Y = 10;
68
+ const HORIZONTAL_LABEL_HEIGHT = 12;
69
+ const HORIZONTAL_LABEL_GAP = 6;
65
70
  const VERTICAL_THUMB_PADDING_Y = 12;
66
71
  const VERTICAL_THUMB_GAP = 8;
67
72
  const VIRTUAL_OVERSCAN = 4;
@@ -177,60 +182,16 @@ export function ThumbnailRail({
177
182
  return (
178
183
  <div className="bg-sidebar">
179
184
  <div className="overflow-x-auto overflow-y-hidden">
180
- <div className="flex items-center gap-2 px-3 py-2.5">
181
- {pages.map((PageComp, i) => {
182
- const active = i === current;
183
- const button = (
184
- <button
185
- // biome-ignore lint/suspicious/noArrayIndexKey: pages list is render-stable
186
- key={i}
187
- type="button"
188
- ref={active ? activeRef : undefined}
189
- onClick={() => onSelect(i)}
190
- aria-label={format(t.thumbnailRail.goToPageAria, { n: i + 1 })}
191
- aria-current={active ? 'true' : undefined}
192
- className={cn('group/thumb relative flex shrink-0 flex-col items-center gap-1.5')}
193
- >
194
- <span
195
- className={cn(
196
- 'font-mono text-[9.5px] font-medium tracking-[0.06em] tabular-nums uppercase',
197
- active ? 'text-brand' : 'text-muted-foreground/70',
198
- )}
199
- >
200
- {(i + 1).toString().padStart(2, '0')}
201
- </span>
202
- <div
203
- className={cn(
204
- 'relative shrink-0 overflow-hidden rounded-[4px] border bg-card motion-safe:transition-[border-color,box-shadow]',
205
- active
206
- ? 'border-brand shadow-[0_0_0_1px_var(--brand)]'
207
- : 'border-hairline group-hover/thumb:border-foreground/25',
208
- )}
209
- style={{ width: horizontalWidth, height: HORIZONTAL_THUMB_HEIGHT }}
210
- >
211
- <SlideCanvas scale={scale} center={false} flat freezeMotion design={design}>
212
- <SlidePageProvider index={i} total={pages.length}>
213
- <PageComp />
214
- </SlidePageProvider>
215
- </SlideCanvas>
216
- </div>
217
- </button>
218
- );
219
- if (!actions) return button;
220
- return (
221
- <ThumbContextMenu
222
- // biome-ignore lint/suspicious/noArrayIndexKey: pages list is render-stable
223
- key={i}
224
- index={i}
225
- actions={actions}
226
- pageCount={pages.length}
227
- ariaLabel={format(t.thumbnailRail.pageActionsAria, { n: i + 1 })}
228
- >
229
- {button}
230
- </ThumbContextMenu>
231
- );
232
- })}
233
- </div>
185
+ <HorizontalVirtualThumbList
186
+ pages={pages}
187
+ design={design}
188
+ current={current}
189
+ actions={actions}
190
+ activeRef={activeRef}
191
+ onSelect={onSelect}
192
+ scale={scale}
193
+ thumbWidth={horizontalWidth}
194
+ />
234
195
  </div>
235
196
  </div>
236
197
  );
@@ -306,6 +267,166 @@ function thumbButtonClass(active: boolean): string {
306
267
  );
307
268
  }
308
269
 
270
+ function HorizontalVirtualThumbList({
271
+ pages,
272
+ design,
273
+ current,
274
+ actions,
275
+ activeRef,
276
+ onSelect,
277
+ scale,
278
+ thumbWidth,
279
+ }: {
280
+ pages: Page[];
281
+ design?: DesignSystem;
282
+ current: number;
283
+ actions?: ThumbnailActions;
284
+ activeRef: React.MutableRefObject<HTMLButtonElement | null>;
285
+ onSelect: (index: number) => void;
286
+ scale: number;
287
+ thumbWidth: number;
288
+ }) {
289
+ const rootRef = useRef<HTMLDivElement | null>(null);
290
+ const viewportRef = useRef<HTMLElement | null>(null);
291
+ const t = useLocale();
292
+ const itemWidth = thumbWidth + HORIZONTAL_THUMB_GAP;
293
+ const listHeight =
294
+ HORIZONTAL_RAIL_PADDING_Y * 2 +
295
+ HORIZONTAL_LABEL_HEIGHT +
296
+ HORIZONTAL_LABEL_GAP +
297
+ HORIZONTAL_THUMB_HEIGHT;
298
+ const [range, setRange] = useState(() => getInitialVisibleRange(current, pages.length));
299
+
300
+ const updateRange = useCallback(() => {
301
+ const viewport = viewportRef.current;
302
+ if (!viewport) return;
303
+ const scrollLeft = Math.max(0, viewport.scrollLeft - HORIZONTAL_RAIL_PADDING_X);
304
+ setRange(getVisibleRange(scrollLeft, pages.length, viewport.clientWidth, itemWidth));
305
+ }, [itemWidth, pages.length]);
306
+
307
+ useLayoutEffect(() => {
308
+ const root = rootRef.current;
309
+ const viewport = root?.parentElement;
310
+ if (!viewport) return;
311
+ viewportRef.current = viewport;
312
+
313
+ let frame = 0;
314
+ const scheduleUpdate = () => {
315
+ cancelAnimationFrame(frame);
316
+ frame = requestAnimationFrame(updateRange);
317
+ };
318
+ const resizeObserver = new ResizeObserver(scheduleUpdate);
319
+
320
+ viewport.addEventListener('scroll', scheduleUpdate, { passive: true });
321
+ resizeObserver.observe(viewport);
322
+ scheduleUpdate();
323
+
324
+ return () => {
325
+ cancelAnimationFrame(frame);
326
+ viewport.removeEventListener('scroll', scheduleUpdate);
327
+ resizeObserver.disconnect();
328
+ if (viewportRef.current === viewport) viewportRef.current = null;
329
+ };
330
+ }, [updateRange]);
331
+
332
+ useLayoutEffect(() => {
333
+ if (pages.length <= 0) return;
334
+ const viewport = viewportRef.current ?? rootRef.current?.parentElement;
335
+ if (!viewport) return;
336
+ viewportRef.current = viewport;
337
+
338
+ const clampedCurrent = Math.min(Math.max(current, 0), pages.length - 1);
339
+ const left = HORIZONTAL_RAIL_PADDING_X + clampedCurrent * itemWidth;
340
+ const right = left + thumbWidth;
341
+ const viewportLeft = viewport.scrollLeft;
342
+ const viewportRight = viewportLeft + viewport.clientWidth;
343
+
344
+ if (left < viewportLeft) {
345
+ viewport.scrollLeft = left;
346
+ } else if (right > viewportRight) {
347
+ viewport.scrollLeft = right - viewport.clientWidth;
348
+ }
349
+
350
+ const scrollLeft = Math.max(0, viewport.scrollLeft - HORIZONTAL_RAIL_PADDING_X);
351
+ setRange(getVisibleRange(scrollLeft, pages.length, viewport.clientWidth, itemWidth));
352
+ }, [current, itemWidth, pages.length, thumbWidth]);
353
+
354
+ const visibleRange = clampVisibleRange(range, current, pages.length);
355
+ const visible = [];
356
+ for (let i = visibleRange.start; i < visibleRange.end; i++) {
357
+ const PageComp = pages[i];
358
+ const active = i === current;
359
+ const button = (
360
+ <button
361
+ type="button"
362
+ ref={active ? activeRef : undefined}
363
+ onClick={() => onSelect(i)}
364
+ aria-label={format(t.thumbnailRail.goToPageAria, { n: i + 1 })}
365
+ aria-current={active ? 'true' : undefined}
366
+ className={cn('group/thumb relative flex shrink-0 flex-col items-center gap-1.5')}
367
+ >
368
+ <span
369
+ className={cn(
370
+ 'font-mono text-[9.5px] font-medium tracking-[0.06em] tabular-nums uppercase',
371
+ active ? 'text-brand' : 'text-muted-foreground/70',
372
+ )}
373
+ >
374
+ {(i + 1).toString().padStart(2, '0')}
375
+ </span>
376
+ <div
377
+ className={cn(
378
+ 'relative shrink-0 overflow-hidden rounded-[4px] border bg-card motion-safe:transition-[border-color,box-shadow]',
379
+ active
380
+ ? 'border-brand shadow-[0_0_0_1px_var(--brand)]'
381
+ : 'border-hairline group-hover/thumb:border-foreground/25',
382
+ )}
383
+ style={{ width: thumbWidth, height: HORIZONTAL_THUMB_HEIGHT }}
384
+ >
385
+ <SlideCanvas scale={scale} center={false} flat freezeMotion design={design}>
386
+ <SlidePageProvider index={i} total={pages.length}>
387
+ <PageComp />
388
+ </SlidePageProvider>
389
+ </SlideCanvas>
390
+ </div>
391
+ </button>
392
+ );
393
+
394
+ visible.push(
395
+ <div
396
+ key={i}
397
+ className="absolute top-2.5"
398
+ style={{ left: HORIZONTAL_RAIL_PADDING_X + i * itemWidth, width: thumbWidth }}
399
+ >
400
+ {actions ? (
401
+ <ThumbContextMenu
402
+ index={i}
403
+ actions={actions}
404
+ pageCount={pages.length}
405
+ ariaLabel={format(t.thumbnailRail.pageActionsAria, { n: i + 1 })}
406
+ >
407
+ {button}
408
+ </ThumbContextMenu>
409
+ ) : (
410
+ button
411
+ )}
412
+ </div>,
413
+ );
414
+ }
415
+
416
+ return (
417
+ <div
418
+ ref={rootRef}
419
+ className="relative"
420
+ style={{
421
+ width: HORIZONTAL_RAIL_PADDING_X * 2 + pages.length * itemWidth - HORIZONTAL_THUMB_GAP,
422
+ height: listHeight,
423
+ }}
424
+ >
425
+ {visible}
426
+ </div>
427
+ );
428
+ }
429
+
309
430
  function VirtualThumbList({
310
431
  pages,
311
432
  current,
@@ -1,12 +1,21 @@
1
+ import { Menu } from 'lucide-react';
1
2
  import { useCallback, useMemo, useState } from 'react';
2
3
  import { Outlet, useLocation, useNavigate, useSearchParams } from 'react-router-dom';
3
4
  import { toast } from 'sonner';
5
+ import { LanguageToggle } from '@/components/language-toggle';
6
+ import { ThemeToggle } from '@/components/theme-toggle';
7
+ import {
8
+ DropdownMenu,
9
+ DropdownMenuContent,
10
+ DropdownMenuItem,
11
+ DropdownMenuTrigger,
12
+ } from '@/components/ui/dropdown-menu';
4
13
  import { useAssets } from '@/lib/assets';
5
14
  import { useFolders } from '@/lib/folders';
6
15
  import { format, useLocale } from '@/lib/use-locale';
7
16
  import { cn } from '@/lib/utils';
8
- import { MobileFolderPill } from '../components/sidebar/mobile-pill';
9
- import { ASSETS_ID, DRAFT_ID, Sidebar, THEMES_ID } from '../components/sidebar/sidebar';
17
+ import { FolderIconChip } from '../components/sidebar/folder-item';
18
+ import { ALL_SLIDES_ID, ASSETS_ID, Sidebar, THEMES_ID } from '../components/sidebar/sidebar';
10
19
  import type { FoldersManifest } from '../lib/sdk';
11
20
  import { slideIds } from '../lib/slides';
12
21
  import { themes as themeRegistry } from '../lib/themes';
@@ -16,8 +25,9 @@ export type HomeOutletContext = {
16
25
  loading: boolean;
17
26
  draftSlides: string[];
18
27
  slidesByFolder: Record<string, string[]>;
19
- /** Selected folder id when on `/`; equals DRAFT_ID, a folder id, or THEMES_ID. */
28
+ /** Selected view id: ALL_SLIDES_ID, DRAFT_ID, a folder id, THEMES_ID, or ASSETS_ID. */
20
29
  selectedId: string;
30
+ selectFolder: (id: string) => void;
21
31
  reportTitle: (slideId: string, title: string) => void;
22
32
  titleMap: Record<string, string>;
23
33
  assign: (slideId: string, folderId: string | null) => Promise<void>;
@@ -29,7 +39,7 @@ export type HomeOutletContext = {
29
39
  function pathToSelectedId(pathname: string, search: URLSearchParams): string {
30
40
  if (pathname === '/themes' || pathname.startsWith('/themes/')) return THEMES_ID;
31
41
  if (pathname === '/assets') return ASSETS_ID;
32
- return search.get('f') ?? DRAFT_ID;
42
+ return search.get('f') ?? ALL_SLIDES_ID;
33
43
  }
34
44
 
35
45
  export function HomeShell() {
@@ -63,7 +73,7 @@ export function HomeShell() {
63
73
  (id: string) => {
64
74
  if (id === THEMES_ID) navigate('/themes', { replace: true });
65
75
  else if (id === ASSETS_ID) navigate('/assets', { replace: true });
66
- else if (id === DRAFT_ID) navigate('/', { replace: true });
76
+ else if (id === ALL_SLIDES_ID) navigate('/', { replace: true });
67
77
  else navigate(`/?f=${encodeURIComponent(id)}`, { replace: true });
68
78
  },
69
79
  [navigate],
@@ -115,6 +125,7 @@ export function HomeShell() {
115
125
  draftSlides,
116
126
  slidesByFolder,
117
127
  selectedId,
128
+ selectFolder,
118
129
  reportTitle,
119
130
  titleMap,
120
131
  assign,
@@ -129,6 +140,7 @@ export function HomeShell() {
129
140
  <Sidebar
130
141
  folders={manifest.folders}
131
142
  countFor={countFor}
143
+ allCount={slideIds.length}
132
144
  themesCount={themeRegistry.length}
133
145
  assetsCount={globalAssets.length}
134
146
  selectedId={selectedId}
@@ -138,7 +150,7 @@ export function HomeShell() {
138
150
  onChangeIcon={(id, icon) => update(id, { icon })}
139
151
  onDelete={async (id) => {
140
152
  const name = manifest.folders.find((f) => f.id === id)?.name ?? id;
141
- if (selectedId === id) selectFolder(DRAFT_ID);
153
+ if (selectedId === id) selectFolder(ALL_SLIDES_ID);
142
154
  try {
143
155
  await remove(id);
144
156
  toast.success(format(t.home.toastFolderDeleted, { name }));
@@ -161,40 +173,50 @@ export function HomeShell() {
161
173
  <div className="paper relative flex min-w-0 flex-1 flex-col overflow-y-auto bg-canvas">
162
174
  <div className="flex items-center justify-between border-b border-hairline bg-sidebar px-4 py-3 md:hidden">
163
175
  <h1 className="font-heading text-lg font-bold tracking-tight">{t.home.appTitle}</h1>
164
- </div>
165
- <div className="border-b border-hairline bg-sidebar px-4 py-2 md:hidden">
166
- <div className="flex gap-2 overflow-x-auto pb-1">
167
- <MobileFolderPill
168
- icon={{ type: 'emoji', value: '📝' }}
169
- label={t.home.draft}
170
- count={countFor(null)}
171
- active={selectedId === DRAFT_ID}
172
- onClick={() => selectFolder(DRAFT_ID)}
173
- />
174
- <MobileFolderPill
175
- icon={{ type: 'emoji', value: '🎨' }}
176
- label={t.home.themes}
177
- count={themeRegistry.length}
178
- active={selectedId === THEMES_ID}
179
- onClick={() => selectFolder(THEMES_ID)}
180
- />
181
- <MobileFolderPill
182
- icon={{ type: 'emoji', value: '🗂️' }}
183
- label={t.home.assets}
184
- count={globalAssets.length}
185
- active={selectedId === ASSETS_ID}
186
- onClick={() => selectFolder(ASSETS_ID)}
187
- />
188
- {manifest.folders.map((f) => (
189
- <MobileFolderPill
190
- key={f.id}
191
- icon={f.icon}
192
- label={f.name}
193
- count={countFor(f.id)}
194
- active={selectedId === f.id}
195
- onClick={() => selectFolder(f.id)}
196
- />
197
- ))}
176
+ <div className="-mr-1.5 flex items-center gap-0.5">
177
+ <LanguageToggle />
178
+ <ThemeToggle />
179
+ <DropdownMenu>
180
+ <DropdownMenuTrigger asChild>
181
+ <button
182
+ type="button"
183
+ aria-label={t.home.menu}
184
+ className="flex size-8 items-center justify-center rounded-[6px] text-muted-foreground hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground"
185
+ >
186
+ <Menu className="size-4" />
187
+ </button>
188
+ </DropdownMenuTrigger>
189
+ <DropdownMenuContent align="end" className="min-w-[200px]">
190
+ <DropdownMenuItem
191
+ onSelect={() => selectFolder(ALL_SLIDES_ID)}
192
+ className={cn(
193
+ selectedId !== THEMES_ID &&
194
+ selectedId !== ASSETS_ID &&
195
+ 'bg-muted text-foreground',
196
+ )}
197
+ >
198
+ <FolderIconChip icon={{ type: 'emoji', value: '🎞️' }} />
199
+ <span className="flex-1 truncate">{t.home.slides}</span>
200
+ <span className="folio">{slideIds.length.toString().padStart(2, '0')}</span>
201
+ </DropdownMenuItem>
202
+ <DropdownMenuItem
203
+ onSelect={() => selectFolder(THEMES_ID)}
204
+ className={cn(selectedId === THEMES_ID && 'bg-muted text-foreground')}
205
+ >
206
+ <FolderIconChip icon={{ type: 'emoji', value: '🎨' }} />
207
+ <span className="flex-1 truncate">{t.home.themes}</span>
208
+ <span className="folio">{themeRegistry.length.toString().padStart(2, '0')}</span>
209
+ </DropdownMenuItem>
210
+ <DropdownMenuItem
211
+ onSelect={() => selectFolder(ASSETS_ID)}
212
+ className={cn(selectedId === ASSETS_ID && 'bg-muted text-foreground')}
213
+ >
214
+ <FolderIconChip icon={{ type: 'emoji', value: '🗂️' }} />
215
+ <span className="flex-1 truncate">{t.home.assets}</span>
216
+ <span className="folio">{globalAssets.length.toString().padStart(2, '0')}</span>
217
+ </DropdownMenuItem>
218
+ </DropdownMenuContent>
219
+ </DropdownMenu>
198
220
  </div>
199
221
  </div>
200
222
 
@@ -33,11 +33,11 @@ import {
33
33
  import { format, useLocale } from '@/lib/use-locale';
34
34
  import { cn } from '@/lib/utils';
35
35
  import { FolderIconChip, SLIDE_DND_MIME } from '../components/sidebar/folder-item';
36
- import { DRAFT_ID } from '../components/sidebar/sidebar';
36
+ import { ALL_SLIDES_ID, DRAFT_ID } from '../components/sidebar/sidebar';
37
37
  import { SlideCanvas } from '../components/slide-canvas';
38
38
  import { SlidePageProvider } from '../lib/page-context';
39
39
  import type { Folder, FolderIcon, SlideModule } from '../lib/sdk';
40
- import { loadSlide, slideCreatedAt } from '../lib/slides';
40
+ import { loadSlide, slideCreatedAt, slideIds } from '../lib/slides';
41
41
  import type { HomeOutletContext } from './home-shell';
42
42
 
43
43
  type SortKey = 'created-desc' | 'created-asc' | 'title-asc' | 'title-desc';
@@ -76,6 +76,7 @@ export function Home() {
76
76
  draftSlides,
77
77
  slidesByFolder,
78
78
  selectedId,
79
+ selectFolder,
79
80
  reportTitle,
80
81
  titleMap,
81
82
  assign,
@@ -85,13 +86,21 @@ export function Home() {
85
86
  } = useOutletContext<HomeOutletContext>();
86
87
  const t = useLocale();
87
88
 
88
- const selectedFolder =
89
- selectedId === DRAFT_ID ? null : (manifest.folders.find((f) => f.id === selectedId) ?? null);
90
- const visibleSlides = selectedId === DRAFT_ID ? draftSlides : (slidesByFolder[selectedId] ?? []);
91
-
92
- const title = selectedFolder?.name ?? t.home.draft;
93
- const headerIcon = selectedFolder?.icon ?? { type: 'emoji' as const, value: '📝' };
89
+ const isAll = selectedId === ALL_SLIDES_ID;
94
90
  const isDraft = selectedId === DRAFT_ID;
91
+ const selectedFolder =
92
+ isAll || isDraft ? null : (manifest.folders.find((f) => f.id === selectedId) ?? null);
93
+ const visibleSlides = isAll
94
+ ? slideIds
95
+ : isDraft
96
+ ? draftSlides
97
+ : (slidesByFolder[selectedId] ?? []);
98
+
99
+ const title = selectedFolder?.name ?? (isAll ? t.home.slides : t.home.draft);
100
+ const headerIcon = selectedFolder?.icon ?? {
101
+ type: 'emoji' as const,
102
+ value: isAll ? '🎞️' : '📝',
103
+ };
95
104
 
96
105
  const [query, setQuery] = useState('');
97
106
  const [sortKey, setSortKey] = useSortPref();
@@ -133,6 +142,48 @@ export function Home() {
133
142
  <h1 className="font-heading text-[32px] font-semibold leading-[1.05] tracking-[-0.025em] md:text-[44px]">
134
143
  {title}
135
144
  </h1>
145
+ <DropdownMenu>
146
+ <DropdownMenuTrigger asChild>
147
+ <button
148
+ type="button"
149
+ aria-label={t.home.folders}
150
+ className="flex size-7 items-center justify-center rounded-[6px] border border-border bg-card text-muted-foreground hover:text-foreground aria-expanded:border-foreground/40 aria-expanded:text-foreground md:hidden"
151
+ >
152
+ <ChevronDown className="size-4" />
153
+ </button>
154
+ </DropdownMenuTrigger>
155
+ <DropdownMenuContent align="start" className="min-w-[200px]">
156
+ <DropdownMenuItem
157
+ onSelect={() => selectFolder(ALL_SLIDES_ID)}
158
+ className={cn(isAll && 'bg-muted text-foreground')}
159
+ >
160
+ <FolderIconChip icon={{ type: 'emoji', value: '🎞️' }} />
161
+ <span className="flex-1 truncate">{t.home.slides}</span>
162
+ <span className="folio">{slideIds.length.toString().padStart(2, '0')}</span>
163
+ </DropdownMenuItem>
164
+ <DropdownMenuItem
165
+ onSelect={() => selectFolder(DRAFT_ID)}
166
+ className={cn(isDraft && 'bg-muted text-foreground')}
167
+ >
168
+ <FolderIconChip icon={{ type: 'emoji', value: '📝' }} />
169
+ <span className="flex-1 truncate">{t.home.draft}</span>
170
+ <span className="folio">{draftSlides.length.toString().padStart(2, '0')}</span>
171
+ </DropdownMenuItem>
172
+ {manifest.folders.map((f) => (
173
+ <DropdownMenuItem
174
+ key={f.id}
175
+ onSelect={() => selectFolder(f.id)}
176
+ className={cn(selectedId === f.id && 'bg-muted text-foreground')}
177
+ >
178
+ <FolderIconChip icon={f.icon} />
179
+ <span className="flex-1 truncate">{f.name}</span>
180
+ <span className="folio">
181
+ {(slidesByFolder[f.id]?.length ?? 0).toString().padStart(2, '0')}
182
+ </span>
183
+ </DropdownMenuItem>
184
+ ))}
185
+ </DropdownMenuContent>
186
+ </DropdownMenu>
136
187
  {!loading && (
137
188
  <span className="folio ml-1 self-end pb-2">
138
189
  {(isSearching ? filteredSlides.length : visibleSlides.length)
@@ -155,7 +206,7 @@ export function Home() {
155
206
  {loading ? (
156
207
  <HomeLoading />
157
208
  ) : visibleSlides.length === 0 ? (
158
- <EmptyState isDraft={isDraft} folderName={selectedFolder?.name} />
209
+ <EmptyState isDraft={isAll || isDraft} folderName={selectedFolder?.name} />
159
210
  ) : filteredSlides.length === 0 ? (
160
211
  <NoResultsState query={query} onClear={() => setQuery('')} />
161
212
  ) : (
package/src/locale/en.ts CHANGED
@@ -42,6 +42,8 @@ export const en: Locale = {
42
42
  themes: 'Themes',
43
43
  assets: 'Assets',
44
44
  folders: 'Folders',
45
+ slides: 'Slides',
46
+ menu: 'Menu',
45
47
  newFolder: 'New folder',
46
48
  folderName: 'Folder name',
47
49
  updateAvailable: 'open-slide {version} is available — update the package to get the latest.',
package/src/locale/ja.ts CHANGED
@@ -42,6 +42,8 @@ export const ja: Locale = {
42
42
  themes: 'テーマ',
43
43
  assets: 'アセット',
44
44
  folders: 'フォルダ',
45
+ slides: 'スライド',
46
+ menu: 'メニュー',
45
47
  newFolder: '新規フォルダ',
46
48
  folderName: 'フォルダ名',
47
49
  updateAvailable:
@@ -42,6 +42,8 @@ export type Locale = {
42
42
  themes: string;
43
43
  assets: string;
44
44
  folders: string;
45
+ slides: string;
46
+ menu: string;
45
47
  newFolder: string;
46
48
  folderName: string;
47
49
  updateAvailable: string;
@@ -42,6 +42,8 @@ export const zhCN: Locale = {
42
42
  themes: '主题',
43
43
  assets: '素材',
44
44
  folders: '文件夹',
45
+ slides: '幻灯片',
46
+ menu: '菜单',
45
47
  newFolder: '新建文件夹',
46
48
  folderName: '文件夹名称',
47
49
  updateAvailable: 'open-slide {version} 已发布,请更新软件包以获取最新版本。',
@@ -42,6 +42,8 @@ export const zhTW: Locale = {
42
42
  themes: '主題',
43
43
  assets: '素材',
44
44
  folders: '資料夾',
45
+ slides: '投影片',
46
+ menu: '選單',
45
47
  newFolder: '新增資料夾',
46
48
  folderName: '資料夾名稱',
47
49
  updateAvailable: 'open-slide {version} 已發布,請更新套件以取得最新版本。',
@@ -1,34 +0,0 @@
1
- import { cn } from '@/lib/utils';
2
- import type { FolderIcon } from '../../lib/sdk';
3
- import { FolderIconChip } from './folder-item';
4
-
5
- export function MobileFolderPill({
6
- icon,
7
- label,
8
- count,
9
- active,
10
- onClick,
11
- }: {
12
- icon: FolderIcon;
13
- label: string;
14
- count: number;
15
- active: boolean;
16
- onClick: () => void;
17
- }) {
18
- return (
19
- <button
20
- type="button"
21
- onClick={onClick}
22
- className={cn(
23
- 'flex shrink-0 items-center gap-1.5 rounded-[5px] border px-2.5 py-1 text-[11.5px] font-medium transition-colors',
24
- active
25
- ? 'border-foreground/40 bg-foreground text-background'
26
- : 'border-border bg-card text-muted-foreground hover:text-foreground',
27
- )}
28
- >
29
- <FolderIconChip icon={icon} className="size-3.5 text-sm" />
30
- <span className="max-w-[8rem] truncate">{label}</span>
31
- <span className="folio nums">{count.toString().padStart(2, '0')}</span>
32
- </button>
33
- );
34
- }