@progress/kendo-editor-common 1.11.9-dev.202412020819 → 1.11.9-develop.2
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 +389 -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 +14 -29
- package/dist/npm/utils.js +133 -145
- package/package.json +35 -53
- 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/npm/inline-style.js
CHANGED
|
@@ -1,99 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return (0, utils_1.changeStylesString)(elementStyle, toChange);
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var prosemirrorTransform = require('prosemirror-transform');
|
|
4
|
+
var prosemirrorState = require('prosemirror-state');
|
|
5
|
+
var utils = require('./utils.js');
|
|
6
|
+
var mark = require('./mark.js');
|
|
7
|
+
|
|
8
|
+
const changeStyleFromMark = (marks, toChange) => {
|
|
9
|
+
const styleMark = marks.find(m => m.type.name === 'style');
|
|
10
|
+
const elementStyle = styleMark && styleMark.attrs.style;
|
|
11
|
+
return utils.changeStylesString(elementStyle, toChange);
|
|
13
12
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
tr.doc.nodesBetween(from, to,
|
|
13
|
+
const changeStyleMark = (tr, from, to, attrs, markType) => {
|
|
14
|
+
const mark = markType.create({ style: attrs.style });
|
|
15
|
+
let removed = [], added = [], removing = null, adding = null;
|
|
16
|
+
tr.doc.nodesBetween(from, to, (node, pos, parent) => {
|
|
18
17
|
if (!node.isInline) {
|
|
19
18
|
return;
|
|
20
19
|
}
|
|
21
|
-
|
|
20
|
+
const marks = node.marks;
|
|
22
21
|
if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) {
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to);
|
|
23
|
+
const newStyle = changeStyleFromMark(marks, attrs);
|
|
25
24
|
if (newStyle.changed || attrs.newValue) {
|
|
26
|
-
|
|
27
|
-
{ style: newStyle.style || null } : { style:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
for (
|
|
25
|
+
const style = newStyle.changed ?
|
|
26
|
+
{ style: newStyle.style || null } : { style: `${[attrs.style]}: ${attrs.newValue};` };
|
|
27
|
+
const currentMark = markType.isInSet(marks) ? marks.find(m => m.type.name === 'style') : null;
|
|
28
|
+
const newMarkAttrs = currentMark ? { ...currentMark.attrs, ...style } : style;
|
|
29
|
+
const newStyleMark = markType.create(newMarkAttrs);
|
|
30
|
+
const newSet = newStyleMark.addToSet(marks);
|
|
31
|
+
for (let i = 0; i < marks.length; i++) {
|
|
33
32
|
if (!marks[i].isInSet(newSet)) {
|
|
34
33
|
if (removing && removing.to === start && removing.mark.eq(marks[i])) {
|
|
35
34
|
removing.to = end;
|
|
36
35
|
}
|
|
37
36
|
else {
|
|
38
|
-
removing = new
|
|
37
|
+
removing = new prosemirrorTransform.RemoveMarkStep(start, end, marks[i]);
|
|
39
38
|
removed.push(removing);
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const previousAdded = adding && adding.to === start;
|
|
43
|
+
const sameAdding = previousAdded && newStyleMark.attrs.style === adding.mark.attrs.style;
|
|
45
44
|
if (previousAdded && sameAdding) {
|
|
46
45
|
adding.to = end;
|
|
47
46
|
}
|
|
48
|
-
else if (Object.keys(
|
|
49
|
-
adding = new
|
|
47
|
+
else if (Object.keys(newMarkAttrs).some(attrName => newMarkAttrs[attrName] !== null)) {
|
|
48
|
+
adding = new prosemirrorTransform.AddMarkStep(start, end, newStyleMark);
|
|
50
49
|
added.push(adding);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
});
|
|
55
|
-
removed.forEach(
|
|
56
|
-
added.forEach(
|
|
54
|
+
removed.forEach(s => tr.step(s));
|
|
55
|
+
added.forEach(s => tr.step(s));
|
|
57
56
|
return removed.length + added.length > 0;
|
|
58
57
|
};
|
|
59
58
|
/**
|
|
60
59
|
* Used by FontSize and FontName tools for getting their state.
|
|
61
60
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return marks.map(
|
|
61
|
+
const getInlineStyles = (state, style) => {
|
|
62
|
+
const styleMark = state.schema.marks.style;
|
|
63
|
+
const marks = styleMark ? mark.selectionMarks(state, styleMark) : [];
|
|
64
|
+
return marks.map(mark$1 => mark.styleValue(mark$1, style)).filter(m => m !== null);
|
|
66
65
|
};
|
|
67
|
-
|
|
68
|
-
var changeStyle = function (markType, attrs) {
|
|
66
|
+
const changeStyle = (markType, attrs) => {
|
|
69
67
|
return function (state, dispatch, tr) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if ((empty && !$cursor) || !
|
|
68
|
+
const { empty, ranges } = state.selection;
|
|
69
|
+
const $cursor = state.selection instanceof prosemirrorState.TextSelection && state.selection.$cursor;
|
|
70
|
+
if ((empty && !$cursor) || !mark.markApplies(state.doc, ranges, markType)) {
|
|
73
71
|
return false;
|
|
74
72
|
}
|
|
75
|
-
|
|
73
|
+
let result = false;
|
|
76
74
|
if (dispatch) {
|
|
77
|
-
|
|
75
|
+
const transaction = tr || state.tr;
|
|
78
76
|
if ($cursor) {
|
|
79
|
-
|
|
77
|
+
const currentMarks = state.storedMarks || $cursor.marks();
|
|
80
78
|
if (markType.isInSet(currentMarks)) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (
|
|
79
|
+
const newStyle = changeStyleFromMark(currentMarks, attrs);
|
|
80
|
+
const styleMark = currentMarks.find(m => m.type.name === 'style');
|
|
81
|
+
const newAttrs = { ...(styleMark ? styleMark.attrs : {}), style: newStyle.style || null };
|
|
82
|
+
if (utils.shallowEqual(styleMark.attrs, newAttrs)) {
|
|
85
83
|
return false;
|
|
86
84
|
}
|
|
87
85
|
dispatch(transaction.removeStoredMark(markType));
|
|
88
|
-
if (Object.keys(
|
|
89
|
-
dispatch(transaction.addStoredMark(markType.create(
|
|
86
|
+
if (Object.keys(newAttrs).some(attrName => newAttrs[attrName] !== null)) {
|
|
87
|
+
dispatch(transaction.addStoredMark(markType.create(newAttrs)));
|
|
90
88
|
}
|
|
91
89
|
result = true;
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
92
|
else {
|
|
95
|
-
for (
|
|
96
|
-
|
|
93
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
94
|
+
const { $from, $to } = ranges[i];
|
|
97
95
|
result = changeStyleMark(transaction, $from.pos, $to.pos, attrs, markType) || result;
|
|
98
96
|
}
|
|
99
97
|
if (result) {
|
|
@@ -108,68 +106,67 @@ var changeStyle = function (markType, attrs) {
|
|
|
108
106
|
/**
|
|
109
107
|
* Used by bold, italic, ... and link commands.
|
|
110
108
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
109
|
+
const toggleInlineFormat = (options, tr, markAttrs) => (state, dispatch) => {
|
|
110
|
+
const marks = state.schema.marks;
|
|
111
|
+
const { altStyle, altMarks = [], mark: mark$1 } = options;
|
|
112
|
+
const transaction = tr || state.tr;
|
|
113
|
+
let styleRemoved = false;
|
|
114
|
+
let dispatched = false;
|
|
115
|
+
const markDispatched = () => dispatched = true;
|
|
118
116
|
if (altStyle && marks.style) {
|
|
119
|
-
|
|
117
|
+
const cmd = changeStyle(marks.style, { style: altStyle.name, value: altStyle.value });
|
|
120
118
|
styleRemoved = cmd(state, markDispatched, transaction);
|
|
121
119
|
}
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
const allMarks = [mark$1, ...altMarks].filter(m => marks[m]);
|
|
121
|
+
const toRemove = allMarks.map(m => mark.hasMark(state, { mark: m }) && marks[m]).filter(m => m);
|
|
124
122
|
if (toRemove.length) {
|
|
125
|
-
|
|
123
|
+
mark.removeMarks(toRemove, state, markDispatched, transaction);
|
|
126
124
|
}
|
|
127
125
|
else {
|
|
128
126
|
if (!styleRemoved) {
|
|
129
|
-
|
|
127
|
+
mark.toggleMark(marks[mark$1], markAttrs, transaction)(state, markDispatched);
|
|
130
128
|
}
|
|
131
129
|
}
|
|
132
130
|
if (dispatched) {
|
|
133
131
|
dispatch(transaction);
|
|
134
132
|
}
|
|
135
133
|
return dispatched;
|
|
136
|
-
};
|
|
137
|
-
exports.toggleInlineFormat = toggleInlineFormat;
|
|
134
|
+
};
|
|
138
135
|
/**
|
|
139
136
|
* Used by FontSize, FontName, Color and BackColor commands.
|
|
140
137
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
138
|
+
const applyInlineStyle = (options, command) => (state, dispatch) => {
|
|
139
|
+
const marks = state.schema.marks;
|
|
140
|
+
const markType = marks.style;
|
|
141
|
+
const attrs = {
|
|
145
142
|
style: options.style, value: /^.+$/, newValue: options.value
|
|
146
143
|
};
|
|
147
|
-
|
|
144
|
+
const tr = state.tr;
|
|
148
145
|
if (command) {
|
|
149
146
|
tr.setMeta('commandName', command);
|
|
150
147
|
}
|
|
151
148
|
tr.setMeta('args', options);
|
|
152
|
-
|
|
153
|
-
if ((empty && !$cursor) || !markType || !
|
|
149
|
+
const { empty, $cursor, ranges } = state.selection;
|
|
150
|
+
if ((empty && !$cursor) || !markType || !mark.markApplies(state.doc, ranges, markType)) {
|
|
154
151
|
return false;
|
|
155
152
|
}
|
|
156
153
|
// Empty selection
|
|
157
154
|
if ($cursor) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
155
|
+
const marksFromSelection = state.storedMarks || $cursor.marks();
|
|
156
|
+
const currentMark = markType.isInSet(marksFromSelection) ? marksFromSelection.find(m => m.type.name === 'style') : null;
|
|
157
|
+
const newStyles = { style: null };
|
|
161
158
|
if (currentMark && currentMark.attrs.style) {
|
|
162
|
-
|
|
159
|
+
const resultStyles = utils.changeStylesString(currentMark.attrs.style, attrs);
|
|
163
160
|
if (resultStyles.changed && resultStyles.style) {
|
|
164
161
|
newStyles.style = resultStyles.style;
|
|
165
162
|
}
|
|
166
163
|
}
|
|
167
164
|
else if (attrs.newValue) {
|
|
168
|
-
newStyles.style =
|
|
165
|
+
newStyles.style = `${[attrs.style]}: ${attrs.newValue};`;
|
|
169
166
|
}
|
|
170
|
-
|
|
171
|
-
if (Object.keys(
|
|
172
|
-
dispatch(tr.addStoredMark(markType.create(
|
|
167
|
+
const newMarkAttrs = currentMark ? { ...currentMark.attrs, ...newStyles } : newStyles;
|
|
168
|
+
if (Object.keys(newMarkAttrs).some(attrName => newMarkAttrs[attrName] !== null)) {
|
|
169
|
+
dispatch(tr.addStoredMark(markType.create(newMarkAttrs)));
|
|
173
170
|
}
|
|
174
171
|
else {
|
|
175
172
|
dispatch(tr.removeStoredMark(markType));
|
|
@@ -177,5 +174,8 @@ var applyInlineStyle = function (options, command) { return function (state, dis
|
|
|
177
174
|
return true;
|
|
178
175
|
}
|
|
179
176
|
return changeStyle(markType, attrs)(state, dispatch, tr);
|
|
180
|
-
};
|
|
177
|
+
};
|
|
178
|
+
|
|
181
179
|
exports.applyInlineStyle = applyInlineStyle;
|
|
180
|
+
exports.getInlineStyles = getInlineStyles;
|
|
181
|
+
exports.toggleInlineFormat = toggleInlineFormat;
|
package/dist/npm/link.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
declare const removeLink: (options: any, tr?: any) => (state: any, dispatch: any) => void;
|
|
2
|
+
declare const applyLink: ({ mark, attrs }: {
|
|
3
3
|
mark: any;
|
|
4
4
|
attrs: any;
|
|
5
5
|
}, commandName?: string) => (state: any, dispatch: any) => boolean;
|
|
6
|
+
|
|
7
|
+
export { applyLink, removeLink };
|
package/dist/npm/link.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var inlineStyle = require('./inline-style.js');
|
|
4
|
+
var mark = require('./mark.js');
|
|
5
|
+
var prosemirrorState = require('prosemirror-state');
|
|
6
|
+
|
|
7
|
+
const modifyLink = (options, tr) => (state, dispatch) => {
|
|
8
|
+
const { $cursor, from, to } = state.selection;
|
|
9
|
+
const markType = state.schema.marks[options.mark];
|
|
10
10
|
if (!$cursor) {
|
|
11
|
-
tr.doc.nodesBetween(from, to,
|
|
11
|
+
tr.doc.nodesBetween(from, to, (node, pos) => {
|
|
12
12
|
if (node.isInline && markType.isInSet(node.marks)) {
|
|
13
13
|
tr.removeMark(pos, pos + node.nodeSize, markType);
|
|
14
14
|
tr.addMark(pos, pos + node.nodeSize, markType.create(options.attrs));
|
|
@@ -17,11 +17,11 @@ var modifyLink = function (options, tr) { return function (state, dispatch) {
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const parentNode = $cursor.parent;
|
|
21
|
+
const cursorNodeIndex = $cursor.index();
|
|
22
|
+
const mark = parentNode.child(cursorNodeIndex).marks.find(m => m.type === markType);
|
|
23
|
+
const childCount = parentNode.childCount;
|
|
24
|
+
let linkStart = $cursor.pos - $cursor.textOffset, linkSize = parentNode.child(cursorNodeIndex).nodeSize, index, nodeSize;
|
|
25
25
|
index = cursorNodeIndex - 1;
|
|
26
26
|
while (index >= 0 && mark.isInSet(parentNode.child(index).marks)) {
|
|
27
27
|
nodeSize = parentNode.child(index).nodeSize;
|
|
@@ -38,74 +38,71 @@ var modifyLink = function (options, tr) { return function (state, dispatch) {
|
|
|
38
38
|
tr.addMark(linkStart, linkStart + linkSize, markType.create(options.attrs));
|
|
39
39
|
dispatch(tr);
|
|
40
40
|
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
};
|
|
42
|
+
const removeLink = (options, tr) => (state, dispatch) => {
|
|
43
|
+
const { $cursor } = state.selection;
|
|
44
44
|
if (!$cursor) {
|
|
45
|
-
|
|
45
|
+
inlineStyle.toggleInlineFormat(options, tr)(state, dispatch);
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
const parentNode = $cursor.parent;
|
|
49
|
+
const cursorNodeIndex = $cursor.index();
|
|
50
|
+
const toolMark = state.schema.marks[options.mark];
|
|
51
|
+
const mark$1 = parentNode.child(cursorNodeIndex).marks.find(m => m.type === toolMark);
|
|
52
|
+
const childCount = parentNode.childCount;
|
|
53
|
+
let linkStart = $cursor.pos - $cursor.textOffset, linkSize = parentNode.child(cursorNodeIndex).nodeSize, index, nodeSize;
|
|
54
54
|
index = cursorNodeIndex - 1;
|
|
55
|
-
while (index >= 0 && mark.isInSet(parentNode.child(index).marks)) {
|
|
55
|
+
while (index >= 0 && mark$1.isInSet(parentNode.child(index).marks)) {
|
|
56
56
|
nodeSize = parentNode.child(index).nodeSize;
|
|
57
57
|
linkSize += nodeSize;
|
|
58
58
|
linkStart -= nodeSize;
|
|
59
59
|
index -= 1;
|
|
60
60
|
}
|
|
61
61
|
index = cursorNodeIndex + 1;
|
|
62
|
-
while (index < childCount && mark.isInSet(parentNode.child(index).marks)) {
|
|
62
|
+
while (index < childCount && mark$1.isInSet(parentNode.child(index).marks)) {
|
|
63
63
|
linkSize += parentNode.child(index).nodeSize;
|
|
64
64
|
index += 1;
|
|
65
65
|
}
|
|
66
|
-
dispatch(
|
|
66
|
+
dispatch(mark.removeMark(tr || state.tr, linkStart, linkStart + linkSize, mark$1));
|
|
67
67
|
}
|
|
68
|
-
};
|
|
69
|
-
exports.removeLink = removeLink;
|
|
68
|
+
};
|
|
70
69
|
/**
|
|
71
70
|
* Returns a mark which wraps the selection.
|
|
72
71
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
const getParentMark = (state, markType) => {
|
|
73
|
+
const marks = mark.selectionMarks(state, markType);
|
|
75
74
|
return marks.length === 1 && marks[0] ? marks[0] : null;
|
|
76
75
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
const applyLink = ({ mark: mark$1, attrs }, commandName = 'link') => (state, dispatch) => {
|
|
77
|
+
const marks = state.schema.marks;
|
|
78
|
+
const tr = state.tr;
|
|
79
|
+
if (commandName) {
|
|
80
|
+
tr.setMeta('commandName', commandName);
|
|
81
|
+
tr.setMeta('args', attrs);
|
|
82
|
+
}
|
|
83
|
+
let dispatched = false;
|
|
84
|
+
const markDispatched = () => dispatched = true;
|
|
85
|
+
if (getParentMark(state, marks[mark$1])) {
|
|
86
|
+
modifyLink({ mark: mark$1, attrs }, tr)(state, markDispatched);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
let nextState = state;
|
|
90
|
+
if (mark.hasMark(state, { mark: mark$1 })) {
|
|
91
|
+
removeLink({ mark: mark$1, attrs }, tr)(state, markDispatched);
|
|
92
|
+
nextState = prosemirrorState.EditorState.create({ doc: tr.doc, selection: tr.selection });
|
|
86
93
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (getParentMark(state, marks[mark])) {
|
|
90
|
-
modifyLink({ mark: mark, attrs: attrs }, tr)(state, markDispatched);
|
|
94
|
+
if (dispatched) {
|
|
95
|
+
mark.toggleMark(marks[mark$1], attrs, tr)(nextState, markDispatched);
|
|
91
96
|
}
|
|
92
97
|
else {
|
|
93
|
-
|
|
94
|
-
if ((0, mark_1.hasMark)(state, { mark: mark })) {
|
|
95
|
-
(0, exports.removeLink)({ mark: mark, attrs: attrs }, tr)(state, markDispatched);
|
|
96
|
-
nextState = prosemirror_state_1.EditorState.create({ doc: tr.doc, selection: tr.selection });
|
|
97
|
-
}
|
|
98
|
-
if (dispatched) {
|
|
99
|
-
(0, mark_1.toggleMark)(marks[mark], attrs, tr)(nextState, markDispatched);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
(0, inline_style_1.toggleInlineFormat)({ mark: mark }, tr, attrs)(nextState, markDispatched);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (dispatched) {
|
|
106
|
-
dispatch(tr);
|
|
98
|
+
inlineStyle.toggleInlineFormat({ mark: mark$1 }, tr, attrs)(nextState, markDispatched);
|
|
107
99
|
}
|
|
108
|
-
|
|
109
|
-
|
|
100
|
+
}
|
|
101
|
+
if (dispatched) {
|
|
102
|
+
dispatch(tr);
|
|
103
|
+
}
|
|
104
|
+
return dispatched;
|
|
110
105
|
};
|
|
106
|
+
|
|
111
107
|
exports.applyLink = applyLink;
|
|
108
|
+
exports.removeLink = removeLink;
|
package/dist/npm/listConvert.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
html = html.replace(msoListRegExp,
|
|
8
|
-
return
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var source = require('./source.js');
|
|
4
|
+
|
|
5
|
+
const msoListRegExp = /style=['"]?[^'"]*?mso-list:\s*[a-zA-Z]+(\d+)\s[a-zA-Z]+(\d+)\s(\w+)/gi;
|
|
6
|
+
const extractListLevels = (html) => {
|
|
7
|
+
html = html.replace(msoListRegExp, (match, list, level) => {
|
|
8
|
+
return `datalist="${list}" datalevel="${level}" ${match}`;
|
|
9
9
|
});
|
|
10
10
|
return html;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
const isPartOfListItem = (element) => {
|
|
13
13
|
return /^MsoListParagraph/.test(element.className);
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const innerText = (node) => {
|
|
16
|
+
let text = node.innerHTML;
|
|
17
17
|
text = text.replace(/<!--(.|\s)*?-->/gi, '');
|
|
18
18
|
text = text.replace(/<\/?[^>]+?\/?>/gm, '');
|
|
19
19
|
return text;
|
|
20
20
|
};
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const createList = (type, styleType) => {
|
|
22
|
+
const list = document.createElement(type);
|
|
23
23
|
list.style.listStyleType = styleType;
|
|
24
24
|
return list;
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
const guessUnorderedListStyle = (symbol) => {
|
|
27
27
|
if (/^[\u2022\u00b7\u00FC\u00D8\u002dv-]/.test(symbol)) {
|
|
28
28
|
return null; // return "disc"; //default CSS value
|
|
29
29
|
}
|
|
@@ -34,21 +34,21 @@ var guessUnorderedListStyle = function (symbol) {
|
|
|
34
34
|
return 'square';
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const guessOrderedListStyle = (symbol) => {
|
|
38
|
+
let type = null;
|
|
39
39
|
if (!/^\d/.test(symbol)) {
|
|
40
40
|
type = (/^[a-z]/.test(symbol) ? 'lower-' : 'upper-') +
|
|
41
41
|
(/^[ivxlcdm]/i.test(symbol) ? 'roman' : 'alpha');
|
|
42
42
|
}
|
|
43
43
|
return type;
|
|
44
44
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
Array.from(nodes).forEach(
|
|
45
|
+
const mapListsCandidates = (nodes, groups) => {
|
|
46
|
+
let group = [];
|
|
47
|
+
Array.from(nodes).forEach(node => {
|
|
48
48
|
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
const element = node;
|
|
52
52
|
if (element.getAttribute('datalist')) {
|
|
53
53
|
group.push(node);
|
|
54
54
|
groups.add(group);
|
|
@@ -62,16 +62,16 @@ var mapListsCandidates = function (nodes, groups) {
|
|
|
62
62
|
mapListsCandidates(element.children, groups);
|
|
63
63
|
}
|
|
64
64
|
else if (element.nodeName === 'TABLE') {
|
|
65
|
-
Array.from(element.querySelectorAll('td,th')).forEach(
|
|
65
|
+
Array.from(element.querySelectorAll('td,th')).forEach(cell => {
|
|
66
66
|
mapListsCandidates(cell.children, groups);
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
const listTypes = (p) => {
|
|
73
|
+
let html = p.innerHTML;
|
|
74
|
+
const trimStartText = (t) => {
|
|
75
75
|
return t.replace(/^(?: |[\u00a0\n\r\s])+/, '');
|
|
76
76
|
};
|
|
77
77
|
html = html.replace(/<\/?\w+[^>]*>/g, '').replace(/ /g, '\u00a0');
|
|
@@ -88,8 +88,8 @@ var listTypes = function (p) {
|
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
const convertToLi = (p) => {
|
|
92
|
+
let content, name = p.nodeName.toLowerCase();
|
|
93
93
|
if (p.firstChild && p.firstChild.nodeType === Node.COMMENT_NODE) {
|
|
94
94
|
p.removeChild(p.firstChild);
|
|
95
95
|
}
|
|
@@ -116,20 +116,20 @@ var convertToLi = function (p) {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
p.parentNode.removeChild(p);
|
|
119
|
-
|
|
120
|
-
li.appendChild(
|
|
119
|
+
const li = document.createElement('li');
|
|
120
|
+
li.appendChild(source.htmlToFragment(content));
|
|
121
121
|
return li;
|
|
122
122
|
};
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
const toList = (blockNodes) => {
|
|
124
|
+
let lastMargin = -1, levels = {}, li, rootMargin, rootIndex, lastRootLi, isLastRootLi, rootList, items, i, p, type, margin, list, listData;
|
|
125
125
|
for (i = 0; i < blockNodes.length; i++) {
|
|
126
126
|
p = blockNodes[i];
|
|
127
127
|
listData = {
|
|
128
128
|
datalist: p.getAttribute('datalist'),
|
|
129
129
|
datalevel: p.getAttribute('datalevel')
|
|
130
130
|
};
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
const listIndex = listData.datalist;
|
|
132
|
+
const listType = listTypes(p);
|
|
133
133
|
type = listType && listType.tag;
|
|
134
134
|
if (!type) {
|
|
135
135
|
if (li && (!isLastRootLi || isPartOfListItem(p))) {
|
|
@@ -148,14 +148,14 @@ var toList = function (blockNodes) {
|
|
|
148
148
|
if (!listData.datalevel && !p.style.marginLeft) {
|
|
149
149
|
continue;
|
|
150
150
|
}
|
|
151
|
-
|
|
151
|
+
const levelType = type + listIndex;
|
|
152
152
|
if (!levels[margin]) {
|
|
153
153
|
levels[margin] = {};
|
|
154
154
|
}
|
|
155
155
|
if (!rootMargin || rootMargin < 0) {
|
|
156
156
|
rootMargin = margin;
|
|
157
157
|
rootIndex = listIndex;
|
|
158
|
-
items = blockNodes.filter(
|
|
158
|
+
items = blockNodes.filter(e => e.getAttribute('datalist') === String(rootIndex));
|
|
159
159
|
lastRootLi = items[items.length - 1];
|
|
160
160
|
rootList = createList(type, listType && listType.style);
|
|
161
161
|
p.parentNode.insertBefore(rootList, p);
|
|
@@ -179,11 +179,12 @@ var toList = function (blockNodes) {
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
const convertMsLists = (html) => {
|
|
183
|
+
const container = source.htmlToFragment(extractListLevels(html));
|
|
184
|
+
const groups = new Set();
|
|
185
185
|
mapListsCandidates(container.children, groups);
|
|
186
|
-
groups.forEach(
|
|
187
|
-
return
|
|
186
|
+
groups.forEach(listsCandidates => toList(listsCandidates));
|
|
187
|
+
return source.fragmentToHtml(container);
|
|
188
188
|
};
|
|
189
|
+
|
|
189
190
|
exports.convertMsLists = convertMsLists;
|
package/dist/npm/lists.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Node } from 'prosemirror-model';
|
|
2
2
|
import { EditorState, Transaction } from 'prosemirror-state';
|
|
3
3
|
import { EditorView } from 'prosemirror-view';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
type ListOptions = {
|
|
6
6
|
listType: string;
|
|
7
7
|
orderedList: string;
|
|
8
8
|
bulletList: string;
|
|
@@ -15,9 +15,9 @@ declare type ListOptions = {
|
|
|
15
15
|
* @param attrs - The attributes of the list node
|
|
16
16
|
* @returns The extracted list-style-type.
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export {};
|
|
18
|
+
declare const listStyle: (attrs: Node["attrs"]) => string;
|
|
19
|
+
declare const toggleList: (state: EditorState, dispatch: (tr: Transaction) => void, view: EditorView, options: ListOptions, command?: string) => boolean;
|
|
20
|
+
declare function toggleUnorderedList(state: EditorState, dispatch: (tr: Transaction) => void, view: EditorView): any;
|
|
21
|
+
declare function toggleOrderedList(state: EditorState, dispatch: (tr: Transaction) => void, view: EditorView): any;
|
|
22
|
+
|
|
23
|
+
export { listStyle, toggleList, toggleOrderedList, toggleUnorderedList };
|