@dexhq/canvas 0.14.0 → 0.15.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 +36 -0
- package/README.md +5 -3
- package/app/canvas/activity.tsx +8 -15
- package/app/canvas/anchoring.ts +3 -5
- package/app/canvas/canvas-input.ts +151 -14
- package/app/canvas/canvas-keys.ts +9 -0
- package/app/canvas/canvas-model.ts +5 -42
- package/app/canvas/canvas-panels.ts +1 -17
- package/app/canvas/canvas-scene.ts +7 -3
- package/app/canvas/canvas-ui.ts +2 -1
- package/app/canvas/canvas.css +61 -26
- package/app/canvas/change-notice.tsx +10 -1
- package/app/canvas/comment-layer.tsx +2 -1
- package/app/canvas/comments.tsx +204 -82
- package/app/canvas/element-picker.ts +200 -27
- package/app/canvas/engine/canvas-gestures.ts +72 -17
- package/app/canvas/engine/canvas-store.ts +17 -1
- package/app/canvas/engine/engine.css +6 -3
- package/app/canvas/find-bar.tsx +817 -0
- package/app/canvas/find-model.ts +135 -0
- package/app/canvas/flow-canvas.tsx +18 -2
- package/app/canvas/follow-pin.ts +26 -6
- package/app/canvas/frame-node.tsx +9 -9
- package/app/canvas/imported-reviews.tsx +12 -22
- package/app/canvas/layout.ts +27 -0
- package/app/canvas/live-page.ts +142 -19
- package/app/canvas/page-find.ts +220 -0
- package/app/canvas/page-style.ts +23 -0
- package/app/canvas/section-node.tsx +2 -0
- package/app/canvas/spec-threads.ts +24 -23
- package/app/canvas/thread-focus.tsx +14 -12
- package/app/canvas/use-activity.ts +0 -8
- package/app/canvas/use-agent-changes.tsx +34 -40
- package/app/canvas/use-canvas-clipboard.tsx +11 -14
- package/app/canvas/xray.ts +3 -12
- package/app/frame.tsx +5 -0
- package/app/i18n/locales/en/messages.po +88 -8
- package/app/i18n/locales/en/messages.ts +1 -1
- package/app/i18n/locales/pseudo/messages.po +88 -8
- package/app/i18n/locales/pseudo/messages.ts +1 -1
- package/app/icons/glyphs.tsx +4 -0
- package/app/main.tsx +3 -0
- package/app/pages/canvas.tsx +27 -8
- package/app/pages/commands-settings.tsx +16 -2
- package/app/shell/feedback-form.tsx +10 -21
- package/app/shell/feedback-link.tsx +2 -1
- package/app/shell/scaled-frame.tsx +21 -9
- package/app/types.ts +21 -205
- package/app/ui/file-drop.ts +128 -0
- package/app/ui/shadcn/input-group.tsx +2 -2
- package/dist/cli/banner.d.mts +4 -2
- package/dist/cli/banner.mjs +34 -11
- package/dist/cli/commands/app.mjs +19 -11
- package/dist/cli/commands/hook.mjs +2 -1
- package/dist/config/project-files.d.mts +6 -0
- package/dist/config/project-files.mjs +14 -2
- package/dist/config/renamed.d.mts +0 -2
- package/dist/config/renamed.mjs +1 -3
- package/dist/content/capture.d.mts +2 -2
- package/dist/content/capture.mjs +2 -2
- package/dist/content/content.d.mts +3 -141
- package/dist/content/content.mjs +7 -62
- package/dist/content/flow-specs.mjs +1 -1
- package/dist/content/prototype-summary.d.mts +3 -39
- package/dist/content/prototype-summary.mjs +2 -3
- package/dist/content/prototypes.mjs +1 -1
- package/dist/content/text-replace.d.mts +30 -0
- package/dist/content/text-replace.mjs +309 -0
- package/dist/content/thread-module.mjs +1 -1
- package/dist/content/threads.mjs +1 -1
- package/dist/paste/paste.mjs +1 -1
- package/dist/paths.d.mts +0 -2
- package/dist/paths.mjs +1 -3
- package/dist/server/agent-env.d.mts +5 -1
- package/dist/server/agent-env.mjs +7 -2
- package/dist/server/agent-session.d.mts +14 -1
- package/dist/server/agent-session.mjs +84 -19
- package/dist/server/build-pictures.mjs +1 -1
- package/dist/server/channel.d.mts +13 -24
- package/dist/server/channel.mjs +55 -37
- package/dist/server/claimed-presence.d.mts +3 -2
- package/dist/server/claimed-presence.mjs +15 -7
- package/dist/server/close-check.mjs +2 -2
- package/dist/server/comments/actions.d.mts +153 -0
- package/dist/server/comments/actions.mjs +154 -0
- package/dist/server/comments/routes.d.mts +25 -0
- package/dist/server/comments/routes.mjs +88 -0
- package/dist/server/comments/tools.d.mts +6 -0
- package/dist/server/comments/tools.mjs +154 -0
- package/dist/server/dev-server.mjs +27 -13
- package/dist/server/file-lock.d.mts +2 -2
- package/dist/server/file-lock.mjs +130 -36
- package/dist/server/mcp.d.mts +0 -2
- package/dist/server/mcp.mjs +7 -8
- package/dist/server/me.d.mts +1 -1
- package/dist/server/open-page.d.mts +22 -0
- package/dist/server/open-page.mjs +20 -2
- package/dist/server/outcome.d.mts +22 -0
- package/dist/server/outcome.mjs +8 -0
- package/dist/server/own-copies.mjs +2 -2
- package/dist/server/people.d.mts +1 -1
- package/dist/server/port.d.mts +12 -0
- package/dist/server/port.mjs +66 -14
- package/dist/server/presence.d.mts +4 -1
- package/dist/server/presence.mjs +2 -2
- package/dist/server/requests.d.mts +5 -1
- package/dist/server/requests.mjs +33 -48
- package/dist/server/studio-for.d.mts +5 -0
- package/dist/server/studio-for.mjs +17 -3
- package/dist/server/sync-install.d.mts +8 -12
- package/dist/server/sync-install.mjs +12 -30
- package/dist/server/thread-source.mjs +2 -2
- package/dist/server/tools/describe.d.mts +1 -1
- package/dist/server/tools/describe.mjs +1 -1
- package/dist/server/tools/feedback.d.mts +1 -1
- package/dist/server/tools/reading.mjs +13 -4
- package/dist/server/tools/show.d.mts +1 -1
- package/dist/server/tools/snapshot.d.mts +1 -1
- package/dist/server/tools/thread-list.mjs +1 -1
- package/dist/server/tools/watch.mjs +5 -3
- package/dist/server/vite.mjs +2 -2
- package/dist/server/web-app.mjs +4 -7
- package/dist/server/work-groups.mjs +1 -1
- package/dist/setup/create.d.mts +4 -2
- package/dist/setup/create.mjs +67 -17
- package/dist/setup/design-system-checks.mjs +3 -12
- package/dist/setup/desktop-app-script.mjs +4 -3
- package/dist/setup/desktop-app-start.d.mts +8 -2
- package/dist/setup/desktop-app-start.mjs +64 -29
- package/dist/setup/desktop-app.d.mts +8 -0
- package/dist/setup/desktop-app.mjs +19 -3
- package/dist/setup/detect.d.mts +0 -2
- package/dist/setup/detect.mjs +1 -3
- package/dist/setup/doctor.mjs +1 -1
- package/dist/setup/migrate/row-titles.mjs +1 -1
- package/dist/setup/project.d.mts +6 -1
- package/dist/setup/project.mjs +9 -9
- package/dist/setup/starters.d.mts +2 -0
- package/dist/setup/starters.mjs +7 -1
- package/dist/shared/annotations-core.mjs +1 -1
- package/dist/shared/canvas-core.mjs +1 -1
- package/dist/shared/canvas-file.d.mts +201 -0
- package/dist/shared/canvas-file.mjs +1 -0
- package/dist/shared/comments/routes.d.mts +53 -0
- package/dist/shared/comments/routes.mjs +37 -0
- package/dist/shared/feedback.d.mts +8 -0
- package/dist/shared/feedback.mjs +10 -2
- package/dist/shared/page-review.d.mts +2 -11
- package/dist/shared/page-review.mjs +4 -13
- package/dist/shared/presence-core.d.mts +11 -0
- package/dist/shared/presence-core.mjs +11 -2
- package/dist/shared/review-file.d.mts +5 -0
- package/dist/shared/review-file.mjs +23 -13
- package/dist/shared/server-page.mjs +1 -1
- package/dist/shared/signup.d.mts +2 -5
- package/dist/shared/signup.mjs +2 -35
- package/dist/shared/studio-events.d.mts +0 -6
- package/dist/shared/studio-events.mjs +1 -5
- package/dist/shared/studio-files.d.mts +12 -0
- package/dist/shared/studio-files.mjs +6 -1
- package/dist/shared/studio-routes.d.mts +16 -62
- package/dist/shared/studio-routes.mjs +1 -69
- package/dist/shared/threads-core.d.mts +2 -2
- package/dist/shared/threads-core.mjs +1 -1
- package/extension/dist/feedback.js +148 -138
- package/extension/dist/manifest.json +1 -1
- package/extension/dist/picker.js +146 -136
- package/package.json +2 -2
- package/src/cli/banner.ts +45 -11
- package/src/cli/commands/app.ts +23 -8
- package/src/cli/commands/hook.ts +4 -1
- package/src/config/project-files.ts +21 -6
- package/src/config/renamed.ts +0 -3
- package/src/content/capture.ts +6 -12
- package/src/content/content.ts +7 -241
- package/src/content/flow-specs.ts +2 -1
- package/src/content/prototype-summary.ts +4 -44
- package/src/content/review-pages.ts +2 -1
- package/src/content/text-replace.ts +449 -0
- package/src/paths.ts +0 -8
- package/src/server/agent-env.ts +12 -2
- package/src/server/agent-session.ts +124 -34
- package/src/server/channel.ts +94 -52
- package/src/server/claimed-presence.ts +26 -10
- package/src/server/comments/actions.ts +352 -0
- package/src/server/comments/routes.ts +176 -0
- package/src/server/comments/tools.ts +317 -0
- package/src/server/dev-server.ts +36 -15
- package/src/server/file-lock.ts +205 -54
- package/src/server/mcp.ts +13 -14
- package/src/server/me.ts +2 -5
- package/src/server/open-page.ts +54 -4
- package/src/server/outcome.ts +26 -0
- package/src/server/people.ts +2 -1
- package/src/server/port.ts +94 -20
- package/src/server/presence.ts +11 -3
- package/src/server/requests.ts +60 -70
- package/src/server/studio-for.ts +26 -2
- package/src/server/sync-install.ts +35 -26
- package/src/server/thread-place.ts +2 -4
- package/src/server/tools/reading.ts +16 -3
- package/src/server/tools/watch.ts +7 -7
- package/src/server/web-app.ts +11 -9
- package/src/setup/create.ts +91 -17
- package/src/setup/design-system-checks.ts +7 -15
- package/src/setup/desktop-app-script.ts +4 -3
- package/src/setup/desktop-app-start.ts +94 -26
- package/src/setup/desktop-app.ts +23 -2
- package/src/setup/detect.ts +0 -4
- package/src/setup/project.ts +9 -8
- package/src/setup/starters.ts +8 -1
- package/src/shared/canvas-file.ts +205 -0
- package/src/shared/comments/routes.ts +79 -0
- package/src/shared/feedback.ts +14 -4
- package/src/shared/page-review.ts +11 -16
- package/src/shared/presence-core.ts +16 -2
- package/src/shared/review-file.ts +28 -12
- package/src/shared/server-page.ts +2 -1
- package/src/shared/signup.ts +4 -28
- package/src/shared/studio-events.ts +0 -13
- package/src/shared/studio-files.ts +14 -0
- package/src/shared/studio-routes.ts +21 -64
- package/src/shared/threads-core.ts +2 -2
- package/dist/server/tools/close-reply.d.mts +0 -6
- package/dist/server/tools/close-reply.mjs +0 -138
- package/dist/server/tools/comment.d.mts +0 -6
- package/dist/server/tools/comment.mjs +0 -49
- package/src/server/tools/close-reply.ts +0 -271
- package/src/server/tools/comment.ts +0 -96
|
@@ -0,0 +1,817 @@
|
|
|
1
|
+
import type { MessageDescriptor } from "@lingui/core";
|
|
2
|
+
import { msg } from "@lingui/core/macro";
|
|
3
|
+
import { Trans, useLingui } from "@lingui/react/macro";
|
|
4
|
+
import { Icon, type IconName } from "@studio/icons";
|
|
5
|
+
import { Button } from "@studio/ui/shadcn/button";
|
|
6
|
+
import { cn } from "cn";
|
|
7
|
+
import {
|
|
8
|
+
type KeyboardEvent as ReactKeyboardEvent,
|
|
9
|
+
useCallback,
|
|
10
|
+
useEffect,
|
|
11
|
+
useMemo,
|
|
12
|
+
useRef,
|
|
13
|
+
useState,
|
|
14
|
+
} from "react";
|
|
15
|
+
import { flushSync } from "react-dom";
|
|
16
|
+
import { withBase } from "../base";
|
|
17
|
+
import { problemsOf } from "../live/studio-action";
|
|
18
|
+
import { studioRequest } from "../live/studio-request";
|
|
19
|
+
import { COVERS_CANVAS } from "./canvas-clipboard.ts";
|
|
20
|
+
import { useCanvas } from "./canvas-context";
|
|
21
|
+
import { isFindKey } from "./canvas-keys.ts";
|
|
22
|
+
import { sceneItem } from "./canvas-scene";
|
|
23
|
+
import { useCanvasView } from "./engine/canvas-view";
|
|
24
|
+
import {
|
|
25
|
+
findOnFrames,
|
|
26
|
+
type Hit,
|
|
27
|
+
hitsByFrame,
|
|
28
|
+
MOST_HITS,
|
|
29
|
+
seenTexts,
|
|
30
|
+
snippet,
|
|
31
|
+
stepHit,
|
|
32
|
+
} from "./find-model.ts";
|
|
33
|
+
import { frameSource } from "./frame-source";
|
|
34
|
+
import { framePages, type LivePage, onFramePages } from "./live-page";
|
|
35
|
+
import { hitsIn, type PageHit, readPageTexts } from "./page-find.ts";
|
|
36
|
+
import { useCanvasScene } from "./scene-context";
|
|
37
|
+
import { Tip, TipGroup } from "./tip";
|
|
38
|
+
|
|
39
|
+
// Find on the canvas: ⌘F opens a bar at the top, over the middle of the
|
|
40
|
+
// canvas, that finds words on every frame's page. Each match is painted
|
|
41
|
+
// yellow on its page, the current one brighter, and the canvas moves to it
|
|
42
|
+
// as it becomes current. The count, the steps either way, and a list of the
|
|
43
|
+
// matches by frame; on a canvas you can change, Replace all, which changes
|
|
44
|
+
// the words in your own files of this file, and Undo. Only the key opens it.
|
|
45
|
+
|
|
46
|
+
/** The canvas never zooms out past this to show a match: it reads there. */
|
|
47
|
+
const REVEAL_ZOOM = 0.6;
|
|
48
|
+
const REVEAL_MS = 220;
|
|
49
|
+
/** How near the screen's edge a match counts as off it, in pixels. */
|
|
50
|
+
const REVEAL_MARGIN = 80;
|
|
51
|
+
/** How long a page's changes settle before it is searched again. */
|
|
52
|
+
const SETTLE_MS = 120;
|
|
53
|
+
/** How often the canvas looks again for a match not placed yet. */
|
|
54
|
+
const LOOKS_AGAIN = 2;
|
|
55
|
+
/** Pages read off the canvas at once. */
|
|
56
|
+
const READ_AT_ONCE = 2;
|
|
57
|
+
/** How old a page's texts read off the canvas can be before reading again. */
|
|
58
|
+
const READ_AGAIN_MS = 60_000;
|
|
59
|
+
/** How long a change to the code takes to reach a page that loads. */
|
|
60
|
+
const SETTLE_AFTER_CHANGE_MS = 600;
|
|
61
|
+
/** Rows the list draws at most; the count says how many there are. */
|
|
62
|
+
const LISTED = 200;
|
|
63
|
+
const FIND_BAR = "[data-find-bar]";
|
|
64
|
+
/** Most text a Replace all sends, well under the studio's request limit. */
|
|
65
|
+
const MOST_SEEN_BYTES = 900_000;
|
|
66
|
+
|
|
67
|
+
/** What the studio answers a replacement, or its undo. */
|
|
68
|
+
type ReplaceAnswer = Awaited<
|
|
69
|
+
ReturnType<typeof studioRequest<"replace", "POST">>
|
|
70
|
+
>;
|
|
71
|
+
|
|
72
|
+
type Status =
|
|
73
|
+
| { kind: "replaced"; files: number; replaced: number; undo?: string }
|
|
74
|
+
| { kind: "message"; text: string };
|
|
75
|
+
|
|
76
|
+
/** A view frame: its key, its name, and its page. */
|
|
77
|
+
interface ViewFrame {
|
|
78
|
+
href: string;
|
|
79
|
+
key: string;
|
|
80
|
+
size: { height: number; width: number };
|
|
81
|
+
title: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Each frame's texts, as its page last showed them, kept while the bar is
|
|
86
|
+
* closed too, and the pages on the canvas now, searched as they change.
|
|
87
|
+
* While the bar is open, the frames whose pages are not on the canvas (off
|
|
88
|
+
* screen, or never shown yet) are read out of sight, a couple at a time, so
|
|
89
|
+
* every frame is found on. `forget` reads those again: after a replacement.
|
|
90
|
+
*/
|
|
91
|
+
const useFrameTexts = (open: boolean, frames: readonly ViewFrame[]) => {
|
|
92
|
+
const texts = useRef(new Map<string, string[]>());
|
|
93
|
+
const live = useRef(new Map<string, Text[]>());
|
|
94
|
+
const readAt = useRef(new Map<string, number>());
|
|
95
|
+
const inFlight = useRef(new Set<string>());
|
|
96
|
+
const pending = useRef<readonly ViewFrame[]>([]);
|
|
97
|
+
const [version, setVersion] = useState(0);
|
|
98
|
+
/** When the pages off the canvas were last read again, at the latest. */
|
|
99
|
+
const [forgottenAt, setForgottenAt] = useState(0);
|
|
100
|
+
const [reading, setReading] = useState(false);
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
const watched = new Map<string, { page: LivePage; stop: () => void }>();
|
|
104
|
+
const dirty = new Set<string>();
|
|
105
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
106
|
+
const flush = () => {
|
|
107
|
+
timer = undefined;
|
|
108
|
+
for (const key of dirty) {
|
|
109
|
+
const page = framePages.get(key);
|
|
110
|
+
if (page) {
|
|
111
|
+
const nodes = page.texts();
|
|
112
|
+
live.current.set(key, nodes);
|
|
113
|
+
// A page still loading, or hidden while it updates, shows nothing
|
|
114
|
+
// for a moment: what it showed before still counts until it shows.
|
|
115
|
+
if (nodes.length > 0 || !texts.current.has(key)) {
|
|
116
|
+
texts.current.set(
|
|
117
|
+
key,
|
|
118
|
+
nodes.map(({ data }) => data)
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
dirty.clear();
|
|
124
|
+
setVersion((count) => count + 1);
|
|
125
|
+
};
|
|
126
|
+
const changed = (key: string) => {
|
|
127
|
+
dirty.add(key);
|
|
128
|
+
timer ??= setTimeout(flush, SETTLE_MS);
|
|
129
|
+
};
|
|
130
|
+
const sync = () => {
|
|
131
|
+
for (const [key, { page, stop }] of watched) {
|
|
132
|
+
if (framePages.get(key) !== page) {
|
|
133
|
+
stop();
|
|
134
|
+
watched.delete(key);
|
|
135
|
+
live.current.delete(key);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
for (const [key, page] of framePages) {
|
|
139
|
+
if (watched.has(key)) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
// Each time a page has painted its view; open, every change too.
|
|
143
|
+
// Closed, painting is all a page asks of the canvas.
|
|
144
|
+
const stopPainted = page.onPainted(() => changed(key));
|
|
145
|
+
const stopChanges = open
|
|
146
|
+
? page.onChange(() => changed(key))
|
|
147
|
+
: () => undefined;
|
|
148
|
+
watched.set(key, {
|
|
149
|
+
page,
|
|
150
|
+
stop: () => {
|
|
151
|
+
stopPainted();
|
|
152
|
+
stopChanges();
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
sync();
|
|
158
|
+
const stopPages = onFramePages(sync);
|
|
159
|
+
return () => {
|
|
160
|
+
stopPages();
|
|
161
|
+
clearTimeout(timer);
|
|
162
|
+
for (const { stop } of watched.values()) {
|
|
163
|
+
stop();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}, [open]);
|
|
167
|
+
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (!open) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
let stopped = false;
|
|
173
|
+
const before = Math.max(Date.now() - READ_AGAIN_MS, forgottenAt);
|
|
174
|
+
// A page on the canvas that shows nothing yet (zoomed out, its lazy
|
|
175
|
+
// iframe not loaded) is read out of sight too.
|
|
176
|
+
const unread = (key: string) =>
|
|
177
|
+
!framePages.has(key) || (live.current.get(key)?.length ?? 0) === 0;
|
|
178
|
+
const queue = frames.filter(
|
|
179
|
+
({ key }) =>
|
|
180
|
+
unread(key) &&
|
|
181
|
+
!inFlight.current.has(key) &&
|
|
182
|
+
(readAt.current.get(key) ?? 0) < before
|
|
183
|
+
);
|
|
184
|
+
// Reading until every read has come back, this one's or an earlier's,
|
|
185
|
+
// and the frames waiting now have been read.
|
|
186
|
+
pending.current = queue;
|
|
187
|
+
const settle = () =>
|
|
188
|
+
setReading(pending.current.length > 0 || inFlight.current.size > 0);
|
|
189
|
+
const work = async () => {
|
|
190
|
+
for (let next = queue.shift(); next && !stopped; next = queue.shift()) {
|
|
191
|
+
inFlight.current.add(next.key);
|
|
192
|
+
const read = await readPageTexts(withBase(next.href), next.size);
|
|
193
|
+
inFlight.current.delete(next.key);
|
|
194
|
+
settle();
|
|
195
|
+
readAt.current.set(next.key, Date.now());
|
|
196
|
+
// A page that came on the canvas meanwhile is read there.
|
|
197
|
+
if (unread(next.key)) {
|
|
198
|
+
texts.current.set(next.key, read);
|
|
199
|
+
setVersion((count) => count + 1);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
settle();
|
|
204
|
+
Promise.all(Array.from({ length: READ_AT_ONCE }, work)).finally(settle);
|
|
205
|
+
return () => {
|
|
206
|
+
stopped = true;
|
|
207
|
+
};
|
|
208
|
+
}, [forgottenAt, frames, open]);
|
|
209
|
+
|
|
210
|
+
const forget = useCallback(() => setForgottenAt(Date.now()), []);
|
|
211
|
+
|
|
212
|
+
// A copy each time they change, so what reads them knows they did.
|
|
213
|
+
return useMemo(
|
|
214
|
+
() => ({
|
|
215
|
+
forget,
|
|
216
|
+
live: new Map(live.current),
|
|
217
|
+
reading,
|
|
218
|
+
texts: new Map(texts.current),
|
|
219
|
+
version,
|
|
220
|
+
}),
|
|
221
|
+
[forget, reading, version]
|
|
222
|
+
);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/** The view frames, in the canvas's order. */
|
|
226
|
+
const useFrames = (): ViewFrame[] => {
|
|
227
|
+
const { prototype } = useCanvas();
|
|
228
|
+
const scene = useCanvasScene();
|
|
229
|
+
return useMemo(
|
|
230
|
+
() =>
|
|
231
|
+
scene.items.flatMap((item) => {
|
|
232
|
+
const node = sceneItem(item);
|
|
233
|
+
if (node.type !== "frame") {
|
|
234
|
+
return [];
|
|
235
|
+
}
|
|
236
|
+
const source = frameSource(prototype, node.data.frame);
|
|
237
|
+
return source.kind === "view"
|
|
238
|
+
? [
|
|
239
|
+
{
|
|
240
|
+
href: source.href,
|
|
241
|
+
key: item.id,
|
|
242
|
+
size: source.size,
|
|
243
|
+
title: source.title,
|
|
244
|
+
},
|
|
245
|
+
]
|
|
246
|
+
: [];
|
|
247
|
+
}),
|
|
248
|
+
[prototype, scene]
|
|
249
|
+
);
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const HitRow = ({
|
|
253
|
+
current,
|
|
254
|
+
hit,
|
|
255
|
+
length,
|
|
256
|
+
onPick,
|
|
257
|
+
}: {
|
|
258
|
+
current: boolean;
|
|
259
|
+
hit: Hit;
|
|
260
|
+
length: number;
|
|
261
|
+
onPick: () => void;
|
|
262
|
+
}) => {
|
|
263
|
+
const { before, match, after } = snippet(hit, length);
|
|
264
|
+
return (
|
|
265
|
+
<li>
|
|
266
|
+
<button
|
|
267
|
+
aria-current={current ? "true" : undefined}
|
|
268
|
+
className={cn(
|
|
269
|
+
"studio-small block w-full truncate rounded-md px-2 py-1 text-left text-muted-foreground outline-none hover:bg-studio-hover focus-visible:bg-studio-hover",
|
|
270
|
+
current && "bg-studio-hover text-foreground"
|
|
271
|
+
)}
|
|
272
|
+
onClick={onPick}
|
|
273
|
+
type="button"
|
|
274
|
+
>
|
|
275
|
+
{before}
|
|
276
|
+
<mark
|
|
277
|
+
className={cn(
|
|
278
|
+
"rounded-[2px] text-[#0a0a0a]",
|
|
279
|
+
current ? "bg-[#ffd34d]" : "bg-[#ffd34d]/45"
|
|
280
|
+
)}
|
|
281
|
+
>
|
|
282
|
+
{match}
|
|
283
|
+
</mark>
|
|
284
|
+
{after}
|
|
285
|
+
</button>
|
|
286
|
+
</li>
|
|
287
|
+
);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/** Opens the bar on ⌘F, over the canvas or a frame's page (canvas-input). */
|
|
291
|
+
const useFindKey = (onFind: () => void) => {
|
|
292
|
+
const latest = useRef(onFind);
|
|
293
|
+
latest.current = onFind;
|
|
294
|
+
useEffect(() => {
|
|
295
|
+
const onKey = (event: KeyboardEvent) => {
|
|
296
|
+
if (!isFindKey(event) || document.querySelector(COVERS_CANVAS)) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
event.preventDefault();
|
|
300
|
+
event.stopPropagation();
|
|
301
|
+
latest.current();
|
|
302
|
+
};
|
|
303
|
+
window.addEventListener("keydown", onKey, { capture: true });
|
|
304
|
+
return () =>
|
|
305
|
+
window.removeEventListener("keydown", onKey, { capture: true });
|
|
306
|
+
}, []);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
type CanvasViewStore = ReturnType<typeof useCanvasView>;
|
|
310
|
+
|
|
311
|
+
/** Where on the canvas a match is: itself once placed, else its frame. */
|
|
312
|
+
const matchPoint = (
|
|
313
|
+
item: { height: number; width: number; x: number; y: number },
|
|
314
|
+
placed: DOMRect | undefined
|
|
315
|
+
) =>
|
|
316
|
+
placed
|
|
317
|
+
? {
|
|
318
|
+
x: item.x + placed.x + placed.width / 2,
|
|
319
|
+
y: item.y + placed.y + placed.height / 2,
|
|
320
|
+
}
|
|
321
|
+
: {
|
|
322
|
+
x: item.x + item.width / 2,
|
|
323
|
+
y: item.y + Math.min(item.height / 2, 400),
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Whether a point on the canvas is on screen, at a zoom that reads, and not
|
|
328
|
+
* under the bar, which reaches `covered` pixels down.
|
|
329
|
+
*/
|
|
330
|
+
const readable = (
|
|
331
|
+
view: CanvasViewStore,
|
|
332
|
+
point: { x: number; y: number },
|
|
333
|
+
covered: number
|
|
334
|
+
) => {
|
|
335
|
+
const at = view.canvasToScreen(point);
|
|
336
|
+
const screen = view.getScreen();
|
|
337
|
+
return (
|
|
338
|
+
view.getZoom() >= REVEAL_ZOOM &&
|
|
339
|
+
at.x > REVEAL_MARGIN &&
|
|
340
|
+
at.y > Math.max(REVEAL_MARGIN, covered + REVEAL_MARGIN / 2) &&
|
|
341
|
+
at.x < screen.width - REVEAL_MARGIN &&
|
|
342
|
+
at.y < screen.height - REVEAL_MARGIN
|
|
343
|
+
);
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
/** A match's place on its page, once it has one: none while not laid out. */
|
|
347
|
+
const placeOf = (range: Range | undefined) => {
|
|
348
|
+
const box = range?.getBoundingClientRect();
|
|
349
|
+
return box && (box.width > 0 || box.height > 0) ? box : undefined;
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Moves the canvas to the current match: to its frame, and once its page is
|
|
354
|
+
* on the canvas and laid out, to the match itself, unless it is on screen
|
|
355
|
+
* already. Once for each `step`, and again once the match can be placed.
|
|
356
|
+
*/
|
|
357
|
+
const useRevealHit = (
|
|
358
|
+
hit: Hit | undefined,
|
|
359
|
+
pageHits: ReadonlyMap<string, PageHit[]>,
|
|
360
|
+
step: number
|
|
361
|
+
) => {
|
|
362
|
+
const view = useCanvasView();
|
|
363
|
+
const revealed = useRef<{
|
|
364
|
+
exact: boolean;
|
|
365
|
+
hit?: Hit;
|
|
366
|
+
looks: number;
|
|
367
|
+
step: number;
|
|
368
|
+
}>({ exact: false, looks: 0, step: -1 });
|
|
369
|
+
/** Looks again once a move has ended: the page may be laid out by then. */
|
|
370
|
+
const [again, setAgain] = useState(0);
|
|
371
|
+
useEffect(() => {
|
|
372
|
+
const item = hit && view.getItem(hit.frame);
|
|
373
|
+
if (!(hit && item)) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const range = pageHits.get(hit.frame)?.[hit.index]?.range;
|
|
377
|
+
const placed = placeOf(range);
|
|
378
|
+
const last = revealed.current;
|
|
379
|
+
const same =
|
|
380
|
+
last.step === step &&
|
|
381
|
+
last.hit?.frame === hit.frame &&
|
|
382
|
+
last.hit.index === hit.index;
|
|
383
|
+
if (same && again === last.looks && (last.exact || !placed)) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
const looks = same ? again : 0;
|
|
387
|
+
revealed.current = { exact: Boolean(placed), hit, looks, step };
|
|
388
|
+
const point = matchPoint(item, placed);
|
|
389
|
+
const bar = document.querySelector(FIND_BAR)?.getBoundingClientRect();
|
|
390
|
+
if (readable(view, point, bar?.bottom ?? 0)) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
view.setCenter(point.x, point.y, {
|
|
394
|
+
duration: REVEAL_MS,
|
|
395
|
+
zoom: Math.max(view.getZoom(), REVEAL_ZOOM),
|
|
396
|
+
});
|
|
397
|
+
if (placed || !range || looks >= LOOKS_AGAIN) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const timer = setTimeout(() => setAgain(looks + 1), REVEAL_MS + SETTLE_MS);
|
|
401
|
+
return () => clearTimeout(timer);
|
|
402
|
+
}, [again, hit, pageHits, step, view]);
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
/** Paints each page's matches while it is on the canvas; none once closed. */
|
|
406
|
+
const usePaintHits = (
|
|
407
|
+
hit: Hit | undefined,
|
|
408
|
+
pageHits: ReadonlyMap<string, PageHit[]>
|
|
409
|
+
) => {
|
|
410
|
+
useEffect(() => {
|
|
411
|
+
for (const [key, page] of framePages) {
|
|
412
|
+
const hits = pageHits.get(key) ?? [];
|
|
413
|
+
const here = hit?.frame === key ? hits[hit.index]?.range : undefined;
|
|
414
|
+
page.paintHits(hits, here);
|
|
415
|
+
}
|
|
416
|
+
}, [hit, pageHits]);
|
|
417
|
+
useEffect(
|
|
418
|
+
() => () => {
|
|
419
|
+
for (const page of framePages.values()) {
|
|
420
|
+
page.paintHits([]);
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
[]
|
|
424
|
+
);
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
/** Replace all and its Undo, through the studio, and what each did. */
|
|
428
|
+
const useReplace = (forget: () => void) => {
|
|
429
|
+
const { t, i18n } = useLingui();
|
|
430
|
+
const { prototype } = useCanvas();
|
|
431
|
+
const [status, setStatus] = useState<Status>();
|
|
432
|
+
const [busy, setBusy] = useState(false);
|
|
433
|
+
const run = async (
|
|
434
|
+
body: Record<string, unknown>,
|
|
435
|
+
said: (done: ReplaceAnswer) => Status,
|
|
436
|
+
failed: MessageDescriptor
|
|
437
|
+
) => {
|
|
438
|
+
setBusy(true);
|
|
439
|
+
try {
|
|
440
|
+
const done = await studioRequest("replace", {
|
|
441
|
+
method: "POST",
|
|
442
|
+
body: { ...body, slug: prototype.slug },
|
|
443
|
+
});
|
|
444
|
+
// Once the change has reached the pages: Vite takes a moment.
|
|
445
|
+
setTimeout(forget, SETTLE_AFTER_CHANGE_MS);
|
|
446
|
+
setStatus(said(done));
|
|
447
|
+
} catch (error) {
|
|
448
|
+
setStatus({
|
|
449
|
+
kind: "message",
|
|
450
|
+
text: problemsOf(error, i18n, failed).join(" "),
|
|
451
|
+
});
|
|
452
|
+
} finally {
|
|
453
|
+
setBusy(false);
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
const replaceAll = (find: string, to: string, seen: string[]) =>
|
|
457
|
+
run(
|
|
458
|
+
{ find, seen, to },
|
|
459
|
+
(done) => {
|
|
460
|
+
if (!("replaced" in done)) {
|
|
461
|
+
return { kind: "message", text: t`Nothing changed.` };
|
|
462
|
+
}
|
|
463
|
+
const left = done.left ?? 0;
|
|
464
|
+
if (done.replaced === 0 && left > 0) {
|
|
465
|
+
return {
|
|
466
|
+
kind: "message",
|
|
467
|
+
text: t`Nothing changed: ${left} files changed meanwhile, or could not be written. Try again.`,
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
if (done.replaced === 0) {
|
|
471
|
+
return {
|
|
472
|
+
kind: "message",
|
|
473
|
+
text: t`Nothing changed: these words aren't written as text in your files.`,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
return {
|
|
477
|
+
files: done.files.length,
|
|
478
|
+
kind: "replaced",
|
|
479
|
+
replaced: done.replaced,
|
|
480
|
+
undo: done.undo,
|
|
481
|
+
};
|
|
482
|
+
},
|
|
483
|
+
msg`They could not be replaced.`
|
|
484
|
+
);
|
|
485
|
+
const undo = (id: string) =>
|
|
486
|
+
run(
|
|
487
|
+
{ undo: id },
|
|
488
|
+
(done) => {
|
|
489
|
+
const kept = "kept" in done ? done.kept.length : 0;
|
|
490
|
+
return {
|
|
491
|
+
kind: "message",
|
|
492
|
+
text:
|
|
493
|
+
kept > 0
|
|
494
|
+
? t`Put back, but for ${kept} files changed since.`
|
|
495
|
+
: t`Put back.`,
|
|
496
|
+
};
|
|
497
|
+
},
|
|
498
|
+
msg`It could not be put back.`
|
|
499
|
+
);
|
|
500
|
+
return { busy, replaceAll, setStatus, status, undo };
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
/** Escape closes the bar; Enter does a field's thing, Shift Enter its other. */
|
|
504
|
+
const fieldKeys =
|
|
505
|
+
(close: () => void, enter: (shift: boolean) => void) =>
|
|
506
|
+
(event: ReactKeyboardEvent<HTMLInputElement>) => {
|
|
507
|
+
if (event.key === "Escape") {
|
|
508
|
+
event.preventDefault();
|
|
509
|
+
event.stopPropagation();
|
|
510
|
+
close();
|
|
511
|
+
} else if (event.key === "Enter" && !event.nativeEvent.isComposing) {
|
|
512
|
+
event.preventDefault();
|
|
513
|
+
enter(event.shiftKey);
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
const FIELD =
|
|
518
|
+
"studio-small h-7 min-w-0 flex-1 bg-transparent px-1 outline-none placeholder:text-muted-foreground";
|
|
519
|
+
|
|
520
|
+
/** A round button of the bar, its name in a tip. */
|
|
521
|
+
const BarButton = ({
|
|
522
|
+
disabled,
|
|
523
|
+
icon,
|
|
524
|
+
label,
|
|
525
|
+
onClick,
|
|
526
|
+
shortcut,
|
|
527
|
+
}: {
|
|
528
|
+
disabled?: boolean;
|
|
529
|
+
icon: IconName;
|
|
530
|
+
label: string;
|
|
531
|
+
onClick: () => void;
|
|
532
|
+
shortcut?: string;
|
|
533
|
+
}) => (
|
|
534
|
+
<Tip label={label} shortcut={shortcut}>
|
|
535
|
+
<Button
|
|
536
|
+
aria-label={label}
|
|
537
|
+
className="size-7 rounded-full"
|
|
538
|
+
disabled={disabled}
|
|
539
|
+
onClick={onClick}
|
|
540
|
+
size="icon-sm"
|
|
541
|
+
variant="ghost"
|
|
542
|
+
>
|
|
543
|
+
<Icon name={icon} />
|
|
544
|
+
</Button>
|
|
545
|
+
</Tip>
|
|
546
|
+
);
|
|
547
|
+
|
|
548
|
+
/** What Replace all or Undo did, and Undo while it can. */
|
|
549
|
+
const StatusLine = ({
|
|
550
|
+
busy,
|
|
551
|
+
onUndo,
|
|
552
|
+
status,
|
|
553
|
+
}: {
|
|
554
|
+
busy: boolean;
|
|
555
|
+
onUndo: (id: string) => void;
|
|
556
|
+
status: Status;
|
|
557
|
+
}) => (
|
|
558
|
+
<p
|
|
559
|
+
className="studio-small flex items-center gap-2 px-2 pt-1.5 pb-1 text-muted-foreground"
|
|
560
|
+
role="status"
|
|
561
|
+
>
|
|
562
|
+
<span className="min-w-0 flex-1">
|
|
563
|
+
{status.kind === "replaced" ? (
|
|
564
|
+
<Trans>
|
|
565
|
+
Replaced {status.replaced} in {status.files} files.
|
|
566
|
+
</Trans>
|
|
567
|
+
) : (
|
|
568
|
+
status.text
|
|
569
|
+
)}
|
|
570
|
+
</span>
|
|
571
|
+
{status.kind === "replaced" && status.undo ? (
|
|
572
|
+
<Button
|
|
573
|
+
className="h-6 rounded-full px-2"
|
|
574
|
+
disabled={busy}
|
|
575
|
+
onClick={() => status.undo && onUndo(status.undo)}
|
|
576
|
+
size="xs"
|
|
577
|
+
variant="ghost"
|
|
578
|
+
>
|
|
579
|
+
<Icon data-icon="inline-start" name="Undo2" />
|
|
580
|
+
<Trans>Undo</Trans>
|
|
581
|
+
</Button>
|
|
582
|
+
) : null}
|
|
583
|
+
</p>
|
|
584
|
+
);
|
|
585
|
+
|
|
586
|
+
/** The matches, by frame, the current one marked; a click goes to one. */
|
|
587
|
+
const HitList = ({
|
|
588
|
+
at,
|
|
589
|
+
hits,
|
|
590
|
+
length,
|
|
591
|
+
onPick,
|
|
592
|
+
}: {
|
|
593
|
+
at: number;
|
|
594
|
+
hits: readonly Hit[];
|
|
595
|
+
length: number;
|
|
596
|
+
onPick: (index: number) => void;
|
|
597
|
+
}) => {
|
|
598
|
+
const groups = hitsByFrame(hits.slice(0, LISTED));
|
|
599
|
+
if (groups.length === 0) {
|
|
600
|
+
return null;
|
|
601
|
+
}
|
|
602
|
+
return (
|
|
603
|
+
<div className="mt-[3px] max-h-64 overflow-y-auto overscroll-contain border-studio-edge border-t px-1 pt-1 pb-0.5">
|
|
604
|
+
{groups.map((group) => (
|
|
605
|
+
<section aria-label={group.title} key={group.frame}>
|
|
606
|
+
<h3 className="studio-label truncate px-2 pt-1.5 pb-0.5 text-muted-foreground">
|
|
607
|
+
{group.title}
|
|
608
|
+
</h3>
|
|
609
|
+
<ul>
|
|
610
|
+
{group.hits.map(({ at: index, hit }) => (
|
|
611
|
+
<HitRow
|
|
612
|
+
current={index === at}
|
|
613
|
+
hit={hit}
|
|
614
|
+
key={`${hit.frame}:${hit.index}`}
|
|
615
|
+
length={length}
|
|
616
|
+
onPick={() => onPick(index)}
|
|
617
|
+
/>
|
|
618
|
+
))}
|
|
619
|
+
</ul>
|
|
620
|
+
</section>
|
|
621
|
+
))}
|
|
622
|
+
</div>
|
|
623
|
+
);
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
export const FindBar = ({ writable }: { writable: boolean }) => {
|
|
627
|
+
const { t } = useLingui();
|
|
628
|
+
const [open, setOpen] = useState(false);
|
|
629
|
+
const [query, setQuery] = useState("");
|
|
630
|
+
const [replacing, setReplacing] = useState(false);
|
|
631
|
+
const [replacement, setReplacement] = useState("");
|
|
632
|
+
const [current, setCurrent] = useState(0);
|
|
633
|
+
/** Each step to a match, so a step to the one shown moves there again. */
|
|
634
|
+
const [step, setStep] = useState(0);
|
|
635
|
+
const findField = useRef<HTMLInputElement>(null);
|
|
636
|
+
const frames = useFrames();
|
|
637
|
+
const { forget, live, reading, texts } = useFrameTexts(open, frames);
|
|
638
|
+
const { busy, replaceAll, setStatus, status, undo } = useReplace(forget);
|
|
639
|
+
|
|
640
|
+
// Open now, so the keys typed straight after ⌘F go to the field.
|
|
641
|
+
useFindKey(() => {
|
|
642
|
+
flushSync(() => setOpen(true));
|
|
643
|
+
findField.current?.focus();
|
|
644
|
+
findField.current?.select();
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
const found = useMemo(
|
|
648
|
+
() =>
|
|
649
|
+
findOnFrames(
|
|
650
|
+
open
|
|
651
|
+
? frames.map(({ key, title }) => ({
|
|
652
|
+
key,
|
|
653
|
+
texts: texts.get(key) ?? [],
|
|
654
|
+
title,
|
|
655
|
+
}))
|
|
656
|
+
: [],
|
|
657
|
+
query
|
|
658
|
+
),
|
|
659
|
+
[frames, open, query, texts]
|
|
660
|
+
);
|
|
661
|
+
const count = found.hits.length;
|
|
662
|
+
const at = count === 0 ? 0 : Math.min(current, count - 1);
|
|
663
|
+
const hit = open ? found.hits[at] : undefined;
|
|
664
|
+
|
|
665
|
+
const pageHits = useMemo(() => {
|
|
666
|
+
const byFrame = new Map<string, PageHit[]>();
|
|
667
|
+
if (open && query.trim()) {
|
|
668
|
+
for (const [key, nodes] of live) {
|
|
669
|
+
byFrame.set(key, hitsIn(nodes, query, MOST_HITS));
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return byFrame;
|
|
673
|
+
}, [live, open, query]);
|
|
674
|
+
usePaintHits(hit, pageHits);
|
|
675
|
+
useRevealHit(hit, pageHits, step);
|
|
676
|
+
|
|
677
|
+
const go = (next: number) => {
|
|
678
|
+
setCurrent(next);
|
|
679
|
+
setStep((steps) => steps + 1);
|
|
680
|
+
};
|
|
681
|
+
const stepBy = (by: 1 | -1) => go(stepHit(at, by, count));
|
|
682
|
+
const close = () => {
|
|
683
|
+
setOpen(false);
|
|
684
|
+
setStatus(undefined);
|
|
685
|
+
};
|
|
686
|
+
const replace = () => {
|
|
687
|
+
if (busy || reading || count === 0) {
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
const seen = seenTexts(frames, texts, query);
|
|
691
|
+
// The studio takes a request up to a megabyte: past that, too many.
|
|
692
|
+
const bytes = new TextEncoder().encode(JSON.stringify(seen)).length;
|
|
693
|
+
if (bytes > MOST_SEEN_BYTES) {
|
|
694
|
+
setStatus({
|
|
695
|
+
kind: "message",
|
|
696
|
+
text: t`Too many places to replace at once: find something narrower.`,
|
|
697
|
+
});
|
|
698
|
+
} else {
|
|
699
|
+
replaceAll(query, replacement, seen);
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
if (!open) {
|
|
704
|
+
return null;
|
|
705
|
+
}
|
|
706
|
+
const counted = found.more ? `${MOST_HITS}+` : String(count);
|
|
707
|
+
let countLabel = "";
|
|
708
|
+
if (count > 0) {
|
|
709
|
+
countLabel = t`${at + 1} of ${counted}`;
|
|
710
|
+
} else if (query.trim()) {
|
|
711
|
+
countLabel = reading ? t`Finding…` : t`No results`;
|
|
712
|
+
}
|
|
713
|
+
return (
|
|
714
|
+
<div
|
|
715
|
+
className="absolute top-3 left-1/2 z-40 w-[min(26rem,calc(100cqw-2rem))] -translate-x-1/2"
|
|
716
|
+
data-find-bar=""
|
|
717
|
+
>
|
|
718
|
+
<search
|
|
719
|
+
aria-label={t`Find on the frames`}
|
|
720
|
+
className="studio-float flex flex-col overflow-hidden rounded-[17px] p-[3px] text-popover-foreground"
|
|
721
|
+
>
|
|
722
|
+
<TipGroup side="bottom">
|
|
723
|
+
<div className="flex h-7 items-center gap-[3px]">
|
|
724
|
+
{writable ? (
|
|
725
|
+
<Tip label={replacing ? t`Hide replace` : t`Replace`}>
|
|
726
|
+
<Button
|
|
727
|
+
aria-expanded={replacing}
|
|
728
|
+
aria-label={t`Replace`}
|
|
729
|
+
className="size-7 rounded-full"
|
|
730
|
+
onClick={() => setReplacing((on) => !on)}
|
|
731
|
+
size="icon-sm"
|
|
732
|
+
variant="ghost"
|
|
733
|
+
>
|
|
734
|
+
<Icon
|
|
735
|
+
className={cn(
|
|
736
|
+
"transition-transform duration-150 motion-reduce:transition-none",
|
|
737
|
+
replacing && "rotate-90"
|
|
738
|
+
)}
|
|
739
|
+
name="ChevronRight"
|
|
740
|
+
/>
|
|
741
|
+
</Button>
|
|
742
|
+
</Tip>
|
|
743
|
+
) : (
|
|
744
|
+
<Icon
|
|
745
|
+
className="mx-2 shrink-0 text-muted-foreground"
|
|
746
|
+
name="Search"
|
|
747
|
+
/>
|
|
748
|
+
)}
|
|
749
|
+
<input
|
|
750
|
+
aria-label={t`Find`}
|
|
751
|
+
className={FIELD}
|
|
752
|
+
onChange={(event) => {
|
|
753
|
+
setQuery(event.target.value);
|
|
754
|
+
go(0);
|
|
755
|
+
}}
|
|
756
|
+
onKeyDown={fieldKeys(close, (shift) => stepBy(shift ? -1 : 1))}
|
|
757
|
+
placeholder={t`Find on the frames`}
|
|
758
|
+
ref={findField}
|
|
759
|
+
spellCheck={false}
|
|
760
|
+
value={query}
|
|
761
|
+
/>
|
|
762
|
+
<span
|
|
763
|
+
aria-live="polite"
|
|
764
|
+
className="studio-small shrink-0 px-1 text-muted-foreground tabular-nums"
|
|
765
|
+
>
|
|
766
|
+
{countLabel}
|
|
767
|
+
</span>
|
|
768
|
+
<BarButton
|
|
769
|
+
disabled={count === 0}
|
|
770
|
+
icon="ArrowUp"
|
|
771
|
+
label={t`Previous`}
|
|
772
|
+
onClick={() => stepBy(-1)}
|
|
773
|
+
shortcut="⇧↵"
|
|
774
|
+
/>
|
|
775
|
+
<BarButton
|
|
776
|
+
disabled={count === 0}
|
|
777
|
+
icon="ArrowDown"
|
|
778
|
+
label={t`Next`}
|
|
779
|
+
onClick={() => stepBy(1)}
|
|
780
|
+
shortcut="↵"
|
|
781
|
+
/>
|
|
782
|
+
<BarButton
|
|
783
|
+
icon="X"
|
|
784
|
+
label={t`Close`}
|
|
785
|
+
onClick={close}
|
|
786
|
+
shortcut="Esc"
|
|
787
|
+
/>
|
|
788
|
+
</div>
|
|
789
|
+
{writable && replacing ? (
|
|
790
|
+
<div className="flex h-7 items-center gap-[3px] pl-[31px]">
|
|
791
|
+
<input
|
|
792
|
+
aria-label={t`Replace with`}
|
|
793
|
+
className={FIELD}
|
|
794
|
+
onChange={(event) => setReplacement(event.target.value)}
|
|
795
|
+
onKeyDown={fieldKeys(close, replace)}
|
|
796
|
+
placeholder={t`Replace with`}
|
|
797
|
+
spellCheck={false}
|
|
798
|
+
value={replacement}
|
|
799
|
+
/>
|
|
800
|
+
<BarButton
|
|
801
|
+
disabled={busy || reading || count === 0}
|
|
802
|
+
icon="ReplaceAll"
|
|
803
|
+
label={t`Replace all, in your files`}
|
|
804
|
+
onClick={replace}
|
|
805
|
+
shortcut="↵"
|
|
806
|
+
/>
|
|
807
|
+
</div>
|
|
808
|
+
) : null}
|
|
809
|
+
</TipGroup>
|
|
810
|
+
{status ? (
|
|
811
|
+
<StatusLine busy={busy} onUndo={undo} status={status} />
|
|
812
|
+
) : null}
|
|
813
|
+
<HitList at={at} hits={found.hits} length={query.length} onPick={go} />
|
|
814
|
+
</search>
|
|
815
|
+
</div>
|
|
816
|
+
);
|
|
817
|
+
};
|