@next-degree/pickle-shared-js 0.3.30 → 0.4.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.
Files changed (39) hide show
  1. package/dist/app/layout.css +29 -0
  2. package/dist/app/layout.css.map +1 -1
  3. package/dist/app/page.cjs +148 -8
  4. package/dist/app/page.cjs.map +1 -1
  5. package/dist/app/page.js +148 -8
  6. package/dist/app/page.js.map +1 -1
  7. package/dist/components/demos/PlacesQueryInputDemo.cjs +341 -0
  8. package/dist/components/demos/PlacesQueryInputDemo.cjs.map +1 -0
  9. package/dist/components/demos/PlacesQueryInputDemo.d.cts +5 -0
  10. package/dist/components/demos/PlacesQueryInputDemo.d.ts +5 -0
  11. package/dist/components/demos/PlacesQueryInputDemo.js +309 -0
  12. package/dist/components/demos/PlacesQueryInputDemo.js.map +1 -0
  13. package/dist/components/demos/index.cjs +146 -6
  14. package/dist/components/demos/index.cjs.map +1 -1
  15. package/dist/components/demos/index.js +146 -6
  16. package/dist/components/demos/index.js.map +1 -1
  17. package/dist/components/primitives/command.d.cts +1 -1
  18. package/dist/components/primitives/command.d.ts +1 -1
  19. package/dist/components/ui/PlacesQueryInput.cjs +321 -0
  20. package/dist/components/ui/PlacesQueryInput.cjs.map +1 -0
  21. package/dist/components/ui/PlacesQueryInput.d.cts +18 -0
  22. package/dist/components/ui/PlacesQueryInput.d.ts +18 -0
  23. package/dist/components/ui/PlacesQueryInput.js +289 -0
  24. package/dist/components/ui/PlacesQueryInput.js.map +1 -0
  25. package/dist/index.cjs +306 -185
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +2 -0
  28. package/dist/index.d.ts +2 -0
  29. package/dist/index.js +298 -178
  30. package/dist/index.js.map +1 -1
  31. package/dist/lib/google.cjs +43 -0
  32. package/dist/lib/google.cjs.map +1 -0
  33. package/dist/lib/google.d.cts +5 -0
  34. package/dist/lib/google.d.ts +5 -0
  35. package/dist/lib/google.js +19 -0
  36. package/dist/lib/google.js.map +1 -0
  37. package/dist/styles/globals.css +29 -0
  38. package/dist/styles/globals.css.map +1 -1
  39. package/package.json +22 -21
@@ -0,0 +1,309 @@
1
+ "use client";
2
+
3
+ // src/components/primitives/command.tsx
4
+ import { Command as CommandPrimitive } from "cmdk";
5
+ import { Search } from "lucide-react";
6
+ import * as React2 from "react";
7
+
8
+ // src/lib/utils.ts
9
+ import { clsx } from "clsx";
10
+ import { twMerge } from "tailwind-merge";
11
+ function cn(...inputs) {
12
+ return twMerge(clsx(inputs));
13
+ }
14
+
15
+ // src/components/primitives/dialog.tsx
16
+ import * as DialogPrimitive from "@radix-ui/react-dialog";
17
+ import { X } from "lucide-react";
18
+ import * as React from "react";
19
+ import { jsx, jsxs } from "react/jsx-runtime";
20
+ var DialogPortal = DialogPrimitive.Portal;
21
+ var DialogOverlay = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
22
+ DialogPrimitive.Overlay,
23
+ {
24
+ ref,
25
+ className: cn(
26
+ "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
27
+ className
28
+ ),
29
+ ...props
30
+ }
31
+ ));
32
+ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
33
+ var DialogContent = React.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxs(DialogPortal, { children: [
34
+ /* @__PURE__ */ jsx(DialogOverlay, {}),
35
+ /* @__PURE__ */ jsxs(
36
+ DialogPrimitive.Content,
37
+ {
38
+ ref,
39
+ className: cn(
40
+ "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-neutral-200 bg-white p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg dark:border-neutral-800 dark:bg-neutral-950",
41
+ className
42
+ ),
43
+ ...props,
44
+ children: [
45
+ children,
46
+ /* @__PURE__ */ jsxs(DialogPrimitive.Close, { className: "absolute right-4 top-4 rounded-sm opacity-70 ring-offset-white transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-neutral-950 focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-neutral-100 data-[state=open]:text-neutral-500 dark:ring-offset-neutral-950 dark:focus:ring-neutral-300 dark:data-[state=open]:bg-neutral-800 dark:data-[state=open]:text-neutral-400", children: [
47
+ /* @__PURE__ */ jsx(X, { className: "h-4 w-4" }),
48
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Close" })
49
+ ] })
50
+ ]
51
+ }
52
+ )
53
+ ] }));
54
+ DialogContent.displayName = DialogPrimitive.Content.displayName;
55
+ var DialogHeader = ({ className, ...props }) => /* @__PURE__ */ jsx("div", { className: cn("flex flex-col space-y-1.5 text-center sm:text-left", className), ...props });
56
+ DialogHeader.displayName = "DialogHeader";
57
+ var DialogFooter = ({ className, ...props }) => /* @__PURE__ */ jsx(
58
+ "div",
59
+ {
60
+ className: cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className),
61
+ ...props
62
+ }
63
+ );
64
+ DialogFooter.displayName = "DialogFooter";
65
+ var DialogTitle = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
66
+ DialogPrimitive.Title,
67
+ {
68
+ ref,
69
+ className: cn("text-lg font-semibold leading-none tracking-tight", className),
70
+ ...props
71
+ }
72
+ ));
73
+ DialogTitle.displayName = DialogPrimitive.Title.displayName;
74
+ var DialogDescription = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
75
+ DialogPrimitive.Description,
76
+ {
77
+ ref,
78
+ className: cn("text-sm text-neutral-500 dark:text-neutral-400", className),
79
+ ...props
80
+ }
81
+ ));
82
+ DialogDescription.displayName = DialogPrimitive.Description.displayName;
83
+
84
+ // src/components/primitives/command.tsx
85
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
86
+ var Command = React2.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx2(
87
+ CommandPrimitive,
88
+ {
89
+ ref,
90
+ className: cn(
91
+ "flex h-full w-full flex-col overflow-hidden rounded-xl bg-white text-neutral-950",
92
+ className
93
+ ),
94
+ ...props
95
+ }
96
+ ));
97
+ Command.displayName = CommandPrimitive.displayName;
98
+ var CommandInput = React2.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxs2("div", { className: "m-1 flex items-center rounded-xl border px-3", "cmdk-input-wrapper": "", children: [
99
+ /* @__PURE__ */ jsx2(Search, { className: "mr-2 h-4 w-4 shrink-0 opacity-50" }),
100
+ /* @__PURE__ */ jsx2(
101
+ CommandPrimitive.Input,
102
+ {
103
+ ref,
104
+ className: cn(
105
+ "flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-neutral-500 disabled:cursor-not-allowed disabled:opacity-50",
106
+ className
107
+ ),
108
+ ...props
109
+ }
110
+ )
111
+ ] }));
112
+ CommandInput.displayName = CommandPrimitive.Input.displayName;
113
+ var CommandList = React2.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx2(
114
+ CommandPrimitive.List,
115
+ {
116
+ ref,
117
+ className: cn("overflow-y-auto overflow-x-hidden", className),
118
+ ...props
119
+ }
120
+ ));
121
+ CommandList.displayName = CommandPrimitive.List.displayName;
122
+ var CommandEmpty = React2.forwardRef((props, ref) => /* @__PURE__ */ jsx2(CommandPrimitive.Empty, { ref, className: "py-6 text-center text-sm", ...props }));
123
+ CommandEmpty.displayName = CommandPrimitive.Empty.displayName;
124
+ var CommandGroup = React2.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx2(
125
+ CommandPrimitive.Group,
126
+ {
127
+ ref,
128
+ className: cn(
129
+ "overflow-hidden p-1 text-neutral-950 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-neutral-500",
130
+ className
131
+ ),
132
+ ...props
133
+ }
134
+ ));
135
+ CommandGroup.displayName = CommandPrimitive.Group.displayName;
136
+ var CommandSeparator = React2.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx2(
137
+ CommandPrimitive.Separator,
138
+ {
139
+ ref,
140
+ className: cn("-mx-1 h-px bg-neutral-200", className),
141
+ ...props
142
+ }
143
+ ));
144
+ CommandSeparator.displayName = CommandPrimitive.Separator.displayName;
145
+ var CommandItem = React2.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx2(
146
+ CommandPrimitive.Item,
147
+ {
148
+ ref,
149
+ className: cn(
150
+ "relative flex cursor-pointer select-none items-center rounded-xl px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-neutral-100 data-[selected=true]:text-neutral-900 data-[disabled=true]:opacity-50",
151
+ className
152
+ ),
153
+ ...props
154
+ }
155
+ ));
156
+ CommandItem.displayName = CommandPrimitive.Item.displayName;
157
+ var CommandShortcut = ({ className, ...props }) => {
158
+ return /* @__PURE__ */ jsx2(
159
+ "span",
160
+ {
161
+ className: cn("ml-auto text-xs tracking-widest text-neutral-500", className),
162
+ ...props
163
+ }
164
+ );
165
+ };
166
+ CommandShortcut.displayName = "CommandShortcut";
167
+
168
+ // src/lib/google.ts
169
+ import { Client, PlaceAutocompleteType } from "@googlemaps/google-maps-services-js";
170
+ var client = new Client();
171
+ var autocomplete = async (input, key) => {
172
+ try {
173
+ const response = await client.placeAutocomplete({
174
+ params: { input, key, types: PlaceAutocompleteType.address }
175
+ });
176
+ return response.data.predictions;
177
+ } catch (error) {
178
+ console.error(error);
179
+ }
180
+ };
181
+
182
+ // src/components/ui/PlacesQueryInput.tsx
183
+ import { CircleX, LoaderCircle } from "lucide-react";
184
+ import { useState, useCallback, useRef, useEffect } from "react";
185
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
186
+ function PlacesQueryInput({
187
+ apiKey,
188
+ selected,
189
+ onSelect,
190
+ className
191
+ }) {
192
+ const [predictions, setPredictions] = useState(null);
193
+ const [input, setInput] = useState(selected?.description ?? "");
194
+ const [isLoadingPredictions, setIsLoadingPredictions] = useState(false);
195
+ const [shouldOpenUpward, setShouldOpenUpward] = useState(false);
196
+ const timeoutRef = useRef(null);
197
+ const inputRef = useRef(null);
198
+ const debouncedAutocomplete = useCallback((value) => {
199
+ if (timeoutRef.current) {
200
+ clearTimeout(timeoutRef.current);
201
+ }
202
+ timeoutRef.current = setTimeout(async () => {
203
+ if (value.length > 2) {
204
+ setIsLoadingPredictions(true);
205
+ const fetchedPredictions = await autocomplete(value, apiKey);
206
+ fetchedPredictions && setIsLoadingPredictions(false);
207
+ setPredictions(fetchedPredictions ?? []);
208
+ } else {
209
+ setPredictions(null);
210
+ }
211
+ }, 300);
212
+ }, []);
213
+ const handleInputChange = (value) => {
214
+ setInput(value);
215
+ debouncedAutocomplete(value);
216
+ };
217
+ const handleSelect = (prediction) => {
218
+ onSelect(prediction);
219
+ setPredictions(null);
220
+ setInput(prediction.description);
221
+ };
222
+ const handleClear = () => {
223
+ onSelect();
224
+ setPredictions(null);
225
+ setInput("");
226
+ };
227
+ const handleBlur = () => setTimeout(() => setPredictions(null), 200);
228
+ useEffect(() => {
229
+ const checkDropdownPosition = () => {
230
+ if (inputRef.current) {
231
+ const rect = inputRef.current.getBoundingClientRect();
232
+ const windowHeight = window.innerHeight;
233
+ setShouldOpenUpward(rect.bottom + 200 > windowHeight);
234
+ }
235
+ };
236
+ checkDropdownPosition();
237
+ window.addEventListener("resize", checkDropdownPosition);
238
+ return () => window.removeEventListener("resize", checkDropdownPosition);
239
+ }, []);
240
+ return /* @__PURE__ */ jsx3("div", { className: cn("relative w-full", className), ref: inputRef, onBlur: handleBlur, children: /* @__PURE__ */ jsxs3(Command, { children: [
241
+ /* @__PURE__ */ jsxs3("div", { className: "relative w-full", children: [
242
+ /* @__PURE__ */ jsx3(
243
+ CommandInput,
244
+ {
245
+ placeholder: "Type an address to search...",
246
+ value: input,
247
+ onValueChange: handleInputChange,
248
+ className: "truncate pr-8"
249
+ }
250
+ ),
251
+ isLoadingPredictions && /* @__PURE__ */ jsx3(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" }),
252
+ input && /* @__PURE__ */ jsx3(
253
+ "button",
254
+ {
255
+ type: "button",
256
+ 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",
257
+ onClick: handleClear,
258
+ children: /* @__PURE__ */ jsx3(CircleX, { className: "h-4 w-4 text-green-100" })
259
+ }
260
+ )
261
+ ] }),
262
+ predictions && /* @__PURE__ */ jsxs3(
263
+ CommandList,
264
+ {
265
+ className: cn(
266
+ "absolute z-50 w-full rounded-md border bg-white shadow-lg",
267
+ shouldOpenUpward ? "bottom-full" : "top-full"
268
+ ),
269
+ children: [
270
+ /* @__PURE__ */ jsx3(CommandEmpty, { children: "No results" }),
271
+ /* @__PURE__ */ jsx3(CommandGroup, { children: predictions.map((prediction) => /* @__PURE__ */ jsx3(
272
+ CommandItem,
273
+ {
274
+ onSelect: () => handleSelect(prediction),
275
+ className: "truncate",
276
+ children: prediction.description
277
+ },
278
+ prediction.place_id
279
+ )) })
280
+ ]
281
+ }
282
+ )
283
+ ] }) });
284
+ }
285
+ var PlacesQueryInput_default = PlacesQueryInput;
286
+
287
+ // src/components/demos/PlacesQueryInputDemo.tsx
288
+ import { useState as useState2 } from "react";
289
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
290
+ function PlacesQueryInputDemo() {
291
+ const [selected, setSelected] = useState2();
292
+ return /* @__PURE__ */ jsxs4("div", { className: "flex h-24 flex-col p-4", children: [
293
+ /* @__PURE__ */ jsx4(
294
+ PlacesQueryInput_default,
295
+ {
296
+ className: "max-w-96",
297
+ apiKey: process.env.NEXT_PUBLIC_GOOGLE_API_KEY ?? "",
298
+ selected,
299
+ onSelect: setSelected
300
+ }
301
+ ),
302
+ /* @__PURE__ */ jsx4("h3", { className: "px-3", children: selected?.description })
303
+ ] });
304
+ }
305
+ var PlacesQueryInputDemo_default = PlacesQueryInputDemo;
306
+ export {
307
+ PlacesQueryInputDemo_default as default
308
+ };
309
+ //# sourceMappingURL=PlacesQueryInputDemo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/primitives/command.tsx","../../../src/lib/utils.ts","../../../src/components/primitives/dialog.tsx","../../../src/lib/google.ts","../../../src/components/ui/PlacesQueryInput.tsx","../../../src/components/demos/PlacesQueryInputDemo.tsx"],"sourcesContent":["'use client'\n\nimport { type DialogProps } from '@radix-ui/react-dialog'\nimport { Command as CommandPrimitive } from 'cmdk'\nimport { Search } from 'lucide-react'\nimport * as React from 'react'\n\nimport { Dialog, DialogContent } from '@/components/primitives/dialog'\n\nimport { cn } from '@/lib/utils'\n\nconst Command = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive>\n>(({ className, ...props }, ref) => (\n <CommandPrimitive\n ref={ref}\n className={cn(\n 'flex h-full w-full flex-col overflow-hidden rounded-xl bg-white text-neutral-950',\n className\n )}\n {...props}\n />\n))\nCommand.displayName = CommandPrimitive.displayName\n\ntype CommandDialogProps = DialogProps\n\nconst CommandDialog = ({ children, ...props }: CommandDialogProps) => {\n return (\n <Dialog {...props}>\n <DialogContent className=\"overflow-hidden p-0 shadow-lg\">\n <Command className=\"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-neutral-500 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5\">\n {children}\n </Command>\n </DialogContent>\n </Dialog>\n )\n}\n\nconst CommandInput = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.Input>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>\n>(({ className, ...props }, ref) => (\n <div className=\"m-1 flex items-center rounded-xl border px-3\" cmdk-input-wrapper=\"\">\n <Search className=\"mr-2 h-4 w-4 shrink-0 opacity-50\" />\n <CommandPrimitive.Input\n ref={ref}\n className={cn(\n 'flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-neutral-500 disabled:cursor-not-allowed disabled:opacity-50',\n className\n )}\n {...props}\n />\n </div>\n))\n\nCommandInput.displayName = CommandPrimitive.Input.displayName\n\nconst CommandList = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.List>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>\n>(({ className, ...props }, ref) => (\n <CommandPrimitive.List\n ref={ref}\n className={cn('overflow-y-auto overflow-x-hidden', className)}\n {...props}\n />\n))\n\nCommandList.displayName = CommandPrimitive.List.displayName\n\nconst CommandEmpty = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.Empty>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>\n>((props, ref) => (\n <CommandPrimitive.Empty ref={ref} className=\"py-6 text-center text-sm\" {...props} />\n))\n\nCommandEmpty.displayName = CommandPrimitive.Empty.displayName\n\nconst CommandGroup = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.Group>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>\n>(({ className, ...props }, ref) => (\n <CommandPrimitive.Group\n ref={ref}\n className={cn(\n 'overflow-hidden p-1 text-neutral-950 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-neutral-500',\n className\n )}\n {...props}\n />\n))\n\nCommandGroup.displayName = CommandPrimitive.Group.displayName\n\nconst CommandSeparator = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.Separator>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>\n>(({ className, ...props }, ref) => (\n <CommandPrimitive.Separator\n ref={ref}\n className={cn('-mx-1 h-px bg-neutral-200', className)}\n {...props}\n />\n))\nCommandSeparator.displayName = CommandPrimitive.Separator.displayName\n\nconst CommandItem = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.Item>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>\n>(({ className, ...props }, ref) => (\n <CommandPrimitive.Item\n ref={ref}\n className={cn(\n \"relative flex cursor-pointer select-none items-center rounded-xl px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-neutral-100 data-[selected=true]:text-neutral-900 data-[disabled=true]:opacity-50\",\n className\n )}\n {...props}\n />\n))\n\nCommandItem.displayName = CommandPrimitive.Item.displayName\n\nconst CommandShortcut = ({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>) => {\n return (\n <span\n className={cn('ml-auto text-xs tracking-widest text-neutral-500', className)}\n {...props}\n />\n )\n}\nCommandShortcut.displayName = 'CommandShortcut'\n\nexport {\n Command,\n CommandDialog,\n CommandEmpty,\n CommandGroup,\n CommandInput,\n CommandItem,\n CommandList,\n CommandSeparator,\n CommandShortcut,\n}\n","import { type ClassValue, clsx } from 'clsx'\nimport { twMerge } from 'tailwind-merge'\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs))\n}\n","'use client'\n\nimport { cn } from '@/lib/utils'\nimport * as DialogPrimitive from '@radix-ui/react-dialog'\nimport { X } from 'lucide-react'\nimport * as React from 'react'\n\nconst Dialog = DialogPrimitive.Root\n\nconst DialogTrigger = DialogPrimitive.Trigger\n\nconst DialogPortal = DialogPrimitive.Portal\n\nconst DialogClose = DialogPrimitive.Close\n\nconst DialogOverlay = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Overlay>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Overlay\n ref={ref}\n className={cn(\n 'fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',\n className\n )}\n {...props}\n />\n))\nDialogOverlay.displayName = DialogPrimitive.Overlay.displayName\n\nconst DialogContent = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>\n>(({ className, children, ...props }, ref) => (\n <DialogPortal>\n <DialogOverlay />\n <DialogPrimitive.Content\n ref={ref}\n className={cn(\n 'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-neutral-200 bg-white p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg dark:border-neutral-800 dark:bg-neutral-950',\n className\n )}\n {...props}\n >\n {children}\n <DialogPrimitive.Close className=\"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-white transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-neutral-950 focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-neutral-100 data-[state=open]:text-neutral-500 dark:ring-offset-neutral-950 dark:focus:ring-neutral-300 dark:data-[state=open]:bg-neutral-800 dark:data-[state=open]:text-neutral-400\">\n <X className=\"h-4 w-4\" />\n <span className=\"sr-only\">Close</span>\n </DialogPrimitive.Close>\n </DialogPrimitive.Content>\n </DialogPortal>\n))\nDialogContent.displayName = DialogPrimitive.Content.displayName\n\nconst DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (\n <div className={cn('flex flex-col space-y-1.5 text-center sm:text-left', className)} {...props} />\n)\nDialogHeader.displayName = 'DialogHeader'\n\nconst DialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (\n <div\n className={cn('flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2', className)}\n {...props}\n />\n)\nDialogFooter.displayName = 'DialogFooter'\n\nconst DialogTitle = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Title>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Title\n ref={ref}\n className={cn('text-lg font-semibold leading-none tracking-tight', className)}\n {...props}\n />\n))\nDialogTitle.displayName = DialogPrimitive.Title.displayName\n\nconst DialogDescription = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Description>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Description\n ref={ref}\n className={cn('text-sm text-neutral-500 dark:text-neutral-400', className)}\n {...props}\n />\n))\nDialogDescription.displayName = DialogPrimitive.Description.displayName\n\nexport {\n Dialog,\n DialogClose,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogOverlay,\n DialogPortal,\n DialogTitle,\n DialogTrigger,\n}\n","'use server'\n\nimport { Client, PlaceAutocompleteType } from '@googlemaps/google-maps-services-js'\n\nconst client = new Client()\nexport const autocomplete = async (input: string, key: string) => {\n try {\n const response = await client.placeAutocomplete({\n params: { input, key, types: PlaceAutocompleteType.address },\n })\n\n return response.data.predictions\n } catch (error) {\n console.error(error)\n }\n}\n","'use client'\n\nimport {\n Command,\n CommandEmpty,\n CommandGroup,\n CommandInput,\n CommandItem,\n CommandList,\n} from '@/components/primitives/command'\nimport { autocomplete } from '@/lib/google'\nimport { cn } from '@/lib/utils'\nimport { type PlaceAutocompleteResult } from '@googlemaps/google-maps-services-js'\nimport { CircleX, LoaderCircle } from 'lucide-react'\nimport { useState, useCallback, useRef, useEffect } from 'react'\n\n/**\n * The idea is of this type is to have a more specific type for the Place object,\n * without the repos that use it having to import the PlaceAutocompleteResult type.\n * 'place_id' can be used to query the Google Places API directly for more information about the place.\n */\nexport type Place = Pick<PlaceAutocompleteResult, 'description' | 'place_id'>\n\ninterface PlacesQueryInputProps {\n apiKey: string\n selected?: Place\n onSelect: (place?: Place) => void\n className?: string\n}\n\nfunction PlacesQueryInput({\n apiKey,\n selected,\n onSelect,\n className,\n}: Readonly<PlacesQueryInputProps>) {\n const [predictions, setPredictions] = useState<PlaceAutocompleteResult[] | null>(null)\n const [input, setInput] = useState(selected?.description ?? '')\n const [isLoadingPredictions, setIsLoadingPredictions] = useState(false)\n const [shouldOpenUpward, setShouldOpenUpward] = useState(false)\n const timeoutRef = useRef<NodeJS.Timeout | null>(null)\n const inputRef = useRef<HTMLDivElement | null>(null)\n\n const debouncedAutocomplete = useCallback((value: string) => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current)\n }\n\n timeoutRef.current = setTimeout(async () => {\n if (value.length > 2) {\n setIsLoadingPredictions(true)\n const fetchedPredictions = await autocomplete(value, apiKey)\n fetchedPredictions && setIsLoadingPredictions(false)\n setPredictions(fetchedPredictions ?? [])\n } else {\n setPredictions(null)\n }\n }, 300)\n }, [])\n\n const handleInputChange = (value: string) => {\n setInput(value)\n debouncedAutocomplete(value)\n }\n\n const handleSelect = (prediction: PlaceAutocompleteResult) => {\n onSelect(prediction)\n setPredictions(null)\n setInput(prediction.description)\n }\n\n const handleClear = () => {\n onSelect()\n setPredictions(null)\n setInput('')\n }\n\n /** Close the dropdown when the input loses focus, with the timeout to allow the user to click on a prediction.\n * */\n const handleBlur = () => setTimeout(() => setPredictions(null), 200)\n\n useEffect(() => {\n const checkDropdownPosition = () => {\n if (inputRef.current) {\n const rect = inputRef.current.getBoundingClientRect()\n const windowHeight = window.innerHeight\n setShouldOpenUpward(rect.bottom + 200 > windowHeight)\n }\n }\n\n checkDropdownPosition()\n window.addEventListener('resize', checkDropdownPosition)\n return () => window.removeEventListener('resize', checkDropdownPosition)\n }, [])\n\n return (\n <div className={cn('relative w-full', className)} ref={inputRef} onBlur={handleBlur}>\n <Command>\n <div className=\"relative w-full\">\n <CommandInput\n placeholder=\"Type an address to search...\"\n value={input}\n onValueChange={handleInputChange}\n className=\"truncate pr-8\"\n />\n {isLoadingPredictions && (\n <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\" />\n )}\n {input && (\n <button\n type=\"button\"\n 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\"\n onClick={handleClear}\n >\n <CircleX className=\"h-4 w-4 text-green-100\" />\n </button>\n )}\n </div>\n {predictions && (\n <CommandList\n className={cn(\n 'absolute z-50 w-full rounded-md border bg-white shadow-lg',\n shouldOpenUpward ? 'bottom-full' : 'top-full'\n )}\n >\n <CommandEmpty>No results</CommandEmpty>\n <CommandGroup>\n {predictions.map((prediction) => (\n <CommandItem\n key={prediction.place_id}\n onSelect={() => handleSelect(prediction)}\n className=\"truncate\"\n >\n {prediction.description}\n </CommandItem>\n ))}\n </CommandGroup>\n </CommandList>\n )}\n </Command>\n </div>\n )\n}\n\nexport default PlacesQueryInput\n","'use client'\n\nimport PlacesQueryInput from '@/components/ui/PlacesQueryInput'\nimport { useState } from 'react'\n\ninterface Place {\n description: string\n place_id: string\n}\n\nfunction PlacesQueryInputDemo() {\n const [selected, setSelected] = useState<Place | undefined>()\n\n return (\n <div className=\"flex h-24 flex-col p-4\">\n <PlacesQueryInput\n className=\"max-w-96\"\n apiKey={process.env.NEXT_PUBLIC_GOOGLE_API_KEY ?? ''}\n selected={selected}\n onSelect={setSelected}\n />\n <h3 className=\"px-3\">{selected?.description}</h3>\n </div>\n )\n}\n\nexport default PlacesQueryInputDemo\n"],"mappings":";;;AAGA,SAAS,WAAW,wBAAwB;AAC5C,SAAS,cAAc;AACvB,YAAYA,YAAW;;;ACLvB,SAA0B,YAAY;AACtC,SAAS,eAAe;AAEjB,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;;;ACFA,YAAY,qBAAqB;AACjC,SAAS,SAAS;AAClB,YAAY,WAAW;AAcrB,cA0BI,YA1BJ;AARF,IAAM,eAA+B;AAIrC,IAAM,gBAAsB,iBAG1B,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,QAC1B;AAAA,EAAiB;AAAA,EAAhB;AAAA,IACC;AAAA,IACA,WAAW;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,IACC,GAAG;AAAA;AACN,CACD;AACD,cAAc,cAA8B,wBAAQ;AAEpD,IAAM,gBAAsB,iBAG1B,CAAC,EAAE,WAAW,UAAU,GAAG,MAAM,GAAG,QACpC,qBAAC,gBACC;AAAA,sBAAC,iBAAc;AAAA,EACf;AAAA,IAAiB;AAAA,IAAhB;AAAA,MACC;AAAA,MACA,WAAW;AAAA,QACT;AAAA,QACA;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEH;AAAA;AAAA,QACD,qBAAiB,uBAAhB,EAAsB,WAAU,0ZAC/B;AAAA,8BAAC,KAAE,WAAU,WAAU;AAAA,UACvB,oBAAC,UAAK,WAAU,WAAU,mBAAK;AAAA,WACjC;AAAA;AAAA;AAAA,EACF;AAAA,GACF,CACD;AACD,cAAc,cAA8B,wBAAQ;AAEpD,IAAM,eAAe,CAAC,EAAE,WAAW,GAAG,MAAM,MAC1C,oBAAC,SAAI,WAAW,GAAG,sDAAsD,SAAS,GAAI,GAAG,OAAO;AAElG,aAAa,cAAc;AAE3B,IAAM,eA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gBAAa,wBAAU;AAAA,UACxB,gBAAAA,KAAC,gBACE,sBAAY,IAAI,CAAC,eAChB,gBAAAA;AAAA,YAAC;AAAA;AAAA,cAEC,UAAU,MAAM,aAAa,UAAU;AAAA,cACvC,WAAU;AAAA,cAET,qBAAW;AAAA;AAAA,YAJP,WAAW;AAAA,UAKlB,CACD,GACH;AAAA;AAAA;AAAA,IACF;AAAA,KAEJ,GACF;AAEJ;AAEA,IAAO,2BAAQ;;;AC7If,SAAS,YAAAE,iBAAgB;AAWrB,SACE,OAAAC,MADF,QAAAC,aAAA;AAJJ,SAAS,uBAAuB;AAC9B,QAAM,CAAC,UAAU,WAAW,IAAIF,UAA4B;AAE5D,SACE,gBAAAE,MAAC,SAAI,WAAU,0BACb;AAAA,oBAAAD;AAAA,MAAC;AAAA;AAAA,QACC,WAAU;AAAA,QACV,QAAQ,QAAQ,IAAI,8BAA8B;AAAA,QAClD;AAAA,QACA,UAAU;AAAA;AAAA,IACZ;AAAA,IACA,gBAAAA,KAAC,QAAG,WAAU,QAAQ,oBAAU,aAAY;AAAA,KAC9C;AAEJ;AAEA,IAAO,+BAAQ;","names":["React","jsx","jsxs","jsxs","jsx","jsx","jsxs","useState","jsx","jsxs"]}
@@ -1356,14 +1356,154 @@ function CounterDemo() {
1356
1356
  }
1357
1357
  var CounterDemo_default = CounterDemo;
1358
1358
 
1359
- // src/components/demos/index.tsx
1359
+ // src/lib/google.ts
1360
+ var import_google_maps_services_js = require("@googlemaps/google-maps-services-js");
1361
+ var client = new import_google_maps_services_js.Client();
1362
+ var autocomplete = async (input, key) => {
1363
+ try {
1364
+ const response = await client.placeAutocomplete({
1365
+ params: { input, key, types: import_google_maps_services_js.PlaceAutocompleteType.address }
1366
+ });
1367
+ return response.data.predictions;
1368
+ } catch (error) {
1369
+ console.error(error);
1370
+ }
1371
+ };
1372
+
1373
+ // src/components/ui/PlacesQueryInput.tsx
1374
+ var import_lucide_react11 = require("lucide-react");
1375
+ var import_react9 = require("react");
1360
1376
  var import_jsx_runtime21 = require("react/jsx-runtime");
1377
+ function PlacesQueryInput({
1378
+ apiKey,
1379
+ selected,
1380
+ onSelect,
1381
+ className
1382
+ }) {
1383
+ const [predictions, setPredictions] = (0, import_react9.useState)(null);
1384
+ const [input, setInput] = (0, import_react9.useState)(selected?.description ?? "");
1385
+ const [isLoadingPredictions, setIsLoadingPredictions] = (0, import_react9.useState)(false);
1386
+ const [shouldOpenUpward, setShouldOpenUpward] = (0, import_react9.useState)(false);
1387
+ const timeoutRef = (0, import_react9.useRef)(null);
1388
+ const inputRef = (0, import_react9.useRef)(null);
1389
+ const debouncedAutocomplete = (0, import_react9.useCallback)((value) => {
1390
+ if (timeoutRef.current) {
1391
+ clearTimeout(timeoutRef.current);
1392
+ }
1393
+ timeoutRef.current = setTimeout(async () => {
1394
+ if (value.length > 2) {
1395
+ setIsLoadingPredictions(true);
1396
+ const fetchedPredictions = await autocomplete(value, apiKey);
1397
+ fetchedPredictions && setIsLoadingPredictions(false);
1398
+ setPredictions(fetchedPredictions ?? []);
1399
+ } else {
1400
+ setPredictions(null);
1401
+ }
1402
+ }, 300);
1403
+ }, []);
1404
+ const handleInputChange = (value) => {
1405
+ setInput(value);
1406
+ debouncedAutocomplete(value);
1407
+ };
1408
+ const handleSelect = (prediction) => {
1409
+ onSelect(prediction);
1410
+ setPredictions(null);
1411
+ setInput(prediction.description);
1412
+ };
1413
+ const handleClear = () => {
1414
+ onSelect();
1415
+ setPredictions(null);
1416
+ setInput("");
1417
+ };
1418
+ const handleBlur = () => setTimeout(() => setPredictions(null), 200);
1419
+ (0, import_react9.useEffect)(() => {
1420
+ const checkDropdownPosition = () => {
1421
+ if (inputRef.current) {
1422
+ const rect = inputRef.current.getBoundingClientRect();
1423
+ const windowHeight = window.innerHeight;
1424
+ setShouldOpenUpward(rect.bottom + 200 > windowHeight);
1425
+ }
1426
+ };
1427
+ checkDropdownPosition();
1428
+ window.addEventListener("resize", checkDropdownPosition);
1429
+ return () => window.removeEventListener("resize", checkDropdownPosition);
1430
+ }, []);
1431
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: cn("relative w-full", className), ref: inputRef, onBlur: handleBlur, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(Command, { children: [
1432
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "relative w-full", children: [
1433
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
1434
+ CommandInput,
1435
+ {
1436
+ placeholder: "Type an address to search...",
1437
+ value: input,
1438
+ onValueChange: handleInputChange,
1439
+ className: "truncate pr-8"
1440
+ }
1441
+ ),
1442
+ isLoadingPredictions && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react11.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" }),
1443
+ input && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
1444
+ "button",
1445
+ {
1446
+ type: "button",
1447
+ 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",
1448
+ onClick: handleClear,
1449
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react11.CircleX, { className: "h-4 w-4 text-green-100" })
1450
+ }
1451
+ )
1452
+ ] }),
1453
+ predictions && /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
1454
+ CommandList,
1455
+ {
1456
+ className: cn(
1457
+ "absolute z-50 w-full rounded-md border bg-white shadow-lg",
1458
+ shouldOpenUpward ? "bottom-full" : "top-full"
1459
+ ),
1460
+ children: [
1461
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(CommandEmpty, { children: "No results" }),
1462
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(CommandGroup, { children: predictions.map((prediction) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
1463
+ CommandItem,
1464
+ {
1465
+ onSelect: () => handleSelect(prediction),
1466
+ className: "truncate",
1467
+ children: prediction.description
1468
+ },
1469
+ prediction.place_id
1470
+ )) })
1471
+ ]
1472
+ }
1473
+ )
1474
+ ] }) });
1475
+ }
1476
+ var PlacesQueryInput_default = PlacesQueryInput;
1477
+
1478
+ // src/components/demos/PlacesQueryInputDemo.tsx
1479
+ var import_react10 = require("react");
1480
+ var import_jsx_runtime22 = require("react/jsx-runtime");
1481
+ function PlacesQueryInputDemo() {
1482
+ const [selected, setSelected] = (0, import_react10.useState)();
1483
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "flex h-24 flex-col p-4", children: [
1484
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1485
+ PlacesQueryInput_default,
1486
+ {
1487
+ className: "max-w-96",
1488
+ apiKey: process.env.NEXT_PUBLIC_GOOGLE_API_KEY ?? "",
1489
+ selected,
1490
+ onSelect: setSelected
1491
+ }
1492
+ ),
1493
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("h3", { className: "px-3", children: selected?.description })
1494
+ ] });
1495
+ }
1496
+ var PlacesQueryInputDemo_default = PlacesQueryInputDemo;
1497
+
1498
+ // src/components/demos/index.tsx
1499
+ var import_jsx_runtime23 = require("react/jsx-runtime");
1361
1500
  function Demos() {
1362
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { children: [
1363
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ComboboxDemo_default, {}),
1364
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SelectDemo_default, {}),
1365
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(InputDemo_default, {}),
1366
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(CounterDemo_default, {})
1501
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { children: [
1502
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ComboboxDemo_default, {}),
1503
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(SelectDemo_default, {}),
1504
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(InputDemo_default, {}),
1505
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(CounterDemo_default, {}),
1506
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(PlacesQueryInputDemo_default, {})
1367
1507
  ] });
1368
1508
  }
1369
1509
  var demos_default = Demos;