@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/mark.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { RemoveMarkStep } from 'prosemirror-transform';
|
|
2
2
|
import { MarkType } from 'prosemirror-model';
|
|
3
|
-
import { parseStyle } from './utils';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
import { parseStyle } from './utils.js';
|
|
4
|
+
|
|
5
|
+
const markApplies = (doc, ranges, type) => {
|
|
6
|
+
const loop = i => {
|
|
7
|
+
const ref = ranges[i];
|
|
8
|
+
const $from = ref.$from;
|
|
9
|
+
const $to = ref.$to;
|
|
10
|
+
let can = $from.depth === 0 ? doc.type.allowsMarkType(type) : false;
|
|
11
|
+
doc.nodesBetween($from.pos, $to.pos, node => {
|
|
11
12
|
if (can) {
|
|
12
13
|
return false;
|
|
13
14
|
}
|
|
@@ -17,16 +18,16 @@ export var markApplies = function (doc, ranges, type) {
|
|
|
17
18
|
return { v: true };
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
|
-
for (
|
|
21
|
-
|
|
21
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
22
|
+
const returned = loop(i);
|
|
22
23
|
if (returned) {
|
|
23
24
|
return returned.v;
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
return false;
|
|
27
28
|
};
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
const toggleMark = (markType, attrs, tr) => (state, dispatch) => {
|
|
30
|
+
const { empty, $cursor, ranges } = state.selection;
|
|
30
31
|
if ((empty && !$cursor) || !markApplies(state.doc, ranges, markType)) {
|
|
31
32
|
return false;
|
|
32
33
|
}
|
|
@@ -40,13 +41,13 @@ export var toggleMark = function (markType, attrs, tr) { return function (state,
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
else {
|
|
43
|
-
|
|
44
|
-
for (
|
|
45
|
-
|
|
44
|
+
let has = false;
|
|
45
|
+
for (let i = 0; !has && i < ranges.length; i++) {
|
|
46
|
+
const { $from, $to } = ranges[i];
|
|
46
47
|
has = state.doc.rangeHasMark($from.pos, $to.pos, markType);
|
|
47
48
|
}
|
|
48
|
-
for (
|
|
49
|
-
|
|
49
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
50
|
+
const { $from, $to } = ranges[i];
|
|
50
51
|
if (has) {
|
|
51
52
|
tr.removeMark($from.pos, $to.pos, markType);
|
|
52
53
|
}
|
|
@@ -58,20 +59,20 @@ export var toggleMark = function (markType, attrs, tr) { return function (state,
|
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
return true;
|
|
61
|
-
};
|
|
62
|
-
|
|
62
|
+
};
|
|
63
|
+
const removeMark = (tr, from, to, mark) => {
|
|
63
64
|
if (mark === void 0) {
|
|
64
65
|
mark = null;
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
-
tr.doc.nodesBetween(from, to,
|
|
67
|
+
let matched = [], step = 0;
|
|
68
|
+
tr.doc.nodesBetween(from, to, (node, pos) => {
|
|
68
69
|
if (!node.isInline) {
|
|
69
70
|
return;
|
|
70
71
|
}
|
|
71
72
|
step++;
|
|
72
|
-
|
|
73
|
+
let toRemove = null;
|
|
73
74
|
if (mark instanceof MarkType) {
|
|
74
|
-
|
|
75
|
+
const found = mark.isInSet(node.marks);
|
|
75
76
|
if (found) {
|
|
76
77
|
toRemove = [found];
|
|
77
78
|
}
|
|
@@ -85,11 +86,11 @@ export var removeMark = function (tr, from, to, mark) {
|
|
|
85
86
|
toRemove = node.marks;
|
|
86
87
|
}
|
|
87
88
|
if (toRemove && toRemove.length) {
|
|
88
|
-
|
|
89
|
-
for (
|
|
90
|
-
|
|
91
|
-
for (
|
|
92
|
-
|
|
89
|
+
const end = Math.min(pos + node.nodeSize, to);
|
|
90
|
+
for (let i = 0; i < toRemove.length; i++) {
|
|
91
|
+
let style = toRemove[i], found$1 = (void 0);
|
|
92
|
+
for (let j = 0; j < matched.length; j++) {
|
|
93
|
+
const m = matched[j];
|
|
93
94
|
if (m.step === step - 1 && style.eq(m.style)) {
|
|
94
95
|
found$1 = m;
|
|
95
96
|
}
|
|
@@ -104,43 +105,37 @@ export var removeMark = function (tr, from, to, mark) {
|
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
});
|
|
107
|
-
matched.forEach(
|
|
108
|
+
matched.forEach((m) => { return tr.step(new RemoveMarkStep(m.from, m.to, m.style)); });
|
|
108
109
|
return tr;
|
|
109
110
|
};
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
const removeMarks = (marks, state, dispatch, tr) => {
|
|
112
|
+
const { $cursor, ranges } = state.selection;
|
|
112
113
|
tr = tr || state.tr;
|
|
113
114
|
if ($cursor) {
|
|
114
|
-
marks.forEach(
|
|
115
|
+
marks.forEach(m => {
|
|
115
116
|
if (m.isInSet(state.storedMarks || $cursor.marks())) {
|
|
116
117
|
dispatch(tr.removeStoredMark(m));
|
|
117
118
|
}
|
|
118
119
|
});
|
|
119
120
|
}
|
|
120
121
|
else {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
marks.forEach(
|
|
122
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
123
|
+
const { $from, $to } = ranges[i];
|
|
124
|
+
marks.forEach(m => {
|
|
124
125
|
removeMark(tr, $from.pos, $to.pos, m);
|
|
125
126
|
});
|
|
126
|
-
};
|
|
127
|
-
for (var i = 0; i < ranges.length; i++) {
|
|
128
|
-
_loop_1(i);
|
|
129
127
|
}
|
|
130
128
|
dispatch(tr.scrollIntoView());
|
|
131
129
|
}
|
|
132
130
|
return true;
|
|
133
131
|
};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
dispatch(tr);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
132
|
+
const toArray = (x) => x instanceof Array ? x : [x];
|
|
133
|
+
const removeAllMarks = ({ except = [] } = {}) => (state, dispatch) => {
|
|
134
|
+
const tr = state.tr;
|
|
135
|
+
cleanMarks(tr, { except: toArray(except) });
|
|
136
|
+
if (tr.docChanged) {
|
|
137
|
+
dispatch(tr);
|
|
138
|
+
}
|
|
144
139
|
};
|
|
145
140
|
/**
|
|
146
141
|
* Removes the marks from the selection base on the passed parameter.
|
|
@@ -149,19 +144,17 @@ export var removeAllMarks = function (_a) {
|
|
|
149
144
|
* @example
|
|
150
145
|
* See `removeAllMarks` or `cleanFormatting` function.
|
|
151
146
|
*/
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
var excludedMarkTypes = (except || []).map(function (mt) { return mt.name; });
|
|
147
|
+
const cleanMarks = (tr, { except }) => {
|
|
148
|
+
const { doc, selection } = tr;
|
|
149
|
+
const schema = doc.type.schema;
|
|
150
|
+
const { empty, ranges } = selection;
|
|
151
|
+
const excludedMarkTypes = (except || []).map(mt => mt.name);
|
|
158
152
|
if (!empty) {
|
|
159
|
-
|
|
160
|
-
.map(
|
|
161
|
-
.filter(
|
|
162
|
-
ranges.forEach(
|
|
163
|
-
|
|
164
|
-
marks_1.forEach(function (mark) { return tr.removeMark($from.pos, $to.pos, mark); });
|
|
153
|
+
const marks = Object.keys(schema.marks)
|
|
154
|
+
.map(m => schema.marks[m])
|
|
155
|
+
.filter(mt => excludedMarkTypes.indexOf(mt.name) === -1);
|
|
156
|
+
ranges.forEach(({ $from, $to }) => {
|
|
157
|
+
marks.forEach(mark => tr.removeMark($from.pos, $to.pos, mark));
|
|
165
158
|
});
|
|
166
159
|
}
|
|
167
160
|
};
|
|
@@ -169,36 +162,36 @@ export var cleanMarks = function (tr, _a) {
|
|
|
169
162
|
* Checks if a mark exists in the selection.
|
|
170
163
|
* Used for checking the state of bold, italic, ... and unlink tools.
|
|
171
164
|
*/
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
165
|
+
const hasMark = (state, options) => {
|
|
166
|
+
const marks = state.schema.marks;
|
|
167
|
+
const altMarks = (options.altMarks || []).filter(m => marks[m]);
|
|
168
|
+
const altStyle = options.altStyle;
|
|
169
|
+
const { from, $from, to, empty } = state.selection;
|
|
170
|
+
const type = marks[options.mark];
|
|
171
|
+
const doc = state.doc;
|
|
172
|
+
let result = false;
|
|
173
|
+
let currMarks;
|
|
181
174
|
if (empty) {
|
|
182
175
|
currMarks = state.storedMarks || $from.marks();
|
|
183
|
-
result = (type && type.isInSet(currMarks)) || altMarks.some(
|
|
176
|
+
result = (type && type.isInSet(currMarks)) || altMarks.some(m => marks[m].isInSet(currMarks));
|
|
184
177
|
}
|
|
185
178
|
else {
|
|
186
|
-
result = (type && doc.rangeHasMark(from, to, type)) || altMarks.some(
|
|
179
|
+
result = (type && doc.rangeHasMark(from, to, type)) || altMarks.some(m => doc.rangeHasMark(from, to, marks[m]));
|
|
187
180
|
}
|
|
188
181
|
if (!result && altStyle && marks.style) {
|
|
189
182
|
return selectionMarks(state, marks.style)
|
|
190
|
-
.some(
|
|
183
|
+
.some(mark => styleValue(mark, altStyle) !== null);
|
|
191
184
|
}
|
|
192
185
|
return Boolean(result);
|
|
193
186
|
};
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
for (
|
|
199
|
-
|
|
200
|
-
if (
|
|
201
|
-
return styles[
|
|
187
|
+
const styleValue = (mark, style) => {
|
|
188
|
+
const styleText = (mark && mark.attrs.style) || '';
|
|
189
|
+
const styles = parseStyle(styleText);
|
|
190
|
+
const styleNames = Object.keys(styles);
|
|
191
|
+
for (let i = 0; i < styleNames.length; i++) {
|
|
192
|
+
const name = styleNames[i];
|
|
193
|
+
if (name.toLowerCase() === style.name && style.value.test(styles[name])) {
|
|
194
|
+
return styles[name];
|
|
202
195
|
}
|
|
203
196
|
}
|
|
204
197
|
return null;
|
|
@@ -206,14 +199,14 @@ export var styleValue = function (mark, style) {
|
|
|
206
199
|
/**
|
|
207
200
|
* Returns the marks of a specific type for every inline node in the selection.
|
|
208
201
|
*/
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
202
|
+
const selectionMarks = (state, markType) => {
|
|
203
|
+
const { from, $from, to, empty } = state.selection;
|
|
204
|
+
const marks = [];
|
|
212
205
|
if (empty) {
|
|
213
206
|
marks.push(markType.isInSet(state.storedMarks || $from.marks()));
|
|
214
207
|
}
|
|
215
208
|
else {
|
|
216
|
-
state.doc.nodesBetween(from, to,
|
|
209
|
+
state.doc.nodesBetween(from, to, node => {
|
|
217
210
|
if (node.isInline) {
|
|
218
211
|
marks.push(markType.isInSet(node.marks));
|
|
219
212
|
}
|
|
@@ -225,20 +218,22 @@ export var selectionMarks = function (state, markType) {
|
|
|
225
218
|
* Returns the specified mark which wraps the selection.
|
|
226
219
|
* Used by link tools.
|
|
227
220
|
*/
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
221
|
+
const getMark = (state, markType) => {
|
|
222
|
+
const marks = selectionMarks(state, markType);
|
|
223
|
+
const filtered = marks.filter(m => Boolean(m));
|
|
231
224
|
return marks.length === filtered.length ? marks[0] : undefined;
|
|
232
225
|
};
|
|
233
226
|
/**
|
|
234
227
|
* **Deprecated.** Use `selectionMarks` function instead.
|
|
235
228
|
*/
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
229
|
+
const getActiveMarks = (state, markType) => {
|
|
230
|
+
const marks = selectionMarks(state, markType);
|
|
231
|
+
const filtered = marks.filter(m => Boolean(m));
|
|
232
|
+
const hasNodesWithoutMarks = marks.length !== filtered.length;
|
|
240
233
|
return {
|
|
241
|
-
hasNodesWithoutMarks
|
|
234
|
+
hasNodesWithoutMarks,
|
|
242
235
|
marks: filtered
|
|
243
236
|
};
|
|
244
237
|
};
|
|
238
|
+
|
|
239
|
+
export { cleanMarks, getActiveMarks, getMark, hasMark, markApplies, removeAllMarks, removeMark, removeMarks, selectionMarks, styleValue, toggleMark };
|
package/dist/es/paste.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { convertMsLists } from './listConvert';
|
|
2
|
-
import {
|
|
3
|
-
import { parseStyle } from './utils';
|
|
1
|
+
import { convertMsLists } from './listConvert.js';
|
|
2
|
+
import { htmlToFragment, fragmentToHtml } from './source.js';
|
|
3
|
+
import { parseStyle } from './utils.js';
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Removes the invalid HTML. Use it as a first step for cleaning the HTML.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
const sanitize = (html) => {
|
|
8
9
|
html = html.replace(/^[\s\S]+?<!--StartFragment-->\s*([\s\S]*?)\s*<!--EndFragment-->[\s\S]+$/, '$1');
|
|
9
10
|
html = html.replace(/<\/?[ovw]:[^>]*?>/gi, ''); // MS elements, e.g. <o:p>, <w:sdtPr>, <v:
|
|
10
11
|
html = html.replace(/<\\?\??xml[^>]*>/gi, ''); // XML namespaces
|
|
@@ -20,19 +21,19 @@ export var sanitize = function (html) {
|
|
|
20
21
|
/**
|
|
21
22
|
* Removes comments in HTML.
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
+
const removeComments = (html) => {
|
|
24
25
|
return html.replace(/<!--[\s\S]+?-->/g, '');
|
|
25
26
|
};
|
|
26
27
|
/**
|
|
27
28
|
* Removes the specified tag(s).
|
|
28
29
|
*/
|
|
29
|
-
|
|
30
|
+
const removeTag = (html, tagPattern) => {
|
|
30
31
|
return html.replace(new RegExp('<\\/?(' + tagPattern + ')(?:\\s[^>]*?)?>', 'gi'), '');
|
|
31
32
|
};
|
|
32
33
|
/**
|
|
33
34
|
* Removes the passed attribute.
|
|
34
35
|
*/
|
|
35
|
-
|
|
36
|
+
const removeAttribute = (attr) => {
|
|
36
37
|
if (attr.ownerElement) {
|
|
37
38
|
attr.ownerElement.removeAttribute(attr.name);
|
|
38
39
|
}
|
|
@@ -40,7 +41,7 @@ export var removeAttribute = function (attr) {
|
|
|
40
41
|
/**
|
|
41
42
|
* Remove the attribute if its value matches /^Mso/ regex.
|
|
42
43
|
*/
|
|
43
|
-
|
|
44
|
+
const sanitizeClassAttr = (attr) => {
|
|
44
45
|
if (/^Mso/.test(attr.value)) {
|
|
45
46
|
removeAttribute(attr);
|
|
46
47
|
}
|
|
@@ -48,14 +49,14 @@ export var sanitizeClassAttr = function (attr) {
|
|
|
48
49
|
/**
|
|
49
50
|
* Removes invalid HTML styles.
|
|
50
51
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
Object.keys(styles).forEach(
|
|
52
|
+
const sanitizeStyleAttr = (attr) => {
|
|
53
|
+
const styles = parseStyle(attr.value);
|
|
54
|
+
const element = attr.ownerElement;
|
|
55
|
+
const supportedStyles = element.style;
|
|
56
|
+
let result = '';
|
|
57
|
+
Object.keys(styles).forEach(name => {
|
|
57
58
|
if (supportedStyles[name] !== undefined) {
|
|
58
|
-
result +=
|
|
59
|
+
result += `${name}: ${styles[name]}; `;
|
|
59
60
|
}
|
|
60
61
|
});
|
|
61
62
|
result = result.trim();
|
|
@@ -66,8 +67,8 @@ export var sanitizeStyleAttr = function (attr) {
|
|
|
66
67
|
removeAttribute(attr);
|
|
67
68
|
}
|
|
68
69
|
};
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const removeNode = (node) => {
|
|
71
|
+
const parentNode = node.parentNode;
|
|
71
72
|
if (parentNode) {
|
|
72
73
|
while (node.firstChild) {
|
|
73
74
|
parentNode.insertBefore(node.firstChild, node);
|
|
@@ -75,10 +76,10 @@ var removeNode = function (node) {
|
|
|
75
76
|
parentNode.removeChild(node);
|
|
76
77
|
}
|
|
77
78
|
};
|
|
78
|
-
|
|
79
|
+
const sanitizeNode = (node, attributes) => {
|
|
79
80
|
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
80
|
-
for (
|
|
81
|
-
|
|
81
|
+
for (let i = node.attributes.length - 1; i >= 0; i--) {
|
|
82
|
+
const attr = node.attributes[i];
|
|
82
83
|
if (attributes[attr.name]) {
|
|
83
84
|
attributes[attr.name](attr);
|
|
84
85
|
}
|
|
@@ -95,8 +96,8 @@ var sanitizeNode = function (node, attributes) {
|
|
|
95
96
|
* Cleans the HTML based on passed settings.
|
|
96
97
|
* Before using it, clean the HTML with the `sanitize` function.
|
|
97
98
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
const pasteCleanup = (html, settings) => {
|
|
100
|
+
let result = html;
|
|
100
101
|
if (settings.convertMsLists) {
|
|
101
102
|
result = convertMsLists(result);
|
|
102
103
|
}
|
|
@@ -104,27 +105,27 @@ export var pasteCleanup = function (html, settings) {
|
|
|
104
105
|
result = removeTag(result, settings.stripTags);
|
|
105
106
|
}
|
|
106
107
|
if (settings.attributes) {
|
|
107
|
-
|
|
108
|
-
Array.from(fragment.querySelectorAll('*')).forEach(
|
|
108
|
+
const fragment = htmlToFragment(result);
|
|
109
|
+
Array.from(fragment.querySelectorAll('*')).forEach(node => sanitizeNode(node, settings.attributes));
|
|
109
110
|
result = fragmentToHtml(fragment);
|
|
110
111
|
}
|
|
111
112
|
return result;
|
|
112
113
|
};
|
|
113
114
|
function convertHexToBase64(hex) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
for (
|
|
115
|
+
const length = hex.length;
|
|
116
|
+
const data = new Array(length / 2);
|
|
117
|
+
for (let i = 0; i < length; i += 2) {
|
|
117
118
|
data[i] = String.fromCharCode(parseInt(hex.substring(i, i + 2), 16));
|
|
118
119
|
}
|
|
119
120
|
return btoa(data.join(''));
|
|
120
121
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
const reHtmlImg = /<img\s[^>]*?src=(?:'|")file:\/[^'"]+(?:'|")[^>]*>/gi;
|
|
123
|
+
const reRtfImgHeader = /{\\pict[\s\S]+?\\bliptag-?\d+(\\blipupi-?\d+)?({\\\*\\blipuid\s?[\da-fA-F]+)?[\s}]*?/;
|
|
124
|
+
const reRtfImg = new RegExp('(?:(' + reRtfImgHeader.source + '))([\\da-fA-F\\s]+)\\}', 'g');
|
|
125
|
+
const reNonHex = /[^\da-fA-F]/g;
|
|
126
|
+
const reLocalFile = /file:\/[^'"]+\.(jpg|png|gif)/i;
|
|
127
|
+
const reExtension = /\\(png|jpeg)blip\\/;
|
|
128
|
+
const textRtfType = 'text/rtf';
|
|
128
129
|
/**
|
|
129
130
|
* If the input HTML contains images with 'src' pointing to local file system (it happens when pasting images and text from MS Word),
|
|
130
131
|
* the function will extract the image sources form the RTF and replace the image 'src' with extracted base64 format data in `html` string.
|
|
@@ -133,30 +134,31 @@ var textRtfType = 'text/rtf';
|
|
|
133
134
|
* @param clipboardData - The paste event clipboardData object (event.clipboardData).
|
|
134
135
|
* @returns - The html with the replaced images sources.
|
|
135
136
|
*/
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
const replaceImageSourcesFromRtf = (html, clipboardData) => {
|
|
138
|
+
const htmlImages = html.match(reHtmlImg);
|
|
138
139
|
if (!htmlImages || clipboardData.types.indexOf(textRtfType) === -1) {
|
|
139
140
|
return html;
|
|
140
141
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
const rtf = clipboardData.getData(textRtfType);
|
|
143
|
+
const base64Sources = [];
|
|
144
|
+
const rtfImages = rtf.match(reRtfImg);
|
|
144
145
|
if (!rtf || !rtfImages) {
|
|
145
146
|
return html;
|
|
146
147
|
}
|
|
147
|
-
for (
|
|
148
|
-
|
|
149
|
-
var extension = reExtension.exec(image);
|
|
148
|
+
for (const image of rtfImages) {
|
|
149
|
+
const extension = reExtension.exec(image);
|
|
150
150
|
if (extension) {
|
|
151
|
-
|
|
152
|
-
base64Sources.push(
|
|
151
|
+
const hex = image.replace(reRtfImgHeader, '').replace(reNonHex, '');
|
|
152
|
+
base64Sources.push(`data:image/${extension[1]};base64,${convertHexToBase64(hex)}`);
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
if (htmlImages.length !== base64Sources.length) {
|
|
156
156
|
return html;
|
|
157
157
|
}
|
|
158
|
-
return html.replace(reHtmlImg,
|
|
159
|
-
|
|
158
|
+
return html.replace(reHtmlImg, img => {
|
|
159
|
+
const src = base64Sources.shift() || '';
|
|
160
160
|
return img.replace(reLocalFile, src);
|
|
161
161
|
});
|
|
162
162
|
};
|
|
163
|
+
|
|
164
|
+
export { pasteCleanup, removeAttribute, removeComments, removeTag, replaceImageSourcesFromRtf, sanitize, sanitizeClassAttr, sanitizeStyleAttr };
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { styleValue } from '
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { PluginKey, Plugin } from 'prosemirror-state';
|
|
2
|
+
import { DecorationSet, Decoration } from 'prosemirror-view';
|
|
3
|
+
import { styleValue } from '../mark.js';
|
|
4
|
+
|
|
5
|
+
const caretColorKey = new PluginKey('caret-color');
|
|
6
|
+
function caretColor() {
|
|
6
7
|
return new Plugin({
|
|
7
8
|
key: caretColorKey,
|
|
8
9
|
props: {
|
|
9
|
-
decorations:
|
|
10
|
-
|
|
10
|
+
decorations: (state) => {
|
|
11
|
+
const { doc, selection, storedMarks } = state;
|
|
11
12
|
if (!selection.empty || !storedMarks) {
|
|
12
13
|
return DecorationSet.empty;
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
+
const color = styleValue((storedMarks || []).find((m) => m.type.name === 'style'), { name: 'color', value: /^.+$/ });
|
|
15
16
|
if (!color) {
|
|
16
17
|
return DecorationSet.empty;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
doc.descendants(
|
|
19
|
+
const parentNode = selection.$anchor.parent;
|
|
20
|
+
const decorations = [];
|
|
21
|
+
doc.descendants((node, pos) => {
|
|
21
22
|
if (node.eq(parentNode)) {
|
|
22
23
|
decorations.push(Decoration.node(pos, pos + node.nodeSize, {
|
|
23
24
|
style: 'caret-color: ' + color
|
|
@@ -29,3 +30,5 @@ export function caretColor() {
|
|
|
29
30
|
}
|
|
30
31
|
});
|
|
31
32
|
}
|
|
33
|
+
|
|
34
|
+
export { caretColor, caretColorKey };
|
|
@@ -1,51 +1,51 @@
|
|
|
1
1
|
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
-
import { setAttribute } from '../utils';
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { setAttribute } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
const setAttributes = (dom, attrs) => {
|
|
5
|
+
for (const attrName in attrs) {
|
|
5
6
|
if (attrName) {
|
|
6
7
|
setAttribute(dom, attrName, attrs[attrName]);
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (isLeaf === void 0) { isLeaf = false; }
|
|
11
|
+
class CustomNodeView {
|
|
12
|
+
constructor(node, view, nodeName, isLeaf = false) {
|
|
13
13
|
this.node = node;
|
|
14
14
|
this.view = view;
|
|
15
15
|
this.dom = document.createElement(nodeName);
|
|
16
16
|
setAttributes(this.dom, node.attrs);
|
|
17
17
|
this.contentDOM = !isLeaf ? this.dom : undefined;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function StyleView(mark, view) {
|
|
19
|
+
}
|
|
20
|
+
class StyleView {
|
|
21
|
+
constructor(mark, view) {
|
|
23
22
|
this.mark = mark;
|
|
24
23
|
this.view = view;
|
|
25
24
|
this.dom = document.createElement('span');
|
|
26
25
|
setAttributes(this.dom, mark.attrs);
|
|
27
26
|
this.contentDOM = this.dom;
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export var cspFix = function () {
|
|
28
|
+
}
|
|
29
|
+
const cspFix = () => {
|
|
32
30
|
return new Plugin({
|
|
33
31
|
key: new PluginKey('csp-fix'),
|
|
34
32
|
props: {
|
|
35
33
|
nodeViews: {
|
|
36
|
-
paragraph:
|
|
37
|
-
div:
|
|
38
|
-
table_wrapper:
|
|
39
|
-
table_caption_external:
|
|
40
|
-
table:
|
|
41
|
-
table_row:
|
|
42
|
-
table_cell:
|
|
43
|
-
table_header:
|
|
44
|
-
image:
|
|
34
|
+
paragraph: (node, view) => new CustomNodeView(node, view, 'p'),
|
|
35
|
+
div: (node, view) => new CustomNodeView(node, view, 'div'),
|
|
36
|
+
table_wrapper: (node, view) => new CustomNodeView(node, view, 'div'),
|
|
37
|
+
table_caption_external: (node, view) => new CustomNodeView(node, view, 'div'),
|
|
38
|
+
table: (node, view) => new CustomNodeView(node, view, 'table'),
|
|
39
|
+
table_row: (node, view) => new CustomNodeView(node, view, 'tr'),
|
|
40
|
+
table_cell: (node, view) => new CustomNodeView(node, view, 'td'),
|
|
41
|
+
table_header: (node, view) => new CustomNodeView(node, view, 'th'),
|
|
42
|
+
image: (node, view) => new CustomNodeView(node, view, 'img', true)
|
|
45
43
|
},
|
|
46
44
|
markViews: {
|
|
47
|
-
style:
|
|
45
|
+
style: (mark, view) => new StyleView(mark, view)
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
48
|
});
|
|
51
49
|
};
|
|
50
|
+
|
|
51
|
+
export { cspFix };
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluginKey, Plugin } from 'prosemirror-state';
|
|
2
2
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
3
|
+
|
|
3
4
|
// https://discuss.prosemirror.net/t/passing-data-between-plugins/1843
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (key === void 0) { key = textHighlightKey; }
|
|
5
|
+
const textHighlightKey = new PluginKey('highlight');
|
|
6
|
+
function textHighlight(key = textHighlightKey) {
|
|
7
7
|
return new Plugin({
|
|
8
|
-
key
|
|
8
|
+
key,
|
|
9
9
|
state: {
|
|
10
|
-
init
|
|
11
|
-
apply
|
|
10
|
+
init() { return null; },
|
|
11
|
+
apply(tr) { return tr.getMeta(this.spec.key); }
|
|
12
12
|
},
|
|
13
13
|
props: {
|
|
14
|
-
decorations
|
|
15
|
-
|
|
16
|
-
.map(
|
|
14
|
+
decorations(state) {
|
|
15
|
+
const decorations = (this.spec.key.getState(state) || [])
|
|
16
|
+
.map((d) => Decoration.inline(d.from, d.to, d.attrs));
|
|
17
17
|
return DecorationSet.create(state.doc, decorations);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
export { textHighlight, textHighlightKey };
|