@legendapp/spark 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/package.json +3 -3
  2. package/skills/spark/UPGRADING.md +58 -0
  3. package/skills/spark/storage-settings.md +2 -28
  4. package/skills/spark/ui.md +27 -1
  5. package/vendor/node_modules/@legendapp/spark-ai/package.json +3 -3
  6. package/vendor/node_modules/@legendapp/spark-audio/package.json +2 -2
  7. package/vendor/node_modules/@legendapp/spark-auth-session/package.json +3 -3
  8. package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +43 -24
  9. package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.cjs +3 -0
  10. package/vendor/node_modules/@legendapp/spark-cli/dist/package.js +4 -8
  11. package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +1 -1
  12. package/vendor/node_modules/@legendapp/spark-cli/dist/publish-directory.js +32 -0
  13. package/vendor/node_modules/@legendapp/spark-cli/dist/release-app.js +139 -0
  14. package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +21 -21
  15. package/vendor/node_modules/@legendapp/spark-cli/dist/signing.js +61 -41
  16. package/vendor/node_modules/@legendapp/spark-cli/package.json +4 -4
  17. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +2 -2
  18. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +2 -2
  19. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +2 -2
  20. package/vendor/node_modules/@legendapp/spark-clipboard/package.json +2 -2
  21. package/vendor/node_modules/@legendapp/spark-codex/package.json +2 -2
  22. package/vendor/node_modules/@legendapp/spark-commands/package.json +5 -5
  23. package/vendor/node_modules/@legendapp/spark-context-menu/package.json +2 -2
  24. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.h +2 -0
  25. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.mm +1 -0
  26. package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +1 -1
  27. package/vendor/node_modules/@legendapp/spark-desktop-config/app.plugin.cjs +1 -0
  28. package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +3 -3
  29. package/vendor/node_modules/@legendapp/spark-desktop-config/rpaths.cjs +20 -0
  30. package/vendor/node_modules/@legendapp/spark-desktop-config/rpaths.d.cts +1 -0
  31. package/vendor/node_modules/@legendapp/spark-desktop-host/AppDelegate.mm +16 -5
  32. package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +2 -2
  33. package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +2 -2
  34. package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +2 -2
  35. package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +3 -3
  36. package/vendor/node_modules/@legendapp/spark-documents/package.json +7 -7
  37. package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +2 -2
  38. package/vendor/node_modules/@legendapp/spark-expo-compat/package.json +4 -4
  39. package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +2 -2
  40. package/vendor/node_modules/@legendapp/spark-file-system/package.json +2 -2
  41. package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +2 -2
  42. package/vendor/node_modules/@legendapp/spark-html/package.json +2 -2
  43. package/vendor/node_modules/@legendapp/spark-markdown/package.json +2 -2
  44. package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +2 -2
  45. package/vendor/node_modules/@legendapp/spark-native-menu/package.json +2 -2
  46. package/vendor/node_modules/@legendapp/spark-notifications/package.json +2 -2
  47. package/vendor/node_modules/@legendapp/spark-processes/package.json +2 -2
  48. package/vendor/node_modules/@legendapp/spark-rich-text/package.json +2 -2
  49. package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +2 -2
  50. package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
  51. package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +4 -4
  52. package/vendor/node_modules/@legendapp/spark-settings-ui/src/index.tsx +122 -334
  53. package/vendor/node_modules/@legendapp/spark-settings-ui/src/rows.tsx +183 -0
  54. package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
  55. package/vendor/node_modules/@legendapp/spark-system/package.json +2 -2
  56. package/vendor/node_modules/@legendapp/spark-tray/package.json +2 -2
  57. package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSegmentedControl.mm +2 -0
  58. package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSelect.mm +17 -1
  59. package/vendor/node_modules/@legendapp/spark-ui/macos/sidebar/RNSidebar.mm +20 -0
  60. package/vendor/node_modules/@legendapp/spark-ui/package.json +2 -2
  61. package/vendor/node_modules/@legendapp/spark-ui/src/availability.ts +2 -1
  62. package/vendor/node_modules/@legendapp/spark-ui/src/control.ts +1 -1
  63. package/vendor/node_modules/@legendapp/spark-ui/src/desktop.tsx +10 -8
  64. package/vendor/node_modules/@legendapp/spark-ui/src/index.android.tsx +7 -6
  65. package/vendor/node_modules/@legendapp/spark-ui/src/index.ios.tsx +10 -9
  66. package/vendor/node_modules/@legendapp/spark-ui/src/index.web.tsx +6 -4
  67. package/vendor/node_modules/@legendapp/spark-ui/src/native-select/NativeSelectNativeComponent.ts +1 -0
  68. package/vendor/node_modules/@legendapp/spark-ui/src/select.ts +4 -0
  69. package/vendor/node_modules/@legendapp/spark-ui/src/switch.tsx +13 -0
  70. package/vendor/node_modules/@legendapp/spark-ui/src/types.ts +16 -4
  71. package/vendor/node_modules/@legendapp/spark-updates/package.json +2 -2
  72. package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
  73. package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
  74. /package/{settings-window.ts → ui-settings.ts} +0 -0
@@ -1,51 +1,73 @@
1
1
  import { LegendList, type LegendListRef, type LegendListRenderItemProps } from "@legendapp/list/react-native";
2
- import { cn } from "@legendapp/spark-ui/src/classnames";
3
- import { SidebarSplitView, type SidebarSplitViewAppearance, type SidebarSplitViewResizeEvent } from "@legendapp/spark-ui/src/appkit-split-view";
2
+ import { SidebarSplitView, type SidebarSplitViewAppearance, type SidebarSplitViewResizeEvent, type SplitViewTitleBarOptions } from "@legendapp/spark-ui/src/appkit-split-view";
3
+ import { Sidebar, SidebarItem } from "@legendapp/spark-ui/src/sidebar";
4
+ import { SFSymbol } from "@legendapp/spark-ui/src/sf-symbol";
5
+ import { identifier } from "@legendapp/spark-ui/src/specialized";
4
6
  import { SparkError, nativeError } from "@legendapp/spark-desktop-app/src/contracts";
5
- import { createContext, type ReactNode, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
6
- import { Pressable, Platform, ScrollView, StyleSheet, Text, View } from "react-native";
7
+ import { Children, Fragment, isValidElement, type ReactNode, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
8
+ import { Platform, PlatformColor, StyleSheet, Text, View } from "react-native";
7
9
 
8
- const SETTINGS_SIDEBAR_TOP_INSET = 40;
9
- const SETTINGS_TITLEBAR_CONTENT_INSET = 56;
10
- const settingsContentInset = { bottom: 0, left: 0, right: 0, top: SETTINGS_TITLEBAR_CONTENT_INSET };
11
- const settingsSidebarPressablePlatformProps = Platform.OS === "macos" ? { enableFocusRing: false } : {};
12
- const SettingsRowGroupContext = createContext(false);
13
- // Load the windows API lazily, once, and share that import across every settings window.
10
+ export * from "./options";
11
+ export * from "./rows";
12
+
13
+ const TITLEBAR_HEIGHT = 52;
14
+ const titleBar: SplitViewTitleBarOptions = { content: { height: TITLEBAR_HEIGHT, material: "windowBackground" } };
14
15
  let windowsApi: Promise<typeof import("@legendapp/spark-desktop-windows/src/api")> | undefined;
15
16
  const loadWindowsApi = () => windowsApi ??= import("@legendapp/spark-desktop-windows/src/api");
16
- export * from "./options";
17
17
 
18
- export interface SettingsWindowPage<PageId extends string = string> {
18
+ export interface SettingsPageProps<PageId extends string = string> {
19
19
  id: PageId;
20
20
  title: string;
21
- render: () => ReactNode;
21
+ icon: string;
22
+ children: ReactNode;
23
+ }
24
+
25
+ export function SettingsPage({ children }: SettingsPageProps) {
26
+ return <>{children}</>;
22
27
  }
23
- export interface SettingsWindowBaseProps<PageId extends string = string> {
28
+
29
+ export type SettingsWindowSelectionProps<PageId extends string = string> =
30
+ | { selectedPageId: PageId; defaultPageId?: never; onSelectionChange: (pageId: PageId) => void }
31
+ | { selectedPageId?: never; defaultPageId?: PageId; onSelectionChange?: (pageId: PageId) => void };
32
+
33
+ export type SettingsWindowProps<PageId extends string = string> = SettingsWindowSelectionProps<PageId> & {
24
34
  /** Immutable for this mount. Remount to change the owning window. */
25
35
  windowId: string;
26
- pages: readonly SettingsWindowPage<PageId>[];
36
+ children: ReactNode;
27
37
  appearance?: SidebarSplitViewAppearance;
28
- backgroundClassName?: string;
29
- contentBackgroundClassName?: string;
30
- contentMinWidth?: number;
31
- sidebarMinWidth?: number;
32
38
  onError?: (error: SparkError) => void;
39
+ };
40
+
41
+ export type VirtualizedSettingsWindowProps<PageId extends string = string> = SettingsWindowProps<PageId>;
42
+
43
+ function childPages<PageId extends string>(children: ReactNode): SettingsPageProps<PageId>[] {
44
+ const pages: SettingsPageProps<PageId>[] = [];
45
+ Children.forEach(children, child => {
46
+ if (child === null) return;
47
+ if (isValidElement<{ children: ReactNode }>(child) && child.type === Fragment) {
48
+ pages.push(...childPages<PageId>(child.props.children));
49
+ } else if (isValidElement<SettingsPageProps<PageId>>(child) && child.type === SettingsPage) {
50
+ pages.push(child.props);
51
+ } else {
52
+ throw new SparkError("E_INVALID_ARGUMENT", "Settings windows require SettingsPage children or fragments");
53
+ }
54
+ });
55
+ return pages;
33
56
  }
34
- export type SettingsWindowSelectionProps<PageId extends string = string> =
35
- | { selectedPageId: PageId; defaultPageId?: never; onSelectionChange: (pageId: PageId) => void }
36
- | { selectedPageId?: never; defaultPageId?: PageId; onSelectionChange?: (pageId: PageId) => void };
37
- export type SettingsWindowProps<PageId extends string = string> = SettingsWindowBaseProps<PageId> & SettingsWindowSelectionProps<PageId>;
38
- export type VirtualizedSettingsWindowProps<PageId extends string = string> = SettingsWindowProps<PageId> & { estimatedItemSize?: number };
39
57
 
40
- function useSettingsSelection<PageId extends string>(props: SettingsWindowProps<PageId>) {
41
- const { pages, windowId, selectedPageId, defaultPageId, onSelectionChange } = props;
58
+ function useSettingsSelection<PageId extends string>(props: SettingsWindowProps<PageId>, pages: readonly SettingsPageProps<PageId>[]) {
59
+ const { windowId, selectedPageId, defaultPageId, onSelectionChange } = props;
42
60
  const controlled = selectedPageId !== undefined;
43
61
  const identity = useRef({ windowId, controlled });
44
- if (!windowId || windowId.includes("\0") || identity.current.windowId !== windowId) throw new SparkError("E_INVALID_ARGUMENT", "Settings windowId must be nonempty and immutable; remount to change it");
62
+ identifier(windowId, "settings window ID");
63
+ if (identity.current.windowId !== windowId) throw new SparkError("E_INVALID_ARGUMENT", "Settings windowId must be nonempty and immutable; remount to change it");
45
64
  if (identity.current.controlled !== controlled || (controlled && defaultPageId !== undefined) || (controlled && typeof onSelectionChange !== "function")) throw new SparkError("E_INVALID_ARGUMENT", "Settings selection must have one stable owner");
46
65
  const ids = new Set<string>();
47
66
  for (const page of pages) {
48
- if (!page.id || page.id.includes("\0") || ids.has(page.id) || !page.title || typeof page.render !== "function") throw new SparkError("E_INVALID_ARGUMENT", "Settings pages require unique nonempty IDs, titles and render callbacks");
67
+ identifier(page.id, "settings page ID");
68
+ identifier(page.title, "settings page title");
69
+ identifier(page.icon, "settings page icon");
70
+ if (ids.has(page.id)) throw new SparkError("E_INVALID_ARGUMENT", "Settings page IDs must be unique");
49
71
  ids.add(page.id);
50
72
  }
51
73
  if (!pages.length || (controlled && !ids.has(selectedPageId))) throw new SparkError("E_INVALID_ARGUMENT", "Settings selection must identify an existing page");
@@ -57,19 +79,19 @@ function useSettingsSelection<PageId extends string>(props: SettingsWindowProps<
57
79
  useEffect(() => { if (!controlled && local !== selected) setLocal(selected); }, [controlled, local, selected]);
58
80
  const [revision, setRevision] = useState(0);
59
81
  const requestSelection = useCallback((id: PageId) => {
60
- if (!pages.some(page => page.id === id)) return;
61
- if (!controlled) setLocal(id);
62
- // A controlled parent may keep its value; the scrolling variant must restore it.
63
- setRevision(value => value + 1);
64
- if (selected !== id) onSelectionChange?.(id);
65
- }, [controlled, onSelectionChange, pages, selected]);
82
+ if (selected === id) return;
83
+ // A controlled parent may keep its value, so request a scroll even if it stays the same.
84
+ if (controlled) setRevision(value => value + 1);
85
+ else setLocal(id);
86
+ onSelectionChange?.(id);
87
+ }, [controlled, onSelectionChange, selected]);
66
88
  return { selected, requestSelection, revision };
67
89
  }
68
90
 
69
- function useSettingsWindow(windowId: string, title: string, appearance: SidebarSplitViewAppearance, onError: SettingsWindowBaseProps["onError"], contentReadyInitially: boolean) {
91
+ function useSettingsWindow(windowId: string, title: string, appearance: SidebarSplitViewAppearance, onError: SettingsWindowProps["onError"]) {
70
92
  const errorRef = useRef(onError); errorRef.current = onError;
71
93
  const active = useRef(false);
72
- const contentReady = useRef(contentReadyInitially);
94
+ const contentReady = useRef(false);
73
95
  const splitReady = useRef(false);
74
96
  const shown = useRef(false);
75
97
  const report = useCallback((cause: unknown) => {
@@ -86,7 +108,7 @@ function useSettingsWindow(windowId: string, title: string, appearance: SidebarS
86
108
  await windows.showWindow(windowId);
87
109
  }).catch(cause => { shown.current = false; report(cause); });
88
110
  }, [report, windowId]);
89
- useEffect(() => { active.current = true; showIfReady(); return () => { active.current = false; }; }, [showIfReady]);
111
+ useLayoutEffect(() => { active.current = true; showIfReady(); return () => { active.current = false; }; }, [showIfReady]);
90
112
  useEffect(() => {
91
113
  let current = true;
92
114
  void loadWindowsApi().then(async windows => {
@@ -103,337 +125,103 @@ function useSettingsWindow(windowId: string, title: string, appearance: SidebarS
103
125
  return { onResize, markContentReady, report };
104
126
  }
105
127
 
106
- export function SettingsWindow<PageId extends string = string>(props: SettingsWindowProps<PageId>) {
107
- const { appearance = "system", backgroundClassName = "bg-background", contentBackgroundClassName = backgroundClassName, contentMinWidth = 340, pages, sidebarMinWidth = 180, windowId, onError } = props;
108
- const { selected, requestSelection } = useSettingsSelection(props);
109
- const page = pages.find(page => page.id === selected)!;
110
- const { onResize, report } = useSettingsWindow(windowId, page.title, appearance, onError, true);
111
- return <SidebarSplitView appearance={appearance} className={cn("flex-1", backgroundClassName)} contentMinWidth={contentMinWidth} onResize={onResize} onError={report} sidebarMinWidth={sidebarMinWidth} style={styles.root}
112
- sidebar={<View className="min-w-0 flex-1 overflow-hidden" style={styles.pane}>
113
- <SettingsSidebar onSelectionChange={requestSelection} pages={pages} selectedPageId={selected} />
114
- <SettingsToolbarBackground variant="sidebar" />
115
- </View>}
116
- content={<View className={cn("min-w-0 flex-1 overflow-hidden", contentBackgroundClassName)} style={styles.pane}>
117
- {page.render()}<SettingsToolbarBackground variant="content" />
118
- </View>}
119
- />;
120
- }
121
-
122
128
  export function VirtualizedSettingsWindow<PageId extends string = string>(props: VirtualizedSettingsWindowProps<PageId>) {
123
- const { appearance = "system", backgroundClassName = "bg-background", contentBackgroundClassName = backgroundClassName, contentMinWidth = 340, estimatedItemSize = 520, pages, sidebarMinWidth = 180, windowId, onError } = props;
124
- if (!Number.isFinite(estimatedItemSize) || estimatedItemSize <= 0) throw new SparkError("E_INVALID_ARGUMENT", "estimatedItemSize must be positive");
125
- const { selected, requestSelection, revision } = useSettingsSelection(props);
129
+ if (Platform.OS !== "macos") throw new SparkError("E_UNSUPPORTED_PLATFORM", "Settings windows require macOS");
130
+ const { appearance = "system", children, windowId, onError } = props;
131
+ const pages = useMemo(() => childPages<PageId>(children), [children]);
132
+ const { selected, requestSelection, revision } = useSettingsSelection(props, pages);
126
133
  const listRef = useRef<LegendListRef | null>(null);
127
- const page = pages.find(page => page.id === selected)!;
128
- const { onResize, markContentReady, report } = useSettingsWindow(windowId, page.title, appearance, onError, false);
129
- const programmatic = useRef(0);
134
+ const pageIndex = pages.findIndex(page => page.id === selected);
135
+ const { onResize, markContentReady, report } = useSettingsWindow(windowId, pages[pageIndex].title, appearance, onError);
136
+ const [viewportHeight, setViewportHeight] = useState(0);
137
+ const hasLayout = viewportHeight > 0;
138
+ const scrollingToPage = useRef(false);
130
139
  const visiblePage = useRef<PageId | undefined>(undefined);
131
140
  const initialized = useRef(false);
132
- const pageIndexById = useMemo(() => new Map(pages.map((page, index) => [page.id, index])), [pages]);
141
+
133
142
  useEffect(() => {
143
+ if (!hasLayout) return;
134
144
  let current = true;
135
- const generation = ++programmatic.current;
145
+ scrollingToPage.current = true;
136
146
  const frame = requestAnimationFrame(() => {
137
- if (visiblePage.current === selected && initialized.current) { programmatic.current = 0; return; }
147
+ if (visiblePage.current === selected && initialized.current) { scrollingToPage.current = false; return; }
138
148
  const list = listRef.current;
139
149
  if (!list) { report(new SparkError("E_UNAVAILABLE", "Settings list is not mounted")); return; }
140
- void list.scrollToIndex({ animated: initialized.current, index: pageIndexById.get(selected)!, viewOffset: SETTINGS_TITLEBAR_CONTENT_INSET, viewPosition: 0 })
150
+ visiblePage.current = undefined;
151
+ void list.scrollToIndex({ animated: initialized.current, index: pageIndex, viewOffset: TITLEBAR_HEIGHT, viewPosition: 0 })
141
152
  .then(() => { if (current) visiblePage.current = selected; })
142
153
  .catch(cause => { if (current) report(cause); })
143
154
  .finally(() => {
144
155
  if (!current) return;
145
156
  initialized.current = true;
146
- if (programmatic.current === generation) programmatic.current = 0;
157
+ scrollingToPage.current = false;
147
158
  markContentReady();
148
159
  });
149
160
  });
150
161
  return () => { current = false; cancelAnimationFrame(frame); };
151
- }, [markContentReady, pageIndexById, report, revision, selected]);
152
- const onFirstVisibleItemChanged = useCallback((info: { index: number }) => {
153
- if (programmatic.current) return;
162
+ }, [hasLayout, markContentReady, pageIndex, report, revision, selected]);
163
+
164
+ const onScroll = useCallback(() => {
165
+ if (!initialized.current || scrollingToPage.current) return;
154
166
  const state = listRef.current?.getState();
155
- let index = info.index;
156
- if (state) {
157
- const visibleTop = state.scroll + SETTINGS_TITLEBAR_CONTENT_INSET;
158
- while (index < pages.length - 1 && state.positionAtIndex(index) + state.sizeAtIndex(index) <= visibleTop) index++;
159
- }
167
+ if (!state || state.start < 0) return;
168
+ let index = state.start;
169
+ while (index < pages.length - 1 && state.positionAtIndex(index + 1) <= state.scroll + 0.5) index++;
160
170
  const page = pages[index];
161
171
  if (page && visiblePage.current !== page.id) {
162
172
  visiblePage.current = page.id;
163
173
  requestSelection(page.id);
164
174
  }
165
175
  }, [pages, requestSelection]);
166
- const onScroll = useCallback(() => {
167
- const state = listRef.current?.getState();
168
- if (state) onFirstVisibleItemChanged({ index: state.start });
169
- }, [onFirstVisibleItemChanged]);
170
- const renderItem = useCallback(({ index, item }: LegendListRenderItemProps<SettingsWindowPage<PageId>>) => (
171
- <View className="flex-col gap-5" style={[styles.virtualizedSettingsListPage, index > 0 && styles.virtualizedSettingsListPageAfterFirst]}>
172
- <View className="flex-col gap-2"><Text className="text-xl font-semibold text-text-primary leading-tight">{item.title}</Text></View>
173
- <View className="flex-col">{item.render()}</View>
174
- </View>
175
- ), []);
176
- return <SidebarSplitView appearance={appearance} className={cn("flex-1", backgroundClassName)} contentMinWidth={contentMinWidth} onResize={onResize} onError={report} sidebarMinWidth={sidebarMinWidth} style={styles.root}
177
- sidebar={<View className="min-w-0 flex-1 overflow-hidden" style={styles.pane}>
178
- <SettingsSidebar onSelectionChange={requestSelection} pages={pages} selectedPageId={selected} /><SettingsToolbarBackground variant="sidebar" />
179
- </View>}
180
- content={<View className={cn("min-w-0 flex-1 overflow-hidden", contentBackgroundClassName)} style={styles.pane}>
181
- <LegendList contentInset={settingsContentInset} contentContainerStyle={styles.virtualizedSettingsListContent} data={pages} estimatedItemSize={estimatedItemSize} keyExtractor={settingsPageKey} onFirstVisibleItemChanged={onFirstVisibleItemChanged} onScroll={onScroll} scrollEventThrottle={16} ref={listRef} renderItem={renderItem} recycleItems style={styles.virtualizedSettingsList} />
182
- <SettingsToolbarBackground variant="content" />
183
- </View>}
184
- />;
185
- }
186
- const settingsPageKey = (page: SettingsWindowPage) => page.id;
187
-
188
- function SettingsToolbarBackground({ variant }: { variant: "content" | "sidebar" }) {
189
- return (
190
- <View
191
- className="absolute left-0 right-0 top-0 bg-gradient-to-b from-background-primary from-60% to-background-primary/0"
192
- pointerEvents="none"
193
- style={[styles.toolbarBackground, variant === "sidebar" ? styles.sidebarToolbarBackground : undefined]}
194
- />
195
- );
196
- }
197
-
198
- export type SettingsSidebarProps<PageId extends string = string> = {
199
- onSelectionChange: (pageId: PageId) => void;
200
- pages: readonly Pick<SettingsWindowPage<PageId>, "id" | "title">[];
201
- selectedPageId: PageId;
202
- };
203
-
204
- export function SettingsSidebar<PageId extends string = string>({
205
- onSelectionChange,
206
- pages,
207
- selectedPageId,
208
- }: SettingsSidebarProps<PageId>) {
209
- return (
210
- <View className="flex-1 min-h-0">
211
- <ScrollView
212
- className="flex-1"
213
- contentContainerStyle={styles.sidebarContent}
214
- showsVerticalScrollIndicator={false}
215
- >
216
- {pages.map((page) => {
217
- const isSelected = selectedPageId === page.id;
218
176
 
219
- return (
220
- <Pressable
221
- {...settingsSidebarPressablePlatformProps}
222
- accessibilityRole="button"
223
- accessibilityState={{ selected: isSelected }}
224
- collapsable={false}
225
- style={styles.sidebarRow}
226
- className={cn(
227
- "justify-center rounded-md px-2",
228
- isSelected ? "bg-primary/15" : "hover:bg-background-secondary/60 active:bg-background-secondary",
229
- )}
230
- key={page.id}
231
- onPress={() => onSelectionChange(page.id)}
232
- >
233
- <Text
234
- className={isSelected ? "text-sm font-medium text-text-primary" : "text-sm text-text-secondary"}
235
- numberOfLines={1}
236
- >
237
- {page.title}
238
- </Text>
239
- </Pressable>
240
- );
241
- })}
242
- </ScrollView>
177
+ // Keep short pages tall enough to align at the top and avoid opening on two pages at once.
178
+ const pageHeight = Math.max(0, viewportHeight - TITLEBAR_HEIGHT);
179
+ const renderItem = useCallback(({ item }: LegendListRenderItemProps<SettingsPageProps<PageId>>) => (
180
+ <View style={[styles.page, { minHeight: pageHeight }]}>
181
+ {item.children}
243
182
  </View>
244
- );
245
- }
246
-
247
- export interface SettingsPageProps {
248
- actions?: ReactNode;
249
- children: ReactNode;
250
- contentClassName?: string;
251
- }
183
+ ), [pageHeight]);
252
184
 
253
- export function SettingsPage({ actions, children, contentClassName }: SettingsPageProps) {
254
185
  return (
255
- <View className="w-full flex-1 self-stretch overflow-hidden">
256
- {actions ? <View className="flex-row justify-end px-6 pt-4">{actions}</View> : null}
257
- <ScrollView
258
- className="flex-1"
259
- contentContainerClassName={cn("w-full max-w-4xl flex-col self-center px-8 pb-7", contentClassName)}
260
- contentInset={settingsContentInset}
261
- horizontal={false}
262
- >
263
- {children}
264
- </ScrollView>
265
- </View>
266
- );
267
- }
268
-
269
- export interface SettingsSectionProps {
270
- card?: boolean;
271
- children?: ReactNode;
272
- className?: string;
273
- contentClassName?: string;
274
- description?: string;
275
- first?: boolean;
276
- headerRight?: ReactNode;
277
- title?: string | null;
278
- }
279
-
280
- export function SettingsSection({
281
- card = true,
282
- children,
283
- className,
284
- contentClassName,
285
- description,
286
- first = false,
287
- headerRight,
288
- title,
289
- }: SettingsSectionProps) {
290
- const containerClassName = cn("flex flex-col gap-3", !first && "mt-7", className);
291
- const hasHeader = Boolean(title || description || headerRight);
292
- const contentNode = children !== undefined && children !== null
293
- ? card
294
- ? <SettingsRowGroup className={contentClassName}>{children}</SettingsRowGroup>
295
- : <View className={cn("flex flex-col gap-4", contentClassName)}>{children}</View>
296
- : null;
297
-
298
- return (
299
- <View className={containerClassName}>
300
- {hasHeader ? (
301
- <View className="flex-row items-start justify-between gap-4">
302
- <View className="flex-1 flex-col gap-1">
303
- {title ? (
304
- <Text className="text-sm font-semibold leading-tight text-text-secondary">{title}</Text>
305
- ) : null}
306
- {description ? (
307
- <Text className="text-xs leading-relaxed text-text-secondary">{description}</Text>
308
- ) : null}
309
- </View>
310
- {headerRight ? <View className="flex-none ml-4">{headerRight}</View> : null}
311
- </View>
186
+ <SidebarSplitView appearance={appearance} contentMinWidth={340} sidebarMinWidth={180} sidebarWidth={200} titleBar={titleBar} style={styles.fill}
187
+ onResize={event => { if (event.contentWidth > 0) setViewportHeight(event.contentHeight); onResize(event); }} onError={report}
188
+ sidebar={
189
+ <Sidebar defaultRowHeight={30} contentInsetTop={66} selectedId={selected} style={styles.fill} onError={report}
190
+ onSelectionChange={({ id }) => { if (id !== null) requestSelection(id as PageId); }}>
191
+ {pages.map(({ id, title, icon }) => {
192
+ const active = id === selected;
193
+ const foreground = active ? PlatformColor("alternateSelectedControlTextColor") : PlatformColor("labelColor");
194
+ return (
195
+ <SidebarItem key={id} id={id} accessibilityLabel={title} onError={report}>
196
+ <View pointerEvents="none" style={styles.sidebarRow}>
197
+ <View style={styles.sidebarIcon}>
198
+ <SFSymbol name={icon} size={16} color={active ? foreground : PlatformColor("secondaryLabelColor")} onError={report} />
199
+ </View>
200
+ <Text numberOfLines={1} style={[styles.sidebarLabel, { color: foreground }]}>{title}</Text>
201
+ </View>
202
+ </SidebarItem>
203
+ );
204
+ })}
205
+ </Sidebar>
206
+ }
207
+ content={hasLayout ? (
208
+ <LegendList ref={listRef} data={pages} keyExtractor={pageKey} renderItem={renderItem} estimatedItemSize={Math.max(1, pageHeight)}
209
+ contentContainerStyle={styles.listContent} contentInsetAdjustmentBehavior="never"
210
+ onFirstVisibleItemChanged={onScroll} onScroll={onScroll} scrollEventThrottle={16} style={styles.fill} />
312
211
  ) : null}
313
- {contentNode}
314
- </View>
315
- );
316
- }
317
-
318
- export interface SettingsCardProps {
319
- children: ReactNode;
320
- className?: string;
321
- }
322
-
323
- export function SettingsCard({ children, className }: SettingsCardProps) {
324
- return (
325
- <View className={cn("overflow-hidden rounded-xl border border-border-primary bg-background-secondary/20", className)}>
326
- {children}
327
- </View>
328
- );
329
- }
330
-
331
- export interface SettingsRowGroupProps {
332
- children: ReactNode;
333
- className?: string;
334
- }
335
-
336
- export function SettingsRowGroup({ children, className }: SettingsRowGroupProps) {
337
- return (
338
- <SettingsRowGroupContext.Provider value>
339
- <SettingsCard className={className}>{children}</SettingsCard>
340
- </SettingsRowGroupContext.Provider>
212
+ />
341
213
  );
342
214
  }
343
215
 
344
- export interface SettingsRowProps {
345
- align?: "start" | "center";
346
- className?: string;
347
- contentClassName?: string;
348
- control: ReactNode;
349
- controlWrapperClassName?: string;
350
- description?: string;
351
- /** Visual emphasis only. Disable the control itself when needed. */
352
- muted?: boolean;
353
- title: string;
354
- }
355
-
356
- export function SettingsRow({
357
- align = "start",
358
- className,
359
- contentClassName,
360
- control,
361
- controlWrapperClassName,
362
- description,
363
- muted = false,
364
- title,
365
- }: SettingsRowProps) {
366
- const grouped = useContext(SettingsRowGroupContext);
216
+ export { VirtualizedSettingsWindow as SettingsWindow };
367
217
 
368
- return (
369
- <View
370
- className={cn(
371
- "flex-row justify-between gap-5 px-4 py-4",
372
- align === "center" ? "items-center" : "items-start",
373
- grouped ? "border-border-primary" : "",
374
- muted ? "opacity-60" : "",
375
- className,
376
- )}
377
- style={grouped ? styles.groupedRow : undefined}
378
- >
379
- <View className={cn("min-w-0 flex-1 flex-col gap-1 pr-6", contentClassName)}>
380
- <Text className="text-sm font-semibold leading-tight text-text-primary">{title}</Text>
381
- {description ? (
382
- <Text className="text-xs leading-relaxed text-text-secondary">{description}</Text>
383
- ) : null}
384
- </View>
385
- <View className={cn("max-w-full flex-shrink items-end", controlWrapperClassName)}>
386
- {control}
387
- </View>
388
- </View>
389
- );
390
- }
218
+ const pageKey = (page: SettingsPageProps) => page.id;
391
219
 
392
220
  const styles = StyleSheet.create({
393
- pane: {
394
- flex: 1,
395
- minWidth: 0,
396
- },
397
- root: {
398
- flex: 1,
399
- },
400
- virtualizedSettingsList: {
401
- flex: 1,
402
- },
403
- virtualizedSettingsListContent: {
404
- flexDirection: "column",
405
- paddingBottom: 28,
406
- },
407
- // Keep horizontal sizing inside the item, so the virtualized scroll content
408
- // cannot add its padding to the measured page width and clip the controls.
409
- virtualizedSettingsListPage: {
410
- alignSelf: "center",
411
- maxWidth: 896,
412
- paddingHorizontal: 32,
413
- width: "100%",
414
- },
415
- virtualizedSettingsListPageAfterFirst: {
416
- marginTop: 40,
417
- },
418
- groupedRow: {
419
- borderBottomWidth: StyleSheet.hairlineWidth,
420
- },
421
- // Selection adds a background to an otherwise flattenable row. Keep its native
422
- // bounds stable and clip painting when Fabric updates selection during scroll.
423
- sidebarRow: {
424
- height: 28,
425
- flexShrink: 0,
426
- overflow: "hidden",
427
- },
428
- sidebarContent: {
429
- paddingHorizontal: 8,
430
- paddingTop: SETTINGS_SIDEBAR_TOP_INSET,
431
- },
432
- sidebarToolbarBackground: {
433
- height: SETTINGS_SIDEBAR_TOP_INSET,
434
- },
435
- toolbarBackground: {
436
- height: SETTINGS_TITLEBAR_CONTENT_INSET,
437
- zIndex: 1,
438
- },
221
+ fill: { flex: 1, minWidth: 0 },
222
+ listContent: { paddingTop: TITLEBAR_HEIGHT },
223
+ page: { alignSelf: "center", width: "100%", maxWidth: 760, padding: 20, gap: 16 },
224
+ sidebarRow: { flexDirection: "row", alignItems: "center", height: 30, gap: 10, paddingHorizontal: 10 },
225
+ sidebarIcon: { width: 20, height: 20, alignItems: "center", justifyContent: "center" },
226
+ sidebarLabel: { fontSize: 13, flexShrink: 1 },
439
227
  });