@progress/kendo-editor-common 1.8.2-dev.202204011319 → 1.9.0-dev.202204060830
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn/js/kendo-editor-common.js +2 -2
- package/dist/cdn/main.js +1 -1
- package/dist/es/config/constants.js +4 -0
- package/dist/es/config/schema.js +9 -5
- package/dist/es/main.js +1 -0
- package/dist/es/plugins/image-resize.js +4 -3
- package/dist/es/plugins/table-resize/column-resize.js +294 -0
- package/dist/es/plugins/table-resize/index.js +8 -0
- package/dist/es/plugins/table-resize/row-resize.js +244 -0
- package/dist/es/plugins/table-resize/table-resize.js +281 -0
- package/dist/es/plugins/table-resize/table-view.js +87 -0
- package/dist/es/plugins/table-resize/utils.js +53 -0
- package/dist/es2015/config/constants.js +4 -0
- package/dist/es2015/config/schema.js +11 -8
- package/dist/es2015/main.js +1 -0
- package/dist/es2015/plugins/image-resize.js +4 -3
- package/dist/es2015/plugins/table-resize/column-resize.js +290 -0
- package/dist/es2015/plugins/table-resize/index.js +8 -0
- package/dist/es2015/plugins/table-resize/row-resize.js +240 -0
- package/dist/es2015/plugins/table-resize/table-resize.js +277 -0
- package/dist/es2015/plugins/table-resize/table-view.js +84 -0
- package/dist/es2015/plugins/table-resize/utils.js +51 -0
- package/dist/npm/config/constants.d.ts +4 -0
- package/dist/npm/config/constants.js +4 -0
- package/dist/npm/config/schema.d.ts +1 -0
- package/dist/npm/config/schema.js +8 -4
- package/dist/npm/main.d.ts +1 -0
- package/dist/npm/main.js +2 -0
- package/dist/npm/plugins/image-resize.js +4 -3
- package/dist/npm/plugins/table-resize/column-resize.d.ts +2 -0
- package/dist/npm/plugins/table-resize/column-resize.js +297 -0
- package/dist/npm/plugins/table-resize/index.d.ts +1 -0
- package/dist/npm/plugins/table-resize/index.js +10 -0
- package/dist/npm/plugins/table-resize/row-resize.d.ts +2 -0
- package/dist/npm/plugins/table-resize/row-resize.js +247 -0
- package/dist/npm/plugins/table-resize/table-resize.d.ts +6 -0
- package/dist/npm/plugins/table-resize/table-resize.js +283 -0
- package/dist/npm/plugins/table-resize/table-view.d.ts +17 -0
- package/dist/npm/plugins/table-resize/table-view.js +89 -0
- package/dist/npm/plugins/table-resize/utils.d.ts +12 -0
- package/dist/npm/plugins/table-resize/utils.js +59 -0
- package/dist/systemjs/kendo-editor-common.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { NodeSelection, Plugin } from 'prosemirror-state';
|
|
2
|
+
import { colgroupAttr, dataDirection, resizableAttr } from '../../config/constants';
|
|
3
|
+
import { getTable, parseStyle, setNodeStyle, tableResizeKey as key } from './utils';
|
|
4
|
+
function parentNode(pos, predicate) {
|
|
5
|
+
for (let d = pos.depth; d > 0; d--) {
|
|
6
|
+
let node = pos.node(d);
|
|
7
|
+
if (predicate(node)) {
|
|
8
|
+
return node;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const directions = {
|
|
14
|
+
'southeast': { x: 1, y: 1 },
|
|
15
|
+
'east': { x: 1, y: 0 },
|
|
16
|
+
'south': { x: 0, y: 1 },
|
|
17
|
+
'north': { x: 0, y: -1 },
|
|
18
|
+
'west': { x: -1, y: 0 },
|
|
19
|
+
'southwest': { x: -1, y: 1 },
|
|
20
|
+
'northwest': { x: -1, y: -1 },
|
|
21
|
+
'northeast': { x: 1, y: -1 } // top right
|
|
22
|
+
};
|
|
23
|
+
const commonDir = {
|
|
24
|
+
'southeast': true,
|
|
25
|
+
'southwest': true,
|
|
26
|
+
'northwest': true,
|
|
27
|
+
'northeast': true
|
|
28
|
+
};
|
|
29
|
+
const horizontalDir = Object.assign({ 'east': true, 'west': true }, commonDir);
|
|
30
|
+
const verticalDir = Object.assign({ 'south': true, 'north': true }, commonDir);
|
|
31
|
+
const setSize = (domNode, sizeType, value) => {
|
|
32
|
+
domNode.style[sizeType] = value + 'px';
|
|
33
|
+
};
|
|
34
|
+
class ResizeState {
|
|
35
|
+
constructor(activeHandle, dragging, nodePosition) {
|
|
36
|
+
this.activeHandle = activeHandle;
|
|
37
|
+
this.dragging = dragging;
|
|
38
|
+
this.nodePosition = nodePosition;
|
|
39
|
+
}
|
|
40
|
+
apply(tr) {
|
|
41
|
+
let state = this, next = tr.getMeta(key);
|
|
42
|
+
if (next) {
|
|
43
|
+
const nextState = new ResizeState(next.activeHandle, next.setDragging, next.nodePosition);
|
|
44
|
+
return nextState;
|
|
45
|
+
}
|
|
46
|
+
return state;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const handleMouseMove = (view, event, options) => {
|
|
50
|
+
const state = key.getState(view.state);
|
|
51
|
+
const { dragging, nodePosition, activeHandle } = state;
|
|
52
|
+
if (nodePosition < 0 || !dragging) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
let resizedNode = getTable(view.nodeDOM(nodePosition));
|
|
56
|
+
const rect = resizedNode.getBoundingClientRect();
|
|
57
|
+
const dir = directions[activeHandle];
|
|
58
|
+
const diffX = (event.clientX - dragging.startX) * dir.x;
|
|
59
|
+
const diffY = (event.clientY - dragging.startY) * dir.y;
|
|
60
|
+
const nodeWidth = resizedNode.offsetWidth;
|
|
61
|
+
const nodeHeight = resizedNode.offsetHeight;
|
|
62
|
+
let width = dir.x ? diffX + nodeWidth : rect.width;
|
|
63
|
+
let height = dir.y ? diffY + nodeHeight : rect.height;
|
|
64
|
+
if (options.lockRatio && dir.x && dir.y) {
|
|
65
|
+
let ratio = Math.min(width / nodeWidth, height / nodeHeight);
|
|
66
|
+
let lockWidth = nodeWidth * ratio;
|
|
67
|
+
let lockHeight = nodeHeight * ratio;
|
|
68
|
+
dragging.startX = event.clientX - (width - lockWidth) * dir.x;
|
|
69
|
+
dragging.startY = event.clientY - (height - lockHeight) * dir.y;
|
|
70
|
+
width = lockWidth;
|
|
71
|
+
height = lockHeight;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
dragging.startX = dir.x ? event.clientX : dragging.startX;
|
|
75
|
+
dragging.startY = dir.y ? event.clientY : dragging.startY;
|
|
76
|
+
}
|
|
77
|
+
if (horizontalDir[activeHandle]) {
|
|
78
|
+
setSize(resizedNode, 'width', width);
|
|
79
|
+
}
|
|
80
|
+
if (verticalDir[activeHandle]) {
|
|
81
|
+
setSize(resizedNode, 'height', height);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const toPercents = (view, tr, tablePos) => {
|
|
85
|
+
const tableNode = view.state.doc.nodeAt(tablePos);
|
|
86
|
+
const tableDom = getTable(view.nodeDOM(tablePos));
|
|
87
|
+
const { width: tableWidth, height: tableHeight, colsWidth } = tableSize(tableDom);
|
|
88
|
+
const colgroup = tableDom.firstChild;
|
|
89
|
+
const cols = Array.from((colgroup && colgroup.children) || []);
|
|
90
|
+
// const borders = new Array(cols.length).fill(tableWidth / tableOffsetWidth / cols.length);
|
|
91
|
+
let widthChanged = false;
|
|
92
|
+
cols.forEach((col, i) => {
|
|
93
|
+
if (col.style.width && !/%$/.test(col.style.width)) {
|
|
94
|
+
col.style.width = ((colsWidth[i]) * 100 / tableWidth) + '%';
|
|
95
|
+
widthChanged = true;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
const rows = Array.from(tableDom.rows);
|
|
99
|
+
let heightChange = false;
|
|
100
|
+
tableNode.forEach((row, offset, index) => {
|
|
101
|
+
const rowHeight = parseStyle(row.attrs.style).height;
|
|
102
|
+
if (rowHeight && !/%$/.test(rowHeight)) {
|
|
103
|
+
tr.setNodeMarkup(tablePos + offset + 1, null, setNodeStyle(row.attrs, 'height', (rows[index].offsetHeight * 100 / tableHeight) + '%'));
|
|
104
|
+
heightChange = true;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
let tableAttrs = tableNode.attrs;
|
|
108
|
+
if (parseStyle(tableAttrs.style).width !== tableWidth + 'px') {
|
|
109
|
+
tableAttrs = setNodeStyle(tableAttrs, 'width', tableWidth + 'px');
|
|
110
|
+
}
|
|
111
|
+
if (widthChanged) {
|
|
112
|
+
tableAttrs[colgroupAttr] = colgroup.outerHTML;
|
|
113
|
+
}
|
|
114
|
+
if (heightChange) {
|
|
115
|
+
tableAttrs = setNodeStyle(tableAttrs, 'height', tableHeight + 'px');
|
|
116
|
+
}
|
|
117
|
+
if (widthChanged || heightChange) {
|
|
118
|
+
tr.setNodeMarkup(tablePos, null, tableAttrs);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const toPixels = (view, tr, tablePos, attrs) => {
|
|
122
|
+
const tableNode = view.state.doc.nodeAt(tablePos);
|
|
123
|
+
const tableDom = getTable(view.nodeDOM(tablePos));
|
|
124
|
+
const rows = Array.from(tableDom.rows);
|
|
125
|
+
tableNode.forEach((row, offset, index) => {
|
|
126
|
+
const rowHeight = parseStyle(row.attrs.style).height;
|
|
127
|
+
if (rowHeight && !/px$/.test(rowHeight)) {
|
|
128
|
+
tr.setNodeMarkup(tablePos + offset + 1, null, setNodeStyle(row.attrs, 'height', rows[index].offsetHeight + 'px'));
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
const colgroup = tableDom.firstChild;
|
|
132
|
+
const cols = Array.from((colgroup && colgroup.children) || []);
|
|
133
|
+
let widthChanged = false;
|
|
134
|
+
cols.forEach((col, i) => {
|
|
135
|
+
if (col.style.width && !/px$/.test(col.style.width)) {
|
|
136
|
+
col.style.width = cols[i].offsetWidth + 'px';
|
|
137
|
+
widthChanged = true;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
let tableAttrs = Object.assign({}, attrs);
|
|
141
|
+
if (widthChanged) {
|
|
142
|
+
tableAttrs[colgroupAttr] = colgroup.outerHTML;
|
|
143
|
+
}
|
|
144
|
+
return tableAttrs;
|
|
145
|
+
};
|
|
146
|
+
const tableSize = (table) => {
|
|
147
|
+
const cols = Array.from(table.firstChild.children);
|
|
148
|
+
const colsWidth = cols.map(c => c.offsetWidth);
|
|
149
|
+
const width = colsWidth.reduce((acc, cur) => acc + cur, 0);
|
|
150
|
+
const height = table.offsetHeight; // Array.from(table.rows).reduce((acc, cur) => acc + cur.offsetHeight, 0);
|
|
151
|
+
return { width, height, colsWidth, offsetWidth: table.offsetWidth };
|
|
152
|
+
};
|
|
153
|
+
const handleMouseUp = (view) => {
|
|
154
|
+
const { dragging, nodePosition, activeHandle } = key.getState(view.state);
|
|
155
|
+
if (dragging) {
|
|
156
|
+
const node = view.state.doc.nodeAt(nodePosition);
|
|
157
|
+
const dom = getTable(view.nodeDOM(nodePosition));
|
|
158
|
+
const rect = tableSize(dom);
|
|
159
|
+
if (node) {
|
|
160
|
+
const width = rect.offsetWidth + 'px';
|
|
161
|
+
const height = rect.height + 'px';
|
|
162
|
+
const tr = view.state.tr;
|
|
163
|
+
let attrs = node.attrs;
|
|
164
|
+
const parsedStyles = parseStyle(attrs.style);
|
|
165
|
+
if (horizontalDir[activeHandle] && dom.style.width && parsedStyles.width !== width) {
|
|
166
|
+
attrs = setNodeStyle(attrs, 'width', width);
|
|
167
|
+
}
|
|
168
|
+
if (verticalDir[activeHandle] && dom.style.height && parsedStyles.height !== height) {
|
|
169
|
+
attrs = setNodeStyle(attrs, 'height', height);
|
|
170
|
+
}
|
|
171
|
+
toPixels(view, tr, nodePosition, attrs);
|
|
172
|
+
tr.setNodeMarkup(nodePosition, null, attrs);
|
|
173
|
+
tr.setMeta('commandName', 'node-resize');
|
|
174
|
+
tr.setMeta('args', attrs);
|
|
175
|
+
tr.setMeta(key, {
|
|
176
|
+
setDragging: null,
|
|
177
|
+
activeHandle: null,
|
|
178
|
+
nodePosition
|
|
179
|
+
});
|
|
180
|
+
view.dispatch(tr);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const handleMouseDown = (view, event, options) => {
|
|
185
|
+
const target = event.target;
|
|
186
|
+
const activeHandle = target.getAttribute(dataDirection);
|
|
187
|
+
if (!activeHandle) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
const resizeState = key.getState(view.state);
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
const transaction = view.state.tr;
|
|
193
|
+
transaction.setMeta(key, {
|
|
194
|
+
setDragging: { startX: event.clientX, startY: event.clientY },
|
|
195
|
+
activeHandle,
|
|
196
|
+
nodePosition: resizeState.nodePosition
|
|
197
|
+
});
|
|
198
|
+
transaction.setMeta('addToHistory', false);
|
|
199
|
+
toPercents(view, transaction, resizeState.nodePosition);
|
|
200
|
+
view.dispatch(transaction);
|
|
201
|
+
const curWindow = event.view || window;
|
|
202
|
+
function move(e) {
|
|
203
|
+
handleMouseMove(view, e, options);
|
|
204
|
+
}
|
|
205
|
+
function finish(_e) {
|
|
206
|
+
curWindow.removeEventListener('mouseup', finish);
|
|
207
|
+
curWindow.removeEventListener('mousemove', move);
|
|
208
|
+
handleMouseUp(view);
|
|
209
|
+
}
|
|
210
|
+
curWindow.addEventListener('mouseup', finish);
|
|
211
|
+
curWindow.addEventListener('mousemove', move);
|
|
212
|
+
return true;
|
|
213
|
+
};
|
|
214
|
+
export const tableResizing = (options = { node: 'table', lockRatio: false }) => {
|
|
215
|
+
return new Plugin({
|
|
216
|
+
key: key,
|
|
217
|
+
view: (_viewObj) => ({
|
|
218
|
+
selectedNode(state, nodeType) {
|
|
219
|
+
const selection = state.selection;
|
|
220
|
+
const isNodeSelected = selection instanceof NodeSelection && nodeType === selection.node.type;
|
|
221
|
+
if (isNodeSelected && selection instanceof NodeSelection) {
|
|
222
|
+
return { node: selection.node, pos: selection.from };
|
|
223
|
+
}
|
|
224
|
+
const node = parentNode(selection.$from, (n) => n.type === nodeType);
|
|
225
|
+
if (node) {
|
|
226
|
+
let tableDepth = new Array(selection.$from.depth + 1).fill(0)
|
|
227
|
+
.findIndex((_, i) => selection.$from.node(i).type.spec.tableRole === 'table');
|
|
228
|
+
const pos = selection.$from.start(tableDepth) - 1;
|
|
229
|
+
return { node, pos };
|
|
230
|
+
}
|
|
231
|
+
return null;
|
|
232
|
+
},
|
|
233
|
+
update(view, prevState) {
|
|
234
|
+
const state = view.state;
|
|
235
|
+
const nodeType = state.schema.nodes[options.node];
|
|
236
|
+
const selected = this.selectedNode(state, nodeType);
|
|
237
|
+
const prevSelected = this.selectedNode(prevState, nodeType);
|
|
238
|
+
if (!selected && prevSelected && !prevState.doc.eq(view.state.doc)) {
|
|
239
|
+
// selected table is deleted
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (selected || prevSelected) {
|
|
243
|
+
let tr = state.tr;
|
|
244
|
+
if (selected && prevSelected && selected.pos !== prevSelected.pos) {
|
|
245
|
+
tr.setMeta(key, { nodePosition: selected.pos });
|
|
246
|
+
tr.setNodeMarkup(prevSelected.pos, nodeType, Object.assign({}, prevSelected.node.attrs, { [resizableAttr]: false }));
|
|
247
|
+
tr.setNodeMarkup(selected.pos, nodeType, Object.assign({}, selected.node.attrs, { [resizableAttr]: true }));
|
|
248
|
+
view.dispatch(tr);
|
|
249
|
+
}
|
|
250
|
+
else if (selected && !prevSelected) {
|
|
251
|
+
tr.setMeta(key, { nodePosition: selected.pos });
|
|
252
|
+
view.dispatch(tr.setNodeMarkup(selected.pos, nodeType, Object.assign({}, selected.node.attrs, { [resizableAttr]: true })));
|
|
253
|
+
}
|
|
254
|
+
else if (!selected && prevSelected) {
|
|
255
|
+
tr.setMeta(key, { nodePosition: -1 });
|
|
256
|
+
view.dispatch(tr.setNodeMarkup(prevSelected.pos, nodeType, Object.assign({}, prevSelected.node.attrs, { [resizableAttr]: false })));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}),
|
|
261
|
+
state: {
|
|
262
|
+
init() {
|
|
263
|
+
return new ResizeState('', null, -1);
|
|
264
|
+
},
|
|
265
|
+
apply(tr, prev) {
|
|
266
|
+
return prev.apply(tr);
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
props: {
|
|
270
|
+
handleDOMEvents: {
|
|
271
|
+
mousedown(view, event) {
|
|
272
|
+
return handleMouseDown(view, event, options);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { colgroupAttr, dataDirection, resizableAttr, resizableWrap, resizeHandle } from '../../config/constants';
|
|
2
|
+
import { parseStrColgroup } from '../../config/schema';
|
|
3
|
+
const directions = ['northwest', 'north', 'northeast', 'southwest', 'south', 'southeast', 'west', 'east'];
|
|
4
|
+
export class TableView {
|
|
5
|
+
constructor(node, view) {
|
|
6
|
+
this.node = node;
|
|
7
|
+
this.view = view;
|
|
8
|
+
this.dom = document.createElement('div');
|
|
9
|
+
this.dom.className = resizableWrap;
|
|
10
|
+
this.table = this.dom.appendChild(document.createElement('table'));
|
|
11
|
+
if (node.attrs[colgroupAttr]) {
|
|
12
|
+
this.renderColgroup(node.attrs[colgroupAttr]);
|
|
13
|
+
}
|
|
14
|
+
const tBody = this.table.appendChild(document.createElement('tbody'));
|
|
15
|
+
this.setAttributes(this.table, node.attrs);
|
|
16
|
+
this.resizeHandles = directions.map(dir => {
|
|
17
|
+
const handle = document.createElement('span');
|
|
18
|
+
handle.className = resizeHandle + ' ' + dir;
|
|
19
|
+
handle.setAttribute(dataDirection, dir);
|
|
20
|
+
return handle;
|
|
21
|
+
});
|
|
22
|
+
this.contentDOM = tBody;
|
|
23
|
+
}
|
|
24
|
+
update(node) {
|
|
25
|
+
if (node.type !== this.node.type) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const prev = this.node;
|
|
29
|
+
this.node = node;
|
|
30
|
+
if (node.attrs[resizableAttr]) {
|
|
31
|
+
this.resizeHandles.forEach(handle => {
|
|
32
|
+
this.dom.appendChild(handle);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
Array.from(this.dom.children)
|
|
37
|
+
.filter((e) => e.classList.contains(resizeHandle))
|
|
38
|
+
.forEach((e) => e.remove());
|
|
39
|
+
}
|
|
40
|
+
this.setAttributes(this.table, node.attrs);
|
|
41
|
+
if (prev.attrs[colgroupAttr] !== node.attrs[colgroupAttr]) {
|
|
42
|
+
this.renderColgroup(node.attrs[colgroupAttr]);
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
ignoreMutation(record) {
|
|
47
|
+
const result = record.type === 'attributes' &&
|
|
48
|
+
(record.target === this.table ||
|
|
49
|
+
record.target.firstChild === this.table ||
|
|
50
|
+
(this.colgroup && this.colgroup.contains(record.target)));
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
destroy() {
|
|
54
|
+
this.node = null;
|
|
55
|
+
this.view = null;
|
|
56
|
+
this.table = null;
|
|
57
|
+
this.colgroup = null;
|
|
58
|
+
this.resizeHandles = null;
|
|
59
|
+
}
|
|
60
|
+
renderColgroup(colgroupStr) {
|
|
61
|
+
if (this.table && this.table.firstChild && this.table.firstChild.nodeName === 'COLGROUP') {
|
|
62
|
+
this.table.removeChild(this.table.firstChild);
|
|
63
|
+
}
|
|
64
|
+
if (colgroupStr) {
|
|
65
|
+
this.colgroup = parseStrColgroup(colgroupStr);
|
|
66
|
+
this.table.insertBefore(this.colgroup, this.table.firstChild);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
setAttributes(table, attrs) {
|
|
70
|
+
const skip = [colgroupAttr, resizableAttr];
|
|
71
|
+
for (let attrName in attrs) {
|
|
72
|
+
if (attrName && skip.indexOf(attrName) === -1) {
|
|
73
|
+
const current = table.getAttribute(attrName);
|
|
74
|
+
const next = attrs[attrName];
|
|
75
|
+
if (next && next !== current) {
|
|
76
|
+
table.setAttribute(attrName, next);
|
|
77
|
+
}
|
|
78
|
+
else if (!next) {
|
|
79
|
+
table.removeAttribute(attrName);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { PluginKey } from 'prosemirror-state';
|
|
2
|
+
import { changeStylesString } from '../../utils';
|
|
3
|
+
export const reAnyValue = /^.+$/;
|
|
4
|
+
export const parseStyle = (styleText) => {
|
|
5
|
+
const styles = (styleText || '').split(/\s*;\s*/).filter(Boolean).map(s => {
|
|
6
|
+
const nameValue = s.split(/\s*:\s*/);
|
|
7
|
+
return { [nameValue[0]]: nameValue[1] };
|
|
8
|
+
}).reduce((acc, val) => (Object.assign({}, acc, val)), {});
|
|
9
|
+
return styles;
|
|
10
|
+
};
|
|
11
|
+
export function setNodeStyle(nodeAttrs, styleType, value) {
|
|
12
|
+
let attrs;
|
|
13
|
+
if (new RegExp('[^-]?' + styleType + ':').test(nodeAttrs.style || '')) {
|
|
14
|
+
const { style } = changeStylesString(nodeAttrs.style || '', { style: styleType, value: reAnyValue, newValue: value });
|
|
15
|
+
attrs = Object.assign({}, nodeAttrs, { style });
|
|
16
|
+
}
|
|
17
|
+
else if (nodeAttrs.style) {
|
|
18
|
+
attrs = Object.assign({}, nodeAttrs, { style: nodeAttrs.style.replace(/;$/, '') + '; ' + styleType + ': ' + value + ';' });
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
attrs = Object.assign({}, nodeAttrs, { style: styleType + ': ' + value + ';' });
|
|
22
|
+
}
|
|
23
|
+
return attrs;
|
|
24
|
+
}
|
|
25
|
+
export const tableResizeKey = new PluginKey('table-resize');
|
|
26
|
+
export const tableColumnResizing = new PluginKey('table-column-resizing');
|
|
27
|
+
export const tableRowResizing = new PluginKey('table-row-resizing');
|
|
28
|
+
export function otherResizing(current, state) {
|
|
29
|
+
let activeResize = false;
|
|
30
|
+
activeResize = activeResize ||
|
|
31
|
+
(current !== tableResizeKey && Boolean(tableResizeKey.get(state)) && tableResizeKey.getState(state).dragging);
|
|
32
|
+
activeResize = activeResize ||
|
|
33
|
+
(current !== tableColumnResizing && Boolean(tableColumnResizing.get(state)) && tableColumnResizing.getState(state).dragging);
|
|
34
|
+
activeResize = activeResize ||
|
|
35
|
+
(current !== tableRowResizing && Boolean(tableRowResizing.get(state)) && tableRowResizing.getState(state).dragging);
|
|
36
|
+
return activeResize;
|
|
37
|
+
}
|
|
38
|
+
export function otherResizeHandle(current, state) {
|
|
39
|
+
let activeResize = false;
|
|
40
|
+
activeResize = activeResize ||
|
|
41
|
+
(current !== tableColumnResizing && tableColumnResizing.get(state) && tableColumnResizing.getState(state).activeHandle > -1);
|
|
42
|
+
activeResize = activeResize ||
|
|
43
|
+
(current !== tableRowResizing && tableRowResizing.get(state) && tableRowResizing.getState(state).activeHandle > -1);
|
|
44
|
+
return activeResize;
|
|
45
|
+
}
|
|
46
|
+
export function getTable(dom) {
|
|
47
|
+
if (dom && dom.firstChild && dom.firstChild.nodeName === 'TABLE') {
|
|
48
|
+
return dom.firstChild;
|
|
49
|
+
}
|
|
50
|
+
return dom;
|
|
51
|
+
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export declare const rowTypeAttr = "k-parent-node";
|
|
2
2
|
export declare const colgroupAttr = "k-colgroup-data";
|
|
3
|
+
export declare const resizableAttr = "resizable-node";
|
|
4
|
+
export declare const resizableWrap = "k-editor-resize-wrap-element";
|
|
5
|
+
export declare const resizeHandle = "k-editor-resize-handle";
|
|
6
|
+
export declare const dataDirection = "data-direction";
|
|
@@ -2,3 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rowTypeAttr = 'k-parent-node';
|
|
4
4
|
exports.colgroupAttr = 'k-colgroup-data';
|
|
5
|
+
exports.resizableAttr = 'resizable-node';
|
|
6
|
+
exports.resizableWrap = 'k-editor-resize-wrap-element';
|
|
7
|
+
exports.resizeHandle = 'k-editor-resize-handle';
|
|
8
|
+
exports.dataDirection = 'data-direction';
|
|
@@ -112,18 +112,22 @@ var shouldSkipColgroup = function (node) {
|
|
|
112
112
|
}
|
|
113
113
|
return shouldSkip;
|
|
114
114
|
};
|
|
115
|
+
exports.parseStrColgroup = function (colgroup) {
|
|
116
|
+
var doc = source_1.domToPmDoc(source_1.htmlToFragment(colgroup), colgroupSchema, { preserveWhitespace: false });
|
|
117
|
+
var fragment = source_1.pmDocToFragment(doc);
|
|
118
|
+
var colgroupEl = fragment.firstChild;
|
|
119
|
+
return colgroupEl;
|
|
120
|
+
};
|
|
115
121
|
var tNodes = prosemirror_tables_1.tableNodes({ tableGroup: 'block', cellContent: 'block+', cellAttributes: cellAttributes });
|
|
116
122
|
tNodes.table_row.attrs = tslib_1.__assign({}, tNodes.table_row.attrs, defaultAttrs([constants_1.rowTypeAttr, 'style', 'class', 'id']));
|
|
117
123
|
tNodes.table_row.toDOM = function (node) { return ['tr', pmAttributes(node.attrs), 0]; };
|
|
118
124
|
tNodes.table_row.parseDOM = [{ tag: 'tr', getAttrs: domAttributes }];
|
|
119
|
-
tNodes.table.attrs = tslib_1.__assign({}, tNodes.table.attrs, defaultAttrs(['style', 'class', 'id', constants_1.colgroupAttr]));
|
|
125
|
+
tNodes.table.attrs = tslib_1.__assign({}, tNodes.table.attrs, defaultAttrs(['style', 'class', 'id', constants_1.colgroupAttr, constants_1.resizableAttr]));
|
|
120
126
|
tNodes.table.toDOM = function (node) {
|
|
121
127
|
var tableAttrs = hasAttrs(node.attrs) ? pmAttributes(node.attrs, constants_1.colgroupAttr) : {};
|
|
122
128
|
var colgroup = null;
|
|
123
129
|
if (node.attrs[constants_1.colgroupAttr] && !shouldSkipColgroup(node)) {
|
|
124
|
-
var
|
|
125
|
-
var fragment = source_1.pmDocToFragment(doc);
|
|
126
|
-
var colgroupEl = fragment.firstChild;
|
|
130
|
+
var colgroupEl = exports.parseStrColgroup(node.attrs[constants_1.colgroupAttr]);
|
|
127
131
|
if (colgroupEl) {
|
|
128
132
|
var cols = Array.from(colgroupEl.children).map(function (c) { return ['col', domAttributes(c)]; });
|
|
129
133
|
colgroup = [
|
package/dist/npm/main.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export { spacesFix } from './plugins/spaces-fix';
|
|
|
26
26
|
export { textHighlight, textHighlightKey, InlineDecoration } from './plugins/highlight';
|
|
27
27
|
export { imageResizing, imageResizeKey, ImageResizeOptions } from './plugins/image-resize';
|
|
28
28
|
export { caretColor, caretColorKey } from './plugins/caret-color';
|
|
29
|
+
export { tableResizing } from './plugins/table-resize';
|
|
29
30
|
export * from 'prosemirror-commands';
|
|
30
31
|
export * from 'prosemirror-dropcursor';
|
|
31
32
|
export * from 'prosemirror-gapcursor';
|
package/dist/npm/main.js
CHANGED
|
@@ -120,6 +120,8 @@ exports.imageResizeKey = image_resize_1.imageResizeKey;
|
|
|
120
120
|
var caret_color_1 = require("./plugins/caret-color");
|
|
121
121
|
exports.caretColor = caret_color_1.caretColor;
|
|
122
122
|
exports.caretColorKey = caret_color_1.caretColorKey;
|
|
123
|
+
var table_resize_1 = require("./plugins/table-resize");
|
|
124
|
+
exports.tableResizing = table_resize_1.tableResizing;
|
|
123
125
|
// ProseMirror re-exports
|
|
124
126
|
tslib_1.__exportStar(require("prosemirror-commands"), exports);
|
|
125
127
|
tslib_1.__exportStar(require("prosemirror-dropcursor"), exports);
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
4
|
var prosemirror_state_1 = require("prosemirror-state");
|
|
5
5
|
var prosemirror_view_1 = require("prosemirror-view");
|
|
6
|
+
var constants_1 = require("../config/constants");
|
|
6
7
|
var utils_1 = require("../utils");
|
|
7
8
|
exports.imageResizeKey = new prosemirror_state_1.PluginKey('image-resize');
|
|
8
9
|
var directions = {
|
|
@@ -111,7 +112,7 @@ var handleMouseUp = function (view) {
|
|
|
111
112
|
};
|
|
112
113
|
var handleMouseDown = function (view, event, options) {
|
|
113
114
|
var target = event.target;
|
|
114
|
-
var activeHandle = target.getAttribute(
|
|
115
|
+
var activeHandle = target.getAttribute(constants_1.dataDirection);
|
|
115
116
|
if (!activeHandle) {
|
|
116
117
|
return false;
|
|
117
118
|
}
|
|
@@ -223,8 +224,8 @@ exports.imageResizing = function (options) {
|
|
|
223
224
|
wrapper.style.left = rect.left + 'px';
|
|
224
225
|
for (var i = 0; i < handles.length; i++) {
|
|
225
226
|
var dom = document.createElement('div');
|
|
226
|
-
dom.className = '
|
|
227
|
-
dom.setAttribute(
|
|
227
|
+
dom.className = constants_1.resizeHandle + ' ' + handles[i];
|
|
228
|
+
dom.setAttribute(constants_1.dataDirection, handles[i]);
|
|
228
229
|
wrapper.appendChild(dom);
|
|
229
230
|
}
|
|
230
231
|
return prosemirror_view_1.DecorationSet.create(state.doc, [prosemirror_view_1.Decoration.widget(state.selection.from + 1, wrapper)]);
|