@garagem-ai/site-sdk 0.4.0 → 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 +29 -9
- package/dist/index.d.mts +57 -58
- package/dist/index.d.ts +57 -58
- package/dist/index.js +187 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +176 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +33 -6
- package/dist/react.d.ts +33 -6
- package/dist/react.js +573 -486
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +542 -456
- package/dist/react.mjs.map +1 -1
- package/dist/{listing-card-model-D7iR4asd.d.mts → search-engine-D4EZkNrQ.d.mts} +67 -1
- package/dist/{listing-card-model-D7iR4asd.d.ts → search-engine-D4EZkNrQ.d.ts} +67 -1
- package/package.json +9 -4
- package/src/index.ts +15 -0
- package/src/presentation.ts +7 -0
- package/src/react/filter-panel.tsx +39 -42
- package/src/react/icons.tsx +46 -0
- package/src/react/index.ts +7 -1
- package/src/react/listing-card.tsx +61 -106
- package/src/react/search-chrome.tsx +30 -27
- package/src/react/search-page.tsx +210 -111
- package/src/react/search-pagination.tsx +50 -40
- package/src/react/search-query-form.tsx +31 -26
- package/src/react/search.css +717 -0
- package/src/react/styles/index.ts +1 -0
- package/src/react/styles/search-chrome-css.generated.ts +5 -0
- package/src/react/styles/search-chrome-styles.tsx +31 -0
- package/src/react/types.ts +18 -0
- package/src/react/use-public-search.ts +7 -0
- package/src/search-engine.ts +79 -0
- package/src/studio-contract.ts +138 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/* Generated by scripts/build-search-chrome-css.mjs — do not edit. */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/* prettier-ignore */
|
|
4
|
+
export const SEARCH_CHROME_CSS_VERSION = "0.4.2";
|
|
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}}";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useLayoutEffect, type ReactElement } from "react";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
SEARCH_CHROME_CSS,
|
|
7
|
+
SEARCH_CHROME_CSS_VERSION,
|
|
8
|
+
} from "./search-chrome-css.generated";
|
|
9
|
+
|
|
10
|
+
const STYLE_ID = `garagem-search-chrome-${SEARCH_CHROME_CSS_VERSION}`;
|
|
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;
|
|
31
|
+
}
|
package/src/react/types.ts
CHANGED
|
@@ -7,20 +7,37 @@ import type {
|
|
|
7
7
|
SearchUi,
|
|
8
8
|
} from "../types";
|
|
9
9
|
import type { ListingCardModel } from "../listing-card-model";
|
|
10
|
+
import type { LocationNameTables } from "../search-engine";
|
|
10
11
|
|
|
11
12
|
export type SearchPageVariant = "toolbar" | "dialog" | "sidebar";
|
|
12
13
|
|
|
13
14
|
export type SearchPageClassNames = {
|
|
14
15
|
root?: string;
|
|
15
16
|
header?: string;
|
|
17
|
+
heading?: string;
|
|
18
|
+
headingCount?: string;
|
|
19
|
+
headingTitle?: string;
|
|
16
20
|
toolbar?: string;
|
|
21
|
+
toolbarTrigger?: string;
|
|
22
|
+
popover?: string;
|
|
17
23
|
query?: string;
|
|
24
|
+
sort?: string;
|
|
25
|
+
icon?: string;
|
|
18
26
|
sidebar?: string;
|
|
19
27
|
dialog?: string;
|
|
28
|
+
dialogOverlay?: string;
|
|
29
|
+
dialogPanel?: string;
|
|
20
30
|
grid?: string;
|
|
21
31
|
card?: string;
|
|
22
32
|
pagination?: string;
|
|
23
33
|
applyBar?: string;
|
|
34
|
+
skeleton?: string;
|
|
35
|
+
checkbox?: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type SearchPageIcons = {
|
|
39
|
+
search?: ReactNode;
|
|
40
|
+
clear?: ReactNode;
|
|
24
41
|
};
|
|
25
42
|
|
|
26
43
|
export type ListingCardClassNames = {
|
|
@@ -85,4 +102,5 @@ export type PublicSearchState = {
|
|
|
85
102
|
setSort: (sort: string | null) => void;
|
|
86
103
|
hrefForPage: (page: number) => string;
|
|
87
104
|
go: (href: string) => void;
|
|
105
|
+
locationNames: LocationNameTables | null;
|
|
88
106
|
};
|
|
@@ -53,6 +53,9 @@ export function usePublicSearch(
|
|
|
53
53
|
const [loading, setLoading] = useState(true);
|
|
54
54
|
const [qDraft, setQDraft] = useState("");
|
|
55
55
|
const [staged, setStaged] = useState<SearchPathFilters>({});
|
|
56
|
+
const [locationNames, setLocationNames] = useState<LocationNameTables | null>(
|
|
57
|
+
null
|
|
58
|
+
);
|
|
56
59
|
|
|
57
60
|
const parsed = useMemo(
|
|
58
61
|
() => readPublicSearch(pathname, search, schema?.dictionary),
|
|
@@ -106,6 +109,7 @@ export function usePublicSearch(
|
|
|
106
109
|
const id = catalogId;
|
|
107
110
|
let active = true;
|
|
108
111
|
locationsRef.current = null;
|
|
112
|
+
setLocationNames(null);
|
|
109
113
|
setSchema(null);
|
|
110
114
|
setListings([]);
|
|
111
115
|
setLoading(true);
|
|
@@ -128,10 +132,12 @@ export function usePublicSearch(
|
|
|
128
132
|
}
|
|
129
133
|
if (!active) return;
|
|
130
134
|
locationsRef.current = locations;
|
|
135
|
+
setLocationNames(locations);
|
|
131
136
|
setSchema(nextSchema);
|
|
132
137
|
} catch {
|
|
133
138
|
if (active) {
|
|
134
139
|
locationsRef.current = null;
|
|
140
|
+
setLocationNames(null);
|
|
135
141
|
setSchema(null);
|
|
136
142
|
setLoading(false);
|
|
137
143
|
}
|
|
@@ -293,5 +299,6 @@ export function usePublicSearch(
|
|
|
293
299
|
setSort,
|
|
294
300
|
hrefForPage,
|
|
295
301
|
go,
|
|
302
|
+
locationNames,
|
|
296
303
|
};
|
|
297
304
|
}
|
package/src/search-engine.ts
CHANGED
|
@@ -389,6 +389,85 @@ export function countFacetChoices(
|
|
|
389
389
|
return out;
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
+
const FEMININE_HEADING =
|
|
393
|
+
/(casa|cobertura|kitnet|loja|sala|fazenda|chácara|chacara)s?$/i;
|
|
394
|
+
|
|
395
|
+
function pluralizePt(label: string): string {
|
|
396
|
+
const text = label.trim();
|
|
397
|
+
if (!text || /s$/i.test(text)) return text;
|
|
398
|
+
if (/il$/i.test(text)) return `${text.slice(0, -1)}is`;
|
|
399
|
+
if (/m$/i.test(text)) return `${text.slice(0, -1)}ns`;
|
|
400
|
+
return `${text}s`;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function headingLocationSuffix(
|
|
404
|
+
location: SearchPathFilters["location"] | null
|
|
405
|
+
): string {
|
|
406
|
+
if (!location) return "";
|
|
407
|
+
if (location.street && location.neighborhood) {
|
|
408
|
+
return `${location.street}, ${location.neighborhood}`;
|
|
409
|
+
}
|
|
410
|
+
if (location.neighborhood && location.city) {
|
|
411
|
+
return `${location.neighborhood}, ${location.city}`;
|
|
412
|
+
}
|
|
413
|
+
if (location.city && location.state) {
|
|
414
|
+
return `${location.city} - ${location.state}`;
|
|
415
|
+
}
|
|
416
|
+
return (
|
|
417
|
+
location.city ||
|
|
418
|
+
location.neighborhood ||
|
|
419
|
+
location.street ||
|
|
420
|
+
location.state ||
|
|
421
|
+
""
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* SEO H1 for a search URL. Must stay stable for the same path — never
|
|
427
|
+
* include the hit count (Google treats a changing H1 on one URL as
|
|
428
|
+
* volatile). Count is rendered in a sibling `<span>`.
|
|
429
|
+
*/
|
|
430
|
+
export function searchResultsHeading(
|
|
431
|
+
pathFilters: SearchPathFilters,
|
|
432
|
+
dictionary?: SearchUiDictionary | null,
|
|
433
|
+
locationNames?: LocationNameTables | null
|
|
434
|
+
): string {
|
|
435
|
+
const types = ([] as string[])
|
|
436
|
+
.concat(pathFilters.propertyType || [])
|
|
437
|
+
.filter(Boolean);
|
|
438
|
+
let noun = "Imóveis";
|
|
439
|
+
let found = "encontrados";
|
|
440
|
+
if (types.length === 1) {
|
|
441
|
+
const id = String(types[0]);
|
|
442
|
+
const option = dictionary?.propertyTypes?.find(
|
|
443
|
+
(entry) => entry.id === id || entry.slug === id
|
|
444
|
+
);
|
|
445
|
+
const label = option?.label;
|
|
446
|
+
if (label) {
|
|
447
|
+
noun = pluralizePt(label.charAt(0).toUpperCase() + label.slice(1));
|
|
448
|
+
if (FEMININE_HEADING.test(id) || FEMININE_HEADING.test(label)) {
|
|
449
|
+
found = "encontradas";
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
const place = locationNames
|
|
454
|
+
? headingLocationSuffix(
|
|
455
|
+
displayPathLocation(pathFilters.location, locationNames)
|
|
456
|
+
)
|
|
457
|
+
: "";
|
|
458
|
+
if (place) return `${noun} ${found} em ${place}`;
|
|
459
|
+
return `${noun} ${found}`;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Next App Router does not navigate when the href is unchanged. Canonical
|
|
464
|
+
* URLs omit `page=1`, so pagination must still emit `?page=1` on the link.
|
|
465
|
+
*/
|
|
466
|
+
export function hrefWithExplicitPage(href: string, page: number): string {
|
|
467
|
+
if (page !== 1 || /(?:\?|&)page=/.test(href)) return href;
|
|
468
|
+
return href.includes("?") ? `${href}&page=1` : `${href}?page=1`;
|
|
469
|
+
}
|
|
470
|
+
|
|
392
471
|
export function paginationPages(
|
|
393
472
|
currentPage: number,
|
|
394
473
|
totalPages: number,
|
|
@@ -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
|
+
}
|