@mgamadeus/ddd-design-studio 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +358 -2
- package/dist/canvas/index.d.ts +18 -0
- package/dist/canvas/index.js +3063 -0
- package/dist/canvas/index.js.map +1 -0
- package/dist/chunk-RFW6QPM3.js +143 -0
- package/dist/chunk-RFW6QPM3.js.map +1 -0
- package/dist/index.d.ts +803 -0
- package/dist/index.js +386 -0
- package/dist/index.js.map +1 -0
- package/package.json +86 -4
|
@@ -0,0 +1,3063 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
buildBoardDeepLink,
|
|
4
|
+
buildDesignReference,
|
|
5
|
+
buildThemeReference,
|
|
6
|
+
copyTextToClipboard,
|
|
7
|
+
cx,
|
|
8
|
+
splitThemeReference,
|
|
9
|
+
useDesignStudio,
|
|
10
|
+
useDesignStudioComponents,
|
|
11
|
+
useDesignStudioTexts
|
|
12
|
+
} from "../chunk-RFW6QPM3.js";
|
|
13
|
+
|
|
14
|
+
// src/canvas/DesignStudioCanvasScreen.tsx
|
|
15
|
+
import { normalizeDddError as normalizeDddError3 } from "@mgamadeus/ddd-web/api";
|
|
16
|
+
import {
|
|
17
|
+
ClipboardCopy as ClipboardCopy4,
|
|
18
|
+
ImageDown,
|
|
19
|
+
ListFilter,
|
|
20
|
+
LoaderCircle,
|
|
21
|
+
Maximize,
|
|
22
|
+
Maximize2 as Maximize22,
|
|
23
|
+
MessageSquare as MessageSquare2,
|
|
24
|
+
Minimize,
|
|
25
|
+
Moon,
|
|
26
|
+
PanelRightClose,
|
|
27
|
+
PanelRightOpen,
|
|
28
|
+
RefreshCw,
|
|
29
|
+
Sun
|
|
30
|
+
} from "lucide-react";
|
|
31
|
+
import { useCallback as useCallback2, useEffect as useEffect6, useMemo as useMemo2, useRef as useRef3, useState as useState8 } from "react";
|
|
32
|
+
|
|
33
|
+
// src/canvas/BoardComments.tsx
|
|
34
|
+
import { normalizeDddError } from "@mgamadeus/ddd-web/api";
|
|
35
|
+
import { Bot, CheckCircle2, ClipboardCopy, Flag, History, Hourglass, MapPin, RotateCcw, Trash2 } from "lucide-react";
|
|
36
|
+
import { useState } from "react";
|
|
37
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
38
|
+
var buildCommentThreads = (comments) => {
|
|
39
|
+
const repliesByRootId = /* @__PURE__ */ new Map();
|
|
40
|
+
for (const comment of comments) {
|
|
41
|
+
if (comment.parentDesignStudioCommentId != null) {
|
|
42
|
+
const replies = repliesByRootId.get(comment.parentDesignStudioCommentId) ?? [];
|
|
43
|
+
replies.push(comment);
|
|
44
|
+
repliesByRootId.set(comment.parentDesignStudioCommentId, replies);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
let pinNumber = 0;
|
|
48
|
+
return comments.filter((comment) => comment.parentDesignStudioCommentId == null).map((root) => ({
|
|
49
|
+
root,
|
|
50
|
+
replies: repliesByRootId.get(Number(root.id)) ?? [],
|
|
51
|
+
pinNumber: root.x != null && root.y != null ? ++pinNumber : null
|
|
52
|
+
}));
|
|
53
|
+
};
|
|
54
|
+
var errorMessage = (error) => normalizeDddError(error, "Request failed").message;
|
|
55
|
+
var CommentLine = ({ comment, isOwn, writesAllowed }) => {
|
|
56
|
+
const { api, components, formatDateTime, notify } = useDesignStudio();
|
|
57
|
+
const { Button } = components;
|
|
58
|
+
const [deleteComment, { isLoading: isDeleting }] = api.useDeleteCommentMutation();
|
|
59
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
|
|
60
|
+
/* @__PURE__ */ jsxs("p", { className: "flex items-center gap-1.5 text-xs text-muted-foreground", children: [
|
|
61
|
+
comment.authorKind === "AGENT" && /* @__PURE__ */ jsx(Bot, { className: "size-3.5 text-brand-emphasis", "aria-label": "Agent" }),
|
|
62
|
+
/* @__PURE__ */ jsx("span", { className: "font-semibold text-foreground", children: comment.authorName ?? "Unknown" }),
|
|
63
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
64
|
+
"\xB7 ",
|
|
65
|
+
formatDateTime(comment.changeHistory?.createdTime)
|
|
66
|
+
] }),
|
|
67
|
+
isOwn && /* @__PURE__ */ jsx(
|
|
68
|
+
Button,
|
|
69
|
+
{
|
|
70
|
+
variant: "ghost",
|
|
71
|
+
size: "icon-sm",
|
|
72
|
+
className: "ml-auto size-6",
|
|
73
|
+
"aria-label": "Delete comment",
|
|
74
|
+
disabled: !writesAllowed || isDeleting,
|
|
75
|
+
onClick: () => deleteComment({ designStudioCommentId: Number(comment.id) }).unwrap().catch((error) => notify.error(errorMessage(error))),
|
|
76
|
+
children: /* @__PURE__ */ jsx(Trash2, { className: "size-3.5" })
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
] }),
|
|
80
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm whitespace-pre-wrap break-words", children: comment.text })
|
|
81
|
+
] });
|
|
82
|
+
};
|
|
83
|
+
var ThreadCard = ({
|
|
84
|
+
thread,
|
|
85
|
+
onCopyReference,
|
|
86
|
+
isHighlighted,
|
|
87
|
+
onHighlight,
|
|
88
|
+
authAccountId,
|
|
89
|
+
writesAllowed,
|
|
90
|
+
hasBoardChangedSince,
|
|
91
|
+
isExpiring
|
|
92
|
+
}) => {
|
|
93
|
+
const { root, replies, pinNumber } = thread;
|
|
94
|
+
const [replyText, setReplyText] = useState("");
|
|
95
|
+
const { api, components, notify } = useDesignStudio();
|
|
96
|
+
const { Badge, Button, Textarea } = components;
|
|
97
|
+
const [createReply, { isLoading: isReplying }] = api.useReplyToCommentMutation();
|
|
98
|
+
const [resolveThread, { isLoading: isResolving }] = api.useResolveCommentMutation();
|
|
99
|
+
const [reopenThread, { isLoading: isReopening }] = api.useReopenCommentMutation();
|
|
100
|
+
const [patchComment, { isLoading: isPatching }] = api.usePatchCommentMutation();
|
|
101
|
+
const [keepThread, { isLoading: isKeeping }] = api.useKeepCommentMutation();
|
|
102
|
+
const designStudioCommentId = Number(root.id);
|
|
103
|
+
const sendReply = async () => {
|
|
104
|
+
try {
|
|
105
|
+
await createReply({
|
|
106
|
+
designStudioCommentId,
|
|
107
|
+
body: { text: replyText }
|
|
108
|
+
}).unwrap();
|
|
109
|
+
setReplyText("");
|
|
110
|
+
} catch (error) {
|
|
111
|
+
notify.error(errorMessage(error));
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
return (
|
|
115
|
+
// biome-ignore lint/a11y/useSemanticElements: an article that highlights its pin on hover / focus, not a control
|
|
116
|
+
/* @__PURE__ */ jsxs(
|
|
117
|
+
"article",
|
|
118
|
+
{
|
|
119
|
+
className: cx(
|
|
120
|
+
"space-y-3 rounded-2xl bg-card p-4 shadow-surface-raised ring-1 ring-foreground/5",
|
|
121
|
+
root.isResolved && "opacity-70",
|
|
122
|
+
isHighlighted && "ring-2 ring-brand"
|
|
123
|
+
),
|
|
124
|
+
onMouseEnter: onHighlight,
|
|
125
|
+
onFocus: onHighlight,
|
|
126
|
+
role: "group",
|
|
127
|
+
"aria-label": `Comment thread${pinNumber ? ` ${pinNumber}` : ""}`,
|
|
128
|
+
children: [
|
|
129
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-1.5", children: [
|
|
130
|
+
pinNumber !== null ? /* @__PURE__ */ jsxs(Badge, { className: "bg-primary text-primary-foreground", children: [
|
|
131
|
+
/* @__PURE__ */ jsx(MapPin, { "aria-hidden": true }),
|
|
132
|
+
" ",
|
|
133
|
+
pinNumber
|
|
134
|
+
] }) : /* @__PURE__ */ jsx(Badge, { variant: "outline", children: "Board" }),
|
|
135
|
+
root.isDecision && /* @__PURE__ */ jsxs(Badge, { variant: "outline", className: "border-transparent bg-success/15 text-success", children: [
|
|
136
|
+
/* @__PURE__ */ jsx(Flag, { "aria-hidden": true }),
|
|
137
|
+
" Decision"
|
|
138
|
+
] }),
|
|
139
|
+
root.isResolved && /* @__PURE__ */ jsxs(Badge, { variant: "outline", className: "border-transparent bg-tint text-muted-foreground", children: [
|
|
140
|
+
"Resolved",
|
|
141
|
+
root.resolvedByName ? ` by ${root.resolvedByName}` : ""
|
|
142
|
+
] }),
|
|
143
|
+
hasBoardChangedSince && /* @__PURE__ */ jsxs(
|
|
144
|
+
Badge,
|
|
145
|
+
{
|
|
146
|
+
variant: "outline",
|
|
147
|
+
className: "border-transparent bg-warning/15 text-warning",
|
|
148
|
+
title: "The board file is another version than the one this thread was written on",
|
|
149
|
+
children: [
|
|
150
|
+
/* @__PURE__ */ jsx(History, { "aria-hidden": true }),
|
|
151
|
+
" Board changed since"
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
),
|
|
155
|
+
isExpiring && /* @__PURE__ */ jsxs(
|
|
156
|
+
Badge,
|
|
157
|
+
{
|
|
158
|
+
variant: "outline",
|
|
159
|
+
className: "border-transparent bg-tint text-muted-foreground",
|
|
160
|
+
title: "Idle threads are deleted; \u201CKeep\u201D or any reply postpones that",
|
|
161
|
+
children: [
|
|
162
|
+
/* @__PURE__ */ jsx(Hourglass, { "aria-hidden": true }),
|
|
163
|
+
" Expires soon"
|
|
164
|
+
]
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
] }),
|
|
168
|
+
/* @__PURE__ */ jsx(CommentLine, { comment: root, isOwn: authAccountId !== null && root.authorAccountId === authAccountId, writesAllowed }),
|
|
169
|
+
replies.map((reply) => /* @__PURE__ */ jsx("div", { className: "border-l-2 border-border pl-3", children: /* @__PURE__ */ jsx(
|
|
170
|
+
CommentLine,
|
|
171
|
+
{
|
|
172
|
+
comment: reply,
|
|
173
|
+
isOwn: authAccountId !== null && reply.authorAccountId === authAccountId,
|
|
174
|
+
writesAllowed
|
|
175
|
+
}
|
|
176
|
+
) }, String(reply.id))),
|
|
177
|
+
/* @__PURE__ */ jsx(
|
|
178
|
+
Textarea,
|
|
179
|
+
{
|
|
180
|
+
value: replyText,
|
|
181
|
+
onChange: (event) => setReplyText(event.target.value),
|
|
182
|
+
placeholder: "Reply\u2026",
|
|
183
|
+
rows: 2,
|
|
184
|
+
"aria-label": "Reply",
|
|
185
|
+
disabled: !writesAllowed
|
|
186
|
+
}
|
|
187
|
+
),
|
|
188
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
189
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "outline", disabled: !writesAllowed || !replyText.trim() || isReplying, onClick: sendReply, children: "Reply" }),
|
|
190
|
+
/* @__PURE__ */ jsxs(
|
|
191
|
+
Button,
|
|
192
|
+
{
|
|
193
|
+
size: "sm",
|
|
194
|
+
variant: "outline",
|
|
195
|
+
disabled: !writesAllowed || isPatching,
|
|
196
|
+
"aria-pressed": Boolean(root.isDecision),
|
|
197
|
+
onClick: () => patchComment({
|
|
198
|
+
designStudioCommentId,
|
|
199
|
+
body: { isDecision: !root.isDecision }
|
|
200
|
+
}).unwrap().catch((error) => notify.error(errorMessage(error))),
|
|
201
|
+
children: [
|
|
202
|
+
/* @__PURE__ */ jsx(Flag, {}),
|
|
203
|
+
" ",
|
|
204
|
+
root.isDecision ? "Not a decision" : "Decision"
|
|
205
|
+
]
|
|
206
|
+
}
|
|
207
|
+
),
|
|
208
|
+
/* @__PURE__ */ jsxs(Button, { size: "sm", variant: "outline", onClick: () => onCopyReference(thread), "aria-label": "Copy for agent", children: [
|
|
209
|
+
/* @__PURE__ */ jsx(ClipboardCopy, {}),
|
|
210
|
+
" Copy for agent"
|
|
211
|
+
] }),
|
|
212
|
+
isExpiring && /* @__PURE__ */ jsx(
|
|
213
|
+
Button,
|
|
214
|
+
{
|
|
215
|
+
size: "sm",
|
|
216
|
+
variant: "outline",
|
|
217
|
+
disabled: !writesAllowed || isKeeping,
|
|
218
|
+
onClick: () => keepThread({ designStudioCommentId }).unwrap().catch((error) => notify.error(errorMessage(error))),
|
|
219
|
+
children: "Keep"
|
|
220
|
+
}
|
|
221
|
+
),
|
|
222
|
+
root.isResolved ? /* @__PURE__ */ jsxs(
|
|
223
|
+
Button,
|
|
224
|
+
{
|
|
225
|
+
size: "sm",
|
|
226
|
+
variant: "outline",
|
|
227
|
+
className: "ml-auto",
|
|
228
|
+
disabled: !writesAllowed || isReopening,
|
|
229
|
+
onClick: () => reopenThread({ designStudioCommentId }).unwrap().catch((error) => notify.error(errorMessage(error))),
|
|
230
|
+
children: [
|
|
231
|
+
/* @__PURE__ */ jsx(RotateCcw, {}),
|
|
232
|
+
" Reopen"
|
|
233
|
+
]
|
|
234
|
+
}
|
|
235
|
+
) : /* @__PURE__ */ jsxs(
|
|
236
|
+
Button,
|
|
237
|
+
{
|
|
238
|
+
size: "sm",
|
|
239
|
+
variant: "outline",
|
|
240
|
+
className: "ml-auto",
|
|
241
|
+
disabled: !writesAllowed || isResolving,
|
|
242
|
+
onClick: async () => {
|
|
243
|
+
try {
|
|
244
|
+
await resolveThread({
|
|
245
|
+
designStudioCommentId,
|
|
246
|
+
body: { replyText: replyText.trim() ? replyText : null }
|
|
247
|
+
}).unwrap();
|
|
248
|
+
setReplyText("");
|
|
249
|
+
} catch (error) {
|
|
250
|
+
notify.error(errorMessage(error));
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
children: [
|
|
254
|
+
/* @__PURE__ */ jsx(CheckCircle2, {}),
|
|
255
|
+
" Resolve"
|
|
256
|
+
]
|
|
257
|
+
}
|
|
258
|
+
)
|
|
259
|
+
] })
|
|
260
|
+
]
|
|
261
|
+
}
|
|
262
|
+
)
|
|
263
|
+
);
|
|
264
|
+
};
|
|
265
|
+
var BoardComments = ({
|
|
266
|
+
projectKey,
|
|
267
|
+
canvasKey,
|
|
268
|
+
board,
|
|
269
|
+
threads,
|
|
270
|
+
pendingPin,
|
|
271
|
+
onClearPendingPin,
|
|
272
|
+
highlightedCommentId,
|
|
273
|
+
onHighlightComment,
|
|
274
|
+
writesAllowed,
|
|
275
|
+
showResolved,
|
|
276
|
+
onShowResolvedChange,
|
|
277
|
+
pinHint,
|
|
278
|
+
onCopyThreadReference
|
|
279
|
+
}) => {
|
|
280
|
+
const [text, setText] = useState("");
|
|
281
|
+
const [isDecision, setIsDecision] = useState(false);
|
|
282
|
+
const { api, components, notify, useCurrentAccountId } = useDesignStudio();
|
|
283
|
+
const { Button, Checkbox, Label, Textarea } = components;
|
|
284
|
+
const [createComment, { isLoading }] = api.useCreateCommentMutation();
|
|
285
|
+
const authAccountId = useCurrentAccountId();
|
|
286
|
+
const { data: expiringData } = api.useExpiringCommentsQuery();
|
|
287
|
+
const expiringCommentIds = new Set(
|
|
288
|
+
(expiringData?.designStudioComments.elements ?? []).map((comment) => Number(comment.id))
|
|
289
|
+
);
|
|
290
|
+
const visibleThreads = showResolved ? threads : threads.filter((thread) => !thread.root.isResolved);
|
|
291
|
+
const resolvedCount = threads.length - threads.filter((thread) => !thread.root.isResolved).length;
|
|
292
|
+
const addComment = async () => {
|
|
293
|
+
try {
|
|
294
|
+
await createComment({
|
|
295
|
+
projectKey,
|
|
296
|
+
canvasKey,
|
|
297
|
+
boardKey: board.boardKey ?? "",
|
|
298
|
+
body: {
|
|
299
|
+
text,
|
|
300
|
+
x: pendingPin?.x ?? null,
|
|
301
|
+
y: pendingPin?.y ?? null,
|
|
302
|
+
isDecision
|
|
303
|
+
}
|
|
304
|
+
}).unwrap();
|
|
305
|
+
setText("");
|
|
306
|
+
setIsDecision(false);
|
|
307
|
+
onClearPendingPin();
|
|
308
|
+
} catch (error) {
|
|
309
|
+
notify.error(errorMessage(error));
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
313
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
314
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "design-comment-text", className: "flex items-center gap-1.5", children: pendingPin ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
315
|
+
/* @__PURE__ */ jsx(MapPin, { className: "size-4 text-brand-emphasis", "aria-hidden": true }),
|
|
316
|
+
" Comment at the placed pin"
|
|
317
|
+
] }) : "New comment on the board" }),
|
|
318
|
+
/* @__PURE__ */ jsx(
|
|
319
|
+
Textarea,
|
|
320
|
+
{
|
|
321
|
+
id: "design-comment-text",
|
|
322
|
+
value: text,
|
|
323
|
+
onChange: (event) => setText(event.target.value),
|
|
324
|
+
placeholder: pendingPin ? "What should change here?" : `Comment\u2026 (${pinHint})`,
|
|
325
|
+
rows: 3,
|
|
326
|
+
disabled: !writesAllowed
|
|
327
|
+
}
|
|
328
|
+
),
|
|
329
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
|
|
330
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
331
|
+
/* @__PURE__ */ jsx(
|
|
332
|
+
Checkbox,
|
|
333
|
+
{
|
|
334
|
+
id: "design-comment-decision",
|
|
335
|
+
checked: isDecision,
|
|
336
|
+
onCheckedChange: (checked) => setIsDecision(checked === true),
|
|
337
|
+
disabled: !writesAllowed
|
|
338
|
+
}
|
|
339
|
+
),
|
|
340
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "design-comment-decision", className: "font-normal", children: "Decision" })
|
|
341
|
+
] }),
|
|
342
|
+
pendingPin && /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", onClick: onClearPendingPin, children: "Remove pin" }),
|
|
343
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", className: "ml-auto", disabled: !writesAllowed || !text.trim() || isLoading || !board.boardKey, onClick: addComment, children: "Comment" })
|
|
344
|
+
] })
|
|
345
|
+
] }),
|
|
346
|
+
resolvedCount > 0 && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
347
|
+
/* @__PURE__ */ jsx(
|
|
348
|
+
Checkbox,
|
|
349
|
+
{
|
|
350
|
+
id: "design-comment-show-resolved",
|
|
351
|
+
checked: showResolved,
|
|
352
|
+
onCheckedChange: (checked) => onShowResolvedChange(checked === true)
|
|
353
|
+
}
|
|
354
|
+
),
|
|
355
|
+
/* @__PURE__ */ jsxs(Label, { htmlFor: "design-comment-show-resolved", className: "font-normal text-muted-foreground", children: [
|
|
356
|
+
"Show ",
|
|
357
|
+
resolvedCount,
|
|
358
|
+
" resolved"
|
|
359
|
+
] })
|
|
360
|
+
] }),
|
|
361
|
+
visibleThreads.length === 0 && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "No open comments on this board." }),
|
|
362
|
+
visibleThreads.map((thread) => /* @__PURE__ */ jsx(
|
|
363
|
+
ThreadCard,
|
|
364
|
+
{
|
|
365
|
+
thread,
|
|
366
|
+
onCopyReference: onCopyThreadReference,
|
|
367
|
+
isHighlighted: highlightedCommentId === Number(thread.root.id),
|
|
368
|
+
onHighlight: () => onHighlightComment(Number(thread.root.id)),
|
|
369
|
+
authAccountId,
|
|
370
|
+
writesAllowed,
|
|
371
|
+
hasBoardChangedSince: Boolean(thread.root.contentHash && board.contentHash) && thread.root.contentHash !== board.contentHash,
|
|
372
|
+
isExpiring: expiringCommentIds.has(Number(thread.root.id))
|
|
373
|
+
},
|
|
374
|
+
String(thread.root.id)
|
|
375
|
+
))
|
|
376
|
+
] });
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// src/canvas/BoardFocusView.tsx
|
|
380
|
+
import { ChevronLeft, ChevronRight, ClipboardCopy as ClipboardCopy3, MapPin as MapPin2, MapPinPlus, SquareDashedMousePointer, X } from "lucide-react";
|
|
381
|
+
import { useEffect as useEffect4, useState as useState6 } from "react";
|
|
382
|
+
|
|
383
|
+
// src/canvas/BoardNode.tsx
|
|
384
|
+
import { useStore } from "@xyflow/react";
|
|
385
|
+
import { ClipboardCopy as ClipboardCopy2, Download, Maximize2, MessageSquare } from "lucide-react";
|
|
386
|
+
import { memo, useEffect as useEffect3, useRef, useState as useState5 } from "react";
|
|
387
|
+
|
|
388
|
+
// src/canvas/boardStatus.ts
|
|
389
|
+
var boardStatusDefinition = (statuses, status) => statuses[status];
|
|
390
|
+
var boardStatusLabel = (statuses, status) => boardStatusDefinition(statuses, status)?.label ?? status;
|
|
391
|
+
|
|
392
|
+
// src/canvas/boardDetail.ts
|
|
393
|
+
var SMALL_THUMBNAIL_MAX_RENDERED_WIDTH = 130;
|
|
394
|
+
var LIVE_MIN_RENDERED_WIDTH_RATIO = 0.6;
|
|
395
|
+
var LIVE_MIN_RENDERED_WIDTH_RATIO_WITHOUT_THUMBNAILS = 0.35;
|
|
396
|
+
var MAX_LIVE_BOARDS = 6;
|
|
397
|
+
var thumbnailVariantForZoom = (zoom, boardWidth) => boardWidth * zoom <= SMALL_THUMBNAIL_MAX_RENDERED_WIDTH ? "small" : "default";
|
|
398
|
+
var isZoomLiveCapable = (zoom, minRatio = LIVE_MIN_RENDERED_WIDTH_RATIO) => zoom >= minRatio;
|
|
399
|
+
var selectLiveBoardIds = (boards, viewport, screen, maxLiveBoards = MAX_LIVE_BOARDS, minRatio = LIVE_MIN_RENDERED_WIDTH_RATIO) => {
|
|
400
|
+
if (!isZoomLiveCapable(viewport.zoom, minRatio) || screen.width <= 0 || screen.height <= 0) {
|
|
401
|
+
return /* @__PURE__ */ new Set();
|
|
402
|
+
}
|
|
403
|
+
const left = -viewport.x / viewport.zoom;
|
|
404
|
+
const top = -viewport.y / viewport.zoom;
|
|
405
|
+
const right = left + screen.width / viewport.zoom;
|
|
406
|
+
const bottom = top + screen.height / viewport.zoom;
|
|
407
|
+
const centreX = (left + right) / 2;
|
|
408
|
+
const centreY = (top + bottom) / 2;
|
|
409
|
+
const visible = [];
|
|
410
|
+
for (const board of boards) {
|
|
411
|
+
const isInside = board.x < right && board.x + board.width > left && board.y < bottom && board.y + board.height > top;
|
|
412
|
+
if (!isInside) continue;
|
|
413
|
+
const distance = Math.hypot(board.x + board.width / 2 - centreX, board.y + Math.min(board.height, 844) / 2 - centreY);
|
|
414
|
+
visible.push({ id: board.id, distance });
|
|
415
|
+
}
|
|
416
|
+
visible.sort((first, second) => first.distance - second.distance);
|
|
417
|
+
return new Set(visible.slice(0, maxLiveBoards).map((entry) => entry.id));
|
|
418
|
+
};
|
|
419
|
+
var selectVisibleBoardIds = (boards, viewport, screen) => {
|
|
420
|
+
if (screen.width <= 0 || screen.height <= 0 || viewport.zoom <= 0) return [];
|
|
421
|
+
const left = -viewport.x / viewport.zoom;
|
|
422
|
+
const top = -viewport.y / viewport.zoom;
|
|
423
|
+
const right = left + screen.width / viewport.zoom;
|
|
424
|
+
const bottom = top + screen.height / viewport.zoom;
|
|
425
|
+
const centreX = (left + right) / 2;
|
|
426
|
+
const centreY = (top + bottom) / 2;
|
|
427
|
+
return boards.filter((board) => board.x < right && board.x + board.width > left && board.y < bottom && board.y + board.height > top).map((board) => ({ id: board.id, distance: Math.hypot(board.x + board.width / 2 - centreX, board.y + board.height / 2 - centreY) })).sort((first, second) => first.distance - second.distance).map((entry) => entry.id);
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
// src/canvas/boardKey.ts
|
|
431
|
+
var boardCodeOf = (boardKey) => boardKey.replace(/(?:\.dc)?\.html$/, "");
|
|
432
|
+
|
|
433
|
+
// src/canvas/canvasLayout.ts
|
|
434
|
+
var MAX_COLUMNS = 14;
|
|
435
|
+
var BOARD_GAP_X = 44;
|
|
436
|
+
var BOARD_GAP_Y = 64;
|
|
437
|
+
var MAX_BOARD_CANVAS_HEIGHT = 1400;
|
|
438
|
+
var BOARD_HEADER_HEIGHT = 92;
|
|
439
|
+
var SECTION_TITLE_HEIGHT = 104;
|
|
440
|
+
var SECTION_PADDING = 48;
|
|
441
|
+
var SECTION_GAP = 140;
|
|
442
|
+
var TARGET_ASPECT_RATIO = 1.4;
|
|
443
|
+
var UNSECTIONED_ID = "unsectioned";
|
|
444
|
+
var ROW_COUNT_CANDIDATES = [1, 2, 3, 4, 5, 6, 7, 8, 10];
|
|
445
|
+
var MIN_COLUMNS = 4;
|
|
446
|
+
var columnsForSection = (boardCount, rows) => Math.max(
|
|
447
|
+
Math.min(boardCount, MIN_COLUMNS),
|
|
448
|
+
Math.min(boardCount, MAX_COLUMNS, Math.ceil(boardCount / Math.max(1, rows)))
|
|
449
|
+
);
|
|
450
|
+
var buildSectionGrid = (section, boards, rows) => {
|
|
451
|
+
const columns = columnsForSection(boards.length, rows);
|
|
452
|
+
const relativeRects = /* @__PURE__ */ new Map();
|
|
453
|
+
let rowTop = SECTION_PADDING + SECTION_TITLE_HEIGHT;
|
|
454
|
+
let right = 0;
|
|
455
|
+
for (let rowStart = 0; rowStart < boards.length; rowStart += columns) {
|
|
456
|
+
const row = boards.slice(rowStart, rowStart + columns);
|
|
457
|
+
let left = SECTION_PADDING;
|
|
458
|
+
let rowHeight = 0;
|
|
459
|
+
for (const board of row) {
|
|
460
|
+
const height = BOARD_HEADER_HEIGHT + Math.min(board.height, MAX_BOARD_CANVAS_HEIGHT);
|
|
461
|
+
relativeRects.set(board.id, { x: left, y: rowTop, width: board.width, height });
|
|
462
|
+
left += board.width + BOARD_GAP_X;
|
|
463
|
+
rowHeight = Math.max(rowHeight, height);
|
|
464
|
+
}
|
|
465
|
+
right = Math.max(right, left - BOARD_GAP_X);
|
|
466
|
+
rowTop += rowHeight + BOARD_GAP_Y;
|
|
467
|
+
}
|
|
468
|
+
return {
|
|
469
|
+
section,
|
|
470
|
+
boards,
|
|
471
|
+
relativeRects,
|
|
472
|
+
width: right + SECTION_PADDING,
|
|
473
|
+
height: rowTop - BOARD_GAP_Y + SECTION_PADDING
|
|
474
|
+
};
|
|
475
|
+
};
|
|
476
|
+
var packShelves = (grids, maxShelfWidth) => {
|
|
477
|
+
const positions = [];
|
|
478
|
+
let shelfTop = 0;
|
|
479
|
+
let shelfHeight = 0;
|
|
480
|
+
let x = 0;
|
|
481
|
+
let maxRight = 0;
|
|
482
|
+
for (const grid of grids) {
|
|
483
|
+
if (x > 0 && x + grid.width > maxShelfWidth) {
|
|
484
|
+
shelfTop += shelfHeight + SECTION_GAP;
|
|
485
|
+
shelfHeight = 0;
|
|
486
|
+
x = 0;
|
|
487
|
+
}
|
|
488
|
+
positions.push({ x, y: shelfTop, width: grid.width, height: grid.height });
|
|
489
|
+
maxRight = Math.max(maxRight, x + grid.width);
|
|
490
|
+
shelfHeight = Math.max(shelfHeight, grid.height);
|
|
491
|
+
x += grid.width + SECTION_GAP;
|
|
492
|
+
}
|
|
493
|
+
return { positions, bounds: { x: 0, y: 0, width: maxRight, height: shelfTop + shelfHeight } };
|
|
494
|
+
};
|
|
495
|
+
var computeCanvasLayout = (sections, boards, targetAspectRatio = TARGET_ASPECT_RATIO) => {
|
|
496
|
+
const boardsBySectionId = /* @__PURE__ */ new Map();
|
|
497
|
+
for (const board of boards) {
|
|
498
|
+
const sectionId = board.sectionId ?? UNSECTIONED_ID;
|
|
499
|
+
const sectionBoards = boardsBySectionId.get(sectionId) ?? [];
|
|
500
|
+
sectionBoards.push(board);
|
|
501
|
+
boardsBySectionId.set(sectionId, sectionBoards);
|
|
502
|
+
}
|
|
503
|
+
const orderedSections = [...sections].sort(
|
|
504
|
+
(first, second) => first.displayOrder - second.displayOrder
|
|
505
|
+
);
|
|
506
|
+
if (boardsBySectionId.has(UNSECTIONED_ID)) {
|
|
507
|
+
orderedSections.push({ id: UNSECTIONED_ID, title: "Weitere Boards", displayOrder: Number.MAX_SAFE_INTEGER });
|
|
508
|
+
}
|
|
509
|
+
const sectionsWithBoards = orderedSections.map((section) => ({
|
|
510
|
+
section,
|
|
511
|
+
boards: [...boardsBySectionId.get(section.id) ?? []].sort(
|
|
512
|
+
(first, second) => first.displayOrder - second.displayOrder
|
|
513
|
+
)
|
|
514
|
+
})).filter((entry) => entry.boards.length > 0);
|
|
515
|
+
if (sectionsWithBoards.length === 0) {
|
|
516
|
+
return { sections: [], boards: /* @__PURE__ */ new Map(), bounds: { x: 0, y: 0, width: 0, height: 0 } };
|
|
517
|
+
}
|
|
518
|
+
let bestGrids = [];
|
|
519
|
+
let best = { positions: [], bounds: { x: 0, y: 0, width: 1, height: 1 } };
|
|
520
|
+
let bestFitScale = 0;
|
|
521
|
+
for (const rows of ROW_COUNT_CANDIDATES) {
|
|
522
|
+
const grids2 = sectionsWithBoards.map((entry) => buildSectionGrid(entry.section, entry.boards, rows));
|
|
523
|
+
const widestSection = Math.max(...grids2.map((grid) => grid.width));
|
|
524
|
+
const totalWidth = grids2.reduce((sum, grid) => sum + grid.width + SECTION_GAP, -SECTION_GAP);
|
|
525
|
+
for (let step = 0; step <= 32; step++) {
|
|
526
|
+
const packed = packShelves(grids2, widestSection + (totalWidth - widestSection) * step / 32);
|
|
527
|
+
const fitScale = Math.min(targetAspectRatio / packed.bounds.width, 1 / packed.bounds.height);
|
|
528
|
+
if (fitScale > bestFitScale) {
|
|
529
|
+
bestFitScale = fitScale;
|
|
530
|
+
best = packed;
|
|
531
|
+
bestGrids = grids2;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
const grids = bestGrids;
|
|
536
|
+
const layoutSections = [];
|
|
537
|
+
const boardRects = /* @__PURE__ */ new Map();
|
|
538
|
+
grids.forEach((grid, index) => {
|
|
539
|
+
const position = best.positions[index];
|
|
540
|
+
for (const [boardId, rect] of grid.relativeRects) {
|
|
541
|
+
boardRects.set(boardId, { ...rect, x: position.x + rect.x, y: position.y + rect.y });
|
|
542
|
+
}
|
|
543
|
+
layoutSections.push({
|
|
544
|
+
id: grid.section.id,
|
|
545
|
+
title: grid.section.title,
|
|
546
|
+
...position,
|
|
547
|
+
boardCount: grid.boards.length,
|
|
548
|
+
boardIds: grid.boards.map((board) => board.id)
|
|
549
|
+
});
|
|
550
|
+
});
|
|
551
|
+
return { sections: layoutSections, boards: boardRects, bounds: best.bounds };
|
|
552
|
+
};
|
|
553
|
+
var findSectionAt = (sections, x, y) => {
|
|
554
|
+
let nearest;
|
|
555
|
+
let nearestDistance = Number.POSITIVE_INFINITY;
|
|
556
|
+
for (const section of sections) {
|
|
557
|
+
if (x >= section.x && x <= section.x + section.width && y >= section.y && y <= section.y + section.height) {
|
|
558
|
+
return section;
|
|
559
|
+
}
|
|
560
|
+
const distance = Math.hypot(x - section.x - section.width / 2, y - section.y - section.height / 2);
|
|
561
|
+
if (distance < nearestDistance) {
|
|
562
|
+
nearest = section;
|
|
563
|
+
nearestDistance = distance;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return nearest;
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
// src/canvas/canvasLiveUpdate.ts
|
|
570
|
+
var VIEWPORT_MIN_ZOOM = 1e-3;
|
|
571
|
+
var VIEWPORT_MAX_ZOOM = 10;
|
|
572
|
+
var formatViewportParam = ({ x, y, zoom }) => `${Math.round(x)},${Math.round(y)},${Number(zoom.toFixed(4))}`;
|
|
573
|
+
var parseViewportParam = (value) => {
|
|
574
|
+
if (!value) return null;
|
|
575
|
+
const parts = value.split(",");
|
|
576
|
+
if (parts.length !== 3 || parts.some((part) => part.trim() === "")) return null;
|
|
577
|
+
const [x, y, zoom] = parts.map(Number);
|
|
578
|
+
if (![x, y, zoom].every(Number.isFinite) || zoom < VIEWPORT_MIN_ZOOM || zoom > VIEWPORT_MAX_ZOOM) return null;
|
|
579
|
+
return { x, y, zoom };
|
|
580
|
+
};
|
|
581
|
+
var withoutContentToken = (url) => {
|
|
582
|
+
if (!url) return "";
|
|
583
|
+
const [path, query = ""] = url.split("?");
|
|
584
|
+
const params = new URLSearchParams(query);
|
|
585
|
+
params.delete("token");
|
|
586
|
+
const rest = params.toString();
|
|
587
|
+
return rest ? `${path}?${rest}` : path;
|
|
588
|
+
};
|
|
589
|
+
var shortContentHash = (contentHash) => (contentHash ?? "").slice(0, 7);
|
|
590
|
+
var pickDeliveryUrl = (previous, next, keepPreviousUrls) => keepPreviousUrls && previous && withoutContentToken(previous) === withoutContentToken(next) ? previous : next;
|
|
591
|
+
var isSameBoard = (previous, next) => {
|
|
592
|
+
const previousEntries = Object.entries(previous);
|
|
593
|
+
if (previousEntries.length !== Object.keys(next).length) return false;
|
|
594
|
+
const nextRecord = next;
|
|
595
|
+
return previousEntries.every(([key, value]) => key in nextRecord && Object.is(nextRecord[key], value));
|
|
596
|
+
};
|
|
597
|
+
var mergeRefetchedBoards = (previousBoards, nextBoards, keepPreviousUrls) => {
|
|
598
|
+
if (previousBoards === null) return { boards: [...nextBoards], changedBoardKeys: [], isChanged: true };
|
|
599
|
+
const previousByKey = new Map(previousBoards.map((board) => [String(board.boardKey), board]));
|
|
600
|
+
const changedBoardKeys = [];
|
|
601
|
+
const boards = nextBoards.map((next) => {
|
|
602
|
+
const previous = previousByKey.get(String(next.boardKey));
|
|
603
|
+
if (!previous || (previous.contentHash ?? null) !== (next.contentHash ?? null)) {
|
|
604
|
+
changedBoardKeys.push(String(next.boardKey));
|
|
605
|
+
return next;
|
|
606
|
+
}
|
|
607
|
+
const candidate = {
|
|
608
|
+
...next,
|
|
609
|
+
htmlUrl: pickDeliveryUrl(previous.htmlUrl, next.htmlUrl, keepPreviousUrls),
|
|
610
|
+
thumbnailUrl: pickDeliveryUrl(previous.thumbnailUrl, next.thumbnailUrl, keepPreviousUrls),
|
|
611
|
+
thumbnailSmallUrl: pickDeliveryUrl(previous.thumbnailSmallUrl, next.thumbnailSmallUrl, keepPreviousUrls)
|
|
612
|
+
};
|
|
613
|
+
return isSameBoard(previous, candidate) ? previous : candidate;
|
|
614
|
+
});
|
|
615
|
+
const isChanged = boards.length !== previousBoards.length || boards.some((board, index) => board !== previousBoards[index]);
|
|
616
|
+
return { boards: isChanged ? boards : previousBoards, changedBoardKeys, isChanged };
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
// src/canvas/canvasView.ts
|
|
620
|
+
import { createContext, useContext } from "react";
|
|
621
|
+
var CanvasViewContext = createContext(null);
|
|
622
|
+
var useCanvasView = () => {
|
|
623
|
+
const canvasView = useContext(CanvasViewContext);
|
|
624
|
+
if (!canvasView) {
|
|
625
|
+
throw new Error("useCanvasView needs a CanvasViewContext provider");
|
|
626
|
+
}
|
|
627
|
+
return canvasView;
|
|
628
|
+
};
|
|
629
|
+
var boardNodeId = (boardKey) => `board-${boardKey}`;
|
|
630
|
+
var sectionNodeId = (sectionKey) => `section-${sectionKey}`;
|
|
631
|
+
|
|
632
|
+
// src/canvas/useCheckedContentUrl.ts
|
|
633
|
+
import { useEffect, useState as useState2 } from "react";
|
|
634
|
+
var MAX_CONCURRENT_LOADS = 2;
|
|
635
|
+
var RETRY_DELAYS_MS = [2e3, 5e3, 15e3, 3e4];
|
|
636
|
+
var MAX_REMEMBERED_URLS = 24;
|
|
637
|
+
var loadedUrls = /* @__PURE__ */ new Set();
|
|
638
|
+
var rememberLoadedUrl = (url) => {
|
|
639
|
+
loadedUrls.delete(url);
|
|
640
|
+
loadedUrls.add(url);
|
|
641
|
+
while (loadedUrls.size > MAX_REMEMBERED_URLS) {
|
|
642
|
+
const oldestUrl = loadedUrls.values().next().value;
|
|
643
|
+
if (oldestUrl === void 0) break;
|
|
644
|
+
loadedUrls.delete(oldestUrl);
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
var wasContentUrlLoaded = (url) => Boolean(url && loadedUrls.has(url));
|
|
648
|
+
var activeLoads = 0;
|
|
649
|
+
var waitingLoads = [];
|
|
650
|
+
var acquireLoadSlot = () => new Promise((resolve) => {
|
|
651
|
+
if (activeLoads < MAX_CONCURRENT_LOADS) {
|
|
652
|
+
activeLoads += 1;
|
|
653
|
+
resolve();
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
waitingLoads.push(() => {
|
|
657
|
+
activeLoads += 1;
|
|
658
|
+
resolve();
|
|
659
|
+
});
|
|
660
|
+
});
|
|
661
|
+
var releaseLoadSlot = () => {
|
|
662
|
+
activeLoads -= 1;
|
|
663
|
+
waitingLoads.shift()?.();
|
|
664
|
+
};
|
|
665
|
+
var loadUrl = async (url, signal) => {
|
|
666
|
+
await acquireLoadSlot();
|
|
667
|
+
try {
|
|
668
|
+
if (signal.aborted) return false;
|
|
669
|
+
const response = await fetch(url, { signal, credentials: "omit", referrerPolicy: "no-referrer" });
|
|
670
|
+
if (!response.ok) return false;
|
|
671
|
+
await response.blob();
|
|
672
|
+
return true;
|
|
673
|
+
} catch {
|
|
674
|
+
return false;
|
|
675
|
+
} finally {
|
|
676
|
+
releaseLoadSlot();
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
var useCheckedContentUrl = (url) => {
|
|
680
|
+
const [checkedUrl, setCheckedUrl] = useState2(
|
|
681
|
+
() => url && loadedUrls.has(url) ? url : void 0
|
|
682
|
+
);
|
|
683
|
+
useEffect(() => {
|
|
684
|
+
if (!url) {
|
|
685
|
+
setCheckedUrl(void 0);
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (loadedUrls.has(url)) {
|
|
689
|
+
rememberLoadedUrl(url);
|
|
690
|
+
setCheckedUrl(url);
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
setCheckedUrl(void 0);
|
|
694
|
+
const abortController = new AbortController();
|
|
695
|
+
let retryTimer;
|
|
696
|
+
let attempt = 0;
|
|
697
|
+
const tryLoad = async () => {
|
|
698
|
+
const isLoaded = await loadUrl(url, abortController.signal);
|
|
699
|
+
if (abortController.signal.aborted) return;
|
|
700
|
+
if (isLoaded) {
|
|
701
|
+
rememberLoadedUrl(url);
|
|
702
|
+
setCheckedUrl(url);
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
const delay = RETRY_DELAYS_MS[Math.min(attempt, RETRY_DELAYS_MS.length - 1)];
|
|
706
|
+
attempt += 1;
|
|
707
|
+
retryTimer = setTimeout(tryLoad, delay);
|
|
708
|
+
};
|
|
709
|
+
void tryLoad();
|
|
710
|
+
return () => {
|
|
711
|
+
abortController.abort();
|
|
712
|
+
if (retryTimer) clearTimeout(retryTimer);
|
|
713
|
+
};
|
|
714
|
+
}, [url]);
|
|
715
|
+
return checkedUrl;
|
|
716
|
+
};
|
|
717
|
+
var useImageRetry = (url) => {
|
|
718
|
+
const [attempt, setAttempt] = useState2(0);
|
|
719
|
+
const [isFailed, setIsFailed] = useState2(false);
|
|
720
|
+
const [previousUrl, setPreviousUrl] = useState2(url);
|
|
721
|
+
if (url !== previousUrl) {
|
|
722
|
+
setPreviousUrl(url);
|
|
723
|
+
setAttempt(0);
|
|
724
|
+
setIsFailed(false);
|
|
725
|
+
}
|
|
726
|
+
useEffect(() => {
|
|
727
|
+
if (!isFailed) return;
|
|
728
|
+
const retryTimer = setTimeout(
|
|
729
|
+
() => {
|
|
730
|
+
setIsFailed(false);
|
|
731
|
+
setAttempt((previousAttempt) => previousAttempt + 1);
|
|
732
|
+
},
|
|
733
|
+
RETRY_DELAYS_MS[Math.min(attempt, RETRY_DELAYS_MS.length - 1)]
|
|
734
|
+
);
|
|
735
|
+
return () => clearTimeout(retryTimer);
|
|
736
|
+
}, [isFailed, attempt]);
|
|
737
|
+
return { imageKey: `${url ?? ""}#${attempt}`, isFailed, onError: () => setIsFailed(true) };
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
// src/canvas/useDeferredMount.ts
|
|
741
|
+
import { useEffect as useEffect2, useState as useState3 } from "react";
|
|
742
|
+
var MOUNTS_PER_FRAME = 12;
|
|
743
|
+
var queue = [];
|
|
744
|
+
var isScheduled = false;
|
|
745
|
+
var flush = () => {
|
|
746
|
+
isScheduled = false;
|
|
747
|
+
for (const mount of queue.splice(0, MOUNTS_PER_FRAME)) mount();
|
|
748
|
+
if (queue.length > 0) schedule();
|
|
749
|
+
};
|
|
750
|
+
var schedule = () => {
|
|
751
|
+
if (isScheduled) return;
|
|
752
|
+
isScheduled = true;
|
|
753
|
+
requestAnimationFrame(flush);
|
|
754
|
+
};
|
|
755
|
+
var useDeferredMount = () => {
|
|
756
|
+
const [isMounted, setIsMounted] = useState3(false);
|
|
757
|
+
useEffect2(() => {
|
|
758
|
+
let isActive = true;
|
|
759
|
+
const mount = () => {
|
|
760
|
+
if (isActive) setIsMounted(true);
|
|
761
|
+
};
|
|
762
|
+
queue.push(mount);
|
|
763
|
+
schedule();
|
|
764
|
+
return () => {
|
|
765
|
+
isActive = false;
|
|
766
|
+
const index = queue.indexOf(mount);
|
|
767
|
+
if (index >= 0) queue.splice(index, 1);
|
|
768
|
+
};
|
|
769
|
+
}, []);
|
|
770
|
+
return isMounted;
|
|
771
|
+
};
|
|
772
|
+
|
|
773
|
+
// src/canvas/stableContentUrl.ts
|
|
774
|
+
import { useState as useState4 } from "react";
|
|
775
|
+
var EXPIRY_MARGIN_SECONDS = 120;
|
|
776
|
+
var urlByContentKey = /* @__PURE__ */ new Map();
|
|
777
|
+
var expiryByToken = /* @__PURE__ */ new Map();
|
|
778
|
+
var contentTokenExpiry = (url) => {
|
|
779
|
+
const query = url.split("?")[1];
|
|
780
|
+
if (!query) return null;
|
|
781
|
+
const token = new URLSearchParams(query).get("token");
|
|
782
|
+
if (!token) return null;
|
|
783
|
+
const known = expiryByToken.get(token);
|
|
784
|
+
if (known !== void 0) return known;
|
|
785
|
+
let expiry = 0;
|
|
786
|
+
try {
|
|
787
|
+
const payload = token.split(".")[1] ?? "";
|
|
788
|
+
const json = JSON.parse(atob(payload.replace(/-/g, "+").replace(/_/g, "/")));
|
|
789
|
+
expiry = Number(json.expiresAt ?? json.exp ?? 0) || 0;
|
|
790
|
+
} catch {
|
|
791
|
+
expiry = 0;
|
|
792
|
+
}
|
|
793
|
+
expiryByToken.set(token, expiry);
|
|
794
|
+
return expiry;
|
|
795
|
+
};
|
|
796
|
+
var isContentUrlExpiring = (url, nowSeconds = Date.now() / 1e3) => {
|
|
797
|
+
const expiry = contentTokenExpiry(url);
|
|
798
|
+
return expiry !== null && expiry - EXPIRY_MARGIN_SECONDS <= nowSeconds;
|
|
799
|
+
};
|
|
800
|
+
var resolveStableContentUrl = (url) => {
|
|
801
|
+
const contentKey = withoutContentToken(url);
|
|
802
|
+
const kept = urlByContentKey.get(contentKey);
|
|
803
|
+
if (kept !== void 0 && (kept === url || !isContentUrlExpiring(kept))) return kept;
|
|
804
|
+
urlByContentKey.set(contentKey, url);
|
|
805
|
+
return url;
|
|
806
|
+
};
|
|
807
|
+
var useStableContentUrl = (url, isDisplayed = false) => {
|
|
808
|
+
const [shownUrl, setShownUrl] = useState4(() => url ? resolveStableContentUrl(url) : void 0);
|
|
809
|
+
if (!url) {
|
|
810
|
+
if (shownUrl !== void 0) setShownUrl(void 0);
|
|
811
|
+
return void 0;
|
|
812
|
+
}
|
|
813
|
+
if (shownUrl !== void 0 && withoutContentToken(shownUrl) === withoutContentToken(url) && (isDisplayed || !isContentUrlExpiring(shownUrl))) {
|
|
814
|
+
return shownUrl;
|
|
815
|
+
}
|
|
816
|
+
const nextUrl = resolveStableContentUrl(url);
|
|
817
|
+
if (nextUrl !== shownUrl) setShownUrl(nextUrl);
|
|
818
|
+
return nextUrl;
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
// src/canvas/BoardNode.tsx
|
|
822
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
823
|
+
var isSameContent = (first, second) => Boolean(first && second) && withoutContentToken(first) === withoutContentToken(second);
|
|
824
|
+
var designContentUrl = (apiBaseUrl, path) => path ? `${apiBaseUrl}${path}` : void 0;
|
|
825
|
+
var downloadName = (board, extension) => `${boardCodeOf(board.boardKey ?? "board")}.${extension}`;
|
|
826
|
+
var CLICK_MAX_MOVE = 5;
|
|
827
|
+
var HEADER_ICON_BUTTON_CLASS = "nodrag nopan flex size-8 shrink-0 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-tint-strong hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none motion-reduce:transition-none";
|
|
828
|
+
var BoardNodeComponent = ({ id, data }) => {
|
|
829
|
+
const { board } = data;
|
|
830
|
+
const { apiBaseUrl, components, statuses } = useDesignStudio();
|
|
831
|
+
const texts = useDesignStudioTexts();
|
|
832
|
+
const { StatusBadge } = components;
|
|
833
|
+
const statusDefinition = board.status ? boardStatusDefinition(statuses, board.status) : void 0;
|
|
834
|
+
const width = board.width ?? 390;
|
|
835
|
+
const height = board.height ?? 844;
|
|
836
|
+
const visibleHeight = Math.min(height, MAX_BOARD_CANVAS_HEIGHT);
|
|
837
|
+
const isCut = height > visibleHeight;
|
|
838
|
+
const thumbnailVariant = useStore((state) => thumbnailVariantForZoom(state.transform[2], width));
|
|
839
|
+
const {
|
|
840
|
+
liveBoardIds,
|
|
841
|
+
selectedBoardIds,
|
|
842
|
+
matchingBoardIds,
|
|
843
|
+
openThreadCounts,
|
|
844
|
+
defaultStatus,
|
|
845
|
+
onSelectBoard,
|
|
846
|
+
onCopyReference,
|
|
847
|
+
onOpenBoard
|
|
848
|
+
} = useCanvasView();
|
|
849
|
+
const isLive = liveBoardIds.has(id);
|
|
850
|
+
const isSelected = selectedBoardIds.has(id);
|
|
851
|
+
const isDimmed = matchingBoardIds !== null && !matchingBoardIds.has(id);
|
|
852
|
+
const openThreads = openThreadCounts.get(id) ?? 0;
|
|
853
|
+
const isReady = useDeferredMount();
|
|
854
|
+
const isThumbnailMissing = !board.thumbnailUrl;
|
|
855
|
+
const latestThumbnailUrl = designContentUrl(
|
|
856
|
+
apiBaseUrl,
|
|
857
|
+
thumbnailVariant === "small" ? board.thumbnailSmallUrl ?? board.thumbnailUrl : board.thumbnailUrl
|
|
858
|
+
);
|
|
859
|
+
const latestHtmlUrl = designContentUrl(apiBaseUrl, board.htmlUrl);
|
|
860
|
+
const [loadedImageUrl, setLoadedImageUrl] = useState5(null);
|
|
861
|
+
const [loadedFrameUrl, setLoadedFrameUrl] = useState5(null);
|
|
862
|
+
const thumbnailUrl = useStableContentUrl(latestThumbnailUrl, isSameContent(loadedImageUrl, latestThumbnailUrl));
|
|
863
|
+
const htmlUrl = useStableContentUrl(latestHtmlUrl, isSameContent(loadedFrameUrl, latestHtmlUrl));
|
|
864
|
+
const isRememberedLive = isThumbnailMissing && thumbnailVariant === "default" && isReady && wasContentUrlLoaded(htmlUrl);
|
|
865
|
+
const showsLiveHtml = isLive || isRememberedLive;
|
|
866
|
+
const liveHtmlUrl = useCheckedContentUrl(showsLiveHtml && isReady ? htmlUrl : void 0);
|
|
867
|
+
const thumbnailRetry = useImageRetry(thumbnailUrl);
|
|
868
|
+
useEffect3(() => {
|
|
869
|
+
if (!liveHtmlUrl) setLoadedFrameUrl(null);
|
|
870
|
+
}, [liveHtmlUrl]);
|
|
871
|
+
const title = board.title ?? board.boardKey ?? "";
|
|
872
|
+
const boardCode = boardCodeOf(board.boardKey ?? "");
|
|
873
|
+
const [isDownloadOpen, setIsDownloadOpen] = useState5(false);
|
|
874
|
+
const pressPointRef = useRef(null);
|
|
875
|
+
const isCompact = thumbnailVariant === "small";
|
|
876
|
+
if (!isReady) {
|
|
877
|
+
return /* @__PURE__ */ jsx2("div", { className: cx("h-full w-full", isDimmed && "opacity-15"), style: { paddingTop: BOARD_HEADER_HEIGHT }, children: /* @__PURE__ */ jsx2("div", { className: "rounded-[20px] bg-card/70", style: { width, height: visibleHeight } }) });
|
|
878
|
+
}
|
|
879
|
+
return /* @__PURE__ */ jsxs2("div", { className: cx("relative h-full w-full", isDimmed && "opacity-15"), children: [
|
|
880
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex flex-col justify-end gap-0.5 pb-1", style: { height: BOARD_HEADER_HEIGHT }, children: [
|
|
881
|
+
/* @__PURE__ */ jsx2("span", { className: "line-clamp-2 text-[19px] leading-6 font-medium text-muted-foreground", title, children: title }),
|
|
882
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-1", children: [
|
|
883
|
+
/* @__PURE__ */ jsx2("span", { className: "min-w-0 flex-1 truncate text-[15px] leading-5 font-semibold text-foreground/70 tabular-nums", title: boardCode, children: isCompact ? "" : boardCode }),
|
|
884
|
+
!isCompact && openThreads > 0 && /* @__PURE__ */ jsxs2("span", { className: "inline-flex shrink-0 items-center gap-1 rounded-full bg-primary px-2 py-0.5 text-sm font-semibold text-primary-foreground", children: [
|
|
885
|
+
/* @__PURE__ */ jsx2(MessageSquare, { className: "size-3.5", "aria-hidden": true }),
|
|
886
|
+
openThreads
|
|
887
|
+
] }),
|
|
888
|
+
!isCompact && board.status && board.status !== defaultStatus && /* @__PURE__ */ jsx2(
|
|
889
|
+
StatusBadge,
|
|
890
|
+
{
|
|
891
|
+
tone: statusDefinition?.tone ?? "neutral",
|
|
892
|
+
label: statusDefinition?.label ?? board.status,
|
|
893
|
+
icon: statusDefinition?.icon,
|
|
894
|
+
title: statusDefinition?.description,
|
|
895
|
+
className: "shrink-0"
|
|
896
|
+
}
|
|
897
|
+
),
|
|
898
|
+
!isCompact && /* @__PURE__ */ jsx2(
|
|
899
|
+
"button",
|
|
900
|
+
{
|
|
901
|
+
type: "button",
|
|
902
|
+
className: HEADER_ICON_BUTTON_CLASS,
|
|
903
|
+
"aria-label": `Copy reference of ${title} for an agent`,
|
|
904
|
+
title: "Copy reference (C)",
|
|
905
|
+
onClick: () => onCopyReference(id),
|
|
906
|
+
children: /* @__PURE__ */ jsx2(ClipboardCopy2, { className: "size-5" })
|
|
907
|
+
}
|
|
908
|
+
),
|
|
909
|
+
!isCompact && /* @__PURE__ */ jsx2(
|
|
910
|
+
"button",
|
|
911
|
+
{
|
|
912
|
+
type: "button",
|
|
913
|
+
className: HEADER_ICON_BUTTON_CLASS,
|
|
914
|
+
"aria-label": `Open ${title} large`,
|
|
915
|
+
title: "Expand",
|
|
916
|
+
onClick: () => onOpenBoard(id),
|
|
917
|
+
children: /* @__PURE__ */ jsx2(Maximize2, { className: "size-5" })
|
|
918
|
+
}
|
|
919
|
+
),
|
|
920
|
+
!isCompact && /* @__PURE__ */ jsxs2("div", { className: "relative", children: [
|
|
921
|
+
/* @__PURE__ */ jsx2(
|
|
922
|
+
"button",
|
|
923
|
+
{
|
|
924
|
+
type: "button",
|
|
925
|
+
className: HEADER_ICON_BUTTON_CLASS,
|
|
926
|
+
"aria-label": `Download ${title}`,
|
|
927
|
+
"aria-expanded": isDownloadOpen,
|
|
928
|
+
title: "Download",
|
|
929
|
+
onClick: () => setIsDownloadOpen((isOpen) => !isOpen),
|
|
930
|
+
children: /* @__PURE__ */ jsx2(Download, { className: "size-5" })
|
|
931
|
+
}
|
|
932
|
+
),
|
|
933
|
+
isDownloadOpen && // a plain menu instead of a Radix one: mounted only while open, nothing per node at rest
|
|
934
|
+
/* @__PURE__ */ jsxs2(
|
|
935
|
+
"div",
|
|
936
|
+
{
|
|
937
|
+
className: "nodrag nopan absolute top-full right-0 z-20 mt-1 flex w-56 flex-col rounded-2xl bg-popover p-1.5 text-[18px] shadow-surface-raised ring-1 ring-foreground/5",
|
|
938
|
+
children: [
|
|
939
|
+
board.thumbnailUrl && /* @__PURE__ */ jsx2(
|
|
940
|
+
"a",
|
|
941
|
+
{
|
|
942
|
+
href: designContentUrl(apiBaseUrl, board.thumbnailUrl),
|
|
943
|
+
download: downloadName(board, "png"),
|
|
944
|
+
className: "rounded-[10px] px-3 py-2 hover:bg-tint",
|
|
945
|
+
onClick: () => setIsDownloadOpen(false),
|
|
946
|
+
children: "PNG (thumbnail)"
|
|
947
|
+
}
|
|
948
|
+
),
|
|
949
|
+
board.htmlUrl && /* @__PURE__ */ jsx2(
|
|
950
|
+
"a",
|
|
951
|
+
{
|
|
952
|
+
href: htmlUrl,
|
|
953
|
+
download: downloadName(board, "html"),
|
|
954
|
+
className: "rounded-[10px] px-3 py-2 hover:bg-tint",
|
|
955
|
+
onClick: () => setIsDownloadOpen(false),
|
|
956
|
+
children: "HTML"
|
|
957
|
+
}
|
|
958
|
+
)
|
|
959
|
+
]
|
|
960
|
+
}
|
|
961
|
+
)
|
|
962
|
+
] })
|
|
963
|
+
] })
|
|
964
|
+
] }),
|
|
965
|
+
/* @__PURE__ */ jsxs2(
|
|
966
|
+
"div",
|
|
967
|
+
{
|
|
968
|
+
className: cx(
|
|
969
|
+
"relative overflow-hidden rounded-[20px] bg-card shadow-surface-raised ring-1 ring-foreground/10",
|
|
970
|
+
isSelected && "ring-4 ring-brand"
|
|
971
|
+
),
|
|
972
|
+
style: { width, height: visibleHeight },
|
|
973
|
+
children: [
|
|
974
|
+
thumbnailUrl && // biome-ignore lint/performance/noImgElement: canvas thumbnails are API images at canvas scale, next/image cannot optimise them
|
|
975
|
+
/* @__PURE__ */ jsx2(
|
|
976
|
+
"img",
|
|
977
|
+
{
|
|
978
|
+
src: thumbnailUrl,
|
|
979
|
+
alt: "",
|
|
980
|
+
width,
|
|
981
|
+
height,
|
|
982
|
+
loading: "lazy",
|
|
983
|
+
decoding: "async",
|
|
984
|
+
draggable: false,
|
|
985
|
+
onError: thumbnailRetry.onError,
|
|
986
|
+
onLoad: () => setLoadedImageUrl(thumbnailUrl),
|
|
987
|
+
className: cx(
|
|
988
|
+
"pointer-events-none absolute inset-0 h-full w-full object-cover object-top select-none",
|
|
989
|
+
thumbnailRetry.isFailed && "invisible"
|
|
990
|
+
)
|
|
991
|
+
},
|
|
992
|
+
thumbnailRetry.imageKey
|
|
993
|
+
),
|
|
994
|
+
isThumbnailMissing && !isCompact && !(showsLiveHtml && liveHtmlUrl) && /* @__PURE__ */ jsx2("span", { className: "pointer-events-none absolute inset-0 flex items-center justify-center px-6 text-center text-[17px] font-semibold text-muted-foreground", children: texts.thumbnailMissing }),
|
|
995
|
+
showsLiveHtml && liveHtmlUrl && /* @__PURE__ */ jsx2(
|
|
996
|
+
"iframe",
|
|
997
|
+
{
|
|
998
|
+
src: liveHtmlUrl,
|
|
999
|
+
onLoad: () => setLoadedFrameUrl(liveHtmlUrl),
|
|
1000
|
+
title: title || "Board",
|
|
1001
|
+
sandbox: "",
|
|
1002
|
+
referrerPolicy: "no-referrer",
|
|
1003
|
+
loading: "lazy",
|
|
1004
|
+
width,
|
|
1005
|
+
height,
|
|
1006
|
+
className: "pointer-events-none absolute inset-0 border-0 bg-transparent"
|
|
1007
|
+
}
|
|
1008
|
+
),
|
|
1009
|
+
isCut && /* @__PURE__ */ jsxs2("span", { className: "pointer-events-none absolute inset-x-0 bottom-0 flex h-40 items-end justify-center bg-gradient-to-t from-card to-transparent pb-4 text-[16px] font-semibold text-muted-foreground", children: [
|
|
1010
|
+
"\u2193 ",
|
|
1011
|
+
Math.round(height),
|
|
1012
|
+
" px \u2014 full length in the focus view"
|
|
1013
|
+
] }),
|
|
1014
|
+
/* @__PURE__ */ jsx2(
|
|
1015
|
+
"button",
|
|
1016
|
+
{
|
|
1017
|
+
type: "button",
|
|
1018
|
+
className: "absolute inset-0 z-10 cursor-pointer rounded-[20px] bg-transparent focus-visible:ring-4 focus-visible:ring-ring focus-visible:outline-none",
|
|
1019
|
+
onPointerDown: (event) => {
|
|
1020
|
+
pressPointRef.current = { x: event.clientX, y: event.clientY };
|
|
1021
|
+
},
|
|
1022
|
+
onClick: (event) => {
|
|
1023
|
+
const pressPoint = pressPointRef.current;
|
|
1024
|
+
if (pressPoint && Math.hypot(event.clientX - pressPoint.x, event.clientY - pressPoint.y) > CLICK_MAX_MOVE) return;
|
|
1025
|
+
onSelectBoard(id, event.shiftKey || event.metaKey || event.ctrlKey);
|
|
1026
|
+
},
|
|
1027
|
+
onDoubleClick: () => onOpenBoard(id),
|
|
1028
|
+
onKeyDown: (event) => {
|
|
1029
|
+
if (event.key === "Enter" && event.shiftKey) onOpenBoard(id);
|
|
1030
|
+
},
|
|
1031
|
+
"aria-label": `${title}: select (double-click or Shift+Enter opens it)`
|
|
1032
|
+
}
|
|
1033
|
+
)
|
|
1034
|
+
]
|
|
1035
|
+
}
|
|
1036
|
+
)
|
|
1037
|
+
] });
|
|
1038
|
+
};
|
|
1039
|
+
var BoardNode = memo(BoardNodeComponent);
|
|
1040
|
+
|
|
1041
|
+
// src/canvas/BoardStatusChips.tsx
|
|
1042
|
+
import { normalizeDddError as normalizeDddError2 } from "@mgamadeus/ddd-web/api";
|
|
1043
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1044
|
+
var BoardStatusChips = ({
|
|
1045
|
+
projectKey,
|
|
1046
|
+
canvasKey,
|
|
1047
|
+
board,
|
|
1048
|
+
statuses,
|
|
1049
|
+
writesAllowed,
|
|
1050
|
+
onStatusChanged
|
|
1051
|
+
}) => {
|
|
1052
|
+
const { api, notify, statuses: statusDefinitions } = useDesignStudio();
|
|
1053
|
+
const [patchStatus, { isLoading }] = api.useSetBoardStatusMutation();
|
|
1054
|
+
return /* @__PURE__ */ jsxs3("fieldset", { className: "m-0 flex flex-wrap items-center gap-1.5 border-0 p-0", "aria-label": "Board status", children: [
|
|
1055
|
+
statuses.map((status) => {
|
|
1056
|
+
const Icon = boardStatusDefinition(statusDefinitions, status)?.icon;
|
|
1057
|
+
const isActive = board.status === status;
|
|
1058
|
+
return /* @__PURE__ */ jsxs3(
|
|
1059
|
+
"button",
|
|
1060
|
+
{
|
|
1061
|
+
type: "button",
|
|
1062
|
+
"aria-pressed": isActive,
|
|
1063
|
+
disabled: !writesAllowed || isLoading || isActive || !board.boardKey,
|
|
1064
|
+
onClick: async () => {
|
|
1065
|
+
try {
|
|
1066
|
+
await patchStatus({
|
|
1067
|
+
projectKey,
|
|
1068
|
+
canvasKey,
|
|
1069
|
+
boardKey: board.boardKey ?? "",
|
|
1070
|
+
body: { status }
|
|
1071
|
+
}).unwrap();
|
|
1072
|
+
onStatusChanged(status);
|
|
1073
|
+
} catch (error) {
|
|
1074
|
+
notify.error(normalizeDddError2(error, "Request failed").message);
|
|
1075
|
+
}
|
|
1076
|
+
},
|
|
1077
|
+
className: cx(
|
|
1078
|
+
"inline-flex h-8 items-center gap-1.5 rounded-full px-3 text-xs font-semibold transition-colors motion-reduce:transition-none",
|
|
1079
|
+
"disabled:cursor-default",
|
|
1080
|
+
isActive ? "bg-primary text-primary-foreground" : "bg-tint text-muted-foreground hover:bg-tint-strong hover:text-foreground disabled:opacity-60"
|
|
1081
|
+
),
|
|
1082
|
+
children: [
|
|
1083
|
+
Icon && /* @__PURE__ */ jsx3(Icon, { className: "size-3.5", "aria-hidden": true }),
|
|
1084
|
+
boardStatusLabel(statusDefinitions, status)
|
|
1085
|
+
]
|
|
1086
|
+
},
|
|
1087
|
+
status
|
|
1088
|
+
);
|
|
1089
|
+
}),
|
|
1090
|
+
board.hasChangedSinceStatus && /* @__PURE__ */ jsx3("span", { className: "text-xs text-muted-foreground", title: "The board file changed after this status was set", children: "changed since" })
|
|
1091
|
+
] });
|
|
1092
|
+
};
|
|
1093
|
+
|
|
1094
|
+
// src/canvas/BoardFocusView.tsx
|
|
1095
|
+
import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1096
|
+
var DEVICE_SCREEN_HEIGHT = 844;
|
|
1097
|
+
var BoardFocusView = ({
|
|
1098
|
+
projectKey,
|
|
1099
|
+
canvasKey,
|
|
1100
|
+
board,
|
|
1101
|
+
statuses,
|
|
1102
|
+
sectionTitle,
|
|
1103
|
+
position,
|
|
1104
|
+
threads,
|
|
1105
|
+
writesAllowed,
|
|
1106
|
+
presentLabel,
|
|
1107
|
+
onClose,
|
|
1108
|
+
onPrevious,
|
|
1109
|
+
onNext,
|
|
1110
|
+
onStatusChanged,
|
|
1111
|
+
onCopyReference,
|
|
1112
|
+
onCopyThreadReference
|
|
1113
|
+
}) => {
|
|
1114
|
+
const { apiBaseUrl, components } = useDesignStudio();
|
|
1115
|
+
const texts = useDesignStudioTexts();
|
|
1116
|
+
const { Button, Dialog, DialogContent, DialogDescription, DialogTitle, Textarea } = components;
|
|
1117
|
+
const [isPlacingPin, setIsPlacingPin] = useState6(false);
|
|
1118
|
+
const [pendingPin, setPendingPin] = useState6(null);
|
|
1119
|
+
const [highlightedCommentId, setHighlightedCommentId] = useState6(null);
|
|
1120
|
+
const [showResolved, setShowResolved] = useState6(false);
|
|
1121
|
+
const [isMarkingRegion, setIsMarkingRegion] = useState6(false);
|
|
1122
|
+
const [region, setRegion] = useState6(null);
|
|
1123
|
+
const [regionDraft, setRegionDraft] = useState6(null);
|
|
1124
|
+
const [referenceNote, setReferenceNote] = useState6("");
|
|
1125
|
+
const [isRegionFlashing, setIsRegionFlashing] = useState6(false);
|
|
1126
|
+
const boardKey = board?.boardKey ?? null;
|
|
1127
|
+
useEffect4(() => {
|
|
1128
|
+
if (boardKey === null) return;
|
|
1129
|
+
setPendingPin(null);
|
|
1130
|
+
setIsPlacingPin(false);
|
|
1131
|
+
setHighlightedCommentId(null);
|
|
1132
|
+
setRegion(null);
|
|
1133
|
+
setRegionDraft(null);
|
|
1134
|
+
setIsMarkingRegion(false);
|
|
1135
|
+
setReferenceNote("");
|
|
1136
|
+
}, [boardKey]);
|
|
1137
|
+
useEffect4(() => {
|
|
1138
|
+
if (!board) return;
|
|
1139
|
+
const onKeyDown = (event) => {
|
|
1140
|
+
const target = event.target;
|
|
1141
|
+
if (target && (target.tagName === "TEXTAREA" || target.tagName === "INPUT" || target.isContentEditable)) return;
|
|
1142
|
+
if (event.key === "c" || event.key === "C") {
|
|
1143
|
+
if (event.metaKey || event.ctrlKey || event.altKey) return;
|
|
1144
|
+
event.preventDefault();
|
|
1145
|
+
copyReference();
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
if (event.key === "ArrowLeft") {
|
|
1149
|
+
event.preventDefault();
|
|
1150
|
+
onPrevious();
|
|
1151
|
+
} else if (event.key === "ArrowRight") {
|
|
1152
|
+
event.preventDefault();
|
|
1153
|
+
onNext();
|
|
1154
|
+
}
|
|
1155
|
+
};
|
|
1156
|
+
window.addEventListener("keydown", onKeyDown);
|
|
1157
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
1158
|
+
});
|
|
1159
|
+
const width = board?.width ?? 390;
|
|
1160
|
+
const height = board?.height ?? 844;
|
|
1161
|
+
const htmlUrl = useCheckedContentUrl(useStableContentUrl(designContentUrl(apiBaseUrl, board?.htmlUrl), true));
|
|
1162
|
+
const thumbnailUrl = useStableContentUrl(designContentUrl(apiBaseUrl, board?.thumbnailUrl), true);
|
|
1163
|
+
const pinnedThreads = threads.filter((thread) => thread.pinNumber !== null && (showResolved || !thread.root.isResolved));
|
|
1164
|
+
const copyReference = () => {
|
|
1165
|
+
onCopyReference({ region, note: referenceNote });
|
|
1166
|
+
if (region) {
|
|
1167
|
+
setIsRegionFlashing(true);
|
|
1168
|
+
window.setTimeout(() => setIsRegionFlashing(false), 1200);
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
const boardPointOf = (event) => {
|
|
1172
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
1173
|
+
return {
|
|
1174
|
+
x: Math.max(0, Math.min(width, event.clientX - rect.left)),
|
|
1175
|
+
y: Math.max(0, Math.min(height, event.clientY - rect.top))
|
|
1176
|
+
};
|
|
1177
|
+
};
|
|
1178
|
+
const startRegion = (event) => {
|
|
1179
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
1180
|
+
const point = boardPointOf(event);
|
|
1181
|
+
setRegionDraft({ startX: point.x, startY: point.y, x: point.x, y: point.y });
|
|
1182
|
+
};
|
|
1183
|
+
const moveRegion = (event) => {
|
|
1184
|
+
if (!regionDraft) return;
|
|
1185
|
+
const point = boardPointOf(event);
|
|
1186
|
+
setRegionDraft({ ...regionDraft, x: point.x, y: point.y });
|
|
1187
|
+
};
|
|
1188
|
+
const endRegion = () => {
|
|
1189
|
+
if (!regionDraft) return;
|
|
1190
|
+
const marked = {
|
|
1191
|
+
x: Math.min(regionDraft.startX, regionDraft.x),
|
|
1192
|
+
y: Math.min(regionDraft.startY, regionDraft.y),
|
|
1193
|
+
width: Math.abs(regionDraft.x - regionDraft.startX),
|
|
1194
|
+
height: Math.abs(regionDraft.y - regionDraft.startY)
|
|
1195
|
+
};
|
|
1196
|
+
setRegionDraft(null);
|
|
1197
|
+
if (marked.width >= 4 && marked.height >= 4) {
|
|
1198
|
+
setRegion(marked);
|
|
1199
|
+
setIsMarkingRegion(false);
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
const shownRegion = regionDraft ? {
|
|
1203
|
+
x: Math.min(regionDraft.startX, regionDraft.x),
|
|
1204
|
+
y: Math.min(regionDraft.startY, regionDraft.y),
|
|
1205
|
+
width: Math.abs(regionDraft.x - regionDraft.startX),
|
|
1206
|
+
height: Math.abs(regionDraft.y - regionDraft.startY)
|
|
1207
|
+
} : region;
|
|
1208
|
+
const placePin = (event) => {
|
|
1209
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
1210
|
+
setPendingPin({ x: Math.round(event.clientX - rect.left), y: Math.round(event.clientY - rect.top) });
|
|
1211
|
+
setIsPlacingPin(false);
|
|
1212
|
+
};
|
|
1213
|
+
return /* @__PURE__ */ jsx4(Dialog, { open: board !== null, onOpenChange: (open) => !open && onClose(), children: /* @__PURE__ */ jsx4(
|
|
1214
|
+
DialogContent,
|
|
1215
|
+
{
|
|
1216
|
+
showCloseButton: false,
|
|
1217
|
+
className: "flex h-[calc(100dvh-2rem)] w-[calc(100vw-2rem)] max-w-none flex-col gap-0 overflow-hidden rounded-3xl p-0 sm:max-w-none",
|
|
1218
|
+
children: board && /* @__PURE__ */ jsxs4(Fragment2, { children: [
|
|
1219
|
+
/* @__PURE__ */ jsxs4("header", { className: "flex flex-wrap items-center gap-3 border-b border-border px-5 py-3", children: [
|
|
1220
|
+
/* @__PURE__ */ jsxs4("div", { className: "min-w-0 flex-1", children: [
|
|
1221
|
+
/* @__PURE__ */ jsx4(DialogTitle, { className: "truncate text-lg font-semibold", children: board.title }),
|
|
1222
|
+
/* @__PURE__ */ jsxs4(DialogDescription, { className: "truncate text-xs", children: [
|
|
1223
|
+
presentLabel ? "Present \xB7 " : "",
|
|
1224
|
+
sectionTitle ? `${sectionTitle} \xB7 ` : "",
|
|
1225
|
+
board.boardKey,
|
|
1226
|
+
" \xB7 ",
|
|
1227
|
+
shortContentHash(board.contentHash),
|
|
1228
|
+
" \xB7 ",
|
|
1229
|
+
position.index,
|
|
1230
|
+
" / ",
|
|
1231
|
+
position.count
|
|
1232
|
+
] })
|
|
1233
|
+
] }),
|
|
1234
|
+
/* @__PURE__ */ jsx4(
|
|
1235
|
+
BoardStatusChips,
|
|
1236
|
+
{
|
|
1237
|
+
projectKey,
|
|
1238
|
+
canvasKey,
|
|
1239
|
+
board,
|
|
1240
|
+
statuses,
|
|
1241
|
+
writesAllowed,
|
|
1242
|
+
onStatusChanged
|
|
1243
|
+
}
|
|
1244
|
+
),
|
|
1245
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-1", children: [
|
|
1246
|
+
/* @__PURE__ */ jsx4(Button, { variant: "outline", size: "icon", "aria-label": "Previous board (\u2190)", onClick: onPrevious, children: /* @__PURE__ */ jsx4(ChevronLeft, {}) }),
|
|
1247
|
+
/* @__PURE__ */ jsx4(Button, { variant: "outline", size: "icon", "aria-label": "Next board (\u2192)", onClick: onNext, children: /* @__PURE__ */ jsx4(ChevronRight, {}) }),
|
|
1248
|
+
/* @__PURE__ */ jsx4(Button, { variant: "ghost", size: "icon", "aria-label": "Close focus view", onClick: onClose, children: /* @__PURE__ */ jsx4(X, {}) })
|
|
1249
|
+
] })
|
|
1250
|
+
] }),
|
|
1251
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex min-h-0 flex-1 flex-col lg:flex-row", children: [
|
|
1252
|
+
/* @__PURE__ */ jsx4("div", { className: "flex min-h-0 flex-1 items-start justify-center overflow-auto bg-tint p-6", children: /* @__PURE__ */ jsx4("div", { className: "rounded-[56px] bg-foreground p-3 shadow-surface-raised", children: /* @__PURE__ */ jsx4(
|
|
1253
|
+
"div",
|
|
1254
|
+
{
|
|
1255
|
+
className: "relative overflow-y-auto overflow-x-hidden rounded-[44px] bg-card",
|
|
1256
|
+
style: { width, height: Math.min(height, DEVICE_SCREEN_HEIGHT) },
|
|
1257
|
+
children: /* @__PURE__ */ jsxs4("div", { className: "relative", style: { width, height }, children: [
|
|
1258
|
+
thumbnailUrl && // biome-ignore lint/performance/noImgElement: API thumbnail under the live board while it loads
|
|
1259
|
+
/* @__PURE__ */ jsx4(
|
|
1260
|
+
"img",
|
|
1261
|
+
{
|
|
1262
|
+
src: thumbnailUrl,
|
|
1263
|
+
alt: "",
|
|
1264
|
+
width,
|
|
1265
|
+
height,
|
|
1266
|
+
className: "pointer-events-none absolute inset-0 select-none"
|
|
1267
|
+
}
|
|
1268
|
+
),
|
|
1269
|
+
htmlUrl && /* @__PURE__ */ jsx4(
|
|
1270
|
+
"iframe",
|
|
1271
|
+
{
|
|
1272
|
+
src: htmlUrl,
|
|
1273
|
+
title: board.title ?? board.boardKey ?? "Board",
|
|
1274
|
+
sandbox: "",
|
|
1275
|
+
referrerPolicy: "no-referrer",
|
|
1276
|
+
width,
|
|
1277
|
+
height,
|
|
1278
|
+
className: "absolute inset-0 border-0 bg-transparent"
|
|
1279
|
+
},
|
|
1280
|
+
htmlUrl
|
|
1281
|
+
),
|
|
1282
|
+
isPlacingPin && /* @__PURE__ */ jsx4(
|
|
1283
|
+
"button",
|
|
1284
|
+
{
|
|
1285
|
+
type: "button",
|
|
1286
|
+
"aria-label": "Place the pin here",
|
|
1287
|
+
className: "absolute inset-0 z-10 cursor-crosshair bg-brand/10",
|
|
1288
|
+
onClick: placePin
|
|
1289
|
+
}
|
|
1290
|
+
),
|
|
1291
|
+
isMarkingRegion && /* @__PURE__ */ jsx4(
|
|
1292
|
+
"button",
|
|
1293
|
+
{
|
|
1294
|
+
type: "button",
|
|
1295
|
+
"aria-label": "Drag a rectangle to mark a region of the board",
|
|
1296
|
+
className: "absolute inset-0 z-10 cursor-crosshair touch-none bg-brand/5",
|
|
1297
|
+
onPointerDown: startRegion,
|
|
1298
|
+
onPointerMove: moveRegion,
|
|
1299
|
+
onPointerUp: endRegion
|
|
1300
|
+
}
|
|
1301
|
+
),
|
|
1302
|
+
shownRegion && /* @__PURE__ */ jsx4(
|
|
1303
|
+
"span",
|
|
1304
|
+
{
|
|
1305
|
+
"aria-hidden": true,
|
|
1306
|
+
className: cx(
|
|
1307
|
+
"pointer-events-none absolute z-20 rounded-md border-2 border-dashed border-brand bg-brand/10 transition-shadow motion-reduce:transition-none",
|
|
1308
|
+
isRegionFlashing && "shadow-[0_0_0_6px_var(--brand)]"
|
|
1309
|
+
),
|
|
1310
|
+
style: {
|
|
1311
|
+
left: shownRegion.x,
|
|
1312
|
+
top: shownRegion.y,
|
|
1313
|
+
width: shownRegion.width,
|
|
1314
|
+
height: shownRegion.height
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
),
|
|
1318
|
+
pinnedThreads.map((thread) => /* @__PURE__ */ jsx4(
|
|
1319
|
+
"button",
|
|
1320
|
+
{
|
|
1321
|
+
type: "button",
|
|
1322
|
+
"aria-label": `Comment ${thread.pinNumber}`,
|
|
1323
|
+
onMouseEnter: () => setHighlightedCommentId(Number(thread.root.id)),
|
|
1324
|
+
onClick: () => setHighlightedCommentId(Number(thread.root.id)),
|
|
1325
|
+
className: cx(
|
|
1326
|
+
"absolute z-20 flex size-7 -translate-x-1/2 -translate-y-full items-center justify-center rounded-full rounded-bl-none text-xs font-bold shadow-surface-raised ring-2 ring-card",
|
|
1327
|
+
thread.root.isResolved ? "bg-muted text-muted-foreground" : "bg-primary text-primary-foreground",
|
|
1328
|
+
highlightedCommentId === Number(thread.root.id) && "ring-brand scale-110"
|
|
1329
|
+
),
|
|
1330
|
+
style: { left: thread.root.x ?? 0, top: thread.root.y ?? 0 },
|
|
1331
|
+
children: thread.pinNumber
|
|
1332
|
+
},
|
|
1333
|
+
String(thread.root.id)
|
|
1334
|
+
)),
|
|
1335
|
+
pendingPin && /* @__PURE__ */ jsx4(
|
|
1336
|
+
"span",
|
|
1337
|
+
{
|
|
1338
|
+
className: "absolute z-20 flex size-7 -translate-x-1/2 -translate-y-full items-center justify-center rounded-full rounded-bl-none bg-brand text-card shadow-surface-raised ring-2 ring-card",
|
|
1339
|
+
style: { left: pendingPin.x, top: pendingPin.y },
|
|
1340
|
+
"aria-hidden": true,
|
|
1341
|
+
children: /* @__PURE__ */ jsx4(MapPin2, { className: "size-4" })
|
|
1342
|
+
}
|
|
1343
|
+
)
|
|
1344
|
+
] })
|
|
1345
|
+
}
|
|
1346
|
+
) }) }),
|
|
1347
|
+
/* @__PURE__ */ jsxs4("aside", { className: "flex min-h-0 w-full flex-col border-t border-border lg:w-[400px] lg:border-t-0 lg:border-l", children: [
|
|
1348
|
+
/* @__PURE__ */ jsxs4("div", { className: "space-y-2 border-b border-border px-5 py-4", children: [
|
|
1349
|
+
/* @__PURE__ */ jsx4("p", { className: "text-sm font-semibold", children: "Reference for an agent" }),
|
|
1350
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
1351
|
+
/* @__PURE__ */ jsxs4(
|
|
1352
|
+
Button,
|
|
1353
|
+
{
|
|
1354
|
+
variant: isMarkingRegion ? "default" : "outline",
|
|
1355
|
+
size: "sm",
|
|
1356
|
+
"aria-pressed": isMarkingRegion,
|
|
1357
|
+
onClick: () => setIsMarkingRegion((marking) => !marking),
|
|
1358
|
+
children: [
|
|
1359
|
+
/* @__PURE__ */ jsx4(SquareDashedMousePointer, {}),
|
|
1360
|
+
" ",
|
|
1361
|
+
isMarkingRegion ? "Drag on the board\u2026" : "Mark region"
|
|
1362
|
+
]
|
|
1363
|
+
}
|
|
1364
|
+
),
|
|
1365
|
+
region && /* @__PURE__ */ jsx4(Button, { variant: "ghost", size: "sm", onClick: () => setRegion(null), children: "Clear region" }),
|
|
1366
|
+
/* @__PURE__ */ jsxs4(Button, { variant: "outline", size: "sm", className: "ml-auto", onClick: copyReference, children: [
|
|
1367
|
+
/* @__PURE__ */ jsx4(ClipboardCopy3, {}),
|
|
1368
|
+
" Copy reference"
|
|
1369
|
+
] })
|
|
1370
|
+
] }),
|
|
1371
|
+
region && /* @__PURE__ */ jsxs4("p", { className: "text-xs text-muted-foreground tabular-nums", children: [
|
|
1372
|
+
"Region ",
|
|
1373
|
+
Math.round(region.x),
|
|
1374
|
+
",",
|
|
1375
|
+
Math.round(region.y),
|
|
1376
|
+
" \xB7 ",
|
|
1377
|
+
Math.round(region.width),
|
|
1378
|
+
" \xD7",
|
|
1379
|
+
" ",
|
|
1380
|
+
Math.round(region.height),
|
|
1381
|
+
" px"
|
|
1382
|
+
] }),
|
|
1383
|
+
/* @__PURE__ */ jsx4(
|
|
1384
|
+
Textarea,
|
|
1385
|
+
{
|
|
1386
|
+
value: referenceNote,
|
|
1387
|
+
onChange: (event) => setReferenceNote(event.target.value),
|
|
1388
|
+
placeholder: texts.referenceNotePlaceholder,
|
|
1389
|
+
rows: 2,
|
|
1390
|
+
"aria-label": "Note for the reference"
|
|
1391
|
+
}
|
|
1392
|
+
)
|
|
1393
|
+
] }),
|
|
1394
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2 px-5 pt-4", children: [
|
|
1395
|
+
/* @__PURE__ */ jsxs4(
|
|
1396
|
+
Button,
|
|
1397
|
+
{
|
|
1398
|
+
variant: isPlacingPin ? "default" : "outline",
|
|
1399
|
+
size: "sm",
|
|
1400
|
+
disabled: !writesAllowed,
|
|
1401
|
+
"aria-pressed": isPlacingPin,
|
|
1402
|
+
onClick: () => setIsPlacingPin((placing) => !placing),
|
|
1403
|
+
children: [
|
|
1404
|
+
/* @__PURE__ */ jsx4(MapPinPlus, {}),
|
|
1405
|
+
" ",
|
|
1406
|
+
isPlacingPin ? "Click on the board\u2026" : "Add pin"
|
|
1407
|
+
]
|
|
1408
|
+
}
|
|
1409
|
+
),
|
|
1410
|
+
/* @__PURE__ */ jsxs4("span", { className: "text-xs text-muted-foreground", children: [
|
|
1411
|
+
threads.filter((thread) => !thread.root.isResolved).length,
|
|
1412
|
+
" open"
|
|
1413
|
+
] })
|
|
1414
|
+
] }),
|
|
1415
|
+
/* @__PURE__ */ jsx4("div", { className: "min-h-0 flex-1 overflow-y-auto px-5 py-4", children: /* @__PURE__ */ jsx4(
|
|
1416
|
+
BoardComments,
|
|
1417
|
+
{
|
|
1418
|
+
projectKey,
|
|
1419
|
+
canvasKey,
|
|
1420
|
+
board,
|
|
1421
|
+
threads,
|
|
1422
|
+
pendingPin,
|
|
1423
|
+
onClearPendingPin: () => setPendingPin(null),
|
|
1424
|
+
highlightedCommentId,
|
|
1425
|
+
onHighlightComment: setHighlightedCommentId,
|
|
1426
|
+
writesAllowed,
|
|
1427
|
+
showResolved,
|
|
1428
|
+
onShowResolvedChange: setShowResolved,
|
|
1429
|
+
pinHint: "\u201CAdd pin\u201D marks a spot on the board",
|
|
1430
|
+
onCopyThreadReference
|
|
1431
|
+
}
|
|
1432
|
+
) })
|
|
1433
|
+
] })
|
|
1434
|
+
] })
|
|
1435
|
+
] })
|
|
1436
|
+
}
|
|
1437
|
+
) });
|
|
1438
|
+
};
|
|
1439
|
+
|
|
1440
|
+
// src/canvas/DesignCanvasFlow.tsx
|
|
1441
|
+
import "@xyflow/react/dist/style.css";
|
|
1442
|
+
import {
|
|
1443
|
+
Background,
|
|
1444
|
+
BackgroundVariant,
|
|
1445
|
+
MiniMap,
|
|
1446
|
+
Panel,
|
|
1447
|
+
ReactFlow,
|
|
1448
|
+
ReactFlowProvider,
|
|
1449
|
+
useReactFlow,
|
|
1450
|
+
useStore as useStore3
|
|
1451
|
+
} from "@xyflow/react";
|
|
1452
|
+
import { ChevronDown, Hand, MousePointer2, Play } from "lucide-react";
|
|
1453
|
+
import { useCallback, useEffect as useEffect5, useMemo, useRef as useRef2, useState as useState7 } from "react";
|
|
1454
|
+
|
|
1455
|
+
// src/canvas/SectionNode.tsx
|
|
1456
|
+
import { useStore as useStore2 } from "@xyflow/react";
|
|
1457
|
+
import { memo as memo2 } from "react";
|
|
1458
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1459
|
+
var OVERVIEW_TITLE_SCREEN_PX = 15;
|
|
1460
|
+
var SectionNodeComponent = ({ data }) => {
|
|
1461
|
+
const { onZoomToSection } = useCanvasView();
|
|
1462
|
+
const zoom = useStore2((state) => data.isOverview ? Math.round(state.transform[2] * 1e3) / 1e3 : 1);
|
|
1463
|
+
if (!data.isOverview) {
|
|
1464
|
+
return /* @__PURE__ */ jsx5("div", { className: "pointer-events-none h-full w-full rounded-[64px] bg-card/50 ring-2 ring-foreground/5 backdrop-blur-xl", children: /* @__PURE__ */ jsxs5(
|
|
1465
|
+
"div",
|
|
1466
|
+
{
|
|
1467
|
+
className: "flex items-baseline gap-4 overflow-hidden text-ellipsis whitespace-nowrap",
|
|
1468
|
+
style: { padding: `${SECTION_PADDING}px ${SECTION_PADDING}px 0` },
|
|
1469
|
+
title: data.title,
|
|
1470
|
+
children: [
|
|
1471
|
+
/* @__PURE__ */ jsx5("span", { className: "text-[56px] leading-none font-bold tracking-tight text-foreground", children: data.title }),
|
|
1472
|
+
/* @__PURE__ */ jsxs5("span", { className: "text-[28px] leading-none text-muted-foreground", children: [
|
|
1473
|
+
data.boardCount,
|
|
1474
|
+
" boards"
|
|
1475
|
+
] })
|
|
1476
|
+
]
|
|
1477
|
+
}
|
|
1478
|
+
) });
|
|
1479
|
+
}
|
|
1480
|
+
const titleFontSize = Math.min(OVERVIEW_TITLE_SCREEN_PX / zoom, data.width / 7);
|
|
1481
|
+
return /* @__PURE__ */ jsxs5(
|
|
1482
|
+
"button",
|
|
1483
|
+
{
|
|
1484
|
+
type: "button",
|
|
1485
|
+
onClick: () => onZoomToSection(data.sectionId),
|
|
1486
|
+
"aria-label": `${data.title}: ${data.boardCount} boards \u2014 zoom in`,
|
|
1487
|
+
className: "flex h-full w-full cursor-zoom-in flex-col overflow-hidden rounded-[64px] bg-card text-left shadow-surface-raised ring-1 ring-foreground/10 transition-shadow hover:ring-[24px] hover:ring-brand/40",
|
|
1488
|
+
style: { padding: titleFontSize },
|
|
1489
|
+
children: [
|
|
1490
|
+
/* @__PURE__ */ jsxs5("span", { className: "block w-full", style: { fontSize: titleFontSize, lineHeight: 1.2 }, children: [
|
|
1491
|
+
/* @__PURE__ */ jsx5("span", { className: "line-clamp-2 font-bold text-foreground", children: data.title }),
|
|
1492
|
+
/* @__PURE__ */ jsxs5("span", { className: "block text-muted-foreground", style: { fontSize: titleFontSize * 0.8 }, children: [
|
|
1493
|
+
data.boardCount,
|
|
1494
|
+
" boards"
|
|
1495
|
+
] })
|
|
1496
|
+
] }),
|
|
1497
|
+
/* @__PURE__ */ jsx5(
|
|
1498
|
+
"span",
|
|
1499
|
+
{
|
|
1500
|
+
className: "mt-auto grid min-h-0 flex-1 grid-cols-2 content-end",
|
|
1501
|
+
style: { gap: titleFontSize * 0.6, paddingTop: titleFontSize * 0.6 },
|
|
1502
|
+
children: data.coverUrls.map((coverUrl) => (
|
|
1503
|
+
// biome-ignore lint/performance/noImgElement: small cover thumbnails from the API at canvas scale
|
|
1504
|
+
/* @__PURE__ */ jsx5(
|
|
1505
|
+
"img",
|
|
1506
|
+
{
|
|
1507
|
+
src: coverUrl,
|
|
1508
|
+
alt: "",
|
|
1509
|
+
loading: "lazy",
|
|
1510
|
+
decoding: "async",
|
|
1511
|
+
draggable: false,
|
|
1512
|
+
className: "pointer-events-none w-full rounded-[24px] object-cover object-top shadow-surface-raised select-none"
|
|
1513
|
+
},
|
|
1514
|
+
coverUrl
|
|
1515
|
+
)
|
|
1516
|
+
))
|
|
1517
|
+
}
|
|
1518
|
+
)
|
|
1519
|
+
]
|
|
1520
|
+
}
|
|
1521
|
+
);
|
|
1522
|
+
};
|
|
1523
|
+
var SectionNode = memo2(SectionNodeComponent);
|
|
1524
|
+
|
|
1525
|
+
// src/canvas/DesignCanvasFlow.tsx
|
|
1526
|
+
import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1527
|
+
var NODE_TYPES = { board: BoardNode, section: SectionNode };
|
|
1528
|
+
var ZOOM_PRESETS = [0.25, 0.5, 1];
|
|
1529
|
+
var MIN_ZOOM = 5e-3;
|
|
1530
|
+
var MAX_ZOOM = 2.5;
|
|
1531
|
+
var WHEEL_ZOOM_PER_PIXEL = Math.log(1.12) / 100;
|
|
1532
|
+
var PINCH_ZOOM_PER_PIXEL = 0.012;
|
|
1533
|
+
var WHEEL_LINE_PIXELS = 100 / 3;
|
|
1534
|
+
var WHEEL_PAGE_PIXELS = 800;
|
|
1535
|
+
var WHEEL_MAX_PIXELS = 300;
|
|
1536
|
+
var ZOOM_EASE = 0.35;
|
|
1537
|
+
var VIEWPORT_COMMIT_MS = 300;
|
|
1538
|
+
var FIT_PADDING = 24;
|
|
1539
|
+
var FIT_TOP = 72;
|
|
1540
|
+
var OVERVIEW_ZOOM = 0.06;
|
|
1541
|
+
var LIVE_BOARDS_SETTLE_MS = 300;
|
|
1542
|
+
var OVERVIEW_COVER_COUNT = 4;
|
|
1543
|
+
var MINIMAP_WIDTH = 200;
|
|
1544
|
+
var CLICK_MAX_MOVE2 = 5;
|
|
1545
|
+
var MARQUEE_MIN_DRAG = 4;
|
|
1546
|
+
var TOOLBAR_GROUP_CLASS = "surface-glass-strong flex items-center gap-1 rounded-2xl p-1 ring-1 ring-foreground/5";
|
|
1547
|
+
var TOOL_BUTTON_CLASS = "flex size-8 items-center justify-center rounded-xl text-muted-foreground transition-colors hover:bg-tint hover:text-foreground motion-reduce:transition-none";
|
|
1548
|
+
var ZoomMenu = ({ onFitAll }) => {
|
|
1549
|
+
const { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } = useDesignStudioComponents();
|
|
1550
|
+
const reactFlow = useReactFlow();
|
|
1551
|
+
const zoomPercent = useStore3((state) => Math.round(state.transform[2] * 100));
|
|
1552
|
+
return /* @__PURE__ */ jsxs6(DropdownMenu, { modal: false, children: [
|
|
1553
|
+
/* @__PURE__ */ jsx6(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs6(
|
|
1554
|
+
"button",
|
|
1555
|
+
{
|
|
1556
|
+
type: "button",
|
|
1557
|
+
className: "flex h-8 min-w-16 items-center justify-center gap-1 rounded-xl px-2 text-sm font-semibold tabular-nums transition-colors hover:bg-tint",
|
|
1558
|
+
"aria-label": `Zoom ${zoomPercent} %`,
|
|
1559
|
+
children: [
|
|
1560
|
+
zoomPercent,
|
|
1561
|
+
"%",
|
|
1562
|
+
/* @__PURE__ */ jsx6(ChevronDown, { className: "size-3.5 text-muted-foreground", "aria-hidden": true })
|
|
1563
|
+
]
|
|
1564
|
+
}
|
|
1565
|
+
) }),
|
|
1566
|
+
/* @__PURE__ */ jsxs6(DropdownMenuContent, { align: "end", children: [
|
|
1567
|
+
ZOOM_PRESETS.map((zoom) => /* @__PURE__ */ jsxs6(DropdownMenuItem, { onSelect: () => void reactFlow.zoomTo(zoom, { duration: 250 }), children: [
|
|
1568
|
+
Math.round(zoom * 100),
|
|
1569
|
+
" %"
|
|
1570
|
+
] }, zoom)),
|
|
1571
|
+
/* @__PURE__ */ jsx6(DropdownMenuSeparator, {}),
|
|
1572
|
+
/* @__PURE__ */ jsx6(DropdownMenuItem, { onSelect: () => void reactFlow.zoomIn({ duration: 200 }), children: "Zoom in" }),
|
|
1573
|
+
/* @__PURE__ */ jsx6(DropdownMenuItem, { onSelect: () => void reactFlow.zoomOut({ duration: 200 }), children: "Zoom out" }),
|
|
1574
|
+
/* @__PURE__ */ jsx6(DropdownMenuItem, { onSelect: onFitAll, children: "Fit all" })
|
|
1575
|
+
] })
|
|
1576
|
+
] });
|
|
1577
|
+
};
|
|
1578
|
+
var buildNodes = (layout, boardsByNodeId, isOverview, apiBaseUrl) => {
|
|
1579
|
+
const sectionNodes = layout.sections.map((section) => ({
|
|
1580
|
+
id: sectionNodeId(section.id),
|
|
1581
|
+
type: "section",
|
|
1582
|
+
position: { x: section.x, y: section.y },
|
|
1583
|
+
width: section.width,
|
|
1584
|
+
height: section.height,
|
|
1585
|
+
data: {
|
|
1586
|
+
sectionId: section.id,
|
|
1587
|
+
title: section.title,
|
|
1588
|
+
boardCount: section.boardCount,
|
|
1589
|
+
isOverview,
|
|
1590
|
+
width: section.width,
|
|
1591
|
+
coverUrls: isOverview ? section.boardIds.slice(0, OVERVIEW_COVER_COUNT).map((boardId) => boardsByNodeId.get(boardId)?.thumbnailSmallUrl).filter((url) => Boolean(url)).map((url) => resolveStableContentUrl(`${apiBaseUrl}${url}`)) : []
|
|
1592
|
+
},
|
|
1593
|
+
draggable: false,
|
|
1594
|
+
selectable: false,
|
|
1595
|
+
focusable: false,
|
|
1596
|
+
// overview cards are buttons (click = zoom to the section); React Flow would set pointer-events: none otherwise
|
|
1597
|
+
style: isOverview ? { pointerEvents: "all" } : void 0,
|
|
1598
|
+
zIndex: 0
|
|
1599
|
+
}));
|
|
1600
|
+
if (isOverview) return sectionNodes;
|
|
1601
|
+
const boardNodes = [];
|
|
1602
|
+
for (const [nodeId, rect] of layout.boards) {
|
|
1603
|
+
const board = boardsByNodeId.get(nodeId);
|
|
1604
|
+
if (!board) continue;
|
|
1605
|
+
boardNodes.push({
|
|
1606
|
+
id: nodeId,
|
|
1607
|
+
type: "board",
|
|
1608
|
+
position: { x: rect.x, y: rect.y },
|
|
1609
|
+
width: rect.width,
|
|
1610
|
+
height: rect.height,
|
|
1611
|
+
data: { board },
|
|
1612
|
+
draggable: false,
|
|
1613
|
+
selectable: false,
|
|
1614
|
+
// the node's own buttons select / open it; React Flow would set pointer-events: none on a non-selectable node
|
|
1615
|
+
style: { pointerEvents: "all" },
|
|
1616
|
+
zIndex: 1
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1619
|
+
return [...sectionNodes, ...boardNodes];
|
|
1620
|
+
};
|
|
1621
|
+
var isSameNodeValue = (previous, next) => {
|
|
1622
|
+
if (Object.is(previous, next)) return true;
|
|
1623
|
+
if (Array.isArray(previous) && Array.isArray(next)) {
|
|
1624
|
+
return previous.length === next.length && previous.every(
|
|
1625
|
+
(value, index) => typeof value === "string" && typeof next[index] === "string" ? withoutContentToken(value) === withoutContentToken(next[index]) : Object.is(value, next[index])
|
|
1626
|
+
);
|
|
1627
|
+
}
|
|
1628
|
+
return false;
|
|
1629
|
+
};
|
|
1630
|
+
var isSameRecord = (previous, next) => {
|
|
1631
|
+
if (previous === next) return true;
|
|
1632
|
+
if (!previous || !next) return false;
|
|
1633
|
+
const previousEntries = Object.entries(previous);
|
|
1634
|
+
const nextRecord = next;
|
|
1635
|
+
return previousEntries.length === Object.keys(next).length && previousEntries.every(([key, value]) => key in nextRecord && isSameNodeValue(value, nextRecord[key]));
|
|
1636
|
+
};
|
|
1637
|
+
var reuseUnchangedNodes = (previousNodes, nextNodes) => {
|
|
1638
|
+
if (previousNodes.length === 0) return nextNodes;
|
|
1639
|
+
const previousById = new Map(previousNodes.map((node) => [node.id, node]));
|
|
1640
|
+
let isAnyChanged = previousNodes.length !== nextNodes.length;
|
|
1641
|
+
const nodes = nextNodes.map((next, index) => {
|
|
1642
|
+
const previous = previousById.get(next.id);
|
|
1643
|
+
const isSame = previous !== void 0 && previous.type === next.type && previous.width === next.width && previous.height === next.height && previous.zIndex === next.zIndex && isSameRecord(previous.position, next.position) && isSameRecord(previous.style, next.style) && isSameRecord(previous.data, next.data);
|
|
1644
|
+
if (!isSame || previousNodes[index] !== previous) isAnyChanged = true;
|
|
1645
|
+
return isSame ? previous : next;
|
|
1646
|
+
});
|
|
1647
|
+
return isAnyChanged ? nodes : previousNodes;
|
|
1648
|
+
};
|
|
1649
|
+
var useWheelZoom = (containerRef) => {
|
|
1650
|
+
const reactFlow = useReactFlow();
|
|
1651
|
+
useEffect5(() => {
|
|
1652
|
+
const container = containerRef.current;
|
|
1653
|
+
if (!container) return;
|
|
1654
|
+
const minLogZoom = Math.log(MIN_ZOOM);
|
|
1655
|
+
const maxLogZoom = Math.log(MAX_ZOOM);
|
|
1656
|
+
let targetLogZoom = 0;
|
|
1657
|
+
let anchorX = 0;
|
|
1658
|
+
let anchorY = 0;
|
|
1659
|
+
let frame = null;
|
|
1660
|
+
let frameCount = 0;
|
|
1661
|
+
const step = () => {
|
|
1662
|
+
const { x, y, zoom } = reactFlow.getViewport();
|
|
1663
|
+
const currentLogZoom = Math.log(zoom);
|
|
1664
|
+
const difference = targetLogZoom - currentLogZoom;
|
|
1665
|
+
frameCount += 1;
|
|
1666
|
+
const isLast = Math.abs(difference) < 2e-3 || frameCount > 90;
|
|
1667
|
+
const nextZoom = Math.exp(isLast ? targetLogZoom : currentLogZoom + difference * ZOOM_EASE);
|
|
1668
|
+
void reactFlow.setViewport({
|
|
1669
|
+
x: anchorX - (anchorX - x) / zoom * nextZoom,
|
|
1670
|
+
y: anchorY - (anchorY - y) / zoom * nextZoom,
|
|
1671
|
+
zoom: nextZoom
|
|
1672
|
+
});
|
|
1673
|
+
frame = isLast ? null : requestAnimationFrame(step);
|
|
1674
|
+
};
|
|
1675
|
+
const zoomBy = (logDelta, clientX, clientY) => {
|
|
1676
|
+
const bounds = container.getBoundingClientRect();
|
|
1677
|
+
anchorX = clientX - bounds.left;
|
|
1678
|
+
anchorY = clientY - bounds.top;
|
|
1679
|
+
if (frame === null) targetLogZoom = Math.log(reactFlow.getZoom());
|
|
1680
|
+
targetLogZoom = Math.min(maxLogZoom, Math.max(minLogZoom, targetLogZoom + logDelta));
|
|
1681
|
+
frameCount = 0;
|
|
1682
|
+
if (frame === null) frame = requestAnimationFrame(step);
|
|
1683
|
+
};
|
|
1684
|
+
const onWheel = (event) => {
|
|
1685
|
+
if (event.target instanceof Element && event.target.closest(".nowheel")) return;
|
|
1686
|
+
event.preventDefault();
|
|
1687
|
+
if (isGesturing && event.ctrlKey) return;
|
|
1688
|
+
const unit = event.deltaMode === 1 ? WHEEL_LINE_PIXELS : event.deltaMode === 2 ? WHEEL_PAGE_PIXELS : 1;
|
|
1689
|
+
const pixels = Math.max(-WHEEL_MAX_PIXELS, Math.min(WHEEL_MAX_PIXELS, event.deltaY * unit));
|
|
1690
|
+
zoomBy(-pixels * (event.ctrlKey ? PINCH_ZOOM_PER_PIXEL : WHEEL_ZOOM_PER_PIXEL), event.clientX, event.clientY);
|
|
1691
|
+
};
|
|
1692
|
+
let gestureScale = 1;
|
|
1693
|
+
let isGesturing = false;
|
|
1694
|
+
const onGestureStart = (event) => {
|
|
1695
|
+
event.preventDefault();
|
|
1696
|
+
gestureScale = 1;
|
|
1697
|
+
isGesturing = true;
|
|
1698
|
+
};
|
|
1699
|
+
const onGestureEnd = () => {
|
|
1700
|
+
isGesturing = false;
|
|
1701
|
+
};
|
|
1702
|
+
const onGestureChange = (event) => {
|
|
1703
|
+
event.preventDefault();
|
|
1704
|
+
const gesture = event;
|
|
1705
|
+
const scale = gesture.scale ?? 1;
|
|
1706
|
+
if (scale <= 0) return;
|
|
1707
|
+
zoomBy(Math.log(scale / gestureScale), gesture.clientX ?? 0, gesture.clientY ?? 0);
|
|
1708
|
+
gestureScale = scale;
|
|
1709
|
+
};
|
|
1710
|
+
container.addEventListener("wheel", onWheel, { passive: false });
|
|
1711
|
+
container.addEventListener("gesturestart", onGestureStart);
|
|
1712
|
+
container.addEventListener("gesturechange", onGestureChange);
|
|
1713
|
+
container.addEventListener("gestureend", onGestureEnd);
|
|
1714
|
+
return () => {
|
|
1715
|
+
container.removeEventListener("gestureend", onGestureEnd);
|
|
1716
|
+
container.removeEventListener("wheel", onWheel);
|
|
1717
|
+
container.removeEventListener("gesturestart", onGestureStart);
|
|
1718
|
+
container.removeEventListener("gesturechange", onGestureChange);
|
|
1719
|
+
if (frame !== null) cancelAnimationFrame(frame);
|
|
1720
|
+
};
|
|
1721
|
+
}, [containerRef, reactFlow]);
|
|
1722
|
+
};
|
|
1723
|
+
var FlowCanvas = ({
|
|
1724
|
+
layout,
|
|
1725
|
+
boardsByNodeId,
|
|
1726
|
+
fitRequest,
|
|
1727
|
+
initialFitNodeIds,
|
|
1728
|
+
initialViewport = null,
|
|
1729
|
+
onViewportCommit,
|
|
1730
|
+
tool,
|
|
1731
|
+
onToolChange,
|
|
1732
|
+
liveMinRatio,
|
|
1733
|
+
onLiveBoardIdsChange,
|
|
1734
|
+
onVisibleBoardIdsChange,
|
|
1735
|
+
onPaneClick,
|
|
1736
|
+
onPresentSection,
|
|
1737
|
+
toolbarStart,
|
|
1738
|
+
toolbarEnd,
|
|
1739
|
+
selectedNodeId,
|
|
1740
|
+
onMarqueeSelect
|
|
1741
|
+
}) => {
|
|
1742
|
+
const { apiBaseUrl, components, statusColors } = useDesignStudio();
|
|
1743
|
+
const { Tooltip, TooltipContent, TooltipTrigger } = components;
|
|
1744
|
+
const containerRef = useRef2(null);
|
|
1745
|
+
const reactFlow = useReactFlow();
|
|
1746
|
+
useWheelZoom(containerRef);
|
|
1747
|
+
const isOverview = useStore3((state) => state.transform[2] < OVERVIEW_ZOOM);
|
|
1748
|
+
const previousNodesRef = useRef2([]);
|
|
1749
|
+
const nodes = useMemo(() => {
|
|
1750
|
+
const reused = reuseUnchangedNodes(
|
|
1751
|
+
previousNodesRef.current,
|
|
1752
|
+
buildNodes(layout, boardsByNodeId, isOverview, apiBaseUrl)
|
|
1753
|
+
);
|
|
1754
|
+
previousNodesRef.current = reused;
|
|
1755
|
+
return reused;
|
|
1756
|
+
}, [layout, boardsByNodeId, isOverview, apiBaseUrl]);
|
|
1757
|
+
const isEverythingVisible = useStore3((state) => {
|
|
1758
|
+
const [x, y, zoom] = state.transform;
|
|
1759
|
+
return x >= -1 && y >= -1 && x + layout.bounds.width * zoom <= state.width + 1 && y + layout.bounds.height * zoom <= state.height + 1;
|
|
1760
|
+
});
|
|
1761
|
+
const boardRects = useMemo(
|
|
1762
|
+
() => [...layout.boards].map(([id, rect]) => ({ id, ...rect })),
|
|
1763
|
+
[layout]
|
|
1764
|
+
);
|
|
1765
|
+
const liveBoardsTimerRef = useRef2(null);
|
|
1766
|
+
const cancelLiveBoardsUpdate = useCallback(() => {
|
|
1767
|
+
if (liveBoardsTimerRef.current) clearTimeout(liveBoardsTimerRef.current);
|
|
1768
|
+
liveBoardsTimerRef.current = null;
|
|
1769
|
+
}, []);
|
|
1770
|
+
useEffect5(() => cancelLiveBoardsUpdate, [cancelLiveBoardsUpdate]);
|
|
1771
|
+
const updateLiveBoards = useCallback(
|
|
1772
|
+
(viewport) => {
|
|
1773
|
+
const container = containerRef.current;
|
|
1774
|
+
if (!container) return;
|
|
1775
|
+
const screen = { width: container.clientWidth, height: container.clientHeight };
|
|
1776
|
+
onLiveBoardIdsChange(selectLiveBoardIds(boardRects, viewport, screen, void 0, liveMinRatio));
|
|
1777
|
+
onVisibleBoardIdsChange?.(selectVisibleBoardIds(boardRects, viewport, screen));
|
|
1778
|
+
},
|
|
1779
|
+
[boardRects, onLiveBoardIdsChange, onVisibleBoardIdsChange, liveMinRatio]
|
|
1780
|
+
);
|
|
1781
|
+
const hasInitialFitRef = useRef2(false);
|
|
1782
|
+
const fitRect = useCallback(
|
|
1783
|
+
(rect, duration, fitWidthOnly = false) => {
|
|
1784
|
+
const container = containerRef.current;
|
|
1785
|
+
if (!container || container.clientWidth === 0 || rect.width <= 0 || rect.height <= 0) return null;
|
|
1786
|
+
const width = container.clientWidth;
|
|
1787
|
+
const height = container.clientHeight;
|
|
1788
|
+
const widthZoom = (width - 2 * FIT_PADDING) / rect.width;
|
|
1789
|
+
const heightZoom = fitWidthOnly ? widthZoom : (height - FIT_TOP - FIT_PADDING) / rect.height;
|
|
1790
|
+
const zoom = Math.max(MIN_ZOOM, Math.min(widthZoom, heightZoom, 1));
|
|
1791
|
+
const viewport = { x: (width - rect.width * zoom) / 2 - rect.x * zoom, y: FIT_TOP - rect.y * zoom, zoom };
|
|
1792
|
+
void reactFlow.setViewport(viewport, { duration }).then(() => {
|
|
1793
|
+
updateLiveBoards(viewport);
|
|
1794
|
+
});
|
|
1795
|
+
return viewport;
|
|
1796
|
+
},
|
|
1797
|
+
[reactFlow, updateLiveBoards]
|
|
1798
|
+
);
|
|
1799
|
+
const rectOfNodes = useCallback(
|
|
1800
|
+
(nodeIds) => {
|
|
1801
|
+
const sectionRects = new Map(layout.sections.map((section) => [sectionNodeId(section.id), section]));
|
|
1802
|
+
const rects = nodeIds.map((nodeId) => sectionRects.get(nodeId) ?? layout.boards.get(nodeId)).filter((rect) => rect !== void 0);
|
|
1803
|
+
if (rects.length === 0) return null;
|
|
1804
|
+
const left = Math.min(...rects.map((rect) => rect.x));
|
|
1805
|
+
const top = Math.min(...rects.map((rect) => rect.y));
|
|
1806
|
+
const right = Math.max(...rects.map((rect) => rect.x + rect.width));
|
|
1807
|
+
const bottom = Math.max(...rects.map((rect) => rect.y + rect.height));
|
|
1808
|
+
return { x: left, y: top, width: right - left, height: bottom - top };
|
|
1809
|
+
},
|
|
1810
|
+
[layout]
|
|
1811
|
+
);
|
|
1812
|
+
const fitNodes = useCallback(
|
|
1813
|
+
(nodeIds, duration = 400) => {
|
|
1814
|
+
const rect = rectOfNodes(nodeIds);
|
|
1815
|
+
const isSingleSection = nodeIds.length === 1 && nodeIds[0].startsWith(sectionNodeId(""));
|
|
1816
|
+
return rect ? fitRect(rect, duration, isSingleSection) : null;
|
|
1817
|
+
},
|
|
1818
|
+
[rectOfNodes, fitRect]
|
|
1819
|
+
);
|
|
1820
|
+
const fitAll = useCallback(() => {
|
|
1821
|
+
fitRect(layout.bounds, 400);
|
|
1822
|
+
}, [fitRect, layout]);
|
|
1823
|
+
const handledFitKeyRef = useRef2(null);
|
|
1824
|
+
useEffect5(() => {
|
|
1825
|
+
if (!fitRequest || handledFitKeyRef.current === fitRequest.key) return;
|
|
1826
|
+
handledFitKeyRef.current = fitRequest.key;
|
|
1827
|
+
fitNodes(fitRequest.nodeIds);
|
|
1828
|
+
}, [fitRequest, fitNodes]);
|
|
1829
|
+
const committedViewportRef = useRef2(null);
|
|
1830
|
+
const isFlowReadyRef = useRef2(false);
|
|
1831
|
+
const initialViewportRef = useRef2(initialViewport);
|
|
1832
|
+
const fitInitialView = useCallback(() => {
|
|
1833
|
+
if (!isFlowReadyRef.current || hasInitialFitRef.current || layout.sections.length === 0) return;
|
|
1834
|
+
const container = containerRef.current;
|
|
1835
|
+
if (!container || container.clientWidth === 0) return;
|
|
1836
|
+
const savedViewport = initialViewportRef.current;
|
|
1837
|
+
if (savedViewport) {
|
|
1838
|
+
hasInitialFitRef.current = true;
|
|
1839
|
+
committedViewportRef.current = formatViewportParam(savedViewport);
|
|
1840
|
+
void reactFlow.setViewport(savedViewport, { duration: 0 }).then(() => updateLiveBoards(savedViewport));
|
|
1841
|
+
return;
|
|
1842
|
+
}
|
|
1843
|
+
const viewport = initialFitNodeIds.length > 0 ? fitNodes(initialFitNodeIds, 0) : fitRect(layout.bounds, 0);
|
|
1844
|
+
if (viewport) {
|
|
1845
|
+
hasInitialFitRef.current = true;
|
|
1846
|
+
committedViewportRef.current = formatViewportParam(viewport);
|
|
1847
|
+
}
|
|
1848
|
+
}, [layout, initialFitNodeIds, fitNodes, fitRect, reactFlow, updateLiveBoards]);
|
|
1849
|
+
const viewportCommitTimerRef = useRef2(null);
|
|
1850
|
+
useEffect5(
|
|
1851
|
+
() => () => {
|
|
1852
|
+
if (viewportCommitTimerRef.current) clearTimeout(viewportCommitTimerRef.current);
|
|
1853
|
+
},
|
|
1854
|
+
[]
|
|
1855
|
+
);
|
|
1856
|
+
const commitViewport = (viewport) => {
|
|
1857
|
+
if (!hasInitialFitRef.current) return;
|
|
1858
|
+
if (viewportCommitTimerRef.current) clearTimeout(viewportCommitTimerRef.current);
|
|
1859
|
+
viewportCommitTimerRef.current = setTimeout(() => {
|
|
1860
|
+
viewportCommitTimerRef.current = null;
|
|
1861
|
+
const value = formatViewportParam(viewport);
|
|
1862
|
+
if (value === committedViewportRef.current) return;
|
|
1863
|
+
committedViewportRef.current = value;
|
|
1864
|
+
onViewportCommit?.(viewport);
|
|
1865
|
+
}, VIEWPORT_COMMIT_MS);
|
|
1866
|
+
};
|
|
1867
|
+
useEffect5(() => {
|
|
1868
|
+
fitInitialView();
|
|
1869
|
+
}, [fitInitialView]);
|
|
1870
|
+
useEffect5(() => {
|
|
1871
|
+
if (hasInitialFitRef.current) updateLiveBoards(reactFlow.getViewport());
|
|
1872
|
+
}, [reactFlow, updateLiveBoards]);
|
|
1873
|
+
useEffect5(() => {
|
|
1874
|
+
const container = containerRef.current;
|
|
1875
|
+
if (!container) return;
|
|
1876
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
1877
|
+
if (hasInitialFitRef.current) updateLiveBoards(reactFlow.getViewport());
|
|
1878
|
+
else fitInitialView();
|
|
1879
|
+
});
|
|
1880
|
+
resizeObserver.observe(container);
|
|
1881
|
+
return () => resizeObserver.disconnect();
|
|
1882
|
+
}, [reactFlow, updateLiveBoards, fitInitialView]);
|
|
1883
|
+
useEffect5(() => {
|
|
1884
|
+
const onKeyDown = (event) => {
|
|
1885
|
+
const target = event.target;
|
|
1886
|
+
if (target && (target.tagName === "TEXTAREA" || target.tagName === "INPUT" || target.isContentEditable)) return;
|
|
1887
|
+
if (document.querySelector("[role=dialog]")) return;
|
|
1888
|
+
if (event.metaKey || event.ctrlKey || event.altKey) return;
|
|
1889
|
+
if (event.key === "v" || event.key === "V") onToolChange("select");
|
|
1890
|
+
else if (event.key === "h" || event.key === "H" || event.key === "Escape") onToolChange("hand");
|
|
1891
|
+
else if (event.shiftKey && event.code === "Digit1") fitAll();
|
|
1892
|
+
else if (event.shiftKey && event.code === "Digit2") fitSelectionOrSection();
|
|
1893
|
+
else if (event.key === "+" || event.key === "=") void reactFlow.zoomIn({ duration: 200 });
|
|
1894
|
+
else if (event.key === "-" || event.key === "_") void reactFlow.zoomOut({ duration: 200 });
|
|
1895
|
+
else if (event.key === "0" && !event.shiftKey) void reactFlow.zoomTo(1, { duration: 250 });
|
|
1896
|
+
};
|
|
1897
|
+
window.addEventListener("keydown", onKeyDown);
|
|
1898
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
1899
|
+
});
|
|
1900
|
+
const sectionInView = () => {
|
|
1901
|
+
const container = containerRef.current;
|
|
1902
|
+
if (!container || layout.sections.length === 0) return void 0;
|
|
1903
|
+
const viewport = reactFlow.getViewport();
|
|
1904
|
+
const centreX = (-viewport.x + container.clientWidth / 2) / viewport.zoom;
|
|
1905
|
+
const centreY = (-viewport.y + container.clientHeight / 2) / viewport.zoom;
|
|
1906
|
+
return findSectionAt(layout.sections, centreX, centreY) ?? layout.sections[0];
|
|
1907
|
+
};
|
|
1908
|
+
const fitSelectionOrSection = () => {
|
|
1909
|
+
if (selectedNodeId && layout.boards.has(selectedNodeId)) {
|
|
1910
|
+
fitNodes([selectedNodeId]);
|
|
1911
|
+
return;
|
|
1912
|
+
}
|
|
1913
|
+
const section = sectionInView();
|
|
1914
|
+
if (section) fitNodes([sectionNodeId(section.id)]);
|
|
1915
|
+
};
|
|
1916
|
+
const presentCurrentSection = () => {
|
|
1917
|
+
const section = sectionInView();
|
|
1918
|
+
if (section) onPresentSection(section.id);
|
|
1919
|
+
};
|
|
1920
|
+
const [marquee, setMarquee] = useState7(null);
|
|
1921
|
+
const isMarqueeJustEndedRef = useRef2(false);
|
|
1922
|
+
const startMarquee = (event) => {
|
|
1923
|
+
const target = event.target;
|
|
1924
|
+
if (tool !== "select" || event.button !== 0 || !target.classList.contains("react-flow__pane")) return;
|
|
1925
|
+
const container = containerRef.current;
|
|
1926
|
+
if (!container) return;
|
|
1927
|
+
const bounds = container.getBoundingClientRect();
|
|
1928
|
+
const startX = event.clientX - bounds.left;
|
|
1929
|
+
const startY = event.clientY - bounds.top;
|
|
1930
|
+
const isAdditive = event.shiftKey || event.metaKey || event.ctrlKey;
|
|
1931
|
+
let current = { startX, startY, x: startX, y: startY };
|
|
1932
|
+
setMarquee(current);
|
|
1933
|
+
const onMove = (moveEvent) => {
|
|
1934
|
+
current = { startX, startY, x: moveEvent.clientX - bounds.left, y: moveEvent.clientY - bounds.top };
|
|
1935
|
+
setMarquee(current);
|
|
1936
|
+
};
|
|
1937
|
+
const onUp = () => {
|
|
1938
|
+
window.removeEventListener("pointermove", onMove);
|
|
1939
|
+
window.removeEventListener("pointerup", onUp);
|
|
1940
|
+
setMarquee(null);
|
|
1941
|
+
if (Math.abs(current.x - startX) < MARQUEE_MIN_DRAG && Math.abs(current.y - startY) < MARQUEE_MIN_DRAG) return;
|
|
1942
|
+
isMarqueeJustEndedRef.current = true;
|
|
1943
|
+
const topLeft = reactFlow.screenToFlowPosition({
|
|
1944
|
+
x: bounds.left + Math.min(startX, current.x),
|
|
1945
|
+
y: bounds.top + Math.min(startY, current.y)
|
|
1946
|
+
});
|
|
1947
|
+
const bottomRight = reactFlow.screenToFlowPosition({
|
|
1948
|
+
x: bounds.left + Math.max(startX, current.x),
|
|
1949
|
+
y: bounds.top + Math.max(startY, current.y)
|
|
1950
|
+
});
|
|
1951
|
+
const nodeIds = [...layout.boards].filter(
|
|
1952
|
+
([, rect]) => rect.x < bottomRight.x && rect.x + rect.width > topLeft.x && rect.y < bottomRight.y && rect.y + rect.height > topLeft.y
|
|
1953
|
+
).map(([nodeId]) => nodeId);
|
|
1954
|
+
onMarqueeSelect(nodeIds, isAdditive);
|
|
1955
|
+
};
|
|
1956
|
+
window.addEventListener("pointermove", onMove);
|
|
1957
|
+
window.addEventListener("pointerup", onUp);
|
|
1958
|
+
};
|
|
1959
|
+
const onPaneClickUnlessMarquee = () => {
|
|
1960
|
+
if (isMarqueeJustEndedRef.current) {
|
|
1961
|
+
isMarqueeJustEndedRef.current = false;
|
|
1962
|
+
return;
|
|
1963
|
+
}
|
|
1964
|
+
onPaneClick();
|
|
1965
|
+
};
|
|
1966
|
+
const minimapHeight = Math.round(
|
|
1967
|
+
Math.min(180, Math.max(60, MINIMAP_WIDTH * layout.bounds.height / Math.max(1, layout.bounds.width)))
|
|
1968
|
+
);
|
|
1969
|
+
return /* @__PURE__ */ jsxs6(
|
|
1970
|
+
"div",
|
|
1971
|
+
{
|
|
1972
|
+
ref: containerRef,
|
|
1973
|
+
className: cx("relative h-full w-full", tool === "hand" && "cursor-grab active:cursor-grabbing"),
|
|
1974
|
+
onPointerDownCapture: startMarquee,
|
|
1975
|
+
children: [
|
|
1976
|
+
marquee && /* @__PURE__ */ jsx6(
|
|
1977
|
+
"div",
|
|
1978
|
+
{
|
|
1979
|
+
"aria-hidden": true,
|
|
1980
|
+
className: "pointer-events-none absolute z-10 rounded-sm border border-brand bg-brand/10",
|
|
1981
|
+
style: {
|
|
1982
|
+
left: Math.min(marquee.startX, marquee.x),
|
|
1983
|
+
top: Math.min(marquee.startY, marquee.y),
|
|
1984
|
+
width: Math.abs(marquee.x - marquee.startX),
|
|
1985
|
+
height: Math.abs(marquee.y - marquee.startY)
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
),
|
|
1989
|
+
/* @__PURE__ */ jsxs6(
|
|
1990
|
+
ReactFlow,
|
|
1991
|
+
{
|
|
1992
|
+
nodes,
|
|
1993
|
+
edges: [],
|
|
1994
|
+
nodeTypes: NODE_TYPES,
|
|
1995
|
+
onlyRenderVisibleElements: true,
|
|
1996
|
+
nodesDraggable: false,
|
|
1997
|
+
nodesConnectable: false,
|
|
1998
|
+
elementsSelectable: false,
|
|
1999
|
+
zoomOnDoubleClick: false,
|
|
2000
|
+
panOnScroll: false,
|
|
2001
|
+
zoomOnScroll: false,
|
|
2002
|
+
zoomOnPinch: false,
|
|
2003
|
+
minZoom: MIN_ZOOM,
|
|
2004
|
+
maxZoom: MAX_ZOOM,
|
|
2005
|
+
defaultViewport: { x: 0, y: 0, zoom: 0.1 },
|
|
2006
|
+
onInit: () => {
|
|
2007
|
+
isFlowReadyRef.current = true;
|
|
2008
|
+
fitInitialView();
|
|
2009
|
+
},
|
|
2010
|
+
onMoveStart: cancelLiveBoardsUpdate,
|
|
2011
|
+
onMoveEnd: (_event, viewport) => {
|
|
2012
|
+
cancelLiveBoardsUpdate();
|
|
2013
|
+
liveBoardsTimerRef.current = setTimeout(() => updateLiveBoards(viewport), LIVE_BOARDS_SETTLE_MS);
|
|
2014
|
+
commitViewport(viewport);
|
|
2015
|
+
},
|
|
2016
|
+
onPaneClick: onPaneClickUnlessMarquee,
|
|
2017
|
+
panOnDrag: tool === "hand" ? true : [1, 2],
|
|
2018
|
+
paneClickDistance: CLICK_MAX_MOVE2,
|
|
2019
|
+
selectionOnDrag: false,
|
|
2020
|
+
proOptions: { hideAttribution: true },
|
|
2021
|
+
children: [
|
|
2022
|
+
/* @__PURE__ */ jsx6(Background, { variant: BackgroundVariant.Dots, gap: 32, size: 1.5, color: "var(--tint-strong)" }),
|
|
2023
|
+
/* @__PURE__ */ jsxs6(Panel, { position: "top-left", className: "flex max-w-[calc(100%-32rem)] flex-wrap items-center gap-2", children: [
|
|
2024
|
+
/* @__PURE__ */ jsx6("div", { className: TOOLBAR_GROUP_CLASS, role: "toolbar", "aria-label": "Canvas tools", children: [
|
|
2025
|
+
["hand", Hand, "Pan (H / Esc) \u2014 drag moves the canvas, click selects a board"],
|
|
2026
|
+
["select", MousePointer2, "Select area (V) \u2014 drag a rectangle to select boards, Space + drag pans"]
|
|
2027
|
+
].map(([toolName, Icon, label]) => /* @__PURE__ */ jsxs6(Tooltip, { children: [
|
|
2028
|
+
/* @__PURE__ */ jsx6(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx6(
|
|
2029
|
+
"button",
|
|
2030
|
+
{
|
|
2031
|
+
type: "button",
|
|
2032
|
+
"aria-label": label,
|
|
2033
|
+
"aria-pressed": tool === toolName,
|
|
2034
|
+
onClick: () => onToolChange(toolName),
|
|
2035
|
+
className: cx(TOOL_BUTTON_CLASS, tool === toolName && "bg-brand-light text-brand-emphasis"),
|
|
2036
|
+
children: /* @__PURE__ */ jsx6(Icon, { className: "size-4" })
|
|
2037
|
+
}
|
|
2038
|
+
) }),
|
|
2039
|
+
/* @__PURE__ */ jsx6(TooltipContent, { side: "bottom", children: label })
|
|
2040
|
+
] }, toolName)) }),
|
|
2041
|
+
toolbarStart
|
|
2042
|
+
] }),
|
|
2043
|
+
/* @__PURE__ */ jsx6(Panel, { position: "top-right", children: /* @__PURE__ */ jsxs6("div", { className: TOOLBAR_GROUP_CLASS, children: [
|
|
2044
|
+
toolbarEnd,
|
|
2045
|
+
/* @__PURE__ */ jsxs6(Tooltip, { children: [
|
|
2046
|
+
/* @__PURE__ */ jsx6(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx6(
|
|
2047
|
+
"button",
|
|
2048
|
+
{
|
|
2049
|
+
type: "button",
|
|
2050
|
+
"aria-label": "Present the section in view",
|
|
2051
|
+
onClick: presentCurrentSection,
|
|
2052
|
+
className: TOOL_BUTTON_CLASS,
|
|
2053
|
+
children: /* @__PURE__ */ jsx6(Play, { className: "size-4" })
|
|
2054
|
+
}
|
|
2055
|
+
) }),
|
|
2056
|
+
/* @__PURE__ */ jsx6(TooltipContent, { side: "bottom", children: "Present this section (\u2190 / \u2192)" })
|
|
2057
|
+
] }),
|
|
2058
|
+
/* @__PURE__ */ jsx6(ZoomMenu, { onFitAll: fitAll })
|
|
2059
|
+
] }) }),
|
|
2060
|
+
/* @__PURE__ */ jsx6(Panel, { position: "bottom-left", className: "pointer-events-none", children: /* @__PURE__ */ jsx6("p", { className: "surface-glass-strong rounded-xl px-3 py-1.5 text-xs text-muted-foreground ring-1 ring-foreground/5", children: "Drag to pan \xB7 Scroll or pinch to zoom \xB7 Click selects \xB7 Double-click opens \xB7 + / \u2212 / 0 \xB7 Shift+1 fits all" }) }),
|
|
2061
|
+
!isEverythingVisible && /* @__PURE__ */ jsx6(
|
|
2062
|
+
MiniMap,
|
|
2063
|
+
{
|
|
2064
|
+
pannable: true,
|
|
2065
|
+
zoomable: true,
|
|
2066
|
+
ariaLabel: "Canvas overview: click or drag to move",
|
|
2067
|
+
style: { width: MINIMAP_WIDTH, height: minimapHeight },
|
|
2068
|
+
nodeColor: (node) => node.type === "section" ? "var(--brand-light)" : statusColors?.[node.data.board.status ?? ""] ?? "var(--muted-foreground)",
|
|
2069
|
+
nodeStrokeWidth: 0,
|
|
2070
|
+
nodeBorderRadius: 24,
|
|
2071
|
+
maskColor: "rgb(8 9 72 / 0.12)",
|
|
2072
|
+
maskStrokeColor: "var(--brand)",
|
|
2073
|
+
maskStrokeWidth: 3,
|
|
2074
|
+
onClick: (_event, position) => void reactFlow.setCenter(position.x, position.y, { zoom: reactFlow.getZoom(), duration: 300 }),
|
|
2075
|
+
className: "surface-glass-strong !rounded-xl"
|
|
2076
|
+
}
|
|
2077
|
+
)
|
|
2078
|
+
]
|
|
2079
|
+
}
|
|
2080
|
+
)
|
|
2081
|
+
]
|
|
2082
|
+
}
|
|
2083
|
+
);
|
|
2084
|
+
};
|
|
2085
|
+
var DesignCanvasFlow = (props) => /* @__PURE__ */ jsx6(ReactFlowProvider, { children: /* @__PURE__ */ jsx6(FlowCanvas, { ...props }) });
|
|
2086
|
+
|
|
2087
|
+
// src/canvas/DesignStudioCanvasScreen.tsx
|
|
2088
|
+
import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
2089
|
+
var CANVAS_STATE_KEYS = ["q", "section", "status", "theme", "mode", "vp"];
|
|
2090
|
+
var UNCOUNTED_CANVAS_STATE_KEYS = ["q", "theme", "mode", "vp"];
|
|
2091
|
+
var LIVE_UPDATE_POLL_MS = 15e3;
|
|
2092
|
+
var THUMBNAIL_RENDER_POLL_MS = 3e3;
|
|
2093
|
+
var OPEN_RENDER_STATUSES = /* @__PURE__ */ new Set(["QUEUED", "RUNNING", "WAITING_FOR_RENDERER"]);
|
|
2094
|
+
var MAX_PRIORITY_BOARDS = 200;
|
|
2095
|
+
var LIVE_UPDATE_TOAST_ID = "design-canvas-live-update";
|
|
2096
|
+
var usePageVisible = () => {
|
|
2097
|
+
const [isVisible, setIsVisible] = useState8(true);
|
|
2098
|
+
useEffect6(() => {
|
|
2099
|
+
const update = () => setIsVisible(document.visibilityState === "visible");
|
|
2100
|
+
update();
|
|
2101
|
+
document.addEventListener("visibilitychange", update);
|
|
2102
|
+
return () => document.removeEventListener("visibilitychange", update);
|
|
2103
|
+
}, []);
|
|
2104
|
+
return isVisible;
|
|
2105
|
+
};
|
|
2106
|
+
var BOARD_PARAM = "board";
|
|
2107
|
+
var TOOL_BUTTON_CLASS2 = "relative flex size-8 items-center justify-center rounded-xl text-muted-foreground transition-colors hover:bg-tint hover:text-foreground disabled:pointer-events-none disabled:opacity-40 motion-reduce:transition-none";
|
|
2108
|
+
var CANVAS_TOOLBAR_HEIGHT = 96;
|
|
2109
|
+
var TOOLBAR_GROUP_CLASS2 = "surface-glass-strong flex items-center gap-1 rounded-2xl p-1 ring-1 ring-foreground/5";
|
|
2110
|
+
var NO_SIDEBAR = [true, () => void 0];
|
|
2111
|
+
var useNoSidebar = () => NO_SIDEBAR;
|
|
2112
|
+
var useCollapsedSidebarWhileMounted = (useSidebarCollapsed = useNoSidebar) => {
|
|
2113
|
+
const [isCollapsed, toggleCollapsed] = useSidebarCollapsed();
|
|
2114
|
+
const collapsedByCanvasRef = useRef3(false);
|
|
2115
|
+
const toggleRef = useRef3(toggleCollapsed);
|
|
2116
|
+
toggleRef.current = toggleCollapsed;
|
|
2117
|
+
useEffect6(() => {
|
|
2118
|
+
if (!isCollapsed) {
|
|
2119
|
+
collapsedByCanvasRef.current = true;
|
|
2120
|
+
toggleRef.current();
|
|
2121
|
+
}
|
|
2122
|
+
const restore = () => {
|
|
2123
|
+
if (!collapsedByCanvasRef.current) return;
|
|
2124
|
+
collapsedByCanvasRef.current = false;
|
|
2125
|
+
toggleRef.current();
|
|
2126
|
+
};
|
|
2127
|
+
window.addEventListener("pagehide", restore);
|
|
2128
|
+
return () => {
|
|
2129
|
+
window.removeEventListener("pagehide", restore);
|
|
2130
|
+
restore();
|
|
2131
|
+
};
|
|
2132
|
+
}, []);
|
|
2133
|
+
};
|
|
2134
|
+
var SelectedBoardPanel = ({
|
|
2135
|
+
projectKey,
|
|
2136
|
+
canvasKey,
|
|
2137
|
+
board,
|
|
2138
|
+
statuses,
|
|
2139
|
+
sectionTitle,
|
|
2140
|
+
threads,
|
|
2141
|
+
writesAllowed,
|
|
2142
|
+
onOpen,
|
|
2143
|
+
onStatusChanged,
|
|
2144
|
+
onCopyThreadReference
|
|
2145
|
+
}) => {
|
|
2146
|
+
const { Button } = useDesignStudioComponents();
|
|
2147
|
+
const [showResolved, setShowResolved] = useState8(false);
|
|
2148
|
+
return /* @__PURE__ */ jsxs7("div", { className: "space-y-5", children: [
|
|
2149
|
+
/* @__PURE__ */ jsxs7("div", { className: "space-y-1", children: [
|
|
2150
|
+
/* @__PURE__ */ jsx7("h2", { className: "text-title-card font-semibold break-words", children: board.title }),
|
|
2151
|
+
/* @__PURE__ */ jsxs7("p", { className: "text-xs text-muted-foreground", children: [
|
|
2152
|
+
sectionTitle ? `${sectionTitle} \xB7 ` : "",
|
|
2153
|
+
board.boardKey
|
|
2154
|
+
] })
|
|
2155
|
+
] }),
|
|
2156
|
+
/* @__PURE__ */ jsx7(
|
|
2157
|
+
BoardStatusChips,
|
|
2158
|
+
{
|
|
2159
|
+
projectKey,
|
|
2160
|
+
canvasKey,
|
|
2161
|
+
board,
|
|
2162
|
+
statuses,
|
|
2163
|
+
writesAllowed,
|
|
2164
|
+
onStatusChanged
|
|
2165
|
+
}
|
|
2166
|
+
),
|
|
2167
|
+
/* @__PURE__ */ jsxs7(Button, { variant: "outline", className: "w-full", onClick: onOpen, children: [
|
|
2168
|
+
/* @__PURE__ */ jsx7(Maximize22, {}),
|
|
2169
|
+
" Open focus view"
|
|
2170
|
+
] }),
|
|
2171
|
+
board.contentHash && /* @__PURE__ */ jsxs7("p", { className: "text-xs text-muted-foreground", title: `Content hash of the board file: ${board.contentHash}`, children: [
|
|
2172
|
+
"Version ",
|
|
2173
|
+
/* @__PURE__ */ jsx7("span", { className: "font-mono", children: shortContentHash(board.contentHash) })
|
|
2174
|
+
] }),
|
|
2175
|
+
/* @__PURE__ */ jsx7(
|
|
2176
|
+
BoardComments,
|
|
2177
|
+
{
|
|
2178
|
+
projectKey,
|
|
2179
|
+
canvasKey,
|
|
2180
|
+
board,
|
|
2181
|
+
threads,
|
|
2182
|
+
pendingPin: null,
|
|
2183
|
+
onClearPendingPin: () => void 0,
|
|
2184
|
+
highlightedCommentId: null,
|
|
2185
|
+
onHighlightComment: () => void 0,
|
|
2186
|
+
writesAllowed,
|
|
2187
|
+
showResolved,
|
|
2188
|
+
onShowResolvedChange: setShowResolved,
|
|
2189
|
+
pinHint: "open the focus view to pin it to a spot",
|
|
2190
|
+
onCopyThreadReference
|
|
2191
|
+
}
|
|
2192
|
+
)
|
|
2193
|
+
] });
|
|
2194
|
+
};
|
|
2195
|
+
var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
|
|
2196
|
+
const {
|
|
2197
|
+
api,
|
|
2198
|
+
components,
|
|
2199
|
+
notify,
|
|
2200
|
+
router,
|
|
2201
|
+
shell,
|
|
2202
|
+
statuses: statusDefinitions,
|
|
2203
|
+
storage,
|
|
2204
|
+
useCanWrite
|
|
2205
|
+
} = useDesignStudio();
|
|
2206
|
+
const texts = useDesignStudioTexts();
|
|
2207
|
+
const {
|
|
2208
|
+
Button,
|
|
2209
|
+
Combobox,
|
|
2210
|
+
Popover,
|
|
2211
|
+
PopoverContent,
|
|
2212
|
+
PopoverTrigger,
|
|
2213
|
+
QuickFilterPills,
|
|
2214
|
+
SearchField,
|
|
2215
|
+
Skeleton,
|
|
2216
|
+
StatusCallout,
|
|
2217
|
+
Tooltip,
|
|
2218
|
+
TooltipContent,
|
|
2219
|
+
TooltipTrigger
|
|
2220
|
+
} = components;
|
|
2221
|
+
const searchParams = router.useSearchParams();
|
|
2222
|
+
const writeSearchParams = router.useSearchParamsWriter();
|
|
2223
|
+
const writesAllowed = useCanWrite();
|
|
2224
|
+
const isPageVisible = usePageVisible();
|
|
2225
|
+
const [statusOverrides, setStatusOverrides] = useState8(/* @__PURE__ */ new Map());
|
|
2226
|
+
const [liveBoardIds, setLiveBoardIds] = useState8(/* @__PURE__ */ new Set());
|
|
2227
|
+
const [selectedBoardId, setSelectedBoardId] = useState8(null);
|
|
2228
|
+
const [selectedBoardIds, setSelectedBoardIds] = useState8(/* @__PURE__ */ new Set());
|
|
2229
|
+
const [focusedBoardId, setFocusedBoardId] = useState8(null);
|
|
2230
|
+
const [presentSectionId, setPresentSectionId] = useState8(null);
|
|
2231
|
+
const [fitRequest, setFitRequest] = useState8(null);
|
|
2232
|
+
const [tool, setTool] = useState8("hand");
|
|
2233
|
+
const [isCommentsPanelOpen, setIsCommentsPanelOpen] = useState8(() => storage.read("commentsPanelOpen") !== "0");
|
|
2234
|
+
const canvasState = router.useUrlState(CANVAS_STATE_KEYS, {
|
|
2235
|
+
stateId: `designCanvas.${projectKey}.${canvasKey}`,
|
|
2236
|
+
debounceMs: 250,
|
|
2237
|
+
uncounted: UNCOUNTED_CANVAS_STATE_KEYS
|
|
2238
|
+
});
|
|
2239
|
+
const search = canvasState.values.q;
|
|
2240
|
+
const sectionFilter = canvasState.values.section;
|
|
2241
|
+
const statusFilter = canvasState.values.status;
|
|
2242
|
+
const chosenThemeId = canvasState.values.theme || null;
|
|
2243
|
+
const chosenMode = canvasState.values.mode === "dark" || canvasState.values.mode === "light" ? canvasState.values.mode : null;
|
|
2244
|
+
const { setValue: setCanvasStateValue } = canvasState;
|
|
2245
|
+
const setSearch = useCallback2((value) => setCanvasStateValue("q", value), [setCanvasStateValue]);
|
|
2246
|
+
const setSectionFilter = useCallback2((value) => setCanvasStateValue("section", value), [setCanvasStateValue]);
|
|
2247
|
+
const setStatusFilter = useCallback2((value) => setCanvasStateValue("status", value), [setCanvasStateValue]);
|
|
2248
|
+
const [isFullscreen, setIsFullscreen] = useState8(false);
|
|
2249
|
+
const canvasAreaRef = useRef3(null);
|
|
2250
|
+
const [canvasAspectRatio, setCanvasAspectRatio] = useState8(null);
|
|
2251
|
+
useCollapsedSidebarWhileMounted(shell?.useSidebarCollapsed);
|
|
2252
|
+
const debouncedSearch = canvasState.debounced.q;
|
|
2253
|
+
const [initialViewport] = useState8(() => parseViewportParam(canvasState.values.vp));
|
|
2254
|
+
const [hasInitialFilterWithViewport] = useState8(
|
|
2255
|
+
() => initialViewport !== null && Boolean(canvasState.values.q.trim() || canvasState.values.section || canvasState.values.status)
|
|
2256
|
+
);
|
|
2257
|
+
const currentViewportRef = useRef3(initialViewport ? formatViewportParam(initialViewport) : null);
|
|
2258
|
+
const commitViewport = useCallback2(
|
|
2259
|
+
(viewport) => {
|
|
2260
|
+
const value = formatViewportParam(viewport);
|
|
2261
|
+
currentViewportRef.current = value;
|
|
2262
|
+
setCanvasStateValue("vp", value);
|
|
2263
|
+
},
|
|
2264
|
+
[setCanvasStateValue]
|
|
2265
|
+
);
|
|
2266
|
+
const { data: overviewData, isError: isOverviewError } = api.useOverviewQuery();
|
|
2267
|
+
const overview = overviewData?.designStudioOverview;
|
|
2268
|
+
const projectSummary = overview?.projects?.elements?.find((project) => project.projectKey === projectKey);
|
|
2269
|
+
const canvasSummary = projectSummary?.canvases?.elements?.find((item) => item.canvasKey === canvasKey);
|
|
2270
|
+
const hasThemes = Boolean(overview?.hasThemes);
|
|
2271
|
+
const {
|
|
2272
|
+
data: themesData,
|
|
2273
|
+
isLoading: isLoadingThemes,
|
|
2274
|
+
isError: isThemesError
|
|
2275
|
+
} = api.useThemesQuery({}, { skip: !hasThemes });
|
|
2276
|
+
const themes = useMemo2(() => themesData?.designThemes.elements ?? [], [themesData]);
|
|
2277
|
+
const isDefaultLook = chosenThemeId === null && chosenMode === null;
|
|
2278
|
+
const isLookResolved = isDefaultLook || (overviewData !== void 0 || isOverviewError) && (!hasThemes || themesData !== void 0 || isThemesError);
|
|
2279
|
+
const [loadedReferenceTheme, setLoadedReferenceTheme] = useState8(void 0);
|
|
2280
|
+
const referenceTheme = loadedReferenceTheme !== void 0 ? loadedReferenceTheme : canvasSummary?.referenceTheme;
|
|
2281
|
+
const referenceLook = useMemo2(() => splitThemeReference(referenceTheme), [referenceTheme]);
|
|
2282
|
+
const referenceThemeId = referenceLook?.themeId ?? null;
|
|
2283
|
+
const themeId = chosenThemeId ?? referenceThemeId;
|
|
2284
|
+
const selectedTheme = themes.find((theme) => theme.themeId === themeId);
|
|
2285
|
+
const supportsDark = Boolean(selectedTheme?.supportsDark);
|
|
2286
|
+
const defaultMode = themeId !== null && themeId === referenceThemeId ? referenceLook?.mode ?? "light" : "light";
|
|
2287
|
+
const requestedMode = chosenMode ?? defaultMode;
|
|
2288
|
+
const effectiveMode = requestedMode === "dark" && (isDefaultLook || supportsDark) ? "dark" : "light";
|
|
2289
|
+
const themeArgument = isDefaultLook || themeId === null ? void 0 : buildThemeReference(themeId, effectiveMode);
|
|
2290
|
+
const canvasQueryArgument = useMemo2(
|
|
2291
|
+
() => ({ projectKey, canvasKey, ...themeArgument ? { theme: themeArgument } : {} }),
|
|
2292
|
+
[projectKey, canvasKey, themeArgument]
|
|
2293
|
+
);
|
|
2294
|
+
const [isRenderPolling, setIsRenderPolling] = useState8(false);
|
|
2295
|
+
const {
|
|
2296
|
+
data,
|
|
2297
|
+
currentData: currentCanvasData,
|
|
2298
|
+
isLoading,
|
|
2299
|
+
error,
|
|
2300
|
+
isFetching: isFetchingCanvas,
|
|
2301
|
+
refetch: refetchCanvas
|
|
2302
|
+
} = api.useCanvasQuery(canvasQueryArgument, {
|
|
2303
|
+
skip: !isLookResolved,
|
|
2304
|
+
pollingInterval: isPageVisible && isRenderPolling ? THUMBNAIL_RENDER_POLL_MS : 0
|
|
2305
|
+
});
|
|
2306
|
+
const { data: commentsData, refetch: refetchComments } = api.useCanvasCommentsQuery({ projectKey, canvasKey });
|
|
2307
|
+
const { currentData: currentRevisionData, refetch: refetchRevision } = api.useCanvasRevisionQuery(
|
|
2308
|
+
canvasQueryArgument,
|
|
2309
|
+
{
|
|
2310
|
+
skip: !isLookResolved,
|
|
2311
|
+
pollingInterval: isPageVisible ? LIVE_UPDATE_POLL_MS : 0
|
|
2312
|
+
}
|
|
2313
|
+
);
|
|
2314
|
+
const canvas = data?.designStudioCanvasView;
|
|
2315
|
+
const currentCanvas = currentCanvasData?.designStudioCanvasView;
|
|
2316
|
+
if (canvas && (canvas.referenceTheme ?? null) !== loadedReferenceTheme) {
|
|
2317
|
+
setLoadedReferenceTheme(canvas.referenceTheme ?? null);
|
|
2318
|
+
}
|
|
2319
|
+
const shownLook = useMemo2(() => splitThemeReference(canvas?.themeReference), [canvas?.themeReference]);
|
|
2320
|
+
const sections = useMemo2(() => canvas?.sections?.elements ?? [], [canvas]);
|
|
2321
|
+
const statuses = useMemo2(() => canvas?.statuses ?? overview?.statuses ?? [], [canvas?.statuses, overview?.statuses]);
|
|
2322
|
+
const defaultStatus = statuses[0] ?? null;
|
|
2323
|
+
const statusFilterOptions = useMemo2(
|
|
2324
|
+
() => statuses.map((status) => ({ value: status, label: boardStatusLabel(statusDefinitions, status) })),
|
|
2325
|
+
[statuses, statusDefinitions]
|
|
2326
|
+
);
|
|
2327
|
+
const canvasBoards = canvas?.boards?.elements;
|
|
2328
|
+
const [shownBoards, setShownBoards] = useState8({
|
|
2329
|
+
source: void 0,
|
|
2330
|
+
themeReference: "",
|
|
2331
|
+
boards: [],
|
|
2332
|
+
urlsAdoptedAt: 0,
|
|
2333
|
+
changedBoardKeys: [],
|
|
2334
|
+
serial: 0
|
|
2335
|
+
});
|
|
2336
|
+
if (canvasBoards && canvasBoards !== shownBoards.source) {
|
|
2337
|
+
const now = Date.now();
|
|
2338
|
+
const themeReference = canvas?.themeReference ?? "";
|
|
2339
|
+
const isFirstLoad = shownBoards.source === void 0 || themeReference !== shownBoards.themeReference;
|
|
2340
|
+
const shownTokenUrl = shownBoards.boards.find((board) => board.htmlUrl)?.htmlUrl;
|
|
2341
|
+
const keepPreviousUrls = !isFirstLoad && (!shownTokenUrl || !isContentUrlExpiring(shownTokenUrl));
|
|
2342
|
+
const merged = mergeRefetchedBoards(isFirstLoad ? null : shownBoards.boards, canvasBoards, keepPreviousUrls);
|
|
2343
|
+
setShownBoards({
|
|
2344
|
+
source: canvasBoards,
|
|
2345
|
+
themeReference,
|
|
2346
|
+
boards: merged.boards,
|
|
2347
|
+
urlsAdoptedAt: keepPreviousUrls ? shownBoards.urlsAdoptedAt : now,
|
|
2348
|
+
changedBoardKeys: merged.changedBoardKeys,
|
|
2349
|
+
serial: shownBoards.serial + 1
|
|
2350
|
+
});
|
|
2351
|
+
}
|
|
2352
|
+
const shownBoardList = shownBoards.boards;
|
|
2353
|
+
const boards = useMemo2(
|
|
2354
|
+
() => shownBoardList.map((board) => {
|
|
2355
|
+
const status = statusOverrides.get(boardNodeId(board.boardKey ?? ""));
|
|
2356
|
+
return status ? { ...board, status } : board;
|
|
2357
|
+
}),
|
|
2358
|
+
[shownBoardList, statusOverrides]
|
|
2359
|
+
);
|
|
2360
|
+
const boardsByNodeId = useMemo2(
|
|
2361
|
+
() => new Map(boards.map((board) => [boardNodeId(board.boardKey ?? ""), board])),
|
|
2362
|
+
[boards]
|
|
2363
|
+
);
|
|
2364
|
+
const sectionTitleByKey = useMemo2(
|
|
2365
|
+
() => new Map(sections.map((section) => [section.sectionKey ?? "", section.title ?? ""])),
|
|
2366
|
+
[sections]
|
|
2367
|
+
);
|
|
2368
|
+
const layout = useMemo2(() => {
|
|
2369
|
+
const sectionKeys = new Set(sections.map((section) => section.sectionKey ?? ""));
|
|
2370
|
+
return computeCanvasLayout(
|
|
2371
|
+
sections.map((section) => ({
|
|
2372
|
+
id: section.sectionKey ?? "",
|
|
2373
|
+
title: section.title ?? "",
|
|
2374
|
+
displayOrder: section.displayOrder ?? 0
|
|
2375
|
+
})),
|
|
2376
|
+
shownBoardList.map((board) => ({
|
|
2377
|
+
id: boardNodeId(board.boardKey ?? ""),
|
|
2378
|
+
sectionId: board.sectionKey && sectionKeys.has(board.sectionKey) ? board.sectionKey : null,
|
|
2379
|
+
width: board.width ?? 390,
|
|
2380
|
+
height: board.height ?? 844,
|
|
2381
|
+
displayOrder: board.displayOrder ?? 0
|
|
2382
|
+
})),
|
|
2383
|
+
canvasAspectRatio ?? void 0
|
|
2384
|
+
);
|
|
2385
|
+
}, [sections, shownBoardList, canvasAspectRatio]);
|
|
2386
|
+
const hasCanvas = Boolean(canvas);
|
|
2387
|
+
useEffect6(() => {
|
|
2388
|
+
const canvasArea = canvasAreaRef.current;
|
|
2389
|
+
if (!canvasArea) return;
|
|
2390
|
+
const measure = () => {
|
|
2391
|
+
if (canvasArea.clientWidth === 0 || canvasArea.clientHeight === 0) return;
|
|
2392
|
+
const aspectRatio = canvasArea.clientWidth / Math.max(1, canvasArea.clientHeight - CANVAS_TOOLBAR_HEIGHT);
|
|
2393
|
+
setCanvasAspectRatio(
|
|
2394
|
+
(current) => current === null || Math.abs(aspectRatio / current - 1) > 0.15 ? Math.round(aspectRatio * 10) / 10 : current
|
|
2395
|
+
);
|
|
2396
|
+
};
|
|
2397
|
+
measure();
|
|
2398
|
+
const resizeObserver = new ResizeObserver(measure);
|
|
2399
|
+
resizeObserver.observe(canvasArea);
|
|
2400
|
+
return () => resizeObserver.disconnect();
|
|
2401
|
+
}, [hasCanvas]);
|
|
2402
|
+
const isRendererEnabled = Boolean(canvas?.isRendererEnabled);
|
|
2403
|
+
const missingThumbnailCount = canvas?.missingThumbnailCount ?? 0;
|
|
2404
|
+
const renderStatus = canvas?.renderRequestStatus ?? null;
|
|
2405
|
+
const isRenderOpen = renderStatus !== null && OPEN_RENDER_STATUSES.has(renderStatus);
|
|
2406
|
+
useEffect6(() => setIsRenderPolling(isRenderOpen), [isRenderOpen]);
|
|
2407
|
+
const [requestThumbnailRendering] = api.useRequestThumbnailRenderingMutation();
|
|
2408
|
+
const visibleBoardIdsRef = useRef3([]);
|
|
2409
|
+
const rememberVisibleBoardIds = useCallback2((visibleBoardIds) => {
|
|
2410
|
+
visibleBoardIdsRef.current = visibleBoardIds;
|
|
2411
|
+
}, []);
|
|
2412
|
+
const boardsByNodeIdRef = useRef3(boardsByNodeId);
|
|
2413
|
+
boardsByNodeIdRef.current = boardsByNodeId;
|
|
2414
|
+
const requestedThumbnailsRef = useRef3(/* @__PURE__ */ new Set());
|
|
2415
|
+
const fileRenderRequest = useCallback2(
|
|
2416
|
+
(isRetry) => {
|
|
2417
|
+
if (!writesAllowed || !currentCanvas) return;
|
|
2418
|
+
const missingKeys = (currentCanvas.boards?.elements ?? []).filter((board) => !board.thumbnailUrl).map((board) => `${themeArgument ?? ""}|${board.boardKey ?? ""}@${board.contentHash ?? ""}`);
|
|
2419
|
+
if (missingKeys.length === 0) return;
|
|
2420
|
+
if (!isRetry && missingKeys.every((key) => requestedThumbnailsRef.current.has(key))) return;
|
|
2421
|
+
for (const key of missingKeys) requestedThumbnailsRef.current.add(key);
|
|
2422
|
+
const priorityBoardKeys = visibleBoardIdsRef.current.map((nodeId) => boardsByNodeIdRef.current.get(nodeId)?.boardKey).filter((boardKey) => Boolean(boardKey)).slice(0, MAX_PRIORITY_BOARDS);
|
|
2423
|
+
void requestThumbnailRendering({
|
|
2424
|
+
projectKey,
|
|
2425
|
+
canvasKey,
|
|
2426
|
+
...themeArgument ? { theme: themeArgument } : {},
|
|
2427
|
+
body: {
|
|
2428
|
+
theme: themeArgument ?? null,
|
|
2429
|
+
priorityBoardKeys
|
|
2430
|
+
}
|
|
2431
|
+
});
|
|
2432
|
+
},
|
|
2433
|
+
[writesAllowed, currentCanvas, themeArgument, projectKey, canvasKey, requestThumbnailRendering]
|
|
2434
|
+
);
|
|
2435
|
+
useEffect6(() => {
|
|
2436
|
+
if (!currentCanvas?.isRendererEnabled || !currentCanvas.missingThumbnailCount) return;
|
|
2437
|
+
const currentStatus = currentCanvas.renderRequestStatus ?? null;
|
|
2438
|
+
if (currentStatus === "FAILED" || currentStatus !== null && OPEN_RENDER_STATUSES.has(currentStatus)) return;
|
|
2439
|
+
fileRenderRequest(false);
|
|
2440
|
+
}, [currentCanvas, fileRenderRequest]);
|
|
2441
|
+
const themeOptions = useMemo2(
|
|
2442
|
+
() => [
|
|
2443
|
+
// without a reference theme the default look is the boards as authored
|
|
2444
|
+
...referenceThemeId === null ? [{ value: "", label: "As authored" }] : [],
|
|
2445
|
+
...themes.map((theme) => ({ value: theme.themeId ?? "", label: theme.label || theme.themeId || "Theme" }))
|
|
2446
|
+
],
|
|
2447
|
+
[themes, referenceThemeId]
|
|
2448
|
+
);
|
|
2449
|
+
const shownThemeLabel = themes.find((theme) => theme.themeId === shownLook?.themeId)?.label ?? texts.thumbnailsFallbackThemeLabel;
|
|
2450
|
+
const commentsByBoardNodeId = useMemo2(() => {
|
|
2451
|
+
const comments = /* @__PURE__ */ new Map();
|
|
2452
|
+
for (const comment of commentsData?.designStudioComments.elements ?? []) {
|
|
2453
|
+
const nodeId = boardNodeId(comment.boardKey ?? "");
|
|
2454
|
+
const boardComments = comments.get(nodeId) ?? [];
|
|
2455
|
+
boardComments.push(comment);
|
|
2456
|
+
comments.set(nodeId, boardComments);
|
|
2457
|
+
}
|
|
2458
|
+
return comments;
|
|
2459
|
+
}, [commentsData]);
|
|
2460
|
+
const openThreadCounts = useMemo2(() => {
|
|
2461
|
+
const counts = /* @__PURE__ */ new Map();
|
|
2462
|
+
for (const [nodeId, comments] of commentsByBoardNodeId) {
|
|
2463
|
+
const openCount = comments.filter(
|
|
2464
|
+
(comment) => comment.parentDesignStudioCommentId == null && !comment.isResolved
|
|
2465
|
+
).length;
|
|
2466
|
+
if (openCount > 0) counts.set(nodeId, openCount);
|
|
2467
|
+
}
|
|
2468
|
+
return counts;
|
|
2469
|
+
}, [commentsByBoardNodeId]);
|
|
2470
|
+
const openThreadTotal = useMemo2(
|
|
2471
|
+
() => [...openThreadCounts.values()].reduce((sum, count) => sum + count, 0),
|
|
2472
|
+
[openThreadCounts]
|
|
2473
|
+
);
|
|
2474
|
+
const matchingBoardIds = useMemo2(() => {
|
|
2475
|
+
const searchText = debouncedSearch.trim().toLowerCase();
|
|
2476
|
+
if (!searchText && !sectionFilter && !statusFilter) return null;
|
|
2477
|
+
const matching = /* @__PURE__ */ new Set();
|
|
2478
|
+
for (const board of boards) {
|
|
2479
|
+
if (sectionFilter && (board.sectionKey ?? "") !== sectionFilter) continue;
|
|
2480
|
+
if (statusFilter && board.status !== statusFilter) continue;
|
|
2481
|
+
if (searchText && !(board.title ?? "").toLowerCase().includes(searchText) && !(board.boardKey ?? "").toLowerCase().includes(searchText)) {
|
|
2482
|
+
continue;
|
|
2483
|
+
}
|
|
2484
|
+
matching.add(boardNodeId(board.boardKey ?? ""));
|
|
2485
|
+
}
|
|
2486
|
+
return matching;
|
|
2487
|
+
}, [boards, debouncedSearch, sectionFilter, statusFilter]);
|
|
2488
|
+
const layoutOrder = useMemo2(() => layout.sections.flatMap((section) => section.boardIds), [layout]);
|
|
2489
|
+
const navigationOrder = useMemo2(() => {
|
|
2490
|
+
if (presentSectionId) {
|
|
2491
|
+
return layout.sections.find((section) => section.id === presentSectionId)?.boardIds ?? [];
|
|
2492
|
+
}
|
|
2493
|
+
return layoutOrder.filter((nodeId) => matchingBoardIds === null || matchingBoardIds.has(nodeId));
|
|
2494
|
+
}, [layout, layoutOrder, matchingBoardIds, presentSectionId]);
|
|
2495
|
+
const fitKeyRef = useRef3(0);
|
|
2496
|
+
const requestFit = useCallback2((nodeIds) => {
|
|
2497
|
+
fitKeyRef.current += 1;
|
|
2498
|
+
setFitRequest({ nodeIds, key: fitKeyRef.current });
|
|
2499
|
+
}, []);
|
|
2500
|
+
const filterKey = matchingBoardIds === null ? null : `${debouncedSearch.trim()}|${sectionFilter}|${statusFilter}`;
|
|
2501
|
+
const fittedFilterKeyRef = useRef3(null);
|
|
2502
|
+
const skipInitialFilterFitRef = useRef3(hasInitialFilterWithViewport);
|
|
2503
|
+
useEffect6(() => {
|
|
2504
|
+
if (filterKey === null || matchingBoardIds === null) {
|
|
2505
|
+
fittedFilterKeyRef.current = null;
|
|
2506
|
+
return;
|
|
2507
|
+
}
|
|
2508
|
+
if (matchingBoardIds.size === 0 || fittedFilterKeyRef.current === filterKey) return;
|
|
2509
|
+
fittedFilterKeyRef.current = filterKey;
|
|
2510
|
+
if (skipInitialFilterFitRef.current) {
|
|
2511
|
+
skipInitialFilterFitRef.current = false;
|
|
2512
|
+
return;
|
|
2513
|
+
}
|
|
2514
|
+
requestFit(
|
|
2515
|
+
sectionFilter && !debouncedSearch.trim() && !statusFilter ? [sectionNodeId(sectionFilter)] : [...matchingBoardIds]
|
|
2516
|
+
);
|
|
2517
|
+
}, [filterKey, matchingBoardIds, sectionFilter, debouncedSearch, statusFilter, requestFit]);
|
|
2518
|
+
const openBoard = useCallback2(
|
|
2519
|
+
(nodeId) => {
|
|
2520
|
+
setSelectedBoardId(nodeId);
|
|
2521
|
+
setFocusedBoardId(nodeId);
|
|
2522
|
+
const board = boardsByNodeId.get(nodeId);
|
|
2523
|
+
if (board?.boardKey) writeSearchParams({ [BOARD_PARAM]: board.boardKey });
|
|
2524
|
+
},
|
|
2525
|
+
[boardsByNodeId, writeSearchParams]
|
|
2526
|
+
);
|
|
2527
|
+
const openBoardFromCanvas = useCallback2(
|
|
2528
|
+
(nodeId) => {
|
|
2529
|
+
setPresentSectionId(null);
|
|
2530
|
+
openBoard(nodeId);
|
|
2531
|
+
},
|
|
2532
|
+
[openBoard]
|
|
2533
|
+
);
|
|
2534
|
+
const closeFocus = useCallback2(() => {
|
|
2535
|
+
setFocusedBoardId(null);
|
|
2536
|
+
setPresentSectionId(null);
|
|
2537
|
+
writeSearchParams({ [BOARD_PARAM]: null });
|
|
2538
|
+
}, [writeSearchParams]);
|
|
2539
|
+
const presentSection = useCallback2(
|
|
2540
|
+
(sectionId) => {
|
|
2541
|
+
const firstBoardId = layout.sections.find((section) => section.id === sectionId)?.boardIds[0];
|
|
2542
|
+
if (!firstBoardId) return;
|
|
2543
|
+
setPresentSectionId(sectionId);
|
|
2544
|
+
openBoard(firstBoardId);
|
|
2545
|
+
},
|
|
2546
|
+
[layout, openBoard]
|
|
2547
|
+
);
|
|
2548
|
+
const boardParam = searchParams.get(BOARD_PARAM);
|
|
2549
|
+
const isDeepLinkHandledRef = useRef3(false);
|
|
2550
|
+
useEffect6(() => {
|
|
2551
|
+
if (isDeepLinkHandledRef.current || !boardParam || boards.length === 0) return;
|
|
2552
|
+
isDeepLinkHandledRef.current = true;
|
|
2553
|
+
const nodeId = boardNodeId(boardParam);
|
|
2554
|
+
if (!boardsByNodeId.has(nodeId)) return;
|
|
2555
|
+
setSelectedBoardId(nodeId);
|
|
2556
|
+
setFocusedBoardId(nodeId);
|
|
2557
|
+
if (!initialViewport) requestFit([nodeId]);
|
|
2558
|
+
}, [boardParam, boards.length, boardsByNodeId, requestFit, initialViewport]);
|
|
2559
|
+
const stepFocus = useCallback2(
|
|
2560
|
+
(step) => {
|
|
2561
|
+
if (!focusedBoardId || navigationOrder.length === 0) return;
|
|
2562
|
+
const index = navigationOrder.indexOf(focusedBoardId);
|
|
2563
|
+
openBoard(navigationOrder[(index + step + navigationOrder.length) % navigationOrder.length]);
|
|
2564
|
+
},
|
|
2565
|
+
[focusedBoardId, navigationOrder, openBoard]
|
|
2566
|
+
);
|
|
2567
|
+
const setBoardStatus = useCallback2((nodeId, status) => {
|
|
2568
|
+
setStatusOverrides((overrides) => new Map(overrides).set(nodeId, status));
|
|
2569
|
+
}, []);
|
|
2570
|
+
const toggleCommentsPanel = () => {
|
|
2571
|
+
setIsCommentsPanelOpen((isOpen) => {
|
|
2572
|
+
storage.write("commentsPanelOpen", isOpen ? "0" : "1");
|
|
2573
|
+
return !isOpen;
|
|
2574
|
+
});
|
|
2575
|
+
};
|
|
2576
|
+
const selectBoard = useCallback2((nodeId, isAdditive) => {
|
|
2577
|
+
setSelectedBoardId(nodeId);
|
|
2578
|
+
setSelectedBoardIds((current) => {
|
|
2579
|
+
if (!isAdditive) return /* @__PURE__ */ new Set([nodeId]);
|
|
2580
|
+
const next = new Set(current);
|
|
2581
|
+
if (next.has(nodeId)) next.delete(nodeId);
|
|
2582
|
+
else next.add(nodeId);
|
|
2583
|
+
return next;
|
|
2584
|
+
});
|
|
2585
|
+
}, []);
|
|
2586
|
+
const selectBoards = useCallback2((nodeIds, isAdditive) => {
|
|
2587
|
+
setSelectedBoardIds((current) => /* @__PURE__ */ new Set([...isAdditive ? current : [], ...nodeIds]));
|
|
2588
|
+
setSelectedBoardId(nodeIds[0] ?? null);
|
|
2589
|
+
}, []);
|
|
2590
|
+
const clearSelection = useCallback2(() => {
|
|
2591
|
+
setSelectedBoardId(null);
|
|
2592
|
+
setSelectedBoardIds(/* @__PURE__ */ new Set());
|
|
2593
|
+
}, []);
|
|
2594
|
+
const projectName = projectSummary?.label ?? projectKey;
|
|
2595
|
+
const canvasName = canvas?.label ?? canvasSummary?.label ?? canvasKey;
|
|
2596
|
+
const shownThemeReference = canvas?.themeReference ?? null;
|
|
2597
|
+
const buildReferenceFor = useCallback2(
|
|
2598
|
+
(nodeId, extra = {}) => {
|
|
2599
|
+
const board = boardsByNodeId.get(nodeId);
|
|
2600
|
+
if (!board?.boardKey || typeof window === "undefined") return null;
|
|
2601
|
+
return buildDesignReference({
|
|
2602
|
+
projectName,
|
|
2603
|
+
canvasName,
|
|
2604
|
+
projectKey,
|
|
2605
|
+
canvasKey,
|
|
2606
|
+
boardTitle: board.title ?? board.boardKey,
|
|
2607
|
+
boardKey: board.boardKey,
|
|
2608
|
+
contentHash: board.contentHash ?? null,
|
|
2609
|
+
themeReference: shownThemeReference,
|
|
2610
|
+
url: buildBoardDeepLink(
|
|
2611
|
+
window.location.href,
|
|
2612
|
+
board.boardKey,
|
|
2613
|
+
shownLook?.themeId ?? null,
|
|
2614
|
+
shownLook?.mode ?? "light",
|
|
2615
|
+
currentViewportRef.current
|
|
2616
|
+
),
|
|
2617
|
+
...extra
|
|
2618
|
+
});
|
|
2619
|
+
},
|
|
2620
|
+
[boardsByNodeId, projectName, canvasName, projectKey, canvasKey, shownThemeReference, shownLook]
|
|
2621
|
+
);
|
|
2622
|
+
const copyReferences = useCallback2(async (blocks) => {
|
|
2623
|
+
const text = blocks.filter((block) => block !== null).join("\n\n");
|
|
2624
|
+
if (!text) return;
|
|
2625
|
+
if (await copyTextToClipboard(text)) {
|
|
2626
|
+
notify.success(texts.referencesCopied(blocks.length));
|
|
2627
|
+
} else {
|
|
2628
|
+
notify.error("Could not copy to the clipboard");
|
|
2629
|
+
}
|
|
2630
|
+
}, [notify, texts]);
|
|
2631
|
+
const copySelectedReferences = useCallback2(() => {
|
|
2632
|
+
const nodeIds = layoutOrder.filter((nodeId) => selectedBoardIds.has(nodeId));
|
|
2633
|
+
void copyReferences(nodeIds.map((nodeId) => buildReferenceFor(nodeId)));
|
|
2634
|
+
}, [layoutOrder, selectedBoardIds, copyReferences, buildReferenceFor]);
|
|
2635
|
+
const copyThreadReference = useCallback2(
|
|
2636
|
+
(thread) => void copyReferences([
|
|
2637
|
+
buildReferenceFor(boardNodeId(thread.root.boardKey ?? ""), {
|
|
2638
|
+
comment: {
|
|
2639
|
+
id: thread.root.id ?? "",
|
|
2640
|
+
x: thread.root.x ?? null,
|
|
2641
|
+
y: thread.root.y ?? null,
|
|
2642
|
+
lines: [thread.root, ...thread.replies].map((comment) => `${comment.authorName ?? "Unknown"}: ${comment.text ?? ""}`)
|
|
2643
|
+
}
|
|
2644
|
+
})
|
|
2645
|
+
]),
|
|
2646
|
+
[copyReferences, buildReferenceFor]
|
|
2647
|
+
);
|
|
2648
|
+
const seenRevisionRef = useRef3(null);
|
|
2649
|
+
const revision = currentRevisionData?.revision;
|
|
2650
|
+
const revisionLook = themeArgument ?? "";
|
|
2651
|
+
useEffect6(() => {
|
|
2652
|
+
if (!revision) return;
|
|
2653
|
+
const seen = seenRevisionRef.current;
|
|
2654
|
+
seenRevisionRef.current = { look: revisionLook, revision };
|
|
2655
|
+
if (!seen || seen.look !== revisionLook || seen.revision === revision) return;
|
|
2656
|
+
void refetchCanvas();
|
|
2657
|
+
void refetchComments();
|
|
2658
|
+
}, [revision, revisionLook, refetchCanvas, refetchComments]);
|
|
2659
|
+
useEffect6(() => {
|
|
2660
|
+
if (isPageVisible && seenRevisionRef.current) void refetchRevision();
|
|
2661
|
+
}, [isPageVisible, refetchRevision]);
|
|
2662
|
+
const showBoard = useCallback2(
|
|
2663
|
+
(nodeId) => {
|
|
2664
|
+
setSelectedBoardId(nodeId);
|
|
2665
|
+
setSelectedBoardIds(/* @__PURE__ */ new Set([nodeId]));
|
|
2666
|
+
requestFit([nodeId]);
|
|
2667
|
+
},
|
|
2668
|
+
[requestFit]
|
|
2669
|
+
);
|
|
2670
|
+
const layoutOrderRef = useRef3(layoutOrder);
|
|
2671
|
+
layoutOrderRef.current = layoutOrder;
|
|
2672
|
+
useEffect6(() => {
|
|
2673
|
+
const changedBoardKeys = shownBoards.changedBoardKeys;
|
|
2674
|
+
if (changedBoardKeys.length === 0) return;
|
|
2675
|
+
const changedNodeIds = new Set(changedBoardKeys.map((boardKey) => boardNodeId(boardKey)));
|
|
2676
|
+
const firstNodeId = layoutOrderRef.current.find((nodeId) => changedNodeIds.has(nodeId)) ?? boardNodeId(changedBoardKeys[0]);
|
|
2677
|
+
notify.info(texts.boardsUpdated(changedBoardKeys.length), {
|
|
2678
|
+
id: LIVE_UPDATE_TOAST_ID,
|
|
2679
|
+
action: { label: texts.showUpdatedBoard, onClick: () => showBoard(firstNodeId) }
|
|
2680
|
+
});
|
|
2681
|
+
}, [shownBoards.serial]);
|
|
2682
|
+
const shownBoardsRef = useRef3(shownBoards);
|
|
2683
|
+
shownBoardsRef.current = shownBoards;
|
|
2684
|
+
const reloadCanvas = useCallback2(async () => {
|
|
2685
|
+
if (shownBoardsRef.current.source === void 0) return;
|
|
2686
|
+
const serialBefore = shownBoardsRef.current.serial;
|
|
2687
|
+
const [canvasResult] = await Promise.all([refetchCanvas(), refetchComments(), refetchRevision()]);
|
|
2688
|
+
const reloadedBoards = canvasResult.data?.designStudioCanvasView.boards?.elements;
|
|
2689
|
+
const shown = shownBoardsRef.current;
|
|
2690
|
+
if (!reloadedBoards || shown.serial !== serialBefore && shown.changedBoardKeys.length > 0) return;
|
|
2691
|
+
if (mergeRefetchedBoards(shown.boards, reloadedBoards, true).changedBoardKeys.length === 0) {
|
|
2692
|
+
notify.info(texts.canvasUpToDate, { id: LIVE_UPDATE_TOAST_ID });
|
|
2693
|
+
}
|
|
2694
|
+
}, [refetchCanvas, refetchComments, refetchRevision, notify, texts]);
|
|
2695
|
+
const reloadCanvasRef = useRef3(reloadCanvas);
|
|
2696
|
+
reloadCanvasRef.current = reloadCanvas;
|
|
2697
|
+
const canvasView = useMemo2(
|
|
2698
|
+
() => ({
|
|
2699
|
+
liveBoardIds,
|
|
2700
|
+
selectedBoardId,
|
|
2701
|
+
selectedBoardIds,
|
|
2702
|
+
matchingBoardIds,
|
|
2703
|
+
openThreadCounts,
|
|
2704
|
+
defaultStatus,
|
|
2705
|
+
isHandTool: tool === "hand",
|
|
2706
|
+
onSelectBoard: selectBoard,
|
|
2707
|
+
onCopyReference: (nodeId) => void copyReferences([buildReferenceFor(nodeId)]),
|
|
2708
|
+
onOpenBoard: openBoardFromCanvas,
|
|
2709
|
+
onZoomToSection: (sectionId) => requestFit([sectionNodeId(sectionId)])
|
|
2710
|
+
}),
|
|
2711
|
+
[
|
|
2712
|
+
liveBoardIds,
|
|
2713
|
+
selectedBoardId,
|
|
2714
|
+
selectedBoardIds,
|
|
2715
|
+
matchingBoardIds,
|
|
2716
|
+
openThreadCounts,
|
|
2717
|
+
defaultStatus,
|
|
2718
|
+
tool,
|
|
2719
|
+
selectBoard,
|
|
2720
|
+
copyReferences,
|
|
2721
|
+
buildReferenceFor,
|
|
2722
|
+
openBoardFromCanvas,
|
|
2723
|
+
requestFit
|
|
2724
|
+
]
|
|
2725
|
+
);
|
|
2726
|
+
const selectedBoard = selectedBoardId ? boardsByNodeId.get(selectedBoardId) ?? null : null;
|
|
2727
|
+
const focusedBoard = focusedBoardId ? boardsByNodeId.get(focusedBoardId) ?? null : null;
|
|
2728
|
+
const threadsOf = (nodeId) => nodeId ? buildCommentThreads(commentsByBoardNodeId.get(nodeId) ?? []) : [];
|
|
2729
|
+
const boardsWithOpenThreads = layoutOrder.filter((nodeId) => openThreadCounts.has(nodeId));
|
|
2730
|
+
const initialFitNodeIds = useMemo2(
|
|
2731
|
+
() => layout.sections[0] ? [sectionNodeId(layout.sections[0].id)] : [],
|
|
2732
|
+
[layout]
|
|
2733
|
+
);
|
|
2734
|
+
const sectionOptions = layout.sections.map((section) => ({ value: section.id, label: section.title }));
|
|
2735
|
+
const presentedSectionTitle = presentSectionId ? layout.sections.find((section) => section.id === presentSectionId)?.title ?? null : null;
|
|
2736
|
+
const copySelectedRef = useRef3(copySelectedReferences);
|
|
2737
|
+
copySelectedRef.current = copySelectedReferences;
|
|
2738
|
+
useEffect6(() => {
|
|
2739
|
+
const onKeyDown = (event) => {
|
|
2740
|
+
const target = event.target;
|
|
2741
|
+
if (target && (target.tagName === "TEXTAREA" || target.tagName === "INPUT" || target.isContentEditable)) return;
|
|
2742
|
+
if (document.querySelector("[role=dialog]") || event.metaKey || event.ctrlKey || event.altKey) return;
|
|
2743
|
+
if (event.key === "f" || event.key === "F") setIsFullscreen((value) => !value);
|
|
2744
|
+
else if (event.key === "c" || event.key === "C") copySelectedRef.current();
|
|
2745
|
+
else if (event.key === "r" || event.key === "R") void reloadCanvasRef.current();
|
|
2746
|
+
else if (event.key === "Escape") setIsFullscreen(false);
|
|
2747
|
+
};
|
|
2748
|
+
window.addEventListener("keydown", onKeyDown);
|
|
2749
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
2750
|
+
}, []);
|
|
2751
|
+
const activeFilterCount = (sectionFilter ? 1 : 0) + (statusFilter ? 1 : 0);
|
|
2752
|
+
const toolbarStart = /* @__PURE__ */ jsxs7("div", { className: cx(TOOLBAR_GROUP_CLASS2, "min-w-0 pl-3"), children: [
|
|
2753
|
+
/* @__PURE__ */ jsxs7("div", { className: "min-w-0 pr-1", children: [
|
|
2754
|
+
/* @__PURE__ */ jsx7("h1", { className: "max-w-72 truncate text-sm leading-tight font-semibold", title: canvasName, children: canvasName }),
|
|
2755
|
+
/* @__PURE__ */ jsxs7("p", { className: "text-xs leading-tight text-muted-foreground", children: [
|
|
2756
|
+
boards.length,
|
|
2757
|
+
" boards \xB7 ",
|
|
2758
|
+
layout.sections.length,
|
|
2759
|
+
" sections",
|
|
2760
|
+
matchingBoardIds !== null ? ` \xB7 ${matchingBoardIds.size} matching` : ""
|
|
2761
|
+
] })
|
|
2762
|
+
] }),
|
|
2763
|
+
/* @__PURE__ */ jsx7(
|
|
2764
|
+
SearchField,
|
|
2765
|
+
{
|
|
2766
|
+
size: "sm",
|
|
2767
|
+
value: search,
|
|
2768
|
+
onChange: setSearch,
|
|
2769
|
+
clearable: true,
|
|
2770
|
+
placeholder: "Search boards\u2026",
|
|
2771
|
+
"aria-label": "Search boards",
|
|
2772
|
+
className: "w-44"
|
|
2773
|
+
}
|
|
2774
|
+
),
|
|
2775
|
+
/* @__PURE__ */ jsxs7(Popover, { children: [
|
|
2776
|
+
/* @__PURE__ */ jsx7(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs7("button", { type: "button", className: cx(TOOL_BUTTON_CLASS2, activeFilterCount > 0 && "text-brand-emphasis"), "aria-label": "Filters", children: [
|
|
2777
|
+
/* @__PURE__ */ jsx7(ListFilter, { className: "size-4" }),
|
|
2778
|
+
activeFilterCount > 0 && /* @__PURE__ */ jsx7("span", { className: "absolute -top-1 -right-1 flex size-4 items-center justify-center rounded-full bg-primary text-[10px] font-bold text-primary-foreground", children: activeFilterCount })
|
|
2779
|
+
] }) }),
|
|
2780
|
+
/* @__PURE__ */ jsxs7(PopoverContent, { align: "start", className: "w-[22rem] space-y-4 p-4", children: [
|
|
2781
|
+
/* @__PURE__ */ jsxs7("div", { className: "space-y-1.5", children: [
|
|
2782
|
+
/* @__PURE__ */ jsx7("p", { className: "text-[12.5px] font-bold text-muted-foreground", children: "Section" }),
|
|
2783
|
+
/* @__PURE__ */ jsx7(
|
|
2784
|
+
Combobox,
|
|
2785
|
+
{
|
|
2786
|
+
size: "sm",
|
|
2787
|
+
options: [{ value: "", label: "All sections" }, ...sectionOptions],
|
|
2788
|
+
value: sectionFilter,
|
|
2789
|
+
onChange: setSectionFilter,
|
|
2790
|
+
placeholder: "All sections",
|
|
2791
|
+
searchPlaceholder: "Search sections\u2026",
|
|
2792
|
+
"aria-label": "Section",
|
|
2793
|
+
className: "w-full"
|
|
2794
|
+
}
|
|
2795
|
+
)
|
|
2796
|
+
] }),
|
|
2797
|
+
/* @__PURE__ */ jsxs7("div", { className: "space-y-1.5", children: [
|
|
2798
|
+
/* @__PURE__ */ jsx7("p", { className: "text-[12.5px] font-bold text-muted-foreground", children: "Status" }),
|
|
2799
|
+
/* @__PURE__ */ jsx7(
|
|
2800
|
+
QuickFilterPills,
|
|
2801
|
+
{
|
|
2802
|
+
options: statusFilterOptions,
|
|
2803
|
+
value: statusFilter,
|
|
2804
|
+
onChange: setStatusFilter,
|
|
2805
|
+
allLabel: "All",
|
|
2806
|
+
size: "sm",
|
|
2807
|
+
"aria-label": "Board status"
|
|
2808
|
+
}
|
|
2809
|
+
)
|
|
2810
|
+
] }),
|
|
2811
|
+
activeFilterCount > 0 && /* @__PURE__ */ jsx7(
|
|
2812
|
+
Button,
|
|
2813
|
+
{
|
|
2814
|
+
size: "sm",
|
|
2815
|
+
variant: "outline",
|
|
2816
|
+
onClick: () => {
|
|
2817
|
+
setSectionFilter("");
|
|
2818
|
+
setStatusFilter("");
|
|
2819
|
+
},
|
|
2820
|
+
children: "Clear filters"
|
|
2821
|
+
}
|
|
2822
|
+
)
|
|
2823
|
+
] })
|
|
2824
|
+
] })
|
|
2825
|
+
] });
|
|
2826
|
+
const toolbarEnd = /* @__PURE__ */ jsxs7(Fragment3, { children: [
|
|
2827
|
+
/* @__PURE__ */ jsxs7(Tooltip, { children: [
|
|
2828
|
+
/* @__PURE__ */ jsx7(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx7(
|
|
2829
|
+
"button",
|
|
2830
|
+
{
|
|
2831
|
+
type: "button",
|
|
2832
|
+
className: TOOL_BUTTON_CLASS2,
|
|
2833
|
+
"aria-label": texts.reload,
|
|
2834
|
+
"aria-keyshortcuts": "r",
|
|
2835
|
+
"aria-busy": isFetchingCanvas,
|
|
2836
|
+
onClick: () => void reloadCanvas(),
|
|
2837
|
+
children: /* @__PURE__ */ jsx7(RefreshCw, { className: cx("size-4", isFetchingCanvas && "animate-spin motion-reduce:animate-none") })
|
|
2838
|
+
}
|
|
2839
|
+
) }),
|
|
2840
|
+
/* @__PURE__ */ jsx7(TooltipContent, { side: "bottom", children: texts.reload })
|
|
2841
|
+
] }),
|
|
2842
|
+
/* @__PURE__ */ jsxs7(Tooltip, { children: [
|
|
2843
|
+
/* @__PURE__ */ jsx7(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx7("span", { children: /* @__PURE__ */ jsxs7(
|
|
2844
|
+
"button",
|
|
2845
|
+
{
|
|
2846
|
+
type: "button",
|
|
2847
|
+
className: TOOL_BUTTON_CLASS2,
|
|
2848
|
+
disabled: selectedBoardIds.size === 0,
|
|
2849
|
+
"aria-label": `Copy reference of ${selectedBoardIds.size} selected board(s) for an agent (C)`,
|
|
2850
|
+
onClick: copySelectedReferences,
|
|
2851
|
+
children: [
|
|
2852
|
+
/* @__PURE__ */ jsx7(ClipboardCopy4, { className: "size-4" }),
|
|
2853
|
+
selectedBoardIds.size > 1 && /* @__PURE__ */ jsx7("span", { className: "absolute -top-1 -right-1 flex h-4 min-w-4 items-center justify-center rounded-full bg-brand px-1 text-[10px] font-bold text-foreground", children: selectedBoardIds.size })
|
|
2854
|
+
]
|
|
2855
|
+
}
|
|
2856
|
+
) }) }),
|
|
2857
|
+
/* @__PURE__ */ jsx7(TooltipContent, { side: "bottom", children: selectedBoardIds.size === 0 ? "Select boards to copy their reference" : "Copy reference for an agent (C)" })
|
|
2858
|
+
] }),
|
|
2859
|
+
hasThemes && themes.length > 0 && /* @__PURE__ */ jsx7(
|
|
2860
|
+
Combobox,
|
|
2861
|
+
{
|
|
2862
|
+
shape: "pill",
|
|
2863
|
+
size: "sm",
|
|
2864
|
+
options: themeOptions,
|
|
2865
|
+
value: themeId ?? "",
|
|
2866
|
+
onChange: (value) => setCanvasStateValue("theme", value === (referenceThemeId ?? "") ? "" : value),
|
|
2867
|
+
isLoading: isLoadingThemes,
|
|
2868
|
+
placeholder: "Theme",
|
|
2869
|
+
searchPlaceholder: "Search themes\u2026",
|
|
2870
|
+
"aria-label": "Theme",
|
|
2871
|
+
className: "w-44"
|
|
2872
|
+
}
|
|
2873
|
+
),
|
|
2874
|
+
isRendererEnabled && missingThumbnailCount > 0 && renderStatus !== null && renderStatus !== "DONE" ? /* @__PURE__ */ jsxs7(Tooltip, { children: [
|
|
2875
|
+
/* @__PURE__ */ jsx7(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxs7(
|
|
2876
|
+
"button",
|
|
2877
|
+
{
|
|
2878
|
+
type: "button",
|
|
2879
|
+
disabled: renderStatus !== "FAILED" || !writesAllowed,
|
|
2880
|
+
className: "flex h-8 shrink-0 items-center gap-1.5 rounded-full bg-tint px-3 text-xs font-semibold text-muted-foreground transition-colors enabled:hover:bg-tint-strong enabled:hover:text-foreground",
|
|
2881
|
+
onClick: () => fileRenderRequest(true),
|
|
2882
|
+
children: [
|
|
2883
|
+
renderStatus === "FAILED" ? /* @__PURE__ */ jsx7(ImageDown, { className: "size-4", "aria-hidden": true }) : /* @__PURE__ */ jsx7(LoaderCircle, { className: "size-4 animate-spin motion-reduce:animate-none", "aria-hidden": true }),
|
|
2884
|
+
renderStatus === "FAILED" ? texts.thumbnailsFailed : renderStatus === "WAITING_FOR_RENDERER" ? texts.thumbnailsWaitingForRenderer(shownThemeLabel) : texts.thumbnailsRendering(shownThemeLabel),
|
|
2885
|
+
" ",
|
|
2886
|
+
"\xB7 ",
|
|
2887
|
+
Math.max(0, shownBoardList.length - missingThumbnailCount),
|
|
2888
|
+
"/",
|
|
2889
|
+
shownBoardList.length
|
|
2890
|
+
]
|
|
2891
|
+
}
|
|
2892
|
+
) }),
|
|
2893
|
+
/* @__PURE__ */ jsxs7(TooltipContent, { side: "bottom", className: "max-w-sm", children: [
|
|
2894
|
+
texts.thumbnailsMissing(missingThumbnailCount),
|
|
2895
|
+
canvas?.renderRequestError ? ` ${texts.thumbnailsLastError(canvas.renderRequestError)}` : ""
|
|
2896
|
+
] })
|
|
2897
|
+
] }) : null,
|
|
2898
|
+
hasThemes && themes.length > 0 && /* @__PURE__ */ jsxs7(Tooltip, { children: [
|
|
2899
|
+
/* @__PURE__ */ jsx7(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx7("span", { children: /* @__PURE__ */ jsx7(
|
|
2900
|
+
"button",
|
|
2901
|
+
{
|
|
2902
|
+
type: "button",
|
|
2903
|
+
className: TOOL_BUTTON_CLASS2,
|
|
2904
|
+
disabled: !supportsDark,
|
|
2905
|
+
"aria-label": effectiveMode === "dark" ? "Light theme" : "Dark theme",
|
|
2906
|
+
"aria-pressed": effectiveMode === "dark",
|
|
2907
|
+
onClick: () => {
|
|
2908
|
+
const nextMode = effectiveMode === "dark" ? "light" : "dark";
|
|
2909
|
+
setCanvasStateValue("mode", nextMode === defaultMode ? "" : nextMode);
|
|
2910
|
+
},
|
|
2911
|
+
children: effectiveMode === "dark" ? /* @__PURE__ */ jsx7(Sun, { className: "size-4" }) : /* @__PURE__ */ jsx7(Moon, { className: "size-4" })
|
|
2912
|
+
}
|
|
2913
|
+
) }) }),
|
|
2914
|
+
/* @__PURE__ */ jsx7(TooltipContent, { side: "bottom", children: supportsDark ? effectiveMode === "dark" ? "Light theme" : "Dark theme" : texts.themeWithoutDarkMode })
|
|
2915
|
+
] }),
|
|
2916
|
+
/* @__PURE__ */ jsxs7(Tooltip, { children: [
|
|
2917
|
+
/* @__PURE__ */ jsx7(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxs7(
|
|
2918
|
+
"button",
|
|
2919
|
+
{
|
|
2920
|
+
type: "button",
|
|
2921
|
+
className: cx(TOOL_BUTTON_CLASS2, isCommentsPanelOpen && "bg-brand-light text-brand-emphasis"),
|
|
2922
|
+
"aria-label": isCommentsPanelOpen ? "Hide comments" : "Show comments",
|
|
2923
|
+
"aria-pressed": isCommentsPanelOpen,
|
|
2924
|
+
onClick: toggleCommentsPanel,
|
|
2925
|
+
children: [
|
|
2926
|
+
isCommentsPanelOpen ? /* @__PURE__ */ jsx7(PanelRightClose, { className: "size-4" }) : /* @__PURE__ */ jsx7(PanelRightOpen, { className: "size-4" }),
|
|
2927
|
+
openThreadTotal > 0 && /* @__PURE__ */ jsx7("span", { className: "absolute -top-1 -right-1 flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-bold text-primary-foreground", children: openThreadTotal })
|
|
2928
|
+
]
|
|
2929
|
+
}
|
|
2930
|
+
) }),
|
|
2931
|
+
/* @__PURE__ */ jsx7(TooltipContent, { side: "bottom", children: isCommentsPanelOpen ? "Hide comments" : "Show comments" })
|
|
2932
|
+
] }),
|
|
2933
|
+
/* @__PURE__ */ jsxs7(Tooltip, { children: [
|
|
2934
|
+
/* @__PURE__ */ jsx7(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx7(
|
|
2935
|
+
"button",
|
|
2936
|
+
{
|
|
2937
|
+
type: "button",
|
|
2938
|
+
className: cx(TOOL_BUTTON_CLASS2, isFullscreen && "bg-brand-light text-brand-emphasis"),
|
|
2939
|
+
"aria-label": isFullscreen ? "Exit fullscreen (F)" : "Fullscreen (F)",
|
|
2940
|
+
"aria-pressed": isFullscreen,
|
|
2941
|
+
onClick: () => setIsFullscreen((value) => !value),
|
|
2942
|
+
children: isFullscreen ? /* @__PURE__ */ jsx7(Minimize, { className: "size-4" }) : /* @__PURE__ */ jsx7(Maximize, { className: "size-4" })
|
|
2943
|
+
}
|
|
2944
|
+
) }),
|
|
2945
|
+
/* @__PURE__ */ jsx7(TooltipContent, { side: "bottom", children: isFullscreen ? "Exit fullscreen (F)" : "Fullscreen (F)" })
|
|
2946
|
+
] })
|
|
2947
|
+
] });
|
|
2948
|
+
return /* @__PURE__ */ jsxs7(
|
|
2949
|
+
"div",
|
|
2950
|
+
{
|
|
2951
|
+
"data-page-frame": true,
|
|
2952
|
+
"data-canvas-fullscreen": isFullscreen ? "" : void 0,
|
|
2953
|
+
className: cx(
|
|
2954
|
+
// on the shell's cloud background (transparent); fullscreen covers the shell with the flat sky colour
|
|
2955
|
+
"relative flex h-[calc(100dvh_-_var(--nav-h))] min-h-[560px] flex-col lg:flex-row",
|
|
2956
|
+
isFullscreen && "fixed inset-0 z-40 h-dvh bg-background"
|
|
2957
|
+
),
|
|
2958
|
+
children: [
|
|
2959
|
+
error && /* @__PURE__ */ jsx7("div", { className: "p-6", children: /* @__PURE__ */ jsx7(
|
|
2960
|
+
StatusCallout,
|
|
2961
|
+
{
|
|
2962
|
+
tone: "destructive",
|
|
2963
|
+
title: "The canvas could not be loaded",
|
|
2964
|
+
description: normalizeDddError3(error, "Request failed").message
|
|
2965
|
+
}
|
|
2966
|
+
) }),
|
|
2967
|
+
(isLoading || !isLookResolved && !canvas) && /* @__PURE__ */ jsx7(Skeleton, { className: "m-6 flex-1 rounded-2xl" }),
|
|
2968
|
+
canvas && /* @__PURE__ */ jsxs7(CanvasViewContext.Provider, { value: canvasView, children: [
|
|
2969
|
+
/* @__PURE__ */ jsx7("div", { ref: canvasAreaRef, className: "relative min-h-[480px] min-w-0 flex-1", children: canvasAspectRatio !== null && /* @__PURE__ */ jsx7(
|
|
2970
|
+
DesignCanvasFlow,
|
|
2971
|
+
{
|
|
2972
|
+
layout,
|
|
2973
|
+
boardsByNodeId,
|
|
2974
|
+
fitRequest,
|
|
2975
|
+
initialFitNodeIds,
|
|
2976
|
+
initialViewport,
|
|
2977
|
+
onViewportCommit: commitViewport,
|
|
2978
|
+
tool,
|
|
2979
|
+
onToolChange: setTool,
|
|
2980
|
+
liveMinRatio: !isRendererEnabled || missingThumbnailCount > 0 ? LIVE_MIN_RENDERED_WIDTH_RATIO_WITHOUT_THUMBNAILS : LIVE_MIN_RENDERED_WIDTH_RATIO,
|
|
2981
|
+
onLiveBoardIdsChange: setLiveBoardIds,
|
|
2982
|
+
onVisibleBoardIdsChange: rememberVisibleBoardIds,
|
|
2983
|
+
onPaneClick: clearSelection,
|
|
2984
|
+
onMarqueeSelect: selectBoards,
|
|
2985
|
+
onPresentSection: presentSection,
|
|
2986
|
+
toolbarStart,
|
|
2987
|
+
toolbarEnd,
|
|
2988
|
+
selectedNodeId: selectedBoardId
|
|
2989
|
+
}
|
|
2990
|
+
) }),
|
|
2991
|
+
isCommentsPanelOpen && /* @__PURE__ */ jsx7("aside", { className: "surface-glass-strong m-3 shrink-0 overflow-y-auto rounded-3xl p-5 ring-1 ring-foreground/5 lg:my-3 lg:ml-0 lg:w-[380px]", children: selectedBoard ? /* @__PURE__ */ jsx7(
|
|
2992
|
+
SelectedBoardPanel,
|
|
2993
|
+
{
|
|
2994
|
+
projectKey,
|
|
2995
|
+
canvasKey,
|
|
2996
|
+
board: selectedBoard,
|
|
2997
|
+
statuses,
|
|
2998
|
+
sectionTitle: sectionTitleByKey.get(selectedBoard.sectionKey ?? "") ?? null,
|
|
2999
|
+
threads: threadsOf(selectedBoardId),
|
|
3000
|
+
writesAllowed,
|
|
3001
|
+
onOpen: () => selectedBoardId && openBoardFromCanvas(selectedBoardId),
|
|
3002
|
+
onStatusChanged: (status) => selectedBoardId && setBoardStatus(selectedBoardId, status),
|
|
3003
|
+
onCopyThreadReference: copyThreadReference
|
|
3004
|
+
},
|
|
3005
|
+
selectedBoard.boardKey ?? ""
|
|
3006
|
+
) : /* @__PURE__ */ jsxs7("div", { className: "space-y-4", children: [
|
|
3007
|
+
/* @__PURE__ */ jsxs7("div", { children: [
|
|
3008
|
+
/* @__PURE__ */ jsx7("h2", { className: "text-title-card font-semibold", children: "Open comments" }),
|
|
3009
|
+
/* @__PURE__ */ jsx7("p", { className: "text-sm text-muted-foreground", children: "Click a board to see its status and comments, double-click to open it large." })
|
|
3010
|
+
] }),
|
|
3011
|
+
boardsWithOpenThreads.length === 0 && /* @__PURE__ */ jsx7("p", { className: "text-sm text-muted-foreground", children: "No open comments on this canvas." }),
|
|
3012
|
+
/* @__PURE__ */ jsx7("ul", { className: "space-y-1", children: boardsWithOpenThreads.map((nodeId) => /* @__PURE__ */ jsx7("li", { children: /* @__PURE__ */ jsxs7(
|
|
3013
|
+
"button",
|
|
3014
|
+
{
|
|
3015
|
+
type: "button",
|
|
3016
|
+
className: "flex w-full items-center justify-between gap-2 rounded-[10px] px-3 py-2 text-left text-sm transition-colors hover:bg-tint",
|
|
3017
|
+
onClick: () => {
|
|
3018
|
+
setSelectedBoardId(nodeId);
|
|
3019
|
+
requestFit([nodeId]);
|
|
3020
|
+
},
|
|
3021
|
+
children: [
|
|
3022
|
+
/* @__PURE__ */ jsx7("span", { className: "truncate", children: boardsByNodeId.get(nodeId)?.title }),
|
|
3023
|
+
/* @__PURE__ */ jsxs7("span", { className: "inline-flex shrink-0 items-center gap-1 text-xs font-semibold text-muted-foreground", children: [
|
|
3024
|
+
/* @__PURE__ */ jsx7(MessageSquare2, { className: "size-3.5", "aria-hidden": true }),
|
|
3025
|
+
" ",
|
|
3026
|
+
openThreadCounts.get(nodeId)
|
|
3027
|
+
] })
|
|
3028
|
+
]
|
|
3029
|
+
}
|
|
3030
|
+
) }, nodeId)) })
|
|
3031
|
+
] }) })
|
|
3032
|
+
] }),
|
|
3033
|
+
/* @__PURE__ */ jsx7(
|
|
3034
|
+
BoardFocusView,
|
|
3035
|
+
{
|
|
3036
|
+
projectKey,
|
|
3037
|
+
canvasKey,
|
|
3038
|
+
board: focusedBoard,
|
|
3039
|
+
statuses,
|
|
3040
|
+
sectionTitle: focusedBoard ? sectionTitleByKey.get(focusedBoard.sectionKey ?? "") ?? null : null,
|
|
3041
|
+
position: {
|
|
3042
|
+
index: focusedBoardId ? navigationOrder.indexOf(focusedBoardId) + 1 : 0,
|
|
3043
|
+
count: navigationOrder.length
|
|
3044
|
+
},
|
|
3045
|
+
threads: threadsOf(focusedBoardId),
|
|
3046
|
+
writesAllowed,
|
|
3047
|
+
presentLabel: presentedSectionTitle,
|
|
3048
|
+
onClose: closeFocus,
|
|
3049
|
+
onPrevious: () => stepFocus(-1),
|
|
3050
|
+
onNext: () => stepFocus(1),
|
|
3051
|
+
onStatusChanged: (status) => focusedBoardId && setBoardStatus(focusedBoardId, status),
|
|
3052
|
+
onCopyReference: ({ region, note }) => focusedBoardId && void copyReferences([buildReferenceFor(focusedBoardId, { region, note })]),
|
|
3053
|
+
onCopyThreadReference: copyThreadReference
|
|
3054
|
+
}
|
|
3055
|
+
)
|
|
3056
|
+
]
|
|
3057
|
+
}
|
|
3058
|
+
);
|
|
3059
|
+
};
|
|
3060
|
+
export {
|
|
3061
|
+
DesignStudioCanvasScreen
|
|
3062
|
+
};
|
|
3063
|
+
//# sourceMappingURL=index.js.map
|