@progress/kendo-editor-common 1.10.3-dev.202309121208 → 1.10.3
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 +188 -0
- package/dist/es/main.js +1 -0
- package/dist/es/plugins/csp-fix.js +51 -0
- package/dist/es/plugins/table-resize/column-resize.js +2 -1
- package/dist/es/plugins/table-resize/row-resize.js +2 -1
- package/dist/es/plugins/table-resize/table-resize.js +2 -1
- package/dist/es/plugins/table-resize/table-view.js +3 -17
- package/dist/es/plugins/table-resize/utils.js +0 -8
- package/dist/es/source.js +29 -19
- package/dist/es/utils.js +31 -0
- package/dist/es2015/DOMSerializer.js +181 -0
- package/dist/es2015/main.js +1 -0
- package/dist/es2015/plugins/csp-fix.js +48 -0
- package/dist/es2015/plugins/table-resize/column-resize.js +2 -1
- package/dist/es2015/plugins/table-resize/row-resize.js +2 -1
- package/dist/es2015/plugins/table-resize/table-resize.js +2 -1
- package/dist/es2015/plugins/table-resize/table-view.js +3 -17
- package/dist/es2015/plugins/table-resize/utils.js +0 -7
- package/dist/es2015/source.js +27 -19
- package/dist/es2015/utils.js +30 -0
- package/dist/npm/DOMSerializer.d.ts +35 -0
- package/dist/npm/DOMSerializer.js +191 -0
- package/dist/npm/main.d.ts +1 -0
- package/dist/npm/main.js +4 -2
- package/dist/npm/plugins/csp-fix.d.ts +2 -0
- package/dist/npm/plugins/csp-fix.js +55 -0
- package/dist/npm/plugins/table-resize/column-resize.js +23 -22
- package/dist/npm/plugins/table-resize/row-resize.js +3 -2
- package/dist/npm/plugins/table-resize/table-resize.js +7 -6
- package/dist/npm/plugins/table-resize/table-view.js +3 -17
- package/dist/npm/plugins/table-resize/utils.d.ts +0 -3
- package/dist/npm/plugins/table-resize/utils.js +1 -10
- package/dist/npm/source.js +29 -19
- package/dist/npm/utils.d.ts +4 -0
- package/dist/npm/utils.js +34 -1
- package/dist/systemjs/kendo-editor-common.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Plugin, PluginKey } from "prosemirror-state";
|
|
2
|
+
import { setAttribute } from "../utils";
|
|
3
|
+
const setAttributes = (dom, attrs) => {
|
|
4
|
+
for (let attrName in attrs) {
|
|
5
|
+
if (attrName) {
|
|
6
|
+
setAttribute(dom, attrName, attrs[attrName]);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
class CustomNodeView {
|
|
11
|
+
constructor(node, view, nodeName, isLeaf = false) {
|
|
12
|
+
this.node = node;
|
|
13
|
+
this.view = view;
|
|
14
|
+
this.dom = document.createElement(nodeName);
|
|
15
|
+
setAttributes(this.dom, node.attrs);
|
|
16
|
+
this.contentDOM = !isLeaf ? this.dom : undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
class StyleView {
|
|
20
|
+
constructor(mark, view, _inline) {
|
|
21
|
+
this.mark = mark;
|
|
22
|
+
this.view = view;
|
|
23
|
+
this.dom = document.createElement('span');
|
|
24
|
+
setAttributes(this.dom, mark.attrs);
|
|
25
|
+
this.contentDOM = this.dom;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export const cspFix = () => {
|
|
29
|
+
return new Plugin({
|
|
30
|
+
key: new PluginKey('csp-fix'),
|
|
31
|
+
props: {
|
|
32
|
+
nodeViews: {
|
|
33
|
+
paragraph: (node, view) => new CustomNodeView(node, view, 'p'),
|
|
34
|
+
div: (node, view) => new CustomNodeView(node, view, 'div'),
|
|
35
|
+
table_wrapper: (node, view) => new CustomNodeView(node, view, 'div'),
|
|
36
|
+
table_caption_external: (node, view) => new CustomNodeView(node, view, 'div'),
|
|
37
|
+
table: (node, view) => new CustomNodeView(node, view, 'table'),
|
|
38
|
+
table_row: (node, view) => new CustomNodeView(node, view, 'tr'),
|
|
39
|
+
table_cell: (node, view) => new CustomNodeView(node, view, 'td'),
|
|
40
|
+
table_header: (node, view) => new CustomNodeView(node, view, 'th'),
|
|
41
|
+
image: (node, view) => new CustomNodeView(node, view, 'img', true)
|
|
42
|
+
},
|
|
43
|
+
markViews: {
|
|
44
|
+
style: (mark, view, inline) => new StyleView(mark, view, inline)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
@@ -3,7 +3,8 @@ import { TableMap } from 'prosemirror-tables';
|
|
|
3
3
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
4
4
|
import { colgroupAttr } from '../../config/constants';
|
|
5
5
|
import { TableView, TableWrapperView } from './table-view';
|
|
6
|
-
import {
|
|
6
|
+
import { parseStyle } from './../../utils';
|
|
7
|
+
import { cellIndexes, domCellAround, otherResizeHandle, otherResizing, edgeCell, setNodeStyle, tableColumnResizeKey as key } from './utils';
|
|
7
8
|
export function columnResizing() {
|
|
8
9
|
const handleWidth = 5, cellMinWidth = 25;
|
|
9
10
|
let plugin = new Plugin({
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Plugin } from 'prosemirror-state';
|
|
2
2
|
import { TableMap, tableNodeTypes } from 'prosemirror-tables';
|
|
3
3
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
4
|
-
import { cellIndexes, domCellAround, otherResizeHandle, otherResizing,
|
|
4
|
+
import { cellIndexes, domCellAround, otherResizeHandle, otherResizing, setNodeStyle, tableRowResizeKey as key, edgeCell } from './utils';
|
|
5
|
+
import { parseStyle } from './../../utils';
|
|
5
6
|
class TableRowView {
|
|
6
7
|
ignoreMutation(record) {
|
|
7
8
|
return record.type === 'attributes' && record.attributeName === 'style' && record.target.nodeName === 'TR';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NodeSelection, Plugin } from 'prosemirror-state';
|
|
2
2
|
import { colgroupAttr, dataResizeDirTable, resizableAttr } from '../../config/constants';
|
|
3
|
-
import { getTable, parentNode,
|
|
3
|
+
import { getTable, parentNode, setNodeStyle, tableResizeKey as key } from './utils';
|
|
4
|
+
import { parseStyle } from './../../utils';
|
|
4
5
|
import { directions } from './../resize-utils';
|
|
5
6
|
const commonDir = {
|
|
6
7
|
'southeast': true,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { colgroupAttr, dataResizeDirTable, resizableAttr, resizableWrap, resizeHandle } from '../../config/constants';
|
|
2
2
|
import { parseStrColgroup } from '../../config/schema';
|
|
3
3
|
import { handles } from './../resize-utils';
|
|
4
|
-
import { parseStyle } from '
|
|
4
|
+
import { parseStyle, setAttribute } from './../../utils';
|
|
5
5
|
export class TableView {
|
|
6
6
|
constructor(node, view) {
|
|
7
7
|
this.node = node;
|
|
@@ -71,14 +71,7 @@ export class TableView {
|
|
|
71
71
|
const skip = [colgroupAttr, resizableAttr];
|
|
72
72
|
for (let attrName in attrs) {
|
|
73
73
|
if (attrName && skip.indexOf(attrName) === -1) {
|
|
74
|
-
|
|
75
|
-
const next = attrs[attrName];
|
|
76
|
-
if (next && next !== current) {
|
|
77
|
-
table.setAttribute(attrName, next);
|
|
78
|
-
}
|
|
79
|
-
else if (!next) {
|
|
80
|
-
table.removeAttribute(attrName);
|
|
81
|
-
}
|
|
74
|
+
setAttribute(table, attrName, attrs[attrName]);
|
|
82
75
|
}
|
|
83
76
|
}
|
|
84
77
|
if (/%$/.test(table.style.width)) {
|
|
@@ -116,14 +109,7 @@ export class TableWrapperView {
|
|
|
116
109
|
setAttributes(dom, attrs) {
|
|
117
110
|
for (let attrName in attrs) {
|
|
118
111
|
if (attrName) {
|
|
119
|
-
|
|
120
|
-
const next = attrs[attrName];
|
|
121
|
-
if (next && next !== current) {
|
|
122
|
-
dom.setAttribute(attrName, next);
|
|
123
|
-
}
|
|
124
|
-
else if (!next) {
|
|
125
|
-
dom.removeAttribute(attrName);
|
|
126
|
-
}
|
|
112
|
+
setAttribute(dom, attrName, attrs[attrName]);
|
|
127
113
|
}
|
|
128
114
|
}
|
|
129
115
|
dom.setAttribute('table', '');
|
|
@@ -2,13 +2,6 @@ import { PluginKey } from 'prosemirror-state';
|
|
|
2
2
|
import { TableMap } from 'prosemirror-tables';
|
|
3
3
|
import { changeStylesString } from '../../utils';
|
|
4
4
|
export const reAnyValue = /^.+$/;
|
|
5
|
-
export const parseStyle = (styleText) => {
|
|
6
|
-
const styles = (styleText || '').split(/\s*;\s*/).filter(Boolean).map(s => {
|
|
7
|
-
const nameValue = s.split(/\s*:\s*/);
|
|
8
|
-
return { [nameValue[0]]: nameValue[1] };
|
|
9
|
-
}).reduce((acc, val) => (Object.assign(Object.assign({}, acc), val)), {});
|
|
10
|
-
return styles;
|
|
11
|
-
};
|
|
12
5
|
export function setNodeStyle(nodeAttrs, styleType, value) {
|
|
13
6
|
let attrs;
|
|
14
7
|
if (new RegExp('[^-]?' + styleType + ':').test(nodeAttrs.style || '')) {
|
package/dist/es2015/source.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DOMParser as ProseMirrorDOMParser } from 'prosemirror-model';
|
|
2
2
|
import { AllSelection } from 'prosemirror-state';
|
|
3
3
|
import { rowTypeAttr, colgroupAttr } from './config/constants';
|
|
4
|
+
import { DOMSerializer } from './DOMSerializer';
|
|
4
5
|
const blockWrappers = [
|
|
5
6
|
'div', 'ol', 'ul', 'li', 'table', 'tbody', 'thead', 'tfoot', 'caption', 'td', 'th', 'p',
|
|
6
7
|
'tr', 'col', 'colgroup', 'article', 'main', 'nav', 'header', 'footer', 'aside', 'section'
|
|
@@ -127,6 +128,27 @@ export const trimWhitespace = (html, trimAroundTags = blockWrappers) => {
|
|
|
127
128
|
return html.replace(new RegExp('\\s*(<(?:' + tags + ')(?:\\s[^>]*?)?>)', 'g'), '$1')
|
|
128
129
|
.replace(new RegExp('(<\\/(?:' + tags + ')(?:\\s[^>]*?)?>)\\s*', 'g'), '$1');
|
|
129
130
|
};
|
|
131
|
+
const styleAttr = 'data-style';
|
|
132
|
+
const styleReplace = ' ' + styleAttr + '=';
|
|
133
|
+
const reTag = /<[^>]+>/gm;
|
|
134
|
+
const reStyle = /\sstyle=/gm;
|
|
135
|
+
const replacer = (match) => {
|
|
136
|
+
return match.replace(reStyle, styleReplace);
|
|
137
|
+
};
|
|
138
|
+
const replaceStyleAttr = (html) => {
|
|
139
|
+
return html.replace(reTag, replacer);
|
|
140
|
+
};
|
|
141
|
+
const applyStyle = (styleString, element) => styleString.split(';').filter(s => s !== '').forEach(s => {
|
|
142
|
+
const parts = s.split(':');
|
|
143
|
+
element.style[parts[0].trim()] = parts[1].trim();
|
|
144
|
+
});
|
|
145
|
+
const restoreStyleAttr = (container) => {
|
|
146
|
+
Array.from(container.querySelectorAll('[' + styleAttr + ']')).forEach((element) => {
|
|
147
|
+
const styleString = element.getAttribute(styleAttr);
|
|
148
|
+
element.removeAttribute(styleAttr);
|
|
149
|
+
applyStyle(styleString, element);
|
|
150
|
+
});
|
|
151
|
+
};
|
|
130
152
|
/**
|
|
131
153
|
* Creates a DocumentFragment from the given HTML content.
|
|
132
154
|
*
|
|
@@ -135,21 +157,9 @@ export const trimWhitespace = (html, trimAroundTags = blockWrappers) => {
|
|
|
135
157
|
*/
|
|
136
158
|
export const htmlToFragment = (html) => {
|
|
137
159
|
const template = document.createElement('template');
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
fragment = template.content;
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
// Internet Explorer
|
|
145
|
-
const parsedDocument = new DOMParser().parseFromString(html, 'text/html');
|
|
146
|
-
fragment = document.createDocumentFragment();
|
|
147
|
-
const dom = parsedDocument.body;
|
|
148
|
-
while (dom && dom.firstChild) {
|
|
149
|
-
fragment.appendChild(dom.firstChild);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return fragment;
|
|
160
|
+
template.innerHTML = replaceStyleAttr(html);
|
|
161
|
+
restoreStyleAttr(template.content);
|
|
162
|
+
return template.content;
|
|
153
163
|
};
|
|
154
164
|
/**
|
|
155
165
|
* @hidden
|
|
@@ -199,9 +209,7 @@ export const parseContent = (content, schema, parseOptions) => {
|
|
|
199
209
|
*/
|
|
200
210
|
export const getHtml = (state) => {
|
|
201
211
|
const fragment = pmDocToFragment(state.doc);
|
|
202
|
-
|
|
203
|
-
container.appendChild(fragment);
|
|
204
|
-
return container.innerHTML;
|
|
212
|
+
return fragmentToHtml(fragment);
|
|
205
213
|
};
|
|
206
214
|
/**
|
|
207
215
|
* Replaces the content of the editor with a new one.
|
package/dist/es2015/utils.js
CHANGED
|
@@ -226,3 +226,33 @@ export const expandToWordWrap = (command, options) => {
|
|
|
226
226
|
return command(options)(cmdState, cmdDispatch);
|
|
227
227
|
};
|
|
228
228
|
};
|
|
229
|
+
export const parseStyle = (styleText) => {
|
|
230
|
+
const styles = (styleText || '').split(/\s*;\s*/).filter(Boolean).map(s => {
|
|
231
|
+
const nameValue = s.split(/\s*:\s*/);
|
|
232
|
+
return { [nameValue[0]]: nameValue[1] };
|
|
233
|
+
}).reduce((acc, val) => (Object.assign(Object.assign({}, acc), val)), {});
|
|
234
|
+
return styles;
|
|
235
|
+
};
|
|
236
|
+
const setStyleAttr = (element, styleString) => {
|
|
237
|
+
const styles = parseStyle(styleString);
|
|
238
|
+
for (let style in styles) {
|
|
239
|
+
if (style && typeof element.style[style] !== 'undefined') {
|
|
240
|
+
element.style[style] = styles[style];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
export const setAttribute = (node, attrName, value) => {
|
|
245
|
+
const current = node.getAttribute(attrName);
|
|
246
|
+
if (value !== undefined && value !== current) {
|
|
247
|
+
if (attrName === 'style') {
|
|
248
|
+
node.removeAttribute(attrName);
|
|
249
|
+
setStyleAttr(node, value);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
node.setAttribute(attrName, value);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else if (value === undefined) {
|
|
256
|
+
node.removeAttribute(attrName);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DOMOutputSpec, Fragment, Mark, Node, Schema } from "prosemirror-model";
|
|
2
|
+
declare type DOMNode = InstanceType<typeof window.Node>;
|
|
3
|
+
export declare class DOMSerializer {
|
|
4
|
+
readonly nodes: {
|
|
5
|
+
[node: string]: (node: Node) => DOMOutputSpec;
|
|
6
|
+
};
|
|
7
|
+
readonly marks: {
|
|
8
|
+
[mark: string]: (mark: Mark, inline: boolean) => DOMOutputSpec;
|
|
9
|
+
};
|
|
10
|
+
static renderSpec(docum: Document, structure: DOMOutputSpec, xmlNS?: string | null): {
|
|
11
|
+
dom: DOMNode;
|
|
12
|
+
contentDOM?: HTMLElement;
|
|
13
|
+
};
|
|
14
|
+
static fromSchema(schema: Schema): DOMSerializer;
|
|
15
|
+
static nodesFromSchema(schema: Schema): {
|
|
16
|
+
[node: string]: (node: Node) => DOMOutputSpec;
|
|
17
|
+
};
|
|
18
|
+
static marksFromSchema(schema: Schema): {
|
|
19
|
+
[mark: string]: (mark: Mark, inline: boolean) => DOMOutputSpec;
|
|
20
|
+
};
|
|
21
|
+
constructor(nodes: {
|
|
22
|
+
[node: string]: (node: Node) => DOMOutputSpec;
|
|
23
|
+
}, marks: {
|
|
24
|
+
[mark: string]: (mark: Mark, inline: boolean) => DOMOutputSpec;
|
|
25
|
+
});
|
|
26
|
+
serializeFragment(fragment: Fragment, options?: {
|
|
27
|
+
document?: Document;
|
|
28
|
+
}, target?: HTMLElement | DocumentFragment): HTMLElement | DocumentFragment;
|
|
29
|
+
serializeNode(node: Node, options?: {
|
|
30
|
+
document?: Document;
|
|
31
|
+
}): globalThis.Node;
|
|
32
|
+
private serializeMark;
|
|
33
|
+
private serializeNodeInner;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DOMSerializer = void 0;
|
|
4
|
+
var utils_1 = require("./utils");
|
|
5
|
+
var DOMSerializer = /** @class */ (function () {
|
|
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
|
+
}
|
|
21
|
+
/// Render an [output spec](#model.DOMOutputSpec) to a DOM node. If
|
|
22
|
+
/// the spec has a hole (zero) in it, `contentDOM` will point at the
|
|
23
|
+
/// node with the hole.
|
|
24
|
+
DOMSerializer.renderSpec = function (docum, structure, xmlNS) {
|
|
25
|
+
if (xmlNS === void 0) { xmlNS = null; }
|
|
26
|
+
if (typeof structure === "string") {
|
|
27
|
+
return { dom: docum.createTextNode(structure) };
|
|
28
|
+
}
|
|
29
|
+
if (structure.nodeType != null) {
|
|
30
|
+
return { dom: structure };
|
|
31
|
+
}
|
|
32
|
+
if (structure.dom && structure.dom.nodeType != null) {
|
|
33
|
+
return structure;
|
|
34
|
+
}
|
|
35
|
+
var tagName = structure[0], space = tagName.indexOf(" ");
|
|
36
|
+
if (space > 0) {
|
|
37
|
+
xmlNS = tagName.slice(0, space);
|
|
38
|
+
tagName = tagName.slice(space + 1);
|
|
39
|
+
}
|
|
40
|
+
var contentDOM;
|
|
41
|
+
var dom = (xmlNS ? docum.createElementNS(xmlNS, tagName) : docum.createElement(tagName));
|
|
42
|
+
var attrs = structure[1], start = 1;
|
|
43
|
+
if (attrs && typeof attrs === "object" && attrs.nodeType == null && !Array.isArray(attrs)) {
|
|
44
|
+
start = 2;
|
|
45
|
+
for (var name_1 in attrs) {
|
|
46
|
+
if (attrs[name_1] != null) {
|
|
47
|
+
space = name_1.indexOf(" ");
|
|
48
|
+
if (space > 0) {
|
|
49
|
+
dom.setAttributeNS(name_1.slice(0, space), name_1.slice(space + 1), attrs[name_1]);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
utils_1.setAttribute(dom, name_1, attrs[name_1]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (var i = start; i < structure.length; i++) {
|
|
58
|
+
var child = structure[i];
|
|
59
|
+
if (child === 0) {
|
|
60
|
+
if (i < structure.length - 1 || i > start) {
|
|
61
|
+
throw new RangeError("Content hole must be the only child of its parent node");
|
|
62
|
+
}
|
|
63
|
+
return { dom: dom, contentDOM: dom };
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
var _a = DOMSerializer.renderSpec(docum, child, xmlNS), inner = _a.dom, innerContent = _a.contentDOM;
|
|
67
|
+
dom.appendChild(inner);
|
|
68
|
+
if (innerContent) {
|
|
69
|
+
if (contentDOM) {
|
|
70
|
+
throw new RangeError("Multiple content holes");
|
|
71
|
+
}
|
|
72
|
+
contentDOM = innerContent;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { dom: dom, contentDOM: contentDOM };
|
|
77
|
+
};
|
|
78
|
+
/// Build a serializer using the [`toDOM`](#model.NodeSpec.toDOM)
|
|
79
|
+
/// properties in a schema's node and mark specs.
|
|
80
|
+
DOMSerializer.fromSchema = function (schema) {
|
|
81
|
+
return schema.cached.domSerializer ||
|
|
82
|
+
(schema.cached.domSerializer = new DOMSerializer(this.nodesFromSchema(schema), this.marksFromSchema(schema)));
|
|
83
|
+
};
|
|
84
|
+
/// Gather the serializers in a schema's node specs into an object.
|
|
85
|
+
/// This can be useful as a base to build a custom serializer from.
|
|
86
|
+
DOMSerializer.nodesFromSchema = function (schema) {
|
|
87
|
+
var result = gatherToDOM(schema.nodes);
|
|
88
|
+
if (!result.text) {
|
|
89
|
+
result.text = function (node) { return node.text; };
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
};
|
|
93
|
+
/// Gather the serializers in a schema's mark specs into an object.
|
|
94
|
+
DOMSerializer.marksFromSchema = function (schema) {
|
|
95
|
+
return gatherToDOM(schema.marks);
|
|
96
|
+
};
|
|
97
|
+
/// Serialize the content of this fragment to a DOM fragment. When
|
|
98
|
+
/// not in the browser, the `document` option, containing a DOM
|
|
99
|
+
/// document, should be passed so that the serializer can create
|
|
100
|
+
/// nodes.
|
|
101
|
+
DOMSerializer.prototype.serializeFragment = function (fragment, options, target) {
|
|
102
|
+
var _this = this;
|
|
103
|
+
if (options === void 0) { options = {}; }
|
|
104
|
+
if (!target) {
|
|
105
|
+
target = doc(options).createDocumentFragment();
|
|
106
|
+
}
|
|
107
|
+
var top = target, active = [];
|
|
108
|
+
fragment.forEach(function (node) {
|
|
109
|
+
if (active.length || node.marks.length) {
|
|
110
|
+
var keep = 0, rendered = 0;
|
|
111
|
+
while (keep < active.length && rendered < node.marks.length) {
|
|
112
|
+
var next = node.marks[rendered];
|
|
113
|
+
if (!_this.marks[next.type.name]) {
|
|
114
|
+
rendered++;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (!next.eq(active[keep][0]) || next.type.spec.spanning === false) {
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
keep++;
|
|
121
|
+
rendered++;
|
|
122
|
+
}
|
|
123
|
+
while (keep < active.length) {
|
|
124
|
+
top = active.pop()[1];
|
|
125
|
+
}
|
|
126
|
+
while (rendered < node.marks.length) {
|
|
127
|
+
var add = node.marks[rendered++];
|
|
128
|
+
var markDOM = _this.serializeMark(add, node.isInline, options);
|
|
129
|
+
if (markDOM) {
|
|
130
|
+
active.push([add, top]);
|
|
131
|
+
top.appendChild(markDOM.dom);
|
|
132
|
+
top = markDOM.contentDOM || markDOM.dom;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
top.appendChild(_this.serializeNodeInner(node, options));
|
|
137
|
+
});
|
|
138
|
+
return target;
|
|
139
|
+
};
|
|
140
|
+
/// Serialize this node to a DOM node. This can be useful when you
|
|
141
|
+
/// need to serialize a part of a document, as opposed to the whole
|
|
142
|
+
/// document. To serialize a whole document, use
|
|
143
|
+
/// [`serializeFragment`](#model.DOMSerializer.serializeFragment) on
|
|
144
|
+
/// its [content](#model.Node.content).
|
|
145
|
+
DOMSerializer.prototype.serializeNode = function (node, options) {
|
|
146
|
+
if (options === void 0) { options = {}; }
|
|
147
|
+
var dom = this.serializeNodeInner(node, options);
|
|
148
|
+
for (var i = node.marks.length - 1; i >= 0; i--) {
|
|
149
|
+
var wrap = this.serializeMark(node.marks[i], node.isInline, options);
|
|
150
|
+
if (wrap) {
|
|
151
|
+
(wrap.contentDOM || wrap.dom).appendChild(dom);
|
|
152
|
+
dom = wrap.dom;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return dom;
|
|
156
|
+
};
|
|
157
|
+
/// @internal
|
|
158
|
+
DOMSerializer.prototype.serializeMark = function (mark, inline, options) {
|
|
159
|
+
if (options === void 0) { options = {}; }
|
|
160
|
+
var toDOM = this.marks[mark.type.name];
|
|
161
|
+
return toDOM && DOMSerializer.renderSpec(doc(options), toDOM(mark, inline));
|
|
162
|
+
};
|
|
163
|
+
/// @internal
|
|
164
|
+
DOMSerializer.prototype.serializeNodeInner = function (node, options) {
|
|
165
|
+
var _a = DOMSerializer.renderSpec(doc(options), this.nodes[node.type.name](node)), dom = _a.dom, contentDOM = _a.contentDOM;
|
|
166
|
+
if (contentDOM) {
|
|
167
|
+
if (node.isLeaf) {
|
|
168
|
+
throw new RangeError("Content hole not allowed in a leaf node spec");
|
|
169
|
+
}
|
|
170
|
+
this.serializeFragment(node.content, options, contentDOM);
|
|
171
|
+
}
|
|
172
|
+
return dom;
|
|
173
|
+
};
|
|
174
|
+
return DOMSerializer;
|
|
175
|
+
}());
|
|
176
|
+
exports.DOMSerializer = DOMSerializer;
|
|
177
|
+
function gatherToDOM(obj) {
|
|
178
|
+
var result = {};
|
|
179
|
+
for (var name_2 in obj) {
|
|
180
|
+
if (obj[name_2]) {
|
|
181
|
+
var toDOM = obj[name_2].spec.toDOM;
|
|
182
|
+
if (toDOM) {
|
|
183
|
+
result[name_2] = toDOM;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
function doc(options) {
|
|
190
|
+
return options.document || window.document;
|
|
191
|
+
}
|
package/dist/npm/main.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export { convertMsLists } from './listConvert';
|
|
|
23
23
|
export { find, findAt, findAll, replace, replaceAll, SearchOptions } from './find-replace';
|
|
24
24
|
export { placeholder } from './plugins/placeholder';
|
|
25
25
|
export { spacesFix } from './plugins/spaces-fix';
|
|
26
|
+
export { cspFix } from './plugins/csp-fix';
|
|
26
27
|
export { textHighlight, textHighlightKey, InlineDecoration } from './plugins/highlight';
|
|
27
28
|
export { imageResizing, imageResizeKey, ImageResizeOptions } from './plugins/image-resize';
|
|
28
29
|
export { caretColor, caretColorKey } from './plugins/caret-color';
|
package/dist/npm/main.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.expandSelection = exports.selectedLineTextOnly = exports.getNodeFromSelection = exports.getSelectionText = exports.hasSameMarkup = exports.liftBlockquote = exports.blockquote = exports.listStyle = exports.toggleList = exports.toggleUnorderedList = exports.toggleOrderedList = exports.indentBlocks = exports.canBeIndented = exports.isIndented = exports.canOutdentAsListItem = exports.outdent = exports.canIndentAsListItem = exports.indent = exports.selectionMarks = exports.cleanMarks = exports.removeAllMarks = exports.getActiveMarks = exports.getMark = exports.hasMark = exports.cleanTextBlockFormatting = exports.blockNodes = exports.changeTextBlock = exports.parentBlockFormat = exports.getBlockFormats = exports.formatBlockElements = exports.activeNode = exports.hasNode = exports.cleanFormatting = exports.isAligned = exports.alignBlocks = exports.insertImage = exports.insertText = exports.removeLink = exports.applyLink = exports.toggleInlineFormat = exports.getInlineStyles = exports.applyInlineStyle = exports.fragmentToHtml = exports.pmDocToFragment = exports.domToPmDoc = exports.htmlToFragment = exports.trimWhitespace = exports.parseContent = exports.setHtml = exports.getHtml = void 0;
|
|
4
|
-
exports.
|
|
5
|
-
exports.pmDeleteColumn = exports.pmAddRowBefore = exports.pmAddRowAfter = exports.pmAddColumnAfter = exports.pmAddColumnBefore = exports.deleteColumn = exports.addColumnAfter = exports.addColumnBefore = exports.addRowBefore = exports.addRowAfter = exports.createTable = exports.nextCell = exports.moveCellForward = exports.removeColSpan = exports.findCell = exports.cellAround = exports.updateColumnsOnResize = exports.columnResizingPluginKey = exports.columnResizing = exports.columnIsHeader = exports.colCount = exports.addColumn = exports.addColSpan = exports.addRow = exports.rowIsHeader = exports.deleteRow = exports.mergeCells = exports.splitCellWithType = exports.splitCell = exports.toggleHeaderRow = exports.toggleHeaderColumn = exports.toggleHeaderCell = exports.toggleHeader = exports.goToNextCell = exports.setCellAttr = exports.selectionCell = exports.selectedRect = exports.CellSelection = exports.inSameTable = exports.deleteTable = exports.isInTable = exports.fixTablesKey = exports.fixTables = exports.tableNodes = exports.tableNodeTypes = exports.tableEditingKey = void 0;
|
|
4
|
+
exports.TableMap = exports.tableRowResizeKey = exports.tableColumnResizeKey = exports.tableResizeKey = exports.tableResizing = exports.caretColorKey = exports.caretColor = exports.imageResizeKey = exports.imageResizing = exports.textHighlightKey = exports.textHighlight = exports.cspFix = exports.spacesFix = exports.placeholder = exports.replaceAll = exports.replace = exports.findAll = exports.findAt = exports.find = exports.convertMsLists = exports.replaceImageSourcesFromRtf = exports.removeAttribute = exports.sanitizeStyleAttr = exports.sanitizeClassAttr = exports.pasteCleanup = exports.removeTag = exports.removeComments = exports.sanitize = exports.link = exports.superscript = exports.subscript = exports.strikethrough = exports.underline = exports.italic = exports.bold = exports.buildListKeymap = exports.buildKeymap = exports.marks = exports.nodes = exports.outdentRules = exports.indentRules = exports.alignRemoveRules = exports.alignJustifyRules = exports.alignRightRules = exports.alignCenterRules = exports.alignLeftRules = exports.indentHtml = exports.insertNode = exports.canInsert = exports.expandToWordWrap = void 0;
|
|
5
|
+
exports.pmDeleteColumn = exports.pmAddRowBefore = exports.pmAddRowAfter = exports.pmAddColumnAfter = exports.pmAddColumnBefore = exports.deleteColumn = exports.addColumnAfter = exports.addColumnBefore = exports.addRowBefore = exports.addRowAfter = exports.createTable = exports.nextCell = exports.moveCellForward = exports.removeColSpan = exports.findCell = exports.cellAround = exports.updateColumnsOnResize = exports.columnResizingPluginKey = exports.columnResizing = exports.columnIsHeader = exports.colCount = exports.addColumn = exports.addColSpan = exports.addRow = exports.rowIsHeader = exports.deleteRow = exports.mergeCells = exports.splitCellWithType = exports.splitCell = exports.toggleHeaderRow = exports.toggleHeaderColumn = exports.toggleHeaderCell = exports.toggleHeader = exports.goToNextCell = exports.setCellAttr = exports.selectionCell = exports.selectedRect = exports.CellSelection = exports.inSameTable = exports.deleteTable = exports.isInTable = exports.fixTablesKey = exports.fixTables = exports.tableNodes = exports.tableNodeTypes = exports.tableEditingKey = exports.tableEditing = void 0;
|
|
6
6
|
var tslib_1 = require("tslib");
|
|
7
7
|
var source_1 = require("./source");
|
|
8
8
|
Object.defineProperty(exports, "getHtml", { enumerable: true, get: function () { return source_1.getHtml; } });
|
|
@@ -115,6 +115,8 @@ var placeholder_1 = require("./plugins/placeholder");
|
|
|
115
115
|
Object.defineProperty(exports, "placeholder", { enumerable: true, get: function () { return placeholder_1.placeholder; } });
|
|
116
116
|
var spaces_fix_1 = require("./plugins/spaces-fix");
|
|
117
117
|
Object.defineProperty(exports, "spacesFix", { enumerable: true, get: function () { return spaces_fix_1.spacesFix; } });
|
|
118
|
+
var csp_fix_1 = require("./plugins/csp-fix");
|
|
119
|
+
Object.defineProperty(exports, "cspFix", { enumerable: true, get: function () { return csp_fix_1.cspFix; } });
|
|
118
120
|
var highlight_1 = require("./plugins/highlight");
|
|
119
121
|
Object.defineProperty(exports, "textHighlight", { enumerable: true, get: function () { return highlight_1.textHighlight; } });
|
|
120
122
|
Object.defineProperty(exports, "textHighlightKey", { enumerable: true, get: function () { return highlight_1.textHighlightKey; } });
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cspFix = void 0;
|
|
4
|
+
var prosemirror_state_1 = require("prosemirror-state");
|
|
5
|
+
var utils_1 = require("../utils");
|
|
6
|
+
var setAttributes = function (dom, attrs) {
|
|
7
|
+
for (var attrName in attrs) {
|
|
8
|
+
if (attrName) {
|
|
9
|
+
utils_1.setAttribute(dom, attrName, attrs[attrName]);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var CustomNodeView = /** @class */ (function () {
|
|
14
|
+
function CustomNodeView(node, view, nodeName, isLeaf) {
|
|
15
|
+
if (isLeaf === void 0) { isLeaf = false; }
|
|
16
|
+
this.node = node;
|
|
17
|
+
this.view = view;
|
|
18
|
+
this.dom = document.createElement(nodeName);
|
|
19
|
+
setAttributes(this.dom, node.attrs);
|
|
20
|
+
this.contentDOM = !isLeaf ? this.dom : undefined;
|
|
21
|
+
}
|
|
22
|
+
return CustomNodeView;
|
|
23
|
+
}());
|
|
24
|
+
var StyleView = /** @class */ (function () {
|
|
25
|
+
function StyleView(mark, view, _inline) {
|
|
26
|
+
this.mark = mark;
|
|
27
|
+
this.view = view;
|
|
28
|
+
this.dom = document.createElement('span');
|
|
29
|
+
setAttributes(this.dom, mark.attrs);
|
|
30
|
+
this.contentDOM = this.dom;
|
|
31
|
+
}
|
|
32
|
+
return StyleView;
|
|
33
|
+
}());
|
|
34
|
+
var cspFix = function () {
|
|
35
|
+
return new prosemirror_state_1.Plugin({
|
|
36
|
+
key: new prosemirror_state_1.PluginKey('csp-fix'),
|
|
37
|
+
props: {
|
|
38
|
+
nodeViews: {
|
|
39
|
+
paragraph: function (node, view) { return new CustomNodeView(node, view, 'p'); },
|
|
40
|
+
div: function (node, view) { return new CustomNodeView(node, view, 'div'); },
|
|
41
|
+
table_wrapper: function (node, view) { return new CustomNodeView(node, view, 'div'); },
|
|
42
|
+
table_caption_external: function (node, view) { return new CustomNodeView(node, view, 'div'); },
|
|
43
|
+
table: function (node, view) { return new CustomNodeView(node, view, 'table'); },
|
|
44
|
+
table_row: function (node, view) { return new CustomNodeView(node, view, 'tr'); },
|
|
45
|
+
table_cell: function (node, view) { return new CustomNodeView(node, view, 'td'); },
|
|
46
|
+
table_header: function (node, view) { return new CustomNodeView(node, view, 'th'); },
|
|
47
|
+
image: function (node, view) { return new CustomNodeView(node, view, 'img', true); }
|
|
48
|
+
},
|
|
49
|
+
markViews: {
|
|
50
|
+
style: function (mark, view, inline) { return new StyleView(mark, view, inline); }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
exports.cspFix = cspFix;
|