@stapel/listings-react 0.23.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/README.md +56 -0
  3. package/dist/api/generated/schema.d.ts +119 -6
  4. package/dist/api/generated/schema.d.ts.map +1 -1
  5. package/dist/api/types.d.ts +46 -3
  6. package/dist/api/types.d.ts.map +1 -1
  7. package/dist/api/types.js.map +1 -1
  8. package/dist/default/CardBadges.d.ts +47 -0
  9. package/dist/default/CardBadges.d.ts.map +1 -0
  10. package/dist/default/CardBadges.js +38 -0
  11. package/dist/default/CardBadges.js.map +1 -0
  12. package/dist/default/ListingCard.d.ts.map +1 -1
  13. package/dist/default/ListingCard.js +6 -6
  14. package/dist/default/ListingCard.js.map +1 -1
  15. package/dist/default/ListingDetailPane.d.ts.map +1 -1
  16. package/dist/default/ListingDetailPane.js +12 -19
  17. package/dist/default/ListingDetailPane.js.map +1 -1
  18. package/dist/default/ListingPhoto.d.ts.map +1 -1
  19. package/dist/default/ListingPhoto.js +12 -8
  20. package/dist/default/ListingPhoto.js.map +1 -1
  21. package/dist/default/ListingSerpCard.d.ts.map +1 -1
  22. package/dist/default/ListingSerpCard.js +3 -5
  23. package/dist/default/ListingSerpCard.js.map +1 -1
  24. package/dist/default/ListingSpecList.d.ts +74 -0
  25. package/dist/default/ListingSpecList.d.ts.map +1 -0
  26. package/dist/default/ListingSpecList.js +90 -0
  27. package/dist/default/ListingSpecList.js.map +1 -0
  28. package/dist/default/cardGallery.d.ts +81 -0
  29. package/dist/default/cardGallery.d.ts.map +1 -0
  30. package/dist/default/cardGallery.js +266 -0
  31. package/dist/default/cardGallery.js.map +1 -0
  32. package/dist/default/index.d.ts +6 -0
  33. package/dist/default/index.d.ts.map +1 -1
  34. package/dist/default/index.js +5 -0
  35. package/dist/default/index.js.map +1 -1
  36. package/dist/i18n/es.d.ts.map +1 -1
  37. package/dist/i18n/es.js +1 -0
  38. package/dist/i18n/es.js.map +1 -1
  39. package/dist/i18n/generated/errors.es.gen.d.ts +1 -1
  40. package/dist/i18n/generated/errors.es.gen.js +1 -1
  41. package/dist/i18n/generated/errors.gen.d.ts +6 -0
  42. package/dist/i18n/generated/errors.gen.d.ts.map +1 -1
  43. package/dist/i18n/generated/errors.gen.js +3 -0
  44. package/dist/i18n/generated/errors.gen.js.map +1 -1
  45. package/dist/i18n/generated/errors.ru.gen.d.ts +1 -1
  46. package/dist/i18n/generated/errors.ru.gen.js +1 -1
  47. package/dist/i18n/ru.d.ts.map +1 -1
  48. package/dist/i18n/ru.js +3 -0
  49. package/dist/i18n/ru.js.map +1 -1
  50. package/dist/index.d.ts +3 -0
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +3 -0
  53. package/dist/index.js.map +1 -1
  54. package/dist/model/cardBadges.d.ts +134 -0
  55. package/dist/model/cardBadges.d.ts.map +1 -0
  56. package/dist/model/cardBadges.js +131 -0
  57. package/dist/model/cardBadges.js.map +1 -0
  58. package/dist/model/featureText.d.ts +63 -0
  59. package/dist/model/featureText.d.ts.map +1 -0
  60. package/dist/model/featureText.js +133 -0
  61. package/dist/model/featureText.js.map +1 -0
  62. package/dist/model/features.d.ts.map +1 -1
  63. package/dist/model/features.js +59 -0
  64. package/dist/model/features.js.map +1 -1
  65. package/llms.txt +5 -2
  66. package/manifest.json +47 -1
  67. package/nav-manifest.json +1 -1
  68. package/package.json +5 -5
  69. package/src/analytics/generated/events.json +1 -1
  70. package/src/api/generated/schema.ts +119 -6
  71. package/src/api/types.ts +55 -5
  72. package/src/default/CardBadges.tsx +105 -0
  73. package/src/default/ListingCard.tsx +7 -21
  74. package/src/default/ListingDetailPane.tsx +13 -37
  75. package/src/default/ListingPhoto.tsx +54 -26
  76. package/src/default/ListingSerpCard.tsx +10 -28
  77. package/src/default/ListingSpecList.tsx +195 -0
  78. package/src/default/cardGallery.ts +287 -0
  79. package/src/default/index.ts +22 -0
  80. package/src/i18n/es.ts +3 -0
  81. package/src/i18n/generated/errors.es.gen.ts +1 -1
  82. package/src/i18n/generated/errors.gen.ts +3 -0
  83. package/src/i18n/generated/errors.json +9 -0
  84. package/src/i18n/generated/errors.ru.gen.ts +1 -1
  85. package/src/i18n/ru.ts +5 -0
  86. package/src/index.ts +15 -0
  87. package/src/model/cardBadges.ts +237 -0
  88. package/src/model/featureText.ts +199 -0
  89. package/src/model/features.ts +60 -0
@@ -79,13 +79,8 @@ import { SkinTheme } from "@stapel/tokens-antd/skin";
79
79
  import type { SignInCta } from "@stapel/core";
80
80
  import { useT } from "@stapel/core";
81
81
  import { fontSize, spacing } from "@stapel/tokens";
82
- import { FeatureBadges } from "@stapel/attributes-react/default";
83
82
  import type { ListingCard as ListingCardData } from "../api/types.js";
84
- import {
85
- asFeatureDaoList,
86
- featuresDtoFromDaoList,
87
- featuresFromDaoList,
88
- } from "../model/features.js";
83
+ import { asFeatureDaoList } from "../model/features.js";
89
84
  import type { FeatureCopySource } from "../model/features.js";
90
85
  import { lifecycleCaption } from "../model/status.js";
91
86
  import { isListingViewed } from "../model/engagement.js";
@@ -93,6 +88,7 @@ import { useEngagedListing } from "../headless/Engagement.js";
93
88
  import { LISTINGS_I18N_KEYS } from "../i18n/keys.js";
94
89
  import { PriceTrendIcon } from "./icons.js";
95
90
  import { FavoriteHeart } from "./favorite.js";
91
+ import { CardBadges, CardSpecLine } from "./CardBadges.js";
96
92
  import {
97
93
  CARD_FRAME_CLASS,
98
94
  CARD_MAIN_CLASS,
@@ -188,8 +184,6 @@ export function ListingSerpCard(props: ListingSerpCardProps): ReactElement {
188
184
  props.categoryFeatures !== undefined
189
185
  ? { categoryFeatures: props.categoryFeatures }
190
186
  : {};
191
- const badgeFeatures = featuresFromDaoList(badgeDaos, copy);
192
- const badgeValues = featuresDtoFromDaoList(badgeDaos);
193
187
  // The fallback spec line when the host derived none: the row's own
194
188
  // `features_title` projection, exactly the line `ListingCard` draws.
195
189
  const titleDaos =
@@ -346,27 +340,15 @@ export function ListingSerpCard(props: ListingSerpCardProps): ReactElement {
346
340
  >
347
341
  {props.specsLine}
348
342
  </Typography.Text>
349
- ) : titleDaos.length > 0 ? (
350
- <Typography.Text
351
- type="secondary"
352
- ellipsis
353
- data-testid="listings-serp-specs"
354
- >
355
- <FeatureBadges
356
- features={featuresFromDaoList(titleDaos, copy).map(
357
- (view) => view.feature,
358
- )}
359
- values={featuresDtoFromDaoList(titleDaos)}
360
- />
361
- </Typography.Text>
362
- ) : null}
363
-
364
- {badgeFeatures.length > 0 ? (
365
- <FeatureBadges
366
- features={badgeFeatures.map((view) => view.feature)}
367
- values={badgeValues}
343
+ ) : (
344
+ <CardSpecLine
345
+ rows={titleDaos}
346
+ copy={copy}
347
+ testId="listings-serp-specs"
368
348
  />
369
- ) : null}
349
+ )}
350
+
351
+ <CardBadges rows={badgeDaos} copy={copy} variant="badges" />
370
352
  </CardTarget>
371
353
 
372
354
  {/* Outside the anchor, both of them: a seller line usually holds
@@ -0,0 +1,195 @@
1
+ /**
2
+ * The listing page's spec rows ("Characteristics"), as SENTENCES.
3
+ *
4
+ * ── What was on screen, and why a table was the wrong shape ───────────────
5
+ *
6
+ * The list was `<Descriptions column={1}>`: a real two-column table, label
7
+ * cell beside value cell. On a phone — and in the split layout's half-width
8
+ * left column — the value cell is narrow, so a long answer ("Trim level",
9
+ * a full trim name, a two-line address) wrapped INSIDE it and stacked under
10
+ * itself in a column a third of the page wide, beside acres of empty label
11
+ * gutter. A spec row is not tabular data that a reader scans down one axis;
12
+ * it is a short question and its answer, and it reads as a line of text.
13
+ *
14
+ * So the label is an inline `<span>`, muted, and the value follows it in the
15
+ * SAME text flow. A long value now wraps as a paragraph — full measure,
16
+ * hanging under the label — and a short one costs one line instead of a row
17
+ * of a table.
18
+ *
19
+ * ── The two-column grid that survives is a grid of ROWS ───────────────────
20
+ *
21
+ * The split layout still puts two columns of spec rows side by side on a wide
22
+ * screen, because a forty-row list under a photograph is a scroll nobody
23
+ * finishes. What is gone is the label being its own COLUMN: the columns hold
24
+ * whole rows, cut by row count so the category's declaration order still
25
+ * reads top-to-bottom, left column first. `<ListingSpecColumns>` is that cut,
26
+ * kept here beside the row it cuts.
27
+ *
28
+ * ── Units and digits ─────────────────────────────────────────────────────
29
+ *
30
+ * Every value goes through `formatSpecValue` rather than the shared
31
+ * `formatFeatureValue`: same answer, typeset — the unit appended and the
32
+ * digits grouped by the reader's locale. `model/featureText.ts` says where
33
+ * the unit comes from and why there is no `unit` key to read it from.
34
+ */
35
+ import type { CSSProperties, ReactElement } from "react";
36
+ import { Typography, theme as antdTheme } from "antd";
37
+ import { SkinTheme } from "@stapel/tokens-antd/skin";
38
+ import { useI18n, useT } from "@stapel/core";
39
+ import { spacing } from "@stapel/tokens";
40
+ import {
41
+ ATTRIBUTES_I18N_KEYS,
42
+ featureName,
43
+ featureType,
44
+ isRedactedValue,
45
+ isValuePresent,
46
+ isValueVerified,
47
+ } from "@stapel/attributes-react";
48
+ import type { FeatureDef, FeatureValueDto } from "@stapel/attributes-react";
49
+ import { formatSpecValue } from "../model/featureText.js";
50
+
51
+ /** The class one spec row carries. */
52
+ export const SPEC_ROW_CLASS = "stapel-listing-spec-row";
53
+ /** The class the row's inline label carries. */
54
+ export const SPEC_LABEL_CLASS = "stapel-listing-spec-label";
55
+ /** The `href` the hoisted spec stylesheet is deduplicated by. */
56
+ export const SPEC_STYLE_HREF = "stapel-listings-spec";
57
+
58
+ /**
59
+ * The rules an inline style cannot express — the label's own colour is set
60
+ * per-instance as a custom property so ONE hoisted copy serves either theme.
61
+ *
62
+ * `display: inline` on the label is the whole fix and is stated rather than
63
+ * inherited: antd's `<Text>` renders a `<span>`, but a skin that retunes it
64
+ * to a block would silently put the table back.
65
+ */
66
+ export function specListCss(): string {
67
+ return [
68
+ // A paragraph, not a table row. `margin: 0` because the gap between rows
69
+ // is the list's, so a row can be lifted into a grid cell unchanged.
70
+ `.${SPEC_ROW_CLASS}{margin:0;min-inline-size:0;overflow-wrap:anywhere}`,
71
+ `.${SPEC_LABEL_CLASS}{display:inline;color:var(--listing-spec-label)}`,
72
+ // The one space between the question and the answer, owned by the label
73
+ // rather than written as a text node — a `{" "}` between two JSX elements
74
+ // is the kind of whitespace a formatter deletes.
75
+ `.${SPEC_LABEL_CLASS}::after{content:"\\00a0"}`,
76
+ ].join("");
77
+ }
78
+
79
+ export interface ListingSpecListProps {
80
+ /** The category's features, in the order they are declared. */
81
+ readonly features: readonly FeatureDef[];
82
+ /** The DISPLAY envelope — redacted stubs included, which is what makes a
83
+ * withheld row keep its place. */
84
+ readonly values: Readonly<Record<string, FeatureValueDto>>;
85
+ /** The surface's own test id, so a split page holding two columns of these
86
+ * does not hand a test two elements under one name. */
87
+ readonly testId?: string;
88
+ readonly style?: CSSProperties;
89
+ }
90
+
91
+ /**
92
+ * A withheld value's row: what the system OBSERVED, and nothing more — the
93
+ * same three states `@stapel/attributes-react` prints, said with its own
94
+ * copy keys so the two lists cannot drift into two different sentences.
95
+ */
96
+ function redactedText(dto: FeatureValueDto | undefined, t: (key: string) => string): string {
97
+ if (!isValuePresent(dto)) return t(ATTRIBUTES_I18N_KEYS.valueNotSet);
98
+ if (isValueVerified(dto)) return t(ATTRIBUTES_I18N_KEYS.valueVerified);
99
+ return t(ATTRIBUTES_I18N_KEYS.valueProvided);
100
+ }
101
+
102
+ export function ListingSpecList(props: ListingSpecListProps): ReactElement {
103
+ const t = useT();
104
+ const { locale } = useI18n();
105
+ const { token } = antdTheme.useToken();
106
+
107
+ // A `header` is a section caption in a FORM, not a value: it has none, and
108
+ // a spec table that printed one would print "not specified" under it.
109
+ const rows = props.features.filter((feature) => featureType(feature) !== "header");
110
+
111
+ return (
112
+ <SkinTheme surface="bare">
113
+ <style href={SPEC_STYLE_HREF} precedence="default">
114
+ {specListCss()}
115
+ </style>
116
+ <div
117
+ data-testid={props.testId ?? "listings-spec-list"}
118
+ style={{
119
+ display: "flex",
120
+ flexDirection: "column",
121
+ gap: spacing[1],
122
+ minWidth: 0,
123
+ ["--listing-spec-label" as string]: token.colorTextSecondary,
124
+ ...props.style,
125
+ }}
126
+ >
127
+ {rows.map((feature) => {
128
+ const dto = props.values[feature.slug];
129
+ const redacted = isRedactedValue(dto);
130
+ const text = redacted
131
+ ? redactedText(dto, t)
132
+ : (formatSpecValue(feature, dto, { t, locale }) ??
133
+ t(
134
+ dto === undefined || featureType(feature) === undefined
135
+ ? ATTRIBUTES_I18N_KEYS.valueNotSet
136
+ : ATTRIBUTES_I18N_KEYS.valueUnreadable
137
+ ));
138
+ return (
139
+ <p
140
+ key={feature.slug}
141
+ className={SPEC_ROW_CLASS}
142
+ data-testid={`listings-spec-row-${feature.slug}`}
143
+ >
144
+ <Typography.Text
145
+ type="secondary"
146
+ className={SPEC_LABEL_CLASS}
147
+ data-testid={`listings-spec-label-${feature.slug}`}
148
+ >
149
+ {featureName(feature)}
150
+ </Typography.Text>
151
+ <span data-testid={`listings-spec-value-${feature.slug}`}>{text}</span>
152
+ </p>
153
+ );
154
+ })}
155
+ </div>
156
+ </SkinTheme>
157
+ );
158
+ }
159
+
160
+ /**
161
+ * The same rows in TWO columns on a wide screen — a grid of whole rows, cut
162
+ * by row count so the category's declaration order still reads top-to-bottom,
163
+ * left column first.
164
+ *
165
+ * The cut is here rather than inside the list because a CSS `columns` rule
166
+ * would break a wrapped paragraph across the column boundary, which is
167
+ * exactly the defect the paragraph shape was adopted to avoid.
168
+ */
169
+ export function ListingSpecColumns(props: ListingSpecListProps): ReactElement {
170
+ const half = Math.ceil(props.features.length / 2);
171
+ return (
172
+ <div
173
+ data-testid={props.testId ?? "listings-detail-specs-split"}
174
+ style={{
175
+ display: "grid",
176
+ gridTemplateColumns: "repeat(2, minmax(0, 1fr))",
177
+ gap: spacing[4],
178
+ alignItems: "start",
179
+ }}
180
+ >
181
+ <ListingSpecList
182
+ features={props.features.slice(0, half)}
183
+ values={props.values}
184
+ testId="listings-spec-list"
185
+ />
186
+ {props.features.length > half ? (
187
+ <ListingSpecList
188
+ features={props.features.slice(half)}
189
+ values={props.values}
190
+ testId="listings-spec-list-second"
191
+ />
192
+ ) : null}
193
+ </div>
194
+ );
195
+ }
@@ -0,0 +1,287 @@
1
+ /**
2
+ * The card gallery's two gestures — the ones a classified is expected to have
3
+ * and this pair did not.
4
+ *
5
+ * ── Hover scrub, on a device that has a pointer ──────────────────────────
6
+ *
7
+ * A card with six photographs showed one, and the only way to the other five
8
+ * was to open the listing. Every mature classified answers this the same way:
9
+ * the media box is divided into N equal segments, and the segment the cursor
10
+ * is over IS the photograph on screen. Six photos become six glances and no
11
+ * clicks, and the pointer leaving puts the first photo back — the card must
12
+ * be in the same state after a hover as before one, or a grid of forty tiles
13
+ * becomes forty different tiles depending on where a cursor happened to pass.
14
+ *
15
+ * It is gated on `(hover: hover) and (pointer: fine)` and on a `mouse`
16
+ * pointer type, both, and the two gates are not redundant: the media query
17
+ * says the DEVICE has a real pointer, the pointer type says THIS gesture came
18
+ * from it. A touch laptop answers `hover: hover` and still delivers finger
19
+ * events, and a scrub driven by a finger dragging across the box is the
20
+ * gesture below wearing the wrong costume.
21
+ *
22
+ * ── Swipe, on a device that does not ─────────────────────────────────────
23
+ *
24
+ * A finger gets the same six photographs by swiping horizontally, one photo
25
+ * per swipe, in either direction.
26
+ *
27
+ * The rule that matters is the one about the OTHER axis: a card is a small
28
+ * box inside a long scrolling feed, and a gesture layer that treats every
29
+ * touch as its own turns the page into something that will not scroll. So
30
+ * the strip declares `touch-action: pan-y` — the browser keeps the vertical
31
+ * axis, unconditionally, and can never be argued out of it — and this hook
32
+ * only acts on a drag that has declared horizontal INTENT: past
33
+ * {@link SWIPE_MIN_PX}, and further across than down by
34
+ * {@link SWIPE_AXIS_RATIO}. A diagonal thumb scrolling the feed changes no
35
+ * photograph.
36
+ *
37
+ * ── What neither gesture touches ─────────────────────────────────────────
38
+ *
39
+ * The keyboard, and the card's single link target. The strip underneath is
40
+ * still `<SkinCarousel>`: a real scroll container, a tab stop, arrow-key
41
+ * scrollable, with the slides in the document and its own dots reporting the
42
+ * position. Both gestures below work by SCROLLING it — they set no state the
43
+ * strip does not already publish — so what a keyboard reaches, what a screen
44
+ * reader reads and what the dots say are unchanged, and the card stays one
45
+ * anchor with one accessible name.
46
+ */
47
+ import { useCallback, useEffect, useRef, useState } from "react";
48
+ import type { PointerEvent as ReactPointerEvent, RefObject } from "react";
49
+
50
+ /** The class the gallery's own box carries — see {@link cardGalleryCss}. */
51
+ export const CARD_GALLERY_CLASS = "stapel-listing-gallery";
52
+ /** The `href` the hoisted gallery stylesheet is deduplicated by. */
53
+ export const CARD_GALLERY_STYLE_HREF = "stapel-listings-card-gallery";
54
+
55
+ /** The environment a hover scrub is allowed in, and the only one. */
56
+ export const SCRUB_MEDIA = "(hover: hover) and (pointer: fine)";
57
+
58
+ /**
59
+ * How far a finger travels before it has said "photo", in CSS pixels.
60
+ *
61
+ * Under this, a drag is a tap that wobbled — and a tap on a card is a
62
+ * navigation, so a low threshold does not change a photograph, it changes one
63
+ * and then leaves the listing.
64
+ */
65
+ export const SWIPE_MIN_PX = 32;
66
+
67
+ /**
68
+ * How much more horizontal than vertical a drag must be to count.
69
+ *
70
+ * 1.2 rather than 1: a thumb scrolling a feed travels a few degrees off
71
+ * vertical, and a bare `|dx| > |dy|` comparison hands the gesture to the
72
+ * gallery on the first pixel where the wobble wins.
73
+ */
74
+ export const SWIPE_AXIS_RATIO = 1.2;
75
+
76
+ /**
77
+ * Which of `count` equal segments the pointer is over.
78
+ *
79
+ * Clamped at both ends: `offsetX` can be reported one pixel past the box's
80
+ * own width, and an index of `count` is a photograph that does not exist.
81
+ */
82
+ export function segmentIndex(offsetX: number, width: number, count: number): number {
83
+ if (count <= 1 || width <= 0) return 0;
84
+ const raw = Math.floor((offsetX / width) * count);
85
+ return Math.min(count - 1, Math.max(0, raw));
86
+ }
87
+
88
+ /**
89
+ * A drag → the number of photographs it asks for: `1` forward, `-1` back, `0`
90
+ * for a drag that has not declared horizontal intent.
91
+ *
92
+ * Dragging LEFT advances, the direction the content moves under the finger —
93
+ * the same mapping the native scroller has.
94
+ */
95
+ export function swipeStep(dx: number, dy: number): -1 | 0 | 1 {
96
+ const across = Math.abs(dx);
97
+ if (across < SWIPE_MIN_PX) return 0;
98
+ if (across <= Math.abs(dy) * SWIPE_AXIS_RATIO) return 0;
99
+ return dx < 0 ? 1 : -1;
100
+ }
101
+
102
+ /** Does this environment have a real pointer? `false` where there is no
103
+ * `matchMedia` to ask (a server render, an old jsdom), which is the safe
104
+ * side: a scrub that does not happen costs a hover, a scrub on a phone is a
105
+ * photograph that changes when nobody touched it. */
106
+ export function hasFinePointer(): boolean {
107
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") return false;
108
+ try {
109
+ return window.matchMedia(SCRUB_MEDIA).matches;
110
+ } catch {
111
+ return false;
112
+ }
113
+ }
114
+
115
+ /**
116
+ * {@link hasFinePointer}, as state.
117
+ *
118
+ * It opens `false` and settles in an effect rather than reading the media
119
+ * query during render: a server render has no `matchMedia`, and a first
120
+ * client render that disagreed with it is a hydration mismatch on every card
121
+ * on the page. Nothing is drawn differently either way — the flag only gates
122
+ * a gesture — so the one frame it costs is invisible.
123
+ */
124
+ export function useFinePointer(): boolean {
125
+ const [fine, setFine] = useState(false);
126
+ useEffect(() => {
127
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") return;
128
+ let query: MediaQueryList;
129
+ try {
130
+ query = window.matchMedia(SCRUB_MEDIA);
131
+ } catch {
132
+ return;
133
+ }
134
+ setFine(query.matches);
135
+ const onChange = (event: MediaQueryListEvent): void => {
136
+ setFine(event.matches);
137
+ };
138
+ // `addEventListener` is the modern spelling; Safari < 14 has only
139
+ // `addListener`, and a card grid that throws on mount there is worse than
140
+ // one that never notices a device changing its pointer.
141
+ if (typeof query.addEventListener === "function") {
142
+ query.addEventListener("change", onChange);
143
+ return () => {
144
+ query.removeEventListener("change", onChange);
145
+ };
146
+ }
147
+ return;
148
+ }, []);
149
+ return fine;
150
+ }
151
+
152
+ /** The handlers and the box reference a gallery hands its media well. */
153
+ export interface CardGallery {
154
+ readonly ref: RefObject<HTMLDivElement | null>;
155
+ /** The photograph currently on screen. */
156
+ readonly active: number;
157
+ /** True while a pointer is scrubbing — the box publishes it so the strip's
158
+ * smooth-scroll can be switched off for the duration. */
159
+ readonly scrubbing: boolean;
160
+ readonly onPointerMove: (event: ReactPointerEvent<HTMLDivElement>) => void;
161
+ readonly onPointerDown: (event: ReactPointerEvent<HTMLDivElement>) => void;
162
+ readonly onPointerUp: (event: ReactPointerEvent<HTMLDivElement>) => void;
163
+ readonly onPointerCancel: (event: ReactPointerEvent<HTMLDivElement>) => void;
164
+ readonly onPointerLeave: (event: ReactPointerEvent<HTMLDivElement>) => void;
165
+ }
166
+
167
+ /** Scroll the strip inside `box` so that slide `index` is at its leading
168
+ * edge. Rectangles rather than `scrollLeft / slideWidth`, for the reason
169
+ * `SkinCarousel`'s own `nearestSlideIndex` gives: the arithmetic version has
170
+ * to know the gap, the peek and the writing direction. */
171
+ function showSlide(box: HTMLElement, index: number, instant: boolean): void {
172
+ const strip = box.querySelector<HTMLElement>("[data-stapel-carousel-strip]");
173
+ if (strip === null) return;
174
+ const slide = strip.children.item(index);
175
+ if (slide === null) return;
176
+ const left =
177
+ slide.getBoundingClientRect().left - strip.getBoundingClientRect().left + strip.scrollLeft;
178
+ if (typeof strip.scrollTo === "function") {
179
+ strip.scrollTo({ left, behavior: instant ? "auto" : "smooth" });
180
+ } else {
181
+ strip.scrollLeft = left;
182
+ }
183
+ }
184
+
185
+ /**
186
+ * The gallery gestures for a media well holding `count` photographs.
187
+ *
188
+ * A well with one photograph gets an inert bag: every handler returns
189
+ * immediately, so a grid of forty single-photo tiles pays for nothing.
190
+ */
191
+ export function useCardGallery(count: number): CardGallery {
192
+ const ref = useRef<HTMLDivElement | null>(null);
193
+ const [active, setActive] = useState(0);
194
+ const [scrubbing, setScrubbing] = useState(false);
195
+ // The origin of the drag in progress, or `null`. A ref rather than state:
196
+ // it changes on every move and no render depends on it.
197
+ const origin = useRef<{ x: number; y: number } | null>(null);
198
+ const fine = useFinePointer();
199
+ const many = count > 1;
200
+
201
+ // The one place the strip is driven. `active` is the whole state of both
202
+ // gestures, so neither handler talks to the DOM.
203
+ useEffect(() => {
204
+ const box = ref.current;
205
+ if (box === null || !many) return;
206
+ showSlide(box, active, scrubbing);
207
+ }, [active, scrubbing, many]);
208
+
209
+ const onPointerMove = useCallback(
210
+ (event: ReactPointerEvent<HTMLDivElement>): void => {
211
+ if (!many) return;
212
+ if (event.pointerType === "mouse") {
213
+ if (!fine) return;
214
+ const box = ref.current;
215
+ if (box === null) return;
216
+ const rect = box.getBoundingClientRect();
217
+ setScrubbing(true);
218
+ setActive(segmentIndex(event.clientX - rect.left, rect.width, count));
219
+ return;
220
+ }
221
+ const from = origin.current;
222
+ if (from === null) return;
223
+ const step = swipeStep(event.clientX - from.x, event.clientY - from.y);
224
+ if (step === 0) return;
225
+ // The origin moves with the commit, so a long drag walks the strip one
226
+ // photograph per threshold rather than one per gesture.
227
+ origin.current = { x: event.clientX, y: event.clientY };
228
+ setScrubbing(false);
229
+ setActive((current) => Math.min(count - 1, Math.max(0, current + step)));
230
+ },
231
+ [count, fine, many]
232
+ );
233
+
234
+ const onPointerDown = useCallback(
235
+ (event: ReactPointerEvent<HTMLDivElement>): void => {
236
+ if (!many || event.pointerType === "mouse") return;
237
+ origin.current = { x: event.clientX, y: event.clientY };
238
+ },
239
+ [many]
240
+ );
241
+
242
+ const endDrag = useCallback((): void => {
243
+ origin.current = null;
244
+ }, []);
245
+
246
+ const onPointerLeave = useCallback((): void => {
247
+ origin.current = null;
248
+ if (!many) return;
249
+ // The card goes back to the photograph it was drawn with. A hover is a
250
+ // look, not an edit.
251
+ setScrubbing(false);
252
+ setActive(0);
253
+ }, [many]);
254
+
255
+ return {
256
+ ref,
257
+ active,
258
+ scrubbing,
259
+ onPointerMove,
260
+ onPointerDown,
261
+ onPointerUp: endDrag,
262
+ onPointerCancel: endDrag,
263
+ onPointerLeave,
264
+ };
265
+ }
266
+
267
+ /**
268
+ * The rules an inline style cannot reach: they apply to the STRIP inside the
269
+ * carousel, which this package renders through a component and does not hold
270
+ * a handle on.
271
+ */
272
+ export function cardGalleryCss(): string {
273
+ const box = `.${CARD_GALLERY_CLASS}`;
274
+ return [
275
+ // THE VERTICAL AXIS IS THE BROWSER'S, and is not negotiable: a card is a
276
+ // small box in a long feed, and the one unacceptable outcome of a gallery
277
+ // gesture is a page that will not scroll. `pan-y` says so at the platform
278
+ // level, where no handler can argue with it, and takes the horizontal
279
+ // axis for the swipe above.
280
+ `${box} [data-stapel-carousel-strip]{touch-action:pan-y}`,
281
+ // A per-pixel scrub must not animate: the strip's own `scroll-behavior:
282
+ // smooth` is right for a swipe committing one photograph and turns a
283
+ // cursor sweep into a queue of easing curves finishing after the pointer
284
+ // has left.
285
+ `${box}[data-scrubbing="true"] [data-stapel-carousel-strip]{scroll-behavior:auto}`,
286
+ ].join("");
287
+ }
@@ -104,6 +104,28 @@ export {
104
104
  LISTING_PHOTO_ASPECT,
105
105
  } from "./ListingPhoto.js";
106
106
  export type { ListingPhotoProps } from "./ListingPhoto.js";
107
+
108
+ // ── the listing page's characteristics, and a card's badge line ──────────────
109
+ export {
110
+ ListingSpecColumns,
111
+ ListingSpecList,
112
+ specListCss,
113
+ } from "./ListingSpecList.js";
114
+ export type { ListingSpecListProps } from "./ListingSpecList.js";
115
+ export { CardBadges, CardSpecLine } from "./CardBadges.js";
116
+ export type { CardBadgesProps } from "./CardBadges.js";
117
+
118
+ // ── the card gallery's two gestures ─────────────────────────────────────────
119
+ export {
120
+ SWIPE_AXIS_RATIO,
121
+ SWIPE_MIN_PX,
122
+ cardGalleryCss,
123
+ hasFinePointer,
124
+ segmentIndex,
125
+ swipeStep,
126
+ useCardGallery,
127
+ } from "./cardGallery.js";
128
+ export type { CardGallery } from "./cardGallery.js";
107
129
  export { SignInLink } from "./SignInLink.js";
108
130
  export type { SignInLinkProps } from "./SignInLink.js";
109
131
  export type { CategoryFeaturesProp, ThemeModeProp } from "./types.js";
package/src/i18n/es.ts CHANGED
@@ -219,6 +219,9 @@ export const listingsI18nBundleEs: I18nDictionary = {
219
219
  "error.400.listing_zero_price_not_allowed":
220
220
  "En esta categoría no se permite un precio de 0. Deja el precio vacío para «precio no indicado».",
221
221
 
222
+ "error.400.listing_draft_meta_too_large":
223
+ "El borrador es demasiado grande (máximo {max_bytes} bytes). Quita parte de los datos y guarda de nuevo.",
224
+
222
225
  "listings.blocked.sign_in": "Inicia sesión para hacer esto",
223
226
  "listings.blocked.guest":
224
227
  "Esta cuenta todavía no puede hacerlo — termina de configurarla primero",
@@ -8,7 +8,7 @@ import type { ListingsErrorCode } from "./errors.gen.js";
8
8
  /**
9
9
  * `es` texts for the backend error codes this catalog carries.
10
10
  *
11
- * PARTIAL, and deliberately typed to say so: 26 key(s) owned by
11
+ * PARTIAL, and deliberately typed to say so: 27 key(s) owned by
12
12
  * stapel_attributes, stapel_listings are absent, because that owner ships no locale catalog
13
13
  * (ERRORS_LOCALE_EXEMPT_OWNERS). English for them still comes from the registry
14
14
  * artifact via the en bundle; the pair layers its own authored `es`
@@ -66,6 +66,7 @@ export const LISTINGS_ERRORS = {
66
66
  "error.400.field.unique": { status: 400, params: ["field"], remediation: "fix_input", en: "{field} must be unique" },
67
67
  "error.400.image_required": { status: 400, params: [], remediation: "fix_input", en: "At least one image is required to publish" },
68
68
  "error.400.invalid_ad_id": { status: 400, params: [], remediation: "fix_input", en: "Invalid advertisement ID" },
69
+ "error.400.listing_draft_meta_too_large": { status: 400, params: ["max_bytes"], remediation: "fix_input", en: "draft_meta is too large ({max_bytes} bytes max)" },
69
70
  "error.400.listing_feature_not_allowed": { status: 400, params: ["feature"], remediation: "fix_input", en: "Feature '{feature}' is not allowed for this category" },
70
71
  "error.400.listing_invalid_status_filter": { status: 400, params: ["status"], remediation: "fix_input", en: "Unknown listing status '{status}'" },
71
72
  "error.400.listing_location_required": { status: 400, params: [], remediation: "fix_input", en: "Choose where the item is before publishing" },
@@ -140,6 +141,7 @@ export const LISTINGS_ERROR_CODES: readonly ListingsErrorCode[] = [
140
141
  "error.400.field.unique",
141
142
  "error.400.image_required",
142
143
  "error.400.invalid_ad_id",
144
+ "error.400.listing_draft_meta_too_large",
143
145
  "error.400.listing_feature_not_allowed",
144
146
  "error.400.listing_invalid_status_filter",
145
147
  "error.400.listing_location_required",
@@ -216,6 +218,7 @@ export const listingsErrorBundleEn: Record<ListingsErrorCode, string> = {
216
218
  "error.400.field.unique": "{field} must be unique",
217
219
  "error.400.image_required": "At least one image is required to publish",
218
220
  "error.400.invalid_ad_id": "Invalid advertisement ID",
221
+ "error.400.listing_draft_meta_too_large": "draft_meta is too large ({max_bytes} bytes max)",
219
222
  "error.400.listing_feature_not_allowed": "Feature '{feature}' is not allowed for this category",
220
223
  "error.400.listing_invalid_status_filter": "Unknown listing status '{status}'",
221
224
  "error.400.listing_location_required": "Choose where the item is before publishing",
@@ -268,6 +268,15 @@
268
268
  "remediation": "fix_input",
269
269
  "en": "Invalid advertisement ID"
270
270
  },
271
+ {
272
+ "code": "error.400.listing_draft_meta_too_large",
273
+ "status": 400,
274
+ "params": [
275
+ "max_bytes"
276
+ ],
277
+ "remediation": "fix_input",
278
+ "en": "draft_meta is too large ({max_bytes} bytes max)"
279
+ },
271
280
  {
272
281
  "code": "error.400.listing_feature_not_allowed",
273
282
  "status": 400,
@@ -8,7 +8,7 @@ import type { ListingsErrorCode } from "./errors.gen.js";
8
8
  /**
9
9
  * `ru` texts for the backend error codes this catalog carries.
10
10
  *
11
- * PARTIAL, and deliberately typed to say so: 26 key(s) owned by
11
+ * PARTIAL, and deliberately typed to say so: 27 key(s) owned by
12
12
  * stapel_attributes, stapel_listings are absent, because that owner ships no locale catalog
13
13
  * (ERRORS_LOCALE_EXEMPT_OWNERS). English for them still comes from the registry
14
14
  * artifact via the en bundle; the pair layers its own authored `ru`
package/src/i18n/ru.ts CHANGED
@@ -244,6 +244,11 @@ export const listingsI18nBundleRu: I18nDictionary = {
244
244
  "error.400.listing_zero_price_not_allowed":
245
245
  "В этой категории цена 0 недопустима. Оставьте поле пустым — это и есть «цена не указана».",
246
246
 
247
+ // stapel-listings 0.21.2: the composer's per-field provenance sidecar has a
248
+ // size ceiling, and the number is the server's own — never restated here.
249
+ "error.400.listing_draft_meta_too_large":
250
+ "Черновик слишком большой (не больше {max_bytes} байт). Уберите часть данных и сохраните ещё раз.",
251
+
247
252
  "listings.blocked.sign_in": "Войдите, чтобы сделать это",
248
253
  "listings.blocked.guest":
249
254
  "Этот аккаунт пока так не может — сначала завершите настройку",