@progress/kendo-editor-common 1.12.2-develop.5 → 1.12.2-develop.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn/js/kendo-editor-common.js +1 -1
- package/dist/cdn/main.js +1 -1
- package/dist/es/DOMSerializer.js +6 -7
- package/dist/es/align.js +3 -6
- package/dist/es/blockNode.js +11 -14
- package/dist/es/blockquote.js +2 -5
- package/dist/es/cleanFormatting.js +3 -6
- package/dist/es/config/align-rules.js +5 -7
- package/dist/es/config/commands.js +13 -9
- package/dist/es/config/constants.js +7 -9
- package/dist/es/config/indent-rules.js +3 -6
- package/dist/es/config/keymap.js +7 -10
- package/dist/es/config/list-settings.js +3 -5
- package/dist/es/config/schema.js +4 -6
- package/dist/es/find-replace.js +8 -10
- package/dist/es/flatten-spans.js +2 -5
- package/dist/es/image.js +2 -5
- package/dist/es/indent.js +11 -14
- package/dist/es/inline-style.js +10 -12
- package/dist/es/link.js +5 -8
- package/dist/es/listConvert.js +8 -9
- package/dist/es/lists.js +12 -15
- package/dist/es/main.js +34 -33
- package/dist/es/mark.js +16 -17
- package/dist/es/paste.js +10 -13
- package/dist/es/plugins/caret-color.js +5 -8
- package/dist/es/plugins/csp-fix.js +2 -5
- package/dist/es/plugins/highlight.js +3 -6
- package/dist/es/plugins/image-resize.js +8 -11
- package/dist/es/plugins/list-markers-styles.js +2 -5
- package/dist/es/plugins/placeholder.js +2 -5
- package/dist/es/plugins/resize-utils.js +2 -4
- package/dist/es/plugins/spaces-fix.js +1 -4
- package/dist/es/plugins/table-resize/column-resize.js +21 -24
- package/dist/es/plugins/table-resize/index.js +6 -9
- package/dist/es/plugins/table-resize/row-resize.js +23 -24
- package/dist/es/plugins/table-resize/table-resize.js +17 -20
- package/dist/es/plugins/table-resize/table-view.js +6 -9
- package/dist/es/plugins/table-resize/utils.js +10 -13
- package/dist/es/source.js +15 -18
- package/dist/es/table.js +15 -18
- package/dist/es/text.js +1 -3
- package/dist/es/types/active-marks.js +1 -0
- package/dist/es/types/command.js +1 -0
- package/dist/es/types/dispatchFn.js +1 -0
- package/dist/es/types/paste-cleanup-settings.js +1 -0
- package/dist/es/types/predicate.js +1 -0
- package/dist/es/utils.js +18 -21
- package/dist/npm/DOMSerializer.d.ts +35 -0
- package/dist/npm/DOMSerializer.js +10 -9
- package/dist/npm/align.d.ts +4 -7
- package/dist/npm/align.js +9 -10
- package/dist/npm/blockNode.d.ts +15 -12
- package/dist/npm/blockNode.js +28 -29
- package/dist/npm/blockquote.d.ts +2 -5
- package/dist/npm/blockquote.js +6 -7
- package/dist/npm/cleanFormatting.d.ts +3 -6
- package/dist/npm/cleanFormatting.js +7 -8
- package/dist/npm/config/align-rules.d.ts +6 -8
- package/dist/npm/config/align-rules.js +8 -13
- package/dist/npm/config/commands.d.ts +19 -11
- package/dist/npm/config/commands.js +16 -17
- package/dist/npm/config/constants.d.ts +7 -0
- package/dist/npm/config/constants.js +10 -17
- package/dist/npm/config/indent-rules.d.ts +4 -6
- package/dist/npm/config/indent-rules.js +8 -11
- package/dist/npm/config/keymap.d.ts +2 -5
- package/dist/npm/config/keymap.js +21 -22
- package/dist/npm/config/list-settings.d.ts +30 -0
- package/dist/npm/config/list-settings.js +10 -13
- package/dist/npm/config/schema.d.ts +2 -3
- package/dist/npm/config/schema.js +19 -20
- package/dist/npm/find-replace.d.ts +7 -10
- package/dist/npm/find-replace.js +20 -20
- package/dist/npm/flatten-spans.d.ts +1 -3
- package/dist/npm/flatten-spans.js +6 -7
- package/dist/npm/image.d.ts +3 -6
- package/dist/npm/image.js +5 -6
- package/dist/npm/indent.d.ts +9 -12
- package/dist/npm/indent.js +37 -38
- package/dist/npm/inline-style.d.ts +4 -7
- package/dist/npm/inline-style.js +28 -28
- package/dist/npm/link.d.ts +2 -4
- package/dist/npm/link.js +21 -22
- package/dist/npm/listConvert.d.ts +1 -3
- package/dist/npm/listConvert.js +13 -12
- package/dist/npm/lists.d.ts +8 -8
- package/dist/npm/lists.js +26 -27
- package/dist/npm/main.d.ts +34 -35
- package/dist/npm/main.js +214 -391
- package/dist/npm/mark.d.ts +17 -12
- package/dist/npm/mark.js +30 -29
- package/dist/npm/paste.d.ts +8 -11
- package/dist/npm/paste.js +19 -20
- package/dist/npm/plugins/caret-color.d.ts +2 -5
- package/dist/npm/plugins/caret-color.js +15 -17
- package/dist/npm/plugins/csp-fix.d.ts +1 -4
- package/dist/npm/plugins/csp-fix.js +8 -9
- package/dist/npm/plugins/highlight.d.ts +4 -7
- package/dist/npm/plugins/highlight.js +11 -13
- package/dist/npm/plugins/image-resize.d.ts +5 -7
- package/dist/npm/plugins/image-resize.js +35 -37
- package/dist/npm/plugins/list-markers-styles.d.ts +2 -5
- package/dist/npm/plugins/list-markers-styles.js +14 -16
- package/dist/npm/plugins/placeholder.d.ts +1 -4
- package/dist/npm/plugins/placeholder.js +10 -12
- package/dist/npm/plugins/resize-utils.d.ts +35 -0
- package/dist/npm/plugins/resize-utils.js +5 -7
- package/dist/npm/plugins/spaces-fix.d.ts +1 -4
- package/dist/npm/plugins/spaces-fix.js +9 -10
- package/dist/npm/plugins/table-resize/column-resize.d.ts +2 -0
- package/dist/npm/plugins/table-resize/column-resize.js +44 -46
- package/dist/npm/plugins/table-resize/index.d.ts +2 -5
- package/dist/npm/plugins/table-resize/index.js +13 -14
- package/dist/npm/plugins/table-resize/row-resize.d.ts +2 -0
- package/dist/npm/plugins/table-resize/row-resize.js +40 -40
- package/dist/npm/plugins/table-resize/table-resize.d.ts +18 -0
- package/dist/npm/plugins/table-resize/table-resize.js +51 -52
- package/dist/npm/plugins/table-resize/table-view.d.ts +28 -0
- package/dist/npm/plugins/table-resize/table-view.js +23 -24
- package/dist/npm/plugins/table-resize/utils.d.ts +17 -7
- package/dist/npm/plugins/table-resize/utils.js +24 -28
- package/dist/npm/source.d.ts +13 -16
- package/dist/npm/source.js +35 -36
- package/dist/npm/table.d.ts +9 -10
- package/dist/npm/table.js +33 -49
- package/dist/npm/text.d.ts +3 -6
- package/dist/npm/text.js +3 -3
- package/dist/npm/types/active-marks.d.ts +1 -4
- package/dist/npm/types/active-marks.js +2 -0
- package/dist/npm/types/command.d.ts +2 -5
- package/dist/npm/types/command.js +2 -0
- package/dist/npm/types/dispatchFn.d.ts +1 -4
- package/dist/npm/types/dispatchFn.js +2 -0
- package/dist/npm/types/paste-cleanup-settings.d.ts +1 -3
- package/dist/npm/types/paste-cleanup-settings.js +2 -0
- package/dist/npm/types/predicate.d.ts +1 -0
- package/dist/npm/types/predicate.js +2 -0
- package/dist/npm/utils.d.ts +33 -14
- package/dist/npm/utils.js +38 -39
- package/package.json +4 -51
- package/dist/es2015/DOMSerializer.js +0 -184
- package/dist/es2015/align.js +0 -43
- package/dist/es2015/blockNode.js +0 -180
- package/dist/es2015/blockquote.js +0 -26
- package/dist/es2015/cleanFormatting.js +0 -20
- package/dist/es2015/config/align-rules.js +0 -30
- package/dist/es2015/config/commands.js +0 -50
- package/dist/es2015/config/constants.js +0 -9
- package/dist/es2015/config/indent-rules.js +0 -42
- package/dist/es2015/config/keymap.js +0 -51
- package/dist/es2015/config/list-settings.js +0 -21
- package/dist/es2015/config/schema.js +0 -314
- package/dist/es2015/find-replace.js +0 -122
- package/dist/es2015/flatten-spans.js +0 -112
- package/dist/es2015/image.js +0 -10
- package/dist/es2015/indent.js +0 -105
- package/dist/es2015/inline-style.js +0 -177
- package/dist/es2015/link.js +0 -105
- package/dist/es2015/listConvert.js +0 -184
- package/dist/es2015/lists.js +0 -266
- package/dist/es2015/main.js +0 -44
- package/dist/es2015/mark.js +0 -239
- package/dist/es2015/node_modules/tslib/tslib.es6.js +0 -35
- package/dist/es2015/paste.js +0 -162
- package/dist/es2015/plugins/caret-color.js +0 -34
- package/dist/es2015/plugins/csp-fix.js +0 -51
- package/dist/es2015/plugins/highlight.js +0 -23
- package/dist/es2015/plugins/image-resize.js +0 -225
- package/dist/es2015/plugins/list-markers-styles.js +0 -104
- package/dist/es2015/plugins/placeholder.js +0 -27
- package/dist/es2015/plugins/resize-utils.js +0 -13
- package/dist/es2015/plugins/spaces-fix.js +0 -46
- package/dist/es2015/plugins/table-resize/column-resize.js +0 -267
- package/dist/es2015/plugins/table-resize/index.js +0 -12
- package/dist/es2015/plugins/table-resize/row-resize.js +0 -234
- package/dist/es2015/plugins/table-resize/table-resize.js +0 -278
- package/dist/es2015/plugins/table-resize/table-view.js +0 -128
- package/dist/es2015/plugins/table-resize/utils.js +0 -93
- package/dist/es2015/source.js +0 -251
- package/dist/es2015/table.js +0 -132
- package/dist/es2015/text.js +0 -5
- package/dist/es2015/utils.js +0 -289
package/dist/es2015/source.js
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import { DOMParser, Fragment } from 'prosemirror-model';
|
|
2
|
-
import { AllSelection } from 'prosemirror-state';
|
|
3
|
-
import { rowTypeAttr, colgroupAttr } from './config/constants.js';
|
|
4
|
-
import { DOMSerializer } from './DOMSerializer.js';
|
|
5
|
-
import { setStyleAttr } from './utils.js';
|
|
6
|
-
|
|
7
|
-
const blockWrappers = [
|
|
8
|
-
'div', 'ol', 'ul', 'li', 'table', 'tbody', 'thead', 'tfoot', 'caption', 'td', 'th', 'p',
|
|
9
|
-
'tr', 'col', 'colgroup', 'article', 'main', 'nav', 'header', 'footer', 'aside', 'section'
|
|
10
|
-
];
|
|
11
|
-
const removeRowType = (table, nodeName) => {
|
|
12
|
-
const wrapper = (table.ownerDocument || document).createElement(nodeName);
|
|
13
|
-
Array.from(table.rows).filter(r => r.getAttribute(rowTypeAttr) === nodeName).forEach(row => {
|
|
14
|
-
row.removeAttribute(rowTypeAttr);
|
|
15
|
-
wrapper.appendChild(row);
|
|
16
|
-
});
|
|
17
|
-
if (wrapper.children.length) {
|
|
18
|
-
table.appendChild(wrapper);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const restoreTables = (fragment) => {
|
|
22
|
-
Array.from(fragment.querySelectorAll('table')).forEach((table) => {
|
|
23
|
-
removeRowType(table, 'thead');
|
|
24
|
-
removeRowType(table, 'tbody');
|
|
25
|
-
removeRowType(table, 'tfoot');
|
|
26
|
-
const emptyElement = Array.from(table.children).find(el => el.children.length === 0);
|
|
27
|
-
if (emptyElement) {
|
|
28
|
-
emptyElement.remove();
|
|
29
|
-
}
|
|
30
|
-
const wrapper = table.parentNode instanceof HTMLDivElement ? table.parentNode : null;
|
|
31
|
-
if (wrapper && wrapper.matches('div[table]')) {
|
|
32
|
-
table.style.marginLeft = wrapper.style.marginLeft;
|
|
33
|
-
table.style.marginRight = wrapper.style.marginRight;
|
|
34
|
-
const captionDiv = Array.from(wrapper.children).find(el => el.matches('div[caption]'));
|
|
35
|
-
if (captionDiv && captionDiv.innerHTML !== '<img>') {
|
|
36
|
-
const caption = table.createCaption();
|
|
37
|
-
if (captionDiv.id) {
|
|
38
|
-
caption.id = captionDiv.id;
|
|
39
|
-
}
|
|
40
|
-
if (captionDiv.className) {
|
|
41
|
-
caption.className = captionDiv.className;
|
|
42
|
-
}
|
|
43
|
-
Array.from(captionDiv.style).forEach((styleName) => {
|
|
44
|
-
caption.style[styleName] = captionDiv.style[styleName];
|
|
45
|
-
});
|
|
46
|
-
while (captionDiv.firstChild) {
|
|
47
|
-
caption.appendChild(captionDiv.firstChild);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (wrapper.style.width && !table.style.width) {
|
|
51
|
-
table.style.width = wrapper.style.width;
|
|
52
|
-
}
|
|
53
|
-
wrapper.parentNode.insertBefore(table, wrapper);
|
|
54
|
-
wrapper.parentNode.removeChild(wrapper);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
const setRowType = (children, nodeName) => {
|
|
59
|
-
const tag = nodeName.toUpperCase();
|
|
60
|
-
children.filter(c => c.nodeName === tag).forEach(rowsWrapper => {
|
|
61
|
-
Array.from(rowsWrapper.children).forEach(row => {
|
|
62
|
-
row.setAttribute(rowTypeAttr, nodeName);
|
|
63
|
-
if (rowsWrapper.parentNode) {
|
|
64
|
-
rowsWrapper.parentNode.insertBefore(row, rowsWrapper);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
rowsWrapper.remove();
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
const validateTablesToPmSchema = (fragment) => {
|
|
71
|
-
Array.from(fragment.querySelectorAll('table')).forEach((table) => {
|
|
72
|
-
const children = Array.from(table.children);
|
|
73
|
-
if (children.some(e => e.nodeName === 'THEAD' || e.nodeName === 'TFOOT')) {
|
|
74
|
-
setRowType(children, 'thead');
|
|
75
|
-
setRowType(children, 'tbody');
|
|
76
|
-
setRowType(children, 'tfoot');
|
|
77
|
-
}
|
|
78
|
-
const colgroup = children.find(c => c.nodeName === 'COLGROUP');
|
|
79
|
-
if (colgroup) {
|
|
80
|
-
table.setAttribute(colgroupAttr, colgroup.outerHTML);
|
|
81
|
-
colgroup.remove();
|
|
82
|
-
}
|
|
83
|
-
if (table.caption || table.style.marginLeft || table.style.marginRight) {
|
|
84
|
-
const wrapper = document.createElement('div');
|
|
85
|
-
wrapper.setAttribute('table', '');
|
|
86
|
-
wrapper.style.display = 'table';
|
|
87
|
-
wrapper.style.marginLeft = table.style.marginLeft;
|
|
88
|
-
wrapper.style.marginRight = table.style.marginRight;
|
|
89
|
-
if (table.caption) {
|
|
90
|
-
const captionDiv = document.createElement('div');
|
|
91
|
-
captionDiv.setAttribute('caption', '');
|
|
92
|
-
if (table.caption.id) {
|
|
93
|
-
captionDiv.id = table.caption.id;
|
|
94
|
-
}
|
|
95
|
-
if (table.caption.className) {
|
|
96
|
-
captionDiv.className = table.caption.className;
|
|
97
|
-
}
|
|
98
|
-
Array.from(table.caption.style).forEach((styleName) => {
|
|
99
|
-
captionDiv.style[styleName] = table.caption.style[styleName];
|
|
100
|
-
});
|
|
101
|
-
while (table.caption.firstChild) {
|
|
102
|
-
captionDiv.appendChild(table.caption.firstChild);
|
|
103
|
-
}
|
|
104
|
-
table.removeChild(table.caption);
|
|
105
|
-
wrapper.appendChild(captionDiv);
|
|
106
|
-
}
|
|
107
|
-
table.parentNode.insertBefore(wrapper, table);
|
|
108
|
-
wrapper.appendChild(table);
|
|
109
|
-
if (/%/.test(table.style.width)) {
|
|
110
|
-
wrapper.style.width = table.style.width;
|
|
111
|
-
table.style.width = '';
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
* Trims the whitespace around the provided block nodes.
|
|
118
|
-
*
|
|
119
|
-
* @param html - Input HTML content
|
|
120
|
-
* @param trimAroundTags - Block elements to which trimming will be applied.
|
|
121
|
-
* Defaults to block nodes of the current default schema:
|
|
122
|
-
* 'div', 'ol', 'ul', 'li', 'table', 'tbody', 'thead', 'tfoot', 'td', 'th', 'p'
|
|
123
|
-
* and additional table and semantic nodes from the default Angular Editor schema:
|
|
124
|
-
* 'tr', 'col', 'colgroup', 'article', 'main', 'nav', 'header', 'footer', 'aside', 'section'
|
|
125
|
-
*
|
|
126
|
-
* @returns The trimmed HTML content
|
|
127
|
-
*/
|
|
128
|
-
const trimWhitespace = (html, trimAroundTags = blockWrappers) => {
|
|
129
|
-
const tags = trimAroundTags.join('|');
|
|
130
|
-
return html.replace(new RegExp('\\s*(<(?:' + tags + ')(?:\\s[^>]*?)?>)', 'g'), '$1')
|
|
131
|
-
.replace(new RegExp('(<\\/(?:' + tags + ')(?:\\s[^>]*?)?>)\\s*', 'g'), '$1');
|
|
132
|
-
};
|
|
133
|
-
const styleAttr = 'data-style';
|
|
134
|
-
const styleReplace = ' ' + styleAttr + '=';
|
|
135
|
-
const reTag = /<[^>]+>/gm;
|
|
136
|
-
const reStyle = /\sstyle=/gm;
|
|
137
|
-
const replacer = (match) => {
|
|
138
|
-
return match.replace(reStyle, styleReplace);
|
|
139
|
-
};
|
|
140
|
-
const replaceStyleAttr = (html) => {
|
|
141
|
-
return html.replace(reTag, replacer);
|
|
142
|
-
};
|
|
143
|
-
const restoreStyleAttr = (container) => {
|
|
144
|
-
Array.from(container.querySelectorAll('[' + styleAttr + ']')).forEach((element) => {
|
|
145
|
-
const styleString = element.getAttribute(styleAttr);
|
|
146
|
-
element.removeAttribute(styleAttr);
|
|
147
|
-
setStyleAttr(element, styleString);
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
/**
|
|
151
|
-
* Creates a DocumentFragment from the given HTML content.
|
|
152
|
-
*
|
|
153
|
-
* @param html
|
|
154
|
-
* @returns DocumentFragment
|
|
155
|
-
*/
|
|
156
|
-
const htmlToFragment = (html) => {
|
|
157
|
-
const template = document.createElement('template');
|
|
158
|
-
template.innerHTML = replaceStyleAttr(html);
|
|
159
|
-
restoreStyleAttr(template.content);
|
|
160
|
-
return template.content.cloneNode(true);
|
|
161
|
-
};
|
|
162
|
-
/**
|
|
163
|
-
* @hidden
|
|
164
|
-
*/
|
|
165
|
-
const fragmentToHtml = (fragment) => {
|
|
166
|
-
return Array.from(fragment.childNodes).reduce((acc, cur) => acc + (cur.outerHTML || cur.textContent || ''), '');
|
|
167
|
-
};
|
|
168
|
-
/**
|
|
169
|
-
* Creates a DocumentFragment from the given ProseMirrorNode.
|
|
170
|
-
*
|
|
171
|
-
* @param doc ProseMirrorNode
|
|
172
|
-
* @returns DocumentFragment
|
|
173
|
-
*/
|
|
174
|
-
const pmDocToFragment = (doc) => {
|
|
175
|
-
const fragment = DOMSerializer.fromSchema(doc.type.schema).serializeFragment(doc.content);
|
|
176
|
-
restoreTables(fragment);
|
|
177
|
-
return fragment;
|
|
178
|
-
};
|
|
179
|
-
/**
|
|
180
|
-
* Creates a ProseMirrorNode from the given DOM element.
|
|
181
|
-
*
|
|
182
|
-
* @param dom
|
|
183
|
-
* @param schema
|
|
184
|
-
* @param parseOptions
|
|
185
|
-
* @returns ProseMirrorNode
|
|
186
|
-
*/
|
|
187
|
-
const domToPmDoc = (dom, schema, parseOptions) => {
|
|
188
|
-
return DOMParser.fromSchema(schema).parse(dom, parseOptions);
|
|
189
|
-
};
|
|
190
|
-
/**
|
|
191
|
-
* Creates a ProseMirrorNode from the given HTML content.
|
|
192
|
-
*
|
|
193
|
-
* @param content - The new HTML content.
|
|
194
|
-
* @param schema - The document schema.
|
|
195
|
-
* @param parseOptions - ProseMirror parse options recognized by the `parse` and `parseSlice` methods.
|
|
196
|
-
* @returns - New ProseMirrorNode instance.
|
|
197
|
-
*/
|
|
198
|
-
const parseContent = (content, schema, parseOptions) => {
|
|
199
|
-
const dom = htmlToFragment(content);
|
|
200
|
-
validateTablesToPmSchema(dom);
|
|
201
|
-
return domToPmDoc(dom, schema, parseOptions);
|
|
202
|
-
};
|
|
203
|
-
/**
|
|
204
|
-
* A function that serializes the Editor State content as HTML string.
|
|
205
|
-
*
|
|
206
|
-
* @param state - The Editor State
|
|
207
|
-
* @returns - The serialized content
|
|
208
|
-
*/
|
|
209
|
-
const getHtml = (state) => {
|
|
210
|
-
const fragment = pmDocToFragment(state.doc);
|
|
211
|
-
return fragmentToHtml(fragment);
|
|
212
|
-
};
|
|
213
|
-
/**
|
|
214
|
-
* Replaces the content of the editor with a new one.
|
|
215
|
-
*
|
|
216
|
-
* @param content - The new HTML content.
|
|
217
|
-
* @param commandName - The name of the command.
|
|
218
|
-
* @param parseOptions - ProseMirror parse options recognized by the `parse` and `parseSlice` methods.
|
|
219
|
-
* @returns - Command function that takes an editor `state` and `dispatch` function.
|
|
220
|
-
*/
|
|
221
|
-
const setHtml = (content, command = 'setHTML', parseOptions = { preserveWhitespace: 'full' }) => (state, dispatch) => dispatch(state.tr
|
|
222
|
-
.setSelection(new AllSelection(state.doc))
|
|
223
|
-
.replaceSelectionWith(parseContent(content, state.schema, parseOptions))
|
|
224
|
-
.setMeta('commandName', command));
|
|
225
|
-
/**
|
|
226
|
-
* @hidden
|
|
227
|
-
*/
|
|
228
|
-
const hasSameMarkup = (dom1, dom2, schema, parseOptions) => {
|
|
229
|
-
const fragment1 = Fragment.from(parseContent(dom1, schema, parseOptions));
|
|
230
|
-
const fragment2 = Fragment.from(parseContent(dom2, schema, parseOptions));
|
|
231
|
-
return fragment1.eq(fragment2);
|
|
232
|
-
};
|
|
233
|
-
/**
|
|
234
|
-
* Removes comments in HTML.
|
|
235
|
-
*/
|
|
236
|
-
const removeComments = (html) => {
|
|
237
|
-
const fragment = htmlToFragment(html);
|
|
238
|
-
removeCommentsFromDom(fragment);
|
|
239
|
-
return fragmentToHtml(fragment);
|
|
240
|
-
};
|
|
241
|
-
const removeCommentsFromDom = (dom) => {
|
|
242
|
-
var _a;
|
|
243
|
-
const iterator = dom.ownerDocument.createNodeIterator(dom, NodeFilter.SHOW_COMMENT);
|
|
244
|
-
let commentNode = iterator.nextNode();
|
|
245
|
-
while (commentNode) {
|
|
246
|
-
(_a = commentNode.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(commentNode);
|
|
247
|
-
commentNode = iterator.nextNode();
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
export { domToPmDoc, fragmentToHtml, getHtml, hasSameMarkup, htmlToFragment, parseContent, pmDocToFragment, removeComments, setHtml, trimWhitespace };
|
package/dist/es2015/table.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { addRowAfter as addRowAfter$1, addRowBefore as addRowBefore$1, addColumnBefore as addColumnBefore$1, addColumnAfter as addColumnAfter$1, deleteColumn as deleteColumn$1, TableMap } from 'prosemirror-tables';
|
|
2
|
-
export { addColumnAfter as pmAddColumnAfter, addColumnBefore as pmAddColumnBefore, addRowAfter as pmAddRowAfter, addRowBefore as pmAddRowBefore, deleteColumn as pmDeleteColumn } from 'prosemirror-tables';
|
|
3
|
-
import { colgroupAttr, rowTypeAttr } from './config/constants.js';
|
|
4
|
-
import { parseStrColgroup } from './config/schema.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Creates a table.
|
|
8
|
-
*
|
|
9
|
-
* @returns Node
|
|
10
|
-
*/
|
|
11
|
-
const createTable = (nodes, rows, columns) => {
|
|
12
|
-
const { table, table_row, table_cell } = nodes;
|
|
13
|
-
const tableRows = [];
|
|
14
|
-
let cells;
|
|
15
|
-
for (let r = 0; r < rows + 1; r++) {
|
|
16
|
-
cells = [];
|
|
17
|
-
for (let c = 0; c < columns + 1; c++) {
|
|
18
|
-
cells.push(table_cell.createAndFill());
|
|
19
|
-
}
|
|
20
|
-
tableRows.push(table_row.createAndFill(undefined, cells));
|
|
21
|
-
}
|
|
22
|
-
return table.createAndFill(undefined, tableRows);
|
|
23
|
-
};
|
|
24
|
-
const reTable = /^table$/;
|
|
25
|
-
const reRow = /^table_row$/;
|
|
26
|
-
const reCell = /^table_cell|table_header$/;
|
|
27
|
-
const closest = (selection, name) => {
|
|
28
|
-
const pos = selection.$head;
|
|
29
|
-
for (let i = pos.depth; i > 0; i--) {
|
|
30
|
-
const node = pos.node(i);
|
|
31
|
-
if (name.test(node.type.name)) {
|
|
32
|
-
return {
|
|
33
|
-
pos: pos.before(i),
|
|
34
|
-
node
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return null;
|
|
39
|
-
};
|
|
40
|
-
const addRowBefore = (state, dispatch) => {
|
|
41
|
-
const cmdDispatch = dispatch && (tr => {
|
|
42
|
-
const row = closest(tr.selection, reRow);
|
|
43
|
-
const table = closest(tr.selection, reTable);
|
|
44
|
-
if (row && table && row.node.attrs[rowTypeAttr]) {
|
|
45
|
-
let index = 0;
|
|
46
|
-
for (let i = 0; i < table.node.nodeSize; i++) {
|
|
47
|
-
if (table.node.child(i).eq(row.node)) {
|
|
48
|
-
index = i;
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
const next = table.node.child(index - 1);
|
|
53
|
-
const from = row.pos - next.nodeSize;
|
|
54
|
-
tr.setNodeMarkup(from, undefined, { [rowTypeAttr]: row.node.attrs[rowTypeAttr] });
|
|
55
|
-
}
|
|
56
|
-
return dispatch(tr);
|
|
57
|
-
});
|
|
58
|
-
return addRowBefore$1(state, cmdDispatch);
|
|
59
|
-
};
|
|
60
|
-
const addRowAfter = (state, dispatch) => {
|
|
61
|
-
const cmdDispatch = dispatch && (tr => {
|
|
62
|
-
const row = closest(tr.selection, reRow);
|
|
63
|
-
if (row && row.node.attrs[rowTypeAttr]) {
|
|
64
|
-
const from = row.pos + row.node.nodeSize;
|
|
65
|
-
tr.setNodeMarkup(from, undefined, { [rowTypeAttr]: row.node.attrs[rowTypeAttr] });
|
|
66
|
-
}
|
|
67
|
-
return dispatch(tr);
|
|
68
|
-
});
|
|
69
|
-
return addRowAfter$1(state, cmdDispatch);
|
|
70
|
-
};
|
|
71
|
-
const columnIndex = (table, selection) => {
|
|
72
|
-
if (!table) {
|
|
73
|
-
return -1;
|
|
74
|
-
}
|
|
75
|
-
const map = TableMap.get(table.node);
|
|
76
|
-
const tableCell = closest(selection, reCell);
|
|
77
|
-
const idx = map.map.indexOf(tableCell.pos - table.pos - 1);
|
|
78
|
-
let colIndex = -1;
|
|
79
|
-
if (idx !== -1) {
|
|
80
|
-
colIndex = idx % map.width;
|
|
81
|
-
}
|
|
82
|
-
return colIndex;
|
|
83
|
-
};
|
|
84
|
-
const addCol = (tr, table, to) => {
|
|
85
|
-
const colIndex = columnIndex(table, tr.selection);
|
|
86
|
-
const colgroup = parseStrColgroup(table.node.attrs[colgroupAttr]);
|
|
87
|
-
colgroup.insertBefore(colgroup.ownerDocument.createElement('col'), colgroup.children[colIndex + to]);
|
|
88
|
-
tr.setNodeMarkup(table.pos, null, Object.assign(Object.assign({}, table.node.attrs), { [colgroupAttr]: colgroup.outerHTML }));
|
|
89
|
-
};
|
|
90
|
-
const deleteCol = (tr, table, colIndex) => {
|
|
91
|
-
const colgroup = parseStrColgroup(table.node.attrs[colgroupAttr]);
|
|
92
|
-
colgroup.removeChild(colgroup.children[colIndex]);
|
|
93
|
-
tr.setNodeMarkup(table.pos, null, Object.assign(Object.assign({}, table.node.attrs), { [colgroupAttr]: colgroup.outerHTML }));
|
|
94
|
-
};
|
|
95
|
-
const addColumnBefore = (state, dispatch) => {
|
|
96
|
-
const cmdDispatch = dispatch && (tr => {
|
|
97
|
-
const table = closest(tr.selection, reTable);
|
|
98
|
-
if (!table.node.attrs[colgroupAttr]) {
|
|
99
|
-
return dispatch(tr);
|
|
100
|
-
}
|
|
101
|
-
addCol(tr, table, -1);
|
|
102
|
-
return dispatch(tr);
|
|
103
|
-
});
|
|
104
|
-
return addColumnBefore$1(state, cmdDispatch);
|
|
105
|
-
};
|
|
106
|
-
const addColumnAfter = (state, dispatch) => {
|
|
107
|
-
const cmdDispatch = dispatch && (tr => {
|
|
108
|
-
const table = closest(tr.selection, reTable);
|
|
109
|
-
if (!table.node.attrs[colgroupAttr]) {
|
|
110
|
-
return dispatch(tr);
|
|
111
|
-
}
|
|
112
|
-
addCol(tr, table, 1);
|
|
113
|
-
return dispatch(tr);
|
|
114
|
-
});
|
|
115
|
-
return addColumnAfter$1(state, cmdDispatch);
|
|
116
|
-
};
|
|
117
|
-
const deleteColumn = (state, dispatch) => {
|
|
118
|
-
const parentTable = closest(state.selection, reTable);
|
|
119
|
-
const colgroup = parentTable && parentTable.node.attrs[colgroupAttr];
|
|
120
|
-
const colIndex = columnIndex(parentTable, state.selection);
|
|
121
|
-
const cmdDispatch = dispatch && ((tr) => {
|
|
122
|
-
if (!colgroup) {
|
|
123
|
-
return dispatch(tr);
|
|
124
|
-
}
|
|
125
|
-
const table = tr.doc.nodeAt(parentTable.pos);
|
|
126
|
-
deleteCol(tr, { node: table, pos: parentTable.pos }, colIndex);
|
|
127
|
-
return dispatch(tr);
|
|
128
|
-
});
|
|
129
|
-
return deleteColumn$1(state, cmdDispatch);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
export { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, createTable, deleteColumn };
|
package/dist/es2015/text.js
DELETED
package/dist/es2015/utils.js
DELETED
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { Node } from 'prosemirror-model';
|
|
2
|
-
import { TextSelection, AllSelection, NodeSelection } from 'prosemirror-state';
|
|
3
|
-
import { parseInlineStyles } from '@progress/kendo-common';
|
|
4
|
-
|
|
5
|
-
const changeStylesString = (styleText, newStyle) => {
|
|
6
|
-
const styleToChange = newStyle.style;
|
|
7
|
-
const regExp = newStyle.value;
|
|
8
|
-
const newValue = newStyle.newValue;
|
|
9
|
-
if (!styleText) {
|
|
10
|
-
return { changed: false, style: null };
|
|
11
|
-
}
|
|
12
|
-
const styles = parseStyle(styleText);
|
|
13
|
-
const styleNames = Object.keys(styles);
|
|
14
|
-
const filtered = [];
|
|
15
|
-
for (let i = 0; i < styleNames.length; i++) {
|
|
16
|
-
const name = styleNames[i];
|
|
17
|
-
if (name.toLowerCase() !== styleToChange || !regExp.test(styles[name])) {
|
|
18
|
-
filtered.push(`${name}: ${styles[name]}`);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
if (newValue) {
|
|
22
|
-
filtered.push(`${styleToChange}: ${newValue}`);
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
style: filtered.join('; ') + (filtered.length ? ';' : ''),
|
|
26
|
-
changed: Boolean(newValue) || filtered.length !== styleNames.length
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
const reAnyValue = /^.+$/;
|
|
30
|
-
function setNodeStyle(nodeAttrs, styleType, value) {
|
|
31
|
-
let attrs;
|
|
32
|
-
if (new RegExp('[^-]?' + styleType + ':').test(nodeAttrs.style || '')) {
|
|
33
|
-
const { style } = changeStylesString(nodeAttrs.style || '', { style: styleType, value: reAnyValue, newValue: value });
|
|
34
|
-
attrs = Object.assign(Object.assign({}, nodeAttrs), { style });
|
|
35
|
-
}
|
|
36
|
-
else if (nodeAttrs.style) {
|
|
37
|
-
attrs = Object.assign(Object.assign({}, nodeAttrs), { style: nodeAttrs.style.replace(/;$/, '') + '; ' + styleType + ': ' + value + ';' });
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
attrs = Object.assign(Object.assign({}, nodeAttrs), { style: styleType + ': ' + value + ';' });
|
|
41
|
-
}
|
|
42
|
-
return attrs;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Determines if a given node type can be inserted at the current cursor position.
|
|
46
|
-
*/
|
|
47
|
-
const canInsert = (state, nodeType) => {
|
|
48
|
-
const $from = state.selection.$from;
|
|
49
|
-
for (let d = $from.depth; d >= 0; d--) {
|
|
50
|
-
const index = $from.index(d);
|
|
51
|
-
if ($from.node(d).canReplaceWith(index, index, nodeType)) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return false;
|
|
56
|
-
};
|
|
57
|
-
const getTypeName = (n) => {
|
|
58
|
-
return n instanceof Node ? n.type.name : n.name;
|
|
59
|
-
};
|
|
60
|
-
const findNthParentNode = (predicate, depth = 1) => {
|
|
61
|
-
return (selection) => {
|
|
62
|
-
const { $from } = selection;
|
|
63
|
-
for (let i = $from.depth; i > 0; i--) {
|
|
64
|
-
const node = $from.node(i);
|
|
65
|
-
if (predicate(node)) {
|
|
66
|
-
depth = depth - 1;
|
|
67
|
-
if (depth === 0) {
|
|
68
|
-
return { depth: i, node };
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
const findNthParentNodeOfType = (nodeType, depth = 1) => {
|
|
75
|
-
return (selection) => {
|
|
76
|
-
return findNthParentNode((node) => getTypeName(node) === getTypeName(nodeType), depth)(selection);
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
function parentNode(pos, predicate) {
|
|
80
|
-
for (let depth = pos.depth; depth > 0; depth--) {
|
|
81
|
-
const node = pos.node(depth);
|
|
82
|
-
if (predicate(node)) {
|
|
83
|
-
return { node, depth };
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
const filterEmptyAttrs = (attrs) => {
|
|
89
|
-
const result = {};
|
|
90
|
-
for (const attr in attrs) {
|
|
91
|
-
if (attr && (attrs[attr] || attrs[attr] === 0)) {
|
|
92
|
-
result[attr] = attrs[attr];
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return result;
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Inserts the given node at the place of current selection.
|
|
99
|
-
*/
|
|
100
|
-
const insertNode = (node, scrollIntoView) => (state, dispatch) => {
|
|
101
|
-
const { selection, tr } = state;
|
|
102
|
-
if (selection instanceof NodeSelection
|
|
103
|
-
&& selection.node.type.name === node.type.name
|
|
104
|
-
&& node.isLeaf && !node.isText && node.nodeSize === 1) {
|
|
105
|
-
tr.setNodeMarkup(selection.from, null, Object.assign(Object.assign({}, filterEmptyAttrs(selection.node.attrs)), filterEmptyAttrs(node.attrs)));
|
|
106
|
-
tr.setSelection(NodeSelection.create(tr.doc, selection.from));
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
tr.replaceSelectionWith(node);
|
|
110
|
-
}
|
|
111
|
-
if (scrollIntoView) {
|
|
112
|
-
tr.scrollIntoView();
|
|
113
|
-
}
|
|
114
|
-
dispatch(tr);
|
|
115
|
-
};
|
|
116
|
-
const getSelectionText = (state) => {
|
|
117
|
-
const sel = state.selection;
|
|
118
|
-
if (sel instanceof TextSelection || sel instanceof AllSelection) {
|
|
119
|
-
const fragment = sel.content().content;
|
|
120
|
-
return fragment.textBetween(0, fragment.size);
|
|
121
|
-
}
|
|
122
|
-
return '';
|
|
123
|
-
};
|
|
124
|
-
const getNodeFromSelection = (state) => {
|
|
125
|
-
if (state.selection instanceof NodeSelection) {
|
|
126
|
-
return state.selection.node;
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* Returns the text from the selection if only text is selected on a single line.
|
|
131
|
-
* If selection contains leaf nodes (br, image) between text elements or
|
|
132
|
-
* text from multiple block nodes, the function will return empty string.
|
|
133
|
-
*
|
|
134
|
-
* Useful for values of the inputs of Link and Find&Replace dialogs where the inputs value has been retrieved from the selection and
|
|
135
|
-
* should be single line text only.
|
|
136
|
-
*/
|
|
137
|
-
const selectedLineTextOnly = (state) => {
|
|
138
|
-
let result = '', hasLeafs = false;
|
|
139
|
-
const { selection, doc } = state;
|
|
140
|
-
const { $from, $to, from, to } = selection;
|
|
141
|
-
if ($from.sameParent($to)) {
|
|
142
|
-
doc.nodesBetween(from, to, (node) => {
|
|
143
|
-
hasLeafs = hasLeafs || (node.isLeaf && !node.isText);
|
|
144
|
-
});
|
|
145
|
-
if (!hasLeafs) {
|
|
146
|
-
result = getSelectionText(state);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return result;
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* Used by ViewHtml/ViewSource dialogs for making the HTML more readable.
|
|
153
|
-
*/
|
|
154
|
-
const indentHtml = (content) => {
|
|
155
|
-
return content.replace(/<\/(p|li|ul|ol|h[1-6]|table|tr|td|th)>/ig, '</$1>\n')
|
|
156
|
-
.replace(/<(ul|ol)([^>]*)><li/ig, '<$1$2>\n<li')
|
|
157
|
-
.replace(/<br \/>/ig, '<br />\n')
|
|
158
|
-
.replace(/\n$/, '');
|
|
159
|
-
};
|
|
160
|
-
const shallowEqual = (object1, object2) => {
|
|
161
|
-
const keys1 = Object.keys(object1);
|
|
162
|
-
const keys2 = Object.keys(object2);
|
|
163
|
-
return keys1.length === keys2.length &&
|
|
164
|
-
keys1.every(k => object1[k] === object2[k]);
|
|
165
|
-
};
|
|
166
|
-
const applyToWordDefault = { before: /[^ !,?.\[\]{}()]+$/i, after: /^[^ !,?.\[\]{}()]+/i };
|
|
167
|
-
/**
|
|
168
|
-
* if options.applyToWord is set, expands the selection to the word where the cursor is and
|
|
169
|
-
* returns modified state and dispatch.
|
|
170
|
-
*/
|
|
171
|
-
const expandSelection = (state, dispatch, options) => {
|
|
172
|
-
if (!options.applyToWord || !state.selection.empty) {
|
|
173
|
-
return { state, dispatch };
|
|
174
|
-
}
|
|
175
|
-
const applyToWordOptions = options.applyToWord === true ? applyToWordDefault : options.applyToWord;
|
|
176
|
-
let initialPosition = null;
|
|
177
|
-
const tr = state.tr;
|
|
178
|
-
const selection = state.selection;
|
|
179
|
-
const before = selection.$head.nodeBefore;
|
|
180
|
-
const after = selection.$head.nodeAfter;
|
|
181
|
-
if (before && before.type.name === 'text' && before.text && after && after.type.name === 'text' && after.text) {
|
|
182
|
-
const children = [];
|
|
183
|
-
selection.$head.parent.descendants((node, pos) => {
|
|
184
|
-
children.push({ node, pos });
|
|
185
|
-
return false;
|
|
186
|
-
});
|
|
187
|
-
let cursor = selection.$head.parentOffset;
|
|
188
|
-
const nodeIndex = children.findIndex(({ node, pos }) => pos <= cursor && pos + node.nodeSize >= cursor);
|
|
189
|
-
let text = children[nodeIndex].node.text;
|
|
190
|
-
let skip = false;
|
|
191
|
-
for (let i = nodeIndex - 1; i >= 0; i--) {
|
|
192
|
-
const element = children[i];
|
|
193
|
-
if (!skip && element && element.node.type.name === 'text') {
|
|
194
|
-
text = element.node.text + text;
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
skip = true;
|
|
198
|
-
cursor -= element.node.nodeSize;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
for (let i = nodeIndex + 1; i < children.length; i++) {
|
|
202
|
-
const element = children[i];
|
|
203
|
-
if (element && element.node.type.name === 'text') {
|
|
204
|
-
text = text + element.node.text;
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
const textBefore = text.substring(0, cursor);
|
|
211
|
-
const textAfter = text.substring(cursor);
|
|
212
|
-
const matchBefore = applyToWordOptions.before.exec(textBefore);
|
|
213
|
-
const matchAfter = applyToWordOptions.after.exec(textAfter);
|
|
214
|
-
if (matchBefore && matchAfter) {
|
|
215
|
-
const extendLeft = matchBefore[0].length;
|
|
216
|
-
const extendRight = matchAfter[0].length;
|
|
217
|
-
const pos = initialPosition = selection.from;
|
|
218
|
-
tr.setSelection(TextSelection.create(state.doc, pos - extendLeft, pos + extendRight));
|
|
219
|
-
const cmdState = {
|
|
220
|
-
tr,
|
|
221
|
-
selection: tr.selection,
|
|
222
|
-
doc: tr.doc,
|
|
223
|
-
storedMarks: null,
|
|
224
|
-
schema: tr.doc.type.schema
|
|
225
|
-
};
|
|
226
|
-
const cmdDispatch = tran => {
|
|
227
|
-
tran.setSelection(TextSelection.create(tran.doc, initialPosition));
|
|
228
|
-
dispatch(tran);
|
|
229
|
-
};
|
|
230
|
-
return { state: cmdState, dispatch: cmdDispatch };
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return { state, dispatch };
|
|
234
|
-
};
|
|
235
|
-
/**
|
|
236
|
-
* if options.applyToWord is set, expands the selection to the word where the cursor is and
|
|
237
|
-
* use the modified state for the passed command.
|
|
238
|
-
* Designed to work with toggleInlineFormat, applyInlineStyle and applyLink functions.
|
|
239
|
-
*
|
|
240
|
-
* Example:
|
|
241
|
-
* const applyToWord: boolean|{before: RegExp, after: RegExp} = true;
|
|
242
|
-
* // or applyToWord = { before: /[^ !,?.\[\]{}()]+$/i, after: /^[^ !,?.\[\]{}()]+/i }};
|
|
243
|
-
*
|
|
244
|
-
* const command = expandToWordWrap(toggleInlineFormat, {...bold, applyToWord );
|
|
245
|
-
* command(view.state, view.dispatch);
|
|
246
|
-
*/
|
|
247
|
-
const expandToWordWrap = (command, options) => {
|
|
248
|
-
return (state, dispatch) => {
|
|
249
|
-
const { state: cmdState, dispatch: cmdDispatch } = expandSelection(state, dispatch, options);
|
|
250
|
-
return command(options)(cmdState, cmdDispatch);
|
|
251
|
-
};
|
|
252
|
-
};
|
|
253
|
-
const parseStyle = (styleText) => {
|
|
254
|
-
return parseInlineStyles(styleText);
|
|
255
|
-
};
|
|
256
|
-
const applyStyle = (styleText, styleType, styleValue) => {
|
|
257
|
-
const styles = parseStyle(styleText);
|
|
258
|
-
styles[styleType] = styleValue;
|
|
259
|
-
const result = Object.keys(styles)
|
|
260
|
-
.map(name => styles[name] ? `${name}: ${styles[name]}` : null)
|
|
261
|
-
.filter(Boolean)
|
|
262
|
-
.join('; ');
|
|
263
|
-
return result ? result + ';' : null;
|
|
264
|
-
};
|
|
265
|
-
const setStyleAttr = (element, styleString) => {
|
|
266
|
-
const styles = parseStyle(styleString);
|
|
267
|
-
for (const style in styles) {
|
|
268
|
-
if (style && element.style[style] !== undefined) {
|
|
269
|
-
element.style[style] = styles[style];
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
const setAttribute = (node, attrName, value) => {
|
|
274
|
-
const current = node.getAttribute(attrName);
|
|
275
|
-
if (value !== undefined && value !== current) {
|
|
276
|
-
if (attrName === 'style') {
|
|
277
|
-
node.removeAttribute(attrName);
|
|
278
|
-
setStyleAttr(node, value);
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
node.setAttribute(attrName, value);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
else if (value === undefined) {
|
|
285
|
-
node.removeAttribute(attrName);
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
export { applyStyle, canInsert, changeStylesString, expandSelection, expandToWordWrap, findNthParentNodeOfType, getNodeFromSelection, getSelectionText, indentHtml, insertNode, parentNode, parseStyle, selectedLineTextOnly, setAttribute, setNodeStyle, setStyleAttr, shallowEqual };
|