@progress/kendo-editor-common 1.8.2-dev.202204060750 → 1.9.0-dev.202204180753
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 +5 -0
- package/dist/es/config/schema.js +9 -5
- package/dist/es/main.js +1 -0
- package/dist/es/plugins/image-resize.js +5 -14
- package/dist/es/plugins/resize-utils.js +11 -0
- package/dist/es/plugins/table-resize/column-resize.js +273 -0
- package/dist/es/plugins/table-resize/index.js +8 -0
- package/dist/es/plugins/table-resize/row-resize.js +230 -0
- package/dist/es/plugins/table-resize/table-resize.js +255 -0
- package/dist/es/plugins/table-resize/table-view.js +87 -0
- package/dist/es/plugins/table-resize/utils.js +77 -0
- package/dist/es2015/config/constants.js +5 -0
- package/dist/es2015/config/schema.js +11 -8
- package/dist/es2015/main.js +1 -0
- package/dist/es2015/plugins/image-resize.js +5 -14
- package/dist/es2015/plugins/resize-utils.js +11 -0
- package/dist/es2015/plugins/table-resize/column-resize.js +269 -0
- package/dist/es2015/plugins/table-resize/index.js +8 -0
- package/dist/es2015/plugins/table-resize/row-resize.js +226 -0
- package/dist/es2015/plugins/table-resize/table-resize.js +251 -0
- package/dist/es2015/plugins/table-resize/table-view.js +84 -0
- package/dist/es2015/plugins/table-resize/utils.js +75 -0
- package/dist/npm/config/constants.d.ts +5 -0
- package/dist/npm/config/constants.js +5 -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 +7 -16
- package/dist/npm/plugins/resize-utils.d.ts +35 -0
- package/dist/npm/plugins/resize-utils.js +13 -0
- package/dist/npm/plugins/table-resize/column-resize.d.ts +2 -0
- package/dist/npm/plugins/table-resize/column-resize.js +276 -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 +233 -0
- package/dist/npm/plugins/table-resize/table-resize.d.ts +4 -0
- package/dist/npm/plugins/table-resize/table-resize.js +257 -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 +22 -0
- package/dist/npm/plugins/table-resize/utils.js +86 -0
- package/dist/systemjs/kendo-editor-common.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import * as tslib_1 from "tslib";
|
|
2
|
+
import { NodeSelection, Plugin } from 'prosemirror-state';
|
|
3
|
+
import { colgroupAttr, dataResizeDirTable, resizableAttr } from '../../config/constants';
|
|
4
|
+
import { getTable, parentNode, parseStyle, setNodeStyle, tableResizeKey as key } from './utils';
|
|
5
|
+
import { directions } from './../resize-utils';
|
|
6
|
+
var commonDir = {
|
|
7
|
+
'southeast': true,
|
|
8
|
+
'southwest': true,
|
|
9
|
+
'northwest': true,
|
|
10
|
+
'northeast': true
|
|
11
|
+
};
|
|
12
|
+
var horizontalDir = tslib_1.__assign({ 'east': true, 'west': true }, commonDir);
|
|
13
|
+
var verticalDir = tslib_1.__assign({ 'south': true, 'north': true }, commonDir);
|
|
14
|
+
var ResizeState = /** @class */ (function () {
|
|
15
|
+
function ResizeState(activeHandle, dragging, nodePosition) {
|
|
16
|
+
this.activeHandle = activeHandle;
|
|
17
|
+
this.dragging = dragging;
|
|
18
|
+
this.nodePosition = nodePosition;
|
|
19
|
+
}
|
|
20
|
+
ResizeState.prototype.apply = function (tr) {
|
|
21
|
+
var state = this, next = tr.getMeta(key);
|
|
22
|
+
if (next) {
|
|
23
|
+
var nextState = new ResizeState(next.activeHandle, next.setDragging, next.nodePosition);
|
|
24
|
+
return nextState;
|
|
25
|
+
}
|
|
26
|
+
return state;
|
|
27
|
+
};
|
|
28
|
+
return ResizeState;
|
|
29
|
+
}());
|
|
30
|
+
var handleMouseMove = function (view, event) {
|
|
31
|
+
var state = key.getState(view.state);
|
|
32
|
+
var dragging = state.dragging, nodePosition = state.nodePosition, activeHandle = state.activeHandle;
|
|
33
|
+
if (nodePosition < 0 || !dragging) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
var tableDom = getTable(view.nodeDOM(nodePosition));
|
|
37
|
+
var rect = tableDom.getBoundingClientRect();
|
|
38
|
+
var dir = directions[activeHandle];
|
|
39
|
+
var diffX = (event.clientX - dragging.startX) * dir.x;
|
|
40
|
+
var diffY = (event.clientY - dragging.startY) * dir.y;
|
|
41
|
+
var win = (tableDom.ownerDocument && tableDom.ownerDocument.defaultView) || window;
|
|
42
|
+
var compStyles = win.getComputedStyle(tableDom);
|
|
43
|
+
var nodeWidth = /px/.test(compStyles.width) ? parseFloat(compStyles.width) : tableDom.offsetWidth;
|
|
44
|
+
var nodeHeight = /px/.test(compStyles.height) ? parseFloat(compStyles.height) : tableDom.offsetHeight;
|
|
45
|
+
var width = dir.x ? diffX + nodeWidth : rect.width;
|
|
46
|
+
var height = dir.y ? diffY + nodeHeight : rect.height;
|
|
47
|
+
dragging.startX = dir.x ? event.clientX : dragging.startX;
|
|
48
|
+
dragging.startY = dir.y ? event.clientY : dragging.startY;
|
|
49
|
+
if (horizontalDir[activeHandle]) {
|
|
50
|
+
tableDom.style.width = width + 'px';
|
|
51
|
+
}
|
|
52
|
+
if (verticalDir[activeHandle]) {
|
|
53
|
+
tableDom.style.height = height + 'px';
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var toPercents = function (view, tr, tablePos) {
|
|
57
|
+
var tableNode = view.state.doc.nodeAt(tablePos);
|
|
58
|
+
var tableDom = getTable(view.nodeDOM(tablePos));
|
|
59
|
+
var _a = tableSize(tableDom), width = _a.width, height = _a.height, colsWidth = _a.colsWidth, rowsHeight = _a.rowsHeight, offsetWidth = _a.offsetWidth, offsetHeight = _a.offsetHeight;
|
|
60
|
+
var colgroup = tableDom.firstChild;
|
|
61
|
+
var cols = Array.from((colgroup && colgroup.children) || []);
|
|
62
|
+
var widthChanged = false;
|
|
63
|
+
cols.forEach(function (col, i) {
|
|
64
|
+
if (col.style.width && !/%$/.test(col.style.width)) {
|
|
65
|
+
col.style.width = ((colsWidth[i]) * 100 / width) + '%';
|
|
66
|
+
widthChanged = true;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
var heightChange = false;
|
|
70
|
+
tableNode.forEach(function (row, offset, index) {
|
|
71
|
+
var rowHeight = parseStyle(row.attrs.style).height;
|
|
72
|
+
if (rowHeight && !/%$/.test(rowHeight)) {
|
|
73
|
+
tr.setNodeMarkup(tablePos + offset + 1, null, setNodeStyle(row.attrs, 'height', (rowsHeight[index] * 100 / height) + '%'));
|
|
74
|
+
heightChange = true;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
var tableAttrs = tableNode.attrs;
|
|
78
|
+
if (parseStyle(tableAttrs.style).width !== offsetWidth + 'px') {
|
|
79
|
+
tableAttrs = setNodeStyle(tableAttrs, 'width', offsetWidth + 'px');
|
|
80
|
+
}
|
|
81
|
+
if (widthChanged) {
|
|
82
|
+
tableAttrs[colgroupAttr] = colgroup.outerHTML;
|
|
83
|
+
}
|
|
84
|
+
if (heightChange) {
|
|
85
|
+
tableAttrs = setNodeStyle(tableAttrs, 'height', offsetHeight + 'px');
|
|
86
|
+
}
|
|
87
|
+
if (widthChanged || heightChange) {
|
|
88
|
+
tr.setNodeMarkup(tablePos, null, tableAttrs);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
var toPixels = function (view, tr, tablePos, attrs) {
|
|
92
|
+
var tableNode = view.state.doc.nodeAt(tablePos);
|
|
93
|
+
var tableDom = getTable(view.nodeDOM(tablePos));
|
|
94
|
+
var win = (tableDom.ownerDocument && tableDom.ownerDocument.defaultView) || window;
|
|
95
|
+
var calcStyle = win.getComputedStyle;
|
|
96
|
+
var rows = Array.from(tableDom.rows);
|
|
97
|
+
tableNode.forEach(function (row, offset, index) {
|
|
98
|
+
var rowHeight = parseStyle(row.attrs.style).height;
|
|
99
|
+
if (rowHeight && !/px$/.test(rowHeight)) {
|
|
100
|
+
tr.setNodeMarkup(tablePos + offset + 1, null, setNodeStyle(row.attrs, 'height', calcStyle(rows[index]).height));
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
var colgroup = tableDom.firstChild;
|
|
104
|
+
var cols = Array.from((colgroup && colgroup.children) || []);
|
|
105
|
+
var widthChanged = false;
|
|
106
|
+
cols.forEach(function (col, i) {
|
|
107
|
+
if (col.style.width && !/px$/.test(col.style.width)) {
|
|
108
|
+
col.style.width = calcStyle(cols[i]).width;
|
|
109
|
+
widthChanged = true;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
var tableAttrs = tslib_1.__assign({}, attrs);
|
|
113
|
+
if (widthChanged) {
|
|
114
|
+
tableAttrs[colgroupAttr] = colgroup.outerHTML;
|
|
115
|
+
}
|
|
116
|
+
return tableAttrs;
|
|
117
|
+
};
|
|
118
|
+
var tableSize = function (table) {
|
|
119
|
+
var cols = Array.from(table.firstChild.children);
|
|
120
|
+
var colsWidth = cols.map(function (c) { return c.offsetWidth; });
|
|
121
|
+
var rowsHeight = Array.from(table.rows).map(function (row) { return row.offsetHeight; });
|
|
122
|
+
var width = colsWidth.reduce(function (acc, cur) { return acc + cur; }, 0);
|
|
123
|
+
var height = rowsHeight.reduce(function (acc, cur) { return acc + cur; }, 0);
|
|
124
|
+
var offsetHeight = table.offsetHeight;
|
|
125
|
+
var offsetWidth = table.offsetWidth;
|
|
126
|
+
return { width: width, height: height, colsWidth: colsWidth, rowsHeight: rowsHeight, offsetWidth: offsetWidth, offsetHeight: offsetHeight };
|
|
127
|
+
};
|
|
128
|
+
var handleMouseUp = function (view) {
|
|
129
|
+
var _a = key.getState(view.state), dragging = _a.dragging, nodePosition = _a.nodePosition, activeHandle = _a.activeHandle;
|
|
130
|
+
if (dragging) {
|
|
131
|
+
var node = view.state.doc.nodeAt(nodePosition);
|
|
132
|
+
var dom = getTable(view.nodeDOM(nodePosition));
|
|
133
|
+
var rect = tableSize(dom);
|
|
134
|
+
if (node) {
|
|
135
|
+
var width = rect.offsetWidth + 'px';
|
|
136
|
+
var height = rect.offsetHeight + 'px';
|
|
137
|
+
var tr = view.state.tr;
|
|
138
|
+
var attrs = node.attrs;
|
|
139
|
+
var parsedStyles = parseStyle(attrs.style);
|
|
140
|
+
if (horizontalDir[activeHandle] && dom.style.width && parsedStyles.width !== width) {
|
|
141
|
+
attrs = setNodeStyle(attrs, 'width', width);
|
|
142
|
+
}
|
|
143
|
+
if (verticalDir[activeHandle] && dom.style.height && parsedStyles.height !== height) {
|
|
144
|
+
attrs = setNodeStyle(attrs, 'height', height);
|
|
145
|
+
}
|
|
146
|
+
attrs = toPixels(view, tr, nodePosition, attrs);
|
|
147
|
+
tr.setNodeMarkup(nodePosition, null, attrs);
|
|
148
|
+
tr.setMeta('commandName', 'node-resize');
|
|
149
|
+
tr.setMeta('args', attrs);
|
|
150
|
+
tr.setMeta(key, {
|
|
151
|
+
setDragging: null,
|
|
152
|
+
activeHandle: null,
|
|
153
|
+
nodePosition: nodePosition
|
|
154
|
+
});
|
|
155
|
+
view.dispatch(tr);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
var handleMouseDown = function (view, event) {
|
|
160
|
+
var target = event.target;
|
|
161
|
+
var activeHandle = target.getAttribute(dataResizeDirTable);
|
|
162
|
+
if (!activeHandle) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
var resizeState = key.getState(view.state);
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
var transaction = view.state.tr;
|
|
168
|
+
transaction.setMeta(key, {
|
|
169
|
+
setDragging: { startX: event.clientX, startY: event.clientY },
|
|
170
|
+
activeHandle: activeHandle,
|
|
171
|
+
nodePosition: resizeState.nodePosition
|
|
172
|
+
});
|
|
173
|
+
transaction.setMeta('addToHistory', false);
|
|
174
|
+
toPercents(view, transaction, resizeState.nodePosition);
|
|
175
|
+
view.dispatch(transaction);
|
|
176
|
+
var curWindow = event.view || window;
|
|
177
|
+
function move(e) {
|
|
178
|
+
handleMouseMove(view, e);
|
|
179
|
+
}
|
|
180
|
+
function finish(_e) {
|
|
181
|
+
curWindow.removeEventListener('mouseup', finish);
|
|
182
|
+
curWindow.removeEventListener('mousemove', move);
|
|
183
|
+
handleMouseUp(view);
|
|
184
|
+
}
|
|
185
|
+
curWindow.addEventListener('mouseup', finish);
|
|
186
|
+
curWindow.addEventListener('mousemove', move);
|
|
187
|
+
return true;
|
|
188
|
+
};
|
|
189
|
+
export var tableResizing = function (options) {
|
|
190
|
+
if (options === void 0) { options = { node: 'table' }; }
|
|
191
|
+
return new Plugin({
|
|
192
|
+
key: key,
|
|
193
|
+
view: function (_viewObj) { return ({
|
|
194
|
+
selectedNode: function (state, nodeType) {
|
|
195
|
+
var selection = state.selection;
|
|
196
|
+
var isNodeSelected = selection instanceof NodeSelection && nodeType === selection.node.type;
|
|
197
|
+
if (isNodeSelected && selection instanceof NodeSelection) {
|
|
198
|
+
return { node: selection.node, pos: selection.from };
|
|
199
|
+
}
|
|
200
|
+
var parent = parentNode(selection.$from, function (n) { return n.type === nodeType; });
|
|
201
|
+
var node = parent && parent.node;
|
|
202
|
+
if (node) {
|
|
203
|
+
var tableDepth = new Array(selection.$from.depth + 1).fill(0)
|
|
204
|
+
.findIndex(function (_, i) { return selection.$from.node(i).type.spec.tableRole === 'table'; });
|
|
205
|
+
var pos = selection.$from.start(tableDepth) - 1;
|
|
206
|
+
return { node: node, pos: pos };
|
|
207
|
+
}
|
|
208
|
+
return null;
|
|
209
|
+
},
|
|
210
|
+
update: function (view, prevState) {
|
|
211
|
+
var _a, _b, _c, _d;
|
|
212
|
+
var state = view.state;
|
|
213
|
+
var nodeType = state.schema.nodes[options.node];
|
|
214
|
+
var selected = this.selectedNode(state, nodeType);
|
|
215
|
+
var prevSelected = this.selectedNode(prevState, nodeType);
|
|
216
|
+
if (!selected && prevSelected && !prevState.doc.eq(view.state.doc)) {
|
|
217
|
+
// selected table is deleted
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (selected || prevSelected) {
|
|
221
|
+
var tr = state.tr;
|
|
222
|
+
if (selected && prevSelected && selected.pos !== prevSelected.pos) {
|
|
223
|
+
tr.setMeta(key, { nodePosition: selected.pos });
|
|
224
|
+
tr.setNodeMarkup(prevSelected.pos, nodeType, tslib_1.__assign({}, prevSelected.node.attrs, (_a = {}, _a[resizableAttr] = false, _a)));
|
|
225
|
+
tr.setNodeMarkup(selected.pos, nodeType, tslib_1.__assign({}, selected.node.attrs, (_b = {}, _b[resizableAttr] = true, _b)));
|
|
226
|
+
view.dispatch(tr);
|
|
227
|
+
}
|
|
228
|
+
else if (selected && !prevSelected) {
|
|
229
|
+
tr.setMeta(key, { nodePosition: selected.pos });
|
|
230
|
+
view.dispatch(tr.setNodeMarkup(selected.pos, nodeType, tslib_1.__assign({}, selected.node.attrs, (_c = {}, _c[resizableAttr] = true, _c))));
|
|
231
|
+
}
|
|
232
|
+
else if (!selected && prevSelected) {
|
|
233
|
+
tr.setMeta(key, { nodePosition: -1 });
|
|
234
|
+
view.dispatch(tr.setNodeMarkup(prevSelected.pos, nodeType, tslib_1.__assign({}, prevSelected.node.attrs, (_d = {}, _d[resizableAttr] = false, _d))));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}); },
|
|
239
|
+
state: {
|
|
240
|
+
init: function () {
|
|
241
|
+
return new ResizeState('', null, -1);
|
|
242
|
+
},
|
|
243
|
+
apply: function (tr, prev) {
|
|
244
|
+
return prev.apply(tr);
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
props: {
|
|
248
|
+
handleDOMEvents: {
|
|
249
|
+
mousedown: function (view, event) {
|
|
250
|
+
return handleMouseDown(view, event);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { colgroupAttr, dataResizeDirTable, resizableAttr, resizableWrap, resizeHandle } from '../../config/constants';
|
|
2
|
+
import { parseStrColgroup } from '../../config/schema';
|
|
3
|
+
import { handles } from './../resize-utils';
|
|
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 = handles.map(function (dir) {
|
|
17
|
+
var handle = document.createElement('span');
|
|
18
|
+
handle.className = resizeHandle + ' ' + dir;
|
|
19
|
+
handle.setAttribute(dataResizeDirTable, 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 = undefined;
|
|
56
|
+
this.view = undefined;
|
|
57
|
+
this.table = undefined;
|
|
58
|
+
this.colgroup = undefined;
|
|
59
|
+
this.resizeHandles = undefined;
|
|
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,77 @@
|
|
|
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 &&
|
|
44
|
+
Boolean(tableColumnResizing.get(state)) &&
|
|
45
|
+
tableColumnResizing.getState(state).activeHandle > -1);
|
|
46
|
+
activeResize = activeResize ||
|
|
47
|
+
(current !== tableRowResizing && Boolean(tableRowResizing.get(state)) && tableRowResizing.getState(state).activeHandle > -1);
|
|
48
|
+
return activeResize;
|
|
49
|
+
}
|
|
50
|
+
export function getTable(dom) {
|
|
51
|
+
if (dom && dom.firstChild && dom.firstChild.nodeName === 'TABLE') {
|
|
52
|
+
return dom.firstChild;
|
|
53
|
+
}
|
|
54
|
+
return dom;
|
|
55
|
+
}
|
|
56
|
+
export function domCellAround(target) {
|
|
57
|
+
while (target && target.nodeName !== 'TD' && target.nodeName !== 'TH') {
|
|
58
|
+
target = target.classList.contains('ProseMirror') ? null : target.parentNode;
|
|
59
|
+
}
|
|
60
|
+
return target;
|
|
61
|
+
}
|
|
62
|
+
export function cellIndexes(cell) {
|
|
63
|
+
var row = cell.parentNode;
|
|
64
|
+
return {
|
|
65
|
+
cellIndex: cell.cellIndex,
|
|
66
|
+
rowIndex: row.rowIndex
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function parentNode(pos, predicate) {
|
|
70
|
+
for (var depth = pos.depth; depth > 0; depth--) {
|
|
71
|
+
var node = pos.node(depth);
|
|
72
|
+
if (predicate(node)) {
|
|
73
|
+
return { node: node, depth: depth };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
@@ -1,2 +1,7 @@
|
|
|
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 dataResizeDirTable = 'data-direction';
|
|
7
|
+
export const dataResizeDirImage = 'data-direction-image';
|
|
@@ -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,18 +1,9 @@
|
|
|
1
1
|
import { NodeSelection, Plugin, PluginKey } from "prosemirror-state";
|
|
2
2
|
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
3
|
+
import { dataResizeDirImage, resizeHandle } from "../config/constants";
|
|
3
4
|
import { changeStylesString } from "../utils";
|
|
5
|
+
import { directions, handles } from './resize-utils';
|
|
4
6
|
export const imageResizeKey = new PluginKey('image-resize');
|
|
5
|
-
const directions = {
|
|
6
|
-
'southeast': { x: 1, y: 1 },
|
|
7
|
-
'east': { x: 1, y: 0 },
|
|
8
|
-
'south': { x: 0, y: 1 },
|
|
9
|
-
'north': { x: 0, y: -1 },
|
|
10
|
-
'west': { x: -1, y: 0 },
|
|
11
|
-
'southwest': { x: -1, y: 1 },
|
|
12
|
-
'northwest': { x: -1, y: -1 },
|
|
13
|
-
'northeast': { x: 1, y: -1 } // top right
|
|
14
|
-
};
|
|
15
|
-
const handles = Object.keys(directions);
|
|
16
7
|
const setSize = (domNode, sizeType, value) => {
|
|
17
8
|
domNode.style[sizeType] = value + 'px';
|
|
18
9
|
};
|
|
@@ -107,7 +98,7 @@ const handleMouseUp = (view) => {
|
|
|
107
98
|
};
|
|
108
99
|
const handleMouseDown = (view, event, options) => {
|
|
109
100
|
const target = event.target;
|
|
110
|
-
const activeHandle = target.getAttribute(
|
|
101
|
+
const activeHandle = target.getAttribute(dataResizeDirImage);
|
|
111
102
|
if (!activeHandle) {
|
|
112
103
|
return false;
|
|
113
104
|
}
|
|
@@ -218,8 +209,8 @@ export const imageResizing = (options = { node: 'image', lockRatio: true }) => {
|
|
|
218
209
|
wrapper.style.left = rect.left + 'px';
|
|
219
210
|
for (let i = 0; i < handles.length; i++) {
|
|
220
211
|
let dom = document.createElement('div');
|
|
221
|
-
dom.className = '
|
|
222
|
-
dom.setAttribute(
|
|
212
|
+
dom.className = resizeHandle + ' ' + handles[i];
|
|
213
|
+
dom.setAttribute(dataResizeDirImage, handles[i]);
|
|
223
214
|
wrapper.appendChild(dom);
|
|
224
215
|
}
|
|
225
216
|
return DecorationSet.create(state.doc, [Decoration.widget(state.selection.from + 1, wrapper)]);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const directions = {
|
|
2
|
+
'southeast': { x: 1, y: 1 },
|
|
3
|
+
'east': { x: 1, y: 0 },
|
|
4
|
+
'south': { x: 0, y: 1 },
|
|
5
|
+
'north': { x: 0, y: -1 },
|
|
6
|
+
'west': { x: -1, y: 0 },
|
|
7
|
+
'southwest': { x: -1, y: 1 },
|
|
8
|
+
'northwest': { x: -1, y: -1 },
|
|
9
|
+
'northeast': { x: 1, y: -1 } // top right
|
|
10
|
+
};
|
|
11
|
+
export const handles = Object.keys(directions);
|