@progress/kendo-editor-common 1.11.9-dev.202412020819 → 1.11.9-develop.1
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/main.js +1 -1
- package/dist/es/DOMSerializer.js +71 -75
- package/dist/es/align.js +19 -16
- package/dist/es/blockNode.js +76 -78
- package/dist/es/blockquote.js +12 -9
- package/dist/es/cleanFormatting.js +16 -16
- package/dist/es/config/align-rules.js +8 -6
- package/dist/es/config/commands.js +9 -13
- package/dist/es/config/constants.js +9 -7
- package/dist/es/config/indent-rules.js +8 -6
- package/dist/es/config/keymap.js +20 -18
- package/dist/es/config/list-settings.js +7 -6
- package/dist/es/config/schema.js +184 -126
- package/dist/es/find-replace.js +34 -32
- package/dist/es/image.js +10 -7
- package/dist/es/indent.js +47 -44
- package/dist/es/inline-style.js +72 -70
- package/dist/es/link.js +51 -52
- package/dist/es/listConvert.js +37 -34
- package/dist/es/lists.js +83 -82
- package/dist/es/main.js +32 -33
- package/dist/es/mark.js +87 -92
- package/dist/es/paste.js +48 -46
- package/dist/es/plugins/caret-color.js +14 -11
- package/dist/es/plugins/csp-fix.js +23 -23
- package/dist/es/plugins/highlight.js +12 -10
- package/dist/es/plugins/image-resize.js +81 -81
- package/dist/es/plugins/list-markers-styles.js +43 -39
- package/dist/es/plugins/placeholder.js +12 -9
- package/dist/es/plugins/resize-utils.js +11 -9
- package/dist/es/plugins/spaces-fix.js +13 -10
- package/dist/es/plugins/table-resize/column-resize.js +104 -102
- package/dist/es/plugins/table-resize/index.js +10 -7
- package/dist/es/plugins/table-resize/row-resize.js +88 -89
- package/dist/es/plugins/table-resize/table-resize.js +129 -122
- package/dist/es/plugins/table-resize/table-view.js +46 -48
- package/dist/es/plugins/table-resize/utils.js +39 -41
- package/dist/es/source.js +78 -74
- package/dist/es/table.js +64 -66
- package/dist/es/text.js +4 -2
- package/dist/es/utils.js +107 -116
- package/dist/es2015/DOMSerializer.js +20 -17
- package/dist/es2015/align.js +6 -3
- package/dist/es2015/blockNode.js +15 -12
- package/dist/es2015/blockquote.js +5 -2
- package/dist/es2015/cleanFormatting.js +6 -3
- package/dist/es2015/config/align-rules.js +7 -5
- package/dist/es2015/config/commands.js +9 -13
- package/dist/es2015/config/constants.js +9 -7
- package/dist/es2015/config/indent-rules.js +6 -3
- package/dist/es2015/config/keymap.js +10 -7
- package/dist/es2015/config/list-settings.js +5 -3
- package/dist/es2015/config/schema.js +8 -6
- package/dist/es2015/find-replace.js +9 -6
- package/dist/es2015/image.js +5 -2
- package/dist/es2015/indent.js +14 -11
- package/dist/es2015/inline-style.js +9 -6
- package/dist/es2015/link.js +7 -4
- package/dist/es2015/listConvert.js +5 -2
- package/dist/es2015/lists.js +14 -11
- package/dist/es2015/main.js +32 -33
- package/dist/es2015/mark.js +15 -12
- package/dist/es2015/node_modules/tslib/tslib.es6.js +35 -0
- package/dist/es2015/paste.js +14 -11
- package/dist/es2015/plugins/caret-color.js +8 -5
- package/dist/es2015/plugins/csp-fix.js +5 -2
- package/dist/es2015/plugins/highlight.js +6 -3
- package/dist/es2015/plugins/image-resize.js +10 -7
- package/dist/es2015/plugins/list-markers-styles.js +6 -3
- package/dist/es2015/plugins/placeholder.js +5 -2
- package/dist/es2015/plugins/resize-utils.js +11 -9
- package/dist/es2015/plugins/spaces-fix.js +4 -1
- package/dist/es2015/plugins/table-resize/column-resize.js +24 -21
- package/dist/es2015/plugins/table-resize/index.js +9 -6
- package/dist/es2015/plugins/table-resize/row-resize.js +23 -20
- package/dist/es2015/plugins/table-resize/table-resize.js +20 -17
- package/dist/es2015/plugins/table-resize/table-view.js +9 -6
- package/dist/es2015/plugins/table-resize/utils.js +13 -10
- package/dist/es2015/source.js +24 -13
- package/dist/es2015/table.js +18 -15
- package/dist/es2015/text.js +3 -1
- package/dist/es2015/utils.js +22 -25
- package/dist/npm/DOMSerializer.js +73 -78
- package/dist/npm/align.d.ts +7 -4
- package/dist/npm/align.js +22 -21
- package/dist/npm/blockNode.d.ts +14 -15
- package/dist/npm/blockNode.js +91 -95
- package/dist/npm/blockquote.d.ts +5 -2
- package/dist/npm/blockquote.js +16 -15
- package/dist/npm/cleanFormatting.d.ts +6 -3
- package/dist/npm/cleanFormatting.js +17 -19
- package/dist/npm/config/align-rules.d.ts +8 -6
- package/dist/npm/config/align-rules.js +14 -9
- package/dist/npm/config/commands.d.ts +11 -19
- package/dist/npm/config/commands.js +17 -16
- package/dist/npm/config/constants.js +17 -10
- package/dist/npm/config/indent-rules.d.ts +6 -4
- package/dist/npm/config/indent-rules.js +11 -9
- package/dist/npm/config/keymap.d.ts +5 -2
- package/dist/npm/config/keymap.js +30 -30
- package/dist/npm/config/list-settings.js +13 -11
- package/dist/npm/config/schema.d.ts +4 -3
- package/dist/npm/config/schema.js +191 -134
- package/dist/npm/find-replace.d.ts +10 -7
- package/dist/npm/find-replace.js +47 -47
- package/dist/npm/image.d.ts +6 -3
- package/dist/npm/image.js +11 -10
- package/dist/npm/indent.d.ts +12 -9
- package/dist/npm/indent.js +68 -67
- package/dist/npm/inline-style.d.ts +7 -4
- package/dist/npm/inline-style.js +83 -83
- package/dist/npm/link.d.ts +4 -2
- package/dist/npm/link.js +58 -61
- package/dist/npm/listConvert.d.ts +3 -1
- package/dist/npm/listConvert.js +40 -39
- package/dist/npm/lists.d.ts +9 -9
- package/dist/npm/lists.js +94 -95
- package/dist/npm/main.d.ts +34 -33
- package/dist/npm/main.js +388 -198
- package/dist/npm/mark.d.ts +13 -18
- package/dist/npm/mark.js +104 -111
- package/dist/npm/paste.d.ts +12 -9
- package/dist/npm/paste.js +61 -61
- package/dist/npm/plugins/caret-color.d.ts +6 -3
- package/dist/npm/plugins/caret-color.js +21 -19
- package/dist/npm/plugins/csp-fix.d.ts +4 -1
- package/dist/npm/plugins/csp-fix.js +28 -30
- package/dist/npm/plugins/highlight.d.ts +7 -4
- package/dist/npm/plugins/highlight.js +17 -16
- package/dist/npm/plugins/image-resize.d.ts +7 -5
- package/dist/npm/plugins/image-resize.js +96 -97
- package/dist/npm/plugins/list-markers-styles.d.ts +5 -2
- package/dist/npm/plugins/list-markers-styles.js +49 -47
- package/dist/npm/plugins/placeholder.d.ts +4 -1
- package/dist/npm/plugins/placeholder.js +18 -17
- package/dist/npm/plugins/resize-utils.js +14 -12
- package/dist/npm/plugins/spaces-fix.d.ts +4 -1
- package/dist/npm/plugins/spaces-fix.js +19 -18
- package/dist/npm/plugins/table-resize/column-resize.js +117 -117
- package/dist/npm/plugins/table-resize/index.d.ts +5 -2
- package/dist/npm/plugins/table-resize/index.js +16 -15
- package/dist/npm/plugins/table-resize/row-resize.js +98 -101
- package/dist/npm/plugins/table-resize/table-resize.js +144 -139
- package/dist/npm/plugins/table-resize/table-view.js +59 -61
- package/dist/npm/plugins/table-resize/utils.d.ts +7 -17
- package/dist/npm/plugins/table-resize/utils.js +51 -52
- package/dist/npm/source.d.ts +18 -11
- package/dist/npm/source.js +94 -91
- package/dist/npm/table.d.ts +10 -9
- package/dist/npm/table.js +93 -82
- package/dist/npm/text.d.ts +6 -3
- package/dist/npm/text.js +5 -5
- package/dist/npm/types/active-marks.d.ts +4 -1
- package/dist/npm/types/command.d.ts +5 -2
- package/dist/npm/types/dispatchFn.d.ts +4 -1
- package/dist/npm/types/paste-cleanup-settings.d.ts +3 -1
- package/dist/npm/utils.d.ts +13 -32
- package/dist/npm/utils.js +133 -145
- package/package.json +34 -52
- package/dist/cdn/js/kendo-editor-common.js +0 -1
- package/dist/es/types/active-marks.js +0 -1
- package/dist/es/types/command.js +0 -1
- package/dist/es/types/dispatchFn.js +0 -1
- package/dist/es/types/paste-cleanup-settings.js +0 -1
- package/dist/es/types/predicate.js +0 -1
- package/dist/es2015/types/active-marks.js +0 -1
- package/dist/es2015/types/command.js +0 -1
- package/dist/es2015/types/dispatchFn.js +0 -1
- package/dist/es2015/types/paste-cleanup-settings.js +0 -1
- package/dist/es2015/types/predicate.js +0 -1
- package/dist/npm/DOMSerializer.d.ts +0 -35
- package/dist/npm/config/constants.d.ts +0 -7
- package/dist/npm/config/list-settings.d.ts +0 -30
- package/dist/npm/plugins/resize-utils.d.ts +0 -35
- package/dist/npm/plugins/table-resize/column-resize.d.ts +0 -2
- package/dist/npm/plugins/table-resize/row-resize.d.ts +0 -2
- package/dist/npm/plugins/table-resize/table-resize.d.ts +0 -18
- package/dist/npm/plugins/table-resize/table-view.d.ts +0 -28
- package/dist/npm/types/active-marks.js +0 -2
- package/dist/npm/types/command.js +0 -2
- package/dist/npm/types/dispatchFn.js +0 -2
- package/dist/npm/types/paste-cleanup-settings.js +0 -2
- package/dist/npm/types/predicate.d.ts +0 -1
- package/dist/npm/types/predicate.js +0 -2
- package/dist/systemjs/kendo-editor-common.js +0 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { PluginKey } from 'prosemirror-state';
|
|
2
2
|
import { TableMap } from 'prosemirror-tables';
|
|
3
|
-
import { parentNode } from '../../utils';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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;
|
|
9
10
|
activeResize = activeResize ||
|
|
10
11
|
(current !== tableResizeKey && Boolean(tableResizeKey.get(state)) && tableResizeKey.getState(state).dragging);
|
|
11
12
|
activeResize = activeResize ||
|
|
@@ -14,8 +15,8 @@ export function otherResizing(current, state) {
|
|
|
14
15
|
(current !== tableRowResizeKey && Boolean(tableRowResizeKey.get(state)) && tableRowResizeKey.getState(state).dragging);
|
|
15
16
|
return activeResize;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
function otherResizeHandle(current, state) {
|
|
19
|
+
let activeResize = false;
|
|
19
20
|
activeResize = activeResize ||
|
|
20
21
|
(current !== tableColumnResizeKey &&
|
|
21
22
|
Boolean(tableColumnResizeKey.get(state)) &&
|
|
@@ -24,30 +25,30 @@ export function otherResizeHandle(current, state) {
|
|
|
24
25
|
(current !== tableRowResizeKey && Boolean(tableRowResizeKey.get(state)) && tableRowResizeKey.getState(state).activeHandle > -1);
|
|
25
26
|
return activeResize;
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
+
function getTable(dom) {
|
|
28
29
|
if (dom && dom.firstChild && dom.firstChild.nodeName === 'TABLE') {
|
|
29
30
|
return dom.firstChild;
|
|
30
31
|
}
|
|
31
32
|
return dom;
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
+
function domCellAround(target) {
|
|
34
35
|
while (target && target.nodeName !== 'TD' && target.nodeName !== 'TH') {
|
|
35
36
|
target = target.classList.contains('ProseMirror') ? null : target.parentNode;
|
|
36
37
|
}
|
|
37
38
|
return target;
|
|
38
39
|
}
|
|
39
40
|
function tableSpansMap(table) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
.map(
|
|
43
|
-
.reduce(
|
|
44
|
-
|
|
45
|
-
rows.forEach(
|
|
46
|
-
|
|
47
|
-
Array.from(row.cells).forEach(
|
|
48
|
-
for (
|
|
49
|
-
for (
|
|
50
|
-
|
|
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);
|
|
51
52
|
map[r + rowSp][ind] = c;
|
|
52
53
|
}
|
|
53
54
|
curColSpan++;
|
|
@@ -56,40 +57,37 @@ function tableSpansMap(table) {
|
|
|
56
57
|
});
|
|
57
58
|
return map;
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
row.forEach(
|
|
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) => {
|
|
65
66
|
if (dataCell === cell) {
|
|
66
67
|
result = { rowIndex: r, cellIndex: c };
|
|
67
68
|
}
|
|
68
69
|
});
|
|
69
70
|
if (result) {
|
|
70
|
-
return "break";
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
for (var r = 0; r < map.length; r++) {
|
|
74
|
-
var state_1 = _loop_1(r);
|
|
75
|
-
if (state_1 === "break")
|
|
76
71
|
break;
|
|
72
|
+
}
|
|
77
73
|
}
|
|
78
74
|
return result || { rowIndex: -1, cellIndex: -1 };
|
|
79
75
|
}
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
function edgeCell(view, event, indexes) {
|
|
77
|
+
const found = view.posAtCoords({ left: event.clientX, top: event.clientY });
|
|
82
78
|
if (!found) {
|
|
83
79
|
return -1;
|
|
84
80
|
}
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
const $pos = view.state.doc.resolve(found.pos);
|
|
82
|
+
const parentTable = parentNode($pos, n => n.type.spec.tableRole === 'table');
|
|
87
83
|
if (parentTable === null) {
|
|
88
84
|
return -1;
|
|
89
85
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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];
|
|
94
90
|
return cell;
|
|
95
91
|
}
|
|
92
|
+
|
|
93
|
+
export { cellIndexes, domCellAround, edgeCell, getTable, otherResizeHandle, otherResizing, tableColumnResizeKey, tableResizeKey, tableRowResizeKey };
|
package/dist/es/source.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { DOMParser
|
|
1
|
+
import { DOMParser, Fragment } from 'prosemirror-model';
|
|
2
2
|
import { AllSelection } from 'prosemirror-state';
|
|
3
|
-
import {
|
|
4
|
-
import { DOMSerializer } from './DOMSerializer';
|
|
5
|
-
import { setStyleAttr } from './utils';
|
|
6
|
-
|
|
3
|
+
import { colgroupAttr, rowTypeAttr } from './config/constants.js';
|
|
4
|
+
import { DOMSerializer } from './DOMSerializer.js';
|
|
5
|
+
import { setStyleAttr } from './utils.js';
|
|
6
|
+
|
|
7
|
+
const blockWrappers = [
|
|
7
8
|
'div', 'ol', 'ul', 'li', 'table', 'tbody', 'thead', 'tfoot', 'caption', 'td', 'th', 'p',
|
|
8
9
|
'tr', 'col', 'colgroup', 'article', 'main', 'nav', 'header', 'footer', 'aside', 'section'
|
|
9
10
|
];
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Array.from(table.rows).filter(
|
|
11
|
+
const removeRowType = (table, nodeName) => {
|
|
12
|
+
const wrapper = (table.ownerDocument || document).createElement(nodeName);
|
|
13
|
+
Array.from(table.rows).filter(r => r.getAttribute(rowTypeAttr) === nodeName).forEach(row => {
|
|
13
14
|
row.removeAttribute(rowTypeAttr);
|
|
14
15
|
wrapper.appendChild(row);
|
|
15
16
|
});
|
|
@@ -17,33 +18,33 @@ var removeRowType = function (table, nodeName) {
|
|
|
17
18
|
table.appendChild(wrapper);
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
|
-
|
|
21
|
-
Array.from(fragment.querySelectorAll('table')).forEach(
|
|
21
|
+
const restoreTables = (fragment) => {
|
|
22
|
+
Array.from(fragment.querySelectorAll('table')).forEach((table) => {
|
|
22
23
|
removeRowType(table, 'thead');
|
|
23
24
|
removeRowType(table, 'tbody');
|
|
24
25
|
removeRowType(table, 'tfoot');
|
|
25
|
-
|
|
26
|
+
const emptyElement = Array.from(table.children).find(el => el.children.length === 0);
|
|
26
27
|
if (emptyElement) {
|
|
27
28
|
emptyElement.remove();
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
+
const wrapper = table.parentNode instanceof HTMLDivElement ? table.parentNode : null;
|
|
30
31
|
if (wrapper && wrapper.matches('div[table]')) {
|
|
31
32
|
table.style.marginLeft = wrapper.style.marginLeft;
|
|
32
33
|
table.style.marginRight = wrapper.style.marginRight;
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
34
|
+
const captionDiv = Array.from(wrapper.children).find(el => el.matches('div[caption]'));
|
|
35
|
+
if (captionDiv && captionDiv.innerHTML !== '<img>') {
|
|
36
|
+
const caption = table.createCaption();
|
|
37
|
+
if (captionDiv.id) {
|
|
38
|
+
caption.id = captionDiv.id;
|
|
38
39
|
}
|
|
39
|
-
if (
|
|
40
|
-
|
|
40
|
+
if (captionDiv.className) {
|
|
41
|
+
caption.className = captionDiv.className;
|
|
41
42
|
}
|
|
42
|
-
Array.from(
|
|
43
|
-
|
|
43
|
+
Array.from(captionDiv.style).forEach((styleName) => {
|
|
44
|
+
caption.style[styleName] = captionDiv.style[styleName];
|
|
44
45
|
});
|
|
45
|
-
while (
|
|
46
|
-
|
|
46
|
+
while (captionDiv.firstChild) {
|
|
47
|
+
caption.appendChild(captionDiv.firstChild);
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
if (wrapper.style.width && !table.style.width) {
|
|
@@ -54,10 +55,10 @@ var restoreTables = function (fragment) {
|
|
|
54
55
|
}
|
|
55
56
|
});
|
|
56
57
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
children.filter(
|
|
60
|
-
Array.from(rowsWrapper.children).forEach(
|
|
58
|
+
const setRowType = (children, nodeName) => {
|
|
59
|
+
const tag = nodeName.toUpperCase();
|
|
60
|
+
children.filter(c => c.nodeName === tag).forEach(rowsWrapper => {
|
|
61
|
+
Array.from(rowsWrapper.children).forEach(row => {
|
|
61
62
|
row.setAttribute(rowTypeAttr, nodeName);
|
|
62
63
|
if (rowsWrapper.parentNode) {
|
|
63
64
|
rowsWrapper.parentNode.insertBefore(row, rowsWrapper);
|
|
@@ -66,42 +67,42 @@ var setRowType = function (children, nodeName) {
|
|
|
66
67
|
rowsWrapper.remove();
|
|
67
68
|
});
|
|
68
69
|
};
|
|
69
|
-
|
|
70
|
-
Array.from(fragment.querySelectorAll('table')).forEach(
|
|
71
|
-
|
|
72
|
-
if (children.some(
|
|
70
|
+
const validateTablesToPmSchema = (fragment) => {
|
|
71
|
+
Array.from(fragment.querySelectorAll('table')).forEach((table) => {
|
|
72
|
+
const children = Array.from(table.children);
|
|
73
|
+
if (children.some(e => e.nodeName === 'THEAD' || e.nodeName === 'TFOOT')) {
|
|
73
74
|
setRowType(children, 'thead');
|
|
74
75
|
setRowType(children, 'tbody');
|
|
75
76
|
setRowType(children, 'tfoot');
|
|
76
77
|
}
|
|
77
|
-
|
|
78
|
+
const colgroup = children.find(c => c.nodeName === 'COLGROUP');
|
|
78
79
|
if (colgroup) {
|
|
79
80
|
table.setAttribute(colgroupAttr, colgroup.outerHTML);
|
|
80
81
|
colgroup.remove();
|
|
81
82
|
}
|
|
82
83
|
if (table.caption || table.style.marginLeft || table.style.marginRight) {
|
|
83
|
-
|
|
84
|
+
const wrapper = document.createElement('div');
|
|
84
85
|
wrapper.setAttribute('table', '');
|
|
85
86
|
wrapper.style.display = 'table';
|
|
86
87
|
wrapper.style.marginLeft = table.style.marginLeft;
|
|
87
88
|
wrapper.style.marginRight = table.style.marginRight;
|
|
88
89
|
if (table.caption) {
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
const captionDiv = document.createElement('div');
|
|
91
|
+
captionDiv.setAttribute('caption', '');
|
|
91
92
|
if (table.caption.id) {
|
|
92
|
-
|
|
93
|
+
captionDiv.id = table.caption.id;
|
|
93
94
|
}
|
|
94
95
|
if (table.caption.className) {
|
|
95
|
-
|
|
96
|
+
captionDiv.className = table.caption.className;
|
|
96
97
|
}
|
|
97
|
-
Array.from(table.caption.style).forEach(
|
|
98
|
-
|
|
98
|
+
Array.from(table.caption.style).forEach((styleName) => {
|
|
99
|
+
captionDiv.style[styleName] = table.caption.style[styleName];
|
|
99
100
|
});
|
|
100
101
|
while (table.caption.firstChild) {
|
|
101
|
-
|
|
102
|
+
captionDiv.appendChild(table.caption.firstChild);
|
|
102
103
|
}
|
|
103
104
|
table.removeChild(table.caption);
|
|
104
|
-
wrapper.appendChild(
|
|
105
|
+
wrapper.appendChild(captionDiv);
|
|
105
106
|
}
|
|
106
107
|
table.parentNode.insertBefore(wrapper, table);
|
|
107
108
|
wrapper.appendChild(table);
|
|
@@ -124,25 +125,24 @@ var validateTablesToPmSchema = function (fragment) {
|
|
|
124
125
|
*
|
|
125
126
|
* @returns The trimmed HTML content
|
|
126
127
|
*/
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
var tags = trimAroundTags.join('|');
|
|
128
|
+
const trimWhitespace = (html, trimAroundTags = blockWrappers) => {
|
|
129
|
+
const tags = trimAroundTags.join('|');
|
|
130
130
|
return html.replace(new RegExp('\\s*(<(?:' + tags + ')(?:\\s[^>]*?)?>)', 'g'), '$1')
|
|
131
131
|
.replace(new RegExp('(<\\/(?:' + tags + ')(?:\\s[^>]*?)?>)\\s*', 'g'), '$1');
|
|
132
132
|
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
const styleAttr = 'data-style';
|
|
134
|
+
const styleReplace = ' ' + styleAttr + '=';
|
|
135
|
+
const reTag = /<[^>]+>/gm;
|
|
136
|
+
const reStyle = /\sstyle=/gm;
|
|
137
|
+
const replacer = (match) => {
|
|
138
138
|
return match.replace(reStyle, styleReplace);
|
|
139
139
|
};
|
|
140
|
-
|
|
140
|
+
const replaceStyleAttr = (html) => {
|
|
141
141
|
return html.replace(reTag, replacer);
|
|
142
142
|
};
|
|
143
|
-
|
|
144
|
-
Array.from(container.querySelectorAll('[' + styleAttr + ']')).forEach(
|
|
145
|
-
|
|
143
|
+
const restoreStyleAttr = (container) => {
|
|
144
|
+
Array.from(container.querySelectorAll('[' + styleAttr + ']')).forEach((element) => {
|
|
145
|
+
const styleString = element.getAttribute(styleAttr);
|
|
146
146
|
element.removeAttribute(styleAttr);
|
|
147
147
|
setStyleAttr(element, styleString);
|
|
148
148
|
});
|
|
@@ -153,8 +153,8 @@ var restoreStyleAttr = function (container) {
|
|
|
153
153
|
* @param html
|
|
154
154
|
* @returns DocumentFragment
|
|
155
155
|
*/
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
const htmlToFragment = (html) => {
|
|
157
|
+
const template = document.createElement('template');
|
|
158
158
|
template.innerHTML = replaceStyleAttr(html);
|
|
159
159
|
restoreStyleAttr(template.content);
|
|
160
160
|
return template.content;
|
|
@@ -162,8 +162,8 @@ export var htmlToFragment = function (html) {
|
|
|
162
162
|
/**
|
|
163
163
|
* @hidden
|
|
164
164
|
*/
|
|
165
|
-
|
|
166
|
-
return Array.from(fragment.childNodes).reduce(
|
|
165
|
+
const fragmentToHtml = (fragment) => {
|
|
166
|
+
return Array.from(fragment.childNodes).reduce((acc, cur) => acc + (cur.outerHTML || cur.textContent || ''), '');
|
|
167
167
|
};
|
|
168
168
|
/**
|
|
169
169
|
* Creates a DocumentFragment from the given ProseMirrorNode.
|
|
@@ -171,8 +171,8 @@ export var fragmentToHtml = function (fragment) {
|
|
|
171
171
|
* @param doc ProseMirrorNode
|
|
172
172
|
* @returns DocumentFragment
|
|
173
173
|
*/
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
const pmDocToFragment = (doc) => {
|
|
175
|
+
const fragment = DOMSerializer.fromSchema(doc.type.schema).serializeFragment(doc.content);
|
|
176
176
|
restoreTables(fragment);
|
|
177
177
|
return fragment;
|
|
178
178
|
};
|
|
@@ -184,8 +184,8 @@ export var pmDocToFragment = function (doc) {
|
|
|
184
184
|
* @param parseOptions
|
|
185
185
|
* @returns ProseMirrorNode
|
|
186
186
|
*/
|
|
187
|
-
|
|
188
|
-
return
|
|
187
|
+
const domToPmDoc = (dom, schema, parseOptions) => {
|
|
188
|
+
return DOMParser.fromSchema(schema).parse(dom, parseOptions);
|
|
189
189
|
};
|
|
190
190
|
/**
|
|
191
191
|
* Creates a ProseMirrorNode from the given HTML content.
|
|
@@ -195,8 +195,8 @@ export var domToPmDoc = function (dom, schema, parseOptions) {
|
|
|
195
195
|
* @param parseOptions - ProseMirror parse options recognized by the `parse` and `parseSlice` methods.
|
|
196
196
|
* @returns - New ProseMirrorNode instance.
|
|
197
197
|
*/
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
const parseContent = (content, schema, parseOptions) => {
|
|
199
|
+
const dom = htmlToFragment(content);
|
|
200
200
|
validateTablesToPmSchema(dom);
|
|
201
201
|
return domToPmDoc(dom, schema, parseOptions);
|
|
202
202
|
};
|
|
@@ -206,8 +206,8 @@ export var parseContent = function (content, schema, parseOptions) {
|
|
|
206
206
|
* @param state - The Editor State
|
|
207
207
|
* @returns - The serialized content
|
|
208
208
|
*/
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
const getHtml = (state) => {
|
|
210
|
+
const fragment = pmDocToFragment(state.doc);
|
|
211
211
|
return fragmentToHtml(fragment);
|
|
212
212
|
};
|
|
213
213
|
/**
|
|
@@ -218,13 +218,17 @@ export var getHtml = function (state) {
|
|
|
218
218
|
* @param parseOptions - ProseMirror parse options recognized by the `parse` and `parseSlice` methods.
|
|
219
219
|
* @returns - Command function that takes an editor `state` and `dispatch` function.
|
|
220
220
|
*/
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
221
|
+
const setHtml = (content, command = 'setHTML', parseOptions = { preserveWhitespace: 'full' }) => (state, dispatch) => dispatch(state.tr
|
|
222
|
+
.setSelection(new AllSelection(state.doc))
|
|
223
|
+
.replaceSelectionWith(parseContent(content, state.schema, parseOptions))
|
|
224
|
+
.setMeta('commandName', command));
|
|
225
|
+
/**
|
|
226
|
+
* @hidden
|
|
227
|
+
*/
|
|
228
|
+
const hasSameMarkup = (dom1, dom2, schema, parseOptions) => {
|
|
229
|
+
const fragment1 = Fragment.from(parseContent(dom1, schema, parseOptions));
|
|
230
|
+
const fragment2 = Fragment.from(parseContent(dom2, schema, parseOptions));
|
|
231
|
+
return fragment1.eq(fragment2);
|
|
230
232
|
};
|
|
233
|
+
|
|
234
|
+
export { domToPmDoc, fragmentToHtml, getHtml, hasSameMarkup, htmlToFragment, parseContent, pmDocToFragment, setHtml, trimWhitespace };
|
package/dist/es/table.js
CHANGED
|
@@ -1,134 +1,132 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { colgroupAttr, rowTypeAttr } from './config/constants';
|
|
4
|
-
import { parseStrColgroup } from './config/schema';
|
|
1
|
+
import { addRowBefore as addRowBefore$1, addRowAfter as addRowAfter$1, addColumnBefore as addColumnBefore$1, addColumnAfter as addColumnAfter$1, deleteColumn as deleteColumn$1, TableMap } from 'prosemirror-tables';
|
|
2
|
+
export { addColumnAfter as pmAddColumnAfter, addColumnBefore as pmAddColumnBefore, addRowAfter as pmAddRowAfter, addRowBefore as pmAddRowBefore, deleteColumn as pmDeleteColumn } from 'prosemirror-tables';
|
|
3
|
+
import { colgroupAttr, rowTypeAttr } from './config/constants.js';
|
|
4
|
+
import { parseStrColgroup } from './config/schema.js';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Creates a table.
|
|
7
8
|
*
|
|
8
9
|
* @returns Node
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
for (
|
|
11
|
+
const createTable = (nodes, rows, columns) => {
|
|
12
|
+
const { table, table_row, table_cell } = nodes;
|
|
13
|
+
const tableRows = [];
|
|
14
|
+
let cells;
|
|
15
|
+
for (let r = 0; r < rows + 1; r++) {
|
|
15
16
|
cells = [];
|
|
16
|
-
for (
|
|
17
|
+
for (let c = 0; c < columns + 1; c++) {
|
|
17
18
|
cells.push(table_cell.createAndFill());
|
|
18
19
|
}
|
|
19
20
|
tableRows.push(table_row.createAndFill(undefined, cells));
|
|
20
21
|
}
|
|
21
22
|
return table.createAndFill(undefined, tableRows);
|
|
22
23
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (
|
|
29
|
-
|
|
24
|
+
const reTable = /^table$/;
|
|
25
|
+
const reRow = /^table_row$/;
|
|
26
|
+
const reCell = /^table_cell|table_header$/;
|
|
27
|
+
const closest = (selection, name) => {
|
|
28
|
+
const pos = selection.$head;
|
|
29
|
+
for (let i = pos.depth; i > 0; i--) {
|
|
30
|
+
const node = pos.node(i);
|
|
30
31
|
if (name.test(node.type.name)) {
|
|
31
32
|
return {
|
|
32
33
|
pos: pos.before(i),
|
|
33
|
-
node
|
|
34
|
+
node
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
return null;
|
|
38
39
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var table = closest(tr.selection, reTable);
|
|
40
|
+
const addRowBefore = (state, dispatch) => {
|
|
41
|
+
const cmdDispatch = dispatch && (tr => {
|
|
42
|
+
const row = closest(tr.selection, reRow);
|
|
43
|
+
const table = closest(tr.selection, reTable);
|
|
44
44
|
if (row && table && row.node.attrs[rowTypeAttr]) {
|
|
45
|
-
|
|
46
|
-
for (
|
|
45
|
+
let index = 0;
|
|
46
|
+
for (let i = 0; i < table.node.nodeSize; i++) {
|
|
47
47
|
if (table.node.child(i).eq(row.node)) {
|
|
48
48
|
index = i;
|
|
49
49
|
break;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
tr.setNodeMarkup(from, undefined,
|
|
52
|
+
const next = table.node.child(index - 1);
|
|
53
|
+
const from = row.pos - next.nodeSize;
|
|
54
|
+
tr.setNodeMarkup(from, undefined, { [rowTypeAttr]: row.node.attrs[rowTypeAttr] });
|
|
55
55
|
}
|
|
56
56
|
return dispatch(tr);
|
|
57
57
|
});
|
|
58
|
-
return
|
|
58
|
+
return addRowBefore$1(state, cmdDispatch);
|
|
59
59
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var row = closest(tr.selection, reRow);
|
|
60
|
+
const addRowAfter = (state, dispatch) => {
|
|
61
|
+
const cmdDispatch = dispatch && (tr => {
|
|
62
|
+
const row = closest(tr.selection, reRow);
|
|
64
63
|
if (row && row.node.attrs[rowTypeAttr]) {
|
|
65
|
-
|
|
66
|
-
tr.setNodeMarkup(from, undefined,
|
|
64
|
+
const from = row.pos + row.node.nodeSize;
|
|
65
|
+
tr.setNodeMarkup(from, undefined, { [rowTypeAttr]: row.node.attrs[rowTypeAttr] });
|
|
67
66
|
}
|
|
68
67
|
return dispatch(tr);
|
|
69
68
|
});
|
|
70
|
-
return
|
|
69
|
+
return addRowAfter$1(state, cmdDispatch);
|
|
71
70
|
};
|
|
72
|
-
|
|
71
|
+
const columnIndex = (table, selection) => {
|
|
73
72
|
if (!table) {
|
|
74
73
|
return -1;
|
|
75
74
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
const map = TableMap.get(table.node);
|
|
76
|
+
const tableCell = closest(selection, reCell);
|
|
77
|
+
const idx = map.map.indexOf(tableCell.pos - table.pos - 1);
|
|
78
|
+
let colIndex = -1;
|
|
80
79
|
if (idx !== -1) {
|
|
81
80
|
colIndex = idx % map.width;
|
|
82
81
|
}
|
|
83
82
|
return colIndex;
|
|
84
83
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
var colgroup = parseStrColgroup(table.node.attrs[colgroupAttr]);
|
|
84
|
+
const addCol = (tr, table, to) => {
|
|
85
|
+
const colIndex = columnIndex(table, tr.selection);
|
|
86
|
+
const colgroup = parseStrColgroup(table.node.attrs[colgroupAttr]);
|
|
89
87
|
colgroup.insertBefore(colgroup.ownerDocument.createElement('col'), colgroup.children[colIndex + to]);
|
|
90
|
-
tr.setNodeMarkup(table.pos, null,
|
|
88
|
+
tr.setNodeMarkup(table.pos, null, { ...table.node.attrs, [colgroupAttr]: colgroup.outerHTML });
|
|
91
89
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
var colgroup = parseStrColgroup(table.node.attrs[colgroupAttr]);
|
|
90
|
+
const deleteCol = (tr, table, colIndex) => {
|
|
91
|
+
const colgroup = parseStrColgroup(table.node.attrs[colgroupAttr]);
|
|
95
92
|
colgroup.removeChild(colgroup.children[colIndex]);
|
|
96
|
-
tr.setNodeMarkup(table.pos, null,
|
|
93
|
+
tr.setNodeMarkup(table.pos, null, { ...table.node.attrs, [colgroupAttr]: colgroup.outerHTML });
|
|
97
94
|
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
const addColumnBefore = (state, dispatch) => {
|
|
96
|
+
const cmdDispatch = dispatch && (tr => {
|
|
97
|
+
const table = closest(tr.selection, reTable);
|
|
101
98
|
if (!table.node.attrs[colgroupAttr]) {
|
|
102
99
|
return dispatch(tr);
|
|
103
100
|
}
|
|
104
101
|
addCol(tr, table, -1);
|
|
105
102
|
return dispatch(tr);
|
|
106
103
|
});
|
|
107
|
-
return
|
|
104
|
+
return addColumnBefore$1(state, cmdDispatch);
|
|
108
105
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
106
|
+
const addColumnAfter = (state, dispatch) => {
|
|
107
|
+
const cmdDispatch = dispatch && (tr => {
|
|
108
|
+
const table = closest(tr.selection, reTable);
|
|
112
109
|
if (!table.node.attrs[colgroupAttr]) {
|
|
113
110
|
return dispatch(tr);
|
|
114
111
|
}
|
|
115
112
|
addCol(tr, table, 1);
|
|
116
113
|
return dispatch(tr);
|
|
117
114
|
});
|
|
118
|
-
return
|
|
115
|
+
return addColumnAfter$1(state, cmdDispatch);
|
|
119
116
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
117
|
+
const deleteColumn = (state, dispatch) => {
|
|
118
|
+
const parentTable = closest(state.selection, reTable);
|
|
119
|
+
const colgroup = parentTable && parentTable.node.attrs[colgroupAttr];
|
|
120
|
+
const colIndex = columnIndex(parentTable, state.selection);
|
|
121
|
+
const cmdDispatch = dispatch && ((tr) => {
|
|
125
122
|
if (!colgroup) {
|
|
126
123
|
return dispatch(tr);
|
|
127
124
|
}
|
|
128
|
-
|
|
125
|
+
const table = tr.doc.nodeAt(parentTable.pos);
|
|
129
126
|
deleteCol(tr, { node: table, pos: parentTable.pos }, colIndex);
|
|
130
127
|
return dispatch(tr);
|
|
131
128
|
});
|
|
132
|
-
return
|
|
129
|
+
return deleteColumn$1(state, cmdDispatch);
|
|
133
130
|
};
|
|
134
|
-
|
|
131
|
+
|
|
132
|
+
export { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, createTable, deleteColumn };
|
package/dist/es/text.js
CHANGED