@progress/kendo-editor-common 1.12.2-develop.5 → 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,46 +0,0 @@
1
- import { Plugin, PluginKey } from 'prosemirror-state';
2
- import { Decoration, DecorationSet } from 'prosemirror-view';
3
-
4
- // The plugin resolves the following problems:
5
- //
6
- // 1. white-space: pre-wrap does not work with text-align: justify in firefox
7
- // https://bugzilla.mozilla.org/show_bug.cgi?id=1253840
8
- // https://bugzilla.mozilla.org/show_bug.cgi?id=299721
9
- // 2. Align right in pre-wrap doesn't give the expected outcome,
10
- // as in pre-wrap it will preserve the white-space when the text breaks based on the container width.
11
- // Additional info here:
12
- // https://github.com/ProseMirror/prosemirror/issues/651
13
- // https://github.com/ProseMirror/prosemirror/issues/857
14
- const spaces = /\s+/g;
15
- const align = /text-align/;
16
- const aligned = (node) => align.test((node && node.attrs && node.attrs.style) || '');
17
- const spacesFix = () => new Plugin({
18
- key: new PluginKey('spaces-fix'),
19
- props: {
20
- decorations: (state) => {
21
- const decorations = [];
22
- const doc = state.doc;
23
- let start, match, length, i;
24
- doc.nodesBetween(0, doc.content.size, (node, position, parent) => {
25
- if (node.type.isText && aligned(parent)) {
26
- match = spaces.exec(node.text || '');
27
- while (match !== null) {
28
- start = position + match.index;
29
- length = match[0].length;
30
- if (match.index + length < match.input.length) {
31
- for (i = 0; i <= length - 1; i += 2) {
32
- decorations.push(Decoration.inline(start + i, start + i + 1, {
33
- style: 'white-space: normal'
34
- }));
35
- }
36
- }
37
- match = spaces.exec(node.text || '');
38
- }
39
- }
40
- });
41
- return DecorationSet.create(doc, decorations);
42
- }
43
- }
44
- });
45
-
46
- export { spacesFix };
@@ -1,267 +0,0 @@
1
- import { Plugin } from 'prosemirror-state';
2
- import { TableMap } from 'prosemirror-tables';
3
- import { DecorationSet, Decoration } from 'prosemirror-view';
4
- import { colgroupAttr } from '../../config/constants.js';
5
- import { TableView, TableWrapperView } from './table-view.js';
6
- import { setNodeStyle, parseStyle } from '../../utils.js';
7
- import { tableColumnResizeKey, otherResizing, otherResizeHandle, domCellAround, cellIndexes, edgeCell } from './utils.js';
8
-
9
- function columnResizing() {
10
- const handleWidth = 5, cellMinWidth = 25;
11
- const plugin = new Plugin({
12
- key: tableColumnResizeKey,
13
- state: {
14
- init() {
15
- return new ResizeState(-1, null);
16
- },
17
- apply(tr, prev) {
18
- return prev.apply(tr);
19
- }
20
- },
21
- props: {
22
- attributes(state) {
23
- if (otherResizeHandle(tableColumnResizeKey, state)) {
24
- return null;
25
- }
26
- const pluginState = tableColumnResizeKey.getState(state);
27
- return pluginState.activeHandle > -1 ? { class: 'resize-cursor' } : null;
28
- },
29
- handleDOMEvents: {
30
- mousemove(view, event) {
31
- if (!otherResizing(tableColumnResizeKey, view.state)) {
32
- handleMouseMove(view, event, handleWidth);
33
- }
34
- return false;
35
- },
36
- mouseleave(view) {
37
- handleMouseLeave(view);
38
- return false;
39
- },
40
- mousedown(view, event) {
41
- return handleMouseDown(view, event, cellMinWidth);
42
- }
43
- },
44
- decorations(state) {
45
- if (!otherResizing(tableColumnResizeKey, state)) {
46
- const pluginState = tableColumnResizeKey.getState(state);
47
- if (pluginState.activeHandle > -1) {
48
- return handleDecorations(state, pluginState.activeHandle);
49
- }
50
- }
51
- return DecorationSet.empty;
52
- },
53
- nodeViews: {
54
- table_wrapper: (node, view) => new TableWrapperView(node, view),
55
- table: (node, view) => new TableView(node, view)
56
- }
57
- }
58
- });
59
- return plugin;
60
- }
61
- function pointsAtCell($pos) {
62
- return Boolean($pos.parent.type.spec.tableRole === 'row' && $pos.nodeAfter);
63
- }
64
- class ResizeState {
65
- constructor(activeHandle, dragging) {
66
- this.activeHandle = activeHandle;
67
- this.dragging = dragging;
68
- }
69
- apply(tr) {
70
- let state;
71
- const action = tr.getMeta(tableColumnResizeKey);
72
- if (action && action.setHandle != null) {
73
- return new ResizeState(action.setHandle, null);
74
- }
75
- if (action && action.setDragging !== undefined) {
76
- return new ResizeState(this.activeHandle, action.setDragging);
77
- }
78
- if (this.activeHandle > -1 && tr.docChanged) {
79
- let handle = tr.mapping.map(this.activeHandle, -1);
80
- if (!pointsAtCell(tr.doc.resolve(handle))) {
81
- handle = -1;
82
- }
83
- state = new ResizeState(handle, this.dragging);
84
- }
85
- return state || this;
86
- }
87
- }
88
- function handleMouseMove(view, event, handleWidth) {
89
- const pluginState = tableColumnResizeKey.getState(view.state);
90
- if (!pluginState.dragging) {
91
- const target = domCellAround(event.target);
92
- let cell = -1;
93
- if (target) {
94
- const indexes = cellIndexes(target);
95
- const { left, right } = target.getBoundingClientRect();
96
- if (Math.abs(event.clientX - left) <= handleWidth && indexes.cellIndex > 0) {
97
- indexes.cellIndex -= target.colSpan;
98
- cell = edgeCell(view, event, indexes);
99
- }
100
- else if (right - event.clientX > 0 && right - event.clientX <= handleWidth) {
101
- cell = edgeCell(view, event, indexes);
102
- }
103
- }
104
- if (cell !== pluginState.activeHandle) {
105
- updateHandle(view, cell);
106
- }
107
- }
108
- }
109
- function handleMouseLeave(view) {
110
- const pluginState = tableColumnResizeKey.getState(view.state);
111
- if (pluginState.activeHandle > -1 && !pluginState.dragging) {
112
- updateHandle(view, -1);
113
- }
114
- }
115
- function handleMouseDown(view, event, cellMinWidth) {
116
- const pluginState = tableColumnResizeKey.getState(view.state);
117
- if (pluginState.activeHandle === -1 || pluginState.dragging) {
118
- return false;
119
- }
120
- const $cell = view.state.doc.resolve(pluginState.activeHandle);
121
- const row = $cell.parent;
122
- const cellIndex = $cell.index();
123
- let colSpan = 0;
124
- for (let i = 0; i <= cellIndex; i++) {
125
- colSpan += row.child(i).attrs.colspan;
126
- }
127
- const tableNode = $cell.node($cell.depth - 1);
128
- const dom = view.domAtPos(pluginState.activeHandle);
129
- const domCell = dom.node.childNodes[dom.offset];
130
- const tableDom = domCell.closest('table');
131
- let col, tableAttrs;
132
- if (tableNode.attrs[colgroupAttr]) {
133
- const colgroup = tableDom.firstChild;
134
- col = colgroup.children[colSpan - 1];
135
- if (!col.style.width) {
136
- col.style.width = col.offsetWidth + 'px';
137
- }
138
- }
139
- else {
140
- let total = 0;
141
- for (let i = 0; i < row.childCount; i++) {
142
- total += row.child(i).attrs.colspan;
143
- }
144
- const colgroup = document.createElement('colgroup');
145
- const cols = new Array(total);
146
- for (let i = 0; i < total; i++) {
147
- cols[i] = document.createElement('col');
148
- colgroup.appendChild(cols[i]);
149
- }
150
- tableDom.insertBefore(colgroup, tableDom.firstChild);
151
- col = cols[cellIndex];
152
- col.style.width = col.offsetWidth + 'px';
153
- tableAttrs = Object.assign(Object.assign({}, tableNode.attrs), { [colgroupAttr]: '<colgroup>' + cols.reduce((acc, cur) => acc + cur.outerHTML, '') + '</colgroup>' });
154
- }
155
- const width = parseFloat(col.style.width);
156
- const tr = view.state.tr.setMeta(tableColumnResizeKey, { setDragging: { startX: event.clientX, startWidth: width } });
157
- if (!tableDom.style.width) {
158
- const widths = Array.from(col.parentNode.children).map((c) => c.style.width);
159
- if (widths.every(Boolean)) {
160
- const sum = widths.reduce((acc, cur) => acc + parseFloat(cur), 0);
161
- tableAttrs = setNodeStyle(tableAttrs || tableNode.attrs, 'width', sum + 'px');
162
- }
163
- }
164
- if (tableAttrs) {
165
- const tablePos = $cell.posAtIndex(0, $cell.depth - 1) - 1;
166
- tr.setNodeMarkup(tablePos, null, tableAttrs);
167
- }
168
- view.dispatch(tr);
169
- function finish(ev) {
170
- ev.view.removeEventListener('mouseup', finish);
171
- ev.view.removeEventListener('mousemove', move);
172
- const curPluginState = tableColumnResizeKey.getState(view.state);
173
- if (curPluginState.dragging) {
174
- const transaction = view.state.tr;
175
- updateColumnWidth(view, transaction, curPluginState.activeHandle);
176
- view.dispatch(transaction.setMeta(tableColumnResizeKey, { setDragging: null }));
177
- }
178
- }
179
- function move(ev) {
180
- if (!ev.which) {
181
- return finish(ev);
182
- }
183
- const curPluginState = tableColumnResizeKey.getState(view.state);
184
- const dragged = draggedWidth(curPluginState.dragging, ev, cellMinWidth);
185
- displayColumnWidth(view, curPluginState.activeHandle, dragged);
186
- }
187
- event.view.addEventListener('mouseup', finish);
188
- event.view.addEventListener('mousemove', move);
189
- event.preventDefault();
190
- return true;
191
- }
192
- function draggedWidth(dragging, event, cellMinWidth) {
193
- const offset = event.clientX - dragging.startX;
194
- return Math.max(cellMinWidth, dragging.startWidth + offset);
195
- }
196
- function updateHandle(view, value) {
197
- const tr = view.state.tr;
198
- tr.setMeta('addToHistory', false);
199
- tr.setMeta(tableColumnResizeKey, { setHandle: value });
200
- view.dispatch(tr);
201
- }
202
- function updateColumnWidth(view, tr, cell) {
203
- const $cell = view.state.doc.resolve(cell);
204
- const tableNode = $cell.node(-1), start = $cell.start(-1);
205
- const tablePos = $cell.posAtIndex(0, $cell.depth - 1) - 1;
206
- const tableDom = view.nodeDOM(start).closest('table');
207
- let attrs = tableNode.attrs;
208
- if (tableNode && attrs[colgroupAttr]) {
209
- const colgroup = tableDom.firstChild;
210
- attrs = Object.assign(Object.assign({}, attrs), { [colgroupAttr]: colgroup.outerHTML });
211
- }
212
- const tableDomWidth = tableDom.style.width;
213
- if (tableDom && tableDomWidth && parseStyle(attrs.style).width !== tableDomWidth) {
214
- attrs = setNodeStyle(attrs, 'width', tableDomWidth);
215
- }
216
- tr.setNodeMarkup(tablePos, null, attrs);
217
- }
218
- function displayColumnWidth(view, cell, width) {
219
- const $cell = view.state.doc.resolve(cell);
220
- const table = $cell.node(-1), start = $cell.start(-1);
221
- const col = TableMap.get(table).colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;
222
- let dom = view.domAtPos($cell.start(-1)).node;
223
- if (dom.nodeName !== 'TABLE') {
224
- dom = dom.closest('table');
225
- }
226
- const tableDom = dom;
227
- const colgroup = tableDom.firstChild;
228
- const cols = Array.from(colgroup.children);
229
- cols[col].style.width = width + 'px';
230
- if (tableDom.style.width) {
231
- const widths = cols.map(c => c.style.width);
232
- if (widths.every(Boolean)) {
233
- const sum = widths.reduce((acc, cur) => acc + parseFloat(cur), 0);
234
- tableDom.style.width = sum + 'px';
235
- }
236
- }
237
- }
238
- function handleDecorations(state, cell) {
239
- const decorations = [];
240
- const $cell = state.doc.resolve(cell);
241
- const table = $cell.node(-1), map = TableMap.get(table), start = $cell.start(-1);
242
- const cellsPositions = [];
243
- const cellPos = cell - start;
244
- let column = -1;
245
- for (let i = 0; i < map.height; i++) {
246
- cellsPositions.push(map.map.slice(i * map.width, (i * map.width) + map.width));
247
- if (column === -1) {
248
- column = cellsPositions[i].lastIndexOf(cellPos);
249
- }
250
- }
251
- const cells = [];
252
- cellsPositions.forEach((row) => {
253
- const c = row[column];
254
- if (row[column] !== row[column + 1]) {
255
- cells.push(c);
256
- }
257
- });
258
- cells.forEach((cPos => {
259
- const pos = start + cPos + table.nodeAt(cPos).nodeSize - 1;
260
- const dom = document.createElement('div');
261
- dom.className = 'column-resize-handle';
262
- decorations.push(Decoration.widget(pos, dom));
263
- }));
264
- return DecorationSet.create(state.doc, decorations);
265
- }
266
-
267
- export { columnResizing };
@@ -1,12 +0,0 @@
1
- import { columnResizing } from './column-resize.js';
2
- import { tableResizing as tableResizing$1 } from './table-resize.js';
3
- import { rowResizing } from './row-resize.js';
4
- export { tableColumnResizeKey, tableResizeKey, tableRowResizeKey } from './utils.js';
5
-
6
- const tableResizing = () => [
7
- tableResizing$1(),
8
- columnResizing(),
9
- rowResizing()
10
- ];
11
-
12
- export { tableResizing };
@@ -1,234 +0,0 @@
1
- import { Plugin } from 'prosemirror-state';
2
- import { tableNodeTypes, TableMap } from 'prosemirror-tables';
3
- import { DecorationSet, Decoration } from 'prosemirror-view';
4
- import { tableRowResizeKey, otherResizing, otherResizeHandle, domCellAround, cellIndexes, edgeCell } from './utils.js';
5
- import { parseStyle, setNodeStyle } from '../../utils.js';
6
-
7
- class TableRowView {
8
- ignoreMutation(record) {
9
- return record.type === 'attributes' && record.attributeName === 'style' && record.target.nodeName === 'TR';
10
- }
11
- }
12
- function rowResizing() {
13
- const handleWidth = 5;
14
- const plugin = new Plugin({
15
- key: tableRowResizeKey,
16
- state: {
17
- init(_, state) {
18
- this.spec.props.nodeViews[tableNodeTypes(state.schema).row.name] = () => new TableRowView();
19
- return new ResizeState(-1, null);
20
- },
21
- apply(tr, prev) {
22
- return prev.apply(tr);
23
- }
24
- },
25
- props: {
26
- attributes(state) {
27
- if (otherResizeHandle(tableRowResizeKey, state)) {
28
- return null;
29
- }
30
- const pluginState = tableRowResizeKey.getState(state);
31
- return pluginState.activeHandle > -1 ? { class: 'resize-cursor-vertical' } : null;
32
- },
33
- handleDOMEvents: {
34
- mousemove(view, event) {
35
- if (!otherResizing(tableRowResizeKey, view.state)) {
36
- handleMouseMove(view, event, handleWidth);
37
- }
38
- return false;
39
- },
40
- mouseleave(view) {
41
- handleMouseLeave(view);
42
- return false;
43
- },
44
- mousedown(view, event) {
45
- return handleMouseDown(view, event);
46
- }
47
- },
48
- decorations(state) {
49
- if (otherResizing(tableRowResizeKey, state)) {
50
- return DecorationSet.empty;
51
- }
52
- const pluginState = tableRowResizeKey.getState(state);
53
- if (pluginState.activeHandle > -1) {
54
- return handleDecorations(state, pluginState.activeHandle);
55
- }
56
- },
57
- nodeViews: {}
58
- }
59
- });
60
- return plugin;
61
- }
62
- function pointsAtCell($pos) {
63
- return $pos.parent.type.spec.tableRole === 'row' && $pos.nodeAfter;
64
- }
65
- class ResizeState {
66
- constructor(activeHandle, dragging) {
67
- this.activeHandle = activeHandle;
68
- this.dragging = dragging;
69
- }
70
- apply(tr) {
71
- let state, action = tr.getMeta(tableRowResizeKey);
72
- if (action && action.setHandle != null) {
73
- return new ResizeState(action.setHandle, null);
74
- }
75
- if (action && action.setDragging !== undefined) {
76
- return new ResizeState(this.activeHandle, action.setDragging);
77
- }
78
- if (this.activeHandle > -1) {
79
- let handle = tr.mapping.map(this.activeHandle, -1);
80
- if (!pointsAtCell(tr.doc.resolve(handle))) {
81
- handle = null;
82
- }
83
- state = new ResizeState(handle, this.dragging);
84
- }
85
- return state || this;
86
- }
87
- }
88
- function handleMouseMove(view, event, handleWidth) {
89
- const pluginState = tableRowResizeKey.getState(view.state);
90
- if (!pluginState.dragging) {
91
- let target = domCellAround(event.target), cell = -1;
92
- if (target) {
93
- const indexes = cellIndexes(target);
94
- const { top, bottom } = target.getBoundingClientRect();
95
- if (Math.abs(event.clientY - top) <= handleWidth && indexes.rowIndex > 0) {
96
- indexes.rowIndex -= target.rowSpan;
97
- cell = edgeCell(view, event, indexes);
98
- }
99
- else if (bottom - event.clientY > 0 && bottom - event.clientY <= handleWidth) {
100
- cell = edgeCell(view, event, indexes);
101
- }
102
- }
103
- if (cell !== pluginState.activeHandle) {
104
- updateHandle(view, cell);
105
- }
106
- }
107
- }
108
- function handleMouseLeave(view) {
109
- const pluginState = tableRowResizeKey.getState(view.state);
110
- if (pluginState.activeHandle > -1 && !pluginState.dragging) {
111
- updateHandle(view, -1);
112
- }
113
- }
114
- function handleMouseDown(view, event) {
115
- const pluginState = tableRowResizeKey.getState(view.state);
116
- if (pluginState.activeHandle === -1 || pluginState.dragging) {
117
- return false;
118
- }
119
- const doc = view.state.doc;
120
- const $cell = doc.resolve(pluginState.activeHandle);
121
- const row = $cell.parent;
122
- const table = $cell.node(-1);
123
- const rowHeightStr = parseStyle(row.attrs.style).height;
124
- const tableHeight = parseStyle(table.attrs.style).height;
125
- let rowHeight = rowHeightStr ? parseFloat(rowHeightStr) : 0;
126
- if (!rowHeightStr) {
127
- const tr = view.nodeDOM(pluginState.activeHandle);
128
- rowHeight = tr.offsetHeight;
129
- }
130
- view.dispatch(view.state.tr.setMeta(tableRowResizeKey, {
131
- setDragging: {
132
- startY: event.clientY,
133
- startHeight: { rowHeight, tableHeight }
134
- }
135
- }));
136
- function finish(ev) {
137
- ev.view.removeEventListener('mouseup', finish);
138
- ev.view.removeEventListener('mousemove', move);
139
- const curPluginState = tableRowResizeKey.getState(view.state);
140
- if (curPluginState.dragging) {
141
- const tr = view.state.tr.setMeta(tableRowResizeKey, { setDragging: null });
142
- updateRowHeight(view, tr, curPluginState.activeHandle);
143
- view.dispatch(tr);
144
- }
145
- }
146
- function move(ev) {
147
- if (!ev.which) {
148
- return finish(ev);
149
- }
150
- const curPluginState = tableRowResizeKey.getState(view.state);
151
- const dragged = draggedHeight(curPluginState.dragging, ev);
152
- const offset = ev.clientY - curPluginState.dragging.startY;
153
- displayRowHeight(view, curPluginState.activeHandle, dragged, offset, tableHeight);
154
- }
155
- event.view.addEventListener('mouseup', finish);
156
- event.view.addEventListener('mousemove', move);
157
- event.preventDefault();
158
- return true;
159
- }
160
- function draggedHeight(dragging, event) {
161
- const offset = event.clientY - dragging.startY;
162
- return dragging.startHeight.rowHeight + offset;
163
- }
164
- function updateHandle(view, value) {
165
- const tr = view.state.tr;
166
- tr.setMeta('addToHistory', false);
167
- tr.setMeta(tableRowResizeKey, { setHandle: value });
168
- view.dispatch(tr);
169
- }
170
- function updateRowHeight(view, tr, cellPos) {
171
- const doc = view.state.doc;
172
- const $cell = doc.resolve(cellPos);
173
- const row = $cell.parent;
174
- const rowPos = $cell.posAtIndex(0) - 1;
175
- const dom = view.nodeDOM(rowPos);
176
- const win = (dom.ownerDocument && dom.ownerDocument.defaultView) || window;
177
- dom.style.height = win.getComputedStyle(dom).height;
178
- tr.setNodeMarkup(rowPos, null, setNodeStyle(row.attrs, 'height', dom.style.height));
179
- const table = dom && dom.closest('table');
180
- const tableHeight = table && table.style.height;
181
- if (tableHeight) {
182
- const $pos = doc.resolve(rowPos);
183
- const tablePos = $pos.start($pos.depth) - 1;
184
- tr.setNodeMarkup(tablePos, null, setNodeStyle($pos.parent.attrs, 'height', tableHeight));
185
- }
186
- }
187
- function displayRowHeight(view, cellPos, height, offset, tableHeight) {
188
- const cell = view.nodeDOM(cellPos);
189
- const row = cell && cell.parentNode;
190
- if (row) {
191
- row.style.height = height + 'px';
192
- const win = (row.ownerDocument && row.ownerDocument.defaultView) || window;
193
- row.style.height = win.getComputedStyle(row).height;
194
- const table = row.closest('table');
195
- const newHeight = (parseFloat(tableHeight) + offset) + 'px';
196
- const current = table && table.style.height;
197
- if (current && current !== newHeight) {
198
- table.style.height = (parseFloat(tableHeight) + offset) + 'px';
199
- table.style.height = win.getComputedStyle(table).height;
200
- }
201
- }
202
- }
203
- function handleDecorations(state, cell) {
204
- const decorations = [];
205
- if (typeof cell !== 'number') {
206
- return DecorationSet.empty;
207
- }
208
- const $cell = state.doc.resolve(cell), table = $cell.node(-1), map = TableMap.get(table), start = $cell.start(-1);
209
- const cellsPositions = [];
210
- const cellPos = cell - start;
211
- let rowIndex = -1;
212
- for (let i = 0; i < map.height; i++) {
213
- cellsPositions.push(map.map.slice(i * map.width, (i * map.width) + map.width));
214
- if (cellsPositions[i].indexOf(cellPos) !== -1) {
215
- rowIndex = i;
216
- }
217
- }
218
- const cells = [];
219
- cellsPositions[rowIndex].forEach((c, i) => {
220
- if (!cellsPositions[rowIndex + 1] || c !== cellsPositions[rowIndex + 1][i]) {
221
- cells.push(c);
222
- }
223
- });
224
- cells.forEach((cPos) => {
225
- const cellNode = table.nodeAt(cPos);
226
- const widgetPos = start + cPos + (cellNode ? cellNode.nodeSize : 0) - 1;
227
- const dom = document.createElement('div');
228
- dom.className = 'row-resize-handle';
229
- decorations.push(Decoration.widget(widgetPos, dom));
230
- });
231
- return DecorationSet.create(state.doc, decorations);
232
- }
233
-
234
- export { rowResizing };