@ctzhian/tiptap 2.12.4 → 2.12.5

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.
@@ -33,10 +33,10 @@ export var AttachmentContent = function AttachmentContent(_ref) {
33
33
  isHovered = _useState2[0],
34
34
  setIsHovered = _useState2[1];
35
35
 
36
- // 处理文件下载
37
- var handleDownload = /*#__PURE__*/function () {
36
+ // 处理 PDF 预览(绕过 nginx 的 Content-Disposition 限制)
37
+ var handlePreview = /*#__PURE__*/function () {
38
38
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(e) {
39
- var response, blob, url, a;
39
+ var response, blob, url;
40
40
  return _regeneratorRuntime().wrap(function _callee$(_context) {
41
41
  while (1) switch (_context.prev = _context.next) {
42
42
  case 0:
@@ -51,6 +51,50 @@ export var AttachmentContent = function AttachmentContent(_ref) {
51
51
  return response.blob();
52
52
  case 8:
53
53
  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;
54
98
  url = window.URL.createObjectURL(blob);
55
99
  a = document.createElement('a');
56
100
  a.href = url;
@@ -59,22 +103,22 @@ export var AttachmentContent = function AttachmentContent(_ref) {
59
103
  a.click();
60
104
  window.URL.revokeObjectURL(url);
61
105
  document.body.removeChild(a);
62
- _context.next = 23;
106
+ _context2.next = 23;
63
107
  break;
64
108
  case 19:
65
- _context.prev = 19;
66
- _context.t0 = _context["catch"](2);
67
- console.error('下载失败:', _context.t0);
109
+ _context2.prev = 19;
110
+ _context2.t0 = _context2["catch"](2);
111
+ console.error('下载失败:', _context2.t0);
68
112
  // 如果 fetch 失败,回退到直接打开链接
69
113
  window.open(attrs.url, '_blank');
70
114
  case 23:
71
115
  case "end":
72
- return _context.stop();
116
+ return _context2.stop();
73
117
  }
74
- }, _callee, null, [[2, 19]]);
118
+ }, _callee2, null, [[2, 19]]);
75
119
  }));
76
- return function handleDownload(_x) {
77
- return _ref2.apply(this, arguments);
120
+ return function handleDownload(_x2) {
121
+ return _ref3.apply(this, arguments);
78
122
  };
79
123
  }();
80
124
  var blockStyles = editable ? {
@@ -204,13 +248,7 @@ export var AttachmentContent = function AttachmentContent(_ref) {
204
248
  gap: 0.5
205
249
  }, isPdf && /*#__PURE__*/React.createElement(IconButton, {
206
250
  size: "small",
207
- component: "a",
208
- href: attrs.url,
209
- target: "_blank",
210
- rel: "noopener noreferrer",
211
- onClick: function onClick(e) {
212
- return e.stopPropagation();
213
- },
251
+ onClick: handlePreview,
214
252
  sx: {
215
253
  color: attrs.url === 'error' ? 'error.main' : 'text.disabled',
216
254
  alignSelf: 'center'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctzhian/tiptap",
3
- "version": "2.12.4",
3
+ "version": "2.12.5",
4
4
  "description": "基于 Tiptap 二次开发的编辑器组件",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",