@ctzhian/tiptap 1.13.9 → 2.0.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.
Files changed (47) hide show
  1. package/dist/Editor/demo.js +1 -1
  2. package/dist/Editor/index.js +17 -0
  3. package/dist/component/CustomBubbleMenu/index.js +1 -1
  4. package/dist/component/CustomDragHandle/index.js +3 -59
  5. package/dist/component/Icons/delete-back-2-line-icon.d.ts +6 -0
  6. package/dist/component/Icons/delete-back-2-line-icon.js +13 -0
  7. package/dist/component/Menu/index.js +5 -1
  8. package/dist/contants/enums.d.ts +9 -0
  9. package/dist/contants/enums.js +61 -1
  10. package/dist/extension/component/TableCellHandleMenu/index.d.ts +9 -0
  11. package/dist/extension/component/TableCellHandleMenu/index.js +443 -0
  12. package/dist/extension/component/TableExtendButton/TableExtendButton.css +30 -0
  13. package/dist/extension/component/TableExtendButton/index.d.ts +23 -0
  14. package/dist/extension/component/TableExtendButton/index.js +201 -0
  15. package/dist/extension/component/TableExtendButton/use-table-extend-row-column.d.ts +15 -0
  16. package/dist/extension/component/TableExtendButton/use-table-extend-row-column.js +87 -0
  17. package/dist/extension/component/TableHandle/TableHandleMenu.css +36 -0
  18. package/dist/extension/component/TableHandle/TableHandleMenu.d.ts +17 -0
  19. package/dist/extension/component/TableHandle/TableHandleMenu.js +685 -0
  20. package/dist/extension/component/TableHandle/index.d.ts +28 -0
  21. package/dist/extension/component/TableHandle/index.js +93 -0
  22. package/dist/extension/component/TableHandle/use-table-handle-positioning.d.ts +40 -0
  23. package/dist/extension/component/TableHandle/use-table-handle-positioning.js +193 -0
  24. package/dist/extension/component/TableHandle/use-table-handle-state.d.ts +22 -0
  25. package/dist/extension/component/TableHandle/use-table-handle-state.js +45 -0
  26. package/dist/extension/component/TableSelectionOverlay/index.d.ts +16 -0
  27. package/dist/extension/component/TableSelectionOverlay/index.js +460 -0
  28. package/dist/extension/component/UploadProgress/index.d.ts +1 -1
  29. package/dist/extension/node/FileHandler.d.ts +1 -1
  30. package/dist/extension/node/Table.js +226 -43
  31. package/dist/extension/node/TableHandler/create-image.d.ts +9 -0
  32. package/dist/extension/node/TableHandler/create-image.js +235 -0
  33. package/dist/extension/node/TableHandler/index.d.ts +15 -0
  34. package/dist/extension/node/TableHandler/index.js +33 -0
  35. package/dist/extension/node/TableHandler/plugin.d.ts +49 -0
  36. package/dist/extension/node/TableHandler/plugin.js +1030 -0
  37. package/dist/index.css +29 -10
  38. package/dist/type/index.d.ts +2 -0
  39. package/dist/util/table-utils.d.ts +161 -0
  40. package/dist/util/table-utils.js +605 -0
  41. package/package.json +2 -1
  42. package/dist/extension/component/Table/ContextMenu.d.ts +0 -11
  43. package/dist/extension/component/Table/ContextMenu.js +0 -186
  44. package/dist/extension/component/Table/TableContextMenuPlugin.d.ts +0 -9
  45. package/dist/extension/component/Table/TableContextMenuPlugin.js +0 -336
  46. package/dist/extension/component/Table/index.d.ts +0 -2
  47. package/dist/extension/component/Table/index.js +0 -2
@@ -1,9 +1,25 @@
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
2
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
3
  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; }
6
4
  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; }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
13
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
14
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
15
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
16
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
17
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
18
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
19
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
20
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
21
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
22
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
7
23
  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; }
8
24
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
25
  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); }
@@ -12,17 +28,121 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
12
28
  import { Extension } from '@tiptap/core';
13
29
  import { Table, TableCell, TableHeader, TableRow } from '@tiptap/extension-table';
14
30
  import { Plugin, TextSelection } from '@tiptap/pm/state';
15
- import { createTableContextMenuPlugin } from "../component/Table";
31
+ import { TableView } from '@tiptap/pm/tables';
32
+ import { TableHandleExtension } from "./TableHandler";
16
33
  export var TableExtension = function TableExtension(_ref) {
17
34
  var editable = _ref.editable;
18
35
  return [Table.extend({
19
- addCommands: function addCommands() {
36
+ addNodeView: function addNodeView() {
37
+ var _this = this;
38
+ return function (_ref2) {
39
+ var node = _ref2.node,
40
+ HTMLAttributes = _ref2.HTMLAttributes;
41
+ var TiptapTableView = /*#__PURE__*/function (_TableView) {
42
+ _inherits(TiptapTableView, _TableView);
43
+ var _super = _createSuper(TiptapTableView);
44
+ function TiptapTableView(node, minCellWidth, containerAttributes) {
45
+ var _this2;
46
+ _classCallCheck(this, TiptapTableView);
47
+ _this2 = _super.call(this, node, minCellWidth);
48
+ _defineProperty(_assertThisInitialized(_this2), "tableWrapper", void 0);
49
+ _defineProperty(_assertThisInitialized(_this2), "innerTableContainer", void 0);
50
+ _defineProperty(_assertThisInitialized(_this2), "widgetsContainer", void 0);
51
+ _defineProperty(_assertThisInitialized(_this2), "containerAttributes", void 0);
52
+ _this2.containerAttributes = containerAttributes !== null && containerAttributes !== void 0 ? containerAttributes : {};
53
+ _this2.tableWrapper = _this2.createTableWrapper();
54
+ _this2.innerTableContainer = _this2.createInnerTableContainer();
55
+ _this2.widgetsContainer = _this2.createWidgetsContainer();
56
+ _this2.setupDOMStructure();
57
+ return _this2;
58
+ }
59
+ _createClass(TiptapTableView, [{
60
+ key: "createTableWrapper",
61
+ value: function createTableWrapper() {
62
+ var container = document.createElement('div');
63
+ container.className = 'tableWrapper';
64
+ this.applyContainerAttributes(container);
65
+ return container;
66
+ }
67
+ }, {
68
+ key: "createInnerTableContainer",
69
+ value: function createInnerTableContainer() {
70
+ var container = document.createElement('div');
71
+ container.className = 'table-container';
72
+ return container;
73
+ }
74
+ }, {
75
+ key: "createWidgetsContainer",
76
+ value: function createWidgetsContainer() {
77
+ var container = document.createElement('div');
78
+ container.className = 'table-controls';
79
+ container.style.position = 'relative';
80
+ return container;
81
+ }
82
+ }, {
83
+ key: "applyContainerAttributes",
84
+ value: function applyContainerAttributes(element) {
85
+ Object.entries(this.containerAttributes).forEach(function (_ref3) {
86
+ var _ref4 = _slicedToArray(_ref3, 2),
87
+ key = _ref4[0],
88
+ value = _ref4[1];
89
+ if (key !== 'class') {
90
+ element.setAttribute(key, value);
91
+ }
92
+ });
93
+ }
94
+ }, {
95
+ key: "setupDOMStructure",
96
+ value: function setupDOMStructure() {
97
+ var originalTable = this.dom;
98
+ var tableElement = originalTable.firstChild;
99
+
100
+ // Move table into inner container
101
+ this.innerTableContainer.appendChild(tableElement);
102
+
103
+ // Build the hierarchy: tableWrapper > innerContainer + widgetsContainer
104
+ this.tableWrapper.appendChild(this.innerTableContainer);
105
+ this.tableWrapper.appendChild(this.widgetsContainer);
106
+ this.dom = this.tableWrapper;
107
+ }
108
+ }, {
109
+ key: "ignoreMutation",
110
+ value: function ignoreMutation(mutation) {
111
+ var target = mutation.target;
112
+ var isInsideTable = target.closest('.table-container');
113
+ return !isInsideTable || _get(_getPrototypeOf(TiptapTableView.prototype), "ignoreMutation", this).call(this, mutation);
114
+ }
115
+ }]);
116
+ return TiptapTableView;
117
+ }(TableView);
118
+ var cellMinWidth = _this.options.cellMinWidth < 100 ? 100 : _this.options.cellMinWidth;
119
+ return new TiptapTableView(node, cellMinWidth, HTMLAttributes);
120
+ };
121
+ },
122
+ renderHTML: function renderHTML(_ref5) {
20
123
  var _this$parent;
21
- return _objectSpread(_objectSpread({}, (_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.call(this)), {}, {
124
+ var node = _ref5.node,
125
+ HTMLAttributes = _ref5.HTMLAttributes;
126
+ var originalRender = (_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.call(this, {
127
+ node: node,
128
+ HTMLAttributes: HTMLAttributes
129
+ });
130
+ var wrapper = ['div', {
131
+ class: 'tableWrapper'
132
+ }, ['div', {
133
+ class: 'table-container'
134
+ }, originalRender], ['div', {
135
+ class: 'table-controls'
136
+ }]];
137
+ return wrapper;
138
+ },
139
+ addCommands: function addCommands() {
140
+ var _this$parent2;
141
+ return _objectSpread(_objectSpread({}, (_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.call(this)), {}, {
22
142
  cancelSelection: function cancelSelection() {
23
- return function (_ref2) {
24
- var state = _ref2.state,
25
- dispatch = _ref2.dispatch;
143
+ return function (_ref6) {
144
+ var state = _ref6.state,
145
+ dispatch = _ref6.dispatch;
26
146
  if (dispatch) {
27
147
  var selection = state.selection;
28
148
  var $from = selection.$from;
@@ -53,29 +173,16 @@ export var TableExtension = function TableExtension(_ref) {
53
173
  });
54
174
  },
55
175
  addKeyboardShortcuts: function addKeyboardShortcuts() {
56
- var _this = this;
176
+ var _this3 = this;
57
177
  return {
58
178
  'Mod-9': function Mod9() {
59
- return _this.editor.chain().insertTable({
179
+ return _this3.editor.chain().insertTable({
60
180
  rows: 3,
61
181
  cols: 4,
62
182
  withHeaderRow: true
63
183
  }).focus().run();
64
184
  }
65
185
  };
66
- },
67
- renderHTML: function renderHTML(_ref3) {
68
- var _this$parent2;
69
- var node = _ref3.node,
70
- HTMLAttributes = _ref3.HTMLAttributes;
71
- var originalRender = (_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.call(this, {
72
- node: node,
73
- HTMLAttributes: HTMLAttributes
74
- });
75
- var wrapper = ['div', {
76
- class: 'tableWrapper'
77
- }, originalRender];
78
- return wrapper;
79
186
  }
80
187
  }).configure({
81
188
  handleWidth: 5,
@@ -83,7 +190,77 @@ export var TableExtension = function TableExtension(_ref) {
83
190
  resizable: editable,
84
191
  lastColumnResizable: editable,
85
192
  allowTableNodeSelection: editable
86
- }), TableHeader.configure({
193
+ }), TableHeader.extend({
194
+ addAttributes: function addAttributes() {
195
+ var _this$parent3;
196
+ return _objectSpread(_objectSpread({}, (_this$parent3 = this.parent) === null || _this$parent3 === void 0 ? void 0 : _this$parent3.call(this)), {}, {
197
+ bgcolor: {
198
+ default: null,
199
+ parseHTML: function parseHTML(element) {
200
+ return element.getAttribute('data-background-color') || element.style.backgroundColor;
201
+ },
202
+ renderHTML: function renderHTML(attributes) {
203
+ return {
204
+ 'data-background-color': attributes.bgcolor,
205
+ style: "background-color: ".concat(attributes.bgcolor)
206
+ };
207
+ }
208
+ },
209
+ textAlign: {
210
+ default: null,
211
+ parseHTML: function parseHTML(element) {
212
+ return element.getAttribute('data-text-align') || element.style.textAlign;
213
+ },
214
+ renderHTML: function renderHTML(attributes) {
215
+ if (!attributes.textAlign) return {};
216
+ return {
217
+ style: "text-align: ".concat(attributes.textAlign),
218
+ 'data-text-align': attributes.textAlign
219
+ };
220
+ }
221
+ },
222
+ verticalAlign: {
223
+ default: null,
224
+ parseHTML: function parseHTML(element) {
225
+ return element.getAttribute('data-vertical-align') || element.style.verticalAlign;
226
+ },
227
+ renderHTML: function renderHTML(attributes) {
228
+ if (!attributes.verticalAlign) return {};
229
+ return {
230
+ style: "vertical-align: ".concat(attributes.verticalAlign),
231
+ 'data-vertical-align': attributes.verticalAlign
232
+ };
233
+ }
234
+ },
235
+ fontSize: {
236
+ default: null,
237
+ parseHTML: function parseHTML(element) {
238
+ return element.getAttribute('data-font-size') || element.style.fontSize;
239
+ },
240
+ renderHTML: function renderHTML(attributes) {
241
+ if (!attributes.fontSize) return {};
242
+ return {
243
+ style: "font-size: ".concat(attributes.fontSize),
244
+ 'data-font-size': attributes.fontSize
245
+ };
246
+ }
247
+ },
248
+ fontWeight: {
249
+ default: null,
250
+ parseHTML: function parseHTML(element) {
251
+ return element.getAttribute('data-font-weight') || element.style.fontWeight;
252
+ },
253
+ renderHTML: function renderHTML(attributes) {
254
+ if (!attributes.fontWeight) return {};
255
+ return {
256
+ style: "font-weight: ".concat(attributes.fontWeight),
257
+ 'data-font-weight': attributes.fontWeight
258
+ };
259
+ }
260
+ }
261
+ });
262
+ }
263
+ }).configure({
87
264
  HTMLAttributes: {
88
265
  class: 'table-header'
89
266
  }
@@ -93,10 +270,10 @@ export var TableExtension = function TableExtension(_ref) {
93
270
  }
94
271
  }), TableCell.extend({
95
272
  addAttributes: function addAttributes() {
96
- var _this$parent3;
97
- return _objectSpread(_objectSpread({}, (_this$parent3 = this.parent) === null || _this$parent3 === void 0 ? void 0 : _this$parent3.call(this)), {}, {
273
+ var _this$parent4;
274
+ return _objectSpread(_objectSpread({}, (_this$parent4 = this.parent) === null || _this$parent4 === void 0 ? void 0 : _this$parent4.call(this)), {}, {
98
275
  bgcolor: {
99
- default: 'transparent',
276
+ default: null,
100
277
  parseHTML: function parseHTML(element) {
101
278
  return element.getAttribute('data-background-color') || element.style.backgroundColor;
102
279
  },
@@ -120,6 +297,19 @@ export var TableExtension = function TableExtension(_ref) {
120
297
  };
121
298
  }
122
299
  },
300
+ verticalAlign: {
301
+ default: null,
302
+ parseHTML: function parseHTML(element) {
303
+ return element.getAttribute('data-vertical-align') || element.style.verticalAlign;
304
+ },
305
+ renderHTML: function renderHTML(attributes) {
306
+ if (!attributes.verticalAlign) return {};
307
+ return {
308
+ style: "vertical-align: ".concat(attributes.verticalAlign),
309
+ 'data-vertical-align': attributes.verticalAlign
310
+ };
311
+ }
312
+ },
123
313
  fontSize: {
124
314
  default: null,
125
315
  parseHTML: function parseHTML(element) {
@@ -149,32 +339,25 @@ export var TableExtension = function TableExtension(_ref) {
149
339
  });
150
340
  },
151
341
  addKeyboardShortcuts: function addKeyboardShortcuts() {
152
- var _this2 = this;
342
+ var _this4 = this;
153
343
  return {
154
344
  Tab: function Tab() {
155
- if (_this2.editor.chain().goToNextCell().focus().run()) {
156
- return _this2.editor.chain().cancelSelection().run();
157
- } else if (!_this2.editor.can().addRowAfter()) {
345
+ if (_this4.editor.chain().goToNextCell().focus().run()) {
346
+ return _this4.editor.chain().cancelSelection().run();
347
+ } else if (!_this4.editor.can().addRowAfter()) {
158
348
  return false;
159
349
  } else {
160
- return _this2.editor.chain().addRowAfter().goToNextCell().cancelSelection().run();
350
+ return _this4.editor.chain().addRowAfter().goToNextCell().cancelSelection().run();
161
351
  }
162
352
  },
163
353
  'Shift-Tab': function ShiftTab() {
164
- return _this2.editor.chain().goToPreviousCell().cancelSelection().run();
354
+ return _this4.editor.chain().goToPreviousCell().cancelSelection().run();
165
355
  }
166
356
  };
167
357
  }
168
- }),
169
- // 表格右键菜单插件
170
- Extension.create({
171
- name: 'tableContextMenu',
172
- addProseMirrorPlugins: function addProseMirrorPlugins() {
173
- return editable ? [createTableContextMenuPlugin(this.editor)] : [];
174
- }
175
- }),
176
- // Safari 中文输入 deleteCompositionText 修复
177
- Extension.create({
358
+ }), editable ? TableHandleExtension : Extension.create({
359
+ name: 'tableHandleExtension'
360
+ }), Extension.create({
178
361
  name: 'safariCompositionDeleteFix',
179
362
  addProseMirrorPlugins: function addProseMirrorPlugins() {
180
363
  if (!editable) return [];
@@ -0,0 +1,9 @@
1
+ import type { Editor } from '@tiptap/core';
2
+ /**
3
+ * Public API
4
+ * Creates a polished drag image for a row/column from a TipTap/ProseMirror table.
5
+ * - Subtle rounded corners & shadow
6
+ * - Scales down if it exceeds editor width
7
+ * - Preserves computed styles to look 1:1 with the table
8
+ */
9
+ export declare function createTableDragImage(editor: Editor, orientation: 'row' | 'col', index: number, tablePos: number): HTMLElement;
@@ -0,0 +1,235 @@
1
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4
+ var STYLE_PROPS = [
5
+ // Box & border
6
+ 'boxSizing', 'backgroundColor', 'borderTopColor', 'borderRightColor', 'borderBottomColor', 'borderLeftColor', 'borderTopStyle', 'borderRightStyle', 'borderBottomStyle', 'borderLeftStyle', 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', 'borderRadius',
7
+ // Spacing
8
+ 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft',
9
+ // Typography
10
+ 'color', 'font', 'fontFamily', 'fontSize', 'fontWeight', 'fontStyle', 'lineHeight', 'letterSpacing', 'textTransform', 'textDecoration', 'textAlign', 'verticalAlign', 'whiteSpace',
11
+ // Sizing
12
+ 'width', 'minWidth', 'maxWidth', 'height', 'minHeight', 'maxHeight',
13
+ // Table specifics
14
+ 'backgroundClip'];
15
+ var toDash = function toDash(p) {
16
+ return p.replace(/[A-Z]/g, function (m) {
17
+ return '-' + m.toLowerCase();
18
+ });
19
+ };
20
+
21
+ /**
22
+ * Copy a curated list of computed styles from source -> target
23
+ * (Works for TD/TH and most inline content you'd expect inside.)
24
+ */
25
+ function copyComputedStyles(source, target) {
26
+ var cs = getComputedStyle(source);
27
+ var _iterator = _createForOfIteratorHelper(STYLE_PROPS),
28
+ _step;
29
+ try {
30
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
31
+ var p = _step.value;
32
+ var prop = String(p);
33
+ var val = cs.getPropertyValue(toDash(prop));
34
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
+ if (val) target.style[prop] = val;
36
+ }
37
+
38
+ // Ensure long content doesn't overflow the drag image
39
+ } catch (err) {
40
+ _iterator.e(err);
41
+ } finally {
42
+ _iterator.f();
43
+ }
44
+ target.style.overflow = 'hidden';
45
+ target.style.textOverflow = 'ellipsis';
46
+ // Respect existing wrapping if set on the source; otherwise prefer single line
47
+ if (cs.whiteSpace === '' || cs.whiteSpace === 'normal') {
48
+ target.style.whiteSpace = 'nowrap';
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Deep clone a node and copy computed styles element-by-element.
54
+ * Avoids the browser's default cloning which loses computed styles.
55
+ */
56
+ function cloneWithStyles(root) {
57
+ var clone = root.cloneNode(true);
58
+
59
+ // Iterative walk to avoid recursion limits
60
+ var q = [{
61
+ src: root,
62
+ dst: clone
63
+ }];
64
+ while (q.length) {
65
+ var _ref = q.shift(),
66
+ src = _ref.src,
67
+ dst = _ref.dst;
68
+ if (src instanceof HTMLElement && dst instanceof HTMLElement) {
69
+ copyComputedStyles(src, dst);
70
+ }
71
+ var srcChildren = Array.from(src.children);
72
+ var dstChildren = Array.from(dst.children);
73
+ var len = Math.min(srcChildren.length, dstChildren.length);
74
+ for (var i = 0; i < len; i++) {
75
+ var srcChild = srcChildren[i];
76
+ var dstChild = dstChildren[i];
77
+ if (srcChild && dstChild) {
78
+ q.push({
79
+ src: srcChild,
80
+ dst: dstChild
81
+ });
82
+ }
83
+ }
84
+ }
85
+ return clone;
86
+ }
87
+
88
+ /**
89
+ * Apply crisp, rounded, off-screen wrapper styling for drag image.
90
+ */
91
+ function styleDragWrapper(el, maxWidth) {
92
+ Object.assign(el.style, {
93
+ position: 'fixed',
94
+ top: '-10000px',
95
+ left: '-10000px',
96
+ pointerEvents: 'none',
97
+ zIndex: '2147483647',
98
+ maxWidth: "".concat(maxWidth, "px"),
99
+ borderRadius: '12px',
100
+ background: 'transparent',
101
+ filter: 'drop-shadow(0 8px 24px rgba(0,0,0,0.18)) drop-shadow(0 2px 8px rgba(0,0,0,0.10))',
102
+ overflow: 'hidden'
103
+ });
104
+ }
105
+
106
+ /**
107
+ * Scale an element down if it exceeds the max width, keeping crisp layout.
108
+ * Assumes the element is already positioned off-screen (so attaching to body is safe).
109
+ */
110
+ function scaleToFit(el, maxWidth) {
111
+ // Attach once (if not already) so measurements are correct.
112
+ if (!el.isConnected) document.body.appendChild(el);
113
+ var rect = el.getBoundingClientRect();
114
+ if (rect.width > maxWidth && rect.width > 0) {
115
+ var scale = maxWidth / rect.width;
116
+ el.style.transformOrigin = 'top left';
117
+ el.style.transform = "scale(".concat(scale, ")");
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Copy table-level styles that affect layout.
123
+ */
124
+ function applyTableBoxStyles(srcTable, dstTable) {
125
+ var tcs = getComputedStyle(srcTable);
126
+ dstTable.style.borderCollapse = tcs.borderCollapse;
127
+ dstTable.style.borderSpacing = tcs.borderSpacing;
128
+ dstTable.style.tableLayout = 'fixed'; // consistent drag image
129
+ dstTable.className = srcTable.className;
130
+ }
131
+
132
+ /**
133
+ * Lock a cell's width to its rendered width.
134
+ */
135
+ function lockCellWidth(fromCell, toCell) {
136
+ var rect = fromCell.getBoundingClientRect();
137
+ if (rect.width > 0) {
138
+ toCell.style.width = "".concat(rect.width, "px");
139
+ toCell.style.maxWidth = "".concat(rect.width, "px");
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Build a 1-row preview table.
145
+ */
146
+ function buildRowPreview(tableEl, rowIndex) {
147
+ var _tableEl$tBodies$, _tableEl$tBodies, _body$rows;
148
+ var body = (_tableEl$tBodies$ = (_tableEl$tBodies = tableEl.tBodies) === null || _tableEl$tBodies === void 0 ? void 0 : _tableEl$tBodies[0]) !== null && _tableEl$tBodies$ !== void 0 ? _tableEl$tBodies$ : tableEl.querySelector('tbody');
149
+ if (!body) return null;
150
+ var row = (_body$rows = body.rows) === null || _body$rows === void 0 ? void 0 : _body$rows[rowIndex];
151
+ if (!row) return null;
152
+ var tableClone = document.createElement('table');
153
+ var tbodyClone = document.createElement('tbody');
154
+ var rowClone = cloneWithStyles(row);
155
+ applyTableBoxStyles(tableEl, tableClone);
156
+
157
+ // Lock each cell width
158
+ for (var i = 0; i < row.cells.length; i++) {
159
+ var src = row.cells[i];
160
+ var dst = rowClone.cells[i];
161
+ if (dst) lockCellWidth(src, dst);
162
+ }
163
+ tbodyClone.appendChild(rowClone);
164
+ tableClone.appendChild(tbodyClone);
165
+ return tableClone;
166
+ }
167
+
168
+ /**
169
+ * Build a 1-column preview table (one cell per row).
170
+ */
171
+ function buildColumnPreview(tableEl, colIndex) {
172
+ var _tableEl$tBodies$2, _tableEl$tBodies2;
173
+ var body = (_tableEl$tBodies$2 = (_tableEl$tBodies2 = tableEl.tBodies) === null || _tableEl$tBodies2 === void 0 ? void 0 : _tableEl$tBodies2[0]) !== null && _tableEl$tBodies$2 !== void 0 ? _tableEl$tBodies$2 : tableEl.querySelector('tbody');
174
+ if (!body) return null;
175
+ var tableClone = document.createElement('table');
176
+ var tbodyClone = document.createElement('tbody');
177
+ applyTableBoxStyles(tableEl, tableClone);
178
+ var firstCellWidth = 0;
179
+ for (var r = 0; r < body.rows.length; r++) {
180
+ var _srcRow$cells;
181
+ var srcRow = body.rows[r];
182
+ if (!srcRow) continue;
183
+ var srcCell = (_srcRow$cells = srcRow.cells) === null || _srcRow$cells === void 0 ? void 0 : _srcRow$cells[colIndex];
184
+ if (!srcCell) continue;
185
+ var tr = document.createElement('tr');
186
+ var cellClone = cloneWithStyles(srcCell);
187
+ var rect = srcCell.getBoundingClientRect();
188
+ if (!firstCellWidth && rect.width > 0) firstCellWidth = rect.width;
189
+ lockCellWidth(srcCell, cellClone);
190
+ tr.appendChild(cellClone);
191
+ tbodyClone.appendChild(tr);
192
+ }
193
+ if (firstCellWidth > 0) {
194
+ tableClone.style.width = "".concat(firstCellWidth, "px");
195
+ tableClone.style.maxWidth = "".concat(firstCellWidth, "px");
196
+ }
197
+ tableClone.appendChild(tbodyClone);
198
+ return tableClone;
199
+ }
200
+
201
+ /**
202
+ * Public API
203
+ * Creates a polished drag image for a row/column from a TipTap/ProseMirror table.
204
+ * - Subtle rounded corners & shadow
205
+ * - Scales down if it exceeds editor width
206
+ * - Preserves computed styles to look 1:1 with the table
207
+ */
208
+ export function createTableDragImage(editor, orientation, index, tablePos) {
209
+ var editorRect = editor.view.dom.getBoundingClientRect();
210
+ var maxWidth = Math.max(0, editorRect.width);
211
+ var wrapper = document.createElement('div');
212
+ styleDragWrapper(wrapper, maxWidth);
213
+ var tableEl = editor.view.nodeDOM(tablePos);
214
+ if (!tableEl) {
215
+ document.body.appendChild(wrapper);
216
+ return wrapper;
217
+ }
218
+ var tableRect = tableEl.getBoundingClientRect();
219
+ var dragWidth = Math.min(tableRect.width, editorRect.width);
220
+ wrapper.style.width = "".concat(dragWidth, "px");
221
+ var preview = orientation === 'row' ? buildRowPreview(tableEl, index) : buildColumnPreview(tableEl, index);
222
+ if (preview) {
223
+ var card = document.createElement('div');
224
+ Object.assign(card.style, {
225
+ background: 'var(--drag-image-bg, transparent)',
226
+ overflow: 'hidden'
227
+ });
228
+ card.appendChild(preview);
229
+ wrapper.appendChild(card);
230
+ }
231
+
232
+ // Measure & scale after attaching
233
+ scaleToFit(wrapper, maxWidth);
234
+ return wrapper;
235
+ }
@@ -0,0 +1,15 @@
1
+ import { Extension } from '@tiptap/core';
2
+ import type { TableHandlesState } from './plugin';
3
+ declare module '@tiptap/core' {
4
+ interface Commands<ReturnType> {
5
+ tableHandle: {
6
+ freezeHandles: () => ReturnType;
7
+ unfreezeHandles: () => ReturnType;
8
+ };
9
+ }
10
+ interface EditorEvents {
11
+ tableHandleState: TableHandlesState;
12
+ }
13
+ }
14
+ export declare const TableHandleExtension: Extension<any, any>;
15
+ export * from './plugin';
@@ -0,0 +1,33 @@
1
+ import { Extension } from '@tiptap/core';
2
+ import { TableHandlePlugin, tableHandlePluginKey } from "./plugin";
3
+ export var TableHandleExtension = Extension.create({
4
+ name: 'tableHandleExtension',
5
+ addCommands: function addCommands() {
6
+ return {
7
+ freezeHandles: function freezeHandles() {
8
+ return function (_ref) {
9
+ var tr = _ref.tr,
10
+ dispatch = _ref.dispatch;
11
+ if (dispatch) tr.setMeta(tableHandlePluginKey, true);
12
+ return true;
13
+ };
14
+ },
15
+ unfreezeHandles: function unfreezeHandles() {
16
+ return function (_ref2) {
17
+ var tr = _ref2.tr,
18
+ dispatch = _ref2.dispatch;
19
+ if (dispatch) tr.setMeta(tableHandlePluginKey, false);
20
+ return true;
21
+ };
22
+ }
23
+ };
24
+ },
25
+ addProseMirrorPlugins: function addProseMirrorPlugins() {
26
+ var _this = this;
27
+ var editor = this.editor;
28
+ return [TableHandlePlugin(editor, function (state) {
29
+ _this.editor.emit('tableHandleState', state);
30
+ })];
31
+ }
32
+ });
33
+ export * from "./plugin";