@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.
@@ -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, 18).map(function (item, index) {
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, "editor" | "key">, any>;
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: 760,
38
+ default: '100%',
39
39
  parseHTML: function parseHTML(element) {
40
40
  var width = element.getAttribute('width');
41
- return width ? parseInt(width, 10) : 760;
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 width = dom.getAttribute('width') ? parseInt(dom.getAttribute('width'), 10) : dom.style.width ? parseInt(dom.style.width, 10) : 760;
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 || 760,
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> | Extension<any, 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
@@ -448,7 +448,6 @@
448
448
  overflow-x: auto;
449
449
  overflow-y: hidden;
450
450
  position: relative;
451
- margin: 20px 0;
452
451
  }
453
452
 
454
453
  .tiptap.ProseMirror[contenteditable="true"] .tableWrapper {
@@ -22,3 +22,4 @@ export declare const getLinkTitle: (href: string) => string;
22
22
  export declare const getLinkAttributesWithSelectedText: (editor: Editor) => {
23
23
  title?: string;
24
24
  };
25
+ export declare const extractSrcFromIframe: (input: string) => string;
@@ -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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctzhian/tiptap",
3
- "version": "2.1.12",
3
+ "version": "2.1.13",
4
4
  "description": "基于 Tiptap 二次开发的编辑器组件",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",