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