@bigbinary/neeto-molecules 3.16.26 → 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,8 +1,9 @@
1
+ import { shallow } from 'zustand/shallow';
2
+ import { useEffect, useState, useMemo } from 'react';
1
3
  import { isPresent, filterBy, hyphenate, noop } from '@bigbinary/neeto-cist';
2
4
  import { useLocation, useHistory } from 'react-router-dom';
3
5
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
6
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
- import { useState, useEffect } from 'react';
6
7
  import classnames from 'classnames';
7
8
  import LeftArrow from '@bigbinary/neeto-icons/LeftArrow';
8
9
  import Button from '@bigbinary/neetoui/Button';
@@ -21,6 +22,8 @@ import Delete from '@bigbinary/neeto-icons/Delete';
21
22
  import Plus from '@bigbinary/neeto-icons/Plus';
22
23
  import Label from '@bigbinary/neetoui/Label';
23
24
  import HelpPopover from './HelpPopover.js';
25
+ import { withImmutableActions, handleMetaClick } from '@bigbinary/neeto-commons-frontend/react-utils';
26
+ import { create } from 'zustand';
24
27
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
25
28
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
26
29
  import Checkbox from '@bigbinary/neetoui/Checkbox';
@@ -29,7 +32,6 @@ import _objectDestructuringEmpty from '@babel/runtime/helpers/objectDestructurin
29
32
  import Spinner from '@bigbinary/neetoui/Spinner';
30
33
  import BrowserPreview from './BrowserPreview.js';
31
34
  import { n } from './inject-css-DmrvuTKK.js';
32
- import { handleMetaClick } from '@bigbinary/neeto-commons-frontend/react-utils';
33
35
  import './index-DAYCJu79.js';
34
36
  import './_commonjsHelpers-BFTU3MAI.js';
35
37
  import './Breadcrumbs.js';
@@ -65,6 +67,24 @@ var INITIAL_QUERY_PARAM = {
65
67
  value: ""
66
68
  };
67
69
 
70
+ /** @type {import("neetocommons/react-utils").ZustandStoreHook} */
71
+ var useProductEmbedStore = create(withImmutableActions(function (set) {
72
+ return {
73
+ isQueryParamsEnabled: false,
74
+ queryParams: [INITIAL_QUERY_PARAM],
75
+ queryParamsProps: {
76
+ helpPopoverProps: {},
77
+ label: ""
78
+ },
79
+ setProductEmbedState: set,
80
+ setQueryParams: function setQueryParams(queryParams) {
81
+ return set({
82
+ queryParams: queryParams
83
+ });
84
+ }
85
+ };
86
+ }));
87
+
68
88
  var camelCasedAppName$1 = globalProps.appName.replace(/^neeto/i, "neeto");
69
89
  var embedBaseScript = function embedBaseScript(embedScriptLink) {
70
90
  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>");
@@ -237,14 +257,19 @@ var toCamelCasedString = function toCamelCasedString(string) {
237
257
  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; }
238
258
  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; }
239
259
  var DynamicQueryParams = function DynamicQueryParams(_ref) {
240
- var updateCustomization = _ref.updateCustomization,
241
- queryParamsProps = _ref.queryParamsProps;
260
+ var updateCustomization = _ref.updateCustomization;
242
261
  var _useTranslation = useTranslation(),
243
262
  t = _useTranslation.t;
244
- var _useState = useState([INITIAL_QUERY_PARAM]),
245
- _useState2 = _slicedToArray(_useState, 2),
246
- queryParams = _useState2[0],
247
- setQueryParams = _useState2[1];
263
+ var _useProductEmbedStore = useProductEmbedStore(function (store) {
264
+ return {
265
+ queryParamsProps: store["queryParamsProps"],
266
+ queryParams: store["queryParams"],
267
+ setQueryParams: store["setQueryParams"]
268
+ };
269
+ }, shallow),
270
+ queryParamsProps = _useProductEmbedStore.queryParamsProps,
271
+ queryParams = _useProductEmbedStore.queryParams,
272
+ setQueryParams = _useProductEmbedStore.setQueryParams;
248
273
  var handleAddQueryParam = function handleAddQueryParam() {
249
274
  setQueryParams([].concat(_toConsumableArray(queryParams), [INITIAL_QUERY_PARAM]));
250
275
  };
@@ -320,12 +345,16 @@ var DynamicQueryParams = function DynamicQueryParams(_ref) {
320
345
  var ElementPopup$1 = function ElementPopup(_ref) {
321
346
  var customization = _ref.customization,
322
347
  updateCustomization = _ref.updateCustomization,
323
- isQueryParamsEnabled = _ref.isQueryParamsEnabled,
324
- queryParamsProps = _ref.queryParamsProps,
325
348
  otherCustomizations = _ref.otherCustomizations;
326
349
  var elementSelector = customization.elementSelector;
327
350
  var _useTranslation = useTranslation(),
328
351
  t = _useTranslation.t;
352
+ var _useProductEmbedStore = useProductEmbedStore(function (store) {
353
+ return {
354
+ isQueryParamsEnabled: store["isQueryParamsEnabled"]
355
+ };
356
+ }, shallow),
357
+ isQueryParamsEnabled = _useProductEmbedStore.isQueryParamsEnabled;
329
358
  useEffect(function () {
330
359
  if (isQueryParamsEnabled) return;
331
360
  updateCustomization({
@@ -349,7 +378,6 @@ var ElementPopup$1 = function ElementPopup(_ref) {
349
378
  });
350
379
  }
351
380
  }), otherCustomizations(), isQueryParamsEnabled && /*#__PURE__*/jsx(DynamicQueryParams, {
352
- queryParamsProps: queryParamsProps,
353
381
  updateCustomization: updateCustomization
354
382
  })]
355
383
  });
@@ -358,11 +386,15 @@ var ElementPopup$1 = function ElementPopup(_ref) {
358
386
  var FloatingPopup$1 = function FloatingPopup(_ref) {
359
387
  var customization = _ref.customization,
360
388
  updateCustomization = _ref.updateCustomization,
361
- isQueryParamsEnabled = _ref.isQueryParamsEnabled,
362
- queryParamsProps = _ref.queryParamsProps,
363
389
  otherCustomizations = _ref.otherCustomizations;
364
390
  var _useTranslation = useTranslation(),
365
391
  t = _useTranslation.t;
392
+ var _useProductEmbedStore = useProductEmbedStore(function (store) {
393
+ return {
394
+ isQueryParamsEnabled: store["isQueryParamsEnabled"]
395
+ };
396
+ }, shallow),
397
+ isQueryParamsEnabled = _useProductEmbedStore.isQueryParamsEnabled;
366
398
  var btnTextColor = customization.btnTextColor,
367
399
  showIcon = customization.showIcon,
368
400
  btnText = customization.btnText,
@@ -446,7 +478,6 @@ var FloatingPopup$1 = function FloatingPopup(_ref) {
446
478
  });
447
479
  }
448
480
  }), otherCustomizations(), isQueryParamsEnabled && /*#__PURE__*/jsx(DynamicQueryParams, {
449
- queryParamsProps: queryParamsProps,
450
481
  updateCustomization: updateCustomization
451
482
  })]
452
483
  });
@@ -455,14 +486,18 @@ var FloatingPopup$1 = function FloatingPopup(_ref) {
455
486
  var Inline$1 = function Inline(_ref) {
456
487
  var customization = _ref.customization,
457
488
  updateCustomization = _ref.updateCustomization,
458
- isQueryParamsEnabled = _ref.isQueryParamsEnabled,
459
- queryParamsProps = _ref.queryParamsProps,
460
489
  otherCustomizations = _ref.otherCustomizations;
490
+ var _useTranslation = useTranslation(),
491
+ t = _useTranslation.t;
492
+ var _useProductEmbedStore = useProductEmbedStore(function (store) {
493
+ return {
494
+ isQueryParamsEnabled: store["isQueryParamsEnabled"]
495
+ };
496
+ }, shallow),
497
+ isQueryParamsEnabled = _useProductEmbedStore.isQueryParamsEnabled;
461
498
  var height = customization.height,
462
499
  width = customization.width,
463
500
  elementSelector = customization.elementSelector;
464
- var _useTranslation = useTranslation(),
465
- t = _useTranslation.t;
466
501
  var handleInputChange = function handleInputChange(_ref2, attribute) {
467
502
  var value = _ref2.target.value;
468
503
  return updateCustomization(_defineProperty({}, attribute, value));
@@ -523,7 +558,6 @@ var Inline$1 = function Inline(_ref) {
523
558
  }
524
559
  })]
525
560
  }), otherCustomizations(), isQueryParamsEnabled && /*#__PURE__*/jsx(DynamicQueryParams, {
526
- queryParamsProps: queryParamsProps,
527
561
  updateCustomization: updateCustomization
528
562
  })]
529
563
  });
@@ -1251,18 +1285,25 @@ var ElementPopupPlaceholderImage = function ElementPopupPlaceholderImage(_ref2)
1251
1285
  };
1252
1286
 
1253
1287
  var ElementPopup = function ElementPopup(_ref) {
1254
- var iframeURL = _ref.iframeURL,
1255
- customization = _ref.customization;
1288
+ var iframeURL = _ref.iframeURL;
1256
1289
  var _useTranslation = useTranslation(),
1257
1290
  t = _useTranslation.t;
1258
- var elementSelector = customization.elementSelector;
1291
+
1292
+ /**
1293
+ * Currently embed() function doesn't have an unembed handler.
1294
+ * When iframe link changes, we don't have an option to reinitiate it.
1295
+ * So we forcefully recreate the element with `key` and call embed() again
1296
+ */
1297
+ var elementSelectorId = useMemo(function () {
1298
+ return "popup-button-".concat(Math.random().toString().substring(2, 10));
1299
+ }, [iframeURL]);
1259
1300
  useEffect(function () {
1260
- var element = document.getElementById(elementSelector);
1301
+ var element = document.getElementById(elementSelectorId);
1261
1302
  if (element) {
1262
1303
  var _window$globalProps$a;
1263
1304
  (_window$globalProps$a = window[globalProps.appName.replace(/^neeto/i, "neeto")]) === null || _window$globalProps$a === void 0 || _window$globalProps$a.embed(element, iframeURL);
1264
1305
  }
1265
- }, []);
1306
+ }, [iframeURL]);
1266
1307
  return /*#__PURE__*/jsxs("div", {
1267
1308
  className: "relative h-full w-full overflow-hidden",
1268
1309
  children: [/*#__PURE__*/jsx(ElementPopupPlaceholderImage, {
@@ -1271,9 +1312,9 @@ var ElementPopup = function ElementPopup(_ref) {
1271
1312
  className: "absolute left-[48.5294117647%] top-[39.0804597701%]",
1272
1313
  "data-cy": "preview-element-popup-button",
1273
1314
  "data-testid": "preview-element-popup-button",
1274
- id: elementSelector,
1315
+ id: elementSelectorId,
1275
1316
  label: t("neetoMolecules.productEmbed.elementPopup.label")
1276
- })]
1317
+ }, elementSelectorId)]
1277
1318
  });
1278
1319
  };
1279
1320
 
@@ -1286,13 +1327,24 @@ var FloatingPopup = function FloatingPopup(_ref) {
1286
1327
  btnPosition = customization.btnPosition,
1287
1328
  btnColor = customization.btnColor,
1288
1329
  icon = customization.icon;
1330
+
1331
+ /**
1332
+ * Currently embed() function doesn't have an unembed handler.
1333
+ * When iframe link changes, we don't have an option to reinitiate it.
1334
+ * So we forcefully recreate the element with `key` and call embed() again
1335
+ */
1336
+ var elementSelectorId = useMemo(function () {
1337
+ return "popup-button-".concat(Math.random().toString().substring(2, 10));
1338
+ }, [iframeURL]);
1289
1339
  useEffect(function () {
1290
- var _window$globalProps$a;
1291
- var btn = document.getElementById("embedBtn");
1292
- (_window$globalProps$a = window[globalProps.appName.replace(/^neeto/i, "neeto")]) === null || _window$globalProps$a === void 0 || _window$globalProps$a.embed(btn, iframeURL);
1293
- }, []);
1340
+ var element = document.getElementById(elementSelectorId);
1341
+ if (element) {
1342
+ var _window$globalProps$a;
1343
+ (_window$globalProps$a = window[globalProps.appName.replace(/^neeto/i, "neeto")]) === null || _window$globalProps$a === void 0 || _window$globalProps$a.embed(element, iframeURL);
1344
+ }
1345
+ }, [iframeURL]);
1294
1346
  useEffect(function () {
1295
- var btn = document.getElementById("embedBtn");
1347
+ var btn = document.getElementById(elementSelectorId);
1296
1348
  btn.style.backgroundColor = btnColor;
1297
1349
  btn.style.color = btnTextColor;
1298
1350
  }, [btnColor, btnTextColor]);
@@ -1304,13 +1356,13 @@ var FloatingPopup = function FloatingPopup(_ref) {
1304
1356
  "data-cy": "popup-preview-button",
1305
1357
  icon: icon && showIcon ? icon : null,
1306
1358
  iconPosition: "left",
1307
- id: "embedBtn",
1359
+ id: elementSelectorId,
1308
1360
  label: btnText,
1309
1361
  className: classnames("absolute bottom-0 m-4", {
1310
1362
  "left-0": btnPosition === "bottomLeft",
1311
1363
  "right-0": btnPosition === "bottomRight"
1312
1364
  })
1313
- })]
1365
+ }, elementSelectorId)]
1314
1366
  });
1315
1367
  };
1316
1368
 
@@ -1327,6 +1379,14 @@ var Inline = function Inline(_ref) {
1327
1379
  });
1328
1380
  };
1329
1381
 
1382
+ var buildIframeURL = function buildIframeURL(iframeURL, queryParams) {
1383
+ var url = new URL(iframeURL);
1384
+ queryParams.forEach(function (param) {
1385
+ url.searchParams.append(param.name, param.value);
1386
+ });
1387
+ return url.toString();
1388
+ };
1389
+
1330
1390
  var Preview = function Preview(_ref) {
1331
1391
  var isScriptLoading = _ref.isScriptLoading,
1332
1392
  selectedEmbed = _ref.selectedEmbed,
@@ -1334,8 +1394,14 @@ var Preview = function Preview(_ref) {
1334
1394
  customization = _ref.customization,
1335
1395
  _ref$customPreviewIfr = _ref.customPreviewIframeUrl,
1336
1396
  customPreviewIframeUrl = _ref$customPreviewIfr === void 0 ? "" : _ref$customPreviewIfr;
1397
+ var _useProductEmbedStore = useProductEmbedStore(function (store) {
1398
+ return {
1399
+ queryParams: store["queryParams"]
1400
+ };
1401
+ }, shallow),
1402
+ queryParams = _useProductEmbedStore.queryParams;
1337
1403
  var preview = _defineProperty(_defineProperty(_defineProperty({}, EMBED_OPTIONS.INLINE, Inline), EMBED_OPTIONS.FLOATING_POPUP, FloatingPopup), EMBED_OPTIONS.ELEMENT_POPUP, ElementPopup);
1338
- var iframeURL = customPreviewIframeUrl || "".concat(location.origin, "/embed/").concat(id);
1404
+ var iframeURL = buildIframeURL(customPreviewIframeUrl || "".concat(location.origin, "/embed/").concat(id), queryParams);
1339
1405
  var Component = preview[selectedEmbed];
1340
1406
  if (isScriptLoading) {
1341
1407
  return /*#__PURE__*/jsx("div", {
@@ -1363,8 +1429,6 @@ var EmbedRenderer = function EmbedRenderer(_ref) {
1363
1429
  customEmbedScriptPath = _ref.customEmbedScriptPath,
1364
1430
  customPreviewIframeUrl = _ref.customPreviewIframeUrl,
1365
1431
  id = _ref.id,
1366
- queryParamsProps = _ref.queryParamsProps,
1367
- isQueryParamsEnabled = _ref.isQueryParamsEnabled,
1368
1432
  options = _ref.options,
1369
1433
  extraArgs = _ref.extraArgs,
1370
1434
  otherCustomizations = _ref.otherCustomizations,
@@ -1444,9 +1508,7 @@ var EmbedRenderer = function EmbedRenderer(_ref) {
1444
1508
  supportedLanguages: supportedLanguages
1445
1509
  }), /*#__PURE__*/jsx(CustomizationComponent, {
1446
1510
  customization: customization,
1447
- isQueryParamsEnabled: isQueryParamsEnabled,
1448
1511
  otherCustomizations: otherCustomizations,
1449
- queryParamsProps: queryParamsProps,
1450
1512
  updateCustomization: updateCustomization
1451
1513
  })]
1452
1514
  })
@@ -1566,6 +1628,18 @@ var ProductEmbed = function ProductEmbed(_ref) {
1566
1628
  search = _useLocation.search;
1567
1629
  var queryParams = new URLSearchParams(search);
1568
1630
  var selectedEmbed = toCamelCasedString(queryParams.get("type"));
1631
+ var _useProductEmbedStore = useProductEmbedStore(function (store) {
1632
+ return {
1633
+ setProductEmbedState: store["setProductEmbedState"]
1634
+ };
1635
+ }, shallow),
1636
+ setProductEmbedState = _useProductEmbedStore.setProductEmbedState;
1637
+ useEffect(function () {
1638
+ setProductEmbedState({
1639
+ isQueryParamsEnabled: isQueryParamsEnabled,
1640
+ queryParamsProps: queryParamsProps
1641
+ });
1642
+ }, []);
1569
1643
  return selectedEmbed ? /*#__PURE__*/jsx(EmbedRenderer, {
1570
1644
  className: className,
1571
1645
  customEmbedScriptPath: customEmbedScriptPath,
@@ -1573,7 +1647,6 @@ var ProductEmbed = function ProductEmbed(_ref) {
1573
1647
  extraArgs: extraArgs,
1574
1648
  id: id,
1575
1649
  inlineWrapperStyle: inlineWrapperStyle,
1576
- isQueryParamsEnabled: isQueryParamsEnabled,
1577
1650
  options: options,
1578
1651
  otherCustomizations: otherCustomizations,
1579
1652
  queryParamsProps: queryParamsProps,