@koinzhang/paseo-plugin-customize 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +58 -0
- package/client/category-visibility.test.ts +26 -0
- package/client/design-tokens.test.ts +39 -0
- package/client/design-tokens.ts +104 -0
- package/client/dropdown.tsx +139 -0
- package/client/entries.test.ts +50 -0
- package/client/entries.ts +47 -0
- package/client/entry-row.tsx +89 -0
- package/client/mechanism-card.tsx +75 -0
- package/client/preview-pane.tsx +101 -0
- package/client/provider-options.test.ts +31 -0
- package/client/provider-options.ts +37 -0
- package/client/query-policy.test.ts +57 -0
- package/client/query-policy.ts +20 -0
- package/client/route.ts +29 -0
- package/client/selection-settings.test.ts +16 -0
- package/client/slash-command.test.ts +94 -0
- package/client/slash-command.ts +36 -0
- package/client/surface.tsx +332 -0
- package/client/ui.tsx +265 -0
- package/client/use-app-language.ts +28 -0
- package/client/web.ts +111 -0
- package/index.client.tsx +57 -0
- package/index.server.ts +13 -0
- package/package.json +37 -0
- package/paseo-plugin.json +6 -0
- package/server/agent-plugins.ts +41 -0
- package/server/compatibility.test.ts +104 -0
- package/server/compatibility.ts +46 -0
- package/server/frontmatter.ts +49 -0
- package/server/glob.ts +46 -0
- package/server/handlers.ts +193 -0
- package/server/jsonc.ts +40 -0
- package/server/mcp.ts +87 -0
- package/server/parsers.test.ts +92 -0
- package/server/providers/acp.ts +186 -0
- package/server/providers/claude.ts +284 -0
- package/server/providers/codex.ts +219 -0
- package/server/providers/copilot.ts +116 -0
- package/server/providers/cursor.ts +194 -0
- package/server/providers/omp.ts +263 -0
- package/server/providers/opencode.ts +215 -0
- package/server/providers/pi.ts +102 -0
- package/server/providers.test.ts +306 -0
- package/server/scan-kit.ts +368 -0
- package/server/scan-snapshot.test.ts +56 -0
- package/server/scan-snapshot.ts +58 -0
- package/server/skill-aliases.ts +60 -0
- package/server/toml.ts +240 -0
- package/server/yaml-lite.ts +172 -0
- package/shared/acp-configs.ts +107 -0
- package/shared/category-visibility.ts +26 -0
- package/shared/compatibility.ts +6 -0
- package/shared/contracts.ts +116 -0
- package/shared/i18n.ts +293 -0
- package/shared/mechanisms.ts +380 -0
- package/shared/providers.ts +27 -0
- package/shared/selection-settings.ts +14 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { type PluginSurfaceProps, usePaseo, useRpc, useSettings } from "@getpaseo/plugin/client";
|
|
2
|
+
import { Icon, ScrollView, TextInput } from "@getpaseo/plugin/client/react-native";
|
|
3
|
+
import { useQuery } from "@tanstack/react-query";
|
|
4
|
+
import { useCallback, useEffect, useMemo, useState, type ReactNode } from "react";
|
|
5
|
+
import { Platform, Text, View } from "react-native";
|
|
6
|
+
import { resolveCategory, visibleCategories } from "../shared/category-visibility.ts";
|
|
7
|
+
import { cachedScanRpc, scanRpc, type Category, type Entry } from "../shared/contracts.ts";
|
|
8
|
+
import { messagesFor } from "../shared/i18n.ts";
|
|
9
|
+
import { MECHANISMS, mechanismFor } from "../shared/mechanisms.ts";
|
|
10
|
+
import { PROVIDER_IDS, type ProviderId } from "../shared/providers.ts";
|
|
11
|
+
import { selectionSettings } from "../shared/selection-settings.ts";
|
|
12
|
+
import { CONTROL, ICON_SIZE, PREVIEW_FRACTION, RADIUS, TEXT, pageLayout, titleGap } from "./design-tokens.ts";
|
|
13
|
+
import { Dropdown, type DropdownOption } from "./dropdown.tsx";
|
|
14
|
+
import { countByCategory, groupEntries, projectLabel } from "./entries.ts";
|
|
15
|
+
import { EntryRow } from "./entry-row.tsx";
|
|
16
|
+
import { MechanismCard } from "./mechanism-card.tsx";
|
|
17
|
+
import { PreviewPane } from "./preview-pane.tsx";
|
|
18
|
+
import { enabledProviderOptions, selectedProvider } from "./provider-options.ts";
|
|
19
|
+
import { newestScan, REVISIT_QUERY_POLICY, SCAN_QUERY_POLICY, shouldScanSnapshot } from "./query-policy.ts";
|
|
20
|
+
import { CategoryTabs, ErrorState, IconButton, InlineEmpty, LoadingState, SectionHeader } from "./ui.tsx";
|
|
21
|
+
import { useAppLanguage } from "./use-app-language.ts";
|
|
22
|
+
import { readLastWorkspaceId } from "./web.ts";
|
|
23
|
+
|
|
24
|
+
const NO_PROJECT = "";
|
|
25
|
+
const WORKSPACE_PAGE_LIMIT = 200;
|
|
26
|
+
|
|
27
|
+
const lastCategory: Record<ProviderId, Category> = Object.fromEntries(
|
|
28
|
+
PROVIDER_IDS.map((id) => [id, "instructions"]),
|
|
29
|
+
) as Record<ProviderId, Category>;
|
|
30
|
+
|
|
31
|
+
/** Sidebar surface; an unselected project defaults to the last workspace. */
|
|
32
|
+
export function CustomizeSurface({ theme, layout }: PluginSurfaceProps): ReactNode {
|
|
33
|
+
const colors = theme.colors;
|
|
34
|
+
const compact = layout.compact;
|
|
35
|
+
const page = pageLayout(compact);
|
|
36
|
+
const language = useAppLanguage();
|
|
37
|
+
const m = messagesFor(language);
|
|
38
|
+
const paseo = usePaseo();
|
|
39
|
+
const scan = useRpc(scanRpc);
|
|
40
|
+
const cachedScan = useRpc(cachedScanRpc);
|
|
41
|
+
const settings = useSettings(selectionSettings);
|
|
42
|
+
const providerSnapshot = useQuery({
|
|
43
|
+
queryKey: ["customize", "providers"],
|
|
44
|
+
queryFn: () => paseo.providers.snapshot(),
|
|
45
|
+
staleTime: 15_000,
|
|
46
|
+
...REVISIT_QUERY_POLICY,
|
|
47
|
+
refetchInterval: 30_000,
|
|
48
|
+
});
|
|
49
|
+
const providerOptions = useMemo(() => enabledProviderOptions(
|
|
50
|
+
[
|
|
51
|
+
...(providerSnapshot.data?.entries ?? []),
|
|
52
|
+
...(providerSnapshot.data?.compactSnapshot?.entries ?? []),
|
|
53
|
+
],
|
|
54
|
+
m.builtinProvider,
|
|
55
|
+
), [providerSnapshot.data, m.builtinProvider]);
|
|
56
|
+
const [workspaceId] = useState(() => (Platform.OS === "web" ? readLastWorkspaceId() : null));
|
|
57
|
+
const lastWorkspace = useQuery({
|
|
58
|
+
queryKey: ["customize", "workspace-root", workspaceId],
|
|
59
|
+
enabled: workspaceId !== null,
|
|
60
|
+
staleTime: 60_000,
|
|
61
|
+
...REVISIT_QUERY_POLICY,
|
|
62
|
+
queryFn: async () => {
|
|
63
|
+
let page = await paseo.workspaces.list({ page: { limit: WORKSPACE_PAGE_LIMIT } });
|
|
64
|
+
for (let pages = 0; ; pages++) {
|
|
65
|
+
const hit = page.entries.find((workspace) => workspace.id === workspaceId);
|
|
66
|
+
if (hit) return hit.projectRootPath;
|
|
67
|
+
if (!page.pageInfo.hasMore || !page.pageInfo.nextCursor || pages >= 20) return null;
|
|
68
|
+
page = await paseo.workspaces.list({ page: { limit: WORKSPACE_PAGE_LIMIT, cursor: page.pageInfo.nextCursor } });
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
const workspaceRoot = lastWorkspace.data ?? null;
|
|
73
|
+
|
|
74
|
+
const savedProvider = settings.status === "ready" ? settings.values.provider : "claude";
|
|
75
|
+
const effectiveProvider = selectedProvider(savedProvider, providerOptions);
|
|
76
|
+
const provider = effectiveProvider ?? "claude";
|
|
77
|
+
const projectChoice = settings.status === "ready" ? settings.values.projectRoot : null;
|
|
78
|
+
const [category, setCategoryState] = useState<Category>("instructions");
|
|
79
|
+
const activeCategory = resolveCategory(provider, category);
|
|
80
|
+
const [query, setQuery] = useState("");
|
|
81
|
+
const [selected, setSelected] = useState<Entry | null>(null);
|
|
82
|
+
|
|
83
|
+
const setProvider = (id: string) => {
|
|
84
|
+
if (settings.status !== "ready" || settings.saving || !providerOptions.some((option) => option.id === id)) return;
|
|
85
|
+
void settings.save({ ...settings.values, provider: id as ProviderId }, settings.revision);
|
|
86
|
+
setSelected(null);
|
|
87
|
+
};
|
|
88
|
+
const setCategory = (next: Category) => {
|
|
89
|
+
lastCategory[provider] = next;
|
|
90
|
+
setCategoryState(next);
|
|
91
|
+
setSelected(null);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
const restored = resolveCategory(provider, lastCategory[provider]);
|
|
96
|
+
lastCategory[provider] = restored;
|
|
97
|
+
setCategoryState(restored);
|
|
98
|
+
setSelected(null);
|
|
99
|
+
setQuery("");
|
|
100
|
+
}, [provider]);
|
|
101
|
+
|
|
102
|
+
const projects = useQuery({
|
|
103
|
+
queryKey: ["customize", "projects"],
|
|
104
|
+
queryFn: () => paseo.projects.list(),
|
|
105
|
+
staleTime: 60_000,
|
|
106
|
+
...REVISIT_QUERY_POLICY,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const projectOptions = useMemo<DropdownOption[]>(() => {
|
|
110
|
+
const options = new Map<string, DropdownOption>();
|
|
111
|
+
const add = (root: string, label?: string) => {
|
|
112
|
+
if (root && !options.has(root)) options.set(root, { id: root, label: label || projectLabel(root), hint: root });
|
|
113
|
+
};
|
|
114
|
+
if (workspaceRoot) add(workspaceRoot);
|
|
115
|
+
for (const project of projects.data?.projects ?? []) add(project.projectRootPath, project.projectDisplayName);
|
|
116
|
+
if (projectChoice) add(projectChoice);
|
|
117
|
+
return [...options.values(), { id: NO_PROJECT, label: m.noProject }];
|
|
118
|
+
}, [workspaceRoot, projects.data, projectChoice, m.noProject]);
|
|
119
|
+
const projectRoot = projectChoice ?? workspaceRoot ?? (projects.isPending || (workspaceId !== null && lastWorkspace.isPending) ? null : projectOptions[0]?.id ?? NO_PROJECT);
|
|
120
|
+
|
|
121
|
+
const scanEnabled = settings.status === "ready" && providerSnapshot.data !== undefined && effectiveProvider !== null && projectRoot !== null;
|
|
122
|
+
const saved = useQuery({
|
|
123
|
+
queryKey: ["customize", "cached-scan", provider, projectRoot],
|
|
124
|
+
queryFn: () => cachedScan({ provider, projectRoot: projectRoot || null }),
|
|
125
|
+
enabled: scanEnabled,
|
|
126
|
+
...REVISIT_QUERY_POLICY,
|
|
127
|
+
});
|
|
128
|
+
const result = useQuery({
|
|
129
|
+
queryKey: ["customize", "scan", provider, projectRoot],
|
|
130
|
+
queryFn: () => scan({ provider, projectRoot: projectRoot || null }),
|
|
131
|
+
enabled: scanEnabled && shouldScanSnapshot(saved.data, saved.isFetching, saved.isError),
|
|
132
|
+
...SCAN_QUERY_POLICY,
|
|
133
|
+
});
|
|
134
|
+
const displayed = newestScan(saved.data?.snapshot, result.data);
|
|
135
|
+
const entries = displayed?.entries ?? [];
|
|
136
|
+
const counts = useMemo(() => countByCategory(entries), [entries]);
|
|
137
|
+
const groups = useMemo(() => groupEntries(entries, activeCategory, query), [entries, activeCategory, query]);
|
|
138
|
+
const mechanism = mechanismFor(provider, activeCategory, displayed?.compatibility);
|
|
139
|
+
const compatibility = displayed?.compatibility;
|
|
140
|
+
const compatibilityState = compatibility?.source === "builtIn" ? "supported"
|
|
141
|
+
: compatibility?.enabled === true ? "on" : compatibility?.enabled === false ? "off" : "unknown";
|
|
142
|
+
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
if (!selected || !displayed) return;
|
|
145
|
+
const fresh = displayed.entries.find((entry) => entry.id === selected.id);
|
|
146
|
+
if (fresh !== selected) setSelected(fresh ?? null);
|
|
147
|
+
}, [displayed, selected]);
|
|
148
|
+
|
|
149
|
+
const onSelect = useCallback((entry: Entry) => {
|
|
150
|
+
setSelected((prev) => (prev?.id === entry.id ? null : entry));
|
|
151
|
+
}, []);
|
|
152
|
+
|
|
153
|
+
const tabs = visibleCategories(provider).map((id) => ({
|
|
154
|
+
id,
|
|
155
|
+
label: m.categories[id],
|
|
156
|
+
count: displayed ? counts[id] : undefined,
|
|
157
|
+
muted: !MECHANISMS[provider][id].supported,
|
|
158
|
+
}));
|
|
159
|
+
const filtered = query.trim().length > 0;
|
|
160
|
+
|
|
161
|
+
if (settings.status === "loading") return <LoadingState color={colors.foregroundMuted} />;
|
|
162
|
+
if (settings.status !== "ready") {
|
|
163
|
+
return <ErrorState error={settings.error} onRetry={() => void settings.reload()} colors={colors} />;
|
|
164
|
+
}
|
|
165
|
+
if (providerSnapshot.isPending) return <LoadingState color={colors.foregroundMuted} />;
|
|
166
|
+
if (providerSnapshot.isError && !providerSnapshot.data) {
|
|
167
|
+
return <ErrorState error={providerSnapshot.error} onRetry={() => void providerSnapshot.refetch()} colors={colors} />;
|
|
168
|
+
}
|
|
169
|
+
if (effectiveProvider === null) {
|
|
170
|
+
return (
|
|
171
|
+
<View style={{ flex: 1, padding: page.padding, backgroundColor: colors.surface0, gap: page.gap }}>
|
|
172
|
+
<Text style={{ ...TEXT.body, color: colors.foregroundMuted }}>{m.noEnabledProvider}</Text>
|
|
173
|
+
<IconButton icon="RefreshCw" label={m.refresh} color={colors.foregroundMuted} busy={providerSnapshot.isFetching} onPress={() => void providerSnapshot.refetch()} />
|
|
174
|
+
</View>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<View style={{ flex: 1, minHeight: 0, backgroundColor: colors.surface0 }}>
|
|
180
|
+
<View style={{ flex: selected ? 1 - (compact ? PREVIEW_FRACTION.compact : PREVIEW_FRACTION.regular) : 1, minHeight: 0 }}>
|
|
181
|
+
<ScrollView contentContainerStyle={{ padding: page.padding, gap: page.gap }} keyboardShouldPersistTaps="handled">
|
|
182
|
+
<View style={{ gap: titleGap(compact), zIndex: 1 }}>
|
|
183
|
+
<View
|
|
184
|
+
style={{
|
|
185
|
+
flexDirection: "row",
|
|
186
|
+
alignItems: "center",
|
|
187
|
+
justifyContent: "flex-end",
|
|
188
|
+
zIndex: 30,
|
|
189
|
+
}}
|
|
190
|
+
>
|
|
191
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 14, flexShrink: 1, minWidth: 0 }}>
|
|
192
|
+
{compatibility ? (
|
|
193
|
+
<View accessible accessibilityRole="image" accessibilityLabel={m.compatibility(compatibilityState)}>
|
|
194
|
+
<Icon name={compatibilityState === "off" ? "Link2Off" : "Link2"} size={ICON_SIZE.action} color={compatibilityState === "on" || compatibilityState === "supported" ? colors.statusSuccess : compatibilityState === "off" ? colors.foregroundMuted : colors.statusWarning} />
|
|
195
|
+
</View>
|
|
196
|
+
) : null}
|
|
197
|
+
<Dropdown
|
|
198
|
+
label={m.provider}
|
|
199
|
+
options={providerOptions}
|
|
200
|
+
value={provider}
|
|
201
|
+
onChange={setProvider}
|
|
202
|
+
colors={colors}
|
|
203
|
+
triggerLabel={m.chooseProvider}
|
|
204
|
+
closeLabel={m.closeMenu}
|
|
205
|
+
menuAlign={compact ? "left" : "right"}
|
|
206
|
+
disabled={settings.saving}
|
|
207
|
+
/>
|
|
208
|
+
<Dropdown
|
|
209
|
+
label={m.project}
|
|
210
|
+
options={projectOptions}
|
|
211
|
+
value={projectRoot ?? NO_PROJECT}
|
|
212
|
+
onChange={(id) => {
|
|
213
|
+
if (settings.saving) return;
|
|
214
|
+
void settings.save({ ...settings.values, projectRoot: id }, settings.revision);
|
|
215
|
+
setSelected(null);
|
|
216
|
+
}}
|
|
217
|
+
colors={colors}
|
|
218
|
+
triggerLabel={m.chooseProject}
|
|
219
|
+
closeLabel={m.closeMenu}
|
|
220
|
+
emptyLabel={m.noProject}
|
|
221
|
+
disabled={settings.saving}
|
|
222
|
+
/>
|
|
223
|
+
<IconButton
|
|
224
|
+
icon="RefreshCw"
|
|
225
|
+
label={m.refresh}
|
|
226
|
+
color={colors.foregroundMuted}
|
|
227
|
+
busy={result.isFetching}
|
|
228
|
+
tooltip={displayed ? {
|
|
229
|
+
text: m.lastScanned(new Date(displayed.scannedAt).toLocaleString(language)),
|
|
230
|
+
colors,
|
|
231
|
+
} : undefined}
|
|
232
|
+
onPress={() => {
|
|
233
|
+
void providerSnapshot.refetch();
|
|
234
|
+
void result.refetch();
|
|
235
|
+
}}
|
|
236
|
+
/>
|
|
237
|
+
</View>
|
|
238
|
+
</View>
|
|
239
|
+
<CategoryTabs options={tabs} value={activeCategory} onChange={setCategory} colors={colors} />
|
|
240
|
+
{settings.saveError ? <Text style={{ ...TEXT.small, color: colors.statusDanger }}>{settings.saveError}</Text> : null}
|
|
241
|
+
<MechanismCard key={`${provider}:${activeCategory}`} mechanism={mechanism} language={language} colors={colors} m={m} />
|
|
242
|
+
{result.isError && displayed ? <ErrorState error={result.error} onRetry={() => void result.refetch()} colors={colors} /> : null}
|
|
243
|
+
</View>
|
|
244
|
+
|
|
245
|
+
{mechanism.supported ? (
|
|
246
|
+
<View
|
|
247
|
+
style={{
|
|
248
|
+
flexDirection: "row",
|
|
249
|
+
alignItems: "center",
|
|
250
|
+
gap: 6,
|
|
251
|
+
height: CONTROL.searchHeight,
|
|
252
|
+
paddingHorizontal: 10,
|
|
253
|
+
borderRadius: RADIUS.control,
|
|
254
|
+
borderWidth: 1,
|
|
255
|
+
borderColor: colors.border,
|
|
256
|
+
backgroundColor: colors.surface1,
|
|
257
|
+
}}
|
|
258
|
+
>
|
|
259
|
+
<Icon name="Search" size={ICON_SIZE.inline} color={colors.foregroundMuted} />
|
|
260
|
+
<TextInput
|
|
261
|
+
value={query}
|
|
262
|
+
onChangeText={setQuery}
|
|
263
|
+
placeholder={m.search}
|
|
264
|
+
placeholderTextColor={colors.foregroundMuted}
|
|
265
|
+
accessibilityLabel={m.search}
|
|
266
|
+
autoCorrect={false}
|
|
267
|
+
autoCapitalize="none"
|
|
268
|
+
style={{ flex: 1, ...TEXT.small, color: colors.foreground, paddingVertical: 0 }}
|
|
269
|
+
/>
|
|
270
|
+
{filtered ? <IconButton icon="X" label={m.preview.close} color={colors.foregroundMuted} size={ICON_SIZE.inline} onPress={() => setQuery("")} /> : null}
|
|
271
|
+
</View>
|
|
272
|
+
) : null}
|
|
273
|
+
|
|
274
|
+
{!displayed && (saved.isPending || result.isPending) ? (
|
|
275
|
+
<LoadingState color={colors.foregroundMuted} />
|
|
276
|
+
) : !displayed && (result.isError || saved.isError) ? (
|
|
277
|
+
<ErrorState error={result.error ?? saved.error} onRetry={() => void result.refetch()} colors={colors} />
|
|
278
|
+
) : !mechanism.supported ? null : (
|
|
279
|
+
groups.map((group) => (
|
|
280
|
+
<View key={group.scope} style={{ gap: titleGap(compact) }}>
|
|
281
|
+
<SectionHeader
|
|
282
|
+
title={m.scopes[group.scope]}
|
|
283
|
+
count={group.count}
|
|
284
|
+
colors={colors}
|
|
285
|
+
compact={compact}
|
|
286
|
+
/>
|
|
287
|
+
{group.count === 0 ? (
|
|
288
|
+
<InlineEmpty
|
|
289
|
+
text={filtered ? m.noMatches : group.scope === "project" && !projectRoot ? m.noProject : m.emptyScope(m.scopes[group.scope])}
|
|
290
|
+
color={colors.foregroundMuted}
|
|
291
|
+
/>
|
|
292
|
+
) : (
|
|
293
|
+
group.sources.map((source) => (
|
|
294
|
+
<View key={source.source} style={{ gap: 2 }}>
|
|
295
|
+
<Text style={{ ...TEXT.path, color: colors.foregroundMuted, paddingBottom: 2 }} numberOfLines={1}>
|
|
296
|
+
{source.source}
|
|
297
|
+
</Text>
|
|
298
|
+
{source.entries.map((entry) => (
|
|
299
|
+
<EntryRow
|
|
300
|
+
key={entry.id}
|
|
301
|
+
entry={entry}
|
|
302
|
+
selected={selected?.id === entry.id}
|
|
303
|
+
onSelect={onSelect}
|
|
304
|
+
colors={colors}
|
|
305
|
+
m={m}
|
|
306
|
+
/>
|
|
307
|
+
))}
|
|
308
|
+
</View>
|
|
309
|
+
))
|
|
310
|
+
)}
|
|
311
|
+
</View>
|
|
312
|
+
))
|
|
313
|
+
)}
|
|
314
|
+
</ScrollView>
|
|
315
|
+
</View>
|
|
316
|
+
|
|
317
|
+
{selected ? (
|
|
318
|
+
<View
|
|
319
|
+
style={{
|
|
320
|
+
flex: compact ? PREVIEW_FRACTION.compact : PREVIEW_FRACTION.regular,
|
|
321
|
+
minHeight: 0,
|
|
322
|
+
borderTopWidth: 1,
|
|
323
|
+
borderTopColor: colors.border,
|
|
324
|
+
backgroundColor: colors.surface0,
|
|
325
|
+
}}
|
|
326
|
+
>
|
|
327
|
+
<PreviewPane entry={selected} onClose={() => setSelected(null)} colors={colors} compact={compact} m={m} />
|
|
328
|
+
</View>
|
|
329
|
+
) : null}
|
|
330
|
+
</View>
|
|
331
|
+
);
|
|
332
|
+
}
|
package/client/ui.tsx
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
2
|
+
import { useState, type ReactNode } from "react";
|
|
3
|
+
import { ActivityIndicator, Pressable, Text, View, type StyleProp, type ViewStyle } from "react-native";
|
|
4
|
+
import type { Status } from "../shared/contracts.ts";
|
|
5
|
+
import { CONTROL, FONT_WEIGHT, ICON_SIZE, RADIUS, TEXT, iconButton, pillRadius, sectionTitle } from "./design-tokens.ts";
|
|
6
|
+
import { useMessages } from "./use-app-language.ts";
|
|
7
|
+
|
|
8
|
+
/** Shared building blocks, mirroring `activity/client/ui.tsx`. */
|
|
9
|
+
|
|
10
|
+
export type Colors = {
|
|
11
|
+
surface0: string;
|
|
12
|
+
surface1: string;
|
|
13
|
+
surface2: string;
|
|
14
|
+
border: string;
|
|
15
|
+
foreground: string;
|
|
16
|
+
foregroundMuted: string;
|
|
17
|
+
accent: string;
|
|
18
|
+
accentForeground: string;
|
|
19
|
+
statusSuccess: string;
|
|
20
|
+
statusWarning: string;
|
|
21
|
+
statusDanger: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function IconButton({
|
|
25
|
+
icon,
|
|
26
|
+
label,
|
|
27
|
+
onPress,
|
|
28
|
+
color,
|
|
29
|
+
size = ICON_SIZE.action,
|
|
30
|
+
disabled,
|
|
31
|
+
busy,
|
|
32
|
+
style,
|
|
33
|
+
tooltip,
|
|
34
|
+
}: {
|
|
35
|
+
icon: string;
|
|
36
|
+
label: string;
|
|
37
|
+
onPress: () => void;
|
|
38
|
+
color: string;
|
|
39
|
+
size?: number;
|
|
40
|
+
disabled?: boolean;
|
|
41
|
+
busy?: boolean;
|
|
42
|
+
style?: StyleProp<ViewStyle>;
|
|
43
|
+
tooltip?: { text: string; colors: Pick<Colors, "surface2" | "border" | "foreground"> };
|
|
44
|
+
}): ReactNode {
|
|
45
|
+
const [hovered, setHovered] = useState(false);
|
|
46
|
+
const button = (
|
|
47
|
+
<Pressable
|
|
48
|
+
accessibilityRole="button"
|
|
49
|
+
accessibilityLabel={label}
|
|
50
|
+
accessibilityHint={tooltip?.text}
|
|
51
|
+
accessibilityState={{ disabled: disabled === true }}
|
|
52
|
+
disabled={disabled}
|
|
53
|
+
hitSlop={CONTROL.hitSlop}
|
|
54
|
+
onPress={onPress}
|
|
55
|
+
onHoverIn={tooltip ? () => setHovered(true) : undefined}
|
|
56
|
+
onHoverOut={tooltip ? () => setHovered(false) : undefined}
|
|
57
|
+
style={[iconButton, disabled ? { opacity: 0.4 } : null, style]}
|
|
58
|
+
>
|
|
59
|
+
{busy ? (
|
|
60
|
+
<ActivityIndicator size={size} color={color} style={{ width: size, height: size }} />
|
|
61
|
+
) : (
|
|
62
|
+
<Icon name={icon} size={size} color={color} />
|
|
63
|
+
)}
|
|
64
|
+
</Pressable>
|
|
65
|
+
);
|
|
66
|
+
if (!tooltip) return button;
|
|
67
|
+
return (
|
|
68
|
+
<View style={{ position: "relative", width: CONTROL.iconButton, height: CONTROL.iconButton, zIndex: hovered ? 50 : 1 }}>
|
|
69
|
+
{button}
|
|
70
|
+
{hovered ? (
|
|
71
|
+
<View
|
|
72
|
+
pointerEvents="none"
|
|
73
|
+
style={{
|
|
74
|
+
position: "absolute",
|
|
75
|
+
top: CONTROL.iconButton + 6,
|
|
76
|
+
right: 0,
|
|
77
|
+
minWidth: 180,
|
|
78
|
+
maxWidth: 260,
|
|
79
|
+
paddingHorizontal: 8,
|
|
80
|
+
paddingVertical: 6,
|
|
81
|
+
borderRadius: RADIUS.overlay,
|
|
82
|
+
borderWidth: 1,
|
|
83
|
+
borderColor: tooltip.colors.border,
|
|
84
|
+
backgroundColor: tooltip.colors.surface2,
|
|
85
|
+
}}
|
|
86
|
+
>
|
|
87
|
+
<Text style={{ ...TEXT.caption, color: tooltip.colors.foreground }}>{tooltip.text}</Text>
|
|
88
|
+
</View>
|
|
89
|
+
) : null}
|
|
90
|
+
</View>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Text button with a leading icon (preview actions). */
|
|
95
|
+
export function TextButton({
|
|
96
|
+
icon,
|
|
97
|
+
label,
|
|
98
|
+
onPress,
|
|
99
|
+
colors,
|
|
100
|
+
}: {
|
|
101
|
+
icon: string;
|
|
102
|
+
label: string;
|
|
103
|
+
onPress: () => void;
|
|
104
|
+
colors: Pick<Colors, "foregroundMuted" | "foreground" | "surface2">;
|
|
105
|
+
}): ReactNode {
|
|
106
|
+
return (
|
|
107
|
+
<Pressable
|
|
108
|
+
accessibilityRole="button"
|
|
109
|
+
accessibilityLabel={label}
|
|
110
|
+
hitSlop={CONTROL.hitSlop}
|
|
111
|
+
onPress={onPress}
|
|
112
|
+
style={({ hovered, pressed }: { hovered?: boolean; pressed: boolean }) => ({
|
|
113
|
+
flexDirection: "row",
|
|
114
|
+
alignItems: "center",
|
|
115
|
+
gap: 4,
|
|
116
|
+
paddingVertical: 3,
|
|
117
|
+
paddingHorizontal: 6,
|
|
118
|
+
borderRadius: RADIUS.control,
|
|
119
|
+
backgroundColor: hovered || pressed ? colors.surface2 : "transparent",
|
|
120
|
+
})}
|
|
121
|
+
>
|
|
122
|
+
<Icon name={icon} size={ICON_SIZE.inline} color={colors.foregroundMuted} />
|
|
123
|
+
<Text style={{ ...TEXT.meta, fontWeight: FONT_WEIGHT.medium, color: colors.foreground }}>{label}</Text>
|
|
124
|
+
</Pressable>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function SectionHeader({
|
|
129
|
+
title,
|
|
130
|
+
count,
|
|
131
|
+
colors,
|
|
132
|
+
compact,
|
|
133
|
+
children,
|
|
134
|
+
}: {
|
|
135
|
+
title: string;
|
|
136
|
+
count?: number;
|
|
137
|
+
colors: Pick<Colors, "foreground" | "foregroundMuted">;
|
|
138
|
+
compact?: boolean;
|
|
139
|
+
children?: ReactNode;
|
|
140
|
+
}): ReactNode {
|
|
141
|
+
return (
|
|
142
|
+
<View style={{ flexDirection: "row", alignItems: "center", justifyContent: "space-between", gap: 8 }}>
|
|
143
|
+
<View style={{ flexDirection: "row", alignItems: "baseline", gap: 8, flexShrink: 1 }}>
|
|
144
|
+
<Text style={{ ...sectionTitle(compact), color: colors.foreground }} numberOfLines={1}>
|
|
145
|
+
{title}
|
|
146
|
+
</Text>
|
|
147
|
+
{count != null ? <Text style={{ ...TEXT.count, color: colors.foregroundMuted }}>{count}</Text> : null}
|
|
148
|
+
</View>
|
|
149
|
+
{children ? <View style={{ flexDirection: "row", alignItems: "center", gap: 2 }}>{children}</View> : null}
|
|
150
|
+
</View>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function LoadingState({ color }: { color: string }): ReactNode {
|
|
155
|
+
return <ActivityIndicator color={color} style={{ paddingVertical: 24 }} />;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function ErrorState({
|
|
159
|
+
error,
|
|
160
|
+
onRetry,
|
|
161
|
+
colors,
|
|
162
|
+
}: {
|
|
163
|
+
error: unknown;
|
|
164
|
+
onRetry?: () => void;
|
|
165
|
+
colors: Pick<Colors, "statusDanger" | "accent">;
|
|
166
|
+
}): ReactNode {
|
|
167
|
+
const m = useMessages();
|
|
168
|
+
const detail = error instanceof Error ? error.message : error != null ? String(error) : "";
|
|
169
|
+
return (
|
|
170
|
+
<View style={{ gap: 4 }} accessibilityRole="alert">
|
|
171
|
+
<Text style={{ ...TEXT.small, color: colors.statusDanger }}>{detail ? `${m.loadFailed}: ${detail}` : m.loadFailed}</Text>
|
|
172
|
+
{onRetry ? (
|
|
173
|
+
<Pressable accessibilityRole="button" hitSlop={CONTROL.hitSlop} onPress={onRetry} style={{ alignSelf: "flex-start", paddingVertical: 2 }}>
|
|
174
|
+
<Text style={{ ...TEXT.small, fontWeight: FONT_WEIGHT.medium, color: colors.accent }}>{m.retry}</Text>
|
|
175
|
+
</Pressable>
|
|
176
|
+
) : null}
|
|
177
|
+
</View>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function InlineEmpty({ text, color }: { text: string; color: string }): ReactNode {
|
|
182
|
+
return <Text style={{ ...TEXT.small, color }}>{text}</Text>;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Page filter tabs (Activity `TextTabs` `filter` variant) with trailing counts. */
|
|
186
|
+
export function CategoryTabs<T extends string>({
|
|
187
|
+
options,
|
|
188
|
+
value,
|
|
189
|
+
onChange,
|
|
190
|
+
colors,
|
|
191
|
+
}: {
|
|
192
|
+
options: ReadonlyArray<{ id: T; label: string; count?: number; muted?: boolean }>;
|
|
193
|
+
value: T;
|
|
194
|
+
onChange: (id: T) => void;
|
|
195
|
+
colors: Pick<Colors, "foreground" | "foregroundMuted">;
|
|
196
|
+
}): ReactNode {
|
|
197
|
+
return (
|
|
198
|
+
<View accessibilityRole="tablist" style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 18 }}>
|
|
199
|
+
{options.map((option) => {
|
|
200
|
+
const active = option.id === value;
|
|
201
|
+
return (
|
|
202
|
+
<Pressable
|
|
203
|
+
key={option.id}
|
|
204
|
+
accessibilityRole="tab"
|
|
205
|
+
accessibilityState={{ selected: active }}
|
|
206
|
+
onPress={() => onChange(option.id)}
|
|
207
|
+
style={{ flexDirection: "row", alignItems: "baseline", gap: 6, paddingVertical: 6 }}
|
|
208
|
+
>
|
|
209
|
+
<Text
|
|
210
|
+
style={{
|
|
211
|
+
...TEXT.body,
|
|
212
|
+
fontWeight: active ? FONT_WEIGHT.semibold : FONT_WEIGHT.medium,
|
|
213
|
+
color: active ? colors.foreground : colors.foregroundMuted,
|
|
214
|
+
}}
|
|
215
|
+
>
|
|
216
|
+
{option.label}
|
|
217
|
+
</Text>
|
|
218
|
+
{option.count != null ? (
|
|
219
|
+
<Text style={{ ...TEXT.count, color: colors.foregroundMuted, opacity: option.muted ? 0.6 : 1 }}>{option.count}</Text>
|
|
220
|
+
) : null}
|
|
221
|
+
</Pressable>
|
|
222
|
+
);
|
|
223
|
+
})}
|
|
224
|
+
</View>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function statusColor(status: Status, colors: Colors): string {
|
|
229
|
+
switch (status) {
|
|
230
|
+
case "auto":
|
|
231
|
+
return colors.statusSuccess;
|
|
232
|
+
case "conditional":
|
|
233
|
+
return colors.accent;
|
|
234
|
+
case "manual":
|
|
235
|
+
case "pending":
|
|
236
|
+
return colors.statusWarning;
|
|
237
|
+
case "disabled":
|
|
238
|
+
return colors.statusDanger;
|
|
239
|
+
case "inactive":
|
|
240
|
+
return colors.foregroundMuted;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Outlined status pill: `CONTROL.pillBadgeHeight`, status color text and border. */
|
|
245
|
+
export function StatusBadge({ status, label, colors }: { status: Status; label: string; colors: Colors }): ReactNode {
|
|
246
|
+
const color = statusColor(status, colors);
|
|
247
|
+
return (
|
|
248
|
+
<View
|
|
249
|
+
style={{
|
|
250
|
+
height: CONTROL.pillBadgeHeight,
|
|
251
|
+
paddingHorizontal: 7,
|
|
252
|
+
borderRadius: pillRadius(CONTROL.pillBadgeHeight),
|
|
253
|
+
borderWidth: 1,
|
|
254
|
+
borderColor: color,
|
|
255
|
+
alignItems: "center",
|
|
256
|
+
justifyContent: "center",
|
|
257
|
+
flexShrink: 0,
|
|
258
|
+
}}
|
|
259
|
+
>
|
|
260
|
+
<Text style={{ ...TEXT.pillBadge, color }} numberOfLines={1}>
|
|
261
|
+
{label}
|
|
262
|
+
</Text>
|
|
263
|
+
</View>
|
|
264
|
+
);
|
|
265
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
import { Platform } from "react-native";
|
|
3
|
+
import { messagesFor, type AppLanguage, type Messages } from "../shared/i18n.ts";
|
|
4
|
+
import { readAppLanguage, subscribeAppLanguage } from "./web.ts";
|
|
5
|
+
|
|
6
|
+
const defaultLanguage = (): AppLanguage => "en";
|
|
7
|
+
const noSubscription = () => () => {};
|
|
8
|
+
|
|
9
|
+
/** Paseo app language (Settings → Language, `system` → OS preference); `en` off web. */
|
|
10
|
+
export function useAppLanguage(): AppLanguage {
|
|
11
|
+
return useSyncExternalStore(
|
|
12
|
+
Platform.OS === "web" ? subscribeAppLanguage : noSubscription,
|
|
13
|
+
Platform.OS === "web" ? readAppLanguage : defaultLanguage,
|
|
14
|
+
defaultLanguage,
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function useMessages(): Messages {
|
|
19
|
+
return messagesFor(useAppLanguage());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function currentAppLanguage(): AppLanguage {
|
|
23
|
+
return Platform.OS === "web" ? readAppLanguage() : "en";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function watchAppLanguage(onChange: () => void): () => void {
|
|
27
|
+
return Platform.OS === "web" ? subscribeAppLanguage(onChange) : () => {};
|
|
28
|
+
}
|