@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
package/dist/index.mjs
CHANGED
|
@@ -319,13 +319,19 @@ var SEARCH_CSS_VARS = {
|
|
|
319
319
|
cardRadius: "--garagem-listing-card-radius",
|
|
320
320
|
cardGap: "--garagem-listing-card-gap",
|
|
321
321
|
priceSize: "--garagem-listing-price-size",
|
|
322
|
-
mediaRatio: "--garagem-listing-media-ratio"
|
|
322
|
+
mediaRatio: "--garagem-listing-media-ratio",
|
|
323
|
+
controlHeight: "--garagem-search-control-height",
|
|
324
|
+
iconSize: "--garagem-search-icon-size",
|
|
325
|
+
skeleton: "--garagem-skeleton"
|
|
323
326
|
};
|
|
324
327
|
var SEARCH_CSS_RECIPE = `:root {
|
|
325
328
|
${SEARCH_CSS_VARS.cardRadius}: 0.75rem;
|
|
326
329
|
${SEARCH_CSS_VARS.cardGap}: 1.5rem;
|
|
327
330
|
${SEARCH_CSS_VARS.priceSize}: 1.125rem;
|
|
328
331
|
${SEARCH_CSS_VARS.mediaRatio}: 4 / 3;
|
|
332
|
+
${SEARCH_CSS_VARS.controlHeight}: 2.75rem;
|
|
333
|
+
${SEARCH_CSS_VARS.iconSize}: 1.25rem;
|
|
334
|
+
${SEARCH_CSS_VARS.skeleton}: var(--muted, #e7e5e4);
|
|
329
335
|
}
|
|
330
336
|
`;
|
|
331
337
|
function formatListingPrice(amount, locale = "pt-BR", currency = "BRL") {
|
|
@@ -1103,6 +1109,54 @@ function countFacetChoices(options) {
|
|
|
1103
1109
|
}
|
|
1104
1110
|
return out;
|
|
1105
1111
|
}
|
|
1112
|
+
var FEMININE_HEADING = /(casa|cobertura|kitnet|loja|sala|fazenda|chácara|chacara)s?$/i;
|
|
1113
|
+
function pluralizePt(label) {
|
|
1114
|
+
const text = label.trim();
|
|
1115
|
+
if (!text || /s$/i.test(text)) return text;
|
|
1116
|
+
if (/il$/i.test(text)) return `${text.slice(0, -1)}is`;
|
|
1117
|
+
if (/m$/i.test(text)) return `${text.slice(0, -1)}ns`;
|
|
1118
|
+
return `${text}s`;
|
|
1119
|
+
}
|
|
1120
|
+
function headingLocationSuffix(location) {
|
|
1121
|
+
if (!location) return "";
|
|
1122
|
+
if (location.street && location.neighborhood) {
|
|
1123
|
+
return `${location.street}, ${location.neighborhood}`;
|
|
1124
|
+
}
|
|
1125
|
+
if (location.neighborhood && location.city) {
|
|
1126
|
+
return `${location.neighborhood}, ${location.city}`;
|
|
1127
|
+
}
|
|
1128
|
+
if (location.city && location.state) {
|
|
1129
|
+
return `${location.city} - ${location.state}`;
|
|
1130
|
+
}
|
|
1131
|
+
return location.city || location.neighborhood || location.street || location.state || "";
|
|
1132
|
+
}
|
|
1133
|
+
function searchResultsHeading(pathFilters, dictionary, locationNames) {
|
|
1134
|
+
const types = [].concat(pathFilters.propertyType || []).filter(Boolean);
|
|
1135
|
+
let noun = "Im\xF3veis";
|
|
1136
|
+
let found = "encontrados";
|
|
1137
|
+
if (types.length === 1) {
|
|
1138
|
+
const id = String(types[0]);
|
|
1139
|
+
const option = dictionary?.propertyTypes?.find(
|
|
1140
|
+
(entry) => entry.id === id || entry.slug === id
|
|
1141
|
+
);
|
|
1142
|
+
const label = option?.label;
|
|
1143
|
+
if (label) {
|
|
1144
|
+
noun = pluralizePt(label.charAt(0).toUpperCase() + label.slice(1));
|
|
1145
|
+
if (FEMININE_HEADING.test(id) || FEMININE_HEADING.test(label)) {
|
|
1146
|
+
found = "encontradas";
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
const place = locationNames ? headingLocationSuffix(
|
|
1151
|
+
displayPathLocation(pathFilters.location, locationNames)
|
|
1152
|
+
) : "";
|
|
1153
|
+
if (place) return `${noun} ${found} em ${place}`;
|
|
1154
|
+
return `${noun} ${found}`;
|
|
1155
|
+
}
|
|
1156
|
+
function hrefWithExplicitPage(href, page) {
|
|
1157
|
+
if (page !== 1 || /(?:\?|&)page=/.test(href)) return href;
|
|
1158
|
+
return href.includes("?") ? `${href}&page=1` : `${href}?page=1`;
|
|
1159
|
+
}
|
|
1106
1160
|
function paginationPages(currentPage, totalPages, padding) {
|
|
1107
1161
|
if (totalPages < 1) return [];
|
|
1108
1162
|
const current = Math.min(Math.max(1, currentPage), totalPages);
|
|
@@ -1145,6 +1199,116 @@ async function resolvePublicSiteId(options) {
|
|
|
1145
1199
|
);
|
|
1146
1200
|
}
|
|
1147
1201
|
|
|
1202
|
+
// src/studio-contract.ts
|
|
1203
|
+
var STUDIO_SDK_PACKAGE = "@garagem-ai/site-sdk";
|
|
1204
|
+
var STUDIO_SDK_CONTRACT = {
|
|
1205
|
+
package: STUDIO_SDK_PACKAGE,
|
|
1206
|
+
/**
|
|
1207
|
+
* Exact pin for generated Studio sites. Must be ≥ `selfInjectSince` so
|
|
1208
|
+
* prompts that skip the layout chrome tag match the tarball v0 installs.
|
|
1209
|
+
* This PR’s changeset publishes that tarball as 0.4.2 — do not generate
|
|
1210
|
+
* against this floor until Version Packages is on npm.
|
|
1211
|
+
*/
|
|
1212
|
+
minNpmVersion: "0.4.2",
|
|
1213
|
+
/** First release where ListingCard and ResultsSkeleton inject the sheet. */
|
|
1214
|
+
selfInjectSince: "0.4.2",
|
|
1215
|
+
chromeStrategy: "self-inject",
|
|
1216
|
+
reactExports: [
|
|
1217
|
+
"SearchPage",
|
|
1218
|
+
"ListingCard",
|
|
1219
|
+
"usePublicSearch",
|
|
1220
|
+
"ResultsSkeleton"
|
|
1221
|
+
],
|
|
1222
|
+
/**
|
|
1223
|
+
* Names that exist in git / the unpublished patch. Completeness treats an
|
|
1224
|
+
* import as `sdk-export-mismatch` when the generated pin is older than
|
|
1225
|
+
* `since`. Studio prompts must not mention these names at all (even as
|
|
1226
|
+
* “never import”) — v0 copies the identifier and the preview ESM loader
|
|
1227
|
+
* throws FatalRendererError.
|
|
1228
|
+
*/
|
|
1229
|
+
optionalReactExports: {
|
|
1230
|
+
SearchPageFallback: "0.4.1",
|
|
1231
|
+
SearchChromeStyles: "0.4.1"
|
|
1232
|
+
},
|
|
1233
|
+
forbiddenImports: ["@garagem-ai/site-sdk/react/search.css"]
|
|
1234
|
+
};
|
|
1235
|
+
var REACT_SDK_NAMED_IMPORT_RE = /(?:^|[\n;])\s*import\s+(?!type\b)(?:type\s+)?\{([^}]+)\}\s+from\s+['"]@garagem-ai\/site-sdk\/react['"]/g;
|
|
1236
|
+
function coerceNpmVersion(raw) {
|
|
1237
|
+
if (typeof raw !== "string") return null;
|
|
1238
|
+
const match = raw.trim().match(/(\d+)\.(\d+)\.(\d+)/);
|
|
1239
|
+
return match ? `${match[1]}.${match[2]}.${match[3]}` : null;
|
|
1240
|
+
}
|
|
1241
|
+
function compareSemver(a, b) {
|
|
1242
|
+
const left = a.split(".").map((part) => Number(part));
|
|
1243
|
+
const right = b.split(".").map((part) => Number(part));
|
|
1244
|
+
for (let i = 0; i < 3; i += 1) {
|
|
1245
|
+
const delta = (left[i] ?? 0) - (right[i] ?? 0);
|
|
1246
|
+
if (delta !== 0) return delta;
|
|
1247
|
+
}
|
|
1248
|
+
return 0;
|
|
1249
|
+
}
|
|
1250
|
+
function parseReactSdkNamedImports(source) {
|
|
1251
|
+
const names = [];
|
|
1252
|
+
REACT_SDK_NAMED_IMPORT_RE.lastIndex = 0;
|
|
1253
|
+
let match;
|
|
1254
|
+
while ((match = REACT_SDK_NAMED_IMPORT_RE.exec(source)) !== null) {
|
|
1255
|
+
const body = match[1];
|
|
1256
|
+
if (!body) continue;
|
|
1257
|
+
for (const raw of body.split(",")) {
|
|
1258
|
+
const token = raw.trim();
|
|
1259
|
+
if (!token || token.startsWith("type ")) continue;
|
|
1260
|
+
const name = token.split(/\s+as\s+/)[0]?.trim();
|
|
1261
|
+
if (name) names.push(name);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
return names;
|
|
1265
|
+
}
|
|
1266
|
+
function reactExportsAvailableAt(pin) {
|
|
1267
|
+
const available = new Set(STUDIO_SDK_CONTRACT.reactExports);
|
|
1268
|
+
for (const [name, since] of Object.entries(
|
|
1269
|
+
STUDIO_SDK_CONTRACT.optionalReactExports
|
|
1270
|
+
)) {
|
|
1271
|
+
if (compareSemver(pin, since) >= 0) available.add(name);
|
|
1272
|
+
}
|
|
1273
|
+
return available;
|
|
1274
|
+
}
|
|
1275
|
+
function unavailableReactImports(source, pin) {
|
|
1276
|
+
const available = reactExportsAvailableAt(pin);
|
|
1277
|
+
const missing = [];
|
|
1278
|
+
for (const name of parseReactSdkNamedImports(source)) {
|
|
1279
|
+
if (!available.has(name) && !missing.includes(name)) {
|
|
1280
|
+
missing.push(name);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
return missing;
|
|
1284
|
+
}
|
|
1285
|
+
function studioSdkPinInstruction() {
|
|
1286
|
+
const version = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
1287
|
+
const names = STUDIO_SDK_CONTRACT.reactExports.join(", ");
|
|
1288
|
+
return `In \`package.json\` set \`"@garagem-ai/site-sdk": "${version}"\` (exact). Import only these \`${STUDIO_SDK_PACKAGE}/react\` names: ${names}.`;
|
|
1289
|
+
}
|
|
1290
|
+
function studioChromeInstruction() {
|
|
1291
|
+
const injectors = compareSemver(
|
|
1292
|
+
STUDIO_SDK_CONTRACT.minNpmVersion,
|
|
1293
|
+
STUDIO_SDK_CONTRACT.selfInjectSince
|
|
1294
|
+
) >= 0 ? "`SearchPage`, `ListingCard`, and `ResultsSkeleton`" : "`SearchPage`";
|
|
1295
|
+
return `Search chrome CSS is injected by ${injectors} (JS \`<style>\` tag). Never \`import "@garagem-ai/site-sdk/react/search.css"\` \u2014 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\`.`;
|
|
1296
|
+
}
|
|
1297
|
+
function studioCodegenContractViolations(text) {
|
|
1298
|
+
const violations = [];
|
|
1299
|
+
for (const name of Object.keys(STUDIO_SDK_CONTRACT.optionalReactExports)) {
|
|
1300
|
+
if (text.includes(name)) violations.push(name);
|
|
1301
|
+
}
|
|
1302
|
+
const pin = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
1303
|
+
const available = reactExportsAvailableAt(pin);
|
|
1304
|
+
for (const name of parseReactSdkNamedImports(text)) {
|
|
1305
|
+
if (!available.has(name) && !violations.includes(name)) {
|
|
1306
|
+
violations.push(name);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
return violations;
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1148
1312
|
// src/client.ts
|
|
1149
1313
|
function createGaragemClient(options = {}) {
|
|
1150
1314
|
const resolveSiteId = (override) => {
|
|
@@ -1282,11 +1446,15 @@ export {
|
|
|
1282
1446
|
SEARCH_CSS_RECIPE,
|
|
1283
1447
|
SEARCH_CSS_VARS,
|
|
1284
1448
|
SEARCH_SORT_RELEVANCE,
|
|
1449
|
+
STUDIO_SDK_CONTRACT,
|
|
1450
|
+
STUDIO_SDK_PACKAGE,
|
|
1285
1451
|
TOOLBAR_PRIMARY_FILTER_IDS,
|
|
1286
1452
|
applyPathFilter,
|
|
1287
1453
|
buildQueryListingsParams,
|
|
1288
1454
|
canonicalizeSearchHref,
|
|
1289
1455
|
clearStagedPathFilters,
|
|
1456
|
+
coerceNpmVersion,
|
|
1457
|
+
compareSemver,
|
|
1290
1458
|
composeSearchPublicHref2 as composeSearchPublicHref,
|
|
1291
1459
|
composeSearchPublicPath2 as composeSearchPublicPath,
|
|
1292
1460
|
countFacetChoices,
|
|
@@ -1307,6 +1475,7 @@ export {
|
|
|
1307
1475
|
getSite,
|
|
1308
1476
|
hrefForAppliedChange,
|
|
1309
1477
|
hrefForPathFilters,
|
|
1478
|
+
hrefWithExplicitPage,
|
|
1310
1479
|
isListingDetailPath,
|
|
1311
1480
|
isStudioPreviewHost,
|
|
1312
1481
|
listingBusinessLabel,
|
|
@@ -1317,6 +1486,7 @@ export {
|
|
|
1317
1486
|
paginationPages,
|
|
1318
1487
|
parseAppliedSearchQuery2 as parseAppliedSearchQuery,
|
|
1319
1488
|
parseGroupedInteger,
|
|
1489
|
+
parseReactSdkNamedImports,
|
|
1320
1490
|
parseSearchPublicPath2 as parseSearchPublicPath,
|
|
1321
1491
|
pathFilterHasOption,
|
|
1322
1492
|
pathFilterValue,
|
|
@@ -1329,10 +1499,15 @@ export {
|
|
|
1329
1499
|
resolvePublicSiteId,
|
|
1330
1500
|
searchHrefUsesLegacyFilterQuery,
|
|
1331
1501
|
searchListings,
|
|
1502
|
+
searchResultsHeading,
|
|
1332
1503
|
searchSortOptions,
|
|
1333
1504
|
serializeAppliedSearchQuery2 as serializeAppliedSearchQuery,
|
|
1505
|
+
studioChromeInstruction,
|
|
1506
|
+
studioCodegenContractViolations,
|
|
1507
|
+
studioSdkPinInstruction,
|
|
1334
1508
|
toListingCardModel,
|
|
1335
1509
|
toolbarFilterIds,
|
|
1510
|
+
unavailableReactImports,
|
|
1336
1511
|
visibleSearchFilters
|
|
1337
1512
|
};
|
|
1338
1513
|
//# sourceMappingURL=index.mjs.map
|