@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
package/dist/es/utils.js
CHANGED
|
@@ -1,96 +1,93 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { TextSelection, AllSelection, NodeSelection } from 'prosemirror-state';
|
|
1
|
+
import { Node } from 'prosemirror-model';
|
|
2
|
+
import { NodeSelection, TextSelection, AllSelection } from 'prosemirror-state';
|
|
4
3
|
import { parseInlineStyles } from '@progress/kendo-common';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
|
|
5
|
+
const changeStylesString = (styleText, newStyle) => {
|
|
6
|
+
const styleToChange = newStyle.style;
|
|
7
|
+
const regExp = newStyle.value;
|
|
8
|
+
const newValue = newStyle.newValue;
|
|
10
9
|
if (!styleText) {
|
|
11
10
|
return { changed: false, style: null };
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
for (
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
filtered.push(
|
|
12
|
+
const styles = parseStyle(styleText);
|
|
13
|
+
const styleNames = Object.keys(styles);
|
|
14
|
+
const filtered = [];
|
|
15
|
+
for (let i = 0; i < styleNames.length; i++) {
|
|
16
|
+
const name = styleNames[i];
|
|
17
|
+
if (name.toLowerCase() !== styleToChange || !regExp.test(styles[name])) {
|
|
18
|
+
filtered.push(`${name}: ${styles[name]}`);
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
if (newValue) {
|
|
23
|
-
filtered.push(
|
|
22
|
+
filtered.push(`${styleToChange}: ${newValue}`);
|
|
24
23
|
}
|
|
25
24
|
return {
|
|
26
25
|
style: filtered.join('; ') + (filtered.length ? ';' : ''),
|
|
27
26
|
changed: Boolean(newValue) || filtered.length !== styleNames.length
|
|
28
27
|
};
|
|
29
28
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const reAnyValue = /^.+$/;
|
|
30
|
+
function setNodeStyle(nodeAttrs, styleType, value) {
|
|
31
|
+
let attrs;
|
|
33
32
|
if (new RegExp('[^-]?' + styleType + ':').test(nodeAttrs.style || '')) {
|
|
34
|
-
|
|
35
|
-
attrs =
|
|
33
|
+
const { style } = changeStylesString(nodeAttrs.style || '', { style: styleType, value: reAnyValue, newValue: value });
|
|
34
|
+
attrs = { ...nodeAttrs, style };
|
|
36
35
|
}
|
|
37
36
|
else if (nodeAttrs.style) {
|
|
38
|
-
attrs =
|
|
37
|
+
attrs = { ...nodeAttrs, style: nodeAttrs.style.replace(/;$/, '') + '; ' + styleType + ': ' + value + ';' };
|
|
39
38
|
}
|
|
40
39
|
else {
|
|
41
|
-
attrs =
|
|
40
|
+
attrs = { ...nodeAttrs, style: styleType + ': ' + value + ';' };
|
|
42
41
|
}
|
|
43
42
|
return attrs;
|
|
44
43
|
}
|
|
45
44
|
/**
|
|
46
45
|
* Determines if a given node type can be inserted at the current cursor position.
|
|
47
46
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
for (
|
|
51
|
-
|
|
47
|
+
const canInsert = (state, nodeType) => {
|
|
48
|
+
const $from = state.selection.$from;
|
|
49
|
+
for (let d = $from.depth; d >= 0; d--) {
|
|
50
|
+
const index = $from.index(d);
|
|
52
51
|
if ($from.node(d).canReplaceWith(index, index, nodeType)) {
|
|
53
52
|
return true;
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
return false;
|
|
57
56
|
};
|
|
58
|
-
|
|
57
|
+
const getTypeName = (n) => {
|
|
59
58
|
return n instanceof Node ? n.type.name : n.name;
|
|
60
59
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var node = $from.node(i);
|
|
60
|
+
const findNthParentNode = (predicate, depth = 1) => {
|
|
61
|
+
return (selection) => {
|
|
62
|
+
const { $from } = selection;
|
|
63
|
+
for (let i = $from.depth; i > 0; i--) {
|
|
64
|
+
const node = $from.node(i);
|
|
67
65
|
if (predicate(node)) {
|
|
68
66
|
depth = depth - 1;
|
|
69
67
|
if (depth === 0) {
|
|
70
|
-
return { depth: i, node
|
|
68
|
+
return { depth: i, node };
|
|
71
69
|
}
|
|
72
70
|
}
|
|
73
71
|
}
|
|
74
72
|
};
|
|
75
73
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return findNthParentNode(function (node) { return getTypeName(node) === getTypeName(nodeType); }, depth)(selection);
|
|
74
|
+
const findNthParentNodeOfType = (nodeType, depth = 1) => {
|
|
75
|
+
return (selection) => {
|
|
76
|
+
return findNthParentNode((node) => getTypeName(node) === getTypeName(nodeType), depth)(selection);
|
|
80
77
|
};
|
|
81
78
|
};
|
|
82
|
-
|
|
83
|
-
for (
|
|
84
|
-
|
|
79
|
+
function parentNode(pos, predicate) {
|
|
80
|
+
for (let depth = pos.depth; depth > 0; depth--) {
|
|
81
|
+
const node = pos.node(depth);
|
|
85
82
|
if (predicate(node)) {
|
|
86
|
-
return { node
|
|
83
|
+
return { node, depth };
|
|
87
84
|
}
|
|
88
85
|
}
|
|
89
86
|
return null;
|
|
90
87
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
for (
|
|
88
|
+
const filterEmptyAttrs = (attrs) => {
|
|
89
|
+
const result = {};
|
|
90
|
+
for (const attr in attrs) {
|
|
94
91
|
if (attr && (attrs[attr] || attrs[attr] === 0)) {
|
|
95
92
|
result[attr] = attrs[attr];
|
|
96
93
|
}
|
|
@@ -100,12 +97,12 @@ var filterEmptyAttrs = function (attrs) {
|
|
|
100
97
|
/**
|
|
101
98
|
* Inserts the given node at the place of current selection.
|
|
102
99
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
const insertNode = (node, scrollIntoView) => (state, dispatch) => {
|
|
101
|
+
const { selection, tr } = state;
|
|
105
102
|
if (selection instanceof NodeSelection
|
|
106
103
|
&& selection.node.type.name === node.type.name
|
|
107
104
|
&& node.isLeaf && !node.isText && node.nodeSize === 1) {
|
|
108
|
-
tr.setNodeMarkup(selection.from, null,
|
|
105
|
+
tr.setNodeMarkup(selection.from, null, { ...filterEmptyAttrs(selection.node.attrs), ...filterEmptyAttrs(node.attrs) });
|
|
109
106
|
tr.setSelection(NodeSelection.create(tr.doc, selection.from));
|
|
110
107
|
}
|
|
111
108
|
else {
|
|
@@ -115,21 +112,16 @@ export var insertNode = function (node, scrollIntoView) { return function (state
|
|
|
115
112
|
tr.scrollIntoView();
|
|
116
113
|
}
|
|
117
114
|
dispatch(tr);
|
|
118
|
-
}; };
|
|
119
|
-
export var hasSameMarkup = function (dom1, dom2, schema, parseOptions) {
|
|
120
|
-
var fragment1 = Fragment.from(parseContent(dom1, schema, parseOptions));
|
|
121
|
-
var fragment2 = Fragment.from(parseContent(dom2, schema, parseOptions));
|
|
122
|
-
return fragment1.eq(fragment2);
|
|
123
115
|
};
|
|
124
|
-
|
|
125
|
-
|
|
116
|
+
const getSelectionText = (state) => {
|
|
117
|
+
const sel = state.selection;
|
|
126
118
|
if (sel instanceof TextSelection || sel instanceof AllSelection) {
|
|
127
|
-
|
|
119
|
+
const fragment = sel.content().content;
|
|
128
120
|
return fragment.textBetween(0, fragment.size);
|
|
129
121
|
}
|
|
130
122
|
return '';
|
|
131
123
|
};
|
|
132
|
-
|
|
124
|
+
const getNodeFromSelection = (state) => {
|
|
133
125
|
if (state.selection instanceof NodeSelection) {
|
|
134
126
|
return state.selection.node;
|
|
135
127
|
}
|
|
@@ -142,12 +134,12 @@ export var getNodeFromSelection = function (state) {
|
|
|
142
134
|
* Useful for values of the inputs of Link and Find&Replace dialogs where the inputs value has been retrieved from the selection and
|
|
143
135
|
* should be single line text only.
|
|
144
136
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
137
|
+
const selectedLineTextOnly = (state) => {
|
|
138
|
+
let result = '', hasLeafs = false;
|
|
139
|
+
const { selection, doc } = state;
|
|
140
|
+
const { $from, $to, from, to } = selection;
|
|
149
141
|
if ($from.sameParent($to)) {
|
|
150
|
-
doc.nodesBetween(from, to,
|
|
142
|
+
doc.nodesBetween(from, to, (node) => {
|
|
151
143
|
hasLeafs = hasLeafs || (node.isLeaf && !node.isText);
|
|
152
144
|
});
|
|
153
145
|
if (!hasLeafs) {
|
|
@@ -159,58 +151,55 @@ export var selectedLineTextOnly = function (state) {
|
|
|
159
151
|
/**
|
|
160
152
|
* Used by ViewHtml/ViewSource dialogs for making the HTML more readable.
|
|
161
153
|
*/
|
|
162
|
-
|
|
154
|
+
const indentHtml = (content) => {
|
|
163
155
|
return content.replace(/<\/(p|li|ul|ol|h[1-6]|table|tr|td|th)>/ig, '</$1>\n')
|
|
164
156
|
.replace(/<(ul|ol)([^>]*)><li/ig, '<$1$2>\n<li')
|
|
165
157
|
.replace(/<br \/>/ig, '<br />\n')
|
|
166
158
|
.replace(/\n$/, '');
|
|
167
159
|
};
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
160
|
+
const shallowEqual = (object1, object2) => {
|
|
161
|
+
const keys1 = Object.keys(object1);
|
|
162
|
+
const keys2 = Object.keys(object2);
|
|
171
163
|
return keys1.length === keys2.length &&
|
|
172
|
-
keys1.every(
|
|
164
|
+
keys1.every(k => object1[k] === object2[k]);
|
|
173
165
|
};
|
|
174
|
-
|
|
166
|
+
const applyToWordDefault = { before: /[^ !,?.\[\]{}()]+$/i, after: /^[^ !,?.\[\]{}()]+/i };
|
|
175
167
|
/**
|
|
176
168
|
* if options.applyToWord is set, expands the selection to the word where the cursor is and
|
|
177
169
|
* returns modified state and dispatch.
|
|
178
170
|
*/
|
|
179
|
-
|
|
171
|
+
const expandSelection = (state, dispatch, options) => {
|
|
180
172
|
if (!options.applyToWord || !state.selection.empty) {
|
|
181
|
-
return { state
|
|
173
|
+
return { state, dispatch };
|
|
182
174
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
175
|
+
const applyToWordOptions = options.applyToWord === true ? applyToWordDefault : options.applyToWord;
|
|
176
|
+
let initialPosition = null;
|
|
177
|
+
const tr = state.tr;
|
|
178
|
+
const selection = state.selection;
|
|
179
|
+
const before = selection.$head.nodeBefore;
|
|
180
|
+
const after = selection.$head.nodeAfter;
|
|
189
181
|
if (before && before.type.name === 'text' && before.text && after && after.type.name === 'text' && after.text) {
|
|
190
|
-
|
|
191
|
-
selection.$head.parent.descendants(
|
|
192
|
-
|
|
182
|
+
const children = [];
|
|
183
|
+
selection.$head.parent.descendants((node, pos) => {
|
|
184
|
+
children.push({ node, pos });
|
|
193
185
|
return false;
|
|
194
186
|
});
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
var skip = false;
|
|
202
|
-
for (var i = nodeIndex - 1; i >= 0; i--) {
|
|
203
|
-
var element = children_1[i];
|
|
187
|
+
let cursor = selection.$head.parentOffset;
|
|
188
|
+
const nodeIndex = children.findIndex(({ node, pos }) => pos <= cursor && pos + node.nodeSize >= cursor);
|
|
189
|
+
let text = children[nodeIndex].node.text;
|
|
190
|
+
let skip = false;
|
|
191
|
+
for (let i = nodeIndex - 1; i >= 0; i--) {
|
|
192
|
+
const element = children[i];
|
|
204
193
|
if (!skip && element && element.node.type.name === 'text') {
|
|
205
194
|
text = element.node.text + text;
|
|
206
195
|
}
|
|
207
196
|
else {
|
|
208
197
|
skip = true;
|
|
209
|
-
|
|
198
|
+
cursor -= element.node.nodeSize;
|
|
210
199
|
}
|
|
211
200
|
}
|
|
212
|
-
for (
|
|
213
|
-
|
|
201
|
+
for (let i = nodeIndex + 1; i < children.length; i++) {
|
|
202
|
+
const element = children[i];
|
|
214
203
|
if (element && element.node.type.name === 'text') {
|
|
215
204
|
text = text + element.node.text;
|
|
216
205
|
}
|
|
@@ -218,30 +207,30 @@ export var expandSelection = function (state, dispatch, options) {
|
|
|
218
207
|
break;
|
|
219
208
|
}
|
|
220
209
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
210
|
+
const textBefore = text.substring(0, cursor);
|
|
211
|
+
const textAfter = text.substring(cursor);
|
|
212
|
+
const matchBefore = applyToWordOptions.before.exec(textBefore);
|
|
213
|
+
const matchAfter = applyToWordOptions.after.exec(textAfter);
|
|
225
214
|
if (matchBefore && matchAfter) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
215
|
+
const extendLeft = matchBefore[0].length;
|
|
216
|
+
const extendRight = matchAfter[0].length;
|
|
217
|
+
const pos = initialPosition = selection.from;
|
|
229
218
|
tr.setSelection(TextSelection.create(state.doc, pos - extendLeft, pos + extendRight));
|
|
230
|
-
|
|
231
|
-
tr
|
|
219
|
+
const cmdState = {
|
|
220
|
+
tr,
|
|
232
221
|
selection: tr.selection,
|
|
233
222
|
doc: tr.doc,
|
|
234
223
|
storedMarks: null,
|
|
235
224
|
schema: tr.doc.type.schema
|
|
236
225
|
};
|
|
237
|
-
|
|
226
|
+
const cmdDispatch = tran => {
|
|
238
227
|
tran.setSelection(TextSelection.create(tran.doc, initialPosition));
|
|
239
228
|
dispatch(tran);
|
|
240
229
|
};
|
|
241
230
|
return { state: cmdState, dispatch: cmdDispatch };
|
|
242
231
|
}
|
|
243
232
|
}
|
|
244
|
-
return { state
|
|
233
|
+
return { state, dispatch };
|
|
245
234
|
};
|
|
246
235
|
/**
|
|
247
236
|
* if options.applyToWord is set, expands the selection to the word where the cursor is and
|
|
@@ -255,34 +244,34 @@ export var expandSelection = function (state, dispatch, options) {
|
|
|
255
244
|
* const command = expandToWordWrap(toggleInlineFormat, {...bold, applyToWord );
|
|
256
245
|
* command(view.state, view.dispatch);
|
|
257
246
|
*/
|
|
258
|
-
|
|
259
|
-
return
|
|
260
|
-
|
|
247
|
+
const expandToWordWrap = (command, options) => {
|
|
248
|
+
return (state, dispatch) => {
|
|
249
|
+
const { state: cmdState, dispatch: cmdDispatch } = expandSelection(state, dispatch, options);
|
|
261
250
|
return command(options)(cmdState, cmdDispatch);
|
|
262
251
|
};
|
|
263
252
|
};
|
|
264
|
-
|
|
253
|
+
const parseStyle = (styleText) => {
|
|
265
254
|
return parseInlineStyles(styleText);
|
|
266
255
|
};
|
|
267
|
-
|
|
268
|
-
|
|
256
|
+
const applyStyle = (styleText, styleType, styleValue) => {
|
|
257
|
+
const styles = parseStyle(styleText);
|
|
269
258
|
styles[styleType] = styleValue;
|
|
270
|
-
|
|
271
|
-
.map(
|
|
259
|
+
const result = Object.keys(styles)
|
|
260
|
+
.map(name => styles[name] ? `${name}: ${styles[name]}` : null)
|
|
272
261
|
.filter(Boolean)
|
|
273
262
|
.join('; ');
|
|
274
263
|
return result ? result + ';' : null;
|
|
275
264
|
};
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
for (
|
|
265
|
+
const setStyleAttr = (element, styleString) => {
|
|
266
|
+
const styles = parseStyle(styleString);
|
|
267
|
+
for (const style in styles) {
|
|
279
268
|
if (style && typeof element.style[style] !== 'undefined') {
|
|
280
269
|
element.style[style] = styles[style];
|
|
281
270
|
}
|
|
282
271
|
}
|
|
283
272
|
};
|
|
284
|
-
|
|
285
|
-
|
|
273
|
+
const setAttribute = (node, attrName, value) => {
|
|
274
|
+
const current = node.getAttribute(attrName);
|
|
286
275
|
if (value !== undefined && value !== current) {
|
|
287
276
|
if (attrName === 'style') {
|
|
288
277
|
node.removeAttribute(attrName);
|
|
@@ -296,3 +285,5 @@ export var setAttribute = function (node, attrName, value) {
|
|
|
296
285
|
node.removeAttribute(attrName);
|
|
297
286
|
}
|
|
298
287
|
};
|
|
288
|
+
|
|
289
|
+
export { applyStyle, canInsert, changeStylesString, expandSelection, expandToWordWrap, findNthParentNodeOfType, getNodeFromSelection, getSelectionText, indentHtml, insertNode, parentNode, parseStyle, selectedLineTextOnly, setAttribute, setNodeStyle, setStyleAttr, shallowEqual };
|
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
import { setAttribute } from './utils';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/// that take a node and return a description of the corresponding
|
|
5
|
-
/// DOM. `marks` does the same for mark names, but also gets an
|
|
6
|
-
/// argument that tells it whether the mark's content is block or
|
|
7
|
-
/// inline content (for typical use, it'll always be inline). A mark
|
|
8
|
-
/// serializer may be `null` to indicate that marks of that type
|
|
9
|
-
/// should not be serialized.
|
|
10
|
-
constructor(
|
|
11
|
-
/// The node serialization functions.
|
|
12
|
-
nodes,
|
|
13
|
-
/// The mark serialization functions.
|
|
14
|
-
marks) {
|
|
15
|
-
this.nodes = nodes;
|
|
16
|
-
this.marks = marks;
|
|
17
|
-
}
|
|
1
|
+
import { setAttribute } from './utils.js';
|
|
2
|
+
|
|
3
|
+
class DOMSerializer {
|
|
18
4
|
/// Render an [output spec](#model.DOMOutputSpec) to a DOM node. If
|
|
19
5
|
/// the spec has a hole (zero) in it, `contentDOM` will point at the
|
|
20
6
|
/// node with the hole.
|
|
@@ -90,6 +76,21 @@ export class DOMSerializer {
|
|
|
90
76
|
static marksFromSchema(schema) {
|
|
91
77
|
return gatherToDOM(schema.marks);
|
|
92
78
|
}
|
|
79
|
+
/// Create a serializer. `nodes` should map node names to functions
|
|
80
|
+
/// that take a node and return a description of the corresponding
|
|
81
|
+
/// DOM. `marks` does the same for mark names, but also gets an
|
|
82
|
+
/// argument that tells it whether the mark's content is block or
|
|
83
|
+
/// inline content (for typical use, it'll always be inline). A mark
|
|
84
|
+
/// serializer may be `null` to indicate that marks of that type
|
|
85
|
+
/// should not be serialized.
|
|
86
|
+
constructor(
|
|
87
|
+
/// The node serialization functions.
|
|
88
|
+
nodes,
|
|
89
|
+
/// The mark serialization functions.
|
|
90
|
+
marks) {
|
|
91
|
+
this.nodes = nodes;
|
|
92
|
+
this.marks = marks;
|
|
93
|
+
}
|
|
93
94
|
/// Serialize the content of this fragment to a DOM fragment. When
|
|
94
95
|
/// not in the browser, the `document` option, containing a DOM
|
|
95
96
|
/// document, should be passed so that the serializer can create
|
|
@@ -179,3 +180,5 @@ function gatherToDOM(obj) {
|
|
|
179
180
|
function doc(options) {
|
|
180
181
|
return options.document || window.document;
|
|
181
182
|
}
|
|
183
|
+
|
|
184
|
+
export { DOMSerializer };
|
package/dist/es2015/align.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { blockNodes, addStyles, changeTextBlock } from './blockNode';
|
|
1
|
+
import { blockNodes, addStyles, changeTextBlock } from './blockNode.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Aligning block elements in the selection.
|
|
4
5
|
*
|
|
5
6
|
* @returns {boolean} - Returns true if any alignment is applied.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
const alignBlocks = (actions, commandName) => (state, dispatch) => {
|
|
8
9
|
const blocks = blockNodes(state);
|
|
9
10
|
const tr = state.tr;
|
|
10
11
|
tr.setMeta('commandName', commandName);
|
|
@@ -23,7 +24,7 @@ export const alignBlocks = (actions, commandName) => (state, dispatch) => {
|
|
|
23
24
|
}
|
|
24
25
|
return result;
|
|
25
26
|
};
|
|
26
|
-
|
|
27
|
+
const isAligned = (state, actions) => {
|
|
27
28
|
const blocks = blockNodes(state);
|
|
28
29
|
let result = false;
|
|
29
30
|
blocks.forEach(node => {
|
|
@@ -38,3 +39,5 @@ export const isAligned = (state, actions) => {
|
|
|
38
39
|
});
|
|
39
40
|
return result;
|
|
40
41
|
};
|
|
42
|
+
|
|
43
|
+
export { alignBlocks, isAligned };
|
package/dist/es2015/blockNode.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { __rest } from
|
|
2
|
-
import { changeStylesString } from './utils';
|
|
1
|
+
import { __rest } from './node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { changeStylesString } from './utils.js';
|
|
3
3
|
import { ReplaceAroundStep } from 'prosemirror-transform';
|
|
4
|
-
import {
|
|
4
|
+
import { Slice, Fragment } from 'prosemirror-model';
|
|
5
5
|
import { NodeSelection } from 'prosemirror-state';
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* @hidden
|
|
8
9
|
*/
|
|
@@ -16,7 +17,7 @@ const canChangeType = (stateDoc, pos, type) => {
|
|
|
16
17
|
* @example
|
|
17
18
|
* See `cleanTextBlockFormatting` or `formatBlockElements` function.
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
+
const changeTextBlock = (tr, node, nodeType, attrs) => {
|
|
20
21
|
if (!nodeType.isTextblock) {
|
|
21
22
|
return false;
|
|
22
23
|
}
|
|
@@ -47,7 +48,7 @@ export const changeTextBlock = (tr, node, nodeType, attrs) => {
|
|
|
47
48
|
* @example
|
|
48
49
|
* See `cleanTextBlockFormatting` function.
|
|
49
50
|
*/
|
|
50
|
-
|
|
51
|
+
const blockNodes = (state, options = { blocksInSelection: false }) => {
|
|
51
52
|
const { doc, selection } = state;
|
|
52
53
|
const { $from, ranges } = selection;
|
|
53
54
|
const { blocksInSelection } = options;
|
|
@@ -79,7 +80,7 @@ export const blockNodes = (state, options = { blocksInSelection: false }) => {
|
|
|
79
80
|
}
|
|
80
81
|
return result;
|
|
81
82
|
};
|
|
82
|
-
|
|
83
|
+
const formatBlockElements = (value, commandName) => (state, dispatch) => {
|
|
83
84
|
const blocks = blockNodes(state);
|
|
84
85
|
const nodes = state.schema.nodes;
|
|
85
86
|
const tr = state.tr;
|
|
@@ -112,7 +113,7 @@ export const formatBlockElements = (value, commandName) => (state, dispatch) =>
|
|
|
112
113
|
* @example
|
|
113
114
|
* See `cleanFormatting` function.
|
|
114
115
|
*/
|
|
115
|
-
|
|
116
|
+
const cleanTextBlockFormatting = (tr, options = { blocksInSelection: true }) => {
|
|
116
117
|
const { doc, selection } = tr;
|
|
117
118
|
const { blocksInSelection, blockNodeType } = options;
|
|
118
119
|
const nodes = blockNodes({ doc, selection }, { blocksInSelection });
|
|
@@ -125,7 +126,7 @@ export const cleanTextBlockFormatting = (tr, options = { blocksInSelection: true
|
|
|
125
126
|
}
|
|
126
127
|
});
|
|
127
128
|
};
|
|
128
|
-
|
|
129
|
+
const getBlockFormats = (state) => {
|
|
129
130
|
const blocks = blockNodes(state);
|
|
130
131
|
const nodes = state.schema.nodes;
|
|
131
132
|
const result = [];
|
|
@@ -143,7 +144,7 @@ export const getBlockFormats = (state) => {
|
|
|
143
144
|
});
|
|
144
145
|
return result;
|
|
145
146
|
};
|
|
146
|
-
|
|
147
|
+
const addStyles = (node, stylesToApply) => {
|
|
147
148
|
let currentStyles = node.attrs.style, changedStyleResult, toChange;
|
|
148
149
|
if (currentStyles) {
|
|
149
150
|
stylesToApply.forEach(style => {
|
|
@@ -156,7 +157,7 @@ export const addStyles = (node, stylesToApply) => {
|
|
|
156
157
|
currentStyles = currentStyles || stylesToApply.reduce(reducer, '');
|
|
157
158
|
return Object.assign({}, node.attrs, { style: currentStyles || null });
|
|
158
159
|
};
|
|
159
|
-
|
|
160
|
+
const hasNode = (state, nodeType) => {
|
|
160
161
|
const { from, to } = state.selection;
|
|
161
162
|
let result = false;
|
|
162
163
|
state.doc.nodesBetween(from, to, node => {
|
|
@@ -165,13 +166,15 @@ export const hasNode = (state, nodeType) => {
|
|
|
165
166
|
});
|
|
166
167
|
return result;
|
|
167
168
|
};
|
|
168
|
-
|
|
169
|
+
const parentBlockFormat = (state) => {
|
|
169
170
|
const formats = getBlockFormats(state);
|
|
170
171
|
return new Set(formats).size === 1 ? formats[0] : null;
|
|
171
172
|
};
|
|
172
173
|
/**
|
|
173
174
|
* **Deprecated.** Use `parentBlockFormat` function instead.
|
|
174
175
|
*/
|
|
175
|
-
|
|
176
|
+
const activeNode = (state) => {
|
|
176
177
|
return { tag: parentBlockFormat(state) || '' };
|
|
177
178
|
};
|
|
179
|
+
|
|
180
|
+
export { activeNode, addStyles, blockNodes, changeTextBlock, cleanTextBlockFormatting, formatBlockElements, getBlockFormats, hasNode, parentBlockFormat };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { wrapIn } from 'prosemirror-commands';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
const blockquote = (state, dispatch) => {
|
|
3
4
|
return wrapIn(state.schema.nodes.blockquote)(state, dispatch);
|
|
4
5
|
};
|
|
5
|
-
|
|
6
|
+
const liftBlockquote = (state, dispatch) => {
|
|
6
7
|
const { $from, $to } = state.selection;
|
|
7
8
|
const nodeType = state.schema.nodes.blockquote;
|
|
8
9
|
const doc = state.doc;
|
|
@@ -21,3 +22,5 @@ export const liftBlockquote = (state, dispatch) => {
|
|
|
21
22
|
}
|
|
22
23
|
return result;
|
|
23
24
|
};
|
|
25
|
+
|
|
26
|
+
export { blockquote, liftBlockquote };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { cleanTextBlockFormatting } from './blockNode';
|
|
2
|
-
import { cleanMarks } from './mark';
|
|
1
|
+
import { cleanTextBlockFormatting } from './blockNode.js';
|
|
2
|
+
import { cleanMarks } from './mark.js';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* A command which removes the inline formatting, class and style attributes of paragraph and heading elements in the selection.
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
+
const cleanFormatting = (options = { blocksInSelection: true }) => (state, dispatch) => {
|
|
7
8
|
const tr = state.tr;
|
|
8
9
|
const { blocksInSelection, blockNodeType, exceptMarks } = options;
|
|
9
10
|
const except = (exceptMarks || [state.schema.marks.link]).filter(Boolean);
|
|
@@ -15,3 +16,5 @@ export const cleanFormatting = (options = { blocksInSelection: true }) => (state
|
|
|
15
16
|
}
|
|
16
17
|
return result;
|
|
17
18
|
};
|
|
19
|
+
|
|
20
|
+
export { cleanFormatting };
|
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
const style = (name, value) => {
|
|
2
2
|
return { name: name, value: value };
|
|
3
3
|
};
|
|
4
|
-
|
|
4
|
+
const alignLeftRules = [
|
|
5
5
|
{ node: 'paragraph', style: [style('text-align', 'left')] },
|
|
6
6
|
{ node: 'heading', style: [style('text-align', 'left')] },
|
|
7
7
|
{ node: 'table_caption_external', style: [style('text-align', 'left')] }
|
|
8
8
|
];
|
|
9
|
-
|
|
9
|
+
const alignRightRules = [
|
|
10
10
|
{ node: 'paragraph', style: [style('text-align', 'right')] },
|
|
11
11
|
{ node: 'heading', style: [style('text-align', 'right')] },
|
|
12
12
|
{ node: 'table_caption_external', style: [style('text-align', 'right')] }
|
|
13
13
|
];
|
|
14
|
-
|
|
14
|
+
const alignCenterRules = [
|
|
15
15
|
{ node: 'paragraph', style: [style('text-align', 'center')] },
|
|
16
16
|
{ node: 'heading', style: [style('text-align', 'center')] },
|
|
17
17
|
{ node: 'table_caption_external', style: [style('text-align', 'center')] }
|
|
18
18
|
];
|
|
19
|
-
|
|
19
|
+
const alignJustifyRules = [
|
|
20
20
|
{ node: 'paragraph', style: [style('text-align', 'justify')] },
|
|
21
21
|
{ node: 'heading', style: [style('text-align', 'justify')] },
|
|
22
22
|
{ node: 'table_caption_external', style: [style('text-align', 'justify')] }
|
|
23
23
|
];
|
|
24
|
-
|
|
24
|
+
const alignRemoveRules = [
|
|
25
25
|
{ node: 'paragraph', style: [style('text-align', '')] },
|
|
26
26
|
{ node: 'heading', style: [style('text-align', '')] },
|
|
27
27
|
{ node: 'table_caption_external', style: [style('text-align', '')] }
|
|
28
28
|
];
|
|
29
|
+
|
|
30
|
+
export { alignCenterRules, alignJustifyRules, alignLeftRules, alignRemoveRules, alignRightRules };
|