@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.
Files changed (33) 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 +2 -1
  4. package/dist/es/plugins/image-resize.js +4 -14
  5. package/dist/es/plugins/resize-utils.js +11 -0
  6. package/dist/es/plugins/table-resize/column-resize.js +28 -49
  7. package/dist/es/plugins/table-resize/row-resize.js +40 -54
  8. package/dist/es/plugins/table-resize/table-resize.js +38 -64
  9. package/dist/es/plugins/table-resize/table-view.js +9 -9
  10. package/dist/es/plugins/table-resize/utils.js +26 -2
  11. package/dist/es2015/config/constants.js +2 -1
  12. package/dist/es2015/plugins/image-resize.js +4 -14
  13. package/dist/es2015/plugins/resize-utils.js +11 -0
  14. package/dist/es2015/plugins/table-resize/column-resize.js +28 -49
  15. package/dist/es2015/plugins/table-resize/row-resize.js +40 -54
  16. package/dist/es2015/plugins/table-resize/table-resize.js +40 -66
  17. package/dist/es2015/plugins/table-resize/table-view.js +9 -9
  18. package/dist/es2015/plugins/table-resize/utils.js +26 -2
  19. package/dist/npm/config/constants.d.ts +2 -1
  20. package/dist/npm/config/constants.js +2 -1
  21. package/dist/npm/plugins/image-resize.js +6 -16
  22. package/dist/npm/plugins/resize-utils.d.ts +35 -0
  23. package/dist/npm/plugins/resize-utils.js +13 -0
  24. package/dist/npm/plugins/table-resize/column-resize.js +28 -49
  25. package/dist/npm/plugins/table-resize/row-resize.js +39 -53
  26. package/dist/npm/plugins/table-resize/table-resize.d.ts +2 -4
  27. package/dist/npm/plugins/table-resize/table-resize.js +37 -63
  28. package/dist/npm/plugins/table-resize/table-view.d.ts +7 -7
  29. package/dist/npm/plugins/table-resize/table-view.js +8 -8
  30. package/dist/npm/plugins/table-resize/utils.d.ts +10 -0
  31. package/dist/npm/plugins/table-resize/utils.js +29 -2
  32. package/dist/systemjs/kendo-editor-common.js +1 -1
  33. package/package.json +1 -1
@@ -1,25 +1,7 @@
1
1
  import { NodeSelection, Plugin } from 'prosemirror-state';
2
- import { colgroupAttr, dataDirection, resizableAttr } from '../../config/constants';
3
- import { getTable, parseStyle, setNodeStyle, tableResizeKey as key } from './utils';
4
- function parentNode(pos, predicate) {
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, options) => {
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 resizedNode = getTable(view.nodeDOM(nodePosition));
56
- const rect = resizedNode.getBoundingClientRect();
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 nodeWidth = resizedNode.offsetWidth;
61
- const nodeHeight = resizedNode.offsetHeight;
62
- let width = dir.x ? diffX + nodeWidth : rect.width;
63
- let height = dir.y ? diffY + nodeHeight : rect.height;
64
- if (options.lockRatio && dir.x && dir.y) {
65
- let ratio = Math.min(width / nodeWidth, height / nodeHeight);
66
- let lockWidth = nodeWidth * ratio;
67
- let lockHeight = nodeHeight * ratio;
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
- setSize(resizedNode, 'width', width);
48
+ tableDom.style.width = width + 'px';
79
49
  }
80
50
  if (verticalDir[activeHandle]) {
81
- setSize(resizedNode, 'height', height);
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: tableWidth, height: tableHeight, colsWidth } = tableSize(tableDom);
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 / tableWidth) + '%';
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', (rows[index].offsetHeight * 100 / tableHeight) + '%'));
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 !== tableWidth + 'px') {
109
- tableAttrs = setNodeStyle(tableAttrs, 'width', tableWidth + 'px');
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', tableHeight + 'px');
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].offsetHeight + 'px'));
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].offsetWidth + 'px';
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 = table.offsetHeight; // Array.from(table.rows).reduce((acc, cur) => acc + cur.offsetHeight, 0);
151
- return { width, height, colsWidth, offsetWidth: table.offsetWidth };
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.height + 'px';
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, options) => {
157
+ const handleMouseDown = (view, event) => {
185
158
  const target = event.target;
186
- const activeHandle = target.getAttribute(dataDirection);
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, options);
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', lockRatio: false }) => {
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 node = parentNode(selection.$from, (n) => n.type === nodeType);
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');
@@ -269,7 +243,7 @@ export const tableResizing = (options = { node: 'table', lockRatio: false }) =>
269
243
  props: {
270
244
  handleDOMEvents: {
271
245
  mousedown(view, event) {
272
- return handleMouseDown(view, event, options);
246
+ return handleMouseDown(view, event);
273
247
  }
274
248
  }
275
249
  }
@@ -1,6 +1,6 @@
1
- import { colgroupAttr, dataDirection, resizableAttr, resizableWrap, resizeHandle } from '../../config/constants';
1
+ import { colgroupAttr, dataResizeDirTable, resizableAttr, resizableWrap, resizeHandle } from '../../config/constants';
2
2
  import { parseStrColgroup } from '../../config/schema';
3
- const directions = ['northwest', 'north', 'northeast', 'southwest', 'south', 'southeast', 'west', 'east'];
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 = directions.map(dir => {
16
+ this.resizeHandles = handles.map(dir => {
17
17
  const handle = document.createElement('span');
18
18
  handle.className = resizeHandle + ' ' + dir;
19
- handle.setAttribute(dataDirection, dir);
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 = null;
55
- this.view = null;
56
- this.table = null;
57
- this.colgroup = null;
58
- this.resizeHandles = null;
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 && tableColumnResizing.get(state) && tableColumnResizing.getState(state).activeHandle > -1);
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 dataDirection = "data-direction";
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.dataDirection = 'data-direction';
8
+ exports.dataResizeDirTable = 'data-direction';
9
+ exports.dataResizeDirImage = 'data-direction-image';
@@ -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,7 +9,7 @@ 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
14
  key: utils_1.tableColumnResizing,
15
15
  state: {
@@ -32,7 +32,7 @@ function columnResizing() {
32
32
  handleDOMEvents: {
33
33
  mousemove: function (view, event) {
34
34
  if (!utils_1.otherResizing(utils_1.tableColumnResizing, view.state)) {
35
- handleMouseMove(view, event, handleWidth, cellMinWidth, lastColumnResizable);
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.tableColumnResizing, state)) {
49
+ var pluginState = utils_1.tableColumnResizing.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) {
@@ -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,28 +86,22 @@ var ResizeState = /** @class */ (function () {
94
86
  };
95
87
  return ResizeState;
96
88
  }());
97
- function handleMouseMove(view, event, handleWidth, _cellMinWidth, lastColumnResizable) {
89
+ function handleMouseMove(view, event, handleWidth) {
98
90
  var pluginState = utils_1.tableColumnResizing.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
  }
@@ -173,7 +159,7 @@ function handleMouseDown(view, event, cellMinWidth) {
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) {
@@ -203,28 +189,21 @@ 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;