@progress/kendo-editor-common 1.9.0-dev.202204060830 → 1.9.0-dev.202204181342
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 +2 -1
- package/dist/es/config/schema.js +10 -6
- package/dist/es/plugins/image-resize.js +4 -14
- package/dist/es/plugins/resize-utils.js +11 -0
- package/dist/es/plugins/table-resize/column-resize.js +28 -49
- package/dist/es/plugins/table-resize/row-resize.js +40 -54
- package/dist/es/plugins/table-resize/table-resize.js +46 -67
- package/dist/es/plugins/table-resize/table-view.js +9 -9
- package/dist/es/plugins/table-resize/utils.js +26 -2
- package/dist/es2015/config/constants.js +2 -1
- package/dist/es2015/config/schema.js +6 -6
- package/dist/es2015/plugins/image-resize.js +4 -14
- package/dist/es2015/plugins/resize-utils.js +11 -0
- package/dist/es2015/plugins/table-resize/column-resize.js +28 -49
- package/dist/es2015/plugins/table-resize/row-resize.js +40 -54
- package/dist/es2015/plugins/table-resize/table-resize.js +45 -66
- package/dist/es2015/plugins/table-resize/table-view.js +9 -9
- package/dist/es2015/plugins/table-resize/utils.js +26 -2
- package/dist/npm/config/constants.d.ts +2 -1
- package/dist/npm/config/constants.js +2 -1
- package/dist/npm/config/schema.js +10 -6
- package/dist/npm/plugins/image-resize.js +6 -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.js +28 -49
- package/dist/npm/plugins/table-resize/row-resize.js +39 -53
- package/dist/npm/plugins/table-resize/table-resize.d.ts +2 -4
- package/dist/npm/plugins/table-resize/table-resize.js +45 -66
- package/dist/npm/plugins/table-resize/table-view.d.ts +7 -7
- package/dist/npm/plugins/table-resize/table-view.js +8 -8
- package/dist/npm/plugins/table-resize/utils.d.ts +10 -0
- package/dist/npm/plugins/table-resize/utils.js +29 -2
- package/dist/systemjs/kendo-editor-common.js +1 -1
- package/package.json +2 -2
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Plugin } from 'prosemirror-state';
|
|
2
2
|
import { TableMap, tableNodeTypes } from 'prosemirror-tables';
|
|
3
3
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
4
|
-
import { otherResizeHandle, otherResizing, parseStyle, setNodeStyle, tableRowResizing as key } from './utils';
|
|
4
|
+
import { domCellAround, otherResizeHandle, otherResizing, parentNode, parseStyle, setNodeStyle, tableRowResizing as key } from './utils';
|
|
5
5
|
class TableRowView {
|
|
6
6
|
ignoreMutation(record) {
|
|
7
7
|
return record.type === 'attributes' && record.attributeName === 'style' && record.target.nodeName === 'TR';
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
export function rowResizing() {
|
|
11
|
-
const handleWidth = 5
|
|
11
|
+
const handleWidth = 5;
|
|
12
12
|
let plugin = new Plugin({
|
|
13
13
|
key,
|
|
14
14
|
state: {
|
|
@@ -31,7 +31,7 @@ export function rowResizing() {
|
|
|
31
31
|
handleDOMEvents: {
|
|
32
32
|
mousemove(view, event) {
|
|
33
33
|
if (!otherResizing(key, view.state)) {
|
|
34
|
-
handleMouseMove(view, event, handleWidth
|
|
34
|
+
handleMouseMove(view, event, handleWidth);
|
|
35
35
|
}
|
|
36
36
|
return false;
|
|
37
37
|
},
|
|
@@ -40,7 +40,7 @@ export function rowResizing() {
|
|
|
40
40
|
return false;
|
|
41
41
|
},
|
|
42
42
|
mousedown(view, event) {
|
|
43
|
-
return handleMouseDown(view, event
|
|
43
|
+
return handleMouseDown(view, event);
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
decorations(state) {
|
|
@@ -73,7 +73,7 @@ class ResizeState {
|
|
|
73
73
|
if (action && action.setDragging !== undefined) {
|
|
74
74
|
return new ResizeState(state.activeHandle, action.setDragging);
|
|
75
75
|
}
|
|
76
|
-
if (state.activeHandle > -1) {
|
|
76
|
+
if (state.activeHandle > -1) {
|
|
77
77
|
let handle = tr.mapping.map(state.activeHandle, -1);
|
|
78
78
|
if (!pointsAtCell(tr.doc.resolve(handle))) {
|
|
79
79
|
handle = null;
|
|
@@ -83,30 +83,22 @@ class ResizeState {
|
|
|
83
83
|
return state;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
function handleMouseMove(view, event, handleWidth
|
|
86
|
+
function handleMouseMove(view, event, handleWidth) {
|
|
87
87
|
let pluginState = key.getState(view.state);
|
|
88
88
|
if (!pluginState.dragging) {
|
|
89
|
-
let target = domCellAround(event.target),
|
|
89
|
+
let target = domCellAround(event.target), row = -1;
|
|
90
90
|
if (target) {
|
|
91
91
|
const rowDom = target.parentNode;
|
|
92
92
|
let domRect = rowDom.getBoundingClientRect();
|
|
93
|
-
if (event.clientY - domRect.top <= handleWidth) {
|
|
94
|
-
|
|
93
|
+
if (Math.abs(event.clientY - domRect.top) <= handleWidth && rowDom.rowIndex > 0) {
|
|
94
|
+
row = edgeRow(view, event, rowDom.rowIndex - 1);
|
|
95
95
|
}
|
|
96
|
-
else if (domRect.bottom - event.clientY <= handleWidth) {
|
|
97
|
-
|
|
96
|
+
else if (domRect.bottom - event.clientY > 0 && domRect.bottom - event.clientY <= handleWidth) {
|
|
97
|
+
row = edgeRow(view, event, rowDom.rowIndex);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
// let $cell = view.state.doc.resolve(cell);
|
|
103
|
-
// let table = $cell.node(-1), map = TableMap.get(table), start = $cell.start(-1);
|
|
104
|
-
// let col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;
|
|
105
|
-
// if (col === map.width - 1) {
|
|
106
|
-
// return;
|
|
107
|
-
// }
|
|
108
|
-
}
|
|
109
|
-
updateHandle(view, cell);
|
|
100
|
+
if (row !== pluginState.activeHandle) {
|
|
101
|
+
updateHandle(view, row);
|
|
110
102
|
}
|
|
111
103
|
}
|
|
112
104
|
}
|
|
@@ -116,7 +108,7 @@ function handleMouseLeave(view) {
|
|
|
116
108
|
updateHandle(view, -1);
|
|
117
109
|
}
|
|
118
110
|
}
|
|
119
|
-
function handleMouseDown(view, event
|
|
111
|
+
function handleMouseDown(view, event) {
|
|
120
112
|
let pluginState = key.getState(view.state);
|
|
121
113
|
if (pluginState.activeHandle === -1 || pluginState.dragging) {
|
|
122
114
|
return false;
|
|
@@ -144,7 +136,7 @@ function handleMouseDown(view, event, rowMinHeight) {
|
|
|
144
136
|
let curPluginState = key.getState(view.state);
|
|
145
137
|
if (curPluginState.dragging) {
|
|
146
138
|
const tr = view.state.tr.setMeta(key, { setDragging: null });
|
|
147
|
-
updateRowHeight(view, tr, curPluginState.activeHandle
|
|
139
|
+
updateRowHeight(view, tr, curPluginState.activeHandle);
|
|
148
140
|
view.dispatch(tr);
|
|
149
141
|
}
|
|
150
142
|
}
|
|
@@ -153,54 +145,45 @@ function handleMouseDown(view, event, rowMinHeight) {
|
|
|
153
145
|
return finish(ev);
|
|
154
146
|
}
|
|
155
147
|
let curPluginState = key.getState(view.state);
|
|
156
|
-
let dragged = draggedHeight(curPluginState.dragging, ev
|
|
148
|
+
let dragged = draggedHeight(curPluginState.dragging, ev);
|
|
157
149
|
let offset = ev.clientY - curPluginState.dragging.startY;
|
|
158
|
-
displayRowHeight(view, curPluginState.activeHandle, dragged,
|
|
150
|
+
displayRowHeight(view, curPluginState.activeHandle, dragged, offset, tableHeight);
|
|
159
151
|
}
|
|
160
152
|
event.view.addEventListener('mouseup', finish);
|
|
161
153
|
event.view.addEventListener('mousemove', move);
|
|
162
154
|
event.preventDefault();
|
|
163
155
|
return true;
|
|
164
156
|
}
|
|
165
|
-
function
|
|
166
|
-
while (target && target.nodeName !== 'TD' && target.nodeName !== 'TH') {
|
|
167
|
-
target = target.classList.contains('ProseMirror') ? null : target.parentNode;
|
|
168
|
-
}
|
|
169
|
-
return target;
|
|
170
|
-
}
|
|
171
|
-
function edgeCell(view, event, side) {
|
|
157
|
+
function edgeRow(view, event, rowIndex) {
|
|
172
158
|
let found = view.posAtCoords({ left: event.clientX, top: event.clientY });
|
|
173
159
|
if (!found) {
|
|
174
160
|
return -1;
|
|
175
161
|
}
|
|
176
|
-
let
|
|
177
|
-
let
|
|
178
|
-
|
|
179
|
-
let rowDepth = new Array($pos.depth + 1).fill(0).findIndex((_, i) => $pos.node(i).type.spec.tableRole === 'row');
|
|
180
|
-
if (rowDepth === -1) {
|
|
181
|
-
return -1;
|
|
182
|
-
}
|
|
183
|
-
let tableDepth = rowDepth - 1;
|
|
184
|
-
let rowIndex = $pos.index(tableDepth);
|
|
185
|
-
rowIndex += side === 'up' ? -1 : 0;
|
|
186
|
-
if (rowIndex < 0) {
|
|
162
|
+
let $pos = view.state.doc.resolve(found.pos);
|
|
163
|
+
let parentTable = parentNode($pos, n => n.type.spec.tableRole === 'table');
|
|
164
|
+
if (parentTable === null) {
|
|
187
165
|
return -1;
|
|
188
166
|
}
|
|
189
|
-
let
|
|
190
|
-
|
|
167
|
+
let tablePos = $pos.start(parentTable.depth);
|
|
168
|
+
const tableNode = parentTable.node;
|
|
169
|
+
const map = TableMap.get(tableNode);
|
|
170
|
+
const row = tablePos + map.map[(map.width * rowIndex)] - 1;
|
|
171
|
+
return row;
|
|
191
172
|
}
|
|
192
|
-
function draggedHeight(dragging, event
|
|
173
|
+
function draggedHeight(dragging, event) {
|
|
193
174
|
let offset = event.clientY - dragging.startY;
|
|
194
|
-
return
|
|
175
|
+
return dragging.startHeight.rowHeight + offset;
|
|
195
176
|
}
|
|
196
177
|
function updateHandle(view, value) {
|
|
197
178
|
view.dispatch(view.state.tr.setMeta(key, { setHandle: value }));
|
|
198
179
|
}
|
|
199
|
-
function updateRowHeight(view, tr, rowPos
|
|
180
|
+
function updateRowHeight(view, tr, rowPos) {
|
|
200
181
|
const doc = view.state.doc;
|
|
201
182
|
let row = doc.nodeAt(rowPos);
|
|
202
|
-
tr.setNodeMarkup(rowPos, null, setNodeStyle(row.attrs, 'height', height + 'px'));
|
|
203
183
|
const dom = view.nodeDOM(rowPos);
|
|
184
|
+
const win = (dom.ownerDocument && dom.ownerDocument.defaultView) || window;
|
|
185
|
+
dom.style.height = win.getComputedStyle(dom).height;
|
|
186
|
+
tr.setNodeMarkup(rowPos, null, setNodeStyle(row.attrs, 'height', dom.style.height));
|
|
204
187
|
const table = dom && dom.closest('table');
|
|
205
188
|
const tableHeight = table && table.style.height;
|
|
206
189
|
if (tableHeight) {
|
|
@@ -209,29 +192,32 @@ function updateRowHeight(view, tr, rowPos, height) {
|
|
|
209
192
|
tr.setNodeMarkup(tablePos, null, setNodeStyle($pos.parent.attrs, 'height', tableHeight));
|
|
210
193
|
}
|
|
211
194
|
}
|
|
212
|
-
|
|
213
|
-
function displayRowHeight(view, rowPos, height, rowMinHeight, offset, tableHeight) {
|
|
195
|
+
function displayRowHeight(view, rowPos, height, offset, tableHeight) {
|
|
214
196
|
const dom = view.nodeDOM(rowPos);
|
|
215
197
|
if (dom) {
|
|
216
|
-
dom.style.height =
|
|
198
|
+
dom.style.height = height + 'px';
|
|
199
|
+
const win = (dom.ownerDocument && dom.ownerDocument.defaultView) || window;
|
|
200
|
+
dom.style.height = win.getComputedStyle(dom).height;
|
|
217
201
|
const table = dom.closest('table');
|
|
218
202
|
const newHeight = (parseFloat(tableHeight) + offset) + 'px';
|
|
219
203
|
const current = table && table.style.height;
|
|
220
204
|
if (current && current !== newHeight) {
|
|
221
205
|
table.style.height = (parseFloat(tableHeight) + offset) + 'px';
|
|
206
|
+
table.style.height = win.getComputedStyle(table).height;
|
|
222
207
|
}
|
|
223
208
|
}
|
|
224
209
|
}
|
|
225
210
|
function handleDecorations(state, pos) {
|
|
226
211
|
let decorations = [];
|
|
227
212
|
if (typeof pos !== 'number') {
|
|
228
|
-
return;
|
|
213
|
+
return DecorationSet.empty;
|
|
229
214
|
}
|
|
230
215
|
let $row = state.doc.resolve(pos), table = $row.parent, map = TableMap.get(table), rowIndex = $row.index($row.depth), start = $row.start($row.depth);
|
|
231
216
|
for (let col = 0; col < map.width; col++) {
|
|
232
217
|
let index = col + rowIndex * map.width;
|
|
233
218
|
let cellPos = map.map[index];
|
|
234
|
-
|
|
219
|
+
const cell = table.nodeAt(cellPos);
|
|
220
|
+
let widgetPos = start + cellPos + (cell ? cell.nodeSize : 0) - 1;
|
|
235
221
|
let dom = document.createElement('div');
|
|
236
222
|
dom.className = 'row-resize-handle';
|
|
237
223
|
decorations.push(Decoration.widget(widgetPos, dom));
|
|
@@ -1,25 +1,7 @@
|
|
|
1
1
|
import { NodeSelection, Plugin } from 'prosemirror-state';
|
|
2
|
-
import { colgroupAttr,
|
|
3
|
-
import { getTable, parseStyle, setNodeStyle, tableResizeKey as key } from './utils';
|
|
4
|
-
|
|
5
|
-
for (let d = pos.depth; d > 0; d--) {
|
|
6
|
-
let node = pos.node(d);
|
|
7
|
-
if (predicate(node)) {
|
|
8
|
-
return node;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
const directions = {
|
|
14
|
-
'southeast': { x: 1, y: 1 },
|
|
15
|
-
'east': { x: 1, y: 0 },
|
|
16
|
-
'south': { x: 0, y: 1 },
|
|
17
|
-
'north': { x: 0, y: -1 },
|
|
18
|
-
'west': { x: -1, y: 0 },
|
|
19
|
-
'southwest': { x: -1, y: 1 },
|
|
20
|
-
'northwest': { x: -1, y: -1 },
|
|
21
|
-
'northeast': { x: 1, y: -1 } // top right
|
|
22
|
-
};
|
|
2
|
+
import { colgroupAttr, dataResizeDirTable, resizableAttr } from '../../config/constants';
|
|
3
|
+
import { getTable, parentNode, parseStyle, setNodeStyle, tableResizeKey as key } from './utils';
|
|
4
|
+
import { directions } from './../resize-utils';
|
|
23
5
|
const commonDir = {
|
|
24
6
|
'southeast': true,
|
|
25
7
|
'southwest': true,
|
|
@@ -28,9 +10,6 @@ const commonDir = {
|
|
|
28
10
|
};
|
|
29
11
|
const horizontalDir = Object.assign({ 'east': true, 'west': true }, commonDir);
|
|
30
12
|
const verticalDir = Object.assign({ 'south': true, 'north': true }, commonDir);
|
|
31
|
-
const setSize = (domNode, sizeType, value) => {
|
|
32
|
-
domNode.style[sizeType] = value + 'px';
|
|
33
|
-
};
|
|
34
13
|
class ResizeState {
|
|
35
14
|
constructor(activeHandle, dragging, nodePosition) {
|
|
36
15
|
this.activeHandle = activeHandle;
|
|
@@ -46,73 +25,62 @@ class ResizeState {
|
|
|
46
25
|
return state;
|
|
47
26
|
}
|
|
48
27
|
}
|
|
49
|
-
const handleMouseMove = (view, event
|
|
28
|
+
const handleMouseMove = (view, event) => {
|
|
50
29
|
const state = key.getState(view.state);
|
|
51
30
|
const { dragging, nodePosition, activeHandle } = state;
|
|
52
31
|
if (nodePosition < 0 || !dragging) {
|
|
53
32
|
return;
|
|
54
33
|
}
|
|
55
|
-
let
|
|
56
|
-
const rect =
|
|
34
|
+
let tableDom = getTable(view.nodeDOM(nodePosition));
|
|
35
|
+
const rect = tableDom.getBoundingClientRect();
|
|
57
36
|
const dir = directions[activeHandle];
|
|
58
37
|
const diffX = (event.clientX - dragging.startX) * dir.x;
|
|
59
38
|
const diffY = (event.clientY - dragging.startY) * dir.y;
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
dragging.startX = event.clientX - (width - lockWidth) * dir.x;
|
|
69
|
-
dragging.startY = event.clientY - (height - lockHeight) * dir.y;
|
|
70
|
-
width = lockWidth;
|
|
71
|
-
height = lockHeight;
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
dragging.startX = dir.x ? event.clientX : dragging.startX;
|
|
75
|
-
dragging.startY = dir.y ? event.clientY : dragging.startY;
|
|
76
|
-
}
|
|
39
|
+
const win = (tableDom.ownerDocument && tableDom.ownerDocument.defaultView) || window;
|
|
40
|
+
const compStyles = win.getComputedStyle(tableDom);
|
|
41
|
+
const nodeWidth = /px/.test(compStyles.width) ? parseFloat(compStyles.width) : tableDom.offsetWidth;
|
|
42
|
+
const nodeHeight = /px/.test(compStyles.height) ? parseFloat(compStyles.height) : tableDom.offsetHeight;
|
|
43
|
+
const width = dir.x ? diffX + nodeWidth : rect.width;
|
|
44
|
+
const height = dir.y ? diffY + nodeHeight : rect.height;
|
|
45
|
+
dragging.startX = dir.x ? event.clientX : dragging.startX;
|
|
46
|
+
dragging.startY = dir.y ? event.clientY : dragging.startY;
|
|
77
47
|
if (horizontalDir[activeHandle]) {
|
|
78
|
-
|
|
48
|
+
tableDom.style.width = width + 'px';
|
|
79
49
|
}
|
|
80
50
|
if (verticalDir[activeHandle]) {
|
|
81
|
-
|
|
51
|
+
tableDom.style.height = height + 'px';
|
|
82
52
|
}
|
|
83
53
|
};
|
|
84
54
|
const toPercents = (view, tr, tablePos) => {
|
|
85
55
|
const tableNode = view.state.doc.nodeAt(tablePos);
|
|
86
56
|
const tableDom = getTable(view.nodeDOM(tablePos));
|
|
87
|
-
const { width
|
|
57
|
+
const { width, height, colsWidth, rowsHeight, offsetWidth, offsetHeight } = tableSize(tableDom);
|
|
88
58
|
const colgroup = tableDom.firstChild;
|
|
89
59
|
const cols = Array.from((colgroup && colgroup.children) || []);
|
|
90
|
-
// const borders = new Array(cols.length).fill(tableWidth / tableOffsetWidth / cols.length);
|
|
91
60
|
let widthChanged = false;
|
|
92
61
|
cols.forEach((col, i) => {
|
|
93
62
|
if (col.style.width && !/%$/.test(col.style.width)) {
|
|
94
|
-
col.style.width = ((colsWidth[i]) * 100 /
|
|
63
|
+
col.style.width = ((colsWidth[i]) * 100 / width) + '%';
|
|
95
64
|
widthChanged = true;
|
|
96
65
|
}
|
|
97
66
|
});
|
|
98
|
-
const rows = Array.from(tableDom.rows);
|
|
99
67
|
let heightChange = false;
|
|
100
68
|
tableNode.forEach((row, offset, index) => {
|
|
101
69
|
const rowHeight = parseStyle(row.attrs.style).height;
|
|
102
70
|
if (rowHeight && !/%$/.test(rowHeight)) {
|
|
103
|
-
tr.setNodeMarkup(tablePos + offset + 1, null, setNodeStyle(row.attrs, 'height', (
|
|
71
|
+
tr.setNodeMarkup(tablePos + offset + 1, null, setNodeStyle(row.attrs, 'height', (rowsHeight[index] * 100 / height) + '%'));
|
|
104
72
|
heightChange = true;
|
|
105
73
|
}
|
|
106
74
|
});
|
|
107
75
|
let tableAttrs = tableNode.attrs;
|
|
108
|
-
if (parseStyle(tableAttrs.style).width !==
|
|
109
|
-
tableAttrs = setNodeStyle(tableAttrs, 'width',
|
|
76
|
+
if (parseStyle(tableAttrs.style).width !== offsetWidth + 'px') {
|
|
77
|
+
tableAttrs = setNodeStyle(tableAttrs, 'width', offsetWidth + 'px');
|
|
110
78
|
}
|
|
111
79
|
if (widthChanged) {
|
|
112
80
|
tableAttrs[colgroupAttr] = colgroup.outerHTML;
|
|
113
81
|
}
|
|
114
82
|
if (heightChange) {
|
|
115
|
-
tableAttrs = setNodeStyle(tableAttrs, 'height',
|
|
83
|
+
tableAttrs = setNodeStyle(tableAttrs, 'height', offsetHeight + 'px');
|
|
116
84
|
}
|
|
117
85
|
if (widthChanged || heightChange) {
|
|
118
86
|
tr.setNodeMarkup(tablePos, null, tableAttrs);
|
|
@@ -121,11 +89,13 @@ const toPercents = (view, tr, tablePos) => {
|
|
|
121
89
|
const toPixels = (view, tr, tablePos, attrs) => {
|
|
122
90
|
const tableNode = view.state.doc.nodeAt(tablePos);
|
|
123
91
|
const tableDom = getTable(view.nodeDOM(tablePos));
|
|
92
|
+
const win = (tableDom.ownerDocument && tableDom.ownerDocument.defaultView) || window;
|
|
93
|
+
const calcStyle = win.getComputedStyle;
|
|
124
94
|
const rows = Array.from(tableDom.rows);
|
|
125
95
|
tableNode.forEach((row, offset, index) => {
|
|
126
96
|
const rowHeight = parseStyle(row.attrs.style).height;
|
|
127
97
|
if (rowHeight && !/px$/.test(rowHeight)) {
|
|
128
|
-
tr.setNodeMarkup(tablePos + offset + 1, null, setNodeStyle(row.attrs, 'height', rows[index].
|
|
98
|
+
tr.setNodeMarkup(tablePos + offset + 1, null, setNodeStyle(row.attrs, 'height', calcStyle(rows[index]).height));
|
|
129
99
|
}
|
|
130
100
|
});
|
|
131
101
|
const colgroup = tableDom.firstChild;
|
|
@@ -133,7 +103,7 @@ const toPixels = (view, tr, tablePos, attrs) => {
|
|
|
133
103
|
let widthChanged = false;
|
|
134
104
|
cols.forEach((col, i) => {
|
|
135
105
|
if (col.style.width && !/px$/.test(col.style.width)) {
|
|
136
|
-
col.style.width = cols[i].
|
|
106
|
+
col.style.width = calcStyle(cols[i]).width;
|
|
137
107
|
widthChanged = true;
|
|
138
108
|
}
|
|
139
109
|
});
|
|
@@ -146,9 +116,12 @@ const toPixels = (view, tr, tablePos, attrs) => {
|
|
|
146
116
|
const tableSize = (table) => {
|
|
147
117
|
const cols = Array.from(table.firstChild.children);
|
|
148
118
|
const colsWidth = cols.map(c => c.offsetWidth);
|
|
119
|
+
const rowsHeight = Array.from(table.rows).map(row => row.offsetHeight);
|
|
149
120
|
const width = colsWidth.reduce((acc, cur) => acc + cur, 0);
|
|
150
|
-
const height =
|
|
151
|
-
|
|
121
|
+
const height = rowsHeight.reduce((acc, cur) => acc + cur, 0);
|
|
122
|
+
const offsetHeight = table.offsetHeight;
|
|
123
|
+
const offsetWidth = table.offsetWidth;
|
|
124
|
+
return { width, height, colsWidth, rowsHeight, offsetWidth, offsetHeight };
|
|
152
125
|
};
|
|
153
126
|
const handleMouseUp = (view) => {
|
|
154
127
|
const { dragging, nodePosition, activeHandle } = key.getState(view.state);
|
|
@@ -158,7 +131,7 @@ const handleMouseUp = (view) => {
|
|
|
158
131
|
const rect = tableSize(dom);
|
|
159
132
|
if (node) {
|
|
160
133
|
const width = rect.offsetWidth + 'px';
|
|
161
|
-
const height = rect.
|
|
134
|
+
const height = rect.offsetHeight + 'px';
|
|
162
135
|
const tr = view.state.tr;
|
|
163
136
|
let attrs = node.attrs;
|
|
164
137
|
const parsedStyles = parseStyle(attrs.style);
|
|
@@ -168,7 +141,7 @@ const handleMouseUp = (view) => {
|
|
|
168
141
|
if (verticalDir[activeHandle] && dom.style.height && parsedStyles.height !== height) {
|
|
169
142
|
attrs = setNodeStyle(attrs, 'height', height);
|
|
170
143
|
}
|
|
171
|
-
toPixels(view, tr, nodePosition, attrs);
|
|
144
|
+
attrs = toPixels(view, tr, nodePosition, attrs);
|
|
172
145
|
tr.setNodeMarkup(nodePosition, null, attrs);
|
|
173
146
|
tr.setMeta('commandName', 'node-resize');
|
|
174
147
|
tr.setMeta('args', attrs);
|
|
@@ -181,9 +154,9 @@ const handleMouseUp = (view) => {
|
|
|
181
154
|
}
|
|
182
155
|
}
|
|
183
156
|
};
|
|
184
|
-
const handleMouseDown = (view, event
|
|
157
|
+
const handleMouseDown = (view, event) => {
|
|
185
158
|
const target = event.target;
|
|
186
|
-
const activeHandle = target.getAttribute(
|
|
159
|
+
const activeHandle = target.getAttribute(dataResizeDirTable);
|
|
187
160
|
if (!activeHandle) {
|
|
188
161
|
return false;
|
|
189
162
|
}
|
|
@@ -200,7 +173,7 @@ const handleMouseDown = (view, event, options) => {
|
|
|
200
173
|
view.dispatch(transaction);
|
|
201
174
|
const curWindow = event.view || window;
|
|
202
175
|
function move(e) {
|
|
203
|
-
handleMouseMove(view, e
|
|
176
|
+
handleMouseMove(view, e);
|
|
204
177
|
}
|
|
205
178
|
function finish(_e) {
|
|
206
179
|
curWindow.removeEventListener('mouseup', finish);
|
|
@@ -211,7 +184,7 @@ const handleMouseDown = (view, event, options) => {
|
|
|
211
184
|
curWindow.addEventListener('mousemove', move);
|
|
212
185
|
return true;
|
|
213
186
|
};
|
|
214
|
-
export const tableResizing = (options = { node: 'table'
|
|
187
|
+
export const tableResizing = (options = { node: 'table' }) => {
|
|
215
188
|
return new Plugin({
|
|
216
189
|
key: key,
|
|
217
190
|
view: (_viewObj) => ({
|
|
@@ -221,7 +194,8 @@ export const tableResizing = (options = { node: 'table', lockRatio: false }) =>
|
|
|
221
194
|
if (isNodeSelected && selection instanceof NodeSelection) {
|
|
222
195
|
return { node: selection.node, pos: selection.from };
|
|
223
196
|
}
|
|
224
|
-
const
|
|
197
|
+
const parent = parentNode(selection.$from, (n) => n.type === nodeType);
|
|
198
|
+
const node = parent && parent.node;
|
|
225
199
|
if (node) {
|
|
226
200
|
let tableDepth = new Array(selection.$from.depth + 1).fill(0)
|
|
227
201
|
.findIndex((_, i) => selection.$from.node(i).type.spec.tableRole === 'table');
|
|
@@ -247,6 +221,11 @@ export const tableResizing = (options = { node: 'table', lockRatio: false }) =>
|
|
|
247
221
|
tr.setNodeMarkup(selected.pos, nodeType, Object.assign({}, selected.node.attrs, { [resizableAttr]: true }));
|
|
248
222
|
view.dispatch(tr);
|
|
249
223
|
}
|
|
224
|
+
else if (selected && prevSelected && selected.pos === prevSelected.pos &&
|
|
225
|
+
!selected.node.attrs[resizableAttr] && !state.selection.eq(prevState.selection)) {
|
|
226
|
+
tr.setMeta(key, { nodePosition: selected.pos });
|
|
227
|
+
view.dispatch(tr.setNodeMarkup(selected.pos, nodeType, Object.assign({}, selected.node.attrs, { [resizableAttr]: true })));
|
|
228
|
+
}
|
|
250
229
|
else if (selected && !prevSelected) {
|
|
251
230
|
tr.setMeta(key, { nodePosition: selected.pos });
|
|
252
231
|
view.dispatch(tr.setNodeMarkup(selected.pos, nodeType, Object.assign({}, selected.node.attrs, { [resizableAttr]: true })));
|
|
@@ -269,7 +248,7 @@ export const tableResizing = (options = { node: 'table', lockRatio: false }) =>
|
|
|
269
248
|
props: {
|
|
270
249
|
handleDOMEvents: {
|
|
271
250
|
mousedown(view, event) {
|
|
272
|
-
return handleMouseDown(view, event
|
|
251
|
+
return handleMouseDown(view, event);
|
|
273
252
|
}
|
|
274
253
|
}
|
|
275
254
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { colgroupAttr,
|
|
1
|
+
import { colgroupAttr, dataResizeDirTable, resizableAttr, resizableWrap, resizeHandle } from '../../config/constants';
|
|
2
2
|
import { parseStrColgroup } from '../../config/schema';
|
|
3
|
-
|
|
3
|
+
import { handles } from './../resize-utils';
|
|
4
4
|
export class TableView {
|
|
5
5
|
constructor(node, view) {
|
|
6
6
|
this.node = node;
|
|
@@ -13,10 +13,10 @@ export class TableView {
|
|
|
13
13
|
}
|
|
14
14
|
const tBody = this.table.appendChild(document.createElement('tbody'));
|
|
15
15
|
this.setAttributes(this.table, node.attrs);
|
|
16
|
-
this.resizeHandles =
|
|
16
|
+
this.resizeHandles = handles.map(dir => {
|
|
17
17
|
const handle = document.createElement('span');
|
|
18
18
|
handle.className = resizeHandle + ' ' + dir;
|
|
19
|
-
handle.setAttribute(
|
|
19
|
+
handle.setAttribute(dataResizeDirTable, dir);
|
|
20
20
|
return handle;
|
|
21
21
|
});
|
|
22
22
|
this.contentDOM = tBody;
|
|
@@ -51,11 +51,11 @@ export class TableView {
|
|
|
51
51
|
return result;
|
|
52
52
|
}
|
|
53
53
|
destroy() {
|
|
54
|
-
this.node =
|
|
55
|
-
this.view =
|
|
56
|
-
this.table =
|
|
57
|
-
this.colgroup =
|
|
58
|
-
this.resizeHandles =
|
|
54
|
+
this.node = undefined;
|
|
55
|
+
this.view = undefined;
|
|
56
|
+
this.table = undefined;
|
|
57
|
+
this.colgroup = undefined;
|
|
58
|
+
this.resizeHandles = undefined;
|
|
59
59
|
}
|
|
60
60
|
renderColgroup(colgroupStr) {
|
|
61
61
|
if (this.table && this.table.firstChild && this.table.firstChild.nodeName === 'COLGROUP') {
|
|
@@ -38,9 +38,11 @@ export function otherResizing(current, state) {
|
|
|
38
38
|
export function otherResizeHandle(current, state) {
|
|
39
39
|
let activeResize = false;
|
|
40
40
|
activeResize = activeResize ||
|
|
41
|
-
(current !== tableColumnResizing &&
|
|
41
|
+
(current !== tableColumnResizing &&
|
|
42
|
+
Boolean(tableColumnResizing.get(state)) &&
|
|
43
|
+
tableColumnResizing.getState(state).activeHandle > -1);
|
|
42
44
|
activeResize = activeResize ||
|
|
43
|
-
(current !== tableRowResizing && tableRowResizing.get(state) && tableRowResizing.getState(state).activeHandle > -1);
|
|
45
|
+
(current !== tableRowResizing && Boolean(tableRowResizing.get(state)) && tableRowResizing.getState(state).activeHandle > -1);
|
|
44
46
|
return activeResize;
|
|
45
47
|
}
|
|
46
48
|
export function getTable(dom) {
|
|
@@ -49,3 +51,25 @@ export function getTable(dom) {
|
|
|
49
51
|
}
|
|
50
52
|
return dom;
|
|
51
53
|
}
|
|
54
|
+
export function domCellAround(target) {
|
|
55
|
+
while (target && target.nodeName !== 'TD' && target.nodeName !== 'TH') {
|
|
56
|
+
target = target.classList.contains('ProseMirror') ? null : target.parentNode;
|
|
57
|
+
}
|
|
58
|
+
return target;
|
|
59
|
+
}
|
|
60
|
+
export function cellIndexes(cell) {
|
|
61
|
+
const row = cell.parentNode;
|
|
62
|
+
return {
|
|
63
|
+
cellIndex: cell.cellIndex,
|
|
64
|
+
rowIndex: row.rowIndex
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function parentNode(pos, predicate) {
|
|
68
|
+
for (let depth = pos.depth; depth > 0; depth--) {
|
|
69
|
+
let node = pos.node(depth);
|
|
70
|
+
if (predicate(node)) {
|
|
71
|
+
return { node, depth };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
@@ -3,4 +3,5 @@ export declare const colgroupAttr = "k-colgroup-data";
|
|
|
3
3
|
export declare const resizableAttr = "resizable-node";
|
|
4
4
|
export declare const resizableWrap = "k-editor-resize-wrap-element";
|
|
5
5
|
export declare const resizeHandle = "k-editor-resize-handle";
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const dataResizeDirTable = "data-direction";
|
|
7
|
+
export declare const dataResizeDirImage = "data-direction-image";
|
|
@@ -5,4 +5,5 @@ exports.colgroupAttr = 'k-colgroup-data';
|
|
|
5
5
|
exports.resizableAttr = 'resizable-node';
|
|
6
6
|
exports.resizableWrap = 'k-editor-resize-wrap-element';
|
|
7
7
|
exports.resizeHandle = 'k-editor-resize-handle';
|
|
8
|
-
exports.
|
|
8
|
+
exports.dataResizeDirTable = 'data-direction';
|
|
9
|
+
exports.dataResizeDirImage = 'data-direction-image';
|
|
@@ -34,11 +34,15 @@ var hasAttrs = function (attrs, exclude) {
|
|
|
34
34
|
return false;
|
|
35
35
|
};
|
|
36
36
|
var pmAttributes = function (attrs, exclude) {
|
|
37
|
+
if (exclude === void 0) { exclude = []; }
|
|
37
38
|
var result = {};
|
|
38
|
-
|
|
39
|
-
if (attr && attrs[attr] !== null && attr
|
|
39
|
+
var _loop_1 = function (attr) {
|
|
40
|
+
if (attr && attrs[attr] !== null && !exclude.find(function (e) { return e === attr; })) {
|
|
40
41
|
result[attr] = attrs[attr];
|
|
41
42
|
}
|
|
43
|
+
};
|
|
44
|
+
for (var attr in attrs) {
|
|
45
|
+
_loop_1(attr);
|
|
42
46
|
}
|
|
43
47
|
return result;
|
|
44
48
|
};
|
|
@@ -124,7 +128,7 @@ tNodes.table_row.toDOM = function (node) { return ['tr', pmAttributes(node.attrs
|
|
|
124
128
|
tNodes.table_row.parseDOM = [{ tag: 'tr', getAttrs: domAttributes }];
|
|
125
129
|
tNodes.table.attrs = tslib_1.__assign({}, tNodes.table.attrs, defaultAttrs(['style', 'class', 'id', constants_1.colgroupAttr, constants_1.resizableAttr]));
|
|
126
130
|
tNodes.table.toDOM = function (node) {
|
|
127
|
-
var tableAttrs = hasAttrs(node.attrs) ? pmAttributes(node.attrs, constants_1.colgroupAttr) : {};
|
|
131
|
+
var tableAttrs = hasAttrs(node.attrs) ? pmAttributes(node.attrs, [constants_1.colgroupAttr, constants_1.resizableAttr]) : {};
|
|
128
132
|
var colgroup = null;
|
|
129
133
|
if (node.attrs[constants_1.colgroupAttr] && !shouldSkipColgroup(node)) {
|
|
130
134
|
var colgroupEl = exports.parseStrColgroup(node.attrs[constants_1.colgroupAttr]);
|
|
@@ -213,7 +217,7 @@ var nodes = tslib_1.__assign({
|
|
|
213
217
|
{ tag: 'h6', getAttrs: function (node) { return (tslib_1.__assign({}, domAttributes(node), { level: 6 })); } }
|
|
214
218
|
],
|
|
215
219
|
toDOM: function (node) { return hasAttrs(node.attrs, 'level') ?
|
|
216
|
-
['h' + node.attrs.level, pmAttributes(node.attrs, 'level'), hole] :
|
|
220
|
+
['h' + node.attrs.level, pmAttributes(node.attrs, ['level']), hole] :
|
|
217
221
|
['h' + node.attrs.level, hole]; }
|
|
218
222
|
},
|
|
219
223
|
// :: NodeSpec A code listing. Disallows marks or non-text inline
|
|
@@ -270,8 +274,8 @@ var nodes = tslib_1.__assign({
|
|
|
270
274
|
} }],
|
|
271
275
|
toDOM: function (node) {
|
|
272
276
|
return node.attrs.order === 1 ?
|
|
273
|
-
(hasAttrs(node.attrs, 'order') ? ['ol', pmAttributes(node.attrs, 'order'), hole] : olDOM) :
|
|
274
|
-
['ol', tslib_1.__assign({}, pmAttributes(node.attrs, 'order'), { start: node.attrs.order }), hole];
|
|
277
|
+
(hasAttrs(node.attrs, 'order') ? ['ol', pmAttributes(node.attrs, ['order']), hole] : olDOM) :
|
|
278
|
+
['ol', tslib_1.__assign({}, pmAttributes(node.attrs, ['order']), { start: node.attrs.order }), hole];
|
|
275
279
|
}
|
|
276
280
|
},
|
|
277
281
|
// :: NodeSpec
|
|
@@ -5,18 +5,8 @@ var prosemirror_state_1 = require("prosemirror-state");
|
|
|
5
5
|
var prosemirror_view_1 = require("prosemirror-view");
|
|
6
6
|
var constants_1 = require("../config/constants");
|
|
7
7
|
var utils_1 = require("../utils");
|
|
8
|
+
var resize_utils_1 = require("./resize-utils");
|
|
8
9
|
exports.imageResizeKey = new prosemirror_state_1.PluginKey('image-resize');
|
|
9
|
-
var directions = {
|
|
10
|
-
'southeast': { x: 1, y: 1 },
|
|
11
|
-
'east': { x: 1, y: 0 },
|
|
12
|
-
'south': { x: 0, y: 1 },
|
|
13
|
-
'north': { x: 0, y: -1 },
|
|
14
|
-
'west': { x: -1, y: 0 },
|
|
15
|
-
'southwest': { x: -1, y: 1 },
|
|
16
|
-
'northwest': { x: -1, y: -1 },
|
|
17
|
-
'northeast': { x: 1, y: -1 } // top right
|
|
18
|
-
};
|
|
19
|
-
var handles = Object.keys(directions);
|
|
20
10
|
var setSize = function (domNode, sizeType, value) {
|
|
21
11
|
domNode.style[sizeType] = value + 'px';
|
|
22
12
|
};
|
|
@@ -45,7 +35,7 @@ var handleMouseMove = function (view, event, options) {
|
|
|
45
35
|
return;
|
|
46
36
|
}
|
|
47
37
|
var img = view.nodeDOM(nodePosition);
|
|
48
|
-
var dir = directions[activeHandle];
|
|
38
|
+
var dir = resize_utils_1.directions[activeHandle];
|
|
49
39
|
var diffX = (event.clientX - dragging.startX) * dir.x;
|
|
50
40
|
var diffY = (event.clientY - dragging.startY) * dir.y;
|
|
51
41
|
var width = dir.x ? diffX + img.width : rect.width;
|
|
@@ -112,7 +102,7 @@ var handleMouseUp = function (view) {
|
|
|
112
102
|
};
|
|
113
103
|
var handleMouseDown = function (view, event, options) {
|
|
114
104
|
var target = event.target;
|
|
115
|
-
var activeHandle = target.getAttribute(constants_1.
|
|
105
|
+
var activeHandle = target.getAttribute(constants_1.dataResizeDirImage);
|
|
116
106
|
if (!activeHandle) {
|
|
117
107
|
return false;
|
|
118
108
|
}
|
|
@@ -222,10 +212,10 @@ exports.imageResizing = function (options) {
|
|
|
222
212
|
wrapper.style.height = rect.height + 'px';
|
|
223
213
|
wrapper.style.top = rect.top + 'px';
|
|
224
214
|
wrapper.style.left = rect.left + 'px';
|
|
225
|
-
for (var i = 0; i < handles.length; i++) {
|
|
215
|
+
for (var i = 0; i < resize_utils_1.handles.length; i++) {
|
|
226
216
|
var dom = document.createElement('div');
|
|
227
|
-
dom.className = constants_1.resizeHandle + ' ' + handles[i];
|
|
228
|
-
dom.setAttribute(constants_1.
|
|
217
|
+
dom.className = constants_1.resizeHandle + ' ' + resize_utils_1.handles[i];
|
|
218
|
+
dom.setAttribute(constants_1.dataResizeDirImage, resize_utils_1.handles[i]);
|
|
229
219
|
wrapper.appendChild(dom);
|
|
230
220
|
}
|
|
231
221
|
return prosemirror_view_1.DecorationSet.create(state.doc, [prosemirror_view_1.Decoration.widget(state.selection.from + 1, wrapper)]);
|