@ctzhian/tiptap 1.12.5 → 1.12.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.
@@ -0,0 +1,840 @@
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
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
+ 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."); }
4
+ 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); }
5
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
+ 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; }
9
+ 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); } }
10
+ 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); }); }; }
11
+ import { Box, Divider, Stack, Typography } from "@mui/material";
12
+ import React from "react";
13
+ import { AddCircleFillIcon, ArrowDownSLineIcon, AttachmentLineIcon, BoldIcon, CheckboxCircleFillIcon, CloseCircleFillIcon, CodeBoxLineIcon, CodeLineIcon, DoubleQuotesLIcon, ErrorWarningFillIcon, Folder2LineIcon, FunctionsIcon, H1Icon, H2Icon, H3Icon, H4Icon, H5Icon, H6Icon, ImageLineIcon, Information2FillIcon, Information2LineIcon, ItalicIcon, LinkIcon, ListCheck3Icon, ListOrdered2Icon, ListUnorderedIcon, MarkPenLineIcon, MenuFold2FillIcon, MovieLineIcon, Music2LineIcon, SeparatorIcon, SquareRootIcon, StrikethroughIcon, SubscriptIcon, SuperscriptIcon, Table2Icon, UnderlineIcon, UserSmileFillIcon } from "../component/Icons";
14
+ import Menu from "../component/Menu";
15
+ import { ToolbarItem } from "../component/Toolbar";
16
+ import TableSizePicker from "../component/Toolbar/TableSizePicker";
17
+ import { getFileType } from "../util/fileHandler";
18
+ var EditorMarkdownToolbar = function EditorMarkdownToolbar(_ref) {
19
+ var aceEditorRef = _ref.aceEditorRef,
20
+ isExpend = _ref.isExpend,
21
+ onUpload = _ref.onUpload;
22
+ var imageInputRef = React.useRef(null);
23
+ var videoInputRef = React.useRef(null);
24
+ var audioInputRef = React.useRef(null);
25
+ var attachmentInputRef = React.useRef(null);
26
+ var handleFileUpload = /*#__PURE__*/function () {
27
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file, expectedType) {
28
+ var url, fileType, content;
29
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
30
+ while (1) switch (_context.prev = _context.next) {
31
+ case 0:
32
+ if (onUpload) {
33
+ _context.next = 2;
34
+ break;
35
+ }
36
+ return _context.abrupt("return");
37
+ case 2:
38
+ _context.prev = 2;
39
+ _context.next = 5;
40
+ return onUpload(file, function (_ref3) {
41
+ var progress = _ref3.progress;
42
+ // 可以在这里显示上传进度
43
+ console.log('Upload progress:', progress);
44
+ });
45
+ case 5:
46
+ url = _context.sent;
47
+ fileType = getFileType(file);
48
+ content = ''; // 根据文件类型插入对应的内容
49
+ if (expectedType === 'image') {
50
+ // 图片:插入 [file.name](url)
51
+ content = "![".concat(file.name, "](").concat(url, ")");
52
+ } else if (expectedType === 'video') {
53
+ // 视频:插入 <video src="url"></video>
54
+ content = "<p>\n<video src=\"".concat(url, "\" controls=\"true\"></video>\n</p>");
55
+ } else if (expectedType === 'audio') {
56
+ // 音频:插入 <audio src="url"></audio>
57
+ content = "<p>\n<audio src=\"".concat(url, "\" controls=\"true\"></audio>\n</p>");
58
+ } else {
59
+ // 附件:插入 <a href="url" download="file.name">file.name</a>
60
+ content = "<p>\n<a href=\"".concat(url, "\" download=\"").concat(file.name, "\">").concat(file.name, "</a>\n</p>");
61
+ }
62
+ insertTextAndFocusPositionRow({
63
+ text: content,
64
+ block: true
65
+ });
66
+ _context.next = 15;
67
+ break;
68
+ case 12:
69
+ _context.prev = 12;
70
+ _context.t0 = _context["catch"](2);
71
+ console.error('文件上传失败:', _context.t0);
72
+ case 15:
73
+ case "end":
74
+ return _context.stop();
75
+ }
76
+ }, _callee, null, [[2, 12]]);
77
+ }));
78
+ return function handleFileUpload(_x, _x2) {
79
+ return _ref2.apply(this, arguments);
80
+ };
81
+ }();
82
+ var handleFileSelect = function handleFileSelect(event, expectedType) {
83
+ var _event$target$files;
84
+ var file = (_event$target$files = event.target.files) === null || _event$target$files === void 0 ? void 0 : _event$target$files[0];
85
+ if (file) {
86
+ handleFileUpload(file, expectedType);
87
+ }
88
+ event.target.value = '';
89
+ };
90
+ var insertTextAndFocusPositionRow = function insertTextAndFocusPositionRow(options) {
91
+ var _aceEditorRef$current;
92
+ var _options$position = options.position,
93
+ position = _options$position === void 0 ? 0 : _options$position,
94
+ _options$row = options.row,
95
+ row = _options$row === void 0 ? 0 : _options$row,
96
+ _options$block = options.block,
97
+ block = _options$block === void 0 ? false : _options$block;
98
+ var editor = (_aceEditorRef$current = aceEditorRef.current) === null || _aceEditorRef$current === void 0 ? void 0 : _aceEditorRef$current.editor;
99
+ if (!editor) return;
100
+ var cursor = editor.getCursorPosition();
101
+ var isEditorEmpty = editor.getValue().length === 0;
102
+ var text = options.text;
103
+ var curRow = cursor.row + row;
104
+ var curColumn = cursor.column + position;
105
+ if (block) {
106
+ curColumn = position;
107
+ text = "\n\n".concat(options.text);
108
+ curRow += 2;
109
+ }
110
+ if (isEditorEmpty) {
111
+ text = "".concat(options.text);
112
+ }
113
+ editor.insert(text);
114
+ editor.moveCursorTo(curRow, curColumn);
115
+ editor.focus();
116
+ };
117
+ var HeadingOptions = [{
118
+ id: '1',
119
+ icon: /*#__PURE__*/React.createElement(H1Icon, {
120
+ sx: {
121
+ fontSize: '1rem'
122
+ }
123
+ }),
124
+ label: '一级标题',
125
+ onClick: function onClick() {
126
+ insertTextAndFocusPositionRow({
127
+ text: '# ',
128
+ position: 2,
129
+ block: true
130
+ });
131
+ }
132
+ }, {
133
+ id: '2',
134
+ icon: /*#__PURE__*/React.createElement(H2Icon, {
135
+ sx: {
136
+ fontSize: '1rem'
137
+ }
138
+ }),
139
+ label: '二级标题',
140
+ onClick: function onClick() {
141
+ insertTextAndFocusPositionRow({
142
+ text: '## ',
143
+ position: 3,
144
+ block: true
145
+ });
146
+ }
147
+ }, {
148
+ id: '3',
149
+ icon: /*#__PURE__*/React.createElement(H3Icon, {
150
+ sx: {
151
+ fontSize: '1rem'
152
+ }
153
+ }),
154
+ label: '三级标题',
155
+ onClick: function onClick() {
156
+ insertTextAndFocusPositionRow({
157
+ text: '### ',
158
+ position: 4,
159
+ block: true
160
+ });
161
+ }
162
+ }, {
163
+ id: '4',
164
+ icon: /*#__PURE__*/React.createElement(H4Icon, {
165
+ sx: {
166
+ fontSize: '1rem'
167
+ }
168
+ }),
169
+ label: '四级标题',
170
+ onClick: function onClick() {
171
+ insertTextAndFocusPositionRow({
172
+ text: '#### ',
173
+ position: 5,
174
+ block: true
175
+ });
176
+ }
177
+ }, {
178
+ id: '5',
179
+ icon: /*#__PURE__*/React.createElement(H5Icon, {
180
+ sx: {
181
+ fontSize: '1rem'
182
+ }
183
+ }),
184
+ label: '五级标题',
185
+ onClick: function onClick() {
186
+ insertTextAndFocusPositionRow({
187
+ text: '##### ',
188
+ position: 6,
189
+ block: true
190
+ });
191
+ }
192
+ }, {
193
+ id: '6',
194
+ icon: /*#__PURE__*/React.createElement(H6Icon, {
195
+ sx: {
196
+ fontSize: '1rem'
197
+ }
198
+ }),
199
+ label: '六级标题',
200
+ onClick: function onClick() {
201
+ insertTextAndFocusPositionRow({
202
+ text: '###### ',
203
+ position: 7,
204
+ block: true
205
+ });
206
+ }
207
+ }];
208
+ var ToolList = [{
209
+ id: 'bold',
210
+ icon: /*#__PURE__*/React.createElement(BoldIcon, {
211
+ sx: {
212
+ fontSize: '1rem'
213
+ }
214
+ }),
215
+ label: '加粗',
216
+ onClick: function onClick() {
217
+ insertTextAndFocusPositionRow({
218
+ text: '****',
219
+ position: 2
220
+ });
221
+ }
222
+ }, {
223
+ id: 'italic',
224
+ icon: /*#__PURE__*/React.createElement(ItalicIcon, {
225
+ sx: {
226
+ fontSize: '1rem'
227
+ }
228
+ }),
229
+ label: '斜体',
230
+ onClick: function onClick() {
231
+ insertTextAndFocusPositionRow({
232
+ text: '**',
233
+ position: 1
234
+ });
235
+ }
236
+ }, {
237
+ id: 'strikethrough',
238
+ icon: /*#__PURE__*/React.createElement(StrikethroughIcon, {
239
+ sx: {
240
+ fontSize: '1rem'
241
+ }
242
+ }),
243
+ label: '删除线',
244
+ onClick: function onClick() {
245
+ insertTextAndFocusPositionRow({
246
+ text: '~~~~',
247
+ position: 2
248
+ });
249
+ }
250
+ }, {
251
+ id: 'underline',
252
+ icon: /*#__PURE__*/React.createElement(UnderlineIcon, {
253
+ sx: {
254
+ fontSize: '1rem'
255
+ }
256
+ }),
257
+ label: '下划线',
258
+ onClick: function onClick() {
259
+ insertTextAndFocusPositionRow({
260
+ text: '++++',
261
+ position: 2
262
+ });
263
+ }
264
+ }, {
265
+ id: 'highlight',
266
+ icon: /*#__PURE__*/React.createElement(MarkPenLineIcon, {
267
+ sx: {
268
+ fontSize: '1rem'
269
+ }
270
+ }),
271
+ label: '高亮',
272
+ onClick: function onClick() {
273
+ insertTextAndFocusPositionRow({
274
+ text: '====',
275
+ position: 2
276
+ });
277
+ }
278
+ }, {
279
+ id: 'superscript',
280
+ icon: /*#__PURE__*/React.createElement(SuperscriptIcon, {
281
+ sx: {
282
+ fontSize: '1rem'
283
+ }
284
+ }),
285
+ label: '上标',
286
+ onClick: function onClick() {
287
+ insertTextAndFocusPositionRow({
288
+ text: '^^',
289
+ position: 1
290
+ });
291
+ }
292
+ }, {
293
+ id: 'subscript',
294
+ icon: /*#__PURE__*/React.createElement(SubscriptIcon, {
295
+ sx: {
296
+ fontSize: '1rem'
297
+ }
298
+ }),
299
+ label: '下标',
300
+ onClick: function onClick() {
301
+ insertTextAndFocusPositionRow({
302
+ text: '~~',
303
+ position: 1
304
+ });
305
+ }
306
+ }, {
307
+ id: 'divider-1'
308
+ }, {
309
+ id: 'bullet-list',
310
+ icon: /*#__PURE__*/React.createElement(ListUnorderedIcon, {
311
+ sx: {
312
+ fontSize: '1rem'
313
+ }
314
+ }),
315
+ label: '无序列表',
316
+ onClick: function onClick() {
317
+ insertTextAndFocusPositionRow({
318
+ text: '- ',
319
+ position: 2,
320
+ block: true
321
+ });
322
+ }
323
+ }, {
324
+ id: 'ordered-list',
325
+ icon: /*#__PURE__*/React.createElement(ListOrdered2Icon, {
326
+ sx: {
327
+ fontSize: '1rem'
328
+ }
329
+ }),
330
+ label: '有序列表',
331
+ onClick: function onClick() {
332
+ insertTextAndFocusPositionRow({
333
+ text: '1. ',
334
+ position: 3,
335
+ block: true
336
+ });
337
+ }
338
+ }, {
339
+ id: 'task-list',
340
+ icon: /*#__PURE__*/React.createElement(ListCheck3Icon, {
341
+ sx: {
342
+ fontSize: '1rem'
343
+ }
344
+ }),
345
+ label: '任务列表',
346
+ onClick: function onClick() {
347
+ insertTextAndFocusPositionRow({
348
+ text: '- [ ] ',
349
+ position: 6,
350
+ block: true
351
+ });
352
+ }
353
+ }, {
354
+ id: 'divider-2'
355
+ }, {
356
+ id: 'inline-math',
357
+ icon: /*#__PURE__*/React.createElement(SquareRootIcon, {
358
+ sx: {
359
+ fontSize: '1rem'
360
+ }
361
+ }),
362
+ label: '行内数学公式',
363
+ onClick: function onClick() {
364
+ insertTextAndFocusPositionRow({
365
+ text: '$$',
366
+ position: 1
367
+ });
368
+ }
369
+ }, {
370
+ id: 'block-math',
371
+ icon: /*#__PURE__*/React.createElement(FunctionsIcon, {
372
+ sx: {
373
+ fontSize: '1rem'
374
+ }
375
+ }),
376
+ label: '块级数学公式',
377
+ onClick: function onClick() {
378
+ insertTextAndFocusPositionRow({
379
+ text: '$$\n\n$$',
380
+ row: 1,
381
+ block: true
382
+ });
383
+ }
384
+ }, {
385
+ id: 'code',
386
+ icon: /*#__PURE__*/React.createElement(CodeLineIcon, {
387
+ sx: {
388
+ fontSize: '1rem'
389
+ }
390
+ }),
391
+ label: '代码',
392
+ onClick: function onClick() {
393
+ insertTextAndFocusPositionRow({
394
+ text: '``',
395
+ position: 1
396
+ });
397
+ }
398
+ }, {
399
+ id: 'codeBlock',
400
+ icon: /*#__PURE__*/React.createElement(CodeBoxLineIcon, {
401
+ sx: {
402
+ fontSize: '1rem'
403
+ }
404
+ }),
405
+ label: '代码块',
406
+ onClick: function onClick() {
407
+ insertTextAndFocusPositionRow({
408
+ text: '```\n\n```',
409
+ row: 1,
410
+ block: true
411
+ });
412
+ }
413
+ }, {
414
+ id: 'divider-3'
415
+ }, {
416
+ id: 'link',
417
+ icon: /*#__PURE__*/React.createElement(LinkIcon, {
418
+ sx: {
419
+ fontSize: '1rem'
420
+ }
421
+ }),
422
+ label: '链接',
423
+ onClick: function onClick() {
424
+ insertTextAndFocusPositionRow({
425
+ text: '[]()',
426
+ position: 1
427
+ });
428
+ }
429
+ }, {
430
+ id: 'image',
431
+ icon: /*#__PURE__*/React.createElement(ImageLineIcon, {
432
+ sx: {
433
+ fontSize: '1rem'
434
+ }
435
+ }),
436
+ label: '图片',
437
+ onClick: function onClick() {
438
+ insertTextAndFocusPositionRow({
439
+ text: '![alt]()',
440
+ position: 7
441
+ });
442
+ }
443
+ }];
444
+ return /*#__PURE__*/React.createElement(Stack, {
445
+ direction: 'row',
446
+ alignItems: 'center'
447
+ }, /*#__PURE__*/React.createElement(Menu, {
448
+ context: /*#__PURE__*/React.createElement(ToolbarItem, {
449
+ text: '插入',
450
+ icon: /*#__PURE__*/React.createElement(AddCircleFillIcon, {
451
+ sx: {
452
+ fontSize: '1rem'
453
+ }
454
+ })
455
+ }),
456
+ anchorOrigin: {
457
+ vertical: 'bottom',
458
+ horizontal: 'left'
459
+ },
460
+ transformOrigin: {
461
+ vertical: 'top',
462
+ horizontal: 'left'
463
+ },
464
+ arrowIcon: /*#__PURE__*/React.createElement(ArrowDownSLineIcon, {
465
+ sx: {
466
+ fontSize: '1rem',
467
+ transform: 'rotate(-90deg)'
468
+ }
469
+ }),
470
+ zIndex: isExpend ? 2100 : undefined,
471
+ list: [{
472
+ customLabel: /*#__PURE__*/React.createElement(Typography, {
473
+ sx: {
474
+ px: 1,
475
+ pt: 2,
476
+ fontSize: '12px',
477
+ color: 'text.disabled'
478
+ }
479
+ }, "\u901A\u7528"),
480
+ key: 'current-node'
481
+ }, {
482
+ label: '表格',
483
+ key: 'table',
484
+ icon: /*#__PURE__*/React.createElement(Table2Icon, {
485
+ sx: {
486
+ fontSize: '1rem'
487
+ }
488
+ }),
489
+ children: [{
490
+ key: 'table-size-picker',
491
+ customLabel: /*#__PURE__*/React.createElement(TableSizePicker, {
492
+ onConfirm: function onConfirm(cols, rows) {
493
+ var headerRow = "| ".concat(Array.from({
494
+ length: cols
495
+ }).map(function () {
496
+ return '';
497
+ }).join(' | '), " |\n");
498
+ var separatorRow = "| ".concat(Array.from({
499
+ length: cols
500
+ }).map(function () {
501
+ return '---';
502
+ }).join(' | '), " |\n");
503
+ var dataRows = Array.from({
504
+ length: rows
505
+ }).map(function () {
506
+ return "| ".concat(Array.from({
507
+ length: cols
508
+ }).map(function () {
509
+ return '';
510
+ }).join(' | '), " |\n");
511
+ }).join('');
512
+ var tableMarkdown = "".concat(headerRow).concat(separatorRow).concat(dataRows);
513
+ insertTextAndFocusPositionRow({
514
+ text: tableMarkdown,
515
+ position: 1,
516
+ block: true
517
+ });
518
+ }
519
+ })
520
+ }]
521
+ }, {
522
+ label: '上传文件',
523
+ key: 'upload-file',
524
+ icon: /*#__PURE__*/React.createElement(Folder2LineIcon, {
525
+ sx: {
526
+ fontSize: '1rem'
527
+ }
528
+ }),
529
+ children: [{
530
+ label: '上传图片',
531
+ key: 'upload-image',
532
+ icon: /*#__PURE__*/React.createElement(ImageLineIcon, {
533
+ sx: {
534
+ fontSize: '1rem'
535
+ }
536
+ }),
537
+ onClick: function onClick() {
538
+ var _imageInputRef$curren;
539
+ return (_imageInputRef$curren = imageInputRef.current) === null || _imageInputRef$curren === void 0 ? void 0 : _imageInputRef$curren.click();
540
+ }
541
+ }, {
542
+ label: '上传视频',
543
+ key: 'upload-video',
544
+ icon: /*#__PURE__*/React.createElement(MovieLineIcon, {
545
+ sx: {
546
+ fontSize: '1rem'
547
+ }
548
+ }),
549
+ onClick: function onClick() {
550
+ var _videoInputRef$curren;
551
+ return (_videoInputRef$curren = videoInputRef.current) === null || _videoInputRef$curren === void 0 ? void 0 : _videoInputRef$curren.click();
552
+ }
553
+ }, {
554
+ label: '上传音频',
555
+ key: 'upload-audio',
556
+ icon: /*#__PURE__*/React.createElement(Music2LineIcon, {
557
+ sx: {
558
+ fontSize: '1rem'
559
+ }
560
+ }),
561
+ onClick: function onClick() {
562
+ var _audioInputRef$curren;
563
+ return (_audioInputRef$curren = audioInputRef.current) === null || _audioInputRef$curren === void 0 ? void 0 : _audioInputRef$curren.click();
564
+ }
565
+ }, {
566
+ label: '上传附件',
567
+ key: 'upload-attachment',
568
+ icon: /*#__PURE__*/React.createElement(AttachmentLineIcon, {
569
+ sx: {
570
+ fontSize: '1rem'
571
+ }
572
+ }),
573
+ onClick: function onClick() {
574
+ var _attachmentInputRef$c;
575
+ return (_attachmentInputRef$c = attachmentInputRef.current) === null || _attachmentInputRef$c === void 0 ? void 0 : _attachmentInputRef$c.click();
576
+ }
577
+ }]
578
+ }, {
579
+ customLabel: /*#__PURE__*/React.createElement(Typography, {
580
+ sx: {
581
+ px: 1,
582
+ pt: 2,
583
+ fontSize: '12px',
584
+ color: 'text.disabled'
585
+ }
586
+ }, "\u6837\u5F0F\u5E03\u5C40"),
587
+ key: 'style'
588
+ }, {
589
+ label: '分割线',
590
+ key: 'separator',
591
+ icon: /*#__PURE__*/React.createElement(SeparatorIcon, {
592
+ sx: {
593
+ fontSize: '1rem'
594
+ }
595
+ }),
596
+ onClick: function onClick() {
597
+ return insertTextAndFocusPositionRow({
598
+ text: '---',
599
+ position: 3,
600
+ block: true
601
+ });
602
+ }
603
+ }, {
604
+ label: '引用',
605
+ key: 'blockquote',
606
+ icon: /*#__PURE__*/React.createElement(DoubleQuotesLIcon, {
607
+ sx: {
608
+ fontSize: '1rem'
609
+ }
610
+ }),
611
+ onClick: function onClick() {
612
+ return insertTextAndFocusPositionRow({
613
+ text: '> ',
614
+ position: 2,
615
+ block: true
616
+ });
617
+ }
618
+ }, {
619
+ label: '折叠面板',
620
+ key: 'details',
621
+ icon: /*#__PURE__*/React.createElement(MenuFold2FillIcon, {
622
+ sx: {
623
+ fontSize: '1rem'
624
+ }
625
+ }),
626
+ onClick: function onClick() {
627
+ return insertTextAndFocusPositionRow({
628
+ text: ':::details\n\n:::detailsSummary\n\n:::\n\n:::detailsContent\n\n:::\n\n:::\n',
629
+ row: 1,
630
+ block: true
631
+ });
632
+ }
633
+ }, {
634
+ label: '警告块',
635
+ key: 'highlight',
636
+ icon: /*#__PURE__*/React.createElement(Information2LineIcon, {
637
+ sx: {
638
+ fontSize: '1rem'
639
+ }
640
+ }),
641
+ children: [{
642
+ label: '信息 Info',
643
+ key: 'info',
644
+ icon: /*#__PURE__*/React.createElement(Information2FillIcon, {
645
+ sx: {
646
+ fontSize: '1rem',
647
+ color: 'primary.main'
648
+ }
649
+ }),
650
+ onClick: function onClick() {
651
+ insertTextAndFocusPositionRow({
652
+ text: ':::alert {variant="info"}\n\n:::',
653
+ row: -1,
654
+ block: true
655
+ });
656
+ }
657
+ }, {
658
+ label: '警告 Warning',
659
+ key: 'warning',
660
+ icon: /*#__PURE__*/React.createElement(ErrorWarningFillIcon, {
661
+ sx: {
662
+ fontSize: '1rem',
663
+ color: 'warning.main'
664
+ }
665
+ }),
666
+ onClick: function onClick() {
667
+ insertTextAndFocusPositionRow({
668
+ text: ':::alert {variant="warning"}\n\n:::',
669
+ row: -1,
670
+ block: true
671
+ });
672
+ }
673
+ }, {
674
+ label: '错误 Error',
675
+ key: 'error',
676
+ icon: /*#__PURE__*/React.createElement(CloseCircleFillIcon, {
677
+ sx: {
678
+ fontSize: '1rem',
679
+ color: 'error.main'
680
+ }
681
+ }),
682
+ onClick: function onClick() {
683
+ insertTextAndFocusPositionRow({
684
+ text: ':::alert {variant="error"}\n\n:::',
685
+ row: -1,
686
+ block: true
687
+ });
688
+ }
689
+ }, {
690
+ label: '成功 Success',
691
+ key: 'success',
692
+ icon: /*#__PURE__*/React.createElement(CheckboxCircleFillIcon, {
693
+ sx: {
694
+ fontSize: '1rem',
695
+ color: 'success.main'
696
+ }
697
+ }),
698
+ onClick: function onClick() {
699
+ insertTextAndFocusPositionRow({
700
+ text: ':::alert {variant="success"}\n\n:::',
701
+ row: -1,
702
+ block: true
703
+ });
704
+ }
705
+ }, {
706
+ label: '默认 Default',
707
+ key: 'default',
708
+ icon: /*#__PURE__*/React.createElement(UserSmileFillIcon, {
709
+ sx: {
710
+ fontSize: '1rem',
711
+ color: 'text.disabled'
712
+ }
713
+ }),
714
+ onClick: function onClick() {
715
+ insertTextAndFocusPositionRow({
716
+ text: ':::alert {variant="default"}\n\n:::',
717
+ row: -1,
718
+ block: true
719
+ });
720
+ }
721
+ }]
722
+ }]
723
+ }), /*#__PURE__*/React.createElement(Divider, {
724
+ sx: {
725
+ mx: 0.5,
726
+ height: 20,
727
+ alignSelf: 'center'
728
+ },
729
+ orientation: "vertical",
730
+ flexItem: true
731
+ }), /*#__PURE__*/React.createElement(Menu, {
732
+ context: /*#__PURE__*/React.createElement(ToolbarItem, {
733
+ tip: '标题',
734
+ text: /*#__PURE__*/React.createElement(Box, {
735
+ sx: {
736
+ position: 'relative',
737
+ pr: 1
738
+ }
739
+ }, /*#__PURE__*/React.createElement(Box, {
740
+ sx: {
741
+ width: '38px',
742
+ textAlign: 'left'
743
+ }
744
+ }, "\u6807\u9898"), /*#__PURE__*/React.createElement(ArrowDownSLineIcon, {
745
+ sx: {
746
+ position: 'absolute',
747
+ right: -6,
748
+ top: '50%',
749
+ transform: 'translateY(-50%)',
750
+ flexSelf: 'center',
751
+ fontSize: '1rem',
752
+ flexShrink: 0,
753
+ mr: 0,
754
+ color: 'text.disabled',
755
+ cursor: 'pointer',
756
+ pointerEvents: 'none'
757
+ }
758
+ }))
759
+ }),
760
+ anchorOrigin: {
761
+ vertical: 'bottom',
762
+ horizontal: 'left'
763
+ },
764
+ transformOrigin: {
765
+ vertical: 'top',
766
+ horizontal: 'left'
767
+ },
768
+ arrowIcon: /*#__PURE__*/React.createElement(ArrowDownSLineIcon, {
769
+ sx: {
770
+ fontSize: '1rem',
771
+ transform: 'rotate(-90deg)'
772
+ }
773
+ }),
774
+ zIndex: isExpend ? 2100 : undefined,
775
+ list: _toConsumableArray(HeadingOptions.map(function (it) {
776
+ return {
777
+ label: it.label,
778
+ key: it.id,
779
+ icon: it.icon,
780
+ onClick: it.onClick
781
+ };
782
+ }))
783
+ }), ToolList.map(function (it) {
784
+ return it.id.includes('divider') ? /*#__PURE__*/React.createElement(Divider, {
785
+ key: it.id,
786
+ sx: {
787
+ mx: 0.5,
788
+ height: 20,
789
+ alignSelf: 'center'
790
+ },
791
+ orientation: "vertical",
792
+ flexItem: true
793
+ }) : /*#__PURE__*/React.createElement(ToolbarItem, {
794
+ key: it.id,
795
+ tip: it.label,
796
+ icon: it.icon,
797
+ onClick: it === null || it === void 0 ? void 0 : it.onClick
798
+ });
799
+ }), /*#__PURE__*/React.createElement("input", {
800
+ ref: imageInputRef,
801
+ type: "file",
802
+ accept: "image/*",
803
+ style: {
804
+ display: 'none'
805
+ },
806
+ onChange: function onChange(e) {
807
+ return handleFileSelect(e, 'image');
808
+ }
809
+ }), /*#__PURE__*/React.createElement("input", {
810
+ ref: videoInputRef,
811
+ type: "file",
812
+ accept: "video/*",
813
+ style: {
814
+ display: 'none'
815
+ },
816
+ onChange: function onChange(e) {
817
+ return handleFileSelect(e, 'video');
818
+ }
819
+ }), /*#__PURE__*/React.createElement("input", {
820
+ ref: audioInputRef,
821
+ type: "file",
822
+ accept: "audio/*",
823
+ style: {
824
+ display: 'none'
825
+ },
826
+ onChange: function onChange(e) {
827
+ return handleFileSelect(e, 'audio');
828
+ }
829
+ }), /*#__PURE__*/React.createElement("input", {
830
+ ref: attachmentInputRef,
831
+ type: "file",
832
+ style: {
833
+ display: 'none'
834
+ },
835
+ onChange: function onChange(e) {
836
+ return handleFileSelect(e, 'attachment');
837
+ }
838
+ }));
839
+ };
840
+ export default EditorMarkdownToolbar;