@progress/kendo-editor-common 1.11.1 → 1.11.2-dev.202402200937
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/es/DOMSerializer.js +8 -8
- package/dist/es/align.js +1 -1
- package/dist/es/blockNode.js +5 -7
- package/dist/es/blockquote.js +1 -1
- package/dist/es/config/keymap.js +3 -3
- package/dist/es/config/schema.js +2 -1
- package/dist/es/find-replace.js +1 -1
- package/dist/es/indent.js +4 -4
- package/dist/es/inline-style.js +3 -3
- package/dist/es/listConvert.js +2 -2
- package/dist/es/lists.js +2 -1
- package/dist/es/paste.js +2 -2
- package/dist/es/plugins/caret-color.js +1 -1
- package/dist/es/plugins/csp-fix.js +4 -4
- package/dist/es/plugins/highlight.js +1 -1
- package/dist/es/plugins/image-resize.js +6 -6
- package/dist/es/plugins/list-markers-styles.js +3 -3
- package/dist/es/plugins/placeholder.js +1 -1
- package/dist/es/plugins/spaces-fix.js +1 -1
- package/dist/es/plugins/table-resize/column-resize.js +14 -12
- package/dist/es/plugins/table-resize/row-resize.js +7 -7
- package/dist/es/plugins/table-resize/table-resize.js +6 -6
- package/dist/es/source.js +1 -0
- package/dist/es/table.js +1 -0
- package/dist/es/utils.js +3 -3
- package/dist/es2015/DOMSerializer.js +37 -37
- package/dist/es2015/blockNode.js +9 -11
- package/dist/es2015/blockquote.js +1 -1
- package/dist/es2015/config/keymap.js +3 -3
- package/dist/es2015/config/schema.js +4 -3
- package/dist/es2015/find-replace.js +1 -1
- package/dist/es2015/inline-style.js +5 -5
- package/dist/es2015/listConvert.js +6 -6
- package/dist/es2015/lists.js +6 -5
- package/dist/es2015/mark.js +17 -17
- package/dist/es2015/plugins/caret-color.js +1 -1
- package/dist/es2015/plugins/csp-fix.js +5 -5
- package/dist/es2015/plugins/highlight.js +1 -1
- package/dist/es2015/plugins/image-resize.js +10 -10
- package/dist/es2015/plugins/list-markers-styles.js +2 -2
- package/dist/es2015/plugins/placeholder.js +1 -1
- package/dist/es2015/plugins/spaces-fix.js +1 -1
- package/dist/es2015/plugins/table-resize/column-resize.js +41 -39
- package/dist/es2015/plugins/table-resize/row-resize.js +27 -27
- package/dist/es2015/plugins/table-resize/table-resize.js +6 -6
- package/dist/es2015/plugins/table-resize/table-view.js +2 -2
- package/dist/es2015/source.js +1 -0
- package/dist/es2015/table.js +1 -0
- package/dist/es2015/utils.js +6 -6
- package/dist/npm/DOMSerializer.d.ts +2 -2
- package/dist/npm/DOMSerializer.js +8 -8
- package/dist/npm/align.js +5 -5
- package/dist/npm/blockNode.js +13 -15
- package/dist/npm/blockquote.js +2 -2
- package/dist/npm/cleanFormatting.js +2 -2
- package/dist/npm/config/keymap.js +7 -7
- package/dist/npm/config/schema.js +6 -5
- package/dist/npm/find-replace.js +7 -7
- package/dist/npm/image.js +1 -1
- package/dist/npm/indent.js +24 -24
- package/dist/npm/inline-style.js +13 -13
- package/dist/npm/link.js +7 -7
- package/dist/npm/listConvert.js +4 -4
- package/dist/npm/lists.d.ts +2 -1
- package/dist/npm/lists.js +10 -9
- package/dist/npm/mark.js +7 -7
- package/dist/npm/paste.js +8 -8
- package/dist/npm/plugins/caret-color.js +1 -1
- package/dist/npm/plugins/csp-fix.d.ts +1 -1
- package/dist/npm/plugins/csp-fix.js +3 -3
- package/dist/npm/plugins/highlight.d.ts +1 -1
- package/dist/npm/plugins/image-resize.d.ts +1 -1
- package/dist/npm/plugins/image-resize.js +4 -4
- package/dist/npm/plugins/list-markers-styles.js +8 -8
- package/dist/npm/plugins/table-resize/column-resize.js +23 -21
- package/dist/npm/plugins/table-resize/index.js +3 -3
- package/dist/npm/plugins/table-resize/row-resize.js +18 -18
- package/dist/npm/plugins/table-resize/table-resize.js +25 -25
- package/dist/npm/plugins/table-resize/table-view.js +4 -4
- package/dist/npm/plugins/table-resize/utils.js +1 -1
- package/dist/npm/source.d.ts +1 -0
- package/dist/npm/source.js +6 -5
- package/dist/npm/table.d.ts +1 -0
- package/dist/npm/table.js +8 -7
- package/dist/npm/types/command.d.ts +1 -1
- package/dist/npm/types/dispatchFn.d.ts +1 -1
- package/dist/npm/types/predicate.d.ts +1 -1
- package/dist/npm/utils.d.ts +1 -1
- package/dist/npm/utils.js +10 -10
- package/package.json +25 -18
- package/NOTICE.txt +0 -614
- package/dist/cdn/js/kendo-editor-common.js +0 -1
- package/dist/cdn/main.js +0 -1
- package/dist/systemjs/kendo-editor-common.js +0 -1
|
@@ -1,25 +1,10 @@
|
|
|
1
|
-
import { setAttribute } from
|
|
1
|
+
import { setAttribute } from './utils';
|
|
2
2
|
export class DOMSerializer {
|
|
3
|
-
/// Create a serializer. `nodes` should map node names to functions
|
|
4
|
-
/// that take a node and return a description of the corresponding
|
|
5
|
-
/// DOM. `marks` does the same for mark names, but also gets an
|
|
6
|
-
/// argument that tells it whether the mark's content is block or
|
|
7
|
-
/// inline content (for typical use, it'll always be inline). A mark
|
|
8
|
-
/// serializer may be `null` to indicate that marks of that type
|
|
9
|
-
/// should not be serialized.
|
|
10
|
-
constructor(
|
|
11
|
-
/// The node serialization functions.
|
|
12
|
-
nodes,
|
|
13
|
-
/// The mark serialization functions.
|
|
14
|
-
marks) {
|
|
15
|
-
this.nodes = nodes;
|
|
16
|
-
this.marks = marks;
|
|
17
|
-
}
|
|
18
3
|
/// Render an [output spec](#model.DOMOutputSpec) to a DOM node. If
|
|
19
4
|
/// the spec has a hole (zero) in it, `contentDOM` will point at the
|
|
20
5
|
/// node with the hole.
|
|
21
6
|
static renderSpec(docum, structure, xmlNS = null) {
|
|
22
|
-
if (typeof structure ===
|
|
7
|
+
if (typeof structure === 'string') {
|
|
23
8
|
return { dom: docum.createTextNode(structure) };
|
|
24
9
|
}
|
|
25
10
|
if (structure.nodeType != null) {
|
|
@@ -28,19 +13,19 @@ export class DOMSerializer {
|
|
|
28
13
|
if (structure.dom && structure.dom.nodeType != null) {
|
|
29
14
|
return structure;
|
|
30
15
|
}
|
|
31
|
-
let tagName = structure[0], space = tagName.indexOf(
|
|
16
|
+
let tagName = structure[0], space = tagName.indexOf(' ');
|
|
32
17
|
if (space > 0) {
|
|
33
18
|
xmlNS = tagName.slice(0, space);
|
|
34
19
|
tagName = tagName.slice(space + 1);
|
|
35
20
|
}
|
|
36
21
|
let contentDOM;
|
|
37
|
-
|
|
22
|
+
const dom = (xmlNS ? docum.createElementNS(xmlNS, tagName) : docum.createElement(tagName));
|
|
38
23
|
let attrs = structure[1], start = 1;
|
|
39
|
-
if (attrs && typeof attrs ===
|
|
24
|
+
if (attrs && typeof attrs === 'object' && attrs.nodeType == null && !Array.isArray(attrs)) {
|
|
40
25
|
start = 2;
|
|
41
|
-
for (
|
|
26
|
+
for (const name in attrs) {
|
|
42
27
|
if (attrs[name] != null) {
|
|
43
|
-
space = name.indexOf(
|
|
28
|
+
space = name.indexOf(' ');
|
|
44
29
|
if (space > 0) {
|
|
45
30
|
dom.setAttributeNS(name.slice(0, space), name.slice(space + 1), attrs[name]);
|
|
46
31
|
}
|
|
@@ -51,19 +36,19 @@ export class DOMSerializer {
|
|
|
51
36
|
}
|
|
52
37
|
}
|
|
53
38
|
for (let i = start; i < structure.length; i++) {
|
|
54
|
-
|
|
39
|
+
const child = structure[i];
|
|
55
40
|
if (child === 0) {
|
|
56
41
|
if (i < structure.length - 1 || i > start) {
|
|
57
|
-
throw new RangeError(
|
|
42
|
+
throw new RangeError('Content hole must be the only child of its parent node');
|
|
58
43
|
}
|
|
59
44
|
return { dom, contentDOM: dom };
|
|
60
45
|
}
|
|
61
46
|
else {
|
|
62
|
-
|
|
47
|
+
const { dom: inner, contentDOM: innerContent } = DOMSerializer.renderSpec(docum, child, xmlNS);
|
|
63
48
|
dom.appendChild(inner);
|
|
64
49
|
if (innerContent) {
|
|
65
50
|
if (contentDOM) {
|
|
66
|
-
throw new RangeError(
|
|
51
|
+
throw new RangeError('Multiple content holes');
|
|
67
52
|
}
|
|
68
53
|
contentDOM = innerContent;
|
|
69
54
|
}
|
|
@@ -80,7 +65,7 @@ export class DOMSerializer {
|
|
|
80
65
|
/// Gather the serializers in a schema's node specs into an object.
|
|
81
66
|
/// This can be useful as a base to build a custom serializer from.
|
|
82
67
|
static nodesFromSchema(schema) {
|
|
83
|
-
|
|
68
|
+
const result = gatherToDOM(schema.nodes);
|
|
84
69
|
if (!result.text) {
|
|
85
70
|
result.text = node => node.text;
|
|
86
71
|
}
|
|
@@ -90,6 +75,21 @@ export class DOMSerializer {
|
|
|
90
75
|
static marksFromSchema(schema) {
|
|
91
76
|
return gatherToDOM(schema.marks);
|
|
92
77
|
}
|
|
78
|
+
/// Create a serializer. `nodes` should map node names to functions
|
|
79
|
+
/// that take a node and return a description of the corresponding
|
|
80
|
+
/// DOM. `marks` does the same for mark names, but also gets an
|
|
81
|
+
/// argument that tells it whether the mark's content is block or
|
|
82
|
+
/// inline content (for typical use, it'll always be inline). A mark
|
|
83
|
+
/// serializer may be `null` to indicate that marks of that type
|
|
84
|
+
/// should not be serialized.
|
|
85
|
+
constructor(
|
|
86
|
+
/// The node serialization functions.
|
|
87
|
+
nodes,
|
|
88
|
+
/// The mark serialization functions.
|
|
89
|
+
marks) {
|
|
90
|
+
this.nodes = nodes;
|
|
91
|
+
this.marks = marks;
|
|
92
|
+
}
|
|
93
93
|
/// Serialize the content of this fragment to a DOM fragment. When
|
|
94
94
|
/// not in the browser, the `document` option, containing a DOM
|
|
95
95
|
/// document, should be passed so that the serializer can create
|
|
@@ -103,7 +103,7 @@ export class DOMSerializer {
|
|
|
103
103
|
if (active.length || node.marks.length) {
|
|
104
104
|
let keep = 0, rendered = 0;
|
|
105
105
|
while (keep < active.length && rendered < node.marks.length) {
|
|
106
|
-
|
|
106
|
+
const next = node.marks[rendered];
|
|
107
107
|
if (!this.marks[next.type.name]) {
|
|
108
108
|
rendered++;
|
|
109
109
|
continue;
|
|
@@ -118,8 +118,8 @@ export class DOMSerializer {
|
|
|
118
118
|
top = active.pop()[1];
|
|
119
119
|
}
|
|
120
120
|
while (rendered < node.marks.length) {
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
const add = node.marks[rendered++];
|
|
122
|
+
const markDOM = this.serializeMark(add, node.isInline, options);
|
|
123
123
|
if (markDOM) {
|
|
124
124
|
active.push([add, top]);
|
|
125
125
|
top.appendChild(markDOM.dom);
|
|
@@ -139,7 +139,7 @@ export class DOMSerializer {
|
|
|
139
139
|
serializeNode(node, options = {}) {
|
|
140
140
|
let dom = this.serializeNodeInner(node, options);
|
|
141
141
|
for (let i = node.marks.length - 1; i >= 0; i--) {
|
|
142
|
-
|
|
142
|
+
const wrap = this.serializeMark(node.marks[i], node.isInline, options);
|
|
143
143
|
if (wrap) {
|
|
144
144
|
(wrap.contentDOM || wrap.dom).appendChild(dom);
|
|
145
145
|
dom = wrap.dom;
|
|
@@ -149,15 +149,15 @@ export class DOMSerializer {
|
|
|
149
149
|
}
|
|
150
150
|
/// @internal
|
|
151
151
|
serializeMark(mark, inline, options = {}) {
|
|
152
|
-
|
|
152
|
+
const toDOM = this.marks[mark.type.name];
|
|
153
153
|
return toDOM && DOMSerializer.renderSpec(doc(options), toDOM(mark, inline));
|
|
154
154
|
}
|
|
155
155
|
/// @internal
|
|
156
156
|
serializeNodeInner(node, options) {
|
|
157
|
-
|
|
157
|
+
const { dom, contentDOM } = DOMSerializer.renderSpec(doc(options), this.nodes[node.type.name](node));
|
|
158
158
|
if (contentDOM) {
|
|
159
159
|
if (node.isLeaf) {
|
|
160
|
-
throw new RangeError(
|
|
160
|
+
throw new RangeError('Content hole not allowed in a leaf node spec');
|
|
161
161
|
}
|
|
162
162
|
this.serializeFragment(node.content, options, contentDOM);
|
|
163
163
|
}
|
|
@@ -165,10 +165,10 @@ export class DOMSerializer {
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
function gatherToDOM(obj) {
|
|
168
|
-
|
|
169
|
-
for (
|
|
168
|
+
const result = {};
|
|
169
|
+
for (const name in obj) {
|
|
170
170
|
if (obj[name]) {
|
|
171
|
-
|
|
171
|
+
const toDOM = obj[name].spec.toDOM;
|
|
172
172
|
if (toDOM) {
|
|
173
173
|
result[name] = toDOM;
|
|
174
174
|
}
|
package/dist/es2015/blockNode.js
CHANGED
|
@@ -7,7 +7,7 @@ import { NodeSelection } from 'prosemirror-state';
|
|
|
7
7
|
* @hidden
|
|
8
8
|
*/
|
|
9
9
|
const canChangeType = (stateDoc, pos, type) => {
|
|
10
|
-
|
|
10
|
+
const $pos = stateDoc.resolve(pos), index = $pos.index();
|
|
11
11
|
return $pos.parent.canReplaceWith(index, index + 1, type);
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
@@ -32,9 +32,9 @@ export const changeTextBlock = (tr, node, nodeType, attrs) => {
|
|
|
32
32
|
canChangeType(tr.doc, tr.mapping.slice(mapFrom).map(pos), nodeType)) {
|
|
33
33
|
// Ensure all markup that isn't allowed in the new node type is cleared
|
|
34
34
|
tr.clearIncompatible(tr.mapping.slice(mapFrom).map(pos, 1), nodeType);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const mapping = tr.mapping.slice(mapFrom);
|
|
36
|
+
const startM = mapping.map(pos, 1), endM = mapping.map(pos + currNode.nodeSize, 1);
|
|
37
|
+
const slice = new Slice(Fragment.from(nodeType.create(attrs, null, currNode.marks)), 0, 0);
|
|
38
38
|
tr.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, slice, 1, true));
|
|
39
39
|
return false; // this will skip the node children
|
|
40
40
|
}
|
|
@@ -49,7 +49,7 @@ export const changeTextBlock = (tr, node, nodeType, attrs) => {
|
|
|
49
49
|
*/
|
|
50
50
|
export const blockNodes = (state, options = { blocksInSelection: false }) => {
|
|
51
51
|
const { doc, selection } = state;
|
|
52
|
-
|
|
52
|
+
const { $from, ranges } = selection;
|
|
53
53
|
const { blocksInSelection } = options;
|
|
54
54
|
const result = [];
|
|
55
55
|
const selNode = selection instanceof NodeSelection ? selection.node : undefined;
|
|
@@ -70,7 +70,7 @@ export const blockNodes = (state, options = { blocksInSelection: false }) => {
|
|
|
70
70
|
ranges.forEach(range => {
|
|
71
71
|
const from = range.$from.pos;
|
|
72
72
|
const to = range.$to.pos;
|
|
73
|
-
doc.nodesBetween(from, to, (node, pos
|
|
73
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
74
74
|
if (node.isBlock && (!blocksInSelection || (pos >= from && pos + node.content.size + 2 <= to))) {
|
|
75
75
|
result.push(node);
|
|
76
76
|
}
|
|
@@ -88,16 +88,14 @@ export const formatBlockElements = (value, commandName) => (state, dispatch) =>
|
|
|
88
88
|
blocks.forEach(node => {
|
|
89
89
|
if (node.type.isTextblock) {
|
|
90
90
|
if (value === 'p') {
|
|
91
|
-
|
|
92
|
-
changeTextBlock(tr, node, nodes.paragraph, attrs);
|
|
91
|
+
changeTextBlock(tr, node, nodes.paragraph, node.attrs);
|
|
93
92
|
}
|
|
94
93
|
else if (/^h[1-6]$/i.test(value)) {
|
|
95
94
|
const level = parseInt(value.substr(1), 10);
|
|
96
95
|
changeTextBlock(tr, node, nodes.heading, Object.assign(Object.assign({}, node.attrs), { level }));
|
|
97
96
|
}
|
|
98
97
|
else if (value === 'blockquote') {
|
|
99
|
-
|
|
100
|
-
changeTextBlock(tr, node, nodes.blockquote, attrs);
|
|
98
|
+
changeTextBlock(tr, node, nodes.blockquote, node.attrs);
|
|
101
99
|
}
|
|
102
100
|
}
|
|
103
101
|
});
|
|
@@ -159,7 +157,7 @@ export const addStyles = (node, stylesToApply) => {
|
|
|
159
157
|
return Object.assign({}, node.attrs, { style: currentStyles || null });
|
|
160
158
|
};
|
|
161
159
|
export const hasNode = (state, nodeType) => {
|
|
162
|
-
|
|
160
|
+
const { from, to } = state.selection;
|
|
163
161
|
let result = false;
|
|
164
162
|
state.doc.nodesBetween(from, to, node => {
|
|
165
163
|
result = result || node.type === nodeType;
|
|
@@ -9,7 +9,7 @@ export const liftBlockquote = (state, dispatch) => {
|
|
|
9
9
|
let target = -1;
|
|
10
10
|
const range = $from.blockRange($to);
|
|
11
11
|
if (range) {
|
|
12
|
-
doc.nodesBetween(range.start, range.end, (node, pos
|
|
12
|
+
doc.nodesBetween(range.start, range.end, (node, pos) => {
|
|
13
13
|
if (node.type === nodeType) {
|
|
14
14
|
target = pos;
|
|
15
15
|
}
|
|
@@ -13,9 +13,9 @@ export const buildKeymap = (schema, options) => {
|
|
|
13
13
|
keys['Mod-z'] = undo;
|
|
14
14
|
keys['Shift-Mod-z'] = redo;
|
|
15
15
|
// tslint:disable-next-line:no-string-literal
|
|
16
|
-
keys
|
|
16
|
+
keys.Backspace = chainCommands(undoInputRule, deleteSelection, joinBackward, selectNodeBackward);
|
|
17
17
|
// tslint:disable-next-line:no-string-literal
|
|
18
|
-
keys
|
|
18
|
+
keys.Enter = chainCommands(newlineInCode, createParagraphNear, liftEmptyBlock, splitBlockKeepMarks);
|
|
19
19
|
if (!mac) {
|
|
20
20
|
keys['Mod-y'] = redo;
|
|
21
21
|
}
|
|
@@ -42,7 +42,7 @@ export const buildListKeymap = (schema) => {
|
|
|
42
42
|
const keys = {};
|
|
43
43
|
if (schema.nodes.list_item) {
|
|
44
44
|
// tslint:disable-next-line:no-string-literal
|
|
45
|
-
keys
|
|
45
|
+
keys.Enter = splitListItemKeepMarks(schema.nodes.list_item);
|
|
46
46
|
}
|
|
47
47
|
return keys;
|
|
48
48
|
};
|
|
@@ -7,7 +7,8 @@ const blockquoteDOM = ['blockquote', hole], hrDOM = ['hr'], preDOM = ['pre', ['c
|
|
|
7
7
|
const olDOM = ['ol', 0], ulDOM = ['ul', 0], liDOM = ['li', 0];
|
|
8
8
|
const domAttributes = (dom) => {
|
|
9
9
|
const result = {};
|
|
10
|
-
|
|
10
|
+
const attributes = dom.attributes;
|
|
11
|
+
let attr;
|
|
11
12
|
for (let i = 0; i < attributes.length; i++) {
|
|
12
13
|
attr = attributes[i];
|
|
13
14
|
result[attr.name] = attr.value;
|
|
@@ -23,7 +24,7 @@ const defaultAttrs = (attrs) => {
|
|
|
23
24
|
};
|
|
24
25
|
const commonAttributes = () => defaultAttrs(['style', 'class', 'id']);
|
|
25
26
|
const hasAttrs = (attrs, exclude) => {
|
|
26
|
-
for (
|
|
27
|
+
for (const attr in attrs) {
|
|
27
28
|
if (attr && attrs[attr] !== null && attr !== exclude) {
|
|
28
29
|
return true;
|
|
29
30
|
}
|
|
@@ -32,7 +33,7 @@ const hasAttrs = (attrs, exclude) => {
|
|
|
32
33
|
};
|
|
33
34
|
const pmAttributes = (attrs, exclude = []) => {
|
|
34
35
|
const result = {};
|
|
35
|
-
for (
|
|
36
|
+
for (const attr in attrs) {
|
|
36
37
|
if (attr && attrs[attr] !== null && !exclude.find(e => e === attr)) {
|
|
37
38
|
result[attr] = attrs[attr];
|
|
38
39
|
}
|
|
@@ -14,7 +14,7 @@ export const findAt = (doc, searchOptions, start, end, exit) => {
|
|
|
14
14
|
}
|
|
15
15
|
const flags = matchCase ? 'g' : 'gi';
|
|
16
16
|
const regExp = useRegExp ? new RegExp(searchText, flags) : createRegExp(searchText, flags);
|
|
17
|
-
doc.nodesBetween(start, end, (node, pos
|
|
17
|
+
doc.nodesBetween(start, end, (node, pos) => {
|
|
18
18
|
if (exit(result)) {
|
|
19
19
|
return false;
|
|
20
20
|
}
|
|
@@ -14,9 +14,9 @@ const changeStyleMark = (tr, from, to, attrs, markType) => {
|
|
|
14
14
|
if (!node.isInline) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
const marks = node.marks;
|
|
18
18
|
if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) {
|
|
19
|
-
|
|
19
|
+
const start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to);
|
|
20
20
|
const newStyle = changeStyleFromMark(marks, attrs);
|
|
21
21
|
if (newStyle.changed || attrs.newValue) {
|
|
22
22
|
const style = newStyle.changed ?
|
|
@@ -24,7 +24,7 @@ const changeStyleMark = (tr, from, to, attrs, markType) => {
|
|
|
24
24
|
const currentMark = markType.isInSet(marks) ? marks.find(m => m.type.name === 'style') : null;
|
|
25
25
|
const newMarkAttrs = currentMark ? Object.assign(Object.assign({}, currentMark.attrs), style) : style;
|
|
26
26
|
const newStyleMark = markType.create(newMarkAttrs);
|
|
27
|
-
|
|
27
|
+
const newSet = newStyleMark.addToSet(marks);
|
|
28
28
|
for (let i = 0; i < marks.length; i++) {
|
|
29
29
|
if (!marks[i].isInSet(newSet)) {
|
|
30
30
|
if (removing && removing.to === start && removing.mark.eq(marks[i])) {
|
|
@@ -88,7 +88,7 @@ const changeStyle = (markType, attrs) => {
|
|
|
88
88
|
}
|
|
89
89
|
else {
|
|
90
90
|
for (let i = 0; i < ranges.length; i++) {
|
|
91
|
-
|
|
91
|
+
const { $from, $to } = ranges[i];
|
|
92
92
|
result = changeStyleMark(transaction, $from.pos, $to.pos, attrs, markType) || result;
|
|
93
93
|
}
|
|
94
94
|
if (result) {
|
|
@@ -143,7 +143,7 @@ export const applyInlineStyle = (options, command) => (state, dispatch) => {
|
|
|
143
143
|
tr.setMeta('commandName', command);
|
|
144
144
|
}
|
|
145
145
|
tr.setMeta('args', options);
|
|
146
|
-
|
|
146
|
+
const { empty, $cursor, ranges } = state.selection;
|
|
147
147
|
if ((empty && !$cursor) || !markType || !markApplies(state.doc, ranges, markType)) {
|
|
148
148
|
return false;
|
|
149
149
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fragmentToHtml, htmlToFragment } from
|
|
1
|
+
import { fragmentToHtml, htmlToFragment } from './source';
|
|
2
2
|
const msoListRegExp = /style=['"]?[^'"]*?mso-list:\s*[a-zA-Z]+(\d+)\s[a-zA-Z]+(\d+)\s(\w+)/gi;
|
|
3
3
|
const extractListLevels = (html) => {
|
|
4
4
|
html = html.replace(msoListRegExp, (match, list, level) => {
|
|
@@ -45,7 +45,7 @@ const mapListsCandidates = (nodes, groups) => {
|
|
|
45
45
|
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
const element = node;
|
|
49
49
|
if (element.getAttribute('datalist')) {
|
|
50
50
|
group.push(node);
|
|
51
51
|
groups.add(group);
|
|
@@ -68,7 +68,7 @@ const mapListsCandidates = (nodes, groups) => {
|
|
|
68
68
|
};
|
|
69
69
|
const listTypes = (p) => {
|
|
70
70
|
let html = p.innerHTML;
|
|
71
|
-
|
|
71
|
+
const trimStartText = (t) => {
|
|
72
72
|
return t.replace(/^(?: |[\u00a0\n\r\s])+/, '');
|
|
73
73
|
};
|
|
74
74
|
html = html.replace(/<\/?\w+[^>]*>/g, '').replace(/ /g, '\u00a0');
|
|
@@ -125,8 +125,8 @@ const toList = (blockNodes) => {
|
|
|
125
125
|
datalist: p.getAttribute('datalist'),
|
|
126
126
|
datalevel: p.getAttribute('datalevel')
|
|
127
127
|
};
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
const listIndex = listData.datalist;
|
|
129
|
+
const listType = listTypes(p);
|
|
130
130
|
type = listType && listType.tag;
|
|
131
131
|
if (!type) {
|
|
132
132
|
if (li && (!isLastRootLi || isPartOfListItem(p))) {
|
|
@@ -145,7 +145,7 @@ const toList = (blockNodes) => {
|
|
|
145
145
|
if (!listData.datalevel && !p.style.marginLeft) {
|
|
146
146
|
continue;
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
const levelType = type + listIndex;
|
|
149
149
|
if (!levels[margin]) {
|
|
150
150
|
levels[margin] = {};
|
|
151
151
|
}
|
package/dist/es2015/lists.js
CHANGED
|
@@ -94,13 +94,13 @@ function toggleListCommand(options) {
|
|
|
94
94
|
}
|
|
95
95
|
function liftListItem(state, selection, tr, nodeType) {
|
|
96
96
|
const listItemNodeType = nodeType || state.schema.nodes.listItem;
|
|
97
|
-
|
|
97
|
+
const { $from, $to } = selection;
|
|
98
98
|
let range = $from.blockRange($to, node => node.childCount && node.firstChild.type === listItemNodeType);
|
|
99
99
|
if (!range || range.depth < 2 || $from.node(range.depth - 1).type !== listItemNodeType) {
|
|
100
100
|
return tr;
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
const end = range.end;
|
|
103
|
+
const endOfList = $to.end(range.depth);
|
|
104
104
|
if (end < endOfList) {
|
|
105
105
|
tr.step(new ReplaceAroundStep(end - 1, endOfList, end, endOfList, new Slice(Fragment.from(listItemNodeType.create(undefined, range.parent.copy())), 1, 0), 1, true));
|
|
106
106
|
range = new NodeRange(tr.doc.resolve($from.pos), tr.doc.resolve(endOfList), range.depth);
|
|
@@ -135,7 +135,7 @@ function isRangeOfType(doc, $from, $to, nodeType) {
|
|
|
135
135
|
}
|
|
136
136
|
function getAncestorNodesBetween(doc, $from, $to) {
|
|
137
137
|
// Returns all top-level ancestor-nodes between $from and $to
|
|
138
|
-
const nodes =
|
|
138
|
+
const nodes = [];
|
|
139
139
|
const maxDepth = findAncestorPosition(doc, $from).depth;
|
|
140
140
|
let current = doc.resolve($from.start(maxDepth));
|
|
141
141
|
while (current.pos <= $to.start($to.depth)) {
|
|
@@ -212,6 +212,7 @@ function wrapInList(nodeType, attrs = {}) {
|
|
|
212
212
|
const reListStyle = /list\-style\-type:\s?([\w-]+)/;
|
|
213
213
|
/**
|
|
214
214
|
* Extracts list-style-type style from node's attributes.
|
|
215
|
+
*
|
|
215
216
|
* @param attrs - The attributes of the list node
|
|
216
217
|
* @returns The extracted list-style-type.
|
|
217
218
|
*/
|
|
@@ -253,7 +254,7 @@ export function toggleOrderedList(state, dispatch, view) {
|
|
|
253
254
|
export const splitListItemKeepMarks = (itemType) => (state, dispatch) => {
|
|
254
255
|
// see https://github.com/ProseMirror/prosemirror-commands/blob/master/src/commands.js#L321-L327
|
|
255
256
|
return splitListItem(itemType)(state, tr => {
|
|
256
|
-
|
|
257
|
+
const marks = state.storedMarks || (state.selection.$to.parentOffset && state.selection.$from.marks());
|
|
257
258
|
if (marks) {
|
|
258
259
|
tr.ensureMarks(marks);
|
|
259
260
|
}
|
package/dist/es2015/mark.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { RemoveMarkStep } from 'prosemirror-transform';
|
|
2
2
|
import { MarkType } from 'prosemirror-model';
|
|
3
3
|
export const markApplies = (doc, ranges, type) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const loop = i => {
|
|
5
|
+
const ref = ranges[i];
|
|
6
|
+
const $from = ref.$from;
|
|
7
|
+
const $to = ref.$to;
|
|
8
8
|
let can = $from.depth === 0 ? doc.type.allowsMarkType(type) : false;
|
|
9
9
|
doc.nodesBetween($from.pos, $to.pos, node => {
|
|
10
10
|
if (can) {
|
|
@@ -17,7 +17,7 @@ export const markApplies = (doc, ranges, type) => {
|
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
for (let i = 0; i < ranges.length; i++) {
|
|
20
|
-
|
|
20
|
+
const returned = loop(i);
|
|
21
21
|
if (returned) {
|
|
22
22
|
return returned.v;
|
|
23
23
|
}
|
|
@@ -25,7 +25,7 @@ export const markApplies = (doc, ranges, type) => {
|
|
|
25
25
|
return false;
|
|
26
26
|
};
|
|
27
27
|
export const toggleMark = (markType, attrs, tr) => (state, dispatch) => {
|
|
28
|
-
|
|
28
|
+
const { empty, $cursor, ranges } = state.selection;
|
|
29
29
|
if ((empty && !$cursor) || !markApplies(state.doc, ranges, markType)) {
|
|
30
30
|
return false;
|
|
31
31
|
}
|
|
@@ -41,11 +41,11 @@ export const toggleMark = (markType, attrs, tr) => (state, dispatch) => {
|
|
|
41
41
|
else {
|
|
42
42
|
let has = false;
|
|
43
43
|
for (let i = 0; !has && i < ranges.length; i++) {
|
|
44
|
-
|
|
44
|
+
const { $from, $to } = ranges[i];
|
|
45
45
|
has = state.doc.rangeHasMark($from.pos, $to.pos, markType);
|
|
46
46
|
}
|
|
47
47
|
for (let i = 0; i < ranges.length; i++) {
|
|
48
|
-
|
|
48
|
+
const { $from, $to } = ranges[i];
|
|
49
49
|
if (has) {
|
|
50
50
|
tr.removeMark($from.pos, $to.pos, markType);
|
|
51
51
|
}
|
|
@@ -70,7 +70,7 @@ export const removeMark = (tr, from, to, mark) => {
|
|
|
70
70
|
step++;
|
|
71
71
|
let toRemove = null;
|
|
72
72
|
if (mark instanceof MarkType) {
|
|
73
|
-
|
|
73
|
+
const found = mark.isInSet(node.marks);
|
|
74
74
|
if (found) {
|
|
75
75
|
toRemove = [found];
|
|
76
76
|
}
|
|
@@ -84,11 +84,11 @@ export const removeMark = (tr, from, to, mark) => {
|
|
|
84
84
|
toRemove = node.marks;
|
|
85
85
|
}
|
|
86
86
|
if (toRemove && toRemove.length) {
|
|
87
|
-
|
|
87
|
+
const end = Math.min(pos + node.nodeSize, to);
|
|
88
88
|
for (let i = 0; i < toRemove.length; i++) {
|
|
89
89
|
let style = toRemove[i], found$1 = (void 0);
|
|
90
90
|
for (let j = 0; j < matched.length; j++) {
|
|
91
|
-
|
|
91
|
+
const m = matched[j];
|
|
92
92
|
if (m.step === step - 1 && style.eq(m.style)) {
|
|
93
93
|
found$1 = m;
|
|
94
94
|
}
|
|
@@ -107,7 +107,7 @@ export const removeMark = (tr, from, to, mark) => {
|
|
|
107
107
|
return tr;
|
|
108
108
|
};
|
|
109
109
|
export const removeMarks = (marks, state, dispatch, tr) => {
|
|
110
|
-
|
|
110
|
+
const { $cursor, ranges } = state.selection;
|
|
111
111
|
tr = tr || state.tr;
|
|
112
112
|
if ($cursor) {
|
|
113
113
|
marks.forEach(m => {
|
|
@@ -118,7 +118,7 @@ export const removeMarks = (marks, state, dispatch, tr) => {
|
|
|
118
118
|
}
|
|
119
119
|
else {
|
|
120
120
|
for (let i = 0; i < ranges.length; i++) {
|
|
121
|
-
|
|
121
|
+
const { $from, $to } = ranges[i];
|
|
122
122
|
marks.forEach(m => {
|
|
123
123
|
removeMark(tr, $from.pos, $to.pos, m);
|
|
124
124
|
});
|
|
@@ -164,7 +164,7 @@ export const hasMark = (state, options) => {
|
|
|
164
164
|
const marks = state.schema.marks;
|
|
165
165
|
const altMarks = (options.altMarks || []).filter(m => marks[m]);
|
|
166
166
|
const altStyle = options.altStyle;
|
|
167
|
-
|
|
167
|
+
const { from, $from, to, empty } = state.selection;
|
|
168
168
|
const type = marks[options.mark];
|
|
169
169
|
const doc = state.doc;
|
|
170
170
|
let result = false;
|
|
@@ -197,8 +197,8 @@ export const styleValue = (mark, style) => {
|
|
|
197
197
|
* Returns the marks of a specific type for every inline node in the selection.
|
|
198
198
|
*/
|
|
199
199
|
export const selectionMarks = (state, markType) => {
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
const { from, $from, to, empty } = state.selection;
|
|
201
|
+
const marks = [];
|
|
202
202
|
if (empty) {
|
|
203
203
|
marks.push(markType.isInSet(state.storedMarks || $from.marks()));
|
|
204
204
|
}
|
|
@@ -226,7 +226,7 @@ export const getMark = (state, markType) => {
|
|
|
226
226
|
export const getActiveMarks = (state, markType) => {
|
|
227
227
|
const marks = selectionMarks(state, markType);
|
|
228
228
|
const filtered = marks.filter(m => Boolean(m));
|
|
229
|
-
|
|
229
|
+
const hasNodesWithoutMarks = marks.length !== filtered.length;
|
|
230
230
|
return {
|
|
231
231
|
hasNodesWithoutMarks,
|
|
232
232
|
marks: filtered
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
-
import { Decoration, DecorationSet } from
|
|
2
|
+
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
3
3
|
import { styleValue } from './../mark';
|
|
4
4
|
export const caretColorKey = new PluginKey('caret-color');
|
|
5
5
|
export function caretColor() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Plugin, PluginKey } from
|
|
2
|
-
import { setAttribute } from
|
|
1
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
+
import { setAttribute } from '../utils';
|
|
3
3
|
const setAttributes = (dom, attrs) => {
|
|
4
|
-
for (
|
|
4
|
+
for (const attrName in attrs) {
|
|
5
5
|
if (attrName) {
|
|
6
6
|
setAttribute(dom, attrName, attrs[attrName]);
|
|
7
7
|
}
|
|
@@ -17,7 +17,7 @@ class CustomNodeView {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
class StyleView {
|
|
20
|
-
constructor(mark, view
|
|
20
|
+
constructor(mark, view) {
|
|
21
21
|
this.mark = mark;
|
|
22
22
|
this.view = view;
|
|
23
23
|
this.dom = document.createElement('span');
|
|
@@ -41,7 +41,7 @@ export const cspFix = () => {
|
|
|
41
41
|
image: (node, view) => new CustomNodeView(node, view, 'img', true)
|
|
42
42
|
},
|
|
43
43
|
markViews: {
|
|
44
|
-
style: (mark, view
|
|
44
|
+
style: (mark, view) => new StyleView(mark, view)
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
-
import { Decoration, DecorationSet } from
|
|
2
|
+
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
3
3
|
// https://discuss.prosemirror.net/t/passing-data-between-plugins/1843
|
|
4
4
|
export const textHighlightKey = new PluginKey('highlight');
|
|
5
5
|
export function textHighlight(key = textHighlightKey) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { NodeSelection, Plugin, PluginKey } from
|
|
2
|
-
import { Decoration, DecorationSet } from
|
|
3
|
-
import { dataResizeDirImage, resizeHandle } from
|
|
4
|
-
import { changeStylesString } from
|
|
1
|
+
import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
+
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
3
|
+
import { dataResizeDirImage, resizeHandle } from '../config/constants';
|
|
4
|
+
import { changeStylesString } from '../utils';
|
|
5
5
|
import { directions, handles } from './resize-utils';
|
|
6
6
|
export const imageResizeKey = new PluginKey('image-resize');
|
|
7
7
|
const setSize = (domNode, sizeType, value) => {
|
|
@@ -17,11 +17,11 @@ class ResizeState {
|
|
|
17
17
|
this.nodePosition = nodePosition;
|
|
18
18
|
}
|
|
19
19
|
apply(tr) {
|
|
20
|
-
|
|
20
|
+
const next = tr.getMeta(imageResizeKey);
|
|
21
21
|
if (next) {
|
|
22
22
|
return new ResizeState(next.activeHandle, next.setDragging, next.rect, next.nodePosition);
|
|
23
23
|
}
|
|
24
|
-
return
|
|
24
|
+
return this;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
const handleMouseMove = (view, event, options) => {
|
|
@@ -37,9 +37,9 @@ const handleMouseMove = (view, event, options) => {
|
|
|
37
37
|
let width = dir.x ? diffX + img.width : rect.width;
|
|
38
38
|
let height = dir.y ? diffY + img.height : rect.height;
|
|
39
39
|
if (options.lockRatio && dir.x && dir.y) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
const ratio = Math.min(width / img.width, height / img.height);
|
|
41
|
+
const lockWidth = img.width * ratio;
|
|
42
|
+
const lockHeight = img.height * ratio;
|
|
43
43
|
dragging.startX = event.clientX - (width - lockWidth) * dir.x;
|
|
44
44
|
dragging.startY = event.clientY - (height - lockHeight) * dir.y;
|
|
45
45
|
width = lockWidth;
|
|
@@ -208,7 +208,7 @@ export const imageResizing = (options = { node: 'image', lockRatio: true }) => {
|
|
|
208
208
|
wrapper.style.top = rect.top + 'px';
|
|
209
209
|
wrapper.style.left = rect.left + 'px';
|
|
210
210
|
for (let i = 0; i < handles.length; i++) {
|
|
211
|
-
|
|
211
|
+
const dom = document.createElement('div');
|
|
212
212
|
dom.className = resizeHandle + ' ' + handles[i];
|
|
213
213
|
dom.setAttribute(dataResizeDirImage, handles[i]);
|
|
214
214
|
wrapper.appendChild(dom);
|
|
@@ -35,7 +35,7 @@ const applyToListItems = (tr, state, options) => {
|
|
|
35
35
|
const cleanListItems = (tr, state, options) => {
|
|
36
36
|
const stylesToClean = Object.keys(options.resetValues);
|
|
37
37
|
const { tr: transaction, doc, selection: { from, to } } = state;
|
|
38
|
-
doc.nodesBetween(from, to, (node, pos
|
|
38
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
39
39
|
if (node.type.name === options.listItem && inSelection(from, to, pos, node, doc)) {
|
|
40
40
|
let attrs = node.attrs;
|
|
41
41
|
const nodeStyles = parseStyle(node.attrs.style);
|
|
@@ -53,7 +53,7 @@ const cleanListItems = (tr, state, options) => {
|
|
|
53
53
|
if (step instanceof RemoveMarkStep) {
|
|
54
54
|
const mark = step.mark;
|
|
55
55
|
if (mark.type.name === 'style' && mark.attrs.style) {
|
|
56
|
-
const [name
|
|
56
|
+
const [name] = mark.attrs.style.split(/\s*:\s*/);
|
|
57
57
|
const $pos = transaction.doc.resolve(step.from);
|
|
58
58
|
const li = parentNode($pos, n => n.type.name === options.listItem);
|
|
59
59
|
if (li) {
|