@sumaris-net/ngx-components 1.20.6 → 1.20.7
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/bundles/sumaris-net.ngx-components.umd.js +32 -24
- package/bundles/sumaris-net.ngx-components.umd.js.map +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js.map +1 -1
- package/doc/changelog.md +3 -0
- package/esm2015/src/app/shared/file/csv.utils.js +5 -25
- package/esm2015/src/app/shared/file/file.utils.js +30 -1
- package/fesm2015/sumaris-net.ngx-components.js +32 -24
- package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
- package/package.json +1 -1
- package/src/app/shared/file/csv.utils.d.ts +1 -0
- package/src/app/shared/file/file.utils.d.ts +5 -0
- package/sumaris-net.ngx-components.metadata.json +1 -1
|
@@ -18353,6 +18353,34 @@
|
|
|
18353
18353
|
reader.readAsText(file, encoding);
|
|
18354
18354
|
return $progress.asObservable();
|
|
18355
18355
|
};
|
|
18356
|
+
FilesUtils.writeTextToFile = function (content, opts) {
|
|
18357
|
+
if (isNilOrBlank(content))
|
|
18358
|
+
return; // Skip if empty
|
|
18359
|
+
var filename = (opts === null || opts === void 0 ? void 0 : opts.filename) || 'export.txt';
|
|
18360
|
+
var charset = ((opts === null || opts === void 0 ? void 0 : opts.encoding) || 'utf-8').toLowerCase();
|
|
18361
|
+
var type = (opts === null || opts === void 0 ? void 0 : opts.type) || 'text/plain';
|
|
18362
|
+
var blob = new Blob((charset === 'utf-8')
|
|
18363
|
+
// Add UTF-8 BOM character
|
|
18364
|
+
? [FilesUtils.UTF8_BOM_CHAR, content]
|
|
18365
|
+
// Non UTF-8 charset
|
|
18366
|
+
: [content], { type: type + ";charset=" + charset + ";" });
|
|
18367
|
+
if (navigator.msSaveBlob) { // IE 10+
|
|
18368
|
+
navigator.msSaveBlob(blob, filename);
|
|
18369
|
+
}
|
|
18370
|
+
else {
|
|
18371
|
+
var link = document.createElement('a');
|
|
18372
|
+
if (link.download !== undefined) {
|
|
18373
|
+
// Browsers that support HTML5 download attribute
|
|
18374
|
+
var url = URL.createObjectURL(blob);
|
|
18375
|
+
link.setAttribute('href', url);
|
|
18376
|
+
link.setAttribute('download', filename);
|
|
18377
|
+
link.style.visibility = 'hidden';
|
|
18378
|
+
document.body.appendChild(link);
|
|
18379
|
+
link.click();
|
|
18380
|
+
document.body.removeChild(link);
|
|
18381
|
+
}
|
|
18382
|
+
}
|
|
18383
|
+
};
|
|
18356
18384
|
return FilesUtils;
|
|
18357
18385
|
}());
|
|
18358
18386
|
FilesUtils.UTF8_BOM_CHAR = new Uint8Array([0xEF, 0xBB, 0xBF]); // UTF-8 BOM
|
|
@@ -20878,13 +20906,12 @@
|
|
|
20878
20906
|
CsvUtils.exportToFile = function (rows, opts) {
|
|
20879
20907
|
if (!rows || !rows.length)
|
|
20880
20908
|
return; // Skip if empty
|
|
20881
|
-
|
|
20882
|
-
var charset = ((opts === null || opts === void 0 ? void 0 : opts.encoding) || 'utf-8').toLowerCase();
|
|
20909
|
+
// Create text content
|
|
20883
20910
|
var separator = (opts === null || opts === void 0 ? void 0 : opts.separator) || ',';
|
|
20884
20911
|
var protectCellRegexp = new RegExp("/(\"|" + separator + "|\n)/g");
|
|
20885
20912
|
var keys = Object.keys(rows[0]);
|
|
20886
20913
|
var headers = (opts === null || opts === void 0 ? void 0 : opts.headers) || keys;
|
|
20887
|
-
var
|
|
20914
|
+
var textContent =
|
|
20888
20915
|
// Header row
|
|
20889
20916
|
headers.join(separator) + '\n' +
|
|
20890
20917
|
// Data rows
|
|
@@ -20900,27 +20927,8 @@
|
|
|
20900
20927
|
return cellStr;
|
|
20901
20928
|
}).join(separator);
|
|
20902
20929
|
}).join('\n');
|
|
20903
|
-
|
|
20904
|
-
|
|
20905
|
-
? [FilesUtils.UTF8_BOM_CHAR, csvContent]
|
|
20906
|
-
// Non UTF-8 charset
|
|
20907
|
-
: [csvContent], { type: "text/csv;charset=" + charset + ";" });
|
|
20908
|
-
if (navigator.msSaveBlob) { // IE 10+
|
|
20909
|
-
navigator.msSaveBlob(blob, filename);
|
|
20910
|
-
}
|
|
20911
|
-
else {
|
|
20912
|
-
var link = document.createElement('a');
|
|
20913
|
-
if (link.download !== undefined) {
|
|
20914
|
-
// Browsers that support HTML5 download attribute
|
|
20915
|
-
var url = URL.createObjectURL(blob);
|
|
20916
|
-
link.setAttribute('href', url);
|
|
20917
|
-
link.setAttribute('download', filename);
|
|
20918
|
-
link.style.visibility = 'hidden';
|
|
20919
|
-
document.body.appendChild(link);
|
|
20920
|
-
link.click();
|
|
20921
|
-
document.body.removeChild(link);
|
|
20922
|
-
}
|
|
20923
|
-
}
|
|
20930
|
+
// Write to file
|
|
20931
|
+
FilesUtils.writeTextToFile(textContent, Object.assign({ type: 'text/csv', filename: 'export.csv' }, opts));
|
|
20924
20932
|
};
|
|
20925
20933
|
CsvUtils.parseFile = function (file, opts) {
|
|
20926
20934
|
return FilesUtils.readAsText(file, opts === null || opts === void 0 ? void 0 : opts.encoding)
|