@wix/himalaya-cli 0.1642.0 → 0.1643.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 (86) hide show
  1. package/package.json +2 -2
  2. package/template-icons/conference.png +0 -0
  3. package/templates/branded-lite/dev/index.ts +152 -88
  4. package/templates/branded-lite/l10n/en.json +1 -1
  5. package/templates/branded-lite/tier5-src/_shared/featured-event.ts +63 -0
  6. package/templates/branded-lite/tier5-src/himi-events-detail/index.ts +93 -11
  7. package/templates/community-club/dev/index.ts +152 -88
  8. package/templates/community-club/tier5-src/_shared/featured-event.ts +63 -0
  9. package/templates/community-club/tier5-src/himi-events-detail/index.ts +93 -11
  10. package/templates/conference/README.md +53 -0
  11. package/templates/conference/config.ts +321 -0
  12. package/templates/conference/dev/index.ts +17252 -0
  13. package/templates/conference/himalaya.content.json +46 -0
  14. package/templates/conference/himalaya.template.json +15 -0
  15. package/templates/conference/icon.png +0 -0
  16. package/templates/conference/platforms.json +1 -0
  17. package/templates/conference/tier5-src/_shared/agenda-stars.ts +64 -0
  18. package/templates/conference/tier5-src/_shared/app-locale.ts +61 -0
  19. package/templates/conference/tier5-src/_shared/branded-lite-hosted.ts +279 -0
  20. package/templates/conference/tier5-src/_shared/branded-load-state.ts +109 -0
  21. package/templates/conference/tier5-src/_shared/business-chat-copy.ts +40 -0
  22. package/templates/conference/tier5-src/_shared/business-chat-history.ts +51 -0
  23. package/templates/conference/tier5-src/_shared/business-chat-message-model.ts +177 -0
  24. package/templates/conference/tier5-src/_shared/business-chat-model.ts +56 -0
  25. package/templates/conference/tier5-src/_shared/business-chat-presenter.ts +576 -0
  26. package/templates/conference/tier5-src/_shared/business-chat-transport.ts +148 -0
  27. package/templates/conference/tier5-src/_shared/collection-contract.ts +229 -0
  28. package/templates/conference/tier5-src/_shared/collection-query.ts +193 -0
  29. package/templates/conference/tier5-src/_shared/collection-service.ts +400 -0
  30. package/templates/conference/tier5-src/_shared/engine-intl.ts +508 -0
  31. package/templates/conference/tier5-src/_shared/event-agenda.ts +122 -0
  32. package/templates/conference/tier5-src/_shared/event-registration.ts +86 -0
  33. package/templates/conference/tier5-src/_shared/featured-event.ts +63 -0
  34. package/templates/conference/tier5-src/_shared/himi-account.ts +164 -0
  35. package/templates/conference/tier5-src/_shared/himi-copy.ts +89 -0
  36. package/templates/conference/tier5-src/_shared/himi-events.ts +65 -0
  37. package/templates/conference/tier5-src/_shared/himi-store.ts +7 -0
  38. package/templates/conference/tier5-src/_shared/hosted-checkout.ts +70 -0
  39. package/templates/conference/tier5-src/_shared/iap-attendance-form.ts +106 -0
  40. package/templates/conference/tier5-src/_shared/iap-attendance-purchase.ts +211 -0
  41. package/templates/conference/tier5-src/_shared/iap-attendance.ts +38 -0
  42. package/templates/conference/tier5-src/_shared/iap-worker.ts +125 -0
  43. package/templates/conference/tier5-src/_shared/inbox-rooms.ts +68 -0
  44. package/templates/conference/tier5-src/_shared/local-preferences.ts +38 -0
  45. package/templates/conference/tier5-src/_shared/member-access.ts +52 -0
  46. package/templates/conference/tier5-src/_shared/member-account-routes.ts +52 -0
  47. package/templates/conference/tier5-src/_shared/member-read.ts +52 -0
  48. package/templates/conference/tier5-src/_shared/member-screen.ts +99 -0
  49. package/templates/conference/tier5-src/_shared/offset-page.ts +10 -0
  50. package/templates/conference/tier5-src/_shared/online-actions.ts +76 -0
  51. package/templates/conference/tier5-src/_shared/owner-load-error.ts +348 -0
  52. package/templates/conference/tier5-src/_shared/payment-setup.ts +6 -0
  53. package/templates/conference/tier5-src/_shared/rich-body.ts +78 -0
  54. package/templates/conference/tier5-src/_shared/rich-content-link.ts +34 -0
  55. package/templates/conference/tier5-src/_shared/sign-in-sheet.ts +18 -0
  56. package/templates/conference/tier5-src/business-chat/index.ts +724 -0
  57. package/templates/conference/tier5-src/himi-conference-agenda/index.ts +183 -0
  58. package/templates/conference/tier5-src/himi-conference-home/index.ts +389 -0
  59. package/templates/conference/tier5-src/himi-events-account/index.ts +219 -0
  60. package/templates/conference/tier5-src/himi-events-detail/index.ts +1304 -0
  61. package/templates/conference/tier5-src/himi-events-list/index.ts +124 -0
  62. package/templates/conference/tier5-src/himi-events-my-events/index.ts +225 -0
  63. package/templates/conference/tier5-src/himi-events-rsvp/index.ts +230 -0
  64. package/templates/conference/tier5-src/himi-store-account/index.ts +998 -0
  65. package/templates/conference/tokens.json +365 -0
  66. package/templates/events-meetups/dev/index.ts +152 -88
  67. package/templates/events-meetups/tier5-src/_shared/featured-event.ts +63 -0
  68. package/templates/events-meetups/tier5-src/himi-events-detail/index.ts +93 -11
  69. package/templates/gym-fitness/dev/index.ts +152 -88
  70. package/templates/gym-fitness/tier5-src/_shared/featured-event.ts +63 -0
  71. package/templates/gym-fitness/tier5-src/himi-events-detail/index.ts +93 -11
  72. package/templates/nonprofit-cause/dev/index.ts +152 -88
  73. package/templates/nonprofit-cause/tier5-src/_shared/featured-event.ts +63 -0
  74. package/templates/nonprofit-cause/tier5-src/himi-events-detail/index.ts +93 -11
  75. package/templates/podcast-creator/dev/index.ts +152 -88
  76. package/templates/podcast-creator/tier5-src/_shared/featured-event.ts +63 -0
  77. package/templates/podcast-creator/tier5-src/himi-events-detail/index.ts +93 -11
  78. package/templates/portfolio-creative/dev/index.ts +152 -88
  79. package/templates/portfolio-creative/tier5-src/_shared/featured-event.ts +63 -0
  80. package/templates/portfolio-creative/tier5-src/himi-events-detail/index.ts +93 -11
  81. package/templates/restaurant/dev/index.ts +152 -88
  82. package/templates/restaurant/tier5-src/_shared/featured-event.ts +63 -0
  83. package/templates/restaurant/tier5-src/himi-events-detail/index.ts +93 -11
  84. package/templates/yoga-studio/dev/index.ts +152 -88
  85. package/templates/yoga-studio/tier5-src/_shared/featured-event.ts +63 -0
  86. package/templates/yoga-studio/tier5-src/himi-events-detail/index.ts +93 -11
@@ -0,0 +1,183 @@
1
+ // Tier-5 bundle: himi-conference-agenda — the conference template's Agenda tab.
2
+ //
3
+ // The featured event's Wix Events agenda (_shared/event-agenda.ts), day by day, with a star on
4
+ // each session: "My Agenda" is the starred ones (_shared/agenda-stars.ts — on the device for a
5
+ // visitor, the member's own once signed in). The list is flat: a row carries its day's heading
6
+ // (`showDay`) when it is the first of that day, so a bound grid draws the days without nesting.
7
+ //
8
+ // A failed read is an error with Retry; an event with no agenda (or none at all) is an empty
9
+ // state; a star that could not be saved says so and stays unstarred.
10
+ import { defineService, navigate } from "@himalaya/state";
11
+ import { type WixEvent } from "@himalaya/wix-events";
12
+ import { readFeaturedEvent } from "../_shared/featured-event.js";
13
+ import { agendaSettingsOf, readAgenda, type AgendaSession } from "../_shared/event-agenda.js";
14
+ import { starredSessions, toggleStar } from "../_shared/agenda-stars.js";
15
+ import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
16
+
17
+ export interface AgendaRow extends AgendaSession {
18
+ starred: boolean;
19
+ notStarred: boolean;
20
+ /** What a tap on the star does now: "Add Keynote to My Agenda". */
21
+ starLabel: string;
22
+ /** The first row of its day: the day heading is drawn above it. */
23
+ showDay: boolean;
24
+ hideDay: boolean;
25
+ }
26
+ type Status = "loading" | "ready" | "error";
27
+ type Filter = "all" | "mine";
28
+ interface S {
29
+ status: Status;
30
+ eventId: string;
31
+ eventTitle: string;
32
+ filter: Filter;
33
+ sessions: AgendaSession[];
34
+ starred: string[];
35
+ rows: AgendaRow[];
36
+ noRows: boolean;
37
+ /** "All items (5)". */
38
+ allLabel: string;
39
+ /** "My Agenda (1)". */
40
+ myLabel: string;
41
+ /** The My Agenda card's link: "View" while all show, "Show all" while only the starred do. */
42
+ myActionLabel: string;
43
+ showingMine: boolean;
44
+ showingAll: boolean;
45
+ /** A star that could not be saved, or "" — announced politely. */
46
+ message: string;
47
+ emptyTitle: string;
48
+ emptyBody: string;
49
+ errorText: string;
50
+ isLoading: boolean;
51
+ notLoading: boolean;
52
+ errored: boolean;
53
+ notErrored: boolean;
54
+ /** No agenda at all (no event, or an event without sessions). */
55
+ noEmpty: boolean;
56
+ /** My Agenda shows and nothing is starred. */
57
+ noMineEmpty: boolean;
58
+ /** The My Agenda card shows only when there are sessions to star. */
59
+ noAgendaCard: boolean;
60
+ }
61
+
62
+ /** The starred ids, or `unreadable` when the device store cannot be read: that is said on screen
63
+ * (`message`), never shown as an empty My Agenda the attendee would take as real. */
64
+ type StarRead = { ok: true; ids: string[] } | { ok: false; ids: string[] };
65
+ function readStars(eventId: string): StarRead {
66
+ try { return { ok: true, ids: [...starredSessions(eventId)] }; } catch { return { ok: false, ids: [] }; }
67
+ }
68
+ const unreadable = (): string => copyParam("agenda.starsUnreadable", "My Agenda could not be read on this device.");
69
+
70
+ function derive(s: S): S {
71
+ const loading = s.status === "loading", errored = s.status === "error";
72
+ const stars = new Set(s.starred.filter((id) => s.sessions.some((row) => row.id === id)));
73
+ const visible = s.filter === "mine" ? s.sessions.filter((row) => stars.has(row.id)) : s.sessions;
74
+ const rows = visible.map((row, index): AgendaRow => {
75
+ const starred = stars.has(row.id);
76
+ const showDay = index === 0 || visible[index - 1].dayKey !== row.dayKey;
77
+ return {
78
+ ...row,
79
+ starred,
80
+ notStarred: !starred,
81
+ starLabel: starred
82
+ ? copyTemplate("agenda.unstarLabel", "Remove {name} from My Agenda", { name: row.name })
83
+ : copyTemplate("agenda.starLabel", "Add {name} to My Agenda", { name: row.name }),
84
+ showDay,
85
+ hideDay: !showDay,
86
+ };
87
+ });
88
+ const mine = s.filter === "mine";
89
+ const ready = !loading && !errored;
90
+ return {
91
+ ...s,
92
+ rows,
93
+ noRows: rows.length === 0,
94
+ allLabel: copyTemplate("agenda.allItems", "All items ({n})", { n: s.sessions.length }),
95
+ myLabel: copyTemplate("agenda.myAgenda", "My Agenda ({n})", { n: stars.size }),
96
+ myActionLabel: mine ? copyParam("agenda.showAllCta", "Show all") : copyParam("agenda.viewMineCta", "View"),
97
+ showingMine: mine,
98
+ showingAll: !mine,
99
+ emptyTitle: s.eventId ? copyParam("agenda.emptyTitle", "The agenda is not out yet") : copyParam("agenda.noEventTitle", "No upcoming event"),
100
+ emptyBody: s.eventId ? copyParam("agenda.emptyBody", "Sessions will appear here once the organizers publish them.") : copyParam("agenda.noEventBody", "The agenda will appear here once the next event is published."),
101
+ errorText: copyParam("agenda.errorText", "The agenda could not be loaded."),
102
+ isLoading: loading,
103
+ notLoading: !loading,
104
+ errored,
105
+ notErrored: !errored,
106
+ noEmpty: !ready || s.sessions.length > 0,
107
+ noMineEmpty: !ready || !mine || rows.length > 0,
108
+ noAgendaCard: !ready || s.sessions.length === 0,
109
+ };
110
+ }
111
+
112
+ const BOOT: S = derive({
113
+ status: "loading", eventId: "", eventTitle: "", filter: "all", sessions: [], starred: [], rows: [], noRows: true,
114
+ allLabel: "", myLabel: "", myActionLabel: "", showingMine: false, showingAll: true, message: "",
115
+ emptyTitle: "", emptyBody: "", errorText: "",
116
+ isLoading: true, notLoading: false, errored: false, notErrored: true, noEmpty: true, noMineEmpty: true, noAgendaCard: true,
117
+ });
118
+
119
+ let loadSeq = 0;
120
+ let latest: S = BOOT;
121
+ const commit = (next: S): S => (latest = next);
122
+ const now = (): S => (svc.getState?.() as S | undefined) ?? latest;
123
+
124
+ async function load(s: S): Promise<S> {
125
+ const mine = ++loadSeq;
126
+ // AGENDA: without it Wix leaves `agendaSettings` out, and the agenda would never be read.
127
+ const featured = await readFeaturedEvent(["DETAILS", "AGENDA"]);
128
+ if (mine !== loadSeq) return now();
129
+ if (!featured.ok) return derive({ ...now(), status: "error" });
130
+ const e: WixEvent | null = featured.event;
131
+ // From the state as it is NOW (a filter tapped during the read stays), and with no message of
132
+ // an event that is gone.
133
+ if (!e?.id) return derive({ ...now(), status: "ready", eventId: "", eventTitle: "", sessions: [], starred: [], message: "" });
134
+ const settings = agendaSettingsOf(e);
135
+ const agenda = await readAgenda(e.id, settings.enabled, settings.zone);
136
+ if (mine !== loadSeq) return now();
137
+ // A failed read keeps the rows only when they are THIS event's: another event's sessions under
138
+ // this event's id would take stars for sessions it does not have.
139
+ if (!agenda.ok) {
140
+ const current = now();
141
+ const same = current.eventId === e.id;
142
+ const stars = same ? { ok: true as const, ids: current.starred } : readStars(e.id);
143
+ return derive({ ...current, status: "error", eventId: e.id, eventTitle: e.title ?? "", sessions: same ? current.sessions : [], starred: stars.ids, message: stars.ok ? current.message : unreadable() });
144
+ }
145
+ const stars = readStars(e.id);
146
+ return derive({ ...now(), status: "ready", eventId: e.id, eventTitle: e.title ?? "", sessions: agenda.sessions, starred: stars.ids, message: stars.ok ? "" : unreadable() });
147
+ }
148
+
149
+ const svc = defineService<S, {
150
+ load: (s: S, arg?: unknown) => Promise<S>;
151
+ refresh: (s: S, arg?: unknown) => Promise<S>;
152
+ toggleStar: (s: S, arg?: unknown) => S;
153
+ showMine: (s: S) => S;
154
+ showAll: (s: S) => S;
155
+ toggleMine: (s: S) => S;
156
+ openEvent: (s: S) => S;
157
+ openTab: (s: S, arg?: unknown) => S;
158
+ }>("himiConferenceAgenda", {
159
+ notHydrated: ["message"],
160
+ state: BOOT,
161
+ actions: {
162
+ load: (s, arg) => { stashCopy(arg); return load(s).then(commit); },
163
+ refresh: (s, arg) => { stashCopy(arg); return load(s.status === "error" ? { ...s, status: "loading" } : s).then(commit); },
164
+ toggleStar: (s, arg) => {
165
+ const id = String((arg as { id?: unknown } | undefined)?.id ?? "");
166
+ if (!s.eventId || !s.sessions.some((row) => row.id === id)) return s;
167
+ try {
168
+ toggleStar(s.eventId, id);
169
+ const stars = readStars(s.eventId);
170
+ return commit(derive({ ...s, starred: stars.ids, message: stars.ok ? "" : unreadable() }));
171
+ } catch {
172
+ return commit(derive({ ...s, starred: readStars(s.eventId).ids, message: copyParam("agenda.starFailed", "This session could not be saved to My Agenda. Try again.") }));
173
+ }
174
+ },
175
+ showMine: (s) => commit(derive({ ...s, filter: "mine" })),
176
+ showAll: (s) => commit(derive({ ...s, filter: "all" })),
177
+ toggleMine: (s) => commit(derive({ ...s, filter: s.filter === "mine" ? "all" : "mine" })),
178
+ // "Get Tickets": select the Tickets tab (a `_nav` tab directive).
179
+ openTab: (s, arg) => { const tab = String((arg as { tab?: unknown } | undefined)?.tab ?? ""); return tab ? navigate(s, { tab }) : s; },
180
+ openEvent: (s) => (s.eventId ? navigate(s, { screenId: `himi_event_${s.eventId}`, args: { id: s.eventId } }) : s),
181
+ },
182
+ });
183
+ export { svc };
@@ -0,0 +1,389 @@
1
+ // Tier-5 bundle: himi-conference-home — the conference template's Home, Speakers and Venue.
2
+ //
3
+ // Home shows the site's FEATURED event (_shared/featured-event.ts: the one on now, else the next
4
+ // to start) as a poster hero, the first sessions of its Wix Events agenda, the speakers and the
5
+ // workshops. Speakers and workshops have no Wix vertical: they are the app's own CMS collections
6
+ // (Wix Data), whose ids reach the worker as the `speakers` / `workshops` onAppear params, so a
7
+ // scaffold's own `himi_<app>_*` pair is the one read. The organiser edits all of it on the site.
8
+ //
9
+ // A failed event read is an error with Retry; no live or upcoming event is an empty state. A
10
+ // failed speakers or workshops read hides that section on Home and is an error with Retry on the
11
+ // Speakers screen; an empty collection hides it (Speakers: an empty state). Never sample rows.
12
+ import { defineService, navigate } from "@himalaya/state";
13
+ import { eventAddress, eventImage, eventLocation, startDateOf, type WixEvent } from "@himalaya/wix-events";
14
+ import { queryDataItems, type WixDataItem } from "@himalaya/wix-data";
15
+ import { wixMediaUrl, WIX_DETAIL_IMAGE } from "@himalaya/wix-media";
16
+ import { open as openUrl } from "@himalaya/open-url";
17
+ import { readFeaturedEvent } from "../_shared/featured-event.js";
18
+ import { agendaSettingsOf, readAgenda, type AgendaSession } from "../_shared/event-agenda.js";
19
+ import { registrationKindOf } from "../_shared/event-registration.js";
20
+ import { formatClock, formatDateMedium } from "../_shared/engine-intl.js";
21
+ import { signedInEmail } from "../_shared/himi-account.js";
22
+ import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
23
+
24
+ export interface SpeakerRow {
25
+ id: string;
26
+ name: string;
27
+ role: string;
28
+ noRole: boolean;
29
+ bio: string;
30
+ noBio: boolean;
31
+ image: string;
32
+ hasImage: boolean;
33
+ noImage: boolean;
34
+ initials: string;
35
+ linkedin: string;
36
+ noLinkedin: boolean;
37
+ twitter: string;
38
+ noTwitter: boolean;
39
+ website: string;
40
+ noWebsite: boolean;
41
+ /** No link of any kind: the links row is hidden. */
42
+ noLinks: boolean;
43
+ }
44
+ export interface WorkshopRow {
45
+ id: string;
46
+ /** "Workshop #1" — its place in the collection's order. */
47
+ label: string;
48
+ title: string;
49
+ description: string;
50
+ noDescription: boolean;
51
+ image: string;
52
+ hasImage: boolean;
53
+ noImage: boolean;
54
+ }
55
+ type Status = "loading" | "ready" | "error";
56
+ interface S {
57
+ status: Status;
58
+ eventId: string;
59
+ title: string;
60
+ /** "Jan 12, 2035, 9:00 AM" in the event's zone. */
61
+ dateLine: string;
62
+ venue: string;
63
+ noVenue: boolean;
64
+ address: string;
65
+ noAddress: boolean;
66
+ /** What "Get directions" searches for: the venue's own name or address, never a type word
67
+ * such as "Online"; empty hides the button. */
68
+ mapQuery: string;
69
+ noDirections: boolean;
70
+ /** "Jan 12, 2035, 9:00 AM | Bernal Plaza" — the hero's one line. */
71
+ heroLine: string;
72
+ image: string;
73
+ hasImage: boolean;
74
+ noImage: boolean;
75
+ /** Get Tickets / RSVP / Register — what the hero's button does for this event. */
76
+ ctaLabel: string;
77
+ agenda: AgendaSession[];
78
+ noAgenda: boolean;
79
+ agendaCountLabel: string;
80
+ speakers: SpeakerRow[];
81
+ speakersStatus: Status;
82
+ noSpeakers: boolean;
83
+ speakersErrored: boolean;
84
+ speakersNotErrored: boolean;
85
+ speakersLoading: boolean;
86
+ speakersNotLoading: boolean;
87
+ speakersNoEmpty: boolean;
88
+ workshops: WorkshopRow[];
89
+ noWorkshops: boolean;
90
+ /** The outcome line of the last link tap ("" when it opened). */
91
+ linkMessage: string;
92
+ emptyText: string;
93
+ errorText: string;
94
+ isLoading: boolean;
95
+ notLoading: boolean;
96
+ errored: boolean;
97
+ notErrored: boolean;
98
+ hasEvent: boolean;
99
+ noEvent: boolean;
100
+ noEmpty: boolean;
101
+ /** Home and Venue hide their content while loading, on an error and with no event. */
102
+ hideContent: boolean;
103
+ }
104
+
105
+ const AGENDA_PREVIEW = 5;
106
+ const CMS_LIMIT = 100;
107
+
108
+ const clean = (value: unknown): string => (typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "");
109
+ const field = (arg: unknown, key: string): string => clean((arg as Record<string, unknown> | undefined)?.[key]);
110
+
111
+ /** A link a CMS row holds: https only, and no `user@` part (in "https://x.com@evil.example" the
112
+ * host is evil.example). No `URL`: a bare iOS JSContext has none. A bare host ("linkedin.com/in/x")
113
+ * gets https. Anything else is no link. */
114
+ export function safeLink(raw: unknown): string {
115
+ let url = clean(raw);
116
+ if (!url) return "";
117
+ if (!/^[a-z][a-z0-9+.-]*:/i.test(url)) url = `https://${url.replace(/^\/+/, "")}`;
118
+ return /^https:\/\/[^/?#:@\s\\]+(?::\d+)?(?:[/?#]\S*)?$/i.test(url) ? url : "";
119
+ }
120
+
121
+ const initialsOf = (name: string): string => {
122
+ const words = name.split(/\s+/).filter(Boolean);
123
+ return ((words[0]?.[0] ?? "") + (words.length > 1 ? words[words.length - 1]?.[0] ?? "" : "")).toUpperCase();
124
+ };
125
+
126
+ /** CMS rows in the organiser's order (`order`, then as stored). */
127
+ function ordered(items: WixDataItem[]): Array<{ id: string; data: Record<string, unknown> }> {
128
+ return items
129
+ .map((item, index) => ({ id: clean(item.id) || clean(item.data?._id), data: item.data ?? {}, index }))
130
+ .filter((row) => !!row.id)
131
+ .sort((a, b) => {
132
+ const oa = Number(a.data.order), ob = Number(b.data.order);
133
+ const fa = Number.isFinite(oa) ? oa : Number.MAX_SAFE_INTEGER, fb = Number.isFinite(ob) ? ob : Number.MAX_SAFE_INTEGER;
134
+ return fa - fb || a.index - b.index;
135
+ });
136
+ }
137
+
138
+ export function speakerRow(id: string, data: Record<string, unknown>): SpeakerRow | null {
139
+ const name = clean(data.name) || clean(data.title);
140
+ if (!name) return null;
141
+ const image = wixMediaUrl(data.photo ?? data.image);
142
+ const role = clean(data.role), bio = clean(data.bio);
143
+ const linkedin = safeLink(data.linkedin), twitter = safeLink(data.twitter), website = safeLink(data.website);
144
+ return {
145
+ id, name, role, noRole: !role, bio, noBio: !bio,
146
+ image, hasImage: !!image, noImage: !image, initials: initialsOf(name),
147
+ linkedin, noLinkedin: !linkedin, twitter, noTwitter: !twitter, website, noWebsite: !website,
148
+ noLinks: !linkedin && !twitter && !website,
149
+ };
150
+ }
151
+
152
+ export function workshopRow(id: string, data: Record<string, unknown>, place: number): WorkshopRow | null {
153
+ const title = clean(data.title) || clean(data.name);
154
+ if (!title) return null;
155
+ const image = wixMediaUrl(data.photo ?? data.image);
156
+ const description = clean(data.description);
157
+ return {
158
+ id,
159
+ label: copyTemplate("home.workshopLabel", "Workshop #{n}", { n: place }),
160
+ title, description, noDescription: !description,
161
+ image, hasImage: !!image, noImage: !image,
162
+ };
163
+ }
164
+
165
+ type Read<T> = { ok: true; rows: T[] } | { ok: false; rows: T[] };
166
+ async function readCollection<T>(collectionId: string, map: (row: { id: string; data: Record<string, unknown> }, index: number) => T | null): Promise<Read<T>> {
167
+ // No collection named: the section is off (a scaffold that drops it from its config).
168
+ if (!collectionId) return { ok: true, rows: [] };
169
+ try {
170
+ const res = await queryDataItems(collectionId, CMS_LIMIT);
171
+ const rows: T[] = [];
172
+ for (const row of ordered(res.dataItems ?? [])) {
173
+ const mapped = map(row, rows.length);
174
+ if (mapped) rows.push(mapped);
175
+ }
176
+ return { ok: true, rows };
177
+ } catch {
178
+ return { ok: false, rows: [] };
179
+ }
180
+ }
181
+
182
+ /** The hero's date: "Jan 12, 2035, 9:00 AM", in the event's zone. "" with no valid start. */
183
+ export function heroDate(e: WixEvent, zone: string): string {
184
+ const start = new Date(startDateOf(e) ?? "");
185
+ if (Number.isNaN(start.getTime())) return copyParam("home.dateTbd", "Date to be announced");
186
+ return `${formatDateMedium(start, "en-US", zone || undefined)}, ${formatClock(start, "en-US", zone || undefined)}`;
187
+ }
188
+
189
+ function ctaLabelOf(e: WixEvent): string {
190
+ switch (registrationKindOf(e)) {
191
+ case "rsvp": return copyParam("home.rsvpCta", "RSVP");
192
+ case "external": return copyParam("home.registerCta", "Register");
193
+ case "tickets": return copyParam("home.ticketsCta", "Get Tickets");
194
+ default: return copyParam("home.detailsCta", "Event details");
195
+ }
196
+ }
197
+
198
+ function derive(s: S): S {
199
+ const loading = s.status === "loading", errored = s.status === "error";
200
+ const sLoading = s.speakersStatus === "loading", sErrored = s.speakersStatus === "error";
201
+ const hasEvent = !!s.eventId;
202
+ return {
203
+ ...s,
204
+ noVenue: !s.venue,
205
+ noAddress: !s.address,
206
+ noDirections: !s.mapQuery,
207
+ heroLine: [s.dateLine, s.venue].filter(Boolean).join(" | "),
208
+ hasImage: !!s.image,
209
+ noImage: !s.image,
210
+ noAgenda: s.agenda.length === 0,
211
+ noSpeakers: s.speakers.length === 0,
212
+ speakersLoading: sLoading,
213
+ speakersNotLoading: !sLoading,
214
+ speakersErrored: sErrored,
215
+ speakersNotErrored: !sErrored,
216
+ speakersNoEmpty: sLoading || sErrored || s.speakers.length > 0,
217
+ noWorkshops: s.workshops.length === 0,
218
+ isLoading: loading,
219
+ notLoading: !loading,
220
+ errored,
221
+ notErrored: !errored,
222
+ hasEvent,
223
+ noEvent: !hasEvent,
224
+ noEmpty: loading || errored || hasEvent,
225
+ hideContent: loading || errored || !hasEvent,
226
+ emptyText: copyParam("home.emptyText", "The next event will appear here once it is published."),
227
+ errorText: copyParam("home.errorText", "The event could not be loaded."),
228
+ };
229
+ }
230
+
231
+ const BOOT: S = derive({
232
+ status: "loading", eventId: "", title: "", dateLine: "", venue: "", noVenue: true, address: "", noAddress: true, mapQuery: "", noDirections: true,
233
+ heroLine: "", image: "", hasImage: false, noImage: true, ctaLabel: "",
234
+ agenda: [], noAgenda: true, agendaCountLabel: "",
235
+ speakers: [], speakersStatus: "loading", noSpeakers: true, speakersErrored: false, speakersNotErrored: true,
236
+ speakersLoading: true, speakersNotLoading: false, speakersNoEmpty: true,
237
+ workshops: [], noWorkshops: true,
238
+ linkMessage: "", emptyText: "", errorText: "",
239
+ isLoading: true, notLoading: false, errored: false, notErrored: true, hasEvent: false, noEvent: true, noEmpty: true, hideContent: true,
240
+ });
241
+
242
+ // The collections this run reads, from the newest onAppear: a refresh (Retry) has no params.
243
+ let speakersCollection = "";
244
+ let workshopsCollection = "";
245
+ let loadSeq = 0;
246
+ let latest: S = BOOT;
247
+ const commit = (next: S): S => (latest = next);
248
+ /** The runtime's state: it also holds one a host restored (hydrated), where `latest` is BOOT. */
249
+ const now = (): S => (svc.getState?.() as S | undefined) ?? latest;
250
+
251
+ async function load(_dispatched: S): Promise<S> {
252
+ const mine = ++loadSeq;
253
+ // The answer is built on the state as it is when the reads land (`base`), never the snapshot
254
+ // the load was dispatched with: a link tapped meanwhile keeps its message, an older one is cleared.
255
+ const tapsAtStart = linkTaps;
256
+ const base = (): S => { const current = now(); return { ...current, linkMessage: linkTaps > tapsAtStart ? current.linkMessage : "" }; };
257
+ const [featured, speakers, workshops] = await Promise.all([
258
+ // AGENDA: without it Wix leaves `agendaSettings` out, and the agenda would never be read.
259
+ readFeaturedEvent(["DETAILS", "REGISTRATION", "AGENDA"]),
260
+ readCollection(speakersCollection, (row) => speakerRow(row.id, row.data)),
261
+ readCollection(workshopsCollection, (row, index) => workshopRow(row.id, row.data, index + 1)),
262
+ ]);
263
+ const speakersPart = { speakers: speakers.rows, speakersStatus: (speakers.ok ? "ready" : "error") as Status, workshops: workshops.rows };
264
+ if (!featured.ok) {
265
+ if (mine !== loadSeq) return now();
266
+ return derive({ ...now(), ...speakersPart, status: "error" });
267
+ }
268
+ const e = featured.event;
269
+ if (!e?.id) {
270
+ if (mine !== loadSeq) return now();
271
+ return derive({ ...base(), ...speakersPart, status: "ready", eventId: "", title: "", dateLine: "", venue: "", address: "", mapQuery: "", image: "", ctaLabel: "", agenda: [], agendaCountLabel: "" });
272
+ }
273
+ const settings = agendaSettingsOf(e);
274
+ const agenda = await readAgenda(e.id, settings.enabled, settings.zone);
275
+ if (mine !== loadSeq) return now();
276
+ const venue = eventLocation(e);
277
+ const address = eventAddress(e);
278
+ return derive({
279
+ ...base(),
280
+ ...speakersPart,
281
+ status: "ready",
282
+ eventId: e.id,
283
+ title: clean(e.title) || copyParam("home.eventFallback", "Event"),
284
+ dateLine: heroDate(e, settings.zone),
285
+ venue: venue === "Location to be announced" ? copyParam("home.locationTbd", "Location to be announced") : venue,
286
+ // The full address, only when it says more than the venue's name.
287
+ address: address && address !== venue ? address : "",
288
+ // eventLocation falls back to the location TYPE ("Online", "Venue"); a maps search for that
289
+ // finds nothing, so directions use only the name and address Wix holds — and never for an
290
+ // online event, whose name is its provider ("Zoom"), not a place.
291
+ mapQuery: mapQueryOf(e.location as { name?: string; type?: string } | undefined, address),
292
+ image: eventImage(e, WIX_DETAIL_IMAGE),
293
+ ctaLabel: ctaLabelOf(e),
294
+ // A failed agenda read hides the preview; the Agenda tab says it failed and retries.
295
+ agenda: agenda.sessions.slice(0, AGENDA_PREVIEW),
296
+ agendaCountLabel: agenda.sessions.length ? copyTemplate("home.agendaCount", "All sessions ({n})", { n: agenda.sessions.length }) : "",
297
+ });
298
+ }
299
+
300
+ /** What "Get directions" searches for: the place's own name and address, deduped; nothing for an
301
+ * online event. */
302
+ export function mapQueryOf(location: { name?: string; type?: string } | undefined, address: string): string {
303
+ if (String(location?.type ?? "").toUpperCase() === "ONLINE") return "";
304
+ return [clean(location?.name), address].filter((part, i, all) => part && all.indexOf(part) === i).join(", ");
305
+ }
306
+
307
+ /** A maps search for the venue: the only link the Venue screen builds itself. */
308
+ export function directionsUrl(venue: string, address: string): string {
309
+ const query = [venue, address].filter(Boolean).join(", ");
310
+ return query ? `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(query)}` : "";
311
+ }
312
+
313
+ let linkTaps = 0;
314
+ let memberTaps = 0;
315
+
316
+ /** `read`, or `fallback` after `ms` where the engine has a timer. A bare JSContext has none. */
317
+ function within<T>(read: Promise<T>, ms: number, fallback: T): Promise<T> {
318
+ const host = globalThis as { setTimeout?: (fn: () => void, ms: number) => unknown; clearTimeout?: (timer: unknown) => void };
319
+ if (typeof host.setTimeout !== "function") return read;
320
+ return new Promise<T>((resolve) => {
321
+ const timer = host.setTimeout!(() => resolve(fallback), ms);
322
+ void read.then((value) => { host.clearTimeout?.(timer); resolve(value); });
323
+ });
324
+ }
325
+
326
+ async function openOut(url: string): Promise<S | undefined> {
327
+ const tap = ++linkTaps;
328
+ const failed = copyParam("home.linkFailed", "This link could not be opened.");
329
+ if (!url) return commit(derive({ ...now(), linkMessage: failed }));
330
+ let opened = false;
331
+ try { opened = (await openUrl(url)).opened === true; } catch { opened = false; }
332
+ if (tap !== linkTaps) return undefined;
333
+ const current = now();
334
+ if (opened && !current.linkMessage) return undefined;
335
+ return commit(derive({ ...current, linkMessage: opened ? "" : failed }));
336
+ }
337
+
338
+ const svc = defineService<S, {
339
+ load: (s: S, arg?: unknown) => Promise<S>;
340
+ refresh: (s: S, arg?: unknown) => Promise<S>;
341
+ openTickets: (s: S) => S;
342
+ openTab: (s: S, arg?: unknown) => S;
343
+ openSpeakerLink: (s: S, arg?: unknown) => Promise<S | undefined>;
344
+ openDirections: (s: S) => Promise<S | undefined>;
345
+ openForMember: (s: S, arg?: unknown) => Promise<S>;
346
+ }>("himiConferenceHome", {
347
+ notHydrated: ["linkMessage"],
348
+ state: BOOT,
349
+ actions: {
350
+ load: (s, arg) => {
351
+ stashCopy(arg);
352
+ speakersCollection = field(arg, "speakers");
353
+ workshopsCollection = field(arg, "workshops");
354
+ return load({ ...s, linkMessage: "" }).then(commit);
355
+ },
356
+ refresh: (s, arg) => {
357
+ stashCopy(arg);
358
+ return load({ ...s, status: s.status === "error" ? "loading" : s.status, speakersStatus: s.speakersStatus === "error" ? "loading" : s.speakersStatus }).then(commit);
359
+ },
360
+ // The featured event's own detail (its tickets, RSVP or registration).
361
+ openTickets: (s) => (s.eventId ? navigate(s, { screenId: `himi_event_${s.eventId}`, args: { id: s.eventId } }) : s),
362
+ // "See all" speakers, "Agenda & Tickets": select that tab (a `_nav` tab directive), never push a
363
+ // second copy of the tab's screen onto Home's stack.
364
+ openTab: (s, arg) => { const tab = field(arg, "tab"); return tab ? navigate(s, { tab }) : s; },
365
+ // The link is looked up in this worker's own rows: a tap names a speaker and a kind, never a URL.
366
+ openSpeakerLink: (s, arg) => {
367
+ const row = s.speakers.find((speaker) => speaker.id === field(arg, "id"));
368
+ const kind = field(arg, "kind");
369
+ const url = !row ? "" : kind === "linkedin" ? row.linkedin : kind === "twitter" ? row.twitter : kind === "website" ? row.website : "";
370
+ return openOut(url);
371
+ },
372
+ openDirections: async (s) => (s.mapQuery ? openOut(directionsUrl(s.mapQuery, "")) : s),
373
+ // A member screen (the chat): a member goes there; a guest gets the sign-in sheet first. The
374
+ // session is asked at the tap. Once signed in, the sheet closes and opens the screen on `returnTab`.
375
+ openForMember: async (_s, arg) => {
376
+ const screenId = field(arg, "screenId"), signInScreenId = field(arg, "signInScreenId");
377
+ if (!screenId) return now();
378
+ const mine = ++memberTaps;
379
+ const email = signInScreenId ? await within(signedInEmail(), 1500, "") : "";
380
+ if (mine !== memberTaps) return now();
381
+ if (!signInScreenId || email) return navigate(now(), { screenId });
382
+ const args: Record<string, string> = { mode: "signin", returnScreenId: screenId, modal: "1" };
383
+ if (field(arg, "returnTab")) args.returnTab = field(arg, "returnTab");
384
+ return navigate(now(), { screenId: signInScreenId, presentation: "sheet", args });
385
+ },
386
+ },
387
+ });
388
+ // No load at boot: each screen loads on appear, with its copy and its collection ids.
389
+ export { svc };