@ctzhian/tiptap 1.11.0 → 1.11.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 +1 -1
- package/dist/extension/node/Alert.js +17 -56
- package/package.json +1 -1
package/dist/Editor/demo.js
CHANGED
|
@@ -158,7 +158,7 @@ var Reader = function Reader() {
|
|
|
158
158
|
}
|
|
159
159
|
return onUpload;
|
|
160
160
|
}(),
|
|
161
|
-
content: "
|
|
161
|
+
content: ":::alert\n# \u798F\u5EFA\u5E08\u5927\u4F60\u770B\n\u526F\u4E66\u8BB0\u770B\u5230\u4E86\u53D1\u9001\n:::\n\n:::alert {variant=\"warning\", type=\"text\"}\nThis is a warning message with **bold** text.\n:::"
|
|
162
162
|
}),
|
|
163
163
|
editor = _useTiptap.editor;
|
|
164
164
|
return /*#__PURE__*/React.createElement(EditorThemeProvider, {
|
|
@@ -1,7 +1,13 @@
|
|
|
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
|
+
import { createBlockMarkdownSpec, mergeAttributes, Node } from '@tiptap/core';
|
|
2
8
|
import { ReactNodeViewRenderer } from '@tiptap/react';
|
|
3
9
|
import AlertView from "../component/Alert";
|
|
4
|
-
export var AlertExtension = Node.create({
|
|
10
|
+
export var AlertExtension = Node.create(_objectSpread(_objectSpread({
|
|
5
11
|
name: 'alert',
|
|
6
12
|
group: 'block',
|
|
7
13
|
content: 'block+',
|
|
@@ -26,14 +32,14 @@ export var AlertExtension = Node.create({
|
|
|
26
32
|
}
|
|
27
33
|
},
|
|
28
34
|
variant: {
|
|
29
|
-
default: '
|
|
35
|
+
default: 'default',
|
|
30
36
|
renderHTML: function renderHTML(attributes) {
|
|
31
37
|
return {
|
|
32
38
|
'data-variant': attributes.variant
|
|
33
39
|
};
|
|
34
40
|
},
|
|
35
41
|
parseHTML: function parseHTML(element) {
|
|
36
|
-
return element.getAttribute('data-variant') || '
|
|
42
|
+
return element.getAttribute('data-variant') || 'default';
|
|
37
43
|
}
|
|
38
44
|
},
|
|
39
45
|
type: {
|
|
@@ -59,55 +65,10 @@ export var AlertExtension = Node.create({
|
|
|
59
65
|
return ['div', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
|
|
60
66
|
'data-node': 'alert'
|
|
61
67
|
}), 0];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
},
|
|
68
|
+
}
|
|
69
|
+
}, createBlockMarkdownSpec({
|
|
70
|
+
nodeName: 'alert'
|
|
71
|
+
})), {}, {
|
|
111
72
|
addCommands: function addCommands() {
|
|
112
73
|
var _this = this;
|
|
113
74
|
return {
|
|
@@ -116,7 +77,7 @@ export var AlertExtension = Node.create({
|
|
|
116
77
|
return function (_ref2) {
|
|
117
78
|
var commands = _ref2.commands;
|
|
118
79
|
var id = "alert_".concat(Math.random().toString(36).slice(2));
|
|
119
|
-
var variant = attrs.variant || '
|
|
80
|
+
var variant = attrs.variant || 'default';
|
|
120
81
|
var type = attrs.type || 'icon';
|
|
121
82
|
return commands.wrapIn(_this.name, {
|
|
122
83
|
id: id,
|
|
@@ -146,7 +107,7 @@ export var AlertExtension = Node.create({
|
|
|
146
107
|
return function (_ref5) {
|
|
147
108
|
var commands = _ref5.commands;
|
|
148
109
|
var id = "alert_".concat(Math.random().toString(36).slice(2));
|
|
149
|
-
var variant = attrs.variant || '
|
|
110
|
+
var variant = attrs.variant || 'default';
|
|
150
111
|
var type = attrs.type || 'icon';
|
|
151
112
|
return commands.toggleWrap(_this.name, {
|
|
152
113
|
id: id,
|
|
@@ -160,5 +121,5 @@ export var AlertExtension = Node.create({
|
|
|
160
121
|
addNodeView: function addNodeView() {
|
|
161
122
|
return ReactNodeViewRenderer(AlertView);
|
|
162
123
|
}
|
|
163
|
-
});
|
|
124
|
+
}));
|
|
164
125
|
export default AlertExtension;
|