@wikala/spmkt 3.0.0-beta.2 → 4.0.0-alpha.2
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/README.md +88 -0
- package/dist/analytics/ga4.d.ts +44 -0
- package/dist/analytics/ga4.js +47 -0
- package/dist/analytics/ga4.js.map +1 -0
- package/dist/core/api/account.d.ts +25 -0
- package/dist/core/api/account.js +27 -0
- package/dist/core/api/account.js.map +1 -0
- package/dist/core/api/address.d.ts +15 -0
- package/dist/core/api/address.js +23 -0
- package/dist/core/api/address.js.map +1 -0
- package/dist/core/api/cart.d.ts +24 -0
- package/dist/core/api/cart.js +20 -0
- package/dist/core/api/cart.js.map +1 -0
- package/dist/core/api/checkout.d.ts +83 -0
- package/dist/core/api/checkout.js +68 -0
- package/dist/core/api/checkout.js.map +1 -0
- package/dist/core/api/index.d.ts +12 -0
- package/dist/core/api/location.d.ts +8 -0
- package/dist/core/api/location.js +16 -0
- package/dist/core/api/location.js.map +1 -0
- package/dist/core/api/product.d.ts +5 -0
- package/dist/core/api/product.js +7 -0
- package/dist/core/api/product.js.map +1 -0
- package/dist/core/api/questions.d.ts +3 -0
- package/dist/core/api/questions.js +9 -0
- package/dist/core/api/questions.js.map +1 -0
- package/dist/core/api/reviews.d.ts +17 -0
- package/dist/core/api/reviews.js +30 -0
- package/dist/core/api/reviews.js.map +1 -0
- package/dist/core/api/search.d.ts +3 -0
- package/dist/core/api/search.js +8 -0
- package/dist/core/api/search.js.map +1 -0
- package/dist/core/config.d.ts +16 -0
- package/dist/core/config.js +33 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/cookies.d.ts +5 -0
- package/dist/core/cookies.js +29 -0
- package/dist/core/cookies.js.map +1 -0
- package/dist/core/errors.d.ts +27 -0
- package/dist/core/errors.js +42 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/events.d.ts +138 -0
- package/dist/core/events.js +13 -0
- package/dist/core/events.js.map +1 -0
- package/dist/core/forms.d.ts +17 -0
- package/dist/core/forms.js +70 -0
- package/dist/core/forms.js.map +1 -0
- package/dist/core/i18n.d.ts +26 -0
- package/dist/core/i18n.js +82 -0
- package/dist/core/i18n.js.map +1 -0
- package/dist/core/index.d.ts +22 -0
- package/dist/core/index.js +160 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/money.d.ts +12 -0
- package/dist/core/money.js +35 -0
- package/dist/core/money.js.map +1 -0
- package/dist/core/page-events.d.ts +30 -0
- package/dist/core/page-events.js +110 -0
- package/dist/core/page-events.js.map +1 -0
- package/dist/core/recaptcha.d.ts +17 -0
- package/dist/core/recaptcha.js +44 -0
- package/dist/core/recaptcha.js.map +1 -0
- package/dist/core/request.d.ts +38 -0
- package/dist/core/request.js +170 -0
- package/dist/core/request.js.map +1 -0
- package/dist/core/session.d.ts +7 -0
- package/dist/core/session.js +16 -0
- package/dist/core/session.js.map +1 -0
- package/dist/core/state.d.ts +29 -0
- package/dist/core/state.js +192 -0
- package/dist/core/state.js.map +1 -0
- package/dist/core/stores/cart.d.ts +44 -0
- package/dist/core/stores/cart.js +94 -0
- package/dist/core/stores/cart.js.map +1 -0
- package/dist/core/stores/checkout-draft.d.ts +58 -0
- package/dist/core/stores/checkout-draft.js +67 -0
- package/dist/core/stores/checkout-draft.js.map +1 -0
- package/dist/core/stores/checkout.d.ts +83 -0
- package/dist/core/stores/checkout.js +294 -0
- package/dist/core/stores/checkout.js.map +1 -0
- package/dist/core/stores/compare.d.ts +17 -0
- package/dist/core/stores/compare.js +78 -0
- package/dist/core/stores/compare.js.map +1 -0
- package/dist/core/stores/customer.d.ts +2 -0
- package/dist/core/stores/customer.js +13 -0
- package/dist/core/stores/customer.js.map +1 -0
- package/dist/core/stores/index.d.ts +9 -0
- package/dist/core/stores/location.d.ts +13 -0
- package/dist/core/stores/location.js +32 -0
- package/dist/core/stores/location.js.map +1 -0
- package/dist/core/types.d.ts +273 -0
- package/dist/elements/account-form/account-form.d.ts +33 -0
- package/dist/elements/account-form/account-form.js +42 -0
- package/dist/elements/account-form/account-form.js.map +1 -0
- package/dist/elements/account-form/index.d.ts +3 -0
- package/dist/elements/account-form/index.js +6 -0
- package/dist/elements/account-form/index.js.map +1 -0
- package/dist/elements/add-to-cart/add-to-cart.d.ts +42 -0
- package/dist/elements/add-to-cart/add-to-cart.js +113 -0
- package/dist/elements/add-to-cart/add-to-cart.js.map +1 -0
- package/dist/elements/add-to-cart/index.d.ts +3 -0
- package/dist/elements/add-to-cart/index.js +6 -0
- package/dist/elements/add-to-cart/index.js.map +1 -0
- package/dist/elements/address-autocomplete/address-autocomplete.d.ts +65 -0
- package/dist/elements/address-autocomplete/address-autocomplete.js +124 -0
- package/dist/elements/address-autocomplete/address-autocomplete.js.map +1 -0
- package/dist/elements/address-autocomplete/index.d.ts +3 -0
- package/dist/elements/address-autocomplete/index.js +7 -0
- package/dist/elements/address-autocomplete/index.js.map +1 -0
- package/dist/elements/address-book/address-book.d.ts +66 -0
- package/dist/elements/address-book/address-book.js +248 -0
- package/dist/elements/address-book/address-book.js.map +1 -0
- package/dist/elements/address-book/index.d.ts +3 -0
- package/dist/elements/address-book/index.js +6 -0
- package/dist/elements/address-book/index.js.map +1 -0
- package/dist/elements/age-check/age-check.d.ts +89 -0
- package/dist/elements/age-check/age-check.js +195 -0
- package/dist/elements/age-check/age-check.js.map +1 -0
- package/dist/elements/age-check/index.d.ts +3 -0
- package/dist/elements/age-check/index.js +8 -0
- package/dist/elements/age-check/index.js.map +1 -0
- package/dist/elements/age-gate/age-gate.d.ts +21 -0
- package/dist/elements/age-gate/age-gate.js +24 -0
- package/dist/elements/age-gate/age-gate.js.map +1 -0
- package/dist/elements/age-gate/index.d.ts +3 -0
- package/dist/elements/age-gate/index.js +7 -0
- package/dist/elements/age-gate/index.js.map +1 -0
- package/dist/elements/back-in-stock/back-in-stock.d.ts +61 -0
- package/dist/elements/back-in-stock/back-in-stock.js +101 -0
- package/dist/elements/back-in-stock/back-in-stock.js.map +1 -0
- package/dist/elements/back-in-stock/index.d.ts +3 -0
- package/dist/elements/back-in-stock/index.js +6 -0
- package/dist/elements/back-in-stock/index.js.map +1 -0
- package/dist/elements/carousel/carousel.d.ts +51 -0
- package/dist/elements/carousel/carousel.js +133 -0
- package/dist/elements/carousel/carousel.js.map +1 -0
- package/dist/elements/carousel/index.d.ts +3 -0
- package/dist/elements/carousel/index.js +6 -0
- package/dist/elements/carousel/index.js.map +1 -0
- package/dist/elements/cart/cart.d.ts +50 -0
- package/dist/elements/cart/cart.js +268 -0
- package/dist/elements/cart/cart.js.map +1 -0
- package/dist/elements/cart/index.d.ts +3 -0
- package/dist/elements/cart/index.js +6 -0
- package/dist/elements/cart/index.js.map +1 -0
- package/dist/elements/cart-count/cart-count.d.ts +16 -0
- package/dist/elements/cart-count/cart-count.js +32 -0
- package/dist/elements/cart-count/cart-count.js.map +1 -0
- package/dist/elements/cart-count/index.d.ts +3 -0
- package/dist/elements/cart-count/index.js +6 -0
- package/dist/elements/cart-count/index.js.map +1 -0
- package/dist/elements/checkout/checkout.d.ts +58 -0
- package/dist/elements/checkout/checkout.js +177 -0
- package/dist/elements/checkout/checkout.js.map +1 -0
- package/dist/elements/checkout/index.d.ts +3 -0
- package/dist/elements/checkout/index.js +6 -0
- package/dist/elements/checkout/index.js.map +1 -0
- package/dist/elements/checkout-address/checkout-address.d.ts +41 -0
- package/dist/elements/checkout-address/checkout-address.js +105 -0
- package/dist/elements/checkout-address/checkout-address.js.map +1 -0
- package/dist/elements/checkout-address/index.d.ts +3 -0
- package/dist/elements/checkout-address/index.js +6 -0
- package/dist/elements/checkout-address/index.js.map +1 -0
- package/dist/elements/checkout-delivery/checkout-delivery.d.ts +68 -0
- package/dist/elements/checkout-delivery/checkout-delivery.js +286 -0
- package/dist/elements/checkout-delivery/checkout-delivery.js.map +1 -0
- package/dist/elements/checkout-delivery/index.d.ts +3 -0
- package/dist/elements/checkout-delivery/index.js +6 -0
- package/dist/elements/checkout-delivery/index.js.map +1 -0
- package/dist/elements/checkout-identity/checkout-identity.d.ts +34 -0
- package/dist/elements/checkout-identity/checkout-identity.js +49 -0
- package/dist/elements/checkout-identity/checkout-identity.js.map +1 -0
- package/dist/elements/checkout-identity/index.d.ts +3 -0
- package/dist/elements/checkout-identity/index.js +6 -0
- package/dist/elements/checkout-identity/index.js.map +1 -0
- package/dist/elements/checkout-payment/checkout-payment.d.ts +67 -0
- package/dist/elements/checkout-payment/checkout-payment.js +279 -0
- package/dist/elements/checkout-payment/checkout-payment.js.map +1 -0
- package/dist/elements/checkout-payment/index.d.ts +3 -0
- package/dist/elements/checkout-payment/index.js +6 -0
- package/dist/elements/checkout-payment/index.js.map +1 -0
- package/dist/elements/collection/collection.d.ts +62 -0
- package/dist/elements/collection/collection.js +179 -0
- package/dist/elements/collection/collection.js.map +1 -0
- package/dist/elements/collection/index.d.ts +3 -0
- package/dist/elements/collection/index.js +6 -0
- package/dist/elements/collection/index.js.map +1 -0
- package/dist/elements/combobox/combobox.d.ts +54 -0
- package/dist/elements/combobox/combobox.js +178 -0
- package/dist/elements/combobox/combobox.js.map +1 -0
- package/dist/elements/combobox/index.d.ts +2 -0
- package/dist/elements/combobox/index.js +5 -0
- package/dist/elements/combobox/index.js.map +1 -0
- package/dist/elements/compare-bar/compare-bar.d.ts +21 -0
- package/dist/elements/compare-bar/compare-bar.js +34 -0
- package/dist/elements/compare-bar/compare-bar.js.map +1 -0
- package/dist/elements/compare-bar/index.d.ts +3 -0
- package/dist/elements/compare-bar/index.js +6 -0
- package/dist/elements/compare-bar/index.js.map +1 -0
- package/dist/elements/compare-remove/compare-remove.d.ts +20 -0
- package/dist/elements/compare-remove/compare-remove.js +19 -0
- package/dist/elements/compare-remove/compare-remove.js.map +1 -0
- package/dist/elements/compare-remove/index.d.ts +3 -0
- package/dist/elements/compare-remove/index.js +6 -0
- package/dist/elements/compare-remove/index.js.map +1 -0
- package/dist/elements/compare-toggle/compare-toggle.d.ts +39 -0
- package/dist/elements/compare-toggle/compare-toggle.js +53 -0
- package/dist/elements/compare-toggle/compare-toggle.js.map +1 -0
- package/dist/elements/compare-toggle/index.d.ts +3 -0
- package/dist/elements/compare-toggle/index.js +6 -0
- package/dist/elements/compare-toggle/index.js.map +1 -0
- package/dist/elements/dialog/dialog.d.ts +27 -0
- package/dist/elements/dialog/dialog.js +69 -0
- package/dist/elements/dialog/dialog.js.map +1 -0
- package/dist/elements/dialog/index.d.ts +3 -0
- package/dist/elements/dialog/index.js +6 -0
- package/dist/elements/dialog/index.js.map +1 -0
- package/dist/elements/location-picker/index.d.ts +3 -0
- package/dist/elements/location-picker/index.js +6 -0
- package/dist/elements/location-picker/index.js.map +1 -0
- package/dist/elements/location-picker/location-picker.d.ts +28 -0
- package/dist/elements/location-picker/location-picker.js +88 -0
- package/dist/elements/location-picker/location-picker.js.map +1 -0
- package/dist/elements/mini-cart/index.d.ts +3 -0
- package/dist/elements/mini-cart/index.js +6 -0
- package/dist/elements/mini-cart/index.js.map +1 -0
- package/dist/elements/mini-cart/mini-cart.d.ts +29 -0
- package/dist/elements/mini-cart/mini-cart.js +114 -0
- package/dist/elements/mini-cart/mini-cart.js.map +1 -0
- package/dist/elements/mobile-nav/index.d.ts +3 -0
- package/dist/elements/mobile-nav/index.js +6 -0
- package/dist/elements/mobile-nav/index.js.map +1 -0
- package/dist/elements/mobile-nav/mobile-nav.d.ts +20 -0
- package/dist/elements/mobile-nav/mobile-nav.js +29 -0
- package/dist/elements/mobile-nav/mobile-nav.js.map +1 -0
- package/dist/elements/order-confirmation/index.d.ts +3 -0
- package/dist/elements/order-confirmation/index.js +7 -0
- package/dist/elements/order-confirmation/index.js.map +1 -0
- package/dist/elements/order-confirmation/order-confirmation.d.ts +35 -0
- package/dist/elements/order-confirmation/order-confirmation.js +123 -0
- package/dist/elements/order-confirmation/order-confirmation.js.map +1 -0
- package/dist/elements/product-gallery/index.d.ts +3 -0
- package/dist/elements/product-gallery/index.js +6 -0
- package/dist/elements/product-gallery/index.js.map +1 -0
- package/dist/elements/product-gallery/product-gallery.d.ts +49 -0
- package/dist/elements/product-gallery/product-gallery.js +143 -0
- package/dist/elements/product-gallery/product-gallery.js.map +1 -0
- package/dist/elements/quantity/index.d.ts +3 -0
- package/dist/elements/quantity/index.js +6 -0
- package/dist/elements/quantity/index.js.map +1 -0
- package/dist/elements/quantity/quantity.d.ts +21 -0
- package/dist/elements/quantity/quantity.js +57 -0
- package/dist/elements/quantity/quantity.js.map +1 -0
- package/dist/elements/questions/index.d.ts +3 -0
- package/dist/elements/questions/index.js +6 -0
- package/dist/elements/questions/index.js.map +1 -0
- package/dist/elements/questions/questions.d.ts +28 -0
- package/dist/elements/questions/questions.js +65 -0
- package/dist/elements/questions/questions.js.map +1 -0
- package/dist/elements/quick-view/index.d.ts +2 -0
- package/dist/elements/quick-view/index.js +6 -0
- package/dist/elements/quick-view/index.js.map +1 -0
- package/dist/elements/quick-view/quick-view.d.ts +29 -0
- package/dist/elements/quick-view/quick-view.js +76 -0
- package/dist/elements/quick-view/quick-view.js.map +1 -0
- package/dist/elements/range/index.d.ts +3 -0
- package/dist/elements/range/index.js +6 -0
- package/dist/elements/range/index.js.map +1 -0
- package/dist/elements/range/range.d.ts +24 -0
- package/dist/elements/range/range.js +37 -0
- package/dist/elements/range/range.js.map +1 -0
- package/dist/elements/related/index.d.ts +3 -0
- package/dist/elements/related/index.js +6 -0
- package/dist/elements/related/index.js.map +1 -0
- package/dist/elements/related/related.d.ts +28 -0
- package/dist/elements/related/related.js +69 -0
- package/dist/elements/related/related.js.map +1 -0
- package/dist/elements/review-form/index.d.ts +3 -0
- package/dist/elements/review-form/index.js +6 -0
- package/dist/elements/review-form/index.js.map +1 -0
- package/dist/elements/review-form/review-form.d.ts +60 -0
- package/dist/elements/review-form/review-form.js +158 -0
- package/dist/elements/review-form/review-form.js.map +1 -0
- package/dist/elements/reviews/index.d.ts +3 -0
- package/dist/elements/reviews/index.js +6 -0
- package/dist/elements/reviews/index.js.map +1 -0
- package/dist/elements/reviews/reviews.d.ts +19 -0
- package/dist/elements/reviews/reviews.js +30 -0
- package/dist/elements/reviews/reviews.js.map +1 -0
- package/dist/elements/search/index.d.ts +3 -0
- package/dist/elements/search/index.js +6 -0
- package/dist/elements/search/index.js.map +1 -0
- package/dist/elements/search/search.d.ts +20 -0
- package/dist/elements/search/search.js +53 -0
- package/dist/elements/search/search.js.map +1 -0
- package/dist/elements/shared/folding-form.d.ts +15 -0
- package/dist/elements/shared/folding-form.js +35 -0
- package/dist/elements/shared/folding-form.js.map +1 -0
- package/dist/elements/shared/google-maps.d.ts +100 -0
- package/dist/elements/shared/google-maps.js +34 -0
- package/dist/elements/shared/google-maps.js.map +1 -0
- package/dist/elements/shared/json-form.d.ts +28 -0
- package/dist/elements/shared/json-form.js +85 -0
- package/dist/elements/shared/json-form.js.map +1 -0
- package/dist/elements/shared/paged-section.d.ts +28 -0
- package/dist/elements/shared/paged-section.js +93 -0
- package/dist/elements/shared/paged-section.js.map +1 -0
- package/dist/elements/shared/phone-mask.d.ts +9 -0
- package/dist/elements/shared/phone-mask.js +38 -0
- package/dist/elements/shared/phone-mask.js.map +1 -0
- package/dist/elements/shared/select-item.d.ts +7 -0
- package/dist/elements/shared/select-item.js +19 -0
- package/dist/elements/shared/select-item.js.map +1 -0
- package/dist/elements/shared/totals.d.ts +53 -0
- package/dist/elements/shared/totals.js +82 -0
- package/dist/elements/shared/totals.js.map +1 -0
- package/dist/elements/store-availability/index.d.ts +3 -0
- package/dist/elements/store-availability/index.js +6 -0
- package/dist/elements/store-availability/index.js.map +1 -0
- package/dist/elements/store-availability/store-availability.d.ts +26 -0
- package/dist/elements/store-availability/store-availability.js +66 -0
- package/dist/elements/store-availability/store-availability.js.map +1 -0
- package/dist/elements/store-map/index.d.ts +4 -0
- package/dist/elements/store-map/index.js +8 -0
- package/dist/elements/store-map/index.js.map +1 -0
- package/dist/elements/store-map/store-map.d.ts +59 -0
- package/dist/elements/store-map/store-map.js +118 -0
- package/dist/elements/store-map/store-map.js.map +1 -0
- package/dist/elements/tabs/index.d.ts +3 -0
- package/dist/elements/tabs/index.js +6 -0
- package/dist/elements/tabs/index.js.map +1 -0
- package/dist/elements/tabs/tabs.d.ts +21 -0
- package/dist/elements/tabs/tabs.js +69 -0
- package/dist/elements/tabs/tabs.js.map +1 -0
- package/dist/elements/toaster/index.d.ts +3 -0
- package/dist/elements/toaster/index.js +7 -0
- package/dist/elements/toaster/index.js.map +1 -0
- package/dist/elements/toaster/toaster.d.ts +47 -0
- package/dist/elements/toaster/toaster.js +109 -0
- package/dist/elements/toaster/toaster.js.map +1 -0
- package/dist/elements/variant-picker/index.d.ts +3 -0
- package/dist/elements/variant-picker/index.js +6 -0
- package/dist/elements/variant-picker/index.js.map +1 -0
- package/dist/elements/variant-picker/variant-picker.d.ts +30 -0
- package/dist/elements/variant-picker/variant-picker.js +85 -0
- package/dist/elements/variant-picker/variant-picker.js.map +1 -0
- package/dist/elements/vote/index.d.ts +3 -0
- package/dist/elements/vote/index.js +6 -0
- package/dist/elements/vote/index.js.map +1 -0
- package/dist/elements/vote/vote.d.ts +33 -0
- package/dist/elements/vote/vote.js +72 -0
- package/dist/elements/vote/vote.js.map +1 -0
- package/dist/lit/forms.d.ts +8 -0
- package/dist/lit/forms.js +42 -0
- package/dist/lit/forms.js.map +1 -0
- package/dist/lit/fragments.d.ts +28 -0
- package/dist/lit/fragments.js +70 -0
- package/dist/lit/fragments.js.map +1 -0
- package/dist/lit/index.d.ts +7 -0
- package/dist/lit/index.js +21 -0
- package/dist/lit/index.js.map +1 -0
- package/dist/lit/lazy-define.d.ts +35 -0
- package/dist/lit/lazy-define.js +103 -0
- package/dist/lit/lazy-define.js.map +1 -0
- package/dist/lit/signal-controller.d.ts +19 -0
- package/dist/lit/signal-controller.js +30 -0
- package/dist/lit/signal-controller.js.map +1 -0
- package/dist/lit/spmkt-element.d.ts +40 -0
- package/dist/lit/spmkt-element.js +76 -0
- package/dist/lit/spmkt-element.js.map +1 -0
- package/dist/locales/en.json +170 -0
- package/dist/locales/sr.json +176 -0
- package/package.json +45 -55
- package/MIGRATION_GUIDE.md +0 -310
- package/api/address.js +0 -115
- package/api/affiliate.js +0 -12
- package/api/cart.js +0 -81
- package/api/compare.js +0 -47
- package/api/countries.js +0 -13
- package/api/order.js +0 -27
- package/api/product-questions.js +0 -36
- package/api/product-reviews.js +0 -35
- package/api/product.js +0 -59
- package/api/request.js +0 -118
- package/api/user.js +0 -71
- package/api.js +0 -26
- package/components/Account/AccountDashboard.vue +0 -136
- package/components/Account/AccountStore.js +0 -97
- package/components/Account/AffiliateReport.vue +0 -98
- package/components/Account/Orders/OrderDetail.vue +0 -169
- package/components/Account/Orders/Orders.vue +0 -124
- package/components/Account/Settings/AccountSettings.vue +0 -45
- package/components/Account/Settings/ChangeEmail.vue +0 -136
- package/components/Account/Settings/ChangeName.vue +0 -82
- package/components/Account/Settings/ChangePassword.vue +0 -91
- package/components/Address/Address.vue +0 -141
- package/components/Address/AddressBook.vue +0 -171
- package/components/Address/AddressSelect.vue +0 -203
- package/components/Address/Edit.vue +0 -507
- package/components/Address/PostalCode.vue +0 -67
- package/components/Address/address.schema.js +0 -84
- package/components/AgeGate.vue +0 -109
- package/components/Auth/Login.vue +0 -191
- package/components/Auth/Register.vue +0 -240
- package/components/Auth/ResetPassword.vue +0 -108
- package/components/Cart/AgeVerification/AgeChecker.vue +0 -141
- package/components/Cart/CartBadge.vue +0 -68
- package/components/Cart/CartBox.vue +0 -139
- package/components/Cart/CartItem.vue +0 -126
- package/components/Cart/CartMode.vue +0 -200
- package/components/Cart/CartPreview.vue +0 -166
- package/components/Cart/CartSummary.vue +0 -107
- package/components/Cart/Coupon.vue +0 -107
- package/components/Cart/CreditCard/Everyware.vue +0 -262
- package/components/Cart/CreditCard/ExtendedCreditCard.vue +0 -240
- package/components/Cart/CreditCard/SquarePay.vue +0 -296
- package/components/Cart/CreditCard/StandardCreditCard.vue +0 -241
- package/components/Cart/Delivery/Delivery.vue +0 -364
- package/components/Cart/Delivery/DeliveryAddress.vue +0 -195
- package/components/Cart/Delivery/DeliveryAddressGuest.vue +0 -204
- package/components/Cart/Delivery/DeliveryMethods.vue +0 -109
- package/components/Cart/Delivery/DeliveryOptions.vue +0 -171
- package/components/Cart/Delivery/DeliveryTypes.vue +0 -61
- package/components/Cart/Delivery/DeliveryWarning.vue +0 -14
- package/components/Cart/Delivery/ReservationSlots.vue +0 -88
- package/components/Cart/Delivery/reservation.schema.js +0 -35
- package/components/Cart/Disclaimer.vue +0 -56
- package/components/Cart/OrderConfirmation.vue +0 -187
- package/components/Cart/Payment/Payment.vue +0 -436
- package/components/Cart/Payment/PaymentMethods.vue +0 -59
- package/components/Cart/ReviewAndSubmit.vue +0 -159
- package/components/Cart/ShoppingCart.vue +0 -219
- package/components/Cart/Store/actions.js +0 -129
- package/components/Cart/Store/getters.js +0 -82
- package/components/Cart/Store/index.js +0 -14
- package/components/Cart/Store/mutations.js +0 -174
- package/components/Cart/Store/state.js +0 -80
- package/components/Cart/UserIdentity.vue +0 -178
- package/components/Category/CategoryFilter.vue +0 -333
- package/components/Category/CategorySort.vue +0 -77
- package/components/Category/LoadMore.vue +0 -98
- package/components/DeliverTo.vue +0 -51
- package/components/DeliveryNotice.vue +0 -123
- package/components/DobInput.vue +0 -294
- package/components/Gmaps/GmapsAutocomplete.vue +0 -166
- package/components/Gmaps/GmapsLocations.vue +0 -233
- package/components/Gmaps/GmapsSingleLocation.vue +0 -134
- package/components/MobileMenu/MobileMenu.vue +0 -224
- package/components/MobileMenu/components/MenuBurger.vue +0 -23
- package/components/MobileMenu/components/MenuPanel.vue +0 -80
- package/components/MobileMenu/components/MenuShadow.vue +0 -21
- package/components/MobileMenu/demo-data.js +0 -97
- package/components/MobileMenu/icons/LeftArrowIcon.vue +0 -25
- package/components/MobileMenu/icons/MenuIcon.vue +0 -27
- package/components/MobileMenu/icons/RightArrowIcon.vue +0 -25
- package/components/MobileMenu/index.js +0 -8
- package/components/MobileMenu/mixins/contentControl.mixin.js +0 -46
- package/components/MobileMenu/mixins/functionalityStyle.mixin.js +0 -59
- package/components/MobileMenu/mixins/panelControl.mixin.js +0 -51
- package/components/ModalContainer/ModalContainer.vue +0 -212
- package/components/ModalContainer/index.js +0 -103
- package/components/Oembed.vue +0 -46
- package/components/Product/AddToCart.vue +0 -287
- package/components/Product/BoxAddToCart.vue +0 -177
- package/components/Product/Compare.vue +0 -150
- package/components/Product/CompareBox.vue +0 -164
- package/components/Product/Lookup.vue +0 -132
- package/components/Product/Photo.vue +0 -115
- package/components/Product/Price.vue +0 -106
- package/components/Product/ProductAutocomplete.vue +0 -103
- package/components/Product/ProductBox.vue +0 -88
- package/components/Product/ProductImages.vue +0 -137
- package/components/Product/Quantity.vue +0 -126
- package/components/Product/QuickView.vue +0 -145
- package/components/Product/RelatedProducts.vue +0 -104
- package/components/Product/SKU.vue +0 -46
- package/components/Product/Variants.vue +0 -399
- package/components/Product/reviews-questions/ProductQuestions.vue +0 -319
- package/components/Product/reviews-questions/ProductReviews.vue +0 -182
- package/components/Product/reviews-questions/Review.vue +0 -126
- package/components/Product/reviews-questions/ReviewForm.vue +0 -313
- package/components/Product/reviews-questions/ReviewImages.vue +0 -229
- package/components/Product/reviews-questions/Vote.vue +0 -104
- package/components/QuantityInput.vue +0 -111
- package/components/RangeInput.vue +0 -141
- package/components/Recaptcha.vue +0 -104
- package/components/SelectShippingCountry.vue +0 -115
- package/components/TimedOffer.vue +0 -84
- package/composables/globals.js +0 -53
- package/config.js +0 -21
- package/index.js +0 -182
- package/install.js +0 -88
- package/locales/en.json +0 -288
- package/locales/sr.json +0 -288
- package/translations.js +0 -4
- package/utils/animate.css +0 -50
- package/utils/animate.js +0 -23
- package/utils/buefy.js +0 -62
- package/utils/custom-event-bus.js +0 -13
- package/utils/directives.js +0 -79
- package/utils/event-bus.js +0 -56
- package/utils/filters.js +0 -161
- package/utils/format-date.js +0 -17
- package/utils/google/gmaps.js +0 -269
- package/utils/google/google-analytics-eec.js +0 -108
- package/utils/native-dom.js +0 -27
- package/utils/objects.js +0 -19
- package/utils/parse-url-filters.js +0 -19
- package/utils/random-id.js +0 -10
- package/utils/rc-token.js +0 -24
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { nothing, html } from "lit";
|
|
2
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
3
|
+
import { SpmktElement } from "../../lit/spmkt-element.js";
|
|
4
|
+
import { warnOnce } from "../../core/config.js";
|
|
5
|
+
import { t } from "../../core/i18n.js";
|
|
6
|
+
let nextId = 1;
|
|
7
|
+
const queue = [];
|
|
8
|
+
const QUEUE_LIMIT = 10;
|
|
9
|
+
function showToast(input) {
|
|
10
|
+
const toaster = document.querySelector("spmkt-toaster");
|
|
11
|
+
if (toaster instanceof SpmktToaster && toaster.isConnected) {
|
|
12
|
+
toaster.show(input);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (!toaster) {
|
|
16
|
+
warnOnce("toaster:missing", "No <spmkt-toaster> on the page: toasts cannot be shown");
|
|
17
|
+
if (input.tone === "error") console.error(`[spmkt] ${input.message}`);
|
|
18
|
+
}
|
|
19
|
+
queue.push(input);
|
|
20
|
+
if (queue.length > QUEUE_LIMIT) queue.shift();
|
|
21
|
+
}
|
|
22
|
+
class SpmktToaster extends SpmktElement {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments);
|
|
25
|
+
this.toasts = [];
|
|
26
|
+
this.timers = /* @__PURE__ */ new Map();
|
|
27
|
+
this.held = false;
|
|
28
|
+
}
|
|
29
|
+
connectedCallback() {
|
|
30
|
+
super.connectedCallback();
|
|
31
|
+
const list = this.requirePart("list");
|
|
32
|
+
const hold = () => this.hold(true);
|
|
33
|
+
const release = () => this.hold(false);
|
|
34
|
+
this.listen(list, "pointerenter", hold);
|
|
35
|
+
this.listen(list, "pointerleave", release);
|
|
36
|
+
this.listen(list, "focusin", hold);
|
|
37
|
+
this.listen(list, "focusout", release);
|
|
38
|
+
this.onDisconnect(() => this.timers.forEach((timer) => clearTimeout(timer)));
|
|
39
|
+
queue.splice(0).forEach((input) => this.show(input));
|
|
40
|
+
}
|
|
41
|
+
show(input) {
|
|
42
|
+
const toast = {
|
|
43
|
+
id: nextId++,
|
|
44
|
+
message: input.message,
|
|
45
|
+
tone: input.tone ?? "info",
|
|
46
|
+
duration: input.duration ?? 5e3,
|
|
47
|
+
action: input.action
|
|
48
|
+
};
|
|
49
|
+
this.toasts = [...this.toasts, toast];
|
|
50
|
+
this.schedule(toast);
|
|
51
|
+
this.paint();
|
|
52
|
+
return toast;
|
|
53
|
+
}
|
|
54
|
+
dismiss(id) {
|
|
55
|
+
clearTimeout(this.timers.get(id));
|
|
56
|
+
this.timers.delete(id);
|
|
57
|
+
this.toasts = this.toasts.filter((toast) => toast.id !== id);
|
|
58
|
+
this.paint();
|
|
59
|
+
}
|
|
60
|
+
get current() {
|
|
61
|
+
return this.toasts;
|
|
62
|
+
}
|
|
63
|
+
renderToast(toast) {
|
|
64
|
+
return html`<li class="toast toast--${toast.tone}" data-state=${toast.tone}>
|
|
65
|
+
<p class="toast__message">${toast.message}</p>
|
|
66
|
+
${toast.action ? html`<a class="toast__action" href=${toast.action.href}>${toast.action.label}</a>` : nothing}
|
|
67
|
+
<button
|
|
68
|
+
type="button"
|
|
69
|
+
class="toast__close"
|
|
70
|
+
aria-label=${t("common.close")}
|
|
71
|
+
@click=${() => this.dismiss(toast.id)}
|
|
72
|
+
>
|
|
73
|
+
×
|
|
74
|
+
</button>
|
|
75
|
+
</li>`;
|
|
76
|
+
}
|
|
77
|
+
paint() {
|
|
78
|
+
this.renderPart(
|
|
79
|
+
"list",
|
|
80
|
+
html`${repeat(
|
|
81
|
+
this.toasts,
|
|
82
|
+
(toast) => toast.id,
|
|
83
|
+
(toast) => this.renderToast(toast)
|
|
84
|
+
)}`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
schedule(toast) {
|
|
88
|
+
if (toast.duration > 0 && !this.held) {
|
|
89
|
+
this.timers.set(
|
|
90
|
+
toast.id,
|
|
91
|
+
setTimeout(() => this.dismiss(toast.id), toast.duration)
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
hold(held) {
|
|
96
|
+
this.held = held;
|
|
97
|
+
if (held) {
|
|
98
|
+
this.timers.forEach((timer) => clearTimeout(timer));
|
|
99
|
+
this.timers.clear();
|
|
100
|
+
} else {
|
|
101
|
+
this.toasts.forEach((toast) => this.schedule(toast));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
SpmktToaster,
|
|
107
|
+
showToast
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=toaster.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toaster.js","sources":["../../../src/elements/toaster/toaster.ts"],"sourcesContent":["import { html, nothing } from 'lit'\nimport { repeat } from 'lit/directives/repeat.js'\nimport { SpmktElement } from '../../lit/spmkt-element'\nimport { warnOnce } from '../../core/config'\nimport { t } from '../../core/i18n'\n\nexport type ToastTone = 'info' | 'success' | 'error'\n\nexport interface ToastInput {\n message: string\n tone?: ToastTone\n /** A link shown with the message, e.g. \"Na korpu\" */\n action?: { label: string; href: string }\n /** Milliseconds; 0 keeps it until closed. Default 5000 */\n duration?: number\n}\n\nexport interface Toast extends Required<Pick<ToastInput, 'message' | 'tone' | 'duration'>> {\n id: number\n action?: ToastInput['action']\n}\n\n/**\n * Parts of <spmkt-toaster>:\n * - list (required, element-owned): an empty list; give it aria-live=\"polite\" (and role=\"status\") in Blade\n */\nexport interface ToasterParts {\n list: HTMLElement\n}\n\nlet nextId = 1\nconst queue: ToastInput[] = []\n/** Toasts kept for a toaster that is not ready yet; older ones make way */\nconst QUEUE_LIMIT = 10\n\n/**\n * Shows a toast in the page's toaster. Toasts before the toaster is ready (its class still loading) wait for\n * it. Several elements tell the visitor about errors only by toast, so every layout needs a <spmkt-toaster>:\n * without one, debug mode warns, and an error is logged to the console rather than lost without a trace.\n */\nexport function showToast(input: ToastInput): void {\n const toaster = document.querySelector('spmkt-toaster')\n if (toaster instanceof SpmktToaster && toaster.isConnected) {\n toaster.show(input)\n return\n }\n if (!toaster) {\n warnOnce('toaster:missing', 'No <spmkt-toaster> on the page: toasts cannot be shown')\n if (input.tone === 'error') console.error(`[spmkt] ${input.message}`)\n }\n queue.push(input)\n if (queue.length > QUEUE_LIMIT) queue.shift()\n}\n\n/**\n * Short messages (added to cart, errors). Each expires after its duration; hovering or focusing the list\n * holds them. Subclass and override renderToast() to change the markup.\n */\nexport class SpmktToaster extends SpmktElement {\n private toasts: Toast[] = []\n private timers = new Map<number, ReturnType<typeof setTimeout>>()\n private held = false\n\n override connectedCallback(): void {\n super.connectedCallback()\n const list = this.requirePart('list')\n const hold = () => this.hold(true)\n const release = () => this.hold(false)\n this.listen(list, 'pointerenter', hold)\n this.listen(list, 'pointerleave', release)\n this.listen(list, 'focusin', hold)\n this.listen(list, 'focusout', release)\n this.onDisconnect(() => this.timers.forEach((timer) => clearTimeout(timer)))\n queue.splice(0).forEach((input) => this.show(input))\n }\n\n show(input: ToastInput): Toast {\n const toast: Toast = {\n id: nextId++,\n message: input.message,\n tone: input.tone ?? 'info',\n duration: input.duration ?? 5000,\n action: input.action,\n }\n this.toasts = [...this.toasts, toast]\n this.schedule(toast)\n this.paint()\n return toast\n }\n\n dismiss(id: number): void {\n clearTimeout(this.timers.get(id))\n this.timers.delete(id)\n this.toasts = this.toasts.filter((toast) => toast.id !== id)\n this.paint()\n }\n\n get current(): readonly Toast[] {\n return this.toasts\n }\n\n protected renderToast(toast: Toast): unknown {\n return html`<li class=\"toast toast--${toast.tone}\" data-state=${toast.tone}>\n <p class=\"toast__message\">${toast.message}</p>\n ${toast.action ? html`<a class=\"toast__action\" href=${toast.action.href}>${toast.action.label}</a>` : nothing}\n <button\n type=\"button\"\n class=\"toast__close\"\n aria-label=${t('common.close')}\n @click=${() => this.dismiss(toast.id)}\n >\n ×\n </button>\n </li>`\n }\n\n private paint(): void {\n this.renderPart(\n 'list',\n html`${repeat(\n this.toasts,\n (toast) => toast.id,\n (toast) => this.renderToast(toast),\n )}`,\n )\n }\n\n private schedule(toast: Toast): void {\n if (toast.duration > 0 && !this.held) {\n this.timers.set(\n toast.id,\n setTimeout(() => this.dismiss(toast.id), toast.duration),\n )\n }\n }\n\n private hold(held: boolean): void {\n this.held = held\n if (held) {\n this.timers.forEach((timer) => clearTimeout(timer))\n this.timers.clear()\n } else {\n this.toasts.forEach((toast) => this.schedule(toast))\n }\n }\n}\n"],"names":[],"mappings":";;;;;AA8BA,IAAI,SAAS;AACb,MAAM,QAAsB,CAAA;AAE5B,MAAM,cAAc;AAOb,SAAS,UAAU,OAAyB;AACjD,QAAM,UAAU,SAAS,cAAc,eAAe;AACtD,MAAI,mBAAmB,gBAAgB,QAAQ,aAAa;AAC1D,YAAQ,KAAK,KAAK;AAClB;AAAA,EACF;AACA,MAAI,CAAC,SAAS;AACZ,aAAS,mBAAmB,wDAAwD;AACpF,QAAI,MAAM,SAAS,QAAS,SAAQ,MAAM,WAAW,MAAM,OAAO,EAAE;AAAA,EACtE;AACA,QAAM,KAAK,KAAK;AAChB,MAAI,MAAM,SAAS,YAAa,OAAM,MAAA;AACxC;AAMO,MAAM,qBAAqB,aAAa;AAAA,EAAxC,cAAA;AAAA,UAAA,GAAA,SAAA;AACL,SAAQ,SAAkB,CAAA;AAC1B,SAAQ,6BAAa,IAAA;AACrB,SAAQ,OAAO;AAAA,EAAA;AAAA,EAEN,oBAA0B;AACjC,UAAM,kBAAA;AACN,UAAM,OAAO,KAAK,YAAY,MAAM;AACpC,UAAM,OAAO,MAAM,KAAK,KAAK,IAAI;AACjC,UAAM,UAAU,MAAM,KAAK,KAAK,KAAK;AACrC,SAAK,OAAO,MAAM,gBAAgB,IAAI;AACtC,SAAK,OAAO,MAAM,gBAAgB,OAAO;AACzC,SAAK,OAAO,MAAM,WAAW,IAAI;AACjC,SAAK,OAAO,MAAM,YAAY,OAAO;AACrC,SAAK,aAAa,MAAM,KAAK,OAAO,QAAQ,CAAC,UAAU,aAAa,KAAK,CAAC,CAAC;AAC3E,UAAM,OAAO,CAAC,EAAE,QAAQ,CAAC,UAAU,KAAK,KAAK,KAAK,CAAC;AAAA,EACrD;AAAA,EAEA,KAAK,OAA0B;AAC7B,UAAM,QAAe;AAAA,MACnB,IAAI;AAAA,MACJ,SAAS,MAAM;AAAA,MACf,MAAM,MAAM,QAAQ;AAAA,MACpB,UAAU,MAAM,YAAY;AAAA,MAC5B,QAAQ,MAAM;AAAA,IAAA;AAEhB,SAAK,SAAS,CAAC,GAAG,KAAK,QAAQ,KAAK;AACpC,SAAK,SAAS,KAAK;AACnB,SAAK,MAAA;AACL,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ,IAAkB;AACxB,iBAAa,KAAK,OAAO,IAAI,EAAE,CAAC;AAChC,SAAK,OAAO,OAAO,EAAE;AACrB,SAAK,SAAS,KAAK,OAAO,OAAO,CAAC,UAAU,MAAM,OAAO,EAAE;AAC3D,SAAK,MAAA;AAAA,EACP;AAAA,EAEA,IAAI,UAA4B;AAC9B,WAAO,KAAK;AAAA,EACd;AAAA,EAEU,YAAY,OAAuB;AAC3C,WAAO,+BAA+B,MAAM,IAAI,gBAAgB,MAAM,IAAI;AAAA,kCAC5C,MAAM,OAAO;AAAA,QACvC,MAAM,SAAS,qCAAqC,MAAM,OAAO,IAAI,IAAI,MAAM,OAAO,KAAK,SAAS,OAAO;AAAA;AAAA;AAAA;AAAA,qBAI9F,EAAE,cAAc,CAAC;AAAA,iBACrB,MAAM,KAAK,QAAQ,MAAM,EAAE,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAK3C;AAAA,EAEQ,QAAc;AACpB,SAAK;AAAA,MACH;AAAA,MACA,OAAO;AAAA,QACL,KAAK;AAAA,QACL,CAAC,UAAU,MAAM;AAAA,QACjB,CAAC,UAAU,KAAK,YAAY,KAAK;AAAA,MAAA,CAClC;AAAA,IAAA;AAAA,EAEL;AAAA,EAEQ,SAAS,OAAoB;AACnC,QAAI,MAAM,WAAW,KAAK,CAAC,KAAK,MAAM;AACpC,WAAK,OAAO;AAAA,QACV,MAAM;AAAA,QACN,WAAW,MAAM,KAAK,QAAQ,MAAM,EAAE,GAAG,MAAM,QAAQ;AAAA,MAAA;AAAA,IAE3D;AAAA,EACF;AAAA,EAEQ,KAAK,MAAqB;AAChC,SAAK,OAAO;AACZ,QAAI,MAAM;AACR,WAAK,OAAO,QAAQ,CAAC,UAAU,aAAa,KAAK,CAAC;AAClD,WAAK,OAAO,MAAA;AAAA,IACd,OAAO;AACL,WAAK,OAAO,QAAQ,CAAC,UAAU,KAAK,SAAS,KAAK,CAAC;AAAA,IACrD;AAAA,EACF;AACF;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SpmktElement } from '../../lit/spmkt-element';
|
|
2
|
+
/**
|
|
3
|
+
* Parts of <spmkt-variant-picker variant="<id of the variant shown>"> (inside the product section):
|
|
4
|
+
* - form (required): a GET form back to the product with one control per option group, named
|
|
5
|
+
* options[<attribute id>], each with data-group="<attribute id>"; the server picks the variant
|
|
6
|
+
* - apply (optional): the form's submit button, hidden once the element applies changes itself
|
|
7
|
+
*
|
|
8
|
+
* A change re-renders the section around the element (its own copy: a quick view puts a second one on the page)
|
|
9
|
+
* for the chosen options (sections=<key>, plus changed=<attribute id> so a missing combination keeps the option
|
|
10
|
+
* just picked), then, for the page's own product (not in a dialog), puts ?variant=<id> in the address bar,
|
|
11
|
+
* read from the new picker's `variant` attribute. The new section's page events are not announced: another
|
|
12
|
+
* variant is not another product view.
|
|
13
|
+
*/
|
|
14
|
+
export interface VariantPickerParts {
|
|
15
|
+
form: HTMLFormElement;
|
|
16
|
+
apply?: HTMLElement;
|
|
17
|
+
}
|
|
18
|
+
/** Variant choice without a page load; the product section is re-rendered for the variant. */
|
|
19
|
+
export declare class SpmktVariantPicker extends SpmktElement {
|
|
20
|
+
static properties: {
|
|
21
|
+
variant: {
|
|
22
|
+
type: NumberConstructor;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
variant: number;
|
|
26
|
+
connectedCallback(): void;
|
|
27
|
+
/** The product URL for the form's options (and the group just changed). */
|
|
28
|
+
optionsUrl(changed?: number): URL;
|
|
29
|
+
private choose;
|
|
30
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { SpmktElement } from "../../lit/spmkt-element.js";
|
|
2
|
+
import { sectionKey, fetchFragments, swapSection } from "../../lit/fragments.js";
|
|
3
|
+
import { dispatch } from "../../core/events.js";
|
|
4
|
+
import { isAbortError } from "../../core/errors.js";
|
|
5
|
+
import { t } from "../../core/i18n.js";
|
|
6
|
+
import { showToast } from "../toaster/toaster.js";
|
|
7
|
+
let inFlight;
|
|
8
|
+
class SpmktVariantPicker extends SpmktElement {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.variant = 0;
|
|
12
|
+
}
|
|
13
|
+
static {
|
|
14
|
+
this.properties = {
|
|
15
|
+
variant: { type: Number }
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
connectedCallback() {
|
|
19
|
+
super.connectedCallback();
|
|
20
|
+
const form = this.requirePart("form");
|
|
21
|
+
if (!sectionKey(this)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const apply = this.findPart("apply");
|
|
25
|
+
if (apply) apply.hidden = true;
|
|
26
|
+
this.listen(form, "change", (event) => {
|
|
27
|
+
const group = event.target?.dataset?.group;
|
|
28
|
+
void this.choose(group ? Number(group) : void 0);
|
|
29
|
+
});
|
|
30
|
+
this.listen(form, "submit", (event) => {
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
void this.choose();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** The product URL for the form's options (and the group just changed). */
|
|
36
|
+
optionsUrl(changed) {
|
|
37
|
+
const form = this.requirePart("form");
|
|
38
|
+
const url = new URL(form.action || location.href, location.href);
|
|
39
|
+
url.search = "";
|
|
40
|
+
for (const [name, value] of new FormData(form)) {
|
|
41
|
+
if (typeof value === "string") url.searchParams.append(name, value);
|
|
42
|
+
}
|
|
43
|
+
if (changed !== void 0) url.searchParams.set("changed", String(changed));
|
|
44
|
+
return url;
|
|
45
|
+
}
|
|
46
|
+
async choose(changed) {
|
|
47
|
+
const key = sectionKey(this);
|
|
48
|
+
if (!key) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
inFlight?.abort();
|
|
52
|
+
const controller = inFlight = new AbortController();
|
|
53
|
+
const section = this.closest("[data-section-id]");
|
|
54
|
+
section?.setAttribute("aria-busy", "true");
|
|
55
|
+
try {
|
|
56
|
+
const response = await fetchFragments(this.optionsUrl(changed), {
|
|
57
|
+
sections: [key],
|
|
58
|
+
signal: controller.signal
|
|
59
|
+
});
|
|
60
|
+
const html = response.sections[key];
|
|
61
|
+
if (!html) {
|
|
62
|
+
throw new Error("The product section was not in the response");
|
|
63
|
+
}
|
|
64
|
+
const next = swapSection(this, html);
|
|
65
|
+
const id = Number(next?.querySelector("spmkt-variant-picker")?.getAttribute("variant"));
|
|
66
|
+
if (id > 0) {
|
|
67
|
+
if (!next?.closest("dialog")) {
|
|
68
|
+
const address = new URL(location.href);
|
|
69
|
+
address.searchParams.set("variant", String(id));
|
|
70
|
+
history.replaceState(history.state, "", address);
|
|
71
|
+
}
|
|
72
|
+
dispatch(next ?? document, "spmkt:variant-change", { id });
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (!isAbortError(error)) {
|
|
76
|
+
section?.removeAttribute("aria-busy");
|
|
77
|
+
showToast({ message: t("common.error"), tone: "error" });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
SpmktVariantPicker
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=variant-picker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variant-picker.js","sources":["../../../src/elements/variant-picker/variant-picker.ts"],"sourcesContent":["import { SpmktElement } from '../../lit/spmkt-element'\nimport { fetchFragments, sectionKey, swapSection } from '../../lit/fragments'\nimport { dispatch } from '../../core/events'\nimport { isAbortError } from '../../core/errors'\nimport { t } from '../../core/i18n'\nimport { showToast } from '../toaster/toaster'\n\n/**\n * Parts of <spmkt-variant-picker variant=\"<id of the variant shown>\"> (inside the product section):\n * - form (required): a GET form back to the product with one control per option group, named\n * options[<attribute id>], each with data-group=\"<attribute id>\"; the server picks the variant\n * - apply (optional): the form's submit button, hidden once the element applies changes itself\n *\n * A change re-renders the section around the element (its own copy: a quick view puts a second one on the page)\n * for the chosen options (sections=<key>, plus changed=<attribute id> so a missing combination keeps the option\n * just picked), then, for the page's own product (not in a dialog), puts ?variant=<id> in the address bar,\n * read from the new picker's `variant` attribute. The new section's page events are not announced: another\n * variant is not another product view.\n */\nexport interface VariantPickerParts {\n form: HTMLFormElement\n apply?: HTMLElement\n}\n\nlet inFlight: AbortController | undefined\n\n/** Variant choice without a page load; the product section is re-rendered for the variant. */\nexport class SpmktVariantPicker extends SpmktElement {\n static override properties = {\n variant: { type: Number },\n }\n variant = 0\n\n override connectedCallback(): void {\n super.connectedCallback()\n const form = this.requirePart<HTMLFormElement>('form')\n // Outside a theme section (nothing to re-render) the form submits as usual\n if (!sectionKey(this)) {\n return\n }\n const apply = this.findPart('apply')\n if (apply) apply.hidden = true\n this.listen(form, 'change', (event) => {\n const group = (event.target as HTMLElement | null)?.dataset?.group\n void this.choose(group ? Number(group) : undefined)\n })\n this.listen(form, 'submit', (event) => {\n event.preventDefault()\n void this.choose()\n })\n }\n\n /** The product URL for the form's options (and the group just changed). */\n optionsUrl(changed?: number): URL {\n const form = this.requirePart<HTMLFormElement>('form')\n const url = new URL(form.action || location.href, location.href)\n url.search = ''\n for (const [name, value] of new FormData(form)) {\n if (typeof value === 'string') url.searchParams.append(name, value)\n }\n if (changed !== undefined) url.searchParams.set('changed', String(changed))\n return url\n }\n\n private async choose(changed?: number): Promise<void> {\n const key = sectionKey(this)\n if (!key) {\n return\n }\n inFlight?.abort()\n const controller = (inFlight = new AbortController())\n const section = this.closest('[data-section-id]')\n section?.setAttribute('aria-busy', 'true')\n try {\n const response = await fetchFragments(this.optionsUrl(changed), {\n sections: [key],\n signal: controller.signal,\n })\n const html = response.sections[key]\n if (!html) {\n throw new Error('The product section was not in the response')\n }\n const next = swapSection(this, html)\n const id = Number(next?.querySelector('spmkt-variant-picker')?.getAttribute('variant'))\n if (id > 0) {\n // The address bar is the page's product: a quick view's choice stays in the dialog\n if (!next?.closest('dialog')) {\n const address = new URL(location.href)\n address.searchParams.set('variant', String(id))\n history.replaceState(history.state, '', address)\n }\n dispatch(next ?? document, 'spmkt:variant-change', { id })\n }\n } catch (error) {\n if (!isAbortError(error)) {\n section?.removeAttribute('aria-busy')\n showToast({ message: t('common.error'), tone: 'error' })\n }\n }\n }\n}\n"],"names":[],"mappings":";;;;;;AAwBA,IAAI;AAGG,MAAM,2BAA2B,aAAa;AAAA,EAA9C,cAAA;AAAA,UAAA,GAAA,SAAA;AAIL,SAAA,UAAU;AAAA,EAAA;AAAA,EAHV,OAAA;AAAA,SAAgB,aAAa;AAAA,MAC3B,SAAS,EAAE,MAAM,OAAA;AAAA,IAAO;AAAA,EAC1B;AAAA,EAGS,oBAA0B;AACjC,UAAM,kBAAA;AACN,UAAM,OAAO,KAAK,YAA6B,MAAM;AAErD,QAAI,CAAC,WAAW,IAAI,GAAG;AACrB;AAAA,IACF;AACA,UAAM,QAAQ,KAAK,SAAS,OAAO;AACnC,QAAI,aAAa,SAAS;AAC1B,SAAK,OAAO,MAAM,UAAU,CAAC,UAAU;AACrC,YAAM,QAAS,MAAM,QAA+B,SAAS;AAC7D,WAAK,KAAK,OAAO,QAAQ,OAAO,KAAK,IAAI,MAAS;AAAA,IACpD,CAAC;AACD,SAAK,OAAO,MAAM,UAAU,CAAC,UAAU;AACrC,YAAM,eAAA;AACN,WAAK,KAAK,OAAA;AAAA,IACZ,CAAC;AAAA,EACH;AAAA;AAAA,EAGA,WAAW,SAAuB;AAChC,UAAM,OAAO,KAAK,YAA6B,MAAM;AACrD,UAAM,MAAM,IAAI,IAAI,KAAK,UAAU,SAAS,MAAM,SAAS,IAAI;AAC/D,QAAI,SAAS;AACb,eAAW,CAAC,MAAM,KAAK,KAAK,IAAI,SAAS,IAAI,GAAG;AAC9C,UAAI,OAAO,UAAU,cAAc,aAAa,OAAO,MAAM,KAAK;AAAA,IACpE;AACA,QAAI,YAAY,OAAW,KAAI,aAAa,IAAI,WAAW,OAAO,OAAO,CAAC;AAC1E,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,OAAO,SAAiC;AACpD,UAAM,MAAM,WAAW,IAAI;AAC3B,QAAI,CAAC,KAAK;AACR;AAAA,IACF;AACA,cAAU,MAAA;AACV,UAAM,aAAc,WAAW,IAAI,gBAAA;AACnC,UAAM,UAAU,KAAK,QAAQ,mBAAmB;AAChD,aAAS,aAAa,aAAa,MAAM;AACzC,QAAI;AACF,YAAM,WAAW,MAAM,eAAe,KAAK,WAAW,OAAO,GAAG;AAAA,QAC9D,UAAU,CAAC,GAAG;AAAA,QACd,QAAQ,WAAW;AAAA,MAAA,CACpB;AACD,YAAM,OAAO,SAAS,SAAS,GAAG;AAClC,UAAI,CAAC,MAAM;AACT,cAAM,IAAI,MAAM,6CAA6C;AAAA,MAC/D;AACA,YAAM,OAAO,YAAY,MAAM,IAAI;AACnC,YAAM,KAAK,OAAO,MAAM,cAAc,sBAAsB,GAAG,aAAa,SAAS,CAAC;AACtF,UAAI,KAAK,GAAG;AAEV,YAAI,CAAC,MAAM,QAAQ,QAAQ,GAAG;AAC5B,gBAAM,UAAU,IAAI,IAAI,SAAS,IAAI;AACrC,kBAAQ,aAAa,IAAI,WAAW,OAAO,EAAE,CAAC;AAC9C,kBAAQ,aAAa,QAAQ,OAAO,IAAI,OAAO;AAAA,QACjD;AACA,iBAAS,QAAQ,UAAU,wBAAwB,EAAE,IAAI;AAAA,MAC3D;AAAA,IACF,SAAS,OAAO;AACd,UAAI,CAAC,aAAa,KAAK,GAAG;AACxB,iBAAS,gBAAgB,WAAW;AACpC,kBAAU,EAAE,SAAS,EAAE,cAAc,GAAG,MAAM,SAAS;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AACF;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SpmktElement } from '../../lit/spmkt-element';
|
|
2
|
+
/**
|
|
3
|
+
* Parts of <spmkt-vote review-id> ("was this review helpful?"):
|
|
4
|
+
* - up, down (required): buttons with aria-pressed
|
|
5
|
+
* - up-count, down-count (optional): the counts
|
|
6
|
+
*
|
|
7
|
+
* The server keeps one vote per review and visitor (a signed-in customer, else an address per day) and lets
|
|
8
|
+
* it change sides; the element mirrors that in aria-pressed and counts optimistically, rolling back on refusal.
|
|
9
|
+
*/
|
|
10
|
+
export interface VoteParts {
|
|
11
|
+
up: HTMLButtonElement;
|
|
12
|
+
down: HTMLButtonElement;
|
|
13
|
+
'up-count'?: HTMLElement;
|
|
14
|
+
'down-count'?: HTMLElement;
|
|
15
|
+
}
|
|
16
|
+
type Side = 'up' | 'down';
|
|
17
|
+
export declare class SpmktVote extends SpmktElement {
|
|
18
|
+
static properties: {
|
|
19
|
+
reviewId: {
|
|
20
|
+
type: NumberConstructor;
|
|
21
|
+
attribute: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
reviewId: number;
|
|
25
|
+
private busy;
|
|
26
|
+
connectedCallback(): void;
|
|
27
|
+
get choice(): Side | undefined;
|
|
28
|
+
vote(side: Side): Promise<void>;
|
|
29
|
+
private counts;
|
|
30
|
+
private apply;
|
|
31
|
+
private paintPressed;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { SpmktElement } from "../../lit/spmkt-element.js";
|
|
2
|
+
import { voteOnReview } from "../../core/api/reviews.js";
|
|
3
|
+
import { ValidationError } from "../../core/errors.js";
|
|
4
|
+
import { t } from "../../core/i18n.js";
|
|
5
|
+
import { showToast } from "../toaster/toaster.js";
|
|
6
|
+
const votes = /* @__PURE__ */ new Map();
|
|
7
|
+
class SpmktVote extends SpmktElement {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.reviewId = 0;
|
|
11
|
+
this.busy = false;
|
|
12
|
+
}
|
|
13
|
+
static {
|
|
14
|
+
this.properties = { reviewId: { type: Number, attribute: "review-id" } };
|
|
15
|
+
}
|
|
16
|
+
connectedCallback() {
|
|
17
|
+
super.connectedCallback();
|
|
18
|
+
for (const side of ["up", "down"]) {
|
|
19
|
+
this.listen(this.requirePart(side), "click", () => void this.vote(side));
|
|
20
|
+
}
|
|
21
|
+
this.paintPressed(votes.get(this.reviewId));
|
|
22
|
+
}
|
|
23
|
+
get choice() {
|
|
24
|
+
return votes.get(this.reviewId);
|
|
25
|
+
}
|
|
26
|
+
async vote(side) {
|
|
27
|
+
const previous = votes.get(this.reviewId);
|
|
28
|
+
if (this.busy) return;
|
|
29
|
+
if (previous === side) {
|
|
30
|
+
showToast({ message: t("reviews.alreadyVoted"), tone: "info" });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const counts = this.counts();
|
|
34
|
+
this.busy = true;
|
|
35
|
+
this.apply(side, {
|
|
36
|
+
up: counts.up + (side === "up" ? 1 : 0) - (previous === "up" ? 1 : 0),
|
|
37
|
+
down: counts.down + (side === "down" ? 1 : 0) - (previous === "down" ? 1 : 0)
|
|
38
|
+
});
|
|
39
|
+
try {
|
|
40
|
+
const review = await voteOnReview(this.reviewId, side === "up");
|
|
41
|
+
this.apply(side, { up: Number(review.up_votes) || 0, down: Number(review.down_votes) || 0 });
|
|
42
|
+
} catch (error) {
|
|
43
|
+
this.apply(previous, counts);
|
|
44
|
+
const message = error instanceof ValidationError && error.message ? error.message : t("reviews.voteFailed");
|
|
45
|
+
showToast({ message, tone: "error" });
|
|
46
|
+
} finally {
|
|
47
|
+
this.busy = false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
counts() {
|
|
51
|
+
const read = (side) => Number(this.findPart(`${side}-count`)?.textContent ?? 0) || 0;
|
|
52
|
+
return { up: read("up"), down: read("down") };
|
|
53
|
+
}
|
|
54
|
+
apply(side, counts) {
|
|
55
|
+
if (side) votes.set(this.reviewId, side);
|
|
56
|
+
else votes.delete(this.reviewId);
|
|
57
|
+
this.paintPressed(side);
|
|
58
|
+
for (const s of ["up", "down"]) {
|
|
59
|
+
const count = this.findPart(`${s}-count`);
|
|
60
|
+
if (count) count.textContent = String(counts[s]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
paintPressed(side) {
|
|
64
|
+
for (const s of ["up", "down"]) {
|
|
65
|
+
this.findPart(s)?.setAttribute("aria-pressed", String(s === side));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
SpmktVote
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=vote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vote.js","sources":["../../../src/elements/vote/vote.ts"],"sourcesContent":["import { SpmktElement } from '../../lit/spmkt-element'\nimport { voteOnReview } from '../../core/api/reviews'\nimport { ValidationError } from '../../core/errors'\nimport { t } from '../../core/i18n'\nimport { showToast } from '../toaster/toaster'\n\n/**\n * Parts of <spmkt-vote review-id> (\"was this review helpful?\"):\n * - up, down (required): buttons with aria-pressed\n * - up-count, down-count (optional): the counts\n *\n * The server keeps one vote per review and visitor (a signed-in customer, else an address per day) and lets\n * it change sides; the element mirrors that in aria-pressed and counts optimistically, rolling back on refusal.\n */\nexport interface VoteParts {\n up: HTMLButtonElement\n down: HTMLButtonElement\n 'up-count'?: HTMLElement\n 'down-count'?: HTMLElement\n}\n\ntype Side = 'up' | 'down'\n\n/** This page's votes by review id, so a re-rendered list still shows them */\nconst votes = new Map<number, Side>()\n\nexport class SpmktVote extends SpmktElement {\n static override properties = { reviewId: { type: Number, attribute: 'review-id' } }\n reviewId = 0\n\n private busy = false\n\n override connectedCallback(): void {\n super.connectedCallback()\n for (const side of ['up', 'down'] as const) {\n this.listen(this.requirePart(side), 'click', () => void this.vote(side))\n }\n this.paintPressed(votes.get(this.reviewId))\n }\n\n get choice(): Side | undefined {\n return votes.get(this.reviewId)\n }\n\n async vote(side: Side): Promise<void> {\n const previous = votes.get(this.reviewId)\n if (this.busy) return\n if (previous === side) {\n showToast({ message: t('reviews.alreadyVoted'), tone: 'info' })\n return\n }\n const counts = this.counts()\n this.busy = true\n // Optimistic: the new side gains a vote, a changed one loses it\n this.apply(side, {\n up: counts.up + (side === 'up' ? 1 : 0) - (previous === 'up' ? 1 : 0),\n down: counts.down + (side === 'down' ? 1 : 0) - (previous === 'down' ? 1 : 0),\n })\n try {\n const review = await voteOnReview(this.reviewId, side === 'up')\n this.apply(side, { up: Number(review.up_votes) || 0, down: Number(review.down_votes) || 0 })\n } catch (error) {\n this.apply(previous, counts)\n const message =\n error instanceof ValidationError && error.message ? error.message : t('reviews.voteFailed')\n showToast({ message, tone: 'error' })\n } finally {\n this.busy = false\n }\n }\n\n private counts(): Record<Side, number> {\n const read = (side: Side) => Number(this.findPart(`${side}-count`)?.textContent ?? 0) || 0\n return { up: read('up'), down: read('down') }\n }\n\n private apply(side: Side | undefined, counts: Record<Side, number>): void {\n if (side) votes.set(this.reviewId, side)\n else votes.delete(this.reviewId)\n this.paintPressed(side)\n for (const s of ['up', 'down'] as const) {\n const count = this.findPart(`${s}-count`)\n if (count) count.textContent = String(counts[s])\n }\n }\n\n private paintPressed(side: Side | undefined): void {\n for (const s of ['up', 'down'] as const) {\n this.findPart(s)?.setAttribute('aria-pressed', String(s === side))\n }\n }\n}\n"],"names":[],"mappings":";;;;;AAwBA,MAAM,4BAAY,IAAA;AAEX,MAAM,kBAAkB,aAAa;AAAA,EAArC,cAAA;AAAA,UAAA,GAAA,SAAA;AAEL,SAAA,WAAW;AAEX,SAAQ,OAAO;AAAA,EAAA;AAAA,EAHf,OAAA;AAAA,SAAgB,aAAa,EAAE,UAAU,EAAE,MAAM,QAAQ,WAAW,cAAY;AAAA,EAAE;AAAA,EAKzE,oBAA0B;AACjC,UAAM,kBAAA;AACN,eAAW,QAAQ,CAAC,MAAM,MAAM,GAAY;AAC1C,WAAK,OAAO,KAAK,YAAY,IAAI,GAAG,SAAS,MAAM,KAAK,KAAK,KAAK,IAAI,CAAC;AAAA,IACzE;AACA,SAAK,aAAa,MAAM,IAAI,KAAK,QAAQ,CAAC;AAAA,EAC5C;AAAA,EAEA,IAAI,SAA2B;AAC7B,WAAO,MAAM,IAAI,KAAK,QAAQ;AAAA,EAChC;AAAA,EAEA,MAAM,KAAK,MAA2B;AACpC,UAAM,WAAW,MAAM,IAAI,KAAK,QAAQ;AACxC,QAAI,KAAK,KAAM;AACf,QAAI,aAAa,MAAM;AACrB,gBAAU,EAAE,SAAS,EAAE,sBAAsB,GAAG,MAAM,QAAQ;AAC9D;AAAA,IACF;AACA,UAAM,SAAS,KAAK,OAAA;AACpB,SAAK,OAAO;AAEZ,SAAK,MAAM,MAAM;AAAA,MACf,IAAI,OAAO,MAAM,SAAS,OAAO,IAAI,MAAM,aAAa,OAAO,IAAI;AAAA,MACnE,MAAM,OAAO,QAAQ,SAAS,SAAS,IAAI,MAAM,aAAa,SAAS,IAAI;AAAA,IAAA,CAC5E;AACD,QAAI;AACF,YAAM,SAAS,MAAM,aAAa,KAAK,UAAU,SAAS,IAAI;AAC9D,WAAK,MAAM,MAAM,EAAE,IAAI,OAAO,OAAO,QAAQ,KAAK,GAAG,MAAM,OAAO,OAAO,UAAU,KAAK,GAAG;AAAA,IAC7F,SAAS,OAAO;AACd,WAAK,MAAM,UAAU,MAAM;AAC3B,YAAM,UACJ,iBAAiB,mBAAmB,MAAM,UAAU,MAAM,UAAU,EAAE,oBAAoB;AAC5F,gBAAU,EAAE,SAAS,MAAM,QAAA,CAAS;AAAA,IACtC,UAAA;AACE,WAAK,OAAO;AAAA,IACd;AAAA,EACF;AAAA,EAEQ,SAA+B;AACrC,UAAM,OAAO,CAAC,SAAe,OAAO,KAAK,SAAS,GAAG,IAAI,QAAQ,GAAG,eAAe,CAAC,KAAK;AACzF,WAAO,EAAE,IAAI,KAAK,IAAI,GAAG,MAAM,KAAK,MAAM,EAAA;AAAA,EAC5C;AAAA,EAEQ,MAAM,MAAwB,QAAoC;AACxE,QAAI,KAAM,OAAM,IAAI,KAAK,UAAU,IAAI;AAAA,QAClC,OAAM,OAAO,KAAK,QAAQ;AAC/B,SAAK,aAAa,IAAI;AACtB,eAAW,KAAK,CAAC,MAAM,MAAM,GAAY;AACvC,YAAM,QAAQ,KAAK,SAAS,GAAG,CAAC,QAAQ;AACxC,UAAI,MAAO,OAAM,cAAc,OAAO,OAAO,CAAC,CAAC;AAAA,IACjD;AAAA,EACF;AAAA,EAEQ,aAAa,MAA8B;AACjD,eAAW,KAAK,CAAC,MAAM,MAAM,GAAY;AACvC,WAAK,SAAS,CAAC,GAAG,aAAa,gBAAgB,OAAO,MAAM,IAAI,CAAC;AAAA,IACnE;AAAA,EACF;AACF;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field messages in theme markup: each field has an element with data-error-for="<field name>" (render it
|
|
3
|
+
* hidden). Messages for fields without one are returned, so the caller can show them elsewhere.
|
|
4
|
+
*/
|
|
5
|
+
export declare function showFieldErrors(root: ParentNode, errors: Record<string, string[]>): string[];
|
|
6
|
+
export declare function clearFieldErrors(root: ParentNode): void;
|
|
7
|
+
/** What to tell the visitor about a failed request: the server's own words where they are meant for people. */
|
|
8
|
+
export declare function errorMessage(error: unknown, fallback?: string): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { SessionExpiredError, TimeoutError, NetworkError, ValidationError, HttpError } from "../core/errors.js";
|
|
2
|
+
import { t } from "../core/i18n.js";
|
|
3
|
+
function showFieldErrors(root, errors) {
|
|
4
|
+
clearFieldErrors(root);
|
|
5
|
+
const unplaced = [];
|
|
6
|
+
for (const [field, messages] of Object.entries(errors)) {
|
|
7
|
+
const message = messages[0];
|
|
8
|
+
if (!message) continue;
|
|
9
|
+
const name = field.split(".")[0];
|
|
10
|
+
const slot = root.querySelector(`[data-error-for="${CSS.escape(name)}"]`);
|
|
11
|
+
if (slot) {
|
|
12
|
+
slot.textContent = message;
|
|
13
|
+
slot.hidden = false;
|
|
14
|
+
root.querySelectorAll(`[name="${CSS.escape(name)}"]`).forEach((control) => control.setAttribute("aria-invalid", "true"));
|
|
15
|
+
} else {
|
|
16
|
+
unplaced.push(message);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return unplaced;
|
|
20
|
+
}
|
|
21
|
+
function clearFieldErrors(root) {
|
|
22
|
+
root.querySelectorAll("[data-error-for]").forEach((slot) => {
|
|
23
|
+
slot.textContent = "";
|
|
24
|
+
slot.hidden = true;
|
|
25
|
+
});
|
|
26
|
+
root.querySelectorAll("[aria-invalid]").forEach((control) => control.removeAttribute("aria-invalid"));
|
|
27
|
+
}
|
|
28
|
+
function errorMessage(error, fallback = t("common.error")) {
|
|
29
|
+
if (error instanceof SessionExpiredError) return t("common.sessionExpired");
|
|
30
|
+
if (error instanceof TimeoutError) return t("common.timeout");
|
|
31
|
+
if (error instanceof NetworkError) return t("common.network");
|
|
32
|
+
if (error instanceof ValidationError) return error.message || fallback;
|
|
33
|
+
if (error instanceof HttpError && error.status < 500 && error.status !== 429 && error.message)
|
|
34
|
+
return error.message;
|
|
35
|
+
return fallback;
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
clearFieldErrors,
|
|
39
|
+
errorMessage,
|
|
40
|
+
showFieldErrors
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=forms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forms.js","sources":["../../src/lit/forms.ts"],"sourcesContent":["import { HttpError, NetworkError, SessionExpiredError, TimeoutError, ValidationError } from '../core/errors'\nimport { t } from '../core/i18n'\n\n/**\n * Field messages in theme markup: each field has an element with data-error-for=\"<field name>\" (render it\n * hidden). Messages for fields without one are returned, so the caller can show them elsewhere.\n */\nexport function showFieldErrors(root: ParentNode, errors: Record<string, string[]>): string[] {\n clearFieldErrors(root)\n const unplaced: string[] = []\n for (const [field, messages] of Object.entries(errors)) {\n const message = messages[0]\n if (!message) continue\n // images.0 belongs to images\n const name = field.split('.')[0]!\n const slot = root.querySelector<HTMLElement>(`[data-error-for=\"${CSS.escape(name)}\"]`)\n if (slot) {\n slot.textContent = message\n slot.hidden = false\n root\n .querySelectorAll(`[name=\"${CSS.escape(name)}\"]`)\n .forEach((control) => control.setAttribute('aria-invalid', 'true'))\n } else {\n unplaced.push(message)\n }\n }\n return unplaced\n}\n\nexport function clearFieldErrors(root: ParentNode): void {\n root.querySelectorAll<HTMLElement>('[data-error-for]').forEach((slot) => {\n slot.textContent = ''\n slot.hidden = true\n })\n root.querySelectorAll('[aria-invalid]').forEach((control) => control.removeAttribute('aria-invalid'))\n}\n\n/** What to tell the visitor about a failed request: the server's own words where they are meant for people. */\nexport function errorMessage(error: unknown, fallback = t('common.error')): string {\n if (error instanceof SessionExpiredError) return t('common.sessionExpired')\n if (error instanceof TimeoutError) return t('common.timeout')\n if (error instanceof NetworkError) return t('common.network')\n if (error instanceof ValidationError) return error.message || fallback\n if (error instanceof HttpError && error.status < 500 && error.status !== 429 && error.message)\n return error.message\n return fallback\n}\n"],"names":[],"mappings":";;AAOO,SAAS,gBAAgB,MAAkB,QAA4C;AAC5F,mBAAiB,IAAI;AACrB,QAAM,WAAqB,CAAA;AAC3B,aAAW,CAAC,OAAO,QAAQ,KAAK,OAAO,QAAQ,MAAM,GAAG;AACtD,UAAM,UAAU,SAAS,CAAC;AAC1B,QAAI,CAAC,QAAS;AAEd,UAAM,OAAO,MAAM,MAAM,GAAG,EAAE,CAAC;AAC/B,UAAM,OAAO,KAAK,cAA2B,oBAAoB,IAAI,OAAO,IAAI,CAAC,IAAI;AACrF,QAAI,MAAM;AACR,WAAK,cAAc;AACnB,WAAK,SAAS;AACd,WACG,iBAAiB,UAAU,IAAI,OAAO,IAAI,CAAC,IAAI,EAC/C,QAAQ,CAAC,YAAY,QAAQ,aAAa,gBAAgB,MAAM,CAAC;AAAA,IACtE,OAAO;AACL,eAAS,KAAK,OAAO;AAAA,IACvB;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,iBAAiB,MAAwB;AACvD,OAAK,iBAA8B,kBAAkB,EAAE,QAAQ,CAAC,SAAS;AACvE,SAAK,cAAc;AACnB,SAAK,SAAS;AAAA,EAChB,CAAC;AACD,OAAK,iBAAiB,gBAAgB,EAAE,QAAQ,CAAC,YAAY,QAAQ,gBAAgB,cAAc,CAAC;AACtG;AAGO,SAAS,aAAa,OAAgB,WAAW,EAAE,cAAc,GAAW;AACjF,MAAI,iBAAiB,oBAAqB,QAAO,EAAE,uBAAuB;AAC1E,MAAI,iBAAiB,aAAc,QAAO,EAAE,gBAAgB;AAC5D,MAAI,iBAAiB,aAAc,QAAO,EAAE,gBAAgB;AAC5D,MAAI,iBAAiB,gBAAiB,QAAO,MAAM,WAAW;AAC9D,MAAI,iBAAiB,aAAa,MAAM,SAAS,OAAO,MAAM,WAAW,OAAO,MAAM;AACpF,WAAO,MAAM;AACf,SAAO;AACT;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Sections of a page, keyed as requested (see StorefrontPage on the platform). */
|
|
2
|
+
export interface FragmentResponse {
|
|
3
|
+
/** "<document>/<sectionId>" -> section HTML, wrapper included; "" when hidden or gone */
|
|
4
|
+
sections: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
export interface FetchFragmentsOptions {
|
|
7
|
+
sections: string[];
|
|
8
|
+
/** More query parameters for the page, e.g. { related_page: 2 }; they replace the URL's own of that name */
|
|
9
|
+
query?: Record<string, string | number>;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
/** The fragment key of the section that contains `el`, e.g. "template:category/main", or null. */
|
|
13
|
+
export declare function sectionKey(el: Element): string | null;
|
|
14
|
+
/**
|
|
15
|
+
* Asks a storefront URL for some of its sections instead of the whole page:
|
|
16
|
+
* GET url?sections=a,b (the URL's own query, e.g. filters, is kept; `query` adds to it).
|
|
17
|
+
*/
|
|
18
|
+
export declare function fetchFragments(url: string | URL, options: FetchFragmentsOptions): Promise<FragmentResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* Replaces the section that contains `from` (the element asking, so its own copy: a quick view can put a second
|
|
21
|
+
* section with the same key on the page) with its re-rendered HTML; "" removes it.
|
|
22
|
+
* Returns the new section element, or null when it was removed or `from` is in no section.
|
|
23
|
+
*/
|
|
24
|
+
export declare function swapSection(from: Element, html: string): Element | null;
|
|
25
|
+
/** Replaces the children of `el` (an owned part, or a Blade region being re-rendered) with HTML. */
|
|
26
|
+
export declare function swapInto(el: Element, html: string): void;
|
|
27
|
+
/** Appends the HTML's nodes to `el` (load more). */
|
|
28
|
+
export declare function appendInto(el: Element, html: string): void;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { shopRequestUrl, get } from "../core/request.js";
|
|
2
|
+
function sectionKey(el) {
|
|
3
|
+
const section = el.closest("[data-section-id][data-theme-document]");
|
|
4
|
+
return section ? `${section.dataset.themeDocument}/${section.dataset.sectionId}` : null;
|
|
5
|
+
}
|
|
6
|
+
function previewHeaders() {
|
|
7
|
+
const token = window.__themePreview?.token;
|
|
8
|
+
return token ? { "X-Theme-Preview": token } : {};
|
|
9
|
+
}
|
|
10
|
+
async function fetchFragments(url, options) {
|
|
11
|
+
const target = shopRequestUrl(url);
|
|
12
|
+
for (const [name, value] of Object.entries(options.query ?? {})) {
|
|
13
|
+
target.searchParams.set(name, String(value));
|
|
14
|
+
}
|
|
15
|
+
target.searchParams.set("sections", options.sections.join(","));
|
|
16
|
+
const response = await get(target.toString(), {
|
|
17
|
+
signal: options.signal,
|
|
18
|
+
headers: previewHeaders()
|
|
19
|
+
});
|
|
20
|
+
return { sections: response?.sections ?? {} };
|
|
21
|
+
}
|
|
22
|
+
function parse(html) {
|
|
23
|
+
const template = document.createElement("template");
|
|
24
|
+
template.innerHTML = html;
|
|
25
|
+
return template.content;
|
|
26
|
+
}
|
|
27
|
+
function keepFocus(scope, swap) {
|
|
28
|
+
const active = document.activeElement;
|
|
29
|
+
const id = active && scope.contains(active) && active.id ? active.id : null;
|
|
30
|
+
const replacement = swap();
|
|
31
|
+
if (id && replacement) {
|
|
32
|
+
replacement.querySelector(`#${CSS.escape(id)}`)?.focus();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function swapSection(from, html) {
|
|
36
|
+
const current = from.closest("[data-section-id][data-theme-document]");
|
|
37
|
+
if (!current) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
if (html === "") {
|
|
41
|
+
current.remove();
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const next = parse(html).firstElementChild;
|
|
45
|
+
if (!next) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
keepFocus(current, () => {
|
|
49
|
+
current.replaceWith(next);
|
|
50
|
+
return next;
|
|
51
|
+
});
|
|
52
|
+
return next;
|
|
53
|
+
}
|
|
54
|
+
function swapInto(el, html) {
|
|
55
|
+
keepFocus(el, () => {
|
|
56
|
+
el.replaceChildren(parse(html));
|
|
57
|
+
return el;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function appendInto(el, html) {
|
|
61
|
+
el.append(parse(html));
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
appendInto,
|
|
65
|
+
fetchFragments,
|
|
66
|
+
sectionKey,
|
|
67
|
+
swapInto,
|
|
68
|
+
swapSection
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=fragments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fragments.js","sources":["../../src/lit/fragments.ts"],"sourcesContent":["import { get, shopRequestUrl } from '../core/request'\n\n/** Sections of a page, keyed as requested (see StorefrontPage on the platform). */\nexport interface FragmentResponse {\n /** \"<document>/<sectionId>\" -> section HTML, wrapper included; \"\" when hidden or gone */\n sections: Record<string, string>\n}\n\nexport interface FetchFragmentsOptions {\n sections: string[]\n /** More query parameters for the page, e.g. { related_page: 2 }; they replace the URL's own of that name */\n query?: Record<string, string | number>\n signal?: AbortSignal\n}\n\n/** The fragment key of the section that contains `el`, e.g. \"template:category/main\", or null. */\nexport function sectionKey(el: Element): string | null {\n const section = el.closest<HTMLElement>('[data-section-id][data-theme-document]')\n return section ? `${section.dataset.themeDocument}/${section.dataset.sectionId}` : null\n}\n\n/** In the theme editor's preview, requests carry the preview token so drafts render. */\nfunction previewHeaders(): Record<string, string> {\n const token = (window as unknown as { __themePreview?: { token?: string } }).__themePreview?.token\n return token ? { 'X-Theme-Preview': token } : {}\n}\n\n/**\n * Asks a storefront URL for some of its sections instead of the whole page:\n * GET url?sections=a,b (the URL's own query, e.g. filters, is kept; `query` adds to it).\n */\nexport async function fetchFragments(\n url: string | URL,\n options: FetchFragmentsOptions,\n): Promise<FragmentResponse> {\n // Same origin only (the HTML goes into the page); a root-relative URL gets the shop's base path\n const target = shopRequestUrl(url)\n for (const [name, value] of Object.entries(options.query ?? {})) {\n target.searchParams.set(name, String(value))\n }\n target.searchParams.set('sections', options.sections.join(','))\n const response = await get<Partial<FragmentResponse>>(target.toString(), {\n signal: options.signal,\n headers: previewHeaders(),\n })\n return { sections: response?.sections ?? {} }\n}\n\nfunction parse(html: string): DocumentFragment {\n const template = document.createElement('template')\n template.innerHTML = html\n return template.content\n}\n\n/** Re-focuses the element that had focus inside `scope` before a swap, found again by id. */\nfunction keepFocus(scope: Element, swap: () => ParentNode | null): void {\n const active = document.activeElement\n const id = active && scope.contains(active) && active.id ? active.id : null\n const replacement = swap()\n if (id && replacement) {\n replacement.querySelector<HTMLElement>(`#${CSS.escape(id)}`)?.focus()\n }\n}\n\n/**\n * Replaces the section that contains `from` (the element asking, so its own copy: a quick view can put a second\n * section with the same key on the page) with its re-rendered HTML; \"\" removes it.\n * Returns the new section element, or null when it was removed or `from` is in no section.\n */\nexport function swapSection(from: Element, html: string): Element | null {\n const current = from.closest('[data-section-id][data-theme-document]')\n if (!current) {\n return null\n }\n if (html === '') {\n current.remove()\n return null\n }\n const next = parse(html).firstElementChild\n if (!next) {\n return null\n }\n keepFocus(current, () => {\n current.replaceWith(next)\n return next\n })\n return next\n}\n\n/** Replaces the children of `el` (an owned part, or a Blade region being re-rendered) with HTML. */\nexport function swapInto(el: Element, html: string): void {\n keepFocus(el, () => {\n el.replaceChildren(parse(html))\n return el\n })\n}\n\n/** Appends the HTML's nodes to `el` (load more). */\nexport function appendInto(el: Element, html: string): void {\n el.append(parse(html))\n}\n"],"names":[],"mappings":";AAgBO,SAAS,WAAW,IAA4B;AACrD,QAAM,UAAU,GAAG,QAAqB,wCAAwC;AAChF,SAAO,UAAU,GAAG,QAAQ,QAAQ,aAAa,IAAI,QAAQ,QAAQ,SAAS,KAAK;AACrF;AAGA,SAAS,iBAAyC;AAChD,QAAM,QAAS,OAA8D,gBAAgB;AAC7F,SAAO,QAAQ,EAAE,mBAAmB,MAAA,IAAU,CAAA;AAChD;AAMA,eAAsB,eACpB,KACA,SAC2B;AAE3B,QAAM,SAAS,eAAe,GAAG;AACjC,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,QAAQ,SAAS,CAAA,CAAE,GAAG;AAC/D,WAAO,aAAa,IAAI,MAAM,OAAO,KAAK,CAAC;AAAA,EAC7C;AACA,SAAO,aAAa,IAAI,YAAY,QAAQ,SAAS,KAAK,GAAG,CAAC;AAC9D,QAAM,WAAW,MAAM,IAA+B,OAAO,YAAY;AAAA,IACvE,QAAQ,QAAQ;AAAA,IAChB,SAAS,eAAA;AAAA,EAAe,CACzB;AACD,SAAO,EAAE,UAAU,UAAU,YAAY,CAAA,EAAC;AAC5C;AAEA,SAAS,MAAM,MAAgC;AAC7C,QAAM,WAAW,SAAS,cAAc,UAAU;AAClD,WAAS,YAAY;AACrB,SAAO,SAAS;AAClB;AAGA,SAAS,UAAU,OAAgB,MAAqC;AACtE,QAAM,SAAS,SAAS;AACxB,QAAM,KAAK,UAAU,MAAM,SAAS,MAAM,KAAK,OAAO,KAAK,OAAO,KAAK;AACvE,QAAM,cAAc,KAAA;AACpB,MAAI,MAAM,aAAa;AACrB,gBAAY,cAA2B,IAAI,IAAI,OAAO,EAAE,CAAC,EAAE,GAAG,MAAA;AAAA,EAChE;AACF;AAOO,SAAS,YAAY,MAAe,MAA8B;AACvE,QAAM,UAAU,KAAK,QAAQ,wCAAwC;AACrE,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AACA,MAAI,SAAS,IAAI;AACf,YAAQ,OAAA;AACR,WAAO;AAAA,EACT;AACA,QAAM,OAAO,MAAM,IAAI,EAAE;AACzB,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AACA,YAAU,SAAS,MAAM;AACvB,YAAQ,YAAY,IAAI;AACxB,WAAO;AAAA,EACT,CAAC;AACD,SAAO;AACT;AAGO,SAAS,SAAS,IAAa,MAAoB;AACxD,YAAU,IAAI,MAAM;AAClB,OAAG,gBAAgB,MAAM,IAAI,CAAC;AAC9B,WAAO;AAAA,EACT,CAAC;AACH;AAGO,SAAS,WAAW,IAAa,MAAoB;AAC1D,KAAG,OAAO,MAAM,IAAI,CAAC;AACvB;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { SpmktElement, MissingPartError } from './spmkt-element';
|
|
2
|
+
export { SignalController, watch } from './signal-controller';
|
|
3
|
+
export { lazyDefine } from './lazy-define';
|
|
4
|
+
export type { ElementLoader } from './lazy-define';
|
|
5
|
+
export { fetchFragments, swapSection, swapInto, appendInto, sectionKey } from './fragments';
|
|
6
|
+
export type { FragmentResponse, FetchFragmentsOptions } from './fragments';
|
|
7
|
+
export { showFieldErrors, clearFieldErrors, errorMessage } from './forms';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MissingPartError, SpmktElement } from "./spmkt-element.js";
|
|
2
|
+
import { SignalController, watch } from "./signal-controller.js";
|
|
3
|
+
import { lazyDefine } from "./lazy-define.js";
|
|
4
|
+
import { appendInto, fetchFragments, sectionKey, swapInto, swapSection } from "./fragments.js";
|
|
5
|
+
import { clearFieldErrors, errorMessage, showFieldErrors } from "./forms.js";
|
|
6
|
+
export {
|
|
7
|
+
MissingPartError,
|
|
8
|
+
SignalController,
|
|
9
|
+
SpmktElement,
|
|
10
|
+
appendInto,
|
|
11
|
+
clearFieldErrors,
|
|
12
|
+
errorMessage,
|
|
13
|
+
fetchFragments,
|
|
14
|
+
lazyDefine,
|
|
15
|
+
sectionKey,
|
|
16
|
+
showFieldErrors,
|
|
17
|
+
swapInto,
|
|
18
|
+
swapSection,
|
|
19
|
+
watch
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|