@sumit_yewale/react 1.1.14 → 1.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import React, { PropsWithChildren } from 'react';
2
- declare module '@csvbox/react' {
2
+ declare module '@sumit_yewale/react' {
3
3
  interface CSVBoxImporterProps {
4
4
  lazy?: boolean;
5
5
  loadStarted?:() => void;
@@ -16,7 +16,7 @@ declare module '@csvbox/react' {
16
16
  language?: string;
17
17
  environment?: any;
18
18
  theme?: string;
19
- render?:(launch:any, isLoading:boolean) => void
19
+ render?:(launch:any, isLoading:boolean, launchWithFile:(file:File) => void) => void
20
20
  }
21
21
 
22
22
  export class CSVBoxButton extends React.Component<PropsWithChildren<CSVBoxImporterProps>>{
@@ -25,9 +25,26 @@ declare module '@csvbox/react' {
25
25
  holder: React.RefObject<HTMLDivElement>;
26
26
  uuid: string;
27
27
  iframe: HTMLIFrameElement | null;
28
+ isModalShown: boolean;
29
+ isReady: boolean;
30
+ pendingFile: File | null;
31
+ targetOrigin?: string;
32
+ baseDomain?: string;
33
+ importerOrigin?: string;
34
+ probingOrigin?: boolean;
28
35
 
29
36
  openModal(): void;
30
37
 
38
+ openModalWithFile(file: File): void;
39
+
40
+ postPendingFile(): void;
41
+
42
+ sendPendingFile(origin: string): void;
43
+
44
+ learnImporterOrigin(event: MessageEvent): void;
45
+
46
+ isImporterOrigin(origin: string): boolean;
47
+
31
48
  componentDidMount(): void;
32
49
 
33
50
  initImporter(): void;
package/README.md CHANGED
@@ -38,6 +38,67 @@ import { CSVBoxButton } from '@csvbox/react'
38
38
  </CSVBoxButton>
39
39
  ```
40
40
 
41
+ ## Importing a file you already have
42
+
43
+ `openModalWithFile(file)` opens the importer on a `File` your own page is holding — from your
44
+ own drop target, your own file input, anything — instead of the importer's file picker. The
45
+ file still goes through the importer's extension, worksheet and size checks; this skips the
46
+ picker, not the validation.
47
+
48
+ Through a ref:
49
+
50
+ ```jsx
51
+ const importer = useRef(null)
52
+
53
+ <CSVBoxButton ref={importer} licenseKey="Sheet license key" user={{ user_id: "default123" }} onImport={onImport}>
54
+ Import
55
+ </CSVBoxButton>
56
+
57
+ <input type="file" onChange={(e) => importer.current.openModalWithFile(e.target.files[0])} />
58
+ ```
59
+
60
+ Or from the `render` prop, which is handed the same function as its third argument:
61
+
62
+ ```jsx
63
+ <CSVBoxButton
64
+ licenseKey="Sheet license key"
65
+ user={{ user_id: "default123" }}
66
+ onImport={onImport}
67
+ render={(launch, isLoading, launchWithFile) => (
68
+ <div
69
+ onDragOver={(e) => e.preventDefault()}
70
+ onDrop={(e) => {
71
+ e.preventDefault()
72
+ launchWithFile(e.dataTransfer.files[0])
73
+ }}
74
+ >
75
+ Drop a spreadsheet here, or <button disabled={isLoading} onClick={launch}>browse</button>
76
+ </div>
77
+ )}
78
+ />
79
+ ```
80
+
81
+ The importer can decline a file it is handed, and says why in a console warning
82
+ (`[csvbox] importer declined the supplied file: <reason>`):
83
+
84
+ - `import-in-progress` — the importer is open past its upload step, or is still reading an
85
+ earlier file. An import that is already open stays open.
86
+ - `modal-closing` — the importer was closing when the file arrived.
87
+ - `import-file-url-configured` — the sheet is set up to load its own file from a URL.
88
+
89
+ Pass a `File`, not a `Blob`: a `Blob` has no name to read an extension from, and anything that
90
+ is not a `File` is ignored.
91
+
92
+ When the importer redirects to another host (data-location sheets do this), the file is sent to the host the importer actually ended up on, as long as that host is your importer domain or `<region>-<your domain>` (for example `eu-app.csvbox.io` for `app.csvbox.io`). A file is never sent to any other host.
93
+
94
+ If the importer does not answer a supplied file within about 8 seconds (for example because it redirected to a host that does not follow that naming, or it is too old to know the message), the importer is put away, the other buttons are enabled again, and the console says `[csvbox] the importer did not respond to the supplied file`.
95
+
96
+ ## Several importers on one page
97
+
98
+ While an importer is open (or still loading to open), the button of every other CSVBox instance on the page is disabled until it closes, so two importers are not opened by accident. In React, the second argument of the `render` prop (`isLoading`) is also `true` in that state, so a custom trigger can disable itself the same way.
99
+
100
+ Opening a second importer from code (`openModal()` or `openModalWithFile()`) is still possible. The importer opened last is shown on top of the others, and closing it reveals the one underneath.
101
+
41
102
  ## Readme
42
103
 
43
104
  For usage see the guide here - https://help.csvbox.io/getting-started#2-install-code
package/dist/index.js CHANGED
@@ -28,7 +28,61 @@ function _assertThisInitialized(self) {
28
28
  return self;
29
29
  }
30
30
 
31
- var version = "1.1.14";
31
+ var version = "1.1.17";
32
+
33
+ var FILE_ACK_TIMEOUT_MS = 8000;
34
+ var OPEN_IMPORTERS_KEY = '__csvboxOpenImporters';
35
+ var TOP_Z_INDEX = 2147483647;
36
+
37
+ function openImporters() {
38
+ if (!window[OPEN_IMPORTERS_KEY]) window[OPEN_IMPORTERS_KEY] = {
39
+ open: [],
40
+ listeners: []
41
+ };
42
+ return window[OPEN_IMPORTERS_KEY];
43
+ }
44
+
45
+ function restackOpenImporters(reg) {
46
+ reg.open.forEach(function (entry, i) {
47
+ var holder = entry.getHolder();
48
+ if (holder) holder.style.zIndex = String(TOP_Z_INDEX - (reg.open.length - 1 - i));
49
+ });
50
+ }
51
+
52
+ function registerOpenImporter(entry) {
53
+ var reg = openImporters();
54
+ if (reg.open.indexOf(entry) >= 0) return;
55
+ reg.open.push(entry);
56
+ restackOpenImporters(reg);
57
+ reg.listeners.slice().forEach(function (fn) {
58
+ fn();
59
+ });
60
+ }
61
+
62
+ function unregisterOpenImporter(entry) {
63
+ var reg = openImporters();
64
+ var i = reg.open.indexOf(entry);
65
+ if (i < 0) return;
66
+ reg.open.splice(i, 1);
67
+ restackOpenImporters(reg);
68
+ reg.listeners.slice().forEach(function (fn) {
69
+ fn();
70
+ });
71
+ }
72
+
73
+ function isBlockedByOpenImporter(entry) {
74
+ var reg = openImporters();
75
+ return reg.open.length > 0 && reg.open.indexOf(entry) < 0;
76
+ }
77
+
78
+ function subscribeOpenImporters(fn) {
79
+ var reg = openImporters();
80
+ reg.listeners.push(fn);
81
+ return function () {
82
+ var i = reg.listeners.indexOf(fn);
83
+ if (i >= 0) reg.listeners.splice(i, 1);
84
+ };
85
+ }
32
86
 
33
87
  var CSVBoxButton = /*#__PURE__*/function (_Component) {
34
88
  _inheritsLoose(CSVBoxButton, _Component);
@@ -39,45 +93,84 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
39
93
  _this = _Component.call(this, props) || this;
40
94
  _this.holder = React__default.createRef();
41
95
  _this.openModal = _this.openModal.bind(_assertThisInitialized(_this));
96
+ _this.openModalWithFile = _this.openModalWithFile.bind(_assertThisInitialized(_this));
42
97
  _this.lifecycle = adapterCore.createModalLifecycle();
98
+ _this.isModalShown = false;
99
+ _this.isReady = false;
100
+ _this.pendingFile = null;
43
101
  _this.uuid = adapterCore.generateUuid();
44
102
  _this.state = {
45
- isLoading: true
103
+ isLoading: true,
104
+ blocked: false
46
105
  };
47
106
  _this.iframe = null;
107
+ _this.registryEntry = {
108
+ getHolder: function getHolder() {
109
+ return _this.holder.current;
110
+ }
111
+ };
112
+ _this.fileSender = adapterCore.createFileSender({
113
+ getIframe: function getIframe() {
114
+ return _this.iframe;
115
+ },
116
+ getToken: function getToken() {
117
+ return _this.uuid;
118
+ },
119
+ getTargetOrigin: function getTargetOrigin() {
120
+ return _this.targetOrigin;
121
+ },
122
+ getBaseDomain: function getBaseDomain() {
123
+ return _this.baseDomain;
124
+ },
125
+ takeFile: function takeFile() {
126
+ var file = _this.pendingFile;
127
+ _this.pendingFile = null;
128
+ return file;
129
+ },
130
+ onSent: function onSent() {
131
+ return _this.startFileAckTimer();
132
+ }
133
+ });
48
134
  return _this;
49
135
  }
50
136
 
51
137
  var _proto = CSVBoxButton.prototype;
52
138
 
53
139
  _proto.componentDidMount = function componentDidMount() {
140
+ var _this2 = this;
141
+
142
+ this.syncBlocked();
143
+ this.unsubscribeOpenImporters = subscribeOpenImporters(function () {
144
+ return _this2.syncBlocked();
145
+ });
54
146
  var lazy = this.props.lazy;
55
147
 
56
148
  if (!lazy && !this.iframe) {
57
149
  this.initImporter();
58
150
  } else if (lazy) {
59
- this.enableInitator();
151
+ this.enableInitiator();
60
152
  }
61
153
  };
62
154
 
63
155
  _proto.initImporter = function initImporter() {
64
- var _this2 = this;
65
-
66
- var loadStarted = this.props.loadStarted;
156
+ var _this3 = this;
157
+
158
+ var _this$props = this.props,
159
+ loadStarted = _this$props.loadStarted,
160
+ user = _this$props.user,
161
+ dynamicColumns = _this$props.dynamicColumns,
162
+ options = _this$props.options,
163
+ onReady = _this$props.onReady,
164
+ onImport = _this$props.onImport,
165
+ onSubmit = _this$props.onSubmit,
166
+ onClose = _this$props.onClose,
167
+ licenseKey = _this$props.licenseKey,
168
+ dataLocation = _this$props.dataLocation,
169
+ customDomain = _this$props.customDomain,
170
+ language = _this$props.language,
171
+ environment = _this$props.environment,
172
+ theme = _this$props.theme;
67
173
  loadStarted === null || loadStarted === void 0 ? void 0 : loadStarted();
68
- var user = this.props.user;
69
- var dynamicColumns = this.props.dynamicColumns;
70
- var options = this.props.options;
71
- var onReady = this.props.onReady;
72
- var onImport = this.props.onImport;
73
- var onSubmit = this.props.onSubmit;
74
- var onClose = this.props.onClose;
75
- var licenseKey = this.props.licenseKey;
76
- var dataLocation = this.props.dataLocation;
77
- var customDomain = this.props.customDomain;
78
- var language = this.props.language;
79
- var environment = this.props.environment;
80
- var theme = this.props.theme;
81
174
  var iframeUrl = adapterCore.buildImportUrl({
82
175
  licenseKey: licenseKey,
83
176
  customDomain: customDomain,
@@ -86,16 +179,26 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
86
179
  theme: theme,
87
180
  environment: environment
88
181
  }, "react", version);
182
+ this.targetOrigin = new URL(iframeUrl).origin;
183
+ this.baseDomain = customDomain || "app.csvbox.io";
184
+ this.fileSender.reset();
89
185
 
90
186
  var handleModalClosed = function handleModalClosed() {
91
- if (_this2.holder && _this2.holder.current) {
92
- _this2.holder.current.style.display = 'none';
93
- _this2.holder.current.innerHTML = '';
187
+ if (_this3.holder.current) {
188
+ _this3.holder.current.style.display = 'none';
189
+ _this3.holder.current.style.pointerEvents = 'auto';
190
+ _this3.holder.current.innerHTML = '';
94
191
  }
95
192
 
96
- _this2.lifecycle.markClosed();
193
+ _this3.lifecycle.markClosed();
97
194
 
98
- _this2.iframe = null;
195
+ _this3.isModalShown = false;
196
+ _this3.isReady = false;
197
+ _this3.iframe = null;
198
+
199
+ _this3.clearProbeTimer();
200
+
201
+ unregisterOpenImporter(_this3.registryEntry);
99
202
  onClose === null || onClose === void 0 ? void 0 : onClose();
100
203
  };
101
204
 
@@ -107,6 +210,10 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
107
210
  var legacy = adapterCore.classifyLegacyMessage(event.data);
108
211
 
109
212
  if (legacy) {
213
+ if (!_this3.iframe || event.source !== _this3.iframe.contentWindow) {
214
+ return;
215
+ }
216
+
110
217
  if (legacy.type === "mainModalHidden") {
111
218
  handleModalClosed();
112
219
  }
@@ -122,7 +229,46 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
122
229
  return;
123
230
  }
124
231
 
125
- var message = adapterCore.classifyStructuredMessage(event.data, _this2.uuid);
232
+ var raw = event.data;
233
+
234
+ if (raw && typeof raw === "object" && raw.data && raw.data.unique_token == _this3.uuid) {
235
+ _this3.fileSender.learnOrigin(event);
236
+
237
+ if (raw.type === "csvbox-set-file-rejected" && raw.data.reason === "not-a-file") {
238
+ return;
239
+ }
240
+
241
+ if (raw.type === "csvbox-modal-shown") {
242
+ _this3.clearFileAckTimer();
243
+
244
+ registerOpenImporter(_this3.registryEntry);
245
+ _this3.isModalShown = true;
246
+
247
+ _this3.lifecycle.requestOpen();
248
+
249
+ if (_this3.holder.current) {
250
+ _this3.holder.current.style.display = 'block';
251
+ _this3.holder.current.style.pointerEvents = 'auto';
252
+ }
253
+
254
+ return;
255
+ }
256
+
257
+ if (raw.type === "csvbox-set-file-rejected") {
258
+ _this3.clearFileAckTimer();
259
+
260
+ if (!_this3.isModalShown && _this3.holder.current) {
261
+ _this3.holder.current.style.display = 'none';
262
+ _this3.holder.current.style.pointerEvents = 'auto';
263
+ unregisterOpenImporter(_this3.registryEntry);
264
+ }
265
+
266
+ console.warn("[csvbox] importer declined the supplied file: " + raw.data.reason);
267
+ return;
268
+ }
269
+ }
270
+
271
+ var message = adapterCore.classifyStructuredMessage(event.data, _this3.uuid);
126
272
 
127
273
  if (!message) {
128
274
  return;
@@ -143,21 +289,24 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
143
289
 
144
290
  window.addEventListener("message", this.messageListener, false);
145
291
  this.uuid = adapterCore.generateUuid();
146
- var self = this;
147
292
  var iframe = document.createElement("iframe");
148
293
  this.iframe = iframe;
149
294
  iframe.setAttribute("src", iframeUrl);
295
+ iframe.setAttribute("allow", "clipboard-read; clipboard-write *");
150
296
  iframe.frameBorder = 0;
151
297
  iframe.classList.add('csvbox-iframe');
152
298
  Object.assign(iframe.style, adapterCore.IFRAME_STYLE);
153
299
 
154
300
  iframe.onload = function () {
155
- self.enableInitator();
156
- iframe.contentWindow.postMessage(adapterCore.buildInitPayload(user, dynamicColumns, options, self.uuid), "*");
301
+ _this3.isReady = true;
302
+
303
+ _this3.enableInitiator();
304
+
305
+ iframe.contentWindow.postMessage(adapterCore.buildInitPayload(user, dynamicColumns, options, _this3.uuid), "*");
157
306
  onReady === null || onReady === void 0 ? void 0 : onReady();
158
307
 
159
- if (self.lifecycle.markReady()) {
160
- self.openModal();
308
+ if (_this3.lifecycle.markReady()) {
309
+ _this3.openModal();
161
310
  }
162
311
  };
163
312
 
@@ -165,19 +314,114 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
165
314
  };
166
315
 
167
316
  _proto.openModal = function openModal() {
317
+ registerOpenImporter(this.registryEntry);
318
+
168
319
  if (!this.iframe) {
169
320
  this.lifecycle.requestOpen();
170
321
  this.initImporter();
171
322
  return;
172
323
  }
173
324
 
325
+ if (this.pendingFile) {
326
+ if (!this.isReady) {
327
+ this.lifecycle.requestOpen();
328
+ return;
329
+ }
330
+
331
+ this.holder.current.style.pointerEvents = 'none';
332
+ this.holder.current.style.display = 'block';
333
+ this.fileSender.send();
334
+ return;
335
+ }
336
+
174
337
  if (this.lifecycle.requestOpen()) {
338
+ this.isModalShown = true;
175
339
  this.iframe.contentWindow.postMessage('openModal', '*');
340
+ this.holder.current.style.pointerEvents = 'auto';
176
341
  this.holder.current.style.display = 'block';
177
342
  }
178
343
  };
179
344
 
180
- _proto.enableInitator = function enableInitator() {
345
+ _proto.openModalWithFile = function openModalWithFile(file) {
346
+ if (!window.File || !(file instanceof window.File)) {
347
+ return;
348
+ }
349
+
350
+ this.pendingFile = file;
351
+
352
+ if (this.isModalShown && this.iframe && this.isReady) {
353
+ this.fileSender.send();
354
+ return;
355
+ }
356
+
357
+ this.openModal();
358
+ };
359
+
360
+ _proto.clearProbeTimer = function clearProbeTimer() {
361
+ this.clearFileAckTimer();
362
+ this.fileSender.reset();
363
+ };
364
+
365
+ _proto.startFileAckTimer = function startFileAckTimer() {
366
+ var _this4 = this;
367
+
368
+ this.clearFileAckTimer();
369
+ this.fileAckTimer = setTimeout(function () {
370
+ _this4.fileAckTimer = null;
371
+
372
+ _this4.giveUpOnFile();
373
+ }, FILE_ACK_TIMEOUT_MS);
374
+ };
375
+
376
+ _proto.clearFileAckTimer = function clearFileAckTimer() {
377
+ if (this.fileAckTimer) {
378
+ clearTimeout(this.fileAckTimer);
379
+ this.fileAckTimer = null;
380
+ }
381
+ };
382
+
383
+ _proto.giveUpOnFile = function giveUpOnFile() {
384
+ if (this.isModalShown) {
385
+ return;
386
+ }
387
+
388
+ var holder = this.holder.current;
389
+
390
+ if (holder) {
391
+ holder.style.display = 'none';
392
+ holder.style.pointerEvents = 'auto';
393
+ }
394
+
395
+ unregisterOpenImporter(this.registryEntry);
396
+ console.warn("[csvbox] the importer did not respond to the supplied file");
397
+ };
398
+
399
+ _proto.componentWillUnmount = function componentWillUnmount() {
400
+ this.clearProbeTimer();
401
+ unregisterOpenImporter(this.registryEntry);
402
+
403
+ if (this.unsubscribeOpenImporters) {
404
+ this.unsubscribeOpenImporters();
405
+ this.unsubscribeOpenImporters = null;
406
+ }
407
+
408
+ if (this.messageListener) {
409
+ window.removeEventListener("message", this.messageListener, false);
410
+ this.messageListener = null;
411
+ }
412
+ };
413
+
414
+ _proto.syncBlocked = function syncBlocked() {
415
+ var blocked = isBlockedByOpenImporter(this.registryEntry);
416
+
417
+ if (blocked !== this.state.blocked) {
418
+ this.setState({
419
+ blocked: blocked
420
+ });
421
+ }
422
+ };
423
+
424
+ _proto.enableInitiator = function enableInitiator() {
181
425
  this.setState({
182
426
  isLoading: false
183
427
  });
@@ -185,21 +429,21 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
185
429
 
186
430
  _proto.render = function render() {
187
431
  if (this.props.render) {
188
- return /*#__PURE__*/React__default.createElement("div", null, this.props.render(this.openModal, this.state.isLoading), /*#__PURE__*/React__default.createElement("div", {
189
- ref: this.holder,
190
- style: adapterCore.HOLDER_STYLE
191
- }));
192
- } else {
193
- return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("button", {
194
- disabled: this.state.isLoading,
195
- onClick: this.openModal,
196
- "data-csvbox-initator": true,
197
- "data-csvbox-token": this.uuid
198
- }, this.props.children), /*#__PURE__*/React__default.createElement("div", {
432
+ return /*#__PURE__*/React__default.createElement("div", null, this.props.render(this.openModal, this.state.isLoading || this.state.blocked, this.openModalWithFile), /*#__PURE__*/React__default.createElement("div", {
199
433
  ref: this.holder,
200
434
  style: adapterCore.HOLDER_STYLE
201
435
  }));
202
436
  }
437
+
438
+ return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("button", {
439
+ disabled: this.state.isLoading || this.state.blocked,
440
+ onClick: this.openModal,
441
+ "data-csvbox-initator": true,
442
+ "data-csvbox-token": this.uuid
443
+ }, this.props.children), /*#__PURE__*/React__default.createElement("div", {
444
+ ref: this.holder,
445
+ style: adapterCore.HOLDER_STYLE
446
+ }));
203
447
  };
204
448
 
205
449
  return CSVBoxButton;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["import React, { Component } from 'react';\nimport { version } from '../package.json';\nimport {\n\tHOLDER_STYLE,\n\tIFRAME_STYLE,\n\tbuildImportUrl,\n\tgenerateUuid,\n\tbuildInitPayload,\n\tcreateModalLifecycle,\n\tclassifyStructuredMessage,\n\tclassifyLegacyMessage\n} from '@sumit_yewale/adapter-core';\n\nexport class CSVBoxButton extends Component {\n\n\tconstructor(props) {\n\t\tsuper(props)\n\t\tthis.holder = React.createRef();\n\t\tthis.openModal = this.openModal.bind(this)\n\t\tthis.lifecycle = createModalLifecycle();\n\t\tthis.uuid = generateUuid();\n\t\tthis.state = {\n\t\t\tisLoading: true\n\t\t};\n\t\tthis.iframe = null;\n\t}\n\n\tcomponentDidMount() {\n\t\tconst { lazy } = this.props;\n\t\tif (!lazy && !this.iframe) {\n\t\t\tthis.initImporter();\n\t\t} else if (lazy) {\n\t\t\tthis.enableInitator();\n\t\t}\n\t}\n\n\tinitImporter() {\n\n\t\tconst { loadStarted } = this.props;\n\n\t\tloadStarted?.();\n\n\t\tconst { user } = this.props;\n\t\tconst { dynamicColumns } = this.props;\n\t\tconst { options } = this.props;\n\t\tconst { onReady } = this.props;\n\t\tconst { onImport } = this.props;\n\t\tconst { onSubmit } = this.props;\n\t\tconst { onClose } = this.props;\n\t\tconst { licenseKey } = this.props;\n\t\tconst { dataLocation } = this.props;\n\t\tconst { customDomain } = this.props;\n\t\tconst { language } = this.props;\n\t\tconst { environment } = this.props;\n\t\tconst { theme } = this.props;\n\n\t\tlet iframeUrl = buildImportUrl(\n\t\t\t{ licenseKey, customDomain, dataLocation, language, theme, environment },\n\t\t\t\"react\",\n\t\t\tversion\n\t\t);\n\n\t\tlet handleModalClosed = () => {\n\t\t\tif (this.holder && this.holder.current) {\n\t\t\t\tthis.holder.current.style.display = 'none';\n\t\t\t\tthis.holder.current.innerHTML = '';\n\t\t\t}\n\t\t\tthis.lifecycle.markClosed();\n\t\t\tthis.iframe = null;\n\t\t\tonClose?.();\n\t\t};\n\n\t\tif (this.messageListener) {\n\t\t\twindow.removeEventListener(\"message\", this.messageListener, false);\n\t\t}\n\n\t\tthis.messageListener = (event) => {\n\n\t\t\tlet legacy = classifyLegacyMessage(event.data);\n\t\t\tif (legacy) {\n\t\t\t\tif (legacy.type === \"mainModalHidden\") {\n\t\t\t\t\thandleModalClosed();\n\t\t\t\t}\n\t\t\t\tif (legacy.type === \"uploadSuccessful\") {\n\t\t\t\t\tonImport(true);\n\t\t\t\t}\n\t\t\t\tif (legacy.type === \"uploadFailed\") {\n\t\t\t\t\tonImport(false);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet message = classifyStructuredMessage(event.data, this.uuid);\n\t\t\tif (!message) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (message.type === \"data-on-submit\") {\n\t\t\t\tonSubmit?.(message.metadata);\n\t\t\t} else if (message.type === \"data-push-status\") {\n\t\t\t\tonImport(message.success, message.metadata);\n\t\t\t} else if (message.type === \"csvbox-modal-hidden\") {\n\t\t\t\thandleModalClosed();\n\t\t\t} else if (message.type === \"csvbox-upload-successful\") {\n\t\t\t\tonImport(true);\n\t\t\t} else if (message.type === \"csvbox-upload-failed\") {\n\t\t\t\tonImport(false);\n\t\t\t}\n\n\t\t};\n\n\t\twindow.addEventListener(\"message\", this.messageListener, false);\n\n\t\tthis.uuid = generateUuid();\n\n\t\tlet self = this;\n\n\t\tlet iframe = document.createElement(\"iframe\");\n\t\tthis.iframe = iframe;\n\t\tiframe.setAttribute(\"src\", iframeUrl);\n\t\tiframe.frameBorder = 0;\n\t\tiframe.classList.add('csvbox-iframe');\n\n\t\tObject.assign(iframe.style, IFRAME_STYLE);\n\n\t\tiframe.onload = function () {\n\t\t\tself.enableInitator();\n\t\t\tiframe.contentWindow.postMessage(buildInitPayload(user, dynamicColumns, options, self.uuid), \"*\");\n\t\t\tonReady?.();\n\t\t\tif (self.lifecycle.markReady()) {\n\t\t\t\tself.openModal();\n\t\t\t}\n\t\t}\n\t\tthis.holder.current.appendChild(iframe);\n\t}\n\n\topenModal() {\n\n\t\tif (!this.iframe) {\n\t\t\tthis.lifecycle.requestOpen();\n\t\t\tthis.initImporter();\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.lifecycle.requestOpen()) {\n\t\t\tthis.iframe.contentWindow.postMessage('openModal', '*');\n\t\t\tthis.holder.current.style.display = 'block';\n\t\t}\n\n\t}\n\n\tenableInitator() {\n\t\tthis.setState({\n\t\t\tisLoading: false\n\t\t})\n\t}\n\n\trender() {\n\n\t\tif (this.props.render) {\n\t\t\treturn (\n\t\t\t\t<div>\n\t\t\t\t\t{this.props.render(this.openModal, this.state.isLoading)}\n\t\t\t\t\t<div ref={this.holder} style={HOLDER_STYLE}></div>\n\t\t\t\t</div>\n\t\t\t)\n\t\t} else {\n\t\t\treturn (\n\t\t\t\t<div>\n\t\t\t\t\t<button disabled={this.state.isLoading} onClick={this.openModal} data-csvbox-initator data-csvbox-token={this.uuid}>{this.props.children}</button>\n\t\t\t\t\t<div ref={this.holder} style={HOLDER_STYLE}></div>\n\t\t\t\t</div>\n\t\t\t)\n\t\t}\n\n\n\t}\n}\n\nexport default CSVBoxButton;\n"],"names":["CSVBoxButton","props","holder","React","createRef","openModal","bind","lifecycle","createModalLifecycle","uuid","generateUuid","state","isLoading","iframe","componentDidMount","lazy","initImporter","enableInitator","loadStarted","user","dynamicColumns","options","onReady","onImport","onSubmit","onClose","licenseKey","dataLocation","customDomain","language","environment","theme","iframeUrl","buildImportUrl","version","handleModalClosed","current","style","display","innerHTML","markClosed","messageListener","window","removeEventListener","event","legacy","classifyLegacyMessage","data","type","message","classifyStructuredMessage","metadata","success","addEventListener","self","document","createElement","setAttribute","frameBorder","classList","add","Object","assign","IFRAME_STYLE","onload","contentWindow","postMessage","buildInitPayload","markReady","appendChild","requestOpen","setState","render","HOLDER_STYLE","children","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,CAAoBC,KAApB,CAA0BC,OAA1B,GAAoC,OAApC;AACA;AAED,GAxIF;;AAAA,SA0ICrB,cA1ID,GA0IC,0BAAiB;AAChB,SAAKsD,QAAL,CAAc;AACb3D,MAAAA,SAAS,EAAE;AADE,KAAd;AAGA,GA9IF;;AAAA,SAgJC4D,MAhJD,GAgJC,kBAAS;AAER,QAAI,KAAKvE,KAAL,CAAWuE,MAAf,EAAuB;AACtB,0BACCrE,0CACE,KAAKF,KAAL,CAAWuE,MAAX,CAAkB,KAAKnE,SAAvB,EAAkC,KAAKM,KAAL,CAAWC,SAA7C,CADF,eAECT;AAAK,QAAA,GAAG,EAAE,KAAKD,MAAf;AAAuB,QAAA,KAAK,EAAEuE;AAA9B,QAFD,CADD;AAMA,KAPD,MAOO;AACN,0BACCtE,uDACCA;AAAQ,QAAA,QAAQ,EAAE,KAAKQ,KAAL,CAAWC,SAA7B;AAAwC,QAAA,OAAO,EAAE,KAAKP,SAAtD;AAAiE,oCAAjE;AAAsF,6BAAmB,KAAKI;AAA9G,SAAqH,KAAKR,KAAL,CAAWyE,QAAhI,CADD,eAECvE;AAAK,QAAA,GAAG,EAAE,KAAKD,MAAf;AAAuB,QAAA,KAAK,EAAEuE;AAA9B,QAFD,CADD;AAMA;AAGD,GAnKF;;AAAA;AAAA,EAAkCE,eAAlC;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["import React, { Component } from 'react';\nimport { version } from '../package.json';\nimport {\n\tHOLDER_STYLE,\n\tIFRAME_STYLE,\n\tbuildImportUrl,\n\tgenerateUuid,\n\tbuildInitPayload,\n\tcreateModalLifecycle,\n\tcreateFileSender,\n\tclassifyStructuredMessage,\n\tclassifyLegacyMessage\n} from '@sumit_yewale/adapter-core';\n\n// How long we wait for the importer to confirm a file it was sent before giving up on it.\nconst FILE_ACK_TIMEOUT_MS = 8000;\n\n// Page-wide record of the importers that are open or opening, shared by every CSVBox adapter\n// on the page (it lives on window so separate copies of an adapter see the same list). It does\n// two things: the newest importer is stacked on top (every holder is fixed, full screen and\n// z-index 2147483647, so equal z-indexes would leave the one that comes first in the DOM on\n// top), and the other instances learn that an importer is open so they can disable their button.\nconst OPEN_IMPORTERS_KEY = '__csvboxOpenImporters';\nconst TOP_Z_INDEX = 2147483647;\n\nfunction openImporters() {\n\tif (!window[OPEN_IMPORTERS_KEY]) window[OPEN_IMPORTERS_KEY] = { open: [], listeners: [] };\n\treturn window[OPEN_IMPORTERS_KEY];\n}\n\nfunction restackOpenImporters(reg) {\n\treg.open.forEach(function (entry, i) {\n\t\tconst holder = entry.getHolder();\n\t\tif (holder) holder.style.zIndex = String(TOP_Z_INDEX - (reg.open.length - 1 - i));\n\t});\n}\n\nfunction registerOpenImporter(entry) {\n\tconst reg = openImporters();\n\tif (reg.open.indexOf(entry) >= 0) return;\n\treg.open.push(entry);\n\trestackOpenImporters(reg);\n\treg.listeners.slice().forEach(function (fn) { fn(); });\n}\n\nfunction unregisterOpenImporter(entry) {\n\tconst reg = openImporters();\n\tconst i = reg.open.indexOf(entry);\n\tif (i < 0) return;\n\treg.open.splice(i, 1);\n\trestackOpenImporters(reg);\n\treg.listeners.slice().forEach(function (fn) { fn(); });\n}\n\nfunction isBlockedByOpenImporter(entry) {\n\tconst reg = openImporters();\n\treturn reg.open.length > 0 && reg.open.indexOf(entry) < 0;\n}\n\nfunction subscribeOpenImporters(fn) {\n\tconst reg = openImporters();\n\treg.listeners.push(fn);\n\treturn function () {\n\t\tconst i = reg.listeners.indexOf(fn);\n\t\tif (i >= 0) reg.listeners.splice(i, 1);\n\t};\n}\n\nexport class CSVBoxButton extends Component {\n\n\tconstructor(props) {\n\t\tsuper(props);\n\t\tthis.holder = React.createRef();\n\t\tthis.openModal = this.openModal.bind(this);\n\t\tthis.openModalWithFile = this.openModalWithFile.bind(this);\n\t\tthis.lifecycle = createModalLifecycle();\n\t\tthis.isModalShown = false;\n\t\tthis.isReady = false;\n\t\tthis.pendingFile = null;\n\t\tthis.uuid = generateUuid();\n\t\tthis.state = {\n\t\t\tisLoading: true,\n\t\t\t// True while a different importer on the page is open: the button stays disabled.\n\t\t\tblocked: false\n\t\t};\n\t\tthis.iframe = null;\n\t\tthis.registryEntry = { getHolder: () => this.holder.current };\n\t\tthis.fileSender = createFileSender({\n\t\t\tgetIframe: () => this.iframe,\n\t\t\tgetToken: () => this.uuid,\n\t\t\tgetTargetOrigin: () => this.targetOrigin,\n\t\t\tgetBaseDomain: () => this.baseDomain,\n\t\t\ttakeFile: () => {\n\t\t\t\tconst file = this.pendingFile;\n\t\t\t\tthis.pendingFile = null;\n\t\t\t\treturn file;\n\t\t\t},\n\t\t\tonSent: () => this.startFileAckTimer()\n\t\t});\n\t}\n\n\tcomponentDidMount() {\n\t\tthis.syncBlocked();\n\t\tthis.unsubscribeOpenImporters = subscribeOpenImporters(() => this.syncBlocked());\n\t\tconst { lazy } = this.props;\n\t\tif (!lazy && !this.iframe) {\n\t\t\tthis.initImporter();\n\t\t} else if (lazy) {\n\t\t\tthis.enableInitiator();\n\t\t}\n\t}\n\n\tinitImporter() {\n\t\tconst {\n\t\t\tloadStarted, user, dynamicColumns, options, onReady, onImport,\n\t\t\tonSubmit, onClose, licenseKey, dataLocation, customDomain,\n\t\t\tlanguage, environment, theme\n\t\t} = this.props;\n\n\t\tloadStarted?.();\n\n\t\tconst iframeUrl = buildImportUrl(\n\t\t\t{ licenseKey, customDomain, dataLocation, language, theme, environment },\n\t\t\t\"react\",\n\t\t\tversion\n\t\t);\n\n\t\t// Default place to send the file. A file is only ever sent to a named origin, never \"*\".\n\t\tthis.targetOrigin = new URL(iframeUrl).origin;\n\n\t\t// Data-location sheets redirect to another host, so the iframe origin can differ from\n\t\t// targetOrigin. We use this domain to check the real origin before trusting it.\n\t\tthis.baseDomain = customDomain || \"app.csvbox.io\";\n\t\tthis.fileSender.reset();\n\n\t\tconst handleModalClosed = () => {\n\t\t\tif (this.holder.current) {\n\t\t\t\tthis.holder.current.style.display = 'none';\n\t\t\t\tthis.holder.current.style.pointerEvents = 'auto';\n\t\t\t\tthis.holder.current.innerHTML = '';\n\t\t\t}\n\t\t\tthis.lifecycle.markClosed();\n\t\t\tthis.isModalShown = false;\n\t\t\tthis.isReady = false;\n\t\t\tthis.iframe = null;\n\t\t\t// A new iframe is built on the next open, so the origin is learned again.\n\t\t\tthis.clearProbeTimer();\n\t\t\tunregisterOpenImporter(this.registryEntry);\n\t\t\tonClose?.();\n\t\t};\n\n\t\tif (this.messageListener) {\n\t\t\twindow.removeEventListener(\"message\", this.messageListener, false);\n\t\t}\n\n\t\tthis.messageListener = (event) => {\n\t\t\tconst legacy = classifyLegacyMessage(event.data);\n\t\t\tif (legacy) {\n\t\t\t\t// Legacy messages carry no token, so the only way to tell which importer sent one is\n\t\t\t\t// its window. Ignore those that came from another instance's iframe (or anywhere else).\n\t\t\t\tif (!this.iframe || event.source !== this.iframe.contentWindow) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (legacy.type === \"mainModalHidden\") {\n\t\t\t\t\thandleModalClosed();\n\t\t\t\t}\n\t\t\t\tif (legacy.type === \"uploadSuccessful\") {\n\t\t\t\t\tonImport(true);\n\t\t\t\t}\n\t\t\t\tif (legacy.type === \"uploadFailed\") {\n\t\t\t\t\tonImport(false);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Set-file handshake messages. The shared core does not classify these, so they are\n\t\t\t// read here, behind the same unique_token check the core applies.\n\t\t\tconst raw = event.data;\n\t\t\tif (raw && typeof raw === \"object\" && raw.data && raw.data.unique_token == this.uuid) {\n\t\t\t\tthis.fileSender.learnOrigin(event);\n\n\t\t\t\tif (raw.type === \"csvbox-set-file-rejected\" && raw.data.reason === \"not-a-file\") {\n\t\t\t\t\t// Reply to our probe (it has no file). It only tells us the origin, so do nothing.\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (raw.type === \"csvbox-modal-shown\") {\n\t\t\t\t\tthis.clearFileAckTimer();\n\t\t\t\t\tregisterOpenImporter(this.registryEntry);\n\t\t\t\t\t// What the file path in openModal() is waiting for. display as well as\n\t\t\t\t\t// pointer-events: a second file declined while the first was still opening the\n\t\t\t\t\t// modal has put the holder away in the meantime.\n\t\t\t\t\tthis.isModalShown = true;\n\t\t\t\t\tthis.lifecycle.requestOpen();\n\t\t\t\t\tif (this.holder.current) {\n\t\t\t\t\t\tthis.holder.current.style.display = 'block';\n\t\t\t\t\t\tthis.holder.current.style.pointerEvents = 'auto';\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (raw.type === \"csvbox-set-file-rejected\") {\n\t\t\t\t\tthis.clearFileAckTimer();\n\t\t\t\t\t// The importer has the file and will not take it. Put the holder away only if the\n\t\t\t\t\t// modal was never confirmed up: a file declined while it is open (an import past\n\t\t\t\t\t// the upload step, a fade-out under way) leaves that modal where it is, and its\n\t\t\t\t\t// own 'csvbox-modal-hidden' will put the holder away when it closes.\n\t\t\t\t\tif (!this.isModalShown && this.holder.current) {\n\t\t\t\t\t\tthis.holder.current.style.display = 'none';\n\t\t\t\t\t\tthis.holder.current.style.pointerEvents = 'auto';\n\t\t\t\t\t\tunregisterOpenImporter(this.registryEntry);\n\t\t\t\t\t}\n\t\t\t\t\tconsole.warn(\"[csvbox] importer declined the supplied file: \" + raw.data.reason);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst message = classifyStructuredMessage(event.data, this.uuid);\n\t\t\tif (!message) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (message.type === \"data-on-submit\") {\n\t\t\t\tonSubmit?.(message.metadata);\n\t\t\t} else if (message.type === \"data-push-status\") {\n\t\t\t\tonImport(message.success, message.metadata);\n\t\t\t} else if (message.type === \"csvbox-modal-hidden\") {\n\t\t\t\thandleModalClosed();\n\t\t\t} else if (message.type === \"csvbox-upload-successful\") {\n\t\t\t\tonImport(true);\n\t\t\t} else if (message.type === \"csvbox-upload-failed\") {\n\t\t\t\tonImport(false);\n\t\t\t}\n\t\t};\n\n\t\twindow.addEventListener(\"message\", this.messageListener, false);\n\n\t\tthis.uuid = generateUuid();\n\n\t\tconst iframe = document.createElement(\"iframe\");\n\t\tthis.iframe = iframe;\n\t\tiframe.setAttribute(\"src\", iframeUrl);\n\t\tiframe.setAttribute(\"allow\", \"clipboard-read; clipboard-write *\");\n\t\tiframe.frameBorder = 0;\n\t\tiframe.classList.add('csvbox-iframe');\n\t\tObject.assign(iframe.style, IFRAME_STYLE);\n\n\t\tiframe.onload = () => {\n\t\t\tthis.isReady = true;\n\t\t\tthis.enableInitiator();\n\t\t\tiframe.contentWindow.postMessage(buildInitPayload(user, dynamicColumns, options, this.uuid), \"*\");\n\t\t\tonReady?.();\n\t\t\tif (this.lifecycle.markReady()) {\n\t\t\t\tthis.openModal();\n\t\t\t}\n\t\t};\n\n\t\tthis.holder.current.appendChild(iframe);\n\t}\n\n\topenModal() {\n\t\t// Counts as open from the moment it is requested, so the other buttons are disabled while\n\t\t// this importer is still loading, and so it is stacked above any importer opened earlier.\n\t\tregisterOpenImporter(this.registryEntry);\n\t\tif (!this.iframe) {\n\t\t\tthis.lifecycle.requestOpen();\n\t\t\tthis.initImporter();\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.pendingFile) {\n\t\t\tif (!this.isReady) {\n\t\t\t\t// Deferred: onload's markReady() calls openModal() again once the iframe is up.\n\t\t\t\tthis.lifecycle.requestOpen();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// The importer opens its own modal once it has the file, so that it can inject on\n\t\t\t// 'shown.bs.modal'. Sending 'openModal' as well would race that.\n\t\t\t//\n\t\t\t// It can also decline: wrong step, an import file URL configured on the sheet, or\n\t\t\t// an importer too old to know the message at all. So the holder goes up\n\t\t\t// click-through and stays that way until 'csvbox-modal-shown' confirms the modal\n\t\t\t// is really up. It covers the viewport at z-index 2147483647 and the importer\n\t\t\t// renders transparent with its modal closed, so arming it on an unanswered message\n\t\t\t// leaves an invisible sheet over the host page eating every click.\n\t\t\t//\n\t\t\t// display:block regardless, so the iframe lays out and animates normally; only\n\t\t\t// pointer-events is held back. isModalShown likewise waits for the confirmation,\n\t\t\t// or a declined file would latch the importer shut for good.\n\t\t\tthis.holder.current.style.pointerEvents = 'none';\n\t\t\tthis.holder.current.style.display = 'block';\n\t\t\tthis.fileSender.send();\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.lifecycle.requestOpen()) {\n\t\t\tthis.isModalShown = true;\n\t\t\tthis.iframe.contentWindow.postMessage('openModal', '*');\n\t\t\t// Explicit: a previously declined file leaves the holder click-through.\n\t\t\tthis.holder.current.style.pointerEvents = 'auto';\n\t\t\tthis.holder.current.style.display = 'block';\n\t\t}\n\t}\n\n\t/**\n\t * Open the importer on a File the host page already has, instead of the file picker.\n\t *\n\t * Reachable two ways: a ref on the component (`ref.current.openModalWithFile(file)`), or\n\t * the third argument handed to the `render` prop.\n\t *\n\t * The File crosses to the iframe by structured clone, so the importer receives the real\n\t * object and applies its own extension, worksheet and size rules to it -- this does not\n\t * bypass any of them. Pass a File; a Blob has no name for the importer to read an\n\t * extension from.\n\t */\n\topenModalWithFile(file) {\n\t\t// window.File, not a bare File: eslint-config-standard declares only window, document\n\t\t// and navigator as browser globals, so a bare File is a no-undef error here.\n\t\tif (!window.File || !(file instanceof window.File)) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.pendingFile = file;\n\n\t\t// Already open: hand it over now rather than holding it for the next open. The importer\n\t\t// takes it only while it is still on the upload step, and ignores it once the user has a\n\t\t// dataset and a mapping in progress.\n\t\tif (this.isModalShown && this.iframe && this.isReady) {\n\t\t\tthis.fileSender.send();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.openModal();\n\t}\n\n\tclearProbeTimer() {\n\t\tthis.clearFileAckTimer();\n\t\tthis.fileSender.reset();\n\t}\n\n\tstartFileAckTimer() {\n\t\tthis.clearFileAckTimer();\n\t\tthis.fileAckTimer = setTimeout(() => {\n\t\t\tthis.fileAckTimer = null;\n\t\t\tthis.giveUpOnFile();\n\t\t}, FILE_ACK_TIMEOUT_MS);\n\t}\n\n\tclearFileAckTimer() {\n\t\tif (this.fileAckTimer) {\n\t\t\tclearTimeout(this.fileAckTimer);\n\t\t\tthis.fileAckTimer = null;\n\t\t}\n\t}\n\n\t// The importer never confirmed the file it was sent (an origin we do not trust, or an importer too\n\t// old to know the message). Without this the holder would stay up, invisible and click-through,\n\t// and the other instances' buttons would stay disabled for good.\n\tgiveUpOnFile() {\n\t\tif (this.isModalShown) {\n\t\t\treturn;\n\t\t}\n\t\tconst holder = this.holder.current;\n\t\tif (holder) {\n\t\t\tholder.style.display = 'none';\n\t\t\tholder.style.pointerEvents = 'auto';\n\t\t}\n\t\tunregisterOpenImporter(this.registryEntry);\n\t\tconsole.warn(\"[csvbox] the importer did not respond to the supplied file\");\n\t}\n\n\tcomponentWillUnmount() {\n\t\tthis.clearProbeTimer();\n\t\tunregisterOpenImporter(this.registryEntry);\n\t\tif (this.unsubscribeOpenImporters) {\n\t\t\tthis.unsubscribeOpenImporters();\n\t\t\tthis.unsubscribeOpenImporters = null;\n\t\t}\n\t\tif (this.messageListener) {\n\t\t\twindow.removeEventListener(\"message\", this.messageListener, false);\n\t\t\tthis.messageListener = null;\n\t\t}\n\t}\n\n\tsyncBlocked() {\n\t\tconst blocked = isBlockedByOpenImporter(this.registryEntry);\n\t\tif (blocked !== this.state.blocked) {\n\t\t\tthis.setState({ blocked });\n\t\t}\n\t}\n\n\tenableInitiator() {\n\t\tthis.setState({\n\t\t\tisLoading: false\n\t\t});\n\t}\n\n\trender() {\n\t\tif (this.props.render) {\n\t\t\treturn (\n\t\t\t\t<div>\n\t\t\t\t\t{this.props.render(this.openModal, this.state.isLoading || this.state.blocked, this.openModalWithFile)}\n\t\t\t\t\t<div ref={this.holder} style={HOLDER_STYLE}></div>\n\t\t\t\t</div>\n\t\t\t)\n\t\t}\n\n\t\treturn (\n\t\t\t<div>\n\t\t\t\t<button disabled={this.state.isLoading || this.state.blocked} onClick={this.openModal} data-csvbox-initator data-csvbox-token={this.uuid}>{this.props.children}</button>\n\t\t\t\t<div ref={this.holder} style={HOLDER_STYLE}></div>\n\t\t\t</div>\n\t\t)\n\t}\n}\n\nexport default CSVBoxButton;\n"],"names":["FILE_ACK_TIMEOUT_MS","OPEN_IMPORTERS_KEY","TOP_Z_INDEX","openImporters","window","open","listeners","restackOpenImporters","reg","forEach","entry","i","holder","getHolder","style","zIndex","String","length","registerOpenImporter","indexOf","push","slice","fn","unregisterOpenImporter","splice","isBlockedByOpenImporter","subscribeOpenImporters","CSVBoxButton","props","React","createRef","openModal","bind","openModalWithFile","lifecycle","createModalLifecycle","isModalShown","isReady","pendingFile","uuid","generateUuid","state","isLoading","blocked","iframe","registryEntry","current","fileSender","createFileSender","getIframe","getToken","getTargetOrigin","targetOrigin","getBaseDomain","baseDomain","takeFile","file","onSent","startFileAckTimer","componentDidMount","syncBlocked","unsubscribeOpenImporters","lazy","initImporter","enableInitiator","loadStarted","user","dynamicColumns","options","onReady","onImport","onSubmit","onClose","licenseKey","dataLocation","customDomain","language","environment","theme","iframeUrl","buildImportUrl","version","URL","origin","reset","handleModalClosed","display","pointerEvents","innerHTML","markClosed","clearProbeTimer","messageListener","removeEventListener","event","legacy","classifyLegacyMessage","data","source","contentWindow","type","raw","unique_token","learnOrigin","reason","clearFileAckTimer","requestOpen","console","warn","message","classifyStructuredMessage","metadata","success","addEventListener","document","createElement","setAttribute","frameBorder","classList","add","Object","assign","IFRAME_STYLE","onload","postMessage","buildInitPayload","markReady","appendChild","send","File","fileAckTimer","setTimeout","giveUpOnFile","clearTimeout","componentWillUnmount","setState","render","HOLDER_STYLE","children","Component"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,IAAMA,mBAAmB,GAAG,IAA5B;AAOA,IAAMC,kBAAkB,GAAG,uBAA3B;AACA,IAAMC,WAAW,GAAG,UAApB;;AAEA,SAASC,aAAT,GAAyB;AACxB,MAAI,C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AKV,iBAAnF,CADF,eAECJ;AAAK,QAAA,GAAG,EAAE,KAAKjB,MAAf;AAAuB,QAAA,KAAK,EAAE4H;AAA9B,QAFD,CADD;AAMA;;AAED,wBACC3G,uDACCA;AAAQ,MAAA,QAAQ,EAAE,KAAKY,KAAL,CAAWC,SAAX,IAAwB,KAAKD,KAAL,CAAWE,OAArD;AAA8D,MAAA,OAAO,EAAE,KAAKZ,SAA5E;AAAuF,kCAAvF;AAA4G,2BAAmB,KAAKQ;AAApI,OAA2I,KAAKX,KAAL,CAAW6G,QAAtJ,CADD,eAEC5G;AAAK,MAAA,GAAG,EAAE,KAAKjB,MAAf;AAAuB,MAAA,KAAK,EAAE4H;AAA9B,MAFD,CADD;AAMA,GAvVF;;AAAA;AAAA,EAAkCE,eAAlC;;;;;"}
@@ -1,5 +1,5 @@
1
1
  import React, { Component } from 'react';
2
- import { buildImportUrl, classifyLegacyMessage, classifyStructuredMessage, generateUuid, IFRAME_STYLE, buildInitPayload, HOLDER_STYLE, createModalLifecycle } from '@sumit_yewale/adapter-core';
2
+ import { buildImportUrl, classifyLegacyMessage, classifyStructuredMessage, generateUuid, IFRAME_STYLE, buildInitPayload, HOLDER_STYLE, createModalLifecycle, createFileSender } from '@sumit_yewale/adapter-core';
3
3
 
4
4
  function _inheritsLoose(subClass, superClass) {
5
5
  subClass.prototype = Object.create(superClass.prototype);
@@ -25,7 +25,61 @@ function _assertThisInitialized(self) {
25
25
  return self;
26
26
  }
27
27
 
28
- var version = "1.1.14";
28
+ var version = "1.1.17";
29
+
30
+ var FILE_ACK_TIMEOUT_MS = 8000;
31
+ var OPEN_IMPORTERS_KEY = '__csvboxOpenImporters';
32
+ var TOP_Z_INDEX = 2147483647;
33
+
34
+ function openImporters() {
35
+ if (!window[OPEN_IMPORTERS_KEY]) window[OPEN_IMPORTERS_KEY] = {
36
+ open: [],
37
+ listeners: []
38
+ };
39
+ return window[OPEN_IMPORTERS_KEY];
40
+ }
41
+
42
+ function restackOpenImporters(reg) {
43
+ reg.open.forEach(function (entry, i) {
44
+ var holder = entry.getHolder();
45
+ if (holder) holder.style.zIndex = String(TOP_Z_INDEX - (reg.open.length - 1 - i));
46
+ });
47
+ }
48
+
49
+ function registerOpenImporter(entry) {
50
+ var reg = openImporters();
51
+ if (reg.open.indexOf(entry) >= 0) return;
52
+ reg.open.push(entry);
53
+ restackOpenImporters(reg);
54
+ reg.listeners.slice().forEach(function (fn) {
55
+ fn();
56
+ });
57
+ }
58
+
59
+ function unregisterOpenImporter(entry) {
60
+ var reg = openImporters();
61
+ var i = reg.open.indexOf(entry);
62
+ if (i < 0) return;
63
+ reg.open.splice(i, 1);
64
+ restackOpenImporters(reg);
65
+ reg.listeners.slice().forEach(function (fn) {
66
+ fn();
67
+ });
68
+ }
69
+
70
+ function isBlockedByOpenImporter(entry) {
71
+ var reg = openImporters();
72
+ return reg.open.length > 0 && reg.open.indexOf(entry) < 0;
73
+ }
74
+
75
+ function subscribeOpenImporters(fn) {
76
+ var reg = openImporters();
77
+ reg.listeners.push(fn);
78
+ return function () {
79
+ var i = reg.listeners.indexOf(fn);
80
+ if (i >= 0) reg.listeners.splice(i, 1);
81
+ };
82
+ }
29
83
 
30
84
  var CSVBoxButton = /*#__PURE__*/function (_Component) {
31
85
  _inheritsLoose(CSVBoxButton, _Component);
@@ -36,45 +90,84 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
36
90
  _this = _Component.call(this, props) || this;
37
91
  _this.holder = React.createRef();
38
92
  _this.openModal = _this.openModal.bind(_assertThisInitialized(_this));
93
+ _this.openModalWithFile = _this.openModalWithFile.bind(_assertThisInitialized(_this));
39
94
  _this.lifecycle = createModalLifecycle();
95
+ _this.isModalShown = false;
96
+ _this.isReady = false;
97
+ _this.pendingFile = null;
40
98
  _this.uuid = generateUuid();
41
99
  _this.state = {
42
- isLoading: true
100
+ isLoading: true,
101
+ blocked: false
43
102
  };
44
103
  _this.iframe = null;
104
+ _this.registryEntry = {
105
+ getHolder: function getHolder() {
106
+ return _this.holder.current;
107
+ }
108
+ };
109
+ _this.fileSender = createFileSender({
110
+ getIframe: function getIframe() {
111
+ return _this.iframe;
112
+ },
113
+ getToken: function getToken() {
114
+ return _this.uuid;
115
+ },
116
+ getTargetOrigin: function getTargetOrigin() {
117
+ return _this.targetOrigin;
118
+ },
119
+ getBaseDomain: function getBaseDomain() {
120
+ return _this.baseDomain;
121
+ },
122
+ takeFile: function takeFile() {
123
+ var file = _this.pendingFile;
124
+ _this.pendingFile = null;
125
+ return file;
126
+ },
127
+ onSent: function onSent() {
128
+ return _this.startFileAckTimer();
129
+ }
130
+ });
45
131
  return _this;
46
132
  }
47
133
 
48
134
  var _proto = CSVBoxButton.prototype;
49
135
 
50
136
  _proto.componentDidMount = function componentDidMount() {
137
+ var _this2 = this;
138
+
139
+ this.syncBlocked();
140
+ this.unsubscribeOpenImporters = subscribeOpenImporters(function () {
141
+ return _this2.syncBlocked();
142
+ });
51
143
  var lazy = this.props.lazy;
52
144
 
53
145
  if (!lazy && !this.iframe) {
54
146
  this.initImporter();
55
147
  } else if (lazy) {
56
- this.enableInitator();
148
+ this.enableInitiator();
57
149
  }
58
150
  };
59
151
 
60
152
  _proto.initImporter = function initImporter() {
61
- var _this2 = this;
62
-
63
- var loadStarted = this.props.loadStarted;
153
+ var _this3 = this;
154
+
155
+ var _this$props = this.props,
156
+ loadStarted = _this$props.loadStarted,
157
+ user = _this$props.user,
158
+ dynamicColumns = _this$props.dynamicColumns,
159
+ options = _this$props.options,
160
+ onReady = _this$props.onReady,
161
+ onImport = _this$props.onImport,
162
+ onSubmit = _this$props.onSubmit,
163
+ onClose = _this$props.onClose,
164
+ licenseKey = _this$props.licenseKey,
165
+ dataLocation = _this$props.dataLocation,
166
+ customDomain = _this$props.customDomain,
167
+ language = _this$props.language,
168
+ environment = _this$props.environment,
169
+ theme = _this$props.theme;
64
170
  loadStarted === null || loadStarted === void 0 ? void 0 : loadStarted();
65
- var user = this.props.user;
66
- var dynamicColumns = this.props.dynamicColumns;
67
- var options = this.props.options;
68
- var onReady = this.props.onReady;
69
- var onImport = this.props.onImport;
70
- var onSubmit = this.props.onSubmit;
71
- var onClose = this.props.onClose;
72
- var licenseKey = this.props.licenseKey;
73
- var dataLocation = this.props.dataLocation;
74
- var customDomain = this.props.customDomain;
75
- var language = this.props.language;
76
- var environment = this.props.environment;
77
- var theme = this.props.theme;
78
171
  var iframeUrl = buildImportUrl({
79
172
  licenseKey: licenseKey,
80
173
  customDomain: customDomain,
@@ -83,16 +176,26 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
83
176
  theme: theme,
84
177
  environment: environment
85
178
  }, "react", version);
179
+ this.targetOrigin = new URL(iframeUrl).origin;
180
+ this.baseDomain = customDomain || "app.csvbox.io";
181
+ this.fileSender.reset();
86
182
 
87
183
  var handleModalClosed = function handleModalClosed() {
88
- if (_this2.holder && _this2.holder.current) {
89
- _this2.holder.current.style.display = 'none';
90
- _this2.holder.current.innerHTML = '';
184
+ if (_this3.holder.current) {
185
+ _this3.holder.current.style.display = 'none';
186
+ _this3.holder.current.style.pointerEvents = 'auto';
187
+ _this3.holder.current.innerHTML = '';
91
188
  }
92
189
 
93
- _this2.lifecycle.markClosed();
190
+ _this3.lifecycle.markClosed();
94
191
 
95
- _this2.iframe = null;
192
+ _this3.isModalShown = false;
193
+ _this3.isReady = false;
194
+ _this3.iframe = null;
195
+
196
+ _this3.clearProbeTimer();
197
+
198
+ unregisterOpenImporter(_this3.registryEntry);
96
199
  onClose === null || onClose === void 0 ? void 0 : onClose();
97
200
  };
98
201
 
@@ -104,6 +207,10 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
104
207
  var legacy = classifyLegacyMessage(event.data);
105
208
 
106
209
  if (legacy) {
210
+ if (!_this3.iframe || event.source !== _this3.iframe.contentWindow) {
211
+ return;
212
+ }
213
+
107
214
  if (legacy.type === "mainModalHidden") {
108
215
  handleModalClosed();
109
216
  }
@@ -119,7 +226,46 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
119
226
  return;
120
227
  }
121
228
 
122
- var message = classifyStructuredMessage(event.data, _this2.uuid);
229
+ var raw = event.data;
230
+
231
+ if (raw && typeof raw === "object" && raw.data && raw.data.unique_token == _this3.uuid) {
232
+ _this3.fileSender.learnOrigin(event);
233
+
234
+ if (raw.type === "csvbox-set-file-rejected" && raw.data.reason === "not-a-file") {
235
+ return;
236
+ }
237
+
238
+ if (raw.type === "csvbox-modal-shown") {
239
+ _this3.clearFileAckTimer();
240
+
241
+ registerOpenImporter(_this3.registryEntry);
242
+ _this3.isModalShown = true;
243
+
244
+ _this3.lifecycle.requestOpen();
245
+
246
+ if (_this3.holder.current) {
247
+ _this3.holder.current.style.display = 'block';
248
+ _this3.holder.current.style.pointerEvents = 'auto';
249
+ }
250
+
251
+ return;
252
+ }
253
+
254
+ if (raw.type === "csvbox-set-file-rejected") {
255
+ _this3.clearFileAckTimer();
256
+
257
+ if (!_this3.isModalShown && _this3.holder.current) {
258
+ _this3.holder.current.style.display = 'none';
259
+ _this3.holder.current.style.pointerEvents = 'auto';
260
+ unregisterOpenImporter(_this3.registryEntry);
261
+ }
262
+
263
+ console.warn("[csvbox] importer declined the supplied file: " + raw.data.reason);
264
+ return;
265
+ }
266
+ }
267
+
268
+ var message = classifyStructuredMessage(event.data, _this3.uuid);
123
269
 
124
270
  if (!message) {
125
271
  return;
@@ -140,21 +286,24 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
140
286
 
141
287
  window.addEventListener("message", this.messageListener, false);
142
288
  this.uuid = generateUuid();
143
- var self = this;
144
289
  var iframe = document.createElement("iframe");
145
290
  this.iframe = iframe;
146
291
  iframe.setAttribute("src", iframeUrl);
292
+ iframe.setAttribute("allow", "clipboard-read; clipboard-write *");
147
293
  iframe.frameBorder = 0;
148
294
  iframe.classList.add('csvbox-iframe');
149
295
  Object.assign(iframe.style, IFRAME_STYLE);
150
296
 
151
297
  iframe.onload = function () {
152
- self.enableInitator();
153
- iframe.contentWindow.postMessage(buildInitPayload(user, dynamicColumns, options, self.uuid), "*");
298
+ _this3.isReady = true;
299
+
300
+ _this3.enableInitiator();
301
+
302
+ iframe.contentWindow.postMessage(buildInitPayload(user, dynamicColumns, options, _this3.uuid), "*");
154
303
  onReady === null || onReady === void 0 ? void 0 : onReady();
155
304
 
156
- if (self.lifecycle.markReady()) {
157
- self.openModal();
305
+ if (_this3.lifecycle.markReady()) {
306
+ _this3.openModal();
158
307
  }
159
308
  };
160
309
 
@@ -162,19 +311,114 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
162
311
  };
163
312
 
164
313
  _proto.openModal = function openModal() {
314
+ registerOpenImporter(this.registryEntry);
315
+
165
316
  if (!this.iframe) {
166
317
  this.lifecycle.requestOpen();
167
318
  this.initImporter();
168
319
  return;
169
320
  }
170
321
 
322
+ if (this.pendingFile) {
323
+ if (!this.isReady) {
324
+ this.lifecycle.requestOpen();
325
+ return;
326
+ }
327
+
328
+ this.holder.current.style.pointerEvents = 'none';
329
+ this.holder.current.style.display = 'block';
330
+ this.fileSender.send();
331
+ return;
332
+ }
333
+
171
334
  if (this.lifecycle.requestOpen()) {
335
+ this.isModalShown = true;
172
336
  this.iframe.contentWindow.postMessage('openModal', '*');
337
+ this.holder.current.style.pointerEvents = 'auto';
173
338
  this.holder.current.style.display = 'block';
174
339
  }
175
340
  };
176
341
 
177
- _proto.enableInitator = function enableInitator() {
342
+ _proto.openModalWithFile = function openModalWithFile(file) {
343
+ if (!window.File || !(file instanceof window.File)) {
344
+ return;
345
+ }
346
+
347
+ this.pendingFile = file;
348
+
349
+ if (this.isModalShown && this.iframe && this.isReady) {
350
+ this.fileSender.send();
351
+ return;
352
+ }
353
+
354
+ this.openModal();
355
+ };
356
+
357
+ _proto.clearProbeTimer = function clearProbeTimer() {
358
+ this.clearFileAckTimer();
359
+ this.fileSender.reset();
360
+ };
361
+
362
+ _proto.startFileAckTimer = function startFileAckTimer() {
363
+ var _this4 = this;
364
+
365
+ this.clearFileAckTimer();
366
+ this.fileAckTimer = setTimeout(function () {
367
+ _this4.fileAckTimer = null;
368
+
369
+ _this4.giveUpOnFile();
370
+ }, FILE_ACK_TIMEOUT_MS);
371
+ };
372
+
373
+ _proto.clearFileAckTimer = function clearFileAckTimer() {
374
+ if (this.fileAckTimer) {
375
+ clearTimeout(this.fileAckTimer);
376
+ this.fileAckTimer = null;
377
+ }
378
+ };
379
+
380
+ _proto.giveUpOnFile = function giveUpOnFile() {
381
+ if (this.isModalShown) {
382
+ return;
383
+ }
384
+
385
+ var holder = this.holder.current;
386
+
387
+ if (holder) {
388
+ holder.style.display = 'none';
389
+ holder.style.pointerEvents = 'auto';
390
+ }
391
+
392
+ unregisterOpenImporter(this.registryEntry);
393
+ console.warn("[csvbox] the importer did not respond to the supplied file");
394
+ };
395
+
396
+ _proto.componentWillUnmount = function componentWillUnmount() {
397
+ this.clearProbeTimer();
398
+ unregisterOpenImporter(this.registryEntry);
399
+
400
+ if (this.unsubscribeOpenImporters) {
401
+ this.unsubscribeOpenImporters();
402
+ this.unsubscribeOpenImporters = null;
403
+ }
404
+
405
+ if (this.messageListener) {
406
+ window.removeEventListener("message", this.messageListener, false);
407
+ this.messageListener = null;
408
+ }
409
+ };
410
+
411
+ _proto.syncBlocked = function syncBlocked() {
412
+ var blocked = isBlockedByOpenImporter(this.registryEntry);
413
+
414
+ if (blocked !== this.state.blocked) {
415
+ this.setState({
416
+ blocked: blocked
417
+ });
418
+ }
419
+ };
420
+
421
+ _proto.enableInitiator = function enableInitiator() {
178
422
  this.setState({
179
423
  isLoading: false
180
424
  });
@@ -182,21 +426,21 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
182
426
 
183
427
  _proto.render = function render() {
184
428
  if (this.props.render) {
185
- return /*#__PURE__*/React.createElement("div", null, this.props.render(this.openModal, this.state.isLoading), /*#__PURE__*/React.createElement("div", {
186
- ref: this.holder,
187
- style: HOLDER_STYLE
188
- }));
189
- } else {
190
- return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("button", {
191
- disabled: this.state.isLoading,
192
- onClick: this.openModal,
193
- "data-csvbox-initator": true,
194
- "data-csvbox-token": this.uuid
195
- }, this.props.children), /*#__PURE__*/React.createElement("div", {
429
+ return /*#__PURE__*/React.createElement("div", null, this.props.render(this.openModal, this.state.isLoading || this.state.blocked, this.openModalWithFile), /*#__PURE__*/React.createElement("div", {
196
430
  ref: this.holder,
197
431
  style: HOLDER_STYLE
198
432
  }));
199
433
  }
434
+
435
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("button", {
436
+ disabled: this.state.isLoading || this.state.blocked,
437
+ onClick: this.openModal,
438
+ "data-csvbox-initator": true,
439
+ "data-csvbox-token": this.uuid
440
+ }, this.props.children), /*#__PURE__*/React.createElement("div", {
441
+ ref: this.holder,
442
+ style: HOLDER_STYLE
443
+ }));
200
444
  };
201
445
 
202
446
  return CSVBoxButton;
@@ -1 +1 @@
1
- {"version":3,"file":"index.modern.js","sources":["../src/index.js"],"sourcesContent":["import React, { Component } from 'react';\nimport { version } from '../package.json';\nimport {\n\tHOLDER_STYLE,\n\tIFRAME_STYLE,\n\tbuildImportUrl,\n\tgenerateUuid,\n\tbuildInitPayload,\n\tcreateModalLifecycle,\n\tclassifyStructuredMessage,\n\tclassifyLegacyMessage\n} from '@sumit_yewale/adapter-core';\n\nexport class CSVBoxButton extends Component {\n\n\tconstructor(props) {\n\t\tsuper(props)\n\t\tthis.holder = React.createRef();\n\t\tthis.openModal = this.openModal.bind(this)\n\t\tthis.lifecycle = createModalLifecycle();\n\t\tthis.uuid = generateUuid();\n\t\tthis.state = {\n\t\t\tisLoading: true\n\t\t};\n\t\tthis.iframe = null;\n\t}\n\n\tcomponentDidMount() {\n\t\tconst { lazy } = this.props;\n\t\tif (!lazy && !this.iframe) {\n\t\t\tthis.initImporter();\n\t\t} else if (lazy) {\n\t\t\tthis.enableInitator();\n\t\t}\n\t}\n\n\tinitImporter() {\n\n\t\tconst { loadStarted } = this.props;\n\n\t\tloadStarted?.();\n\n\t\tconst { user } = this.props;\n\t\tconst { dynamicColumns } = this.props;\n\t\tconst { options } = this.props;\n\t\tconst { onReady } = this.props;\n\t\tconst { onImport } = this.props;\n\t\tconst { onSubmit } = this.props;\n\t\tconst { onClose } = this.props;\n\t\tconst { licenseKey } = this.props;\n\t\tconst { dataLocation } = this.props;\n\t\tconst { customDomain } = this.props;\n\t\tconst { language } = this.props;\n\t\tconst { environment } = this.props;\n\t\tconst { theme } = this.props;\n\n\t\tlet iframeUrl = buildImportUrl(\n\t\t\t{ licenseKey, customDomain, dataLocation, language, theme, environment },\n\t\t\t\"react\",\n\t\t\tversion\n\t\t);\n\n\t\tlet handleModalClosed = () => {\n\t\t\tif (this.holder && this.holder.current) {\n\t\t\t\tthis.holder.current.style.display = 'none';\n\t\t\t\tthis.holder.current.innerHTML = '';\n\t\t\t}\n\t\t\tthis.lifecycle.markClosed();\n\t\t\tthis.iframe = null;\n\t\t\tonClose?.();\n\t\t};\n\n\t\tif (this.messageListener) {\n\t\t\twindow.removeEventListener(\"message\", this.messageListener, false);\n\t\t}\n\n\t\tthis.messageListener = (event) => {\n\n\t\t\tlet legacy = classifyLegacyMessage(event.data);\n\t\t\tif (legacy) {\n\t\t\t\tif (legacy.type === \"mainModalHidden\") {\n\t\t\t\t\thandleModalClosed();\n\t\t\t\t}\n\t\t\t\tif (legacy.type === \"uploadSuccessful\") {\n\t\t\t\t\tonImport(true);\n\t\t\t\t}\n\t\t\t\tif (legacy.type === \"uploadFailed\") {\n\t\t\t\t\tonImport(false);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet message = classifyStructuredMessage(event.data, this.uuid);\n\t\t\tif (!message) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (message.type === \"data-on-submit\") {\n\t\t\t\tonSubmit?.(message.metadata);\n\t\t\t} else if (message.type === \"data-push-status\") {\n\t\t\t\tonImport(message.success, message.metadata);\n\t\t\t} else if (message.type === \"csvbox-modal-hidden\") {\n\t\t\t\thandleModalClosed();\n\t\t\t} else if (message.type === \"csvbox-upload-successful\") {\n\t\t\t\tonImport(true);\n\t\t\t} else if (message.type === \"csvbox-upload-failed\") {\n\t\t\t\tonImport(false);\n\t\t\t}\n\n\t\t};\n\n\t\twindow.addEventListener(\"message\", this.messageListener, false);\n\n\t\tthis.uuid = generateUuid();\n\n\t\tlet self = this;\n\n\t\tlet iframe = document.createElement(\"iframe\");\n\t\tthis.iframe = iframe;\n\t\tiframe.setAttribute(\"src\", iframeUrl);\n\t\tiframe.frameBorder = 0;\n\t\tiframe.classList.add('csvbox-iframe');\n\n\t\tObject.assign(iframe.style, IFRAME_STYLE);\n\n\t\tiframe.onload = function () {\n\t\t\tself.enableInitator();\n\t\t\tiframe.contentWindow.postMessage(buildInitPayload(user, dynamicColumns, options, self.uuid), \"*\");\n\t\t\tonReady?.();\n\t\t\tif (self.lifecycle.markReady()) {\n\t\t\t\tself.openModal();\n\t\t\t}\n\t\t}\n\t\tthis.holder.current.appendChild(iframe);\n\t}\n\n\topenModal() {\n\n\t\tif (!this.iframe) {\n\t\t\tthis.lifecycle.requestOpen();\n\t\t\tthis.initImporter();\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.lifecycle.requestOpen()) {\n\t\t\tthis.iframe.contentWindow.postMessage('openModal', '*');\n\t\t\tthis.holder.current.style.display = 'block';\n\t\t}\n\n\t}\n\n\tenableInitator() {\n\t\tthis.setState({\n\t\t\tisLoading: false\n\t\t})\n\t}\n\n\trender() {\n\n\t\tif (this.props.render) {\n\t\t\treturn (\n\t\t\t\t<div>\n\t\t\t\t\t{this.props.render(this.openModal, this.state.isLoading)}\n\t\t\t\t\t<div ref={this.holder} style={HOLDER_STYLE}></div>\n\t\t\t\t</div>\n\t\t\t)\n\t\t} else {\n\t\t\treturn (\n\t\t\t\t<div>\n\t\t\t\t\t<button disabled={this.state.isLoading} onClick={this.openModal} data-csvbox-initator data-csvbox-token={this.uuid}>{this.props.children}</button>\n\t\t\t\t\t<div ref={this.holder} style={HOLDER_STYLE}></div>\n\t\t\t\t</div>\n\t\t\t)\n\t\t}\n\n\n\t}\n}\n\nexport default CSVBoxButton;\n"],"names":["CSVBoxButton","props","holder","React","createRef","openModal","bind","lifecycle","createModalLifecycle","uuid","generateUuid","state","isLoading","iframe","componentDidMount","lazy","initImporter","enableInitator","loadStarted","user","dynamicColumns","options","onReady","onImport","onSubmit","onClose","licenseKey","dataLocation","customDomain","language","environment","theme","iframeUrl","buildImportUrl","version","handleModalClosed","current","style","display","innerHTML","markClosed","messageListener","window","removeEventListener","event","legacy","classifyLegacyMessage","data","type","message","classifyStructuredMessage","metadata","success","addEventListener","self","document","createElement","setAttribute","frameBorder","classList","add","Object","assign","IFRAME_STYLE","onload","contentWindow","postMessage","buildInitPayload","markReady","appendChild","requestOpen","setState","render","HOLDER_STYLE","children","Component"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAaaA,YAAb;AAAA;;AAEC,wBAAYC,KAAZ,EAAmB;AAAA;;AAClB,kCAAMA,KAAN;AACA,UAAKC,MAAL,GAAcC,KAAK,CAACC,SAAN,EAAd;AACA,UAAKC,SAAL,GAAiB,MAAKA,SAAL,CAAeC,IAAf,+BAAjB;AACA,UAAKC,SAAL,GAAiBC,oBAAoB,EAArC;AACA,UAAKC,IAAL,GAAYC,YAAY,EAAxB;AACA,UAAKC,KAAL,GAAa;AACZC,MAAAA,SAAS,EAAE;AADC,KAAb;AAGA,UAAKC,MAAL,GAAc,IAAd;AATkB;AAUlB;;AAZF;;AAAA,SAcCC,iBAdD,GAcC,6BAAoB;AACnB,QAAQC,IAAR,GAAiB,KAAKd,KAAtB,CAAQc,IAAR;;AACA,QAAI,CAACA,IAAD,IAAS,CAAC,KAAKF,MAAnB,EAA2B;AAC1B,WAAKG,YAAL;AACA,KAFD,MAEO,IAAID,IAAJ,EAAU;AAChB,WAAKE,cAAL;AACA;AACD,GArBF;;AAAA,SAuBCD,YAvBD,GAuBC,wBAAe;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KAAKxE,MAAf;AAAuB,QAAA,KAAK,EAAEuE;AAA9B,QAFD,CADD;AAMA;AAGD,GAnKF;;AAAA;AAAA,EAAkCE,SAAlC;;;;;"}
1
+ {"version":3,"file":"index.modern.js","sources":["../src/index.js"],"sourcesContent":["import React, { Component } from 'react';\nimport { version } from '../package.json';\nimport {\n\tHOLDER_STYLE,\n\tIFRAME_STYLE,\n\tbuildImportUrl,\n\tgenerateUuid,\n\tbuildInitPayload,\n\tcreateModalLifecycle,\n\tcreateFileSender,\n\tclassifyStructuredMessage,\n\tclassifyLegacyMessage\n} from '@sumit_yewale/adapter-core';\n\n// How long we wait for the importer to confirm a file it was sent before giving up on it.\nconst FILE_ACK_TIMEOUT_MS = 8000;\n\n// Page-wide record of the importers that are open or opening, shared by every CSVBox adapter\n// on the page (it lives on window so separate copies of an adapter see the same list). It does\n// two things: the newest importer is stacked on top (every holder is fixed, full screen and\n// z-index 2147483647, so equal z-indexes would leave the one that comes first in the DOM on\n// top), and the other instances learn that an importer is open so they can disable their button.\nconst OPEN_IMPORTERS_KEY = '__csvboxOpenImporters';\nconst TOP_Z_INDEX = 2147483647;\n\nfunction openImporters() {\n\tif (!window[OPEN_IMPORTERS_KEY]) window[OPEN_IMPORTERS_KEY] = { open: [], listeners: [] };\n\treturn window[OPEN_IMPORTERS_KEY];\n}\n\nfunction restackOpenImporters(reg) {\n\treg.open.forEach(function (entry, i) {\n\t\tconst holder = entry.getHolder();\n\t\tif (holder) holder.style.zIndex = String(TOP_Z_INDEX - (reg.open.length - 1 - i));\n\t});\n}\n\nfunction registerOpenImporter(entry) {\n\tconst reg = openImporters();\n\tif (reg.open.indexOf(entry) >= 0) return;\n\treg.open.push(entry);\n\trestackOpenImporters(reg);\n\treg.listeners.slice().forEach(function (fn) { fn(); });\n}\n\nfunction unregisterOpenImporter(entry) {\n\tconst reg = openImporters();\n\tconst i = reg.open.indexOf(entry);\n\tif (i < 0) return;\n\treg.open.splice(i, 1);\n\trestackOpenImporters(reg);\n\treg.listeners.slice().forEach(function (fn) { fn(); });\n}\n\nfunction isBlockedByOpenImporter(entry) {\n\tconst reg = openImporters();\n\treturn reg.open.length > 0 && reg.open.indexOf(entry) < 0;\n}\n\nfunction subscribeOpenImporters(fn) {\n\tconst reg = openImporters();\n\treg.listeners.push(fn);\n\treturn function () {\n\t\tconst i = reg.listeners.indexOf(fn);\n\t\tif (i >= 0) reg.listeners.splice(i, 1);\n\t};\n}\n\nexport class CSVBoxButton extends Component {\n\n\tconstructor(props) {\n\t\tsuper(props);\n\t\tthis.holder = React.createRef();\n\t\tthis.openModal = this.openModal.bind(this);\n\t\tthis.openModalWithFile = this.openModalWithFile.bind(this);\n\t\tthis.lifecycle = createModalLifecycle();\n\t\tthis.isModalShown = false;\n\t\tthis.isReady = false;\n\t\tthis.pendingFile = null;\n\t\tthis.uuid = generateUuid();\n\t\tthis.state = {\n\t\t\tisLoading: true,\n\t\t\t// True while a different importer on the page is open: the button stays disabled.\n\t\t\tblocked: false\n\t\t};\n\t\tthis.iframe = null;\n\t\tthis.registryEntry = { getHolder: () => this.holder.current };\n\t\tthis.fileSender = createFileSender({\n\t\t\tgetIframe: () => this.iframe,\n\t\t\tgetToken: () => this.uuid,\n\t\t\tgetTargetOrigin: () => this.targetOrigin,\n\t\t\tgetBaseDomain: () => this.baseDomain,\n\t\t\ttakeFile: () => {\n\t\t\t\tconst file = this.pendingFile;\n\t\t\t\tthis.pendingFile = null;\n\t\t\t\treturn file;\n\t\t\t},\n\t\t\tonSent: () => this.startFileAckTimer()\n\t\t});\n\t}\n\n\tcomponentDidMount() {\n\t\tthis.syncBlocked();\n\t\tthis.unsubscribeOpenImporters = subscribeOpenImporters(() => this.syncBlocked());\n\t\tconst { lazy } = this.props;\n\t\tif (!lazy && !this.iframe) {\n\t\t\tthis.initImporter();\n\t\t} else if (lazy) {\n\t\t\tthis.enableInitiator();\n\t\t}\n\t}\n\n\tinitImporter() {\n\t\tconst {\n\t\t\tloadStarted, user, dynamicColumns, options, onReady, onImport,\n\t\t\tonSubmit, onClose, licenseKey, dataLocation, customDomain,\n\t\t\tlanguage, environment, theme\n\t\t} = this.props;\n\n\t\tloadStarted?.();\n\n\t\tconst iframeUrl = buildImportUrl(\n\t\t\t{ licenseKey, customDomain, dataLocation, language, theme, environment },\n\t\t\t\"react\",\n\t\t\tversion\n\t\t);\n\n\t\t// Default place to send the file. A file is only ever sent to a named origin, never \"*\".\n\t\tthis.targetOrigin = new URL(iframeUrl).origin;\n\n\t\t// Data-location sheets redirect to another host, so the iframe origin can differ from\n\t\t// targetOrigin. We use this domain to check the real origin before trusting it.\n\t\tthis.baseDomain = customDomain || \"app.csvbox.io\";\n\t\tthis.fileSender.reset();\n\n\t\tconst handleModalClosed = () => {\n\t\t\tif (this.holder.current) {\n\t\t\t\tthis.holder.current.style.display = 'none';\n\t\t\t\tthis.holder.current.style.pointerEvents = 'auto';\n\t\t\t\tthis.holder.current.innerHTML = '';\n\t\t\t}\n\t\t\tthis.lifecycle.markClosed();\n\t\t\tthis.isModalShown = false;\n\t\t\tthis.isReady = false;\n\t\t\tthis.iframe = null;\n\t\t\t// A new iframe is built on the next open, so the origin is learned again.\n\t\t\tthis.clearProbeTimer();\n\t\t\tunregisterOpenImporter(this.registryEntry);\n\t\t\tonClose?.();\n\t\t};\n\n\t\tif (this.messageListener) {\n\t\t\twindow.removeEventListener(\"message\", this.messageListener, false);\n\t\t}\n\n\t\tthis.messageListener = (event) => {\n\t\t\tconst legacy = classifyLegacyMessage(event.data);\n\t\t\tif (legacy) {\n\t\t\t\t// Legacy messages carry no token, so the only way to tell which importer sent one is\n\t\t\t\t// its window. Ignore those that came from another instance's iframe (or anywhere else).\n\t\t\t\tif (!this.iframe || event.source !== this.iframe.contentWindow) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (legacy.type === \"mainModalHidden\") {\n\t\t\t\t\thandleModalClosed();\n\t\t\t\t}\n\t\t\t\tif (legacy.type === \"uploadSuccessful\") {\n\t\t\t\t\tonImport(true);\n\t\t\t\t}\n\t\t\t\tif (legacy.type === \"uploadFailed\") {\n\t\t\t\t\tonImport(false);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Set-file handshake messages. The shared core does not classify these, so they are\n\t\t\t// read here, behind the same unique_token check the core applies.\n\t\t\tconst raw = event.data;\n\t\t\tif (raw && typeof raw === \"object\" && raw.data && raw.data.unique_token == this.uuid) {\n\t\t\t\tthis.fileSender.learnOrigin(event);\n\n\t\t\t\tif (raw.type === \"csvbox-set-file-rejected\" && raw.data.reason === \"not-a-file\") {\n\t\t\t\t\t// Reply to our probe (it has no file). It only tells us the origin, so do nothing.\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (raw.type === \"csvbox-modal-shown\") {\n\t\t\t\t\tthis.clearFileAckTimer();\n\t\t\t\t\tregisterOpenImporter(this.registryEntry);\n\t\t\t\t\t// What the file path in openModal() is waiting for. display as well as\n\t\t\t\t\t// pointer-events: a second file declined while the first was still opening the\n\t\t\t\t\t// modal has put the holder away in the meantime.\n\t\t\t\t\tthis.isModalShown = true;\n\t\t\t\t\tthis.lifecycle.requestOpen();\n\t\t\t\t\tif (this.holder.current) {\n\t\t\t\t\t\tthis.holder.current.style.display = 'block';\n\t\t\t\t\t\tthis.holder.current.style.pointerEvents = 'auto';\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (raw.type === \"csvbox-set-file-rejected\") {\n\t\t\t\t\tthis.clearFileAckTimer();\n\t\t\t\t\t// The importer has the file and will not take it. Put the holder away only if the\n\t\t\t\t\t// modal was never confirmed up: a file declined while it is open (an import past\n\t\t\t\t\t// the upload step, a fade-out under way) leaves that modal where it is, and its\n\t\t\t\t\t// own 'csvbox-modal-hidden' will put the holder away when it closes.\n\t\t\t\t\tif (!this.isModalShown && this.holder.current) {\n\t\t\t\t\t\tthis.holder.current.style.display = 'none';\n\t\t\t\t\t\tthis.holder.current.style.pointerEvents = 'auto';\n\t\t\t\t\t\tunregisterOpenImporter(this.registryEntry);\n\t\t\t\t\t}\n\t\t\t\t\tconsole.warn(\"[csvbox] importer declined the supplied file: \" + raw.data.reason);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst message = classifyStructuredMessage(event.data, this.uuid);\n\t\t\tif (!message) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (message.type === \"data-on-submit\") {\n\t\t\t\tonSubmit?.(message.metadata);\n\t\t\t} else if (message.type === \"data-push-status\") {\n\t\t\t\tonImport(message.success, message.metadata);\n\t\t\t} else if (message.type === \"csvbox-modal-hidden\") {\n\t\t\t\thandleModalClosed();\n\t\t\t} else if (message.type === \"csvbox-upload-successful\") {\n\t\t\t\tonImport(true);\n\t\t\t} else if (message.type === \"csvbox-upload-failed\") {\n\t\t\t\tonImport(false);\n\t\t\t}\n\t\t};\n\n\t\twindow.addEventListener(\"message\", this.messageListener, false);\n\n\t\tthis.uuid = generateUuid();\n\n\t\tconst iframe = document.createElement(\"iframe\");\n\t\tthis.iframe = iframe;\n\t\tiframe.setAttribute(\"src\", iframeUrl);\n\t\tiframe.setAttribute(\"allow\", \"clipboard-read; clipboard-write *\");\n\t\tiframe.frameBorder = 0;\n\t\tiframe.classList.add('csvbox-iframe');\n\t\tObject.assign(iframe.style, IFRAME_STYLE);\n\n\t\tiframe.onload = () => {\n\t\t\tthis.isReady = true;\n\t\t\tthis.enableInitiator();\n\t\t\tiframe.contentWindow.postMessage(buildInitPayload(user, dynamicColumns, options, this.uuid), \"*\");\n\t\t\tonReady?.();\n\t\t\tif (this.lifecycle.markReady()) {\n\t\t\t\tthis.openModal();\n\t\t\t}\n\t\t};\n\n\t\tthis.holder.current.appendChild(iframe);\n\t}\n\n\topenModal() {\n\t\t// Counts as open from the moment it is requested, so the other buttons are disabled while\n\t\t// this importer is still loading, and so it is stacked above any importer opened earlier.\n\t\tregisterOpenImporter(this.registryEntry);\n\t\tif (!this.iframe) {\n\t\t\tthis.lifecycle.requestOpen();\n\t\t\tthis.initImporter();\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.pendingFile) {\n\t\t\tif (!this.isReady) {\n\t\t\t\t// Deferred: onload's markReady() calls openModal() again once the iframe is up.\n\t\t\t\tthis.lifecycle.requestOpen();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// The importer opens its own modal once it has the file, so that it can inject on\n\t\t\t// 'shown.bs.modal'. Sending 'openModal' as well would race that.\n\t\t\t//\n\t\t\t// It can also decline: wrong step, an import file URL configured on the sheet, or\n\t\t\t// an importer too old to know the message at all. So the holder goes up\n\t\t\t// click-through and stays that way until 'csvbox-modal-shown' confirms the modal\n\t\t\t// is really up. It covers the viewport at z-index 2147483647 and the importer\n\t\t\t// renders transparent with its modal closed, so arming it on an unanswered message\n\t\t\t// leaves an invisible sheet over the host page eating every click.\n\t\t\t//\n\t\t\t// display:block regardless, so the iframe lays out and animates normally; only\n\t\t\t// pointer-events is held back. isModalShown likewise waits for the confirmation,\n\t\t\t// or a declined file would latch the importer shut for good.\n\t\t\tthis.holder.current.style.pointerEvents = 'none';\n\t\t\tthis.holder.current.style.display = 'block';\n\t\t\tthis.fileSender.send();\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.lifecycle.requestOpen()) {\n\t\t\tthis.isModalShown = true;\n\t\t\tthis.iframe.contentWindow.postMessage('openModal', '*');\n\t\t\t// Explicit: a previously declined file leaves the holder click-through.\n\t\t\tthis.holder.current.style.pointerEvents = 'auto';\n\t\t\tthis.holder.current.style.display = 'block';\n\t\t}\n\t}\n\n\t/**\n\t * Open the importer on a File the host page already has, instead of the file picker.\n\t *\n\t * Reachable two ways: a ref on the component (`ref.current.openModalWithFile(file)`), or\n\t * the third argument handed to the `render` prop.\n\t *\n\t * The File crosses to the iframe by structured clone, so the importer receives the real\n\t * object and applies its own extension, worksheet and size rules to it -- this does not\n\t * bypass any of them. Pass a File; a Blob has no name for the importer to read an\n\t * extension from.\n\t */\n\topenModalWithFile(file) {\n\t\t// window.File, not a bare File: eslint-config-standard declares only window, document\n\t\t// and navigator as browser globals, so a bare File is a no-undef error here.\n\t\tif (!window.File || !(file instanceof window.File)) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.pendingFile = file;\n\n\t\t// Already open: hand it over now rather than holding it for the next open. The importer\n\t\t// takes it only while it is still on the upload step, and ignores it once the user has a\n\t\t// dataset and a mapping in progress.\n\t\tif (this.isModalShown && this.iframe && this.isReady) {\n\t\t\tthis.fileSender.send();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.openModal();\n\t}\n\n\tclearProbeTimer() {\n\t\tthis.clearFileAckTimer();\n\t\tthis.fileSender.reset();\n\t}\n\n\tstartFileAckTimer() {\n\t\tthis.clearFileAckTimer();\n\t\tthis.fileAckTimer = setTimeout(() => {\n\t\t\tthis.fileAckTimer = null;\n\t\t\tthis.giveUpOnFile();\n\t\t}, FILE_ACK_TIMEOUT_MS);\n\t}\n\n\tclearFileAckTimer() {\n\t\tif (this.fileAckTimer) {\n\t\t\tclearTimeout(this.fileAckTimer);\n\t\t\tthis.fileAckTimer = null;\n\t\t}\n\t}\n\n\t// The importer never confirmed the file it was sent (an origin we do not trust, or an importer too\n\t// old to know the message). Without this the holder would stay up, invisible and click-through,\n\t// and the other instances' buttons would stay disabled for good.\n\tgiveUpOnFile() {\n\t\tif (this.isModalShown) {\n\t\t\treturn;\n\t\t}\n\t\tconst holder = this.holder.current;\n\t\tif (holder) {\n\t\t\tholder.style.display = 'none';\n\t\t\tholder.style.pointerEvents = 'auto';\n\t\t}\n\t\tunregisterOpenImporter(this.registryEntry);\n\t\tconsole.warn(\"[csvbox] the importer did not respond to the supplied file\");\n\t}\n\n\tcomponentWillUnmount() {\n\t\tthis.clearProbeTimer();\n\t\tunregisterOpenImporter(this.registryEntry);\n\t\tif (this.unsubscribeOpenImporters) {\n\t\t\tthis.unsubscribeOpenImporters();\n\t\t\tthis.unsubscribeOpenImporters = null;\n\t\t}\n\t\tif (this.messageListener) {\n\t\t\twindow.removeEventListener(\"message\", this.messageListener, false);\n\t\t\tthis.messageListener = null;\n\t\t}\n\t}\n\n\tsyncBlocked() {\n\t\tconst blocked = isBlockedByOpenImporter(this.registryEntry);\n\t\tif (blocked !== this.state.blocked) {\n\t\t\tthis.setState({ blocked });\n\t\t}\n\t}\n\n\tenableInitiator() {\n\t\tthis.setState({\n\t\t\tisLoading: false\n\t\t});\n\t}\n\n\trender() {\n\t\tif (this.props.render) {\n\t\t\treturn (\n\t\t\t\t<div>\n\t\t\t\t\t{this.props.render(this.openModal, this.state.isLoading || this.state.blocked, this.openModalWithFile)}\n\t\t\t\t\t<div ref={this.holder} style={HOLDER_STYLE}></div>\n\t\t\t\t</div>\n\t\t\t)\n\t\t}\n\n\t\treturn (\n\t\t\t<div>\n\t\t\t\t<button disabled={this.state.isLoading || this.state.blocked} onClick={this.openModal} data-csvbox-initator data-csvbox-token={this.uuid}>{this.props.children}</button>\n\t\t\t\t<div ref={this.holder} style={HOLDER_STYLE}></div>\n\t\t\t</div>\n\t\t)\n\t}\n}\n\nexport default CSVBoxButton;\n"],"names":["FILE_ACK_TIMEOUT_MS","OPEN_IMPORTERS_KEY","TOP_Z_INDEX","openImporters","window","open","listeners","restackOpenImporters","reg","forEach","entry","i","holder","getHolder","style","zIndex","String","length","registerOpenImporter","indexOf","push","slice","fn","unregisterOpenImporter","splice","isBlockedByOpenImporter","subscribeOpenImporters","CSVBoxButton","props","React","createRef","openModal","bind","openModalWithFile","lifecycle","createModalLifecycle","isModalShown","isReady","pendingFile","uuid","generateUuid","state","isLoading","blocked","iframe","registryEntry","current","fileSender","createFileSender","getIframe","getToken","getTargetOrigin","targetOrigin","getBaseDomain","baseDomain","takeFile","file","onSent","startFileAckTimer","componentDidMount","syncBlocked","unsubscribeOpenImporters","lazy","initImporter","enableInitiator","loadStarted","user","dynamicColumns","options","onReady","onImport","onSubmit","onClose","licenseKey","dataLocation","customDomain","language","environment","theme","iframeUrl","buildImportUrl","version","URL","origin","reset","handleModalClosed","display","pointerEvents","innerHTML","markClosed","clearProbeTimer","messageListener","removeEventListener","event","legacy","classifyLegacyMessage","data","source","contentWindow","type","raw","unique_token","learnOrigin","reason","clearFileAckTimer","requestOpen","console","warn","message","classifyStructuredMessage","metadata","success","addEventListener","document","createElement","setAttribute","frameBorder","classList","add","Object","assign","IFRAME_STYLE","onload","postMessage","buildInitPayload","markReady","appendChild","send","File","fileAckTimer","setTimeout","giveUpOnFile","clearTimeout","componentWillUnmount","setState","render","HOLDER_STYLE","children","Component"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,IAAMA,mBAAmB,GAAG,IAA5B;AAOA,IAAMC,kBAAkB,GAAG,uBAA3B;AACA,IAAMC,WAAW,GAAG,UAApB;;AAEA,SAASC,aAAT,GAAyB;AACxB,MAAI,CAACC,MAAM,CAACH,kBAAD,CAAX,EAAiCG,MAAM,CAACH,kBAAD,CAAN,GAA6B;AAAEI,IAAAA,IAAI,EAAE,EAAR;AAAYC,IAAAA,SAAS,EAAE;AAAvB,GAA7B;AACjC,SAAOF,MAAM,CAACH,kBAAD,CAAb;AACA;;AAED,SAASM,oBAAT,CAA8BC,GAA9B,EAAmC;AAClCA,EAAAA,GAAG,CAACH,IAAJ,CAASI,OAAT,CAAiB,UAAUC,KAAV,EAAiBC,CAAjB,EAAoB;AACpC,QAAMC,MAAM,GAAGF,KAAK,CAACG,SAAN,EAAf;AACA,QAAID,MAAJ,EAAYA,MAAM,CAACE,KAAP,CAAaC,MAAb,GAAsBC,MAAM,CAACd,WAAW,IAAIM,GAAG,CAACH,IAAJ,CAASY,MAAT,GAAkB,CAAlB,GAAsBN,CAA1B,CAAZ,CAA5B;AACZ,GAHD;AAIA;;AAED,SAASO,oBAAT,CAA8BR,KAA9B,EAAqC;AACpC,MAAMF,GAAG,GAAGL,aAAa,EAAzB;AACA,MAAIK,GAAG,CAACH,IAAJ,CAASc,OAAT,CAAiBT,KAAjB,KAA2B,CAA/B,EAAk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AAKoB,aAAN,CAAvC;;AACA,QAAIF,OAAO,KAAK,KAAKF,KAAL,CAAWE,OAA3B,EAAoC;AACnC,WAAK2F,QAAL,CAAc;AAAE3F,QAAAA,OAAO,EAAPA;AAAF,OAAd;AACA;AACD,GA/TF;;AAAA,SAiUCqB,eAjUD,GAiUC,2BAAkB;AACjB,SAAKsE,QAAL,CAAc;AACb5F,MAAAA,SAAS,EAAE;AADE,KAAd;AAGA,GArUF;;AAAA,SAuUC6F,MAvUD,GAuUC,kBAAS;AACR,QAAI,KAAK3G,KAAL,CAAW2G,MAAf,EAAuB;AACtB,0BACC,iCACE,KAAK3G,KAAL,CAAW2G,MAAX,CAAkB,KAAKxG,SAAvB,EAAkC,KAAKU,KAAL,CAAWC,SAAX,IAAwB,KAAKD,KAAL,CAAWE,OAArE,EAA8E,KAAKV,iBAAnF,CADF,eAEC;AAAK,QAAA,GAAG,EAAE,KAAKrB,MAAf;AAAuB,QAAA,KAAK,EAAE4H;AAA9B,QAFD,CADD;AAMA;;AAED,wBACC,8CACC;AAAQ,MAAA,QAAQ,EAAE,KAAK/F,KAAL,CAAWC,SAAX,IAAwB,KAAKD,KAAL,CAAWE,OAArD;AAA8D,MAAA,OAAO,EAAE,KAAKZ,SAA5E;AAAuF,kCAAvF;AAA4G,2BAAmB,KAAKQ;AAApI,OAA2I,KAAKX,KAAL,CAAW6G,QAAtJ,CADD,eAEC;AAAK,MAAA,GAAG,EAAE,KAAK7H,MAAf;AAAuB,MAAA,KAAK,EAAE4H;AAA9B,MAFD,CADD;AAMA,GAvVF;;AAAA;AAAA,EAAkCE,SAAlC;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sumit_yewale/react",
3
- "version": "1.1.14",
3
+ "version": "1.1.17",
4
4
  "description": "React adapter for csvbox.io",
5
5
  "types": "@types/csvbox__react.d.ts",
6
6
  "author": "csvbox-io",
@@ -9,9 +9,6 @@
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/csvbox-io/react.git"
11
11
  },
12
- "publishConfig": {
13
- "access": "public"
14
- },
15
12
  "main": "dist/index.js",
16
13
  "module": "dist/index.modern.js",
17
14
  "source": "src/index.js",
@@ -35,7 +32,7 @@
35
32
  "react-dom": "^16.13.1 || ^17.0.2 || ^18.0.0 || ^19.0.0"
36
33
  },
37
34
  "dependencies": {
38
- "@sumit_yewale/adapter-core": "^0.0.1"
35
+ "@sumit_yewale/adapter-core": "^0.1.0"
39
36
  },
40
37
  "devDependencies": {
41
38
  "babel-eslint": "^10.0.3",