@nosto/nosto-react 0.3.0 → 0.4.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/README.md +66 -86
- package/dist/index.es.client.js +178 -178
- package/dist/index.umd.client.js +2 -2
- package/package.json +29 -13
- package/src/components/Category/index.client.tsx +30 -8
- package/src/components/Checkout/index.client.tsx +25 -8
- package/src/components/Fohofo/index.client.tsx +25 -8
- package/src/components/Home/index.client.tsx +28 -8
- package/src/components/Order/index.client.tsx +28 -13
- package/src/components/Other/index.client.tsx +23 -7
- package/src/components/Placement/index.client.tsx +18 -8
- package/src/components/Product/index.client.tsx +50 -31
- package/src/components/Provider/context.client.ts +24 -10
- package/src/components/Provider/index.client.tsx +129 -28
- package/src/components/Search/index.client.tsx +29 -8
- package/src/components/Session/index.client.tsx +19 -14
- package/src/index.client.ts +7 -10
- package/src/types.ts +84 -2
- package/src/utils/compare.ts +30 -0
- package/src/utils/hooks.ts +21 -0
- package/src/utils/object.ts +20 -0
- package/src/utils/snakeize.ts +28 -0
- package/src/snakeize.d.ts +0 -1
- package/src/utils/stringinate.ts +0 -16
package/dist/index.es.client.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import React__default, { createContext, useContext, useEffect, isValidElement, useState, useRef } from "react";
|
|
1
|
+
import React, { createContext, useContext, useEffect, useRef, useMemo, isValidElement, useState } from "react";
|
|
3
2
|
import { createRoot } from "react-dom/client";
|
|
4
3
|
const NostoContext = createContext({
|
|
5
|
-
account:
|
|
4
|
+
account: "",
|
|
6
5
|
currentVariation: "",
|
|
7
|
-
|
|
6
|
+
pageType: "",
|
|
7
|
+
responseMode: "HTML",
|
|
8
|
+
clientScriptLoaded: false,
|
|
9
|
+
useRenderCampaigns: () => void 0
|
|
8
10
|
});
|
|
9
11
|
function useNostoContext() {
|
|
10
12
|
const context = useContext(NostoContext);
|
|
@@ -24,7 +26,7 @@ var reactJsxRuntime_production_min = {};
|
|
|
24
26
|
* This source code is licensed under the MIT license found in the
|
|
25
27
|
* LICENSE file in the root directory of this source tree.
|
|
26
28
|
*/
|
|
27
|
-
var f =
|
|
29
|
+
var f = React, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: true, ref: true, __self: true, __source: true };
|
|
28
30
|
function q(c, a, g) {
|
|
29
31
|
var b, d = {}, e = null, h = null;
|
|
30
32
|
void 0 !== g && (e = "" + g);
|
|
@@ -46,7 +48,7 @@ reactJsxRuntime_production_min.jsxs = q;
|
|
|
46
48
|
const jsx = jsxRuntime.exports.jsx;
|
|
47
49
|
const jsxs = jsxRuntime.exports.jsxs;
|
|
48
50
|
const Fragment = jsxRuntime.exports.Fragment;
|
|
49
|
-
|
|
51
|
+
function Nosto404() {
|
|
50
52
|
const {
|
|
51
53
|
clientScriptLoaded,
|
|
52
54
|
currentVariation,
|
|
@@ -76,8 +78,8 @@ const NostoFohofo = () => {
|
|
|
76
78
|
children: "notfound"
|
|
77
79
|
})
|
|
78
80
|
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
+
}
|
|
82
|
+
function NostoOther() {
|
|
81
83
|
const {
|
|
82
84
|
clientScriptLoaded,
|
|
83
85
|
currentVariation,
|
|
@@ -107,8 +109,8 @@ const NostoOther = () => {
|
|
|
107
109
|
children: "other"
|
|
108
110
|
})
|
|
109
111
|
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
+
}
|
|
113
|
+
function NostoCheckout() {
|
|
112
114
|
const {
|
|
113
115
|
clientScriptLoaded,
|
|
114
116
|
currentVariation,
|
|
@@ -138,11 +140,61 @@ const NostoCheckout = () => {
|
|
|
138
140
|
children: "cart"
|
|
139
141
|
})
|
|
140
142
|
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
}
|
|
144
|
+
function isPlainObject(value) {
|
|
145
|
+
const isObject = (v) => String(v) === "[object Object]";
|
|
146
|
+
if (!isObject(value))
|
|
147
|
+
return false;
|
|
148
|
+
const constructor = value.constructor;
|
|
149
|
+
if (constructor === void 0)
|
|
150
|
+
return true;
|
|
151
|
+
const prototype = constructor.prototype;
|
|
152
|
+
if (!isObject(prototype))
|
|
153
|
+
return false;
|
|
154
|
+
if (!prototype.hasOwnProperty("isPrototypeOf")) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
function deepCompare(a, b) {
|
|
160
|
+
if (a === b) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
if (a instanceof Date && b instanceof Date) {
|
|
164
|
+
return a.getTime() === b.getTime();
|
|
165
|
+
}
|
|
166
|
+
if (a instanceof Array && b instanceof Array) {
|
|
167
|
+
if (a.length !== b.length) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
return a.every((v, i) => deepCompare(v, b[i]));
|
|
171
|
+
}
|
|
172
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
173
|
+
const entriesA = Object.entries(a);
|
|
174
|
+
if (entriesA.length !== Object.keys(b).length) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
return entriesA.every(([k2, v]) => deepCompare(v, b[k2]));
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
function useDeepCompareEffect(callback, dependencies) {
|
|
182
|
+
return useEffect(callback, useDeepCompareMemoize(dependencies));
|
|
183
|
+
}
|
|
184
|
+
function useDeepCompareMemoize(value) {
|
|
185
|
+
const ref = useRef(value);
|
|
186
|
+
const signalRef = useRef(0);
|
|
187
|
+
if (!deepCompare(value, ref.current)) {
|
|
188
|
+
ref.current = value;
|
|
189
|
+
signalRef.current += 1;
|
|
190
|
+
}
|
|
191
|
+
return useMemo(() => ref.current, [signalRef.current]);
|
|
192
|
+
}
|
|
193
|
+
function NostoProduct(props) {
|
|
194
|
+
const {
|
|
195
|
+
product,
|
|
196
|
+
tagging
|
|
197
|
+
} = props;
|
|
146
198
|
const {
|
|
147
199
|
clientScriptLoaded,
|
|
148
200
|
currentVariation,
|
|
@@ -154,15 +206,15 @@ const NostoProduct = ({
|
|
|
154
206
|
renderCampaigns,
|
|
155
207
|
pageTypeUpdated
|
|
156
208
|
} = useRenderCampaigns("product");
|
|
157
|
-
|
|
209
|
+
useDeepCompareEffect(() => {
|
|
158
210
|
if (clientScriptLoaded && pageTypeUpdated) {
|
|
159
211
|
window.nostojs((api) => {
|
|
160
212
|
api.defaultSession().setResponseMode(responseMode).viewProduct(product).setPlacements(api.placements.getPlacements()).load().then((data) => {
|
|
161
213
|
renderCampaigns(data, api);
|
|
162
214
|
});
|
|
163
|
-
}
|
|
215
|
+
});
|
|
164
216
|
}
|
|
165
|
-
});
|
|
217
|
+
}, [clientScriptLoaded, currentVariation, product, recommendationComponent, pageTypeUpdated]);
|
|
166
218
|
return /* @__PURE__ */ jsxs(Fragment, {
|
|
167
219
|
children: [/* @__PURE__ */ jsx("div", {
|
|
168
220
|
className: "nosto_page_type",
|
|
@@ -280,10 +332,11 @@ const NostoProduct = ({
|
|
|
280
332
|
}, index))]
|
|
281
333
|
})]
|
|
282
334
|
});
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
335
|
+
}
|
|
336
|
+
function NostoCategory(props) {
|
|
337
|
+
const {
|
|
338
|
+
category
|
|
339
|
+
} = props;
|
|
287
340
|
const {
|
|
288
341
|
clientScriptLoaded,
|
|
289
342
|
currentVariation,
|
|
@@ -319,10 +372,11 @@ const NostoCategory = ({
|
|
|
319
372
|
children: category
|
|
320
373
|
})]
|
|
321
374
|
});
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
375
|
+
}
|
|
376
|
+
function NostoSearch(props) {
|
|
377
|
+
const {
|
|
378
|
+
query
|
|
379
|
+
} = props;
|
|
326
380
|
const {
|
|
327
381
|
clientScriptLoaded,
|
|
328
382
|
currentVariation,
|
|
@@ -358,31 +412,35 @@ const NostoSearch = ({
|
|
|
358
412
|
children: query
|
|
359
413
|
})]
|
|
360
414
|
});
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
if (!obj || typeof obj !== "object")
|
|
415
|
+
}
|
|
416
|
+
function snakeize(obj) {
|
|
417
|
+
if (!obj || typeof obj !== "object") {
|
|
364
418
|
return obj;
|
|
365
|
-
|
|
419
|
+
}
|
|
420
|
+
if (isDate(obj) || isRegex(obj)) {
|
|
366
421
|
return obj;
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
422
|
+
}
|
|
423
|
+
if (Array.isArray(obj)) {
|
|
424
|
+
return obj.map(snakeize);
|
|
425
|
+
}
|
|
426
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
427
|
+
var camel = key[0].toLowerCase() + key.slice(1).replace(/([A-Z]+)/g, (_, x) => {
|
|
371
428
|
return "_" + x.toLowerCase();
|
|
372
429
|
});
|
|
373
|
-
acc[camel] =
|
|
430
|
+
acc[camel] = snakeize(obj[key]);
|
|
374
431
|
return acc;
|
|
375
432
|
}, {});
|
|
376
|
-
}
|
|
377
|
-
|
|
433
|
+
}
|
|
434
|
+
function isDate(obj) {
|
|
378
435
|
return Object.prototype.toString.call(obj) === "[object Date]";
|
|
379
|
-
}
|
|
380
|
-
|
|
436
|
+
}
|
|
437
|
+
function isRegex(obj) {
|
|
381
438
|
return Object.prototype.toString.call(obj) === "[object RegExp]";
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
439
|
+
}
|
|
440
|
+
function NostoOrder(props) {
|
|
441
|
+
const {
|
|
442
|
+
order
|
|
443
|
+
} = props;
|
|
386
444
|
const {
|
|
387
445
|
clientScriptLoaded,
|
|
388
446
|
currentVariation,
|
|
@@ -418,8 +476,8 @@ const NostoOrder = ({
|
|
|
418
476
|
children: order.purchase.number
|
|
419
477
|
})]
|
|
420
478
|
});
|
|
421
|
-
}
|
|
422
|
-
|
|
479
|
+
}
|
|
480
|
+
function NostoHome() {
|
|
423
481
|
const {
|
|
424
482
|
clientScriptLoaded,
|
|
425
483
|
currentVariation,
|
|
@@ -449,31 +507,34 @@ const NostoHome = () => {
|
|
|
449
507
|
children: "front"
|
|
450
508
|
})
|
|
451
509
|
});
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
510
|
+
}
|
|
511
|
+
function NostoPlacement(props) {
|
|
512
|
+
const {
|
|
513
|
+
id,
|
|
514
|
+
pageType
|
|
515
|
+
} = props;
|
|
457
516
|
return /* @__PURE__ */ jsx("div", {
|
|
458
517
|
className: "nosto_element",
|
|
459
518
|
id
|
|
460
|
-
}, id + pageType);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
519
|
+
}, id + (pageType || ""));
|
|
520
|
+
}
|
|
521
|
+
function NostoProvider(props) {
|
|
522
|
+
let {
|
|
523
|
+
account,
|
|
524
|
+
currentVariation = "",
|
|
525
|
+
multiCurrency = false,
|
|
526
|
+
host,
|
|
527
|
+
children,
|
|
528
|
+
recommendationComponent,
|
|
529
|
+
shopifyMarkets
|
|
530
|
+
} = props;
|
|
531
|
+
const [clientScriptLoadedState, setClientScriptLoadedState] = React.useState(false);
|
|
532
|
+
const clientScriptLoaded = React.useMemo(() => clientScriptLoadedState, [clientScriptLoadedState]);
|
|
472
533
|
currentVariation = multiCurrency ? currentVariation : "";
|
|
473
534
|
const responseMode = isValidElement(recommendationComponent) ? "JSON_ORIGINAL" : "HTML";
|
|
474
|
-
function RecommendationComponentWrapper(
|
|
475
|
-
return
|
|
476
|
-
nostoRecommendation:
|
|
535
|
+
function RecommendationComponentWrapper(props2) {
|
|
536
|
+
return React.cloneElement(recommendationComponent, {
|
|
537
|
+
nostoRecommendation: props2.nostoRecommendation
|
|
477
538
|
});
|
|
478
539
|
}
|
|
479
540
|
const [pageType, setPageType] = useState("");
|
|
@@ -511,21 +572,59 @@ const NostoProvider = ({
|
|
|
511
572
|
};
|
|
512
573
|
};
|
|
513
574
|
useEffect(() => {
|
|
514
|
-
|
|
575
|
+
var _a, _b, _c;
|
|
576
|
+
if (!window.nostojs) {
|
|
577
|
+
window.nostojs = (cb) => {
|
|
578
|
+
(window.nostojs.q = window.nostojs.q || []).push(cb);
|
|
579
|
+
};
|
|
580
|
+
window.nostojs((api) => api.setAutoLoad(false));
|
|
581
|
+
}
|
|
582
|
+
if (!document.querySelectorAll("[nosto-client-script]").length && !shopifyMarkets) {
|
|
515
583
|
const script = document.createElement("script");
|
|
516
584
|
script.type = "text/javascript";
|
|
517
585
|
script.src = "//" + (host || "connect.nosto.com") + "/include/" + account;
|
|
518
586
|
script.async = true;
|
|
519
587
|
script.setAttribute("nosto-client-script", "");
|
|
520
588
|
script.onload = () => {
|
|
521
|
-
|
|
589
|
+
var _a2;
|
|
590
|
+
if (typeof jest !== "undefined") {
|
|
591
|
+
(_a2 = window.nosto) == null ? void 0 : _a2.reload({
|
|
592
|
+
site: "localhost"
|
|
593
|
+
});
|
|
594
|
+
}
|
|
522
595
|
setClientScriptLoadedState(true);
|
|
523
596
|
};
|
|
524
|
-
document.
|
|
597
|
+
document.body.appendChild(script);
|
|
598
|
+
}
|
|
599
|
+
if (!!shopifyMarkets) {
|
|
600
|
+
const existingScript = document.querySelector("[nosto-client-script]");
|
|
601
|
+
const nostoSandbox = document.querySelector("#nosto-sandbox");
|
|
602
|
+
if (!existingScript || (existingScript == null ? void 0 : existingScript.getAttribute("nosto-language")) != (shopifyMarkets == null ? void 0 : shopifyMarkets.language) || (existingScript == null ? void 0 : existingScript.getAttribute("nosto-market-id")) != (shopifyMarkets == null ? void 0 : shopifyMarkets.marketId)) {
|
|
603
|
+
if (clientScriptLoadedState) {
|
|
604
|
+
setClientScriptLoadedState(false);
|
|
605
|
+
}
|
|
606
|
+
(_a = existingScript == null ? void 0 : existingScript.parentNode) == null ? void 0 : _a.removeChild(existingScript);
|
|
607
|
+
(_b = nostoSandbox == null ? void 0 : nostoSandbox.parentNode) == null ? void 0 : _b.removeChild(nostoSandbox);
|
|
608
|
+
const script = document.createElement("script");
|
|
609
|
+
script.type = "text/javascript";
|
|
610
|
+
script.src = "//" + (host || "connect.nosto.com") + `/script/shopify/market/nosto.js?merchant=${account}&market=${shopifyMarkets.marketId || ""}&locale=${((_c = shopifyMarkets == null ? void 0 : shopifyMarkets.language) == null ? void 0 : _c.toLowerCase()) || ""}`;
|
|
611
|
+
script.async = true;
|
|
612
|
+
script.setAttribute("nosto-client-script", "");
|
|
613
|
+
script.setAttribute("nosto-language", (shopifyMarkets == null ? void 0 : shopifyMarkets.language) || "");
|
|
614
|
+
script.setAttribute("nosto-market-id", String(shopifyMarkets == null ? void 0 : shopifyMarkets.marketId));
|
|
615
|
+
script.onload = () => {
|
|
616
|
+
var _a2;
|
|
617
|
+
if (typeof jest !== "undefined") {
|
|
618
|
+
(_a2 = window.nosto) == null ? void 0 : _a2.reload({
|
|
619
|
+
site: "localhost"
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
setClientScriptLoadedState(true);
|
|
623
|
+
};
|
|
624
|
+
document.body.appendChild(script);
|
|
625
|
+
}
|
|
525
626
|
}
|
|
526
|
-
|
|
527
|
-
window.nostojs((api) => api.setAutoLoad(false));
|
|
528
|
-
}, []);
|
|
627
|
+
}, [clientScriptLoadedState, shopifyMarkets]);
|
|
529
628
|
return /* @__PURE__ */ jsx(NostoContext.Provider, {
|
|
530
629
|
value: {
|
|
531
630
|
account,
|
|
@@ -538,111 +637,12 @@ const NostoProvider = ({
|
|
|
538
637
|
},
|
|
539
638
|
children
|
|
540
639
|
});
|
|
541
|
-
};
|
|
542
|
-
var has = Object.prototype.hasOwnProperty;
|
|
543
|
-
function find(iter, tar, key) {
|
|
544
|
-
for (key of iter.keys()) {
|
|
545
|
-
if (dequal(key, tar))
|
|
546
|
-
return key;
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
function dequal(foo, bar) {
|
|
550
|
-
var ctor, len, tmp;
|
|
551
|
-
if (foo === bar)
|
|
552
|
-
return true;
|
|
553
|
-
if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
|
|
554
|
-
if (ctor === Date)
|
|
555
|
-
return foo.getTime() === bar.getTime();
|
|
556
|
-
if (ctor === RegExp)
|
|
557
|
-
return foo.toString() === bar.toString();
|
|
558
|
-
if (ctor === Array) {
|
|
559
|
-
if ((len = foo.length) === bar.length) {
|
|
560
|
-
while (len-- && dequal(foo[len], bar[len]))
|
|
561
|
-
;
|
|
562
|
-
}
|
|
563
|
-
return len === -1;
|
|
564
|
-
}
|
|
565
|
-
if (ctor === Set) {
|
|
566
|
-
if (foo.size !== bar.size) {
|
|
567
|
-
return false;
|
|
568
|
-
}
|
|
569
|
-
for (len of foo) {
|
|
570
|
-
tmp = len;
|
|
571
|
-
if (tmp && typeof tmp === "object") {
|
|
572
|
-
tmp = find(bar, tmp);
|
|
573
|
-
if (!tmp)
|
|
574
|
-
return false;
|
|
575
|
-
}
|
|
576
|
-
if (!bar.has(tmp))
|
|
577
|
-
return false;
|
|
578
|
-
}
|
|
579
|
-
return true;
|
|
580
|
-
}
|
|
581
|
-
if (ctor === Map) {
|
|
582
|
-
if (foo.size !== bar.size) {
|
|
583
|
-
return false;
|
|
584
|
-
}
|
|
585
|
-
for (len of foo) {
|
|
586
|
-
tmp = len[0];
|
|
587
|
-
if (tmp && typeof tmp === "object") {
|
|
588
|
-
tmp = find(bar, tmp);
|
|
589
|
-
if (!tmp)
|
|
590
|
-
return false;
|
|
591
|
-
}
|
|
592
|
-
if (!dequal(len[1], bar.get(tmp))) {
|
|
593
|
-
return false;
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
return true;
|
|
597
|
-
}
|
|
598
|
-
if (ctor === ArrayBuffer) {
|
|
599
|
-
foo = new Uint8Array(foo);
|
|
600
|
-
bar = new Uint8Array(bar);
|
|
601
|
-
} else if (ctor === DataView) {
|
|
602
|
-
if ((len = foo.byteLength) === bar.byteLength) {
|
|
603
|
-
while (len-- && foo.getInt8(len) === bar.getInt8(len))
|
|
604
|
-
;
|
|
605
|
-
}
|
|
606
|
-
return len === -1;
|
|
607
|
-
}
|
|
608
|
-
if (ArrayBuffer.isView(foo)) {
|
|
609
|
-
if ((len = foo.byteLength) === bar.byteLength) {
|
|
610
|
-
while (len-- && foo[len] === bar[len])
|
|
611
|
-
;
|
|
612
|
-
}
|
|
613
|
-
return len === -1;
|
|
614
|
-
}
|
|
615
|
-
if (!ctor || typeof foo === "object") {
|
|
616
|
-
len = 0;
|
|
617
|
-
for (ctor in foo) {
|
|
618
|
-
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor))
|
|
619
|
-
return false;
|
|
620
|
-
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor]))
|
|
621
|
-
return false;
|
|
622
|
-
}
|
|
623
|
-
return Object.keys(bar).length === len;
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
return foo !== foo && bar !== bar;
|
|
627
|
-
}
|
|
628
|
-
function useDeepCompareMemoize(value) {
|
|
629
|
-
var ref = React.useRef(value);
|
|
630
|
-
var signalRef = React.useRef(0);
|
|
631
|
-
if (!dequal(value, ref.current)) {
|
|
632
|
-
ref.current = value;
|
|
633
|
-
signalRef.current += 1;
|
|
634
|
-
}
|
|
635
|
-
return React.useMemo(function() {
|
|
636
|
-
return ref.current;
|
|
637
|
-
}, [signalRef.current]);
|
|
638
|
-
}
|
|
639
|
-
function useDeepCompareEffect(callback, dependencies) {
|
|
640
|
-
return React.useEffect(callback, useDeepCompareMemoize(dependencies));
|
|
641
640
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
641
|
+
function NostoSession(props) {
|
|
642
|
+
const {
|
|
643
|
+
cart,
|
|
644
|
+
customer
|
|
645
|
+
} = props;
|
|
646
646
|
const {
|
|
647
647
|
clientScriptLoaded
|
|
648
648
|
} = useNostoContext();
|
|
@@ -654,7 +654,7 @@ const NostoSession = ({
|
|
|
654
654
|
api.defaultSession().setResponseMode("HTML").setCart(currentCart).setCustomer(currentCustomer).viewOther().load();
|
|
655
655
|
});
|
|
656
656
|
}
|
|
657
|
-
}, [clientScriptLoaded, cart
|
|
657
|
+
}, [clientScriptLoaded, cart, customer]);
|
|
658
658
|
return /* @__PURE__ */ jsx(Fragment, {});
|
|
659
|
-
}
|
|
660
|
-
export {
|
|
659
|
+
}
|
|
660
|
+
export { Nosto404, NostoCategory, NostoCheckout, NostoContext, NostoHome, NostoOrder, NostoOther, NostoPlacement, NostoProduct, NostoProvider, NostoSearch, NostoSession, useNostoContext };
|
package/dist/index.umd.client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(m
|
|
1
|
+
(function(u,m){typeof exports=="object"&&typeof module!="undefined"?m(exports,require("react"),require("react-dom/client")):typeof define=="function"&&define.amd?define(["exports","react","react-dom/client"],m):(u=typeof globalThis!="undefined"?globalThis:u||self,m(u["@nosto/nosto-react"]={},u.React,u.ReactDOM))})(this,function(u,m,x){"use strict";function D(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var R=D(m);const V=m.createContext({account:"",currentVariation:"",pageType:"",responseMode:"HTML",clientScriptLoaded:!1,useRenderCampaigns:()=>{}});function h(){const t=m.useContext(V);if(!t)throw new Error("No nosto context found");return t}var E={exports:{}},b={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var b=w.default,z=Symbol.for("react.element"),q=Symbol.for("react.fragment"),H=Object.prototype.hasOwnProperty,B=b.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,G={key:!0,ref:!0,__self:!0,__source:!0};function E(t,e,r){var n,c={},a=null,d=null;r!==void 0&&(a=""+r),e.key!==void 0&&(a=""+e.key),e.ref!==void 0&&(d=e.ref);for(n in e)H.call(e,n)&&!G.hasOwnProperty(n)&&(c[n]=e[n]);if(t&&t.defaultProps)for(n in e=t.defaultProps,e)c[n]===void 0&&(c[n]=e[n]);return{$$typeof:z,type:t,key:a,ref:d,props:c,_owner:B.current}}j.Fragment=q,j.jsx=E,j.jsxs=E,P.exports=j;const o=P.exports.jsx,_=P.exports.jsxs,y=P.exports.Fragment,J=()=>{const{clientScriptLoaded:t,currentVariation:e,responseMode:r,recommendationComponent:n,useRenderCampaigns:c}=h(),{renderCampaigns:a,pageTypeUpdated:d}=c("404");return p.useEffect(()=>{t&&d&&window.nostojs(l=>{l.defaultSession().setVariation(e).setResponseMode(r).viewNotFound().setPlacements(l.placements.getPlacements()).load().then(i=>{a(i,l)})})},[t,e,n,d]),o(y,{children:o("div",{className:"nosto_page_type",style:{display:"none"},children:"notfound"})})},W=()=>{const{clientScriptLoaded:t,currentVariation:e,responseMode:r,recommendationComponent:n,useRenderCampaigns:c}=h(),{renderCampaigns:a,pageTypeUpdated:d}=c("other");return p.useEffect(()=>{t&&d&&window.nostojs(l=>{l.defaultSession().setVariation(e).setResponseMode(r).viewOther().setPlacements(l.placements.getPlacements()).load().then(i=>{a(i,l)})})},[t,e,n,d]),o(y,{children:o("div",{className:"nosto_page_type",style:{display:"none"},children:"other"})})},$=()=>{const{clientScriptLoaded:t,currentVariation:e,responseMode:r,recommendationComponent:n,useRenderCampaigns:c}=h(),{renderCampaigns:a,pageTypeUpdated:d}=c("checkout");return p.useEffect(()=>{t&&d&&window.nostojs(l=>{l.defaultSession().setVariation(e).setResponseMode(r).viewCart().setPlacements(l.placements.getPlacements()).load().then(i=>{a(i,l)})})},[t,e,n,d]),o(y,{children:o("div",{className:"nosto_page_type",style:{display:"none"},children:"cart"})})},Y=({product:t,tagging:e})=>{const{clientScriptLoaded:r,currentVariation:n,responseMode:c,recommendationComponent:a,useRenderCampaigns:d}=h(),{renderCampaigns:l,pageTypeUpdated:i}=d("product");return p.useEffect(()=>{r&&i&&window.nostojs(s=>{s.defaultSession().setResponseMode(c).viewProduct(t).setPlacements(s.placements.getPlacements()).load().then(u=>{l(u,s)})},[r,n,t,a,i])}),_(y,{children:[o("div",{className:"nosto_page_type",style:{display:"none"},children:"product"}),_("div",{className:"nosto_product",style:{display:"none"},children:[(e==null?void 0:e.variationId)&&o("span",{className:"variation_id",children:e.variationId}),t&&o("span",{className:"product_id",children:t}),(e==null?void 0:e.name)&&o("span",{className:"name",children:e.name}),(e==null?void 0:e.url)&&o("span",{className:"url",children:e.url.toString()}),(e==null?void 0:e.imageUrl)&&o("span",{className:"image_url",children:e.imageUrl.toString()}),(e==null?void 0:e.availability)&&o("span",{className:"availability",children:e.availability}),(e==null?void 0:e.price)&&o("span",{className:"price",children:e.price}),(e==null?void 0:e.listPrice)&&o("span",{className:"list_price",children:e.listPrice}),(e==null?void 0:e.priceCurrencyCode)&&o("span",{className:"price_currency_code",children:e.priceCurrencyCode}),(e==null?void 0:e.brand)&&o("span",{className:"brand",children:e.brand}),(e==null?void 0:e.description)&&o("span",{className:"description",children:e.description}),(e==null?void 0:e.googleCategory)&&o("span",{className:"description",children:e.googleCategory}),(e==null?void 0:e.condition)&&o("span",{className:"condition",children:e.condition}),(e==null?void 0:e.gender)&&o("span",{className:"gender",children:e.gender}),(e==null?void 0:e.ageGroup)&&o("span",{className:"age_group",children:e.ageGroup}),(e==null?void 0:e.gtin)&&o("span",{className:"gtin",children:e.gtin}),(e==null?void 0:e.category)&&(e==null?void 0:e.category.map((s,u)=>o("span",{className:"category",children:s},u))),(e==null?void 0:e.tags1)&&e.tags1.map((s,u)=>o("span",{className:"tag1",children:s},u)),(e==null?void 0:e.tags2)&&e.tags2.map((s,u)=>o("span",{className:"tag2",children:s},u)),(e==null?void 0:e.tags3)&&e.tags3.map((s,u)=>o("span",{className:"tag3",children:s},u)),(e==null?void 0:e.ratingValue)&&o("span",{className:"rating_value",children:e.ratingValue}),(e==null?void 0:e.reviewCount)&&o("span",{className:"review_count",children:e.reviewCount}),(e==null?void 0:e.alternateImageUrls)&&e.alternateImageUrls.map((s,u)=>o("span",{className:"alternate_image_url",children:s.toString()},u)),(e==null?void 0:e.customFields)&&Object.keys(e.customFields).map((s,u)=>e.customFields&&e.customFields[s]&&o("span",{className:s,children:e.customFields[s]},u)),(e==null?void 0:e.skus)&&e.skus.map((s,u)=>_("span",{className:"nosto_sku",children:[(s==null?void 0:s.id)&&o("span",{className:"product_id",children:s.id}),(s==null?void 0:s.name)&&o("span",{className:"name",children:s.name}),(s==null?void 0:s.price)&&o("span",{className:"price",children:s.price}),(s==null?void 0:s.listPrice)&&o("span",{className:"list_price",children:s.listPrice}),(s==null?void 0:s.url)&&o("span",{className:"url",children:s.url.toString()}),(s==null?void 0:s.imageUrl)&&o("span",{className:"image_url",children:s.imageUrl.toString()}),(s==null?void 0:s.gtin)&&o("span",{className:"gtin",children:s.gtin}),(s==null?void 0:s.availability)&&o("span",{className:"availability",children:s.availability}),(s==null?void 0:s.customFields)&&Object.keys(s.customFields).map((N,L)=>s.customFields&&s.customFields[N]&&o("span",{className:N,children:s.customFields[N]},L))]},u))]})]})},Z=({category:t})=>{const{clientScriptLoaded:e,currentVariation:r,responseMode:n,recommendationComponent:c,useRenderCampaigns:a}=h(),{renderCampaigns:d,pageTypeUpdated:l}=a("home");return p.useEffect(()=>{e&&l&&window.nostojs(i=>{i.defaultSession().setVariation(r).setResponseMode(n).viewCategory(t).setPlacements(i.placements.getPlacements()).load().then(s=>{d(s,i)})})},[e,t,r,c,l]),_(y,{children:[o("div",{className:"nosto_page_type",style:{display:"none"},children:"category"}),o("div",{className:"nosto_category",style:{display:"none"},children:t})]})},K=({query:t})=>{const{clientScriptLoaded:e,currentVariation:r,responseMode:n,recommendationComponent:c,useRenderCampaigns:a}=h(),{renderCampaigns:d,pageTypeUpdated:l}=a("search");return p.useEffect(()=>{e&&l&&window.nostojs(i=>{i.defaultSession().setVariation(r).setResponseMode(n).viewSearch(t).setPlacements(i.placements.getPlacements()).load().then(s=>{d(s,i)})})},[e,r,t,c,l]),_(y,{children:[o("div",{className:"nosto_page_type",style:{display:"none"},children:"search"}),o("div",{className:"nosto_search",style:{display:"none"},children:t})]})};var M=function t(e){return!e||typeof e!="object"||Q(e)||X(e)?e:Array.isArray(e)?e.map(t):Object.keys(e).reduce(function(r,n){var c=n[0].toLowerCase()+n.slice(1).replace(/([A-Z]+)/g,function(a,d){return"_"+d.toLowerCase()});return r[c]=t(e[n]),r},{})},Q=function(t){return Object.prototype.toString.call(t)==="[object Date]"},X=function(t){return Object.prototype.toString.call(t)==="[object RegExp]"};const k=({order:t})=>{const{clientScriptLoaded:e,currentVariation:r,responseMode:n,recommendationComponent:c,useRenderCampaigns:a}=h(),{renderCampaigns:d,pageTypeUpdated:l}=a("order");return p.useEffect(()=>{e&&l&&window.nostojs(i=>{i.defaultSession().setVariation(r).setResponseMode(n).addOrder(M(t)).setPlacements(i.placements.getPlacements()).load().then(s=>{d(s,i)})})},[e,r,c,l]),_(y,{children:[o("div",{className:"nosto_page_type",style:{display:"none"},children:"order"}),o("div",{className:"nosto_order",style:{display:"none"},children:t.purchase.number})]})},g=()=>{const{clientScriptLoaded:t,currentVariation:e,responseMode:r,recommendationComponent:n,useRenderCampaigns:c}=h(),{renderCampaigns:a,pageTypeUpdated:d}=c("home");return p.useEffect(()=>{t&&d&&window.nostojs(l=>{l.defaultSession().setVariation(e).setResponseMode(r).viewFrontPage().setPlacements(l.placements.getPlacements()).load().then(i=>{a(i,l)})})},[t,e,n,d]),o(y,{children:o("div",{className:"nosto_page_type",style:{display:"none"},children:"front"})})},ee=({id:t,pageType:e})=>o("div",{className:"nosto_element",id:t},t+e),te=({account:t,currentVariation:e="",multiCurrency:r=!1,host:n,children:c,recommendationComponent:a})=>{const[d,l]=w.default.useState(!1),i=w.default.useMemo(()=>d,[d]);e=r?e:"";const s=p.isValidElement(a)?"JSON_ORIGINAL":"HTML";function u(f){return w.default.cloneElement(a,{nostoRecommendation:f.nostoRecommendation})}const[N,L]=p.useState(""),oe=function(f=""){const R=p.useRef({});p.useEffect(()=>{N!=f&&L(f)},[]);const ce=f==N;function le(V,de){if(s=="HTML")de.placements.injectCampaigns(V.recommendations);else{const F=V.campaigns.recommendations;for(const C in F){let ae=F[C],ie="#"+C,x=()=>document.querySelector(ie);x()&&(R.current[C]||(R.current[C]=A.createRoot(x())),R.current[C].render(o(u,{nostoRecommendation:ae})))}}}return{renderCampaigns:le,pageTypeUpdated:ce}};return p.useEffect(()=>{if(!document.querySelectorAll("[nosto-client-script]").length){const f=document.createElement("script");f.type="text/javascript",f.src="//"+(n||"connect.nosto.com")+"/include/"+t,f.async=!0,f.setAttribute("nosto-client-script",""),f.onload=()=>{console.log("Nosto client script loaded"),l(!0)},document.head.appendChild(f)}window.nostojs=f=>(window.nostojs.q=window.nostojs.q||[]).push(f),window.nostojs(f=>f.setAutoLoad(!1))},[]),o(O.Provider,{value:{account:t,clientScriptLoaded:i,currentVariation:e,responseMode:s,recommendationComponent:a,useRenderCampaigns:oe,pageType:N},children:c})};var T=Object.prototype.hasOwnProperty;function U(t,e,r){for(r of t.keys())if(v(r,e))return r}function v(t,e){var r,n,c;if(t===e)return!0;if(t&&e&&(r=t.constructor)===e.constructor){if(r===Date)return t.getTime()===e.getTime();if(r===RegExp)return t.toString()===e.toString();if(r===Array){if((n=t.length)===e.length)for(;n--&&v(t[n],e[n]););return n===-1}if(r===Set){if(t.size!==e.size)return!1;for(n of t)if(c=n,c&&typeof c=="object"&&(c=U(e,c),!c)||!e.has(c))return!1;return!0}if(r===Map){if(t.size!==e.size)return!1;for(n of t)if(c=n[0],c&&typeof c=="object"&&(c=U(e,c),!c)||!v(n[1],e.get(c)))return!1;return!0}if(r===ArrayBuffer)t=new Uint8Array(t),e=new Uint8Array(e);else if(r===DataView){if((n=t.byteLength)===e.byteLength)for(;n--&&t.getInt8(n)===e.getInt8(n););return n===-1}if(ArrayBuffer.isView(t)){if((n=t.byteLength)===e.byteLength)for(;n--&&t[n]===e[n];);return n===-1}if(!r||typeof t=="object"){n=0;for(r in t)if(T.call(t,r)&&++n&&!T.call(e,r)||!(r in e)||!v(t[r],e[r]))return!1;return Object.keys(e).length===n}}return t!==t&&e!==e}function se(t){var e=S.useRef(t),r=S.useRef(0);return v(t,e.current)||(e.current=t,r.current+=1),S.useMemo(function(){return e.current},[r.current])}function ne(t,e){return S.useEffect(t,se(e))}const re=({cart:t,customer:e})=>{const{clientScriptLoaded:r}=h();return ne(()=>{const n=t?M(t):void 0,c=e?M(e):void 0;r&&window.nostojs(a=>{a.defaultSession().setResponseMode("HTML").setCart(n).setCustomer(c).viewOther().load()})},[r,t||[],e||{}]),o(y,{})};m.Nosto404=J,m.NostoCategory=Z,m.NostoCheckout=$,m.NostoContext=O,m.NostoHome=g,m.NostoOrder=k,m.NostoOther=W,m.NostoPlacement=ee,m.NostoProduct=Y,m.NostoProvider=te,m.NostoSearch=K,m.NostoSession=re,m.useNostoContext=h,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
9
|
+
*/var H=R.default,$=Symbol.for("react.element"),G=Symbol.for("react.fragment"),z=Object.prototype.hasOwnProperty,J=H.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,W={key:!0,ref:!0,__self:!0,__source:!0};function A(t,n,e){var r,c={},d=null,i=null;e!==void 0&&(d=""+e),n.key!==void 0&&(d=""+n.key),n.ref!==void 0&&(i=n.ref);for(r in n)z.call(n,r)&&!W.hasOwnProperty(r)&&(c[r]=n[r]);if(t&&t.defaultProps)for(r in n=t.defaultProps,n)c[r]===void 0&&(c[r]=n[r]);return{$$typeof:$,type:t,key:d,ref:i,props:c,_owner:J.current}}b.Fragment=G,b.jsx=A,b.jsxs=A,E.exports=b;const s=E.exports.jsx,w=E.exports.jsxs,_=E.exports.Fragment;function B(){const{clientScriptLoaded:t,currentVariation:n,responseMode:e,recommendationComponent:r,useRenderCampaigns:c}=h(),{renderCampaigns:d,pageTypeUpdated:i}=c("404");return m.useEffect(()=>{t&&i&&window.nostojs(a=>{a.defaultSession().setVariation(n).setResponseMode(e).viewNotFound().setPlacements(a.placements.getPlacements()).load().then(p=>{d(p,a)})})},[t,n,r,i]),s(_,{children:s("div",{className:"nosto_page_type",style:{display:"none"},children:"notfound"})})}function Y(){const{clientScriptLoaded:t,currentVariation:n,responseMode:e,recommendationComponent:r,useRenderCampaigns:c}=h(),{renderCampaigns:d,pageTypeUpdated:i}=c("other");return m.useEffect(()=>{t&&i&&window.nostojs(a=>{a.defaultSession().setVariation(n).setResponseMode(e).viewOther().setPlacements(a.placements.getPlacements()).load().then(p=>{d(p,a)})})},[t,n,r,i]),s(_,{children:s("div",{className:"nosto_page_type",style:{display:"none"},children:"other"})})}function Z(){const{clientScriptLoaded:t,currentVariation:n,responseMode:e,recommendationComponent:r,useRenderCampaigns:c}=h(),{renderCampaigns:d,pageTypeUpdated:i}=c("checkout");return m.useEffect(()=>{t&&i&&window.nostojs(a=>{a.defaultSession().setVariation(n).setResponseMode(e).viewCart().setPlacements(a.placements.getPlacements()).load().then(p=>{d(p,a)})})},[t,n,r,i]),s(_,{children:s("div",{className:"nosto_page_type",style:{display:"none"},children:"cart"})})}function F(t){const n=c=>String(c)==="[object Object]";if(!n(t))return!1;const e=t.constructor;if(e===void 0)return!0;const r=e.prototype;return!(!n(r)||!r.hasOwnProperty("isPrototypeOf"))}function U(t,n){if(t===n)return!0;if(t instanceof Date&&n instanceof Date)return t.getTime()===n.getTime();if(t instanceof Array&&n instanceof Array)return t.length!==n.length?!1:t.every((e,r)=>U(e,n[r]));if(F(t)&&F(n)){const e=Object.entries(t);return e.length!==Object.keys(n).length?!1:e.every(([r,c])=>U(c,n[r]))}return!1}function I(t,n){return m.useEffect(t,K(n))}function K(t){const n=m.useRef(t),e=m.useRef(0);return U(t,n.current)||(n.current=t,e.current+=1),m.useMemo(()=>n.current,[e.current])}function Q(t){const{product:n,tagging:e}=t,{clientScriptLoaded:r,currentVariation:c,responseMode:d,recommendationComponent:i,useRenderCampaigns:a}=h(),{renderCampaigns:p,pageTypeUpdated:f}=a("product");return I(()=>{r&&f&&window.nostojs(o=>{o.defaultSession().setResponseMode(d).viewProduct(n).setPlacements(o.placements.getPlacements()).load().then(y=>{p(y,o)})})},[r,c,n,i,f]),w(_,{children:[s("div",{className:"nosto_page_type",style:{display:"none"},children:"product"}),w("div",{className:"nosto_product",style:{display:"none"},children:[(e==null?void 0:e.variationId)&&s("span",{className:"variation_id",children:e.variationId}),n&&s("span",{className:"product_id",children:n}),(e==null?void 0:e.name)&&s("span",{className:"name",children:e.name}),(e==null?void 0:e.url)&&s("span",{className:"url",children:e.url.toString()}),(e==null?void 0:e.imageUrl)&&s("span",{className:"image_url",children:e.imageUrl.toString()}),(e==null?void 0:e.availability)&&s("span",{className:"availability",children:e.availability}),(e==null?void 0:e.price)&&s("span",{className:"price",children:e.price}),(e==null?void 0:e.listPrice)&&s("span",{className:"list_price",children:e.listPrice}),(e==null?void 0:e.priceCurrencyCode)&&s("span",{className:"price_currency_code",children:e.priceCurrencyCode}),(e==null?void 0:e.brand)&&s("span",{className:"brand",children:e.brand}),(e==null?void 0:e.description)&&s("span",{className:"description",children:e.description}),(e==null?void 0:e.googleCategory)&&s("span",{className:"description",children:e.googleCategory}),(e==null?void 0:e.condition)&&s("span",{className:"condition",children:e.condition}),(e==null?void 0:e.gender)&&s("span",{className:"gender",children:e.gender}),(e==null?void 0:e.ageGroup)&&s("span",{className:"age_group",children:e.ageGroup}),(e==null?void 0:e.gtin)&&s("span",{className:"gtin",children:e.gtin}),(e==null?void 0:e.category)&&(e==null?void 0:e.category.map((o,y)=>s("span",{className:"category",children:o},y))),(e==null?void 0:e.tags1)&&e.tags1.map((o,y)=>s("span",{className:"tag1",children:o},y)),(e==null?void 0:e.tags2)&&e.tags2.map((o,y)=>s("span",{className:"tag2",children:o},y)),(e==null?void 0:e.tags3)&&e.tags3.map((o,y)=>s("span",{className:"tag3",children:o},y)),(e==null?void 0:e.ratingValue)&&s("span",{className:"rating_value",children:e.ratingValue}),(e==null?void 0:e.reviewCount)&&s("span",{className:"review_count",children:e.reviewCount}),(e==null?void 0:e.alternateImageUrls)&&e.alternateImageUrls.map((o,y)=>s("span",{className:"alternate_image_url",children:o.toString()},y)),(e==null?void 0:e.customFields)&&Object.keys(e.customFields).map((o,y)=>e.customFields&&e.customFields[o]&&s("span",{className:o,children:e.customFields[o]},y)),(e==null?void 0:e.skus)&&e.skus.map((o,y)=>w("span",{className:"nosto_sku",children:[(o==null?void 0:o.id)&&s("span",{className:"product_id",children:o.id}),(o==null?void 0:o.name)&&s("span",{className:"name",children:o.name}),(o==null?void 0:o.price)&&s("span",{className:"price",children:o.price}),(o==null?void 0:o.listPrice)&&s("span",{className:"list_price",children:o.listPrice}),(o==null?void 0:o.url)&&s("span",{className:"url",children:o.url.toString()}),(o==null?void 0:o.imageUrl)&&s("span",{className:"image_url",children:o.imageUrl.toString()}),(o==null?void 0:o.gtin)&&s("span",{className:"gtin",children:o.gtin}),(o==null?void 0:o.availability)&&s("span",{className:"availability",children:o.availability}),(o==null?void 0:o.customFields)&&Object.keys(o.customFields).map((j,O)=>o.customFields&&o.customFields[j]&&s("span",{className:j,children:o.customFields[j]},O))]},y))]})]})}function X(t){const{category:n}=t,{clientScriptLoaded:e,currentVariation:r,responseMode:c,recommendationComponent:d,useRenderCampaigns:i}=h(),{renderCampaigns:a,pageTypeUpdated:p}=i("home");return m.useEffect(()=>{e&&p&&window.nostojs(f=>{f.defaultSession().setVariation(r).setResponseMode(c).viewCategory(n).setPlacements(f.placements.getPlacements()).load().then(o=>{a(o,f)})})},[e,n,r,d,p]),w(_,{children:[s("div",{className:"nosto_page_type",style:{display:"none"},children:"category"}),s("div",{className:"nosto_category",style:{display:"none"},children:n})]})}function g(t){const{query:n}=t,{clientScriptLoaded:e,currentVariation:r,responseMode:c,recommendationComponent:d,useRenderCampaigns:i}=h(),{renderCampaigns:a,pageTypeUpdated:p}=i("search");return m.useEffect(()=>{e&&p&&window.nostojs(f=>{f.defaultSession().setVariation(r).setResponseMode(c).viewSearch(n).setPlacements(f.placements.getPlacements()).load().then(o=>{a(o,f)})})},[e,r,n,d,p]),w(_,{children:[s("div",{className:"nosto_page_type",style:{display:"none"},children:"search"}),s("div",{className:"nosto_search",style:{display:"none"},children:n})]})}function P(t){return!t||typeof t!="object"||k(t)||ee(t)?t:Array.isArray(t)?t.map(P):Object.keys(t).reduce((n,e)=>{var r=e[0].toLowerCase()+e.slice(1).replace(/([A-Z]+)/g,(c,d)=>"_"+d.toLowerCase());return n[r]=P(t[e]),n},{})}function k(t){return Object.prototype.toString.call(t)==="[object Date]"}function ee(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function te(t){const{order:n}=t,{clientScriptLoaded:e,currentVariation:r,responseMode:c,recommendationComponent:d,useRenderCampaigns:i}=h(),{renderCampaigns:a,pageTypeUpdated:p}=i("order");return m.useEffect(()=>{e&&p&&window.nostojs(f=>{f.defaultSession().setVariation(r).setResponseMode(c).addOrder(P(n)).setPlacements(f.placements.getPlacements()).load().then(o=>{a(o,f)})})},[e,r,d,p]),w(_,{children:[s("div",{className:"nosto_page_type",style:{display:"none"},children:"order"}),s("div",{className:"nosto_order",style:{display:"none"},children:n.purchase.number})]})}function ne(){const{clientScriptLoaded:t,currentVariation:n,responseMode:e,recommendationComponent:r,useRenderCampaigns:c}=h(),{renderCampaigns:d,pageTypeUpdated:i}=c("home");return m.useEffect(()=>{t&&i&&window.nostojs(a=>{a.defaultSession().setVariation(n).setResponseMode(e).viewFrontPage().setPlacements(a.placements.getPlacements()).load().then(p=>{d(p,a)})})},[t,n,r,i]),s(_,{children:s("div",{className:"nosto_page_type",style:{display:"none"},children:"front"})})}function oe(t){const{id:n,pageType:e}=t;return s("div",{className:"nosto_element",id:n},n+(e||""))}function se(t){let{account:n,currentVariation:e="",multiCurrency:r=!1,host:c,children:d,recommendationComponent:i,shopifyMarkets:a}=t;const[p,f]=R.default.useState(!1),o=R.default.useMemo(()=>p,[p]);e=r?e:"";const y=m.isValidElement(i)?"JSON_ORIGINAL":"HTML";function j(v){return R.default.cloneElement(i,{nostoRecommendation:v.nostoRecommendation})}const[O,ae]=m.useState(""),ce=function(v=""){const S=m.useRef({});m.useEffect(()=>{O!=v&&ae(v)},[]);const M=v==O;function l(N,C){if(y=="HTML")C.placements.injectCampaigns(N.recommendations);else{const L=N.campaigns.recommendations;for(const T in L){let ie=L[T],de="#"+T,q=()=>document.querySelector(de);q()&&(S.current[T]||(S.current[T]=x.createRoot(q())),S.current[T].render(s(j,{nostoRecommendation:ie})))}}}return{renderCampaigns:l,pageTypeUpdated:M}};return m.useEffect(()=>{var v,S,M;if(window.nostojs||(window.nostojs=l=>{(window.nostojs.q=window.nostojs.q||[]).push(l)},window.nostojs(l=>l.setAutoLoad(!1))),!document.querySelectorAll("[nosto-client-script]").length&&!a){const l=document.createElement("script");l.type="text/javascript",l.src="//"+(c||"connect.nosto.com")+"/include/"+n,l.async=!0,l.setAttribute("nosto-client-script",""),l.onload=()=>{var N;typeof jest!="undefined"&&((N=window.nosto)==null||N.reload({site:"localhost"})),f(!0)},document.body.appendChild(l)}if(a){const l=document.querySelector("[nosto-client-script]"),N=document.querySelector("#nosto-sandbox");if(!l||(l==null?void 0:l.getAttribute("nosto-language"))!=(a==null?void 0:a.language)||(l==null?void 0:l.getAttribute("nosto-market-id"))!=(a==null?void 0:a.marketId)){p&&f(!1),(v=l==null?void 0:l.parentNode)==null||v.removeChild(l),(S=N==null?void 0:N.parentNode)==null||S.removeChild(N);const C=document.createElement("script");C.type="text/javascript",C.src="//"+(c||"connect.nosto.com")+`/script/shopify/market/nosto.js?merchant=${n}&market=${a.marketId||""}&locale=${((M=a==null?void 0:a.language)==null?void 0:M.toLowerCase())||""}`,C.async=!0,C.setAttribute("nosto-client-script",""),C.setAttribute("nosto-language",(a==null?void 0:a.language)||""),C.setAttribute("nosto-market-id",String(a==null?void 0:a.marketId)),C.onload=()=>{var L;typeof jest!="undefined"&&((L=window.nosto)==null||L.reload({site:"localhost"})),f(!0)},document.body.appendChild(C)}}},[p,a]),s(V.Provider,{value:{account:n,clientScriptLoaded:o,currentVariation:e,responseMode:y,recommendationComponent:i,useRenderCampaigns:ce,pageType:O},children:d})}function re(t){const{cart:n,customer:e}=t,{clientScriptLoaded:r}=h();return I(()=>{const c=n?P(n):void 0,d=e?P(e):void 0;r&&window.nostojs(i=>{i.defaultSession().setResponseMode("HTML").setCart(c).setCustomer(d).viewOther().load()})},[r,n,e]),s(_,{})}u.Nosto404=B,u.NostoCategory=X,u.NostoCheckout=Z,u.NostoContext=V,u.NostoHome=ne,u.NostoOrder=te,u.NostoOther=Y,u.NostoPlacement=oe,u.NostoProduct=Q,u.NostoProvider=se,u.NostoSearch=g,u.NostoSession=re,u.useNostoContext=h,Object.defineProperties(u,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nosto/nosto-react",
|
|
3
3
|
"description": "Component library to simply implementing Nosto on React.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"author": "Mridang Agarwalla, Dominik Gilg",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"repository": {
|
|
@@ -14,31 +14,39 @@
|
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
16
|
"dev": "vite",
|
|
17
|
-
"build": "tsc && vite build",
|
|
17
|
+
"build": "tsc && vite build && typedoc src/index.client.ts",
|
|
18
18
|
"preview": "vite preview",
|
|
19
19
|
"prepare": "vite build",
|
|
20
20
|
"typecheck": "tsc",
|
|
21
21
|
"tslint": "tslint 'src/**/*.ts?(x)'",
|
|
22
22
|
"clean": "rimraf dist",
|
|
23
|
-
"prettier": "prettier '
|
|
24
|
-
"prettier:fix": "prettier '
|
|
23
|
+
"prettier": "prettier '{src,spec}/*/**' --list-different",
|
|
24
|
+
"prettier:fix": "prettier '{src,spec}/*/**' --write",
|
|
25
|
+
"test": "jest spec"
|
|
25
26
|
},
|
|
26
27
|
"files": [
|
|
27
28
|
"dist",
|
|
28
29
|
"src"
|
|
29
30
|
],
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"snakeize": "^0.1.0",
|
|
32
|
-
"use-deep-compare-effect": "^1.3.1",
|
|
33
|
-
"@vitejs/plugin-react": "^1.3.0"
|
|
34
|
-
},
|
|
35
31
|
"devDependencies": {
|
|
32
|
+
"@testing-library/jest-dom": "^5.16.5",
|
|
33
|
+
"@testing-library/react": "^14.0.0",
|
|
34
|
+
"@testing-library/user-event": "^14.4.3",
|
|
35
|
+
"@types/jest": "^29.5.0",
|
|
36
36
|
"@types/react": "^18.0.0",
|
|
37
37
|
"@types/react-dom": "^18.0.0",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
38
|
+
"@types/user-event": "^4.1.1",
|
|
39
|
+
"@vitejs/plugin-react": "^1.3.0",
|
|
40
|
+
"jest": "^29.5.0",
|
|
41
|
+
"jest-environment-jsdom": "^29.5.0",
|
|
40
42
|
"prettier": "^2.0.5",
|
|
41
|
-
"
|
|
43
|
+
"react": "*",
|
|
44
|
+
"react-dom": "*",
|
|
45
|
+
"rimraf": "^3.0.2",
|
|
46
|
+
"ts-jest": "^29.1.0",
|
|
47
|
+
"typedoc": "^0.24.1",
|
|
48
|
+
"typescript": "^4.6.3",
|
|
49
|
+
"vite": "^2.9.9"
|
|
42
50
|
},
|
|
43
51
|
"main": "./dist/index.umd.client.js",
|
|
44
52
|
"module": "./dist/index.es.client.js",
|
|
@@ -53,5 +61,13 @@
|
|
|
53
61
|
"bugs": {
|
|
54
62
|
"url": "https://github.com/Nosto/nosto-react/issues"
|
|
55
63
|
},
|
|
56
|
-
"homepage": "https://github.com/Nosto/nosto-react#readme"
|
|
64
|
+
"homepage": "https://github.com/Nosto/nosto-react#readme",
|
|
65
|
+
"jest": {
|
|
66
|
+
"preset": "ts-jest",
|
|
67
|
+
"testEnvironment": "jsdom",
|
|
68
|
+
"testEnvironmentOptions": {
|
|
69
|
+
"resources": "usable",
|
|
70
|
+
"runScripts": "dangerously"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
57
73
|
}
|