@keystone-sites/marketing-design-system 1.0.7 → 1.0.8

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/lib/grader.ts CHANGED
@@ -68,12 +68,9 @@ export interface GraderSuggestion {
68
68
  website?: string | null;
69
69
  }
70
70
 
71
- export interface GraderSearchResponse {
72
- places: GraderSuggestion[];
73
- web: GraderSuggestion[];
74
- }
75
-
76
- const EMPTY_GRADER_SEARCH: GraderSearchResponse = { places: [], web: [] };
71
+ /** The two suggestion sources, each its own request so the fast one is
72
+ * never held back by the slow one. */
73
+ export type GraderSearchGroup = "places" | "web";
77
74
 
78
75
  function isSuggestion(value: unknown): value is GraderSuggestion {
79
76
  if (!value || typeof value !== "object") return false;
@@ -81,16 +78,9 @@ function isSuggestion(value: unknown): value is GraderSuggestion {
81
78
  return typeof r.id === "string" && typeof r.name === "string" && typeof r.address === "string";
82
79
  }
83
80
 
84
- /** Drop malformed entries from the grouped API response. */
85
- function normalizeGraderSearchResponse(body: unknown): GraderSearchResponse {
86
- if (body && typeof body === "object") {
87
- const r = body as Record<string, unknown>;
88
- return {
89
- places: Array.isArray(r.places) ? r.places.filter(isSuggestion) : [],
90
- web: Array.isArray(r.web) ? r.web.filter(isSuggestion) : [],
91
- };
92
- }
93
- return EMPTY_GRADER_SEARCH;
81
+ /** Drop malformed entries from the API's list. */
82
+ function normalizeSuggestions(body: unknown): GraderSuggestion[] {
83
+ return Array.isArray(body) ? body.filter(isSuggestion) : [];
94
84
  }
95
85
 
96
86
  /** The Grader deep link for a chosen business. The hub keys on `placeId`;
@@ -103,29 +93,31 @@ export function graderScanUrl(business: GraderSuggestion): string {
103
93
  return `${GRADER_URL}/?${params.toString()}`;
104
94
  }
105
95
 
106
- function graderSearchApiUrl(query: string, path: string): string {
107
- return `${GRADER_API_BASE_URL}${path}?q=${encodeURIComponent(query)}`;
96
+ function graderSearchApiUrl(group: GraderSearchGroup, query: string, path: string): string {
97
+ return `${GRADER_API_BASE_URL}${path}/${group}?q=${encodeURIComponent(query)}`;
108
98
  }
109
99
 
110
- /** Query the search endpoint, walking the configured paths until one
111
- * answers; a non-OK response or a network error moves to the next path,
112
- * exhausting them yields the empty response. An aborted signal stops
113
- * the walk immediately (re-thrown so the caller can ignore stale runs). */
114
- export async function fetchGraderSuggestions(
100
+ /** Query one group of the search endpoint, walking the configured paths
101
+ * until one answers; a non-OK response or a network error moves to the
102
+ * next path, exhausting them yields no suggestions. An aborted signal
103
+ * stops the walk immediately (re-thrown so the caller can ignore stale
104
+ * runs). */
105
+ export async function fetchGraderGroup(
106
+ group: GraderSearchGroup,
115
107
  query: string,
116
108
  signal?: AbortSignal,
117
- ): Promise<GraderSearchResponse> {
109
+ ): Promise<GraderSuggestion[]> {
118
110
  for (const path of GRADER_SEARCH_PATHS) {
119
111
  try {
120
112
  const timeout = AbortSignal.timeout(GRADER_SEARCH_TIMEOUT_MS);
121
113
  const combined = signal ? AbortSignal.any([signal, timeout]) : timeout;
122
- const resp = await fetch(graderSearchApiUrl(query, path), { signal: combined });
114
+ const resp = await fetch(graderSearchApiUrl(group, query, path), { signal: combined });
123
115
  if (!resp.ok) continue;
124
- return normalizeGraderSearchResponse(await resp.json());
116
+ return normalizeSuggestions(await resp.json());
125
117
  } catch (error) {
126
118
  if (signal?.aborted) throw error;
127
119
  // timeout or network failure — try the next configured path
128
120
  }
129
121
  }
130
- return EMPTY_GRADER_SEARCH;
122
+ return [];
131
123
  }
@@ -1,16 +1,18 @@
1
1
  "use client";
2
2
 
3
- /** Grader typeahead state. Debouncing, cancellation, grouped limits, and
4
- * a small cache prevent stale results and backspace flicker. */
3
+ /** Grader typeahead state. Each group is its own request so Google's
4
+ * ~100ms matches show while the web search is still out; debouncing,
5
+ * cancellation, grouped limits, and a small cache prevent stale results
6
+ * and backspace flicker. */
5
7
 
6
8
  import { useEffect, useMemo, useState } from "react";
7
- import { fetchGraderSuggestions, type GraderSearchResponse, type GraderSuggestion } from "./grader";
9
+ import { fetchGraderGroup, type GraderSearchGroup, type GraderSuggestion } from "./grader";
8
10
 
9
11
  /** Keystroke settle time before a request goes out. */
10
12
  const DEBOUNCE_MS = 200;
11
13
  /** Rows offered per group. */
12
- const MAX_PLACES = 5;
13
- const MAX_WEB = 3;
14
+ const MAX: Record<GraderSearchGroup, number> = { places: 5, web: 3 };
15
+ const GROUPS: GraderSearchGroup[] = ["places", "web"];
14
16
  /** Answers remembered per session (queries are short; this is tiny). */
15
17
  const CACHE_SIZE = 50;
16
18
 
@@ -34,13 +36,15 @@ export interface GraderSearchState {
34
36
  resultsFor: string;
35
37
  }
36
38
 
39
+ /** What has answered so far for one query; a group is absent until it does. */
37
40
  interface Answer {
38
- groups: GraderSearchGroups;
39
41
  resultsFor: string;
42
+ places?: GraderSuggestion[];
43
+ web?: GraderSuggestion[];
40
44
  }
41
45
 
42
46
  const EMPTY_GROUPS: GraderSearchGroups = { places: [], web: [] };
43
- const EMPTY_ANSWER: Answer = { groups: EMPTY_GROUPS, resultsFor: "" };
47
+ const EMPTY_ANSWER: Answer = { resultsFor: "" };
44
48
 
45
49
  function capped(items: GraderSuggestion[], max: number, seen: Set<string>): GraderSuggestion[] {
46
50
  const out: GraderSuggestion[] = [];
@@ -53,14 +57,18 @@ function capped(items: GraderSuggestion[], max: number, seen: Set<string>): Grad
53
57
  return out;
54
58
  }
55
59
 
56
- function group(response: GraderSearchResponse): GraderSearchGroups {
60
+ function group(answer: Answer): GraderSearchGroups {
57
61
  const seen = new Set<string>();
58
62
  return {
59
- places: capped(response.places, MAX_PLACES, seen),
60
- web: capped(response.web, MAX_WEB, seen),
63
+ places: capped(answer.places ?? [], MAX.places, seen),
64
+ web: capped(answer.web ?? [], MAX.web, seen),
61
65
  };
62
66
  }
63
67
 
68
+ function complete(answer: Answer): boolean {
69
+ return GROUPS.every((g) => answer[g] !== undefined);
70
+ }
71
+
64
72
  const cache = new Map<string, GraderSearchGroups>();
65
73
 
66
74
  function remember(query: string, groups: GraderSearchGroups) {
@@ -89,17 +97,18 @@ export function useGraderSearch(query: string, enabled = true): GraderSearchStat
89
97
  if (!q || cache.has(q)) return;
90
98
  const controller = new AbortController();
91
99
  const timer = window.setTimeout(() => {
92
- fetchGraderSuggestions(q, controller.signal)
93
- .then((response) => {
94
- if (controller.signal.aborted) return;
95
- const groups = group(response);
96
- remember(q, groups);
97
- setAnswer({ groups, resultsFor: q });
98
- })
99
- .catch(() => {
100
- if (controller.signal.aborted) return;
101
- setAnswer({ groups: EMPTY_GROUPS, resultsFor: q });
102
- });
100
+ for (const g of GROUPS) {
101
+ fetchGraderGroup(g, q, controller.signal)
102
+ .catch((): GraderSuggestion[] => [])
103
+ .then((items) => {
104
+ if (controller.signal.aborted) return;
105
+ setAnswer((prev) => ({
106
+ ...(prev.resultsFor === q ? prev : {}),
107
+ resultsFor: q,
108
+ [g]: items,
109
+ }));
110
+ });
111
+ }
103
112
  }, DEBOUNCE_MS);
104
113
  return () => {
105
114
  window.clearTimeout(timer);
@@ -107,12 +116,22 @@ export function useGraderSearch(query: string, enabled = true): GraderSearchStat
107
116
  };
108
117
  }, [q]);
109
118
 
119
+ useEffect(() => {
120
+ if (answer.resultsFor && complete(answer)) remember(answer.resultsFor, group(answer));
121
+ }, [answer]);
122
+
110
123
  return useMemo<GraderSearchState>(() => {
111
124
  if (!q) return state("idle", EMPTY_GROUPS, "");
112
125
  // A remembered query answers in the same render — no fetch, no flicker.
113
126
  const cached = cache.get(q);
114
127
  if (cached) return state("ready", cached, q);
115
- if (answer.resultsFor === q) return state("ready", answer.groups, q);
128
+ if (answer.resultsFor === q) {
129
+ const groups = group(answer);
130
+ // Ready as soon as there is something to show, or nothing left to wait for.
131
+ if (answer.places !== undefined && (groups.places.length > 0 || complete(answer))) {
132
+ return state("ready", groups, q);
133
+ }
134
+ }
116
135
  return state("loading", EMPTY_GROUPS, "");
117
136
  }, [q, answer]);
118
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keystone-sites/marketing-design-system",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Keystone's marketing design system: tokens, the tick grid, type, primitives, site chrome, and the landing kit. Source-shipped CSS and TSX for Next.js consumers.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
package/sections/nav.css CHANGED
@@ -92,7 +92,7 @@
92
92
  display: block;
93
93
  width: var(--knav-logomark);
94
94
  height: var(--knav-logomark);
95
- background: var(--color-text-200);
95
+ background: var(--knav-mark-ink);
96
96
  -webkit-mask: url("/media/brand/ks-logomark.svg") center / contain no-repeat;
97
97
  mask: url("/media/brand/ks-logomark.svg") center / contain no-repeat;
98
98
  }
package/site-links.ts CHANGED
@@ -31,7 +31,7 @@ export const SITE_LINKS = {
31
31
  terms: "/terms",
32
32
  privacy: "/privacy",
33
33
  accessibility: "/accessibility",
34
- login: "https://console.localkeystone.com/login",
34
+ login: "https://go.keystone.app/login",
35
35
  spotify: "https://open.spotify.com/show/41MuXEI3TIvCAQW20Ko9cX",
36
36
  applePodcasts: "https://podcasts.apple.com/us/podcast/made-locally/id1895736090",
37
37
  } as const;
@@ -138,6 +138,8 @@
138
138
  --z-sticky: 20;
139
139
  --knav-bar-h: 44px;
140
140
  --knav-logomark: 18px;
141
+ /* The mark's ink; a product app sets it to its own brand color. */
142
+ --knav-mark-ink: var(--color-text-200);
141
143
  --hx-wm-w: 3.9563em;
142
144
  --hx-wm-h: 0.8031em;
143
145
  --hx-wm-drop: 0.19045;