@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/es2015/utils.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Node
|
|
2
|
-
import { TextSelection, AllSelection
|
|
1
|
+
import { Node } from 'prosemirror-model';
|
|
2
|
+
import { NodeSelection, TextSelection, AllSelection } from 'prosemirror-state';
|
|
3
3
|
import { parseInlineStyles } from '@progress/kendo-common';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
const changeStylesString = (styleText, newStyle) => {
|
|
6
6
|
const styleToChange = newStyle.style;
|
|
7
7
|
const regExp = newStyle.value;
|
|
8
8
|
const newValue = newStyle.newValue;
|
|
@@ -27,7 +27,7 @@ export const changeStylesString = (styleText, newStyle) => {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
const reAnyValue = /^.+$/;
|
|
30
|
-
|
|
30
|
+
function setNodeStyle(nodeAttrs, styleType, value) {
|
|
31
31
|
let attrs;
|
|
32
32
|
if (new RegExp('[^-]?' + styleType + ':').test(nodeAttrs.style || '')) {
|
|
33
33
|
const { style } = changeStylesString(nodeAttrs.style || '', { style: styleType, value: reAnyValue, newValue: value });
|
|
@@ -44,7 +44,7 @@ export function setNodeStyle(nodeAttrs, styleType, value) {
|
|
|
44
44
|
/**
|
|
45
45
|
* Determines if a given node type can be inserted at the current cursor position.
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
const canInsert = (state, nodeType) => {
|
|
48
48
|
const $from = state.selection.$from;
|
|
49
49
|
for (let d = $from.depth; d >= 0; d--) {
|
|
50
50
|
const index = $from.index(d);
|
|
@@ -71,12 +71,12 @@ const findNthParentNode = (predicate, depth = 1) => {
|
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
73
|
};
|
|
74
|
-
|
|
74
|
+
const findNthParentNodeOfType = (nodeType, depth = 1) => {
|
|
75
75
|
return (selection) => {
|
|
76
76
|
return findNthParentNode((node) => getTypeName(node) === getTypeName(nodeType), depth)(selection);
|
|
77
77
|
};
|
|
78
78
|
};
|
|
79
|
-
|
|
79
|
+
function parentNode(pos, predicate) {
|
|
80
80
|
for (let depth = pos.depth; depth > 0; depth--) {
|
|
81
81
|
const node = pos.node(depth);
|
|
82
82
|
if (predicate(node)) {
|
|
@@ -97,7 +97,7 @@ const filterEmptyAttrs = (attrs) => {
|
|
|
97
97
|
/**
|
|
98
98
|
* Inserts the given node at the place of current selection.
|
|
99
99
|
*/
|
|
100
|
-
|
|
100
|
+
const insertNode = (node, scrollIntoView) => (state, dispatch) => {
|
|
101
101
|
const { selection, tr } = state;
|
|
102
102
|
if (selection instanceof NodeSelection
|
|
103
103
|
&& selection.node.type.name === node.type.name
|
|
@@ -113,12 +113,7 @@ export const insertNode = (node, scrollIntoView) => (state, dispatch) => {
|
|
|
113
113
|
}
|
|
114
114
|
dispatch(tr);
|
|
115
115
|
};
|
|
116
|
-
|
|
117
|
-
const fragment1 = Fragment.from(parseContent(dom1, schema, parseOptions));
|
|
118
|
-
const fragment2 = Fragment.from(parseContent(dom2, schema, parseOptions));
|
|
119
|
-
return fragment1.eq(fragment2);
|
|
120
|
-
};
|
|
121
|
-
export const getSelectionText = (state) => {
|
|
116
|
+
const getSelectionText = (state) => {
|
|
122
117
|
const sel = state.selection;
|
|
123
118
|
if (sel instanceof TextSelection || sel instanceof AllSelection) {
|
|
124
119
|
const fragment = sel.content().content;
|
|
@@ -126,7 +121,7 @@ export const getSelectionText = (state) => {
|
|
|
126
121
|
}
|
|
127
122
|
return '';
|
|
128
123
|
};
|
|
129
|
-
|
|
124
|
+
const getNodeFromSelection = (state) => {
|
|
130
125
|
if (state.selection instanceof NodeSelection) {
|
|
131
126
|
return state.selection.node;
|
|
132
127
|
}
|
|
@@ -139,7 +134,7 @@ export const getNodeFromSelection = (state) => {
|
|
|
139
134
|
* Useful for values of the inputs of Link and Find&Replace dialogs where the inputs value has been retrieved from the selection and
|
|
140
135
|
* should be single line text only.
|
|
141
136
|
*/
|
|
142
|
-
|
|
137
|
+
const selectedLineTextOnly = (state) => {
|
|
143
138
|
let result = '', hasLeafs = false;
|
|
144
139
|
const { selection, doc } = state;
|
|
145
140
|
const { $from, $to, from, to } = selection;
|
|
@@ -156,13 +151,13 @@ export const selectedLineTextOnly = (state) => {
|
|
|
156
151
|
/**
|
|
157
152
|
* Used by ViewHtml/ViewSource dialogs for making the HTML more readable.
|
|
158
153
|
*/
|
|
159
|
-
|
|
154
|
+
const indentHtml = (content) => {
|
|
160
155
|
return content.replace(/<\/(p|li|ul|ol|h[1-6]|table|tr|td|th)>/ig, '</$1>\n')
|
|
161
156
|
.replace(/<(ul|ol)([^>]*)><li/ig, '<$1$2>\n<li')
|
|
162
157
|
.replace(/<br \/>/ig, '<br />\n')
|
|
163
158
|
.replace(/\n$/, '');
|
|
164
159
|
};
|
|
165
|
-
|
|
160
|
+
const shallowEqual = (object1, object2) => {
|
|
166
161
|
const keys1 = Object.keys(object1);
|
|
167
162
|
const keys2 = Object.keys(object2);
|
|
168
163
|
return keys1.length === keys2.length &&
|
|
@@ -173,7 +168,7 @@ const applyToWordDefault = { before: /[^ !,?.\[\]{}()]+$/i, after: /^[^ !,?.\[\]
|
|
|
173
168
|
* if options.applyToWord is set, expands the selection to the word where the cursor is and
|
|
174
169
|
* returns modified state and dispatch.
|
|
175
170
|
*/
|
|
176
|
-
|
|
171
|
+
const expandSelection = (state, dispatch, options) => {
|
|
177
172
|
if (!options.applyToWord || !state.selection.empty) {
|
|
178
173
|
return { state, dispatch };
|
|
179
174
|
}
|
|
@@ -249,16 +244,16 @@ export const expandSelection = (state, dispatch, options) => {
|
|
|
249
244
|
* const command = expandToWordWrap(toggleInlineFormat, {...bold, applyToWord );
|
|
250
245
|
* command(view.state, view.dispatch);
|
|
251
246
|
*/
|
|
252
|
-
|
|
247
|
+
const expandToWordWrap = (command, options) => {
|
|
253
248
|
return (state, dispatch) => {
|
|
254
249
|
const { state: cmdState, dispatch: cmdDispatch } = expandSelection(state, dispatch, options);
|
|
255
250
|
return command(options)(cmdState, cmdDispatch);
|
|
256
251
|
};
|
|
257
252
|
};
|
|
258
|
-
|
|
253
|
+
const parseStyle = (styleText) => {
|
|
259
254
|
return parseInlineStyles(styleText);
|
|
260
255
|
};
|
|
261
|
-
|
|
256
|
+
const applyStyle = (styleText, styleType, styleValue) => {
|
|
262
257
|
const styles = parseStyle(styleText);
|
|
263
258
|
styles[styleType] = styleValue;
|
|
264
259
|
const result = Object.keys(styles)
|
|
@@ -267,7 +262,7 @@ export const applyStyle = (styleText, styleType, styleValue) => {
|
|
|
267
262
|
.join('; ');
|
|
268
263
|
return result ? result + ';' : null;
|
|
269
264
|
};
|
|
270
|
-
|
|
265
|
+
const setStyleAttr = (element, styleString) => {
|
|
271
266
|
const styles = parseStyle(styleString);
|
|
272
267
|
for (const style in styles) {
|
|
273
268
|
if (style && typeof element.style[style] !== 'undefined') {
|
|
@@ -275,7 +270,7 @@ export const setStyleAttr = (element, styleString) => {
|
|
|
275
270
|
}
|
|
276
271
|
}
|
|
277
272
|
};
|
|
278
|
-
|
|
273
|
+
const setAttribute = (node, attrName, value) => {
|
|
279
274
|
const current = node.getAttribute(attrName);
|
|
280
275
|
if (value !== undefined && value !== current) {
|
|
281
276
|
if (attrName === 'style') {
|
|
@@ -290,3 +285,5 @@ export const setAttribute = (node, attrName, value) => {
|
|
|
290
285
|
node.removeAttribute(attrName);
|
|
291
286
|
}
|
|
292
287
|
};
|
|
288
|
+
|
|
289
|
+
export { applyStyle, canInsert, changeStylesString, expandSelection, expandToWordWrap, findNthParentNodeOfType, getNodeFromSelection, getSelectionText, indentHtml, insertNode, parentNode, parseStyle, selectedLineTextOnly, setAttribute, setNodeStyle, setStyleAttr, shallowEqual };
|
|
@@ -1,28 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/// Create a serializer. `nodes` should map node names to functions
|
|
7
|
-
/// that take a node and return a description of the corresponding
|
|
8
|
-
/// DOM. `marks` does the same for mark names, but also gets an
|
|
9
|
-
/// argument that tells it whether the mark's content is block or
|
|
10
|
-
/// inline content (for typical use, it'll always be inline). A mark
|
|
11
|
-
/// serializer may be `null` to indicate that marks of that type
|
|
12
|
-
/// should not be serialized.
|
|
13
|
-
function DOMSerializer(
|
|
14
|
-
/// The node serialization functions.
|
|
15
|
-
nodes,
|
|
16
|
-
/// The mark serialization functions.
|
|
17
|
-
marks) {
|
|
18
|
-
this.nodes = nodes;
|
|
19
|
-
this.marks = marks;
|
|
20
|
-
}
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('./utils.js');
|
|
4
|
+
|
|
5
|
+
class DOMSerializer {
|
|
21
6
|
/// Render an [output spec](#model.DOMOutputSpec) to a DOM node. If
|
|
22
7
|
/// the spec has a hole (zero) in it, `contentDOM` will point at the
|
|
23
8
|
/// node with the hole.
|
|
24
|
-
|
|
25
|
-
if (xmlNS === void 0) { xmlNS = null; }
|
|
9
|
+
static renderSpec(docum, structure, xmlNS = null) {
|
|
26
10
|
if (typeof structure === 'string') {
|
|
27
11
|
return { dom: docum.createTextNode(structure) };
|
|
28
12
|
}
|
|
@@ -32,38 +16,38 @@ var DOMSerializer = /** @class */ (function () {
|
|
|
32
16
|
if (structure.dom && structure.dom.nodeType != null) {
|
|
33
17
|
return structure;
|
|
34
18
|
}
|
|
35
|
-
|
|
19
|
+
let tagName = structure[0], space = tagName.indexOf(' ');
|
|
36
20
|
if (space > 0) {
|
|
37
21
|
xmlNS = tagName.slice(0, space);
|
|
38
22
|
tagName = tagName.slice(space + 1);
|
|
39
23
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
24
|
+
let contentDOM;
|
|
25
|
+
const dom = (xmlNS ? docum.createElementNS(xmlNS, tagName) : docum.createElement(tagName));
|
|
26
|
+
let attrs = structure[1], start = 1;
|
|
43
27
|
if (attrs && typeof attrs === 'object' && attrs.nodeType == null && !Array.isArray(attrs)) {
|
|
44
28
|
start = 2;
|
|
45
|
-
for (
|
|
46
|
-
if (attrs[
|
|
47
|
-
space =
|
|
29
|
+
for (const name in attrs) {
|
|
30
|
+
if (attrs[name] != null) {
|
|
31
|
+
space = name.indexOf(' ');
|
|
48
32
|
if (space > 0) {
|
|
49
|
-
dom.setAttributeNS(
|
|
33
|
+
dom.setAttributeNS(name.slice(0, space), name.slice(space + 1), attrs[name]);
|
|
50
34
|
}
|
|
51
35
|
else {
|
|
52
|
-
|
|
36
|
+
utils.setAttribute(dom, name, attrs[name]);
|
|
53
37
|
}
|
|
54
38
|
}
|
|
55
39
|
}
|
|
56
40
|
}
|
|
57
|
-
for (
|
|
58
|
-
|
|
41
|
+
for (let i = start; i < structure.length; i++) {
|
|
42
|
+
const child = structure[i];
|
|
59
43
|
if (child === 0) {
|
|
60
44
|
if (i < structure.length - 1 || i > start) {
|
|
61
45
|
throw new RangeError('Content hole must be the only child of its parent node');
|
|
62
46
|
}
|
|
63
|
-
return { dom
|
|
47
|
+
return { dom, contentDOM: dom };
|
|
64
48
|
}
|
|
65
49
|
else {
|
|
66
|
-
|
|
50
|
+
const { dom: inner, contentDOM: innerContent } = DOMSerializer.renderSpec(docum, child, xmlNS);
|
|
67
51
|
dom.appendChild(inner);
|
|
68
52
|
if (innerContent) {
|
|
69
53
|
if (contentDOM) {
|
|
@@ -73,44 +57,57 @@ var DOMSerializer = /** @class */ (function () {
|
|
|
73
57
|
}
|
|
74
58
|
}
|
|
75
59
|
}
|
|
76
|
-
return { dom
|
|
77
|
-
}
|
|
60
|
+
return { dom, contentDOM };
|
|
61
|
+
}
|
|
78
62
|
/// Build a serializer using the [`toDOM`](#model.NodeSpec.toDOM)
|
|
79
63
|
/// properties in a schema's node and mark specs.
|
|
80
|
-
|
|
64
|
+
static fromSchema(schema) {
|
|
81
65
|
return schema.cached.domSerializer ||
|
|
82
66
|
(schema.cached.domSerializer = new DOMSerializer(this.nodesFromSchema(schema), this.marksFromSchema(schema)));
|
|
83
|
-
}
|
|
67
|
+
}
|
|
84
68
|
/// Gather the serializers in a schema's node specs into an object.
|
|
85
69
|
/// This can be useful as a base to build a custom serializer from.
|
|
86
|
-
|
|
87
|
-
|
|
70
|
+
static nodesFromSchema(schema) {
|
|
71
|
+
const result = gatherToDOM(schema.nodes);
|
|
88
72
|
if (!result.text) {
|
|
89
|
-
result.text =
|
|
73
|
+
result.text = node => node.text;
|
|
90
74
|
}
|
|
91
75
|
return result;
|
|
92
|
-
}
|
|
76
|
+
}
|
|
93
77
|
/// Gather the serializers in a schema's mark specs into an object.
|
|
94
|
-
|
|
78
|
+
static marksFromSchema(schema) {
|
|
95
79
|
return gatherToDOM(schema.marks);
|
|
96
|
-
}
|
|
80
|
+
}
|
|
81
|
+
/// Create a serializer. `nodes` should map node names to functions
|
|
82
|
+
/// that take a node and return a description of the corresponding
|
|
83
|
+
/// DOM. `marks` does the same for mark names, but also gets an
|
|
84
|
+
/// argument that tells it whether the mark's content is block or
|
|
85
|
+
/// inline content (for typical use, it'll always be inline). A mark
|
|
86
|
+
/// serializer may be `null` to indicate that marks of that type
|
|
87
|
+
/// should not be serialized.
|
|
88
|
+
constructor(
|
|
89
|
+
/// The node serialization functions.
|
|
90
|
+
nodes,
|
|
91
|
+
/// The mark serialization functions.
|
|
92
|
+
marks) {
|
|
93
|
+
this.nodes = nodes;
|
|
94
|
+
this.marks = marks;
|
|
95
|
+
}
|
|
97
96
|
/// Serialize the content of this fragment to a DOM fragment. When
|
|
98
97
|
/// not in the browser, the `document` option, containing a DOM
|
|
99
98
|
/// document, should be passed so that the serializer can create
|
|
100
99
|
/// nodes.
|
|
101
|
-
|
|
102
|
-
var _this = this;
|
|
103
|
-
if (options === void 0) { options = {}; }
|
|
100
|
+
serializeFragment(fragment, options = {}, target) {
|
|
104
101
|
if (!target) {
|
|
105
102
|
target = doc(options).createDocumentFragment();
|
|
106
103
|
}
|
|
107
|
-
|
|
108
|
-
fragment.forEach(
|
|
104
|
+
let top = target, active = [];
|
|
105
|
+
fragment.forEach(node => {
|
|
109
106
|
if (active.length || node.marks.length) {
|
|
110
|
-
|
|
107
|
+
let keep = 0, rendered = 0;
|
|
111
108
|
while (keep < active.length && rendered < node.marks.length) {
|
|
112
|
-
|
|
113
|
-
if (!
|
|
109
|
+
const next = node.marks[rendered];
|
|
110
|
+
if (!this.marks[next.type.name]) {
|
|
114
111
|
rendered++;
|
|
115
112
|
continue;
|
|
116
113
|
}
|
|
@@ -124,8 +121,8 @@ var DOMSerializer = /** @class */ (function () {
|
|
|
124
121
|
top = active.pop()[1];
|
|
125
122
|
}
|
|
126
123
|
while (rendered < node.marks.length) {
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
const add = node.marks[rendered++];
|
|
125
|
+
const markDOM = this.serializeMark(add, node.isInline, options);
|
|
129
126
|
if (markDOM) {
|
|
130
127
|
active.push([add, top]);
|
|
131
128
|
top.appendChild(markDOM.dom);
|
|
@@ -133,36 +130,34 @@ var DOMSerializer = /** @class */ (function () {
|
|
|
133
130
|
}
|
|
134
131
|
}
|
|
135
132
|
}
|
|
136
|
-
top.appendChild(
|
|
133
|
+
top.appendChild(this.serializeNodeInner(node, options));
|
|
137
134
|
});
|
|
138
135
|
return target;
|
|
139
|
-
}
|
|
136
|
+
}
|
|
140
137
|
/// Serialize this node to a DOM node. This can be useful when you
|
|
141
138
|
/// need to serialize a part of a document, as opposed to the whole
|
|
142
139
|
/// document. To serialize a whole document, use
|
|
143
140
|
/// [`serializeFragment`](#model.DOMSerializer.serializeFragment) on
|
|
144
141
|
/// its [content](#model.Node.content).
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
var wrap = this.serializeMark(node.marks[i], node.isInline, options);
|
|
142
|
+
serializeNode(node, options = {}) {
|
|
143
|
+
let dom = this.serializeNodeInner(node, options);
|
|
144
|
+
for (let i = node.marks.length - 1; i >= 0; i--) {
|
|
145
|
+
const wrap = this.serializeMark(node.marks[i], node.isInline, options);
|
|
150
146
|
if (wrap) {
|
|
151
147
|
(wrap.contentDOM || wrap.dom).appendChild(dom);
|
|
152
148
|
dom = wrap.dom;
|
|
153
149
|
}
|
|
154
150
|
}
|
|
155
151
|
return dom;
|
|
156
|
-
}
|
|
152
|
+
}
|
|
157
153
|
/// @internal
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
var toDOM = this.marks[mark.type.name];
|
|
154
|
+
serializeMark(mark, inline, options = {}) {
|
|
155
|
+
const toDOM = this.marks[mark.type.name];
|
|
161
156
|
return toDOM && DOMSerializer.renderSpec(doc(options), toDOM(mark, inline));
|
|
162
|
-
}
|
|
157
|
+
}
|
|
163
158
|
/// @internal
|
|
164
|
-
|
|
165
|
-
|
|
159
|
+
serializeNodeInner(node, options) {
|
|
160
|
+
const { dom, contentDOM } = DOMSerializer.renderSpec(doc(options), this.nodes[node.type.name](node));
|
|
166
161
|
if (contentDOM) {
|
|
167
162
|
if (node.isLeaf) {
|
|
168
163
|
throw new RangeError('Content hole not allowed in a leaf node spec');
|
|
@@ -170,17 +165,15 @@ var DOMSerializer = /** @class */ (function () {
|
|
|
170
165
|
this.serializeFragment(node.content, options, contentDOM);
|
|
171
166
|
}
|
|
172
167
|
return dom;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
}());
|
|
176
|
-
exports.DOMSerializer = DOMSerializer;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
177
170
|
function gatherToDOM(obj) {
|
|
178
|
-
|
|
179
|
-
for (
|
|
180
|
-
if (obj[
|
|
181
|
-
|
|
171
|
+
const result = {};
|
|
172
|
+
for (const name in obj) {
|
|
173
|
+
if (obj[name]) {
|
|
174
|
+
const toDOM = obj[name].spec.toDOM;
|
|
182
175
|
if (toDOM) {
|
|
183
|
-
result[
|
|
176
|
+
result[name] = toDOM;
|
|
184
177
|
}
|
|
185
178
|
}
|
|
186
179
|
}
|
|
@@ -189,3 +182,5 @@ function gatherToDOM(obj) {
|
|
|
189
182
|
function doc(options) {
|
|
190
183
|
return options.document || window.document;
|
|
191
184
|
}
|
|
185
|
+
|
|
186
|
+
exports.DOMSerializer = DOMSerializer;
|
package/dist/npm/align.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { EditorState } from 'prosemirror-state';
|
|
2
|
-
import { AlignRule } from './config/align-rules';
|
|
3
|
-
import { Command } from './types/command';
|
|
2
|
+
import { AlignRule } from './config/align-rules.js';
|
|
3
|
+
import { Command } from './types/command.js';
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Aligning block elements in the selection.
|
|
6
7
|
*
|
|
7
8
|
* @returns {boolean} - Returns true if any alignment is applied.
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
declare const alignBlocks: (actions: Array<AlignRule>, commandName?: string) => Command;
|
|
11
|
+
declare const isAligned: (state: EditorState, actions: Array<AlignRule>) => boolean;
|
|
12
|
+
|
|
13
|
+
export { alignBlocks, isAligned };
|
package/dist/npm/align.js
CHANGED
|
@@ -1,45 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var blockNode = require('./blockNode.js');
|
|
4
|
+
|
|
5
5
|
/**
|
|
6
6
|
* Aligning block elements in the selection.
|
|
7
7
|
*
|
|
8
8
|
* @returns {boolean} - Returns true if any alignment is applied.
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const alignBlocks = (actions, commandName) => (state, dispatch) => {
|
|
11
|
+
const blocks = blockNode.blockNodes(state);
|
|
12
|
+
const tr = state.tr;
|
|
13
13
|
tr.setMeta('commandName', commandName);
|
|
14
|
-
blocks.forEach(
|
|
14
|
+
blocks.forEach(node => {
|
|
15
15
|
if (node.type.isTextblock) {
|
|
16
|
-
|
|
16
|
+
const action = actions.find(n => n.node === node.type.name);
|
|
17
17
|
if (action) {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const newAttrs = blockNode.addStyles(node, action.style);
|
|
19
|
+
blockNode.changeTextBlock(tr, node, node.type, newAttrs);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
|
-
|
|
23
|
+
const result = tr.docChanged;
|
|
24
24
|
if (result) {
|
|
25
25
|
dispatch(tr.scrollIntoView());
|
|
26
26
|
}
|
|
27
27
|
return result;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
blocks.forEach(function (node) {
|
|
28
|
+
};
|
|
29
|
+
const isAligned = (state, actions) => {
|
|
30
|
+
const blocks = blockNode.blockNodes(state);
|
|
31
|
+
let result = false;
|
|
32
|
+
blocks.forEach(node => {
|
|
34
33
|
if (!result && node.type.isTextblock && node.attrs.style) {
|
|
35
|
-
|
|
34
|
+
const action = actions.find(a => a.node === node.type.name);
|
|
36
35
|
if (action) {
|
|
37
|
-
result = action.style.every(
|
|
38
|
-
return !!style.value && new RegExp(
|
|
36
|
+
result = action.style.every(style => {
|
|
37
|
+
return !!style.value && new RegExp(`${style.name}:\\s?${style.value}`, 'i').test(node.attrs.style);
|
|
39
38
|
});
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
});
|
|
43
42
|
return result;
|
|
44
43
|
};
|
|
44
|
+
|
|
45
|
+
exports.alignBlocks = alignBlocks;
|
|
45
46
|
exports.isAligned = isAligned;
|
package/dist/npm/blockNode.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { CleanFormattingOptions } from './cleanFormatting';
|
|
1
|
+
import { Node, NodeType } from 'prosemirror-model';
|
|
2
|
+
import { Transaction, EditorState, Selection } from 'prosemirror-state';
|
|
3
|
+
import { CleanFormattingOptions } from './cleanFormatting.js';
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Changes the type or the attributes of the passed node.
|
|
6
7
|
*
|
|
7
8
|
* @example
|
|
8
9
|
* See `cleanTextBlockFormatting` or `formatBlockElements` function.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
declare const changeTextBlock: (tr: Transaction, node: Node, nodeType: NodeType, attrs?: {
|
|
11
12
|
[key: string]: any;
|
|
12
13
|
}) => boolean;
|
|
13
14
|
/**
|
|
@@ -16,13 +17,13 @@ export declare const changeTextBlock: (tr: Transaction, node: Node, nodeType: No
|
|
|
16
17
|
* @example
|
|
17
18
|
* See `cleanTextBlockFormatting` function.
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
+
declare const blockNodes: (state: EditorState | {
|
|
20
21
|
doc: Node;
|
|
21
22
|
selection: Selection;
|
|
22
23
|
}, options?: {
|
|
23
24
|
blocksInSelection: boolean;
|
|
24
25
|
}) => Array<Node>;
|
|
25
|
-
|
|
26
|
+
declare const formatBlockElements: (value: "p" | "blockquote" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6", commandName?: string) => (state: any, dispatch: any) => any;
|
|
26
27
|
/**
|
|
27
28
|
* Removes the style and class attributes of text block elements.
|
|
28
29
|
* Requires to dispatch the transaction.
|
|
@@ -30,17 +31,15 @@ export declare const formatBlockElements: (value: 'p' | 'blockquote' | 'h1' | 'h
|
|
|
30
31
|
* @example
|
|
31
32
|
* See `cleanFormatting` function.
|
|
32
33
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
value: string;
|
|
38
|
-
}>) => {};
|
|
39
|
-
export declare const hasNode: (state: EditorState, nodeType: NodeType) => boolean;
|
|
40
|
-
export declare const parentBlockFormat: (state: EditorState) => string | null;
|
|
34
|
+
declare const cleanTextBlockFormatting: (tr: Transaction, options?: CleanFormattingOptions) => void;
|
|
35
|
+
declare const getBlockFormats: (state: EditorState) => Array<string>;
|
|
36
|
+
declare const hasNode: (state: EditorState, nodeType: NodeType) => boolean;
|
|
37
|
+
declare const parentBlockFormat: (state: EditorState) => string | null;
|
|
41
38
|
/**
|
|
42
39
|
* **Deprecated.** Use `parentBlockFormat` function instead.
|
|
43
40
|
*/
|
|
44
|
-
|
|
41
|
+
declare const activeNode: (state: EditorState) => {
|
|
45
42
|
tag: string;
|
|
46
43
|
};
|
|
44
|
+
|
|
45
|
+
export { activeNode, blockNodes, changeTextBlock, cleanTextBlockFormatting, formatBlockElements, getBlockFormats, hasNode, parentBlockFormat };
|