@ctzhian/tiptap 1.9.1 → 1.10.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 +2 -2
- package/dist/component/CustomBubbleMenu/index.js +1 -1
- package/dist/extension/component/UploadProgress/index.d.ts +1 -1
- package/dist/extension/index.js +3 -2
- package/dist/extension/node/HorizontalRule.d.ts +1 -0
- package/dist/extension/node/HorizontalRule.js +23 -0
- package/dist/extension/node/YamlFormat.d.ts +55 -0
- package/dist/extension/node/YamlFormat.js +347 -0
- package/dist/extension/node/index.d.ts +2 -0
- package/dist/extension/node/index.js +2 -0
- package/dist/index.css +12 -0
- package/dist/type/index.d.ts +1 -1
- package/package.json +33 -32
package/dist/Editor/demo.js
CHANGED
|
@@ -7,7 +7,7 @@ import { Box, Button } from '@mui/material';
|
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import "../index.css";
|
|
9
9
|
var Reader = function Reader() {
|
|
10
|
-
var isMarkdown =
|
|
10
|
+
var isMarkdown = true;
|
|
11
11
|
var _useTiptap = useTiptap({
|
|
12
12
|
editable: true,
|
|
13
13
|
contentType: isMarkdown ? 'markdown' : 'html',
|
|
@@ -158,7 +158,7 @@ var Reader = function Reader() {
|
|
|
158
158
|
}
|
|
159
159
|
return onUpload;
|
|
160
160
|
}(),
|
|
161
|
-
content:
|
|
161
|
+
content: "---\nissue_key: gitlab://git.in.chaitin.net/dev/board/ai-ready?issue=1\ncode_repo: https://git.in.chaitin.net/dev/board/ai-ready.git\npriority: high\ndesigned_by: jinzhao.liu\ndev_env: n/a\nstart_from: main\nmerge_to: main\nestimated_loc: 500\ndifficulty_level: medium\n---\n\n\u53D1\u5565\u4E86\u89C1\u98CE\u4F7F\u8235\u4F60\u770B**fjsldk**\u653E\u5047 sd \u5361\u90A3\n\n# \u6807\u98981\n"
|
|
162
162
|
}),
|
|
163
163
|
editor = _useTiptap.editor;
|
|
164
164
|
return /*#__PURE__*/React.createElement(EditorThemeProvider, {
|
|
@@ -84,7 +84,7 @@ var CustomBubbleMenu = function CustomBubbleMenu(_ref) {
|
|
|
84
84
|
// return cellSelection.$anchorCell.pos !== cellSelection.$headCell.pos;
|
|
85
85
|
// }
|
|
86
86
|
// }
|
|
87
|
-
if (editor.state.selection.empty || editor.isActive('image') || editor.isActive('video') || editor.isActive('audio') || editor.isActive('emoji') || editor.isActive('codeBlock') || editor.isActive('blockMath') || editor.isActive('inlineMath') || editor.isActive('blockLink') || editor.isActive('inlineLink') || editor.isActive('blockAttachment') || editor.isActive('inlineAttachment') || editor.isActive('horizontalRule') || editor.isActive('iframe')) {
|
|
87
|
+
if (editor.state.selection.empty || editor.isActive('image') || editor.isActive('video') || editor.isActive('audio') || editor.isActive('emoji') || editor.isActive('codeBlock') || editor.isActive('blockMath') || editor.isActive('inlineMath') || editor.isActive('blockLink') || editor.isActive('inlineLink') || editor.isActive('blockAttachment') || editor.isActive('inlineAttachment') || editor.isActive('horizontalRule') || editor.isActive('iframe') || editor.isActive('yamlFormat')) {
|
|
88
88
|
return false;
|
|
89
89
|
}
|
|
90
90
|
return true;
|
|
@@ -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
|
@@ -16,7 +16,7 @@ import StarterKit from '@tiptap/starter-kit';
|
|
|
16
16
|
import { PLACEHOLDER } from "../contants/placeholder";
|
|
17
17
|
import { AiWritingExtension, SlashCommands, StructuredDiffExtension } from "./extension";
|
|
18
18
|
import { CodeExtension } from "./mark/Code";
|
|
19
|
-
import { AlertExtension, AudioExtension, BlockAttachmentExtension, BlockLinkExtension, CodeBlockLowlightExtension, CustomBlockMathExtension, CustomInlineMathExtension, DetailsContentExtension, DetailsExtension, DetailsSummaryExtension, EmojiExtension, FileHandlerExtension, IframeExtension, ImageExtension, Indent, InlineAttachmentExtension, InlineLinkExtension, InlineUploadProgressExtension, ListExtension, MentionExtension, TableExtension, TableOfContents, UploadProgressExtension, VerticalAlign, VideoExtension, YoutubeExtension } from "./node";
|
|
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";
|
|
20
20
|
export var getExtensions = function getExtensions(_ref) {
|
|
21
21
|
var contentType = _ref.contentType,
|
|
22
22
|
limit = _ref.limit,
|
|
@@ -35,6 +35,7 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
35
35
|
link: false,
|
|
36
36
|
code: false,
|
|
37
37
|
codeBlock: false,
|
|
38
|
+
horizontalRule: false,
|
|
38
39
|
listItem: false,
|
|
39
40
|
orderedList: false,
|
|
40
41
|
bulletList: false,
|
|
@@ -44,7 +45,7 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
44
45
|
color: 'var(--mui-palette-primary-main)',
|
|
45
46
|
width: 2
|
|
46
47
|
}
|
|
47
|
-
}), Subscript, Superscript, TextStyleKit, CodeExtension, ListExtension, EmojiExtension, DetailsExtension, InlineLinkExtension, DetailsContentExtension, DetailsSummaryExtension, CodeBlockLowlightExtension].concat(_toConsumableArray(TableExtension({
|
|
48
|
+
}), Subscript, Superscript, TextStyleKit, CodeExtension, ListExtension, EmojiExtension, DetailsExtension, InlineLinkExtension, DetailsContentExtension, DetailsSummaryExtension, CodeBlockLowlightExtension, YamlFormat, CustomHorizontalRule].concat(_toConsumableArray(TableExtension({
|
|
48
49
|
editable: editable
|
|
49
50
|
})), [TableOfContents({
|
|
50
51
|
onTocUpdate: onTocUpdate
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CustomHorizontalRule: import("@tiptap/core").Node<import("@tiptap/extension-horizontal-rule").HorizontalRuleOptions, any>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { InputRule } from '@tiptap/core';
|
|
2
|
+
import HorizontalRule from "@tiptap/extension-horizontal-rule";
|
|
3
|
+
export var CustomHorizontalRule = HorizontalRule.extend({
|
|
4
|
+
addInputRules: function addInputRules() {
|
|
5
|
+
var hrInputRule = new InputRule({
|
|
6
|
+
find: /^(?:(?:-\s?){3,}|(?:\*\s?){3,}|(?:_\s?){3,})\s$/,
|
|
7
|
+
handler: function handler(_ref) {
|
|
8
|
+
var state = _ref.state,
|
|
9
|
+
range = _ref.range,
|
|
10
|
+
chain = _ref.chain;
|
|
11
|
+
if (range.from === 1) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
chain().deleteRange(range).setHorizontalRule().run();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return [hrInputRule];
|
|
18
|
+
}
|
|
19
|
+
}).configure({
|
|
20
|
+
HTMLAttributes: {
|
|
21
|
+
class: 'custom-horizontal-rule'
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
export interface YamlFormatOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Define whether the node should be exited on triple enter.
|
|
5
|
+
* @default true
|
|
6
|
+
*/
|
|
7
|
+
exitOnTripleEnter: boolean | null | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Define whether the node should be exited on arrow down if there is no node after it.
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
12
|
+
exitOnArrowDown: boolean | null | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Enable tab key for indentation in code blocks.
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
enableTabIndentation: boolean | null | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* The number of spaces to use for tab indentation.
|
|
20
|
+
* @default 4
|
|
21
|
+
*/
|
|
22
|
+
tabSize: number | null | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Custom HTML attributes that should be added to the rendered HTML tag.
|
|
25
|
+
* @default {}
|
|
26
|
+
* @example { class: 'foo' }
|
|
27
|
+
*/
|
|
28
|
+
HTMLAttributes: Record<string, any>;
|
|
29
|
+
}
|
|
30
|
+
declare module '@tiptap/core' {
|
|
31
|
+
interface Commands<ReturnType> {
|
|
32
|
+
yamlFormat: {
|
|
33
|
+
/**
|
|
34
|
+
* Set a yaml format
|
|
35
|
+
* @example editor.commands.setYamlFormat()
|
|
36
|
+
*/
|
|
37
|
+
setYamlFormat: () => ReturnType;
|
|
38
|
+
/**
|
|
39
|
+
* Toggle a yaml format
|
|
40
|
+
* @example editor.commands.toggleYamlFormat()
|
|
41
|
+
*/
|
|
42
|
+
toggleYamlFormat: () => ReturnType;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Matches a yaml format with backticks.
|
|
48
|
+
* Only matches exactly `--- ` (three dashes followed by a space)
|
|
49
|
+
*/
|
|
50
|
+
export declare const yamlInputRegex: RegExp;
|
|
51
|
+
/**
|
|
52
|
+
* This extension allows you to create yaml format.
|
|
53
|
+
* @see https://tiptap.dev/api/nodes/code-block
|
|
54
|
+
*/
|
|
55
|
+
export declare const YamlFormat: Node<YamlFormatOptions, any>;
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { InputRule, mergeAttributes, Node } from '@tiptap/core';
|
|
2
|
+
import { Plugin, PluginKey, Selection, TextSelection } from '@tiptap/pm/state';
|
|
3
|
+
var DEFAULT_TAB_SIZE = 4;
|
|
4
|
+
/**
|
|
5
|
+
* Matches a yaml format with backticks.
|
|
6
|
+
* Only matches exactly `--- ` (three dashes followed by a space)
|
|
7
|
+
*/
|
|
8
|
+
export var yamlInputRegex = /^---\s$/;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* This extension allows you to create yaml format.
|
|
12
|
+
* @see https://tiptap.dev/api/nodes/code-block
|
|
13
|
+
*/
|
|
14
|
+
export var YamlFormat = Node.create({
|
|
15
|
+
name: 'yamlFormat',
|
|
16
|
+
addOptions: function addOptions() {
|
|
17
|
+
return {
|
|
18
|
+
exitOnTripleEnter: true,
|
|
19
|
+
exitOnArrowDown: true,
|
|
20
|
+
enableTabIndentation: false,
|
|
21
|
+
tabSize: DEFAULT_TAB_SIZE,
|
|
22
|
+
HTMLAttributes: {}
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
content: 'text*',
|
|
26
|
+
marks: '',
|
|
27
|
+
group: 'block',
|
|
28
|
+
code: true,
|
|
29
|
+
defining: true,
|
|
30
|
+
addAttributes: function addAttributes() {
|
|
31
|
+
return {};
|
|
32
|
+
},
|
|
33
|
+
parseHTML: function parseHTML() {
|
|
34
|
+
return [{
|
|
35
|
+
tag: 'pre[data-type="yaml-frontmatter"]',
|
|
36
|
+
preserveWhitespace: 'full'
|
|
37
|
+
}];
|
|
38
|
+
},
|
|
39
|
+
renderHTML: function renderHTML(_ref) {
|
|
40
|
+
var node = _ref.node,
|
|
41
|
+
HTMLAttributes = _ref.HTMLAttributes;
|
|
42
|
+
return ['pre', mergeAttributes({
|
|
43
|
+
'data-type': 'yaml-frontmatter'
|
|
44
|
+
}, this.options.HTMLAttributes, HTMLAttributes), ['code', {}, 0]];
|
|
45
|
+
},
|
|
46
|
+
markdownTokenName: 'frontmatter',
|
|
47
|
+
parseMarkdown: function parseMarkdown(token, helpers) {
|
|
48
|
+
var _token$raw;
|
|
49
|
+
if (((_token$raw = token.raw) === null || _token$raw === void 0 ? void 0 : _token$raw.startsWith('---')) === false) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
return helpers.createNode('yamlFormat', {}, token.text ? [helpers.createTextNode(token.text)] : []);
|
|
53
|
+
},
|
|
54
|
+
renderMarkdown: function renderMarkdown(node, h) {
|
|
55
|
+
var content = node.content ? h.renderChildren(node.content) : '';
|
|
56
|
+
if (!content) {
|
|
57
|
+
return "---\n---";
|
|
58
|
+
}
|
|
59
|
+
return "---\n".concat(content, "\n---");
|
|
60
|
+
},
|
|
61
|
+
addCommands: function addCommands() {
|
|
62
|
+
var _this = this;
|
|
63
|
+
return {
|
|
64
|
+
setYamlFormat: function setYamlFormat() {
|
|
65
|
+
return function (ctx) {
|
|
66
|
+
return ctx.commands.setNode(_this.name, {});
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
toggleYamlFormat: function toggleYamlFormat() {
|
|
70
|
+
return function (ctx) {
|
|
71
|
+
return ctx.commands.toggleNode(_this.name, 'paragraph', {});
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
addKeyboardShortcuts: function addKeyboardShortcuts() {
|
|
77
|
+
var _this2 = this;
|
|
78
|
+
return {
|
|
79
|
+
Backspace: function Backspace() {
|
|
80
|
+
var _this2$editor$state$s = _this2.editor.state.selection,
|
|
81
|
+
empty = _this2$editor$state$s.empty,
|
|
82
|
+
$anchor = _this2$editor$state$s.$anchor;
|
|
83
|
+
var isAtStart = $anchor.pos === 1;
|
|
84
|
+
if (!empty || $anchor.parent.type.name !== _this2.name) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if (isAtStart || !$anchor.parent.textContent.length) {
|
|
88
|
+
return _this2.editor.commands.clearNodes();
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
},
|
|
92
|
+
Tab: function Tab(_ref2) {
|
|
93
|
+
var _this2$options$tabSiz;
|
|
94
|
+
var editor = _ref2.editor;
|
|
95
|
+
if (!_this2.options.enableTabIndentation) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
var tabSize = (_this2$options$tabSiz = _this2.options.tabSize) !== null && _this2$options$tabSiz !== void 0 ? _this2$options$tabSiz : DEFAULT_TAB_SIZE;
|
|
99
|
+
var state = editor.state;
|
|
100
|
+
var selection = state.selection;
|
|
101
|
+
var $from = selection.$from,
|
|
102
|
+
empty = selection.empty;
|
|
103
|
+
if ($from.parent.type !== _this2.type) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
var indent = ' '.repeat(tabSize);
|
|
107
|
+
if (empty) {
|
|
108
|
+
return editor.commands.insertContent(indent);
|
|
109
|
+
}
|
|
110
|
+
return editor.commands.command(function (_ref3) {
|
|
111
|
+
var tr = _ref3.tr;
|
|
112
|
+
var from = selection.from,
|
|
113
|
+
to = selection.to;
|
|
114
|
+
var text = state.doc.textBetween(from, to, '\n', '\n');
|
|
115
|
+
var lines = text.split('\n');
|
|
116
|
+
var indentedText = lines.map(function (line) {
|
|
117
|
+
return indent + line;
|
|
118
|
+
}).join('\n');
|
|
119
|
+
tr.replaceWith(from, to, state.schema.text(indentedText));
|
|
120
|
+
return true;
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
'Shift-Tab': function ShiftTab(_ref4) {
|
|
124
|
+
var _this2$options$tabSiz2;
|
|
125
|
+
var editor = _ref4.editor;
|
|
126
|
+
if (!_this2.options.enableTabIndentation) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
var tabSize = (_this2$options$tabSiz2 = _this2.options.tabSize) !== null && _this2$options$tabSiz2 !== void 0 ? _this2$options$tabSiz2 : DEFAULT_TAB_SIZE;
|
|
130
|
+
var state = editor.state;
|
|
131
|
+
var selection = state.selection;
|
|
132
|
+
var $from = selection.$from,
|
|
133
|
+
empty = selection.empty;
|
|
134
|
+
if ($from.parent.type !== _this2.type) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
if (empty) {
|
|
138
|
+
return editor.commands.command(function (_ref5) {
|
|
139
|
+
var _currentLine$match;
|
|
140
|
+
var tr = _ref5.tr;
|
|
141
|
+
var pos = $from.pos;
|
|
142
|
+
var yamlFormatStart = $from.start();
|
|
143
|
+
var yamlFormatEnd = $from.end();
|
|
144
|
+
var allText = state.doc.textBetween(yamlFormatStart, yamlFormatEnd, '\n', '\n');
|
|
145
|
+
var lines = allText.split('\n');
|
|
146
|
+
var currentLineIndex = 0;
|
|
147
|
+
var charCount = 0;
|
|
148
|
+
var relativeCursorPos = pos - yamlFormatStart;
|
|
149
|
+
for (var i = 0; i < lines.length; i += 1) {
|
|
150
|
+
if (charCount + lines[i].length >= relativeCursorPos) {
|
|
151
|
+
currentLineIndex = i;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
charCount += lines[i].length + 1;
|
|
155
|
+
}
|
|
156
|
+
var currentLine = lines[currentLineIndex];
|
|
157
|
+
var leadingSpaces = ((_currentLine$match = currentLine.match(/^ */)) === null || _currentLine$match === void 0 ? void 0 : _currentLine$match[0]) || '';
|
|
158
|
+
var spacesToRemove = Math.min(leadingSpaces.length, tabSize);
|
|
159
|
+
if (spacesToRemove === 0) {
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
var lineStartPos = yamlFormatStart;
|
|
163
|
+
for (var _i = 0; _i < currentLineIndex; _i += 1) {
|
|
164
|
+
lineStartPos += lines[_i].length + 1;
|
|
165
|
+
}
|
|
166
|
+
tr.delete(lineStartPos, lineStartPos + spacesToRemove);
|
|
167
|
+
var cursorPosInLine = pos - yamlFormatStart;
|
|
168
|
+
if (cursorPosInLine <= spacesToRemove) {
|
|
169
|
+
tr.setSelection(TextSelection.create(tr.doc, yamlFormatStart));
|
|
170
|
+
}
|
|
171
|
+
return true;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return editor.commands.command(function (_ref6) {
|
|
175
|
+
var tr = _ref6.tr;
|
|
176
|
+
var from = selection.from,
|
|
177
|
+
to = selection.to;
|
|
178
|
+
var text = state.doc.textBetween(from, to, '\n', '\n');
|
|
179
|
+
var lines = text.split('\n');
|
|
180
|
+
var reverseIndentText = lines.map(function (line) {
|
|
181
|
+
var _line$match;
|
|
182
|
+
var leadingSpaces = ((_line$match = line.match(/^ */)) === null || _line$match === void 0 ? void 0 : _line$match[0]) || '';
|
|
183
|
+
var spacesToRemove = Math.min(leadingSpaces.length, tabSize);
|
|
184
|
+
return line.slice(spacesToRemove);
|
|
185
|
+
}).join('\n');
|
|
186
|
+
tr.replaceWith(from, to, state.schema.text(reverseIndentText));
|
|
187
|
+
return true;
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
Enter: function Enter(_ref7) {
|
|
191
|
+
var editor = _ref7.editor;
|
|
192
|
+
if (!_this2.options.exitOnTripleEnter) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
var state = editor.state;
|
|
196
|
+
var selection = state.selection;
|
|
197
|
+
var $from = selection.$from,
|
|
198
|
+
empty = selection.empty;
|
|
199
|
+
if (!empty || $from.parent.type !== _this2.type) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
var isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
|
|
203
|
+
var endsWithDoubleNewline = $from.parent.textContent.endsWith('\n\n');
|
|
204
|
+
if (!isAtEnd || !endsWithDoubleNewline) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
return editor.chain().command(function (_ref8) {
|
|
208
|
+
var tr = _ref8.tr;
|
|
209
|
+
tr.delete($from.pos - 2, $from.pos);
|
|
210
|
+
return true;
|
|
211
|
+
}).exitCode().run();
|
|
212
|
+
},
|
|
213
|
+
ArrowDown: function ArrowDown(_ref9) {
|
|
214
|
+
var editor = _ref9.editor;
|
|
215
|
+
if (!_this2.options.exitOnArrowDown) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
var state = editor.state;
|
|
219
|
+
var selection = state.selection,
|
|
220
|
+
doc = state.doc;
|
|
221
|
+
var $from = selection.$from,
|
|
222
|
+
empty = selection.empty;
|
|
223
|
+
if (!empty || $from.parent.type !== _this2.type) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
var isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
|
|
227
|
+
if (!isAtEnd) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
var after = $from.after();
|
|
231
|
+
if (after === undefined) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
var nodeAfter = doc.nodeAt(after);
|
|
235
|
+
if (nodeAfter) {
|
|
236
|
+
return editor.commands.command(function (_ref10) {
|
|
237
|
+
var tr = _ref10.tr;
|
|
238
|
+
tr.setSelection(Selection.near(doc.resolve(after)));
|
|
239
|
+
return true;
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
return editor.commands.exitCode();
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
},
|
|
246
|
+
addInputRules: function addInputRules() {
|
|
247
|
+
var _this3 = this;
|
|
248
|
+
return [new InputRule({
|
|
249
|
+
find: yamlInputRegex,
|
|
250
|
+
handler: function handler(_ref11) {
|
|
251
|
+
var state = _ref11.state,
|
|
252
|
+
range = _ref11.range,
|
|
253
|
+
chain = _ref11.chain;
|
|
254
|
+
if (range.from !== 1) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
chain().command(function (_ref12) {
|
|
258
|
+
var tr = _ref12.tr;
|
|
259
|
+
tr.delete(range.from, range.to);
|
|
260
|
+
return true;
|
|
261
|
+
}).setNode(_this3.name, {}).run();
|
|
262
|
+
}
|
|
263
|
+
})];
|
|
264
|
+
},
|
|
265
|
+
addProseMirrorPlugins: function addProseMirrorPlugins() {
|
|
266
|
+
var _this4 = this;
|
|
267
|
+
return [new Plugin({
|
|
268
|
+
key: new PluginKey('yamlFormatHandler'),
|
|
269
|
+
props: {
|
|
270
|
+
handlePaste: function handlePaste(view, event) {
|
|
271
|
+
if (!event.clipboardData) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
if (_this4.editor.isActive(_this4.type.name)) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
var text = event.clipboardData.getData('text/plain');
|
|
278
|
+
if (!text) {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
var _view$state = view.state,
|
|
282
|
+
tr = _view$state.tr,
|
|
283
|
+
schema = _view$state.schema;
|
|
284
|
+
var isAtDocStart = view.state.selection.$from.pos === 1;
|
|
285
|
+
var fmRegex = /^-{3,}\s*\n([\s\S]*?)\n-{3,}\s*$/;
|
|
286
|
+
var match = fmRegex.exec(text.replace(/\r\n?/g, '\n'));
|
|
287
|
+
if (!isAtDocStart || !match) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
var content = match[1] || '';
|
|
291
|
+
var textNode = schema.text(content);
|
|
292
|
+
var node = _this4.type.create({}, textNode);
|
|
293
|
+
tr.replaceSelectionWith(node);
|
|
294
|
+
if (tr.selection.$from.parent.type !== _this4.type) {
|
|
295
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2))));
|
|
296
|
+
}
|
|
297
|
+
tr.setMeta('paste', true);
|
|
298
|
+
view.dispatch(tr);
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
appendTransaction: function appendTransaction(transactions, oldState, newState) {
|
|
303
|
+
var _attrs;
|
|
304
|
+
var docChanged = transactions.some(function (tr) {
|
|
305
|
+
return tr.docChanged;
|
|
306
|
+
});
|
|
307
|
+
if (!docChanged) {
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
var doc = newState.doc;
|
|
311
|
+
var firstNode = doc.firstChild;
|
|
312
|
+
if (!firstNode || firstNode.type.name !== 'horizontalRule') {
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
var isInitialLoad = transactions.some(function (tr) {
|
|
316
|
+
var addToHistory = tr.getMeta('addToHistory');
|
|
317
|
+
var isPasteHandled = tr.getMeta('paste');
|
|
318
|
+
return (addToHistory === false || addToHistory === undefined) && !isPasteHandled;
|
|
319
|
+
});
|
|
320
|
+
if (!isInitialLoad) {
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
doc.descendants(function (node, pos) {
|
|
324
|
+
return true;
|
|
325
|
+
});
|
|
326
|
+
var secondNode = doc.maybeChild(1);
|
|
327
|
+
var isSecondNodeHeading = secondNode && secondNode.type.name === 'heading' && ((_attrs = secondNode.attrs) === null || _attrs === void 0 ? void 0 : _attrs.level) === 2;
|
|
328
|
+
if (isSecondNodeHeading) {
|
|
329
|
+
var tr = newState.tr;
|
|
330
|
+
var replaceEnd = firstNode.nodeSize + secondNode.nodeSize;
|
|
331
|
+
var yamlContent = '';
|
|
332
|
+
doc.nodesBetween(firstNode.nodeSize, replaceEnd, function (node, pos) {
|
|
333
|
+
if (node.isText && node.text) {
|
|
334
|
+
yamlContent += node.text;
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
yamlContent = yamlContent.trim();
|
|
338
|
+
var textNode = yamlContent ? newState.schema.text(yamlContent) : undefined;
|
|
339
|
+
var yamlNode = _this4.type.create({}, textNode ? [textNode] : []);
|
|
340
|
+
tr.replaceRangeWith(0, replaceEnd, yamlNode);
|
|
341
|
+
return tr;
|
|
342
|
+
}
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
})];
|
|
346
|
+
}
|
|
347
|
+
});
|
|
@@ -5,6 +5,7 @@ export * from './CodeBlockLowlight';
|
|
|
5
5
|
export * from './Details';
|
|
6
6
|
export * from './Emoji';
|
|
7
7
|
export * from './FileHandler';
|
|
8
|
+
export * from './HorizontalRule';
|
|
8
9
|
export * from './Iframe';
|
|
9
10
|
export * from './Image';
|
|
10
11
|
export * from './Indent';
|
|
@@ -18,4 +19,5 @@ export * from './TableOfContents';
|
|
|
18
19
|
export * from './UploadProgress';
|
|
19
20
|
export * from './VerticalAlign';
|
|
20
21
|
export * from './Video';
|
|
22
|
+
export * from './YamlFormat';
|
|
21
23
|
export * from './Youtube';
|
|
@@ -5,6 +5,7 @@ export * from "./CodeBlockLowlight";
|
|
|
5
5
|
export * from "./Details";
|
|
6
6
|
export * from "./Emoji";
|
|
7
7
|
export * from "./FileHandler";
|
|
8
|
+
export * from "./HorizontalRule";
|
|
8
9
|
export * from "./Iframe";
|
|
9
10
|
export * from "./Image";
|
|
10
11
|
export * from "./Indent";
|
|
@@ -18,4 +19,5 @@ export * from "./TableOfContents";
|
|
|
18
19
|
export * from "./UploadProgress";
|
|
19
20
|
export * from "./VerticalAlign";
|
|
20
21
|
export * from "./Video";
|
|
22
|
+
export * from "./YamlFormat";
|
|
21
23
|
export * from "./Youtube";
|
package/dist/index.css
CHANGED
|
@@ -190,6 +190,12 @@
|
|
|
190
190
|
background-color: #171c19;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
+
.tiptap.ProseMirror pre[data-type="yaml-frontmatter"] {
|
|
194
|
+
padding: 8px 16px;
|
|
195
|
+
margin-bottom: 20px;
|
|
196
|
+
border-radius: var(--mui-shape-borderRadius);
|
|
197
|
+
}
|
|
198
|
+
|
|
193
199
|
.tiptap.ProseMirror code {
|
|
194
200
|
padding: 2px 8px;
|
|
195
201
|
margin: 0 4px;
|
|
@@ -203,6 +209,12 @@
|
|
|
203
209
|
border-radius: 6px;
|
|
204
210
|
}
|
|
205
211
|
|
|
212
|
+
.tiptap.ProseMirror pre[data-type="yaml-frontmatter"] code {
|
|
213
|
+
border: none;
|
|
214
|
+
margin: 0;
|
|
215
|
+
display: inline-block;
|
|
216
|
+
}
|
|
217
|
+
|
|
206
218
|
.tiptap.ProseMirror pre code {
|
|
207
219
|
color: inherit;
|
|
208
220
|
padding: 0;
|
package/dist/type/index.d.ts
CHANGED
|
@@ -101,7 +101,7 @@ export type UseTiptapProps = {
|
|
|
101
101
|
export type GetExtensionsProps = ExtensionRelativeProps;
|
|
102
102
|
export type UseTiptapReturn = {
|
|
103
103
|
editor: Editor;
|
|
104
|
-
setContent: (value: string, type
|
|
104
|
+
setContent: (value: string, type?: UseEditorOptions['contentType']) => void;
|
|
105
105
|
getContent: () => string;
|
|
106
106
|
getMarkdown: () => string;
|
|
107
107
|
getText: () => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ctzhian/tiptap",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "基于 Tiptap 二次开发的编辑器组件",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -81,37 +81,38 @@
|
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
83
|
"@floating-ui/dom": "^1.7.2",
|
|
84
|
-
"@tiptap/core": "^3.
|
|
85
|
-
"@tiptap/extension-bubble-menu": "^3.
|
|
86
|
-
"@tiptap/extension-code": "^3.
|
|
87
|
-
"@tiptap/extension-code-block-lowlight": "^3.
|
|
88
|
-
"@tiptap/extension-details": "^3.
|
|
89
|
-
"@tiptap/extension-drag-handle-react": "^3.
|
|
90
|
-
"@tiptap/extension-emoji": "^3.
|
|
91
|
-
"@tiptap/extension-file-handler": "^3.
|
|
92
|
-
"@tiptap/extension-highlight": "^3.
|
|
93
|
-
"@tiptap/extension-
|
|
94
|
-
"@tiptap/extension-
|
|
95
|
-
"@tiptap/extension-
|
|
96
|
-
"@tiptap/extension-
|
|
97
|
-
"@tiptap/extension-
|
|
98
|
-
"@tiptap/extension-
|
|
99
|
-
"@tiptap/extension-
|
|
100
|
-
"@tiptap/extension-
|
|
101
|
-
"@tiptap/extension-
|
|
102
|
-
"@tiptap/extension-table
|
|
103
|
-
"@tiptap/extension-
|
|
104
|
-
"@tiptap/extension-text-
|
|
105
|
-
"@tiptap/extension-
|
|
106
|
-
"@tiptap/extension-
|
|
107
|
-
"@tiptap/
|
|
108
|
-
"@tiptap/
|
|
109
|
-
"@tiptap/
|
|
110
|
-
"@tiptap/
|
|
111
|
-
"@tiptap/
|
|
112
|
-
"@tiptap/
|
|
113
|
-
"@tiptap/
|
|
114
|
-
"@tiptap/
|
|
84
|
+
"@tiptap/core": "^3.10.1",
|
|
85
|
+
"@tiptap/extension-bubble-menu": "^3.10.1",
|
|
86
|
+
"@tiptap/extension-code": "^3.10.1",
|
|
87
|
+
"@tiptap/extension-code-block-lowlight": "^3.10.1",
|
|
88
|
+
"@tiptap/extension-details": "^3.10.1",
|
|
89
|
+
"@tiptap/extension-drag-handle-react": "^3.10.1",
|
|
90
|
+
"@tiptap/extension-emoji": "^3.10.1",
|
|
91
|
+
"@tiptap/extension-file-handler": "^3.10.1",
|
|
92
|
+
"@tiptap/extension-highlight": "^3.10.1",
|
|
93
|
+
"@tiptap/extension-horizontal-rule": "^3.10.1",
|
|
94
|
+
"@tiptap/extension-image": "^3.10.1",
|
|
95
|
+
"@tiptap/extension-invisible-characters": "^3.10.1",
|
|
96
|
+
"@tiptap/extension-link": "^3.10.1",
|
|
97
|
+
"@tiptap/extension-list": "^3.10.1",
|
|
98
|
+
"@tiptap/extension-mathematics": "^3.10.1",
|
|
99
|
+
"@tiptap/extension-mention": "^3.10.1",
|
|
100
|
+
"@tiptap/extension-subscript": "^3.10.1",
|
|
101
|
+
"@tiptap/extension-superscript": "^3.10.1",
|
|
102
|
+
"@tiptap/extension-table": "^3.10.1",
|
|
103
|
+
"@tiptap/extension-table-of-contents": "^3.10.1",
|
|
104
|
+
"@tiptap/extension-text-align": "^3.10.1",
|
|
105
|
+
"@tiptap/extension-text-style": "^3.10.1",
|
|
106
|
+
"@tiptap/extension-unique-id": "^3.10.1",
|
|
107
|
+
"@tiptap/extension-youtube": "^3.10.1",
|
|
108
|
+
"@tiptap/extensions": "^3.10.1",
|
|
109
|
+
"@tiptap/html": "^3.10.1",
|
|
110
|
+
"@tiptap/markdown": "^3.10.1",
|
|
111
|
+
"@tiptap/pm": "^3.10.1",
|
|
112
|
+
"@tiptap/react": "^3.10.1",
|
|
113
|
+
"@tiptap/starter-kit": "^3.10.1",
|
|
114
|
+
"@tiptap/static-renderer": "^3.10.1",
|
|
115
|
+
"@tiptap/suggestion": "^3.10.1",
|
|
115
116
|
"core-js": "^3.46.0",
|
|
116
117
|
"diff-match-patch": "^1.0.5",
|
|
117
118
|
"highlight.js": "^11.11.1",
|