@legendapp/spark 0.0.4 → 0.0.6

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 (79) hide show
  1. package/package.json +4 -4
  2. package/skills/spark/UPGRADING.md +105 -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 +47 -25
  9. package/vendor/node_modules/@legendapp/spark-cli/dist/expo-desktop-template-bare-minimum-55.83.10.tgz +0 -0
  10. package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.cjs +6 -0
  11. package/vendor/node_modules/@legendapp/spark-cli/dist/package.js +4 -8
  12. package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +5 -3
  13. package/vendor/node_modules/@legendapp/spark-cli/dist/publish-directory.js +40 -0
  14. package/vendor/node_modules/@legendapp/spark-cli/dist/release-app.js +139 -0
  15. package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +21 -21
  16. package/vendor/node_modules/@legendapp/spark-cli/dist/signing.js +61 -41
  17. package/vendor/node_modules/@legendapp/spark-cli/package.json +4 -4
  18. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +2 -2
  19. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +2 -2
  20. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +2 -2
  21. package/vendor/node_modules/@legendapp/spark-clipboard/package.json +2 -2
  22. package/vendor/node_modules/@legendapp/spark-codex/package.json +2 -2
  23. package/vendor/node_modules/@legendapp/spark-commands/package.json +5 -5
  24. package/vendor/node_modules/@legendapp/spark-context-menu/package.json +2 -2
  25. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.h +2 -0
  26. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.mm +1 -0
  27. package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +1 -1
  28. package/vendor/node_modules/@legendapp/spark-desktop-config/app.plugin.cjs +1 -0
  29. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.cjs +15 -1
  30. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.d.cts +1 -0
  31. package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +3 -3
  32. package/vendor/node_modules/@legendapp/spark-desktop-config/rpaths.cjs +20 -0
  33. package/vendor/node_modules/@legendapp/spark-desktop-config/rpaths.d.cts +1 -0
  34. package/vendor/node_modules/@legendapp/spark-desktop-host/AppDelegate.mm +16 -5
  35. package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +2 -2
  36. package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +2 -2
  37. package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +2 -2
  38. package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +3 -3
  39. package/vendor/node_modules/@legendapp/spark-documents/package.json +7 -7
  40. package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +2 -2
  41. package/vendor/node_modules/@legendapp/spark-expo-compat/package.json +4 -4
  42. package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +2 -2
  43. package/vendor/node_modules/@legendapp/spark-file-system/package.json +2 -2
  44. package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +2 -2
  45. package/vendor/node_modules/@legendapp/spark-html/package.json +2 -2
  46. package/vendor/node_modules/@legendapp/spark-markdown/package.json +2 -2
  47. package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +2 -2
  48. package/vendor/node_modules/@legendapp/spark-native-menu/package.json +2 -2
  49. package/vendor/node_modules/@legendapp/spark-notifications/package.json +2 -2
  50. package/vendor/node_modules/@legendapp/spark-processes/package.json +2 -2
  51. package/vendor/node_modules/@legendapp/spark-rich-text/package.json +2 -2
  52. package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +2 -2
  53. package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
  54. package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +5 -5
  55. package/vendor/node_modules/@legendapp/spark-settings-ui/src/heading.tsx +14 -0
  56. package/vendor/node_modules/@legendapp/spark-settings-ui/src/index.tsx +132 -332
  57. package/vendor/node_modules/@legendapp/spark-settings-ui/src/rows.tsx +185 -0
  58. package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
  59. package/vendor/node_modules/@legendapp/spark-system/package.json +2 -2
  60. package/vendor/node_modules/@legendapp/spark-tray/package.json +2 -2
  61. package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSegmentedControl.mm +29 -0
  62. package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSelect.mm +17 -1
  63. package/vendor/node_modules/@legendapp/spark-ui/macos/sidebar/RNSidebar.mm +20 -0
  64. package/vendor/node_modules/@legendapp/spark-ui/package.json +2 -2
  65. package/vendor/node_modules/@legendapp/spark-ui/src/availability.ts +2 -1
  66. package/vendor/node_modules/@legendapp/spark-ui/src/control.ts +1 -1
  67. package/vendor/node_modules/@legendapp/spark-ui/src/desktop.tsx +15 -12
  68. package/vendor/node_modules/@legendapp/spark-ui/src/index.android.tsx +7 -6
  69. package/vendor/node_modules/@legendapp/spark-ui/src/index.ios.tsx +10 -9
  70. package/vendor/node_modules/@legendapp/spark-ui/src/index.web.tsx +6 -4
  71. package/vendor/node_modules/@legendapp/spark-ui/src/native-select/NativeSegmentedControlNativeComponent.ts +2 -1
  72. package/vendor/node_modules/@legendapp/spark-ui/src/native-select/NativeSelectNativeComponent.ts +1 -0
  73. package/vendor/node_modules/@legendapp/spark-ui/src/select.ts +4 -0
  74. package/vendor/node_modules/@legendapp/spark-ui/src/switch.tsx +13 -0
  75. package/vendor/node_modules/@legendapp/spark-ui/src/types.ts +16 -4
  76. package/vendor/node_modules/@legendapp/spark-updates/package.json +2 -2
  77. package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
  78. package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
  79. /package/{settings-window.ts → ui-settings.ts} +0 -0
@@ -1,51 +1,76 @@
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";
9
+ import { SettingsHeading, settingsHeadingGap } from "./heading";
7
10
 
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.
11
+ export * from "./options";
12
+ export * from "./rows";
13
+
14
+ const TITLEBAR_HEIGHT = 52;
15
+ const titleBar: SplitViewTitleBarOptions = { content: { height: TITLEBAR_HEIGHT, material: "windowBackground" } };
14
16
  let windowsApi: Promise<typeof import("@legendapp/spark-desktop-windows/src/api")> | undefined;
15
17
  const loadWindowsApi = () => windowsApi ??= import("@legendapp/spark-desktop-windows/src/api");
16
- export * from "./options";
17
18
 
18
- export interface SettingsWindowPage<PageId extends string = string> {
19
+ export interface SettingsPageProps<PageId extends string = string> {
19
20
  id: PageId;
20
21
  title: string;
21
- render: () => ReactNode;
22
+ icon: string;
23
+ heading?: string | false;
24
+ children: ReactNode;
22
25
  }
23
- export interface SettingsWindowBaseProps<PageId extends string = string> {
26
+
27
+ export function SettingsPage({ children }: SettingsPageProps) {
28
+ return <>{children}</>;
29
+ }
30
+
31
+ export type SettingsWindowSelectionProps<PageId extends string = string> =
32
+ | { selectedPageId: PageId; defaultPageId?: never; onSelectionChange: (pageId: PageId) => void }
33
+ | { selectedPageId?: never; defaultPageId?: PageId; onSelectionChange?: (pageId: PageId) => void };
34
+
35
+ export type SettingsWindowProps<PageId extends string = string> = SettingsWindowSelectionProps<PageId> & {
24
36
  /** Immutable for this mount. Remount to change the owning window. */
25
37
  windowId: string;
26
- pages: readonly SettingsWindowPage<PageId>[];
38
+ children: ReactNode;
27
39
  appearance?: SidebarSplitViewAppearance;
28
- backgroundClassName?: string;
29
- contentBackgroundClassName?: string;
30
- contentMinWidth?: number;
31
- sidebarMinWidth?: number;
32
40
  onError?: (error: SparkError) => void;
41
+ };
42
+
43
+ export type VirtualizedSettingsWindowProps<PageId extends string = string> = SettingsWindowProps<PageId>;
44
+
45
+ function childPages<PageId extends string>(children: ReactNode): SettingsPageProps<PageId>[] {
46
+ const pages: SettingsPageProps<PageId>[] = [];
47
+ Children.forEach(children, child => {
48
+ if (child === null) return;
49
+ if (isValidElement<{ children: ReactNode }>(child) && child.type === Fragment) {
50
+ pages.push(...childPages<PageId>(child.props.children));
51
+ } else if (isValidElement<SettingsPageProps<PageId>>(child) && child.type === SettingsPage) {
52
+ pages.push(child.props);
53
+ } else {
54
+ throw new SparkError("E_INVALID_ARGUMENT", "Settings windows require SettingsPage children or fragments");
55
+ }
56
+ });
57
+ return pages;
33
58
  }
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
59
 
40
- function useSettingsSelection<PageId extends string>(props: SettingsWindowProps<PageId>) {
41
- const { pages, windowId, selectedPageId, defaultPageId, onSelectionChange } = props;
60
+ function useSettingsSelection<PageId extends string>(props: SettingsWindowProps<PageId>, pages: readonly SettingsPageProps<PageId>[]) {
61
+ const { windowId, selectedPageId, defaultPageId, onSelectionChange } = props;
42
62
  const controlled = selectedPageId !== undefined;
43
63
  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");
64
+ identifier(windowId, "settings window ID");
65
+ if (identity.current.windowId !== windowId) throw new SparkError("E_INVALID_ARGUMENT", "Settings windowId must be nonempty and immutable; remount to change it");
45
66
  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
67
  const ids = new Set<string>();
47
68
  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");
69
+ identifier(page.id, "settings page ID");
70
+ identifier(page.title, "settings page title");
71
+ identifier(page.icon, "settings page icon");
72
+ if (page.heading !== undefined && page.heading !== false) identifier(page.heading, "settings page heading");
73
+ if (ids.has(page.id)) throw new SparkError("E_INVALID_ARGUMENT", "Settings page IDs must be unique");
49
74
  ids.add(page.id);
50
75
  }
51
76
  if (!pages.length || (controlled && !ids.has(selectedPageId))) throw new SparkError("E_INVALID_ARGUMENT", "Settings selection must identify an existing page");
@@ -57,19 +82,18 @@ function useSettingsSelection<PageId extends string>(props: SettingsWindowProps<
57
82
  useEffect(() => { if (!controlled && local !== selected) setLocal(selected); }, [controlled, local, selected]);
58
83
  const [revision, setRevision] = useState(0);
59
84
  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]);
85
+ // A controlled parent may keep its value, so request a scroll even if it stays the same.
86
+ if (controlled) setRevision(value => value + 1);
87
+ else setLocal(id);
88
+ onSelectionChange?.(id);
89
+ }, [controlled, onSelectionChange]);
66
90
  return { selected, requestSelection, revision };
67
91
  }
68
92
 
69
- function useSettingsWindow(windowId: string, title: string, appearance: SidebarSplitViewAppearance, onError: SettingsWindowBaseProps["onError"], contentReadyInitially: boolean) {
93
+ function useSettingsWindow(windowId: string, title: string, appearance: SidebarSplitViewAppearance, onError: SettingsWindowProps["onError"]) {
70
94
  const errorRef = useRef(onError); errorRef.current = onError;
71
95
  const active = useRef(false);
72
- const contentReady = useRef(contentReadyInitially);
96
+ const contentReady = useRef(false);
73
97
  const splitReady = useRef(false);
74
98
  const shown = useRef(false);
75
99
  const report = useCallback((cause: unknown) => {
@@ -86,7 +110,7 @@ function useSettingsWindow(windowId: string, title: string, appearance: SidebarS
86
110
  await windows.showWindow(windowId);
87
111
  }).catch(cause => { shown.current = false; report(cause); });
88
112
  }, [report, windowId]);
89
- useEffect(() => { active.current = true; showIfReady(); return () => { active.current = false; }; }, [showIfReady]);
113
+ useLayoutEffect(() => { active.current = true; showIfReady(); return () => { active.current = false; }; }, [showIfReady]);
90
114
  useEffect(() => {
91
115
  let current = true;
92
116
  void loadWindowsApi().then(async windows => {
@@ -103,337 +127,113 @@ function useSettingsWindow(windowId: string, title: string, appearance: SidebarS
103
127
  return { onResize, markContentReady, report };
104
128
  }
105
129
 
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
130
  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);
131
+ if (Platform.OS !== "macos") throw new SparkError("E_UNSUPPORTED_PLATFORM", "Settings windows require macOS");
132
+ const { appearance = "system", children, windowId, onError } = props;
133
+ const pages = useMemo(() => childPages<PageId>(children), [children]);
134
+ const { selected, requestSelection, revision } = useSettingsSelection(props, pages);
126
135
  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);
136
+ const pageIndex = pages.findIndex(page => page.id === selected);
137
+ const lastPageIndex = pages.length - 1;
138
+ const anchoredEndSpace = useMemo(() => ({ anchorIndex: lastPageIndex, anchorOffset: TITLEBAR_HEIGHT }), [lastPageIndex]);
139
+ const { onResize, markContentReady, report } = useSettingsWindow(windowId, pages[pageIndex].title, appearance, onError);
140
+ const [hasLayout, setHasLayout] = useState(false);
141
+ const scrollingToPage = useRef(false);
130
142
  const visiblePage = useRef<PageId | undefined>(undefined);
131
143
  const initialized = useRef(false);
132
- const pageIndexById = useMemo(() => new Map(pages.map((page, index) => [page.id, index])), [pages]);
144
+
133
145
  useEffect(() => {
146
+ if (!hasLayout || (initialized.current && visiblePage.current === selected)) return;
134
147
  let current = true;
135
- const generation = ++programmatic.current;
148
+ scrollingToPage.current = true;
136
149
  const frame = requestAnimationFrame(() => {
137
- if (visiblePage.current === selected && initialized.current) { programmatic.current = 0; return; }
138
150
  const list = listRef.current;
139
151
  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 })
152
+ visiblePage.current = undefined;
153
+ void list.scrollToIndex({ animated: initialized.current, index: pageIndex, viewOffset: TITLEBAR_HEIGHT, viewPosition: 0 })
141
154
  .then(() => { if (current) visiblePage.current = selected; })
142
155
  .catch(cause => { if (current) report(cause); })
143
156
  .finally(() => {
144
157
  if (!current) return;
145
158
  initialized.current = true;
146
- if (programmatic.current === generation) programmatic.current = 0;
159
+ scrollingToPage.current = false;
147
160
  markContentReady();
148
161
  });
149
162
  });
150
- return () => { current = false; cancelAnimationFrame(frame); };
151
- }, [markContentReady, pageIndexById, report, revision, selected]);
152
- const onFirstVisibleItemChanged = useCallback((info: { index: number }) => {
153
- if (programmatic.current) return;
163
+ return () => {
164
+ current = false;
165
+ scrollingToPage.current = false;
166
+ cancelAnimationFrame(frame);
167
+ };
168
+ }, [hasLayout, markContentReady, pageIndex, report, revision, selected]);
169
+
170
+ const onScroll = useCallback(() => {
171
+ if (!initialized.current || scrollingToPage.current) return;
154
172
  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
- }
173
+ if (!state || state.start == null || state.start < 0) return;
174
+ // LegendList item positions exclude the top padding that matches the overlay title bar.
175
+ const paneTop = state.scroll + 0.5;
176
+ let index = state.start;
177
+ while (index > 0 && state.positionAtIndex(index) > paneTop) index--;
178
+ while (index < pages.length - 1 && state.positionAtIndex(index + 1) <= paneTop) index++;
160
179
  const page = pages[index];
161
180
  if (page && visiblePage.current !== page.id) {
162
181
  visiblePage.current = page.id;
163
182
  requestSelection(page.id);
164
183
  }
165
184
  }, [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
185
 
204
- export function SettingsSidebar<PageId extends string = string>({
205
- onSelectionChange,
206
- pages,
207
- selectedPageId,
208
- }: SettingsSidebarProps<PageId>) {
209
186
  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
-
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>
243
- </View>
244
- );
245
- }
246
-
247
- export interface SettingsPageProps {
248
- actions?: ReactNode;
249
- children: ReactNode;
250
- contentClassName?: string;
251
- }
252
-
253
- export function SettingsPage({ actions, children, contentClassName }: SettingsPageProps) {
254
- 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>
187
+ <SidebarSplitView appearance={appearance} contentMinWidth={340} sidebarMinWidth={180} sidebarWidth={200} titleBar={titleBar} style={styles.fill}
188
+ onResize={event => { if (event.contentWidth > 0) setHasLayout(event.contentHeight > 0); onResize(event); }} onError={report}
189
+ sidebar={
190
+ <Sidebar defaultRowHeight={30} contentInsetTop={66} selectedId={selected} style={styles.fill} onError={report}
191
+ onSelectionChange={({ id }) => { if (id !== null && id !== selected) requestSelection(id as PageId); }}>
192
+ {pages.map(({ id, title, icon }) => {
193
+ const active = id === selected;
194
+ const foreground = active ? PlatformColor("alternateSelectedControlTextColor") : PlatformColor("labelColor");
195
+ return (
196
+ <SidebarItem key={id} id={id} accessibilityLabel={title} onError={report}>
197
+ <View pointerEvents="none" style={styles.sidebarRow}>
198
+ <View style={styles.sidebarIcon}>
199
+ <SFSymbol name={icon} size={16} color={active ? foreground : PlatformColor("secondaryLabelColor")} onError={report} />
200
+ </View>
201
+ <Text numberOfLines={1} style={[styles.sidebarLabel, { color: foreground }]}>{title}</Text>
202
+ </View>
203
+ </SidebarItem>
204
+ );
205
+ })}
206
+ </Sidebar>
207
+ }
208
+ content={hasLayout ? (
209
+ <LegendList ref={listRef} data={pages} keyExtractor={pageKey} renderItem={renderPage} anchoredEndSpace={anchoredEndSpace}
210
+ contentContainerStyle={styles.listContent} contentInsetAdjustmentBehavior="never"
211
+ onFirstVisibleItemChanged={onScroll} onScroll={onScroll} scrollEventThrottle={16} style={styles.fill} />
312
212
  ) : 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>
213
+ />
341
214
  );
342
215
  }
343
216
 
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
- }
217
+ export { VirtualizedSettingsWindow as SettingsWindow };
355
218
 
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);
219
+ const pageKey = (page: SettingsPageProps) => page.id;
367
220
 
221
+ function renderPage({ item }: LegendListRenderItemProps<SettingsPageProps>) {
222
+ const { heading = item.title, children } = item;
368
223
  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>
224
+ <View style={styles.page}>
225
+ {heading !== false && <SettingsHeading title={heading} variant="page" />}
226
+ <View style={styles.pageBody}>{children}</View>
388
227
  </View>
389
228
  );
390
229
  }
391
230
 
392
231
  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
- },
232
+ fill: { flex: 1, minWidth: 0 },
233
+ listContent: { paddingTop: TITLEBAR_HEIGHT, paddingBottom: 20 },
234
+ page: { alignSelf: "center", width: "100%", maxWidth: 760, paddingHorizontal: 20, paddingTop: 20, gap: settingsHeadingGap },
235
+ pageBody: { gap: 20 },
236
+ sidebarRow: { flexDirection: "row", alignItems: "center", height: 30, gap: 10, paddingHorizontal: 10 },
237
+ sidebarIcon: { width: 20, height: 20, alignItems: "center", justifyContent: "center" },
238
+ sidebarLabel: { fontSize: 13, flexShrink: 1 },
439
239
  });