@ctzhian/tiptap 2.12.7 → 2.12.9
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/dist/extension/node/Image.js +281 -98
- package/package.json +1 -1
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
2
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
3
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
6
4
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
5
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -13,12 +11,102 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
13
11
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
12
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
15
13
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
15
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
16
16
|
import { getFileType, removeBaseUrl, withBaseUrl } from "../../util";
|
|
17
17
|
import Image from "@tiptap/extension-image";
|
|
18
18
|
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
19
19
|
import { ReactNodeViewRenderer } from "@tiptap/react";
|
|
20
20
|
import { generateJSON } from "@tiptap/html";
|
|
21
21
|
import ImageViewWrapper, { getImageDimensionsFromFile } from "../component/Image";
|
|
22
|
+
/** 从 URL 下载图片并转换为 File 对象 */
|
|
23
|
+
function downloadImageAsFile(_x, _x2) {
|
|
24
|
+
return _downloadImageAsFile.apply(this, arguments);
|
|
25
|
+
}
|
|
26
|
+
/** 解码 HTML 实体 */
|
|
27
|
+
function _downloadImageAsFile() {
|
|
28
|
+
_downloadImageAsFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(url, index) {
|
|
29
|
+
var response, blob, fileName, file;
|
|
30
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
31
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
32
|
+
case 0:
|
|
33
|
+
_context5.prev = 0;
|
|
34
|
+
_context5.next = 3;
|
|
35
|
+
return fetch(url, {
|
|
36
|
+
mode: 'cors',
|
|
37
|
+
credentials: 'omit'
|
|
38
|
+
});
|
|
39
|
+
case 3:
|
|
40
|
+
response = _context5.sent;
|
|
41
|
+
if (response.ok) {
|
|
42
|
+
_context5.next = 11;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
_context5.next = 7;
|
|
46
|
+
return fetch(url, {
|
|
47
|
+
mode: 'no-cors'
|
|
48
|
+
});
|
|
49
|
+
case 7:
|
|
50
|
+
response = _context5.sent;
|
|
51
|
+
if (!(response.type === 'opaque')) {
|
|
52
|
+
_context5.next = 11;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
console.error("[\u56FE\u7247\u4E0B\u8F7D] \u56FE\u7247 ".concat(index + 1, " \u88ABCORS\u963B\u6B62\uFF0C\u65E0\u6CD5\u4E0B\u8F7D"));
|
|
56
|
+
return _context5.abrupt("return", null);
|
|
57
|
+
case 11:
|
|
58
|
+
_context5.next = 13;
|
|
59
|
+
return response.blob();
|
|
60
|
+
case 13:
|
|
61
|
+
blob = _context5.sent;
|
|
62
|
+
if (!(blob.size === 0)) {
|
|
63
|
+
_context5.next = 17;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
console.error("[\u56FE\u7247\u4E0B\u8F7D] \u56FE\u7247 ".concat(index + 1, " blob\u4E3A\u7A7A"));
|
|
67
|
+
return _context5.abrupt("return", null);
|
|
68
|
+
case 17:
|
|
69
|
+
fileName = "image-".concat(index + 1, ".").concat(blob.type.split('/')[1] || 'png');
|
|
70
|
+
file = new File([blob], fileName, {
|
|
71
|
+
type: blob.type
|
|
72
|
+
}); // console.log(`[下载] 图片 ${index + 1} 下载成功:`, { name: file.name, type: file.type, size: file.size });
|
|
73
|
+
return _context5.abrupt("return", file);
|
|
74
|
+
case 22:
|
|
75
|
+
_context5.prev = 22;
|
|
76
|
+
_context5.t0 = _context5["catch"](0);
|
|
77
|
+
console.error("[\u56FE\u7247\u4E0B\u8F7D] \u56FE\u7247 ".concat(index + 1, " \u4E0B\u8F7D\u5F02\u5E38:"), _context5.t0);
|
|
78
|
+
return _context5.abrupt("return", null);
|
|
79
|
+
case 26:
|
|
80
|
+
case "end":
|
|
81
|
+
return _context5.stop();
|
|
82
|
+
}
|
|
83
|
+
}, _callee5, null, [[0, 22]]);
|
|
84
|
+
}));
|
|
85
|
+
return _downloadImageAsFile.apply(this, arguments);
|
|
86
|
+
}
|
|
87
|
+
function decodeHTMLEntities(text) {
|
|
88
|
+
var textarea = document.createElement('textarea');
|
|
89
|
+
textarea.innerHTML = text;
|
|
90
|
+
return textarea.value;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 从 HTML 中提取所有 img 标签的 src */
|
|
94
|
+
function extractImageUrls(html) {
|
|
95
|
+
var imgRegex = /<img[^>]+src=["']([^"']+)["'][^>]*>/gi;
|
|
96
|
+
var urls = [];
|
|
97
|
+
var match;
|
|
98
|
+
while ((match = imgRegex.exec(html)) !== null) {
|
|
99
|
+
var src = match[1];
|
|
100
|
+
// 解码HTML实体(如 & -> &)
|
|
101
|
+
src = decodeHTMLEntities(src);
|
|
102
|
+
// 过滤掉 base64 和无效 URL
|
|
103
|
+
if (src && !src.startsWith('data:') && (src.startsWith('http') || src.startsWith('//'))) {
|
|
104
|
+
urls.push(src.startsWith('//') ? "https:".concat(src) : src);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return urls;
|
|
108
|
+
}
|
|
109
|
+
|
|
22
110
|
/** 在 JSON 结构中用 progress 节点替换 image 节点,按顺序匹配 Files */
|
|
23
111
|
function replaceImagesWithProgressNodes(node, imageFiles, fileIndex, tempIds) {
|
|
24
112
|
if (node.type === 'image' && fileIndex.current < imageFiles.length) {
|
|
@@ -122,18 +210,15 @@ var customImage = function customImage(props) {
|
|
|
122
210
|
}).filter(function (file) {
|
|
123
211
|
return file !== null && getFileType(file) === 'image';
|
|
124
212
|
});
|
|
125
|
-
if (imageFiles.length === 0) return false;
|
|
126
213
|
var htmlData = (_event$clipboardData2 = event.clipboardData) === null || _event$clipboardData2 === void 0 ? void 0 : _event$clipboardData2.getData('text/html');
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (htmlLower.includes('<table') || htmlLower.includes('<tr') || htmlLower.includes('<td') || htmlLower.includes('<th')) {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
214
|
+
|
|
215
|
+
// 提前声明变量和函数,避免在异步回调中出现 TDZ 错误
|
|
133
216
|
var _view$state$selection = view.state.selection,
|
|
134
217
|
from = _view$state$selection.from,
|
|
135
218
|
to = _view$state$selection.to;
|
|
136
219
|
var editor = _this2.editor;
|
|
220
|
+
|
|
221
|
+
// 定义辅助函数
|
|
137
222
|
var findNodePosition = function findNodePosition(typeName, tempId) {
|
|
138
223
|
var targetPos = null;
|
|
139
224
|
editor.state.doc.descendants(function (node, position) {
|
|
@@ -187,11 +272,12 @@ var customImage = function customImage(props) {
|
|
|
187
272
|
width: 760
|
|
188
273
|
}).run();
|
|
189
274
|
case 20:
|
|
190
|
-
_context.next =
|
|
275
|
+
_context.next = 30;
|
|
191
276
|
break;
|
|
192
277
|
case 22:
|
|
193
278
|
_context.prev = 22;
|
|
194
279
|
_context.t1 = _context["catch"](0);
|
|
280
|
+
console.error("[\u56FE\u7247\u4E0A\u4F20] ".concat(file.name, " \u4E0A\u4F20\u5931\u8D25:"), _context.t1);
|
|
195
281
|
editor.chain().removeInlineUploadProgress(tempId).focus().run();
|
|
196
282
|
_progressPos = findNodePosition('inlineUploadProgress', tempId);
|
|
197
283
|
_chain = editor.chain().focus();
|
|
@@ -202,107 +288,204 @@ var customImage = function customImage(props) {
|
|
|
202
288
|
src: '',
|
|
203
289
|
width: 760
|
|
204
290
|
}).run();
|
|
205
|
-
case
|
|
291
|
+
case 30:
|
|
206
292
|
case "end":
|
|
207
293
|
return _context.stop();
|
|
208
294
|
}
|
|
209
295
|
}, _callee, null, [[0, 22], [8, 15]]);
|
|
210
296
|
}));
|
|
211
|
-
return function uploadSingleImage(
|
|
297
|
+
return function uploadSingleImage(_x3, _x4) {
|
|
212
298
|
return _ref.apply(this, arguments);
|
|
213
299
|
};
|
|
214
300
|
}();
|
|
215
|
-
|
|
216
|
-
var
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
301
|
+
var processImagePaste = /*#__PURE__*/function () {
|
|
302
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(files, html, fromPos, toPos) {
|
|
303
|
+
var _htmlTrimmed$match;
|
|
304
|
+
var htmlTrimmed, hasRichHtml, _parsed$content, extensions, parsed, tempIds, fileIndex, modifiedDoc, finalDoc, i, useSimpleInsert;
|
|
305
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
306
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
307
|
+
case 0:
|
|
308
|
+
useSimpleInsert = function _useSimpleInsert(files, fromPos, toPos) {
|
|
309
|
+
var baseTime = Date.now();
|
|
310
|
+
var content = files.map(function (file, i) {
|
|
311
|
+
return {
|
|
312
|
+
type: 'paragraph',
|
|
313
|
+
content: [{
|
|
314
|
+
type: 'inlineUploadProgress',
|
|
315
|
+
attrs: {
|
|
316
|
+
fileName: file.name,
|
|
317
|
+
fileType: 'image',
|
|
318
|
+
progress: 0,
|
|
319
|
+
tempId: "upload-".concat(baseTime, "-").concat(i)
|
|
320
|
+
}
|
|
321
|
+
}]
|
|
322
|
+
};
|
|
323
|
+
});
|
|
324
|
+
editor.chain().insertContentAt({
|
|
325
|
+
from: fromPos,
|
|
326
|
+
to: toPos
|
|
327
|
+
}, content).focus().run();
|
|
328
|
+
files.forEach(function (file, i) {
|
|
329
|
+
var tempId = "upload-".concat(baseTime, "-").concat(i);
|
|
330
|
+
uploadSingleImage(file, tempId);
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
if (props.onUpload) {
|
|
334
|
+
_context2.next = 3;
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
return _context2.abrupt("return");
|
|
338
|
+
case 3:
|
|
339
|
+
htmlTrimmed = (html === null || html === void 0 ? void 0 : html.trim()) || '';
|
|
340
|
+
hasRichHtml = htmlTrimmed.length > 0 && (htmlTrimmed.includes('<p') || htmlTrimmed.includes('<div') || htmlTrimmed.includes('<br') || htmlTrimmed.includes('<span') || ((_htmlTrimmed$match = htmlTrimmed.match(/<img/gi)) === null || _htmlTrimmed$match === void 0 ? void 0 : _htmlTrimmed$match.length) !== 1);
|
|
341
|
+
if (!hasRichHtml) {
|
|
342
|
+
_context2.next = 31;
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
_context2.prev = 6;
|
|
346
|
+
extensions = editor.extensionManager.extensions;
|
|
347
|
+
parsed = generateJSON(htmlTrimmed, extensions);
|
|
348
|
+
if (parsed !== null && parsed !== void 0 && (_parsed$content = parsed.content) !== null && _parsed$content !== void 0 && _parsed$content.length) {
|
|
349
|
+
_context2.next = 11;
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
throw new Error('Empty parsed content');
|
|
353
|
+
case 11:
|
|
354
|
+
tempIds = [];
|
|
355
|
+
fileIndex = {
|
|
356
|
+
current: 0
|
|
357
|
+
};
|
|
358
|
+
modifiedDoc = replaceImagesWithProgressNodes(parsed, files, fileIndex, tempIds);
|
|
359
|
+
finalDoc = appendExtraImagesToDoc(modifiedDoc, files, fileIndex.current, tempIds);
|
|
237
360
|
editor.chain().insertContentAt({
|
|
238
|
-
from:
|
|
239
|
-
to:
|
|
240
|
-
},
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
hasRichHtml = htmlTrimmed.length > 0 && (htmlTrimmed.includes('<p') || htmlTrimmed.includes('<div') || htmlTrimmed.includes('<br') || htmlTrimmed.includes('<span') || ((_htmlTrimmed$match = htmlTrimmed.match(/<img/gi)) === null || _htmlTrimmed$match === void 0 ? void 0 : _htmlTrimmed$match.length) !== 1);
|
|
253
|
-
if (!hasRichHtml) {
|
|
254
|
-
_context2.next = 30;
|
|
361
|
+
from: fromPos,
|
|
362
|
+
to: toPos
|
|
363
|
+
}, finalDoc).focus().run();
|
|
364
|
+
i = 0;
|
|
365
|
+
case 17:
|
|
366
|
+
if (!(i < tempIds.length)) {
|
|
367
|
+
_context2.next = 23;
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
_context2.next = 20;
|
|
371
|
+
return uploadSingleImage(files[i], tempIds[i]);
|
|
372
|
+
case 20:
|
|
373
|
+
i++;
|
|
374
|
+
_context2.next = 17;
|
|
255
375
|
break;
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
extensions = editor.extensionManager.extensions;
|
|
259
|
-
parsed = generateJSON(htmlTrimmed, extensions);
|
|
260
|
-
if (parsed !== null && parsed !== void 0 && (_parsed$content = parsed.content) !== null && _parsed$content !== void 0 && _parsed$content.length) {
|
|
261
|
-
_context2.next = 11;
|
|
376
|
+
case 23:
|
|
377
|
+
_context2.next = 29;
|
|
262
378
|
break;
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
modifiedDoc = replaceImagesWithProgressNodes(parsed, imageFiles, fileIndex, tempIds);
|
|
271
|
-
finalDoc = appendExtraImagesToDoc(modifiedDoc, imageFiles, fileIndex.current, tempIds);
|
|
272
|
-
editor.chain().insertContentAt({
|
|
273
|
-
from: from,
|
|
274
|
-
to: to
|
|
275
|
-
}, finalDoc).focus().run();
|
|
276
|
-
i = 0;
|
|
277
|
-
case 17:
|
|
278
|
-
if (!(i < tempIds.length)) {
|
|
279
|
-
_context2.next = 23;
|
|
379
|
+
case 25:
|
|
380
|
+
_context2.prev = 25;
|
|
381
|
+
_context2.t0 = _context2["catch"](6);
|
|
382
|
+
console.error('[图片粘贴] 富文本解析失败,使用简单插入:', _context2.t0);
|
|
383
|
+
useSimpleInsert(files, fromPos, toPos);
|
|
384
|
+
case 29:
|
|
385
|
+
_context2.next = 32;
|
|
280
386
|
break;
|
|
387
|
+
case 31:
|
|
388
|
+
useSimpleInsert(files, fromPos, toPos);
|
|
389
|
+
case 32:
|
|
390
|
+
case "end":
|
|
391
|
+
return _context2.stop();
|
|
392
|
+
}
|
|
393
|
+
}, _callee2, null, [[6, 25]]);
|
|
394
|
+
}));
|
|
395
|
+
return function processImagePaste(_x5, _x6, _x7, _x8) {
|
|
396
|
+
return _ref2.apply(this, arguments);
|
|
397
|
+
};
|
|
398
|
+
}();
|
|
399
|
+
|
|
400
|
+
// 如果没有 File 对象,尝试从 HTML 中提取图片 URL
|
|
401
|
+
var finalImageFiles = imageFiles;
|
|
402
|
+
if (imageFiles.length === 0 && htmlData) {
|
|
403
|
+
var imageUrls = extractImageUrls(htmlData);
|
|
404
|
+
if (imageUrls.length > 0) {
|
|
405
|
+
event.preventDefault(); // 阻止默认粘贴行为
|
|
406
|
+
|
|
407
|
+
// 异步下载所有图片
|
|
408
|
+
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
409
|
+
var downloadedFiles, validFiles, _parsed$content2, extensions, parsed;
|
|
410
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
411
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
412
|
+
case 0:
|
|
413
|
+
_context3.next = 2;
|
|
414
|
+
return Promise.all(imageUrls.map(function (url, i) {
|
|
415
|
+
return downloadImageAsFile(url, i);
|
|
416
|
+
}));
|
|
417
|
+
case 2:
|
|
418
|
+
downloadedFiles = _context3.sent;
|
|
419
|
+
validFiles = downloadedFiles.filter(function (f) {
|
|
420
|
+
return f !== null;
|
|
421
|
+
});
|
|
422
|
+
if (!(validFiles.length === 0)) {
|
|
423
|
+
_context3.next = 19;
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
_context3.prev = 5;
|
|
427
|
+
extensions = editor.extensionManager.extensions;
|
|
428
|
+
parsed = generateJSON(htmlData, extensions);
|
|
429
|
+
if (!(parsed !== null && parsed !== void 0 && (_parsed$content2 = parsed.content) !== null && _parsed$content2 !== void 0 && _parsed$content2.length)) {
|
|
430
|
+
_context3.next = 12;
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
433
|
+
editor.chain().insertContentAt({
|
|
434
|
+
from: from,
|
|
435
|
+
to: to
|
|
436
|
+
}, parsed).focus().run();
|
|
437
|
+
_context3.next = 13;
|
|
438
|
+
break;
|
|
439
|
+
case 12:
|
|
440
|
+
throw new Error('解析失败');
|
|
441
|
+
case 13:
|
|
442
|
+
_context3.next = 18;
|
|
443
|
+
break;
|
|
444
|
+
case 15:
|
|
445
|
+
_context3.prev = 15;
|
|
446
|
+
_context3.t0 = _context3["catch"](5);
|
|
447
|
+
return _context3.abrupt("return");
|
|
448
|
+
case 18:
|
|
449
|
+
return _context3.abrupt("return");
|
|
450
|
+
case 19:
|
|
451
|
+
_context3.next = 21;
|
|
452
|
+
return processImagePaste(validFiles, htmlData, from, to);
|
|
453
|
+
case 21:
|
|
454
|
+
case "end":
|
|
455
|
+
return _context3.stop();
|
|
281
456
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
457
|
+
}, _callee3, null, [[5, 15]]);
|
|
458
|
+
}))();
|
|
459
|
+
return true; // 已处理
|
|
460
|
+
} else {
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (imageFiles.length === 0) {
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
if (htmlData && htmlData.trim().length > 0) {
|
|
468
|
+
var htmlLower = htmlData.toLowerCase();
|
|
469
|
+
if (htmlLower.includes('<table') || htmlLower.includes('<tr') || htmlLower.includes('<td') || htmlLower.includes('<th')) {
|
|
470
|
+
return false;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// 如果有 File 对象,直接处理
|
|
475
|
+
if (finalImageFiles.length > 0) {
|
|
476
|
+
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
477
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
478
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
479
|
+
case 0:
|
|
480
|
+
_context4.next = 2;
|
|
481
|
+
return processImagePaste(finalImageFiles, htmlData, from, to);
|
|
482
|
+
case 2:
|
|
483
|
+
case "end":
|
|
484
|
+
return _context4.stop();
|
|
485
|
+
}
|
|
486
|
+
}, _callee4);
|
|
487
|
+
}))();
|
|
488
|
+
}
|
|
306
489
|
return true;
|
|
307
490
|
}
|
|
308
491
|
}
|