@progress/kendo-editor-common 1.11.9-dev.202412020819 → 1.11.9-develop.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn/main.js +1 -1
- package/dist/es/DOMSerializer.js +71 -75
- package/dist/es/align.js +19 -16
- package/dist/es/blockNode.js +76 -78
- package/dist/es/blockquote.js +12 -9
- package/dist/es/cleanFormatting.js +16 -16
- package/dist/es/config/align-rules.js +8 -6
- package/dist/es/config/commands.js +9 -13
- package/dist/es/config/constants.js +9 -7
- package/dist/es/config/indent-rules.js +8 -6
- package/dist/es/config/keymap.js +20 -18
- package/dist/es/config/list-settings.js +7 -6
- package/dist/es/config/schema.js +184 -126
- package/dist/es/find-replace.js +34 -32
- package/dist/es/image.js +10 -7
- package/dist/es/indent.js +47 -44
- package/dist/es/inline-style.js +72 -70
- package/dist/es/link.js +51 -52
- package/dist/es/listConvert.js +37 -34
- package/dist/es/lists.js +83 -82
- package/dist/es/main.js +32 -33
- package/dist/es/mark.js +87 -92
- package/dist/es/paste.js +48 -46
- package/dist/es/plugins/caret-color.js +14 -11
- package/dist/es/plugins/csp-fix.js +23 -23
- package/dist/es/plugins/highlight.js +12 -10
- package/dist/es/plugins/image-resize.js +81 -81
- package/dist/es/plugins/list-markers-styles.js +43 -39
- package/dist/es/plugins/placeholder.js +12 -9
- package/dist/es/plugins/resize-utils.js +11 -9
- package/dist/es/plugins/spaces-fix.js +13 -10
- package/dist/es/plugins/table-resize/column-resize.js +104 -102
- package/dist/es/plugins/table-resize/index.js +10 -7
- package/dist/es/plugins/table-resize/row-resize.js +88 -89
- package/dist/es/plugins/table-resize/table-resize.js +129 -122
- package/dist/es/plugins/table-resize/table-view.js +46 -48
- package/dist/es/plugins/table-resize/utils.js +39 -41
- package/dist/es/source.js +78 -74
- package/dist/es/table.js +64 -66
- package/dist/es/text.js +4 -2
- package/dist/es/utils.js +107 -116
- package/dist/es2015/DOMSerializer.js +20 -17
- package/dist/es2015/align.js +6 -3
- package/dist/es2015/blockNode.js +15 -12
- package/dist/es2015/blockquote.js +5 -2
- package/dist/es2015/cleanFormatting.js +6 -3
- package/dist/es2015/config/align-rules.js +7 -5
- package/dist/es2015/config/commands.js +9 -13
- package/dist/es2015/config/constants.js +9 -7
- package/dist/es2015/config/indent-rules.js +6 -3
- package/dist/es2015/config/keymap.js +10 -7
- package/dist/es2015/config/list-settings.js +5 -3
- package/dist/es2015/config/schema.js +8 -6
- package/dist/es2015/find-replace.js +9 -6
- package/dist/es2015/image.js +5 -2
- package/dist/es2015/indent.js +14 -11
- package/dist/es2015/inline-style.js +9 -6
- package/dist/es2015/link.js +7 -4
- package/dist/es2015/listConvert.js +5 -2
- package/dist/es2015/lists.js +14 -11
- package/dist/es2015/main.js +32 -33
- package/dist/es2015/mark.js +15 -12
- package/dist/es2015/node_modules/tslib/tslib.es6.js +35 -0
- package/dist/es2015/paste.js +14 -11
- package/dist/es2015/plugins/caret-color.js +8 -5
- package/dist/es2015/plugins/csp-fix.js +5 -2
- package/dist/es2015/plugins/highlight.js +6 -3
- package/dist/es2015/plugins/image-resize.js +10 -7
- package/dist/es2015/plugins/list-markers-styles.js +6 -3
- package/dist/es2015/plugins/placeholder.js +5 -2
- package/dist/es2015/plugins/resize-utils.js +11 -9
- package/dist/es2015/plugins/spaces-fix.js +4 -1
- package/dist/es2015/plugins/table-resize/column-resize.js +24 -21
- package/dist/es2015/plugins/table-resize/index.js +9 -6
- package/dist/es2015/plugins/table-resize/row-resize.js +23 -20
- package/dist/es2015/plugins/table-resize/table-resize.js +20 -17
- package/dist/es2015/plugins/table-resize/table-view.js +9 -6
- package/dist/es2015/plugins/table-resize/utils.js +13 -10
- package/dist/es2015/source.js +24 -13
- package/dist/es2015/table.js +18 -15
- package/dist/es2015/text.js +3 -1
- package/dist/es2015/utils.js +22 -25
- package/dist/npm/DOMSerializer.js +73 -78
- package/dist/npm/align.d.ts +7 -4
- package/dist/npm/align.js +22 -21
- package/dist/npm/blockNode.d.ts +14 -15
- package/dist/npm/blockNode.js +91 -95
- package/dist/npm/blockquote.d.ts +5 -2
- package/dist/npm/blockquote.js +16 -15
- package/dist/npm/cleanFormatting.d.ts +6 -3
- package/dist/npm/cleanFormatting.js +17 -19
- package/dist/npm/config/align-rules.d.ts +8 -6
- package/dist/npm/config/align-rules.js +14 -9
- package/dist/npm/config/commands.d.ts +11 -19
- package/dist/npm/config/commands.js +17 -16
- package/dist/npm/config/constants.js +17 -10
- package/dist/npm/config/indent-rules.d.ts +6 -4
- package/dist/npm/config/indent-rules.js +11 -9
- package/dist/npm/config/keymap.d.ts +5 -2
- package/dist/npm/config/keymap.js +30 -30
- package/dist/npm/config/list-settings.js +13 -11
- package/dist/npm/config/schema.d.ts +4 -3
- package/dist/npm/config/schema.js +191 -134
- package/dist/npm/find-replace.d.ts +10 -7
- package/dist/npm/find-replace.js +47 -47
- package/dist/npm/image.d.ts +6 -3
- package/dist/npm/image.js +11 -10
- package/dist/npm/indent.d.ts +12 -9
- package/dist/npm/indent.js +68 -67
- package/dist/npm/inline-style.d.ts +7 -4
- package/dist/npm/inline-style.js +83 -83
- package/dist/npm/link.d.ts +4 -2
- package/dist/npm/link.js +58 -61
- package/dist/npm/listConvert.d.ts +3 -1
- package/dist/npm/listConvert.js +40 -39
- package/dist/npm/lists.d.ts +9 -9
- package/dist/npm/lists.js +94 -95
- package/dist/npm/main.d.ts +34 -33
- package/dist/npm/main.js +388 -198
- package/dist/npm/mark.d.ts +13 -18
- package/dist/npm/mark.js +104 -111
- package/dist/npm/paste.d.ts +12 -9
- package/dist/npm/paste.js +61 -61
- package/dist/npm/plugins/caret-color.d.ts +6 -3
- package/dist/npm/plugins/caret-color.js +21 -19
- package/dist/npm/plugins/csp-fix.d.ts +4 -1
- package/dist/npm/plugins/csp-fix.js +28 -30
- package/dist/npm/plugins/highlight.d.ts +7 -4
- package/dist/npm/plugins/highlight.js +17 -16
- package/dist/npm/plugins/image-resize.d.ts +7 -5
- package/dist/npm/plugins/image-resize.js +96 -97
- package/dist/npm/plugins/list-markers-styles.d.ts +5 -2
- package/dist/npm/plugins/list-markers-styles.js +49 -47
- package/dist/npm/plugins/placeholder.d.ts +4 -1
- package/dist/npm/plugins/placeholder.js +18 -17
- package/dist/npm/plugins/resize-utils.js +14 -12
- package/dist/npm/plugins/spaces-fix.d.ts +4 -1
- package/dist/npm/plugins/spaces-fix.js +19 -18
- package/dist/npm/plugins/table-resize/column-resize.js +117 -117
- package/dist/npm/plugins/table-resize/index.d.ts +5 -2
- package/dist/npm/plugins/table-resize/index.js +16 -15
- package/dist/npm/plugins/table-resize/row-resize.js +98 -101
- package/dist/npm/plugins/table-resize/table-resize.js +144 -139
- package/dist/npm/plugins/table-resize/table-view.js +59 -61
- package/dist/npm/plugins/table-resize/utils.d.ts +7 -17
- package/dist/npm/plugins/table-resize/utils.js +51 -52
- package/dist/npm/source.d.ts +18 -11
- package/dist/npm/source.js +94 -91
- package/dist/npm/table.d.ts +10 -9
- package/dist/npm/table.js +93 -82
- package/dist/npm/text.d.ts +6 -3
- package/dist/npm/text.js +5 -5
- package/dist/npm/types/active-marks.d.ts +4 -1
- package/dist/npm/types/command.d.ts +5 -2
- package/dist/npm/types/dispatchFn.d.ts +4 -1
- package/dist/npm/types/paste-cleanup-settings.d.ts +3 -1
- package/dist/npm/utils.d.ts +13 -32
- package/dist/npm/utils.js +133 -145
- package/package.json +34 -52
- package/dist/cdn/js/kendo-editor-common.js +0 -1
- package/dist/es/types/active-marks.js +0 -1
- package/dist/es/types/command.js +0 -1
- package/dist/es/types/dispatchFn.js +0 -1
- package/dist/es/types/paste-cleanup-settings.js +0 -1
- package/dist/es/types/predicate.js +0 -1
- package/dist/es2015/types/active-marks.js +0 -1
- package/dist/es2015/types/command.js +0 -1
- package/dist/es2015/types/dispatchFn.js +0 -1
- package/dist/es2015/types/paste-cleanup-settings.js +0 -1
- package/dist/es2015/types/predicate.js +0 -1
- package/dist/npm/DOMSerializer.d.ts +0 -35
- package/dist/npm/config/constants.d.ts +0 -7
- package/dist/npm/config/list-settings.d.ts +0 -30
- package/dist/npm/plugins/resize-utils.d.ts +0 -35
- package/dist/npm/plugins/table-resize/column-resize.d.ts +0 -2
- package/dist/npm/plugins/table-resize/row-resize.d.ts +0 -2
- package/dist/npm/plugins/table-resize/table-resize.d.ts +0 -18
- package/dist/npm/plugins/table-resize/table-view.d.ts +0 -28
- package/dist/npm/types/active-marks.js +0 -2
- package/dist/npm/types/command.js +0 -2
- package/dist/npm/types/dispatchFn.js +0 -2
- package/dist/npm/types/paste-cleanup-settings.js +0 -2
- package/dist/npm/types/predicate.d.ts +0 -1
- package/dist/npm/types/predicate.js +0 -2
- package/dist/systemjs/kendo-editor-common.js +0 -1
package/dist/es/DOMSerializer.js
CHANGED
|
@@ -1,25 +1,10 @@
|
|
|
1
|
-
import { setAttribute } from './utils';
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
function DOMSerializer(
|
|
11
|
-
/// The node serialization functions.
|
|
12
|
-
nodes,
|
|
13
|
-
/// The mark serialization functions.
|
|
14
|
-
marks) {
|
|
15
|
-
this.nodes = nodes;
|
|
16
|
-
this.marks = marks;
|
|
17
|
-
}
|
|
1
|
+
import { setAttribute } from './utils.js';
|
|
2
|
+
|
|
3
|
+
class DOMSerializer {
|
|
18
4
|
/// Render an [output spec](#model.DOMOutputSpec) to a DOM node. If
|
|
19
5
|
/// the spec has a hole (zero) in it, `contentDOM` will point at the
|
|
20
6
|
/// node with the hole.
|
|
21
|
-
|
|
22
|
-
if (xmlNS === void 0) { xmlNS = null; }
|
|
7
|
+
static renderSpec(docum, structure, xmlNS = null) {
|
|
23
8
|
if (typeof structure === 'string') {
|
|
24
9
|
return { dom: docum.createTextNode(structure) };
|
|
25
10
|
}
|
|
@@ -29,38 +14,38 @@ var DOMSerializer = /** @class */ (function () {
|
|
|
29
14
|
if (structure.dom && structure.dom.nodeType != null) {
|
|
30
15
|
return structure;
|
|
31
16
|
}
|
|
32
|
-
|
|
17
|
+
let tagName = structure[0], space = tagName.indexOf(' ');
|
|
33
18
|
if (space > 0) {
|
|
34
19
|
xmlNS = tagName.slice(0, space);
|
|
35
20
|
tagName = tagName.slice(space + 1);
|
|
36
21
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
22
|
+
let contentDOM;
|
|
23
|
+
const dom = (xmlNS ? docum.createElementNS(xmlNS, tagName) : docum.createElement(tagName));
|
|
24
|
+
let attrs = structure[1], start = 1;
|
|
40
25
|
if (attrs && typeof attrs === 'object' && attrs.nodeType == null && !Array.isArray(attrs)) {
|
|
41
26
|
start = 2;
|
|
42
|
-
for (
|
|
43
|
-
if (attrs[
|
|
44
|
-
space =
|
|
27
|
+
for (const name in attrs) {
|
|
28
|
+
if (attrs[name] != null) {
|
|
29
|
+
space = name.indexOf(' ');
|
|
45
30
|
if (space > 0) {
|
|
46
|
-
dom.setAttributeNS(
|
|
31
|
+
dom.setAttributeNS(name.slice(0, space), name.slice(space + 1), attrs[name]);
|
|
47
32
|
}
|
|
48
33
|
else {
|
|
49
|
-
setAttribute(dom,
|
|
34
|
+
setAttribute(dom, name, attrs[name]);
|
|
50
35
|
}
|
|
51
36
|
}
|
|
52
37
|
}
|
|
53
38
|
}
|
|
54
|
-
for (
|
|
55
|
-
|
|
39
|
+
for (let i = start; i < structure.length; i++) {
|
|
40
|
+
const child = structure[i];
|
|
56
41
|
if (child === 0) {
|
|
57
42
|
if (i < structure.length - 1 || i > start) {
|
|
58
43
|
throw new RangeError('Content hole must be the only child of its parent node');
|
|
59
44
|
}
|
|
60
|
-
return { dom
|
|
45
|
+
return { dom, contentDOM: dom };
|
|
61
46
|
}
|
|
62
47
|
else {
|
|
63
|
-
|
|
48
|
+
const { dom: inner, contentDOM: innerContent } = DOMSerializer.renderSpec(docum, child, xmlNS);
|
|
64
49
|
dom.appendChild(inner);
|
|
65
50
|
if (innerContent) {
|
|
66
51
|
if (contentDOM) {
|
|
@@ -70,44 +55,57 @@ var DOMSerializer = /** @class */ (function () {
|
|
|
70
55
|
}
|
|
71
56
|
}
|
|
72
57
|
}
|
|
73
|
-
return { dom
|
|
74
|
-
}
|
|
58
|
+
return { dom, contentDOM };
|
|
59
|
+
}
|
|
75
60
|
/// Build a serializer using the [`toDOM`](#model.NodeSpec.toDOM)
|
|
76
61
|
/// properties in a schema's node and mark specs.
|
|
77
|
-
|
|
62
|
+
static fromSchema(schema) {
|
|
78
63
|
return schema.cached.domSerializer ||
|
|
79
64
|
(schema.cached.domSerializer = new DOMSerializer(this.nodesFromSchema(schema), this.marksFromSchema(schema)));
|
|
80
|
-
}
|
|
65
|
+
}
|
|
81
66
|
/// Gather the serializers in a schema's node specs into an object.
|
|
82
67
|
/// This can be useful as a base to build a custom serializer from.
|
|
83
|
-
|
|
84
|
-
|
|
68
|
+
static nodesFromSchema(schema) {
|
|
69
|
+
const result = gatherToDOM(schema.nodes);
|
|
85
70
|
if (!result.text) {
|
|
86
|
-
result.text =
|
|
71
|
+
result.text = node => node.text;
|
|
87
72
|
}
|
|
88
73
|
return result;
|
|
89
|
-
}
|
|
74
|
+
}
|
|
90
75
|
/// Gather the serializers in a schema's mark specs into an object.
|
|
91
|
-
|
|
76
|
+
static marksFromSchema(schema) {
|
|
92
77
|
return gatherToDOM(schema.marks);
|
|
93
|
-
}
|
|
78
|
+
}
|
|
79
|
+
/// Create a serializer. `nodes` should map node names to functions
|
|
80
|
+
/// that take a node and return a description of the corresponding
|
|
81
|
+
/// DOM. `marks` does the same for mark names, but also gets an
|
|
82
|
+
/// argument that tells it whether the mark's content is block or
|
|
83
|
+
/// inline content (for typical use, it'll always be inline). A mark
|
|
84
|
+
/// serializer may be `null` to indicate that marks of that type
|
|
85
|
+
/// should not be serialized.
|
|
86
|
+
constructor(
|
|
87
|
+
/// The node serialization functions.
|
|
88
|
+
nodes,
|
|
89
|
+
/// The mark serialization functions.
|
|
90
|
+
marks) {
|
|
91
|
+
this.nodes = nodes;
|
|
92
|
+
this.marks = marks;
|
|
93
|
+
}
|
|
94
94
|
/// Serialize the content of this fragment to a DOM fragment. When
|
|
95
95
|
/// not in the browser, the `document` option, containing a DOM
|
|
96
96
|
/// document, should be passed so that the serializer can create
|
|
97
97
|
/// nodes.
|
|
98
|
-
|
|
99
|
-
var _this = this;
|
|
100
|
-
if (options === void 0) { options = {}; }
|
|
98
|
+
serializeFragment(fragment, options = {}, target) {
|
|
101
99
|
if (!target) {
|
|
102
100
|
target = doc(options).createDocumentFragment();
|
|
103
101
|
}
|
|
104
|
-
|
|
105
|
-
fragment.forEach(
|
|
102
|
+
let top = target, active = [];
|
|
103
|
+
fragment.forEach(node => {
|
|
106
104
|
if (active.length || node.marks.length) {
|
|
107
|
-
|
|
105
|
+
let keep = 0, rendered = 0;
|
|
108
106
|
while (keep < active.length && rendered < node.marks.length) {
|
|
109
|
-
|
|
110
|
-
if (!
|
|
107
|
+
const next = node.marks[rendered];
|
|
108
|
+
if (!this.marks[next.type.name]) {
|
|
111
109
|
rendered++;
|
|
112
110
|
continue;
|
|
113
111
|
}
|
|
@@ -121,8 +119,8 @@ var DOMSerializer = /** @class */ (function () {
|
|
|
121
119
|
top = active.pop()[1];
|
|
122
120
|
}
|
|
123
121
|
while (rendered < node.marks.length) {
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
const add = node.marks[rendered++];
|
|
123
|
+
const markDOM = this.serializeMark(add, node.isInline, options);
|
|
126
124
|
if (markDOM) {
|
|
127
125
|
active.push([add, top]);
|
|
128
126
|
top.appendChild(markDOM.dom);
|
|
@@ -130,36 +128,34 @@ var DOMSerializer = /** @class */ (function () {
|
|
|
130
128
|
}
|
|
131
129
|
}
|
|
132
130
|
}
|
|
133
|
-
top.appendChild(
|
|
131
|
+
top.appendChild(this.serializeNodeInner(node, options));
|
|
134
132
|
});
|
|
135
133
|
return target;
|
|
136
|
-
}
|
|
134
|
+
}
|
|
137
135
|
/// Serialize this node to a DOM node. This can be useful when you
|
|
138
136
|
/// need to serialize a part of a document, as opposed to the whole
|
|
139
137
|
/// document. To serialize a whole document, use
|
|
140
138
|
/// [`serializeFragment`](#model.DOMSerializer.serializeFragment) on
|
|
141
139
|
/// its [content](#model.Node.content).
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
var wrap = this.serializeMark(node.marks[i], node.isInline, options);
|
|
140
|
+
serializeNode(node, options = {}) {
|
|
141
|
+
let dom = this.serializeNodeInner(node, options);
|
|
142
|
+
for (let i = node.marks.length - 1; i >= 0; i--) {
|
|
143
|
+
const wrap = this.serializeMark(node.marks[i], node.isInline, options);
|
|
147
144
|
if (wrap) {
|
|
148
145
|
(wrap.contentDOM || wrap.dom).appendChild(dom);
|
|
149
146
|
dom = wrap.dom;
|
|
150
147
|
}
|
|
151
148
|
}
|
|
152
149
|
return dom;
|
|
153
|
-
}
|
|
150
|
+
}
|
|
154
151
|
/// @internal
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
var toDOM = this.marks[mark.type.name];
|
|
152
|
+
serializeMark(mark, inline, options = {}) {
|
|
153
|
+
const toDOM = this.marks[mark.type.name];
|
|
158
154
|
return toDOM && DOMSerializer.renderSpec(doc(options), toDOM(mark, inline));
|
|
159
|
-
}
|
|
155
|
+
}
|
|
160
156
|
/// @internal
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
serializeNodeInner(node, options) {
|
|
158
|
+
const { dom, contentDOM } = DOMSerializer.renderSpec(doc(options), this.nodes[node.type.name](node));
|
|
163
159
|
if (contentDOM) {
|
|
164
160
|
if (node.isLeaf) {
|
|
165
161
|
throw new RangeError('Content hole not allowed in a leaf node spec');
|
|
@@ -167,17 +163,15 @@ var DOMSerializer = /** @class */ (function () {
|
|
|
167
163
|
this.serializeFragment(node.content, options, contentDOM);
|
|
168
164
|
}
|
|
169
165
|
return dom;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
}());
|
|
173
|
-
export { DOMSerializer };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
174
168
|
function gatherToDOM(obj) {
|
|
175
|
-
|
|
176
|
-
for (
|
|
177
|
-
if (obj[
|
|
178
|
-
|
|
169
|
+
const result = {};
|
|
170
|
+
for (const name in obj) {
|
|
171
|
+
if (obj[name]) {
|
|
172
|
+
const toDOM = obj[name].spec.toDOM;
|
|
179
173
|
if (toDOM) {
|
|
180
|
-
result[
|
|
174
|
+
result[name] = toDOM;
|
|
181
175
|
}
|
|
182
176
|
}
|
|
183
177
|
}
|
|
@@ -186,3 +180,5 @@ function gatherToDOM(obj) {
|
|
|
186
180
|
function doc(options) {
|
|
187
181
|
return options.document || window.document;
|
|
188
182
|
}
|
|
183
|
+
|
|
184
|
+
export { DOMSerializer };
|
package/dist/es/align.js
CHANGED
|
@@ -1,40 +1,43 @@
|
|
|
1
|
-
import { blockNodes, addStyles, changeTextBlock } from './blockNode';
|
|
1
|
+
import { blockNodes, addStyles, changeTextBlock } from './blockNode.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Aligning block elements in the selection.
|
|
4
5
|
*
|
|
5
6
|
* @returns {boolean} - Returns true if any alignment is applied.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const alignBlocks = (actions, commandName) => (state, dispatch) => {
|
|
9
|
+
const blocks = blockNodes(state);
|
|
10
|
+
const tr = state.tr;
|
|
10
11
|
tr.setMeta('commandName', commandName);
|
|
11
|
-
blocks.forEach(
|
|
12
|
+
blocks.forEach(node => {
|
|
12
13
|
if (node.type.isTextblock) {
|
|
13
|
-
|
|
14
|
+
const action = actions.find(n => n.node === node.type.name);
|
|
14
15
|
if (action) {
|
|
15
|
-
|
|
16
|
+
const newAttrs = addStyles(node, action.style);
|
|
16
17
|
changeTextBlock(tr, node, node.type, newAttrs);
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
+
const result = tr.docChanged;
|
|
21
22
|
if (result) {
|
|
22
23
|
dispatch(tr.scrollIntoView());
|
|
23
24
|
}
|
|
24
25
|
return result;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
blocks.forEach(
|
|
26
|
+
};
|
|
27
|
+
const isAligned = (state, actions) => {
|
|
28
|
+
const blocks = blockNodes(state);
|
|
29
|
+
let result = false;
|
|
30
|
+
blocks.forEach(node => {
|
|
30
31
|
if (!result && node.type.isTextblock && node.attrs.style) {
|
|
31
|
-
|
|
32
|
+
const action = actions.find(a => a.node === node.type.name);
|
|
32
33
|
if (action) {
|
|
33
|
-
result = action.style.every(
|
|
34
|
-
return !!style.value && new RegExp(
|
|
34
|
+
result = action.style.every(style => {
|
|
35
|
+
return !!style.value && new RegExp(`${style.name}:\\s?${style.value}`, 'i').test(node.attrs.style);
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
});
|
|
39
40
|
return result;
|
|
40
41
|
};
|
|
42
|
+
|
|
43
|
+
export { alignBlocks, isAligned };
|
package/dist/es/blockNode.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { changeStylesString } from './utils';
|
|
1
|
+
import { changeStylesString } from './utils.js';
|
|
3
2
|
import { ReplaceAroundStep } from 'prosemirror-transform';
|
|
4
|
-
import {
|
|
3
|
+
import { Slice, Fragment } from 'prosemirror-model';
|
|
5
4
|
import { NodeSelection } from 'prosemirror-state';
|
|
5
|
+
|
|
6
6
|
/**
|
|
7
7
|
* @hidden
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const canChangeType = (stateDoc, pos, type) => {
|
|
10
|
+
const $pos = stateDoc.resolve(pos), index = $pos.index();
|
|
11
11
|
return $pos.parent.canReplaceWith(index, index + 1, type);
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
@@ -16,25 +16,25 @@ var canChangeType = function (stateDoc, pos, type) {
|
|
|
16
16
|
* @example
|
|
17
17
|
* See `cleanTextBlockFormatting` or `formatBlockElements` function.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
const changeTextBlock = (tr, node, nodeType, attrs) => {
|
|
20
20
|
if (!nodeType.isTextblock) {
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
ranges.forEach(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
tr.doc.nodesBetween(from, to,
|
|
23
|
+
const { ranges } = tr.selection;
|
|
24
|
+
ranges.forEach(range => {
|
|
25
|
+
const mapFrom = tr.steps.length;
|
|
26
|
+
const from = range.$from.pos;
|
|
27
|
+
const to = range.$to.pos;
|
|
28
|
+
tr.doc.nodesBetween(from, to, (currNode, pos) => {
|
|
29
29
|
if (currNode.eq(node) &&
|
|
30
30
|
currNode.isTextblock &&
|
|
31
31
|
!currNode.hasMarkup(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
|
}
|
|
@@ -47,17 +47,16 @@ export var changeTextBlock = function (tr, node, nodeType, attrs) {
|
|
|
47
47
|
* @example
|
|
48
48
|
* See `cleanTextBlockFormatting` function.
|
|
49
49
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var selNode = selection instanceof NodeSelection ? selection.node : undefined;
|
|
50
|
+
const blockNodes = (state, options = { blocksInSelection: false }) => {
|
|
51
|
+
const { doc, selection } = state;
|
|
52
|
+
const { $from, ranges } = selection;
|
|
53
|
+
const { blocksInSelection } = options;
|
|
54
|
+
const result = [];
|
|
55
|
+
const selNode = selection instanceof NodeSelection ? selection.node : undefined;
|
|
57
56
|
if (selNode) {
|
|
58
57
|
if (selNode.isBlock) {
|
|
59
58
|
result.push(selNode);
|
|
60
|
-
selNode.nodesBetween(0, selNode.content.size,
|
|
59
|
+
selNode.nodesBetween(0, selNode.content.size, node => {
|
|
61
60
|
if (node.isBlock) {
|
|
62
61
|
result.push(node);
|
|
63
62
|
}
|
|
@@ -68,10 +67,10 @@ export var blockNodes = function (state, options) {
|
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
else {
|
|
71
|
-
ranges.forEach(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
doc.nodesBetween(from, to,
|
|
70
|
+
ranges.forEach(range => {
|
|
71
|
+
const from = range.$from.pos;
|
|
72
|
+
const to = range.$to.pos;
|
|
73
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
75
74
|
if (node.isBlock && (!blocksInSelection || (pos >= from && pos + node.content.size + 2 <= to))) {
|
|
76
75
|
result.push(node);
|
|
77
76
|
}
|
|
@@ -80,33 +79,31 @@ export var blockNodes = function (state, options) {
|
|
|
80
79
|
}
|
|
81
80
|
return result;
|
|
82
81
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
changeTextBlock(tr, node, nodes.blockquote, node.attrs);
|
|
101
|
-
}
|
|
82
|
+
const formatBlockElements = (value, commandName) => (state, dispatch) => {
|
|
83
|
+
const blocks = blockNodes(state);
|
|
84
|
+
const nodes = state.schema.nodes;
|
|
85
|
+
const tr = state.tr;
|
|
86
|
+
tr.setMeta('commandName', commandName);
|
|
87
|
+
tr.setMeta('args', { value });
|
|
88
|
+
blocks.forEach(node => {
|
|
89
|
+
if (node.type.isTextblock) {
|
|
90
|
+
if (value === 'p') {
|
|
91
|
+
changeTextBlock(tr, node, nodes.paragraph, node.attrs);
|
|
92
|
+
}
|
|
93
|
+
else if (/^h[1-6]$/i.test(value)) {
|
|
94
|
+
const level = parseInt(value.substr(1), 10);
|
|
95
|
+
changeTextBlock(tr, node, nodes.heading, { ...node.attrs, level });
|
|
96
|
+
}
|
|
97
|
+
else if (value === 'blockquote') {
|
|
98
|
+
changeTextBlock(tr, node, nodes.blockquote, node.attrs);
|
|
102
99
|
}
|
|
103
|
-
});
|
|
104
|
-
var result = tr.docChanged;
|
|
105
|
-
if (result) {
|
|
106
|
-
dispatch(tr.scrollIntoView());
|
|
107
100
|
}
|
|
108
|
-
|
|
109
|
-
|
|
101
|
+
});
|
|
102
|
+
const result = tr.docChanged;
|
|
103
|
+
if (result) {
|
|
104
|
+
dispatch(tr.scrollIntoView());
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
110
107
|
};
|
|
111
108
|
/**
|
|
112
109
|
* Removes the style and class attributes of text block elements.
|
|
@@ -115,30 +112,29 @@ export var formatBlockElements = function (value, commandName) {
|
|
|
115
112
|
* @example
|
|
116
113
|
* See `cleanFormatting` function.
|
|
117
114
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
var nodeType = blockNodeType || node.type;
|
|
115
|
+
const cleanTextBlockFormatting = (tr, options = { blocksInSelection: true }) => {
|
|
116
|
+
const { doc, selection } = tr;
|
|
117
|
+
const { blocksInSelection, blockNodeType } = options;
|
|
118
|
+
const nodes = blockNodes({ doc, selection }, { blocksInSelection });
|
|
119
|
+
const textBlocks = nodes.filter(node => node.isTextblock);
|
|
120
|
+
textBlocks.forEach(node => {
|
|
121
|
+
const { style = '', class: className = '', ...attrs } = node.attrs || {};
|
|
122
|
+
const nodeType = blockNodeType || node.type;
|
|
127
123
|
if (style || className || nodeType !== node.type) {
|
|
128
124
|
changeTextBlock(tr, node, nodeType, attrs);
|
|
129
125
|
}
|
|
130
126
|
});
|
|
131
127
|
};
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
blocks.forEach(
|
|
128
|
+
const getBlockFormats = (state) => {
|
|
129
|
+
const blocks = blockNodes(state);
|
|
130
|
+
const nodes = state.schema.nodes;
|
|
131
|
+
const result = [];
|
|
132
|
+
blocks.forEach((node) => {
|
|
137
133
|
if (node.type === nodes.paragraph) {
|
|
138
134
|
result.push('p');
|
|
139
135
|
}
|
|
140
136
|
else if (node.type === nodes.heading) {
|
|
141
|
-
result.push(
|
|
137
|
+
result.push(`h${node.attrs.level}`);
|
|
142
138
|
}
|
|
143
139
|
else if (node.type === nodes.blockquote && nodes.blockquote.isTextblock) {
|
|
144
140
|
// In case the blockquote can have inline content.
|
|
@@ -147,35 +143,37 @@ export var getBlockFormats = function (state) {
|
|
|
147
143
|
});
|
|
148
144
|
return result;
|
|
149
145
|
};
|
|
150
|
-
|
|
151
|
-
|
|
146
|
+
const addStyles = (node, stylesToApply) => {
|
|
147
|
+
let currentStyles = node.attrs.style, changedStyleResult, toChange;
|
|
152
148
|
if (currentStyles) {
|
|
153
|
-
stylesToApply.forEach(
|
|
149
|
+
stylesToApply.forEach(style => {
|
|
154
150
|
toChange = { style: style.name, value: /^.+$/, newValue: style.value };
|
|
155
151
|
changedStyleResult = changeStylesString(currentStyles, toChange);
|
|
156
152
|
currentStyles = changedStyleResult.changed ? changedStyleResult.style : currentStyles;
|
|
157
153
|
});
|
|
158
154
|
}
|
|
159
|
-
|
|
155
|
+
const reducer = (acc, curr) => ((acc && curr.value ? acc + ' ' : '') + curr.value ? `${curr.name}: ${curr.value};` : '');
|
|
160
156
|
currentStyles = currentStyles || stylesToApply.reduce(reducer, '');
|
|
161
157
|
return Object.assign({}, node.attrs, { style: currentStyles || null });
|
|
162
158
|
};
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
state.doc.nodesBetween(from, to,
|
|
159
|
+
const hasNode = (state, nodeType) => {
|
|
160
|
+
const { from, to } = state.selection;
|
|
161
|
+
let result = false;
|
|
162
|
+
state.doc.nodesBetween(from, to, node => {
|
|
167
163
|
result = result || node.type === nodeType;
|
|
168
164
|
return !result;
|
|
169
165
|
});
|
|
170
166
|
return result;
|
|
171
167
|
};
|
|
172
|
-
|
|
173
|
-
|
|
168
|
+
const parentBlockFormat = (state) => {
|
|
169
|
+
const formats = getBlockFormats(state);
|
|
174
170
|
return new Set(formats).size === 1 ? formats[0] : null;
|
|
175
171
|
};
|
|
176
172
|
/**
|
|
177
173
|
* **Deprecated.** Use `parentBlockFormat` function instead.
|
|
178
174
|
*/
|
|
179
|
-
|
|
175
|
+
const activeNode = (state) => {
|
|
180
176
|
return { tag: parentBlockFormat(state) || '' };
|
|
181
177
|
};
|
|
178
|
+
|
|
179
|
+
export { activeNode, addStyles, blockNodes, changeTextBlock, cleanTextBlockFormatting, formatBlockElements, getBlockFormats, hasNode, parentBlockFormat };
|
package/dist/es/blockquote.js
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import { wrapIn } from 'prosemirror-commands';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
const blockquote = (state, dispatch) => {
|
|
3
4
|
return wrapIn(state.schema.nodes.blockquote)(state, dispatch);
|
|
4
5
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const liftBlockquote = (state, dispatch) => {
|
|
7
|
+
const { $from, $to } = state.selection;
|
|
8
|
+
const nodeType = state.schema.nodes.blockquote;
|
|
9
|
+
const doc = state.doc;
|
|
10
|
+
let target = -1;
|
|
11
|
+
const range = $from.blockRange($to);
|
|
11
12
|
if (range) {
|
|
12
|
-
doc.nodesBetween(range.start, range.end,
|
|
13
|
+
doc.nodesBetween(range.start, range.end, (node, pos) => {
|
|
13
14
|
if (node.type === nodeType) {
|
|
14
15
|
target = pos;
|
|
15
16
|
}
|
|
16
17
|
});
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
const result = target !== -1;
|
|
19
20
|
if (dispatch && result) {
|
|
20
21
|
dispatch(state.tr.lift(range, doc.resolve(target).depth));
|
|
21
22
|
}
|
|
22
23
|
return result;
|
|
23
24
|
};
|
|
25
|
+
|
|
26
|
+
export { blockquote, liftBlockquote };
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { cleanTextBlockFormatting } from './blockNode';
|
|
2
|
-
import { cleanMarks } from './mark';
|
|
1
|
+
import { cleanTextBlockFormatting } from './blockNode.js';
|
|
2
|
+
import { cleanMarks } from './mark.js';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* A command which removes the inline formatting, class and style attributes of paragraph and heading elements in the selection.
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
};
|
|
7
|
+
const cleanFormatting = (options = { blocksInSelection: true }) => (state, dispatch) => {
|
|
8
|
+
const tr = state.tr;
|
|
9
|
+
const { blocksInSelection, blockNodeType, exceptMarks } = options;
|
|
10
|
+
const except = (exceptMarks || [state.schema.marks.link]).filter(Boolean);
|
|
11
|
+
cleanMarks(tr, { except });
|
|
12
|
+
cleanTextBlockFormatting(tr, { blocksInSelection, blockNodeType });
|
|
13
|
+
const result = tr.docChanged;
|
|
14
|
+
if (result && dispatch) {
|
|
15
|
+
dispatch(tr);
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
20
18
|
};
|
|
19
|
+
|
|
20
|
+
export { cleanFormatting };
|