@okendo/shopify-hydrogen 2.0.2 → 2.0.3
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/cjs/index.js +1 -1
- package/dist/cjs/types/components/OkendoProvider/OkendoProvider.d.ts +6 -0
- package/dist/cjs/types/components/OkendoReviews/OkendoReviews.d.ts +1 -1
- package/dist/cjs/types/components/OkendoStarRating/OkendoStarRating.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/types/components/OkendoProvider/OkendoProvider.d.ts +6 -0
- package/dist/esm/types/components/OkendoReviews/OkendoReviews.d.ts +1 -1
- package/dist/esm/types/components/OkendoStarRating/OkendoStarRating.d.ts +1 -1
- package/dist/index.d.ts +8 -2
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("react");const e=({dataAttributes:e,metafieldContent:n=""})=>{const r=t.useRef(null),s=()=>{r.current&&window.okeWidgetApi.initWidget(r.current)};return t.useEffect((()=>(window.okeWidgetApi&&r.current?s():document.addEventListener("oke-script-loaded",s),()=>{document.removeEventListener("oke-script-loaded",s)})),[e]),t.createElement("div",{ref:r,key:JSON.stringify(e),...e,dangerouslySetInnerHTML:{__html:n}})},n=/^[0-9]*$/;function r(t){if(t)return`shopify-${n.test(t)?t:t.split("/").slice(-1)[0]}`}exports.OKENDO_PRODUCT_REVIEWS_FRAGMENT='#graphql\n\tfragment OkendoReviewsSnippet on Product {\n\t\tokendoReviewsSnippet: metafield(\n\t\t\tnamespace: "okendo"\n\t\t\tkey: "ReviewsWidgetSnippet"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n',exports.OKENDO_PRODUCT_STAR_RATING_FRAGMENT='#graphql\n\tfragment OkendoStarRatingSnippet on Product {\n\t\tokendoStarRatingSnippet: metafield(\n\t\t\tnamespace: "okendo"\n\t\t\tkey: "StarRatingSnippet"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n',exports.OkendoProvider=({okendoProviderData:e})=>{if(!e)return null;const{reviewsHeaderConfig:
|
|
1
|
+
"use strict";var t=require("react");const e=({dataAttributes:e,metafieldContent:n=""})=>{const r=t.useRef(null),s=()=>{r.current&&window.okeWidgetApi.initWidget(r.current)};return t.useEffect((()=>(window.okeWidgetApi&&r.current?s():document.addEventListener("oke-script-loaded",s),()=>{document.removeEventListener("oke-script-loaded",s)})),[e]),t.createElement("div",{ref:r,key:JSON.stringify(e),...e,dangerouslySetInnerHTML:{__html:n}})},n=/^[0-9]*$/;function r(t){if(t)return`shopify-${n.test(t)?t:t.split("/").slice(-1)[0]}`}exports.OKENDO_PRODUCT_REVIEWS_FRAGMENT='#graphql\n\tfragment OkendoReviewsSnippet on Product {\n\t\tokendoReviewsSnippet: metafield(\n\t\t\tnamespace: "okendo"\n\t\t\tkey: "ReviewsWidgetSnippet"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n',exports.OKENDO_PRODUCT_STAR_RATING_FRAGMENT='#graphql\n\tfragment OkendoStarRatingSnippet on Product {\n\t\tokendoStarRatingSnippet: metafield(\n\t\t\tnamespace: "okendo"\n\t\t\tkey: "StarRatingSnippet"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n',exports.OkendoProvider=({okendoProviderData:e,productUrlFormatter:n})=>{if(!e)return null;const{reviewsHeaderConfig:r,cssVariables:s,customCss:i,initScriptContents:o,preRenderStyleTags:a,starSymbols:d}=e,l="function"==typeof n?n.toString():"string"==typeof n?n:"(product) =>\n\t\t\t\t\tproduct && product.productHandle\n\t\t\t\t\t\t? \"/products/\" + product.productHandle + \"/\" + (product.variantId ? '?variantId=' + product.variantId : '')\n\t\t\t\t\t\t: undefined",c=(s??"").replace('<style id="oke-css-vars">',"").replace("</style>",""),p=i?i.replace('<style id="oke-reviews-custom-css">',"").replace("</style>",""):"";return t.createElement("div",null,t.createElement("script",{id:"oke-reviews-settings",type:"application/json",dangerouslySetInnerHTML:{__html:JSON.stringify(r)}}),t.createElement("style",{id:"oke-css-vars",dangerouslySetInnerHTML:{__html:c}}),p&&t.createElement("style",{id:"oke-reviews-custom-css",dangerouslySetInnerHTML:{__html:p}}),o&&t.createElement("script",{dangerouslySetInnerHTML:{__html:o}}),t.createElement("script",{type:"text/javascript",dangerouslySetInnerHTML:{__html:`window.okeProductUrlFormatter = ${l.toString()}`}}),a&&t.createElement("div",{dangerouslySetInnerHTML:{__html:a}}),d&&t.createElement("div",{dangerouslySetInnerHTML:{__html:d}}))},exports.OkendoReviews=({productId:n,okendoReviewsSnippet:s})=>{const i={"data-oke-widget":"","data-oke-reviews-product-id":r(n)};return t.createElement(e,{dataAttributes:i,metafieldContent:s?.value})},exports.OkendoStarRating=({productId:n,okendoStarRatingSnippet:s})=>{const i={"data-oke-star-rating":"","data-oke-reviews-product-id":r(n)};return t.createElement(e,{dataAttributes:i,metafieldContent:s?.value})},exports.getOkendoProviderData=async({context:t,subscriberId:e,apiDomain:n,cdnDomain:r})=>{const s=`https://${n||"api.okendo.io/v1"}/stores/${e}/widget_plus_settings`,i=await fetch(s);if(!i.ok)return console.error(`Failed to retrieve subscriber settings for subscriber ID '${e}'.`),null;const{reviewsHeaderConfig:o,cssVariables:a,customCss:d,starSymbols:l}=await i.json(),c=await fetch(`https://${r||"cdn-static.okendo.io"}/reviews-widget-plus/js/okendo-reviews.js`);if(!c.ok)return console.error("Failed to retrieve widget initialisation script."),null;const p=await c.text(),{shop:{widgetPreRenderStyleTags:u}}=await t.storefront.query('#graphql\n\t\tquery metafields {\n\t\t\tshop {\n\t\t\t\twidgetPreRenderStyleTags: metafield(\n\t\t\t\t\tnamespace: "okendo"\n\t\t\t\t\tkey: "WidgetPreRenderStyleTags"\n\t\t\t\t) {\n\t\t\t\t\tvalue\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t'),g=u?.value??"";return g||console.warn("Failed to retrieve pre-rendered widget style settings."),{reviewsHeaderConfig:o,cssVariables:a,customCss:d,initScriptContents:p,preRenderStyleTags:g,starSymbols:l}};
|
|
@@ -23,8 +23,14 @@ export declare const getOkendoProviderData: ({ context, subscriberId, apiDomain,
|
|
|
23
23
|
preRenderStyleTags: string;
|
|
24
24
|
starSymbols: string;
|
|
25
25
|
} | null>;
|
|
26
|
+
interface ReviewProduct {
|
|
27
|
+
productHandle?: string;
|
|
28
|
+
productId: string;
|
|
29
|
+
variantId?: string;
|
|
30
|
+
}
|
|
26
31
|
interface OkendoProviderProps {
|
|
27
32
|
okendoProviderData: Partial<OkendoProviderData> | null;
|
|
33
|
+
productUrlFormatter?: (product: ReviewProduct) => string;
|
|
28
34
|
}
|
|
29
35
|
export declare const OkendoProvider: FC<OkendoProviderProps>;
|
|
30
36
|
export {};
|
|
@@ -5,7 +5,7 @@ export interface WithOkendoStarRatingSnippet {
|
|
|
5
5
|
}
|
|
6
6
|
interface OkendoStarRatingProps {
|
|
7
7
|
productId: string;
|
|
8
|
-
okendoStarRatingSnippet
|
|
8
|
+
okendoStarRatingSnippet?: MetafieldValue;
|
|
9
9
|
}
|
|
10
10
|
export declare const OkendoStarRating: FC<OkendoStarRatingProps>;
|
|
11
11
|
export {};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t,{useRef as e,useEffect as n}from"react";const r=async({context:t,subscriberId:e,apiDomain:n,cdnDomain:r})=>{const i=`https://${n
|
|
1
|
+
import t,{useRef as e,useEffect as n}from"react";const r=async({context:t,subscriberId:e,apiDomain:n,cdnDomain:r})=>{const i=`https://${n||"api.okendo.io/v1"}/stores/${e}/widget_plus_settings`,o=await fetch(i);if(!o.ok)return console.error(`Failed to retrieve subscriber settings for subscriber ID '${e}'.`),null;const{reviewsHeaderConfig:s,cssVariables:a,customCss:d,starSymbols:l}=await o.json(),c=await fetch(`https://${r||"cdn-static.okendo.io"}/reviews-widget-plus/js/okendo-reviews.js`);if(!c.ok)return console.error("Failed to retrieve widget initialisation script."),null;const p=await c.text(),{shop:{widgetPreRenderStyleTags:u}}=await t.storefront.query('#graphql\n\t\tquery metafields {\n\t\t\tshop {\n\t\t\t\twidgetPreRenderStyleTags: metafield(\n\t\t\t\t\tnamespace: "okendo"\n\t\t\t\t\tkey: "WidgetPreRenderStyleTags"\n\t\t\t\t) {\n\t\t\t\t\tvalue\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t'),m=u?.value??"";return m||console.warn("Failed to retrieve pre-rendered widget style settings."),{reviewsHeaderConfig:s,cssVariables:a,customCss:d,initScriptContents:p,preRenderStyleTags:m,starSymbols:l}},i=({okendoProviderData:e,productUrlFormatter:n})=>{if(!e)return null;const{reviewsHeaderConfig:r,cssVariables:i,customCss:o,initScriptContents:s,preRenderStyleTags:a,starSymbols:d}=e,l="function"==typeof n?n.toString():"string"==typeof n?n:"(product) =>\n\t\t\t\t\tproduct && product.productHandle\n\t\t\t\t\t\t? \"/products/\" + product.productHandle + \"/\" + (product.variantId ? '?variantId=' + product.variantId : '')\n\t\t\t\t\t\t: undefined",c=(i??"").replace('<style id="oke-css-vars">',"").replace("</style>",""),p=o?o.replace('<style id="oke-reviews-custom-css">',"").replace("</style>",""):"";return t.createElement("div",null,t.createElement("script",{id:"oke-reviews-settings",type:"application/json",dangerouslySetInnerHTML:{__html:JSON.stringify(r)}}),t.createElement("style",{id:"oke-css-vars",dangerouslySetInnerHTML:{__html:c}}),p&&t.createElement("style",{id:"oke-reviews-custom-css",dangerouslySetInnerHTML:{__html:p}}),s&&t.createElement("script",{dangerouslySetInnerHTML:{__html:s}}),t.createElement("script",{type:"text/javascript",dangerouslySetInnerHTML:{__html:`window.okeProductUrlFormatter = ${l.toString()}`}}),a&&t.createElement("div",{dangerouslySetInnerHTML:{__html:a}}),d&&t.createElement("div",{dangerouslySetInnerHTML:{__html:d}}))},o=({dataAttributes:r,metafieldContent:i=""})=>{const o=e(null),s=()=>{o.current&&window.okeWidgetApi.initWidget(o.current)};return n((()=>(window.okeWidgetApi&&o.current?s():document.addEventListener("oke-script-loaded",s),()=>{document.removeEventListener("oke-script-loaded",s)})),[r]),t.createElement("div",{ref:o,key:JSON.stringify(r),...r,dangerouslySetInnerHTML:{__html:i}})},s=/^[0-9]*$/;function a(t){if(t)return`shopify-${s.test(t)?t:t.split("/").slice(-1)[0]}`}const d=({productId:e,okendoReviewsSnippet:n})=>{const r={"data-oke-widget":"","data-oke-reviews-product-id":a(e)};return t.createElement(o,{dataAttributes:r,metafieldContent:n?.value})},l=({productId:e,okendoStarRatingSnippet:n})=>{const r={"data-oke-star-rating":"","data-oke-reviews-product-id":a(e)};return t.createElement(o,{dataAttributes:r,metafieldContent:n?.value})},c='#graphql\n\tfragment OkendoStarRatingSnippet on Product {\n\t\tokendoStarRatingSnippet: metafield(\n\t\t\tnamespace: "okendo"\n\t\t\tkey: "StarRatingSnippet"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n',p='#graphql\n\tfragment OkendoReviewsSnippet on Product {\n\t\tokendoReviewsSnippet: metafield(\n\t\t\tnamespace: "okendo"\n\t\t\tkey: "ReviewsWidgetSnippet"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n';export{p as OKENDO_PRODUCT_REVIEWS_FRAGMENT,c as OKENDO_PRODUCT_STAR_RATING_FRAGMENT,i as OkendoProvider,d as OkendoReviews,l as OkendoStarRating,r as getOkendoProviderData};
|
|
@@ -23,8 +23,14 @@ export declare const getOkendoProviderData: ({ context, subscriberId, apiDomain,
|
|
|
23
23
|
preRenderStyleTags: string;
|
|
24
24
|
starSymbols: string;
|
|
25
25
|
} | null>;
|
|
26
|
+
interface ReviewProduct {
|
|
27
|
+
productHandle?: string;
|
|
28
|
+
productId: string;
|
|
29
|
+
variantId?: string;
|
|
30
|
+
}
|
|
26
31
|
interface OkendoProviderProps {
|
|
27
32
|
okendoProviderData: Partial<OkendoProviderData> | null;
|
|
33
|
+
productUrlFormatter?: (product: ReviewProduct) => string;
|
|
28
34
|
}
|
|
29
35
|
export declare const OkendoProvider: FC<OkendoProviderProps>;
|
|
30
36
|
export {};
|
|
@@ -5,7 +5,7 @@ export interface WithOkendoStarRatingSnippet {
|
|
|
5
5
|
}
|
|
6
6
|
interface OkendoStarRatingProps {
|
|
7
7
|
productId: string;
|
|
8
|
-
okendoStarRatingSnippet
|
|
8
|
+
okendoStarRatingSnippet?: MetafieldValue;
|
|
9
9
|
}
|
|
10
10
|
export declare const OkendoStarRating: FC<OkendoStarRatingProps>;
|
|
11
11
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -25,8 +25,14 @@ declare const getOkendoProviderData: ({ context, subscriberId, apiDomain, cdnDom
|
|
|
25
25
|
preRenderStyleTags: string;
|
|
26
26
|
starSymbols: string;
|
|
27
27
|
} | null>;
|
|
28
|
+
interface ReviewProduct {
|
|
29
|
+
productHandle?: string;
|
|
30
|
+
productId: string;
|
|
31
|
+
variantId?: string;
|
|
32
|
+
}
|
|
28
33
|
interface OkendoProviderProps {
|
|
29
34
|
okendoProviderData: Partial<OkendoProviderData> | null;
|
|
35
|
+
productUrlFormatter?: (product: ReviewProduct) => string;
|
|
30
36
|
}
|
|
31
37
|
declare const OkendoProvider: FC<OkendoProviderProps>;
|
|
32
38
|
|
|
@@ -39,7 +45,7 @@ interface WithOkendoReviewsSnippet {
|
|
|
39
45
|
}
|
|
40
46
|
interface OkendoReviewsProps {
|
|
41
47
|
productId: string;
|
|
42
|
-
okendoReviewsSnippet
|
|
48
|
+
okendoReviewsSnippet?: MetafieldValue;
|
|
43
49
|
}
|
|
44
50
|
declare const OkendoReviews: FC<OkendoReviewsProps>;
|
|
45
51
|
|
|
@@ -48,7 +54,7 @@ interface WithOkendoStarRatingSnippet {
|
|
|
48
54
|
}
|
|
49
55
|
interface OkendoStarRatingProps {
|
|
50
56
|
productId: string;
|
|
51
|
-
okendoStarRatingSnippet
|
|
57
|
+
okendoStarRatingSnippet?: MetafieldValue;
|
|
52
58
|
}
|
|
53
59
|
declare const OkendoStarRating: FC<OkendoStarRatingProps>;
|
|
54
60
|
|