@omercnet/paseo-pr-radar 3.2.3-next.492.1 → 3.2.3-next.527.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,7 +28,17 @@ DevTools before capture. Both PNGs come from an isolated Paseo test daemon at 2
28
28
  - Waiting externally: running checks, pending reviews, repository requirements, and external-author work.
29
29
  - Ready: authored pull requests that are mergeable with settled checks and reviews.
30
30
  - Viewer labels: `YOURS`, `REVIEW`, and `EXTERNAL`.
31
- - Contextual actions: ask an existing agent or start one in the linked workspace.
31
+ - Working-directory tags: `CWD-WORKTREE`, `CWD-BASE`, and `CWD-TBD` (shown on rows and maintained as Paseo workspace/agent labels).
32
+ - Draft PRs (DPRs): displayed in a separate collapsible section below regular pull requests.
33
+ - Issues tab: switch between `Pull Requests` and `Issues` (authored by you, assigned to you, or in your owned repos) with the same `Start New Agent`, `Open Existing Agent`, `CWD-*` tags, `Copy link`, and `Open Issue` workflow.
34
+ - Action cluster on every PR:
35
+ - `Open issues (N)`: opens all linked/closing GitHub issues in your browser when present.
36
+ - `Start New Agent`: available on every PR (orange when a local checkout/worktree exists, brown when `CWD-TBD` and a clone or directory pick is needed). Opens an interactive directory/worktree chooser (supporting incremental typing, GUI selection, `CWD-WORKTREE` vs `CWD-BASE`, and one-click clone + worktree creation), or launches immediately when configured in Settings.
37
+ - `Open Existing Agent`: jumps directly to an existing linked Paseo agent.
38
+ - `Ask agent` / `Open workspace` / `Copy link` / `Open PR`.
39
+ - Settings (`PR Radar settings`): configure `sourceCodeDir` (default `~/src`), `defaultCwdMode` (`CWD-WORKTREE` or `CWD-BASE`), `autoLaunchMode` (`prompt`, `existing_only`, or `existing_or_clone`), default agent launch options (profile, provider, model, effort, mode, context mode), and an optional absolute/`~/` routing script path (copy `examples/pr-radar-route.py`, a small example of the stdin/stdout contract, to e.g. `~/.config/pr-radar/route.py` and edit it). The script path and `sourceCodeDir` are read from the saved settings on the server, never from the request. The script must be an executable regular file owned by you or root, in directories that group and others cannot write (a sticky directory such as `/tmp` is fine); it runs with a minimal environment, a 30 second timeout and a 1 MiB output cap, one at a time (not on Windows). It may set only the `default`, `plan`, `acceptEdits` and `read-only` permission modes and the `contextMode` option; other values are ignored and the launch notice says so. A profile it names is ignored too when that profile sets another permission mode, option or feature value. Directories outside `sourceCodeDir` are refused for clones, checkouts and worktrees. These checks are defense in depth against crafted requests, not a privilege boundary: the settings are the trust source, but any Paseo client can write them.
40
+
41
+ When PR Radar checks out or fetches a repository, it runs `git` with a hardened environment: `~/.gitconfig` and the system git config are ignored, repository hooks, filters, credential helpers and transport helpers are neutralized, and GitHub credentials come only from the `gh` CLI (never from git's environment). Network proxies must be provided through the environment (`HTTPS_PROXY`/`http_proxy`/`NO_PROXY` and friends), not through git config.
32
42
  - Linked workspaces and agents include those in background workspaces. Helpers, meaning background
33
43
  agents that Paseo hides from tabs, lists and attention, never appear on a row. They also do not
34
44
  count toward its active agents, attention, permission state or the sidebar count.
@@ -68,7 +78,7 @@ Update an npm installation to the latest published release:
68
78
  paseo plugin update pr-radar
69
79
  ```
70
80
 
71
- The npm install and update flow requires Paseo `^0.12.0 || ^0.13.0 || ^0.14.0 || ^0.15.0 || ^0.16.0` with npm available on the daemon host.
81
+ The npm install and update flow requires Paseo `^0.12.0 || ^0.13.0 || ^0.14.0 || ^0.15.0 || ^0.16.0 || ^0.17.0` with npm available on the daemon host.
72
82
 
73
83
 
74
84
  The daemon must have plugins enabled and `gh` authenticated for GitHub viewer-aware triage.
@@ -86,7 +96,7 @@ bun run typecheck
86
96
  Release Please maintains the version, changelog, component tag, and GitHub release from
87
97
  Conventional Commits in the monorepo.
88
98
 
89
- The manifest supports Paseo `^0.12.0 || ^0.13.0 || ^0.14.0 || ^0.15.0 || ^0.16.0`. Development uses the 0.16 CLI, client, plugin SDK,
99
+ The manifest supports Paseo `^0.12.0 || ^0.13.0 || ^0.14.0 || ^0.15.0 || ^0.16.0 || ^0.17.0`. Development uses the 0.16 CLI, client, plugin SDK,
90
100
  and protocol packages together from the workspace catalog. Host-owned navigation opens linked agents and workspaces without private routes or
91
101
  page reloads on web, desktop, iOS, and Android. React `19.1` and React Native `0.81` match the versions supplied by
92
102
  the plugin host.
@@ -0,0 +1,416 @@
1
+ import { type PluginSurfaceProps, usePaseo } from "@getpaseo/plugin/client";
2
+ import { TextInput } from "@getpaseo/plugin/client/ui";
3
+ import { useQuery } from "@tanstack/react-query";
4
+ import { useEffect, useMemo, useState } from "react";
5
+ import { Pressable, ScrollView, Text, View } from "react-native";
6
+ import { pickerOptionAccessibility } from "./screen-state";
7
+
8
+ export interface ComboOption {
9
+ label: string;
10
+ value: string;
11
+ detail?: string;
12
+ }
13
+
14
+ export const EFFORT_OPTIONS: readonly ComboOption[] = [
15
+ { label: "Profile / provider default", value: "" },
16
+ { label: "Low", value: "low" },
17
+ { label: "Medium", value: "medium" },
18
+ { label: "High", value: "high" },
19
+ { label: "Extra high (xhigh)", value: "xhigh" },
20
+ ];
21
+
22
+ export const KNOWN_PROVIDERS: readonly string[] = [
23
+ "claude",
24
+ "codex",
25
+ "pi",
26
+ "antigravity",
27
+ "gemini",
28
+ "hermes",
29
+ "cursor",
30
+ ];
31
+
32
+ export const KNOWN_MODELS: readonly string[] = [
33
+ "sonnet",
34
+ "opus",
35
+ "haiku",
36
+ "gpt-6-astra",
37
+ "gpt-6.1-sol",
38
+ "gpt-5.4",
39
+ "gemini-2.5-pro",
40
+ "gemini-2.5-flash",
41
+ ];
42
+
43
+ export const KNOWN_MODES: readonly string[] = [
44
+ "default",
45
+ "bypassPermissions",
46
+ "plan",
47
+ "acceptEdits",
48
+ "dontAsk",
49
+ "auto",
50
+ ];
51
+
52
+ export const KNOWN_CONTEXT_MODES: readonly string[] = ["full", "compact", "minimal", "none"];
53
+
54
+ export function dedupeOptions(options: readonly ComboOption[]): ComboOption[] {
55
+ const seen = new Set<string>();
56
+ const result: ComboOption[] = [];
57
+ for (const option of options) {
58
+ const key = option.value;
59
+ if (seen.has(key)) continue;
60
+ seen.add(key);
61
+ result.push(option);
62
+ }
63
+ return result;
64
+ }
65
+
66
+ function matchesContinuousText(option: ComboOption, query: string): boolean {
67
+ const trimmed = query.trim().toLowerCase();
68
+ if (!trimmed) return true;
69
+ const haystack = `${option.label} ${option.value} ${option.detail ?? ""}`.toLowerCase();
70
+ return trimmed.split(/\s+/).every((token) => haystack.includes(token));
71
+ }
72
+
73
+ export function ComboSelect({
74
+ label,
75
+ hint,
76
+ value,
77
+ placeholder,
78
+ options,
79
+ allowEmpty = true,
80
+ compact = false,
81
+ theme,
82
+ onSelect,
83
+ onQueryChange,
84
+ }: {
85
+ label: string;
86
+ hint?: string;
87
+ value: string;
88
+ placeholder?: string;
89
+ options: readonly ComboOption[];
90
+ allowEmpty?: boolean;
91
+ compact?: boolean;
92
+ theme: PluginSurfaceProps["theme"];
93
+ onSelect: (nextValue: string) => void;
94
+ onQueryChange?: (text: string) => void;
95
+ }) {
96
+ const [text, setText] = useState(value);
97
+ const [open, setOpen] = useState(false);
98
+
99
+ useEffect(() => {
100
+ setText(value);
101
+ }, [value]);
102
+
103
+ const filtered = useMemo(() => {
104
+ const list = options.filter((option) => matchesContinuousText(option, text));
105
+ return list.slice(0, 12);
106
+ }, [options, text]);
107
+
108
+ const trimmed = text.trim();
109
+ const hasExactMatch = options.some((option) => option.value === trimmed);
110
+
111
+ return (
112
+ <View style={compact ? { gap: 4 } : { paddingVertical: 10, paddingHorizontal: 14, gap: 6 }}>
113
+ {compact ? (
114
+ <Text style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}>{label}</Text>
115
+ ) : (
116
+ <View
117
+ style={{
118
+ flexDirection: "row",
119
+ alignItems: "center",
120
+ justifyContent: "space-between",
121
+ gap: 12,
122
+ }}
123
+ >
124
+ <View style={{ flex: 1, gap: 2 }}>
125
+ <Text style={{ color: theme.colors.foreground, fontSize: 13, fontWeight: "600" }}>
126
+ {label}
127
+ </Text>
128
+ {hint ? (
129
+ <Text style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}>{hint}</Text>
130
+ ) : null}
131
+ </View>
132
+ </View>
133
+ )}
134
+
135
+ <View style={{ flexDirection: "row", alignItems: "center", gap: 6 }}>
136
+ <View style={{ flex: 1 }}>
137
+ <TextInput
138
+ value={text}
139
+ placeholder={placeholder}
140
+ placeholderTextColor={theme.colors.foregroundMuted}
141
+ autoCapitalize="none"
142
+ autoCorrect={false}
143
+ onFocus={() => setOpen(true)}
144
+ onChangeText={(next) => {
145
+ setText(next);
146
+ setOpen(true);
147
+ onQueryChange?.(next);
148
+ if (next.trim() || allowEmpty) {
149
+ onSelect(next.trim());
150
+ }
151
+ }}
152
+ onSubmitEditing={() => {
153
+ if (trimmed || allowEmpty) {
154
+ onSelect(trimmed);
155
+ }
156
+ setOpen(false);
157
+ }}
158
+ style={{
159
+ minHeight: compact ? 34 : 36,
160
+ color: theme.colors.foreground,
161
+ backgroundColor: theme.colors.surface0,
162
+ borderWidth: 1,
163
+ borderColor: open ? theme.colors.accent : theme.colors.border,
164
+ borderRadius: compact ? 8 : 7,
165
+ paddingHorizontal: 10,
166
+ paddingVertical: 6,
167
+ fontSize: 13,
168
+ }}
169
+ />
170
+ </View>
171
+ {allowEmpty && text ? (
172
+ <Pressable
173
+ accessibilityRole="button"
174
+ accessibilityLabel={`Clear ${label}`}
175
+ onPress={() => {
176
+ setText("");
177
+ onQueryChange?.("");
178
+ onSelect("");
179
+ }}
180
+ style={({ pressed }) => ({
181
+ minHeight: compact ? 34 : 36,
182
+ minWidth: compact ? 30 : 32,
183
+ alignItems: "center",
184
+ justifyContent: "center",
185
+ borderWidth: 1,
186
+ borderColor: theme.colors.border,
187
+ borderRadius: compact ? 8 : 7,
188
+ backgroundColor: theme.colors.surface0,
189
+ opacity: pressed ? 0.7 : 1,
190
+ })}
191
+ >
192
+ <Text style={{ color: theme.colors.foregroundMuted, fontSize: 13, fontWeight: "700" }}>
193
+ ×
194
+ </Text>
195
+ </Pressable>
196
+ ) : null}
197
+ <Pressable
198
+ accessibilityRole="button"
199
+ accessibilityLabel={`Toggle ${label} options`}
200
+ accessibilityState={{ expanded: open }}
201
+ onPress={() => setOpen((prev) => !prev)}
202
+ style={({ pressed }) => ({
203
+ minHeight: compact ? 34 : 36,
204
+ minWidth: compact ? 32 : 34,
205
+ alignItems: "center",
206
+ justifyContent: "center",
207
+ borderWidth: 1,
208
+ borderColor: open ? theme.colors.accent : theme.colors.border,
209
+ borderRadius: compact ? 8 : 7,
210
+ backgroundColor: theme.colors.surface0,
211
+ opacity: pressed ? 0.7 : 1,
212
+ })}
213
+ >
214
+ <Text style={{ color: theme.colors.foregroundMuted, fontSize: 12, fontWeight: "700" }}>
215
+ {open ? "▲" : "▼"}
216
+ </Text>
217
+ </Pressable>
218
+ </View>
219
+
220
+ {open ? (
221
+ <View
222
+ style={{
223
+ borderWidth: 1,
224
+ borderColor: theme.colors.border,
225
+ borderRadius: 8,
226
+ backgroundColor: theme.colors.surface0,
227
+ maxHeight: 200,
228
+ overflow: "hidden",
229
+ }}
230
+ >
231
+ <ScrollView nestedScrollEnabled style={{ maxHeight: 200 }}>
232
+ {filtered.map((option) => {
233
+ const selected = option.value === value;
234
+ return (
235
+ <Pressable
236
+ key={`${option.label}:${option.value}`}
237
+ {...pickerOptionAccessibility(selected)}
238
+ onPress={() => {
239
+ setText(option.value);
240
+ onQueryChange?.(option.value);
241
+ onSelect(option.value);
242
+ setOpen(false);
243
+ }}
244
+ style={({ pressed }) => ({
245
+ paddingHorizontal: 10,
246
+ paddingVertical: 8,
247
+ borderBottomWidth: 1,
248
+ borderBottomColor: theme.colors.border,
249
+ backgroundColor: selected
250
+ ? `${theme.colors.accent}22`
251
+ : pressed
252
+ ? theme.colors.surface1
253
+ : "transparent",
254
+ flexDirection: "row",
255
+ alignItems: "center",
256
+ justifyContent: "space-between",
257
+ gap: 8,
258
+ })}
259
+ >
260
+ <View style={{ flex: 1, gap: 1 }}>
261
+ <Text
262
+ style={{
263
+ color: selected ? theme.colors.accent : theme.colors.foreground,
264
+ fontSize: 12,
265
+ fontWeight: selected ? "700" : "600",
266
+ }}
267
+ numberOfLines={1}
268
+ >
269
+ {option.label}
270
+ </Text>
271
+ {option.value && option.value !== option.label ? (
272
+ <Text
273
+ style={{ color: theme.colors.foregroundMuted, fontSize: 11 }}
274
+ numberOfLines={1}
275
+ >
276
+ {option.value}
277
+ </Text>
278
+ ) : null}
279
+ </View>
280
+ {option.detail ? (
281
+ <Text
282
+ style={{ color: theme.colors.foregroundMuted, fontSize: 11 }}
283
+ numberOfLines={1}
284
+ >
285
+ {option.detail}
286
+ </Text>
287
+ ) : null}
288
+ </Pressable>
289
+ );
290
+ })}
291
+ {trimmed && !hasExactMatch ? (
292
+ <Pressable
293
+ accessibilityRole="button"
294
+ onPress={() => {
295
+ onSelect(trimmed);
296
+ setOpen(false);
297
+ }}
298
+ style={({ pressed }) => ({
299
+ paddingHorizontal: 10,
300
+ paddingVertical: 8,
301
+ backgroundColor: pressed ? theme.colors.surface1 : "transparent",
302
+ })}
303
+ >
304
+ <Text style={{ color: theme.colors.accent, fontSize: 12, fontWeight: "600" }}>
305
+ Use "{trimmed}"
306
+ </Text>
307
+ </Pressable>
308
+ ) : null}
309
+ {filtered.length === 0 && !trimmed ? (
310
+ <View style={{ paddingHorizontal: 10, paddingVertical: 8 }}>
311
+ <Text style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}>
312
+ No matching options. Type a custom value above.
313
+ </Text>
314
+ </View>
315
+ ) : null}
316
+ </ScrollView>
317
+ </View>
318
+ ) : null}
319
+ </View>
320
+ );
321
+ }
322
+
323
+ export function useAgentLaunchOptions(enabled = true) {
324
+ const paseo = usePaseo();
325
+
326
+ const configQuery = useQuery({
327
+ queryKey: ["pr-radar-paseo-config"],
328
+ queryFn: async () => {
329
+ const { config } = await paseo.config.get();
330
+ return config;
331
+ },
332
+ enabled,
333
+ staleTime: 30_000,
334
+ });
335
+
336
+ const profileOptions = useMemo<ComboOption[]>(() => {
337
+ const profiles = configQuery.data?.agentProfiles ?? [];
338
+ return dedupeOptions([
339
+ { label: "Model Router", value: "Model Router", detail: "Default" },
340
+ ...profiles.map((profile) => ({
341
+ label: profile.name,
342
+ value: profile.name,
343
+ detail: [profile.provider, profile.model].filter(Boolean).join("/") || undefined,
344
+ })),
345
+ ]);
346
+ }, [configQuery.data]);
347
+
348
+ const providerOptions = useMemo<ComboOption[]>(() => {
349
+ const profiles = configQuery.data?.agentProfiles ?? [];
350
+ const fromProfiles = profiles
351
+ .map((profile) => profile.provider)
352
+ .filter((provider): provider is string => Boolean(provider?.trim()));
353
+ return dedupeOptions([
354
+ { label: "Use profile default", value: "" },
355
+ ...[...fromProfiles, ...KNOWN_PROVIDERS].map((provider) => ({
356
+ label: provider,
357
+ value: provider,
358
+ })),
359
+ ]);
360
+ }, [configQuery.data]);
361
+
362
+ const modelOptions = useMemo<ComboOption[]>(() => {
363
+ const profiles = configQuery.data?.agentProfiles ?? [];
364
+ const fromProfiles = profiles
365
+ .map((profile) => profile.model)
366
+ .filter((model): model is string => Boolean(model?.trim()));
367
+ return dedupeOptions([
368
+ { label: "Use provider default", value: "" },
369
+ ...[...fromProfiles, ...KNOWN_MODELS].map((model) => ({
370
+ label: model,
371
+ value: model,
372
+ })),
373
+ ]);
374
+ }, [configQuery.data]);
375
+
376
+ const modeOptions = useMemo<ComboOption[]>(() => {
377
+ const profiles = configQuery.data?.agentProfiles ?? [];
378
+ const fromProfiles = profiles
379
+ .map((profile) => profile.modeId)
380
+ .filter((modeId): modeId is string => Boolean(modeId?.trim()));
381
+ return dedupeOptions([
382
+ { label: "Use profile default", value: "" },
383
+ ...[...fromProfiles, ...KNOWN_MODES].map((modeId) => ({
384
+ label: modeId,
385
+ value: modeId,
386
+ })),
387
+ ]);
388
+ }, [configQuery.data]);
389
+
390
+ const contextModeOptions = useMemo<ComboOption[]>(() => {
391
+ const profiles = configQuery.data?.agentProfiles ?? [];
392
+ const fromProfiles = profiles
393
+ .map((profile) => {
394
+ const ctx = profile.options?.contextMode;
395
+ return typeof ctx === "string" ? ctx : undefined;
396
+ })
397
+ .filter((ctx): ctx is string => Boolean(ctx?.trim()));
398
+ return dedupeOptions([
399
+ { label: "Use provider default", value: "" },
400
+ ...[...fromProfiles, ...KNOWN_CONTEXT_MODES].map((ctx) => ({
401
+ label: ctx,
402
+ value: ctx,
403
+ })),
404
+ ]);
405
+ }, [configQuery.data]);
406
+
407
+ return {
408
+ profiles: configQuery.data?.agentProfiles ?? [],
409
+ profileOptions,
410
+ providerOptions,
411
+ modelOptions,
412
+ modeOptions,
413
+ contextModeOptions,
414
+ effortOptions: EFFORT_OPTIONS,
415
+ };
416
+ }
@@ -1,29 +1,60 @@
1
1
  import { isHelperAgent, type PaseoApi } from "./radar";
2
2
 
3
+ interface AgentUpdate {
4
+ id?: unknown;
5
+ workspaceId?: unknown;
6
+ title?: unknown;
7
+ status?: unknown;
8
+ requiresAttention?: unknown;
9
+ attentionReason?: unknown;
10
+ pendingPermissions?: unknown;
11
+ }
12
+
13
+ // The agent fields buildRadarSnapshot and toRadarAgent read, minus `updatedAt`. The daemon touches
14
+ // `updatedAt` and re-publishes a running agent on every usage report, so refetching on it rescanned
15
+ // the directory every second or two. `updatedAt` only orders agents inside a row; the poll keeps it.
16
+ function rowFields(agent: AgentUpdate): string {
17
+ return JSON.stringify([
18
+ agent.workspaceId,
19
+ agent.title,
20
+ agent.status,
21
+ agent.requiresAttention,
22
+ agent.attentionReason,
23
+ agent.pendingPermissions,
24
+ ]);
25
+ }
26
+
3
27
  /**
4
- * Tracks helpers seen on the agent stream so their updates do not refetch the directory. Helpers
5
- * are fixed at creation, so an upsert identifies one and the later removal reuses that knowledge.
6
- * Anything unrecognised still invalidates.
28
+ * Skips agent updates that cannot change a row: helpers (fixed at creation, so an upsert
29
+ * identifies one and the later removal reuses that knowledge) and repeat upserts of a user agent
30
+ * whose row fields are unchanged. Anything unrecognised still invalidates.
7
31
  */
8
- function helperUpdateFilter() {
32
+ function quietUpdateFilter() {
9
33
  const helperIds = new Set<string>();
34
+ const shownFields = new Map<string, string>();
10
35
  return (message: unknown): boolean => {
11
36
  if (typeof message !== "object" || message === null) return false;
12
37
  const { type, payload } = message as {
13
38
  type?: unknown;
14
39
  payload?: {
15
40
  kind?: unknown;
16
- agent?: { id?: unknown } | null;
41
+ agent?: AgentUpdate | null;
17
42
  agentId?: unknown;
18
43
  };
19
44
  };
20
45
  if (type !== "agent_update" || !payload) return false;
21
46
  if (payload.kind === "upsert" && payload.agent && typeof payload.agent.id === "string") {
22
- if (!isHelperAgent(payload.agent)) return false;
23
- helperIds.add(payload.agent.id);
24
- return true;
47
+ if (isHelperAgent(payload.agent)) {
48
+ helperIds.add(payload.agent.id);
49
+ return true;
50
+ }
51
+ const fields = rowFields(payload.agent);
52
+ if (shownFields.get(payload.agent.id) === fields) return true;
53
+ shownFields.set(payload.agent.id, fields);
54
+ return false;
25
55
  }
26
56
  if (payload.kind === "remove" && typeof payload.agentId === "string") {
57
+ shownFields.delete(payload.agentId);
27
58
  return helperIds.delete(payload.agentId);
28
59
  }
29
60
  return false;
@@ -71,7 +102,7 @@ export function observeDirectoryInvalidation(
71
102
 
72
103
  void paseo.agents
73
104
  .list({ subscribe: {}, includeBackground: true, signal: lifetime.signal })
74
- .then(({ subscription }) => attach(subscription, helperUpdateFilter()))
105
+ .then(({ subscription }) => attach(subscription, quietUpdateFilter()))
75
106
  .catch(() => undefined);
76
107
  void paseo.workspaces
77
108
  .list({ subscribe: {}, includeBackground: true })
@@ -0,0 +1,24 @@
1
+ export interface HighlightSegment {
2
+ text: string;
3
+ match: boolean;
4
+ }
5
+
6
+ function escapeRegExp(value: string): string {
7
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
8
+ }
9
+
10
+ export function splitHighlight(text: string, needle: string): HighlightSegment[] {
11
+ const query = needle.trim();
12
+ if (!query || !text) return [{ text, match: false }];
13
+ const pattern = new RegExp(escapeRegExp(query), "giu");
14
+ const segments: HighlightSegment[] = [];
15
+ let cursor = 0;
16
+ for (const found of text.matchAll(pattern)) {
17
+ const start = found.index;
18
+ if (start > cursor) segments.push({ text: text.slice(cursor, start), match: false });
19
+ segments.push({ text: found[0], match: true });
20
+ cursor = start + found[0].length;
21
+ }
22
+ if (cursor < text.length) segments.push({ text: text.slice(cursor), match: false });
23
+ return segments.length > 0 ? segments : [{ text, match: false }];
24
+ }
@@ -0,0 +1,27 @@
1
+ import { Text, type TextStyle } from "react-native";
2
+ import { splitHighlight } from "./highlight";
3
+
4
+ interface HighlightedTextProps {
5
+ text: string;
6
+ query: string;
7
+ highlightStyle: TextStyle;
8
+ }
9
+
10
+ export function HighlightedText({ text, query, highlightStyle }: HighlightedTextProps) {
11
+ let offset = 0;
12
+ return (
13
+ <>
14
+ {splitHighlight(text, query).map((segment) => {
15
+ const key = offset;
16
+ offset += segment.text.length;
17
+ return segment.match ? (
18
+ <Text key={key} style={highlightStyle}>
19
+ {segment.text}
20
+ </Text>
21
+ ) : (
22
+ segment.text
23
+ );
24
+ })}
25
+ </>
26
+ );
27
+ }