@progress/kendo-editor-common 1.10.4-dev.202311091213 → 1.11.0
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/main.js +1 -0
- package/dist/es/plugins/list-markers-styles.js +103 -0
- package/dist/es/plugins/table-resize/column-resize.js +2 -2
- package/dist/es/plugins/table-resize/row-resize.js +2 -2
- package/dist/es/plugins/table-resize/table-resize.js +2 -2
- package/dist/es/plugins/table-resize/utils.js +1 -26
- package/dist/es/utils.js +33 -0
- package/dist/es2015/main.js +1 -0
- package/dist/es2015/plugins/list-markers-styles.js +101 -0
- package/dist/es2015/plugins/table-resize/column-resize.js +2 -2
- package/dist/es2015/plugins/table-resize/row-resize.js +2 -2
- package/dist/es2015/plugins/table-resize/table-resize.js +2 -2
- package/dist/es2015/plugins/table-resize/utils.js +1 -25
- package/dist/es2015/utils.js +33 -0
- package/dist/npm/main.d.ts +1 -0
- package/dist/npm/main.js +4 -2
- package/dist/npm/plugins/list-markers-styles.d.ts +13 -0
- package/dist/npm/plugins/list-markers-styles.js +107 -0
- package/dist/npm/plugins/table-resize/column-resize.js +2 -2
- package/dist/npm/plugins/table-resize/row-resize.js +2 -2
- package/dist/npm/plugins/table-resize/table-resize.js +9 -9
- package/dist/npm/plugins/table-resize/utils.d.ts +0 -7
- package/dist/npm/plugins/table-resize/utils.js +2 -29
- package/dist/npm/utils.d.ts +7 -1
- package/dist/npm/utils.js +37 -1
- package/dist/systemjs/kendo-editor-common.js +1 -1
- package/package.json +1 -1
package/dist/es/main.js
CHANGED
|
@@ -26,6 +26,7 @@ export { textHighlight, textHighlightKey } from './plugins/highlight';
|
|
|
26
26
|
export { imageResizing, imageResizeKey } from './plugins/image-resize';
|
|
27
27
|
export { caretColor, caretColorKey } from './plugins/caret-color';
|
|
28
28
|
export { tableResizing, tableResizeKey, tableColumnResizeKey, tableRowResizeKey } from './plugins/table-resize';
|
|
29
|
+
export { listMarkersStyles } from './plugins/list-markers-styles';
|
|
29
30
|
// ProseMirror re-exports
|
|
30
31
|
export * from 'prosemirror-commands';
|
|
31
32
|
export * from 'prosemirror-dropcursor';
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
3
|
+
import { RemoveMarkStep } from 'prosemirror-transform';
|
|
4
|
+
import { parseStyle, applyStyle, parentNode } from '../utils';
|
|
5
|
+
var inSelection = function (from, to, nodePos, node, doc) {
|
|
6
|
+
var $from = doc.resolve(from);
|
|
7
|
+
var $to = doc.resolve(to);
|
|
8
|
+
var nodeName = node.type.name;
|
|
9
|
+
var wrapper, parentLi;
|
|
10
|
+
if (!$from.nodeBefore) {
|
|
11
|
+
wrapper = $from.node($from.depth);
|
|
12
|
+
parentLi = $from.node($from.depth - 1);
|
|
13
|
+
if (wrapper && parentLi && parentLi.firstChild === wrapper && parentLi.type.name === nodeName) {
|
|
14
|
+
return nodePos + node.content.size <= to;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (!$to.nodeAfter) {
|
|
18
|
+
wrapper = $to.node($to.depth);
|
|
19
|
+
parentLi = $to.node($to.depth - 1);
|
|
20
|
+
if (wrapper && parentLi && parentLi.lastChild === wrapper && parentLi.type.name === nodeName) {
|
|
21
|
+
return from <= nodePos;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return from <= nodePos && nodePos + node.content.size <= to;
|
|
25
|
+
};
|
|
26
|
+
var applyToListItems = function (tr, state, options) {
|
|
27
|
+
var transaction = state.tr, doc = state.doc, _a = state.selection, from = _a.from, to = _a.to;
|
|
28
|
+
var args = tr.getMeta('args');
|
|
29
|
+
doc.nodesBetween(from, to, function (node, pos) {
|
|
30
|
+
if ((node.type.name === options.listItem) && inSelection(from, to, pos, node, doc)) {
|
|
31
|
+
transaction.setNodeMarkup(pos, null, __assign(__assign({}, node.attrs), { style: applyStyle(node.attrs.style, args.style, args.value) }));
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return transaction.docChanged ? transaction : undefined;
|
|
35
|
+
};
|
|
36
|
+
var cleanListItems = function (tr, state, options) {
|
|
37
|
+
var stylesToClean = Object.keys(options.resetValues);
|
|
38
|
+
var transaction = state.tr, doc = state.doc, _a = state.selection, from = _a.from, to = _a.to;
|
|
39
|
+
doc.nodesBetween(from, to, function (node, pos, _parent) {
|
|
40
|
+
if (node.type.name === options.listItem && inSelection(from, to, pos, node, doc)) {
|
|
41
|
+
var attrs_1 = node.attrs;
|
|
42
|
+
var nodeStyles_1 = parseStyle(node.attrs.style);
|
|
43
|
+
stylesToClean.forEach(function (style) {
|
|
44
|
+
if (nodeStyles_1[style]) {
|
|
45
|
+
attrs_1 = __assign(__assign({}, attrs_1), { style: applyStyle(attrs_1.style, style, '') });
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
if (attrs_1 !== node.attrs) {
|
|
49
|
+
transaction.setNodeMarkup(pos, null, attrs_1);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
tr.steps.forEach(function (step) {
|
|
54
|
+
if (step instanceof RemoveMarkStep) {
|
|
55
|
+
var mark = step.mark;
|
|
56
|
+
if (mark.type.name === 'style' && mark.attrs.style) {
|
|
57
|
+
var _a = mark.attrs.style.split(/\s*:\s*/), name_1 = _a[0], _value = _a[1];
|
|
58
|
+
var $pos = transaction.doc.resolve(step.from);
|
|
59
|
+
var li = parentNode($pos, function (n) { return n.type.name === options.listItem; });
|
|
60
|
+
if (li) {
|
|
61
|
+
var liStyles = parseStyle(li.node.attrs.style);
|
|
62
|
+
if (liStyles[name_1] && options.resetValues[name_1]) {
|
|
63
|
+
var newMark = mark.type.create({ style: name_1 + ": " + options.resetValues[name_1] + ";" });
|
|
64
|
+
transaction.addMark(step.from, step.to, newMark);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return transaction.docChanged ? transaction : undefined;
|
|
71
|
+
};
|
|
72
|
+
var DEFAULT_OPTIONS = {
|
|
73
|
+
listItem: 'list_item',
|
|
74
|
+
resetValues: {
|
|
75
|
+
'font-size': '',
|
|
76
|
+
'font-family': '',
|
|
77
|
+
'color': ''
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Returns a plugin which applies font-size, font-family, color styles to list item marker.
|
|
82
|
+
*/
|
|
83
|
+
export function listMarkersStyles(options) {
|
|
84
|
+
if (options === void 0) { options = DEFAULT_OPTIONS; }
|
|
85
|
+
return new Plugin({
|
|
86
|
+
key: new PluginKey('list-markers-styles'),
|
|
87
|
+
appendTransaction: function (transactions, _oldState, newState) {
|
|
88
|
+
var tr = transactions.slice().pop();
|
|
89
|
+
var commandName = tr.getMeta('commandName');
|
|
90
|
+
var transaction;
|
|
91
|
+
if (commandName === 'FontSize' || commandName === 'FontName' || commandName === 'ForeColor') {
|
|
92
|
+
transaction = applyToListItems(tr, newState, options);
|
|
93
|
+
}
|
|
94
|
+
else if (commandName === 'CleanFormatting') {
|
|
95
|
+
transaction = cleanListItems(tr, newState, options);
|
|
96
|
+
}
|
|
97
|
+
if (transaction) {
|
|
98
|
+
transaction.setMeta('addToHistory', true);
|
|
99
|
+
}
|
|
100
|
+
return transaction;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
@@ -4,8 +4,8 @@ import { TableMap } from 'prosemirror-tables';
|
|
|
4
4
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
5
5
|
import { colgroupAttr } from '../../config/constants';
|
|
6
6
|
import { TableView, TableWrapperView } from './table-view';
|
|
7
|
-
import { parseStyle } from './../../utils';
|
|
8
|
-
import { cellIndexes, domCellAround, otherResizeHandle, otherResizing, edgeCell,
|
|
7
|
+
import { parseStyle, setNodeStyle } from './../../utils';
|
|
8
|
+
import { cellIndexes, domCellAround, otherResizeHandle, otherResizing, edgeCell, tableColumnResizeKey as key } from './utils';
|
|
9
9
|
export function columnResizing() {
|
|
10
10
|
var handleWidth = 5, cellMinWidth = 25;
|
|
11
11
|
var plugin = new Plugin({
|
|
@@ -1,8 +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,
|
|
5
|
-
import { parseStyle } from './../../utils';
|
|
4
|
+
import { cellIndexes, domCellAround, otherResizeHandle, otherResizing, tableRowResizeKey as key, edgeCell } from './utils';
|
|
5
|
+
import { parseStyle, setNodeStyle } from './../../utils';
|
|
6
6
|
var TableRowView = /** @class */ (function () {
|
|
7
7
|
function TableRowView() {
|
|
8
8
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __assign } from "tslib";
|
|
2
2
|
import { NodeSelection, Plugin } from 'prosemirror-state';
|
|
3
3
|
import { colgroupAttr, dataResizeDirTable, resizableAttr } from '../../config/constants';
|
|
4
|
-
import { getTable,
|
|
5
|
-
import { parseStyle } from './../../utils';
|
|
4
|
+
import { getTable, tableResizeKey as key } from './utils';
|
|
5
|
+
import { parseStyle, setNodeStyle, parentNode } from './../../utils';
|
|
6
6
|
import { directions } from './../resize-utils';
|
|
7
7
|
var commonDir = {
|
|
8
8
|
'southeast': true,
|
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
1
|
import { PluginKey } from 'prosemirror-state';
|
|
3
2
|
import { TableMap } from 'prosemirror-tables';
|
|
4
|
-
import {
|
|
5
|
-
export var reAnyValue = /^.+$/;
|
|
6
|
-
export function setNodeStyle(nodeAttrs, styleType, value) {
|
|
7
|
-
var attrs;
|
|
8
|
-
if (new RegExp('[^-]?' + styleType + ':').test(nodeAttrs.style || '')) {
|
|
9
|
-
var style = changeStylesString(nodeAttrs.style || '', { style: styleType, value: reAnyValue, newValue: value }).style;
|
|
10
|
-
attrs = __assign(__assign({}, nodeAttrs), { style: style });
|
|
11
|
-
}
|
|
12
|
-
else if (nodeAttrs.style) {
|
|
13
|
-
attrs = __assign(__assign({}, nodeAttrs), { style: nodeAttrs.style.replace(/;$/, '') + '; ' + styleType + ': ' + value + ';' });
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
attrs = __assign(__assign({}, nodeAttrs), { style: styleType + ': ' + value + ';' });
|
|
17
|
-
}
|
|
18
|
-
return attrs;
|
|
19
|
-
}
|
|
3
|
+
import { parentNode } from '../../utils';
|
|
20
4
|
export var tableResizeKey = new PluginKey('table-resize');
|
|
21
5
|
export var tableColumnResizeKey = new PluginKey('table-column-resizing');
|
|
22
6
|
export var tableRowResizeKey = new PluginKey('table-row-resizing');
|
|
@@ -93,15 +77,6 @@ export function cellIndexes(dataCell) {
|
|
|
93
77
|
}
|
|
94
78
|
return result || { rowIndex: -1, cellIndex: -1 };
|
|
95
79
|
}
|
|
96
|
-
export function parentNode(pos, predicate) {
|
|
97
|
-
for (var depth = pos.depth; depth > 0; depth--) {
|
|
98
|
-
var node = pos.node(depth);
|
|
99
|
-
if (predicate(node)) {
|
|
100
|
-
return { node: node, depth: depth };
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
80
|
export function edgeCell(view, event, indexes) {
|
|
106
81
|
var found = view.posAtCoords({ left: event.clientX, top: event.clientY });
|
|
107
82
|
if (!found) {
|
package/dist/es/utils.js
CHANGED
|
@@ -22,6 +22,21 @@ export var changeStylesString = function (styleText, newStyle) {
|
|
|
22
22
|
changed: Boolean(newValue) || filtered.length !== styles.length
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
+
var reAnyValue = /^.+$/;
|
|
26
|
+
export function setNodeStyle(nodeAttrs, styleType, value) {
|
|
27
|
+
var attrs;
|
|
28
|
+
if (new RegExp('[^-]?' + styleType + ':').test(nodeAttrs.style || '')) {
|
|
29
|
+
var style = changeStylesString(nodeAttrs.style || '', { style: styleType, value: reAnyValue, newValue: value }).style;
|
|
30
|
+
attrs = __assign(__assign({}, nodeAttrs), { style: style });
|
|
31
|
+
}
|
|
32
|
+
else if (nodeAttrs.style) {
|
|
33
|
+
attrs = __assign(__assign({}, nodeAttrs), { style: nodeAttrs.style.replace(/;$/, '') + '; ' + styleType + ': ' + value + ';' });
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
attrs = __assign(__assign({}, nodeAttrs), { style: styleType + ': ' + value + ';' });
|
|
37
|
+
}
|
|
38
|
+
return attrs;
|
|
39
|
+
}
|
|
25
40
|
/**
|
|
26
41
|
* Determines if a given node type can be inserted at the current cursor position.
|
|
27
42
|
*/
|
|
@@ -59,6 +74,15 @@ export var findNthParentNodeOfType = function (nodeType, depth) {
|
|
|
59
74
|
return findNthParentNode(function (node) { return getTypeName(node) === getTypeName(nodeType); }, depth)(selection);
|
|
60
75
|
};
|
|
61
76
|
};
|
|
77
|
+
export function parentNode(pos, predicate) {
|
|
78
|
+
for (var depth = pos.depth; depth > 0; depth--) {
|
|
79
|
+
var node = pos.node(depth);
|
|
80
|
+
if (predicate(node)) {
|
|
81
|
+
return { node: node, depth: depth };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
62
86
|
var filterEmptyAttrs = function (attrs) {
|
|
63
87
|
var result = {};
|
|
64
88
|
for (var attr in attrs) {
|
|
@@ -240,6 +264,15 @@ export var parseStyle = function (styleText) {
|
|
|
240
264
|
}).reduce(function (acc, val) { return (__assign(__assign({}, acc), val)); }, {});
|
|
241
265
|
return styles;
|
|
242
266
|
};
|
|
267
|
+
export var applyStyle = function (styleText, styleType, styleValue) {
|
|
268
|
+
var styles = parseStyle(styleText);
|
|
269
|
+
styles[styleType] = styleValue;
|
|
270
|
+
var result = Object.keys(styles)
|
|
271
|
+
.map(function (name) { return styles[name] ? name + ": " + styles[name] : null; })
|
|
272
|
+
.filter(Boolean)
|
|
273
|
+
.join('; ');
|
|
274
|
+
return result ? result + ';' : null;
|
|
275
|
+
};
|
|
243
276
|
var setStyleAttr = function (element, styleString) {
|
|
244
277
|
var styles = parseStyle(styleString);
|
|
245
278
|
for (var style in styles) {
|
package/dist/es2015/main.js
CHANGED
|
@@ -26,6 +26,7 @@ export { textHighlight, textHighlightKey } from './plugins/highlight';
|
|
|
26
26
|
export { imageResizing, imageResizeKey } from './plugins/image-resize';
|
|
27
27
|
export { caretColor, caretColorKey } from './plugins/caret-color';
|
|
28
28
|
export { tableResizing, tableResizeKey, tableColumnResizeKey, tableRowResizeKey } from './plugins/table-resize';
|
|
29
|
+
export { listMarkersStyles } from './plugins/list-markers-styles';
|
|
29
30
|
// ProseMirror re-exports
|
|
30
31
|
export * from 'prosemirror-commands';
|
|
31
32
|
export * from 'prosemirror-dropcursor';
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
+
import { RemoveMarkStep } from 'prosemirror-transform';
|
|
3
|
+
import { parseStyle, applyStyle, parentNode } from '../utils';
|
|
4
|
+
const inSelection = (from, to, nodePos, node, doc) => {
|
|
5
|
+
const $from = doc.resolve(from);
|
|
6
|
+
const $to = doc.resolve(to);
|
|
7
|
+
const nodeName = node.type.name;
|
|
8
|
+
let wrapper, parentLi;
|
|
9
|
+
if (!$from.nodeBefore) {
|
|
10
|
+
wrapper = $from.node($from.depth);
|
|
11
|
+
parentLi = $from.node($from.depth - 1);
|
|
12
|
+
if (wrapper && parentLi && parentLi.firstChild === wrapper && parentLi.type.name === nodeName) {
|
|
13
|
+
return nodePos + node.content.size <= to;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (!$to.nodeAfter) {
|
|
17
|
+
wrapper = $to.node($to.depth);
|
|
18
|
+
parentLi = $to.node($to.depth - 1);
|
|
19
|
+
if (wrapper && parentLi && parentLi.lastChild === wrapper && parentLi.type.name === nodeName) {
|
|
20
|
+
return from <= nodePos;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return from <= nodePos && nodePos + node.content.size <= to;
|
|
24
|
+
};
|
|
25
|
+
const applyToListItems = (tr, state, options) => {
|
|
26
|
+
const { tr: transaction, doc, selection: { from, to } } = state;
|
|
27
|
+
const args = tr.getMeta('args');
|
|
28
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
29
|
+
if ((node.type.name === options.listItem) && inSelection(from, to, pos, node, doc)) {
|
|
30
|
+
transaction.setNodeMarkup(pos, null, Object.assign(Object.assign({}, node.attrs), { style: applyStyle(node.attrs.style, args.style, args.value) }));
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return transaction.docChanged ? transaction : undefined;
|
|
34
|
+
};
|
|
35
|
+
const cleanListItems = (tr, state, options) => {
|
|
36
|
+
const stylesToClean = Object.keys(options.resetValues);
|
|
37
|
+
const { tr: transaction, doc, selection: { from, to } } = state;
|
|
38
|
+
doc.nodesBetween(from, to, (node, pos, _parent) => {
|
|
39
|
+
if (node.type.name === options.listItem && inSelection(from, to, pos, node, doc)) {
|
|
40
|
+
let attrs = node.attrs;
|
|
41
|
+
const nodeStyles = parseStyle(node.attrs.style);
|
|
42
|
+
stylesToClean.forEach(style => {
|
|
43
|
+
if (nodeStyles[style]) {
|
|
44
|
+
attrs = Object.assign(Object.assign({}, attrs), { style: applyStyle(attrs.style, style, '') });
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
if (attrs !== node.attrs) {
|
|
48
|
+
transaction.setNodeMarkup(pos, null, attrs);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
tr.steps.forEach((step) => {
|
|
53
|
+
if (step instanceof RemoveMarkStep) {
|
|
54
|
+
const mark = step.mark;
|
|
55
|
+
if (mark.type.name === 'style' && mark.attrs.style) {
|
|
56
|
+
const [name, _value] = mark.attrs.style.split(/\s*:\s*/);
|
|
57
|
+
const $pos = transaction.doc.resolve(step.from);
|
|
58
|
+
const li = parentNode($pos, n => n.type.name === options.listItem);
|
|
59
|
+
if (li) {
|
|
60
|
+
const liStyles = parseStyle(li.node.attrs.style);
|
|
61
|
+
if (liStyles[name] && options.resetValues[name]) {
|
|
62
|
+
const newMark = mark.type.create({ style: `${name}: ${options.resetValues[name]};` });
|
|
63
|
+
transaction.addMark(step.from, step.to, newMark);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return transaction.docChanged ? transaction : undefined;
|
|
70
|
+
};
|
|
71
|
+
const DEFAULT_OPTIONS = {
|
|
72
|
+
listItem: 'list_item',
|
|
73
|
+
resetValues: {
|
|
74
|
+
'font-size': '',
|
|
75
|
+
'font-family': '',
|
|
76
|
+
'color': ''
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Returns a plugin which applies font-size, font-family, color styles to list item marker.
|
|
81
|
+
*/
|
|
82
|
+
export function listMarkersStyles(options = DEFAULT_OPTIONS) {
|
|
83
|
+
return new Plugin({
|
|
84
|
+
key: new PluginKey('list-markers-styles'),
|
|
85
|
+
appendTransaction: (transactions, _oldState, newState) => {
|
|
86
|
+
const tr = transactions.slice().pop();
|
|
87
|
+
const commandName = tr.getMeta('commandName');
|
|
88
|
+
let transaction;
|
|
89
|
+
if (commandName === 'FontSize' || commandName === 'FontName' || commandName === 'ForeColor') {
|
|
90
|
+
transaction = applyToListItems(tr, newState, options);
|
|
91
|
+
}
|
|
92
|
+
else if (commandName === 'CleanFormatting') {
|
|
93
|
+
transaction = cleanListItems(tr, newState, options);
|
|
94
|
+
}
|
|
95
|
+
if (transaction) {
|
|
96
|
+
transaction.setMeta('addToHistory', true);
|
|
97
|
+
}
|
|
98
|
+
return transaction;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
@@ -3,8 +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 { parseStyle } from './../../utils';
|
|
7
|
-
import { cellIndexes, domCellAround, otherResizeHandle, otherResizing, edgeCell,
|
|
6
|
+
import { parseStyle, setNodeStyle } from './../../utils';
|
|
7
|
+
import { cellIndexes, domCellAround, otherResizeHandle, otherResizing, edgeCell, tableColumnResizeKey as key } from './utils';
|
|
8
8
|
export function columnResizing() {
|
|
9
9
|
const handleWidth = 5, cellMinWidth = 25;
|
|
10
10
|
let plugin = new Plugin({
|
|
@@ -1,8 +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,
|
|
5
|
-
import { parseStyle } from './../../utils';
|
|
4
|
+
import { cellIndexes, domCellAround, otherResizeHandle, otherResizing, tableRowResizeKey as key, edgeCell } from './utils';
|
|
5
|
+
import { parseStyle, setNodeStyle } from './../../utils';
|
|
6
6
|
class TableRowView {
|
|
7
7
|
ignoreMutation(record) {
|
|
8
8
|
return record.type === 'attributes' && record.attributeName === 'style' && record.target.nodeName === 'TR';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NodeSelection, Plugin } from 'prosemirror-state';
|
|
2
2
|
import { colgroupAttr, dataResizeDirTable, resizableAttr } from '../../config/constants';
|
|
3
|
-
import { getTable,
|
|
4
|
-
import { parseStyle } from './../../utils';
|
|
3
|
+
import { getTable, tableResizeKey as key } from './utils';
|
|
4
|
+
import { parseStyle, setNodeStyle, parentNode } from './../../utils';
|
|
5
5
|
import { directions } from './../resize-utils';
|
|
6
6
|
const commonDir = {
|
|
7
7
|
'southeast': true,
|
|
@@ -1,21 +1,6 @@
|
|
|
1
1
|
import { PluginKey } from 'prosemirror-state';
|
|
2
2
|
import { TableMap } from 'prosemirror-tables';
|
|
3
|
-
import {
|
|
4
|
-
export const reAnyValue = /^.+$/;
|
|
5
|
-
export function setNodeStyle(nodeAttrs, styleType, value) {
|
|
6
|
-
let attrs;
|
|
7
|
-
if (new RegExp('[^-]?' + styleType + ':').test(nodeAttrs.style || '')) {
|
|
8
|
-
const { style } = changeStylesString(nodeAttrs.style || '', { style: styleType, value: reAnyValue, newValue: value });
|
|
9
|
-
attrs = Object.assign(Object.assign({}, nodeAttrs), { style });
|
|
10
|
-
}
|
|
11
|
-
else if (nodeAttrs.style) {
|
|
12
|
-
attrs = Object.assign(Object.assign({}, nodeAttrs), { style: nodeAttrs.style.replace(/;$/, '') + '; ' + styleType + ': ' + value + ';' });
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
attrs = Object.assign(Object.assign({}, nodeAttrs), { style: styleType + ': ' + value + ';' });
|
|
16
|
-
}
|
|
17
|
-
return attrs;
|
|
18
|
-
}
|
|
3
|
+
import { parentNode } from '../../utils';
|
|
19
4
|
export const tableResizeKey = new PluginKey('table-resize');
|
|
20
5
|
export const tableColumnResizeKey = new PluginKey('table-column-resizing');
|
|
21
6
|
export const tableRowResizeKey = new PluginKey('table-row-resizing');
|
|
@@ -87,15 +72,6 @@ export function cellIndexes(dataCell) {
|
|
|
87
72
|
}
|
|
88
73
|
return result || { rowIndex: -1, cellIndex: -1 };
|
|
89
74
|
}
|
|
90
|
-
export function parentNode(pos, predicate) {
|
|
91
|
-
for (let depth = pos.depth; depth > 0; depth--) {
|
|
92
|
-
let node = pos.node(depth);
|
|
93
|
-
if (predicate(node)) {
|
|
94
|
-
return { node, depth };
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
75
|
export function edgeCell(view, event, indexes) {
|
|
100
76
|
const found = view.posAtCoords({ left: event.clientX, top: event.clientY });
|
|
101
77
|
if (!found) {
|
package/dist/es2015/utils.js
CHANGED
|
@@ -21,6 +21,21 @@ export const changeStylesString = (styleText, newStyle) => {
|
|
|
21
21
|
changed: Boolean(newValue) || filtered.length !== styles.length
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
|
+
const reAnyValue = /^.+$/;
|
|
25
|
+
export function setNodeStyle(nodeAttrs, styleType, value) {
|
|
26
|
+
let attrs;
|
|
27
|
+
if (new RegExp('[^-]?' + styleType + ':').test(nodeAttrs.style || '')) {
|
|
28
|
+
const { style } = changeStylesString(nodeAttrs.style || '', { style: styleType, value: reAnyValue, newValue: value });
|
|
29
|
+
attrs = Object.assign(Object.assign({}, nodeAttrs), { style });
|
|
30
|
+
}
|
|
31
|
+
else if (nodeAttrs.style) {
|
|
32
|
+
attrs = Object.assign(Object.assign({}, nodeAttrs), { style: nodeAttrs.style.replace(/;$/, '') + '; ' + styleType + ': ' + value + ';' });
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
attrs = Object.assign(Object.assign({}, nodeAttrs), { style: styleType + ': ' + value + ';' });
|
|
36
|
+
}
|
|
37
|
+
return attrs;
|
|
38
|
+
}
|
|
24
39
|
/**
|
|
25
40
|
* Determines if a given node type can be inserted at the current cursor position.
|
|
26
41
|
*/
|
|
@@ -56,6 +71,15 @@ export const findNthParentNodeOfType = (nodeType, depth = 1) => {
|
|
|
56
71
|
return findNthParentNode((node) => getTypeName(node) === getTypeName(nodeType), depth)(selection);
|
|
57
72
|
};
|
|
58
73
|
};
|
|
74
|
+
export function parentNode(pos, predicate) {
|
|
75
|
+
for (let depth = pos.depth; depth > 0; depth--) {
|
|
76
|
+
let node = pos.node(depth);
|
|
77
|
+
if (predicate(node)) {
|
|
78
|
+
return { node, depth };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
59
83
|
const filterEmptyAttrs = (attrs) => {
|
|
60
84
|
const result = {};
|
|
61
85
|
for (let attr in attrs) {
|
|
@@ -233,6 +257,15 @@ export const parseStyle = (styleText) => {
|
|
|
233
257
|
}).reduce((acc, val) => (Object.assign(Object.assign({}, acc), val)), {});
|
|
234
258
|
return styles;
|
|
235
259
|
};
|
|
260
|
+
export const applyStyle = (styleText, styleType, styleValue) => {
|
|
261
|
+
const styles = parseStyle(styleText);
|
|
262
|
+
styles[styleType] = styleValue;
|
|
263
|
+
const result = Object.keys(styles)
|
|
264
|
+
.map(name => styles[name] ? `${name}: ${styles[name]}` : null)
|
|
265
|
+
.filter(Boolean)
|
|
266
|
+
.join('; ');
|
|
267
|
+
return result ? result + ';' : null;
|
|
268
|
+
};
|
|
236
269
|
const setStyleAttr = (element, styleString) => {
|
|
237
270
|
const styles = parseStyle(styleString);
|
|
238
271
|
for (let style in styles) {
|
package/dist/npm/main.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export { textHighlight, textHighlightKey, InlineDecoration } from './plugins/hig
|
|
|
28
28
|
export { imageResizing, imageResizeKey, ImageResizeOptions } from './plugins/image-resize';
|
|
29
29
|
export { caretColor, caretColorKey } from './plugins/caret-color';
|
|
30
30
|
export { tableResizing, tableResizeKey, tableColumnResizeKey, tableRowResizeKey } from './plugins/table-resize';
|
|
31
|
+
export { listMarkersStyles, ListMarkersStylesOptions } from './plugins/list-markers-styles';
|
|
31
32
|
export * from 'prosemirror-commands';
|
|
32
33
|
export * from 'prosemirror-dropcursor';
|
|
33
34
|
export * from 'prosemirror-gapcursor';
|
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 = exports.tableEditing = void 0;
|
|
4
|
+
exports.listMarkersStyles = 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 = exports.TableMap = 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; } });
|
|
@@ -131,6 +131,8 @@ Object.defineProperty(exports, "tableResizing", { enumerable: true, get: functio
|
|
|
131
131
|
Object.defineProperty(exports, "tableResizeKey", { enumerable: true, get: function () { return table_resize_1.tableResizeKey; } });
|
|
132
132
|
Object.defineProperty(exports, "tableColumnResizeKey", { enumerable: true, get: function () { return table_resize_1.tableColumnResizeKey; } });
|
|
133
133
|
Object.defineProperty(exports, "tableRowResizeKey", { enumerable: true, get: function () { return table_resize_1.tableRowResizeKey; } });
|
|
134
|
+
var list_markers_styles_1 = require("./plugins/list-markers-styles");
|
|
135
|
+
Object.defineProperty(exports, "listMarkersStyles", { enumerable: true, get: function () { return list_markers_styles_1.listMarkersStyles; } });
|
|
134
136
|
// ProseMirror re-exports
|
|
135
137
|
tslib_1.__exportStar(require("prosemirror-commands"), exports);
|
|
136
138
|
tslib_1.__exportStar(require("prosemirror-dropcursor"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
export interface ListMarkersStylesOptions {
|
|
3
|
+
listItem: string;
|
|
4
|
+
resetValues: {
|
|
5
|
+
'font-size': string;
|
|
6
|
+
'font-family': string;
|
|
7
|
+
'color': string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Returns a plugin which applies font-size, font-family, color styles to list item marker.
|
|
12
|
+
*/
|
|
13
|
+
export declare function listMarkersStyles(options?: ListMarkersStylesOptions): Plugin;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listMarkersStyles = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var prosemirror_state_1 = require("prosemirror-state");
|
|
6
|
+
var prosemirror_transform_1 = require("prosemirror-transform");
|
|
7
|
+
var utils_1 = require("../utils");
|
|
8
|
+
var inSelection = function (from, to, nodePos, node, doc) {
|
|
9
|
+
var $from = doc.resolve(from);
|
|
10
|
+
var $to = doc.resolve(to);
|
|
11
|
+
var nodeName = node.type.name;
|
|
12
|
+
var wrapper, parentLi;
|
|
13
|
+
if (!$from.nodeBefore) {
|
|
14
|
+
wrapper = $from.node($from.depth);
|
|
15
|
+
parentLi = $from.node($from.depth - 1);
|
|
16
|
+
if (wrapper && parentLi && parentLi.firstChild === wrapper && parentLi.type.name === nodeName) {
|
|
17
|
+
return nodePos + node.content.size <= to;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (!$to.nodeAfter) {
|
|
21
|
+
wrapper = $to.node($to.depth);
|
|
22
|
+
parentLi = $to.node($to.depth - 1);
|
|
23
|
+
if (wrapper && parentLi && parentLi.lastChild === wrapper && parentLi.type.name === nodeName) {
|
|
24
|
+
return from <= nodePos;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return from <= nodePos && nodePos + node.content.size <= to;
|
|
28
|
+
};
|
|
29
|
+
var applyToListItems = function (tr, state, options) {
|
|
30
|
+
var transaction = state.tr, doc = state.doc, _a = state.selection, from = _a.from, to = _a.to;
|
|
31
|
+
var args = tr.getMeta('args');
|
|
32
|
+
doc.nodesBetween(from, to, function (node, pos) {
|
|
33
|
+
if ((node.type.name === options.listItem) && inSelection(from, to, pos, node, doc)) {
|
|
34
|
+
transaction.setNodeMarkup(pos, null, tslib_1.__assign(tslib_1.__assign({}, node.attrs), { style: utils_1.applyStyle(node.attrs.style, args.style, args.value) }));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return transaction.docChanged ? transaction : undefined;
|
|
38
|
+
};
|
|
39
|
+
var cleanListItems = function (tr, state, options) {
|
|
40
|
+
var stylesToClean = Object.keys(options.resetValues);
|
|
41
|
+
var transaction = state.tr, doc = state.doc, _a = state.selection, from = _a.from, to = _a.to;
|
|
42
|
+
doc.nodesBetween(from, to, function (node, pos, _parent) {
|
|
43
|
+
if (node.type.name === options.listItem && inSelection(from, to, pos, node, doc)) {
|
|
44
|
+
var attrs_1 = node.attrs;
|
|
45
|
+
var nodeStyles_1 = utils_1.parseStyle(node.attrs.style);
|
|
46
|
+
stylesToClean.forEach(function (style) {
|
|
47
|
+
if (nodeStyles_1[style]) {
|
|
48
|
+
attrs_1 = tslib_1.__assign(tslib_1.__assign({}, attrs_1), { style: utils_1.applyStyle(attrs_1.style, style, '') });
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
if (attrs_1 !== node.attrs) {
|
|
52
|
+
transaction.setNodeMarkup(pos, null, attrs_1);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
tr.steps.forEach(function (step) {
|
|
57
|
+
if (step instanceof prosemirror_transform_1.RemoveMarkStep) {
|
|
58
|
+
var mark = step.mark;
|
|
59
|
+
if (mark.type.name === 'style' && mark.attrs.style) {
|
|
60
|
+
var _a = mark.attrs.style.split(/\s*:\s*/), name_1 = _a[0], _value = _a[1];
|
|
61
|
+
var $pos = transaction.doc.resolve(step.from);
|
|
62
|
+
var li = utils_1.parentNode($pos, function (n) { return n.type.name === options.listItem; });
|
|
63
|
+
if (li) {
|
|
64
|
+
var liStyles = utils_1.parseStyle(li.node.attrs.style);
|
|
65
|
+
if (liStyles[name_1] && options.resetValues[name_1]) {
|
|
66
|
+
var newMark = mark.type.create({ style: name_1 + ": " + options.resetValues[name_1] + ";" });
|
|
67
|
+
transaction.addMark(step.from, step.to, newMark);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return transaction.docChanged ? transaction : undefined;
|
|
74
|
+
};
|
|
75
|
+
var DEFAULT_OPTIONS = {
|
|
76
|
+
listItem: 'list_item',
|
|
77
|
+
resetValues: {
|
|
78
|
+
'font-size': '',
|
|
79
|
+
'font-family': '',
|
|
80
|
+
'color': ''
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Returns a plugin which applies font-size, font-family, color styles to list item marker.
|
|
85
|
+
*/
|
|
86
|
+
function listMarkersStyles(options) {
|
|
87
|
+
if (options === void 0) { options = DEFAULT_OPTIONS; }
|
|
88
|
+
return new prosemirror_state_1.Plugin({
|
|
89
|
+
key: new prosemirror_state_1.PluginKey('list-markers-styles'),
|
|
90
|
+
appendTransaction: function (transactions, _oldState, newState) {
|
|
91
|
+
var tr = transactions.slice().pop();
|
|
92
|
+
var commandName = tr.getMeta('commandName');
|
|
93
|
+
var transaction;
|
|
94
|
+
if (commandName === 'FontSize' || commandName === 'FontName' || commandName === 'ForeColor') {
|
|
95
|
+
transaction = applyToListItems(tr, newState, options);
|
|
96
|
+
}
|
|
97
|
+
else if (commandName === 'CleanFormatting') {
|
|
98
|
+
transaction = cleanListItems(tr, newState, options);
|
|
99
|
+
}
|
|
100
|
+
if (transaction) {
|
|
101
|
+
transaction.setMeta('addToHistory', true);
|
|
102
|
+
}
|
|
103
|
+
return transaction;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
exports.listMarkersStyles = listMarkersStyles;
|