@wix/himalaya-cli 0.1852.0 → 0.1853.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 (149) hide show
  1. package/dist/cli.mjs +95 -32
  2. package/guides/himi-json-output.md +8 -2
  3. package/guides/one-app-section-mappings.md +1 -1
  4. package/guides/one-app-to-himi-app.md +19 -6
  5. package/package.json +2 -2
  6. package/template-icons/bare-fashion.png +0 -0
  7. package/templates/bare-fashion/README.md +52 -0
  8. package/templates/bare-fashion/config.ts +474 -0
  9. package/templates/bare-fashion/dev/index.ts +16526 -0
  10. package/templates/bare-fashion/himalaya.content.json +70 -0
  11. package/templates/bare-fashion/himalaya.template.json +18 -0
  12. package/templates/bare-fashion/icon.png +0 -0
  13. package/templates/bare-fashion/platforms.json +3 -0
  14. package/templates/bare-fashion/tier5-src/_shared/app-locale.ts +70 -0
  15. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-book.ts +116 -0
  16. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-countries.ts +261 -0
  17. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-bag-count.ts +24 -0
  18. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-categories.ts +48 -0
  19. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-facets.ts +265 -0
  20. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-load-error.ts +38 -0
  21. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-product-card.ts +136 -0
  22. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-store-options.ts +129 -0
  23. package/templates/bare-fashion/tier5-src/_shared/branded-lite-hosted.ts +282 -0
  24. package/templates/bare-fashion/tier5-src/_shared/collection-contract.ts +228 -0
  25. package/templates/bare-fashion/tier5-src/_shared/collection-query.ts +201 -0
  26. package/templates/bare-fashion/tier5-src/_shared/collection-service.ts +429 -0
  27. package/templates/bare-fashion/tier5-src/_shared/engine-intl.ts +529 -0
  28. package/templates/bare-fashion/tier5-src/_shared/himi-account.ts +209 -0
  29. package/templates/bare-fashion/tier5-src/_shared/himi-copy.ts +123 -0
  30. package/templates/bare-fashion/tier5-src/_shared/himi-layouts.ts +142 -0
  31. package/templates/bare-fashion/tier5-src/_shared/himi-store-categories.ts +108 -0
  32. package/templates/bare-fashion/tier5-src/_shared/himi-store-saved.ts +57 -0
  33. package/templates/bare-fashion/tier5-src/_shared/himi-store.ts +7 -0
  34. package/templates/bare-fashion/tier5-src/_shared/himi-text.ts +24 -0
  35. package/templates/bare-fashion/tier5-src/_shared/hosted-checkout.ts +70 -0
  36. package/templates/bare-fashion/tier5-src/_shared/live-session.ts +172 -0
  37. package/templates/bare-fashion/tier5-src/_shared/local-preferences.ts +38 -0
  38. package/templates/bare-fashion/tier5-src/_shared/member-access.ts +63 -0
  39. package/templates/bare-fashion/tier5-src/_shared/member-avatar.ts +76 -0
  40. package/templates/bare-fashion/tier5-src/_shared/member-orders.ts +8 -0
  41. package/templates/bare-fashion/tier5-src/_shared/online-actions.ts +76 -0
  42. package/templates/bare-fashion/tier5-src/_shared/owner-load-error.ts +348 -0
  43. package/templates/bare-fashion/tier5-src/himi-bare-fashion-account/index.ts +127 -0
  44. package/templates/bare-fashion/tier5-src/himi-bare-fashion-address-form/index.ts +367 -0
  45. package/templates/bare-fashion/tier5-src/himi-bare-fashion-addresses/index.ts +202 -0
  46. package/templates/bare-fashion/tier5-src/himi-bare-fashion-appearance/index.ts +73 -0
  47. package/templates/bare-fashion/tier5-src/himi-bare-fashion-cart/index.ts +540 -0
  48. package/templates/bare-fashion/tier5-src/himi-bare-fashion-collection/index.ts +111 -0
  49. package/templates/bare-fashion/tier5-src/himi-bare-fashion-home/index.ts +241 -0
  50. package/templates/bare-fashion/tier5-src/himi-bare-fashion-nav/index.ts +56 -0
  51. package/templates/bare-fashion/tier5-src/himi-bare-fashion-order/index.ts +437 -0
  52. package/templates/bare-fashion/tier5-src/himi-bare-fashion-product/index.ts +650 -0
  53. package/templates/bare-fashion/tier5-src/himi-bare-fashion-products/index.ts +142 -0
  54. package/templates/bare-fashion/tier5-src/himi-bare-fashion-saved/index.ts +45 -0
  55. package/templates/bare-fashion/tier5-src/himi-bare-fashion-search/index.ts +199 -0
  56. package/templates/bare-fashion/tier5-src/himi-bare-fashion-shop/index.ts +79 -0
  57. package/templates/bare-fashion/tier5-src/himi-bare-fashion-sign-in/index.ts +269 -0
  58. package/templates/bare-fashion/tier5-src/himi-bare-fashion-wallet/index.ts +224 -0
  59. package/templates/bare-fashion/tier5-src/himi-branded-lite-info/index.ts +209 -0
  60. package/templates/bare-fashion/tier5-src/himi-branded-lite-orders/index.ts +327 -0
  61. package/templates/bare-fashion/tier5-src/wix-spaces-collections/index.ts +48 -0
  62. package/templates/bare-fashion/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  63. package/templates/bare-fashion/tier5-src/wix-spaces-view-profile/index.ts +119 -0
  64. package/templates/bare-fashion/tokens.json +348 -0
  65. package/templates/beauty-salon/tier5-src/_shared/collection-query.ts +8 -0
  66. package/templates/beauty-salon/tier5-src/_shared/collection-service.ts +7 -1
  67. package/templates/beauty-salon-owner/tier5-src/_shared/collection-query.ts +8 -0
  68. package/templates/beauty-salon-owner/tier5-src/_shared/collection-service.ts +7 -1
  69. package/templates/branded-lite/recipes/upcoming-bookings.json +118 -6
  70. package/templates/branded-lite/tier5-src/_shared/collection-query-legacy.ts +7 -0
  71. package/templates/branded-lite/tier5-src/_shared/collection-query.ts +7 -0
  72. package/templates/branded-lite/tier5-src/_shared/collection-service.ts +7 -1
  73. package/templates/branded-lite/tier5-src/_shared/events-inline-options.ts +55 -3
  74. package/templates/branded-lite/tier5-src/_shared/events-inline.ts +5 -3
  75. package/templates/branded-lite/tier5-src/_shared/upcoming-bookings-section.ts +15 -4
  76. package/templates/branded-lite/tier5-src/himi-events-list/index.ts +17 -0
  77. package/templates/brandy/tier5-src/_shared/collection-query-legacy.ts +7 -0
  78. package/templates/brandy/tier5-src/_shared/collection-query.ts +7 -0
  79. package/templates/brandy/tier5-src/_shared/collection-service.ts +7 -1
  80. package/templates/community-club/tier5-src/_shared/collection-query.ts +8 -0
  81. package/templates/community-club/tier5-src/_shared/collection-service.ts +7 -1
  82. package/templates/community-club/tier5-src/_shared/events-inline-options.ts +77 -0
  83. package/templates/community-club/tier5-src/himi-events-list/index.ts +17 -0
  84. package/templates/community-club-owner/tier5-src/_shared/collection-query.ts +8 -0
  85. package/templates/community-club-owner/tier5-src/_shared/collection-service.ts +7 -1
  86. package/templates/conference/tier5-src/_shared/collection-query.ts +8 -0
  87. package/templates/conference/tier5-src/_shared/collection-service.ts +7 -1
  88. package/templates/conference/tier5-src/_shared/events-inline-options.ts +77 -0
  89. package/templates/conference/tier5-src/himi-events-list/index.ts +17 -0
  90. package/templates/events-meetups/tier5-src/_shared/collection-query.ts +8 -0
  91. package/templates/events-meetups/tier5-src/_shared/collection-service.ts +7 -1
  92. package/templates/events-meetups/tier5-src/_shared/events-inline-options.ts +77 -0
  93. package/templates/events-meetups/tier5-src/himi-events-list/index.ts +17 -0
  94. package/templates/events-meetups-owner/tier5-src/_shared/collection-query.ts +8 -0
  95. package/templates/events-meetups-owner/tier5-src/_shared/collection-service.ts +7 -1
  96. package/templates/fitness-gym/tier5-src/_shared/collection-query.ts +8 -0
  97. package/templates/fitness-gym/tier5-src/_shared/collection-service.ts +7 -1
  98. package/templates/gym-fitness/tier5-src/_shared/collection-query.ts +8 -0
  99. package/templates/gym-fitness/tier5-src/_shared/collection-service.ts +7 -1
  100. package/templates/gym-fitness/tier5-src/_shared/events-inline-options.ts +77 -0
  101. package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +17 -0
  102. package/templates/gym-fitness-owner/tier5-src/_shared/collection-query.ts +8 -0
  103. package/templates/gym-fitness-owner/tier5-src/_shared/collection-service.ts +7 -1
  104. package/templates/medical-services/tier5-src/_shared/collection-query.ts +8 -0
  105. package/templates/medical-services/tier5-src/_shared/collection-service.ts +7 -1
  106. package/templates/nonprofit-cause/tier5-src/_shared/collection-query.ts +8 -0
  107. package/templates/nonprofit-cause/tier5-src/_shared/collection-service.ts +7 -1
  108. package/templates/nonprofit-cause/tier5-src/_shared/events-inline-options.ts +77 -0
  109. package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +17 -0
  110. package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-query.ts +8 -0
  111. package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-service.ts +7 -1
  112. package/templates/owner-lite/tier5-src/_shared/collection-query.ts +8 -0
  113. package/templates/owner-lite/tier5-src/_shared/collection-service.ts +7 -1
  114. package/templates/personal-fitness-trainer/tier5-src/_shared/collection-query.ts +8 -0
  115. package/templates/personal-fitness-trainer/tier5-src/_shared/collection-service.ts +7 -1
  116. package/templates/podcast-creator/tier5-src/_shared/collection-query.ts +8 -0
  117. package/templates/podcast-creator/tier5-src/_shared/collection-service.ts +7 -1
  118. package/templates/podcast-creator/tier5-src/_shared/events-inline-options.ts +77 -0
  119. package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +17 -0
  120. package/templates/podcast-creator-owner/tier5-src/_shared/collection-query.ts +8 -0
  121. package/templates/podcast-creator-owner/tier5-src/_shared/collection-service.ts +7 -1
  122. package/templates/portfolio-creative/tier5-src/_shared/collection-query.ts +8 -0
  123. package/templates/portfolio-creative/tier5-src/_shared/collection-service.ts +7 -1
  124. package/templates/portfolio-creative/tier5-src/_shared/events-inline-options.ts +77 -0
  125. package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +17 -0
  126. package/templates/portfolio-creative-owner/tier5-src/_shared/collection-query.ts +8 -0
  127. package/templates/portfolio-creative-owner/tier5-src/_shared/collection-service.ts +7 -1
  128. package/templates/restaurant/tier5-src/_shared/collection-query.ts +8 -0
  129. package/templates/restaurant/tier5-src/_shared/collection-service.ts +7 -1
  130. package/templates/restaurant/tier5-src/_shared/events-inline-options.ts +77 -0
  131. package/templates/restaurant/tier5-src/himi-events-list/index.ts +17 -0
  132. package/templates/restaurant-owner/tier5-src/_shared/collection-query.ts +8 -0
  133. package/templates/restaurant-owner/tier5-src/_shared/collection-service.ts +7 -1
  134. package/templates/retail-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
  135. package/templates/retail-store/tier5-src/_shared/collection-query.ts +7 -0
  136. package/templates/retail-store/tier5-src/_shared/collection-service.ts +7 -1
  137. package/templates/retail-store-owner/tier5-src/_shared/collection-query.ts +8 -0
  138. package/templates/retail-store-owner/tier5-src/_shared/collection-service.ts +7 -1
  139. package/templates/salon-spa/tier5-src/_shared/collection-query.ts +8 -0
  140. package/templates/salon-spa/tier5-src/_shared/collection-service.ts +7 -1
  141. package/templates/wholesale-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
  142. package/templates/wholesale-store/tier5-src/_shared/collection-query.ts +7 -0
  143. package/templates/wholesale-store/tier5-src/_shared/collection-service.ts +7 -1
  144. package/templates/yoga-studio/tier5-src/_shared/collection-query.ts +8 -0
  145. package/templates/yoga-studio/tier5-src/_shared/collection-service.ts +7 -1
  146. package/templates/yoga-studio/tier5-src/_shared/events-inline-options.ts +77 -0
  147. package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +17 -0
  148. package/templates/yoga-studio-owner/tier5-src/_shared/collection-query.ts +8 -0
  149. package/templates/yoga-studio-owner/tier5-src/_shared/collection-service.ts +7 -1
@@ -1,11 +1,12 @@
1
1
  {
2
- "_recipe": "A page's upcoming bookings: the signed-in member's next bookings as rows (what, when, staff and place; a tap opens that booking on My Bookings), their latest past bookings under a Past heading when the source shows them, the section's See All button when there are more upcoming ones, the source's empty text, and a sign-in state for a guest. ONE node, always mounted. Service: registerUpcomingBookingsSection(svc, { limit, showPast, emptyText }).",
2
+ "_recipe": "A page's upcoming bookings: the signed-in member's next bookings as rows (what, when, staff and place; a tap opens that booking on My Bookings), the section's See All button when there are more upcoming ones, the source's empty text, and a sign-in state for a guest. When the source shows previous bookings, a History block under them, as the source's does: a \"History\" heading with a Show All link to My Bookings, the member's latest past booking (what, when, staff and place) with a Book Again button (opens the service), or the source's empty state when the member has none. `{{id}}.past.again` is removed when the scaffold has no service screen. ONE node, always mounted. Service: registerUpcomingBookingsSection(svc, { limit, showPast, pastLimit, emptyText }).",
3
3
  "_placeholders": {
4
4
  "svc": "service name the page worker registered with registerUpcomingBookingsSection",
5
5
  "id": "unique node id prefix for this section",
6
6
  "signInScreen": "the screen the sign-in button opens, himi_sign_in",
7
7
  "seeAllLabel": "the See All button's label",
8
- "seeAllScreen": "the bookings screen, himi_bookings: See All, a row and a past row open it"
8
+ "seeAllScreen": "the bookings screen, himi_bookings: See All, a row and a past row open it",
9
+ "serviceScreen": "the service screen, himi_service: Book Again on a past booking opens it"
9
10
  },
10
11
  "node": {
11
12
  "id": "{{id}}.bookings",
@@ -238,11 +239,53 @@
238
239
  "id": "{{id}}.pastHead",
239
240
  "body": {
240
241
  "package": "himalaya",
241
- "type": "Text",
242
+ "type": "HStack",
242
243
  "props": {
243
- "text": "Past",
244
- "style": "bodyEmphasis"
244
+ "spacing": 8,
245
+ "alignment": "center",
246
+ "children": [
247
+ {
248
+ "id": "{{id}}.pastHead.title",
249
+ "body": {
250
+ "package": "himalaya",
251
+ "type": "Text",
252
+ "props": {
253
+ "text": "History",
254
+ "style": "bodyEmphasis"
255
+ }
256
+ }
257
+ },
258
+ {
259
+ "id": "",
260
+ "body": {
261
+ "package": "himalaya",
262
+ "type": "Spacer",
263
+ "props": {}
264
+ }
265
+ },
266
+ {
267
+ "id": "{{id}}.pastHead.all",
268
+ "body": {
269
+ "package": "himalaya",
270
+ "type": "Button",
271
+ "props": {
272
+ "title": "Show All",
273
+ "style": "tertiary",
274
+ "size": "md",
275
+ "action": {
276
+ "actionId": "himi.open",
277
+ "params": {
278
+ "screenId": "{{seeAllScreen}}"
279
+ }
280
+ }
281
+ }
282
+ }
283
+ }
284
+ ]
245
285
  }
286
+ },
287
+ "modifiers": {
288
+ "fillMaxWidth": true
246
289
  }
247
290
  },
248
291
  {
@@ -304,6 +347,31 @@
304
347
  "modifiers": {
305
348
  "hiddenPath": "$item.noDetail"
306
349
  }
350
+ },
351
+ {
352
+ "id": "{{id}}.past.again",
353
+ "body": {
354
+ "package": "himalaya",
355
+ "type": "Button",
356
+ "props": {
357
+ "title": "Book Again",
358
+ "style": "secondary",
359
+ "size": "sm",
360
+ "action": {
361
+ "actionId": "himi.open",
362
+ "params": {
363
+ "screenId": "{{serviceScreen}}",
364
+ "id": "$item.serviceId"
365
+ }
366
+ }
367
+ }
368
+ },
369
+ "modifiers": {
370
+ "hiddenPath": "$item.noBookAgain",
371
+ "padding": {
372
+ "top": 6
373
+ }
374
+ }
307
375
  }
308
376
  ]
309
377
  }
@@ -331,13 +399,57 @@
331
399
  "modifiers": {
332
400
  "hiddenPath": "$service:{{svc}}.noPast"
333
401
  }
402
+ },
403
+ {
404
+ "id": "{{id}}.pastEmpty",
405
+ "body": {
406
+ "package": "himalaya",
407
+ "type": "VStack",
408
+ "props": {
409
+ "spacing": 4,
410
+ "alignment": "leading",
411
+ "children": [
412
+ {
413
+ "id": "{{id}}.pastEmpty.title",
414
+ "body": {
415
+ "package": "himalaya",
416
+ "type": "Text",
417
+ "props": {
418
+ "text": "You've Got Nothing Booked at the Moment",
419
+ "style": "bodyEmphasis"
420
+ }
421
+ }
422
+ },
423
+ {
424
+ "id": "{{id}}.pastEmpty.text",
425
+ "body": {
426
+ "package": "himalaya",
427
+ "type": "Text",
428
+ "props": {
429
+ "text": "You'll see all your future bookings here.",
430
+ "style": "footnote",
431
+ "color": "textSecondary"
432
+ }
433
+ }
434
+ }
435
+ ]
436
+ }
437
+ },
438
+ "modifiers": {
439
+ "hiddenPath": "$service:{{svc}}.noPastEmpty",
440
+ "fillMaxWidth": true,
441
+ "padding": {
442
+ "top": 8,
443
+ "bottom": 8
444
+ }
445
+ }
334
446
  }
335
447
  ]
336
448
  }
337
449
  },
338
450
  "modifiers": {
339
451
  "fillMaxWidth": true,
340
- "hiddenPath": "$service:{{svc}}.noPast"
452
+ "hiddenPath": "$service:{{svc}}.noHistory"
341
453
  }
342
454
  }
343
455
  ]
@@ -7,6 +7,10 @@ export interface CollectionQuery {
7
7
  filter: string;
8
8
  sort: 'default' | 'az' | 'za';
9
9
  savedIds: string[];
10
+ /** What the list is limited to beyond the controls above (a domain's own selection, e.g. the events of some categories), as one
11
+ * canonical string. Part of the criteria, so a list opened on another selection never shows or restores this one's rows. Absent
12
+ * when there is none: criteria without it keep the key they always had. */
13
+ scope?: string;
10
14
  }
11
15
  export interface CollectionPage<Row> {
12
16
  items: Row[];
@@ -42,11 +46,14 @@ export interface CollectionQuerySource<Row> {
42
46
  * key carries the account, and a purge tears parked workers down). */
43
47
  clearOnError?(error: unknown): boolean;
44
48
  }
49
+ /** A scope is read back by its domain, so it is never cut: this exceeds the largest selection the events list encodes (100 ids of 64 characters, about 6.9k). */
50
+ const SCOPE_MAX = 8192;
45
51
  const normalize = (q: Partial<CollectionQuery>): CollectionQuery => ({
46
52
  query: typeof q.query === 'string' ? q.query.trim().slice(0, 256) : '',
47
53
  filter: typeof q.filter === 'string' ? q.filter.slice(0, 256) : 'all',
48
54
  sort: q.sort === 'az' || q.sort === 'za' ? q.sort : 'default',
49
55
  savedIds: Array.isArray(q.savedIds) ? [...new Set(q.savedIds.filter(id => typeof id === 'string' && id.length > 0 && id.length <= 256))].slice(0, 500) : [],
56
+ ...(typeof q.scope === 'string' && q.scope ? { scope: q.scope.slice(0, SCOPE_MAX) } : {}),
50
57
  });
51
58
  const copyQuery = (q: CollectionQuery): CollectionQuery => ({ ...q, savedIds: [...q.savedIds] });
52
59
 
@@ -8,6 +8,10 @@ export interface CollectionQuery {
8
8
  filter: string;
9
9
  sort: 'default' | 'az' | 'za';
10
10
  savedIds: string[];
11
+ /** What the list is limited to beyond the controls above (a domain's own selection, e.g. the events of some categories), as one
12
+ * canonical string. Part of the criteria, so a list opened on another selection never shows or restores this one's rows. Absent
13
+ * when there is none: criteria without it keep the key they always had. */
14
+ scope?: string;
11
15
  }
12
16
  export interface CollectionPage<Row> {
13
17
  items: Row[];
@@ -52,11 +56,14 @@ export interface CollectionReadOptions {
52
56
  cache: 'only-if-cached' | 'reload';
53
57
  onCacheResult(metadata: ReadMetadata): void;
54
58
  }
59
+ /** A scope is read back by its domain, so it is never cut: this exceeds the largest selection the events list encodes (100 ids of 64 characters, about 6.9k). */
60
+ const SCOPE_MAX = 8192;
55
61
  const normalize = (q: Partial<CollectionQuery>): CollectionQuery => ({
56
62
  query: typeof q.query === 'string' ? q.query.trim().slice(0, 256) : '',
57
63
  filter: typeof q.filter === 'string' ? q.filter.slice(0, 256) : 'all',
58
64
  sort: q.sort === 'az' || q.sort === 'za' ? q.sort : 'default',
59
65
  savedIds: Array.isArray(q.savedIds) ? [...new Set(q.savedIds.filter(id => typeof id === 'string' && id.length > 0 && id.length <= 256))].slice(0, 500) : [],
66
+ ...(typeof q.scope === 'string' && q.scope ? { scope: q.scope.slice(0, SCOPE_MAX) } : {}),
60
67
  });
61
68
  const copyQuery = (q: CollectionQuery): CollectionQuery => ({ ...q, savedIds: [...q.savedIds] });
62
69
 
@@ -19,6 +19,8 @@ interface BackendCollection {
19
19
  /** Sees the load action's argument (the screen's onAppear params) BEFORE the query runs. A returned
20
20
  * `{ filter, sort }` resets the criteria for that load (a screen that always opens on one view). */
21
21
  onLoad?(arg: unknown): CollectionCriteriaReset | void;
22
+ /** The collection's own selection as part of every query's criteria (see `CollectionQuery.scope`); "" for none. */
23
+ scope?(): string;
22
24
  controller: ReturnType<typeof createCollectionQuery<CollectionRow>>;
23
25
  apply(state: State, page: CollectionQueryState<CollectionRow>): State;
24
26
  }
@@ -288,7 +290,7 @@ export function decorateCollection(name: string, def: { state: State; actions?:
288
290
  // A screen with no search field clears a query an older screen persisted, or it narrows every view for good.
289
291
  if (typeof input.query === 'string') prefs.query = input.query.slice(0, 256);
290
292
  };
291
- const criteria = () => ({ query: prefs.query, sort: prefs.sort, filter: prefs.filter, savedIds: prefs.filter === 'saved' ? prefs.savedIds : [] });
293
+ const criteria = () => ({ query: prefs.query, sort: prefs.sort, filter: prefs.filter, savedIds: prefs.filter === 'saved' ? prefs.savedIds : [], ...(backend?.scope ? { scope: backend.scope() } : {}) });
292
294
  const criteriaKey = () => JSON.stringify(criteria());
293
295
  actions.collectionDismissFilters = change(() => { filtersPresented = false; });
294
296
  actions.collectionFilters = change(() => { filtersPresented = !filtersPresented; });
@@ -378,6 +380,9 @@ export function defineBackendCollection<S extends object, Row extends object>(na
378
380
  /** The load action's argument (onAppear params beyond `copy`), before the query runs — for a
379
381
  * domain setting that rides the descriptor, e.g. My Bookings' `weeklyGoal`. */
380
382
  onLoad?(arg: unknown): CollectionCriteriaReset | void;
383
+ /** A selection the list is limited to, as one canonical string ("" for none): it joins the criteria, so another selection is another
384
+ * result set (no stale rows behind a revalidation, no restore of another selection's pages) and `source` reads it off `criteria.scope`. */
385
+ scope?(): string;
381
386
  state: S;
382
387
  source: CollectionQuerySource<Row>;
383
388
  apply(state: S, page: CollectionQueryState<Row>): S;
@@ -397,6 +402,7 @@ export function defineBackendCollection<S extends object, Row extends object>(na
397
402
  restorePagesOnLoad: options.restorePagesOnLoad,
398
403
  readLifecycle: options.readLifecycle,
399
404
  onLoad: avatar ? arg => { avatar.onLoad(arg); return options.onLoad?.(arg); } : options.onLoad,
405
+ scope: options.scope,
400
406
  controller: controller as unknown as BackendCollection['controller'],
401
407
  apply: (state, page) => {
402
408
  const applied = { ...options.apply(state as S, page as unknown as CollectionQueryState<Row>), ...(options.readLifecycle ? { readStatus: page.read } : {}) } as State;
@@ -3,10 +3,19 @@
3
3
  export interface EventsInlineOptions {
4
4
  /** How many events the section shows. Clamped to 1..10; default 3. */
5
5
  limit?: number;
6
+ /** Show only events in these categories (Wix event category ids). Empty or absent: every category. */
7
+ categoryIds?: readonly string[];
8
+ /** Show only these events (Wix event ids). Empty or absent: every event. */
9
+ eventIds?: readonly string[];
6
10
  }
7
11
 
12
+ /** The events a list is limited to: both lists empty is no limit. */
13
+ export interface EventsSelection { categoryIds: string[]; eventIds: string[] }
14
+
8
15
  export const EVENTS_INLINE_DEFAULT_LIMIT = 3;
9
16
  export const EVENTS_INLINE_MAX_LIMIT = 10;
17
+ /** More ids than this are dropped: a selection is a handful of categories or events, and each id rides the query. */
18
+ export const EVENTS_SELECTION_MAX_IDS = 50;
10
19
 
11
20
  /** A bad or missing limit is the default, never an error: the value arrives from a generated recipe. */
12
21
  export function eventsInlineLimit(value: unknown): number {
@@ -15,11 +24,54 @@ export function eventsInlineLimit(value: unknown): number {
15
24
  return Math.min(EVENTS_INLINE_MAX_LIMIT, Math.max(1, Math.trunc(n)));
16
25
  }
17
26
 
18
- /** Events that have not finished: not started yet, or still running (a festival on its second day is still on). */
19
- export function upcomingFilter(nowIso: string): Record<string, unknown> {
27
+ /** Wix ids are UUIDs; anything else (a route value is user-controllable text) never becomes part of a query. */
28
+ const ID = /^[A-Za-z0-9_-]{1,64}$/;
29
+
30
+ /** The ids in a list, or in a comma-separated string (how a `himi.open` link carries them): valid, distinct, at most 50. */
31
+ export function eventsSelectionIds(value: unknown): string[] {
32
+ const parts = Array.isArray(value) ? value : typeof value === "string" ? value.split(",") : [];
33
+ const ids = parts.flatMap((part) => (typeof part === "string" && ID.test(part.trim()) ? [part.trim()] : []));
34
+ return [...new Set(ids)].slice(0, EVENTS_SELECTION_MAX_IDS);
35
+ }
36
+
37
+ export function eventsSelectionOf(source: { categoryIds?: unknown; eventIds?: unknown } | undefined): EventsSelection {
38
+ return { categoryIds: eventsSelectionIds(source?.categoryIds), eventIds: eventsSelectionIds(source?.eventIds) };
39
+ }
40
+
41
+ /** A selection as the canonical string a collection carries in its criteria (`CollectionQuery.scope`): "" for none, so no scope is set. */
42
+ export function eventsSelectionScope(selection: EventsSelection): string {
43
+ return hasEventsSelection(selection) ? JSON.stringify({ categoryIds: selection.categoryIds, eventIds: selection.eventIds }) : "";
44
+ }
45
+
46
+ /** The selection a scope string names (every id is checked again: a scope is data that crossed a cache). Anything unreadable is none. */
47
+ export function eventsSelectionFromScope(scope: unknown): EventsSelection {
48
+ if (typeof scope !== "string" || !scope) return { categoryIds: [], eventIds: [] };
49
+ try { return eventsSelectionOf(JSON.parse(scope) as { categoryIds?: unknown; eventIds?: unknown }); } catch { return { categoryIds: [], eventIds: [] }; }
50
+ }
51
+
52
+ /** Whether a selection limits anything. */
53
+ export function hasEventsSelection(selection: EventsSelection): boolean {
54
+ return selection.categoryIds.length > 0 || selection.eventIds.length > 0;
55
+ }
56
+
57
+ /**
58
+ * The query filter of a selection: events in any of the categories (`categories.id $hasSome`, which a visitor may query) and events
59
+ * among the chosen ones (`id $in`). A selection naming both narrows by both. `limitIds` further narrows the chosen events, for
60
+ * a list that also shows only the visitor's saved events: an id both lists agree on, so a saved event outside the selection stays out.
61
+ */
62
+ export function eventsSelectionFilter(selection: EventsSelection, limitIds?: readonly string[]): Record<string, unknown> {
63
+ const ids = limitIds && selection.eventIds.length ? selection.eventIds.filter((id) => limitIds.includes(id)) : limitIds ? [...limitIds] : selection.eventIds;
64
+ return {
65
+ ...(selection.categoryIds.length ? { "categories.id": { $hasSome: selection.categoryIds } } : {}),
66
+ ...(limitIds || selection.eventIds.length ? { id: { $in: ids } } : {}),
67
+ };
68
+ }
69
+
70
+ /** Events that have not finished: not started yet, or still running (a festival on its second day is still on). Narrowed to a selection when given one. */
71
+ export function upcomingFilter(nowIso: string, selection?: EventsSelection): Record<string, unknown> {
20
72
  return {
21
73
  status: { $ne: "DRAFT" },
22
74
  $or: [{ "dateAndTimeSettings.startDate": { $gte: nowIso } }, { "dateAndTimeSettings.endDate": { $gte: nowIso } }],
75
+ ...(selection ? eventsSelectionFilter(selection) : {}),
23
76
  };
24
77
  }
25
-
@@ -11,9 +11,9 @@ import { share as shareSheet } from "@himalaya/share";
11
11
  import { normalizeEvent } from "./himi-events";
12
12
  import { copyParam, stashCopy } from "./himi-copy.js";
13
13
  import { withDateBadge, withRegistration, type ListEventRow } from "./events-card.js";
14
- import { eventsInlineLimit, upcomingFilter, type EventsInlineOptions } from "./events-inline-options.js";
14
+ import { eventsInlineLimit, eventsSelectionOf, upcomingFilter, type EventsInlineOptions } from "./events-inline-options.js";
15
15
 
16
- export { EVENTS_INLINE_DEFAULT_LIMIT, EVENTS_INLINE_MAX_LIMIT, eventsInlineLimit, upcomingFilter, type EventsInlineOptions } from "./events-inline-options.js";
16
+ export { EVENTS_INLINE_DEFAULT_LIMIT, EVENTS_INLINE_MAX_LIMIT, eventsInlineLimit, eventsSelectionOf, upcomingFilter, type EventsInlineOptions } from "./events-inline-options.js";
17
17
 
18
18
  export interface EventsInlineState {
19
19
  status: "loading" | "ready" | "error";
@@ -42,6 +42,8 @@ function derive(state: Omit<EventsInlineState, "isLoading" | "notLoading" | "isE
42
42
 
43
43
  export function registerEventsInline(serviceName: string, options: EventsInlineOptions = {}) {
44
44
  const limit = eventsInlineLimit(options.limit);
45
+ // A section limited to categories or to chosen events (the source's own selection) reads only those, and counts only those for See all.
46
+ const selection = eventsSelectionOf(options);
45
47
  const initial = derive({ status: "loading", rows: [], hasMore: false, emptyText: "", emptyBody: "" });
46
48
  return defineService<EventsInlineState, {
47
49
  load: (state: EventsInlineState, arg?: unknown) => Promise<EventsInlineState>;
@@ -54,7 +56,7 @@ export function registerEventsInline(serviceName: string, options: EventsInlineO
54
56
  try {
55
57
  const res = await queryEvents({
56
58
  limit, offset: 0, fields: ["DETAILS", "REGISTRATION", "URLS"],
57
- query: { filter: upcomingFilter(new Date().toISOString()),
59
+ query: { filter: upcomingFilter(new Date().toISOString(), selection),
58
60
  sort: [{ fieldName: "dateAndTimeSettings.startDate", order: "ASC" }, { fieldName: "id", order: "ASC" }] },
59
61
  });
60
62
  const raw: WixEvent[] = (res.events ?? []).filter((event) => !!event.id);
@@ -2,7 +2,9 @@
2
2
  // shows them, their latest past ones. It reads through the same member-scoped read as My Bookings (himi_bookings), so a booking
3
3
  // shows only for the member whose email it carries, and a guest or a refused member gets the sign-in state instead of a read.
4
4
  // limit -> at most N bookings per list, and `noMore` is false when the member has more upcoming ones (See All shows then),
5
- // showPast -> also the latest past bookings (the source's `previousBookings.enabled`),
5
+ // showPast -> also the History block under the upcoming ones (the source's `previousBookings.enabled`): its heading and Show All link,
6
+ // the latest past bookings (`pastLimit`) with Book Again, or the source's empty state when the member has none,
7
+ // pastLimit-> at most N past bookings in History (the source's section shows 1; default: `limit`),
6
8
  // emptyText-> the source's own empty line (unset: the stock one).
7
9
  // A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipe upcoming-bookings.json).
8
10
  import { defineService } from "@himalaya/state";
@@ -14,8 +16,10 @@ import { memberAccess, memberAccessDenied, memberChanged } from "./member-access
14
16
  export interface UpcomingBookingsOptions {
15
17
  /** Show at most this many bookings in each list. */
16
18
  limit: number;
17
- /** Also show the member's latest past bookings. */
19
+ /** Also show the History block: the member's latest past bookings, or its empty state. */
18
20
  showPast?: boolean;
21
+ /** Show at most this many past bookings in History (the source's section shows 1). Default: `limit`. */
22
+ pastLimit?: number;
19
23
  /** The source section's own text for "no upcoming bookings". */
20
24
  emptyText?: string;
21
25
  }
@@ -26,6 +30,8 @@ export interface BookingCard {
26
30
  when: string;
27
31
  /** The staff member and the place, "" when the booking names neither. */
28
32
  detail: string; noDetail: boolean;
33
+ /** The service a past booking can be booked again from; "" (and no Book Again button) when the record names none. */
34
+ serviceId: string; noBookAgain: boolean;
29
35
  a11y: string;
30
36
  }
31
37
 
@@ -38,6 +44,10 @@ export interface UpcomingBookingsState {
38
44
  emptyText: string;
39
45
  notLoading: boolean; notErrored: boolean; notSignedOut: boolean;
40
46
  noUpcoming: boolean; noPast: boolean;
47
+ /** The History block is hidden: nothing shown yet, or a guest. Once a member's read answered it stays, with the past bookings or the empty state. */
48
+ noHistory: boolean;
49
+ /** The member has no past booking (History says so, as the source's does). */
50
+ noPastEmpty: boolean;
41
51
  /** The member has no upcoming booking (shown only once the read answered for a signed-in member). */
42
52
  noEmpty: boolean;
43
53
  /** false when the member has more upcoming bookings than the section shows. */
@@ -46,7 +56,7 @@ export interface UpcomingBookingsState {
46
56
 
47
57
  const card = (row: MemberBookingRow): BookingCard => {
48
58
  const detail = [row.staff, row.placeName].filter(Boolean).join(" · ");
49
- return { id: row.id, title: row.title, when: row.subtitle, detail, noDetail: !detail, a11y: [row.title, row.subtitle, detail].filter(Boolean).join(", ") };
59
+ return { id: row.id, title: row.title, when: row.subtitle, detail, noDetail: !detail, serviceId: row.serviceId, noBookAgain: !row.serviceId, a11y: [row.title, row.subtitle, detail].filter(Boolean).join(", ") };
50
60
  };
51
61
 
52
62
  export function registerUpcomingBookingsSection(serviceName: string, options: UpcomingBookingsOptions) {
@@ -55,6 +65,7 @@ export function registerUpcomingBookingsSection(serviceName: string, options: Up
55
65
  emptyText: options.emptyText?.trim() || copyParam("upcomingBookings.emptyText", "You don't have any upcoming bookings."),
56
66
  notLoading: status !== "loading", notErrored: status !== "error", notSignedOut: !signedOut,
57
67
  noUpcoming: !upcoming.length, noPast: !past.length,
68
+ noHistory: !(status === "ready" && !signedOut), noPastEmpty: !(status === "ready" && !signedOut && !past.length),
58
69
  noEmpty: !(status === "ready" && !signedOut && !upcoming.length),
59
70
  noMore: !more,
60
71
  });
@@ -82,7 +93,7 @@ export function registerUpcomingBookingsSection(serviceName: string, options: Up
82
93
  const read = (filter: string, sort: "default" | "za") => fetchMemberBookings({ query: "", filter, sort, savedIds: [] }, "", now, member);
83
94
  const [next, previous] = await Promise.all([read("value:Upcoming", "default"), options.showPast ? read("value:Past", "za") : undefined]);
84
95
  if (seq !== sequence) return undefined;
85
- return view("ready", false, next.items.slice(0, options.limit).map(card), (previous?.items ?? []).slice(0, options.limit).map(card),
96
+ return view("ready", false, next.items.slice(0, options.limit).map(card), (previous?.items ?? []).slice(0, options.pastLimit ?? options.limit).map(card),
86
97
  next.items.length > options.limit || !!next.nextCursor);
87
98
  } catch (error) {
88
99
  if (seq !== sequence) return undefined;
@@ -7,6 +7,7 @@ import { offsetPage } from "../_shared/offset-page.js";
7
7
  import { copyParam } from "../_shared/himi-copy.js";
8
8
  import { eventPageUrlOf, registrationUi } from "../_shared/event-registration.js";
9
9
  import { share as shareSheet } from "@himalaya/share";
10
+ import { eventsSelectionFilter, eventsSelectionFromScope, eventsSelectionOf, eventsSelectionScope, type EventsSelection } from "../_shared/events-inline-options.js";
10
11
 
11
12
  // Offline-first (data-offline): the public events list is a read-through catalog —
12
13
  // paint the last-synced rows from the on-device store first (instant, works offline),
@@ -58,8 +59,20 @@ interface S {
58
59
  nextCursor?: string; complete?: boolean; total?: number; loadingMore?: boolean; pageError?: boolean; fromCache?: boolean;
59
60
  }
60
61
  let queryNow = new Date().toISOString();
62
+
63
+ // A link may open the list on some events only (`categoryIds` / `eventIds`, comma-separated: a See All from a section the app owner
64
+ // limited to a category). It is the selection of the visit that opened the screen: a visit that names none is the full list again.
65
+ // A route value is user-controllable text, so only well-formed ids are read (`eventsSelectionIds`). The selection is part of the
66
+ // query's criteria (`scope`), so rows, cached pages and restored pages are always those of the selection being shown.
67
+ let selection: EventsSelection = { categoryIds: [], eventIds: [] };
68
+ function readSelection(arg?: unknown): EventsSelection {
69
+ const own = (value: unknown) => (value && typeof value === "object" && ("categoryIds" in value || "eventIds" in value) ? value : undefined);
70
+ return eventsSelectionOf((own(arg) ?? (globalThis as { himalaya?: { input?: unknown } }).himalaya?.input) as { categoryIds?: unknown; eventIds?: unknown } | undefined);
71
+ }
61
72
  const svc = defineBackendCollection<S, ListEventRow>("himiEvents", {
62
73
  restorePagesOnLoad: true,
74
+ onLoad(arg) { selection = readSelection(arg); },
75
+ scope: () => eventsSelectionScope(selection),
63
76
  state: { status: "loading", query: "", all: [], results: [], emptyText: "", countLabel: "", errored: false, notErrored: true,
64
77
  isLoading: true, notLoading: false, noEmpty: true },
65
78
  source: {
@@ -69,6 +82,8 @@ const svc = defineBackendCollection<S, ListEventRow>("himiEvents", {
69
82
  // The list now OPENS on Upcoming, so the default view must keep its offline-first paint:
70
83
  // serve the cache for it too, minus the rows that have finished.
71
84
  const upcoming = criteria.filter === "value:Upcoming";
85
+ // The cache holds the whole catalog: a list limited to some events must not paint rows outside the selection first.
86
+ if (criteria.scope) return undefined;
72
87
  if (criteria.query || (criteria.filter !== "all" && !upcoming) || criteria.sort !== "default") return undefined;
73
88
  const rows = await readCached();
74
89
  return { items: upcoming ? rows.filter((row) => row.statusLabel !== "Past") : rows, nextCursor: "", metadata: { fromCache: true } };
@@ -81,6 +96,8 @@ const svc = defineBackendCollection<S, ListEventRow>("himiEvents", {
81
96
  // nothing for "Harvest" when the event is "Harvest Tasting".
82
97
  if (criteria.query) filter.title = { $startsWith: criteria.query };
83
98
  if (criteria.filter === "saved") filter.id = { $in: criteria.savedIds };
99
+ // The selection also limits Saved: a saved event outside it stays out (`eventsSelectionFilter` intersects the two id lists).
100
+ Object.assign(filter, eventsSelectionFilter(eventsSelectionFromScope(criteria.scope), criteria.filter === "saved" ? criteria.savedIds : undefined));
84
101
  // Upcoming = not started yet OR not finished yet: an event in progress (a festival on its
85
102
  // second day) is still on. The start-date arm is what keeps a START-ONLY event (no endDate
86
103
  // — valid in Wix Events) in the list; a filter on endDate alone dropped it from both views.
@@ -7,6 +7,10 @@ export interface CollectionQuery {
7
7
  filter: string;
8
8
  sort: 'default' | 'az' | 'za';
9
9
  savedIds: string[];
10
+ /** What the list is limited to beyond the controls above (a domain's own selection, e.g. the events of some categories), as one
11
+ * canonical string. Part of the criteria, so a list opened on another selection never shows or restores this one's rows. Absent
12
+ * when there is none: criteria without it keep the key they always had. */
13
+ scope?: string;
10
14
  }
11
15
  export interface CollectionPage<Row> {
12
16
  items: Row[];
@@ -42,11 +46,14 @@ export interface CollectionQuerySource<Row> {
42
46
  * key carries the account, and a purge tears parked workers down). */
43
47
  clearOnError?(error: unknown): boolean;
44
48
  }
49
+ /** A scope is read back by its domain, so it is never cut: this exceeds the largest selection the events list encodes (100 ids of 64 characters, about 6.9k). */
50
+ const SCOPE_MAX = 8192;
45
51
  const normalize = (q: Partial<CollectionQuery>): CollectionQuery => ({
46
52
  query: typeof q.query === 'string' ? q.query.trim().slice(0, 256) : '',
47
53
  filter: typeof q.filter === 'string' ? q.filter.slice(0, 256) : 'all',
48
54
  sort: q.sort === 'az' || q.sort === 'za' ? q.sort : 'default',
49
55
  savedIds: Array.isArray(q.savedIds) ? [...new Set(q.savedIds.filter(id => typeof id === 'string' && id.length > 0 && id.length <= 256))].slice(0, 500) : [],
56
+ ...(typeof q.scope === 'string' && q.scope ? { scope: q.scope.slice(0, SCOPE_MAX) } : {}),
50
57
  });
51
58
  const copyQuery = (q: CollectionQuery): CollectionQuery => ({ ...q, savedIds: [...q.savedIds] });
52
59
 
@@ -8,6 +8,10 @@ export interface CollectionQuery {
8
8
  filter: string;
9
9
  sort: 'default' | 'az' | 'za';
10
10
  savedIds: string[];
11
+ /** What the list is limited to beyond the controls above (a domain's own selection, e.g. the events of some categories), as one
12
+ * canonical string. Part of the criteria, so a list opened on another selection never shows or restores this one's rows. Absent
13
+ * when there is none: criteria without it keep the key they always had. */
14
+ scope?: string;
11
15
  }
12
16
  export interface CollectionPage<Row> {
13
17
  items: Row[];
@@ -52,11 +56,14 @@ export interface CollectionReadOptions {
52
56
  cache: 'only-if-cached' | 'reload';
53
57
  onCacheResult(metadata: ReadMetadata): void;
54
58
  }
59
+ /** A scope is read back by its domain, so it is never cut: this exceeds the largest selection the events list encodes (100 ids of 64 characters, about 6.9k). */
60
+ const SCOPE_MAX = 8192;
55
61
  const normalize = (q: Partial<CollectionQuery>): CollectionQuery => ({
56
62
  query: typeof q.query === 'string' ? q.query.trim().slice(0, 256) : '',
57
63
  filter: typeof q.filter === 'string' ? q.filter.slice(0, 256) : 'all',
58
64
  sort: q.sort === 'az' || q.sort === 'za' ? q.sort : 'default',
59
65
  savedIds: Array.isArray(q.savedIds) ? [...new Set(q.savedIds.filter(id => typeof id === 'string' && id.length > 0 && id.length <= 256))].slice(0, 500) : [],
66
+ ...(typeof q.scope === 'string' && q.scope ? { scope: q.scope.slice(0, SCOPE_MAX) } : {}),
60
67
  });
61
68
  const copyQuery = (q: CollectionQuery): CollectionQuery => ({ ...q, savedIds: [...q.savedIds] });
62
69
 
@@ -19,6 +19,8 @@ interface BackendCollection {
19
19
  /** Sees the load action's argument (the screen's onAppear params) BEFORE the query runs. A returned
20
20
  * `{ filter, sort }` resets the criteria for that load (a screen that always opens on one view). */
21
21
  onLoad?(arg: unknown): CollectionCriteriaReset | void;
22
+ /** The collection's own selection as part of every query's criteria (see `CollectionQuery.scope`); "" for none. */
23
+ scope?(): string;
22
24
  controller: ReturnType<typeof createCollectionQuery<CollectionRow>>;
23
25
  apply(state: State, page: CollectionQueryState<CollectionRow>): State;
24
26
  }
@@ -288,7 +290,7 @@ export function decorateCollection(name: string, def: { state: State; actions?:
288
290
  // A screen with no search field clears a query an older screen persisted, or it narrows every view for good.
289
291
  if (typeof input.query === 'string') prefs.query = input.query.slice(0, 256);
290
292
  };
291
- const criteria = () => ({ query: prefs.query, sort: prefs.sort, filter: prefs.filter, savedIds: prefs.filter === 'saved' ? prefs.savedIds : [] });
293
+ const criteria = () => ({ query: prefs.query, sort: prefs.sort, filter: prefs.filter, savedIds: prefs.filter === 'saved' ? prefs.savedIds : [], ...(backend?.scope ? { scope: backend.scope() } : {}) });
292
294
  const criteriaKey = () => JSON.stringify(criteria());
293
295
  actions.collectionDismissFilters = change(() => { filtersPresented = false; });
294
296
  actions.collectionFilters = change(() => { filtersPresented = !filtersPresented; });
@@ -378,6 +380,9 @@ export function defineBackendCollection<S extends object, Row extends object>(na
378
380
  /** The load action's argument (onAppear params beyond `copy`), before the query runs — for a
379
381
  * domain setting that rides the descriptor, e.g. My Bookings' `weeklyGoal`. */
380
382
  onLoad?(arg: unknown): CollectionCriteriaReset | void;
383
+ /** A selection the list is limited to, as one canonical string ("" for none): it joins the criteria, so another selection is another
384
+ * result set (no stale rows behind a revalidation, no restore of another selection's pages) and `source` reads it off `criteria.scope`. */
385
+ scope?(): string;
381
386
  state: S;
382
387
  source: CollectionQuerySource<Row>;
383
388
  apply(state: S, page: CollectionQueryState<Row>): S;
@@ -397,6 +402,7 @@ export function defineBackendCollection<S extends object, Row extends object>(na
397
402
  restorePagesOnLoad: options.restorePagesOnLoad,
398
403
  readLifecycle: options.readLifecycle,
399
404
  onLoad: avatar ? arg => { avatar.onLoad(arg); return options.onLoad?.(arg); } : options.onLoad,
405
+ scope: options.scope,
400
406
  controller: controller as unknown as BackendCollection['controller'],
401
407
  apply: (state, page) => {
402
408
  const applied = { ...options.apply(state as S, page as unknown as CollectionQueryState<Row>), ...(options.readLifecycle ? { readStatus: page.read } : {}) } as State;
@@ -5,6 +5,10 @@ export interface CollectionQuery {
5
5
  filter: string;
6
6
  sort: 'default' | 'az' | 'za';
7
7
  savedIds: string[];
8
+ /** What the list is limited to beyond the controls above (a domain's own selection, e.g. the events of some categories), as one
9
+ * canonical string. Part of the criteria, so a list opened on another selection never shows or restores this one's rows. Absent
10
+ * when there is none: criteria without it keep the key they always had. */
11
+ scope?: string;
8
12
  }
9
13
  export interface CollectionPage<Row> {
10
14
  items: Row[];
@@ -39,11 +43,15 @@ export interface CollectionQuerySource<Row> {
39
43
  * key carries the account, and a purge tears parked workers down). */
40
44
  clearOnError?(error: unknown): boolean;
41
45
  }
46
+ /** A scope is read back by its domain, so it is never cut: this exceeds the largest selection the events list encodes (100 ids of 64 characters, about 6.9k). */
47
+ const SCOPE_MAX = 8192;
42
48
  const normalize = (q: Partial<CollectionQuery>): CollectionQuery => ({
43
49
  query: typeof q.query === 'string' ? q.query.trim().slice(0, 256) : '',
44
50
  filter: typeof q.filter === 'string' ? q.filter.slice(0, 256) : 'all',
45
51
  sort: q.sort === 'az' || q.sort === 'za' ? q.sort : 'default',
46
52
  savedIds: Array.isArray(q.savedIds) ? [...new Set(q.savedIds.filter(id => typeof id === 'string' && id.length > 0 && id.length <= 256))].slice(0, 500) : [],
53
+
54
+ ...(typeof q.scope === 'string' && q.scope ? { scope: q.scope.slice(0, SCOPE_MAX) } : {}),
47
55
  });
48
56
  const copyQuery = (q: CollectionQuery): CollectionQuery => ({ ...q, savedIds: [...q.savedIds] });
49
57
 
@@ -23,6 +23,8 @@ interface BackendCollection {
23
23
  /** Sees the load action's argument (the screen's onAppear params) BEFORE the query runs. A returned
24
24
  * `{ filter, sort }` resets the criteria for that load (a screen that always opens on one view). */
25
25
  onLoad?(arg: unknown): CollectionCriteriaReset | void;
26
+ /** The collection's own selection as part of every query's criteria (see `CollectionQuery.scope`); "" for none. */
27
+ scope?(): string;
26
28
  controller: ReturnType<typeof createCollectionQuery<CollectionRow>>;
27
29
  apply(state: State, page: CollectionQueryState<CollectionRow>): State;
28
30
  }
@@ -284,7 +286,7 @@ export function decorateCollection(name: string, def: { state: State; actions?:
284
286
  // A screen with no search field clears a query an older screen persisted, or it narrows every view for good.
285
287
  if (typeof input.query === 'string') prefs.query = input.query.slice(0, 256);
286
288
  };
287
- const criteria = () => ({ query: prefs.query, sort: prefs.sort, filter: prefs.filter, savedIds: prefs.filter === 'saved' ? prefs.savedIds : [] });
289
+ const criteria = () => ({ query: prefs.query, sort: prefs.sort, filter: prefs.filter, savedIds: prefs.filter === 'saved' ? prefs.savedIds : [], ...(backend?.scope ? { scope: backend.scope() } : {}) });
288
290
  const criteriaKey = () => JSON.stringify(criteria());
289
291
  actions.collectionDismissFilters = change(() => { filtersPresented = false; });
290
292
  actions.collectionFilters = change(() => { filtersPresented = !filtersPresented; });
@@ -365,6 +367,9 @@ export function defineBackendCollection<S extends object, Row extends object>(na
365
367
  /** The load action's argument (onAppear params beyond `copy`), before the query runs — for a
366
368
  * domain setting that rides the descriptor, e.g. My Bookings' `weeklyGoal`. */
367
369
  onLoad?(arg: unknown): CollectionCriteriaReset | void;
370
+ /** A selection the list is limited to, as one canonical string ("" for none): it joins the criteria, so another selection is another
371
+ * result set (no stale rows behind a revalidation, no restore of another selection's pages) and `source` reads it off `criteria.scope`. */
372
+ scope?(): string;
368
373
  state: S;
369
374
  source: CollectionQuerySource<Row>;
370
375
  apply(state: S, page: CollectionQueryState<Row>): S;
@@ -380,6 +385,7 @@ export function defineBackendCollection<S extends object, Row extends object>(na
380
385
  const definition = decorateCollection(name, { state: options.state as State, actions: options.actions as Record<string, Reducer> | undefined }, options.saving, {
381
386
  restorePagesOnLoad: options.restorePagesOnLoad,
382
387
  onLoad: avatar ? arg => { avatar.onLoad(arg); return options.onLoad?.(arg); } : options.onLoad,
388
+ scope: options.scope,
383
389
  controller: controller as unknown as BackendCollection['controller'],
384
390
  apply: (state, page) => {
385
391
  const applied = options.apply(state as S, page as unknown as CollectionQueryState<Row>) as State;