@ctzhian/tiptap 1.10.3 → 1.11.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 +3 -13
- package/dist/component/Toolbar/EditorInsert/index.js +1 -1
- package/dist/extension/index.js +2 -4
- package/dist/extension/node/Alert.js +48 -0
- package/dist/extension/node/Script.d.ts +2 -0
- package/dist/extension/node/Script.js +70 -0
- package/dist/extension/node/index.d.ts +1 -0
- package/dist/extension/node/index.js +1 -0
- package/package.json +1 -1
package/dist/Editor/demo.js
CHANGED
|
@@ -3,7 +3,7 @@ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyri
|
|
|
3
3
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
4
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
5
|
import { Editor, EditorThemeProvider, EditorToolbar, useTiptap } from "./..";
|
|
6
|
-
import { Box
|
|
6
|
+
import { Box } from '@mui/material';
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import "../index.css";
|
|
9
9
|
var Reader = function Reader() {
|
|
@@ -158,22 +158,12 @@ var Reader = function Reader() {
|
|
|
158
158
|
}
|
|
159
159
|
return onUpload;
|
|
160
160
|
}(),
|
|
161
|
-
content: "
|
|
161
|
+
content: "### Subscript\n\nH~2~O\n\n### Superscript\n\nX^2^\n"
|
|
162
162
|
}),
|
|
163
163
|
editor = _useTiptap.editor;
|
|
164
164
|
return /*#__PURE__*/React.createElement(EditorThemeProvider, {
|
|
165
165
|
mode: "light"
|
|
166
|
-
}, /*#__PURE__*/React.createElement(
|
|
167
|
-
variant: "contained",
|
|
168
|
-
onClick: function onClick() {
|
|
169
|
-
editor.commands.insertContent('# 标题1\n\n<a target="_blank" type="icon" href="http://localhost:8000/components/editor" title="发生的发">发生的发</a>\n\n## 标题2\n标题*斜体*\n标题**加粗**\n标题~~删除线~~\n标题`代码`\n标题^上标^,标题~下标~\n标题==高亮==', {
|
|
170
|
-
contentType: 'markdown'
|
|
171
|
-
});
|
|
172
|
-
// editor.commands.setContent('# 标题1\n## 标题2\n标题*斜体*\n标题**加粗**\n标题~~删除线~~\n标题`代码`\n标题^上标^,标题~下标~\n标题==高亮==', {
|
|
173
|
-
// contentType: 'markdown'
|
|
174
|
-
// })
|
|
175
|
-
}
|
|
176
|
-
}, "\u6D4B\u8BD5\u4E00\u4E0B"), /*#__PURE__*/React.createElement(Box, {
|
|
166
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
177
167
|
sx: {
|
|
178
168
|
border: '1px solid #eee',
|
|
179
169
|
borderRadius: '10px',
|
|
@@ -223,7 +223,7 @@ var EditorInsert = function EditorInsert(_ref) {
|
|
|
223
223
|
onClick: function onClick() {
|
|
224
224
|
return editor.chain().focus().setDetails().run();
|
|
225
225
|
}
|
|
226
|
-
}], _toConsumableArray(
|
|
226
|
+
}], _toConsumableArray(isMarkdown ? [{
|
|
227
227
|
label: '警告提示',
|
|
228
228
|
key: 'highlight',
|
|
229
229
|
icon: /*#__PURE__*/React.createElement(Information2LineIcon, {
|
package/dist/extension/index.js
CHANGED
|
@@ -6,8 +6,6 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
|
6
6
|
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; }
|
|
7
7
|
import Highlight from '@tiptap/extension-highlight';
|
|
8
8
|
import InvisibleCharacters from '@tiptap/extension-invisible-characters';
|
|
9
|
-
import Subscript from '@tiptap/extension-subscript';
|
|
10
|
-
import Superscript from '@tiptap/extension-superscript';
|
|
11
9
|
import TextAlign from '@tiptap/extension-text-align';
|
|
12
10
|
import { TextStyleKit } from '@tiptap/extension-text-style';
|
|
13
11
|
import { CharacterCount, Placeholder } from '@tiptap/extensions';
|
|
@@ -16,7 +14,7 @@ import StarterKit from '@tiptap/starter-kit';
|
|
|
16
14
|
import { PLACEHOLDER } from "../contants/placeholder";
|
|
17
15
|
import { AiWritingExtension, SlashCommands, StructuredDiffExtension } from "./extension";
|
|
18
16
|
import { CodeExtension } from "./mark/Code";
|
|
19
|
-
import { AlertExtension, AudioExtension, BlockAttachmentExtension, BlockLinkExtension, CodeBlockLowlightExtension, CustomBlockMathExtension, CustomHorizontalRule, CustomInlineMathExtension, DetailsContentExtension, DetailsExtension, DetailsSummaryExtension, EmojiExtension, FileHandlerExtension, IframeExtension, ImageExtension, Indent, InlineAttachmentExtension, InlineLinkExtension, InlineUploadProgressExtension, ListExtension, MentionExtension, TableExtension, TableOfContents, UploadProgressExtension, VerticalAlign, VideoExtension, YamlFormat, YoutubeExtension } from "./node";
|
|
17
|
+
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";
|
|
20
18
|
export var getExtensions = function getExtensions(_ref) {
|
|
21
19
|
var contentType = _ref.contentType,
|
|
22
20
|
limit = _ref.limit,
|
|
@@ -45,7 +43,7 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
45
43
|
color: 'var(--mui-palette-primary-main)',
|
|
46
44
|
width: 2
|
|
47
45
|
}
|
|
48
|
-
}),
|
|
46
|
+
}), TextStyleKit, CodeExtension, ListExtension, EmojiExtension, AlertExtension, CustomSubscript, DetailsExtension, CustomSuperscript, InlineLinkExtension, DetailsContentExtension, DetailsSummaryExtension, CodeBlockLowlightExtension, InlineUploadProgressExtension, YamlFormat, CustomHorizontalRule].concat(_toConsumableArray(TableExtension({
|
|
49
47
|
editable: editable
|
|
50
48
|
})), [TableOfContents({
|
|
51
49
|
onTocUpdate: onTocUpdate
|
|
@@ -60,6 +60,54 @@ export var AlertExtension = Node.create({
|
|
|
60
60
|
'data-node': 'alert'
|
|
61
61
|
}), 0];
|
|
62
62
|
},
|
|
63
|
+
markdownTokenizer: {
|
|
64
|
+
name: 'alert',
|
|
65
|
+
level: 'block',
|
|
66
|
+
start: function start(src) {
|
|
67
|
+
return src.indexOf(':::alert');
|
|
68
|
+
},
|
|
69
|
+
tokenize: function tokenize(src, _tokens, helpers) {
|
|
70
|
+
var match = /^:::alert(?:\s+([^\s\n]+))?(?:\s+([^\s\n]+))?\s*\n([\s\S]*?)\n?:::(?:\s*\n|$)/.exec(src);
|
|
71
|
+
if (!match) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
var variant = match[1] || 'info';
|
|
75
|
+
var alertType = match[2] || 'icon';
|
|
76
|
+
var body = match[3] || '';
|
|
77
|
+
return {
|
|
78
|
+
type: 'alert',
|
|
79
|
+
raw: match[0],
|
|
80
|
+
variant: variant,
|
|
81
|
+
alertType: alertType,
|
|
82
|
+
tokens: helpers.blockTokens(body)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
renderMarkdown: function renderMarkdown(node, helpers) {
|
|
87
|
+
var _node$attrs, _node$attrs2;
|
|
88
|
+
var variant = ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.variant) || 'info';
|
|
89
|
+
var alertType = ((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.type) || 'icon';
|
|
90
|
+
var headerParts = [':::alert'];
|
|
91
|
+
if (variant && variant !== 'info') {
|
|
92
|
+
headerParts.push(variant);
|
|
93
|
+
}
|
|
94
|
+
if (alertType && alertType !== 'icon') {
|
|
95
|
+
headerParts.push(alertType);
|
|
96
|
+
}
|
|
97
|
+
var header = headerParts.join(' ');
|
|
98
|
+
var content = node.content ? helpers.renderChildren(node.content, '\n\n') : '';
|
|
99
|
+
var body = content ? "\n".concat(content) : '';
|
|
100
|
+
return "".concat(header).concat(body, "\n:::");
|
|
101
|
+
},
|
|
102
|
+
parseMarkdown: function parseMarkdown(token, helpers) {
|
|
103
|
+
var variant = token.variant || 'info';
|
|
104
|
+
var alertType = token.alertType || 'icon';
|
|
105
|
+
var content = helpers.parseChildren(token.tokens || []);
|
|
106
|
+
return helpers.createNode('alert', {
|
|
107
|
+
variant: variant,
|
|
108
|
+
type: alertType
|
|
109
|
+
}, content);
|
|
110
|
+
},
|
|
63
111
|
addCommands: function addCommands() {
|
|
64
112
|
var _this = this;
|
|
65
113
|
return {
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const CustomSubscript: import("@tiptap/core").Mark<import("@tiptap/extension-subscript").SubscriptExtensionOptions, any>;
|
|
2
|
+
export declare const CustomSuperscript: import("@tiptap/core").Mark<import("@tiptap/extension-superscript").SuperscriptExtensionOptions, any>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import Subscript from '@tiptap/extension-subscript';
|
|
2
|
+
import Superscript from '@tiptap/extension-superscript';
|
|
3
|
+
export var CustomSubscript = Subscript.extend({
|
|
4
|
+
markdownTokenName: 'sub',
|
|
5
|
+
renderMarkdown: function renderMarkdown(node, helpers) {
|
|
6
|
+
var content = helpers.renderChildren(node);
|
|
7
|
+
return "~".concat(content, "~");
|
|
8
|
+
},
|
|
9
|
+
parseMarkdown: function parseMarkdown(token, helpers) {
|
|
10
|
+
var content = helpers.parseInline(token.tokens || []);
|
|
11
|
+
if (!content.length && token.text) {
|
|
12
|
+
content.push(helpers.createTextNode(token.text));
|
|
13
|
+
}
|
|
14
|
+
return helpers.applyMark('subscript', content);
|
|
15
|
+
},
|
|
16
|
+
markdownTokenizer: {
|
|
17
|
+
name: 'sub',
|
|
18
|
+
level: 'inline',
|
|
19
|
+
start: function start(src) {
|
|
20
|
+
return src.indexOf('~');
|
|
21
|
+
},
|
|
22
|
+
tokenize: function tokenize(src, _tokens, helpers) {
|
|
23
|
+
var match = /^~(?!~)([\s\S]+?)~(?!~)/.exec(src);
|
|
24
|
+
if (!match) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
var innerContent = match[1];
|
|
28
|
+
return {
|
|
29
|
+
type: 'sub',
|
|
30
|
+
raw: match[0],
|
|
31
|
+
text: innerContent,
|
|
32
|
+
tokens: helpers.inlineTokens(innerContent)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
export var CustomSuperscript = Superscript.extend({
|
|
38
|
+
markdownTokenName: 'sup',
|
|
39
|
+
renderMarkdown: function renderMarkdown(node, helpers) {
|
|
40
|
+
var content = helpers.renderChildren(node);
|
|
41
|
+
return "^".concat(content, "^");
|
|
42
|
+
},
|
|
43
|
+
parseMarkdown: function parseMarkdown(token, helpers) {
|
|
44
|
+
var content = helpers.parseInline(token.tokens || []);
|
|
45
|
+
if (!content.length && token.text) {
|
|
46
|
+
content.push(helpers.createTextNode(token.text));
|
|
47
|
+
}
|
|
48
|
+
return helpers.applyMark('superscript', content);
|
|
49
|
+
},
|
|
50
|
+
markdownTokenizer: {
|
|
51
|
+
name: 'sup',
|
|
52
|
+
level: 'inline',
|
|
53
|
+
start: function start(src) {
|
|
54
|
+
return src.indexOf('^');
|
|
55
|
+
},
|
|
56
|
+
tokenize: function tokenize(src, _tokens, helpers) {
|
|
57
|
+
var match = /^\^(?!\^)([\s\S]+?)\^(?!\^)/.exec(src);
|
|
58
|
+
if (!match) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
var innerContent = match[1];
|
|
62
|
+
return {
|
|
63
|
+
type: 'sup',
|
|
64
|
+
raw: match[0],
|
|
65
|
+
text: innerContent,
|
|
66
|
+
tokens: helpers.inlineTokens(innerContent)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|