@meta-cms/next
Advanced tools
Comparing version 1.0.27 to 1.0.28
147
index.js
@@ -34,2 +34,33 @@ "use strict"; | ||
// ../core/get.ts | ||
function get(obj, propsArg, defaultValue) { | ||
if (!obj) { | ||
return defaultValue; | ||
} | ||
var props, prop; | ||
if (Array.isArray(propsArg)) { | ||
props = propsArg.slice(0); | ||
} | ||
if (typeof propsArg == "string") { | ||
props = propsArg.split("."); | ||
} | ||
if (typeof propsArg == "symbol") { | ||
props = [propsArg]; | ||
} | ||
if (!Array.isArray(props)) { | ||
throw new Error("props arg must be an array, a string or a symbol"); | ||
} | ||
while (props.length) { | ||
prop = props.shift(); | ||
if (!obj) { | ||
return defaultValue; | ||
} | ||
obj = obj[prop]; | ||
if (obj === void 0) { | ||
return defaultValue; | ||
} | ||
} | ||
return obj; | ||
} | ||
// ../core/graphql/storefront.contentQuery.ts | ||
@@ -170,33 +201,2 @@ var contentQuery = ` | ||
// ../core/get.ts | ||
function get(obj, propsArg, defaultValue) { | ||
if (!obj) { | ||
return defaultValue; | ||
} | ||
var props, prop; | ||
if (Array.isArray(propsArg)) { | ||
props = propsArg.slice(0); | ||
} | ||
if (typeof propsArg == "string") { | ||
props = propsArg.split("."); | ||
} | ||
if (typeof propsArg == "symbol") { | ||
props = [propsArg]; | ||
} | ||
if (!Array.isArray(props)) { | ||
throw new Error("props arg must be an array, a string or a symbol"); | ||
} | ||
while (props.length) { | ||
prop = props.shift(); | ||
if (!obj) { | ||
return defaultValue; | ||
} | ||
obj = obj[prop]; | ||
if (obj === void 0) { | ||
return defaultValue; | ||
} | ||
} | ||
return obj; | ||
} | ||
// ../core/client.ts | ||
@@ -222,10 +222,19 @@ var GraphqlClient = class { | ||
var MetaCms = class { | ||
constructor(config, { storefrontName, storefrontAccessToken, defaultNameSpaces }) { | ||
constructor(config, { | ||
storefrontName, | ||
storefrontAccessToken, | ||
defaultNameSpaces | ||
}) { | ||
this.getContentForNamespaces = async (namespaces, locale = "fra") => { | ||
const { | ||
shop: { content } | ||
} = await this.client.request(contentQuery, { | ||
identifiers: this.buildIdentifiers(namespaces.concat(this.defaultNameSpaces), locale) | ||
}); | ||
console.log({ content }); | ||
} = await this.client.request( | ||
contentQuery, | ||
{ | ||
identifiers: this.buildIdentifiers( | ||
namespaces.concat(this.defaultNameSpaces), | ||
locale | ||
) | ||
} | ||
); | ||
return content.reduce((acc, item) => { | ||
@@ -339,12 +348,15 @@ if (!item) { | ||
const namespaceConfig = this.config[namespace]; | ||
const keys = Object.entries(namespaceConfig).reduce((acc2, [key, value]) => { | ||
if (value.config) { | ||
Object.keys(value.config).forEach((subKey) => { | ||
acc2.push(`${key}.${subKey}`); | ||
}); | ||
} else { | ||
acc2.push(key); | ||
} | ||
return acc2; | ||
}, []); | ||
const keys = Object.entries(namespaceConfig).reduce( | ||
(acc2, [key, value]) => { | ||
if (value.config) { | ||
Object.keys(value.config).forEach((subKey) => { | ||
acc2.push(`${key}.${subKey}`); | ||
}); | ||
} else { | ||
acc2.push(key); | ||
} | ||
return acc2; | ||
}, | ||
[] | ||
); | ||
keys.forEach((key) => { | ||
@@ -359,5 +371,8 @@ acc.push({ namespace: `${namespace}_${locale}`, key }); | ||
this.defaultNameSpaces = defaultNameSpaces || []; | ||
this.client = new GraphqlClient(`https://${storefrontName}.myshopify.com/api/2022-10/graphql.json`, { | ||
"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN": storefrontAccessToken | ||
}); | ||
this.client = new GraphqlClient( | ||
`https://${storefrontName}.myshopify.com/api/2022-10/graphql.json`, | ||
{ | ||
"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN": storefrontAccessToken | ||
} | ||
); | ||
} | ||
@@ -376,8 +391,20 @@ }; | ||
var useBuilder = (content) => { | ||
const state = content; | ||
let state = content; | ||
let source = (0, import_react.useRef)(null); | ||
let tipsRefs = (0, import_react.useRef)([]); | ||
let mounted = (0, import_react.useRef)(false); | ||
const sendNamespaces = () => { | ||
if (source.current) { | ||
console.log("send ns"); | ||
source.current.source.postMessage( | ||
{ action: "show_me_your_namespaces", namespaces: Object.keys(content) }, | ||
source.current.origin | ||
); | ||
} | ||
}; | ||
const onMessage = (event) => { | ||
mounted.current = true; | ||
if (event.data.action === "show_indicator") { | ||
if (!source.current) { | ||
} | ||
if (tipsRefs.current.length === 0) { | ||
@@ -402,3 +429,2 @@ const elements = document.querySelectorAll("[itemid^='gid']"); | ||
var _a2; | ||
console.log("click"); | ||
(_a2 = event.source) == null ? void 0 : _a2.postMessage({ action: "click", namespace, key }, event.origin); | ||
@@ -409,11 +435,20 @@ }); | ||
tipsRefs.current = tips; | ||
} else { | ||
tipsRefs.current.forEach((tip) => { | ||
tip.destroy(); | ||
}); | ||
tipsRefs.current = []; | ||
} | ||
} else if (event.data.action === "hide_indicator") { | ||
console.log(source.current); | ||
tipsRefs.current.forEach((tip) => { | ||
tip.destroy(); | ||
}); | ||
tipsRefs.current = []; | ||
} else if (event.data.action === "init" && event.source) { | ||
source.current = { source: event.source, origin: event.origin }; | ||
sendNamespaces(); | ||
} | ||
}; | ||
(0, import_react.useEffect)(() => { | ||
if (source.current) { | ||
sendNamespaces(); | ||
} | ||
}, [content]); | ||
(0, import_react.useEffect)(() => { | ||
window.addEventListener("message", onMessage, false); | ||
@@ -420,0 +455,0 @@ return () => { |
{ | ||
"name": "@meta-cms/next", | ||
"version": "1.0.27", | ||
"version": "1.0.28", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17041
538