@ctzhian/tiptap 2.1.12 → 2.1.13
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/asset/css/index.css +3 -1
- package/dist/component/Icons/bilibili-line-icon.d.ts +6 -0
- package/dist/component/Icons/bilibili-line-icon.js +13 -0
- package/dist/component/Icons/index.d.ts +1 -0
- package/dist/component/Icons/index.js +1 -0
- package/dist/component/Toolbar/EditorInsert/index.js +20 -3
- package/dist/contants/enums.d.ts +5 -0
- package/dist/contants/enums.js +24 -0
- package/dist/contants/slash-commands.js +117 -119
- package/dist/extension/component/Iframe/Insert.d.ts +4 -2
- package/dist/extension/component/Iframe/Insert.js +12 -14
- package/dist/extension/component/Iframe/Readonly.d.ts +2 -1
- package/dist/extension/component/Iframe/Readonly.js +14 -5
- package/dist/extension/component/Iframe/index.js +389 -171
- package/dist/extension/component/SlashCommandsList/index.js +1 -1
- package/dist/extension/node/FileHandler.d.ts +1 -1
- package/dist/extension/node/Iframe.d.ts +3 -1
- package/dist/extension/node/Iframe.js +51 -8
- package/dist/extension/node/Table.d.ts +1 -1
- package/dist/index.css +0 -1
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +8 -0
- package/package.json +1 -1
|
@@ -25,7 +25,7 @@ var SlashCommandsList = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
25
25
|
}, /*#__PURE__*/React.createElement(Stack, {
|
|
26
26
|
direction: 'row',
|
|
27
27
|
flexWrap: 'wrap'
|
|
28
|
-
}, items.slice(0,
|
|
28
|
+
}, items.slice(0, 16).map(function (item, index) {
|
|
29
29
|
return /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
30
30
|
key: index,
|
|
31
31
|
shortcutKey: (item === null || item === void 0 ? void 0 : item.shortcutKey) || [],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { UploadFunction } from "../../type";
|
|
2
2
|
export declare const FileHandlerExtension: (props: {
|
|
3
3
|
onUpload?: UploadFunction;
|
|
4
|
-
}) => import("@tiptap/core").Extension<Omit<import("@tiptap/extension-file-handler").FileHandlePluginOptions, "
|
|
4
|
+
}) => import("@tiptap/core").Extension<Omit<import("@tiptap/extension-file-handler").FileHandlePluginOptions, "key" | "editor">, any>;
|
|
@@ -4,9 +4,11 @@ declare module '@tiptap/core' {
|
|
|
4
4
|
interface Commands<ReturnType> {
|
|
5
5
|
iframe: {
|
|
6
6
|
setIframe: (options: {
|
|
7
|
+
type?: 'iframe' | 'bilibili';
|
|
7
8
|
src: string;
|
|
8
|
-
width?: number;
|
|
9
|
+
width?: number | string;
|
|
9
10
|
height?: number;
|
|
11
|
+
align?: 'left' | 'center' | 'right';
|
|
10
12
|
}) => ReturnType;
|
|
11
13
|
};
|
|
12
14
|
}
|
|
@@ -35,10 +35,15 @@ export var IframeExtension = function IframeExtension(props) {
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
width: {
|
|
38
|
-
default:
|
|
38
|
+
default: '100%',
|
|
39
39
|
parseHTML: function parseHTML(element) {
|
|
40
40
|
var width = element.getAttribute('width');
|
|
41
|
-
|
|
41
|
+
if (width) {
|
|
42
|
+
if (width.endsWith('%')) return width;
|
|
43
|
+
var numWidth = parseInt(width, 10);
|
|
44
|
+
return isNaN(numWidth) ? '100%' : numWidth;
|
|
45
|
+
}
|
|
46
|
+
return '100%';
|
|
42
47
|
},
|
|
43
48
|
renderHTML: function renderHTML(attributes) {
|
|
44
49
|
return {
|
|
@@ -57,6 +62,29 @@ export var IframeExtension = function IframeExtension(props) {
|
|
|
57
62
|
height: attributes.height
|
|
58
63
|
};
|
|
59
64
|
}
|
|
65
|
+
},
|
|
66
|
+
type: {
|
|
67
|
+
default: 'iframe',
|
|
68
|
+
parseHTML: function parseHTML(element) {
|
|
69
|
+
return element.getAttribute('data-type');
|
|
70
|
+
},
|
|
71
|
+
renderHTML: function renderHTML(attributes) {
|
|
72
|
+
return {
|
|
73
|
+
'data-type': attributes.type
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
align: {
|
|
78
|
+
default: null,
|
|
79
|
+
parseHTML: function parseHTML(element) {
|
|
80
|
+
return element.getAttribute('data-align');
|
|
81
|
+
},
|
|
82
|
+
renderHTML: function renderHTML(attributes) {
|
|
83
|
+
if (!attributes.align) return {};
|
|
84
|
+
return {
|
|
85
|
+
'data-align': attributes.align
|
|
86
|
+
};
|
|
87
|
+
}
|
|
60
88
|
}
|
|
61
89
|
};
|
|
62
90
|
},
|
|
@@ -67,12 +95,24 @@ export var IframeExtension = function IframeExtension(props) {
|
|
|
67
95
|
if (!(dom instanceof HTMLElement)) return false;
|
|
68
96
|
var src = dom.getAttribute('src');
|
|
69
97
|
if (!src) return false;
|
|
70
|
-
var
|
|
98
|
+
var widthAttr = dom.getAttribute('width');
|
|
99
|
+
var width = '100%';
|
|
100
|
+
if (widthAttr) {
|
|
101
|
+
// 如果是百分比,保留字符串格式
|
|
102
|
+
if (widthAttr.endsWith('%')) {
|
|
103
|
+
width = widthAttr;
|
|
104
|
+
} else {
|
|
105
|
+
// 否则解析为数字
|
|
106
|
+
var numWidth = parseInt(widthAttr, 10);
|
|
107
|
+
width = isNaN(numWidth) ? '100%' : numWidth;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
71
110
|
var height = dom.getAttribute('height') ? parseInt(dom.getAttribute('height'), 10) : dom.style.height ? parseInt(dom.style.height, 10) : 400;
|
|
72
111
|
return {
|
|
73
112
|
src: src,
|
|
74
113
|
width: width,
|
|
75
|
-
height: height
|
|
114
|
+
height: height,
|
|
115
|
+
align: dom.getAttribute('data-align') || dom.getAttribute('align')
|
|
76
116
|
};
|
|
77
117
|
}
|
|
78
118
|
}];
|
|
@@ -94,9 +134,10 @@ export var IframeExtension = function IframeExtension(props) {
|
|
|
94
134
|
var _ref3 = node.attrs,
|
|
95
135
|
src = _ref3.src,
|
|
96
136
|
width = _ref3.width,
|
|
97
|
-
height = _ref3.height
|
|
137
|
+
height = _ref3.height,
|
|
138
|
+
align = _ref3['data-align'];
|
|
98
139
|
if (!src || src.trim() === '') return '';
|
|
99
|
-
return "<iframe src=\"".concat(src, "\" ").concat(width ? "width=\"".concat(width, "\"") : '', " ").concat(height ? "height=\"".concat(height, "\"") : '', " frameborder=\"0\" allowfullscreen=\"true\" autoplay=\"0\" loop=\"0\"></iframe>");
|
|
140
|
+
return "<iframe src=\"".concat(src, "\" ").concat(width ? "width=\"".concat(width, "\"") : '', " ").concat(height ? "height=\"".concat(height, "\"") : '', " ").concat(align ? "data-align=\"".concat(align, "\"") : '', " frameborder=\"0\" allowfullscreen=\"true\" autoplay=\"0\" loop=\"0\"></iframe>");
|
|
100
141
|
},
|
|
101
142
|
addCommands: function addCommands() {
|
|
102
143
|
var _this = this;
|
|
@@ -107,9 +148,11 @@ export var IframeExtension = function IframeExtension(props) {
|
|
|
107
148
|
return commands.insertContent({
|
|
108
149
|
type: _this.name,
|
|
109
150
|
attrs: {
|
|
151
|
+
type: options.type || 'iframe',
|
|
110
152
|
src: options.src,
|
|
111
|
-
width: options.width ||
|
|
112
|
-
height: options.height || 400
|
|
153
|
+
width: options.width || '100%',
|
|
154
|
+
height: options.height || 400,
|
|
155
|
+
align: options.align || null
|
|
113
156
|
}
|
|
114
157
|
});
|
|
115
158
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Extension } from '@tiptap/core';
|
|
2
2
|
export declare const TableExtension: ({ editable }: {
|
|
3
3
|
editable: boolean;
|
|
4
|
-
}) => (import("@tiptap/core").Node<import("@tiptap/extension-table").TableOptions, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableHeaderOptions, any>
|
|
4
|
+
}) => (Extension<any, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableOptions, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableHeaderOptions, any>)[];
|
|
5
5
|
export default TableExtension;
|
package/dist/index.css
CHANGED
package/dist/util/index.d.ts
CHANGED
package/dist/util/index.js
CHANGED
|
@@ -88,4 +88,12 @@ export var getLinkAttributesWithSelectedText = function getLinkAttributesWithSel
|
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
return {};
|
|
91
|
+
};
|
|
92
|
+
export var extractSrcFromIframe = function extractSrcFromIframe(input) {
|
|
93
|
+
var trimmed = input.trim();
|
|
94
|
+
var iframeMatch = trimmed.match(/<iframe[^>]*\ssrc\s*=\s*["']([^"']+)["'][^>]*>/i) || trimmed.match(/<iframe[^>]*\ssrc\s*=\s*([^\s>]+)[^>]*>/i);
|
|
95
|
+
if (iframeMatch && iframeMatch[1]) {
|
|
96
|
+
return iframeMatch[1].trim();
|
|
97
|
+
}
|
|
98
|
+
return trimmed;
|
|
91
99
|
};
|