@next-degree/pickle-shared-js 0.3.30 → 0.5.31
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/app/layout.css +41 -0
- package/dist/app/layout.css.map +1 -1
- package/dist/app/page.cjs +238 -8
- package/dist/app/page.cjs.map +1 -1
- package/dist/app/page.js +238 -8
- package/dist/app/page.js.map +1 -1
- package/dist/components/demos/MapComponentDemo.cjs +129 -0
- package/dist/components/demos/MapComponentDemo.cjs.map +1 -0
- package/dist/components/demos/MapComponentDemo.d.cts +5 -0
- package/dist/components/demos/MapComponentDemo.d.ts +5 -0
- package/dist/components/demos/MapComponentDemo.js +107 -0
- package/dist/components/demos/MapComponentDemo.js.map +1 -0
- package/dist/components/demos/PlacesQueryInputDemo.cjs +341 -0
- package/dist/components/demos/PlacesQueryInputDemo.cjs.map +1 -0
- package/dist/components/demos/PlacesQueryInputDemo.d.cts +5 -0
- package/dist/components/demos/PlacesQueryInputDemo.d.ts +5 -0
- package/dist/components/demos/PlacesQueryInputDemo.js +309 -0
- package/dist/components/demos/PlacesQueryInputDemo.js.map +1 -0
- package/dist/components/demos/index.cjs +236 -6
- package/dist/components/demos/index.cjs.map +1 -1
- package/dist/components/demos/index.js +236 -6
- package/dist/components/demos/index.js.map +1 -1
- package/dist/components/ui/MapComponent.cjs +54 -0
- package/dist/components/ui/MapComponent.cjs.map +1 -0
- package/dist/components/ui/MapComponent.d.cts +15 -0
- package/dist/components/ui/MapComponent.d.ts +15 -0
- package/dist/components/ui/MapComponent.js +34 -0
- package/dist/components/ui/MapComponent.js.map +1 -0
- package/dist/components/ui/PlacesQueryInput.cjs +321 -0
- package/dist/components/ui/PlacesQueryInput.cjs.map +1 -0
- package/dist/components/ui/PlacesQueryInput.d.cts +18 -0
- package/dist/components/ui/PlacesQueryInput.d.ts +18 -0
- package/dist/components/ui/PlacesQueryInput.js +289 -0
- package/dist/components/ui/PlacesQueryInput.js.map +1 -0
- package/dist/index.cjs +354 -173
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +345 -167
- package/dist/index.js.map +1 -1
- package/dist/lib/google.cjs +85 -0
- package/dist/lib/google.cjs.map +1 -0
- package/dist/lib/google.d.cts +26 -0
- package/dist/lib/google.d.ts +26 -0
- package/dist/lib/google.js +58 -0
- package/dist/lib/google.js.map +1 -0
- package/dist/styles/globals.css +41 -0
- package/dist/styles/globals.css.map +1 -1
- package/package.json +23 -21
|
@@ -1327,14 +1327,244 @@ function CounterDemo() {
|
|
|
1327
1327
|
}
|
|
1328
1328
|
var CounterDemo_default = CounterDemo;
|
|
1329
1329
|
|
|
1330
|
-
// src/
|
|
1330
|
+
// src/lib/google.ts
|
|
1331
|
+
import { Client, PlaceAutocompleteType } from "@googlemaps/google-maps-services-js";
|
|
1332
|
+
var client = new Client();
|
|
1333
|
+
var autocomplete = async (input, key) => {
|
|
1334
|
+
try {
|
|
1335
|
+
const response = await client.placeAutocomplete({
|
|
1336
|
+
params: { input, key, types: PlaceAutocompleteType.address }
|
|
1337
|
+
});
|
|
1338
|
+
return response.data.predictions;
|
|
1339
|
+
} catch (error) {
|
|
1340
|
+
console.error(error);
|
|
1341
|
+
}
|
|
1342
|
+
};
|
|
1343
|
+
var fetchLocation = async (place, key) => {
|
|
1344
|
+
try {
|
|
1345
|
+
if (place.place_id) {
|
|
1346
|
+
const placeDetails = await getPlaceDetails(place.place_id, key);
|
|
1347
|
+
if (placeDetails) return placeDetails;
|
|
1348
|
+
}
|
|
1349
|
+
if (place.address) {
|
|
1350
|
+
const result = await geocode(place.address, key);
|
|
1351
|
+
const firstAddress = result?.[0];
|
|
1352
|
+
return firstAddress;
|
|
1353
|
+
}
|
|
1354
|
+
return void 0;
|
|
1355
|
+
} catch (error) {
|
|
1356
|
+
console.error("Error fetching location:", error);
|
|
1357
|
+
}
|
|
1358
|
+
};
|
|
1359
|
+
var getPlaceDetails = async (place_id, key) => {
|
|
1360
|
+
try {
|
|
1361
|
+
const response = await client.placeDetails({
|
|
1362
|
+
params: { place_id, key }
|
|
1363
|
+
});
|
|
1364
|
+
return response.data.result;
|
|
1365
|
+
} catch (error) {
|
|
1366
|
+
console.error(error);
|
|
1367
|
+
}
|
|
1368
|
+
};
|
|
1369
|
+
var geocode = async (address, key) => {
|
|
1370
|
+
try {
|
|
1371
|
+
const response = await client.geocode({
|
|
1372
|
+
params: { address, key }
|
|
1373
|
+
});
|
|
1374
|
+
return response.data.results;
|
|
1375
|
+
} catch (error) {
|
|
1376
|
+
console.error(error);
|
|
1377
|
+
}
|
|
1378
|
+
};
|
|
1379
|
+
|
|
1380
|
+
// src/components/ui/PlacesQueryInput.tsx
|
|
1381
|
+
import { CircleX as CircleX2, LoaderCircle } from "lucide-react";
|
|
1382
|
+
import { useState as useState6, useCallback, useRef as useRef2, useEffect as useEffect4 } from "react";
|
|
1331
1383
|
import { jsx as jsx21, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
1384
|
+
function PlacesQueryInput({
|
|
1385
|
+
apiKey,
|
|
1386
|
+
selected,
|
|
1387
|
+
onSelect,
|
|
1388
|
+
className
|
|
1389
|
+
}) {
|
|
1390
|
+
const [predictions, setPredictions] = useState6(null);
|
|
1391
|
+
const [input, setInput] = useState6(selected?.description ?? "");
|
|
1392
|
+
const [isLoadingPredictions, setIsLoadingPredictions] = useState6(false);
|
|
1393
|
+
const [shouldOpenUpward, setShouldOpenUpward] = useState6(false);
|
|
1394
|
+
const timeoutRef = useRef2(null);
|
|
1395
|
+
const inputRef = useRef2(null);
|
|
1396
|
+
const debouncedAutocomplete = useCallback((value) => {
|
|
1397
|
+
if (timeoutRef.current) {
|
|
1398
|
+
clearTimeout(timeoutRef.current);
|
|
1399
|
+
}
|
|
1400
|
+
timeoutRef.current = setTimeout(async () => {
|
|
1401
|
+
if (value.length > 2) {
|
|
1402
|
+
setIsLoadingPredictions(true);
|
|
1403
|
+
const fetchedPredictions = await autocomplete(value, apiKey);
|
|
1404
|
+
fetchedPredictions && setIsLoadingPredictions(false);
|
|
1405
|
+
setPredictions(fetchedPredictions ?? []);
|
|
1406
|
+
} else {
|
|
1407
|
+
setPredictions(null);
|
|
1408
|
+
}
|
|
1409
|
+
}, 300);
|
|
1410
|
+
}, []);
|
|
1411
|
+
const handleInputChange = (value) => {
|
|
1412
|
+
setInput(value);
|
|
1413
|
+
debouncedAutocomplete(value);
|
|
1414
|
+
};
|
|
1415
|
+
const handleSelect = (prediction) => {
|
|
1416
|
+
onSelect(prediction);
|
|
1417
|
+
setPredictions(null);
|
|
1418
|
+
setInput(prediction.description);
|
|
1419
|
+
};
|
|
1420
|
+
const handleClear = () => {
|
|
1421
|
+
onSelect();
|
|
1422
|
+
setPredictions(null);
|
|
1423
|
+
setInput("");
|
|
1424
|
+
};
|
|
1425
|
+
const handleBlur = () => setTimeout(() => setPredictions(null), 200);
|
|
1426
|
+
useEffect4(() => {
|
|
1427
|
+
const checkDropdownPosition = () => {
|
|
1428
|
+
if (inputRef.current) {
|
|
1429
|
+
const rect = inputRef.current.getBoundingClientRect();
|
|
1430
|
+
const windowHeight = window.innerHeight;
|
|
1431
|
+
setShouldOpenUpward(rect.bottom + 200 > windowHeight);
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1434
|
+
checkDropdownPosition();
|
|
1435
|
+
window.addEventListener("resize", checkDropdownPosition);
|
|
1436
|
+
return () => window.removeEventListener("resize", checkDropdownPosition);
|
|
1437
|
+
}, []);
|
|
1438
|
+
return /* @__PURE__ */ jsx21("div", { className: cn("relative w-full", className), ref: inputRef, onBlur: handleBlur, children: /* @__PURE__ */ jsxs14(Command, { children: [
|
|
1439
|
+
/* @__PURE__ */ jsxs14("div", { className: "relative w-full", children: [
|
|
1440
|
+
/* @__PURE__ */ jsx21(
|
|
1441
|
+
CommandInput,
|
|
1442
|
+
{
|
|
1443
|
+
placeholder: "Type an address to search...",
|
|
1444
|
+
value: input,
|
|
1445
|
+
onValueChange: handleInputChange,
|
|
1446
|
+
className: "truncate pr-8"
|
|
1447
|
+
}
|
|
1448
|
+
),
|
|
1449
|
+
isLoadingPredictions && /* @__PURE__ */ jsx21(LoaderCircle, { className: "absolute inset-y-0 right-2 my-auto flex h-8 w-8 animate-spin items-center justify-center rounded-full text-green-100" }),
|
|
1450
|
+
input && /* @__PURE__ */ jsx21(
|
|
1451
|
+
"button",
|
|
1452
|
+
{
|
|
1453
|
+
type: "button",
|
|
1454
|
+
className: "absolute inset-y-0 right-2 my-auto flex h-8 w-8 cursor-pointer items-center justify-center rounded-full hover:bg-pickle-20",
|
|
1455
|
+
onClick: handleClear,
|
|
1456
|
+
children: /* @__PURE__ */ jsx21(CircleX2, { className: "h-4 w-4 text-green-100" })
|
|
1457
|
+
}
|
|
1458
|
+
)
|
|
1459
|
+
] }),
|
|
1460
|
+
predictions && /* @__PURE__ */ jsxs14(
|
|
1461
|
+
CommandList,
|
|
1462
|
+
{
|
|
1463
|
+
className: cn(
|
|
1464
|
+
"absolute z-50 w-full rounded-md border bg-white shadow-lg",
|
|
1465
|
+
shouldOpenUpward ? "bottom-full" : "top-full"
|
|
1466
|
+
),
|
|
1467
|
+
children: [
|
|
1468
|
+
/* @__PURE__ */ jsx21(CommandEmpty, { children: "No results" }),
|
|
1469
|
+
/* @__PURE__ */ jsx21(CommandGroup, { children: predictions.map((prediction) => /* @__PURE__ */ jsx21(
|
|
1470
|
+
CommandItem,
|
|
1471
|
+
{
|
|
1472
|
+
onSelect: () => handleSelect(prediction),
|
|
1473
|
+
className: "truncate",
|
|
1474
|
+
children: prediction.description
|
|
1475
|
+
},
|
|
1476
|
+
prediction.place_id
|
|
1477
|
+
)) })
|
|
1478
|
+
]
|
|
1479
|
+
}
|
|
1480
|
+
)
|
|
1481
|
+
] }) });
|
|
1482
|
+
}
|
|
1483
|
+
var PlacesQueryInput_default = PlacesQueryInput;
|
|
1484
|
+
|
|
1485
|
+
// src/components/demos/PlacesQueryInputDemo.tsx
|
|
1486
|
+
import { useState as useState7 } from "react";
|
|
1487
|
+
import { jsx as jsx22, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
1488
|
+
function PlacesQueryInputDemo() {
|
|
1489
|
+
const [selected, setSelected] = useState7();
|
|
1490
|
+
return /* @__PURE__ */ jsxs15("div", { className: "flex h-24 flex-col p-4", children: [
|
|
1491
|
+
/* @__PURE__ */ jsx22(
|
|
1492
|
+
PlacesQueryInput_default,
|
|
1493
|
+
{
|
|
1494
|
+
className: "max-w-96",
|
|
1495
|
+
apiKey: process.env.NEXT_PUBLIC_GOOGLE_API_KEY ?? "",
|
|
1496
|
+
selected,
|
|
1497
|
+
onSelect: setSelected
|
|
1498
|
+
}
|
|
1499
|
+
),
|
|
1500
|
+
/* @__PURE__ */ jsx22("h3", { className: "px-3", children: selected?.description })
|
|
1501
|
+
] });
|
|
1502
|
+
}
|
|
1503
|
+
var PlacesQueryInputDemo_default = PlacesQueryInputDemo;
|
|
1504
|
+
|
|
1505
|
+
// src/components/ui/MapComponent.tsx
|
|
1506
|
+
import { APIProvider, Map, AdvancedMarker, Pin } from "@vis.gl/react-google-maps";
|
|
1507
|
+
import { jsx as jsx23 } from "react/jsx-runtime";
|
|
1508
|
+
function MapComponent({ apiKey, mapId, position, className, zoom = 15 }) {
|
|
1509
|
+
const defaultPosition = { lat: 40.715021, lng: -74.00459 };
|
|
1510
|
+
const defaultZoom = 11;
|
|
1511
|
+
return /* @__PURE__ */ jsx23(APIProvider, { apiKey, children: /* @__PURE__ */ jsx23("div", { className: cn("h-screen max-w-full", className), children: /* @__PURE__ */ jsx23(
|
|
1512
|
+
Map,
|
|
1513
|
+
{
|
|
1514
|
+
zoom: position ? zoom : defaultZoom,
|
|
1515
|
+
center: position || defaultPosition,
|
|
1516
|
+
mapId,
|
|
1517
|
+
keyboardShortcuts: false,
|
|
1518
|
+
disableDefaultUI: true,
|
|
1519
|
+
children: position && /* @__PURE__ */ jsx23(AdvancedMarker, { position, children: /* @__PURE__ */ jsx23(Pin, { background: "#0B5441", borderColor: "#EBFDF1", glyphColor: "#D4F500" }) })
|
|
1520
|
+
}
|
|
1521
|
+
) }) });
|
|
1522
|
+
}
|
|
1523
|
+
var MapComponent_default = MapComponent;
|
|
1524
|
+
|
|
1525
|
+
// src/components/demos/MapComponentDemo.tsx
|
|
1526
|
+
import { useEffect as useEffect5, useState as useState8 } from "react";
|
|
1527
|
+
import { jsx as jsx24 } from "react/jsx-runtime";
|
|
1528
|
+
var API_KEY = process.env.NEXT_PUBLIC_GOOGLE_API_KEY ?? "";
|
|
1529
|
+
var MAP_ID = process.env.NEXT_PUBLIC_GOOGLE_MAP_ID ?? "";
|
|
1530
|
+
function MapComponentDemo() {
|
|
1531
|
+
const [position, setPosition] = useState8();
|
|
1532
|
+
const place = {
|
|
1533
|
+
place_id: "ChIJaXQRs6lZwokRY6EFpJnhNNE",
|
|
1534
|
+
// Empire State Building Place ID
|
|
1535
|
+
address: "Empire State Building, New York, NY, USA"
|
|
1536
|
+
};
|
|
1537
|
+
useEffect5(() => {
|
|
1538
|
+
fetchLocation(place, API_KEY).then((location) => {
|
|
1539
|
+
if (location) {
|
|
1540
|
+
const { lat, lng } = location.geometry?.location ?? {};
|
|
1541
|
+
if (!lat || !lng) return;
|
|
1542
|
+
setPosition({ lat, lng });
|
|
1543
|
+
}
|
|
1544
|
+
});
|
|
1545
|
+
}, []);
|
|
1546
|
+
return /* @__PURE__ */ jsx24(
|
|
1547
|
+
MapComponent_default,
|
|
1548
|
+
{
|
|
1549
|
+
apiKey: API_KEY,
|
|
1550
|
+
mapId: MAP_ID,
|
|
1551
|
+
className: "h-[36rem] w-[36rem] p-4",
|
|
1552
|
+
position
|
|
1553
|
+
}
|
|
1554
|
+
);
|
|
1555
|
+
}
|
|
1556
|
+
var MapComponentDemo_default = MapComponentDemo;
|
|
1557
|
+
|
|
1558
|
+
// src/components/demos/index.tsx
|
|
1559
|
+
import { jsx as jsx25, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
1332
1560
|
function Demos() {
|
|
1333
|
-
return /* @__PURE__ */
|
|
1334
|
-
/* @__PURE__ */
|
|
1335
|
-
/* @__PURE__ */
|
|
1336
|
-
/* @__PURE__ */
|
|
1337
|
-
/* @__PURE__ */
|
|
1561
|
+
return /* @__PURE__ */ jsxs16("div", { children: [
|
|
1562
|
+
/* @__PURE__ */ jsx25(ComboboxDemo_default, {}),
|
|
1563
|
+
/* @__PURE__ */ jsx25(SelectDemo_default, {}),
|
|
1564
|
+
/* @__PURE__ */ jsx25(InputDemo_default, {}),
|
|
1565
|
+
/* @__PURE__ */ jsx25(CounterDemo_default, {}),
|
|
1566
|
+
/* @__PURE__ */ jsx25(PlacesQueryInputDemo_default, {}),
|
|
1567
|
+
/* @__PURE__ */ jsx25(MapComponentDemo_default, {})
|
|
1338
1568
|
] });
|
|
1339
1569
|
}
|
|
1340
1570
|
var demos_default = Demos;
|