@wix/himalaya-cli 0.1783.0 → 0.1785.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/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/builder.d.ts +3 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/l10n-strings.d.ts +8 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +8 -3
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +3 -3
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +3 -3
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{ef0d32c6770cbe9b695a3774a00fc3da19cd4f8655784f5cd935938054a34541.bin → bd05b082ca023da46cfeef63687d1ddc10eaed1a03e86c7671ca821954222066.bin} +1 -1
- package/dist/browser-plane/sw.js +1 -1
- package/dist/cli.mjs +484 -330
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/component-reference.json +2 -2
- package/guides/component-reference.md +8 -3
- package/guides/himi-test.md +16 -1
- package/guides/image-preview.md +2 -0
- package/guides/push-cli-onboarding.md +1 -1
- package/guides/store-submission.md +2 -0
- package/package.json +10 -10
- package/templates/beauty-salon/l10n/en.json +1 -1
- package/templates/beauty-salon/tokens.json +8 -1
- package/templates/branded-lite/config.ts +2 -0
- package/templates/branded-lite/dev/index.ts +1249 -2307
- package/templates/branded-lite/l10n/ar.json +87 -28
- package/templates/branded-lite/l10n/cs.json +87 -28
- package/templates/branded-lite/l10n/da.json +87 -28
- package/templates/branded-lite/l10n/de.json +87 -28
- package/templates/branded-lite/l10n/el.json +87 -28
- package/templates/branded-lite/l10n/en.json +52 -34
- package/templates/branded-lite/l10n/es.json +87 -28
- package/templates/branded-lite/l10n/fi.json +87 -28
- package/templates/branded-lite/l10n/fr.json +87 -28
- package/templates/branded-lite/l10n/he.json +71 -23
- package/templates/branded-lite/l10n/hu.json +87 -28
- package/templates/branded-lite/l10n/id.json +87 -28
- package/templates/branded-lite/l10n/it.json +87 -28
- package/templates/branded-lite/l10n/ja.json +87 -28
- package/templates/branded-lite/l10n/ko.json +87 -28
- package/templates/branded-lite/l10n/lt.json +87 -28
- package/templates/branded-lite/l10n/nl.json +87 -28
- package/templates/branded-lite/l10n/no.json +87 -28
- package/templates/branded-lite/l10n/pl.json +87 -28
- package/templates/branded-lite/l10n/pt.json +87 -28
- package/templates/branded-lite/l10n/ru.json +87 -28
- package/templates/branded-lite/l10n/sv.json +87 -28
- package/templates/branded-lite/l10n/th.json +87 -28
- package/templates/branded-lite/l10n/tr.json +87 -28
- package/templates/branded-lite/l10n/uk.json +87 -28
- package/templates/branded-lite/l10n/vi.json +87 -28
- package/templates/branded-lite/l10n/zh.json +87 -28
- package/templates/branded-lite/tier5-src/_shared/wix-member-links.ts +2 -2
- package/templates/branded-lite/tier5-src/himi-branded-lite-galleries/index.ts +423 -117
- package/templates/branded-lite/tokens.json +3 -1
- package/templates/brandy/tier5-src/_shared/wix-member-links.ts +2 -2
- package/templates/community-club/l10n/en.json +1 -1
- package/templates/community-club/tokens.json +8 -1
- package/templates/events-meetups/l10n/en.json +1 -1
- package/templates/events-meetups/tokens.json +8 -1
- package/templates/fitness-gym/tier5-src/_shared/wix-member-links.ts +2 -2
- package/templates/gym-fitness/l10n/en.json +1 -1
- package/templates/gym-fitness/tokens.json +8 -1
- package/templates/medical-services/tier5-src/_shared/wix-member-links.ts +2 -2
- package/templates/nonprofit-cause/l10n/en.json +1 -1
- package/templates/nonprofit-cause/tokens.json +8 -1
- package/templates/podcast-creator/l10n/en.json +1 -1
- package/templates/podcast-creator/tokens.json +8 -1
- package/templates/portfolio-creative/l10n/en.json +1 -1
- package/templates/portfolio-creative/tokens.json +8 -1
- package/templates/restaurant/l10n/en.json +1 -1
- package/templates/restaurant/tokens.json +8 -1
- package/templates/retail-store/l10n/en.json +1 -1
- package/templates/retail-store/tokens.json +8 -1
- package/templates/salon-spa/config.ts +1 -1
- package/templates/salon-spa/dev/index.ts +141 -12
- package/templates/salon-spa/tier5-src/himi-branded-lite-galleries/index.ts +423 -117
- package/templates/yoga-studio/l10n/en.json +1 -1
- package/templates/yoga-studio/tokens.json +8 -1
|
@@ -2,42 +2,70 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Published Gallery page photos are carried by site analyze in the descriptor and
|
|
4
4
|
// displayed without a Pro Gallery request. Sites with no page gallery use the Wix
|
|
5
|
-
// API gateway: the list takes each gallery's first
|
|
6
|
-
// gateway gallery reads its items. Failed reads remain errors;
|
|
7
|
-
// preview only.
|
|
5
|
+
// API gateway: the list takes each gallery's first 4 items as its card's photos, and
|
|
6
|
+
// opening a gateway gallery reads its items page by page. Failed reads remain errors;
|
|
7
|
+
// sample data is explicit preview only.
|
|
8
8
|
//
|
|
9
9
|
import { defineService } from "../_shared/collection-service.js";
|
|
10
10
|
import { get as getAppInfo } from "@himalaya/app-info";
|
|
11
|
-
import {
|
|
11
|
+
import { open as openUrl } from "@himalaya/open-url";
|
|
12
|
+
import { LOADING, loaded, loadFailed, samplesRequested, type LoadCopy, type LoadFlags } from "../_shared/branded-load-state.js";
|
|
12
13
|
import { isNotFoundError, presence, type PresenceFlags } from "../_shared/detail-presence.js";
|
|
13
14
|
import { wixMediaUrl } from "@himalaya/wix-media";
|
|
15
|
+
import { copyParam } from "../_shared/himi-copy.js";
|
|
14
16
|
|
|
15
17
|
const GALLERIES_PATH = "/progallery/v2/galleries";
|
|
16
18
|
const LEGACY_GALLERIES_URL =
|
|
17
|
-
"https://www.wix.com/_api/photography-one-app-viewer/galleries?itemsPerGallery=
|
|
18
|
-
const PAGE_SIZE = 10; //
|
|
19
|
-
const
|
|
19
|
+
"https://www.wix.com/_api/photography-one-app-viewer/galleries?itemsPerGallery=4&offset=0&limit=30&withHidden=false&useNew=true";
|
|
20
|
+
const PAGE_SIZE = 10; // ListGalleries' maximum `limit`.
|
|
21
|
+
const PREVIEW_ITEMS = 4; // A list card shows its gallery's first 4 items.
|
|
22
|
+
const ITEM_PAGE = 100; // GetGallery allows up to 200.
|
|
23
|
+
const GUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
20
24
|
|
|
21
25
|
type WixApi = { call: (m: string, p: string, b?: unknown, h?: Record<string, string>) => Promise<unknown> };
|
|
22
26
|
function wixApi(): WixApi | null {
|
|
23
27
|
return (globalThis as { himalaya?: { wixApi?: WixApi } }).himalaya?.wixApi ?? null;
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
interface RawItem {
|
|
30
|
+
interface RawItem {
|
|
31
|
+
id?: unknown; title?: unknown; description?: unknown; type?: unknown;
|
|
32
|
+
image?: { imageInfo?: unknown }; video?: { type?: unknown; videoInfo?: unknown }; link?: { url?: unknown; text?: unknown };
|
|
33
|
+
}
|
|
27
34
|
interface RawGallery { id: string; name?: string; totalItems?: number; totalItemsCount?: number; items?: RawItem[]; source?: "gateway" | "legacy" }
|
|
28
35
|
interface StaticGallery { id: string; title: string; photos: string[] }
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
type Origin = "gateway" | "legacy" | "page";
|
|
37
|
+
/** `source`/`origin`: which route listed the gallery. Only a GATEWAY gallery can be opened live by
|
|
38
|
+
* id — a legacy row's id (or a synthesized `gallery-<n>`) is unknown to the gateway. `source` is
|
|
39
|
+
* kept for apps that already bind it (salon-spa); a new tap passes `origin`, because the web host
|
|
40
|
+
* drops a `source` URL param as its own boot param. */
|
|
41
|
+
interface Row {
|
|
42
|
+
id: string; title: string; subtitle: string; name: string; description: string; image: string; noCover: boolean; hasCover: boolean;
|
|
43
|
+
source: Origin; origin: Origin; a11y: string;
|
|
44
|
+
photo1: string; photo2: string; photo3: string; photo4: string;
|
|
45
|
+
noPhoto1: boolean; noPhoto2: boolean; noPhoto3: boolean; noPhoto4: boolean;
|
|
46
|
+
hasPhoto1: boolean; hasPhoto2: boolean; hasPhoto3: boolean; hasPhoto4: boolean;
|
|
47
|
+
}
|
|
48
|
+
/** One gallery item. `title` is the spoken name (the item's title, else "<gallery>, photo n of m");
|
|
49
|
+
* `caption` is the item's own title only, for the built-in viewer — never invented. */
|
|
50
|
+
interface PhotoRow {
|
|
51
|
+
id: string; kind: "image" | "video" | "external"; url: string; title: string; caption: string; label: string;
|
|
52
|
+
description: string; width: number; height: number; videoUrl: string; poster: string; linkUrl: string; linkText: string;
|
|
53
|
+
notImage: boolean; notVideo: boolean; notExternal: boolean;
|
|
54
|
+
/** The item's place in the gallery, counting the items `photoRows` drops: what a link's `index` names. */
|
|
55
|
+
position: number;
|
|
56
|
+
}
|
|
33
57
|
interface S extends LoadFlags, PresenceFlags {
|
|
34
|
-
galleries: Row[]; emptyText: string;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
58
|
+
galleries: Row[]; emptyText: string; nextCursor: string; errorVariant: string; pageFailed: boolean; pageOk: boolean;
|
|
59
|
+
/** The gallery's own next-page flags: the host can run `load` on a gallery's worker, and that must not hide its Retry. */
|
|
60
|
+
photoPageFailed: boolean; photoPageOk: boolean;
|
|
61
|
+
galleryTitle: string; countText: string; photos: PhotoRow[]; noGallery: boolean; hasPhotos: boolean; photoCursor: string;
|
|
62
|
+
/** A cold link has no name until the read lands: its title skeleton shows meanwhile. */
|
|
63
|
+
noTitleSkeleton: boolean; hideNoPhotos: boolean;
|
|
64
|
+
// Photo page (`view`).
|
|
65
|
+
photoUrl: string; noPhotoImage: boolean; photoTitle: string; photoSubtitle: string; photoDescription: string; photoCaption: string; photoLabel: string;
|
|
66
|
+
linkUrl: string; linkText: string; noLink: boolean; noSubtitle: boolean; noDescription: boolean;
|
|
67
|
+
galleryId: string; noGalleryLink: boolean; hasPhoto: boolean; noPhoto: boolean;
|
|
68
|
+
isMock: boolean; notMock: boolean; notMockEmpty: boolean; notMockUnavailable: boolean;
|
|
41
69
|
}
|
|
42
70
|
|
|
43
71
|
function input(key: string): string {
|
|
@@ -45,6 +73,11 @@ function input(key: string): string {
|
|
|
45
73
|
return typeof value === "string" ? value : "";
|
|
46
74
|
}
|
|
47
75
|
|
|
76
|
+
/** The shared copy seam: the provisioned override that onAppear's copy pack carries, else stock English. */
|
|
77
|
+
const copy = (key: string, fallback: string) => copyParam(key, fallback);
|
|
78
|
+
const fill = (template: string, vars: Record<string, string | number>) =>
|
|
79
|
+
template.replace(/\{(\w+)\}/g, (_, k: string) => String(vars[k] ?? ""));
|
|
80
|
+
|
|
48
81
|
function parseStaticGalleries(raw: unknown): StaticGallery[] {
|
|
49
82
|
const parsed: unknown = typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
50
83
|
if (parsed == null) return [];
|
|
@@ -64,7 +97,24 @@ function parseStaticGalleries(raw: unknown): StaticGallery[] {
|
|
|
64
97
|
let staticGalleries: StaticGallery[] = [];
|
|
65
98
|
/** The gateway gallery open on screen: each `open` counts up, and a read answers for its own. */
|
|
66
99
|
let openSeq = 0;
|
|
67
|
-
|
|
100
|
+
/** The galleries list: each `load` counts up, and a next page read before it is dropped. */
|
|
101
|
+
let listSeq = 0;
|
|
102
|
+
/** The photo page's read: on a pooled worker, a slower read for an earlier link never overwrites a later one. */
|
|
103
|
+
let viewSeq = 0;
|
|
104
|
+
/** The cursor whose next page is in flight: a second Retry tap, or the trigger with it, does not read the
|
|
105
|
+
* same page again. Keyed by cursor, so a stale read in flight never blocks a refreshed cursor's page. */
|
|
106
|
+
let listPaging = "";
|
|
107
|
+
let photoPaging = "";
|
|
108
|
+
/** A cursor carries the read it came from, so a refresh that lands on the same offset still publishes
|
|
109
|
+
* a new cursor and the renderer's load-more trigger, which pages once per cursor, can fire again. */
|
|
110
|
+
const tagCursor = (next: string, gen: number) => (next ? `${next}:${gen}` : "");
|
|
111
|
+
const cursorOffset = (cursor: string) => Number.parseInt(cursor, 10) || 0;
|
|
112
|
+
/** The read a cursor came from: a cursor from before a refresh pages nothing (the refresh publishes a new one). */
|
|
113
|
+
const cursorGen = (cursor: string) => Number(cursor.split(":")[1] ?? -1);
|
|
114
|
+
/** The same offset, now for read `gen`: a failed refresh keeps the rows, and their next page must stay reachable. */
|
|
115
|
+
const retagCursor = (cursor: string, gen: number) => (cursor ? `${cursorOffset(cursor)}:${gen}` : "");
|
|
116
|
+
type PhotoRead = { seq: number; galleryId: string; index: number; offset: number } & ({ read: { name: string; items: RawItem[]; total: number } } | { error: unknown });
|
|
117
|
+
type PhotosRead = { seq: number; title?: string; photos?: PhotoRow[]; total?: number; reported?: number; next?: string; refresh?: boolean } | { seq: number; error: unknown; refresh?: boolean };
|
|
68
118
|
|
|
69
119
|
/** A Pro Gallery image item's URL. `imageInfo` is either a Wix media object (`{ id, url }`,
|
|
70
120
|
* where `url` may be the bare media id) or a `wix:image://` string; anything else is "". */
|
|
@@ -76,57 +126,86 @@ function itemUrl(item: RawItem | undefined): string {
|
|
|
76
126
|
return wixMediaUrl(media.url) || wixMediaUrl(media.id);
|
|
77
127
|
}
|
|
78
128
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
129
|
+
const str = (v: unknown) => (typeof v === "string" ? v.trim() : "");
|
|
130
|
+
const num = (v: unknown) => (typeof v === "number" && v > 0 ? v : 0);
|
|
131
|
+
|
|
132
|
+
/** A Wix-hosted video's playable mp4 (the largest at or under 720p, else the first) and poster. */
|
|
133
|
+
function videoSources(item: RawItem): { videoUrl: string; poster: string; width: number; height: number } | null {
|
|
134
|
+
const info = item.video?.videoInfo as { url?: unknown; resolutions?: unknown; posters?: unknown } | undefined;
|
|
135
|
+
if (!info) return null;
|
|
136
|
+
const all = (Array.isArray(info.resolutions) ? info.resolutions : []) as Array<{ url?: unknown; width?: unknown; height?: unknown }>;
|
|
137
|
+
// amit1 (2026-11-17): a 240p mp4 and an `hls` entry with height 0 — play an mp4 when there is one.
|
|
138
|
+
const https = all.filter((r) => /^https:\/\//.test(str(r.url)));
|
|
139
|
+
const mp4 = https.filter((r) => /mp4/i.test(str((r as { format?: unknown }).format)) || /\.mp4$/i.test(str(r.url)));
|
|
140
|
+
const playable = mp4.length ? mp4 : https;
|
|
141
|
+
const pick = [...playable].sort((a, b) => num(b.height) - num(a.height)).find((r) => num(r.height) <= 720) ?? playable[0];
|
|
142
|
+
const firstPoster = (Array.isArray(info.posters) ? info.posters[0] : undefined) as { url?: unknown; id?: unknown } | undefined;
|
|
143
|
+
const poster = firstPoster ? wixMediaUrl(firstPoster.url) || wixMediaUrl(firstPoster.id) : "";
|
|
144
|
+
if (!pick) return null;
|
|
145
|
+
return { videoUrl: str(pick.url), poster, width: num(pick.width), height: num(pick.height) };
|
|
86
146
|
}
|
|
87
147
|
|
|
88
|
-
/** A
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
148
|
+
/** A gallery's items as rows; text items (and items with nothing to show) are dropped. */
|
|
149
|
+
function photoRows(galleryName: string, galleryId: string, items: RawItem[], offset: number, total: number): PhotoRow[] {
|
|
150
|
+
const label = copy("gallery.photoLabel", "{gallery}, photo {n} of {total}");
|
|
151
|
+
// A screen reader must not call a video a photo: an untitled video gets its own spoken name.
|
|
152
|
+
const videoLabel = copy("gallery.videoLabel", "{gallery}, video {n} of {total}");
|
|
153
|
+
return items.flatMap((item, i): PhotoRow[] => {
|
|
154
|
+
const n = offset + i + 1;
|
|
155
|
+
const caption = str(item.title);
|
|
156
|
+
const base = {
|
|
157
|
+
id: str(item.id) || `${galleryId}-${n - 1}`, position: n - 1, caption, description: str(item.description),
|
|
158
|
+
label: fill(label, { gallery: galleryName, n, total: total || n }),
|
|
159
|
+
linkUrl: /^https?:\/\//.test(str(item.link?.url)) ? str(item.link?.url) : "", linkText: str(item.link?.text),
|
|
160
|
+
};
|
|
161
|
+
const row = (kind: PhotoRow["kind"], url: string, extra: Partial<PhotoRow> = {}): PhotoRow => ({
|
|
162
|
+
...base, kind, url, title: caption || (kind === "image" ? base.label : fill(videoLabel, { gallery: galleryName, n, total: total || n })),
|
|
163
|
+
width: 0, height: 0, videoUrl: "", poster: "",
|
|
164
|
+
notImage: kind !== "image", notVideo: kind !== "video", notExternal: kind !== "external", ...extra,
|
|
165
|
+
});
|
|
166
|
+
const type = str(item.type);
|
|
167
|
+
if (item.video || type === "VIDEO") {
|
|
168
|
+
const videoType = str(item.video?.type);
|
|
169
|
+
if (videoType === "YOUTUBE" || videoType === "VIMEO") {
|
|
170
|
+
const url = str((item.video?.videoInfo as { url?: unknown } | undefined)?.url);
|
|
171
|
+
return /^https:\/\//.test(url) ? [row("external", "", { videoUrl: url })] : [];
|
|
172
|
+
}
|
|
173
|
+
const src = item.video ? videoSources(item) : null;
|
|
174
|
+
return src ? [row("video", src.poster, { videoUrl: src.videoUrl, poster: src.poster, width: src.width, height: src.height })] : [];
|
|
175
|
+
}
|
|
176
|
+
// The original media URL, like a page gallery's: the renderer sizes the image to its slot.
|
|
109
177
|
const url = itemUrl(item).replace(/\/v1\/.*$/, "");
|
|
110
178
|
if (!url) return [];
|
|
111
|
-
const
|
|
112
|
-
return [
|
|
179
|
+
const info = item.image?.imageInfo as { width?: unknown; height?: unknown } | undefined;
|
|
180
|
+
return [row("image", url, { width: num(info?.width), height: num(info?.height) })];
|
|
113
181
|
});
|
|
114
|
-
return { title: typeof name === "string" ? name.trim() : "", photos };
|
|
115
182
|
}
|
|
116
183
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
184
|
+
/** One page of a gateway gallery (`itemOffset` / `itemLimit`; `totalItems` says when to stop). */
|
|
185
|
+
async function readGalleryPage(api: WixApi, id: string, offset: number): Promise<{ name: string; items: RawItem[]; total: number; reported: number; next: string }> {
|
|
186
|
+
const res = await api.call("GET", `${GALLERIES_PATH}/${encodeURIComponent(id)}?itemOffset=${offset}&itemLimit=${ITEM_PAGE}`) as { gallery?: { name?: unknown; items?: unknown; totalItems?: unknown } } | null;
|
|
187
|
+
const gallery = res?.gallery;
|
|
188
|
+
if (!gallery || typeof gallery !== "object") throw new Error("Malformed Pro Gallery response");
|
|
189
|
+
const items = Array.isArray(gallery.items) ? gallery.items as RawItem[] : [];
|
|
190
|
+
// `totalItems` can leave out videos (amit1: 6 for 6 photos and 1 video): never below what was read,
|
|
191
|
+
// and never what decides the last page. A full page may have more after it.
|
|
192
|
+
const total = Math.max(typeof gallery.totalItems === "number" ? gallery.totalItems : 0, offset + items.length);
|
|
193
|
+
const more = items.length === ITEM_PAGE;
|
|
194
|
+
// `reported`: what Wix counts, the photos only (amit1) — the count line's number while pages remain.
|
|
195
|
+
const reported = typeof gallery.totalItems === "number" ? gallery.totalItems : 0;
|
|
196
|
+
return { name: str(gallery.name), items, total, reported, next: more ? String(offset + items.length) : "" };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async function readGalleriesPage(api: WixApi, offset: number): Promise<{ galleries: RawGallery[]; next: string }> {
|
|
200
|
+
const res = await api.call("GET", `${GALLERIES_PATH}?itemLimit=${PREVIEW_ITEMS}&offset=${offset}&limit=${PAGE_SIZE}`) as unknown;
|
|
201
|
+
const page = (res as { galleries?: unknown } | null)?.galleries;
|
|
202
|
+
if (!Array.isArray(page) || page.some((g) => !g || typeof g.id !== "string" || !g.id)) {
|
|
203
|
+
throw new Error("Malformed Pro Gallery list response");
|
|
128
204
|
}
|
|
129
|
-
|
|
205
|
+
const total = (res as { totalGalleries?: unknown }).totalGalleries;
|
|
206
|
+
const seen = offset + page.length;
|
|
207
|
+
const more = page.length === PAGE_SIZE && (typeof total !== "number" || seen < total);
|
|
208
|
+
return { galleries: page as RawGallery[], next: more ? String(seen) : "" };
|
|
130
209
|
}
|
|
131
210
|
|
|
132
211
|
async function readLegacyGalleries(api: WixApi): Promise<RawGallery[]> {
|
|
@@ -142,7 +221,8 @@ async function readLegacyGalleries(api: WixApi): Promise<RawGallery[]> {
|
|
|
142
221
|
});
|
|
143
222
|
}
|
|
144
223
|
|
|
145
|
-
|
|
224
|
+
/** The first gateway page, falling back to the older Pro Gallery route on native only. */
|
|
225
|
+
async function readFirstPage(api: WixApi): Promise<{ galleries: RawGallery[]; next: string }> {
|
|
146
226
|
// The old absolute host is supported by native Wix transports, but the
|
|
147
227
|
// published web bridge refuses it as webwix_owner_only.
|
|
148
228
|
const nativeLegacyAvailable = async (): Promise<boolean> => {
|
|
@@ -151,26 +231,63 @@ async function readCompatibleGalleries(api: WixApi): Promise<RawGallery[]> {
|
|
|
151
231
|
info?.platform === "macos" || info?.platform === "react-native";
|
|
152
232
|
};
|
|
153
233
|
try {
|
|
154
|
-
const
|
|
155
|
-
if (galleries.length) return
|
|
156
|
-
if (!(await nativeLegacyAvailable())) return
|
|
234
|
+
const first = await readGalleriesPage(api, 0);
|
|
235
|
+
if (first.galleries.length) return first;
|
|
236
|
+
if (!(await nativeLegacyAvailable())) return first;
|
|
157
237
|
// A native site's older Pro Gallery app can have content even when the gateway
|
|
158
238
|
// reports none. Keep the gateway's honest empty result if the old route is blocked.
|
|
159
239
|
try {
|
|
160
240
|
const legacy = await readLegacyGalleries(api);
|
|
161
|
-
return legacy.length ? legacy :
|
|
162
|
-
} catch { return
|
|
241
|
+
return legacy.length ? { galleries: legacy, next: "" } : first;
|
|
242
|
+
} catch { return first; }
|
|
163
243
|
} catch (gatewayError) {
|
|
164
244
|
if (!(await nativeLegacyAvailable())) throw gatewayError;
|
|
165
|
-
try { return await readLegacyGalleries(api); }
|
|
245
|
+
try { return { galleries: await readLegacyGalleries(api), next: "" }; }
|
|
166
246
|
catch { throw gatewayError; }
|
|
167
247
|
}
|
|
168
248
|
}
|
|
169
249
|
|
|
250
|
+
function countText(n: number): string {
|
|
251
|
+
if (!n) return "";
|
|
252
|
+
return n === 1 ? copy("galleries.countPhoto", "1 photo") : fill(copy("galleries.countPhotos", "{n} photos"), { n });
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
type SlotFields = "photo1" | "photo2" | "photo3" | "photo4" | "noPhoto1" | "noPhoto2" | "noPhoto3" | "noPhoto4" | "hasPhoto1" | "hasPhoto2" | "hasPhoto3" | "hasPhoto4";
|
|
256
|
+
function slots(urls: string[]): Pick<Row, SlotFields | "image" | "noCover" | "hasCover"> {
|
|
257
|
+
const [a = "", b = "", c = "", d = ""] = urls;
|
|
258
|
+
return {
|
|
259
|
+
photo1: a, photo2: b, photo3: c, photo4: d, noPhoto1: !a, noPhoto2: !b, noPhoto3: !c, noPhoto4: !d,
|
|
260
|
+
hasPhoto1: !!a, hasPhoto2: !!b, hasPhoto3: !!c, hasPhoto4: !!d, image: a, noCover: !a, hasCover: !!a,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function row(id: string, title: string, total: number, urls: string[], origin: Origin): Row {
|
|
265
|
+
const count = countText(total);
|
|
266
|
+
return { id, title, subtitle: count, name: title, description: count, source: origin, origin, a11y: count ? `${title}, ${count}` : title, ...slots(urls) };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function norm(g: RawGallery, i: number): Row {
|
|
270
|
+
const title = (g.name || "").trim() || `Gallery ${i + 1}`;
|
|
271
|
+
const n = g.totalItems ?? g.totalItemsCount ?? 0;
|
|
272
|
+
// The list asks for the first 4 items: images give their photo, a Wix video its poster.
|
|
273
|
+
const urls = (Array.isArray(g.items) ? g.items : []).flatMap((item) => {
|
|
274
|
+
if (item.video) return videoSources(item)?.poster ? [videoSources(item)!.poster] : [];
|
|
275
|
+
const url = itemUrl(item);
|
|
276
|
+
return url ? [url] : [];
|
|
277
|
+
}).slice(0, PREVIEW_ITEMS);
|
|
278
|
+
return row(g.id, title, n, urls, g.source ?? "gateway");
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** offline when the device has no network, else server. */
|
|
282
|
+
function errorVariant(err: unknown): string {
|
|
283
|
+
const msg = String((err as { message?: unknown } | null)?.message ?? err ?? "");
|
|
284
|
+
return /offline|network|internet|failed to fetch|ENOTFOUND|ECONN|timed? ?out/i.test(msg) ? "offline" : "server";
|
|
285
|
+
}
|
|
286
|
+
|
|
170
287
|
const MOCK: Row[] = [
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
288
|
+
row("sample-work", "Our Work", 24, [], "page"),
|
|
289
|
+
row("sample-events", "Events", 48, [], "page"),
|
|
290
|
+
row("sample-team", "The Team", 9, [], "page"),
|
|
174
291
|
];
|
|
175
292
|
|
|
176
293
|
/** sample rows reach the screen ONLY in the host's explicit sample preview;
|
|
@@ -186,42 +303,157 @@ const COPY: LoadCopy<Row> = {
|
|
|
186
303
|
/** The newest state, for an action that answers after an await (`s` is from before it). */
|
|
187
304
|
const current = (s: S): S => (svc.getState?.() as S | undefined) ?? s;
|
|
188
305
|
|
|
306
|
+
/** A gallery's own empty, missing, loading and failed states never show together. */
|
|
307
|
+
const NO_GALLERY = { photos: [], noGallery: true, hasPhotos: false, photoCursor: "", countText: "", photoPageFailed: false, photoPageOk: true, noTitleSkeleton: true, hideNoPhotos: true };
|
|
308
|
+
const NO_PHOTO = {
|
|
309
|
+
photoUrl: "", noPhotoImage: true, photoTitle: "", photoSubtitle: "", photoDescription: "", photoCaption: "", photoLabel: "",
|
|
310
|
+
linkUrl: "", linkText: "", noLink: true, noSubtitle: true, noDescription: true, galleryId: "", noGalleryLink: true, hasPhoto: false, noPhoto: true,
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
function galleryCount(photos: PhotoRow[], reported: number, complete: boolean): string {
|
|
314
|
+
// Pages remain: the photos Wix reports (never fewer than are already shown). Videos are counted once all are read.
|
|
315
|
+
if (!complete) return countText(Math.max(reported, photos.filter((p) => p.kind === "image").length));
|
|
316
|
+
const videos = photos.filter((p) => p.kind !== "image").length, images = photos.length - videos;
|
|
317
|
+
const videoText = videos === 1 ? copy("galleries.countVideo", "1 video") : fill(copy("galleries.countVideos", "{n} videos"), { n: videos });
|
|
318
|
+
return [countText(images), videos ? videoText : ""].filter(Boolean).join(", ");
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** The live-read rule. With page galleries there is nothing to read. A tap from a gateway row reads
|
|
322
|
+
* live (a synthesized legacy `gallery-<n>` id never does). A cold link carries no origin — the web
|
|
323
|
+
* host drops a `source` URL param — so it reads live when its id is a GUID, as every Pro Gallery
|
|
324
|
+
* id is (B2). A legacy or page row opens by its title: the gateway does not know its id. */
|
|
325
|
+
function readsLive(id: string, origin: string): boolean {
|
|
326
|
+
if (staticGalleries.length || /^gallery-\d+$/.test(id)) return false;
|
|
327
|
+
if (origin === "gateway") return true;
|
|
328
|
+
return !origin && GUID.test(id);
|
|
329
|
+
}
|
|
330
|
+
const tapOrigin = () => input("origin") || input("source");
|
|
331
|
+
|
|
332
|
+
/** A 404, or a 400 for a malformed id: the gallery is gone, so not found, never a Retry. */
|
|
333
|
+
const isGone = (err: unknown) => isNotFoundError(err) || /\b400\b|not a valid GUID/i.test(String((err as { message?: unknown } | null)?.message ?? err ?? ""));
|
|
334
|
+
|
|
335
|
+
function photoPage(s: S, gallery: { id: string; title: string }, photo: PhotoRow | undefined): S {
|
|
336
|
+
if (!photo) return { ...s, ...loaded("galleries", s.galleries, COPY), ...presence("missing"), ...NO_PHOTO };
|
|
337
|
+
const title = photo.caption || gallery.title;
|
|
338
|
+
const subtitle = photo.caption ? gallery.title : "";
|
|
339
|
+
return {
|
|
340
|
+
...s, ...loaded("galleries", s.galleries, COPY), ...presence("found"),
|
|
341
|
+
photoUrl: photo.kind === "image" ? photo.url : photo.poster, noPhotoImage: !(photo.kind === "image" ? photo.url : photo.poster), photoTitle: title, photoSubtitle: subtitle, photoDescription: photo.description,
|
|
342
|
+
photoCaption: photo.caption, photoLabel: photo.title,
|
|
343
|
+
// A YouTube or Vimeo item has no picture: its link opens the video.
|
|
344
|
+
linkUrl: photo.linkUrl || (photo.kind === "external" ? photo.videoUrl : ""), linkText: photo.linkText || copy("photoAlbum.openLink", "Open Link"),
|
|
345
|
+
noLink: !(photo.linkUrl || (photo.kind === "external" && photo.videoUrl)),
|
|
346
|
+
noSubtitle: !subtitle, noDescription: !photo.description, galleryId: gallery.id, noGalleryLink: !gallery.id, hasPhoto: true, noPhoto: false,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
async function loadMorePage(s: S): Promise<S> {
|
|
351
|
+
const api = wixApi();
|
|
352
|
+
const cursor = s.nextCursor;
|
|
353
|
+
const gen = cursorGen(cursor);
|
|
354
|
+
if (!api || !cursor || gen !== listSeq || listPaging === cursor) return s;
|
|
355
|
+
const offset = cursorOffset(cursor);
|
|
356
|
+
listPaging = cursor;
|
|
357
|
+
try {
|
|
358
|
+
const page = await readGalleriesPage(api, offset);
|
|
359
|
+
const now = current(s);
|
|
360
|
+
if (gen !== listSeq) return now;
|
|
361
|
+
const rows = page.galleries.map((g, i) => norm(g, offset + i));
|
|
362
|
+
return { ...now, galleries: [...now.galleries, ...rows], nextCursor: tagCursor(page.next, gen), pageFailed: false, pageOk: true };
|
|
363
|
+
} catch {
|
|
364
|
+
// A failed next page keeps the rows; the end of the list offers a retry.
|
|
365
|
+
return gen !== listSeq ? current(s) : { ...current(s), pageFailed: true, pageOk: false };
|
|
366
|
+
} finally {
|
|
367
|
+
if (listPaging === cursor) listPaging = "";
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
async function morePhotosPage(s: S): Promise<S> {
|
|
372
|
+
const api = wixApi();
|
|
373
|
+
const id = input("id");
|
|
374
|
+
if (!api || !s.photoCursor || !id) return s;
|
|
375
|
+
const cursor = s.photoCursor;
|
|
376
|
+
const seq = cursorGen(cursor);
|
|
377
|
+
if (seq !== openSeq || photoPaging === cursor) return s;
|
|
378
|
+
const offset = cursorOffset(cursor);
|
|
379
|
+
photoPaging = cursor;
|
|
380
|
+
try {
|
|
381
|
+
const page = await readGalleryPage(api, id, offset);
|
|
382
|
+
const now = current(s);
|
|
383
|
+
if (seq !== openSeq) return now;
|
|
384
|
+
const photos = [...now.photos, ...photoRows(now.galleryTitle, id, page.items, offset, page.total)];
|
|
385
|
+
return { ...now, photos, hasPhotos: photos.length > 0, hideNoPhotos: photos.length > 0, photoCursor: tagCursor(page.next, seq), photoPageFailed: false, photoPageOk: true, countText: galleryCount(photos, page.reported, !page.next) };
|
|
386
|
+
} catch (err) {
|
|
387
|
+
if (seq !== openSeq) return current(s);
|
|
388
|
+
// A gallery deleted after its first page is gone, as on the first read: a page Retry cannot succeed.
|
|
389
|
+
if (isGone(err)) return { ...current(s), ...loaded("galleries", s.galleries, COPY), ...presence("missing"), galleryTitle: "", ...NO_GALLERY };
|
|
390
|
+
return { ...current(s), photoPageFailed: true, photoPageOk: false };
|
|
391
|
+
} finally {
|
|
392
|
+
if (photoPaging === cursor) photoPaging = "";
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
189
396
|
const svc = defineService<S, {
|
|
190
|
-
load: (s: S, arg?: { staticGalleries?: unknown }) => Promise<S>;
|
|
191
|
-
|
|
397
|
+
load: (s: S, arg?: { staticGalleries?: unknown; refresh?: string; appearReason?: string }) => Promise<S>;
|
|
398
|
+
loadMore: (s: S) => Promise<S>;
|
|
399
|
+
retryLoadMore: (s: S) => Promise<S>;
|
|
400
|
+
open: (s: S, arg?: { staticGalleries?: unknown; appearReason?: string }) => S;
|
|
401
|
+
refresh: (s: S, arg?: { staticGalleries?: unknown }) => S;
|
|
192
402
|
photosRead: (s: S, arg?: PhotosRead) => S | undefined;
|
|
193
|
-
|
|
403
|
+
morePhotos: (s: S) => Promise<S>;
|
|
404
|
+
retryMorePhotos: (s: S) => Promise<S>;
|
|
405
|
+
view: (s: S, arg?: { staticGalleries?: unknown }) => Promise<S>;
|
|
406
|
+
photoRead: (s: S, arg?: PhotoRead) => S | undefined;
|
|
407
|
+
openExternal: (s: S, arg?: { url?: string }) => Promise<S>;
|
|
194
408
|
}>("himiBrandedGalleries", {
|
|
195
|
-
state: {
|
|
409
|
+
state: {
|
|
410
|
+
...LOADING, ...presence("loading"), galleries: [], emptyText: "", nextCursor: "", pageFailed: false, pageOk: true, errorVariant: "server", galleryTitle: "",
|
|
411
|
+
...NO_GALLERY, ...NO_PHOTO,
|
|
412
|
+
} as S,
|
|
196
413
|
actions: {
|
|
197
414
|
load: async (s, arg) => {
|
|
198
415
|
// No `openSeq` bump here: the list and a gallery never share a worker (workers are pooled by
|
|
199
416
|
// screen and input), and a host's refresh runs `load` on the gallery's own worker, where a
|
|
200
|
-
// bump would drop that gallery's read in flight and leave its screen blank.
|
|
417
|
+
// bump would drop that gallery's read in flight and leave its screen blank. `listSeq` is the list's own.
|
|
418
|
+
// A gallery's or photo page's own worker has no list: the host's `load` there changes nothing, and the
|
|
419
|
+
// unchanged state tells the collection wrapper this request was a no-op, so a `morePhotos` or `view`
|
|
420
|
+
// in flight is not dropped as superseded.
|
|
421
|
+
if (input("id") || input("galleryId") || input("url")) return s;
|
|
422
|
+
// Back to the list (`appearReason: "return"`): keep the pages already read, not page 1 again.
|
|
423
|
+
if (arg?.appearReason === "return" && current(s).galleries.length) return s;
|
|
424
|
+
const gen = ++listSeq;
|
|
201
425
|
try {
|
|
202
426
|
if (arg && "staticGalleries" in arg) {
|
|
203
427
|
staticGalleries = [];
|
|
204
428
|
staticGalleries = parseStaticGalleries(arg.staticGalleries);
|
|
205
429
|
}
|
|
206
430
|
if (staticGalleries.length) {
|
|
207
|
-
const rows = staticGalleries.map((gallery) =>
|
|
208
|
-
|
|
209
|
-
return { id: gallery.id, title: gallery.title, subtitle, name: gallery.title, description: subtitle, image: gallery.photos[0], noCover: false, hasCover: true, source: "page" as const };
|
|
210
|
-
});
|
|
211
|
-
return { ...s, ...loaded("galleries", rows, COPY) };
|
|
431
|
+
const rows = staticGalleries.map((gallery) => row(gallery.id, gallery.title, gallery.photos.length, gallery.photos.slice(0, PREVIEW_ITEMS), "page"));
|
|
432
|
+
return { ...s, ...loaded("galleries", rows, COPY), nextCursor: "" };
|
|
212
433
|
}
|
|
213
434
|
const api = wixApi();
|
|
214
|
-
if (!api) return { ...s, ...loadFailed("galleries", new Error("Wix bridge unavailable"), COPY) };
|
|
215
|
-
const
|
|
216
|
-
|
|
435
|
+
if (!api) return { ...s, ...loadFailed("galleries", new Error("Wix bridge unavailable"), COPY), errorVariant: "server" };
|
|
436
|
+
const first = await readFirstPage(api);
|
|
437
|
+
// A newer load (another refresh) started during this read: its result wins.
|
|
438
|
+
if (gen !== listSeq) return current(s);
|
|
217
439
|
// From the state as it is NOW: on a gallery's own worker, its photos may have landed
|
|
218
440
|
// (`photosRead`) during the read, and `s` is from before it.
|
|
219
|
-
return { ...current(s), ...loaded("galleries", galleries, COPY) };
|
|
441
|
+
return { ...current(s), ...loaded("galleries", first.galleries.map(norm), COPY), nextCursor: tagCursor(first.next, gen), pageFailed: false, pageOk: true };
|
|
220
442
|
} catch (err) {
|
|
221
|
-
|
|
443
|
+
// A failed pull-to-refresh keeps the rows on screen: no full-screen error over content.
|
|
444
|
+
if (gen !== listSeq) return current(s);
|
|
445
|
+
if (arg?.refresh && current(s).galleries.length) return { ...current(s), nextCursor: retagCursor(current(s).nextCursor, gen) };
|
|
446
|
+
// The full-screen error replaces the rows, and with them an earlier failed page's Retry.
|
|
447
|
+
return { ...current(s), ...loadFailed("galleries", err, COPY), errorVariant: errorVariant(err), nextCursor: "", pageFailed: false, pageOk: true };
|
|
222
448
|
}
|
|
223
449
|
},
|
|
450
|
+
loadMore: (s) => loadMorePage(s),
|
|
451
|
+
// A distinct action for the end-of-list retry: the list's own onLoadMore stays the only automatic one.
|
|
452
|
+
retryLoadMore: (s) => loadMorePage(s),
|
|
224
453
|
open: (s, arg) => {
|
|
454
|
+
// Back to this gallery (`appearReason: "return"`): keep its photos and pages, read nothing.
|
|
455
|
+
// Workers are pooled by screen and input, so the state here is this gallery's.
|
|
456
|
+
if (arg?.appearReason === "return" && !s.noGallery && s.photos.length) return s;
|
|
225
457
|
// Every open, live or not, makes the reads of earlier opens stale (`photosRead` drops them):
|
|
226
458
|
// a page or legacy gallery opened after a slow gateway read must not get that read's photos.
|
|
227
459
|
const seq = ++openSeq;
|
|
@@ -231,51 +463,125 @@ const svc = defineService<S, {
|
|
|
231
463
|
staticGalleries = parseStaticGalleries(arg.staticGalleries);
|
|
232
464
|
}
|
|
233
465
|
} catch (err) {
|
|
234
|
-
return { ...s, ...loadFailed("galleries", err, COPY), ...presence("failed"),
|
|
235
|
-
noGallery: true, hasPhotos: false, photoUrl: "", photoTitle: "", hasPhoto: false, noPhoto: true };
|
|
466
|
+
return { ...s, ...loadFailed("galleries", err, COPY), ...presence("failed"), errorVariant: "server", galleryTitle: "", ...NO_GALLERY };
|
|
236
467
|
}
|
|
237
468
|
const id = input("id");
|
|
469
|
+
const name = input("name");
|
|
238
470
|
const gallery = staticGalleries.find((entry) => entry.id === id);
|
|
239
|
-
// No page galleries were carried in: a gateway (Pro Gallery app) gallery is read live, but
|
|
240
|
-
// ONLY when the tap says the list row came from the gateway (`source: "gateway"`, the row's
|
|
241
|
-
// own field). A legacy row's id and a sample row's id ("sample-work") are unknown to the
|
|
242
|
-
// gateway, and a tap that passes no source (Branded Lite's) cannot tell them apart: those
|
|
243
|
-
// open as before, by their title.
|
|
244
471
|
const api = wixApi();
|
|
245
|
-
|
|
246
|
-
if (id && !staticGalleries.length && api && live) {
|
|
472
|
+
if (id && api && readsLive(id, tapOrigin())) {
|
|
247
473
|
// The read lands through `photosRead`, tagged with this open: a pooled worker shows THIS
|
|
248
474
|
// gallery loading at once (never the last one's photos), and a slower read for a gallery
|
|
249
475
|
// left since is dropped instead of overwriting the one on screen.
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
({ title, photos }) => svc.photosRead({ seq, title: title || name, photos }),
|
|
476
|
+
void readGalleryPage(api, id, 0).then(
|
|
477
|
+
(page) => svc.photosRead({ seq, title: page.name || name, total: page.total, reported: page.reported, next: page.next, photos: photoRows(page.name || name, id, page.items, 0, page.total) }),
|
|
253
478
|
(err: unknown) => svc.photosRead({ seq, error: err }),
|
|
254
479
|
);
|
|
255
|
-
return { ...s, ...LOADING, ...presence("loading"), galleryTitle: name,
|
|
256
|
-
photoUrl: "", photoTitle: "", hasPhoto: false, noPhoto: true };
|
|
480
|
+
return { ...s, ...LOADING, ...presence("loading"), galleryTitle: name, ...NO_GALLERY, noTitleSkeleton: !!name };
|
|
257
481
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
482
|
+
// A page gallery's photos come with the descriptor. A legacy or sample (`page`) row opens by its
|
|
483
|
+
// title (the gateway does not know its id). An id that matches no page gallery is gone, and so
|
|
484
|
+
// is a link with a non-GUID id and no origin, outside the explicit sample preview (B3).
|
|
485
|
+
const origin = tapOrigin();
|
|
486
|
+
const unknownLink = !staticGalleries.length && !origin && !GUID.test(id) && !samplesRequested();
|
|
487
|
+
const missing = !id || (staticGalleries.length > 0 && !gallery) || (!staticGalleries.length && !api) || unknownLink;
|
|
488
|
+
const title = gallery?.title || name;
|
|
489
|
+
const photos = (gallery?.photos ?? []).map((url, index): PhotoRow => photoRows(title, id, [{ id: `${id}-${index}`, image: { imageInfo: url } }], index, gallery!.photos.length)[0]);
|
|
490
|
+
return {
|
|
491
|
+
// A gallery that is not there has no heading over "Gallery not found".
|
|
492
|
+
...s, ...loaded("galleries", s.galleries, COPY), ...presence(missing ? "missing" : "found"), galleryTitle: missing ? "" : title,
|
|
493
|
+
...NO_GALLERY, photos, noGallery: missing, hasPhotos: photos.length > 0, countText: countText(photos.length),
|
|
494
|
+
hideNoPhotos: missing || photos.length > 0,
|
|
495
|
+
};
|
|
496
|
+
},
|
|
497
|
+
refresh: (s) => {
|
|
498
|
+
// Pull to refresh: read again, keep the photos on screen until the read lands, and keep them
|
|
499
|
+
// if it fails. A page or legacy gallery has nothing to re-read.
|
|
500
|
+
const id = input("id");
|
|
501
|
+
const api = wixApi();
|
|
502
|
+
if (!id || !api || !readsLive(id, tapOrigin()) || s.noEntity) return s;
|
|
503
|
+
const seq = ++openSeq;
|
|
504
|
+
void readGalleryPage(api, id, 0).then(
|
|
505
|
+
(page) => svc.photosRead({ seq, refresh: true, title: page.name || s.galleryTitle, total: page.total, reported: page.reported, next: page.next, photos: photoRows(page.name || s.galleryTitle, id, page.items, 0, page.total) }),
|
|
506
|
+
(err: unknown) => svc.photosRead({ seq, refresh: true, error: err }),
|
|
507
|
+
);
|
|
508
|
+
return s;
|
|
262
509
|
},
|
|
263
510
|
photosRead: (s, arg) => {
|
|
264
511
|
if (!arg || arg.seq !== openSeq) return undefined;
|
|
265
512
|
if ("error" in arg) {
|
|
266
|
-
|
|
267
|
-
//
|
|
268
|
-
|
|
269
|
-
|
|
513
|
+
if (arg.refresh && !isGone(arg.error)) return { ...s, photoCursor: retagCursor(s.photoCursor, arg.seq) };
|
|
514
|
+
// A 404 (or a 400 for a malformed id) is the gallery being GONE — the not-found state
|
|
515
|
+
// alone, never also an error card whose Retry cannot succeed. Any other failure is the error.
|
|
516
|
+
return { ...s, ...(isGone(arg.error) ? { ...loaded("galleries", s.galleries, COPY), ...presence("missing") } : { ...loadFailed("galleries", arg.error, COPY), ...presence("failed"), errorVariant: errorVariant(arg.error) }),
|
|
517
|
+
// The tapped name is not a heading over "Gallery not found" or the error.
|
|
518
|
+
galleryTitle: "", ...NO_GALLERY };
|
|
270
519
|
}
|
|
271
|
-
|
|
272
|
-
|
|
520
|
+
const photos = arg.photos ?? [];
|
|
521
|
+
return {
|
|
522
|
+
...s, ...loaded("galleries", s.galleries, COPY), ...presence("found"), galleryTitle: arg.title ?? "",
|
|
523
|
+
...NO_GALLERY, photos, noGallery: false, hasPhotos: photos.length > 0, photoCursor: tagCursor(arg.next ?? "", arg.seq), hideNoPhotos: photos.length > 0,
|
|
524
|
+
countText: galleryCount(photos, arg.reported ?? 0, !arg.next),
|
|
525
|
+
};
|
|
273
526
|
},
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
527
|
+
morePhotos: (s) => morePhotosPage(s),
|
|
528
|
+
retryMorePhotos: (s) => morePhotosPage(s),
|
|
529
|
+
view: async (s, arg) => {
|
|
530
|
+
// The photo page opens from a link or a push only: `galleryId` + `index`, or an old `url` link.
|
|
531
|
+
try {
|
|
532
|
+
if (arg && "staticGalleries" in arg) staticGalleries = parseStaticGalleries(arg.staticGalleries);
|
|
533
|
+
} catch (err) {
|
|
534
|
+
return { ...s, ...loadFailed("galleries", err, COPY), ...presence("failed"), errorVariant: "server", ...NO_PHOTO };
|
|
535
|
+
}
|
|
536
|
+
const seq = ++viewSeq;
|
|
537
|
+
const galleryId = input("galleryId");
|
|
538
|
+
const index = input("index") ? Number(input("index")) : 0;
|
|
539
|
+
if (!galleryId) {
|
|
540
|
+
const photoUrl = input("url");
|
|
541
|
+
const valid = /^https:\/\/static\.wixstatic\.com\/media\/[A-Za-z0-9_~.-]+$/.test(photoUrl);
|
|
542
|
+
const title = input("name") || copy("photoAlbum.fallbackTitle", "Gallery photo");
|
|
543
|
+
return { ...s, ...loaded("galleries", s.galleries, COPY), ...presence(valid ? "found" : "missing"), ...NO_PHOTO,
|
|
544
|
+
photoUrl: valid ? photoUrl : "", noPhotoImage: !valid, photoTitle: valid ? title : "", photoLabel: valid ? title : "", hasPhoto: valid, noPhoto: !valid };
|
|
545
|
+
}
|
|
546
|
+
// An index that names no item (negative, not a whole number) is a photo that is not there.
|
|
547
|
+
if (!Number.isInteger(index) || index < 0) return photoPage(s, { id: "", title: "" }, undefined);
|
|
548
|
+
const page = staticGalleries.find((g) => g.id === galleryId);
|
|
549
|
+
// With page galleries the gallery screen reads nothing live (`readsLive`): a photo of any other
|
|
550
|
+
// gallery is not found here too, so View Gallery never leads to "Gallery not found".
|
|
551
|
+
if (!page && staticGalleries.length) return photoPage(s, { id: "", title: "" }, undefined);
|
|
552
|
+
if (page) {
|
|
553
|
+
const photos = photoRows(page.title, page.id, page.photos.map((url, i) => ({ id: `${page.id}-${i}`, image: { imageInfo: url } })), 0, page.photos.length);
|
|
554
|
+
return photoPage(s, { id: page.id, title: page.title }, photos.find((p) => p.position === index));
|
|
555
|
+
}
|
|
556
|
+
const api = wixApi();
|
|
557
|
+
if (!api || !GUID.test(galleryId)) return photoPage(s, { id: "", title: "" }, undefined);
|
|
558
|
+
// GetGallery pages hold 100 items: read the page that holds `index`. The read lands through
|
|
559
|
+
// `photoRead`, tagged with this request; meanwhile the page shows loading, never the photo (and
|
|
560
|
+
// the View Gallery target) of a link this pooled worker opened before.
|
|
561
|
+
const offset = Math.floor(index / ITEM_PAGE) * ITEM_PAGE;
|
|
562
|
+
void readGalleryPage(api, galleryId, offset).then(
|
|
563
|
+
(read) => svc.photoRead({ seq, galleryId, index, offset, read }),
|
|
564
|
+
(error: unknown) => svc.photoRead({ seq, galleryId, index, offset, error }),
|
|
565
|
+
);
|
|
566
|
+
return { ...s, ...LOADING, ...presence("loading"), ...NO_PHOTO };
|
|
567
|
+
},
|
|
568
|
+
photoRead: (s, arg) => {
|
|
569
|
+
if (!arg || arg.seq !== viewSeq) return undefined;
|
|
570
|
+
if ("error" in arg) {
|
|
571
|
+
return isGone(arg.error)
|
|
572
|
+
? photoPage(s, { id: "", title: "" }, undefined)
|
|
573
|
+
: { ...s, ...loadFailed("galleries", arg.error, COPY), ...presence("failed"), errorVariant: errorVariant(arg.error), ...NO_PHOTO };
|
|
574
|
+
}
|
|
575
|
+
const photos = photoRows(arg.read.name, arg.galleryId, arg.read.items, arg.offset, arg.read.total);
|
|
576
|
+
return photoPage(s, { id: arg.galleryId, title: arg.read.name }, photos.find((p) => p.position === arg.index));
|
|
577
|
+
},
|
|
578
|
+
openExternal: async (s, arg) => {
|
|
579
|
+
const url = str(arg?.url) || s.linkUrl;
|
|
580
|
+
if (/^https?:\/\//.test(url)) {
|
|
581
|
+
try { await openUrl(url, "in_app_browser"); } catch { /* the handoff is best-effort */ }
|
|
582
|
+
}
|
|
583
|
+
// The state as it is now: a page or a refresh may have landed during the handoff.
|
|
584
|
+
return current(s);
|
|
279
585
|
},
|
|
280
586
|
},
|
|
281
587
|
});
|