@progress/kendo-editor-common 1.9.0-dev.202204081457 → 1.9.0-dev.202204181536

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