@progress/kendo-editor-common 1.12.2-develop.4 → 1.12.2-develop.6

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 (183) hide show
  1. package/dist/cdn/js/kendo-editor-common.js +1 -1
  2. package/dist/cdn/main.js +1 -1
  3. package/dist/es/DOMSerializer.js +6 -7
  4. package/dist/es/align.js +3 -6
  5. package/dist/es/blockNode.js +11 -14
  6. package/dist/es/blockquote.js +2 -5
  7. package/dist/es/cleanFormatting.js +3 -6
  8. package/dist/es/config/align-rules.js +5 -7
  9. package/dist/es/config/commands.js +13 -9
  10. package/dist/es/config/constants.js +7 -9
  11. package/dist/es/config/indent-rules.js +3 -6
  12. package/dist/es/config/keymap.js +7 -10
  13. package/dist/es/config/list-settings.js +3 -5
  14. package/dist/es/config/schema.js +4 -6
  15. package/dist/es/find-replace.js +8 -10
  16. package/dist/es/flatten-spans.js +2 -5
  17. package/dist/es/image.js +2 -5
  18. package/dist/es/indent.js +11 -14
  19. package/dist/es/inline-style.js +10 -12
  20. package/dist/es/link.js +5 -8
  21. package/dist/es/listConvert.js +8 -9
  22. package/dist/es/lists.js +12 -15
  23. package/dist/es/main.js +34 -33
  24. package/dist/es/mark.js +16 -17
  25. package/dist/es/paste.js +10 -13
  26. package/dist/es/plugins/caret-color.js +5 -8
  27. package/dist/es/plugins/csp-fix.js +2 -5
  28. package/dist/es/plugins/highlight.js +3 -6
  29. package/dist/es/plugins/image-resize.js +8 -11
  30. package/dist/es/plugins/list-markers-styles.js +2 -5
  31. package/dist/es/plugins/placeholder.js +2 -5
  32. package/dist/es/plugins/resize-utils.js +2 -4
  33. package/dist/es/plugins/spaces-fix.js +1 -4
  34. package/dist/es/plugins/table-resize/column-resize.js +21 -24
  35. package/dist/es/plugins/table-resize/index.js +6 -9
  36. package/dist/es/plugins/table-resize/row-resize.js +23 -24
  37. package/dist/es/plugins/table-resize/table-resize.js +17 -20
  38. package/dist/es/plugins/table-resize/table-view.js +6 -9
  39. package/dist/es/plugins/table-resize/utils.js +10 -13
  40. package/dist/es/source.js +15 -18
  41. package/dist/es/table.js +15 -18
  42. package/dist/es/text.js +1 -3
  43. package/dist/es/types/active-marks.js +1 -0
  44. package/dist/es/types/command.js +1 -0
  45. package/dist/es/types/dispatchFn.js +1 -0
  46. package/dist/es/types/paste-cleanup-settings.js +1 -0
  47. package/dist/es/types/predicate.js +1 -0
  48. package/dist/es/utils.js +18 -21
  49. package/dist/npm/DOMSerializer.d.ts +35 -0
  50. package/dist/npm/DOMSerializer.js +10 -9
  51. package/dist/npm/align.d.ts +4 -7
  52. package/dist/npm/align.js +9 -10
  53. package/dist/npm/blockNode.d.ts +15 -12
  54. package/dist/npm/blockNode.js +28 -29
  55. package/dist/npm/blockquote.d.ts +2 -5
  56. package/dist/npm/blockquote.js +6 -7
  57. package/dist/npm/cleanFormatting.d.ts +3 -6
  58. package/dist/npm/cleanFormatting.js +7 -8
  59. package/dist/npm/config/align-rules.d.ts +6 -8
  60. package/dist/npm/config/align-rules.js +8 -13
  61. package/dist/npm/config/commands.d.ts +19 -11
  62. package/dist/npm/config/commands.js +16 -17
  63. package/dist/npm/config/constants.d.ts +7 -0
  64. package/dist/npm/config/constants.js +10 -17
  65. package/dist/npm/config/indent-rules.d.ts +4 -6
  66. package/dist/npm/config/indent-rules.js +8 -11
  67. package/dist/npm/config/keymap.d.ts +2 -5
  68. package/dist/npm/config/keymap.js +21 -22
  69. package/dist/npm/config/list-settings.d.ts +30 -0
  70. package/dist/npm/config/list-settings.js +10 -13
  71. package/dist/npm/config/schema.d.ts +2 -3
  72. package/dist/npm/config/schema.js +19 -20
  73. package/dist/npm/find-replace.d.ts +7 -10
  74. package/dist/npm/find-replace.js +20 -20
  75. package/dist/npm/flatten-spans.d.ts +1 -3
  76. package/dist/npm/flatten-spans.js +6 -7
  77. package/dist/npm/image.d.ts +3 -6
  78. package/dist/npm/image.js +5 -6
  79. package/dist/npm/indent.d.ts +9 -12
  80. package/dist/npm/indent.js +37 -38
  81. package/dist/npm/inline-style.d.ts +4 -7
  82. package/dist/npm/inline-style.js +28 -28
  83. package/dist/npm/link.d.ts +2 -4
  84. package/dist/npm/link.js +21 -22
  85. package/dist/npm/listConvert.d.ts +1 -3
  86. package/dist/npm/listConvert.js +13 -12
  87. package/dist/npm/lists.d.ts +8 -8
  88. package/dist/npm/lists.js +26 -27
  89. package/dist/npm/main.d.ts +34 -35
  90. package/dist/npm/main.js +214 -391
  91. package/dist/npm/mark.d.ts +17 -12
  92. package/dist/npm/mark.js +30 -29
  93. package/dist/npm/paste.d.ts +8 -11
  94. package/dist/npm/paste.js +19 -20
  95. package/dist/npm/plugins/caret-color.d.ts +2 -5
  96. package/dist/npm/plugins/caret-color.js +15 -17
  97. package/dist/npm/plugins/csp-fix.d.ts +1 -4
  98. package/dist/npm/plugins/csp-fix.js +8 -9
  99. package/dist/npm/plugins/highlight.d.ts +4 -7
  100. package/dist/npm/plugins/highlight.js +11 -13
  101. package/dist/npm/plugins/image-resize.d.ts +5 -7
  102. package/dist/npm/plugins/image-resize.js +35 -37
  103. package/dist/npm/plugins/list-markers-styles.d.ts +2 -5
  104. package/dist/npm/plugins/list-markers-styles.js +14 -16
  105. package/dist/npm/plugins/placeholder.d.ts +1 -4
  106. package/dist/npm/plugins/placeholder.js +10 -12
  107. package/dist/npm/plugins/resize-utils.d.ts +35 -0
  108. package/dist/npm/plugins/resize-utils.js +5 -7
  109. package/dist/npm/plugins/spaces-fix.d.ts +1 -4
  110. package/dist/npm/plugins/spaces-fix.js +9 -10
  111. package/dist/npm/plugins/table-resize/column-resize.d.ts +2 -0
  112. package/dist/npm/plugins/table-resize/column-resize.js +44 -46
  113. package/dist/npm/plugins/table-resize/index.d.ts +2 -5
  114. package/dist/npm/plugins/table-resize/index.js +13 -14
  115. package/dist/npm/plugins/table-resize/row-resize.d.ts +2 -0
  116. package/dist/npm/plugins/table-resize/row-resize.js +40 -40
  117. package/dist/npm/plugins/table-resize/table-resize.d.ts +18 -0
  118. package/dist/npm/plugins/table-resize/table-resize.js +51 -52
  119. package/dist/npm/plugins/table-resize/table-view.d.ts +28 -0
  120. package/dist/npm/plugins/table-resize/table-view.js +23 -24
  121. package/dist/npm/plugins/table-resize/utils.d.ts +17 -7
  122. package/dist/npm/plugins/table-resize/utils.js +24 -28
  123. package/dist/npm/source.d.ts +13 -16
  124. package/dist/npm/source.js +35 -36
  125. package/dist/npm/table.d.ts +9 -10
  126. package/dist/npm/table.js +33 -49
  127. package/dist/npm/text.d.ts +3 -6
  128. package/dist/npm/text.js +3 -3
  129. package/dist/npm/types/active-marks.d.ts +1 -4
  130. package/dist/npm/types/active-marks.js +2 -0
  131. package/dist/npm/types/command.d.ts +2 -5
  132. package/dist/npm/types/command.js +2 -0
  133. package/dist/npm/types/dispatchFn.d.ts +1 -4
  134. package/dist/npm/types/dispatchFn.js +2 -0
  135. package/dist/npm/types/paste-cleanup-settings.d.ts +1 -3
  136. package/dist/npm/types/paste-cleanup-settings.js +2 -0
  137. package/dist/npm/types/predicate.d.ts +1 -0
  138. package/dist/npm/types/predicate.js +2 -0
  139. package/dist/npm/utils.d.ts +33 -14
  140. package/dist/npm/utils.js +38 -39
  141. package/package.json +3 -50
  142. package/dist/es2015/DOMSerializer.js +0 -184
  143. package/dist/es2015/align.js +0 -43
  144. package/dist/es2015/blockNode.js +0 -180
  145. package/dist/es2015/blockquote.js +0 -26
  146. package/dist/es2015/cleanFormatting.js +0 -20
  147. package/dist/es2015/config/align-rules.js +0 -30
  148. package/dist/es2015/config/commands.js +0 -50
  149. package/dist/es2015/config/constants.js +0 -9
  150. package/dist/es2015/config/indent-rules.js +0 -42
  151. package/dist/es2015/config/keymap.js +0 -51
  152. package/dist/es2015/config/list-settings.js +0 -21
  153. package/dist/es2015/config/schema.js +0 -314
  154. package/dist/es2015/find-replace.js +0 -122
  155. package/dist/es2015/flatten-spans.js +0 -112
  156. package/dist/es2015/image.js +0 -10
  157. package/dist/es2015/indent.js +0 -105
  158. package/dist/es2015/inline-style.js +0 -177
  159. package/dist/es2015/link.js +0 -105
  160. package/dist/es2015/listConvert.js +0 -184
  161. package/dist/es2015/lists.js +0 -266
  162. package/dist/es2015/main.js +0 -44
  163. package/dist/es2015/mark.js +0 -239
  164. package/dist/es2015/node_modules/tslib/tslib.es6.js +0 -35
  165. package/dist/es2015/paste.js +0 -162
  166. package/dist/es2015/plugins/caret-color.js +0 -34
  167. package/dist/es2015/plugins/csp-fix.js +0 -51
  168. package/dist/es2015/plugins/highlight.js +0 -23
  169. package/dist/es2015/plugins/image-resize.js +0 -225
  170. package/dist/es2015/plugins/list-markers-styles.js +0 -104
  171. package/dist/es2015/plugins/placeholder.js +0 -27
  172. package/dist/es2015/plugins/resize-utils.js +0 -13
  173. package/dist/es2015/plugins/spaces-fix.js +0 -46
  174. package/dist/es2015/plugins/table-resize/column-resize.js +0 -267
  175. package/dist/es2015/plugins/table-resize/index.js +0 -12
  176. package/dist/es2015/plugins/table-resize/row-resize.js +0 -234
  177. package/dist/es2015/plugins/table-resize/table-resize.js +0 -278
  178. package/dist/es2015/plugins/table-resize/table-view.js +0 -128
  179. package/dist/es2015/plugins/table-resize/utils.js +0 -93
  180. package/dist/es2015/source.js +0 -251
  181. package/dist/es2015/table.js +0 -132
  182. package/dist/es2015/text.js +0 -5
  183. package/dist/es2015/utils.js +0 -289
@@ -1,278 +0,0 @@
1
- import { Plugin, NodeSelection } from 'prosemirror-state';
2
- import { resizableAttr, dataResizeDirTable, colgroupAttr } from '../../config/constants.js';
3
- import { tableResizeKey, getTable } from './utils.js';
4
- import { parentNode, parseStyle, setNodeStyle } from '../../utils.js';
5
- import { directions } from '../resize-utils.js';
6
-
7
- const commonDir = {
8
- 'southeast': true,
9
- 'southwest': true,
10
- 'northwest': true,
11
- 'northeast': true
12
- };
13
- const horizontalDir = Object.assign({ 'east': true, 'west': true }, commonDir);
14
- const verticalDir = Object.assign({ 'south': true, 'north': true }, commonDir);
15
- class ResizeState {
16
- constructor(activeHandle, dragging, nodePosition) {
17
- this.activeHandle = activeHandle;
18
- this.dragging = dragging;
19
- this.nodePosition = nodePosition;
20
- }
21
- apply(tr) {
22
- const next = tr.getMeta(tableResizeKey);
23
- if (next) {
24
- const nextState = new ResizeState(next.activeHandle, next.setDragging, next.nodePosition);
25
- return nextState;
26
- }
27
- return this;
28
- }
29
- }
30
- const handleMouseMove = (view, event) => {
31
- var _a;
32
- const state = tableResizeKey.getState(view.state);
33
- const { dragging, nodePosition, activeHandle } = state;
34
- if (nodePosition < 0 || !dragging) {
35
- return;
36
- }
37
- const tableDom = getTable(view.nodeDOM(nodePosition));
38
- const rect = tableDom.getBoundingClientRect();
39
- const dir = directions[activeHandle];
40
- const diffX = (event.clientX - dragging.startX) * dir.x;
41
- const diffY = (event.clientY - dragging.startY) * dir.y;
42
- const win = (tableDom.ownerDocument && tableDom.ownerDocument.defaultView) || window;
43
- const compStyles = win.getComputedStyle(tableDom);
44
- const nodeWidth = /px/.test(compStyles.width) ? parseFloat(compStyles.width) : tableDom.offsetWidth;
45
- const nodeHeight = /px/.test(compStyles.height) ? parseFloat(compStyles.height) : tableDom.offsetHeight;
46
- const width = dir.x ? diffX + nodeWidth : rect.width;
47
- const height = dir.y ? diffY + nodeHeight : rect.height;
48
- dragging.startX = dir.x ? event.clientX : dragging.startX;
49
- dragging.startY = dir.y ? event.clientY : dragging.startY;
50
- if (horizontalDir[activeHandle]) {
51
- tableDom.style.width = width + 'px';
52
- }
53
- if (verticalDir[activeHandle]) {
54
- tableDom.style.height = height + 'px';
55
- }
56
- if (/px/.test(tableDom.style.width)) {
57
- const wrapper = (_a = tableDom.parentNode) === null || _a === void 0 ? void 0 : _a.parentNode;
58
- if (wrapper instanceof HTMLDivElement && wrapper.matches('div[table]') && /%/.test(wrapper.style.width)) {
59
- wrapper.style.width = '';
60
- }
61
- }
62
- };
63
- const toPercents = (view, tr, tablePos) => {
64
- const tableNode = view.state.doc.nodeAt(tablePos);
65
- const tableDom = getTable(view.nodeDOM(tablePos));
66
- const { width, height, colsWidth, rowsHeight, offsetWidth, offsetHeight } = tableSize(tableDom);
67
- const colgroup = tableDom.firstChild;
68
- const cols = Array.from((colgroup && colgroup.children) || []);
69
- let widthChanged = false;
70
- cols.forEach((col, i) => {
71
- if (col.style.width && !/%$/.test(col.style.width)) {
72
- col.style.width = ((colsWidth[i]) * 100 / width) + '%';
73
- widthChanged = true;
74
- }
75
- });
76
- let heightChange = false;
77
- tableNode.forEach((row, offset, index) => {
78
- const rowHeight = parseStyle(row.attrs.style).height;
79
- if (rowHeight && !/%$/.test(rowHeight)) {
80
- tr.setNodeMarkup(tablePos + offset + 1, null, setNodeStyle(row.attrs, 'height', (rowsHeight[index] * 100 / height) + '%'));
81
- heightChange = true;
82
- }
83
- });
84
- let tableAttrs = tableNode.attrs;
85
- if (parseStyle(tableAttrs.style).width !== offsetWidth + 'px') {
86
- tableAttrs = setNodeStyle(tableAttrs, 'width', offsetWidth + 'px');
87
- }
88
- if (widthChanged) {
89
- tableAttrs[colgroupAttr] = colgroup.outerHTML;
90
- }
91
- if (heightChange) {
92
- tableAttrs = setNodeStyle(tableAttrs, 'height', offsetHeight + 'px');
93
- }
94
- if (widthChanged || heightChange) {
95
- tr.setNodeMarkup(tablePos, null, tableAttrs);
96
- }
97
- };
98
- const toPixels = (view, tr, tablePos, attrs) => {
99
- const tableNode = view.state.doc.nodeAt(tablePos);
100
- const tableDom = getTable(view.nodeDOM(tablePos));
101
- const win = (tableDom.ownerDocument && tableDom.ownerDocument.defaultView) || window;
102
- const calcStyle = win.getComputedStyle;
103
- const rows = Array.from(tableDom.rows);
104
- tableNode.forEach((row, offset, index) => {
105
- const rowHeight = parseStyle(row.attrs.style).height;
106
- if (rowHeight && !/px$/.test(rowHeight)) {
107
- tr.setNodeMarkup(tablePos + offset + 1, null, setNodeStyle(row.attrs, 'height', calcStyle(rows[index]).height));
108
- }
109
- });
110
- const colgroup = tableDom.firstChild;
111
- const cols = Array.from((colgroup && colgroup.children) || []);
112
- let widthChanged = false;
113
- cols.forEach((col, i) => {
114
- if (col.style.width && !/px$/.test(col.style.width)) {
115
- col.style.width = calcStyle(cols[i]).width;
116
- widthChanged = true;
117
- }
118
- });
119
- const tableAttrs = Object.assign({}, attrs);
120
- if (widthChanged) {
121
- tableAttrs[colgroupAttr] = colgroup.outerHTML;
122
- }
123
- return tableAttrs;
124
- };
125
- const tableSize = (table) => {
126
- const cols = Array.from(table.firstChild.children);
127
- const colsWidth = cols.map(c => c.offsetWidth);
128
- const rowsHeight = Array.from(table.rows).map(row => row.offsetHeight);
129
- const width = colsWidth.reduce((acc, cur) => acc + cur, 0);
130
- const height = rowsHeight.reduce((acc, cur) => acc + cur, 0);
131
- const offsetHeight = table.offsetHeight;
132
- const offsetWidth = table.offsetWidth;
133
- return { width, height, colsWidth, rowsHeight, offsetWidth, offsetHeight };
134
- };
135
- const handleMouseUp = (view) => {
136
- const { dragging, nodePosition, activeHandle } = tableResizeKey.getState(view.state);
137
- if (dragging) {
138
- const node = view.state.doc.nodeAt(nodePosition);
139
- const dom = getTable(view.nodeDOM(nodePosition));
140
- const rect = tableSize(dom);
141
- if (node) {
142
- const width = rect.offsetWidth + 'px';
143
- const height = rect.offsetHeight + 'px';
144
- const tr = view.state.tr;
145
- let attrs = node.attrs;
146
- const parsedStyles = parseStyle(attrs.style);
147
- if (horizontalDir[activeHandle] && dom.style.width && parsedStyles.width !== width) {
148
- attrs = setNodeStyle(attrs, 'width', width);
149
- }
150
- if (verticalDir[activeHandle] && dom.style.height && parsedStyles.height !== height) {
151
- attrs = setNodeStyle(attrs, 'height', height);
152
- }
153
- attrs = toPixels(view, tr, nodePosition, attrs);
154
- tr.setNodeMarkup(nodePosition, null, attrs);
155
- tr.setMeta('commandName', 'node-resize');
156
- tr.setMeta('args', attrs);
157
- tr.setMeta(tableResizeKey, {
158
- setDragging: null,
159
- activeHandle: null,
160
- nodePosition
161
- });
162
- if (!/%/.test(parseStyle(attrs.style).width || '')) {
163
- const $pos = tr.doc.resolve(nodePosition);
164
- const wrapper = parentNode($pos, n => n.type.name === 'table_wrapper');
165
- if (wrapper && /%/.test(parseStyle(wrapper.node.attrs.style).width || '')) {
166
- const wrapperAttrs = setNodeStyle(wrapper.node.attrs, 'width', '');
167
- const wrapperPos = $pos.start(wrapper.depth) - 1;
168
- tr.setNodeMarkup(wrapperPos, null, wrapperAttrs);
169
- }
170
- }
171
- view.dispatch(tr);
172
- }
173
- }
174
- };
175
- const handleMouseDown = (view, event) => {
176
- const target = event.target;
177
- const activeHandle = target.getAttribute(dataResizeDirTable);
178
- if (!activeHandle) {
179
- return false;
180
- }
181
- const resizeState = tableResizeKey.getState(view.state);
182
- event.preventDefault();
183
- const transaction = view.state.tr;
184
- transaction.setMeta(tableResizeKey, {
185
- setDragging: { startX: event.clientX, startY: event.clientY },
186
- activeHandle,
187
- nodePosition: resizeState.nodePosition
188
- });
189
- transaction.setMeta('addToHistory', false);
190
- toPercents(view, transaction, resizeState.nodePosition);
191
- view.dispatch(transaction);
192
- const curWindow = event.view || window;
193
- function move(e) {
194
- handleMouseMove(view, e);
195
- }
196
- function finish() {
197
- curWindow.removeEventListener('mouseup', finish);
198
- curWindow.removeEventListener('mousemove', move);
199
- handleMouseUp(view);
200
- }
201
- curWindow.addEventListener('mouseup', finish);
202
- curWindow.addEventListener('mousemove', move);
203
- return true;
204
- };
205
- const tableResizing = (options = { node: 'table' }) => {
206
- return new Plugin({
207
- key: tableResizeKey,
208
- view: () => ({
209
- selectedNode(state, nodeType) {
210
- const selection = state.selection;
211
- const isNodeSelected = selection instanceof NodeSelection && nodeType === selection.node.type;
212
- if (isNodeSelected && selection instanceof NodeSelection) {
213
- return { node: selection.node, pos: selection.from };
214
- }
215
- const parent = parentNode(selection.$from, (n) => n.type === nodeType);
216
- const node = parent && parent.node;
217
- if (node) {
218
- const pos = selection.$from.start(parent.depth) - 1;
219
- return { node, pos };
220
- }
221
- return null;
222
- },
223
- update(view, prevState) {
224
- const state = view.state;
225
- const nodeType = state.schema.nodes[options.node];
226
- const selected = this.selectedNode(state, nodeType);
227
- const prevSelected = this.selectedNode(prevState, nodeType);
228
- if (!selected && prevSelected && !prevState.doc.eq(view.state.doc)) {
229
- // selected table is deleted
230
- return;
231
- }
232
- if (selected || prevSelected) {
233
- const tr = state.tr;
234
- tr.setMeta('addToHistory', false);
235
- if (selected && prevSelected && selected.pos !== prevSelected.pos) {
236
- tr.setMeta(tableResizeKey, { nodePosition: selected.pos });
237
- const prevNode = tr.doc.nodeAt(prevSelected.pos);
238
- if (prevNode && prevNode.type.name === nodeType.name) {
239
- tr.setNodeMarkup(prevSelected.pos, nodeType, Object.assign(Object.assign({}, prevSelected.node.attrs), { [resizableAttr]: false }));
240
- }
241
- tr.setNodeMarkup(selected.pos, nodeType, Object.assign(Object.assign({}, selected.node.attrs), { [resizableAttr]: true }));
242
- view.dispatch(tr);
243
- }
244
- else if (selected && prevSelected && selected.pos === prevSelected.pos &&
245
- !selected.node.attrs[resizableAttr] && !state.selection.eq(prevState.selection)) {
246
- tr.setMeta(tableResizeKey, { nodePosition: selected.pos });
247
- view.dispatch(tr.setNodeMarkup(selected.pos, nodeType, Object.assign(Object.assign({}, selected.node.attrs), { [resizableAttr]: true })));
248
- }
249
- else if (selected && !prevSelected) {
250
- tr.setMeta(tableResizeKey, { nodePosition: selected.pos });
251
- view.dispatch(tr.setNodeMarkup(selected.pos, nodeType, Object.assign(Object.assign({}, selected.node.attrs), { [resizableAttr]: true })));
252
- }
253
- else if (!selected && prevSelected) {
254
- tr.setMeta(tableResizeKey, { nodePosition: -1 });
255
- view.dispatch(tr.setNodeMarkup(prevSelected.pos, nodeType, Object.assign(Object.assign({}, prevSelected.node.attrs), { [resizableAttr]: false })));
256
- }
257
- }
258
- }
259
- }),
260
- state: {
261
- init() {
262
- return new ResizeState('', null, -1);
263
- },
264
- apply(tr, prev) {
265
- return prev.apply(tr);
266
- }
267
- },
268
- props: {
269
- handleDOMEvents: {
270
- mousedown(view, event) {
271
- return handleMouseDown(view, event);
272
- }
273
- }
274
- }
275
- });
276
- };
277
-
278
- export { tableResizing };
@@ -1,128 +0,0 @@
1
- import { resizableWrap, colgroupAttr, resizeHandle, dataResizeDirTable, resizableAttr } from '../../config/constants.js';
2
- import { parseStrColgroup } from '../../config/schema.js';
3
- import { handles } from '../resize-utils.js';
4
- import { setAttribute, parseStyle } from '../../utils.js';
5
-
6
- class TableView {
7
- constructor(node, view) {
8
- this.node = node;
9
- this.view = view;
10
- this.dom = document.createElement('div');
11
- this.dom.className = resizableWrap;
12
- this.table = this.dom.appendChild(document.createElement('table'));
13
- if (node.attrs[colgroupAttr]) {
14
- this.renderColgroup(node.attrs[colgroupAttr]);
15
- }
16
- const tBody = this.table.appendChild(document.createElement('tbody'));
17
- this.setAttributes(this.table, node.attrs);
18
- this.resizeHandles = handles.map(dir => {
19
- const handle = document.createElement('span');
20
- handle.className = resizeHandle + ' ' + dir;
21
- handle.setAttribute(dataResizeDirTable, dir);
22
- return handle;
23
- });
24
- this.contentDOM = tBody;
25
- }
26
- update(node) {
27
- if (node.type !== this.node.type) {
28
- return false;
29
- }
30
- const prev = this.node;
31
- this.node = node;
32
- if (node.attrs[resizableAttr]) {
33
- this.resizeHandles.forEach(handle => {
34
- this.dom.appendChild(handle);
35
- });
36
- }
37
- else {
38
- Array.from(this.dom.children)
39
- .filter((e) => e.classList.contains(resizeHandle))
40
- .forEach((e) => e.remove());
41
- }
42
- this.setAttributes(this.table, node.attrs);
43
- if (prev.attrs[colgroupAttr] !== node.attrs[colgroupAttr]) {
44
- this.renderColgroup(node.attrs[colgroupAttr]);
45
- }
46
- return true;
47
- }
48
- ignoreMutation(record) {
49
- const result = record.type === 'attributes' &&
50
- (record.target === this.table ||
51
- record.target.firstChild === this.table ||
52
- (this.colgroup && this.colgroup.contains(record.target)));
53
- return result;
54
- }
55
- destroy() {
56
- this.node = undefined;
57
- this.view = undefined;
58
- this.table = undefined;
59
- this.colgroup = undefined;
60
- this.resizeHandles = undefined;
61
- }
62
- renderColgroup(colgroupStr) {
63
- if (this.table && this.table.firstChild && this.table.firstChild.nodeName === 'COLGROUP') {
64
- this.table.removeChild(this.table.firstChild);
65
- }
66
- if (colgroupStr) {
67
- this.colgroup = parseStrColgroup(colgroupStr);
68
- this.table.insertBefore(this.colgroup, this.table.firstChild);
69
- }
70
- }
71
- setAttributes(table, attrs) {
72
- const skip = [colgroupAttr, resizableAttr];
73
- for (const attrName in attrs) {
74
- if (attrName && skip.indexOf(attrName) === -1) {
75
- setAttribute(table, attrName, attrs[attrName]);
76
- }
77
- }
78
- if (/%$/.test(table.style.width)) {
79
- this.dom.style.width = table.style.width;
80
- table.style.width = '';
81
- }
82
- else {
83
- this.dom.style.width = '';
84
- }
85
- }
86
- }
87
- class TableWrapperView {
88
- constructor(node, view) {
89
- this.node = node;
90
- this.view = view;
91
- this.dom = document.createElement('div');
92
- this.setAttributes(this.dom, node.attrs);
93
- this.contentDOM = this.dom;
94
- }
95
- update(node) {
96
- if (node.type !== this.node.type) {
97
- return false;
98
- }
99
- this.node = node;
100
- this.setAttributes(this.dom, node.attrs);
101
- return true;
102
- }
103
- ignoreMutation(record) {
104
- return record.type === 'attributes' && record.attributeName === 'style';
105
- }
106
- destroy() {
107
- this.node = undefined;
108
- this.view = undefined;
109
- }
110
- setAttributes(dom, attrs) {
111
- for (const attrName in attrs) {
112
- if (attrName) {
113
- setAttribute(dom, attrName, attrs[attrName]);
114
- }
115
- }
116
- dom.setAttribute('table', '');
117
- if (/%/.test(dom.style.width)) {
118
- const table = this.node && this.node.lastChild;
119
- const tableStyles = table ? parseStyle(table.attrs.style) : {};
120
- const tableWidth = tableStyles.width || '';
121
- if (tableWidth && !/%/.test(tableWidth)) {
122
- dom.style.width = '';
123
- }
124
- }
125
- }
126
- }
127
-
128
- export { TableView, TableWrapperView };
@@ -1,93 +0,0 @@
1
- import { PluginKey } from 'prosemirror-state';
2
- import { TableMap } from 'prosemirror-tables';
3
- import { parentNode } from '../../utils.js';
4
-
5
- const tableResizeKey = new PluginKey('table-resize');
6
- const tableColumnResizeKey = new PluginKey('table-column-resizing');
7
- const tableRowResizeKey = new PluginKey('table-row-resizing');
8
- function otherResizing(current, state) {
9
- let activeResize = false;
10
- activeResize = activeResize ||
11
- (current !== tableResizeKey && Boolean(tableResizeKey.get(state)) && tableResizeKey.getState(state).dragging);
12
- activeResize = activeResize ||
13
- (current !== tableColumnResizeKey && Boolean(tableColumnResizeKey.get(state)) && tableColumnResizeKey.getState(state).dragging);
14
- activeResize = activeResize ||
15
- (current !== tableRowResizeKey && Boolean(tableRowResizeKey.get(state)) && tableRowResizeKey.getState(state).dragging);
16
- return activeResize;
17
- }
18
- function otherResizeHandle(current, state) {
19
- let activeResize = false;
20
- activeResize = activeResize ||
21
- (current !== tableColumnResizeKey &&
22
- Boolean(tableColumnResizeKey.get(state)) &&
23
- tableColumnResizeKey.getState(state).activeHandle > -1);
24
- activeResize = activeResize ||
25
- (current !== tableRowResizeKey && Boolean(tableRowResizeKey.get(state)) && tableRowResizeKey.getState(state).activeHandle > -1);
26
- return activeResize;
27
- }
28
- function getTable(dom) {
29
- if (dom && dom.firstChild && dom.firstChild.nodeName === 'TABLE') {
30
- return dom.firstChild;
31
- }
32
- return dom;
33
- }
34
- function domCellAround(target) {
35
- while (target && target.nodeName !== 'TD' && target.nodeName !== 'TH') {
36
- target = target.classList.contains('ProseMirror') ? null : target.parentNode;
37
- }
38
- return target;
39
- }
40
- function tableSpansMap(table) {
41
- const rows = Array.from((table && table.rows) || []);
42
- const colsCount = Array.from((rows && rows[0] && rows[0].cells) || [])
43
- .map(c => c.colSpan)
44
- .reduce((prev, cur) => prev + cur, 0);
45
- const map = rows.map(() => new Array(colsCount));
46
- rows.forEach((row, r) => {
47
- let curColSpan = 0;
48
- Array.from(row.cells).forEach((c) => {
49
- for (let colSp = 0; colSp < c.colSpan; colSp++) {
50
- for (let rowSp = 0; rowSp < c.rowSpan; rowSp++) {
51
- const ind = map[r + rowSp].findIndex((val, curInd) => curInd >= curColSpan && !val);
52
- map[r + rowSp][ind] = c;
53
- }
54
- curColSpan++;
55
- }
56
- });
57
- });
58
- return map;
59
- }
60
- function cellIndexes(dataCell) {
61
- const map = tableSpansMap(dataCell.closest('table'));
62
- let result = null;
63
- for (let r = 0; r < map.length; r++) {
64
- const row = map[r];
65
- row.forEach((cell, c) => {
66
- if (dataCell === cell) {
67
- result = { rowIndex: r, cellIndex: c };
68
- }
69
- });
70
- if (result) {
71
- break;
72
- }
73
- }
74
- return result || { rowIndex: -1, cellIndex: -1 };
75
- }
76
- function edgeCell(view, event, indexes) {
77
- const found = view.posAtCoords({ left: event.clientX, top: event.clientY });
78
- if (!found) {
79
- return -1;
80
- }
81
- const $pos = view.state.doc.resolve(found.pos);
82
- const parentTable = parentNode($pos, n => n.type.spec.tableRole === 'table');
83
- if (parentTable === null) {
84
- return -1;
85
- }
86
- const tablePos = $pos.start(parentTable.depth);
87
- const tableNode = parentTable.node;
88
- const map = TableMap.get(tableNode);
89
- const cell = tablePos + map.map[(map.width * indexes.rowIndex) + indexes.cellIndex];
90
- return cell;
91
- }
92
-
93
- export { cellIndexes, domCellAround, edgeCell, getTable, otherResizeHandle, otherResizing, tableColumnResizeKey, tableResizeKey, tableRowResizeKey };