@ctzhian/tiptap 1.12.5 → 1.12.7
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/EditorMarkdown/Toolbar.d.ts +10 -0
- package/dist/EditorMarkdown/Toolbar.js +840 -0
- package/dist/EditorMarkdown/demo.js +87 -104
- package/dist/EditorMarkdown/index.d.ts +2 -0
- package/dist/EditorMarkdown/index.js +46 -31
- package/dist/component/CustomDragHandle/index.js +3 -3
- package/dist/component/FloatingPopover/index.js +1 -1
- package/dist/component/Menu/NestedList.d.ts +1 -0
- package/dist/component/Menu/NestedList.js +6 -3
- package/dist/component/Menu/index.d.ts +4 -1
- package/dist/component/Menu/index.js +16 -5
- package/dist/component/Toolbar/EditorInsert/index.js +3 -3
- package/dist/contants/enums.js +1 -1
- package/dist/contants/markdown-placeholder.d.ts +1 -1
- package/dist/contants/markdown-placeholder.js +1 -1
- package/dist/contants/slash-commands.js +1 -1
- package/dist/extension/component/Link/Markdown.d.ts +4 -0
- package/dist/extension/component/Link/Markdown.js +40 -0
- package/dist/extension/component/SlashCommandsList/index.js +6 -6
- package/dist/extension/component/UploadProgress/index.d.ts +1 -1
- package/dist/extension/index.js +12 -11
- package/dist/extension/mark/Link.d.ts +2 -0
- package/dist/extension/mark/Link.js +84 -57
- package/dist/extension/node/Link/index.js +0 -19
- package/dist/extension/node/Video.js +0 -3
- package/dist/type/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useTheme } from "@mui/material/styles";
|
|
2
|
+
import { MarkViewContent } from "@tiptap/react";
|
|
3
|
+
import React, { useCallback } from "react";
|
|
4
|
+
var LinkViewWrapper = function LinkViewWrapper(_ref) {
|
|
5
|
+
var _mark$attrs2, _mark$attrs3, _mark$attrs4;
|
|
6
|
+
var editor = _ref.editor,
|
|
7
|
+
mark = _ref.mark;
|
|
8
|
+
var theme = useTheme();
|
|
9
|
+
var handleClick = useCallback(function (e) {
|
|
10
|
+
var _mark$attrs;
|
|
11
|
+
if (mark !== null && mark !== void 0 && (_mark$attrs = mark.attrs) !== null && _mark$attrs !== void 0 && _mark$attrs.download) {
|
|
12
|
+
e.preventDefault();
|
|
13
|
+
var _href = mark.attrs.href;
|
|
14
|
+
if (_href) {
|
|
15
|
+
var link = document.createElement('a');
|
|
16
|
+
link.href = _href;
|
|
17
|
+
link.download = mark.attrs.download === '' ? _href.split('/').pop() || 'download' : mark.attrs.download;
|
|
18
|
+
document.body.appendChild(link);
|
|
19
|
+
link.click();
|
|
20
|
+
document.body.removeChild(link);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}, [mark]);
|
|
24
|
+
var href = (mark === null || mark === void 0 || (_mark$attrs2 = mark.attrs) === null || _mark$attrs2 === void 0 ? void 0 : _mark$attrs2.href) || '';
|
|
25
|
+
var target = (mark === null || mark === void 0 || (_mark$attrs3 = mark.attrs) === null || _mark$attrs3 === void 0 ? void 0 : _mark$attrs3.target) || '_blank';
|
|
26
|
+
var download = mark === null || mark === void 0 || (_mark$attrs4 = mark.attrs) === null || _mark$attrs4 === void 0 ? void 0 : _mark$attrs4.download;
|
|
27
|
+
return /*#__PURE__*/React.createElement(MarkViewContent, {
|
|
28
|
+
as: "a",
|
|
29
|
+
href: href,
|
|
30
|
+
target: download ? undefined : target,
|
|
31
|
+
download: download || undefined,
|
|
32
|
+
onClick: handleClick,
|
|
33
|
+
style: {
|
|
34
|
+
color: theme.palette.primary.main,
|
|
35
|
+
textDecoration: 'underline',
|
|
36
|
+
cursor: 'pointer'
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
export default LinkViewWrapper;
|
|
@@ -71,7 +71,7 @@ var SlashCommandsList = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
71
71
|
})
|
|
72
72
|
}]
|
|
73
73
|
}, {
|
|
74
|
-
label: '
|
|
74
|
+
label: '警告块',
|
|
75
75
|
key: 'highlight',
|
|
76
76
|
icon: /*#__PURE__*/React.createElement(Information2LineIcon, {
|
|
77
77
|
sx: {
|
|
@@ -89,7 +89,7 @@ var SlashCommandsList = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
89
89
|
}),
|
|
90
90
|
onClick: function onClick() {
|
|
91
91
|
var node = items.find(function (it) {
|
|
92
|
-
return it.title === '
|
|
92
|
+
return it.title === '警告块';
|
|
93
93
|
});
|
|
94
94
|
if (node) command(_objectSpread(_objectSpread({}, node), {}, {
|
|
95
95
|
attrs: {
|
|
@@ -109,7 +109,7 @@ var SlashCommandsList = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
109
109
|
}),
|
|
110
110
|
onClick: function onClick() {
|
|
111
111
|
var node = items.find(function (it) {
|
|
112
|
-
return it.title === '
|
|
112
|
+
return it.title === '警告块';
|
|
113
113
|
});
|
|
114
114
|
if (node) command(_objectSpread(_objectSpread({}, node), {}, {
|
|
115
115
|
attrs: {
|
|
@@ -129,7 +129,7 @@ var SlashCommandsList = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
129
129
|
}),
|
|
130
130
|
onClick: function onClick() {
|
|
131
131
|
var node = items.find(function (it) {
|
|
132
|
-
return it.title === '
|
|
132
|
+
return it.title === '警告块';
|
|
133
133
|
});
|
|
134
134
|
if (node) command(_objectSpread(_objectSpread({}, node), {}, {
|
|
135
135
|
attrs: {
|
|
@@ -149,7 +149,7 @@ var SlashCommandsList = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
149
149
|
}),
|
|
150
150
|
onClick: function onClick() {
|
|
151
151
|
var node = items.find(function (it) {
|
|
152
|
-
return it.title === '
|
|
152
|
+
return it.title === '警告块';
|
|
153
153
|
});
|
|
154
154
|
if (node) command(_objectSpread(_objectSpread({}, node), {}, {
|
|
155
155
|
attrs: {
|
|
@@ -169,7 +169,7 @@ var SlashCommandsList = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
169
169
|
}),
|
|
170
170
|
onClick: function onClick() {
|
|
171
171
|
var node = items.find(function (it) {
|
|
172
|
-
return it.title === '
|
|
172
|
+
return it.title === '警告块';
|
|
173
173
|
});
|
|
174
174
|
if (node) command(_objectSpread(_objectSpread({}, node), {}, {
|
|
175
175
|
attrs: {
|
|
@@ -7,6 +7,6 @@ export interface UploadProgressAttributes {
|
|
|
7
7
|
tempId: string;
|
|
8
8
|
}
|
|
9
9
|
export declare const getFileIcon: (fileType: string) => React.JSX.Element;
|
|
10
|
-
export declare const getFileTypeText: (fileType: string) => "
|
|
10
|
+
export declare const getFileTypeText: (fileType: string) => "视频" | "音频" | "图片" | "文件";
|
|
11
11
|
declare const UploadProgressView: React.FC<NodeViewProps>;
|
|
12
12
|
export default UploadProgressView;
|
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, SlashCommands, StructuredDiffExtension } from "./extension";
|
|
16
16
|
import { CodeExtension } from "./mark/Code";
|
|
17
|
+
import CustomLink from "./mark/Link";
|
|
17
18
|
import { AlertExtension, AudioExtension, BlockAttachmentExtension, BlockLinkExtension, CodeBlockLowlightExtension, CustomBlockMathExtension, CustomHorizontalRule, CustomInlineMathExtension, CustomSubscript, CustomSuperscript, DetailsContentExtension, DetailsExtension, DetailsSummaryExtension, EmojiExtension, FileHandlerExtension, 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 contentType = _ref.contentType,
|
|
@@ -43,7 +44,15 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
43
44
|
color: 'var(--mui-palette-primary-main)',
|
|
44
45
|
width: 2
|
|
45
46
|
}
|
|
46
|
-
}), TextStyleKit, CodeExtension, ListExtension, EmojiExtension, AlertExtension, CustomSubscript, DetailsExtension, CustomSuperscript,
|
|
47
|
+
}), TextStyleKit, CodeExtension, ListExtension, EmojiExtension, AlertExtension, CustomSubscript, DetailsExtension, CustomSuperscript, DetailsContentExtension, DetailsSummaryExtension, CodeBlockLowlightExtension, InlineUploadProgressExtension, YamlFormat, CustomHorizontalRule, VideoExtension({
|
|
48
|
+
onUpload: onUpload,
|
|
49
|
+
onError: onError,
|
|
50
|
+
onValidateUrl: onValidateUrl
|
|
51
|
+
}), AudioExtension({
|
|
52
|
+
onUpload: onUpload,
|
|
53
|
+
onError: onError,
|
|
54
|
+
onValidateUrl: onValidateUrl
|
|
55
|
+
})].concat(_toConsumableArray(TableExtension({
|
|
47
56
|
editable: editable
|
|
48
57
|
})), [TableOfContents({
|
|
49
58
|
onTocUpdate: onTocUpdate
|
|
@@ -92,7 +101,7 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
92
101
|
}
|
|
93
102
|
})]);
|
|
94
103
|
if (contentType === 'markdown') {
|
|
95
|
-
defaultExtensions.push(Markdown.configure({
|
|
104
|
+
defaultExtensions.push(CustomLink, Markdown.configure({
|
|
96
105
|
indentation: {
|
|
97
106
|
style: 'space',
|
|
98
107
|
size: 2
|
|
@@ -104,15 +113,7 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
104
113
|
}
|
|
105
114
|
}));
|
|
106
115
|
} else {
|
|
107
|
-
defaultExtensions.push.apply(defaultExtensions, [BlockLinkExtension, IframeExtension({
|
|
108
|
-
onError: onError,
|
|
109
|
-
onValidateUrl: onValidateUrl
|
|
110
|
-
}), VideoExtension({
|
|
111
|
-
onUpload: onUpload,
|
|
112
|
-
onError: onError,
|
|
113
|
-
onValidateUrl: onValidateUrl
|
|
114
|
-
}), AudioExtension({
|
|
115
|
-
onUpload: onUpload,
|
|
116
|
+
defaultExtensions.push.apply(defaultExtensions, [InlineLinkExtension, BlockLinkExtension, IframeExtension({
|
|
116
117
|
onError: onError,
|
|
117
118
|
onValidateUrl: onValidateUrl
|
|
118
119
|
}), BlockAttachmentExtension({
|
|
@@ -1,58 +1,85 @@
|
|
|
1
|
-
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
// @ts-nocheck
|
|
2
8
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
9
|
+
import { Link } from "@tiptap/extension-link";
|
|
10
|
+
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
11
|
+
import { ReactMarkViewRenderer } from "@tiptap/react";
|
|
12
|
+
import LinkViewWrapper from "../component/Link/Markdown";
|
|
13
|
+
var CustomLink = Link.extend({
|
|
14
|
+
addMarkView: function addMarkView() {
|
|
15
|
+
return ReactMarkViewRenderer(LinkViewWrapper);
|
|
16
|
+
},
|
|
17
|
+
addAttributes: function addAttributes() {
|
|
18
|
+
var _this$parent;
|
|
19
|
+
return _objectSpread(_objectSpread({}, (_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.call(this)), {}, {
|
|
20
|
+
download: {
|
|
21
|
+
default: null,
|
|
22
|
+
parseHTML: function parseHTML(element) {
|
|
23
|
+
return element.getAttribute('download');
|
|
24
|
+
},
|
|
25
|
+
renderHTML: function renderHTML(attributes) {
|
|
26
|
+
if (!attributes.download) {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
download: attributes.download
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
// 确保能够解析 HTML 中的 <a> 标签
|
|
37
|
+
parseHTML: function parseHTML() {
|
|
38
|
+
return [{
|
|
39
|
+
tag: 'a[href]',
|
|
40
|
+
getAttrs: function getAttrs(element) {
|
|
41
|
+
if (typeof element === 'string') return false;
|
|
42
|
+
var href = element.getAttribute('href');
|
|
43
|
+
if (!href) return false;
|
|
44
|
+
return {
|
|
45
|
+
href: href,
|
|
46
|
+
target: element.getAttribute('target') || '_blank',
|
|
47
|
+
download: element.getAttribute('download')
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}];
|
|
51
|
+
},
|
|
52
|
+
renderHTML: function renderHTML(_ref) {
|
|
53
|
+
var HTMLAttributes = _ref.HTMLAttributes;
|
|
54
|
+
return ['a', HTMLAttributes, 0];
|
|
55
|
+
},
|
|
56
|
+
addProseMirrorPlugins: function addProseMirrorPlugins() {
|
|
57
|
+
return [new Plugin({
|
|
58
|
+
key: new PluginKey('linkDownloadHandler'),
|
|
59
|
+
props: {
|
|
60
|
+
handleDOMEvents: {
|
|
61
|
+
click: function click(view, event) {
|
|
62
|
+
var target = event.target;
|
|
63
|
+
var link = target.closest('a[download]');
|
|
64
|
+
if (link) {
|
|
65
|
+
var downloadAttr = link.getAttribute('download');
|
|
66
|
+
var href = link.getAttribute('href');
|
|
67
|
+
if (href && downloadAttr !== null) {
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
var downloadLink = document.createElement('a');
|
|
70
|
+
downloadLink.href = href;
|
|
71
|
+
downloadLink.download = downloadAttr === '' ? href.split('/').pop() || 'download' : downloadAttr;
|
|
72
|
+
document.body.appendChild(downloadLink);
|
|
73
|
+
downloadLink.click();
|
|
74
|
+
document.body.removeChild(downloadLink);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
})];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
export default CustomLink;
|
|
@@ -199,25 +199,6 @@ export var InlineLinkExtension = Node.create({
|
|
|
199
199
|
}
|
|
200
200
|
return ['a', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), title];
|
|
201
201
|
},
|
|
202
|
-
markdownTokenName: 'link',
|
|
203
|
-
parseMarkdown: function parseMarkdown(token, helpers) {
|
|
204
|
-
var content = helpers.parseInline(token.tokens || []);
|
|
205
|
-
return {
|
|
206
|
-
type: 'inlineLink',
|
|
207
|
-
attrs: {
|
|
208
|
-
href: token.href,
|
|
209
|
-
title: token.title || null,
|
|
210
|
-
type: 'text'
|
|
211
|
-
},
|
|
212
|
-
content: content
|
|
213
|
-
};
|
|
214
|
-
},
|
|
215
|
-
renderMarkdown: function renderMarkdown(node, h) {
|
|
216
|
-
var _node$attrs, _node$attrs2;
|
|
217
|
-
var href = ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.href) || '';
|
|
218
|
-
var text = ((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.title) || h.renderChildren(node) || '';
|
|
219
|
-
return "[".concat(text, "](").concat(href, ")");
|
|
220
|
-
},
|
|
221
202
|
addCommands: function addCommands() {
|
|
222
203
|
var _this3 = this;
|
|
223
204
|
return {
|
package/dist/type/index.d.ts
CHANGED