@ctzhian/tiptap 1.11.4 → 1.12.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 +17 -22
- package/dist/EditorMarkdown/index.js +1 -1
- package/dist/asset/css/index.css +19 -8
- package/dist/component/ActionDropdown/index.d.ts +25 -0
- package/dist/component/ActionDropdown/index.js +147 -0
- package/dist/component/CustomDragHandle/index.js +2 -2
- package/dist/component/FloatingPopover/index.d.ts +2 -0
- package/dist/component/FloatingPopover/index.js +7 -1
- package/dist/component/HoverPopover/index.d.ts +29 -0
- package/dist/component/HoverPopover/index.js +143 -0
- package/dist/component/Icons/chrome-icon.d.ts +6 -0
- package/dist/component/Icons/chrome-icon.js +31 -0
- package/dist/component/Icons/edit-line-icon.d.ts +6 -0
- package/dist/component/Icons/edit-line-icon.js +13 -0
- package/dist/component/Icons/file-icon.d.ts +6 -0
- package/dist/component/Icons/file-icon.js +20 -0
- package/dist/component/Icons/index.d.ts +3 -0
- package/dist/component/Icons/index.js +3 -0
- package/dist/component/index.d.ts +2 -0
- package/dist/component/index.js +2 -0
- package/dist/extension/component/Alert/index.js +73 -85
- package/dist/extension/component/Attachment/AttachmentContent.d.ts +14 -0
- package/dist/extension/component/Attachment/AttachmentContent.js +142 -0
- package/dist/extension/component/Attachment/index.js +144 -201
- package/dist/extension/component/CodeBlock/Readonly.js +42 -35
- package/dist/extension/component/CodeBlock/index.js +137 -90
- package/dist/extension/component/Image/Insert.js +41 -26
- package/dist/extension/component/Image/Readonly.js +13 -6
- package/dist/extension/component/Image/index.d.ts +1 -0
- package/dist/extension/component/Image/index.js +234 -92
- package/dist/extension/component/Link/Insert.js +1 -1
- package/dist/extension/component/Link/LinkContent.d.ts +13 -0
- package/dist/extension/component/Link/LinkContent.js +169 -0
- package/dist/extension/component/Link/index.js +182 -264
- package/dist/extension/component/MentionList/index.js +1 -1
- package/dist/extension/index.js +1 -1
- package/dist/index.css +65 -63
- package/dist/themes/dark.js +2 -2
- package/dist/themes/light.d.ts +1 -1
- package/dist/themes/light.js +2 -2
- package/dist/themes/palette.d.ts +1 -1
- package/package.json +1 -1
- package/dist/extension/component/Attachment/Readonly.d.ts +0 -9
- package/dist/extension/component/Attachment/Readonly.js +0 -91
- package/dist/extension/component/CustomLink/Insert.d.ts +0 -0
- package/dist/extension/component/CustomLink/Insert.js +0 -176
- package/dist/extension/component/CustomLink/Readonly.d.ts +0 -0
- package/dist/extension/component/CustomLink/Readonly.js +0 -106
- package/dist/extension/component/CustomLink/index.d.ts +0 -0
- package/dist/extension/component/CustomLink/index.js +0 -440
- package/dist/extension/component/Link/Readonly.d.ts +0 -8
- package/dist/extension/component/Link/Readonly.js +0 -110
|
@@ -5,14 +5,14 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
5
5
|
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; }
|
|
6
6
|
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; } }
|
|
7
7
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
|
-
import { FloatingPopover } from "../../../component";
|
|
9
|
-
import {
|
|
8
|
+
import { ActionDropdown, FloatingPopover, HoverPopover } from "../../../component";
|
|
9
|
+
import { CarouselViewIcon, DeleteLineIcon, DownloadLineIcon, EditLineIcon, ScrollToBottomLineIcon } from "../../../component/Icons";
|
|
10
10
|
import { ToolbarItem } from "../../../component/Toolbar";
|
|
11
11
|
import { Box, Button, Divider, Stack, TextField } from "@mui/material";
|
|
12
12
|
import { NodeViewWrapper } from "@tiptap/react";
|
|
13
|
-
import React, { useEffect, useState } from "react";
|
|
13
|
+
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
14
|
+
import { AttachmentContent } from "./AttachmentContent";
|
|
14
15
|
import InsertAttachment from "./Insert";
|
|
15
|
-
import ReadonlyAttachment from "./Readonly";
|
|
16
16
|
var AttachmentViewWrapper = function AttachmentViewWrapper(_ref) {
|
|
17
17
|
var editor = _ref.editor,
|
|
18
18
|
node = _ref.node,
|
|
@@ -22,7 +22,9 @@ var AttachmentViewWrapper = function AttachmentViewWrapper(_ref) {
|
|
|
22
22
|
onUpload = _ref.onUpload,
|
|
23
23
|
onError = _ref.onError,
|
|
24
24
|
_ref$attachmentType = _ref.attachmentType,
|
|
25
|
-
attachmentType = _ref$attachmentType === void 0 ? 'icon' : _ref$attachmentType
|
|
25
|
+
attachmentType = _ref$attachmentType === void 0 ? 'icon' : _ref$attachmentType,
|
|
26
|
+
getPos = _ref.getPos;
|
|
27
|
+
var isMarkdown = editor.options.contentType === 'markdown';
|
|
26
28
|
var attrs = node.attrs;
|
|
27
29
|
var attachmentDisplayType = attachmentType || attrs.type || 'icon';
|
|
28
30
|
var _useState = useState(''),
|
|
@@ -35,28 +37,124 @@ var AttachmentViewWrapper = function AttachmentViewWrapper(_ref) {
|
|
|
35
37
|
setExtension = _useState4[1];
|
|
36
38
|
var _useState5 = useState(null),
|
|
37
39
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
anchorEl = _useState6[0],
|
|
41
|
+
setAnchorEl = _useState6[1];
|
|
42
|
+
var attachmentContentRef = useRef(null);
|
|
43
|
+
useEffect(function () {
|
|
44
|
+
var title = attrs.title || '';
|
|
45
|
+
setTitle(title.split('.').slice(0, -1).join('.'));
|
|
46
|
+
setExtension(title.split('.').pop() || '');
|
|
47
|
+
}, [attrs.title, attachmentDisplayType]);
|
|
48
|
+
var handleShowPopover = function handleShowPopover() {
|
|
49
|
+
setAnchorEl(attachmentContentRef.current);
|
|
46
50
|
};
|
|
47
|
-
var
|
|
48
|
-
return
|
|
51
|
+
var handleClosePopover = function handleClosePopover() {
|
|
52
|
+
return setAnchorEl(null);
|
|
49
53
|
};
|
|
50
|
-
var
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
var handleConvertAttachmentType = function handleConvertAttachmentType(newType) {
|
|
55
|
+
if (attachmentDisplayType === 'block' && newType === 'icon') {
|
|
56
|
+
var pos = getPos();
|
|
57
|
+
if (typeof pos === 'number') {
|
|
58
|
+
editor.chain().focus().deleteRange({
|
|
59
|
+
from: pos,
|
|
60
|
+
to: pos + node.nodeSize
|
|
61
|
+
}).insertContentAt(pos, {
|
|
62
|
+
type: 'inlineAttachment',
|
|
63
|
+
attrs: {
|
|
64
|
+
url: attrs.url,
|
|
65
|
+
title: attrs.title,
|
|
66
|
+
type: newType,
|
|
67
|
+
size: attrs.size
|
|
68
|
+
}
|
|
69
|
+
}).run();
|
|
70
|
+
}
|
|
71
|
+
} else if (attachmentDisplayType === 'icon' && newType === 'block') {
|
|
72
|
+
var _pos = getPos();
|
|
73
|
+
if (typeof _pos === 'number') {
|
|
74
|
+
editor.chain().focus().deleteRange({
|
|
75
|
+
from: _pos,
|
|
76
|
+
to: _pos + node.nodeSize
|
|
77
|
+
}).insertContentAt(_pos, {
|
|
78
|
+
type: 'blockAttachment',
|
|
79
|
+
attrs: {
|
|
80
|
+
url: attrs.url,
|
|
81
|
+
title: attrs.title,
|
|
82
|
+
type: newType,
|
|
83
|
+
size: attrs.size
|
|
84
|
+
}
|
|
85
|
+
}).run();
|
|
86
|
+
}
|
|
56
87
|
}
|
|
57
88
|
};
|
|
58
|
-
var
|
|
59
|
-
return
|
|
89
|
+
var renderOperationActions = function renderOperationActions() {
|
|
90
|
+
return /*#__PURE__*/React.createElement(Stack, {
|
|
91
|
+
direction: 'row',
|
|
92
|
+
alignItems: 'center',
|
|
93
|
+
sx: {
|
|
94
|
+
p: 0.5
|
|
95
|
+
}
|
|
96
|
+
}, /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
97
|
+
icon: /*#__PURE__*/React.createElement(DownloadLineIcon, {
|
|
98
|
+
sx: {
|
|
99
|
+
fontSize: '1rem'
|
|
100
|
+
}
|
|
101
|
+
}),
|
|
102
|
+
tip: "\u4E0B\u8F7D",
|
|
103
|
+
onClick: handleDownload
|
|
104
|
+
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
105
|
+
icon: /*#__PURE__*/React.createElement(EditLineIcon, {
|
|
106
|
+
sx: {
|
|
107
|
+
fontSize: '1rem'
|
|
108
|
+
}
|
|
109
|
+
}),
|
|
110
|
+
tip: "\u7F16\u8F91",
|
|
111
|
+
onClick: handleShowPopover
|
|
112
|
+
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
113
|
+
icon: /*#__PURE__*/React.createElement(DeleteLineIcon, {
|
|
114
|
+
sx: {
|
|
115
|
+
fontSize: '1rem'
|
|
116
|
+
}
|
|
117
|
+
}),
|
|
118
|
+
tip: "\u5220\u9664",
|
|
119
|
+
onClick: handleDeleteAttachment
|
|
120
|
+
}), !isMarkdown && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Divider, {
|
|
121
|
+
orientation: "vertical",
|
|
122
|
+
flexItem: true,
|
|
123
|
+
sx: {
|
|
124
|
+
height: '1rem',
|
|
125
|
+
mx: 0.5,
|
|
126
|
+
alignSelf: 'center',
|
|
127
|
+
borderColor: 'divider'
|
|
128
|
+
}
|
|
129
|
+
}), /*#__PURE__*/React.createElement(ActionDropdown, {
|
|
130
|
+
id: "attachment-type-dropdown",
|
|
131
|
+
selected: attachmentDisplayType,
|
|
132
|
+
list: [{
|
|
133
|
+
key: 'icon',
|
|
134
|
+
label: '图标文字',
|
|
135
|
+
icon: /*#__PURE__*/React.createElement(ScrollToBottomLineIcon, {
|
|
136
|
+
sx: {
|
|
137
|
+
transform: 'rotate(90deg)',
|
|
138
|
+
fontSize: '1rem'
|
|
139
|
+
}
|
|
140
|
+
}),
|
|
141
|
+
onClick: function onClick() {
|
|
142
|
+
return handleConvertAttachmentType('icon');
|
|
143
|
+
}
|
|
144
|
+
}, {
|
|
145
|
+
key: 'block',
|
|
146
|
+
label: '卡片',
|
|
147
|
+
icon: /*#__PURE__*/React.createElement(CarouselViewIcon, {
|
|
148
|
+
sx: {
|
|
149
|
+
transform: 'rotate(90deg)',
|
|
150
|
+
fontSize: '1rem'
|
|
151
|
+
}
|
|
152
|
+
}),
|
|
153
|
+
onClick: function onClick() {
|
|
154
|
+
return handleConvertAttachmentType('block');
|
|
155
|
+
}
|
|
156
|
+
}]
|
|
157
|
+
})));
|
|
60
158
|
};
|
|
61
159
|
var handleSave = function handleSave() {
|
|
62
160
|
updateAttributes === null || updateAttributes === void 0 || updateAttributes({
|
|
@@ -67,22 +165,27 @@ var AttachmentViewWrapper = function AttachmentViewWrapper(_ref) {
|
|
|
67
165
|
var handleDeleteAttachment = function handleDeleteAttachment() {
|
|
68
166
|
deleteNode === null || deleteNode === void 0 || deleteNode();
|
|
69
167
|
};
|
|
70
|
-
var handleDownload = function
|
|
168
|
+
var handleDownload = useCallback(function () {
|
|
71
169
|
var a = document.createElement('a');
|
|
72
170
|
a.href = attrs.url;
|
|
73
171
|
a.target = '_blank';
|
|
74
172
|
a.download = attrs.title;
|
|
75
173
|
a.click();
|
|
76
174
|
a.remove();
|
|
77
|
-
};
|
|
78
|
-
useEffect(function () {
|
|
79
|
-
var title = attrs.title || '';
|
|
80
|
-
setTitle(title.split('.').slice(0, -1).join('.'));
|
|
81
|
-
setExtension(title.split('.').pop() || '');
|
|
82
|
-
}, [attrs.title, attachmentDisplayType]);
|
|
175
|
+
}, [attrs.url, attrs.title]);
|
|
83
176
|
if ((!attrs.url || attrs.url === 'error') && !editor.isEditable) {
|
|
84
177
|
return null;
|
|
85
178
|
}
|
|
179
|
+
if (!editor.isEditable) {
|
|
180
|
+
return /*#__PURE__*/React.createElement(NodeViewWrapper, {
|
|
181
|
+
className: "attachment-wrapper".concat(attachmentDisplayType === 'block' ? ' block-attachment-wrapper' : ''),
|
|
182
|
+
as: attachmentDisplayType === 'block' ? 'div' : 'span'
|
|
183
|
+
}, /*#__PURE__*/React.createElement(AttachmentContent, {
|
|
184
|
+
attrs: attrs,
|
|
185
|
+
type: attachmentDisplayType,
|
|
186
|
+
editable: false
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
86
189
|
if (!attrs.title) {
|
|
87
190
|
return /*#__PURE__*/React.createElement(InsertAttachment, {
|
|
88
191
|
editor: editor,
|
|
@@ -94,181 +197,21 @@ var AttachmentViewWrapper = function AttachmentViewWrapper(_ref) {
|
|
|
94
197
|
onError: onError
|
|
95
198
|
});
|
|
96
199
|
}
|
|
97
|
-
if (!editor.isEditable) {
|
|
98
|
-
return /*#__PURE__*/React.createElement(ReadonlyAttachment, {
|
|
99
|
-
attrs: attrs,
|
|
100
|
-
type: attachmentDisplayType
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
200
|
return /*#__PURE__*/React.createElement(NodeViewWrapper, _extends({
|
|
104
|
-
className: "attachment-wrapper".concat(attachmentDisplayType === 'block' ? '
|
|
201
|
+
className: "attachment-wrapper ".concat(attachmentDisplayType === 'block' ? 'block-attachment-wrapper' : '').concat(selected ? ' ProseMirror-selectednode' : ''),
|
|
105
202
|
as: attachmentDisplayType === 'block' ? 'div' : 'span'
|
|
106
203
|
}, attachmentDisplayType === 'block' ? {
|
|
107
204
|
'data-drag-handle': true
|
|
108
|
-
} : {}),
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
sx: {
|
|
114
|
-
border: '1px solid',
|
|
115
|
-
borderColor: attrs.url === 'error' ? 'error.main' : 'divider',
|
|
116
|
-
cursor: 'pointer',
|
|
117
|
-
borderRadius: 'var(--mui-shape-borderRadius)',
|
|
118
|
-
bgcolor: 'background.paper',
|
|
119
|
-
p: 2,
|
|
120
|
-
':hover': {
|
|
121
|
-
borderColor: attrs.url === 'error' ? 'error.main' : 'primary.main',
|
|
122
|
-
color: attrs.url === 'error' ? 'error.main' : 'primary.main'
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}, /*#__PURE__*/React.createElement(Attachment2Icon, {
|
|
126
|
-
sx: {
|
|
127
|
-
fontSize: '2rem',
|
|
128
|
-
cursor: 'grab',
|
|
129
|
-
color: attrs.url === 'error' ? 'error.main' : 'primary.main',
|
|
130
|
-
alignSelf: 'center',
|
|
131
|
-
':active': {
|
|
132
|
-
cursor: 'grabbing'
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}), /*#__PURE__*/React.createElement(Stack, {
|
|
136
|
-
sx: {
|
|
137
|
-
flex: 1
|
|
138
|
-
},
|
|
139
|
-
gap: 0.5
|
|
140
|
-
}, /*#__PURE__*/React.createElement(Box, {
|
|
141
|
-
sx: {
|
|
142
|
-
fontSize: '0.875rem',
|
|
143
|
-
fontWeight: 'bold'
|
|
144
|
-
}
|
|
145
|
-
}, attrs.title), /*#__PURE__*/React.createElement(Box, {
|
|
146
|
-
sx: {
|
|
147
|
-
fontSize: '0.75rem',
|
|
148
|
-
color: 'text.secondary'
|
|
149
|
-
}
|
|
150
|
-
}, attrs.size))) : /*#__PURE__*/React.createElement(Box, {
|
|
151
|
-
component: 'span',
|
|
152
|
-
onClick: handleShowOperationPopover,
|
|
153
|
-
sx: {
|
|
154
|
-
color: 'primary.main',
|
|
155
|
-
textDecoration: 'none',
|
|
156
|
-
cursor: 'pointer',
|
|
157
|
-
borderRadius: 'var(--mui-shape-borderRadius)',
|
|
158
|
-
transition: 'background-color 0.2s ease',
|
|
159
|
-
':hover': {
|
|
160
|
-
bgcolor: 'background.paper'
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}, /*#__PURE__*/React.createElement(Box, {
|
|
164
|
-
component: 'span',
|
|
165
|
-
sx: {
|
|
166
|
-
display: 'inline-flex',
|
|
167
|
-
alignItems: 'center',
|
|
168
|
-
gap: 0.5
|
|
169
|
-
}
|
|
170
|
-
}, /*#__PURE__*/React.createElement(Attachment2Icon, {
|
|
171
|
-
sx: {
|
|
172
|
-
fontSize: '0.875rem',
|
|
173
|
-
cursor: 'grab',
|
|
174
|
-
color: 'primary.main',
|
|
175
|
-
alignSelf: 'center',
|
|
176
|
-
':active': {
|
|
177
|
-
cursor: 'grabbing'
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}), attrs.title)), /*#__PURE__*/React.createElement(FloatingPopover, {
|
|
181
|
-
open: Boolean(opraAnchorEl),
|
|
182
|
-
anchorEl: opraAnchorEl,
|
|
183
|
-
onClose: handleCloseOperationPopover,
|
|
205
|
+
} : {}), /*#__PURE__*/React.createElement("div", {
|
|
206
|
+
ref: attachmentContentRef
|
|
207
|
+
}, /*#__PURE__*/React.createElement(HoverPopover, {
|
|
208
|
+
actions: renderOperationActions(),
|
|
209
|
+
hoverDelay: 500,
|
|
184
210
|
placement: "top"
|
|
185
|
-
}, /*#__PURE__*/React.createElement(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
p: 0.5
|
|
190
|
-
}
|
|
191
|
-
}, /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
192
|
-
icon: /*#__PURE__*/React.createElement(DownloadLineIcon, {
|
|
193
|
-
sx: {
|
|
194
|
-
fontSize: '1rem'
|
|
195
|
-
}
|
|
196
|
-
}),
|
|
197
|
-
text: "\u4E0B\u8F7D",
|
|
198
|
-
onClick: handleDownload
|
|
199
|
-
}), /*#__PURE__*/React.createElement(Divider, {
|
|
200
|
-
orientation: "vertical",
|
|
201
|
-
flexItem: true,
|
|
202
|
-
sx: {
|
|
203
|
-
height: '1rem',
|
|
204
|
-
mx: 0.5,
|
|
205
|
-
alignSelf: 'center',
|
|
206
|
-
borderColor: 'divider'
|
|
207
|
-
}
|
|
208
|
-
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
209
|
-
icon: /*#__PURE__*/React.createElement(EditBoxLineIcon, {
|
|
210
|
-
sx: {
|
|
211
|
-
fontSize: '1rem'
|
|
212
|
-
}
|
|
213
|
-
}),
|
|
214
|
-
tip: "\u7F16\u8F91",
|
|
215
|
-
onClick: function onClick() {
|
|
216
|
-
handleCloseOperationPopover();
|
|
217
|
-
handleShowPopover();
|
|
218
|
-
}
|
|
219
|
-
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
220
|
-
icon: /*#__PURE__*/React.createElement(DeleteLineIcon, {
|
|
221
|
-
sx: {
|
|
222
|
-
fontSize: '1rem'
|
|
223
|
-
}
|
|
224
|
-
}),
|
|
225
|
-
tip: "\u5220\u9664",
|
|
226
|
-
onClick: handleDeleteAttachment
|
|
227
|
-
}), /*#__PURE__*/React.createElement(Divider, {
|
|
228
|
-
orientation: "vertical",
|
|
229
|
-
flexItem: true,
|
|
230
|
-
sx: {
|
|
231
|
-
height: '1rem',
|
|
232
|
-
mx: 0.5,
|
|
233
|
-
alignSelf: 'center',
|
|
234
|
-
borderColor: 'divider'
|
|
235
|
-
}
|
|
236
|
-
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
237
|
-
icon: /*#__PURE__*/React.createElement(ScrollToBottomLineIcon, {
|
|
238
|
-
sx: {
|
|
239
|
-
transform: 'rotate(90deg)',
|
|
240
|
-
fontSize: '1rem'
|
|
241
|
-
}
|
|
242
|
-
}),
|
|
243
|
-
tip: "\u56FE\u6807\u6587\u5B57\u94FE\u63A5",
|
|
244
|
-
className: attachmentDisplayType === 'icon' ? 'tool-active' : '',
|
|
245
|
-
onClick: function onClick() {
|
|
246
|
-
deleteNode === null || deleteNode === void 0 || deleteNode();
|
|
247
|
-
editor.commands.setInlineAttachment({
|
|
248
|
-
url: attrs.url,
|
|
249
|
-
title: attrs.title,
|
|
250
|
-
size: attrs.size
|
|
251
|
-
});
|
|
252
|
-
handleCloseOperationPopover();
|
|
253
|
-
}
|
|
254
|
-
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
255
|
-
icon: /*#__PURE__*/React.createElement(CarouselViewIcon, {
|
|
256
|
-
sx: {
|
|
257
|
-
transform: 'rotate(90deg)',
|
|
258
|
-
fontSize: '1rem'
|
|
259
|
-
}
|
|
260
|
-
}),
|
|
261
|
-
tip: "\u6458\u8981\u5361\u7247",
|
|
262
|
-
className: attachmentDisplayType === 'block' ? 'tool-active' : '',
|
|
263
|
-
onClick: function onClick() {
|
|
264
|
-
deleteNode === null || deleteNode === void 0 || deleteNode();
|
|
265
|
-
editor.commands.setBlockAttachment({
|
|
266
|
-
url: attrs.url,
|
|
267
|
-
title: attrs.title,
|
|
268
|
-
size: attrs.size
|
|
269
|
-
});
|
|
270
|
-
handleCloseOperationPopover();
|
|
271
|
-
}
|
|
211
|
+
}, /*#__PURE__*/React.createElement(AttachmentContent, {
|
|
212
|
+
attrs: attrs,
|
|
213
|
+
type: attachmentDisplayType,
|
|
214
|
+
editable: true
|
|
272
215
|
}))), /*#__PURE__*/React.createElement(FloatingPopover, {
|
|
273
216
|
open: Boolean(anchorEl),
|
|
274
217
|
anchorEl: anchorEl,
|
|
@@ -314,6 +257,6 @@ var AttachmentViewWrapper = function AttachmentViewWrapper(_ref) {
|
|
|
314
257
|
size: "small",
|
|
315
258
|
fullWidth: true,
|
|
316
259
|
onClick: handleSave
|
|
317
|
-
}, "\
|
|
260
|
+
}, "\u4FEE\u6539\u9644\u4EF6")))));
|
|
318
261
|
};
|
|
319
262
|
export default AttachmentViewWrapper;
|
|
@@ -9,7 +9,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
9
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
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
11
|
import { FileCopyLineIcon } from "../../../component/Icons";
|
|
12
|
-
import { Box, Stack } from '@mui/material';
|
|
12
|
+
import { Box, Divider, Stack } from '@mui/material';
|
|
13
13
|
import { NodeViewContent, NodeViewWrapper } from '@tiptap/react';
|
|
14
14
|
import React, { useCallback, useState } from 'react';
|
|
15
15
|
var ReadonlyCodeBlock = function ReadonlyCodeBlock(_ref) {
|
|
@@ -30,34 +30,35 @@ var ReadonlyCodeBlock = function ReadonlyCodeBlock(_ref) {
|
|
|
30
30
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
31
31
|
while (1) switch (_context.prev = _context.next) {
|
|
32
32
|
case 0:
|
|
33
|
+
event.preventDefault();
|
|
33
34
|
event.stopPropagation();
|
|
34
35
|
codeText = node.textContent || '';
|
|
35
|
-
_context.prev =
|
|
36
|
-
_context.next =
|
|
36
|
+
_context.prev = 3;
|
|
37
|
+
_context.next = 6;
|
|
37
38
|
return navigator.clipboard.writeText(codeText);
|
|
38
|
-
case
|
|
39
|
+
case 6:
|
|
39
40
|
setCopyText('复制成功');
|
|
40
41
|
setTimeout(function () {
|
|
41
42
|
setCopyText('复制');
|
|
42
43
|
}, 2000);
|
|
43
|
-
_context.next =
|
|
44
|
+
_context.next = 13;
|
|
44
45
|
break;
|
|
45
|
-
case
|
|
46
|
-
_context.prev =
|
|
47
|
-
_context.t0 = _context["catch"](
|
|
46
|
+
case 10:
|
|
47
|
+
_context.prev = 10;
|
|
48
|
+
_context.t0 = _context["catch"](3);
|
|
48
49
|
console.error('复制失败:', _context.t0);
|
|
49
|
-
case
|
|
50
|
+
case 13:
|
|
50
51
|
case "end":
|
|
51
52
|
return _context.stop();
|
|
52
53
|
}
|
|
53
|
-
}, _callee, null, [[
|
|
54
|
+
}, _callee, null, [[3, 10]]);
|
|
54
55
|
}));
|
|
55
56
|
return function (_x) {
|
|
56
57
|
return _ref2.apply(this, arguments);
|
|
57
58
|
};
|
|
58
59
|
}(), [node]);
|
|
59
60
|
return /*#__PURE__*/React.createElement(NodeViewWrapper, {
|
|
60
|
-
className: "codeblock-wrapper",
|
|
61
|
+
className: "codeblock-wrapper ".concat(selected ? 'ProseMirror-selectednode' : ''),
|
|
61
62
|
"data-drag-handle": true,
|
|
62
63
|
onMouseEnter: function onMouseEnter() {
|
|
63
64
|
return setIsHovering(true);
|
|
@@ -71,29 +72,45 @@ var ReadonlyCodeBlock = function ReadonlyCodeBlock(_ref) {
|
|
|
71
72
|
p: '0.75rem 1rem',
|
|
72
73
|
m: 0,
|
|
73
74
|
borderRadius: '6px',
|
|
74
|
-
overflow: 'hidden'
|
|
75
|
-
position: 'relative'
|
|
75
|
+
overflow: 'hidden'
|
|
76
76
|
}
|
|
77
|
-
},
|
|
77
|
+
}, /*#__PURE__*/React.createElement(Stack, {
|
|
78
78
|
direction: "row",
|
|
79
79
|
alignItems: "center",
|
|
80
|
-
justifyContent: "
|
|
80
|
+
justifyContent: "space-between",
|
|
81
|
+
className: "codeblock-toolbar",
|
|
81
82
|
sx: {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
right: 0,
|
|
85
|
-
px: 0.5,
|
|
86
|
-
pt: 0.5,
|
|
87
|
-
zIndex: 1
|
|
83
|
+
zIndex: 1,
|
|
84
|
+
mb: 2
|
|
88
85
|
}
|
|
89
|
-
}, /*#__PURE__*/React.createElement(
|
|
86
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
87
|
+
sx: {
|
|
88
|
+
flex: 1,
|
|
89
|
+
fontSize: '0.875rem',
|
|
90
|
+
color: 'text.auxiliary',
|
|
91
|
+
letterSpacing: '0.01rem'
|
|
92
|
+
}
|
|
93
|
+
}, attrs.title || '代码块'), isHovering && /*#__PURE__*/React.createElement(Stack, {
|
|
94
|
+
direction: "row",
|
|
95
|
+
alignItems: "center",
|
|
96
|
+
gap: 0.5
|
|
97
|
+
}, /*#__PURE__*/React.createElement(Box, null, attrs.language || 'Auto'), /*#__PURE__*/React.createElement(Divider, {
|
|
98
|
+
orientation: "vertical",
|
|
99
|
+
flexItem: true,
|
|
100
|
+
sx: {
|
|
101
|
+
height: '1rem',
|
|
102
|
+
mr: 0.5,
|
|
103
|
+
ml: 1,
|
|
104
|
+
alignSelf: 'center',
|
|
105
|
+
borderColor: 'divider'
|
|
106
|
+
}
|
|
107
|
+
}), /*#__PURE__*/React.createElement(Stack, {
|
|
90
108
|
direction: "row",
|
|
91
109
|
alignItems: "center",
|
|
92
110
|
gap: 0.5,
|
|
93
111
|
onClick: handleCopy,
|
|
94
112
|
sx: {
|
|
95
113
|
px: 1,
|
|
96
|
-
py: 0.5,
|
|
97
114
|
borderRadius: 'var(--mui-shape-borderRadius)',
|
|
98
115
|
cursor: 'pointer',
|
|
99
116
|
userSelect: 'none',
|
|
@@ -110,7 +127,7 @@ var ReadonlyCodeBlock = function ReadonlyCodeBlock(_ref) {
|
|
|
110
127
|
fontSize: '0.75rem',
|
|
111
128
|
lineHeight: 1
|
|
112
129
|
}
|
|
113
|
-
}, copyText))), /*#__PURE__*/React.createElement(NodeViewContent, {
|
|
130
|
+
}, copyText)))), /*#__PURE__*/React.createElement(NodeViewContent, {
|
|
114
131
|
style: {
|
|
115
132
|
margin: 0,
|
|
116
133
|
fontSize: '0.875rem',
|
|
@@ -118,16 +135,6 @@ var ReadonlyCodeBlock = function ReadonlyCodeBlock(_ref) {
|
|
|
118
135
|
whiteSpace: 'pre-wrap',
|
|
119
136
|
wordBreak: 'break-word'
|
|
120
137
|
}
|
|
121
|
-
}))
|
|
122
|
-
sx: {
|
|
123
|
-
pl: 1,
|
|
124
|
-
pt: 0.5,
|
|
125
|
-
height: '1rem',
|
|
126
|
-
lineHeight: 1,
|
|
127
|
-
fontSize: '0.875rem',
|
|
128
|
-
color: 'inherit',
|
|
129
|
-
letterSpacing: '0.01rem'
|
|
130
|
-
}
|
|
131
|
-
}, attrs.title));
|
|
138
|
+
})));
|
|
132
139
|
};
|
|
133
140
|
export default ReadonlyCodeBlock;
|