@revenexx/cover 0.1.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/LICENSE +21 -0
- package/README.md +39 -0
- package/app/api/account.ts +8 -0
- package/app/api/categories.ts +3 -0
- package/app/api/checkout.ts +6 -0
- package/app/api/images.ts +4 -0
- package/app/api/markets.ts +3 -0
- package/app/api/product.ts +3 -0
- package/app/api/products.ts +4 -0
- package/app/api/search.ts +4 -0
- package/app/app.config.ts +29 -0
- package/app/assets/css/cover.css +25 -0
- package/app/components/account/AccountMenu.vue +30 -0
- package/app/components/account/AccountShell.vue +18 -0
- package/app/components/account/AccountSidebar.vue +90 -0
- package/app/components/account/address/AccountAddressCard.vue +287 -0
- package/app/components/account/carts/AccountCartsTable.vue +284 -0
- package/app/components/account/dashboard/AccountDashboard.vue +351 -0
- package/app/components/account/directorder/AccountDirectOrder.vue +512 -0
- package/app/components/account/governance/AccountApprovalLimitsTable.vue +221 -0
- package/app/components/account/governance/AccountCostCenterDetail.vue +276 -0
- package/app/components/account/governance/AccountCostCentersTable.vue +252 -0
- package/app/components/account/governance/AccountRequisitionDetail.vue +295 -0
- package/app/components/account/governance/AccountRequisitionsTable.vue +255 -0
- package/app/components/account/governance/AccountWorkflowDetail.vue +215 -0
- package/app/components/account/governance/AccountWorkflowsTable.vue +168 -0
- package/app/components/account/governance/GovernanceApprovalLimitModal.vue +183 -0
- package/app/components/account/governance/GovernanceCostCenterModal.vue +188 -0
- package/app/components/account/governance/GovernanceWorkflowModal.vue +191 -0
- package/app/components/account/orderlists/AccountOrderListDetail.vue +349 -0
- package/app/components/account/orderlists/AccountOrderListsTable.vue +352 -0
- package/app/components/account/orders/AccountOrderDetail.vue +376 -0
- package/app/components/account/orders/AccountOrdersTable.vue +281 -0
- package/app/components/account/preferences/AccountPreferences.vue +50 -0
- package/app/components/auth/AuthForgotPasswordPanel.vue +88 -0
- package/app/components/auth/AuthLoginPanel.vue +103 -0
- package/app/components/auth/AuthLoginTeaser.vue +24 -0
- package/app/components/auth/AuthPageHeader.vue +21 -0
- package/app/components/auth/AuthRegisterPanel.vue +431 -0
- package/app/components/auth/AuthRegisterTeaser.vue +24 -0
- package/app/components/auth/AuthResetPasswordPanel.vue +115 -0
- package/app/components/cart/CartButton.vue +42 -0
- package/app/components/cart/actions/CartCostCenterModal.vue +110 -0
- package/app/components/cart/actions/CartExportModal.vue +82 -0
- package/app/components/cart/actions/CartPositionTextsModal.vue +92 -0
- package/app/components/cart/actions/CartSaveToListModal.vue +177 -0
- package/app/components/cart/actions/CartWorkflowPickerModal.vue +64 -0
- package/app/components/cart/drawer/CartDrawer.vue +49 -0
- package/app/components/cart/item/CartItem.vue +318 -0
- package/app/components/cart/manage/CartNameModal.vue +68 -0
- package/app/components/cart/position/CartPosition.vue +369 -0
- package/app/components/cart/quickadd/CartQuickAdd.vue +145 -0
- package/app/components/cart/recommend/CartCrossSell.vue +102 -0
- package/app/components/cart/recommend/CartRecommendCard.vue +59 -0
- package/app/components/cart/recommend/CartReorderStrip.vue +108 -0
- package/app/components/cart/requisition/CartRequisitionGroup.vue +74 -0
- package/app/components/cart/skeleton/CartSkeleton.vue +18 -0
- package/app/components/cart/summary/CartSummary.vue +25 -0
- package/app/components/cart/summary/CartSummaryBreakdown.vue +35 -0
- package/app/components/cart/switcher/CartSwitcher.vue +147 -0
- package/app/components/cart/target/CartTargetModal.vue +129 -0
- package/app/components/cart/view/CartApprovalsPanel.vue +89 -0
- package/app/components/cart/view/CartListHeader.vue +86 -0
- package/app/components/cart/view/CartPositionList.vue +94 -0
- package/app/components/cart/view/CartSummaryPanel.vue +254 -0
- package/app/components/cart/view/CartView.vue +310 -0
- package/app/components/category/info/CategoryPrice.vue +47 -0
- package/app/components/category/info/CategorySku.vue +15 -0
- package/app/components/category/info/CategoryStock.vue +25 -0
- package/app/components/category/list/CategoryItemCount.vue +27 -0
- package/app/components/category/list/CategoryListPagination.vue +81 -0
- package/app/components/category/skeleton/CategoryDetailSkeleton.vue +12 -0
- package/app/components/category/skeleton/CategoryListSkeleton.vue +65 -0
- package/app/components/category/view/CategoryViewToggle.vue +33 -0
- package/app/components/category/view/GridView.vue +78 -0
- package/app/components/category/view/ListView.vue +80 -0
- package/app/components/checkout/confirmation/CheckoutConfirmationView.vue +289 -0
- package/app/components/checkout/form/CheckoutSchemaForm.vue +72 -0
- package/app/components/checkout/onepage/CheckoutAddressPickerModal.vue +260 -0
- package/app/components/checkout/onepage/CheckoutAddressSection.vue +186 -0
- package/app/components/checkout/onepage/CheckoutDeliverySection.vue +158 -0
- package/app/components/checkout/onepage/CheckoutGate.vue +67 -0
- package/app/components/checkout/onepage/CheckoutGuestDetailsSection.vue +154 -0
- package/app/components/checkout/onepage/CheckoutNotesSection.vue +62 -0
- package/app/components/checkout/onepage/CheckoutOnePageView.vue +77 -0
- package/app/components/checkout/onepage/CheckoutPaymentSection.vue +181 -0
- package/app/components/checkout/onepage/CheckoutSectionTitle.vue +18 -0
- package/app/components/checkout/onepage/CheckoutSummarySection.vue +211 -0
- package/app/components/checkout/onepage/CheckoutWorkflowPanel.vue +38 -0
- package/app/components/layout/AppLogo.vue +21 -0
- package/app/components/layout/footer/Footer.vue +148 -0
- package/app/components/layout/header/AppBar.vue +75 -0
- package/app/components/layout/header/CategoryNav.vue +93 -0
- package/app/components/layout/header/HeaderActionItem.vue +81 -0
- package/app/components/layout/header/LocaleSwitcher.vue +123 -0
- package/app/components/layout/header/MainNav.vue +61 -0
- package/app/components/layout/header/MobileMenu.vue +81 -0
- package/app/components/layout/header/TopBar.vue +63 -0
- package/app/components/listing/ListingView.vue +227 -0
- package/app/components/product/detail/ProductDetailAddToCart.vue +188 -0
- package/app/components/product/detail/ProductDetailDescription.vue +20 -0
- package/app/components/product/detail/ProductDetailImageGallery.vue +58 -0
- package/app/components/product/detail/ProductDetailPricing.vue +108 -0
- package/app/components/product/detail/ProductDetailSaveToList.vue +291 -0
- package/app/components/product/detail/ProductDetailSpecifications.vue +33 -0
- package/app/components/product/detail/ProductDetailStock.vue +36 -0
- package/app/components/search/filter/SearchFacets.vue +256 -0
- package/app/components/search/filter/SearchFacetsDrawer.vue +58 -0
- package/app/components/ui/AppShell.vue +7 -0
- package/app/components/ui/debug/PiniaStateCard.vue +106 -0
- package/app/components/ui/feedback/EmptyState.vue +30 -0
- package/app/components/ui/feedback/ErrorBoundary.vue +44 -0
- package/app/components/ui/feedback/NotFound.vue +34 -0
- package/app/components/ui/forms/CountrySelection.vue +14 -0
- package/app/components/ui/forms/FormKitDatePicker.vue +124 -0
- package/app/components/ui/forms/PasswordInput.vue +136 -0
- package/app/components/ui/forms/SearchInput.vue +213 -0
- package/app/components/ui/table/TableSortButton.vue +51 -0
- package/app/components/ui/table/TableToolbar.vue +66 -0
- package/app/composables/useAccount.ts +27 -0
- package/app/composables/useAccountAddresses.ts +116 -0
- package/app/composables/useAccountOrders.ts +18 -0
- package/app/composables/useAppUrl.ts +38 -0
- package/app/composables/useAuthStore.ts +202 -0
- package/app/composables/useB2BContext.ts +23 -0
- package/app/composables/useCartActions.ts +25 -0
- package/app/composables/useCartCalculation.ts +90 -0
- package/app/composables/useCartSelection.ts +46 -0
- package/app/composables/useCartStore.ts +837 -0
- package/app/composables/useCartSummaryFormatting.ts +28 -0
- package/app/composables/useCategories.ts +29 -0
- package/app/composables/useCheckoutOnePage.ts +438 -0
- package/app/composables/useCheckoutProfileSource.ts +8 -0
- package/app/composables/useCheckoutSchema.ts +28 -0
- package/app/composables/useDataTable.ts +14 -0
- package/app/composables/useFormValidation.ts +29 -0
- package/app/composables/useIcons.ts +17 -0
- package/app/composables/useLocalePreferences.ts +45 -0
- package/app/composables/useMarkets.ts +15 -0
- package/app/composables/useProduct.ts +89 -0
- package/app/composables/useProductCard.ts +8 -0
- package/app/composables/useProductCardActions.ts +106 -0
- package/app/composables/useProductImage.ts +12 -0
- package/app/composables/useProductListing.ts +210 -0
- package/app/composables/useProductUrl.ts +17 -0
- package/app/composables/useProducts.ts +130 -0
- package/app/composables/useSearch.ts +12 -0
- package/app/composables/useThemeStore.ts +81 -0
- package/app/composables/useViewMode.ts +18 -0
- package/app/config/countries.ts +74 -0
- package/app/config/icons.ts +283 -0
- package/app/config/navigation.ts +191 -0
- package/app/config/palette.ts +13 -0
- package/app/config/themes.ts +20 -0
- package/app/formkit.config.ts +50 -0
- package/app/interfaces/account/address-list.ts +34 -0
- package/app/interfaces/account/order-list.ts +47 -0
- package/app/interfaces/account/order-lists.ts +35 -0
- package/app/interfaces/account/profile.ts +17 -0
- package/app/interfaces/account.ts +3 -0
- package/app/interfaces/address.ts +9 -0
- package/app/interfaces/auth.ts +104 -0
- package/app/interfaces/b2b.ts +234 -0
- package/app/interfaces/cart-calculation.ts +131 -0
- package/app/interfaces/cart-item.ts +45 -0
- package/app/interfaces/checkout-draft.ts +4 -0
- package/app/interfaces/checkout.ts +43 -0
- package/app/interfaces/delivery.ts +13 -0
- package/app/interfaces/market.ts +24 -0
- package/app/interfaces/payment.ts +19 -0
- package/app/interfaces/persisted-cart.ts +10 -0
- package/app/interfaces/product-detail.ts +54 -0
- package/app/interfaces/product-list.ts +33 -0
- package/app/interfaces/search-facets.ts +14 -0
- package/app/interfaces/validation.ts +14 -0
- package/app/layouts/default.vue +78 -0
- package/app/layouts/focus.vue +80 -0
- package/app/plugins/formkit-locale.client.ts +23 -0
- package/app/shared/constants.ts +1 -0
- package/app/validations/companyName.ts +18 -0
- package/app/validations/emailFormat.ts +10 -0
- package/app/validations/formValidationConfig.ts +50 -0
- package/app/validations/maxLength.ts +12 -0
- package/app/validations/minLength.ts +9 -0
- package/app/validations/optionalCompanyName.ts +23 -0
- package/app/validations/passwordsMatch.ts +5 -0
- package/app/validations/phoneNumber.ts +19 -0
- package/app/validations/required.ts +11 -0
- package/app/validations/termsRequired.ts +4 -0
- package/app/validations/types.ts +10 -0
- package/app/validations/zipCode.ts +15 -0
- package/i18n/locales/de/account.json +458 -0
- package/i18n/locales/de/auth.json +155 -0
- package/i18n/locales/de/cart.json +263 -0
- package/i18n/locales/de/checkout.json +217 -0
- package/i18n/locales/de/common.json +80 -0
- package/i18n/locales/de/cover.json +33 -0
- package/i18n/locales/de/order.json +1 -0
- package/i18n/locales/de/product.json +71 -0
- package/i18n/locales/de/search.json +54 -0
- package/i18n/locales/de/validation.json +12 -0
- package/i18n/locales/en/account.json +458 -0
- package/i18n/locales/en/auth.json +155 -0
- package/i18n/locales/en/cart.json +263 -0
- package/i18n/locales/en/checkout.json +217 -0
- package/i18n/locales/en/common.json +80 -0
- package/i18n/locales/en/cover.json +33 -0
- package/i18n/locales/en/order.json +1 -0
- package/i18n/locales/en/product.json +71 -0
- package/i18n/locales/en/search.json +54 -0
- package/i18n/locales/en/validation.json +12 -0
- package/nuxt.config.ts +109 -0
- package/package.json +65 -0
- package/public/img/product-placeholder.svg +8 -0
- package/public/templates/direct-order-template.csv +3 -0
- package/public/templates/direct-order-template.xlsx +0 -0
- package/server/api/account/address/[id].delete.ts +51 -0
- package/server/api/account/address/[id].put.ts +83 -0
- package/server/api/account/address/index.post.ts +60 -0
- package/server/api/account/addresses.get.ts +25 -0
- package/server/api/account/context.get.ts +16 -0
- package/server/api/account/governance/[domain]/[id].put.ts +57 -0
- package/server/api/account/governance/[domain].post.ts +111 -0
- package/server/api/account/order-lists/[id].delete.ts +22 -0
- package/server/api/account/order-lists/[id].get.ts +17 -0
- package/server/api/account/order-lists/[id].put.ts +46 -0
- package/server/api/account/order-lists/index.get.ts +14 -0
- package/server/api/account/order-lists/index.post.ts +38 -0
- package/server/api/account/orders/[id].get.ts +35 -0
- package/server/api/account/orders.get.ts +35 -0
- package/server/api/account/profile.get.ts +56 -0
- package/server/api/account/profile.put.ts +128 -0
- package/server/api/account/requisitions/[id].get.ts +15 -0
- package/server/api/account/requisitions.get.ts +23 -0
- package/server/api/auth/login.post.ts +37 -0
- package/server/api/auth/logout.post.ts +4 -0
- package/server/api/auth/me.get.ts +3 -0
- package/server/api/auth/personas.get.ts +7 -0
- package/server/api/auth/recovery.post.ts +32 -0
- package/server/api/auth/recovery.put.ts +37 -0
- package/server/api/auth/register.post.ts +126 -0
- package/server/api/cart/calculate.post.ts +25 -0
- package/server/api/cart/export.post.ts +81 -0
- package/server/api/cart/index.delete.ts +10 -0
- package/server/api/cart/index.get.ts +10 -0
- package/server/api/cart/sync.post.ts +14 -0
- package/server/api/carts/[id]/activate.post.ts +18 -0
- package/server/api/carts/[id]/index.delete.ts +18 -0
- package/server/api/carts/[id]/index.put.ts +19 -0
- package/server/api/carts/[id]/items.post.ts +21 -0
- package/server/api/carts/index.get.ts +14 -0
- package/server/api/carts/index.post.ts +14 -0
- package/server/api/categories/[slug].get.ts +22 -0
- package/server/api/categories/index.get.ts +11 -0
- package/server/api/checkout/profile.get.ts +21 -0
- package/server/api/checkout/schema/[key].get.ts +19 -0
- package/server/api/checkout/session.post.ts +8 -0
- package/server/api/images/detail/[filename].get.ts +18 -0
- package/server/api/images/list/[filename].get.ts +17 -0
- package/server/api/markets.get.ts +9 -0
- package/server/api/orders/index.post.ts +376 -0
- package/server/api/payment/methods.post.ts +65 -0
- package/server/api/product/[id].get.ts +29 -0
- package/server/api/products/[id].get.ts +30 -0
- package/server/api/products/index.get.ts +21 -0
- package/server/api/requisitions/index.post.ts +67 -0
- package/server/api/shipping/rates.post.ts +70 -0
- package/server/api/themes/index.get.ts +9 -0
- package/server/api/typesense/drop.get.ts +22 -0
- package/server/api/typesense/health.get.ts +9 -0
- package/server/api/typesense/search.post.ts +199 -0
- package/server/api/typesense/seed.get.ts +112 -0
- package/server/api/typesense/suggest.post.ts +69 -0
- package/server/config/account/organization.json +146 -0
- package/server/config/account/personas.json +169 -0
- package/server/config/account/user.json +8 -0
- package/server/config/account/workflows.json +19 -0
- package/server/data/account/address-list.json +103 -0
- package/server/data/account/order-list.json +491 -0
- package/server/data/account/order-lists.json +149 -0
- package/server/data/account/profile.json +9 -0
- package/server/data/account/registration-requests.json +3 -0
- package/server/data/account/requisitions.json +686 -0
- package/server/data/categories.json +186 -0
- package/server/data/forms/checkout/add-address.json +24 -0
- package/server/data/list/5137-1.png +0 -0
- package/server/data/list/5498-1.png +0 -0
- package/server/data/list/5498-2.png +0 -0
- package/server/data/list/5498-3.png +0 -0
- package/server/data/list/5498-4.png +0 -0
- package/server/data/list/5498-5.png +0 -0
- package/server/data/list/5498-6.png +0 -0
- package/server/data/list/5519-1.png +0 -0
- package/server/data/list/5713-1.png +0 -0
- package/server/data/list/5789-1.png +0 -0
- package/server/data/list/5930-1.png +0 -0
- package/server/data/list/6127-1.png +0 -0
- package/server/data/list/6234-1.png +0 -0
- package/server/data/list/6238-1.png +0 -0
- package/server/data/list/6246-1.png +0 -0
- package/server/data/list/6270-1.png +0 -0
- package/server/data/list/6330-1.png +0 -0
- package/server/data/list/6336-1.png +0 -0
- package/server/data/list/6360-1.png +0 -0
- package/server/data/list/6363-1.png +0 -0
- package/server/data/list/6375-1.png +0 -0
- package/server/data/list/6385-1.png +0 -0
- package/server/data/list/6413-1.png +0 -0
- package/server/data/list/6418-1.png +0 -0
- package/server/data/list/6465-1.png +0 -0
- package/server/data/list/6477-1.png +0 -0
- package/server/data/list/6509-1.png +0 -0
- package/server/data/list/6545-1.png +0 -0
- package/server/data/list/6548-1.png +0 -0
- package/server/data/list/6566-1.png +0 -0
- package/server/data/list/6581-1.png +0 -0
- package/server/data/list/6609-1.png +0 -0
- package/server/data/list/6611-1.png +0 -0
- package/server/data/list/6641-1.png +0 -0
- package/server/data/list/6659-1.png +0 -0
- package/server/data/list/6662-1.png +0 -0
- package/server/data/list/6689-1.png +0 -0
- package/server/data/list/6698-1.png +0 -0
- package/server/data/list/6701-1.png +0 -0
- package/server/data/list/6752-1.png +0 -0
- package/server/data/list/6755-1.png +0 -0
- package/server/data/list/6837-1.png +0 -0
- package/server/data/list/6841-1.png +0 -0
- package/server/data/list/6844-1.png +0 -0
- package/server/data/list/6846-1.png +0 -0
- package/server/data/list/6886-1.png +0 -0
- package/server/data/list/6895-1.png +0 -0
- package/server/data/list/6897-1.png +0 -0
- package/server/data/list/6919-1.png +0 -0
- package/server/data/list/6977-1.png +0 -0
- package/server/data/list/6983-1.png +0 -0
- package/server/data/list/6984-1.png +0 -0
- package/server/data/list/6985-1.png +0 -0
- package/server/data/list/6986-1.png +0 -0
- package/server/data/list/6989-1.png +0 -0
- package/server/data/list/6995-1.png +0 -0
- package/server/data/list/6998-1.png +0 -0
- package/server/data/markets.json +24 -0
- package/server/data/product-detail.json +2450 -0
- package/server/data/product-list.json +2450 -0
- package/server/data/themes.json +8 -0
- package/server/interfaces/account.ts +20 -0
- package/server/interfaces/auth.ts +32 -0
- package/server/interfaces/b2bContext.ts +23 -0
- package/server/interfaces/cart.ts +46 -0
- package/server/interfaces/cartCalculation.ts +17 -0
- package/server/interfaces/category.ts +12 -0
- package/server/interfaces/checkoutProfile.ts +5 -0
- package/server/interfaces/log.ts +3 -0
- package/server/interfaces/market.ts +10 -0
- package/server/interfaces/product.ts +21 -0
- package/server/interfaces/schema.ts +20 -0
- package/server/interfaces/theme.ts +10 -0
- package/server/services/ApiAuthService.ts +138 -0
- package/server/services/ApiCartService.ts +254 -0
- package/server/services/ApiCategoryService.ts +25 -0
- package/server/services/ApiMarketService.ts +71 -0
- package/server/services/ApiProductService.ts +53 -0
- package/server/services/LocalFileCategoryService.ts +23 -0
- package/server/services/LocalFileCheckoutProfileService.ts +117 -0
- package/server/services/LocalFileProductService.ts +128 -0
- package/server/services/LocalFileSchemaService.ts +70 -0
- package/server/services/LocalFileThemeService.ts +18 -0
- package/server/services/LogService.ts +28 -0
- package/server/services/MockAccountService.ts +58 -0
- package/server/services/MockAuthService.ts +105 -0
- package/server/services/MockB2BContextService.ts +149 -0
- package/server/services/MockCartCalculationService.ts +395 -0
- package/server/services/MockMarketService.ts +18 -0
- package/server/services/SdkAccountService.ts +56 -0
- package/server/services/SdkAuthService.ts +83 -0
- package/server/services/SessionCartService.ts +31 -0
- package/server/utils/accountService.ts +30 -0
- package/server/utils/authCookie.ts +13 -0
- package/server/utils/authService.ts +43 -0
- package/server/utils/b2bService.ts +49 -0
- package/server/utils/cartService.ts +59 -0
- package/server/utils/categoryService.ts +19 -0
- package/server/utils/checkoutProfileService.ts +9 -0
- package/server/utils/checkoutSession.ts +38 -0
- package/server/utils/coverData.ts +84 -0
- package/server/utils/governanceStore.ts +38 -0
- package/server/utils/i18n.ts +76 -0
- package/server/utils/inventoryService.ts +14 -0
- package/server/utils/liveCatalog.ts +234 -0
- package/server/utils/liveInventories.ts +76 -0
- package/server/utils/liveOrders.ts +139 -0
- package/server/utils/livePrices.ts +93 -0
- package/server/utils/locale.ts +39 -0
- package/server/utils/logService.ts +19 -0
- package/server/utils/marketService.ts +24 -0
- package/server/utils/orderService.ts +14 -0
- package/server/utils/paymentService.ts +14 -0
- package/server/utils/priceService.ts +14 -0
- package/server/utils/productService.ts +28 -0
- package/server/utils/productsSchema.ts +30 -0
- package/server/utils/revenexxApi.ts +136 -0
- package/server/utils/schemaService.ts +25 -0
- package/server/utils/serviceMode.ts +70 -0
- package/server/utils/shippingService.ts +14 -0
- package/server/utils/shopSdk.ts +88 -0
- package/server/utils/themeService.ts +16 -0
- package/server/utils/typesense.ts +27 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { accountApi } from "../api/account";
|
|
2
|
+
import type { AccountAddress, AccountAddressFormState, AccountAddressListResponse } from "../interfaces/account/address-list";
|
|
3
|
+
|
|
4
|
+
export const useAccountAddresses = () => {
|
|
5
|
+
const { data, status, error, refresh } = useFetch<AccountAddressListResponse>(
|
|
6
|
+
accountApi.addresses(),
|
|
7
|
+
{
|
|
8
|
+
key: "account-addresses",
|
|
9
|
+
default: () => ({ addresses: [] as AccountAddress[] }),
|
|
10
|
+
},
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const addresses = computed(() => data.value.addresses);
|
|
14
|
+
|
|
15
|
+
async function updateAddress(
|
|
16
|
+
id: string,
|
|
17
|
+
formState: AccountAddressFormState,
|
|
18
|
+
): Promise<AccountAddress> {
|
|
19
|
+
const updated = await $fetch<AccountAddress>(accountApi.addressUpdate(id), {
|
|
20
|
+
method: "PUT",
|
|
21
|
+
body: formState,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
data.value = {
|
|
25
|
+
...data.value,
|
|
26
|
+
addresses: data.value.addresses.map((a) => {
|
|
27
|
+
if (a.id === id) {
|
|
28
|
+
return updated;
|
|
29
|
+
}
|
|
30
|
+
if (updated.isDefault && a.type === updated.type) {
|
|
31
|
+
return { ...a, isDefault: false };
|
|
32
|
+
}
|
|
33
|
+
return a;
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return updated;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function createAddress(formState: AccountAddressFormState): Promise<AccountAddress> {
|
|
41
|
+
const created = await $fetch<AccountAddress>(accountApi.addressCreate(), {
|
|
42
|
+
method: "POST",
|
|
43
|
+
body: formState,
|
|
44
|
+
});
|
|
45
|
+
if (created.isDefault) {
|
|
46
|
+
data.value = {
|
|
47
|
+
...data.value,
|
|
48
|
+
addresses: [
|
|
49
|
+
...data.value.addresses.map(a =>
|
|
50
|
+
a.type === created.type ? { ...a, isDefault: false } : a,
|
|
51
|
+
),
|
|
52
|
+
created,
|
|
53
|
+
],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
data.value = { ...data.value, addresses: [...data.value.addresses, created] };
|
|
58
|
+
}
|
|
59
|
+
return created;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function deleteAddress(id: string): Promise<void> {
|
|
63
|
+
const result = await $fetch<AccountAddressListResponse>(accountApi.addressDelete(id), {
|
|
64
|
+
method: "DELETE",
|
|
65
|
+
});
|
|
66
|
+
data.value = { ...data.value, addresses: result.addresses };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function autoFixDefaults(list: AccountAddress[]) {
|
|
70
|
+
const byType: Record<string, AccountAddress[]> = {};
|
|
71
|
+
for (const a of list) {
|
|
72
|
+
(byType[a.type] ??= []).push(a);
|
|
73
|
+
}
|
|
74
|
+
for (const group of Object.values(byType)) {
|
|
75
|
+
if (group.length === 1 && !group[0].isDefault) {
|
|
76
|
+
const a = group[0];
|
|
77
|
+
await updateAddress(a.id, {
|
|
78
|
+
company: a.company,
|
|
79
|
+
label: a.label,
|
|
80
|
+
firstName: a.firstName,
|
|
81
|
+
lastName: a.lastName,
|
|
82
|
+
street: a.street,
|
|
83
|
+
streetNumber: a.streetNumber,
|
|
84
|
+
city: a.city,
|
|
85
|
+
zip: a.zip,
|
|
86
|
+
country: a.country,
|
|
87
|
+
type: a.type,
|
|
88
|
+
isDefault: true,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let fixApplied = false;
|
|
95
|
+
watch(
|
|
96
|
+
addresses,
|
|
97
|
+
async (list) => {
|
|
98
|
+
if (list.length === 0 || fixApplied) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
fixApplied = true;
|
|
102
|
+
await autoFixDefaults(list);
|
|
103
|
+
},
|
|
104
|
+
{ immediate: true },
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
addresses,
|
|
109
|
+
status,
|
|
110
|
+
error,
|
|
111
|
+
refresh,
|
|
112
|
+
updateAddress,
|
|
113
|
+
createAddress,
|
|
114
|
+
deleteAddress,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { accountApi } from "../api/account";
|
|
2
|
+
import type { AccountOrder, AccountOrderListResponse } from "../interfaces/account/order-list";
|
|
3
|
+
|
|
4
|
+
export const useAccountOrders = () => {
|
|
5
|
+
const { data, status, error, refresh } = useFetch<AccountOrderListResponse>(accountApi.orders(), {
|
|
6
|
+
key: "account-orders",
|
|
7
|
+
default: () => ({ orders: [] as AccountOrder[] }),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const orders = computed(() => data.value.orders);
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
orders,
|
|
14
|
+
status,
|
|
15
|
+
error,
|
|
16
|
+
refresh,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locale-aware URL helper. Converts slash-prefixed paths to Nuxt route names
|
|
3
|
+
* and delegates to useLocalePath() so all navigation carries the current locale.
|
|
4
|
+
*
|
|
5
|
+
* Path → route name mapping follows Nuxt 4 file-based routing:
|
|
6
|
+
* / → index
|
|
7
|
+
* /cart → cart
|
|
8
|
+
* /checkout → checkout
|
|
9
|
+
* /checkout/... → checkout-...
|
|
10
|
+
*
|
|
11
|
+
* useLocalePath() from @nuxtjs/i18n v10 requires route names (not path strings);
|
|
12
|
+
* passing paths is documented as unsupported and breaks with prefix strategies.
|
|
13
|
+
*/
|
|
14
|
+
export const useAppUrl = () => {
|
|
15
|
+
const localePath = useLocalePath();
|
|
16
|
+
const route = useRoute();
|
|
17
|
+
|
|
18
|
+
function pathToRouteName(path: string): string {
|
|
19
|
+
if (path === "/") {
|
|
20
|
+
return "index";
|
|
21
|
+
}
|
|
22
|
+
return path.replace(/^\//, "").replace(/\//g, "-");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function to(path: string, query?: Record<string, string>): string {
|
|
26
|
+
const name = pathToRouteName(path);
|
|
27
|
+
if (query) {
|
|
28
|
+
return localePath({ name, query });
|
|
29
|
+
}
|
|
30
|
+
return localePath(name);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const isCartOrCheckoutPage = computed(() =>
|
|
34
|
+
/\/(cart|checkout)(\/|$)/.test(route.path),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return { to, isCartOrCheckoutPage };
|
|
38
|
+
};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { defineStore } from "pinia";
|
|
2
|
+
|
|
3
|
+
import type { AuthUser, LoginInput, RegisterInput, StoredSession } from "../interfaces/auth";
|
|
4
|
+
|
|
5
|
+
const WAS_AUTHENTICATED_KEY = "cover-was-authenticated";
|
|
6
|
+
|
|
7
|
+
function mapAuthError(err: unknown, context: "login" | "recovery" = "login"): string {
|
|
8
|
+
const type = (err as { data?: { data?: { type?: string } } })?.data?.data?.type;
|
|
9
|
+
if (typeof type === "string") {
|
|
10
|
+
switch (type) {
|
|
11
|
+
case "service_unavailable":
|
|
12
|
+
return "auth.errors.serviceUnavailable";
|
|
13
|
+
case "user_invalid_credentials":
|
|
14
|
+
case "user_not_found":
|
|
15
|
+
return context === "recovery"
|
|
16
|
+
? "auth.recovery.errors.userNotFound"
|
|
17
|
+
: "auth.login.errors.invalidCredentials";
|
|
18
|
+
case "user_blocked":
|
|
19
|
+
return "auth.login.errors.accountBlocked";
|
|
20
|
+
case "general_rate_limit_exceeded":
|
|
21
|
+
return context === "recovery"
|
|
22
|
+
? "auth.recovery.errors.rateLimited"
|
|
23
|
+
: "auth.login.errors.rateLimited";
|
|
24
|
+
case "user_session_already_exists":
|
|
25
|
+
return "auth.login.errors.sessionExists";
|
|
26
|
+
case "user_invalid_token":
|
|
27
|
+
case "general_argument_invalid":
|
|
28
|
+
return "auth.recovery.errors.invalidToken";
|
|
29
|
+
case "password_recently_used":
|
|
30
|
+
return "auth.recovery.errors.passwordRecentlyUsed";
|
|
31
|
+
}
|
|
32
|
+
return context === "recovery"
|
|
33
|
+
? "auth.recovery.errors.unknown"
|
|
34
|
+
: "auth.login.errors.unknown";
|
|
35
|
+
}
|
|
36
|
+
return context === "recovery"
|
|
37
|
+
? "auth.recovery.errors.network"
|
|
38
|
+
: "auth.login.errors.network";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const useAuthStore = defineStore("auth", () => {
|
|
42
|
+
const user = ref<AuthUser | null>(null);
|
|
43
|
+
const session = ref<StoredSession | null>(null);
|
|
44
|
+
|
|
45
|
+
const isLoggedIn = computed(() => user.value !== null);
|
|
46
|
+
|
|
47
|
+
const loading = ref(false);
|
|
48
|
+
const error = ref<string | null>(null);
|
|
49
|
+
|
|
50
|
+
function markAuthenticated() {
|
|
51
|
+
localStorage.setItem(WAS_AUTHENTICATED_KEY, "1");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function handleAuthExpiry() {
|
|
55
|
+
if (!localStorage.getItem(WAS_AUTHENTICATED_KEY)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
localStorage.removeItem(WAS_AUTHENTICATED_KEY);
|
|
59
|
+
const cart = useCartStore();
|
|
60
|
+
if (cart.liveCarts) {
|
|
61
|
+
// The customer's carts live server-side — only the local view resets.
|
|
62
|
+
await cart.onAuthLogout();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
cart.clearCart();
|
|
66
|
+
await cart.clearServerCart();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const register = async ({ email, password, name, profile }: RegisterInput) => {
|
|
70
|
+
loading.value = true;
|
|
71
|
+
error.value = null;
|
|
72
|
+
try {
|
|
73
|
+
const created = await $fetch<AuthUser>("/api/auth/register", {
|
|
74
|
+
method: "POST",
|
|
75
|
+
body: { email, password, name, profile },
|
|
76
|
+
});
|
|
77
|
+
user.value = created;
|
|
78
|
+
return created;
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
error.value = mapAuthError(err);
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
loading.value = false;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const login = async ({ email, password }: LoginInput) => {
|
|
90
|
+
loading.value = true;
|
|
91
|
+
error.value = null;
|
|
92
|
+
try {
|
|
93
|
+
const result = await $fetch<{ user: AuthUser; session: StoredSession }>("/api/auth/login", {
|
|
94
|
+
method: "POST",
|
|
95
|
+
body: { email, password },
|
|
96
|
+
});
|
|
97
|
+
user.value = result.user;
|
|
98
|
+
session.value = result.session;
|
|
99
|
+
markAuthenticated();
|
|
100
|
+
// Live carts: the BFF claimed/merged the session carts on login —
|
|
101
|
+
// adopt the merged server state into the local cart.
|
|
102
|
+
void useCartStore().onAuthLogin();
|
|
103
|
+
return result.session;
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
error.value = mapAuthError(err);
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
loading.value = false;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const logout = async () => {
|
|
115
|
+
loading.value = true;
|
|
116
|
+
error.value = null;
|
|
117
|
+
try {
|
|
118
|
+
await $fetch("/api/auth/logout", { method: "POST" });
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
error.value = mapAuthError(err);
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
localStorage.removeItem(WAS_AUTHENTICATED_KEY);
|
|
125
|
+
const cart = useCartStore();
|
|
126
|
+
if (cart.liveCarts) {
|
|
127
|
+
// The customer's carts stay in the carts app — reset the view.
|
|
128
|
+
void cart.onAuthLogout();
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
cart.clearCart();
|
|
132
|
+
void cart.clearServerCart();
|
|
133
|
+
}
|
|
134
|
+
loading.value = false;
|
|
135
|
+
session.value = null;
|
|
136
|
+
user.value = null;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const requestRecovery = async (email: string, url: string) => {
|
|
141
|
+
loading.value = true;
|
|
142
|
+
error.value = null;
|
|
143
|
+
try {
|
|
144
|
+
return await $fetch("/api/auth/recovery", {
|
|
145
|
+
method: "POST",
|
|
146
|
+
body: { email, url },
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
error.value = mapAuthError(err, "recovery");
|
|
151
|
+
throw err;
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
loading.value = false;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const confirmRecovery = async (userId: string, secret: string, password: string) => {
|
|
159
|
+
loading.value = true;
|
|
160
|
+
error.value = null;
|
|
161
|
+
try {
|
|
162
|
+
return await $fetch("/api/auth/recovery", {
|
|
163
|
+
method: "PUT",
|
|
164
|
+
body: { userId, secret, password },
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
error.value = mapAuthError(err, "recovery");
|
|
169
|
+
throw err;
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
loading.value = false;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const init = async (): Promise<void> => {
|
|
177
|
+
try {
|
|
178
|
+
const me = await $fetch<AuthUser | null>("/api/auth/me");
|
|
179
|
+
if (me) {
|
|
180
|
+
user.value = me;
|
|
181
|
+
markAuthenticated();
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
user.value = null;
|
|
185
|
+
session.value = null;
|
|
186
|
+
await handleAuthExpiry();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
user.value = null;
|
|
191
|
+
session.value = null;
|
|
192
|
+
await handleAuthExpiry();
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
user, session, isLoggedIn, loading, error,
|
|
198
|
+
register, login, logout,
|
|
199
|
+
requestRecovery, confirmRecovery,
|
|
200
|
+
init,
|
|
201
|
+
};
|
|
202
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { B2BContext } from "../interfaces/b2b";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The current user's B2B context — organization settings, cost centers,
|
|
5
|
+
* spending limits and workflow memberships. Fetched once and shared;
|
|
6
|
+
* call `refresh()` after auth changes.
|
|
7
|
+
*/
|
|
8
|
+
export function useB2BContext() {
|
|
9
|
+
const { data: context, refresh, status } = useFetch<B2BContext>("/api/account/context", {
|
|
10
|
+
key: "b2b-context",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const settings = computed(() => context.value?.settings ?? null);
|
|
14
|
+
const costCenters = computed(() => context.value?.costCenters ?? []);
|
|
15
|
+
const role = computed(() => context.value?.role ?? null);
|
|
16
|
+
const workflows = computed(() => context.value?.workflows ?? []);
|
|
17
|
+
|
|
18
|
+
const costCenterById = computed(() =>
|
|
19
|
+
new Map(costCenters.value.map(cc => [cc.id, cc])),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return { context, settings, costCenters, costCenterById, role, workflows, refresh, status };
|
|
23
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type CartActionType = "cost-center" | "texts" | "save" | "export";
|
|
2
|
+
|
|
3
|
+
interface CartActionState {
|
|
4
|
+
type: CartActionType | null;
|
|
5
|
+
lineKeys: string[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Shared state for the cart position/bulk action modals. The modals are
|
|
10
|
+
* mounted once in the cart view; positions and the bulk bar open them by
|
|
11
|
+
* setting the action with the affected line keys.
|
|
12
|
+
*/
|
|
13
|
+
export function useCartActions() {
|
|
14
|
+
const action = useState<CartActionState>("cart-action", () => ({ type: null, lineKeys: [] }));
|
|
15
|
+
|
|
16
|
+
function open(type: CartActionType, lineKeys: string[]): void {
|
|
17
|
+
action.value = { type, lineKeys };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function close(): void {
|
|
21
|
+
action.value = { type: null, lineKeys: [] };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return { action, open, close };
|
|
25
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { CartCalculation, CalculatedCartLine } from "../interfaces/cart-calculation";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shared cart calculation state. Exactly one component per page (the cart
|
|
5
|
+
* view or the checkout summary) orchestrates the recalculation by passing
|
|
6
|
+
* `orchestrate: true`; every other consumer just reads the shared state.
|
|
7
|
+
*
|
|
8
|
+
* Lines are matched to cart items BY INDEX — the same article may sit on
|
|
9
|
+
* several positions, so ids are not unique per line.
|
|
10
|
+
*/
|
|
11
|
+
export function useCartCalculation(options?: {
|
|
12
|
+
orchestrate?: boolean;
|
|
13
|
+
deliveryMethod?: Ref<string | undefined>;
|
|
14
|
+
}) {
|
|
15
|
+
const cart = useCartStore();
|
|
16
|
+
const { locale } = useI18n();
|
|
17
|
+
|
|
18
|
+
const calculation = useState<CartCalculation | null>("cart-calculation", () => null);
|
|
19
|
+
const pending = useState<boolean>("cart-calculation-pending", () => false);
|
|
20
|
+
|
|
21
|
+
async function refresh(): Promise<void> {
|
|
22
|
+
if (cart.items.length === 0) {
|
|
23
|
+
calculation.value = null;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
pending.value = true;
|
|
27
|
+
try {
|
|
28
|
+
calculation.value = await $fetch<CartCalculation>("/api/cart/calculate", {
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: { "x-locale": locale.value },
|
|
31
|
+
body: {
|
|
32
|
+
items: cart.items,
|
|
33
|
+
...(options?.deliveryMethod?.value
|
|
34
|
+
? { deliveryMethod: options.deliveryMethod.value }
|
|
35
|
+
: {}),
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// keep the previous calculation; the cart stays usable
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
pending.value = false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (options?.orchestrate && import.meta.client) {
|
|
48
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
49
|
+
const debouncedRefresh = () => {
|
|
50
|
+
if (timer) {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
}
|
|
53
|
+
timer = setTimeout(() => {
|
|
54
|
+
timer = null;
|
|
55
|
+
void refresh();
|
|
56
|
+
}, 300);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
watch(() => cart.items, debouncedRefresh, { deep: true, immediate: true });
|
|
60
|
+
watch(locale, debouncedRefresh);
|
|
61
|
+
if (options.deliveryMethod) {
|
|
62
|
+
watch(options.deliveryMethod, debouncedRefresh);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
onScopeDispose(() => {
|
|
66
|
+
if (timer) {
|
|
67
|
+
clearTimeout(timer);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Calculated line for the cart item at the given index. */
|
|
73
|
+
const lineAt = (index: number): CalculatedCartLine | null =>
|
|
74
|
+
calculation.value?.lines[index] ?? null;
|
|
75
|
+
|
|
76
|
+
/** lineKey → calculated line, zipped by index. */
|
|
77
|
+
const linesByKey = computed(() => {
|
|
78
|
+
const map = new Map<string, CalculatedCartLine>();
|
|
79
|
+
const lines = calculation.value?.lines ?? [];
|
|
80
|
+
cart.items.forEach((item, index) => {
|
|
81
|
+
const line = lines[index];
|
|
82
|
+
if (line) {
|
|
83
|
+
map.set(cart.keyOf(item), line);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return map;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return { calculation, pending, refresh, lineAt, linesByKey };
|
|
90
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-selection state for cart positions (by lineKey). Drives the
|
|
3
|
+
* three-state header checkbox and the bulk action bar.
|
|
4
|
+
*/
|
|
5
|
+
export function useCartSelection() {
|
|
6
|
+
const cart = useCartStore();
|
|
7
|
+
const selected = useState<string[]>("cart-selection", () => []);
|
|
8
|
+
|
|
9
|
+
const selectedSet = computed(() => new Set(selected.value));
|
|
10
|
+
|
|
11
|
+
const allKeys = computed(() => cart.items.map(item => cart.keyOf(item)));
|
|
12
|
+
|
|
13
|
+
const allSelected = computed(() =>
|
|
14
|
+
allKeys.value.length > 0 && allKeys.value.every(key => selectedSet.value.has(key)),
|
|
15
|
+
);
|
|
16
|
+
const someSelected = computed(() => selected.value.length > 0 && !allSelected.value);
|
|
17
|
+
|
|
18
|
+
function isSelected(lineKey: string): boolean {
|
|
19
|
+
return selectedSet.value.has(lineKey);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function toggle(lineKey: string): void {
|
|
23
|
+
selected.value = isSelected(lineKey)
|
|
24
|
+
? selected.value.filter(key => key !== lineKey)
|
|
25
|
+
: [...selected.value, lineKey];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Header checkbox: unchecked/intermediate → select all; checked → none. */
|
|
29
|
+
function toggleAll(): void {
|
|
30
|
+
selected.value = allSelected.value ? [] : [...allKeys.value];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function clear(): void {
|
|
34
|
+
selected.value = [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Drops selections whose positions left the cart. */
|
|
38
|
+
function prune(): void {
|
|
39
|
+
const keys = new Set(allKeys.value);
|
|
40
|
+
if (selected.value.some(key => !keys.has(key))) {
|
|
41
|
+
selected.value = selected.value.filter(key => keys.has(key));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return { selected, allSelected, someSelected, isSelected, toggle, toggleAll, clear, prune };
|
|
46
|
+
}
|