@progress/kendo-angular-editor 3.0.0-dev.202112211443 → 3.0.0-dev.202201121058

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/cdn/js/kendo-angular-editor.js +2 -2
  2. package/dist/cdn/main.js +1 -1
  3. package/dist/es/config/commands.js +2 -2
  4. package/dist/es/config/schema.js +1 -2
  5. package/dist/es/config/table-commands.js +1 -363
  6. package/dist/es/editor.component.js +6 -6
  7. package/dist/es/package-metadata.js +1 -1
  8. package/dist/es2015/config/commands.js +2 -2
  9. package/dist/es2015/config/schema.js +1 -2
  10. package/dist/es2015/config/table-commands.d.ts +0 -36
  11. package/dist/es2015/config/table-commands.js +1 -357
  12. package/dist/es2015/editor.component.js +6 -6
  13. package/dist/es2015/index.metadata.json +1 -1
  14. package/dist/es2015/package-metadata.js +1 -1
  15. package/dist/fesm2015/index.js +153 -1530
  16. package/dist/fesm5/index.js +171 -1574
  17. package/dist/npm/config/commands.js +1 -1
  18. package/dist/npm/config/schema.js +1 -2
  19. package/dist/npm/config/table-commands.js +1 -368
  20. package/dist/npm/editor.component.js +5 -5
  21. package/dist/npm/package-metadata.js +1 -1
  22. package/dist/systemjs/kendo-angular-editor.js +1 -1
  23. package/package.json +2 -2
  24. package/dist/es/config/table-nodes.js +0 -146
  25. package/dist/es/config/tables/CellSelection.js +0 -268
  26. package/dist/es/config/tables/TableMap.js +0 -333
  27. package/dist/es/config/tables/table-utils.js +0 -302
  28. package/dist/es2015/config/table-nodes.d.ts +0 -9
  29. package/dist/es2015/config/table-nodes.js +0 -145
  30. package/dist/es2015/config/tables/CellSelection.d.ts +0 -35
  31. package/dist/es2015/config/tables/CellSelection.js +0 -256
  32. package/dist/es2015/config/tables/TableMap.d.ts +0 -35
  33. package/dist/es2015/config/tables/TableMap.js +0 -329
  34. package/dist/es2015/config/tables/table-utils.d.ts +0 -77
  35. package/dist/es2015/config/tables/table-utils.js +0 -299
  36. package/dist/npm/config/table-nodes.js +0 -157
  37. package/dist/npm/config/tables/CellSelection.js +0 -270
  38. package/dist/npm/config/tables/TableMap.js +0 -338
  39. package/dist/npm/config/tables/table-utils.js +0 -307
@@ -10,7 +10,7 @@ import { take, map, filter, concatMap, takeUntil } from 'rxjs/operators';
10
10
  import { ToolBarComponent, ToolBarToolComponent, ToolBarButtonComponent, ToolBarModule } from '@progress/kendo-angular-toolbar';
11
11
  import { DialogRef, DialogContentBase, DialogService, DialogModule } from '@progress/kendo-angular-dialog';
12
12
  import { isDocumentAvailable, guid, PreventableEvent, KendoInput, hasObservers, Keys } from '@progress/kendo-angular-common';
13
- import { nodes, Schema, marks, SelectionRange, TextSelection, Fragment, Slice, Selection, NodeSelection, insertNode, expandToWordWrap, toggleInlineFormat, bold, cleanFormatting, applyLink, applyInlineStyle, insertText, italic, strikethrough, subscript, superscript, underline, removeLink, link, selectAll, isAligned, alignCenterRules, alignBlocks, alignRemoveRules, alignJustifyRules, alignLeftRules, alignRightRules, formatBlockElements, getHtml, indent, insertImage, toggleOrderedList, toggleUnorderedList, outdent, redo, setHtml, undo, hasMark, activeNode, canIndentAsListItem, canBeIndented, indentRules, hasNode, canOutdentAsListItem, outdentRules, getActiveMarks, expandSelection, addColumnBefore, addColumnAfter, addRowBefore, addRowAfter, deleteRow, deleteColumn, mergeCells, splitCell, deleteTable, getNodeFromSelection, getMark, getSelectionText, parseContent, Plugin, PluginKey, history, keymap, buildListKeymap, buildKeymap, baseKeymap, gapCursor, imageResizing, placeholder, EditorState, EditorView, pasteCleanup, AllSelection, removeComments, sanitize, removeAttribute, sanitizeStyleAttr, sanitizeClassAttr } from '@progress/kendo-editor-common';
13
+ import { nodes, Schema, marks, createTable, insertNode, expandToWordWrap, toggleInlineFormat, bold, cleanFormatting, applyLink, applyInlineStyle, insertText, italic, strikethrough, subscript, superscript, underline, removeLink, link, selectAll, isAligned, alignCenterRules, alignBlocks, alignRemoveRules, alignJustifyRules, alignLeftRules, alignRightRules, formatBlockElements, getHtml, indent, insertImage, toggleOrderedList, toggleUnorderedList, outdent, redo, setHtml, undo, addColumnBefore, addColumnAfter, addRowBefore, addRowAfter, deleteRow, deleteColumn, mergeCells, splitCell, deleteTable, hasMark, activeNode, canIndentAsListItem, canBeIndented, indentRules, hasNode, canOutdentAsListItem, outdentRules, getActiveMarks, expandSelection, getNodeFromSelection, getMark, getSelectionText, TextSelection, parseContent, Plugin, PluginKey, history, keymap, buildListKeymap, buildKeymap, baseKeymap, gapCursor, imageResizing, tableEditing, placeholder, EditorState, EditorView, pasteCleanup, AllSelection, removeComments, sanitize, removeAttribute, sanitizeStyleAttr, sanitizeClassAttr } from '@progress/kendo-editor-common';
14
14
  export { Schema, EditorState, Plugin, PluginKey, Transaction, EditorView, Decoration, DecorationSet, NodeType, Node, MarkType, Mark, InputRule, inputRules, wrappingInputRule, textblockTypeInputRule, keymap, baseKeymap, history, dropCursor, gapCursor, tableNodes, getSelectionText } from '@progress/kendo-editor-common';
15
15
  import { validatePackage } from '@progress/kendo-licensing';
16
16
  import { L10N_PREFIX, RTL, MessageService, LocalizationService, ComponentMessages } from '@progress/kendo-angular-l10n';
@@ -27,7 +27,7 @@ var packageMetadata = {
27
27
  name: '@progress/kendo-angular-editor',
28
28
  productName: 'Kendo UI for Angular',
29
29
  productCodes: ['KENDOUIANGULAR', 'KENDOUICOMPLETE'],
30
- publishDate: 1640097479,
30
+ publishDate: 1641984793,
31
31
  version: '',
32
32
  licensingDocsUrl: 'https://www.telerik.com/kendo-angular-ui/my-license/?utm_medium=product&utm_source=kendoangular&utm_campaign=kendo-ui-angular-purchase-license-keys-warning'
33
33
  };
@@ -70,1598 +70,84 @@ var getAttributes = function (dom) {
70
70
  /**
71
71
  * @hidden
72
72
  */
73
- var serializeDOMAttrs = function (el) {
74
- return Array.from(el.attributes)
75
- .reduce(function (acc, curr) {
76
- var _a;
77
- return Object.assign({}, acc, (_a = {}, _a[curr.name] = curr.value, _a));
78
- }, {});
79
- };
80
- /**
81
- * @hidden
82
- */
83
- var commonAttributes = function () {
84
- return __assign({}, createDefaultAttributes(['class', 'id', 'style']));
85
- };
86
- /**
87
- * @hidden
88
- */
89
- var createDefaultAttributes = function (attrs) {
90
- if (attrs === void 0) { attrs = []; }
91
- return __assign({}, attrs.reduce(function (acc, curr) {
92
- var _a;
93
- return (__assign({}, acc, (_a = {}, _a[curr] = { default: null }, _a)));
94
- }, {}));
95
- };
96
- /**
97
- * @hidden
98
- */
99
- var hole = 0;
100
- /**
101
- * @hidden
102
- */
103
- var isSchemaNode = function (schemaNodeName) { return function (node) { return node.type.name === schemaNodeName; }; };
104
- /**
105
- * @hidden
106
- */
107
- var isTable = isSchemaNode('table');
108
- /**
109
- * @hidden
110
- */
111
- var isTableBody = isSchemaNode('table_body');
112
- /**
113
- * @hidden
114
- */
115
- var isTableHead = isSchemaNode('table_head');
116
- /**
117
- * @hidden
118
- */
119
- var isTableFoot = isSchemaNode('table_foot');
120
- /**
121
- * @hidden
122
- */
123
- var isTableRow = isSchemaNode('table_row');
124
- /**
125
- * @hidden
126
- */
127
- var isTableCell = isSchemaNode('table_cell');
128
- /**
129
- * @hidden
130
- */
131
- var isTableHeaderCell = isSchemaNode('table_header');
132
-
133
- var createSemanticNode = function (tagName) { return ({
134
- // Uncaught SyntaxError: Mixing inline and block content (in content expression '(block | inline)*')
135
- // content: '(block | inline)*',
136
- content: 'block*',
137
- group: 'block',
138
- attrs: __assign({}, commonAttributes()),
139
- parseDOM: [{
140
- tag: tagName,
141
- getAttrs: getAttributes
142
- }],
143
- toDOM: function (node) { return hasAttrs(node.attrs) ? [tagName, getAttrs(node.attrs), hole] : [tagName, hole]; }
144
- }); };
145
- /**
146
- * @hidden
147
- */
148
- var semanticTagNames = ['article', 'main', 'nav', 'header', 'footer', 'aside', 'section'];
149
- var ɵ1 = function (acc, curr) {
150
- var _a;
151
- return Object.assign(acc, (_a = {}, _a[curr] = createSemanticNode(curr), _a));
152
- };
153
- /**
154
- * @hidden
155
- */
156
- var semanticNodes = semanticTagNames.reduce(ɵ1, {});
157
-
158
- /**
159
- * @hidden
160
- */
161
- function outerWidth(element) {
162
- var width = element.offsetWidth;
163
- var style = getComputedStyle(element);
164
- width += parseFloat(style.marginLeft) || 0 + parseFloat(style.marginRight) || 0;
165
- return width;
166
- }
167
- /**
168
- * @hidden
169
- */
170
- var removeEntries = function (obj, predicate) {
171
- return Object.keys(obj)
172
- .filter(function (key) { return predicate(key); })
173
- .reduce(function (acc, curr) {
174
- var _a;
175
- return Object.assign(acc, (_a = {}, _a[curr] = obj[curr], _a));
176
- }, {});
177
- };
178
- /**
179
- * @hidden
180
- */
181
- var removeEmptyEntries = function (obj) {
182
- var predicate = function (key) { return obj[key] !== null && obj[key] !== undefined && obj[key] !== ''; };
183
- return removeEntries(obj, predicate);
184
- };
185
- /**
186
- * @hidden
187
- */
188
- var isNullOrUndefined = function (value) { return value === undefined || value === null; };
189
- /**
190
- * @hidden
191
- */
192
- var isPresent = function (value) { return !isNullOrUndefined(value); };
193
- /**
194
- * @hidden
195
- */
196
- var detectIE = function () {
197
- if (!isDocumentAvailable()) {
198
- return false;
199
- }
200
- var ua = window.navigator.userAgent;
201
- var msie = ua.indexOf('MSIE ');
202
- var trident = ua.indexOf('Trident/');
203
- return msie > 0 || trident > 0;
204
- };
205
- /**
206
- * @hidden
207
- */
208
- var safeString = function (value) { return (isNullOrUndefined(value) ? '' : value.toString()); };
209
- /**
210
- * @hidden
211
- */
212
- var first = function (arr) { return arr[0]; };
213
- /**
214
- * @hidden
215
- */
216
- var last = function (arr) { return arr[arr.length - 1]; };
217
- /**
218
- * @hidden
219
- */
220
- var split = function (splitter) { return function (value) { return value.split(splitter); }; };
221
- /**
222
- * @hidden
223
- */
224
- var trim = function (value) { return value.trim(); };
225
- /**
226
- * @hidden
227
- */
228
- var filter$1 = function (predicate) { return function (arr) { return arr.filter(predicate); }; };
229
- /**
230
- * @hidden
231
- */
232
- var getUniqueStyleValues = function (style, cssStyle) {
233
- if (style.hasNodesWithoutMarks) {
234
- return '';
235
- }
236
- var uniqueMarkValues = style.marks
237
- .filter(function (m) { return m.type.name === 'style'; })
238
- .map(function (m) { return m.attrs.style; })
239
- .map(safeString)
240
- .map(split(';'))
241
- .map(filter$1(function (m) { return m.includes(cssStyle); }))
242
- // guards against empty array
243
- .map(function (cssStyleValues) { return (cssStyleValues.length !== 0 ? cssStyleValues : [cssStyle + ": INVALID"]); })
244
- .map(first)
245
- .map(split(':'))
246
- .map(last)
247
- .map(trim)
248
- .reduce(function (acc, curr) { return (acc.indexOf(curr) > -1 ? acc : acc.concat([curr])); }, []);
249
- if (uniqueMarkValues.indexOf('INVALID') > -1 || uniqueMarkValues.length !== 1) {
250
- return '';
251
- }
252
- return uniqueMarkValues[0];
253
- };
254
- /**
255
- * @hidden
256
- */
257
- var conditionallyExecute = function (fn) { return function (condition) { return function (param) { return (condition ? fn(param) : param); }; }; };
258
- /**
259
- * @hidden
260
- */
261
- var pipe = function () {
262
- var fns = [];
263
- for (var _i = 0; _i < arguments.length; _i++) {
264
- fns[_i] = arguments[_i];
265
- }
266
- return function (x) { return fns.reduce(function (y, f) { return f(y); }, x); };
267
- };
268
-
269
- var setCellAttrs = function (nodeAttributes) {
270
- var attrs = __assign({}, nodeAttributes);
271
- if (nodeAttributes.colspan !== 1) {
272
- attrs.colspan = nodeAttributes.colspan;
273
- }
274
- else {
275
- attrs.colspan = null;
276
- }
277
- if (nodeAttributes.rowspan !== 1) {
278
- attrs.rowspan = nodeAttributes.rowspan;
279
- }
280
- else {
281
- attrs.rowspan = null;
282
- }
283
- return removeEmptyEntries(attrs);
284
- };
285
- var ɵ1$1 = function (node) { return ['table', removeEmptyEntries(node.attrs), 0]; }, ɵ2 = function (node) { return ['tr', removeEmptyEntries(node.attrs), 0]; }, ɵ3 = function (node) { return ['td', setCellAttrs(node.attrs), 0]; }, ɵ4 = function (node) { return ['th', setCellAttrs(node.attrs), 0]; }, ɵ5 = function (node) { return ['tbody', removeEmptyEntries(node.attrs), 0]; }, ɵ6 = function (node) { return ['tfoot', removeEmptyEntries(node.attrs), 0]; }, ɵ7 = function (node) { return ['thead', removeEmptyEntries(node.attrs), 0]; }, ɵ8 = function (node) { return ['col', removeEmptyEntries(node.attrs)]; }, ɵ9 = function (node) { return ['colgroup', removeEmptyEntries(node.attrs), 0]; };
286
- /**
287
- * @hidden
288
- */
289
- var tableNodes = {
290
- // all table node names must start with table - this is needed for the commands to work properly
291
- table: {
292
- attrs: __assign({}, commonAttributes(), createDefaultAttributes(['cellspacing', 'cellpadding'])),
293
- content: '(table_body | table_head | table_foot | table_colgroup)+',
294
- tableRole: 'table',
295
- isolating: true,
296
- group: 'block',
297
- parseDOM: [
298
- {
299
- getAttrs: serializeDOMAttrs,
300
- tag: 'table'
301
- }
302
- ],
303
- toDOM: ɵ1$1
304
- },
305
- table_row: {
306
- content: '(table_cell | table_header)*',
307
- attrs: __assign({}, commonAttributes()),
308
- tableRole: 'row',
309
- parseDOM: [
310
- {
311
- getAttrs: serializeDOMAttrs,
312
- tag: 'tr'
313
- }
314
- ],
315
- toDOM: ɵ2
316
- },
317
- table_cell: {
318
- content: 'block+',
319
- attrs: __assign({}, commonAttributes(), createDefaultAttributes(['headers']), {
320
- // this is needed for the commands
321
- colspan: { default: 1 }, rowspan: { default: 1 } }),
322
- tableRole: 'cell',
323
- isolating: true,
324
- parseDOM: [
325
- {
326
- getAttrs: serializeDOMAttrs,
327
- tag: 'td'
328
- }
329
- ],
330
- toDOM: ɵ3
331
- },
332
- table_header: {
333
- content: 'block+',
334
- attrs: __assign({}, commonAttributes(), createDefaultAttributes(['headers', 'abbr', 'scope']), { colspan: { default: 1 }, rowspan: { default: 1 } }),
335
- tableRole: 'header_cell',
336
- isolating: true,
337
- parseDOM: [
338
- {
339
- getAttrs: serializeDOMAttrs,
340
- tag: 'th'
341
- }
342
- ],
343
- toDOM: ɵ4
344
- },
345
- table_body: {
346
- attrs: __assign({}, commonAttributes()),
347
- content: 'table_row+',
348
- isolating: true,
349
- parseDOM: [
350
- {
351
- getAttrs: serializeDOMAttrs,
352
- tag: 'tbody'
353
- }
354
- ],
355
- toDOM: ɵ5
356
- },
357
- table_foot: {
358
- attrs: __assign({}, commonAttributes()),
359
- content: 'table_row+',
360
- isolating: true,
361
- parseDOM: [
362
- {
363
- getAttrs: serializeDOMAttrs,
364
- tag: 'tfoot'
365
- }
366
- ],
367
- toDOM: ɵ6
368
- },
369
- table_head: {
370
- attrs: __assign({}, commonAttributes()),
371
- content: 'table_row+',
372
- isolating: true,
373
- parseDOM: [
374
- {
375
- getAttrs: serializeDOMAttrs,
376
- tag: 'thead'
377
- }
378
- ],
379
- toDOM: ɵ7
380
- },
381
- table_col: {
382
- attrs: __assign({}, commonAttributes(), createDefaultAttributes(['span'])),
383
- selectable: false,
384
- atom: true,
385
- parseDOM: [
386
- {
387
- getAttrs: serializeDOMAttrs,
388
- tag: 'col'
389
- }
390
- ],
391
- toDOM: ɵ8
392
- },
393
- table_colgroup: {
394
- attrs: __assign({}, commonAttributes(), createDefaultAttributes(['span'])),
395
- content: 'table_col*',
396
- selectable: false,
397
- parseDOM: [
398
- {
399
- getAttrs: serializeDOMAttrs,
400
- tag: 'colgroup'
401
- }
402
- ],
403
- toDOM: ɵ9
404
- }
405
- };
406
-
407
- /**
408
- * @hidden
409
- */
410
- var marks$1 = marks;
411
- var nodes$1 = Object.assign(nodes, tableNodes, semanticNodes);
412
- /**
413
- * @hidden
414
- */
415
- var schema = new Schema({
416
- marks: marks$1,
417
- nodes: __assign({}, nodes$1, { blockquote: __assign({}, nodes$1.blockquote, { content: 'inline*' }) })
418
- });
419
-
420
- // Because working with row and column-spanning cells is not quite
421
- // trivial, this code builds up a descriptive structure for a given
422
- // table node. The structures are cached with the (persistent) table
423
- // nodes as key, so that they only have to be recomputed when the
424
- // content of the table changes.
425
- //
426
- // This does mean that they have to store table-relative, not
427
- // document-relative positions. So code that uses them will typically
428
- // compute the start position of the table and offset positions passed
429
- // to or gotten from this structure by that amount.
430
- var readFromCache;
431
- var addToCache;
432
- // Prefer using a weak map to cache table maps. Fall back on a
433
- // fixed-size cache if that's not supported.
434
- if (typeof WeakMap !== 'undefined') {
435
- var cache_1 = new WeakMap();
436
- readFromCache = function (key) { return cache_1.get(key); };
437
- addToCache = function (key, value) {
438
- cache_1.set(key, value);
439
- return value;
440
- };
441
- }
442
- else {
443
- var cache_2 = [];
444
- var cacheSize_1 = 10;
445
- var cachePos_1 = 0;
446
- readFromCache = function (key) {
447
- for (var i = 0; i < cache_2.length; i += 2) {
448
- if (cache_2[i] === key) {
449
- return cache_2[i + 1];
450
- }
451
- }
452
- };
453
- addToCache = function (key, value) {
454
- if (cachePos_1 === cacheSize_1) {
455
- cachePos_1 = 0;
456
- }
457
- cache_2[cachePos_1++] = key;
458
- return (cache_2[cachePos_1++] = value);
459
- };
460
- }
461
- var findWidth = function (table) {
462
- var width = -1;
463
- var hasRowSpan = false;
464
- for (var row = 0; row < table.childCount; row++) {
465
- var rowNode = table.child(row);
466
- var rowWidth = 0;
467
- if (hasRowSpan) {
468
- for (var j = 0; j < row; j++) {
469
- var prevRow = table.child(j);
470
- for (var i = 0; i < prevRow.childCount; i++) {
471
- var cell = prevRow.child(i);
472
- if (j + cell.attrs.rowspan > row) {
473
- rowWidth += cell.attrs.colspan;
474
- }
475
- }
476
- }
477
- }
478
- // check if the cell spans accross multiple columns
479
- for (var i = 0; i < rowNode.childCount; i++) {
480
- var cell = rowNode.child(i);
481
- rowWidth += cell.attrs.colspan;
482
- if (cell.attrs.rowspan > 1) {
483
- hasRowSpan = true;
484
- }
485
- }
486
- if (width === -1) {
487
- width = rowWidth;
488
- }
489
- else if (width !== rowWidth) {
490
- width = Math.max(width, rowWidth);
491
- }
492
- }
493
- return width;
494
- };
495
- var freshColWidth = function (attrs) {
496
- if (attrs.colwidth) {
497
- return attrs.colwidth.slice();
498
- }
499
- var result = [];
500
- for (var i = 0; i < attrs.colspan; i++) {
501
- result.push(0);
502
- }
503
- return result;
504
- };
505
- var findBadColWidths = function (map$$1, colWidths, table) {
506
- if (!map$$1.problems) {
507
- map$$1.problems = [];
508
- }
509
- for (var i = 0, seen = {}; i < map$$1.map.length; i++) {
510
- var pos = map$$1.map[i];
511
- if (seen[pos]) {
512
- continue;
513
- }
514
- seen[pos] = true;
515
- var node = table.nodeAt(pos);
516
- var updated = null;
517
- for (var j = 0; j < node.attrs.colspan; j++) {
518
- var col = (i + j) % map$$1.width;
519
- var colWidth = colWidths[col * 2];
520
- if (colWidth != null && (!node.attrs.colwidth || node.attrs.colwidth[j] !== colWidth)) {
521
- (updated || (updated = freshColWidth(node.attrs)))[j] = colWidth;
522
- }
523
- }
524
- if (updated) {
525
- map$$1.problems.unshift({ type: 'colwidth mismatch', pos: pos, colwidth: updated });
526
- }
527
- }
528
- };
529
- // Compute a table map.
530
- var computeMap = function (tableNode) {
531
- if (!isTable(tableNode) && !isTableBody(tableNode) && !isTableHead(tableNode) && !isTableFoot(tableNode)) {
532
- throw new RangeError('Not a table node: ' + tableNode.type.name);
533
- }
534
- var width = findWidth(tableNode);
535
- var height = tableNode.childCount;
536
- var map$$1 = [];
537
- var mapPos = 0;
538
- var problems = null;
539
- var colWidths = [];
540
- for (var i = 0, e = width * height; i < e; i++) {
541
- map$$1[i] = 0;
542
- }
543
- for (var row = 0, pos = 0; row < height; row++) {
544
- var rowNode = tableNode.child(row);
545
- pos++;
546
- for (var i = 0;; i++) {
547
- while (mapPos < map$$1.length && map$$1[mapPos] !== 0) {
548
- mapPos++;
549
- }
550
- if (i === rowNode.childCount) {
551
- break;
552
- }
553
- var cellNode = rowNode.child(i);
554
- var _a = cellNode.attrs, colspan = _a.colspan, rowspan = _a.rowspan, colwidth = _a.colwidth;
555
- for (var h = 0; h < rowspan; h++) {
556
- if (h + row >= height) {
557
- (problems || (problems = [])).push({ type: 'overlong_rowspan', pos: pos, n: rowspan - h });
558
- break;
559
- }
560
- var start = mapPos + h * width;
561
- for (var w = 0; w < colspan; w++) {
562
- if (map$$1[start + w] === 0) {
563
- map$$1[start + w] = pos;
564
- }
565
- else {
566
- (problems || (problems = [])).push({ type: 'collision', row: row, pos: pos, n: colspan - w });
567
- }
568
- var colW = colwidth && colwidth[w];
569
- if (colW) {
570
- var widthIndex = ((start + w) % width) * 2, prev = colWidths[widthIndex];
571
- if (prev == null || (prev !== colW && colWidths[widthIndex + 1] === 1)) {
572
- colWidths[widthIndex] = colW;
573
- colWidths[widthIndex + 1] = 1;
574
- }
575
- else if (prev === colW) {
576
- colWidths[widthIndex + 1]++;
577
- }
578
- }
579
- }
580
- }
581
- mapPos += colspan;
582
- pos += cellNode.nodeSize;
583
- }
584
- var expectedPos = (row + 1) * width;
585
- var missing = 0;
586
- while (mapPos < expectedPos) {
587
- if (map$$1[mapPos++] === 0) {
588
- missing++;
589
- }
590
- }
591
- if (missing) {
592
- (problems || (problems = [])).push({ type: 'missing', row: row, n: missing });
593
- }
594
- pos++;
595
- }
596
- var tableMap = new TableMap(width, height, map$$1, problems);
597
- var badWidths = false;
598
- // For columns that have defined widths, but whose widths disagree
599
- // between rows, fix up the cells whose width doesn't match the
600
- // computed one.
601
- for (var i = 0; !badWidths && i < colWidths.length; i += 2) {
602
- if (colWidths[i] != null && colWidths[i + 1] < height) {
603
- badWidths = true;
604
- }
605
- }
606
- if (badWidths) {
607
- findBadColWidths(tableMap, colWidths, tableNode);
608
- }
609
- return tableMap;
610
- };
611
- /**
612
- * @hidden
613
- */
614
- var Rect = /** @class */ (function () {
615
- function Rect(left, top, right, bottom) {
616
- this.left = left;
617
- this.top = top;
618
- this.right = right;
619
- this.bottom = bottom;
620
- }
621
- return Rect;
622
- }());
623
- /**
624
- * @hidden
625
- */
626
- var TableMap = /** @class */ (function () {
627
- function TableMap(width, height, map$$1, problems) {
628
- // :: number The width of the table
629
- this.width = width;
630
- // :: number The table's height
631
- this.height = height;
632
- // :: [number] A width * height array with the start position of
633
- // the cell covering that part of the table in each slot
634
- this.map = map$$1;
635
- // An optional array of problems (cell overlap or non-rectangular
636
- // shape) for the table, used by the table normalizer.
637
- this.problems = problems;
638
- }
639
- // :: (Node) → TableMap
640
- // Find the table map for the given table node.
641
- TableMap.get = function (table) {
642
- return readFromCache(table) || addToCache(table, computeMap(table));
643
- };
644
- // :: (number) → Rect
645
- // Find the dimensions of the cell at the given position.
646
- TableMap.prototype.findCell = function (pos) {
647
- for (var i = 0; i < this.map.length; i++) {
648
- var curPos = this.map[i];
649
- if (curPos !== pos) {
650
- continue;
651
- }
652
- var left = i % this.width;
653
- var top_1 = Math.floor(i / this.width);
654
- var right = left + 1;
655
- var bottom = top_1 + 1;
656
- for (var j = 1; right < this.width && this.map[i + j] === curPos; j++) {
657
- right++;
658
- }
659
- for (var j = 1; bottom < this.height && this.map[i + this.width * j] === curPos; j++) {
660
- bottom++;
661
- }
662
- return new Rect(left, top_1, right, bottom);
663
- }
664
- throw new RangeError('No cell with offset ' + pos + ' found');
665
- };
666
- // :: (number) → number
667
- // Find the left side of the cell at the given position.
668
- TableMap.prototype.colCount = function (pos) {
669
- for (var i = 0; i < this.map.length; i++) {
670
- if (this.map[i] === pos) {
671
- return i % this.width;
672
- }
673
- }
674
- throw new RangeError('No cell with offset ' + pos + ' found');
675
- };
676
- // :: (number, string, number) → ?number
677
- // Find the next cell in the given direction, starting from the cell
678
- // at `pos`, if any.
679
- TableMap.prototype.nextCell = function (pos, axis, dir) {
680
- var _a = this.findCell(pos), left = _a.left, right = _a.right, top = _a.top, bottom = _a.bottom;
681
- if (axis === 'horiz') {
682
- if (dir < 0 ? left === 0 : right === this.width) {
683
- return null;
684
- }
685
- return this.map[top * this.width + (dir < 0 ? left - 1 : right)];
686
- }
687
- else {
688
- if (dir < 0 ? top === 0 : bottom === this.height) {
689
- return null;
690
- }
691
- return this.map[left + this.width * (dir < 0 ? top - 1 : bottom)];
692
- }
693
- };
694
- // :: (number, number) → Rect
695
- // Get the rectangle spanning the two given cells.
696
- TableMap.prototype.rectBetween = function (a, b) {
697
- var _a = this.findCell(a), leftA = _a.left, rightA = _a.right, topA = _a.top, bottomA = _a.bottom;
698
- var _b = this.findCell(b), leftB = _b.left, rightB = _b.right, topB = _b.top, bottomB = _b.bottom;
699
- return new Rect(Math.min(leftA, leftB), Math.min(topA, topB), Math.max(rightA, rightB), Math.max(bottomA, bottomB));
700
- };
701
- // :: (Rect) → [number]
702
- // Return the position of all cells that have the top left corner in
703
- // the given rectangle.
704
- TableMap.prototype.cellsInRect = function (rect) {
705
- var result = [];
706
- var seen = {};
707
- for (var row = rect.top; row < rect.bottom; row++) {
708
- for (var col = rect.left; col < rect.right; col++) {
709
- var index = row * this.width + col, pos = this.map[index];
710
- if (seen[pos]) {
711
- continue;
712
- }
713
- seen[pos] = true;
714
- if ((col !== rect.left || !col || this.map[index - 1] !== pos) &&
715
- (row !== rect.top || !row || this.map[index - this.width] !== pos)) {
716
- result.push(pos);
717
- }
718
- }
719
- }
720
- return result;
721
- };
722
- // :: (number, number, Node) → number
723
- // Return the position at which the cell at the given row and column
724
- // starts, or would start, if a cell started there.
725
- TableMap.prototype.positionAt = function (row, col, table) {
726
- for (var i = 0, rowStart = 0;; i++) {
727
- var rowEnd = rowStart + table.child(i).nodeSize;
728
- if (i === row) {
729
- var index = col + row * this.width, rowEndIndex = (row + 1) * this.width;
730
- // Skip past cells from previous rows (via rowspan)
731
- while (index < rowEndIndex && this.map[index] < rowStart) {
732
- index++;
733
- }
734
- return index === rowEndIndex ? rowEnd - 1 : this.map[index];
735
- }
736
- rowStart = rowEnd;
737
- }
738
- };
739
- return TableMap;
740
- }());
741
-
742
- /**
743
- * @hidden
744
- */
745
- // ::- A [`Selection`](http://prosemirror.net/docs/ref/#state.Selection)
746
- // subclass that represents a cell selection spanning part of a table.
747
- // With the plugin enabled, these will be created when the user
748
- // selects across cells, and will be drawn by giving selected cells a
749
- // `selectedCell` CSS class.
750
- var CellSelection = /** @class */ (function (_super) {
751
- __extends(CellSelection, _super);
752
- // :: (ResolvedPos, ?ResolvedPos)
753
- // A table selection is identified by its anchor and head cells. The
754
- // positions given to this constructor should point _before_ two
755
- // cells in the same table. They may be the same, to select a single
756
- // cell.
757
- function CellSelection($anchorCell, $headCell) {
758
- if ($headCell === void 0) { $headCell = $anchorCell; }
759
- var _this = this;
760
- var table = $anchorCell.node(-1), map$$1 = TableMap.get(table), start = $anchorCell.start(-1);
761
- var rect = map$$1.rectBetween($anchorCell.pos - start, $headCell.pos - start);
762
- var doc = $anchorCell.node(0);
763
- var cells = map$$1.cellsInRect(rect).filter(function (p) { return p !== $headCell.pos - start; });
764
- // Make the head cell the first range, so that it counts as the
765
- // primary part of the selection
766
- cells.unshift($headCell.pos - start);
767
- var ranges = cells.map(function (pos) {
768
- var cell = table.nodeAt(pos), from = pos + start + 1;
769
- return new SelectionRange(doc.resolve(from), doc.resolve(from + cell.content.size));
770
- });
771
- _this = _super.call(this, ranges[0].$from, ranges[0].$to, ranges) || this;
772
- // :: ResolvedPos
773
- // A resolved position pointing _in front of_ the anchor cell (the one
774
- // that doesn't move when extending the selection).
775
- _this.$anchorCell = $anchorCell;
776
- // :: ResolvedPos
777
- // A resolved position pointing in front of the head cell (the one
778
- // moves when extending the selection).
779
- _this.$headCell = $headCell;
780
- return _this;
781
- }
782
- // :: (ResolvedPos, ?ResolvedPos) → CellSelection
783
- // Returns the smallest column selection that covers the given anchor
784
- // and head cell.
785
- CellSelection.colSelection = function ($anchorCell, $headCell) {
786
- if ($headCell === void 0) { $headCell = $anchorCell; }
787
- var map$$1 = TableMap.get($anchorCell.node(-1));
788
- var start = $anchorCell.start(-1);
789
- var anchorRect = map$$1.findCell($anchorCell.pos - start);
790
- var headRect = map$$1.findCell($headCell.pos - start);
791
- var doc = $anchorCell.node(0);
792
- if (anchorRect.top <= headRect.top) {
793
- if (anchorRect.top > 0) {
794
- $anchorCell = doc.resolve(start + map$$1.map[anchorRect.left]);
795
- }
796
- if (headRect.bottom < map$$1.height) {
797
- $headCell = doc.resolve(start + map$$1.map[map$$1.width * (map$$1.height - 1) + headRect.right - 1]);
798
- }
799
- }
800
- else {
801
- if (headRect.top > 0) {
802
- $headCell = doc.resolve(start + map$$1.map[headRect.left]);
803
- }
804
- if (anchorRect.bottom < map$$1.height) {
805
- $anchorCell = doc.resolve(start + map$$1.map[map$$1.width * (map$$1.height - 1) + anchorRect.right - 1]);
806
- }
807
- }
808
- return new CellSelection($anchorCell, $headCell);
809
- };
810
- // :: (ResolvedPos, ?ResolvedPos) → CellSelection
811
- // Returns the smallest row selection that covers the given anchor
812
- // and head cell.
813
- CellSelection.rowSelection = function ($anchorCell, $headCell) {
814
- if ($headCell === void 0) { $headCell = $anchorCell; }
815
- var map$$1 = TableMap.get($anchorCell.node(-1));
816
- var start = $anchorCell.start(-1);
817
- var anchorRect = map$$1.findCell($anchorCell.pos - start);
818
- var headRect = map$$1.findCell($headCell.pos - start);
819
- var doc = $anchorCell.node(0);
820
- if (anchorRect.left <= headRect.left) {
821
- if (anchorRect.left > 0) {
822
- $anchorCell = doc.resolve(start + map$$1.map[anchorRect.top * map$$1.width]);
823
- }
824
- if (headRect.right < map$$1.width) {
825
- $headCell = doc.resolve(start + map$$1.map[map$$1.width * (headRect.top + 1) - 1]);
826
- }
827
- }
828
- else {
829
- if (headRect.left > 0) {
830
- $headCell = doc.resolve(start + map$$1.map[headRect.top * map$$1.width]);
831
- }
832
- if (anchorRect.right < map$$1.width) {
833
- $anchorCell = doc.resolve(start + map$$1.map[map$$1.width * (anchorRect.top + 1) - 1]);
834
- }
835
- }
836
- return new CellSelection($anchorCell, $headCell);
837
- };
838
- CellSelection.fromJSON = function (doc, json) {
839
- return new CellSelection(doc.resolve(json.anchor), doc.resolve(json.head));
840
- };
841
- // :: (Node, number, ?number) → CellSelection
842
- CellSelection.create = function (doc, anchorCell, headCell) {
843
- if (headCell === void 0) { headCell = anchorCell; }
844
- return new CellSelection(doc.resolve(anchorCell), doc.resolve(headCell));
845
- };
846
- CellSelection.prototype.map = function (doc, mapping) {
847
- var $anchorCell = doc.resolve(mapping.map(this.$anchorCell.pos));
848
- var $headCell = doc.resolve(mapping.map(this.$headCell.pos));
849
- if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {
850
- var tableChanged = this.$anchorCell.node(-1) !== $anchorCell.node(-1);
851
- if (tableChanged && this.isRowSelection()) {
852
- return CellSelection.rowSelection($anchorCell, $headCell);
853
- }
854
- else {
855
- if (tableChanged && this.isColSelection()) {
856
- return CellSelection.colSelection($anchorCell, $headCell);
857
- }
858
- else {
859
- return new CellSelection($anchorCell, $headCell);
860
- }
861
- }
862
- }
863
- return TextSelection.between($anchorCell, $headCell);
864
- };
865
- // :: () → Slice
866
- // Returns a rectangular slice of table rows containing the selected
867
- // cells.
868
- CellSelection.prototype.content = function () {
869
- var table = this.$anchorCell.node(-1), map$$1 = TableMap.get(table), start = this.$anchorCell.start(-1);
870
- var rect = map$$1.rectBetween(this.$anchorCell.pos - start, this.$headCell.pos - start);
871
- var seen = {}, rows = [];
872
- for (var row = rect.top; row < rect.bottom; row++) {
873
- var rowContent = [];
874
- for (var index = row * map$$1.width + rect.left, col = rect.left; col < rect.right; col++, index++) {
875
- var pos = map$$1.map[index];
876
- if (!seen[pos]) {
877
- seen[pos] = true;
878
- var cellRect = map$$1.findCell(pos), cell = table.nodeAt(pos);
879
- var extraLeft = rect.left - cellRect.left, extraRight = cellRect.right - rect.right;
880
- if (extraLeft > 0 || extraRight > 0) {
881
- var attrs = cell.attrs;
882
- if (extraLeft > 0) {
883
- attrs = removeColSpan(attrs, 0, extraLeft);
884
- }
885
- if (extraRight > 0) {
886
- attrs = removeColSpan(attrs, attrs.colspan - extraRight, extraRight);
887
- }
888
- if (cellRect.left < rect.left) {
889
- cell = cell.type.createAndFill(attrs);
890
- }
891
- else {
892
- cell = cell.type.create(attrs, cell.content);
893
- }
894
- }
895
- if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {
896
- var attrs = setAttr(cell.attrs, 'rowspan', Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top));
897
- if (cellRect.top < rect.top) {
898
- cell = cell.type.createAndFill(attrs);
899
- }
900
- else {
901
- cell = cell.type.create(attrs, cell.content);
902
- }
903
- }
904
- rowContent.push(cell);
905
- }
906
- }
907
- rows.push(table.child(row).copy(Fragment.from(rowContent)));
908
- }
909
- var fragment = this.isColSelection() && this.isRowSelection() ? table : rows;
910
- return new Slice(Fragment.from(fragment), 1, 1);
911
- };
912
- CellSelection.prototype.replace = function (tr, content) {
913
- if (content === void 0) { content = Slice.empty; }
914
- var mapFrom = tr.steps.length;
915
- var ranges = this.ranges;
916
- for (var i = 0; i < ranges.length; i++) {
917
- var _a = ranges[i], $from = _a.$from, $to = _a.$to;
918
- var mapping = tr.mapping.slice(mapFrom);
919
- tr.replace(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);
920
- }
921
- var sel = Selection.findFrom(tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)), -1);
922
- if (sel) {
923
- tr.setSelection(sel);
924
- }
925
- };
926
- CellSelection.prototype.replaceWith = function (tr, node) {
927
- this.replace(tr, new Slice(Fragment.from(node), 0, 0));
928
- };
929
- CellSelection.prototype.forEachCell = function (f) {
930
- var table = this.$anchorCell.node(-1);
931
- var map$$1 = TableMap.get(table);
932
- var start = this.$anchorCell.start(-1);
933
- var cells = map$$1.cellsInRect(map$$1.rectBetween(this.$anchorCell.pos - start, this.$headCell.pos - start));
934
- for (var i = 0; i < cells.length; i++) {
935
- f(table.nodeAt(cells[i]), start + cells[i]);
936
- }
937
- };
938
- // :: () → bool
939
- // True if this selection goes all the way from the top to the
940
- // bottom of the table.
941
- CellSelection.prototype.isColSelection = function () {
942
- var anchorTop = this.$anchorCell.index(-1), headTop = this.$headCell.index(-1);
943
- if (Math.min(anchorTop, headTop) > 0) {
944
- return false;
945
- }
946
- var anchorBot = anchorTop + this.$anchorCell.nodeAfter.attrs.rowspan;
947
- var headBot = headTop + this.$headCell.nodeAfter.attrs.rowspan;
948
- return Math.max(anchorBot, headBot) === this.$headCell.node(-1).childCount;
949
- };
950
- // :: () → bool
951
- // True if this selection goes all the way from the left to the
952
- // right of the table.
953
- CellSelection.prototype.isRowSelection = function () {
954
- var map$$1 = TableMap.get(this.$anchorCell.node(-1));
955
- var start = this.$anchorCell.start(-1);
956
- var anchorLeft = map$$1.colCount(this.$anchorCell.pos - start);
957
- var headLeft = map$$1.colCount(this.$headCell.pos - start);
958
- if (Math.min(anchorLeft, headLeft) > 0) {
959
- return false;
960
- }
961
- var anchorRight = anchorLeft + this.$anchorCell.nodeAfter.attrs.colspan;
962
- var headRight = headLeft + this.$headCell.nodeAfter.attrs.colspan;
963
- return Math.max(anchorRight, headRight) === map$$1.width;
964
- };
965
- CellSelection.prototype.eq = function (other) {
966
- return (other instanceof CellSelection && other.$anchorCell.pos === this.$anchorCell.pos && other.$headCell.pos === this.$headCell.pos);
967
- };
968
- CellSelection.prototype.toJSON = function () {
969
- return { type: 'cell', anchor: this.$anchorCell.pos, head: this.$headCell.pos };
970
- };
971
- CellSelection.prototype.getBookmark = function () {
972
- return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos);
973
- };
974
- return CellSelection;
975
- }(Selection));
976
- CellSelection.prototype.visible = false;
977
- Selection.jsonID('table_cell', CellSelection);
978
- var CellBookmark = /** @class */ (function () {
979
- function CellBookmark(anchor, head) {
980
- this.anchor = anchor;
981
- this.head = head;
982
- }
983
- CellBookmark.prototype.map = function (mapping) {
984
- return new CellBookmark(mapping.map(this.anchor), mapping.map(this.head));
985
- };
986
- CellBookmark.prototype.resolve = function (doc) {
987
- var $anchorCell = doc.resolve(this.anchor), $headCell = doc.resolve(this.head);
988
- if ($anchorCell.parent.type.spec.tableRole === 'row' &&
989
- $headCell.parent.type.spec.tableRole === 'row' &&
990
- $anchorCell.index() < $anchorCell.parent.childCount &&
991
- $headCell.index() < $headCell.parent.childCount &&
992
- inSameTable($anchorCell, $headCell)) {
993
- return new CellSelection($anchorCell, $headCell);
994
- }
995
- else {
996
- return Selection.near($headCell, 1);
997
- }
998
- };
999
- return CellBookmark;
1000
- }());
1001
-
1002
- /**
1003
- * @hidden
1004
- */
1005
- var findParentNodeClosestToPos = function ($pos, predicate) {
1006
- for (var i = $pos.depth; i > 0; i--) {
1007
- var node = $pos.node(i);
1008
- if (predicate(node)) {
1009
- return {
1010
- start: $pos.start(i),
1011
- pos: i > 0 ? $pos.before(i) : 0,
1012
- depth: i,
1013
- node: node
1014
- };
1015
- }
1016
- }
1017
- };
1018
- /**
1019
- * @hidden
1020
- */
1021
- var createTable = function (nodes$$1, rows, columns) {
1022
- var table = nodes$$1.table, table_body = nodes$$1.table_body, table_row = nodes$$1.table_row, table_cell = nodes$$1.table_cell;
1023
- var tableRows = [];
1024
- var cells;
1025
- for (var r = 0; r < rows + 1; r++) {
1026
- cells = [];
1027
- for (var c = 0; c < columns + 1; c++) {
1028
- cells.push(table_cell.createAndFill());
1029
- }
1030
- tableRows.push(table_row.createAndFill(undefined, cells));
1031
- }
1032
- var body = table_body.createAndFill(undefined, tableRows);
1033
- return table.createAndFill(undefined, body);
1034
- };
1035
- /**
1036
- * @hidden
1037
- */
1038
- var isInTable = function (state) {
1039
- var $head = state.selection.$head;
1040
- for (var d = $head.depth; d > 0; d--) {
1041
- if (isTableRow($head.node(d))) {
1042
- return true;
1043
- }
1044
- }
1045
- return false;
1046
- };
1047
- /**
1048
- * @hidden
1049
- */
1050
- var setAttr = function (attrs, name, value) {
1051
- var result = {};
1052
- // tslint:disable-next-line
1053
- for (var prop in attrs) {
1054
- result[prop] = attrs[prop];
1055
- }
1056
- result[name] = value;
1057
- return result;
1058
- };
1059
- var cellNear = function ($pos) {
1060
- for (var after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {
1061
- var role = after.type.spec.tableRole;
1062
- if (role === 'cell' || role === 'header_cell') {
1063
- return $pos.doc.resolve(pos);
1064
- }
1065
- }
1066
- for (var before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
1067
- var role = before.type.spec.tableRole;
1068
- if (role === 'cell' || role === 'header_cell') {
1069
- return $pos.doc.resolve(pos - before.nodeSize);
1070
- }
1071
- }
1072
- };
1073
- var cellAround = function ($pos) {
1074
- for (var d = $pos.depth - 1; d > 0; d--) {
1075
- if (isTableRow($pos.node(d))) {
1076
- return $pos.node(0).resolve($pos.before(d + 1));
1077
- }
1078
- }
1079
- return null;
1080
- };
1081
- var selectionCell = function (sel) {
1082
- if (sel instanceof CellSelection && sel.$anchorCell) {
1083
- return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
1084
- }
1085
- else if (sel instanceof NodeSelection && sel.node && isTableCell(sel.node)) {
1086
- return sel.$anchor;
1087
- }
1088
- return cellAround(sel.$head) || cellNear(sel.$head);
1089
- };
1090
- /**
1091
- * @hidden
1092
- */
1093
- // Helper to get the selected rectangle in a table, if any. Adds table
1094
- // map, table node, and table start offset to the object for
1095
- // convenience.
1096
- var selectedRect = function (sel) {
1097
- // create arr of rect for each table section
1098
- // there has to be a rect for thead, tbody and tfoot(if each exists)
1099
- // and NOT for colgroups
1100
- var $pos = selectionCell(sel);
1101
- var table = $pos.node(-1);
1102
- var tableStart = $pos.start(-1);
1103
- var map$$1 = TableMap.get(table);
1104
- var rect = sel instanceof CellSelection
1105
- ? map$$1.rectBetween(sel.$anchorCell.pos - tableStart, sel.$headCell.pos - tableStart)
1106
- : map$$1.findCell($pos.pos - tableStart);
1107
- rect.tableStart = tableStart;
1108
- rect.map = map$$1;
1109
- rect.table = table;
1110
- return rect;
1111
- };
1112
- /**
1113
- * @hidden
1114
- */
1115
- // this has to be removed since the schema should not have roles inside NodeSpec.
1116
- var tableNodeTypes = function (schema) {
1117
- var result = schema.cached.tableNodeTypes;
1118
- if (!result) {
1119
- result = schema.cached.tableNodeTypes = {};
1120
- // tslint:disable-next-line
1121
- for (var name_1 in schema.nodes) {
1122
- var type = schema.nodes[name_1];
1123
- var role = type.spec.tableRole;
1124
- if (role) {
1125
- result[role] = type;
1126
- }
1127
- }
1128
- }
1129
- return result;
1130
- };
1131
- /**
1132
- * @hidden
1133
- */
1134
- var rowIsHeader = function (map$$1, table, row) {
1135
- var headerCell = tableNodeTypes(table.type.schema).header_cell;
1136
- for (var col = 0; col < map$$1.width; col++) {
1137
- if (table.nodeAt(map$$1.map[col + row * map$$1.width]).type !== headerCell) {
1138
- return false;
1139
- }
1140
- }
1141
- return true;
1142
- };
1143
- /**
1144
- * @hidden
1145
- */
1146
- var addColSpan = function (attrs, pos, n) {
1147
- if (n === void 0) { n = 1; }
1148
- var result = setAttr(attrs, 'colspan', attrs.colspan + n);
1149
- if (result.colwidth) {
1150
- result.colwidth = result.colwidth.slice();
1151
- for (var i = 0; i < n; i++) {
1152
- result.colwidth.splice(pos, 0, 0);
1153
- }
1154
- }
1155
- return result;
1156
- };
1157
- /**
1158
- * @hidden
1159
- */
1160
- var removeColSpan = function (attrs, pos, n) {
1161
- if (n === void 0) { n = 1; }
1162
- var result = setAttr(attrs, 'colspan', attrs.colspan - n);
1163
- if (result.colwidth) {
1164
- result.colwidth = result.colwidth.slice();
1165
- result.colwidth.splice(pos, n);
1166
- if (!result.colwidth.some(function (w) { return w > 0; })) {
1167
- result.colwidth = null;
1168
- }
1169
- }
1170
- return result;
1171
- };
1172
- /**
1173
- * @hidden
1174
- */
1175
- var isCellEmpty = function (cell) {
1176
- var c = cell.content;
1177
- return c.childCount === 1 && c.firstChild.isTextblock && c.firstChild.childCount === 0;
1178
- };
1179
- var cellWrapping = function ($pos) {
1180
- for (var d = $pos.depth; d > 0; d--) {
1181
- // Sometimes the cell can be in the same depth.
1182
- var role = $pos.node(d).type.spec.tableRole;
1183
- if (role === 'cell' || role === 'header_cell') {
1184
- return $pos.node(d);
1185
- }
1186
- }
1187
- return null;
1188
- };
1189
- /**
1190
- * @hidden
1191
- */
1192
- // Split a selected cell, whose rowpan or colspan is greater than one,
1193
- // into smaller cells with the cell type (th, td) returned by getType function.
1194
- var splitCellWithType = function (getCellType) {
1195
- return function (state, dispatch) {
1196
- var sel = state.selection;
1197
- var cellNode;
1198
- var cellPos;
1199
- if (!(sel instanceof CellSelection)) {
1200
- cellNode = cellWrapping(sel.$from);
1201
- if (!cellNode) {
1202
- return false;
1203
- }
1204
- cellPos = cellAround(sel.$from).pos;
1205
- }
1206
- else {
1207
- if (sel.$anchorCell.pos !== sel.$headCell.pos) {
1208
- return false;
1209
- }
1210
- cellNode = sel.$anchorCell.nodeAfter;
1211
- cellPos = sel.$anchorCell.pos;
1212
- }
1213
- if (cellNode.attrs.colspan === 1 && cellNode.attrs.rowspan === 1) {
1214
- return false;
1215
- }
1216
- if (dispatch) {
1217
- var baseAttrs = cellNode.attrs;
1218
- var attrs = [];
1219
- var colwidth = baseAttrs.colwidth;
1220
- if (baseAttrs.rowspan > 1) {
1221
- baseAttrs = setAttr(baseAttrs, 'rowspan', 1);
1222
- }
1223
- if (baseAttrs.colspan > 1) {
1224
- baseAttrs = setAttr(baseAttrs, 'colspan', 1);
1225
- }
1226
- var rect = selectedRect(state);
1227
- var tr = state.tr;
1228
- for (var i = 0; i < rect.right - rect.left; i++) {
1229
- attrs.push(colwidth ? setAttr(baseAttrs, 'colwidth', colwidth && colwidth[i] ? [colwidth[i]] : null) : baseAttrs);
1230
- }
1231
- var lastCell = void 0;
1232
- for (var row = rect.top; row < rect.bottom; row++) {
1233
- var pos = rect.map.positionAt(row, rect.left, rect.table);
1234
- if (row === rect.top) {
1235
- pos += cellNode.nodeSize;
1236
- }
1237
- for (var col = rect.left, i = 0; col < rect.right; col++, i++) {
1238
- if (col === rect.left && row === rect.top) {
1239
- continue;
1240
- }
1241
- tr.insert((lastCell = tr.mapping.map(pos + rect.tableStart, 1)), getCellType({ node: cellNode, row: row, col: col }).createAndFill(attrs[i]));
1242
- }
1243
- }
1244
- tr.setNodeMarkup(cellPos, getCellType({ node: cellNode, row: rect.top, col: rect.left }), attrs[0]);
1245
- if (sel instanceof CellSelection) {
1246
- tr.setSelection(new CellSelection(tr.doc.resolve(sel.$anchorCell.pos), lastCell && tr.doc.resolve(lastCell)));
1247
- }
1248
- dispatch(tr);
1249
- }
1250
- return true;
1251
- };
1252
- };
1253
- /**
1254
- * @hidden
1255
- */
1256
- var pointsAtCell = function ($pos) {
1257
- return isTableRow($pos.parent) && $pos.nodeAfter;
1258
- };
1259
- /**
1260
- * @hidden
1261
- */
1262
- var inSameTable = function ($a, $b) {
1263
- return $a.depth === $b.depth && $a.pos >= $b.start(-1) && $a.pos <= $b.end(-1);
1264
- };
1265
- /**
1266
- * @hidden
1267
- */
1268
- var cellsOverlapRectangle = function (_a, rect) {
1269
- var width = _a.width, height = _a.height, map$$1 = _a.map;
1270
- var indexTop = rect.top * width + rect.left;
1271
- var indexLeft = indexTop;
1272
- var indexBottom = (rect.bottom - 1) * width + rect.left;
1273
- var indexRight = indexTop + (rect.right - rect.left - 1);
1274
- for (var i = rect.top; i < rect.bottom; i++) {
1275
- if ((rect.left > 0 && map$$1[indexLeft] === map$$1[indexLeft - 1]) || (rect.right < width && map$$1[indexRight] === map$$1[indexRight + 1])) {
1276
- return true;
1277
- }
1278
- indexLeft += width;
1279
- indexRight += width;
1280
- }
1281
- for (var i = rect.left; i < rect.right; i++) {
1282
- if ((rect.top > 0 && map$$1[indexTop] === map$$1[indexTop - width]) ||
1283
- (rect.bottom < height && map$$1[indexBottom] === map$$1[indexBottom + width])) {
1284
- return true;
1285
- }
1286
- indexTop++;
1287
- indexBottom++;
1288
- }
1289
- return false;
1290
- };
1291
-
1292
- /**
1293
- * @hidden
1294
- */
1295
- var insertTable = function (attrs) { return function (state, dispatch) {
1296
- var newTable = createTable(state.schema.nodes, attrs.rows, attrs.cols);
1297
- if (newTable) {
1298
- insertNode(newTable, true)(state, dispatch);
1299
- }
1300
- }; };
1301
- var addTableGroupColumn = function (tr, _a, col, mainTable, requiredGroup, doc) {
1302
- var left = _a.left, right = _a.right;
1303
- var refColumn = col > 0 ? -1 : 0;
1304
- // not sure if this should be deleted
1305
- // if (columnIsHeader(map, table, col + refColumn)) {
1306
- // refColumn = col === 0 || col === map.width ? null : 0;
1307
- // }
1308
- var rect;
1309
- mainTable.node.descendants(function (tableChildNode, offset) {
1310
- if (requiredGroup(tableChildNode)) {
1311
- var i_1 = -1;
1312
- tableChildNode.firstChild.descendants(function (childNode, pos) {
1313
- if (isTableCell(childNode) || isTableHeaderCell(childNode)) {
1314
- i_1 = i_1 + 1;
1315
- if (i_1 === right || i_1 === left) {
1316
- var selection = new Selection(doc.resolve(pos + offset + mainTable.start), doc.resolve(pos + offset + mainTable.start));
1317
- rect = selectedRect(selection);
1318
- }
1319
- }
1320
- });
1321
- }
1322
- });
1323
- // Do nothing if thead, tfoot or tbody is missing
1324
- if (!rect) {
1325
- return tr;
1326
- }
1327
- for (var row = 0; row < rect.map.height; row++) {
1328
- var index = row * rect.map.width + col;
1329
- // If this position falls inside a col-spanning cell
1330
- if (col > 0 && col < rect.map.width && rect.map.map[index - 1] === rect.map.map[index]) {
1331
- var pos = rect.map.map[index];
1332
- var cell = rect.table.nodeAt(pos);
1333
- tr.setNodeMarkup(tr.mapping.map(rect.tableStart + pos), null, addColSpan(cell.attrs, col - rect.map.colCount(pos)));
1334
- // Skip ahead if rowspan > 1
1335
- row += cell.attrs.rowspan - 1;
1336
- }
1337
- else {
1338
- var type = rect.table.nodeAt(rect.map.map[index + refColumn]).type;
1339
- var pos = rect.map.positionAt(row, col, rect.table);
1340
- tr.insert(tr.mapping.map(rect.tableStart + pos), type.createAndFill());
1341
- }
1342
- }
1343
- return tr;
1344
- };
1345
- var removeTableGroupColumn = function (tr, _a, mainTable, requiredGroup, doc) {
1346
- var right = _a.right, left = _a.left;
1347
- var rect;
1348
- mainTable.node.descendants(function (tableChildNode, offset) {
1349
- if (requiredGroup(tableChildNode)) {
1350
- var i_2 = -1;
1351
- tableChildNode.firstChild.descendants(function (childNode, pos) {
1352
- if (isTableCell(childNode) || isTableHeaderCell(childNode)) {
1353
- i_2 = i_2 + 1;
1354
- if (i_2 >= left && i_2 < right) {
1355
- var resolvedPos = doc.resolve(pos + offset + mainTable.start + childNode.nodeSize);
1356
- var selection = new Selection(resolvedPos, resolvedPos);
1357
- rect = selectedRect(selection);
1358
- }
1359
- }
1360
- });
1361
- }
1362
- });
1363
- // Do nothing if thead, tfoot or tbody is missing
1364
- if (!rect) {
1365
- return;
1366
- }
1367
- for (var i = rect.right - 1;; i--) {
1368
- removeColumn(tr, rect, i);
1369
- if (i === rect.left) {
1370
- break;
1371
- }
1372
- rect.table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;
1373
- rect.map = TableMap.get(rect.table);
1374
- }
1375
- return;
1376
- };
1377
- var removeColumn = function (tr, _a, col) {
1378
- var map$$1 = _a.map, table = _a.table, tableStart = _a.tableStart;
1379
- for (var row = 0; row < map$$1.height;) {
1380
- var index = row * map$$1.width + col;
1381
- var pos = map$$1.map[index];
1382
- var cell = table.nodeAt(pos);
1383
- // If this is part of a col-spanning cell
1384
- if ((col > 0 && map$$1.map[index - 1] === pos) || (col < map$$1.width - 1 && map$$1.map[index + 1] === pos)) {
1385
- tr.setNodeMarkup(tr.mapping.map(tableStart + pos), null, removeColSpan(cell.attrs, col - map$$1.colCount(pos)));
1386
- }
1387
- else {
1388
- var start = tr.mapping.map(tableStart + pos);
1389
- tr.delete(start, start + cell.nodeSize);
1390
- }
1391
- row += cell.attrs.rowspan;
1392
- }
1393
- };
1394
- /**
1395
- * @hidden
1396
- */
1397
- // Command to add a column before the column with the selection.
1398
- var addColumnBefore$1 = function (state, dispatch) {
1399
- if (!isInTable(state)) {
1400
- return false;
1401
- }
1402
- if (dispatch) {
1403
- var rect = selectedRect(state.selection);
1404
- var mainTable = findParentNodeClosestToPos(state.selection.$anchor, isTable);
1405
- var tHeadTr = addTableGroupColumn(state.tr, rect, rect.left, mainTable, isTableHead, state.doc);
1406
- var tBodyTr = addTableGroupColumn(tHeadTr, rect, rect.left, mainTable, isTableBody, state.doc);
1407
- var tFootTr = addTableGroupColumn(tBodyTr, rect, rect.left, mainTable, isTableFoot, state.doc);
1408
- dispatch(tFootTr);
1409
- }
1410
- return true;
73
+ var commonAttributes = function () {
74
+ return __assign({}, createDefaultAttributes(['class', 'id', 'style']));
1411
75
  };
1412
76
  /**
1413
77
  * @hidden
1414
78
  */
1415
- // Command to add a column after the column with the selection.
1416
- var addColumnAfter$1 = function (state, dispatch) {
1417
- if (!isInTable(state)) {
1418
- return false;
1419
- }
1420
- if (dispatch) {
1421
- var rect = selectedRect(state.selection);
1422
- var mainTable = findParentNodeClosestToPos(state.selection.$anchor, isTable);
1423
- var theadTr = addTableGroupColumn(state.tr, rect, rect.right, mainTable, isTableHead, state.doc);
1424
- var tBodyTr = addTableGroupColumn(theadTr, rect, rect.right, mainTable, isTableBody, state.doc);
1425
- var tFootTr = addTableGroupColumn(tBodyTr, rect, rect.right, mainTable, isTableFoot, state.doc);
1426
- dispatch(tFootTr);
1427
- }
1428
- return true;
1429
- };
1430
- var addRow = function (tr, _a, row) {
1431
- var map$$1 = _a.map, tableStart = _a.tableStart, table = _a.table;
1432
- var rowPos = tableStart;
1433
- for (var i = 0; i < row; i++) {
1434
- rowPos += table.child(i).nodeSize;
1435
- }
1436
- var cells = [];
1437
- var refRow = row > 0 ? -1 : 0;
1438
- if (rowIsHeader(map$$1, table, row + refRow)) {
1439
- refRow = row === 0 || row === map$$1.height ? null : 0;
1440
- }
1441
- for (var col = 0, index = map$$1.width * row; col < map$$1.width; col++, index++) {
1442
- // Covered by a rowspan cell
1443
- if (row > 0 && row < map$$1.height && map$$1.map[index] === map$$1.map[index - map$$1.width]) {
1444
- var pos = map$$1.map[index];
1445
- var attrs = table.nodeAt(pos).attrs;
1446
- tr.setNodeMarkup(tableStart + pos, null, setAttr(attrs, 'rowspan', attrs.rowspan + 1));
1447
- col += attrs.colspan - 1;
1448
- }
1449
- else {
1450
- var type = refRow == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map$$1.map[index + refRow * map$$1.width]).type;
1451
- cells.push(type.createAndFill());
1452
- }
1453
- }
1454
- tr.insert(rowPos, tableNodeTypes(table.type.schema).row.create(null, cells));
1455
- return tr;
79
+ var createDefaultAttributes = function (attrs) {
80
+ if (attrs === void 0) { attrs = []; }
81
+ return __assign({}, attrs.reduce(function (acc, curr) {
82
+ var _a;
83
+ return (__assign({}, acc, (_a = {}, _a[curr] = { default: null }, _a)));
84
+ }, {}));
1456
85
  };
1457
86
  /**
1458
87
  * @hidden
1459
88
  */
1460
- // Add a table row before the selection.
1461
- var addRowBefore$1 = function (state, dispatch) {
1462
- if (!isInTable(state)) {
1463
- return false;
1464
- }
1465
- if (dispatch) {
1466
- var rect = selectedRect(state.selection);
1467
- dispatch(addRow(state.tr, rect, rect.top));
1468
- }
1469
- return true;
1470
- };
89
+ var hole = 0;
90
+
91
+ var createSemanticNode = function (tagName) { return ({
92
+ // Uncaught SyntaxError: Mixing inline and block content (in content expression '(block | inline)*')
93
+ // content: '(block | inline)*',
94
+ content: 'block*',
95
+ group: 'block',
96
+ attrs: __assign({}, commonAttributes()),
97
+ parseDOM: [{
98
+ tag: tagName,
99
+ getAttrs: getAttributes
100
+ }],
101
+ toDOM: function (node) { return hasAttrs(node.attrs) ? [tagName, getAttrs(node.attrs), hole] : [tagName, hole]; }
102
+ }); };
1471
103
  /**
1472
104
  * @hidden
1473
105
  */
1474
- // Add a table row after the selection.
1475
- var addRowAfter$1 = function (state, dispatch) {
1476
- if (!isInTable(state)) {
1477
- return false;
1478
- }
1479
- if (dispatch) {
1480
- var rect = selectedRect(state.selection);
1481
- dispatch(addRow(state.tr, rect, rect.bottom));
1482
- }
1483
- return true;
106
+ var semanticTagNames = ['article', 'main', 'nav', 'header', 'footer', 'aside', 'section'];
107
+ var ɵ1 = function (acc, curr) {
108
+ var _a;
109
+ return Object.assign(acc, (_a = {}, _a[curr] = createSemanticNode(curr), _a));
1484
110
  };
1485
111
  /**
1486
112
  * @hidden
1487
113
  */
1488
- // Command function that removes the selected columns from a table.
1489
- var deleteColumn$1 = function (state, dispatch) {
1490
- if (!isInTable(state)) {
1491
- return false;
1492
- }
1493
- if (dispatch) {
1494
- var rect = selectedRect(state.selection);
1495
- // if only one column left - delete the whole table
1496
- if (rect.left === 0 && rect.right === rect.map.width) {
1497
- return deleteTable$1(state, dispatch);
1498
- }
1499
- var mainTable = findParentNodeClosestToPos(state.selection.$anchor, isTable);
1500
- var tr = state.tr;
1501
- removeTableGroupColumn(tr, rect, mainTable, isTableFoot, tr.doc);
1502
- removeTableGroupColumn(tr, rect, mainTable, isTableBody, tr.doc);
1503
- removeTableGroupColumn(tr, rect, mainTable, isTableHead, tr.doc);
1504
- dispatch(tr);
1505
- }
1506
- return true;
1507
- };
1508
- var removeRow = function (tr, _a, row) {
1509
- var map$$1 = _a.map, table = _a.table, tableStart = _a.tableStart;
1510
- var rowPos = 0;
1511
- for (var i = 0; i < row; i++) {
1512
- rowPos += table.child(i).nodeSize;
1513
- }
1514
- var nextRow = rowPos + table.child(row).nodeSize;
1515
- var mapFrom = tr.mapping.maps.length;
1516
- tr.delete(rowPos + tableStart, nextRow + tableStart);
1517
- for (var col = 0, index = row * map$$1.width; col < map$$1.width; col++, index++) {
1518
- var pos = map$$1.map[index];
1519
- if (row > 0 && pos === map$$1.map[index - map$$1.width]) {
1520
- // If this cell starts in the row above, simply reduce its rowspan
1521
- var attrs = table.nodeAt(pos).attrs;
1522
- tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + tableStart), null, setAttr(attrs, 'rowspan', attrs.rowspan - 1));
1523
- col += attrs.colspan - 1;
1524
- }
1525
- else if (row < map$$1.width && pos === map$$1.map[index + map$$1.width]) {
1526
- // Else, if it continues in the row below, it has to be moved down
1527
- var cell = table.nodeAt(pos);
1528
- var copy = cell.type.create(setAttr(cell.attrs, 'rowspan', cell.attrs.rowspan - 1), cell.content);
1529
- var newPos = map$$1.positionAt(row + 1, col, table);
1530
- tr.insert(tr.mapping.slice(mapFrom).map(tableStart + newPos), copy);
1531
- col += cell.attrs.colspan - 1;
1532
- }
1533
- }
1534
- };
114
+ var semanticNodes = semanticTagNames.reduce(ɵ1, {});
115
+
1535
116
  /**
1536
117
  * @hidden
1537
118
  */
1538
- // Remove the selected rows from a table.
1539
- var deleteRow$1 = function (state, dispatch) {
1540
- if (!isInTable(state)) {
1541
- return false;
1542
- }
1543
- if (dispatch) {
1544
- var rect_1 = selectedRect(state.selection);
1545
- var tr = state.tr;
1546
- if (rect_1.top === 0 && rect_1.bottom === rect_1.map.height) {
1547
- var mainTable = findParentNodeClosestToPos(state.selection.$anchor, isTable);
1548
- if (mainTable.node.childCount === 1) {
1549
- deleteTable$1(state, dispatch);
1550
- }
1551
- else {
1552
- deleteTableElement(function (n) { return n.type.name === rect_1.table.type.name; })(state, dispatch);
1553
- }
1554
- return true;
1555
- }
1556
- for (var i = rect_1.bottom - 1;; i--) {
1557
- removeRow(tr, rect_1, i);
1558
- if (i === rect_1.top) {
1559
- break;
1560
- }
1561
- rect_1.table = rect_1.tableStart ? tr.doc.nodeAt(rect_1.tableStart - 1) : tr.doc;
1562
- rect_1.map = TableMap.get(rect_1.table);
1563
- }
1564
- dispatch(tr);
1565
- }
1566
- return true;
1567
- };
119
+ var marks$1 = marks;
120
+ var nodes$1 = Object.assign(nodes, semanticNodes);
1568
121
  /**
1569
122
  * @hidden
1570
123
  */
1571
- // Merge the selected cells into a single cell. Only available when
1572
- // the selected cells' outline forms a rectangle.
1573
- var mergeCells$1 = function (state, dispatch) {
1574
- var sel = state.selection;
1575
- if (!(sel instanceof CellSelection) || sel.$anchorCell.pos === sel.$headCell.pos) {
1576
- return false;
1577
- }
1578
- var rect = selectedRect(state.selection);
1579
- var map$$1 = rect.map;
1580
- if (cellsOverlapRectangle(map$$1, rect)) {
1581
- return false;
1582
- }
1583
- if (dispatch) {
1584
- var tr = state.tr;
1585
- var seen = {};
1586
- var content = Fragment.empty;
1587
- var mergedPos = void 0;
1588
- var mergedCell = void 0;
1589
- for (var row = rect.top; row < rect.bottom; row++) {
1590
- for (var col = rect.left; col < rect.right; col++) {
1591
- var cellPos = map$$1.map[row * map$$1.width + col], cell = rect.table.nodeAt(cellPos);
1592
- if (seen[cellPos]) {
1593
- continue;
1594
- }
1595
- seen[cellPos] = true;
1596
- if (mergedPos === null) {
1597
- mergedPos = cellPos;
1598
- mergedCell = cell;
1599
- }
1600
- else {
1601
- if (!isCellEmpty(cell)) {
1602
- content = content.append(cell.content);
1603
- }
1604
- var mapped = tr.mapping.map(cellPos + rect.tableStart);
1605
- tr.delete(mapped, mapped + cell.nodeSize);
1606
- }
1607
- }
1608
- }
1609
- tr.setNodeMarkup(mergedPos + rect.tableStart, null, setAttr(addColSpan(mergedCell.attrs, mergedCell.attrs.colspan, rect.right - rect.left - mergedCell.attrs.colspan), 'rowspan', rect.bottom - rect.top));
1610
- if (content.size) {
1611
- var end = mergedPos + 1 + mergedCell.content.size;
1612
- var start = isCellEmpty(mergedCell) ? mergedPos + 1 : end;
1613
- tr.replaceWith(start + rect.tableStart, end + rect.tableStart, content);
1614
- }
1615
- tr.setSelection(new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart)));
1616
- dispatch(tr);
1617
- }
1618
- return true;
1619
- };
124
+ var schema = new Schema({
125
+ marks: marks$1,
126
+ nodes: __assign({}, nodes$1, { blockquote: __assign({}, nodes$1.blockquote, { content: 'inline*' }) })
127
+ });
128
+
1620
129
  /**
1621
130
  * @hidden
1622
131
  */
1623
- // Split a selected cell, whose rowpan or colspan is greater than one,
1624
- // into smaller cells. Use the first cell type for the new cells.
1625
- var splitCell$1 = function (state, dispatch) {
1626
- var nodeTypes = tableNodeTypes(state.schema);
1627
- return splitCellWithType(function (_a) {
1628
- var node = _a.node;
1629
- return nodeTypes[node.type.spec.tableRole];
1630
- })(state, dispatch);
1631
- };
1632
- var deleteTableElement = function (selector) { return function (state, dispatch) {
1633
- var $pos = state.selection.$anchor;
1634
- for (var d = $pos.depth; d > 0; d--) {
1635
- var node = $pos.node(d);
1636
- if (selector(node)) {
1637
- if (dispatch) {
1638
- var tr = state.tr;
1639
- tr.delete($pos.before(d), $pos.after(d)).scrollIntoView();
1640
- dispatch(tr);
1641
- }
1642
- return true;
1643
- }
132
+ var insertTable = function (attrs) { return function (state, dispatch) {
133
+ var newTable = createTable(state.schema.nodes, attrs.rows, attrs.cols);
134
+ if (newTable) {
135
+ insertNode(newTable, true)(state, dispatch);
1644
136
  }
1645
- return false;
1646
137
  }; };
1647
- /**
1648
- * @hidden
1649
- */
1650
- // Deletes the table around the selection, if any.
1651
- var deleteTable$1 = deleteTableElement(isTable);
1652
138
 
1653
139
  var alignRemove = function (state, dispatch) { return alignBlocks(alignRemoveRules)(state, dispatch); };
1654
- var ɵ1$5 = function (applyToWord) { return expandToWordWrap(toggleInlineFormat, __assign({}, bold, { applyToWord: applyToWord })); }, ɵ2$4 = function (options) { return cleanFormatting(options); }, ɵ3$4 = function (attrs) { return expandToWordWrap(applyLink, { mark: 'link', attrs: attrs.value, applyToWord: attrs.applyToWord }); }, ɵ4$2 = function (attrs) { return expandToWordWrap(applyInlineStyle, { style: 'font-family', value: attrs.value, applyToWord: attrs.applyToWord }); }, ɵ5$2 = function (attrs) { return expandToWordWrap(applyInlineStyle, { style: 'font-size', value: attrs.value + 'px', applyToWord: attrs.applyToWord }); }, ɵ6$1 = function (attrs) { return expandToWordWrap(applyLink, { mark: 'link', attrs: attrs, applyToWord: attrs.applyToWord }); }, ɵ7$1 = function (text) { return insertText(text); }, ɵ8$1 = function (applyToWord) { return expandToWordWrap(toggleInlineFormat, __assign({}, italic, { applyToWord: applyToWord })); }, ɵ9$1 = function (applyToWord) { return expandToWordWrap(toggleInlineFormat, __assign({}, strikethrough, { applyToWord: applyToWord })); }, ɵ10 = function (applyToWord) { return expandToWordWrap(toggleInlineFormat, __assign({}, subscript, { applyToWord: applyToWord })); }, ɵ11 = function (applyToWord) { return expandToWordWrap(toggleInlineFormat, __assign({}, superscript, { applyToWord: applyToWord })); }, ɵ12 = function (applyToWord) { return expandToWordWrap(toggleInlineFormat, __assign({}, underline, { applyToWord: applyToWord })); }, ɵ13 = function () { return removeLink(link); }, ɵ14 = function (attrs) { return expandToWordWrap(applyInlineStyle, { style: 'color', value: attrs.value, applyToWord: attrs.applyToWord }); }, ɵ15 = function (attrs) { return expandToWordWrap(applyInlineStyle, { style: 'background-color', value: attrs.value, applyToWord: attrs.applyToWord }); }, ɵ16 = function () { return function (state, dispatch) { return selectAll(state, dispatch); }; };
140
+ var ɵ1$1 = function (applyToWord) { return expandToWordWrap(toggleInlineFormat, __assign({}, bold, { applyToWord: applyToWord })); }, ɵ2 = function (options) { return cleanFormatting(options); }, ɵ3 = function (attrs) { return expandToWordWrap(applyLink, { mark: 'link', attrs: attrs.value, applyToWord: attrs.applyToWord }); }, ɵ4 = function (attrs) { return expandToWordWrap(applyInlineStyle, { style: 'font-family', value: attrs.value, applyToWord: attrs.applyToWord }); }, ɵ5 = function (attrs) { return expandToWordWrap(applyInlineStyle, { style: 'font-size', value: attrs.value + 'px', applyToWord: attrs.applyToWord }); }, ɵ6 = function (attrs) { return expandToWordWrap(applyLink, { mark: 'link', attrs: attrs, applyToWord: attrs.applyToWord }); }, ɵ7 = function (text) { return insertText(text); }, ɵ8 = function (applyToWord) { return expandToWordWrap(toggleInlineFormat, __assign({}, italic, { applyToWord: applyToWord })); }, ɵ9 = function (applyToWord) { return expandToWordWrap(toggleInlineFormat, __assign({}, strikethrough, { applyToWord: applyToWord })); }, ɵ10 = function (applyToWord) { return expandToWordWrap(toggleInlineFormat, __assign({}, subscript, { applyToWord: applyToWord })); }, ɵ11 = function (applyToWord) { return expandToWordWrap(toggleInlineFormat, __assign({}, superscript, { applyToWord: applyToWord })); }, ɵ12 = function (applyToWord) { return expandToWordWrap(toggleInlineFormat, __assign({}, underline, { applyToWord: applyToWord })); }, ɵ13 = function () { return removeLink(link); }, ɵ14 = function (attrs) { return expandToWordWrap(applyInlineStyle, { style: 'color', value: attrs.value, applyToWord: attrs.applyToWord }); }, ɵ15 = function (attrs) { return expandToWordWrap(applyInlineStyle, { style: 'background-color', value: attrs.value, applyToWord: attrs.applyToWord }); }, ɵ16 = function () { return function (state, dispatch) { return selectAll(state, dispatch); }; };
1655
141
  var inlineCommand = {
1656
- bold: ɵ1$5,
1657
- cleanFormatting: ɵ2$4,
1658
- createLink: ɵ3$4,
1659
- fontFamily: ɵ4$2,
1660
- fontSize: ɵ5$2,
1661
- insertFile: ɵ6$1,
1662
- insertText: ɵ7$1,
1663
- italic: ɵ8$1,
1664
- strikethrough: ɵ9$1,
142
+ bold: ɵ1$1,
143
+ cleanFormatting: ɵ2,
144
+ createLink: ɵ3,
145
+ fontFamily: ɵ4,
146
+ fontSize: ɵ5,
147
+ insertFile: ɵ6,
148
+ insertText: ɵ7,
149
+ italic: ɵ8,
150
+ strikethrough: ɵ9,
1665
151
  subscript: ɵ10,
1666
152
  superscript: ɵ11,
1667
153
  underline: ɵ12,
@@ -1692,7 +178,7 @@ var blockCommand = {
1692
178
  setHTML: ɵ29,
1693
179
  undo: ɵ30
1694
180
  };
1695
- var ɵ31 = function (attr) { return insertTable(attr); }, ɵ32 = function () { return addColumnBefore$1; }, ɵ33 = function () { return addColumnAfter$1; }, ɵ34 = function () { return addRowBefore$1; }, ɵ35 = function () { return addRowAfter$1; }, ɵ36 = function () { return deleteRow$1; }, ɵ37 = function () { return deleteColumn$1; }, ɵ38 = function () { return mergeCells$1; }, ɵ39 = function () { return splitCell$1; }, ɵ40 = function () { return deleteTable$1; };
181
+ var ɵ31 = function (attr) { return insertTable(attr); }, ɵ32 = function () { return addColumnBefore; }, ɵ33 = function () { return addColumnAfter; }, ɵ34 = function () { return addRowBefore; }, ɵ35 = function () { return addRowAfter; }, ɵ36 = function () { return deleteRow; }, ɵ37 = function () { return deleteColumn; }, ɵ38 = function () { return mergeCells; }, ɵ39 = function () { return splitCell; }, ɵ40 = function () { return deleteTable; };
1696
182
  var tableCommand = {
1697
183
  insertTable: ɵ31,
1698
184
  addColumnBefore: ɵ32,
@@ -1975,6 +461,117 @@ var disabledToolBarState = {
1975
461
  selectAll: { selected: false, disabled: true }
1976
462
  };
1977
463
 
464
+ /**
465
+ * @hidden
466
+ */
467
+ function outerWidth(element) {
468
+ var width = element.offsetWidth;
469
+ var style = getComputedStyle(element);
470
+ width += parseFloat(style.marginLeft) || 0 + parseFloat(style.marginRight) || 0;
471
+ return width;
472
+ }
473
+ /**
474
+ * @hidden
475
+ */
476
+ var removeEntries = function (obj, predicate) {
477
+ return Object.keys(obj)
478
+ .filter(function (key) { return predicate(key); })
479
+ .reduce(function (acc, curr) {
480
+ var _a;
481
+ return Object.assign(acc, (_a = {}, _a[curr] = obj[curr], _a));
482
+ }, {});
483
+ };
484
+ /**
485
+ * @hidden
486
+ */
487
+ var removeEmptyEntries = function (obj) {
488
+ var predicate = function (key) { return obj[key] !== null && obj[key] !== undefined && obj[key] !== ''; };
489
+ return removeEntries(obj, predicate);
490
+ };
491
+ /**
492
+ * @hidden
493
+ */
494
+ var isNullOrUndefined = function (value) { return value === undefined || value === null; };
495
+ /**
496
+ * @hidden
497
+ */
498
+ var isPresent = function (value) { return !isNullOrUndefined(value); };
499
+ /**
500
+ * @hidden
501
+ */
502
+ var detectIE = function () {
503
+ if (!isDocumentAvailable()) {
504
+ return false;
505
+ }
506
+ var ua = window.navigator.userAgent;
507
+ var msie = ua.indexOf('MSIE ');
508
+ var trident = ua.indexOf('Trident/');
509
+ return msie > 0 || trident > 0;
510
+ };
511
+ /**
512
+ * @hidden
513
+ */
514
+ var safeString = function (value) { return (isNullOrUndefined(value) ? '' : value.toString()); };
515
+ /**
516
+ * @hidden
517
+ */
518
+ var first = function (arr) { return arr[0]; };
519
+ /**
520
+ * @hidden
521
+ */
522
+ var last = function (arr) { return arr[arr.length - 1]; };
523
+ /**
524
+ * @hidden
525
+ */
526
+ var split = function (splitter) { return function (value) { return value.split(splitter); }; };
527
+ /**
528
+ * @hidden
529
+ */
530
+ var trim = function (value) { return value.trim(); };
531
+ /**
532
+ * @hidden
533
+ */
534
+ var filter$1 = function (predicate) { return function (arr) { return arr.filter(predicate); }; };
535
+ /**
536
+ * @hidden
537
+ */
538
+ var getUniqueStyleValues = function (style, cssStyle) {
539
+ if (style.hasNodesWithoutMarks) {
540
+ return '';
541
+ }
542
+ var uniqueMarkValues = style.marks
543
+ .filter(function (m) { return m.type.name === 'style'; })
544
+ .map(function (m) { return m.attrs.style; })
545
+ .map(safeString)
546
+ .map(split(';'))
547
+ .map(filter$1(function (m) { return m.includes(cssStyle); }))
548
+ // guards against empty array
549
+ .map(function (cssStyleValues) { return (cssStyleValues.length !== 0 ? cssStyleValues : [cssStyle + ": INVALID"]); })
550
+ .map(first)
551
+ .map(split(':'))
552
+ .map(last)
553
+ .map(trim)
554
+ .reduce(function (acc, curr) { return (acc.indexOf(curr) > -1 ? acc : acc.concat([curr])); }, []);
555
+ if (uniqueMarkValues.indexOf('INVALID') > -1 || uniqueMarkValues.length !== 1) {
556
+ return '';
557
+ }
558
+ return uniqueMarkValues[0];
559
+ };
560
+ /**
561
+ * @hidden
562
+ */
563
+ var conditionallyExecute = function (fn) { return function (condition) { return function (param) { return (condition ? fn(param) : param); }; }; };
564
+ /**
565
+ * @hidden
566
+ */
567
+ var pipe = function () {
568
+ var fns = [];
569
+ for (var _i = 0; _i < arguments.length; _i++) {
570
+ fns[_i] = arguments[_i];
571
+ }
572
+ return function (x) { return fns.reduce(function (y, f) { return f(y); }, x); };
573
+ };
574
+
1978
575
  /**
1979
576
  * @hidden
1980
577
  */
@@ -2273,7 +870,7 @@ var tablesStyles = "\n .ProseMirror .tableWrapper {\n overflow-x: auto;\n
2273
870
  */
2274
871
  var rtlStyles = 'body { direction: rtl }';
2275
872
 
2276
- var ɵ0$6 = function (arg) { return "plugins must be a function, but received " + JSON.stringify(arg) + "."; }, ɵ1$6 = function (arg) { return "pastedContent must be a function, but received " + JSON.stringify(arg) + "."; };
873
+ var ɵ0$2 = function (arg) { return "plugins must be a function, but received " + JSON.stringify(arg) + "."; }, ɵ1$2 = function (arg) { return "pastedContent must be a function, but received " + JSON.stringify(arg) + "."; };
2277
874
  /* tslint:disable:variable-name */
2278
875
  /**
2279
876
  * @hidden
@@ -2281,8 +878,8 @@ var ɵ0$6 = function (arg) { return "plugins must be a function, but received "
2281
878
  var EditorErrorMessages = {
2282
879
  schemaType: 'Expected value of type Schema. See http://www.telerik.com/kendo-angular-ui/components/editor/schema/',
2283
880
  setSchemaOnce: 'The Schema cannot be changed dynamically. See http://www.telerik.com/kendo-angular-ui/components/editor/schema/',
2284
- pluginsCallbackType: ɵ0$6,
2285
- pastedContentCallbackType: ɵ1$6,
881
+ pluginsCallbackType: ɵ0$2,
882
+ pastedContentCallbackType: ɵ1$2,
2286
883
  setPluginsOnce: 'The plugins cannot be changed dynamically. See http://www.telerik.com/kendo-angular-ui/components/editor/plugins/',
2287
884
  setPlaceHolderOnce: 'The placeholder cannot be changed dynamically. See http://www.telerik.com/kendo-angular-ui/components/editor/placeholder/',
2288
885
  printTool: 'The Print tool and functionality are supported only in iframe mode. See https://www.telerik.com/kendo-angular-ui-develop/components/editor/api/EditorPrintButtonDirective/'
@@ -2418,6 +1015,9 @@ var EditorComponent = /** @class */ (function () {
2418
1015
  this.contentAreaLoaded = new Subject();
2419
1016
  this.dispatchTransaction = function (tr) {
2420
1017
  var docChanged = tr.docChanged;
1018
+ if (_this.disabled || (_this.readonly && docChanged)) {
1019
+ return;
1020
+ }
2421
1021
  if (docChanged) {
2422
1022
  var doc = tr.doc;
2423
1023
  var html_1 = getHtml({ doc: doc });
@@ -3006,16 +1606,13 @@ var EditorComponent = /** @class */ (function () {
3006
1606
  }
3007
1607
  }); }
3008
1608
  }),
3009
- new Plugin({
3010
- key: new PluginKey('editor-filter-disabled-state'),
3011
- filterTransaction: function () { return !_this.disabled || _this.inForm; }
3012
- }),
3013
1609
  history(),
3014
1610
  keymap(buildListKeymap(currentSchema)),
3015
1611
  keymap(buildKeymap(currentSchema, { applyToWord: this.applyToWord })),
3016
1612
  keymap(baseKeymap),
3017
1613
  gapCursor(),
3018
- imageResizing()
1614
+ imageResizing(),
1615
+ tableEditing()
3019
1616
  ];
3020
1617
  if (this.placeholder) {
3021
1618
  defaultPlugins.push(placeholder(this.placeholder));