@ctzhian/tiptap 1.13.9 → 2.1.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 +133 -123
- package/dist/Editor/index.js +17 -0
- package/dist/EditorToolbar/index.js +11 -9
- package/dist/asset/css/index.css +5 -7
- package/dist/component/ActionDropdown/index.d.ts +5 -0
- package/dist/component/ActionDropdown/index.js +8 -3
- package/dist/component/CustomBubbleMenu/index.js +1 -1
- package/dist/component/CustomDragHandle/index.js +3 -59
- package/dist/component/FloatingPopover/index.d.ts +2 -2
- package/dist/component/HoverPopover/index.d.ts +2 -0
- package/dist/component/HoverPopover/index.js +22 -3
- package/dist/component/Icons/delete-back-2-line-icon.d.ts +6 -0
- package/dist/component/Icons/delete-back-2-line-icon.js +13 -0
- package/dist/component/Icons/{expand-horizontal-line.js → expand-horizontal-line-icon.js} +1 -1
- package/dist/component/Icons/index.d.ts +3 -2
- package/dist/component/Icons/index.js +4 -3
- package/dist/component/Menu/index.js +5 -1
- package/dist/contants/enums.d.ts +9 -0
- package/dist/contants/enums.js +61 -1
- package/dist/extension/component/Alert/index.js +141 -137
- package/dist/extension/component/Flow/Edit.d.ts +1 -1
- package/dist/extension/component/Flow/Edit.js +3 -31
- package/dist/extension/component/Flow/index.js +20 -19
- package/dist/extension/component/Image/index.d.ts +1 -0
- package/dist/extension/component/Image/index.js +16 -2
- package/dist/extension/component/Link/index.js +1 -1
- package/dist/extension/component/TableCellHandleMenu/index.d.ts +9 -0
- package/dist/extension/component/TableCellHandleMenu/index.js +500 -0
- package/dist/extension/component/TableExtendButton/TableExtendButton.css +30 -0
- package/dist/extension/component/TableExtendButton/index.d.ts +23 -0
- package/dist/extension/component/TableExtendButton/index.js +201 -0
- package/dist/extension/component/TableExtendButton/use-table-extend-row-column.d.ts +15 -0
- package/dist/extension/component/TableExtendButton/use-table-extend-row-column.js +87 -0
- package/dist/extension/component/TableHandle/TableHandleMenu.css +36 -0
- package/dist/extension/component/TableHandle/TableHandleMenu.d.ts +17 -0
- package/dist/extension/component/TableHandle/TableHandleMenu.js +685 -0
- package/dist/extension/component/TableHandle/index.d.ts +28 -0
- package/dist/extension/component/TableHandle/index.js +93 -0
- package/dist/extension/component/TableHandle/use-table-handle-positioning.d.ts +40 -0
- package/dist/extension/component/TableHandle/use-table-handle-positioning.js +193 -0
- package/dist/extension/component/TableHandle/use-table-handle-state.d.ts +22 -0
- package/dist/extension/component/TableHandle/use-table-handle-state.js +45 -0
- package/dist/extension/component/TableSelectionOverlay/index.d.ts +16 -0
- package/dist/extension/component/TableSelectionOverlay/index.js +452 -0
- package/dist/extension/component/Video/Insert.js +4 -2
- package/dist/extension/component/Video/Readonly.js +4 -11
- package/dist/extension/component/Video/index.d.ts +2 -1
- package/dist/extension/component/Video/index.js +447 -65
- package/dist/extension/extension/ImeComposition.d.ts +2 -0
- package/dist/extension/extension/ImeComposition.js +145 -0
- package/dist/extension/extension/index.d.ts +1 -0
- package/dist/extension/extension/index.js +1 -0
- package/dist/extension/index.js +2 -2
- package/dist/extension/node/FileHandler.d.ts +1 -1
- package/dist/extension/node/Flow/index.d.ts +0 -3
- package/dist/extension/node/Flow/index.js +7 -4
- package/dist/extension/node/Link/index.js +4 -3
- package/dist/extension/node/Table.js +236 -117
- package/dist/extension/node/TableHandler/create-image.d.ts +9 -0
- package/dist/extension/node/TableHandler/create-image.js +235 -0
- package/dist/extension/node/TableHandler/index.d.ts +15 -0
- package/dist/extension/node/TableHandler/index.js +33 -0
- package/dist/extension/node/TableHandler/plugin.d.ts +49 -0
- package/dist/extension/node/TableHandler/plugin.js +1030 -0
- package/dist/extension/node/TableOfContents/index.d.ts +5 -3
- package/dist/extension/node/TableOfContents/index.js +22 -2
- package/dist/extension/node/Video.d.ts +1 -0
- package/dist/extension/node/Video.js +38 -6
- package/dist/hook/index.js +1 -1
- package/dist/index.css +45 -29
- package/dist/type/index.d.ts +2 -0
- package/dist/util/index.d.ts +9 -0
- package/dist/util/index.js +26 -0
- package/dist/util/table-utils.d.ts +161 -0
- package/dist/util/table-utils.js +605 -0
- package/package.json +2 -1
- package/dist/extension/component/Table/ContextMenu.d.ts +0 -11
- package/dist/extension/component/Table/ContextMenu.js +0 -186
- package/dist/extension/component/Table/TableContextMenuPlugin.d.ts +0 -9
- package/dist/extension/component/Table/TableContextMenuPlugin.js +0 -336
- package/dist/extension/component/Table/index.d.ts +0 -2
- package/dist/extension/component/Table/index.js +0 -2
- /package/dist/component/Icons/{expand-horizontal-line.d.ts → expand-horizontal-line-icon.d.ts} +0 -0
|
@@ -1,9 +1,24 @@
|
|
|
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 _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
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; }
|
|
6
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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
5
|
+
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."); }
|
|
6
|
+
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); }
|
|
7
|
+
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; }
|
|
8
|
+
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; } }
|
|
9
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
10
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
+
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); } }
|
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
+
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); }
|
|
14
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
15
|
+
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); }
|
|
16
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
17
|
+
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); }; }
|
|
18
|
+
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); }
|
|
19
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
|
+
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; } }
|
|
21
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
7
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; }
|
|
8
23
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
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); }
|
|
@@ -11,18 +26,132 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
11
26
|
|
|
12
27
|
import { Extension } from '@tiptap/core';
|
|
13
28
|
import { Table, TableCell, TableHeader, TableRow } from '@tiptap/extension-table';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
29
|
+
import { TextSelection } from '@tiptap/pm/state';
|
|
30
|
+
import { TableView } from '@tiptap/pm/tables';
|
|
31
|
+
import { TableHandleExtension } from "./TableHandler";
|
|
16
32
|
export var TableExtension = function TableExtension(_ref) {
|
|
17
33
|
var editable = _ref.editable;
|
|
18
34
|
return [Table.extend({
|
|
19
|
-
|
|
35
|
+
addNodeView: function addNodeView() {
|
|
36
|
+
var _this = this;
|
|
37
|
+
return function (_ref2) {
|
|
38
|
+
var node = _ref2.node,
|
|
39
|
+
HTMLAttributes = _ref2.HTMLAttributes;
|
|
40
|
+
var TiptapTableView = /*#__PURE__*/function (_TableView) {
|
|
41
|
+
_inherits(TiptapTableView, _TableView);
|
|
42
|
+
var _super = _createSuper(TiptapTableView);
|
|
43
|
+
function TiptapTableView(node, minCellWidth, containerAttributes) {
|
|
44
|
+
var _this2;
|
|
45
|
+
_classCallCheck(this, TiptapTableView);
|
|
46
|
+
_this2 = _super.call(this, node, minCellWidth);
|
|
47
|
+
_defineProperty(_assertThisInitialized(_this2), "tableWrapper", void 0);
|
|
48
|
+
_defineProperty(_assertThisInitialized(_this2), "innerTableContainer", void 0);
|
|
49
|
+
_defineProperty(_assertThisInitialized(_this2), "widgetsContainer", void 0);
|
|
50
|
+
_defineProperty(_assertThisInitialized(_this2), "selectionOverlayContainer", 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.selectionOverlayContainer = _this2.createSelectionOverlayContainer();
|
|
57
|
+
_this2.setupDOMStructure();
|
|
58
|
+
return _this2;
|
|
59
|
+
}
|
|
60
|
+
_createClass(TiptapTableView, [{
|
|
61
|
+
key: "createTableWrapper",
|
|
62
|
+
value: function createTableWrapper() {
|
|
63
|
+
var container = document.createElement('div');
|
|
64
|
+
container.setAttribute("data-content-type", "table");
|
|
65
|
+
this.applyContainerAttributes(container);
|
|
66
|
+
return container;
|
|
67
|
+
}
|
|
68
|
+
}, {
|
|
69
|
+
key: "createInnerTableContainer",
|
|
70
|
+
value: function createInnerTableContainer() {
|
|
71
|
+
var container = document.createElement('div');
|
|
72
|
+
container.className = 'table-container';
|
|
73
|
+
return container;
|
|
74
|
+
}
|
|
75
|
+
}, {
|
|
76
|
+
key: "createWidgetsContainer",
|
|
77
|
+
value: function createWidgetsContainer() {
|
|
78
|
+
var container = document.createElement('div');
|
|
79
|
+
container.className = 'table-controls';
|
|
80
|
+
container.style.position = 'relative';
|
|
81
|
+
return container;
|
|
82
|
+
}
|
|
83
|
+
}, {
|
|
84
|
+
key: "createSelectionOverlayContainer",
|
|
85
|
+
value: function createSelectionOverlayContainer() {
|
|
86
|
+
var container = document.createElement('div');
|
|
87
|
+
container.className = 'table-selection-overlay-container';
|
|
88
|
+
container.style.position = 'relative';
|
|
89
|
+
return container;
|
|
90
|
+
}
|
|
91
|
+
}, {
|
|
92
|
+
key: "applyContainerAttributes",
|
|
93
|
+
value: function applyContainerAttributes(element) {
|
|
94
|
+
Object.entries(this.containerAttributes).forEach(function (_ref3) {
|
|
95
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
96
|
+
key = _ref4[0],
|
|
97
|
+
value = _ref4[1];
|
|
98
|
+
if (key !== 'class') {
|
|
99
|
+
element.setAttribute(key, value);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}, {
|
|
104
|
+
key: "setupDOMStructure",
|
|
105
|
+
value: function setupDOMStructure() {
|
|
106
|
+
var originalTable = this.dom;
|
|
107
|
+
var tableElement = originalTable.firstChild;
|
|
108
|
+
this.innerTableContainer.appendChild(tableElement);
|
|
109
|
+
originalTable.appendChild(this.innerTableContainer);
|
|
110
|
+
originalTable.appendChild(this.widgetsContainer);
|
|
111
|
+
originalTable.appendChild(this.selectionOverlayContainer);
|
|
112
|
+
this.tableWrapper.appendChild(originalTable);
|
|
113
|
+
this.dom = this.tableWrapper;
|
|
114
|
+
}
|
|
115
|
+
}, {
|
|
116
|
+
key: "ignoreMutation",
|
|
117
|
+
value: function ignoreMutation(mutation) {
|
|
118
|
+
var target = mutation.target;
|
|
119
|
+
var isInsideTable = target.closest('.table-container');
|
|
120
|
+
return !isInsideTable || _get(_getPrototypeOf(TiptapTableView.prototype), "ignoreMutation", this).call(this, mutation);
|
|
121
|
+
}
|
|
122
|
+
}]);
|
|
123
|
+
return TiptapTableView;
|
|
124
|
+
}(TableView);
|
|
125
|
+
var cellMinWidth = _this.options.cellMinWidth < 100 ? 100 : _this.options.cellMinWidth;
|
|
126
|
+
return new TiptapTableView(node, cellMinWidth, HTMLAttributes);
|
|
127
|
+
};
|
|
128
|
+
},
|
|
129
|
+
renderHTML: function renderHTML(_ref5) {
|
|
20
130
|
var _this$parent;
|
|
21
|
-
|
|
131
|
+
var node = _ref5.node,
|
|
132
|
+
HTMLAttributes = _ref5.HTMLAttributes;
|
|
133
|
+
var originalRender = (_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.call(this, {
|
|
134
|
+
node: node,
|
|
135
|
+
HTMLAttributes: HTMLAttributes
|
|
136
|
+
});
|
|
137
|
+
var wrapper = ['div', {
|
|
138
|
+
class: 'tableWrapper'
|
|
139
|
+
}, ['div', {
|
|
140
|
+
class: 'table-container'
|
|
141
|
+
}, originalRender], ['div', {
|
|
142
|
+
class: 'table-controls'
|
|
143
|
+
}], ['div', {
|
|
144
|
+
class: 'table-selection-overlay-container'
|
|
145
|
+
}]];
|
|
146
|
+
return wrapper;
|
|
147
|
+
},
|
|
148
|
+
addCommands: function addCommands() {
|
|
149
|
+
var _this$parent2;
|
|
150
|
+
return _objectSpread(_objectSpread({}, (_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.call(this)), {}, {
|
|
22
151
|
cancelSelection: function cancelSelection() {
|
|
23
|
-
return function (
|
|
24
|
-
var state =
|
|
25
|
-
dispatch =
|
|
152
|
+
return function (_ref6) {
|
|
153
|
+
var state = _ref6.state,
|
|
154
|
+
dispatch = _ref6.dispatch;
|
|
26
155
|
if (dispatch) {
|
|
27
156
|
var selection = state.selection;
|
|
28
157
|
var $from = selection.$from;
|
|
@@ -53,29 +182,16 @@ export var TableExtension = function TableExtension(_ref) {
|
|
|
53
182
|
});
|
|
54
183
|
},
|
|
55
184
|
addKeyboardShortcuts: function addKeyboardShortcuts() {
|
|
56
|
-
var
|
|
185
|
+
var _this3 = this;
|
|
57
186
|
return {
|
|
58
187
|
'Mod-9': function Mod9() {
|
|
59
|
-
return
|
|
188
|
+
return _this3.editor.chain().insertTable({
|
|
60
189
|
rows: 3,
|
|
61
190
|
cols: 4,
|
|
62
191
|
withHeaderRow: true
|
|
63
192
|
}).focus().run();
|
|
64
193
|
}
|
|
65
194
|
};
|
|
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
195
|
}
|
|
80
196
|
}).configure({
|
|
81
197
|
handleWidth: 5,
|
|
@@ -83,7 +199,77 @@ export var TableExtension = function TableExtension(_ref) {
|
|
|
83
199
|
resizable: editable,
|
|
84
200
|
lastColumnResizable: editable,
|
|
85
201
|
allowTableNodeSelection: editable
|
|
86
|
-
}), TableHeader.
|
|
202
|
+
}), TableHeader.extend({
|
|
203
|
+
addAttributes: function addAttributes() {
|
|
204
|
+
var _this$parent3;
|
|
205
|
+
return _objectSpread(_objectSpread({}, (_this$parent3 = this.parent) === null || _this$parent3 === void 0 ? void 0 : _this$parent3.call(this)), {}, {
|
|
206
|
+
bgcolor: {
|
|
207
|
+
default: null,
|
|
208
|
+
parseHTML: function parseHTML(element) {
|
|
209
|
+
return element.getAttribute('data-background-color') || element.style.backgroundColor;
|
|
210
|
+
},
|
|
211
|
+
renderHTML: function renderHTML(attributes) {
|
|
212
|
+
return {
|
|
213
|
+
'data-background-color': attributes.bgcolor,
|
|
214
|
+
style: "background-color: ".concat(attributes.bgcolor)
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
textAlign: {
|
|
219
|
+
default: null,
|
|
220
|
+
parseHTML: function parseHTML(element) {
|
|
221
|
+
return element.getAttribute('data-text-align') || element.style.textAlign;
|
|
222
|
+
},
|
|
223
|
+
renderHTML: function renderHTML(attributes) {
|
|
224
|
+
if (!attributes.textAlign) return {};
|
|
225
|
+
return {
|
|
226
|
+
style: "text-align: ".concat(attributes.textAlign),
|
|
227
|
+
'data-text-align': attributes.textAlign
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
verticalAlign: {
|
|
232
|
+
default: null,
|
|
233
|
+
parseHTML: function parseHTML(element) {
|
|
234
|
+
return element.getAttribute('data-vertical-align') || element.style.verticalAlign;
|
|
235
|
+
},
|
|
236
|
+
renderHTML: function renderHTML(attributes) {
|
|
237
|
+
if (!attributes.verticalAlign) return {};
|
|
238
|
+
return {
|
|
239
|
+
style: "vertical-align: ".concat(attributes.verticalAlign),
|
|
240
|
+
'data-vertical-align': attributes.verticalAlign
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
fontSize: {
|
|
245
|
+
default: null,
|
|
246
|
+
parseHTML: function parseHTML(element) {
|
|
247
|
+
return element.getAttribute('data-font-size') || element.style.fontSize;
|
|
248
|
+
},
|
|
249
|
+
renderHTML: function renderHTML(attributes) {
|
|
250
|
+
if (!attributes.fontSize) return {};
|
|
251
|
+
return {
|
|
252
|
+
style: "font-size: ".concat(attributes.fontSize),
|
|
253
|
+
'data-font-size': attributes.fontSize
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
fontWeight: {
|
|
258
|
+
default: null,
|
|
259
|
+
parseHTML: function parseHTML(element) {
|
|
260
|
+
return element.getAttribute('data-font-weight') || element.style.fontWeight;
|
|
261
|
+
},
|
|
262
|
+
renderHTML: function renderHTML(attributes) {
|
|
263
|
+
if (!attributes.fontWeight) return {};
|
|
264
|
+
return {
|
|
265
|
+
style: "font-weight: ".concat(attributes.fontWeight),
|
|
266
|
+
'data-font-weight': attributes.fontWeight
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}).configure({
|
|
87
273
|
HTMLAttributes: {
|
|
88
274
|
class: 'table-header'
|
|
89
275
|
}
|
|
@@ -93,10 +279,10 @@ export var TableExtension = function TableExtension(_ref) {
|
|
|
93
279
|
}
|
|
94
280
|
}), TableCell.extend({
|
|
95
281
|
addAttributes: function addAttributes() {
|
|
96
|
-
var _this$
|
|
97
|
-
return _objectSpread(_objectSpread({}, (_this$
|
|
282
|
+
var _this$parent4;
|
|
283
|
+
return _objectSpread(_objectSpread({}, (_this$parent4 = this.parent) === null || _this$parent4 === void 0 ? void 0 : _this$parent4.call(this)), {}, {
|
|
98
284
|
bgcolor: {
|
|
99
|
-
default:
|
|
285
|
+
default: null,
|
|
100
286
|
parseHTML: function parseHTML(element) {
|
|
101
287
|
return element.getAttribute('data-background-color') || element.style.backgroundColor;
|
|
102
288
|
},
|
|
@@ -120,6 +306,19 @@ export var TableExtension = function TableExtension(_ref) {
|
|
|
120
306
|
};
|
|
121
307
|
}
|
|
122
308
|
},
|
|
309
|
+
verticalAlign: {
|
|
310
|
+
default: null,
|
|
311
|
+
parseHTML: function parseHTML(element) {
|
|
312
|
+
return element.getAttribute('data-vertical-align') || element.style.verticalAlign;
|
|
313
|
+
},
|
|
314
|
+
renderHTML: function renderHTML(attributes) {
|
|
315
|
+
if (!attributes.verticalAlign) return {};
|
|
316
|
+
return {
|
|
317
|
+
style: "vertical-align: ".concat(attributes.verticalAlign),
|
|
318
|
+
'data-vertical-align': attributes.verticalAlign
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
},
|
|
123
322
|
fontSize: {
|
|
124
323
|
default: null,
|
|
125
324
|
parseHTML: function parseHTML(element) {
|
|
@@ -149,104 +348,24 @@ export var TableExtension = function TableExtension(_ref) {
|
|
|
149
348
|
});
|
|
150
349
|
},
|
|
151
350
|
addKeyboardShortcuts: function addKeyboardShortcuts() {
|
|
152
|
-
var
|
|
351
|
+
var _this4 = this;
|
|
153
352
|
return {
|
|
154
353
|
Tab: function Tab() {
|
|
155
|
-
if (
|
|
156
|
-
return
|
|
157
|
-
} else if (!
|
|
354
|
+
if (_this4.editor.chain().goToNextCell().focus().run()) {
|
|
355
|
+
return _this4.editor.chain().cancelSelection().run();
|
|
356
|
+
} else if (!_this4.editor.can().addRowAfter()) {
|
|
158
357
|
return false;
|
|
159
358
|
} else {
|
|
160
|
-
return
|
|
359
|
+
return _this4.editor.chain().addRowAfter().goToNextCell().cancelSelection().run();
|
|
161
360
|
}
|
|
162
361
|
},
|
|
163
362
|
'Shift-Tab': function ShiftTab() {
|
|
164
|
-
return
|
|
363
|
+
return _this4.editor.chain().goToPreviousCell().cancelSelection().run();
|
|
165
364
|
}
|
|
166
365
|
};
|
|
167
366
|
}
|
|
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({
|
|
178
|
-
name: 'safariCompositionDeleteFix',
|
|
179
|
-
addProseMirrorPlugins: function addProseMirrorPlugins() {
|
|
180
|
-
if (!editable) return [];
|
|
181
|
-
var ZERO_WIDTH_SPACE = "\u200B";
|
|
182
|
-
var isSafari = function () {
|
|
183
|
-
if (typeof navigator === 'undefined') return false;
|
|
184
|
-
var ua = navigator.userAgent;
|
|
185
|
-
var isAppleMobile = /iP(ad|hone|od)/.test(ua);
|
|
186
|
-
var isMacSafari = /Safari\//.test(ua) && !/Chrome\//.test(ua);
|
|
187
|
-
return isAppleMobile || isMacSafari;
|
|
188
|
-
}();
|
|
189
|
-
if (!isSafari) return [];
|
|
190
|
-
|
|
191
|
-
// 注意:这里不能使用上面从 ProseMirror 导入的 Node 类型,需判断 DOM 文本节点
|
|
192
|
-
var isTextNode = function isTextNode(node) {
|
|
193
|
-
return !!node && node.nodeType === 3;
|
|
194
|
-
};
|
|
195
|
-
return [new Plugin({
|
|
196
|
-
props: {
|
|
197
|
-
handleDOMEvents: {
|
|
198
|
-
beforeinput: function beforeinput(_view, event) {
|
|
199
|
-
// 仅处理 Safari 在中文合成结束后触发的删除合成文本行为
|
|
200
|
-
if (event.inputType !== 'deleteCompositionText') {
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
var selection = window.getSelection();
|
|
204
|
-
if (!selection || selection.rangeCount === 0) return false;
|
|
205
|
-
var range = selection.getRangeAt(0);
|
|
206
|
-
var startContainer = range.startContainer,
|
|
207
|
-
endContainer = range.endContainer,
|
|
208
|
-
startOffset = range.startOffset,
|
|
209
|
-
endOffset = range.endOffset;
|
|
210
|
-
if (isTextNode(startContainer) && startContainer === endContainer && startOffset === 0 && endOffset === startContainer.length) {
|
|
211
|
-
var _startContainer$paren;
|
|
212
|
-
(_startContainer$paren = startContainer.parentElement) === null || _startContainer$paren === void 0 || _startContainer$paren.insertBefore(document.createTextNode(ZERO_WIDTH_SPACE), startContainer);
|
|
213
|
-
}
|
|
214
|
-
// 让 ProseMirror 照常处理
|
|
215
|
-
return false;
|
|
216
|
-
},
|
|
217
|
-
input: function input(_view, event) {
|
|
218
|
-
if (event.inputType !== 'deleteCompositionText') {
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
var selection = window.getSelection();
|
|
222
|
-
if (!selection || selection.rangeCount === 0) return false;
|
|
223
|
-
var range = selection.getRangeAt(0);
|
|
224
|
-
var node = range.startContainer;
|
|
225
|
-
var parentEl = (node === null || node === void 0 ? void 0 : node.parentElement) || null;
|
|
226
|
-
if (!parentEl) return false;
|
|
227
|
-
var textNodes = Array.from(parentEl.childNodes).filter(isTextNode);
|
|
228
|
-
var _iterator = _createForOfIteratorHelper(textNodes),
|
|
229
|
-
_step;
|
|
230
|
-
try {
|
|
231
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
232
|
-
var textNode = _step.value;
|
|
233
|
-
if (textNode.textContent === ZERO_WIDTH_SPACE) {
|
|
234
|
-
textNode.remove();
|
|
235
|
-
} else if (textNode.textContent && textNode.textContent.includes(ZERO_WIDTH_SPACE)) {
|
|
236
|
-
textNode.textContent = textNode.textContent.split(ZERO_WIDTH_SPACE).join('');
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
} catch (err) {
|
|
240
|
-
_iterator.e(err);
|
|
241
|
-
} finally {
|
|
242
|
-
_iterator.f();
|
|
243
|
-
}
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
})];
|
|
249
|
-
}
|
|
367
|
+
}), editable ? TableHandleExtension : Extension.create({
|
|
368
|
+
name: 'tableHandleExtension'
|
|
250
369
|
})];
|
|
251
370
|
};
|
|
252
371
|
export default TableExtension;
|
|
@@ -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
|
+
}
|