@ctzhian/tiptap 2.6.1 → 2.7.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 +1 -1
- package/dist/EditorMarkdown/demo.js +1 -1
- package/dist/extension/component/TableExtendButton/index.d.ts +1 -3
- package/dist/extension/component/TableExtendButton/index.js +16 -7
- package/dist/extension/component/TableExtendButton/use-table-extend-row-column.d.ts +1 -3
- package/dist/extension/component/TableExtendButton/use-table-extend-row-column.js +5 -10
- package/dist/extension/component/TableHandle/TableHandleAddButton.js +19 -11
- package/dist/extension/component/TableHandle/TableHandleMenu.js +159 -83
- package/dist/extension/component/TableHandle/index.d.ts +2 -7
- package/dist/extension/component/TableHandle/index.js +1 -4
- package/dist/extension/component/TableHandle/use-table-handle-positioning.d.ts +2 -6
- package/dist/extension/component/TableHandle/use-table-handle-positioning.js +28 -55
- package/dist/extension/component/TableHandle/use-table-handle-state.d.ts +4 -13
- package/dist/extension/component/TableHandle/use-table-handle-state.js +1 -1
- package/dist/extension/component/UploadProgress/index.d.ts +1 -1
- package/dist/extension/index.js +2 -2
- package/dist/extension/node/Table.js +112 -151
- package/dist/extension/node/TableHandler/plugin.d.ts +5 -9
- package/dist/extension/node/TableHandler/plugin.js +177 -124
- package/dist/extension/node/TableOfContents/index.d.ts +4 -7
- package/dist/extension/node/TableOfContents/index.js +23 -419
- package/dist/util/table-utils.d.ts +28 -61
- package/dist/util/table-utils.js +157 -124
- package/package.json +32 -32
- package/dist/extension/node/TableOfContents/plugin.d.ts +0 -6
- package/dist/extension/node/TableOfContents/plugin.js +0 -58
- package/dist/extension/node/TableOfContents/types.d.ts +0 -45
- package/dist/extension/node/TableOfContents/types.js +0 -1
- package/dist/extension/node/TableOfContents/util.d.ts +0 -6
- package/dist/extension/node/TableOfContents/util.js +0 -70
|
@@ -22,13 +22,98 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
22
22
|
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; }
|
|
23
23
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
24
24
|
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); }
|
|
25
|
-
// @ts-nocheck
|
|
26
|
-
|
|
27
25
|
import { Extension } from '@tiptap/core';
|
|
28
26
|
import { Table, TableCell, TableHeader, TableRow } from '@tiptap/extension-table';
|
|
29
27
|
import { TextSelection } from '@tiptap/pm/state';
|
|
30
28
|
import { TableView } from '@tiptap/pm/tables';
|
|
31
29
|
import { TableHandleExtension } from "./TableHandler";
|
|
30
|
+
|
|
31
|
+
// 表格相关常量
|
|
32
|
+
var TABLE_CONSTANTS = {
|
|
33
|
+
DEFAULT_CELL_MIN_WIDTH: 100,
|
|
34
|
+
HANDLE_WIDTH: 5,
|
|
35
|
+
SHORTCUT_KEY: 'Mod-9',
|
|
36
|
+
DEFAULT_ROWS: 3,
|
|
37
|
+
DEFAULT_COLS: 4
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// 表格单元格的通用属性定义
|
|
41
|
+
var createCommonCellAttributes = function createCommonCellAttributes() {
|
|
42
|
+
var isHeader = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
43
|
+
return {
|
|
44
|
+
bgcolor: {
|
|
45
|
+
default: null,
|
|
46
|
+
parseHTML: function parseHTML(element) {
|
|
47
|
+
return element.getAttribute('data-background-color') || element.style.backgroundColor;
|
|
48
|
+
},
|
|
49
|
+
renderHTML: function renderHTML(attributes) {
|
|
50
|
+
if (isHeader) {
|
|
51
|
+
return {
|
|
52
|
+
'data-background-color': attributes.bgcolor,
|
|
53
|
+
style: "background-color: ".concat(attributes.bgcolor)
|
|
54
|
+
};
|
|
55
|
+
} else {
|
|
56
|
+
return {
|
|
57
|
+
'data-background-color': attributes.bgcolor,
|
|
58
|
+
style: "background-color: ".concat(attributes.bgcolor)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
textAlign: {
|
|
64
|
+
default: null,
|
|
65
|
+
parseHTML: function parseHTML(element) {
|
|
66
|
+
return element.getAttribute('data-text-align') || element.style.textAlign;
|
|
67
|
+
},
|
|
68
|
+
renderHTML: function renderHTML(attributes) {
|
|
69
|
+
if (!attributes.textAlign) return {};
|
|
70
|
+
return {
|
|
71
|
+
style: "text-align: ".concat(attributes.textAlign),
|
|
72
|
+
'data-text-align': attributes.textAlign
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
verticalAlign: {
|
|
77
|
+
default: null,
|
|
78
|
+
parseHTML: function parseHTML(element) {
|
|
79
|
+
return element.getAttribute('data-vertical-align') || element.style.verticalAlign;
|
|
80
|
+
},
|
|
81
|
+
renderHTML: function renderHTML(attributes) {
|
|
82
|
+
if (!attributes.verticalAlign) return {};
|
|
83
|
+
return {
|
|
84
|
+
style: "vertical-align: ".concat(attributes.verticalAlign),
|
|
85
|
+
'data-vertical-align': attributes.verticalAlign
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
fontSize: {
|
|
90
|
+
default: null,
|
|
91
|
+
parseHTML: function parseHTML(element) {
|
|
92
|
+
return element.getAttribute('data-font-size') || element.style.fontSize;
|
|
93
|
+
},
|
|
94
|
+
renderHTML: function renderHTML(attributes) {
|
|
95
|
+
if (!attributes.fontSize) return {};
|
|
96
|
+
return {
|
|
97
|
+
style: "font-size: ".concat(attributes.fontSize),
|
|
98
|
+
'data-font-size': attributes.fontSize
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
fontWeight: {
|
|
103
|
+
default: null,
|
|
104
|
+
parseHTML: function parseHTML(element) {
|
|
105
|
+
return element.getAttribute('data-font-weight') || element.style.fontWeight;
|
|
106
|
+
},
|
|
107
|
+
renderHTML: function renderHTML(attributes) {
|
|
108
|
+
if (!attributes.fontWeight) return {};
|
|
109
|
+
return {
|
|
110
|
+
style: "font-weight: ".concat(attributes.fontWeight),
|
|
111
|
+
'data-font-weight': attributes.fontWeight
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
};
|
|
32
117
|
export var TableExtension = function TableExtension(_ref) {
|
|
33
118
|
var editable = _ref.editable;
|
|
34
119
|
return [Table.extend({
|
|
@@ -122,7 +207,7 @@ export var TableExtension = function TableExtension(_ref) {
|
|
|
122
207
|
}]);
|
|
123
208
|
return TiptapTableView;
|
|
124
209
|
}(TableView);
|
|
125
|
-
var cellMinWidth = _this.options.cellMinWidth <
|
|
210
|
+
var cellMinWidth = _this.options.cellMinWidth < TABLE_CONSTANTS.DEFAULT_CELL_MIN_WIDTH ? TABLE_CONSTANTS.DEFAULT_CELL_MIN_WIDTH : _this.options.cellMinWidth;
|
|
126
211
|
return new TiptapTableView(node, cellMinWidth, HTMLAttributes);
|
|
127
212
|
};
|
|
128
213
|
},
|
|
@@ -131,10 +216,18 @@ export var TableExtension = function TableExtension(_ref) {
|
|
|
131
216
|
HTMLAttributes = _ref5.HTMLAttributes;
|
|
132
217
|
var firstRow = node.content.firstChild;
|
|
133
218
|
var colCount = firstRow ? firstRow.childCount : 0;
|
|
134
|
-
|
|
219
|
+
|
|
220
|
+
// 构建表格样式
|
|
221
|
+
var tableStyles = ["--default-cell-min-width: ".concat(TABLE_CONSTANTS.DEFAULT_CELL_MIN_WIDTH, "px"), "min-width: ".concat(colCount * TABLE_CONSTANTS.DEFAULT_CELL_MIN_WIDTH, "px")];
|
|
222
|
+
|
|
223
|
+
// 合并现有样式
|
|
224
|
+
var existingStyle = HTMLAttributes.style;
|
|
225
|
+
var combinedStyle = existingStyle ? "".concat(existingStyle, "; ").concat(tableStyles.join('; ')) : tableStyles.join('; ');
|
|
135
226
|
var attrs = _objectSpread(_objectSpread({}, HTMLAttributes), {}, {
|
|
136
|
-
style:
|
|
227
|
+
style: combinedStyle
|
|
137
228
|
});
|
|
229
|
+
|
|
230
|
+
// 生成列定义
|
|
138
231
|
var cols = [];
|
|
139
232
|
for (var i = 0; i < colCount; i++) {
|
|
140
233
|
cols.push(['col', {}]);
|
|
@@ -179,91 +272,24 @@ export var TableExtension = function TableExtension(_ref) {
|
|
|
179
272
|
},
|
|
180
273
|
addKeyboardShortcuts: function addKeyboardShortcuts() {
|
|
181
274
|
var _this3 = this;
|
|
182
|
-
return {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
};
|
|
275
|
+
return _defineProperty({}, TABLE_CONSTANTS.SHORTCUT_KEY, function () {
|
|
276
|
+
return _this3.editor.chain().insertTable({
|
|
277
|
+
rows: TABLE_CONSTANTS.DEFAULT_ROWS,
|
|
278
|
+
cols: TABLE_CONSTANTS.DEFAULT_COLS,
|
|
279
|
+
withHeaderRow: false
|
|
280
|
+
}).focus().run();
|
|
281
|
+
});
|
|
191
282
|
}
|
|
192
283
|
}).configure({
|
|
193
|
-
handleWidth:
|
|
194
|
-
cellMinWidth:
|
|
284
|
+
handleWidth: TABLE_CONSTANTS.HANDLE_WIDTH,
|
|
285
|
+
cellMinWidth: TABLE_CONSTANTS.DEFAULT_CELL_MIN_WIDTH,
|
|
195
286
|
resizable: editable,
|
|
196
287
|
lastColumnResizable: editable,
|
|
197
288
|
allowTableNodeSelection: editable
|
|
198
289
|
}), TableHeader.extend({
|
|
199
290
|
addAttributes: function addAttributes() {
|
|
200
291
|
var _this$parent2;
|
|
201
|
-
return _objectSpread(_objectSpread({}, (_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.call(this)),
|
|
202
|
-
bgcolor: {
|
|
203
|
-
default: null,
|
|
204
|
-
parseHTML: function parseHTML(element) {
|
|
205
|
-
return element.getAttribute('data-background-color') || element.style.backgroundColor;
|
|
206
|
-
},
|
|
207
|
-
renderHTML: function renderHTML(attributes) {
|
|
208
|
-
return {
|
|
209
|
-
'data-background-color': attributes.bgcolor,
|
|
210
|
-
style: "background-color: ".concat(attributes.bgcolor)
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
|
-
textAlign: {
|
|
215
|
-
default: null,
|
|
216
|
-
parseHTML: function parseHTML(element) {
|
|
217
|
-
return element.getAttribute('data-text-align') || element.style.textAlign;
|
|
218
|
-
},
|
|
219
|
-
renderHTML: function renderHTML(attributes) {
|
|
220
|
-
if (!attributes.textAlign) return {};
|
|
221
|
-
return {
|
|
222
|
-
style: "text-align: ".concat(attributes.textAlign),
|
|
223
|
-
'data-text-align': attributes.textAlign
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
verticalAlign: {
|
|
228
|
-
default: null,
|
|
229
|
-
parseHTML: function parseHTML(element) {
|
|
230
|
-
return element.getAttribute('data-vertical-align') || element.style.verticalAlign;
|
|
231
|
-
},
|
|
232
|
-
renderHTML: function renderHTML(attributes) {
|
|
233
|
-
if (!attributes.verticalAlign) return {};
|
|
234
|
-
return {
|
|
235
|
-
style: "vertical-align: ".concat(attributes.verticalAlign),
|
|
236
|
-
'data-vertical-align': attributes.verticalAlign
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
fontSize: {
|
|
241
|
-
default: null,
|
|
242
|
-
parseHTML: function parseHTML(element) {
|
|
243
|
-
return element.getAttribute('data-font-size') || element.style.fontSize;
|
|
244
|
-
},
|
|
245
|
-
renderHTML: function renderHTML(attributes) {
|
|
246
|
-
if (!attributes.fontSize) return {};
|
|
247
|
-
return {
|
|
248
|
-
style: "font-size: ".concat(attributes.fontSize),
|
|
249
|
-
'data-font-size': attributes.fontSize
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
fontWeight: {
|
|
254
|
-
default: null,
|
|
255
|
-
parseHTML: function parseHTML(element) {
|
|
256
|
-
return element.getAttribute('data-font-weight') || element.style.fontWeight;
|
|
257
|
-
},
|
|
258
|
-
renderHTML: function renderHTML(attributes) {
|
|
259
|
-
if (!attributes.fontWeight) return {};
|
|
260
|
-
return {
|
|
261
|
-
style: "font-weight: ".concat(attributes.fontWeight),
|
|
262
|
-
'data-font-weight': attributes.fontWeight
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
});
|
|
292
|
+
return _objectSpread(_objectSpread({}, (_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.call(this)), createCommonCellAttributes(true));
|
|
267
293
|
}
|
|
268
294
|
}).configure({
|
|
269
295
|
HTMLAttributes: {
|
|
@@ -276,87 +302,22 @@ export var TableExtension = function TableExtension(_ref) {
|
|
|
276
302
|
}), TableCell.extend({
|
|
277
303
|
addAttributes: function addAttributes() {
|
|
278
304
|
var _this$parent3;
|
|
279
|
-
return _objectSpread(_objectSpread({}, (_this$parent3 = this.parent) === null || _this$parent3 === void 0 ? void 0 : _this$parent3.call(this)),
|
|
280
|
-
bgcolor: {
|
|
281
|
-
default: null,
|
|
282
|
-
parseHTML: function parseHTML(element) {
|
|
283
|
-
return element.getAttribute('data-background-color') || element.style.backgroundColor;
|
|
284
|
-
},
|
|
285
|
-
renderHTML: function renderHTML(attributes) {
|
|
286
|
-
return {
|
|
287
|
-
'data-background-color': attributes.bgcolor,
|
|
288
|
-
style: "background-color: ".concat(attributes.bgcolor)
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
textAlign: {
|
|
293
|
-
default: null,
|
|
294
|
-
parseHTML: function parseHTML(element) {
|
|
295
|
-
return element.getAttribute('data-text-align') || element.style.textAlign;
|
|
296
|
-
},
|
|
297
|
-
renderHTML: function renderHTML(attributes) {
|
|
298
|
-
if (!attributes.textAlign) return {};
|
|
299
|
-
return {
|
|
300
|
-
style: "text-align: ".concat(attributes.textAlign),
|
|
301
|
-
'data-text-align': attributes.textAlign
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
},
|
|
305
|
-
verticalAlign: {
|
|
306
|
-
default: null,
|
|
307
|
-
parseHTML: function parseHTML(element) {
|
|
308
|
-
return element.getAttribute('data-vertical-align') || element.style.verticalAlign;
|
|
309
|
-
},
|
|
310
|
-
renderHTML: function renderHTML(attributes) {
|
|
311
|
-
if (!attributes.verticalAlign) return {};
|
|
312
|
-
return {
|
|
313
|
-
style: "vertical-align: ".concat(attributes.verticalAlign),
|
|
314
|
-
'data-vertical-align': attributes.verticalAlign
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
},
|
|
318
|
-
fontSize: {
|
|
319
|
-
default: null,
|
|
320
|
-
parseHTML: function parseHTML(element) {
|
|
321
|
-
return element.getAttribute('data-font-size') || element.style.fontSize;
|
|
322
|
-
},
|
|
323
|
-
renderHTML: function renderHTML(attributes) {
|
|
324
|
-
if (!attributes.fontSize) return {};
|
|
325
|
-
return {
|
|
326
|
-
style: "font-size: ".concat(attributes.fontSize),
|
|
327
|
-
'data-font-size': attributes.fontSize
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
},
|
|
331
|
-
fontWeight: {
|
|
332
|
-
default: null,
|
|
333
|
-
parseHTML: function parseHTML(element) {
|
|
334
|
-
return element.getAttribute('data-font-weight') || element.style.fontWeight;
|
|
335
|
-
},
|
|
336
|
-
renderHTML: function renderHTML(attributes) {
|
|
337
|
-
if (!attributes.fontWeight) return {};
|
|
338
|
-
return {
|
|
339
|
-
style: "font-weight: ".concat(attributes.fontWeight),
|
|
340
|
-
'data-font-weight': attributes.fontWeight
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
});
|
|
305
|
+
return _objectSpread(_objectSpread({}, (_this$parent3 = this.parent) === null || _this$parent3 === void 0 ? void 0 : _this$parent3.call(this)), createCommonCellAttributes(false));
|
|
345
306
|
},
|
|
346
307
|
addKeyboardShortcuts: function addKeyboardShortcuts() {
|
|
347
308
|
var _this4 = this;
|
|
348
309
|
return {
|
|
349
310
|
Tab: function Tab() {
|
|
350
311
|
if (_this4.editor.chain().goToNextCell().focus().run()) {
|
|
351
|
-
return
|
|
312
|
+
return true;
|
|
352
313
|
} else if (!_this4.editor.can().addRowAfter()) {
|
|
353
314
|
return false;
|
|
354
315
|
} else {
|
|
355
|
-
return _this4.editor.chain().addRowAfter().goToNextCell().
|
|
316
|
+
return _this4.editor.chain().addRowAfter().goToNextCell().run();
|
|
356
317
|
}
|
|
357
318
|
},
|
|
358
319
|
'Shift-Tab': function ShiftTab() {
|
|
359
|
-
return _this4.editor.chain().goToPreviousCell().
|
|
320
|
+
return _this4.editor.chain().goToPreviousCell().run();
|
|
360
321
|
}
|
|
361
322
|
};
|
|
362
323
|
}
|
|
@@ -24,26 +24,22 @@ export type TableHandlesState = {
|
|
|
24
24
|
};
|
|
25
25
|
} | undefined;
|
|
26
26
|
widgetContainer: HTMLElement | undefined;
|
|
27
|
+
_cachedHandleRects?: DOMRect[];
|
|
28
|
+
_cachedHandleRectsTime?: number;
|
|
27
29
|
};
|
|
28
30
|
export declare const tableHandlePluginKey: PluginKey<any>;
|
|
29
31
|
export declare function TableHandlePlugin(editor: Editor, emitUpdate: (state: TableHandlesState) => void): Plugin;
|
|
30
|
-
/**
|
|
31
|
-
* Callback for column drag handle
|
|
32
|
-
*/
|
|
32
|
+
/** 列拖拽句柄回调 */
|
|
33
33
|
export declare const colDragStart: (event: {
|
|
34
34
|
dataTransfer: DataTransfer | null;
|
|
35
35
|
currentTarget: EventTarget & Element;
|
|
36
36
|
clientX: number;
|
|
37
37
|
}) => void;
|
|
38
|
-
/**
|
|
39
|
-
* Callback for row drag handle
|
|
40
|
-
*/
|
|
38
|
+
/** 行拖拽句柄回调 */
|
|
41
39
|
export declare const rowDragStart: (event: {
|
|
42
40
|
dataTransfer: DataTransfer | null;
|
|
43
41
|
currentTarget: EventTarget & Element;
|
|
44
42
|
clientY: number;
|
|
45
43
|
}) => void;
|
|
46
|
-
/**
|
|
47
|
-
* Drag end cleanup
|
|
48
|
-
*/
|
|
44
|
+
/** 拖拽结束后的清理 */
|
|
49
45
|
export declare const dragEnd: () => void;
|