@progress/kendo-editor-common 1.8.2-dev.202204011319 → 1.9.0-dev.202204060830
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/cdn/js/kendo-editor-common.js +2 -2
- package/dist/cdn/main.js +1 -1
- package/dist/es/config/constants.js +4 -0
- package/dist/es/config/schema.js +9 -5
- package/dist/es/main.js +1 -0
- package/dist/es/plugins/image-resize.js +4 -3
- package/dist/es/plugins/table-resize/column-resize.js +294 -0
- package/dist/es/plugins/table-resize/index.js +8 -0
- package/dist/es/plugins/table-resize/row-resize.js +244 -0
- package/dist/es/plugins/table-resize/table-resize.js +281 -0
- package/dist/es/plugins/table-resize/table-view.js +87 -0
- package/dist/es/plugins/table-resize/utils.js +53 -0
- package/dist/es2015/config/constants.js +4 -0
- package/dist/es2015/config/schema.js +11 -8
- package/dist/es2015/main.js +1 -0
- package/dist/es2015/plugins/image-resize.js +4 -3
- package/dist/es2015/plugins/table-resize/column-resize.js +290 -0
- package/dist/es2015/plugins/table-resize/index.js +8 -0
- package/dist/es2015/plugins/table-resize/row-resize.js +240 -0
- package/dist/es2015/plugins/table-resize/table-resize.js +277 -0
- package/dist/es2015/plugins/table-resize/table-view.js +84 -0
- package/dist/es2015/plugins/table-resize/utils.js +51 -0
- package/dist/npm/config/constants.d.ts +4 -0
- package/dist/npm/config/constants.js +4 -0
- package/dist/npm/config/schema.d.ts +1 -0
- package/dist/npm/config/schema.js +8 -4
- package/dist/npm/main.d.ts +1 -0
- package/dist/npm/main.js +2 -0
- package/dist/npm/plugins/image-resize.js +4 -3
- package/dist/npm/plugins/table-resize/column-resize.d.ts +2 -0
- package/dist/npm/plugins/table-resize/column-resize.js +297 -0
- package/dist/npm/plugins/table-resize/index.d.ts +1 -0
- package/dist/npm/plugins/table-resize/index.js +10 -0
- package/dist/npm/plugins/table-resize/row-resize.d.ts +2 -0
- package/dist/npm/plugins/table-resize/row-resize.js +247 -0
- package/dist/npm/plugins/table-resize/table-resize.d.ts +6 -0
- package/dist/npm/plugins/table-resize/table-resize.js +283 -0
- package/dist/npm/plugins/table-resize/table-view.d.ts +17 -0
- package/dist/npm/plugins/table-resize/table-view.js +89 -0
- package/dist/npm/plugins/table-resize/utils.d.ts +12 -0
- package/dist/npm/plugins/table-resize/utils.js +59 -0
- package/dist/systemjs/kendo-editor-common.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import * as tslib_1 from "tslib";
|
|
2
|
+
import { NodeSelection, Plugin } from 'prosemirror-state';
|
|
3
|
+
import { colgroupAttr, dataDirection, resizableAttr } from '../../config/constants';
|
|
4
|
+
import { getTable, parseStyle, setNodeStyle, tableResizeKey as key } from './utils';
|
|
5
|
+
function parentNode(pos, predicate) {
|
|
6
|
+
for (var d = pos.depth; d > 0; d--) {
|
|
7
|
+
var node = pos.node(d);
|
|
8
|
+
if (predicate(node)) {
|
|
9
|
+
return node;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
var directions = {
|
|
15
|
+
'southeast': { x: 1, y: 1 },
|
|
16
|
+
'east': { x: 1, y: 0 },
|
|
17
|
+
'south': { x: 0, y: 1 },
|
|
18
|
+
'north': { x: 0, y: -1 },
|
|
19
|
+
'west': { x: -1, y: 0 },
|
|
20
|
+
'southwest': { x: -1, y: 1 },
|
|
21
|
+
'northwest': { x: -1, y: -1 },
|
|
22
|
+
'northeast': { x: 1, y: -1 } // top right
|
|
23
|
+
};
|
|
24
|
+
var commonDir = {
|
|
25
|
+
'southeast': true,
|
|
26
|
+
'southwest': true,
|
|
27
|
+
'northwest': true,
|
|
28
|
+
'northeast': true
|
|
29
|
+
};
|
|
30
|
+
var horizontalDir = tslib_1.__assign({ 'east': true, 'west': true }, commonDir);
|
|
31
|
+
var verticalDir = tslib_1.__assign({ 'south': true, 'north': true }, commonDir);
|
|
32
|
+
var setSize = function (domNode, sizeType, value) {
|
|
33
|
+
domNode.style[sizeType] = value + 'px';
|
|
34
|
+
};
|
|
35
|
+
var ResizeState = /** @class */ (function () {
|
|
36
|
+
function ResizeState(activeHandle, dragging, nodePosition) {
|
|
37
|
+
this.activeHandle = activeHandle;
|
|
38
|
+
this.dragging = dragging;
|
|
39
|
+
this.nodePosition = nodePosition;
|
|
40
|
+
}
|
|
41
|
+
ResizeState.prototype.apply = function (tr) {
|
|
42
|
+
var state = this, next = tr.getMeta(key);
|
|
43
|
+
if (next) {
|
|
44
|
+
var nextState = new ResizeState(next.activeHandle, next.setDragging, next.nodePosition);
|
|
45
|
+
return nextState;
|
|
46
|
+
}
|
|
47
|
+
return state;
|
|
48
|
+
};
|
|
49
|
+
return ResizeState;
|
|
50
|
+
}());
|
|
51
|
+
var handleMouseMove = function (view, event, options) {
|
|
52
|
+
var state = key.getState(view.state);
|
|
53
|
+
var dragging = state.dragging, nodePosition = state.nodePosition, activeHandle = state.activeHandle;
|
|
54
|
+
if (nodePosition < 0 || !dragging) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
var resizedNode = getTable(view.nodeDOM(nodePosition));
|
|
58
|
+
var rect = resizedNode.getBoundingClientRect();
|
|
59
|
+
var dir = directions[activeHandle];
|
|
60
|
+
var diffX = (event.clientX - dragging.startX) * dir.x;
|
|
61
|
+
var diffY = (event.clientY - dragging.startY) * dir.y;
|
|
62
|
+
var nodeWidth = resizedNode.offsetWidth;
|
|
63
|
+
var nodeHeight = resizedNode.offsetHeight;
|
|
64
|
+
var width = dir.x ? diffX + nodeWidth : rect.width;
|
|
65
|
+
var height = dir.y ? diffY + nodeHeight : rect.height;
|
|
66
|
+
if (options.lockRatio && dir.x && dir.y) {
|
|
67
|
+
var ratio = Math.min(width / nodeWidth, height / nodeHeight);
|
|
68
|
+
var lockWidth = nodeWidth * ratio;
|
|
69
|
+
var lockHeight = nodeHeight * ratio;
|
|
70
|
+
dragging.startX = event.clientX - (width - lockWidth) * dir.x;
|
|
71
|
+
dragging.startY = event.clientY - (height - lockHeight) * dir.y;
|
|
72
|
+
width = lockWidth;
|
|
73
|
+
height = lockHeight;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
dragging.startX = dir.x ? event.clientX : dragging.startX;
|
|
77
|
+
dragging.startY = dir.y ? event.clientY : dragging.startY;
|
|
78
|
+
}
|
|
79
|
+
if (horizontalDir[activeHandle]) {
|
|
80
|
+
setSize(resizedNode, 'width', width);
|
|
81
|
+
}
|
|
82
|
+
if (verticalDir[activeHandle]) {
|
|
83
|
+
setSize(resizedNode, 'height', height);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var toPercents = function (view, tr, tablePos) {
|
|
87
|
+
var tableNode = view.state.doc.nodeAt(tablePos);
|
|
88
|
+
var tableDom = getTable(view.nodeDOM(tablePos));
|
|
89
|
+
var _a = tableSize(tableDom), tableWidth = _a.width, tableHeight = _a.height, colsWidth = _a.colsWidth;
|
|
90
|
+
var colgroup = tableDom.firstChild;
|
|
91
|
+
var cols = Array.from((colgroup && colgroup.children) || []);
|
|
92
|
+
// const borders = new Array(cols.length).fill(tableWidth / tableOffsetWidth / cols.length);
|
|
93
|
+
var widthChanged = false;
|
|
94
|
+
cols.forEach(function (col, i) {
|
|
95
|
+
if (col.style.width && !/%$/.test(col.style.width)) {
|
|
96
|
+
col.style.width = ((colsWidth[i]) * 100 / tableWidth) + '%';
|
|
97
|
+
widthChanged = true;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
var rows = Array.from(tableDom.rows);
|
|
101
|
+
var heightChange = false;
|
|
102
|
+
tableNode.forEach(function (row, offset, index) {
|
|
103
|
+
var rowHeight = parseStyle(row.attrs.style).height;
|
|
104
|
+
if (rowHeight && !/%$/.test(rowHeight)) {
|
|
105
|
+
tr.setNodeMarkup(tablePos + offset + 1, null, setNodeStyle(row.attrs, 'height', (rows[index].offsetHeight * 100 / tableHeight) + '%'));
|
|
106
|
+
heightChange = true;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
var tableAttrs = tableNode.attrs;
|
|
110
|
+
if (parseStyle(tableAttrs.style).width !== tableWidth + 'px') {
|
|
111
|
+
tableAttrs = setNodeStyle(tableAttrs, 'width', tableWidth + 'px');
|
|
112
|
+
}
|
|
113
|
+
if (widthChanged) {
|
|
114
|
+
tableAttrs[colgroupAttr] = colgroup.outerHTML;
|
|
115
|
+
}
|
|
116
|
+
if (heightChange) {
|
|
117
|
+
tableAttrs = setNodeStyle(tableAttrs, 'height', tableHeight + 'px');
|
|
118
|
+
}
|
|
119
|
+
if (widthChanged || heightChange) {
|
|
120
|
+
tr.setNodeMarkup(tablePos, null, tableAttrs);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var toPixels = function (view, tr, tablePos, attrs) {
|
|
124
|
+
var tableNode = view.state.doc.nodeAt(tablePos);
|
|
125
|
+
var tableDom = getTable(view.nodeDOM(tablePos));
|
|
126
|
+
var rows = Array.from(tableDom.rows);
|
|
127
|
+
tableNode.forEach(function (row, offset, index) {
|
|
128
|
+
var rowHeight = parseStyle(row.attrs.style).height;
|
|
129
|
+
if (rowHeight && !/px$/.test(rowHeight)) {
|
|
130
|
+
tr.setNodeMarkup(tablePos + offset + 1, null, setNodeStyle(row.attrs, 'height', rows[index].offsetHeight + 'px'));
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
var colgroup = tableDom.firstChild;
|
|
134
|
+
var cols = Array.from((colgroup && colgroup.children) || []);
|
|
135
|
+
var widthChanged = false;
|
|
136
|
+
cols.forEach(function (col, i) {
|
|
137
|
+
if (col.style.width && !/px$/.test(col.style.width)) {
|
|
138
|
+
col.style.width = cols[i].offsetWidth + 'px';
|
|
139
|
+
widthChanged = true;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
var tableAttrs = tslib_1.__assign({}, attrs);
|
|
143
|
+
if (widthChanged) {
|
|
144
|
+
tableAttrs[colgroupAttr] = colgroup.outerHTML;
|
|
145
|
+
}
|
|
146
|
+
return tableAttrs;
|
|
147
|
+
};
|
|
148
|
+
var tableSize = function (table) {
|
|
149
|
+
var cols = Array.from(table.firstChild.children);
|
|
150
|
+
var colsWidth = cols.map(function (c) { return c.offsetWidth; });
|
|
151
|
+
var width = colsWidth.reduce(function (acc, cur) { return acc + cur; }, 0);
|
|
152
|
+
var height = table.offsetHeight; // Array.from(table.rows).reduce((acc, cur) => acc + cur.offsetHeight, 0);
|
|
153
|
+
return { width: width, height: height, colsWidth: colsWidth, offsetWidth: table.offsetWidth };
|
|
154
|
+
};
|
|
155
|
+
var handleMouseUp = function (view) {
|
|
156
|
+
var _a = key.getState(view.state), dragging = _a.dragging, nodePosition = _a.nodePosition, activeHandle = _a.activeHandle;
|
|
157
|
+
if (dragging) {
|
|
158
|
+
var node = view.state.doc.nodeAt(nodePosition);
|
|
159
|
+
var dom = getTable(view.nodeDOM(nodePosition));
|
|
160
|
+
var rect = tableSize(dom);
|
|
161
|
+
if (node) {
|
|
162
|
+
var width = rect.offsetWidth + 'px';
|
|
163
|
+
var height = rect.height + 'px';
|
|
164
|
+
var tr = view.state.tr;
|
|
165
|
+
var attrs = node.attrs;
|
|
166
|
+
var parsedStyles = parseStyle(attrs.style);
|
|
167
|
+
if (horizontalDir[activeHandle] && dom.style.width && parsedStyles.width !== width) {
|
|
168
|
+
attrs = setNodeStyle(attrs, 'width', width);
|
|
169
|
+
}
|
|
170
|
+
if (verticalDir[activeHandle] && dom.style.height && parsedStyles.height !== height) {
|
|
171
|
+
attrs = setNodeStyle(attrs, 'height', height);
|
|
172
|
+
}
|
|
173
|
+
toPixels(view, tr, nodePosition, attrs);
|
|
174
|
+
tr.setNodeMarkup(nodePosition, null, attrs);
|
|
175
|
+
tr.setMeta('commandName', 'node-resize');
|
|
176
|
+
tr.setMeta('args', attrs);
|
|
177
|
+
tr.setMeta(key, {
|
|
178
|
+
setDragging: null,
|
|
179
|
+
activeHandle: null,
|
|
180
|
+
nodePosition: nodePosition
|
|
181
|
+
});
|
|
182
|
+
view.dispatch(tr);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
var handleMouseDown = function (view, event, options) {
|
|
187
|
+
var target = event.target;
|
|
188
|
+
var activeHandle = target.getAttribute(dataDirection);
|
|
189
|
+
if (!activeHandle) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
var resizeState = key.getState(view.state);
|
|
193
|
+
event.preventDefault();
|
|
194
|
+
var transaction = view.state.tr;
|
|
195
|
+
transaction.setMeta(key, {
|
|
196
|
+
setDragging: { startX: event.clientX, startY: event.clientY },
|
|
197
|
+
activeHandle: activeHandle,
|
|
198
|
+
nodePosition: resizeState.nodePosition
|
|
199
|
+
});
|
|
200
|
+
transaction.setMeta('addToHistory', false);
|
|
201
|
+
toPercents(view, transaction, resizeState.nodePosition);
|
|
202
|
+
view.dispatch(transaction);
|
|
203
|
+
var curWindow = event.view || window;
|
|
204
|
+
function move(e) {
|
|
205
|
+
handleMouseMove(view, e, options);
|
|
206
|
+
}
|
|
207
|
+
function finish(_e) {
|
|
208
|
+
curWindow.removeEventListener('mouseup', finish);
|
|
209
|
+
curWindow.removeEventListener('mousemove', move);
|
|
210
|
+
handleMouseUp(view);
|
|
211
|
+
}
|
|
212
|
+
curWindow.addEventListener('mouseup', finish);
|
|
213
|
+
curWindow.addEventListener('mousemove', move);
|
|
214
|
+
return true;
|
|
215
|
+
};
|
|
216
|
+
export var tableResizing = function (options) {
|
|
217
|
+
if (options === void 0) { options = { node: 'table', lockRatio: false }; }
|
|
218
|
+
return new Plugin({
|
|
219
|
+
key: key,
|
|
220
|
+
view: function (_viewObj) { return ({
|
|
221
|
+
selectedNode: function (state, nodeType) {
|
|
222
|
+
var selection = state.selection;
|
|
223
|
+
var isNodeSelected = selection instanceof NodeSelection && nodeType === selection.node.type;
|
|
224
|
+
if (isNodeSelected && selection instanceof NodeSelection) {
|
|
225
|
+
return { node: selection.node, pos: selection.from };
|
|
226
|
+
}
|
|
227
|
+
var node = parentNode(selection.$from, function (n) { return n.type === nodeType; });
|
|
228
|
+
if (node) {
|
|
229
|
+
var tableDepth = new Array(selection.$from.depth + 1).fill(0)
|
|
230
|
+
.findIndex(function (_, i) { return selection.$from.node(i).type.spec.tableRole === 'table'; });
|
|
231
|
+
var pos = selection.$from.start(tableDepth) - 1;
|
|
232
|
+
return { node: node, pos: pos };
|
|
233
|
+
}
|
|
234
|
+
return null;
|
|
235
|
+
},
|
|
236
|
+
update: function (view, prevState) {
|
|
237
|
+
var _a, _b, _c, _d;
|
|
238
|
+
var state = view.state;
|
|
239
|
+
var nodeType = state.schema.nodes[options.node];
|
|
240
|
+
var selected = this.selectedNode(state, nodeType);
|
|
241
|
+
var prevSelected = this.selectedNode(prevState, nodeType);
|
|
242
|
+
if (!selected && prevSelected && !prevState.doc.eq(view.state.doc)) {
|
|
243
|
+
// selected table is deleted
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (selected || prevSelected) {
|
|
247
|
+
var tr = state.tr;
|
|
248
|
+
if (selected && prevSelected && selected.pos !== prevSelected.pos) {
|
|
249
|
+
tr.setMeta(key, { nodePosition: selected.pos });
|
|
250
|
+
tr.setNodeMarkup(prevSelected.pos, nodeType, tslib_1.__assign({}, prevSelected.node.attrs, (_a = {}, _a[resizableAttr] = false, _a)));
|
|
251
|
+
tr.setNodeMarkup(selected.pos, nodeType, tslib_1.__assign({}, selected.node.attrs, (_b = {}, _b[resizableAttr] = true, _b)));
|
|
252
|
+
view.dispatch(tr);
|
|
253
|
+
}
|
|
254
|
+
else if (selected && !prevSelected) {
|
|
255
|
+
tr.setMeta(key, { nodePosition: selected.pos });
|
|
256
|
+
view.dispatch(tr.setNodeMarkup(selected.pos, nodeType, tslib_1.__assign({}, selected.node.attrs, (_c = {}, _c[resizableAttr] = true, _c))));
|
|
257
|
+
}
|
|
258
|
+
else if (!selected && prevSelected) {
|
|
259
|
+
tr.setMeta(key, { nodePosition: -1 });
|
|
260
|
+
view.dispatch(tr.setNodeMarkup(prevSelected.pos, nodeType, tslib_1.__assign({}, prevSelected.node.attrs, (_d = {}, _d[resizableAttr] = false, _d))));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}); },
|
|
265
|
+
state: {
|
|
266
|
+
init: function () {
|
|
267
|
+
return new ResizeState('', null, -1);
|
|
268
|
+
},
|
|
269
|
+
apply: function (tr, prev) {
|
|
270
|
+
return prev.apply(tr);
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
props: {
|
|
274
|
+
handleDOMEvents: {
|
|
275
|
+
mousedown: function (view, event) {
|
|
276
|
+
return handleMouseDown(view, event, options);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { colgroupAttr, dataDirection, resizableAttr, resizableWrap, resizeHandle } from '../../config/constants';
|
|
2
|
+
import { parseStrColgroup } from '../../config/schema';
|
|
3
|
+
var directions = ['northwest', 'north', 'northeast', 'southwest', 'south', 'southeast', 'west', 'east'];
|
|
4
|
+
var TableView = /** @class */ (function () {
|
|
5
|
+
function TableView(node, view) {
|
|
6
|
+
this.node = node;
|
|
7
|
+
this.view = view;
|
|
8
|
+
this.dom = document.createElement('div');
|
|
9
|
+
this.dom.className = resizableWrap;
|
|
10
|
+
this.table = this.dom.appendChild(document.createElement('table'));
|
|
11
|
+
if (node.attrs[colgroupAttr]) {
|
|
12
|
+
this.renderColgroup(node.attrs[colgroupAttr]);
|
|
13
|
+
}
|
|
14
|
+
var tBody = this.table.appendChild(document.createElement('tbody'));
|
|
15
|
+
this.setAttributes(this.table, node.attrs);
|
|
16
|
+
this.resizeHandles = directions.map(function (dir) {
|
|
17
|
+
var handle = document.createElement('span');
|
|
18
|
+
handle.className = resizeHandle + ' ' + dir;
|
|
19
|
+
handle.setAttribute(dataDirection, dir);
|
|
20
|
+
return handle;
|
|
21
|
+
});
|
|
22
|
+
this.contentDOM = tBody;
|
|
23
|
+
}
|
|
24
|
+
TableView.prototype.update = function (node) {
|
|
25
|
+
var _this = this;
|
|
26
|
+
if (node.type !== this.node.type) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
var prev = this.node;
|
|
30
|
+
this.node = node;
|
|
31
|
+
if (node.attrs[resizableAttr]) {
|
|
32
|
+
this.resizeHandles.forEach(function (handle) {
|
|
33
|
+
_this.dom.appendChild(handle);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
Array.from(this.dom.children)
|
|
38
|
+
.filter(function (e) { return e.classList.contains(resizeHandle); })
|
|
39
|
+
.forEach(function (e) { return e.remove(); });
|
|
40
|
+
}
|
|
41
|
+
this.setAttributes(this.table, node.attrs);
|
|
42
|
+
if (prev.attrs[colgroupAttr] !== node.attrs[colgroupAttr]) {
|
|
43
|
+
this.renderColgroup(node.attrs[colgroupAttr]);
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
};
|
|
47
|
+
TableView.prototype.ignoreMutation = function (record) {
|
|
48
|
+
var result = record.type === 'attributes' &&
|
|
49
|
+
(record.target === this.table ||
|
|
50
|
+
record.target.firstChild === this.table ||
|
|
51
|
+
(this.colgroup && this.colgroup.contains(record.target)));
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
TableView.prototype.destroy = function () {
|
|
55
|
+
this.node = null;
|
|
56
|
+
this.view = null;
|
|
57
|
+
this.table = null;
|
|
58
|
+
this.colgroup = null;
|
|
59
|
+
this.resizeHandles = null;
|
|
60
|
+
};
|
|
61
|
+
TableView.prototype.renderColgroup = function (colgroupStr) {
|
|
62
|
+
if (this.table && this.table.firstChild && this.table.firstChild.nodeName === 'COLGROUP') {
|
|
63
|
+
this.table.removeChild(this.table.firstChild);
|
|
64
|
+
}
|
|
65
|
+
if (colgroupStr) {
|
|
66
|
+
this.colgroup = parseStrColgroup(colgroupStr);
|
|
67
|
+
this.table.insertBefore(this.colgroup, this.table.firstChild);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
TableView.prototype.setAttributes = function (table, attrs) {
|
|
71
|
+
var skip = [colgroupAttr, resizableAttr];
|
|
72
|
+
for (var attrName in attrs) {
|
|
73
|
+
if (attrName && skip.indexOf(attrName) === -1) {
|
|
74
|
+
var current = table.getAttribute(attrName);
|
|
75
|
+
var next = attrs[attrName];
|
|
76
|
+
if (next && next !== current) {
|
|
77
|
+
table.setAttribute(attrName, next);
|
|
78
|
+
}
|
|
79
|
+
else if (!next) {
|
|
80
|
+
table.removeAttribute(attrName);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
return TableView;
|
|
86
|
+
}());
|
|
87
|
+
export { TableView };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as tslib_1 from "tslib";
|
|
2
|
+
import { PluginKey } from 'prosemirror-state';
|
|
3
|
+
import { changeStylesString } from '../../utils';
|
|
4
|
+
export var reAnyValue = /^.+$/;
|
|
5
|
+
export var parseStyle = function (styleText) {
|
|
6
|
+
var styles = (styleText || '').split(/\s*;\s*/).filter(Boolean).map(function (s) {
|
|
7
|
+
var _a;
|
|
8
|
+
var nameValue = s.split(/\s*:\s*/);
|
|
9
|
+
return _a = {}, _a[nameValue[0]] = nameValue[1], _a;
|
|
10
|
+
}).reduce(function (acc, val) { return (tslib_1.__assign({}, acc, val)); }, {});
|
|
11
|
+
return styles;
|
|
12
|
+
};
|
|
13
|
+
export function setNodeStyle(nodeAttrs, styleType, value) {
|
|
14
|
+
var attrs;
|
|
15
|
+
if (new RegExp('[^-]?' + styleType + ':').test(nodeAttrs.style || '')) {
|
|
16
|
+
var style = changeStylesString(nodeAttrs.style || '', { style: styleType, value: reAnyValue, newValue: value }).style;
|
|
17
|
+
attrs = tslib_1.__assign({}, nodeAttrs, { style: style });
|
|
18
|
+
}
|
|
19
|
+
else if (nodeAttrs.style) {
|
|
20
|
+
attrs = tslib_1.__assign({}, nodeAttrs, { style: nodeAttrs.style.replace(/;$/, '') + '; ' + styleType + ': ' + value + ';' });
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
attrs = tslib_1.__assign({}, nodeAttrs, { style: styleType + ': ' + value + ';' });
|
|
24
|
+
}
|
|
25
|
+
return attrs;
|
|
26
|
+
}
|
|
27
|
+
export var tableResizeKey = new PluginKey('table-resize');
|
|
28
|
+
export var tableColumnResizing = new PluginKey('table-column-resizing');
|
|
29
|
+
export var tableRowResizing = new PluginKey('table-row-resizing');
|
|
30
|
+
export function otherResizing(current, state) {
|
|
31
|
+
var activeResize = false;
|
|
32
|
+
activeResize = activeResize ||
|
|
33
|
+
(current !== tableResizeKey && Boolean(tableResizeKey.get(state)) && tableResizeKey.getState(state).dragging);
|
|
34
|
+
activeResize = activeResize ||
|
|
35
|
+
(current !== tableColumnResizing && Boolean(tableColumnResizing.get(state)) && tableColumnResizing.getState(state).dragging);
|
|
36
|
+
activeResize = activeResize ||
|
|
37
|
+
(current !== tableRowResizing && Boolean(tableRowResizing.get(state)) && tableRowResizing.getState(state).dragging);
|
|
38
|
+
return activeResize;
|
|
39
|
+
}
|
|
40
|
+
export function otherResizeHandle(current, state) {
|
|
41
|
+
var activeResize = false;
|
|
42
|
+
activeResize = activeResize ||
|
|
43
|
+
(current !== tableColumnResizing && tableColumnResizing.get(state) && tableColumnResizing.getState(state).activeHandle > -1);
|
|
44
|
+
activeResize = activeResize ||
|
|
45
|
+
(current !== tableRowResizing && tableRowResizing.get(state) && tableRowResizing.getState(state).activeHandle > -1);
|
|
46
|
+
return activeResize;
|
|
47
|
+
}
|
|
48
|
+
export function getTable(dom) {
|
|
49
|
+
if (dom && dom.firstChild && dom.firstChild.nodeName === 'TABLE') {
|
|
50
|
+
return dom.firstChild;
|
|
51
|
+
}
|
|
52
|
+
return dom;
|
|
53
|
+
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export const rowTypeAttr = 'k-parent-node';
|
|
2
2
|
export const colgroupAttr = 'k-colgroup-data';
|
|
3
|
+
export const resizableAttr = 'resizable-node';
|
|
4
|
+
export const resizableWrap = 'k-editor-resize-wrap-element';
|
|
5
|
+
export const resizeHandle = 'k-editor-resize-handle';
|
|
6
|
+
export const dataDirection = 'data-direction';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema } from 'prosemirror-model';
|
|
2
2
|
import { tableNodes } from 'prosemirror-tables';
|
|
3
3
|
import { domToPmDoc, htmlToFragment, pmDocToFragment } from '../source';
|
|
4
|
-
import { rowTypeAttr, colgroupAttr } from './constants';
|
|
4
|
+
import { rowTypeAttr, colgroupAttr, resizableAttr } from './constants';
|
|
5
5
|
const hole = 0;
|
|
6
6
|
const blockquoteDOM = ['blockquote', hole], hrDOM = ['hr'], preDOM = ['pre', ['code', hole]];
|
|
7
7
|
const olDOM = ['ol', 0], ulDOM = ['ul', 0], liDOM = ['li', 0];
|
|
@@ -106,25 +106,28 @@ const shouldSkipColgroup = (node) => {
|
|
|
106
106
|
}
|
|
107
107
|
return shouldSkip;
|
|
108
108
|
};
|
|
109
|
+
export const parseStrColgroup = (colgroup) => {
|
|
110
|
+
const doc = domToPmDoc(htmlToFragment(colgroup), colgroupSchema, { preserveWhitespace: false });
|
|
111
|
+
const fragment = pmDocToFragment(doc);
|
|
112
|
+
const colgroupEl = fragment.firstChild;
|
|
113
|
+
return colgroupEl;
|
|
114
|
+
};
|
|
109
115
|
const tNodes = tableNodes({ tableGroup: 'block', cellContent: 'block+', cellAttributes });
|
|
110
116
|
tNodes.table_row.attrs = Object.assign({}, tNodes.table_row.attrs, defaultAttrs([rowTypeAttr, 'style', 'class', 'id']));
|
|
111
117
|
tNodes.table_row.toDOM = node => ['tr', pmAttributes(node.attrs), 0];
|
|
112
118
|
tNodes.table_row.parseDOM = [{ tag: 'tr', getAttrs: domAttributes }];
|
|
113
|
-
tNodes.table.attrs = Object.assign({}, tNodes.table.attrs, defaultAttrs(['style', 'class', 'id', colgroupAttr]));
|
|
119
|
+
tNodes.table.attrs = Object.assign({}, tNodes.table.attrs, defaultAttrs(['style', 'class', 'id', colgroupAttr, resizableAttr]));
|
|
114
120
|
tNodes.table.toDOM = (node) => {
|
|
115
121
|
const tableAttrs = hasAttrs(node.attrs) ? pmAttributes(node.attrs, colgroupAttr) : {};
|
|
116
122
|
let colgroup = null;
|
|
117
123
|
if (node.attrs[colgroupAttr] && !shouldSkipColgroup(node)) {
|
|
118
|
-
const
|
|
119
|
-
const fragment = pmDocToFragment(doc);
|
|
120
|
-
const colgroupEl = fragment.firstChild;
|
|
124
|
+
const colgroupEl = parseStrColgroup(node.attrs[colgroupAttr]);
|
|
121
125
|
if (colgroupEl) {
|
|
122
126
|
const cols = Array.from(colgroupEl.children).map((c) => ['col', domAttributes(c)]);
|
|
123
127
|
colgroup = [
|
|
124
128
|
'colgroup',
|
|
125
|
-
domAttributes(colgroupEl)
|
|
126
|
-
|
|
127
|
-
];
|
|
129
|
+
domAttributes(colgroupEl)
|
|
130
|
+
].concat(cols);
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
133
|
return colgroup ? ['table', tableAttrs, colgroup, ['tbody', 0]] :
|
package/dist/es2015/main.js
CHANGED
|
@@ -24,6 +24,7 @@ export { spacesFix } from './plugins/spaces-fix';
|
|
|
24
24
|
export { textHighlight, textHighlightKey } from './plugins/highlight';
|
|
25
25
|
export { imageResizing, imageResizeKey } from './plugins/image-resize';
|
|
26
26
|
export { caretColor, caretColorKey } from './plugins/caret-color';
|
|
27
|
+
export { tableResizing } from './plugins/table-resize';
|
|
27
28
|
// ProseMirror re-exports
|
|
28
29
|
export * from 'prosemirror-commands';
|
|
29
30
|
export * from 'prosemirror-dropcursor';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NodeSelection, Plugin, PluginKey } from "prosemirror-state";
|
|
2
2
|
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
3
|
+
import { dataDirection, resizeHandle } from "../config/constants";
|
|
3
4
|
import { changeStylesString } from "../utils";
|
|
4
5
|
export const imageResizeKey = new PluginKey('image-resize');
|
|
5
6
|
const directions = {
|
|
@@ -107,7 +108,7 @@ const handleMouseUp = (view) => {
|
|
|
107
108
|
};
|
|
108
109
|
const handleMouseDown = (view, event, options) => {
|
|
109
110
|
const target = event.target;
|
|
110
|
-
const activeHandle = target.getAttribute(
|
|
111
|
+
const activeHandle = target.getAttribute(dataDirection);
|
|
111
112
|
if (!activeHandle) {
|
|
112
113
|
return false;
|
|
113
114
|
}
|
|
@@ -218,8 +219,8 @@ export const imageResizing = (options = { node: 'image', lockRatio: true }) => {
|
|
|
218
219
|
wrapper.style.left = rect.left + 'px';
|
|
219
220
|
for (let i = 0; i < handles.length; i++) {
|
|
220
221
|
let dom = document.createElement('div');
|
|
221
|
-
dom.className = '
|
|
222
|
-
dom.setAttribute(
|
|
222
|
+
dom.className = resizeHandle + ' ' + handles[i];
|
|
223
|
+
dom.setAttribute(dataDirection, handles[i]);
|
|
223
224
|
wrapper.appendChild(dom);
|
|
224
225
|
}
|
|
225
226
|
return DecorationSet.create(state.doc, [Decoration.widget(state.selection.from + 1, wrapper)]);
|