@usequeek/theme-kit 0.1.44 → 0.2.0

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 CHANGED
@@ -135,7 +135,6 @@ they keep the data already on screen. They return `isLoading`, except
135
135
  | `useAuth()` | `hooks/use-auth` | The signed-in customer and sign-in modal controls |
136
136
  | `useVariantSelection(product, preferredVariantPId?)` | `hooks/use-variant-selection` | Option selection state and the add-to-cart gate; opens on a linked `?variant=` |
137
137
  | `useSearch(query, products, collections)` | `hooks/use-search` | Instant search over data you hold |
138
- | `useAddressAutocomplete(text)` / `useResolveCoordinates()` | `hooks/use-address-autocomplete`, `hooks/use-resolve-coordinates` | Delivery address lookup |
139
138
  | `useHref()` | `hooks/use-href` | Builds a store-relative link |
140
139
  | `useLocales()` | `hooks/use-locales` | The store's languages and the active one |
141
140
  | `useStorefront()` / `useStorefrontLocale()` / `useThemeStrings()` | `provider` | The store, the request locale, the bound `t` |
package/client.ts CHANGED
@@ -52,8 +52,6 @@ export * from './hooks/use-search';
52
52
  export * from './hooks/use-posts';
53
53
  export * from './hooks/use-reviews';
54
54
  export * from './hooks/use-variant-selection';
55
- export * from './hooks/use-address-autocomplete';
56
- export * from './hooks/use-resolve-coordinates';
57
55
  export * from './stores/cart-panel-store';
58
56
  export * from './stores/product-modal-store';
59
57
  export * from './stores/search-modal-store';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usequeek/theme-kit",
3
- "version": "0.1.44",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "The runtime a Queek storefront theme is built on: hooks, stores, page renderer, navigation, shared blocks and locale strings.",
@@ -1,80 +0,0 @@
1
- 'use client';
2
-
3
- import { useEffect, useState } from 'react';
4
- import { useIsThemePreview, useStorefront, useThemeStrings } from '../provider';
5
- import { getQueekClient } from '../sdk/queek-client';
6
-
7
- /** One address suggestion. Pass `place_id` to `useResolveCoordinates` to get its position. */
8
- export interface AddressSuggestion {
9
- description: string;
10
- place_id: string;
11
- }
12
-
13
- const DEBOUNCE_MS = 300;
14
-
15
- /**
16
- * Address suggestions for what the shopper has typed, after a 300 ms pause.
17
- * Nothing is requested for fewer than two characters. A failed request clears
18
- * the suggestions rather than throwing, so the field stays usable.
19
- *
20
- * @example
21
- * const { suggestions, loading } = useAddressAutocomplete(text);
22
- */
23
- export function useAddressAutocomplete(query: string): {
24
- suggestions: AddressSuggestion[];
25
- loading: boolean;
26
- /** Preview notice for the address field to display. */
27
- error: string | null;
28
- } {
29
- const { vendor } = useStorefront();
30
- const isThemePreview = useIsThemePreview();
31
- const t = useThemeStrings();
32
- const [suggestions, setSuggestions] = useState<AddressSuggestion[]>([]);
33
- const [loading, setLoading] = useState(false);
34
-
35
- useEffect(() => {
36
- if (isThemePreview) {
37
- setSuggestions([]);
38
- setLoading(false);
39
- return;
40
- }
41
- if (!query || query.trim().length < 2) {
42
- setSuggestions([]);
43
- return;
44
- }
45
-
46
- let cancelled = false;
47
- const timer = setTimeout(() => {
48
- setLoading(true);
49
- const client = getQueekClient(vendor.slug ?? undefined);
50
- const path = `/client/address/autocomplete?query=${encodeURIComponent(query.trim())}`;
51
-
52
- client
53
- .get<AddressSuggestion[] | { data: AddressSuggestion[] }>(path)
54
- .then((res) => {
55
- if (cancelled) return;
56
- // Backend returns a bare array (not wrapped in envelope). SDK returns
57
- // whatever the server sent — handle both shapes defensively.
58
- const list: unknown = Array.isArray(res)
59
- ? res
60
- : Array.isArray((res as { data?: unknown })?.data)
61
- ? (res as { data: AddressSuggestion[] }).data
62
- : [];
63
- setSuggestions(list as AddressSuggestion[]);
64
- })
65
- .catch(() => {
66
- if (!cancelled) setSuggestions([]);
67
- })
68
- .finally(() => {
69
- if (!cancelled) setLoading(false);
70
- });
71
- }, DEBOUNCE_MS);
72
-
73
- return () => {
74
- cancelled = true;
75
- clearTimeout(timer);
76
- };
77
- }, [query, vendor.slug, isThemePreview]);
78
-
79
- return { suggestions, loading, error: isThemePreview ? t('preview.address') : null };
80
- }
@@ -1,62 +0,0 @@
1
- 'use client';
2
-
3
- import { useState } from 'react';
4
- import { useIsThemePreview, useStorefront, useThemeStrings } from '../provider';
5
- import { getQueekClient } from '../sdk/queek-client';
6
- import { useLocationStore } from '../stores/location-store';
7
-
8
- interface CoordinatesResponse {
9
- lat?: number;
10
- lng?: number;
11
- latitude?: number;
12
- longitude?: number;
13
- formatted_address?: string;
14
- state_id?: string | null;
15
- }
16
-
17
- /**
18
- * Turns a chosen address suggestion into coordinates and saves it as the
19
- * shopper's delivery location. `resolve` returns true when a location was
20
- * saved and false when the API gave no usable position or the request failed.
21
- *
22
- * @example
23
- * const { resolve, resolving } = useResolveCoordinates();
24
- * const ok = await resolve(suggestion.place_id, suggestion.description);
25
- */
26
- export function useResolveCoordinates(): {
27
- resolve: (placeId: string, description: string) => Promise<boolean>;
28
- resolving: boolean;
29
- /** Preview notice for the address field to display. */
30
- error: string | null;
31
- } {
32
- const { vendor } = useStorefront();
33
- const isThemePreview = useIsThemePreview();
34
- const t = useThemeStrings();
35
- const setLocation = useLocationStore((s) => s.setLocation);
36
- const [resolving, setResolving] = useState(false);
37
-
38
- const resolve = async (placeId: string, description: string): Promise<boolean> => {
39
- if (isThemePreview) return false;
40
- setResolving(true);
41
- try {
42
- const client = getQueekClient(vendor.slug ?? undefined);
43
- const res = await client.post<CoordinatesResponse>('/client/geo/resolve', {
44
- place_id: placeId,
45
- });
46
- const data = (res?.data ?? {}) as CoordinatesResponse;
47
- const lat = data.lat ?? data.latitude;
48
- const lng = data.lng ?? data.longitude;
49
- if (typeof lat === 'number' && typeof lng === 'number') {
50
- setLocation(lat, lng, data.formatted_address ?? description, data.state_id ?? null);
51
- return true;
52
- }
53
- return false;
54
- } catch {
55
- return false;
56
- } finally {
57
- setResolving(false);
58
- }
59
- };
60
-
61
- return { resolve, resolving, error: isThemePreview ? t('preview.address') : null };
62
- }