@crystaldesign/widget-library 25.7.5 → 25.8.0-beta.10
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/build/esm/index.js +501 -120
- package/build/types/widget-library/src/components/Gallery/index.d.ts.map +1 -1
- package/build/types/widget-library/src/components/Gallery/types.d.ts +1 -0
- package/build/types/widget-library/src/components/Gallery/types.d.ts.map +1 -1
- package/build/types/widget-library/src/components/Gallery/useGallery.d.ts +1 -0
- package/build/types/widget-library/src/components/Gallery/useGallery.d.ts.map +1 -1
- package/build/types/widget-library/src/components/MediaItem/index.d.ts +1 -0
- package/build/types/widget-library/src/components/MediaItem/index.d.ts.map +1 -1
- package/build/types/widget-library/src/hooks/useGlobalCache.d.ts +68 -0
- package/build/types/widget-library/src/hooks/useGlobalCache.d.ts.map +1 -0
- package/build/types/widget-library/src/hooks/useGlobalSelectedProduct.d.ts +32 -0
- package/build/types/widget-library/src/hooks/useGlobalSelectedProduct.d.ts.map +1 -0
- package/build/types/widget-library/src/hooks/useProductData.d.ts +11 -3
- package/build/types/widget-library/src/hooks/useProductData.d.ts.map +1 -1
- package/package.json +2 -2
package/build/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useMemo,
|
|
1
|
+
import { useEffect, useMemo, useCallback, useState, useRef, forwardRef } from 'react';
|
|
2
2
|
import { useDivaCore, getLogger, DivaError, useTranslation } from '@crystaldesign/diva-core';
|
|
3
3
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
4
4
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
@@ -80,142 +80,505 @@ function useConfiguration(type, componentSettings) {
|
|
|
80
80
|
return settings;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
var LOG$2 = getLogger('DivaWidget', 'useGlobalCache');
|
|
84
|
+
|
|
85
|
+
// Global cache for shared data between widgets
|
|
86
|
+
|
|
87
|
+
// Initialize global cache if not exists
|
|
88
|
+
if (typeof window !== 'undefined' && !window.__divaWidgetCache) {
|
|
89
|
+
window.__divaWidgetCache = {
|
|
90
|
+
cache: new Map()
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Global cache for shared data between widgets of a website
|
|
96
|
+
* Simple implementation with request deduplication
|
|
97
|
+
*/
|
|
98
|
+
function useGlobalCache(_ref) {
|
|
99
|
+
var uniqueWidgetId = _ref.uniqueWidgetId,
|
|
100
|
+
widgetType = _ref.widgetType;
|
|
101
|
+
var getOrFetch = useCallback(function (key, fetcher) {
|
|
102
|
+
LOG$2.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] getOrFetch called for key: ").concat(key));
|
|
103
|
+
if (typeof window === 'undefined' || !window.__divaWidgetCache) {
|
|
104
|
+
LOG$2.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] No global cache available, fetching directly for key: ").concat(key));
|
|
105
|
+
return fetcher();
|
|
106
|
+
}
|
|
107
|
+
var cache = window.__divaWidgetCache.cache;
|
|
108
|
+
var entry = cache.get(key);
|
|
109
|
+
|
|
110
|
+
// If we have cached data, return it immediately
|
|
111
|
+
if (entry !== null && entry !== void 0 && entry.data) {
|
|
112
|
+
LOG$2.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] Cache hit for key: ").concat(key, ", returning cached data"));
|
|
113
|
+
return Promise.resolve(entry.data);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// If there's already a pending request, return that promise (deduplication)
|
|
117
|
+
if (entry !== null && entry !== void 0 && entry.promise) {
|
|
118
|
+
LOG$2.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] Cache hit for pending request, returning existing promise for key: ").concat(key));
|
|
119
|
+
return entry.promise;
|
|
120
|
+
}
|
|
121
|
+
LOG$2.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] Cache miss for key: ").concat(key, ", creating new request"));
|
|
122
|
+
|
|
123
|
+
// Create new entry or reset existing one
|
|
124
|
+
var newEntry = {
|
|
125
|
+
data: null,
|
|
126
|
+
promise: null,
|
|
127
|
+
error: null,
|
|
128
|
+
timestamp: Date.now()
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// Create new request
|
|
132
|
+
var promise = fetcher().then(function (data) {
|
|
133
|
+
LOG$2.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] Request successful for key: ").concat(key, ", updating cache with ").concat(data.length, " items"));
|
|
134
|
+
var currentEntry = cache.get(key);
|
|
135
|
+
if (currentEntry) {
|
|
136
|
+
currentEntry.data = data;
|
|
137
|
+
currentEntry.promise = null;
|
|
138
|
+
currentEntry.error = null;
|
|
139
|
+
currentEntry.timestamp = Date.now();
|
|
140
|
+
}
|
|
141
|
+
return data;
|
|
142
|
+
})["catch"](function (error) {
|
|
143
|
+
LOG$2.error(new DivaError("[".concat(widgetType, ":").concat(uniqueWidgetId, "] Request failed for key: ").concat(key), {
|
|
144
|
+
cause: error
|
|
145
|
+
}));
|
|
146
|
+
var currentEntry = cache.get(key);
|
|
147
|
+
if (currentEntry) {
|
|
148
|
+
currentEntry.promise = null;
|
|
149
|
+
currentEntry.error = error;
|
|
150
|
+
currentEntry.timestamp = Date.now();
|
|
151
|
+
}
|
|
152
|
+
throw error;
|
|
153
|
+
});
|
|
154
|
+
newEntry.promise = promise;
|
|
155
|
+
cache.set(key, newEntry);
|
|
156
|
+
return promise;
|
|
157
|
+
}, [uniqueWidgetId, widgetType]);
|
|
158
|
+
var clear = useCallback(function (key) {
|
|
159
|
+
LOG$2.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] Clearing cache entry for key: ").concat(key));
|
|
160
|
+
if (typeof window !== 'undefined' && window.__divaWidgetCache) {
|
|
161
|
+
var deleted = window.__divaWidgetCache.cache["delete"](key);
|
|
162
|
+
LOG$2.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] Cache entry ").concat(deleted ? 'deleted' : 'not found', " for key: ").concat(key));
|
|
163
|
+
}
|
|
164
|
+
}, [uniqueWidgetId, widgetType]);
|
|
165
|
+
var clearAll = useCallback(function () {
|
|
166
|
+
LOG$2.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] Clearing all cache entries"));
|
|
167
|
+
if (typeof window !== 'undefined' && window.__divaWidgetCache) {
|
|
168
|
+
var size = window.__divaWidgetCache.cache.size;
|
|
169
|
+
window.__divaWidgetCache.cache.clear();
|
|
170
|
+
LOG$2.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] Cleared ").concat(size, " cache entries"));
|
|
171
|
+
}
|
|
172
|
+
}, [uniqueWidgetId, widgetType]);
|
|
173
|
+
var setCache = useCallback(function (key, data) {
|
|
174
|
+
LOG$2.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] Setting cache entry for key: ").concat(key));
|
|
175
|
+
if (typeof window !== 'undefined' && window.__divaWidgetCache) {
|
|
176
|
+
window.__divaWidgetCache.cache.set(key, data);
|
|
177
|
+
}
|
|
178
|
+
}, [uniqueWidgetId, widgetType]);
|
|
179
|
+
return useMemo(function () {
|
|
180
|
+
return {
|
|
181
|
+
getOrFetch: getOrFetch,
|
|
182
|
+
clear: clear,
|
|
183
|
+
clearAll: clearAll,
|
|
184
|
+
setCache: setCache
|
|
185
|
+
};
|
|
186
|
+
}, [getOrFetch, clear, clearAll, setCache]);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
var LOG$1 = getLogger('DivaWidget', 'useGlobalSelectedProduct');
|
|
190
|
+
var EVENT_NAME_PRODUCT_SELECTED = 'diva:widget:product-selected';
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Hook to get the globally selected product
|
|
194
|
+
*
|
|
195
|
+
* Initially and when the product changes, it gets selected.
|
|
196
|
+
* When ever the selected product is changed, an event is dispatched to notify other widgets, so they can also set the new product as selected.
|
|
197
|
+
* The hook also listens for product selection events from other widgets and updates the selected product accordingly.
|
|
198
|
+
*
|
|
199
|
+
* @param product - The product to select initially
|
|
200
|
+
* @returns The selected product and a function to set the selected product
|
|
201
|
+
*/
|
|
202
|
+
function useGlobalSelectedProduct(_ref) {
|
|
203
|
+
var selectedProduct = _ref.selectedProduct,
|
|
204
|
+
uniqueWidgetId = _ref.uniqueWidgetId,
|
|
205
|
+
widgetType = _ref.widgetType,
|
|
206
|
+
handleSelectedProductChange = _ref.handleSelectedProductChange;
|
|
207
|
+
// Listen to product selection events from other widgets
|
|
208
|
+
var handleProductSelection = useCallback(function (event) {
|
|
209
|
+
var customEvent = event;
|
|
210
|
+
var _customEvent$detail = customEvent.detail,
|
|
211
|
+
product = _customEvent$detail.product,
|
|
212
|
+
sourceId = _customEvent$detail.sourceId;
|
|
213
|
+
LOG$1.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] Received product selection event from ").concat(sourceId, ", product: ").concat(product._id));
|
|
214
|
+
|
|
215
|
+
// Ignore our own events
|
|
216
|
+
if (sourceId === uniqueWidgetId) {
|
|
217
|
+
LOG$1.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] Ignoring own event"));
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Ignore if product hasn't actually changed
|
|
222
|
+
if ((selectedProduct === null || selectedProduct === void 0 ? void 0 : selectedProduct._id) === product._id) {
|
|
223
|
+
LOG$1.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] Ignoring event - product already selected: ").concat(product._id));
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
LOG$1.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] Updating selected product from ").concat((selectedProduct === null || selectedProduct === void 0 ? void 0 : selectedProduct._id) || 'none', " to ").concat(product._id));
|
|
227
|
+
handleSelectedProductChange(product);
|
|
228
|
+
}, [uniqueWidgetId, selectedProduct, widgetType]);
|
|
229
|
+
|
|
230
|
+
// Stable event listener setup
|
|
231
|
+
useEffect(function () {
|
|
232
|
+
window.addEventListener(EVENT_NAME_PRODUCT_SELECTED, handleProductSelection);
|
|
233
|
+
return function () {
|
|
234
|
+
window.removeEventListener(EVENT_NAME_PRODUCT_SELECTED, handleProductSelection);
|
|
235
|
+
};
|
|
236
|
+
}, [handleProductSelection]);
|
|
237
|
+
var notifyProductChanged = useCallback(function (product) {
|
|
238
|
+
// Dispatch event to notify other widgets
|
|
239
|
+
LOG$1.debug("[".concat(widgetType, ":").concat(uniqueWidgetId, "] Dispatching product selection event to notify other widgets"));
|
|
240
|
+
window.dispatchEvent(new CustomEvent(EVENT_NAME_PRODUCT_SELECTED, {
|
|
241
|
+
detail: {
|
|
242
|
+
product: product,
|
|
243
|
+
sourceId: uniqueWidgetId
|
|
244
|
+
}
|
|
245
|
+
}));
|
|
246
|
+
}, [uniqueWidgetId, widgetType]);
|
|
247
|
+
return {
|
|
248
|
+
notifyProductChanged: notifyProductChanged
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
86
252
|
var LOG = getLogger('DivaWidget', 'useProductData');
|
|
253
|
+
// Generate unique widget instance ID
|
|
254
|
+
var generateWidgetId = function generateWidgetId() {
|
|
255
|
+
return "widget-".concat(Date.now(), "-").concat(Math.random().toString(36).substr(2, 9));
|
|
256
|
+
};
|
|
87
257
|
function useProductData(_ref) {
|
|
88
258
|
var productIds = _ref.productIds,
|
|
89
259
|
variants = _ref.variants,
|
|
90
|
-
|
|
260
|
+
widgetType = _ref.widgetType;
|
|
261
|
+
// Generate stable widget ID that persists for the lifetime of this hook instance
|
|
262
|
+
// Function to handle selectedProduct changes
|
|
263
|
+
|
|
264
|
+
var widgetId = useMemo(function () {
|
|
265
|
+
return generateWidgetId();
|
|
266
|
+
}, []);
|
|
91
267
|
var _useDivaCore = useDivaCore(),
|
|
92
268
|
handler = _useDivaCore.handler;
|
|
93
|
-
var
|
|
269
|
+
var _useGlobalCache = useGlobalCache({
|
|
270
|
+
uniqueWidgetId: widgetId,
|
|
271
|
+
widgetType: widgetType
|
|
272
|
+
}),
|
|
273
|
+
getOrFetch = _useGlobalCache.getOrFetch,
|
|
274
|
+
setCache = _useGlobalCache.setCache;
|
|
275
|
+
var _useState = useState([]),
|
|
94
276
|
_useState2 = _slicedToArray(_useState, 2),
|
|
95
277
|
productVariants = _useState2[0],
|
|
96
278
|
setProductVariants = _useState2[1];
|
|
97
|
-
var _useState3 = useState(
|
|
279
|
+
var _useState3 = useState(),
|
|
98
280
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
var _useState5 = useState(
|
|
281
|
+
selectedProduct = _useState4[0],
|
|
282
|
+
setSelectedProduct = _useState4[1];
|
|
283
|
+
var _useState5 = useState(false),
|
|
102
284
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
103
285
|
loading = _useState6[0],
|
|
104
286
|
setLoading = _useState6[1];
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
119
|
-
case 0:
|
|
120
|
-
_context2.prev = 0;
|
|
121
|
-
if (!variants) {
|
|
122
|
-
_context2.next = 6;
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
setProductVariants(variants);
|
|
126
|
-
newVariants = variants;
|
|
127
|
-
_context2.next = 13;
|
|
287
|
+
var _useState7 = useState(false),
|
|
288
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
289
|
+
error = _useState8[0],
|
|
290
|
+
setError = _useState8[1];
|
|
291
|
+
var fetchProducts = useCallback(/*#__PURE__*/function () {
|
|
292
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(ids) {
|
|
293
|
+
var productPromises, results, flattenedResults;
|
|
294
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
295
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
296
|
+
case 0:
|
|
297
|
+
LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] fetchProducts called with ids: ").concat(ids.join(', ')));
|
|
298
|
+
if (!variants) {
|
|
299
|
+
_context2.next = 4;
|
|
128
300
|
break;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
productsResults = _context2.sent;
|
|
138
|
-
// Flatten the array of arrays into a single array of variants
|
|
139
|
-
allProducts = productsResults.flat();
|
|
140
|
-
setProductVariants(allProducts);
|
|
141
|
-
newVariants = allProducts;
|
|
142
|
-
case 13:
|
|
143
|
-
// Log business events for loaded products
|
|
144
|
-
_iterator = _createForOfIteratorHelper(newVariants);
|
|
145
|
-
_context2.prev = 14;
|
|
146
|
-
_loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
|
|
147
|
-
var product, matchingProductId;
|
|
148
|
-
return _regeneratorRuntime.wrap(function _loop$(_context) {
|
|
301
|
+
}
|
|
302
|
+
LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Using provided variants instead of fetching"));
|
|
303
|
+
return _context2.abrupt("return", variants);
|
|
304
|
+
case 4:
|
|
305
|
+
// Create promises for all products (cached or to be fetched) to preserve order
|
|
306
|
+
productPromises = ids.map(/*#__PURE__*/function () {
|
|
307
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(id) {
|
|
308
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
149
309
|
while (1) switch (_context.prev = _context.next) {
|
|
150
310
|
case 0:
|
|
151
|
-
product
|
|
152
|
-
|
|
153
|
-
return
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
LOG.businessEvent('onLoadProductPDP', 'ProductDetailPage', 'Neues Product in PDP geladen.', {
|
|
157
|
-
productId: matchingProductId,
|
|
158
|
-
catalogName: product.modelName,
|
|
159
|
-
catalogCodex: product.catCodex
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
case 3:
|
|
311
|
+
LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Fetching product variants for id: ").concat(id));
|
|
312
|
+
return _context.abrupt("return", getOrFetch(id, function () {
|
|
313
|
+
return handler.productHandler.apiGetProductVariants(id, true);
|
|
314
|
+
}));
|
|
315
|
+
case 2:
|
|
163
316
|
case "end":
|
|
164
317
|
return _context.stop();
|
|
165
318
|
}
|
|
166
|
-
},
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
319
|
+
}, _callee);
|
|
320
|
+
}));
|
|
321
|
+
return function (_x2) {
|
|
322
|
+
return _ref3.apply(this, arguments);
|
|
323
|
+
};
|
|
324
|
+
}());
|
|
325
|
+
_context2.next = 7;
|
|
326
|
+
return Promise.all(productPromises);
|
|
327
|
+
case 7:
|
|
328
|
+
results = _context2.sent;
|
|
329
|
+
flattenedResults = results.flat();
|
|
330
|
+
LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Fetched ").concat(flattenedResults.length, " total product variants"));
|
|
331
|
+
return _context2.abrupt("return", flattenedResults);
|
|
332
|
+
case 11:
|
|
333
|
+
case "end":
|
|
334
|
+
return _context2.stop();
|
|
335
|
+
}
|
|
336
|
+
}, _callee2);
|
|
337
|
+
}));
|
|
338
|
+
return function (_x) {
|
|
339
|
+
return _ref2.apply(this, arguments);
|
|
340
|
+
};
|
|
341
|
+
}(), [handler.productHandler, getOrFetch, variants, widgetId, widgetType]);
|
|
342
|
+
|
|
343
|
+
// Function to handle selectedProduct changes
|
|
344
|
+
var handleSelectedProductChange = useCallback(/*#__PURE__*/function () {
|
|
345
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(newProduct) {
|
|
346
|
+
var _variants;
|
|
347
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
348
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
349
|
+
case 0:
|
|
350
|
+
if (!(!newProduct || productVariants.find(function (p) {
|
|
351
|
+
return p._id === newProduct._id;
|
|
352
|
+
}))) {
|
|
353
|
+
_context3.next = 4;
|
|
177
354
|
break;
|
|
178
|
-
|
|
179
|
-
|
|
355
|
+
}
|
|
356
|
+
LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Selected product ").concat(newProduct._id, " already in current variants, setting as selected"));
|
|
357
|
+
setSelectedProduct(newProduct);
|
|
358
|
+
return _context3.abrupt("return");
|
|
359
|
+
case 4:
|
|
360
|
+
LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Selected product ").concat(newProduct._id, " not in current variants, fetching variants for it"));
|
|
361
|
+
setLoading(true);
|
|
362
|
+
setError(false);
|
|
363
|
+
_context3.prev = 7;
|
|
364
|
+
_context3.next = 10;
|
|
365
|
+
return fetchProducts([newProduct._id]);
|
|
366
|
+
case 10:
|
|
367
|
+
_variants = _context3.sent;
|
|
368
|
+
setProductVariants(_variants);
|
|
369
|
+
LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] New ").concat(_variants.length, " variants to productVariants"));
|
|
370
|
+
setLoading(false);
|
|
371
|
+
LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Setting product ").concat(newProduct._id, " as selected after fetching"));
|
|
372
|
+
setSelectedProduct(newProduct);
|
|
373
|
+
_context3.next = 23;
|
|
374
|
+
break;
|
|
375
|
+
case 18:
|
|
376
|
+
_context3.prev = 18;
|
|
377
|
+
_context3.t0 = _context3["catch"](7);
|
|
378
|
+
LOG.error(new DivaError("[".concat(widgetType, ":").concat(widgetId, "] Error loading product"), {
|
|
379
|
+
cause: _context3.t0
|
|
380
|
+
}));
|
|
381
|
+
setError(true);
|
|
382
|
+
setLoading(false);
|
|
383
|
+
case 23:
|
|
384
|
+
case "end":
|
|
385
|
+
return _context3.stop();
|
|
386
|
+
}
|
|
387
|
+
}, _callee3, null, [[7, 18]]);
|
|
388
|
+
}));
|
|
389
|
+
return function (_x3) {
|
|
390
|
+
return _ref4.apply(this, arguments);
|
|
391
|
+
};
|
|
392
|
+
}(), [selectedProduct, productVariants, fetchProducts, widgetId, widgetType]);
|
|
393
|
+
var _useGlobalSelectedPro = useGlobalSelectedProduct({
|
|
394
|
+
selectedProduct: selectedProduct,
|
|
395
|
+
uniqueWidgetId: widgetId,
|
|
396
|
+
widgetType: widgetType,
|
|
397
|
+
handleSelectedProductChange: handleSelectedProductChange
|
|
398
|
+
}),
|
|
399
|
+
notifyProductChanged = _useGlobalSelectedPro.notifyProductChanged;
|
|
400
|
+
var normalizedProductIds = useMemo(function () {
|
|
401
|
+
if (!productIds) return [];
|
|
402
|
+
return Array.isArray(productIds) ? productIds : [productIds];
|
|
403
|
+
}, [productIds]);
|
|
404
|
+
|
|
405
|
+
// Main effect for loading products when productIds or variants change
|
|
406
|
+
useEffect(function () {
|
|
407
|
+
LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Main effect triggered with normalizedProductIds: ").concat(normalizedProductIds.join(', ')));
|
|
408
|
+
if (!normalizedProductIds.length) {
|
|
409
|
+
LOG.error(new DivaError("[".concat(widgetType, ":").concat(widgetId, "] ProductIds array is required and cannot be empty")));
|
|
410
|
+
setError(true);
|
|
411
|
+
setLoading(false);
|
|
412
|
+
setProductVariants([]);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
setError(false);
|
|
416
|
+
setLoading(true);
|
|
417
|
+
fetchProducts(normalizedProductIds).then(function (variants) {
|
|
418
|
+
LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Successfully loaded ").concat(variants.length, " product variants"));
|
|
419
|
+
setProductVariants(variants);
|
|
420
|
+
setSelectedProduct(variants[0]);
|
|
421
|
+
setLoading(false);
|
|
422
|
+
})["catch"](function (error) {
|
|
423
|
+
LOG.error(new DivaError("[".concat(widgetType, ":").concat(widgetId, "] Error loading products"), {
|
|
424
|
+
cause: error
|
|
425
|
+
}));
|
|
426
|
+
setError(true);
|
|
427
|
+
setLoading(false);
|
|
428
|
+
setProductVariants([]);
|
|
429
|
+
});
|
|
430
|
+
}, [normalizedProductIds]);
|
|
431
|
+
var setSelectedProductId = useCallback(/*#__PURE__*/function () {
|
|
432
|
+
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(productId) {
|
|
433
|
+
var product, _variants2, _product;
|
|
434
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
435
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
436
|
+
case 0:
|
|
437
|
+
LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] setSelectedProductId called with productId: ").concat(productId));
|
|
438
|
+
|
|
439
|
+
// If a product is selected that is not in the productVariants list,
|
|
440
|
+
// fetch the variants for that product and append them to the productVariants list
|
|
441
|
+
product = productVariants.find(function (p) {
|
|
442
|
+
return p._id === productId;
|
|
443
|
+
});
|
|
444
|
+
if (!product) {
|
|
445
|
+
_context4.next = 7;
|
|
180
446
|
break;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
447
|
+
}
|
|
448
|
+
LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Product ").concat(productId, " found in current variants, setting as selected"));
|
|
449
|
+
setSelectedProduct(product);
|
|
450
|
+
notifyProductChanged(product);
|
|
451
|
+
return _context4.abrupt("return");
|
|
452
|
+
case 7:
|
|
453
|
+
LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Product ").concat(productId, " not found in current variants, fetching variants for it"));
|
|
454
|
+
_context4.prev = 8;
|
|
455
|
+
setError(false);
|
|
456
|
+
setLoading(true);
|
|
457
|
+
_context4.next = 13;
|
|
458
|
+
return fetchProducts([productId]);
|
|
459
|
+
case 13:
|
|
460
|
+
_variants2 = _context4.sent;
|
|
461
|
+
setProductVariants(_variants2);
|
|
462
|
+
LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] New ").concat(_variants2.length, " variants to productVariants"));
|
|
463
|
+
_product = _variants2.find(function (p) {
|
|
464
|
+
return p._id === productId;
|
|
465
|
+
});
|
|
466
|
+
if (!_product) {
|
|
467
|
+
_context4.next = 23;
|
|
192
468
|
break;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
469
|
+
}
|
|
470
|
+
LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Setting product ").concat(productId, " as selected after fetching"));
|
|
471
|
+
setSelectedProduct(_product);
|
|
472
|
+
notifyProductChanged(_product);
|
|
473
|
+
_context4.next = 24;
|
|
474
|
+
break;
|
|
475
|
+
case 23:
|
|
476
|
+
throw new DivaError("[".concat(widgetType, ":").concat(widgetId, "] Product ").concat(productId, " not found"));
|
|
477
|
+
case 24:
|
|
478
|
+
_context4.next = 30;
|
|
479
|
+
break;
|
|
480
|
+
case 26:
|
|
481
|
+
_context4.prev = 26;
|
|
482
|
+
_context4.t0 = _context4["catch"](8);
|
|
483
|
+
LOG.error(new DivaError("[".concat(widgetType, ":").concat(widgetId, "] Error loading product"), {
|
|
484
|
+
cause: _context4.t0
|
|
485
|
+
}));
|
|
486
|
+
setError(true);
|
|
487
|
+
case 30:
|
|
488
|
+
_context4.prev = 30;
|
|
489
|
+
setLoading(false);
|
|
490
|
+
return _context4.finish(30);
|
|
491
|
+
case 33:
|
|
492
|
+
case "end":
|
|
493
|
+
return _context4.stop();
|
|
494
|
+
}
|
|
495
|
+
}, _callee4, null, [[8, 26, 30, 33]]);
|
|
496
|
+
}));
|
|
497
|
+
return function (_x4) {
|
|
498
|
+
return _ref5.apply(this, arguments);
|
|
499
|
+
};
|
|
500
|
+
}(), [productVariants, fetchProducts, setSelectedProduct, widgetId, widgetType]);
|
|
501
|
+
function getProductsByDivaNrs(_x5) {
|
|
502
|
+
return _getProductsByDivaNrs.apply(this, arguments);
|
|
503
|
+
}
|
|
504
|
+
function _getProductsByDivaNrs() {
|
|
505
|
+
_getProductsByDivaNrs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(divaNrs) {
|
|
506
|
+
var products;
|
|
507
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
508
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
509
|
+
case 0:
|
|
510
|
+
// Sort divaNrs array to ensure consistent cache keys
|
|
511
|
+
divaNrs.sort();
|
|
512
|
+
_context5.next = 3;
|
|
513
|
+
return getOrFetch('divaNrs' + divaNrs.join(','), function () {
|
|
514
|
+
return handler.productHandler.apiGetProductByQuery([{
|
|
515
|
+
id: 'divaNr',
|
|
516
|
+
op: 'in',
|
|
517
|
+
value: divaNrs.join(',').replaceAll('"', '')
|
|
518
|
+
}], 1000, false);
|
|
519
|
+
});
|
|
520
|
+
case 3:
|
|
521
|
+
products = _context5.sent;
|
|
522
|
+
return _context5.abrupt("return", products);
|
|
523
|
+
case 5:
|
|
524
|
+
case "end":
|
|
525
|
+
return _context5.stop();
|
|
526
|
+
}
|
|
527
|
+
}, _callee5);
|
|
528
|
+
}));
|
|
529
|
+
return _getProductsByDivaNrs.apply(this, arguments);
|
|
530
|
+
}
|
|
531
|
+
function getProductByDivaNrAndVariantId(_x6, _x7) {
|
|
532
|
+
return _getProductByDivaNrAndVariantId.apply(this, arguments);
|
|
533
|
+
}
|
|
534
|
+
function _getProductByDivaNrAndVariantId() {
|
|
535
|
+
_getProductByDivaNrAndVariantId = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(divaNr, variantId) {
|
|
536
|
+
var filter, product;
|
|
537
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
538
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
539
|
+
case 0:
|
|
540
|
+
filter = [{
|
|
541
|
+
id: 'divaNr',
|
|
542
|
+
op: 'eq',
|
|
543
|
+
value: divaNr
|
|
544
|
+
}];
|
|
545
|
+
if (variantId) {
|
|
546
|
+
filter.push({
|
|
547
|
+
id: 'variantId',
|
|
548
|
+
op: 'eq',
|
|
549
|
+
value: parseInt(variantId)
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
_context6.next = 4;
|
|
553
|
+
return getOrFetch('divaNr' + divaNr + 'variantId' + variantId, function () {
|
|
554
|
+
return handler.productHandler.apiGetProductByQuery(filter, 1, false);
|
|
555
|
+
});
|
|
556
|
+
case 4:
|
|
557
|
+
product = _context6.sent;
|
|
558
|
+
return _context6.abrupt("return", product);
|
|
559
|
+
case 6:
|
|
560
|
+
case "end":
|
|
561
|
+
return _context6.stop();
|
|
562
|
+
}
|
|
563
|
+
}, _callee6);
|
|
564
|
+
}));
|
|
565
|
+
return _getProductByDivaNrAndVariantId.apply(this, arguments);
|
|
566
|
+
}
|
|
567
|
+
function setProductCache(key, data) {
|
|
568
|
+
setCache(key, {
|
|
569
|
+
data: data,
|
|
570
|
+
timestamp: Date.now()
|
|
571
|
+
});
|
|
572
|
+
}
|
|
215
573
|
return {
|
|
216
574
|
productVariants: productVariants,
|
|
217
575
|
error: error,
|
|
218
|
-
loading: loading
|
|
576
|
+
loading: loading,
|
|
577
|
+
getProductsByDivaNrs: getProductsByDivaNrs,
|
|
578
|
+
getProductByDivaNrAndVariantId: getProductByDivaNrAndVariantId,
|
|
579
|
+
selectedProduct: selectedProduct,
|
|
580
|
+
setSelectedProductId: setSelectedProductId,
|
|
581
|
+
setProductCache: setProductCache
|
|
219
582
|
};
|
|
220
583
|
}
|
|
221
584
|
|
|
@@ -285,7 +648,8 @@ function useMedia(_ref) {
|
|
|
285
648
|
}
|
|
286
649
|
newMedias = [].concat(_toConsumableArray(newMedias), _toConsumableArray(filteredMedia.map(function (media) {
|
|
287
650
|
return _objectSpread$3(_objectSpread$3({}, media), {}, {
|
|
288
|
-
productIndex: productIndex
|
|
651
|
+
productIndex: productIndex,
|
|
652
|
+
productId: product._id
|
|
289
653
|
});
|
|
290
654
|
})));
|
|
291
655
|
}
|
|
@@ -298,7 +662,8 @@ function useMedia(_ref) {
|
|
|
298
662
|
if (add3DImageAsFallback && product.image && !hasAddedMediaForProduct) {
|
|
299
663
|
newMedias.unshift({
|
|
300
664
|
url: product.image,
|
|
301
|
-
productIndex: productIndex
|
|
665
|
+
productIndex: productIndex,
|
|
666
|
+
productId: product._id
|
|
302
667
|
});
|
|
303
668
|
}
|
|
304
669
|
|
|
@@ -306,7 +671,8 @@ function useMedia(_ref) {
|
|
|
306
671
|
if (add2DImage && product.image2D) {
|
|
307
672
|
newMedias.push({
|
|
308
673
|
url: product.image2D,
|
|
309
|
-
productIndex: productIndex
|
|
674
|
+
productIndex: productIndex,
|
|
675
|
+
productId: product._id
|
|
310
676
|
});
|
|
311
677
|
}
|
|
312
678
|
});
|
|
@@ -342,7 +708,7 @@ function useGallery(_ref) {
|
|
|
342
708
|
add2DImage: add2DImage,
|
|
343
709
|
add3DImageAsFallback: add3DImageAsFallback
|
|
344
710
|
});
|
|
345
|
-
|
|
711
|
+
var userTriggeredRef = useRef(false);
|
|
346
712
|
// Update currentMediaIndex when currentProductIndex changes from outside
|
|
347
713
|
useEffect(function () {
|
|
348
714
|
var _medias$currentMediaI;
|
|
@@ -357,6 +723,9 @@ function useGallery(_ref) {
|
|
|
357
723
|
}
|
|
358
724
|
}
|
|
359
725
|
}, [currentProductIndex]);
|
|
726
|
+
var markUserInteraction = function markUserInteraction() {
|
|
727
|
+
userTriggeredRef.current = true;
|
|
728
|
+
};
|
|
360
729
|
var hasSirvMedia = useMemo(function () {
|
|
361
730
|
var _loop = function _loop(i) {
|
|
362
731
|
if (medias.find(function (m) {
|
|
@@ -379,6 +748,7 @@ function useGallery(_ref) {
|
|
|
379
748
|
}),
|
|
380
749
|
sirvLoaded = _useSirv.sirvLoaded;
|
|
381
750
|
var onSlideChange = function onSlideChange(swiper) {
|
|
751
|
+
if (!userTriggeredRef.current) return;
|
|
382
752
|
var newMediaIndex = swiper.realIndex;
|
|
383
753
|
setCurrentMediaIndex(newMediaIndex);
|
|
384
754
|
|
|
@@ -389,6 +759,7 @@ function useGallery(_ref) {
|
|
|
389
759
|
if (setCurrentProductIndex && media) {
|
|
390
760
|
setCurrentProductIndex(media.productIndex);
|
|
391
761
|
}
|
|
762
|
+
userTriggeredRef.current = false;
|
|
392
763
|
};
|
|
393
764
|
|
|
394
765
|
// Get the current product index based on the current media index
|
|
@@ -404,7 +775,8 @@ function useGallery(_ref) {
|
|
|
404
775
|
setCurrentProductIndex: setCurrentProductIndex,
|
|
405
776
|
setThumbsSwiper: setThumbsSwiper,
|
|
406
777
|
setSwiper: setSwiper,
|
|
407
|
-
onSlideChange: onSlideChange
|
|
778
|
+
onSlideChange: onSlideChange,
|
|
779
|
+
markUserInteraction: markUserInteraction
|
|
408
780
|
};
|
|
409
781
|
}
|
|
410
782
|
|
|
@@ -513,6 +885,7 @@ var MediaItem = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
513
885
|
videoAutolay = _ref.videoAutolay,
|
|
514
886
|
config = _ref.config;
|
|
515
887
|
_ref.isCurrentlyVisible;
|
|
888
|
+
var onClick = _ref.onClick;
|
|
516
889
|
var useSirv = false;
|
|
517
890
|
var _useDivaCore = useDivaCore(),
|
|
518
891
|
baseSirvUrls = _useDivaCore.state.apiConfig.baseSirvUrls;
|
|
@@ -543,7 +916,11 @@ var MediaItem = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
543
916
|
}, media.url);
|
|
544
917
|
return /*#__PURE__*/jsx("img", {
|
|
545
918
|
className: "diva-widget-mediaitem",
|
|
546
|
-
src: url
|
|
919
|
+
src: url,
|
|
920
|
+
onClick: onClick,
|
|
921
|
+
style: {
|
|
922
|
+
cursor: onClick ? 'pointer' : 'default'
|
|
923
|
+
}
|
|
547
924
|
}, url);
|
|
548
925
|
});
|
|
549
926
|
|
|
@@ -686,14 +1063,15 @@ var focusable = '.smv-cursor-zoom-in, .sirv-zoom-wrapper, .sirv-zoom-map-lens ,.
|
|
|
686
1063
|
var noSwiping = 'canvas, model-viewer, .sirv-zoom-map, .zoom-controls, .smv-icon';
|
|
687
1064
|
var Gallery = function Gallery(props) {
|
|
688
1065
|
var _medias$find, _props$config$arIconP;
|
|
689
|
-
var _useGallery = useGallery(props),
|
|
1066
|
+
var _useGallery = useGallery(_objectSpread({}, props)),
|
|
690
1067
|
medias = _useGallery.medias,
|
|
691
1068
|
thumbsSwiper = _useGallery.thumbsSwiper,
|
|
692
1069
|
swiper = _useGallery.swiper,
|
|
693
1070
|
onSlideChange = _useGallery.onSlideChange,
|
|
694
1071
|
setThumbsSwiper = _useGallery.setThumbsSwiper,
|
|
695
1072
|
setSwiper = _useGallery.setSwiper,
|
|
696
|
-
currentIndex = _useGallery.currentIndex
|
|
1073
|
+
currentIndex = _useGallery.currentIndex,
|
|
1074
|
+
markUserInteraction = _useGallery.markUserInteraction;
|
|
697
1075
|
useEffect(function () {
|
|
698
1076
|
if (props.setCurrentMedia) {
|
|
699
1077
|
props.setCurrentMedia(medias[currentIndex]);
|
|
@@ -712,6 +1090,9 @@ var Gallery = function Gallery(props) {
|
|
|
712
1090
|
htmlArElement: htmlArElement === null || htmlArElement === void 0 ? void 0 : htmlArElement.current
|
|
713
1091
|
}), /*#__PURE__*/jsx(Swiper, _objectSpread(_objectSpread({
|
|
714
1092
|
onSwiper: setSwiper,
|
|
1093
|
+
onTouchStart: markUserInteraction,
|
|
1094
|
+
onNavigationNext: markUserInteraction,
|
|
1095
|
+
onNavigationPrev: markUserInteraction,
|
|
715
1096
|
resizeObserver: false,
|
|
716
1097
|
onSlideChange: onSlideChange,
|
|
717
1098
|
focusableElements: focusable,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Gallery/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AASvC,cAAc,SAAS,CAAC;AAKxB,eAAO,MAAM,OAAO,UAAW,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Gallery/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AASvC,cAAc,SAAS,CAAC;AAKxB,eAAO,MAAM,OAAO,UAAW,YAAY,sBAyD1C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Gallery/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,WAAW,aAAc,SAAQ,iBAAiB,EAAE,eAAe;IACvE,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,eAAe,CAAC,EAAE,WAAW,CAAC;IAC9B,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sBAAsB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,eAAe,CAAC,EAAE,CAAC,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACtD;AAED,MAAM,WAAW,qBAAsB,SAAQ,KAAK;IAClD,YAAY,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Gallery/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,WAAW,aAAc,SAAQ,iBAAiB,EAAE,eAAe;IACvE,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,eAAe,CAAC,EAAE,WAAW,CAAC;IAC9B,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sBAAsB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,eAAe,CAAC,EAAE,CAAC,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACtD;AAED,MAAM,WAAW,qBAAsB,SAAQ,KAAK;IAClD,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -11,5 +11,6 @@ export default function useGallery({ products, config: { functionTypes, add2DIma
|
|
|
11
11
|
setThumbsSwiper: import("react").Dispatch<import("react").SetStateAction<SwiperClass | null>>;
|
|
12
12
|
setSwiper: import("react").Dispatch<import("react").SetStateAction<SwiperClass | null>>;
|
|
13
13
|
onSlideChange: (swiper: SwiperClass) => void;
|
|
14
|
+
markUserInteraction: () => void;
|
|
14
15
|
};
|
|
15
16
|
//# sourceMappingURL=useGallery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGallery.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Gallery/useGallery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAI9D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,QAAQ,EACR,MAAM,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,oBAAoB,EAAE,EAC3D,mBAAmB,EACnB,sBAAsB,GACvB,EAAE,YAAY;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useGallery.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Gallery/useGallery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAI9D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,QAAQ,EACR,MAAM,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,oBAAoB,EAAE,EAC3D,mBAAmB,EACnB,sBAAsB,GACvB,EAAE,YAAY;;;;;;;;;;4BAmCkB,WAAW;;EAgC3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/MediaItem/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAe,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAqB,MAAM,OAAO,CAAC;AAE1C,OAAiB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEzD,KAAK,KAAK,GAAG;IACX,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,eAAe,CAAC;IACxB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/MediaItem/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAe,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAqB,MAAM,OAAO,CAAC;AAE1C,OAAiB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEzD,KAAK,KAAK,GAAG;IACX,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,eAAe,CAAC;IACxB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,SAAS,mFAiCpB,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
interface CacheEntry<T> {
|
|
2
|
+
/**
|
|
3
|
+
* The actual data after the request is resolved
|
|
4
|
+
*/
|
|
5
|
+
data: T[] | null;
|
|
6
|
+
/**
|
|
7
|
+
* The promise for the request
|
|
8
|
+
*/
|
|
9
|
+
promise: Promise<T[]> | null;
|
|
10
|
+
/**
|
|
11
|
+
* The error if the request failed
|
|
12
|
+
*/
|
|
13
|
+
error: Error | null;
|
|
14
|
+
/**
|
|
15
|
+
* Timestamp when the entry was last updated
|
|
16
|
+
*/
|
|
17
|
+
timestamp: number;
|
|
18
|
+
}
|
|
19
|
+
interface DivaWidgetCache {
|
|
20
|
+
/**
|
|
21
|
+
* Get data from cache or fetch if not available
|
|
22
|
+
* Implements request deduplication - multiple components requesting the same data
|
|
23
|
+
* will share the same promise
|
|
24
|
+
* @param key - Cache key (product ID)
|
|
25
|
+
* @param fetcher - Function to fetch data
|
|
26
|
+
* @returns Promise that resolves to the data
|
|
27
|
+
*/
|
|
28
|
+
getOrFetch: <T>(key: string, fetcher: () => Promise<T[]>) => Promise<T[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Clear a specific cache entry
|
|
31
|
+
* @param key - Cache key to clear
|
|
32
|
+
*/
|
|
33
|
+
clear: (key: string) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Clear all cache entries
|
|
36
|
+
*/
|
|
37
|
+
clearAll: () => void;
|
|
38
|
+
/**
|
|
39
|
+
* Set a cache entry
|
|
40
|
+
* @param key - Cache key
|
|
41
|
+
* @param data - Data to set
|
|
42
|
+
*/
|
|
43
|
+
setCache: (key: string, data: any) => void;
|
|
44
|
+
}
|
|
45
|
+
interface UseGlobalCacheProps {
|
|
46
|
+
/**
|
|
47
|
+
* Unique widget instance ID, used for events and logging
|
|
48
|
+
*/
|
|
49
|
+
uniqueWidgetId: string;
|
|
50
|
+
/**
|
|
51
|
+
* Widget type, used for events and logging
|
|
52
|
+
*/
|
|
53
|
+
widgetType: string;
|
|
54
|
+
}
|
|
55
|
+
declare global {
|
|
56
|
+
interface Window {
|
|
57
|
+
__divaWidgetCache: {
|
|
58
|
+
cache: Map<string, CacheEntry<any>>;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Global cache for shared data between widgets of a website
|
|
64
|
+
* Simple implementation with request deduplication
|
|
65
|
+
*/
|
|
66
|
+
export declare function useGlobalCache({ uniqueWidgetId, widgetType }: UseGlobalCacheProps): DivaWidgetCache;
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=useGlobalCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGlobalCache.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/useGlobalCache.ts"],"names":[],"mappings":"AAKA,UAAU,UAAU,CAAC,CAAC;IACpB;;OAEG;IACH,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;IACjB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IAC7B;;OAEG;IACH,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,eAAe;IACvB;;;;;;;OAOG;IACH,UAAU,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IAC1E;;;OAGG;IACH,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B;;OAEG;IACH,QAAQ,EAAE,MAAM,IAAI,CAAC;IAErB;;;;OAIG;IACH,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;CAC5C;AAED,UAAU,mBAAmB;IAC3B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAGD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,iBAAiB,EAAE;YACjB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;SACrC,CAAC;KACH;CACF;AASD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAAE,cAAc,EAAE,UAAU,EAAE,EAAE,mBAAmB,GAAG,eAAe,CAkGnG"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ProductData } from '@crystaldesign/diva-core';
|
|
2
|
+
interface UseGlobalSelectedProductProps {
|
|
3
|
+
selectedProduct?: ProductData;
|
|
4
|
+
/**
|
|
5
|
+
* Unique widget instance ID, used for events and logging
|
|
6
|
+
*/
|
|
7
|
+
uniqueWidgetId: string;
|
|
8
|
+
/**
|
|
9
|
+
* Widget type, used for events and logging
|
|
10
|
+
*/
|
|
11
|
+
widgetType: string;
|
|
12
|
+
/**
|
|
13
|
+
* Function to handle selected product changes
|
|
14
|
+
*/
|
|
15
|
+
handleSelectedProductChange: (product: ProductData) => void;
|
|
16
|
+
}
|
|
17
|
+
interface UseGlobalSelectedProductReturn {
|
|
18
|
+
notifyProductChanged: (product: ProductData) => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Hook to get the globally selected product
|
|
22
|
+
*
|
|
23
|
+
* Initially and when the product changes, it gets selected.
|
|
24
|
+
* When ever the selected product is changed, an event is dispatched to notify other widgets, so they can also set the new product as selected.
|
|
25
|
+
* The hook also listens for product selection events from other widgets and updates the selected product accordingly.
|
|
26
|
+
*
|
|
27
|
+
* @param product - The product to select initially
|
|
28
|
+
* @returns The selected product and a function to set the selected product
|
|
29
|
+
*/
|
|
30
|
+
export declare function useGlobalSelectedProduct({ selectedProduct, uniqueWidgetId, widgetType, handleSelectedProductChange, }: UseGlobalSelectedProductProps): UseGlobalSelectedProductReturn;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=useGlobalSelectedProduct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGlobalSelectedProduct.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/useGlobalSelectedProduct.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAIlE,UAAU,6BAA6B;IACrC,eAAe,CAAC,EAAE,WAAW,CAAC;IAC9B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,2BAA2B,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;CAC7D;AAED,UAAU,8BAA8B;IACtC,oBAAoB,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;CACtD;AAWD;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,eAAe,EACf,cAAc,EACd,UAAU,EACV,2BAA2B,GAC5B,EAAE,6BAA6B,GAAG,8BAA8B,CAsDhE"}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { ProductData } from '@crystaldesign/diva-core';
|
|
2
2
|
export interface UseProductDataProps {
|
|
3
|
-
productIds?: string[];
|
|
3
|
+
productIds?: string[] | string;
|
|
4
4
|
variants?: ProductData[];
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Widget type, used for logging
|
|
7
|
+
*/
|
|
8
|
+
widgetType: string;
|
|
6
9
|
}
|
|
7
|
-
export declare function useProductData({ productIds, variants,
|
|
10
|
+
export declare function useProductData({ productIds, variants, widgetType }: UseProductDataProps): {
|
|
8
11
|
productVariants: ProductData[];
|
|
9
12
|
error: boolean;
|
|
10
13
|
loading: boolean;
|
|
14
|
+
getProductsByDivaNrs: (divaNrs: string[]) => Promise<any>;
|
|
15
|
+
getProductByDivaNrAndVariantId: (divaNr: string, variantId?: string) => Promise<any>;
|
|
16
|
+
selectedProduct: ProductData | undefined;
|
|
17
|
+
setSelectedProductId: (productId: string) => Promise<void>;
|
|
18
|
+
setProductCache: (key: string, data: any) => void;
|
|
11
19
|
};
|
|
12
20
|
//# sourceMappingURL=useProductData.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProductData.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/useProductData.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,WAAW,EAA0B,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"useProductData.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/useProductData.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,WAAW,EAA0B,MAAM,0BAA0B,CAAC;AAM1F,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAKD,wBAAgB,cAAc,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,mBAAmB;;;;oCAqJzC,MAAM,EAAE,KAAG,OAAO,CAAC,GAAG,CAAC;6CAoBd,MAAM,cAAc,MAAM,KAAG,OAAO,CAAC,GAAG,CAAC;;sCA9D3E,MAAM;2BAoFI,MAAM,QAAQ,GAAG;EAiBhD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crystaldesign/widget-library",
|
|
3
|
-
"version": "25.
|
|
3
|
+
"version": "25.8.0-beta.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"storybook": "storybook dev -p 6006",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"suiteName": "widget-library",
|
|
37
37
|
"outputDirectory": "./test-reports"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "72f0eae11ba09885de9b2ff2f10054cea54754aa"
|
|
40
40
|
}
|