@wix/himalaya-cli 0.1151.0 → 0.1152.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.
@@ -11,7 +11,9 @@ import { normalizeEvent, eventDescription } from "../_shared/himi-events.js";
11
11
  import { ownerLoadError, isBridgeUnavailable, isOwnerPreviewDemo, shouldQueueOwnerWrite } from "../_shared/owner-load-error.js";
12
12
  import { DEMO_EVENTS, DEMO_NOTE, DEMO_SAVE_NOTE } from "../_shared/owner-preview-demo.js";
13
13
  import { stashCopy, copyParam } from "../_shared/himi-copy.js";
14
- import { get as dbGet, remove as dbRemove, enqueue as dbEnqueue, type DbEntity } from "../_shared/owner-local-db.js";
14
+ import { openRichLink } from "../_shared/rich-content-link.js";
15
+ import { richBody } from "../_shared/rich-body.js";
16
+ import { get as dbGet, upsert as dbUpsert, remove as dbRemove, enqueue as dbEnqueue, type DbEntity } from "../_shared/owner-local-db.js";
15
17
 
16
18
  // Offline-first (data-offline): the event DETAIL falls back to the last-synced
17
19
  // local `owner_events` row (put by the event form's write-behind) on a failed
@@ -20,6 +22,7 @@ import { get as dbGet, remove as dbRemove, enqueue as dbEnqueue, type DbEntity }
20
22
  // ENQUEUED for replay on reconnect. Every local-db call is wrapped so a build
21
23
  // without the `local_database` grant behaves exactly as before (online-only).
22
24
  const ENTITY = "owner_events";
25
+ async function cachePut(row: DbEntity): Promise<void> { try { await dbUpsert(ENTITY, row); } catch { /* capability not granted */ } }
23
26
  async function cacheDrop(id: string): Promise<void> { try { await dbRemove(ENTITY, id); } catch { /* capability not granted */ } }
24
27
  async function cacheGet(id: string): Promise<DbEntity | null> { try { return await dbGet(ENTITY, id); } catch { return null; } }
25
28
  async function queueWrite(actionId: string, params: Record<string, string>): Promise<void> { try { await dbEnqueue(actionId, params); } catch { /* capability not granted */ } }
@@ -33,6 +36,13 @@ interface EventState {
33
36
  title: string;
34
37
  subtitle: string;
35
38
  summary: string;
39
+ // Body ([rico] #3499) — RichContent binds bodyJson; the plain text shows when there is no document.
40
+ /** The v3 Ricos `description` (read with `fields=TEXTS`) as ONE document string; "" when there is none. */
41
+ bodyJson: string;
42
+ /** bodyJson !== "" — gates the plain text, because RichContent draws nothing for "". */
43
+ hasBodyJson: boolean;
44
+ /** The description's plain text (the document's own text, else the legacy description). */
45
+ bodyText: string;
36
46
  initial: string;
37
47
  image: string;
38
48
  dateLine: string;
@@ -55,6 +65,17 @@ interface EventState {
55
65
  }
56
66
 
57
67
  /* eslint-disable @typescript-eslint/no-explicit-any */
68
+ /** [rico] #3499 — keep the description's plain text with the event's cached row, so the offline detail shows it.
69
+ * Merged into the row the events list (or the form) wrote rather than replacing it; with no row yet, the
70
+ * loaded detail's own fields become one. */
71
+ async function cacheBodyText(s: EventState): Promise<void> {
72
+ if (s.status !== "ready" || !s.id) return;
73
+ const prev = await cacheGet(s.id);
74
+ await cachePut(prev ? { ...prev, bodyText: s.bodyText } : {
75
+ id: s.id, title: s.title, subtitle: s.subtitle, image: s.image, dateLine: s.dateLine, location: s.location,
76
+ statusLabel: s.statusLabel, registration: s.registration, bodyText: s.bodyText,
77
+ });
78
+ }
58
79
  function idFrom(arg: unknown, fallback = ""): string {
59
80
  return typeof arg === "string" ? arg : String((arg as any)?.id ?? fallback);
60
81
  }
@@ -97,6 +118,9 @@ function shape(s: Partial<EventState>): EventState {
97
118
  title: s.title ?? "",
98
119
  subtitle: s.subtitle ?? "",
99
120
  summary: s.summary ?? "",
121
+ bodyJson: s.bodyJson ?? "",
122
+ hasBodyJson: !!s.bodyJson,
123
+ bodyText: s.bodyText ?? "",
100
124
  initial: s.initial ?? "?",
101
125
  image,
102
126
  dateLine: s.dateLine ?? "—",
@@ -128,7 +152,9 @@ function demoDetail(s: EventState, id: string): EventState | null {
128
152
  status: "ready",
129
153
  title: d.title,
130
154
  subtitle: [d.dateLine, d.location].filter(Boolean).join(" · "),
131
- summary: d.description,
155
+ summary: "",
156
+ bodyJson: "",
157
+ bodyText: d.description,
132
158
  initial: (d.title[0] || "?").toUpperCase(),
133
159
  image: "",
134
160
  dateLine: d.dateLine,
@@ -151,7 +177,9 @@ function cachedDetail(s: EventState, row: DbEntity): EventState {
151
177
  status: "ready",
152
178
  title,
153
179
  subtitle: String(row.subtitle ?? [dateLine, location].filter((x) => x && x !== "—").join(" · ")),
154
- summary: String(row.summary ?? row.description ?? ""),
180
+ summary: "",
181
+ bodyJson: "",
182
+ bodyText: String(row.bodyText ?? row.summary ?? row.description ?? ""),
155
183
  initial: String(row.initial ?? (title[0] || "?")).slice(0, 1).toUpperCase(),
156
184
  image: String(row.image ?? ""),
157
185
  dateLine: dateLine || "—",
@@ -164,21 +192,27 @@ function cachedDetail(s: EventState, row: DbEntity): EventState {
164
192
  }
165
193
 
166
194
  async function refresh(prev: EventState, id: string): Promise<EventState> {
167
- const res = await getEvent(id);
195
+ // A bare read returns the base fieldset: DETAILS adds `shortDescription` (the teaser and the legacy body),
196
+ // TEXTS the Ricos `description`.
197
+ const res = await getEvent(id, { fields: ["DETAILS", "TEXTS"] });
168
198
  const ev = (res.event ?? res) as WixEvent;
169
199
  if (!ev || !(ev as any).id) {
170
200
  return shape({ ...prev, id, status: "error", title: "", error: copyParam("ownerEvent.errorNotFound", "event not found") });
171
201
  }
172
202
  const row = normalizeEvent(ev); // reuses date/location/status normalization
173
203
  const image = /^https?:\/\//.test(row.image) ? row.image : "";
174
- const desc = (eventDescription(ev) || "").trim();
204
+ const { bodyJson, bodyText } = richBody((ev as unknown as { description?: unknown }).description, (eventDescription(ev) || "").trim());
205
+ // The teaser stays above the body only when it says something the body does not.
206
+ const teaser = String((ev as any).shortDescription ?? "").trim();
175
207
  return shape({
176
208
  ...prev,
177
209
  id,
178
210
  status: "ready",
179
211
  title: row.title,
180
212
  subtitle: [row.dateLine, row.location].filter((x) => x && x !== "—").join(" · "),
181
- summary: desc,
213
+ summary: teaser && teaser !== bodyText.trim() ? teaser : "",
214
+ bodyJson,
215
+ bodyText,
182
216
  initial: (row.title[0] || "?").toUpperCase(),
183
217
  image,
184
218
  dateLine: row.dateLine || "—",
@@ -194,6 +228,7 @@ const svc = defineService<EventState, {
194
228
  load: (s: EventState, arg?: unknown) => Promise<EventState>;
195
229
  retry: (s: EventState) => Promise<EventState>;
196
230
  delete: (s: EventState) => Promise<EventState>;
231
+ openLink: (s: EventState, arg?: unknown) => Promise<EventState>;
197
232
  }>("himiOwnerLiteEvent", {
198
233
  state: shape({ status: "loading" }),
199
234
  actions: {
@@ -208,7 +243,9 @@ const svc = defineService<EventState, {
208
243
  return shape({ ...s, status: "error", error: "Sample item not found." });
209
244
  }
210
245
  try {
211
- return await refresh(shape({ ...s, id, status: "loading" }), id);
246
+ const loaded = await refresh(shape({ ...s, id, status: "loading" }), id);
247
+ await cacheBodyText(loaded);
248
+ return loaded;
212
249
  } catch (e) {
213
250
  // Offline: fall back to the last-synced local row before the demo/error paths.
214
251
  const cached = await cacheGet(id);
@@ -229,7 +266,9 @@ const svc = defineService<EventState, {
229
266
  return shape({ ...s, status: "error", error: "Sample item not found." });
230
267
  }
231
268
  try {
232
- return await refresh(shape({ ...s, status: "loading" }), s.id);
269
+ const loaded = await refresh(shape({ ...s, status: "loading" }), s.id);
270
+ await cacheBodyText(loaded);
271
+ return loaded;
233
272
  } catch (e) {
234
273
  const cached = await cacheGet(s.id);
235
274
  if (cached) return cachedDetail(s, cached);
@@ -256,6 +295,11 @@ const svc = defineService<EventState, {
256
295
  return shape({ ...s, actionMessage: ownerLoadError(e) });
257
296
  }
258
297
  },
298
+ // [rico] #3499 — a link tapped in the RichContent description.
299
+ openLink: async (s, arg) => shape({
300
+ ...s,
301
+ actionMessage: (await openRichLink(arg)) ? "" : copyParam("ownerEvent.linkOpenFailed", "This link could not be opened."),
302
+ }),
259
303
  },
260
304
  });
261
305
 
@@ -81263,6 +81263,48 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
81263
81263
  }
81264
81264
  }
81265
81265
  },
81266
+ {
81267
+ "id": "event_body",
81268
+ "body": {
81269
+ "package": "himalaya",
81270
+ "type": "RichContent",
81271
+ "props": {
81272
+ "documentJsonPath": "$service:himiOwnerLiteEvent.bodyJson",
81273
+ "onLink": {
81274
+ "actionId": "tier5.himiOwnerLiteEvent.openLink"
81275
+ },
81276
+ "fallback": {
81277
+ "id": "",
81278
+ "body": {
81279
+ "package": "himalaya",
81280
+ "type": "Text",
81281
+ "props": {
81282
+ "text": "$service:himiOwnerLiteEvent.bodyText",
81283
+ "style": "body",
81284
+ "color": "textPrimary",
81285
+ "collapseWhenEmpty": true
81286
+ }
81287
+ }
81288
+ }
81289
+ }
81290
+ }
81291
+ },
81292
+ {
81293
+ "id": "event_body_text",
81294
+ "body": {
81295
+ "package": "himalaya",
81296
+ "type": "Text",
81297
+ "props": {
81298
+ "text": "$service:himiOwnerLiteEvent.bodyText",
81299
+ "style": "body",
81300
+ "color": "textPrimary",
81301
+ "collapseWhenEmpty": true
81302
+ }
81303
+ },
81304
+ "modifiers": {
81305
+ "hiddenPath": "$service:himiOwnerLiteEvent.hasBodyJson"
81306
+ }
81307
+ },
81266
81308
  {
81267
81309
  "id": "event_info_card",
81268
81310
  "body": {
@@ -81601,7 +81643,8 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
81601
81643
  "contentType": "application/javascript+ts-bundle",
81602
81644
  "declaredCapabilities": [
81603
81645
  "wix_api",
81604
- "local_database"
81646
+ "local_database",
81647
+ "open_url"
81605
81648
  ],
81606
81649
  "minBinaryVersion": "0.1.0",
81607
81650
  "bundleVersion": "0.0.1"
@@ -11,7 +11,9 @@ import { normalizeEvent, eventDescription } from "../_shared/himi-events.js";
11
11
  import { ownerLoadError, isBridgeUnavailable, isOwnerPreviewDemo, shouldQueueOwnerWrite } from "../_shared/owner-load-error.js";
12
12
  import { DEMO_EVENTS, DEMO_NOTE, DEMO_SAVE_NOTE } from "../_shared/owner-preview-demo.js";
13
13
  import { stashCopy, copyParam } from "../_shared/himi-copy.js";
14
- import { get as dbGet, remove as dbRemove, enqueue as dbEnqueue, type DbEntity } from "../_shared/owner-local-db.js";
14
+ import { openRichLink } from "../_shared/rich-content-link.js";
15
+ import { richBody } from "../_shared/rich-body.js";
16
+ import { get as dbGet, upsert as dbUpsert, remove as dbRemove, enqueue as dbEnqueue, type DbEntity } from "../_shared/owner-local-db.js";
15
17
 
16
18
  // Offline-first (data-offline): the event DETAIL falls back to the last-synced
17
19
  // local `owner_events` row (put by the event form's write-behind) on a failed
@@ -20,6 +22,7 @@ import { get as dbGet, remove as dbRemove, enqueue as dbEnqueue, type DbEntity }
20
22
  // ENQUEUED for replay on reconnect. Every local-db call is wrapped so a build
21
23
  // without the `local_database` grant behaves exactly as before (online-only).
22
24
  const ENTITY = "owner_events";
25
+ async function cachePut(row: DbEntity): Promise<void> { try { await dbUpsert(ENTITY, row); } catch { /* capability not granted */ } }
23
26
  async function cacheDrop(id: string): Promise<void> { try { await dbRemove(ENTITY, id); } catch { /* capability not granted */ } }
24
27
  async function cacheGet(id: string): Promise<DbEntity | null> { try { return await dbGet(ENTITY, id); } catch { return null; } }
25
28
  async function queueWrite(actionId: string, params: Record<string, string>): Promise<void> { try { await dbEnqueue(actionId, params); } catch { /* capability not granted */ } }
@@ -33,6 +36,13 @@ interface EventState {
33
36
  title: string;
34
37
  subtitle: string;
35
38
  summary: string;
39
+ // Body ([rico] #3499) — RichContent binds bodyJson; the plain text shows when there is no document.
40
+ /** The v3 Ricos `description` (read with `fields=TEXTS`) as ONE document string; "" when there is none. */
41
+ bodyJson: string;
42
+ /** bodyJson !== "" — gates the plain text, because RichContent draws nothing for "". */
43
+ hasBodyJson: boolean;
44
+ /** The description's plain text (the document's own text, else the legacy description). */
45
+ bodyText: string;
36
46
  initial: string;
37
47
  image: string;
38
48
  dateLine: string;
@@ -55,6 +65,17 @@ interface EventState {
55
65
  }
56
66
 
57
67
  /* eslint-disable @typescript-eslint/no-explicit-any */
68
+ /** [rico] #3499 — keep the description's plain text with the event's cached row, so the offline detail shows it.
69
+ * Merged into the row the events list (or the form) wrote rather than replacing it; with no row yet, the
70
+ * loaded detail's own fields become one. */
71
+ async function cacheBodyText(s: EventState): Promise<void> {
72
+ if (s.status !== "ready" || !s.id) return;
73
+ const prev = await cacheGet(s.id);
74
+ await cachePut(prev ? { ...prev, bodyText: s.bodyText } : {
75
+ id: s.id, title: s.title, subtitle: s.subtitle, image: s.image, dateLine: s.dateLine, location: s.location,
76
+ statusLabel: s.statusLabel, registration: s.registration, bodyText: s.bodyText,
77
+ });
78
+ }
58
79
  function idFrom(arg: unknown, fallback = ""): string {
59
80
  return typeof arg === "string" ? arg : String((arg as any)?.id ?? fallback);
60
81
  }
@@ -97,6 +118,9 @@ function shape(s: Partial<EventState>): EventState {
97
118
  title: s.title ?? "",
98
119
  subtitle: s.subtitle ?? "",
99
120
  summary: s.summary ?? "",
121
+ bodyJson: s.bodyJson ?? "",
122
+ hasBodyJson: !!s.bodyJson,
123
+ bodyText: s.bodyText ?? "",
100
124
  initial: s.initial ?? "?",
101
125
  image,
102
126
  dateLine: s.dateLine ?? "—",
@@ -128,7 +152,9 @@ function demoDetail(s: EventState, id: string): EventState | null {
128
152
  status: "ready",
129
153
  title: d.title,
130
154
  subtitle: [d.dateLine, d.location].filter(Boolean).join(" · "),
131
- summary: d.description,
155
+ summary: "",
156
+ bodyJson: "",
157
+ bodyText: d.description,
132
158
  initial: (d.title[0] || "?").toUpperCase(),
133
159
  image: "",
134
160
  dateLine: d.dateLine,
@@ -151,7 +177,9 @@ function cachedDetail(s: EventState, row: DbEntity): EventState {
151
177
  status: "ready",
152
178
  title,
153
179
  subtitle: String(row.subtitle ?? [dateLine, location].filter((x) => x && x !== "—").join(" · ")),
154
- summary: String(row.summary ?? row.description ?? ""),
180
+ summary: "",
181
+ bodyJson: "",
182
+ bodyText: String(row.bodyText ?? row.summary ?? row.description ?? ""),
155
183
  initial: String(row.initial ?? (title[0] || "?")).slice(0, 1).toUpperCase(),
156
184
  image: String(row.image ?? ""),
157
185
  dateLine: dateLine || "—",
@@ -164,21 +192,27 @@ function cachedDetail(s: EventState, row: DbEntity): EventState {
164
192
  }
165
193
 
166
194
  async function refresh(prev: EventState, id: string): Promise<EventState> {
167
- const res = await getEvent(id);
195
+ // A bare read returns the base fieldset: DETAILS adds `shortDescription` (the teaser and the legacy body),
196
+ // TEXTS the Ricos `description`.
197
+ const res = await getEvent(id, { fields: ["DETAILS", "TEXTS"] });
168
198
  const ev = (res.event ?? res) as WixEvent;
169
199
  if (!ev || !(ev as any).id) {
170
200
  return shape({ ...prev, id, status: "error", title: "", error: copyParam("ownerEvent.errorNotFound", "event not found") });
171
201
  }
172
202
  const row = normalizeEvent(ev); // reuses date/location/status normalization
173
203
  const image = /^https?:\/\//.test(row.image) ? row.image : "";
174
- const desc = (eventDescription(ev) || "").trim();
204
+ const { bodyJson, bodyText } = richBody((ev as unknown as { description?: unknown }).description, (eventDescription(ev) || "").trim());
205
+ // The teaser stays above the body only when it says something the body does not.
206
+ const teaser = String((ev as any).shortDescription ?? "").trim();
175
207
  return shape({
176
208
  ...prev,
177
209
  id,
178
210
  status: "ready",
179
211
  title: row.title,
180
212
  subtitle: [row.dateLine, row.location].filter((x) => x && x !== "—").join(" · "),
181
- summary: desc,
213
+ summary: teaser && teaser !== bodyText.trim() ? teaser : "",
214
+ bodyJson,
215
+ bodyText,
182
216
  initial: (row.title[0] || "?").toUpperCase(),
183
217
  image,
184
218
  dateLine: row.dateLine || "—",
@@ -194,6 +228,7 @@ const svc = defineService<EventState, {
194
228
  load: (s: EventState, arg?: unknown) => Promise<EventState>;
195
229
  retry: (s: EventState) => Promise<EventState>;
196
230
  delete: (s: EventState) => Promise<EventState>;
231
+ openLink: (s: EventState, arg?: unknown) => Promise<EventState>;
197
232
  }>("himiOwnerLiteEvent", {
198
233
  state: shape({ status: "loading" }),
199
234
  actions: {
@@ -208,7 +243,9 @@ const svc = defineService<EventState, {
208
243
  return shape({ ...s, status: "error", error: "Sample item not found." });
209
244
  }
210
245
  try {
211
- return await refresh(shape({ ...s, id, status: "loading" }), id);
246
+ const loaded = await refresh(shape({ ...s, id, status: "loading" }), id);
247
+ await cacheBodyText(loaded);
248
+ return loaded;
212
249
  } catch (e) {
213
250
  // Offline: fall back to the last-synced local row before the demo/error paths.
214
251
  const cached = await cacheGet(id);
@@ -229,7 +266,9 @@ const svc = defineService<EventState, {
229
266
  return shape({ ...s, status: "error", error: "Sample item not found." });
230
267
  }
231
268
  try {
232
- return await refresh(shape({ ...s, status: "loading" }), s.id);
269
+ const loaded = await refresh(shape({ ...s, status: "loading" }), s.id);
270
+ await cacheBodyText(loaded);
271
+ return loaded;
233
272
  } catch (e) {
234
273
  const cached = await cacheGet(s.id);
235
274
  if (cached) return cachedDetail(s, cached);
@@ -256,6 +295,11 @@ const svc = defineService<EventState, {
256
295
  return shape({ ...s, actionMessage: ownerLoadError(e) });
257
296
  }
258
297
  },
298
+ // [rico] #3499 — a link tapped in the RichContent description.
299
+ openLink: async (s, arg) => shape({
300
+ ...s,
301
+ actionMessage: (await openRichLink(arg)) ? "" : copyParam("ownerEvent.linkOpenFailed", "This link could not be opened."),
302
+ }),
259
303
  },
260
304
  });
261
305
 
@@ -73229,6 +73229,48 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
73229
73229
  }
73230
73230
  }
73231
73231
  },
73232
+ {
73233
+ "id": "event_body",
73234
+ "body": {
73235
+ "package": "himalaya",
73236
+ "type": "RichContent",
73237
+ "props": {
73238
+ "documentJsonPath": "$service:himiOwnerLiteEvent.bodyJson",
73239
+ "onLink": {
73240
+ "actionId": "tier5.himiOwnerLiteEvent.openLink"
73241
+ },
73242
+ "fallback": {
73243
+ "id": "",
73244
+ "body": {
73245
+ "package": "himalaya",
73246
+ "type": "Text",
73247
+ "props": {
73248
+ "text": "$service:himiOwnerLiteEvent.bodyText",
73249
+ "style": "body",
73250
+ "color": "textPrimary",
73251
+ "collapseWhenEmpty": true
73252
+ }
73253
+ }
73254
+ }
73255
+ }
73256
+ }
73257
+ },
73258
+ {
73259
+ "id": "event_body_text",
73260
+ "body": {
73261
+ "package": "himalaya",
73262
+ "type": "Text",
73263
+ "props": {
73264
+ "text": "$service:himiOwnerLiteEvent.bodyText",
73265
+ "style": "body",
73266
+ "color": "textPrimary",
73267
+ "collapseWhenEmpty": true
73268
+ }
73269
+ },
73270
+ "modifiers": {
73271
+ "hiddenPath": "$service:himiOwnerLiteEvent.hasBodyJson"
73272
+ }
73273
+ },
73232
73274
  {
73233
73275
  "id": "event_info_card",
73234
73276
  "body": {
@@ -73567,7 +73609,8 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
73567
73609
  "contentType": "application/javascript+ts-bundle",
73568
73610
  "declaredCapabilities": [
73569
73611
  "wix_api",
73570
- "local_database"
73612
+ "local_database",
73613
+ "open_url"
73571
73614
  ],
73572
73615
  "minBinaryVersion": "0.1.0",
73573
73616
  "bundleVersion": "0.0.1"
@@ -11,7 +11,9 @@ import { normalizeEvent, eventDescription } from "../_shared/himi-events.js";
11
11
  import { ownerLoadError, isBridgeUnavailable, isOwnerPreviewDemo, shouldQueueOwnerWrite } from "../_shared/owner-load-error.js";
12
12
  import { DEMO_EVENTS, DEMO_NOTE, DEMO_SAVE_NOTE } from "../_shared/owner-preview-demo.js";
13
13
  import { stashCopy, copyParam } from "../_shared/himi-copy.js";
14
- import { get as dbGet, remove as dbRemove, enqueue as dbEnqueue, type DbEntity } from "../_shared/owner-local-db.js";
14
+ import { openRichLink } from "../_shared/rich-content-link.js";
15
+ import { richBody } from "../_shared/rich-body.js";
16
+ import { get as dbGet, upsert as dbUpsert, remove as dbRemove, enqueue as dbEnqueue, type DbEntity } from "../_shared/owner-local-db.js";
15
17
 
16
18
  // Offline-first (data-offline): the event DETAIL falls back to the last-synced
17
19
  // local `owner_events` row (put by the event form's write-behind) on a failed
@@ -20,6 +22,7 @@ import { get as dbGet, remove as dbRemove, enqueue as dbEnqueue, type DbEntity }
20
22
  // ENQUEUED for replay on reconnect. Every local-db call is wrapped so a build
21
23
  // without the `local_database` grant behaves exactly as before (online-only).
22
24
  const ENTITY = "owner_events";
25
+ async function cachePut(row: DbEntity): Promise<void> { try { await dbUpsert(ENTITY, row); } catch { /* capability not granted */ } }
23
26
  async function cacheDrop(id: string): Promise<void> { try { await dbRemove(ENTITY, id); } catch { /* capability not granted */ } }
24
27
  async function cacheGet(id: string): Promise<DbEntity | null> { try { return await dbGet(ENTITY, id); } catch { return null; } }
25
28
  async function queueWrite(actionId: string, params: Record<string, string>): Promise<void> { try { await dbEnqueue(actionId, params); } catch { /* capability not granted */ } }
@@ -33,6 +36,13 @@ interface EventState {
33
36
  title: string;
34
37
  subtitle: string;
35
38
  summary: string;
39
+ // Body ([rico] #3499) — RichContent binds bodyJson; the plain text shows when there is no document.
40
+ /** The v3 Ricos `description` (read with `fields=TEXTS`) as ONE document string; "" when there is none. */
41
+ bodyJson: string;
42
+ /** bodyJson !== "" — gates the plain text, because RichContent draws nothing for "". */
43
+ hasBodyJson: boolean;
44
+ /** The description's plain text (the document's own text, else the legacy description). */
45
+ bodyText: string;
36
46
  initial: string;
37
47
  image: string;
38
48
  dateLine: string;
@@ -55,6 +65,17 @@ interface EventState {
55
65
  }
56
66
 
57
67
  /* eslint-disable @typescript-eslint/no-explicit-any */
68
+ /** [rico] #3499 — keep the description's plain text with the event's cached row, so the offline detail shows it.
69
+ * Merged into the row the events list (or the form) wrote rather than replacing it; with no row yet, the
70
+ * loaded detail's own fields become one. */
71
+ async function cacheBodyText(s: EventState): Promise<void> {
72
+ if (s.status !== "ready" || !s.id) return;
73
+ const prev = await cacheGet(s.id);
74
+ await cachePut(prev ? { ...prev, bodyText: s.bodyText } : {
75
+ id: s.id, title: s.title, subtitle: s.subtitle, image: s.image, dateLine: s.dateLine, location: s.location,
76
+ statusLabel: s.statusLabel, registration: s.registration, bodyText: s.bodyText,
77
+ });
78
+ }
58
79
  function idFrom(arg: unknown, fallback = ""): string {
59
80
  return typeof arg === "string" ? arg : String((arg as any)?.id ?? fallback);
60
81
  }
@@ -97,6 +118,9 @@ function shape(s: Partial<EventState>): EventState {
97
118
  title: s.title ?? "",
98
119
  subtitle: s.subtitle ?? "",
99
120
  summary: s.summary ?? "",
121
+ bodyJson: s.bodyJson ?? "",
122
+ hasBodyJson: !!s.bodyJson,
123
+ bodyText: s.bodyText ?? "",
100
124
  initial: s.initial ?? "?",
101
125
  image,
102
126
  dateLine: s.dateLine ?? "—",
@@ -128,7 +152,9 @@ function demoDetail(s: EventState, id: string): EventState | null {
128
152
  status: "ready",
129
153
  title: d.title,
130
154
  subtitle: [d.dateLine, d.location].filter(Boolean).join(" · "),
131
- summary: d.description,
155
+ summary: "",
156
+ bodyJson: "",
157
+ bodyText: d.description,
132
158
  initial: (d.title[0] || "?").toUpperCase(),
133
159
  image: "",
134
160
  dateLine: d.dateLine,
@@ -151,7 +177,9 @@ function cachedDetail(s: EventState, row: DbEntity): EventState {
151
177
  status: "ready",
152
178
  title,
153
179
  subtitle: String(row.subtitle ?? [dateLine, location].filter((x) => x && x !== "—").join(" · ")),
154
- summary: String(row.summary ?? row.description ?? ""),
180
+ summary: "",
181
+ bodyJson: "",
182
+ bodyText: String(row.bodyText ?? row.summary ?? row.description ?? ""),
155
183
  initial: String(row.initial ?? (title[0] || "?")).slice(0, 1).toUpperCase(),
156
184
  image: String(row.image ?? ""),
157
185
  dateLine: dateLine || "—",
@@ -164,21 +192,27 @@ function cachedDetail(s: EventState, row: DbEntity): EventState {
164
192
  }
165
193
 
166
194
  async function refresh(prev: EventState, id: string): Promise<EventState> {
167
- const res = await getEvent(id);
195
+ // A bare read returns the base fieldset: DETAILS adds `shortDescription` (the teaser and the legacy body),
196
+ // TEXTS the Ricos `description`.
197
+ const res = await getEvent(id, { fields: ["DETAILS", "TEXTS"] });
168
198
  const ev = (res.event ?? res) as WixEvent;
169
199
  if (!ev || !(ev as any).id) {
170
200
  return shape({ ...prev, id, status: "error", title: "", error: copyParam("ownerEvent.errorNotFound", "event not found") });
171
201
  }
172
202
  const row = normalizeEvent(ev); // reuses date/location/status normalization
173
203
  const image = /^https?:\/\//.test(row.image) ? row.image : "";
174
- const desc = (eventDescription(ev) || "").trim();
204
+ const { bodyJson, bodyText } = richBody((ev as unknown as { description?: unknown }).description, (eventDescription(ev) || "").trim());
205
+ // The teaser stays above the body only when it says something the body does not.
206
+ const teaser = String((ev as any).shortDescription ?? "").trim();
175
207
  return shape({
176
208
  ...prev,
177
209
  id,
178
210
  status: "ready",
179
211
  title: row.title,
180
212
  subtitle: [row.dateLine, row.location].filter((x) => x && x !== "—").join(" · "),
181
- summary: desc,
213
+ summary: teaser && teaser !== bodyText.trim() ? teaser : "",
214
+ bodyJson,
215
+ bodyText,
182
216
  initial: (row.title[0] || "?").toUpperCase(),
183
217
  image,
184
218
  dateLine: row.dateLine || "—",
@@ -194,6 +228,7 @@ const svc = defineService<EventState, {
194
228
  load: (s: EventState, arg?: unknown) => Promise<EventState>;
195
229
  retry: (s: EventState) => Promise<EventState>;
196
230
  delete: (s: EventState) => Promise<EventState>;
231
+ openLink: (s: EventState, arg?: unknown) => Promise<EventState>;
197
232
  }>("himiOwnerLiteEvent", {
198
233
  state: shape({ status: "loading" }),
199
234
  actions: {
@@ -208,7 +243,9 @@ const svc = defineService<EventState, {
208
243
  return shape({ ...s, status: "error", error: "Sample item not found." });
209
244
  }
210
245
  try {
211
- return await refresh(shape({ ...s, id, status: "loading" }), id);
246
+ const loaded = await refresh(shape({ ...s, id, status: "loading" }), id);
247
+ await cacheBodyText(loaded);
248
+ return loaded;
212
249
  } catch (e) {
213
250
  // Offline: fall back to the last-synced local row before the demo/error paths.
214
251
  const cached = await cacheGet(id);
@@ -229,7 +266,9 @@ const svc = defineService<EventState, {
229
266
  return shape({ ...s, status: "error", error: "Sample item not found." });
230
267
  }
231
268
  try {
232
- return await refresh(shape({ ...s, status: "loading" }), s.id);
269
+ const loaded = await refresh(shape({ ...s, status: "loading" }), s.id);
270
+ await cacheBodyText(loaded);
271
+ return loaded;
233
272
  } catch (e) {
234
273
  const cached = await cacheGet(s.id);
235
274
  if (cached) return cachedDetail(s, cached);
@@ -256,6 +295,11 @@ const svc = defineService<EventState, {
256
295
  return shape({ ...s, actionMessage: ownerLoadError(e) });
257
296
  }
258
297
  },
298
+ // [rico] #3499 — a link tapped in the RichContent description.
299
+ openLink: async (s, arg) => shape({
300
+ ...s,
301
+ actionMessage: (await openRichLink(arg)) ? "" : copyParam("ownerEvent.linkOpenFailed", "This link could not be opened."),
302
+ }),
259
303
  },
260
304
  });
261
305