@ctzhian/tiptap 2.12.5 → 2.12.6
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.
|
@@ -32,11 +32,26 @@ export var AttachmentContent = function AttachmentContent(_ref) {
|
|
|
32
32
|
_useState2 = _slicedToArray(_useState, 2),
|
|
33
33
|
isHovered = _useState2[0],
|
|
34
34
|
setIsHovered = _useState2[1];
|
|
35
|
+
var handlePreview = function handlePreview(e) {
|
|
36
|
+
e.preventDefault();
|
|
37
|
+
e.stopPropagation();
|
|
38
|
+
try {
|
|
39
|
+
var a = document.createElement('a');
|
|
40
|
+
a.href = attrs.url;
|
|
41
|
+
a.target = '_blank';
|
|
42
|
+
document.body.appendChild(a);
|
|
43
|
+
a.click();
|
|
44
|
+
document.body.removeChild(a);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error('预览失败:', error);
|
|
47
|
+
window.open(attrs.url, '_blank');
|
|
48
|
+
}
|
|
49
|
+
};
|
|
35
50
|
|
|
36
|
-
//
|
|
37
|
-
var
|
|
51
|
+
// 处理文件下载
|
|
52
|
+
var handleDownload = /*#__PURE__*/function () {
|
|
38
53
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(e) {
|
|
39
|
-
var response, blob, url;
|
|
54
|
+
var response, blob, url, a;
|
|
40
55
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
41
56
|
while (1) switch (_context.prev = _context.next) {
|
|
42
57
|
case 0:
|
|
@@ -51,50 +66,6 @@ export var AttachmentContent = function AttachmentContent(_ref) {
|
|
|
51
66
|
return response.blob();
|
|
52
67
|
case 8:
|
|
53
68
|
blob = _context.sent;
|
|
54
|
-
url = window.URL.createObjectURL(blob); // 在新标签页中预览 PDF
|
|
55
|
-
window.open(url, '_blank');
|
|
56
|
-
// 注意:不立即清理 URL,因为新标签页需要使用它
|
|
57
|
-
// 可以在一段时间后清理
|
|
58
|
-
setTimeout(function () {
|
|
59
|
-
window.URL.revokeObjectURL(url);
|
|
60
|
-
}, 100);
|
|
61
|
-
_context.next = 18;
|
|
62
|
-
break;
|
|
63
|
-
case 14:
|
|
64
|
-
_context.prev = 14;
|
|
65
|
-
_context.t0 = _context["catch"](2);
|
|
66
|
-
console.error('预览失败:', _context.t0);
|
|
67
|
-
// 降级:直接打开原始链接
|
|
68
|
-
window.open(attrs.url, '_blank');
|
|
69
|
-
case 18:
|
|
70
|
-
case "end":
|
|
71
|
-
return _context.stop();
|
|
72
|
-
}
|
|
73
|
-
}, _callee, null, [[2, 14]]);
|
|
74
|
-
}));
|
|
75
|
-
return function handlePreview(_x) {
|
|
76
|
-
return _ref2.apply(this, arguments);
|
|
77
|
-
};
|
|
78
|
-
}();
|
|
79
|
-
|
|
80
|
-
// 处理文件下载
|
|
81
|
-
var handleDownload = /*#__PURE__*/function () {
|
|
82
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(e) {
|
|
83
|
-
var response, blob, url, a;
|
|
84
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
85
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
86
|
-
case 0:
|
|
87
|
-
e.preventDefault();
|
|
88
|
-
e.stopPropagation();
|
|
89
|
-
_context2.prev = 2;
|
|
90
|
-
_context2.next = 5;
|
|
91
|
-
return fetch(attrs.url);
|
|
92
|
-
case 5:
|
|
93
|
-
response = _context2.sent;
|
|
94
|
-
_context2.next = 8;
|
|
95
|
-
return response.blob();
|
|
96
|
-
case 8:
|
|
97
|
-
blob = _context2.sent;
|
|
98
69
|
url = window.URL.createObjectURL(blob);
|
|
99
70
|
a = document.createElement('a');
|
|
100
71
|
a.href = url;
|
|
@@ -103,22 +74,22 @@ export var AttachmentContent = function AttachmentContent(_ref) {
|
|
|
103
74
|
a.click();
|
|
104
75
|
window.URL.revokeObjectURL(url);
|
|
105
76
|
document.body.removeChild(a);
|
|
106
|
-
|
|
77
|
+
_context.next = 23;
|
|
107
78
|
break;
|
|
108
79
|
case 19:
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
console.error('下载失败:',
|
|
80
|
+
_context.prev = 19;
|
|
81
|
+
_context.t0 = _context["catch"](2);
|
|
82
|
+
console.error('下载失败:', _context.t0);
|
|
112
83
|
// 如果 fetch 失败,回退到直接打开链接
|
|
113
84
|
window.open(attrs.url, '_blank');
|
|
114
85
|
case 23:
|
|
115
86
|
case "end":
|
|
116
|
-
return
|
|
87
|
+
return _context.stop();
|
|
117
88
|
}
|
|
118
|
-
},
|
|
89
|
+
}, _callee, null, [[2, 19]]);
|
|
119
90
|
}));
|
|
120
|
-
return function handleDownload(
|
|
121
|
-
return
|
|
91
|
+
return function handleDownload(_x) {
|
|
92
|
+
return _ref2.apply(this, arguments);
|
|
122
93
|
};
|
|
123
94
|
}();
|
|
124
95
|
var blockStyles = editable ? {
|