@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.
@@ -933,9 +933,9 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
933
933
 
934
934
  var defaultProduct = {
935
935
  id: "123456789",
936
- name: "Product Placeholder",
936
+ name: "Product name",
937
937
  description: "",
938
- descriptionHtml: "\n <p>This is a <strong>placeholder</strong>.</p>\n <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>\n <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</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: "variiant1",
951
- name: "Variant Placeholder",
950
+ id: "variant1",
951
+ name: "Variant 1",
952
952
  options: []
953
953
  }, {
954
954
  id: "variant2",
955
- name: "Variant Placeholder 2",
955
+ name: "Variant 2",
956
956
  options: []
957
957
  }],
958
958
  price: {
@@ -993,20 +993,20 @@ var useCategoryContext = function useCategoryContext() {
993
993
  var usePrimaryCategory = function usePrimaryCategory() {
994
994
  return useContext(PrimaryCategoryContext);
995
995
  };
996
- var SliderContext = /*#__PURE__*/React.createContext(undefined);
997
- function ProductSliderProvider(_ref3) {
996
+ var ProductMediaContext = /*#__PURE__*/React.createContext(undefined);
997
+ function ProductMediaProvider(_ref3) {
998
998
  var mediaIndex = _ref3.mediaIndex,
999
999
  onClick = _ref3.onClick,
1000
1000
  children = _ref3.children;
1001
- return React.createElement(SliderContext.Provider, {
1001
+ return React.createElement(ProductMediaContext.Provider, {
1002
1002
  value: mediaIndex,
1003
1003
  key: mediaIndex
1004
1004
  }, React.cloneElement(React.isValidElement(children) ? children : React.createElement(React.Fragment, null), {
1005
1005
  onClick: onClick
1006
1006
  }));
1007
1007
  }
1008
- var useProductSliderContext = function useProductSliderContext() {
1009
- return useContext(SliderContext);
1008
+ var useProductMediaContext = function useProductMediaContext() {
1009
+ return useContext(ProductMediaContext);
1010
1010
  };
1011
1011
 
1012
1012
  var _excluded = ["children"];
@@ -1788,26 +1788,7 @@ var categoryMediaMeta = {
1788
1788
  name: "plasmic-commerce-category-media",
1789
1789
  displayName: "Category Media",
1790
1790
  props: {
1791
- mediaIndex: "number",
1792
- mediaSize: {
1793
- type: "choice",
1794
- options: [{
1795
- label: "Fill",
1796
- value: "fill"
1797
- }, {
1798
- label: "Container",
1799
- value: "contain"
1800
- }, {
1801
- label: "Cover",
1802
- value: "cover"
1803
- }, {
1804
- label: "None",
1805
- value: "none"
1806
- }, {
1807
- label: "Scale down",
1808
- value: "scale-down"
1809
- }]
1810
- }
1791
+ mediaIndex: "number"
1811
1792
  },
1812
1793
  importPath: "@plasmicpkgs/commerce",
1813
1794
  importName: "CategoryMedia"
@@ -1817,18 +1798,14 @@ function CategoryMedia(props) {
1817
1798
 
1818
1799
  var className = props.className,
1819
1800
  _props$mediaIndex = props.mediaIndex,
1820
- mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex,
1821
- mediaSize = props.mediaSize;
1801
+ mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex;
1822
1802
  var category = useCategoryContext();
1823
1803
  var image = category != null && category.images ? category.images[mediaIndex] : undefined;
1824
1804
  return React.createElement("img", {
1825
1805
  alt: (category == null ? void 0 : category.name) || "Category Image",
1826
1806
  src: (_image$url = image == null ? void 0 : image.url) != null ? _image$url : "",
1827
1807
  loading: "lazy",
1828
- className: className,
1829
- style: {
1830
- objectFit: mediaSize
1831
- }
1808
+ className: className
1832
1809
  });
1833
1810
  }
1834
1811
  function registerCategoryMedia(loader, customCategoryMediaMeta) {
@@ -2231,25 +2208,12 @@ var productMediaMeta = {
2231
2208
  name: "plasmic-commerce-product-media",
2232
2209
  displayName: "Product Media",
2233
2210
  props: {
2234
- mediaIndex: "number",
2235
- mediaSize: {
2236
- type: "choice",
2237
- options: [{
2238
- label: "Fill",
2239
- value: "fill"
2240
- }, {
2241
- label: "Container",
2242
- value: "contain"
2243
- }, {
2244
- label: "Cover",
2245
- value: "cover"
2246
- }, {
2247
- label: "None",
2248
- value: "none"
2249
- }, {
2250
- label: "Scale down",
2251
- value: "scale-down"
2252
- }]
2211
+ mediaIndex: {
2212
+ type: "number",
2213
+ min: 0,
2214
+ hidden: function hidden(_, ctx) {
2215
+ return !!(ctx != null && ctx.inMediaContext);
2216
+ }
2253
2217
  }
2254
2218
  },
2255
2219
  importPath: "@plasmicpkgs/commerce",
@@ -2261,18 +2225,18 @@ function ProductMedia(props) {
2261
2225
  var className = props.className,
2262
2226
  _props$mediaIndex = props.mediaIndex,
2263
2227
  mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex,
2264
- mediaSize = props.mediaSize;
2228
+ setControlContextData = props.setControlContextData;
2265
2229
  var product = useProduct();
2266
- var sliderContext = useProductSliderContext();
2267
- var image = product == null ? void 0 : product.images[sliderContext != null ? sliderContext : mediaIndex];
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];
2268
2235
  return React.createElement("img", {
2269
2236
  alt: (product == null ? void 0 : product.name) || "Product Image",
2270
2237
  src: product ? (_image$url = image == null ? void 0 : image.url) != null ? _image$url : "" : placeholderImage,
2271
2238
  loading: "lazy",
2272
- className: className,
2273
- style: {
2274
- objectFit: mediaSize
2275
- }
2239
+ className: className
2276
2240
  });
2277
2241
  }
2278
2242
  function registerProductMedia(loader, customProductMediaMeta) {
@@ -2283,6 +2247,51 @@ function registerProductMedia(loader, customProductMediaMeta) {
2283
2247
  doRegisterComponent(ProductMedia, customProductMediaMeta != null ? customProductMediaMeta : productMediaMeta);
2284
2248
  }
2285
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
+
2286
2295
  var getProductPrice = function getProductPrice(product, variantId) {
2287
2296
  var _product$variants$fin, _product$variants$fin2;
2288
2297
 
@@ -2421,11 +2430,11 @@ function ProductSlider(props) {
2421
2430
  selected = _React$useState[0],
2422
2431
  setSelected = _React$useState[1];
2423
2432
 
2424
- var maximumRight = product.images.length - thumbsVisible;
2425
- var leftIndex = Math.min(maximumRight, Math.max(0, selected - 1));
2433
+ var maximumLeft = Math.max(0, product.images.length - thumbsVisible);
2434
+ var leftIndex = Math.min(maximumLeft, Math.max(0, selected - 1));
2426
2435
  return React.createElement("div", {
2427
2436
  className: className
2428
- }, React.createElement(ProductSliderProvider, {
2437
+ }, React.createElement(ProductMediaProvider, {
2429
2438
  mediaIndex: selected,
2430
2439
  children: slideContainer
2431
2440
  }), React.createElement("div", {
@@ -2434,7 +2443,7 @@ function ProductSlider(props) {
2434
2443
  gridTemplateColumns: "repeat(" + thumbsVisible + ", 1fr)"
2435
2444
  }
2436
2445
  }, product.images.slice(leftIndex, leftIndex + thumbsVisible).map(function (image, i) {
2437
- return repeatedElement(i === 0, React.createElement(ProductSliderProvider, {
2446
+ return repeatedElement(i === 0, React.createElement(ProductMediaProvider, {
2438
2447
  mediaIndex: leftIndex + i,
2439
2448
  children: thumbsContainer,
2440
2449
  onClick: function onClick() {
@@ -2604,6 +2613,7 @@ function registerAll(loader) {
2604
2613
  registerTextField(loader);
2605
2614
  registerProductPrice(loader);
2606
2615
  registerProductMedia(loader);
2616
+ registerProductMediaCollection(loader);
2607
2617
  registerCart(loader);
2608
2618
  registerAddToCartButton(loader);
2609
2619
  registerProductQuantity(loader);
@@ -2617,5 +2627,5 @@ function registerAll(loader) {
2617
2627
  registerCategoryMedia(loader);
2618
2628
  }
2619
2629
 
2620
- 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 };
2621
2631
  //# sourceMappingURL=commerce.esm.js.map