@plasmicpkgs/commerce 0.0.17 → 0.0.20
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 +96 -70
- 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 +94 -71
- package/dist/commerce.esm.js.map +1 -1
- package/dist/contexts.d.ts +6 -4
- package/dist/index.d.ts +1 -0
- package/dist/registerCategoryMedia.d.ts +0 -1
- package/dist/registerProductCollection.d.ts +1 -1
- package/dist/registerProductMedia.d.ts +3 -1
- package/dist/registerProductMediaCollection.d.ts +11 -0
- package/package.json +3 -3
package/dist/commerce.esm.js
CHANGED
|
@@ -933,9 +933,9 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
|
|
|
933
933
|
|
|
934
934
|
var defaultProduct = {
|
|
935
935
|
id: "123456789",
|
|
936
|
-
name: "Product
|
|
936
|
+
name: "Product name",
|
|
937
937
|
description: "",
|
|
938
|
-
descriptionHtml: "\n <p>This is a <strong>placeholder</strong>.</p>\n
|
|
938
|
+
descriptionHtml: "\n <p>This is a <strong>placeholder</strong>.</p>\n ",
|
|
939
939
|
images: [{
|
|
940
940
|
url: "https://static1.plasmic.app/commerce/lightweight-jacket-0.png",
|
|
941
941
|
alt: "Lightweight Jacket"
|
|
@@ -947,12 +947,12 @@ var defaultProduct = {
|
|
|
947
947
|
alt: "Lightweight Jacket"
|
|
948
948
|
}],
|
|
949
949
|
variants: [{
|
|
950
|
-
id: "
|
|
951
|
-
name: "Variant
|
|
950
|
+
id: "variant1",
|
|
951
|
+
name: "Variant 1",
|
|
952
952
|
options: []
|
|
953
953
|
}, {
|
|
954
954
|
id: "variant2",
|
|
955
|
-
name: "Variant
|
|
955
|
+
name: "Variant 2",
|
|
956
956
|
options: []
|
|
957
957
|
}],
|
|
958
958
|
price: {
|
|
@@ -963,8 +963,6 @@ var defaultProduct = {
|
|
|
963
963
|
};
|
|
964
964
|
|
|
965
965
|
var ProductContext = /*#__PURE__*/React.createContext(undefined);
|
|
966
|
-
var CategoryContext = /*#__PURE__*/React.createContext(undefined);
|
|
967
|
-
var SliderContext = /*#__PURE__*/React.createContext(undefined);
|
|
968
966
|
function ProductProvider(_ref) {
|
|
969
967
|
var product = _ref.product,
|
|
970
968
|
children = _ref.children;
|
|
@@ -978,6 +976,9 @@ var useProduct = function useProduct() {
|
|
|
978
976
|
var product = useContext(ProductContext);
|
|
979
977
|
return product != null ? product : defaultProduct;
|
|
980
978
|
};
|
|
979
|
+
var CategoryContext = /*#__PURE__*/React.createContext(undefined);
|
|
980
|
+
var PrimaryCategoryContext = /*#__PURE__*/React.createContext(undefined); //used to render correctly the defaultValueHint in ProductCollection
|
|
981
|
+
|
|
981
982
|
function CategoryProvider(_ref2) {
|
|
982
983
|
var category = _ref2.category,
|
|
983
984
|
children = _ref2.children;
|
|
@@ -989,19 +990,23 @@ function CategoryProvider(_ref2) {
|
|
|
989
990
|
var useCategoryContext = function useCategoryContext() {
|
|
990
991
|
return useContext(CategoryContext);
|
|
991
992
|
};
|
|
992
|
-
function
|
|
993
|
+
var usePrimaryCategory = function usePrimaryCategory() {
|
|
994
|
+
return useContext(PrimaryCategoryContext);
|
|
995
|
+
};
|
|
996
|
+
var ProductMediaContext = /*#__PURE__*/React.createContext(undefined);
|
|
997
|
+
function ProductMediaProvider(_ref3) {
|
|
993
998
|
var mediaIndex = _ref3.mediaIndex,
|
|
994
999
|
onClick = _ref3.onClick,
|
|
995
1000
|
children = _ref3.children;
|
|
996
|
-
return React.createElement(
|
|
1001
|
+
return React.createElement(ProductMediaContext.Provider, {
|
|
997
1002
|
value: mediaIndex,
|
|
998
1003
|
key: mediaIndex
|
|
999
1004
|
}, React.cloneElement(React.isValidElement(children) ? children : React.createElement(React.Fragment, null), {
|
|
1000
1005
|
onClick: onClick
|
|
1001
1006
|
}));
|
|
1002
1007
|
}
|
|
1003
|
-
var
|
|
1004
|
-
return useContext(
|
|
1008
|
+
var useProductMediaContext = function useProductMediaContext() {
|
|
1009
|
+
return useContext(ProductMediaContext);
|
|
1005
1010
|
};
|
|
1006
1011
|
|
|
1007
1012
|
var _excluded = ["children"];
|
|
@@ -1668,9 +1673,11 @@ function CategoryCollection(props) {
|
|
|
1668
1673
|
return React.isValidElement(emptyMessage) ? emptyMessage : null;
|
|
1669
1674
|
}
|
|
1670
1675
|
|
|
1671
|
-
return
|
|
1676
|
+
return React.createElement(PrimaryCategoryContext.Provider, {
|
|
1677
|
+
value: firstCategoryNotEmpty != null ? firstCategoryNotEmpty : categories[0]
|
|
1678
|
+
}, noLayout ? React.createElement(React.Fragment, null, renderedData) : React.createElement("div", {
|
|
1672
1679
|
className: className
|
|
1673
|
-
}, renderedData);
|
|
1680
|
+
}, renderedData));
|
|
1674
1681
|
}
|
|
1675
1682
|
function registerCategoryCollection(loader, customCategoryCollectionMeta) {
|
|
1676
1683
|
var doRegisterComponent = function doRegisterComponent() {
|
|
@@ -1781,26 +1788,7 @@ var categoryMediaMeta = {
|
|
|
1781
1788
|
name: "plasmic-commerce-category-media",
|
|
1782
1789
|
displayName: "Category Media",
|
|
1783
1790
|
props: {
|
|
1784
|
-
mediaIndex: "number"
|
|
1785
|
-
mediaSize: {
|
|
1786
|
-
type: "choice",
|
|
1787
|
-
options: [{
|
|
1788
|
-
label: "Fill",
|
|
1789
|
-
value: "fill"
|
|
1790
|
-
}, {
|
|
1791
|
-
label: "Container",
|
|
1792
|
-
value: "contain"
|
|
1793
|
-
}, {
|
|
1794
|
-
label: "Cover",
|
|
1795
|
-
value: "cover"
|
|
1796
|
-
}, {
|
|
1797
|
-
label: "None",
|
|
1798
|
-
value: "none"
|
|
1799
|
-
}, {
|
|
1800
|
-
label: "Scale down",
|
|
1801
|
-
value: "scale-down"
|
|
1802
|
-
}]
|
|
1803
|
-
}
|
|
1791
|
+
mediaIndex: "number"
|
|
1804
1792
|
},
|
|
1805
1793
|
importPath: "@plasmicpkgs/commerce",
|
|
1806
1794
|
importName: "CategoryMedia"
|
|
@@ -1810,18 +1798,14 @@ function CategoryMedia(props) {
|
|
|
1810
1798
|
|
|
1811
1799
|
var className = props.className,
|
|
1812
1800
|
_props$mediaIndex = props.mediaIndex,
|
|
1813
|
-
mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex
|
|
1814
|
-
mediaSize = props.mediaSize;
|
|
1801
|
+
mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex;
|
|
1815
1802
|
var category = useCategoryContext();
|
|
1816
1803
|
var image = category != null && category.images ? category.images[mediaIndex] : undefined;
|
|
1817
1804
|
return React.createElement("img", {
|
|
1818
1805
|
alt: (category == null ? void 0 : category.name) || "Category Image",
|
|
1819
1806
|
src: (_image$url = image == null ? void 0 : image.url) != null ? _image$url : "",
|
|
1820
1807
|
loading: "lazy",
|
|
1821
|
-
className: className
|
|
1822
|
-
style: {
|
|
1823
|
-
objectFit: mediaSize
|
|
1824
|
-
}
|
|
1808
|
+
className: className
|
|
1825
1809
|
});
|
|
1826
1810
|
}
|
|
1827
1811
|
function registerCategoryMedia(loader, customCategoryMediaMeta) {
|
|
@@ -2017,8 +2001,13 @@ var productCollectionMeta = {
|
|
|
2017
2001
|
};
|
|
2018
2002
|
})) != null ? _ctx$categories$map : [];
|
|
2019
2003
|
},
|
|
2020
|
-
|
|
2021
|
-
|
|
2004
|
+
defaultValueHint: function defaultValueHint(props, ctx) {
|
|
2005
|
+
var _ctx$categoryCtx;
|
|
2006
|
+
|
|
2007
|
+
return ctx == null ? void 0 : (_ctx$categoryCtx = ctx.categoryCtx) == null ? void 0 : _ctx$categoryCtx.name;
|
|
2008
|
+
},
|
|
2009
|
+
readOnly: function readOnly(props, ctx) {
|
|
2010
|
+
return !!(ctx != null && ctx.categoryCtx);
|
|
2022
2011
|
}
|
|
2023
2012
|
},
|
|
2024
2013
|
includeSubCategories: {
|
|
@@ -2113,13 +2102,14 @@ function ProductCollection(props) {
|
|
|
2113
2102
|
isSearchLoading = _useSearch.isLoading;
|
|
2114
2103
|
|
|
2115
2104
|
var features = useCommerceExtraFeatures();
|
|
2105
|
+
var primaryCategory = usePrimaryCategory();
|
|
2116
2106
|
|
|
2117
2107
|
if (categories && brands) {
|
|
2118
2108
|
setControlContextData == null ? void 0 : setControlContextData({
|
|
2119
2109
|
categories: categories,
|
|
2120
2110
|
brands: brands,
|
|
2121
2111
|
features: features,
|
|
2122
|
-
|
|
2112
|
+
categoryCtx: primaryCategory
|
|
2123
2113
|
});
|
|
2124
2114
|
}
|
|
2125
2115
|
|
|
@@ -2218,25 +2208,12 @@ var productMediaMeta = {
|
|
|
2218
2208
|
name: "plasmic-commerce-product-media",
|
|
2219
2209
|
displayName: "Product Media",
|
|
2220
2210
|
props: {
|
|
2221
|
-
mediaIndex:
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
}, {
|
|
2228
|
-
label: "Container",
|
|
2229
|
-
value: "contain"
|
|
2230
|
-
}, {
|
|
2231
|
-
label: "Cover",
|
|
2232
|
-
value: "cover"
|
|
2233
|
-
}, {
|
|
2234
|
-
label: "None",
|
|
2235
|
-
value: "none"
|
|
2236
|
-
}, {
|
|
2237
|
-
label: "Scale down",
|
|
2238
|
-
value: "scale-down"
|
|
2239
|
-
}]
|
|
2211
|
+
mediaIndex: {
|
|
2212
|
+
type: "number",
|
|
2213
|
+
min: 0,
|
|
2214
|
+
hidden: function hidden(_, ctx) {
|
|
2215
|
+
return !!(ctx != null && ctx.inMediaContext);
|
|
2216
|
+
}
|
|
2240
2217
|
}
|
|
2241
2218
|
},
|
|
2242
2219
|
importPath: "@plasmicpkgs/commerce",
|
|
@@ -2248,18 +2225,18 @@ function ProductMedia(props) {
|
|
|
2248
2225
|
var className = props.className,
|
|
2249
2226
|
_props$mediaIndex = props.mediaIndex,
|
|
2250
2227
|
mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex,
|
|
2251
|
-
|
|
2228
|
+
setControlContextData = props.setControlContextData;
|
|
2252
2229
|
var product = useProduct();
|
|
2253
|
-
var
|
|
2254
|
-
|
|
2230
|
+
var mediaContext = useProductMediaContext();
|
|
2231
|
+
setControlContextData == null ? void 0 : setControlContextData({
|
|
2232
|
+
inMediaContext: mediaContext !== undefined
|
|
2233
|
+
});
|
|
2234
|
+
var image = product == null ? void 0 : product.images[mediaContext != null ? mediaContext : mediaIndex];
|
|
2255
2235
|
return React.createElement("img", {
|
|
2256
2236
|
alt: (product == null ? void 0 : product.name) || "Product Image",
|
|
2257
2237
|
src: product ? (_image$url = image == null ? void 0 : image.url) != null ? _image$url : "" : placeholderImage,
|
|
2258
2238
|
loading: "lazy",
|
|
2259
|
-
className: className
|
|
2260
|
-
style: {
|
|
2261
|
-
objectFit: mediaSize
|
|
2262
|
-
}
|
|
2239
|
+
className: className
|
|
2263
2240
|
});
|
|
2264
2241
|
}
|
|
2265
2242
|
function registerProductMedia(loader, customProductMediaMeta) {
|
|
@@ -2270,6 +2247,51 @@ function registerProductMedia(loader, customProductMediaMeta) {
|
|
|
2270
2247
|
doRegisterComponent(ProductMedia, customProductMediaMeta != null ? customProductMediaMeta : productMediaMeta);
|
|
2271
2248
|
}
|
|
2272
2249
|
|
|
2250
|
+
var productMediaCollectionMeta = {
|
|
2251
|
+
name: "plasmic-commerce-product-media-collection",
|
|
2252
|
+
displayName: "Product Media Collection",
|
|
2253
|
+
props: {
|
|
2254
|
+
media: {
|
|
2255
|
+
type: "slot",
|
|
2256
|
+
defaultValue: {
|
|
2257
|
+
type: "component",
|
|
2258
|
+
name: "plasmic-commerce-product-media"
|
|
2259
|
+
},
|
|
2260
|
+
allowedComponents: ["plasmic-commerce-product-media"]
|
|
2261
|
+
}
|
|
2262
|
+
},
|
|
2263
|
+
defaultStyles: {
|
|
2264
|
+
display: "grid",
|
|
2265
|
+
gridTemplateColumns: "1fr 1fr",
|
|
2266
|
+
gridRowGap: "8px",
|
|
2267
|
+
gridColumnGap: "8px",
|
|
2268
|
+
padding: "8px",
|
|
2269
|
+
maxWidth: "100%"
|
|
2270
|
+
},
|
|
2271
|
+
importPath: "@plasmicpkgs/commerce",
|
|
2272
|
+
importName: "ProductMediaCollection"
|
|
2273
|
+
};
|
|
2274
|
+
function ProductMediaCollection(props) {
|
|
2275
|
+
var media = props.media,
|
|
2276
|
+
className = props.className;
|
|
2277
|
+
var product = useProduct();
|
|
2278
|
+
return React.createElement("div", {
|
|
2279
|
+
className: className
|
|
2280
|
+
}, product == null ? void 0 : product.images.map(function (image, i) {
|
|
2281
|
+
return repeatedElement(i === 0, React.createElement(ProductMediaProvider, {
|
|
2282
|
+
mediaIndex: i,
|
|
2283
|
+
children: media
|
|
2284
|
+
}));
|
|
2285
|
+
}));
|
|
2286
|
+
}
|
|
2287
|
+
function registerProductMediaCollection(loader, customProductMediaCollectionMeta) {
|
|
2288
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
2289
|
+
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
2290
|
+
};
|
|
2291
|
+
|
|
2292
|
+
doRegisterComponent(ProductMediaCollection, customProductMediaCollectionMeta != null ? customProductMediaCollectionMeta : productMediaCollectionMeta);
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2273
2295
|
var getProductPrice = function getProductPrice(product, variantId) {
|
|
2274
2296
|
var _product$variants$fin, _product$variants$fin2;
|
|
2275
2297
|
|
|
@@ -2412,7 +2434,7 @@ function ProductSlider(props) {
|
|
|
2412
2434
|
var leftIndex = Math.min(maximumRight, Math.max(0, selected - 1));
|
|
2413
2435
|
return React.createElement("div", {
|
|
2414
2436
|
className: className
|
|
2415
|
-
}, React.createElement(
|
|
2437
|
+
}, React.createElement(ProductMediaProvider, {
|
|
2416
2438
|
mediaIndex: selected,
|
|
2417
2439
|
children: slideContainer
|
|
2418
2440
|
}), React.createElement("div", {
|
|
@@ -2421,7 +2443,7 @@ function ProductSlider(props) {
|
|
|
2421
2443
|
gridTemplateColumns: "repeat(" + thumbsVisible + ", 1fr)"
|
|
2422
2444
|
}
|
|
2423
2445
|
}, product.images.slice(leftIndex, leftIndex + thumbsVisible).map(function (image, i) {
|
|
2424
|
-
return repeatedElement(i === 0, React.createElement(
|
|
2446
|
+
return repeatedElement(i === 0, React.createElement(ProductMediaProvider, {
|
|
2425
2447
|
mediaIndex: leftIndex + i,
|
|
2426
2448
|
children: thumbsContainer,
|
|
2427
2449
|
onClick: function onClick() {
|
|
@@ -2591,6 +2613,7 @@ function registerAll(loader) {
|
|
|
2591
2613
|
registerTextField(loader);
|
|
2592
2614
|
registerProductPrice(loader);
|
|
2593
2615
|
registerProductMedia(loader);
|
|
2616
|
+
registerProductMediaCollection(loader);
|
|
2594
2617
|
registerCart(loader);
|
|
2595
2618
|
registerAddToCartButton(loader);
|
|
2596
2619
|
registerProductQuantity(loader);
|
|
@@ -2604,5 +2627,5 @@ function registerAll(loader) {
|
|
|
2604
2627
|
registerCategoryMedia(loader);
|
|
2605
2628
|
}
|
|
2606
2629
|
|
|
2607
|
-
export { AddToCartButton, CartComponent, cart as CartType, CategoryCollection, CategoryField, CategoryLink, CategoryMedia, CommerceError, CoreCommerceProvider, FetcherError, ProductBox, ProductCollection, ProductLink, ProductMedia, defaultProduct as ProductPlaceholder, ProductPriceComponent, ProductQuantity, ProductSlider, ProductTextField, product as ProductTypes, ProductVariantPicker, site as SiteTypes, ValidationError, addToCartButtonMeta, cartMeta, categoryCollectionMeta, categoryFieldMeta, categoryLinkMeta, categoryMediaMeta, fetcher$4 as fetcher, getCommerceProvider, productBoxMeta, productCollectionMeta, productLinkMeta, productMediaMeta, productPriceMeta, productQuantityMeta, productSliderMeta, productTextFieldMeta, productVariantPickerMeta, registerAddToCartButton, registerAll, registerCart, registerCategoryCollection, registerCategoryField, registerCategoryLink, registerCategoryMedia, registerProductBox, registerProductCollection, registerProductLink, registerProductMedia, registerProductPrice, registerProductQuantity, registerProductSlider, registerProductVariantPicker, registerTextField, useAddItem, useBrands, useCart, useCategories, useCommerce, useProduct$1 as useProduct, useRemoveItem, useSearch, useUpdateItem };
|
|
2630
|
+
export { AddToCartButton, CartComponent, cart as CartType, CategoryCollection, CategoryField, CategoryLink, CategoryMedia, CommerceError, CoreCommerceProvider, FetcherError, ProductBox, ProductCollection, ProductLink, ProductMedia, ProductMediaCollection, defaultProduct as ProductPlaceholder, ProductPriceComponent, ProductQuantity, ProductSlider, ProductTextField, product as ProductTypes, ProductVariantPicker, site as SiteTypes, ValidationError, addToCartButtonMeta, cartMeta, categoryCollectionMeta, categoryFieldMeta, categoryLinkMeta, categoryMediaMeta, fetcher$4 as fetcher, getCommerceProvider, productBoxMeta, productCollectionMeta, productLinkMeta, productMediaCollectionMeta, productMediaMeta, productPriceMeta, productQuantityMeta, productSliderMeta, productTextFieldMeta, productVariantPickerMeta, registerAddToCartButton, registerAll, registerCart, registerCategoryCollection, registerCategoryField, registerCategoryLink, registerCategoryMedia, registerProductBox, registerProductCollection, registerProductLink, registerProductMedia, registerProductMediaCollection, registerProductPrice, registerProductQuantity, registerProductSlider, registerProductVariantPicker, registerTextField, useAddItem, useBrands, useCart, useCategories, useCommerce, useProduct$1 as useProduct, useRemoveItem, useSearch, useUpdateItem };
|
|
2608
2631
|
//# sourceMappingURL=commerce.esm.js.map
|