@crystaldesign/widget-image-carousel 25.9.0-beta.31 → 25.9.0-beta.33

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.
@@ -23,6 +23,9 @@ import { jsx, jsxs } from 'react/jsx-runtime';
23
23
  globalThis.process = { env:env };
24
24
  })();
25
25
 
26
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
27
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
28
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
26
29
  function useImageCarousel(_ref) {
27
30
  var productId = _ref.productId,
28
31
  settings = _ref.settings;
@@ -128,29 +131,30 @@ function useImageCarousel(_ref) {
128
131
  }
129
132
  function _getWallMockups() {
130
133
  _getWallMockups = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(product, wallMockupFunctionType) {
131
- var _product$customData, _product$customData2;
132
- var wallMockupDivaNrs, wallMockupProducts, optCodex, optOpvPairsToSearch, media, _loop, i;
133
- return _regeneratorRuntime.wrap(function _callee2$(_context4) {
134
- while (1) switch (_context4.prev = _context4.next) {
134
+ var _product$customData, _product$customData2, _product$customData3;
135
+ var wallMockupDivaNrs, wallMockupProducts, optCodex, opvMapping, optOpvPairsToSearch, media, _loop, i;
136
+ return _regeneratorRuntime.wrap(function _callee2$(_context5) {
137
+ while (1) switch (_context5.prev = _context5.next) {
135
138
  case 0:
136
139
  wallMockupDivaNrs = (_product$customData = product.customData) === null || _product$customData === void 0 || (_product$customData = _product$customData['WALL_MOCKUP_DIVANRS']) === null || _product$customData === void 0 ? void 0 : _product$customData.value;
137
140
  if (wallMockupDivaNrs) {
138
- _context4.next = 3;
141
+ _context5.next = 3;
139
142
  break;
140
143
  }
141
- return _context4.abrupt("return", undefined);
144
+ return _context5.abrupt("return", undefined);
142
145
  case 3:
143
- _context4.next = 5;
146
+ _context5.next = 5;
144
147
  return getProductsByDivaNrs(wallMockupDivaNrs);
145
148
  case 5:
146
- wallMockupProducts = _context4.sent;
149
+ wallMockupProducts = _context5.sent;
147
150
  optCodex = (_product$customData2 = product.customData) === null || _product$customData2 === void 0 || (_product$customData2 = _product$customData2['OPT_TO_CHECK']) === null || _product$customData2 === void 0 ? void 0 : _product$customData2.value;
148
- if (optCodex) {
149
- _context4.next = 9;
151
+ opvMapping = (_product$customData3 = product.customData) === null || _product$customData3 === void 0 || (_product$customData3 = _product$customData3['MANUAL_OPV_MAPPING']) === null || _product$customData3 === void 0 ? void 0 : _product$customData3.value;
152
+ if (!(!optCodex && !opvMapping)) {
153
+ _context5.next = 10;
150
154
  break;
151
155
  }
152
- throw new Error('OPT_TO_CHECK is not set- ProductId: ' + product._id);
153
- case 9:
156
+ throw new Error('OPT_TO_CHECK or MANUAL_OPV_MAPPING is not set- ProductId: ' + product._id);
157
+ case 10:
154
158
  optOpvPairsToSearch = [];
155
159
  optCodex.forEach(function (opt) {
156
160
  var _product$configuratio;
@@ -158,30 +162,32 @@ function useImageCarousel(_ref) {
158
162
  });
159
163
  media = [];
160
164
  _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
161
- var currentDivaNr, currentMockupVariants, _loop2, j;
162
- return _regeneratorRuntime.wrap(function _loop$(_context3) {
163
- while (1) switch (_context3.prev = _context3.next) {
165
+ var currentDivaNr, currentMockupVariants, foundMedia, _loop2, j, currentProducts, _iterator, _step, _loop3;
166
+ return _regeneratorRuntime.wrap(function _loop$(_context4) {
167
+ while (1) switch (_context4.prev = _context4.next) {
164
168
  case 0:
165
169
  currentDivaNr = wallMockupDivaNrs[i];
166
170
  currentMockupVariants = wallMockupProducts.data.filter(function (wmp) {
167
171
  return wmp.divaNr === currentDivaNr && wmp.baseProduct === false;
168
172
  });
173
+ foundMedia = false;
169
174
  _loop2 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop2() {
170
175
  var variant, allMatch, _variant$media, mediaUrl;
171
- return _regeneratorRuntime.wrap(function _loop2$(_context2) {
172
- while (1) switch (_context2.prev = _context2.next) {
176
+ return _regeneratorRuntime.wrap(function _loop2$(_context3) {
177
+ while (1) switch (_context3.prev = _context3.next) {
173
178
  case 0:
174
179
  variant = currentMockupVariants[j]; // check if all opt-opv-pairs match
175
180
  allMatch = optCodex.every(function (opt) {
176
- var _product$configuratio2, _variant$configuratio;
177
- var mainProductOPV = (_product$configuratio2 = product.configuration) === null || _product$configuratio2 === void 0 || (_product$configuratio2 = _product$configuratio2.OrderSets[0].Variant) === null || _product$configuratio2 === void 0 ? void 0 : _product$configuratio2[opt];
181
+ var _product$configuratio3, _variant$configuratio;
182
+ var mainProductOPV = (_product$configuratio3 = product.configuration) === null || _product$configuratio3 === void 0 || (_product$configuratio3 = _product$configuratio3.OrderSets[0].Variant) === null || _product$configuratio3 === void 0 ? void 0 : _product$configuratio3[opt];
178
183
  var variantOPV = (_variant$configuratio = variant.configuration) === null || _variant$configuratio === void 0 || (_variant$configuratio = _variant$configuratio.OrderSets[0].Variant) === null || _variant$configuratio === void 0 ? void 0 : _variant$configuratio[opt];
179
184
  return variantOPV === mainProductOPV;
180
185
  });
181
186
  if (!allMatch) {
182
- _context2.next = 8;
187
+ _context3.next = 8;
183
188
  break;
184
189
  }
190
+ foundMedia = true;
185
191
  setProductCache(variant._id, wallMockupProducts.data.filter(function (wmp) {
186
192
  return wmp.divaNr === currentDivaNr;
187
193
  }));
@@ -192,90 +198,162 @@ function useImageCarousel(_ref) {
192
198
  url: mediaUrl,
193
199
  productId: variant._id
194
200
  });
195
- return _context2.abrupt("return", 1);
201
+ return _context3.abrupt("return", 1);
196
202
  case 8:
197
203
  case "end":
198
- return _context2.stop();
204
+ return _context3.stop();
199
205
  }
200
206
  }, _loop2);
201
207
  });
202
208
  j = 0;
203
209
  case 5:
204
210
  if (!(j < currentMockupVariants.length)) {
205
- _context3.next = 12;
211
+ _context4.next = 12;
206
212
  break;
207
213
  }
208
- return _context3.delegateYield(_loop2(), "t0", 7);
214
+ return _context4.delegateYield(_loop2(), "t0", 7);
209
215
  case 7:
210
- if (!_context3.t0) {
211
- _context3.next = 9;
216
+ if (!_context4.t0) {
217
+ _context4.next = 9;
212
218
  break;
213
219
  }
214
- return _context3.abrupt("break", 12);
220
+ return _context4.abrupt("break", 12);
215
221
  case 9:
216
222
  j++;
217
- _context3.next = 5;
223
+ _context4.next = 5;
218
224
  break;
219
225
  case 12:
226
+ if (foundMedia) {
227
+ _context4.next = 30;
228
+ break;
229
+ }
230
+ //Search opv mapping
231
+ currentProducts = wallMockupProducts.data.filter(function (wmp) {
232
+ return wmp.divaNr === currentDivaNr;
233
+ });
234
+ _iterator = _createForOfIteratorHelper(opvMapping);
235
+ _context4.prev = 15;
236
+ _loop3 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop3() {
237
+ var _product$configuratio2;
238
+ var opvMappingItem, sourceOPT, sourceOPV, targetOPT, targetOPV, sourceProductOPV, targetProduct, _targetProduct$media, mediaUrl;
239
+ return _regeneratorRuntime.wrap(function _loop3$(_context2) {
240
+ while (1) switch (_context2.prev = _context2.next) {
241
+ case 0:
242
+ opvMappingItem = _step.value;
243
+ sourceOPT = opvMappingItem['SOURCE'].split('#')[0];
244
+ sourceOPV = opvMappingItem['SOURCE'].split('#')[1];
245
+ targetOPT = opvMappingItem['TARGET'].split('#')[0];
246
+ targetOPV = opvMappingItem['TARGET'].split('#')[1];
247
+ sourceProductOPV = (_product$configuratio2 = product.configuration) === null || _product$configuratio2 === void 0 || (_product$configuratio2 = _product$configuratio2.OrderSets[0].Variant) === null || _product$configuratio2 === void 0 ? void 0 : _product$configuratio2[sourceOPT];
248
+ if (sourceProductOPV === sourceOPV) {
249
+ targetProduct = currentProducts.find(function (p) {
250
+ var _p$configuration, _p$configuration2;
251
+ return ((_p$configuration = p.configuration) === null || _p$configuration === void 0 || (_p$configuration = _p$configuration.OrderSets[0].Variant) === null || _p$configuration === void 0 ? void 0 : _p$configuration[targetOPT]) === targetOPV || hasMatchingOrderLine((_p$configuration2 = p.configuration) === null || _p$configuration2 === void 0 ? void 0 : _p$configuration2.OrderSets[0], targetOPT, targetOPV);
252
+ });
253
+ if (targetProduct) {
254
+ mediaUrl = targetProduct === null || targetProduct === void 0 || (_targetProduct$media = targetProduct.media) === null || _targetProduct$media === void 0 || (_targetProduct$media = _targetProduct$media.find(function (m) {
255
+ return m.functionType === wallMockupFunctionType;
256
+ })) === null || _targetProduct$media === void 0 ? void 0 : _targetProduct$media.url;
257
+ media.push({
258
+ url: mediaUrl,
259
+ productId: targetProduct._id
260
+ });
261
+ }
262
+ }
263
+ case 7:
264
+ case "end":
265
+ return _context2.stop();
266
+ }
267
+ }, _loop3);
268
+ });
269
+ _iterator.s();
270
+ case 18:
271
+ if ((_step = _iterator.n()).done) {
272
+ _context4.next = 22;
273
+ break;
274
+ }
275
+ return _context4.delegateYield(_loop3(), "t1", 20);
276
+ case 20:
277
+ _context4.next = 18;
278
+ break;
279
+ case 22:
280
+ _context4.next = 27;
281
+ break;
282
+ case 24:
283
+ _context4.prev = 24;
284
+ _context4.t2 = _context4["catch"](15);
285
+ _iterator.e(_context4.t2);
286
+ case 27:
287
+ _context4.prev = 27;
288
+ _iterator.f();
289
+ return _context4.finish(27);
290
+ case 30:
220
291
  case "end":
221
- return _context3.stop();
292
+ return _context4.stop();
222
293
  }
223
- }, _loop);
294
+ }, _loop, null, [[15, 24, 27, 30]]);
224
295
  });
225
296
  i = 0;
226
- case 14:
297
+ case 15:
227
298
  if (!(i < wallMockupDivaNrs.length)) {
228
- _context4.next = 19;
299
+ _context5.next = 20;
229
300
  break;
230
301
  }
231
- return _context4.delegateYield(_loop(), "t0", 16);
232
- case 16:
302
+ return _context5.delegateYield(_loop(), "t0", 17);
303
+ case 17:
233
304
  i++;
234
- _context4.next = 14;
305
+ _context5.next = 15;
235
306
  break;
236
- case 19:
237
- return _context4.abrupt("return", media);
238
307
  case 20:
308
+ return _context5.abrupt("return", media);
309
+ case 21:
239
310
  case "end":
240
- return _context4.stop();
311
+ return _context5.stop();
241
312
  }
242
313
  }, _callee2);
243
314
  }));
244
315
  return _getWallMockups.apply(this, arguments);
245
316
  }
317
+ function hasMatchingOrderLine(orderSet, targetOPT, targetOPV) {
318
+ return orderSet.OrderLines.some(function (line) {
319
+ return line.VariantBasketDatas.some(function (variant) {
320
+ return 'OPT' + variant.OPT === targetOPT && 'OPV' + variant.OPV === targetOPV;
321
+ });
322
+ });
323
+ }
246
324
  function getSimilarProductMedia(_x3, _x4, _x5) {
247
325
  return _getSimilarProductMedia.apply(this, arguments);
248
326
  }
249
327
  function _getSimilarProductMedia() {
250
328
  _getSimilarProductMedia = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(product, mediaFunctionType, description) {
251
- var _product$customData3;
329
+ var _product$customData4;
252
330
  var similarProductsDivaNr, similarProducts, media, i, _similarProduct$media, _similarProduct$media2, similarProduct, mediaUrl, desc, _similarProduct$descr;
253
- return _regeneratorRuntime.wrap(function _callee4$(_context6) {
254
- while (1) switch (_context6.prev = _context6.next) {
331
+ return _regeneratorRuntime.wrap(function _callee4$(_context7) {
332
+ while (1) switch (_context7.prev = _context7.next) {
255
333
  case 0:
256
- similarProductsDivaNr = (_product$customData3 = product.customData) === null || _product$customData3 === void 0 || (_product$customData3 = _product$customData3['SIMILAR_PRODUCTS_DIVANRS']) === null || _product$customData3 === void 0 ? void 0 : _product$customData3.value;
334
+ similarProductsDivaNr = (_product$customData4 = product.customData) === null || _product$customData4 === void 0 || (_product$customData4 = _product$customData4['SIMILAR_PRODUCTS_DIVANRS']) === null || _product$customData4 === void 0 ? void 0 : _product$customData4.value;
257
335
  if (!(!Array.isArray(similarProductsDivaNr) || similarProductsDivaNr.length === 0)) {
258
- _context6.next = 3;
336
+ _context7.next = 3;
259
337
  break;
260
338
  }
261
- return _context6.abrupt("return", []);
339
+ return _context7.abrupt("return", []);
262
340
  case 3:
263
- _context6.next = 5;
341
+ _context7.next = 5;
264
342
  return Promise.all(similarProductsDivaNr.map(/*#__PURE__*/function () {
265
343
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(divaNr) {
266
344
  var _divaNrParts$;
267
345
  var divaNrParts;
268
- return _regeneratorRuntime.wrap(function _callee3$(_context5) {
269
- while (1) switch (_context5.prev = _context5.next) {
346
+ return _regeneratorRuntime.wrap(function _callee3$(_context6) {
347
+ while (1) switch (_context6.prev = _context6.next) {
270
348
  case 0:
271
349
  divaNrParts = divaNr.split('-');
272
- _context5.next = 3;
350
+ _context6.next = 3;
273
351
  return getProductByDivaNrAndVariantId('DIVA-' + divaNrParts[1], (_divaNrParts$ = divaNrParts[2]) !== null && _divaNrParts$ !== void 0 ? _divaNrParts$ : undefined);
274
352
  case 3:
275
- return _context5.abrupt("return", _context5.sent);
353
+ return _context6.abrupt("return", _context6.sent);
276
354
  case 4:
277
355
  case "end":
278
- return _context5.stop();
356
+ return _context6.stop();
279
357
  }
280
358
  }, _callee3);
281
359
  }));
@@ -284,7 +362,7 @@ function useImageCarousel(_ref) {
284
362
  };
285
363
  }()));
286
364
  case 5:
287
- similarProducts = _context6.sent;
365
+ similarProducts = _context7.sent;
288
366
  media = [];
289
367
  for (i = 0; i < similarProducts.length; i++) {
290
368
  similarProduct = similarProducts[i].data[0];
@@ -304,10 +382,10 @@ function useImageCarousel(_ref) {
304
382
  });
305
383
  }
306
384
  }
307
- return _context6.abrupt("return", media);
385
+ return _context7.abrupt("return", media);
308
386
  case 9:
309
387
  case "end":
310
- return _context6.stop();
388
+ return _context7.stop();
311
389
  }
312
390
  }, _callee4);
313
391
  }));
@@ -0,0 +1,8 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { WithDivaMock } from '@crystaldesign/diva-core';
3
+ import { ImageCarouselProps } from '../../types';
4
+ declare const meta: Meta<WithDivaMock<ImageCarouselProps>>;
5
+ export default meta;
6
+ type Story = StoryObj<WithDivaMock<ImageCarouselProps>>;
7
+ export declare const ImageCarousel: Story;
8
+ //# sourceMappingURL=kirchner-prod.stories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kirchner-prod.stories.d.ts","sourceRoot":"","sources":["../../../../../../src/stories/WallMockup/kirchner-prod.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAqB,MAAM,0BAA0B,CAAC;AAG3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAIjD,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAmBhD,CAAC;AAEF,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAAC;AAuCxD,eAAO,MAAM,aAAa,EAAE,KAE3B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useImageCarousel.d.ts","sourceRoot":"","sources":["../../../../src/useImageCarousel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAM7C,UAAU,KAAK;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,gBAAgB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,kBAAkB;;;;;EAkI3E"}
1
+ {"version":3,"file":"useImageCarousel.d.ts","sourceRoot":"","sources":["../../../../src/useImageCarousel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAM7C,UAAU,KAAK;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,gBAAgB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,kBAAkB;;;;;EAgK3E"}