@sumit_yewale/angular 1.1.18 → 1.1.20
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.
- package/README.md +41 -0
- package/bundles/sumit_yewale-angular.umd.js +532 -60
- package/bundles/sumit_yewale-angular.umd.js.map +1 -1
- package/bundles/sumit_yewale-angular.umd.min.js +1 -1
- package/bundles/sumit_yewale-angular.umd.min.js.map +1 -1
- package/esm2015/lib/csvbox-button.component.js +481 -60
- package/esm2015/public-api.js +1 -2
- package/esm5/lib/csvbox-button.component.js +535 -63
- package/esm5/public-api.js +1 -2
- package/fesm2015/sumit_yewale-angular.js +480 -59
- package/fesm2015/sumit_yewale-angular.js.map +1 -1
- package/fesm5/sumit_yewale-angular.js +534 -62
- package/fesm5/sumit_yewale-angular.js.map +1 -1
- package/lib/csvbox-button.component.d.ts +32 -4
- package/package.json +2 -8
- package/sumit_yewale-angular.metadata.json +1 -1
|
@@ -36,11 +36,129 @@
|
|
|
36
36
|
* Generated from: lib/csvbox-button.component.ts
|
|
37
37
|
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
38
38
|
*/
|
|
39
|
+
// How long we wait for the importer to confirm a file it was sent before giving up on it.
|
|
39
40
|
/** @type {?} */
|
|
40
|
-
var
|
|
41
|
+
var FILE_ACK_TIMEOUT_MS = 8000;
|
|
42
|
+
/**
|
|
43
|
+
* @record
|
|
44
|
+
*/
|
|
45
|
+
function OpenImporterEntry() { }
|
|
46
|
+
if (false) {
|
|
47
|
+
/** @type {?} */
|
|
48
|
+
OpenImporterEntry.prototype.getHolder;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @record
|
|
52
|
+
*/
|
|
53
|
+
function OpenImporters() { }
|
|
54
|
+
if (false) {
|
|
55
|
+
/** @type {?} */
|
|
56
|
+
OpenImporters.prototype.open;
|
|
57
|
+
/** @type {?} */
|
|
58
|
+
OpenImporters.prototype.listeners;
|
|
59
|
+
}
|
|
60
|
+
/** @type {?} */
|
|
61
|
+
var OPEN_IMPORTERS_KEY = '__csvboxOpenImporters';
|
|
62
|
+
/** @type {?} */
|
|
63
|
+
var TOP_Z_INDEX = 2147483647;
|
|
64
|
+
/**
|
|
65
|
+
* @return {?}
|
|
66
|
+
*/
|
|
67
|
+
function openImporters() {
|
|
68
|
+
/** @type {?} */
|
|
69
|
+
var w = (/** @type {?} */ (window));
|
|
70
|
+
if (!w[OPEN_IMPORTERS_KEY])
|
|
71
|
+
w[OPEN_IMPORTERS_KEY] = { open: [], listeners: [] };
|
|
72
|
+
return w[OPEN_IMPORTERS_KEY];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @param {?} reg
|
|
76
|
+
* @return {?}
|
|
77
|
+
*/
|
|
78
|
+
function restackOpenImporters(reg) {
|
|
79
|
+
reg.open.forEach((/**
|
|
80
|
+
* @param {?} entry
|
|
81
|
+
* @param {?} i
|
|
82
|
+
* @return {?}
|
|
83
|
+
*/
|
|
84
|
+
function (entry, i) {
|
|
85
|
+
/** @type {?} */
|
|
86
|
+
var holder = entry.getHolder();
|
|
87
|
+
if (holder)
|
|
88
|
+
holder.style.zIndex = String(TOP_Z_INDEX - (reg.open.length - 1 - i));
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* @param {?} entry
|
|
93
|
+
* @return {?}
|
|
94
|
+
*/
|
|
95
|
+
function registerOpenImporter(entry) {
|
|
96
|
+
/** @type {?} */
|
|
97
|
+
var reg = openImporters();
|
|
98
|
+
if (reg.open.indexOf(entry) >= 0)
|
|
99
|
+
return;
|
|
100
|
+
reg.open.push(entry);
|
|
101
|
+
restackOpenImporters(reg);
|
|
102
|
+
reg.listeners.slice().forEach((/**
|
|
103
|
+
* @param {?} fn
|
|
104
|
+
* @return {?}
|
|
105
|
+
*/
|
|
106
|
+
function (fn) { return fn(); }));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* @param {?} entry
|
|
110
|
+
* @return {?}
|
|
111
|
+
*/
|
|
112
|
+
function unregisterOpenImporter(entry) {
|
|
113
|
+
/** @type {?} */
|
|
114
|
+
var reg = openImporters();
|
|
115
|
+
/** @type {?} */
|
|
116
|
+
var i = reg.open.indexOf(entry);
|
|
117
|
+
if (i < 0)
|
|
118
|
+
return;
|
|
119
|
+
reg.open.splice(i, 1);
|
|
120
|
+
restackOpenImporters(reg);
|
|
121
|
+
reg.listeners.slice().forEach((/**
|
|
122
|
+
* @param {?} fn
|
|
123
|
+
* @return {?}
|
|
124
|
+
*/
|
|
125
|
+
function (fn) { return fn(); }));
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* @param {?} entry
|
|
129
|
+
* @return {?}
|
|
130
|
+
*/
|
|
131
|
+
function isBlockedByOpenImporter(entry) {
|
|
132
|
+
/** @type {?} */
|
|
133
|
+
var reg = openImporters();
|
|
134
|
+
return reg.open.length > 0 && reg.open.indexOf(entry) < 0;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @param {?} fn
|
|
138
|
+
* @return {?}
|
|
139
|
+
*/
|
|
140
|
+
function subscribeOpenImporters(fn) {
|
|
141
|
+
/** @type {?} */
|
|
142
|
+
var reg = openImporters();
|
|
143
|
+
reg.listeners.push(fn);
|
|
144
|
+
return (/**
|
|
145
|
+
* @return {?}
|
|
146
|
+
*/
|
|
147
|
+
function () {
|
|
148
|
+
/** @type {?} */
|
|
149
|
+
var i = reg.listeners.indexOf(fn);
|
|
150
|
+
if (i >= 0)
|
|
151
|
+
reg.listeners.splice(i, 1);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/** @type {?} */
|
|
155
|
+
var appVersion = '1.1.20';
|
|
41
156
|
var CSVBoxButtonComponent = /** @class */ (function () {
|
|
42
|
-
function CSVBoxButtonComponent(sanitizer) {
|
|
157
|
+
function CSVBoxButtonComponent(sanitizer, cdr, zone) {
|
|
158
|
+
var _this = this;
|
|
43
159
|
this.sanitizer = sanitizer;
|
|
160
|
+
this.cdr = cdr;
|
|
161
|
+
this.zone = zone;
|
|
44
162
|
this.isModalShown = false;
|
|
45
163
|
this.licenseKey = null;
|
|
46
164
|
this.uuid = null;
|
|
@@ -53,6 +171,165 @@
|
|
|
53
171
|
this.lazy = false;
|
|
54
172
|
this.iframe = null;
|
|
55
173
|
this.disabled = true;
|
|
174
|
+
// True while a different importer on the page is open: the button stays disabled.
|
|
175
|
+
this.blockedByOther = false;
|
|
176
|
+
this.registryEntry = { getHolder: (/**
|
|
177
|
+
* @return {?}
|
|
178
|
+
*/
|
|
179
|
+
function () { return _this.holder; }) };
|
|
180
|
+
this.fileSender = adapterCore.createFileSender({
|
|
181
|
+
getIframe: (/**
|
|
182
|
+
* @return {?}
|
|
183
|
+
*/
|
|
184
|
+
function () { return _this.iframe; }),
|
|
185
|
+
getToken: (/**
|
|
186
|
+
* @return {?}
|
|
187
|
+
*/
|
|
188
|
+
function () { return (/** @type {?} */ (_this.uuid)); }),
|
|
189
|
+
getTargetOrigin: (/**
|
|
190
|
+
* @return {?}
|
|
191
|
+
*/
|
|
192
|
+
function () { return (/** @type {?} */ (_this.targetOrigin)); }),
|
|
193
|
+
getBaseDomain: (/**
|
|
194
|
+
* @return {?}
|
|
195
|
+
*/
|
|
196
|
+
function () { return _this.baseDomain; }),
|
|
197
|
+
takeFile: (/**
|
|
198
|
+
* @return {?}
|
|
199
|
+
*/
|
|
200
|
+
function () {
|
|
201
|
+
/** @type {?} */
|
|
202
|
+
var file = _this.pendingFile;
|
|
203
|
+
_this.pendingFile = null;
|
|
204
|
+
return file;
|
|
205
|
+
}),
|
|
206
|
+
onSent: (/**
|
|
207
|
+
* @return {?}
|
|
208
|
+
*/
|
|
209
|
+
function () { return _this.startFileAckTimer(); })
|
|
210
|
+
});
|
|
211
|
+
this.unsubscribeOpenImporters = null;
|
|
212
|
+
this.pendingFile = null;
|
|
213
|
+
// Data-location sheets redirect to another host, so the iframe origin can differ from
|
|
214
|
+
// targetOrigin. baseDomain is used to check the real origin before trusting it.
|
|
215
|
+
this.baseDomain = "app.csvbox.io";
|
|
216
|
+
this.fileAckTimer = null;
|
|
217
|
+
this.messageListener = (/**
|
|
218
|
+
* @param {?} event
|
|
219
|
+
* @return {?}
|
|
220
|
+
*/
|
|
221
|
+
function (event) {
|
|
222
|
+
// Older importers send these as bare strings, without a token.
|
|
223
|
+
/** @type {?} */
|
|
224
|
+
var legacy = adapterCore.classifyLegacyMessage(event.data);
|
|
225
|
+
if (legacy) {
|
|
226
|
+
// Legacy messages carry no token, so the only way to tell which importer sent one is its
|
|
227
|
+
// window. Ignore those that came from another instance's iframe (or anywhere else).
|
|
228
|
+
if (!_this.iframe || event.source !== _this.iframe.contentWindow) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (legacy.type === "mainModalHidden") {
|
|
232
|
+
_this.handleModalClosed();
|
|
233
|
+
}
|
|
234
|
+
else if (legacy.type === "uploadSuccessful") {
|
|
235
|
+
if (_this.onImport)
|
|
236
|
+
_this.onImport(true);
|
|
237
|
+
if (_this.isImported)
|
|
238
|
+
_this.isImported(true);
|
|
239
|
+
if (_this.imported)
|
|
240
|
+
_this.imported(true);
|
|
241
|
+
}
|
|
242
|
+
else if (legacy.type === "uploadFailed") {
|
|
243
|
+
if (_this.onImport)
|
|
244
|
+
_this.onImport(false);
|
|
245
|
+
if (_this.isImported)
|
|
246
|
+
_this.isImported(false);
|
|
247
|
+
if (_this.imported)
|
|
248
|
+
_this.imported(false);
|
|
249
|
+
}
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
// Set-file handshake messages. The shared core does not classify these, so they are
|
|
253
|
+
// read here, behind the same unique_token check the core applies.
|
|
254
|
+
/** @type {?} */
|
|
255
|
+
var raw = event.data;
|
|
256
|
+
if (raw && typeof raw === "object" && raw.data && raw.data.unique_token == _this.uuid) {
|
|
257
|
+
_this.fileSender.learnOrigin(event);
|
|
258
|
+
if (raw.type === "csvbox-set-file-rejected" && raw.data.reason === "not-a-file") {
|
|
259
|
+
// Reply to our probe (it has no file). It only tells us the origin, so do nothing.
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (raw.type === "csvbox-modal-shown") {
|
|
263
|
+
_this.clearFileAckTimer();
|
|
264
|
+
registerOpenImporter(_this.registryEntry);
|
|
265
|
+
// What the file path in openModal() is waiting for. display as well as
|
|
266
|
+
// pointer-events: a second file declined while the first was still opening the
|
|
267
|
+
// modal has put the holder away in the meantime.
|
|
268
|
+
_this.isModalShown = true;
|
|
269
|
+
if (_this.holder) {
|
|
270
|
+
_this.holder.style.display = 'block';
|
|
271
|
+
_this.holder.style.pointerEvents = 'auto';
|
|
272
|
+
}
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (raw.type === "csvbox-set-file-rejected") {
|
|
276
|
+
_this.clearFileAckTimer();
|
|
277
|
+
// The importer has the file and will not take it. Put the holder away only if the
|
|
278
|
+
// modal was never confirmed up: a file declined while it is open leaves that modal
|
|
279
|
+
// where it is, and its own 'csvbox-modal-hidden' will put the holder away.
|
|
280
|
+
if (!_this.isModalShown && _this.holder) {
|
|
281
|
+
_this.holder.style.display = 'none';
|
|
282
|
+
_this.holder.style.pointerEvents = 'auto';
|
|
283
|
+
unregisterOpenImporter(_this.registryEntry);
|
|
284
|
+
}
|
|
285
|
+
console.warn("[csvbox] importer declined the supplied file: " + raw.data.reason);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/** @type {?} */
|
|
290
|
+
var message = adapterCore.classifyStructuredMessage(event.data, (/** @type {?} */ (_this.uuid)));
|
|
291
|
+
if (!message) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
if (message.type === "data-on-submit") {
|
|
295
|
+
if (_this.onSubmit)
|
|
296
|
+
_this.onSubmit(message.metadata);
|
|
297
|
+
if (_this.isSubmitted)
|
|
298
|
+
_this.isSubmitted(message.metadata);
|
|
299
|
+
if (_this.submitted)
|
|
300
|
+
_this.submitted(message.metadata);
|
|
301
|
+
}
|
|
302
|
+
else if (message.type === "data-push-status") {
|
|
303
|
+
if (!message.success) {
|
|
304
|
+
delete message.metadata["unique_token"];
|
|
305
|
+
}
|
|
306
|
+
if (_this.onImport)
|
|
307
|
+
_this.onImport(message.success, message.metadata);
|
|
308
|
+
if (_this.isImported)
|
|
309
|
+
_this.isImported(message.success, message.metadata);
|
|
310
|
+
if (_this.imported)
|
|
311
|
+
_this.imported(message.success, message.metadata);
|
|
312
|
+
}
|
|
313
|
+
else if (message.type === "csvbox-modal-hidden") {
|
|
314
|
+
_this.handleModalClosed();
|
|
315
|
+
}
|
|
316
|
+
else if (message.type === "csvbox-upload-successful") {
|
|
317
|
+
if (_this.onImport)
|
|
318
|
+
_this.onImport(true);
|
|
319
|
+
if (_this.isImported)
|
|
320
|
+
_this.isImported(true);
|
|
321
|
+
if (_this.imported)
|
|
322
|
+
_this.imported(true);
|
|
323
|
+
}
|
|
324
|
+
else if (message.type === "csvbox-upload-failed") {
|
|
325
|
+
if (_this.onImport)
|
|
326
|
+
_this.onImport(false);
|
|
327
|
+
if (_this.isImported)
|
|
328
|
+
_this.isImported(false);
|
|
329
|
+
if (_this.imported)
|
|
330
|
+
_this.imported(false);
|
|
331
|
+
}
|
|
332
|
+
});
|
|
56
333
|
}
|
|
57
334
|
/**
|
|
58
335
|
* @return {?}
|
|
@@ -71,6 +348,9 @@
|
|
|
71
348
|
theme: this.theme,
|
|
72
349
|
environment: this.environment
|
|
73
350
|
}, "angular", appVersion);
|
|
351
|
+
// Default place to send the file. A file is only ever sent to a named origin, never "*".
|
|
352
|
+
this.targetOrigin = new URL(iframeUrl).origin;
|
|
353
|
+
this.baseDomain = this.customDomain || "app.csvbox.io";
|
|
74
354
|
this.safeUrl = this.sanitizer.sanitize(core.SecurityContext.RESOURCE_URL, this.sanitizer.bypassSecurityTrustResourceUrl(iframeUrl));
|
|
75
355
|
};
|
|
76
356
|
/**
|
|
@@ -110,55 +390,12 @@
|
|
|
110
390
|
*/
|
|
111
391
|
function () {
|
|
112
392
|
var _this = this;
|
|
113
|
-
window.addEventListener("message",
|
|
114
|
-
|
|
393
|
+
window.addEventListener("message", this.messageListener, false);
|
|
394
|
+
this.syncBlocked();
|
|
395
|
+
this.unsubscribeOpenImporters = subscribeOpenImporters((/**
|
|
115
396
|
* @return {?}
|
|
116
397
|
*/
|
|
117
|
-
function (
|
|
118
|
-
/** @type {?} */
|
|
119
|
-
var message = adapterCore.classifyStructuredMessage(event.data, (/** @type {?} */ (_this.uuid)));
|
|
120
|
-
if (!message) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (message.type === "data-on-submit") {
|
|
124
|
-
if (_this.onSubmit)
|
|
125
|
-
_this.onSubmit(message.metadata);
|
|
126
|
-
if (_this.isSubmitted)
|
|
127
|
-
_this.isSubmitted(message.metadata);
|
|
128
|
-
if (_this.submitted)
|
|
129
|
-
_this.submitted(message.metadata);
|
|
130
|
-
}
|
|
131
|
-
else if (message.type === "data-push-status") {
|
|
132
|
-
if (!message.success) {
|
|
133
|
-
delete message.metadata["unique_token"];
|
|
134
|
-
}
|
|
135
|
-
if (_this.onImport)
|
|
136
|
-
_this.onImport(message.success, message.metadata);
|
|
137
|
-
if (_this.isImported)
|
|
138
|
-
_this.isImported(message.success, message.metadata);
|
|
139
|
-
if (_this.imported)
|
|
140
|
-
_this.imported(message.success, message.metadata);
|
|
141
|
-
}
|
|
142
|
-
else if (message.type === "csvbox-modal-hidden") {
|
|
143
|
-
_this.handleModalClosed();
|
|
144
|
-
}
|
|
145
|
-
else if (message.type === "csvbox-upload-successful") {
|
|
146
|
-
if (_this.onImport)
|
|
147
|
-
_this.onImport(true);
|
|
148
|
-
if (_this.isImported)
|
|
149
|
-
_this.isImported(true);
|
|
150
|
-
if (_this.imported)
|
|
151
|
-
_this.imported(true);
|
|
152
|
-
}
|
|
153
|
-
else if (message.type === "csvbox-upload-failed") {
|
|
154
|
-
if (_this.onImport)
|
|
155
|
-
_this.onImport(false);
|
|
156
|
-
if (_this.isImported)
|
|
157
|
-
_this.isImported(false);
|
|
158
|
-
if (_this.imported)
|
|
159
|
-
_this.imported(false);
|
|
160
|
-
}
|
|
161
|
-
}), false);
|
|
398
|
+
function () { return _this.syncBlocked(); }));
|
|
162
399
|
if (this.lazy) {
|
|
163
400
|
this.disabled = false;
|
|
164
401
|
}
|
|
@@ -174,8 +411,10 @@
|
|
|
174
411
|
* @return {?}
|
|
175
412
|
*/
|
|
176
413
|
function () {
|
|
177
|
-
if (this.holder)
|
|
414
|
+
if (this.holder) {
|
|
178
415
|
this.holder.style.display = 'none';
|
|
416
|
+
this.holder.style.pointerEvents = 'auto';
|
|
417
|
+
}
|
|
179
418
|
this.isModalShown = false;
|
|
180
419
|
this.isIframeLoaded = false;
|
|
181
420
|
this.openModalOnIframeLoad = false;
|
|
@@ -183,6 +422,9 @@
|
|
|
183
422
|
this.holder.remove();
|
|
184
423
|
this.holder = null;
|
|
185
424
|
this.iframe = null;
|
|
425
|
+
// A new iframe is built on the next open, so the origin is learned again.
|
|
426
|
+
this.clearProbeTimer();
|
|
427
|
+
unregisterOpenImporter(this.registryEntry);
|
|
186
428
|
if (this.onClose)
|
|
187
429
|
this.onClose();
|
|
188
430
|
if (this.isClosed)
|
|
@@ -205,6 +447,7 @@
|
|
|
205
447
|
var iframe = document.createElement("iframe");
|
|
206
448
|
this.iframe = iframe;
|
|
207
449
|
iframe.setAttribute("src", this.safeUrl);
|
|
450
|
+
iframe.setAttribute("allow", "clipboard-read; clipboard-write *");
|
|
208
451
|
iframe.frameBorder = "0";
|
|
209
452
|
/** @type {?} */
|
|
210
453
|
var self = this;
|
|
@@ -232,6 +475,8 @@
|
|
|
232
475
|
this.holder.setAttribute('id', "csvbox-embed-" + this.uuid);
|
|
233
476
|
this.holder.appendChild(iframe);
|
|
234
477
|
document.body.insertAdjacentElement('beforeend', this.holder);
|
|
478
|
+
// The holder did not exist yet if openModal() asked for the importer before it was built.
|
|
479
|
+
restackOpenImporters(openImporters());
|
|
235
480
|
};
|
|
236
481
|
/**
|
|
237
482
|
* @return {?}
|
|
@@ -240,6 +485,9 @@
|
|
|
240
485
|
* @return {?}
|
|
241
486
|
*/
|
|
242
487
|
function () {
|
|
488
|
+
// Counts as open from the moment it is requested, so the other buttons are disabled while
|
|
489
|
+
// this importer is still loading, and so it is stacked above any importer opened earlier.
|
|
490
|
+
registerOpenImporter(this.registryEntry);
|
|
243
491
|
if (!this.iframe) {
|
|
244
492
|
this.openModalOnIframeLoad = true;
|
|
245
493
|
this.initImporter();
|
|
@@ -247,11 +495,36 @@
|
|
|
247
495
|
}
|
|
248
496
|
if (!this.isModalShown) {
|
|
249
497
|
if (this.isIframeLoaded) {
|
|
250
|
-
this.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
498
|
+
if (this.pendingFile) {
|
|
499
|
+
// The importer opens its own modal once it has the file, so that it can inject on
|
|
500
|
+
// 'shown.bs.modal'. Sending 'openModal' as well would race that.
|
|
501
|
+
//
|
|
502
|
+
// It can also decline: wrong step, an import file URL configured on the sheet, or
|
|
503
|
+
// an importer too old to know the message at all. So the holder goes up
|
|
504
|
+
// click-through and stays that way until 'csvbox-modal-shown' confirms the modal
|
|
505
|
+
// is really up. It covers the viewport at z-index 2147483647 and the importer
|
|
506
|
+
// renders transparent with its modal closed, so arming it on an unanswered message
|
|
507
|
+
// leaves an invisible sheet over the host page eating every click.
|
|
508
|
+
//
|
|
509
|
+
// display:block regardless, so the iframe lays out and animates normally; only
|
|
510
|
+
// pointer-events is held back. isModalShown likewise waits for the confirmation,
|
|
511
|
+
// or a declined file would latch the importer shut for good.
|
|
512
|
+
if (this.holder) {
|
|
513
|
+
this.holder.style.pointerEvents = 'none';
|
|
514
|
+
this.holder.style.display = 'block';
|
|
515
|
+
}
|
|
516
|
+
this.fileSender.send();
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
this.isModalShown = true;
|
|
520
|
+
if (this.holder) {
|
|
521
|
+
// Explicit: a previously declined file leaves the holder click-through.
|
|
522
|
+
this.holder.style.pointerEvents = 'auto';
|
|
523
|
+
this.holder.style.display = 'block';
|
|
524
|
+
}
|
|
525
|
+
if (this.iframe && this.iframe.contentWindow) {
|
|
526
|
+
this.iframe.contentWindow.postMessage('openModal', '*');
|
|
527
|
+
}
|
|
255
528
|
}
|
|
256
529
|
}
|
|
257
530
|
else {
|
|
@@ -259,18 +532,176 @@
|
|
|
259
532
|
}
|
|
260
533
|
}
|
|
261
534
|
};
|
|
535
|
+
/**
|
|
536
|
+
* Open the importer on a File the host page already has, instead of the file picker.
|
|
537
|
+
*
|
|
538
|
+
* Reachable through a template reference (`#importer` then `importer.openModalWithFile(file)`)
|
|
539
|
+
* or `@ViewChild(CSVBoxButtonComponent)`.
|
|
540
|
+
*
|
|
541
|
+
* The File crosses to the iframe by structured clone, so the importer receives the real
|
|
542
|
+
* object and applies its own extension, worksheet and size rules to it -- this does not
|
|
543
|
+
* bypass any of them. Pass a File; a Blob has no name for the importer to read an
|
|
544
|
+
* extension from.
|
|
545
|
+
*/
|
|
546
|
+
/**
|
|
547
|
+
* Open the importer on a File the host page already has, instead of the file picker.
|
|
548
|
+
*
|
|
549
|
+
* Reachable through a template reference (`#importer` then `importer.openModalWithFile(file)`)
|
|
550
|
+
* or `\@ViewChild(CSVBoxButtonComponent)`.
|
|
551
|
+
*
|
|
552
|
+
* The File crosses to the iframe by structured clone, so the importer receives the real
|
|
553
|
+
* object and applies its own extension, worksheet and size rules to it -- this does not
|
|
554
|
+
* bypass any of them. Pass a File; a Blob has no name for the importer to read an
|
|
555
|
+
* extension from.
|
|
556
|
+
* @param {?} file
|
|
557
|
+
* @return {?}
|
|
558
|
+
*/
|
|
559
|
+
CSVBoxButtonComponent.prototype.openModalWithFile = /**
|
|
560
|
+
* Open the importer on a File the host page already has, instead of the file picker.
|
|
561
|
+
*
|
|
562
|
+
* Reachable through a template reference (`#importer` then `importer.openModalWithFile(file)`)
|
|
563
|
+
* or `\@ViewChild(CSVBoxButtonComponent)`.
|
|
564
|
+
*
|
|
565
|
+
* The File crosses to the iframe by structured clone, so the importer receives the real
|
|
566
|
+
* object and applies its own extension, worksheet and size rules to it -- this does not
|
|
567
|
+
* bypass any of them. Pass a File; a Blob has no name for the importer to read an
|
|
568
|
+
* extension from.
|
|
569
|
+
* @param {?} file
|
|
570
|
+
* @return {?}
|
|
571
|
+
*/
|
|
572
|
+
function (file) {
|
|
573
|
+
if (typeof File === 'undefined' || !(file instanceof File)) {
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
this.pendingFile = file;
|
|
577
|
+
// Already open: hand it over now rather than holding it for the next open. The importer
|
|
578
|
+
// takes it only while it is still on the upload step, and ignores it once the user has a
|
|
579
|
+
// dataset and a mapping in progress.
|
|
580
|
+
if (this.isModalShown && this.iframe && this.isIframeLoaded) {
|
|
581
|
+
this.fileSender.send();
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
this.openModal();
|
|
585
|
+
};
|
|
586
|
+
/**
|
|
587
|
+
* @return {?}
|
|
588
|
+
*/
|
|
589
|
+
CSVBoxButtonComponent.prototype.clearProbeTimer = /**
|
|
590
|
+
* @return {?}
|
|
591
|
+
*/
|
|
592
|
+
function () {
|
|
593
|
+
this.clearFileAckTimer();
|
|
594
|
+
this.fileSender.reset();
|
|
595
|
+
};
|
|
596
|
+
/**
|
|
597
|
+
* @return {?}
|
|
598
|
+
*/
|
|
599
|
+
CSVBoxButtonComponent.prototype.startFileAckTimer = /**
|
|
600
|
+
* @return {?}
|
|
601
|
+
*/
|
|
602
|
+
function () {
|
|
603
|
+
var _this = this;
|
|
604
|
+
this.clearFileAckTimer();
|
|
605
|
+
this.fileAckTimer = setTimeout((/**
|
|
606
|
+
* @return {?}
|
|
607
|
+
*/
|
|
608
|
+
function () {
|
|
609
|
+
_this.fileAckTimer = null;
|
|
610
|
+
_this.giveUpOnFile();
|
|
611
|
+
}), FILE_ACK_TIMEOUT_MS);
|
|
612
|
+
};
|
|
613
|
+
/**
|
|
614
|
+
* @return {?}
|
|
615
|
+
*/
|
|
616
|
+
CSVBoxButtonComponent.prototype.clearFileAckTimer = /**
|
|
617
|
+
* @return {?}
|
|
618
|
+
*/
|
|
619
|
+
function () {
|
|
620
|
+
if (this.fileAckTimer) {
|
|
621
|
+
clearTimeout(this.fileAckTimer);
|
|
622
|
+
this.fileAckTimer = null;
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
// The importer never confirmed the file it was sent (an origin we do not trust, or an importer too
|
|
626
|
+
// old to know the message). Without this the holder would stay up, invisible and click-through,
|
|
627
|
+
// and the other instances' buttons would stay disabled for good.
|
|
628
|
+
// The importer never confirmed the file it was sent (an origin we do not trust, or an importer too
|
|
629
|
+
// old to know the message). Without this the holder would stay up, invisible and click-through,
|
|
630
|
+
// and the other instances' buttons would stay disabled for good.
|
|
631
|
+
/**
|
|
632
|
+
* @return {?}
|
|
633
|
+
*/
|
|
634
|
+
CSVBoxButtonComponent.prototype.giveUpOnFile =
|
|
635
|
+
// The importer never confirmed the file it was sent (an origin we do not trust, or an importer too
|
|
636
|
+
// old to know the message). Without this the holder would stay up, invisible and click-through,
|
|
637
|
+
// and the other instances' buttons would stay disabled for good.
|
|
638
|
+
/**
|
|
639
|
+
* @return {?}
|
|
640
|
+
*/
|
|
641
|
+
function () {
|
|
642
|
+
if (this.isModalShown) {
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
/** @type {?} */
|
|
646
|
+
var holder = this.holder;
|
|
647
|
+
if (holder) {
|
|
648
|
+
holder.style.display = 'none';
|
|
649
|
+
holder.style.pointerEvents = 'auto';
|
|
650
|
+
}
|
|
651
|
+
unregisterOpenImporter(this.registryEntry);
|
|
652
|
+
console.warn("[csvbox] the importer did not respond to the supplied file");
|
|
653
|
+
};
|
|
654
|
+
/**
|
|
655
|
+
* @private
|
|
656
|
+
* @return {?}
|
|
657
|
+
*/
|
|
658
|
+
CSVBoxButtonComponent.prototype.syncBlocked = /**
|
|
659
|
+
* @private
|
|
660
|
+
* @return {?}
|
|
661
|
+
*/
|
|
662
|
+
function () {
|
|
663
|
+
var _this = this;
|
|
664
|
+
/** @type {?} */
|
|
665
|
+
var blocked = isBlockedByOpenImporter(this.registryEntry);
|
|
666
|
+
if (blocked !== this.blockedByOther) {
|
|
667
|
+
// The registry can call back from outside Angular's zone (another instance, another app).
|
|
668
|
+
this.zone.run((/**
|
|
669
|
+
* @return {?}
|
|
670
|
+
*/
|
|
671
|
+
function () {
|
|
672
|
+
_this.blockedByOther = blocked;
|
|
673
|
+
_this.cdr.markForCheck();
|
|
674
|
+
}));
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
/**
|
|
678
|
+
* @return {?}
|
|
679
|
+
*/
|
|
680
|
+
CSVBoxButtonComponent.prototype.ngOnDestroy = /**
|
|
681
|
+
* @return {?}
|
|
682
|
+
*/
|
|
683
|
+
function () {
|
|
684
|
+
this.clearProbeTimer();
|
|
685
|
+
window.removeEventListener("message", this.messageListener);
|
|
686
|
+
unregisterOpenImporter(this.registryEntry);
|
|
687
|
+
if (this.unsubscribeOpenImporters) {
|
|
688
|
+
this.unsubscribeOpenImporters();
|
|
689
|
+
this.unsubscribeOpenImporters = null;
|
|
690
|
+
}
|
|
691
|
+
};
|
|
262
692
|
CSVBoxButtonComponent.decorators = [
|
|
263
693
|
{ type: core.Component, args: [{
|
|
264
694
|
selector: 'csvbox-button',
|
|
265
|
-
template: "\n <div>\n <button [disabled]=\"disabled\"
|
|
695
|
+
template: "\n <div>\n <button [disabled]=\"disabled || blockedByOther\" (click)=\"openModal()\" [attr.data-csvbox-token]=\"uuid\">\n <ng-content></ng-content>\n </button>\n </div>\n "
|
|
266
696
|
}] }
|
|
267
697
|
];
|
|
268
698
|
/** @nocollapse */
|
|
269
699
|
CSVBoxButtonComponent.ctorParameters = function () { return [
|
|
270
|
-
{ type: platformBrowser.DomSanitizer }
|
|
700
|
+
{ type: platformBrowser.DomSanitizer },
|
|
701
|
+
{ type: core.ChangeDetectorRef },
|
|
702
|
+
{ type: core.NgZone }
|
|
271
703
|
]; };
|
|
272
704
|
CSVBoxButtonComponent.propDecorators = {
|
|
273
|
-
initiator: [{ type: core.ViewChild, args: ['initiator', { static: false },] }],
|
|
274
705
|
onImport: [{ type: core.Input }],
|
|
275
706
|
onReady: [{ type: core.Input }],
|
|
276
707
|
onClose: [{ type: core.Input }],
|
|
@@ -305,8 +736,6 @@
|
|
|
305
736
|
/** @type {?} */
|
|
306
737
|
CSVBoxButtonComponent.prototype.isModalShown;
|
|
307
738
|
/** @type {?} */
|
|
308
|
-
CSVBoxButtonComponent.prototype.initiator;
|
|
309
|
-
/** @type {?} */
|
|
310
739
|
CSVBoxButtonComponent.prototype.onImport;
|
|
311
740
|
/** @type {?} */
|
|
312
741
|
CSVBoxButtonComponent.prototype.onReady;
|
|
@@ -365,9 +794,52 @@
|
|
|
365
794
|
/** @type {?} */
|
|
366
795
|
CSVBoxButtonComponent.prototype.disabled;
|
|
367
796
|
/** @type {?} */
|
|
797
|
+
CSVBoxButtonComponent.prototype.blockedByOther;
|
|
798
|
+
/**
|
|
799
|
+
* @type {?}
|
|
800
|
+
* @private
|
|
801
|
+
*/
|
|
802
|
+
CSVBoxButtonComponent.prototype.registryEntry;
|
|
803
|
+
/**
|
|
804
|
+
* @type {?}
|
|
805
|
+
* @private
|
|
806
|
+
*/
|
|
807
|
+
CSVBoxButtonComponent.prototype.fileSender;
|
|
808
|
+
/**
|
|
809
|
+
* @type {?}
|
|
810
|
+
* @private
|
|
811
|
+
*/
|
|
812
|
+
CSVBoxButtonComponent.prototype.unsubscribeOpenImporters;
|
|
813
|
+
/** @type {?} */
|
|
368
814
|
CSVBoxButtonComponent.prototype.holder;
|
|
369
815
|
/** @type {?} */
|
|
816
|
+
CSVBoxButtonComponent.prototype.pendingFile;
|
|
817
|
+
/** @type {?} */
|
|
818
|
+
CSVBoxButtonComponent.prototype.targetOrigin;
|
|
819
|
+
/** @type {?} */
|
|
820
|
+
CSVBoxButtonComponent.prototype.baseDomain;
|
|
821
|
+
/**
|
|
822
|
+
* @type {?}
|
|
823
|
+
* @private
|
|
824
|
+
*/
|
|
825
|
+
CSVBoxButtonComponent.prototype.fileAckTimer;
|
|
826
|
+
/**
|
|
827
|
+
* @type {?}
|
|
828
|
+
* @private
|
|
829
|
+
*/
|
|
830
|
+
CSVBoxButtonComponent.prototype.messageListener;
|
|
831
|
+
/** @type {?} */
|
|
370
832
|
CSVBoxButtonComponent.prototype.sanitizer;
|
|
833
|
+
/**
|
|
834
|
+
* @type {?}
|
|
835
|
+
* @private
|
|
836
|
+
*/
|
|
837
|
+
CSVBoxButtonComponent.prototype.cdr;
|
|
838
|
+
/**
|
|
839
|
+
* @type {?}
|
|
840
|
+
* @private
|
|
841
|
+
*/
|
|
842
|
+
CSVBoxButtonComponent.prototype.zone;
|
|
371
843
|
}
|
|
372
844
|
|
|
373
845
|
/**
|