sanity-plugin-shopify-assets
2.0.202.1.0
dist/index.js~
dist/index.jsModified+78−43
Index: package/dist/index.js
===================================================================
--- package/dist/index.js
+++ package/dist/index.js
@@ -265,17 +265,46 @@
t4,
t5
]
}), $[12] = t1, $[13] = t4, $[14] = t5, $[15] = t6) : t6 = $[15], t6;
-}, fetchSearch = (props) => {
- let { projectId, dataset, shop, query, cursor, resultsPerPage, token } = props, cursorParam = cursor ? `&cursor=${encodeURIComponent(cursor)}` : "", url = `https://${projectId}.api.sanity.io/v1/shopify/assets/${dataset}?shop=${encodeURIComponent(shop)}&query=${encodeURIComponent(query)}${cursorParam}&limit=${resultsPerPage}`;
+};
+/**
+* Field `options` replace the parent type's `options` object rather than merging
+* with it. Walk the type chain so a field can override one setting and still
+* inherit the other from the plugin.
+*/
+function resolveShopifyAssetConfig(schemaType) {
+ return {
+ shopifyDomain: readConfiguredString(schemaType, "shopifyDomain"),
+ dataset: readConfiguredString(schemaType, "dataset")
+ };
+}
+function isSchemaNode(value) {
+ return typeof value == "object" && !!value;
+}
+function readConfiguredString(schemaType, key) {
+ let seen = /* @__PURE__ */ new Set(), current = schemaType;
+ for (let depth = 0; current && depth < 8; depth += 1) {
+ if (seen.has(current)) return;
+ seen.add(current);
+ let value = current.options?.[key];
+ if (typeof value == "string") {
+ let trimmed = value.trim();
+ if (trimmed) return trimmed;
+ }
+ if (!isSchemaNode(current.type)) return;
+ current = current.type;
+ }
+}
+const fetchSearch = (props) => {
+ let { projectId, dataset, shop, query, cursor, resultsPerPage, token } = props, cursorParam = cursor ? `&cursor=${encodeURIComponent(cursor)}` : "", url = `https://${projectId}.api.sanity.io/v1/shopify/assets/${encodeURIComponent(dataset)}?shop=${encodeURIComponent(shop)}&query=${encodeURIComponent(query)}${cursorParam}&limit=${resultsPerPage}`;
return defer(() => axios.get(url, {
withCredentials: !0,
method: "GET",
headers: token ? { Authorization: `Bearer ${token}` } : {}
})).pipe(map((result) => result.data));
}, fetchList = (props) => {
- let { projectId, dataset, shop, cursor, resultsPerPage, token } = props, cursorParam = cursor ? `&cursor=${encodeURIComponent(cursor)}` : "", url = `https://${projectId}.api.sanity.io/v1/shopify/assets/${dataset}?shop=${encodeURIComponent(shop)}${cursorParam}&limit=${resultsPerPage}`;
+ let { projectId, dataset, shop, cursor, resultsPerPage, token } = props, cursorParam = cursor ? `&cursor=${encodeURIComponent(cursor)}` : "", url = `https://${projectId}.api.sanity.io/v1/shopify/assets/${encodeURIComponent(dataset)}?shop=${encodeURIComponent(shop)}${cursorParam}&limit=${resultsPerPage}`;
return defer(() => axios.get(url, {
withCredentials: !0,
method: "GET",
headers: token ? { Authorization: `Bearer ${token}` } : {}
@@ -401,9 +430,9 @@
displayName: "Search",
componentId: "sc-g5v4d7-0"
})`position:sticky;top:0;z-index:1;`;
function ShopifyAssetPicker(props) {
- let $ = c(38), { isOpen, onClose, shopifyDomain, onChange, schemaType, value } = props, projectId = useProjectId(), dataset = useDataset(), t0;
+ let $ = c(38), { isOpen, onClose, shopifyDomain, dataset: configuredDataset, onChange, schemaType, value } = props, projectId = useProjectId(), studioDataset = useDataset(), dataset = configuredDataset || studioDataset, t0;
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = { apiVersion: "2021-06-07" }, $[0] = t0) : t0 = $[0];
let client = useClient(t0), t1;
$[1] === client ? t1 = $[2] : (t1 = client.config(), $[1] = client, $[2] = t1);
let token = t1.token, [apiError, setApiError] = useState(""), [query, setQuery] = useState(""), t2;
@@ -595,95 +624,101 @@
]
}), $[0] = t0) : t0 = $[0], t0;
};
function ShopifyAssetInput(props) {
- let $ = c(28), { onChange, readOnly, value, schemaType } = props, { options } = schemaType, shopifyDomain = options?.shopifyDomain, [dialogOpen, setDialogOpen] = useState(!1), t0;
- $[0] === onChange ? t0 = $[1] : (t0 = () => {
+ let $ = c(31), { onChange, readOnly, value, schemaType } = props, t0;
+ $[0] === schemaType ? t0 = $[1] : (t0 = resolveShopifyAssetConfig(schemaType), $[0] = schemaType, $[1] = t0);
+ let { shopifyDomain, dataset } = t0, [dialogOpen, setDialogOpen] = useState(!1), t1;
+ $[2] === onChange ? t1 = $[3] : (t1 = () => {
onChange(PatchEvent.from([unset()]));
- }, $[0] = onChange, $[1] = t0);
- let removeValue = t0, t1;
- $[2] === Symbol.for("react.memo_cache_sentinel") ? (t1 = () => {
+ }, $[2] = onChange, $[3] = t1);
+ let removeValue = t1, t2;
+ $[4] === Symbol.for("react.memo_cache_sentinel") ? (t2 = () => {
setDialogOpen(!0);
- }, $[2] = t1) : t1 = $[2];
- let onOpen = t1, t2;
- $[3] === Symbol.for("react.memo_cache_sentinel") ? (t2 = () => {
+ }, $[4] = t2) : t2 = $[4];
+ let onOpen = t2, t3;
+ $[5] === Symbol.for("react.memo_cache_sentinel") ? (t3 = () => {
setDialogOpen(!1);
- }, $[3] = t2) : t2 = $[3];
- let onClose = t2;
+ }, $[5] = t3) : t3 = $[5];
+ let onClose = t3;
if (!shopifyDomain) {
- let t3;
- $[4] === Symbol.for("react.memo_cache_sentinel") ? (t3 = /* @__PURE__ */ jsx(Text, {
+ let t4;
+ $[6] === Symbol.for("react.memo_cache_sentinel") ? (t4 = /* @__PURE__ */ jsx(Text, {
size: 2,
children: /* @__PURE__ */ jsx(ErrorOutlineIcon, {})
- }), $[4] = t3) : t3 = $[4];
- let t4;
- return $[5] === Symbol.for("react.memo_cache_sentinel") ? (t4 = /* @__PURE__ */ jsx(Card, {
+ }), $[6] = t4) : t4 = $[6];
+ let t5;
+ return $[7] === Symbol.for("react.memo_cache_sentinel") ? (t5 = /* @__PURE__ */ jsx(Card, {
overflow: "hidden",
padding: 4,
radius: 2,
shadow: 1,
tone: "critical",
children: /* @__PURE__ */ jsxs(Flex, {
align: "center",
gap: 3,
- children: [t3, /* @__PURE__ */ jsx(Inline, {
+ children: [t4, /* @__PURE__ */ jsx(Inline, {
gap: 2,
children: /* @__PURE__ */ jsx(Text, {
size: 1,
children: "You need to configure your *.myshopify.com domain in the plugin / field options to enable Shopify Assets."
})
})]
})
- }), $[5] = t4) : t4 = $[5], t4;
+ }), $[7] = t5) : t5 = $[7], t5;
}
- let t3;
- $[6] !== dialogOpen || $[7] !== props || $[8] !== shopifyDomain || $[9] !== value ? (t3 = dialogOpen && /* @__PURE__ */ jsx(ShopifyAssetPicker, {
+ let t4;
+ $[8] !== dataset || $[9] !== dialogOpen || $[10] !== props || $[11] !== shopifyDomain || $[12] !== value ? (t4 = dialogOpen && /* @__PURE__ */ jsx(ShopifyAssetPicker, {
...props,
shopifyDomain,
+ dataset,
isOpen: dialogOpen,
onClose,
value
- }), $[6] = dialogOpen, $[7] = props, $[8] = shopifyDomain, $[9] = value, $[10] = t3) : t3 = $[10];
- let t4;
- $[11] === value ? t4 = $[12] : (t4 = /* @__PURE__ */ jsx(AssetPreview, { value }), $[11] = value, $[12] = t4);
+ }), $[8] = dataset, $[9] = dialogOpen, $[10] = props, $[11] = shopifyDomain, $[12] = value, $[13] = t4) : t4 = $[13];
let t5;
- $[13] === Symbol.for("react.memo_cache_sentinel") ? (t5 = { gridTemplateColumns: "repeat(auto-fit, minmax(100px, 1fr))" }, $[13] = t5) : t5 = $[13];
+ $[14] === value ? t5 = $[15] : (t5 = /* @__PURE__ */ jsx(AssetPreview, { value }), $[14] = value, $[15] = t5);
let t6;
- $[14] === readOnly ? t6 = $[15] : (t6 = /* @__PURE__ */ jsx(Button, {
+ $[16] === Symbol.for("react.memo_cache_sentinel") ? (t6 = { gridTemplateColumns: "repeat(auto-fit, minmax(100px, 1fr))" }, $[16] = t6) : t6 = $[16];
+ let t7;
+ $[17] === readOnly ? t7 = $[18] : (t7 = /* @__PURE__ */ jsx(Button, {
disabled: readOnly,
mode: "ghost",
icon: ShopifyIcon,
title: "Select an asset",
onClick: onOpen,
text: "Select…"
- }), $[14] = readOnly, $[15] = t6);
- let t7 = readOnly || !value, t8;
- $[16] !== removeValue || $[17] !== t7 ? (t8 = /* @__PURE__ */ jsx(Button, {
- disabled: t7,
+ }), $[17] = readOnly, $[18] = t7);
+ let t8 = readOnly || !value, t9;
+ $[19] !== removeValue || $[20] !== t8 ? (t9 = /* @__PURE__ */ jsx(Button, {
+ disabled: t8,
tone: "critical",
mode: "ghost",
title: "Remove asset",
text: "Remove",
onClick: removeValue
- }), $[16] = removeValue, $[17] = t7, $[18] = t8) : t8 = $[18];
- let t9;
- $[19] !== t6 || $[20] !== t8 ? (t9 = /* @__PURE__ */ jsxs(Grid, {
- gap: 1,
- style: t5,
- children: [t6, t8]
- }), $[19] = t6, $[20] = t8, $[21] = t9) : t9 = $[21];
+ }), $[19] = removeValue, $[20] = t8, $[21] = t9) : t9 = $[21];
let t10;
- $[22] !== t4 || $[23] !== t9 ? (t10 = /* @__PURE__ */ jsxs(Stack, { children: [t4, t9] }), $[22] = t4, $[23] = t9, $[24] = t10) : t10 = $[24];
+ $[22] !== t7 || $[23] !== t9 ? (t10 = /* @__PURE__ */ jsxs(Grid, {
+ gap: 1,
+ style: t6,
+ children: [t7, t9]
+ }), $[22] = t7, $[23] = t9, $[24] = t10) : t10 = $[24];
let t11;
- return $[25] !== t10 || $[26] !== t3 ? (t11 = /* @__PURE__ */ jsxs(Fragment, { children: [t3, t10] }), $[25] = t10, $[26] = t3, $[27] = t11) : t11 = $[27], t11;
+ $[25] !== t10 || $[26] !== t5 ? (t11 = /* @__PURE__ */ jsxs(Stack, { children: [t5, t10] }), $[25] = t10, $[26] = t5, $[27] = t11) : t11 = $[27];
+ let t12;
+ return $[28] !== t11 || $[29] !== t4 ? (t12 = /* @__PURE__ */ jsxs(Fragment, { children: [t4, t11] }), $[28] = t11, $[29] = t4, $[30] = t12) : t12 = $[30], t12;
}
const shopifyAssetSchema = (config) => {
- let { shopifyDomain } = config;
+ let { shopifyDomain } = config, dataset = config.dataset?.trim();
return defineType({
type: "object",
name: "shopify.asset",
title: "Shopify Asset",
- options: { shopifyDomain },
+ options: {
+ shopifyDomain,
+ ...dataset ? { dataset } : {}
+ },
fields: [
defineField({
type: "string",
name: "filename",