@progress/kendo-react-editor 6.1.1 → 7.0.0-develop.2

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