@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.
Files changed (47) hide show
  1. package/dist/cdn/js/kendo-editor-common.js +2 -2
  2. package/dist/cdn/main.js +1 -1
  3. package/dist/es/config/constants.js +5 -0
  4. package/dist/es/config/schema.js +9 -5
  5. package/dist/es/main.js +1 -0
  6. package/dist/es/plugins/image-resize.js +5 -14
  7. package/dist/es/plugins/resize-utils.js +11 -0
  8. package/dist/es/plugins/table-resize/column-resize.js +273 -0
  9. package/dist/es/plugins/table-resize/index.js +8 -0
  10. package/dist/es/plugins/table-resize/row-resize.js +230 -0
  11. package/dist/es/plugins/table-resize/table-resize.js +255 -0
  12. package/dist/es/plugins/table-resize/table-view.js +87 -0
  13. package/dist/es/plugins/table-resize/utils.js +77 -0
  14. package/dist/es2015/config/constants.js +5 -0
  15. package/dist/es2015/config/schema.js +11 -8
  16. package/dist/es2015/main.js +1 -0
  17. package/dist/es2015/plugins/image-resize.js +5 -14
  18. package/dist/es2015/plugins/resize-utils.js +11 -0
  19. package/dist/es2015/plugins/table-resize/column-resize.js +269 -0
  20. package/dist/es2015/plugins/table-resize/index.js +8 -0
  21. package/dist/es2015/plugins/table-resize/row-resize.js +226 -0
  22. package/dist/es2015/plugins/table-resize/table-resize.js +251 -0
  23. package/dist/es2015/plugins/table-resize/table-view.js +84 -0
  24. package/dist/es2015/plugins/table-resize/utils.js +75 -0
  25. package/dist/npm/config/constants.d.ts +5 -0
  26. package/dist/npm/config/constants.js +5 -0
  27. package/dist/npm/config/schema.d.ts +1 -0
  28. package/dist/npm/config/schema.js +8 -4
  29. package/dist/npm/main.d.ts +1 -0
  30. package/dist/npm/main.js +2 -0
  31. package/dist/npm/plugins/image-resize.js +7 -16
  32. package/dist/npm/plugins/resize-utils.d.ts +35 -0
  33. package/dist/npm/plugins/resize-utils.js +13 -0
  34. package/dist/npm/plugins/table-resize/column-resize.d.ts +2 -0
  35. package/dist/npm/plugins/table-resize/column-resize.js +276 -0
  36. package/dist/npm/plugins/table-resize/index.d.ts +1 -0
  37. package/dist/npm/plugins/table-resize/index.js +10 -0
  38. package/dist/npm/plugins/table-resize/row-resize.d.ts +2 -0
  39. package/dist/npm/plugins/table-resize/row-resize.js +233 -0
  40. package/dist/npm/plugins/table-resize/table-resize.d.ts +4 -0
  41. package/dist/npm/plugins/table-resize/table-resize.js +257 -0
  42. package/dist/npm/plugins/table-resize/table-view.d.ts +17 -0
  43. package/dist/npm/plugins/table-resize/table-view.js +89 -0
  44. package/dist/npm/plugins/table-resize/utils.d.ts +22 -0
  45. package/dist/npm/plugins/table-resize/utils.js +86 -0
  46. package/dist/systemjs/kendo-editor-common.js +1 -1
  47. package/package.json +2 -2
@@ -0,0 +1,276 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ var prosemirror_state_1 = require("prosemirror-state");
5
+ var prosemirror_tables_1 = require("prosemirror-tables");
6
+ var prosemirror_view_1 = require("prosemirror-view");
7
+ var constants_1 = require("../../config/constants");
8
+ var table_view_1 = require("./table-view");
9
+ var utils_1 = require("./utils");
10
+ function columnResizing() {
11
+ // tslint:disable-next-line:variable-name
12
+ var View = table_view_1.TableView, handleWidth = 5, cellMinWidth = 25;
13
+ var plugin = new prosemirror_state_1.Plugin({
14
+ key: utils_1.tableColumnResizing,
15
+ state: {
16
+ init: function (_, state) {
17
+ this.spec.props.nodeViews[prosemirror_tables_1.tableNodeTypes(state.schema).table.name] = function (node, view) { return new View(node, view); };
18
+ return new ResizeState(-1, null);
19
+ },
20
+ apply: function (tr, prev) {
21
+ return prev.apply(tr);
22
+ }
23
+ },
24
+ props: {
25
+ attributes: function (state) {
26
+ if (utils_1.otherResizeHandle(utils_1.tableColumnResizing, state)) {
27
+ return null;
28
+ }
29
+ var pluginState = utils_1.tableColumnResizing.getState(state);
30
+ return pluginState.activeHandle > -1 ? { class: 'resize-cursor' } : null;
31
+ },
32
+ handleDOMEvents: {
33
+ mousemove: function (view, event) {
34
+ if (!utils_1.otherResizing(utils_1.tableColumnResizing, view.state)) {
35
+ handleMouseMove(view, event, handleWidth);
36
+ }
37
+ return false;
38
+ },
39
+ mouseleave: function (view) {
40
+ handleMouseLeave(view);
41
+ return false;
42
+ },
43
+ mousedown: function (view, event) {
44
+ return handleMouseDown(view, event, cellMinWidth);
45
+ }
46
+ },
47
+ decorations: function (state) {
48
+ if (!utils_1.otherResizing(utils_1.tableColumnResizing, state)) {
49
+ var pluginState = utils_1.tableColumnResizing.getState(state);
50
+ if (pluginState.activeHandle > -1) {
51
+ return handleDecorations(state, pluginState.activeHandle);
52
+ }
53
+ }
54
+ return prosemirror_view_1.DecorationSet.empty;
55
+ },
56
+ nodeViews: {}
57
+ }
58
+ });
59
+ return plugin;
60
+ }
61
+ exports.columnResizing = columnResizing;
62
+ function pointsAtCell($pos) {
63
+ return Boolean($pos.parent.type.spec.tableRole === 'row' && $pos.nodeAfter);
64
+ }
65
+ var ResizeState = /** @class */ (function () {
66
+ function ResizeState(activeHandle, dragging) {
67
+ this.activeHandle = activeHandle;
68
+ this.dragging = dragging;
69
+ }
70
+ ResizeState.prototype.apply = function (tr) {
71
+ var state = this, action = tr.getMeta(utils_1.tableColumnResizing);
72
+ if (action && action.setHandle != null) {
73
+ return new ResizeState(action.setHandle, null);
74
+ }
75
+ if (action && action.setDragging !== undefined) {
76
+ return new ResizeState(state.activeHandle, action.setDragging);
77
+ }
78
+ if (state.activeHandle > -1 && tr.docChanged) {
79
+ var handle = tr.mapping.map(state.activeHandle, -1);
80
+ if (!pointsAtCell(tr.doc.resolve(handle))) {
81
+ handle = -1;
82
+ }
83
+ state = new ResizeState(handle, state.dragging);
84
+ }
85
+ return state;
86
+ };
87
+ return ResizeState;
88
+ }());
89
+ function handleMouseMove(view, event, handleWidth) {
90
+ var pluginState = utils_1.tableColumnResizing.getState(view.state);
91
+ if (!pluginState.dragging) {
92
+ var target = utils_1.domCellAround(event.target), cell = -1;
93
+ if (target) {
94
+ var indexes = utils_1.cellIndexes(target);
95
+ var _a = target.getBoundingClientRect(), left = _a.left, right = _a.right;
96
+ if (Math.abs(event.clientX - left) <= handleWidth && indexes.cellIndex > 0) {
97
+ indexes.cellIndex--;
98
+ cell = edgeCell(view, event, indexes);
99
+ }
100
+ else if (right - event.clientX > 0 && right - event.clientX <= handleWidth) {
101
+ cell = edgeCell(view, event, indexes);
102
+ }
103
+ }
104
+ if (cell !== pluginState.activeHandle) {
105
+ updateHandle(view, cell);
106
+ }
107
+ }
108
+ }
109
+ function handleMouseLeave(view) {
110
+ var pluginState = utils_1.tableColumnResizing.getState(view.state);
111
+ if (pluginState.activeHandle > -1 && !pluginState.dragging) {
112
+ updateHandle(view, -1);
113
+ }
114
+ }
115
+ function handleMouseDown(view, event, cellMinWidth) {
116
+ var _a;
117
+ var pluginState = utils_1.tableColumnResizing.getState(view.state);
118
+ if (pluginState.activeHandle === -1 || pluginState.dragging) {
119
+ return false;
120
+ }
121
+ var $cell = view.state.doc.resolve(pluginState.activeHandle);
122
+ var row = $cell.parent;
123
+ var cellIndex = $cell.index();
124
+ var colSpan = 0;
125
+ for (var i = 0; i <= cellIndex; i++) {
126
+ colSpan += row.child(i).attrs.colspan;
127
+ }
128
+ var tableNode = $cell.node($cell.depth - 1);
129
+ var dom = view.domAtPos(pluginState.activeHandle);
130
+ var domCell = dom.node.childNodes[dom.offset];
131
+ var tableDom = domCell.closest('table');
132
+ var col, tableAttrs;
133
+ if (tableNode.attrs[constants_1.colgroupAttr]) {
134
+ var colgroup = tableDom.firstChild;
135
+ col = colgroup.children[colSpan - 1];
136
+ if (!col.style.width) {
137
+ col.style.width = col.offsetWidth + 'px';
138
+ }
139
+ }
140
+ else {
141
+ var total = 0;
142
+ for (var i = 0; i < row.childCount; i++) {
143
+ total += row.child(i).attrs.colspan;
144
+ }
145
+ var colgroup = document.createElement('colgroup');
146
+ var cols = new Array(total);
147
+ for (var i = 0; i < total; i++) {
148
+ cols[i] = document.createElement('col');
149
+ colgroup.appendChild(cols[i]);
150
+ }
151
+ tableDom.insertBefore(colgroup, tableDom.firstChild);
152
+ col = cols[cellIndex];
153
+ col.style.width = col.offsetWidth + 'px';
154
+ tableAttrs = tslib_1.__assign({}, tableNode.attrs, (_a = {}, _a[constants_1.colgroupAttr] = '<colgroup>' + cols.reduce(function (acc, cur) { return acc + cur.outerHTML; }, '') + '</colgroup>', _a));
155
+ }
156
+ var width = parseFloat(col.style.width);
157
+ var tr = view.state.tr.setMeta(utils_1.tableColumnResizing, { setDragging: { startX: event.clientX, startWidth: width } });
158
+ if (!tableDom.style.width) {
159
+ var widths = Array.from(col.parentNode.children).map(function (c) { return c.style.width; });
160
+ if (widths.every(Boolean)) {
161
+ var sum = widths.reduce(function (acc, cur) { return acc + parseFloat(cur); }, 0);
162
+ tableAttrs = utils_1.setNodeStyle(tableAttrs || tableNode.attrs, 'width', sum + 'px');
163
+ }
164
+ }
165
+ if (tableAttrs) {
166
+ var tablePos = $cell.posAtIndex(0, $cell.depth - 1) - 1;
167
+ tr.setNodeMarkup(tablePos, null, tableAttrs);
168
+ }
169
+ view.dispatch(tr);
170
+ function finish(ev) {
171
+ ev.view.removeEventListener('mouseup', finish);
172
+ ev.view.removeEventListener('mousemove', move);
173
+ var curPluginState = utils_1.tableColumnResizing.getState(view.state);
174
+ if (curPluginState.dragging) {
175
+ updateColumnWidth(view, curPluginState.activeHandle, draggedWidth(curPluginState.dragging, ev, cellMinWidth));
176
+ view.dispatch(view.state.tr.setMeta(utils_1.tableColumnResizing, { setDragging: null }));
177
+ }
178
+ }
179
+ function move(ev) {
180
+ if (!ev.which) {
181
+ return finish(ev);
182
+ }
183
+ var curPluginState = utils_1.tableColumnResizing.getState(view.state);
184
+ var dragged = draggedWidth(curPluginState.dragging, ev, cellMinWidth);
185
+ displayColumnWidth(view, curPluginState.activeHandle, dragged, cellMinWidth);
186
+ }
187
+ event.view.addEventListener('mouseup', finish);
188
+ event.view.addEventListener('mousemove', move);
189
+ event.preventDefault();
190
+ return true;
191
+ }
192
+ function edgeCell(view, event, indexes) {
193
+ var found = view.posAtCoords({ left: event.clientX, top: event.clientY });
194
+ if (!found) {
195
+ return -1;
196
+ }
197
+ var $pos = view.state.doc.resolve(found.pos);
198
+ var parentTable = utils_1.parentNode($pos, function (n) { return n.type.spec.tableRole === 'table'; });
199
+ if (parentTable === null) {
200
+ return -1;
201
+ }
202
+ var tablePos = $pos.start(parentTable.depth);
203
+ var tableNode = parentTable.node;
204
+ var map = prosemirror_tables_1.TableMap.get(tableNode);
205
+ var cell = tablePos + map.map[(map.width * indexes.rowIndex) + indexes.cellIndex];
206
+ return cell;
207
+ }
208
+ function draggedWidth(dragging, event, cellMinWidth) {
209
+ var offset = event.clientX - dragging.startX;
210
+ return Math.max(cellMinWidth, dragging.startWidth + offset);
211
+ }
212
+ function updateHandle(view, value) {
213
+ view.dispatch(view.state.tr.setMeta(utils_1.tableColumnResizing, { setHandle: value }));
214
+ }
215
+ function updateColumnWidth(view, cell, _width) {
216
+ var _a;
217
+ var $cell = view.state.doc.resolve(cell);
218
+ var tableNode = $cell.node(-1), start = $cell.start(-1);
219
+ var tr = view.state.tr;
220
+ var tablePos = $cell.posAtIndex(0, $cell.depth - 1) - 1;
221
+ var tableDom = view.nodeDOM(start).closest('table');
222
+ var attrs = tableNode.attrs;
223
+ if (tableNode && attrs[constants_1.colgroupAttr]) {
224
+ var colgroup = tableDom.firstChild;
225
+ attrs = tslib_1.__assign({}, attrs, (_a = {}, _a[constants_1.colgroupAttr] = colgroup.outerHTML, _a));
226
+ }
227
+ var tableDomWidth = tableDom.style.width;
228
+ if (tableDom && tableDomWidth && utils_1.parseStyle(attrs.style).width !== tableDomWidth) {
229
+ attrs = utils_1.setNodeStyle(attrs, 'width', tableDomWidth);
230
+ tr.setNodeMarkup(tablePos, null, attrs);
231
+ }
232
+ if (tr.docChanged) {
233
+ view.dispatch(tr);
234
+ }
235
+ }
236
+ function displayColumnWidth(view, cell, width, _cellMinWidth) {
237
+ var $cell = view.state.doc.resolve(cell);
238
+ var table = $cell.node(-1), start = $cell.start(-1);
239
+ var col = prosemirror_tables_1.TableMap.get(table).colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;
240
+ var dom = view.domAtPos($cell.start(-1)).node;
241
+ if (dom.nodeName !== 'TABLE') {
242
+ dom = dom.closest('table');
243
+ }
244
+ var tableDom = dom;
245
+ var colgroup = tableDom.firstChild;
246
+ var cols = Array.from(colgroup.children);
247
+ cols[col].style.width = width + 'px';
248
+ if (tableDom.style.width) {
249
+ var widths = cols.map(function (c) { return c.style.width; });
250
+ if (widths.every(Boolean)) {
251
+ var sum = widths.reduce(function (acc, cur) { return acc + parseFloat(cur); }, 0);
252
+ tableDom.style.width = sum + 'px';
253
+ }
254
+ }
255
+ }
256
+ function handleDecorations(state, cell) {
257
+ var decorations = [];
258
+ var $cell = state.doc.resolve(cell);
259
+ var table = $cell.node(-1), map = prosemirror_tables_1.TableMap.get(table), start = $cell.start(-1);
260
+ var col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan;
261
+ for (var row = 0; row < map.height; row++) {
262
+ var index = col + row * map.width - 1;
263
+ // For positions that are have either a different cell or the end
264
+ // of the table to their right, and either the top of the table or
265
+ // a different cell above them, add a decoration
266
+ if ((col === map.width || map.map[index] !== map.map[index + 1]) &&
267
+ (row === 0 || map.map[index - 1] !== map.map[index - 1 - map.width])) {
268
+ var cellPos = map.map[index];
269
+ var pos = start + cellPos + table.nodeAt(cellPos).nodeSize - 1;
270
+ var dom = document.createElement('div');
271
+ dom.className = 'column-resize-handle';
272
+ decorations.push(prosemirror_view_1.Decoration.widget(pos, dom));
273
+ }
274
+ }
275
+ return prosemirror_view_1.DecorationSet.create(state.doc, decorations);
276
+ }
@@ -0,0 +1 @@
1
+ export declare const tableResizing: () => import("prosemirror-state").Plugin<any, any>[];
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var column_resize_1 = require("./column-resize");
4
+ var table_resize_1 = require("./table-resize");
5
+ var row_resize_1 = require("./row-resize");
6
+ exports.tableResizing = function () { return [
7
+ table_resize_1.tableResizing(),
8
+ column_resize_1.columnResizing(),
9
+ row_resize_1.rowResizing()
10
+ ]; };
@@ -0,0 +1,2 @@
1
+ import { Plugin } from 'prosemirror-state';
2
+ export declare function rowResizing(): Plugin;
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var prosemirror_state_1 = require("prosemirror-state");
4
+ var prosemirror_tables_1 = require("prosemirror-tables");
5
+ var prosemirror_view_1 = require("prosemirror-view");
6
+ var utils_1 = require("./utils");
7
+ var TableRowView = /** @class */ (function () {
8
+ function TableRowView() {
9
+ }
10
+ TableRowView.prototype.ignoreMutation = function (record) {
11
+ return record.type === 'attributes' && record.attributeName === 'style' && record.target.nodeName === 'TR';
12
+ };
13
+ return TableRowView;
14
+ }());
15
+ function rowResizing() {
16
+ var handleWidth = 5;
17
+ var plugin = new prosemirror_state_1.Plugin({
18
+ key: utils_1.tableRowResizing,
19
+ state: {
20
+ init: function (_, state) {
21
+ this.spec.props.nodeViews[prosemirror_tables_1.tableNodeTypes(state.schema).row.name] = function (_node, _view) { return new TableRowView(); };
22
+ return new ResizeState(-1, null);
23
+ },
24
+ apply: function (tr, prev) {
25
+ return prev.apply(tr);
26
+ }
27
+ },
28
+ props: {
29
+ attributes: function (state) {
30
+ if (utils_1.otherResizeHandle(utils_1.tableRowResizing, state)) {
31
+ return null;
32
+ }
33
+ var pluginState = utils_1.tableRowResizing.getState(state);
34
+ return pluginState.activeHandle > -1 ? { class: 'resize-cursor-vertical' } : null;
35
+ },
36
+ handleDOMEvents: {
37
+ mousemove: function (view, event) {
38
+ if (!utils_1.otherResizing(utils_1.tableRowResizing, view.state)) {
39
+ handleMouseMove(view, event, handleWidth);
40
+ }
41
+ return false;
42
+ },
43
+ mouseleave: function (view) {
44
+ handleMouseLeave(view);
45
+ return false;
46
+ },
47
+ mousedown: function (view, event) {
48
+ return handleMouseDown(view, event);
49
+ }
50
+ },
51
+ decorations: function (state) {
52
+ if (utils_1.otherResizing(utils_1.tableRowResizing, state)) {
53
+ return prosemirror_view_1.DecorationSet.empty;
54
+ }
55
+ var pluginState = utils_1.tableRowResizing.getState(state);
56
+ if (pluginState.activeHandle > -1) {
57
+ return handleDecorations(state, pluginState.activeHandle);
58
+ }
59
+ },
60
+ nodeViews: {}
61
+ }
62
+ });
63
+ return plugin;
64
+ }
65
+ exports.rowResizing = rowResizing;
66
+ function pointsAtCell($pos) {
67
+ return $pos.parent.type.spec.tableRole === 'row' && $pos.nodeAfter;
68
+ }
69
+ var ResizeState = /** @class */ (function () {
70
+ function ResizeState(activeHandle, dragging) {
71
+ this.activeHandle = activeHandle;
72
+ this.dragging = dragging;
73
+ }
74
+ ResizeState.prototype.apply = function (tr) {
75
+ var state = this, action = tr.getMeta(utils_1.tableRowResizing);
76
+ if (action && action.setHandle != null) {
77
+ return new ResizeState(action.setHandle, null);
78
+ }
79
+ if (action && action.setDragging !== undefined) {
80
+ return new ResizeState(state.activeHandle, action.setDragging);
81
+ }
82
+ if (state.activeHandle > -1) {
83
+ var handle = tr.mapping.map(state.activeHandle, -1);
84
+ if (!pointsAtCell(tr.doc.resolve(handle))) {
85
+ handle = null;
86
+ }
87
+ state = new ResizeState(handle, state.dragging);
88
+ }
89
+ return state;
90
+ };
91
+ return ResizeState;
92
+ }());
93
+ function handleMouseMove(view, event, handleWidth) {
94
+ var pluginState = utils_1.tableRowResizing.getState(view.state);
95
+ if (!pluginState.dragging) {
96
+ var target = utils_1.domCellAround(event.target), row = -1;
97
+ if (target) {
98
+ var rowDom = target.parentNode;
99
+ var domRect = rowDom.getBoundingClientRect();
100
+ if (Math.abs(event.clientY - domRect.top) <= handleWidth && rowDom.rowIndex > 0) {
101
+ row = edgeRow(view, event, rowDom.rowIndex - 1);
102
+ }
103
+ else if (domRect.bottom - event.clientY > 0 && domRect.bottom - event.clientY <= handleWidth) {
104
+ row = edgeRow(view, event, rowDom.rowIndex);
105
+ }
106
+ }
107
+ if (row !== pluginState.activeHandle) {
108
+ updateHandle(view, row);
109
+ }
110
+ }
111
+ }
112
+ function handleMouseLeave(view) {
113
+ var pluginState = utils_1.tableRowResizing.getState(view.state);
114
+ if (pluginState.activeHandle > -1 && !pluginState.dragging) {
115
+ updateHandle(view, -1);
116
+ }
117
+ }
118
+ function handleMouseDown(view, event) {
119
+ var pluginState = utils_1.tableRowResizing.getState(view.state);
120
+ if (pluginState.activeHandle === -1 || pluginState.dragging) {
121
+ return false;
122
+ }
123
+ var doc = view.state.doc;
124
+ var $pos = doc.resolve(pluginState.activeHandle);
125
+ var row = doc.nodeAt(pluginState.activeHandle);
126
+ var table = $pos.parent;
127
+ var rowHeightStr = utils_1.parseStyle(row.attrs.style).height;
128
+ var tableHeight = utils_1.parseStyle(table.attrs.style).height;
129
+ var rowHeight = rowHeightStr ? parseFloat(rowHeightStr) : 0;
130
+ if (!rowHeightStr) {
131
+ var tr = view.nodeDOM(pluginState.activeHandle);
132
+ rowHeight = tr.offsetHeight;
133
+ }
134
+ view.dispatch(view.state.tr.setMeta(utils_1.tableRowResizing, {
135
+ setDragging: {
136
+ startY: event.clientY,
137
+ startHeight: { rowHeight: rowHeight, tableHeight: tableHeight }
138
+ }
139
+ }));
140
+ function finish(ev) {
141
+ ev.view.removeEventListener('mouseup', finish);
142
+ ev.view.removeEventListener('mousemove', move);
143
+ var curPluginState = utils_1.tableRowResizing.getState(view.state);
144
+ if (curPluginState.dragging) {
145
+ var tr = view.state.tr.setMeta(utils_1.tableRowResizing, { setDragging: null });
146
+ updateRowHeight(view, tr, curPluginState.activeHandle);
147
+ view.dispatch(tr);
148
+ }
149
+ }
150
+ function move(ev) {
151
+ if (!ev.which) {
152
+ return finish(ev);
153
+ }
154
+ var curPluginState = utils_1.tableRowResizing.getState(view.state);
155
+ var dragged = draggedHeight(curPluginState.dragging, ev);
156
+ var offset = ev.clientY - curPluginState.dragging.startY;
157
+ displayRowHeight(view, curPluginState.activeHandle, dragged, offset, tableHeight);
158
+ }
159
+ event.view.addEventListener('mouseup', finish);
160
+ event.view.addEventListener('mousemove', move);
161
+ event.preventDefault();
162
+ return true;
163
+ }
164
+ function edgeRow(view, event, rowIndex) {
165
+ var found = view.posAtCoords({ left: event.clientX, top: event.clientY });
166
+ if (!found) {
167
+ return -1;
168
+ }
169
+ var $pos = view.state.doc.resolve(found.pos);
170
+ var parentTable = utils_1.parentNode($pos, function (n) { return n.type.spec.tableRole === 'table'; });
171
+ if (parentTable === null) {
172
+ return -1;
173
+ }
174
+ var tablePos = $pos.start(parentTable.depth);
175
+ var tableNode = parentTable.node;
176
+ var map = prosemirror_tables_1.TableMap.get(tableNode);
177
+ var row = tablePos + map.map[(map.width * rowIndex)] - 1;
178
+ return row;
179
+ }
180
+ function draggedHeight(dragging, event) {
181
+ var offset = event.clientY - dragging.startY;
182
+ return dragging.startHeight.rowHeight + offset;
183
+ }
184
+ function updateHandle(view, value) {
185
+ view.dispatch(view.state.tr.setMeta(utils_1.tableRowResizing, { setHandle: value }));
186
+ }
187
+ function updateRowHeight(view, tr, rowPos) {
188
+ var doc = view.state.doc;
189
+ var row = doc.nodeAt(rowPos);
190
+ var dom = view.nodeDOM(rowPos);
191
+ var win = (dom.ownerDocument && dom.ownerDocument.defaultView) || window;
192
+ dom.style.height = win.getComputedStyle(dom).height;
193
+ tr.setNodeMarkup(rowPos, null, utils_1.setNodeStyle(row.attrs, 'height', dom.style.height));
194
+ var table = dom && dom.closest('table');
195
+ var tableHeight = table && table.style.height;
196
+ if (tableHeight) {
197
+ var $pos = doc.resolve(rowPos);
198
+ var tablePos = $pos.start($pos.depth) - 1;
199
+ tr.setNodeMarkup(tablePos, null, utils_1.setNodeStyle($pos.parent.attrs, 'height', tableHeight));
200
+ }
201
+ }
202
+ function displayRowHeight(view, rowPos, height, offset, tableHeight) {
203
+ var dom = view.nodeDOM(rowPos);
204
+ if (dom) {
205
+ dom.style.height = height + 'px';
206
+ var win = (dom.ownerDocument && dom.ownerDocument.defaultView) || window;
207
+ dom.style.height = win.getComputedStyle(dom).height;
208
+ var table = dom.closest('table');
209
+ var newHeight = (parseFloat(tableHeight) + offset) + 'px';
210
+ var current = table && table.style.height;
211
+ if (current && current !== newHeight) {
212
+ table.style.height = (parseFloat(tableHeight) + offset) + 'px';
213
+ table.style.height = win.getComputedStyle(table).height;
214
+ }
215
+ }
216
+ }
217
+ function handleDecorations(state, pos) {
218
+ var decorations = [];
219
+ if (typeof pos !== 'number') {
220
+ return prosemirror_view_1.DecorationSet.empty;
221
+ }
222
+ var $row = state.doc.resolve(pos), table = $row.parent, map = prosemirror_tables_1.TableMap.get(table), rowIndex = $row.index($row.depth), start = $row.start($row.depth);
223
+ for (var col = 0; col < map.width; col++) {
224
+ var index = col + rowIndex * map.width;
225
+ var cellPos = map.map[index];
226
+ var cell = table.nodeAt(cellPos);
227
+ var widgetPos = start + cellPos + (cell ? cell.nodeSize : 0) - 1;
228
+ var dom = document.createElement('div');
229
+ dom.className = 'row-resize-handle';
230
+ decorations.push(prosemirror_view_1.Decoration.widget(widgetPos, dom));
231
+ }
232
+ return prosemirror_view_1.DecorationSet.create(state.doc, decorations);
233
+ }
@@ -0,0 +1,4 @@
1
+ import { Plugin } from 'prosemirror-state';
2
+ export declare const tableResizing: (options?: {
3
+ node: string;
4
+ }) => Plugin<any, any>;