@wix/himalaya-cli 0.1851.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.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/builder.d.ts +5 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +13 -3
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{166f7ee733ea8d0fe7bba8b796232efd4f5413e22af4a8aeee20cae1069b2fd6.bin → fb500748f6c4768468f2e7f985aa67c38633077c7a98caaa6b500c7b00eea8e9.bin} +1 -1
- package/dist/browser-plane/sw.js +7 -7
- package/dist/cli.mjs +10136 -9601
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/component-index.md +1 -1
- package/guides/component-reference.json +2 -2
- package/guides/component-reference.md +8 -1
- package/guides/designing-himi-screens.md +5 -1
- package/guides/himi-json-output.md +13 -3
- package/guides/one-app-section-mappings.md +1 -1
- package/guides/one-app-to-himi-app.md +60 -10
- package/guides/sdk-reference.json +2 -2
- 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/dev/index.ts +223 -0
- package/templates/beauty-salon/l10n/ar.json +6 -0
- package/templates/beauty-salon/l10n/cs.json +6 -0
- package/templates/beauty-salon/l10n/da.json +6 -0
- package/templates/beauty-salon/l10n/de.json +6 -0
- package/templates/beauty-salon/l10n/el.json +6 -0
- package/templates/beauty-salon/l10n/en.json +9 -2
- package/templates/beauty-salon/l10n/es.json +6 -0
- package/templates/beauty-salon/l10n/fi.json +6 -0
- package/templates/beauty-salon/l10n/fr.json +6 -0
- package/templates/beauty-salon/l10n/he.json +5 -0
- package/templates/beauty-salon/l10n/hu.json +6 -0
- package/templates/beauty-salon/l10n/id.json +6 -0
- package/templates/beauty-salon/l10n/it.json +6 -0
- package/templates/beauty-salon/l10n/ja.json +6 -0
- package/templates/beauty-salon/l10n/ko.json +6 -0
- package/templates/beauty-salon/l10n/lt.json +6 -0
- package/templates/beauty-salon/l10n/nl.json +6 -0
- package/templates/beauty-salon/l10n/no.json +6 -0
- package/templates/beauty-salon/l10n/pl.json +6 -0
- package/templates/beauty-salon/l10n/pt.json +6 -0
- package/templates/beauty-salon/l10n/ru.json +6 -0
- package/templates/beauty-salon/l10n/sv.json +6 -0
- package/templates/beauty-salon/l10n/th.json +6 -0
- package/templates/beauty-salon/l10n/tr.json +6 -0
- package/templates/beauty-salon/l10n/uk.json +6 -0
- package/templates/beauty-salon/l10n/vi.json +6 -0
- package/templates/beauty-salon/l10n/zh.json +6 -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/tier5-src/_shared/lifecycle.ts +15 -0
- package/templates/beauty-salon/tier5-src/_shared/nav-member-avatar.ts +92 -0
- package/templates/beauty-salon/tier5-src/himi-branded-lite-nav/index.ts +15 -6
- package/templates/beauty-salon/tier5-src/himi-store-account/index.ts +26 -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/dev/index.ts +2167 -0
- package/templates/branded-lite/l10n/ar.json +6 -0
- package/templates/branded-lite/l10n/cs.json +6 -0
- package/templates/branded-lite/l10n/da.json +6 -0
- package/templates/branded-lite/l10n/de.json +6 -0
- package/templates/branded-lite/l10n/el.json +6 -0
- package/templates/branded-lite/l10n/en.json +12 -5
- package/templates/branded-lite/l10n/es.json +6 -0
- package/templates/branded-lite/l10n/fi.json +6 -0
- package/templates/branded-lite/l10n/fr.json +6 -0
- package/templates/branded-lite/l10n/he.json +5 -0
- package/templates/branded-lite/l10n/hu.json +6 -0
- package/templates/branded-lite/l10n/id.json +6 -0
- package/templates/branded-lite/l10n/it.json +6 -0
- package/templates/branded-lite/l10n/ja.json +6 -0
- package/templates/branded-lite/l10n/ko.json +6 -0
- package/templates/branded-lite/l10n/lt.json +6 -0
- package/templates/branded-lite/l10n/nl.json +6 -0
- package/templates/branded-lite/l10n/no.json +6 -0
- package/templates/branded-lite/l10n/pl.json +6 -0
- package/templates/branded-lite/l10n/pt.json +6 -0
- package/templates/branded-lite/l10n/ru.json +6 -0
- package/templates/branded-lite/l10n/sv.json +6 -0
- package/templates/branded-lite/l10n/th.json +6 -0
- package/templates/branded-lite/l10n/tr.json +6 -0
- package/templates/branded-lite/l10n/uk.json +6 -0
- package/templates/branded-lite/l10n/vi.json +6 -0
- package/templates/branded-lite/l10n/zh.json +6 -0
- package/templates/branded-lite/recipes/upcoming-bookings.json +118 -6
- package/templates/branded-lite/tier5-src/_shared/access-gates.ts +0 -13
- 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/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/guest-sign-in.ts +36 -0
- package/templates/branded-lite/tier5-src/_shared/lifecycle.ts +15 -0
- package/templates/branded-lite/tier5-src/_shared/nav-member-avatar.ts +92 -0
- package/templates/branded-lite/tier5-src/_shared/upcoming-bookings-section.ts +15 -4
- package/templates/branded-lite/tier5-src/himi-branded-lite-access-nav/index.ts +14 -9
- package/templates/branded-lite/tier5-src/himi-branded-lite-inbox/index.ts +6 -1
- package/templates/branded-lite/tier5-src/himi-branded-lite-nav/index.ts +15 -6
- package/templates/branded-lite/tier5-src/himi-branded-lite-notifications/index.ts +8 -1
- package/templates/branded-lite/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/branded-lite/tier5-src/himi-store-account/index.ts +26 -1
- 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/brandy/tier5-src/_shared/guest-sign-in.ts +36 -0
- package/templates/brandy/tier5-src/himi-branded-lite-inbox/index.ts +6 -1
- package/templates/brandy/tier5-src/himi-branded-lite-notifications/index.ts +8 -1
- package/templates/brandy/tier5-src/himi-store-account/index.ts +26 -1
- package/templates/community-club/dev/index.ts +223 -0
- package/templates/community-club/l10n/ar.json +6 -0
- package/templates/community-club/l10n/cs.json +6 -0
- package/templates/community-club/l10n/da.json +6 -0
- package/templates/community-club/l10n/de.json +6 -0
- package/templates/community-club/l10n/el.json +6 -0
- package/templates/community-club/l10n/en.json +9 -2
- package/templates/community-club/l10n/es.json +6 -0
- package/templates/community-club/l10n/fi.json +6 -0
- package/templates/community-club/l10n/fr.json +6 -0
- package/templates/community-club/l10n/he.json +5 -0
- package/templates/community-club/l10n/hu.json +6 -0
- package/templates/community-club/l10n/id.json +6 -0
- package/templates/community-club/l10n/it.json +6 -0
- package/templates/community-club/l10n/ja.json +6 -0
- package/templates/community-club/l10n/ko.json +6 -0
- package/templates/community-club/l10n/lt.json +6 -0
- package/templates/community-club/l10n/nl.json +6 -0
- package/templates/community-club/l10n/no.json +6 -0
- package/templates/community-club/l10n/pl.json +6 -0
- package/templates/community-club/l10n/pt.json +6 -0
- package/templates/community-club/l10n/ru.json +6 -0
- package/templates/community-club/l10n/sv.json +6 -0
- package/templates/community-club/l10n/th.json +6 -0
- package/templates/community-club/l10n/tr.json +6 -0
- package/templates/community-club/l10n/uk.json +6 -0
- package/templates/community-club/l10n/vi.json +6 -0
- package/templates/community-club/l10n/zh.json +6 -0
- 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/tier5-src/himi-store-account/index.ts +26 -1
- 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/conference/tier5-src/himi-store-account/index.ts +26 -1
- package/templates/events-meetups/dev/index.ts +142 -0
- package/templates/events-meetups/l10n/ar.json +6 -0
- package/templates/events-meetups/l10n/cs.json +6 -0
- package/templates/events-meetups/l10n/da.json +6 -0
- package/templates/events-meetups/l10n/de.json +6 -0
- package/templates/events-meetups/l10n/el.json +6 -0
- package/templates/events-meetups/l10n/en.json +8 -1
- package/templates/events-meetups/l10n/es.json +6 -0
- package/templates/events-meetups/l10n/fi.json +6 -0
- package/templates/events-meetups/l10n/fr.json +6 -0
- package/templates/events-meetups/l10n/he.json +5 -0
- package/templates/events-meetups/l10n/hu.json +6 -0
- package/templates/events-meetups/l10n/id.json +6 -0
- package/templates/events-meetups/l10n/it.json +6 -0
- package/templates/events-meetups/l10n/ja.json +6 -0
- package/templates/events-meetups/l10n/ko.json +6 -0
- package/templates/events-meetups/l10n/lt.json +6 -0
- package/templates/events-meetups/l10n/nl.json +6 -0
- package/templates/events-meetups/l10n/no.json +6 -0
- package/templates/events-meetups/l10n/pl.json +6 -0
- package/templates/events-meetups/l10n/pt.json +6 -0
- package/templates/events-meetups/l10n/ru.json +6 -0
- package/templates/events-meetups/l10n/sv.json +6 -0
- package/templates/events-meetups/l10n/th.json +6 -0
- package/templates/events-meetups/l10n/tr.json +6 -0
- package/templates/events-meetups/l10n/uk.json +6 -0
- package/templates/events-meetups/l10n/vi.json +6 -0
- package/templates/events-meetups/l10n/zh.json +6 -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/tier5-src/himi-store-account/index.ts +26 -1
- 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/fitness-gym/tier5-src/_shared/guest-sign-in.ts +36 -0
- package/templates/fitness-gym/tier5-src/himi-branded-lite-notifications/index.ts +8 -1
- package/templates/fitness-gym/tier5-src/himi-store-account/index.ts +26 -1
- package/templates/gym-fitness/dev/index.ts +385 -0
- package/templates/gym-fitness/l10n/ar.json +6 -0
- package/templates/gym-fitness/l10n/cs.json +6 -0
- package/templates/gym-fitness/l10n/da.json +6 -0
- package/templates/gym-fitness/l10n/de.json +6 -0
- package/templates/gym-fitness/l10n/el.json +6 -0
- package/templates/gym-fitness/l10n/en.json +9 -2
- package/templates/gym-fitness/l10n/es.json +6 -0
- package/templates/gym-fitness/l10n/fi.json +6 -0
- package/templates/gym-fitness/l10n/fr.json +6 -0
- package/templates/gym-fitness/l10n/he.json +5 -0
- package/templates/gym-fitness/l10n/hu.json +6 -0
- package/templates/gym-fitness/l10n/id.json +6 -0
- package/templates/gym-fitness/l10n/it.json +6 -0
- package/templates/gym-fitness/l10n/ja.json +6 -0
- package/templates/gym-fitness/l10n/ko.json +6 -0
- package/templates/gym-fitness/l10n/lt.json +6 -0
- package/templates/gym-fitness/l10n/nl.json +6 -0
- package/templates/gym-fitness/l10n/no.json +6 -0
- package/templates/gym-fitness/l10n/pl.json +6 -0
- package/templates/gym-fitness/l10n/pt.json +6 -0
- package/templates/gym-fitness/l10n/ru.json +6 -0
- package/templates/gym-fitness/l10n/sv.json +6 -0
- package/templates/gym-fitness/l10n/th.json +6 -0
- package/templates/gym-fitness/l10n/tr.json +6 -0
- package/templates/gym-fitness/l10n/uk.json +6 -0
- package/templates/gym-fitness/l10n/vi.json +6 -0
- package/templates/gym-fitness/l10n/zh.json +6 -0
- 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/_shared/lifecycle.ts +15 -0
- package/templates/gym-fitness/tier5-src/_shared/nav-member-avatar.ts +92 -0
- package/templates/gym-fitness/tier5-src/himi-branded-lite-nav/index.ts +15 -6
- package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/gym-fitness/tier5-src/himi-store-account/index.ts +26 -1
- 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/medical-services/tier5-src/_shared/guest-sign-in.ts +36 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-notifications/index.ts +8 -1
- package/templates/medical-services/tier5-src/himi-store-account/index.ts +26 -1
- package/templates/nonprofit-cause/dev/index.ts +223 -0
- package/templates/nonprofit-cause/l10n/ar.json +6 -0
- package/templates/nonprofit-cause/l10n/cs.json +6 -0
- package/templates/nonprofit-cause/l10n/da.json +6 -0
- package/templates/nonprofit-cause/l10n/de.json +6 -0
- package/templates/nonprofit-cause/l10n/el.json +6 -0
- package/templates/nonprofit-cause/l10n/en.json +8 -1
- package/templates/nonprofit-cause/l10n/es.json +6 -0
- package/templates/nonprofit-cause/l10n/fi.json +6 -0
- package/templates/nonprofit-cause/l10n/fr.json +6 -0
- package/templates/nonprofit-cause/l10n/he.json +5 -0
- package/templates/nonprofit-cause/l10n/hu.json +6 -0
- package/templates/nonprofit-cause/l10n/id.json +6 -0
- package/templates/nonprofit-cause/l10n/it.json +6 -0
- package/templates/nonprofit-cause/l10n/ja.json +6 -0
- package/templates/nonprofit-cause/l10n/ko.json +6 -0
- package/templates/nonprofit-cause/l10n/lt.json +6 -0
- package/templates/nonprofit-cause/l10n/nl.json +6 -0
- package/templates/nonprofit-cause/l10n/no.json +6 -0
- package/templates/nonprofit-cause/l10n/pl.json +6 -0
- package/templates/nonprofit-cause/l10n/pt.json +6 -0
- package/templates/nonprofit-cause/l10n/ru.json +6 -0
- package/templates/nonprofit-cause/l10n/sv.json +6 -0
- package/templates/nonprofit-cause/l10n/th.json +6 -0
- package/templates/nonprofit-cause/l10n/tr.json +6 -0
- package/templates/nonprofit-cause/l10n/uk.json +6 -0
- package/templates/nonprofit-cause/l10n/vi.json +6 -0
- package/templates/nonprofit-cause/l10n/zh.json +6 -0
- 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/tier5-src/himi-store-account/index.ts +26 -1
- 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/personal-fitness-trainer/tier5-src/himi-store-account/index.ts +26 -1
- package/templates/podcast-creator/dev/index.ts +223 -0
- package/templates/podcast-creator/l10n/ar.json +6 -0
- package/templates/podcast-creator/l10n/cs.json +6 -0
- package/templates/podcast-creator/l10n/da.json +6 -0
- package/templates/podcast-creator/l10n/de.json +6 -0
- package/templates/podcast-creator/l10n/el.json +6 -0
- package/templates/podcast-creator/l10n/en.json +8 -1
- package/templates/podcast-creator/l10n/es.json +6 -0
- package/templates/podcast-creator/l10n/fi.json +6 -0
- package/templates/podcast-creator/l10n/fr.json +6 -0
- package/templates/podcast-creator/l10n/he.json +5 -0
- package/templates/podcast-creator/l10n/hu.json +6 -0
- package/templates/podcast-creator/l10n/id.json +6 -0
- package/templates/podcast-creator/l10n/it.json +6 -0
- package/templates/podcast-creator/l10n/ja.json +6 -0
- package/templates/podcast-creator/l10n/ko.json +6 -0
- package/templates/podcast-creator/l10n/lt.json +6 -0
- package/templates/podcast-creator/l10n/nl.json +6 -0
- package/templates/podcast-creator/l10n/no.json +6 -0
- package/templates/podcast-creator/l10n/pl.json +6 -0
- package/templates/podcast-creator/l10n/pt.json +6 -0
- package/templates/podcast-creator/l10n/ru.json +6 -0
- package/templates/podcast-creator/l10n/sv.json +6 -0
- package/templates/podcast-creator/l10n/th.json +6 -0
- package/templates/podcast-creator/l10n/tr.json +6 -0
- package/templates/podcast-creator/l10n/uk.json +6 -0
- package/templates/podcast-creator/l10n/vi.json +6 -0
- package/templates/podcast-creator/l10n/zh.json +6 -0
- 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/tier5-src/himi-store-account/index.ts +26 -1
- 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/dev/index.ts +142 -0
- package/templates/portfolio-creative/l10n/ar.json +6 -0
- package/templates/portfolio-creative/l10n/cs.json +6 -0
- package/templates/portfolio-creative/l10n/da.json +6 -0
- package/templates/portfolio-creative/l10n/de.json +6 -0
- package/templates/portfolio-creative/l10n/el.json +6 -0
- package/templates/portfolio-creative/l10n/en.json +8 -1
- package/templates/portfolio-creative/l10n/es.json +6 -0
- package/templates/portfolio-creative/l10n/fi.json +6 -0
- package/templates/portfolio-creative/l10n/fr.json +6 -0
- package/templates/portfolio-creative/l10n/he.json +5 -0
- package/templates/portfolio-creative/l10n/hu.json +6 -0
- package/templates/portfolio-creative/l10n/id.json +6 -0
- package/templates/portfolio-creative/l10n/it.json +6 -0
- package/templates/portfolio-creative/l10n/ja.json +6 -0
- package/templates/portfolio-creative/l10n/ko.json +6 -0
- package/templates/portfolio-creative/l10n/lt.json +6 -0
- package/templates/portfolio-creative/l10n/nl.json +6 -0
- package/templates/portfolio-creative/l10n/no.json +6 -0
- package/templates/portfolio-creative/l10n/pl.json +6 -0
- package/templates/portfolio-creative/l10n/pt.json +6 -0
- package/templates/portfolio-creative/l10n/ru.json +6 -0
- package/templates/portfolio-creative/l10n/sv.json +6 -0
- package/templates/portfolio-creative/l10n/th.json +6 -0
- package/templates/portfolio-creative/l10n/tr.json +6 -0
- package/templates/portfolio-creative/l10n/uk.json +6 -0
- package/templates/portfolio-creative/l10n/vi.json +6 -0
- package/templates/portfolio-creative/l10n/zh.json +6 -0
- 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/tier5-src/himi-store-account/index.ts +26 -1
- 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/dev/index.ts +142 -0
- package/templates/restaurant/l10n/ar.json +6 -0
- package/templates/restaurant/l10n/cs.json +6 -0
- package/templates/restaurant/l10n/da.json +6 -0
- package/templates/restaurant/l10n/de.json +6 -0
- package/templates/restaurant/l10n/el.json +6 -0
- package/templates/restaurant/l10n/en.json +9 -2
- package/templates/restaurant/l10n/es.json +6 -0
- package/templates/restaurant/l10n/fi.json +6 -0
- package/templates/restaurant/l10n/fr.json +6 -0
- package/templates/restaurant/l10n/he.json +5 -0
- package/templates/restaurant/l10n/hu.json +6 -0
- package/templates/restaurant/l10n/id.json +6 -0
- package/templates/restaurant/l10n/it.json +6 -0
- package/templates/restaurant/l10n/ja.json +6 -0
- package/templates/restaurant/l10n/ko.json +6 -0
- package/templates/restaurant/l10n/lt.json +6 -0
- package/templates/restaurant/l10n/nl.json +6 -0
- package/templates/restaurant/l10n/no.json +6 -0
- package/templates/restaurant/l10n/pl.json +6 -0
- package/templates/restaurant/l10n/pt.json +6 -0
- package/templates/restaurant/l10n/ru.json +6 -0
- package/templates/restaurant/l10n/sv.json +6 -0
- package/templates/restaurant/l10n/th.json +6 -0
- package/templates/restaurant/l10n/tr.json +6 -0
- package/templates/restaurant/l10n/uk.json +6 -0
- package/templates/restaurant/l10n/vi.json +6 -0
- package/templates/restaurant/l10n/zh.json +6 -0
- 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/tier5-src/himi-store-account/index.ts +26 -1
- 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/dev/index.ts +142 -0
- package/templates/retail-store/l10n/ar.json +6 -0
- package/templates/retail-store/l10n/cs.json +6 -0
- package/templates/retail-store/l10n/da.json +6 -0
- package/templates/retail-store/l10n/de.json +6 -0
- package/templates/retail-store/l10n/el.json +6 -0
- package/templates/retail-store/l10n/en.json +8 -1
- package/templates/retail-store/l10n/es.json +6 -0
- package/templates/retail-store/l10n/fi.json +6 -0
- package/templates/retail-store/l10n/fr.json +6 -0
- package/templates/retail-store/l10n/he.json +5 -0
- package/templates/retail-store/l10n/hu.json +6 -0
- package/templates/retail-store/l10n/id.json +6 -0
- package/templates/retail-store/l10n/it.json +6 -0
- package/templates/retail-store/l10n/ja.json +6 -0
- package/templates/retail-store/l10n/ko.json +6 -0
- package/templates/retail-store/l10n/lt.json +6 -0
- package/templates/retail-store/l10n/nl.json +6 -0
- package/templates/retail-store/l10n/no.json +6 -0
- package/templates/retail-store/l10n/pl.json +6 -0
- package/templates/retail-store/l10n/pt.json +6 -0
- package/templates/retail-store/l10n/ru.json +6 -0
- package/templates/retail-store/l10n/sv.json +6 -0
- package/templates/retail-store/l10n/th.json +6 -0
- package/templates/retail-store/l10n/tr.json +6 -0
- package/templates/retail-store/l10n/uk.json +6 -0
- package/templates/retail-store/l10n/vi.json +6 -0
- package/templates/retail-store/l10n/zh.json +6 -0
- 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/tier5-src/himi-store-account/index.ts +26 -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/salon-spa/tier5-src/himi-store-account/index.ts +26 -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/wholesale-store/tier5-src/himi-store-account/index.ts +26 -1
- package/templates/yoga-studio/dev/index.ts +304 -0
- package/templates/yoga-studio/l10n/ar.json +6 -0
- package/templates/yoga-studio/l10n/cs.json +6 -0
- package/templates/yoga-studio/l10n/da.json +6 -0
- package/templates/yoga-studio/l10n/de.json +6 -0
- package/templates/yoga-studio/l10n/el.json +6 -0
- package/templates/yoga-studio/l10n/en.json +10 -3
- package/templates/yoga-studio/l10n/es.json +6 -0
- package/templates/yoga-studio/l10n/fi.json +6 -0
- package/templates/yoga-studio/l10n/fr.json +6 -0
- package/templates/yoga-studio/l10n/he.json +5 -0
- package/templates/yoga-studio/l10n/hu.json +6 -0
- package/templates/yoga-studio/l10n/id.json +6 -0
- package/templates/yoga-studio/l10n/it.json +6 -0
- package/templates/yoga-studio/l10n/ja.json +6 -0
- package/templates/yoga-studio/l10n/ko.json +6 -0
- package/templates/yoga-studio/l10n/lt.json +6 -0
- package/templates/yoga-studio/l10n/nl.json +6 -0
- package/templates/yoga-studio/l10n/no.json +6 -0
- package/templates/yoga-studio/l10n/pl.json +6 -0
- package/templates/yoga-studio/l10n/pt.json +6 -0
- package/templates/yoga-studio/l10n/ru.json +6 -0
- package/templates/yoga-studio/l10n/sv.json +6 -0
- package/templates/yoga-studio/l10n/th.json +6 -0
- package/templates/yoga-studio/l10n/tr.json +6 -0
- package/templates/yoga-studio/l10n/uk.json +6 -0
- package/templates/yoga-studio/l10n/vi.json +6 -0
- package/templates/yoga-studio/l10n/zh.json +6 -0
- 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/_shared/lifecycle.ts +15 -0
- package/templates/yoga-studio/tier5-src/_shared/nav-member-avatar.ts +92 -0
- package/templates/yoga-studio/tier5-src/himi-branded-lite-nav/index.ts +15 -6
- package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/yoga-studio/tier5-src/himi-store-account/index.ts +26 -1
- 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,367 @@
|
|
|
1
|
+
// Tier-5 bundle: himi-store-address-form — add or edit one address in the member's Wix
|
|
2
|
+
// address book. Opened from My addresses: no `id` adds an address, an `id` edits it.
|
|
3
|
+
//
|
|
4
|
+
// Fields follow the Wix address form: first and last name, company, country, address,
|
|
5
|
+
// address line 2, city, region (only for a country with a region list), postal code and
|
|
6
|
+
// phone. Countries and regions are the Wix locale dataset, so checkout reads the same codes.
|
|
7
|
+
// After a save the worker bumps the address-book row (the list screen reloads) and goes back.
|
|
8
|
+
import { defineService, navigate } from "@himalaya/state";
|
|
9
|
+
import { COUNTRIES, type CountryRow } from "../_shared/bare-fashion-address-countries.js";
|
|
10
|
+
import { signedInEmail } from "../_shared/himi-account.js";
|
|
11
|
+
import {
|
|
12
|
+
getAddress, createAddress, updateAddress, bumpAddressBook, countryByCode, regionName, streetLineOf,
|
|
13
|
+
type WixAddress,
|
|
14
|
+
} from "../_shared/bare-fashion-address-book.js";
|
|
15
|
+
import { errorFlags, errorKindOf, type ErrorKind } from "../_shared/bare-fashion-load-error.js";
|
|
16
|
+
import { appLocale, setAppLocale } from "../_shared/app-locale.js";
|
|
17
|
+
|
|
18
|
+
type Field = "firstName" | "lastName" | "company" | "addressLine1" | "addressLine2" | "city" | "zipCode" | "phone";
|
|
19
|
+
const FIELDS: Field[] = ["firstName", "lastName", "company", "addressLine1", "addressLine2", "city", "zipCode", "phone"];
|
|
20
|
+
|
|
21
|
+
/** Countries where Wix checkout does not need a postal code. */
|
|
22
|
+
const NO_POSTCODE = new Set(["ARE", "HKG", "IRL", "MAC", "QAT", "BHS", "PAN", "JAM", "FJI", "GHA", "AGO", "BOL", "BWA", "TTO", "ZWE"]);
|
|
23
|
+
|
|
24
|
+
interface PickRow { id: string; label: string; selected: boolean; notSelected: boolean }
|
|
25
|
+
|
|
26
|
+
interface S {
|
|
27
|
+
status: "loading" | "ready" | "error" | "signedOut";
|
|
28
|
+
editId: string;
|
|
29
|
+
title: string;
|
|
30
|
+
saveLabel: string;
|
|
31
|
+
firstName: string;
|
|
32
|
+
lastName: string;
|
|
33
|
+
company: string;
|
|
34
|
+
addressLine1: string;
|
|
35
|
+
addressLine2: string;
|
|
36
|
+
city: string;
|
|
37
|
+
zipCode: string;
|
|
38
|
+
phone: string;
|
|
39
|
+
formDirty: boolean;
|
|
40
|
+
countryCode: string;
|
|
41
|
+
countryLabel: string;
|
|
42
|
+
regionKey: string;
|
|
43
|
+
regionValue: string;
|
|
44
|
+
regionLabel: string;
|
|
45
|
+
cityLabel: string;
|
|
46
|
+
zipLabel: string;
|
|
47
|
+
hideRegion: boolean;
|
|
48
|
+
setAsDefault: boolean;
|
|
49
|
+
/** The address is the default already: the switch has nothing to do. */
|
|
50
|
+
hideDefaultSwitch: boolean;
|
|
51
|
+
/** Field errors ("" = none) and the flags that swap the select boxes' border. */
|
|
52
|
+
errFirstName: string;
|
|
53
|
+
errLastName: string;
|
|
54
|
+
errCountry: string;
|
|
55
|
+
errAddressLine1: string;
|
|
56
|
+
errCity: string;
|
|
57
|
+
errRegion: string;
|
|
58
|
+
errZipCode: string;
|
|
59
|
+
countryNoError: boolean;
|
|
60
|
+
countryHasError: boolean;
|
|
61
|
+
regionNoError: boolean;
|
|
62
|
+
regionHasError: boolean;
|
|
63
|
+
message: string;
|
|
64
|
+
saving: boolean;
|
|
65
|
+
notSaving: boolean;
|
|
66
|
+
/** Picker sheets. */
|
|
67
|
+
countrySheetOpen: boolean;
|
|
68
|
+
countryQuery: string;
|
|
69
|
+
countryItems: PickRow[];
|
|
70
|
+
regionSheetOpen: boolean;
|
|
71
|
+
regionItems: PickRow[];
|
|
72
|
+
hideForm: boolean;
|
|
73
|
+
hideLoading: boolean;
|
|
74
|
+
hideError: boolean;
|
|
75
|
+
/** Why the last load failed: the error state shows the offline or the server variant. */
|
|
76
|
+
errorKind?: ErrorKind;
|
|
77
|
+
hideOfflineError?: boolean;
|
|
78
|
+
hideServerError?: boolean;
|
|
79
|
+
hideSignedOut: boolean;
|
|
80
|
+
/** Token that focuses the first invalid text field. */
|
|
81
|
+
focusFirstName: string;
|
|
82
|
+
focusLastName: string;
|
|
83
|
+
focusAddressLine1: string;
|
|
84
|
+
focusCity: string;
|
|
85
|
+
focusZipCode: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function inputId(): string {
|
|
89
|
+
const input = (globalThis as { himalaya?: { input?: { id?: unknown } } }).himalaya?.input;
|
|
90
|
+
return typeof input?.id === "string" ? input.id : "";
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function textOf(arg: unknown): string {
|
|
94
|
+
if (typeof arg === "string") return arg;
|
|
95
|
+
const a = arg as { value?: unknown; text?: unknown } | undefined;
|
|
96
|
+
const v = a?.value ?? a?.text;
|
|
97
|
+
return typeof v === "string" ? v : "";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function boolOf(arg: unknown): boolean {
|
|
101
|
+
const v = arg && typeof arg === "object" ? (arg as { value?: unknown }).value : arg;
|
|
102
|
+
return v === true || v === "true";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function idOf(arg: unknown): string {
|
|
106
|
+
const id = arg && typeof arg === "object" ? (arg as { id?: unknown }).id : arg;
|
|
107
|
+
return typeof id === "string" ? id : "";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Take the app's language tag when the action carries one; an argument without it (pull to
|
|
111
|
+
* refresh) keeps the tag already set. */
|
|
112
|
+
function takeLocale(arg: unknown): void {
|
|
113
|
+
const locale = (arg as { locale?: unknown } | undefined)?.locale;
|
|
114
|
+
if (typeof locale === "string" && locale) setAppLocale(locale);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The app's region ("en-IE" → "IE"), the first guess for a new address. It reads the app's own
|
|
118
|
+
* language tag rather than `Intl`, which a bare iOS JSContext and the wrist engine do not have. */
|
|
119
|
+
function deviceCountry(): CountryRow | undefined {
|
|
120
|
+
const region = appLocale().split(/[-_]/).find((part, i) => i > 0 && /^[A-Z]{2}$/.test(part));
|
|
121
|
+
return region ? countryByCode(region) : undefined;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function countryItems(selected: string, query: string): PickRow[] {
|
|
125
|
+
const q = query.trim().toLowerCase();
|
|
126
|
+
return COUNTRIES
|
|
127
|
+
.filter((c) => !q || c[2].toLowerCase().includes(q) || c[1].toLowerCase() === q || c[0].toLowerCase() === q)
|
|
128
|
+
.map((c) => ({ id: c[0], label: c[2], selected: c[0] === selected, notSelected: c[0] !== selected }));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function derive(s: S): S {
|
|
132
|
+
const country = countryByCode(s.countryCode);
|
|
133
|
+
const regions = country?.[6] ?? [];
|
|
134
|
+
const ready = s.status === "ready";
|
|
135
|
+
return {
|
|
136
|
+
...s,
|
|
137
|
+
title: s.editId ? "Edit address" : "Add new address",
|
|
138
|
+
saveLabel: s.saving ? "SAVING…" : "SAVE ADDRESS",
|
|
139
|
+
notSaving: !s.saving,
|
|
140
|
+
countryLabel: country?.[2] ?? "Select a country",
|
|
141
|
+
regionLabel: country?.[3] || "State",
|
|
142
|
+
cityLabel: country?.[4] || "City",
|
|
143
|
+
zipLabel: country?.[5] || "Zip / Postal code",
|
|
144
|
+
regionValue: s.regionKey ? regionName(country, s.regionKey) : `Select ${(country?.[3] || "state").toLowerCase()}`,
|
|
145
|
+
hideRegion: regions.length === 0,
|
|
146
|
+
countryNoError: !s.errCountry,
|
|
147
|
+
countryHasError: !!s.errCountry,
|
|
148
|
+
regionNoError: !s.errRegion,
|
|
149
|
+
regionHasError: !!s.errRegion,
|
|
150
|
+
countryItems: s.countrySheetOpen ? countryItems(s.countryCode, s.countryQuery) : [],
|
|
151
|
+
regionItems: s.regionSheetOpen
|
|
152
|
+
? regions.map(([k, n]) => ({ id: k, label: n, selected: k === s.regionKey, notSelected: k !== s.regionKey }))
|
|
153
|
+
: [],
|
|
154
|
+
hideForm: !ready,
|
|
155
|
+
hideLoading: s.status !== "loading",
|
|
156
|
+
hideError: s.status !== "error",
|
|
157
|
+
...errorFlags(s.status, s.errorKind),
|
|
158
|
+
hideSignedOut: s.status !== "signedOut",
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const NO_ERRORS = { errFirstName: "", errLastName: "", errCountry: "", errAddressLine1: "", errCity: "", errRegion: "", errZipCode: "" };
|
|
163
|
+
|
|
164
|
+
function blank(): S {
|
|
165
|
+
return derive({
|
|
166
|
+
status: "loading", editId: "", title: "", saveLabel: "",
|
|
167
|
+
firstName: "", lastName: "", company: "", addressLine1: "", addressLine2: "", city: "", zipCode: "", phone: "",
|
|
168
|
+
countryCode: "", countryLabel: "", regionKey: "", regionValue: "", regionLabel: "", cityLabel: "", zipLabel: "",
|
|
169
|
+
hideRegion: true, setAsDefault: false, hideDefaultSwitch: false,
|
|
170
|
+
...NO_ERRORS,
|
|
171
|
+
countryNoError: true, countryHasError: false, regionNoError: true, regionHasError: false,
|
|
172
|
+
message: "", saving: false, notSaving: true, formDirty: false,
|
|
173
|
+
countrySheetOpen: false, countryQuery: "", countryItems: [], regionSheetOpen: false, regionItems: [],
|
|
174
|
+
hideForm: true, hideLoading: false, hideError: true, hideSignedOut: true,
|
|
175
|
+
focusFirstName: "", focusLastName: "", focusAddressLine1: "", focusCity: "", focusZipCode: "",
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function fromAddress(s: S, a: WixAddress, isDefault: boolean): S {
|
|
180
|
+
const country = countryByCode(a.country);
|
|
181
|
+
const sub = String(a.subdivision ?? "");
|
|
182
|
+
return derive({
|
|
183
|
+
...s,
|
|
184
|
+
status: "ready",
|
|
185
|
+
formDirty: false,
|
|
186
|
+
firstName: a.fullName?.firstName ?? "",
|
|
187
|
+
lastName: a.fullName?.lastName ?? "",
|
|
188
|
+
company: a.company ?? "",
|
|
189
|
+
addressLine1: streetLineOf(a),
|
|
190
|
+
addressLine2: a.addressLine2 ?? "",
|
|
191
|
+
city: a.city ?? "",
|
|
192
|
+
zipCode: a.zipCode ?? "",
|
|
193
|
+
phone: a.phoneNumber ?? "",
|
|
194
|
+
countryCode: country?.[0] ?? "",
|
|
195
|
+
regionKey: sub.includes("-") ? sub.slice(sub.indexOf("-") + 1) : sub,
|
|
196
|
+
setAsDefault: isDefault,
|
|
197
|
+
hideDefaultSwitch: isDefault,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Required fields, in screen order. Returns the state with errors and a focus token. */
|
|
202
|
+
function validate(s: S): { ok: boolean; next: S } {
|
|
203
|
+
const country = countryByCode(s.countryCode);
|
|
204
|
+
const needsRegion = (country?.[6].length ?? 0) > 0;
|
|
205
|
+
const needsZip = !!country && !NO_POSTCODE.has(country[0]);
|
|
206
|
+
const errs = {
|
|
207
|
+
errFirstName: s.firstName.trim() ? "" : "Enter a first name.",
|
|
208
|
+
errLastName: s.lastName.trim() ? "" : "Enter a last name.",
|
|
209
|
+
errCountry: country ? "" : "Select a country.",
|
|
210
|
+
errAddressLine1: s.addressLine1.trim() ? "" : "Enter an address.",
|
|
211
|
+
errCity: s.city.trim() ? "" : `Enter a ${(country?.[4] || "city").toLowerCase()}.`,
|
|
212
|
+
errRegion: !needsRegion || s.regionKey ? "" : `Select a ${(country?.[3] || "state").toLowerCase()}.`,
|
|
213
|
+
errZipCode: !needsZip || s.zipCode.trim() ? "" : `Enter a ${(country?.[5] || "zip / postal code").toLowerCase()}.`,
|
|
214
|
+
};
|
|
215
|
+
const ok = Object.values(errs).every((e) => !e);
|
|
216
|
+
const token = String(Date.now());
|
|
217
|
+
const focus = { focusFirstName: "", focusLastName: "", focusAddressLine1: "", focusCity: "", focusZipCode: "" };
|
|
218
|
+
if (errs.errFirstName) focus.focusFirstName = token;
|
|
219
|
+
else if (errs.errLastName) focus.focusLastName = token;
|
|
220
|
+
else if (errs.errAddressLine1) focus.focusAddressLine1 = token;
|
|
221
|
+
else if (errs.errCity) focus.focusCity = token;
|
|
222
|
+
else if (errs.errZipCode && !errs.errCountry && !errs.errRegion) focus.focusZipCode = token;
|
|
223
|
+
return { ok, next: derive({ ...s, ...errs, ...focus, message: ok ? "" : "Check the highlighted fields." }) };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function toWix(s: S): WixAddress {
|
|
227
|
+
const t = (v: string) => (v.trim() ? v.trim() : null);
|
|
228
|
+
return {
|
|
229
|
+
...(s.editId ? { id: s.editId } : {}),
|
|
230
|
+
fullName: { firstName: s.firstName.trim(), lastName: s.lastName.trim() },
|
|
231
|
+
country: s.countryCode || null,
|
|
232
|
+
subdivision: s.regionKey || null,
|
|
233
|
+
city: t(s.city),
|
|
234
|
+
zipCode: t(s.zipCode),
|
|
235
|
+
phoneNumber: t(s.phone),
|
|
236
|
+
company: t(s.company),
|
|
237
|
+
addressLine1: t(s.addressLine1),
|
|
238
|
+
addressLine2: t(s.addressLine2),
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** The update mask: every form field, so a cleared field is cleared in Wix too. */
|
|
243
|
+
const UPDATE_MASK = ["fullName.firstName", "fullName.lastName", "country", "subdivision", "city", "zipCode",
|
|
244
|
+
"phoneNumber", "company", "addressLine1", "addressLine2"];
|
|
245
|
+
|
|
246
|
+
function setField(field: Field, errKey?: keyof typeof NO_ERRORS) {
|
|
247
|
+
return (s: S, arg?: unknown): S => derive({ ...s, [field]: textOf(arg), formDirty: true, ...(errKey ? { [errKey]: "" } : {}) } as S);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async function loadForm(s: S): Promise<S> {
|
|
251
|
+
if (!(await signedInEmail())) return derive({ ...s, status: "signedOut" });
|
|
252
|
+
const editId = inputId();
|
|
253
|
+
if (!editId) {
|
|
254
|
+
const guess = s.countryCode ? undefined : deviceCountry();
|
|
255
|
+
return derive({ ...s, status: "ready", editId: "", ...(guess ? { countryCode: guess[0] } : {}) });
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
const { address, isDefault } = await getAddress(editId);
|
|
259
|
+
if (!address) return derive({ ...s, status: "error", errorKind: "server", editId });
|
|
260
|
+
return fromAddress({ ...s, editId }, address, isDefault);
|
|
261
|
+
} catch (e) {
|
|
262
|
+
return derive({ ...s, status: "error", errorKind: errorKindOf(e), editId });
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Save runs in two steps on one host `_poll` (a worker has no timer), like Add to bag on
|
|
267
|
+
// the product screen: the tap sets `saving` so the button shows it, and arms the poll with
|
|
268
|
+
// `immediate`; the tick runs the Wix write. The latch lives at module scope, so a second
|
|
269
|
+
// tap or a restored state never writes twice.
|
|
270
|
+
const SAVE_POLL = { id: "himi-address-form-save", intervalMs: 1000, action: "bareFashionAddressForm.tick" };
|
|
271
|
+
let pendingSave = false;
|
|
272
|
+
|
|
273
|
+
async function commitSave(s: S): Promise<S> {
|
|
274
|
+
try {
|
|
275
|
+
if (s.editId) await updateAddress(toWix(s), UPDATE_MASK, s.setAsDefault && !s.hideDefaultSwitch);
|
|
276
|
+
else await createAddress(toWix(s), s.setAsDefault);
|
|
277
|
+
await bumpAddressBook();
|
|
278
|
+
return navigate(derive({ ...s, saving: false }), { presentation: "back" });
|
|
279
|
+
} catch {
|
|
280
|
+
return derive({ ...s, saving: false, message: "We couldn't save this address. Check your connection and try again." });
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const svc = defineService<S, {
|
|
285
|
+
load: (s: S, arg?: unknown) => Promise<S>;
|
|
286
|
+
refresh: (s: S, arg?: unknown) => Promise<S> | S;
|
|
287
|
+
retry: (s: S) => Promise<S>;
|
|
288
|
+
setFirstName: (s: S, arg?: unknown) => S;
|
|
289
|
+
setLastName: (s: S, arg?: unknown) => S;
|
|
290
|
+
setCompany: (s: S, arg?: unknown) => S;
|
|
291
|
+
setAddressLine1: (s: S, arg?: unknown) => S;
|
|
292
|
+
setAddressLine2: (s: S, arg?: unknown) => S;
|
|
293
|
+
setCity: (s: S, arg?: unknown) => S;
|
|
294
|
+
setZipCode: (s: S, arg?: unknown) => S;
|
|
295
|
+
setPhone: (s: S, arg?: unknown) => S;
|
|
296
|
+
setDefault: (s: S, arg?: unknown) => S;
|
|
297
|
+
openCountry: (s: S) => S;
|
|
298
|
+
filterCountry: (s: S, arg?: unknown) => S;
|
|
299
|
+
pickCountry: (s: S, arg?: unknown) => S;
|
|
300
|
+
closeCountry: (s: S) => S;
|
|
301
|
+
openRegion: (s: S) => S;
|
|
302
|
+
pickRegion: (s: S, arg?: unknown) => S;
|
|
303
|
+
closeRegion: (s: S) => S;
|
|
304
|
+
save: (s: S) => S | undefined;
|
|
305
|
+
tick: (s: S) => Promise<S | undefined>;
|
|
306
|
+
cancel: (s: S) => S;
|
|
307
|
+
signIn: (s: S) => S;
|
|
308
|
+
}>("bareFashionAddressForm", {
|
|
309
|
+
state: blank(),
|
|
310
|
+
actions: {
|
|
311
|
+
// The screen passes the app's language tag (`locale`, from config.ts): a worker has no host
|
|
312
|
+
// locale to read, and the first country guess comes from its region ("en-IE" → Ireland).
|
|
313
|
+
load: (s, arg) => { takeLocale(arg); return loadForm(s); },
|
|
314
|
+
// Do not replace edits that the user has not saved.
|
|
315
|
+
refresh: (s, arg) => {
|
|
316
|
+
takeLocale(arg);
|
|
317
|
+
return s.formDirty ? s : loadForm(derive({ ...s, status: "loading" }));
|
|
318
|
+
},
|
|
319
|
+
retry: (s) => loadForm(derive({ ...s, status: "loading" })),
|
|
320
|
+
setFirstName: setField("firstName", "errFirstName"),
|
|
321
|
+
setLastName: setField("lastName", "errLastName"),
|
|
322
|
+
setCompany: setField("company"),
|
|
323
|
+
setAddressLine1: setField("addressLine1", "errAddressLine1"),
|
|
324
|
+
setAddressLine2: setField("addressLine2"),
|
|
325
|
+
setCity: setField("city", "errCity"),
|
|
326
|
+
setZipCode: setField("zipCode", "errZipCode"),
|
|
327
|
+
setPhone: setField("phone"),
|
|
328
|
+
setDefault: (s, arg) => derive({ ...s, setAsDefault: boolOf(arg), formDirty: true }),
|
|
329
|
+
openCountry: (s) => derive({ ...s, countrySheetOpen: true, countryQuery: "", regionSheetOpen: false }),
|
|
330
|
+
filterCountry: (s, arg) => derive({ ...s, countryQuery: textOf(arg) }),
|
|
331
|
+
pickCountry: (s, arg) => {
|
|
332
|
+
const country = countryByCode(idOf(arg));
|
|
333
|
+
if (!country) return derive({ ...s, countrySheetOpen: false });
|
|
334
|
+
// A region belongs to one country: a new country clears it.
|
|
335
|
+
const regionKey = country[0] === s.countryCode ? s.regionKey : "";
|
|
336
|
+
return derive({ ...s, countryCode: country[0], regionKey, countrySheetOpen: false, countryQuery: "", formDirty: true,
|
|
337
|
+
errCountry: "", errRegion: "", errZipCode: "" });
|
|
338
|
+
},
|
|
339
|
+
closeCountry: (s) => derive({ ...s, countrySheetOpen: false, countryQuery: "" }),
|
|
340
|
+
openRegion: (s) => derive({ ...s, regionSheetOpen: !!countryByCode(s.countryCode)?.[6].length, countrySheetOpen: false }),
|
|
341
|
+
pickRegion: (s, arg) => {
|
|
342
|
+
const key = idOf(arg);
|
|
343
|
+
const known = countryByCode(s.countryCode)?.[6].some(([k]) => k === key);
|
|
344
|
+
return derive({ ...s, regionKey: known ? key : s.regionKey, regionSheetOpen: false, formDirty: known ? true : s.formDirty, errRegion: known ? "" : s.errRegion });
|
|
345
|
+
},
|
|
346
|
+
closeRegion: (s) => derive({ ...s, regionSheetOpen: false }),
|
|
347
|
+
save: (s) => {
|
|
348
|
+
if (s.saving) return undefined;
|
|
349
|
+
const { ok, next } = validate(s);
|
|
350
|
+
if (!ok) return next;
|
|
351
|
+
pendingSave = true;
|
|
352
|
+
return { ...derive({ ...next, saving: true }), _poll: { ...SAVE_POLL, immediate: true } } as S;
|
|
353
|
+
},
|
|
354
|
+
tick: async (s) => {
|
|
355
|
+
if (pendingSave) {
|
|
356
|
+
pendingSave = false;
|
|
357
|
+
return commitSave(s);
|
|
358
|
+
}
|
|
359
|
+
// A busy button with no write behind it (a torn-down worker) must not stick.
|
|
360
|
+
return s.saving ? derive({ ...s, saving: false }) : undefined;
|
|
361
|
+
},
|
|
362
|
+
cancel: (s) => navigate(s, { presentation: "back" }),
|
|
363
|
+
signIn: (s) => navigate(s, { screenId: "himi_sign_in", args: { mode: "signin", returnScreenId: "himi_addresses" } }),
|
|
364
|
+
},
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
export { svc };
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// Tier-5 bundle: himi-store-addresses — My addresses, the member's Wix address book.
|
|
2
|
+
//
|
|
3
|
+
// Same jobs as the site's My Addresses page: list the saved addresses (the default first,
|
|
4
|
+
// with a Default badge), add one, edit one, remove one, and set the default. The add and
|
|
5
|
+
// edit form is its own screen (himi_address_form, bundle himi-store-address-form), because
|
|
6
|
+
// a screen cannot bind to another screen's service. After a save the form bumps an
|
|
7
|
+
// on-device row; a `_poll` here reads that row and reloads the list when it changes.
|
|
8
|
+
import { defineService, navigate } from "@himalaya/state";
|
|
9
|
+
import { signedInEmail } from "../_shared/himi-account.js";
|
|
10
|
+
import {
|
|
11
|
+
listAddresses, deleteAddress, setDefaultAddress, readAddressBookRev,
|
|
12
|
+
fullNameOf, streetLineOf, cityLineOf, countryNameOf, type WixAddress,
|
|
13
|
+
} from "../_shared/bare-fashion-address-book.js";
|
|
14
|
+
import { errorFlags, errorKindOf, type ErrorKind } from "../_shared/bare-fashion-load-error.js";
|
|
15
|
+
|
|
16
|
+
const BOOK_POLL = { id: "himi-addresses-book", intervalMs: 1000, action: "bareFashionAddresses.sync" };
|
|
17
|
+
|
|
18
|
+
// Remove and Set as default run in two steps on the same `_poll`, like Add to bag on the
|
|
19
|
+
// product screen: the tap paints the busy state and arms the poll with `immediate`; the
|
|
20
|
+
// next tick runs the Wix write. The latch lives at module scope, so a second tap or a
|
|
21
|
+
// restored state never writes twice.
|
|
22
|
+
let pending: { kind: "remove" | "default"; id: string } | null = null;
|
|
23
|
+
|
|
24
|
+
interface Row {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
company: string;
|
|
28
|
+
street: string;
|
|
29
|
+
street2: string;
|
|
30
|
+
cityLine: string;
|
|
31
|
+
country: string;
|
|
32
|
+
phone: string;
|
|
33
|
+
isDefault: boolean;
|
|
34
|
+
/** Hides the Default badge. */
|
|
35
|
+
notDefault: boolean;
|
|
36
|
+
/** Hides Set as default on the default address. */
|
|
37
|
+
hideSetDefault: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface S {
|
|
41
|
+
status: "loading" | "ready" | "error" | "signedOut";
|
|
42
|
+
rows: Row[];
|
|
43
|
+
rev: string;
|
|
44
|
+
/** One-line result of the last change ("Address removed."), or an error. */
|
|
45
|
+
message: string;
|
|
46
|
+
/** Remove confirmation sheet. */
|
|
47
|
+
confirmId: string;
|
|
48
|
+
confirmOpen: boolean;
|
|
49
|
+
confirmText: string;
|
|
50
|
+
/** A write is in flight: the row buttons and the sheet's Remove are disabled. */
|
|
51
|
+
busy: boolean;
|
|
52
|
+
notBusy: boolean;
|
|
53
|
+
removeLabel: string;
|
|
54
|
+
/** Visibility flags for the four states. */
|
|
55
|
+
hideLoading: boolean;
|
|
56
|
+
hideList: boolean;
|
|
57
|
+
hideEmpty: boolean;
|
|
58
|
+
hideError: boolean;
|
|
59
|
+
/** Why the last load failed: the error state shows the offline or the server variant. */
|
|
60
|
+
errorKind?: ErrorKind;
|
|
61
|
+
hideOfflineError?: boolean;
|
|
62
|
+
hideServerError?: boolean;
|
|
63
|
+
hideSignedOut: boolean;
|
|
64
|
+
hideAdd: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function toRow(a: WixAddress, defaultId: string): Row {
|
|
68
|
+
const isDefault = a.id === defaultId;
|
|
69
|
+
return {
|
|
70
|
+
id: String(a.id),
|
|
71
|
+
name: fullNameOf(a),
|
|
72
|
+
company: (a.company ?? "").trim(),
|
|
73
|
+
street: streetLineOf(a),
|
|
74
|
+
street2: (a.addressLine2 ?? "").trim(),
|
|
75
|
+
cityLine: cityLineOf(a),
|
|
76
|
+
country: countryNameOf(a),
|
|
77
|
+
phone: (a.phoneNumber ?? "").trim(),
|
|
78
|
+
isDefault,
|
|
79
|
+
notDefault: !isDefault,
|
|
80
|
+
hideSetDefault: isDefault,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function derive(s: S): S {
|
|
85
|
+
const has = s.rows.length > 0;
|
|
86
|
+
return {
|
|
87
|
+
...s,
|
|
88
|
+
confirmOpen: !!s.confirmId,
|
|
89
|
+
notBusy: !s.busy,
|
|
90
|
+
removeLabel: s.busy && pending?.kind !== "default" && !!s.confirmId ? "REMOVING…" : "REMOVE ADDRESS",
|
|
91
|
+
hideLoading: s.status !== "loading",
|
|
92
|
+
hideList: s.status !== "ready" || !has,
|
|
93
|
+
hideEmpty: s.status !== "ready" || has,
|
|
94
|
+
hideError: s.status !== "error",
|
|
95
|
+
...errorFlags(s.status, s.errorKind),
|
|
96
|
+
hideSignedOut: s.status !== "signedOut",
|
|
97
|
+
hideAdd: s.status !== "ready" || !has,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function fetchRows(s: S, message = ""): Promise<S> {
|
|
102
|
+
if (!(await signedInEmail())) return derive({ ...s, status: "signedOut", rows: [], message: "" });
|
|
103
|
+
try {
|
|
104
|
+
const { addresses, defaultAddressId } = await listAddresses();
|
|
105
|
+
const rows = addresses.map((a) => toRow(a, defaultAddressId));
|
|
106
|
+
// The site lists the default address first.
|
|
107
|
+
rows.sort((a, b) => Number(b.isDefault) - Number(a.isDefault));
|
|
108
|
+
return derive({ ...s, status: "ready", rows, message });
|
|
109
|
+
} catch (e) {
|
|
110
|
+
return derive({ ...s, status: "error", errorKind: errorKindOf(e), message: "" });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function commitRemove(s: S, id: string): Promise<S> {
|
|
115
|
+
try {
|
|
116
|
+
await deleteAddress(id);
|
|
117
|
+
return fetchRows(derive({ ...s, confirmId: "", busy: false }), "Address removed.");
|
|
118
|
+
} catch {
|
|
119
|
+
return derive({ ...s, confirmId: "", busy: false, message: "We couldn't remove this address. Try again." });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function commitDefault(s: S, id: string): Promise<S> {
|
|
124
|
+
try {
|
|
125
|
+
await setDefaultAddress(id);
|
|
126
|
+
return fetchRows(derive({ ...s, busy: false }), "Default address updated.");
|
|
127
|
+
} catch {
|
|
128
|
+
return derive({ ...s, busy: false, message: "We couldn't change your default address. Try again." });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function idOf(arg: unknown): string {
|
|
133
|
+
const id = arg && typeof arg === "object" ? (arg as { id?: unknown }).id : arg;
|
|
134
|
+
return typeof id === "string" ? id : "";
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const svc = defineService<S, {
|
|
138
|
+
load: (s: S) => Promise<S>;
|
|
139
|
+
retry: (s: S) => Promise<S>;
|
|
140
|
+
sync: (s: S) => Promise<S | undefined>;
|
|
141
|
+
add: (s: S) => S;
|
|
142
|
+
edit: (s: S, arg?: unknown) => S;
|
|
143
|
+
askRemove: (s: S, arg?: unknown) => S;
|
|
144
|
+
cancelRemove: (s: S) => S;
|
|
145
|
+
confirmRemove: (s: S) => S | undefined;
|
|
146
|
+
setDefault: (s: S, arg?: unknown) => S | undefined;
|
|
147
|
+
signIn: (s: S) => S;
|
|
148
|
+
}>("bareFashionAddresses", {
|
|
149
|
+
state: derive({
|
|
150
|
+
status: "loading", rows: [], rev: "", message: "",
|
|
151
|
+
confirmId: "", confirmOpen: false, confirmText: "", busy: false, notBusy: true, removeLabel: "REMOVE ADDRESS",
|
|
152
|
+
hideLoading: false, hideList: true, hideEmpty: true, hideError: true, hideSignedOut: true, hideAdd: true,
|
|
153
|
+
}),
|
|
154
|
+
actions: {
|
|
155
|
+
load: async (s) => {
|
|
156
|
+
const rev = await readAddressBookRev();
|
|
157
|
+
return { ...(await fetchRows({ ...s, rev })), _poll: { ...BOOK_POLL } } as S;
|
|
158
|
+
},
|
|
159
|
+
retry: (s) => fetchRows(derive({ ...s, status: "loading" })),
|
|
160
|
+
// Runs a queued write first. Idle ticks return undefined. A save on the form screen
|
|
161
|
+
// changes the address-book row, so the list reloads.
|
|
162
|
+
sync: async (s) => {
|
|
163
|
+
if (pending) {
|
|
164
|
+
const op = pending;
|
|
165
|
+
pending = null;
|
|
166
|
+
return op.kind === "remove" ? commitRemove(s, op.id) : commitDefault(s, op.id);
|
|
167
|
+
}
|
|
168
|
+
if (s.busy) return derive({ ...s, busy: false });
|
|
169
|
+
const rev = await readAddressBookRev();
|
|
170
|
+
if (rev === s.rev) return undefined;
|
|
171
|
+
return fetchRows({ ...s, rev }, "Address saved.");
|
|
172
|
+
},
|
|
173
|
+
add: (s) => navigate(derive({ ...s, message: "" }), { screenId: "himi_address_form" }),
|
|
174
|
+
edit: (s, arg) => {
|
|
175
|
+
const id = idOf(arg);
|
|
176
|
+
return id && !s.busy ? navigate(derive({ ...s, message: "" }), { screenId: "himi_address_form", args: { id } }) : s;
|
|
177
|
+
},
|
|
178
|
+
askRemove: (s, arg) => {
|
|
179
|
+
const row = s.rows.find((r) => r.id === idOf(arg));
|
|
180
|
+
if (!row || s.busy) return s;
|
|
181
|
+
const label = [row.street, row.cityLine].filter(Boolean).join(", ");
|
|
182
|
+
return derive({ ...s, message: "", confirmId: row.id,
|
|
183
|
+
confirmText: `${label || "This address"} will no longer be saved for faster checkout.` });
|
|
184
|
+
},
|
|
185
|
+
cancelRemove: (s) => (s.busy ? s : derive({ ...s, confirmId: "" })),
|
|
186
|
+
confirmRemove: (s) => {
|
|
187
|
+
if (!s.confirmId || s.busy) return undefined;
|
|
188
|
+
pending = { kind: "remove", id: s.confirmId };
|
|
189
|
+
return { ...derive({ ...s, busy: true }), _poll: { ...BOOK_POLL, immediate: true } } as S;
|
|
190
|
+
},
|
|
191
|
+
setDefault: (s, arg) => {
|
|
192
|
+
const id = idOf(arg);
|
|
193
|
+
if (!id || s.busy) return undefined;
|
|
194
|
+
pending = { kind: "default", id };
|
|
195
|
+
return { ...derive({ ...s, busy: true, message: "" }), _poll: { ...BOOK_POLL, immediate: true } } as S;
|
|
196
|
+
},
|
|
197
|
+
signIn: (s) => navigate(s, { screenId: "himi_sign_in", args: { mode: "signin", returnScreenId: "himi_addresses" } }),
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
svc.load();
|
|
202
|
+
export { svc };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { defineService } from "@himalaya/state";
|
|
2
|
+
import { dispatch } from "@himalaya/dispatch";
|
|
3
|
+
import { DEFAULT_THEME, THEME_IDS, THEME_KEY, isThemeId, type ThemeId } from "../_shared/himi-layouts.js";
|
|
4
|
+
|
|
5
|
+
// A theme choice applies at once through the host. Worker storage keeps the radio
|
|
6
|
+
// selection visible on older binaries that do not support theme host actions.
|
|
7
|
+
|
|
8
|
+
interface State {
|
|
9
|
+
theme: string;
|
|
10
|
+
/** Shown under the choices when this app version cannot apply a theme ("" otherwise). */
|
|
11
|
+
errorText: string;
|
|
12
|
+
[flag: `selected_${string}`]: boolean | string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface StorageLike {
|
|
16
|
+
getItem(k: string): string | null;
|
|
17
|
+
setItem(k: string, v: string): void;
|
|
18
|
+
}
|
|
19
|
+
function storage(): StorageLike | undefined {
|
|
20
|
+
const host = globalThis as { himalaya?: { storage?: StorageLike }; localStorage?: StorageLike };
|
|
21
|
+
return host.himalaya?.storage ?? host.localStorage;
|
|
22
|
+
}
|
|
23
|
+
function storedTheme(): ThemeId {
|
|
24
|
+
try {
|
|
25
|
+
const theme = storage()?.getItem(THEME_KEY) ?? null;
|
|
26
|
+
return isThemeId(theme) ? theme : DEFAULT_THEME;
|
|
27
|
+
} catch { return DEFAULT_THEME; }
|
|
28
|
+
}
|
|
29
|
+
function remember(theme: ThemeId): void {
|
|
30
|
+
try { storage()?.setItem(THEME_KEY, theme); } catch { /* best-effort */ }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const NOT_APPLIED = "This version of the app cannot change its colors yet. Your choice is saved.";
|
|
34
|
+
function build(theme: ThemeId, errorText = ""): State {
|
|
35
|
+
const flags: Record<string, boolean> = {};
|
|
36
|
+
for (const id of THEME_IDS) flags[`selected_${id}`] = id === theme;
|
|
37
|
+
return { ...flags, theme, errorText };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let choiceRevision = 0;
|
|
41
|
+
|
|
42
|
+
const svc = defineService<State, {
|
|
43
|
+
sync: (state: State, arg?: unknown) => Promise<State>;
|
|
44
|
+
selectTheme: (state: State, arg?: unknown) => Promise<State>;
|
|
45
|
+
}>("bareFashionAppearance", {
|
|
46
|
+
state: build(storedTheme()),
|
|
47
|
+
actions: {
|
|
48
|
+
sync: async () => {
|
|
49
|
+
const choiceAtStart = choiceRevision;
|
|
50
|
+
try {
|
|
51
|
+
const payload = await dispatch("theme.get") as { scheme?: unknown } | null;
|
|
52
|
+
if (choiceAtStart !== choiceRevision) return build(storedTheme());
|
|
53
|
+
if (isThemeId(payload?.scheme)) {
|
|
54
|
+
remember(payload.scheme);
|
|
55
|
+
return build(payload.scheme);
|
|
56
|
+
}
|
|
57
|
+
} catch { /* older hosts keep the mirrored choice */ }
|
|
58
|
+
return build(storedTheme());
|
|
59
|
+
},
|
|
60
|
+
selectTheme: async (_state, arg) => {
|
|
61
|
+
const id = typeof arg === "string" ? arg : (arg as Record<string, unknown> | undefined)?.id;
|
|
62
|
+
if (!isThemeId(id)) return _state;
|
|
63
|
+
const revision = ++choiceRevision;
|
|
64
|
+
remember(id);
|
|
65
|
+
// An older host keeps the choice but cannot change the app colors: say so.
|
|
66
|
+
let errorText = "";
|
|
67
|
+
try { await dispatch("theme.set", { scheme: id }); } catch { errorText = NOT_APPLIED; }
|
|
68
|
+
return revision === choiceRevision ? build(id, errorText) : build(storedTheme());
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export { svc };
|