@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.
- package/dist/cdn/js/kendo-react-editor.js +1 -1
- 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/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
|
@@ -37,336 +37,10 @@ import { Window, WindowActionsBar } from '@progress/kendo-react-dialogs';
|
|
|
37
37
|
import { TabStrip, TabStripTab } from '@progress/kendo-react-layout';
|
|
38
38
|
import { tableAlignMiddleCenterIcon, tableAlignMiddleLeftIcon, tableAlignMiddleRightIcon, tableAlignRemoveIcon, tablePropertiesIcon, tablePositionStartIcon, tablePositionCenterIcon, tablePositionEndIcon, positionTopIcon, positionBottomIcon } from '@progress/kendo-svg-icons';
|
|
39
39
|
import { borderStyles, onDownPreventDefault, popupSettings, units, parentNode } from './../utils';
|
|
40
|
-
import {
|
|
41
|
-
import { itemRenderWithIcon, selectedCells, tableCells, valueRenderWithIcon } from './tableCellProperties';
|
|
42
|
-
import { Selection, TableMap, TextSelection, addColumnAfter, addRowAfter, pmDocToFragment, fragmentToHtml, parseContent, CellSelection } from '@progress/kendo-editor-common';
|
|
43
|
-
import { deleteColumnCmd, deleteRowCmd } from '../tableEdit';
|
|
40
|
+
import { itemRenderWithIcon, valueRenderWithIcon } from './tableCellProperties';
|
|
44
41
|
import { useLocalization } from '@progress/kendo-react-intl';
|
|
45
42
|
import { messages, keys } from './../../messages';
|
|
46
|
-
|
|
47
|
-
var lastRow = table.lastChild;
|
|
48
|
-
var cell = lastRow.lastChild;
|
|
49
|
-
return { node: cell, pos: table.content.size - cell.nodeSize };
|
|
50
|
-
};
|
|
51
|
-
var addTableNodes = function (state, tablePos, table, toAdd, command) {
|
|
52
|
-
var last = lastCell(table);
|
|
53
|
-
var cellPos = tablePos + last.pos;
|
|
54
|
-
var cell = state.doc.nodeAt(cellPos);
|
|
55
|
-
if (!cell) {
|
|
56
|
-
return state;
|
|
57
|
-
}
|
|
58
|
-
var res = state.doc.resolve(cellPos);
|
|
59
|
-
var sel = new CellSelection(res, res);
|
|
60
|
-
var selTr = state.tr.setSelection(sel);
|
|
61
|
-
var resultState = state.apply(selTr);
|
|
62
|
-
for (var i = 0; i < toAdd; i++) {
|
|
63
|
-
command(resultState, function (tr) {
|
|
64
|
-
resultState = resultState.apply(tr);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return resultState;
|
|
68
|
-
};
|
|
69
|
-
var removeTableNodes = function (state, tablePos, toDelete, command) {
|
|
70
|
-
var resultState = state;
|
|
71
|
-
for (var i = 0; i < toDelete; i++) {
|
|
72
|
-
var table = resultState.doc.nodeAt(tablePos);
|
|
73
|
-
if (table) {
|
|
74
|
-
var last = lastCell(table);
|
|
75
|
-
var cellPos = tablePos + last.pos;
|
|
76
|
-
var res = resultState.doc.resolve(cellPos);
|
|
77
|
-
var selection = new CellSelection(res, res);
|
|
78
|
-
var selTr = resultState.tr.setSelection(selection);
|
|
79
|
-
resultState = resultState.apply(selTr);
|
|
80
|
-
command(resultState, function (tr) {
|
|
81
|
-
resultState = resultState.apply(tr);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return resultState;
|
|
86
|
-
};
|
|
87
|
-
var resizeTable = function (state, tablePos, rows, columns) {
|
|
88
|
-
var nextState = state;
|
|
89
|
-
var table = nextState.doc.nodeAt(tablePos);
|
|
90
|
-
if (!table) {
|
|
91
|
-
return nextState;
|
|
92
|
-
}
|
|
93
|
-
var map = TableMap.get(table);
|
|
94
|
-
if (map.width === columns && map.height === rows) {
|
|
95
|
-
return nextState;
|
|
96
|
-
}
|
|
97
|
-
if (columns > map.width) {
|
|
98
|
-
nextState = addTableNodes(nextState, tablePos, table, columns - map.width, addColumnAfter);
|
|
99
|
-
}
|
|
100
|
-
else if (columns < map.width) {
|
|
101
|
-
nextState = removeTableNodes(nextState, tablePos, map.width - columns, deleteColumnCmd);
|
|
102
|
-
}
|
|
103
|
-
table = nextState.doc.nodeAt(tablePos);
|
|
104
|
-
if (!table) {
|
|
105
|
-
return nextState;
|
|
106
|
-
}
|
|
107
|
-
map = TableMap.get(table);
|
|
108
|
-
if (rows > map.height) {
|
|
109
|
-
nextState = addTableNodes(nextState, tablePos, table, rows - map.height, addRowAfter);
|
|
110
|
-
}
|
|
111
|
-
else if (rows < map.height) {
|
|
112
|
-
nextState = removeTableNodes(nextState, tablePos, map.height - rows, deleteRowCmd);
|
|
113
|
-
}
|
|
114
|
-
return nextState;
|
|
115
|
-
};
|
|
116
|
-
var setTableStyles = function (state, data, tablePos) {
|
|
117
|
-
var _a;
|
|
118
|
-
var table = state.doc.nodeAt(tablePos);
|
|
119
|
-
if (!table) {
|
|
120
|
-
return state;
|
|
121
|
-
}
|
|
122
|
-
var attrs = __assign({}, table.attrs);
|
|
123
|
-
attrs = setNodeStyle(attrs, 'width', data.width !== null ? data.width + data.widthUnit : '');
|
|
124
|
-
attrs = setNodeStyle(attrs, 'height', data.height !== null ? data.height + data.heightUnit : '');
|
|
125
|
-
attrs = setNodeStyle(attrs, 'text-align', data.textAlign || '');
|
|
126
|
-
attrs = setNodeStyle(attrs, 'background-color', data.backgroundColor || '');
|
|
127
|
-
attrs = setNodeStyle(attrs, 'border-width', data.borderWidth ? data.borderWidth + 'px' : '');
|
|
128
|
-
attrs = setNodeStyle(attrs, 'border-style', data.borderStyle || '');
|
|
129
|
-
attrs = setNodeStyle(attrs, 'border-color', data.borderColor || '');
|
|
130
|
-
attrs = setNodeStyle(attrs, 'border-spacing', data.cellSpacing !== null ? data.cellSpacing + 'px' : '');
|
|
131
|
-
if (data.cellSpacing !== null) {
|
|
132
|
-
attrs = setNodeStyle(attrs, 'border-collapse', 'unset');
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
attrs = setNodeStyle(attrs, 'border-collapse', data.collapseBorders ? 'collapse' : '');
|
|
136
|
-
}
|
|
137
|
-
var posStyles = ((_a = data.position) === null || _a === void 0 ? void 0 : _a.style) || {};
|
|
138
|
-
Object.keys(posStyles).forEach(function (style) {
|
|
139
|
-
attrs = setNodeStyle(attrs, style, posStyles[style]);
|
|
140
|
-
});
|
|
141
|
-
attrs.id = data.id || null;
|
|
142
|
-
attrs.class = data.className || null;
|
|
143
|
-
var tr = state.tr.setNodeMarkup(tablePos, null, attrs);
|
|
144
|
-
state = state.apply(tr);
|
|
145
|
-
return state;
|
|
146
|
-
};
|
|
147
|
-
var toCellsMap = function (map) {
|
|
148
|
-
var cells = [];
|
|
149
|
-
for (var h = 0; h < map.height; h++) {
|
|
150
|
-
var start = h * map.width;
|
|
151
|
-
var end = start + map.width;
|
|
152
|
-
cells.push(map.map.slice(start, end));
|
|
153
|
-
}
|
|
154
|
-
return cells;
|
|
155
|
-
};
|
|
156
|
-
var headerCellsCount = function (table, map) {
|
|
157
|
-
var headerRows = 0;
|
|
158
|
-
var headerColumns = 0;
|
|
159
|
-
var cells = toCellsMap(map);
|
|
160
|
-
cells.forEach(function (row) {
|
|
161
|
-
var headerCells = true;
|
|
162
|
-
row.forEach(function (cellPos) {
|
|
163
|
-
var cell = table.nodeAt(cellPos);
|
|
164
|
-
if (cell && cell.type.name !== 'table_header') {
|
|
165
|
-
headerCells = false;
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
if (headerCells) {
|
|
169
|
-
headerRows++;
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
for (var col = 0; col < map.width; col++) {
|
|
173
|
-
var headerCells = true;
|
|
174
|
-
for (var row = 0; row < map.height; row++) {
|
|
175
|
-
var cellPos = cells[row] && cells[row][col];
|
|
176
|
-
var cell = typeof cellPos === 'number' && table.nodeAt(cellPos);
|
|
177
|
-
if (cell && cell.type.name !== 'table_header') {
|
|
178
|
-
headerCells = false;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
if (headerCells) {
|
|
182
|
-
headerColumns++;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return { rows: headerRows, columns: headerColumns };
|
|
186
|
-
};
|
|
187
|
-
var setCellType = function (state, cell, pos, type, attrs) {
|
|
188
|
-
if (cell.type.name !== type.name || Object.keys(attrs).length > 0) {
|
|
189
|
-
var tr = state.tr.setNodeMarkup(pos, type, __assign(__assign({}, cell.attrs), attrs));
|
|
190
|
-
return state.apply(tr);
|
|
191
|
-
}
|
|
192
|
-
return state;
|
|
193
|
-
};
|
|
194
|
-
var resetId = function (cell, attrs) {
|
|
195
|
-
if (/^cell-[0-9]+-[0-9]+$/.test(cell.attrs.id || '')) {
|
|
196
|
-
attrs.id = null;
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
var setTableHeaderCells = function (state, data, tablePos) {
|
|
200
|
-
var table = state.doc.nodeAt(tablePos);
|
|
201
|
-
var map = table && TableMap.get(table);
|
|
202
|
-
if (!table || !map) {
|
|
203
|
-
return state;
|
|
204
|
-
}
|
|
205
|
-
// const headerCells = headerCellsCount(table, map);
|
|
206
|
-
// if (data.headerRows === headerCells.rows && data.headerColumns === headerCells.columns) {
|
|
207
|
-
// return state;
|
|
208
|
-
// }
|
|
209
|
-
var cells = toCellsMap(map);
|
|
210
|
-
var newState = state;
|
|
211
|
-
var _a = state.schema.nodes, table_header = _a.table_header, table_cell = _a.table_cell;
|
|
212
|
-
var id = String(new Date().getTime());
|
|
213
|
-
var ids = [];
|
|
214
|
-
var cellId = function (row, col) {
|
|
215
|
-
var result = "cell-".concat(row).concat(col, "-").concat(id);
|
|
216
|
-
if (!ids[row]) {
|
|
217
|
-
ids.push([]);
|
|
218
|
-
}
|
|
219
|
-
if (!ids[row][col]) {
|
|
220
|
-
ids[row].push([]);
|
|
221
|
-
}
|
|
222
|
-
ids[row][col] = result;
|
|
223
|
-
return result;
|
|
224
|
-
};
|
|
225
|
-
var headers = function (row, col, colHeader, rowHeader) {
|
|
226
|
-
var result = [];
|
|
227
|
-
if (rowHeader) {
|
|
228
|
-
for (var r = 0; r < row; r++) {
|
|
229
|
-
if (ids[r] && ids[r][col]) {
|
|
230
|
-
result.push(ids[r][col]);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
if (colHeader) {
|
|
235
|
-
for (var c = 0; c < col; c++) {
|
|
236
|
-
if (ids[row] && ids[row][c]) {
|
|
237
|
-
result.push(ids[row][c]);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return result.join(' ');
|
|
242
|
-
};
|
|
243
|
-
cells.forEach(function (row, rowIndex) {
|
|
244
|
-
row.forEach(function (cellPos, cellIndex) {
|
|
245
|
-
var cell = table.nodeAt(cellPos);
|
|
246
|
-
if (cell) {
|
|
247
|
-
var colHeader = cellIndex < data.headerColumns;
|
|
248
|
-
var rowHeader = rowIndex < data.headerRows;
|
|
249
|
-
var attrs = __assign({}, cell.attrs);
|
|
250
|
-
resetId(cell, attrs);
|
|
251
|
-
attrs.headers = null;
|
|
252
|
-
attrs.scope = null;
|
|
253
|
-
if (rowHeader || colHeader) {
|
|
254
|
-
if (data.associateHeaders === 'scope') {
|
|
255
|
-
attrs.scope = rowHeader ? 'col' : 'row';
|
|
256
|
-
}
|
|
257
|
-
if (data.associateHeaders === 'id') {
|
|
258
|
-
attrs.id = cellId(rowIndex, cellIndex);
|
|
259
|
-
if (cellIndex > 0 || rowIndex > 0) {
|
|
260
|
-
attrs.headers = headers(rowIndex, cellIndex, colHeader, rowHeader) || null;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
newState = setCellType(newState, cell, tablePos + cellPos + 1, table_header, attrs);
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
if (data.associateHeaders === 'id') {
|
|
267
|
-
attrs.headers = headers(rowIndex, cellIndex, data.headerColumns > 0, data.headerRows > 0) || null;
|
|
268
|
-
}
|
|
269
|
-
newState = setCellType(newState, cell, tablePos + cellPos + 1, table_cell, attrs);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
return newState;
|
|
275
|
-
};
|
|
276
|
-
var setTablePosition = function (state, wrapperNode, wrapperPos, styles) {
|
|
277
|
-
var attrs = __assign({}, wrapperNode.attrs);
|
|
278
|
-
attrs = setNodeStyle(attrs, 'margin-left', '');
|
|
279
|
-
attrs = setNodeStyle(attrs, 'margin-right', '');
|
|
280
|
-
Object.keys(styles || {}).forEach(function (s) {
|
|
281
|
-
attrs = setNodeStyle(attrs, s, (styles || {})[s] || '');
|
|
282
|
-
});
|
|
283
|
-
return state.apply(state.tr.setNodeMarkup(wrapperPos, null, attrs));
|
|
284
|
-
};
|
|
285
|
-
var parseCaptionContent = function (content, schema) {
|
|
286
|
-
var doc = parseContent('<p>' + content + '</p>', schema);
|
|
287
|
-
return doc.content.firstChild.content;
|
|
288
|
-
};
|
|
289
|
-
var createCaption = function (data, schema) {
|
|
290
|
-
if (!data.caption) {
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
var captAttrs = { caption: '', style: 'display: table-caption' };
|
|
294
|
-
if (data.captionAlignment) {
|
|
295
|
-
captAttrs = setNodeStyle(captAttrs, 'text-align', data.captionAlignment);
|
|
296
|
-
}
|
|
297
|
-
if (data.captionPosition) {
|
|
298
|
-
captAttrs = setNodeStyle(captAttrs, 'caption-side', data.captionPosition);
|
|
299
|
-
}
|
|
300
|
-
var captionContent = parseCaptionContent(data.caption, schema);
|
|
301
|
-
var captionNode = (captionContent && schema.nodes.table_caption_external.createAndFill(captAttrs, captionContent)) || undefined;
|
|
302
|
-
return captionNode;
|
|
303
|
-
};
|
|
304
|
-
var hasCaption = function (wrapperNode) {
|
|
305
|
-
return wrapperNode.firstChild && wrapperNode.firstChild.type.name === 'table_caption_external';
|
|
306
|
-
};
|
|
307
|
-
var setTableCaption = function (state, wrapperNode, wrapperPos, data) {
|
|
308
|
-
var nextState = state;
|
|
309
|
-
var captionNode;
|
|
310
|
-
var captContentPos = wrapperPos + 2;
|
|
311
|
-
var captPos = wrapperPos + 1;
|
|
312
|
-
var schema = nextState.schema;
|
|
313
|
-
if (hasCaption(wrapperNode)) {
|
|
314
|
-
captionNode = wrapperNode.firstChild;
|
|
315
|
-
if (data.caption) {
|
|
316
|
-
var captionContent = parseCaptionContent(data.caption, schema);
|
|
317
|
-
nextState = nextState.apply(nextState.tr.replaceWith(captContentPos, captContentPos + captionNode.content.size, captionContent));
|
|
318
|
-
captionNode = nextState.doc.nodeAt(captPos);
|
|
319
|
-
if (captionNode) {
|
|
320
|
-
var captAttrs = __assign({}, captionNode.attrs);
|
|
321
|
-
captAttrs = setNodeStyle(captAttrs, 'text-align', data.captionAlignment || '');
|
|
322
|
-
captAttrs = setNodeStyle(captAttrs, 'caption-side', data.captionPosition || '');
|
|
323
|
-
nextState = nextState.apply(nextState.tr.setNodeAttribute(captPos, 'style', captAttrs.style));
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
nextState = nextState.apply(nextState.tr.deleteRange(captContentPos, captContentPos + captionNode.content.size));
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
captionNode = createCaption(data, schema);
|
|
332
|
-
if (captionNode) {
|
|
333
|
-
nextState = nextState.apply(nextState.tr.replaceWith(captPos, captPos, captionNode));
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return nextState;
|
|
337
|
-
};
|
|
338
|
-
var updateWrapper = function (state, data, tablePos, tableWrapper, tableWrapperPos) {
|
|
339
|
-
if (!tableWrapper && (data.position || data.caption)) {
|
|
340
|
-
var wrapperAttrs_1 = { table: '', style: 'display: table' };
|
|
341
|
-
var children = [];
|
|
342
|
-
if (data.position) {
|
|
343
|
-
Object.keys(data.position.style).forEach(function (s) {
|
|
344
|
-
wrapperAttrs_1 = setNodeStyle(wrapperAttrs_1, s, data.position.style[s] || '');
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
var captionNode = createCaption(data, state.schema);
|
|
348
|
-
if (captionNode) {
|
|
349
|
-
children.push(captionNode);
|
|
350
|
-
}
|
|
351
|
-
var table = state.doc.nodeAt(tablePos);
|
|
352
|
-
children.push(table);
|
|
353
|
-
var createdWrapper = state.schema.nodes.table_wrapper.createAndFill(wrapperAttrs_1, children);
|
|
354
|
-
if (createdWrapper) {
|
|
355
|
-
var tr = state.tr.replaceWith(tablePos, tablePos + table.content.size, createdWrapper);
|
|
356
|
-
state = state.apply(tr);
|
|
357
|
-
return { state: state, pos: tablePos };
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
else if (tableWrapper && (data.position || data.caption || (!data.caption && hasCaption(tableWrapper.node)))) {
|
|
361
|
-
state = setTablePosition(state, tableWrapper.node, tableWrapperPos, data.position && data.position.style);
|
|
362
|
-
state = setTableCaption(state, tableWrapper.node, tableWrapperPos, data);
|
|
363
|
-
return { state: state, pos: tableWrapperPos };
|
|
364
|
-
}
|
|
365
|
-
else if (tableWrapper && !(data.position || data.caption)) {
|
|
366
|
-
return { state: state, node: tableWrapper.node, pos: state.selection.$from.start(tableWrapper.depth) - 1 };
|
|
367
|
-
}
|
|
368
|
-
return { state: state, pos: tablePos };
|
|
369
|
-
};
|
|
43
|
+
import { applyTableData, initialTableData, tableDefaultData, tablePositionStyles } from './tablePropsUtils';
|
|
370
44
|
/**
|
|
371
45
|
* @hidden
|
|
372
46
|
*/
|
|
@@ -383,40 +57,10 @@ export var TableProperties = function (props) {
|
|
|
383
57
|
}, []);
|
|
384
58
|
var onSave = React.useCallback(function (data) {
|
|
385
59
|
if (view && data) {
|
|
386
|
-
var
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
var tablePos = $from.start(table.depth) - 1;
|
|
392
|
-
var state = resizeTable(view.state, tablePos, data.rows, data.columns);
|
|
393
|
-
if (!state) {
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
var transaction_1 = state.tr;
|
|
397
|
-
tableCells(state).forEach(function (cell) {
|
|
398
|
-
var attrs = __assign({}, cell.node.attrs);
|
|
399
|
-
attrs = setNodeStyle(attrs, 'padding', typeof data.cellPadding === 'number' ? data.cellPadding + 'px' : '');
|
|
400
|
-
transaction_1.setNodeMarkup(cell.pos, null, attrs);
|
|
401
|
-
});
|
|
402
|
-
state = state.apply(transaction_1);
|
|
403
|
-
state = setTableStyles(state, data, tablePos);
|
|
404
|
-
state = setTableHeaderCells(state, data, tablePos);
|
|
405
|
-
var tableParent = parentNode($from, function (n) { return n.type.name === 'table_wrapper'; });
|
|
406
|
-
var tableParentPos = $from.start((tableParent === null || tableParent === void 0 ? void 0 : tableParent.depth) || 0) - 1;
|
|
407
|
-
var result = updateWrapper(state, data, tablePos, tableParent, tableParentPos);
|
|
408
|
-
state = result.state;
|
|
409
|
-
var from = result.pos;
|
|
410
|
-
var node = state.doc.nodeAt(result.pos);
|
|
411
|
-
if (!node) {
|
|
412
|
-
return;
|
|
60
|
+
var tr = applyTableData(view.state, data);
|
|
61
|
+
if (tr) {
|
|
62
|
+
view.dispatch(tr);
|
|
413
63
|
}
|
|
414
|
-
var to = from + (tableParent || table).node.content.size;
|
|
415
|
-
var tr = view.state.tr.replaceWith(from, to, node);
|
|
416
|
-
var atEnd = Selection.atEnd(node);
|
|
417
|
-
var selection = TextSelection.create(tr.doc, from + atEnd.to);
|
|
418
|
-
tr.setSelection(selection);
|
|
419
|
-
view.dispatch(tr);
|
|
420
64
|
}
|
|
421
65
|
setShowDialog(false);
|
|
422
66
|
}, [view]);
|
|
@@ -438,24 +82,24 @@ var tablePosition = [{
|
|
|
438
82
|
textKey: keys.tablePropertiesLeft,
|
|
439
83
|
text: messages[keys.tablePropertiesLeft],
|
|
440
84
|
value: 'left',
|
|
441
|
-
style: {
|
|
85
|
+
style: {},
|
|
442
86
|
icon: 'table-position-left',
|
|
443
87
|
svgIcon: tablePositionStartIcon
|
|
444
88
|
}, {
|
|
445
89
|
textKey: keys.tablePropertiesCenter,
|
|
446
90
|
text: messages[keys.tablePropertiesCenter],
|
|
447
91
|
value: 'center',
|
|
448
|
-
style: {
|
|
92
|
+
style: {},
|
|
449
93
|
icon: 'table-position-center',
|
|
450
94
|
svgIcon: tablePositionCenterIcon
|
|
451
95
|
}, {
|
|
452
96
|
textKey: keys.tablePropertiesRight,
|
|
453
97
|
text: messages[keys.tablePropertiesRight],
|
|
454
98
|
value: 'right',
|
|
455
|
-
style: {
|
|
99
|
+
style: {},
|
|
456
100
|
icon: 'table-position-right',
|
|
457
101
|
svgIcon: tablePositionEndIcon
|
|
458
|
-
}];
|
|
102
|
+
}].map(function (p) { return (__assign(__assign({}, p), { style: tablePositionStyles[p.value] })); });
|
|
459
103
|
var captionPositionData = [{
|
|
460
104
|
textKey: keys.tablePropertiesTop,
|
|
461
105
|
text: messages[keys.tablePropertiesTop],
|
|
@@ -474,63 +118,11 @@ var associateHeadersData = [
|
|
|
474
118
|
{ textKey: keys.tablePropertiesUsingScopeAttribute, text: messages[keys.tablePropertiesUsingScopeAttribute], value: 'scope' },
|
|
475
119
|
{ textKey: keys.tablePropertiesUsingIdAttributes, text: messages[keys.tablePropertiesUsingIdAttributes], value: 'id' }
|
|
476
120
|
];
|
|
477
|
-
var initialData = {
|
|
478
|
-
rows: 0,
|
|
479
|
-
columns: 0,
|
|
480
|
-
width: null,
|
|
481
|
-
widthUnit: '',
|
|
482
|
-
height: null,
|
|
483
|
-
heightUnit: '',
|
|
484
|
-
position: null,
|
|
485
|
-
textAlign: '',
|
|
486
|
-
cellPadding: null,
|
|
487
|
-
cellSpacing: null,
|
|
488
|
-
backgroundColor: undefined,
|
|
489
|
-
borderWidth: null,
|
|
490
|
-
borderColor: undefined,
|
|
491
|
-
borderStyle: null,
|
|
492
|
-
collapseBorders: false,
|
|
493
|
-
id: '',
|
|
494
|
-
className: '',
|
|
495
|
-
caption: '',
|
|
496
|
-
captionAlignment: null,
|
|
497
|
-
captionPosition: null,
|
|
498
|
-
headerRows: 0,
|
|
499
|
-
headerColumns: 0,
|
|
500
|
-
associateHeaders: 'none'
|
|
501
|
-
};
|
|
502
121
|
var TablePropertiesDialog = function (props) {
|
|
503
122
|
var defaults = React.useMemo(function () {
|
|
504
|
-
var
|
|
505
|
-
var
|
|
506
|
-
|
|
507
|
-
var table = cells.length ? parentNode($pos, function (n) { return n.type.spec.tableRole === 'table'; }) : null;
|
|
508
|
-
if (!table) {
|
|
509
|
-
return initialData;
|
|
510
|
-
}
|
|
511
|
-
var tableParent = parentNode($pos, function (n) { return n.type.name === 'table_wrapper'; });
|
|
512
|
-
var captionStr = '';
|
|
513
|
-
var captionStyles = {};
|
|
514
|
-
var parentStyles = {};
|
|
515
|
-
if (tableParent) {
|
|
516
|
-
parentStyles = parseStyle(tableParent.node.attrs.style);
|
|
517
|
-
tableParent.node.content.forEach(function (node) {
|
|
518
|
-
if (node.type.name === 'table_caption_external') {
|
|
519
|
-
var fr = pmDocToFragment(node);
|
|
520
|
-
captionStr = fragmentToHtml(fr);
|
|
521
|
-
captionStyles = parseStyle(node.attrs.style);
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
var styles = parseStyle(((_a = table.node.attrs) === null || _a === void 0 ? void 0 : _a.style) || '');
|
|
526
|
-
var map = TableMap.get(table.node);
|
|
527
|
-
var pos = (parentStyles['margin-left'] === 'auto' && parentStyles['margin-right'] === 'auto') ? tablePosition.find(function (p) { return p.value === 'center'; }) :
|
|
528
|
-
parentStyles['margin-right'] === 'auto' ? tablePosition.find(function (p) { return p.value === 'left'; }) :
|
|
529
|
-
parentStyles['margin-left'] === 'auto' ? tablePosition.find(function (p) { return p.value === 'right'; }) : null;
|
|
530
|
-
var headerCells = headerCellsCount(table.node, map);
|
|
531
|
-
return __assign(__assign(__assign(__assign(__assign({}, initialData), { columns: map.width, rows: map.height }), nodeSize(table.node, 'width')), nodeSize(table.node, 'height')), { textAlign: styles['text-align'] || '', position: pos || null, cellPadding: styles.padding ? parseFloat(styles.padding) : 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'], collapseBorders: styles['border-collapse'] === 'collapse', caption: captionStr, captionAlignment: captionStyles['text-align'], captionPosition: captionStyles['caption-side'], headerRows: headerCells.rows, headerColumns: headerCells.columns,
|
|
532
|
-
// associateHeaders
|
|
533
|
-
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 });
|
|
123
|
+
var state = props.view && props.view.state;
|
|
124
|
+
var data = state ? tableDefaultData(state) : initialTableData;
|
|
125
|
+
return data;
|
|
534
126
|
}, [props.view]);
|
|
535
127
|
var loc = useLocalization();
|
|
536
128
|
var _a = React.useState(0), selected = _a[0], setSelected = _a[1];
|
|
@@ -563,7 +155,7 @@ var TablePropertiesDialog = function (props) {
|
|
|
563
155
|
var captionPosition = React.useRef(null);
|
|
564
156
|
var associateHeaders = React.useRef(null);
|
|
565
157
|
var onSave = React.useCallback(function () {
|
|
566
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
158
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
567
159
|
var data = {
|
|
568
160
|
rows: ((_a = rows.current) === null || _a === void 0 ? void 0 : _a.value) || 0,
|
|
569
161
|
columns: ((_b = columns.current) === null || _b === void 0 ? void 0 : _b.value) || 0,
|
|
@@ -574,20 +166,20 @@ var TablePropertiesDialog = function (props) {
|
|
|
574
166
|
borderWidth: borderWidth.current ? borderWidth.current.value : null,
|
|
575
167
|
widthUnit: ((_c = widthUnit.current) === null || _c === void 0 ? void 0 : _c.value) || '',
|
|
576
168
|
heightUnit: ((_d = heightUnit.current) === null || _d === void 0 ? void 0 : _d.value) || '',
|
|
577
|
-
position: ((_e = position.current) === null || _e === void 0 ? void 0 : _e.value) || null,
|
|
578
|
-
textAlign: ((
|
|
579
|
-
borderStyle: ((
|
|
580
|
-
backgroundColor: (
|
|
581
|
-
borderColor: (
|
|
582
|
-
collapseBorders: Boolean((
|
|
583
|
-
id: String(((
|
|
584
|
-
className: String(((
|
|
585
|
-
caption: String(((
|
|
586
|
-
headerRows: ((
|
|
587
|
-
headerColumns: ((
|
|
588
|
-
captionAlignment: ((
|
|
589
|
-
captionPosition: ((
|
|
590
|
-
associateHeaders: ((
|
|
169
|
+
position: ((_f = (_e = position.current) === null || _e === void 0 ? void 0 : _e.value) === null || _f === void 0 ? void 0 : _f.value) || null,
|
|
170
|
+
textAlign: ((_g = alignment.current) === null || _g === void 0 ? void 0 : _g.value) ? alignment.current.value.value : null,
|
|
171
|
+
borderStyle: ((_h = borderStyle.current) === null || _h === void 0 ? void 0 : _h.value) ? borderStyle.current.value.value : null,
|
|
172
|
+
backgroundColor: (_j = backgroundColor.current) === null || _j === void 0 ? void 0 : _j.value,
|
|
173
|
+
borderColor: (_k = borderColor.current) === null || _k === void 0 ? void 0 : _k.value,
|
|
174
|
+
collapseBorders: Boolean((_m = (_l = collapseBorders.current) === null || _l === void 0 ? void 0 : _l.element) === null || _m === void 0 ? void 0 : _m.checked),
|
|
175
|
+
id: String(((_o = id.current) === null || _o === void 0 ? void 0 : _o.value) || ''),
|
|
176
|
+
className: String(((_p = className.current) === null || _p === void 0 ? void 0 : _p.value) || ''),
|
|
177
|
+
caption: String(((_q = caption.current) === null || _q === void 0 ? void 0 : _q.value) || ''),
|
|
178
|
+
headerRows: ((_r = headerRows.current) === null || _r === void 0 ? void 0 : _r.value) || 0,
|
|
179
|
+
headerColumns: ((_s = headerColumns.current) === null || _s === void 0 ? void 0 : _s.value) || 0,
|
|
180
|
+
captionAlignment: ((_t = captionAlignment.current) === null || _t === void 0 ? void 0 : _t.value) ? captionAlignment.current.value.value : null,
|
|
181
|
+
captionPosition: ((_u = captionPosition.current) === null || _u === void 0 ? void 0 : _u.value) ? captionPosition.current.value.value : null,
|
|
182
|
+
associateHeaders: ((_v = associateHeaders.current) === null || _v === void 0 ? void 0 : _v.value) ? associateHeaders.current.value.value : 'none'
|
|
591
183
|
};
|
|
592
184
|
props.onSave.call(undefined, data);
|
|
593
185
|
}, [props.onSave]);
|
|
@@ -621,7 +213,7 @@ var TablePropertiesDialog = function (props) {
|
|
|
621
213
|
React.createElement("div", { className: "k-form-field k-col-span-2" },
|
|
622
214
|
React.createElement("label", { className: "k-label k-form-label" }, loc.toLanguageString(keys.tablePropertiesPosition, messages[keys.tablePropertiesPosition])),
|
|
623
215
|
React.createElement("div", { className: "k-form-field-wrap" },
|
|
624
|
-
React.createElement(DropDownList, { ref: position, defaultValue: defaults.position, popupSettings: popupSettings, data: tablePosition.map(function (i) { return (__assign(__assign({}, i), { text: loc.toLanguageString(i.textKey, i.text) })); }), textField: 'text', dataItemKey: 'value', valueRender: valueRenderWithIcon, itemRender: itemRenderWithIcon }))),
|
|
216
|
+
React.createElement(DropDownList, { ref: position, defaultValue: tablePosition.find(function (p) { return p.value === defaults.position; }), popupSettings: popupSettings, data: tablePosition.map(function (i) { return (__assign(__assign({}, i), { text: loc.toLanguageString(i.textKey, i.text) })); }), textField: 'text', dataItemKey: 'value', valueRender: valueRenderWithIcon, itemRender: itemRenderWithIcon }))),
|
|
625
217
|
React.createElement("div", { className: "k-form-field k-col-span-2" },
|
|
626
218
|
React.createElement("label", { className: "k-label k-form-label" }, loc.toLanguageString(keys.tablePropertiesAlignment, messages[keys.tablePropertiesAlignment])),
|
|
627
219
|
React.createElement("div", { className: "k-form-field-wrap" },
|
|
@@ -690,7 +282,7 @@ var TablePropertiesDialog = function (props) {
|
|
|
690
282
|
React.createElement("div", { className: "k-form-field k-col-span-2" },
|
|
691
283
|
React.createElement("label", { className: "k-label k-form-label" }, loc.toLanguageString(keys.tablePropertiesAssociateHeaders, messages[keys.tablePropertiesAssociateHeaders])),
|
|
692
284
|
React.createElement("div", { className: "k-form-field-wrap" },
|
|
693
|
-
React.createElement(DropDownList, { ref: associateHeaders, defaultValue: associateHeadersData
|
|
285
|
+
React.createElement(DropDownList, { ref: associateHeaders, defaultValue: associateHeadersData.find(function (i) { return i.value === defaults.associateHeaders; }), data: associateHeadersData.map(function (i) { return (__assign(__assign({}, i), { text: loc.toLanguageString(i.textKey, i.text) })); }), popupSettings: popupSettings, textField: 'text', dataItemKey: 'value' })))))))));
|
|
694
286
|
var content = (React.createElement(TabStrip, { selected: selected, onSelect: onSelect, animation: false, keepTabsMounted: true },
|
|
695
287
|
React.createElement(TabStripTab, { title: loc.toLanguageString(keys.tablePropertiesGeneral, messages[keys.tablePropertiesGeneral]) }, general),
|
|
696
288
|
React.createElement(TabStripTab, { title: loc.toLanguageString(keys.tablePropertiesAdvanced, messages[keys.tablePropertiesAdvanced]) }, advanced)));
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { EditorState, Transaction } from '@progress/kendo-editor-common';
|
|
2
|
+
/**
|
|
3
|
+
* @hidden
|
|
4
|
+
*/
|
|
5
|
+
declare type TablePosition = 'left' | 'right' | 'center' | '';
|
|
6
|
+
/**
|
|
7
|
+
* @hidden
|
|
8
|
+
*/
|
|
9
|
+
interface TableData {
|
|
10
|
+
rows: number;
|
|
11
|
+
columns: number;
|
|
12
|
+
width: number | null;
|
|
13
|
+
widthUnit: string;
|
|
14
|
+
height: number | null;
|
|
15
|
+
heightUnit: string;
|
|
16
|
+
position: TablePosition | null;
|
|
17
|
+
textAlign: string;
|
|
18
|
+
cellPadding: number | null;
|
|
19
|
+
cellSpacing: number | null;
|
|
20
|
+
backgroundColor: string | undefined;
|
|
21
|
+
borderWidth: number | null;
|
|
22
|
+
borderColor: string | undefined;
|
|
23
|
+
borderStyle: string | null;
|
|
24
|
+
collapseBorders: boolean;
|
|
25
|
+
id: string;
|
|
26
|
+
className: string;
|
|
27
|
+
caption?: string;
|
|
28
|
+
captionPosition: string | null;
|
|
29
|
+
captionAlignment: string | null;
|
|
30
|
+
headerRows: number;
|
|
31
|
+
headerColumns: number;
|
|
32
|
+
associateHeaders: 'none' | 'scope' | 'id';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @hidden
|
|
36
|
+
*/
|
|
37
|
+
declare const initialTableData: TableData;
|
|
38
|
+
/**
|
|
39
|
+
* @hidden
|
|
40
|
+
*/
|
|
41
|
+
declare const tablePositionStyles: Record<TablePosition, {
|
|
42
|
+
[styleName: string]: string;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* @hidden
|
|
46
|
+
*/
|
|
47
|
+
declare const tableDefaultData: (state: EditorState) => TableData;
|
|
48
|
+
/**
|
|
49
|
+
* @hidden
|
|
50
|
+
*/
|
|
51
|
+
declare const applyTableData: (state: EditorState, data: TableData) => Transaction | undefined;
|
|
52
|
+
export { TableData, initialTableData, tablePositionStyles, TablePosition, tableDefaultData, applyTableData };
|