@cloudgrid-io/ui 0.69.0 → 0.70.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.
Files changed (75) hide show
  1. package/dist/badge/marks.d.ts +2 -0
  2. package/dist/badge/marks.d.ts.map +1 -1
  3. package/dist/badge/marks.js +5 -0
  4. package/dist/badge/marks.js.map +1 -1
  5. package/dist/badge/watermark.js +2 -2
  6. package/dist/badge/watermark.js.map +1 -1
  7. package/dist/blocks/browse-categories.d.ts +80 -0
  8. package/dist/blocks/browse-categories.d.ts.map +1 -0
  9. package/dist/blocks/browse-categories.js +106 -0
  10. package/dist/blocks/browse-categories.js.map +1 -0
  11. package/dist/blocks/creation-search.d.ts +145 -102
  12. package/dist/blocks/creation-search.d.ts.map +1 -1
  13. package/dist/blocks/creation-search.js +502 -125
  14. package/dist/blocks/creation-search.js.map +1 -1
  15. package/dist/blocks/feed-row.d.ts +92 -0
  16. package/dist/blocks/feed-row.d.ts.map +1 -0
  17. package/dist/blocks/feed-row.js +30 -0
  18. package/dist/blocks/feed-row.js.map +1 -0
  19. package/dist/blocks/filter-tabs.d.ts +12 -1
  20. package/dist/blocks/filter-tabs.d.ts.map +1 -1
  21. package/dist/blocks/filter-tabs.js +11 -2
  22. package/dist/blocks/filter-tabs.js.map +1 -1
  23. package/dist/blocks/greeting.d.ts +42 -0
  24. package/dist/blocks/greeting.d.ts.map +1 -0
  25. package/dist/blocks/greeting.js +38 -0
  26. package/dist/blocks/greeting.js.map +1 -0
  27. package/dist/blocks/home-bento.d.ts +11 -4
  28. package/dist/blocks/home-bento.d.ts.map +1 -1
  29. package/dist/blocks/home-bento.js +22 -6
  30. package/dist/blocks/home-bento.js.map +1 -1
  31. package/dist/blocks/home-pinned.d.ts +81 -3
  32. package/dist/blocks/home-pinned.d.ts.map +1 -1
  33. package/dist/blocks/home-pinned.js +195 -9
  34. package/dist/blocks/home-pinned.js.map +1 -1
  35. package/dist/blocks/icons.d.ts +54 -6
  36. package/dist/blocks/icons.d.ts.map +1 -1
  37. package/dist/blocks/icons.js +67 -6
  38. package/dist/blocks/icons.js.map +1 -1
  39. package/dist/blocks/impact-card.d.ts +105 -0
  40. package/dist/blocks/impact-card.d.ts.map +1 -0
  41. package/dist/blocks/impact-card.js +57 -0
  42. package/dist/blocks/impact-card.js.map +1 -0
  43. package/dist/blocks/inspiration-cards.d.ts +227 -5
  44. package/dist/blocks/inspiration-cards.d.ts.map +1 -1
  45. package/dist/blocks/inspiration-cards.js +286 -8
  46. package/dist/blocks/inspiration-cards.js.map +1 -1
  47. package/dist/blocks/jump-back-in.d.ts +249 -0
  48. package/dist/blocks/jump-back-in.d.ts.map +1 -0
  49. package/dist/blocks/jump-back-in.js +272 -0
  50. package/dist/blocks/jump-back-in.js.map +1 -0
  51. package/dist/blocks/load-more-grid.d.ts +125 -0
  52. package/dist/blocks/load-more-grid.d.ts.map +1 -0
  53. package/dist/blocks/load-more-grid.js +157 -0
  54. package/dist/blocks/load-more-grid.js.map +1 -0
  55. package/dist/blocks/menu-trigger.d.ts +7 -2
  56. package/dist/blocks/menu-trigger.d.ts.map +1 -1
  57. package/dist/blocks/menu-trigger.js +2 -0
  58. package/dist/blocks/menu-trigger.js.map +1 -1
  59. package/dist/blocks/phosphor-marks.d.ts +17 -1
  60. package/dist/blocks/phosphor-marks.d.ts.map +1 -1
  61. package/dist/blocks/phosphor-marks.js +25 -1
  62. package/dist/blocks/phosphor-marks.js.map +1 -1
  63. package/dist/blocks/start-card.d.ts +76 -0
  64. package/dist/blocks/start-card.d.ts.map +1 -0
  65. package/dist/blocks/start-card.js +82 -0
  66. package/dist/blocks/start-card.js.map +1 -0
  67. package/dist/index.d.ts +7 -0
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +7 -0
  70. package/dist/index.js.map +1 -1
  71. package/dist/lib/motion.d.ts +14 -0
  72. package/dist/lib/motion.d.ts.map +1 -1
  73. package/dist/lib/motion.js +4 -0
  74. package/dist/lib/motion.js.map +1 -1
  75. package/package.json +1 -1
@@ -4,112 +4,304 @@ import * as React from "react";
4
4
  import { cn } from "../lib/cloudgrid-cn.js";
5
5
  import { Button } from "../ui/button.js";
6
6
  import { DASHED_LINE_CLASS } from "./dashed-line.js";
7
- import { Dialog, DialogClose, DialogContent, DialogTitle } from "../ui/dialog.js";
8
7
  import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from "../ui/dropdown-menu.js";
9
8
  import { EMPTY_CREATIONS_PREVIEWS } from "./empty-creations-previews.js";
10
9
  import { ENTITY_KIND_ICON, ENTITY_KIND_LABEL } from "./entity-card.js";
11
- import { CloseIcon, MoreActionsIcon, OpenLiveIcon, PinIcon, PlusIcon, SaveFilledIcon, SearchIcon, } from "./icons.js";
12
- import { Input } from "../ui/input.js";
13
- import { Separator } from "../ui/separator.js";
10
+ import { MoreActionsIcon, OpenLiveIcon, PinIcon, PlusIcon, SaveFilledIcon, SearchIcon } from "./icons.js";
11
+ import { Kbd } from "../ui/kbd.js";
14
12
  import { THUMBNAIL_WITH_IDENTITY, ThumbnailIdentity } from "../lib/thumbnail-identity.js";
15
13
  /**
16
- * THE CREATION SEARCH WINDOW FOR HOME (ui#531, Asaf's design, 2026-11-20).
17
- *
18
- * Opened from the search button beside the Space menu on Home: a centred
19
- * dialog over the page's scrim, the library's modal `Dialog`. It fetches
20
- * nothing. The caller owns the query, the rows and which of the four states
21
- * shows, and hears every action through a handler.
22
- *
23
- * ```
24
- * .------------------------------------------------- 680 ---.
25
- * | [ (o) Search creations ] [x] | 20 top, field 48
26
- * | ------------------------------------------------------ | hairline
27
- * | Recently opened (or "N creations") | SemiBold 14, steel-strong
28
- * | [thumb 96x56] demo-shop [type] | rows 80, 3 tall (240),
29
- * | You · Everyone | the list scrolls past 3
30
- * | ------------------------------------------------------ |
31
- * | Search creations across your Grid | 13, steel-strong
32
- * '----------------------------------------------------------' 24 bottom; 28 aside
33
- * ```
34
- *
35
- * ## The four states (`state`)
36
- *
37
- * recent "Recently opened" over `rows`; the footer invites a search
38
- * results "N creations" over `rows`; the footer says the keys
39
- * no-match the stacked-rows drawing, "No matching creations" and a hint
40
- * empty-grid the creations strip with its dashed + tile, two lines and
41
- * "Add a creation +" (`onAddCreation`)
42
- *
43
- * The no-match and empty-grid bodies are 316 tall with no footer, as drawn.
44
- *
45
- * ## The row, hover and the active row
46
- *
47
- * Thumbnail, name (SemiBold 17), "Owner · Space" (14) and the type icon on
48
- * its tint at the right. The pointer over a row, or the arrow keys, make it
49
- * the ACTIVE row: one at a time, and it is the row Enter opens. The active
50
- * row takes the light cyan highlight; the type icon glides left as the
51
- * actions (open live, pin, "...") ease in beside it; the gaps close from 16
52
- * to 12, as the hovered row is drawn. One short transition (the library's
53
- * `--cg-duration`, 180ms, ease-out) and none under reduced motion.
54
- *
55
- * A click anywhere on the row except its actions calls `onOpen(row)`: the
56
- * row's open control is one button whose hit area covers the row. The arrow
57
- * calls `onOpenLive(row)` (the live creation in a new tab), the pin
58
- * `onTogglePin(row)` (`aria-pressed` from `row.pinned`), and "..." opens a
59
- * menu of `renderMenu(row)`'s items, the same items the creation card's menu
60
- * has. A row's actions are `inert` until it is active, so only that row's
61
- * are in the tab order; a row whose actions hold focus stays shown when the
62
- * pointer moves on.
63
- *
64
- * ## A phone
65
- *
66
- * The design draws the desktop only. Under 30rem of card (a container query,
67
- * so a phone's 343) the thumbnail is 64 wide, and the active row's type icon
68
- * folds away while its actions show, so the name keeps room beside them. The
69
- * empty grid's strip drops its outer pair under 360 of room.
14
+ * THE FRONT PAGES' SEARCH (ui#590, Asaf's design, 2026-11-25): a framed bar
15
+ * with a soft purple halo, and the results opening right under it in liquid
16
+ * glass. For the Grid page (console#1183) and the Console page (console#1184).
17
+ * It replaces #531's round button and its dialog over a scrim, and this
18
+ * issue's first, floating version.
70
19
  *
71
- * ## Keys
20
+ * It fetches nothing. The caller owns the query, the rows and which state
21
+ * shows, and hears every action through a handler, as #531's window did.
22
+ *
23
+ * ## The bar
24
+ *
25
+ * Rendered where the caller puts it (`className` sizes it): on the Grid page
26
+ * under the greeting with the Space menu on its left, on the Console page
27
+ * under the title between the Space menu and "New creation". 56 high, white,
28
+ * corner radius 16, and the HALO: a thin brand-purple edge and a soft purple
29
+ * glow around it, so it reads as the centre of the page. The search mark, the
30
+ * page's placeholder ("Search creations" / "Search your creations"), and the
31
+ * shortcut hint at the right while it is empty: ⌘K on a Mac, Ctrl K
32
+ * elsewhere, none on a phone or a tablet.
33
+ *
34
+ * The cursor is the brand purple with a soft purple glow, one colour, and
35
+ * blinks; under reduced motion it holds still. A click focuses the bar with no
36
+ * frame; the library's `focus-line` from the keyboard only. ⌘K or Ctrl K
37
+ * focuses it from anywhere on the page, except from inside another field (an
38
+ * input, a textarea or something editable), which keeps the keys.
39
+ *
40
+ * ## The results: right under the bar
41
+ *
42
+ * The first character typed opens them DIRECTLY UNDER THE BAR, the bar's own
43
+ * width, 10 below it. No popup, no dialog, no dimming, nothing moves: the
44
+ * page stays where it is and the results sit over the content below (the bar
45
+ * lifts itself over its later siblings while they show). The panel grows
46
+ * with the results up to the room the screen has, above a phone's keyboard
47
+ * too (the visual viewport).
48
+ *
49
+ * results "N creations", the rows, and "Arrow keys to move ·
50
+ * Enter to open · Esc to close" (hidden on a touch screen, by
51
+ * the rule that hides the ⌘K hint there)
52
+ * no-match #531's drawing, "No matching creations" and its hint
53
+ * empty-grid #531's strip, its two lines and "Add a creation +"
72
54
  *
73
- * Focus starts in the field. Down and up move the active row and wrap at the
74
- * ends; Enter opens the active row, or the first when none is active yet;
75
- * Escape closes, through the Dialog. The field is a `combobox` whose popup is
76
- * the `grid` of rows; `aria-activedescendant` names the active row's open
77
- * cell, so a screen reader follows the arrows while focus stays in the field.
55
+ * `recent` (nothing typed) shows nothing under the bar.
78
56
  *
79
- * ## Surfaces
57
+ * On a phone (under 640 wide) the bar shares its row with the compact Space
58
+ * menu on its left, and the results span that whole row: pass the row as
59
+ * `row` (a ref to the element holding the menu and the bar) and the results
60
+ * run from the row's left edge to the bar's right, with the same gap, radius,
61
+ * glass and shadow. From 640 up they keep the bar's width, so the Console can
62
+ * pass `row` at every width:
80
63
  *
81
- * An overlay: it portals to the body, out of any `data-cg-surface` scope, and
82
- * draws the same white card over a page on the card, the panel or ink. The
83
- * cyan highlight, the type tint and the steel lines are `:root` tokens.
64
+ * const rowRef = React.useRef<HTMLDivElement>(null)
65
+ * <div ref={rowRef} className="flex items-center gap-3">
66
+ * <SpaceMenu /> // MenuTrigger variant="bar", compact under 640
67
+ * <CreationSearch row={rowRef} className="min-w-0 flex-1" ... />
68
+ * </div>
84
69
  *
85
- * ## Tokens, and where the design has none
70
+ * Esc, a click outside, or clearing the text closes them; the text stays in
71
+ * the bar until it is cleared. Typing again, a click on the bar or Down opens
72
+ * them again.
86
73
  *
87
- * field hairline line, radius 10 (`rounded-sm`), 48 tall, 17 text
88
- * card radius 20 (`rounded-container`), `shadow-float`
89
- * highlight `--cg-cyan-200` at half, which is the drawn #effdfd on white
90
- * type tint the app tint is `--cg-primary-20` as drawn
91
- * 23px titles no 23 rung: `text-heading-lg`, 22
92
- * add button the library's default Button (40, radius 16, Bold 15), not
93
- * the drawn 42 / radius 8 / SemiBold
74
+ * ## The glass: liquid, readable first
75
+ *
76
+ * frost the page behind, blurred 28px and saturated, under a white fill at
77
+ * 86% with a faint purple-to-cyan tint: what keeps every line at
78
+ * 4.5:1 or more over a black page (the unit test works it out; the
79
+ * browser test measures it over dark pictures)
80
+ * light a bright rim along the top edge, soft diagonal light bands, and a
81
+ * wide, soft shadow. Opaque white where transparency is turned down.
82
+ *
83
+ * ## A row
84
+ *
85
+ * The picture (its top), the name, and "By you · 2 days ago" or "Dana · 5 days
86
+ * ago". The pointer or the arrow keys make a row ACTIVE (one at a time, and
87
+ * the one Enter opens): a light lavender highlight, and its actions open
88
+ * beside the type: Pin (Unpin when pinned), Live, and the caller's "..." when
89
+ * it passes `renderMenu`. A click anywhere else on the row opens the creation.
90
+ * A row's actions are `inert` until it is active.
91
+ *
92
+ * ## Keys
93
+ *
94
+ * The bar is a `combobox` whose popup is the `grid` of rows, with
95
+ * `aria-activedescendant` on the active row. Down and Up move the active row
96
+ * and wrap; Enter opens the active row, or the first; Escape closes.
94
97
  */
95
- /** Every line the window writes, as the design writes it. */
98
+ /** Every line the search writes, as the design writes it. */
96
99
  export const CREATION_SEARCH_COPY = {
97
100
  placeholder: "Search creations",
98
- close: "Close search",
99
- recentHeading: "Recently opened",
100
- recentFooter: "Search creations across your Grid",
101
- resultsFooter: "Arrow keys to navigate · Enter to open · Esc to close",
101
+ resultsFooter: "Arrow keys to move · Enter to open · Esc to close",
102
+ byYou: "By you",
103
+ pin: "Pin",
104
+ unpin: "Unpin",
105
+ live: "Live",
102
106
  noMatchTitle: "No matching creations",
103
107
  noMatchLine: "Try another name or a shorter search.",
104
108
  emptyTitle: "Your Grid starts with a creation.",
105
109
  emptyLine: "Once you add creations, you can find them here.",
106
110
  addCreation: "Add a creation",
107
111
  };
112
+ /** The glass. Percentages. */
113
+ export const CREATION_SEARCH_GLASS = {
114
+ /** The white fill over the blurred page: the frost that keeps the text readable. */
115
+ frost: 86,
116
+ /** The purple (start) and cyan (end) tint mixed into that fill. */
117
+ tint: 6,
118
+ /** The blur behind the frost, px. */
119
+ blur: 28,
120
+ /** The saturation behind it. */
121
+ saturate: 1.6,
122
+ };
108
123
  /** The line above the results: "2 creations", "1 creation". */
109
124
  export function creationCountLabel(count) {
110
125
  return `${count} ${count === 1 ? "creation" : "creations"}`;
111
126
  }
112
- /** The kind's tint behind the type icon. The app tint is the drawn --cg-primary-20. */
127
+ /**
128
+ * The shortcut hint: ⌘K on a Mac, Ctrl K on Windows and Linux, none on a
129
+ * phone or a tablet (no hover and a coarse pointer), where there is no key to
130
+ * press. An iPad names itself a Mac, so touch is asked first.
131
+ */
132
+ export function creationSearchShortcut(env) {
133
+ if (env.touch)
134
+ return null;
135
+ return /mac|iphone|ipad|ipod/i.test(env.platform) ? "⌘K" : "Ctrl K";
136
+ }
137
+ /**
138
+ * The row's second line: "By you" or the owner, then when. A row without
139
+ * `when` keeps the Space it was given (#531's rows), so a caller that has no
140
+ * date yet still says something.
141
+ */
142
+ export function creationRowDetail(row) {
143
+ const who = row.owner === "You" ? CREATION_SEARCH_COPY.byYou : row.owner;
144
+ const second = row.when ?? row.space;
145
+ return second ? `${who} · ${second}` : who;
146
+ }
147
+ /* -------------------------------------------------------------------------- */
148
+ /* The environment */
149
+ /* -------------------------------------------------------------------------- */
150
+ const TOUCH = "(hover: none) and (pointer: coarse)";
151
+ const matches = (query) => typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia(query).matches;
152
+ function subscribeTouch(onChange) {
153
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function")
154
+ return () => { };
155
+ const list = window.matchMedia(TOUCH);
156
+ list.addEventListener("change", onChange);
157
+ return () => list.removeEventListener("change", onChange);
158
+ }
159
+ function platformName() {
160
+ const nav = navigator;
161
+ return nav.userAgentData?.platform || nav.platform || "";
162
+ }
163
+ /** The hint the browser asks for; none on the server, until it says. */
164
+ function useShortcutHint() {
165
+ return React.useSyncExternalStore(subscribeTouch, () => creationSearchShortcut({ platform: platformName(), touch: matches(TOUCH) }), () => null);
166
+ }
167
+ /* -------------------------------------------------------------------------- */
168
+ /* The halo and the glass */
169
+ /* -------------------------------------------------------------------------- */
170
+ const G = CREATION_SEARCH_GLASS;
171
+ const white = (alpha) => `color-mix(in srgb, var(--cg-neutral-0) ${alpha}%, transparent)`;
172
+ const tinted = (token, tint, alpha) => `color-mix(in srgb, color-mix(in srgb, var(${token}) ${tint}%, var(--cg-neutral-0)) ${alpha}%, transparent)`;
173
+ const ink = (alpha) => `color-mix(in srgb, var(--cg-ink) ${alpha}%, transparent)`;
174
+ const brand = (alpha) => `color-mix(in srgb, var(--cg-primary) ${alpha}%, transparent)`;
175
+ /** The halo: a thin brand-purple edge, a faint purple ring hugging it, and a soft purple glow, lower than it is wide. */
176
+ const HALO_EDGE = brand(55);
177
+ const HALO = `0 0 0 6px ${brand(9)}, 0 10px 28px -8px ${brand(34)}`;
178
+ /** The frost's fill: purple at the start, white, cyan at the end. */
179
+ const FROST_FILL = `linear-gradient(100deg, ${tinted("--cg-primary", G.tint, G.frost)} 0%, ${white(G.frost)} 45%, ${tinted("--cg-tertiary", G.tint, G.frost)} 100%)`;
180
+ /** The light: soft diagonal bands across. */
181
+ const BANDS = `linear-gradient(112deg, transparent 18%, ${white(55)} 30%, transparent 44%, transparent 62%, ${white(30)} 70%, transparent 80%)`;
182
+ /** The bright rim along the top, a thin line all round. */
183
+ const RIM = `inset 0 1px 0 ${white(95)}`;
184
+ /** Wide, soft and low. */
185
+ const SHADOW = `0 1px 3px ${ink(6)}, 0 28px 56px -20px ${ink(32)}, 0 16px 44px -24px ${brand(28)}`;
186
+ /**
187
+ * What a utility class cannot carry cleanly: the halo, the frost and its
188
+ * light, the cursor's glow and blink. A React 19 hoistable stylesheet, once
189
+ * however many searches render, in `@layer components`.
190
+ */
191
+ const STYLES = `
192
+ @layer theme, base, components, utilities;
193
+ @layer components {
194
+ [data-slot="creation-search-bar"] {
195
+ border: 1px solid ${HALO_EDGE};
196
+ box-shadow: ${HALO};
197
+ }
198
+ [data-slot="creation-search-panel"] {
199
+ background-image: ${BANDS}, ${FROST_FILL};
200
+ box-shadow: ${RIM}, ${SHADOW};
201
+ border: 1px solid ${white(70)};
202
+ -webkit-backdrop-filter: blur(${G.blur}px) saturate(${G.saturate});
203
+ backdrop-filter: blur(${G.blur}px) saturate(${G.saturate});
204
+ animation: cg-creation-search-in var(--cg-duration-fast) ease-out;
205
+ }
206
+ @media (prefers-reduced-transparency: reduce) {
207
+ [data-slot="creation-search-panel"] {
208
+ background-image: none;
209
+ background-color: var(--cg-neutral-0);
210
+ -webkit-backdrop-filter: none;
211
+ backdrop-filter: none;
212
+ }
213
+ }
214
+ @keyframes cg-creation-search-in {
215
+ from { opacity: 0; }
216
+ }
217
+ [data-slot="creation-search-caret"] {
218
+ background-color: var(--cg-primary);
219
+ box-shadow: 0 0 4px ${brand(70)}, 0 0 12px 2px ${brand(35)};
220
+ animation: cg-creation-search-blink 1.06s steps(1, end) infinite;
221
+ }
222
+ @keyframes cg-creation-search-blink {
223
+ 0%, 55% { opacity: 1; }
224
+ 56%, 100% { opacity: 0.15; }
225
+ }
226
+ @media (prefers-reduced-motion: reduce) {
227
+ [data-slot="creation-search-caret"] { animation: none; }
228
+ }
229
+ }
230
+ `;
231
+ /* -------------------------------------------------------------------------- */
232
+ /* The cursor */
233
+ /* -------------------------------------------------------------------------- */
234
+ let measureContext = null;
235
+ /** How far the placeholder stands in from where the text starts, px: `ps-13` to `placeholder-shown:ps-16`. */
236
+ const PLACEHOLDER_STEP = 12;
237
+ function textWidth(input, text) {
238
+ if (!text)
239
+ return 0;
240
+ measureContext ??= document.createElement("canvas").getContext("2d");
241
+ if (!measureContext)
242
+ return 0;
243
+ const s = getComputedStyle(input);
244
+ measureContext.font = s.font || `${s.fontStyle} ${s.fontWeight} ${s.fontSize} ${s.fontFamily}`;
245
+ return measureContext.measureText(text).width;
246
+ }
247
+ /**
248
+ * The purple cursor, drawn over the field's own (which is transparent), with
249
+ * a soft purple glow. It follows the caret, and steps aside for a selection,
250
+ * where the browser draws its own highlight.
251
+ */
252
+ function GlowCaret({ input, value }) {
253
+ const [at, setAt] = React.useState(null);
254
+ const place = React.useCallback(() => {
255
+ const el = input.current;
256
+ if (!el || document.activeElement !== el || el.selectionStart !== el.selectionEnd) {
257
+ setAt(null);
258
+ return;
259
+ }
260
+ const s = getComputedStyle(el);
261
+ const before = el.value.slice(0, el.selectionStart ?? el.value.length);
262
+ let x = el.offsetLeft +
263
+ parseFloat(s.borderLeftWidth || "0") +
264
+ parseFloat(s.paddingLeft || "0") +
265
+ textWidth(el, before) -
266
+ el.scrollLeft;
267
+ const height = Math.round(parseFloat(s.fontSize) * 1.15);
268
+ // Empty, the placeholder stands a step in (`placeholder-shown`) and the
269
+ // cursor stands before it, where the first letter will go.
270
+ if (el.value === "")
271
+ x -= PLACEHOLDER_STEP;
272
+ const at = Math.round(x * 10) / 10;
273
+ // A new cursor only when it moves: the blink restarts, so it is solid while typing.
274
+ setAt((prev) => (prev && prev.x === at && prev.height === height ? prev : { x: at, height, tick: (prev?.tick ?? 0) + 1 }));
275
+ }, [input]);
276
+ React.useLayoutEffect(() => {
277
+ place();
278
+ }, [place, value]);
279
+ React.useEffect(() => {
280
+ const el = input.current;
281
+ if (!el)
282
+ return;
283
+ const events = ["focus", "blur", "keyup", "pointerup", "scroll", "select"];
284
+ for (const e of events)
285
+ el.addEventListener(e, place);
286
+ document.addEventListener("selectionchange", place);
287
+ return () => {
288
+ for (const e of events)
289
+ el.removeEventListener(e, place);
290
+ document.removeEventListener("selectionchange", place);
291
+ };
292
+ }, [input, place]);
293
+ if (!at)
294
+ return null;
295
+ return (_jsx("span", { "aria-hidden": "true", "data-slot": "creation-search-caret", className: "pointer-events-none absolute top-1/2 w-0.5 -translate-y-1/2 rounded-pill", style: { left: at.x, height: at.height } }, at.tick));
296
+ }
297
+ /* -------------------------------------------------------------------------- */
298
+ /* The bar */
299
+ /* -------------------------------------------------------------------------- */
300
+ /** The bar's box: 56 high, white, radius 16. The halo is the stylesheet's. */
301
+ const BAR_BOX = "h-14 rounded-xl bg-card";
302
+ /* -------------------------------------------------------------------------- */
303
+ /* The rows */
304
+ /* -------------------------------------------------------------------------- */
113
305
  const TYPE_TINT = {
114
306
  app: "bg-brand-20",
115
307
  inspiration: "bg-kind-inspiration",
@@ -118,53 +310,60 @@ const TYPE_TINT = {
118
310
  /** One short motion for every moving part of a row. */
119
311
  const ROW_MOTION = "duration-(--cg-duration) ease-out motion-reduce:transition-none";
120
312
  /**
121
- * The actions cell's open width: 12 to the type icon, then 32 per action, 4
122
- * apart. Closed, it is 0 wide, so the type icon sits at the row's edge.
313
+ * The active row's highlight: the primary tint, opaque, so the page behind
314
+ * never shows through it and its details keep 4.5:1.
123
315
  */
124
- const ACTIONS_WIDTH = { 1: "w-11", 2: "w-20", 3: "w-29" };
316
+ const ACTIVE_ROW = "bg-[color-mix(in_oklab,var(--cg-primary-20)_65%,var(--cg-neutral-0))]";
125
317
  /**
126
- * The type icon. On a phone's narrow card the active row has no room for it
127
- * beside the actions, so there it folds away while they show, and the actions
128
- * take its place.
318
+ * The type badge: its tinted square, or on the active row, white with a thin
319
+ * edge like Pin and Live, since the tint all but matched the row's highlight
320
+ * there (Asaf's review, 2026-11-25).
129
321
  */
130
- function TypeIcon({ kind, folded }) {
322
+ function TypeIcon({ kind, active = false }) {
131
323
  const Icon = ENTITY_KIND_ICON[kind];
132
- return (_jsxs("span", { "data-slot": "creation-search-type", "data-kind": kind, className: cn("relative flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-xs text-stone transition-[width,opacity]", ROW_MOTION, TYPE_TINT[kind],
133
- // Under 30rem of card (a phone's), written out whole for Tailwind's scan.
134
- folded && "@max-[30rem]/creation-search:w-0 @max-[30rem]/creation-search:opacity-0"), children: [_jsx(Icon, { className: "size-5.5" }), _jsx("span", { className: "sr-only", children: ENTITY_KIND_LABEL[kind] })] }));
324
+ return (_jsxs("span", { "data-slot": "creation-search-type", "data-kind": kind, className: cn("flex size-7 shrink-0 items-center justify-center rounded-xs text-stone", active ? "bg-card shadow-mark" : TYPE_TINT[kind]), children: [_jsx(Icon, { className: "size-4.5" }), _jsx("span", { className: "sr-only", children: ENTITY_KIND_LABEL[kind] })] }));
135
325
  }
136
- /** The row's picture: 96 by 56 at radius 8; 64 by 38 on a phone's card. */
137
- const THUMBNAIL = "flex h-14 w-24 shrink-0 items-center justify-center overflow-hidden rounded-xs bg-page @max-[30rem]/creation-search:h-9.5 @max-[30rem]/creation-search:w-16";
326
+ /** The row's picture: 64 by 40 at radius 6. */
327
+ const THUMBNAIL = "flex h-10 w-16 shrink-0 items-center justify-center overflow-hidden rounded-2xs bg-page";
138
328
  function Thumbnail({ row }) {
139
329
  const [failed, setFailed] = React.useState(false);
330
+ // The rows render on the server now (nothing portals), so a picture can fail
331
+ // before the page hydrates, with no handler there to hear it: checked when it
332
+ // mounts, as `PictureOverIdentity` does.
333
+ const check = React.useCallback((img) => {
334
+ if (img && img.complete && img.naturalWidth === 0)
335
+ img.decode().catch(() => setFailed(true));
336
+ }, []);
140
337
  const Mark = ENTITY_KIND_ICON[row.kind];
141
338
  const seeded = row.seed !== undefined;
142
- return (_jsxs("span", { "data-slot": "creation-search-thumbnail", className: seeded ? `${THUMBNAIL} ${THUMBNAIL_WITH_IDENTITY}` : THUMBNAIL, children: [row.seed !== undefined ? _jsx(ThumbnailIdentity, { seed: row.seed, name: row.name, size: "thumb" }) : null, row.thumbnail && !failed ? (_jsx("img", { src: row.thumbnail, alt: "", decoding: "async", draggable: false, onError: () => setFailed(true), className: "size-full object-cover object-top" })) : seeded ? null : (_jsx(Mark, { className: "size-6 text-steel" }))] }));
339
+ return (_jsxs("span", { "data-slot": "creation-search-thumbnail", className: seeded ? `${THUMBNAIL} ${THUMBNAIL_WITH_IDENTITY}` : THUMBNAIL, children: [row.seed !== undefined ? _jsx(ThumbnailIdentity, { seed: row.seed, name: row.name, size: "thumb" }) : null, row.thumbnail && !failed ? (_jsx("img", { src: row.thumbnail, alt: "", decoding: "async", draggable: false, ref: check, onError: () => setFailed(true), className: "size-full object-cover object-top" })) : seeded ? null : (_jsx(Mark, { className: "size-5 text-steel" }))] }));
143
340
  }
144
- /** A 32px square action: ghost, radius 8, a 20px glyph in stone. */
145
- const ACTION_CLASS = "size-8 rounded-xs text-stone hover:bg-(--cg-hover) hover:text-ink aria-expanded:bg-(--cg-hover)";
341
+ /** A chip on the active row: white, a pill, 28 tall, its glyph and its word (the glyph alone on a phone). */
342
+ const CHIP = "inline-flex h-7 shrink-0 cursor-pointer items-center gap-1.5 rounded-pill bg-card px-2.5 font-ui text-caption leading-none font-medium text-ink shadow-mark transition-colors motion-reduce:transition-none hover:bg-page focus-line @max-[30rem]/creation-search:px-1.5";
343
+ const CHIP_WORD = "@max-[30rem]/creation-search:sr-only";
146
344
  function Row({ row, index, cellId, shown, onActivate, onOpen, onOpenLive, onTogglePin, renderMenu, onActionsFocus, }) {
147
- const actions = (onOpenLive ? 1 : 0) + (onTogglePin ? 1 : 0) + (renderMenu ? 1 : 0);
148
- return (_jsxs("div", { role: "row", "data-slot": "creation-search-row", "data-active": shown ? "" : undefined, onPointerMove: () => onActivate(index), className: cn("relative flex h-20 shrink-0 items-center rounded-xs px-3 transition-[background-color]", ROW_MOTION, shown && "bg-cyan-tint/50"), children: [_jsx("div", { role: "gridcell", id: cellId, "aria-selected": shown, className: "flex h-full min-w-0 flex-1 items-center", children: _jsxs("button", { type: "button", tabIndex: -1, "data-slot": "creation-search-open", onClick: () => onOpen(row), className: cn("after:absolute after:inset-0 after:rounded-xs after:content-['']", "flex min-w-0 flex-1 cursor-pointer items-center gap-4 text-start outline-none transition-[gap]", ROW_MOTION, shown && "gap-3"), children: [_jsx(Thumbnail, { row: row }), _jsxs("span", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [_jsx("span", { "data-slot": "creation-search-name", className: "truncate font-ui text-heading-sm leading-body font-semibold text-ink", children: row.name }), _jsxs("span", { "data-slot": "creation-search-meta", className: "truncate font-ui text-[length:var(--cg-body-14)] leading-body text-steel-strong", children: [row.owner, " \u00B7 ", row.space] })] }), _jsx(TypeIcon, { kind: row.kind, folded: shown && actions > 0 })] }) }), actions > 0 ? (_jsx("div", { role: "gridcell", "data-slot": "creation-search-actions", inert: !shown, onFocus: () => onActionsFocus(row, true), onBlur: (event) => {
345
+ const actions = Boolean(onOpenLive || onTogglePin || renderMenu);
346
+ return (_jsxs("div", { role: "row", "data-slot": "creation-search-row", "data-active": shown ? "" : undefined, onPointerMove: () => onActivate(index), className: cn("relative flex h-15 shrink-0 items-center gap-2 rounded-md px-2 transition-[background-color]", ROW_MOTION, shown && ACTIVE_ROW), children: [_jsx("div", { role: "gridcell", id: cellId, "aria-selected": shown, className: "flex h-full min-w-0 flex-1 items-center", children: _jsxs("button", { type: "button", tabIndex: -1, "data-slot": "creation-search-open", onClick: () => onOpen(row), className: "flex min-w-0 flex-1 cursor-pointer items-center gap-3 text-start outline-none after:absolute after:inset-0 after:rounded-md after:content-['']", children: [_jsx(Thumbnail, { row: row }), _jsxs("span", { className: "flex min-w-0 flex-1 flex-col", children: [_jsx("span", { "data-slot": "creation-search-name", className: "truncate font-ui text-body-sm leading-normal font-semibold text-ink", children: row.name }), _jsx("span", { "data-slot": "creation-search-meta", className: "truncate font-ui text-caption leading-normal text-body", children: creationRowDetail(row) })] })] }) }), actions ? (_jsx("div", { role: "gridcell", "data-slot": "creation-search-actions", inert: !shown, onFocus: () => onActionsFocus(row, true), onBlur: (event) => {
149
347
  if (!event.currentTarget.contains(event.relatedTarget))
150
348
  onActionsFocus(row, false);
151
- }, className: cn("relative z-10 flex h-8 shrink-0 justify-end overflow-hidden transition-[width,opacity]", ROW_MOTION, shown ? cn(ACTIONS_WIDTH[actions], "opacity-100") : "w-0 opacity-0"), children: _jsxs("div", { className: "flex shrink-0 gap-1 ps-3", children: [onOpenLive ? (_jsx(Button, { variant: "ghost", size: "icon", "data-slot": "creation-search-open-live", "aria-label": `Open ${row.name} live in a new tab`, onClick: () => onOpenLive(row), className: ACTION_CLASS, children: _jsx(OpenLiveIcon, { className: "size-5" }) })) : null, onTogglePin ? (_jsx(Button, { variant: "ghost", size: "icon", "data-slot": "creation-search-pin", "aria-label": `Pin ${row.name}`, "aria-pressed": Boolean(row.pinned), onClick: () => onTogglePin(row), className: ACTION_CLASS, children: row.pinned ? _jsx(SaveFilledIcon, { className: "size-5" }) : _jsx(PinIcon, { className: "size-5" }) })) : null, renderMenu ? (_jsxs(DropdownMenu, { children: [_jsxs(DropdownMenuTrigger, { "data-slot": "creation-search-menu", render: _jsx(Button, { variant: "ghost", size: "icon", className: ACTION_CLASS }), children: [_jsx(MoreActionsIcon, { className: "size-5" }), _jsxs("span", { className: "sr-only", children: ["More actions for ", row.name] })] }), _jsx(DropdownMenuContent, { align: "end", className: "w-48", children: renderMenu(row) })] })) : null] }) })) : null] }));
349
+ },
350
+ // A grid track from 0fr to 1fr: the chips' own width, eased.
351
+ className: cn("relative z-10 grid shrink-0 transition-[grid-template-columns,opacity]", ROW_MOTION, shown ? "grid-cols-[1fr] opacity-100" : "grid-cols-[0fr] opacity-0"), children: _jsxs("div", { className: "flex min-w-0 items-center gap-1.5 overflow-hidden p-0.5", children: [onTogglePin ? (_jsxs("button", { type: "button", "data-slot": "creation-search-pin", "aria-label": `${row.pinned ? CREATION_SEARCH_COPY.unpin : CREATION_SEARCH_COPY.pin} ${row.name}`, "aria-pressed": Boolean(row.pinned), onClick: () => onTogglePin(row), className: CHIP, children: [row.pinned ? _jsx(SaveFilledIcon, { className: "size-3.5" }) : _jsx(PinIcon, { className: "size-3.5" }), _jsx("span", { "aria-hidden": "true", className: CHIP_WORD, children: row.pinned ? CREATION_SEARCH_COPY.unpin : CREATION_SEARCH_COPY.pin })] })) : null, onOpenLive ? (_jsxs("button", { type: "button", "data-slot": "creation-search-open-live", "aria-label": `Open ${row.name} live in a new tab`, onClick: () => onOpenLive(row), className: CHIP, children: [_jsx(OpenLiveIcon, { className: "size-3.5" }), _jsx("span", { "aria-hidden": "true", className: CHIP_WORD, children: CREATION_SEARCH_COPY.live })] })) : null, renderMenu ? (_jsxs(DropdownMenu, { children: [_jsxs(DropdownMenuTrigger, { "data-slot": "creation-search-menu", render: _jsx(Button, { variant: "ghost", size: "icon", className: "size-7 cursor-pointer rounded-pill text-stone hover:bg-card hover:text-ink disabled:cursor-default aria-expanded:bg-card" }), children: [_jsx(MoreActionsIcon, { className: "size-4.5" }), _jsxs("span", { className: "sr-only", children: ["More actions for ", row.name] })] }), _jsx(DropdownMenuContent, { align: "end", className: "w-48", children: renderMenu(row) })] })) : null] }) })) : null, _jsx(TypeIcon, { kind: row.kind, active: shown })] }));
152
352
  }
153
353
  /** The no-match drawing: three empty result tiles, the middle one larger. */
154
354
  function EmptyResultTile({ large = false }) {
155
355
  return (_jsxs("span", { className: cn("flex shrink-0 items-center gap-2.5 rounded-xs bg-card px-2.5 ring-[1.5px] ring-brand-100 ring-inset", large ? "h-9.5 w-51" : "h-7.5 w-41.5 opacity-40"), children: [_jsx("span", { className: "size-5.5 shrink-0 rounded-2xs bg-brand-100" }), _jsxs("span", { className: "flex flex-col gap-1.25", children: [_jsx("span", { className: "block h-1 w-21.25 rounded-pill bg-brand-100" }), _jsx("span", { className: "block h-1 w-13 rounded-pill bg-brand-100" })] })] }));
156
356
  }
157
- const STATE_BODY = "flex min-h-79 flex-col items-center justify-center gap-4 text-center";
357
+ const STATE_BODY = "flex min-h-79 flex-col items-center justify-center gap-4 px-4 text-center";
158
358
  const STATE_TITLE = "m-0 font-ui text-heading-lg leading-body font-bold text-balance text-ink";
159
- const STATE_LINE = "m-0 font-ui text-body-sm leading-body text-pretty text-steel-strong";
359
+ const STATE_LINE = "m-0 font-ui text-body-sm leading-body text-pretty text-body";
160
360
  function NoMatch() {
161
361
  return (_jsxs("div", { "data-slot": "creation-search-no-match", className: STATE_BODY, children: [_jsxs("div", { "aria-hidden": "true", className: "flex h-27.5 w-56 flex-col items-center justify-center gap-1.5", children: [_jsx(EmptyResultTile, {}), _jsx(EmptyResultTile, { large: true }), _jsx(EmptyResultTile, {})] }), _jsx("h3", { className: STATE_TITLE, children: CREATION_SEARCH_COPY.noMatchTitle }), _jsx("p", { className: STATE_LINE, children: CREATION_SEARCH_COPY.noMatchLine })] }));
162
362
  }
163
363
  /**
164
- * The empty grid's creations strip: the Home strip's fan at the size this
165
- * window draws it, 360 wide. Two pictures each side of the dashed + tile,
166
- * overlapping by 23, stacked towards the middle. Under 360 of room the outer
167
- * pair drops, as `EmptyCreations` does.
364
+ * The empty grid's creations strip, as #531 drew it: two pictures each side of
365
+ * the dashed + tile, overlapping, stacked towards the middle; under 360 of
366
+ * room the outer pair drops.
168
367
  */
169
368
  const FAN_SLOTS = [
170
369
  { outer: true, className: "z-10 -me-5.75 h-11 w-19" },
@@ -177,30 +376,127 @@ function EmptyGrid({ onAddCreation }) {
177
376
  const slot = FAN_SLOTS[index];
178
377
  return (_jsx("span", { "data-slot": "creation-search-fan-picture", "data-outer": slot.outer ? "" : undefined, className: cn("relative block shrink-0 overflow-hidden rounded-md bg-raised shadow-card", slot.className, slot.outer && "@max-[22.5rem]/creation-search-empty:hidden"), children: _jsx("img", { src: EMPTY_CREATIONS_PREVIEWS[index % EMPTY_CREATIONS_PREVIEWS.length], alt: "", decoding: "async", draggable: false, className: "block size-full object-cover" }) }, index));
179
378
  };
180
- return (_jsxs("div", { "data-slot": "creation-search-empty-grid", className: cn("@container/creation-search-empty", STATE_BODY), children: [_jsxs("div", { "data-slot": "creation-search-fan", "aria-hidden": "true", className: "flex h-26 items-center justify-center", children: [picture(0), picture(1), _jsx("span", { "data-slot": "creation-search-fan-add", className: cn("relative z-30 flex h-16.25 w-28 shrink-0 items-center justify-center rounded-lg bg-page shadow-card", DASHED_LINE_CLASS), children: _jsx(PlusIcon, { className: "size-5.75 text-steel" }) }), picture(2), picture(3)] }), _jsx("h3", { className: STATE_TITLE, children: CREATION_SEARCH_COPY.emptyTitle }), _jsx("p", { className: STATE_LINE, children: CREATION_SEARCH_COPY.emptyLine }), onAddCreation ? (_jsxs(Button, { type: "button", "data-slot": "creation-search-add", onClick: () => onAddCreation(), children: [CREATION_SEARCH_COPY.addCreation, _jsx(PlusIcon, {})] })) : null] }));
379
+ return (_jsxs("div", { "data-slot": "creation-search-empty-grid", className: cn("@container/creation-search-empty", STATE_BODY), children: [_jsxs("div", { "data-slot": "creation-search-fan", "aria-hidden": "true", className: "flex h-26 items-center justify-center", children: [picture(0), picture(1), _jsx("span", { "data-slot": "creation-search-fan-add", className: cn("relative z-30 flex h-16.25 w-28 shrink-0 items-center justify-center rounded-lg bg-page shadow-card", DASHED_LINE_CLASS), children: _jsx(PlusIcon, { className: "size-5.75 text-steel" }) }), picture(2), picture(3)] }), _jsx("h3", { className: STATE_TITLE, children: CREATION_SEARCH_COPY.emptyTitle }), _jsx("p", { className: STATE_LINE, children: CREATION_SEARCH_COPY.emptyLine }), onAddCreation ? (_jsxs(Button, { type: "button", "data-slot": "creation-search-add", className: "cursor-pointer disabled:cursor-default", onClick: () => onAddCreation(), children: [CREATION_SEARCH_COPY.addCreation, _jsx(PlusIcon, {})] })) : null] }));
181
380
  }
182
- function CreationSearchDialog({ open, onOpenChange, query, onQueryChange, rows, state, onOpen, onOpenLive, onTogglePin, renderMenu, onAddCreation, modal = true, initialFocus = true, defaultActiveIndex = -1, container, className, }) {
381
+ /* -------------------------------------------------------------------------- */
382
+ /* The panel */
383
+ /* -------------------------------------------------------------------------- */
384
+ /** The results' smallest height, and the margin they keep from the screen's bottom, px. */
385
+ const MIN_ROOM = 160;
386
+ const ROOM_MARGIN = 16;
387
+ /**
388
+ * The room under the panel's top, for the search the reader is in: to the
389
+ * bottom of the screen, or above a phone's keyboard (the visual viewport),
390
+ * less a margin. Measured as the results open and when the screen or the
391
+ * keyboard resizes; never as the page scrolls or focus moves inside, so open
392
+ * results keep their size under the pointer. Results open on arrival, with no
393
+ * one in them, take their own height.
394
+ */
395
+ function useRoom(panel) {
396
+ const [room, setRoom] = React.useState(null);
397
+ React.useLayoutEffect(() => {
398
+ const el = panel.current;
399
+ const search = el?.parentElement;
400
+ if (!el || !search)
401
+ return;
402
+ const measure = () => {
403
+ if (!search.contains(document.activeElement)) {
404
+ setRoom(null);
405
+ return;
406
+ }
407
+ const vv = window.visualViewport;
408
+ const bottom = vv ? vv.offsetTop + vv.height : window.innerHeight;
409
+ setRoom(Math.max(MIN_ROOM, Math.floor(bottom - el.getBoundingClientRect().top - ROOM_MARGIN)));
410
+ };
411
+ measure();
412
+ const vv = window.visualViewport;
413
+ window.addEventListener("resize", measure);
414
+ vv?.addEventListener("resize", measure);
415
+ return () => {
416
+ window.removeEventListener("resize", measure);
417
+ vv?.removeEventListener("resize", measure);
418
+ };
419
+ }, [panel]);
420
+ return room;
421
+ }
422
+ /** Under this width the results span the `row`. */
423
+ const PHONE = "(max-width: 639.98px)";
424
+ /**
425
+ * Where the results start on a phone: the `row`'s left edge, measured from
426
+ * the bar's box (so a negative offset). Null from 640 up, without a row, and
427
+ * on the server. Measured again whenever the row or the bar resizes, which
428
+ * crossing 640 does too.
429
+ */
430
+ function useRowStart(panel, row) {
431
+ const [start, setStart] = React.useState(null);
432
+ React.useLayoutEffect(() => {
433
+ const box = panel.current?.parentElement;
434
+ const rowEl = row?.current;
435
+ if (!box || !rowEl || typeof window.matchMedia !== "function")
436
+ return;
437
+ const phone = window.matchMedia(PHONE);
438
+ const measure = () => setStart(phone.matches ? Math.round((rowEl.getBoundingClientRect().left - box.getBoundingClientRect().left) * 10) / 10 : null);
439
+ measure();
440
+ const observer = typeof ResizeObserver === "function" ? new ResizeObserver(measure) : null;
441
+ observer?.observe(rowEl);
442
+ observer?.observe(box);
443
+ return () => observer?.disconnect();
444
+ }, [panel, row]);
445
+ return start;
446
+ }
447
+ /**
448
+ * The results, right under the bar: the bar's width, 10 below it, over the
449
+ * page. The page stays where it is, unless the reader opens them with less
450
+ * room under the bar than their smallest height (the bar low on the screen,
451
+ * or a phone's keyboard up): then the page scrolls just enough to show them.
452
+ */
453
+ function Panel({ id, children, state, row, }) {
454
+ const ref = React.useRef(null);
455
+ const room = useRoom(ref);
456
+ const start = useRowStart(ref, row);
457
+ // Once, as they open (the first measure drawn), and only for the search the
458
+ // reader is in: never while they scroll, never for results open on arrival.
459
+ const placed = React.useRef(false);
460
+ React.useEffect(() => {
461
+ const el = ref.current;
462
+ if (placed.current || room === null || !el)
463
+ return;
464
+ placed.current = true;
465
+ if (!el.parentElement?.contains(document.activeElement))
466
+ return;
467
+ const vv = window.visualViewport;
468
+ const bottom = vv ? vv.offsetTop + vv.height : window.innerHeight;
469
+ const over = el.getBoundingClientRect().bottom + ROOM_MARGIN - bottom;
470
+ if (over > 0)
471
+ window.scrollBy({ top: over });
472
+ }, [room]);
473
+ return (_jsx("div", { ref: ref, "data-slot": "creation-search-panel", "data-state": state, id: id, className: "@container/creation-search absolute inset-x-0 top-full mt-2.5 flex min-h-0 flex-col overflow-hidden rounded-xl font-ui", style: room || start !== null ? { maxHeight: room ?? undefined, left: start ?? undefined } : undefined, children: children }));
474
+ }
475
+ /* -------------------------------------------------------------------------- */
476
+ /* The search */
477
+ /* -------------------------------------------------------------------------- */
478
+ function CreationSearchDialog({ open, onOpenChange, query, onQueryChange, rows, state, placeholder = CREATION_SEARCH_COPY.placeholder, onOpen, onOpenLive, onTogglePin, renderMenu, onAddCreation, shortcut = true, defaultActiveIndex = -1, row, className, }) {
183
479
  const baseId = React.useId();
184
480
  const listId = `${baseId}-list`;
481
+ const panelId = `${baseId}-panel`;
185
482
  const labelId = `${baseId}-label`;
186
483
  const cellId = (index) => `${baseId}-row-${index}`;
187
- const inputRef = React.useRef(null);
484
+ const hint = useShortcutHint();
485
+ const rootRef = React.useRef(null);
486
+ const barRef = React.useRef(null);
188
487
  const listRef = React.useRef(null);
189
- const listed = state === "recent" || state === "results";
190
- const count = listed ? rows.length : 0;
191
- // The active row: -1 until the pointer or a key picks one. A new list (other
192
- // rows, another state, a reopen) starts with none, so it is reset while
193
- // rendering when that changes rather than in an effect a frame later.
488
+ const listed = state === "results";
489
+ const panelShown = open && query !== "" && state !== "recent";
490
+ const count = listed && panelShown ? rows.length : 0;
491
+ // The active row: -1 until the pointer or a key picks one. A new list starts
492
+ // with none, reset while rendering rather than in an effect a frame later.
194
493
  const [active, setActive] = React.useState(defaultActiveIndex);
195
- const listKey = `${open ? 1 : 0}:${state}:${rows.map((row) => row.id).join("\u0000")}`;
494
+ const listKey = `${panelShown ? 1 : 0}:${state}:${rows.map((row) => row.id).join("\u0000")}`;
196
495
  const [seenListKey, setSeenListKey] = React.useState(listKey);
197
496
  if (seenListKey !== listKey) {
198
497
  setSeenListKey(listKey);
199
498
  setActive(-1);
200
499
  }
201
- // A row whose actions hold focus stays shown when the pointer moves on, so
202
- // the focused control never turns inert under the keyboard. (An open "..."
203
- // menu needs nothing: it is modal and holds the pointer until it closes.)
204
500
  const [focusRow, setFocusRow] = React.useState(null);
205
501
  const [scrollTo, setScrollTo] = React.useState(-1);
206
502
  React.useEffect(() => {
@@ -210,6 +506,68 @@ function CreationSearchDialog({ open, onOpenChange, query, onQueryChange, rows,
210
506
  if (row instanceof HTMLElement)
211
507
  row.scrollIntoView({ block: "nearest" });
212
508
  }, [scrollTo]);
509
+ /** Open the results again for what is already in the bar. */
510
+ const reopen = React.useCallback(() => {
511
+ if (!open && query !== "")
512
+ onOpenChange(true);
513
+ }, [open, query, onOpenChange]);
514
+ // A press outside closes the results; a press inside, or in the "..." menu's
515
+ // popup (a menu it portals), does not. So does focus leaving for something
516
+ // outside. Escape anywhere inside closes them, unless something inside (an
517
+ // open menu) took the key first, and leaves the focus in the bar.
518
+ React.useEffect(() => {
519
+ const root = rootRef.current;
520
+ if (!open || !root)
521
+ return;
522
+ const outside = (at) => at instanceof Element && !root.contains(at) && !at.closest('[role="menu"]');
523
+ const onPress = (event) => {
524
+ if (event.target instanceof Element && !outside(event.target))
525
+ return;
526
+ onOpenChange(false);
527
+ };
528
+ const onFocusOut = (event) => {
529
+ if (outside(event.relatedTarget))
530
+ onOpenChange(false);
531
+ };
532
+ const onKey = (event) => {
533
+ if (event.key !== "Escape" || event.defaultPrevented)
534
+ return;
535
+ event.preventDefault();
536
+ onOpenChange(false);
537
+ barRef.current?.focus({ preventScroll: true });
538
+ };
539
+ document.addEventListener("pointerdown", onPress);
540
+ root.addEventListener("focusout", onFocusOut);
541
+ root.addEventListener("keydown", onKey);
542
+ return () => {
543
+ document.removeEventListener("pointerdown", onPress);
544
+ root.removeEventListener("focusout", onFocusOut);
545
+ root.removeEventListener("keydown", onKey);
546
+ };
547
+ }, [open, onOpenChange]);
548
+ // ⌘K or Ctrl K, anywhere on the page: the bar, the caret after its text.
549
+ React.useEffect(() => {
550
+ if (!shortcut)
551
+ return;
552
+ const onKey = (event) => {
553
+ if (!(event.metaKey || event.ctrlKey) || event.altKey || event.shiftKey || event.key.toLowerCase() !== "k")
554
+ return;
555
+ const bar = barRef.current;
556
+ if (!bar)
557
+ return;
558
+ // Another field on the page keeps its own ⌘K.
559
+ const at = event.target;
560
+ if (at instanceof HTMLElement && at !== bar && (at.isContentEditable || at.closest("input, textarea")))
561
+ return;
562
+ event.preventDefault();
563
+ bar.focus();
564
+ const end = bar.value.length;
565
+ bar.setSelectionRange(end, end);
566
+ reopen();
567
+ };
568
+ document.addEventListener("keydown", onKey);
569
+ return () => document.removeEventListener("keydown", onKey);
570
+ }, [shortcut, reopen]);
213
571
  function moveBy(step) {
214
572
  if (count === 0)
215
573
  return;
@@ -217,14 +575,19 @@ function CreationSearchDialog({ open, onOpenChange, query, onQueryChange, rows,
217
575
  setActive(next);
218
576
  setScrollTo(next);
219
577
  }
220
- function onKeyDown(event) {
578
+ function onBarKeyDown(event) {
221
579
  if (event.nativeEvent.isComposing)
222
580
  return;
223
581
  if (event.key === "ArrowDown") {
224
582
  event.preventDefault();
225
- moveBy(1);
583
+ if (panelShown)
584
+ moveBy(1);
585
+ else
586
+ reopen();
226
587
  }
227
588
  else if (event.key === "ArrowUp") {
589
+ if (!panelShown)
590
+ return;
228
591
  event.preventDefault();
229
592
  moveBy(-1);
230
593
  }
@@ -234,10 +597,24 @@ function CreationSearchDialog({ open, onOpenChange, query, onQueryChange, rows,
234
597
  }
235
598
  }
236
599
  const activeShown = active >= 0 && active < count;
237
- return (_jsx(Dialog, { open: open, onOpenChange: (next) => onOpenChange(next), modal: modal, children: _jsxs(DialogContent, { showCloseButton: false, container: container, initialFocus: initialFocus ? inputRef : false, "data-slot": "creation-search", "data-state": state, className: cn("@container/creation-search top-[18svh] flex max-h-[calc(82svh-1rem)] translate-y-0 flex-col gap-4 rounded-container border-0 px-4 pt-5 pb-6 font-ui shadow-float sm:max-w-170 sm:px-7", "motion-reduce:animate-none", className), children: [_jsx(DialogTitle, { className: "sr-only", children: CREATION_SEARCH_COPY.placeholder }), _jsxs("div", { "data-slot": "creation-search-header", className: "flex h-12 shrink-0 items-center gap-3", children: [_jsxs("div", { className: "relative min-w-0 flex-1", children: [_jsx(SearchIcon, { className: "pointer-events-none absolute start-4 top-1/2 size-5.5 -translate-y-1/2 text-stone" }), _jsx(Input, { ref: inputRef, type: "text", role: "combobox", "data-slot": "creation-search-field", "aria-label": CREATION_SEARCH_COPY.placeholder, "aria-autocomplete": "list", "aria-haspopup": "grid", "aria-expanded": count > 0, "aria-controls": listed ? listId : undefined, "aria-activedescendant": activeShown ? cellId(active) : undefined, autoComplete: "off", spellCheck: false, placeholder: CREATION_SEARCH_COPY.placeholder, value: query, onChange: (event) => onQueryChange(event.target.value), onKeyDown: onKeyDown, className: "h-12 rounded-sm ps-12.25 pe-4 font-ui text-heading-sm leading-body text-ink placeholder:text-ink md:text-heading-sm" })] }), _jsxs(DialogClose, { "data-slot": "creation-search-close", render: _jsx(Button, { variant: "ghost", size: "icon", className: "size-11 rounded-xs text-stone hover:bg-(--cg-hover) hover:text-ink" }), children: [_jsx(CloseIcon, { className: "size-6" }), _jsx("span", { className: "sr-only", children: CREATION_SEARCH_COPY.close })] })] }), _jsx(Separator, { className: "bg-hairline" }), listed ? (_jsxs(_Fragment, { children: [_jsx("p", { id: labelId, "data-slot": "creation-search-heading", "aria-live": "polite", className: "m-0 text-[length:var(--cg-body-14)] leading-body font-semibold text-steel-strong", children: state === "recent" ? CREATION_SEARCH_COPY.recentHeading : creationCountLabel(count) }), _jsx("div", { ref: listRef, id: listId, role: "grid", "aria-labelledby": labelId, "data-slot": "creation-search-list", className: "flex h-60 shrink-0 flex-col overflow-y-auto", children: rows.map((row, index) => (_jsx(Row, { row: row, index: index, cellId: cellId(index), shown: index === active || row.id === focusRow, onActivate: (i) => {
238
- if (i !== active)
239
- setActive(i);
240
- }, onOpen: onOpen, onOpenLive: onOpenLive, onTogglePin: onTogglePin, renderMenu: renderMenu, onActionsFocus: (r, focused) => setFocusRow((current) => (focused ? r.id : current === r.id ? null : current)) }, row.id))) }), _jsx(Separator, { className: "bg-hairline" }), _jsx("p", { "data-slot": "creation-search-footer", className: "m-0 text-center text-caption leading-body text-steel-strong", children: state === "recent" ? CREATION_SEARCH_COPY.recentFooter : CREATION_SEARCH_COPY.resultsFooter })] })) : state === "no-match" ? (_jsx(NoMatch, {})) : (_jsx(EmptyGrid, { onAddCreation: onAddCreation }))] }) }));
600
+ return (_jsxs(_Fragment, { children: [_jsx("style", { href: "cg-creation-search", precedence: "medium", children: STYLES }), _jsxs("div", { ref: rootRef, "data-slot": "creation-search-bar-wrap", "data-open": panelShown ? "" : undefined,
601
+ // Over the content below while the results show.
602
+ className: cn("relative w-full min-w-0 font-ui", panelShown && "z-30", className), children: [_jsx("span", { "aria-hidden": "true", className: "pointer-events-none absolute start-5 top-1/2 flex size-5 -translate-y-1/2 text-stone", children: _jsx(SearchIcon, { className: "size-5" }) }), _jsx("input", { ref: barRef, type: "text", role: "combobox", "data-slot": "creation-search-bar", "aria-label": placeholder, "aria-keyshortcuts": "Meta+K Control+K", "aria-autocomplete": "list", "aria-haspopup": "grid", "aria-expanded": panelShown, "aria-controls": panelShown ? (count > 0 ? listId : panelId) : undefined, "aria-activedescendant": activeShown ? cellId(active) : undefined, autoComplete: "off", spellCheck: false, enterKeyHint: "search", placeholder: placeholder, value: query, onChange: (event) => {
603
+ const typed = event.target.value;
604
+ onQueryChange(typed);
605
+ // The first character opens the results; an empty bar closes them.
606
+ if (typed !== "" && !open)
607
+ onOpenChange(true);
608
+ else if (typed === "" && open)
609
+ onOpenChange(false);
610
+ }, onPointerDown: reopen, onKeyDown: onBarKeyDown, className: cn(BAR_BOX, "block w-full min-w-0 caret-transparent ps-13 font-ui text-body-18 leading-normal text-ink placeholder:text-steel-strong placeholder-shown:ps-16 focus-line", hint && query === "" ? "pe-16" : "pe-5") }), hint && query === "" ? (_jsx(Kbd, { "data-slot": "creation-search-hint", "aria-hidden": "true", className: "pointer-events-none absolute end-4 top-1/2 -translate-y-1/2", children: hint })) : null, _jsx(GlowCaret, { input: barRef, value: query }), _jsx("span", { "data-slot": "creation-search-status", "aria-live": "polite", className: "sr-only", children: panelShown ? (listed ? creationCountLabel(count) : state === "no-match" ? CREATION_SEARCH_COPY.noMatchTitle : CREATION_SEARCH_COPY.emptyTitle) : "" }), panelShown ? (_jsx(Panel, { id: panelId, state: state, row: row, children: listed ? (_jsxs(_Fragment, { children: [_jsx("p", { id: labelId, "data-slot": "creation-search-heading", className: "m-0 shrink-0 px-5 pt-3.5 pb-1.5 text-caption leading-body text-body", children: _jsx("span", { className: "font-semibold", children: creationCountLabel(count) }) }), _jsx("div", { ref: listRef, id: listId, role: "grid", "aria-labelledby": labelId, "data-slot": "creation-search-list", className: "flex min-h-0 flex-col gap-0.5 overflow-y-auto px-2 [@media(hover:none)_and_(pointer:coarse)]:pb-2", children: rows.map((row, index) => (_jsx(Row, { row: row, index: index, cellId: cellId(index), shown: index === active || row.id === focusRow, onActivate: (i) => {
611
+ if (i !== active)
612
+ setActive(i);
613
+ }, onOpen: onOpen, onOpenLive: onOpenLive, onTogglePin: onTogglePin, renderMenu: renderMenu, onActionsFocus: (r, focused) => setFocusRow((current) => (focused ? r.id : current === r.id ? null : current)) }, row.id))) }), _jsx("p", { "data-slot": "creation-search-footer",
614
+ // No keys on a touch screen: hidden by the ⌘K hint's own rule (TOUCH).
615
+ className: "m-0 mx-5 mt-1.5 shrink-0 border-t border-hairline py-2.5 text-caption leading-body text-body [@media(hover:none)_and_(pointer:coarse)]:hidden", children: CREATION_SEARCH_COPY.resultsFooter })] })) : state === "no-match" ? (_jsx(NoMatch, {})) : (_jsx(EmptyGrid, { onAddCreation: onAddCreation })) })) : null] })] }));
241
616
  }
242
- export { CreationSearchDialog };
617
+ /** The same search under the name that says what it is now: the front pages' search bar. */
618
+ const CreationSearch = CreationSearchDialog;
619
+ export { CreationSearch, CreationSearchDialog };
243
620
  //# sourceMappingURL=creation-search.js.map