@progress/kendo-react-editor 5.16.0-dev.202307211637 → 5.16.0

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.
@@ -0,0 +1,504 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.applyTableData = exports.tableDefaultData = exports.tablePositionStyles = exports.initialTableData = void 0;
15
+ var kendo_editor_common_1 = require("@progress/kendo-editor-common");
16
+ var tableEdit_1 = require("../tableEdit");
17
+ var utils_1 = require("./utils");
18
+ var utils_2 = require("../utils");
19
+ /**
20
+ * @hidden
21
+ */
22
+ var initialTableData = {
23
+ rows: 0,
24
+ columns: 0,
25
+ width: null,
26
+ widthUnit: '',
27
+ height: null,
28
+ heightUnit: '',
29
+ position: null,
30
+ textAlign: '',
31
+ cellPadding: null,
32
+ cellSpacing: null,
33
+ backgroundColor: undefined,
34
+ borderWidth: null,
35
+ borderColor: undefined,
36
+ borderStyle: null,
37
+ collapseBorders: false,
38
+ id: '',
39
+ className: '',
40
+ caption: '',
41
+ captionAlignment: null,
42
+ captionPosition: null,
43
+ headerRows: 0,
44
+ headerColumns: 0,
45
+ associateHeaders: 'none'
46
+ };
47
+ exports.initialTableData = initialTableData;
48
+ /**
49
+ * @hidden
50
+ */
51
+ var tablePositionStyles = {
52
+ left: { 'margin-left': '', 'margin-right': 'auto' },
53
+ center: { 'margin-left': 'auto', 'margin-right': 'auto' },
54
+ right: { 'margin-left': 'auto', 'margin-right': '' },
55
+ '': {}
56
+ };
57
+ exports.tablePositionStyles = tablePositionStyles;
58
+ var toCellsMap = function (map) {
59
+ var cells = [];
60
+ for (var h = 0; h < map.height; h++) {
61
+ var start = h * map.width;
62
+ var end = start + map.width;
63
+ cells.push(map.map.slice(start, end));
64
+ }
65
+ return cells;
66
+ };
67
+ var headerCellsCount = function (table, map) {
68
+ var headerRows = 0;
69
+ var headerColumns = 0;
70
+ var cells = toCellsMap(map);
71
+ cells.forEach(function (row) {
72
+ var headerCells = true;
73
+ row.forEach(function (cellPos) {
74
+ var cell = table.nodeAt(cellPos);
75
+ if (cell && cell.type.name !== 'table_header') {
76
+ headerCells = false;
77
+ }
78
+ });
79
+ if (headerCells) {
80
+ headerRows++;
81
+ }
82
+ });
83
+ for (var col = 0; col < map.width; col++) {
84
+ var headerCells = true;
85
+ for (var row = 0; row < map.height; row++) {
86
+ var cellPos = cells[row] && cells[row][col];
87
+ var cell = typeof cellPos === 'number' && table.nodeAt(cellPos);
88
+ if (cell && cell.type.name !== 'table_header') {
89
+ headerCells = false;
90
+ }
91
+ }
92
+ if (headerCells) {
93
+ headerColumns++;
94
+ }
95
+ }
96
+ return { rows: headerRows, columns: headerColumns };
97
+ };
98
+ var tableCellsPadding = function (table) {
99
+ var padding = new Set();
100
+ table.content.forEach(function (row) {
101
+ row.content.forEach(function (cell) {
102
+ padding.add((0, utils_1.parseStyle)(cell.attrs.style).padding || '');
103
+ });
104
+ });
105
+ return padding.size === 1 ? Array.from(padding)[0] : '';
106
+ };
107
+ var associateHeadersType = function (table) {
108
+ var useScope = true;
109
+ var useIds = true;
110
+ table.content.forEach(function (row) {
111
+ row.content.forEach(function (cell) {
112
+ var th = cell.type.name === 'table_header';
113
+ var td = cell.type.name === 'table_cell';
114
+ if (th && !cell.attrs.scope) {
115
+ useScope = false;
116
+ }
117
+ if ((th && !cell.attrs.id) || (td && !cell.attrs.headers)) {
118
+ useIds = false;
119
+ }
120
+ });
121
+ });
122
+ return useScope ? 'scope' : (useIds ? 'id' : 'none');
123
+ };
124
+ /**
125
+ * @hidden
126
+ */
127
+ var tableDefaultData = function (state) {
128
+ var _a, _b, _c;
129
+ var cells = (0, utils_1.selectedCells)(state);
130
+ var $pos = state.selection.$from;
131
+ var table = cells.length ? (0, utils_2.parentNode)($pos, function (n) { return n.type.spec.tableRole === 'table'; }) : null;
132
+ if (!table) {
133
+ return initialTableData;
134
+ }
135
+ var tableParent = (0, utils_2.parentNode)($pos, function (n) { return n.type.name === 'table_wrapper'; });
136
+ var captionStr = '';
137
+ var captionStyles = {};
138
+ var parentStyles = {};
139
+ if (tableParent) {
140
+ parentStyles = (0, utils_1.parseStyle)(tableParent.node.attrs.style);
141
+ tableParent.node.content.forEach(function (node) {
142
+ if (node.type.name === 'table_caption_external') {
143
+ var fr = (0, kendo_editor_common_1.pmDocToFragment)(node);
144
+ captionStr = (0, kendo_editor_common_1.fragmentToHtml)(fr);
145
+ captionStr = captionStr === '<img>' ? '' : captionStr;
146
+ captionStyles = (0, utils_1.parseStyle)(node.attrs.style);
147
+ }
148
+ });
149
+ }
150
+ var styles = (0, utils_1.parseStyle)(((_a = table.node.attrs) === null || _a === void 0 ? void 0 : _a.style) || '');
151
+ var map = kendo_editor_common_1.TableMap.get(table.node);
152
+ var pos = (parentStyles['margin-left'] === 'auto' && parentStyles['margin-right'] === 'auto') ? 'center' :
153
+ parentStyles['margin-right'] === 'auto' ? 'left' :
154
+ parentStyles['margin-left'] === 'auto' ? 'right' : null;
155
+ var headerCells = headerCellsCount(table.node, map);
156
+ var cellsPadding = tableCellsPadding(table.node);
157
+ return __assign(__assign(__assign(__assign(__assign(__assign({}, initialTableData), { columns: map.width, rows: map.height }), (0, utils_1.nodeSize)(table.node, 'width')), (tableParent && /%/.test(parentStyles.width || '') ? (0, utils_1.nodeSize)(tableParent.node, 'width') : {})), (0, utils_1.nodeSize)(table.node, 'height')), { textAlign: styles['text-align'] || '', position: pos || null, cellPadding: cellsPadding ? parseFloat(cellsPadding) : null, cellSpacing: styles['border-spacing'] ? parseFloat(styles['border-spacing']) : null, backgroundColor: styles['background-color'], borderWidth: styles['border-width'] ? parseFloat(styles['border-width']) : null, borderColor: styles['border-color'], borderStyle: styles['border-style'] || null, collapseBorders: styles['border-collapse'] === 'collapse', caption: captionStr || undefined, captionAlignment: captionStyles['text-align'] || null, captionPosition: captionStyles['caption-side'] || null, headerRows: headerCells.rows, headerColumns: headerCells.columns, associateHeaders: (headerCells.rows || headerCells.columns) ? associateHeadersType(table.node) : 'none', id: ((_b = table.node.attrs) === null || _b === void 0 ? void 0 : _b.id) || '', className: ((_c = table.node.attrs) === null || _c === void 0 ? void 0 : _c.class) || '' });
158
+ };
159
+ exports.tableDefaultData = tableDefaultData;
160
+ var lastCell = function (table) {
161
+ var lastRow = table.lastChild;
162
+ var cell = lastRow.lastChild;
163
+ return { node: cell, pos: table.content.size - cell.nodeSize };
164
+ };
165
+ var addTableNodes = function (state, tablePos, table, toAdd, command) {
166
+ var last = lastCell(table);
167
+ var cellPos = tablePos + last.pos;
168
+ var cell = state.doc.nodeAt(cellPos);
169
+ if (!cell) {
170
+ return state;
171
+ }
172
+ var res = state.doc.resolve(cellPos);
173
+ var sel = new kendo_editor_common_1.CellSelection(res, res);
174
+ var selTr = state.tr.setSelection(sel);
175
+ var resultState = state.apply(selTr);
176
+ for (var i = 0; i < toAdd; i++) {
177
+ command(resultState, function (tr) {
178
+ resultState = resultState.apply(tr);
179
+ });
180
+ }
181
+ return resultState;
182
+ };
183
+ var removeTableNodes = function (state, tablePos, toDelete, command) {
184
+ var resultState = state;
185
+ for (var i = 0; i < toDelete; i++) {
186
+ var table = resultState.doc.nodeAt(tablePos);
187
+ if (table) {
188
+ var last = lastCell(table);
189
+ var cellPos = tablePos + last.pos;
190
+ var res = resultState.doc.resolve(cellPos);
191
+ var selection = new kendo_editor_common_1.CellSelection(res, res);
192
+ var selTr = resultState.tr.setSelection(selection);
193
+ resultState = resultState.apply(selTr);
194
+ command(resultState, function (tr) {
195
+ resultState = resultState.apply(tr);
196
+ });
197
+ }
198
+ }
199
+ return resultState;
200
+ };
201
+ var resizeTable = function (state, tablePos, rows, columns) {
202
+ var nextState = state;
203
+ var table = nextState.doc.nodeAt(tablePos);
204
+ if (!table) {
205
+ return nextState;
206
+ }
207
+ var map = kendo_editor_common_1.TableMap.get(table);
208
+ if (map.width === columns && map.height === rows) {
209
+ return nextState;
210
+ }
211
+ if (columns > map.width) {
212
+ nextState = addTableNodes(nextState, tablePos, table, columns - map.width, kendo_editor_common_1.addColumnAfter);
213
+ }
214
+ else if (columns < map.width) {
215
+ nextState = removeTableNodes(nextState, tablePos, map.width - columns, tableEdit_1.deleteColumnCmd);
216
+ }
217
+ table = nextState.doc.nodeAt(tablePos);
218
+ if (!table) {
219
+ return nextState;
220
+ }
221
+ map = kendo_editor_common_1.TableMap.get(table);
222
+ if (rows > map.height) {
223
+ nextState = addTableNodes(nextState, tablePos, table, rows - map.height, kendo_editor_common_1.addRowAfter);
224
+ }
225
+ else if (rows < map.height) {
226
+ nextState = removeTableNodes(nextState, tablePos, map.height - rows, tableEdit_1.deleteRowCmd);
227
+ }
228
+ return nextState;
229
+ };
230
+ var setTableStyles = function (state, data, tablePos) {
231
+ var table = state.doc.nodeAt(tablePos);
232
+ if (!table) {
233
+ return state;
234
+ }
235
+ var attrs = __assign({}, table.attrs);
236
+ var shouldSetWidth = data.width !== null && (data.widthUnit !== '%' || (!data.caption && !data.position));
237
+ attrs = (0, utils_1.setNodeStyle)(attrs, 'width', shouldSetWidth ? data.width + data.widthUnit : '');
238
+ attrs = (0, utils_1.setNodeStyle)(attrs, 'height', data.height !== null ? data.height + data.heightUnit : '');
239
+ attrs = (0, utils_1.setNodeStyle)(attrs, 'text-align', data.textAlign || '');
240
+ attrs = (0, utils_1.setNodeStyle)(attrs, 'background-color', data.backgroundColor || '');
241
+ attrs = (0, utils_1.setNodeStyle)(attrs, 'border-width', data.borderWidth ? data.borderWidth + 'px' : '');
242
+ attrs = (0, utils_1.setNodeStyle)(attrs, 'border-style', data.borderStyle || '');
243
+ attrs = (0, utils_1.setNodeStyle)(attrs, 'border-color', data.borderColor || '');
244
+ attrs = (0, utils_1.setNodeStyle)(attrs, 'border-spacing', data.cellSpacing !== null ? data.cellSpacing + 'px' : '');
245
+ if (data.cellSpacing !== null) {
246
+ attrs = (0, utils_1.setNodeStyle)(attrs, 'border-collapse', 'unset');
247
+ }
248
+ else {
249
+ attrs = (0, utils_1.setNodeStyle)(attrs, 'border-collapse', data.collapseBorders ? 'collapse' : '');
250
+ }
251
+ var posStyles = tablePositionStyles[data.position || ''] || {};
252
+ Object.keys(posStyles).forEach(function (style) {
253
+ attrs = (0, utils_1.setNodeStyle)(attrs, style, posStyles[style]);
254
+ });
255
+ attrs.id = data.id || null;
256
+ attrs.class = data.className || null;
257
+ var tr = state.tr.setNodeMarkup(tablePos, null, attrs);
258
+ state = state.apply(tr);
259
+ return state;
260
+ };
261
+ var setCellType = function (state, cell, pos, type, attrs) {
262
+ if (cell.type.name !== type.name || Object.keys(attrs).length > 0) {
263
+ var tr = state.tr.setNodeMarkup(pos, type, __assign(__assign({}, cell.attrs), attrs));
264
+ return state.apply(tr);
265
+ }
266
+ return state;
267
+ };
268
+ var resetId = function (cell, attrs) {
269
+ if (/^cell-[0-9]+-[0-9]+$/.test(cell.attrs.id || '')) {
270
+ attrs.id = null;
271
+ }
272
+ };
273
+ var setTableHeaderCells = function (state, data, tablePos) {
274
+ var table = state.doc.nodeAt(tablePos);
275
+ var map = table && kendo_editor_common_1.TableMap.get(table);
276
+ if (!table || !map) {
277
+ return state;
278
+ }
279
+ var cells = toCellsMap(map);
280
+ var newState = state;
281
+ var _a = state.schema.nodes, table_header = _a.table_header, table_cell = _a.table_cell;
282
+ var id = String(new Date().getTime());
283
+ var ids = [];
284
+ var cellId = function (row, col) {
285
+ var result = "cell-".concat(row).concat(col, "-").concat(id);
286
+ if (!ids[row]) {
287
+ ids.push([]);
288
+ }
289
+ if (!ids[row][col]) {
290
+ ids[row].push([]);
291
+ }
292
+ ids[row][col] = result;
293
+ return result;
294
+ };
295
+ var headers = function (row, col, colHeader, rowHeader) {
296
+ var result = [];
297
+ if (rowHeader) {
298
+ for (var r = 0; r < row; r++) {
299
+ if (ids[r] && ids[r][col]) {
300
+ result.push(ids[r][col]);
301
+ }
302
+ }
303
+ }
304
+ if (colHeader) {
305
+ for (var c = 0; c < col; c++) {
306
+ if (ids[row] && ids[row][c]) {
307
+ result.push(ids[row][c]);
308
+ }
309
+ }
310
+ }
311
+ return result.join(' ');
312
+ };
313
+ cells.forEach(function (row, rowIndex) {
314
+ row.forEach(function (cellPos, cellIndex) {
315
+ var cell = table.nodeAt(cellPos);
316
+ if (cell) {
317
+ var colHeader = cellIndex < data.headerColumns;
318
+ var rowHeader = rowIndex < data.headerRows;
319
+ var attrs = __assign({}, cell.attrs);
320
+ resetId(cell, attrs);
321
+ attrs.headers = null;
322
+ attrs.scope = null;
323
+ if (rowHeader || colHeader) {
324
+ if (data.associateHeaders === 'scope') {
325
+ attrs.scope = rowHeader ? 'col' : 'row';
326
+ }
327
+ if (data.associateHeaders === 'id') {
328
+ attrs.id = cellId(rowIndex, cellIndex);
329
+ if (cellIndex > 0 || rowIndex > 0) {
330
+ attrs.headers = headers(rowIndex, cellIndex, colHeader, rowHeader) || null;
331
+ }
332
+ }
333
+ newState = setCellType(newState, cell, tablePos + cellPos + 1, table_header, attrs);
334
+ }
335
+ else {
336
+ if (data.associateHeaders === 'id') {
337
+ attrs.headers = headers(rowIndex, cellIndex, data.headerColumns > 0, data.headerRows > 0) || null;
338
+ }
339
+ newState = setCellType(newState, cell, tablePos + cellPos + 1, table_cell, attrs);
340
+ }
341
+ }
342
+ });
343
+ });
344
+ return newState;
345
+ };
346
+ var setTablePosition = function (state, wrapperNode, wrapperPos, styles) {
347
+ var attrs = __assign({}, wrapperNode.attrs);
348
+ attrs = (0, utils_1.setNodeStyle)(attrs, 'margin-left', '');
349
+ attrs = (0, utils_1.setNodeStyle)(attrs, 'margin-right', '');
350
+ Object.keys(styles || {}).forEach(function (s) {
351
+ attrs = (0, utils_1.setNodeStyle)(attrs, s, (styles || {})[s] || '');
352
+ });
353
+ return state.apply(state.tr.setNodeMarkup(wrapperPos, null, attrs));
354
+ };
355
+ var parseCaptionContent = function (content, schema) {
356
+ var doc = (0, kendo_editor_common_1.parseContent)('<p>' + content + '</p>', schema);
357
+ return doc.content.firstChild.content;
358
+ };
359
+ var createCaption = function (data, schema) {
360
+ if (!data.caption) {
361
+ return;
362
+ }
363
+ var captAttrs = { caption: '', style: 'display: table-caption' };
364
+ if (data.captionAlignment) {
365
+ captAttrs = (0, utils_1.setNodeStyle)(captAttrs, 'text-align', data.captionAlignment);
366
+ }
367
+ if (data.captionPosition) {
368
+ captAttrs = (0, utils_1.setNodeStyle)(captAttrs, 'caption-side', data.captionPosition);
369
+ }
370
+ var captionContent = parseCaptionContent(data.caption, schema);
371
+ var captionNode = (captionContent && schema.nodes.table_caption_external.createAndFill(captAttrs, captionContent)) || undefined;
372
+ return captionNode;
373
+ };
374
+ var hasCaption = function (wrapperNode) {
375
+ return wrapperNode.firstChild && wrapperNode.firstChild.type.name === 'table_caption_external';
376
+ };
377
+ var setTableCaption = function (state, wrapperNode, wrapperPos, data) {
378
+ var nextState = state;
379
+ var captionNode;
380
+ var captContentPos = wrapperPos + 2;
381
+ var captPos = wrapperPos + 1;
382
+ var schema = nextState.schema;
383
+ if (hasCaption(wrapperNode)) {
384
+ captionNode = wrapperNode.firstChild;
385
+ if (data.caption) {
386
+ var captionContent = parseCaptionContent(data.caption, schema);
387
+ nextState = nextState.apply(nextState.tr.replaceWith(captContentPos, captContentPos + captionNode.content.size, captionContent));
388
+ captionNode = nextState.doc.nodeAt(captPos);
389
+ if (captionNode) {
390
+ var captAttrs = __assign({}, captionNode.attrs);
391
+ captAttrs = (0, utils_1.setNodeStyle)(captAttrs, 'text-align', data.captionAlignment || '');
392
+ captAttrs = (0, utils_1.setNodeStyle)(captAttrs, 'caption-side', data.captionPosition || '');
393
+ nextState = nextState.apply(nextState.tr.setNodeAttribute(captPos, 'style', captAttrs.style));
394
+ }
395
+ }
396
+ else {
397
+ nextState = nextState.apply(nextState.tr.deleteRange(captContentPos, captContentPos + captionNode.content.size));
398
+ }
399
+ }
400
+ else {
401
+ captionNode = createCaption(data, schema);
402
+ if (captionNode) {
403
+ nextState = nextState.apply(nextState.tr.replaceWith(captPos, captPos, captionNode));
404
+ }
405
+ }
406
+ return nextState;
407
+ };
408
+ var updateWrapper = function (state, data, tablePos, tableWrapper, tableWrapperPos) {
409
+ var result = {
410
+ state: state,
411
+ pos: tablePos
412
+ };
413
+ if (!tableWrapper && (data.position || data.caption)) {
414
+ var wrapperAttrs_1 = { table: '', style: 'display: table' };
415
+ var children = [];
416
+ var position = data.position;
417
+ var posStyles_1 = position && tablePositionStyles[position];
418
+ if (posStyles_1) {
419
+ Object.keys(posStyles_1).forEach(function (styleName) {
420
+ wrapperAttrs_1 = (0, utils_1.setNodeStyle)(wrapperAttrs_1, styleName, posStyles_1[styleName] || '');
421
+ });
422
+ }
423
+ if (typeof data.width === 'number' && data.widthUnit === '%') {
424
+ wrapperAttrs_1 = (0, utils_1.setNodeStyle)(wrapperAttrs_1, 'width', data.width + data.widthUnit);
425
+ }
426
+ var captionNode = createCaption(data, state.schema);
427
+ if (captionNode) {
428
+ children.push(captionNode);
429
+ }
430
+ var table = state.doc.nodeAt(tablePos);
431
+ children.push(table);
432
+ var createdWrapper = state.schema.nodes.table_wrapper.createAndFill(wrapperAttrs_1, children);
433
+ if (createdWrapper) {
434
+ var tr = state.tr.replaceWith(tablePos, tablePos + table.content.size, createdWrapper);
435
+ state = state.apply(tr);
436
+ result = { state: state, pos: tablePos };
437
+ }
438
+ }
439
+ else if (tableWrapper && (data.position || data.caption || (!data.caption && hasCaption(tableWrapper.node)))) {
440
+ state = setTablePosition(state, tableWrapper.node, tableWrapperPos, data.position && tablePositionStyles[data.position]);
441
+ state = setTableCaption(state, tableWrapper.node, tableWrapperPos, data);
442
+ result = { state: state, pos: tableWrapperPos };
443
+ }
444
+ else if (tableWrapper && !(data.position || data.caption)) {
445
+ result = { state: state, node: tableWrapper.node, pos: state.selection.$from.start(tableWrapper.depth) - 1 };
446
+ }
447
+ else {
448
+ result = { state: state, pos: tablePos };
449
+ }
450
+ var wrapper = tableWrapper && result.state.doc.nodeAt(tableWrapperPos);
451
+ if (wrapper) {
452
+ var attrs = void 0;
453
+ if (typeof data.width === 'number' && data.widthUnit === '%') {
454
+ attrs = (0, utils_1.setNodeStyle)(wrapper.attrs, 'width', data.width + data.widthUnit);
455
+ }
456
+ else if (data.widthUnit !== '%' && /%/.test((0, utils_1.parseStyle)(wrapper.attrs.style || '').width || '')) {
457
+ attrs = (0, utils_1.setNodeStyle)(wrapper.attrs, 'width', '');
458
+ }
459
+ if (attrs) {
460
+ result.state = result.state.apply(result.state.tr.setNodeMarkup(tableWrapperPos, null, attrs));
461
+ }
462
+ }
463
+ return result;
464
+ };
465
+ /**
466
+ * @hidden
467
+ */
468
+ var applyTableData = function (state, data) {
469
+ var $from = state.selection.$from;
470
+ var table = (0, utils_2.parentNode)($from, function (n) { return n.type.spec.tableRole === 'table'; });
471
+ if (!table) {
472
+ return;
473
+ }
474
+ var tablePos = $from.start(table.depth) - 1;
475
+ var nextState = resizeTable(state, tablePos, data.rows, data.columns);
476
+ if (!nextState) {
477
+ return;
478
+ }
479
+ var transaction = nextState.tr;
480
+ (0, utils_1.tableCells)(nextState).forEach(function (cell) {
481
+ var attrs = __assign({}, cell.node.attrs);
482
+ attrs = (0, utils_1.setNodeStyle)(attrs, 'padding', typeof data.cellPadding === 'number' ? data.cellPadding + 'px' : '');
483
+ transaction.setNodeMarkup(cell.pos, null, attrs);
484
+ });
485
+ nextState = nextState.apply(transaction);
486
+ nextState = setTableStyles(nextState, data, tablePos);
487
+ nextState = setTableHeaderCells(nextState, data, tablePos);
488
+ var tableParent = (0, utils_2.parentNode)($from, function (n) { return n.type.name === 'table_wrapper'; });
489
+ var tableParentPos = $from.start((tableParent === null || tableParent === void 0 ? void 0 : tableParent.depth) || 0) - 1;
490
+ var result = updateWrapper(nextState, data, tablePos, tableParent, tableParentPos);
491
+ nextState = result.state;
492
+ var from = result.pos;
493
+ var node = nextState.doc.nodeAt(result.pos);
494
+ if (!node) {
495
+ return;
496
+ }
497
+ var to = from + (tableParent || table).node.content.size;
498
+ var tr = state.tr.replaceWith(from, to, node);
499
+ var atEnd = kendo_editor_common_1.Selection.atEnd(node);
500
+ var selection = kendo_editor_common_1.TextSelection.create(tr.doc, from + atEnd.to + 1);
501
+ tr.setSelection(selection);
502
+ return tr;
503
+ };
504
+ exports.applyTableData = applyTableData;
@@ -1,4 +1,4 @@
1
- import { Node } from '@progress/kendo-editor-common';
1
+ import { EditorState, Node } from '@progress/kendo-editor-common';
2
2
  /**
3
3
  * @hidden
4
4
  */
@@ -23,3 +23,17 @@ export declare const parseStyle: (styleText: string | null) => {
23
23
  * @hidden
24
24
  */
25
25
  export declare function setNodeStyle(nodeAttrs: any, styleType: string, value: string): any;
26
+ /**
27
+ * @hidden
28
+ */
29
+ export declare const selectedCells: (state: EditorState) => Array<{
30
+ node: Node;
31
+ pos: number;
32
+ }>;
33
+ /**
34
+ * @hidden
35
+ */
36
+ export declare const tableCells: (state: EditorState) => Array<{
37
+ node: Node;
38
+ pos: number;
39
+ }>;
@@ -11,7 +11,9 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.setNodeStyle = exports.parseStyle = exports.nodeSize = exports.getUnit = exports.reUnit = void 0;
14
+ exports.tableCells = exports.selectedCells = exports.setNodeStyle = exports.parseStyle = exports.nodeSize = exports.getUnit = exports.reUnit = void 0;
15
+ var kendo_editor_common_1 = require("@progress/kendo-editor-common");
16
+ var utils_1 = require("../utils");
15
17
  /**
16
18
  * @hidden
17
19
  */
@@ -95,3 +97,57 @@ function setNodeStyle(nodeAttrs, styleType, value) {
95
97
  return attrs;
96
98
  }
97
99
  exports.setNodeStyle = setNodeStyle;
100
+ var getCells = function (state) {
101
+ var doc = state.doc, selection = state.selection;
102
+ var result = [];
103
+ selection.ranges.forEach(function (range) {
104
+ var from = range.$from.pos;
105
+ var to = range.$to.pos;
106
+ doc.nodesBetween(from, to, function (node, pos, _parent, _index) {
107
+ if (node.type.name === 'table_cell' || node.type.name === 'table_header') {
108
+ result.push({ node: node, pos: pos });
109
+ }
110
+ });
111
+ });
112
+ return result;
113
+ };
114
+ /**
115
+ * @hidden
116
+ */
117
+ var selectedCells = function (state) {
118
+ var startNodeTable = (0, utils_1.parentNode)(state.selection.$from, function (n) { return n.type.name === 'table'; });
119
+ var endNodeTable = (0, utils_1.parentNode)(state.selection.$to, function (n) { return n.type.name === 'table'; });
120
+ if (startNodeTable && endNodeTable && startNodeTable.depth === endNodeTable.depth && startNodeTable.node.eq(endNodeTable.node)) {
121
+ var cells = getCells(state).filter(function (_a) {
122
+ var pos = _a.pos;
123
+ var parentTable = (0, utils_1.parentNode)(state.doc.resolve(pos), function (n) { return n.type.name === 'table'; });
124
+ return parentTable && parentTable.depth === startNodeTable.depth && startNodeTable.node.eq(parentTable.node);
125
+ });
126
+ return cells;
127
+ }
128
+ return [];
129
+ };
130
+ exports.selectedCells = selectedCells;
131
+ /**
132
+ * @hidden
133
+ */
134
+ var tableCells = function (state) {
135
+ var cells = [];
136
+ if ((0, exports.selectedCells)(state).length) {
137
+ var $pos = state.selection.$from;
138
+ var parentTable = (0, utils_1.parentNode)($pos, function (n) { return n.type.spec.tableRole === 'table'; });
139
+ if (parentTable === null) {
140
+ return cells;
141
+ }
142
+ var tablePos_1 = $pos.start(parentTable.depth);
143
+ var tableNode = parentTable.node;
144
+ var map = kendo_editor_common_1.TableMap.get(tableNode);
145
+ var doc_1 = state.doc;
146
+ map.map.forEach(function (m) {
147
+ var pos = m + tablePos_1;
148
+ cells.push({ pos: pos, node: doc_1.nodeAt(pos) });
149
+ });
150
+ }
151
+ return cells;
152
+ };
153
+ exports.tableCells = tableCells;