@wix/himalaya-cli 0.1852.0 → 0.1854.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +1104 -711
- package/guides/himi-json-output.md +8 -2
- package/guides/iap-products.md +4 -0
- package/guides/one-app-section-mappings.md +2 -2
- package/guides/one-app-to-himi-app.md +28 -12
- package/guides/push-cli-onboarding.md +20 -0
- package/package.json +2 -2
- package/template-icons/bare-fashion.png +0 -0
- package/templates/bare-fashion/README.md +52 -0
- package/templates/bare-fashion/config.ts +474 -0
- package/templates/bare-fashion/dev/index.ts +16526 -0
- package/templates/bare-fashion/himalaya.content.json +70 -0
- package/templates/bare-fashion/himalaya.template.json +18 -0
- package/templates/bare-fashion/icon.png +0 -0
- package/templates/bare-fashion/platforms.json +3 -0
- package/templates/bare-fashion/tier5-src/_shared/app-locale.ts +70 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-book.ts +116 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-countries.ts +261 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-bag-count.ts +24 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-categories.ts +48 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-facets.ts +265 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-load-error.ts +38 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-product-card.ts +136 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-store-options.ts +129 -0
- package/templates/bare-fashion/tier5-src/_shared/branded-lite-hosted.ts +282 -0
- package/templates/bare-fashion/tier5-src/_shared/collection-contract.ts +228 -0
- package/templates/bare-fashion/tier5-src/_shared/collection-query.ts +201 -0
- package/templates/bare-fashion/tier5-src/_shared/collection-service.ts +429 -0
- package/templates/bare-fashion/tier5-src/_shared/engine-intl.ts +529 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-account.ts +209 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-copy.ts +123 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-layouts.ts +142 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-store-categories.ts +108 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-store-saved.ts +57 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-store.ts +7 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-text.ts +24 -0
- package/templates/bare-fashion/tier5-src/_shared/hosted-checkout.ts +70 -0
- package/templates/bare-fashion/tier5-src/_shared/live-session.ts +172 -0
- package/templates/bare-fashion/tier5-src/_shared/local-preferences.ts +38 -0
- package/templates/bare-fashion/tier5-src/_shared/member-access.ts +63 -0
- package/templates/bare-fashion/tier5-src/_shared/member-avatar.ts +76 -0
- package/templates/bare-fashion/tier5-src/_shared/member-orders.ts +8 -0
- package/templates/bare-fashion/tier5-src/_shared/online-actions.ts +76 -0
- package/templates/bare-fashion/tier5-src/_shared/owner-load-error.ts +348 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-account/index.ts +127 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-address-form/index.ts +367 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-addresses/index.ts +202 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-appearance/index.ts +73 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-cart/index.ts +540 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-collection/index.ts +111 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-home/index.ts +241 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-nav/index.ts +56 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-order/index.ts +437 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-product/index.ts +650 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-products/index.ts +142 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-saved/index.ts +45 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-search/index.ts +199 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-shop/index.ts +79 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-sign-in/index.ts +269 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-wallet/index.ts +224 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-info/index.ts +209 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-orders/index.ts +327 -0
- package/templates/bare-fashion/tier5-src/wix-spaces-collections/index.ts +48 -0
- package/templates/bare-fashion/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/bare-fashion/tier5-src/wix-spaces-view-profile/index.ts +119 -0
- package/templates/bare-fashion/tokens.json +348 -0
- package/templates/beauty-salon/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/beauty-salon/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/beauty-salon-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/beauty-salon-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/branded-lite/recipes/upcoming-bookings.json +118 -6
- package/templates/branded-lite/tier5-src/_shared/announcement-section.ts +6 -14
- package/templates/branded-lite/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/branded-lite/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/branded-lite/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/branded-lite/tier5-src/_shared/draft-content.ts +66 -0
- package/templates/branded-lite/tier5-src/_shared/events-inline-options.ts +55 -3
- package/templates/branded-lite/tier5-src/_shared/events-inline.ts +5 -3
- package/templates/branded-lite/tier5-src/_shared/upcoming-bookings-section.ts +15 -4
- package/templates/branded-lite/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/brandy/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/brandy/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/brandy/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/community-club/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/community-club/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/community-club/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/community-club/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/community-club-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/community-club-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/conference/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/conference/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/conference/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/conference/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/events-meetups/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/events-meetups/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/events-meetups/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/events-meetups/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/events-meetups-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/events-meetups-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/fitness-gym/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/fitness-gym/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/gym-fitness/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/gym-fitness/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/gym-fitness/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/medical-services/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/medical-services/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/nonprofit-cause/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/nonprofit-cause/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/nonprofit-cause/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/owner-lite/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/owner-lite/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/personal-fitness-trainer/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/podcast-creator/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/podcast-creator/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/podcast-creator/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/portfolio-creative/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/portfolio-creative/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/portfolio-creative/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/restaurant/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/restaurant/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/restaurant/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/restaurant/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/restaurant-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/restaurant-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/retail-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/retail-store/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/retail-store/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/retail-store-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/retail-store-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/salon-spa/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/salon-spa/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/wholesale-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/wholesale-store/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/wholesale-store/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/yoga-studio/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/yoga-studio/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/yoga-studio/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/collection-service.ts +7 -1
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// Hosted mode: ONE served Branded Lite that opens any site at runtime, inside a host app such as
|
|
2
|
+
// Spaces Lite, instead of one build per customer.
|
|
3
|
+
//
|
|
4
|
+
// A single-site build decides its verticals at build time from `provisioning.json`. A hosted build
|
|
5
|
+
// declares every vertical and decides at RUNTIME from the site the host opened it for: each
|
|
6
|
+
// vertical's nav row carries a fail-closed `hiddenPath` (`hiddenUntilResolved`: hidden until it resolves), and
|
|
7
|
+
// the app-level nav worker resolves it from the site the host hands over.
|
|
8
|
+
//
|
|
9
|
+
// WHERE THE SITE COMES FROM: the host. A hosted app's Wix capability is pinned to its site and only
|
|
10
|
+
// reaches www.wixapis.com, so it cannot read its own provisioning (the Member View
|
|
11
|
+
// lives on apps.wix.com, the display options on manage.wix.com). The host resolves it with its own
|
|
12
|
+
// account session (the site provisioning mapper) and core injects it into every worker's input under the
|
|
13
|
+
// reserved key `HOST_SITE_INPUT_KEY`, after the nav params are merged — so a deep link's query can
|
|
14
|
+
// never supply or replace it (WorkerPreferenceContext.inject, iOS + Android).
|
|
15
|
+
//
|
|
16
|
+
// PURE and import-free, so the nav and home workers (and the CLI templates that copy them) can
|
|
17
|
+
// bundle it. The app's hosted-mode module re-exports it with the app's types.
|
|
18
|
+
|
|
19
|
+
/** A Branded Lite vertical id (the app contract's `BrandedLiteVertical`). A plain
|
|
20
|
+
* string here: this module is copied into CLI templates, which only allow `_shared` imports. */
|
|
21
|
+
export type BrandedLiteVertical = string;
|
|
22
|
+
|
|
23
|
+
export type BrandedLiteMode = "single-site" | "hosted";
|
|
24
|
+
|
|
25
|
+
/** The worker-input key the host's site arrives under. Core owns it: it is set (or blanked) after
|
|
26
|
+
* every other input source, so nothing but the host can put a site there. */
|
|
27
|
+
export const HOST_SITE_INPUT_KEY = "__himiHostSite";
|
|
28
|
+
|
|
29
|
+
/** The host's site from a worker's `himalaya.input`, or null. */
|
|
30
|
+
export function hostSiteFromInput(input: unknown): HostedSite | null {
|
|
31
|
+
const raw = input && typeof input === "object" ? (input as Record<string, unknown>)[HOST_SITE_INPUT_KEY] : undefined;
|
|
32
|
+
return readHostedSite(raw);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** What the host hands a hosted Branded Lite about the site it opened (`himalaya.input[HOST_SITE_INPUT_KEY]`). */
|
|
36
|
+
export interface HostedSite {
|
|
37
|
+
metaSiteId: string;
|
|
38
|
+
name: string;
|
|
39
|
+
installedVerticals: BrandedLiteVertical[];
|
|
40
|
+
/** #RRGGBB, or "" when the site has none (the build's own brand stays). */
|
|
41
|
+
primaryColor: string;
|
|
42
|
+
logoUrl: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Verticals a hosted build always shows: every member area has a member list, whatever the
|
|
46
|
+
* owner installed. (Home, its About section and Profile are not verticals — always there.) */
|
|
47
|
+
export const HOSTED_ALWAYS: readonly BrandedLiteVertical[] = ["members"];
|
|
48
|
+
|
|
49
|
+
/** The screen each vertical's nav rows open, so a route to an uninstalled vertical can be answered. */
|
|
50
|
+
export const VERTICAL_ROOT_SCREENS: Readonly<Record<string, readonly string[]>> = {
|
|
51
|
+
store: ["himi_shop"], bookings: ["himi_services", "himi_agenda"], restaurants: ["himi_menu", "himi_reserve"],
|
|
52
|
+
programs: ["himi_programs"], plans: ["himi_plans"], feed: ["himi_feed"], members: ["himi_members"],
|
|
53
|
+
forum: ["himi_forum"], coupons: ["himi_coupons"], notifications: ["himi_notifications"],
|
|
54
|
+
loyalty: ["himi_loyalty"], reviews: ["himi_reviews"], portfolio: ["himi_portfolio"],
|
|
55
|
+
reservations: ["himi_reservations"], invoices: ["himi_invoices"], badges: ["himi_badges"],
|
|
56
|
+
notifsettings: ["himi_notif_settings"], events: ["himi_events"], blog: ["himi_blog"],
|
|
57
|
+
groups: ["himi_groups"], cms: ["himi_cms"], donations: ["himi_donations"], giftCards: ["himi_gift_cards"],
|
|
58
|
+
videos: ["himi_videos"], podcasts: ["himi_podcasts"], forms: ["himi_forms"], galleries: ["himi_galleries"],
|
|
59
|
+
inbox: ["himi_business_chat"], faq: ["himi_faq"], fileShare: ["himi_file_share"],
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** Every screen a vertical owns, so a route to ANY of them (a child or action screen as much as the
|
|
63
|
+
* root) lands on `NOT_AVAILABLE_SCREEN` when the site does not have it. A screen several verticals
|
|
64
|
+
* share opens when any of them is shown. Pinned against the app's screen registry
|
|
65
|
+
* (`brandedLiteScreenOwners`, checked by the app's hosted-mode tests), so a screen added
|
|
66
|
+
* to a vertical without being listed here fails the build. */
|
|
67
|
+
export const HOSTED_SCREEN_VERTICALS: Readonly<Record<string, readonly BrandedLiteVertical[]>> = {
|
|
68
|
+
himi_address: ["restaurants", "store"],
|
|
69
|
+
himi_addresses: ["restaurants", "store"],
|
|
70
|
+
himi_agenda: ["bookings"],
|
|
71
|
+
himi_badge: ["badges"],
|
|
72
|
+
himi_badges: ["badges"],
|
|
73
|
+
himi_blog: ["blog"],
|
|
74
|
+
himi_bookings: ["bookings"],
|
|
75
|
+
himi_cart: ["store"],
|
|
76
|
+
himi_business_chat: ["inbox"],
|
|
77
|
+
himi_chat_thread: ["inbox", "members"],
|
|
78
|
+
himi_cms: ["cms"],
|
|
79
|
+
himi_collection: ["store"],
|
|
80
|
+
himi_collections: ["store"],
|
|
81
|
+
himi_coupon: ["coupons"],
|
|
82
|
+
himi_coupons: ["coupons"],
|
|
83
|
+
himi_create_post: ["blog", "forum"],
|
|
84
|
+
himi_donation: ["donations"],
|
|
85
|
+
himi_donations: ["donations"],
|
|
86
|
+
himi_events: ["events"],
|
|
87
|
+
himi_faq: ["faq"],
|
|
88
|
+
himi_feed: ["feed"],
|
|
89
|
+
himi_file_share: ["fileShare"],
|
|
90
|
+
himi_food_order: ["restaurants"],
|
|
91
|
+
himi_food_orders: ["restaurants"],
|
|
92
|
+
himi_form: ["forms"],
|
|
93
|
+
himi_forms: ["forms"],
|
|
94
|
+
himi_forum: ["forum"],
|
|
95
|
+
himi_forum_post: ["forum"],
|
|
96
|
+
himi_galleries: ["galleries"],
|
|
97
|
+
himi_gallery: ["galleries"],
|
|
98
|
+
himi_gift_card: ["giftCards"],
|
|
99
|
+
himi_gift_cards: ["giftCards"],
|
|
100
|
+
himi_groups: ["groups"],
|
|
101
|
+
himi_inbox: ["inbox"],
|
|
102
|
+
himi_group_about: ["groups"],
|
|
103
|
+
himi_my_groups: ["groups"],
|
|
104
|
+
himi_invoice: ["invoices"],
|
|
105
|
+
himi_invoices: ["invoices"],
|
|
106
|
+
himi_loyalty: ["loyalty"],
|
|
107
|
+
himi_loyalty_reward: ["loyalty"],
|
|
108
|
+
himi_member: ["members"],
|
|
109
|
+
himi_members: ["members"],
|
|
110
|
+
himi_menu: ["restaurants"],
|
|
111
|
+
himi_my_events: ["events"],
|
|
112
|
+
himi_my_subscriptions: ["plans"],
|
|
113
|
+
himi_new_message: ["inbox", "members"],
|
|
114
|
+
himi_notifications: ["notifications"],
|
|
115
|
+
himi_orders: ["store"],
|
|
116
|
+
himi_photo_album: ["galleries"],
|
|
117
|
+
himi_place_summary: ["bookings", "plans"],
|
|
118
|
+
himi_plan: ["plans"],
|
|
119
|
+
himi_plans: ["plans"],
|
|
120
|
+
himi_podcast: ["podcasts"],
|
|
121
|
+
himi_podcasts: ["podcasts"],
|
|
122
|
+
himi_portfolio: ["portfolio"],
|
|
123
|
+
himi_portfolio_project: ["portfolio"],
|
|
124
|
+
himi_programs: ["programs"],
|
|
125
|
+
himi_member_programs: ["programs"],
|
|
126
|
+
himi_program_participant: ["programs"],
|
|
127
|
+
himi_program_step: ["programs"],
|
|
128
|
+
himi_reservations: ["reservations"],
|
|
129
|
+
himi_reserve: ["restaurants"],
|
|
130
|
+
himi_review: ["reviews"],
|
|
131
|
+
himi_reviews: ["reviews"],
|
|
132
|
+
himi_saved: ["blog"],
|
|
133
|
+
himi_saved_products: ["store"],
|
|
134
|
+
himi_services: ["bookings"],
|
|
135
|
+
himi_shop: ["store"],
|
|
136
|
+
himi_subscription: ["plans"],
|
|
137
|
+
himi_video: ["videos"],
|
|
138
|
+
himi_video_channel: ["videos"],
|
|
139
|
+
himi_videos: ["videos"],
|
|
140
|
+
himi_wallet: ["bookings", "plans", "restaurants", "store"],
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/** The templated (`<prefix>[_/]<id>`) detail routes each vertical owns, pinned the same way. */
|
|
144
|
+
export const HOSTED_ROUTE_PREFIXES: Readonly<Record<string, readonly BrandedLiteVertical[]>> = {
|
|
145
|
+
himi_order: ["store"],
|
|
146
|
+
himi_product: ["store"],
|
|
147
|
+
himi_service: ["bookings"],
|
|
148
|
+
himi_time: ["bookings"],
|
|
149
|
+
himi_menu_item: ["restaurants"],
|
|
150
|
+
himi_program: ["programs"],
|
|
151
|
+
himi_event: ["events"],
|
|
152
|
+
himi_rsvp: ["events"],
|
|
153
|
+
himi_blog_post: ["blog"],
|
|
154
|
+
himi_group: ["groups"],
|
|
155
|
+
himi_cms_collection: ["cms"],
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/** The verticals that own [screenId], or undefined for a screen every site has (Home, Profile…). */
|
|
159
|
+
export function screenVerticals(screenId: string): readonly BrandedLiteVertical[] | undefined {
|
|
160
|
+
const exact = HOSTED_SCREEN_VERTICALS[screenId];
|
|
161
|
+
if (exact) return exact;
|
|
162
|
+
// The registry's `^<prefix>(?:[_/](.+))?$`: the bare prefix, or the prefix, a separator and an id.
|
|
163
|
+
for (const [prefix, verticals] of Object.entries(HOSTED_ROUTE_PREFIXES)) {
|
|
164
|
+
if (screenId === prefix) return verticals;
|
|
165
|
+
const sep = screenId.charAt(prefix.length);
|
|
166
|
+
if (screenId.startsWith(prefix) && (sep === "_" || sep === "/") && screenId.length > prefix.length + 1) return verticals;
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** The drawer's collapsible folders and the verticals in each (config.ts builds them from this).
|
|
172
|
+
* A folder header is hidden when none of its verticals shows, so a site never sees an empty one. */
|
|
173
|
+
export const HOSTED_DRAWER_FOLDERS: Readonly<Record<string, readonly BrandedLiteVertical[]>> = {
|
|
174
|
+
drawer_sec_community: ["feed", "forum", "groups", "members", "reviews", "badges", "blog"],
|
|
175
|
+
drawer_sec_media: ["videos", "podcasts", "portfolio", "cms", "galleries", "faq", "fileShare"],
|
|
176
|
+
drawer_sec_offers: ["coupons", "giftCards", "donations", "loyalty"],
|
|
177
|
+
drawer_sec_activity: ["inbox", "reservations", "invoices", "forms", "notifications", "notifsettings"],
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/** The vertical a nav row's screen belongs to, or undefined (Home, Profile, Steps…). */
|
|
181
|
+
export function verticalOfScreen(screenId: string | undefined): BrandedLiteVertical | undefined {
|
|
182
|
+
if (!screenId) return undefined;
|
|
183
|
+
for (const [vertical, roots] of Object.entries(VERTICAL_ROOT_SCREENS) as [string, readonly string[]][]) {
|
|
184
|
+
if (roots.includes(screenId)) return vertical;
|
|
185
|
+
}
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The screen a route to an uninstalled vertical lands on. */
|
|
190
|
+
export const NOT_AVAILABLE_SCREEN = "himi_not_available";
|
|
191
|
+
|
|
192
|
+
const HEX = /^#[0-9A-Fa-f]{6}$/;
|
|
193
|
+
const VERTICALS = new Set(Object.keys(VERTICAL_ROOT_SCREENS));
|
|
194
|
+
|
|
195
|
+
/** The host's site, or null when it is missing or malformed — a hosted build then shows no
|
|
196
|
+
* vertical at all (fail closed), never every one. */
|
|
197
|
+
export function readHostedSite(raw: unknown): HostedSite | null {
|
|
198
|
+
let value = raw;
|
|
199
|
+
if (typeof value === "string") {
|
|
200
|
+
try { value = JSON.parse(value); } catch { return null; }
|
|
201
|
+
}
|
|
202
|
+
if (!value || typeof value !== "object") return null;
|
|
203
|
+
const v = value as Record<string, unknown>;
|
|
204
|
+
const metaSiteId = typeof v.metaSiteId === "string" ? v.metaSiteId.trim() : "";
|
|
205
|
+
if (!metaSiteId || !Array.isArray(v.installedVerticals)) return null;
|
|
206
|
+
const installed = v.installedVerticals.filter((x): x is BrandedLiteVertical => typeof x === "string" && VERTICALS.has(x));
|
|
207
|
+
const color = typeof v.primaryColor === "string" && HEX.test(v.primaryColor) ? v.primaryColor : "";
|
|
208
|
+
return {
|
|
209
|
+
metaSiteId,
|
|
210
|
+
name: typeof v.name === "string" ? v.name : "",
|
|
211
|
+
installedVerticals: [...new Set(installed)],
|
|
212
|
+
primaryColor: color,
|
|
213
|
+
logoUrl: typeof v.logoUrl === "string" && /^https:\/\//.test(v.logoUrl) ? v.logoUrl : "",
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** The verticals a hosted build shows for [site]: its installed ones plus the always-on ones.
|
|
218
|
+
* None at all without a site. */
|
|
219
|
+
export function hostedVerticals(site: HostedSite | null): Set<BrandedLiteVertical> {
|
|
220
|
+
if (!site) return new Set();
|
|
221
|
+
return new Set<BrandedLiteVertical>([...site.installedVerticals, ...HOSTED_ALWAYS]);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** `hiddenPath` flags (true hides the row), for the nav worker to publish: one per vertical, and
|
|
225
|
+
* one per drawer folder (hidden when none of its verticals shows). */
|
|
226
|
+
export function hostedHiddenFlags(site: HostedSite | null): Record<string, boolean> {
|
|
227
|
+
const shown = hostedVerticals(site);
|
|
228
|
+
const out: Record<string, boolean> = {};
|
|
229
|
+
for (const v of Object.keys(VERTICAL_ROOT_SCREENS) as BrandedLiteVertical[]) out[v] = !shown.has(v);
|
|
230
|
+
for (const [folder, verticals] of Object.entries(HOSTED_DRAWER_FOLDERS)) out[folder] = !verticals.some((v) => shown.has(v));
|
|
231
|
+
return out;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Where a route to [screenId] lands for [site]: itself, or the "not available on this site" screen
|
|
235
|
+
* when every vertical that owns it is missing from the site. A screen no vertical owns (Home,
|
|
236
|
+
* Profile, settings) is on every site and passes through. */
|
|
237
|
+
export function hostedRoute(screenId: string, site: HostedSite | null): string {
|
|
238
|
+
const owners = screenVerticals(screenId);
|
|
239
|
+
if (!owners) return screenId;
|
|
240
|
+
const shown = hostedVerticals(site);
|
|
241
|
+
return owners.some((v) => shown.has(v)) ? screenId : NOT_AVAILABLE_SCREEN;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** One hosted Home "Explore" card. The descriptor hands the worker the whole catalog (its copy is
|
|
245
|
+
* build-time localized) as `himalaya.input.hostedExplore`; the worker publishes only the site's. */
|
|
246
|
+
export interface HostedExploreCard {
|
|
247
|
+
vertical: BrandedLiteVertical;
|
|
248
|
+
icon: string;
|
|
249
|
+
title: string;
|
|
250
|
+
body: string;
|
|
251
|
+
/** Always the vertical's own root screen — never taken from the input. */
|
|
252
|
+
screenId: string;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** The Explore cards to show for [site], in catalog order: one per catalog entry whose vertical the
|
|
256
|
+
* site shows. Empty without a site or a catalog, so a worker that never boots shows no card at all
|
|
257
|
+
* (the grid binds this list — fail closed, unlike a per-card `hiddenPath`, which native renderers
|
|
258
|
+
* treat as visible until it resolves). */
|
|
259
|
+
export function hostedExploreCards(catalog: unknown, site: HostedSite | null): HostedExploreCard[] {
|
|
260
|
+
if (!Array.isArray(catalog)) return [];
|
|
261
|
+
const shown = hostedVerticals(site);
|
|
262
|
+
const out: HostedExploreCard[] = [];
|
|
263
|
+
const seen = new Set<string>();
|
|
264
|
+
for (const entry of catalog) {
|
|
265
|
+
if (!entry || typeof entry !== "object") continue;
|
|
266
|
+
const e = entry as Record<string, unknown>;
|
|
267
|
+
const vertical = typeof e.vertical === "string" ? e.vertical : "";
|
|
268
|
+
const screenId = VERTICAL_ROOT_SCREENS[vertical]?.[0];
|
|
269
|
+
if (!screenId || !shown.has(vertical) || seen.has(vertical)) continue;
|
|
270
|
+
seen.add(vertical);
|
|
271
|
+
out.push({
|
|
272
|
+
vertical, screenId,
|
|
273
|
+
icon: typeof e.icon === "string" ? e.icon : "grid",
|
|
274
|
+
title: typeof e.title === "string" ? e.title : "",
|
|
275
|
+
body: typeof e.body === "string" ? e.body : "",
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
return out;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** The `$service` path a hosted nav row's visibility binds to (a vertical, or a drawer folder id). */
|
|
282
|
+
export const hostedHiddenPath = (key: string): string => `$service:brandedLiteNav.hosted.${key}`;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { compareText, compareIso } from "./engine-intl.js";
|
|
2
|
+
/** Shared OTA collection contract. No host APIs: used by workers and builders. */
|
|
3
|
+
export interface CollectionConfig {
|
|
4
|
+
rows: string;
|
|
5
|
+
/** Flat customer history rows, divided rather than boxed. */
|
|
6
|
+
rowStyle?: "flat";
|
|
7
|
+
instanceInput?: string;
|
|
8
|
+
title: string;
|
|
9
|
+
subtitle?: string;
|
|
10
|
+
image?: string;
|
|
11
|
+
filter?: string;
|
|
12
|
+
filterValues?: string[];
|
|
13
|
+
/** A state key holding `{ label }` rows (e.g. a worker's full category list) whose
|
|
14
|
+
* labels are filter choices even when no loaded row carries them yet. */
|
|
15
|
+
filterValuesFrom?: string;
|
|
16
|
+
searchPlaceholder?: string;
|
|
17
|
+
sortLabels?: { default: string; az: string; za: string };
|
|
18
|
+
metadata?: string[];
|
|
19
|
+
/** Numeric 0–5 row field rendered as a Rating (accessible "N out of 5") instead of
|
|
20
|
+
* folding a "★★★★☆" glyph string into the metadata line, so screen readers get a value. */
|
|
21
|
+
rating?: string;
|
|
22
|
+
/** Domain-provided calendar text and its unavailable flag, kept separate from media. */
|
|
23
|
+
dateBadge?: { text: string; hidden: string };
|
|
24
|
+
sectioned?: boolean;
|
|
25
|
+
view: 'list' | 'grid';
|
|
26
|
+
backendQuery?: boolean;
|
|
27
|
+
paged?: boolean;
|
|
28
|
+
defaultFilter?: string;
|
|
29
|
+
reviewAction?: string;
|
|
30
|
+
reviewSelectedAction?: string;
|
|
31
|
+
/** Optional comfortable grid media height for immersive visual catalogs. */
|
|
32
|
+
gridImageHeight?: number;
|
|
33
|
+
/** What the count summary counts — ["dish", "dishes"] reads "12 dishes". Default "item(s)". */
|
|
34
|
+
countNoun?: [string, string];
|
|
35
|
+
/** Phone grid columns (default 2). A card carrying a paragraph of benefits and a CTA — a
|
|
36
|
+
* pricing plan — is unreadable at half width, so it opts into one. */
|
|
37
|
+
gridColumns?: number;
|
|
38
|
+
/** Lines of the meta caption a comfortable row may use (default 2). */
|
|
39
|
+
metaMaxLines?: number;
|
|
40
|
+
/** The card's primary verb, shown as a visible button beside the overflow.
|
|
41
|
+
* `screenId` opens that screen with the row id; without it the verb reuses the
|
|
42
|
+
* row's own tap action (the detail screen that owns the verb). */
|
|
43
|
+
primaryVerb?: { label: string; screenId?: string;
|
|
44
|
+
/** A row field holding THIS row's verb label (Register, RSVP, Buy Tickets…); `label` stays the fallback copy. */
|
|
45
|
+
labelPath?: string;
|
|
46
|
+
/** A row boolean that hides the verb on rows that offer no action (an event with no registration). */
|
|
47
|
+
hiddenPath?: string };
|
|
48
|
+
/** The worker action that shares a row (`tier5.<service>.<name>` with `{ id }`): adds Share to the card's overflow menu. */
|
|
49
|
+
shareAction?: string;
|
|
50
|
+
/** A TIME-BOUND entity (an event, a booking, a reservation): the boolean row field the
|
|
51
|
+
* DOMAIN sets once the record has finished — computed by the same rule as the row's own
|
|
52
|
+
* "Past" label, in the same place, so the two cannot disagree. A finished
|
|
53
|
+
* record's `primaryVerb` (Register, Book…) is transactional and would act on something
|
|
54
|
+
* that is over, so it is swapped for a non-transactional "View details" that opens the
|
|
55
|
+
* row's own detail. Without a row tap action the verb is simply hidden. */
|
|
56
|
+
endedWhen?: string;
|
|
57
|
+
/** A catalog card whose one expected per-item action is "favorite".
|
|
58
|
+
* The ellipsis overflow is replaced by an always-visible heart toggle wired to
|
|
59
|
+
* the same `collectionSave` reducer. A dropdown `Menu` anchored inside a
|
|
60
|
+
* list/grid row renders clipped inside the row's own bounds, so on a product
|
|
61
|
+
* card the overflow's items were unreachable AND the wrong pattern: shoppers
|
|
62
|
+
* expect a heart, not a 3-item menu two taps deep. */
|
|
63
|
+
favoriteToggle?: boolean;
|
|
64
|
+
/** A state field the DOMAIN narrows `rows` by (e.g. a category picker). While it is set,
|
|
65
|
+
* zero rows is a filtered result, not an empty source. */
|
|
66
|
+
narrowedBy?: string;
|
|
67
|
+
}
|
|
68
|
+
/** At or below this many records, with no query/filter narrowing them and no further
|
|
69
|
+
* page, the list/grid toggle, Refine, chips, search and count are noise. */
|
|
70
|
+
export const COLLECTION_CHROME_MIN_ITEMS = 4;
|
|
71
|
+
/** The accessible name of a row's overflow menu: `template` with `{title}` filled, or the
|
|
72
|
+
* generic `fallback` for a record with no title. */
|
|
73
|
+
export function collectionActionsLabel(title: string, template: string, fallback: string): string {
|
|
74
|
+
const t = title.trim();
|
|
75
|
+
return t ? template.replace('{title}', () => t) : fallback;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const COLLECTIONS: Record<string, CollectionConfig> = {
|
|
79
|
+
himiStoreShop: { rows: 'results', title: 'name', subtitle: 'subtitle', image: 'image', view: 'grid', backendQuery: true, countNoun: ['product', 'products'], favoriteToggle: true },
|
|
80
|
+
himiBookingServices: { rows: 'results', title: 'name', subtitle: 'subtitle', image: 'image', filter: 'category', view: 'grid', backendQuery: true, searchPlaceholder: 'Search services', countNoun: ['service', 'services'], primaryVerb: { label: 'Book', screenId: 'himi_time' } },
|
|
81
|
+
himiBookingBookings: { rows: 'rows', title: 'title', subtitle: 'subtitle', metadata: ['status'], view: 'list', backendQuery: true,
|
|
82
|
+
defaultFilter: 'value:Upcoming', searchPlaceholder: 'Search by booking ID', countNoun: ['booking', 'bookings'], filterValues: ['Upcoming', 'Past', 'Cancelled'],
|
|
83
|
+
sortLabels: { default: 'Soonest', az: 'Oldest', za: 'Latest' } },
|
|
84
|
+
himiEvents: { rows: 'results', title: 'title', subtitle: 'dateLine', image: 'image', dateBadge: { text: 'dateBadge', hidden: 'noDateBadge' }, gridColumns: 1, view: 'grid', backendQuery: true, defaultFilter: 'value:Upcoming', searchPlaceholder: 'Search events', countNoun: ['event', 'events'], filterValues: ['Upcoming', 'Past'], sortLabels: { default: 'Date', az: 'Title A–Z', za: 'Title Z–A' }, primaryVerb: { label: 'Register', labelPath: 'actionLabel', hiddenPath: 'noAction' }, shareAction: 'share', endedWhen: 'isPast' },
|
|
85
|
+
himiOwnerLiteProducts: { rows: 'products', title: 'name', subtitle: 'price', image: 'image', view: 'grid', backendQuery: true, countNoun: ['product', 'products'] },
|
|
86
|
+
himiOwnerModules: { instanceInput: 'module', rows: 'rows', title: 'title', subtitle: 'subtitle', image: 'image', filter: 'statusLabel', view: 'list', paged: true, reviewAction: 'prepareRecord', reviewSelectedAction: 'prepareSelected' },
|
|
87
|
+
himiOwnerLiteServices: { rows: 'services', title: 'name', subtitle: 'subtitle', view: 'list', backendQuery: true, searchPlaceholder: 'Service name starts with…' },
|
|
88
|
+
himiOwnerLiteEvents: { rows: 'events', title: 'title', subtitle: 'dateLine', view: 'grid', backendQuery: true, searchPlaceholder: 'Exact event title', filterValues: ['Upcoming'], sortLabels: { default: 'Date', az: 'Title A–Z', za: 'Title Z–A' } },
|
|
89
|
+
himiOwnerLitePosts: { rows: 'posts', title: 'title', subtitle: 'excerpt', image: 'image', view: 'grid' },
|
|
90
|
+
himiOwnerLiteOrders: { rows: 'orders', title: 'buyer', subtitle: 'meta', filter: 'statusLabel', view: 'list', backendQuery: true, countNoun: ['order', 'orders'],
|
|
91
|
+
searchPlaceholder: 'Customer name, email or order #', sortLabels: { default: 'Newest', az: 'Customer A–Z', za: 'Customer Z–A' },
|
|
92
|
+
filterValues: ['Recent 7 days', 'Paid', 'Unpaid', 'Partially paid', 'Pending', 'Refunded', 'Partly refunded'] },
|
|
93
|
+
himiBrandedGroups: { rows: 'rows', title: 'name', subtitle: 'description', image: 'image', view: 'grid' },
|
|
94
|
+
himiBrandedCmsCollection: { instanceInput: 'collection', rows: 'rows', title: 'title', subtitle: 'subtitle', view: 'list' },
|
|
95
|
+
himiBrandedOrders: { rows: 'rows', title: 'title', subtitle: 'subtitle', image: 'image', metadata: ['status', 'meta'], rowStyle: 'flat', view: 'list', backendQuery: true,
|
|
96
|
+
searchPlaceholder: 'Search by order number', countNoun: ['order', 'orders'], filterValues: ['Not fulfilled', 'Partially fulfilled', 'Fulfilled'],
|
|
97
|
+
sortLabels: { default: 'Newest', az: 'Oldest', za: 'Order # ↓' } },
|
|
98
|
+
himiBrandedPlans: { rows: 'rows', title: 'name', subtitle: 'description', metadata: ['badge', 'priceLine', 'periodLine', 'trialBadge', 'perk1', 'perk2', 'perk3', 'joinNote'], view: 'grid', gridColumns: 1, metaMaxLines: 8, countNoun: ['plan', 'plans'] },
|
|
99
|
+
himiBrandedPrograms: { rows: 'rows', title: 'name', subtitle: 'description', image: 'image', view: 'grid' },
|
|
100
|
+
himiBrandedCoupons: { rows: 'coupons', title: 'name', subtitle: 'subtitle', view: 'list', primaryVerb: { label: 'Get code' } },
|
|
101
|
+
himiBrandedNotifications: { rows: 'items', title: 'name', subtitle: 'subtitle', image: 'photo', metadata: ['unreadDot'], view: 'list' },
|
|
102
|
+
himiBrandedLoyalty: { rows: 'rewards', title: 'name', subtitle: 'description', view: 'grid', primaryVerb: { label: 'Redeem' } },
|
|
103
|
+
himiBrandedReviews: { rows: 'reviews', title: 'title', subtitle: 'body', metadata: ['author'], rating: 'rating', view: 'list' },
|
|
104
|
+
himiBrandedPortfolio: { rows: 'projects', title: 'title', subtitle: 'subtitle', image: 'image', view: 'grid', gridImageHeight: 180 },
|
|
105
|
+
himiBrandedInvoices: { rows: 'invoices', title: 'title', subtitle: 'subtitle', view: 'list' },
|
|
106
|
+
himiBrandedBadges: { rows: 'badges', title: 'name', subtitle: 'description', view: 'grid' },
|
|
107
|
+
himiBrandedDonations: { rows: 'campaigns', title: 'name', subtitle: 'description', view: 'grid', primaryVerb: { label: 'Donate' } },
|
|
108
|
+
himiBrandedGiftCards: { rows: 'cards', title: 'name', subtitle: 'description', view: 'grid' },
|
|
109
|
+
himiBrandedVideos: { rows: 'channels', title: 'title', subtitle: 'subtitle', image: 'coverUrl', view: 'grid', searchPlaceholder: 'Search channels', countNoun: ['channel', 'channels'] },
|
|
110
|
+
himiBrandedPodcasts: { rows: 'episodes', title: 'title', subtitle: 'subtitle', image: 'image', metadata: ['progressLabel'], view: 'list' },
|
|
111
|
+
himiBrandedForms: { rows: 'forms', title: 'name', subtitle: 'description', view: 'list' },
|
|
112
|
+
himiBrandedGalleries: { rows: 'galleries', title: 'name', subtitle: 'description', image: 'image', view: 'grid' },
|
|
113
|
+
himiBrandedMenus: { rows: 'rows', title: 'name', subtitle: 'description', image: 'image', sectioned: true, filter: 'collectionCategory', metadata: ['collectionCategory', 'priceLine', 'label1', 'label2', 'label3'], view: 'grid', searchPlaceholder: 'Search the menu', countNoun: ['dish', 'dishes'] },
|
|
114
|
+
};
|
|
115
|
+
export interface CollectionPreferences {
|
|
116
|
+
view: 'list' | 'grid';
|
|
117
|
+
density: 'comfortable' | 'compact';
|
|
118
|
+
sort: 'default' | 'az' | 'za';
|
|
119
|
+
filter: string;
|
|
120
|
+
query: string;
|
|
121
|
+
savedIds: string[];
|
|
122
|
+
selectedIds: string[];
|
|
123
|
+
selecting: boolean;
|
|
124
|
+
savedViews: SavedCollectionView[];
|
|
125
|
+
}
|
|
126
|
+
export interface SavedCollectionView {
|
|
127
|
+
id: string; name: string; view: 'list' | 'grid'; density: 'comfortable' | 'compact';
|
|
128
|
+
sort: 'default' | 'az' | 'za'; query: string; filter: string;
|
|
129
|
+
}
|
|
130
|
+
export interface CollectionItemAction {
|
|
131
|
+
id: string;
|
|
132
|
+
label: string;
|
|
133
|
+
destructive: boolean;
|
|
134
|
+
confirmationRequired: boolean;
|
|
135
|
+
}
|
|
136
|
+
export type CollectionRow = Record<string, unknown>;
|
|
137
|
+
export function initialCollection(config: CollectionConfig): CollectionPreferences {
|
|
138
|
+
return { view: config.view, density: 'comfortable', sort: 'default', filter: config.defaultFilter ?? 'all', query: '', savedIds: [], selectedIds: [], selecting: false, savedViews: [] };
|
|
139
|
+
}
|
|
140
|
+
/** Accept only small presentation preferences from local storage. Selection is
|
|
141
|
+
* transient and never restored as an armed bulk operation. */
|
|
142
|
+
export function normalizeCollection(config: CollectionConfig, value: unknown): CollectionPreferences {
|
|
143
|
+
const s = value && typeof value === 'object' ? value as Partial<CollectionPreferences> : {};
|
|
144
|
+
const base = initialCollection(config);
|
|
145
|
+
return { ...base,
|
|
146
|
+
view: s.view === 'list' || s.view === 'grid' ? s.view : base.view,
|
|
147
|
+
density: s.density === 'compact' ? 'compact' : 'comfortable',
|
|
148
|
+
sort: s.sort === 'az' || s.sort === 'za' ? s.sort : 'default',
|
|
149
|
+
query: typeof s.query === 'string' ? s.query.slice(0, 256) : '',
|
|
150
|
+
// Flat collections no longer offer Saved. Migrate its persisted value before
|
|
151
|
+
// the first backend request so an invisible old filter cannot empty the list.
|
|
152
|
+
filter: config.rowStyle === 'flat' && s.filter === 'saved' ? 'all'
|
|
153
|
+
: typeof s.filter === 'string' ? s.filter.slice(0, 256) : config.defaultFilter ?? 'all',
|
|
154
|
+
savedIds: Array.isArray(s.savedIds) ? [...new Set(s.savedIds.filter((id): id is string => typeof id === 'string' && id.length > 0 && id.length <= 256))].slice(0, 500) : [],
|
|
155
|
+
savedViews: Array.isArray(s.savedViews) ? s.savedViews.filter((v): v is SavedCollectionView => !!v && typeof v === 'object' && typeof v.name === 'string' && !!v.name.trim()).slice(0, 8).map((v, i) => ({
|
|
156
|
+
id: `view-${i}`, name: v.name.trim().slice(0, 40),
|
|
157
|
+
view: v.view === 'list' || v.view === 'grid' ? v.view : config.view,
|
|
158
|
+
density: v.density === 'compact' ? 'compact' : 'comfortable',
|
|
159
|
+
sort: v.sort === 'az' || v.sort === 'za' ? v.sort : 'default',
|
|
160
|
+
query: typeof v.query === 'string' ? v.query.slice(0, 256) : '',
|
|
161
|
+
filter: config.rowStyle === 'flat' && v.filter === 'saved' ? 'all'
|
|
162
|
+
: typeof v.filter === 'string' ? v.filter.slice(0, 256) : 'all',
|
|
163
|
+
})) : [],
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const scalar = (value: unknown): string => typeof value === 'string' || typeof value === 'number' ? String(value) : '';
|
|
167
|
+
export function collectionId(row: CollectionRow): string { return scalar(row.id) || scalar(row._id) || scalar(row.key); }
|
|
168
|
+
export function collectionTitle(row: CollectionRow, config: CollectionConfig): string {
|
|
169
|
+
return scalar(row[config.title]) || scalar(row.title) || scalar(row.name) || scalar(row.display) || scalar(row.label);
|
|
170
|
+
}
|
|
171
|
+
/** Does not mutate domain rows, paging, or domain-derived state. */
|
|
172
|
+
export function projectCollection(source: CollectionRow[], config: CollectionConfig, prefs: CollectionPreferences, backendQuery = false, knownFilters: string[] = []) {
|
|
173
|
+
const query = prefs.query.trim().toLocaleLowerCase();
|
|
174
|
+
const unique = new Set<string>();
|
|
175
|
+
// Menu sections describe their following items; they are not actionable
|
|
176
|
+
// records. Carry the category onto each item before sorting or filtering.
|
|
177
|
+
let category = '';
|
|
178
|
+
const records: CollectionRow[] = config.sectioned ? source.flatMap(row => {
|
|
179
|
+
if (row.isHeader === true) { category = scalar(row.title); return []; }
|
|
180
|
+
return [{ ...row, collectionCategory: category }];
|
|
181
|
+
}) : source;
|
|
182
|
+
const rows = records.filter(row => {
|
|
183
|
+
const id = collectionId(row);
|
|
184
|
+
if (!id) return true; // render anonymous records; identity actions stay disabled
|
|
185
|
+
if (unique.has(id)) return false;
|
|
186
|
+
unique.add(id); return true;
|
|
187
|
+
});
|
|
188
|
+
const filters = config.filterValues ?? [...new Set([...knownFilters, ...rows.map(row => config.filter ? scalar(row[config.filter]) : '')].filter(Boolean))].sort();
|
|
189
|
+
const visible = rows.filter(row => {
|
|
190
|
+
if (backendQuery) return true;
|
|
191
|
+
if (prefs.filter === 'saved' && !prefs.savedIds.includes(collectionId(row))) return false;
|
|
192
|
+
if (prefs.filter.startsWith('value:') && (!config.filter || scalar(row[config.filter]) !== prefs.filter.slice(6))) return false;
|
|
193
|
+
return !query || Object.values(row).some(value => scalar(value).toLocaleLowerCase().includes(query));
|
|
194
|
+
});
|
|
195
|
+
if (!backendQuery && prefs.sort !== 'default') visible.sort((a, b) => {
|
|
196
|
+
const order = compareText(collectionTitle(a, config), collectionTitle(b, config));
|
|
197
|
+
return (prefs.sort === 'az' ? order : -order) || compareIso(collectionId(a), collectionId(b));
|
|
198
|
+
});
|
|
199
|
+
return {
|
|
200
|
+
items: visible.map(row => ({ ...row, collectionId: collectionId(row), collectionTitle: collectionTitle(row, config),
|
|
201
|
+
collectionMeta: [...new Set((config.metadata ?? ['total', 'statusLabel', 'price', 'priceLine', 'dateLine', 'meta']).filter(key => key !== config.subtitle).map(key => scalar(row[key])).filter(Boolean))].join(' · '),
|
|
202
|
+
collectionSelectLabel: prefs.selectedIds.includes(collectionId(row)) ? 'Selected' : 'Select',
|
|
203
|
+
// The save toggle names the action it WILL take (the service localizes it).
|
|
204
|
+
collectionSaveLabel: prefs.savedIds.includes(collectionId(row)) ? 'Remove from saved' : 'Save',
|
|
205
|
+
// The row's overflow menu, named for its record: out of context (a rotor, a voice
|
|
206
|
+
// command) a list of identical "Item actions" cannot be told apart.
|
|
207
|
+
collectionActionsLabel: collectionActionsLabel(collectionTitle(row, config), 'Actions for {title}', 'Item actions'),
|
|
208
|
+
collectionSubtitle: scalar(row[config.subtitle ?? '']) || scalar(row.subtitle) || scalar(row.description) || scalar(row.meta),
|
|
209
|
+
collectionImage: scalar(row[config.image ?? '']), collectionNoImage: !scalar(row[config.image ?? '']), collectionHasImage: !!scalar(row[config.image ?? '']),
|
|
210
|
+
collectionSaved: prefs.savedIds.includes(collectionId(row)), collectionNotSaved: !prefs.savedIds.includes(collectionId(row)), collectionSelected: prefs.selectedIds.includes(collectionId(row)),
|
|
211
|
+
collectionNoIdentity: !collectionId(row),
|
|
212
|
+
// Older cached EventRows predate `isPast` but already stored `statusLabel: "Past"`.
|
|
213
|
+
// Keep their ended state through an offline render until the row is refreshed.
|
|
214
|
+
...(config.endedWhen ? (() => {
|
|
215
|
+
const ended = row[config.endedWhen] === true || (config.endedWhen === 'isPast' && row.statusLabel === 'Past');
|
|
216
|
+
return { collectionEnded: ended, collectionNotEnded: !ended };
|
|
217
|
+
})() : {}),
|
|
218
|
+
// A row restored from state saved by an older build has no badge flag. An unset hidden flag
|
|
219
|
+
// fails open and would paint an empty chip, so it reads as "no badge" until a refresh.
|
|
220
|
+
...(config.dateBadge && typeof row[config.dateBadge.hidden] !== 'boolean'
|
|
221
|
+
? { [config.dateBadge.text]: '', [config.dateBadge.hidden]: true } : {}),
|
|
222
|
+
// Same for a per-row verb: an unset hidden flag fails open and would show a verb with an unresolved
|
|
223
|
+
// label, so a row without the flag offers no action until a refresh establishes one.
|
|
224
|
+
...(config.primaryVerb?.hiddenPath && typeof row[config.primaryVerb.hiddenPath] !== 'boolean'
|
|
225
|
+
? { ...(config.primaryVerb.labelPath ? { [config.primaryVerb.labelPath]: '' } : {}), [config.primaryVerb.hiddenPath]: true } : {}) })),
|
|
226
|
+
filters, loaded: rows.length,
|
|
227
|
+
};
|
|
228
|
+
}
|