@bigbinary/neeto-molecules 1.0.36 → 1.0.38

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,13 @@
1
- import React, { useState, useRef, useEffect } from 'react';
1
+ import React, { useRef, useState, useEffect } from 'react';
2
2
  import { slugify, noop } from '@bigbinary/neeto-commons-frontend/pure';
3
- import { copyToClipboard, buildUrl } from '@bigbinary/neeto-commons-frontend/utils';
4
- import { Copy, ExternalLink, MenuHorizontal, Facebook, Linkedin, Twitter, QrCode } from '@bigbinary/neeto-icons';
5
- import { Modal, Typography, Input, Button, Dropdown, Tooltip } from '@bigbinary/neetoui';
3
+ import { buildUrl, copyToClipboard } from '@bigbinary/neeto-commons-frontend/utils';
4
+ import { Facebook, Linkedin, Twitter, Copy, ExternalLink, MenuHorizontal, QrCode } from '@bigbinary/neeto-icons';
5
+ import { Modal, Typography, Input as Input$1, Button as Button$1, Dropdown, Tooltip } from '@bigbinary/neetoui';
6
6
  import { useTranslation } from 'react-i18next';
7
- import { t } from 'i18next';
7
+ import { Formik, Form } from 'formik';
8
+ import { Input, Button } from '@bigbinary/neetoui/formik';
9
+ import { t as t$1 } from 'i18next';
10
+ import * as yup from 'yup';
8
11
 
9
12
  function _arrayWithHoles(arr) {
10
13
  if (Array.isArray(arr)) return arr;
@@ -61,11 +64,150 @@ function _slicedToArray(arr, i) {
61
64
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
62
65
  }
63
66
 
67
+ var facebookShareLink = function facebookShareLink(_ref) {
68
+ var id = _ref.id;
69
+ return buildUrl("https://www.facebook.com/sharer/sharer.php", {
70
+ u: "https://".concat(window.location.host, "/").concat(id)
71
+ });
72
+ };
73
+ var linkedInShareLink = function linkedInShareLink(_ref2) {
74
+ var id = _ref2.id,
75
+ title = _ref2.title;
76
+ return buildUrl("https://www.linkedin.com/shareArticle", {
77
+ mini: true,
78
+ url: "https://".concat(window.location.host, "/").concat(id),
79
+ title: title
80
+ });
81
+ };
82
+ var twitterShareLink = function twitterShareLink(_ref3) {
83
+ var id = _ref3.id,
84
+ title = _ref3.title;
85
+ return buildUrl("http://twitter.com/share", {
86
+ text: title,
87
+ url: "https://".concat(window.location.host, "/").concat(id)
88
+ });
89
+ };
90
+ var downloadCanvas = function downloadCanvas(canvas) {
91
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
92
+ var _options$name = options.name,
93
+ name = _options$name === void 0 ? "image" : _options$name,
94
+ _options$extension = options.extension,
95
+ extension = _options$extension === void 0 ? "png" : _options$extension;
96
+ var canvasUrl = canvas.toDataURL("image/".concat(extension));
97
+ var element = document.createElement("a");
98
+ element.href = canvasUrl;
99
+ element.download = "".concat(name, ".").concat(extension);
100
+ element.click();
101
+ element.remove();
102
+ };
103
+ var getPathname = function getPathname(url) {
104
+ return new URL(url).pathname.slice(1);
105
+ };
106
+ var getPrefixFromUrl = function getPrefixFromUrl(url) {
107
+ return "".concat(new URL(url).origin, "/");
108
+ };
109
+ var truncatePrefix = function truncatePrefix(url) {
110
+ return url.length > MAX_PREFIX_SIZE ? "...".concat(url.slice(-MAX_PREFIX_SIZE)) : url;
111
+ };
112
+
113
+ var SOCIAL_MEDIA_OPTIONS = {
114
+ FACEBOOK: {
115
+ label: t$1("neetoMolecules.shareViaLink.socialMediaShare.facebook"),
116
+ icon: Facebook,
117
+ generateShareUrl: facebookShareLink
118
+ },
119
+ LINKEDIN: {
120
+ label: t$1("neetoMolecules.shareViaLink.socialMediaShare.linkedIn"),
121
+ icon: Linkedin,
122
+ generateShareUrl: linkedInShareLink
123
+ },
124
+ TWITTER: {
125
+ label: t$1("neetoMolecules.shareViaLink.socialMediaShare.twitter"),
126
+ icon: Twitter,
127
+ generateShareUrl: twitterShareLink
128
+ }
129
+ };
130
+ var PATH_VALIDATION_SCHEMA = yup.object().shape({
131
+ path: yup.string().required(t$1("neetoMolecules.shareViaLink.editUrl.validationError")).matches(/^[A-Za-z0-9]([\w/-])*$/, t$1("neetoMolecules.shareViaLink.editUrl.validationError"))
132
+ });
133
+ var MAX_PREFIX_SIZE = 30;
134
+
135
+ var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}
136
+
137
+ var css = ".no-padding .neeto-ui-input.neeto-ui-input--medium input{padding:0}.no-padding .neeto-ui-input__prefix{color:rgb(var(--neeto-ui-gray-600))!important}";
138
+ n(css,{});
139
+
140
+ var EditURL = function EditURL(_ref) {
141
+ var editUrlProps = _ref.editUrlProps,
142
+ isOpen = _ref.isOpen,
143
+ onClose = _ref.onClose,
144
+ url = _ref.url,
145
+ isLoading = _ref.isLoading,
146
+ handleEdit = _ref.handleEdit;
147
+ var _useTranslation = useTranslation(),
148
+ t = _useTranslation.t;
149
+ var focusRef = useRef(null);
150
+ var handleSubmit = function handleSubmit(values) {
151
+ handleEdit(values.path);
152
+ onClose();
153
+ };
154
+ return /*#__PURE__*/React.createElement(Modal, {
155
+ "data-testid": "edit-url-modal",
156
+ initialFocusRef: focusRef,
157
+ isOpen: isOpen,
158
+ onClose: onClose
159
+ }, /*#__PURE__*/React.createElement(Modal.Header, null, /*#__PURE__*/React.createElement(Typography, {
160
+ lineHeight: "normal",
161
+ style: "h2",
162
+ weight: "semibold"
163
+ }, t("neetoMolecules.shareViaLink.editUrl.title"))), /*#__PURE__*/React.createElement(Formik, {
164
+ enableReinitialize: true,
165
+ initialValues: {
166
+ path: (editUrlProps === null || editUrlProps === void 0 ? void 0 : editUrlProps.editablePath) || getPathname(url)
167
+ },
168
+ validationSchema: PATH_VALIDATION_SCHEMA,
169
+ onSubmit: handleSubmit
170
+ }, function (_ref2) {
171
+ var isSubmitting = _ref2.isSubmitting,
172
+ dirty = _ref2.dirty;
173
+ return /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Modal.Body, {
174
+ className: "w-full space-y-6"
175
+ }, /*#__PURE__*/React.createElement(Input, {
176
+ className: "no-padding",
177
+ "data-testid": "edit-url-input",
178
+ label: t("neetoMolecules.shareViaLink.editUrl.inputLabel"),
179
+ maxLength: editUrlProps === null || editUrlProps === void 0 ? void 0 : editUrlProps.maxLength,
180
+ name: "path",
181
+ ref: focusRef,
182
+ prefix: truncatePrefix((editUrlProps === null || editUrlProps === void 0 ? void 0 : editUrlProps.prefix) || getPrefixFromUrl(url))
183
+ }), /*#__PURE__*/React.createElement(Typography, {
184
+ className: "neeto-ui-text-gray-700",
185
+ lineHeight: "normal",
186
+ style: "body2"
187
+ }, t("neetoMolecules.shareViaLink.editUrl.description"))), /*#__PURE__*/React.createElement(Modal.Footer, {
188
+ className: "space-x-2"
189
+ }, /*#__PURE__*/React.createElement(Button, {
190
+ "data-testid": "edit-url-confirm-button",
191
+ disabled: isSubmitting || !dirty,
192
+ loading: isLoading,
193
+ type: "submit",
194
+ label: t("neetoMolecules.shareViaLink.editUrl.submitButtonLabel")
195
+ }), /*#__PURE__*/React.createElement(Button, {
196
+ "data-testid": "edit-url-cancel-button",
197
+ disabled: isSubmitting,
198
+ style: "text",
199
+ type: "reset",
200
+ label: t("neetoMolecules.shareViaLink.editUrl.cancelButtonLabel"),
201
+ onClick: onClose
202
+ })));
203
+ }));
204
+ };
205
+
64
206
  var RegenerateURL = function RegenerateURL(_ref) {
65
207
  var isOpen = _ref.isOpen,
66
208
  onClose = _ref.onClose,
67
209
  url = _ref.url,
68
- isRegenerating = _ref.isRegenerating,
210
+ isLoading = _ref.isLoading,
69
211
  handleRegenerate = _ref.handleRegenerate;
70
212
  var _useTranslation = useTranslation(),
71
213
  t = _useTranslation.t;
@@ -79,7 +221,7 @@ var RegenerateURL = function RegenerateURL(_ref) {
79
221
  weight: "semibold"
80
222
  }, t("neetoMolecules.shareViaLink.regenerateUrl.title"))), /*#__PURE__*/React.createElement(Modal.Body, null, /*#__PURE__*/React.createElement("div", {
81
223
  className: "w-full space-y-6"
82
- }, /*#__PURE__*/React.createElement(Input, {
224
+ }, /*#__PURE__*/React.createElement(Input$1, {
83
225
  disabled: true,
84
226
  label: t("neetoMolecules.shareViaLink.regenerateUrl.inputLabel"),
85
227
  value: url
@@ -87,21 +229,17 @@ var RegenerateURL = function RegenerateURL(_ref) {
87
229
  className: "neeto-ui-text-gray-700",
88
230
  lineHeight: "normal",
89
231
  style: "body2"
90
- }, t("neetoMolecules.shareViaLink.regenerateUrl.description")), /*#__PURE__*/React.createElement(Typography, {
91
- className: "neeto-ui-text-gray-700",
92
- lineHeight: "normal",
93
- style: "body2"
94
- }, t("neetoMolecules.shareViaLink.regenerateUrl.confirmation")))), /*#__PURE__*/React.createElement(Modal.Footer, {
232
+ }, t("neetoMolecules.shareViaLink.regenerateUrl.description")))), /*#__PURE__*/React.createElement(Modal.Footer, {
95
233
  className: "space-x-2"
96
- }, /*#__PURE__*/React.createElement(Button, {
234
+ }, /*#__PURE__*/React.createElement(Button$1, {
97
235
  "data-testid": "regenerate-url-confirm-button",
98
- loading: isRegenerating,
236
+ loading: isLoading,
99
237
  label: t("neetoMolecules.shareViaLink.regenerateUrl.submitButtonLabel"),
100
238
  onClick: function onClick() {
101
239
  handleRegenerate();
102
240
  onClose();
103
241
  }
104
- }), /*#__PURE__*/React.createElement(Button, {
242
+ }), /*#__PURE__*/React.createElement(Button$1, {
105
243
  "data-testid": "regenerate-url-cancel-button",
106
244
  style: "text",
107
245
  label: t("neetoMolecules.shareViaLink.regenerateUrl.cancelButtonLabel"),
@@ -112,18 +250,25 @@ var RegenerateURL = function RegenerateURL(_ref) {
112
250
  var Menu = Dropdown.Menu,
113
251
  MenuItem = Dropdown.MenuItem;
114
252
  var Link = function Link(_ref) {
115
- var enableRegenerateUrl = _ref.enableRegenerateUrl,
253
+ var editUrlProps = _ref.editUrlProps,
254
+ enabledOptions = _ref.enabledOptions,
116
255
  entityName = _ref.entityName,
256
+ handleEdit = _ref.handleEdit,
117
257
  handleRegenerate = _ref.handleRegenerate,
118
- isRegenerating = _ref.isRegenerating,
258
+ isLoading = _ref.isLoading,
119
259
  previewUrl = _ref.previewUrl,
120
260
  url = _ref.url;
121
261
  var _useState = useState(false),
122
262
  _useState2 = _slicedToArray(_useState, 2),
123
263
  isRegenerateURLModalOpen = _useState2[0],
124
264
  setIsRegenerateURLModalOpen = _useState2[1];
265
+ var _useState3 = useState(false),
266
+ _useState4 = _slicedToArray(_useState3, 2),
267
+ isEditURLModalOpen = _useState4[0],
268
+ setIsEditURLModalOpen = _useState4[1];
125
269
  var _useTranslation = useTranslation(),
126
270
  t = _useTranslation.t;
271
+ var isDropdownEnabled = enabledOptions.regenerate || enabledOptions.edit;
127
272
  return /*#__PURE__*/React.createElement("div", {
128
273
  className: "space-y-4",
129
274
  "data-testid": "link-block"
@@ -143,17 +288,17 @@ var Link = function Link(_ref) {
143
288
  entity: entityName
144
289
  }))), /*#__PURE__*/React.createElement("div", {
145
290
  className: "flex items-center gap-1"
146
- }, /*#__PURE__*/React.createElement(Input, {
291
+ }, /*#__PURE__*/React.createElement(Input$1, {
147
292
  readOnly: true,
148
293
  value: url
149
- }), /*#__PURE__*/React.createElement(Button, {
294
+ }), /*#__PURE__*/React.createElement(Button$1, {
150
295
  "data-testid": "link-copy-button",
151
296
  icon: Copy,
152
297
  label: t("neetoMolecules.shareViaLink.copyLink"),
153
298
  onClick: function onClick() {
154
299
  return copyToClipboard(url);
155
300
  }
156
- }), /*#__PURE__*/React.createElement(Button, {
301
+ }), /*#__PURE__*/React.createElement(Button$1, {
157
302
  "data-testid": "preview-button",
158
303
  href: previewUrl || url,
159
304
  icon: ExternalLink,
@@ -165,80 +310,40 @@ var Link = function Link(_ref) {
165
310
  }),
166
311
  position: "top"
167
312
  }
168
- }), enableRegenerateUrl && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Dropdown, {
313
+ }), isDropdownEnabled && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Dropdown, {
169
314
  buttonStyle: "text",
170
315
  icon: MenuHorizontal
171
- }, /*#__PURE__*/React.createElement(Menu, null, /*#__PURE__*/React.createElement(MenuItem.Button, {
316
+ }, /*#__PURE__*/React.createElement(Menu, null, enabledOptions.regenerate && /*#__PURE__*/React.createElement(MenuItem.Button, {
172
317
  "data-testid": "regenerate-url-button",
318
+ isDisabled: !enabledOptions.regenerate,
173
319
  onClick: function onClick() {
174
320
  return setIsRegenerateURLModalOpen(true);
175
321
  }
176
- }, t("neetoMolecules.shareViaLink.regenerateUrl.title")))), /*#__PURE__*/React.createElement(RegenerateURL, {
322
+ }, t("neetoMolecules.shareViaLink.regenerateUrl.title")), enabledOptions.edit && /*#__PURE__*/React.createElement(MenuItem.Button, {
323
+ "data-testid": "edit-url-button",
324
+ onClick: function onClick() {
325
+ return setIsEditURLModalOpen(true);
326
+ }
327
+ }, t("neetoMolecules.shareViaLink.editUrl.title")))), /*#__PURE__*/React.createElement(RegenerateURL, {
177
328
  handleRegenerate: handleRegenerate,
329
+ isLoading: isLoading,
178
330
  isOpen: isRegenerateURLModalOpen,
179
- isRegenerating: isRegenerating,
180
331
  url: url,
181
332
  onClose: function onClose() {
182
333
  return setIsRegenerateURLModalOpen(false);
183
334
  }
335
+ }), /*#__PURE__*/React.createElement(EditURL, {
336
+ editUrlProps: editUrlProps,
337
+ handleEdit: handleEdit,
338
+ isLoading: isLoading,
339
+ isOpen: isEditURLModalOpen,
340
+ url: url,
341
+ onClose: function onClose() {
342
+ return setIsEditURLModalOpen(false);
343
+ }
184
344
  }))));
185
345
  };
186
346
 
187
- var facebookShareLink = function facebookShareLink(_ref) {
188
- var id = _ref.id;
189
- return buildUrl("https://www.facebook.com/sharer/sharer.php", {
190
- u: "https://".concat(window.location.host, "/").concat(id)
191
- });
192
- };
193
- var linkedInShareLink = function linkedInShareLink(_ref2) {
194
- var id = _ref2.id,
195
- title = _ref2.title;
196
- return buildUrl("https://www.linkedin.com/shareArticle", {
197
- mini: true,
198
- url: "https://".concat(window.location.host, "/").concat(id),
199
- title: title
200
- });
201
- };
202
- var twitterShareLink = function twitterShareLink(_ref3) {
203
- var id = _ref3.id,
204
- title = _ref3.title;
205
- return buildUrl("http://twitter.com/share", {
206
- text: title,
207
- url: "https://".concat(window.location.host, "/").concat(id)
208
- });
209
- };
210
- var downloadCanvas = function downloadCanvas(canvas) {
211
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
212
- var _options$name = options.name,
213
- name = _options$name === void 0 ? "image" : _options$name,
214
- _options$extension = options.extension,
215
- extension = _options$extension === void 0 ? "png" : _options$extension;
216
- var canvasUrl = canvas.toDataURL("image/".concat(extension));
217
- var element = document.createElement("a");
218
- element.href = canvasUrl;
219
- element.download = "".concat(name, ".").concat(extension);
220
- element.click();
221
- element.remove();
222
- };
223
-
224
- var SOCIAL_MEDIA_OPTIONS = {
225
- FACEBOOK: {
226
- label: t("neetoMolecules.shareViaLink.socialMediaShare.facebook"),
227
- icon: Facebook,
228
- generateShareUrl: facebookShareLink
229
- },
230
- LINKEDIN: {
231
- label: t("neetoMolecules.shareViaLink.socialMediaShare.linkedIn"),
232
- icon: Linkedin,
233
- generateShareUrl: linkedInShareLink
234
- },
235
- TWITTER: {
236
- label: t("neetoMolecules.shareViaLink.socialMediaShare.twitter"),
237
- icon: Twitter,
238
- generateShareUrl: twitterShareLink
239
- }
240
- };
241
-
242
347
  var __defProp = Object.defineProperty;
243
348
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
244
349
  var __hasOwnProp = Object.prototype.hasOwnProperty;
@@ -1135,11 +1240,11 @@ var QRCodeModal = function QRCodeModal(_ref) {
1135
1240
  value: url
1136
1241
  })), /*#__PURE__*/React.createElement(Modal.Footer, {
1137
1242
  className: "space-x-2"
1138
- }, /*#__PURE__*/React.createElement(Button, {
1243
+ }, /*#__PURE__*/React.createElement(Button$1, {
1139
1244
  "data-testid": "qr-code-download-button",
1140
1245
  label: t("neetoMolecules.shareViaLink.socialMediaShare.qrCodeDownload"),
1141
1246
  onClick: handleDownload
1142
- }), /*#__PURE__*/React.createElement(Button, {
1247
+ }), /*#__PURE__*/React.createElement(Button$1, {
1143
1248
  label: t("neetoMolecules.common.actions.cancel"),
1144
1249
  style: "text",
1145
1250
  onClick: onClose
@@ -1209,12 +1314,22 @@ var SocialMedia = function SocialMedia(_ref) {
1209
1314
  };
1210
1315
 
1211
1316
  var ShareViaLink = function ShareViaLink(_ref) {
1212
- var _ref$isRegenerating = _ref.isRegenerating,
1213
- isRegenerating = _ref$isRegenerating === void 0 ? false : _ref$isRegenerating,
1214
- _ref$enableRegenerate = _ref.enableRegenerateUrl,
1215
- enableRegenerateUrl = _ref$enableRegenerate === void 0 ? false : _ref$enableRegenerate,
1317
+ var _ref$isLoading = _ref.isLoading,
1318
+ isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
1319
+ _ref$enabledOptions = _ref.enabledOptions,
1320
+ enabledOptions = _ref$enabledOptions === void 0 ? {
1321
+ regenerate: false,
1322
+ edit: false
1323
+ } : _ref$enabledOptions,
1324
+ _ref$editUrlProps = _ref.editUrlProps,
1325
+ editUrlProps = _ref$editUrlProps === void 0 ? {
1326
+ prefix: "",
1327
+ editablePath: ""
1328
+ } : _ref$editUrlProps,
1216
1329
  entity = _ref.entity,
1217
1330
  entityName = _ref.entityName,
1331
+ _ref$handleEdit = _ref.handleEdit,
1332
+ handleEdit = _ref$handleEdit === void 0 ? noop : _ref$handleEdit,
1218
1333
  _ref$handleRegenerate = _ref.handleRegenerate,
1219
1334
  handleRegenerate = _ref$handleRegenerate === void 0 ? noop : _ref$handleRegenerate,
1220
1335
  _ref$previewUrl = _ref.previewUrl,
@@ -1225,10 +1340,12 @@ var ShareViaLink = function ShareViaLink(_ref) {
1225
1340
  className: "neeto-ui-border-gray-400 neeto-ui-shadow-xs neeto-ui-rounded-lg neeto-ui-bg-white col-span-2 space-y-4 border p-8",
1226
1341
  "data-testid": "share-via-link"
1227
1342
  }, /*#__PURE__*/React.createElement(Link, {
1228
- enableRegenerateUrl: enableRegenerateUrl,
1343
+ editUrlProps: editUrlProps,
1344
+ enabledOptions: enabledOptions,
1229
1345
  entityName: entityName,
1346
+ handleEdit: handleEdit,
1230
1347
  handleRegenerate: handleRegenerate,
1231
- isRegenerating: isRegenerating,
1348
+ isLoading: isLoading,
1232
1349
  previewUrl: previewUrl,
1233
1350
  url: url
1234
1351
  }), /*#__PURE__*/React.createElement(SocialMedia, {