@bigbinary/neeto-molecules 3.16.27 → 3.16.28

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.
@@ -1,10 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ var shallow = require('zustand/shallow');
4
+ var React = require('react');
3
5
  var neetoCist = require('@bigbinary/neeto-cist');
4
6
  var reactRouterDom = require('react-router-dom');
5
7
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
6
8
  var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
7
- var React = require('react');
8
9
  var classnames = require('classnames');
9
10
  var LeftArrow = require('@bigbinary/neeto-icons/LeftArrow');
10
11
  var Button = require('@bigbinary/neetoui/Button');
@@ -23,6 +24,8 @@ var Delete = require('@bigbinary/neeto-icons/Delete');
23
24
  var Plus = require('@bigbinary/neeto-icons/Plus');
24
25
  var Label = require('@bigbinary/neetoui/Label');
25
26
  var HelpPopover = require('./HelpPopover.js');
27
+ var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
28
+ var zustand = require('zustand');
26
29
  var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
27
30
  var jsxRuntime = require('react/jsx-runtime');
28
31
  var Checkbox = require('@bigbinary/neetoui/Checkbox');
@@ -31,7 +34,6 @@ var _objectDestructuringEmpty = require('@babel/runtime/helpers/objectDestructur
31
34
  var Spinner = require('@bigbinary/neetoui/Spinner');
32
35
  var BrowserPreview = require('./BrowserPreview.js');
33
36
  var injectCss = require('./inject-css-vQvjPR2x.js');
34
- var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
35
37
  require('./index-JY2zVpnv.js');
36
38
  require('./_commonjsHelpers-BJu3ubxk.js');
37
39
  require('./Breadcrumbs.js');
@@ -67,6 +69,24 @@ var INITIAL_QUERY_PARAM = {
67
69
  value: ""
68
70
  };
69
71
 
72
+ /** @type {import("neetocommons/react-utils").ZustandStoreHook} */
73
+ var useProductEmbedStore = zustand.create(reactUtils.withImmutableActions(function (set) {
74
+ return {
75
+ isQueryParamsEnabled: false,
76
+ queryParams: [INITIAL_QUERY_PARAM],
77
+ queryParamsProps: {
78
+ helpPopoverProps: {},
79
+ label: ""
80
+ },
81
+ setProductEmbedState: set,
82
+ setQueryParams: function setQueryParams(queryParams) {
83
+ return set({
84
+ queryParams: queryParams
85
+ });
86
+ }
87
+ };
88
+ }));
89
+
70
90
  var camelCasedAppName$1 = globalProps.appName.replace(/^neeto/i, "neeto");
71
91
  var embedBaseScript = function embedBaseScript(embedScriptLink) {
72
92
  return "<script>window.".concat(camelCasedAppName$1, " = window.").concat(camelCasedAppName$1, " || { embed: function(){(").concat(camelCasedAppName$1, ".q=").concat(camelCasedAppName$1, ".q||[]).push(arguments)} };</script>\n <script async\n src=\"").concat(embedScriptLink, "\">\n </script>");
@@ -239,14 +259,19 @@ var toCamelCasedString = function toCamelCasedString(string) {
239
259
  function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
240
260
  function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
241
261
  var DynamicQueryParams = function DynamicQueryParams(_ref) {
242
- var updateCustomization = _ref.updateCustomization,
243
- queryParamsProps = _ref.queryParamsProps;
262
+ var updateCustomization = _ref.updateCustomization;
244
263
  var _useTranslation = reactI18next.useTranslation(),
245
264
  t = _useTranslation.t;
246
- var _useState = React.useState([INITIAL_QUERY_PARAM]),
247
- _useState2 = _slicedToArray(_useState, 2),
248
- queryParams = _useState2[0],
249
- setQueryParams = _useState2[1];
265
+ var _useProductEmbedStore = useProductEmbedStore(function (store) {
266
+ return {
267
+ queryParamsProps: store["queryParamsProps"],
268
+ queryParams: store["queryParams"],
269
+ setQueryParams: store["setQueryParams"]
270
+ };
271
+ }, shallow.shallow),
272
+ queryParamsProps = _useProductEmbedStore.queryParamsProps,
273
+ queryParams = _useProductEmbedStore.queryParams,
274
+ setQueryParams = _useProductEmbedStore.setQueryParams;
250
275
  var handleAddQueryParam = function handleAddQueryParam() {
251
276
  setQueryParams([].concat(_toConsumableArray(queryParams), [INITIAL_QUERY_PARAM]));
252
277
  };
@@ -322,12 +347,16 @@ var DynamicQueryParams = function DynamicQueryParams(_ref) {
322
347
  var ElementPopup$1 = function ElementPopup(_ref) {
323
348
  var customization = _ref.customization,
324
349
  updateCustomization = _ref.updateCustomization,
325
- isQueryParamsEnabled = _ref.isQueryParamsEnabled,
326
- queryParamsProps = _ref.queryParamsProps,
327
350
  otherCustomizations = _ref.otherCustomizations;
328
351
  var elementSelector = customization.elementSelector;
329
352
  var _useTranslation = reactI18next.useTranslation(),
330
353
  t = _useTranslation.t;
354
+ var _useProductEmbedStore = useProductEmbedStore(function (store) {
355
+ return {
356
+ isQueryParamsEnabled: store["isQueryParamsEnabled"]
357
+ };
358
+ }, shallow.shallow),
359
+ isQueryParamsEnabled = _useProductEmbedStore.isQueryParamsEnabled;
331
360
  React.useEffect(function () {
332
361
  if (isQueryParamsEnabled) return;
333
362
  updateCustomization({
@@ -351,7 +380,6 @@ var ElementPopup$1 = function ElementPopup(_ref) {
351
380
  });
352
381
  }
353
382
  }), otherCustomizations(), isQueryParamsEnabled && /*#__PURE__*/jsxRuntime.jsx(DynamicQueryParams, {
354
- queryParamsProps: queryParamsProps,
355
383
  updateCustomization: updateCustomization
356
384
  })]
357
385
  });
@@ -360,11 +388,15 @@ var ElementPopup$1 = function ElementPopup(_ref) {
360
388
  var FloatingPopup$1 = function FloatingPopup(_ref) {
361
389
  var customization = _ref.customization,
362
390
  updateCustomization = _ref.updateCustomization,
363
- isQueryParamsEnabled = _ref.isQueryParamsEnabled,
364
- queryParamsProps = _ref.queryParamsProps,
365
391
  otherCustomizations = _ref.otherCustomizations;
366
392
  var _useTranslation = reactI18next.useTranslation(),
367
393
  t = _useTranslation.t;
394
+ var _useProductEmbedStore = useProductEmbedStore(function (store) {
395
+ return {
396
+ isQueryParamsEnabled: store["isQueryParamsEnabled"]
397
+ };
398
+ }, shallow.shallow),
399
+ isQueryParamsEnabled = _useProductEmbedStore.isQueryParamsEnabled;
368
400
  var btnTextColor = customization.btnTextColor,
369
401
  showIcon = customization.showIcon,
370
402
  btnText = customization.btnText,
@@ -448,7 +480,6 @@ var FloatingPopup$1 = function FloatingPopup(_ref) {
448
480
  });
449
481
  }
450
482
  }), otherCustomizations(), isQueryParamsEnabled && /*#__PURE__*/jsxRuntime.jsx(DynamicQueryParams, {
451
- queryParamsProps: queryParamsProps,
452
483
  updateCustomization: updateCustomization
453
484
  })]
454
485
  });
@@ -457,14 +488,18 @@ var FloatingPopup$1 = function FloatingPopup(_ref) {
457
488
  var Inline$1 = function Inline(_ref) {
458
489
  var customization = _ref.customization,
459
490
  updateCustomization = _ref.updateCustomization,
460
- isQueryParamsEnabled = _ref.isQueryParamsEnabled,
461
- queryParamsProps = _ref.queryParamsProps,
462
491
  otherCustomizations = _ref.otherCustomizations;
492
+ var _useTranslation = reactI18next.useTranslation(),
493
+ t = _useTranslation.t;
494
+ var _useProductEmbedStore = useProductEmbedStore(function (store) {
495
+ return {
496
+ isQueryParamsEnabled: store["isQueryParamsEnabled"]
497
+ };
498
+ }, shallow.shallow),
499
+ isQueryParamsEnabled = _useProductEmbedStore.isQueryParamsEnabled;
463
500
  var height = customization.height,
464
501
  width = customization.width,
465
502
  elementSelector = customization.elementSelector;
466
- var _useTranslation = reactI18next.useTranslation(),
467
- t = _useTranslation.t;
468
503
  var handleInputChange = function handleInputChange(_ref2, attribute) {
469
504
  var value = _ref2.target.value;
470
505
  return updateCustomization(_defineProperty({}, attribute, value));
@@ -525,7 +560,6 @@ var Inline$1 = function Inline(_ref) {
525
560
  }
526
561
  })]
527
562
  }), otherCustomizations(), isQueryParamsEnabled && /*#__PURE__*/jsxRuntime.jsx(DynamicQueryParams, {
528
- queryParamsProps: queryParamsProps,
529
563
  updateCustomization: updateCustomization
530
564
  })]
531
565
  });
@@ -1253,18 +1287,25 @@ var ElementPopupPlaceholderImage = function ElementPopupPlaceholderImage(_ref2)
1253
1287
  };
1254
1288
 
1255
1289
  var ElementPopup = function ElementPopup(_ref) {
1256
- var iframeURL = _ref.iframeURL,
1257
- customization = _ref.customization;
1290
+ var iframeURL = _ref.iframeURL;
1258
1291
  var _useTranslation = reactI18next.useTranslation(),
1259
1292
  t = _useTranslation.t;
1260
- var elementSelector = customization.elementSelector;
1293
+
1294
+ /**
1295
+ * Currently embed() function doesn't have an unembed handler.
1296
+ * When iframe link changes, we don't have an option to reinitiate it.
1297
+ * So we forcefully recreate the element with `key` and call embed() again
1298
+ */
1299
+ var elementSelectorId = React.useMemo(function () {
1300
+ return "popup-button-".concat(Math.random().toString().substring(2, 10));
1301
+ }, [iframeURL]);
1261
1302
  React.useEffect(function () {
1262
- var element = document.getElementById(elementSelector);
1303
+ var element = document.getElementById(elementSelectorId);
1263
1304
  if (element) {
1264
1305
  var _window$globalProps$a;
1265
1306
  (_window$globalProps$a = window[globalProps.appName.replace(/^neeto/i, "neeto")]) === null || _window$globalProps$a === void 0 || _window$globalProps$a.embed(element, iframeURL);
1266
1307
  }
1267
- }, []);
1308
+ }, [iframeURL]);
1268
1309
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
1269
1310
  className: "relative h-full w-full overflow-hidden",
1270
1311
  children: [/*#__PURE__*/jsxRuntime.jsx(ElementPopupPlaceholderImage, {
@@ -1273,9 +1314,9 @@ var ElementPopup = function ElementPopup(_ref) {
1273
1314
  className: "absolute left-[48.5294117647%] top-[39.0804597701%]",
1274
1315
  "data-cy": "preview-element-popup-button",
1275
1316
  "data-testid": "preview-element-popup-button",
1276
- id: elementSelector,
1317
+ id: elementSelectorId,
1277
1318
  label: t("neetoMolecules.productEmbed.elementPopup.label")
1278
- })]
1319
+ }, elementSelectorId)]
1279
1320
  });
1280
1321
  };
1281
1322
 
@@ -1288,13 +1329,24 @@ var FloatingPopup = function FloatingPopup(_ref) {
1288
1329
  btnPosition = customization.btnPosition,
1289
1330
  btnColor = customization.btnColor,
1290
1331
  icon = customization.icon;
1332
+
1333
+ /**
1334
+ * Currently embed() function doesn't have an unembed handler.
1335
+ * When iframe link changes, we don't have an option to reinitiate it.
1336
+ * So we forcefully recreate the element with `key` and call embed() again
1337
+ */
1338
+ var elementSelectorId = React.useMemo(function () {
1339
+ return "popup-button-".concat(Math.random().toString().substring(2, 10));
1340
+ }, [iframeURL]);
1291
1341
  React.useEffect(function () {
1292
- var _window$globalProps$a;
1293
- var btn = document.getElementById("embedBtn");
1294
- (_window$globalProps$a = window[globalProps.appName.replace(/^neeto/i, "neeto")]) === null || _window$globalProps$a === void 0 || _window$globalProps$a.embed(btn, iframeURL);
1295
- }, []);
1342
+ var element = document.getElementById(elementSelectorId);
1343
+ if (element) {
1344
+ var _window$globalProps$a;
1345
+ (_window$globalProps$a = window[globalProps.appName.replace(/^neeto/i, "neeto")]) === null || _window$globalProps$a === void 0 || _window$globalProps$a.embed(element, iframeURL);
1346
+ }
1347
+ }, [iframeURL]);
1296
1348
  React.useEffect(function () {
1297
- var btn = document.getElementById("embedBtn");
1349
+ var btn = document.getElementById(elementSelectorId);
1298
1350
  btn.style.backgroundColor = btnColor;
1299
1351
  btn.style.color = btnTextColor;
1300
1352
  }, [btnColor, btnTextColor]);
@@ -1306,13 +1358,13 @@ var FloatingPopup = function FloatingPopup(_ref) {
1306
1358
  "data-cy": "popup-preview-button",
1307
1359
  icon: icon && showIcon ? icon : null,
1308
1360
  iconPosition: "left",
1309
- id: "embedBtn",
1361
+ id: elementSelectorId,
1310
1362
  label: btnText,
1311
1363
  className: classnames("absolute bottom-0 m-4", {
1312
1364
  "left-0": btnPosition === "bottomLeft",
1313
1365
  "right-0": btnPosition === "bottomRight"
1314
1366
  })
1315
- })]
1367
+ }, elementSelectorId)]
1316
1368
  });
1317
1369
  };
1318
1370
 
@@ -1329,6 +1381,14 @@ var Inline = function Inline(_ref) {
1329
1381
  });
1330
1382
  };
1331
1383
 
1384
+ var buildIframeURL = function buildIframeURL(iframeURL, queryParams) {
1385
+ var url = new URL(iframeURL);
1386
+ queryParams.forEach(function (param) {
1387
+ url.searchParams.append(param.name, param.value);
1388
+ });
1389
+ return url.toString();
1390
+ };
1391
+
1332
1392
  var Preview = function Preview(_ref) {
1333
1393
  var isScriptLoading = _ref.isScriptLoading,
1334
1394
  selectedEmbed = _ref.selectedEmbed,
@@ -1336,8 +1396,14 @@ var Preview = function Preview(_ref) {
1336
1396
  customization = _ref.customization,
1337
1397
  _ref$customPreviewIfr = _ref.customPreviewIframeUrl,
1338
1398
  customPreviewIframeUrl = _ref$customPreviewIfr === void 0 ? "" : _ref$customPreviewIfr;
1399
+ var _useProductEmbedStore = useProductEmbedStore(function (store) {
1400
+ return {
1401
+ queryParams: store["queryParams"]
1402
+ };
1403
+ }, shallow.shallow),
1404
+ queryParams = _useProductEmbedStore.queryParams;
1339
1405
  var preview = _defineProperty(_defineProperty(_defineProperty({}, EMBED_OPTIONS.INLINE, Inline), EMBED_OPTIONS.FLOATING_POPUP, FloatingPopup), EMBED_OPTIONS.ELEMENT_POPUP, ElementPopup);
1340
- var iframeURL = customPreviewIframeUrl || "".concat(location.origin, "/embed/").concat(id);
1406
+ var iframeURL = buildIframeURL(customPreviewIframeUrl || "".concat(location.origin, "/embed/").concat(id), queryParams);
1341
1407
  var Component = preview[selectedEmbed];
1342
1408
  if (isScriptLoading) {
1343
1409
  return /*#__PURE__*/jsxRuntime.jsx("div", {
@@ -1365,8 +1431,6 @@ var EmbedRenderer = function EmbedRenderer(_ref) {
1365
1431
  customEmbedScriptPath = _ref.customEmbedScriptPath,
1366
1432
  customPreviewIframeUrl = _ref.customPreviewIframeUrl,
1367
1433
  id = _ref.id,
1368
- queryParamsProps = _ref.queryParamsProps,
1369
- isQueryParamsEnabled = _ref.isQueryParamsEnabled,
1370
1434
  options = _ref.options,
1371
1435
  extraArgs = _ref.extraArgs,
1372
1436
  otherCustomizations = _ref.otherCustomizations,
@@ -1446,9 +1510,7 @@ var EmbedRenderer = function EmbedRenderer(_ref) {
1446
1510
  supportedLanguages: supportedLanguages
1447
1511
  }), /*#__PURE__*/jsxRuntime.jsx(CustomizationComponent, {
1448
1512
  customization: customization,
1449
- isQueryParamsEnabled: isQueryParamsEnabled,
1450
1513
  otherCustomizations: otherCustomizations,
1451
- queryParamsProps: queryParamsProps,
1452
1514
  updateCustomization: updateCustomization
1453
1515
  })]
1454
1516
  })
@@ -1568,6 +1630,18 @@ var ProductEmbed = function ProductEmbed(_ref) {
1568
1630
  search = _useLocation.search;
1569
1631
  var queryParams = new URLSearchParams(search);
1570
1632
  var selectedEmbed = toCamelCasedString(queryParams.get("type"));
1633
+ var _useProductEmbedStore = useProductEmbedStore(function (store) {
1634
+ return {
1635
+ setProductEmbedState: store["setProductEmbedState"]
1636
+ };
1637
+ }, shallow.shallow),
1638
+ setProductEmbedState = _useProductEmbedStore.setProductEmbedState;
1639
+ React.useEffect(function () {
1640
+ setProductEmbedState({
1641
+ isQueryParamsEnabled: isQueryParamsEnabled,
1642
+ queryParamsProps: queryParamsProps
1643
+ });
1644
+ }, []);
1571
1645
  return selectedEmbed ? /*#__PURE__*/jsxRuntime.jsx(EmbedRenderer, {
1572
1646
  className: className,
1573
1647
  customEmbedScriptPath: customEmbedScriptPath,
@@ -1575,7 +1649,6 @@ var ProductEmbed = function ProductEmbed(_ref) {
1575
1649
  extraArgs: extraArgs,
1576
1650
  id: id,
1577
1651
  inlineWrapperStyle: inlineWrapperStyle,
1578
- isQueryParamsEnabled: isQueryParamsEnabled,
1579
1652
  options: options,
1580
1653
  otherCustomizations: otherCustomizations,
1581
1654
  queryParamsProps: queryParamsProps,