@ctzhian/tiptap 2.7.5 → 2.9.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/EditorMarkdown/Toolbar.js +15 -15
- package/dist/asset/css/index.css +17 -12
- package/dist/component/CustomBubbleMenu/TooltipInputPopover.d.ts +11 -0
- package/dist/component/CustomBubbleMenu/TooltipInputPopover.js +80 -0
- package/dist/component/CustomBubbleMenu/index.js +39 -36
- package/dist/component/CustomDragHandle/index.js +65 -18
- package/dist/component/Icons/index.d.ts +1 -0
- package/dist/component/Icons/index.js +1 -0
- package/dist/component/Icons/tooltip-line-icon.d.ts +6 -0
- package/dist/component/Icons/tooltip-line-icon.js +13 -0
- package/dist/component/Toolbar/EditorInsert/index.js +1 -1
- package/dist/contants/slash-commands.js +1 -1
- package/dist/extension/component/CodeBlock/index.js +18 -5
- package/dist/extension/component/Flow/FlowDiagram.d.ts +7 -0
- package/dist/extension/component/Flow/FlowDiagram.js +52 -0
- package/dist/extension/component/Flow/Insert.js +1 -1
- package/dist/extension/component/Flow/Readonly.js +6 -2
- package/dist/extension/component/Flow/index.d.ts +1 -0
- package/dist/extension/component/Flow/index.js +133 -68
- package/dist/extension/component/Flow/useMermaidRender.js +2 -2
- package/dist/extension/component/Flow/utils.d.ts +10 -1
- package/dist/extension/component/Flow/utils.js +45 -10
- package/dist/extension/component/Image/index.js +57 -46
- package/dist/extension/component/Tooltip/index.d.ts +4 -0
- package/dist/extension/component/Tooltip/index.js +19 -0
- package/dist/extension/index.d.ts +1 -1
- package/dist/extension/index.js +6 -7
- package/dist/extension/mark/Tooltip.d.ts +24 -0
- package/dist/extension/mark/Tooltip.js +141 -0
- package/dist/extension/node/Flow/index.d.ts +8 -1
- package/dist/extension/node/Flow/index.js +41 -4
- package/dist/index.css +1 -1
- package/dist/themes/index.d.ts +1 -1
- package/dist/type/index.d.ts +2 -0
- package/package.json +2 -2
|
@@ -95,30 +95,37 @@ var ImageViewWrapper = function ImageViewWrapper(_ref) {
|
|
|
95
95
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
96
96
|
isCropping = _useState6[0],
|
|
97
97
|
setIsCropping = _useState6[1];
|
|
98
|
-
var _useState7 = useState(attrs.src),
|
|
98
|
+
var _useState7 = useState(attrs.src || ''),
|
|
99
99
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
100
100
|
editSrc = _useState8[0],
|
|
101
101
|
setEditSrc = _useState8[1];
|
|
102
|
-
var _useState9 = useState(
|
|
102
|
+
var _useState9 = useState(attrs.title || ''),
|
|
103
103
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
editTitle = _useState10[0],
|
|
105
|
+
setEditTitle = _useState10[1];
|
|
106
|
+
var _useState11 = useState(null),
|
|
107
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
108
|
+
dragCorner = _useState12[0],
|
|
109
|
+
setDragCorner = _useState12[1];
|
|
106
110
|
var dragStartXRef = useRef(0);
|
|
107
111
|
var dragStartWidthRef = useRef(0);
|
|
108
|
-
var _useState11 = useState(attrs.title || ''),
|
|
109
|
-
_useState12 = _slicedToArray(_useState11, 2),
|
|
110
|
-
editTitle = _useState12[0],
|
|
111
|
-
setEditTitle = _useState12[1];
|
|
112
112
|
var _useState13 = useState(null),
|
|
113
113
|
_useState14 = _slicedToArray(_useState13, 2),
|
|
114
114
|
anchorEl = _useState14[0],
|
|
115
115
|
setAnchorEl = _useState14[1];
|
|
116
116
|
var imageContentRef = useRef(null);
|
|
117
|
+
var editButtonRef = useRef(null);
|
|
118
|
+
var _useState15 = useState(false),
|
|
119
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
120
|
+
keepHoverPopoverOpen = _useState16[0],
|
|
121
|
+
setKeepHoverPopoverOpen = _useState16[1];
|
|
117
122
|
var handleShowPopover = function handleShowPopover() {
|
|
118
|
-
|
|
123
|
+
setKeepHoverPopoverOpen(true);
|
|
124
|
+
setAnchorEl(editButtonRef.current);
|
|
119
125
|
};
|
|
120
126
|
var handleClosePopover = function handleClosePopover() {
|
|
121
|
-
|
|
127
|
+
setAnchorEl(null);
|
|
128
|
+
setKeepHoverPopoverOpen(false);
|
|
122
129
|
};
|
|
123
130
|
|
|
124
131
|
// 获取当前实际显示的图片宽度
|
|
@@ -135,37 +142,6 @@ var ImageViewWrapper = function ImageViewWrapper(_ref) {
|
|
|
135
142
|
}
|
|
136
143
|
return attrs.width;
|
|
137
144
|
};
|
|
138
|
-
useEffect(function () {
|
|
139
|
-
if (attrs.src && (!attrs.width || attrs.width <= 0)) {
|
|
140
|
-
getImageDimensions(attrs.src).then(function (dimensions) {
|
|
141
|
-
try {
|
|
142
|
-
var pos = typeof getPos === 'function' ? getPos() : null;
|
|
143
|
-
if (pos === null || pos === undefined) return;
|
|
144
|
-
var currentNode = editor.state.doc.nodeAt(pos);
|
|
145
|
-
if (!currentNode || currentNode.type.name !== 'image') return;
|
|
146
|
-
updateAttributes({
|
|
147
|
-
src: attrs.src,
|
|
148
|
-
width: dimensions.width
|
|
149
|
-
});
|
|
150
|
-
} catch (error) {
|
|
151
|
-
// console.warn('Failed to update image dimensions:', error)
|
|
152
|
-
}
|
|
153
|
-
}).catch(function (error) {
|
|
154
|
-
try {
|
|
155
|
-
var pos = typeof getPos === 'function' ? getPos() : null;
|
|
156
|
-
if (pos === null || pos === undefined) return;
|
|
157
|
-
var currentNode = editor.state.doc.nodeAt(pos);
|
|
158
|
-
if (!currentNode || currentNode.type.name !== 'image') return;
|
|
159
|
-
updateAttributes({
|
|
160
|
-
src: attrs.src,
|
|
161
|
-
width: 400
|
|
162
|
-
});
|
|
163
|
-
} catch (updateError) {
|
|
164
|
-
// console.warn('Failed to update image attributes with fallback width:', updateError)
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}, [attrs.src, attrs.width, updateAttributes, getPos, editor]);
|
|
169
145
|
var handleMouseDown = function handleMouseDown(e, corner) {
|
|
170
146
|
e.preventDefault();
|
|
171
147
|
e.stopPropagation();
|
|
@@ -272,6 +248,39 @@ var ImageViewWrapper = function ImageViewWrapper(_ref) {
|
|
|
272
248
|
}
|
|
273
249
|
chain.toggleTextAlign(align).run();
|
|
274
250
|
};
|
|
251
|
+
useEffect(function () {
|
|
252
|
+
if (attrs.src && (!attrs.width || attrs.width <= 0)) {
|
|
253
|
+
getImageDimensions(attrs.src).then(function (dimensions) {
|
|
254
|
+
try {
|
|
255
|
+
var pos = typeof getPos === 'function' ? getPos() : null;
|
|
256
|
+
if (pos === null || pos === undefined) return;
|
|
257
|
+
var currentNode = editor.state.doc.nodeAt(pos);
|
|
258
|
+
if (!currentNode || currentNode.type.name !== 'image') return;
|
|
259
|
+
updateAttributes({
|
|
260
|
+
src: attrs.src,
|
|
261
|
+
title: attrs.title || '',
|
|
262
|
+
width: dimensions.width
|
|
263
|
+
});
|
|
264
|
+
} catch (error) {}
|
|
265
|
+
}).catch(function () {
|
|
266
|
+
try {
|
|
267
|
+
var pos = typeof getPos === 'function' ? getPos() : null;
|
|
268
|
+
if (pos === null || pos === undefined) return;
|
|
269
|
+
var currentNode = editor.state.doc.nodeAt(pos);
|
|
270
|
+
if (!currentNode || currentNode.type.name !== 'image') return;
|
|
271
|
+
updateAttributes({
|
|
272
|
+
src: attrs.src,
|
|
273
|
+
title: attrs.title || '',
|
|
274
|
+
width: 400
|
|
275
|
+
});
|
|
276
|
+
} catch (updateError) {}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}, [attrs, updateAttributes, getPos, editor]);
|
|
280
|
+
useEffect(function () {
|
|
281
|
+
setEditSrc(attrs.src || '');
|
|
282
|
+
setEditTitle(attrs.title || '');
|
|
283
|
+
}, [attrs.src, attrs.title]);
|
|
275
284
|
useEffect(function () {
|
|
276
285
|
if (isDragging) {
|
|
277
286
|
document.addEventListener('mousemove', handleMouseMove);
|
|
@@ -315,6 +324,9 @@ var ImageViewWrapper = function ImageViewWrapper(_ref) {
|
|
|
315
324
|
as: 'span',
|
|
316
325
|
'data-drag-handle': false
|
|
317
326
|
}, /*#__PURE__*/React.createElement(HoverPopover, {
|
|
327
|
+
keepOpen: keepHoverPopoverOpen,
|
|
328
|
+
placement: "top",
|
|
329
|
+
offset: 4,
|
|
318
330
|
actions: /*#__PURE__*/React.createElement(Stack, {
|
|
319
331
|
direction: 'row',
|
|
320
332
|
alignItems: 'center',
|
|
@@ -322,6 +334,7 @@ var ImageViewWrapper = function ImageViewWrapper(_ref) {
|
|
|
322
334
|
p: 0.5
|
|
323
335
|
}
|
|
324
336
|
}, /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
337
|
+
ref: editButtonRef,
|
|
325
338
|
icon: /*#__PURE__*/React.createElement(EditLineIcon, {
|
|
326
339
|
sx: {
|
|
327
340
|
fontSize: '1rem'
|
|
@@ -393,9 +406,7 @@ var ImageViewWrapper = function ImageViewWrapper(_ref) {
|
|
|
393
406
|
}),
|
|
394
407
|
tip: "\u5220\u9664\u56FE\u7247",
|
|
395
408
|
onClick: deleteNode
|
|
396
|
-
}))
|
|
397
|
-
placement: "top",
|
|
398
|
-
offset: 4
|
|
409
|
+
}))
|
|
399
410
|
}, /*#__PURE__*/React.createElement(Box, {
|
|
400
411
|
component: 'span',
|
|
401
412
|
ref: imageContentRef,
|
|
@@ -518,7 +529,7 @@ var ImageViewWrapper = function ImageViewWrapper(_ref) {
|
|
|
518
529
|
open: Boolean(anchorEl),
|
|
519
530
|
anchorEl: anchorEl,
|
|
520
531
|
onClose: handleClosePopover,
|
|
521
|
-
placement: "
|
|
532
|
+
placement: "bottom"
|
|
522
533
|
}, /*#__PURE__*/React.createElement(Stack, {
|
|
523
534
|
sx: {
|
|
524
535
|
p: 2,
|
|
@@ -544,7 +555,7 @@ var ImageViewWrapper = function ImageViewWrapper(_ref) {
|
|
|
544
555
|
fontSize: '0.75rem',
|
|
545
556
|
color: 'text.secondary',
|
|
546
557
|
lineHeight: '1.5',
|
|
547
|
-
|
|
558
|
+
my: 1
|
|
548
559
|
}
|
|
549
560
|
}, "\u56FE\u7247\u63CF\u8FF0"), /*#__PURE__*/React.createElement(TextField, {
|
|
550
561
|
fullWidth: true,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Box, Tooltip } from "@mui/material";
|
|
2
|
+
import { MarkViewContent } from "@tiptap/react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
var TooltipView = function TooltipView(_ref) {
|
|
5
|
+
var mark = _ref.mark;
|
|
6
|
+
var tooltip = mark.attrs.tooltip;
|
|
7
|
+
return /*#__PURE__*/React.createElement(Tooltip, {
|
|
8
|
+
arrow: true,
|
|
9
|
+
placement: "top",
|
|
10
|
+
title: /*#__PURE__*/React.createElement(Box, null, tooltip)
|
|
11
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
12
|
+
component: "span",
|
|
13
|
+
sx: {
|
|
14
|
+
borderBottom: '1px dotted',
|
|
15
|
+
borderColor: 'text.secondary'
|
|
16
|
+
}
|
|
17
|
+
}, /*#__PURE__*/React.createElement(MarkViewContent, null)));
|
|
18
|
+
};
|
|
19
|
+
export default TooltipView;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GetExtensionsProps } from '../type';
|
|
2
|
-
export declare const getExtensions: ({ limit, exclude, extensions: extensionsProps, editable, mentionItems, baseUrl, onMentionFilter, onUpload, onError, onTocUpdate, onAiWritingGetSuggestion, onValidateUrl, placeholder, youtubeOptions, tableOfContentsOptions, }: GetExtensionsProps) => any;
|
|
2
|
+
export declare const getExtensions: ({ limit, exclude, extensions: extensionsProps, editable, mentionItems, baseUrl, onMentionFilter, onUpload, onError, onTocUpdate, onAiWritingGetSuggestion, onValidateUrl, placeholder, mermaidOptions, youtubeOptions, tableOfContentsOptions, }: GetExtensionsProps) => any;
|
package/dist/extension/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import StarterKit from '@tiptap/starter-kit';
|
|
|
14
14
|
import { PLACEHOLDER } from "../contants/placeholder";
|
|
15
15
|
import { AiWritingExtension, ImeComposition, SlashCommands, StructuredDiffExtension } from "./extension";
|
|
16
16
|
import { CodeExtension } from "./mark/Code";
|
|
17
|
+
import Tooltip from "./mark/Tooltip";
|
|
17
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
19
|
export var getExtensions = function getExtensions(_ref) {
|
|
19
20
|
var limit = _ref.limit,
|
|
@@ -30,6 +31,7 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
30
31
|
onAiWritingGetSuggestion = _ref.onAiWritingGetSuggestion,
|
|
31
32
|
onValidateUrl = _ref.onValidateUrl,
|
|
32
33
|
_placeholder = _ref.placeholder,
|
|
34
|
+
mermaidOptions = _ref.mermaidOptions,
|
|
33
35
|
youtubeOptions = _ref.youtubeOptions,
|
|
34
36
|
tableOfContentsOptions = _ref.tableOfContentsOptions;
|
|
35
37
|
var defaultExtensions = [ImeComposition, StarterKit.configure({
|
|
@@ -46,9 +48,11 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
46
48
|
color: 'var(--mui-palette-primary-main)',
|
|
47
49
|
width: 2
|
|
48
50
|
}
|
|
49
|
-
}), YamlFormat, TextStyleKit, CodeExtension, ListExtension, EmojiExtension, AlertExtension, CustomSubscript, DetailsExtension, CustomSuperscript, DetailsContentExtension, DetailsSummaryExtension, CodeBlockLowlightExtension, InlineUploadProgressExtension, CustomHorizontalRule].concat(_toConsumableArray(TableExtension({
|
|
51
|
+
}), YamlFormat, TextStyleKit, CodeExtension, Tooltip, ListExtension, EmojiExtension, AlertExtension, CustomSubscript, DetailsExtension, CustomSuperscript, FlipGridExtension, DetailsContentExtension, DetailsSummaryExtension, CodeBlockLowlightExtension, InlineUploadProgressExtension, CustomHorizontalRule, FlipGridColumnExtension].concat(_toConsumableArray(TableExtension({
|
|
50
52
|
editable: editable
|
|
51
|
-
})), [
|
|
53
|
+
})), [FlowExtension({
|
|
54
|
+
mermaidOptions: mermaidOptions
|
|
55
|
+
}), CustomBlockMathExtension({
|
|
52
56
|
onError: onError
|
|
53
57
|
}), CustomInlineMathExtension({
|
|
54
58
|
onError: onError
|
|
@@ -172,11 +176,6 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
172
176
|
var Youtube = YoutubeExtension(youtubeOptions);
|
|
173
177
|
defaultExtensions.push(Youtube);
|
|
174
178
|
}
|
|
175
|
-
if (!(exclude !== null && exclude !== void 0 && exclude.includes('flow'))) {
|
|
176
|
-
defaultExtensions.push(FlowExtension({
|
|
177
|
-
onError: onError
|
|
178
|
-
}));
|
|
179
|
-
}
|
|
180
179
|
if (extensionsProps && extensionsProps.length > 0) {
|
|
181
180
|
defaultExtensions.push.apply(defaultExtensions, _toConsumableArray(extensionsProps));
|
|
182
181
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Mark } from '@tiptap/core';
|
|
2
|
+
export interface TooltipOptions {
|
|
3
|
+
HTMLAttributes: Record<string, any>;
|
|
4
|
+
}
|
|
5
|
+
declare module '@tiptap/core' {
|
|
6
|
+
interface Commands<ReturnType> {
|
|
7
|
+
tooltip: {
|
|
8
|
+
/**
|
|
9
|
+
* Set a tooltip mark
|
|
10
|
+
*/
|
|
11
|
+
setTooltip: (tooltip: string) => ReturnType;
|
|
12
|
+
/**
|
|
13
|
+
* Toggle a tooltip mark
|
|
14
|
+
*/
|
|
15
|
+
toggleTooltip: (tooltip?: string) => ReturnType;
|
|
16
|
+
/**
|
|
17
|
+
* Unset a tooltip mark
|
|
18
|
+
*/
|
|
19
|
+
unsetTooltip: () => ReturnType;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export declare const Tooltip: Mark<TooltipOptions, any>;
|
|
24
|
+
export default Tooltip;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Mark, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
import { Plugin } from '@tiptap/pm/state';
|
|
3
|
+
import { Decoration, DecorationSet } from '@tiptap/pm/view';
|
|
4
|
+
import { ReactMarkViewRenderer } from '@tiptap/react';
|
|
5
|
+
import TooltipView from "../component/Tooltip";
|
|
6
|
+
export var Tooltip = Mark.create({
|
|
7
|
+
name: 'tooltip',
|
|
8
|
+
addOptions: function addOptions() {
|
|
9
|
+
return {
|
|
10
|
+
HTMLAttributes: {}
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
addAttributes: function addAttributes() {
|
|
14
|
+
return {
|
|
15
|
+
tooltip: {
|
|
16
|
+
default: null,
|
|
17
|
+
parseHTML: function parseHTML(element) {
|
|
18
|
+
return element.getAttribute('data-tooltip');
|
|
19
|
+
},
|
|
20
|
+
renderHTML: function renderHTML(attributes) {
|
|
21
|
+
if (!attributes.tooltip) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
'data-tooltip': attributes.tooltip,
|
|
26
|
+
'class': 'tooltip-mark'
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
parseHTML: function parseHTML() {
|
|
33
|
+
return [{
|
|
34
|
+
tag: 'span[data-tooltip]'
|
|
35
|
+
}];
|
|
36
|
+
},
|
|
37
|
+
renderHTML: function renderHTML(_ref) {
|
|
38
|
+
var HTMLAttributes = _ref.HTMLAttributes;
|
|
39
|
+
return ['span', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
40
|
+
},
|
|
41
|
+
addCommands: function addCommands() {
|
|
42
|
+
var _this = this;
|
|
43
|
+
return {
|
|
44
|
+
setTooltip: function setTooltip(tooltip) {
|
|
45
|
+
return function (_ref2) {
|
|
46
|
+
var commands = _ref2.commands;
|
|
47
|
+
return commands.setMark(_this.name, {
|
|
48
|
+
tooltip: tooltip
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
toggleTooltip: function toggleTooltip(tooltip) {
|
|
53
|
+
return function (_ref3) {
|
|
54
|
+
var commands = _ref3.commands;
|
|
55
|
+
return commands.toggleMark(_this.name, {
|
|
56
|
+
tooltip: tooltip
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
unsetTooltip: function unsetTooltip() {
|
|
61
|
+
return function (_ref4) {
|
|
62
|
+
var commands = _ref4.commands;
|
|
63
|
+
return commands.unsetMark(_this.name);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
addMarkView: function addMarkView() {
|
|
69
|
+
return ReactMarkViewRenderer(TooltipView);
|
|
70
|
+
},
|
|
71
|
+
addProseMirrorPlugins: function addProseMirrorPlugins() {
|
|
72
|
+
var _this2 = this;
|
|
73
|
+
return [new Plugin({
|
|
74
|
+
props: {
|
|
75
|
+
decorations: function decorations(state) {
|
|
76
|
+
var decorations = [];
|
|
77
|
+
state.doc.descendants(function (node, pos) {
|
|
78
|
+
var mark = node.marks.find(function (mark) {
|
|
79
|
+
return mark.type.name === _this2.name;
|
|
80
|
+
});
|
|
81
|
+
if (mark) {
|
|
82
|
+
var _tooltip = mark.attrs.tooltip;
|
|
83
|
+
if (_tooltip) {
|
|
84
|
+
decorations.push(Decoration.inline(pos, pos + node.nodeSize, {
|
|
85
|
+
class: 'tooltip-mark',
|
|
86
|
+
'data-tooltip': _tooltip
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return DecorationSet.create(state.doc, decorations);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
})];
|
|
95
|
+
},
|
|
96
|
+
markdownTokenName: 'tooltip',
|
|
97
|
+
markdownTokenizer: {
|
|
98
|
+
name: 'tooltip',
|
|
99
|
+
level: 'inline',
|
|
100
|
+
start: function start(src) {
|
|
101
|
+
return src.indexOf('{');
|
|
102
|
+
},
|
|
103
|
+
tokenize: function tokenize(src, _tokens, helpers) {
|
|
104
|
+
var match = /^\{([^}]+)\}\(([^)]+)\)/.exec(src);
|
|
105
|
+
if (!match) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
var text = match[1];
|
|
109
|
+
var tooltip = match[2];
|
|
110
|
+
return {
|
|
111
|
+
type: 'tooltip',
|
|
112
|
+
raw: match[0],
|
|
113
|
+
text: text,
|
|
114
|
+
tooltip: tooltip,
|
|
115
|
+
tokens: helpers.inlineTokens(text)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
parseMarkdown: function parseMarkdown(token, helpers) {
|
|
120
|
+
var content = helpers.parseInline(token.tokens || []);
|
|
121
|
+
if (!Array.isArray(content)) {
|
|
122
|
+
content = content ? [content] : [];
|
|
123
|
+
}
|
|
124
|
+
if (content.length === 0 && token.text) {
|
|
125
|
+
content = [helpers.createTextNode(token.text)];
|
|
126
|
+
}
|
|
127
|
+
return helpers.applyMark('tooltip', content, {
|
|
128
|
+
tooltip: token.tooltip
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
renderMarkdown: function renderMarkdown(node, helpers) {
|
|
132
|
+
var _node$attrs;
|
|
133
|
+
var content = helpers.renderChildren(node);
|
|
134
|
+
var tooltip = ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.tooltip) || '';
|
|
135
|
+
if (!tooltip) {
|
|
136
|
+
return content;
|
|
137
|
+
}
|
|
138
|
+
return "{".concat(content, "}(").concat(tooltip, ")");
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
export default Tooltip;
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { EditorFnProps } from "../../../type";
|
|
2
2
|
import { Node } from '@tiptap/core';
|
|
3
|
+
import { MermaidConfig } from 'mermaid';
|
|
3
4
|
declare module '@tiptap/core' {
|
|
4
5
|
interface Commands<ReturnType> {
|
|
5
6
|
flow: {
|
|
6
7
|
setFlow: (options: {
|
|
7
8
|
code?: string;
|
|
8
9
|
width?: string | number;
|
|
10
|
+
align?: 'left' | 'center' | 'right' | null;
|
|
9
11
|
}) => ReturnType;
|
|
10
12
|
};
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
|
-
export type FlowExtensionProps = EditorFnProps
|
|
15
|
+
export type FlowExtensionProps = EditorFnProps & {
|
|
16
|
+
/**
|
|
17
|
+
* Mermaid 配置选项
|
|
18
|
+
*/
|
|
19
|
+
mermaidOptions?: MermaidConfig;
|
|
20
|
+
};
|
|
14
21
|
export declare const FlowExtension: (props: FlowExtensionProps) => Node<any, any>;
|
|
15
22
|
export default FlowExtension;
|
|
@@ -7,7 +7,12 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
7
7
|
import { mergeAttributes, Node } from '@tiptap/core';
|
|
8
8
|
import { ReactNodeViewRenderer } from '@tiptap/react';
|
|
9
9
|
import FlowViewWrapper from "../../component/Flow";
|
|
10
|
+
import { initMermaid } from "../../component/Flow/utils";
|
|
10
11
|
export var FlowExtension = function FlowExtension(props) {
|
|
12
|
+
// 初始化 mermaid 配置(如果提供了配置)
|
|
13
|
+
if (props.mermaidOptions) {
|
|
14
|
+
initMermaid(props.mermaidOptions);
|
|
15
|
+
}
|
|
11
16
|
return Node.create({
|
|
12
17
|
name: 'flow',
|
|
13
18
|
group: 'block',
|
|
@@ -34,7 +39,13 @@ export var FlowExtension = function FlowExtension(props) {
|
|
|
34
39
|
width: {
|
|
35
40
|
default: null,
|
|
36
41
|
parseHTML: function parseHTML(element) {
|
|
37
|
-
|
|
42
|
+
var width = element.getAttribute('data-width');
|
|
43
|
+
if (width) {
|
|
44
|
+
if (width.endsWith('%')) return width;
|
|
45
|
+
var numWidth = parseFloat(width);
|
|
46
|
+
return isNaN(numWidth) ? null : numWidth;
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
38
49
|
},
|
|
39
50
|
renderHTML: function renderHTML(attributes) {
|
|
40
51
|
if (!attributes.width) return {};
|
|
@@ -42,6 +53,18 @@ export var FlowExtension = function FlowExtension(props) {
|
|
|
42
53
|
'data-width': String(attributes.width)
|
|
43
54
|
};
|
|
44
55
|
}
|
|
56
|
+
},
|
|
57
|
+
align: {
|
|
58
|
+
default: null,
|
|
59
|
+
parseHTML: function parseHTML(element) {
|
|
60
|
+
return element.getAttribute('data-align') || null;
|
|
61
|
+
},
|
|
62
|
+
renderHTML: function renderHTML(attributes) {
|
|
63
|
+
if (!attributes.align) return {};
|
|
64
|
+
return {
|
|
65
|
+
'data-align': attributes.align
|
|
66
|
+
};
|
|
67
|
+
}
|
|
45
68
|
}
|
|
46
69
|
};
|
|
47
70
|
},
|
|
@@ -51,10 +74,21 @@ export var FlowExtension = function FlowExtension(props) {
|
|
|
51
74
|
getAttrs: function getAttrs(dom) {
|
|
52
75
|
if (!(dom instanceof HTMLElement)) return false;
|
|
53
76
|
var code = dom.getAttribute('data-code') || '';
|
|
54
|
-
var
|
|
77
|
+
var widthAttr = dom.getAttribute('data-width');
|
|
78
|
+
var width = null;
|
|
79
|
+
if (widthAttr) {
|
|
80
|
+
if (widthAttr.endsWith('%')) {
|
|
81
|
+
width = widthAttr;
|
|
82
|
+
} else {
|
|
83
|
+
var numWidth = parseFloat(widthAttr);
|
|
84
|
+
width = isNaN(numWidth) ? null : numWidth;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
var align = dom.getAttribute('data-align') || null;
|
|
55
88
|
return {
|
|
56
89
|
code: code,
|
|
57
|
-
width: width
|
|
90
|
+
width: width,
|
|
91
|
+
align: align
|
|
58
92
|
};
|
|
59
93
|
}
|
|
60
94
|
}];
|
|
@@ -69,6 +103,8 @@ export var FlowExtension = function FlowExtension(props) {
|
|
|
69
103
|
'data-code': attrs.code
|
|
70
104
|
} : {}, attrs.width ? {
|
|
71
105
|
'data-width': String(attrs.width)
|
|
106
|
+
} : {}, attrs.align ? {
|
|
107
|
+
'data-align': attrs.align
|
|
72
108
|
} : {}, this.options.HTMLAttributes, HTMLAttributes)];
|
|
73
109
|
},
|
|
74
110
|
renderMarkdown: function renderMarkdown(node) {
|
|
@@ -87,7 +123,8 @@ export var FlowExtension = function FlowExtension(props) {
|
|
|
87
123
|
type: _this.name,
|
|
88
124
|
attrs: {
|
|
89
125
|
code: options.code || '',
|
|
90
|
-
width: options.width || null
|
|
126
|
+
width: options.width || null,
|
|
127
|
+
align: options.align || null
|
|
91
128
|
}
|
|
92
129
|
});
|
|
93
130
|
};
|
package/dist/index.css
CHANGED
package/dist/themes/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ declare module '@mui/material/styles' {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
export declare const theme: <T extends string = "
|
|
29
|
+
export declare const theme: <T extends string = "light" | "dark">({ mode, colors, theme: customTheme, }: {
|
|
30
30
|
mode: T;
|
|
31
31
|
colors?: Record<T, any> | undefined;
|
|
32
32
|
theme?: any;
|
package/dist/type/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Editor, Extension } from '@tiptap/core';
|
|
|
4
4
|
import { TableOfContentsOptions } from '@tiptap/extension-table-of-contents';
|
|
5
5
|
import { YoutubeOptions } from '@tiptap/extension-youtube';
|
|
6
6
|
import { UseEditorOptions } from '@tiptap/react';
|
|
7
|
+
import { MermaidConfig } from 'mermaid';
|
|
7
8
|
export type { Editor } from '@tiptap/react';
|
|
8
9
|
export interface MenuItem {
|
|
9
10
|
label?: React.ReactNode;
|
|
@@ -108,6 +109,7 @@ export type MentionExtensionProps = {
|
|
|
108
109
|
}) => Promise<MentionItems>;
|
|
109
110
|
};
|
|
110
111
|
export type NodeOrMetaOrSuggestionOrExtensionOptions = {
|
|
112
|
+
mermaidOptions?: Partial<MermaidConfig>;
|
|
111
113
|
youtubeOptions?: Partial<YoutubeOptions>;
|
|
112
114
|
tableOfContentsOptions?: Partial<TableOfContentsOptions>;
|
|
113
115
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ctzhian/tiptap",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"description": "基于 Tiptap 二次开发的编辑器组件",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"katex": "^0.16.22",
|
|
122
122
|
"linkifyjs": "^4.3.2",
|
|
123
123
|
"lowlight": "^3.3.0",
|
|
124
|
-
"mermaid": "^
|
|
124
|
+
"mermaid": "^11.12.2",
|
|
125
125
|
"react-ace": "^14.0.1",
|
|
126
126
|
"react-colorful": "^5.6.1",
|
|
127
127
|
"react-image-crop": "^11.0.10",
|