@ctzhian/tiptap 1.12.24 → 1.13.1
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/Editor/demo.js +5 -2
- package/dist/EditorMarkdown/demo.js +4 -1
- package/dist/EditorMarkdown/index.d.ts +2 -0
- package/dist/EditorMarkdown/index.js +42 -12
- package/dist/component/CustomBubbleMenu/index.js +1 -1
- package/dist/component/Toolbar/EditorInsert/index.js +12 -1
- package/dist/contants/slash-commands.js +34 -31
- package/dist/extension/component/Flow/Edit.d.ts +10 -0
- package/dist/extension/component/Flow/Edit.js +97 -0
- package/dist/extension/component/Flow/Insert.d.ts +7 -0
- package/dist/extension/component/Flow/Insert.js +108 -0
- package/dist/extension/component/Flow/Readonly.d.ts +8 -0
- package/dist/extension/component/Flow/Readonly.js +65 -0
- package/dist/extension/component/Flow/index.d.ts +9 -0
- package/dist/extension/component/Flow/index.js +354 -0
- package/dist/extension/component/Flow/useMermaidRender.d.ts +16 -0
- package/dist/extension/component/Flow/useMermaidRender.js +138 -0
- package/dist/extension/component/Flow/utils.d.ts +9 -0
- package/dist/extension/component/Flow/utils.js +32 -0
- package/dist/extension/component/SlashCommandsList/index.js +1 -1
- package/dist/extension/component/UploadProgress/index.d.ts +1 -1
- package/dist/extension/index.js +8 -3
- package/dist/extension/node/CodeBlockLowlight.js +15 -0
- package/dist/extension/node/FileHandler.d.ts +1 -1
- package/dist/extension/node/Flow/index.d.ts +18 -0
- package/dist/extension/node/Flow/index.js +103 -0
- package/dist/extension/node/TableOfContents/index.d.ts +2 -7
- package/dist/extension/node/TableOfContents/index.js +5 -373
- package/dist/extension/node/index.d.ts +1 -0
- package/dist/extension/node/index.js +1 -0
- package/dist/hook/index.js +1 -1
- package/dist/util/index.d.ts +0 -1
- package/dist/util/index.js +0 -1
- package/package.json +34 -33
- package/dist/extension/node/TableOfContents/plugin.d.ts +0 -6
- package/dist/extension/node/TableOfContents/plugin.js +0 -58
- package/dist/extension/node/TableOfContents/type.d.ts +0 -45
- package/dist/extension/node/TableOfContents/type.js +0 -1
- package/dist/extension/node/TableOfContents/utils.d.ts +0 -6
- package/dist/extension/node/TableOfContents/utils.js +0 -70
- package/dist/util/migrateMathStrings.d.ts +0 -73
- package/dist/util/migrateMathStrings.js +0 -192
package/dist/Editor/demo.js
CHANGED
|
@@ -7,6 +7,9 @@ import { Box } from '@mui/material';
|
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import "../index.css";
|
|
9
9
|
var Reader = function Reader() {
|
|
10
|
+
var handleTocUpdate = function handleTocUpdate(toc) {
|
|
11
|
+
console.log('toc', toc);
|
|
12
|
+
};
|
|
10
13
|
var _useTiptap = useTiptap({
|
|
11
14
|
editable: true,
|
|
12
15
|
exclude: ['invisibleCharacters'],
|
|
@@ -90,7 +93,7 @@ var Reader = function Reader() {
|
|
|
90
93
|
}
|
|
91
94
|
return onAiWritingGetSuggestion;
|
|
92
95
|
}(),
|
|
93
|
-
|
|
96
|
+
onTocUpdate: handleTocUpdate,
|
|
94
97
|
// onMentionFilter: async ({ query }: { query: string }) => {
|
|
95
98
|
// return new Promise((resolve) => {
|
|
96
99
|
// resolve([
|
|
@@ -152,7 +155,7 @@ var Reader = function Reader() {
|
|
|
152
155
|
}
|
|
153
156
|
return onUpload;
|
|
154
157
|
}(),
|
|
155
|
-
content:
|
|
158
|
+
content: "<pre><code>$$ sflsa $$\n\n$fsjadl$</code></pre><p></p><p><span data-latex=\"x+y=1\" data-type=\"inline-math\"></span></p><div data-latex=\"ssss\" data-type=\"block-math\"></div><p></p><p>fadsjlfkas</p><div data-type=\"flow\" data-code=\"C4Context\n title System Context diagram for Internet Banking System\n Enterprise_Boundary(b0, "BankBoundary0") {\n Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.")\n Person(customerB, "Banking Customer B")\n Person_Ext(customerC, "Banking Customer C", "desc")\n\n Person(customerD, "Banking Customer D", "A customer of the bank, <br/> with personal bank accounts.")\n\n System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.")\n\n Enterprise_Boundary(b1, "BankBoundary") {\n SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")\n\n System_Boundary(b2, "BankBoundary2") {\n System(SystemA, "Banking System A")\n System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts. next line.")\n }\n\n System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.")\n SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.")\n\n Boundary(b3, "BankBoundary3", "boundary") {\n SystemQueue(SystemF, "Banking System F Queue", "A system of the bank.")\n SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.")\n }\n }\n }\n\n BiRel(customerA, SystemAA, "Uses")\n BiRel(SystemAA, SystemE, "Uses")\n Rel(SystemAA, SystemC, "Sends e-mails", "SMTP")\n Rel(SystemC, customerA, "Sends e-mails to")\" data-width=\"100%\" data-height=\"auto\"></div><p>fsajdlkfjadsl</p>"
|
|
156
159
|
}),
|
|
157
160
|
editor = _useTiptap.editor;
|
|
158
161
|
return /*#__PURE__*/React.createElement(EditorThemeProvider, {
|
|
@@ -13,7 +13,7 @@ import { Box } from '@mui/material';
|
|
|
13
13
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
14
14
|
import "../index.css";
|
|
15
15
|
var Reader = function Reader() {
|
|
16
|
-
var _useState = useState(''),
|
|
16
|
+
var _useState = useState(''),
|
|
17
17
|
_useState2 = _slicedToArray(_useState, 2),
|
|
18
18
|
mdContent = _useState2[0],
|
|
19
19
|
setMdContent = _useState2[1];
|
|
@@ -123,6 +123,9 @@ var Reader = function Reader() {
|
|
|
123
123
|
// contentType: 'markdown'
|
|
124
124
|
// }).run()
|
|
125
125
|
},
|
|
126
|
+
onTocUpdate: function onTocUpdate(toc) {
|
|
127
|
+
console.log('toc', toc);
|
|
128
|
+
},
|
|
126
129
|
content: mdContent
|
|
127
130
|
}),
|
|
128
131
|
editor = _useTiptap.editor;
|
|
@@ -37,6 +37,10 @@ var EditorMarkdown = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
37
37
|
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
38
38
|
_ref$splitMode = _ref.splitMode,
|
|
39
39
|
splitMode = _ref$splitMode === void 0 ? false : _ref$splitMode,
|
|
40
|
+
_ref$showAutocomplete = _ref.showAutocomplete,
|
|
41
|
+
showAutocomplete = _ref$showAutocomplete === void 0 ? true : _ref$showAutocomplete,
|
|
42
|
+
_ref$highlightActiveL = _ref.highlightActiveLine,
|
|
43
|
+
highlightActiveLine = _ref$highlightActiveL === void 0 ? true : _ref$highlightActiveL,
|
|
40
44
|
_ref$defaultDisplayMo = _ref.defaultDisplayMode,
|
|
41
45
|
defaultDisplayMode = _ref$defaultDisplayMo === void 0 ? 'edit' : _ref$defaultDisplayMo,
|
|
42
46
|
_ref$showToolbar = _ref.showToolbar,
|
|
@@ -57,14 +61,18 @@ var EditorMarkdown = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
57
61
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
58
62
|
loading = _useState6[0],
|
|
59
63
|
setLoading = _useState6[1];
|
|
60
|
-
var _useState7 = useState(
|
|
64
|
+
var _useState7 = useState(false),
|
|
61
65
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var _useState9 = useState(
|
|
66
|
+
isComposing = _useState8[0],
|
|
67
|
+
setIsComposing = _useState8[1];
|
|
68
|
+
var _useState9 = useState(0),
|
|
65
69
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
progress = _useState10[0],
|
|
71
|
+
setProgress = _useState10[1];
|
|
72
|
+
var _useState11 = useState(''),
|
|
73
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
74
|
+
fileName = _useState12[0],
|
|
75
|
+
setFileName = _useState12[1];
|
|
68
76
|
var EditorHeight = useMemo(function () {
|
|
69
77
|
return isExpend ? 'calc(100vh - 45px)' : height;
|
|
70
78
|
}, [isExpend, height]);
|
|
@@ -357,6 +365,25 @@ var EditorMarkdown = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
357
365
|
editor.setEditable(false);
|
|
358
366
|
}
|
|
359
367
|
}, [editor]);
|
|
368
|
+
useEffect(function () {
|
|
369
|
+
var _aceEditor$textInput;
|
|
370
|
+
if (!aceEditorRef.current) return;
|
|
371
|
+
var aceEditor = aceEditorRef.current.editor;
|
|
372
|
+
var textarea = (_aceEditor$textInput = aceEditor.textInput) === null || _aceEditor$textInput === void 0 ? void 0 : _aceEditor$textInput.getElement();
|
|
373
|
+
if (!textarea) return;
|
|
374
|
+
var handleCompositionStart = function handleCompositionStart() {
|
|
375
|
+
setIsComposing(true);
|
|
376
|
+
};
|
|
377
|
+
var handleCompositionEnd = function handleCompositionEnd() {
|
|
378
|
+
setIsComposing(false);
|
|
379
|
+
};
|
|
380
|
+
textarea.addEventListener('compositionstart', handleCompositionStart);
|
|
381
|
+
textarea.addEventListener('compositionend', handleCompositionEnd);
|
|
382
|
+
return function () {
|
|
383
|
+
textarea.removeEventListener('compositionstart', handleCompositionStart);
|
|
384
|
+
textarea.removeEventListener('compositionend', handleCompositionEnd);
|
|
385
|
+
};
|
|
386
|
+
}, [displayMode]);
|
|
360
387
|
return /*#__PURE__*/React.createElement(Box, {
|
|
361
388
|
sx: _objectSpread({
|
|
362
389
|
position: 'relative',
|
|
@@ -472,14 +499,15 @@ var EditorMarkdown = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
472
499
|
onDrop: handleDrop,
|
|
473
500
|
sx: {
|
|
474
501
|
flex: 1,
|
|
475
|
-
|
|
476
|
-
'.ace_placeholder': {
|
|
502
|
+
'.ace_placeholder': _objectSpread({
|
|
477
503
|
transform: 'scale(1)',
|
|
478
504
|
height: '100%',
|
|
479
505
|
overflow: 'auto',
|
|
480
506
|
width: '100%',
|
|
481
507
|
fontStyle: 'normal'
|
|
482
|
-
}
|
|
508
|
+
}, isComposing && {
|
|
509
|
+
display: 'none'
|
|
510
|
+
})
|
|
483
511
|
}
|
|
484
512
|
}, /*#__PURE__*/React.createElement(AceEditor, {
|
|
485
513
|
ref: aceEditorRef,
|
|
@@ -497,10 +525,12 @@ var EditorMarkdown = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
497
525
|
$blockScrolling: true
|
|
498
526
|
},
|
|
499
527
|
setOptions: {
|
|
500
|
-
|
|
501
|
-
|
|
528
|
+
tabSize: 2,
|
|
529
|
+
showGutter: showLineNumbers,
|
|
502
530
|
showLineNumbers: showLineNumbers,
|
|
503
|
-
|
|
531
|
+
enableBasicAutocompletion: showAutocomplete,
|
|
532
|
+
enableLiveAutocompletion: showAutocomplete,
|
|
533
|
+
highlightActiveLine: highlightActiveLine
|
|
504
534
|
},
|
|
505
535
|
style: {
|
|
506
536
|
width: '100%',
|
|
@@ -84,7 +84,7 @@ var CustomBubbleMenu = function CustomBubbleMenu(_ref) {
|
|
|
84
84
|
// return cellSelection.$anchorCell.pos !== cellSelection.$headCell.pos;
|
|
85
85
|
// }
|
|
86
86
|
// }
|
|
87
|
-
if (editor.state.selection.empty || 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')) {
|
|
87
|
+
if (editor.state.selection.empty || 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')) {
|
|
88
88
|
return false;
|
|
89
89
|
}
|
|
90
90
|
return true;
|
|
@@ -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, CheckboxCircleFillIcon, CloseCircleFillIcon, CodeBoxLineIcon, CodeLineIcon, CodeSSlashLineIcon, DoubleQuotesLIcon, EmotionLineIcon, ErrorWarningFillIcon, FormulaIcon, FunctionsIcon, ImageLineIcon, Information2FillIcon, Information2LineIcon, MenuFold2FillIcon, MovieLineIcon, Music2LineIcon, SeparatorIcon, SquareRootIcon, Table2Icon, UserSmileFillIcon, WindowFillIcon } from "../../Icons";
|
|
4
|
+
import { AddCircleFillIcon, ArrowDownSLineIcon, AttachmentLineIcon, CheckboxCircleFillIcon, CloseCircleFillIcon, CodeBoxLineIcon, CodeLineIcon, CodeSSlashLineIcon, DoubleQuotesLIcon, EmotionLineIcon, ErrorWarningFillIcon, FlowChartIcon, FormulaIcon, FunctionsIcon, ImageLineIcon, Information2FillIcon, Information2LineIcon, MenuFold2FillIcon, MovieLineIcon, Music2LineIcon, SeparatorIcon, SquareRootIcon, Table2Icon, UserSmileFillIcon, WindowFillIcon } from "../../Icons";
|
|
5
5
|
import Menu from "../../Menu";
|
|
6
6
|
import ToolbarItem from "../Item";
|
|
7
7
|
import TableSizePicker from "../TableSizePicker";
|
|
@@ -145,6 +145,17 @@ var EditorInsert = function EditorInsert(_ref) {
|
|
|
145
145
|
size: '0'
|
|
146
146
|
});
|
|
147
147
|
}
|
|
148
|
+
}, {
|
|
149
|
+
label: '流程图',
|
|
150
|
+
key: 'flow',
|
|
151
|
+
icon: /*#__PURE__*/React.createElement(FlowChartIcon, {
|
|
152
|
+
sx: {
|
|
153
|
+
fontSize: '1rem'
|
|
154
|
+
}
|
|
155
|
+
}),
|
|
156
|
+
onClick: function onClick() {
|
|
157
|
+
return editor.commands.setFlow({});
|
|
158
|
+
}
|
|
148
159
|
}, {
|
|
149
160
|
label: '表格',
|
|
150
161
|
key: 'table',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { AttachmentLineIcon, CodeBoxLineIcon, CodeLineIcon, DoubleQuotesLIcon, EmotionLineIcon, FunctionsIcon, H1Icon, H2Icon, H3Icon, H4Icon, H5Icon, H6Icon, ImageLineIcon, Information2LineIcon, LinkIcon, ListCheck2Icon, ListOrdered2Icon, ListUnorderedIcon, MenuFold2FillIcon, MovieLineIcon, Music2LineIcon, SeparatorIcon, SquareRootIcon, Table2Icon,
|
|
2
|
+
import { AttachmentLineIcon, CodeBoxLineIcon, CodeLineIcon, DoubleQuotesLIcon, EmotionLineIcon, FlowChartIcon, FunctionsIcon, H1Icon, H2Icon, H3Icon, H4Icon, H5Icon, H6Icon, ImageLineIcon, Information2LineIcon, LinkIcon, ListCheck2Icon, ListOrdered2Icon, ListUnorderedIcon, MenuFold2FillIcon, MovieLineIcon, Music2LineIcon, SeparatorIcon, SquareRootIcon, Table2Icon, WindowFillIcon } from "../component/Icons";
|
|
3
3
|
export var slashCommands = [{
|
|
4
4
|
title: '标题1',
|
|
5
5
|
shortcutKey: ['ctrl', 'alt', '1'],
|
|
@@ -130,8 +130,8 @@ export var slashCommands = [{
|
|
|
130
130
|
editor.chain().focus().deleteRange(range).toggleTaskList().run();
|
|
131
131
|
}
|
|
132
132
|
}, {
|
|
133
|
-
title: '
|
|
134
|
-
icon: /*#__PURE__*/React.createElement(
|
|
133
|
+
title: '表情',
|
|
134
|
+
icon: /*#__PURE__*/React.createElement(EmotionLineIcon, {
|
|
135
135
|
sx: {
|
|
136
136
|
fontSize: '1rem'
|
|
137
137
|
}
|
|
@@ -139,18 +139,6 @@ export var slashCommands = [{
|
|
|
139
139
|
command: function command(_ref10) {
|
|
140
140
|
var editor = _ref10.editor,
|
|
141
141
|
range = _ref10.range;
|
|
142
|
-
editor.chain().focus().deleteRange(range).insertContent('<br />').run();
|
|
143
|
-
}
|
|
144
|
-
}, {
|
|
145
|
-
title: '表情',
|
|
146
|
-
icon: /*#__PURE__*/React.createElement(EmotionLineIcon, {
|
|
147
|
-
sx: {
|
|
148
|
-
fontSize: '1rem'
|
|
149
|
-
}
|
|
150
|
-
}),
|
|
151
|
-
command: function command(_ref11) {
|
|
152
|
-
var editor = _ref11.editor,
|
|
153
|
-
range = _ref11.range;
|
|
154
142
|
editor.chain().deleteRange(range).insertContentAt(range.from, ' : ').focus(range.from + 2).run();
|
|
155
143
|
}
|
|
156
144
|
}, {
|
|
@@ -160,9 +148,9 @@ export var slashCommands = [{
|
|
|
160
148
|
fontSize: '1rem'
|
|
161
149
|
}
|
|
162
150
|
}),
|
|
163
|
-
command: function command(
|
|
164
|
-
var editor =
|
|
165
|
-
range =
|
|
151
|
+
command: function command(_ref11) {
|
|
152
|
+
var editor = _ref11.editor,
|
|
153
|
+
range = _ref11.range;
|
|
166
154
|
editor.chain().focus().deleteRange(range).setHorizontalRule().run();
|
|
167
155
|
}
|
|
168
156
|
}, {
|
|
@@ -173,9 +161,9 @@ export var slashCommands = [{
|
|
|
173
161
|
fontSize: '1rem'
|
|
174
162
|
}
|
|
175
163
|
}),
|
|
176
|
-
command: function command(
|
|
177
|
-
var editor =
|
|
178
|
-
range =
|
|
164
|
+
command: function command(_ref12) {
|
|
165
|
+
var editor = _ref12.editor,
|
|
166
|
+
range = _ref12.range;
|
|
179
167
|
editor.chain().focus().deleteRange(range).toggleBlockquote().run();
|
|
180
168
|
}
|
|
181
169
|
}, {
|
|
@@ -186,9 +174,9 @@ export var slashCommands = [{
|
|
|
186
174
|
fontSize: '1rem'
|
|
187
175
|
}
|
|
188
176
|
}),
|
|
189
|
-
command: function command(
|
|
190
|
-
var editor =
|
|
191
|
-
range =
|
|
177
|
+
command: function command(_ref13) {
|
|
178
|
+
var editor = _ref13.editor,
|
|
179
|
+
range = _ref13.range;
|
|
192
180
|
editor.chain().focus().deleteRange(range).setMark('code').run();
|
|
193
181
|
}
|
|
194
182
|
}, {
|
|
@@ -199,9 +187,9 @@ export var slashCommands = [{
|
|
|
199
187
|
fontSize: '1rem'
|
|
200
188
|
}
|
|
201
189
|
}),
|
|
202
|
-
command: function command(
|
|
203
|
-
var editor =
|
|
204
|
-
range =
|
|
190
|
+
command: function command(_ref14) {
|
|
191
|
+
var editor = _ref14.editor,
|
|
192
|
+
range = _ref14.range;
|
|
205
193
|
editor.chain().focus().deleteRange(range).toggleCodeBlock().run();
|
|
206
194
|
}
|
|
207
195
|
}, {
|
|
@@ -212,9 +200,9 @@ export var slashCommands = [{
|
|
|
212
200
|
fontSize: '1rem'
|
|
213
201
|
}
|
|
214
202
|
}),
|
|
215
|
-
command: function command(
|
|
216
|
-
var editor =
|
|
217
|
-
range =
|
|
203
|
+
command: function command(_ref15) {
|
|
204
|
+
var editor = _ref15.editor,
|
|
205
|
+
range = _ref15.range;
|
|
218
206
|
editor.chain().focus().deleteRange(range).setInlineLink({
|
|
219
207
|
href: ''
|
|
220
208
|
}).run();
|
|
@@ -227,10 +215,25 @@ export var slashCommands = [{
|
|
|
227
215
|
fontSize: '1rem'
|
|
228
216
|
}
|
|
229
217
|
}),
|
|
218
|
+
command: function command(_ref16) {
|
|
219
|
+
var editor = _ref16.editor,
|
|
220
|
+
range = _ref16.range;
|
|
221
|
+
editor.chain().focus().deleteRange(range).setDetails().run();
|
|
222
|
+
}
|
|
223
|
+
}, {
|
|
224
|
+
title: '流程图',
|
|
225
|
+
icon: /*#__PURE__*/React.createElement(FlowChartIcon, {
|
|
226
|
+
sx: {
|
|
227
|
+
fontSize: '1rem'
|
|
228
|
+
}
|
|
229
|
+
}),
|
|
230
230
|
command: function command(_ref17) {
|
|
231
231
|
var editor = _ref17.editor,
|
|
232
232
|
range = _ref17.range;
|
|
233
|
-
editor.chain().focus().deleteRange(range).
|
|
233
|
+
editor.chain().focus().deleteRange(range).setFlow({
|
|
234
|
+
code: '',
|
|
235
|
+
width: '100%'
|
|
236
|
+
}).run();
|
|
234
237
|
}
|
|
235
238
|
}, {
|
|
236
239
|
title: 'iframe',
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FlowAttributes } from ".";
|
|
3
|
+
type EditFlowProps = {
|
|
4
|
+
anchorEl: HTMLDivElement | null;
|
|
5
|
+
attrs: FlowAttributes;
|
|
6
|
+
updateAttributes: (attrs: FlowAttributes) => void;
|
|
7
|
+
onCancel: () => void;
|
|
8
|
+
};
|
|
9
|
+
declare const EditFlow: ({ anchorEl, attrs, updateAttributes, onCancel, }: EditFlowProps) => React.JSX.Element;
|
|
10
|
+
export default EditFlow;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
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); }
|
|
4
|
+
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; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { FloatingPopover } from "../../../component/FloatingPopover";
|
|
8
|
+
import { Button, Stack, TextField } from "@mui/material";
|
|
9
|
+
import React, { useEffect, useMemo, useState } from "react";
|
|
10
|
+
var EditFlow = function EditFlow(_ref) {
|
|
11
|
+
var anchorEl = _ref.anchorEl,
|
|
12
|
+
attrs = _ref.attrs,
|
|
13
|
+
updateAttributes = _ref.updateAttributes,
|
|
14
|
+
onCancel = _ref.onCancel;
|
|
15
|
+
var _useState = useState(attrs.code || ''),
|
|
16
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
17
|
+
editCode = _useState2[0],
|
|
18
|
+
setEditCode = _useState2[1];
|
|
19
|
+
|
|
20
|
+
// 当 attrs.code 更新时,同步更新 editCode
|
|
21
|
+
useEffect(function () {
|
|
22
|
+
setEditCode(attrs.code || '');
|
|
23
|
+
}, [attrs.code]);
|
|
24
|
+
|
|
25
|
+
// 创建虚拟元素,表示 flow-wrapper 的中心点
|
|
26
|
+
var centerVirtualElement = useMemo(function () {
|
|
27
|
+
if (!anchorEl) return null;
|
|
28
|
+
return {
|
|
29
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
30
|
+
// 每次调用时重新计算,确保位置实时更新
|
|
31
|
+
var rect = anchorEl.getBoundingClientRect();
|
|
32
|
+
var centerX = rect.left + rect.width / 2;
|
|
33
|
+
var centerY = rect.top + rect.height / 2;
|
|
34
|
+
return {
|
|
35
|
+
width: 0,
|
|
36
|
+
height: 0,
|
|
37
|
+
x: centerX,
|
|
38
|
+
y: centerY,
|
|
39
|
+
top: centerY,
|
|
40
|
+
left: centerX,
|
|
41
|
+
right: centerX,
|
|
42
|
+
bottom: centerY
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}, [anchorEl]);
|
|
47
|
+
var handleSaveFlow = function handleSaveFlow() {
|
|
48
|
+
var trimmedCode = editCode.trim();
|
|
49
|
+
if (!trimmedCode) return;
|
|
50
|
+
updateAttributes({
|
|
51
|
+
code: trimmedCode
|
|
52
|
+
});
|
|
53
|
+
onCancel();
|
|
54
|
+
};
|
|
55
|
+
return /*#__PURE__*/React.createElement(FloatingPopover, {
|
|
56
|
+
open: true,
|
|
57
|
+
anchorEl: centerVirtualElement,
|
|
58
|
+
onClose: onCancel,
|
|
59
|
+
placement: "top",
|
|
60
|
+
style: {
|
|
61
|
+
transform: 'translate(-50%, 0)'
|
|
62
|
+
}
|
|
63
|
+
}, /*#__PURE__*/React.createElement(Stack, {
|
|
64
|
+
gap: 2,
|
|
65
|
+
sx: {
|
|
66
|
+
p: 2,
|
|
67
|
+
width: 600
|
|
68
|
+
}
|
|
69
|
+
}, /*#__PURE__*/React.createElement(TextField, {
|
|
70
|
+
fullWidth: true,
|
|
71
|
+
multiline: true,
|
|
72
|
+
rows: 12,
|
|
73
|
+
value: editCode,
|
|
74
|
+
onChange: function onChange(e) {
|
|
75
|
+
return setEditCode(e.target.value);
|
|
76
|
+
},
|
|
77
|
+
placeholder: "\u8F93\u5165 Mermaid \u6D41\u7A0B\u56FE\u4EE3\u7801",
|
|
78
|
+
sx: {
|
|
79
|
+
'& .MuiInputBase-input': {
|
|
80
|
+
fontFamily: 'monospace',
|
|
81
|
+
fontSize: '0.875rem'
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}), /*#__PURE__*/React.createElement(Stack, {
|
|
85
|
+
direction: "row",
|
|
86
|
+
gap: 1
|
|
87
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
88
|
+
variant: "outlined",
|
|
89
|
+
fullWidth: true,
|
|
90
|
+
onClick: onCancel
|
|
91
|
+
}, "\u53D6\u6D88"), /*#__PURE__*/React.createElement(Button, {
|
|
92
|
+
variant: "contained",
|
|
93
|
+
fullWidth: true,
|
|
94
|
+
onClick: handleSaveFlow
|
|
95
|
+
}, "\u4FDD\u5B58"))));
|
|
96
|
+
};
|
|
97
|
+
export default EditFlow;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FlowAttributes } from ".";
|
|
3
|
+
type InsertFlowProps = {
|
|
4
|
+
updateAttributes: (attrs: FlowAttributes) => void;
|
|
5
|
+
};
|
|
6
|
+
declare const InsertFlow: ({ updateAttributes, }: InsertFlowProps) => React.JSX.Element;
|
|
7
|
+
export default InsertFlow;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
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); }
|
|
4
|
+
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; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { FloatingPopover } from "../../../component/FloatingPopover";
|
|
8
|
+
import { FlowChartIcon } from "../../../component/Icons";
|
|
9
|
+
import { Box, Button, Stack, TextField } from "@mui/material";
|
|
10
|
+
import { NodeViewWrapper } from "@tiptap/react";
|
|
11
|
+
import React, { useState } from "react";
|
|
12
|
+
var InsertFlow = function InsertFlow(_ref) {
|
|
13
|
+
var updateAttributes = _ref.updateAttributes;
|
|
14
|
+
var _useState = useState(''),
|
|
15
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
16
|
+
editCode = _useState2[0],
|
|
17
|
+
setEditCode = _useState2[1];
|
|
18
|
+
var _useState3 = useState(null),
|
|
19
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
20
|
+
anchorEl = _useState4[0],
|
|
21
|
+
setAnchorEl = _useState4[1];
|
|
22
|
+
var handleShowPopover = function handleShowPopover(event) {
|
|
23
|
+
return setAnchorEl(event.currentTarget);
|
|
24
|
+
};
|
|
25
|
+
var handleClosePopover = function handleClosePopover() {
|
|
26
|
+
return setAnchorEl(null);
|
|
27
|
+
};
|
|
28
|
+
var handleInsertFlow = function handleInsertFlow() {
|
|
29
|
+
var trimmedCode = editCode.trim();
|
|
30
|
+
if (!trimmedCode) return;
|
|
31
|
+
updateAttributes({
|
|
32
|
+
code: trimmedCode,
|
|
33
|
+
width: '100%'
|
|
34
|
+
});
|
|
35
|
+
handleClosePopover();
|
|
36
|
+
};
|
|
37
|
+
return /*#__PURE__*/React.createElement(NodeViewWrapper, {
|
|
38
|
+
className: "flow-wrapper",
|
|
39
|
+
"data-drag-handle": true
|
|
40
|
+
}, /*#__PURE__*/React.createElement(Stack, {
|
|
41
|
+
direction: 'row',
|
|
42
|
+
alignItems: 'center',
|
|
43
|
+
gap: 2,
|
|
44
|
+
onClick: handleShowPopover,
|
|
45
|
+
sx: {
|
|
46
|
+
border: '1px dashed',
|
|
47
|
+
borderColor: 'divider',
|
|
48
|
+
borderRadius: 'var(--mui-shape-borderRadius)',
|
|
49
|
+
px: 2,
|
|
50
|
+
py: 1.5,
|
|
51
|
+
minWidth: 200,
|
|
52
|
+
textAlign: 'center',
|
|
53
|
+
color: 'text.secondary',
|
|
54
|
+
bgcolor: 'action.default',
|
|
55
|
+
cursor: 'pointer',
|
|
56
|
+
'&:hover': {
|
|
57
|
+
bgcolor: 'action.hover'
|
|
58
|
+
},
|
|
59
|
+
'&:active': {
|
|
60
|
+
bgcolor: 'action.selected'
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}, /*#__PURE__*/React.createElement(FlowChartIcon, {
|
|
64
|
+
sx: {
|
|
65
|
+
fontSize: '1rem',
|
|
66
|
+
position: 'relative',
|
|
67
|
+
flexShrink: 0
|
|
68
|
+
}
|
|
69
|
+
}), /*#__PURE__*/React.createElement(Box, {
|
|
70
|
+
sx: {
|
|
71
|
+
fontSize: '0.875rem',
|
|
72
|
+
position: 'relative',
|
|
73
|
+
flexGrow: 1,
|
|
74
|
+
textAlign: 'left'
|
|
75
|
+
}
|
|
76
|
+
}, "\u70B9\u51FB\u6B64\u5904\u5D4C\u5165\u6216\u7C98\u8D34\u6D41\u7A0B\u56FE\u4EE3\u7801")), /*#__PURE__*/React.createElement(FloatingPopover, {
|
|
77
|
+
open: Boolean(anchorEl),
|
|
78
|
+
anchorEl: anchorEl,
|
|
79
|
+
onClose: handleClosePopover,
|
|
80
|
+
placement: "bottom"
|
|
81
|
+
}, /*#__PURE__*/React.createElement(Stack, {
|
|
82
|
+
gap: 2,
|
|
83
|
+
sx: {
|
|
84
|
+
p: 2,
|
|
85
|
+
width: 600
|
|
86
|
+
}
|
|
87
|
+
}, /*#__PURE__*/React.createElement(TextField, {
|
|
88
|
+
fullWidth: true,
|
|
89
|
+
multiline: true,
|
|
90
|
+
rows: 12,
|
|
91
|
+
value: editCode,
|
|
92
|
+
onChange: function onChange(e) {
|
|
93
|
+
return setEditCode(e.target.value);
|
|
94
|
+
},
|
|
95
|
+
placeholder: "\u8F93\u5165 Mermaid \u6D41\u7A0B\u56FE\u4EE3\u7801",
|
|
96
|
+
sx: {
|
|
97
|
+
'& .MuiInputBase-input': {
|
|
98
|
+
fontFamily: 'monospace',
|
|
99
|
+
fontSize: '0.875rem'
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}), /*#__PURE__*/React.createElement(Button, {
|
|
103
|
+
variant: "contained",
|
|
104
|
+
fullWidth: true,
|
|
105
|
+
onClick: handleInsertFlow
|
|
106
|
+
}, "\u63D0\u4EA4"))));
|
|
107
|
+
};
|
|
108
|
+
export default InsertFlow;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FlowAttributes } from ".";
|
|
3
|
+
interface ReadonlyFlowProps {
|
|
4
|
+
attrs: FlowAttributes;
|
|
5
|
+
onError?: (error: Error) => void;
|
|
6
|
+
}
|
|
7
|
+
declare const ReadonlyFlow: ({ attrs, onError }: ReadonlyFlowProps) => React.JSX.Element | null;
|
|
8
|
+
export default ReadonlyFlow;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Box } from "@mui/material";
|
|
2
|
+
import { NodeViewWrapper } from "@tiptap/react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { useMermaidRender } from "./useMermaidRender";
|
|
5
|
+
var ReadonlyFlow = function ReadonlyFlow(_ref) {
|
|
6
|
+
var attrs = _ref.attrs,
|
|
7
|
+
onError = _ref.onError;
|
|
8
|
+
var _useMermaidRender = useMermaidRender({
|
|
9
|
+
code: attrs.code,
|
|
10
|
+
onError: onError,
|
|
11
|
+
showLoading: false,
|
|
12
|
+
idPrefix: 'mermaid-readonly'
|
|
13
|
+
}),
|
|
14
|
+
svgContent = _useMermaidRender.svgContent,
|
|
15
|
+
error = _useMermaidRender.error;
|
|
16
|
+
if (!attrs.code || attrs.code.trim() === '') {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return /*#__PURE__*/React.createElement(NodeViewWrapper, {
|
|
20
|
+
className: "flow-wrapper"
|
|
21
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
22
|
+
sx: {
|
|
23
|
+
position: 'relative',
|
|
24
|
+
display: 'inline-block',
|
|
25
|
+
border: '1px solid',
|
|
26
|
+
borderColor: 'divider',
|
|
27
|
+
borderRadius: 'var(--mui-shape-borderRadius)',
|
|
28
|
+
width: attrs.width || '100%',
|
|
29
|
+
height: 'auto'
|
|
30
|
+
}
|
|
31
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
32
|
+
sx: {
|
|
33
|
+
width: '100%',
|
|
34
|
+
height: '100%',
|
|
35
|
+
minHeight: '200px',
|
|
36
|
+
display: 'flex',
|
|
37
|
+
alignItems: 'center',
|
|
38
|
+
justifyContent: 'center',
|
|
39
|
+
bgcolor: 'background.default',
|
|
40
|
+
borderRadius: 'var(--mui-shape-borderRadius)'
|
|
41
|
+
}
|
|
42
|
+
}, error && /*#__PURE__*/React.createElement(Box, {
|
|
43
|
+
sx: {
|
|
44
|
+
color: 'error.main',
|
|
45
|
+
padding: '20px',
|
|
46
|
+
textAlign: 'center',
|
|
47
|
+
fontSize: '14px'
|
|
48
|
+
}
|
|
49
|
+
}, error), svgContent && !error && /*#__PURE__*/React.createElement(Box, {
|
|
50
|
+
dangerouslySetInnerHTML: {
|
|
51
|
+
__html: svgContent
|
|
52
|
+
},
|
|
53
|
+
sx: {
|
|
54
|
+
width: '100%',
|
|
55
|
+
display: 'flex',
|
|
56
|
+
alignItems: 'center',
|
|
57
|
+
justifyContent: 'center',
|
|
58
|
+
'& svg': {
|
|
59
|
+
maxWidth: '100%',
|
|
60
|
+
height: 'auto'
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}))));
|
|
64
|
+
};
|
|
65
|
+
export default ReadonlyFlow;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EditorFnProps } from "../../../type";
|
|
2
|
+
import { NodeViewProps } from '@tiptap/react';
|
|
3
|
+
import React from "react";
|
|
4
|
+
export interface FlowAttributes {
|
|
5
|
+
code: string;
|
|
6
|
+
width?: string | number;
|
|
7
|
+
}
|
|
8
|
+
declare const FlowViewWrapper: React.FC<NodeViewProps & EditorFnProps>;
|
|
9
|
+
export default FlowViewWrapper;
|