@getlupa/client 1.7.0 → 1.8.0-alpha.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.
@@ -81,11 +81,11 @@ const hyphenateRE = /\B([A-Z])/g;
81
81
  const hyphenate = cacheStringFunction(
82
82
  (str) => str.replace(hyphenateRE, "-$1").toLowerCase()
83
83
  );
84
- const capitalize$1 = cacheStringFunction(
84
+ const capitalize$2 = cacheStringFunction(
85
85
  (str) => str.charAt(0).toUpperCase() + str.slice(1)
86
86
  );
87
87
  const toHandlerKey = cacheStringFunction(
88
- (str) => str ? `on${capitalize$1(str)}` : ``
88
+ (str) => str ? `on${capitalize$2(str)}` : ``
89
89
  );
90
90
  const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
91
91
  const invokeArrayFns = (fns, arg) => {
@@ -2115,7 +2115,7 @@ function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false
2115
2115
  false
2116
2116
  /* do not include inferred name to avoid breaking existing code */
2117
2117
  );
2118
- if (selfName && (selfName === name || selfName === camelize(name) || selfName === capitalize$1(camelize(name)))) {
2118
+ if (selfName && (selfName === name || selfName === camelize(name) || selfName === capitalize$2(camelize(name)))) {
2119
2119
  return Component;
2120
2120
  }
2121
2121
  }
@@ -2132,7 +2132,7 @@ function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false
2132
2132
  }
2133
2133
  }
2134
2134
  function resolve(registry, name) {
2135
- return registry && (registry[name] || registry[camelize(name)] || registry[capitalize$1(camelize(name))]);
2135
+ return registry && (registry[name] || registry[camelize(name)] || registry[capitalize$2(camelize(name))]);
2136
2136
  }
2137
2137
  function renderList(source, renderItem, cache, index) {
2138
2138
  let ret;
@@ -5378,7 +5378,7 @@ function autoPrefix(style, rawName) {
5378
5378
  if (name !== "filter" && name in style) {
5379
5379
  return prefixCache[rawName] = name;
5380
5380
  }
5381
- name = capitalize$1(name);
5381
+ name = capitalize$2(name);
5382
5382
  for (let i = 0; i < prefixes.length; i++) {
5383
5383
  const prefixed = prefixes[i] + name;
5384
5384
  if (prefixed in style) {
@@ -6324,7 +6324,7 @@ const getNormalizedString = (str) => {
6324
6324
  const transformedStr = typeof str === "string" ? str : str.toString();
6325
6325
  return transformedStr.normalize === void 0 ? transformedStr.toLocaleLowerCase() : transformedStr.toLocaleLowerCase().normalize("NFKD").replace(/[^\w\s.-_/]/g, "");
6326
6326
  };
6327
- const capitalize = (str) => {
6327
+ const capitalize$1 = (str) => {
6328
6328
  if (!str) {
6329
6329
  return "";
6330
6330
  }
@@ -6373,7 +6373,7 @@ const normalizeFloat = (value) => {
6373
6373
  }
6374
6374
  return +((_a = value == null ? void 0 : value.replace(/[^0-9,.]/g, "")) == null ? void 0 : _a.replace(",", "."));
6375
6375
  };
6376
- const escapeHtml = (value) => {
6376
+ const escapeHtml$1 = (value) => {
6377
6377
  if (!value) {
6378
6378
  return "";
6379
6379
  }
@@ -7062,7 +7062,7 @@ const getLabeledFilters = (filters, facets) => {
7062
7062
  return filters.map((f2) => {
7063
7063
  var _a, _b;
7064
7064
  return __spreadProps2(__spreadValues2({}, f2), {
7065
- label: (_b = (_a = facets == null ? void 0 : facets.find((ft) => ft.key === f2.key)) == null ? void 0 : _a.label) != null ? _b : capitalize(f2.key)
7065
+ label: (_b = (_a = facets == null ? void 0 : facets.find((ft) => ft.key === f2.key)) == null ? void 0 : _a.label) != null ? _b : capitalize$1(f2.key)
7066
7066
  });
7067
7067
  });
7068
7068
  };
@@ -7107,9 +7107,9 @@ const pick = (obj, keys) => {
7107
7107
  const getHint = (suggestion, inputValue) => {
7108
7108
  var _a;
7109
7109
  if (!inputValue) {
7110
- return escapeHtml(suggestion);
7110
+ return escapeHtml$1(suggestion);
7111
7111
  }
7112
- return (_a = suggestion == null ? void 0 : suggestion.replace(inputValue, `<strong>${escapeHtml(inputValue)}</strong>`)) != null ? _a : "";
7112
+ return (_a = suggestion == null ? void 0 : suggestion.replace(inputValue, `<strong>${escapeHtml$1(inputValue)}</strong>`)) != null ? _a : "";
7113
7113
  };
7114
7114
  const reverseKeyValue = (obj) => {
7115
7115
  return Object.fromEntries(Object.entries(obj).map(([k, v]) => [v, k.toLowerCase()]));
@@ -13691,7 +13691,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
13691
13691
  return (_b = (_a = props.labels.similarQuery) == null ? void 0 : _a.replace("{1}", "")) != null ? _b : "";
13692
13692
  });
13693
13693
  const getSimilarQueryContent = (displayQuery) => {
13694
- return escapeHtml(displayQuery);
13694
+ return escapeHtml$1(displayQuery);
13695
13695
  };
13696
13696
  const goToResults = ({
13697
13697
  searchText,
@@ -27421,6 +27421,328 @@ const attatchShadowDom = ({
27421
27421
  shadow.appendChild(style);
27422
27422
  }
27423
27423
  };
27424
+ const displayDiscountedPriceSection = (doc2, options) => {
27425
+ var _a, _b;
27426
+ const discountPrice = doc2[(_a = options.fields.discountPriceKey) != null ? _a : ""];
27427
+ const regularPrice = doc2[(_b = options.fields.regularPriceKey) != null ? _b : ""];
27428
+ return discountPrice && regularPrice && discountPrice < regularPrice;
27429
+ };
27430
+ const displayRegularPriceSection = (doc2, options) => {
27431
+ var _a, _b;
27432
+ const discountPrice = doc2[(_a = options.fields.discountPriceKey) != null ? _a : ""];
27433
+ const regularPrice = doc2[(_b = options.fields.regularPriceKey) != null ? _b : ""];
27434
+ const anyPrice = discountPrice || regularPrice;
27435
+ return anyPrice && !displayDiscountedPriceSection(doc2, options);
27436
+ };
27437
+ const escapeHtml = (source) => {
27438
+ if (!source) {
27439
+ return source;
27440
+ }
27441
+ return `${source}`.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
27442
+ };
27443
+ const toMaxDecimalPlaces = (value, maxDecimal = 2) => {
27444
+ if (!value) {
27445
+ return 0;
27446
+ }
27447
+ try {
27448
+ return +parseFloat(`${value}`).toFixed(maxDecimal);
27449
+ } catch (e) {
27450
+ return `${value}`;
27451
+ }
27452
+ };
27453
+ const capitalize = (value) => {
27454
+ if (!value) {
27455
+ return "";
27456
+ }
27457
+ return value.charAt(0).toLocaleUpperCase() + value.slice(1);
27458
+ };
27459
+ const getAlphanumeric = (value) => {
27460
+ if (!value) {
27461
+ return "";
27462
+ }
27463
+ return value.replace(/[\W_]/g, " ");
27464
+ };
27465
+ const getAdditionalElements = (fields) => {
27466
+ return fields.map((key) => ({
27467
+ type: "custom",
27468
+ key,
27469
+ label: capitalize(getAlphanumeric(key)),
27470
+ className: "lupa-custom",
27471
+ display: (doc2) => Boolean(doc2[key])
27472
+ }));
27473
+ };
27474
+ const addFieldIfKeyExists = (field, key, config) => {
27475
+ if (key) {
27476
+ return config;
27477
+ }
27478
+ return { key: field, type: "customHtml", display: () => false };
27479
+ };
27480
+ const getSearchBoxComponent = ({
27481
+ searchBoxOptions,
27482
+ labels,
27483
+ panelOptions,
27484
+ redirections,
27485
+ placeholderImage
27486
+ }) => {
27487
+ var _a, _b;
27488
+ const panels = [
27489
+ ...(panelOptions == null ? void 0 : panelOptions.suggestionPanel) ? [
27490
+ {
27491
+ type: SearchBoxPanelType.SUGGESTION,
27492
+ queryKey: searchBoxOptions.suggestionQueryKey,
27493
+ highlight: true,
27494
+ limit: 8,
27495
+ labels: {
27496
+ topResultsTitle: labels.searchBox.topSuggestionsTitle
27497
+ }
27498
+ }
27499
+ ] : [],
27500
+ ...(panelOptions == null ? void 0 : panelOptions.docPanel) ? [
27501
+ {
27502
+ type: SearchBoxPanelType.DOCUMENT,
27503
+ queryKey: searchBoxOptions.documentQueryKey,
27504
+ limit: 5,
27505
+ elements: [
27506
+ {
27507
+ type: "image",
27508
+ placeholder: placeholderImage,
27509
+ key: searchBoxOptions.fields.imageKey,
27510
+ baseUrl: searchBoxOptions.fields.baseImageUrl
27511
+ },
27512
+ {
27513
+ type: "title",
27514
+ key: searchBoxOptions.fields.titleKey,
27515
+ maxLines: 2
27516
+ },
27517
+ {
27518
+ type: "regularPrice",
27519
+ key: searchBoxOptions.fields.regularPriceKey,
27520
+ display: (doc2) => searchBoxOptions.fields.regularPriceKey && searchBoxOptions.fields.discountPriceKey && parseFloat(doc2[searchBoxOptions.fields.regularPriceKey]) > parseFloat(doc2[searchBoxOptions.fields.discountPriceKey])
27521
+ },
27522
+ {
27523
+ type: "price",
27524
+ key: searchBoxOptions.fields.discountPriceKey
27525
+ }
27526
+ ]
27527
+ }
27528
+ ] : []
27529
+ ];
27530
+ return {
27531
+ inputSelector: searchBoxOptions.inputSelector,
27532
+ options: {
27533
+ environment: (_a = searchBoxOptions.environment) != null ? _a : "production",
27534
+ customUrl: searchBoxOptions.customUrl,
27535
+ customBaseUrl: searchBoxOptions.customBaseUrl,
27536
+ customPayload: searchBoxOptions.customPayload,
27537
+ customHeaders: searchBoxOptions.customHeaders
27538
+ },
27539
+ showTotalCount: true,
27540
+ expandOnSinglePanel: true,
27541
+ minInputLength: (_b = searchBoxOptions.fields.minInputLength) != null ? _b : 0,
27542
+ debounce: 250,
27543
+ labels: labels.searchBox,
27544
+ links: {
27545
+ searchResults: ""
27546
+ },
27547
+ panels,
27548
+ redirections,
27549
+ history: {
27550
+ labels: {
27551
+ clear: labels.searchBox.clearHistory
27552
+ }
27553
+ }
27554
+ };
27555
+ };
27556
+ const getSearchResultsComponent = ({
27557
+ searchResultOptions,
27558
+ labels,
27559
+ redirections,
27560
+ placeholderImage,
27561
+ configuratorOverrides,
27562
+ callbacks,
27563
+ additionalFields
27564
+ }) => {
27565
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
27566
+ const filters = searchResultOptions.showFacets ? {
27567
+ currentFilters: {
27568
+ visibility: {
27569
+ mobileSidebar: true,
27570
+ mobileToolbar: true
27571
+ },
27572
+ labels: {
27573
+ title: "",
27574
+ clearAll: (_a = labels.facets) == null ? void 0 : _a.clearAll
27575
+ }
27576
+ },
27577
+ facets: {
27578
+ labels: {
27579
+ title: labels.facets.facetTitle,
27580
+ showAll: labels.facets.showAll,
27581
+ facetFilter: labels.facets.facetFilter,
27582
+ facetClear: labels.facets.facetClear
27583
+ },
27584
+ filterable: {
27585
+ minValues: 5
27586
+ },
27587
+ hierarchy: {
27588
+ maxInitialLevel: 2,
27589
+ topLevelValueCountLimit: 5,
27590
+ filterable: true
27591
+ },
27592
+ stats: {
27593
+ slider: true,
27594
+ inputs: true,
27595
+ labels: {
27596
+ from: "",
27597
+ to: ""
27598
+ }
27599
+ },
27600
+ facetValueCountLimit: 8,
27601
+ showDocumentCount: true,
27602
+ style: {
27603
+ type: "sidebar"
27604
+ }
27605
+ }
27606
+ } : {};
27607
+ const columns = (_g = searchResultOptions.gridConfiguration) != null ? _g : {
27608
+ xl: (_b = searchResultOptions.maxColumns) != null ? _b : 4,
27609
+ l: (_c = searchResultOptions.maxColumns) != null ? _c : 3,
27610
+ md: (_d = searchResultOptions.maxColumns) != null ? _d : 3,
27611
+ sm: (_e = searchResultOptions.maxColumns) != null ? _e : 2,
27612
+ xs: (_f = searchResultOptions.maxColumns) != null ? _f : 1
27613
+ };
27614
+ const badges = searchResultOptions.showRelevance ? {
27615
+ badges: {
27616
+ anchor: "tr",
27617
+ elements: [
27618
+ {
27619
+ key: "",
27620
+ type: "customHtml",
27621
+ className: "relevance",
27622
+ html: (doc2) => `${toMaxDecimalPlaces(escapeHtml(doc2._relevance), 3)}`,
27623
+ display: (doc2) => Boolean(doc2._relevance !== void 0)
27624
+ }
27625
+ ]
27626
+ }
27627
+ } : {};
27628
+ return __spreadValues(__spreadProps(__spreadValues({
27629
+ options: {
27630
+ environment: (_h = searchResultOptions.environment) != null ? _h : "production",
27631
+ customUrl: searchResultOptions.customUrl,
27632
+ customBaseUrl: searchResultOptions.customBaseUrl,
27633
+ customPayload: searchResultOptions.customPayload,
27634
+ customHeaders: searchResultOptions.customHeaders,
27635
+ onError: searchResultOptions.errorHandler
27636
+ },
27637
+ queryKey: searchResultOptions.queryKey,
27638
+ containerSelector: searchResultOptions.containerSelector,
27639
+ searchTitlePosition: "search-results-top",
27640
+ titleKey: searchResultOptions.fields.titleKey,
27641
+ labels: labels.searchResults,
27642
+ grid: {
27643
+ columns
27644
+ },
27645
+ pagination: {
27646
+ sizeSelection: {
27647
+ position: {
27648
+ top: true,
27649
+ bottom: false
27650
+ },
27651
+ sizes: [12, 24, 36, 48]
27652
+ },
27653
+ pageSelection: {
27654
+ position: {
27655
+ top: false,
27656
+ bottom: true
27657
+ },
27658
+ displayMobile: 3,
27659
+ display: 5
27660
+ }
27661
+ },
27662
+ filters,
27663
+ toolbar: {
27664
+ layoutSelector: false,
27665
+ itemSummary: true,
27666
+ clearFilters: false
27667
+ },
27668
+ isInStock: () => {
27669
+ return true;
27670
+ }
27671
+ }, badges), {
27672
+ links: {
27673
+ details: searchResultOptions.fields.productUrl ? `{${searchResultOptions.fields.productUrl}}` : void 0
27674
+ },
27675
+ callbacks,
27676
+ routingBehavior: callbacks ? "event" : "direct-link",
27677
+ idKey: "id",
27678
+ elements: [
27679
+ {
27680
+ type: "image",
27681
+ placeholder: placeholderImage,
27682
+ key: searchResultOptions.fields.imageKey,
27683
+ baseUrl: searchResultOptions.fields.baseImageUrl,
27684
+ display: () => searchResultOptions.fields.imageKey
27685
+ },
27686
+ addFieldIfKeyExists("_emphasis", (_i = searchResultOptions.fields) == null ? void 0 : _i.emphasizedField, {
27687
+ type: "custom",
27688
+ className: "lupa-custom-emphasis",
27689
+ key: searchResultOptions.fields.emphasizedField,
27690
+ display: () => true
27691
+ }),
27692
+ {
27693
+ type: "title",
27694
+ key: searchResultOptions.fields.titleKey,
27695
+ maxLines: (_j = searchResultOptions.maxLines) != null ? _j : 2,
27696
+ display: (doc2) => searchResultOptions.fields.titleKey && Boolean(doc2[searchResultOptions.fields.titleKey])
27697
+ },
27698
+ ...getAdditionalElements(additionalFields),
27699
+ addFieldIfKeyExists("_discountPrice", searchResultOptions.fields.discountPriceKey, {
27700
+ key: searchResultOptions.fields.discountPriceKey,
27701
+ type: "customHtml",
27702
+ className: "lupa-price lupa-price-discounted",
27703
+ display: (doc2) => displayDiscountedPriceSection(doc2, searchResultOptions),
27704
+ html: (doc2) => {
27705
+ var _a2, _b2, _c2, _d2;
27706
+ const currency = escapeHtml(searchResultOptions.fields.currency || "€");
27707
+ const discountPrice = (_b2 = parseFloat(
27708
+ doc2[(_a2 = searchResultOptions.fields.discountPriceKey) != null ? _a2 : ""]
27709
+ )) == null ? void 0 : _b2.toFixed(2);
27710
+ const regularPrice = (_d2 = parseFloat(
27711
+ doc2[(_c2 = searchResultOptions.fields.regularPriceKey) != null ? _c2 : ""]
27712
+ )) == null ? void 0 : _d2.toFixed(2);
27713
+ const discount = `<span class="lupa-discount">${escapeHtml(
27714
+ discountPrice
27715
+ )} ${currency}</span>`;
27716
+ const regular = `<span class="lupa-regular">${escapeHtml(
27717
+ regularPrice
27718
+ )} ${currency}</span>`;
27719
+ return discount + regular;
27720
+ }
27721
+ }),
27722
+ addFieldIfKeyExists("_regularPrice", searchResultOptions.fields.regularPriceKey, {
27723
+ key: searchResultOptions.fields.regularPriceKey,
27724
+ type: "customHtml",
27725
+ className: "lupa-price lupa-price-single",
27726
+ display: (doc2) => displayRegularPriceSection(doc2, searchResultOptions),
27727
+ html: (doc2) => {
27728
+ var _a2, _b2, _c2, _d2;
27729
+ const currency = escapeHtml(searchResultOptions.fields.currency || "€");
27730
+ const price = (_d2 = parseFloat(
27731
+ (_c2 = doc2[(_a2 = searchResultOptions.fields.regularPriceKey) != null ? _a2 : ""]) != null ? _c2 : doc2[(_b2 = searchResultOptions.fields.discountPriceKey) != null ? _b2 : ""]
27732
+ )) == null ? void 0 : _d2.toFixed(2);
27733
+ return `<span class="lupa-final">${escapeHtml(price)} ${currency}</span>`;
27734
+ }
27735
+ })
27736
+ ],
27737
+ breadcrumbs: [],
27738
+ sort: [],
27739
+ redirections
27740
+ }), configuratorOverrides);
27741
+ };
27742
+ const SearchContainerConfigurationService = {
27743
+ getSearchBoxComponent,
27744
+ getSearchResultsComponent
27745
+ };
27424
27746
  const app = {
27425
27747
  box: {},
27426
27748
  results: {},
@@ -27555,6 +27877,23 @@ const searchContainer = (options, mountOptions) => {
27555
27877
  }
27556
27878
  app.searchContainer[options.trigger] = instance;
27557
27879
  };
27880
+ const preconfiguredSearchContainer = (preconfiguredSearchContainerOptions, mountOptions) => {
27881
+ const searchBox2 = SearchContainerConfigurationService.getSearchBoxComponent(
27882
+ preconfiguredSearchContainerOptions
27883
+ );
27884
+ const searchResults2 = SearchContainerConfigurationService.getSearchResultsComponent(
27885
+ preconfiguredSearchContainerOptions
27886
+ );
27887
+ searchContainer(
27888
+ {
27889
+ trigger: preconfiguredSearchContainerOptions.trigger,
27890
+ searchBox: searchBox2,
27891
+ searchResults: searchResults2,
27892
+ options: preconfiguredSearchContainerOptions.configuration
27893
+ },
27894
+ mountOptions
27895
+ );
27896
+ };
27558
27897
  const recommendations = (options, mountOptions) => {
27559
27898
  const existingInstance = app.recommendations[options.containerSelector];
27560
27899
  if (existingInstance) {
@@ -27692,7 +28031,10 @@ const lupaSearch = {
27692
28031
  clearSearchContainer,
27693
28032
  clearRecommendations,
27694
28033
  chat,
27695
- clearChat
28034
+ clearChat,
28035
+ preconfiguredSearchContainer,
28036
+ getSearchBoxComponent: SearchContainerConfigurationService.getSearchBoxComponent,
28037
+ getSearchResultsComponent: SearchContainerConfigurationService.getSearchResultsComponent
27696
28038
  };
27697
28039
  if (typeof window !== "undefined") {
27698
28040
  window.getLupa = lupaSearch;