@progress/kendo-angular-editor 2.5.0 → 3.0.0-dev.202201191455
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/LICENSE.md +1 -1
- package/NOTICE.txt +119 -79
- package/README.md +1 -1
- package/dist/cdn/js/kendo-angular-editor.js +2 -2
- package/dist/cdn/main.js +1 -1
- package/dist/es/common/error-messages.js +4 -3
- package/dist/es/config/command-icons.js +1 -0
- package/dist/es/config/commands.js +18 -17
- package/dist/es/config/schema.js +2 -4
- package/dist/es/config/table-commands.js +1 -363
- package/dist/es/dialogs/colorpicker-dialog.component.js +1 -1
- package/dist/es/dialogs/file-link-dialog.component.js +1 -1
- package/dist/es/dialogs/image-dialog.component.js +1 -1
- package/dist/es/editor-toolbar-state.js +12 -2
- package/dist/es/editor.component.js +103 -75
- package/dist/es/editor.module.js +6 -3
- package/dist/es/index.js +2 -0
- package/dist/es/localization/messages.js +4 -0
- package/dist/es/main.js +1 -0
- package/dist/es/package-metadata.js +1 -1
- package/dist/{es2015/config/table-nodes.d.ts → es/preventable-events/paste-event-data.js} +0 -5
- package/dist/es/preventable-events/paste-event.js +25 -0
- package/dist/es/tools/blockquote/editor-blockquote-button.directive.js +48 -0
- package/dist/es/tools/colorpicker/editor-colorpicker.component.js +24 -7
- package/dist/es/tools/format/editor-format-dropdownlist.component.js +1 -1
- package/dist/es/tools/format/editor-format.component.js +0 -1
- package/dist/es/tools/tables/popup-table-grid.component.js +1 -1
- package/dist/es2015/common/commands.d.ts +1 -1
- package/dist/es2015/common/error-messages.js +4 -3
- package/dist/es2015/common/format-item.interface.d.ts +1 -1
- package/dist/es2015/common/paste-cleanup-settings.d.ts +14 -0
- package/dist/es2015/config/command-icons.js +1 -0
- package/dist/es2015/config/commands.js +18 -17
- package/dist/es2015/config/schema.d.ts +1 -1
- package/dist/es2015/config/schema.js +2 -3
- package/dist/es2015/config/table-commands.d.ts +0 -36
- package/dist/es2015/config/table-commands.js +1 -357
- package/dist/es2015/dialogs/colorpicker-dialog.component.js +1 -1
- package/dist/es2015/dialogs/file-link-dialog.component.js +4 -4
- package/dist/es2015/dialogs/image-dialog.component.js +4 -4
- package/dist/es2015/editor-toolbar-state.js +12 -2
- package/dist/es2015/editor.component.d.ts +16 -11
- package/dist/es2015/editor.component.js +105 -75
- package/dist/es2015/editor.module.js +6 -3
- package/dist/es2015/index.d.ts +2 -0
- package/dist/es2015/index.js +2 -0
- package/dist/es2015/index.metadata.json +1 -1
- package/dist/es2015/localization/messages.d.ts +4 -0
- package/dist/es2015/localization/messages.js +4 -0
- package/dist/es2015/main.d.ts +2 -0
- package/dist/es2015/main.js +1 -0
- package/dist/es2015/package-metadata.js +1 -1
- package/dist/es2015/preventable-events/paste-event-data.d.ts +21 -0
- package/dist/es2015/preventable-events/paste-event-data.js +4 -0
- package/dist/es2015/preventable-events/paste-event.d.ts +27 -0
- package/dist/es2015/preventable-events/paste-event.js +20 -0
- package/dist/es2015/tools/blockquote/editor-blockquote-button.directive.d.ts +30 -0
- package/dist/es2015/tools/blockquote/editor-blockquote-button.directive.js +45 -0
- package/dist/es2015/tools/colorpicker/editor-colorpicker.component.d.ts +8 -2
- package/dist/es2015/tools/colorpicker/editor-colorpicker.component.js +20 -7
- package/dist/es2015/tools/format/editor-format-dropdownlist.component.js +0 -4
- package/dist/es2015/tools/format/editor-format.component.js +0 -1
- package/dist/es2015/tools/tables/popup-table-grid.component.js +2 -2
- package/dist/fesm2015/index.js +354 -1624
- package/dist/fesm5/index.js +365 -1649
- package/dist/npm/common/error-messages.js +4 -2
- package/dist/npm/config/command-icons.js +1 -0
- package/dist/npm/config/commands.js +16 -14
- package/dist/npm/config/schema.js +2 -4
- package/dist/npm/config/table-commands.js +1 -368
- package/dist/npm/dialogs/colorpicker-dialog.component.js +1 -1
- package/dist/npm/dialogs/file-link-dialog.component.js +1 -1
- package/dist/npm/dialogs/image-dialog.component.js +1 -1
- package/dist/npm/editor-toolbar-state.js +11 -1
- package/dist/npm/editor.component.js +99 -71
- package/dist/npm/editor.module.js +7 -4
- package/dist/npm/index.js +5 -0
- package/dist/npm/localization/messages.js +4 -0
- package/dist/npm/main.js +2 -0
- package/dist/npm/package-metadata.js +1 -1
- package/dist/npm/preventable-events/paste-event-data.js +6 -0
- package/dist/npm/preventable-events/paste-event.js +27 -0
- package/dist/npm/tools/blockquote/editor-blockquote-button.directive.js +50 -0
- package/dist/npm/tools/colorpicker/editor-colorpicker.component.js +24 -7
- package/dist/npm/tools/format/editor-format-dropdownlist.component.js +1 -1
- package/dist/npm/tools/format/editor-format.component.js +0 -1
- package/dist/npm/tools/tables/popup-table-grid.component.js +1 -1
- package/dist/systemjs/kendo-angular-editor.js +1 -1
- package/package.json +18 -18
- package/dist/es/config/table-nodes.js +0 -146
- package/dist/es/config/tables/CellSelection.js +0 -268
- package/dist/es/config/tables/TableMap.js +0 -333
- package/dist/es/config/tables/table-utils.js +0 -302
- package/dist/es2015/config/table-nodes.js +0 -145
- package/dist/es2015/config/tables/CellSelection.d.ts +0 -35
- package/dist/es2015/config/tables/CellSelection.js +0 -256
- package/dist/es2015/config/tables/TableMap.d.ts +0 -35
- package/dist/es2015/config/tables/TableMap.js +0 -329
- package/dist/es2015/config/tables/table-utils.d.ts +0 -77
- package/dist/es2015/config/tables/table-utils.js +0 -299
- package/dist/npm/config/table-nodes.js +0 -157
- package/dist/npm/config/tables/CellSelection.js +0 -270
- package/dist/npm/config/tables/TableMap.js +0 -338
- package/dist/npm/config/tables/table-utils.js +0 -307
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
/**-----------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright © 2021 Progress Software Corporation. All rights reserved.
|
|
3
|
-
* Licensed under commercial license. See LICENSE.md in the project root for more information
|
|
4
|
-
*-------------------------------------------------------------------------------------------*/
|
|
5
|
-
"use strict";
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
var utils_1 = require("../utils");
|
|
8
|
-
// Because working with row and column-spanning cells is not quite
|
|
9
|
-
// trivial, this code builds up a descriptive structure for a given
|
|
10
|
-
// table node. The structures are cached with the (persistent) table
|
|
11
|
-
// nodes as key, so that they only have to be recomputed when the
|
|
12
|
-
// content of the table changes.
|
|
13
|
-
//
|
|
14
|
-
// This does mean that they have to store table-relative, not
|
|
15
|
-
// document-relative positions. So code that uses them will typically
|
|
16
|
-
// compute the start position of the table and offset positions passed
|
|
17
|
-
// to or gotten from this structure by that amount.
|
|
18
|
-
var readFromCache;
|
|
19
|
-
var addToCache;
|
|
20
|
-
// Prefer using a weak map to cache table maps. Fall back on a
|
|
21
|
-
// fixed-size cache if that's not supported.
|
|
22
|
-
if (typeof WeakMap !== 'undefined') {
|
|
23
|
-
var cache_1 = new WeakMap();
|
|
24
|
-
readFromCache = function (key) { return cache_1.get(key); };
|
|
25
|
-
addToCache = function (key, value) {
|
|
26
|
-
cache_1.set(key, value);
|
|
27
|
-
return value;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
var cache_2 = [];
|
|
32
|
-
var cacheSize_1 = 10;
|
|
33
|
-
var cachePos_1 = 0;
|
|
34
|
-
readFromCache = function (key) {
|
|
35
|
-
for (var i = 0; i < cache_2.length; i += 2) {
|
|
36
|
-
if (cache_2[i] === key) {
|
|
37
|
-
return cache_2[i + 1];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
addToCache = function (key, value) {
|
|
42
|
-
if (cachePos_1 === cacheSize_1) {
|
|
43
|
-
cachePos_1 = 0;
|
|
44
|
-
}
|
|
45
|
-
cache_2[cachePos_1++] = key;
|
|
46
|
-
return (cache_2[cachePos_1++] = value);
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
var findWidth = function (table) {
|
|
50
|
-
var width = -1;
|
|
51
|
-
var hasRowSpan = false;
|
|
52
|
-
for (var row = 0; row < table.childCount; row++) {
|
|
53
|
-
var rowNode = table.child(row);
|
|
54
|
-
var rowWidth = 0;
|
|
55
|
-
if (hasRowSpan) {
|
|
56
|
-
for (var j = 0; j < row; j++) {
|
|
57
|
-
var prevRow = table.child(j);
|
|
58
|
-
for (var i = 0; i < prevRow.childCount; i++) {
|
|
59
|
-
var cell = prevRow.child(i);
|
|
60
|
-
if (j + cell.attrs.rowspan > row) {
|
|
61
|
-
rowWidth += cell.attrs.colspan;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// check if the cell spans accross multiple columns
|
|
67
|
-
for (var i = 0; i < rowNode.childCount; i++) {
|
|
68
|
-
var cell = rowNode.child(i);
|
|
69
|
-
rowWidth += cell.attrs.colspan;
|
|
70
|
-
if (cell.attrs.rowspan > 1) {
|
|
71
|
-
hasRowSpan = true;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (width === -1) {
|
|
75
|
-
width = rowWidth;
|
|
76
|
-
}
|
|
77
|
-
else if (width !== rowWidth) {
|
|
78
|
-
width = Math.max(width, rowWidth);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return width;
|
|
82
|
-
};
|
|
83
|
-
var ɵ0 = findWidth;
|
|
84
|
-
exports.ɵ0 = ɵ0;
|
|
85
|
-
var freshColWidth = function (attrs) {
|
|
86
|
-
if (attrs.colwidth) {
|
|
87
|
-
return attrs.colwidth.slice();
|
|
88
|
-
}
|
|
89
|
-
var result = [];
|
|
90
|
-
for (var i = 0; i < attrs.colspan; i++) {
|
|
91
|
-
result.push(0);
|
|
92
|
-
}
|
|
93
|
-
return result;
|
|
94
|
-
};
|
|
95
|
-
var ɵ1 = freshColWidth;
|
|
96
|
-
exports.ɵ1 = ɵ1;
|
|
97
|
-
var findBadColWidths = function (map, colWidths, table) {
|
|
98
|
-
if (!map.problems) {
|
|
99
|
-
map.problems = [];
|
|
100
|
-
}
|
|
101
|
-
for (var i = 0, seen = {}; i < map.map.length; i++) {
|
|
102
|
-
var pos = map.map[i];
|
|
103
|
-
if (seen[pos]) {
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
seen[pos] = true;
|
|
107
|
-
var node = table.nodeAt(pos);
|
|
108
|
-
var updated = null;
|
|
109
|
-
for (var j = 0; j < node.attrs.colspan; j++) {
|
|
110
|
-
var col = (i + j) % map.width;
|
|
111
|
-
var colWidth = colWidths[col * 2];
|
|
112
|
-
if (colWidth != null && (!node.attrs.colwidth || node.attrs.colwidth[j] !== colWidth)) {
|
|
113
|
-
(updated || (updated = freshColWidth(node.attrs)))[j] = colWidth;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (updated) {
|
|
117
|
-
map.problems.unshift({ type: 'colwidth mismatch', pos: pos, colwidth: updated });
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
var ɵ2 = findBadColWidths;
|
|
122
|
-
exports.ɵ2 = ɵ2;
|
|
123
|
-
// Compute a table map.
|
|
124
|
-
var computeMap = function (tableNode) {
|
|
125
|
-
if (!utils_1.isTable(tableNode) && !utils_1.isTableBody(tableNode) && !utils_1.isTableHead(tableNode) && !utils_1.isTableFoot(tableNode)) {
|
|
126
|
-
throw new RangeError('Not a table node: ' + tableNode.type.name);
|
|
127
|
-
}
|
|
128
|
-
var width = findWidth(tableNode);
|
|
129
|
-
var height = tableNode.childCount;
|
|
130
|
-
var map = [];
|
|
131
|
-
var mapPos = 0;
|
|
132
|
-
var problems = null;
|
|
133
|
-
var colWidths = [];
|
|
134
|
-
for (var i = 0, e = width * height; i < e; i++) {
|
|
135
|
-
map[i] = 0;
|
|
136
|
-
}
|
|
137
|
-
for (var row = 0, pos = 0; row < height; row++) {
|
|
138
|
-
var rowNode = tableNode.child(row);
|
|
139
|
-
pos++;
|
|
140
|
-
for (var i = 0;; i++) {
|
|
141
|
-
while (mapPos < map.length && map[mapPos] !== 0) {
|
|
142
|
-
mapPos++;
|
|
143
|
-
}
|
|
144
|
-
if (i === rowNode.childCount) {
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
var cellNode = rowNode.child(i);
|
|
148
|
-
var _a = cellNode.attrs, colspan = _a.colspan, rowspan = _a.rowspan, colwidth = _a.colwidth;
|
|
149
|
-
for (var h = 0; h < rowspan; h++) {
|
|
150
|
-
if (h + row >= height) {
|
|
151
|
-
(problems || (problems = [])).push({ type: 'overlong_rowspan', pos: pos, n: rowspan - h });
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
var start = mapPos + h * width;
|
|
155
|
-
for (var w = 0; w < colspan; w++) {
|
|
156
|
-
if (map[start + w] === 0) {
|
|
157
|
-
map[start + w] = pos;
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
(problems || (problems = [])).push({ type: 'collision', row: row, pos: pos, n: colspan - w });
|
|
161
|
-
}
|
|
162
|
-
var colW = colwidth && colwidth[w];
|
|
163
|
-
if (colW) {
|
|
164
|
-
var widthIndex = ((start + w) % width) * 2, prev = colWidths[widthIndex];
|
|
165
|
-
if (prev == null || (prev !== colW && colWidths[widthIndex + 1] === 1)) {
|
|
166
|
-
colWidths[widthIndex] = colW;
|
|
167
|
-
colWidths[widthIndex + 1] = 1;
|
|
168
|
-
}
|
|
169
|
-
else if (prev === colW) {
|
|
170
|
-
colWidths[widthIndex + 1]++;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
mapPos += colspan;
|
|
176
|
-
pos += cellNode.nodeSize;
|
|
177
|
-
}
|
|
178
|
-
var expectedPos = (row + 1) * width;
|
|
179
|
-
var missing = 0;
|
|
180
|
-
while (mapPos < expectedPos) {
|
|
181
|
-
if (map[mapPos++] === 0) {
|
|
182
|
-
missing++;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (missing) {
|
|
186
|
-
(problems || (problems = [])).push({ type: 'missing', row: row, n: missing });
|
|
187
|
-
}
|
|
188
|
-
pos++;
|
|
189
|
-
}
|
|
190
|
-
var tableMap = new TableMap(width, height, map, problems);
|
|
191
|
-
var badWidths = false;
|
|
192
|
-
// For columns that have defined widths, but whose widths disagree
|
|
193
|
-
// between rows, fix up the cells whose width doesn't match the
|
|
194
|
-
// computed one.
|
|
195
|
-
for (var i = 0; !badWidths && i < colWidths.length; i += 2) {
|
|
196
|
-
if (colWidths[i] != null && colWidths[i + 1] < height) {
|
|
197
|
-
badWidths = true;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
if (badWidths) {
|
|
201
|
-
findBadColWidths(tableMap, colWidths, tableNode);
|
|
202
|
-
}
|
|
203
|
-
return tableMap;
|
|
204
|
-
};
|
|
205
|
-
var ɵ3 = computeMap;
|
|
206
|
-
exports.ɵ3 = ɵ3;
|
|
207
|
-
/**
|
|
208
|
-
* @hidden
|
|
209
|
-
*/
|
|
210
|
-
var Rect = /** @class */ (function () {
|
|
211
|
-
function Rect(left, top, right, bottom) {
|
|
212
|
-
this.left = left;
|
|
213
|
-
this.top = top;
|
|
214
|
-
this.right = right;
|
|
215
|
-
this.bottom = bottom;
|
|
216
|
-
}
|
|
217
|
-
return Rect;
|
|
218
|
-
}());
|
|
219
|
-
exports.Rect = Rect;
|
|
220
|
-
/**
|
|
221
|
-
* @hidden
|
|
222
|
-
*/
|
|
223
|
-
var TableMap = /** @class */ (function () {
|
|
224
|
-
function TableMap(width, height, map, problems) {
|
|
225
|
-
// :: number The width of the table
|
|
226
|
-
this.width = width;
|
|
227
|
-
// :: number The table's height
|
|
228
|
-
this.height = height;
|
|
229
|
-
// :: [number] A width * height array with the start position of
|
|
230
|
-
// the cell covering that part of the table in each slot
|
|
231
|
-
this.map = map;
|
|
232
|
-
// An optional array of problems (cell overlap or non-rectangular
|
|
233
|
-
// shape) for the table, used by the table normalizer.
|
|
234
|
-
this.problems = problems;
|
|
235
|
-
}
|
|
236
|
-
// :: (Node) → TableMap
|
|
237
|
-
// Find the table map for the given table node.
|
|
238
|
-
TableMap.get = function (table) {
|
|
239
|
-
return readFromCache(table) || addToCache(table, computeMap(table));
|
|
240
|
-
};
|
|
241
|
-
// :: (number) → Rect
|
|
242
|
-
// Find the dimensions of the cell at the given position.
|
|
243
|
-
TableMap.prototype.findCell = function (pos) {
|
|
244
|
-
for (var i = 0; i < this.map.length; i++) {
|
|
245
|
-
var curPos = this.map[i];
|
|
246
|
-
if (curPos !== pos) {
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
var left = i % this.width;
|
|
250
|
-
var top_1 = Math.floor(i / this.width);
|
|
251
|
-
var right = left + 1;
|
|
252
|
-
var bottom = top_1 + 1;
|
|
253
|
-
for (var j = 1; right < this.width && this.map[i + j] === curPos; j++) {
|
|
254
|
-
right++;
|
|
255
|
-
}
|
|
256
|
-
for (var j = 1; bottom < this.height && this.map[i + this.width * j] === curPos; j++) {
|
|
257
|
-
bottom++;
|
|
258
|
-
}
|
|
259
|
-
return new Rect(left, top_1, right, bottom);
|
|
260
|
-
}
|
|
261
|
-
throw new RangeError('No cell with offset ' + pos + ' found');
|
|
262
|
-
};
|
|
263
|
-
// :: (number) → number
|
|
264
|
-
// Find the left side of the cell at the given position.
|
|
265
|
-
TableMap.prototype.colCount = function (pos) {
|
|
266
|
-
for (var i = 0; i < this.map.length; i++) {
|
|
267
|
-
if (this.map[i] === pos) {
|
|
268
|
-
return i % this.width;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
throw new RangeError('No cell with offset ' + pos + ' found');
|
|
272
|
-
};
|
|
273
|
-
// :: (number, string, number) → ?number
|
|
274
|
-
// Find the next cell in the given direction, starting from the cell
|
|
275
|
-
// at `pos`, if any.
|
|
276
|
-
TableMap.prototype.nextCell = function (pos, axis, dir) {
|
|
277
|
-
var _a = this.findCell(pos), left = _a.left, right = _a.right, top = _a.top, bottom = _a.bottom;
|
|
278
|
-
if (axis === 'horiz') {
|
|
279
|
-
if (dir < 0 ? left === 0 : right === this.width) {
|
|
280
|
-
return null;
|
|
281
|
-
}
|
|
282
|
-
return this.map[top * this.width + (dir < 0 ? left - 1 : right)];
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
if (dir < 0 ? top === 0 : bottom === this.height) {
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
288
|
-
return this.map[left + this.width * (dir < 0 ? top - 1 : bottom)];
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
// :: (number, number) → Rect
|
|
292
|
-
// Get the rectangle spanning the two given cells.
|
|
293
|
-
TableMap.prototype.rectBetween = function (a, b) {
|
|
294
|
-
var _a = this.findCell(a), leftA = _a.left, rightA = _a.right, topA = _a.top, bottomA = _a.bottom;
|
|
295
|
-
var _b = this.findCell(b), leftB = _b.left, rightB = _b.right, topB = _b.top, bottomB = _b.bottom;
|
|
296
|
-
return new Rect(Math.min(leftA, leftB), Math.min(topA, topB), Math.max(rightA, rightB), Math.max(bottomA, bottomB));
|
|
297
|
-
};
|
|
298
|
-
// :: (Rect) → [number]
|
|
299
|
-
// Return the position of all cells that have the top left corner in
|
|
300
|
-
// the given rectangle.
|
|
301
|
-
TableMap.prototype.cellsInRect = function (rect) {
|
|
302
|
-
var result = [];
|
|
303
|
-
var seen = {};
|
|
304
|
-
for (var row = rect.top; row < rect.bottom; row++) {
|
|
305
|
-
for (var col = rect.left; col < rect.right; col++) {
|
|
306
|
-
var index = row * this.width + col, pos = this.map[index];
|
|
307
|
-
if (seen[pos]) {
|
|
308
|
-
continue;
|
|
309
|
-
}
|
|
310
|
-
seen[pos] = true;
|
|
311
|
-
if ((col !== rect.left || !col || this.map[index - 1] !== pos) &&
|
|
312
|
-
(row !== rect.top || !row || this.map[index - this.width] !== pos)) {
|
|
313
|
-
result.push(pos);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
return result;
|
|
318
|
-
};
|
|
319
|
-
// :: (number, number, Node) → number
|
|
320
|
-
// Return the position at which the cell at the given row and column
|
|
321
|
-
// starts, or would start, if a cell started there.
|
|
322
|
-
TableMap.prototype.positionAt = function (row, col, table) {
|
|
323
|
-
for (var i = 0, rowStart = 0;; i++) {
|
|
324
|
-
var rowEnd = rowStart + table.child(i).nodeSize;
|
|
325
|
-
if (i === row) {
|
|
326
|
-
var index = col + row * this.width, rowEndIndex = (row + 1) * this.width;
|
|
327
|
-
// Skip past cells from previous rows (via rowspan)
|
|
328
|
-
while (index < rowEndIndex && this.map[index] < rowStart) {
|
|
329
|
-
index++;
|
|
330
|
-
}
|
|
331
|
-
return index === rowEndIndex ? rowEnd - 1 : this.map[index];
|
|
332
|
-
}
|
|
333
|
-
rowStart = rowEnd;
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
return TableMap;
|
|
337
|
-
}());
|
|
338
|
-
exports.TableMap = TableMap;
|
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
/**-----------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright © 2021 Progress Software Corporation. All rights reserved.
|
|
3
|
-
* Licensed under commercial license. See LICENSE.md in the project root for more information
|
|
4
|
-
*-------------------------------------------------------------------------------------------*/
|
|
5
|
-
"use strict";
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
var kendo_editor_common_1 = require("@progress/kendo-editor-common");
|
|
8
|
-
var utils_1 = require("../utils");
|
|
9
|
-
var TableMap_1 = require("./TableMap");
|
|
10
|
-
var CellSelection_1 = require("./CellSelection");
|
|
11
|
-
/**
|
|
12
|
-
* @hidden
|
|
13
|
-
*/
|
|
14
|
-
exports.findParentNodeClosestToPos = function ($pos, predicate) {
|
|
15
|
-
for (var i = $pos.depth; i > 0; i--) {
|
|
16
|
-
var node = $pos.node(i);
|
|
17
|
-
if (predicate(node)) {
|
|
18
|
-
return {
|
|
19
|
-
start: $pos.start(i),
|
|
20
|
-
pos: i > 0 ? $pos.before(i) : 0,
|
|
21
|
-
depth: i,
|
|
22
|
-
node: node
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* @hidden
|
|
29
|
-
*/
|
|
30
|
-
exports.createTable = function (nodes, rows, columns) {
|
|
31
|
-
var table = nodes.table, table_body = nodes.table_body, table_row = nodes.table_row, table_cell = nodes.table_cell;
|
|
32
|
-
var tableRows = [];
|
|
33
|
-
var cells;
|
|
34
|
-
for (var r = 0; r < rows + 1; r++) {
|
|
35
|
-
cells = [];
|
|
36
|
-
for (var c = 0; c < columns + 1; c++) {
|
|
37
|
-
cells.push(table_cell.createAndFill());
|
|
38
|
-
}
|
|
39
|
-
tableRows.push(table_row.createAndFill(undefined, cells));
|
|
40
|
-
}
|
|
41
|
-
var body = table_body.createAndFill(undefined, tableRows);
|
|
42
|
-
return table.createAndFill(undefined, body);
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* @hidden
|
|
46
|
-
*/
|
|
47
|
-
exports.isInTable = function (state) {
|
|
48
|
-
var $head = state.selection.$head;
|
|
49
|
-
for (var d = $head.depth; d > 0; d--) {
|
|
50
|
-
if (utils_1.isTableRow($head.node(d))) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return false;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* @hidden
|
|
58
|
-
*/
|
|
59
|
-
exports.setAttr = function (attrs, name, value) {
|
|
60
|
-
var result = {};
|
|
61
|
-
// tslint:disable-next-line
|
|
62
|
-
for (var prop in attrs) {
|
|
63
|
-
result[prop] = attrs[prop];
|
|
64
|
-
}
|
|
65
|
-
result[name] = value;
|
|
66
|
-
return result;
|
|
67
|
-
};
|
|
68
|
-
var cellNear = function ($pos) {
|
|
69
|
-
for (var after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {
|
|
70
|
-
var role = after.type.spec.tableRole;
|
|
71
|
-
if (role === 'cell' || role === 'header_cell') {
|
|
72
|
-
return $pos.doc.resolve(pos);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
for (var before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
|
|
76
|
-
var role = before.type.spec.tableRole;
|
|
77
|
-
if (role === 'cell' || role === 'header_cell') {
|
|
78
|
-
return $pos.doc.resolve(pos - before.nodeSize);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
var ɵ0 = cellNear;
|
|
83
|
-
exports.ɵ0 = ɵ0;
|
|
84
|
-
var cellAround = function ($pos) {
|
|
85
|
-
for (var d = $pos.depth - 1; d > 0; d--) {
|
|
86
|
-
if (utils_1.isTableRow($pos.node(d))) {
|
|
87
|
-
return $pos.node(0).resolve($pos.before(d + 1));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return null;
|
|
91
|
-
};
|
|
92
|
-
var ɵ1 = cellAround;
|
|
93
|
-
exports.ɵ1 = ɵ1;
|
|
94
|
-
var selectionCell = function (sel) {
|
|
95
|
-
if (sel instanceof CellSelection_1.CellSelection && sel.$anchorCell) {
|
|
96
|
-
return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
|
|
97
|
-
}
|
|
98
|
-
else if (sel instanceof kendo_editor_common_1.NodeSelection && sel.node && utils_1.isTableCell(sel.node)) {
|
|
99
|
-
return sel.$anchor;
|
|
100
|
-
}
|
|
101
|
-
return cellAround(sel.$head) || cellNear(sel.$head);
|
|
102
|
-
};
|
|
103
|
-
var ɵ2 = selectionCell;
|
|
104
|
-
exports.ɵ2 = ɵ2;
|
|
105
|
-
/**
|
|
106
|
-
* @hidden
|
|
107
|
-
*/
|
|
108
|
-
// Helper to get the selected rectangle in a table, if any. Adds table
|
|
109
|
-
// map, table node, and table start offset to the object for
|
|
110
|
-
// convenience.
|
|
111
|
-
exports.selectedRect = function (sel) {
|
|
112
|
-
// create arr of rect for each table section
|
|
113
|
-
// there has to be a rect for thead, tbody and tfoot(if each exists)
|
|
114
|
-
// and NOT for colgroups
|
|
115
|
-
var $pos = selectionCell(sel);
|
|
116
|
-
var table = $pos.node(-1);
|
|
117
|
-
var tableStart = $pos.start(-1);
|
|
118
|
-
var map = TableMap_1.TableMap.get(table);
|
|
119
|
-
var rect = sel instanceof CellSelection_1.CellSelection
|
|
120
|
-
? map.rectBetween(sel.$anchorCell.pos - tableStart, sel.$headCell.pos - tableStart)
|
|
121
|
-
: map.findCell($pos.pos - tableStart);
|
|
122
|
-
rect.tableStart = tableStart;
|
|
123
|
-
rect.map = map;
|
|
124
|
-
rect.table = table;
|
|
125
|
-
return rect;
|
|
126
|
-
};
|
|
127
|
-
/**
|
|
128
|
-
* @hidden
|
|
129
|
-
*/
|
|
130
|
-
// this has to be removed since the schema should not have roles inside NodeSpec.
|
|
131
|
-
exports.tableNodeTypes = function (schema) {
|
|
132
|
-
var result = schema.cached.tableNodeTypes;
|
|
133
|
-
if (!result) {
|
|
134
|
-
result = schema.cached.tableNodeTypes = {};
|
|
135
|
-
// tslint:disable-next-line
|
|
136
|
-
for (var name_1 in schema.nodes) {
|
|
137
|
-
var type = schema.nodes[name_1];
|
|
138
|
-
var role = type.spec.tableRole;
|
|
139
|
-
if (role) {
|
|
140
|
-
result[role] = type;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return result;
|
|
145
|
-
};
|
|
146
|
-
/**
|
|
147
|
-
* @hidden
|
|
148
|
-
*/
|
|
149
|
-
exports.rowIsHeader = function (map, table, row) {
|
|
150
|
-
var headerCell = exports.tableNodeTypes(table.type.schema).header_cell;
|
|
151
|
-
for (var col = 0; col < map.width; col++) {
|
|
152
|
-
if (table.nodeAt(map.map[col + row * map.width]).type !== headerCell) {
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return true;
|
|
157
|
-
};
|
|
158
|
-
/**
|
|
159
|
-
* @hidden
|
|
160
|
-
*/
|
|
161
|
-
exports.addColSpan = function (attrs, pos, n) {
|
|
162
|
-
if (n === void 0) { n = 1; }
|
|
163
|
-
var result = exports.setAttr(attrs, 'colspan', attrs.colspan + n);
|
|
164
|
-
if (result.colwidth) {
|
|
165
|
-
result.colwidth = result.colwidth.slice();
|
|
166
|
-
for (var i = 0; i < n; i++) {
|
|
167
|
-
result.colwidth.splice(pos, 0, 0);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return result;
|
|
171
|
-
};
|
|
172
|
-
/**
|
|
173
|
-
* @hidden
|
|
174
|
-
*/
|
|
175
|
-
exports.removeColSpan = function (attrs, pos, n) {
|
|
176
|
-
if (n === void 0) { n = 1; }
|
|
177
|
-
var result = exports.setAttr(attrs, 'colspan', attrs.colspan - n);
|
|
178
|
-
if (result.colwidth) {
|
|
179
|
-
result.colwidth = result.colwidth.slice();
|
|
180
|
-
result.colwidth.splice(pos, n);
|
|
181
|
-
if (!result.colwidth.some(function (w) { return w > 0; })) {
|
|
182
|
-
result.colwidth = null;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return result;
|
|
186
|
-
};
|
|
187
|
-
/**
|
|
188
|
-
* @hidden
|
|
189
|
-
*/
|
|
190
|
-
exports.isCellEmpty = function (cell) {
|
|
191
|
-
var c = cell.content;
|
|
192
|
-
return c.childCount === 1 && c.firstChild.isTextblock && c.firstChild.childCount === 0;
|
|
193
|
-
};
|
|
194
|
-
var cellWrapping = function ($pos) {
|
|
195
|
-
for (var d = $pos.depth; d > 0; d--) {
|
|
196
|
-
// Sometimes the cell can be in the same depth.
|
|
197
|
-
var role = $pos.node(d).type.spec.tableRole;
|
|
198
|
-
if (role === 'cell' || role === 'header_cell') {
|
|
199
|
-
return $pos.node(d);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return null;
|
|
203
|
-
};
|
|
204
|
-
var ɵ3 = cellWrapping;
|
|
205
|
-
exports.ɵ3 = ɵ3;
|
|
206
|
-
/**
|
|
207
|
-
* @hidden
|
|
208
|
-
*/
|
|
209
|
-
// Split a selected cell, whose rowpan or colspan is greater than one,
|
|
210
|
-
// into smaller cells with the cell type (th, td) returned by getType function.
|
|
211
|
-
exports.splitCellWithType = function (getCellType) {
|
|
212
|
-
return function (state, dispatch) {
|
|
213
|
-
var sel = state.selection;
|
|
214
|
-
var cellNode;
|
|
215
|
-
var cellPos;
|
|
216
|
-
if (!(sel instanceof CellSelection_1.CellSelection)) {
|
|
217
|
-
cellNode = cellWrapping(sel.$from);
|
|
218
|
-
if (!cellNode) {
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
cellPos = cellAround(sel.$from).pos;
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
if (sel.$anchorCell.pos !== sel.$headCell.pos) {
|
|
225
|
-
return false;
|
|
226
|
-
}
|
|
227
|
-
cellNode = sel.$anchorCell.nodeAfter;
|
|
228
|
-
cellPos = sel.$anchorCell.pos;
|
|
229
|
-
}
|
|
230
|
-
if (cellNode.attrs.colspan === 1 && cellNode.attrs.rowspan === 1) {
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
if (dispatch) {
|
|
234
|
-
var baseAttrs = cellNode.attrs;
|
|
235
|
-
var attrs = [];
|
|
236
|
-
var colwidth = baseAttrs.colwidth;
|
|
237
|
-
if (baseAttrs.rowspan > 1) {
|
|
238
|
-
baseAttrs = exports.setAttr(baseAttrs, 'rowspan', 1);
|
|
239
|
-
}
|
|
240
|
-
if (baseAttrs.colspan > 1) {
|
|
241
|
-
baseAttrs = exports.setAttr(baseAttrs, 'colspan', 1);
|
|
242
|
-
}
|
|
243
|
-
var rect = exports.selectedRect(state);
|
|
244
|
-
var tr = state.tr;
|
|
245
|
-
for (var i = 0; i < rect.right - rect.left; i++) {
|
|
246
|
-
attrs.push(colwidth ? exports.setAttr(baseAttrs, 'colwidth', colwidth && colwidth[i] ? [colwidth[i]] : null) : baseAttrs);
|
|
247
|
-
}
|
|
248
|
-
var lastCell = void 0;
|
|
249
|
-
for (var row = rect.top; row < rect.bottom; row++) {
|
|
250
|
-
var pos = rect.map.positionAt(row, rect.left, rect.table);
|
|
251
|
-
if (row === rect.top) {
|
|
252
|
-
pos += cellNode.nodeSize;
|
|
253
|
-
}
|
|
254
|
-
for (var col = rect.left, i = 0; col < rect.right; col++, i++) {
|
|
255
|
-
if (col === rect.left && row === rect.top) {
|
|
256
|
-
continue;
|
|
257
|
-
}
|
|
258
|
-
tr.insert((lastCell = tr.mapping.map(pos + rect.tableStart, 1)), getCellType({ node: cellNode, row: row, col: col }).createAndFill(attrs[i]));
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
tr.setNodeMarkup(cellPos, getCellType({ node: cellNode, row: rect.top, col: rect.left }), attrs[0]);
|
|
262
|
-
if (sel instanceof CellSelection_1.CellSelection) {
|
|
263
|
-
tr.setSelection(new CellSelection_1.CellSelection(tr.doc.resolve(sel.$anchorCell.pos), lastCell && tr.doc.resolve(lastCell)));
|
|
264
|
-
}
|
|
265
|
-
dispatch(tr);
|
|
266
|
-
}
|
|
267
|
-
return true;
|
|
268
|
-
};
|
|
269
|
-
};
|
|
270
|
-
/**
|
|
271
|
-
* @hidden
|
|
272
|
-
*/
|
|
273
|
-
exports.pointsAtCell = function ($pos) {
|
|
274
|
-
return utils_1.isTableRow($pos.parent) && $pos.nodeAfter;
|
|
275
|
-
};
|
|
276
|
-
/**
|
|
277
|
-
* @hidden
|
|
278
|
-
*/
|
|
279
|
-
exports.inSameTable = function ($a, $b) {
|
|
280
|
-
return $a.depth === $b.depth && $a.pos >= $b.start(-1) && $a.pos <= $b.end(-1);
|
|
281
|
-
};
|
|
282
|
-
/**
|
|
283
|
-
* @hidden
|
|
284
|
-
*/
|
|
285
|
-
exports.cellsOverlapRectangle = function (_a, rect) {
|
|
286
|
-
var width = _a.width, height = _a.height, map = _a.map;
|
|
287
|
-
var indexTop = rect.top * width + rect.left;
|
|
288
|
-
var indexLeft = indexTop;
|
|
289
|
-
var indexBottom = (rect.bottom - 1) * width + rect.left;
|
|
290
|
-
var indexRight = indexTop + (rect.right - rect.left - 1);
|
|
291
|
-
for (var i = rect.top; i < rect.bottom; i++) {
|
|
292
|
-
if ((rect.left > 0 && map[indexLeft] === map[indexLeft - 1]) || (rect.right < width && map[indexRight] === map[indexRight + 1])) {
|
|
293
|
-
return true;
|
|
294
|
-
}
|
|
295
|
-
indexLeft += width;
|
|
296
|
-
indexRight += width;
|
|
297
|
-
}
|
|
298
|
-
for (var i = rect.left; i < rect.right; i++) {
|
|
299
|
-
if ((rect.top > 0 && map[indexTop] === map[indexTop - width]) ||
|
|
300
|
-
(rect.bottom < height && map[indexBottom] === map[indexBottom + width])) {
|
|
301
|
-
return true;
|
|
302
|
-
}
|
|
303
|
-
indexTop++;
|
|
304
|
-
indexBottom++;
|
|
305
|
-
}
|
|
306
|
-
return false;
|
|
307
|
-
};
|