@garagem-ai/site-sdk 0.10.1 → 0.11.1
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 +7 -7
- package/dist/index.d.mts +17 -6
- package/dist/index.d.ts +17 -6
- package/dist/index.js +86 -59
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -59
- 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 +58 -54
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +58 -54
- package/dist/react.mjs.map +1 -1
- package/dist/{types-photo-search-DIoV75SN.d.mts → types-photo-search-Bmf1f1-Y.d.mts} +455 -419
- package/dist/{types-photo-search-DIoV75SN.d.ts → types-photo-search-Bmf1f1-Y.d.ts} +455 -419
- package/package.json +3 -3
- package/src/index.ts +2 -0
- package/src/listing-detail.ts +1 -0
- package/src/map-search.ts +89 -60
- package/src/react/use-map-search.ts +6 -2
- package/src/search-engine.ts +5 -0
- package/src/studio-contract.ts +40 -7
- package/src/types-maps.ts +17 -1
- package/src/types-market.ts +4 -0
- package/src/types.ts +10 -0
package/dist/react.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { j as SearchUi, J as Listing, ai as LocationNameTables, S as SearchPathFilters, A as AppliedSearchQuery,
|
|
1
|
+
import { j as SearchUi, J as Listing, ai as LocationNameTables, S as SearchPathFilters, A as AppliedSearchQuery, bp as MapSearchSubscription, an as MapBounds, as as MapPolygon, au as MapSearchResult, ar as MapPinCluster, O as PhotoSearchItem, U as ListingWithMatchedPhoto, F as FetchLike } from './types-photo-search-Bmf1f1-Y.mjs';
|
|
2
2
|
|
|
3
3
|
type SiteIdInput = string | Promise<string> | (() => string | Promise<string>);
|
|
4
4
|
type PublicSearchSnapshot = {
|
package/dist/react.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { j as SearchUi, J as Listing, ai as LocationNameTables, S as SearchPathFilters, A as AppliedSearchQuery,
|
|
1
|
+
import { j as SearchUi, J as Listing, ai as LocationNameTables, S as SearchPathFilters, A as AppliedSearchQuery, bp as MapSearchSubscription, an as MapBounds, as as MapPolygon, au as MapSearchResult, ar as MapPinCluster, O as PhotoSearchItem, U as ListingWithMatchedPhoto, F as FetchLike } from './types-photo-search-Bmf1f1-Y.js';
|
|
2
2
|
|
|
3
3
|
type SiteIdInput = string | Promise<string> | (() => string | Promise<string>);
|
|
4
4
|
type PublicSearchSnapshot = {
|
package/dist/react.js
CHANGED
|
@@ -1457,7 +1457,8 @@ function emptyMapSearchResult(pageSize = MAP_SEARCH_DEFAULT_PAGE_SIZE) {
|
|
|
1457
1457
|
page: 1,
|
|
1458
1458
|
pageSize,
|
|
1459
1459
|
total: 0,
|
|
1460
|
-
totalPages: 0
|
|
1460
|
+
totalPages: 0,
|
|
1461
|
+
buckets: []
|
|
1461
1462
|
};
|
|
1462
1463
|
}
|
|
1463
1464
|
function mapSearchPins(listings) {
|
|
@@ -1476,21 +1477,24 @@ function mapSearchPins(listings) {
|
|
|
1476
1477
|
}
|
|
1477
1478
|
return pins;
|
|
1478
1479
|
}
|
|
1479
|
-
function listingsResult(
|
|
1480
|
+
function listingsResult(result, requestedPageSize) {
|
|
1481
|
+
const listings = result.listings ?? [];
|
|
1480
1482
|
return {
|
|
1481
1483
|
pins: mapSearchPins(listings),
|
|
1482
1484
|
cards: listings.map((listing) => toListingCardModel(listing)),
|
|
1483
1485
|
listings,
|
|
1484
|
-
page:
|
|
1485
|
-
pageSize:
|
|
1486
|
-
total:
|
|
1487
|
-
totalPages:
|
|
1486
|
+
page: result.page ?? 1,
|
|
1487
|
+
pageSize: result.limit ?? requestedPageSize,
|
|
1488
|
+
total: result.total ?? listings.length,
|
|
1489
|
+
totalPages: result.totalPages ?? 0,
|
|
1490
|
+
buckets: result.buckets ?? []
|
|
1488
1491
|
};
|
|
1489
1492
|
}
|
|
1490
1493
|
function searchParams(area, options) {
|
|
1491
1494
|
const params = {
|
|
1492
1495
|
page: capMapPage(options.page),
|
|
1493
|
-
limit: capMapPageSize(options.pageSize)
|
|
1496
|
+
limit: capMapPageSize(options.pageSize),
|
|
1497
|
+
buckets: true
|
|
1494
1498
|
};
|
|
1495
1499
|
if (options.q !== void 0) params.q = options.q;
|
|
1496
1500
|
if (options.sort !== void 0) params.sort = options.sort;
|
|
@@ -1511,7 +1515,7 @@ async function runMapSearch(siteId, area, options) {
|
|
|
1511
1515
|
publishableKey: options.publishableKey,
|
|
1512
1516
|
next: options.next
|
|
1513
1517
|
});
|
|
1514
|
-
return listingsResult(result
|
|
1518
|
+
return listingsResult(result, pageSize);
|
|
1515
1519
|
}
|
|
1516
1520
|
async function searchListingsInBounds(siteId, options) {
|
|
1517
1521
|
if (!isMapBounds(options.bounds)) {
|
|
@@ -1536,63 +1540,63 @@ function clampZoom(zoom) {
|
|
|
1536
1540
|
function mapClusterCellDegrees(zoom) {
|
|
1537
1541
|
return 360 / 2 ** clampZoom(zoom) / 4;
|
|
1538
1542
|
}
|
|
1539
|
-
function
|
|
1540
|
-
return finitePair(
|
|
1543
|
+
function usablePoint(point) {
|
|
1544
|
+
return finitePair(point.lat, point.lng) !== null && !(point.lat === 0 && point.lng === 0);
|
|
1541
1545
|
}
|
|
1542
1546
|
function groupPrecision(group) {
|
|
1543
1547
|
let max = 0;
|
|
1544
|
-
for (const
|
|
1548
|
+
for (const point of group) {
|
|
1545
1549
|
max = Math.max(
|
|
1546
1550
|
max,
|
|
1547
|
-
coordinateDecimals(
|
|
1548
|
-
coordinateDecimals(
|
|
1551
|
+
coordinateDecimals(point.lat),
|
|
1552
|
+
coordinateDecimals(point.lng)
|
|
1549
1553
|
);
|
|
1550
1554
|
}
|
|
1551
1555
|
return max;
|
|
1552
1556
|
}
|
|
1553
|
-
function
|
|
1554
|
-
const lat = group.reduce((sum, pin) => sum + pin.lat, 0) / group.length;
|
|
1555
|
-
const lng = group.reduce((sum, pin) => sum + pin.lng, 0) / group.length;
|
|
1556
|
-
const center = coarsenCoordinates({ lat, lng }, groupPrecision(group));
|
|
1557
|
-
return {
|
|
1558
|
-
id: key,
|
|
1559
|
-
lat: center.lat,
|
|
1560
|
-
lng: center.lng,
|
|
1561
|
-
count: group.length,
|
|
1562
|
-
pinIds: group.map((pin) => pin.id),
|
|
1563
|
-
pin: null
|
|
1564
|
-
};
|
|
1565
|
-
}
|
|
1566
|
-
function singleCluster(pin) {
|
|
1567
|
-
return {
|
|
1568
|
-
id: pin.id,
|
|
1569
|
-
lat: pin.lat,
|
|
1570
|
-
lng: pin.lng,
|
|
1571
|
-
count: 1,
|
|
1572
|
-
pinIds: [pin.id],
|
|
1573
|
-
pin
|
|
1574
|
-
};
|
|
1575
|
-
}
|
|
1576
|
-
function clusterPins(pins, zoom) {
|
|
1577
|
-
if (pins.length === 0) return [];
|
|
1557
|
+
function gridCells(points, zoom, weight) {
|
|
1578
1558
|
const cell = mapClusterCellDegrees(zoom);
|
|
1579
1559
|
const groups = /* @__PURE__ */ new Map();
|
|
1580
|
-
for (const
|
|
1581
|
-
if (!
|
|
1582
|
-
const key = `${Math.floor(
|
|
1560
|
+
for (const point of points) {
|
|
1561
|
+
if (!usablePoint(point)) continue;
|
|
1562
|
+
const key = `${Math.floor(point.lat / cell)}:${Math.floor(point.lng / cell)}`;
|
|
1583
1563
|
const list = groups.get(key);
|
|
1584
|
-
if (list) list.push(
|
|
1585
|
-
else groups.set(key, [
|
|
1586
|
-
}
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
const only =
|
|
1590
|
-
|
|
1591
|
-
|
|
1564
|
+
if (list) list.push(point);
|
|
1565
|
+
else groups.set(key, [point]);
|
|
1566
|
+
}
|
|
1567
|
+
return [...groups].map(([key, members]) => {
|
|
1568
|
+
const count = members.reduce((sum, point) => sum + weight(point), 0);
|
|
1569
|
+
const only = members.length === 1 ? members[0] : void 0;
|
|
1570
|
+
const center = only ?? coarsenCoordinates(
|
|
1571
|
+
{
|
|
1572
|
+
lat: members.reduce((sum, p) => sum + p.lat * weight(p), 0) / count,
|
|
1573
|
+
lng: members.reduce((sum, p) => sum + p.lng * weight(p), 0) / count
|
|
1574
|
+
},
|
|
1575
|
+
groupPrecision(members)
|
|
1592
1576
|
);
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1577
|
+
return {
|
|
1578
|
+
id: only?.id ?? key,
|
|
1579
|
+
lat: center.lat,
|
|
1580
|
+
lng: center.lng,
|
|
1581
|
+
count,
|
|
1582
|
+
pinIds: [],
|
|
1583
|
+
pin: null,
|
|
1584
|
+
members
|
|
1585
|
+
};
|
|
1586
|
+
}).sort((a, b) => a.id.localeCompare(b.id));
|
|
1587
|
+
}
|
|
1588
|
+
function clusterPins(pins, zoom) {
|
|
1589
|
+
return gridCells(pins, zoom, () => 1).map(({ members, ...cluster }) => ({
|
|
1590
|
+
...cluster,
|
|
1591
|
+
pinIds: members.map((pin) => pin.id),
|
|
1592
|
+
pin: members.length === 1 ? members[0] ?? null : null
|
|
1593
|
+
}));
|
|
1594
|
+
}
|
|
1595
|
+
function clusterBuckets(buckets, zoom) {
|
|
1596
|
+
const weighted = buckets.filter((bucket) => bucket.count > 0);
|
|
1597
|
+
return gridCells(weighted, zoom, (bucket) => bucket.count).map(
|
|
1598
|
+
({ members: _members, ...cluster }) => cluster
|
|
1599
|
+
);
|
|
1596
1600
|
}
|
|
1597
1601
|
function describeArea(query) {
|
|
1598
1602
|
if (query.polygon != null) {
|
|
@@ -1743,8 +1747,8 @@ function useMapSearch(options) {
|
|
|
1743
1747
|
);
|
|
1744
1748
|
}, [key]);
|
|
1745
1749
|
const clusters = (0, import_react2.useMemo)(
|
|
1746
|
-
() => clusterPins(result.pins, zoom),
|
|
1747
|
-
[result.pins, zoom]
|
|
1750
|
+
() => result.buckets.length > 0 ? clusterBuckets(result.buckets, zoom) : clusterPins(result.pins, zoom),
|
|
1751
|
+
[result.buckets, result.pins, zoom]
|
|
1748
1752
|
);
|
|
1749
1753
|
return { ...result, clusters, loading, error };
|
|
1750
1754
|
}
|