@stapel/listings-react 0.25.10 → 0.27.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/CHANGELOG.md +259 -0
- package/MODULE.md +3 -1
- package/README.md +122 -9
- package/dist/api/generated/schema.d.ts +22 -12
- package/dist/api/generated/schema.d.ts.map +1 -1
- package/dist/default/CardBadges.d.ts.map +1 -1
- package/dist/default/CardBadges.js +3 -1
- package/dist/default/CardBadges.js.map +1 -1
- package/dist/default/ListingActions.d.ts +108 -0
- package/dist/default/ListingActions.d.ts.map +1 -0
- package/dist/default/ListingActions.js +29 -0
- package/dist/default/ListingActions.js.map +1 -0
- package/dist/default/ListingCard.d.ts.map +1 -1
- package/dist/default/ListingCard.js +15 -8
- package/dist/default/ListingCard.js.map +1 -1
- package/dist/default/ListingDetailPane.d.ts +170 -62
- package/dist/default/ListingDetailPane.d.ts.map +1 -1
- package/dist/default/ListingDetailPane.js +284 -28
- package/dist/default/ListingDetailPane.js.map +1 -1
- package/dist/default/ListingFeedCard.d.ts.map +1 -1
- package/dist/default/ListingFeedCard.js +2 -1
- package/dist/default/ListingFeedCard.js.map +1 -1
- package/dist/default/ListingPhoto.d.ts.map +1 -1
- package/dist/default/ListingPhoto.js +5 -2
- package/dist/default/ListingPhoto.js.map +1 -1
- package/dist/default/ListingSerpCard.d.ts.map +1 -1
- package/dist/default/ListingSerpCard.js +18 -4
- package/dist/default/ListingSerpCard.js.map +1 -1
- package/dist/default/MyListingsPane.d.ts.map +1 -1
- package/dist/default/MyListingsPane.js +49 -21
- package/dist/default/MyListingsPane.js.map +1 -1
- package/dist/default/ShareAction.d.ts +32 -0
- package/dist/default/ShareAction.d.ts.map +1 -0
- package/dist/default/ShareAction.js +116 -0
- package/dist/default/ShareAction.js.map +1 -0
- package/dist/default/actionRow.d.ts +58 -0
- package/dist/default/actionRow.d.ts.map +1 -0
- package/dist/default/actionRow.js +128 -0
- package/dist/default/actionRow.js.map +1 -0
- package/dist/default/cardGallery.d.ts +2 -0
- package/dist/default/cardGallery.d.ts.map +1 -1
- package/dist/default/cardGallery.js +31 -0
- package/dist/default/cardGallery.js.map +1 -1
- package/dist/default/detailGallery.d.ts +77 -0
- package/dist/default/detailGallery.d.ts.map +1 -0
- package/dist/default/detailGallery.js +91 -0
- package/dist/default/detailGallery.js.map +1 -0
- package/dist/default/favorite.d.ts +25 -0
- package/dist/default/favorite.d.ts.map +1 -1
- package/dist/default/favorite.js +29 -3
- package/dist/default/favorite.js.map +1 -1
- package/dist/default/icons.d.ts +19 -0
- package/dist/default/icons.d.ts.map +1 -1
- package/dist/default/icons.js +23 -0
- package/dist/default/icons.js.map +1 -1
- package/dist/default/index.d.ts +11 -2
- package/dist/default/index.d.ts.map +1 -1
- package/dist/default/index.js +10 -1
- package/dist/default/index.js.map +1 -1
- package/dist/default/movableCluster.d.ts +18 -0
- package/dist/default/movableCluster.d.ts.map +1 -0
- package/dist/default/movableCluster.js +110 -0
- package/dist/default/movableCluster.js.map +1 -0
- package/dist/default/notice.d.ts +14 -0
- package/dist/default/notice.d.ts.map +1 -0
- package/dist/default/notice.js +62 -0
- package/dist/default/notice.js.map +1 -0
- package/dist/headless/MyListings.d.ts +61 -19
- package/dist/headless/MyListings.d.ts.map +1 -1
- package/dist/headless/MyListings.js +58 -19
- package/dist/headless/MyListings.js.map +1 -1
- package/dist/headless/Share.d.ts +103 -0
- package/dist/headless/Share.d.ts.map +1 -0
- package/dist/headless/Share.js +190 -0
- package/dist/headless/Share.js.map +1 -0
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +21 -0
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/generated/errors.es.gen.d.ts +1 -1
- package/dist/i18n/generated/errors.es.gen.js +1 -1
- package/dist/i18n/generated/errors.gen.d.ts +18 -0
- package/dist/i18n/generated/errors.gen.d.ts.map +1 -1
- package/dist/i18n/generated/errors.gen.js +9 -0
- package/dist/i18n/generated/errors.gen.js.map +1 -1
- package/dist/i18n/generated/errors.ru.gen.d.ts +1 -1
- package/dist/i18n/generated/errors.ru.gen.js +1 -1
- package/dist/i18n/keys.d.ts +45 -0
- package/dist/i18n/keys.d.ts.map +1 -1
- package/dist/i18n/keys.js +60 -0
- package/dist/i18n/keys.js.map +1 -1
- package/dist/i18n/ru.d.ts.map +1 -1
- package/dist/i18n/ru.js +21 -0
- package/dist/i18n/ru.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/model/cardBadges.d.ts +52 -3
- package/dist/model/cardBadges.d.ts.map +1 -1
- package/dist/model/cardBadges.js +74 -12
- package/dist/model/cardBadges.js.map +1 -1
- package/dist/model/mineSource.d.ts +9 -3
- package/dist/model/mineSource.d.ts.map +1 -1
- package/dist/model/mineSource.js.map +1 -1
- package/dist/model/status.d.ts +79 -15
- package/dist/model/status.d.ts.map +1 -1
- package/dist/model/status.js +86 -17
- package/dist/model/status.js.map +1 -1
- package/llms.txt +8 -3
- package/manifest.json +96 -4
- package/nav-manifest.json +1 -1
- package/package.json +10 -10
- package/src/analytics/generated/events.json +1 -1
- package/src/api/generated/schema.ts +22 -12
- package/src/default/CardBadges.tsx +3 -1
- package/src/default/ListingActions.tsx +196 -0
- package/src/default/ListingCard.tsx +79 -43
- package/src/default/ListingDetailPane.tsx +520 -89
- package/src/default/ListingFeedCard.tsx +2 -0
- package/src/default/ListingPhoto.tsx +28 -0
- package/src/default/ListingSerpCard.tsx +39 -12
- package/src/default/MyListingsPane.tsx +81 -44
- package/src/default/ShareAction.tsx +260 -0
- package/src/default/actionRow.ts +131 -0
- package/src/default/cardGallery.ts +31 -0
- package/src/default/detailGallery.ts +97 -0
- package/src/default/favorite.tsx +68 -1
- package/src/default/icons.tsx +60 -0
- package/src/default/index.ts +37 -1
- package/src/default/movableCluster.tsx +137 -0
- package/src/default/notice.ts +68 -0
- package/src/headless/MyListings.tsx +130 -39
- package/src/headless/Share.tsx +278 -0
- package/src/i18n/es.ts +28 -0
- package/src/i18n/generated/errors.es.gen.ts +1 -1
- package/src/i18n/generated/errors.gen.ts +9 -0
- package/src/i18n/generated/errors.json +31 -0
- package/src/i18n/generated/errors.ru.gen.ts +1 -1
- package/src/i18n/keys.ts +63 -0
- package/src/i18n/ru.ts +28 -0
- package/src/index.ts +22 -0
- package/src/model/cardBadges.ts +124 -12
- package/src/model/mineSource.ts +9 -3
- package/src/model/status.ts +102 -20
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The geometry of a listing's action row — the heart, the share button, and
|
|
3
|
+
* the rules that make both of them reachable with a thumb.
|
|
4
|
+
*
|
|
5
|
+
* Split out of `<ListingActions>` so `<ShareAction>` can carry the same class
|
|
6
|
+
* without the two modules importing each other, and so the numbers below are
|
|
7
|
+
* something a test can READ rather than something a rendered button implies.
|
|
8
|
+
*
|
|
9
|
+
* ── Why a class and not an inline style ───────────────────────────────────
|
|
10
|
+
*
|
|
11
|
+
* Three of the four rules here cannot be written inline at all: a media query
|
|
12
|
+
* (the label that disappears on a phone), a descendant selector (the hit area
|
|
13
|
+
* of whatever element the skin registry substituted for antd's button), and
|
|
14
|
+
* `:focus-visible`. The fourth — the 44px floor — is written here with them so
|
|
15
|
+
* that "how big is this control" has ONE answer in this package instead of one
|
|
16
|
+
* per surface, which is how the SERP heart ended up 32px while the feed
|
|
17
|
+
* heart was 40 and neither was the number the platform guidelines ask for.
|
|
18
|
+
*
|
|
19
|
+
* ── 44 px, and where the number comes from ────────────────────────────────
|
|
20
|
+
*
|
|
21
|
+
* `controls["height-phone"]` — the token dictionary's own touch floor, the
|
|
22
|
+
* same value `SkinTheme` feeds antd as `controlHeight` on a phone (WCAG 2.5.8
|
|
23
|
+
* and both platform HIGs land on 44 CSS px). It is applied here as a MINIMUM
|
|
24
|
+
* on every viewport rather than only on a phone: these two controls are small
|
|
25
|
+
* glyphs pinned to the corner of a photograph, and a 32px circle at the edge
|
|
26
|
+
* of an image is a miss on a touchscreen laptop as surely as on a phone.
|
|
27
|
+
*/
|
|
28
|
+
import { breakpoints, controls, radii, spacing } from "@stapel/tokens";
|
|
29
|
+
|
|
30
|
+
/** The class every control in the PAGE cluster carries: the 44px floor. */
|
|
31
|
+
export const LISTING_ACTION_CLASS = "stapel-listing-action";
|
|
32
|
+
/**
|
|
33
|
+
* The class a CARD's control carries — the same floor, one tier smaller on a
|
|
34
|
+
* pointer device.
|
|
35
|
+
*
|
|
36
|
+
* A card heart is drawn forty to a screen on a desktop grid, where the
|
|
37
|
+
* reference classified uses a 36px target and a cursor hits it every time;
|
|
38
|
+
* the same glyph on a phone is a thumb target and goes back to 44. Two tiers
|
|
39
|
+
* rather than one number, because a 44px circle in the corner of a 267px
|
|
40
|
+
* photograph is a fifth of the picture's height on a desktop — measured
|
|
41
|
+
* against the reference (§23), which is why this is not simply
|
|
42
|
+
* {@link LISTING_ACTION_CLASS}.
|
|
43
|
+
*
|
|
44
|
+
* The GLYPH does not change size in either tier; only the box around it does.
|
|
45
|
+
*/
|
|
46
|
+
export const LISTING_CARD_ACTION_CLASS = "stapel-listing-card-action";
|
|
47
|
+
/** The class the cluster's row carries. */
|
|
48
|
+
export const LISTING_ACTIONS_CLASS = "stapel-listing-actions";
|
|
49
|
+
/**
|
|
50
|
+
* The class that pins the cluster to the trailing TOP corner of the media it
|
|
51
|
+
* is drawn over.
|
|
52
|
+
*
|
|
53
|
+
* Top-trailing is the one corner of a card gallery that is free: the dots own
|
|
54
|
+
* the bottom centre (`SkinCarousel`) and the "3 of 16" counter owns the
|
|
55
|
+
* bottom trailing corner (`cardGalleryCss`). Nothing here may move into
|
|
56
|
+
* either, which is why this is a named constant with a comment rather than
|
|
57
|
+
* two numbers picked per surface.
|
|
58
|
+
*/
|
|
59
|
+
export const LISTING_ACTIONS_OVERLAY_CLASS = "stapel-listing-actions-over";
|
|
60
|
+
/** The class on the WORD beside a glyph — painted on a desktop, dropped on a
|
|
61
|
+
* phone, where the same word is still the control's accessible name. */
|
|
62
|
+
export const LISTING_ACTION_LABEL_CLASS = "stapel-listing-action-label";
|
|
63
|
+
/** The `href` the hoisted action-row stylesheet is deduplicated by. */
|
|
64
|
+
export const LISTING_ACTIONS_STYLE_HREF = "stapel-listings-action-row";
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The minimum touch target for every control in the cluster, in CSS pixels.
|
|
68
|
+
*
|
|
69
|
+
* Exported so a host laying out beside the cluster measures against the same
|
|
70
|
+
* number — and so `test/shareAction.test.tsx` asserts the rule carries THIS
|
|
71
|
+
* value rather than a literal that could drift from the token.
|
|
72
|
+
*/
|
|
73
|
+
export const LISTING_ACTION_HIT: number = controls["height-phone"];
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A CARD control's minimum target on a pointer device, in CSS pixels.
|
|
77
|
+
*
|
|
78
|
+
* The reference classified's own desktop measurement (§23). It is not on the
|
|
79
|
+
* token scale, and it is not meant to be: the scale carries a control HEIGHT
|
|
80
|
+
* (32) and a touch FLOOR (44), and this is the third thing — the smallest box
|
|
81
|
+
* a cursor reliably hits around a 16px glyph. Named, with the measurement,
|
|
82
|
+
* rather than typed into a stylesheet as `36`.
|
|
83
|
+
*
|
|
84
|
+
* On a phone the card control goes back to {@link LISTING_ACTION_HIT}: there
|
|
85
|
+
* is no such thing as a small touch target.
|
|
86
|
+
*/
|
|
87
|
+
export const LISTING_CARD_ACTION_HIT = 36;
|
|
88
|
+
|
|
89
|
+
export function actionRowCss(): string {
|
|
90
|
+
const action = `.${LISTING_ACTION_CLASS}`;
|
|
91
|
+
const cardAction = `.${LISTING_CARD_ACTION_CLASS}`;
|
|
92
|
+
const row = `.${LISTING_ACTIONS_CLASS}`;
|
|
93
|
+
const over = `.${LISTING_ACTIONS_OVERLAY_CLASS}`;
|
|
94
|
+
const label = `.${LISTING_ACTION_LABEL_CLASS}`;
|
|
95
|
+
const hit = String(LISTING_ACTION_HIT);
|
|
96
|
+
const phone = `(max-width:${String(breakpoints.tablet - 1)}px)`;
|
|
97
|
+
return [
|
|
98
|
+
// The floor. `min-*` rather than `width`/`height`: a share button with a
|
|
99
|
+
// word in it is wider than 44px and must stay so, and antd's own
|
|
100
|
+
// `controlHeight` already reaches the height on a phone — this is the
|
|
101
|
+
// guarantee for every OTHER viewport and for a host-registered button
|
|
102
|
+
// that never read the antd token at all.
|
|
103
|
+
`${action}{min-inline-size:${hit}px;min-block-size:${hit}px;` +
|
|
104
|
+
`display:inline-flex;align-items:center;justify-content:center}`,
|
|
105
|
+
// A card's control: one tier smaller where there is a cursor, the same
|
|
106
|
+
// 44px where there is a thumb. See LISTING_CARD_ACTION_HIT.
|
|
107
|
+
`${cardAction}{min-inline-size:${String(LISTING_CARD_ACTION_HIT)}px;` +
|
|
108
|
+
`min-block-size:${String(LISTING_CARD_ACTION_HIT)}px;` +
|
|
109
|
+
`display:inline-flex;align-items:center;justify-content:center}`,
|
|
110
|
+
`@media ${phone}{${cardAction}{min-inline-size:${hit}px;min-block-size:${hit}px}}`,
|
|
111
|
+
// The cluster. `align-items:flex-end` so a blocked heart's reason — the
|
|
112
|
+
// one thing here that can be two lines — stacks against the same edge
|
|
113
|
+
// instead of pushing the controls inwards (the arrangement
|
|
114
|
+
// `<ListingFeedCard>` already ships).
|
|
115
|
+
`${row}{display:flex;align-items:flex-end;gap:${String(spacing[2])}px}`,
|
|
116
|
+
// Over a photograph. `z-index:2` puts it above the counter's `1`; the two
|
|
117
|
+
// never meet anyway (top-trailing against bottom-trailing) and the layer
|
|
118
|
+
// is stated so a future third overlay has an order to join.
|
|
119
|
+
`${over}{position:absolute;inset-block-start:${String(spacing[2])}px;` +
|
|
120
|
+
`inset-inline-end:${String(spacing[2])}px;z-index:2;` +
|
|
121
|
+
`flex-direction:column;align-items:flex-end;` +
|
|
122
|
+
`border-radius:${String(radii.full)}px}`,
|
|
123
|
+
// THE WORD DISAPPEARS ON A PHONE, THE NAME NEVER DOES. Both controls
|
|
124
|
+
// carry their `aria-label` in every arm, so what a screen reader
|
|
125
|
+
// announces is identical at 390px and at 1440px; what changes is whether
|
|
126
|
+
// there is room to paint the word as well. A viewport query rather than a
|
|
127
|
+
// container one: this is chrome, not a layout that has to fit a track,
|
|
128
|
+
// and the question really is "is this a phone".
|
|
129
|
+
`@media ${phone}{${label}{display:none}}`,
|
|
130
|
+
].join("");
|
|
131
|
+
}
|
|
@@ -46,9 +46,12 @@
|
|
|
46
46
|
*/
|
|
47
47
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
48
48
|
import type { PointerEvent as ReactPointerEvent, RefObject } from "react";
|
|
49
|
+
import { fontSize, radii, spacing } from "@stapel/tokens";
|
|
49
50
|
|
|
50
51
|
/** The class the gallery's own box carries — see {@link cardGalleryCss}. */
|
|
51
52
|
export const CARD_GALLERY_CLASS = "stapel-listing-gallery";
|
|
53
|
+
/** The class the "3 of 16" pill carries — see {@link cardGalleryCss}. */
|
|
54
|
+
export const CARD_GALLERY_COUNTER_CLASS = "stapel-listing-gallery-count";
|
|
52
55
|
/** The `href` the hoisted gallery stylesheet is deduplicated by. */
|
|
53
56
|
export const CARD_GALLERY_STYLE_HREF = "stapel-listings-card-gallery";
|
|
54
57
|
|
|
@@ -338,7 +341,35 @@ export function useCardGallery(count: number): CardGallery {
|
|
|
338
341
|
*/
|
|
339
342
|
export function cardGalleryCss(): string {
|
|
340
343
|
const box = `.${CARD_GALLERY_CLASS}`;
|
|
344
|
+
const counter = `.${CARD_GALLERY_COUNTER_CLASS}`;
|
|
341
345
|
return [
|
|
346
|
+
// The counter is placed against this box, so the box has to be the
|
|
347
|
+
// containing block. Nothing else about the gallery changes: a `relative`
|
|
348
|
+
// with no offsets moves no pixel of what is already in it.
|
|
349
|
+
`${box}{position:relative}`,
|
|
350
|
+
// "3 of 16", bottom-TRAILING corner — the dots own the bottom centre
|
|
351
|
+
// (`SkinCarousel`: `inset-inline:0; justify-content:center`) and two
|
|
352
|
+
// indicators fighting for one spot is worse than neither.
|
|
353
|
+
//
|
|
354
|
+
// `pointer-events:none` is load-bearing rather than tidy: this box owns
|
|
355
|
+
// the hover-scrub and the swipe, and an element that swallowed a pointer
|
|
356
|
+
// would make one corner of every card's photograph dead to both gestures.
|
|
357
|
+
//
|
|
358
|
+
// A FIXED scrim and white text, not a theme role, and this is the one
|
|
359
|
+
// place in the package where that is the right answer: the pill sits on
|
|
360
|
+
// an arbitrary PHOTOGRAPH, which is neither light nor dark, so a value
|
|
361
|
+
// that followed the page's theme would be unreadable on half the photos
|
|
362
|
+
// in either one.
|
|
363
|
+
`${counter}{position:absolute;inset-block-end:${String(spacing[2])}px;` +
|
|
364
|
+
`inset-inline-end:${String(spacing[2])}px;z-index:1;pointer-events:none;` +
|
|
365
|
+
`padding:${String(spacing[1] / 2)}px ${String(spacing[2])}px;` +
|
|
366
|
+
`border-radius:${String(radii.full)}px;` +
|
|
367
|
+
`background:rgba(0,0,0,0.55);color:#fff;` +
|
|
368
|
+
`font-size:${String(fontSize.xs.fontSize)}px;` +
|
|
369
|
+
`line-height:${String(fontSize.xs.lineHeight)}px;` +
|
|
370
|
+
// A counter whose digits change width makes the pill twitch on every
|
|
371
|
+
// swipe.
|
|
372
|
+
`font-variant-numeric:tabular-nums}`,
|
|
342
373
|
// THE VERTICAL AXIS IS THE BROWSER'S, and is not negotiable: a card is a
|
|
343
374
|
// small box in a long feed, and the one unacceptable outcome of a gallery
|
|
344
375
|
// gesture is a page that will not scroll. `pan-y` says so at the platform
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HOW THE LISTING PAGE LAYS OUT ITS PHOTOGRAPHS — and why the answer is a
|
|
3
|
+
* class and a prop rather than an inline `display`.
|
|
4
|
+
*
|
|
5
|
+
* ── The defect a container was carrying ───────────────────────────────────
|
|
6
|
+
*
|
|
7
|
+
* The gallery is an element-width grid (`repeat(auto-fit, minmax(14rem,
|
|
8
|
+
* 1fr))`), which on a 390px phone resolves to ONE column: a listing with three
|
|
9
|
+
* pictures pushes its own title and price nearly three screens down, and the
|
|
10
|
+
* first thing a person sees after tapping a search result is a photograph with
|
|
11
|
+
* nothing beside it. A phone lays photographs out as a snap-scrolling STRIP —
|
|
12
|
+
* one visible with the next peeking, title and price directly under it.
|
|
13
|
+
*
|
|
14
|
+
* That is layout, and layout is the container's to decide. But the pane wrote
|
|
15
|
+
* `display: grid` INLINE, and an inline declaration is beaten by nothing that
|
|
16
|
+
* is not `!important` — so a live storefront carried
|
|
17
|
+
* `[data-testid="listings-detail-gallery"] { display: flex !important }`
|
|
18
|
+
* against a pair's own geometry, named by a test id, to say a thing the pair
|
|
19
|
+
* offered no way to say (a client storefront's own stylesheet, §2).
|
|
20
|
+
*
|
|
21
|
+
* ── The seam ──────────────────────────────────────────────────────────────
|
|
22
|
+
*
|
|
23
|
+
* Two halves, and both matter:
|
|
24
|
+
*
|
|
25
|
+
* 1. `<ListingDetailPane galleryLayout>` — the pane ships BOTH layouts and
|
|
26
|
+
* the host names one, exactly as it already names `layout="split"` and
|
|
27
|
+
* `gutter`. The host is the side that knows the viewport it granted;
|
|
28
|
+
* a media query guessed in a leaf is the thing this package does not do.
|
|
29
|
+
* 2. `display` and the track are no longer inline. They live on this
|
|
30
|
+
* stylesheet, at one class plus one attribute, so a host that wants
|
|
31
|
+
* something neither arm offers can still write CSS for it at its own
|
|
32
|
+
* breakpoints — and needs no `!important` to be heard, only a selector of
|
|
33
|
+
* its own (`[data-testid="listings-detail-gallery"][data-gallery-layout]`
|
|
34
|
+
* ties; add any third condition and it wins).
|
|
35
|
+
*
|
|
36
|
+
* What stays inline is what nobody overrides and what a stylesheet would make
|
|
37
|
+
* worse: the `gap` (the page's own responsive gutter token, D418 — a var, so
|
|
38
|
+
* a resize reflows it) and `position: relative`, which is the containing block
|
|
39
|
+
* the `actionsPlacement="gallery"` overlay is pinned to.
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* The narrowest a gallery tile may get before the grid drops a column. A
|
|
43
|
+
* measure rather than a pixel: the tiles then fill whatever the ELEMENT is,
|
|
44
|
+
* which is §83's geometry rule — one photo per row on a phone, three on a
|
|
45
|
+
* desktop pane, and no `width: 320` that is near-full-bleed on one and a
|
|
46
|
+
* postage stamp on the other.
|
|
47
|
+
*
|
|
48
|
+
* Declared here rather than in `<ListingDetailPane>` because this is the file
|
|
49
|
+
* that writes the track it feeds; the pane re-exports it, so the public name
|
|
50
|
+
* is unchanged.
|
|
51
|
+
*/
|
|
52
|
+
export const DETAIL_PHOTO_MIN = "14rem";
|
|
53
|
+
|
|
54
|
+
/** Which shape the photographs take. See the file header. */
|
|
55
|
+
export type ListingGalleryLayout = "grid" | "strip";
|
|
56
|
+
|
|
57
|
+
/** The class the gallery box carries. */
|
|
58
|
+
export const LISTINGS_GALLERY_CLASS = "stapel-listings-detail-gallery";
|
|
59
|
+
|
|
60
|
+
/** The `href` the hoisted gallery stylesheet is deduplicated by. */
|
|
61
|
+
export const LISTINGS_GALLERY_STYLE_HREF = "stapel-listings-detail-gallery";
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* How much of the strip's width ONE photograph takes.
|
|
65
|
+
*
|
|
66
|
+
* Not 100: the remaining sliver of the next picture is the only thing on a
|
|
67
|
+
* phone that says the strip scrolls at all. Exported so a host laying out
|
|
68
|
+
* beside it measures against the same number instead of guessing it back out
|
|
69
|
+
* of a screenshot.
|
|
70
|
+
*/
|
|
71
|
+
export const LISTINGS_GALLERY_STRIP_BASIS = "86%";
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The gallery's layout rules, for the hoisted `<style>`.
|
|
75
|
+
*
|
|
76
|
+
* The strip's child rule (`> *`) is the reason this is a stylesheet and not
|
|
77
|
+
* two more inline properties: an inline style cannot reach a child, and the
|
|
78
|
+
* flex basis is what makes the strip a strip rather than a row of squeezed
|
|
79
|
+
* photographs.
|
|
80
|
+
*/
|
|
81
|
+
export function detailGalleryCss(): string {
|
|
82
|
+
return `
|
|
83
|
+
.${LISTINGS_GALLERY_CLASS}[data-gallery-layout="grid"] {
|
|
84
|
+
display: grid;
|
|
85
|
+
grid-template-columns: repeat(auto-fit, minmax(${DETAIL_PHOTO_MIN}, 1fr));
|
|
86
|
+
}
|
|
87
|
+
.${LISTINGS_GALLERY_CLASS}[data-gallery-layout="strip"] {
|
|
88
|
+
display: flex;
|
|
89
|
+
overflow-x: auto;
|
|
90
|
+
scroll-snap-type: x mandatory;
|
|
91
|
+
}
|
|
92
|
+
.${LISTINGS_GALLERY_CLASS}[data-gallery-layout="strip"] > * {
|
|
93
|
+
flex: 0 0 ${LISTINGS_GALLERY_STRIP_BASIS};
|
|
94
|
+
scroll-snap-align: start;
|
|
95
|
+
}
|
|
96
|
+
`.trim();
|
|
97
|
+
}
|
package/src/default/favorite.tsx
CHANGED
|
@@ -35,6 +35,8 @@ import { useFavoriteToggle } from "../headless/Favorites.js";
|
|
|
35
35
|
import { LISTINGS_I18N_KEYS } from "../i18n/keys.js";
|
|
36
36
|
import { GateReasonPopover } from "./GateReasonPopover.js";
|
|
37
37
|
import { HeartIcon } from "./icons.js";
|
|
38
|
+
import { useNotice } from "./notice.js";
|
|
39
|
+
import { LISTING_ACTIONS_STYLE_HREF, actionRowCss } from "./actionRow.js";
|
|
38
40
|
|
|
39
41
|
export interface FavoriteHeartProps {
|
|
40
42
|
readonly listingId: number;
|
|
@@ -83,6 +85,31 @@ export interface FavoriteHeartProps {
|
|
|
83
85
|
* its reason, which is all a surface with no sign-in route can offer.
|
|
84
86
|
*/
|
|
85
87
|
readonly signIn?: SignInCta;
|
|
88
|
+
/**
|
|
89
|
+
* The hit-target class this surface wants — `LISTING_CARD_ACTION_CLASS` on
|
|
90
|
+
* a card (36px with a cursor, 44px with a thumb),
|
|
91
|
+
* `LISTING_ACTION_CLASS` on the listing page (44px everywhere).
|
|
92
|
+
*
|
|
93
|
+
* A CLASS rather than a size prop: the tiers are a media query, and a
|
|
94
|
+
* component that took a number would have to be told the viewport — which
|
|
95
|
+
* is the thing a leaf must never ask. See `actionRow.ts`.
|
|
96
|
+
*/
|
|
97
|
+
readonly className?: string;
|
|
98
|
+
/**
|
|
99
|
+
* SAY THE OUTCOME OUT LOUD — a short toast on each successful press.
|
|
100
|
+
*
|
|
101
|
+
* Off by default and ON for the listing page: one heart on a screen the
|
|
102
|
+
* person came to act on earns a sentence, forty hearts on a grid do not.
|
|
103
|
+
* The icon fill remains the state in both cases; this is the acknowledgement
|
|
104
|
+
* that the press was received, which is the half a small glyph pinned to
|
|
105
|
+
* the corner of a photograph cannot carry on its own.
|
|
106
|
+
*
|
|
107
|
+
* It is raised on the GESTURE, from the predicted next state, for the same
|
|
108
|
+
* reason `useFavoriteToggle` draws that state optimistically: the toast has
|
|
109
|
+
* to arrive with the press. A write that then fails rolls the icon back and
|
|
110
|
+
* states the failure through the heart's own `ErrorAlert`.
|
|
111
|
+
*/
|
|
112
|
+
readonly announce?: boolean;
|
|
86
113
|
readonly style?: CSSProperties;
|
|
87
114
|
}
|
|
88
115
|
|
|
@@ -134,6 +161,7 @@ export interface FavoriteHeartProps {
|
|
|
134
161
|
*/
|
|
135
162
|
export function FavoriteHeart(props: FavoriteHeartProps): ReactElement {
|
|
136
163
|
const t = useT();
|
|
164
|
+
const notice = useNotice();
|
|
137
165
|
const { token } = antdTheme.useToken();
|
|
138
166
|
const favorite = useFavoriteToggle(props.listingId, props.favorited);
|
|
139
167
|
const label = t(
|
|
@@ -154,6 +182,22 @@ export function FavoriteHeart(props: FavoriteHeartProps): ReactElement {
|
|
|
154
182
|
// place a blocked reason becomes words in this fleet.
|
|
155
183
|
const gate = useActionGate(favorite.gate);
|
|
156
184
|
const reason = gate.reason;
|
|
185
|
+
// The press, plus the sentence the surface asked for. The next state is the
|
|
186
|
+
// one the icon is about to draw, so the toast and the fill say the same
|
|
187
|
+
// thing at the same moment — see `announce`.
|
|
188
|
+
const announce = props.announce === true;
|
|
189
|
+
const press = (): void => {
|
|
190
|
+
const next = !favorite.favorited;
|
|
191
|
+
favorite.toggle();
|
|
192
|
+
if (!announce || !favorite.gate.available) return;
|
|
193
|
+
notice(
|
|
194
|
+
t(
|
|
195
|
+
next
|
|
196
|
+
? LISTINGS_I18N_KEYS.favoriteAdded
|
|
197
|
+
: LISTINGS_I18N_KEYS.favoriteRemoved
|
|
198
|
+
)
|
|
199
|
+
);
|
|
200
|
+
};
|
|
157
201
|
// D431. A blocked gate plus a door the surface handed in: the press is not
|
|
158
202
|
// refused, it is ROUTED — through the door, keeping whatever `?next=` the
|
|
159
203
|
// container put in the href. With no door there is nothing better for the
|
|
@@ -175,9 +219,10 @@ export function FavoriteHeart(props: FavoriteHeartProps): ReactElement {
|
|
|
175
219
|
...doorPress,
|
|
176
220
|
...(door?.href !== undefined ? {} : { "aria-pressed": favorite.favorited }),
|
|
177
221
|
}
|
|
178
|
-
: { "aria-pressed": favorite.favorited, onClick:
|
|
222
|
+
: { "aria-pressed": favorite.favorited, onClick: press };
|
|
179
223
|
// A failed save, stated where the heart is. The rollback already put the
|
|
180
224
|
// icon back; this says why it went back.
|
|
225
|
+
// (see `press` above for the toast that rides the successful half)
|
|
181
226
|
const failure = (
|
|
182
227
|
<ErrorAlert
|
|
183
228
|
testId={`${props.testId}-error`}
|
|
@@ -185,8 +230,20 @@ export function FavoriteHeart(props: FavoriteHeartProps): ReactElement {
|
|
|
185
230
|
variant="inline"
|
|
186
231
|
/>
|
|
187
232
|
);
|
|
233
|
+
// The hit-target rules the surfaces address by class. Hoisted here rather
|
|
234
|
+
// than by each card, because the heart is what carries the class and a
|
|
235
|
+
// stylesheet that arrived only on the surfaces that remembered it is a
|
|
236
|
+
// 32px target on the one that forgot.
|
|
237
|
+
const sheet = (
|
|
238
|
+
<style href={LISTING_ACTIONS_STYLE_HREF} precedence="default">
|
|
239
|
+
{actionRowCss()}
|
|
240
|
+
</style>
|
|
241
|
+
);
|
|
242
|
+
|
|
188
243
|
if (props.blockedReason === "popover" && reason !== undefined) {
|
|
189
244
|
return (
|
|
245
|
+
<>
|
|
246
|
+
{sheet}
|
|
190
247
|
<GateReasonPopover
|
|
191
248
|
reason={reason}
|
|
192
249
|
cta={props.signIn}
|
|
@@ -201,6 +258,9 @@ export function FavoriteHeart(props: FavoriteHeartProps): ReactElement {
|
|
|
201
258
|
// control, and the disclosure stays as the hint beside it.
|
|
202
259
|
{...(opensDoor ? {} : { "aria-disabled": true })}
|
|
203
260
|
{...bind}
|
|
261
|
+
{...(props.className !== undefined
|
|
262
|
+
? { className: props.className }
|
|
263
|
+
: {})}
|
|
204
264
|
aria-label={label}
|
|
205
265
|
data-testid={props.testId}
|
|
206
266
|
data-favorited={String(favorite.favorited)}
|
|
@@ -212,9 +272,12 @@ export function FavoriteHeart(props: FavoriteHeartProps): ReactElement {
|
|
|
212
272
|
/>
|
|
213
273
|
)}
|
|
214
274
|
</GateReasonPopover>
|
|
275
|
+
</>
|
|
215
276
|
);
|
|
216
277
|
}
|
|
217
278
|
return (
|
|
279
|
+
<>
|
|
280
|
+
{sheet}
|
|
218
281
|
<GatedControl
|
|
219
282
|
gate={favorite.gate}
|
|
220
283
|
testId={props.gateTestId ?? `${props.testId}-gate`}
|
|
@@ -233,6 +296,9 @@ export function FavoriteHeart(props: FavoriteHeartProps): ReactElement {
|
|
|
233
296
|
shape="circle"
|
|
234
297
|
// See `<ListingCard>`: the substrate's binding, spread whole.
|
|
235
298
|
{...bind}
|
|
299
|
+
{...(props.className !== undefined
|
|
300
|
+
? { className: props.className }
|
|
301
|
+
: {})}
|
|
236
302
|
aria-label={label}
|
|
237
303
|
data-testid={props.testId}
|
|
238
304
|
data-favorited={String(favorite.favorited)}
|
|
@@ -245,5 +311,6 @@ export function FavoriteHeart(props: FavoriteHeartProps): ReactElement {
|
|
|
245
311
|
</>
|
|
246
312
|
)}
|
|
247
313
|
</GatedControl>
|
|
314
|
+
</>
|
|
248
315
|
);
|
|
249
316
|
}
|
package/src/default/icons.tsx
CHANGED
|
@@ -50,6 +50,66 @@ export function HeartIcon(props: HeartIconProps): ReactElement {
|
|
|
50
50
|
);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* The share glyph — three nodes and two edges, the platform-neutral shape
|
|
55
|
+
* both Android and the web draw for "send this somewhere else".
|
|
56
|
+
*
|
|
57
|
+
* `aria-hidden`, like the heart: the control it sits in carries the verb as
|
|
58
|
+
* its accessible name in every arm, including the phone arm where the word
|
|
59
|
+
* itself is not painted, and a glyph announced beside its own label reads the
|
|
60
|
+
* action twice.
|
|
61
|
+
*
|
|
62
|
+
* Deliberately not the iOS "box with an arrow": that shape means "share" to
|
|
63
|
+
* an iPhone user and "upload" or "export" to everybody else, and this control
|
|
64
|
+
* is drawn on a browser, not inside an app the platform styled.
|
|
65
|
+
*/
|
|
66
|
+
export function ShareIcon(): ReactElement {
|
|
67
|
+
return (
|
|
68
|
+
<svg
|
|
69
|
+
width="16"
|
|
70
|
+
height="16"
|
|
71
|
+
viewBox="0 0 24 24"
|
|
72
|
+
fill="none"
|
|
73
|
+
stroke="currentColor"
|
|
74
|
+
strokeWidth="2"
|
|
75
|
+
strokeLinecap="round"
|
|
76
|
+
strokeLinejoin="round"
|
|
77
|
+
role="img"
|
|
78
|
+
aria-hidden="true"
|
|
79
|
+
>
|
|
80
|
+
<circle cx="18" cy="5" r="3" />
|
|
81
|
+
<circle cx="6" cy="12" r="3" />
|
|
82
|
+
<circle cx="18" cy="19" r="3" />
|
|
83
|
+
<path d="M8.6 10.5 15.4 6.6" />
|
|
84
|
+
<path d="M8.6 13.5 15.4 17.4" />
|
|
85
|
+
</svg>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* A chain link — the copy row's glyph, and the one thing on the menu that is
|
|
91
|
+
* not a network's own brand.
|
|
92
|
+
*/
|
|
93
|
+
export function LinkIcon(): ReactElement {
|
|
94
|
+
return (
|
|
95
|
+
<svg
|
|
96
|
+
width="16"
|
|
97
|
+
height="16"
|
|
98
|
+
viewBox="0 0 24 24"
|
|
99
|
+
fill="none"
|
|
100
|
+
stroke="currentColor"
|
|
101
|
+
strokeWidth="2"
|
|
102
|
+
strokeLinecap="round"
|
|
103
|
+
strokeLinejoin="round"
|
|
104
|
+
role="img"
|
|
105
|
+
aria-hidden="true"
|
|
106
|
+
>
|
|
107
|
+
<path d="M10 13a5 5 0 0 0 7.5.6l3-3a5 5 0 0 0-7-7l-1.7 1.7" />
|
|
108
|
+
<path d="M14 11a5 5 0 0 0-7.5-.6l-3 3a5 5 0 0 0 7 7l1.7-1.7" />
|
|
109
|
+
</svg>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
53
113
|
/**
|
|
54
114
|
* Which way the asking price moved — an arrow, and a NAME for it.
|
|
55
115
|
*
|
package/src/default/index.ts
CHANGED
|
@@ -71,8 +71,22 @@ export {
|
|
|
71
71
|
DETAIL_SPLIT_MEASURE,
|
|
72
72
|
DETAIL_SPLIT_ASIDE,
|
|
73
73
|
DETAIL_PHOTO_MIN,
|
|
74
|
+
DETAIL_GALLERY_GUTTER,
|
|
74
75
|
} from "./ListingDetailPane.js";
|
|
75
|
-
export type {
|
|
76
|
+
export type {
|
|
77
|
+
ListingDetailPaneProps,
|
|
78
|
+
ListingActionsPlacement,
|
|
79
|
+
} from "./ListingDetailPane.js";
|
|
80
|
+
// The gallery's two shapes, its class and the stylesheet behind them — a host
|
|
81
|
+
// that wants a third writes CSS against these rather than `!important` over an
|
|
82
|
+
// inline `display`.
|
|
83
|
+
export {
|
|
84
|
+
LISTINGS_GALLERY_CLASS,
|
|
85
|
+
LISTINGS_GALLERY_STYLE_HREF,
|
|
86
|
+
LISTINGS_GALLERY_STRIP_BASIS,
|
|
87
|
+
detailGalleryCss,
|
|
88
|
+
} from "./detailGallery.js";
|
|
89
|
+
export type { ListingGalleryLayout } from "./detailGallery.js";
|
|
76
90
|
export {
|
|
77
91
|
ListingComposerPage,
|
|
78
92
|
COMPOSER_DETAILS_PLACEMENT,
|
|
@@ -126,6 +140,28 @@ export {
|
|
|
126
140
|
useCardGallery,
|
|
127
141
|
} from "./cardGallery.js";
|
|
128
142
|
export type { CardGallery } from "./cardGallery.js";
|
|
143
|
+
// ── the reader's two actions: save it, or send it to somebody ───────────────
|
|
144
|
+
export { ListingActions } from "./ListingActions.js";
|
|
145
|
+
export type {
|
|
146
|
+
ListingActionsConfig,
|
|
147
|
+
ListingActionsProps,
|
|
148
|
+
} from "./ListingActions.js";
|
|
149
|
+
export { ShareAction } from "./ShareAction.js";
|
|
150
|
+
export type { ShareActionProps } from "./ShareAction.js";
|
|
151
|
+
export {
|
|
152
|
+
LISTING_ACTIONS_CLASS,
|
|
153
|
+
LISTING_ACTIONS_OVERLAY_CLASS,
|
|
154
|
+
LISTING_ACTIONS_STYLE_HREF,
|
|
155
|
+
LISTING_ACTION_CLASS,
|
|
156
|
+
LISTING_ACTION_HIT,
|
|
157
|
+
LISTING_ACTION_LABEL_CLASS,
|
|
158
|
+
LISTING_CARD_ACTION_CLASS,
|
|
159
|
+
LISTING_CARD_ACTION_HIT,
|
|
160
|
+
actionRowCss,
|
|
161
|
+
} from "./actionRow.js";
|
|
162
|
+
export { NOTICE_SECONDS, useNotice } from "./notice.js";
|
|
163
|
+
export type { Notice } from "./notice.js";
|
|
164
|
+
|
|
129
165
|
export { SignInLink } from "./SignInLink.js";
|
|
130
166
|
export type { SignInLinkProps } from "./SignInLink.js";
|
|
131
167
|
export type { CategoryFeaturesProp, ThemeModeProp } from "./types.js";
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ONE CLUSTER, TWO PLACES ON THE PAGE — the same instance, moved.
|
|
3
|
+
*
|
|
4
|
+
* ── The ask this answers, and why the obvious shape does not ──────────────
|
|
5
|
+
*
|
|
6
|
+
* A listing page wants the reader's two verbs beside the title AND in the
|
|
7
|
+
* condensed bar that arrives when the title scrolls away (reference §24). A
|
|
8
|
+
* host cannot do that today: `<ListingDetailPane>` mounts its cluster at
|
|
9
|
+
* exactly one `actionsPlacement`, so a container that wants the second one
|
|
10
|
+
* mounts a `<ListingActions>` of its own — which is a SECOND
|
|
11
|
+
* `useFavoriteToggle` on one page, two hearts that agree only after a refetch,
|
|
12
|
+
* and two copies of a control whose geometry this pair exists to rule once.
|
|
13
|
+
*
|
|
14
|
+
* The shapes that do NOT close it, stated because each looks like it would:
|
|
15
|
+
*
|
|
16
|
+
* a render prop handed the cluster ELEMENT
|
|
17
|
+
* A React element is a description, not an instance. Rendered in two
|
|
18
|
+
* places it mounts twice — exactly the defect, now with the pair's name
|
|
19
|
+
* on it.
|
|
20
|
+
*
|
|
21
|
+
* the host moving one element between two parents
|
|
22
|
+
* React unmounts and remounts across a parent change: the hook state
|
|
23
|
+
* goes, the DOM node is a different node, and an optimistic favourite
|
|
24
|
+
* in flight is lost mid-write.
|
|
25
|
+
*
|
|
26
|
+
* two mounts kept in step by lifting the state
|
|
27
|
+
* Two controls, one state — and then the page has two `aria-pressed`
|
|
28
|
+
* hearts, two focus targets and two things for a probe to count.
|
|
29
|
+
*
|
|
30
|
+
* ── What this does ────────────────────────────────────────────────────────
|
|
31
|
+
*
|
|
32
|
+
* The cluster is rendered ONCE, through a portal, into a `<div>` this hook
|
|
33
|
+
* owns. The page draws SLOTS — empty `display: contents` divs — wherever the
|
|
34
|
+
* cluster may sit, and the container element is `appendChild`-ed into whichever
|
|
35
|
+
* slot is currently on screen with the highest priority. Moving a DOM node
|
|
36
|
+
* between parents is not a React tree change, so:
|
|
37
|
+
*
|
|
38
|
+
* - `<ListingActions>` (and everything under it) mounts exactly once;
|
|
39
|
+
* - the favourite button is literally the SAME `HTMLElement` in both
|
|
40
|
+
* placements — `test/detailActionsPlacements.test.tsx` holds the node
|
|
41
|
+
* across the move and asserts identity, which is the only assertion that
|
|
42
|
+
* can tell this apart from a well-behaved remount;
|
|
43
|
+
* - a slot that unmounts hands the cluster back to the next one down,
|
|
44
|
+
* rather than taking it off the page.
|
|
45
|
+
*
|
|
46
|
+
* `display: contents` on both the slot and the container is load-bearing: the
|
|
47
|
+
* cluster must remain a direct flex item of the heading row (it is laid out by
|
|
48
|
+
* `justify="space-between"`) and must stay absolutely positionable against the
|
|
49
|
+
* gallery's containing block in the overlay arm. A wrapper that generated a
|
|
50
|
+
* box would change both.
|
|
51
|
+
*/
|
|
52
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
53
|
+
import type { CSSProperties, ReactElement, ReactNode } from "react";
|
|
54
|
+
import { createPortal } from "react-dom";
|
|
55
|
+
|
|
56
|
+
/** Neither slot nor container may generate a box — see the file header. */
|
|
57
|
+
const CONTENTS: CSSProperties = { display: "contents" };
|
|
58
|
+
|
|
59
|
+
export interface MovableCluster {
|
|
60
|
+
/**
|
|
61
|
+
* True when there is a document to portal into. `false` under SSR, where
|
|
62
|
+
* the caller renders the cluster inline at its primary placement instead —
|
|
63
|
+
* a server render has no scrolling and therefore no second placement.
|
|
64
|
+
*/
|
|
65
|
+
readonly portable: boolean;
|
|
66
|
+
/** Render the cluster ONCE, anywhere in the tree. Returns the portal. */
|
|
67
|
+
render(cluster: ReactNode): ReactNode;
|
|
68
|
+
/**
|
|
69
|
+
* A mount point. The highest `priority` currently on screen holds the
|
|
70
|
+
* cluster; when it goes, the next one down gets it back.
|
|
71
|
+
*/
|
|
72
|
+
slot(priority: number, name: string): ReactElement;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function useMovableCluster(enabled: boolean): MovableCluster {
|
|
76
|
+
const container = useRef<HTMLElement | null>(null);
|
|
77
|
+
if (enabled && container.current === null && typeof document !== "undefined") {
|
|
78
|
+
const host = document.createElement("div");
|
|
79
|
+
host.style.display = "contents";
|
|
80
|
+
host.setAttribute("data-listings-cluster-portal", "");
|
|
81
|
+
container.current = host;
|
|
82
|
+
}
|
|
83
|
+
const slots = useRef(new Map<number, HTMLElement>());
|
|
84
|
+
const refs = useRef(new Map<number, (node: HTMLElement | null) => void>());
|
|
85
|
+
|
|
86
|
+
/** Put the container in the highest-priority slot that is on the page. */
|
|
87
|
+
const settle = useCallback((): void => {
|
|
88
|
+
const host = container.current;
|
|
89
|
+
if (host === null) return;
|
|
90
|
+
let best: HTMLElement | undefined;
|
|
91
|
+
let bestPriority = -1;
|
|
92
|
+
for (const [priority, node] of slots.current) {
|
|
93
|
+
// `isConnected` matters during a commit that removes a slot: React may
|
|
94
|
+
// hand back a node it is about to drop, and appending into it would take
|
|
95
|
+
// the cluster off the page with it.
|
|
96
|
+
if (node.isConnected && priority > bestPriority) {
|
|
97
|
+
bestPriority = priority;
|
|
98
|
+
best = node;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (best !== undefined && host.parentNode !== best) best.appendChild(host);
|
|
102
|
+
}, []);
|
|
103
|
+
|
|
104
|
+
// The belt. A slot's ref cleanup is what normally moves the cluster, but a
|
|
105
|
+
// subtree removed around it would leave the container detached with nothing
|
|
106
|
+
// to notice; this runs after every commit and repairs that in one comparison.
|
|
107
|
+
useEffect(settle);
|
|
108
|
+
|
|
109
|
+
const refFor = useCallback(
|
|
110
|
+
(priority: number): ((node: HTMLElement | null) => void) => {
|
|
111
|
+
let ref = refs.current.get(priority);
|
|
112
|
+
if (ref === undefined) {
|
|
113
|
+
ref = (node: HTMLElement | null): void => {
|
|
114
|
+
if (node === null) slots.current.delete(priority);
|
|
115
|
+
else slots.current.set(priority, node);
|
|
116
|
+
settle();
|
|
117
|
+
};
|
|
118
|
+
refs.current.set(priority, ref);
|
|
119
|
+
}
|
|
120
|
+
return ref;
|
|
121
|
+
},
|
|
122
|
+
[settle]
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
portable: container.current !== null,
|
|
127
|
+
render: (cluster: ReactNode): ReactNode =>
|
|
128
|
+
container.current === null ? null : createPortal(cluster, container.current),
|
|
129
|
+
slot: (priority: number, name: string): ReactElement => (
|
|
130
|
+
<div
|
|
131
|
+
ref={refFor(priority)}
|
|
132
|
+
style={CONTENTS}
|
|
133
|
+
data-listings-cluster-slot={name}
|
|
134
|
+
/>
|
|
135
|
+
),
|
|
136
|
+
};
|
|
137
|
+
}
|