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