tnx-shared 5.1.654 → 5.1.655
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/tnx-shared.umd.js +146 -121
- package/bundles/tnx-shared.umd.js.map +1 -1
- package/bundles/tnx-shared.umd.min.js +1 -1
- package/bundles/tnx-shared.umd.min.js.map +1 -1
- package/components/tn-tinymce/tn-tinymce.component.d.ts.map +1 -1
- package/esm2015/components/tn-tinymce/tn-tinymce.component.js +121 -88
- package/fesm2015/tnx-shared.js +121 -88
- package/fesm2015/tnx-shared.js.map +1 -1
- package/package.json +2 -2
|
@@ -62525,157 +62525,182 @@
|
|
|
62525
62525
|
this.editor.focus();
|
|
62526
62526
|
}
|
|
62527
62527
|
};
|
|
62528
|
+
// async handlePaste(types, pastedData, pastedRtfData, files) {
|
|
62529
|
+
// return new Promise(async (resolve) => {
|
|
62530
|
+
// const images = [];
|
|
62531
|
+
// if (types.indexOf('text/html') !== -1) {
|
|
62532
|
+
// if (pastedData.indexOf('<v:imagedata ') == -1) {
|
|
62533
|
+
// resolve(pastedData);
|
|
62534
|
+
// }
|
|
62535
|
+
// else {
|
|
62536
|
+
// if (types.indexOf('text/rtf') !== -1) {
|
|
62537
|
+
// let index = pastedData.indexOf('<v:imagedata ');
|
|
62538
|
+
// let i = 0;
|
|
62539
|
+
// const imageUploaded = [];
|
|
62540
|
+
// let docm = new DOMParser().parseFromString(pastedData, 'text/html');
|
|
62541
|
+
// let img = docm.getElementsByTagName('img');
|
|
62542
|
+
// while (index > -1) {
|
|
62543
|
+
// const p1 = pastedData.substring(0, index);
|
|
62544
|
+
// const index2 = pastedData.indexOf('/>', index);
|
|
62545
|
+
// if (index == -1) break;
|
|
62546
|
+
// else {
|
|
62547
|
+
// const p2 = pastedData.substring(index2 + 2);
|
|
62548
|
+
// if (images.length > i) {
|
|
62549
|
+
// const indexImg = images[i].indexOf('<img src=');
|
|
62550
|
+
// if (indexImg !== -1) {
|
|
62551
|
+
// images[i] = images[i].substring(indexImg + 10, images[i].length - 2);
|
|
62552
|
+
// }
|
|
62553
|
+
// const imageType = images[i].substring(5, images[i].indexOf(';'));
|
|
62554
|
+
// const base64 = images[i].substring(images[i].indexOf('base64,') + 7);
|
|
62555
|
+
// const imageBlob = this.dataURItoBlob(base64, imageType);
|
|
62556
|
+
// const srcArr = img[i].src.split('/');
|
|
62557
|
+
// const fileName = srcArr[srcArr.length - 1];
|
|
62558
|
+
// const file = new File([imageBlob], fileName, { type: imageType });
|
|
62559
|
+
// const uploadImage = await this._fileObjectService.uploadWithByteArray(file);
|
|
62560
|
+
// if (typeof uploadImage == 'string') {
|
|
62561
|
+
// imageUploaded.push(this._fileObjectService.getUrlImage(uploadImage));
|
|
62562
|
+
// }
|
|
62563
|
+
// else {
|
|
62564
|
+
// this._notifierService.showWarning('Upload file thất bại');
|
|
62565
|
+
// }
|
|
62566
|
+
// }
|
|
62567
|
+
// pastedData = p1 + '<img src=' + imageUploaded[i] + '/>' + p2;
|
|
62568
|
+
// index = pastedData.indexOf('<v:imagedata ');
|
|
62569
|
+
// i++;
|
|
62570
|
+
// }
|
|
62571
|
+
// }
|
|
62572
|
+
// docm = new DOMParser().parseFromString(pastedData, 'text/html');
|
|
62573
|
+
// img = docm.getElementsByTagName('img');
|
|
62574
|
+
// for (let i = 0; i < images.length; i++) {
|
|
62575
|
+
// if (imageUploaded[i]) {
|
|
62576
|
+
// img[i].src = imageUploaded[i];
|
|
62577
|
+
// img[i].alt = imageUploaded[i];
|
|
62578
|
+
// }
|
|
62579
|
+
// }
|
|
62580
|
+
// let result = '';
|
|
62581
|
+
// result = new XMLSerializer().serializeToString(docm);
|
|
62582
|
+
// resolve(result);
|
|
62583
|
+
// }
|
|
62584
|
+
// }
|
|
62585
|
+
// }
|
|
62586
|
+
// else if (types.indexOf('Files') !== -1) {
|
|
62587
|
+
// let result = '';
|
|
62588
|
+
// if (files.length > 0) {
|
|
62589
|
+
// for (const item of files) {
|
|
62590
|
+
// const uploadImage = await this._fileObjectService.uploadWithByteArray(item);
|
|
62591
|
+
// if (typeof uploadImage == 'string') {
|
|
62592
|
+
// result += '<img src=' + this._fileObjectService.getUrlImage(uploadImage) + '/>';
|
|
62593
|
+
// }
|
|
62594
|
+
// else {
|
|
62595
|
+
// this._notifierService.showWarning('Upload file thất bại');
|
|
62596
|
+
// }
|
|
62597
|
+
// }
|
|
62598
|
+
// }
|
|
62599
|
+
// resolve(result);
|
|
62600
|
+
// }
|
|
62601
|
+
// else {
|
|
62602
|
+
// resolve(null);
|
|
62603
|
+
// }
|
|
62604
|
+
// });
|
|
62605
|
+
// }
|
|
62528
62606
|
TnTinymceComponent.prototype.handlePaste = function (types, pastedData, pastedRtfData, files) {
|
|
62529
62607
|
return __awaiter(this, void 0, void 0, function () {
|
|
62530
62608
|
var _this = this;
|
|
62531
62609
|
return __generator(this, function (_a) {
|
|
62532
62610
|
return [2 /*return*/, new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
|
|
62533
|
-
var
|
|
62611
|
+
var doc, imgs, result, files_2, files_2_1, item, uploadImage, e_1_1;
|
|
62534
62612
|
var e_1, _a;
|
|
62535
62613
|
var _this = this;
|
|
62536
62614
|
return __generator(this, function (_b) {
|
|
62537
62615
|
switch (_b.label) {
|
|
62538
62616
|
case 0:
|
|
62539
|
-
|
|
62540
|
-
|
|
62541
|
-
|
|
62542
|
-
|
|
62543
|
-
|
|
62544
|
-
|
|
62545
|
-
var dom = create();
|
|
62546
|
-
images.push(dom.outerHTML);
|
|
62547
|
-
return dom;
|
|
62548
|
-
}
|
|
62549
|
-
else if (!isLegacy) {
|
|
62550
|
-
var dom = create();
|
|
62551
|
-
if (dom.tagName == 'IMG') {
|
|
62552
|
-
images.push(dom.outerHTML);
|
|
62553
|
-
return dom;
|
|
62554
|
-
}
|
|
62555
|
-
else {
|
|
62556
|
-
oldLegacyValue = true;
|
|
62557
|
-
}
|
|
62558
|
-
}
|
|
62559
|
-
}
|
|
62560
|
-
};
|
|
62561
|
-
if (!(types.indexOf('text/html') !== -1)) return [3 /*break*/, 1];
|
|
62562
|
-
if (pastedData.indexOf('<v:imagedata ') == -1) {
|
|
62563
|
-
resolve(pastedData);
|
|
62617
|
+
if (!(types.indexOf('text/html') !== -1)) return [3 /*break*/, 3];
|
|
62618
|
+
doc = new DOMParser().parseFromString(pastedData, 'text/html');
|
|
62619
|
+
imgs = [];
|
|
62620
|
+
if (pastedData.indexOf('<v:imagedata ') > -1 && types.indexOf('text/rtf') !== -1) {
|
|
62621
|
+
// Lấy img từ RTF
|
|
62622
|
+
imgs = Array.from(doc.getElementsByTagName('img'));
|
|
62564
62623
|
}
|
|
62565
|
-
else {
|
|
62566
|
-
|
|
62567
|
-
|
|
62568
|
-
doc.render().then(function (htmlElements) { return __awaiter(_this, void 0, void 0, function () {
|
|
62569
|
-
var index, i, imageUploaded, docm, img, p1, index2, p2, indexImg, imageType, base64, imageBlob, srcArr, fileName, file, uploadImage, i_1, result;
|
|
62570
|
-
return __generator(this, function (_a) {
|
|
62571
|
-
switch (_a.label) {
|
|
62572
|
-
case 0:
|
|
62573
|
-
index = pastedData.indexOf('<v:imagedata ');
|
|
62574
|
-
i = 0;
|
|
62575
|
-
imageUploaded = [];
|
|
62576
|
-
docm = new DOMParser().parseFromString(pastedData, 'text/html');
|
|
62577
|
-
img = docm.getElementsByTagName('img');
|
|
62578
|
-
_a.label = 1;
|
|
62579
|
-
case 1:
|
|
62580
|
-
if (!(index > -1)) return [3 /*break*/, 6];
|
|
62581
|
-
p1 = pastedData.substring(0, index);
|
|
62582
|
-
index2 = pastedData.indexOf('/>', index);
|
|
62583
|
-
if (!(index == -1)) return [3 /*break*/, 2];
|
|
62584
|
-
return [3 /*break*/, 6];
|
|
62585
|
-
case 2:
|
|
62586
|
-
p2 = pastedData.substring(index2 + 2);
|
|
62587
|
-
if (!(images.length > i)) return [3 /*break*/, 4];
|
|
62588
|
-
indexImg = images[i].indexOf('<img src=');
|
|
62589
|
-
if (indexImg !== -1) {
|
|
62590
|
-
images[i] = images[i].substring(indexImg + 10, images[i].length - 2);
|
|
62591
|
-
}
|
|
62592
|
-
imageType = images[i].substring(5, images[i].indexOf(';'));
|
|
62593
|
-
base64 = images[i].substring(images[i].indexOf('base64,') + 7);
|
|
62594
|
-
imageBlob = this.dataURItoBlob(base64, imageType);
|
|
62595
|
-
srcArr = img[i].src.split('/');
|
|
62596
|
-
fileName = srcArr[srcArr.length - 1];
|
|
62597
|
-
file = new File([imageBlob], fileName, { type: imageType });
|
|
62598
|
-
return [4 /*yield*/, this._fileObjectService.uploadWithByteArray(file)];
|
|
62599
|
-
case 3:
|
|
62600
|
-
uploadImage = _a.sent();
|
|
62601
|
-
if (typeof uploadImage == 'string') {
|
|
62602
|
-
imageUploaded.push(this._fileObjectService.getUrlImage(uploadImage));
|
|
62603
|
-
}
|
|
62604
|
-
else {
|
|
62605
|
-
this._notifierService.showWarning('Upload file thất bại');
|
|
62606
|
-
}
|
|
62607
|
-
_a.label = 4;
|
|
62608
|
-
case 4:
|
|
62609
|
-
pastedData = p1 + '<img src=' + imageUploaded[i] + '/>' + p2;
|
|
62610
|
-
index = pastedData.indexOf('<v:imagedata ');
|
|
62611
|
-
i++;
|
|
62612
|
-
_a.label = 5;
|
|
62613
|
-
case 5: return [3 /*break*/, 1];
|
|
62614
|
-
case 6:
|
|
62615
|
-
docm = new DOMParser().parseFromString(pastedData, 'text/html');
|
|
62616
|
-
img = docm.getElementsByTagName('img');
|
|
62617
|
-
for (i_1 = 0; i_1 < images.length; i_1++) {
|
|
62618
|
-
if (imageUploaded[i_1]) {
|
|
62619
|
-
img[i_1].src = imageUploaded[i_1];
|
|
62620
|
-
img[i_1].alt = imageUploaded[i_1];
|
|
62621
|
-
}
|
|
62622
|
-
}
|
|
62623
|
-
result = '';
|
|
62624
|
-
result = new XMLSerializer().serializeToString(docm);
|
|
62625
|
-
resolve(result);
|
|
62626
|
-
return [2 /*return*/];
|
|
62627
|
-
}
|
|
62628
|
-
});
|
|
62629
|
-
}); }).catch(function (err) {
|
|
62630
|
-
console.error(err);
|
|
62631
|
-
resolve(null);
|
|
62632
|
-
});
|
|
62633
|
-
}
|
|
62624
|
+
else if (pastedData.indexOf('<img ') > -1) {
|
|
62625
|
+
// Lấy img từ HTML thường
|
|
62626
|
+
imgs = Array.from(doc.getElementsByTagName('img'));
|
|
62634
62627
|
}
|
|
62635
|
-
return [3 /*break*/,
|
|
62628
|
+
if (!(imgs.length > 0)) return [3 /*break*/, 2];
|
|
62629
|
+
return [4 /*yield*/, Promise.all(imgs.map(function (img, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
62630
|
+
var _a, header, base64, imageType, imageBlob, fileName, file, uploadImage, url, err_1;
|
|
62631
|
+
return __generator(this, function (_b) {
|
|
62632
|
+
switch (_b.label) {
|
|
62633
|
+
case 0:
|
|
62634
|
+
if (!img.src.startsWith('data:image/')) return [3 /*break*/, 4];
|
|
62635
|
+
_b.label = 1;
|
|
62636
|
+
case 1:
|
|
62637
|
+
_b.trys.push([1, 3, , 4]);
|
|
62638
|
+
_a = __read(img.src.split(','), 2), header = _a[0], base64 = _a[1];
|
|
62639
|
+
imageType = header.substring(5, header.indexOf(';'));
|
|
62640
|
+
imageBlob = this.dataURItoBlob(base64, imageType);
|
|
62641
|
+
fileName = "paste-" + Date.now() + "-" + i + "." + imageType.split('/')[1];
|
|
62642
|
+
file = new File([imageBlob], fileName, { type: imageType });
|
|
62643
|
+
return [4 /*yield*/, this._fileObjectService.uploadWithByteArray(file)];
|
|
62644
|
+
case 2:
|
|
62645
|
+
uploadImage = _b.sent();
|
|
62646
|
+
if (typeof uploadImage === 'string') {
|
|
62647
|
+
url = this._fileObjectService.getUrlImage(uploadImage);
|
|
62648
|
+
img.src = url;
|
|
62649
|
+
img.alt = url;
|
|
62650
|
+
}
|
|
62651
|
+
else {
|
|
62652
|
+
this._notifierService.showWarning('Upload file thất bại');
|
|
62653
|
+
}
|
|
62654
|
+
return [3 /*break*/, 4];
|
|
62655
|
+
case 3:
|
|
62656
|
+
err_1 = _b.sent();
|
|
62657
|
+
console.error('Error processing image', err_1);
|
|
62658
|
+
return [3 /*break*/, 4];
|
|
62659
|
+
case 4: return [2 /*return*/];
|
|
62660
|
+
}
|
|
62661
|
+
});
|
|
62662
|
+
}); }))];
|
|
62636
62663
|
case 1:
|
|
62637
|
-
|
|
62638
|
-
result = '';
|
|
62639
|
-
if (!(files.length > 0)) return [3 /*break*/, 9];
|
|
62664
|
+
_b.sent();
|
|
62640
62665
|
_b.label = 2;
|
|
62641
|
-
case 2:
|
|
62642
|
-
_b.trys.push([2, 7, 8, 9]);
|
|
62643
|
-
files_2 = __values(files), files_2_1 = files_2.next();
|
|
62644
|
-
_b.label = 3;
|
|
62666
|
+
case 2: return [2 /*return*/, resolve(new XMLSerializer().serializeToString(doc))];
|
|
62645
62667
|
case 3:
|
|
62646
|
-
if (
|
|
62668
|
+
if (!(types.indexOf('Files') !== -1)) return [3 /*break*/, 12];
|
|
62669
|
+
result = '';
|
|
62670
|
+
_b.label = 4;
|
|
62671
|
+
case 4:
|
|
62672
|
+
_b.trys.push([4, 9, 10, 11]);
|
|
62673
|
+
files_2 = __values(files), files_2_1 = files_2.next();
|
|
62674
|
+
_b.label = 5;
|
|
62675
|
+
case 5:
|
|
62676
|
+
if (!!files_2_1.done) return [3 /*break*/, 8];
|
|
62647
62677
|
item = files_2_1.value;
|
|
62648
62678
|
return [4 /*yield*/, this._fileObjectService.uploadWithByteArray(item)];
|
|
62649
|
-
case
|
|
62679
|
+
case 6:
|
|
62650
62680
|
uploadImage = _b.sent();
|
|
62651
|
-
if (typeof uploadImage
|
|
62652
|
-
result +=
|
|
62681
|
+
if (typeof uploadImage === 'string') {
|
|
62682
|
+
result += "<img src=\"" + this._fileObjectService.getUrlImage(uploadImage) + "\"/>";
|
|
62653
62683
|
}
|
|
62654
62684
|
else {
|
|
62655
62685
|
this._notifierService.showWarning('Upload file thất bại');
|
|
62656
62686
|
}
|
|
62657
|
-
_b.label =
|
|
62658
|
-
case 5:
|
|
62659
|
-
files_2_1 = files_2.next();
|
|
62660
|
-
return [3 /*break*/, 3];
|
|
62661
|
-
case 6: return [3 /*break*/, 9];
|
|
62687
|
+
_b.label = 7;
|
|
62662
62688
|
case 7:
|
|
62689
|
+
files_2_1 = files_2.next();
|
|
62690
|
+
return [3 /*break*/, 5];
|
|
62691
|
+
case 8: return [3 /*break*/, 11];
|
|
62692
|
+
case 9:
|
|
62663
62693
|
e_1_1 = _b.sent();
|
|
62664
62694
|
e_1 = { error: e_1_1 };
|
|
62665
|
-
return [3 /*break*/,
|
|
62666
|
-
case
|
|
62695
|
+
return [3 /*break*/, 11];
|
|
62696
|
+
case 10:
|
|
62667
62697
|
try {
|
|
62668
62698
|
if (files_2_1 && !files_2_1.done && (_a = files_2.return)) _a.call(files_2);
|
|
62669
62699
|
}
|
|
62670
62700
|
finally { if (e_1) throw e_1.error; }
|
|
62671
62701
|
return [7 /*endfinally*/];
|
|
62672
|
-
case
|
|
62673
|
-
|
|
62674
|
-
return [3 /*break*/, 11];
|
|
62675
|
-
case 10:
|
|
62676
|
-
resolve(null);
|
|
62677
|
-
_b.label = 11;
|
|
62678
|
-
case 11: return [2 /*return*/];
|
|
62702
|
+
case 11: return [2 /*return*/, resolve(result)];
|
|
62703
|
+
case 12: return [2 /*return*/, resolve(pastedData)];
|
|
62679
62704
|
}
|
|
62680
62705
|
});
|
|
62681
62706
|
}); })];
|