@bigbinary/neeto-molecules 4.0.44 → 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.
@@ -30,6 +30,7 @@ var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProp
30
30
  var jsxRuntime = require('react/jsx-runtime');
31
31
  var Checkbox = require('@bigbinary/neetoui/Checkbox');
32
32
  var ColorPicker = require('@bigbinary/neetoui/ColorPicker');
33
+ var Switch = require('@bigbinary/neetoui/Switch');
33
34
  var _objectDestructuringEmpty = require('@babel/runtime/helpers/objectDestructuringEmpty');
34
35
  var Spinner = require('@bigbinary/neetoui/Spinner');
35
36
  var BrowserPreview = require('./BrowserPreview.js');
@@ -114,42 +115,42 @@ var inlineEmbedCode$1 = function inlineEmbedCode(_ref3) {
114
115
  embedScriptLink = _ref3.embedScriptLink,
115
116
  extraArgs = _ref3.extraArgs,
116
117
  inlineWrapperStyle = _ref3.inlineWrapperStyle,
117
- iframeStyle = _ref3.iframeStyle;
118
- var elementSelector = customization.elementSelector,
119
- queryParams = customization.queryParams;
118
+ iframeStyle = _ref3.iframeStyle,
119
+ queryParams = _ref3.queryParams;
120
+ var elementSelector = customization.elementSelector;
120
121
  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 -->");
121
122
  };
122
123
  var floatingPopupEmbedCode$1 = function floatingPopupEmbedCode(_ref4) {
123
124
  var customization = _ref4.customization,
124
125
  id = _ref4.id,
125
126
  embedScriptLink = _ref4.embedScriptLink,
126
- extraArgs = _ref4.extraArgs;
127
+ extraArgs = _ref4.extraArgs,
128
+ queryParams = _ref4.queryParams;
127
129
  var btnTextColor = customization.btnTextColor,
128
130
  showIcon = customization.showIcon,
129
131
  btnText = customization.btnText,
130
132
  btnPosition = customization.btnPosition,
131
133
  btnColor = customization.btnColor,
132
- icon = customization.icon,
133
- queryParams = customization.queryParams;
134
+ icon = customization.icon;
134
135
  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 -->");
135
136
  };
136
137
  var elementPopupEmbedCode$1 = function elementPopupEmbedCode(_ref5) {
137
138
  var customization = _ref5.customization,
138
139
  id = _ref5.id,
139
140
  embedScriptLink = _ref5.embedScriptLink,
140
- extraArgs = _ref5.extraArgs;
141
- var elementSelector = customization.elementSelector,
142
- queryParams = customization.queryParams;
141
+ extraArgs = _ref5.extraArgs,
142
+ queryParams = _ref5.queryParams;
143
+ var elementSelector = customization.elementSelector;
143
144
  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 -->");
144
145
  };
145
146
  var iframeEmbedCode$1 = function iframeEmbedCode(_ref6) {
146
147
  var id = _ref6.id,
147
- customization = _ref6.customization;
148
+ customization = _ref6.customization,
149
+ queryParams = _ref6.queryParams;
148
150
  var height = customization.height,
149
151
  width = customization.width,
150
152
  iframeTitle = customization.iframeTitle,
151
- iframeUrl = customization.iframeUrl,
152
- queryParams = customization.queryParams;
153
+ iframeUrl = customization.iframeUrl;
153
154
  var iframeSrc = buildIframeURL$1({
154
155
  id: id,
155
156
  iframeUrl: iframeUrl,
@@ -201,48 +202,48 @@ var inlineEmbedCode = function inlineEmbedCode(_ref3) {
201
202
  embedScriptLink = _ref3.embedScriptLink,
202
203
  extraArgs = _ref3.extraArgs,
203
204
  inlineWrapperStyle = _ref3.inlineWrapperStyle,
204
- iframeStyle = _ref3.iframeStyle;
205
- var elementSelector = customization.elementSelector,
206
- queryParams = customization.queryParams;
205
+ iframeStyle = _ref3.iframeStyle,
206
+ queryParams = _ref3.queryParams;
207
+ var elementSelector = customization.elementSelector;
207
208
  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 };");
208
209
  };
209
210
  var floatingPopupEmbedCode = function floatingPopupEmbedCode(_ref4) {
210
211
  var customization = _ref4.customization,
211
212
  id = _ref4.id,
212
213
  embedScriptLink = _ref4.embedScriptLink,
213
- extraArgs = _ref4.extraArgs;
214
+ extraArgs = _ref4.extraArgs,
215
+ queryParams = _ref4.queryParams;
214
216
  var btnTextColor = customization.btnTextColor,
215
217
  showIcon = customization.showIcon,
216
218
  btnText = customization.btnText,
217
219
  btnPosition = customization.btnPosition,
218
220
  btnColor = customization.btnColor,
219
- icon = customization.icon,
220
- queryParams = customization.queryParams;
221
+ icon = customization.icon;
221
222
  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 };");
222
223
  };
223
224
  var elementPopupEmbedCode = function elementPopupEmbedCode(_ref5) {
224
225
  var customization = _ref5.customization,
225
226
  id = _ref5.id,
226
227
  embedScriptLink = _ref5.embedScriptLink,
227
- extraArgs = _ref5.extraArgs;
228
- var elementSelector = customization.elementSelector,
229
- queryParams = customization.queryParams;
228
+ extraArgs = _ref5.extraArgs,
229
+ queryParams = _ref5.queryParams;
230
+ var elementSelector = customization.elementSelector;
230
231
  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 };");
231
232
  };
232
233
  var iframeEmbedCode = function iframeEmbedCode(_ref6) {
233
234
  var customization = _ref6.customization,
234
- id = _ref6.id;
235
+ id = _ref6.id,
236
+ queryParams = _ref6.queryParams;
235
237
  var height = customization.height,
236
238
  width = customization.width,
237
239
  iframeTitle = customization.iframeTitle,
238
- iframeUrl = customization.iframeUrl,
239
- queryParams = customization.queryParams;
240
+ iframeUrl = customization.iframeUrl;
240
241
  var iframeSrc = buildIframeURL$1({
241
242
  id: id,
242
243
  iframeUrl: iframeUrl,
243
244
  queryParams: queryParams
244
245
  });
245
- 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 ");
246
+ 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");
246
247
  };
247
248
  var reactCodeGenerators = {
248
249
  inline: inlineEmbedCode,
@@ -252,12 +253,30 @@ var reactCodeGenerators = {
252
253
  };
253
254
 
254
255
  var _excluded = ["selectedLanguage", "type"];
256
+ 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; }
257
+ 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; }
258
+ var buildQueryParams = function buildQueryParams() {
259
+ var customization = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
260
+ var existingQueryParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
261
+ var activeKeys = Object.keys(SWITCH_OPTIONS).filter(function (key) {
262
+ return customization[key];
263
+ });
264
+ var activeOptions = ramda.pick(activeKeys, customization);
265
+ var mergedQueryParams = _objectSpread$4(_objectSpread$4({}, existingQueryParams), activeOptions);
266
+ if (ramda.isEmpty(mergedQueryParams)) return "";
267
+ return JSON.stringify(mergedQueryParams, null, 2).replace(/\n/g, " ").replace(/\s\s+/g, " ");
268
+ };
255
269
  var generateCode = function generateCode(options) {
256
- var _reactCodeGenerators$, _htmlCodeGenerators$t;
270
+ var _embeddedCodeOptions$, _reactCodeGenerators$, _htmlCodeGenerators$t;
257
271
  var selectedLanguage = options.selectedLanguage,
258
272
  type = options.type,
259
273
  embeddedCodeOptions = _objectWithoutProperties(options, _excluded);
260
- 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);
274
+ var queryParams = ((_embeddedCodeOptions$ = embeddedCodeOptions.customization) === null || _embeddedCodeOptions$ === void 0 ? void 0 : _embeddedCodeOptions$.queryParams) || {};
275
+ var customization = embeddedCodeOptions.customization || {};
276
+ var codeOptions = _objectSpread$4(_objectSpread$4({}, embeddedCodeOptions), {}, {
277
+ queryParams: buildQueryParams(customization, queryParams)
278
+ });
279
+ 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);
261
280
  };
262
281
  var buildDefaultCustomization = function buildDefaultCustomization(defaultCustomizations) {
263
282
  return ramda.mergeDeepLeft(defaultCustomizations, DEFAULT_CUSTOMIZATION);
@@ -268,15 +287,12 @@ var buildQueryParamsFromInputFields = function buildQueryParamsFromInputFields(i
268
287
  value = _ref.value;
269
288
  return name && value;
270
289
  });
271
- var queryParams = filteredInputFields.reduce(function (queryParams, _ref2) {
290
+ return filteredInputFields.reduce(function (queryParams, _ref2) {
272
291
  var name = _ref2.name,
273
292
  value = _ref2.value;
274
293
  queryParams[name] = value;
275
294
  return queryParams;
276
295
  }, {});
277
- if (ramda.isEmpty(queryParams)) return "";
278
- var queryParamJsonString = JSON.stringify(queryParams, null, 2);
279
- return queryParamJsonString.replace(/\n/g, " ").replace(/\s\s+/g, " ");
280
296
  };
281
297
  var toCamelCasedString = function toCamelCasedString(string) {
282
298
  return string === null || string === void 0 ? void 0 : string.replace(/[_-]+(\w)/g, function (_, nextChar) {
@@ -528,9 +544,47 @@ var FloatingPopup$1 = function FloatingPopup(_ref) {
528
544
  });
529
545
  };
530
546
 
547
+ var SwitchOptions = function SwitchOptions(_ref) {
548
+ var _ref$customization = _ref.customization,
549
+ customization = _ref$customization === void 0 ? {} : _ref$customization,
550
+ updateCustomization = _ref.updateCustomization;
551
+ var visibleOptions = Object.keys(SWITCH_OPTIONS).filter(function (key) {
552
+ return key in customization;
553
+ }).map(function (key) {
554
+ return [key, customization[key]];
555
+ });
556
+ if (ramda.isEmpty(visibleOptions)) return null;
557
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
558
+ className: "flex flex-col gap-4",
559
+ children: visibleOptions.map(function (_ref2) {
560
+ var _ref3 = _slicedToArray(_ref2, 2),
561
+ key = _ref3[0],
562
+ value = _ref3[1];
563
+ var helpText = SWITCH_OPTIONS[key].helpText;
564
+ var labelProps = helpText ? {
565
+ helpIconProps: {
566
+ tooltipProps: {
567
+ content: helpText
568
+ }
569
+ }
570
+ } : undefined;
571
+ return /*#__PURE__*/React.createElement(Switch, {
572
+ labelProps: labelProps,
573
+ checked: value,
574
+ key: key,
575
+ label: SWITCH_OPTIONS[key].label,
576
+ onChange: function onChange(e) {
577
+ return updateCustomization(_defineProperty({}, key, e.target.checked));
578
+ }
579
+ });
580
+ })
581
+ });
582
+ };
583
+
531
584
  var Iframe$1 = function Iframe(_ref) {
532
585
  var updateCustomization = _ref.updateCustomization,
533
- otherCustomizations = _ref.otherCustomizations;
586
+ otherCustomizations = _ref.otherCustomizations,
587
+ customization = _ref.customization;
534
588
  var _useProductEmbedStore = useProductEmbedStore(function (store) {
535
589
  return {
536
590
  isQueryParamsEnabled: store["isQueryParamsEnabled"]
@@ -544,7 +598,10 @@ var Iframe$1 = function Iframe(_ref) {
544
598
  });
545
599
  }, []);
546
600
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
547
- children: [otherCustomizations(), isQueryParamsEnabled && /*#__PURE__*/jsxRuntime.jsx(DynamicQueryParams, {
601
+ children: [otherCustomizations(), /*#__PURE__*/jsxRuntime.jsx(SwitchOptions, {
602
+ customization: customization,
603
+ updateCustomization: updateCustomization
604
+ }), isQueryParamsEnabled && /*#__PURE__*/jsxRuntime.jsx(DynamicQueryParams, {
548
605
  updateCustomization: updateCustomization
549
606
  })]
550
607
  });
@@ -588,6 +645,9 @@ var Inline$1 = function Inline(_ref) {
588
645
  return handleInputChange(e, "elementSelector");
589
646
  }
590
647
  })]
648
+ }), /*#__PURE__*/jsxRuntime.jsx(SwitchOptions, {
649
+ customization: customization,
650
+ updateCustomization: updateCustomization
591
651
  }), otherCustomizations(), isQueryParamsEnabled && /*#__PURE__*/jsxRuntime.jsx(DynamicQueryParams, {
592
652
  updateCustomization: updateCustomization
593
653
  })]
@@ -1140,6 +1200,21 @@ var SUPPORTED_LANGUAGES = [{
1140
1200
  }];
1141
1201
  var SCRIPT_ID = "embed-script";
1142
1202
  var TAB_STRING = " ";
1203
+ var SWITCH_OPTIONS = {
1204
+ dynamicHeight: {
1205
+ label: i18next.t("neetoMolecules.productEmbed.dynamicHeight"),
1206
+ helpText: i18next.t("neetoMolecules.productEmbed.dynamicHeightHelpText")
1207
+ },
1208
+ hideTitle: {
1209
+ label: i18next.t("neetoMolecules.productEmbed.hideTitle")
1210
+ },
1211
+ alignContentLeft: {
1212
+ label: i18next.t("neetoMolecules.productEmbed.alignContentLeft")
1213
+ },
1214
+ transparentBackground: {
1215
+ label: i18next.t("neetoMolecules.productEmbed.transparentBackground")
1216
+ }
1217
+ };
1143
1218
 
1144
1219
  var Code = function Code(_ref) {
1145
1220
  var id = _ref.id,