@progress/kendo-editor-common 1.12.2-develop.4 → 1.12.2-develop.6
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/js/kendo-editor-common.js +1 -1
- package/dist/cdn/main.js +1 -1
- package/dist/es/DOMSerializer.js +6 -7
- package/dist/es/align.js +3 -6
- package/dist/es/blockNode.js +11 -14
- package/dist/es/blockquote.js +2 -5
- package/dist/es/cleanFormatting.js +3 -6
- package/dist/es/config/align-rules.js +5 -7
- package/dist/es/config/commands.js +13 -9
- package/dist/es/config/constants.js +7 -9
- package/dist/es/config/indent-rules.js +3 -6
- package/dist/es/config/keymap.js +7 -10
- package/dist/es/config/list-settings.js +3 -5
- package/dist/es/config/schema.js +4 -6
- package/dist/es/find-replace.js +8 -10
- package/dist/es/flatten-spans.js +2 -5
- package/dist/es/image.js +2 -5
- package/dist/es/indent.js +11 -14
- package/dist/es/inline-style.js +10 -12
- package/dist/es/link.js +5 -8
- package/dist/es/listConvert.js +8 -9
- package/dist/es/lists.js +12 -15
- package/dist/es/main.js +34 -33
- package/dist/es/mark.js +16 -17
- package/dist/es/paste.js +10 -13
- package/dist/es/plugins/caret-color.js +5 -8
- package/dist/es/plugins/csp-fix.js +2 -5
- package/dist/es/plugins/highlight.js +3 -6
- package/dist/es/plugins/image-resize.js +8 -11
- package/dist/es/plugins/list-markers-styles.js +2 -5
- package/dist/es/plugins/placeholder.js +2 -5
- package/dist/es/plugins/resize-utils.js +2 -4
- package/dist/es/plugins/spaces-fix.js +1 -4
- package/dist/es/plugins/table-resize/column-resize.js +21 -24
- package/dist/es/plugins/table-resize/index.js +6 -9
- package/dist/es/plugins/table-resize/row-resize.js +23 -24
- package/dist/es/plugins/table-resize/table-resize.js +17 -20
- package/dist/es/plugins/table-resize/table-view.js +6 -9
- package/dist/es/plugins/table-resize/utils.js +10 -13
- package/dist/es/source.js +15 -18
- package/dist/es/table.js +15 -18
- package/dist/es/text.js +1 -3
- package/dist/es/types/active-marks.js +1 -0
- package/dist/es/types/command.js +1 -0
- package/dist/es/types/dispatchFn.js +1 -0
- package/dist/es/types/paste-cleanup-settings.js +1 -0
- package/dist/es/types/predicate.js +1 -0
- package/dist/es/utils.js +18 -21
- package/dist/npm/DOMSerializer.d.ts +35 -0
- package/dist/npm/DOMSerializer.js +10 -9
- package/dist/npm/align.d.ts +4 -7
- package/dist/npm/align.js +9 -10
- package/dist/npm/blockNode.d.ts +15 -12
- package/dist/npm/blockNode.js +28 -29
- package/dist/npm/blockquote.d.ts +2 -5
- package/dist/npm/blockquote.js +6 -7
- package/dist/npm/cleanFormatting.d.ts +3 -6
- package/dist/npm/cleanFormatting.js +7 -8
- package/dist/npm/config/align-rules.d.ts +6 -8
- package/dist/npm/config/align-rules.js +8 -13
- package/dist/npm/config/commands.d.ts +19 -11
- package/dist/npm/config/commands.js +16 -17
- package/dist/npm/config/constants.d.ts +7 -0
- package/dist/npm/config/constants.js +10 -17
- package/dist/npm/config/indent-rules.d.ts +4 -6
- package/dist/npm/config/indent-rules.js +8 -11
- package/dist/npm/config/keymap.d.ts +2 -5
- package/dist/npm/config/keymap.js +21 -22
- package/dist/npm/config/list-settings.d.ts +30 -0
- package/dist/npm/config/list-settings.js +10 -13
- package/dist/npm/config/schema.d.ts +2 -3
- package/dist/npm/config/schema.js +19 -20
- package/dist/npm/find-replace.d.ts +7 -10
- package/dist/npm/find-replace.js +20 -20
- package/dist/npm/flatten-spans.d.ts +1 -3
- package/dist/npm/flatten-spans.js +6 -7
- package/dist/npm/image.d.ts +3 -6
- package/dist/npm/image.js +5 -6
- package/dist/npm/indent.d.ts +9 -12
- package/dist/npm/indent.js +37 -38
- package/dist/npm/inline-style.d.ts +4 -7
- package/dist/npm/inline-style.js +28 -28
- package/dist/npm/link.d.ts +2 -4
- package/dist/npm/link.js +21 -22
- package/dist/npm/listConvert.d.ts +1 -3
- package/dist/npm/listConvert.js +13 -12
- package/dist/npm/lists.d.ts +8 -8
- package/dist/npm/lists.js +26 -27
- package/dist/npm/main.d.ts +34 -35
- package/dist/npm/main.js +214 -391
- package/dist/npm/mark.d.ts +17 -12
- package/dist/npm/mark.js +30 -29
- package/dist/npm/paste.d.ts +8 -11
- package/dist/npm/paste.js +19 -20
- package/dist/npm/plugins/caret-color.d.ts +2 -5
- package/dist/npm/plugins/caret-color.js +15 -17
- package/dist/npm/plugins/csp-fix.d.ts +1 -4
- package/dist/npm/plugins/csp-fix.js +8 -9
- package/dist/npm/plugins/highlight.d.ts +4 -7
- package/dist/npm/plugins/highlight.js +11 -13
- package/dist/npm/plugins/image-resize.d.ts +5 -7
- package/dist/npm/plugins/image-resize.js +35 -37
- package/dist/npm/plugins/list-markers-styles.d.ts +2 -5
- package/dist/npm/plugins/list-markers-styles.js +14 -16
- package/dist/npm/plugins/placeholder.d.ts +1 -4
- package/dist/npm/plugins/placeholder.js +10 -12
- package/dist/npm/plugins/resize-utils.d.ts +35 -0
- package/dist/npm/plugins/resize-utils.js +5 -7
- package/dist/npm/plugins/spaces-fix.d.ts +1 -4
- package/dist/npm/plugins/spaces-fix.js +9 -10
- package/dist/npm/plugins/table-resize/column-resize.d.ts +2 -0
- package/dist/npm/plugins/table-resize/column-resize.js +44 -46
- package/dist/npm/plugins/table-resize/index.d.ts +2 -5
- package/dist/npm/plugins/table-resize/index.js +13 -14
- package/dist/npm/plugins/table-resize/row-resize.d.ts +2 -0
- package/dist/npm/plugins/table-resize/row-resize.js +40 -40
- package/dist/npm/plugins/table-resize/table-resize.d.ts +18 -0
- package/dist/npm/plugins/table-resize/table-resize.js +51 -52
- package/dist/npm/plugins/table-resize/table-view.d.ts +28 -0
- package/dist/npm/plugins/table-resize/table-view.js +23 -24
- package/dist/npm/plugins/table-resize/utils.d.ts +17 -7
- package/dist/npm/plugins/table-resize/utils.js +24 -28
- package/dist/npm/source.d.ts +13 -16
- package/dist/npm/source.js +35 -36
- package/dist/npm/table.d.ts +9 -10
- package/dist/npm/table.js +33 -49
- package/dist/npm/text.d.ts +3 -6
- package/dist/npm/text.js +3 -3
- package/dist/npm/types/active-marks.d.ts +1 -4
- package/dist/npm/types/active-marks.js +2 -0
- package/dist/npm/types/command.d.ts +2 -5
- package/dist/npm/types/command.js +2 -0
- package/dist/npm/types/dispatchFn.d.ts +1 -4
- package/dist/npm/types/dispatchFn.js +2 -0
- package/dist/npm/types/paste-cleanup-settings.d.ts +1 -3
- package/dist/npm/types/paste-cleanup-settings.js +2 -0
- package/dist/npm/types/predicate.d.ts +1 -0
- package/dist/npm/types/predicate.js +2 -0
- package/dist/npm/utils.d.ts +33 -14
- package/dist/npm/utils.js +38 -39
- package/package.json +3 -50
- package/dist/es2015/DOMSerializer.js +0 -184
- package/dist/es2015/align.js +0 -43
- package/dist/es2015/blockNode.js +0 -180
- package/dist/es2015/blockquote.js +0 -26
- package/dist/es2015/cleanFormatting.js +0 -20
- package/dist/es2015/config/align-rules.js +0 -30
- package/dist/es2015/config/commands.js +0 -50
- package/dist/es2015/config/constants.js +0 -9
- package/dist/es2015/config/indent-rules.js +0 -42
- package/dist/es2015/config/keymap.js +0 -51
- package/dist/es2015/config/list-settings.js +0 -21
- package/dist/es2015/config/schema.js +0 -314
- package/dist/es2015/find-replace.js +0 -122
- package/dist/es2015/flatten-spans.js +0 -112
- package/dist/es2015/image.js +0 -10
- package/dist/es2015/indent.js +0 -105
- package/dist/es2015/inline-style.js +0 -177
- package/dist/es2015/link.js +0 -105
- package/dist/es2015/listConvert.js +0 -184
- package/dist/es2015/lists.js +0 -266
- package/dist/es2015/main.js +0 -44
- package/dist/es2015/mark.js +0 -239
- package/dist/es2015/node_modules/tslib/tslib.es6.js +0 -35
- package/dist/es2015/paste.js +0 -162
- package/dist/es2015/plugins/caret-color.js +0 -34
- package/dist/es2015/plugins/csp-fix.js +0 -51
- package/dist/es2015/plugins/highlight.js +0 -23
- package/dist/es2015/plugins/image-resize.js +0 -225
- package/dist/es2015/plugins/list-markers-styles.js +0 -104
- package/dist/es2015/plugins/placeholder.js +0 -27
- package/dist/es2015/plugins/resize-utils.js +0 -13
- package/dist/es2015/plugins/spaces-fix.js +0 -46
- package/dist/es2015/plugins/table-resize/column-resize.js +0 -267
- package/dist/es2015/plugins/table-resize/index.js +0 -12
- package/dist/es2015/plugins/table-resize/row-resize.js +0 -234
- package/dist/es2015/plugins/table-resize/table-resize.js +0 -278
- package/dist/es2015/plugins/table-resize/table-view.js +0 -128
- package/dist/es2015/plugins/table-resize/utils.js +0 -93
- package/dist/es2015/source.js +0 -251
- package/dist/es2015/table.js +0 -132
- package/dist/es2015/text.js +0 -5
- package/dist/es2015/utils.js +0 -289
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { RemoveMarkStep, AddMarkStep } from 'prosemirror-transform';
|
|
2
|
-
import { TextSelection } from 'prosemirror-state';
|
|
3
|
-
import { changeStylesString, shallowEqual } from './utils.js';
|
|
4
|
-
import { markApplies, selectionMarks, styleValue, hasMark, removeMarks, toggleMark } from './mark.js';
|
|
5
|
-
|
|
6
|
-
const changeStyleFromMark = (marks, toChange) => {
|
|
7
|
-
const styleMark = marks.find(m => m.type.name === 'style');
|
|
8
|
-
const elementStyle = styleMark && styleMark.attrs.style;
|
|
9
|
-
return changeStylesString(elementStyle, toChange);
|
|
10
|
-
};
|
|
11
|
-
const changeStyleMark = (tr, from, to, attrs, markType) => {
|
|
12
|
-
const mark = markType.create({ style: attrs.style });
|
|
13
|
-
let removed = [], added = [], removing = null, adding = null;
|
|
14
|
-
tr.doc.nodesBetween(from, to, (node, pos, parent) => {
|
|
15
|
-
if (!node.isInline) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const marks = node.marks;
|
|
19
|
-
if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) {
|
|
20
|
-
const start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to);
|
|
21
|
-
const newStyle = changeStyleFromMark(marks, attrs);
|
|
22
|
-
if (newStyle.changed || attrs.newValue) {
|
|
23
|
-
const style = newStyle.changed ?
|
|
24
|
-
{ style: newStyle.style || null } : { style: `${[attrs.style]}: ${attrs.newValue};` };
|
|
25
|
-
const currentMark = markType.isInSet(marks) ? marks.find(m => m.type.name === 'style') : null;
|
|
26
|
-
const newMarkAttrs = currentMark ? Object.assign(Object.assign({}, currentMark.attrs), style) : style;
|
|
27
|
-
const newStyleMark = markType.create(newMarkAttrs);
|
|
28
|
-
const newSet = newStyleMark.addToSet(marks);
|
|
29
|
-
for (let i = 0; i < marks.length; i++) {
|
|
30
|
-
if (!marks[i].isInSet(newSet)) {
|
|
31
|
-
if (removing && removing.to === start && removing.mark.eq(marks[i])) {
|
|
32
|
-
removing.to = end;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
removing = new RemoveMarkStep(start, end, marks[i]);
|
|
36
|
-
removed.push(removing);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const previousAdded = adding && adding.to === start;
|
|
41
|
-
const sameAdding = previousAdded && newStyleMark.attrs.style === adding.mark.attrs.style;
|
|
42
|
-
if (previousAdded && sameAdding) {
|
|
43
|
-
adding.to = end;
|
|
44
|
-
}
|
|
45
|
-
else if (Object.keys(newMarkAttrs).some(attrName => newMarkAttrs[attrName] !== null)) {
|
|
46
|
-
adding = new AddMarkStep(start, end, newStyleMark);
|
|
47
|
-
added.push(adding);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
removed.forEach(s => tr.step(s));
|
|
53
|
-
added.forEach(s => tr.step(s));
|
|
54
|
-
return removed.length + added.length > 0;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Used by FontSize and FontName tools for getting their state.
|
|
58
|
-
*/
|
|
59
|
-
const getInlineStyles = (state, style) => {
|
|
60
|
-
const styleMark = state.schema.marks.style;
|
|
61
|
-
const marks = styleMark ? selectionMarks(state, styleMark) : [];
|
|
62
|
-
return marks.map(mark => styleValue(mark, style)).filter(m => m !== null);
|
|
63
|
-
};
|
|
64
|
-
const changeStyle = (markType, attrs) => {
|
|
65
|
-
return function (state, dispatch, tr) {
|
|
66
|
-
const { empty, ranges } = state.selection;
|
|
67
|
-
const $cursor = state.selection instanceof TextSelection && state.selection.$cursor;
|
|
68
|
-
if ((empty && !$cursor) || !markApplies(state.doc, ranges, markType)) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
let result = false;
|
|
72
|
-
if (dispatch) {
|
|
73
|
-
const transaction = tr || state.tr;
|
|
74
|
-
if ($cursor) {
|
|
75
|
-
const currentMarks = state.storedMarks || $cursor.marks();
|
|
76
|
-
if (markType.isInSet(currentMarks)) {
|
|
77
|
-
const newStyle = changeStyleFromMark(currentMarks, attrs);
|
|
78
|
-
const styleMark = currentMarks.find(m => m.type.name === 'style');
|
|
79
|
-
const newAttrs = Object.assign(Object.assign({}, (styleMark ? styleMark.attrs : {})), { style: newStyle.style || null });
|
|
80
|
-
if (shallowEqual(styleMark.attrs, newAttrs)) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
dispatch(transaction.removeStoredMark(markType));
|
|
84
|
-
if (Object.keys(newAttrs).some(attrName => newAttrs[attrName] !== null)) {
|
|
85
|
-
dispatch(transaction.addStoredMark(markType.create(newAttrs)));
|
|
86
|
-
}
|
|
87
|
-
result = true;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
for (let i = 0; i < ranges.length; i++) {
|
|
92
|
-
const { $from, $to } = ranges[i];
|
|
93
|
-
result = changeStyleMark(transaction, $from.pos, $to.pos, attrs, markType) || result;
|
|
94
|
-
}
|
|
95
|
-
if (result) {
|
|
96
|
-
transaction.scrollIntoView();
|
|
97
|
-
dispatch(transaction);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return result;
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Used by bold, italic, ... and link commands.
|
|
106
|
-
*/
|
|
107
|
-
const toggleInlineFormat = (options, tr, markAttrs) => (state, dispatch) => {
|
|
108
|
-
const marks = state.schema.marks;
|
|
109
|
-
const { altStyle, altMarks = [], mark } = options;
|
|
110
|
-
const transaction = tr || state.tr;
|
|
111
|
-
let styleRemoved = false;
|
|
112
|
-
let dispatched = false;
|
|
113
|
-
const markDispatched = () => dispatched = true;
|
|
114
|
-
if (altStyle && marks.style) {
|
|
115
|
-
const cmd = changeStyle(marks.style, { style: altStyle.name, value: altStyle.value });
|
|
116
|
-
styleRemoved = cmd(state, markDispatched, transaction);
|
|
117
|
-
}
|
|
118
|
-
const allMarks = [mark, ...altMarks].filter(m => marks[m]);
|
|
119
|
-
const toRemove = allMarks.map(m => hasMark(state, { mark: m }) && marks[m]).filter(m => m);
|
|
120
|
-
if (toRemove.length) {
|
|
121
|
-
removeMarks(toRemove, state, markDispatched, transaction);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
if (!styleRemoved) {
|
|
125
|
-
toggleMark(marks[mark], markAttrs, transaction)(state, markDispatched);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (dispatched) {
|
|
129
|
-
dispatch(transaction);
|
|
130
|
-
}
|
|
131
|
-
return dispatched;
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* Used by FontSize, FontName, Color and BackColor commands.
|
|
135
|
-
*/
|
|
136
|
-
const applyInlineStyle = (options, command) => (state, dispatch) => {
|
|
137
|
-
const marks = state.schema.marks;
|
|
138
|
-
const markType = marks.style;
|
|
139
|
-
const attrs = {
|
|
140
|
-
style: options.style, value: /^.+$/, newValue: options.value
|
|
141
|
-
};
|
|
142
|
-
const tr = state.tr;
|
|
143
|
-
if (command) {
|
|
144
|
-
tr.setMeta('commandName', command);
|
|
145
|
-
}
|
|
146
|
-
tr.setMeta('args', options);
|
|
147
|
-
const { empty, $cursor, ranges } = state.selection;
|
|
148
|
-
if ((empty && !$cursor) || !markType || !markApplies(state.doc, ranges, markType)) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
// Empty selection
|
|
152
|
-
if ($cursor) {
|
|
153
|
-
const marksFromSelection = state.storedMarks || $cursor.marks();
|
|
154
|
-
const currentMark = markType.isInSet(marksFromSelection) ? marksFromSelection.find(m => m.type.name === 'style') : null;
|
|
155
|
-
const newStyles = { style: null };
|
|
156
|
-
if (currentMark && currentMark.attrs.style) {
|
|
157
|
-
const resultStyles = changeStylesString(currentMark.attrs.style, attrs);
|
|
158
|
-
if (resultStyles.changed && resultStyles.style) {
|
|
159
|
-
newStyles.style = resultStyles.style;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
else if (attrs.newValue) {
|
|
163
|
-
newStyles.style = `${[attrs.style]}: ${attrs.newValue};`;
|
|
164
|
-
}
|
|
165
|
-
const newMarkAttrs = currentMark ? Object.assign(Object.assign({}, currentMark.attrs), newStyles) : newStyles;
|
|
166
|
-
if (Object.keys(newMarkAttrs).some(attrName => newMarkAttrs[attrName] !== null)) {
|
|
167
|
-
dispatch(tr.addStoredMark(markType.create(newMarkAttrs)));
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
dispatch(tr.removeStoredMark(markType));
|
|
171
|
-
}
|
|
172
|
-
return true;
|
|
173
|
-
}
|
|
174
|
-
return changeStyle(markType, attrs)(state, dispatch, tr);
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
export { applyInlineStyle, getInlineStyles, toggleInlineFormat };
|
package/dist/es2015/link.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { toggleInlineFormat } from './inline-style.js';
|
|
2
|
-
import { hasMark, toggleMark, removeMark, selectionMarks } from './mark.js';
|
|
3
|
-
import { EditorState } from 'prosemirror-state';
|
|
4
|
-
|
|
5
|
-
const modifyLink = (options, tr) => (state, dispatch) => {
|
|
6
|
-
const { $cursor, from, to } = state.selection;
|
|
7
|
-
const markType = state.schema.marks[options.mark];
|
|
8
|
-
if (!$cursor) {
|
|
9
|
-
tr.doc.nodesBetween(from, to, (node, pos) => {
|
|
10
|
-
if (node.isInline && markType.isInSet(node.marks)) {
|
|
11
|
-
tr.removeMark(pos, pos + node.nodeSize, markType);
|
|
12
|
-
tr.addMark(pos, pos + node.nodeSize, markType.create(options.attrs));
|
|
13
|
-
dispatch(tr);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
const parentNode = $cursor.parent;
|
|
19
|
-
const cursorNodeIndex = $cursor.index();
|
|
20
|
-
const mark = parentNode.child(cursorNodeIndex).marks.find(m => m.type === markType);
|
|
21
|
-
const childCount = parentNode.childCount;
|
|
22
|
-
let linkStart = $cursor.pos - $cursor.textOffset, linkSize = parentNode.child(cursorNodeIndex).nodeSize, index, nodeSize;
|
|
23
|
-
index = cursorNodeIndex - 1;
|
|
24
|
-
while (index >= 0 && mark.isInSet(parentNode.child(index).marks)) {
|
|
25
|
-
nodeSize = parentNode.child(index).nodeSize;
|
|
26
|
-
linkSize += nodeSize;
|
|
27
|
-
linkStart -= nodeSize;
|
|
28
|
-
index -= 1;
|
|
29
|
-
}
|
|
30
|
-
index = cursorNodeIndex + 1;
|
|
31
|
-
while (index < childCount && mark.isInSet(parentNode.child(index).marks)) {
|
|
32
|
-
linkSize += parentNode.child(index).nodeSize;
|
|
33
|
-
index += 1;
|
|
34
|
-
}
|
|
35
|
-
tr.removeMark(linkStart, linkStart + linkSize, markType);
|
|
36
|
-
tr.addMark(linkStart, linkStart + linkSize, markType.create(options.attrs));
|
|
37
|
-
dispatch(tr);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
const removeLink = (options, tr) => (state, dispatch) => {
|
|
41
|
-
const { $cursor } = state.selection;
|
|
42
|
-
if (!$cursor) {
|
|
43
|
-
toggleInlineFormat(options, tr)(state, dispatch);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
const parentNode = $cursor.parent;
|
|
47
|
-
const cursorNodeIndex = $cursor.index();
|
|
48
|
-
const toolMark = state.schema.marks[options.mark];
|
|
49
|
-
const mark = parentNode.child(cursorNodeIndex).marks.find(m => m.type === toolMark);
|
|
50
|
-
const childCount = parentNode.childCount;
|
|
51
|
-
let linkStart = $cursor.pos - $cursor.textOffset, linkSize = parentNode.child(cursorNodeIndex).nodeSize, index, nodeSize;
|
|
52
|
-
index = cursorNodeIndex - 1;
|
|
53
|
-
while (index >= 0 && mark.isInSet(parentNode.child(index).marks)) {
|
|
54
|
-
nodeSize = parentNode.child(index).nodeSize;
|
|
55
|
-
linkSize += nodeSize;
|
|
56
|
-
linkStart -= nodeSize;
|
|
57
|
-
index -= 1;
|
|
58
|
-
}
|
|
59
|
-
index = cursorNodeIndex + 1;
|
|
60
|
-
while (index < childCount && mark.isInSet(parentNode.child(index).marks)) {
|
|
61
|
-
linkSize += parentNode.child(index).nodeSize;
|
|
62
|
-
index += 1;
|
|
63
|
-
}
|
|
64
|
-
dispatch(removeMark(tr || state.tr, linkStart, linkStart + linkSize, mark));
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Returns a mark which wraps the selection.
|
|
69
|
-
*/
|
|
70
|
-
const getParentMark = (state, markType) => {
|
|
71
|
-
const marks = selectionMarks(state, markType);
|
|
72
|
-
return marks.length === 1 && marks[0] ? marks[0] : null;
|
|
73
|
-
};
|
|
74
|
-
const applyLink = ({ mark, attrs }, commandName = 'link') => (state, dispatch) => {
|
|
75
|
-
const marks = state.schema.marks;
|
|
76
|
-
const tr = state.tr;
|
|
77
|
-
if (commandName) {
|
|
78
|
-
tr.setMeta('commandName', commandName);
|
|
79
|
-
tr.setMeta('args', attrs);
|
|
80
|
-
}
|
|
81
|
-
let dispatched = false;
|
|
82
|
-
const markDispatched = () => dispatched = true;
|
|
83
|
-
if (getParentMark(state, marks[mark])) {
|
|
84
|
-
modifyLink({ mark, attrs }, tr)(state, markDispatched);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
let nextState = state;
|
|
88
|
-
if (hasMark(state, { mark })) {
|
|
89
|
-
removeLink({ mark}, tr)(state, markDispatched);
|
|
90
|
-
nextState = EditorState.create({ doc: tr.doc, selection: tr.selection });
|
|
91
|
-
}
|
|
92
|
-
if (dispatched) {
|
|
93
|
-
toggleMark(marks[mark], attrs, tr)(nextState, markDispatched);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
toggleInlineFormat({ mark: mark }, tr, attrs)(nextState, markDispatched);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (dispatched) {
|
|
100
|
-
dispatch(tr);
|
|
101
|
-
}
|
|
102
|
-
return dispatched;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export { applyLink, removeLink };
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { htmlToFragment, fragmentToHtml } from './source.js';
|
|
2
|
-
|
|
3
|
-
const msoListRegExp = /style=['"]?[^'"]*?mso-list:\s*[a-zA-Z]+(\d+)\s[a-zA-Z]+(\d+)\s(\w+)/gi;
|
|
4
|
-
const extractListLevels = (html) => {
|
|
5
|
-
html = html.replace(msoListRegExp, (match, list, level) => {
|
|
6
|
-
return `datalist="${list}" datalevel="${level}" ${match}`;
|
|
7
|
-
});
|
|
8
|
-
return html;
|
|
9
|
-
};
|
|
10
|
-
const isPartOfListItem = (element) => {
|
|
11
|
-
return /^MsoListParagraph/.test(element.className);
|
|
12
|
-
};
|
|
13
|
-
const innerText = (node) => {
|
|
14
|
-
return node.textContent;
|
|
15
|
-
};
|
|
16
|
-
const createList = (type, styleType) => {
|
|
17
|
-
const list = document.createElement(type);
|
|
18
|
-
list.style.listStyleType = styleType;
|
|
19
|
-
return list;
|
|
20
|
-
};
|
|
21
|
-
const guessUnorderedListStyle = (symbol) => {
|
|
22
|
-
if (/^[\u2022\u00b7\u00FC\u00D8\u002dv-]/.test(symbol)) {
|
|
23
|
-
return null; // return "disc"; //default CSS value
|
|
24
|
-
}
|
|
25
|
-
else if (/^o/.test(symbol)) {
|
|
26
|
-
return 'circle';
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
return 'square';
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const guessOrderedListStyle = (symbol) => {
|
|
33
|
-
let type = null;
|
|
34
|
-
if (!/^\d/.test(symbol)) {
|
|
35
|
-
type = (/^[a-z]/.test(symbol) ? 'lower-' : 'upper-') +
|
|
36
|
-
(/^[ivxlcdm]/i.test(symbol) ? 'roman' : 'alpha');
|
|
37
|
-
}
|
|
38
|
-
return type;
|
|
39
|
-
};
|
|
40
|
-
const mapListsCandidates = (nodes, groups) => {
|
|
41
|
-
let group = [];
|
|
42
|
-
Array.from(nodes).forEach(node => {
|
|
43
|
-
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const element = node;
|
|
47
|
-
if (element.getAttribute('datalist')) {
|
|
48
|
-
group.push(node);
|
|
49
|
-
groups.add(group);
|
|
50
|
-
}
|
|
51
|
-
else if (isPartOfListItem(element) && group.length) {
|
|
52
|
-
group.push(node);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
group = [];
|
|
56
|
-
if (element.nodeName === 'DIV') {
|
|
57
|
-
mapListsCandidates(element.children, groups);
|
|
58
|
-
}
|
|
59
|
-
else if (element.nodeName === 'TABLE') {
|
|
60
|
-
Array.from(element.querySelectorAll('td,th')).forEach(cell => {
|
|
61
|
-
mapListsCandidates(cell.children, groups);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
const listTypes = (p) => {
|
|
68
|
-
const html = p.textContent;
|
|
69
|
-
const trimStartText = (t) => {
|
|
70
|
-
return t.replace(/^(?: |[\u00a0\n\r\s])+/, '');
|
|
71
|
-
};
|
|
72
|
-
if ((/^[\u2022\u00b7\u00a7\u00d8oØüvn][\u00a0 ]+/.test(html))) {
|
|
73
|
-
return {
|
|
74
|
-
tag: 'ul',
|
|
75
|
-
style: guessUnorderedListStyle(trimStartText(innerText(p)))
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
if (/^\s*\w+[\.\)][\u00a0 ]{2,}/.test(html)) {
|
|
79
|
-
return {
|
|
80
|
-
tag: 'ol',
|
|
81
|
-
style: guessOrderedListStyle(trimStartText(innerText(p)))
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
const convertToLi = (p) => {
|
|
86
|
-
let content, name = p.nodeName.toLowerCase();
|
|
87
|
-
if (p.firstChild && p.firstChild.nodeType === Node.COMMENT_NODE) {
|
|
88
|
-
p.removeChild(p.firstChild);
|
|
89
|
-
}
|
|
90
|
-
if (p.childNodes.length === 1) {
|
|
91
|
-
content = p.firstChild.nodeType === Node.TEXT_NODE ?
|
|
92
|
-
innerText(p) : p.firstChild.innerHTML.replace(/^\w+[\.\)]( )+ /, '');
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
p.removeChild(p.firstChild);
|
|
96
|
-
// check for Roman numerals
|
|
97
|
-
if (p.firstChild.nodeType === 3) {
|
|
98
|
-
if (/^[ivxlcdm]+\.$/i.test(p.firstChild.nodeValue)) {
|
|
99
|
-
p.removeChild(p.firstChild);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (/^( |\s)+$/i.test(p.firstChild.innerHTML)) {
|
|
103
|
-
p.removeChild(p.firstChild);
|
|
104
|
-
}
|
|
105
|
-
if (name !== 'p') {
|
|
106
|
-
content = '<' + name + '>' + p.innerHTML + '</' + name + '>';
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
content = p.innerHTML;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
p.parentNode.removeChild(p);
|
|
113
|
-
const li = document.createElement('li');
|
|
114
|
-
li.appendChild(htmlToFragment(content));
|
|
115
|
-
return li;
|
|
116
|
-
};
|
|
117
|
-
const toList = (blockNodes) => {
|
|
118
|
-
let lastMargin = -1, levels = {}, li, rootMargin, rootIndex, lastRootLi, isLastRootLi, rootList, items, i, p, type, margin, list, listData;
|
|
119
|
-
for (i = 0; i < blockNodes.length; i++) {
|
|
120
|
-
p = blockNodes[i];
|
|
121
|
-
listData = {
|
|
122
|
-
datalist: p.getAttribute('datalist'),
|
|
123
|
-
datalevel: p.getAttribute('datalevel')
|
|
124
|
-
};
|
|
125
|
-
const listIndex = listData.datalist;
|
|
126
|
-
const listType = listTypes(p);
|
|
127
|
-
type = listType && listType.tag;
|
|
128
|
-
if (!type) {
|
|
129
|
-
if (li && (!isLastRootLi || isPartOfListItem(p))) {
|
|
130
|
-
if (p.style.marginLeft) {
|
|
131
|
-
p.style.marginLeft = '';
|
|
132
|
-
}
|
|
133
|
-
if (p.style.marginLeft) {
|
|
134
|
-
// tests runner/framework fails to delete marginLeft
|
|
135
|
-
p.style.margin = '';
|
|
136
|
-
}
|
|
137
|
-
li.appendChild(p);
|
|
138
|
-
}
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
margin = listData.datalevel || parseFloat(p.style.marginLeft || 0);
|
|
142
|
-
if (!listData.datalevel && !p.style.marginLeft) {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
const levelType = type + listIndex;
|
|
146
|
-
if (!levels[margin]) {
|
|
147
|
-
levels[margin] = {};
|
|
148
|
-
}
|
|
149
|
-
if (!rootMargin || rootMargin < 0) {
|
|
150
|
-
rootMargin = margin;
|
|
151
|
-
rootIndex = listIndex;
|
|
152
|
-
items = blockNodes.filter(e => e.getAttribute('datalist') === String(rootIndex));
|
|
153
|
-
lastRootLi = items[items.length - 1];
|
|
154
|
-
rootList = createList(type, listType && listType.style);
|
|
155
|
-
p.parentNode.insertBefore(rootList, p);
|
|
156
|
-
lastMargin = margin;
|
|
157
|
-
levels[margin][levelType] = rootList;
|
|
158
|
-
}
|
|
159
|
-
isLastRootLi = lastRootLi === p;
|
|
160
|
-
list = levels[margin][levelType];
|
|
161
|
-
if (margin > lastMargin || !list) {
|
|
162
|
-
list = createList(type, listType && listType.style);
|
|
163
|
-
levels[margin][levelType] = list;
|
|
164
|
-
li.appendChild(list);
|
|
165
|
-
}
|
|
166
|
-
li = convertToLi(p);
|
|
167
|
-
list.appendChild(li);
|
|
168
|
-
if (isLastRootLi) {
|
|
169
|
-
rootMargin = lastMargin = -1;
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
lastMargin = margin;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
const convertMsLists = (html) => {
|
|
177
|
-
const container = htmlToFragment(extractListLevels(html));
|
|
178
|
-
const groups = new Set();
|
|
179
|
-
mapListsCandidates(container.children, groups);
|
|
180
|
-
groups.forEach(listsCandidates => toList(listsCandidates));
|
|
181
|
-
return fragmentToHtml(container);
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
export { convertMsLists };
|