@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/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, bn as MapSearchSubscription, an as MapBounds, ar as MapPolygon, at as MapSearchResult, aq as MapPinCluster, O as PhotoSearchItem, U as ListingWithMatchedPhoto, F as FetchLike } from './types-photo-search-DIoV75SN.mjs';
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, bn as MapSearchSubscription, an as MapBounds, ar as MapPolygon, at as MapSearchResult, aq as MapPinCluster, O as PhotoSearchItem, U as ListingWithMatchedPhoto, F as FetchLike } from './types-photo-search-DIoV75SN.js';
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(listings, meta, requestedPageSize) {
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: meta.page ?? 1,
1485
- pageSize: meta.limit ?? requestedPageSize,
1486
- total: meta.total ?? listings.length,
1487
- totalPages: meta.totalPages ?? 0
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.listings ?? [], result, pageSize);
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 usablePin(pin) {
1540
- return finitePair(pin.lat, pin.lng) !== null && !(pin.lat === 0 && pin.lng === 0);
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 pin of group) {
1548
+ for (const point of group) {
1545
1549
  max = Math.max(
1546
1550
  max,
1547
- coordinateDecimals(pin.lat),
1548
- coordinateDecimals(pin.lng)
1551
+ coordinateDecimals(point.lat),
1552
+ coordinateDecimals(point.lng)
1549
1553
  );
1550
1554
  }
1551
1555
  return max;
1552
1556
  }
1553
- function multiCluster(key, group) {
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 pin of pins) {
1581
- if (!usablePin(pin)) continue;
1582
- const key = `${Math.floor(pin.lat / cell)}:${Math.floor(pin.lng / cell)}`;
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(pin);
1585
- else groups.set(key, [pin]);
1586
- }
1587
- const clusters = [];
1588
- for (const [key, group] of groups) {
1589
- const only = group[0];
1590
- clusters.push(
1591
- group.length === 1 && only ? singleCluster(only) : multiCluster(key, group)
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
- clusters.sort((a, b) => a.id.localeCompare(b.id));
1595
- return clusters;
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
  }