@garagem-ai/site-sdk 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -34
- package/dist/index.d.mts +51 -1
- package/dist/index.d.ts +51 -1
- package/dist/index.js +128 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +119 -0
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +212 -179
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +155 -122
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +13 -0
- package/src/react/listing-card.tsx +64 -52
- package/src/react/search-chrome.tsx +14 -12
- package/src/react/styles/search-chrome-css.generated.ts +1 -1
- package/src/react/styles/search-chrome-styles.tsx +22 -3
- package/src/studio-contract.ts +138 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@garagem-ai/site-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Typed, runtime-agnostic SDK for building custom real estate sites against the Garagem platform. Drop into any Next.js (or other JS) project to fetch listings, sites and CMS data.",
|
|
6
6
|
"main": "./dist/index.js",
|
package/src/index.ts
CHANGED
|
@@ -153,6 +153,19 @@ export {
|
|
|
153
153
|
type ResolvePublicSiteIdOptions,
|
|
154
154
|
} from "./resolve-site-id";
|
|
155
155
|
|
|
156
|
+
export {
|
|
157
|
+
STUDIO_SDK_CONTRACT,
|
|
158
|
+
STUDIO_SDK_PACKAGE,
|
|
159
|
+
coerceNpmVersion,
|
|
160
|
+
compareSemver,
|
|
161
|
+
parseReactSdkNamedImports,
|
|
162
|
+
studioChromeInstruction,
|
|
163
|
+
studioCodegenContractViolations,
|
|
164
|
+
studioSdkPinInstruction,
|
|
165
|
+
unavailableReactImports,
|
|
166
|
+
type StudioSdkContract,
|
|
167
|
+
} from "./studio-contract";
|
|
168
|
+
|
|
156
169
|
export {
|
|
157
170
|
createGaragemClient,
|
|
158
171
|
type CreateGaragemClientOptions,
|
|
@@ -7,6 +7,7 @@ import { formatAreaM2 } from "../presentation";
|
|
|
7
7
|
import { toListingCardModel } from "../listing-card-model";
|
|
8
8
|
import type { Listing } from "../types";
|
|
9
9
|
import { cn } from "./cn";
|
|
10
|
+
import { SearchChromeStyles } from "./styles";
|
|
10
11
|
import type { ListingCardProps } from "./types";
|
|
11
12
|
|
|
12
13
|
function isListing(value: ListingCardProps["listing"]): value is Listing {
|
|
@@ -27,60 +28,71 @@ export function ListingCard({
|
|
|
27
28
|
const target = href ?? model.href;
|
|
28
29
|
const areaLabel = formatAreaM2(model.areaM2);
|
|
29
30
|
return (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
31
|
+
<>
|
|
32
|
+
<SearchChromeStyles />
|
|
33
|
+
<article
|
|
34
|
+
data-slot="listing-card"
|
|
35
|
+
className={cn(className, classNames?.root)}
|
|
36
|
+
style={style}
|
|
37
|
+
>
|
|
38
|
+
<Link href={target} data-slot="listing-card-link">
|
|
39
|
+
<div data-slot="listing-card-media" className={classNames?.media}>
|
|
40
|
+
{slots?.media ??
|
|
41
|
+
(model.coverSrc ? (
|
|
42
|
+
<img src={model.coverSrc} alt={model.coverAlt} />
|
|
43
|
+
) : (
|
|
44
|
+
<div data-slot="listing-card-empty">Sem foto</div>
|
|
45
|
+
))}
|
|
46
|
+
{slots?.badge ?? (
|
|
47
|
+
<span
|
|
48
|
+
data-slot="listing-card-badge"
|
|
49
|
+
className={classNames?.badge}
|
|
50
|
+
>
|
|
51
|
+
{model.businessLabel}
|
|
52
|
+
</span>
|
|
53
|
+
)}
|
|
54
|
+
</div>
|
|
55
|
+
<div data-slot="listing-card-body" className={classNames?.body}>
|
|
56
|
+
<div data-slot="listing-card-price-row">
|
|
57
|
+
<p data-slot="listing-card-price" className={classNames?.price}>
|
|
58
|
+
{model.priceLabel}
|
|
59
|
+
</p>
|
|
60
|
+
{model.pricePeriod ? (
|
|
61
|
+
<span data-slot="listing-card-period">{model.pricePeriod}</span>
|
|
62
|
+
) : null}
|
|
63
|
+
</div>
|
|
64
|
+
<h3 data-slot="listing-card-title" className={classNames?.title}>
|
|
65
|
+
{model.title}
|
|
66
|
+
</h3>
|
|
67
|
+
<p
|
|
68
|
+
data-slot="listing-card-location"
|
|
69
|
+
className={classNames?.location}
|
|
70
|
+
>
|
|
71
|
+
{model.locationLabel || model.propertyType || ""}
|
|
53
72
|
</p>
|
|
54
|
-
|
|
55
|
-
|
|
73
|
+
<ul
|
|
74
|
+
data-slot="listing-card-features"
|
|
75
|
+
className={classNames?.features}
|
|
76
|
+
>
|
|
77
|
+
{model.bedrooms != null ? (
|
|
78
|
+
<li>{model.bedrooms} quartos</li>
|
|
79
|
+
) : null}
|
|
80
|
+
{model.bathrooms != null ? (
|
|
81
|
+
<li>{model.bathrooms} banheiros</li>
|
|
82
|
+
) : null}
|
|
83
|
+
{model.parkingSpaces != null ? (
|
|
84
|
+
<li>{model.parkingSpaces} vagas</li>
|
|
85
|
+
) : null}
|
|
86
|
+
{areaLabel ? <li>{areaLabel}</li> : null}
|
|
87
|
+
</ul>
|
|
88
|
+
{slots?.cta ? (
|
|
89
|
+
<div data-slot="listing-card-cta" className={classNames?.cta}>
|
|
90
|
+
{slots.cta}
|
|
91
|
+
</div>
|
|
56
92
|
) : null}
|
|
57
93
|
</div>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
<p data-slot="listing-card-location" className={classNames?.location}>
|
|
62
|
-
{model.locationLabel || model.propertyType || ""}
|
|
63
|
-
</p>
|
|
64
|
-
<ul
|
|
65
|
-
data-slot="listing-card-features"
|
|
66
|
-
className={classNames?.features}
|
|
67
|
-
>
|
|
68
|
-
{model.bedrooms != null ? <li>{model.bedrooms} quartos</li> : null}
|
|
69
|
-
{model.bathrooms != null ? (
|
|
70
|
-
<li>{model.bathrooms} banheiros</li>
|
|
71
|
-
) : null}
|
|
72
|
-
{model.parkingSpaces != null ? (
|
|
73
|
-
<li>{model.parkingSpaces} vagas</li>
|
|
74
|
-
) : null}
|
|
75
|
-
{areaLabel ? <li>{areaLabel}</li> : null}
|
|
76
|
-
</ul>
|
|
77
|
-
{slots?.cta ? (
|
|
78
|
-
<div data-slot="listing-card-cta" className={classNames?.cta}>
|
|
79
|
-
{slots.cta}
|
|
80
|
-
</div>
|
|
81
|
-
) : null}
|
|
82
|
-
</div>
|
|
83
|
-
</Link>
|
|
84
|
-
</article>
|
|
94
|
+
</Link>
|
|
95
|
+
</article>
|
|
96
|
+
</>
|
|
85
97
|
);
|
|
86
98
|
}
|
|
@@ -44,18 +44,21 @@ export function ResultsSkeleton({
|
|
|
44
44
|
className?: string;
|
|
45
45
|
}): ReactElement {
|
|
46
46
|
return (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
<div data-slot="search-skeleton-
|
|
52
|
-
<div data-slot="search-skeleton-block" data-kind="
|
|
53
|
-
<div data-slot="search-skeleton-
|
|
54
|
-
|
|
47
|
+
<>
|
|
48
|
+
<SearchChromeStyles />
|
|
49
|
+
<div data-slot="search-skeleton" className={className}>
|
|
50
|
+
{Array.from({ length: 6 }, (_, i) => (
|
|
51
|
+
<div key={i} data-slot="search-skeleton-card">
|
|
52
|
+
<div data-slot="search-skeleton-block" data-kind="media" />
|
|
53
|
+
<div data-slot="search-skeleton-body">
|
|
54
|
+
<div data-slot="search-skeleton-block" data-kind="line-lg" />
|
|
55
|
+
<div data-slot="search-skeleton-block" data-kind="line-md" />
|
|
56
|
+
<div data-slot="search-skeleton-block" data-kind="line-sm" />
|
|
57
|
+
</div>
|
|
55
58
|
</div>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
))}
|
|
60
|
+
</div>
|
|
61
|
+
</>
|
|
59
62
|
);
|
|
60
63
|
}
|
|
61
64
|
|
|
@@ -66,7 +69,6 @@ export function SearchPageFallback({
|
|
|
66
69
|
}): ReactElement {
|
|
67
70
|
return (
|
|
68
71
|
<main data-slot="search-page">
|
|
69
|
-
<SearchChromeStyles />
|
|
70
72
|
<ResultsSkeleton className={className} />
|
|
71
73
|
</main>
|
|
72
74
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* Generated by scripts/build-search-chrome-css.mjs — do not edit. */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
/* prettier-ignore */
|
|
4
|
-
export const SEARCH_CHROME_CSS_VERSION = "0.4.
|
|
4
|
+
export const SEARCH_CHROME_CSS_VERSION = "0.4.2";
|
|
5
5
|
export const SEARCH_CHROME_CSS = ":root{--garagem-listing-card-radius:0.75rem;--garagem-listing-card-gap:1.5rem;--garagem-listing-price-size:1.125rem;--garagem-listing-media-ratio:4 / 3;--garagem-search-control-height:2.75rem;--garagem-search-icon-size:1.25rem;--garagem-search-radius:var(--radius,0.75rem);--garagem-skeleton:var(--muted,#e7e5e4)}[data-slot=\"search-page\"]{margin-inline:auto;max-width:80rem;padding:3rem 1.5rem}[data-slot=\"search-heading\"]{display:flex;min-width:0;align-items:baseline;gap:0.375rem;font-size:1.25rem;font-weight:600}[data-slot=\"search-heading-count\"]{flex-shrink:0}[data-slot=\"search-heading-title\"]{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:inherit;font-weight:inherit}[data-slot=\"search-query-sort\"]{display:flex;flex-direction:column;gap:1rem}@media (min-width:1024px){[data-slot=\"search-query-sort\"]{flex-direction:row;align-items:flex-end}}[data-slot=\"search-query\"]{flex:1;min-width:0}[data-slot=\"search-query-input\"],[data-slot=\"search-sort-trigger\"],[data-slot=\"search-toolbar-trigger\"],[data-slot=\"search-filters-trigger\"]{min-height:var(--garagem-search-control-height)}[data-slot=\"search-query-field\"]{position:relative}[data-slot=\"search-query-input\"]{width:100%;border-radius:var(--garagem-search-radius);border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:0.5rem 5.5rem 0.5rem 1rem;outline:none}[data-slot=\"search-query-actions\"]{position:absolute;top:50%;right:0.35rem;display:flex;transform:translateY(-50%);align-items:center;gap:0.15rem}[data-slot=\"search-icon-button\"]{display:inline-flex;height:2.25rem;width:2.25rem;cursor:pointer;align-items:center;justify-content:center;border:0;border-radius:999px;background:var(--primary,#111);color:var(--primary-foreground,#fff)}[data-slot=\"search-icon-button\"][data-kind=\"clear\"]{background:transparent;color:var(--muted-foreground,#737373)}[data-slot=\"search-icon\"]{width:var(--garagem-search-icon-size);height:var(--garagem-search-icon-size);display:block}[data-slot=\"search-sort\"]{display:flex;flex-direction:column;gap:0.25rem}[data-slot=\"search-sort-trigger\"]{appearance:none;cursor:pointer;border-radius:var(--garagem-search-radius);border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:0.5rem 2.25rem 0.5rem 0.75rem;background-image:url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23737373' stroke-width='2' viewBox='0 0 24 24'><path d='m6 9 6 6 6-6'/></svg>\");background-repeat:no-repeat;background-position:right 0.65rem center}[data-slot=\"search-toolbar\"]{display:flex;flex-wrap:wrap;align-items:flex-end;gap:0.5rem}[data-slot=\"search-toolbar-trigger\"],[data-slot=\"search-filters-trigger\"]{cursor:pointer;border-radius:var(--garagem-search-radius);border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:0.5rem 0.75rem;font-size:0.875rem}[data-slot=\"search-popover\"]{position:absolute;z-index:30;margin-top:0.5rem;width:18rem;border-radius:0.75rem;border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:1rem;box-shadow:0 10px 30px rgb(0 0 0 / 0.12);animation:garagem-search-in 140ms ease-out}[data-slot=\"search-grid\"],[data-slot=\"search-skeleton\"]{display:grid;grid-template-columns:1fr;gap:var(--garagem-listing-card-gap)}@media (min-width:640px){[data-slot=\"search-grid\"],[data-slot=\"search-skeleton\"]{grid-template-columns:repeat(2,minmax(0,1fr))}}@media (min-width:1024px){[data-slot=\"search-grid\"],[data-slot=\"search-skeleton\"]{grid-template-columns:repeat(3,minmax(0,1fr))}}[data-slot=\"listing-card\"]{overflow:hidden;border-radius:var(--garagem-listing-card-radius);border:1px solid var(--border,#e4e4e7);background:var(--card,var(--background,#fff))}[data-slot=\"listing-card-price-row\"]{display:inline-flex;align-items:baseline;gap:0.25rem}[data-slot=\"listing-card-price\"]{font-size:var(--garagem-listing-price-size);font-weight:600}[data-slot=\"listing-card-period\"]{font-size:0.75rem;color:var(--muted-foreground,#737373)}[data-slot=\"search-checkbox\"]{appearance:none;width:1.15rem;height:1.15rem;flex-shrink:0;cursor:pointer;border:1px solid var(--primary,#111);border-radius:0.25rem;background:var(--background,#fff)}[data-slot=\"search-checkbox\"]:checked{background-color:var(--primary,#111);background-image:url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3'><path d='M5 12l5 5L20 7'/></svg>\");background-repeat:no-repeat;background-position:center;background-size:0.8rem}[data-slot=\"search-scroll\"]{max-height:12rem;overflow:auto;scrollbar-width:thin;scrollbar-color:var(--muted-foreground,#a1a1aa) transparent}[data-slot=\"search-range-apply\"]{display:inline-flex;min-height:2.5rem;cursor:pointer;align-items:center;justify-content:center;border:0;border-radius:var(--garagem-search-radius);background:var(--primary,#111);color:var(--primary-foreground,#fff);padding:0 0.75rem;font-size:0.75rem;font-weight:600}[data-slot=\"search-sheet\"]{position:fixed;inset:0;z-index:40}[data-slot=\"search-sheet-overlay\"]{position:absolute;inset:0;border:0;cursor:pointer;background:rgb(0 0 0 / 0.4);animation:garagem-search-fade 160ms ease-out}[data-slot=\"search-sheet-panel\"]{position:absolute;top:0;right:0;display:flex;height:100dvh;width:min(22rem,100%);flex-direction:column;background:var(--background,#fff);animation:garagem-search-sheet 180ms ease-out}[data-slot=\"search-sheet-body\"]{min-height:0;flex:1;overflow:auto;padding:1.5rem 1.5rem 0;scrollbar-width:thin}[data-slot=\"search-sheet-footer\"]{display:flex;gap:0.5rem;border-top:1px solid var(--border,#e4e4e7);padding:1rem 1.5rem}[data-slot=\"search-apply-bar\"]{display:flex;width:100%;gap:0.5rem}[data-slot=\"search-apply-bar\"] > button{min-height:2.5rem;flex:1;cursor:pointer;border-radius:var(--garagem-search-radius);padding:0 1rem}[data-slot=\"search-apply-bar\"] > button[data-kind=\"clear\"]{border:1px solid var(--border,#e4e4e7);background:transparent}[data-slot=\"search-apply-bar\"] > button[data-kind=\"apply\"]{border:0;background:var(--primary,#111);color:var(--primary-foreground,#fff);font-weight:600}[data-slot=\"search-pagination\"]{margin-top:2.5rem;display:flex;justify-content:center}[data-slot=\"search-pagination\"] ul{display:flex;flex-wrap:wrap;justify-content:center;gap:0.25rem;padding:0;margin:0;list-style:none}[data-slot=\"search-pagination-item\"]{display:inline-flex;width:2.25rem;height:2.25rem;align-items:center;justify-content:center;border:1px solid var(--border,#e4e4e7);border-radius:0.375rem;font-size:0.75rem;font-weight:500}@media (min-width:768px){[data-slot=\"search-pagination-item\"]{width:2.5rem;height:2.5rem}}[data-slot=\"search-pagination-item\"] a,[data-slot=\"search-pagination-item\"] span{display:flex;width:100%;height:100%;align-items:center;justify-content:center;color:inherit;text-decoration:none}[data-slot=\"search-pagination-item\"][data-current=\"true\"]{background:var(--primary,#111);color:var(--primary-foreground,#fff)}[data-slot=\"search-pagination-item\"][data-disabled=\"true\"]{cursor:not-allowed;color:var(--muted-foreground,#737373)}[data-slot=\"search-toolbar-item\"]{position:relative}[data-slot=\"search-body\"]{margin-top:2rem;display:flex;flex-direction:column;gap:1.5rem}[data-slot=\"search-label\"]{margin-bottom:0.25rem;display:block;font-size:0.875rem;color:var(--muted-foreground,#737373)}[data-slot=\"search-sheet-title\"]{padding:1.5rem 1.5rem 0;font-size:1.125rem;font-weight:600}[data-slot=\"search-layout\"]{display:grid;gap:2rem}[data-slot=\"search-sidebar\"]{display:none}[data-slot=\"search-layout\"] > div > [data-slot=\"search-filters-trigger\"]{margin-bottom:1rem}@media (min-width:1024px){[data-slot=\"search-layout\"]{grid-template-columns:280px minmax(0,1fr)}[data-slot=\"search-sidebar\"]{display:block;position:sticky;top:1.5rem;align-self:start}[data-slot=\"search-layout\"] > div > [data-slot=\"search-filters-trigger\"]{display:none}}[data-slot=\"listing-card-link\"]{display:block;color:inherit;text-decoration:none;cursor:pointer}[data-slot=\"listing-card-media\"]{position:relative;width:100%;overflow:hidden;background:var(--muted,#f5f5f4);aspect-ratio:var(--garagem-listing-media-ratio)}[data-slot=\"listing-card-media\"] img{height:100%;width:100%;object-fit:cover;transition:transform 0.3s}[data-slot=\"listing-card\"]:hover [data-slot=\"listing-card-media\"] img{transform:scale(1.05)}@media (prefers-reduced-motion:reduce){[data-slot=\"listing-card-media\"] img{transition:none}[data-slot=\"listing-card\"]:hover [data-slot=\"listing-card-media\"] img{transform:none}}[data-slot=\"listing-card-empty\"]{display:flex;height:100%;width:100%;align-items:center;justify-content:center;font-size:0.75rem;color:var(--muted-foreground,#737373)}[data-slot=\"listing-card-cta\"]{margin-top:0.75rem}[data-slot=\"search-filters\"]{display:flex;flex-direction:column;gap:1.25rem}[data-slot=\"search-filter\"]{margin:0;padding:0;border:0;font-size:0.875rem}[data-slot=\"search-filter\"] legend{margin-bottom:0.5rem;padding:0;color:var(--muted-foreground,#737373)}[data-slot=\"search-range-row\"]{display:flex;align-items:flex-end;gap:0.5rem}[data-slot=\"search-range-side\"]{min-width:0;flex:1}[data-slot=\"search-range-side\"] > span:first-child{margin-bottom:0.25rem;display:block;font-size:0.75rem;color:var(--muted-foreground,#737373)}[data-slot=\"search-range-affix\"]{position:relative;display:block}[data-slot=\"search-range-prefix\"]{pointer-events:none;position:absolute;inset-block:0;left:0;display:flex;align-items:center;padding-left:0.75rem;color:var(--muted-foreground,#737373)}[data-slot=\"search-range-input\"]{min-height:2.5rem;width:100%;border-radius:var(--garagem-search-radius);border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:0 0.75rem}[data-slot=\"search-range-affix\"] [data-slot=\"search-range-input\"]{padding-left:2.5rem}[data-slot=\"search-count-group\"]{display:flex;flex-wrap:wrap;gap:0.375rem}[data-slot=\"search-count-choice\"]{min-height:2.5rem;cursor:pointer;border-radius:var(--garagem-search-radius);border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:0 0.75rem;font-size:0.875rem}[data-slot=\"search-count-choice\"][data-selected=\"true\"]{border-color:var(--primary,#111);background:color-mix(in srgb,var(--primary,#111) 10%,transparent)}[data-slot=\"search-enum-list\"],[data-slot=\"search-scroll\"]{display:flex;flex-direction:column;gap:0.375rem}[data-slot=\"search-enum-option\"]{display:flex;cursor:pointer;align-items:center;gap:0.5rem}[data-slot=\"listing-card-badge\"]{position:absolute;left:0.75rem;top:0.75rem;border-radius:999px;background:color-mix(in srgb,var(--background,#fff) 90%,transparent);padding:0.25rem 0.5rem;font-size:0.75rem;font-weight:500}[data-slot=\"listing-card-body\"]{padding:1rem}[data-slot=\"listing-card-title\"]{display:-webkit-box;margin-top:0.25rem;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1;font-size:0.875rem;font-weight:500}[data-slot=\"listing-card-location\"]{margin-top:0.125rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:0.75rem;color:var(--muted-foreground,#737373)}[data-slot=\"listing-card-features\"]{display:flex;flex-wrap:wrap;margin-top:0.75rem;gap:0.25rem 1rem;padding:0;list-style:none;font-size:0.75rem;color:var(--muted-foreground,#737373)}[data-slot=\"search-skeleton-block\"]{animation:garagem-search-pulse 1.2s ease-in-out infinite;background:var(--garagem-skeleton);border-radius:0.375rem}[data-slot=\"search-skeleton-card\"]{overflow:hidden;border-radius:var(--garagem-listing-card-radius);border:1px solid var(--border,#e4e4e7)}[data-slot=\"search-skeleton-body\"]{display:flex;flex-direction:column;gap:0.5rem;padding:1rem}[data-slot=\"search-skeleton-block\"][data-kind=\"media\"]{aspect-ratio:var(--garagem-listing-media-ratio)}[data-slot=\"search-skeleton-block\"][data-kind=\"line-lg\"]{height:1.25rem;width:50%}[data-slot=\"search-skeleton-block\"][data-kind=\"line-md\"]{height:1rem;width:75%}[data-slot=\"search-skeleton-block\"][data-kind=\"line-sm\"]{height:0.75rem;width:66.666667%}[data-slot=\"search-skeleton-block\"][data-kind=\"detail-media\"]{max-width:45rem;aspect-ratio:4 / 3}[data-slot=\"search-skeleton-block\"][data-kind=\"detail-title\"]{width:66.666667%;height:2rem;margin-top:1.5rem}@media (prefers-reduced-motion:reduce){[data-slot=\"search-popover\"],[data-slot=\"search-sheet-overlay\"],[data-slot=\"search-sheet-panel\"],[data-slot=\"search-skeleton-block\"]{animation:none}}@keyframes garagem-search-in{from{opacity:0;transform:translateY(-4px) scale(0.98)}to{opacity:1;transform:none}}@keyframes garagem-search-fade{from{opacity:0}to{opacity:1}}@keyframes garagem-search-sheet{from{transform:translateX(100%)}to{transform:none}}@keyframes garagem-search-pulse{50%{opacity:0.55}}";
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useLayoutEffect, type ReactElement } from "react";
|
|
2
4
|
|
|
3
5
|
import {
|
|
4
6
|
SEARCH_CHROME_CSS,
|
|
@@ -7,6 +9,23 @@ import {
|
|
|
7
9
|
|
|
8
10
|
const STYLE_ID = `garagem-search-chrome-${SEARCH_CHROME_CSS_VERSION}`;
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
/** Append once to document.head — never a React child (unmount must not remove it). */
|
|
13
|
+
function injectSearchChromeOnce(): void {
|
|
14
|
+
if (typeof document === "undefined") return;
|
|
15
|
+
if (document.getElementById(STYLE_ID)) return;
|
|
16
|
+
const el = document.createElement("style");
|
|
17
|
+
el.id = STYLE_ID;
|
|
18
|
+
el.textContent = SEARCH_CHROME_CSS;
|
|
19
|
+
document.head.appendChild(el);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function SearchChromeStyles(): ReactElement | null {
|
|
23
|
+
// Client render: inject before paint (Studio / v0 are client-heavy grids).
|
|
24
|
+
if (typeof document !== "undefined") {
|
|
25
|
+
injectSearchChromeOnce();
|
|
26
|
+
}
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
injectSearchChromeOnce();
|
|
29
|
+
}, []);
|
|
30
|
+
return null;
|
|
12
31
|
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Studio ↔ npm contract. Prompt, completeness, and recipes must read this
|
|
3
|
+
* object — do not keep a second list of required `@garagem-ai/site-sdk/react`
|
|
4
|
+
* names in apps/site.
|
|
5
|
+
*
|
|
6
|
+
* `minNpmVersion` is the tarball v0 actually installs. Optional exports exist
|
|
7
|
+
* in git and may already be on npm, but Studio codegen must not name them
|
|
8
|
+
* while chromeStrategy is self-inject (v0 copies identifiers; a layout tag
|
|
9
|
+
* also breaks the pancake stack).
|
|
10
|
+
*/
|
|
11
|
+
export const STUDIO_SDK_PACKAGE = "@garagem-ai/site-sdk" as const;
|
|
12
|
+
|
|
13
|
+
export const STUDIO_SDK_CONTRACT = {
|
|
14
|
+
package: STUDIO_SDK_PACKAGE,
|
|
15
|
+
/**
|
|
16
|
+
* Exact pin for generated Studio sites. Must be ≥ `selfInjectSince` so
|
|
17
|
+
* prompts that skip the layout chrome tag match the tarball v0 installs.
|
|
18
|
+
* This PR’s changeset publishes that tarball as 0.4.2 — do not generate
|
|
19
|
+
* against this floor until Version Packages is on npm.
|
|
20
|
+
*/
|
|
21
|
+
minNpmVersion: "0.4.2",
|
|
22
|
+
/** First release where ListingCard and ResultsSkeleton inject the sheet. */
|
|
23
|
+
selfInjectSince: "0.4.2",
|
|
24
|
+
chromeStrategy: "self-inject" as const,
|
|
25
|
+
reactExports: [
|
|
26
|
+
"SearchPage",
|
|
27
|
+
"ListingCard",
|
|
28
|
+
"usePublicSearch",
|
|
29
|
+
"ResultsSkeleton",
|
|
30
|
+
] as const,
|
|
31
|
+
/**
|
|
32
|
+
* Names that exist in git / the unpublished patch. Completeness treats an
|
|
33
|
+
* import as `sdk-export-mismatch` when the generated pin is older than
|
|
34
|
+
* `since`. Studio prompts must not mention these names at all (even as
|
|
35
|
+
* “never import”) — v0 copies the identifier and the preview ESM loader
|
|
36
|
+
* throws FatalRendererError.
|
|
37
|
+
*/
|
|
38
|
+
optionalReactExports: {
|
|
39
|
+
SearchPageFallback: "0.4.1",
|
|
40
|
+
SearchChromeStyles: "0.4.1",
|
|
41
|
+
} as const,
|
|
42
|
+
forbiddenImports: ["@garagem-ai/site-sdk/react/search.css"] as const,
|
|
43
|
+
} as const;
|
|
44
|
+
|
|
45
|
+
export type StudioSdkContract = typeof STUDIO_SDK_CONTRACT;
|
|
46
|
+
|
|
47
|
+
const REACT_SDK_NAMED_IMPORT_RE =
|
|
48
|
+
/(?:^|[\n;])\s*import\s+(?!type\b)(?:type\s+)?\{([^}]+)\}\s+from\s+['"]@garagem-ai\/site-sdk\/react['"]/g;
|
|
49
|
+
|
|
50
|
+
export function coerceNpmVersion(raw: unknown): string | null {
|
|
51
|
+
if (typeof raw !== "string") return null;
|
|
52
|
+
const match = raw.trim().match(/(\d+)\.(\d+)\.(\d+)/);
|
|
53
|
+
return match ? `${match[1]}.${match[2]}.${match[3]}` : null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function compareSemver(a: string, b: string): number {
|
|
57
|
+
const left = a.split(".").map((part) => Number(part));
|
|
58
|
+
const right = b.split(".").map((part) => Number(part));
|
|
59
|
+
for (let i = 0; i < 3; i += 1) {
|
|
60
|
+
const delta = (left[i] ?? 0) - (right[i] ?? 0);
|
|
61
|
+
if (delta !== 0) return delta;
|
|
62
|
+
}
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function parseReactSdkNamedImports(source: string): string[] {
|
|
67
|
+
const names: string[] = [];
|
|
68
|
+
REACT_SDK_NAMED_IMPORT_RE.lastIndex = 0;
|
|
69
|
+
let match: RegExpExecArray | null;
|
|
70
|
+
while ((match = REACT_SDK_NAMED_IMPORT_RE.exec(source)) !== null) {
|
|
71
|
+
const body = match[1];
|
|
72
|
+
if (!body) continue;
|
|
73
|
+
for (const raw of body.split(",")) {
|
|
74
|
+
const token = raw.trim();
|
|
75
|
+
if (!token || token.startsWith("type ")) continue;
|
|
76
|
+
const name = token.split(/\s+as\s+/)[0]?.trim();
|
|
77
|
+
if (name) names.push(name);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return names;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function reactExportsAvailableAt(pin: string): Set<string> {
|
|
84
|
+
const available = new Set<string>(STUDIO_SDK_CONTRACT.reactExports);
|
|
85
|
+
for (const [name, since] of Object.entries(
|
|
86
|
+
STUDIO_SDK_CONTRACT.optionalReactExports
|
|
87
|
+
)) {
|
|
88
|
+
if (compareSemver(pin, since) >= 0) available.add(name);
|
|
89
|
+
}
|
|
90
|
+
return available;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function unavailableReactImports(source: string, pin: string): string[] {
|
|
94
|
+
const available = reactExportsAvailableAt(pin);
|
|
95
|
+
const missing: string[] = [];
|
|
96
|
+
for (const name of parseReactSdkNamedImports(source)) {
|
|
97
|
+
if (!available.has(name) && !missing.includes(name)) {
|
|
98
|
+
missing.push(name);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return missing;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function studioSdkPinInstruction(): string {
|
|
105
|
+
const version = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
106
|
+
const names = STUDIO_SDK_CONTRACT.reactExports.join(", ");
|
|
107
|
+
return `In \`package.json\` set \`"@garagem-ai/site-sdk": "${version}"\` (exact). Import only these \`${STUDIO_SDK_PACKAGE}/react\` names: ${names}.`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function studioChromeInstruction(): string {
|
|
111
|
+
const injectors =
|
|
112
|
+
compareSemver(
|
|
113
|
+
STUDIO_SDK_CONTRACT.minNpmVersion,
|
|
114
|
+
STUDIO_SDK_CONTRACT.selfInjectSince
|
|
115
|
+
) >= 0
|
|
116
|
+
? "`SearchPage`, `ListingCard`, and `ResultsSkeleton`"
|
|
117
|
+
: "`SearchPage`";
|
|
118
|
+
return `Search chrome CSS is injected by ${injectors} (JS \`<style>\` tag). Never \`import "@garagem-ai/site-sdk/react/search.css"\` — v0 preview cannot load npm CSS. Do not copy SDK layout into the app. Theme via CSS variables in \`app/globals.css\` (\`SEARCH_CSS_RECIPE\` / \`--garagem-*\`), \`classNames\`, and \`data-slot\`.`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Tokens that must not appear in Studio codegen (prompts, recipes, repair).
|
|
123
|
+
* v0 copies identifiers it sees, even inside “never import X”.
|
|
124
|
+
*/
|
|
125
|
+
export function studioCodegenContractViolations(text: string): string[] {
|
|
126
|
+
const violations: string[] = [];
|
|
127
|
+
for (const name of Object.keys(STUDIO_SDK_CONTRACT.optionalReactExports)) {
|
|
128
|
+
if (text.includes(name)) violations.push(name);
|
|
129
|
+
}
|
|
130
|
+
const pin = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
131
|
+
const available = reactExportsAvailableAt(pin);
|
|
132
|
+
for (const name of parseReactSdkNamedImports(text)) {
|
|
133
|
+
if (!available.has(name) && !violations.includes(name)) {
|
|
134
|
+
violations.push(name);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return violations;
|
|
138
|
+
}
|