@bigbinary/neeto-molecules 0.0.1

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.
Files changed (183) hide show
  1. package/README.md +60 -0
  2. package/dist/BrowserSupport.cjs.js +1727 -0
  3. package/dist/BrowserSupport.cjs.js.map +1 -0
  4. package/dist/BrowserSupport.js +1721 -0
  5. package/dist/BrowserSupport.js.map +1 -0
  6. package/dist/Columns.cjs.js +191 -0
  7. package/dist/Columns.cjs.js.map +1 -0
  8. package/dist/Columns.js +184 -0
  9. package/dist/Columns.js.map +1 -0
  10. package/dist/Container.cjs.js +1277 -0
  11. package/dist/Container.cjs.js.map +1 -0
  12. package/dist/Container.js +1271 -0
  13. package/dist/Container.js.map +1 -0
  14. package/dist/CopyToClipboardButton.cjs.js +78 -0
  15. package/dist/CopyToClipboardButton.cjs.js.map +1 -0
  16. package/dist/CopyToClipboardButton.js +72 -0
  17. package/dist/CopyToClipboardButton.js.map +1 -0
  18. package/dist/CustomDomain.cjs.js +680 -0
  19. package/dist/CustomDomain.cjs.js.map +1 -0
  20. package/dist/CustomDomain.js +654 -0
  21. package/dist/CustomDomain.js.map +1 -0
  22. package/dist/CustomDomainDashboard.cjs.js +2306 -0
  23. package/dist/CustomDomainDashboard.cjs.js.map +1 -0
  24. package/dist/CustomDomainDashboard.js +2279 -0
  25. package/dist/CustomDomainDashboard.js.map +1 -0
  26. package/dist/DateFormat.cjs.js +51 -0
  27. package/dist/DateFormat.cjs.js.map +1 -0
  28. package/dist/DateFormat.js +45 -0
  29. package/dist/DateFormat.js.map +1 -0
  30. package/dist/DateRangeFilter.cjs.js +236 -0
  31. package/dist/DateRangeFilter.cjs.js.map +1 -0
  32. package/dist/DateRangeFilter.js +229 -0
  33. package/dist/DateRangeFilter.js.map +1 -0
  34. package/dist/DynamicVariables.cjs.js +112 -0
  35. package/dist/DynamicVariables.cjs.js.map +1 -0
  36. package/dist/DynamicVariables.js +106 -0
  37. package/dist/DynamicVariables.js.map +1 -0
  38. package/dist/EmailPreview.cjs.js +102 -0
  39. package/dist/EmailPreview.cjs.js.map +1 -0
  40. package/dist/EmailPreview.js +96 -0
  41. package/dist/EmailPreview.js.map +1 -0
  42. package/dist/ErrorPage.cjs.js +208 -0
  43. package/dist/ErrorPage.cjs.js.map +1 -0
  44. package/dist/ErrorPage.js +184 -0
  45. package/dist/ErrorPage.js.map +1 -0
  46. package/dist/Header.cjs.js +219 -0
  47. package/dist/Header.cjs.js.map +1 -0
  48. package/dist/Header.js +213 -0
  49. package/dist/Header.js.map +1 -0
  50. package/dist/IconPicker.cjs.js +1307 -0
  51. package/dist/IconPicker.cjs.js.map +1 -0
  52. package/dist/IconPicker.js +1301 -0
  53. package/dist/IconPicker.js.map +1 -0
  54. package/dist/IntegrationCard.cjs.js +75 -0
  55. package/dist/IntegrationCard.cjs.js.map +1 -0
  56. package/dist/IntegrationCard.js +69 -0
  57. package/dist/IntegrationCard.js.map +1 -0
  58. package/dist/IntegrationDisconnectAlert.cjs.js +81 -0
  59. package/dist/IntegrationDisconnectAlert.cjs.js.map +1 -0
  60. package/dist/IntegrationDisconnectAlert.js +75 -0
  61. package/dist/IntegrationDisconnectAlert.js.map +1 -0
  62. package/dist/IntegrationWalkthroughModal.cjs.js +42 -0
  63. package/dist/IntegrationWalkthroughModal.cjs.js.map +1 -0
  64. package/dist/IntegrationWalkthroughModal.js +36 -0
  65. package/dist/IntegrationWalkthroughModal.js.map +1 -0
  66. package/dist/IpRestriction.cjs.js +3764 -0
  67. package/dist/IpRestriction.cjs.js.map +1 -0
  68. package/dist/IpRestriction.js +3738 -0
  69. package/dist/IpRestriction.js.map +1 -0
  70. package/dist/KeyboardShortcuts.cjs.js +2242 -0
  71. package/dist/KeyboardShortcuts.cjs.js.map +1 -0
  72. package/dist/KeyboardShortcuts.js +2235 -0
  73. package/dist/KeyboardShortcuts.js.map +1 -0
  74. package/dist/LoginPage.cjs.js +618 -0
  75. package/dist/LoginPage.cjs.js.map +1 -0
  76. package/dist/LoginPage.js +593 -0
  77. package/dist/LoginPage.js.map +1 -0
  78. package/dist/MenuBar.cjs.js +31044 -0
  79. package/dist/MenuBar.cjs.js.map +1 -0
  80. package/dist/MenuBar.js +31038 -0
  81. package/dist/MenuBar.js.map +1 -0
  82. package/dist/NeetoWidget.cjs.js +3369 -0
  83. package/dist/NeetoWidget.cjs.js.map +1 -0
  84. package/dist/NeetoWidget.js +3343 -0
  85. package/dist/NeetoWidget.js.map +1 -0
  86. package/dist/PageLoader.cjs.js +158 -0
  87. package/dist/PageLoader.cjs.js.map +1 -0
  88. package/dist/PageLoader.js +134 -0
  89. package/dist/PageLoader.js.map +1 -0
  90. package/dist/PhoneNumber.cjs.js +7021 -0
  91. package/dist/PhoneNumber.cjs.js.map +1 -0
  92. package/dist/PhoneNumber.js +6989 -0
  93. package/dist/PhoneNumber.js.map +1 -0
  94. package/dist/PublishBlock.cjs.js +189 -0
  95. package/dist/PublishBlock.cjs.js.map +1 -0
  96. package/dist/PublishBlock.js +183 -0
  97. package/dist/PublishBlock.js.map +1 -0
  98. package/dist/Rename.cjs.js +306 -0
  99. package/dist/Rename.cjs.js.map +1 -0
  100. package/dist/Rename.js +300 -0
  101. package/dist/Rename.js.map +1 -0
  102. package/dist/ResponsiveDevicePicker.cjs.js +260 -0
  103. package/dist/ResponsiveDevicePicker.cjs.js.map +1 -0
  104. package/dist/ResponsiveDevicePicker.js +254 -0
  105. package/dist/ResponsiveDevicePicker.js.map +1 -0
  106. package/dist/Schedule.cjs.js +952 -0
  107. package/dist/Schedule.cjs.js.map +1 -0
  108. package/dist/Schedule.js +921 -0
  109. package/dist/Schedule.js.map +1 -0
  110. package/dist/Scrollable.cjs.js +184 -0
  111. package/dist/Scrollable.cjs.js.map +1 -0
  112. package/dist/Scrollable.js +178 -0
  113. package/dist/Scrollable.js.map +1 -0
  114. package/dist/ShareViaEmail.cjs.js +2992 -0
  115. package/dist/ShareViaEmail.cjs.js.map +1 -0
  116. package/dist/ShareViaEmail.js +2966 -0
  117. package/dist/ShareViaEmail.js.map +1 -0
  118. package/dist/ShareViaLink.cjs.js +1385 -0
  119. package/dist/ShareViaLink.cjs.js.map +1 -0
  120. package/dist/ShareViaLink.js +1360 -0
  121. package/dist/ShareViaLink.js.map +1 -0
  122. package/dist/Sidebar.cjs.js +32222 -0
  123. package/dist/Sidebar.cjs.js.map +1 -0
  124. package/dist/Sidebar.js +32196 -0
  125. package/dist/Sidebar.js.map +1 -0
  126. package/dist/SubHeader.cjs.js +272 -0
  127. package/dist/SubHeader.cjs.js.map +1 -0
  128. package/dist/SubHeader.js +265 -0
  129. package/dist/SubHeader.js.map +1 -0
  130. package/dist/TableWrapper.cjs.js +87 -0
  131. package/dist/TableWrapper.cjs.js.map +1 -0
  132. package/dist/TableWrapper.js +81 -0
  133. package/dist/TableWrapper.js.map +1 -0
  134. package/dist/ThemeSidebar.cjs.js +13618 -0
  135. package/dist/ThemeSidebar.cjs.js.map +1 -0
  136. package/dist/ThemeSidebar.js +13593 -0
  137. package/dist/ThemeSidebar.js.map +1 -0
  138. package/dist/TimeFormat.cjs.js +53 -0
  139. package/dist/TimeFormat.cjs.js.map +1 -0
  140. package/dist/TimeFormat.js +47 -0
  141. package/dist/TimeFormat.js.map +1 -0
  142. package/dist/TimezoneMismatchModal.cjs.js +176 -0
  143. package/dist/TimezoneMismatchModal.cjs.js.map +1 -0
  144. package/dist/TimezoneMismatchModal.js +168 -0
  145. package/dist/TimezoneMismatchModal.js.map +1 -0
  146. package/package.json +185 -0
  147. package/src/translations/en.json +449 -0
  148. package/types/BrowserSupport.d.ts +86 -0
  149. package/types/Columns.d.ts +53 -0
  150. package/types/Container.d.ts +35 -0
  151. package/types/CopyToClipboardButton.d.ts +21 -0
  152. package/types/CustomDomain.d.ts +19 -0
  153. package/types/CustomDomainDashboard.d.ts +33 -0
  154. package/types/DateFormat.d.ts +18 -0
  155. package/types/DateRangeFilter.d.ts +52 -0
  156. package/types/DynamicVariables.d.ts +45 -0
  157. package/types/EmailPreview.d.ts +41 -0
  158. package/types/ErrorPage.d.ts +15 -0
  159. package/types/Header.d.ts +30 -0
  160. package/types/IconPicker.d.ts +43 -0
  161. package/types/IntegrationCard.d.ts +45 -0
  162. package/types/IntegrationDisconnectAlert.d.ts +37 -0
  163. package/types/IntegrationWalkthroughModal.d.ts +31 -0
  164. package/types/IpRestriction.d.ts +23 -0
  165. package/types/KeyboardShortcuts.d.ts +147 -0
  166. package/types/LoginPage.d.ts +43 -0
  167. package/types/MenuBar.d.ts +125 -0
  168. package/types/NeetoWidget.d.ts +41 -0
  169. package/types/PageLoader.d.ts +38 -0
  170. package/types/PhoneNumber.d.ts +106 -0
  171. package/types/PublishBlock.d.ts +84 -0
  172. package/types/Rename.d.ts +60 -0
  173. package/types/ResponsiveDevicePicker.d.ts +30 -0
  174. package/types/Schedule.d.ts +132 -0
  175. package/types/Scrollable.d.ts +28 -0
  176. package/types/ShareViaEmail.d.ts +99 -0
  177. package/types/ShareViaLink.d.ts +117 -0
  178. package/types/Sidebar.d.ts +63 -0
  179. package/types/SubHeader.d.ts +97 -0
  180. package/types/TableWrapper.d.ts +38 -0
  181. package/types/TimeFormat.d.ts +17 -0
  182. package/types/TimezoneMismatchModal.d.ts +39 -0
  183. package/types/themeSidebar.d.ts +80 -0
@@ -0,0 +1,2966 @@
1
+ import React, { forwardRef, useRef, useCallback } from 'react';
2
+ import { Upload, LeftArrow } from '@bigbinary/neeto-icons';
3
+ import { Typography, Button, DatePicker, Label } from '@bigbinary/neetoui';
4
+ import { MultiEmailInput, Input, Switch, ActionBlock, Form as Form$1 } from '@bigbinary/neetoui/formik';
5
+ import { useTranslation } from 'react-i18next';
6
+ import { isNotEmpty, isNot } from '@bigbinary/neeto-commons-frontend/pure';
7
+ import { EditorContent, FormikEditor, isEditorEmpty } from '@bigbinary/neeto-editor';
8
+ import { useField, useFormikContext } from 'formik';
9
+ import dayjs from 'dayjs';
10
+ import { t } from 'i18next';
11
+ import require$$0 from 'stream';
12
+ import { prop } from 'ramda';
13
+ import * as yup from 'yup';
14
+ import { string } from 'yup';
15
+
16
+ var MemoizedEditorContent = /*#__PURE__*/React.memo(EditorContent);
17
+ var EmailPreview = function EmailPreview(_ref) {
18
+ var to = _ref.to,
19
+ from = _ref.from,
20
+ subject = _ref.subject,
21
+ body = _ref.body,
22
+ productName = _ref.productName,
23
+ actionButtonText = _ref.actionButtonText,
24
+ logo = _ref.logo;
25
+ var _useTranslation = useTranslation(),
26
+ t = _useTranslation.t;
27
+ return /*#__PURE__*/React.createElement("div", {
28
+ className: "neeto-ui-border-gray-300 neeto-ui-shadow-m neeto-ui-bg-white flex flex-1 flex-col border",
29
+ "data-cy": "email-preview-card"
30
+ }, /*#__PURE__*/React.createElement("div", {
31
+ className: "neeto-ui-border-gray-300 space-y-3 divide-y divide-gray-200 border-b p-6"
32
+ }, /*#__PURE__*/React.createElement("div", {
33
+ className: "flex gap-2",
34
+ "data-cy": "email-send-to-preview",
35
+ "data-testid": "email-to-block"
36
+ }, /*#__PURE__*/React.createElement(Typography, {
37
+ className: "neeto-ui-text-gray-500",
38
+ lineHeight: "normal",
39
+ style: "body2"
40
+ }, t("neetoMolecules.emailPreview.to"), ":"), isNotEmpty(to) ? /*#__PURE__*/React.createElement(Typography, {
41
+ className: "neeto-ui-text-gray-800 min-w-0 flex-grow break-words",
42
+ lineHeight: "normal",
43
+ style: "body2"
44
+ }, to.join(", ")) : /*#__PURE__*/React.createElement("div", {
45
+ className: "neeto-ui-bg-gray-300 neeto-ui-rounded-full mt-2 h-2 w-40"
46
+ })), from && /*#__PURE__*/React.createElement("div", {
47
+ className: "flex items-center gap-2 pt-3"
48
+ }, /*#__PURE__*/React.createElement(Typography, {
49
+ className: "neeto-ui-text-gray-500",
50
+ lineHeight: "normal",
51
+ style: "body2"
52
+ }, t("neetoMolecules.emailPreview.from"), ":"), /*#__PURE__*/React.createElement(Typography, {
53
+ className: "neeto-ui-text-gray-800 min-w-0 flex-grow break-words",
54
+ "data-cy": "email-send-from-preview",
55
+ lineHeight: "normal",
56
+ style: "body2"
57
+ }, from)), /*#__PURE__*/React.createElement("div", {
58
+ className: "flex items-center gap-2 pt-3"
59
+ }, /*#__PURE__*/React.createElement(Typography, {
60
+ className: "neeto-ui-text-gray-500",
61
+ lineHeight: "normal",
62
+ style: "body2"
63
+ }, t("neetoMolecules.emailPreview.subject"), ":"), /*#__PURE__*/React.createElement(Typography, {
64
+ className: "neeto-ui-text-gray-800 min-w-0 flex-grow break-words",
65
+ "data-cy": "email-subject-preview",
66
+ lineHeight: "normal",
67
+ style: "body2"
68
+ }, subject || /*#__PURE__*/React.createElement("span", {
69
+ className: "neeto-ui-bg-gray-300 neeto-ui-rounded-full h-2 w-40"
70
+ })))), /*#__PURE__*/React.createElement("div", {
71
+ className: "neeto-ui-text-gray-800 flex flex-1 flex-col justify-between space-y-6 p-6 pr-10 text-base leading-relaxed",
72
+ "data-cy": "email-body-preview-container"
73
+ }, body ? /*#__PURE__*/React.createElement(MemoizedEditorContent, {
74
+ content: body
75
+ }) : /*#__PURE__*/React.createElement("div", {
76
+ className: "space-y-4"
77
+ }, /*#__PURE__*/React.createElement("div", {
78
+ className: "neeto-ui-bg-gray-300 neeto-ui-rounded-full h-2 w-80"
79
+ }), /*#__PURE__*/React.createElement("div", {
80
+ className: "neeto-ui-bg-gray-300 neeto-ui-rounded-full h-2 w-72"
81
+ }), /*#__PURE__*/React.createElement("div", {
82
+ className: "neeto-ui-bg-gray-300 neeto-ui-rounded-full h-2 w-80"
83
+ })), actionButtonText && /*#__PURE__*/React.createElement("div", {
84
+ className: "mt-6 flex w-full items-center justify-center"
85
+ }, /*#__PURE__*/React.createElement(Button, {
86
+ className: "pointer-events-none",
87
+ label: actionButtonText
88
+ })), logo && /*#__PURE__*/React.createElement("img", {
89
+ alt: t("neetoMolecules.emailPreview.logoAltText"),
90
+ className: "h-20 w-36 object-cover",
91
+ "data-cy": "company-logo-preview",
92
+ src: logo
93
+ })), productName && /*#__PURE__*/React.createElement("div", {
94
+ className: "neeto-ui-bg-gray-100 mt-auto p-2",
95
+ "data-testid": "product-name-block"
96
+ }, /*#__PURE__*/React.createElement(Typography, {
97
+ className: "neeto-ui-text-gray-600 text-center leading-6",
98
+ style: "body3"
99
+ }, t("neetoMolecules.emailPreview.poweredBy"), /*#__PURE__*/React.createElement("span", {
100
+ className: "neeto-ui-text-gray-800 font-medium"
101
+ }, productName))));
102
+ };
103
+
104
+ function _arrayWithHoles(arr) {
105
+ if (Array.isArray(arr)) return arr;
106
+ }
107
+
108
+ function _iterableToArrayLimit(arr, i) {
109
+ var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
110
+ if (null != _i) {
111
+ var _s,
112
+ _e,
113
+ _x,
114
+ _r,
115
+ _arr = [],
116
+ _n = !0,
117
+ _d = !1;
118
+ try {
119
+ if (_x = (_i = _i.call(arr)).next, 0 === i) {
120
+ if (Object(_i) !== _i) return;
121
+ _n = !1;
122
+ } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
123
+ } catch (err) {
124
+ _d = !0, _e = err;
125
+ } finally {
126
+ try {
127
+ if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
128
+ } finally {
129
+ if (_d) throw _e;
130
+ }
131
+ }
132
+ return _arr;
133
+ }
134
+ }
135
+
136
+ function _arrayLikeToArray(arr, len) {
137
+ if (len == null || len > arr.length) len = arr.length;
138
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
139
+ return arr2;
140
+ }
141
+
142
+ function _unsupportedIterableToArray(o, minLen) {
143
+ if (!o) return;
144
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
145
+ var n = Object.prototype.toString.call(o).slice(8, -1);
146
+ if (n === "Object" && o.constructor) n = o.constructor.name;
147
+ if (n === "Map" || n === "Set") return Array.from(o);
148
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
149
+ }
150
+
151
+ function _nonIterableRest() {
152
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
153
+ }
154
+
155
+ function _slicedToArray(arr, i) {
156
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
157
+ }
158
+
159
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
160
+ try {
161
+ var info = gen[key](arg);
162
+ var value = info.value;
163
+ } catch (error) {
164
+ reject(error);
165
+ return;
166
+ }
167
+ if (info.done) {
168
+ resolve(value);
169
+ } else {
170
+ Promise.resolve(value).then(_next, _throw);
171
+ }
172
+ }
173
+ function _asyncToGenerator(fn) {
174
+ return function () {
175
+ var self = this,
176
+ args = arguments;
177
+ return new Promise(function (resolve, reject) {
178
+ var gen = fn.apply(self, args);
179
+ function _next(value) {
180
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
181
+ }
182
+ function _throw(err) {
183
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
184
+ }
185
+ _next(undefined);
186
+ });
187
+ };
188
+ }
189
+
190
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
191
+
192
+ var regeneratorRuntime$1 = {exports: {}};
193
+
194
+ var _typeof$1 = {exports: {}};
195
+
196
+ (function (module) {
197
+ function _typeof(obj) {
198
+ "@babel/helpers - typeof";
199
+
200
+ return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
201
+ return typeof obj;
202
+ } : function (obj) {
203
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
204
+ }, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(obj);
205
+ }
206
+ module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
207
+ } (_typeof$1));
208
+
209
+ (function (module) {
210
+ var _typeof = _typeof$1.exports["default"];
211
+ function _regeneratorRuntime() {
212
+ module.exports = _regeneratorRuntime = function _regeneratorRuntime() {
213
+ return exports;
214
+ }, module.exports.__esModule = true, module.exports["default"] = module.exports;
215
+ var exports = {},
216
+ Op = Object.prototype,
217
+ hasOwn = Op.hasOwnProperty,
218
+ defineProperty = Object.defineProperty || function (obj, key, desc) {
219
+ obj[key] = desc.value;
220
+ },
221
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
222
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
223
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
224
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
225
+ function define(obj, key, value) {
226
+ return Object.defineProperty(obj, key, {
227
+ value: value,
228
+ enumerable: !0,
229
+ configurable: !0,
230
+ writable: !0
231
+ }), obj[key];
232
+ }
233
+ try {
234
+ define({}, "");
235
+ } catch (err) {
236
+ define = function define(obj, key, value) {
237
+ return obj[key] = value;
238
+ };
239
+ }
240
+ function wrap(innerFn, outerFn, self, tryLocsList) {
241
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
242
+ generator = Object.create(protoGenerator.prototype),
243
+ context = new Context(tryLocsList || []);
244
+ return defineProperty(generator, "_invoke", {
245
+ value: makeInvokeMethod(innerFn, self, context)
246
+ }), generator;
247
+ }
248
+ function tryCatch(fn, obj, arg) {
249
+ try {
250
+ return {
251
+ type: "normal",
252
+ arg: fn.call(obj, arg)
253
+ };
254
+ } catch (err) {
255
+ return {
256
+ type: "throw",
257
+ arg: err
258
+ };
259
+ }
260
+ }
261
+ exports.wrap = wrap;
262
+ var ContinueSentinel = {};
263
+ function Generator() {}
264
+ function GeneratorFunction() {}
265
+ function GeneratorFunctionPrototype() {}
266
+ var IteratorPrototype = {};
267
+ define(IteratorPrototype, iteratorSymbol, function () {
268
+ return this;
269
+ });
270
+ var getProto = Object.getPrototypeOf,
271
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
272
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
273
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
274
+ function defineIteratorMethods(prototype) {
275
+ ["next", "throw", "return"].forEach(function (method) {
276
+ define(prototype, method, function (arg) {
277
+ return this._invoke(method, arg);
278
+ });
279
+ });
280
+ }
281
+ function AsyncIterator(generator, PromiseImpl) {
282
+ function invoke(method, arg, resolve, reject) {
283
+ var record = tryCatch(generator[method], generator, arg);
284
+ if ("throw" !== record.type) {
285
+ var result = record.arg,
286
+ value = result.value;
287
+ return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
288
+ invoke("next", value, resolve, reject);
289
+ }, function (err) {
290
+ invoke("throw", err, resolve, reject);
291
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
292
+ result.value = unwrapped, resolve(result);
293
+ }, function (error) {
294
+ return invoke("throw", error, resolve, reject);
295
+ });
296
+ }
297
+ reject(record.arg);
298
+ }
299
+ var previousPromise;
300
+ defineProperty(this, "_invoke", {
301
+ value: function value(method, arg) {
302
+ function callInvokeWithMethodAndArg() {
303
+ return new PromiseImpl(function (resolve, reject) {
304
+ invoke(method, arg, resolve, reject);
305
+ });
306
+ }
307
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
308
+ }
309
+ });
310
+ }
311
+ function makeInvokeMethod(innerFn, self, context) {
312
+ var state = "suspendedStart";
313
+ return function (method, arg) {
314
+ if ("executing" === state) throw new Error("Generator is already running");
315
+ if ("completed" === state) {
316
+ if ("throw" === method) throw arg;
317
+ return doneResult();
318
+ }
319
+ for (context.method = method, context.arg = arg;;) {
320
+ var delegate = context.delegate;
321
+ if (delegate) {
322
+ var delegateResult = maybeInvokeDelegate(delegate, context);
323
+ if (delegateResult) {
324
+ if (delegateResult === ContinueSentinel) continue;
325
+ return delegateResult;
326
+ }
327
+ }
328
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
329
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
330
+ context.dispatchException(context.arg);
331
+ } else "return" === context.method && context.abrupt("return", context.arg);
332
+ state = "executing";
333
+ var record = tryCatch(innerFn, self, context);
334
+ if ("normal" === record.type) {
335
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
336
+ return {
337
+ value: record.arg,
338
+ done: context.done
339
+ };
340
+ }
341
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
342
+ }
343
+ };
344
+ }
345
+ function maybeInvokeDelegate(delegate, context) {
346
+ var methodName = context.method,
347
+ method = delegate.iterator[methodName];
348
+ if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
349
+ var record = tryCatch(method, delegate.iterator, context.arg);
350
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
351
+ var info = record.arg;
352
+ return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
353
+ }
354
+ function pushTryEntry(locs) {
355
+ var entry = {
356
+ tryLoc: locs[0]
357
+ };
358
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
359
+ }
360
+ function resetTryEntry(entry) {
361
+ var record = entry.completion || {};
362
+ record.type = "normal", delete record.arg, entry.completion = record;
363
+ }
364
+ function Context(tryLocsList) {
365
+ this.tryEntries = [{
366
+ tryLoc: "root"
367
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
368
+ }
369
+ function values(iterable) {
370
+ if (iterable) {
371
+ var iteratorMethod = iterable[iteratorSymbol];
372
+ if (iteratorMethod) return iteratorMethod.call(iterable);
373
+ if ("function" == typeof iterable.next) return iterable;
374
+ if (!isNaN(iterable.length)) {
375
+ var i = -1,
376
+ next = function next() {
377
+ for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
378
+ return next.value = undefined, next.done = !0, next;
379
+ };
380
+ return next.next = next;
381
+ }
382
+ }
383
+ return {
384
+ next: doneResult
385
+ };
386
+ }
387
+ function doneResult() {
388
+ return {
389
+ value: undefined,
390
+ done: !0
391
+ };
392
+ }
393
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
394
+ value: GeneratorFunctionPrototype,
395
+ configurable: !0
396
+ }), defineProperty(GeneratorFunctionPrototype, "constructor", {
397
+ value: GeneratorFunction,
398
+ configurable: !0
399
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
400
+ var ctor = "function" == typeof genFun && genFun.constructor;
401
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
402
+ }, exports.mark = function (genFun) {
403
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
404
+ }, exports.awrap = function (arg) {
405
+ return {
406
+ __await: arg
407
+ };
408
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
409
+ return this;
410
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
411
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
412
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
413
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
414
+ return result.done ? result.value : iter.next();
415
+ });
416
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
417
+ return this;
418
+ }), define(Gp, "toString", function () {
419
+ return "[object Generator]";
420
+ }), exports.keys = function (val) {
421
+ var object = Object(val),
422
+ keys = [];
423
+ for (var key in object) keys.push(key);
424
+ return keys.reverse(), function next() {
425
+ for (; keys.length;) {
426
+ var key = keys.pop();
427
+ if (key in object) return next.value = key, next.done = !1, next;
428
+ }
429
+ return next.done = !0, next;
430
+ };
431
+ }, exports.values = values, Context.prototype = {
432
+ constructor: Context,
433
+ reset: function reset(skipTempReset) {
434
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
435
+ },
436
+ stop: function stop() {
437
+ this.done = !0;
438
+ var rootRecord = this.tryEntries[0].completion;
439
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
440
+ return this.rval;
441
+ },
442
+ dispatchException: function dispatchException(exception) {
443
+ if (this.done) throw exception;
444
+ var context = this;
445
+ function handle(loc, caught) {
446
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
447
+ }
448
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
449
+ var entry = this.tryEntries[i],
450
+ record = entry.completion;
451
+ if ("root" === entry.tryLoc) return handle("end");
452
+ if (entry.tryLoc <= this.prev) {
453
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
454
+ hasFinally = hasOwn.call(entry, "finallyLoc");
455
+ if (hasCatch && hasFinally) {
456
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
457
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
458
+ } else if (hasCatch) {
459
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
460
+ } else {
461
+ if (!hasFinally) throw new Error("try statement without catch or finally");
462
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
463
+ }
464
+ }
465
+ }
466
+ },
467
+ abrupt: function abrupt(type, arg) {
468
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
469
+ var entry = this.tryEntries[i];
470
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
471
+ var finallyEntry = entry;
472
+ break;
473
+ }
474
+ }
475
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
476
+ var record = finallyEntry ? finallyEntry.completion : {};
477
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
478
+ },
479
+ complete: function complete(record, afterLoc) {
480
+ if ("throw" === record.type) throw record.arg;
481
+ return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
482
+ },
483
+ finish: function finish(finallyLoc) {
484
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
485
+ var entry = this.tryEntries[i];
486
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
487
+ }
488
+ },
489
+ "catch": function _catch(tryLoc) {
490
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
491
+ var entry = this.tryEntries[i];
492
+ if (entry.tryLoc === tryLoc) {
493
+ var record = entry.completion;
494
+ if ("throw" === record.type) {
495
+ var thrown = record.arg;
496
+ resetTryEntry(entry);
497
+ }
498
+ return thrown;
499
+ }
500
+ }
501
+ throw new Error("illegal catch attempt");
502
+ },
503
+ delegateYield: function delegateYield(iterable, resultName, nextLoc) {
504
+ return this.delegate = {
505
+ iterator: values(iterable),
506
+ resultName: resultName,
507
+ nextLoc: nextLoc
508
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
509
+ }
510
+ }, exports;
511
+ }
512
+ module.exports = _regeneratorRuntime, module.exports.__esModule = true, module.exports["default"] = module.exports;
513
+ } (regeneratorRuntime$1));
514
+
515
+ // TODO(Babel 8): Remove this file.
516
+
517
+ var runtime = regeneratorRuntime$1.exports();
518
+ var regenerator = runtime;
519
+
520
+ // Copied from https://github.com/facebook/regenerator/blob/main/packages/runtime/runtime.js#L736=
521
+ try {
522
+ regeneratorRuntime = runtime;
523
+ } catch (accidentalStrictMode) {
524
+ if (typeof globalThis === "object") {
525
+ globalThis.regeneratorRuntime = runtime;
526
+ } else {
527
+ Function("r", "regeneratorRuntime = r")(runtime);
528
+ }
529
+ }
530
+
531
+ var classnames$1 = {exports: {}};
532
+
533
+ /*!
534
+ Copyright (c) 2018 Jed Watson.
535
+ Licensed under the MIT License (MIT), see
536
+ http://jedwatson.github.io/classnames
537
+ */
538
+
539
+ (function (module) {
540
+ /* global define */
541
+
542
+ (function () {
543
+
544
+ var hasOwn = {}.hasOwnProperty;
545
+
546
+ function classNames() {
547
+ var classes = [];
548
+
549
+ for (var i = 0; i < arguments.length; i++) {
550
+ var arg = arguments[i];
551
+ if (!arg) continue;
552
+
553
+ var argType = typeof arg;
554
+
555
+ if (argType === 'string' || argType === 'number') {
556
+ classes.push(arg);
557
+ } else if (Array.isArray(arg)) {
558
+ if (arg.length) {
559
+ var inner = classNames.apply(null, arg);
560
+ if (inner) {
561
+ classes.push(inner);
562
+ }
563
+ }
564
+ } else if (argType === 'object') {
565
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {
566
+ classes.push(arg.toString());
567
+ continue;
568
+ }
569
+
570
+ for (var key in arg) {
571
+ if (hasOwn.call(arg, key) && arg[key]) {
572
+ classes.push(key);
573
+ }
574
+ }
575
+ }
576
+ }
577
+
578
+ return classes.join(' ');
579
+ }
580
+
581
+ if (module.exports) {
582
+ classNames.default = classNames;
583
+ module.exports = classNames;
584
+ } else {
585
+ window.classNames = classNames;
586
+ }
587
+ }());
588
+ } (classnames$1));
589
+
590
+ var classnames = classnames$1.exports;
591
+
592
+ var INITIAL_VALUES = {
593
+ sendFromEmail: "",
594
+ replyToEmail: "",
595
+ notifyEmails: [],
596
+ emailSubject: "",
597
+ emailBody: "",
598
+ isSendLaterEnabled: false,
599
+ sendEmailDatetime: undefined,
600
+ category: "email_share",
601
+ actionButtonText: ""
602
+ };
603
+ var EDITOR_ADDONS = ["emoji", "block-quote", "image-upload", "divider"];
604
+ var ALLOWED_FILE_PICKER_TYPES = [".csv"];
605
+
606
+ function _arrayWithoutHoles(arr) {
607
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
608
+ }
609
+
610
+ function _iterableToArray(iter) {
611
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
612
+ }
613
+
614
+ function _nonIterableSpread() {
615
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
616
+ }
617
+
618
+ function _toConsumableArray(arr) {
619
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
620
+ }
621
+
622
+ var EmailBody = function EmailBody(_ref, ref) {
623
+ var id = _ref.id,
624
+ showVideoEmbedInEditor = _ref.showVideoEmbedInEditor;
625
+ var _useTranslation = useTranslation(),
626
+ t = _useTranslation.t;
627
+ return /*#__PURE__*/React.createElement(FormikEditor, {
628
+ required: true,
629
+ className: "mb-6",
630
+ "data-cy": "email-body",
631
+ id: id,
632
+ label: t("neetoMolecules.shareViaEmail.emailBody"),
633
+ name: "emailBody",
634
+ ref: ref,
635
+ addons: showVideoEmbedInEditor ? [].concat(_toConsumableArray(EDITOR_ADDONS), ["video-embed"]) : EDITOR_ADDONS
636
+ });
637
+ };
638
+ var EmailBody$1 = /*#__PURE__*/forwardRef(EmailBody);
639
+
640
+ var FilePicker = function FilePicker(_ref) {
641
+ var _ref$types = _ref.types,
642
+ types = _ref$types === void 0 ? [] : _ref$types,
643
+ onChange = _ref.onChange;
644
+ var _useTranslation = useTranslation(),
645
+ t = _useTranslation.t;
646
+ var inputRef = useRef();
647
+ var accept = types.join(", ");
648
+ var handleInputChange = function handleInputChange(_ref2) {
649
+ var target = _ref2.target;
650
+ if (!target.files) return;
651
+ onChange(target.files);
652
+
653
+ // This will trigger handleClick when same file is uploaded again.
654
+ inputRef.current.value = "";
655
+ handleClick();
656
+ };
657
+ var handleClick = function handleClick() {
658
+ if (!inputRef.current) return;
659
+ inputRef.current.click();
660
+ };
661
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
662
+ icon: Upload,
663
+ label: t("neetoMolecules.shareViaEmail.uploadCsv"),
664
+ size: "small",
665
+ style: "link",
666
+ tooltipProps: {
667
+ content: t("neetoMolecules.shareViaEmail.uploadCsvTooltip")
668
+ },
669
+ onClick: handleClick
670
+ }), /*#__PURE__*/React.createElement("input", {
671
+ accept: accept,
672
+ className: "hidden",
673
+ ref: inputRef,
674
+ type: "file",
675
+ onChange: handleInputChange
676
+ }));
677
+ };
678
+ var FilePicker$1 = /*#__PURE__*/React.memo(FilePicker);
679
+
680
+ function _extends() {
681
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
682
+ for (var i = 1; i < arguments.length; i++) {
683
+ var source = arguments[i];
684
+ for (var key in source) {
685
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
686
+ target[key] = source[key];
687
+ }
688
+ }
689
+ }
690
+ return target;
691
+ };
692
+ return _extends.apply(this, arguments);
693
+ }
694
+
695
+ function _objectWithoutPropertiesLoose(source, excluded) {
696
+ if (source == null) return {};
697
+ var target = {};
698
+ var sourceKeys = Object.keys(source);
699
+ var key, i;
700
+ for (i = 0; i < sourceKeys.length; i++) {
701
+ key = sourceKeys[i];
702
+ if (excluded.indexOf(key) >= 0) continue;
703
+ target[key] = source[key];
704
+ }
705
+ return target;
706
+ }
707
+
708
+ function _objectWithoutProperties(source, excluded) {
709
+ if (source == null) return {};
710
+ var target = _objectWithoutPropertiesLoose(source, excluded);
711
+ var key, i;
712
+ if (Object.getOwnPropertySymbols) {
713
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
714
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
715
+ key = sourceSymbolKeys[i];
716
+ if (excluded.indexOf(key) >= 0) continue;
717
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
718
+ target[key] = source[key];
719
+ }
720
+ }
721
+ return target;
722
+ }
723
+
724
+ var _excluded = ["name"];
725
+ var FormikDatePicker = function FormikDatePicker(_ref) {
726
+ var name = _ref.name,
727
+ props = _objectWithoutProperties(_ref, _excluded);
728
+ var _useField = useField(name),
729
+ _useField2 = _slicedToArray(_useField, 3),
730
+ field = _useField2[0],
731
+ meta = _useField2[1],
732
+ setValue = _useField2[2].setValue;
733
+ return /*#__PURE__*/React.createElement(DatePicker, _extends({}, field, meta, {
734
+ onChange: function onChange(date) {
735
+ return setValue(date || undefined);
736
+ }
737
+ }, props, {
738
+ "data-cy": "email-share-date-input"
739
+ }));
740
+ };
741
+
742
+ function _typeof(obj) {
743
+ "@babel/helpers - typeof";
744
+
745
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
746
+ return typeof obj;
747
+ } : function (obj) {
748
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
749
+ }, _typeof(obj);
750
+ }
751
+
752
+ function _toPrimitive(input, hint) {
753
+ if (_typeof(input) !== "object" || input === null) return input;
754
+ var prim = input[Symbol.toPrimitive];
755
+ if (prim !== undefined) {
756
+ var res = prim.call(input, hint || "default");
757
+ if (_typeof(res) !== "object") return res;
758
+ throw new TypeError("@@toPrimitive must return a primitive value.");
759
+ }
760
+ return (hint === "string" ? String : Number)(input);
761
+ }
762
+
763
+ function _toPropertyKey(arg) {
764
+ var key = _toPrimitive(arg, "string");
765
+ return _typeof(key) === "symbol" ? key : String(key);
766
+ }
767
+
768
+ function _defineProperty(obj, key, value) {
769
+ key = _toPropertyKey(key);
770
+ if (key in obj) {
771
+ Object.defineProperty(obj, key, {
772
+ value: value,
773
+ enumerable: true,
774
+ configurable: true,
775
+ writable: true
776
+ });
777
+ } else {
778
+ obj[key] = value;
779
+ }
780
+ return obj;
781
+ }
782
+
783
+ var papaparse = {exports: {}};
784
+
785
+ /* @license
786
+ Papa Parse
787
+ v5.4.0
788
+ https://github.com/mholt/PapaParse
789
+ License: MIT
790
+ */
791
+
792
+ (function (module, exports) {
793
+ (function(root, factory)
794
+ {
795
+ /* globals define */
796
+ {
797
+ // Node. Does not work with strict CommonJS, but
798
+ // only CommonJS-like environments that support module.exports,
799
+ // like Node.
800
+ module.exports = factory();
801
+ }
802
+ // in strict mode we cannot access arguments.callee, so we need a named reference to
803
+ // stringify the factory method for the blob worker
804
+ // eslint-disable-next-line func-name
805
+ }(commonjsGlobal, function moduleFactory()
806
+ {
807
+
808
+ var global = (function() {
809
+ // alternative method, similar to `Function('return this')()`
810
+ // but without using `eval` (which is disabled when
811
+ // using Content Security Policy).
812
+
813
+ if (typeof self !== 'undefined') { return self; }
814
+ if (typeof window !== 'undefined') { return window; }
815
+ if (typeof global !== 'undefined') { return global; }
816
+
817
+ // When running tests none of the above have been defined
818
+ return {};
819
+ })();
820
+
821
+
822
+ function getWorkerBlob() {
823
+ var URL = global.URL || global.webkitURL || null;
824
+ var code = moduleFactory.toString();
825
+ return Papa.BLOB_URL || (Papa.BLOB_URL = URL.createObjectURL(new Blob(["var global = (function() { if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } return {}; })(); global.IS_PAPA_WORKER=true; ", '(', code, ')();'], {type: 'text/javascript'})));
826
+ }
827
+
828
+ var IS_WORKER = !global.document && !!global.postMessage,
829
+ IS_PAPA_WORKER = global.IS_PAPA_WORKER || false;
830
+
831
+ var workers = {}, workerIdCounter = 0;
832
+
833
+ var Papa = {};
834
+
835
+ Papa.parse = CsvToJson;
836
+ Papa.unparse = JsonToCsv;
837
+
838
+ Papa.RECORD_SEP = String.fromCharCode(30);
839
+ Papa.UNIT_SEP = String.fromCharCode(31);
840
+ Papa.BYTE_ORDER_MARK = '\ufeff';
841
+ Papa.BAD_DELIMITERS = ['\r', '\n', '"', Papa.BYTE_ORDER_MARK];
842
+ Papa.WORKERS_SUPPORTED = !IS_WORKER && !!global.Worker;
843
+ Papa.NODE_STREAM_INPUT = 1;
844
+
845
+ // Configurable chunk sizes for local and remote files, respectively
846
+ Papa.LocalChunkSize = 1024 * 1024 * 10; // 10 MB
847
+ Papa.RemoteChunkSize = 1024 * 1024 * 5; // 5 MB
848
+ Papa.DefaultDelimiter = ','; // Used if not specified and detection fails
849
+
850
+ // Exposed for testing and development only
851
+ Papa.Parser = Parser;
852
+ Papa.ParserHandle = ParserHandle;
853
+ Papa.NetworkStreamer = NetworkStreamer;
854
+ Papa.FileStreamer = FileStreamer;
855
+ Papa.StringStreamer = StringStreamer;
856
+ Papa.ReadableStreamStreamer = ReadableStreamStreamer;
857
+ if (typeof PAPA_BROWSER_CONTEXT === 'undefined') {
858
+ Papa.DuplexStreamStreamer = DuplexStreamStreamer;
859
+ }
860
+
861
+ if (global.jQuery)
862
+ {
863
+ var $ = global.jQuery;
864
+ $.fn.parse = function(options)
865
+ {
866
+ var config = options.config || {};
867
+ var queue = [];
868
+
869
+ this.each(function(idx)
870
+ {
871
+ var supported = $(this).prop('tagName').toUpperCase() === 'INPUT'
872
+ && $(this).attr('type').toLowerCase() === 'file'
873
+ && global.FileReader;
874
+
875
+ if (!supported || !this.files || this.files.length === 0)
876
+ return true; // continue to next input element
877
+
878
+ for (var i = 0; i < this.files.length; i++)
879
+ {
880
+ queue.push({
881
+ file: this.files[i],
882
+ inputElem: this,
883
+ instanceConfig: $.extend({}, config)
884
+ });
885
+ }
886
+ });
887
+
888
+ parseNextFile(); // begin parsing
889
+ return this; // maintains chainability
890
+
891
+
892
+ function parseNextFile()
893
+ {
894
+ if (queue.length === 0)
895
+ {
896
+ if (isFunction(options.complete))
897
+ options.complete();
898
+ return;
899
+ }
900
+
901
+ var f = queue[0];
902
+
903
+ if (isFunction(options.before))
904
+ {
905
+ var returned = options.before(f.file, f.inputElem);
906
+
907
+ if (typeof returned === 'object')
908
+ {
909
+ if (returned.action === 'abort')
910
+ {
911
+ error('AbortError', f.file, f.inputElem, returned.reason);
912
+ return; // Aborts all queued files immediately
913
+ }
914
+ else if (returned.action === 'skip')
915
+ {
916
+ fileComplete(); // parse the next file in the queue, if any
917
+ return;
918
+ }
919
+ else if (typeof returned.config === 'object')
920
+ f.instanceConfig = $.extend(f.instanceConfig, returned.config);
921
+ }
922
+ else if (returned === 'skip')
923
+ {
924
+ fileComplete(); // parse the next file in the queue, if any
925
+ return;
926
+ }
927
+ }
928
+
929
+ // Wrap up the user's complete callback, if any, so that ours also gets executed
930
+ var userCompleteFunc = f.instanceConfig.complete;
931
+ f.instanceConfig.complete = function(results)
932
+ {
933
+ if (isFunction(userCompleteFunc))
934
+ userCompleteFunc(results, f.file, f.inputElem);
935
+ fileComplete();
936
+ };
937
+
938
+ Papa.parse(f.file, f.instanceConfig);
939
+ }
940
+
941
+ function error(name, file, elem, reason)
942
+ {
943
+ if (isFunction(options.error))
944
+ options.error({name: name}, file, elem, reason);
945
+ }
946
+
947
+ function fileComplete()
948
+ {
949
+ queue.splice(0, 1);
950
+ parseNextFile();
951
+ }
952
+ };
953
+ }
954
+
955
+
956
+ if (IS_PAPA_WORKER)
957
+ {
958
+ global.onmessage = workerThreadReceivedMessage;
959
+ }
960
+
961
+
962
+
963
+
964
+ function CsvToJson(_input, _config)
965
+ {
966
+ _config = _config || {};
967
+ var dynamicTyping = _config.dynamicTyping || false;
968
+ if (isFunction(dynamicTyping)) {
969
+ _config.dynamicTypingFunction = dynamicTyping;
970
+ // Will be filled on first row call
971
+ dynamicTyping = {};
972
+ }
973
+ _config.dynamicTyping = dynamicTyping;
974
+
975
+ _config.transform = isFunction(_config.transform) ? _config.transform : false;
976
+
977
+ if (_config.worker && Papa.WORKERS_SUPPORTED)
978
+ {
979
+ var w = newWorker();
980
+
981
+ w.userStep = _config.step;
982
+ w.userChunk = _config.chunk;
983
+ w.userComplete = _config.complete;
984
+ w.userError = _config.error;
985
+
986
+ _config.step = isFunction(_config.step);
987
+ _config.chunk = isFunction(_config.chunk);
988
+ _config.complete = isFunction(_config.complete);
989
+ _config.error = isFunction(_config.error);
990
+ delete _config.worker; // prevent infinite loop
991
+
992
+ w.postMessage({
993
+ input: _input,
994
+ config: _config,
995
+ workerId: w.id
996
+ });
997
+
998
+ return;
999
+ }
1000
+
1001
+ var streamer = null;
1002
+ if (_input === Papa.NODE_STREAM_INPUT && typeof PAPA_BROWSER_CONTEXT === 'undefined')
1003
+ {
1004
+ // create a node Duplex stream for use
1005
+ // with .pipe
1006
+ streamer = new DuplexStreamStreamer(_config);
1007
+ return streamer.getStream();
1008
+ }
1009
+ else if (typeof _input === 'string')
1010
+ {
1011
+ _input = stripBom(_input);
1012
+ if (_config.download)
1013
+ streamer = new NetworkStreamer(_config);
1014
+ else
1015
+ streamer = new StringStreamer(_config);
1016
+ }
1017
+ else if (_input.readable === true && isFunction(_input.read) && isFunction(_input.on))
1018
+ {
1019
+ streamer = new ReadableStreamStreamer(_config);
1020
+ }
1021
+ else if ((global.File && _input instanceof File) || _input instanceof Object) // ...Safari. (see issue #106)
1022
+ streamer = new FileStreamer(_config);
1023
+
1024
+ return streamer.stream(_input);
1025
+
1026
+ // Strip character from UTF-8 BOM encoded files that cause issue parsing the file
1027
+ function stripBom(string) {
1028
+ if (string.charCodeAt(0) === 0xfeff) {
1029
+ return string.slice(1);
1030
+ }
1031
+ return string;
1032
+ }
1033
+ }
1034
+
1035
+
1036
+
1037
+
1038
+
1039
+
1040
+ function JsonToCsv(_input, _config)
1041
+ {
1042
+ // Default configuration
1043
+
1044
+ /** whether to surround every datum with quotes */
1045
+ var _quotes = false;
1046
+
1047
+ /** whether to write headers */
1048
+ var _writeHeader = true;
1049
+
1050
+ /** delimiting character(s) */
1051
+ var _delimiter = ',';
1052
+
1053
+ /** newline character(s) */
1054
+ var _newline = '\r\n';
1055
+
1056
+ /** quote character */
1057
+ var _quoteChar = '"';
1058
+
1059
+ /** escaped quote character, either "" or <config.escapeChar>" */
1060
+ var _escapedQuote = _quoteChar + _quoteChar;
1061
+
1062
+ /** whether to skip empty lines */
1063
+ var _skipEmptyLines = false;
1064
+
1065
+ /** the columns (keys) we expect when we unparse objects */
1066
+ var _columns = null;
1067
+
1068
+ /** whether to prevent outputting cells that can be parsed as formulae by spreadsheet software (Excel and LibreOffice) */
1069
+ var _escapeFormulae = false;
1070
+
1071
+ unpackConfig();
1072
+
1073
+ var quoteCharRegex = new RegExp(escapeRegExp(_quoteChar), 'g');
1074
+
1075
+ if (typeof _input === 'string')
1076
+ _input = JSON.parse(_input);
1077
+
1078
+ if (Array.isArray(_input))
1079
+ {
1080
+ if (!_input.length || Array.isArray(_input[0]))
1081
+ return serialize(null, _input, _skipEmptyLines);
1082
+ else if (typeof _input[0] === 'object')
1083
+ return serialize(_columns || Object.keys(_input[0]), _input, _skipEmptyLines);
1084
+ }
1085
+ else if (typeof _input === 'object')
1086
+ {
1087
+ if (typeof _input.data === 'string')
1088
+ _input.data = JSON.parse(_input.data);
1089
+
1090
+ if (Array.isArray(_input.data))
1091
+ {
1092
+ if (!_input.fields)
1093
+ _input.fields = _input.meta && _input.meta.fields || _columns;
1094
+
1095
+ if (!_input.fields)
1096
+ _input.fields = Array.isArray(_input.data[0])
1097
+ ? _input.fields
1098
+ : typeof _input.data[0] === 'object'
1099
+ ? Object.keys(_input.data[0])
1100
+ : [];
1101
+
1102
+ if (!(Array.isArray(_input.data[0])) && typeof _input.data[0] !== 'object')
1103
+ _input.data = [_input.data]; // handles input like [1,2,3] or ['asdf']
1104
+ }
1105
+
1106
+ return serialize(_input.fields || [], _input.data || [], _skipEmptyLines);
1107
+ }
1108
+
1109
+ // Default (any valid paths should return before this)
1110
+ throw new Error('Unable to serialize unrecognized input');
1111
+
1112
+
1113
+ function unpackConfig()
1114
+ {
1115
+ if (typeof _config !== 'object')
1116
+ return;
1117
+
1118
+ if (typeof _config.delimiter === 'string'
1119
+ && !Papa.BAD_DELIMITERS.filter(function(value) { return _config.delimiter.indexOf(value) !== -1; }).length)
1120
+ {
1121
+ _delimiter = _config.delimiter;
1122
+ }
1123
+
1124
+ if (typeof _config.quotes === 'boolean'
1125
+ || typeof _config.quotes === 'function'
1126
+ || Array.isArray(_config.quotes))
1127
+ _quotes = _config.quotes;
1128
+
1129
+ if (typeof _config.skipEmptyLines === 'boolean'
1130
+ || typeof _config.skipEmptyLines === 'string')
1131
+ _skipEmptyLines = _config.skipEmptyLines;
1132
+
1133
+ if (typeof _config.newline === 'string')
1134
+ _newline = _config.newline;
1135
+
1136
+ if (typeof _config.quoteChar === 'string')
1137
+ _quoteChar = _config.quoteChar;
1138
+
1139
+ if (typeof _config.header === 'boolean')
1140
+ _writeHeader = _config.header;
1141
+
1142
+ if (Array.isArray(_config.columns)) {
1143
+
1144
+ if (_config.columns.length === 0) throw new Error('Option columns is empty');
1145
+
1146
+ _columns = _config.columns;
1147
+ }
1148
+
1149
+ if (_config.escapeChar !== undefined) {
1150
+ _escapedQuote = _config.escapeChar + _quoteChar;
1151
+ }
1152
+
1153
+ if (typeof _config.escapeFormulae === 'boolean' || _config.escapeFormulae instanceof RegExp) {
1154
+ _escapeFormulae = _config.escapeFormulae instanceof RegExp ? _config.escapeFormulae : /^[=+\-@\t\r].*$/;
1155
+ }
1156
+ }
1157
+
1158
+ /** The double for loop that iterates the data and writes out a CSV string including header row */
1159
+ function serialize(fields, data, skipEmptyLines)
1160
+ {
1161
+ var csv = '';
1162
+
1163
+ if (typeof fields === 'string')
1164
+ fields = JSON.parse(fields);
1165
+ if (typeof data === 'string')
1166
+ data = JSON.parse(data);
1167
+
1168
+ var hasHeader = Array.isArray(fields) && fields.length > 0;
1169
+ var dataKeyedByField = !(Array.isArray(data[0]));
1170
+
1171
+ // If there a header row, write it first
1172
+ if (hasHeader && _writeHeader)
1173
+ {
1174
+ for (var i = 0; i < fields.length; i++)
1175
+ {
1176
+ if (i > 0)
1177
+ csv += _delimiter;
1178
+ csv += safe(fields[i], i);
1179
+ }
1180
+ if (data.length > 0)
1181
+ csv += _newline;
1182
+ }
1183
+
1184
+ // Then write out the data
1185
+ for (var row = 0; row < data.length; row++)
1186
+ {
1187
+ var maxCol = hasHeader ? fields.length : data[row].length;
1188
+
1189
+ var emptyLine = false;
1190
+ var nullLine = hasHeader ? Object.keys(data[row]).length === 0 : data[row].length === 0;
1191
+ if (skipEmptyLines && !hasHeader)
1192
+ {
1193
+ emptyLine = skipEmptyLines === 'greedy' ? data[row].join('').trim() === '' : data[row].length === 1 && data[row][0].length === 0;
1194
+ }
1195
+ if (skipEmptyLines === 'greedy' && hasHeader) {
1196
+ var line = [];
1197
+ for (var c = 0; c < maxCol; c++) {
1198
+ var cx = dataKeyedByField ? fields[c] : c;
1199
+ line.push(data[row][cx]);
1200
+ }
1201
+ emptyLine = line.join('').trim() === '';
1202
+ }
1203
+ if (!emptyLine)
1204
+ {
1205
+ for (var col = 0; col < maxCol; col++)
1206
+ {
1207
+ if (col > 0 && !nullLine)
1208
+ csv += _delimiter;
1209
+ var colIdx = hasHeader && dataKeyedByField ? fields[col] : col;
1210
+ csv += safe(data[row][colIdx], col);
1211
+ }
1212
+ if (row < data.length - 1 && (!skipEmptyLines || (maxCol > 0 && !nullLine)))
1213
+ {
1214
+ csv += _newline;
1215
+ }
1216
+ }
1217
+ }
1218
+ return csv;
1219
+ }
1220
+
1221
+ /** Encloses a value around quotes if needed (makes a value safe for CSV insertion) */
1222
+ function safe(str, col)
1223
+ {
1224
+ if (typeof str === 'undefined' || str === null)
1225
+ return '';
1226
+
1227
+ if (str.constructor === Date)
1228
+ return JSON.stringify(str).slice(1, 25);
1229
+
1230
+ var needsQuotes = false;
1231
+
1232
+ if (_escapeFormulae && typeof str === "string" && _escapeFormulae.test(str)) {
1233
+ str = "'" + str;
1234
+ needsQuotes = true;
1235
+ }
1236
+
1237
+ var escapedQuoteStr = str.toString().replace(quoteCharRegex, _escapedQuote);
1238
+
1239
+ needsQuotes = needsQuotes
1240
+ || _quotes === true
1241
+ || (typeof _quotes === 'function' && _quotes(str, col))
1242
+ || (Array.isArray(_quotes) && _quotes[col])
1243
+ || hasAny(escapedQuoteStr, Papa.BAD_DELIMITERS)
1244
+ || escapedQuoteStr.indexOf(_delimiter) > -1
1245
+ || escapedQuoteStr.charAt(0) === ' '
1246
+ || escapedQuoteStr.charAt(escapedQuoteStr.length - 1) === ' ';
1247
+
1248
+ return needsQuotes ? _quoteChar + escapedQuoteStr + _quoteChar : escapedQuoteStr;
1249
+ }
1250
+
1251
+ function hasAny(str, substrings)
1252
+ {
1253
+ for (var i = 0; i < substrings.length; i++)
1254
+ if (str.indexOf(substrings[i]) > -1)
1255
+ return true;
1256
+ return false;
1257
+ }
1258
+ }
1259
+
1260
+ /** ChunkStreamer is the base prototype for various streamer implementations. */
1261
+ function ChunkStreamer(config)
1262
+ {
1263
+ this._handle = null;
1264
+ this._finished = false;
1265
+ this._completed = false;
1266
+ this._halted = false;
1267
+ this._input = null;
1268
+ this._baseIndex = 0;
1269
+ this._partialLine = '';
1270
+ this._rowCount = 0;
1271
+ this._start = 0;
1272
+ this._nextChunk = null;
1273
+ this.isFirstChunk = true;
1274
+ this._completeResults = {
1275
+ data: [],
1276
+ errors: [],
1277
+ meta: {}
1278
+ };
1279
+ replaceConfig.call(this, config);
1280
+
1281
+ this.parseChunk = function(chunk, isFakeChunk)
1282
+ {
1283
+ // First chunk pre-processing
1284
+ if (this.isFirstChunk && isFunction(this._config.beforeFirstChunk))
1285
+ {
1286
+ var modifiedChunk = this._config.beforeFirstChunk(chunk);
1287
+ if (modifiedChunk !== undefined)
1288
+ chunk = modifiedChunk;
1289
+ }
1290
+ this.isFirstChunk = false;
1291
+ this._halted = false;
1292
+
1293
+ // Rejoin the line we likely just split in two by chunking the file
1294
+ var aggregate = this._partialLine + chunk;
1295
+ this._partialLine = '';
1296
+
1297
+ var results = this._handle.parse(aggregate, this._baseIndex, !this._finished);
1298
+
1299
+ if (this._handle.paused() || this._handle.aborted()) {
1300
+ this._halted = true;
1301
+ return;
1302
+ }
1303
+
1304
+ var lastIndex = results.meta.cursor;
1305
+
1306
+ if (!this._finished)
1307
+ {
1308
+ this._partialLine = aggregate.substring(lastIndex - this._baseIndex);
1309
+ this._baseIndex = lastIndex;
1310
+ }
1311
+
1312
+ if (results && results.data)
1313
+ this._rowCount += results.data.length;
1314
+
1315
+ var finishedIncludingPreview = this._finished || (this._config.preview && this._rowCount >= this._config.preview);
1316
+
1317
+ if (IS_PAPA_WORKER)
1318
+ {
1319
+ global.postMessage({
1320
+ results: results,
1321
+ workerId: Papa.WORKER_ID,
1322
+ finished: finishedIncludingPreview
1323
+ });
1324
+ }
1325
+ else if (isFunction(this._config.chunk) && !isFakeChunk)
1326
+ {
1327
+ this._config.chunk(results, this._handle);
1328
+ if (this._handle.paused() || this._handle.aborted()) {
1329
+ this._halted = true;
1330
+ return;
1331
+ }
1332
+ results = undefined;
1333
+ this._completeResults = undefined;
1334
+ }
1335
+
1336
+ if (!this._config.step && !this._config.chunk) {
1337
+ this._completeResults.data = this._completeResults.data.concat(results.data);
1338
+ this._completeResults.errors = this._completeResults.errors.concat(results.errors);
1339
+ this._completeResults.meta = results.meta;
1340
+ }
1341
+
1342
+ if (!this._completed && finishedIncludingPreview && isFunction(this._config.complete) && (!results || !results.meta.aborted)) {
1343
+ this._config.complete(this._completeResults, this._input);
1344
+ this._completed = true;
1345
+ }
1346
+
1347
+ if (!finishedIncludingPreview && (!results || !results.meta.paused))
1348
+ this._nextChunk();
1349
+
1350
+ return results;
1351
+ };
1352
+
1353
+ this._sendError = function(error)
1354
+ {
1355
+ if (isFunction(this._config.error))
1356
+ this._config.error(error);
1357
+ else if (IS_PAPA_WORKER && this._config.error)
1358
+ {
1359
+ global.postMessage({
1360
+ workerId: Papa.WORKER_ID,
1361
+ error: error,
1362
+ finished: false
1363
+ });
1364
+ }
1365
+ };
1366
+
1367
+ function replaceConfig(config)
1368
+ {
1369
+ // Deep-copy the config so we can edit it
1370
+ var configCopy = copy(config);
1371
+ configCopy.chunkSize = parseInt(configCopy.chunkSize); // parseInt VERY important so we don't concatenate strings!
1372
+ if (!config.step && !config.chunk)
1373
+ configCopy.chunkSize = null; // disable Range header if not streaming; bad values break IIS - see issue #196
1374
+ this._handle = new ParserHandle(configCopy);
1375
+ this._handle.streamer = this;
1376
+ this._config = configCopy; // persist the copy to the caller
1377
+ }
1378
+ }
1379
+
1380
+
1381
+ function NetworkStreamer(config)
1382
+ {
1383
+ config = config || {};
1384
+ if (!config.chunkSize)
1385
+ config.chunkSize = Papa.RemoteChunkSize;
1386
+ ChunkStreamer.call(this, config);
1387
+
1388
+ var xhr;
1389
+
1390
+ if (IS_WORKER)
1391
+ {
1392
+ this._nextChunk = function()
1393
+ {
1394
+ this._readChunk();
1395
+ this._chunkLoaded();
1396
+ };
1397
+ }
1398
+ else
1399
+ {
1400
+ this._nextChunk = function()
1401
+ {
1402
+ this._readChunk();
1403
+ };
1404
+ }
1405
+
1406
+ this.stream = function(url)
1407
+ {
1408
+ this._input = url;
1409
+ this._nextChunk(); // Starts streaming
1410
+ };
1411
+
1412
+ this._readChunk = function()
1413
+ {
1414
+ if (this._finished)
1415
+ {
1416
+ this._chunkLoaded();
1417
+ return;
1418
+ }
1419
+
1420
+ xhr = new XMLHttpRequest();
1421
+
1422
+ if (this._config.withCredentials)
1423
+ {
1424
+ xhr.withCredentials = this._config.withCredentials;
1425
+ }
1426
+
1427
+ if (!IS_WORKER)
1428
+ {
1429
+ xhr.onload = bindFunction(this._chunkLoaded, this);
1430
+ xhr.onerror = bindFunction(this._chunkError, this);
1431
+ }
1432
+
1433
+ xhr.open(this._config.downloadRequestBody ? 'POST' : 'GET', this._input, !IS_WORKER);
1434
+ // Headers can only be set when once the request state is OPENED
1435
+ if (this._config.downloadRequestHeaders)
1436
+ {
1437
+ var headers = this._config.downloadRequestHeaders;
1438
+
1439
+ for (var headerName in headers)
1440
+ {
1441
+ xhr.setRequestHeader(headerName, headers[headerName]);
1442
+ }
1443
+ }
1444
+
1445
+ if (this._config.chunkSize)
1446
+ {
1447
+ var end = this._start + this._config.chunkSize - 1; // minus one because byte range is inclusive
1448
+ xhr.setRequestHeader('Range', 'bytes=' + this._start + '-' + end);
1449
+ }
1450
+
1451
+ try {
1452
+ xhr.send(this._config.downloadRequestBody);
1453
+ }
1454
+ catch (err) {
1455
+ this._chunkError(err.message);
1456
+ }
1457
+
1458
+ if (IS_WORKER && xhr.status === 0)
1459
+ this._chunkError();
1460
+ };
1461
+
1462
+ this._chunkLoaded = function()
1463
+ {
1464
+ if (xhr.readyState !== 4)
1465
+ return;
1466
+
1467
+ if (xhr.status < 200 || xhr.status >= 400)
1468
+ {
1469
+ this._chunkError();
1470
+ return;
1471
+ }
1472
+
1473
+ // Use chunckSize as it may be a diference on reponse lentgh due to characters with more than 1 byte
1474
+ this._start += this._config.chunkSize ? this._config.chunkSize : xhr.responseText.length;
1475
+ this._finished = !this._config.chunkSize || this._start >= getFileSize(xhr);
1476
+ this.parseChunk(xhr.responseText);
1477
+ };
1478
+
1479
+ this._chunkError = function(errorMessage)
1480
+ {
1481
+ var errorText = xhr.statusText || errorMessage;
1482
+ this._sendError(new Error(errorText));
1483
+ };
1484
+
1485
+ function getFileSize(xhr)
1486
+ {
1487
+ var contentRange = xhr.getResponseHeader('Content-Range');
1488
+ if (contentRange === null) { // no content range, then finish!
1489
+ return -1;
1490
+ }
1491
+ return parseInt(contentRange.substring(contentRange.lastIndexOf('/') + 1));
1492
+ }
1493
+ }
1494
+ NetworkStreamer.prototype = Object.create(ChunkStreamer.prototype);
1495
+ NetworkStreamer.prototype.constructor = NetworkStreamer;
1496
+
1497
+
1498
+ function FileStreamer(config)
1499
+ {
1500
+ config = config || {};
1501
+ if (!config.chunkSize)
1502
+ config.chunkSize = Papa.LocalChunkSize;
1503
+ ChunkStreamer.call(this, config);
1504
+
1505
+ var reader, slice;
1506
+
1507
+ // FileReader is better than FileReaderSync (even in worker) - see http://stackoverflow.com/q/24708649/1048862
1508
+ // But Firefox is a pill, too - see issue #76: https://github.com/mholt/PapaParse/issues/76
1509
+ var usingAsyncReader = typeof FileReader !== 'undefined'; // Safari doesn't consider it a function - see issue #105
1510
+
1511
+ this.stream = function(file)
1512
+ {
1513
+ this._input = file;
1514
+ slice = file.slice || file.webkitSlice || file.mozSlice;
1515
+
1516
+ if (usingAsyncReader)
1517
+ {
1518
+ reader = new FileReader(); // Preferred method of reading files, even in workers
1519
+ reader.onload = bindFunction(this._chunkLoaded, this);
1520
+ reader.onerror = bindFunction(this._chunkError, this);
1521
+ }
1522
+ else
1523
+ reader = new FileReaderSync(); // Hack for running in a web worker in Firefox
1524
+
1525
+ this._nextChunk(); // Starts streaming
1526
+ };
1527
+
1528
+ this._nextChunk = function()
1529
+ {
1530
+ if (!this._finished && (!this._config.preview || this._rowCount < this._config.preview))
1531
+ this._readChunk();
1532
+ };
1533
+
1534
+ this._readChunk = function()
1535
+ {
1536
+ var input = this._input;
1537
+ if (this._config.chunkSize)
1538
+ {
1539
+ var end = Math.min(this._start + this._config.chunkSize, this._input.size);
1540
+ input = slice.call(input, this._start, end);
1541
+ }
1542
+ var txt = reader.readAsText(input, this._config.encoding);
1543
+ if (!usingAsyncReader)
1544
+ this._chunkLoaded({ target: { result: txt } }); // mimic the async signature
1545
+ };
1546
+
1547
+ this._chunkLoaded = function(event)
1548
+ {
1549
+ // Very important to increment start each time before handling results
1550
+ this._start += this._config.chunkSize;
1551
+ this._finished = !this._config.chunkSize || this._start >= this._input.size;
1552
+ this.parseChunk(event.target.result);
1553
+ };
1554
+
1555
+ this._chunkError = function()
1556
+ {
1557
+ this._sendError(reader.error);
1558
+ };
1559
+
1560
+ }
1561
+ FileStreamer.prototype = Object.create(ChunkStreamer.prototype);
1562
+ FileStreamer.prototype.constructor = FileStreamer;
1563
+
1564
+
1565
+ function StringStreamer(config)
1566
+ {
1567
+ config = config || {};
1568
+ ChunkStreamer.call(this, config);
1569
+
1570
+ var remaining;
1571
+ this.stream = function(s)
1572
+ {
1573
+ remaining = s;
1574
+ return this._nextChunk();
1575
+ };
1576
+ this._nextChunk = function()
1577
+ {
1578
+ if (this._finished) return;
1579
+ var size = this._config.chunkSize;
1580
+ var chunk;
1581
+ if(size) {
1582
+ chunk = remaining.substring(0, size);
1583
+ remaining = remaining.substring(size);
1584
+ } else {
1585
+ chunk = remaining;
1586
+ remaining = '';
1587
+ }
1588
+ this._finished = !remaining;
1589
+ return this.parseChunk(chunk);
1590
+ };
1591
+ }
1592
+ StringStreamer.prototype = Object.create(StringStreamer.prototype);
1593
+ StringStreamer.prototype.constructor = StringStreamer;
1594
+
1595
+
1596
+ function ReadableStreamStreamer(config)
1597
+ {
1598
+ config = config || {};
1599
+
1600
+ ChunkStreamer.call(this, config);
1601
+
1602
+ var queue = [];
1603
+ var parseOnData = true;
1604
+ var streamHasEnded = false;
1605
+
1606
+ this.pause = function()
1607
+ {
1608
+ ChunkStreamer.prototype.pause.apply(this, arguments);
1609
+ this._input.pause();
1610
+ };
1611
+
1612
+ this.resume = function()
1613
+ {
1614
+ ChunkStreamer.prototype.resume.apply(this, arguments);
1615
+ this._input.resume();
1616
+ };
1617
+
1618
+ this.stream = function(stream)
1619
+ {
1620
+ this._input = stream;
1621
+
1622
+ this._input.on('data', this._streamData);
1623
+ this._input.on('end', this._streamEnd);
1624
+ this._input.on('error', this._streamError);
1625
+ };
1626
+
1627
+ this._checkIsFinished = function()
1628
+ {
1629
+ if (streamHasEnded && queue.length === 1) {
1630
+ this._finished = true;
1631
+ }
1632
+ };
1633
+
1634
+ this._nextChunk = function()
1635
+ {
1636
+ this._checkIsFinished();
1637
+ if (queue.length)
1638
+ {
1639
+ this.parseChunk(queue.shift());
1640
+ }
1641
+ else
1642
+ {
1643
+ parseOnData = true;
1644
+ }
1645
+ };
1646
+
1647
+ this._streamData = bindFunction(function(chunk)
1648
+ {
1649
+ try
1650
+ {
1651
+ queue.push(typeof chunk === 'string' ? chunk : chunk.toString(this._config.encoding));
1652
+
1653
+ if (parseOnData)
1654
+ {
1655
+ parseOnData = false;
1656
+ this._checkIsFinished();
1657
+ this.parseChunk(queue.shift());
1658
+ }
1659
+ }
1660
+ catch (error)
1661
+ {
1662
+ this._streamError(error);
1663
+ }
1664
+ }, this);
1665
+
1666
+ this._streamError = bindFunction(function(error)
1667
+ {
1668
+ this._streamCleanUp();
1669
+ this._sendError(error);
1670
+ }, this);
1671
+
1672
+ this._streamEnd = bindFunction(function()
1673
+ {
1674
+ this._streamCleanUp();
1675
+ streamHasEnded = true;
1676
+ this._streamData('');
1677
+ }, this);
1678
+
1679
+ this._streamCleanUp = bindFunction(function()
1680
+ {
1681
+ this._input.removeListener('data', this._streamData);
1682
+ this._input.removeListener('end', this._streamEnd);
1683
+ this._input.removeListener('error', this._streamError);
1684
+ }, this);
1685
+ }
1686
+ ReadableStreamStreamer.prototype = Object.create(ChunkStreamer.prototype);
1687
+ ReadableStreamStreamer.prototype.constructor = ReadableStreamStreamer;
1688
+
1689
+
1690
+ function DuplexStreamStreamer(_config) {
1691
+ var Duplex = require$$0.Duplex;
1692
+ var config = copy(_config);
1693
+ var parseOnWrite = true;
1694
+ var writeStreamHasFinished = false;
1695
+ var parseCallbackQueue = [];
1696
+ var stream = null;
1697
+
1698
+ this._onCsvData = function(results)
1699
+ {
1700
+ var data = results.data;
1701
+ if (!stream.push(data) && !this._handle.paused()) {
1702
+ // the writeable consumer buffer has filled up
1703
+ // so we need to pause until more items
1704
+ // can be processed
1705
+ this._handle.pause();
1706
+ }
1707
+ };
1708
+
1709
+ this._onCsvComplete = function()
1710
+ {
1711
+ // node will finish the read stream when
1712
+ // null is pushed
1713
+ stream.push(null);
1714
+ };
1715
+
1716
+ config.step = bindFunction(this._onCsvData, this);
1717
+ config.complete = bindFunction(this._onCsvComplete, this);
1718
+ ChunkStreamer.call(this, config);
1719
+
1720
+ this._nextChunk = function()
1721
+ {
1722
+ if (writeStreamHasFinished && parseCallbackQueue.length === 1) {
1723
+ this._finished = true;
1724
+ }
1725
+ if (parseCallbackQueue.length) {
1726
+ parseCallbackQueue.shift()();
1727
+ } else {
1728
+ parseOnWrite = true;
1729
+ }
1730
+ };
1731
+
1732
+ this._addToParseQueue = function(chunk, callback)
1733
+ {
1734
+ // add to queue so that we can indicate
1735
+ // completion via callback
1736
+ // node will automatically pause the incoming stream
1737
+ // when too many items have been added without their
1738
+ // callback being invoked
1739
+ parseCallbackQueue.push(bindFunction(function() {
1740
+ this.parseChunk(typeof chunk === 'string' ? chunk : chunk.toString(config.encoding));
1741
+ if (isFunction(callback)) {
1742
+ return callback();
1743
+ }
1744
+ }, this));
1745
+ if (parseOnWrite) {
1746
+ parseOnWrite = false;
1747
+ this._nextChunk();
1748
+ }
1749
+ };
1750
+
1751
+ this._onRead = function()
1752
+ {
1753
+ if (this._handle.paused()) {
1754
+ // the writeable consumer can handle more data
1755
+ // so resume the chunk parsing
1756
+ this._handle.resume();
1757
+ }
1758
+ };
1759
+
1760
+ this._onWrite = function(chunk, encoding, callback)
1761
+ {
1762
+ this._addToParseQueue(chunk, callback);
1763
+ };
1764
+
1765
+ this._onWriteComplete = function()
1766
+ {
1767
+ writeStreamHasFinished = true;
1768
+ // have to write empty string
1769
+ // so parser knows its done
1770
+ this._addToParseQueue('');
1771
+ };
1772
+
1773
+ this.getStream = function()
1774
+ {
1775
+ return stream;
1776
+ };
1777
+ stream = new Duplex({
1778
+ readableObjectMode: true,
1779
+ decodeStrings: false,
1780
+ read: bindFunction(this._onRead, this),
1781
+ write: bindFunction(this._onWrite, this)
1782
+ });
1783
+ stream.once('finish', bindFunction(this._onWriteComplete, this));
1784
+ }
1785
+ if (typeof PAPA_BROWSER_CONTEXT === 'undefined') {
1786
+ DuplexStreamStreamer.prototype = Object.create(ChunkStreamer.prototype);
1787
+ DuplexStreamStreamer.prototype.constructor = DuplexStreamStreamer;
1788
+ }
1789
+
1790
+
1791
+ // Use one ParserHandle per entire CSV file or string
1792
+ function ParserHandle(_config)
1793
+ {
1794
+ // One goal is to minimize the use of regular expressions...
1795
+ var MAX_FLOAT = Math.pow(2, 53);
1796
+ var MIN_FLOAT = -MAX_FLOAT;
1797
+ var FLOAT = /^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/;
1798
+ var ISO_DATE = /^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/;
1799
+ var self = this;
1800
+ var _stepCounter = 0; // Number of times step was called (number of rows parsed)
1801
+ var _rowCounter = 0; // Number of rows that have been parsed so far
1802
+ var _input; // The input being parsed
1803
+ var _parser; // The core parser being used
1804
+ var _paused = false; // Whether we are paused or not
1805
+ var _aborted = false; // Whether the parser has aborted or not
1806
+ var _delimiterError; // Temporary state between delimiter detection and processing results
1807
+ var _fields = []; // Fields are from the header row of the input, if there is one
1808
+ var _results = { // The last results returned from the parser
1809
+ data: [],
1810
+ errors: [],
1811
+ meta: {}
1812
+ };
1813
+
1814
+ if (isFunction(_config.step))
1815
+ {
1816
+ var userStep = _config.step;
1817
+ _config.step = function(results)
1818
+ {
1819
+ _results = results;
1820
+
1821
+ if (needsHeaderRow())
1822
+ processResults();
1823
+ else // only call user's step function after header row
1824
+ {
1825
+ processResults();
1826
+
1827
+ // It's possbile that this line was empty and there's no row here after all
1828
+ if (_results.data.length === 0)
1829
+ return;
1830
+
1831
+ _stepCounter += results.data.length;
1832
+ if (_config.preview && _stepCounter > _config.preview)
1833
+ _parser.abort();
1834
+ else {
1835
+ _results.data = _results.data[0];
1836
+ userStep(_results, self);
1837
+ }
1838
+ }
1839
+ };
1840
+ }
1841
+
1842
+ /**
1843
+ * Parses input. Most users won't need, and shouldn't mess with, the baseIndex
1844
+ * and ignoreLastRow parameters. They are used by streamers (wrapper functions)
1845
+ * when an input comes in multiple chunks, like from a file.
1846
+ */
1847
+ this.parse = function(input, baseIndex, ignoreLastRow)
1848
+ {
1849
+ var quoteChar = _config.quoteChar || '"';
1850
+ if (!_config.newline)
1851
+ _config.newline = guessLineEndings(input, quoteChar);
1852
+
1853
+ _delimiterError = false;
1854
+ if (!_config.delimiter)
1855
+ {
1856
+ var delimGuess = guessDelimiter(input, _config.newline, _config.skipEmptyLines, _config.comments, _config.delimitersToGuess);
1857
+ if (delimGuess.successful)
1858
+ _config.delimiter = delimGuess.bestDelimiter;
1859
+ else
1860
+ {
1861
+ _delimiterError = true; // add error after parsing (otherwise it would be overwritten)
1862
+ _config.delimiter = Papa.DefaultDelimiter;
1863
+ }
1864
+ _results.meta.delimiter = _config.delimiter;
1865
+ }
1866
+ else if(isFunction(_config.delimiter))
1867
+ {
1868
+ _config.delimiter = _config.delimiter(input);
1869
+ _results.meta.delimiter = _config.delimiter;
1870
+ }
1871
+
1872
+ var parserConfig = copy(_config);
1873
+ if (_config.preview && _config.header)
1874
+ parserConfig.preview++; // to compensate for header row
1875
+
1876
+ _input = input;
1877
+ _parser = new Parser(parserConfig);
1878
+ _results = _parser.parse(_input, baseIndex, ignoreLastRow);
1879
+ processResults();
1880
+ return _paused ? { meta: { paused: true } } : (_results || { meta: { paused: false } });
1881
+ };
1882
+
1883
+ this.paused = function()
1884
+ {
1885
+ return _paused;
1886
+ };
1887
+
1888
+ this.pause = function()
1889
+ {
1890
+ _paused = true;
1891
+ _parser.abort();
1892
+
1893
+ // If it is streaming via "chunking", the reader will start appending correctly already so no need to substring,
1894
+ // otherwise we can get duplicate content within a row
1895
+ _input = isFunction(_config.chunk) ? "" : _input.substring(_parser.getCharIndex());
1896
+ };
1897
+
1898
+ this.resume = function()
1899
+ {
1900
+ if(self.streamer._halted) {
1901
+ _paused = false;
1902
+ self.streamer.parseChunk(_input, true);
1903
+ } else {
1904
+ // Bugfix: #636 In case the processing hasn't halted yet
1905
+ // wait for it to halt in order to resume
1906
+ setTimeout(self.resume, 3);
1907
+ }
1908
+ };
1909
+
1910
+ this.aborted = function()
1911
+ {
1912
+ return _aborted;
1913
+ };
1914
+
1915
+ this.abort = function()
1916
+ {
1917
+ _aborted = true;
1918
+ _parser.abort();
1919
+ _results.meta.aborted = true;
1920
+ if (isFunction(_config.complete))
1921
+ _config.complete(_results);
1922
+ _input = '';
1923
+ };
1924
+
1925
+ function testEmptyLine(s) {
1926
+ return _config.skipEmptyLines === 'greedy' ? s.join('').trim() === '' : s.length === 1 && s[0].length === 0;
1927
+ }
1928
+
1929
+ function testFloat(s) {
1930
+ if (FLOAT.test(s)) {
1931
+ var floatValue = parseFloat(s);
1932
+ if (floatValue > MIN_FLOAT && floatValue < MAX_FLOAT) {
1933
+ return true;
1934
+ }
1935
+ }
1936
+ return false;
1937
+ }
1938
+
1939
+ function processResults()
1940
+ {
1941
+ if (_results && _delimiterError)
1942
+ {
1943
+ addError('Delimiter', 'UndetectableDelimiter', 'Unable to auto-detect delimiting character; defaulted to \'' + Papa.DefaultDelimiter + '\'');
1944
+ _delimiterError = false;
1945
+ }
1946
+
1947
+ if (_config.skipEmptyLines)
1948
+ {
1949
+ _results.data = _results.data.filter(function(d) {
1950
+ return !testEmptyLine(d);
1951
+ });
1952
+ }
1953
+
1954
+ if (needsHeaderRow())
1955
+ fillHeaderFields();
1956
+
1957
+ return applyHeaderAndDynamicTypingAndTransformation();
1958
+ }
1959
+
1960
+ function needsHeaderRow()
1961
+ {
1962
+ return _config.header && _fields.length === 0;
1963
+ }
1964
+
1965
+ function fillHeaderFields()
1966
+ {
1967
+ if (!_results)
1968
+ return;
1969
+
1970
+ function addHeader(header, i)
1971
+ {
1972
+ if (isFunction(_config.transformHeader))
1973
+ header = _config.transformHeader(header, i);
1974
+
1975
+ _fields.push(header);
1976
+ }
1977
+
1978
+ if (Array.isArray(_results.data[0]))
1979
+ {
1980
+ for (var i = 0; needsHeaderRow() && i < _results.data.length; i++)
1981
+ _results.data[i].forEach(addHeader);
1982
+
1983
+ _results.data.splice(0, 1);
1984
+ }
1985
+ // if _results.data[0] is not an array, we are in a step where _results.data is the row.
1986
+ else
1987
+ _results.data.forEach(addHeader);
1988
+ }
1989
+
1990
+ function shouldApplyDynamicTyping(field) {
1991
+ // Cache function values to avoid calling it for each row
1992
+ if (_config.dynamicTypingFunction && _config.dynamicTyping[field] === undefined) {
1993
+ _config.dynamicTyping[field] = _config.dynamicTypingFunction(field);
1994
+ }
1995
+ return (_config.dynamicTyping[field] || _config.dynamicTyping) === true;
1996
+ }
1997
+
1998
+ function parseDynamic(field, value)
1999
+ {
2000
+ if (shouldApplyDynamicTyping(field))
2001
+ {
2002
+ if (value === 'true' || value === 'TRUE')
2003
+ return true;
2004
+ else if (value === 'false' || value === 'FALSE')
2005
+ return false;
2006
+ else if (testFloat(value))
2007
+ return parseFloat(value);
2008
+ else if (ISO_DATE.test(value))
2009
+ return new Date(value);
2010
+ else
2011
+ return (value === '' ? null : value);
2012
+ }
2013
+ return value;
2014
+ }
2015
+
2016
+ function applyHeaderAndDynamicTypingAndTransformation()
2017
+ {
2018
+ if (!_results || (!_config.header && !_config.dynamicTyping && !_config.transform))
2019
+ return _results;
2020
+
2021
+ function processRow(rowSource, i)
2022
+ {
2023
+ var row = _config.header ? {} : [];
2024
+
2025
+ var j;
2026
+ for (j = 0; j < rowSource.length; j++)
2027
+ {
2028
+ var field = j;
2029
+ var value = rowSource[j];
2030
+
2031
+ if (_config.header)
2032
+ field = j >= _fields.length ? '__parsed_extra' : _fields[j];
2033
+
2034
+ if (_config.transform)
2035
+ value = _config.transform(value,field);
2036
+
2037
+ value = parseDynamic(field, value);
2038
+
2039
+ if (field === '__parsed_extra')
2040
+ {
2041
+ row[field] = row[field] || [];
2042
+ row[field].push(value);
2043
+ }
2044
+ else
2045
+ row[field] = value;
2046
+ }
2047
+
2048
+
2049
+ if (_config.header)
2050
+ {
2051
+ if (j > _fields.length)
2052
+ addError('FieldMismatch', 'TooManyFields', 'Too many fields: expected ' + _fields.length + ' fields but parsed ' + j, _rowCounter + i);
2053
+ else if (j < _fields.length)
2054
+ addError('FieldMismatch', 'TooFewFields', 'Too few fields: expected ' + _fields.length + ' fields but parsed ' + j, _rowCounter + i);
2055
+ }
2056
+
2057
+ return row;
2058
+ }
2059
+
2060
+ var incrementBy = 1;
2061
+ if (!_results.data.length || Array.isArray(_results.data[0]))
2062
+ {
2063
+ _results.data = _results.data.map(processRow);
2064
+ incrementBy = _results.data.length;
2065
+ }
2066
+ else
2067
+ _results.data = processRow(_results.data, 0);
2068
+
2069
+
2070
+ if (_config.header && _results.meta)
2071
+ _results.meta.fields = _fields;
2072
+
2073
+ _rowCounter += incrementBy;
2074
+ return _results;
2075
+ }
2076
+
2077
+ function guessDelimiter(input, newline, skipEmptyLines, comments, delimitersToGuess) {
2078
+ var bestDelim, bestDelta, fieldCountPrevRow, maxFieldCount;
2079
+
2080
+ delimitersToGuess = delimitersToGuess || [',', '\t', '|', ';', Papa.RECORD_SEP, Papa.UNIT_SEP];
2081
+
2082
+ for (var i = 0; i < delimitersToGuess.length; i++) {
2083
+ var delim = delimitersToGuess[i];
2084
+ var delta = 0, avgFieldCount = 0, emptyLinesCount = 0;
2085
+ fieldCountPrevRow = undefined;
2086
+
2087
+ var preview = new Parser({
2088
+ comments: comments,
2089
+ delimiter: delim,
2090
+ newline: newline,
2091
+ preview: 10
2092
+ }).parse(input);
2093
+
2094
+ for (var j = 0; j < preview.data.length; j++) {
2095
+ if (skipEmptyLines && testEmptyLine(preview.data[j])) {
2096
+ emptyLinesCount++;
2097
+ continue;
2098
+ }
2099
+ var fieldCount = preview.data[j].length;
2100
+ avgFieldCount += fieldCount;
2101
+
2102
+ if (typeof fieldCountPrevRow === 'undefined') {
2103
+ fieldCountPrevRow = fieldCount;
2104
+ continue;
2105
+ }
2106
+ else if (fieldCount > 0) {
2107
+ delta += Math.abs(fieldCount - fieldCountPrevRow);
2108
+ fieldCountPrevRow = fieldCount;
2109
+ }
2110
+ }
2111
+
2112
+ if (preview.data.length > 0)
2113
+ avgFieldCount /= (preview.data.length - emptyLinesCount);
2114
+
2115
+ if ((typeof bestDelta === 'undefined' || delta <= bestDelta)
2116
+ && (typeof maxFieldCount === 'undefined' || avgFieldCount > maxFieldCount) && avgFieldCount > 1.99) {
2117
+ bestDelta = delta;
2118
+ bestDelim = delim;
2119
+ maxFieldCount = avgFieldCount;
2120
+ }
2121
+ }
2122
+
2123
+ _config.delimiter = bestDelim;
2124
+
2125
+ return {
2126
+ successful: !!bestDelim,
2127
+ bestDelimiter: bestDelim
2128
+ };
2129
+ }
2130
+
2131
+ function guessLineEndings(input, quoteChar)
2132
+ {
2133
+ input = input.substring(0, 1024 * 1024); // max length 1 MB
2134
+ // Replace all the text inside quotes
2135
+ var re = new RegExp(escapeRegExp(quoteChar) + '([^]*?)' + escapeRegExp(quoteChar), 'gm');
2136
+ input = input.replace(re, '');
2137
+
2138
+ var r = input.split('\r');
2139
+
2140
+ var n = input.split('\n');
2141
+
2142
+ var nAppearsFirst = (n.length > 1 && n[0].length < r[0].length);
2143
+
2144
+ if (r.length === 1 || nAppearsFirst)
2145
+ return '\n';
2146
+
2147
+ var numWithN = 0;
2148
+ for (var i = 0; i < r.length; i++)
2149
+ {
2150
+ if (r[i][0] === '\n')
2151
+ numWithN++;
2152
+ }
2153
+
2154
+ return numWithN >= r.length / 2 ? '\r\n' : '\r';
2155
+ }
2156
+
2157
+ function addError(type, code, msg, row)
2158
+ {
2159
+ var error = {
2160
+ type: type,
2161
+ code: code,
2162
+ message: msg
2163
+ };
2164
+ if(row !== undefined) {
2165
+ error.row = row;
2166
+ }
2167
+ _results.errors.push(error);
2168
+ }
2169
+ }
2170
+
2171
+ /** https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions */
2172
+ function escapeRegExp(string)
2173
+ {
2174
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
2175
+ }
2176
+
2177
+ /** The core parser implements speedy and correct CSV parsing */
2178
+ function Parser(config)
2179
+ {
2180
+ // Unpack the config object
2181
+ config = config || {};
2182
+ var delim = config.delimiter;
2183
+ var newline = config.newline;
2184
+ var comments = config.comments;
2185
+ var step = config.step;
2186
+ var preview = config.preview;
2187
+ var fastMode = config.fastMode;
2188
+ var quoteChar;
2189
+ if (config.quoteChar === undefined || config.quoteChar === null) {
2190
+ quoteChar = '"';
2191
+ } else {
2192
+ quoteChar = config.quoteChar;
2193
+ }
2194
+ var escapeChar = quoteChar;
2195
+ if (config.escapeChar !== undefined) {
2196
+ escapeChar = config.escapeChar;
2197
+ }
2198
+
2199
+ // Delimiter must be valid
2200
+ if (typeof delim !== 'string'
2201
+ || Papa.BAD_DELIMITERS.indexOf(delim) > -1)
2202
+ delim = ',';
2203
+
2204
+ // Comment character must be valid
2205
+ if (comments === delim)
2206
+ throw new Error('Comment character same as delimiter');
2207
+ else if (comments === true)
2208
+ comments = '#';
2209
+ else if (typeof comments !== 'string'
2210
+ || Papa.BAD_DELIMITERS.indexOf(comments) > -1)
2211
+ comments = false;
2212
+
2213
+ // Newline must be valid: \r, \n, or \r\n
2214
+ if (newline !== '\n' && newline !== '\r' && newline !== '\r\n')
2215
+ newline = '\n';
2216
+
2217
+ // We're gonna need these at the Parser scope
2218
+ var cursor = 0;
2219
+ var aborted = false;
2220
+
2221
+ this.parse = function(input, baseIndex, ignoreLastRow)
2222
+ {
2223
+ // For some reason, in Chrome, this speeds things up (!?)
2224
+ if (typeof input !== 'string')
2225
+ throw new Error('Input must be a string');
2226
+
2227
+ // We don't need to compute some of these every time parse() is called,
2228
+ // but having them in a more local scope seems to perform better
2229
+ var inputLen = input.length,
2230
+ delimLen = delim.length,
2231
+ newlineLen = newline.length,
2232
+ commentsLen = comments.length;
2233
+ var stepIsFunction = isFunction(step);
2234
+
2235
+ // Establish starting state
2236
+ cursor = 0;
2237
+ var data = [], errors = [], row = [], lastCursor = 0;
2238
+
2239
+ if (!input)
2240
+ return returnable();
2241
+
2242
+ // Rename headers if there are duplicates
2243
+ if (config.header)
2244
+ {
2245
+ var firstLine = input.split(newline)[0];
2246
+ var headers = firstLine.split(delim);
2247
+ var separator = '_';
2248
+ var headerMap = [];
2249
+ var headerCount = {};
2250
+ var duplicateHeaders = false;
2251
+
2252
+ for (var j in headers) {
2253
+ var header = headers[j];
2254
+ if (isFunction(config.transformHeader))
2255
+ header = config.transformHeader(header, j);
2256
+ var headerName = header;
2257
+
2258
+ var count = headerCount[header] || 0;
2259
+ if (count > 0) {
2260
+ duplicateHeaders = true;
2261
+ headerName = header + separator + count;
2262
+ }
2263
+ headerCount[header] = count + 1;
2264
+
2265
+ headerMap.push(headerName);
2266
+ }
2267
+ if (duplicateHeaders) {
2268
+ var editedInput = input.split(newline);
2269
+ editedInput[0] = headerMap.join(delim);
2270
+ input = editedInput.join(newline);
2271
+ }
2272
+ }
2273
+ if (fastMode || (fastMode !== false && input.indexOf(quoteChar) === -1))
2274
+ {
2275
+ var rows = input.split(newline);
2276
+ for (var i = 0; i < rows.length; i++)
2277
+ {
2278
+ row = rows[i];
2279
+ cursor += row.length;
2280
+ if (i !== rows.length - 1)
2281
+ cursor += newline.length;
2282
+ else if (ignoreLastRow)
2283
+ return returnable();
2284
+ if (comments && row.substring(0, commentsLen) === comments)
2285
+ continue;
2286
+ if (stepIsFunction)
2287
+ {
2288
+ data = [];
2289
+ pushRow(row.split(delim));
2290
+ doStep();
2291
+ if (aborted)
2292
+ return returnable();
2293
+ }
2294
+ else
2295
+ pushRow(row.split(delim));
2296
+ if (preview && i >= preview)
2297
+ {
2298
+ data = data.slice(0, preview);
2299
+ return returnable(true);
2300
+ }
2301
+ }
2302
+ return returnable();
2303
+ }
2304
+
2305
+ var nextDelim = input.indexOf(delim, cursor);
2306
+ var nextNewline = input.indexOf(newline, cursor);
2307
+ var quoteCharRegex = new RegExp(escapeRegExp(escapeChar) + escapeRegExp(quoteChar), 'g');
2308
+ var quoteSearch = input.indexOf(quoteChar, cursor);
2309
+
2310
+ // Parser loop
2311
+ for (;;)
2312
+ {
2313
+ // Field has opening quote
2314
+ if (input[cursor] === quoteChar)
2315
+ {
2316
+ // Start our search for the closing quote where the cursor is
2317
+ quoteSearch = cursor;
2318
+
2319
+ // Skip the opening quote
2320
+ cursor++;
2321
+
2322
+ for (;;)
2323
+ {
2324
+ // Find closing quote
2325
+ quoteSearch = input.indexOf(quoteChar, quoteSearch + 1);
2326
+
2327
+ //No other quotes are found - no other delimiters
2328
+ if (quoteSearch === -1)
2329
+ {
2330
+ if (!ignoreLastRow) {
2331
+ // No closing quote... what a pity
2332
+ errors.push({
2333
+ type: 'Quotes',
2334
+ code: 'MissingQuotes',
2335
+ message: 'Quoted field unterminated',
2336
+ row: data.length, // row has yet to be inserted
2337
+ index: cursor
2338
+ });
2339
+ }
2340
+ return finish();
2341
+ }
2342
+
2343
+ // Closing quote at EOF
2344
+ if (quoteSearch === inputLen - 1)
2345
+ {
2346
+ var value = input.substring(cursor, quoteSearch).replace(quoteCharRegex, quoteChar);
2347
+ return finish(value);
2348
+ }
2349
+
2350
+ // If this quote is escaped, it's part of the data; skip it
2351
+ // If the quote character is the escape character, then check if the next character is the escape character
2352
+ if (quoteChar === escapeChar && input[quoteSearch + 1] === escapeChar)
2353
+ {
2354
+ quoteSearch++;
2355
+ continue;
2356
+ }
2357
+
2358
+ // If the quote character is not the escape character, then check if the previous character was the escape character
2359
+ if (quoteChar !== escapeChar && quoteSearch !== 0 && input[quoteSearch - 1] === escapeChar)
2360
+ {
2361
+ continue;
2362
+ }
2363
+
2364
+ if(nextDelim !== -1 && nextDelim < (quoteSearch + 1)) {
2365
+ nextDelim = input.indexOf(delim, (quoteSearch + 1));
2366
+ }
2367
+ if(nextNewline !== -1 && nextNewline < (quoteSearch + 1)) {
2368
+ nextNewline = input.indexOf(newline, (quoteSearch + 1));
2369
+ }
2370
+ // Check up to nextDelim or nextNewline, whichever is closest
2371
+ var checkUpTo = nextNewline === -1 ? nextDelim : Math.min(nextDelim, nextNewline);
2372
+ var spacesBetweenQuoteAndDelimiter = extraSpaces(checkUpTo);
2373
+
2374
+ // Closing quote followed by delimiter or 'unnecessary spaces + delimiter'
2375
+ if (input.substr(quoteSearch + 1 + spacesBetweenQuoteAndDelimiter, delimLen) === delim)
2376
+ {
2377
+ row.push(input.substring(cursor, quoteSearch).replace(quoteCharRegex, quoteChar));
2378
+ cursor = quoteSearch + 1 + spacesBetweenQuoteAndDelimiter + delimLen;
2379
+
2380
+ // If char after following delimiter is not quoteChar, we find next quote char position
2381
+ if (input[quoteSearch + 1 + spacesBetweenQuoteAndDelimiter + delimLen] !== quoteChar)
2382
+ {
2383
+ quoteSearch = input.indexOf(quoteChar, cursor);
2384
+ }
2385
+ nextDelim = input.indexOf(delim, cursor);
2386
+ nextNewline = input.indexOf(newline, cursor);
2387
+ break;
2388
+ }
2389
+
2390
+ var spacesBetweenQuoteAndNewLine = extraSpaces(nextNewline);
2391
+
2392
+ // Closing quote followed by newline or 'unnecessary spaces + newLine'
2393
+ if (input.substring(quoteSearch + 1 + spacesBetweenQuoteAndNewLine, quoteSearch + 1 + spacesBetweenQuoteAndNewLine + newlineLen) === newline)
2394
+ {
2395
+ row.push(input.substring(cursor, quoteSearch).replace(quoteCharRegex, quoteChar));
2396
+ saveRow(quoteSearch + 1 + spacesBetweenQuoteAndNewLine + newlineLen);
2397
+ nextDelim = input.indexOf(delim, cursor); // because we may have skipped the nextDelim in the quoted field
2398
+ quoteSearch = input.indexOf(quoteChar, cursor); // we search for first quote in next line
2399
+
2400
+ if (stepIsFunction)
2401
+ {
2402
+ doStep();
2403
+ if (aborted)
2404
+ return returnable();
2405
+ }
2406
+
2407
+ if (preview && data.length >= preview)
2408
+ return returnable(true);
2409
+
2410
+ break;
2411
+ }
2412
+
2413
+
2414
+ // Checks for valid closing quotes are complete (escaped quotes or quote followed by EOF/delimiter/newline) -- assume these quotes are part of an invalid text string
2415
+ errors.push({
2416
+ type: 'Quotes',
2417
+ code: 'InvalidQuotes',
2418
+ message: 'Trailing quote on quoted field is malformed',
2419
+ row: data.length, // row has yet to be inserted
2420
+ index: cursor
2421
+ });
2422
+
2423
+ quoteSearch++;
2424
+ continue;
2425
+
2426
+ }
2427
+
2428
+ continue;
2429
+ }
2430
+
2431
+ // Comment found at start of new line
2432
+ if (comments && row.length === 0 && input.substring(cursor, cursor + commentsLen) === comments)
2433
+ {
2434
+ if (nextNewline === -1) // Comment ends at EOF
2435
+ return returnable();
2436
+ cursor = nextNewline + newlineLen;
2437
+ nextNewline = input.indexOf(newline, cursor);
2438
+ nextDelim = input.indexOf(delim, cursor);
2439
+ continue;
2440
+ }
2441
+
2442
+ // Next delimiter comes before next newline, so we've reached end of field
2443
+ if (nextDelim !== -1 && (nextDelim < nextNewline || nextNewline === -1))
2444
+ {
2445
+ row.push(input.substring(cursor, nextDelim));
2446
+ cursor = nextDelim + delimLen;
2447
+ // we look for next delimiter char
2448
+ nextDelim = input.indexOf(delim, cursor);
2449
+ continue;
2450
+ }
2451
+
2452
+ // End of row
2453
+ if (nextNewline !== -1)
2454
+ {
2455
+ row.push(input.substring(cursor, nextNewline));
2456
+ saveRow(nextNewline + newlineLen);
2457
+
2458
+ if (stepIsFunction)
2459
+ {
2460
+ doStep();
2461
+ if (aborted)
2462
+ return returnable();
2463
+ }
2464
+
2465
+ if (preview && data.length >= preview)
2466
+ return returnable(true);
2467
+
2468
+ continue;
2469
+ }
2470
+
2471
+ break;
2472
+ }
2473
+
2474
+
2475
+ return finish();
2476
+
2477
+
2478
+ function pushRow(row)
2479
+ {
2480
+ data.push(row);
2481
+ lastCursor = cursor;
2482
+ }
2483
+
2484
+ /**
2485
+ * checks if there are extra spaces after closing quote and given index without any text
2486
+ * if Yes, returns the number of spaces
2487
+ */
2488
+ function extraSpaces(index) {
2489
+ var spaceLength = 0;
2490
+ if (index !== -1) {
2491
+ var textBetweenClosingQuoteAndIndex = input.substring(quoteSearch + 1, index);
2492
+ if (textBetweenClosingQuoteAndIndex && textBetweenClosingQuoteAndIndex.trim() === '') {
2493
+ spaceLength = textBetweenClosingQuoteAndIndex.length;
2494
+ }
2495
+ }
2496
+ return spaceLength;
2497
+ }
2498
+
2499
+ /**
2500
+ * Appends the remaining input from cursor to the end into
2501
+ * row, saves the row, calls step, and returns the results.
2502
+ */
2503
+ function finish(value)
2504
+ {
2505
+ if (ignoreLastRow)
2506
+ return returnable();
2507
+ if (typeof value === 'undefined')
2508
+ value = input.substring(cursor);
2509
+ row.push(value);
2510
+ cursor = inputLen; // important in case parsing is paused
2511
+ pushRow(row);
2512
+ if (stepIsFunction)
2513
+ doStep();
2514
+ return returnable();
2515
+ }
2516
+
2517
+ /**
2518
+ * Appends the current row to the results. It sets the cursor
2519
+ * to newCursor and finds the nextNewline. The caller should
2520
+ * take care to execute user's step function and check for
2521
+ * preview and end parsing if necessary.
2522
+ */
2523
+ function saveRow(newCursor)
2524
+ {
2525
+ cursor = newCursor;
2526
+ pushRow(row);
2527
+ row = [];
2528
+ nextNewline = input.indexOf(newline, cursor);
2529
+ }
2530
+
2531
+ /** Returns an object with the results, errors, and meta. */
2532
+ function returnable(stopped)
2533
+ {
2534
+ return {
2535
+ data: data,
2536
+ errors: errors,
2537
+ meta: {
2538
+ delimiter: delim,
2539
+ linebreak: newline,
2540
+ aborted: aborted,
2541
+ truncated: !!stopped,
2542
+ cursor: lastCursor + (baseIndex || 0)
2543
+ }
2544
+ };
2545
+ }
2546
+
2547
+ /** Executes the user's step function and resets data & errors. */
2548
+ function doStep()
2549
+ {
2550
+ step(returnable());
2551
+ data = [];
2552
+ errors = [];
2553
+ }
2554
+ };
2555
+
2556
+ /** Sets the abort flag */
2557
+ this.abort = function()
2558
+ {
2559
+ aborted = true;
2560
+ };
2561
+
2562
+ /** Gets the cursor position */
2563
+ this.getCharIndex = function()
2564
+ {
2565
+ return cursor;
2566
+ };
2567
+ }
2568
+
2569
+
2570
+ function newWorker()
2571
+ {
2572
+ if (!Papa.WORKERS_SUPPORTED)
2573
+ return false;
2574
+
2575
+ var workerUrl = getWorkerBlob();
2576
+ var w = new global.Worker(workerUrl);
2577
+ w.onmessage = mainThreadReceivedMessage;
2578
+ w.id = workerIdCounter++;
2579
+ workers[w.id] = w;
2580
+ return w;
2581
+ }
2582
+
2583
+ /** Callback when main thread receives a message */
2584
+ function mainThreadReceivedMessage(e)
2585
+ {
2586
+ var msg = e.data;
2587
+ var worker = workers[msg.workerId];
2588
+ var aborted = false;
2589
+
2590
+ if (msg.error)
2591
+ worker.userError(msg.error, msg.file);
2592
+ else if (msg.results && msg.results.data)
2593
+ {
2594
+ var abort = function() {
2595
+ aborted = true;
2596
+ completeWorker(msg.workerId, { data: [], errors: [], meta: { aborted: true } });
2597
+ };
2598
+
2599
+ var handle = {
2600
+ abort: abort,
2601
+ pause: notImplemented,
2602
+ resume: notImplemented
2603
+ };
2604
+
2605
+ if (isFunction(worker.userStep))
2606
+ {
2607
+ for (var i = 0; i < msg.results.data.length; i++)
2608
+ {
2609
+ worker.userStep({
2610
+ data: msg.results.data[i],
2611
+ errors: msg.results.errors,
2612
+ meta: msg.results.meta
2613
+ }, handle);
2614
+ if (aborted)
2615
+ break;
2616
+ }
2617
+ delete msg.results; // free memory ASAP
2618
+ }
2619
+ else if (isFunction(worker.userChunk))
2620
+ {
2621
+ worker.userChunk(msg.results, handle, msg.file);
2622
+ delete msg.results;
2623
+ }
2624
+ }
2625
+
2626
+ if (msg.finished && !aborted)
2627
+ completeWorker(msg.workerId, msg.results);
2628
+ }
2629
+
2630
+ function completeWorker(workerId, results) {
2631
+ var worker = workers[workerId];
2632
+ if (isFunction(worker.userComplete))
2633
+ worker.userComplete(results);
2634
+ worker.terminate();
2635
+ delete workers[workerId];
2636
+ }
2637
+
2638
+ function notImplemented() {
2639
+ throw new Error('Not implemented.');
2640
+ }
2641
+
2642
+ /** Callback when worker thread receives a message */
2643
+ function workerThreadReceivedMessage(e)
2644
+ {
2645
+ var msg = e.data;
2646
+
2647
+ if (typeof Papa.WORKER_ID === 'undefined' && msg)
2648
+ Papa.WORKER_ID = msg.workerId;
2649
+
2650
+ if (typeof msg.input === 'string')
2651
+ {
2652
+ global.postMessage({
2653
+ workerId: Papa.WORKER_ID,
2654
+ results: Papa.parse(msg.input, msg.config),
2655
+ finished: true
2656
+ });
2657
+ }
2658
+ else if ((global.File && msg.input instanceof File) || msg.input instanceof Object) // thank you, Safari (see issue #106)
2659
+ {
2660
+ var results = Papa.parse(msg.input, msg.config);
2661
+ if (results)
2662
+ global.postMessage({
2663
+ workerId: Papa.WORKER_ID,
2664
+ results: results,
2665
+ finished: true
2666
+ });
2667
+ }
2668
+ }
2669
+
2670
+ /** Makes a deep copy of an array or object (mostly) */
2671
+ function copy(obj)
2672
+ {
2673
+ if (typeof obj !== 'object' || obj === null)
2674
+ return obj;
2675
+ var cpy = Array.isArray(obj) ? [] : {};
2676
+ for (var key in obj)
2677
+ cpy[key] = copy(obj[key]);
2678
+ return cpy;
2679
+ }
2680
+
2681
+ function bindFunction(f, self)
2682
+ {
2683
+ return function() { f.apply(self, arguments); };
2684
+ }
2685
+
2686
+ function isFunction(func)
2687
+ {
2688
+ return typeof func === 'function';
2689
+ }
2690
+
2691
+ return Papa;
2692
+ }));
2693
+ } (papaparse));
2694
+
2695
+ var Papa = papaparse.exports;
2696
+
2697
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2698
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2699
+ var isValidEmail = function isValidEmail(email) {
2700
+ return string().email().isValidSync(email);
2701
+ };
2702
+ var isPastDate = function isPastDate(date) {
2703
+ return dayjs(date).isBefore(dayjs().subtract(1, "days"));
2704
+ };
2705
+ var createEmailOptions = function createEmailOptions() {
2706
+ var emails = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2707
+ return emails.map(function (email) {
2708
+ return {
2709
+ label: email,
2710
+ value: email,
2711
+ valid: isValidEmail(email)
2712
+ };
2713
+ });
2714
+ };
2715
+ var parseCsvEmails = function parseCsvEmails(file) {
2716
+ return new Promise(function (resolve) {
2717
+ Papa.parse(file, {
2718
+ header: true,
2719
+ skipEmptyLines: true,
2720
+ transformHeader: function transformHeader(h) {
2721
+ return h.toLowerCase().replace(/\W/g, "");
2722
+ },
2723
+ complete: function complete(results) {
2724
+ var _results$meta$fields;
2725
+ var isEmailFieldPresent = (_results$meta$fields = results.meta.fields) === null || _results$meta$fields === void 0 ? void 0 : _results$meta$fields.includes("email");
2726
+ if (!isEmailFieldPresent) return resolve([]);
2727
+ var emails = results.data.map(function (item) {
2728
+ var _item$email;
2729
+ return (_item$email = item.email) === null || _item$email === void 0 ? void 0 : _item$email.trim();
2730
+ }).filter(isNot(undefined));
2731
+ return resolve(createEmailOptions(emails));
2732
+ }
2733
+ });
2734
+ });
2735
+ };
2736
+ var generateInitialValues = function generateInitialValues(defaultValues) {
2737
+ return _objectSpread(_objectSpread({}, INITIAL_VALUES), defaultValues);
2738
+ };
2739
+ var emailFormValidationSchema = function emailFormValidationSchema(disableReplyTo) {
2740
+ return yup.object().shape({
2741
+ emailSubject: yup.string().required(t("neetoMolecules.shareViaEmail.validations.requiredField.subject")),
2742
+ emailBody: yup.string().test("emailBody", t("neetoMolecules.shareViaEmail.validations.requiredField.emailBody"), function (value) {
2743
+ return !isEditorEmpty(value);
2744
+ }),
2745
+ sendFromEmail: yup.string().trim().email(t("neetoMolecules.shareViaEmail.validations.invalidField.emailAddress")).required(t("neetoMolecules.shareViaEmail.validations.requiredField.sendFrom")),
2746
+ replyToEmail: !disableReplyTo && yup.string().trim().email(t("neetoMolecules.shareViaEmail.validations.invalidField.emailAddress")).required(t("neetoMolecules.shareViaEmail.validations.requiredField.replyTo")),
2747
+ notifyEmails: yup.array().min(1, t("neetoMolecules.shareViaEmail.validations.atleastOneIsRequired.emailAddress")).test("are-all-emails-valid", t("neetoMolecules.shareViaEmail.validations.invalidField.emailAddress"), function (emails) {
2748
+ return emails.every(prop("valid"));
2749
+ }),
2750
+ isSendLaterEnabled: yup["boolean"](),
2751
+ sendEmailDatetime: yup.date().when("isSendLaterEnabled", {
2752
+ is: true,
2753
+ then: yup.date().required(t("neetoMolecules.shareViaEmail.validations.requiredField.sendLater"))
2754
+ }),
2755
+ name: yup.string(),
2756
+ actionButtonText: yup.string().required(t("neetoMolecules.shareViaEmail.validations.requiredField.startButtonText"))
2757
+ });
2758
+ };
2759
+
2760
+ var Form = function Form(_ref) {
2761
+ var disableReplyTo = _ref.disableReplyTo,
2762
+ showVideoEmbedInEditor = _ref.showVideoEmbedInEditor,
2763
+ children = _ref.children;
2764
+ var _useFormikContext = useFormikContext(),
2765
+ values = _useFormikContext.values,
2766
+ setFieldValue = _useFormikContext.setFieldValue,
2767
+ initialValues = _useFormikContext.initialValues;
2768
+ var editorRef = useRef();
2769
+ var _useTranslation = useTranslation(),
2770
+ t = _useTranslation.t;
2771
+ var handleReset = function handleReset() {
2772
+ editorRef.current.editor.commands.setContent(initialValues.emailBody);
2773
+ };
2774
+ var handleCSVFile = useCallback( /*#__PURE__*/function () {
2775
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(_ref2) {
2776
+ var _ref4, file, values;
2777
+ return regenerator.wrap(function _callee$(_context) {
2778
+ while (1) switch (_context.prev = _context.next) {
2779
+ case 0:
2780
+ _ref4 = _slicedToArray(_ref2, 1), file = _ref4[0];
2781
+ _context.next = 3;
2782
+ return parseCsvEmails(file);
2783
+ case 3:
2784
+ values = _context.sent;
2785
+ setFieldValue("notifyEmails", values);
2786
+ case 5:
2787
+ case "end":
2788
+ return _context.stop();
2789
+ }
2790
+ }, _callee);
2791
+ }));
2792
+ return function (_x) {
2793
+ return _ref3.apply(this, arguments);
2794
+ };
2795
+ }(), []);
2796
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
2797
+ className: "space-y-4"
2798
+ }, /*#__PURE__*/React.createElement("div", {
2799
+ className: "space-y-2"
2800
+ }, /*#__PURE__*/React.createElement("div", {
2801
+ className: "flex items-center justify-between"
2802
+ }, /*#__PURE__*/React.createElement(Typography, {
2803
+ "data-cy": "send-to-input-label",
2804
+ lineHeight: "normal",
2805
+ style: "h4",
2806
+ weight: "semibold"
2807
+ }, t("neetoMolecules.shareViaEmail.sendTo")), /*#__PURE__*/React.createElement(FilePicker$1, {
2808
+ types: ALLOWED_FILE_PICKER_TYPES,
2809
+ onChange: handleCSVFile
2810
+ })), /*#__PURE__*/React.createElement(MultiEmailInput, {
2811
+ filterInvalidEmails: true,
2812
+ required: true,
2813
+ label: "",
2814
+ name: "notifyEmails"
2815
+ })), /*#__PURE__*/React.createElement(Input, {
2816
+ required: true,
2817
+ className: "col-span-1",
2818
+ label: t("neetoMolecules.shareViaEmail.subject"),
2819
+ name: "emailSubject"
2820
+ }), /*#__PURE__*/React.createElement(EmailBody$1, {
2821
+ id: "emailBody",
2822
+ ref: editorRef,
2823
+ showVideoEmbedInEditor: showVideoEmbedInEditor
2824
+ }), /*#__PURE__*/React.createElement("div", {
2825
+ ref: editorRef
2826
+ }), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Label, {
2827
+ className: "flex items-center gap-2"
2828
+ }, /*#__PURE__*/React.createElement(Switch, {
2829
+ "data-cy": "send-later-switch",
2830
+ "data-testid": "send-later-switch",
2831
+ name: "isSendLaterEnabled"
2832
+ }), /*#__PURE__*/React.createElement(Typography, {
2833
+ component: "span",
2834
+ "data-cy": "send-later-label",
2835
+ lineHeight: "normal",
2836
+ style: "h4",
2837
+ weight: "semibold"
2838
+ }, t("neetoMolecules.shareViaEmail.sendLater")))), values.isSendLaterEnabled && /*#__PURE__*/React.createElement(FormikDatePicker, {
2839
+ autoFocus: true,
2840
+ showTime: true,
2841
+ "data-cy": "email-share-date-input",
2842
+ "data-testid": "formik-date-picker",
2843
+ disabledDate: isPastDate,
2844
+ name: "sendEmailDatetime",
2845
+ picker: "date",
2846
+ size: "large",
2847
+ type: "date"
2848
+ }), /*#__PURE__*/React.createElement(Input, {
2849
+ required: true,
2850
+ label: t("neetoMolecules.shareViaEmail.startButtonText"),
2851
+ name: "actionButtonText"
2852
+ }), /*#__PURE__*/React.createElement("div", {
2853
+ className: classnames({
2854
+ "grid grid-cols-2 gap-6": !disableReplyTo
2855
+ })
2856
+ }, /*#__PURE__*/React.createElement(Input, {
2857
+ required: true,
2858
+ className: "col-auto",
2859
+ label: t("neetoMolecules.shareViaEmail.sendFrom"),
2860
+ name: "sendFromEmail"
2861
+ }), !disableReplyTo && /*#__PURE__*/React.createElement(Input, {
2862
+ required: true,
2863
+ className: "col-auto",
2864
+ "data-testid": "replyTo-field",
2865
+ label: t("neetoMolecules.shareViaEmail.replyTo"),
2866
+ name: "replyToEmail"
2867
+ }))), children && /*#__PURE__*/React.createElement("div", {
2868
+ className: "neeto-ui-border-gray-300 mt-4 border-t py-4"
2869
+ }, /*#__PURE__*/React.createElement("h3", {
2870
+ className: "mb-4"
2871
+ }, t("neetoMolecules.shareViaEmail.additionalOptions")), children), /*#__PURE__*/React.createElement("div", {
2872
+ className: "mt-6"
2873
+ }, /*#__PURE__*/React.createElement(ActionBlock, {
2874
+ cancelButtonProps: {
2875
+ label: t("neetoMolecules.shareViaEmail.reset"),
2876
+ type: "reset",
2877
+ onClick: handleReset
2878
+ },
2879
+ submitButtonProps: {
2880
+ label: t("neetoMolecules.shareViaEmail.sendEmail")
2881
+ }
2882
+ })));
2883
+ };
2884
+
2885
+ var ShareViaEmail = function ShareViaEmail(_ref) {
2886
+ var backToUrl = _ref.backToUrl,
2887
+ handleSubmit = _ref.handleSubmit,
2888
+ children = _ref.children,
2889
+ description = _ref.description,
2890
+ defaultValues = _ref.defaultValues,
2891
+ disableReplyTo = _ref.disableReplyTo,
2892
+ productName = _ref.productName,
2893
+ showVideoEmbedInEditor = _ref.showVideoEmbedInEditor,
2894
+ _ref$title = _ref.title,
2895
+ title = _ref$title === void 0 ? "" : _ref$title;
2896
+ var _useTranslation = useTranslation(),
2897
+ t = _useTranslation.t;
2898
+ var shareViaEmailTitle = title || t("neetoMolecules.shareViaEmail.title");
2899
+ var sendToEmails = function sendToEmails(notifyEmails) {
2900
+ return notifyEmails.map(function (email) {
2901
+ return email === null || email === void 0 ? void 0 : email.value;
2902
+ });
2903
+ };
2904
+ return /*#__PURE__*/React.createElement("div", {
2905
+ className: "neeto-ui-bg-gray-100 flex w-full flex-1 flex-col p-8"
2906
+ }, /*#__PURE__*/React.createElement("div", {
2907
+ className: "mx-auto flex w-full max-w-7xl flex-col"
2908
+ }, /*#__PURE__*/React.createElement(Form$1, {
2909
+ formProps: {
2910
+ noValidate: true
2911
+ },
2912
+ formikProps: {
2913
+ enableReinitialize: true,
2914
+ validateOnMount: true,
2915
+ initialValues: generateInitialValues(defaultValues),
2916
+ validationSchema: emailFormValidationSchema(disableReplyTo),
2917
+ onSubmit: handleSubmit
2918
+ }
2919
+ }, function (_ref2) {
2920
+ var values = _ref2.values;
2921
+ return /*#__PURE__*/React.createElement("div", {
2922
+ className: "grid grid-cols-12 gap-8"
2923
+ }, /*#__PURE__*/React.createElement("div", {
2924
+ className: "col-span-5"
2925
+ }, backToUrl && /*#__PURE__*/React.createElement(Button, {
2926
+ className: "mb-4",
2927
+ "data-testid": "back-to-url-button",
2928
+ icon: LeftArrow,
2929
+ iconPosition: "left",
2930
+ label: t("neetoMolecules.shareViaEmail.backToShare"),
2931
+ size: "small",
2932
+ style: "link",
2933
+ to: backToUrl
2934
+ }), /*#__PURE__*/React.createElement("div", {
2935
+ className: "mb-6"
2936
+ }, /*#__PURE__*/React.createElement(Typography, {
2937
+ className: "mb-0.5 break-words",
2938
+ "data-cy": "share-via-email-heading",
2939
+ lineHeight: "normal",
2940
+ style: "h2",
2941
+ weight: "semibold"
2942
+ }, shareViaEmailTitle), description && /*#__PURE__*/React.createElement(Typography, {
2943
+ className: "neeto-ui-text-gray-700",
2944
+ "data-cy": "share-via-email-sub-heading",
2945
+ lineHeight: "normal",
2946
+ style: "body2"
2947
+ }, description)), /*#__PURE__*/React.createElement(Form, {
2948
+ disableReplyTo: disableReplyTo,
2949
+ showVideoEmbedInEditor: showVideoEmbedInEditor
2950
+ }, children)), /*#__PURE__*/React.createElement("div", {
2951
+ className: "col-span-7"
2952
+ }, /*#__PURE__*/React.createElement("div", {
2953
+ className: "sticky top-10 pt-10"
2954
+ }, /*#__PURE__*/React.createElement(EmailPreview, {
2955
+ actionButtonText: values.actionButtonText,
2956
+ body: values.emailBody,
2957
+ from: values.sendFromEmail,
2958
+ productName: productName,
2959
+ subject: values.emailSubject,
2960
+ to: sendToEmails(values.notifyEmails)
2961
+ }))));
2962
+ })));
2963
+ };
2964
+
2965
+ export { ShareViaEmail as default };
2966
+ //# sourceMappingURL=ShareViaEmail.js.map