@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,60 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var prosemirrorState = require('prosemirror-state');
|
|
4
|
+
var prosemirrorTables = require('prosemirror-tables');
|
|
5
|
+
var utils = require('../../utils.js');
|
|
6
|
+
|
|
7
|
+
const tableResizeKey = new prosemirrorState.PluginKey('table-resize');
|
|
8
|
+
const tableColumnResizeKey = new prosemirrorState.PluginKey('table-column-resizing');
|
|
9
|
+
const tableRowResizeKey = new prosemirrorState.PluginKey('table-row-resizing');
|
|
10
10
|
function otherResizing(current, state) {
|
|
11
|
-
|
|
11
|
+
let activeResize = false;
|
|
12
12
|
activeResize = activeResize ||
|
|
13
|
-
(current !==
|
|
13
|
+
(current !== tableResizeKey && Boolean(tableResizeKey.get(state)) && tableResizeKey.getState(state).dragging);
|
|
14
14
|
activeResize = activeResize ||
|
|
15
|
-
(current !==
|
|
15
|
+
(current !== tableColumnResizeKey && Boolean(tableColumnResizeKey.get(state)) && tableColumnResizeKey.getState(state).dragging);
|
|
16
16
|
activeResize = activeResize ||
|
|
17
|
-
(current !==
|
|
17
|
+
(current !== tableRowResizeKey && Boolean(tableRowResizeKey.get(state)) && tableRowResizeKey.getState(state).dragging);
|
|
18
18
|
return activeResize;
|
|
19
19
|
}
|
|
20
|
-
exports.otherResizing = otherResizing;
|
|
21
20
|
function otherResizeHandle(current, state) {
|
|
22
|
-
|
|
21
|
+
let activeResize = false;
|
|
23
22
|
activeResize = activeResize ||
|
|
24
|
-
(current !==
|
|
25
|
-
Boolean(
|
|
26
|
-
|
|
23
|
+
(current !== tableColumnResizeKey &&
|
|
24
|
+
Boolean(tableColumnResizeKey.get(state)) &&
|
|
25
|
+
tableColumnResizeKey.getState(state).activeHandle > -1);
|
|
27
26
|
activeResize = activeResize ||
|
|
28
|
-
(current !==
|
|
27
|
+
(current !== tableRowResizeKey && Boolean(tableRowResizeKey.get(state)) && tableRowResizeKey.getState(state).activeHandle > -1);
|
|
29
28
|
return activeResize;
|
|
30
29
|
}
|
|
31
|
-
exports.otherResizeHandle = otherResizeHandle;
|
|
32
30
|
function getTable(dom) {
|
|
33
31
|
if (dom && dom.firstChild && dom.firstChild.nodeName === 'TABLE') {
|
|
34
32
|
return dom.firstChild;
|
|
35
33
|
}
|
|
36
34
|
return dom;
|
|
37
35
|
}
|
|
38
|
-
exports.getTable = getTable;
|
|
39
36
|
function domCellAround(target) {
|
|
40
37
|
while (target && target.nodeName !== 'TD' && target.nodeName !== 'TH') {
|
|
41
38
|
target = target.classList.contains('ProseMirror') ? null : target.parentNode;
|
|
42
39
|
}
|
|
43
40
|
return target;
|
|
44
41
|
}
|
|
45
|
-
exports.domCellAround = domCellAround;
|
|
46
42
|
function tableSpansMap(table) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
.map(
|
|
50
|
-
.reduce(
|
|
51
|
-
|
|
52
|
-
rows.forEach(
|
|
53
|
-
|
|
54
|
-
Array.from(row.cells).forEach(
|
|
55
|
-
for (
|
|
56
|
-
for (
|
|
57
|
-
|
|
43
|
+
const rows = Array.from((table && table.rows) || []);
|
|
44
|
+
const colsCount = Array.from((rows && rows[0] && rows[0].cells) || [])
|
|
45
|
+
.map(c => c.colSpan)
|
|
46
|
+
.reduce((prev, cur) => prev + cur, 0);
|
|
47
|
+
const map = rows.map(() => new Array(colsCount));
|
|
48
|
+
rows.forEach((row, r) => {
|
|
49
|
+
let curColSpan = 0;
|
|
50
|
+
Array.from(row.cells).forEach((c) => {
|
|
51
|
+
for (let colSp = 0; colSp < c.colSpan; colSp++) {
|
|
52
|
+
for (let rowSp = 0; rowSp < c.rowSpan; rowSp++) {
|
|
53
|
+
const ind = map[r + rowSp].findIndex((val, curInd) => curInd >= curColSpan && !val);
|
|
58
54
|
map[r + rowSp][ind] = c;
|
|
59
55
|
}
|
|
60
56
|
curColSpan++;
|
|
@@ -64,41 +60,44 @@ function tableSpansMap(table) {
|
|
|
64
60
|
return map;
|
|
65
61
|
}
|
|
66
62
|
function cellIndexes(dataCell) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
row.forEach(
|
|
63
|
+
const map = tableSpansMap(dataCell.closest('table'));
|
|
64
|
+
let result = null;
|
|
65
|
+
for (let r = 0; r < map.length; r++) {
|
|
66
|
+
const row = map[r];
|
|
67
|
+
row.forEach((cell, c) => {
|
|
72
68
|
if (dataCell === cell) {
|
|
73
69
|
result = { rowIndex: r, cellIndex: c };
|
|
74
70
|
}
|
|
75
71
|
});
|
|
76
72
|
if (result) {
|
|
77
|
-
return "break";
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
for (var r = 0; r < map.length; r++) {
|
|
81
|
-
var state_1 = _loop_1(r);
|
|
82
|
-
if (state_1 === "break")
|
|
83
73
|
break;
|
|
74
|
+
}
|
|
84
75
|
}
|
|
85
76
|
return result || { rowIndex: -1, cellIndex: -1 };
|
|
86
77
|
}
|
|
87
|
-
exports.cellIndexes = cellIndexes;
|
|
88
78
|
function edgeCell(view, event, indexes) {
|
|
89
|
-
|
|
79
|
+
const found = view.posAtCoords({ left: event.clientX, top: event.clientY });
|
|
90
80
|
if (!found) {
|
|
91
81
|
return -1;
|
|
92
82
|
}
|
|
93
|
-
|
|
94
|
-
|
|
83
|
+
const $pos = view.state.doc.resolve(found.pos);
|
|
84
|
+
const parentTable = utils.parentNode($pos, n => n.type.spec.tableRole === 'table');
|
|
95
85
|
if (parentTable === null) {
|
|
96
86
|
return -1;
|
|
97
87
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
88
|
+
const tablePos = $pos.start(parentTable.depth);
|
|
89
|
+
const tableNode = parentTable.node;
|
|
90
|
+
const map = prosemirrorTables.TableMap.get(tableNode);
|
|
91
|
+
const cell = tablePos + map.map[(map.width * indexes.rowIndex) + indexes.cellIndex];
|
|
102
92
|
return cell;
|
|
103
93
|
}
|
|
94
|
+
|
|
95
|
+
exports.cellIndexes = cellIndexes;
|
|
96
|
+
exports.domCellAround = domCellAround;
|
|
104
97
|
exports.edgeCell = edgeCell;
|
|
98
|
+
exports.getTable = getTable;
|
|
99
|
+
exports.otherResizeHandle = otherResizeHandle;
|
|
100
|
+
exports.otherResizing = otherResizing;
|
|
101
|
+
exports.tableColumnResizeKey = tableColumnResizeKey;
|
|
102
|
+
exports.tableResizeKey = tableResizeKey;
|
|
103
|
+
exports.tableRowResizeKey = tableRowResizeKey;
|
package/dist/npm/source.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Node as Node$1, Schema, ParseOptions } from 'prosemirror-model';
|
|
2
2
|
import { EditorState } from 'prosemirror-state';
|
|
3
|
-
import { Command } from './types/command';
|
|
3
|
+
import { Command } from './types/command.js';
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Trims the whitespace around the provided block nodes.
|
|
6
7
|
*
|
|
@@ -13,25 +14,25 @@ import { Command } from './types/command';
|
|
|
13
14
|
*
|
|
14
15
|
* @returns The trimmed HTML content
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
+
declare const trimWhitespace: (html: string, trimAroundTags?: string[]) => string;
|
|
17
18
|
/**
|
|
18
19
|
* Creates a DocumentFragment from the given HTML content.
|
|
19
20
|
*
|
|
20
21
|
* @param html
|
|
21
22
|
* @returns DocumentFragment
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
+
declare const htmlToFragment: (html: string) => DocumentFragment;
|
|
24
25
|
/**
|
|
25
26
|
* @hidden
|
|
26
27
|
*/
|
|
27
|
-
|
|
28
|
+
declare const fragmentToHtml: (fragment: DocumentFragment) => string;
|
|
28
29
|
/**
|
|
29
30
|
* Creates a DocumentFragment from the given ProseMirrorNode.
|
|
30
31
|
*
|
|
31
32
|
* @param doc ProseMirrorNode
|
|
32
33
|
* @returns DocumentFragment
|
|
33
34
|
*/
|
|
34
|
-
|
|
35
|
+
declare const pmDocToFragment: (doc: Node$1) => DocumentFragment;
|
|
35
36
|
/**
|
|
36
37
|
* Creates a ProseMirrorNode from the given DOM element.
|
|
37
38
|
*
|
|
@@ -40,7 +41,7 @@ export declare const pmDocToFragment: (doc: ProseMirrorNode) => DocumentFragment
|
|
|
40
41
|
* @param parseOptions
|
|
41
42
|
* @returns ProseMirrorNode
|
|
42
43
|
*/
|
|
43
|
-
|
|
44
|
+
declare const domToPmDoc: (dom: Node, schema: Schema, parseOptions: ParseOptions) => Node$1;
|
|
44
45
|
/**
|
|
45
46
|
* Creates a ProseMirrorNode from the given HTML content.
|
|
46
47
|
*
|
|
@@ -49,15 +50,15 @@ export declare const domToPmDoc: (dom: Node, schema: Schema, parseOptions: Parse
|
|
|
49
50
|
* @param parseOptions - ProseMirror parse options recognized by the `parse` and `parseSlice` methods.
|
|
50
51
|
* @returns - New ProseMirrorNode instance.
|
|
51
52
|
*/
|
|
52
|
-
|
|
53
|
+
declare const parseContent: (content: string, schema: Schema, parseOptions?: ParseOptions) => Node$1;
|
|
53
54
|
/**
|
|
54
55
|
* A function that serializes the Editor State content as HTML string.
|
|
55
56
|
*
|
|
56
57
|
* @param state - The Editor State
|
|
57
58
|
* @returns - The serialized content
|
|
58
59
|
*/
|
|
59
|
-
|
|
60
|
-
doc:
|
|
60
|
+
declare const getHtml: (state: EditorState | {
|
|
61
|
+
doc: Node$1;
|
|
61
62
|
}) => string;
|
|
62
63
|
/**
|
|
63
64
|
* Replaces the content of the editor with a new one.
|
|
@@ -67,4 +68,10 @@ export declare const getHtml: (state: EditorState | {
|
|
|
67
68
|
* @param parseOptions - ProseMirror parse options recognized by the `parse` and `parseSlice` methods.
|
|
68
69
|
* @returns - Command function that takes an editor `state` and `dispatch` function.
|
|
69
70
|
*/
|
|
70
|
-
|
|
71
|
+
declare const setHtml: (content: string, command?: string, parseOptions?: ParseOptions) => Command;
|
|
72
|
+
/**
|
|
73
|
+
* @hidden
|
|
74
|
+
*/
|
|
75
|
+
declare const hasSameMarkup: (dom1: string, dom2: string, schema: Schema, parseOptions?: ParseOptions) => boolean;
|
|
76
|
+
|
|
77
|
+
export { domToPmDoc, fragmentToHtml, getHtml, hasSameMarkup, htmlToFragment, parseContent, pmDocToFragment, setHtml, trimWhitespace };
|
package/dist/npm/source.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var prosemirrorModel = require('prosemirror-model');
|
|
4
|
+
var prosemirrorState = require('prosemirror-state');
|
|
5
|
+
var constants = require('./config/constants.js');
|
|
6
|
+
var DOMSerializer = require('./DOMSerializer.js');
|
|
7
|
+
var utils = require('./utils.js');
|
|
8
|
+
|
|
9
|
+
const blockWrappers = [
|
|
10
10
|
'div', 'ol', 'ul', 'li', 'table', 'tbody', 'thead', 'tfoot', 'caption', 'td', 'th', 'p',
|
|
11
11
|
'tr', 'col', 'colgroup', 'article', 'main', 'nav', 'header', 'footer', 'aside', 'section'
|
|
12
12
|
];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Array.from(table.rows).filter(
|
|
16
|
-
row.removeAttribute(
|
|
13
|
+
const removeRowType = (table, nodeName) => {
|
|
14
|
+
const wrapper = (table.ownerDocument || document).createElement(nodeName);
|
|
15
|
+
Array.from(table.rows).filter(r => r.getAttribute(constants.rowTypeAttr) === nodeName).forEach(row => {
|
|
16
|
+
row.removeAttribute(constants.rowTypeAttr);
|
|
17
17
|
wrapper.appendChild(row);
|
|
18
18
|
});
|
|
19
19
|
if (wrapper.children.length) {
|
|
20
20
|
table.appendChild(wrapper);
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
|
-
|
|
24
|
-
Array.from(fragment.querySelectorAll('table')).forEach(
|
|
23
|
+
const restoreTables = (fragment) => {
|
|
24
|
+
Array.from(fragment.querySelectorAll('table')).forEach((table) => {
|
|
25
25
|
removeRowType(table, 'thead');
|
|
26
26
|
removeRowType(table, 'tbody');
|
|
27
27
|
removeRowType(table, 'tfoot');
|
|
28
|
-
|
|
28
|
+
const emptyElement = Array.from(table.children).find(el => el.children.length === 0);
|
|
29
29
|
if (emptyElement) {
|
|
30
30
|
emptyElement.remove();
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
const wrapper = table.parentNode instanceof HTMLDivElement ? table.parentNode : null;
|
|
33
33
|
if (wrapper && wrapper.matches('div[table]')) {
|
|
34
34
|
table.style.marginLeft = wrapper.style.marginLeft;
|
|
35
35
|
table.style.marginRight = wrapper.style.marginRight;
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
|
|
36
|
+
const captionDiv = Array.from(wrapper.children).find(el => el.matches('div[caption]'));
|
|
37
|
+
if (captionDiv && captionDiv.innerHTML !== '<img>') {
|
|
38
|
+
const caption = table.createCaption();
|
|
39
|
+
if (captionDiv.id) {
|
|
40
|
+
caption.id = captionDiv.id;
|
|
41
41
|
}
|
|
42
|
-
if (
|
|
43
|
-
|
|
42
|
+
if (captionDiv.className) {
|
|
43
|
+
caption.className = captionDiv.className;
|
|
44
44
|
}
|
|
45
|
-
Array.from(
|
|
46
|
-
|
|
45
|
+
Array.from(captionDiv.style).forEach((styleName) => {
|
|
46
|
+
caption.style[styleName] = captionDiv.style[styleName];
|
|
47
47
|
});
|
|
48
|
-
while (
|
|
49
|
-
|
|
48
|
+
while (captionDiv.firstChild) {
|
|
49
|
+
caption.appendChild(captionDiv.firstChild);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
if (wrapper.style.width && !table.style.width) {
|
|
@@ -57,11 +57,11 @@ var restoreTables = function (fragment) {
|
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
children.filter(
|
|
63
|
-
Array.from(rowsWrapper.children).forEach(
|
|
64
|
-
row.setAttribute(
|
|
60
|
+
const setRowType = (children, nodeName) => {
|
|
61
|
+
const tag = nodeName.toUpperCase();
|
|
62
|
+
children.filter(c => c.nodeName === tag).forEach(rowsWrapper => {
|
|
63
|
+
Array.from(rowsWrapper.children).forEach(row => {
|
|
64
|
+
row.setAttribute(constants.rowTypeAttr, nodeName);
|
|
65
65
|
if (rowsWrapper.parentNode) {
|
|
66
66
|
rowsWrapper.parentNode.insertBefore(row, rowsWrapper);
|
|
67
67
|
}
|
|
@@ -69,42 +69,42 @@ var setRowType = function (children, nodeName) {
|
|
|
69
69
|
rowsWrapper.remove();
|
|
70
70
|
});
|
|
71
71
|
};
|
|
72
|
-
|
|
73
|
-
Array.from(fragment.querySelectorAll('table')).forEach(
|
|
74
|
-
|
|
75
|
-
if (children.some(
|
|
72
|
+
const validateTablesToPmSchema = (fragment) => {
|
|
73
|
+
Array.from(fragment.querySelectorAll('table')).forEach((table) => {
|
|
74
|
+
const children = Array.from(table.children);
|
|
75
|
+
if (children.some(e => e.nodeName === 'THEAD' || e.nodeName === 'TFOOT')) {
|
|
76
76
|
setRowType(children, 'thead');
|
|
77
77
|
setRowType(children, 'tbody');
|
|
78
78
|
setRowType(children, 'tfoot');
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
const colgroup = children.find(c => c.nodeName === 'COLGROUP');
|
|
81
81
|
if (colgroup) {
|
|
82
|
-
table.setAttribute(
|
|
82
|
+
table.setAttribute(constants.colgroupAttr, colgroup.outerHTML);
|
|
83
83
|
colgroup.remove();
|
|
84
84
|
}
|
|
85
85
|
if (table.caption || table.style.marginLeft || table.style.marginRight) {
|
|
86
|
-
|
|
86
|
+
const wrapper = document.createElement('div');
|
|
87
87
|
wrapper.setAttribute('table', '');
|
|
88
88
|
wrapper.style.display = 'table';
|
|
89
89
|
wrapper.style.marginLeft = table.style.marginLeft;
|
|
90
90
|
wrapper.style.marginRight = table.style.marginRight;
|
|
91
91
|
if (table.caption) {
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
const captionDiv = document.createElement('div');
|
|
93
|
+
captionDiv.setAttribute('caption', '');
|
|
94
94
|
if (table.caption.id) {
|
|
95
|
-
|
|
95
|
+
captionDiv.id = table.caption.id;
|
|
96
96
|
}
|
|
97
97
|
if (table.caption.className) {
|
|
98
|
-
|
|
98
|
+
captionDiv.className = table.caption.className;
|
|
99
99
|
}
|
|
100
|
-
Array.from(table.caption.style).forEach(
|
|
101
|
-
|
|
100
|
+
Array.from(table.caption.style).forEach((styleName) => {
|
|
101
|
+
captionDiv.style[styleName] = table.caption.style[styleName];
|
|
102
102
|
});
|
|
103
103
|
while (table.caption.firstChild) {
|
|
104
|
-
|
|
104
|
+
captionDiv.appendChild(table.caption.firstChild);
|
|
105
105
|
}
|
|
106
106
|
table.removeChild(table.caption);
|
|
107
|
-
wrapper.appendChild(
|
|
107
|
+
wrapper.appendChild(captionDiv);
|
|
108
108
|
}
|
|
109
109
|
table.parentNode.insertBefore(wrapper, table);
|
|
110
110
|
wrapper.appendChild(table);
|
|
@@ -127,28 +127,26 @@ var validateTablesToPmSchema = function (fragment) {
|
|
|
127
127
|
*
|
|
128
128
|
* @returns The trimmed HTML content
|
|
129
129
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
var tags = trimAroundTags.join('|');
|
|
130
|
+
const trimWhitespace = (html, trimAroundTags = blockWrappers) => {
|
|
131
|
+
const tags = trimAroundTags.join('|');
|
|
133
132
|
return html.replace(new RegExp('\\s*(<(?:' + tags + ')(?:\\s[^>]*?)?>)', 'g'), '$1')
|
|
134
133
|
.replace(new RegExp('(<\\/(?:' + tags + ')(?:\\s[^>]*?)?>)\\s*', 'g'), '$1');
|
|
135
134
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
var replacer = function (match) {
|
|
135
|
+
const styleAttr = 'data-style';
|
|
136
|
+
const styleReplace = ' ' + styleAttr + '=';
|
|
137
|
+
const reTag = /<[^>]+>/gm;
|
|
138
|
+
const reStyle = /\sstyle=/gm;
|
|
139
|
+
const replacer = (match) => {
|
|
142
140
|
return match.replace(reStyle, styleReplace);
|
|
143
141
|
};
|
|
144
|
-
|
|
142
|
+
const replaceStyleAttr = (html) => {
|
|
145
143
|
return html.replace(reTag, replacer);
|
|
146
144
|
};
|
|
147
|
-
|
|
148
|
-
Array.from(container.querySelectorAll('[' + styleAttr + ']')).forEach(
|
|
149
|
-
|
|
145
|
+
const restoreStyleAttr = (container) => {
|
|
146
|
+
Array.from(container.querySelectorAll('[' + styleAttr + ']')).forEach((element) => {
|
|
147
|
+
const styleString = element.getAttribute(styleAttr);
|
|
150
148
|
element.removeAttribute(styleAttr);
|
|
151
|
-
|
|
149
|
+
utils.setStyleAttr(element, styleString);
|
|
152
150
|
});
|
|
153
151
|
};
|
|
154
152
|
/**
|
|
@@ -157,32 +155,29 @@ var restoreStyleAttr = function (container) {
|
|
|
157
155
|
* @param html
|
|
158
156
|
* @returns DocumentFragment
|
|
159
157
|
*/
|
|
160
|
-
|
|
161
|
-
|
|
158
|
+
const htmlToFragment = (html) => {
|
|
159
|
+
const template = document.createElement('template');
|
|
162
160
|
template.innerHTML = replaceStyleAttr(html);
|
|
163
161
|
restoreStyleAttr(template.content);
|
|
164
162
|
return template.content;
|
|
165
163
|
};
|
|
166
|
-
exports.htmlToFragment = htmlToFragment;
|
|
167
164
|
/**
|
|
168
165
|
* @hidden
|
|
169
166
|
*/
|
|
170
|
-
|
|
171
|
-
return Array.from(fragment.childNodes).reduce(
|
|
167
|
+
const fragmentToHtml = (fragment) => {
|
|
168
|
+
return Array.from(fragment.childNodes).reduce((acc, cur) => acc + (cur.outerHTML || cur.textContent || ''), '');
|
|
172
169
|
};
|
|
173
|
-
exports.fragmentToHtml = fragmentToHtml;
|
|
174
170
|
/**
|
|
175
171
|
* Creates a DocumentFragment from the given ProseMirrorNode.
|
|
176
172
|
*
|
|
177
173
|
* @param doc ProseMirrorNode
|
|
178
174
|
* @returns DocumentFragment
|
|
179
175
|
*/
|
|
180
|
-
|
|
181
|
-
|
|
176
|
+
const pmDocToFragment = (doc) => {
|
|
177
|
+
const fragment = DOMSerializer.DOMSerializer.fromSchema(doc.type.schema).serializeFragment(doc.content);
|
|
182
178
|
restoreTables(fragment);
|
|
183
179
|
return fragment;
|
|
184
180
|
};
|
|
185
|
-
exports.pmDocToFragment = pmDocToFragment;
|
|
186
181
|
/**
|
|
187
182
|
* Creates a ProseMirrorNode from the given DOM element.
|
|
188
183
|
*
|
|
@@ -191,10 +186,9 @@ exports.pmDocToFragment = pmDocToFragment;
|
|
|
191
186
|
* @param parseOptions
|
|
192
187
|
* @returns ProseMirrorNode
|
|
193
188
|
*/
|
|
194
|
-
|
|
195
|
-
return
|
|
189
|
+
const domToPmDoc = (dom, schema, parseOptions) => {
|
|
190
|
+
return prosemirrorModel.DOMParser.fromSchema(schema).parse(dom, parseOptions);
|
|
196
191
|
};
|
|
197
|
-
exports.domToPmDoc = domToPmDoc;
|
|
198
192
|
/**
|
|
199
193
|
* Creates a ProseMirrorNode from the given HTML content.
|
|
200
194
|
*
|
|
@@ -203,23 +197,21 @@ exports.domToPmDoc = domToPmDoc;
|
|
|
203
197
|
* @param parseOptions - ProseMirror parse options recognized by the `parse` and `parseSlice` methods.
|
|
204
198
|
* @returns - New ProseMirrorNode instance.
|
|
205
199
|
*/
|
|
206
|
-
|
|
207
|
-
|
|
200
|
+
const parseContent = (content, schema, parseOptions) => {
|
|
201
|
+
const dom = htmlToFragment(content);
|
|
208
202
|
validateTablesToPmSchema(dom);
|
|
209
|
-
return
|
|
203
|
+
return domToPmDoc(dom, schema, parseOptions);
|
|
210
204
|
};
|
|
211
|
-
exports.parseContent = parseContent;
|
|
212
205
|
/**
|
|
213
206
|
* A function that serializes the Editor State content as HTML string.
|
|
214
207
|
*
|
|
215
208
|
* @param state - The Editor State
|
|
216
209
|
* @returns - The serialized content
|
|
217
210
|
*/
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return
|
|
211
|
+
const getHtml = (state) => {
|
|
212
|
+
const fragment = pmDocToFragment(state.doc);
|
|
213
|
+
return fragmentToHtml(fragment);
|
|
221
214
|
};
|
|
222
|
-
exports.getHtml = getHtml;
|
|
223
215
|
/**
|
|
224
216
|
* Replaces the content of the editor with a new one.
|
|
225
217
|
*
|
|
@@ -228,14 +220,25 @@ exports.getHtml = getHtml;
|
|
|
228
220
|
* @param parseOptions - ProseMirror parse options recognized by the `parse` and `parseSlice` methods.
|
|
229
221
|
* @returns - Command function that takes an editor `state` and `dispatch` function.
|
|
230
222
|
*/
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
223
|
+
const setHtml = (content, command = 'setHTML', parseOptions = { preserveWhitespace: 'full' }) => (state, dispatch) => dispatch(state.tr
|
|
224
|
+
.setSelection(new prosemirrorState.AllSelection(state.doc))
|
|
225
|
+
.replaceSelectionWith(parseContent(content, state.schema, parseOptions))
|
|
226
|
+
.setMeta('commandName', command));
|
|
227
|
+
/**
|
|
228
|
+
* @hidden
|
|
229
|
+
*/
|
|
230
|
+
const hasSameMarkup = (dom1, dom2, schema, parseOptions) => {
|
|
231
|
+
const fragment1 = prosemirrorModel.Fragment.from(parseContent(dom1, schema, parseOptions));
|
|
232
|
+
const fragment2 = prosemirrorModel.Fragment.from(parseContent(dom2, schema, parseOptions));
|
|
233
|
+
return fragment1.eq(fragment2);
|
|
240
234
|
};
|
|
235
|
+
|
|
236
|
+
exports.domToPmDoc = domToPmDoc;
|
|
237
|
+
exports.fragmentToHtml = fragmentToHtml;
|
|
238
|
+
exports.getHtml = getHtml;
|
|
239
|
+
exports.hasSameMarkup = hasSameMarkup;
|
|
240
|
+
exports.htmlToFragment = htmlToFragment;
|
|
241
|
+
exports.parseContent = parseContent;
|
|
242
|
+
exports.pmDocToFragment = pmDocToFragment;
|
|
241
243
|
exports.setHtml = setHtml;
|
|
244
|
+
exports.trimWhitespace = trimWhitespace;
|
package/dist/npm/table.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NodeType, Node } from 'prosemirror-model';
|
|
2
2
|
import { EditorState, Transaction } from 'prosemirror-state';
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
/**
|
|
5
5
|
* Creates a table.
|
|
6
6
|
*
|
|
7
7
|
* @returns Node
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
declare const createTable: (nodes: {
|
|
10
10
|
table: NodeType;
|
|
11
11
|
table_row: NodeType;
|
|
12
12
|
table_cell: NodeType;
|
|
13
13
|
}, rows: number, columns: number) => Node;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
declare const addRowBefore: (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
|
|
15
|
+
declare const addRowAfter: (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
|
|
16
|
+
declare const addColumnBefore: (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
|
|
17
|
+
declare const addColumnAfter: (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
|
|
18
|
+
declare const deleteColumn: (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
|
|
19
|
+
|
|
20
|
+
export { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, createTable, deleteColumn };
|