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,38 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { usePrototypeReviewOptional } from "@prototype/lib/prototypes/prototype-review-context";
|
|
4
|
+
import { useEffect } from "react";
|
|
5
|
+
|
|
6
|
+
export function PrototypeStateCanvasRegistrar({
|
|
7
|
+
pagePath,
|
|
8
|
+
}: {
|
|
9
|
+
pagePath: string;
|
|
10
|
+
}) {
|
|
11
|
+
const review = usePrototypeReviewOptional();
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
review?.setStateCanvasPagePath(pagePath);
|
|
15
|
+
return () => review?.setStateCanvasPagePath(null);
|
|
16
|
+
}, [pagePath, review]);
|
|
17
|
+
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { PrototypeStateCanvasView } from "@prototype/components/prototypes/prototype-state-canvas-overlay";
|
|
22
|
+
|
|
23
|
+
export type { PrototypeStateCanvasConfig } from "@prototype/lib/prototypes/prototype-state-canvas-types";
|
|
24
|
+
export {
|
|
25
|
+
buildStateMapHref,
|
|
26
|
+
buildStateMapAnnotationEntries,
|
|
27
|
+
getDefaultPrototypeStateMapPath,
|
|
28
|
+
parseStateMapReturnTo,
|
|
29
|
+
PROTOTYPE_STATE_MAP_RETURN_TO_PARAM,
|
|
30
|
+
stateMapHasAnnotations,
|
|
31
|
+
} from "@prototype/lib/prototypes/prototype-state-canvas-types";
|
|
32
|
+
export type {
|
|
33
|
+
PrototypeStateCanvasEdge,
|
|
34
|
+
PrototypeStateCanvasNode,
|
|
35
|
+
PrototypeStateCanvasNodeCallout,
|
|
36
|
+
PrototypeStateCanvasSection,
|
|
37
|
+
PrototypeStateMapAnnotationEntry,
|
|
38
|
+
} from "@prototype/lib/prototypes/prototype-state-canvas-types";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { getStateScreenshotThumbSize } from "@prototype/lib/prototypes/prototype-state-canvas-constants";
|
|
4
|
+
import { usePrototypeStateScreenshotSrc } from "@prototype/lib/prototypes/use-prototype-state-screenshot-src";
|
|
5
|
+
import { useEffect, useState, type ReactNode } from "react";
|
|
6
|
+
|
|
7
|
+
import { cn } from "@prototype/lib/utils";
|
|
8
|
+
|
|
9
|
+
const THUMB_SIZE = getStateScreenshotThumbSize();
|
|
10
|
+
|
|
11
|
+
type PrototypeStateScreenshotPreviewProps = {
|
|
12
|
+
slug: string;
|
|
13
|
+
stateId: string;
|
|
14
|
+
fallback: ReactNode;
|
|
15
|
+
className?: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function PrototypeStateScreenshotPreview({
|
|
19
|
+
slug,
|
|
20
|
+
stateId,
|
|
21
|
+
fallback,
|
|
22
|
+
className,
|
|
23
|
+
}: PrototypeStateScreenshotPreviewProps) {
|
|
24
|
+
const src = usePrototypeStateScreenshotSrc(slug, stateId);
|
|
25
|
+
const [failed, setFailed] = useState(false);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
setFailed(false);
|
|
29
|
+
}, [src]);
|
|
30
|
+
|
|
31
|
+
if (!src || failed) {
|
|
32
|
+
return <>{fallback}</>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<img
|
|
37
|
+
src={src}
|
|
38
|
+
alt=""
|
|
39
|
+
aria-hidden
|
|
40
|
+
width={THUMB_SIZE.width}
|
|
41
|
+
height={THUMB_SIZE.height}
|
|
42
|
+
decoding="sync"
|
|
43
|
+
className={cn("block h-full w-full object-cover object-top", className)}
|
|
44
|
+
onError={() => setFailed(true)}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useContext,
|
|
6
|
+
type ComponentPropsWithoutRef,
|
|
7
|
+
type ElementType,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
} from "react";
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
isAllowedComponentTargetId,
|
|
13
|
+
type PrototypeComponentRegistry,
|
|
14
|
+
} from "@prototype/lib/prototypes/prototype-component-registry";
|
|
15
|
+
import { cn } from "@prototype/lib/utils";
|
|
16
|
+
|
|
17
|
+
export const PROTOTYPE_TARGET_ATTR = "data-prototype-target";
|
|
18
|
+
|
|
19
|
+
const PrototypeSlugContext = createContext<string | null>(null);
|
|
20
|
+
const PrototypeRegistryContext =
|
|
21
|
+
createContext<PrototypeComponentRegistry | null>(null);
|
|
22
|
+
|
|
23
|
+
export function PrototypeTargetIdProvider({
|
|
24
|
+
slug,
|
|
25
|
+
registry,
|
|
26
|
+
children,
|
|
27
|
+
}: {
|
|
28
|
+
slug: string;
|
|
29
|
+
registry?: PrototypeComponentRegistry;
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
}) {
|
|
32
|
+
return (
|
|
33
|
+
<PrototypeSlugContext.Provider value={slug}>
|
|
34
|
+
<PrototypeRegistryContext.Provider value={registry ?? null}>
|
|
35
|
+
{children}
|
|
36
|
+
</PrototypeRegistryContext.Provider>
|
|
37
|
+
</PrototypeSlugContext.Provider>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function usePrototypeSlug(): string | null {
|
|
42
|
+
return useContext(PrototypeSlugContext);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function buildPrototypeTargetId(slug: string, id: string): string {
|
|
46
|
+
return `${slug}.${id}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function getPrototypeTargetElement(
|
|
50
|
+
element: HTMLElement | null,
|
|
51
|
+
): HTMLElement | null {
|
|
52
|
+
if (!element) return null;
|
|
53
|
+
const anchor = element.closest(`[${PROTOTYPE_TARGET_ATTR}]`);
|
|
54
|
+
return anchor instanceof HTMLElement ? anchor : null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function getPrototypeTargetIdFromElement(
|
|
58
|
+
element: HTMLElement | null,
|
|
59
|
+
): string | null {
|
|
60
|
+
const anchor = getPrototypeTargetElement(element);
|
|
61
|
+
if (!anchor) return null;
|
|
62
|
+
return anchor.getAttribute(PROTOTYPE_TARGET_ATTR);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type PrototypeTargetProps<T extends ElementType = "div"> = {
|
|
66
|
+
/** Registry segment id — must be listed in the prototype's component-ids.ts */
|
|
67
|
+
id: string;
|
|
68
|
+
label?: string;
|
|
69
|
+
as?: T;
|
|
70
|
+
className?: string;
|
|
71
|
+
children?: ReactNode;
|
|
72
|
+
} & Omit<ComponentPropsWithoutRef<T>, "as" | "id" | "children" | "className">;
|
|
73
|
+
|
|
74
|
+
function defaultLabel(id: string): string {
|
|
75
|
+
return id
|
|
76
|
+
.split(".")
|
|
77
|
+
.map((part) => part.replace(/-/g, " "))
|
|
78
|
+
.join(" — ");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function PrototypeTarget<T extends ElementType = "div">({
|
|
82
|
+
id,
|
|
83
|
+
label,
|
|
84
|
+
as,
|
|
85
|
+
className,
|
|
86
|
+
children,
|
|
87
|
+
...rest
|
|
88
|
+
}: PrototypeTargetProps<T>) {
|
|
89
|
+
const slug = usePrototypeSlug();
|
|
90
|
+
const componentRegistry = useContext(PrototypeRegistryContext);
|
|
91
|
+
const Component = (as ?? "div") as ElementType;
|
|
92
|
+
const fullId = slug ? buildPrototypeTargetId(slug, id) : id;
|
|
93
|
+
const displayLabel = label ?? defaultLabel(id);
|
|
94
|
+
|
|
95
|
+
if (
|
|
96
|
+
process.env.NODE_ENV !== "production" &&
|
|
97
|
+
componentRegistry &&
|
|
98
|
+
!isAllowedComponentTargetId(id, componentRegistry)
|
|
99
|
+
) {
|
|
100
|
+
console.error(
|
|
101
|
+
`[PrototypeTarget] Unregistered id "${id}". Add it to the prototype component-ids registry.`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<Component
|
|
107
|
+
{...rest}
|
|
108
|
+
className={cn(className)}
|
|
109
|
+
{...{
|
|
110
|
+
[PROTOTYPE_TARGET_ATTR]: fullId,
|
|
111
|
+
"data-element": displayLabel,
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
{children}
|
|
115
|
+
</Component>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Required root wrapper for every prototype UI component (see AGENTS.md). */
|
|
120
|
+
export const PrototypeComponent = PrototypeTarget;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { injectCaptureColorTokens } from "@prototype/lib/prototype-comments/core/capture-theme";
|
|
4
|
+
import { resolveAnnotationTargetById } from "@prototype/lib/prototype-comments/core/annotation-target";
|
|
5
|
+
import styles from "@prototype/lib/prototype-comments/ui/capture-styles.module.scss";
|
|
6
|
+
import { cn } from "@prototype/lib/utils";
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
8
|
+
import { createPortal } from "react-dom";
|
|
9
|
+
|
|
10
|
+
type HighlightRect = {
|
|
11
|
+
top: number;
|
|
12
|
+
left: number;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type PrototypeTweakHighlightProps = {
|
|
18
|
+
targetId: string;
|
|
19
|
+
onComplete: () => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Fade in, hold, then fade out. */
|
|
23
|
+
const HOLD_MS = 1500;
|
|
24
|
+
const FADE_MS = 250;
|
|
25
|
+
|
|
26
|
+
const HIGHLIGHT_BORDER =
|
|
27
|
+
"color-mix(in srgb, var(--prototype-comment-color-blue) 60%, transparent)";
|
|
28
|
+
const HIGHLIGHT_FILL =
|
|
29
|
+
"color-mix(in srgb, var(--prototype-comment-color-blue) 5%, transparent)";
|
|
30
|
+
|
|
31
|
+
function findTweakTarget(targetId: string): HTMLElement | null {
|
|
32
|
+
const byExact = resolveAnnotationTargetById(targetId);
|
|
33
|
+
if (byExact) return byExact;
|
|
34
|
+
|
|
35
|
+
const screenshotRoot = document.querySelector("[data-prototype-screenshot]");
|
|
36
|
+
return (
|
|
37
|
+
screenshotRoot?.querySelector<HTMLElement>(
|
|
38
|
+
`[data-prototype-target$=".${CSS.escape(targetId)}"]`,
|
|
39
|
+
) ?? null
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function PrototypeTweakHighlight({
|
|
44
|
+
targetId,
|
|
45
|
+
onComplete,
|
|
46
|
+
}: PrototypeTweakHighlightProps) {
|
|
47
|
+
const [mounted, setMounted] = useState(false);
|
|
48
|
+
const [rect, setRect] = useState<HighlightRect | null>(null);
|
|
49
|
+
const [isExiting, setIsExiting] = useState(false);
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
setMounted(true);
|
|
53
|
+
injectCaptureColorTokens();
|
|
54
|
+
}, []);
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (!mounted) return;
|
|
58
|
+
|
|
59
|
+
const updateRect = () => {
|
|
60
|
+
const element = findTweakTarget(targetId);
|
|
61
|
+
if (!element) {
|
|
62
|
+
setRect(null);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const nextRect = element.getBoundingClientRect();
|
|
67
|
+
setRect({
|
|
68
|
+
top: nextRect.top,
|
|
69
|
+
left: nextRect.left,
|
|
70
|
+
width: nextRect.width,
|
|
71
|
+
height: nextRect.height,
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
updateRect();
|
|
76
|
+
|
|
77
|
+
const retryTimer = window.setInterval(updateRect, 50);
|
|
78
|
+
const stopRetryTimer = window.setTimeout(
|
|
79
|
+
() => window.clearInterval(retryTimer),
|
|
80
|
+
400,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const reducedMotion = window.matchMedia(
|
|
84
|
+
"(prefers-reduced-motion: reduce)",
|
|
85
|
+
).matches;
|
|
86
|
+
|
|
87
|
+
const holdMs = reducedMotion ? 120 : HOLD_MS;
|
|
88
|
+
const fadeMs = reducedMotion ? 0 : FADE_MS;
|
|
89
|
+
|
|
90
|
+
const exitTimer = window.setTimeout(() => setIsExiting(true), holdMs + fadeMs);
|
|
91
|
+
const completeTimer = window.setTimeout(
|
|
92
|
+
onComplete,
|
|
93
|
+
holdMs + fadeMs * 2,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
window.addEventListener("scroll", updateRect, true);
|
|
97
|
+
window.addEventListener("resize", updateRect);
|
|
98
|
+
|
|
99
|
+
return () => {
|
|
100
|
+
window.clearInterval(retryTimer);
|
|
101
|
+
window.clearTimeout(stopRetryTimer);
|
|
102
|
+
window.clearTimeout(exitTimer);
|
|
103
|
+
window.clearTimeout(completeTimer);
|
|
104
|
+
window.removeEventListener("scroll", updateRect, true);
|
|
105
|
+
window.removeEventListener("resize", updateRect);
|
|
106
|
+
};
|
|
107
|
+
}, [mounted, onComplete, targetId]);
|
|
108
|
+
|
|
109
|
+
if (!mounted || !rect) return null;
|
|
110
|
+
|
|
111
|
+
return createPortal(
|
|
112
|
+
<div
|
|
113
|
+
aria-hidden
|
|
114
|
+
data-prototype-comment-accent="blue"
|
|
115
|
+
className={cn(
|
|
116
|
+
styles.singleSelectOutline,
|
|
117
|
+
isExiting ? styles.exit : styles.enter,
|
|
118
|
+
"z-[1045] motion-reduce:transition-none",
|
|
119
|
+
)}
|
|
120
|
+
style={{
|
|
121
|
+
top: rect.top,
|
|
122
|
+
left: rect.left,
|
|
123
|
+
width: rect.width,
|
|
124
|
+
height: rect.height,
|
|
125
|
+
borderColor: HIGHLIGHT_BORDER,
|
|
126
|
+
backgroundColor: HIGHLIGHT_FILL,
|
|
127
|
+
animationDuration: `${FADE_MS}ms`,
|
|
128
|
+
}}
|
|
129
|
+
/>,
|
|
130
|
+
document.body,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
focusPrototypeTweak,
|
|
5
|
+
registerPrototypeTweaks,
|
|
6
|
+
} from "@prototype/lib/prototypes/prototype-tweak-registry";
|
|
7
|
+
import type { PrototypeTweakDefinition } from "@prototype/lib/prototypes/prototype-tweak-types";
|
|
8
|
+
import { useLayoutEffect, useMemo, useRef } from "react";
|
|
9
|
+
|
|
10
|
+
export type PrototypeTweakConfig = PrototypeTweakDefinition & {
|
|
11
|
+
onNavigate: () => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type PrototypeTweaksProps = {
|
|
15
|
+
tweaks: PrototypeTweakConfig[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function PrototypeTweaks({ tweaks }: PrototypeTweaksProps) {
|
|
19
|
+
const navigateRef = useRef<Map<string, () => void>>(new Map());
|
|
20
|
+
|
|
21
|
+
const items = useMemo(() => {
|
|
22
|
+
const nextNavigate = new Map<string, () => void>();
|
|
23
|
+
const nextItems = tweaks.map((tweak) => {
|
|
24
|
+
nextNavigate.set(tweak.id, tweak.onNavigate);
|
|
25
|
+
return {
|
|
26
|
+
id: tweak.id,
|
|
27
|
+
label: tweak.label,
|
|
28
|
+
targetId: tweak.targetId,
|
|
29
|
+
category: tweak.category,
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
navigateRef.current = nextNavigate;
|
|
33
|
+
return nextItems;
|
|
34
|
+
}, [tweaks]);
|
|
35
|
+
|
|
36
|
+
useLayoutEffect(() => {
|
|
37
|
+
registerPrototypeTweaks({
|
|
38
|
+
items,
|
|
39
|
+
navigateTo: (id) => {
|
|
40
|
+
navigateRef.current.get(id)?.();
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}, [items]);
|
|
44
|
+
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { focusPrototypeTweak };
|