@plasmicpkgs/commerce 0.0.18 → 0.0.21
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/commerce.cjs.development.js +79 -66
- package/dist/commerce.cjs.development.js.map +1 -1
- package/dist/commerce.cjs.production.min.js +1 -1
- package/dist/commerce.cjs.production.min.js.map +1 -1
- package/dist/commerce.esm.js +77 -67
- package/dist/commerce.esm.js.map +1 -1
- package/dist/contexts.d.ts +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/registerCategoryMedia.d.ts +0 -1
- package/dist/registerProductMedia.d.ts +3 -1
- package/dist/registerProductMediaCollection.d.ts +11 -0
- package/package.json +3 -3
|
@@ -940,9 +940,9 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
|
|
|
940
940
|
|
|
941
941
|
var defaultProduct = {
|
|
942
942
|
id: "123456789",
|
|
943
|
-
name: "Product
|
|
943
|
+
name: "Product name",
|
|
944
944
|
description: "",
|
|
945
|
-
descriptionHtml: "\n <p>This is a <strong>placeholder</strong>.</p>\n
|
|
945
|
+
descriptionHtml: "\n <p>This is a <strong>placeholder</strong>.</p>\n ",
|
|
946
946
|
images: [{
|
|
947
947
|
url: "https://static1.plasmic.app/commerce/lightweight-jacket-0.png",
|
|
948
948
|
alt: "Lightweight Jacket"
|
|
@@ -954,12 +954,12 @@ var defaultProduct = {
|
|
|
954
954
|
alt: "Lightweight Jacket"
|
|
955
955
|
}],
|
|
956
956
|
variants: [{
|
|
957
|
-
id: "
|
|
958
|
-
name: "Variant
|
|
957
|
+
id: "variant1",
|
|
958
|
+
name: "Variant 1",
|
|
959
959
|
options: []
|
|
960
960
|
}, {
|
|
961
961
|
id: "variant2",
|
|
962
|
-
name: "Variant
|
|
962
|
+
name: "Variant 2",
|
|
963
963
|
options: []
|
|
964
964
|
}],
|
|
965
965
|
price: {
|
|
@@ -1000,20 +1000,20 @@ var useCategoryContext = function useCategoryContext() {
|
|
|
1000
1000
|
var usePrimaryCategory = function usePrimaryCategory() {
|
|
1001
1001
|
return React.useContext(PrimaryCategoryContext);
|
|
1002
1002
|
};
|
|
1003
|
-
var
|
|
1004
|
-
function
|
|
1003
|
+
var ProductMediaContext = /*#__PURE__*/React__default.createContext(undefined);
|
|
1004
|
+
function ProductMediaProvider(_ref3) {
|
|
1005
1005
|
var mediaIndex = _ref3.mediaIndex,
|
|
1006
1006
|
onClick = _ref3.onClick,
|
|
1007
1007
|
children = _ref3.children;
|
|
1008
|
-
return React__default.createElement(
|
|
1008
|
+
return React__default.createElement(ProductMediaContext.Provider, {
|
|
1009
1009
|
value: mediaIndex,
|
|
1010
1010
|
key: mediaIndex
|
|
1011
1011
|
}, React__default.cloneElement(React__default.isValidElement(children) ? children : React__default.createElement(React__default.Fragment, null), {
|
|
1012
1012
|
onClick: onClick
|
|
1013
1013
|
}));
|
|
1014
1014
|
}
|
|
1015
|
-
var
|
|
1016
|
-
return React.useContext(
|
|
1015
|
+
var useProductMediaContext = function useProductMediaContext() {
|
|
1016
|
+
return React.useContext(ProductMediaContext);
|
|
1017
1017
|
};
|
|
1018
1018
|
|
|
1019
1019
|
var _excluded = ["children"];
|
|
@@ -1795,26 +1795,7 @@ var categoryMediaMeta = {
|
|
|
1795
1795
|
name: "plasmic-commerce-category-media",
|
|
1796
1796
|
displayName: "Category Media",
|
|
1797
1797
|
props: {
|
|
1798
|
-
mediaIndex: "number"
|
|
1799
|
-
mediaSize: {
|
|
1800
|
-
type: "choice",
|
|
1801
|
-
options: [{
|
|
1802
|
-
label: "Fill",
|
|
1803
|
-
value: "fill"
|
|
1804
|
-
}, {
|
|
1805
|
-
label: "Container",
|
|
1806
|
-
value: "contain"
|
|
1807
|
-
}, {
|
|
1808
|
-
label: "Cover",
|
|
1809
|
-
value: "cover"
|
|
1810
|
-
}, {
|
|
1811
|
-
label: "None",
|
|
1812
|
-
value: "none"
|
|
1813
|
-
}, {
|
|
1814
|
-
label: "Scale down",
|
|
1815
|
-
value: "scale-down"
|
|
1816
|
-
}]
|
|
1817
|
-
}
|
|
1798
|
+
mediaIndex: "number"
|
|
1818
1799
|
},
|
|
1819
1800
|
importPath: "@plasmicpkgs/commerce",
|
|
1820
1801
|
importName: "CategoryMedia"
|
|
@@ -1824,18 +1805,14 @@ function CategoryMedia(props) {
|
|
|
1824
1805
|
|
|
1825
1806
|
var className = props.className,
|
|
1826
1807
|
_props$mediaIndex = props.mediaIndex,
|
|
1827
|
-
mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex
|
|
1828
|
-
mediaSize = props.mediaSize;
|
|
1808
|
+
mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex;
|
|
1829
1809
|
var category = useCategoryContext();
|
|
1830
1810
|
var image = category != null && category.images ? category.images[mediaIndex] : undefined;
|
|
1831
1811
|
return React__default.createElement("img", {
|
|
1832
1812
|
alt: (category == null ? void 0 : category.name) || "Category Image",
|
|
1833
1813
|
src: (_image$url = image == null ? void 0 : image.url) != null ? _image$url : "",
|
|
1834
1814
|
loading: "lazy",
|
|
1835
|
-
className: className
|
|
1836
|
-
style: {
|
|
1837
|
-
objectFit: mediaSize
|
|
1838
|
-
}
|
|
1815
|
+
className: className
|
|
1839
1816
|
});
|
|
1840
1817
|
}
|
|
1841
1818
|
function registerCategoryMedia(loader, customCategoryMediaMeta) {
|
|
@@ -2238,25 +2215,12 @@ var productMediaMeta = {
|
|
|
2238
2215
|
name: "plasmic-commerce-product-media",
|
|
2239
2216
|
displayName: "Product Media",
|
|
2240
2217
|
props: {
|
|
2241
|
-
mediaIndex:
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
}, {
|
|
2248
|
-
label: "Container",
|
|
2249
|
-
value: "contain"
|
|
2250
|
-
}, {
|
|
2251
|
-
label: "Cover",
|
|
2252
|
-
value: "cover"
|
|
2253
|
-
}, {
|
|
2254
|
-
label: "None",
|
|
2255
|
-
value: "none"
|
|
2256
|
-
}, {
|
|
2257
|
-
label: "Scale down",
|
|
2258
|
-
value: "scale-down"
|
|
2259
|
-
}]
|
|
2218
|
+
mediaIndex: {
|
|
2219
|
+
type: "number",
|
|
2220
|
+
min: 0,
|
|
2221
|
+
hidden: function hidden(_, ctx) {
|
|
2222
|
+
return !!(ctx != null && ctx.inMediaContext);
|
|
2223
|
+
}
|
|
2260
2224
|
}
|
|
2261
2225
|
},
|
|
2262
2226
|
importPath: "@plasmicpkgs/commerce",
|
|
@@ -2268,18 +2232,18 @@ function ProductMedia(props) {
|
|
|
2268
2232
|
var className = props.className,
|
|
2269
2233
|
_props$mediaIndex = props.mediaIndex,
|
|
2270
2234
|
mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex,
|
|
2271
|
-
|
|
2235
|
+
setControlContextData = props.setControlContextData;
|
|
2272
2236
|
var product = useProduct();
|
|
2273
|
-
var
|
|
2274
|
-
|
|
2237
|
+
var mediaContext = useProductMediaContext();
|
|
2238
|
+
setControlContextData == null ? void 0 : setControlContextData({
|
|
2239
|
+
inMediaContext: mediaContext !== undefined
|
|
2240
|
+
});
|
|
2241
|
+
var image = product == null ? void 0 : product.images[mediaContext != null ? mediaContext : mediaIndex];
|
|
2275
2242
|
return React__default.createElement("img", {
|
|
2276
2243
|
alt: (product == null ? void 0 : product.name) || "Product Image",
|
|
2277
2244
|
src: product ? (_image$url = image == null ? void 0 : image.url) != null ? _image$url : "" : placeholderImage,
|
|
2278
2245
|
loading: "lazy",
|
|
2279
|
-
className: className
|
|
2280
|
-
style: {
|
|
2281
|
-
objectFit: mediaSize
|
|
2282
|
-
}
|
|
2246
|
+
className: className
|
|
2283
2247
|
});
|
|
2284
2248
|
}
|
|
2285
2249
|
function registerProductMedia(loader, customProductMediaMeta) {
|
|
@@ -2290,6 +2254,51 @@ function registerProductMedia(loader, customProductMediaMeta) {
|
|
|
2290
2254
|
doRegisterComponent(ProductMedia, customProductMediaMeta != null ? customProductMediaMeta : productMediaMeta);
|
|
2291
2255
|
}
|
|
2292
2256
|
|
|
2257
|
+
var productMediaCollectionMeta = {
|
|
2258
|
+
name: "plasmic-commerce-product-media-collection",
|
|
2259
|
+
displayName: "Product Media Collection",
|
|
2260
|
+
props: {
|
|
2261
|
+
media: {
|
|
2262
|
+
type: "slot",
|
|
2263
|
+
defaultValue: {
|
|
2264
|
+
type: "component",
|
|
2265
|
+
name: "plasmic-commerce-product-media"
|
|
2266
|
+
},
|
|
2267
|
+
allowedComponents: ["plasmic-commerce-product-media"]
|
|
2268
|
+
}
|
|
2269
|
+
},
|
|
2270
|
+
defaultStyles: {
|
|
2271
|
+
display: "grid",
|
|
2272
|
+
gridTemplateColumns: "1fr 1fr",
|
|
2273
|
+
gridRowGap: "8px",
|
|
2274
|
+
gridColumnGap: "8px",
|
|
2275
|
+
padding: "8px",
|
|
2276
|
+
maxWidth: "100%"
|
|
2277
|
+
},
|
|
2278
|
+
importPath: "@plasmicpkgs/commerce",
|
|
2279
|
+
importName: "ProductMediaCollection"
|
|
2280
|
+
};
|
|
2281
|
+
function ProductMediaCollection(props) {
|
|
2282
|
+
var media = props.media,
|
|
2283
|
+
className = props.className;
|
|
2284
|
+
var product = useProduct();
|
|
2285
|
+
return React__default.createElement("div", {
|
|
2286
|
+
className: className
|
|
2287
|
+
}, product == null ? void 0 : product.images.map(function (image, i) {
|
|
2288
|
+
return host.repeatedElement(i === 0, React__default.createElement(ProductMediaProvider, {
|
|
2289
|
+
mediaIndex: i,
|
|
2290
|
+
children: media
|
|
2291
|
+
}));
|
|
2292
|
+
}));
|
|
2293
|
+
}
|
|
2294
|
+
function registerProductMediaCollection(loader, customProductMediaCollectionMeta) {
|
|
2295
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
2296
|
+
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
2297
|
+
};
|
|
2298
|
+
|
|
2299
|
+
doRegisterComponent(ProductMediaCollection, customProductMediaCollectionMeta != null ? customProductMediaCollectionMeta : productMediaCollectionMeta);
|
|
2300
|
+
}
|
|
2301
|
+
|
|
2293
2302
|
var getProductPrice = function getProductPrice(product, variantId) {
|
|
2294
2303
|
var _product$variants$fin, _product$variants$fin2;
|
|
2295
2304
|
|
|
@@ -2428,11 +2437,11 @@ function ProductSlider(props) {
|
|
|
2428
2437
|
selected = _React$useState[0],
|
|
2429
2438
|
setSelected = _React$useState[1];
|
|
2430
2439
|
|
|
2431
|
-
var
|
|
2432
|
-
var leftIndex = Math.min(
|
|
2440
|
+
var maximumLeft = Math.max(0, product.images.length - thumbsVisible);
|
|
2441
|
+
var leftIndex = Math.min(maximumLeft, Math.max(0, selected - 1));
|
|
2433
2442
|
return React__default.createElement("div", {
|
|
2434
2443
|
className: className
|
|
2435
|
-
}, React__default.createElement(
|
|
2444
|
+
}, React__default.createElement(ProductMediaProvider, {
|
|
2436
2445
|
mediaIndex: selected,
|
|
2437
2446
|
children: slideContainer
|
|
2438
2447
|
}), React__default.createElement("div", {
|
|
@@ -2441,7 +2450,7 @@ function ProductSlider(props) {
|
|
|
2441
2450
|
gridTemplateColumns: "repeat(" + thumbsVisible + ", 1fr)"
|
|
2442
2451
|
}
|
|
2443
2452
|
}, product.images.slice(leftIndex, leftIndex + thumbsVisible).map(function (image, i) {
|
|
2444
|
-
return host.repeatedElement(i === 0, React__default.createElement(
|
|
2453
|
+
return host.repeatedElement(i === 0, React__default.createElement(ProductMediaProvider, {
|
|
2445
2454
|
mediaIndex: leftIndex + i,
|
|
2446
2455
|
children: thumbsContainer,
|
|
2447
2456
|
onClick: function onClick() {
|
|
@@ -2611,6 +2620,7 @@ function registerAll(loader) {
|
|
|
2611
2620
|
registerTextField(loader);
|
|
2612
2621
|
registerProductPrice(loader);
|
|
2613
2622
|
registerProductMedia(loader);
|
|
2623
|
+
registerProductMediaCollection(loader);
|
|
2614
2624
|
registerCart(loader);
|
|
2615
2625
|
registerAddToCartButton(loader);
|
|
2616
2626
|
registerProductQuantity(loader);
|
|
@@ -2638,6 +2648,7 @@ exports.ProductBox = ProductBox;
|
|
|
2638
2648
|
exports.ProductCollection = ProductCollection;
|
|
2639
2649
|
exports.ProductLink = ProductLink;
|
|
2640
2650
|
exports.ProductMedia = ProductMedia;
|
|
2651
|
+
exports.ProductMediaCollection = ProductMediaCollection;
|
|
2641
2652
|
exports.ProductPlaceholder = defaultProduct;
|
|
2642
2653
|
exports.ProductPriceComponent = ProductPriceComponent;
|
|
2643
2654
|
exports.ProductQuantity = ProductQuantity;
|
|
@@ -2658,6 +2669,7 @@ exports.getCommerceProvider = getCommerceProvider;
|
|
|
2658
2669
|
exports.productBoxMeta = productBoxMeta;
|
|
2659
2670
|
exports.productCollectionMeta = productCollectionMeta;
|
|
2660
2671
|
exports.productLinkMeta = productLinkMeta;
|
|
2672
|
+
exports.productMediaCollectionMeta = productMediaCollectionMeta;
|
|
2661
2673
|
exports.productMediaMeta = productMediaMeta;
|
|
2662
2674
|
exports.productPriceMeta = productPriceMeta;
|
|
2663
2675
|
exports.productQuantityMeta = productQuantityMeta;
|
|
@@ -2675,6 +2687,7 @@ exports.registerProductBox = registerProductBox;
|
|
|
2675
2687
|
exports.registerProductCollection = registerProductCollection;
|
|
2676
2688
|
exports.registerProductLink = registerProductLink;
|
|
2677
2689
|
exports.registerProductMedia = registerProductMedia;
|
|
2690
|
+
exports.registerProductMediaCollection = registerProductMediaCollection;
|
|
2678
2691
|
exports.registerProductPrice = registerProductPrice;
|
|
2679
2692
|
exports.registerProductQuantity = registerProductQuantity;
|
|
2680
2693
|
exports.registerProductSlider = registerProductSlider;
|