proto-plugin 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/AGENTS.md +350 -0
- package/README.md +279 -0
- package/components.json +18 -0
- package/package.json +73 -0
- package/scripts/download-mobbin-reference-images.mjs +112 -0
- package/scripts/lib/host-config.example.sh +48 -0
- package/scripts/lib/host-config.sh +25 -0
- package/scripts/lib/resolve-host-root.mjs +18 -0
- package/scripts/lib/source-path.sh +49 -0
- package/scripts/link-source-db.sh +128 -0
- package/scripts/link-source.sh +40 -0
- package/scripts/publish-package.sh +147 -0
- package/scripts/share-prototype.sh +279 -0
- package/scripts/sync-from-source.sh +74 -0
- package/scripts/verify-prototype-component-ids.mjs +151 -0
- package/scripts/verify-prototype-preview-states.mjs +135 -0
- package/src/app.ts +4 -0
- package/src/components/platform-ui/code-block.tsx +21 -0
- package/src/components/platform-ui/controls-panel-options.tsx +71 -0
- package/src/components/platform-ui/controls-panel-select.tsx +438 -0
- package/src/components/platform-ui/empty-state.tsx +15 -0
- package/src/components/platform-ui/icon-button.tsx +18 -0
- package/src/components/platform-ui/panel-select.tsx +123 -0
- package/src/components/platform-ui/panel.tsx +97 -0
- package/src/components/platform-ui/review-dropdown-menu.tsx +35 -0
- package/src/components/platform-ui/sidebar.tsx +293 -0
- package/src/components/platform-ui/toolbar-icon-button.tsx +34 -0
- package/src/components/platform-ui/toolbar.tsx +37 -0
- package/src/components/prototype-gallery-client.tsx +57 -0
- package/src/components/prototype-provider.tsx +20 -0
- package/src/components/prototypes/mini-pill-label.tsx +37 -0
- package/src/components/prototypes/prototype-change-log-panel.tsx +207 -0
- package/src/components/prototypes/prototype-comment-provider.tsx +61 -0
- package/src/components/prototypes/prototype-comment-toolbar.tsx +65 -0
- package/src/components/prototypes/prototype-control.tsx +31 -0
- package/src/components/prototypes/prototype-controls.tsx +553 -0
- package/src/components/prototypes/prototype-create-exploration-modal.tsx +117 -0
- package/src/components/prototypes/prototype-create-state-modal.tsx +117 -0
- package/src/components/prototypes/prototype-default-state-map-page.tsx +66 -0
- package/src/components/prototypes/prototype-design-brief-modal.tsx +128 -0
- package/src/components/prototypes/prototype-design-brief-panel.tsx +525 -0
- package/src/components/prototypes/prototype-design-context-panel.tsx +65 -0
- package/src/components/prototypes/prototype-floating-pill.module.scss +1341 -0
- package/src/components/prototypes/prototype-mobbin-gallery.tsx +330 -0
- package/src/components/prototypes/prototype-reference-docs.tsx +222 -0
- package/src/components/prototypes/prototype-review-chrome.module.scss +630 -0
- package/src/components/prototypes/prototype-review-chrome.tsx +1241 -0
- package/src/components/prototypes/prototype-review-dropdown-menu-item.tsx +1 -0
- package/src/components/prototypes/prototype-review-dropdown-menu-separator.tsx +1 -0
- package/src/components/prototypes/prototype-review-panel-menu-item.tsx +1 -0
- package/src/components/prototypes/prototype-review-panel-menu-separator.tsx +1 -0
- package/src/components/prototypes/prototype-review-panel-select.tsx +4 -0
- package/src/components/prototypes/prototype-review-sidebar.tsx +167 -0
- package/src/components/prototypes/prototype-share-link-restore.tsx +75 -0
- package/src/components/prototypes/prototype-share-mode.tsx +206 -0
- package/src/components/prototypes/prototype-spec-panel-content.tsx +538 -0
- package/src/components/prototypes/prototype-state-canvas-overlay.module.scss +336 -0
- package/src/components/prototypes/prototype-state-canvas-overlay.tsx +1023 -0
- package/src/components/prototypes/prototype-state-canvas.tsx +38 -0
- package/src/components/prototypes/prototype-state-screenshot-preview.tsx +47 -0
- package/src/components/prototypes/prototype-target.tsx +120 -0
- package/src/components/prototypes/prototype-tweak-highlight.tsx +132 -0
- package/src/components/prototypes/prototype-tweaks.tsx +48 -0
- package/src/components/prototypes/prototype-variant-explorer.tsx +347 -0
- package/src/components/prototypes/prototype-variant-rationale-panel.tsx +49 -0
- package/src/components/prototypes/prototype-variant-tabs.tsx +207 -0
- package/src/components/prototypes/prototype-vercel-preview-modal.tsx +120 -0
- package/src/components/prototypes/state-map-annotation-tooltip.module.scss +89 -0
- package/src/components/prototypes/state-map-annotation-tooltip.tsx +137 -0
- package/src/components/prototypes/state-map-wireframe-highlight.module.scss +25 -0
- package/src/components/prototypes/state-map-wireframe-highlight.tsx +82 -0
- package/src/components/shell/prototype-gallery-shell.tsx +79 -0
- package/src/components/shell/prototype-screenshot-capture.tsx +45 -0
- package/src/components/shell/prototype-shell.module.scss +194 -0
- package/src/components/shell/prototype-shell.tsx +160 -0
- package/src/components/shell/prototype-state-screenshot-capture.tsx +68 -0
- package/src/components/ui/button.tsx +58 -0
- package/src/components/ui/dialog.module.scss +81 -0
- package/src/components/ui/dialog.tsx +127 -0
- package/src/components/ui/dropdown-menu.tsx +200 -0
- package/src/components/ui/input.tsx +22 -0
- package/src/components/ui/label.tsx +26 -0
- package/src/components/ui/option-select.tsx +81 -0
- package/src/components/ui/scroll-area.tsx +48 -0
- package/src/components/ui/separator.tsx +31 -0
- package/src/components/ui/slider.tsx +28 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/tabs.tsx +55 -0
- package/src/components/ui/toggle-group.tsx +80 -0
- package/src/components/ui/tooltip.tsx +32 -0
- package/src/config/create-prototype-gallery-page.tsx +65 -0
- package/src/config/create-prototype-host-app.tsx +121 -0
- package/src/config/create-prototype-page.tsx +41 -0
- package/src/config/create-prototype-site-layout.tsx +28 -0
- package/src/config/define-prototype-config.ts +7 -0
- package/src/config/prototype-icon.tsx +25 -0
- package/src/config/prototype-site-layout-client.tsx +35 -0
- package/src/config/with-prototype.ts +20 -0
- package/src/index.ts +303 -0
- package/src/lib/pr-split/build-pr-agent-prompt.ts +68 -0
- package/src/lib/pr-split/build-pr-split-prototype-url.ts +12 -0
- package/src/lib/pr-split/pr-split-highlight.ts +6 -0
- package/src/lib/pr-split/pr-split-types.ts +58 -0
- package/src/lib/pr-split/resolve-source-preview-url.ts +45 -0
- package/src/lib/pr-split/use-pr-vercel-previews.ts +69 -0
- package/src/lib/prototype-comments/core/annotation-channel.ts +41 -0
- package/src/lib/prototype-comments/core/annotation-status.ts +60 -0
- package/src/lib/prototype-comments/core/annotation-target.ts +567 -0
- package/src/lib/prototype-comments/core/capture-theme.ts +41 -0
- package/src/lib/prototype-comments/core/capture.ts +11 -0
- package/src/lib/prototype-comments/core/comment-capture-blocked.ts +47 -0
- package/src/lib/prototype-comments/core/comment-threads.ts +52 -0
- package/src/lib/prototype-comments/core/element-identification.ts +615 -0
- package/src/lib/prototype-comments/core/export.ts +35 -0
- package/src/lib/prototype-comments/core/freeze-animations.ts +266 -0
- package/src/lib/prototype-comments/core/identify-element.ts +76 -0
- package/src/lib/prototype-comments/core/normalize-viewport.ts +35 -0
- package/src/lib/prototype-comments/core/react-detection.ts +704 -0
- package/src/lib/prototype-comments/core/restore.ts +7 -0
- package/src/lib/prototype-comments/core/screenshot.ts +428 -0
- package/src/lib/prototype-comments/core/source-location.ts +906 -0
- package/src/lib/prototype-comments/core/storage.ts +80 -0
- package/src/lib/prototype-comments/core/types.ts +79 -0
- package/src/lib/prototype-comments/core/validation.ts +17 -0
- package/src/lib/prototype-comments/hooks/useLayoutShift.ts +61 -0
- package/src/lib/prototype-comments/index.ts +58 -0
- package/src/lib/prototype-comments/react/CommentCaptureToolbar.tsx +1398 -0
- package/src/lib/prototype-comments/react/CommentProvider.tsx +298 -0
- package/src/lib/prototype-comments/scss.d.ts +10 -0
- package/src/lib/prototype-comments/ui/CommentAnnotationOverlay.tsx +253 -0
- package/src/lib/prototype-comments/ui/CommentDetailPage.tsx +56 -0
- package/src/lib/prototype-comments/ui/CommentHeaderCount.tsx +28 -0
- package/src/lib/prototype-comments/ui/CommentThread.tsx +331 -0
- package/src/lib/prototype-comments/ui/CommentsGrid.tsx +780 -0
- package/src/lib/prototype-comments/ui/CommentsListPage.tsx +25 -0
- package/src/lib/prototype-comments/ui/CommentsSidebar.tsx +77 -0
- package/src/lib/prototype-comments/ui/annotation-marker/index.tsx +200 -0
- package/src/lib/prototype-comments/ui/annotation-marker/styles.module.scss +194 -0
- package/src/lib/prototype-comments/ui/annotation-popup/index.tsx +335 -0
- package/src/lib/prototype-comments/ui/annotation-popup/styles.module.scss +469 -0
- package/src/lib/prototype-comments/ui/capture-styles.module.scss +2225 -0
- package/src/lib/prototype-comments/ui/comment-highlight.ts +48 -0
- package/src/lib/prototype-comments/ui/comment-thread.module.scss +203 -0
- package/src/lib/prototype-comments/ui/comments-grid-card.module.scss +253 -0
- package/src/lib/prototype-comments/ui/comments-sidebar.module.scss +123 -0
- package/src/lib/prototype-comments/ui/icon-transitions.module.scss +51 -0
- package/src/lib/prototype-comments/ui/icons.tsx +1086 -0
- package/src/lib/prototype-comments/ui/is-comment-detail-path.ts +7 -0
- package/src/lib/prototypes/capture-prototype-viewport.ts +32 -0
- package/src/lib/prototypes/changelog-meta-context.tsx +162 -0
- package/src/lib/prototypes/changelog-meta-storage.ts +62 -0
- package/src/lib/prototypes/changelog-meta.ts +95 -0
- package/src/lib/prototypes/create-prototype-registry.ts +74 -0
- package/src/lib/prototypes/create-state-screenshot-thumbnail.ts +46 -0
- package/src/lib/prototypes/design-exploration-default-storage.ts +68 -0
- package/src/lib/prototypes/design-exploration-default.ts +51 -0
- package/src/lib/prototypes/design-exploration-types.ts +203 -0
- package/src/lib/prototypes/prototype-comment-registry.tsx +145 -0
- package/src/lib/prototypes/prototype-comment-review-bridge.tsx +40 -0
- package/src/lib/prototypes/prototype-comment-review-state.ts +57 -0
- package/src/lib/prototypes/prototype-component-registry.ts +40 -0
- package/src/lib/prototypes/prototype-config-types.ts +34 -0
- package/src/lib/prototypes/prototype-preview-state-registry.ts +443 -0
- package/src/lib/prototypes/prototype-preview-state-types.ts +89 -0
- package/src/lib/prototypes/prototype-review-context.tsx +905 -0
- package/src/lib/prototypes/prototype-review-url.ts +134 -0
- package/src/lib/prototypes/prototype-share-link.ts +175 -0
- package/src/lib/prototypes/prototype-state-canvas-constants.ts +118 -0
- package/src/lib/prototypes/prototype-state-canvas-types.ts +159 -0
- package/src/lib/prototypes/prototype-state-screenshot.ts +39 -0
- package/src/lib/prototypes/prototype-tweak-registry.ts +96 -0
- package/src/lib/prototypes/prototype-tweak-types.ts +31 -0
- package/src/lib/prototypes/reference-docs.ts +137 -0
- package/src/lib/prototypes/screenshot-manifest.ts +33 -0
- package/src/lib/prototypes/screenshot-src.ts +7 -0
- package/src/lib/prototypes/share-command.ts +8 -0
- package/src/lib/prototypes/state-map-annotation.ts +70 -0
- package/src/lib/prototypes/use-design-exploration-default.ts +114 -0
- package/src/lib/prototypes/use-persisted-local-state.ts +140 -0
- package/src/lib/prototypes/use-prototype-comments.ts +63 -0
- package/src/lib/prototypes/use-prototype-mobile-viewport-frame.ts +46 -0
- package/src/lib/prototypes/use-prototype-state-screenshot-src.ts +71 -0
- package/src/lib/prototypes/use-prototype-tool-theme.tsx +115 -0
- package/src/lib/prototypes/use-prototype-viewport-frame.ts +34 -0
- package/src/lib/prototypes/use-register-prototype-reference-docs.ts +16 -0
- package/src/lib/prototypes/use-snap-corner-position.ts +417 -0
- package/src/lib/prototypes/use-toolbar-hover-panel.ts +98 -0
- package/src/lib/prototypes/variant-set-lucide-icon.tsx +55 -0
- package/src/lib/tool-portal.ts +33 -0
- package/src/lib/use-copy-to-clipboard.ts +81 -0
- package/src/lib/utils.ts +6 -0
- package/src/lib/vercel-preview/parse-vercel-github-comment.ts +81 -0
- package/src/server/create-host-api-route.ts +100 -0
- package/src/server/create-prototype-api-routes.ts +428 -0
- package/src/server/gallery/create-gallery-api.ts +56 -0
- package/src/server/gallery/folders-route.ts +156 -0
- package/src/server/gallery/gallery-env.ts +39 -0
- package/src/server/gallery/gallery-route.ts +150 -0
- package/src/server/gallery/gallery-types.ts +15 -0
- package/src/server/gallery/image-route.ts +59 -0
- package/src/server/gallery/item-route.ts +92 -0
- package/src/server/pr-vercel-preview-route.ts +162 -0
- package/src/server/redis/client.ts +55 -0
- package/src/server/redis/prototype-changelog-meta.ts +31 -0
- package/src/server/redis/prototype-comments.ts +92 -0
- package/src/server/redis/prototype-design-exploration-default.ts +32 -0
- package/src/server.ts +51 -0
- package/src/styles/globals.css +624 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useEffect,
|
|
5
|
+
useState,
|
|
6
|
+
type KeyboardEvent,
|
|
7
|
+
type MouseEvent,
|
|
8
|
+
} from "react";
|
|
9
|
+
|
|
10
|
+
import { getRepliesForParent } from "../core/comment-threads";
|
|
11
|
+
import type { CommentAnnotation } from "../core/types";
|
|
12
|
+
import { useCommentStore } from "../react/CommentProvider";
|
|
13
|
+
import threadStyles from "./comment-thread.module.scss";
|
|
14
|
+
import { cn } from "@prototype/lib/utils";
|
|
15
|
+
|
|
16
|
+
function formatReplyTime(timestamp: number): string {
|
|
17
|
+
return new Date(timestamp).toLocaleString(undefined, {
|
|
18
|
+
month: "short",
|
|
19
|
+
day: "numeric",
|
|
20
|
+
hour: "numeric",
|
|
21
|
+
minute: "2-digit",
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function PencilIcon() {
|
|
26
|
+
return (
|
|
27
|
+
<svg
|
|
28
|
+
width="12"
|
|
29
|
+
height="12"
|
|
30
|
+
viewBox="0 0 24 24"
|
|
31
|
+
fill="none"
|
|
32
|
+
stroke="currentColor"
|
|
33
|
+
strokeWidth="2"
|
|
34
|
+
strokeLinecap="round"
|
|
35
|
+
strokeLinejoin="round"
|
|
36
|
+
aria-hidden
|
|
37
|
+
>
|
|
38
|
+
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" />
|
|
39
|
+
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z" />
|
|
40
|
+
</svg>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function TrashIcon() {
|
|
45
|
+
return (
|
|
46
|
+
<svg
|
|
47
|
+
width="12"
|
|
48
|
+
height="12"
|
|
49
|
+
viewBox="0 0 24 24"
|
|
50
|
+
fill="none"
|
|
51
|
+
stroke="currentColor"
|
|
52
|
+
strokeWidth="2"
|
|
53
|
+
strokeLinecap="round"
|
|
54
|
+
strokeLinejoin="round"
|
|
55
|
+
aria-hidden
|
|
56
|
+
>
|
|
57
|
+
<polyline points="3 6 5 6 21 6" />
|
|
58
|
+
<path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6" />
|
|
59
|
+
<path d="M10 11v6M14 11v6" />
|
|
60
|
+
<path d="M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2" />
|
|
61
|
+
</svg>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
type ThreadReplyRowProps<TState> = {
|
|
66
|
+
reply: CommentAnnotation<TState>;
|
|
67
|
+
canModify: boolean;
|
|
68
|
+
dark?: boolean;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
function ThreadReplyRow<TState>({
|
|
72
|
+
reply,
|
|
73
|
+
canModify,
|
|
74
|
+
dark = false,
|
|
75
|
+
}: ThreadReplyRowProps<TState>) {
|
|
76
|
+
const { updateAnnotation, deleteAnnotation } = useCommentStore<TState>();
|
|
77
|
+
const [editing, setEditing] = useState(false);
|
|
78
|
+
const [draft, setDraft] = useState(reply.comment);
|
|
79
|
+
const [actionsVisible, setActionsVisible] = useState(false);
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
setDraft(reply.comment);
|
|
83
|
+
}, [reply.comment]);
|
|
84
|
+
|
|
85
|
+
function handleSave() {
|
|
86
|
+
const text = draft.trim();
|
|
87
|
+
if (!text) return;
|
|
88
|
+
updateAnnotation(reply.id, text);
|
|
89
|
+
setEditing(false);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function handleKeyDown(event: KeyboardEvent<HTMLTextAreaElement>) {
|
|
93
|
+
event.stopPropagation();
|
|
94
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
handleSave();
|
|
97
|
+
}
|
|
98
|
+
if (event.key === "Escape") {
|
|
99
|
+
setDraft(reply.comment);
|
|
100
|
+
setEditing(false);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<div
|
|
106
|
+
className={threadStyles.replyRow}
|
|
107
|
+
role="listitem"
|
|
108
|
+
onMouseEnter={() => setActionsVisible(true)}
|
|
109
|
+
onMouseLeave={() => setActionsVisible(false)}
|
|
110
|
+
>
|
|
111
|
+
<div
|
|
112
|
+
className={cn(threadStyles.replyMeta, dark && threadStyles.replyMetaDark)}
|
|
113
|
+
>
|
|
114
|
+
<span>{formatReplyTime(reply.timestamp)}</span>
|
|
115
|
+
</div>
|
|
116
|
+
|
|
117
|
+
{editing ? (
|
|
118
|
+
<>
|
|
119
|
+
<textarea
|
|
120
|
+
autoFocus
|
|
121
|
+
value={draft}
|
|
122
|
+
onChange={(event) => setDraft(event.target.value)}
|
|
123
|
+
onKeyDown={handleKeyDown}
|
|
124
|
+
rows={2}
|
|
125
|
+
className={cn(threadStyles.textarea, dark && threadStyles.textareaDark)}
|
|
126
|
+
aria-label="Edit reply"
|
|
127
|
+
onClick={(event) => event.stopPropagation()}
|
|
128
|
+
/>
|
|
129
|
+
<div className={threadStyles.rowComposerActions}>
|
|
130
|
+
<button
|
|
131
|
+
type="button"
|
|
132
|
+
className={threadStyles.secondaryBtn}
|
|
133
|
+
onClick={() => {
|
|
134
|
+
setDraft(reply.comment);
|
|
135
|
+
setEditing(false);
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
Cancel
|
|
139
|
+
</button>
|
|
140
|
+
<button
|
|
141
|
+
type="button"
|
|
142
|
+
className={threadStyles.primaryBtn}
|
|
143
|
+
disabled={!draft.trim()}
|
|
144
|
+
onClick={handleSave}
|
|
145
|
+
>
|
|
146
|
+
Save
|
|
147
|
+
</button>
|
|
148
|
+
</div>
|
|
149
|
+
</>
|
|
150
|
+
) : (
|
|
151
|
+
<p
|
|
152
|
+
className={cn(threadStyles.replyText, dark && threadStyles.replyTextDark)}
|
|
153
|
+
>
|
|
154
|
+
{reply.comment}
|
|
155
|
+
</p>
|
|
156
|
+
)}
|
|
157
|
+
|
|
158
|
+
{canModify && !editing && (
|
|
159
|
+
<div
|
|
160
|
+
className={cn(
|
|
161
|
+
threadStyles.rowActions,
|
|
162
|
+
actionsVisible && threadStyles.rowActionsVisible,
|
|
163
|
+
)}
|
|
164
|
+
onClick={(event) => event.stopPropagation()}
|
|
165
|
+
>
|
|
166
|
+
<button
|
|
167
|
+
type="button"
|
|
168
|
+
className={cn(
|
|
169
|
+
threadStyles.iconBtn,
|
|
170
|
+
dark && threadStyles.iconBtnDark,
|
|
171
|
+
)}
|
|
172
|
+
aria-label="Edit reply"
|
|
173
|
+
onClick={() => {
|
|
174
|
+
setDraft(reply.comment);
|
|
175
|
+
setEditing(true);
|
|
176
|
+
}}
|
|
177
|
+
>
|
|
178
|
+
<PencilIcon />
|
|
179
|
+
</button>
|
|
180
|
+
<button
|
|
181
|
+
type="button"
|
|
182
|
+
className={cn(
|
|
183
|
+
threadStyles.iconBtn,
|
|
184
|
+
threadStyles.iconBtnDanger,
|
|
185
|
+
dark && threadStyles.iconBtnDark,
|
|
186
|
+
)}
|
|
187
|
+
aria-label="Delete reply"
|
|
188
|
+
onClick={() => deleteAnnotation(reply.id)}
|
|
189
|
+
>
|
|
190
|
+
<TrashIcon />
|
|
191
|
+
</button>
|
|
192
|
+
</div>
|
|
193
|
+
)}
|
|
194
|
+
</div>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
type CommentThreadProps<TState> = {
|
|
199
|
+
rootAnnotation: CommentAnnotation<TState>;
|
|
200
|
+
readOnly?: boolean;
|
|
201
|
+
/** Attached below the annotation popup on the canvas overlay */
|
|
202
|
+
variant?: "inline" | "overlay";
|
|
203
|
+
dark?: boolean;
|
|
204
|
+
onComposerClick?: (event: MouseEvent) => void;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export function CommentThread<TState>({
|
|
208
|
+
rootAnnotation,
|
|
209
|
+
readOnly = false,
|
|
210
|
+
variant = "inline",
|
|
211
|
+
dark = false,
|
|
212
|
+
onComposerClick,
|
|
213
|
+
}: CommentThreadProps<TState>) {
|
|
214
|
+
const { annotations, addReply } = useCommentStore<TState>();
|
|
215
|
+
const [showComposer, setShowComposer] = useState(false);
|
|
216
|
+
const [draft, setDraft] = useState("");
|
|
217
|
+
|
|
218
|
+
const replies = getRepliesForParent(annotations, rootAnnotation.id);
|
|
219
|
+
const isResolved = rootAnnotation.status === "resolved";
|
|
220
|
+
const canModify = !readOnly && !isResolved;
|
|
221
|
+
|
|
222
|
+
function handleSubmit() {
|
|
223
|
+
const text = draft.trim();
|
|
224
|
+
if (!text) return;
|
|
225
|
+
addReply(rootAnnotation.id, text);
|
|
226
|
+
setDraft("");
|
|
227
|
+
setShowComposer(false);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function handleKeyDown(event: KeyboardEvent<HTMLTextAreaElement>) {
|
|
231
|
+
event.stopPropagation();
|
|
232
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
233
|
+
event.preventDefault();
|
|
234
|
+
handleSubmit();
|
|
235
|
+
}
|
|
236
|
+
if (event.key === "Escape") {
|
|
237
|
+
setDraft("");
|
|
238
|
+
setShowComposer(false);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (replies.length === 0 && !canModify) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const content = (
|
|
247
|
+
<div
|
|
248
|
+
className={threadStyles.root}
|
|
249
|
+
onClick={(event) => event.stopPropagation()}
|
|
250
|
+
>
|
|
251
|
+
{replies.length > 0 && (
|
|
252
|
+
<div
|
|
253
|
+
className={cn(threadStyles.replies, dark && threadStyles.repliesDark)}
|
|
254
|
+
role="list"
|
|
255
|
+
aria-label="Replies"
|
|
256
|
+
>
|
|
257
|
+
{replies.map((reply) => (
|
|
258
|
+
<ThreadReplyRow
|
|
259
|
+
key={reply.id}
|
|
260
|
+
reply={reply}
|
|
261
|
+
canModify={canModify}
|
|
262
|
+
dark={dark}
|
|
263
|
+
/>
|
|
264
|
+
))}
|
|
265
|
+
</div>
|
|
266
|
+
)}
|
|
267
|
+
|
|
268
|
+
{canModify && (
|
|
269
|
+
<>
|
|
270
|
+
{!showComposer ? (
|
|
271
|
+
<button
|
|
272
|
+
type="button"
|
|
273
|
+
className={cn(
|
|
274
|
+
threadStyles.replyLink,
|
|
275
|
+
dark && threadStyles.replyLinkDark,
|
|
276
|
+
)}
|
|
277
|
+
onClick={() => setShowComposer(true)}
|
|
278
|
+
>
|
|
279
|
+
Reply
|
|
280
|
+
</button>
|
|
281
|
+
) : (
|
|
282
|
+
<div onClick={onComposerClick}>
|
|
283
|
+
<textarea
|
|
284
|
+
autoFocus
|
|
285
|
+
value={draft}
|
|
286
|
+
onChange={(event) => setDraft(event.target.value)}
|
|
287
|
+
onKeyDown={handleKeyDown}
|
|
288
|
+
placeholder="Write a reply…"
|
|
289
|
+
rows={2}
|
|
290
|
+
className={cn(threadStyles.textarea, dark && threadStyles.textareaDark)}
|
|
291
|
+
aria-label="Reply to comment"
|
|
292
|
+
/>
|
|
293
|
+
<div className={threadStyles.composerActions}>
|
|
294
|
+
<button
|
|
295
|
+
type="button"
|
|
296
|
+
className={threadStyles.secondaryBtn}
|
|
297
|
+
onClick={() => {
|
|
298
|
+
setDraft("");
|
|
299
|
+
setShowComposer(false);
|
|
300
|
+
}}
|
|
301
|
+
>
|
|
302
|
+
Cancel
|
|
303
|
+
</button>
|
|
304
|
+
<button
|
|
305
|
+
type="button"
|
|
306
|
+
className={threadStyles.primaryBtn}
|
|
307
|
+
disabled={!draft.trim()}
|
|
308
|
+
onClick={handleSubmit}
|
|
309
|
+
>
|
|
310
|
+
Reply
|
|
311
|
+
</button>
|
|
312
|
+
</div>
|
|
313
|
+
</div>
|
|
314
|
+
)}
|
|
315
|
+
</>
|
|
316
|
+
)}
|
|
317
|
+
</div>
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
if (variant === "overlay") {
|
|
321
|
+
return (
|
|
322
|
+
<div
|
|
323
|
+
className={dark ? threadStyles.threadPanelDark : threadStyles.threadPanel}
|
|
324
|
+
>
|
|
325
|
+
{content}
|
|
326
|
+
</div>
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return content;
|
|
331
|
+
}
|