@progress/kendo-editor-common 1.11.9-dev.202411251354 → 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 +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/es/indent.js
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
import { sinkListItem, liftListItem } from 'prosemirror-schema-list';
|
|
2
|
-
import { indentRules, outdentRules } from './config/indent-rules';
|
|
3
|
-
import { blockNodes, addStyles, changeTextBlock, hasNode } from './blockNode';
|
|
4
|
-
import { findNthParentNodeOfType } from './utils';
|
|
5
|
-
import { liftBlockquote } from './blockquote';
|
|
2
|
+
import { indentRules, outdentRules } from './config/indent-rules.js';
|
|
3
|
+
import { blockNodes, addStyles, changeTextBlock, hasNode } from './blockNode.js';
|
|
4
|
+
import { findNthParentNodeOfType } from './utils.js';
|
|
5
|
+
import { liftBlockquote } from './blockquote.js';
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Indenting block elements in the selection.
|
|
8
9
|
*
|
|
9
10
|
* @returns {boolean} - Returns true if any indentation is applied.
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const indentBlocks = (actions, command, dir) => (state, dispatch) => {
|
|
13
|
+
const blocks = blockNodes(state);
|
|
14
|
+
const tr = state.tr;
|
|
14
15
|
tr.setMeta('commandName', command);
|
|
15
|
-
blocks.forEach(
|
|
16
|
+
blocks.forEach(node => {
|
|
16
17
|
if (node.type.isTextblock) {
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
let newAttrs;
|
|
19
|
+
const action = actions.find(a => a.node === node.type.name);
|
|
19
20
|
if (action) {
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
const style = dir === 'rtl' ? action.rtlStyle : action.style;
|
|
22
|
+
const newStyle = {
|
|
22
23
|
name: style,
|
|
23
|
-
value: action.step > 0 ?
|
|
24
|
+
value: action.step > 0 ? `${action.step}${action.unit}` : ''
|
|
24
25
|
};
|
|
25
26
|
if (node.attrs.style) {
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
const re = new RegExp(`${style}:\\s?(\\d+)${action.unit}`, 'i');
|
|
28
|
+
const match = node.attrs.style.match(re);
|
|
28
29
|
if (match) {
|
|
29
|
-
|
|
30
|
+
let newMargin = parseFloat(match[1]) + action.step;
|
|
30
31
|
newMargin = newMargin <= 0 ? '' : newMargin;
|
|
31
|
-
newStyle.value =
|
|
32
|
+
newStyle.value = `${newMargin}${newMargin ? action.unit : ''}`;
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
newAttrs = addStyles(node, [newStyle]);
|
|
@@ -38,47 +39,47 @@ export var indentBlocks = function (actions, command, dir) { return function (st
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
});
|
|
41
|
-
|
|
42
|
+
const result = tr.docChanged;
|
|
42
43
|
if (result) {
|
|
43
44
|
dispatch(tr.scrollIntoView());
|
|
44
45
|
}
|
|
45
46
|
return result;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
blocks.forEach(
|
|
47
|
+
};
|
|
48
|
+
const isIndented = (state, rules, dir) => {
|
|
49
|
+
const blocks = blockNodes(state);
|
|
50
|
+
let result = false;
|
|
51
|
+
blocks.forEach(node => {
|
|
51
52
|
if (!result && node.type.isTextblock && node.attrs.style) {
|
|
52
|
-
|
|
53
|
+
const action = rules.find(a => a.node === node.type.name);
|
|
53
54
|
if (action) {
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
const style = dir === 'rtl' ? action.rtlStyle : action.style;
|
|
56
|
+
const reIndent = new RegExp(`${style}:\\s?\\d+${action.unit}`, 'i');
|
|
56
57
|
result = reIndent.test(node.attrs.style);
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
});
|
|
60
61
|
return result;
|
|
61
62
|
};
|
|
62
|
-
|
|
63
|
+
const canIndentAsListItem = (state, nodeType) => {
|
|
63
64
|
return sinkListItem(nodeType)(state);
|
|
64
65
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
const canOutdentAsListItem = (state, rules) => {
|
|
67
|
+
const listItem = state.schema.nodes[rules.listsTypes.listItem];
|
|
68
|
+
const orderedList = state.schema.nodes[rules.listsTypes.orderedList];
|
|
69
|
+
const bulletList = state.schema.nodes[rules.listsTypes.bulletList];
|
|
70
|
+
const isNestedInOL = !!findNthParentNodeOfType(orderedList, 2)(state.selection);
|
|
71
|
+
const isNestedInUL = !!findNthParentNodeOfType(bulletList, 2)(state.selection);
|
|
71
72
|
return (isNestedInOL || isNestedInUL) && liftListItem(listItem)(state);
|
|
72
73
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return ((isIndented(state, rules.nodes) || indentRules.nodes.some(
|
|
74
|
+
const canBeIndented = (state, rules) => {
|
|
75
|
+
const nodes = state.schema.nodes;
|
|
76
|
+
const listItem = nodes[indentRules.listsTypes.listItem];
|
|
77
|
+
return ((isIndented(state, rules.nodes) || indentRules.nodes.some(rule => nodes[rule.node] && hasNode(state, nodes[rule.node]))) &&
|
|
77
78
|
!hasNode(state, listItem));
|
|
78
79
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
const indent = (state, dispatch) => {
|
|
81
|
+
const listItem = state.schema.nodes[indentRules.listsTypes.listItem];
|
|
82
|
+
const isIndentableBlock = canBeIndented(state, indentRules);
|
|
82
83
|
if (canIndentAsListItem(state, listItem)) {
|
|
83
84
|
sinkListItem(listItem)(state, dispatch);
|
|
84
85
|
}
|
|
@@ -86,10 +87,10 @@ export var indent = function (state, dispatch) {
|
|
|
86
87
|
indentBlocks(indentRules.nodes)(state, dispatch);
|
|
87
88
|
}
|
|
88
89
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
const outdent = (state, dispatch) => {
|
|
91
|
+
const nodes = state.schema.nodes;
|
|
92
|
+
const listItem = nodes[outdentRules.listsTypes.listItem];
|
|
93
|
+
const isIndentableBlock = canBeIndented(state, outdentRules);
|
|
93
94
|
if (hasNode(state, nodes.blockquote)) {
|
|
94
95
|
liftBlockquote(state, dispatch);
|
|
95
96
|
}
|
|
@@ -100,3 +101,5 @@ export var outdent = function (state, dispatch) {
|
|
|
100
101
|
indentBlocks(outdentRules.nodes)(state, dispatch);
|
|
101
102
|
}
|
|
102
103
|
};
|
|
104
|
+
|
|
105
|
+
export { canBeIndented, canIndentAsListItem, canOutdentAsListItem, indent, indentBlocks, isIndented, outdent };
|
package/dist/es/inline-style.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AddMarkStep, RemoveMarkStep } from 'prosemirror-transform';
|
|
1
|
+
import { RemoveMarkStep, AddMarkStep } from 'prosemirror-transform';
|
|
3
2
|
import { TextSelection } from 'prosemirror-state';
|
|
4
|
-
import { changeStylesString, shallowEqual } from './utils';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { changeStylesString, shallowEqual } from './utils.js';
|
|
4
|
+
import { selectionMarks, styleValue, hasMark, removeMarks, toggleMark, markApplies } 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
9
|
return changeStylesString(elementStyle, toChange);
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
tr.doc.nodesBetween(from, to,
|
|
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
15
|
if (!node.isInline) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
const marks = node.marks;
|
|
19
19
|
if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to);
|
|
21
|
+
const newStyle = changeStyleFromMark(marks, attrs);
|
|
22
22
|
if (newStyle.changed || attrs.newValue) {
|
|
23
|
-
|
|
24
|
-
{ style: newStyle.style || null } : { style:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
for (
|
|
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 ? { ...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
30
|
if (!marks[i].isInSet(newSet)) {
|
|
31
31
|
if (removing && removing.to === start && removing.mark.eq(marks[i])) {
|
|
32
32
|
removing.to = end;
|
|
@@ -37,59 +37,59 @@ var changeStyleMark = function (tr, from, to, attrs, markType) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
const previousAdded = adding && adding.to === start;
|
|
41
|
+
const sameAdding = previousAdded && newStyleMark.attrs.style === adding.mark.attrs.style;
|
|
42
42
|
if (previousAdded && sameAdding) {
|
|
43
43
|
adding.to = end;
|
|
44
44
|
}
|
|
45
|
-
else if (Object.keys(
|
|
45
|
+
else if (Object.keys(newMarkAttrs).some(attrName => newMarkAttrs[attrName] !== null)) {
|
|
46
46
|
adding = new AddMarkStep(start, end, newStyleMark);
|
|
47
47
|
added.push(adding);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
|
-
removed.forEach(
|
|
53
|
-
added.forEach(
|
|
52
|
+
removed.forEach(s => tr.step(s));
|
|
53
|
+
added.forEach(s => tr.step(s));
|
|
54
54
|
return removed.length + added.length > 0;
|
|
55
55
|
};
|
|
56
56
|
/**
|
|
57
57
|
* Used by FontSize and FontName tools for getting their state.
|
|
58
58
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return marks.map(
|
|
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
63
|
};
|
|
64
|
-
|
|
64
|
+
const changeStyle = (markType, attrs) => {
|
|
65
65
|
return function (state, dispatch, tr) {
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
const { empty, ranges } = state.selection;
|
|
67
|
+
const $cursor = state.selection instanceof TextSelection && state.selection.$cursor;
|
|
68
68
|
if ((empty && !$cursor) || !markApplies(state.doc, ranges, markType)) {
|
|
69
69
|
return false;
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
let result = false;
|
|
72
72
|
if (dispatch) {
|
|
73
|
-
|
|
73
|
+
const transaction = tr || state.tr;
|
|
74
74
|
if ($cursor) {
|
|
75
|
-
|
|
75
|
+
const currentMarks = state.storedMarks || $cursor.marks();
|
|
76
76
|
if (markType.isInSet(currentMarks)) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (shallowEqual(styleMark.attrs,
|
|
77
|
+
const newStyle = changeStyleFromMark(currentMarks, attrs);
|
|
78
|
+
const styleMark = currentMarks.find(m => m.type.name === 'style');
|
|
79
|
+
const newAttrs = { ...(styleMark ? styleMark.attrs : {}), style: newStyle.style || null };
|
|
80
|
+
if (shallowEqual(styleMark.attrs, newAttrs)) {
|
|
81
81
|
return false;
|
|
82
82
|
}
|
|
83
83
|
dispatch(transaction.removeStoredMark(markType));
|
|
84
|
-
if (Object.keys(
|
|
85
|
-
dispatch(transaction.addStoredMark(markType.create(
|
|
84
|
+
if (Object.keys(newAttrs).some(attrName => newAttrs[attrName] !== null)) {
|
|
85
|
+
dispatch(transaction.addStoredMark(markType.create(newAttrs)));
|
|
86
86
|
}
|
|
87
87
|
result = true;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
else {
|
|
91
|
-
for (
|
|
92
|
-
|
|
91
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
92
|
+
const { $from, $to } = ranges[i];
|
|
93
93
|
result = changeStyleMark(transaction, $from.pos, $to.pos, attrs, markType) || result;
|
|
94
94
|
}
|
|
95
95
|
if (result) {
|
|
@@ -104,19 +104,19 @@ var changeStyle = function (markType, attrs) {
|
|
|
104
104
|
/**
|
|
105
105
|
* Used by bold, italic, ... and link commands.
|
|
106
106
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
114
|
if (altStyle && marks.style) {
|
|
115
|
-
|
|
115
|
+
const cmd = changeStyle(marks.style, { style: altStyle.name, value: altStyle.value });
|
|
116
116
|
styleRemoved = cmd(state, markDispatched, transaction);
|
|
117
117
|
}
|
|
118
|
-
|
|
119
|
-
|
|
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
120
|
if (toRemove.length) {
|
|
121
121
|
removeMarks(toRemove, state, markDispatched, transaction);
|
|
122
122
|
}
|
|
@@ -129,42 +129,42 @@ export var toggleInlineFormat = function (options, tr, markAttrs) { return funct
|
|
|
129
129
|
dispatch(transaction);
|
|
130
130
|
}
|
|
131
131
|
return dispatched;
|
|
132
|
-
};
|
|
132
|
+
};
|
|
133
133
|
/**
|
|
134
134
|
* Used by FontSize, FontName, Color and BackColor commands.
|
|
135
135
|
*/
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
const applyInlineStyle = (options, command) => (state, dispatch) => {
|
|
137
|
+
const marks = state.schema.marks;
|
|
138
|
+
const markType = marks.style;
|
|
139
|
+
const attrs = {
|
|
140
140
|
style: options.style, value: /^.+$/, newValue: options.value
|
|
141
141
|
};
|
|
142
|
-
|
|
142
|
+
const tr = state.tr;
|
|
143
143
|
if (command) {
|
|
144
144
|
tr.setMeta('commandName', command);
|
|
145
145
|
}
|
|
146
146
|
tr.setMeta('args', options);
|
|
147
|
-
|
|
147
|
+
const { empty, $cursor, ranges } = state.selection;
|
|
148
148
|
if ((empty && !$cursor) || !markType || !markApplies(state.doc, ranges, markType)) {
|
|
149
149
|
return false;
|
|
150
150
|
}
|
|
151
151
|
// Empty selection
|
|
152
152
|
if ($cursor) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
156
|
if (currentMark && currentMark.attrs.style) {
|
|
157
|
-
|
|
157
|
+
const resultStyles = changeStylesString(currentMark.attrs.style, attrs);
|
|
158
158
|
if (resultStyles.changed && resultStyles.style) {
|
|
159
159
|
newStyles.style = resultStyles.style;
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
else if (attrs.newValue) {
|
|
163
|
-
newStyles.style =
|
|
163
|
+
newStyles.style = `${[attrs.style]}: ${attrs.newValue};`;
|
|
164
164
|
}
|
|
165
|
-
|
|
166
|
-
if (Object.keys(
|
|
167
|
-
dispatch(tr.addStoredMark(markType.create(
|
|
165
|
+
const newMarkAttrs = currentMark ? { ...currentMark.attrs, ...newStyles } : newStyles;
|
|
166
|
+
if (Object.keys(newMarkAttrs).some(attrName => newMarkAttrs[attrName] !== null)) {
|
|
167
|
+
dispatch(tr.addStoredMark(markType.create(newMarkAttrs)));
|
|
168
168
|
}
|
|
169
169
|
else {
|
|
170
170
|
dispatch(tr.removeStoredMark(markType));
|
|
@@ -172,4 +172,6 @@ export var applyInlineStyle = function (options, command) { return function (sta
|
|
|
172
172
|
return true;
|
|
173
173
|
}
|
|
174
174
|
return changeStyle(markType, attrs)(state, dispatch, tr);
|
|
175
|
-
};
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export { applyInlineStyle, getInlineStyles, toggleInlineFormat };
|
package/dist/es/link.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { toggleInlineFormat } from './inline-style';
|
|
2
|
-
import {
|
|
1
|
+
import { toggleInlineFormat } from './inline-style.js';
|
|
2
|
+
import { removeMark, hasMark, selectionMarks, toggleMark } from './mark.js';
|
|
3
3
|
import { EditorState } from 'prosemirror-state';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
|
|
5
|
+
const modifyLink = (options, tr) => (state, dispatch) => {
|
|
6
|
+
const { $cursor, from, to } = state.selection;
|
|
7
|
+
const markType = state.schema.marks[options.mark];
|
|
7
8
|
if (!$cursor) {
|
|
8
|
-
tr.doc.nodesBetween(from, to,
|
|
9
|
+
tr.doc.nodesBetween(from, to, (node, pos) => {
|
|
9
10
|
if (node.isInline && markType.isInSet(node.marks)) {
|
|
10
11
|
tr.removeMark(pos, pos + node.nodeSize, markType);
|
|
11
12
|
tr.addMark(pos, pos + node.nodeSize, markType.create(options.attrs));
|
|
@@ -14,11 +15,11 @@ var modifyLink = function (options, tr) { return function (state, dispatch) {
|
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
17
|
else {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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;
|
|
22
23
|
index = cursorNodeIndex - 1;
|
|
23
24
|
while (index >= 0 && mark.isInSet(parentNode.child(index).marks)) {
|
|
24
25
|
nodeSize = parentNode.child(index).nodeSize;
|
|
@@ -35,19 +36,19 @@ var modifyLink = function (options, tr) { return function (state, dispatch) {
|
|
|
35
36
|
tr.addMark(linkStart, linkStart + linkSize, markType.create(options.attrs));
|
|
36
37
|
dispatch(tr);
|
|
37
38
|
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
};
|
|
40
|
+
const removeLink = (options, tr) => (state, dispatch) => {
|
|
41
|
+
const { $cursor } = state.selection;
|
|
41
42
|
if (!$cursor) {
|
|
42
43
|
toggleInlineFormat(options, tr)(state, dispatch);
|
|
43
44
|
}
|
|
44
45
|
else {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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;
|
|
51
52
|
index = cursorNodeIndex - 1;
|
|
52
53
|
while (index >= 0 && mark.isInSet(parentNode.child(index).marks)) {
|
|
53
54
|
nodeSize = parentNode.child(index).nodeSize;
|
|
@@ -62,45 +63,43 @@ export var removeLink = function (options, tr) { return function (state, dispatc
|
|
|
62
63
|
}
|
|
63
64
|
dispatch(removeMark(tr || state.tr, linkStart, linkStart + linkSize, mark));
|
|
64
65
|
}
|
|
65
|
-
};
|
|
66
|
+
};
|
|
66
67
|
/**
|
|
67
68
|
* Returns a mark which wraps the selection.
|
|
68
69
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const getParentMark = (state, markType) => {
|
|
71
|
+
const marks = selectionMarks(state, markType);
|
|
71
72
|
return marks.length === 1 && marks[0] ? marks[0] : null;
|
|
72
73
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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, attrs }, tr)(state, markDispatched);
|
|
90
|
+
nextState = EditorState.create({ doc: tr.doc, selection: tr.selection });
|
|
82
91
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (getParentMark(state, marks[mark])) {
|
|
86
|
-
modifyLink({ mark: mark, attrs: attrs }, tr)(state, markDispatched);
|
|
92
|
+
if (dispatched) {
|
|
93
|
+
toggleMark(marks[mark], attrs, tr)(nextState, markDispatched);
|
|
87
94
|
}
|
|
88
95
|
else {
|
|
89
|
-
|
|
90
|
-
if (hasMark(state, { mark: mark })) {
|
|
91
|
-
removeLink({ mark: mark, attrs: attrs }, tr)(state, markDispatched);
|
|
92
|
-
nextState = EditorState.create({ doc: tr.doc, selection: tr.selection });
|
|
93
|
-
}
|
|
94
|
-
if (dispatched) {
|
|
95
|
-
toggleMark(marks[mark], attrs, tr)(nextState, markDispatched);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
toggleInlineFormat({ mark: mark }, tr, attrs)(nextState, markDispatched);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (dispatched) {
|
|
102
|
-
dispatch(tr);
|
|
96
|
+
toggleInlineFormat({ mark: mark }, tr, attrs)(nextState, markDispatched);
|
|
103
97
|
}
|
|
104
|
-
|
|
105
|
-
|
|
98
|
+
}
|
|
99
|
+
if (dispatched) {
|
|
100
|
+
dispatch(tr);
|
|
101
|
+
}
|
|
102
|
+
return dispatched;
|
|
106
103
|
};
|
|
104
|
+
|
|
105
|
+
export { applyLink, removeLink };
|