@nosto/nosto-react 0.4.0 → 0.4.1
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/index.es.client.js +12 -12
- package/dist/index.umd.client.js +2 -2
- package/package.json +1 -1
- package/src/components/Category/index.client.tsx +2 -1
- package/src/components/Checkout/index.client.tsx +4 -2
- package/src/components/Fohofo/index.client.tsx +4 -2
- package/src/components/Home/index.client.tsx +4 -2
- package/src/components/Order/index.client.tsx +2 -1
- package/src/components/Other/index.client.tsx +4 -3
- package/src/components/Product/index.client.tsx +2 -1
- package/src/components/Search/index.client.tsx +5 -2
package/dist/index.es.client.js
CHANGED
|
@@ -48,7 +48,7 @@ reactJsxRuntime_production_min.jsxs = q;
|
|
|
48
48
|
const jsx = jsxRuntime.exports.jsx;
|
|
49
49
|
const jsxs = jsxRuntime.exports.jsxs;
|
|
50
50
|
const Fragment = jsxRuntime.exports.Fragment;
|
|
51
|
-
function Nosto404() {
|
|
51
|
+
function Nosto404(props) {
|
|
52
52
|
const {
|
|
53
53
|
clientScriptLoaded,
|
|
54
54
|
currentVariation,
|
|
@@ -63,7 +63,7 @@ function Nosto404() {
|
|
|
63
63
|
useEffect(() => {
|
|
64
64
|
if (clientScriptLoaded && pageTypeUpdated) {
|
|
65
65
|
window.nostojs((api) => {
|
|
66
|
-
api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewNotFound().setPlacements(api.placements.getPlacements()).load().then((data) => {
|
|
66
|
+
api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewNotFound().setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
|
|
67
67
|
renderCampaigns(data, api);
|
|
68
68
|
});
|
|
69
69
|
});
|
|
@@ -79,7 +79,7 @@ function Nosto404() {
|
|
|
79
79
|
})
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
-
function NostoOther() {
|
|
82
|
+
function NostoOther(props) {
|
|
83
83
|
const {
|
|
84
84
|
clientScriptLoaded,
|
|
85
85
|
currentVariation,
|
|
@@ -94,7 +94,7 @@ function NostoOther() {
|
|
|
94
94
|
useEffect(() => {
|
|
95
95
|
if (clientScriptLoaded && pageTypeUpdated) {
|
|
96
96
|
window.nostojs((api) => {
|
|
97
|
-
api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewOther().setPlacements(api.placements.getPlacements()).load().then((data) => {
|
|
97
|
+
api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewOther().setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
|
|
98
98
|
renderCampaigns(data, api);
|
|
99
99
|
});
|
|
100
100
|
});
|
|
@@ -110,7 +110,7 @@ function NostoOther() {
|
|
|
110
110
|
})
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
|
-
function NostoCheckout() {
|
|
113
|
+
function NostoCheckout(props) {
|
|
114
114
|
const {
|
|
115
115
|
clientScriptLoaded,
|
|
116
116
|
currentVariation,
|
|
@@ -125,7 +125,7 @@ function NostoCheckout() {
|
|
|
125
125
|
useEffect(() => {
|
|
126
126
|
if (clientScriptLoaded && pageTypeUpdated) {
|
|
127
127
|
window.nostojs((api) => {
|
|
128
|
-
api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewCart().setPlacements(api.placements.getPlacements()).load().then((data) => {
|
|
128
|
+
api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewCart().setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
|
|
129
129
|
renderCampaigns(data, api);
|
|
130
130
|
});
|
|
131
131
|
});
|
|
@@ -209,7 +209,7 @@ function NostoProduct(props) {
|
|
|
209
209
|
useDeepCompareEffect(() => {
|
|
210
210
|
if (clientScriptLoaded && pageTypeUpdated) {
|
|
211
211
|
window.nostojs((api) => {
|
|
212
|
-
api.defaultSession().setResponseMode(responseMode).viewProduct(product).setPlacements(api.placements.getPlacements()).load().then((data) => {
|
|
212
|
+
api.defaultSession().setResponseMode(responseMode).viewProduct(product).setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
|
|
213
213
|
renderCampaigns(data, api);
|
|
214
214
|
});
|
|
215
215
|
});
|
|
@@ -351,7 +351,7 @@ function NostoCategory(props) {
|
|
|
351
351
|
useEffect(() => {
|
|
352
352
|
if (clientScriptLoaded && pageTypeUpdated) {
|
|
353
353
|
window.nostojs((api) => {
|
|
354
|
-
api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewCategory(category).setPlacements(api.placements.getPlacements()).load().then((data) => {
|
|
354
|
+
api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewCategory(category).setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
|
|
355
355
|
renderCampaigns(data, api);
|
|
356
356
|
});
|
|
357
357
|
});
|
|
@@ -391,7 +391,7 @@ function NostoSearch(props) {
|
|
|
391
391
|
useEffect(() => {
|
|
392
392
|
if (clientScriptLoaded && pageTypeUpdated) {
|
|
393
393
|
window.nostojs((api) => {
|
|
394
|
-
api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewSearch(query).setPlacements(api.placements.getPlacements()).load().then((data) => {
|
|
394
|
+
api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewSearch(query).setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
|
|
395
395
|
renderCampaigns(data, api);
|
|
396
396
|
});
|
|
397
397
|
});
|
|
@@ -455,7 +455,7 @@ function NostoOrder(props) {
|
|
|
455
455
|
useEffect(() => {
|
|
456
456
|
if (clientScriptLoaded && pageTypeUpdated) {
|
|
457
457
|
window.nostojs((api) => {
|
|
458
|
-
api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).addOrder(snakeize(order)).setPlacements(api.placements.getPlacements()).load().then((data) => {
|
|
458
|
+
api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).addOrder(snakeize(order)).setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
|
|
459
459
|
renderCampaigns(data, api);
|
|
460
460
|
});
|
|
461
461
|
});
|
|
@@ -477,7 +477,7 @@ function NostoOrder(props) {
|
|
|
477
477
|
})]
|
|
478
478
|
});
|
|
479
479
|
}
|
|
480
|
-
function NostoHome() {
|
|
480
|
+
function NostoHome(props) {
|
|
481
481
|
const {
|
|
482
482
|
clientScriptLoaded,
|
|
483
483
|
currentVariation,
|
|
@@ -492,7 +492,7 @@ function NostoHome() {
|
|
|
492
492
|
useEffect(() => {
|
|
493
493
|
if (clientScriptLoaded && pageTypeUpdated) {
|
|
494
494
|
window.nostojs((api) => {
|
|
495
|
-
api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewFrontPage().setPlacements(api.placements.getPlacements()).load().then((data) => {
|
|
495
|
+
api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewFrontPage().setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
|
|
496
496
|
renderCampaigns(data, api);
|
|
497
497
|
});
|
|
498
498
|
});
|
package/dist/index.umd.client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(u
|
|
1
|
+
(function(f,u){typeof exports=="object"&&typeof module!="undefined"?u(exports,require("react"),require("react-dom/client")):typeof define=="function"&&define.amd?define(["exports","react","react-dom/client"],u):(f=typeof globalThis!="undefined"?globalThis:f||self,u(f["@nosto/nosto-react"]={},f.React,f.ReactDOM))})(this,function(f,u,x){"use strict";function D(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var R=D(u);const V=u.createContext({account:"",currentVariation:"",pageType:"",responseMode:"HTML",clientScriptLoaded:!1,useRenderCampaigns:()=>{}});function h(){const t=u.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 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"}})});
|
|
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,i={},l=null,m=null;e!==void 0&&(l=""+e),n.key!==void 0&&(l=""+n.key),n.ref!==void 0&&(m=n.ref);for(r in n)z.call(n,r)&&!W.hasOwnProperty(r)&&(i[r]=n[r]);if(t&&t.defaultProps)for(r in n=t.defaultProps,n)i[r]===void 0&&(i[r]=n[r]);return{$$typeof:$,type:t,key:l,ref:m,props:i,_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(t){const{clientScriptLoaded:n,currentVariation:e,responseMode:r,recommendationComponent:i,useRenderCampaigns:l}=h(),{renderCampaigns:m,pageTypeUpdated:a}=l("404");return u.useEffect(()=>{n&&a&&window.nostojs(c=>{c.defaultSession().setVariation(e).setResponseMode(r).viewNotFound().setPlacements(t.placements||c.placements.getPlacements()).load().then(d=>{m(d,c)})})},[n,e,i,a]),s(_,{children:s("div",{className:"nosto_page_type",style:{display:"none"},children:"notfound"})})}function Y(t){const{clientScriptLoaded:n,currentVariation:e,responseMode:r,recommendationComponent:i,useRenderCampaigns:l}=h(),{renderCampaigns:m,pageTypeUpdated:a}=l("other");return u.useEffect(()=>{n&&a&&window.nostojs(c=>{c.defaultSession().setVariation(e).setResponseMode(r).viewOther().setPlacements(t.placements||c.placements.getPlacements()).load().then(d=>{m(d,c)})})},[n,e,i,a]),s(_,{children:s("div",{className:"nosto_page_type",style:{display:"none"},children:"other"})})}function Z(t){const{clientScriptLoaded:n,currentVariation:e,responseMode:r,recommendationComponent:i,useRenderCampaigns:l}=h(),{renderCampaigns:m,pageTypeUpdated:a}=l("checkout");return u.useEffect(()=>{n&&a&&window.nostojs(c=>{c.defaultSession().setVariation(e).setResponseMode(r).viewCart().setPlacements(t.placements||c.placements.getPlacements()).load().then(d=>{m(d,c)})})},[n,e,i,a]),s(_,{children:s("div",{className:"nosto_page_type",style:{display:"none"},children:"cart"})})}function F(t){const n=i=>String(i)==="[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,i])=>U(i,n[r]))}return!1}function I(t,n){return u.useEffect(t,K(n))}function K(t){const n=u.useRef(t),e=u.useRef(0);return U(t,n.current)||(n.current=t,e.current+=1),u.useMemo(()=>n.current,[e.current])}function Q(t){const{product:n,tagging:e}=t,{clientScriptLoaded:r,currentVariation:i,responseMode:l,recommendationComponent:m,useRenderCampaigns:a}=h(),{renderCampaigns:c,pageTypeUpdated:d}=a("product");return I(()=>{r&&d&&window.nostojs(o=>{o.defaultSession().setResponseMode(l).viewProduct(n).setPlacements(t.placements||o.placements.getPlacements()).load().then(y=>{c(y,o)})})},[r,i,n,m,d]),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:i,recommendationComponent:l,useRenderCampaigns:m}=h(),{renderCampaigns:a,pageTypeUpdated:c}=m("home");return u.useEffect(()=>{e&&c&&window.nostojs(d=>{d.defaultSession().setVariation(r).setResponseMode(i).viewCategory(n).setPlacements(t.placements||d.placements.getPlacements()).load().then(o=>{a(o,d)})})},[e,n,r,l,c]),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:i,recommendationComponent:l,useRenderCampaigns:m}=h(),{renderCampaigns:a,pageTypeUpdated:c}=m("search");return u.useEffect(()=>{e&&c&&window.nostojs(d=>{d.defaultSession().setVariation(r).setResponseMode(i).viewSearch(n).setPlacements(t.placements||d.placements.getPlacements()).load().then(o=>{a(o,d)})})},[e,r,n,l,c]),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,(i,l)=>"_"+l.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:i,recommendationComponent:l,useRenderCampaigns:m}=h(),{renderCampaigns:a,pageTypeUpdated:c}=m("order");return u.useEffect(()=>{e&&c&&window.nostojs(d=>{d.defaultSession().setVariation(r).setResponseMode(i).addOrder(P(n)).setPlacements(t.placements||d.placements.getPlacements()).load().then(o=>{a(o,d)})})},[e,r,l,c]),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(t){const{clientScriptLoaded:n,currentVariation:e,responseMode:r,recommendationComponent:i,useRenderCampaigns:l}=h(),{renderCampaigns:m,pageTypeUpdated:a}=l("home");return u.useEffect(()=>{n&&a&&window.nostojs(c=>{c.defaultSession().setVariation(e).setResponseMode(r).viewFrontPage().setPlacements(t.placements||c.placements.getPlacements()).load().then(d=>{m(d,c)})})},[n,e,i,a]),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:i,children:l,recommendationComponent:m,shopifyMarkets:a}=t;const[c,d]=R.default.useState(!1),o=R.default.useMemo(()=>c,[c]);e=r?e:"";const y=u.isValidElement(m)?"JSON_ORIGINAL":"HTML";function j(v){return R.default.cloneElement(m,{nostoRecommendation:v.nostoRecommendation})}const[O,ae]=u.useState(""),ce=function(v=""){const S=u.useRef({});u.useEffect(()=>{O!=v&&ae(v)},[]);const M=v==O;function p(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:p,pageTypeUpdated:M}};return u.useEffect(()=>{var v,S,M;if(window.nostojs||(window.nostojs=p=>{(window.nostojs.q=window.nostojs.q||[]).push(p)},window.nostojs(p=>p.setAutoLoad(!1))),!document.querySelectorAll("[nosto-client-script]").length&&!a){const p=document.createElement("script");p.type="text/javascript",p.src="//"+(i||"connect.nosto.com")+"/include/"+n,p.async=!0,p.setAttribute("nosto-client-script",""),p.onload=()=>{var N;typeof jest!="undefined"&&((N=window.nosto)==null||N.reload({site:"localhost"})),d(!0)},document.body.appendChild(p)}if(a){const p=document.querySelector("[nosto-client-script]"),N=document.querySelector("#nosto-sandbox");if(!p||(p==null?void 0:p.getAttribute("nosto-language"))!=(a==null?void 0:a.language)||(p==null?void 0:p.getAttribute("nosto-market-id"))!=(a==null?void 0:a.marketId)){c&&d(!1),(v=p==null?void 0:p.parentNode)==null||v.removeChild(p),(S=N==null?void 0:N.parentNode)==null||S.removeChild(N);const C=document.createElement("script");C.type="text/javascript",C.src="//"+(i||"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"})),d(!0)},document.body.appendChild(C)}}},[c,a]),s(V.Provider,{value:{account:n,clientScriptLoaded:o,currentVariation:e,responseMode:y,recommendationComponent:m,useRenderCampaigns:ce,pageType:O},children:l})}function re(t){const{cart:n,customer:e}=t,{clientScriptLoaded:r}=h();return I(()=>{const i=n?P(n):void 0,l=e?P(e):void 0;r&&window.nostojs(m=>{m.defaultSession().setResponseMode("HTML").setCart(i).setCustomer(l).viewOther().load()})},[r,n,e]),s(_,{})}f.Nosto404=B,f.NostoCategory=X,f.NostoCheckout=Z,f.NostoContext=V,f.NostoHome=ne,f.NostoOrder=te,f.NostoOther=Y,f.NostoPlacement=oe,f.NostoProduct=Q,f.NostoProvider=se,f.NostoSearch=g,f.NostoSession=re,f.useNostoContext=h,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -25,6 +25,7 @@ import { useNostoContext } from "../Provider/context.client";
|
|
|
25
25
|
*/
|
|
26
26
|
export default function NostoCategory(props: {
|
|
27
27
|
category: string;
|
|
28
|
+
placements?: string[];
|
|
28
29
|
}): JSX.Element {
|
|
29
30
|
const { category } = props;
|
|
30
31
|
const {
|
|
@@ -45,7 +46,7 @@ export default function NostoCategory(props: {
|
|
|
45
46
|
.setVariation(currentVariation)
|
|
46
47
|
.setResponseMode(responseMode)
|
|
47
48
|
.viewCategory(category)
|
|
48
|
-
.setPlacements(api.placements.getPlacements())
|
|
49
|
+
.setPlacements(props.placements || api.placements.getPlacements())
|
|
49
50
|
.load()
|
|
50
51
|
.then((data) => {
|
|
51
52
|
renderCampaigns(data, api);
|
|
@@ -21,7 +21,9 @@ import { useNostoContext } from "../Provider/context.client";
|
|
|
21
21
|
* @group Personalisation Components
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
export default function NostoCheckout(
|
|
24
|
+
export default function NostoCheckout(props: {
|
|
25
|
+
placements?: string[];
|
|
26
|
+
}): JSX.Element {
|
|
25
27
|
const {
|
|
26
28
|
clientScriptLoaded,
|
|
27
29
|
currentVariation,
|
|
@@ -40,7 +42,7 @@ export default function NostoCheckout(): JSX.Element {
|
|
|
40
42
|
.setVariation(currentVariation)
|
|
41
43
|
.setResponseMode(responseMode)
|
|
42
44
|
.viewCart()
|
|
43
|
-
.setPlacements(api.placements.getPlacements())
|
|
45
|
+
.setPlacements(props.placements || api.placements.getPlacements())
|
|
44
46
|
.load()
|
|
45
47
|
.then((data) => {
|
|
46
48
|
renderCampaigns(data, api);
|
|
@@ -21,7 +21,9 @@ import { useNostoContext } from "../Provider/context.client";
|
|
|
21
21
|
*
|
|
22
22
|
* @group Personalisation Components
|
|
23
23
|
*/
|
|
24
|
-
export default function Nosto404(
|
|
24
|
+
export default function Nosto404(props: {
|
|
25
|
+
placements?: string[];
|
|
26
|
+
}): JSX.Element {
|
|
25
27
|
const {
|
|
26
28
|
clientScriptLoaded,
|
|
27
29
|
currentVariation,
|
|
@@ -40,7 +42,7 @@ export default function Nosto404(): JSX.Element {
|
|
|
40
42
|
.setVariation(currentVariation)
|
|
41
43
|
.setResponseMode(responseMode)
|
|
42
44
|
.viewNotFound()
|
|
43
|
-
.setPlacements(api.placements.getPlacements())
|
|
45
|
+
.setPlacements(props.placements || api.placements.getPlacements())
|
|
44
46
|
.load()
|
|
45
47
|
.then((data) => {
|
|
46
48
|
renderCampaigns(data, api);
|
|
@@ -24,7 +24,9 @@ import { useNostoContext } from "../Provider/context.client";
|
|
|
24
24
|
*
|
|
25
25
|
* @group Personalisation Components
|
|
26
26
|
*/
|
|
27
|
-
export default function NostoHome(
|
|
27
|
+
export default function NostoHome(props: {
|
|
28
|
+
placements?: string[];
|
|
29
|
+
}): JSX.Element {
|
|
28
30
|
const {
|
|
29
31
|
clientScriptLoaded,
|
|
30
32
|
currentVariation,
|
|
@@ -43,7 +45,7 @@ export default function NostoHome(): JSX.Element {
|
|
|
43
45
|
.setVariation(currentVariation)
|
|
44
46
|
.setResponseMode(responseMode)
|
|
45
47
|
.viewFrontPage()
|
|
46
|
-
.setPlacements(api.placements.getPlacements())
|
|
48
|
+
.setPlacements(props.placements || api.placements.getPlacements())
|
|
47
49
|
.load()
|
|
48
50
|
.then((data) => {
|
|
49
51
|
renderCampaigns(data, api);
|
|
@@ -24,6 +24,7 @@ import { snakeize } from "../../utils/snakeize";
|
|
|
24
24
|
*/
|
|
25
25
|
export default function NostoOrder(props: {
|
|
26
26
|
order: { purchase: Purchase };
|
|
27
|
+
placements?: string[];
|
|
27
28
|
}): JSX.Element {
|
|
28
29
|
const { order } = props;
|
|
29
30
|
const {
|
|
@@ -44,7 +45,7 @@ export default function NostoOrder(props: {
|
|
|
44
45
|
.setVariation(currentVariation)
|
|
45
46
|
.setResponseMode(responseMode)
|
|
46
47
|
.addOrder(snakeize(order))
|
|
47
|
-
.setPlacements(api.placements.getPlacements())
|
|
48
|
+
.setPlacements(props.placements || api.placements.getPlacements())
|
|
48
49
|
.load()
|
|
49
50
|
.then((data) => {
|
|
50
51
|
renderCampaigns(data, api);
|
|
@@ -20,7 +20,9 @@ import { useNostoContext } from "../Provider/context.client";
|
|
|
20
20
|
*
|
|
21
21
|
* @group Personalisation Components
|
|
22
22
|
*/
|
|
23
|
-
export default function NostoOther(
|
|
23
|
+
export default function NostoOther(props: {
|
|
24
|
+
placements?: string[];
|
|
25
|
+
}): JSX.Element {
|
|
24
26
|
const {
|
|
25
27
|
clientScriptLoaded,
|
|
26
28
|
currentVariation,
|
|
@@ -30,7 +32,6 @@ export default function NostoOther(): JSX.Element {
|
|
|
30
32
|
} = useNostoContext();
|
|
31
33
|
|
|
32
34
|
const { renderCampaigns, pageTypeUpdated } = useRenderCampaigns("other");
|
|
33
|
-
|
|
34
35
|
useEffect(() => {
|
|
35
36
|
if (clientScriptLoaded && pageTypeUpdated) {
|
|
36
37
|
window.nostojs((api) => {
|
|
@@ -39,7 +40,7 @@ export default function NostoOther(): JSX.Element {
|
|
|
39
40
|
.setVariation(currentVariation)
|
|
40
41
|
.setResponseMode(responseMode)
|
|
41
42
|
.viewOther()
|
|
42
|
-
.setPlacements(api.placements.getPlacements())
|
|
43
|
+
.setPlacements(props.placements || api.placements.getPlacements())
|
|
43
44
|
.load()
|
|
44
45
|
.then((data) => {
|
|
45
46
|
renderCampaigns(data, api);
|
|
@@ -29,6 +29,7 @@ import { useDeepCompareEffect } from "../../utils/hooks";
|
|
|
29
29
|
export default function NostoProduct(props: {
|
|
30
30
|
product: string;
|
|
31
31
|
tagging?: Product;
|
|
32
|
+
placements?: string[];
|
|
32
33
|
}): JSX.Element {
|
|
33
34
|
const { product, tagging } = props;
|
|
34
35
|
const {
|
|
@@ -48,7 +49,7 @@ export default function NostoProduct(props: {
|
|
|
48
49
|
.defaultSession()
|
|
49
50
|
.setResponseMode(responseMode)
|
|
50
51
|
.viewProduct(product)
|
|
51
|
-
.setPlacements(api.placements.getPlacements())
|
|
52
|
+
.setPlacements(props.placements || api.placements.getPlacements())
|
|
52
53
|
.load()
|
|
53
54
|
.then((data) => {
|
|
54
55
|
renderCampaigns(data, api);
|
|
@@ -24,7 +24,10 @@ import { useNostoContext } from "../Provider/context.client";
|
|
|
24
24
|
*
|
|
25
25
|
* @group Personalisation Components
|
|
26
26
|
*/
|
|
27
|
-
export default function NostoSearch(props: {
|
|
27
|
+
export default function NostoSearch(props: {
|
|
28
|
+
query: string,
|
|
29
|
+
placements?: string[];
|
|
30
|
+
}): JSX.Element {
|
|
28
31
|
const { query } = props;
|
|
29
32
|
const {
|
|
30
33
|
clientScriptLoaded,
|
|
@@ -44,7 +47,7 @@ export default function NostoSearch(props: { query: string }): JSX.Element {
|
|
|
44
47
|
.setVariation(currentVariation)
|
|
45
48
|
.setResponseMode(responseMode)
|
|
46
49
|
.viewSearch(query)
|
|
47
|
-
.setPlacements(api.placements.getPlacements())
|
|
50
|
+
.setPlacements(props.placements || api.placements.getPlacements())
|
|
48
51
|
.load()
|
|
49
52
|
.then((data) => {
|
|
50
53
|
renderCampaigns(data, api);
|