@progress/kendo-editor-common 1.9.3-dev.202209121201 → 1.9.3-dev.202210050740

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/es/main.js CHANGED
@@ -36,7 +36,7 @@ export * from 'prosemirror-model';
36
36
  export * from 'prosemirror-schema-list';
37
37
  export * from 'prosemirror-state';
38
38
  // Fixes an error related to setting over the addRowAfter and addRowBefore exports from the PM tables module
39
- export { TableMap, tableEditing, tableEditingKey, tableNodeTypes, tableNodes, fixTables, fixTablesKey, isInTable, deleteTable, inSameTable, CellSelection, selectedRect, selectionCell, setCellAttr, goToNextCell, toggleHeader, toggleHeaderCell, toggleHeaderColumn, toggleHeaderRow, splitCell, splitCellWithType, mergeCells, deleteColumn, deleteRow, rowIsHeader, addRow, addColSpan, addColumn, addColumnAfter, addColumnBefore, colCount, columnIsHeader, columnResizing, columnResizingPluginKey, updateColumnsOnResize, cellAround, findCell, removeColSpan, moveCellForward, nextCell } from 'prosemirror-tables';
39
+ export { TableMap, tableEditing, tableEditingKey, tableNodeTypes, tableNodes, fixTables, fixTablesKey, isInTable, deleteTable, inSameTable, CellSelection, selectedRect, selectionCell, setCellAttr, goToNextCell, toggleHeader, toggleHeaderCell, toggleHeaderColumn, toggleHeaderRow, splitCell, splitCellWithType, mergeCells, deleteRow, rowIsHeader, addRow, addColSpan, addColumn, colCount, columnIsHeader, columnResizing, columnResizingPluginKey, updateColumnsOnResize, cellAround, findCell, removeColSpan, moveCellForward, nextCell } from 'prosemirror-tables';
40
40
  export * from 'prosemirror-transform';
41
41
  export * from 'prosemirror-view';
42
- export { createTable, addRowAfter, addRowBefore, pmAddRowAfter, pmAddRowBefore } from './table';
42
+ export { createTable, addRowAfter, addRowBefore, addColumnBefore, addColumnAfter, deleteColumn, pmAddColumnBefore, pmAddColumnAfter, pmAddRowAfter, pmAddRowBefore, pmDeleteColumn } from './table';
@@ -4,7 +4,7 @@ import { tableNodeTypes, TableMap } from 'prosemirror-tables';
4
4
  import { Decoration, DecorationSet } from 'prosemirror-view';
5
5
  import { colgroupAttr } from '../../config/constants';
6
6
  import { TableView } from './table-view';
7
- import { cellIndexes, domCellAround, otherResizeHandle, otherResizing, parentNode, parseStyle, setNodeStyle, tableColumnResizeKey as key } from './utils';
7
+ import { cellIndexes, domCellAround, otherResizeHandle, otherResizing, edgeCell, parseStyle, setNodeStyle, tableColumnResizeKey as key } from './utils';
8
8
  export function columnResizing() {
9
9
  // tslint:disable-next-line:variable-name
10
10
  var View = TableView, handleWidth = 5, cellMinWidth = 25;
@@ -91,7 +91,7 @@ function handleMouseMove(view, event, handleWidth) {
91
91
  var indexes = cellIndexes(target);
92
92
  var _a = target.getBoundingClientRect(), left = _a.left, right = _a.right;
93
93
  if (Math.abs(event.clientX - left) <= handleWidth && indexes.cellIndex > 0) {
94
- indexes.cellIndex--;
94
+ indexes.cellIndex -= target.colSpan;
95
95
  cell = edgeCell(view, event, indexes);
96
96
  }
97
97
  else if (right - event.clientX > 0 && right - event.clientX <= handleWidth) {
@@ -187,22 +187,6 @@ function handleMouseDown(view, event, cellMinWidth) {
187
187
  event.preventDefault();
188
188
  return true;
189
189
  }
190
- function edgeCell(view, event, indexes) {
191
- var found = view.posAtCoords({ left: event.clientX, top: event.clientY });
192
- if (!found) {
193
- return -1;
194
- }
195
- var $pos = view.state.doc.resolve(found.pos);
196
- var parentTable = parentNode($pos, function (n) { return n.type.spec.tableRole === 'table'; });
197
- if (parentTable === null) {
198
- return -1;
199
- }
200
- var tablePos = $pos.start(parentTable.depth);
201
- var tableNode = parentTable.node;
202
- var map = TableMap.get(tableNode);
203
- var cell = tablePos + map.map[(map.width * indexes.rowIndex) + indexes.cellIndex];
204
- return cell;
205
- }
206
190
  function draggedWidth(dragging, event, cellMinWidth) {
207
191
  var offset = event.clientX - dragging.startX;
208
192
  return Math.max(cellMinWidth, dragging.startWidth + offset);
@@ -227,8 +211,8 @@ function updateColumnWidth(view, tr, cell, _width) {
227
211
  var tableDomWidth = tableDom.style.width;
228
212
  if (tableDom && tableDomWidth && parseStyle(attrs.style).width !== tableDomWidth) {
229
213
  attrs = setNodeStyle(attrs, 'width', tableDomWidth);
230
- tr.setNodeMarkup(tablePos, null, attrs);
231
214
  }
215
+ tr.setNodeMarkup(tablePos, null, attrs);
232
216
  }
233
217
  function displayColumnWidth(view, cell, width, _cellMinWidth) {
234
218
  var $cell = view.state.doc.resolve(cell);
@@ -254,20 +238,27 @@ function handleDecorations(state, cell) {
254
238
  var decorations = [];
255
239
  var $cell = state.doc.resolve(cell);
256
240
  var table = $cell.node(-1), map = TableMap.get(table), start = $cell.start(-1);
257
- var col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan;
258
- for (var row = 0; row < map.height; row++) {
259
- var index = col + row * map.width - 1;
260
- // For positions that are have either a different cell or the end
261
- // of the table to their right, and either the top of the table or
262
- // a different cell above them, add a decoration
263
- if ((col === map.width || map.map[index] !== map.map[index + 1]) &&
264
- (row === 0 || map.map[index - 1] !== map.map[index - 1 - map.width])) {
265
- var cellPos = map.map[index];
266
- var pos = start + cellPos + table.nodeAt(cellPos).nodeSize - 1;
267
- var dom = document.createElement('div');
268
- dom.className = 'column-resize-handle';
269
- decorations.push(Decoration.widget(pos, dom));
241
+ var cellsPositions = [];
242
+ var cellPos = cell - start;
243
+ var column = -1;
244
+ for (var i = 0; i < map.height; i++) {
245
+ cellsPositions.push(map.map.slice(i * map.width, (i * map.width) + map.width));
246
+ if (column === -1) {
247
+ column = cellsPositions[i].lastIndexOf(cellPos);
270
248
  }
271
249
  }
250
+ var cells = [];
251
+ cellsPositions.forEach(function (row) {
252
+ var c = row[column];
253
+ if (row[column] !== row[column + 1]) {
254
+ cells.push(c);
255
+ }
256
+ });
257
+ cells.forEach((function (cPos) {
258
+ var pos = start + cPos + table.nodeAt(cPos).nodeSize - 1;
259
+ var dom = document.createElement('div');
260
+ dom.className = 'column-resize-handle';
261
+ decorations.push(Decoration.widget(pos, dom));
262
+ }));
272
263
  return DecorationSet.create(state.doc, decorations);
273
264
  }
@@ -1,7 +1,7 @@
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 { domCellAround, otherResizeHandle, otherResizing, parentNode, parseStyle, setNodeStyle, tableRowResizeKey as key } from './utils';
4
+ import { cellIndexes, domCellAround, otherResizeHandle, otherResizing, parseStyle, setNodeStyle, tableRowResizeKey as key, edgeCell } from './utils';
5
5
  var TableRowView = /** @class */ (function () {
6
6
  function TableRowView() {
7
7
  }
@@ -90,19 +90,20 @@ var ResizeState = /** @class */ (function () {
90
90
  function handleMouseMove(view, event, handleWidth) {
91
91
  var pluginState = key.getState(view.state);
92
92
  if (!pluginState.dragging) {
93
- var target = domCellAround(event.target), row = -1;
93
+ var target = domCellAround(event.target), cell = -1;
94
94
  if (target) {
95
- var rowDom = target.parentNode;
96
- var domRect = rowDom.getBoundingClientRect();
97
- if (Math.abs(event.clientY - domRect.top) <= handleWidth && rowDom.rowIndex > 0) {
98
- row = edgeRow(view, event, rowDom.rowIndex - 1);
95
+ var indexes = cellIndexes(target);
96
+ var _a = target.getBoundingClientRect(), top_1 = _a.top, bottom = _a.bottom;
97
+ if (Math.abs(event.clientY - top_1) <= handleWidth && indexes.rowIndex > 0) {
98
+ indexes.rowIndex -= target.rowSpan;
99
+ cell = edgeCell(view, event, indexes);
99
100
  }
100
- else if (domRect.bottom - event.clientY > 0 && domRect.bottom - event.clientY <= handleWidth) {
101
- row = edgeRow(view, event, rowDom.rowIndex);
101
+ else if (bottom - event.clientY > 0 && bottom - event.clientY <= handleWidth) {
102
+ cell = edgeCell(view, event, indexes);
102
103
  }
103
104
  }
104
- if (row !== pluginState.activeHandle) {
105
- updateHandle(view, row);
105
+ if (cell !== pluginState.activeHandle) {
106
+ updateHandle(view, cell);
106
107
  }
107
108
  }
108
109
  }
@@ -118,9 +119,9 @@ function handleMouseDown(view, event) {
118
119
  return false;
119
120
  }
120
121
  var doc = view.state.doc;
121
- var $pos = doc.resolve(pluginState.activeHandle);
122
- var row = doc.nodeAt(pluginState.activeHandle);
123
- var table = $pos.parent;
122
+ var $cell = doc.resolve(pluginState.activeHandle);
123
+ var row = $cell.parent;
124
+ var table = $cell.node(-1);
124
125
  var rowHeightStr = parseStyle(row.attrs.style).height;
125
126
  var tableHeight = parseStyle(table.attrs.style).height;
126
127
  var rowHeight = rowHeightStr ? parseFloat(rowHeightStr) : 0;
@@ -158,22 +159,6 @@ function handleMouseDown(view, event) {
158
159
  event.preventDefault();
159
160
  return true;
160
161
  }
161
- function edgeRow(view, event, rowIndex) {
162
- var found = view.posAtCoords({ left: event.clientX, top: event.clientY });
163
- if (!found) {
164
- return -1;
165
- }
166
- var $pos = view.state.doc.resolve(found.pos);
167
- var parentTable = parentNode($pos, function (n) { return n.type.spec.tableRole === 'table'; });
168
- if (parentTable === null) {
169
- return -1;
170
- }
171
- var tablePos = $pos.start(parentTable.depth);
172
- var tableNode = parentTable.node;
173
- var map = TableMap.get(tableNode);
174
- var row = tablePos + map.map[(map.width * rowIndex)] - 1;
175
- return row;
176
- }
177
162
  function draggedHeight(dragging, event) {
178
163
  var offset = event.clientY - dragging.startY;
179
164
  return dragging.startHeight.rowHeight + offset;
@@ -184,9 +169,11 @@ function updateHandle(view, value) {
184
169
  tr.setMeta(key, { setHandle: value });
185
170
  view.dispatch(tr);
186
171
  }
187
- function updateRowHeight(view, tr, rowPos) {
172
+ function updateRowHeight(view, tr, cellPos) {
188
173
  var doc = view.state.doc;
189
- var row = doc.nodeAt(rowPos);
174
+ var $cell = doc.resolve(cellPos);
175
+ var row = $cell.parent;
176
+ var rowPos = $cell.posAtIndex(0) - 1;
190
177
  var dom = view.nodeDOM(rowPos);
191
178
  var win = (dom.ownerDocument && dom.ownerDocument.defaultView) || window;
192
179
  dom.style.height = win.getComputedStyle(dom).height;
@@ -199,13 +186,14 @@ function updateRowHeight(view, tr, rowPos) {
199
186
  tr.setNodeMarkup(tablePos, null, setNodeStyle($pos.parent.attrs, 'height', tableHeight));
200
187
  }
201
188
  }
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');
189
+ function displayRowHeight(view, cellPos, height, offset, tableHeight) {
190
+ var cell = view.nodeDOM(cellPos);
191
+ var row = cell && cell.parentNode;
192
+ if (row) {
193
+ row.style.height = height + 'px';
194
+ var win = (row.ownerDocument && row.ownerDocument.defaultView) || window;
195
+ row.style.height = win.getComputedStyle(row).height;
196
+ var table = row.closest('table');
209
197
  var newHeight = (parseFloat(tableHeight) + offset) + 'px';
210
198
  var current = table && table.style.height;
211
199
  if (current && current !== newHeight) {
@@ -214,20 +202,33 @@ function displayRowHeight(view, rowPos, height, offset, tableHeight) {
214
202
  }
215
203
  }
216
204
  }
217
- function handleDecorations(state, pos) {
205
+ function handleDecorations(state, cell) {
218
206
  var decorations = [];
219
- if (typeof pos !== 'number') {
207
+ if (typeof cell !== 'number') {
220
208
  return DecorationSet.empty;
221
209
  }
222
- var $row = state.doc.resolve(pos), table = $row.parent, map = 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;
210
+ var $cell = state.doc.resolve(cell), table = $cell.node(-1), map = TableMap.get(table), start = $cell.start(-1);
211
+ var cellsPositions = [];
212
+ var cellPos = cell - start;
213
+ var rowIndex = -1;
214
+ for (var i = 0; i < map.height; i++) {
215
+ cellsPositions.push(map.map.slice(i * map.width, (i * map.width) + map.width));
216
+ if (cellsPositions[i].indexOf(cellPos) !== -1) {
217
+ rowIndex = i;
218
+ }
219
+ }
220
+ var cells = [];
221
+ cellsPositions[rowIndex].forEach(function (c, i) {
222
+ if (!cellsPositions[rowIndex + 1] || c !== cellsPositions[rowIndex + 1][i]) {
223
+ cells.push(c);
224
+ }
225
+ });
226
+ cells.forEach(function (cPos) {
227
+ var cellNode = table.nodeAt(cPos);
228
+ var widgetPos = start + cPos + (cellNode ? cellNode.nodeSize : 0) - 1;
228
229
  var dom = document.createElement('div');
229
230
  dom.className = 'row-resize-handle';
230
231
  decorations.push(Decoration.widget(widgetPos, dom));
231
- }
232
+ });
232
233
  return DecorationSet.create(state.doc, decorations);
233
234
  }
@@ -200,9 +200,7 @@ export var tableResizing = function (options) {
200
200
  var parent = parentNode(selection.$from, function (n) { return n.type === nodeType; });
201
201
  var node = parent && parent.node;
202
202
  if (node) {
203
- var tableDepth = new Array(selection.$from.depth + 1).fill(0)
204
- .findIndex(function (_, i) { return selection.$from.node(i).type.spec.tableRole === 'table'; });
205
- var pos = selection.$from.start(tableDepth) - 1;
203
+ var pos = selection.$from.start(parent.depth) - 1;
206
204
  return { node: node, pos: pos };
207
205
  }
208
206
  return null;
@@ -1,5 +1,6 @@
1
1
  import { __assign } from "tslib";
2
2
  import { PluginKey } from 'prosemirror-state';
3
+ import { TableMap } from 'prosemirror-tables';
3
4
  import { changeStylesString } from '../../utils';
4
5
  export var reAnyValue = /^.+$/;
5
6
  export var parseStyle = function (styleText) {
@@ -59,12 +60,46 @@ export function domCellAround(target) {
59
60
  }
60
61
  return target;
61
62
  }
62
- export function cellIndexes(cell) {
63
- var row = cell.parentNode;
64
- return {
65
- cellIndex: cell.cellIndex,
66
- rowIndex: row.rowIndex
63
+ function tableSpansMap(table) {
64
+ var rows = Array.from((table && table.rows) || []);
65
+ var colsCount = Array.from((rows && rows[0] && rows[0].cells) || [])
66
+ .map(function (c) { return c.colSpan; })
67
+ .reduce(function (prev, cur) { return prev + cur; }, 0);
68
+ var map = rows.map(function () { return new Array(colsCount); });
69
+ rows.forEach(function (row, r) {
70
+ var curColSpan = 0;
71
+ Array.from(row.cells).forEach(function (c) {
72
+ for (var colSp = 0; colSp < c.colSpan; colSp++) {
73
+ for (var rowSp = 0; rowSp < c.rowSpan; rowSp++) {
74
+ var ind = map[r + rowSp].findIndex(function (val, curInd) { return curInd >= curColSpan && !val; });
75
+ map[r + rowSp][ind] = c;
76
+ }
77
+ curColSpan++;
78
+ }
79
+ });
80
+ });
81
+ return map;
82
+ }
83
+ export function cellIndexes(dataCell) {
84
+ var map = tableSpansMap(dataCell.closest('table'));
85
+ var result = null;
86
+ var _loop_1 = function (r) {
87
+ var row = map[r];
88
+ row.forEach(function (cell, c) {
89
+ if (dataCell === cell) {
90
+ result = { rowIndex: r, cellIndex: c };
91
+ }
92
+ });
93
+ if (result) {
94
+ return "break";
95
+ }
67
96
  };
97
+ for (var r = 0; r < map.length; r++) {
98
+ var state_1 = _loop_1(r);
99
+ if (state_1 === "break")
100
+ break;
101
+ }
102
+ return result || { rowIndex: -1, cellIndex: -1 };
68
103
  }
69
104
  export function parentNode(pos, predicate) {
70
105
  for (var depth = pos.depth; depth > 0; depth--) {
@@ -75,3 +110,19 @@ export function parentNode(pos, predicate) {
75
110
  }
76
111
  return null;
77
112
  }
113
+ export function edgeCell(view, event, indexes) {
114
+ var found = view.posAtCoords({ left: event.clientX, top: event.clientY });
115
+ if (!found) {
116
+ return -1;
117
+ }
118
+ var $pos = view.state.doc.resolve(found.pos);
119
+ var parentTable = parentNode($pos, function (n) { return n.type.spec.tableRole === 'table'; });
120
+ if (parentTable === null) {
121
+ return -1;
122
+ }
123
+ var tablePos = $pos.start(parentTable.depth);
124
+ var tableNode = parentTable.node;
125
+ var map = TableMap.get(tableNode);
126
+ var cell = tablePos + map.map[(map.width * indexes.rowIndex) + indexes.cellIndex];
127
+ return cell;
128
+ }
package/dist/es/table.js CHANGED
@@ -1,5 +1,7 @@
1
- import { addRowAfter as pmAddRowAfter, addRowBefore as pmAddRowBefore } from 'prosemirror-tables';
2
- import { rowTypeAttr } from './config/constants';
1
+ import { __assign } from "tslib";
2
+ import { addRowAfter as pmAddRowAfter, addRowBefore as pmAddRowBefore, addColumnBefore as pmAddColumnBefore, addColumnAfter as pmAddColumnAfter, deleteColumn as pmDeleteColumn, TableMap } from 'prosemirror-tables';
3
+ import { colgroupAttr, rowTypeAttr } from './config/constants';
4
+ import { parseStrColgroup } from './config/schema';
3
5
  /**
4
6
  * Creates a table.
5
7
  * @returns Node
@@ -17,11 +19,14 @@ export var createTable = function (nodes, rows, columns) {
17
19
  }
18
20
  return table.createAndFill(undefined, tableRows);
19
21
  };
22
+ var reTable = /^table$/;
23
+ var reRow = /^table_row$/;
24
+ var reCell = /^table_cell|table_header$/;
20
25
  var closest = function (selection, name) {
21
26
  var pos = selection.$head;
22
27
  for (var i = pos.depth; i > 0; i--) {
23
28
  var node = pos.node(i);
24
- if (node.type.name === name) {
29
+ if (name.test(node.type.name)) {
25
30
  return {
26
31
  pos: pos.before(i),
27
32
  node: node
@@ -33,8 +38,8 @@ var closest = function (selection, name) {
33
38
  export var addRowBefore = function (state, dispatch) {
34
39
  var cmdDispatch = dispatch && (function (tr) {
35
40
  var _a;
36
- var row = closest(tr.selection, 'table_row');
37
- var table = closest(tr.selection, 'table');
41
+ var row = closest(tr.selection, reRow);
42
+ var table = closest(tr.selection, reTable);
38
43
  if (row && table && row.node.attrs[rowTypeAttr]) {
39
44
  var index = 0;
40
45
  for (var i = 0; i < table.node.nodeSize; i++) {
@@ -54,7 +59,7 @@ export var addRowBefore = function (state, dispatch) {
54
59
  export var addRowAfter = function (state, dispatch) {
55
60
  var cmdDispatch = dispatch && (function (tr) {
56
61
  var _a;
57
- var row = closest(tr.selection, 'table_row');
62
+ var row = closest(tr.selection, reRow);
58
63
  if (row && row.node.attrs[rowTypeAttr]) {
59
64
  var from = row.pos + row.node.nodeSize;
60
65
  tr.setNodeMarkup(from, undefined, (_a = {}, _a[rowTypeAttr] = row.node.attrs[rowTypeAttr], _a));
@@ -63,4 +68,64 @@ export var addRowAfter = function (state, dispatch) {
63
68
  });
64
69
  return pmAddRowAfter(state, cmdDispatch);
65
70
  };
66
- export { pmAddRowBefore, pmAddRowAfter };
71
+ var columnIndex = function (table, selection) {
72
+ if (!table) {
73
+ return -1;
74
+ }
75
+ var map = TableMap.get(table.node);
76
+ var tableCell = closest(selection, reCell);
77
+ var idx = map.map.indexOf(tableCell.pos - table.pos - 1);
78
+ var colIndex = -1;
79
+ if (idx !== -1) {
80
+ colIndex = idx % map.width;
81
+ }
82
+ return colIndex;
83
+ };
84
+ var addCol = function (tr, table, to) {
85
+ var _a;
86
+ var colIndex = columnIndex(table, tr.selection);
87
+ var colgroup = parseStrColgroup(table.node.attrs[colgroupAttr]);
88
+ colgroup.insertBefore(colgroup.ownerDocument.createElement('col'), colgroup.children[colIndex + to]);
89
+ tr.setNodeMarkup(table.pos, null, __assign(__assign({}, table.node.attrs), (_a = {}, _a[colgroupAttr] = colgroup.outerHTML, _a)));
90
+ };
91
+ var deleteCol = function (tr, table, colIndex) {
92
+ var _a;
93
+ var colgroup = parseStrColgroup(table.node.attrs[colgroupAttr]);
94
+ colgroup.removeChild(colgroup.children[colIndex]);
95
+ tr.setNodeMarkup(table.pos, null, __assign(__assign({}, table.node.attrs), (_a = {}, _a[colgroupAttr] = colgroup.outerHTML, _a)));
96
+ };
97
+ export var addColumnBefore = function (state, dispatch) {
98
+ var cmdDispatch = dispatch && (function (tr) {
99
+ var table = closest(tr.selection, reTable);
100
+ if (!table.node.attrs[colgroupAttr]) {
101
+ return dispatch(tr);
102
+ }
103
+ addCol(tr, table, -1);
104
+ return dispatch(tr);
105
+ });
106
+ return pmAddColumnBefore(state, cmdDispatch);
107
+ };
108
+ export var addColumnAfter = function (state, dispatch) {
109
+ var cmdDispatch = dispatch && (function (tr) {
110
+ var table = closest(tr.selection, reTable);
111
+ if (!table.node.attrs[colgroupAttr]) {
112
+ return dispatch(tr);
113
+ }
114
+ addCol(tr, table, 1);
115
+ return dispatch(tr);
116
+ });
117
+ return pmAddColumnAfter(state, cmdDispatch);
118
+ };
119
+ export var deleteColumn = function (state, dispatch) {
120
+ var colIndex = columnIndex(closest(state.selection, reTable), state.selection);
121
+ var cmdDispatch = dispatch && (function (tr) {
122
+ var table = closest(tr.selection, reTable);
123
+ if (!table.node.attrs[colgroupAttr]) {
124
+ return dispatch(tr);
125
+ }
126
+ deleteCol(tr, table, colIndex);
127
+ return dispatch(tr);
128
+ });
129
+ return pmDeleteColumn(state, cmdDispatch);
130
+ };
131
+ export { pmAddRowBefore, pmAddRowAfter, pmAddColumnBefore, pmAddColumnAfter, pmDeleteColumn };
@@ -36,7 +36,7 @@ export * from 'prosemirror-model';
36
36
  export * from 'prosemirror-schema-list';
37
37
  export * from 'prosemirror-state';
38
38
  // Fixes an error related to setting over the addRowAfter and addRowBefore exports from the PM tables module
39
- export { TableMap, tableEditing, tableEditingKey, tableNodeTypes, tableNodes, fixTables, fixTablesKey, isInTable, deleteTable, inSameTable, CellSelection, selectedRect, selectionCell, setCellAttr, goToNextCell, toggleHeader, toggleHeaderCell, toggleHeaderColumn, toggleHeaderRow, splitCell, splitCellWithType, mergeCells, deleteColumn, deleteRow, rowIsHeader, addRow, addColSpan, addColumn, addColumnAfter, addColumnBefore, colCount, columnIsHeader, columnResizing, columnResizingPluginKey, updateColumnsOnResize, cellAround, findCell, removeColSpan, moveCellForward, nextCell } from 'prosemirror-tables';
39
+ export { TableMap, tableEditing, tableEditingKey, tableNodeTypes, tableNodes, fixTables, fixTablesKey, isInTable, deleteTable, inSameTable, CellSelection, selectedRect, selectionCell, setCellAttr, goToNextCell, toggleHeader, toggleHeaderCell, toggleHeaderColumn, toggleHeaderRow, splitCell, splitCellWithType, mergeCells, deleteRow, rowIsHeader, addRow, addColSpan, addColumn, colCount, columnIsHeader, columnResizing, columnResizingPluginKey, updateColumnsOnResize, cellAround, findCell, removeColSpan, moveCellForward, nextCell } from 'prosemirror-tables';
40
40
  export * from 'prosemirror-transform';
41
41
  export * from 'prosemirror-view';
42
- export { createTable, addRowAfter, addRowBefore, pmAddRowAfter, pmAddRowBefore } from './table';
42
+ export { createTable, addRowAfter, addRowBefore, addColumnBefore, addColumnAfter, deleteColumn, pmAddColumnBefore, pmAddColumnAfter, pmAddRowAfter, pmAddRowBefore, pmDeleteColumn } from './table';
@@ -3,7 +3,7 @@ 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 { cellIndexes, domCellAround, otherResizeHandle, otherResizing, parentNode, parseStyle, setNodeStyle, tableColumnResizeKey as key } from './utils';
6
+ import { cellIndexes, domCellAround, otherResizeHandle, otherResizing, edgeCell, parseStyle, setNodeStyle, tableColumnResizeKey as key } from './utils';
7
7
  export function columnResizing() {
8
8
  // tslint:disable-next-line:variable-name
9
9
  const View = TableView, handleWidth = 5, cellMinWidth = 25;
@@ -89,7 +89,7 @@ function handleMouseMove(view, event, handleWidth) {
89
89
  const indexes = cellIndexes(target);
90
90
  let { left, right } = target.getBoundingClientRect();
91
91
  if (Math.abs(event.clientX - left) <= handleWidth && indexes.cellIndex > 0) {
92
- indexes.cellIndex--;
92
+ indexes.cellIndex -= target.colSpan;
93
93
  cell = edgeCell(view, event, indexes);
94
94
  }
95
95
  else if (right - event.clientX > 0 && right - event.clientX <= handleWidth) {
@@ -184,22 +184,6 @@ function handleMouseDown(view, event, cellMinWidth) {
184
184
  event.preventDefault();
185
185
  return true;
186
186
  }
187
- function edgeCell(view, event, indexes) {
188
- let found = view.posAtCoords({ left: event.clientX, top: event.clientY });
189
- if (!found) {
190
- return -1;
191
- }
192
- let $pos = view.state.doc.resolve(found.pos);
193
- let parentTable = parentNode($pos, n => n.type.spec.tableRole === 'table');
194
- if (parentTable === null) {
195
- return -1;
196
- }
197
- let tablePos = $pos.start(parentTable.depth);
198
- const tableNode = parentTable.node;
199
- const map = TableMap.get(tableNode);
200
- const cell = tablePos + map.map[(map.width * indexes.rowIndex) + indexes.cellIndex];
201
- return cell;
202
- }
203
187
  function draggedWidth(dragging, event, cellMinWidth) {
204
188
  let offset = event.clientX - dragging.startX;
205
189
  return Math.max(cellMinWidth, dragging.startWidth + offset);
@@ -223,8 +207,8 @@ function updateColumnWidth(view, tr, cell, _width) {
223
207
  const tableDomWidth = tableDom.style.width;
224
208
  if (tableDom && tableDomWidth && parseStyle(attrs.style).width !== tableDomWidth) {
225
209
  attrs = setNodeStyle(attrs, 'width', tableDomWidth);
226
- tr.setNodeMarkup(tablePos, null, attrs);
227
210
  }
211
+ tr.setNodeMarkup(tablePos, null, attrs);
228
212
  }
229
213
  function displayColumnWidth(view, cell, width, _cellMinWidth) {
230
214
  let $cell = view.state.doc.resolve(cell);
@@ -250,20 +234,27 @@ function handleDecorations(state, cell) {
250
234
  let decorations = [];
251
235
  let $cell = state.doc.resolve(cell);
252
236
  let table = $cell.node(-1), map = TableMap.get(table), start = $cell.start(-1);
253
- let col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan;
254
- for (let row = 0; row < map.height; row++) {
255
- let index = col + row * map.width - 1;
256
- // For positions that are have either a different cell or the end
257
- // of the table to their right, and either the top of the table or
258
- // a different cell above them, add a decoration
259
- if ((col === map.width || map.map[index] !== map.map[index + 1]) &&
260
- (row === 0 || map.map[index - 1] !== map.map[index - 1 - map.width])) {
261
- let cellPos = map.map[index];
262
- let pos = start + cellPos + table.nodeAt(cellPos).nodeSize - 1;
263
- let dom = document.createElement('div');
264
- dom.className = 'column-resize-handle';
265
- decorations.push(Decoration.widget(pos, dom));
237
+ const cellsPositions = [];
238
+ const cellPos = cell - start;
239
+ let column = -1;
240
+ for (let i = 0; i < map.height; i++) {
241
+ cellsPositions.push(map.map.slice(i * map.width, (i * map.width) + map.width));
242
+ if (column === -1) {
243
+ column = cellsPositions[i].lastIndexOf(cellPos);
266
244
  }
267
245
  }
246
+ const cells = [];
247
+ cellsPositions.forEach((row) => {
248
+ let c = row[column];
249
+ if (row[column] !== row[column + 1]) {
250
+ cells.push(c);
251
+ }
252
+ });
253
+ cells.forEach((cPos => {
254
+ let pos = start + cPos + table.nodeAt(cPos).nodeSize - 1;
255
+ let dom = document.createElement('div');
256
+ dom.className = 'column-resize-handle';
257
+ decorations.push(Decoration.widget(pos, dom));
258
+ }));
268
259
  return DecorationSet.create(state.doc, decorations);
269
260
  }