@sumit_yewale/react 1.1.14 → 1.1.18-fix.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.
@@ -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,13 +25,20 @@ 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;
28
33
 
29
34
  openModal(): void;
30
35
 
36
+ openModalWithFile(file: File): void;
37
+
31
38
  componentDidMount(): void;
32
39
 
33
40
  initImporter(): void;
34
41
 
35
- enableInitator(): void;
42
+ enableInitiator(): void;
36
43
  }
37
44
  }
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.18-fix.1";
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,86 @@ 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.messageGate = adapterCore.createMessageGate();
99
+ _this.importTracker = adapterCore.createImportTracker();
100
+ _this.isModalShown = false;
101
+ _this.isReady = false;
102
+ _this.pendingFile = null;
43
103
  _this.uuid = adapterCore.generateUuid();
44
104
  _this.state = {
45
- isLoading: true
105
+ isLoading: true,
106
+ blocked: false
46
107
  };
47
108
  _this.iframe = null;
109
+ _this.registryEntry = {
110
+ getHolder: function getHolder() {
111
+ return _this.holder.current;
112
+ }
113
+ };
114
+ _this.fileSender = adapterCore.createFileSender({
115
+ getIframe: function getIframe() {
116
+ return _this.iframe;
117
+ },
118
+ getToken: function getToken() {
119
+ return _this.uuid;
120
+ },
121
+ getTargetOrigin: function getTargetOrigin() {
122
+ return _this.targetOrigin;
123
+ },
124
+ getBaseDomain: function getBaseDomain() {
125
+ return _this.baseDomain;
126
+ },
127
+ takeFile: function takeFile() {
128
+ var file = _this.pendingFile;
129
+ _this.pendingFile = null;
130
+ return file;
131
+ },
132
+ onSent: function onSent() {
133
+ return _this.startFileAckTimer();
134
+ }
135
+ });
48
136
  return _this;
49
137
  }
50
138
 
51
139
  var _proto = CSVBoxButton.prototype;
52
140
 
53
141
  _proto.componentDidMount = function componentDidMount() {
142
+ var _this2 = this;
143
+
144
+ this.syncBlocked();
145
+ this.unsubscribeOpenImporters = subscribeOpenImporters(function () {
146
+ return _this2.syncBlocked();
147
+ });
54
148
  var lazy = this.props.lazy;
55
149
 
56
150
  if (!lazy && !this.iframe) {
57
151
  this.initImporter();
58
152
  } else if (lazy) {
59
- this.enableInitator();
153
+ this.enableInitiator();
60
154
  }
61
155
  };
62
156
 
63
157
  _proto.initImporter = function initImporter() {
64
- var _this2 = this;
65
-
66
- var loadStarted = this.props.loadStarted;
158
+ var _this3 = this;
159
+
160
+ var _this$props = this.props,
161
+ loadStarted = _this$props.loadStarted,
162
+ user = _this$props.user,
163
+ dynamicColumns = _this$props.dynamicColumns,
164
+ options = _this$props.options,
165
+ onReady = _this$props.onReady,
166
+ onImport = _this$props.onImport,
167
+ onSubmit = _this$props.onSubmit,
168
+ onClose = _this$props.onClose,
169
+ licenseKey = _this$props.licenseKey,
170
+ dataLocation = _this$props.dataLocation,
171
+ customDomain = _this$props.customDomain,
172
+ language = _this$props.language,
173
+ environment = _this$props.environment,
174
+ theme = _this$props.theme;
67
175
  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
176
  var iframeUrl = adapterCore.buildImportUrl({
82
177
  licenseKey: licenseKey,
83
178
  customDomain: customDomain,
@@ -86,19 +181,39 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
86
181
  theme: theme,
87
182
  environment: environment
88
183
  }, "react", version);
184
+ this.targetOrigin = new URL(iframeUrl).origin;
185
+ this.baseDomain = customDomain || "app.csvbox.io";
186
+ this.fileSender.reset();
89
187
 
90
188
  var handleModalClosed = function handleModalClosed() {
91
- if (_this2.holder && _this2.holder.current) {
92
- _this2.holder.current.style.display = 'none';
93
- _this2.holder.current.innerHTML = '';
189
+ if (_this3.importTracker.isInFlight()) {
190
+ if (_this3.holder.current) {
191
+ _this3.holder.current.style.display = 'none';
192
+ _this3.holder.current.style.pointerEvents = 'auto';
193
+ }
194
+
195
+ _this3.lifecycle.markHidden();
196
+
197
+ _this3.isModalShown = false;
198
+
199
+ _this3.clearFileAckTimer();
200
+
201
+ unregisterOpenImporter(_this3.registryEntry);
202
+ onClose === null || onClose === void 0 ? void 0 : onClose();
203
+ return;
94
204
  }
95
205
 
96
- _this2.lifecycle.markClosed();
206
+ _this3.destroyImporter();
97
207
 
98
- _this2.iframe = null;
99
208
  onClose === null || onClose === void 0 ? void 0 : onClose();
100
209
  };
101
210
 
211
+ var finishImport = function finishImport(ended) {
212
+ if (ended && !_this3.isModalShown && _this3.iframe) {
213
+ _this3.destroyImporter();
214
+ }
215
+ };
216
+
102
217
  if (this.messageListener) {
103
218
  window.removeEventListener("message", this.messageListener, false);
104
219
  }
@@ -107,6 +222,16 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
107
222
  var legacy = adapterCore.classifyLegacyMessage(event.data);
108
223
 
109
224
  if (legacy) {
225
+ if (!_this3.iframe || event.source !== _this3.iframe.contentWindow) {
226
+ return;
227
+ }
228
+
229
+ if (!_this3.messageGate.allowLegacy()) {
230
+ return;
231
+ }
232
+
233
+ var _ended = _this3.importTracker.observe(legacy);
234
+
110
235
  if (legacy.type === "mainModalHidden") {
111
236
  handleModalClosed();
112
237
  }
@@ -119,15 +244,59 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
119
244
  onImport(false);
120
245
  }
121
246
 
247
+ finishImport(_ended);
122
248
  return;
123
249
  }
124
250
 
125
- var message = adapterCore.classifyStructuredMessage(event.data, _this2.uuid);
251
+ var raw = event.data;
252
+
253
+ if (raw && typeof raw === "object" && raw.data && raw.data.unique_token == _this3.uuid) {
254
+ _this3.fileSender.learnOrigin(event);
255
+
256
+ if (raw.type === "csvbox-set-file-rejected" && raw.data.reason === "not-a-file") {
257
+ return;
258
+ }
259
+
260
+ if (raw.type === "csvbox-modal-shown") {
261
+ _this3.clearFileAckTimer();
262
+
263
+ registerOpenImporter(_this3.registryEntry);
264
+ _this3.isModalShown = true;
265
+
266
+ _this3.lifecycle.requestOpen();
267
+
268
+ if (_this3.holder.current) {
269
+ _this3.holder.current.style.display = 'block';
270
+ _this3.holder.current.style.pointerEvents = 'auto';
271
+ }
272
+
273
+ return;
274
+ }
275
+
276
+ if (raw.type === "csvbox-set-file-rejected") {
277
+ _this3.clearFileAckTimer();
278
+
279
+ if (!_this3.isModalShown && _this3.holder.current) {
280
+ _this3.holder.current.style.display = 'none';
281
+ _this3.holder.current.style.pointerEvents = 'auto';
282
+ unregisterOpenImporter(_this3.registryEntry);
283
+ }
284
+
285
+ console.warn("[csvbox] importer declined the supplied file: " + raw.data.reason);
286
+ return;
287
+ }
288
+ }
289
+
290
+ var message = adapterCore.classifyStructuredMessage(event.data, _this3.uuid);
126
291
 
127
292
  if (!message) {
128
293
  return;
129
294
  }
130
295
 
296
+ _this3.messageGate.markTyped();
297
+
298
+ var ended = _this3.importTracker.observe(message);
299
+
131
300
  if (message.type === "data-on-submit") {
132
301
  onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(message.metadata);
133
302
  } else if (message.type === "data-push-status") {
@@ -139,25 +308,32 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
139
308
  } else if (message.type === "csvbox-upload-failed") {
140
309
  onImport(false);
141
310
  }
311
+
312
+ finishImport(ended);
142
313
  };
143
314
 
144
315
  window.addEventListener("message", this.messageListener, false);
145
316
  this.uuid = adapterCore.generateUuid();
146
- var self = this;
317
+ this.messageGate.reset();
318
+ this.importTracker.reset();
147
319
  var iframe = document.createElement("iframe");
148
320
  this.iframe = iframe;
149
321
  iframe.setAttribute("src", iframeUrl);
322
+ iframe.setAttribute("allow", "clipboard-read; clipboard-write *");
150
323
  iframe.frameBorder = 0;
151
324
  iframe.classList.add('csvbox-iframe');
152
325
  Object.assign(iframe.style, adapterCore.IFRAME_STYLE);
153
326
 
154
327
  iframe.onload = function () {
155
- self.enableInitator();
156
- iframe.contentWindow.postMessage(adapterCore.buildInitPayload(user, dynamicColumns, options, self.uuid), "*");
328
+ _this3.isReady = true;
329
+
330
+ _this3.enableInitiator();
331
+
332
+ iframe.contentWindow.postMessage(adapterCore.buildInitPayload(user, dynamicColumns, options, _this3.uuid), "*");
157
333
  onReady === null || onReady === void 0 ? void 0 : onReady();
158
334
 
159
- if (self.lifecycle.markReady()) {
160
- self.openModal();
335
+ if (_this3.lifecycle.markReady()) {
336
+ _this3.openModal();
161
337
  }
162
338
  };
163
339
 
@@ -165,19 +341,134 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
165
341
  };
166
342
 
167
343
  _proto.openModal = function openModal() {
344
+ registerOpenImporter(this.registryEntry);
345
+
168
346
  if (!this.iframe) {
169
347
  this.lifecycle.requestOpen();
170
348
  this.initImporter();
171
349
  return;
172
350
  }
173
351
 
352
+ if (this.pendingFile) {
353
+ if (!this.isReady) {
354
+ this.lifecycle.requestOpen();
355
+ return;
356
+ }
357
+
358
+ this.holder.current.style.pointerEvents = 'none';
359
+ this.holder.current.style.display = 'block';
360
+ this.fileSender.send();
361
+ return;
362
+ }
363
+
174
364
  if (this.lifecycle.requestOpen()) {
365
+ this.isModalShown = true;
175
366
  this.iframe.contentWindow.postMessage('openModal', '*');
367
+ this.holder.current.style.pointerEvents = 'auto';
176
368
  this.holder.current.style.display = 'block';
177
369
  }
178
370
  };
179
371
 
180
- _proto.enableInitator = function enableInitator() {
372
+ _proto.openModalWithFile = function openModalWithFile(file) {
373
+ if (!window.File || !(file instanceof window.File)) {
374
+ return;
375
+ }
376
+
377
+ this.pendingFile = file;
378
+
379
+ if (this.isModalShown && this.iframe && this.isReady) {
380
+ this.fileSender.send();
381
+ return;
382
+ }
383
+
384
+ this.openModal();
385
+ };
386
+
387
+ _proto.clearProbeTimer = function clearProbeTimer() {
388
+ this.clearFileAckTimer();
389
+ this.fileSender.reset();
390
+ };
391
+
392
+ _proto.startFileAckTimer = function startFileAckTimer() {
393
+ var _this4 = this;
394
+
395
+ this.clearFileAckTimer();
396
+ this.fileAckTimer = setTimeout(function () {
397
+ _this4.fileAckTimer = null;
398
+
399
+ _this4.giveUpOnFile();
400
+ }, FILE_ACK_TIMEOUT_MS);
401
+ };
402
+
403
+ _proto.clearFileAckTimer = function clearFileAckTimer() {
404
+ if (this.fileAckTimer) {
405
+ clearTimeout(this.fileAckTimer);
406
+ this.fileAckTimer = null;
407
+ }
408
+ };
409
+
410
+ _proto.giveUpOnFile = function giveUpOnFile() {
411
+ if (this.isModalShown) {
412
+ return;
413
+ }
414
+
415
+ var holder = this.holder.current;
416
+
417
+ if (holder) {
418
+ holder.style.display = 'none';
419
+ holder.style.pointerEvents = 'auto';
420
+ }
421
+
422
+ unregisterOpenImporter(this.registryEntry);
423
+ console.warn("[csvbox] the importer did not respond to the supplied file");
424
+ };
425
+
426
+ _proto.destroyImporter = function destroyImporter() {
427
+ if (this.holder.current) {
428
+ this.holder.current.style.display = 'none';
429
+ this.holder.current.style.pointerEvents = 'auto';
430
+ this.holder.current.innerHTML = '';
431
+ }
432
+
433
+ this.lifecycle.markClosed();
434
+ this.isModalShown = false;
435
+ this.isReady = false;
436
+ this.iframe = null;
437
+ this.messageGate.reset();
438
+ this.importTracker.reset();
439
+ this.clearProbeTimer();
440
+ unregisterOpenImporter(this.registryEntry);
441
+ };
442
+
443
+ _proto.teardown = function teardown() {
444
+ this.destroyImporter();
445
+
446
+ if (this.unsubscribeOpenImporters) {
447
+ this.unsubscribeOpenImporters();
448
+ this.unsubscribeOpenImporters = null;
449
+ }
450
+
451
+ if (this.messageListener) {
452
+ window.removeEventListener("message", this.messageListener, false);
453
+ this.messageListener = null;
454
+ }
455
+ };
456
+
457
+ _proto.componentWillUnmount = function componentWillUnmount() {
458
+ this.teardown();
459
+ };
460
+
461
+ _proto.syncBlocked = function syncBlocked() {
462
+ var blocked = isBlockedByOpenImporter(this.registryEntry);
463
+
464
+ if (blocked !== this.state.blocked) {
465
+ this.setState({
466
+ blocked: blocked
467
+ });
468
+ }
469
+ };
470
+
471
+ _proto.enableInitiator = function enableInitiator() {
181
472
  this.setState({
182
473
  isLoading: false
183
474
  });
@@ -185,21 +476,21 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
185
476
 
186
477
  _proto.render = function render() {
187
478
  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", {
479
+ 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
480
  ref: this.holder,
200
481
  style: adapterCore.HOLDER_STYLE
201
482
  }));
202
483
  }
484
+
485
+ return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("button", {
486
+ disabled: this.state.isLoading || this.state.blocked,
487
+ onClick: this.openModal,
488
+ "data-csvbox-initator": true,
489
+ "data-csvbox-token": this.uuid
490
+ }, this.props.children), /*#__PURE__*/React__default.createElement("div", {
491
+ ref: this.holder,
492
+ style: adapterCore.HOLDER_STYLE
493
+ }));
203
494
  };
204
495
 
205
496
  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","Component"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAaaA,YAAb;AAAA;;AAEC,wBAAYC,KAAZ,EAAmB;AAAA;;AAClB,kCAAMA,KAAN;AACA,UAAKC,MAAL,GAAcC,cAAK,CAACC,SAAN,EAAd;AACA,UAAKC,SAAL,GAAiB,MAAKA,SAAL,CAAeC,IAAf,+BAAjB;AACA,UAAKC,SAAL,GAAiBC,gCAAoB,EAArC;AACA,UAAKC,IAAL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AL,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\tcreateMessageGate,\n\tcreateImportTracker,\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.messageGate = createMessageGate();\n\t\tthis.importTracker = createImportTracker();\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.importTracker.isInFlight()) {\n\t\t\t\t// Closed after submitting and before the result arrived: keep the iframe and its\n\t\t\t\t// listener so the late result still reaches onImport. It is removed once that\n\t\t\t\t// result has been delivered (see below), so the next open is a fresh load.\n\t\t\t\tif (this.holder.current) {\n\t\t\t\t\tthis.holder.current.style.display = 'none';\n\t\t\t\t\tthis.holder.current.style.pointerEvents = 'auto';\n\t\t\t\t}\n\t\t\t\tthis.lifecycle.markHidden();\n\t\t\t\tthis.isModalShown = false;\n\t\t\t\tthis.clearFileAckTimer();\n\t\t\t\tunregisterOpenImporter(this.registryEntry);\n\t\t\t\tonClose?.();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.destroyImporter();\n\t\t\tonClose?.();\n\t\t};\n\n\t\t// Called after the result of an import has been delivered. If the modal was closed in the\n\t\t// meantime the iframe was only hidden, so remove it now.\n\t\tconst finishImport = (ended) => {\n\t\t\tif (ended && !this.isModalShown && this.iframe) {\n\t\t\t\tthis.destroyImporter();\n\t\t\t}\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\t// A newer importer sends the typed message as well; act on that one only.\n\t\t\t\tif (!this.messageGate.allowLegacy()) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst ended = this.importTracker.observe(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\tfinishImport(ended);\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\t\t\tthis.messageGate.markTyped();\n\t\t\tconst ended = this.importTracker.observe(message);\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\tfinishImport(ended);\n\t\t};\n\n\t\twindow.addEventListener(\"message\", this.messageListener, false);\n\n\t\tthis.uuid = generateUuid();\n\t\tthis.messageGate.reset();\n\t\tthis.importTracker.reset();\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\t// Puts the importer away: the next open builds a new iframe with a new token.\n\tdestroyImporter() {\n\t\tif (this.holder.current) {\n\t\t\tthis.holder.current.style.display = 'none';\n\t\t\tthis.holder.current.style.pointerEvents = 'auto';\n\t\t\tthis.holder.current.innerHTML = '';\n\t\t}\n\t\tthis.lifecycle.markClosed();\n\t\tthis.isModalShown = false;\n\t\tthis.isReady = false;\n\t\tthis.iframe = null;\n\t\tthis.messageGate.reset();\n\t\tthis.importTracker.reset();\n\t\t// A new iframe is built on the next open, so the origin is learned again.\n\t\tthis.clearProbeTimer();\n\t\tunregisterOpenImporter(this.registryEntry);\n\t}\n\n\t// Everything the component set up outside React. Leaves the instance as it was before its first\n\t// mount, so a remount (React 18 StrictMode in development) initialises it again.\n\tteardown() {\n\t\tthis.destroyImporter();\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\tcomponentWillUnmount() {\n\t\tthis.teardown();\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","messageGate","createMessageGate","importTracker","createImportTracker","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","isInFlight","display","pointerEvents","markHidden","clearFileAckTimer","destroyImporter","finishImport","ended","messageListener","removeEventListener","event","legacy","classifyLegacyMessage","data","source","contentWindow","allowLegacy","observe","type","raw","unique_token","learnOrigin","reason","requestOpen","console","warn","message","classifyStructuredMessage","markTyped","metadata","success","addEventListener","document","createElement","setAttribute","frameBorder","classList","add","Object","assign","IFRAME_STYLE","onload","postMessage","buildInitPayload","markReady","appendChild","send","File","clearProbeTimer","fileAckTimer","setTimeout","giveUpOnFile","clearTimeout","innerHTML","markClosed","teardown","componentWillUnmount","setState","render","HOLDER_STYLE","children","Component"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,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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B,KAAKD,KAAL,CAAWE,OAArD;AAA8D,MAAA,OAAO,EAAE,KAAKhB,SAA5E;AAAuF,kCAAvF;AAA4G,2BAAmB,KAAKY;AAApI,OAA2I,KAAKf,KAAL,CAAW0H,QAAtJ,CADD,eAECzH;AAAK,MAAA,GAAG,EAAE,KAAKjB,MAAf;AAAuB,MAAA,KAAK,EAAEyI;AAA9B,MAFD,CADD;AAMA,GAvYF;;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, createMessageGate, createImportTracker, 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.18-fix.1";
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,86 @@ 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.messageGate = createMessageGate();
96
+ _this.importTracker = createImportTracker();
97
+ _this.isModalShown = false;
98
+ _this.isReady = false;
99
+ _this.pendingFile = null;
40
100
  _this.uuid = generateUuid();
41
101
  _this.state = {
42
- isLoading: true
102
+ isLoading: true,
103
+ blocked: false
43
104
  };
44
105
  _this.iframe = null;
106
+ _this.registryEntry = {
107
+ getHolder: function getHolder() {
108
+ return _this.holder.current;
109
+ }
110
+ };
111
+ _this.fileSender = createFileSender({
112
+ getIframe: function getIframe() {
113
+ return _this.iframe;
114
+ },
115
+ getToken: function getToken() {
116
+ return _this.uuid;
117
+ },
118
+ getTargetOrigin: function getTargetOrigin() {
119
+ return _this.targetOrigin;
120
+ },
121
+ getBaseDomain: function getBaseDomain() {
122
+ return _this.baseDomain;
123
+ },
124
+ takeFile: function takeFile() {
125
+ var file = _this.pendingFile;
126
+ _this.pendingFile = null;
127
+ return file;
128
+ },
129
+ onSent: function onSent() {
130
+ return _this.startFileAckTimer();
131
+ }
132
+ });
45
133
  return _this;
46
134
  }
47
135
 
48
136
  var _proto = CSVBoxButton.prototype;
49
137
 
50
138
  _proto.componentDidMount = function componentDidMount() {
139
+ var _this2 = this;
140
+
141
+ this.syncBlocked();
142
+ this.unsubscribeOpenImporters = subscribeOpenImporters(function () {
143
+ return _this2.syncBlocked();
144
+ });
51
145
  var lazy = this.props.lazy;
52
146
 
53
147
  if (!lazy && !this.iframe) {
54
148
  this.initImporter();
55
149
  } else if (lazy) {
56
- this.enableInitator();
150
+ this.enableInitiator();
57
151
  }
58
152
  };
59
153
 
60
154
  _proto.initImporter = function initImporter() {
61
- var _this2 = this;
62
-
63
- var loadStarted = this.props.loadStarted;
155
+ var _this3 = this;
156
+
157
+ var _this$props = this.props,
158
+ loadStarted = _this$props.loadStarted,
159
+ user = _this$props.user,
160
+ dynamicColumns = _this$props.dynamicColumns,
161
+ options = _this$props.options,
162
+ onReady = _this$props.onReady,
163
+ onImport = _this$props.onImport,
164
+ onSubmit = _this$props.onSubmit,
165
+ onClose = _this$props.onClose,
166
+ licenseKey = _this$props.licenseKey,
167
+ dataLocation = _this$props.dataLocation,
168
+ customDomain = _this$props.customDomain,
169
+ language = _this$props.language,
170
+ environment = _this$props.environment,
171
+ theme = _this$props.theme;
64
172
  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
173
  var iframeUrl = buildImportUrl({
79
174
  licenseKey: licenseKey,
80
175
  customDomain: customDomain,
@@ -83,19 +178,39 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
83
178
  theme: theme,
84
179
  environment: environment
85
180
  }, "react", version);
181
+ this.targetOrigin = new URL(iframeUrl).origin;
182
+ this.baseDomain = customDomain || "app.csvbox.io";
183
+ this.fileSender.reset();
86
184
 
87
185
  var handleModalClosed = function handleModalClosed() {
88
- if (_this2.holder && _this2.holder.current) {
89
- _this2.holder.current.style.display = 'none';
90
- _this2.holder.current.innerHTML = '';
186
+ if (_this3.importTracker.isInFlight()) {
187
+ if (_this3.holder.current) {
188
+ _this3.holder.current.style.display = 'none';
189
+ _this3.holder.current.style.pointerEvents = 'auto';
190
+ }
191
+
192
+ _this3.lifecycle.markHidden();
193
+
194
+ _this3.isModalShown = false;
195
+
196
+ _this3.clearFileAckTimer();
197
+
198
+ unregisterOpenImporter(_this3.registryEntry);
199
+ onClose === null || onClose === void 0 ? void 0 : onClose();
200
+ return;
91
201
  }
92
202
 
93
- _this2.lifecycle.markClosed();
203
+ _this3.destroyImporter();
94
204
 
95
- _this2.iframe = null;
96
205
  onClose === null || onClose === void 0 ? void 0 : onClose();
97
206
  };
98
207
 
208
+ var finishImport = function finishImport(ended) {
209
+ if (ended && !_this3.isModalShown && _this3.iframe) {
210
+ _this3.destroyImporter();
211
+ }
212
+ };
213
+
99
214
  if (this.messageListener) {
100
215
  window.removeEventListener("message", this.messageListener, false);
101
216
  }
@@ -104,6 +219,16 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
104
219
  var legacy = classifyLegacyMessage(event.data);
105
220
 
106
221
  if (legacy) {
222
+ if (!_this3.iframe || event.source !== _this3.iframe.contentWindow) {
223
+ return;
224
+ }
225
+
226
+ if (!_this3.messageGate.allowLegacy()) {
227
+ return;
228
+ }
229
+
230
+ var _ended = _this3.importTracker.observe(legacy);
231
+
107
232
  if (legacy.type === "mainModalHidden") {
108
233
  handleModalClosed();
109
234
  }
@@ -116,15 +241,59 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
116
241
  onImport(false);
117
242
  }
118
243
 
244
+ finishImport(_ended);
119
245
  return;
120
246
  }
121
247
 
122
- var message = classifyStructuredMessage(event.data, _this2.uuid);
248
+ var raw = event.data;
249
+
250
+ if (raw && typeof raw === "object" && raw.data && raw.data.unique_token == _this3.uuid) {
251
+ _this3.fileSender.learnOrigin(event);
252
+
253
+ if (raw.type === "csvbox-set-file-rejected" && raw.data.reason === "not-a-file") {
254
+ return;
255
+ }
256
+
257
+ if (raw.type === "csvbox-modal-shown") {
258
+ _this3.clearFileAckTimer();
259
+
260
+ registerOpenImporter(_this3.registryEntry);
261
+ _this3.isModalShown = true;
262
+
263
+ _this3.lifecycle.requestOpen();
264
+
265
+ if (_this3.holder.current) {
266
+ _this3.holder.current.style.display = 'block';
267
+ _this3.holder.current.style.pointerEvents = 'auto';
268
+ }
269
+
270
+ return;
271
+ }
272
+
273
+ if (raw.type === "csvbox-set-file-rejected") {
274
+ _this3.clearFileAckTimer();
275
+
276
+ if (!_this3.isModalShown && _this3.holder.current) {
277
+ _this3.holder.current.style.display = 'none';
278
+ _this3.holder.current.style.pointerEvents = 'auto';
279
+ unregisterOpenImporter(_this3.registryEntry);
280
+ }
281
+
282
+ console.warn("[csvbox] importer declined the supplied file: " + raw.data.reason);
283
+ return;
284
+ }
285
+ }
286
+
287
+ var message = classifyStructuredMessage(event.data, _this3.uuid);
123
288
 
124
289
  if (!message) {
125
290
  return;
126
291
  }
127
292
 
293
+ _this3.messageGate.markTyped();
294
+
295
+ var ended = _this3.importTracker.observe(message);
296
+
128
297
  if (message.type === "data-on-submit") {
129
298
  onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(message.metadata);
130
299
  } else if (message.type === "data-push-status") {
@@ -136,25 +305,32 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
136
305
  } else if (message.type === "csvbox-upload-failed") {
137
306
  onImport(false);
138
307
  }
308
+
309
+ finishImport(ended);
139
310
  };
140
311
 
141
312
  window.addEventListener("message", this.messageListener, false);
142
313
  this.uuid = generateUuid();
143
- var self = this;
314
+ this.messageGate.reset();
315
+ this.importTracker.reset();
144
316
  var iframe = document.createElement("iframe");
145
317
  this.iframe = iframe;
146
318
  iframe.setAttribute("src", iframeUrl);
319
+ iframe.setAttribute("allow", "clipboard-read; clipboard-write *");
147
320
  iframe.frameBorder = 0;
148
321
  iframe.classList.add('csvbox-iframe');
149
322
  Object.assign(iframe.style, IFRAME_STYLE);
150
323
 
151
324
  iframe.onload = function () {
152
- self.enableInitator();
153
- iframe.contentWindow.postMessage(buildInitPayload(user, dynamicColumns, options, self.uuid), "*");
325
+ _this3.isReady = true;
326
+
327
+ _this3.enableInitiator();
328
+
329
+ iframe.contentWindow.postMessage(buildInitPayload(user, dynamicColumns, options, _this3.uuid), "*");
154
330
  onReady === null || onReady === void 0 ? void 0 : onReady();
155
331
 
156
- if (self.lifecycle.markReady()) {
157
- self.openModal();
332
+ if (_this3.lifecycle.markReady()) {
333
+ _this3.openModal();
158
334
  }
159
335
  };
160
336
 
@@ -162,19 +338,134 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
162
338
  };
163
339
 
164
340
  _proto.openModal = function openModal() {
341
+ registerOpenImporter(this.registryEntry);
342
+
165
343
  if (!this.iframe) {
166
344
  this.lifecycle.requestOpen();
167
345
  this.initImporter();
168
346
  return;
169
347
  }
170
348
 
349
+ if (this.pendingFile) {
350
+ if (!this.isReady) {
351
+ this.lifecycle.requestOpen();
352
+ return;
353
+ }
354
+
355
+ this.holder.current.style.pointerEvents = 'none';
356
+ this.holder.current.style.display = 'block';
357
+ this.fileSender.send();
358
+ return;
359
+ }
360
+
171
361
  if (this.lifecycle.requestOpen()) {
362
+ this.isModalShown = true;
172
363
  this.iframe.contentWindow.postMessage('openModal', '*');
364
+ this.holder.current.style.pointerEvents = 'auto';
173
365
  this.holder.current.style.display = 'block';
174
366
  }
175
367
  };
176
368
 
177
- _proto.enableInitator = function enableInitator() {
369
+ _proto.openModalWithFile = function openModalWithFile(file) {
370
+ if (!window.File || !(file instanceof window.File)) {
371
+ return;
372
+ }
373
+
374
+ this.pendingFile = file;
375
+
376
+ if (this.isModalShown && this.iframe && this.isReady) {
377
+ this.fileSender.send();
378
+ return;
379
+ }
380
+
381
+ this.openModal();
382
+ };
383
+
384
+ _proto.clearProbeTimer = function clearProbeTimer() {
385
+ this.clearFileAckTimer();
386
+ this.fileSender.reset();
387
+ };
388
+
389
+ _proto.startFileAckTimer = function startFileAckTimer() {
390
+ var _this4 = this;
391
+
392
+ this.clearFileAckTimer();
393
+ this.fileAckTimer = setTimeout(function () {
394
+ _this4.fileAckTimer = null;
395
+
396
+ _this4.giveUpOnFile();
397
+ }, FILE_ACK_TIMEOUT_MS);
398
+ };
399
+
400
+ _proto.clearFileAckTimer = function clearFileAckTimer() {
401
+ if (this.fileAckTimer) {
402
+ clearTimeout(this.fileAckTimer);
403
+ this.fileAckTimer = null;
404
+ }
405
+ };
406
+
407
+ _proto.giveUpOnFile = function giveUpOnFile() {
408
+ if (this.isModalShown) {
409
+ return;
410
+ }
411
+
412
+ var holder = this.holder.current;
413
+
414
+ if (holder) {
415
+ holder.style.display = 'none';
416
+ holder.style.pointerEvents = 'auto';
417
+ }
418
+
419
+ unregisterOpenImporter(this.registryEntry);
420
+ console.warn("[csvbox] the importer did not respond to the supplied file");
421
+ };
422
+
423
+ _proto.destroyImporter = function destroyImporter() {
424
+ if (this.holder.current) {
425
+ this.holder.current.style.display = 'none';
426
+ this.holder.current.style.pointerEvents = 'auto';
427
+ this.holder.current.innerHTML = '';
428
+ }
429
+
430
+ this.lifecycle.markClosed();
431
+ this.isModalShown = false;
432
+ this.isReady = false;
433
+ this.iframe = null;
434
+ this.messageGate.reset();
435
+ this.importTracker.reset();
436
+ this.clearProbeTimer();
437
+ unregisterOpenImporter(this.registryEntry);
438
+ };
439
+
440
+ _proto.teardown = function teardown() {
441
+ this.destroyImporter();
442
+
443
+ if (this.unsubscribeOpenImporters) {
444
+ this.unsubscribeOpenImporters();
445
+ this.unsubscribeOpenImporters = null;
446
+ }
447
+
448
+ if (this.messageListener) {
449
+ window.removeEventListener("message", this.messageListener, false);
450
+ this.messageListener = null;
451
+ }
452
+ };
453
+
454
+ _proto.componentWillUnmount = function componentWillUnmount() {
455
+ this.teardown();
456
+ };
457
+
458
+ _proto.syncBlocked = function syncBlocked() {
459
+ var blocked = isBlockedByOpenImporter(this.registryEntry);
460
+
461
+ if (blocked !== this.state.blocked) {
462
+ this.setState({
463
+ blocked: blocked
464
+ });
465
+ }
466
+ };
467
+
468
+ _proto.enableInitiator = function enableInitiator() {
178
469
  this.setState({
179
470
  isLoading: false
180
471
  });
@@ -182,21 +473,21 @@ var CSVBoxButton = /*#__PURE__*/function (_Component) {
182
473
 
183
474
  _proto.render = function render() {
184
475
  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", {
476
+ return /*#__PURE__*/React.createElement("div", null, this.props.render(this.openModal, this.state.isLoading || this.state.blocked, this.openModalWithFile), /*#__PURE__*/React.createElement("div", {
196
477
  ref: this.holder,
197
478
  style: HOLDER_STYLE
198
479
  }));
199
480
  }
481
+
482
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("button", {
483
+ disabled: this.state.isLoading || this.state.blocked,
484
+ onClick: this.openModal,
485
+ "data-csvbox-initator": true,
486
+ "data-csvbox-token": this.uuid
487
+ }, this.props.children), /*#__PURE__*/React.createElement("div", {
488
+ ref: this.holder,
489
+ style: HOLDER_STYLE
490
+ }));
200
491
  };
201
492
 
202
493
  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;AAAA;;AAEd,QAAQE,WAAR,GAAwB,KAAKjB,KAA7B,CAAQiB,WAAR;AAEAA,IAAAA,WAAW,SAAX,IAAAA,WAAW,WAAX,YAAAA,WAAW;AAEX,QAAQC,IAAR,GAAiB,KAAKlB,KAAtB,CAAQkB,IAAR;AACA,QAAQC,cAAR,GAA2B,KAAKnB,KAAhC,CAAQmB,cAAR;AACA,QAAQC,OAAR,GAAoB,KAAKpB,KAAzB,CAAQoB,OAAR;AACA,QAAQC,OAAR,GAAoB,KAAKrB,KAAzB,CAAQqB,OAAR;AACA,QAAQC,QAAR,GAAqB,KAAKtB,KAA1B,CAAQsB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,EAAJ,EAAkC;AACjC,WAAKzD,MAAL,CAAYoD,aAAZ,CAA0BC,WAA1B,CAAsC,WAAtC,EAAmD,GAAnD;AACA,WAAKhE,MAAL,CAAYkC,OAAZ,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,0BACC,iCACE,KAAKvE,KAAL,CAAWuE,MAAX,CAAkB,KAAKnE,SAAvB,EAAkC,KAAKM,KAAL,CAAWC,SAA7C,CADF,eAEC;AAAK,QAAA,GAAG,EAAE,KAAKV,MAAf;AAAuB,QAAA,KAAK,EAAEuE;AAA9B,QAFD,CADD;AAMA,KAPD,MAOO;AACN,0BACC,8CACC;AAAQ,QAAA,QAAQ,EAAE,KAAK9D,KAAL,CAAWC,SAA7B;AAAwC,QAAA,OAAO,EAAE,KAAKP,SAAtD;AAAiE,oCAAjE;AAAsF,6BAAmB,KAAKI;AAA9G,SAAqH,KAAKR,KAAL,CAAWyE,QAAhI,CADD,eAEC;AAAK,QAAA,GAAG,EAAE,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\tcreateMessageGate,\n\tcreateImportTracker,\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.messageGate = createMessageGate();\n\t\tthis.importTracker = createImportTracker();\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.importTracker.isInFlight()) {\n\t\t\t\t// Closed after submitting and before the result arrived: keep the iframe and its\n\t\t\t\t// listener so the late result still reaches onImport. It is removed once that\n\t\t\t\t// result has been delivered (see below), so the next open is a fresh load.\n\t\t\t\tif (this.holder.current) {\n\t\t\t\t\tthis.holder.current.style.display = 'none';\n\t\t\t\t\tthis.holder.current.style.pointerEvents = 'auto';\n\t\t\t\t}\n\t\t\t\tthis.lifecycle.markHidden();\n\t\t\t\tthis.isModalShown = false;\n\t\t\t\tthis.clearFileAckTimer();\n\t\t\t\tunregisterOpenImporter(this.registryEntry);\n\t\t\t\tonClose?.();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.destroyImporter();\n\t\t\tonClose?.();\n\t\t};\n\n\t\t// Called after the result of an import has been delivered. If the modal was closed in the\n\t\t// meantime the iframe was only hidden, so remove it now.\n\t\tconst finishImport = (ended) => {\n\t\t\tif (ended && !this.isModalShown && this.iframe) {\n\t\t\t\tthis.destroyImporter();\n\t\t\t}\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\t// A newer importer sends the typed message as well; act on that one only.\n\t\t\t\tif (!this.messageGate.allowLegacy()) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst ended = this.importTracker.observe(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\tfinishImport(ended);\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\t\t\tthis.messageGate.markTyped();\n\t\t\tconst ended = this.importTracker.observe(message);\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\tfinishImport(ended);\n\t\t};\n\n\t\twindow.addEventListener(\"message\", this.messageListener, false);\n\n\t\tthis.uuid = generateUuid();\n\t\tthis.messageGate.reset();\n\t\tthis.importTracker.reset();\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\t// Puts the importer away: the next open builds a new iframe with a new token.\n\tdestroyImporter() {\n\t\tif (this.holder.current) {\n\t\t\tthis.holder.current.style.display = 'none';\n\t\t\tthis.holder.current.style.pointerEvents = 'auto';\n\t\t\tthis.holder.current.innerHTML = '';\n\t\t}\n\t\tthis.lifecycle.markClosed();\n\t\tthis.isModalShown = false;\n\t\tthis.isReady = false;\n\t\tthis.iframe = null;\n\t\tthis.messageGate.reset();\n\t\tthis.importTracker.reset();\n\t\t// A new iframe is built on the next open, so the origin is learned again.\n\t\tthis.clearProbeTimer();\n\t\tunregisterOpenImporter(this.registryEntry);\n\t}\n\n\t// Everything the component set up outside React. Leaves the instance as it was before its first\n\t// mount, so a remount (React 18 StrictMode in development) initialises it again.\n\tteardown() {\n\t\tthis.destroyImporter();\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\tcomponentWillUnmount() {\n\t\tthis.teardown();\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","messageGate","createMessageGate","importTracker","createImportTracker","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","isInFlight","display","pointerEvents","markHidden","clearFileAckTimer","destroyImporter","finishImport","ended","messageListener","removeEventListener","event","legacy","classifyLegacyMessage","data","source","contentWindow","allowLegacy","observe","type","raw","unique_token","learnOrigin","reason","requestOpen","console","warn","message","classifyStructuredMessage","markTyped","metadata","success","addEventListener","document","createElement","setAttribute","frameBorder","classList","add","Object","assign","IFRAME_STYLE","onload","postMessage","buildInitPayload","markReady","appendChild","send","File","clearProbeTimer","fileAckTimer","setTimeout","giveUpOnFile","clearTimeout","innerHTML","markClosed","teardown","componentWillUnmount","setState","render","HOLDER_STYLE","children","Component"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,IAAMA,mBAAmB,GAAG,IAA5B;AAOA,IAAM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,MAvXD,GAuXC,kBAAS;AACR,QAAI,KAAKxH,KAAL,CAAWwH,MAAf,EAAuB;AACtB,0BACC,iCACE,KAAKxH,KAAL,CAAWwH,MAAX,CAAkB,KAAKrH,SAAvB,EAAkC,KAAKc,KAAL,CAAWC,SAAX,IAAwB,KAAKD,KAAL,CAAWE,OAArE,EAA8E,KAAKd,iBAAnF,CADF,eAEC;AAAK,QAAA,GAAG,EAAE,KAAKrB,MAAf;AAAuB,QAAA,KAAK,EAAEyI;AAA9B,QAFD,CADD;AAMA;;AAED,wBACC,8CACC;AAAQ,MAAA,QAAQ,EAAE,KAAKxG,KAAL,CAAWC,SAAX,IAAwB,KAAKD,KAAL,CAAWE,OAArD;AAA8D,MAAA,OAAO,EAAE,KAAKhB,SAA5E;AAAuF,kCAAvF;AAA4G,2BAAmB,KAAKY;AAApI,OAA2I,KAAKf,KAAL,CAAW0H,QAAtJ,CADD,eAEC;AAAK,MAAA,GAAG,EAAE,KAAK1I,MAAf;AAAuB,MAAA,KAAK,EAAEyI;AAA9B,MAFD,CADD;AAMA,GAvYF;;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.18-fix.1",
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.2.0"
39
36
  },
40
37
  "devDependencies": {
41
38
  "babel-eslint": "^10.0.3",