@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.
- package/dist/badge/marks.d.ts +2 -0
- package/dist/badge/marks.d.ts.map +1 -1
- package/dist/badge/marks.js +5 -0
- package/dist/badge/marks.js.map +1 -1
- package/dist/badge/watermark.js +2 -2
- package/dist/badge/watermark.js.map +1 -1
- package/dist/blocks/browse-categories.d.ts +80 -0
- package/dist/blocks/browse-categories.d.ts.map +1 -0
- package/dist/blocks/browse-categories.js +106 -0
- package/dist/blocks/browse-categories.js.map +1 -0
- package/dist/blocks/creation-search.d.ts +145 -102
- package/dist/blocks/creation-search.d.ts.map +1 -1
- package/dist/blocks/creation-search.js +502 -125
- package/dist/blocks/creation-search.js.map +1 -1
- package/dist/blocks/feed-row.d.ts +92 -0
- package/dist/blocks/feed-row.d.ts.map +1 -0
- package/dist/blocks/feed-row.js +30 -0
- package/dist/blocks/feed-row.js.map +1 -0
- package/dist/blocks/filter-tabs.d.ts +12 -1
- package/dist/blocks/filter-tabs.d.ts.map +1 -1
- package/dist/blocks/filter-tabs.js +11 -2
- package/dist/blocks/filter-tabs.js.map +1 -1
- package/dist/blocks/greeting.d.ts +42 -0
- package/dist/blocks/greeting.d.ts.map +1 -0
- package/dist/blocks/greeting.js +38 -0
- package/dist/blocks/greeting.js.map +1 -0
- package/dist/blocks/home-bento.d.ts +11 -4
- package/dist/blocks/home-bento.d.ts.map +1 -1
- package/dist/blocks/home-bento.js +22 -6
- package/dist/blocks/home-bento.js.map +1 -1
- package/dist/blocks/home-pinned.d.ts +81 -3
- package/dist/blocks/home-pinned.d.ts.map +1 -1
- package/dist/blocks/home-pinned.js +195 -9
- package/dist/blocks/home-pinned.js.map +1 -1
- package/dist/blocks/icons.d.ts +54 -6
- package/dist/blocks/icons.d.ts.map +1 -1
- package/dist/blocks/icons.js +67 -6
- package/dist/blocks/icons.js.map +1 -1
- package/dist/blocks/impact-card.d.ts +105 -0
- package/dist/blocks/impact-card.d.ts.map +1 -0
- package/dist/blocks/impact-card.js +57 -0
- package/dist/blocks/impact-card.js.map +1 -0
- package/dist/blocks/inspiration-cards.d.ts +227 -5
- package/dist/blocks/inspiration-cards.d.ts.map +1 -1
- package/dist/blocks/inspiration-cards.js +286 -8
- package/dist/blocks/inspiration-cards.js.map +1 -1
- package/dist/blocks/jump-back-in.d.ts +249 -0
- package/dist/blocks/jump-back-in.d.ts.map +1 -0
- package/dist/blocks/jump-back-in.js +272 -0
- package/dist/blocks/jump-back-in.js.map +1 -0
- package/dist/blocks/load-more-grid.d.ts +125 -0
- package/dist/blocks/load-more-grid.d.ts.map +1 -0
- package/dist/blocks/load-more-grid.js +157 -0
- package/dist/blocks/load-more-grid.js.map +1 -0
- package/dist/blocks/menu-trigger.d.ts +7 -2
- package/dist/blocks/menu-trigger.d.ts.map +1 -1
- package/dist/blocks/menu-trigger.js +2 -0
- package/dist/blocks/menu-trigger.js.map +1 -1
- package/dist/blocks/phosphor-marks.d.ts +17 -1
- package/dist/blocks/phosphor-marks.d.ts.map +1 -1
- package/dist/blocks/phosphor-marks.js +25 -1
- package/dist/blocks/phosphor-marks.js.map +1 -1
- package/dist/blocks/start-card.d.ts +76 -0
- package/dist/blocks/start-card.d.ts.map +1 -0
- package/dist/blocks/start-card.js +82 -0
- package/dist/blocks/start-card.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/motion.d.ts +14 -0
- package/dist/lib/motion.d.ts.map +1 -1
- package/dist/lib/motion.js +4 -0
- package/dist/lib/motion.js.map +1 -1
- 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 {
|
|
12
|
-
import {
|
|
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
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
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
|
|
98
|
+
/** Every line the search writes, as the design writes it. */
|
|
96
99
|
export const CREATION_SEARCH_COPY = {
|
|
97
100
|
placeholder: "Search creations",
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
/**
|
|
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
|
|
122
|
-
*
|
|
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
|
|
316
|
+
const ACTIVE_ROW = "bg-[color-mix(in_oklab,var(--cg-primary-20)_65%,var(--cg-neutral-0))]";
|
|
125
317
|
/**
|
|
126
|
-
* The type
|
|
127
|
-
*
|
|
128
|
-
*
|
|
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,
|
|
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("
|
|
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:
|
|
137
|
-
const THUMBNAIL = "flex h-
|
|
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-
|
|
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
|
|
145
|
-
const
|
|
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
|
|
148
|
-
return (_jsxs("div", { role: "row", "data-slot": "creation-search-row", "data-active": shown ? "" : undefined, onPointerMove: () => onActivate(index), className: cn("relative flex h-
|
|
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
|
-
},
|
|
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-
|
|
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
|
|
165
|
-
*
|
|
166
|
-
*
|
|
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
|
-
|
|
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
|
|
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 === "
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
//
|
|
193
|
-
//
|
|
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 = `${
|
|
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
|
|
578
|
+
function onBarKeyDown(event) {
|
|
221
579
|
if (event.nativeEvent.isComposing)
|
|
222
580
|
return;
|
|
223
581
|
if (event.key === "ArrowDown") {
|
|
224
582
|
event.preventDefault();
|
|
225
|
-
|
|
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 (
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
|
|
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
|