@progress/kendo-react-editor 5.1.0-dev.202202101059 → 5.1.0-dev.202202180916
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-react-editor.js +1 -1
- package/dist/es/Editor.js +2 -1
- package/dist/es/package-metadata.js +1 -1
- package/dist/es/tools/lists-styled.js +7 -247
- package/dist/es/tools/main.js +1 -1
- package/dist/npm/Editor.js +1 -0
- package/dist/npm/package-metadata.js +1 -1
- package/dist/npm/tools/lists-styled.js +8 -248
- package/dist/npm/tools/main.js +1 -1
- package/dist/systemjs/kendo-react-editor.js +1 -1
- package/package.json +13 -13
package/dist/es/Editor.js
CHANGED
|
@@ -26,7 +26,7 @@ import * as React from 'react';
|
|
|
26
26
|
import * as PropTypes from 'prop-types';
|
|
27
27
|
import { ButtonGroup, Toolbar, ToolbarSeparator } from '@progress/kendo-react-buttons';
|
|
28
28
|
import { classNames } from '@progress/kendo-react-common';
|
|
29
|
-
import { EditorState, Plugin, PluginKey, EditorView, Schema, baseKeymap, keymap, history, dropCursor, gapCursor, getMark, spacesFix, tableEditing } from '@progress/kendo-editor-common';
|
|
29
|
+
import { EditorState, Plugin, PluginKey, EditorView, Schema, baseKeymap, keymap, history, dropCursor, gapCursor, getMark, spacesFix, tableEditing, caretColor } from '@progress/kendo-editor-common';
|
|
30
30
|
import { marks, nodes } from './config/schema';
|
|
31
31
|
import { defaultStyle, tablesStyles, rtlStyles } from './config/defaultStyles';
|
|
32
32
|
import { EditorToolsSettings } from './config/toolsSettings';
|
|
@@ -324,6 +324,7 @@ var Editor = /** @class */ (function (_super) {
|
|
|
324
324
|
}
|
|
325
325
|
}),
|
|
326
326
|
spacesFix(),
|
|
327
|
+
caretColor(),
|
|
327
328
|
history(),
|
|
328
329
|
dropCursor(),
|
|
329
330
|
gapCursor(),
|
|
@@ -5,7 +5,7 @@ export var packageMetadata = {
|
|
|
5
5
|
name: '@progress/kendo-react-editor',
|
|
6
6
|
productName: 'KendoReact',
|
|
7
7
|
productCodes: ['KENDOUIREACT', 'KENDOUICOMPLETE'],
|
|
8
|
-
publishDate:
|
|
8
|
+
publishDate: 1645175078,
|
|
9
9
|
version: '',
|
|
10
10
|
licensingDocsUrl: 'https://www.telerik.com/kendo-react-ui/my-license/?utm_medium=product&utm_source=kendoreact&utm_campaign=kendo-ui-react-purchase-license-keys-warning'
|
|
11
11
|
};
|
|
@@ -10,238 +10,9 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
12
|
import * as React from 'react';
|
|
13
|
-
import {
|
|
13
|
+
import { toggleList, listStyle } from '@progress/kendo-editor-common';
|
|
14
14
|
import { SplitButton } from '@progress/kendo-react-buttons';
|
|
15
15
|
import { listsTypes } from './../config/toolsSettings';
|
|
16
|
-
var rootListDepth = function (pos, nodes) {
|
|
17
|
-
// Get the depth of the nearest ancestor list
|
|
18
|
-
var bulletList = nodes.bulletList, orderedList = nodes.orderedList, listItem = nodes.listItem;
|
|
19
|
-
var depth;
|
|
20
|
-
for (var i = pos.depth - 1; i > 0; i--) {
|
|
21
|
-
var node = pos.node(i);
|
|
22
|
-
if (node.type === bulletList || node.type === orderedList) {
|
|
23
|
-
depth = i;
|
|
24
|
-
}
|
|
25
|
-
if (node.type !== bulletList && node.type !== orderedList && node.type !== listItem) {
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return depth;
|
|
30
|
-
};
|
|
31
|
-
var getListLiftTarget = function (schema, resPos, options) {
|
|
32
|
-
// This will return (depth - 1) for root list parent of a list.
|
|
33
|
-
var target = resPos.depth;
|
|
34
|
-
var bulletList = schema.nodes[options.bulletList];
|
|
35
|
-
var orderedList = schema.nodes[options.orderedList];
|
|
36
|
-
var listItem = schema.nodes[options.listItem];
|
|
37
|
-
for (var i = resPos.depth; i > 0; i--) {
|
|
38
|
-
var node = resPos.node(i);
|
|
39
|
-
if (node.type === bulletList || node.type === orderedList) {
|
|
40
|
-
target = i;
|
|
41
|
-
}
|
|
42
|
-
if (node.type !== bulletList && node.type !== orderedList && node.type !== listItem) {
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return target - 1;
|
|
47
|
-
};
|
|
48
|
-
function liftSelectionList(state, tr, options) {
|
|
49
|
-
// The function will list paragraphs in selection out to level 1 below root list.
|
|
50
|
-
var _a = state.selection, from = _a.from, to = _a.to;
|
|
51
|
-
var _b = state.schema.nodes, paragraph = _b.paragraph, heading = _b.heading;
|
|
52
|
-
var listCol = [];
|
|
53
|
-
tr.doc.nodesBetween(from, to, function (node, pos) {
|
|
54
|
-
if (node.type === paragraph || node.type === heading) {
|
|
55
|
-
listCol.push({ node: node, pos: pos });
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
for (var i = listCol.length - 1; i >= 0; i--) {
|
|
59
|
-
var block = listCol[i];
|
|
60
|
-
var start = tr.doc.resolve(tr.mapping.map(block.pos));
|
|
61
|
-
if (start.depth > 0) {
|
|
62
|
-
var end = void 0;
|
|
63
|
-
if (block.node.textContent && block.node.textContent.length > 0) {
|
|
64
|
-
end = tr.doc.resolve(tr.mapping.map(block.pos + block.node.textContent.length));
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
end = tr.doc.resolve(tr.mapping.map(block.pos + 1));
|
|
68
|
-
}
|
|
69
|
-
var range = start.blockRange(end);
|
|
70
|
-
if (range) {
|
|
71
|
-
tr.lift(range, getListLiftTarget(state.schema, start, options));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return tr;
|
|
76
|
-
}
|
|
77
|
-
function toggleListCommand(options) {
|
|
78
|
-
return function (state, dispatch, view) {
|
|
79
|
-
if (!view) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
state = view.state;
|
|
83
|
-
var listNode = state.schema.nodes[options.listType];
|
|
84
|
-
var _a = state.selection, $from = _a.$from, $to = _a.$to;
|
|
85
|
-
var parent = $from.node(-2);
|
|
86
|
-
var grandgrandParent = $from.node(-3);
|
|
87
|
-
var isRangeOfSingleType = isRangeOfType(state.doc, $from, $to, listNode);
|
|
88
|
-
if (((parent && parent.type === listNode) ||
|
|
89
|
-
(grandgrandParent && grandgrandParent.type === listNode)) &&
|
|
90
|
-
isRangeOfSingleType) {
|
|
91
|
-
// Untoggles list
|
|
92
|
-
return liftListItems(options)(state, dispatch);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
// Wraps selection in list and converts list type e.g. bullet_list -> ordered_list if needed
|
|
96
|
-
if (!isRangeOfSingleType) {
|
|
97
|
-
liftListItems(options)(state, dispatch);
|
|
98
|
-
state = view.state;
|
|
99
|
-
}
|
|
100
|
-
return wrapInList(listNode, options.listAttrs)(state, dispatch);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
function liftListItem(state, selection, tr, nodeType) {
|
|
105
|
-
var listItemNodeType = nodeType || state.schema.nodes.listItem;
|
|
106
|
-
var $from = selection.$from, $to = selection.$to;
|
|
107
|
-
var range = $from.blockRange($to, function (node) { return node.childCount && node.firstChild.type === listItemNodeType; });
|
|
108
|
-
if (!range || range.depth < 2 || $from.node(range.depth - 1).type !== listItemNodeType) {
|
|
109
|
-
return tr;
|
|
110
|
-
}
|
|
111
|
-
var end = range.end;
|
|
112
|
-
var endOfList = $to.end(range.depth);
|
|
113
|
-
if (end < endOfList) {
|
|
114
|
-
tr.step(new ReplaceAroundStep(end - 1, endOfList, end, endOfList, new Slice(Fragment.from(listItemNodeType.create(undefined, range.parent.copy())), 1, 0), 1, true));
|
|
115
|
-
range = new NodeRange(tr.doc.resolve($from.pos), tr.doc.resolve(endOfList), range.depth);
|
|
116
|
-
}
|
|
117
|
-
return tr.lift(range, liftTarget(range)).scrollIntoView();
|
|
118
|
-
}
|
|
119
|
-
function liftFollowingList(state, from, to, rootListDepthNum, tr, listItem) {
|
|
120
|
-
// Function will lift list item following selection to level-1.
|
|
121
|
-
if (!listItem) {
|
|
122
|
-
listItem = state.schema.nodes.listItem;
|
|
123
|
-
}
|
|
124
|
-
var lifted = false;
|
|
125
|
-
tr.doc.nodesBetween(from, to, function (node, pos) {
|
|
126
|
-
if (!lifted && node.type === listItem && pos > from) {
|
|
127
|
-
lifted = true;
|
|
128
|
-
var listDepth = rootListDepthNum + 3;
|
|
129
|
-
while (listDepth > rootListDepthNum + 2) {
|
|
130
|
-
var start = tr.doc.resolve(tr.mapping.map(pos));
|
|
131
|
-
listDepth = start.depth;
|
|
132
|
-
var end = tr.doc.resolve(tr.mapping.map(pos + node.textContent.length));
|
|
133
|
-
var sel = new TextSelection(start, end);
|
|
134
|
-
tr = liftListItem(state, sel, tr, listItem);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
return tr;
|
|
139
|
-
}
|
|
140
|
-
function isRangeOfType(doc, $from, $to, nodeType) {
|
|
141
|
-
// Step through block-nodes between $from and $to and returns false if a node is
|
|
142
|
-
// found that isn't of the specified type
|
|
143
|
-
return getAncestorNodesBetween(doc, $from, $to).filter(function (node) { return node.type !== nodeType; }).length === 0;
|
|
144
|
-
}
|
|
145
|
-
function getAncestorNodesBetween(doc, $from, $to) {
|
|
146
|
-
// Returns all top-level ancestor-nodes between $from and $to
|
|
147
|
-
var nodes = Array();
|
|
148
|
-
var maxDepth = findAncestorPosition(doc, $from).depth;
|
|
149
|
-
var current = doc.resolve($from.start(maxDepth));
|
|
150
|
-
while (current.pos <= $to.start($to.depth)) {
|
|
151
|
-
var depth = Math.min(current.depth, maxDepth);
|
|
152
|
-
var node = current.node(depth);
|
|
153
|
-
if (node) {
|
|
154
|
-
nodes.push(node);
|
|
155
|
-
}
|
|
156
|
-
if (depth === 0) {
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
var next = doc.resolve(current.after(depth));
|
|
160
|
-
if (next.start(depth) >= doc.nodeSize - 2) {
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
if (next.depth !== current.depth) {
|
|
164
|
-
next = doc.resolve(next.pos + 2);
|
|
165
|
-
}
|
|
166
|
-
if (next.depth) {
|
|
167
|
-
current = doc.resolve(next.start(next.depth));
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
current = doc.resolve(next.end(next.depth));
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return nodes;
|
|
174
|
-
}
|
|
175
|
-
function findAncestorPosition(doc, pos) {
|
|
176
|
-
// Traverse the document until an "ancestor" is found. Any nestable block can be an ancestor.
|
|
177
|
-
var nestableBlocks = ['blockquote', 'bulletList', 'orderedList'];
|
|
178
|
-
if (pos.depth === 1) {
|
|
179
|
-
return pos;
|
|
180
|
-
}
|
|
181
|
-
var node = pos.node(pos.depth);
|
|
182
|
-
var newPos = pos;
|
|
183
|
-
while (pos.depth >= 1) {
|
|
184
|
-
pos = doc.resolve(pos.before(pos.depth));
|
|
185
|
-
node = pos.node(pos.depth);
|
|
186
|
-
if (node && nestableBlocks.indexOf(node.type.name) !== -1) {
|
|
187
|
-
newPos = pos;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return newPos;
|
|
191
|
-
}
|
|
192
|
-
function liftListItems(options) {
|
|
193
|
-
return function (state, dispatch) {
|
|
194
|
-
var tr = state.tr;
|
|
195
|
-
var _a = state.selection, $from = _a.$from, $to = _a.$to;
|
|
196
|
-
tr.doc.nodesBetween($from.pos, $to.pos, function (node, pos) {
|
|
197
|
-
// Following condition will ensure that block types `paragraph`, `heading`, `codeBlock`, `blockquote`, `div` are lifted.
|
|
198
|
-
// isTextblock is true for paragraph, heading, codeBlock.
|
|
199
|
-
if (node.isTextblock || node.type.name === 'blockquote' || node.type.name === 'div') {
|
|
200
|
-
var sel = new NodeSelection(tr.doc.resolve(tr.mapping.map(pos)));
|
|
201
|
-
var range = sel.$from.blockRange(sel.$to);
|
|
202
|
-
if (!range || sel.$from.parent.type !== state.schema.nodes[options.listItem]) {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
var target = range && liftTarget(range);
|
|
206
|
-
if (target === undefined || target === null) {
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
tr.lift(range, target);
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
if (dispatch) {
|
|
213
|
-
dispatch(tr);
|
|
214
|
-
}
|
|
215
|
-
return true;
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
function wrapInList(nodeType, attrs) {
|
|
219
|
-
if (attrs === void 0) { attrs = {}; }
|
|
220
|
-
return autoJoin(pmWrapInList(nodeType, attrs), function (before, after) { return before.type === after.type && before.type === nodeType; });
|
|
221
|
-
}
|
|
222
|
-
var toggleList = function (state, dispatch, view, options, command) {
|
|
223
|
-
var listType = options.listType;
|
|
224
|
-
var selection = state.selection;
|
|
225
|
-
var fromNode = selection.$from.node(selection.$from.depth - 2);
|
|
226
|
-
var endNode = selection.$to.node(selection.$to.depth - 2);
|
|
227
|
-
if (!fromNode || fromNode.type.name !== listType || (!endNode || endNode.type.name !== listType)) {
|
|
228
|
-
return toggleListCommand(options)(state, dispatch, view);
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
var nodes = view.state.schema.nodes;
|
|
232
|
-
var listNodes = {
|
|
233
|
-
bulletList: nodes[options.bulletList],
|
|
234
|
-
orderedList: nodes[options.orderedList],
|
|
235
|
-
listItem: nodes[options.listItem]
|
|
236
|
-
};
|
|
237
|
-
var depth = rootListDepth(selection.$to, listNodes);
|
|
238
|
-
var tr = liftFollowingList(state, selection.$to.pos, selection.$to.end(depth), depth, view.state.tr, listNodes.listItem);
|
|
239
|
-
tr = liftSelectionList(state, tr, options);
|
|
240
|
-
tr.setMeta('commandName', command);
|
|
241
|
-
dispatch(tr);
|
|
242
|
-
return true;
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
16
|
var parentNode = function (state, nodeType) {
|
|
246
17
|
var _a = state.selection, from = _a.from, to = _a.to;
|
|
247
18
|
var result = null;
|
|
@@ -251,12 +22,6 @@ var parentNode = function (state, nodeType) {
|
|
|
251
22
|
});
|
|
252
23
|
return result;
|
|
253
24
|
};
|
|
254
|
-
var reListStyle = /list\-style\-type:\s?([\w-]+)/;
|
|
255
|
-
var getListStyle = function (node) {
|
|
256
|
-
var style = node.attrs.style;
|
|
257
|
-
var listStyle = reListStyle.exec(style);
|
|
258
|
-
return (listStyle && listStyle[1]) || '';
|
|
259
|
-
};
|
|
260
25
|
/**
|
|
261
26
|
* @hidden
|
|
262
27
|
*/
|
|
@@ -272,12 +37,7 @@ export var ListTool = function (props) {
|
|
|
272
37
|
var nodes = state && state.schema.nodes;
|
|
273
38
|
ol = nodes && parentNode(state, nodes[types.orderedList]);
|
|
274
39
|
ul = nodes && parentNode(state, nodes[types.bulletList]);
|
|
275
|
-
|
|
276
|
-
isActive = Boolean(ol && !ul);
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
isActive = Boolean(!ol && ul);
|
|
280
|
-
}
|
|
40
|
+
isActive = Boolean(listType === types.orderedList ? (ol && !ul) : (!ol && ul));
|
|
281
41
|
}
|
|
282
42
|
var onButtonClick = function (_event) {
|
|
283
43
|
if (view) {
|
|
@@ -289,9 +49,9 @@ export var ListTool = function (props) {
|
|
|
289
49
|
if (view) {
|
|
290
50
|
var listAttrs = event.item.style ? { style: 'list-style-type: ' + event.item.style + ';' } : {};
|
|
291
51
|
var currentList = ol || ul;
|
|
292
|
-
if (currentList &&
|
|
52
|
+
if (currentList && listStyle(currentList.attrs) !== event.item.style) {
|
|
293
53
|
var pos = view.state.selection.$head.posAtIndex(0, -2) - 1;
|
|
294
|
-
view.dispatch(view.state.tr.setNodeMarkup(pos, view.state.schema.nodes[listType],
|
|
54
|
+
view.dispatch(view.state.tr.setNodeMarkup(pos, view.state.schema.nodes[listType], listAttrs));
|
|
295
55
|
}
|
|
296
56
|
else {
|
|
297
57
|
toggleList(view.state, view.dispatch, view, __assign({ listType: listType }, types, { listAttrs: listAttrs }), 'InsertList');
|
|
@@ -300,9 +60,9 @@ export var ListTool = function (props) {
|
|
|
300
60
|
}
|
|
301
61
|
};
|
|
302
62
|
if (isActive && (ol || ul)) {
|
|
303
|
-
var listStyleType_1 =
|
|
304
|
-
items =
|
|
63
|
+
var listStyleType_1 = listStyle((ol || ul).attrs);
|
|
64
|
+
items = items.map(function (item, index) { return (__assign({}, item, { selected: listStyleType_1 ? item.style === listStyleType_1 : index === 0 })); });
|
|
305
65
|
}
|
|
306
66
|
return (React.createElement("span", { onMouseDown: function (e) { e.preventDefault(); } },
|
|
307
|
-
React.createElement(SplitButton, { textField: "text", items: items, icon: props.icon, onButtonClick: onButtonClick, onItemClick: onItemClick, buttonClass: isActive ? 'k-
|
|
67
|
+
React.createElement(SplitButton, { textField: "text", items: items, icon: props.icon, onButtonClick: onButtonClick, onItemClick: onItemClick, buttonClass: isActive ? 'k-selected' : undefined })));
|
|
308
68
|
};
|
package/dist/es/tools/main.js
CHANGED
|
@@ -412,7 +412,7 @@ export var EditorTools;
|
|
|
412
412
|
EditorTools.BulletedList = function (props) {
|
|
413
413
|
var ulItems = [
|
|
414
414
|
{ icon: 'list-unordered', text: 'Disc', style: 'disc' },
|
|
415
|
-
// { icon: 'list-unordered-
|
|
415
|
+
// { icon: 'list-unordered-outline', text: 'Circle', style: 'circle' },
|
|
416
416
|
{ icon: 'list-unordered-square', text: 'Square', style: 'square' }
|
|
417
417
|
];
|
|
418
418
|
return (React.createElement(ListTool, __assign({ listType: EditorToolsSettings.bulletList.listType, items: ulItems, icon: "list-unordered" }, props)));
|
package/dist/npm/Editor.js
CHANGED
|
@@ -326,6 +326,7 @@ var Editor = /** @class */ (function (_super) {
|
|
|
326
326
|
}
|
|
327
327
|
}),
|
|
328
328
|
kendo_editor_common_1.spacesFix(),
|
|
329
|
+
kendo_editor_common_1.caretColor(),
|
|
329
330
|
kendo_editor_common_1.history(),
|
|
330
331
|
kendo_editor_common_1.dropCursor(),
|
|
331
332
|
kendo_editor_common_1.gapCursor(),
|
|
@@ -7,7 +7,7 @@ exports.packageMetadata = {
|
|
|
7
7
|
name: '@progress/kendo-react-editor',
|
|
8
8
|
productName: 'KendoReact',
|
|
9
9
|
productCodes: ['KENDOUIREACT', 'KENDOUICOMPLETE'],
|
|
10
|
-
publishDate:
|
|
10
|
+
publishDate: 1645175078,
|
|
11
11
|
version: '',
|
|
12
12
|
licensingDocsUrl: 'https://www.telerik.com/kendo-react-ui/my-license/?utm_medium=product&utm_source=kendoreact&utm_campaign=kendo-ui-react-purchase-license-keys-warning'
|
|
13
13
|
};
|
|
@@ -15,235 +15,6 @@ var React = require("react");
|
|
|
15
15
|
var kendo_editor_common_1 = require("@progress/kendo-editor-common");
|
|
16
16
|
var kendo_react_buttons_1 = require("@progress/kendo-react-buttons");
|
|
17
17
|
var toolsSettings_1 = require("./../config/toolsSettings");
|
|
18
|
-
var rootListDepth = function (pos, nodes) {
|
|
19
|
-
// Get the depth of the nearest ancestor list
|
|
20
|
-
var bulletList = nodes.bulletList, orderedList = nodes.orderedList, listItem = nodes.listItem;
|
|
21
|
-
var depth;
|
|
22
|
-
for (var i = pos.depth - 1; i > 0; i--) {
|
|
23
|
-
var node = pos.node(i);
|
|
24
|
-
if (node.type === bulletList || node.type === orderedList) {
|
|
25
|
-
depth = i;
|
|
26
|
-
}
|
|
27
|
-
if (node.type !== bulletList && node.type !== orderedList && node.type !== listItem) {
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return depth;
|
|
32
|
-
};
|
|
33
|
-
var getListLiftTarget = function (schema, resPos, options) {
|
|
34
|
-
// This will return (depth - 1) for root list parent of a list.
|
|
35
|
-
var target = resPos.depth;
|
|
36
|
-
var bulletList = schema.nodes[options.bulletList];
|
|
37
|
-
var orderedList = schema.nodes[options.orderedList];
|
|
38
|
-
var listItem = schema.nodes[options.listItem];
|
|
39
|
-
for (var i = resPos.depth; i > 0; i--) {
|
|
40
|
-
var node = resPos.node(i);
|
|
41
|
-
if (node.type === bulletList || node.type === orderedList) {
|
|
42
|
-
target = i;
|
|
43
|
-
}
|
|
44
|
-
if (node.type !== bulletList && node.type !== orderedList && node.type !== listItem) {
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return target - 1;
|
|
49
|
-
};
|
|
50
|
-
function liftSelectionList(state, tr, options) {
|
|
51
|
-
// The function will list paragraphs in selection out to level 1 below root list.
|
|
52
|
-
var _a = state.selection, from = _a.from, to = _a.to;
|
|
53
|
-
var _b = state.schema.nodes, paragraph = _b.paragraph, heading = _b.heading;
|
|
54
|
-
var listCol = [];
|
|
55
|
-
tr.doc.nodesBetween(from, to, function (node, pos) {
|
|
56
|
-
if (node.type === paragraph || node.type === heading) {
|
|
57
|
-
listCol.push({ node: node, pos: pos });
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
for (var i = listCol.length - 1; i >= 0; i--) {
|
|
61
|
-
var block = listCol[i];
|
|
62
|
-
var start = tr.doc.resolve(tr.mapping.map(block.pos));
|
|
63
|
-
if (start.depth > 0) {
|
|
64
|
-
var end = void 0;
|
|
65
|
-
if (block.node.textContent && block.node.textContent.length > 0) {
|
|
66
|
-
end = tr.doc.resolve(tr.mapping.map(block.pos + block.node.textContent.length));
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
end = tr.doc.resolve(tr.mapping.map(block.pos + 1));
|
|
70
|
-
}
|
|
71
|
-
var range = start.blockRange(end);
|
|
72
|
-
if (range) {
|
|
73
|
-
tr.lift(range, getListLiftTarget(state.schema, start, options));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return tr;
|
|
78
|
-
}
|
|
79
|
-
function toggleListCommand(options) {
|
|
80
|
-
return function (state, dispatch, view) {
|
|
81
|
-
if (!view) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
state = view.state;
|
|
85
|
-
var listNode = state.schema.nodes[options.listType];
|
|
86
|
-
var _a = state.selection, $from = _a.$from, $to = _a.$to;
|
|
87
|
-
var parent = $from.node(-2);
|
|
88
|
-
var grandgrandParent = $from.node(-3);
|
|
89
|
-
var isRangeOfSingleType = isRangeOfType(state.doc, $from, $to, listNode);
|
|
90
|
-
if (((parent && parent.type === listNode) ||
|
|
91
|
-
(grandgrandParent && grandgrandParent.type === listNode)) &&
|
|
92
|
-
isRangeOfSingleType) {
|
|
93
|
-
// Untoggles list
|
|
94
|
-
return liftListItems(options)(state, dispatch);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
// Wraps selection in list and converts list type e.g. bullet_list -> ordered_list if needed
|
|
98
|
-
if (!isRangeOfSingleType) {
|
|
99
|
-
liftListItems(options)(state, dispatch);
|
|
100
|
-
state = view.state;
|
|
101
|
-
}
|
|
102
|
-
return wrapInList(listNode, options.listAttrs)(state, dispatch);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
function liftListItem(state, selection, tr, nodeType) {
|
|
107
|
-
var listItemNodeType = nodeType || state.schema.nodes.listItem;
|
|
108
|
-
var $from = selection.$from, $to = selection.$to;
|
|
109
|
-
var range = $from.blockRange($to, function (node) { return node.childCount && node.firstChild.type === listItemNodeType; });
|
|
110
|
-
if (!range || range.depth < 2 || $from.node(range.depth - 1).type !== listItemNodeType) {
|
|
111
|
-
return tr;
|
|
112
|
-
}
|
|
113
|
-
var end = range.end;
|
|
114
|
-
var endOfList = $to.end(range.depth);
|
|
115
|
-
if (end < endOfList) {
|
|
116
|
-
tr.step(new kendo_editor_common_1.ReplaceAroundStep(end - 1, endOfList, end, endOfList, new kendo_editor_common_1.Slice(kendo_editor_common_1.Fragment.from(listItemNodeType.create(undefined, range.parent.copy())), 1, 0), 1, true));
|
|
117
|
-
range = new kendo_editor_common_1.NodeRange(tr.doc.resolve($from.pos), tr.doc.resolve(endOfList), range.depth);
|
|
118
|
-
}
|
|
119
|
-
return tr.lift(range, kendo_editor_common_1.liftTarget(range)).scrollIntoView();
|
|
120
|
-
}
|
|
121
|
-
function liftFollowingList(state, from, to, rootListDepthNum, tr, listItem) {
|
|
122
|
-
// Function will lift list item following selection to level-1.
|
|
123
|
-
if (!listItem) {
|
|
124
|
-
listItem = state.schema.nodes.listItem;
|
|
125
|
-
}
|
|
126
|
-
var lifted = false;
|
|
127
|
-
tr.doc.nodesBetween(from, to, function (node, pos) {
|
|
128
|
-
if (!lifted && node.type === listItem && pos > from) {
|
|
129
|
-
lifted = true;
|
|
130
|
-
var listDepth = rootListDepthNum + 3;
|
|
131
|
-
while (listDepth > rootListDepthNum + 2) {
|
|
132
|
-
var start = tr.doc.resolve(tr.mapping.map(pos));
|
|
133
|
-
listDepth = start.depth;
|
|
134
|
-
var end = tr.doc.resolve(tr.mapping.map(pos + node.textContent.length));
|
|
135
|
-
var sel = new kendo_editor_common_1.TextSelection(start, end);
|
|
136
|
-
tr = liftListItem(state, sel, tr, listItem);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
return tr;
|
|
141
|
-
}
|
|
142
|
-
function isRangeOfType(doc, $from, $to, nodeType) {
|
|
143
|
-
// Step through block-nodes between $from and $to and returns false if a node is
|
|
144
|
-
// found that isn't of the specified type
|
|
145
|
-
return getAncestorNodesBetween(doc, $from, $to).filter(function (node) { return node.type !== nodeType; }).length === 0;
|
|
146
|
-
}
|
|
147
|
-
function getAncestorNodesBetween(doc, $from, $to) {
|
|
148
|
-
// Returns all top-level ancestor-nodes between $from and $to
|
|
149
|
-
var nodes = Array();
|
|
150
|
-
var maxDepth = findAncestorPosition(doc, $from).depth;
|
|
151
|
-
var current = doc.resolve($from.start(maxDepth));
|
|
152
|
-
while (current.pos <= $to.start($to.depth)) {
|
|
153
|
-
var depth = Math.min(current.depth, maxDepth);
|
|
154
|
-
var node = current.node(depth);
|
|
155
|
-
if (node) {
|
|
156
|
-
nodes.push(node);
|
|
157
|
-
}
|
|
158
|
-
if (depth === 0) {
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
var next = doc.resolve(current.after(depth));
|
|
162
|
-
if (next.start(depth) >= doc.nodeSize - 2) {
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
if (next.depth !== current.depth) {
|
|
166
|
-
next = doc.resolve(next.pos + 2);
|
|
167
|
-
}
|
|
168
|
-
if (next.depth) {
|
|
169
|
-
current = doc.resolve(next.start(next.depth));
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
current = doc.resolve(next.end(next.depth));
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return nodes;
|
|
176
|
-
}
|
|
177
|
-
function findAncestorPosition(doc, pos) {
|
|
178
|
-
// Traverse the document until an "ancestor" is found. Any nestable block can be an ancestor.
|
|
179
|
-
var nestableBlocks = ['blockquote', 'bulletList', 'orderedList'];
|
|
180
|
-
if (pos.depth === 1) {
|
|
181
|
-
return pos;
|
|
182
|
-
}
|
|
183
|
-
var node = pos.node(pos.depth);
|
|
184
|
-
var newPos = pos;
|
|
185
|
-
while (pos.depth >= 1) {
|
|
186
|
-
pos = doc.resolve(pos.before(pos.depth));
|
|
187
|
-
node = pos.node(pos.depth);
|
|
188
|
-
if (node && nestableBlocks.indexOf(node.type.name) !== -1) {
|
|
189
|
-
newPos = pos;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return newPos;
|
|
193
|
-
}
|
|
194
|
-
function liftListItems(options) {
|
|
195
|
-
return function (state, dispatch) {
|
|
196
|
-
var tr = state.tr;
|
|
197
|
-
var _a = state.selection, $from = _a.$from, $to = _a.$to;
|
|
198
|
-
tr.doc.nodesBetween($from.pos, $to.pos, function (node, pos) {
|
|
199
|
-
// Following condition will ensure that block types `paragraph`, `heading`, `codeBlock`, `blockquote`, `div` are lifted.
|
|
200
|
-
// isTextblock is true for paragraph, heading, codeBlock.
|
|
201
|
-
if (node.isTextblock || node.type.name === 'blockquote' || node.type.name === 'div') {
|
|
202
|
-
var sel = new kendo_editor_common_1.NodeSelection(tr.doc.resolve(tr.mapping.map(pos)));
|
|
203
|
-
var range = sel.$from.blockRange(sel.$to);
|
|
204
|
-
if (!range || sel.$from.parent.type !== state.schema.nodes[options.listItem]) {
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
var target = range && kendo_editor_common_1.liftTarget(range);
|
|
208
|
-
if (target === undefined || target === null) {
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
tr.lift(range, target);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
if (dispatch) {
|
|
215
|
-
dispatch(tr);
|
|
216
|
-
}
|
|
217
|
-
return true;
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
function wrapInList(nodeType, attrs) {
|
|
221
|
-
if (attrs === void 0) { attrs = {}; }
|
|
222
|
-
return kendo_editor_common_1.autoJoin(kendo_editor_common_1.wrapInList(nodeType, attrs), function (before, after) { return before.type === after.type && before.type === nodeType; });
|
|
223
|
-
}
|
|
224
|
-
var toggleList = function (state, dispatch, view, options, command) {
|
|
225
|
-
var listType = options.listType;
|
|
226
|
-
var selection = state.selection;
|
|
227
|
-
var fromNode = selection.$from.node(selection.$from.depth - 2);
|
|
228
|
-
var endNode = selection.$to.node(selection.$to.depth - 2);
|
|
229
|
-
if (!fromNode || fromNode.type.name !== listType || (!endNode || endNode.type.name !== listType)) {
|
|
230
|
-
return toggleListCommand(options)(state, dispatch, view);
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
var nodes = view.state.schema.nodes;
|
|
234
|
-
var listNodes = {
|
|
235
|
-
bulletList: nodes[options.bulletList],
|
|
236
|
-
orderedList: nodes[options.orderedList],
|
|
237
|
-
listItem: nodes[options.listItem]
|
|
238
|
-
};
|
|
239
|
-
var depth = rootListDepth(selection.$to, listNodes);
|
|
240
|
-
var tr = liftFollowingList(state, selection.$to.pos, selection.$to.end(depth), depth, view.state.tr, listNodes.listItem);
|
|
241
|
-
tr = liftSelectionList(state, tr, options);
|
|
242
|
-
tr.setMeta('commandName', command);
|
|
243
|
-
dispatch(tr);
|
|
244
|
-
return true;
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
18
|
var parentNode = function (state, nodeType) {
|
|
248
19
|
var _a = state.selection, from = _a.from, to = _a.to;
|
|
249
20
|
var result = null;
|
|
@@ -253,12 +24,6 @@ var parentNode = function (state, nodeType) {
|
|
|
253
24
|
});
|
|
254
25
|
return result;
|
|
255
26
|
};
|
|
256
|
-
var reListStyle = /list\-style\-type:\s?([\w-]+)/;
|
|
257
|
-
var getListStyle = function (node) {
|
|
258
|
-
var style = node.attrs.style;
|
|
259
|
-
var listStyle = reListStyle.exec(style);
|
|
260
|
-
return (listStyle && listStyle[1]) || '';
|
|
261
|
-
};
|
|
262
27
|
/**
|
|
263
28
|
* @hidden
|
|
264
29
|
*/
|
|
@@ -274,16 +39,11 @@ exports.ListTool = function (props) {
|
|
|
274
39
|
var nodes = state && state.schema.nodes;
|
|
275
40
|
ol = nodes && parentNode(state, nodes[types.orderedList]);
|
|
276
41
|
ul = nodes && parentNode(state, nodes[types.bulletList]);
|
|
277
|
-
|
|
278
|
-
isActive = Boolean(ol && !ul);
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
isActive = Boolean(!ol && ul);
|
|
282
|
-
}
|
|
42
|
+
isActive = Boolean(listType === types.orderedList ? (ol && !ul) : (!ol && ul));
|
|
283
43
|
}
|
|
284
44
|
var onButtonClick = function (_event) {
|
|
285
45
|
if (view) {
|
|
286
|
-
toggleList(view.state, view.dispatch, view, __assign({ listType: listType }, types, { listAttrs: {} }), 'InsertList');
|
|
46
|
+
kendo_editor_common_1.toggleList(view.state, view.dispatch, view, __assign({ listType: listType }, types, { listAttrs: {} }), 'InsertList');
|
|
287
47
|
view.focus();
|
|
288
48
|
}
|
|
289
49
|
};
|
|
@@ -291,20 +51,20 @@ exports.ListTool = function (props) {
|
|
|
291
51
|
if (view) {
|
|
292
52
|
var listAttrs = event.item.style ? { style: 'list-style-type: ' + event.item.style + ';' } : {};
|
|
293
53
|
var currentList = ol || ul;
|
|
294
|
-
if (currentList &&
|
|
54
|
+
if (currentList && kendo_editor_common_1.listStyle(currentList.attrs) !== event.item.style) {
|
|
295
55
|
var pos = view.state.selection.$head.posAtIndex(0, -2) - 1;
|
|
296
|
-
view.dispatch(view.state.tr.setNodeMarkup(pos, view.state.schema.nodes[listType],
|
|
56
|
+
view.dispatch(view.state.tr.setNodeMarkup(pos, view.state.schema.nodes[listType], listAttrs));
|
|
297
57
|
}
|
|
298
58
|
else {
|
|
299
|
-
toggleList(view.state, view.dispatch, view, __assign({ listType: listType }, types, { listAttrs: listAttrs }), 'InsertList');
|
|
59
|
+
kendo_editor_common_1.toggleList(view.state, view.dispatch, view, __assign({ listType: listType }, types, { listAttrs: listAttrs }), 'InsertList');
|
|
300
60
|
}
|
|
301
61
|
view.focus();
|
|
302
62
|
}
|
|
303
63
|
};
|
|
304
64
|
if (isActive && (ol || ul)) {
|
|
305
|
-
var listStyleType_1 =
|
|
306
|
-
items =
|
|
65
|
+
var listStyleType_1 = kendo_editor_common_1.listStyle((ol || ul).attrs);
|
|
66
|
+
items = items.map(function (item, index) { return (__assign({}, item, { selected: listStyleType_1 ? item.style === listStyleType_1 : index === 0 })); });
|
|
307
67
|
}
|
|
308
68
|
return (React.createElement("span", { onMouseDown: function (e) { e.preventDefault(); } },
|
|
309
|
-
React.createElement(kendo_react_buttons_1.SplitButton, { textField: "text", items: items, icon: props.icon, onButtonClick: onButtonClick, onItemClick: onItemClick, buttonClass: isActive ? 'k-
|
|
69
|
+
React.createElement(kendo_react_buttons_1.SplitButton, { textField: "text", items: items, icon: props.icon, onButtonClick: onButtonClick, onItemClick: onItemClick, buttonClass: isActive ? 'k-selected' : undefined })));
|
|
310
70
|
};
|
package/dist/npm/tools/main.js
CHANGED
|
@@ -414,7 +414,7 @@ var EditorTools;
|
|
|
414
414
|
EditorTools.BulletedList = function (props) {
|
|
415
415
|
var ulItems = [
|
|
416
416
|
{ icon: 'list-unordered', text: 'Disc', style: 'disc' },
|
|
417
|
-
// { icon: 'list-unordered-
|
|
417
|
+
// { icon: 'list-unordered-outline', text: 'Circle', style: 'circle' },
|
|
418
418
|
{ icon: 'list-unordered-square', text: 'Square', style: 'square' }
|
|
419
419
|
];
|
|
420
420
|
return (React.createElement(lists_styled_1.ListTool, __assign({ listType: toolsSettings_1.EditorToolsSettings.bulletList.listType, items: ulItems, icon: "list-unordered" }, props)));
|