@ctzhian/tiptap 1.2.0 → 1.3.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/Editor/demo.js +1 -1
- package/dist/component/CustomBubbleMenu/SelectionText.js +6 -13
- package/dist/component/CustomDragHandle/index.js +99 -30
- package/dist/component/Icons/index.d.ts +1 -0
- package/dist/component/Icons/index.js +2 -1
- package/dist/component/Icons/window-fill-icon.d.ts +6 -0
- package/dist/component/Icons/window-fill-icon.js +13 -0
- package/dist/contants/enums.d.ts +1 -0
- package/dist/contants/enums.js +4 -1
- package/dist/contants/slash-commands.js +29 -29
- package/dist/extension/component/Iframe/Insert.d.ts +14 -0
- package/dist/extension/component/Iframe/Insert.js +112 -0
- package/dist/extension/component/Iframe/Readonly.d.ts +10 -0
- package/dist/extension/component/Iframe/Readonly.js +14 -0
- package/dist/extension/component/Iframe/index.d.ts +5 -0
- package/dist/extension/component/Iframe/index.js +290 -0
- package/dist/extension/component/SlashCommandsList/index.js +1 -3
- package/dist/extension/index.js +3 -1
- package/dist/extension/node/FileHandler.d.ts +1 -1
- package/dist/extension/node/Iframe.d.ts +16 -0
- package/dist/extension/node/Iframe.js +118 -0
- package/dist/extension/node/index.d.ts +1 -0
- package/dist/extension/node/index.js +1 -0
- package/dist/extension/suggestion/slash.js +0 -1
- package/dist/index.css +1 -1
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +1 -0
- package/dist/util/linewiseConvert.d.ts +42 -0
- package/dist/util/linewiseConvert.js +170 -0
- package/package.json +1 -1
package/dist/Editor/demo.js
CHANGED
|
@@ -81,7 +81,7 @@ var Reader = function Reader() {
|
|
|
81
81
|
}
|
|
82
82
|
return onUpload;
|
|
83
83
|
}(),
|
|
84
|
-
content: "<
|
|
84
|
+
content: "<iframe class=\"iframe-wrapper\" width=\"760\" height=\"400\" src=\"https://bbs.chaitin.cn/user/signin?ref=%2F\" frameborder=\"0\" allowfullscreen=\"true\"></iframe><p></p>"
|
|
85
85
|
}),
|
|
86
86
|
editor = _useTiptap.editor;
|
|
87
87
|
return /*#__PURE__*/React.createElement(EditorThemeProvider, {
|
|
@@ -15,11 +15,7 @@ var SelectionText = function SelectionText(_ref) {
|
|
|
15
15
|
var theme = useTheme();
|
|
16
16
|
var THEME_TEXT_COLOR = [theme.palette.primary.main, theme.palette.success.main, theme.palette.warning.main, theme.palette.error.main, '#D8A47F', '#73B5F0', '#CDDFA0', theme.palette.text.primary, theme.palette.text.secondary, theme.palette.text.disabled, theme.palette.common.white];
|
|
17
17
|
var THEME_TEXT_BG_COLOR = ['#e7bdff', '#FFE0B2', '#F8BBD0', '#FFCDD2', '#FFECB3', '#FFCCBC', '#B3E5FC', '#C8E6C9', '#B2EBF2', '#BBDEFB', '#DCEDC8'];
|
|
18
|
-
var _useState = useState(
|
|
19
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
20
|
-
hideColor = _useState2[0],
|
|
21
|
-
setHideColor = _useState2[1];
|
|
22
|
-
var _useState3 = useState({
|
|
18
|
+
var _useState = useState({
|
|
23
19
|
quote: false,
|
|
24
20
|
bold: false,
|
|
25
21
|
italic: false,
|
|
@@ -29,11 +25,9 @@ var SelectionText = function SelectionText(_ref) {
|
|
|
29
25
|
superscript: false,
|
|
30
26
|
subscript: false
|
|
31
27
|
}),
|
|
32
|
-
|
|
33
|
-
active =
|
|
34
|
-
setActive =
|
|
35
|
-
// const [showColorPicker, setShowColorPicker] = useState(false)
|
|
36
|
-
|
|
28
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
29
|
+
active = _useState2[0],
|
|
30
|
+
setActive = _useState2[1];
|
|
37
31
|
var updateSelection = function updateSelection() {
|
|
38
32
|
setActive({
|
|
39
33
|
quote: editor.isActive('blockquote'),
|
|
@@ -45,7 +39,6 @@ var SelectionText = function SelectionText(_ref) {
|
|
|
45
39
|
superscript: editor.isActive('superscript'),
|
|
46
40
|
subscript: editor.isActive('subscript')
|
|
47
41
|
});
|
|
48
|
-
setHideColor(editor.isActive('codeBlock') || editor.isActive('inlineMath') || editor.isActive('blockMath'));
|
|
49
42
|
};
|
|
50
43
|
useEffect(function () {
|
|
51
44
|
editor.on('selectionUpdate', updateSelection);
|
|
@@ -55,7 +48,7 @@ var SelectionText = function SelectionText(_ref) {
|
|
|
55
48
|
editor.off('transaction', updateSelection);
|
|
56
49
|
};
|
|
57
50
|
}, [editor]);
|
|
58
|
-
if (!editor.isEditable
|
|
51
|
+
if (!editor.isEditable) {
|
|
59
52
|
return null;
|
|
60
53
|
}
|
|
61
54
|
return /*#__PURE__*/React.createElement(BubbleMenu, {
|
|
@@ -69,7 +62,7 @@ var SelectionText = function SelectionText(_ref) {
|
|
|
69
62
|
var editorProps = _ref2.editor,
|
|
70
63
|
from = _ref2.from,
|
|
71
64
|
to = _ref2.to;
|
|
72
|
-
if (editorProps.state.selection.empty || editorProps.isActive('image') || editorProps.isActive('video') || editorProps.isActive('audio') || editorProps.isActive('emoji') || editorProps.isActive('codeBlock') || editorProps.isActive('blockLink') || editorProps.isActive('inlineLink') || editorProps.isActive('blockAttachment') || editorProps.isActive('inlineAttachment')) {
|
|
65
|
+
if (editorProps.state.selection.empty || editorProps.isActive('image') || editorProps.isActive('video') || editorProps.isActive('audio') || editorProps.isActive('emoji') || editorProps.isActive('codeBlock') || editorProps.isActive('blockMath') || editorProps.isActive('inlineMath') || editorProps.isActive('blockLink') || editorProps.isActive('inlineLink') || editorProps.isActive('blockAttachment') || editorProps.isActive('inlineAttachment') || editorProps.isActive('horizontalRule') || editorProps.isActive('iframe')) {
|
|
73
66
|
return false;
|
|
74
67
|
}
|
|
75
68
|
return true;
|
|
@@ -17,9 +17,9 @@ import { NODE_TYPE_LABEL, NodeTypeEnum } from "../../contants/enums";
|
|
|
17
17
|
import { Box, Divider, Stack, Typography, useTheme } from '@mui/material';
|
|
18
18
|
import DragHandle from '@tiptap/extension-drag-handle-react';
|
|
19
19
|
import { Fragment, Slice } from '@tiptap/pm/model';
|
|
20
|
-
import {
|
|
20
|
+
import { NodeSelection } from '@tiptap/pm/state';
|
|
21
21
|
import React, { useCallback, useState } from 'react';
|
|
22
|
-
import { downloadFiles, filterResourcesByType, getAllResources } from "../../util";
|
|
22
|
+
import { convertNodeAt, downloadFiles, filterResourcesByType, getAllResources } from "../../util";
|
|
23
23
|
import { FileCopyLineIcon } from "../Icons/file-copy-line-icon";
|
|
24
24
|
import Menu from "../Menu";
|
|
25
25
|
import { ToolbarItem } from "../Toolbar";
|
|
@@ -178,10 +178,13 @@ var CustomDragHandle = function CustomDragHandle(_ref2) {
|
|
|
178
178
|
state = _current$editor.state,
|
|
179
179
|
view = _current$editor.view;
|
|
180
180
|
var tr = state.tr;
|
|
181
|
-
var
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
181
|
+
var pos = current.pos;
|
|
182
|
+
if (pos >= 0) {
|
|
183
|
+
var selection = NodeSelection.create(tr.doc, pos);
|
|
184
|
+
tr.setSelection(selection);
|
|
185
|
+
view.dispatch(tr);
|
|
186
|
+
view.focus();
|
|
187
|
+
}
|
|
185
188
|
};
|
|
186
189
|
var hasMarksDeep = function hasMarksDeep(node) {
|
|
187
190
|
var _content;
|
|
@@ -243,16 +246,6 @@ var CustomDragHandle = function CustomDragHandle(_ref2) {
|
|
|
243
246
|
vertical: 'top',
|
|
244
247
|
horizontal: 'left'
|
|
245
248
|
},
|
|
246
|
-
childrenProps: {
|
|
247
|
-
anchorOrigin: {
|
|
248
|
-
vertical: 'center',
|
|
249
|
-
horizontal: 'right'
|
|
250
|
-
},
|
|
251
|
-
transformOrigin: {
|
|
252
|
-
vertical: 'center',
|
|
253
|
-
horizontal: 'left'
|
|
254
|
-
}
|
|
255
|
-
},
|
|
256
249
|
arrowIcon: /*#__PURE__*/React.createElement(ArrowDownSLineIcon, {
|
|
257
250
|
sx: {
|
|
258
251
|
fontSize: '1rem',
|
|
@@ -272,7 +265,7 @@ var CustomDragHandle = function CustomDragHandle(_ref2) {
|
|
|
272
265
|
}].concat(_toConsumableArray(currentNode !== null && currentNode !== void 0 && currentNode.color ? [{
|
|
273
266
|
key: 'color',
|
|
274
267
|
label: '颜色',
|
|
275
|
-
maxHeight:
|
|
268
|
+
maxHeight: 400,
|
|
276
269
|
icon: /*#__PURE__*/React.createElement(BrushLineIcon, {
|
|
277
270
|
sx: {
|
|
278
271
|
fontSize: '1rem'
|
|
@@ -553,7 +546,14 @@ var CustomDragHandle = function CustomDragHandle(_ref2) {
|
|
|
553
546
|
}
|
|
554
547
|
}),
|
|
555
548
|
onClick: function onClick() {
|
|
556
|
-
if (current.node
|
|
549
|
+
if (!current.node) return;
|
|
550
|
+
var type = current.node.type.name;
|
|
551
|
+
var groupTypes = [NodeTypeEnum.BulletList, NodeTypeEnum.OrderedList, NodeTypeEnum.TaskList, NodeTypeEnum.Blockquote, NodeTypeEnum.CodeBlock, NodeTypeEnum.Alert];
|
|
552
|
+
if (groupTypes.includes(type)) {
|
|
553
|
+
convertNodeAt(current.editor, current.pos, current.node, {
|
|
554
|
+
type: 'paragraph'
|
|
555
|
+
});
|
|
556
|
+
} else {
|
|
557
557
|
selectCurrentNode();
|
|
558
558
|
cancelNodeType();
|
|
559
559
|
current.editor.commands.setParagraph();
|
|
@@ -569,7 +569,15 @@ var CustomDragHandle = function CustomDragHandle(_ref2) {
|
|
|
569
569
|
}
|
|
570
570
|
}),
|
|
571
571
|
onClick: function onClick() {
|
|
572
|
-
if (current.node
|
|
572
|
+
if (!current.node) return;
|
|
573
|
+
var type = current.node.type.name;
|
|
574
|
+
var groupTypes = [NodeTypeEnum.BulletList, NodeTypeEnum.OrderedList, NodeTypeEnum.TaskList, NodeTypeEnum.Blockquote, NodeTypeEnum.CodeBlock, NodeTypeEnum.Alert];
|
|
575
|
+
if (groupTypes.includes(type)) {
|
|
576
|
+
convertNodeAt(current.editor, current.pos, current.node, {
|
|
577
|
+
type: 'heading',
|
|
578
|
+
level: 1
|
|
579
|
+
});
|
|
580
|
+
} else {
|
|
573
581
|
selectCurrentNode();
|
|
574
582
|
cancelNodeType();
|
|
575
583
|
current.editor.commands.setHeading({
|
|
@@ -587,7 +595,15 @@ var CustomDragHandle = function CustomDragHandle(_ref2) {
|
|
|
587
595
|
}
|
|
588
596
|
}),
|
|
589
597
|
onClick: function onClick() {
|
|
590
|
-
if (current.node
|
|
598
|
+
if (!current.node) return;
|
|
599
|
+
var type = current.node.type.name;
|
|
600
|
+
var groupTypes = [NodeTypeEnum.BulletList, NodeTypeEnum.OrderedList, NodeTypeEnum.TaskList, NodeTypeEnum.Blockquote, NodeTypeEnum.CodeBlock, NodeTypeEnum.Alert];
|
|
601
|
+
if (groupTypes.includes(type)) {
|
|
602
|
+
convertNodeAt(current.editor, current.pos, current.node, {
|
|
603
|
+
type: 'heading',
|
|
604
|
+
level: 2
|
|
605
|
+
});
|
|
606
|
+
} else {
|
|
591
607
|
selectCurrentNode();
|
|
592
608
|
cancelNodeType();
|
|
593
609
|
current.editor.commands.setHeading({
|
|
@@ -605,7 +621,15 @@ var CustomDragHandle = function CustomDragHandle(_ref2) {
|
|
|
605
621
|
}
|
|
606
622
|
}),
|
|
607
623
|
onClick: function onClick() {
|
|
608
|
-
if (current.node
|
|
624
|
+
if (!current.node) return;
|
|
625
|
+
var type = current.node.type.name;
|
|
626
|
+
var groupTypes = [NodeTypeEnum.BulletList, NodeTypeEnum.OrderedList, NodeTypeEnum.TaskList, NodeTypeEnum.Blockquote, NodeTypeEnum.CodeBlock, NodeTypeEnum.Alert];
|
|
627
|
+
if (groupTypes.includes(type)) {
|
|
628
|
+
convertNodeAt(current.editor, current.pos, current.node, {
|
|
629
|
+
type: 'heading',
|
|
630
|
+
level: 3
|
|
631
|
+
});
|
|
632
|
+
} else {
|
|
609
633
|
selectCurrentNode();
|
|
610
634
|
cancelNodeType();
|
|
611
635
|
current.editor.commands.setHeading({
|
|
@@ -630,7 +654,14 @@ var CustomDragHandle = function CustomDragHandle(_ref2) {
|
|
|
630
654
|
}
|
|
631
655
|
}),
|
|
632
656
|
onClick: function onClick() {
|
|
633
|
-
if (current.node
|
|
657
|
+
if (!current.node) return;
|
|
658
|
+
var type = current.node.type.name;
|
|
659
|
+
var groupTypes = [NodeTypeEnum.BulletList, NodeTypeEnum.OrderedList, NodeTypeEnum.TaskList, NodeTypeEnum.Blockquote, NodeTypeEnum.CodeBlock, NodeTypeEnum.Alert];
|
|
660
|
+
if (groupTypes.includes(type)) {
|
|
661
|
+
convertNodeAt(current.editor, current.pos, current.node, {
|
|
662
|
+
type: 'orderedList'
|
|
663
|
+
});
|
|
664
|
+
} else {
|
|
634
665
|
selectCurrentNode();
|
|
635
666
|
cancelNodeType();
|
|
636
667
|
current.editor.commands.toggleOrderedList();
|
|
@@ -646,7 +677,14 @@ var CustomDragHandle = function CustomDragHandle(_ref2) {
|
|
|
646
677
|
}
|
|
647
678
|
}),
|
|
648
679
|
onClick: function onClick() {
|
|
649
|
-
if (current.node
|
|
680
|
+
if (!current.node) return;
|
|
681
|
+
var type = current.node.type.name;
|
|
682
|
+
var groupTypes = [NodeTypeEnum.BulletList, NodeTypeEnum.OrderedList, NodeTypeEnum.TaskList, NodeTypeEnum.Blockquote, NodeTypeEnum.CodeBlock, NodeTypeEnum.Alert];
|
|
683
|
+
if (groupTypes.includes(type)) {
|
|
684
|
+
convertNodeAt(current.editor, current.pos, current.node, {
|
|
685
|
+
type: 'bulletList'
|
|
686
|
+
});
|
|
687
|
+
} else {
|
|
650
688
|
selectCurrentNode();
|
|
651
689
|
cancelNodeType();
|
|
652
690
|
current.editor.commands.toggleBulletList();
|
|
@@ -662,7 +700,14 @@ var CustomDragHandle = function CustomDragHandle(_ref2) {
|
|
|
662
700
|
}
|
|
663
701
|
}),
|
|
664
702
|
onClick: function onClick() {
|
|
665
|
-
if (current.node
|
|
703
|
+
if (!current.node) return;
|
|
704
|
+
var type = current.node.type.name;
|
|
705
|
+
var groupTypes = [NodeTypeEnum.BulletList, NodeTypeEnum.OrderedList, NodeTypeEnum.TaskList, NodeTypeEnum.Blockquote, NodeTypeEnum.CodeBlock, NodeTypeEnum.Alert];
|
|
706
|
+
if (groupTypes.includes(type)) {
|
|
707
|
+
convertNodeAt(current.editor, current.pos, current.node, {
|
|
708
|
+
type: 'taskList'
|
|
709
|
+
});
|
|
710
|
+
} else {
|
|
666
711
|
selectCurrentNode();
|
|
667
712
|
cancelNodeType();
|
|
668
713
|
current.editor.commands.toggleTaskList();
|
|
@@ -685,7 +730,14 @@ var CustomDragHandle = function CustomDragHandle(_ref2) {
|
|
|
685
730
|
}
|
|
686
731
|
}),
|
|
687
732
|
onClick: function onClick() {
|
|
688
|
-
if (current.node
|
|
733
|
+
if (!current.node) return;
|
|
734
|
+
var type = current.node.type.name;
|
|
735
|
+
var groupTypes = [NodeTypeEnum.BulletList, NodeTypeEnum.OrderedList, NodeTypeEnum.TaskList, NodeTypeEnum.Blockquote, NodeTypeEnum.CodeBlock, NodeTypeEnum.Alert];
|
|
736
|
+
if (groupTypes.includes(type)) {
|
|
737
|
+
convertNodeAt(current.editor, current.pos, current.node, {
|
|
738
|
+
type: 'blockquote'
|
|
739
|
+
});
|
|
740
|
+
} else {
|
|
689
741
|
selectCurrentNode();
|
|
690
742
|
cancelNodeType();
|
|
691
743
|
current.editor.commands.toggleBlockquote();
|
|
@@ -701,7 +753,14 @@ var CustomDragHandle = function CustomDragHandle(_ref2) {
|
|
|
701
753
|
}
|
|
702
754
|
}),
|
|
703
755
|
onClick: function onClick() {
|
|
704
|
-
if (current.node
|
|
756
|
+
if (!current.node) return;
|
|
757
|
+
var type = current.node.type.name;
|
|
758
|
+
var groupTypes = [NodeTypeEnum.BulletList, NodeTypeEnum.OrderedList, NodeTypeEnum.TaskList, NodeTypeEnum.Blockquote, NodeTypeEnum.CodeBlock, NodeTypeEnum.Alert];
|
|
759
|
+
if (groupTypes.includes(type)) {
|
|
760
|
+
convertNodeAt(current.editor, current.pos, current.node, {
|
|
761
|
+
type: 'codeBlock'
|
|
762
|
+
});
|
|
763
|
+
} else {
|
|
705
764
|
selectCurrentNode();
|
|
706
765
|
cancelNodeType();
|
|
707
766
|
current.editor.commands.toggleCodeBlock();
|
|
@@ -717,7 +776,18 @@ var CustomDragHandle = function CustomDragHandle(_ref2) {
|
|
|
717
776
|
}
|
|
718
777
|
}),
|
|
719
778
|
onClick: function onClick() {
|
|
720
|
-
if (current.node
|
|
779
|
+
if (!current.node) return;
|
|
780
|
+
var type = current.node.type.name;
|
|
781
|
+
var groupTypes = [NodeTypeEnum.BulletList, NodeTypeEnum.OrderedList, NodeTypeEnum.TaskList, NodeTypeEnum.Blockquote, NodeTypeEnum.CodeBlock, NodeTypeEnum.Alert];
|
|
782
|
+
if (groupTypes.includes(type)) {
|
|
783
|
+
convertNodeAt(current.editor, current.pos, current.node, {
|
|
784
|
+
type: 'alert',
|
|
785
|
+
attrs: {
|
|
786
|
+
variant: 'info',
|
|
787
|
+
type: 'icon'
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
} else {
|
|
721
791
|
selectCurrentNode();
|
|
722
792
|
cancelNodeType();
|
|
723
793
|
current.editor.commands.toggleAlert({
|
|
@@ -1084,8 +1154,6 @@ var CustomDragHandle = function CustomDragHandle(_ref2) {
|
|
|
1084
1154
|
var afterPos = current.pos + current.node.nodeSize;
|
|
1085
1155
|
current.editor.chain().focus().insertContentAt(afterPos, {
|
|
1086
1156
|
type: 'paragraph'
|
|
1087
|
-
}, {
|
|
1088
|
-
updateSelection: true
|
|
1089
1157
|
}).run();
|
|
1090
1158
|
}
|
|
1091
1159
|
},
|
|
@@ -1099,7 +1167,8 @@ var CustomDragHandle = function CustomDragHandle(_ref2) {
|
|
|
1099
1167
|
key: 'insert-divider',
|
|
1100
1168
|
onClick: function onClick() {
|
|
1101
1169
|
if (current.node && current.pos !== undefined) {
|
|
1102
|
-
current.
|
|
1170
|
+
var afterPos = current.pos + current.node.nodeSize;
|
|
1171
|
+
current.editor.chain().focus().insertContentAt(afterPos, {
|
|
1103
1172
|
type: 'horizontalRule'
|
|
1104
1173
|
}).run();
|
|
1105
1174
|
}
|
|
@@ -114,3 +114,4 @@ export { UploadCloud2LineIcon } from './upload-cloud-2-line-icon';
|
|
|
114
114
|
export { UploadIcon } from './upload-icon';
|
|
115
115
|
export { VolumeMuteLineIcon } from './volume-mute-line-icon';
|
|
116
116
|
export { VolumeUpLineIcon } from './volume-up-line-icon';
|
|
117
|
+
export { WindowFillIcon } from './window-fill-icon';
|
|
@@ -116,4 +116,5 @@ export { UnderlineIcon } from "./underline-icon";
|
|
|
116
116
|
export { UploadCloud2LineIcon } from "./upload-cloud-2-line-icon";
|
|
117
117
|
export { UploadIcon } from "./upload-icon";
|
|
118
118
|
export { VolumeMuteLineIcon } from "./volume-mute-line-icon";
|
|
119
|
-
export { VolumeUpLineIcon } from "./volume-up-line-icon";
|
|
119
|
+
export { VolumeUpLineIcon } from "./volume-up-line-icon";
|
|
120
|
+
export { WindowFillIcon } from "./window-fill-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 WindowFillIcon = function WindowFillIcon(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: "M3 3H21C21.5523 3 22 3.44772 22 4V20C22 20.5523 21.5523 21 21 21H3C2.44772 21 2 20.5523 2 20V4C2 3.44772 2.44772 3 3 3ZM20 10H4V19H20V10ZM5 6V8H7V6H5ZM9 6V8H11V6H9Z"
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
WindowFillIcon.displayName = 'icon-window-fill';
|
package/dist/contants/enums.d.ts
CHANGED
package/dist/contants/enums.js
CHANGED
|
@@ -21,6 +21,7 @@ export var NodeTypeEnum = /*#__PURE__*/function (NodeTypeEnum) {
|
|
|
21
21
|
NodeTypeEnum["Video"] = "video";
|
|
22
22
|
NodeTypeEnum["Audio"] = "audio";
|
|
23
23
|
NodeTypeEnum["Link"] = "link";
|
|
24
|
+
NodeTypeEnum["Iframe"] = "iframe";
|
|
24
25
|
NodeTypeEnum["Code"] = "code";
|
|
25
26
|
NodeTypeEnum["InlineMath"] = "inlineMath";
|
|
26
27
|
NodeTypeEnum["BlockMath"] = "blockMath";
|
|
@@ -96,10 +97,12 @@ export var NODE_TYPE_LABEL = (_NODE_TYPE_LABEL = {}, _defineProperty(_defineProp
|
|
|
96
97
|
label: '链接'
|
|
97
98
|
}), NodeTypeEnum.Image, {
|
|
98
99
|
label: '图片'
|
|
100
|
+
}), NodeTypeEnum.Iframe, {
|
|
101
|
+
label: 'iframe'
|
|
99
102
|
}), NodeTypeEnum.InlineMath, {
|
|
100
103
|
label: '行内公式'
|
|
101
104
|
}), NodeTypeEnum.InlineAttachment, {
|
|
102
105
|
label: '附件'
|
|
103
|
-
}), NodeTypeEnum.HorizontalRule, {
|
|
106
|
+
}), _defineProperty(_NODE_TYPE_LABEL, NodeTypeEnum.HorizontalRule, {
|
|
104
107
|
label: '分割线'
|
|
105
108
|
}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { AttachmentLineIcon, CodeBoxLineIcon, CodeLineIcon, DoubleQuotesLIcon, FunctionsIcon, H1Icon, H2Icon, H3Icon, H4Icon, H5Icon, H6Icon, ImageLineIcon, Information2LineIcon, LinkIcon, ListCheck2Icon, ListOrdered2Icon, ListUnorderedIcon, MenuFold2FillIcon, MovieLineIcon, Music2LineIcon, SeparatorIcon, SquareRootIcon, Table2Icon, TextWrapIcon } from "../component/Icons";
|
|
2
|
+
import { AttachmentLineIcon, CodeBoxLineIcon, CodeLineIcon, DoubleQuotesLIcon, FunctionsIcon, H1Icon, H2Icon, H3Icon, H4Icon, H5Icon, H6Icon, ImageLineIcon, Information2LineIcon, LinkIcon, ListCheck2Icon, ListOrdered2Icon, ListUnorderedIcon, MenuFold2FillIcon, MovieLineIcon, Music2LineIcon, SeparatorIcon, SquareRootIcon, Table2Icon, TextWrapIcon, WindowFillIcon } from "../component/Icons";
|
|
3
3
|
export var slashCommands = [{
|
|
4
4
|
title: '一级标题',
|
|
5
5
|
icon: /*#__PURE__*/React.createElement(H1Icon, {
|
|
@@ -223,36 +223,40 @@ export var slashCommands = [{
|
|
|
223
223
|
}).run();
|
|
224
224
|
}
|
|
225
225
|
}, {
|
|
226
|
-
title: '
|
|
227
|
-
icon: /*#__PURE__*/React.createElement(
|
|
226
|
+
title: 'iframe',
|
|
227
|
+
icon: /*#__PURE__*/React.createElement(WindowFillIcon, {
|
|
228
228
|
sx: {
|
|
229
229
|
fontSize: '1rem'
|
|
230
230
|
}
|
|
231
231
|
}),
|
|
232
232
|
command: function command(_ref18) {
|
|
233
233
|
var editor = _ref18.editor,
|
|
234
|
-
range = _ref18.range
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
234
|
+
range = _ref18.range;
|
|
235
|
+
editor.chain().focus().deleteRange(range).setIframe({
|
|
236
|
+
src: '',
|
|
237
|
+
width: 760,
|
|
238
|
+
height: 400
|
|
239
239
|
}).run();
|
|
240
240
|
}
|
|
241
241
|
}, {
|
|
242
|
-
title: '
|
|
243
|
-
icon: /*#__PURE__*/React.createElement(
|
|
242
|
+
title: '警告提示',
|
|
243
|
+
icon: /*#__PURE__*/React.createElement(Information2LineIcon, {
|
|
244
244
|
sx: {
|
|
245
245
|
fontSize: '1rem'
|
|
246
246
|
}
|
|
247
247
|
}),
|
|
248
248
|
command: function command(_ref19) {
|
|
249
249
|
var editor = _ref19.editor,
|
|
250
|
-
range = _ref19.range
|
|
251
|
-
|
|
250
|
+
range = _ref19.range,
|
|
251
|
+
attrs = _ref19.attrs;
|
|
252
|
+
editor.chain().focus().deleteRange(range).toggleAlert({
|
|
253
|
+
type: (attrs === null || attrs === void 0 ? void 0 : attrs.type) || 'icon',
|
|
254
|
+
variant: (attrs === null || attrs === void 0 ? void 0 : attrs.variant) || 'info'
|
|
255
|
+
}).run();
|
|
252
256
|
}
|
|
253
257
|
}, {
|
|
254
|
-
title: '
|
|
255
|
-
icon: /*#__PURE__*/React.createElement(
|
|
258
|
+
title: '折叠块',
|
|
259
|
+
icon: /*#__PURE__*/React.createElement(MenuFold2FillIcon, {
|
|
256
260
|
sx: {
|
|
257
261
|
fontSize: '1rem'
|
|
258
262
|
}
|
|
@@ -260,11 +264,11 @@ export var slashCommands = [{
|
|
|
260
264
|
command: function command(_ref20) {
|
|
261
265
|
var editor = _ref20.editor,
|
|
262
266
|
range = _ref20.range;
|
|
263
|
-
editor.chain().focus().deleteRange(range).
|
|
267
|
+
editor.chain().focus().deleteRange(range).setDetails().run();
|
|
264
268
|
}
|
|
265
269
|
}, {
|
|
266
|
-
title: '
|
|
267
|
-
icon: /*#__PURE__*/React.createElement(
|
|
270
|
+
title: '代码块',
|
|
271
|
+
icon: /*#__PURE__*/React.createElement(CodeBoxLineIcon, {
|
|
268
272
|
sx: {
|
|
269
273
|
fontSize: '1rem'
|
|
270
274
|
}
|
|
@@ -272,13 +276,11 @@ export var slashCommands = [{
|
|
|
272
276
|
command: function command(_ref21) {
|
|
273
277
|
var editor = _ref21.editor,
|
|
274
278
|
range = _ref21.range;
|
|
275
|
-
editor.chain().focus().deleteRange(range).
|
|
276
|
-
latex: ''
|
|
277
|
-
}).run();
|
|
279
|
+
editor.chain().focus().deleteRange(range).toggleCodeBlock().run();
|
|
278
280
|
}
|
|
279
281
|
}, {
|
|
280
|
-
title: '
|
|
281
|
-
icon: /*#__PURE__*/React.createElement(
|
|
282
|
+
title: '行内数学公式',
|
|
283
|
+
icon: /*#__PURE__*/React.createElement(SquareRootIcon, {
|
|
282
284
|
sx: {
|
|
283
285
|
fontSize: '1rem'
|
|
284
286
|
}
|
|
@@ -286,13 +288,13 @@ export var slashCommands = [{
|
|
|
286
288
|
command: function command(_ref22) {
|
|
287
289
|
var editor = _ref22.editor,
|
|
288
290
|
range = _ref22.range;
|
|
289
|
-
editor.chain().focus().deleteRange(range).
|
|
291
|
+
editor.chain().focus().deleteRange(range).setInlineMath({
|
|
290
292
|
latex: ''
|
|
291
293
|
}).run();
|
|
292
294
|
}
|
|
293
295
|
}, {
|
|
294
|
-
title: '
|
|
295
|
-
icon: /*#__PURE__*/React.createElement(
|
|
296
|
+
title: '块级数学公式',
|
|
297
|
+
icon: /*#__PURE__*/React.createElement(FunctionsIcon, {
|
|
296
298
|
sx: {
|
|
297
299
|
fontSize: '1rem'
|
|
298
300
|
}
|
|
@@ -300,10 +302,8 @@ export var slashCommands = [{
|
|
|
300
302
|
command: function command(_ref23) {
|
|
301
303
|
var editor = _ref23.editor,
|
|
302
304
|
range = _ref23.range;
|
|
303
|
-
editor.chain().focus().deleteRange(range).
|
|
304
|
-
|
|
305
|
-
cols: 4,
|
|
306
|
-
withHeaderRow: true
|
|
305
|
+
editor.chain().focus().deleteRange(range).setBlockMath({
|
|
306
|
+
latex: ''
|
|
307
307
|
}).run();
|
|
308
308
|
}
|
|
309
309
|
}, {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EditorFnProps } from "../../../type";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export type IframeAttributes = {
|
|
4
|
+
src: string;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
};
|
|
8
|
+
type InsertIframeProps = {
|
|
9
|
+
selected: boolean;
|
|
10
|
+
attrs: IframeAttributes;
|
|
11
|
+
updateAttributes: (attrs: IframeAttributes) => void;
|
|
12
|
+
} & EditorFnProps;
|
|
13
|
+
declare const InsertIframe: ({ selected, attrs, updateAttributes }: InsertIframeProps) => React.JSX.Element;
|
|
14
|
+
export default InsertIframe;
|
|
@@ -0,0 +1,112 @@
|
|
|
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 { WindowFillIcon } 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 InsertIframe = function InsertIframe(_ref) {
|
|
13
|
+
var selected = _ref.selected,
|
|
14
|
+
attrs = _ref.attrs,
|
|
15
|
+
updateAttributes = _ref.updateAttributes;
|
|
16
|
+
var _useState = useState(attrs.src || ''),
|
|
17
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
18
|
+
editUrl = _useState2[0],
|
|
19
|
+
setEditUrl = _useState2[1];
|
|
20
|
+
var _useState3 = useState(null),
|
|
21
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
22
|
+
anchorEl = _useState4[0],
|
|
23
|
+
setAnchorEl = _useState4[1];
|
|
24
|
+
var handleShowPopover = function handleShowPopover(event) {
|
|
25
|
+
return setAnchorEl(event.currentTarget);
|
|
26
|
+
};
|
|
27
|
+
var handleClosePopover = function handleClosePopover() {
|
|
28
|
+
return setAnchorEl(null);
|
|
29
|
+
};
|
|
30
|
+
var handleInsert = function handleInsert() {
|
|
31
|
+
if (!editUrl.trim()) return;
|
|
32
|
+
updateAttributes({
|
|
33
|
+
src: editUrl.trim(),
|
|
34
|
+
width: attrs.width,
|
|
35
|
+
height: attrs.height
|
|
36
|
+
});
|
|
37
|
+
handleClosePopover();
|
|
38
|
+
};
|
|
39
|
+
return /*#__PURE__*/React.createElement(NodeViewWrapper, {
|
|
40
|
+
className: "iframe-wrapper",
|
|
41
|
+
"data-drag-handle": true
|
|
42
|
+
}, /*#__PURE__*/React.createElement(Stack, {
|
|
43
|
+
direction: 'row',
|
|
44
|
+
alignItems: 'center',
|
|
45
|
+
gap: 2,
|
|
46
|
+
onClick: handleShowPopover,
|
|
47
|
+
sx: {
|
|
48
|
+
border: '1px dashed',
|
|
49
|
+
borderColor: 'divider',
|
|
50
|
+
borderRadius: 'var(--mui-shape-borderRadius)',
|
|
51
|
+
px: 2,
|
|
52
|
+
py: 1.5,
|
|
53
|
+
minWidth: 200,
|
|
54
|
+
textAlign: 'center',
|
|
55
|
+
color: 'text.secondary',
|
|
56
|
+
bgcolor: 'action.default',
|
|
57
|
+
position: 'relative',
|
|
58
|
+
overflow: 'hidden',
|
|
59
|
+
cursor: 'pointer',
|
|
60
|
+
'&:hover': {
|
|
61
|
+
bgcolor: 'action.hover'
|
|
62
|
+
},
|
|
63
|
+
'&:active': {
|
|
64
|
+
bgcolor: 'action.selected'
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, /*#__PURE__*/React.createElement(WindowFillIcon, {
|
|
68
|
+
sx: {
|
|
69
|
+
fontSize: '1rem',
|
|
70
|
+
position: 'relative',
|
|
71
|
+
flexShrink: 0
|
|
72
|
+
}
|
|
73
|
+
}), /*#__PURE__*/React.createElement(Box, {
|
|
74
|
+
sx: {
|
|
75
|
+
fontSize: '0.875rem',
|
|
76
|
+
position: 'relative',
|
|
77
|
+
flexGrow: 1,
|
|
78
|
+
textAlign: 'left'
|
|
79
|
+
}
|
|
80
|
+
}, "\u70B9\u51FB\u6B64\u5904\u5D4C\u5165 iframe")), /*#__PURE__*/React.createElement(FloatingPopover, {
|
|
81
|
+
open: Boolean(anchorEl),
|
|
82
|
+
anchorEl: anchorEl,
|
|
83
|
+
onClose: handleClosePopover,
|
|
84
|
+
placement: "bottom"
|
|
85
|
+
}, /*#__PURE__*/React.createElement(Stack, {
|
|
86
|
+
gap: 2,
|
|
87
|
+
sx: {
|
|
88
|
+
p: 2,
|
|
89
|
+
width: 350
|
|
90
|
+
}
|
|
91
|
+
}, /*#__PURE__*/React.createElement(TextField, {
|
|
92
|
+
fullWidth: true,
|
|
93
|
+
size: "small",
|
|
94
|
+
value: editUrl,
|
|
95
|
+
onChange: function onChange(e) {
|
|
96
|
+
return setEditUrl(e.target.value);
|
|
97
|
+
},
|
|
98
|
+
placeholder: "\u8F93\u5165\u8981\u5D4C\u5165\u7684 URL"
|
|
99
|
+
}), /*#__PURE__*/React.createElement(Stack, {
|
|
100
|
+
direction: 'row',
|
|
101
|
+
gap: 1
|
|
102
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
103
|
+
variant: "outlined",
|
|
104
|
+
fullWidth: true,
|
|
105
|
+
onClick: handleClosePopover
|
|
106
|
+
}, "\u53D6\u6D88"), /*#__PURE__*/React.createElement(Button, {
|
|
107
|
+
variant: "contained",
|
|
108
|
+
fullWidth: true,
|
|
109
|
+
onClick: handleInsert
|
|
110
|
+
}, "\u5D4C\u5165")))));
|
|
111
|
+
};
|
|
112
|
+
export default InsertIframe;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
var ReadonlyIframe = function ReadonlyIframe(_ref) {
|
|
3
|
+
var attrs = _ref.attrs;
|
|
4
|
+
return /*#__PURE__*/React.createElement("iframe", {
|
|
5
|
+
src: attrs.src,
|
|
6
|
+
width: attrs.width,
|
|
7
|
+
height: attrs.height,
|
|
8
|
+
style: {
|
|
9
|
+
display: 'block',
|
|
10
|
+
border: 0
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export default ReadonlyIframe;
|