@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.
@@ -940,9 +940,9 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
940
940
 
941
941
  var defaultProduct = {
942
942
  id: "123456789",
943
- name: "Product Placeholder",
943
+ name: "Product name",
944
944
  description: "",
945
- 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 ",
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: "variiant1",
958
- name: "Variant Placeholder",
957
+ id: "variant1",
958
+ name: "Variant 1",
959
959
  options: []
960
960
  }, {
961
961
  id: "variant2",
962
- name: "Variant Placeholder 2",
962
+ name: "Variant 2",
963
963
  options: []
964
964
  }],
965
965
  price: {
@@ -970,8 +970,6 @@ var defaultProduct = {
970
970
  };
971
971
 
972
972
  var ProductContext = /*#__PURE__*/React__default.createContext(undefined);
973
- var CategoryContext = /*#__PURE__*/React__default.createContext(undefined);
974
- var SliderContext = /*#__PURE__*/React__default.createContext(undefined);
975
973
  function ProductProvider(_ref) {
976
974
  var product = _ref.product,
977
975
  children = _ref.children;
@@ -985,6 +983,9 @@ var useProduct = function useProduct() {
985
983
  var product = React.useContext(ProductContext);
986
984
  return product != null ? product : defaultProduct;
987
985
  };
986
+ var CategoryContext = /*#__PURE__*/React__default.createContext(undefined);
987
+ var PrimaryCategoryContext = /*#__PURE__*/React__default.createContext(undefined); //used to render correctly the defaultValueHint in ProductCollection
988
+
988
989
  function CategoryProvider(_ref2) {
989
990
  var category = _ref2.category,
990
991
  children = _ref2.children;
@@ -996,19 +997,23 @@ function CategoryProvider(_ref2) {
996
997
  var useCategoryContext = function useCategoryContext() {
997
998
  return React.useContext(CategoryContext);
998
999
  };
999
- function ProductSliderProvider(_ref3) {
1000
+ var usePrimaryCategory = function usePrimaryCategory() {
1001
+ return React.useContext(PrimaryCategoryContext);
1002
+ };
1003
+ var ProductMediaContext = /*#__PURE__*/React__default.createContext(undefined);
1004
+ function ProductMediaProvider(_ref3) {
1000
1005
  var mediaIndex = _ref3.mediaIndex,
1001
1006
  onClick = _ref3.onClick,
1002
1007
  children = _ref3.children;
1003
- return React__default.createElement(SliderContext.Provider, {
1008
+ return React__default.createElement(ProductMediaContext.Provider, {
1004
1009
  value: mediaIndex,
1005
1010
  key: mediaIndex
1006
1011
  }, React__default.cloneElement(React__default.isValidElement(children) ? children : React__default.createElement(React__default.Fragment, null), {
1007
1012
  onClick: onClick
1008
1013
  }));
1009
1014
  }
1010
- var useProductSliderContext = function useProductSliderContext() {
1011
- return React.useContext(SliderContext);
1015
+ var useProductMediaContext = function useProductMediaContext() {
1016
+ return React.useContext(ProductMediaContext);
1012
1017
  };
1013
1018
 
1014
1019
  var _excluded = ["children"];
@@ -1675,9 +1680,11 @@ function CategoryCollection(props) {
1675
1680
  return React__default.isValidElement(emptyMessage) ? emptyMessage : null;
1676
1681
  }
1677
1682
 
1678
- return noLayout ? React__default.createElement(React__default.Fragment, null, renderedData) : React__default.createElement("div", {
1683
+ return React__default.createElement(PrimaryCategoryContext.Provider, {
1684
+ value: firstCategoryNotEmpty != null ? firstCategoryNotEmpty : categories[0]
1685
+ }, noLayout ? React__default.createElement(React__default.Fragment, null, renderedData) : React__default.createElement("div", {
1679
1686
  className: className
1680
- }, renderedData);
1687
+ }, renderedData));
1681
1688
  }
1682
1689
  function registerCategoryCollection(loader, customCategoryCollectionMeta) {
1683
1690
  var doRegisterComponent = function doRegisterComponent() {
@@ -1788,26 +1795,7 @@ var categoryMediaMeta = {
1788
1795
  name: "plasmic-commerce-category-media",
1789
1796
  displayName: "Category Media",
1790
1797
  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
- }
1798
+ mediaIndex: "number"
1811
1799
  },
1812
1800
  importPath: "@plasmicpkgs/commerce",
1813
1801
  importName: "CategoryMedia"
@@ -1817,18 +1805,14 @@ function CategoryMedia(props) {
1817
1805
 
1818
1806
  var className = props.className,
1819
1807
  _props$mediaIndex = props.mediaIndex,
1820
- mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex,
1821
- mediaSize = props.mediaSize;
1808
+ mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex;
1822
1809
  var category = useCategoryContext();
1823
1810
  var image = category != null && category.images ? category.images[mediaIndex] : undefined;
1824
1811
  return React__default.createElement("img", {
1825
1812
  alt: (category == null ? void 0 : category.name) || "Category Image",
1826
1813
  src: (_image$url = image == null ? void 0 : image.url) != null ? _image$url : "",
1827
1814
  loading: "lazy",
1828
- className: className,
1829
- style: {
1830
- objectFit: mediaSize
1831
- }
1815
+ className: className
1832
1816
  });
1833
1817
  }
1834
1818
  function registerCategoryMedia(loader, customCategoryMediaMeta) {
@@ -2024,8 +2008,13 @@ var productCollectionMeta = {
2024
2008
  };
2025
2009
  })) != null ? _ctx$categories$map : [];
2026
2010
  },
2027
- hidden: function hidden(props, ctx) {
2028
- return !!(ctx != null && ctx.hasCategoryCtx);
2011
+ defaultValueHint: function defaultValueHint(props, ctx) {
2012
+ var _ctx$categoryCtx;
2013
+
2014
+ return ctx == null ? void 0 : (_ctx$categoryCtx = ctx.categoryCtx) == null ? void 0 : _ctx$categoryCtx.name;
2015
+ },
2016
+ readOnly: function readOnly(props, ctx) {
2017
+ return !!(ctx != null && ctx.categoryCtx);
2029
2018
  }
2030
2019
  },
2031
2020
  includeSubCategories: {
@@ -2120,13 +2109,14 @@ function ProductCollection(props) {
2120
2109
  isSearchLoading = _useSearch.isLoading;
2121
2110
 
2122
2111
  var features = useCommerceExtraFeatures();
2112
+ var primaryCategory = usePrimaryCategory();
2123
2113
 
2124
2114
  if (categories && brands) {
2125
2115
  setControlContextData == null ? void 0 : setControlContextData({
2126
2116
  categories: categories,
2127
2117
  brands: brands,
2128
2118
  features: features,
2129
- hasCategoryCtx: !!categoryCtx
2119
+ categoryCtx: primaryCategory
2130
2120
  });
2131
2121
  }
2132
2122
 
@@ -2225,25 +2215,12 @@ var productMediaMeta = {
2225
2215
  name: "plasmic-commerce-product-media",
2226
2216
  displayName: "Product Media",
2227
2217
  props: {
2228
- mediaIndex: "number",
2229
- mediaSize: {
2230
- type: "choice",
2231
- options: [{
2232
- label: "Fill",
2233
- value: "fill"
2234
- }, {
2235
- label: "Container",
2236
- value: "contain"
2237
- }, {
2238
- label: "Cover",
2239
- value: "cover"
2240
- }, {
2241
- label: "None",
2242
- value: "none"
2243
- }, {
2244
- label: "Scale down",
2245
- value: "scale-down"
2246
- }]
2218
+ mediaIndex: {
2219
+ type: "number",
2220
+ min: 0,
2221
+ hidden: function hidden(_, ctx) {
2222
+ return !!(ctx != null && ctx.inMediaContext);
2223
+ }
2247
2224
  }
2248
2225
  },
2249
2226
  importPath: "@plasmicpkgs/commerce",
@@ -2255,18 +2232,18 @@ function ProductMedia(props) {
2255
2232
  var className = props.className,
2256
2233
  _props$mediaIndex = props.mediaIndex,
2257
2234
  mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex,
2258
- mediaSize = props.mediaSize;
2235
+ setControlContextData = props.setControlContextData;
2259
2236
  var product = useProduct();
2260
- var sliderContext = useProductSliderContext();
2261
- var image = product == null ? void 0 : product.images[sliderContext != null ? sliderContext : mediaIndex];
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];
2262
2242
  return React__default.createElement("img", {
2263
2243
  alt: (product == null ? void 0 : product.name) || "Product Image",
2264
2244
  src: product ? (_image$url = image == null ? void 0 : image.url) != null ? _image$url : "" : placeholderImage,
2265
2245
  loading: "lazy",
2266
- className: className,
2267
- style: {
2268
- objectFit: mediaSize
2269
- }
2246
+ className: className
2270
2247
  });
2271
2248
  }
2272
2249
  function registerProductMedia(loader, customProductMediaMeta) {
@@ -2277,6 +2254,51 @@ function registerProductMedia(loader, customProductMediaMeta) {
2277
2254
  doRegisterComponent(ProductMedia, customProductMediaMeta != null ? customProductMediaMeta : productMediaMeta);
2278
2255
  }
2279
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
+
2280
2302
  var getProductPrice = function getProductPrice(product, variantId) {
2281
2303
  var _product$variants$fin, _product$variants$fin2;
2282
2304
 
@@ -2419,7 +2441,7 @@ function ProductSlider(props) {
2419
2441
  var leftIndex = Math.min(maximumRight, Math.max(0, selected - 1));
2420
2442
  return React__default.createElement("div", {
2421
2443
  className: className
2422
- }, React__default.createElement(ProductSliderProvider, {
2444
+ }, React__default.createElement(ProductMediaProvider, {
2423
2445
  mediaIndex: selected,
2424
2446
  children: slideContainer
2425
2447
  }), React__default.createElement("div", {
@@ -2428,7 +2450,7 @@ function ProductSlider(props) {
2428
2450
  gridTemplateColumns: "repeat(" + thumbsVisible + ", 1fr)"
2429
2451
  }
2430
2452
  }, product.images.slice(leftIndex, leftIndex + thumbsVisible).map(function (image, i) {
2431
- return host.repeatedElement(i === 0, React__default.createElement(ProductSliderProvider, {
2453
+ return host.repeatedElement(i === 0, React__default.createElement(ProductMediaProvider, {
2432
2454
  mediaIndex: leftIndex + i,
2433
2455
  children: thumbsContainer,
2434
2456
  onClick: function onClick() {
@@ -2598,6 +2620,7 @@ function registerAll(loader) {
2598
2620
  registerTextField(loader);
2599
2621
  registerProductPrice(loader);
2600
2622
  registerProductMedia(loader);
2623
+ registerProductMediaCollection(loader);
2601
2624
  registerCart(loader);
2602
2625
  registerAddToCartButton(loader);
2603
2626
  registerProductQuantity(loader);
@@ -2625,6 +2648,7 @@ exports.ProductBox = ProductBox;
2625
2648
  exports.ProductCollection = ProductCollection;
2626
2649
  exports.ProductLink = ProductLink;
2627
2650
  exports.ProductMedia = ProductMedia;
2651
+ exports.ProductMediaCollection = ProductMediaCollection;
2628
2652
  exports.ProductPlaceholder = defaultProduct;
2629
2653
  exports.ProductPriceComponent = ProductPriceComponent;
2630
2654
  exports.ProductQuantity = ProductQuantity;
@@ -2645,6 +2669,7 @@ exports.getCommerceProvider = getCommerceProvider;
2645
2669
  exports.productBoxMeta = productBoxMeta;
2646
2670
  exports.productCollectionMeta = productCollectionMeta;
2647
2671
  exports.productLinkMeta = productLinkMeta;
2672
+ exports.productMediaCollectionMeta = productMediaCollectionMeta;
2648
2673
  exports.productMediaMeta = productMediaMeta;
2649
2674
  exports.productPriceMeta = productPriceMeta;
2650
2675
  exports.productQuantityMeta = productQuantityMeta;
@@ -2662,6 +2687,7 @@ exports.registerProductBox = registerProductBox;
2662
2687
  exports.registerProductCollection = registerProductCollection;
2663
2688
  exports.registerProductLink = registerProductLink;
2664
2689
  exports.registerProductMedia = registerProductMedia;
2690
+ exports.registerProductMediaCollection = registerProductMediaCollection;
2665
2691
  exports.registerProductPrice = registerProductPrice;
2666
2692
  exports.registerProductQuantity = registerProductQuantity;
2667
2693
  exports.registerProductSlider = registerProductSlider;