UNPKG

@xo-union/tk-component-header-nav

Version:
37 lines 1.55 kB
import _Set from "@babel/runtime-corejs3/core-js/set"; const AUTO_FILLED_IN_PAGES = new _Set(['your-favorites', 'wedding-vendor-manager', 'paper']); const NO_HREF_IN_PAGES = AUTO_FILLED_IN_PAGES; const NO_RENDER_IN_PAGES_UNLESS_OPTED_IN = new _Set(['marketplace', 'review-wedding-vendors', 'inbox']); const PAPER_SLUG = 'paper'; const DEFAULT_LINK_KEY = 'YOUR_FAVORITES_INSPIRATION'; const targetLinkForProduct = { vendors: 'VENDOR_MANAGER', paper: 'PAPER_FAVORITES' }; const getHref = (isPaperPage, _ref, links, linkKey) => { let [currentPageSlug, lastCurrentPageSlug] = _ref; if (isPaperPage && !AUTO_FILLED_IN_PAGES.has(lastCurrentPageSlug)) { return links[linkKey]; } return NO_HREF_IN_PAGES.has(currentPageSlug) ? null : links[linkKey]; }; export const getDefaultFavoritesConfig = _ref2 => { let { activeProduct, links, explicitlyOptedIn, location } = _ref2; const pathname = (location === null || location === void 0 ? void 0 : location.pathname) ?? ''; const [, currentPageSlug, lastCurrentPageSlug] = pathname.split('/', 3); const isPaperPage = currentPageSlug === PAPER_SLUG; if (NO_RENDER_IN_PAGES_UNLESS_OPTED_IN.has(currentPageSlug) && !explicitlyOptedIn) { return false; } const linkKey = targetLinkForProduct[activeProduct] ?? DEFAULT_LINK_KEY; const href = getHref(isPaperPage, [currentPageSlug, lastCurrentPageSlug], links, linkKey); return { isFilled: isPaperPage ? AUTO_FILLED_IN_PAGES.has(lastCurrentPageSlug) : AUTO_FILLED_IN_PAGES.has(currentPageSlug), href }; };