@nuskin/react-search-sdk 1.0.0-trying-again.8 → 1.0.0-trying-again.9
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 +5 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +69 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState, useEffect, useRef, useMemo, useCallback, Component } from 'react';
|
|
2
2
|
import configurationSdk from '@nuskin/configuration-sdk';
|
|
3
|
-
import {
|
|
3
|
+
import { SearchPanel } from '@nuskin/react-search-components';
|
|
4
4
|
import { SalesAIChatWidget } from '@nuskin/react-nui-chat-sdk';
|
|
5
5
|
import '@nuskin/react-nui-chat-sdk/styles.css';
|
|
6
6
|
import { createProductClient, ProductProvider, useProductById, ProductCard } from '@nuskin/react-product-sdk';
|
|
@@ -93,6 +93,65 @@ function useCommerceSearchConfig({
|
|
|
93
93
|
return config;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
// src/copy/searchPanelCopy.ts
|
|
97
|
+
var SEARCH_PANEL_COPY_EN = {
|
|
98
|
+
cancel: "Cancel",
|
|
99
|
+
searchPlaceholder: "Search",
|
|
100
|
+
didYouMean: "Did You Mean?",
|
|
101
|
+
noSuggestions: "No suggestions",
|
|
102
|
+
seeMoreResults: "See More Results",
|
|
103
|
+
recentSearches: "Recent searches",
|
|
104
|
+
clearRecentSearches: "Clear all",
|
|
105
|
+
moreRecentSearches: (count) => `+${count} More`,
|
|
106
|
+
searchLabel: "Search",
|
|
107
|
+
submitSearch: "Submit search",
|
|
108
|
+
clearInput: "Clear search",
|
|
109
|
+
suggestionsLabel: "Suggestions",
|
|
110
|
+
addToCart: (productName) => `Add ${productName} to cart`,
|
|
111
|
+
openBundle: (productName) => `Open bundle action for ${productName}`,
|
|
112
|
+
suggestionsLoading: "Loading suggestions",
|
|
113
|
+
suggestionsCount: (count) => `${count} suggestions available`
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// src/copy/fetchSearchPanelCopy.ts
|
|
117
|
+
async function fetchSearchPanelCopy(_options = {}) {
|
|
118
|
+
return SEARCH_PANEL_COPY_EN;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/copy/loadSearchPanelCopy.ts
|
|
122
|
+
var copyByLanguage = /* @__PURE__ */ new Map();
|
|
123
|
+
function loadSearchPanelCopy(language) {
|
|
124
|
+
const key = (language ?? "").toLowerCase();
|
|
125
|
+
const cached = copyByLanguage.get(key);
|
|
126
|
+
if (cached) return cached;
|
|
127
|
+
const pending = fetchSearchPanelCopy(language ? { } : {});
|
|
128
|
+
copyByLanguage.set(key, pending);
|
|
129
|
+
pending.catch(() => copyByLanguage.delete(key));
|
|
130
|
+
return pending;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/hooks/useSearchPanelCopy.ts
|
|
134
|
+
function useSearchPanelCopy({
|
|
135
|
+
language
|
|
136
|
+
}) {
|
|
137
|
+
const [copy, setCopy] = useState(void 0);
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
let isStale = false;
|
|
140
|
+
loadSearchPanelCopy(language).then((next) => {
|
|
141
|
+
if (!isStale) setCopy(next);
|
|
142
|
+
}).catch((error) => {
|
|
143
|
+
console.warn(
|
|
144
|
+
"[search] Could not load the search panel text:",
|
|
145
|
+
error
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
return () => {
|
|
149
|
+
isStale = true;
|
|
150
|
+
};
|
|
151
|
+
}, [language]);
|
|
152
|
+
return copy;
|
|
153
|
+
}
|
|
154
|
+
|
|
96
155
|
// src/services/SearchApiService.ts
|
|
97
156
|
function canUseStorage(storage) {
|
|
98
157
|
return Boolean(storage) && typeof storage.getItem === "function";
|
|
@@ -1006,9 +1065,10 @@ function readCookieFlag(cookie) {
|
|
|
1006
1065
|
const separator = part.indexOf("=");
|
|
1007
1066
|
if (separator < 0) continue;
|
|
1008
1067
|
if (part.slice(0, separator).trim() !== NUI_SEARCH_FLAG) continue;
|
|
1009
|
-
const rawValue = part.slice(separator + 1);
|
|
1010
1068
|
try {
|
|
1011
|
-
return parseFlagValue(
|
|
1069
|
+
return parseFlagValue(
|
|
1070
|
+
decodeURIComponent(part.slice(separator + 1))
|
|
1071
|
+
);
|
|
1012
1072
|
} catch {
|
|
1013
1073
|
return void 0;
|
|
1014
1074
|
}
|
|
@@ -1019,20 +1079,7 @@ function resolveNuiSearchFlag(env = {}) {
|
|
|
1019
1079
|
const inBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
1020
1080
|
const search = env.search ?? (inBrowser ? window.location.search : "");
|
|
1021
1081
|
const cookie = env.cookie ?? (inBrowser ? document.cookie : "");
|
|
1022
|
-
|
|
1023
|
-
document.cookie = value;
|
|
1024
|
-
} : void 0);
|
|
1025
|
-
const fromQuery = parseFlagValue(
|
|
1026
|
-
new URLSearchParams(search).get(NUI_SEARCH_FLAG)
|
|
1027
|
-
);
|
|
1028
|
-
if (fromQuery !== void 0) {
|
|
1029
|
-
const secure = inBrowser && window.location.protocol === "https:" ? "; Secure" : "";
|
|
1030
|
-
setCookie?.(
|
|
1031
|
-
`${NUI_SEARCH_FLAG}=${fromQuery}; path=/; SameSite=Lax${secure}`
|
|
1032
|
-
);
|
|
1033
|
-
return fromQuery;
|
|
1034
|
-
}
|
|
1035
|
-
return readCookieFlag(cookie);
|
|
1082
|
+
return parseFlagValue(new URLSearchParams(search).get(NUI_SEARCH_FLAG)) ?? readCookieFlag(cookie);
|
|
1036
1083
|
}
|
|
1037
1084
|
function isNuiSearchEnabled({
|
|
1038
1085
|
isAuthenticated,
|
|
@@ -1202,6 +1249,7 @@ function uniqueRecentSearches(queries) {
|
|
|
1202
1249
|
});
|
|
1203
1250
|
}
|
|
1204
1251
|
function CommerceSearchView({
|
|
1252
|
+
copy,
|
|
1205
1253
|
isOpen,
|
|
1206
1254
|
onClose,
|
|
1207
1255
|
service,
|
|
@@ -1428,10 +1476,11 @@ function CommerceSearchView({
|
|
|
1428
1476
|
);
|
|
1429
1477
|
}
|
|
1430
1478
|
return /* @__PURE__ */ jsx(
|
|
1431
|
-
|
|
1479
|
+
SearchPanel,
|
|
1432
1480
|
{
|
|
1433
1481
|
isOpen,
|
|
1434
1482
|
onClose: close,
|
|
1483
|
+
copy,
|
|
1435
1484
|
logo,
|
|
1436
1485
|
input: {
|
|
1437
1486
|
value: query,
|
|
@@ -1472,6 +1521,7 @@ function CommerceSearch({
|
|
|
1472
1521
|
useEffect(() => {
|
|
1473
1522
|
if (isOpen) setHasOpened(true);
|
|
1474
1523
|
}, [isOpen]);
|
|
1524
|
+
const copy = useSearchPanelCopy({ language });
|
|
1475
1525
|
const { minimumSearchLength, agent, allowGuestAgent } = useCommerceSearchConfig({
|
|
1476
1526
|
country,
|
|
1477
1527
|
language,
|
|
@@ -1513,6 +1563,7 @@ function CommerceSearch({
|
|
|
1513
1563
|
language: language.toLowerCase()
|
|
1514
1564
|
} : void 0;
|
|
1515
1565
|
}, [country, language]);
|
|
1566
|
+
if (!copy) return null;
|
|
1516
1567
|
return /* @__PURE__ */ jsx(
|
|
1517
1568
|
CommerceSearchView,
|
|
1518
1569
|
{
|
|
@@ -1524,6 +1575,7 @@ function CommerceSearch({
|
|
|
1524
1575
|
...agent ? { agent } : {},
|
|
1525
1576
|
...allowGuestAgent ? { allowGuestAgent } : {},
|
|
1526
1577
|
...agentProducts ? { agentProducts } : {},
|
|
1578
|
+
copy,
|
|
1527
1579
|
logo,
|
|
1528
1580
|
minimumSearchLength,
|
|
1529
1581
|
gtmContext
|