@progress/kendo-editor-common 1.9.0-dev.202204081457 → 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 +2 -1
- 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 +38 -64
- 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/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 +40 -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/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 +37 -63
- 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 +1 -1
|
@@ -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
|
var TableView = /** @class */ (function () {
|
|
5
5
|
function TableView(node, view) {
|
|
6
6
|
this.node = node;
|
|
@@ -13,10 +13,10 @@ var TableView = /** @class */ (function () {
|
|
|
13
13
|
}
|
|
14
14
|
var tBody = this.table.appendChild(document.createElement('tbody'));
|
|
15
15
|
this.setAttributes(this.table, node.attrs);
|
|
16
|
-
this.resizeHandles =
|
|
16
|
+
this.resizeHandles = handles.map(function (dir) {
|
|
17
17
|
var 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;
|
|
@@ -52,11 +52,11 @@ var TableView = /** @class */ (function () {
|
|
|
52
52
|
return result;
|
|
53
53
|
};
|
|
54
54
|
TableView.prototype.destroy = function () {
|
|
55
|
-
this.node =
|
|
56
|
-
this.view =
|
|
57
|
-
this.table =
|
|
58
|
-
this.colgroup =
|
|
59
|
-
this.resizeHandles =
|
|
55
|
+
this.node = undefined;
|
|
56
|
+
this.view = undefined;
|
|
57
|
+
this.table = undefined;
|
|
58
|
+
this.colgroup = undefined;
|
|
59
|
+
this.resizeHandles = undefined;
|
|
60
60
|
};
|
|
61
61
|
TableView.prototype.renderColgroup = function (colgroupStr) {
|
|
62
62
|
if (this.table && this.table.firstChild && this.table.firstChild.nodeName === 'COLGROUP') {
|
|
@@ -40,9 +40,11 @@ export function otherResizing(current, state) {
|
|
|
40
40
|
export function otherResizeHandle(current, state) {
|
|
41
41
|
var activeResize = false;
|
|
42
42
|
activeResize = activeResize ||
|
|
43
|
-
(current !== tableColumnResizing &&
|
|
43
|
+
(current !== tableColumnResizing &&
|
|
44
|
+
Boolean(tableColumnResizing.get(state)) &&
|
|
45
|
+
tableColumnResizing.getState(state).activeHandle > -1);
|
|
44
46
|
activeResize = activeResize ||
|
|
45
|
-
(current !== tableRowResizing && tableRowResizing.get(state) && tableRowResizing.getState(state).activeHandle > -1);
|
|
47
|
+
(current !== tableRowResizing && Boolean(tableRowResizing.get(state)) && tableRowResizing.getState(state).activeHandle > -1);
|
|
46
48
|
return activeResize;
|
|
47
49
|
}
|
|
48
50
|
export function getTable(dom) {
|
|
@@ -51,3 +53,25 @@ export function getTable(dom) {
|
|
|
51
53
|
}
|
|
52
54
|
return dom;
|
|
53
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
|
+
}
|
|
@@ -3,4 +3,5 @@ export const colgroupAttr = 'k-colgroup-data';
|
|
|
3
3
|
export const resizableAttr = 'resizable-node';
|
|
4
4
|
export const resizableWrap = 'k-editor-resize-wrap-element';
|
|
5
5
|
export const resizeHandle = 'k-editor-resize-handle';
|
|
6
|
-
export const
|
|
6
|
+
export const dataResizeDirTable = 'data-direction';
|
|
7
|
+
export const dataResizeDirImage = 'data-direction-image';
|
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
import { NodeSelection, Plugin, PluginKey } from "prosemirror-state";
|
|
2
2
|
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
3
|
-
import {
|
|
3
|
+
import { dataResizeDirImage, resizeHandle } from "../config/constants";
|
|
4
4
|
import { changeStylesString } from "../utils";
|
|
5
|
+
import { directions, handles } from './resize-utils';
|
|
5
6
|
export const imageResizeKey = new PluginKey('image-resize');
|
|
6
|
-
const directions = {
|
|
7
|
-
'southeast': { x: 1, y: 1 },
|
|
8
|
-
'east': { x: 1, y: 0 },
|
|
9
|
-
'south': { x: 0, y: 1 },
|
|
10
|
-
'north': { x: 0, y: -1 },
|
|
11
|
-
'west': { x: -1, y: 0 },
|
|
12
|
-
'southwest': { x: -1, y: 1 },
|
|
13
|
-
'northwest': { x: -1, y: -1 },
|
|
14
|
-
'northeast': { x: 1, y: -1 } // top right
|
|
15
|
-
};
|
|
16
|
-
const handles = Object.keys(directions);
|
|
17
7
|
const setSize = (domNode, sizeType, value) => {
|
|
18
8
|
domNode.style[sizeType] = value + 'px';
|
|
19
9
|
};
|
|
@@ -108,7 +98,7 @@ const handleMouseUp = (view) => {
|
|
|
108
98
|
};
|
|
109
99
|
const handleMouseDown = (view, event, options) => {
|
|
110
100
|
const target = event.target;
|
|
111
|
-
const activeHandle = target.getAttribute(
|
|
101
|
+
const activeHandle = target.getAttribute(dataResizeDirImage);
|
|
112
102
|
if (!activeHandle) {
|
|
113
103
|
return false;
|
|
114
104
|
}
|
|
@@ -220,7 +210,7 @@ export const imageResizing = (options = { node: 'image', lockRatio: true }) => {
|
|
|
220
210
|
for (let i = 0; i < handles.length; i++) {
|
|
221
211
|
let dom = document.createElement('div');
|
|
222
212
|
dom.className = resizeHandle + ' ' + handles[i];
|
|
223
|
-
dom.setAttribute(
|
|
213
|
+
dom.setAttribute(dataResizeDirImage, handles[i]);
|
|
224
214
|
wrapper.appendChild(dom);
|
|
225
215
|
}
|
|
226
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);
|
|
@@ -3,10 +3,10 @@ import { tableNodeTypes, TableMap } from 'prosemirror-tables';
|
|
|
3
3
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
4
4
|
import { colgroupAttr } from '../../config/constants';
|
|
5
5
|
import { TableView } from './table-view';
|
|
6
|
-
import { otherResizeHandle, otherResizing, parseStyle, setNodeStyle, tableColumnResizing as key } from './utils';
|
|
6
|
+
import { cellIndexes, domCellAround, otherResizeHandle, otherResizing, parentNode, parseStyle, setNodeStyle, tableColumnResizing as key } from './utils';
|
|
7
7
|
export function columnResizing() {
|
|
8
8
|
// tslint:disable-next-line:variable-name
|
|
9
|
-
const View = TableView,
|
|
9
|
+
const View = TableView, handleWidth = 5, cellMinWidth = 25;
|
|
10
10
|
let plugin = new Plugin({
|
|
11
11
|
key,
|
|
12
12
|
state: {
|
|
@@ -29,7 +29,7 @@ export function columnResizing() {
|
|
|
29
29
|
handleDOMEvents: {
|
|
30
30
|
mousemove(view, event) {
|
|
31
31
|
if (!otherResizing(key, view.state)) {
|
|
32
|
-
handleMouseMove(view, event, handleWidth
|
|
32
|
+
handleMouseMove(view, event, handleWidth);
|
|
33
33
|
}
|
|
34
34
|
return false;
|
|
35
35
|
},
|
|
@@ -42,29 +42,21 @@ export function columnResizing() {
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
decorations(state) {
|
|
45
|
-
if (otherResizing(key, state)) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return handleDecorations(state, pluginState.activeHandle);
|
|
45
|
+
if (!otherResizing(key, state)) {
|
|
46
|
+
let pluginState = key.getState(state);
|
|
47
|
+
if (pluginState.activeHandle > -1) {
|
|
48
|
+
return handleDecorations(state, pluginState.activeHandle);
|
|
49
|
+
}
|
|
51
50
|
}
|
|
51
|
+
return DecorationSet.empty;
|
|
52
52
|
},
|
|
53
53
|
nodeViews: {}
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
return plugin;
|
|
57
57
|
}
|
|
58
|
-
function cellAround($pos) {
|
|
59
|
-
for (let d = $pos.depth - 1; d > 0; d--) {
|
|
60
|
-
if ($pos.node(d).type.spec.tableRole === 'row') {
|
|
61
|
-
return $pos.node(0).resolve($pos.before(d + 1));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
58
|
function pointsAtCell($pos) {
|
|
67
|
-
return $pos.parent.type.spec.tableRole === 'row' && $pos.nodeAfter;
|
|
59
|
+
return Boolean($pos.parent.type.spec.tableRole === 'row' && $pos.nodeAfter);
|
|
68
60
|
}
|
|
69
61
|
class ResizeState {
|
|
70
62
|
constructor(activeHandle, dragging) {
|
|
@@ -82,35 +74,29 @@ class ResizeState {
|
|
|
82
74
|
if (state.activeHandle > -1 && tr.docChanged) {
|
|
83
75
|
let handle = tr.mapping.map(state.activeHandle, -1);
|
|
84
76
|
if (!pointsAtCell(tr.doc.resolve(handle))) {
|
|
85
|
-
handle =
|
|
77
|
+
handle = -1;
|
|
86
78
|
}
|
|
87
79
|
state = new ResizeState(handle, state.dragging);
|
|
88
80
|
}
|
|
89
81
|
return state;
|
|
90
82
|
}
|
|
91
83
|
}
|
|
92
|
-
function handleMouseMove(view, event, handleWidth
|
|
84
|
+
function handleMouseMove(view, event, handleWidth) {
|
|
93
85
|
let pluginState = key.getState(view.state);
|
|
94
86
|
if (!pluginState.dragging) {
|
|
95
87
|
let target = domCellAround(event.target), cell = -1;
|
|
96
88
|
if (target) {
|
|
89
|
+
const indexes = cellIndexes(target);
|
|
97
90
|
let { left, right } = target.getBoundingClientRect();
|
|
98
|
-
if (event.clientX - left <= handleWidth) {
|
|
99
|
-
|
|
91
|
+
if (Math.abs(event.clientX - left) <= handleWidth && indexes.cellIndex > 0) {
|
|
92
|
+
indexes.cellIndex--;
|
|
93
|
+
cell = edgeCell(view, event, indexes);
|
|
100
94
|
}
|
|
101
|
-
else if (right - event.clientX <= handleWidth) {
|
|
102
|
-
cell = edgeCell(view, event,
|
|
95
|
+
else if (right - event.clientX > 0 && right - event.clientX <= handleWidth) {
|
|
96
|
+
cell = edgeCell(view, event, indexes);
|
|
103
97
|
}
|
|
104
98
|
}
|
|
105
99
|
if (cell !== pluginState.activeHandle) {
|
|
106
|
-
if (!lastColumnResizable && cell !== -1) {
|
|
107
|
-
let $cell = view.state.doc.resolve(cell);
|
|
108
|
-
let table = $cell.node(-1), map = TableMap.get(table), start = $cell.start(-1);
|
|
109
|
-
let col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;
|
|
110
|
-
if (col === map.width - 1) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
100
|
updateHandle(view, cell);
|
|
115
101
|
}
|
|
116
102
|
}
|
|
@@ -167,7 +153,7 @@ function handleMouseDown(view, event, cellMinWidth) {
|
|
|
167
153
|
const widths = Array.from(col.parentNode.children).map((c) => c.style.width);
|
|
168
154
|
if (widths.every(Boolean)) {
|
|
169
155
|
const sum = widths.reduce((acc, cur) => acc + parseFloat(cur), 0);
|
|
170
|
-
tableAttrs = setNodeStyle(tableNode.attrs, 'width', sum + 'px');
|
|
156
|
+
tableAttrs = setNodeStyle(tableAttrs || tableNode.attrs, 'width', sum + 'px');
|
|
171
157
|
}
|
|
172
158
|
}
|
|
173
159
|
if (tableAttrs) {
|
|
@@ -197,28 +183,21 @@ function handleMouseDown(view, event, cellMinWidth) {
|
|
|
197
183
|
event.preventDefault();
|
|
198
184
|
return true;
|
|
199
185
|
}
|
|
200
|
-
function
|
|
201
|
-
while (target && target.nodeName !== 'TD' && target.nodeName !== 'TH') {
|
|
202
|
-
target = target.classList.contains('ProseMirror') ? null : target.parentNode;
|
|
203
|
-
}
|
|
204
|
-
return target;
|
|
205
|
-
}
|
|
206
|
-
function edgeCell(view, event, side) {
|
|
186
|
+
function edgeCell(view, event, indexes) {
|
|
207
187
|
let found = view.posAtCoords({ left: event.clientX, top: event.clientY });
|
|
208
188
|
if (!found) {
|
|
209
189
|
return -1;
|
|
210
190
|
}
|
|
211
|
-
let
|
|
212
|
-
let
|
|
213
|
-
if (
|
|
191
|
+
let $pos = view.state.doc.resolve(found.pos);
|
|
192
|
+
let parentTable = parentNode($pos, n => n.type.spec.tableRole === 'table');
|
|
193
|
+
if (parentTable === null) {
|
|
214
194
|
return -1;
|
|
215
195
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return index % map.width === 0 ? -1 : start + map.map[index - 1];
|
|
196
|
+
let tablePos = $pos.start(parentTable.depth);
|
|
197
|
+
const tableNode = parentTable.node;
|
|
198
|
+
const map = TableMap.get(tableNode);
|
|
199
|
+
const cell = tablePos + map.map[(map.width * indexes.rowIndex) + indexes.cellIndex];
|
|
200
|
+
return cell;
|
|
222
201
|
}
|
|
223
202
|
function draggedWidth(dragging, event, cellMinWidth) {
|
|
224
203
|
let offset = event.clientX - dragging.startX;
|
|
@@ -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));
|