@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
@@ -1,2 +1,7 @@
1
1
  export var rowTypeAttr = 'k-parent-node';
2
2
  export var colgroupAttr = 'k-colgroup-data';
3
+ export var resizableAttr = 'resizable-node';
4
+ export var resizableWrap = 'k-editor-resize-wrap-element';
5
+ export var resizeHandle = 'k-editor-resize-handle';
6
+ export var dataResizeDirTable = 'data-direction';
7
+ export var dataResizeDirImage = 'data-direction-image';
@@ -2,7 +2,7 @@ import * as tslib_1 from "tslib";
2
2
  import { Schema } from 'prosemirror-model';
3
3
  import { tableNodes } from 'prosemirror-tables';
4
4
  import { domToPmDoc, htmlToFragment, pmDocToFragment } from '../source';
5
- import { rowTypeAttr, colgroupAttr } from './constants';
5
+ import { rowTypeAttr, colgroupAttr, resizableAttr } from './constants';
6
6
  var hole = 0;
7
7
  var blockquoteDOM = ['blockquote', hole], hrDOM = ['hr'], preDOM = ['pre', ['code', hole]];
8
8
  var olDOM = ['ol', 0], ulDOM = ['ul', 0], liDOM = ['li', 0];
@@ -109,18 +109,22 @@ var shouldSkipColgroup = function (node) {
109
109
  }
110
110
  return shouldSkip;
111
111
  };
112
+ export var parseStrColgroup = function (colgroup) {
113
+ var doc = domToPmDoc(htmlToFragment(colgroup), colgroupSchema, { preserveWhitespace: false });
114
+ var fragment = pmDocToFragment(doc);
115
+ var colgroupEl = fragment.firstChild;
116
+ return colgroupEl;
117
+ };
112
118
  var tNodes = tableNodes({ tableGroup: 'block', cellContent: 'block+', cellAttributes: cellAttributes });
113
119
  tNodes.table_row.attrs = tslib_1.__assign({}, tNodes.table_row.attrs, defaultAttrs([rowTypeAttr, 'style', 'class', 'id']));
114
120
  tNodes.table_row.toDOM = function (node) { return ['tr', pmAttributes(node.attrs), 0]; };
115
121
  tNodes.table_row.parseDOM = [{ tag: 'tr', getAttrs: domAttributes }];
116
- tNodes.table.attrs = tslib_1.__assign({}, tNodes.table.attrs, defaultAttrs(['style', 'class', 'id', colgroupAttr]));
122
+ tNodes.table.attrs = tslib_1.__assign({}, tNodes.table.attrs, defaultAttrs(['style', 'class', 'id', colgroupAttr, resizableAttr]));
117
123
  tNodes.table.toDOM = function (node) {
118
124
  var tableAttrs = hasAttrs(node.attrs) ? pmAttributes(node.attrs, colgroupAttr) : {};
119
125
  var colgroup = null;
120
126
  if (node.attrs[colgroupAttr] && !shouldSkipColgroup(node)) {
121
- var doc = domToPmDoc(htmlToFragment(node.attrs[colgroupAttr]), colgroupSchema, { preserveWhitespace: false });
122
- var fragment = pmDocToFragment(doc);
123
- var colgroupEl = fragment.firstChild;
127
+ var colgroupEl = parseStrColgroup(node.attrs[colgroupAttr]);
124
128
  if (colgroupEl) {
125
129
  var cols = Array.from(colgroupEl.children).map(function (c) { return ['col', domAttributes(c)]; });
126
130
  colgroup = [
package/dist/es/main.js CHANGED
@@ -24,6 +24,7 @@ export { spacesFix } from './plugins/spaces-fix';
24
24
  export { textHighlight, textHighlightKey } from './plugins/highlight';
25
25
  export { imageResizing, imageResizeKey } from './plugins/image-resize';
26
26
  export { caretColor, caretColorKey } from './plugins/caret-color';
27
+ export { tableResizing } from './plugins/table-resize';
27
28
  // ProseMirror re-exports
28
29
  export * from 'prosemirror-commands';
29
30
  export * from 'prosemirror-dropcursor';
@@ -1,19 +1,10 @@
1
1
  import * as tslib_1 from "tslib";
2
2
  import { NodeSelection, Plugin, PluginKey } from "prosemirror-state";
3
3
  import { Decoration, DecorationSet } from "prosemirror-view";
4
+ import { dataResizeDirImage, resizeHandle } from "../config/constants";
4
5
  import { changeStylesString } from "../utils";
6
+ import { directions, handles } from './resize-utils';
5
7
  export var imageResizeKey = new PluginKey('image-resize');
6
- var directions = {
7
- 'southeast': { x: 1, y: 1 },
8
- 'east': { x: 1, y: 0 },
9
- 'south': { x: 0, y: 1 },
10
- 'north': { x: 0, y: -1 },
11
- 'west': { x: -1, y: 0 },
12
- 'southwest': { x: -1, y: 1 },
13
- 'northwest': { x: -1, y: -1 },
14
- 'northeast': { x: 1, y: -1 } // top right
15
- };
16
- var handles = Object.keys(directions);
17
8
  var setSize = function (domNode, sizeType, value) {
18
9
  domNode.style[sizeType] = value + 'px';
19
10
  };
@@ -109,7 +100,7 @@ var handleMouseUp = function (view) {
109
100
  };
110
101
  var handleMouseDown = function (view, event, options) {
111
102
  var target = event.target;
112
- var activeHandle = target.getAttribute('data-direction');
103
+ var activeHandle = target.getAttribute(dataResizeDirImage);
113
104
  if (!activeHandle) {
114
105
  return false;
115
106
  }
@@ -221,8 +212,8 @@ export var imageResizing = function (options) {
221
212
  wrapper.style.left = rect.left + 'px';
222
213
  for (var i = 0; i < handles.length; i++) {
223
214
  var dom = document.createElement('div');
224
- dom.className = 'k-editor-resize-handle ' + handles[i];
225
- dom.setAttribute('data-direction', handles[i]);
215
+ dom.className = resizeHandle + ' ' + handles[i];
216
+ dom.setAttribute(dataResizeDirImage, handles[i]);
226
217
  wrapper.appendChild(dom);
227
218
  }
228
219
  return DecorationSet.create(state.doc, [Decoration.widget(state.selection.from + 1, wrapper)]);
@@ -0,0 +1,11 @@
1
+ export var directions = {
2
+ 'southeast': { x: 1, y: 1 },
3
+ 'east': { x: 1, y: 0 },
4
+ 'south': { x: 0, y: 1 },
5
+ 'north': { x: 0, y: -1 },
6
+ 'west': { x: -1, y: 0 },
7
+ 'southwest': { x: -1, y: 1 },
8
+ 'northwest': { x: -1, y: -1 },
9
+ 'northeast': { x: 1, y: -1 } // top right
10
+ };
11
+ export var handles = Object.keys(directions);
@@ -0,0 +1,273 @@
1
+ import * as tslib_1 from "tslib";
2
+ import { Plugin } from 'prosemirror-state';
3
+ import { tableNodeTypes, TableMap } from 'prosemirror-tables';
4
+ import { Decoration, DecorationSet } from 'prosemirror-view';
5
+ import { colgroupAttr } from '../../config/constants';
6
+ import { TableView } from './table-view';
7
+ import { cellIndexes, domCellAround, otherResizeHandle, otherResizing, parentNode, parseStyle, setNodeStyle, tableColumnResizing as key } from './utils';
8
+ export function columnResizing() {
9
+ // tslint:disable-next-line:variable-name
10
+ var View = TableView, handleWidth = 5, cellMinWidth = 25;
11
+ var plugin = new Plugin({
12
+ key: key,
13
+ state: {
14
+ init: function (_, state) {
15
+ this.spec.props.nodeViews[tableNodeTypes(state.schema).table.name] = function (node, view) { return new View(node, view); };
16
+ return new ResizeState(-1, null);
17
+ },
18
+ apply: function (tr, prev) {
19
+ return prev.apply(tr);
20
+ }
21
+ },
22
+ props: {
23
+ attributes: function (state) {
24
+ if (otherResizeHandle(key, state)) {
25
+ return null;
26
+ }
27
+ var pluginState = key.getState(state);
28
+ return pluginState.activeHandle > -1 ? { class: 'resize-cursor' } : null;
29
+ },
30
+ handleDOMEvents: {
31
+ mousemove: function (view, event) {
32
+ if (!otherResizing(key, view.state)) {
33
+ handleMouseMove(view, event, handleWidth);
34
+ }
35
+ return false;
36
+ },
37
+ mouseleave: function (view) {
38
+ handleMouseLeave(view);
39
+ return false;
40
+ },
41
+ mousedown: function (view, event) {
42
+ return handleMouseDown(view, event, cellMinWidth);
43
+ }
44
+ },
45
+ decorations: function (state) {
46
+ if (!otherResizing(key, state)) {
47
+ var pluginState = key.getState(state);
48
+ if (pluginState.activeHandle > -1) {
49
+ return handleDecorations(state, pluginState.activeHandle);
50
+ }
51
+ }
52
+ return DecorationSet.empty;
53
+ },
54
+ nodeViews: {}
55
+ }
56
+ });
57
+ return plugin;
58
+ }
59
+ function pointsAtCell($pos) {
60
+ return Boolean($pos.parent.type.spec.tableRole === 'row' && $pos.nodeAfter);
61
+ }
62
+ var ResizeState = /** @class */ (function () {
63
+ function ResizeState(activeHandle, dragging) {
64
+ this.activeHandle = activeHandle;
65
+ this.dragging = dragging;
66
+ }
67
+ ResizeState.prototype.apply = function (tr) {
68
+ var state = this, action = tr.getMeta(key);
69
+ if (action && action.setHandle != null) {
70
+ return new ResizeState(action.setHandle, null);
71
+ }
72
+ if (action && action.setDragging !== undefined) {
73
+ return new ResizeState(state.activeHandle, action.setDragging);
74
+ }
75
+ if (state.activeHandle > -1 && tr.docChanged) {
76
+ var handle = tr.mapping.map(state.activeHandle, -1);
77
+ if (!pointsAtCell(tr.doc.resolve(handle))) {
78
+ handle = -1;
79
+ }
80
+ state = new ResizeState(handle, state.dragging);
81
+ }
82
+ return state;
83
+ };
84
+ return ResizeState;
85
+ }());
86
+ function handleMouseMove(view, event, handleWidth) {
87
+ var pluginState = key.getState(view.state);
88
+ if (!pluginState.dragging) {
89
+ var target = domCellAround(event.target), cell = -1;
90
+ if (target) {
91
+ var indexes = cellIndexes(target);
92
+ var _a = target.getBoundingClientRect(), left = _a.left, right = _a.right;
93
+ if (Math.abs(event.clientX - left) <= handleWidth && indexes.cellIndex > 0) {
94
+ indexes.cellIndex--;
95
+ cell = edgeCell(view, event, indexes);
96
+ }
97
+ else if (right - event.clientX > 0 && right - event.clientX <= handleWidth) {
98
+ cell = edgeCell(view, event, indexes);
99
+ }
100
+ }
101
+ if (cell !== pluginState.activeHandle) {
102
+ updateHandle(view, cell);
103
+ }
104
+ }
105
+ }
106
+ function handleMouseLeave(view) {
107
+ var pluginState = key.getState(view.state);
108
+ if (pluginState.activeHandle > -1 && !pluginState.dragging) {
109
+ updateHandle(view, -1);
110
+ }
111
+ }
112
+ function handleMouseDown(view, event, cellMinWidth) {
113
+ var _a;
114
+ var pluginState = key.getState(view.state);
115
+ if (pluginState.activeHandle === -1 || pluginState.dragging) {
116
+ return false;
117
+ }
118
+ var $cell = view.state.doc.resolve(pluginState.activeHandle);
119
+ var row = $cell.parent;
120
+ var cellIndex = $cell.index();
121
+ var colSpan = 0;
122
+ for (var i = 0; i <= cellIndex; i++) {
123
+ colSpan += row.child(i).attrs.colspan;
124
+ }
125
+ var tableNode = $cell.node($cell.depth - 1);
126
+ var dom = view.domAtPos(pluginState.activeHandle);
127
+ var domCell = dom.node.childNodes[dom.offset];
128
+ var tableDom = domCell.closest('table');
129
+ var col, tableAttrs;
130
+ if (tableNode.attrs[colgroupAttr]) {
131
+ var colgroup = tableDom.firstChild;
132
+ col = colgroup.children[colSpan - 1];
133
+ if (!col.style.width) {
134
+ col.style.width = col.offsetWidth + 'px';
135
+ }
136
+ }
137
+ else {
138
+ var total = 0;
139
+ for (var i = 0; i < row.childCount; i++) {
140
+ total += row.child(i).attrs.colspan;
141
+ }
142
+ var colgroup = document.createElement('colgroup');
143
+ var cols = new Array(total);
144
+ for (var i = 0; i < total; i++) {
145
+ cols[i] = document.createElement('col');
146
+ colgroup.appendChild(cols[i]);
147
+ }
148
+ tableDom.insertBefore(colgroup, tableDom.firstChild);
149
+ col = cols[cellIndex];
150
+ col.style.width = col.offsetWidth + 'px';
151
+ tableAttrs = tslib_1.__assign({}, tableNode.attrs, (_a = {}, _a[colgroupAttr] = '<colgroup>' + cols.reduce(function (acc, cur) { return acc + cur.outerHTML; }, '') + '</colgroup>', _a));
152
+ }
153
+ var width = parseFloat(col.style.width);
154
+ var tr = view.state.tr.setMeta(key, { setDragging: { startX: event.clientX, startWidth: width } });
155
+ if (!tableDom.style.width) {
156
+ var widths = Array.from(col.parentNode.children).map(function (c) { return c.style.width; });
157
+ if (widths.every(Boolean)) {
158
+ var sum = widths.reduce(function (acc, cur) { return acc + parseFloat(cur); }, 0);
159
+ tableAttrs = setNodeStyle(tableAttrs || tableNode.attrs, 'width', sum + 'px');
160
+ }
161
+ }
162
+ if (tableAttrs) {
163
+ var tablePos = $cell.posAtIndex(0, $cell.depth - 1) - 1;
164
+ tr.setNodeMarkup(tablePos, null, tableAttrs);
165
+ }
166
+ view.dispatch(tr);
167
+ function finish(ev) {
168
+ ev.view.removeEventListener('mouseup', finish);
169
+ ev.view.removeEventListener('mousemove', move);
170
+ var curPluginState = key.getState(view.state);
171
+ if (curPluginState.dragging) {
172
+ updateColumnWidth(view, curPluginState.activeHandle, draggedWidth(curPluginState.dragging, ev, cellMinWidth));
173
+ view.dispatch(view.state.tr.setMeta(key, { setDragging: null }));
174
+ }
175
+ }
176
+ function move(ev) {
177
+ if (!ev.which) {
178
+ return finish(ev);
179
+ }
180
+ var curPluginState = key.getState(view.state);
181
+ var dragged = draggedWidth(curPluginState.dragging, ev, cellMinWidth);
182
+ displayColumnWidth(view, curPluginState.activeHandle, dragged, cellMinWidth);
183
+ }
184
+ event.view.addEventListener('mouseup', finish);
185
+ event.view.addEventListener('mousemove', move);
186
+ event.preventDefault();
187
+ return true;
188
+ }
189
+ function edgeCell(view, event, indexes) {
190
+ var found = view.posAtCoords({ left: event.clientX, top: event.clientY });
191
+ if (!found) {
192
+ return -1;
193
+ }
194
+ var $pos = view.state.doc.resolve(found.pos);
195
+ var parentTable = parentNode($pos, function (n) { return n.type.spec.tableRole === 'table'; });
196
+ if (parentTable === null) {
197
+ return -1;
198
+ }
199
+ var tablePos = $pos.start(parentTable.depth);
200
+ var tableNode = parentTable.node;
201
+ var map = TableMap.get(tableNode);
202
+ var cell = tablePos + map.map[(map.width * indexes.rowIndex) + indexes.cellIndex];
203
+ return cell;
204
+ }
205
+ function draggedWidth(dragging, event, cellMinWidth) {
206
+ var offset = event.clientX - dragging.startX;
207
+ return Math.max(cellMinWidth, dragging.startWidth + offset);
208
+ }
209
+ function updateHandle(view, value) {
210
+ view.dispatch(view.state.tr.setMeta(key, { setHandle: value }));
211
+ }
212
+ function updateColumnWidth(view, cell, _width) {
213
+ var _a;
214
+ var $cell = view.state.doc.resolve(cell);
215
+ var tableNode = $cell.node(-1), start = $cell.start(-1);
216
+ var tr = view.state.tr;
217
+ var tablePos = $cell.posAtIndex(0, $cell.depth - 1) - 1;
218
+ var tableDom = view.nodeDOM(start).closest('table');
219
+ var attrs = tableNode.attrs;
220
+ if (tableNode && attrs[colgroupAttr]) {
221
+ var colgroup = tableDom.firstChild;
222
+ attrs = tslib_1.__assign({}, attrs, (_a = {}, _a[colgroupAttr] = colgroup.outerHTML, _a));
223
+ }
224
+ var tableDomWidth = tableDom.style.width;
225
+ if (tableDom && tableDomWidth && parseStyle(attrs.style).width !== tableDomWidth) {
226
+ attrs = setNodeStyle(attrs, 'width', tableDomWidth);
227
+ tr.setNodeMarkup(tablePos, null, attrs);
228
+ }
229
+ if (tr.docChanged) {
230
+ view.dispatch(tr);
231
+ }
232
+ }
233
+ function displayColumnWidth(view, cell, width, _cellMinWidth) {
234
+ var $cell = view.state.doc.resolve(cell);
235
+ var table = $cell.node(-1), start = $cell.start(-1);
236
+ var col = TableMap.get(table).colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;
237
+ var dom = view.domAtPos($cell.start(-1)).node;
238
+ if (dom.nodeName !== 'TABLE') {
239
+ dom = dom.closest('table');
240
+ }
241
+ var tableDom = dom;
242
+ var colgroup = tableDom.firstChild;
243
+ var cols = Array.from(colgroup.children);
244
+ cols[col].style.width = width + 'px';
245
+ if (tableDom.style.width) {
246
+ var widths = cols.map(function (c) { return c.style.width; });
247
+ if (widths.every(Boolean)) {
248
+ var sum = widths.reduce(function (acc, cur) { return acc + parseFloat(cur); }, 0);
249
+ tableDom.style.width = sum + 'px';
250
+ }
251
+ }
252
+ }
253
+ function handleDecorations(state, cell) {
254
+ var decorations = [];
255
+ var $cell = state.doc.resolve(cell);
256
+ 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));
270
+ }
271
+ }
272
+ return DecorationSet.create(state.doc, decorations);
273
+ }
@@ -0,0 +1,8 @@
1
+ import { columnResizing } from './column-resize';
2
+ import { tableResizing as tableResize } from './table-resize';
3
+ import { rowResizing } from './row-resize';
4
+ export var tableResizing = function () { return [
5
+ tableResize(),
6
+ columnResizing(),
7
+ rowResizing()
8
+ ]; };
@@ -0,0 +1,230 @@
1
+ import { Plugin } from 'prosemirror-state';
2
+ import { TableMap, tableNodeTypes } from 'prosemirror-tables';
3
+ import { Decoration, DecorationSet } from 'prosemirror-view';
4
+ import { domCellAround, otherResizeHandle, otherResizing, parentNode, parseStyle, setNodeStyle, tableRowResizing as key } from './utils';
5
+ var TableRowView = /** @class */ (function () {
6
+ function TableRowView() {
7
+ }
8
+ TableRowView.prototype.ignoreMutation = function (record) {
9
+ return record.type === 'attributes' && record.attributeName === 'style' && record.target.nodeName === 'TR';
10
+ };
11
+ return TableRowView;
12
+ }());
13
+ export function rowResizing() {
14
+ var handleWidth = 5;
15
+ var plugin = new Plugin({
16
+ key: key,
17
+ state: {
18
+ init: function (_, state) {
19
+ this.spec.props.nodeViews[tableNodeTypes(state.schema).row.name] = function (_node, _view) { return new TableRowView(); };
20
+ return new ResizeState(-1, null);
21
+ },
22
+ apply: function (tr, prev) {
23
+ return prev.apply(tr);
24
+ }
25
+ },
26
+ props: {
27
+ attributes: function (state) {
28
+ if (otherResizeHandle(key, state)) {
29
+ return null;
30
+ }
31
+ var pluginState = key.getState(state);
32
+ return pluginState.activeHandle > -1 ? { class: 'resize-cursor-vertical' } : null;
33
+ },
34
+ handleDOMEvents: {
35
+ mousemove: function (view, event) {
36
+ if (!otherResizing(key, view.state)) {
37
+ handleMouseMove(view, event, handleWidth);
38
+ }
39
+ return false;
40
+ },
41
+ mouseleave: function (view) {
42
+ handleMouseLeave(view);
43
+ return false;
44
+ },
45
+ mousedown: function (view, event) {
46
+ return handleMouseDown(view, event);
47
+ }
48
+ },
49
+ decorations: function (state) {
50
+ if (otherResizing(key, state)) {
51
+ return DecorationSet.empty;
52
+ }
53
+ var pluginState = key.getState(state);
54
+ if (pluginState.activeHandle > -1) {
55
+ return handleDecorations(state, pluginState.activeHandle);
56
+ }
57
+ },
58
+ nodeViews: {}
59
+ }
60
+ });
61
+ return plugin;
62
+ }
63
+ function pointsAtCell($pos) {
64
+ return $pos.parent.type.spec.tableRole === 'row' && $pos.nodeAfter;
65
+ }
66
+ var ResizeState = /** @class */ (function () {
67
+ function ResizeState(activeHandle, dragging) {
68
+ this.activeHandle = activeHandle;
69
+ this.dragging = dragging;
70
+ }
71
+ ResizeState.prototype.apply = function (tr) {
72
+ var state = this, action = tr.getMeta(key);
73
+ if (action && action.setHandle != null) {
74
+ return new ResizeState(action.setHandle, null);
75
+ }
76
+ if (action && action.setDragging !== undefined) {
77
+ return new ResizeState(state.activeHandle, action.setDragging);
78
+ }
79
+ if (state.activeHandle > -1) {
80
+ var handle = tr.mapping.map(state.activeHandle, -1);
81
+ if (!pointsAtCell(tr.doc.resolve(handle))) {
82
+ handle = null;
83
+ }
84
+ state = new ResizeState(handle, state.dragging);
85
+ }
86
+ return state;
87
+ };
88
+ return ResizeState;
89
+ }());
90
+ function handleMouseMove(view, event, handleWidth) {
91
+ var pluginState = key.getState(view.state);
92
+ if (!pluginState.dragging) {
93
+ var target = domCellAround(event.target), row = -1;
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);
99
+ }
100
+ else if (domRect.bottom - event.clientY > 0 && domRect.bottom - event.clientY <= handleWidth) {
101
+ row = edgeRow(view, event, rowDom.rowIndex);
102
+ }
103
+ }
104
+ if (row !== pluginState.activeHandle) {
105
+ updateHandle(view, row);
106
+ }
107
+ }
108
+ }
109
+ function handleMouseLeave(view) {
110
+ var pluginState = key.getState(view.state);
111
+ if (pluginState.activeHandle > -1 && !pluginState.dragging) {
112
+ updateHandle(view, -1);
113
+ }
114
+ }
115
+ function handleMouseDown(view, event) {
116
+ var pluginState = key.getState(view.state);
117
+ if (pluginState.activeHandle === -1 || pluginState.dragging) {
118
+ return false;
119
+ }
120
+ var doc = view.state.doc;
121
+ var $pos = doc.resolve(pluginState.activeHandle);
122
+ var row = doc.nodeAt(pluginState.activeHandle);
123
+ var table = $pos.parent;
124
+ var rowHeightStr = parseStyle(row.attrs.style).height;
125
+ var tableHeight = parseStyle(table.attrs.style).height;
126
+ var rowHeight = rowHeightStr ? parseFloat(rowHeightStr) : 0;
127
+ if (!rowHeightStr) {
128
+ var tr = view.nodeDOM(pluginState.activeHandle);
129
+ rowHeight = tr.offsetHeight;
130
+ }
131
+ view.dispatch(view.state.tr.setMeta(key, {
132
+ setDragging: {
133
+ startY: event.clientY,
134
+ startHeight: { rowHeight: rowHeight, tableHeight: tableHeight }
135
+ }
136
+ }));
137
+ function finish(ev) {
138
+ ev.view.removeEventListener('mouseup', finish);
139
+ ev.view.removeEventListener('mousemove', move);
140
+ var curPluginState = key.getState(view.state);
141
+ if (curPluginState.dragging) {
142
+ var tr = view.state.tr.setMeta(key, { setDragging: null });
143
+ updateRowHeight(view, tr, curPluginState.activeHandle);
144
+ view.dispatch(tr);
145
+ }
146
+ }
147
+ function move(ev) {
148
+ if (!ev.which) {
149
+ return finish(ev);
150
+ }
151
+ var curPluginState = key.getState(view.state);
152
+ var dragged = draggedHeight(curPluginState.dragging, ev);
153
+ var offset = ev.clientY - curPluginState.dragging.startY;
154
+ displayRowHeight(view, curPluginState.activeHandle, dragged, offset, tableHeight);
155
+ }
156
+ event.view.addEventListener('mouseup', finish);
157
+ event.view.addEventListener('mousemove', move);
158
+ event.preventDefault();
159
+ return true;
160
+ }
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
+ function draggedHeight(dragging, event) {
178
+ var offset = event.clientY - dragging.startY;
179
+ return dragging.startHeight.rowHeight + offset;
180
+ }
181
+ function updateHandle(view, value) {
182
+ view.dispatch(view.state.tr.setMeta(key, { setHandle: value }));
183
+ }
184
+ function updateRowHeight(view, tr, rowPos) {
185
+ var doc = view.state.doc;
186
+ var row = doc.nodeAt(rowPos);
187
+ var dom = view.nodeDOM(rowPos);
188
+ var win = (dom.ownerDocument && dom.ownerDocument.defaultView) || window;
189
+ dom.style.height = win.getComputedStyle(dom).height;
190
+ tr.setNodeMarkup(rowPos, null, setNodeStyle(row.attrs, 'height', dom.style.height));
191
+ var table = dom && dom.closest('table');
192
+ var tableHeight = table && table.style.height;
193
+ if (tableHeight) {
194
+ var $pos = doc.resolve(rowPos);
195
+ var tablePos = $pos.start($pos.depth) - 1;
196
+ tr.setNodeMarkup(tablePos, null, setNodeStyle($pos.parent.attrs, 'height', tableHeight));
197
+ }
198
+ }
199
+ function displayRowHeight(view, rowPos, height, offset, tableHeight) {
200
+ var dom = view.nodeDOM(rowPos);
201
+ if (dom) {
202
+ dom.style.height = height + 'px';
203
+ var win = (dom.ownerDocument && dom.ownerDocument.defaultView) || window;
204
+ dom.style.height = win.getComputedStyle(dom).height;
205
+ var table = dom.closest('table');
206
+ var newHeight = (parseFloat(tableHeight) + offset) + 'px';
207
+ var current = table && table.style.height;
208
+ if (current && current !== newHeight) {
209
+ table.style.height = (parseFloat(tableHeight) + offset) + 'px';
210
+ table.style.height = win.getComputedStyle(table).height;
211
+ }
212
+ }
213
+ }
214
+ function handleDecorations(state, pos) {
215
+ var decorations = [];
216
+ if (typeof pos !== 'number') {
217
+ return DecorationSet.empty;
218
+ }
219
+ var $row = state.doc.resolve(pos), table = $row.parent, map = TableMap.get(table), rowIndex = $row.index($row.depth), start = $row.start($row.depth);
220
+ for (var col = 0; col < map.width; col++) {
221
+ var index = col + rowIndex * map.width;
222
+ var cellPos = map.map[index];
223
+ var cell = table.nodeAt(cellPos);
224
+ var widgetPos = start + cellPos + (cell ? cell.nodeSize : 0) - 1;
225
+ var dom = document.createElement('div');
226
+ dom.className = 'row-resize-handle';
227
+ decorations.push(Decoration.widget(widgetPos, dom));
228
+ }
229
+ return DecorationSet.create(state.doc, decorations);
230
+ }