@getlupa/client 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lupaSearch.iife.js +354 -12
- package/dist/lupaSearch.js +354 -12
- package/dist/lupaSearch.mjs +354 -12
- package/dist/lupaSearch.umd.js +354 -12
- package/dist/src/index.d.ts +11 -1
- package/dist/src/modules/preconfiguredContainer/SearchContainerConfigurationService.d.ts +7 -0
- package/dist/src/modules/preconfiguredContainer/configuratorUtils.d.ts +15 -0
- package/dist/src/types/PreconfiguredSearchContainerOptions.d.ts +57 -0
- package/package.json +1 -1
package/dist/lupaSearch.umd.js
CHANGED
|
@@ -83,11 +83,11 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
83
83
|
const hyphenate = cacheStringFunction(
|
|
84
84
|
(str) => str.replace(hyphenateRE, "-$1").toLowerCase()
|
|
85
85
|
);
|
|
86
|
-
const capitalize$
|
|
86
|
+
const capitalize$2 = cacheStringFunction(
|
|
87
87
|
(str) => str.charAt(0).toUpperCase() + str.slice(1)
|
|
88
88
|
);
|
|
89
89
|
const toHandlerKey = cacheStringFunction(
|
|
90
|
-
(str) => str ? `on${capitalize$
|
|
90
|
+
(str) => str ? `on${capitalize$2(str)}` : ``
|
|
91
91
|
);
|
|
92
92
|
const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
|
|
93
93
|
const invokeArrayFns = (fns, arg) => {
|
|
@@ -2117,7 +2117,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
2117
2117
|
false
|
|
2118
2118
|
/* do not include inferred name to avoid breaking existing code */
|
|
2119
2119
|
);
|
|
2120
|
-
if (selfName && (selfName === name || selfName === camelize(name) || selfName === capitalize$
|
|
2120
|
+
if (selfName && (selfName === name || selfName === camelize(name) || selfName === capitalize$2(camelize(name)))) {
|
|
2121
2121
|
return Component;
|
|
2122
2122
|
}
|
|
2123
2123
|
}
|
|
@@ -2134,7 +2134,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
2134
2134
|
}
|
|
2135
2135
|
}
|
|
2136
2136
|
function resolve(registry, name) {
|
|
2137
|
-
return registry && (registry[name] || registry[camelize(name)] || registry[capitalize$
|
|
2137
|
+
return registry && (registry[name] || registry[camelize(name)] || registry[capitalize$2(camelize(name))]);
|
|
2138
2138
|
}
|
|
2139
2139
|
function renderList(source, renderItem, cache, index) {
|
|
2140
2140
|
let ret;
|
|
@@ -5380,7 +5380,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
5380
5380
|
if (name !== "filter" && name in style) {
|
|
5381
5381
|
return prefixCache[rawName] = name;
|
|
5382
5382
|
}
|
|
5383
|
-
name = capitalize$
|
|
5383
|
+
name = capitalize$2(name);
|
|
5384
5384
|
for (let i = 0; i < prefixes.length; i++) {
|
|
5385
5385
|
const prefixed = prefixes[i] + name;
|
|
5386
5386
|
if (prefixed in style) {
|
|
@@ -6326,7 +6326,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
6326
6326
|
const transformedStr = typeof str === "string" ? str : str.toString();
|
|
6327
6327
|
return transformedStr.normalize === void 0 ? transformedStr.toLocaleLowerCase() : transformedStr.toLocaleLowerCase().normalize("NFKD").replace(/[^\w\s.-_/]/g, "");
|
|
6328
6328
|
};
|
|
6329
|
-
const capitalize = (str) => {
|
|
6329
|
+
const capitalize$1 = (str) => {
|
|
6330
6330
|
if (!str) {
|
|
6331
6331
|
return "";
|
|
6332
6332
|
}
|
|
@@ -6375,7 +6375,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
6375
6375
|
}
|
|
6376
6376
|
return +((_a = value == null ? void 0 : value.replace(/[^0-9,.]/g, "")) == null ? void 0 : _a.replace(",", "."));
|
|
6377
6377
|
};
|
|
6378
|
-
const escapeHtml = (value) => {
|
|
6378
|
+
const escapeHtml$1 = (value) => {
|
|
6379
6379
|
if (!value) {
|
|
6380
6380
|
return "";
|
|
6381
6381
|
}
|
|
@@ -7064,7 +7064,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
7064
7064
|
return filters.map((f2) => {
|
|
7065
7065
|
var _a, _b;
|
|
7066
7066
|
return __spreadProps2(__spreadValues2({}, f2), {
|
|
7067
|
-
label: (_b = (_a = facets == null ? void 0 : facets.find((ft) => ft.key === f2.key)) == null ? void 0 : _a.label) != null ? _b : capitalize(f2.key)
|
|
7067
|
+
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)
|
|
7068
7068
|
});
|
|
7069
7069
|
});
|
|
7070
7070
|
};
|
|
@@ -7109,9 +7109,9 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
7109
7109
|
const getHint = (suggestion, inputValue) => {
|
|
7110
7110
|
var _a;
|
|
7111
7111
|
if (!inputValue) {
|
|
7112
|
-
return escapeHtml(suggestion);
|
|
7112
|
+
return escapeHtml$1(suggestion);
|
|
7113
7113
|
}
|
|
7114
|
-
return (_a = suggestion == null ? void 0 : suggestion.replace(inputValue, `<strong>${escapeHtml(inputValue)}</strong>`)) != null ? _a : "";
|
|
7114
|
+
return (_a = suggestion == null ? void 0 : suggestion.replace(inputValue, `<strong>${escapeHtml$1(inputValue)}</strong>`)) != null ? _a : "";
|
|
7115
7115
|
};
|
|
7116
7116
|
const reverseKeyValue = (obj) => {
|
|
7117
7117
|
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [v, k.toLowerCase()]));
|
|
@@ -13693,7 +13693,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
13693
13693
|
return (_b = (_a = props.labels.similarQuery) == null ? void 0 : _a.replace("{1}", "")) != null ? _b : "";
|
|
13694
13694
|
});
|
|
13695
13695
|
const getSimilarQueryContent = (displayQuery) => {
|
|
13696
|
-
return escapeHtml(displayQuery);
|
|
13696
|
+
return escapeHtml$1(displayQuery);
|
|
13697
13697
|
};
|
|
13698
13698
|
const goToResults = ({
|
|
13699
13699
|
searchText,
|
|
@@ -27423,6 +27423,328 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
27423
27423
|
shadow.appendChild(style);
|
|
27424
27424
|
}
|
|
27425
27425
|
};
|
|
27426
|
+
const displayDiscountedPriceSection = (doc2, options) => {
|
|
27427
|
+
var _a, _b;
|
|
27428
|
+
const discountPrice = doc2[(_a = options.fields.discountPriceKey) != null ? _a : ""];
|
|
27429
|
+
const regularPrice = doc2[(_b = options.fields.regularPriceKey) != null ? _b : ""];
|
|
27430
|
+
return discountPrice && regularPrice && discountPrice < regularPrice;
|
|
27431
|
+
};
|
|
27432
|
+
const displayRegularPriceSection = (doc2, options) => {
|
|
27433
|
+
var _a, _b;
|
|
27434
|
+
const discountPrice = doc2[(_a = options.fields.discountPriceKey) != null ? _a : ""];
|
|
27435
|
+
const regularPrice = doc2[(_b = options.fields.regularPriceKey) != null ? _b : ""];
|
|
27436
|
+
const anyPrice = discountPrice || regularPrice;
|
|
27437
|
+
return anyPrice && !displayDiscountedPriceSection(doc2, options);
|
|
27438
|
+
};
|
|
27439
|
+
const escapeHtml = (source) => {
|
|
27440
|
+
if (!source) {
|
|
27441
|
+
return source;
|
|
27442
|
+
}
|
|
27443
|
+
return `${source}`.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
27444
|
+
};
|
|
27445
|
+
const toMaxDecimalPlaces = (value, maxDecimal = 2) => {
|
|
27446
|
+
if (!value) {
|
|
27447
|
+
return 0;
|
|
27448
|
+
}
|
|
27449
|
+
try {
|
|
27450
|
+
return +parseFloat(`${value}`).toFixed(maxDecimal);
|
|
27451
|
+
} catch (e) {
|
|
27452
|
+
return `${value}`;
|
|
27453
|
+
}
|
|
27454
|
+
};
|
|
27455
|
+
const capitalize = (value) => {
|
|
27456
|
+
if (!value) {
|
|
27457
|
+
return "";
|
|
27458
|
+
}
|
|
27459
|
+
return value.charAt(0).toLocaleUpperCase() + value.slice(1);
|
|
27460
|
+
};
|
|
27461
|
+
const getAlphanumeric = (value) => {
|
|
27462
|
+
if (!value) {
|
|
27463
|
+
return "";
|
|
27464
|
+
}
|
|
27465
|
+
return value.replace(/[\W_]/g, " ");
|
|
27466
|
+
};
|
|
27467
|
+
const getAdditionalElements = (fields) => {
|
|
27468
|
+
return fields.map((key) => ({
|
|
27469
|
+
type: "custom",
|
|
27470
|
+
key,
|
|
27471
|
+
label: capitalize(getAlphanumeric(key)),
|
|
27472
|
+
className: "lupa-custom",
|
|
27473
|
+
display: (doc2) => Boolean(doc2[key])
|
|
27474
|
+
}));
|
|
27475
|
+
};
|
|
27476
|
+
const addFieldIfKeyExists = (field, key, config) => {
|
|
27477
|
+
if (key) {
|
|
27478
|
+
return config;
|
|
27479
|
+
}
|
|
27480
|
+
return { key: field, type: "customHtml", display: () => false };
|
|
27481
|
+
};
|
|
27482
|
+
const getSearchBoxComponent = ({
|
|
27483
|
+
searchBoxOptions,
|
|
27484
|
+
labels,
|
|
27485
|
+
panelOptions,
|
|
27486
|
+
redirections,
|
|
27487
|
+
placeholderImage
|
|
27488
|
+
}) => {
|
|
27489
|
+
var _a, _b;
|
|
27490
|
+
const panels = [
|
|
27491
|
+
...(panelOptions == null ? void 0 : panelOptions.suggestionPanel) ? [
|
|
27492
|
+
{
|
|
27493
|
+
type: SearchBoxPanelType.SUGGESTION,
|
|
27494
|
+
queryKey: searchBoxOptions.suggestionQueryKey,
|
|
27495
|
+
highlight: true,
|
|
27496
|
+
limit: 8,
|
|
27497
|
+
labels: {
|
|
27498
|
+
topResultsTitle: labels.searchBox.topSuggestionsTitle
|
|
27499
|
+
}
|
|
27500
|
+
}
|
|
27501
|
+
] : [],
|
|
27502
|
+
...(panelOptions == null ? void 0 : panelOptions.docPanel) ? [
|
|
27503
|
+
{
|
|
27504
|
+
type: SearchBoxPanelType.DOCUMENT,
|
|
27505
|
+
queryKey: searchBoxOptions.documentQueryKey,
|
|
27506
|
+
limit: 5,
|
|
27507
|
+
elements: [
|
|
27508
|
+
{
|
|
27509
|
+
type: "image",
|
|
27510
|
+
placeholder: placeholderImage,
|
|
27511
|
+
key: searchBoxOptions.fields.imageKey,
|
|
27512
|
+
baseUrl: searchBoxOptions.fields.baseImageUrl
|
|
27513
|
+
},
|
|
27514
|
+
{
|
|
27515
|
+
type: "title",
|
|
27516
|
+
key: searchBoxOptions.fields.titleKey,
|
|
27517
|
+
maxLines: 2
|
|
27518
|
+
},
|
|
27519
|
+
{
|
|
27520
|
+
type: "regularPrice",
|
|
27521
|
+
key: searchBoxOptions.fields.regularPriceKey,
|
|
27522
|
+
display: (doc2) => searchBoxOptions.fields.regularPriceKey && searchBoxOptions.fields.discountPriceKey && parseFloat(doc2[searchBoxOptions.fields.regularPriceKey]) > parseFloat(doc2[searchBoxOptions.fields.discountPriceKey])
|
|
27523
|
+
},
|
|
27524
|
+
{
|
|
27525
|
+
type: "price",
|
|
27526
|
+
key: searchBoxOptions.fields.discountPriceKey
|
|
27527
|
+
}
|
|
27528
|
+
]
|
|
27529
|
+
}
|
|
27530
|
+
] : []
|
|
27531
|
+
];
|
|
27532
|
+
return {
|
|
27533
|
+
inputSelector: searchBoxOptions.inputSelector,
|
|
27534
|
+
options: {
|
|
27535
|
+
environment: (_a = searchBoxOptions.environment) != null ? _a : "production",
|
|
27536
|
+
customUrl: searchBoxOptions.customUrl,
|
|
27537
|
+
customBaseUrl: searchBoxOptions.customBaseUrl,
|
|
27538
|
+
customPayload: searchBoxOptions.customPayload,
|
|
27539
|
+
customHeaders: searchBoxOptions.customHeaders
|
|
27540
|
+
},
|
|
27541
|
+
showTotalCount: true,
|
|
27542
|
+
expandOnSinglePanel: true,
|
|
27543
|
+
minInputLength: (_b = searchBoxOptions.fields.minInputLength) != null ? _b : 0,
|
|
27544
|
+
debounce: 250,
|
|
27545
|
+
labels: labels.searchBox,
|
|
27546
|
+
links: {
|
|
27547
|
+
searchResults: ""
|
|
27548
|
+
},
|
|
27549
|
+
panels,
|
|
27550
|
+
redirections,
|
|
27551
|
+
history: {
|
|
27552
|
+
labels: {
|
|
27553
|
+
clear: labels.searchBox.clearHistory
|
|
27554
|
+
}
|
|
27555
|
+
}
|
|
27556
|
+
};
|
|
27557
|
+
};
|
|
27558
|
+
const getSearchResultsComponent = ({
|
|
27559
|
+
searchResultOptions,
|
|
27560
|
+
labels,
|
|
27561
|
+
redirections,
|
|
27562
|
+
placeholderImage,
|
|
27563
|
+
configuratorOverrides,
|
|
27564
|
+
callbacks,
|
|
27565
|
+
additionalFields
|
|
27566
|
+
}) => {
|
|
27567
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
27568
|
+
const filters = searchResultOptions.showFacets ? {
|
|
27569
|
+
currentFilters: {
|
|
27570
|
+
visibility: {
|
|
27571
|
+
mobileSidebar: true,
|
|
27572
|
+
mobileToolbar: true
|
|
27573
|
+
},
|
|
27574
|
+
labels: {
|
|
27575
|
+
title: "",
|
|
27576
|
+
clearAll: (_a = labels.facets) == null ? void 0 : _a.clearAll
|
|
27577
|
+
}
|
|
27578
|
+
},
|
|
27579
|
+
facets: {
|
|
27580
|
+
labels: {
|
|
27581
|
+
title: labels.facets.facetTitle,
|
|
27582
|
+
showAll: labels.facets.showAll,
|
|
27583
|
+
facetFilter: labels.facets.facetFilter,
|
|
27584
|
+
facetClear: labels.facets.facetClear
|
|
27585
|
+
},
|
|
27586
|
+
filterable: {
|
|
27587
|
+
minValues: 5
|
|
27588
|
+
},
|
|
27589
|
+
hierarchy: {
|
|
27590
|
+
maxInitialLevel: 2,
|
|
27591
|
+
topLevelValueCountLimit: 5,
|
|
27592
|
+
filterable: true
|
|
27593
|
+
},
|
|
27594
|
+
stats: {
|
|
27595
|
+
slider: true,
|
|
27596
|
+
inputs: true,
|
|
27597
|
+
labels: {
|
|
27598
|
+
from: "",
|
|
27599
|
+
to: ""
|
|
27600
|
+
}
|
|
27601
|
+
},
|
|
27602
|
+
facetValueCountLimit: 8,
|
|
27603
|
+
showDocumentCount: true,
|
|
27604
|
+
style: {
|
|
27605
|
+
type: "sidebar"
|
|
27606
|
+
}
|
|
27607
|
+
}
|
|
27608
|
+
} : {};
|
|
27609
|
+
const columns = (_g = searchResultOptions.gridConfiguration) != null ? _g : {
|
|
27610
|
+
xl: (_b = searchResultOptions.maxColumns) != null ? _b : 4,
|
|
27611
|
+
l: (_c = searchResultOptions.maxColumns) != null ? _c : 3,
|
|
27612
|
+
md: (_d = searchResultOptions.maxColumns) != null ? _d : 3,
|
|
27613
|
+
sm: (_e = searchResultOptions.maxColumns) != null ? _e : 2,
|
|
27614
|
+
xs: (_f = searchResultOptions.maxColumns) != null ? _f : 1
|
|
27615
|
+
};
|
|
27616
|
+
const badges = searchResultOptions.showRelevance ? {
|
|
27617
|
+
badges: {
|
|
27618
|
+
anchor: "tr",
|
|
27619
|
+
elements: [
|
|
27620
|
+
{
|
|
27621
|
+
key: "",
|
|
27622
|
+
type: "customHtml",
|
|
27623
|
+
className: "relevance",
|
|
27624
|
+
html: (doc2) => `${toMaxDecimalPlaces(escapeHtml(doc2._relevance), 3)}`,
|
|
27625
|
+
display: (doc2) => Boolean(doc2._relevance !== void 0)
|
|
27626
|
+
}
|
|
27627
|
+
]
|
|
27628
|
+
}
|
|
27629
|
+
} : {};
|
|
27630
|
+
return __spreadValues(__spreadProps(__spreadValues({
|
|
27631
|
+
options: {
|
|
27632
|
+
environment: (_h = searchResultOptions.environment) != null ? _h : "production",
|
|
27633
|
+
customUrl: searchResultOptions.customUrl,
|
|
27634
|
+
customBaseUrl: searchResultOptions.customBaseUrl,
|
|
27635
|
+
customPayload: searchResultOptions.customPayload,
|
|
27636
|
+
customHeaders: searchResultOptions.customHeaders,
|
|
27637
|
+
onError: searchResultOptions.errorHandler
|
|
27638
|
+
},
|
|
27639
|
+
queryKey: searchResultOptions.queryKey,
|
|
27640
|
+
containerSelector: searchResultOptions.containerSelector,
|
|
27641
|
+
searchTitlePosition: "search-results-top",
|
|
27642
|
+
titleKey: searchResultOptions.fields.titleKey,
|
|
27643
|
+
labels: labels.searchResults,
|
|
27644
|
+
grid: {
|
|
27645
|
+
columns
|
|
27646
|
+
},
|
|
27647
|
+
pagination: {
|
|
27648
|
+
sizeSelection: {
|
|
27649
|
+
position: {
|
|
27650
|
+
top: true,
|
|
27651
|
+
bottom: false
|
|
27652
|
+
},
|
|
27653
|
+
sizes: [12, 24, 36, 48]
|
|
27654
|
+
},
|
|
27655
|
+
pageSelection: {
|
|
27656
|
+
position: {
|
|
27657
|
+
top: false,
|
|
27658
|
+
bottom: true
|
|
27659
|
+
},
|
|
27660
|
+
displayMobile: 3,
|
|
27661
|
+
display: 5
|
|
27662
|
+
}
|
|
27663
|
+
},
|
|
27664
|
+
filters,
|
|
27665
|
+
toolbar: {
|
|
27666
|
+
layoutSelector: false,
|
|
27667
|
+
itemSummary: true,
|
|
27668
|
+
clearFilters: false
|
|
27669
|
+
},
|
|
27670
|
+
isInStock: () => {
|
|
27671
|
+
return true;
|
|
27672
|
+
}
|
|
27673
|
+
}, badges), {
|
|
27674
|
+
links: {
|
|
27675
|
+
details: searchResultOptions.fields.productUrl ? `{${searchResultOptions.fields.productUrl}}` : void 0
|
|
27676
|
+
},
|
|
27677
|
+
callbacks,
|
|
27678
|
+
routingBehavior: callbacks ? "event" : "direct-link",
|
|
27679
|
+
idKey: "id",
|
|
27680
|
+
elements: [
|
|
27681
|
+
{
|
|
27682
|
+
type: "image",
|
|
27683
|
+
placeholder: placeholderImage,
|
|
27684
|
+
key: searchResultOptions.fields.imageKey,
|
|
27685
|
+
baseUrl: searchResultOptions.fields.baseImageUrl,
|
|
27686
|
+
display: () => searchResultOptions.fields.imageKey
|
|
27687
|
+
},
|
|
27688
|
+
addFieldIfKeyExists("_emphasis", (_i = searchResultOptions.fields) == null ? void 0 : _i.emphasizedField, {
|
|
27689
|
+
type: "custom",
|
|
27690
|
+
className: "lupa-custom-emphasis",
|
|
27691
|
+
key: searchResultOptions.fields.emphasizedField,
|
|
27692
|
+
display: () => true
|
|
27693
|
+
}),
|
|
27694
|
+
{
|
|
27695
|
+
type: "title",
|
|
27696
|
+
key: searchResultOptions.fields.titleKey,
|
|
27697
|
+
maxLines: (_j = searchResultOptions.maxLines) != null ? _j : 2,
|
|
27698
|
+
display: (doc2) => searchResultOptions.fields.titleKey && Boolean(doc2[searchResultOptions.fields.titleKey])
|
|
27699
|
+
},
|
|
27700
|
+
...getAdditionalElements(additionalFields),
|
|
27701
|
+
addFieldIfKeyExists("_discountPrice", searchResultOptions.fields.discountPriceKey, {
|
|
27702
|
+
key: searchResultOptions.fields.discountPriceKey,
|
|
27703
|
+
type: "customHtml",
|
|
27704
|
+
className: "lupa-price lupa-price-discounted",
|
|
27705
|
+
display: (doc2) => displayDiscountedPriceSection(doc2, searchResultOptions),
|
|
27706
|
+
html: (doc2) => {
|
|
27707
|
+
var _a2, _b2, _c2, _d2;
|
|
27708
|
+
const currency = escapeHtml(searchResultOptions.fields.currency || "€");
|
|
27709
|
+
const discountPrice = (_b2 = parseFloat(
|
|
27710
|
+
doc2[(_a2 = searchResultOptions.fields.discountPriceKey) != null ? _a2 : ""]
|
|
27711
|
+
)) == null ? void 0 : _b2.toFixed(2);
|
|
27712
|
+
const regularPrice = (_d2 = parseFloat(
|
|
27713
|
+
doc2[(_c2 = searchResultOptions.fields.regularPriceKey) != null ? _c2 : ""]
|
|
27714
|
+
)) == null ? void 0 : _d2.toFixed(2);
|
|
27715
|
+
const discount = `<span class="lupa-discount">${escapeHtml(
|
|
27716
|
+
discountPrice
|
|
27717
|
+
)} ${currency}</span>`;
|
|
27718
|
+
const regular = `<span class="lupa-regular">${escapeHtml(
|
|
27719
|
+
regularPrice
|
|
27720
|
+
)} ${currency}</span>`;
|
|
27721
|
+
return discount + regular;
|
|
27722
|
+
}
|
|
27723
|
+
}),
|
|
27724
|
+
addFieldIfKeyExists("_regularPrice", searchResultOptions.fields.regularPriceKey, {
|
|
27725
|
+
key: searchResultOptions.fields.regularPriceKey,
|
|
27726
|
+
type: "customHtml",
|
|
27727
|
+
className: "lupa-price lupa-price-single",
|
|
27728
|
+
display: (doc2) => displayRegularPriceSection(doc2, searchResultOptions),
|
|
27729
|
+
html: (doc2) => {
|
|
27730
|
+
var _a2, _b2, _c2, _d2;
|
|
27731
|
+
const currency = escapeHtml(searchResultOptions.fields.currency || "€");
|
|
27732
|
+
const price = (_d2 = parseFloat(
|
|
27733
|
+
(_c2 = doc2[(_a2 = searchResultOptions.fields.regularPriceKey) != null ? _a2 : ""]) != null ? _c2 : doc2[(_b2 = searchResultOptions.fields.discountPriceKey) != null ? _b2 : ""]
|
|
27734
|
+
)) == null ? void 0 : _d2.toFixed(2);
|
|
27735
|
+
return `<span class="lupa-final">${escapeHtml(price)} ${currency}</span>`;
|
|
27736
|
+
}
|
|
27737
|
+
})
|
|
27738
|
+
],
|
|
27739
|
+
breadcrumbs: [],
|
|
27740
|
+
sort: [],
|
|
27741
|
+
redirections
|
|
27742
|
+
}), configuratorOverrides);
|
|
27743
|
+
};
|
|
27744
|
+
const SearchContainerConfigurationService = {
|
|
27745
|
+
getSearchBoxComponent,
|
|
27746
|
+
getSearchResultsComponent
|
|
27747
|
+
};
|
|
27426
27748
|
const app = {
|
|
27427
27749
|
box: {},
|
|
27428
27750
|
results: {},
|
|
@@ -27557,6 +27879,23 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
27557
27879
|
}
|
|
27558
27880
|
app.searchContainer[options.trigger] = instance;
|
|
27559
27881
|
};
|
|
27882
|
+
const preconfiguredSearchContainer = (preconfiguredSearchContainerOptions, mountOptions) => {
|
|
27883
|
+
const searchBox2 = SearchContainerConfigurationService.getSearchBoxComponent(
|
|
27884
|
+
preconfiguredSearchContainerOptions
|
|
27885
|
+
);
|
|
27886
|
+
const searchResults2 = SearchContainerConfigurationService.getSearchResultsComponent(
|
|
27887
|
+
preconfiguredSearchContainerOptions
|
|
27888
|
+
);
|
|
27889
|
+
searchContainer(
|
|
27890
|
+
{
|
|
27891
|
+
trigger: preconfiguredSearchContainerOptions.trigger,
|
|
27892
|
+
searchBox: searchBox2,
|
|
27893
|
+
searchResults: searchResults2,
|
|
27894
|
+
options: preconfiguredSearchContainerOptions.configuration
|
|
27895
|
+
},
|
|
27896
|
+
mountOptions
|
|
27897
|
+
);
|
|
27898
|
+
};
|
|
27560
27899
|
const recommendations = (options, mountOptions) => {
|
|
27561
27900
|
const existingInstance = app.recommendations[options.containerSelector];
|
|
27562
27901
|
if (existingInstance) {
|
|
@@ -27694,7 +28033,10 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
27694
28033
|
clearSearchContainer,
|
|
27695
28034
|
clearRecommendations,
|
|
27696
28035
|
chat,
|
|
27697
|
-
clearChat
|
|
28036
|
+
clearChat,
|
|
28037
|
+
preconfiguredSearchContainer,
|
|
28038
|
+
getSearchBoxComponent: SearchContainerConfigurationService.getSearchBoxComponent,
|
|
28039
|
+
getSearchResultsComponent: SearchContainerConfigurationService.getSearchResultsComponent
|
|
27698
28040
|
};
|
|
27699
28041
|
if (typeof window !== "undefined") {
|
|
27700
28042
|
window.getLupa = lupaSearch;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Environment, SdkOptions, SortDirection, TrackingOptions, DocumentElement, ImageDocumentElement, TitleDocumentElement, DescriptionDocumentElement, CustomDocumentElement, PriceElement, RegularPriceDocumentElement, RatingElement, AddToCartElement, CustomHtmlElement, SingleStarRatingElement, ProductListOptions, CategoryFilterOptions, ProductRecommendationOptions, RecommendationABTestingOptions, SearchBoxOptions, SearchContainerOptions, SearchContainerConfigOptions, SearchResultBadgeElement, BadgeGenerateSeed, BadgeGenerateOptions, BadgeOptions, RoutingBehavior, SearchResultsOptions, FacetStyle, SearchResultEventCallbacks, CallbackContext, SortCallbackContext, FacetFilterQuery, SearchResultsFilterOptions, ResultFacetOptions, DynamicData, AnchorPosition, SortOptions, SearchResultsSortOptions, ChatOptions, RedirectionOptions } from '@getlupa/vue';
|
|
2
2
|
import { DocumentElementType, SearchBoxPanelType, BadgeType, SearchResultBadgeType } from '@getlupa/vue';
|
|
3
|
+
import { PreconfiguredSearchContainerOptions, SearchBoxDemoOptions, SearchDemoFields, SearchResultDemoOptions } from './types/PreconfiguredSearchContainerOptions';
|
|
3
4
|
type MountOptions = {
|
|
4
5
|
fetch: boolean;
|
|
5
6
|
};
|
|
@@ -17,9 +18,12 @@ declare const lupaSearch: {
|
|
|
17
18
|
clearRecommendations: (selector?: string) => void;
|
|
18
19
|
chat: (options: ChatOptions, mountOptions?: MountOptions) => void;
|
|
19
20
|
clearChat: (selector?: string) => void;
|
|
21
|
+
preconfiguredSearchContainer: (preconfiguredSearchContainerOptions: PreconfiguredSearchContainerOptions, mountOptions?: MountOptions) => void;
|
|
22
|
+
getSearchBoxComponent: ({ searchBoxOptions, labels, panelOptions, redirections, placeholderImage }: PreconfiguredSearchContainerOptions) => SearchBoxOptions;
|
|
23
|
+
getSearchResultsComponent: ({ searchResultOptions, labels, redirections, placeholderImage, configuratorOverrides, callbacks, additionalFields }: PreconfiguredSearchContainerOptions) => SearchResultsOptions;
|
|
20
24
|
};
|
|
21
25
|
export { DocumentElementType, SearchBoxPanelType, BadgeType };
|
|
22
|
-
export type { TrackingOptions, SearchBoxOptions, SearchResultsOptions, ProductListOptions, SdkOptions, FacetStyle, Environment, RoutingBehavior, AnchorPosition, SortDirection, DocumentElement, ImageDocumentElement, TitleDocumentElement, DescriptionDocumentElement, CustomDocumentElement, PriceElement, RegularPriceDocumentElement, RatingElement, AddToCartElement, CustomHtmlElement, SortOptions, SearchResultsSortOptions, SearchResultEventCallbacks, CallbackContext, SortCallbackContext, FacetFilterQuery, CategoryFilterOptions, SearchResultsFilterOptions, SearchResultBadgeType, SearchResultBadgeElement, ResultFacetOptions, BadgeGenerateSeed, BadgeGenerateOptions, BadgeOptions, MountOptions, SearchContainerOptions, SearchContainerConfigOptions, SingleStarRatingElement, DynamicData, ProductRecommendationOptions, RecommendationABTestingOptions, ChatOptions, RedirectionOptions };
|
|
26
|
+
export type { TrackingOptions, SearchBoxOptions, SearchResultsOptions, ProductListOptions, SdkOptions, FacetStyle, Environment, RoutingBehavior, AnchorPosition, SortDirection, DocumentElement, ImageDocumentElement, TitleDocumentElement, DescriptionDocumentElement, CustomDocumentElement, PriceElement, RegularPriceDocumentElement, RatingElement, AddToCartElement, CustomHtmlElement, SortOptions, SearchResultsSortOptions, SearchResultEventCallbacks, CallbackContext, SortCallbackContext, FacetFilterQuery, CategoryFilterOptions, SearchResultsFilterOptions, SearchResultBadgeType, SearchResultBadgeElement, ResultFacetOptions, BadgeGenerateSeed, BadgeGenerateOptions, BadgeOptions, MountOptions, SearchContainerOptions, SearchContainerConfigOptions, SingleStarRatingElement, DynamicData, ProductRecommendationOptions, RecommendationABTestingOptions, ChatOptions, RedirectionOptions, PreconfiguredSearchContainerOptions, SearchBoxDemoOptions, SearchResultDemoOptions, SearchDemoFields };
|
|
23
27
|
declare global {
|
|
24
28
|
interface Window {
|
|
25
29
|
getLupa: {
|
|
@@ -32,6 +36,9 @@ declare global {
|
|
|
32
36
|
clearSearchResults: () => void;
|
|
33
37
|
clearProductList: () => void;
|
|
34
38
|
clearChat: () => void;
|
|
39
|
+
preconfiguredSearchContainer: (preconfiguredSearchContainerOptions: PreconfiguredSearchContainerOptions) => void;
|
|
40
|
+
getSearchBoxComponent: (options: PreconfiguredSearchContainerOptions) => SearchBoxOptions;
|
|
41
|
+
getSearchResultsComponent: (options: PreconfiguredSearchContainerOptions) => SearchResultsOptions;
|
|
35
42
|
};
|
|
36
43
|
lupaSearch: {
|
|
37
44
|
searchBox: (options: SearchBoxOptions) => void;
|
|
@@ -43,6 +50,9 @@ declare global {
|
|
|
43
50
|
clearSearchResults: () => void;
|
|
44
51
|
clearProductList: () => void;
|
|
45
52
|
clearChat: () => void;
|
|
53
|
+
preconfiguredSearchContainer: (preconfiguredSearchContainerOptions: PreconfiguredSearchContainerOptions) => void;
|
|
54
|
+
getSearchBoxComponent: (options: PreconfiguredSearchContainerOptions) => SearchBoxOptions;
|
|
55
|
+
getSearchResultsComponent: (options: PreconfiguredSearchContainerOptions) => SearchResultsOptions;
|
|
46
56
|
};
|
|
47
57
|
}
|
|
48
58
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PreconfiguredSearchContainerOptions } from '../../types/PreconfiguredSearchContainerOptions';
|
|
2
|
+
import { SearchBoxOptions, SearchResultsOptions } from '@getlupa/vue';
|
|
3
|
+
declare const _default: {
|
|
4
|
+
getSearchBoxComponent: ({ searchBoxOptions, labels, panelOptions, redirections, placeholderImage }: PreconfiguredSearchContainerOptions) => SearchBoxOptions;
|
|
5
|
+
getSearchResultsComponent: ({ searchResultOptions, labels, redirections, placeholderImage, configuratorOverrides, callbacks, additionalFields }: PreconfiguredSearchContainerOptions) => SearchResultsOptions;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SearchResultDemoOptions } from '../../types/PreconfiguredSearchContainerOptions';
|
|
2
|
+
export declare const displayDiscountedPriceSection: (doc: Record<string, string>, options: SearchResultDemoOptions) => boolean;
|
|
3
|
+
export declare const displayRegularPriceSection: (doc: Record<string, string>, options: SearchResultDemoOptions) => boolean;
|
|
4
|
+
export declare const escapeHtml: (source?: string) => string | undefined;
|
|
5
|
+
export declare const toMaxDecimalPlaces: (value?: string | number, maxDecimal?: number) => string | number | undefined;
|
|
6
|
+
export declare const capitalize: (value?: string) => string;
|
|
7
|
+
export declare const getAlphanumeric: (value?: string) => string;
|
|
8
|
+
export declare const getAdditionalElements: (fields: string[]) => {
|
|
9
|
+
type: string;
|
|
10
|
+
key: string;
|
|
11
|
+
label: string;
|
|
12
|
+
className: string;
|
|
13
|
+
display: (doc: Record<string, string>) => boolean;
|
|
14
|
+
}[];
|
|
15
|
+
export declare const addFieldIfKeyExists: (field: string, key?: string, config?: any) => any;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { RedirectionOptions, SearchContainerConfigOptions, SearchResultEventCallbacks } from '@getlupa/vue';
|
|
2
|
+
export type SearchDemoFields = {
|
|
3
|
+
imageKey?: string;
|
|
4
|
+
baseImageUrl?: string;
|
|
5
|
+
titleKey?: string;
|
|
6
|
+
regularPriceKey?: string;
|
|
7
|
+
discountPriceKey?: string;
|
|
8
|
+
productUrl?: string;
|
|
9
|
+
currency?: string;
|
|
10
|
+
minInputLength?: number;
|
|
11
|
+
emphasizedField?: string;
|
|
12
|
+
[key: string]: string | number | undefined;
|
|
13
|
+
};
|
|
14
|
+
export type SearchBoxDemoOptions = {
|
|
15
|
+
inputSelector: string;
|
|
16
|
+
fields: SearchDemoFields;
|
|
17
|
+
suggestionQueryKey: string;
|
|
18
|
+
documentQueryKey?: string;
|
|
19
|
+
environment?: string;
|
|
20
|
+
customUrl?: string;
|
|
21
|
+
customBaseUrl?: string;
|
|
22
|
+
customPayload?: Record<string, unknown>;
|
|
23
|
+
customHeaders?: Record<string, string>;
|
|
24
|
+
errorHandler?: (errorResponse: any) => unknown;
|
|
25
|
+
};
|
|
26
|
+
export type SearchResultDemoOptions = {
|
|
27
|
+
containerSelector: string;
|
|
28
|
+
fields: SearchDemoFields;
|
|
29
|
+
queryKey: string;
|
|
30
|
+
showFacets?: boolean;
|
|
31
|
+
maxColumns?: number;
|
|
32
|
+
maxLines?: number;
|
|
33
|
+
environment?: string;
|
|
34
|
+
customUrl?: string;
|
|
35
|
+
customBaseUrl?: string;
|
|
36
|
+
customPayload?: Record<string, unknown>;
|
|
37
|
+
customHeaders?: Record<string, string>;
|
|
38
|
+
gridConfiguration?: Record<string, number>;
|
|
39
|
+
showRelevance?: boolean;
|
|
40
|
+
errorHandler?: (errorResponse: any) => unknown;
|
|
41
|
+
};
|
|
42
|
+
export type PreconfiguredSearchContainerOptions = {
|
|
43
|
+
trigger: string;
|
|
44
|
+
searchBoxOptions?: SearchBoxDemoOptions;
|
|
45
|
+
searchResultOptions?: SearchResultDemoOptions;
|
|
46
|
+
labels: Record<string, any>;
|
|
47
|
+
redirections?: RedirectionOptions;
|
|
48
|
+
panelOptions?: {
|
|
49
|
+
suggestionPanel: boolean;
|
|
50
|
+
docPanel: boolean;
|
|
51
|
+
};
|
|
52
|
+
configuratorOverrides?: Record<string, unknown>;
|
|
53
|
+
callbacks?: SearchResultEventCallbacks;
|
|
54
|
+
placeholderImage?: string;
|
|
55
|
+
configuration?: SearchContainerConfigOptions;
|
|
56
|
+
additionalFields?: string[];
|
|
57
|
+
};
|