@ctzhian/tiptap 2.9.5 → 2.10.0
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/asset/css/index.css +1 -0
- package/dist/component/CustomBubbleMenu/index.js +1 -1
- package/dist/component/Icons/index.d.ts +1 -0
- package/dist/component/Icons/index.js +1 -0
- package/dist/component/Icons/sketching-icon.d.ts +6 -0
- package/dist/component/Icons/sketching-icon.js +13 -0
- package/dist/component/Toolbar/EditorInsert/index.js +12 -1
- package/dist/contants/slash-commands.js +51 -64
- package/dist/extension/component/DrawPanel/ExcalidrawEditor.d.ts +8 -0
- package/dist/extension/component/DrawPanel/ExcalidrawEditor.js +137 -0
- package/dist/extension/component/DrawPanel/Modal.d.ts +8 -0
- package/dist/extension/component/DrawPanel/Modal.js +31 -0
- package/dist/extension/component/DrawPanel/index.d.ts +5 -0
- package/dist/extension/component/DrawPanel/index.js +168 -0
- package/dist/extension/component/SlashCommandsList/index.js +1 -1
- package/dist/extension/index.js +6 -1
- package/dist/extension/node/DrawPanel.d.ts +11 -0
- package/dist/extension/node/DrawPanel.js +61 -0
- package/dist/extension/node/index.d.ts +1 -0
- package/dist/extension/node/index.js +1 -0
- package/dist/types/declare.d.ts +6 -0
- package/package.json +2 -1
package/dist/asset/css/index.css
CHANGED
|
@@ -137,6 +137,7 @@
|
|
|
137
137
|
.tiptap.ProseMirror .react-renderer.node-inlineAttachment,
|
|
138
138
|
.tiptap.ProseMirror .react-renderer.node-blockLink,
|
|
139
139
|
.tiptap.ProseMirror .react-renderer.node-inlineLink,
|
|
140
|
+
.tiptap.ProseMirror .react-renderer.node-excalidraw,
|
|
140
141
|
.tiptap.ProseMirror .react-renderer.node-blockMath,
|
|
141
142
|
.tiptap.ProseMirror .react-renderer.node-inlineMath {
|
|
142
143
|
box-sizing: border-box;
|
|
@@ -46,7 +46,7 @@ var CustomBubbleMenu = function CustomBubbleMenu(_ref) {
|
|
|
46
46
|
shouldShow: function shouldShow(_ref2) {
|
|
47
47
|
var editor = _ref2.editor;
|
|
48
48
|
// 在某些特定节点类型时不显示
|
|
49
|
-
if (editor.state.selection.empty || editor.isEmpty || editor.isActive('image') || editor.isActive('video') || editor.isActive('audio') || editor.isActive('emoji') || editor.isActive('codeBlock') || editor.isActive('blockMath') || editor.isActive('inlineMath') || editor.isActive('blockLink') || editor.isActive('inlineLink') || editor.isActive('blockAttachment') || editor.isActive('inlineAttachment') || editor.isActive('horizontalRule') || editor.isActive('iframe') || editor.isActive('yamlFormat') || editor.isActive('flow') || editor.isActive('table') || editor.isActive('flipGrid') || editor.isActive('flipGridColumn')) {
|
|
49
|
+
if (editor.state.selection.empty || editor.isEmpty || editor.isActive('image') || editor.isActive('video') || editor.isActive('audio') || editor.isActive('emoji') || editor.isActive('codeBlock') || editor.isActive('blockMath') || editor.isActive('inlineMath') || editor.isActive('blockLink') || editor.isActive('inlineLink') || editor.isActive('blockAttachment') || editor.isActive('inlineAttachment') || editor.isActive('horizontalRule') || editor.isActive('iframe') || editor.isActive('yamlFormat') || editor.isActive('flow') || editor.isActive('table') || editor.isActive('flipGrid') || editor.isActive('flipGridColumn') || editor.isActive('excalidraw')) {
|
|
50
50
|
return false;
|
|
51
51
|
}
|
|
52
52
|
return true;
|
|
@@ -120,6 +120,7 @@ export { ScreenshotLineIcon } from './screenshot-line-icon';
|
|
|
120
120
|
export { ScrollToBottomLineIcon } from './scroll-to-bottom-line-icon';
|
|
121
121
|
export { SeparatorIcon } from './separator-icon';
|
|
122
122
|
export { ShareBoxLineIcon } from './share-box-line-icon';
|
|
123
|
+
export { SketchingIcon } from './sketching-icon';
|
|
123
124
|
export { SkipDownIcon } from './skip-down-icon';
|
|
124
125
|
export { SkipLeftIcon } from './skip-left-icon';
|
|
125
126
|
export { SkipRightIcon } from './skip-right-icon';
|
|
@@ -123,6 +123,7 @@ export { ScreenshotLineIcon } from "./screenshot-line-icon";
|
|
|
123
123
|
export { ScrollToBottomLineIcon } from "./scroll-to-bottom-line-icon";
|
|
124
124
|
export { SeparatorIcon } from "./separator-icon";
|
|
125
125
|
export { ShareBoxLineIcon } from "./share-box-line-icon";
|
|
126
|
+
export { SketchingIcon } from "./sketching-icon";
|
|
126
127
|
export { SkipDownIcon } from "./skip-down-icon";
|
|
127
128
|
export { SkipLeftIcon } from "./skip-left-icon";
|
|
128
129
|
export { SkipRightIcon } from "./skip-right-icon";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
import { SvgIcon } from "@mui/material";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
export var SketchingIcon = function SketchingIcon(props) {
|
|
5
|
+
return /*#__PURE__*/React.createElement(SvgIcon, _extends({
|
|
6
|
+
viewBox: "0 0 24 24",
|
|
7
|
+
version: "1.1",
|
|
8
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
9
|
+
}, props), /*#__PURE__*/React.createElement("path", {
|
|
10
|
+
d: "M10.0357 7.69802C8.38492 9.55932 6.5134 12.2442 4.89465 15.4817C4.64766 15.9757 4.04698 16.1759 3.55301 15.9289C3.05903 15.6819 2.8588 15.0812 3.10579 14.5873C4.79739 11.2041 6.76494 8.37171 8.53943 6.37095C9.4251 5.37234 10.2797 4.56162 11.0449 3.99131C11.4272 3.7063 11.8049 3.46806 12.1677 3.29756C12.5193 3.13234 12.921 3 13.3336 3C13.5496 3 13.7872 3.0535 14.007 3.19476C14.2233 3.33371 14.3629 3.51925 14.4495 3.69083C14.6066 4.00215 14.624 4.33473 14.6201 4.55938C14.6118 5.03651 14.4847 5.6328 14.3216 6.23975C13.9874 7.48318 13.3994 9.13104 12.8149 10.7577L12.7329 10.9858C12.1671 12.5598 11.6101 14.1093 11.248 15.3466C11.1505 15.68 11.0706 15.9792 11.0094 16.2414C11.7035 15.6835 12.5581 14.8454 13.466 13.9534L13.4956 13.9243C14.3772 13.0581 15.3098 12.1418 16.0967 11.5127C16.4872 11.2006 16.9082 10.904 17.3138 10.7322C17.6544 10.5878 18.4343 10.3532 19.0407 10.9596C19.4251 11.344 19.5318 11.8438 19.5594 12.2164C19.5883 12.6064 19.5429 13.0267 19.4725 13.4261C19.3315 14.2258 19.0483 15.159 18.7894 16.0009L18.7478 16.136C18.5165 16.8874 18.3102 17.5577 18.1926 18.0965C18.4529 17.8352 18.7734 17.4216 19.1475 16.811C19.436 16.34 20.0517 16.1921 20.5226 16.4806C20.9935 16.7691 21.1414 17.3848 20.8529 17.8557C20.3099 18.7422 19.748 19.4622 19.1519 19.9092C18.5283 20.377 17.7121 20.6407 16.8863 20.2278C16.2779 19.9235 16.1398 19.3173 16.1091 18.9819C16.0759 18.6192 16.1284 18.2233 16.1979 17.8667C16.3288 17.1944 16.5829 16.3698 16.823 15.5907L16.8777 15.4129C17.1447 14.5451 17.3873 13.734 17.5028 13.0789C17.5117 13.0284 17.5196 12.9802 17.5266 12.9341C17.4697 12.977 17.4094 13.0239 17.3455 13.0749C16.6477 13.6328 15.785 14.4788 14.8677 15.38L14.8381 15.4091C13.9566 16.2752 13.024 17.1915 12.2371 17.8206C11.8466 18.1328 11.4255 18.4293 11.02 18.6012C10.6794 18.7455 9.89947 18.9801 9.29311 18.3738C8.9843 18.065 8.9052 17.6753 8.87972 17.4382C8.8515 17.1755 8.86901 16.8971 8.90269 16.6351C8.9706 16.1069 9.12934 15.4656 9.32855 14.7849C9.70829 13.4872 10.2842 11.8852 10.8411 10.3362L10.9327 10.0814C11.5263 8.42931 12.082 6.8674 12.3901 5.72074C12.4172 5.61968 12.4418 5.52435 12.4638 5.43468C12.3924 5.48361 12.3178 5.53695 12.2401 5.59489C11.6173 6.05907 10.8627 6.76559 10.0357 7.69802Z"
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
SketchingIcon.displayName = 'icon-sketching';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getShortcutKeyText } from "../../../util";
|
|
2
2
|
import { Typography } from '@mui/material';
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import { AddCircleFillIcon, ArrowDownSLineIcon, AttachmentLineIcon, BilibiliLineIcon, CheckboxCircleFillIcon, CloseCircleFillIcon, CodeBoxLineIcon, CodeLineIcon, CodeSSlashLineIcon, DoubleQuotesLIcon, EmotionLineIcon, ErrorWarningFillIcon, FlipGridIcon, FlowChartIcon, FormulaIcon, FunctionsIcon, ImageLineIcon, Information2FillIcon, Information2LineIcon, MenuFold2FillIcon, MovieLineIcon, Music2LineIcon, SeparatorIcon, SquareRootIcon, Table2Icon, UserSmileFillIcon, WindowFillIcon } from "../../Icons";
|
|
4
|
+
import { AddCircleFillIcon, ArrowDownSLineIcon, AttachmentLineIcon, BilibiliLineIcon, CheckboxCircleFillIcon, CloseCircleFillIcon, CodeBoxLineIcon, CodeLineIcon, CodeSSlashLineIcon, DoubleQuotesLIcon, EmotionLineIcon, ErrorWarningFillIcon, FlipGridIcon, FlowChartIcon, FormulaIcon, FunctionsIcon, ImageLineIcon, Information2FillIcon, Information2LineIcon, MenuFold2FillIcon, MovieLineIcon, Music2LineIcon, SeparatorIcon, SketchingIcon, SquareRootIcon, Table2Icon, UserSmileFillIcon, WindowFillIcon } from "../../Icons";
|
|
5
5
|
import Menu from "../../Menu";
|
|
6
6
|
import ToolbarItem from "../Item";
|
|
7
7
|
import TableSizePicker from "../TableSizePicker";
|
|
@@ -342,6 +342,17 @@ var EditorInsert = function EditorInsert(_ref) {
|
|
|
342
342
|
onClick: function onClick() {
|
|
343
343
|
return editor.commands.setFlow({});
|
|
344
344
|
}
|
|
345
|
+
}, {
|
|
346
|
+
label: 'Excalidraw 绘图',
|
|
347
|
+
key: 'excalidraw',
|
|
348
|
+
icon: /*#__PURE__*/React.createElement(SketchingIcon, {
|
|
349
|
+
sx: {
|
|
350
|
+
fontSize: '1rem'
|
|
351
|
+
}
|
|
352
|
+
}),
|
|
353
|
+
onClick: function onClick() {
|
|
354
|
+
return editor.commands.setExcalidraw();
|
|
355
|
+
}
|
|
345
356
|
}, {
|
|
346
357
|
label: '代码',
|
|
347
358
|
key: 'code',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { AttachmentLineIcon, BilibiliLineIcon, CodeBoxLineIcon, CodeLineIcon, DoubleQuotesLIcon, EmotionLineIcon, FlipGridIcon, FlowChartIcon, FunctionsIcon, H1Icon, H2Icon, H3Icon, ImageLineIcon, Information2LineIcon, LinkIcon, ListCheck2Icon, ListOrdered2Icon, ListUnorderedIcon, MenuFold2FillIcon, MovieLineIcon, Music2LineIcon, SeparatorIcon, SquareRootIcon, Table2Icon, WindowFillIcon } from "../component/Icons";
|
|
2
|
+
import { AttachmentLineIcon, BilibiliLineIcon, CodeBoxLineIcon, CodeLineIcon, DoubleQuotesLIcon, EmotionLineIcon, FlipGridIcon, FlowChartIcon, FunctionsIcon, H1Icon, H2Icon, H3Icon, ImageLineIcon, Information2LineIcon, LinkIcon, ListCheck2Icon, ListOrdered2Icon, ListUnorderedIcon, MenuFold2FillIcon, MovieLineIcon, Music2LineIcon, SeparatorIcon, SketchingIcon, SquareRootIcon, Table2Icon, WindowFillIcon } from "../component/Icons";
|
|
3
3
|
export var slashCommands = [{
|
|
4
4
|
title: '标题1',
|
|
5
5
|
shortcutKey: ['ctrl', 'alt', '1'],
|
|
@@ -45,32 +45,7 @@ export var slashCommands = [{
|
|
|
45
45
|
level: 3
|
|
46
46
|
}).run();
|
|
47
47
|
}
|
|
48
|
-
},
|
|
49
|
-
// {
|
|
50
|
-
// title: '标题4',
|
|
51
|
-
// shortcutKey: ['ctrl', 'alt', '4'],
|
|
52
|
-
// icon: <H4Icon sx={{ fontSize: '1rem' }} />,
|
|
53
|
-
// command: ({ editor, range }: { editor: Editor; range: { from: number; to: number } }) => {
|
|
54
|
-
// editor.chain().focus().deleteRange(range).setNode('heading', { level: 4 }).run()
|
|
55
|
-
// }
|
|
56
|
-
// },
|
|
57
|
-
// {
|
|
58
|
-
// title: '标题5',
|
|
59
|
-
// shortcutKey: ['ctrl', 'alt', '5'],
|
|
60
|
-
// icon: <H5Icon sx={{ fontSize: '1rem' }} />,
|
|
61
|
-
// command: ({ editor, range }: { editor: Editor; range: { from: number; to: number } }) => {
|
|
62
|
-
// editor.chain().focus().deleteRange(range).setNode('heading', { level: 5 }).run()
|
|
63
|
-
// }
|
|
64
|
-
// },
|
|
65
|
-
// {
|
|
66
|
-
// title: '标题6',
|
|
67
|
-
// shortcutKey: ['ctrl', 'alt', '6'],
|
|
68
|
-
// icon: <H6Icon sx={{ fontSize: '1rem' }} />,
|
|
69
|
-
// command: ({ editor, range }: { editor: Editor; range: { from: number; to: number } }) => {
|
|
70
|
-
// editor.chain().focus().deleteRange(range).setNode('heading', { level: 6 }).run()
|
|
71
|
-
// }
|
|
72
|
-
// },
|
|
73
|
-
{
|
|
48
|
+
}, {
|
|
74
49
|
title: '有序列表',
|
|
75
50
|
shortcutKey: ['ctrl', 'shift', '7'],
|
|
76
51
|
icon: /*#__PURE__*/React.createElement(ListOrdered2Icon, {
|
|
@@ -228,8 +203,8 @@ export var slashCommands = [{
|
|
|
228
203
|
}).run();
|
|
229
204
|
}
|
|
230
205
|
}, {
|
|
231
|
-
title: '
|
|
232
|
-
icon: /*#__PURE__*/React.createElement(
|
|
206
|
+
title: 'Excalidraw 绘图',
|
|
207
|
+
icon: /*#__PURE__*/React.createElement(SketchingIcon, {
|
|
233
208
|
sx: {
|
|
234
209
|
fontSize: '1rem'
|
|
235
210
|
}
|
|
@@ -237,6 +212,18 @@ export var slashCommands = [{
|
|
|
237
212
|
command: function command(_ref16) {
|
|
238
213
|
var editor = _ref16.editor,
|
|
239
214
|
range = _ref16.range;
|
|
215
|
+
editor.chain().focus().deleteRange(range).setExcalidraw().run();
|
|
216
|
+
}
|
|
217
|
+
}, {
|
|
218
|
+
title: 'Bilibili 视频',
|
|
219
|
+
icon: /*#__PURE__*/React.createElement(BilibiliLineIcon, {
|
|
220
|
+
sx: {
|
|
221
|
+
fontSize: '1rem'
|
|
222
|
+
}
|
|
223
|
+
}),
|
|
224
|
+
command: function command(_ref17) {
|
|
225
|
+
var editor = _ref17.editor,
|
|
226
|
+
range = _ref17.range;
|
|
240
227
|
editor.chain().focus().deleteRange(range).setIframe({
|
|
241
228
|
src: '',
|
|
242
229
|
width: '100%',
|
|
@@ -251,9 +238,9 @@ export var slashCommands = [{
|
|
|
251
238
|
fontSize: '1rem'
|
|
252
239
|
}
|
|
253
240
|
}),
|
|
254
|
-
command: function command(
|
|
255
|
-
var editor =
|
|
256
|
-
range =
|
|
241
|
+
command: function command(_ref18) {
|
|
242
|
+
var editor = _ref18.editor,
|
|
243
|
+
range = _ref18.range;
|
|
257
244
|
editor.chain().focus().deleteRange(range).setIframe({
|
|
258
245
|
src: '',
|
|
259
246
|
width: '100%',
|
|
@@ -269,10 +256,10 @@ export var slashCommands = [{
|
|
|
269
256
|
fontSize: '1rem'
|
|
270
257
|
}
|
|
271
258
|
}),
|
|
272
|
-
command: function command(
|
|
273
|
-
var editor =
|
|
274
|
-
range =
|
|
275
|
-
attrs =
|
|
259
|
+
command: function command(_ref19) {
|
|
260
|
+
var editor = _ref19.editor,
|
|
261
|
+
range = _ref19.range,
|
|
262
|
+
attrs = _ref19.attrs;
|
|
276
263
|
editor.chain().focus().deleteRange(range).insertTable({
|
|
277
264
|
rows: attrs.rows || 3,
|
|
278
265
|
cols: attrs.cols || 4,
|
|
@@ -286,10 +273,10 @@ export var slashCommands = [{
|
|
|
286
273
|
fontSize: '1rem'
|
|
287
274
|
}
|
|
288
275
|
}),
|
|
289
|
-
command: function command(
|
|
290
|
-
var editor =
|
|
291
|
-
range =
|
|
292
|
-
attrs =
|
|
276
|
+
command: function command(_ref20) {
|
|
277
|
+
var editor = _ref20.editor,
|
|
278
|
+
range = _ref20.range,
|
|
279
|
+
attrs = _ref20.attrs;
|
|
293
280
|
editor.chain().focus().deleteRange(range).toggleAlert({
|
|
294
281
|
type: (attrs === null || attrs === void 0 ? void 0 : attrs.type) || 'icon',
|
|
295
282
|
variant: (attrs === null || attrs === void 0 ? void 0 : attrs.variant) || 'info'
|
|
@@ -302,9 +289,9 @@ export var slashCommands = [{
|
|
|
302
289
|
fontSize: '1rem'
|
|
303
290
|
}
|
|
304
291
|
}),
|
|
305
|
-
command: function command(
|
|
306
|
-
var editor =
|
|
307
|
-
range =
|
|
292
|
+
command: function command(_ref21) {
|
|
293
|
+
var editor = _ref21.editor,
|
|
294
|
+
range = _ref21.range;
|
|
308
295
|
editor.chain().focus().deleteRange(range).setDetails().run();
|
|
309
296
|
}
|
|
310
297
|
}, {
|
|
@@ -314,9 +301,9 @@ export var slashCommands = [{
|
|
|
314
301
|
fontSize: '1rem'
|
|
315
302
|
}
|
|
316
303
|
}),
|
|
317
|
-
command: function command(
|
|
318
|
-
var editor =
|
|
319
|
-
range =
|
|
304
|
+
command: function command(_ref22) {
|
|
305
|
+
var editor = _ref22.editor,
|
|
306
|
+
range = _ref22.range;
|
|
320
307
|
editor.chain().focus().deleteRange(range).toggleCodeBlock().run();
|
|
321
308
|
}
|
|
322
309
|
}, {
|
|
@@ -326,9 +313,9 @@ export var slashCommands = [{
|
|
|
326
313
|
fontSize: '1rem'
|
|
327
314
|
}
|
|
328
315
|
}),
|
|
329
|
-
command: function command(
|
|
330
|
-
var editor =
|
|
331
|
-
range =
|
|
316
|
+
command: function command(_ref23) {
|
|
317
|
+
var editor = _ref23.editor,
|
|
318
|
+
range = _ref23.range;
|
|
332
319
|
editor.chain().focus().deleteRange(range).setInlineMath({
|
|
333
320
|
latex: ''
|
|
334
321
|
}).run();
|
|
@@ -340,9 +327,9 @@ export var slashCommands = [{
|
|
|
340
327
|
fontSize: '1rem'
|
|
341
328
|
}
|
|
342
329
|
}),
|
|
343
|
-
command: function command(
|
|
344
|
-
var editor =
|
|
345
|
-
range =
|
|
330
|
+
command: function command(_ref24) {
|
|
331
|
+
var editor = _ref24.editor,
|
|
332
|
+
range = _ref24.range;
|
|
346
333
|
editor.chain().focus().deleteRange(range).setBlockMath({
|
|
347
334
|
latex: ''
|
|
348
335
|
}).run();
|
|
@@ -354,9 +341,9 @@ export var slashCommands = [{
|
|
|
354
341
|
fontSize: '1rem'
|
|
355
342
|
}
|
|
356
343
|
}),
|
|
357
|
-
command: function command(
|
|
358
|
-
var editor =
|
|
359
|
-
range =
|
|
344
|
+
command: function command(_ref25) {
|
|
345
|
+
var editor = _ref25.editor,
|
|
346
|
+
range = _ref25.range;
|
|
360
347
|
editor.chain().focus().deleteRange(range).setImage({
|
|
361
348
|
src: '',
|
|
362
349
|
width: 760
|
|
@@ -369,9 +356,9 @@ export var slashCommands = [{
|
|
|
369
356
|
fontSize: '1rem'
|
|
370
357
|
}
|
|
371
358
|
}),
|
|
372
|
-
command: function command(
|
|
373
|
-
var editor =
|
|
374
|
-
range =
|
|
359
|
+
command: function command(_ref26) {
|
|
360
|
+
var editor = _ref26.editor,
|
|
361
|
+
range = _ref26.range;
|
|
375
362
|
editor.chain().focus().deleteRange(range).setVideo({
|
|
376
363
|
src: '',
|
|
377
364
|
width: 760
|
|
@@ -384,9 +371,9 @@ export var slashCommands = [{
|
|
|
384
371
|
fontSize: '1rem'
|
|
385
372
|
}
|
|
386
373
|
}),
|
|
387
|
-
command: function command(
|
|
388
|
-
var editor =
|
|
389
|
-
range =
|
|
374
|
+
command: function command(_ref27) {
|
|
375
|
+
var editor = _ref27.editor,
|
|
376
|
+
range = _ref27.range;
|
|
390
377
|
editor.chain().focus().deleteRange(range).setAudio({
|
|
391
378
|
src: ''
|
|
392
379
|
}).run();
|
|
@@ -398,9 +385,9 @@ export var slashCommands = [{
|
|
|
398
385
|
fontSize: '1rem'
|
|
399
386
|
}
|
|
400
387
|
}),
|
|
401
|
-
command: function command(
|
|
402
|
-
var editor =
|
|
403
|
-
range =
|
|
388
|
+
command: function command(_ref28) {
|
|
389
|
+
var editor = _ref28.editor,
|
|
390
|
+
range = _ref28.range;
|
|
404
391
|
editor.chain().focus().deleteRange(range).setInlineAttachment({
|
|
405
392
|
url: '',
|
|
406
393
|
title: '',
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import '@excalidraw/excalidraw/index.css';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
interface ExcalidrawEditorProps {
|
|
4
|
+
onSave: (file: File) => void;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
}
|
|
7
|
+
declare const ExcalidrawEditorWrapper: React.FC<ExcalidrawEditorProps>;
|
|
8
|
+
export default ExcalidrawEditorWrapper;
|
|
@@ -0,0 +1,137 @@
|
|
|
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 _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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
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; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
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); }
|
|
8
|
+
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); } }
|
|
9
|
+
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); }); }; }
|
|
10
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
+
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
|
+
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; }
|
|
14
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
15
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
+
import '@excalidraw/excalidraw/index.css';
|
|
17
|
+
import { Button } from '@mui/material';
|
|
18
|
+
import React, { useRef, useState } from 'react';
|
|
19
|
+
var ExcalidrawEditor = /*#__PURE__*/React.lazy(function () {
|
|
20
|
+
if (typeof window !== 'undefined' && !window.EXCALIDRAW_ASSET_PATH) {
|
|
21
|
+
window.EXCALIDRAW_ASSET_PATH = '/';
|
|
22
|
+
}
|
|
23
|
+
return import('@excalidraw/excalidraw').then(function (module) {
|
|
24
|
+
return {
|
|
25
|
+
default: module.Excalidraw
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
var ExcalidrawEditorWrapper = function ExcalidrawEditorWrapper(_ref) {
|
|
30
|
+
var onSave = _ref.onSave,
|
|
31
|
+
onClose = _ref.onClose;
|
|
32
|
+
var excalidrawAPIRef = useRef(null);
|
|
33
|
+
var _useState = useState(false),
|
|
34
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
35
|
+
isLoaded = _useState2[0],
|
|
36
|
+
setIsLoaded = _useState2[1];
|
|
37
|
+
var handleSave = /*#__PURE__*/function () {
|
|
38
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
39
|
+
var elements, appState, files, excalidrawModule, exportToBlob, blob, _file;
|
|
40
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
41
|
+
while (1) switch (_context.prev = _context.next) {
|
|
42
|
+
case 0:
|
|
43
|
+
if (!excalidrawAPIRef.current) {
|
|
44
|
+
_context.next = 23;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
_context.prev = 1;
|
|
48
|
+
elements = excalidrawAPIRef.current.getSceneElements();
|
|
49
|
+
if (!(elements.length === 0)) {
|
|
50
|
+
_context.next = 5;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
return _context.abrupt("return");
|
|
54
|
+
case 5:
|
|
55
|
+
appState = excalidrawAPIRef.current.getAppState();
|
|
56
|
+
files = excalidrawAPIRef.current.getFiles();
|
|
57
|
+
_context.next = 9;
|
|
58
|
+
return import('@excalidraw/excalidraw');
|
|
59
|
+
case 9:
|
|
60
|
+
excalidrawModule = _context.sent;
|
|
61
|
+
exportToBlob = excalidrawModule.exportToBlob;
|
|
62
|
+
_context.next = 13;
|
|
63
|
+
return exportToBlob({
|
|
64
|
+
elements: elements,
|
|
65
|
+
appState: _objectSpread(_objectSpread({}, appState), {}, {
|
|
66
|
+
exportBackground: true,
|
|
67
|
+
exportScale: 2
|
|
68
|
+
}),
|
|
69
|
+
files: files,
|
|
70
|
+
mimeType: 'image/png',
|
|
71
|
+
quality: 0.92
|
|
72
|
+
});
|
|
73
|
+
case 13:
|
|
74
|
+
blob = _context.sent;
|
|
75
|
+
_file = new File([blob], "excalidraw-".concat(Date.now(), ".png"), {
|
|
76
|
+
type: 'image/png'
|
|
77
|
+
});
|
|
78
|
+
onSave(_file);
|
|
79
|
+
_context.next = 21;
|
|
80
|
+
break;
|
|
81
|
+
case 18:
|
|
82
|
+
_context.prev = 18;
|
|
83
|
+
_context.t0 = _context["catch"](1);
|
|
84
|
+
console.error('Failed to export Excalidraw as image', _context.t0);
|
|
85
|
+
case 21:
|
|
86
|
+
_context.next = 24;
|
|
87
|
+
break;
|
|
88
|
+
case 23:
|
|
89
|
+
console.warn('Excalidraw API not available');
|
|
90
|
+
case 24:
|
|
91
|
+
case "end":
|
|
92
|
+
return _context.stop();
|
|
93
|
+
}
|
|
94
|
+
}, _callee, null, [[1, 18]]);
|
|
95
|
+
}));
|
|
96
|
+
return function handleSave() {
|
|
97
|
+
return _ref2.apply(this, arguments);
|
|
98
|
+
};
|
|
99
|
+
}();
|
|
100
|
+
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
101
|
+
fallback: /*#__PURE__*/React.createElement("div", null, "\u52A0\u8F7D\u4E2D...")
|
|
102
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
103
|
+
style: {
|
|
104
|
+
width: '100%',
|
|
105
|
+
height: '100%',
|
|
106
|
+
position: 'relative'
|
|
107
|
+
}
|
|
108
|
+
}, /*#__PURE__*/React.createElement(ExcalidrawEditor, {
|
|
109
|
+
excalidrawAPI: function excalidrawAPI(api) {
|
|
110
|
+
excalidrawAPIRef.current = api;
|
|
111
|
+
if (!isLoaded) {
|
|
112
|
+
setIsLoaded(true);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
onChange: function onChange() {
|
|
116
|
+
// 可以在这里实现自动保存逻辑
|
|
117
|
+
}
|
|
118
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
119
|
+
style: {
|
|
120
|
+
position: 'absolute',
|
|
121
|
+
bottom: 16,
|
|
122
|
+
left: '50%',
|
|
123
|
+
transform: 'translateX(-50%)',
|
|
124
|
+
zIndex: 1000,
|
|
125
|
+
display: 'flex',
|
|
126
|
+
gap: 8
|
|
127
|
+
}
|
|
128
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
129
|
+
variant: "outlined",
|
|
130
|
+
onClick: onClose
|
|
131
|
+
}, "\u53D6\u6D88"), /*#__PURE__*/React.createElement(Button, {
|
|
132
|
+
variant: "contained",
|
|
133
|
+
onClick: handleSave,
|
|
134
|
+
disabled: !isLoaded
|
|
135
|
+
}, "\u4FDD\u5B58\u4E3A\u56FE\u7247\u5BFC\u5165"))));
|
|
136
|
+
};
|
|
137
|
+
export default ExcalidrawEditorWrapper;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Box, Dialog, DialogContent, DialogTitle } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import ExcalidrawEditor from "./ExcalidrawEditor";
|
|
4
|
+
var ExcalidrawModal = function ExcalidrawModal(_ref) {
|
|
5
|
+
var open = _ref.open,
|
|
6
|
+
onClose = _ref.onClose,
|
|
7
|
+
onSave = _ref.onSave;
|
|
8
|
+
return /*#__PURE__*/React.createElement(Dialog, {
|
|
9
|
+
open: open,
|
|
10
|
+
onClose: onClose,
|
|
11
|
+
maxWidth: "xl",
|
|
12
|
+
fullWidth: true
|
|
13
|
+
}, /*#__PURE__*/React.createElement(DialogTitle, null, "Excalidraw \u7ED8\u56FE"), /*#__PURE__*/React.createElement(DialogContent, {
|
|
14
|
+
sx: {
|
|
15
|
+
pt: 2,
|
|
16
|
+
p: 0,
|
|
17
|
+
overflow: 'hidden'
|
|
18
|
+
}
|
|
19
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
20
|
+
sx: {
|
|
21
|
+
width: '100%',
|
|
22
|
+
height: '80vh',
|
|
23
|
+
position: 'relative',
|
|
24
|
+
overflow: 'hidden'
|
|
25
|
+
}
|
|
26
|
+
}, /*#__PURE__*/React.createElement(ExcalidrawEditor, {
|
|
27
|
+
onSave: onSave,
|
|
28
|
+
onClose: onClose
|
|
29
|
+
}))));
|
|
30
|
+
};
|
|
31
|
+
export default ExcalidrawModal;
|
|
@@ -0,0 +1,168 @@
|
|
|
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 _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
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
+
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); }
|
|
8
|
+
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; }
|
|
9
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
10
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
import { MindMapIcon } from "../../../component/Icons";
|
|
12
|
+
import { Box, Stack } from '@mui/material';
|
|
13
|
+
import { NodeViewWrapper } from '@tiptap/react';
|
|
14
|
+
import React, { useState } from 'react';
|
|
15
|
+
import { getImageDimensionsFromFile } from "../Image";
|
|
16
|
+
import ExcalidrawModal from "./Modal";
|
|
17
|
+
var ExcalidrawView = function ExcalidrawView(_ref) {
|
|
18
|
+
var editor = _ref.editor,
|
|
19
|
+
node = _ref.node,
|
|
20
|
+
selected = _ref.selected,
|
|
21
|
+
getPos = _ref.getPos,
|
|
22
|
+
onUpload = _ref.onUpload;
|
|
23
|
+
var _useState = useState(false),
|
|
24
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
25
|
+
isModalOpen = _useState2[0],
|
|
26
|
+
setIsModalOpen = _useState2[1];
|
|
27
|
+
var handleOpenModal = function handleOpenModal() {
|
|
28
|
+
if (editor.isEditable) {
|
|
29
|
+
setIsModalOpen(true);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var handleCloseModal = function handleCloseModal() {
|
|
33
|
+
setIsModalOpen(false);
|
|
34
|
+
};
|
|
35
|
+
var handleSave = /*#__PURE__*/function () {
|
|
36
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file) {
|
|
37
|
+
var imageUrl, imageWidth, dimensions, pos, nodePos, nodeSize, imageNodeType, imageNode;
|
|
38
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
39
|
+
while (1) switch (_context.prev = _context.next) {
|
|
40
|
+
case 0:
|
|
41
|
+
_context.prev = 0;
|
|
42
|
+
if (!onUpload) {
|
|
43
|
+
_context.next = 9;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
_context.next = 4;
|
|
47
|
+
return onUpload(file);
|
|
48
|
+
case 4:
|
|
49
|
+
imageUrl = _context.sent;
|
|
50
|
+
if (imageUrl) {
|
|
51
|
+
_context.next = 7;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
return _context.abrupt("return");
|
|
55
|
+
case 7:
|
|
56
|
+
_context.next = 10;
|
|
57
|
+
break;
|
|
58
|
+
case 9:
|
|
59
|
+
imageUrl = URL.createObjectURL(file);
|
|
60
|
+
case 10:
|
|
61
|
+
// 获取图片实际宽度
|
|
62
|
+
imageWidth = 760; // 默认宽度
|
|
63
|
+
_context.prev = 11;
|
|
64
|
+
_context.next = 14;
|
|
65
|
+
return getImageDimensionsFromFile(file);
|
|
66
|
+
case 14:
|
|
67
|
+
dimensions = _context.sent;
|
|
68
|
+
imageWidth = Math.min(dimensions.width, 760);
|
|
69
|
+
_context.next = 21;
|
|
70
|
+
break;
|
|
71
|
+
case 18:
|
|
72
|
+
_context.prev = 18;
|
|
73
|
+
_context.t0 = _context["catch"](11);
|
|
74
|
+
console.warn('Failed to get image dimensions, using default width', _context.t0);
|
|
75
|
+
case 21:
|
|
76
|
+
pos = typeof getPos === 'function' ? getPos() : null;
|
|
77
|
+
if (pos !== null && pos !== undefined && typeof pos === 'number') {
|
|
78
|
+
nodePos = pos;
|
|
79
|
+
nodeSize = node.nodeSize;
|
|
80
|
+
imageNodeType = editor.schema.nodes.image;
|
|
81
|
+
if (imageNodeType) {
|
|
82
|
+
imageNode = imageNodeType.create({
|
|
83
|
+
src: imageUrl,
|
|
84
|
+
width: imageWidth
|
|
85
|
+
});
|
|
86
|
+
editor.chain().focus().command(function (_ref3) {
|
|
87
|
+
var tr = _ref3.tr;
|
|
88
|
+
tr.replaceWith(nodePos, nodePos + nodeSize, imageNode);
|
|
89
|
+
return true;
|
|
90
|
+
}).run();
|
|
91
|
+
} else {
|
|
92
|
+
editor.chain().focus().setImage({
|
|
93
|
+
src: imageUrl,
|
|
94
|
+
width: imageWidth
|
|
95
|
+
}).run();
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
editor.chain().focus().setImage({
|
|
99
|
+
src: imageUrl,
|
|
100
|
+
width: imageWidth
|
|
101
|
+
}).run();
|
|
102
|
+
}
|
|
103
|
+
setIsModalOpen(false);
|
|
104
|
+
_context.next = 29;
|
|
105
|
+
break;
|
|
106
|
+
case 26:
|
|
107
|
+
_context.prev = 26;
|
|
108
|
+
_context.t1 = _context["catch"](0);
|
|
109
|
+
console.error('Failed to save and insert image', _context.t1);
|
|
110
|
+
case 29:
|
|
111
|
+
case "end":
|
|
112
|
+
return _context.stop();
|
|
113
|
+
}
|
|
114
|
+
}, _callee, null, [[0, 26], [11, 18]]);
|
|
115
|
+
}));
|
|
116
|
+
return function handleSave(_x) {
|
|
117
|
+
return _ref2.apply(this, arguments);
|
|
118
|
+
};
|
|
119
|
+
}();
|
|
120
|
+
if (!editor.isEditable) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(NodeViewWrapper, {
|
|
124
|
+
className: "excalidraw-wrapper ".concat(selected ? 'ProseMirror-selectednode' : ''),
|
|
125
|
+
"data-drag-handle": true
|
|
126
|
+
}, /*#__PURE__*/React.createElement(Stack, {
|
|
127
|
+
direction: "row",
|
|
128
|
+
alignItems: "center",
|
|
129
|
+
gap: 2,
|
|
130
|
+
onClick: handleOpenModal,
|
|
131
|
+
sx: {
|
|
132
|
+
border: '1px dashed',
|
|
133
|
+
borderColor: 'divider',
|
|
134
|
+
borderRadius: 'var(--mui-shape-borderRadius)',
|
|
135
|
+
px: 2,
|
|
136
|
+
py: 1.5,
|
|
137
|
+
minWidth: 200,
|
|
138
|
+
textAlign: 'center',
|
|
139
|
+
color: 'text.secondary',
|
|
140
|
+
bgcolor: 'action.default',
|
|
141
|
+
position: 'relative',
|
|
142
|
+
overflow: 'hidden',
|
|
143
|
+
cursor: 'pointer',
|
|
144
|
+
'&:hover': {
|
|
145
|
+
bgcolor: 'action.hover'
|
|
146
|
+
},
|
|
147
|
+
'&:active': {
|
|
148
|
+
bgcolor: 'action.selected'
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}, /*#__PURE__*/React.createElement(MindMapIcon, {
|
|
152
|
+
sx: {
|
|
153
|
+
fontSize: '1rem'
|
|
154
|
+
}
|
|
155
|
+
}), /*#__PURE__*/React.createElement(Box, {
|
|
156
|
+
sx: {
|
|
157
|
+
fontSize: '0.875rem',
|
|
158
|
+
position: 'relative',
|
|
159
|
+
flexGrow: 1,
|
|
160
|
+
textAlign: 'left'
|
|
161
|
+
}
|
|
162
|
+
}, "\u70B9\u51FB\u6B64\u5904\u5D4C\u5165 Excalidraw \u7ED8\u56FE"))), isModalOpen && /*#__PURE__*/React.createElement(ExcalidrawModal, {
|
|
163
|
+
open: isModalOpen,
|
|
164
|
+
onClose: handleCloseModal,
|
|
165
|
+
onSave: handleSave
|
|
166
|
+
}));
|
|
167
|
+
};
|
|
168
|
+
export default ExcalidrawView;
|
|
@@ -25,7 +25,7 @@ var SlashCommandsList = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
25
25
|
}, /*#__PURE__*/React.createElement(Stack, {
|
|
26
26
|
direction: 'row',
|
|
27
27
|
flexWrap: 'wrap'
|
|
28
|
-
}, items.slice(0,
|
|
28
|
+
}, items.slice(0, 18).map(function (item, index) {
|
|
29
29
|
return /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
30
30
|
key: index,
|
|
31
31
|
shortcutKey: (item === null || item === void 0 ? void 0 : item.shortcutKey) || [],
|
package/dist/extension/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { PLACEHOLDER } from "../contants/placeholder";
|
|
|
15
15
|
import { AiWritingExtension, ImeComposition, SlashCommands, StructuredDiffExtension } from "./extension";
|
|
16
16
|
import { CodeExtension } from "./mark/Code";
|
|
17
17
|
import Tooltip from "./mark/Tooltip";
|
|
18
|
-
import { AlertExtension, AudioExtension, BlockAttachmentExtension, BlockLinkExtension, CodeBlockLowlightExtension, CustomBlockMathExtension, CustomHorizontalRule, CustomInlineMathExtension, CustomSubscript, CustomSuperscript, DetailsContentExtension, DetailsExtension, DetailsSummaryExtension, EmojiExtension, FileHandlerExtension, FlipGridColumnExtension, FlipGridExtension, FlowExtension, IframeExtension, ImageExtension, Indent, InlineAttachmentExtension, InlineLinkExtension, InlineUploadProgressExtension, ListExtension, MentionExtension, TableExtension, TableOfContents, UploadProgressExtension, VerticalAlign, VideoExtension, YamlFormat, YoutubeExtension } from "./node";
|
|
18
|
+
import { AlertExtension, AudioExtension, BlockAttachmentExtension, BlockLinkExtension, CodeBlockLowlightExtension, CustomBlockMathExtension, CustomHorizontalRule, CustomInlineMathExtension, CustomSubscript, CustomSuperscript, DetailsContentExtension, DetailsExtension, DetailsSummaryExtension, EmojiExtension, ExcalidrawExtension, FileHandlerExtension, FlipGridColumnExtension, FlipGridExtension, FlowExtension, IframeExtension, ImageExtension, Indent, InlineAttachmentExtension, InlineLinkExtension, InlineUploadProgressExtension, ListExtension, MentionExtension, TableExtension, TableOfContents, UploadProgressExtension, VerticalAlign, VideoExtension, YamlFormat, YoutubeExtension } from "./node";
|
|
19
19
|
export var getExtensions = function getExtensions(_ref) {
|
|
20
20
|
var limit = _ref.limit,
|
|
21
21
|
exclude = _ref.exclude,
|
|
@@ -159,6 +159,11 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
159
159
|
onAiWritingGetSuggestion: onAiWritingGetSuggestion
|
|
160
160
|
}));
|
|
161
161
|
}
|
|
162
|
+
if (!(exclude !== null && exclude !== void 0 && exclude.includes('excalidraw'))) {
|
|
163
|
+
defaultExtensions.push(ExcalidrawExtension({
|
|
164
|
+
onUpload: onUpload
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
162
167
|
} else {
|
|
163
168
|
// 只读模式
|
|
164
169
|
if (!(exclude !== null && exclude !== void 0 && exclude.includes('structuredDiff'))) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EditorFnProps } from "../../type";
|
|
2
|
+
import { Node } from '@tiptap/core';
|
|
3
|
+
declare module '@tiptap/core' {
|
|
4
|
+
interface Commands<ReturnType> {
|
|
5
|
+
excalidraw: {
|
|
6
|
+
setExcalidraw: () => ReturnType;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare const ExcalidrawExtension: (props?: EditorFnProps) => Node<any, any>;
|
|
11
|
+
export default ExcalidrawExtension;
|
|
@@ -0,0 +1,61 @@
|
|
|
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
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; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
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); }
|
|
7
|
+
import { createBlockMarkdownSpec, mergeAttributes, Node } from '@tiptap/core';
|
|
8
|
+
import { ReactNodeViewRenderer } from '@tiptap/react';
|
|
9
|
+
import ExcalidrawView from "../component/DrawPanel";
|
|
10
|
+
export var ExcalidrawExtension = function ExcalidrawExtension() {
|
|
11
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
12
|
+
return Node.create(_objectSpread(_objectSpread({
|
|
13
|
+
name: 'excalidraw',
|
|
14
|
+
group: 'block',
|
|
15
|
+
atom: true,
|
|
16
|
+
selectable: true,
|
|
17
|
+
draggable: true,
|
|
18
|
+
isolating: true,
|
|
19
|
+
addOptions: function addOptions() {
|
|
20
|
+
return {
|
|
21
|
+
HTMLAttributes: {}
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
addAttributes: function addAttributes() {
|
|
25
|
+
return {};
|
|
26
|
+
},
|
|
27
|
+
parseHTML: function parseHTML() {
|
|
28
|
+
return [{
|
|
29
|
+
tag: 'figure[data-type="excalidraw"]'
|
|
30
|
+
}];
|
|
31
|
+
},
|
|
32
|
+
renderHTML: function renderHTML(_ref) {
|
|
33
|
+
var HTMLAttributes = _ref.HTMLAttributes;
|
|
34
|
+
return ['figure', mergeAttributes({
|
|
35
|
+
'data-type': 'excalidraw'
|
|
36
|
+
}, HTMLAttributes, this.options.HTMLAttributes), 0];
|
|
37
|
+
}
|
|
38
|
+
}, createBlockMarkdownSpec({
|
|
39
|
+
nodeName: 'excalidraw'
|
|
40
|
+
})), {}, {
|
|
41
|
+
addCommands: function addCommands() {
|
|
42
|
+
var _this = this;
|
|
43
|
+
return {
|
|
44
|
+
setExcalidraw: function setExcalidraw() {
|
|
45
|
+
return function (_ref2) {
|
|
46
|
+
var commands = _ref2.commands;
|
|
47
|
+
return commands.insertContent({
|
|
48
|
+
type: _this.name
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
addNodeView: function addNodeView() {
|
|
55
|
+
return ReactNodeViewRenderer(function (renderProps) {
|
|
56
|
+
return ExcalidrawView(_objectSpread(_objectSpread({}, renderProps), props));
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
};
|
|
61
|
+
export default ExcalidrawExtension;
|
package/dist/types/declare.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ctzhian/tiptap",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"description": "基于 Tiptap 二次开发的编辑器组件",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"stylelint": "^14.9.1"
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
|
+
"@excalidraw/excalidraw": "^0.18.0",
|
|
83
84
|
"@floating-ui/dom": "^1.7.2",
|
|
84
85
|
"@floating-ui/react": "^0.27.16",
|
|
85
86
|
"@tiptap/core": "^3.13.0",
|