@progress/kendo-editor-common 1.9.0-dev.202204060830 → 1.9.0-dev.202204181342

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 (36) 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/config/schema.js +10 -6
  5. package/dist/es/plugins/image-resize.js +4 -14
  6. package/dist/es/plugins/resize-utils.js +11 -0
  7. package/dist/es/plugins/table-resize/column-resize.js +28 -49
  8. package/dist/es/plugins/table-resize/row-resize.js +40 -54
  9. package/dist/es/plugins/table-resize/table-resize.js +46 -67
  10. package/dist/es/plugins/table-resize/table-view.js +9 -9
  11. package/dist/es/plugins/table-resize/utils.js +26 -2
  12. package/dist/es2015/config/constants.js +2 -1
  13. package/dist/es2015/config/schema.js +6 -6
  14. package/dist/es2015/plugins/image-resize.js +4 -14
  15. package/dist/es2015/plugins/resize-utils.js +11 -0
  16. package/dist/es2015/plugins/table-resize/column-resize.js +28 -49
  17. package/dist/es2015/plugins/table-resize/row-resize.js +40 -54
  18. package/dist/es2015/plugins/table-resize/table-resize.js +45 -66
  19. package/dist/es2015/plugins/table-resize/table-view.js +9 -9
  20. package/dist/es2015/plugins/table-resize/utils.js +26 -2
  21. package/dist/npm/config/constants.d.ts +2 -1
  22. package/dist/npm/config/constants.js +2 -1
  23. package/dist/npm/config/schema.js +10 -6
  24. package/dist/npm/plugins/image-resize.js +6 -16
  25. package/dist/npm/plugins/resize-utils.d.ts +35 -0
  26. package/dist/npm/plugins/resize-utils.js +13 -0
  27. package/dist/npm/plugins/table-resize/column-resize.js +28 -49
  28. package/dist/npm/plugins/table-resize/row-resize.js +39 -53
  29. package/dist/npm/plugins/table-resize/table-resize.d.ts +2 -4
  30. package/dist/npm/plugins/table-resize/table-resize.js +45 -66
  31. package/dist/npm/plugins/table-resize/table-view.d.ts +7 -7
  32. package/dist/npm/plugins/table-resize/table-view.js +8 -8
  33. package/dist/npm/plugins/table-resize/utils.d.ts +10 -0
  34. package/dist/npm/plugins/table-resize/utils.js +29 -2
  35. package/dist/systemjs/kendo-editor-common.js +1 -1
  36. package/package.json +2 -2
@@ -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;
@@ -13,7 +13,7 @@ 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
18
  key: utils_1.tableRowResizing,
19
19
  state: {
@@ -36,7 +36,7 @@ function rowResizing() {
36
36
  handleDOMEvents: {
37
37
  mousemove: function (view, event) {
38
38
  if (!utils_1.otherResizing(utils_1.tableRowResizing, view.state)) {
39
- handleMouseMove(view, event, handleWidth, rowMinHeight, lastRowResizable);
39
+ handleMouseMove(view, event, handleWidth);
40
40
  }
41
41
  return false;
42
42
  },
@@ -45,7 +45,7 @@ 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) {
@@ -79,7 +79,7 @@ var ResizeState = /** @class */ (function () {
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,30 +90,22 @@ var ResizeState = /** @class */ (function () {
90
90
  };
91
91
  return ResizeState;
92
92
  }());
93
- function handleMouseMove(view, event, handleWidth, _rowMinHeight, lastRowResizable) {
93
+ function handleMouseMove(view, event, handleWidth) {
94
94
  var pluginState = utils_1.tableRowResizing.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
  }
@@ -123,7 +115,7 @@ function handleMouseLeave(view) {
123
115
  updateHandle(view, -1);
124
116
  }
125
117
  }
126
- function handleMouseDown(view, event, rowMinHeight) {
118
+ function handleMouseDown(view, event) {
127
119
  var pluginState = utils_1.tableRowResizing.getState(view.state);
128
120
  if (pluginState.activeHandle === -1 || pluginState.dragging) {
129
121
  return false;
@@ -151,7 +143,7 @@ function handleMouseDown(view, event, rowMinHeight) {
151
143
  var curPluginState = utils_1.tableRowResizing.getState(view.state);
152
144
  if (curPluginState.dragging) {
153
145
  var tr = view.state.tr.setMeta(utils_1.tableRowResizing, { setDragging: null });
154
- updateRowHeight(view, tr, curPluginState.activeHandle, draggedHeight(curPluginState.dragging, ev, rowMinHeight));
146
+ updateRowHeight(view, tr, curPluginState.activeHandle);
155
147
  view.dispatch(tr);
156
148
  }
157
149
  }
@@ -160,54 +152,45 @@ function handleMouseDown(view, event, rowMinHeight) {
160
152
  return finish(ev);
161
153
  }
162
154
  var curPluginState = utils_1.tableRowResizing.getState(view.state);
163
- var dragged = draggedHeight(curPluginState.dragging, ev, rowMinHeight);
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
185
  view.dispatch(view.state.tr.setMeta(utils_1.tableRowResizing, { 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>;