@progress/kendo-editor-common 1.7.2-dev.202202071127 → 1.8.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.
@@ -19,12 +19,12 @@ const rootListDepth = (pos, nodes) => {
19
19
  }
20
20
  return depth;
21
21
  };
22
- const getListLiftTarget = (schema, resPos, listNodeNames) => {
22
+ const getListLiftTarget = (schema, resPos, options) => {
23
23
  // This will return (depth - 1) for root list parent of a list.
24
24
  let target = resPos.depth;
25
- const bulletList = schema.nodes[listNodeNames.bulletList];
26
- const orderedList = schema.nodes[listNodeNames.orderedList];
27
- const listItem = schema.nodes[listNodeNames.listItem];
25
+ const bulletList = schema.nodes[options.bulletList];
26
+ const orderedList = schema.nodes[options.orderedList];
27
+ const listItem = schema.nodes[options.listItem];
28
28
  for (let i = resPos.depth; i > 0; i--) {
29
29
  const node = resPos.node(i);
30
30
  if (node.type === bulletList || node.type === orderedList) {
@@ -36,7 +36,7 @@ const getListLiftTarget = (schema, resPos, listNodeNames) => {
36
36
  }
37
37
  return target - 1;
38
38
  };
39
- function liftSelectionList(state, tr, listNodeNames) {
39
+ function liftSelectionList(state, tr, options) {
40
40
  // The function will list paragraphs in selection out to level 1 below root list.
41
41
  const { from, to } = state.selection;
42
42
  const { paragraph, heading } = state.schema.nodes;
@@ -59,19 +59,19 @@ function liftSelectionList(state, tr, listNodeNames) {
59
59
  }
60
60
  const range = start.blockRange(end);
61
61
  if (range) {
62
- tr.lift(range, getListLiftTarget(state.schema, start, listNodeNames));
62
+ tr.lift(range, getListLiftTarget(state.schema, start, options));
63
63
  }
64
64
  }
65
65
  }
66
66
  return tr;
67
67
  }
68
- function toggleListCommand(listNodeNames) {
68
+ function toggleListCommand(options) {
69
69
  return function (state, dispatch, view) {
70
70
  if (!view) {
71
71
  return false;
72
72
  }
73
73
  state = view.state;
74
- const listNode = state.schema.nodes[listNodeNames.listType];
74
+ const listNode = state.schema.nodes[options.listType];
75
75
  const { $from, $to } = state.selection;
76
76
  const parent = $from.node(-2);
77
77
  const grandgrandParent = $from.node(-3);
@@ -80,31 +80,29 @@ function toggleListCommand(listNodeNames) {
80
80
  (grandgrandParent && grandgrandParent.type === listNode)) &&
81
81
  isRangeOfSingleType) {
82
82
  // Untoggles list
83
- return liftListItems(listNodeNames)(state, dispatch);
83
+ return liftListItems(options)(state, dispatch);
84
84
  }
85
85
  else {
86
86
  // Wraps selection in list and converts list type e.g. bullet_list -> ordered_list if needed
87
87
  if (!isRangeOfSingleType) {
88
- liftListItems(listNodeNames)(state, dispatch);
88
+ liftListItems(options)(state, dispatch);
89
89
  state = view.state;
90
90
  }
91
- return wrapInList(listNode)(state, dispatch);
91
+ return wrapInList(listNode, options.listAttrs)(state, dispatch);
92
92
  }
93
93
  };
94
94
  }
95
95
  function liftListItem(state, selection, tr, nodeType) {
96
- if (!nodeType) {
97
- nodeType = state.schema.nodes.listItem;
98
- }
96
+ const listItemNodeType = nodeType || state.schema.nodes.listItem;
99
97
  let { $from, $to } = selection;
100
- let range = $from.blockRange($to, node => node.childCount && node.firstChild.type === nodeType);
101
- if (!range || range.depth < 2 || $from.node(range.depth - 1).type !== nodeType) {
98
+ let range = $from.blockRange($to, node => node.childCount && node.firstChild.type === listItemNodeType);
99
+ if (!range || range.depth < 2 || $from.node(range.depth - 1).type !== listItemNodeType) {
102
100
  return tr;
103
101
  }
104
102
  let end = range.end;
105
103
  let endOfList = $to.end(range.depth);
106
104
  if (end < endOfList) {
107
- tr.step(new ReplaceAroundStep(end - 1, endOfList, end, endOfList, new Slice(Fragment.from(nodeType.create(undefined, range.parent.copy())), 1, 0), 1, true));
105
+ tr.step(new ReplaceAroundStep(end - 1, endOfList, end, endOfList, new Slice(Fragment.from(listItemNodeType.create(undefined, range.parent.copy())), 1, 0), 1, true));
108
106
  range = new NodeRange(tr.doc.resolve($from.pos), tr.doc.resolve(endOfList), range.depth);
109
107
  }
110
108
  return tr.lift(range, liftTarget(range)).scrollIntoView();
@@ -182,7 +180,7 @@ function findAncestorPosition(doc, pos) {
182
180
  }
183
181
  return newPos;
184
182
  }
185
- function liftListItems(listNodeNames) {
183
+ function liftListItems(options) {
186
184
  return function (state, dispatch) {
187
185
  const { tr } = state;
188
186
  const { $from, $to } = state.selection;
@@ -192,7 +190,7 @@ function liftListItems(listNodeNames) {
192
190
  if (node.isTextblock || node.type.name === 'blockquote' || node.type.name === 'div') {
193
191
  const sel = new NodeSelection(tr.doc.resolve(tr.mapping.map(pos)));
194
192
  const range = sel.$from.blockRange(sel.$to);
195
- if (!range || sel.$from.parent.type !== state.schema.nodes[listNodeNames.listItem]) {
193
+ if (!range || sel.$from.parent.type !== state.schema.nodes[options.listItem]) {
196
194
  return false;
197
195
  }
198
196
  const target = range && liftTarget(range);
@@ -208,27 +206,39 @@ function liftListItems(listNodeNames) {
208
206
  return true;
209
207
  };
210
208
  }
211
- function wrapInList(nodeType) {
212
- return autoJoin(pmWrapInList(nodeType), (before, after) => before.type === after.type && before.type === nodeType);
209
+ function wrapInList(nodeType, attrs = {}) {
210
+ return autoJoin(pmWrapInList(nodeType, attrs), (before, after) => before.type === after.type && before.type === nodeType);
213
211
  }
214
- export const toggleList = (state, dispatch, view, listNodeNames, command) => {
215
- const { listType } = listNodeNames;
212
+ const reListStyle = /list\-style\-type:\s?([\w-]+)/;
213
+ /**
214
+ * Extracts list-style-type style from node's attributes.
215
+ * @param attrs - The attributes of the list node
216
+ * @returns The extracted list-style-type.
217
+ */
218
+ export const listStyle = (attrs) => {
219
+ const styleAttr = attrs.style || '';
220
+ const execArray = reListStyle.exec(styleAttr);
221
+ return (execArray && execArray[1]) || '';
222
+ };
223
+ export const toggleList = (state, dispatch, view, options, command) => {
224
+ const { listType, listAttrs = { style: null } } = options;
216
225
  const { selection } = state;
217
226
  const fromNode = selection.$from.node(selection.$from.depth - 2);
218
227
  const endNode = selection.$to.node(selection.$to.depth - 2);
219
- if (!fromNode || fromNode.type.name !== listType || (!endNode || endNode.type.name !== listType)) {
220
- return toggleListCommand(listNodeNames)(state, dispatch, view);
228
+ if (!fromNode || fromNode.type.name !== listType || listStyle(fromNode.attrs) !== listStyle(listAttrs) ||
229
+ (!endNode || endNode.type.name !== listType || listStyle(endNode.attrs) !== listStyle(listAttrs))) {
230
+ return toggleListCommand(options)(state, dispatch, view);
221
231
  }
222
232
  else {
223
233
  const nodes = view.state.schema.nodes;
224
234
  const listNodes = {
225
- bulletList: nodes[listNodeNames.bulletList],
226
- orderedList: nodes[listNodeNames.orderedList],
227
- listItem: nodes[listNodeNames.listItem]
235
+ bulletList: nodes[options.bulletList],
236
+ orderedList: nodes[options.orderedList],
237
+ listItem: nodes[options.listItem]
228
238
  };
229
239
  const depth = rootListDepth(selection.$to, listNodes);
230
240
  let tr = liftFollowingList(state, selection.$to.pos, selection.$to.end(depth), depth, view.state.tr, listNodes.listItem);
231
- tr = liftSelectionList(state, tr, listNodeNames);
241
+ tr = liftSelectionList(state, tr, options);
232
242
  tr.setMeta('commandName', command);
233
243
  dispatch(tr);
234
244
  return true;
@@ -8,7 +8,7 @@ export { cleanFormatting } from './cleanFormatting';
8
8
  export { hasNode, activeNode, formatBlockElements, getBlockFormats, parentBlockFormat, changeTextBlock, blockNodes, cleanTextBlockFormatting } from './blockNode';
9
9
  export { hasMark, getMark, getActiveMarks, removeAllMarks, cleanMarks, selectionMarks } from './mark';
10
10
  export { indent, canIndentAsListItem, outdent, canOutdentAsListItem, isIndented, canBeIndented, indentBlocks } from './indent';
11
- export { toggleOrderedList, toggleUnorderedList, toggleList } from './lists';
11
+ export { toggleOrderedList, toggleUnorderedList, toggleList, listStyle } from './lists';
12
12
  export { blockquote, liftBlockquote } from './blockquote';
13
13
  export { hasSameMarkup, getSelectionText, getNodeFromSelection, selectedLineTextOnly, expandSelection, expandToWordWrap, canInsert, insertNode, indentHtml } from './utils';
14
14
  export { alignLeftRules, alignCenterRules, alignRightRules, alignJustifyRules, alignRemoveRules } from './config/align-rules';
@@ -23,6 +23,7 @@ export { placeholder } from './plugins/placeholder';
23
23
  export { spacesFix } from './plugins/spaces-fix';
24
24
  export { textHighlight, textHighlightKey } from './plugins/highlight';
25
25
  export { imageResizing, imageResizeKey } from './plugins/image-resize';
26
+ export { caretColor, caretColorKey } from './plugins/caret-color';
26
27
  // ProseMirror re-exports
27
28
  export * from 'prosemirror-commands';
28
29
  export * from 'prosemirror-dropcursor';
@@ -0,0 +1,31 @@
1
+ import { Plugin, PluginKey } from 'prosemirror-state';
2
+ import { Decoration, DecorationSet } from "prosemirror-view";
3
+ import { styleValue } from './../mark';
4
+ export const caretColorKey = new PluginKey('caret-color');
5
+ export function caretColor() {
6
+ return new Plugin({
7
+ key: caretColorKey,
8
+ props: {
9
+ decorations: (state) => {
10
+ const { doc, selection, storedMarks } = state;
11
+ if (!selection.empty || !storedMarks) {
12
+ return DecorationSet.empty;
13
+ }
14
+ const color = styleValue((storedMarks || []).find((m) => m.type.name === 'style'), { name: 'color', value: /^.+$/ });
15
+ if (!color) {
16
+ return DecorationSet.empty;
17
+ }
18
+ const parentNode = selection.$anchor.parent;
19
+ const decorations = [];
20
+ doc.descendants((node, pos) => {
21
+ if (node.eq(parentNode)) {
22
+ decorations.push(Decoration.node(pos, pos + node.nodeSize, {
23
+ style: 'caret-color: ' + color
24
+ }));
25
+ }
26
+ });
27
+ return DecorationSet.create(doc, decorations);
28
+ }
29
+ }
30
+ });
31
+ }
@@ -2,13 +2,22 @@ import { NodeType, Schema } from 'prosemirror-model';
2
2
  import { EditorState, Transaction } from 'prosemirror-state';
3
3
  import { EditorView } from 'prosemirror-view';
4
4
  import { Command } from './types/command';
5
- declare type ListNodeNames = {
5
+ declare type ListOptions = {
6
6
  listType: string;
7
7
  orderedList: string;
8
8
  bulletList: string;
9
9
  listItem: string;
10
+ listAttrs?: any;
10
11
  };
11
- export declare const toggleList: (state: EditorState<any>, dispatch: (tr: Transaction<any>) => void, view: EditorView<any>, listNodeNames: ListNodeNames, command?: string) => boolean;
12
+ /**
13
+ * Extracts list-style-type style from node's attributes.
14
+ * @param attrs - The attributes of the list node
15
+ * @returns The extracted list-style-type.
16
+ */
17
+ export declare const listStyle: (attrs: {
18
+ [key: string]: any;
19
+ }) => string;
20
+ export declare const toggleList: (state: EditorState<any>, dispatch: (tr: Transaction<any>) => void, view: EditorView<any>, options: ListOptions, command?: string) => boolean;
12
21
  export declare function toggleUnorderedList(state: EditorState, dispatch: (tr: Transaction) => void, view: EditorView): any;
13
22
  export declare function toggleOrderedList(state: EditorState, dispatch: (tr: Transaction) => void, view: EditorView): any;
14
23
  export declare const splitListItemKeepMarks: (itemType: NodeType<Schema<any, any>>) => Command;
package/dist/npm/lists.js CHANGED
@@ -22,12 +22,12 @@ var rootListDepth = function (pos, nodes) {
22
22
  }
23
23
  return depth;
24
24
  };
25
- var getListLiftTarget = function (schema, resPos, listNodeNames) {
25
+ var getListLiftTarget = function (schema, resPos, options) {
26
26
  // This will return (depth - 1) for root list parent of a list.
27
27
  var target = resPos.depth;
28
- var bulletList = schema.nodes[listNodeNames.bulletList];
29
- var orderedList = schema.nodes[listNodeNames.orderedList];
30
- var listItem = schema.nodes[listNodeNames.listItem];
28
+ var bulletList = schema.nodes[options.bulletList];
29
+ var orderedList = schema.nodes[options.orderedList];
30
+ var listItem = schema.nodes[options.listItem];
31
31
  for (var i = resPos.depth; i > 0; i--) {
32
32
  var node = resPos.node(i);
33
33
  if (node.type === bulletList || node.type === orderedList) {
@@ -39,7 +39,7 @@ var getListLiftTarget = function (schema, resPos, listNodeNames) {
39
39
  }
40
40
  return target - 1;
41
41
  };
42
- function liftSelectionList(state, tr, listNodeNames) {
42
+ function liftSelectionList(state, tr, options) {
43
43
  // The function will list paragraphs in selection out to level 1 below root list.
44
44
  var _a = state.selection, from = _a.from, to = _a.to;
45
45
  var _b = state.schema.nodes, paragraph = _b.paragraph, heading = _b.heading;
@@ -62,19 +62,19 @@ function liftSelectionList(state, tr, listNodeNames) {
62
62
  }
63
63
  var range = start.blockRange(end);
64
64
  if (range) {
65
- tr.lift(range, getListLiftTarget(state.schema, start, listNodeNames));
65
+ tr.lift(range, getListLiftTarget(state.schema, start, options));
66
66
  }
67
67
  }
68
68
  }
69
69
  return tr;
70
70
  }
71
- function toggleListCommand(listNodeNames) {
71
+ function toggleListCommand(options) {
72
72
  return function (state, dispatch, view) {
73
73
  if (!view) {
74
74
  return false;
75
75
  }
76
76
  state = view.state;
77
- var listNode = state.schema.nodes[listNodeNames.listType];
77
+ var listNode = state.schema.nodes[options.listType];
78
78
  var _a = state.selection, $from = _a.$from, $to = _a.$to;
79
79
  var parent = $from.node(-2);
80
80
  var grandgrandParent = $from.node(-3);
@@ -83,31 +83,29 @@ function toggleListCommand(listNodeNames) {
83
83
  (grandgrandParent && grandgrandParent.type === listNode)) &&
84
84
  isRangeOfSingleType) {
85
85
  // Untoggles list
86
- return liftListItems(listNodeNames)(state, dispatch);
86
+ return liftListItems(options)(state, dispatch);
87
87
  }
88
88
  else {
89
89
  // Wraps selection in list and converts list type e.g. bullet_list -> ordered_list if needed
90
90
  if (!isRangeOfSingleType) {
91
- liftListItems(listNodeNames)(state, dispatch);
91
+ liftListItems(options)(state, dispatch);
92
92
  state = view.state;
93
93
  }
94
- return wrapInList(listNode)(state, dispatch);
94
+ return wrapInList(listNode, options.listAttrs)(state, dispatch);
95
95
  }
96
96
  };
97
97
  }
98
98
  function liftListItem(state, selection, tr, nodeType) {
99
- if (!nodeType) {
100
- nodeType = state.schema.nodes.listItem;
101
- }
99
+ var listItemNodeType = nodeType || state.schema.nodes.listItem;
102
100
  var $from = selection.$from, $to = selection.$to;
103
- var range = $from.blockRange($to, function (node) { return node.childCount && node.firstChild.type === nodeType; });
104
- if (!range || range.depth < 2 || $from.node(range.depth - 1).type !== nodeType) {
101
+ var range = $from.blockRange($to, function (node) { return node.childCount && node.firstChild.type === listItemNodeType; });
102
+ if (!range || range.depth < 2 || $from.node(range.depth - 1).type !== listItemNodeType) {
105
103
  return tr;
106
104
  }
107
105
  var end = range.end;
108
106
  var endOfList = $to.end(range.depth);
109
107
  if (end < endOfList) {
110
- tr.step(new prosemirror_transform_1.ReplaceAroundStep(end - 1, endOfList, end, endOfList, new prosemirror_model_1.Slice(prosemirror_model_1.Fragment.from(nodeType.create(undefined, range.parent.copy())), 1, 0), 1, true));
108
+ tr.step(new prosemirror_transform_1.ReplaceAroundStep(end - 1, endOfList, end, endOfList, new prosemirror_model_1.Slice(prosemirror_model_1.Fragment.from(listItemNodeType.create(undefined, range.parent.copy())), 1, 0), 1, true));
111
109
  range = new prosemirror_model_1.NodeRange(tr.doc.resolve($from.pos), tr.doc.resolve(endOfList), range.depth);
112
110
  }
113
111
  return tr.lift(range, prosemirror_transform_1.liftTarget(range)).scrollIntoView();
@@ -185,7 +183,7 @@ function findAncestorPosition(doc, pos) {
185
183
  }
186
184
  return newPos;
187
185
  }
188
- function liftListItems(listNodeNames) {
186
+ function liftListItems(options) {
189
187
  return function (state, dispatch) {
190
188
  var tr = state.tr;
191
189
  var _a = state.selection, $from = _a.$from, $to = _a.$to;
@@ -195,7 +193,7 @@ function liftListItems(listNodeNames) {
195
193
  if (node.isTextblock || node.type.name === 'blockquote' || node.type.name === 'div') {
196
194
  var sel = new prosemirror_state_1.NodeSelection(tr.doc.resolve(tr.mapping.map(pos)));
197
195
  var range = sel.$from.blockRange(sel.$to);
198
- if (!range || sel.$from.parent.type !== state.schema.nodes[listNodeNames.listItem]) {
196
+ if (!range || sel.$from.parent.type !== state.schema.nodes[options.listItem]) {
199
197
  return false;
200
198
  }
201
199
  var target = range && prosemirror_transform_1.liftTarget(range);
@@ -211,27 +209,40 @@ function liftListItems(listNodeNames) {
211
209
  return true;
212
210
  };
213
211
  }
214
- function wrapInList(nodeType) {
215
- return prosemirror_commands_1.autoJoin(prosemirror_schema_list_1.wrapInList(nodeType), function (before, after) { return before.type === after.type && before.type === nodeType; });
212
+ function wrapInList(nodeType, attrs) {
213
+ if (attrs === void 0) { attrs = {}; }
214
+ return prosemirror_commands_1.autoJoin(prosemirror_schema_list_1.wrapInList(nodeType, attrs), function (before, after) { return before.type === after.type && before.type === nodeType; });
216
215
  }
217
- exports.toggleList = function (state, dispatch, view, listNodeNames, command) {
218
- var listType = listNodeNames.listType;
216
+ var reListStyle = /list\-style\-type:\s?([\w-]+)/;
217
+ /**
218
+ * Extracts list-style-type style from node's attributes.
219
+ * @param attrs - The attributes of the list node
220
+ * @returns The extracted list-style-type.
221
+ */
222
+ exports.listStyle = function (attrs) {
223
+ var styleAttr = attrs.style || '';
224
+ var execArray = reListStyle.exec(styleAttr);
225
+ return (execArray && execArray[1]) || '';
226
+ };
227
+ exports.toggleList = function (state, dispatch, view, options, command) {
228
+ var listType = options.listType, _a = options.listAttrs, listAttrs = _a === void 0 ? { style: null } : _a;
219
229
  var selection = state.selection;
220
230
  var fromNode = selection.$from.node(selection.$from.depth - 2);
221
231
  var endNode = selection.$to.node(selection.$to.depth - 2);
222
- if (!fromNode || fromNode.type.name !== listType || (!endNode || endNode.type.name !== listType)) {
223
- return toggleListCommand(listNodeNames)(state, dispatch, view);
232
+ if (!fromNode || fromNode.type.name !== listType || exports.listStyle(fromNode.attrs) !== exports.listStyle(listAttrs) ||
233
+ (!endNode || endNode.type.name !== listType || exports.listStyle(endNode.attrs) !== exports.listStyle(listAttrs))) {
234
+ return toggleListCommand(options)(state, dispatch, view);
224
235
  }
225
236
  else {
226
237
  var nodes = view.state.schema.nodes;
227
238
  var listNodes = {
228
- bulletList: nodes[listNodeNames.bulletList],
229
- orderedList: nodes[listNodeNames.orderedList],
230
- listItem: nodes[listNodeNames.listItem]
239
+ bulletList: nodes[options.bulletList],
240
+ orderedList: nodes[options.orderedList],
241
+ listItem: nodes[options.listItem]
231
242
  };
232
243
  var depth = rootListDepth(selection.$to, listNodes);
233
244
  var tr = liftFollowingList(state, selection.$to.pos, selection.$to.end(depth), depth, view.state.tr, listNodes.listItem);
234
- tr = liftSelectionList(state, tr, listNodeNames);
245
+ tr = liftSelectionList(state, tr, options);
235
246
  tr.setMeta('commandName', command);
236
247
  dispatch(tr);
237
248
  return true;
@@ -8,7 +8,7 @@ export { cleanFormatting, CleanFormattingOptions } from './cleanFormatting';
8
8
  export { hasNode, activeNode, formatBlockElements, getBlockFormats, parentBlockFormat, changeTextBlock, blockNodes, cleanTextBlockFormatting } from './blockNode';
9
9
  export { hasMark, getMark, getActiveMarks, removeAllMarks, cleanMarks, selectionMarks } from './mark';
10
10
  export { indent, canIndentAsListItem, outdent, canOutdentAsListItem, isIndented, canBeIndented, indentBlocks } from './indent';
11
- export { toggleOrderedList, toggleUnorderedList, toggleList } from './lists';
11
+ export { toggleOrderedList, toggleUnorderedList, toggleList, listStyle } from './lists';
12
12
  export { blockquote, liftBlockquote } from './blockquote';
13
13
  export { hasSameMarkup, getSelectionText, getNodeFromSelection, selectedLineTextOnly, expandSelection, expandToWordWrap, canInsert, insertNode, indentHtml } from './utils';
14
14
  export { Command } from './types/command';
@@ -25,6 +25,7 @@ export { placeholder } from './plugins/placeholder';
25
25
  export { spacesFix } from './plugins/spaces-fix';
26
26
  export { textHighlight, textHighlightKey, InlineDecoration } from './plugins/highlight';
27
27
  export { imageResizing, imageResizeKey, ImageResizeOptions } from './plugins/image-resize';
28
+ export { caretColor, caretColorKey } from './plugins/caret-color';
28
29
  export * from 'prosemirror-commands';
29
30
  export * from 'prosemirror-dropcursor';
30
31
  export * from 'prosemirror-gapcursor';
package/dist/npm/main.js CHANGED
@@ -53,6 +53,7 @@ var lists_1 = require("./lists");
53
53
  exports.toggleOrderedList = lists_1.toggleOrderedList;
54
54
  exports.toggleUnorderedList = lists_1.toggleUnorderedList;
55
55
  exports.toggleList = lists_1.toggleList;
56
+ exports.listStyle = lists_1.listStyle;
56
57
  var blockquote_1 = require("./blockquote");
57
58
  exports.blockquote = blockquote_1.blockquote;
58
59
  exports.liftBlockquote = blockquote_1.liftBlockquote;
@@ -116,6 +117,9 @@ exports.textHighlightKey = highlight_1.textHighlightKey;
116
117
  var image_resize_1 = require("./plugins/image-resize");
117
118
  exports.imageResizing = image_resize_1.imageResizing;
118
119
  exports.imageResizeKey = image_resize_1.imageResizeKey;
120
+ var caret_color_1 = require("./plugins/caret-color");
121
+ exports.caretColor = caret_color_1.caretColor;
122
+ exports.caretColorKey = caret_color_1.caretColorKey;
119
123
  // ProseMirror re-exports
120
124
  tslib_1.__exportStar(require("prosemirror-commands"), exports);
121
125
  tslib_1.__exportStar(require("prosemirror-dropcursor"), exports);
@@ -0,0 +1,3 @@
1
+ import { Plugin, PluginKey } from 'prosemirror-state';
2
+ export declare const caretColorKey: PluginKey<any, any>;
3
+ export declare function caretColor(): Plugin;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var prosemirror_state_1 = require("prosemirror-state");
4
+ var prosemirror_view_1 = require("prosemirror-view");
5
+ var mark_1 = require("./../mark");
6
+ exports.caretColorKey = new prosemirror_state_1.PluginKey('caret-color');
7
+ function caretColor() {
8
+ return new prosemirror_state_1.Plugin({
9
+ key: exports.caretColorKey,
10
+ props: {
11
+ decorations: function (state) {
12
+ var doc = state.doc, selection = state.selection, storedMarks = state.storedMarks;
13
+ if (!selection.empty || !storedMarks) {
14
+ return prosemirror_view_1.DecorationSet.empty;
15
+ }
16
+ var color = mark_1.styleValue((storedMarks || []).find(function (m) { return m.type.name === 'style'; }), { name: 'color', value: /^.+$/ });
17
+ if (!color) {
18
+ return prosemirror_view_1.DecorationSet.empty;
19
+ }
20
+ var parentNode = selection.$anchor.parent;
21
+ var decorations = [];
22
+ doc.descendants(function (node, pos) {
23
+ if (node.eq(parentNode)) {
24
+ decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
25
+ style: 'caret-color: ' + color
26
+ }));
27
+ }
28
+ });
29
+ return prosemirror_view_1.DecorationSet.create(doc, decorations);
30
+ }
31
+ }
32
+ });
33
+ }
34
+ exports.caretColor = caretColor;