@bigbinary/neeto-molecules 4.0.45 → 4.0.46

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,5 +1,5 @@
1
1
  import { shallow } from 'zustand/shallow';
2
- import { useEffect, useState, useMemo } from 'react';
2
+ import { useEffect, createElement, useState, useMemo } from 'react';
3
3
  import { isPresent, filterBy, hyphenate, noop } from '@bigbinary/neeto-cist';
4
4
  import { useLocation, useHistory } from 'react-router-dom';
5
5
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
@@ -9,7 +9,7 @@ import useStateWithDependency from '@bigbinary/neeto-commons-frontend/react-util
9
9
  import LeftArrow from '@bigbinary/neeto-icons/LeftArrow';
10
10
  import Button from '@bigbinary/neetoui/Button';
11
11
  import Typography from '@bigbinary/neetoui/Typography';
12
- import { toPairs, isEmpty, mergeDeepLeft, mergeLeft } from 'ramda';
12
+ import { toPairs, mergeDeepLeft, pick, isEmpty, mergeLeft } from 'ramda';
13
13
  import { useTranslation } from 'react-i18next';
14
14
  import Container from './Container.js';
15
15
  import Header from './Header.js';
@@ -28,6 +28,7 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
28
28
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
29
29
  import Checkbox from '@bigbinary/neetoui/Checkbox';
30
30
  import ColorPicker from '@bigbinary/neetoui/ColorPicker';
31
+ import Switch from '@bigbinary/neetoui/Switch';
31
32
  import _objectDestructuringEmpty from '@babel/runtime/helpers/objectDestructuringEmpty';
32
33
  import Spinner from '@bigbinary/neetoui/Spinner';
33
34
  import BrowserPreview from './BrowserPreview.js';
@@ -112,42 +113,42 @@ var inlineEmbedCode$1 = function inlineEmbedCode(_ref3) {
112
113
  embedScriptLink = _ref3.embedScriptLink,
113
114
  extraArgs = _ref3.extraArgs,
114
115
  inlineWrapperStyle = _ref3.inlineWrapperStyle,
115
- iframeStyle = _ref3.iframeStyle;
116
- var elementSelector = customization.elementSelector,
117
- queryParams = customization.queryParams;
116
+ iframeStyle = _ref3.iframeStyle,
117
+ queryParams = _ref3.queryParams;
118
+ var elementSelector = customization.elementSelector;
118
119
  return "\n <!-- ".concat(globalProps.appName, " inline embed code begins -->\n <div style=\"").concat(inlineWrapperStyle, "\" id=\"").concat(elementSelector, "\">\n <!-- ").concat(globalProps.appName, " widget will be added here -->\n </div>\n ").concat(embedBaseScript(embedScriptLink), "\n <script>\n ").concat(camelCasedAppName$1, ".embed({\n type: \"inline\",\n id: \"").concat(id, "\",\n organization: \"").concat(globalProps.organization.subdomain, "\",\n elementSelector: \"#").concat(elementSelector, "\",\n styles: \"").concat(iframeStyle, "\", ").concat(embedQueryParam$1(queryParams)).concat(embedEnv$1()).concat(parseExtraArgs$1(extraArgs), "\n });\n </script>\n <!-- ").concat(globalProps.appName, " inline embed code ends -->");
119
120
  };
120
121
  var floatingPopupEmbedCode$1 = function floatingPopupEmbedCode(_ref4) {
121
122
  var customization = _ref4.customization,
122
123
  id = _ref4.id,
123
124
  embedScriptLink = _ref4.embedScriptLink,
124
- extraArgs = _ref4.extraArgs;
125
+ extraArgs = _ref4.extraArgs,
126
+ queryParams = _ref4.queryParams;
125
127
  var btnTextColor = customization.btnTextColor,
126
128
  showIcon = customization.showIcon,
127
129
  btnText = customization.btnText,
128
130
  btnPosition = customization.btnPosition,
129
131
  btnColor = customization.btnColor,
130
- icon = customization.icon,
131
- queryParams = customization.queryParams;
132
+ icon = customization.icon;
132
133
  return "\n <!-- ".concat(globalProps.appName, " floating-popup embed code begins -->\n ").concat(embedBaseScript(embedScriptLink), "\n <script>\n ").concat(camelCasedAppName$1, ".embed({\n type: \"floatingPopup\",\n id: \"").concat(id, "\",\n organization: \"").concat(globalProps.organization.subdomain, "\",\n styles: {\n btnTextColor: \"").concat(btnTextColor, "\",\n btnPosition: \"").concat(btnPosition, "\",\n btnColor: \"").concat(btnColor, "\",\n btnText: \"").concat(btnText, "\", ").concat(icon ? "\n".concat(TAB_STRING).concat(TAB_STRING, "showIcon: ").concat(showIcon, ",") : "", "\n },").concat(embedQueryParam$1(queryParams)).concat(embedEnv$1()).concat(parseExtraArgs$1(extraArgs), "\n });\n </script>\n <!-- ").concat(globalProps.appName, " floating-popup embed code ends -->");
133
134
  };
134
135
  var elementPopupEmbedCode$1 = function elementPopupEmbedCode(_ref5) {
135
136
  var customization = _ref5.customization,
136
137
  id = _ref5.id,
137
138
  embedScriptLink = _ref5.embedScriptLink,
138
- extraArgs = _ref5.extraArgs;
139
- var elementSelector = customization.elementSelector,
140
- queryParams = customization.queryParams;
139
+ extraArgs = _ref5.extraArgs,
140
+ queryParams = _ref5.queryParams;
141
+ var elementSelector = customization.elementSelector;
141
142
  return "\n <!-- This is a demo button, you can use any element on your website instead. -->\n <!-- <button id=\"".concat(elementSelector, "\">Click to open popup</button> -->\n\n <!-- ").concat(globalProps.appName, " element-click embed code begins -->\n ").concat(embedBaseScript(embedScriptLink), "\n <script>\n ").concat(camelCasedAppName$1, ".embed({\n type: \"elementClick\",\n id: \"").concat(id, "\",\n organization: \"").concat(globalProps.organization.subdomain, "\",\n elementSelector: \"#").concat(elementSelector, "\",").concat(embedQueryParam$1(queryParams)).concat(embedEnv$1()).concat(parseExtraArgs$1(extraArgs), "\n });\n </script>\n <!-- ").concat(globalProps.appName, " element-click embed code ends -->");
142
143
  };
143
144
  var iframeEmbedCode$1 = function iframeEmbedCode(_ref6) {
144
145
  var id = _ref6.id,
145
- customization = _ref6.customization;
146
+ customization = _ref6.customization,
147
+ queryParams = _ref6.queryParams;
146
148
  var height = customization.height,
147
149
  width = customization.width,
148
150
  iframeTitle = customization.iframeTitle,
149
- iframeUrl = customization.iframeUrl,
150
- queryParams = customization.queryParams;
151
+ iframeUrl = customization.iframeUrl;
151
152
  var iframeSrc = buildIframeURL$1({
152
153
  id: id,
153
154
  iframeUrl: iframeUrl,
@@ -199,48 +200,48 @@ var inlineEmbedCode = function inlineEmbedCode(_ref3) {
199
200
  embedScriptLink = _ref3.embedScriptLink,
200
201
  extraArgs = _ref3.extraArgs,
201
202
  inlineWrapperStyle = _ref3.inlineWrapperStyle,
202
- iframeStyle = _ref3.iframeStyle;
203
- var elementSelector = customization.elementSelector,
204
- queryParams = customization.queryParams;
203
+ iframeStyle = _ref3.iframeStyle,
204
+ queryParams = _ref3.queryParams;
205
+ var elementSelector = customization.elementSelector;
205
206
  return "\n import { useEffect } from \"react\";\n\n const App = () => {\n const ".concat(embedFunctionName, " = () => {\n ").concat(embedScript(embedScriptLink), "\n embedScript.onload = () => {\n window.").concat(camelCasedAppName, ".embed({\n type: \"inline\",\n id: \"").concat(id, "\",\n organization: \"").concat(globalProps.organization.subdomain, "\",\n elementSelector: \"#").concat(elementSelector, "\",\n styles: \"").concat(iframeStyle, "\",").concat(embedQueryParam(queryParams)).concat(embedEnv()).concat(parseExtraArgs(extraArgs), "\n });\n };\n\n document.body.appendChild(embedScript);\n ").concat(cleanupFunction, "\n };\n\n useEffect(() => ").concat(embedFunctionName, "(), []);\n\n return (\n <div\n id=\"inline-embed-container\"\n style={{ ").concat(parseInlineStyle(inlineWrapperStyle), " }}\n />\n );\n };");
206
207
  };
207
208
  var floatingPopupEmbedCode = function floatingPopupEmbedCode(_ref4) {
208
209
  var customization = _ref4.customization,
209
210
  id = _ref4.id,
210
211
  embedScriptLink = _ref4.embedScriptLink,
211
- extraArgs = _ref4.extraArgs;
212
+ extraArgs = _ref4.extraArgs,
213
+ queryParams = _ref4.queryParams;
212
214
  var btnTextColor = customization.btnTextColor,
213
215
  showIcon = customization.showIcon,
214
216
  btnText = customization.btnText,
215
217
  btnPosition = customization.btnPosition,
216
218
  btnColor = customization.btnColor,
217
- icon = customization.icon,
218
- queryParams = customization.queryParams;
219
+ icon = customization.icon;
219
220
  return "\n import { useEffect } from \"react\";\n\n const App = () => {\n const ".concat(embedFunctionName, " = () => {\n ").concat(embedScript(embedScriptLink), "\n embedScript.onload = () => {\n window.").concat(camelCasedAppName, ".embed({\n type: \"floatingPopup\",\n id: \"").concat(id, "\",\n organization: \"").concat(globalProps.organization.subdomain, "\",\n styles: {\n btnTextColor: \"").concat(btnTextColor, "\",\n btnPosition: \"").concat(btnPosition, "\",\n btnColor: \"").concat(btnColor, "\",\n btnText: \"").concat(btnText, "\",").concat(icon ? "\n".concat(TAB_STRING).concat(TAB_STRING).concat(TAB_STRING, "showIcon: ").concat(showIcon, ",") : "", "\n },").concat(embedQueryParam(queryParams)).concat(embedEnv()).concat(parseExtraArgs(extraArgs), "\n });\n };\n\n document.body.appendChild(embedScript);\n ").concat(cleanupFunction, "\n };\n\n useEffect(() => ").concat(embedFunctionName, "(), []);\n\n return <div />;\n };");
220
221
  };
221
222
  var elementPopupEmbedCode = function elementPopupEmbedCode(_ref5) {
222
223
  var customization = _ref5.customization,
223
224
  id = _ref5.id,
224
225
  embedScriptLink = _ref5.embedScriptLink,
225
- extraArgs = _ref5.extraArgs;
226
- var elementSelector = customization.elementSelector,
227
- queryParams = customization.queryParams;
226
+ extraArgs = _ref5.extraArgs,
227
+ queryParams = _ref5.queryParams;
228
+ var elementSelector = customization.elementSelector;
228
229
  return "\n import { useEffect } from \"react\";\n\n const App = () => {\n const ".concat(embedFunctionName, " = () => {\n ").concat(embedScript(embedScriptLink), "\n embedScript.onload = () => {\n window.").concat(camelCasedAppName, ".embed({\n type: \"elementClick\",\n id: \"").concat(id, "\",\n organization: \"").concat(globalProps.organization.subdomain, "\",\n elementSelector: \"#").concat(elementSelector, "\",").concat(embedQueryParam(queryParams)).concat(embedEnv()).concat(parseExtraArgs(extraArgs), "\n });\n };\n\n document.body.appendChild(embedScript);\n ").concat(cleanupFunction, "\n };\n\n useEffect(() => ").concat(embedFunctionName, "(), []);\n\n return <button id=\"").concat(elementSelector, "\">Click to open popup</button>;\n };");
229
230
  };
230
231
  var iframeEmbedCode = function iframeEmbedCode(_ref6) {
231
232
  var customization = _ref6.customization,
232
- id = _ref6.id;
233
+ id = _ref6.id,
234
+ queryParams = _ref6.queryParams;
233
235
  var height = customization.height,
234
236
  width = customization.width,
235
237
  iframeTitle = customization.iframeTitle,
236
- iframeUrl = customization.iframeUrl,
237
- queryParams = customization.queryParams;
238
+ iframeUrl = customization.iframeUrl;
238
239
  var iframeSrc = buildIframeURL$1({
239
240
  id: id,
240
241
  iframeUrl: iframeUrl,
241
242
  queryParams: queryParams
242
243
  });
243
- return "\n const App = () => {\n return (\n <>\n {/* ".concat(globalProps.appName, " iframe embed code begins */}\n <iframe\n allowFullScreen\n height=\"").concat(height, "\"\n width=\"").concat(width, "\"\n frameBorder=\"0\"\n title=\"").concat(iframeTitle, "\"\n src=\"").concat(iframeSrc, "\"\n ></iframe>\n {/* ").concat(globalProps.appName, " iframe embed code ends */}\n </>\n );\n };\n ");
244
+ return "\n const App = () => {\n return (\n <>\n {/* ".concat(globalProps.appName, " iframe embed code begins */}\n <iframe\n allowFullScreen\n height=\"").concat(height, "\"\n width=\"").concat(width, "\"\n frameBorder=\"0\"\n title=\"").concat(iframeTitle, "\"\n src=\"").concat(iframeSrc, "\"\n ></iframe>\n {/* ").concat(globalProps.appName, " iframe embed code ends */}\n </>\n );\n };\n");
244
245
  };
245
246
  var reactCodeGenerators = {
246
247
  inline: inlineEmbedCode,
@@ -250,12 +251,30 @@ var reactCodeGenerators = {
250
251
  };
251
252
 
252
253
  var _excluded = ["selectedLanguage", "type"];
254
+ function ownKeys$4(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; }
255
+ function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
256
+ var buildQueryParams = function buildQueryParams() {
257
+ var customization = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
258
+ var existingQueryParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
259
+ var activeKeys = Object.keys(SWITCH_OPTIONS).filter(function (key) {
260
+ return customization[key];
261
+ });
262
+ var activeOptions = pick(activeKeys, customization);
263
+ var mergedQueryParams = _objectSpread$4(_objectSpread$4({}, existingQueryParams), activeOptions);
264
+ if (isEmpty(mergedQueryParams)) return "";
265
+ return JSON.stringify(mergedQueryParams, null, 2).replace(/\n/g, " ").replace(/\s\s+/g, " ");
266
+ };
253
267
  var generateCode = function generateCode(options) {
254
- var _reactCodeGenerators$, _htmlCodeGenerators$t;
268
+ var _embeddedCodeOptions$, _reactCodeGenerators$, _htmlCodeGenerators$t;
255
269
  var selectedLanguage = options.selectedLanguage,
256
270
  type = options.type,
257
271
  embeddedCodeOptions = _objectWithoutProperties(options, _excluded);
258
- return selectedLanguage === "react" ? (_reactCodeGenerators$ = reactCodeGenerators[type]) === null || _reactCodeGenerators$ === void 0 ? void 0 : _reactCodeGenerators$.call(reactCodeGenerators, embeddedCodeOptions) : (_htmlCodeGenerators$t = htmlCodeGenerators[type]) === null || _htmlCodeGenerators$t === void 0 ? void 0 : _htmlCodeGenerators$t.call(htmlCodeGenerators, embeddedCodeOptions);
272
+ var queryParams = ((_embeddedCodeOptions$ = embeddedCodeOptions.customization) === null || _embeddedCodeOptions$ === void 0 ? void 0 : _embeddedCodeOptions$.queryParams) || {};
273
+ var customization = embeddedCodeOptions.customization || {};
274
+ var codeOptions = _objectSpread$4(_objectSpread$4({}, embeddedCodeOptions), {}, {
275
+ queryParams: buildQueryParams(customization, queryParams)
276
+ });
277
+ return selectedLanguage === "react" ? (_reactCodeGenerators$ = reactCodeGenerators[type]) === null || _reactCodeGenerators$ === void 0 ? void 0 : _reactCodeGenerators$.call(reactCodeGenerators, codeOptions) : (_htmlCodeGenerators$t = htmlCodeGenerators[type]) === null || _htmlCodeGenerators$t === void 0 ? void 0 : _htmlCodeGenerators$t.call(htmlCodeGenerators, codeOptions);
259
278
  };
260
279
  var buildDefaultCustomization = function buildDefaultCustomization(defaultCustomizations) {
261
280
  return mergeDeepLeft(defaultCustomizations, DEFAULT_CUSTOMIZATION);
@@ -266,15 +285,12 @@ var buildQueryParamsFromInputFields = function buildQueryParamsFromInputFields(i
266
285
  value = _ref.value;
267
286
  return name && value;
268
287
  });
269
- var queryParams = filteredInputFields.reduce(function (queryParams, _ref2) {
288
+ return filteredInputFields.reduce(function (queryParams, _ref2) {
270
289
  var name = _ref2.name,
271
290
  value = _ref2.value;
272
291
  queryParams[name] = value;
273
292
  return queryParams;
274
293
  }, {});
275
- if (isEmpty(queryParams)) return "";
276
- var queryParamJsonString = JSON.stringify(queryParams, null, 2);
277
- return queryParamJsonString.replace(/\n/g, " ").replace(/\s\s+/g, " ");
278
294
  };
279
295
  var toCamelCasedString = function toCamelCasedString(string) {
280
296
  return string === null || string === void 0 ? void 0 : string.replace(/[_-]+(\w)/g, function (_, nextChar) {
@@ -526,9 +542,47 @@ var FloatingPopup$1 = function FloatingPopup(_ref) {
526
542
  });
527
543
  };
528
544
 
545
+ var SwitchOptions = function SwitchOptions(_ref) {
546
+ var _ref$customization = _ref.customization,
547
+ customization = _ref$customization === void 0 ? {} : _ref$customization,
548
+ updateCustomization = _ref.updateCustomization;
549
+ var visibleOptions = Object.keys(SWITCH_OPTIONS).filter(function (key) {
550
+ return key in customization;
551
+ }).map(function (key) {
552
+ return [key, customization[key]];
553
+ });
554
+ if (isEmpty(visibleOptions)) return null;
555
+ return /*#__PURE__*/jsx("div", {
556
+ className: "flex flex-col gap-4",
557
+ children: visibleOptions.map(function (_ref2) {
558
+ var _ref3 = _slicedToArray(_ref2, 2),
559
+ key = _ref3[0],
560
+ value = _ref3[1];
561
+ var helpText = SWITCH_OPTIONS[key].helpText;
562
+ var labelProps = helpText ? {
563
+ helpIconProps: {
564
+ tooltipProps: {
565
+ content: helpText
566
+ }
567
+ }
568
+ } : undefined;
569
+ return /*#__PURE__*/createElement(Switch, {
570
+ labelProps: labelProps,
571
+ checked: value,
572
+ key: key,
573
+ label: SWITCH_OPTIONS[key].label,
574
+ onChange: function onChange(e) {
575
+ return updateCustomization(_defineProperty({}, key, e.target.checked));
576
+ }
577
+ });
578
+ })
579
+ });
580
+ };
581
+
529
582
  var Iframe$1 = function Iframe(_ref) {
530
583
  var updateCustomization = _ref.updateCustomization,
531
- otherCustomizations = _ref.otherCustomizations;
584
+ otherCustomizations = _ref.otherCustomizations,
585
+ customization = _ref.customization;
532
586
  var _useProductEmbedStore = useProductEmbedStore(function (store) {
533
587
  return {
534
588
  isQueryParamsEnabled: store["isQueryParamsEnabled"]
@@ -542,7 +596,10 @@ var Iframe$1 = function Iframe(_ref) {
542
596
  });
543
597
  }, []);
544
598
  return /*#__PURE__*/jsxs(Fragment, {
545
- children: [otherCustomizations(), isQueryParamsEnabled && /*#__PURE__*/jsx(DynamicQueryParams, {
599
+ children: [otherCustomizations(), /*#__PURE__*/jsx(SwitchOptions, {
600
+ customization: customization,
601
+ updateCustomization: updateCustomization
602
+ }), isQueryParamsEnabled && /*#__PURE__*/jsx(DynamicQueryParams, {
546
603
  updateCustomization: updateCustomization
547
604
  })]
548
605
  });
@@ -586,6 +643,9 @@ var Inline$1 = function Inline(_ref) {
586
643
  return handleInputChange(e, "elementSelector");
587
644
  }
588
645
  })]
646
+ }), /*#__PURE__*/jsx(SwitchOptions, {
647
+ customization: customization,
648
+ updateCustomization: updateCustomization
589
649
  }), otherCustomizations(), isQueryParamsEnabled && /*#__PURE__*/jsx(DynamicQueryParams, {
590
650
  updateCustomization: updateCustomization
591
651
  })]
@@ -1138,6 +1198,21 @@ var SUPPORTED_LANGUAGES = [{
1138
1198
  }];
1139
1199
  var SCRIPT_ID = "embed-script";
1140
1200
  var TAB_STRING = " ";
1201
+ var SWITCH_OPTIONS = {
1202
+ dynamicHeight: {
1203
+ label: t("neetoMolecules.productEmbed.dynamicHeight"),
1204
+ helpText: t("neetoMolecules.productEmbed.dynamicHeightHelpText")
1205
+ },
1206
+ hideTitle: {
1207
+ label: t("neetoMolecules.productEmbed.hideTitle")
1208
+ },
1209
+ alignContentLeft: {
1210
+ label: t("neetoMolecules.productEmbed.alignContentLeft")
1211
+ },
1212
+ transparentBackground: {
1213
+ label: t("neetoMolecules.productEmbed.transparentBackground")
1214
+ }
1215
+ };
1141
1216
 
1142
1217
  var Code = function Code(_ref) {
1143
1218
  var id = _ref.id,