@progress/kendo-editor-common 1.11.9-dev.202412020819 → 1.11.9-develop.2

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.
Files changed (185) hide show
  1. package/dist/cdn/main.js +1 -1
  2. package/dist/es/DOMSerializer.js +71 -75
  3. package/dist/es/align.js +19 -16
  4. package/dist/es/blockNode.js +76 -78
  5. package/dist/es/blockquote.js +12 -9
  6. package/dist/es/cleanFormatting.js +16 -16
  7. package/dist/es/config/align-rules.js +8 -6
  8. package/dist/es/config/commands.js +9 -13
  9. package/dist/es/config/constants.js +9 -7
  10. package/dist/es/config/indent-rules.js +8 -6
  11. package/dist/es/config/keymap.js +20 -18
  12. package/dist/es/config/list-settings.js +7 -6
  13. package/dist/es/config/schema.js +184 -126
  14. package/dist/es/find-replace.js +34 -32
  15. package/dist/es/image.js +10 -7
  16. package/dist/es/indent.js +47 -44
  17. package/dist/es/inline-style.js +72 -70
  18. package/dist/es/link.js +51 -52
  19. package/dist/es/listConvert.js +37 -34
  20. package/dist/es/lists.js +83 -82
  21. package/dist/es/main.js +32 -33
  22. package/dist/es/mark.js +87 -92
  23. package/dist/es/paste.js +48 -46
  24. package/dist/es/plugins/caret-color.js +14 -11
  25. package/dist/es/plugins/csp-fix.js +23 -23
  26. package/dist/es/plugins/highlight.js +12 -10
  27. package/dist/es/plugins/image-resize.js +81 -81
  28. package/dist/es/plugins/list-markers-styles.js +43 -39
  29. package/dist/es/plugins/placeholder.js +12 -9
  30. package/dist/es/plugins/resize-utils.js +11 -9
  31. package/dist/es/plugins/spaces-fix.js +13 -10
  32. package/dist/es/plugins/table-resize/column-resize.js +104 -102
  33. package/dist/es/plugins/table-resize/index.js +10 -7
  34. package/dist/es/plugins/table-resize/row-resize.js +88 -89
  35. package/dist/es/plugins/table-resize/table-resize.js +129 -122
  36. package/dist/es/plugins/table-resize/table-view.js +46 -48
  37. package/dist/es/plugins/table-resize/utils.js +39 -41
  38. package/dist/es/source.js +78 -74
  39. package/dist/es/table.js +64 -66
  40. package/dist/es/text.js +4 -2
  41. package/dist/es/utils.js +107 -116
  42. package/dist/es2015/DOMSerializer.js +20 -17
  43. package/dist/es2015/align.js +6 -3
  44. package/dist/es2015/blockNode.js +15 -12
  45. package/dist/es2015/blockquote.js +5 -2
  46. package/dist/es2015/cleanFormatting.js +6 -3
  47. package/dist/es2015/config/align-rules.js +7 -5
  48. package/dist/es2015/config/commands.js +9 -13
  49. package/dist/es2015/config/constants.js +9 -7
  50. package/dist/es2015/config/indent-rules.js +6 -3
  51. package/dist/es2015/config/keymap.js +10 -7
  52. package/dist/es2015/config/list-settings.js +5 -3
  53. package/dist/es2015/config/schema.js +8 -6
  54. package/dist/es2015/find-replace.js +9 -6
  55. package/dist/es2015/image.js +5 -2
  56. package/dist/es2015/indent.js +14 -11
  57. package/dist/es2015/inline-style.js +9 -6
  58. package/dist/es2015/link.js +7 -4
  59. package/dist/es2015/listConvert.js +5 -2
  60. package/dist/es2015/lists.js +14 -11
  61. package/dist/es2015/main.js +32 -33
  62. package/dist/es2015/mark.js +15 -12
  63. package/dist/es2015/node_modules/tslib/tslib.es6.js +35 -0
  64. package/dist/es2015/paste.js +14 -11
  65. package/dist/es2015/plugins/caret-color.js +8 -5
  66. package/dist/es2015/plugins/csp-fix.js +5 -2
  67. package/dist/es2015/plugins/highlight.js +6 -3
  68. package/dist/es2015/plugins/image-resize.js +10 -7
  69. package/dist/es2015/plugins/list-markers-styles.js +6 -3
  70. package/dist/es2015/plugins/placeholder.js +5 -2
  71. package/dist/es2015/plugins/resize-utils.js +11 -9
  72. package/dist/es2015/plugins/spaces-fix.js +4 -1
  73. package/dist/es2015/plugins/table-resize/column-resize.js +24 -21
  74. package/dist/es2015/plugins/table-resize/index.js +9 -6
  75. package/dist/es2015/plugins/table-resize/row-resize.js +23 -20
  76. package/dist/es2015/plugins/table-resize/table-resize.js +20 -17
  77. package/dist/es2015/plugins/table-resize/table-view.js +9 -6
  78. package/dist/es2015/plugins/table-resize/utils.js +13 -10
  79. package/dist/es2015/source.js +24 -13
  80. package/dist/es2015/table.js +18 -15
  81. package/dist/es2015/text.js +3 -1
  82. package/dist/es2015/utils.js +22 -25
  83. package/dist/npm/DOMSerializer.js +73 -78
  84. package/dist/npm/align.d.ts +7 -4
  85. package/dist/npm/align.js +22 -21
  86. package/dist/npm/blockNode.d.ts +14 -15
  87. package/dist/npm/blockNode.js +91 -95
  88. package/dist/npm/blockquote.d.ts +5 -2
  89. package/dist/npm/blockquote.js +16 -15
  90. package/dist/npm/cleanFormatting.d.ts +6 -3
  91. package/dist/npm/cleanFormatting.js +17 -19
  92. package/dist/npm/config/align-rules.d.ts +8 -6
  93. package/dist/npm/config/align-rules.js +14 -9
  94. package/dist/npm/config/commands.d.ts +11 -19
  95. package/dist/npm/config/commands.js +17 -16
  96. package/dist/npm/config/constants.js +17 -10
  97. package/dist/npm/config/indent-rules.d.ts +6 -4
  98. package/dist/npm/config/indent-rules.js +11 -9
  99. package/dist/npm/config/keymap.d.ts +5 -2
  100. package/dist/npm/config/keymap.js +30 -30
  101. package/dist/npm/config/list-settings.js +13 -11
  102. package/dist/npm/config/schema.d.ts +4 -3
  103. package/dist/npm/config/schema.js +191 -134
  104. package/dist/npm/find-replace.d.ts +10 -7
  105. package/dist/npm/find-replace.js +47 -47
  106. package/dist/npm/image.d.ts +6 -3
  107. package/dist/npm/image.js +11 -10
  108. package/dist/npm/indent.d.ts +12 -9
  109. package/dist/npm/indent.js +68 -67
  110. package/dist/npm/inline-style.d.ts +7 -4
  111. package/dist/npm/inline-style.js +83 -83
  112. package/dist/npm/link.d.ts +4 -2
  113. package/dist/npm/link.js +58 -61
  114. package/dist/npm/listConvert.d.ts +3 -1
  115. package/dist/npm/listConvert.js +40 -39
  116. package/dist/npm/lists.d.ts +9 -9
  117. package/dist/npm/lists.js +94 -95
  118. package/dist/npm/main.d.ts +34 -33
  119. package/dist/npm/main.js +389 -198
  120. package/dist/npm/mark.d.ts +13 -18
  121. package/dist/npm/mark.js +104 -111
  122. package/dist/npm/paste.d.ts +12 -9
  123. package/dist/npm/paste.js +61 -61
  124. package/dist/npm/plugins/caret-color.d.ts +6 -3
  125. package/dist/npm/plugins/caret-color.js +21 -19
  126. package/dist/npm/plugins/csp-fix.d.ts +4 -1
  127. package/dist/npm/plugins/csp-fix.js +28 -30
  128. package/dist/npm/plugins/highlight.d.ts +7 -4
  129. package/dist/npm/plugins/highlight.js +17 -16
  130. package/dist/npm/plugins/image-resize.d.ts +7 -5
  131. package/dist/npm/plugins/image-resize.js +96 -97
  132. package/dist/npm/plugins/list-markers-styles.d.ts +5 -2
  133. package/dist/npm/plugins/list-markers-styles.js +49 -47
  134. package/dist/npm/plugins/placeholder.d.ts +4 -1
  135. package/dist/npm/plugins/placeholder.js +18 -17
  136. package/dist/npm/plugins/resize-utils.js +14 -12
  137. package/dist/npm/plugins/spaces-fix.d.ts +4 -1
  138. package/dist/npm/plugins/spaces-fix.js +19 -18
  139. package/dist/npm/plugins/table-resize/column-resize.js +117 -117
  140. package/dist/npm/plugins/table-resize/index.d.ts +5 -2
  141. package/dist/npm/plugins/table-resize/index.js +16 -15
  142. package/dist/npm/plugins/table-resize/row-resize.js +98 -101
  143. package/dist/npm/plugins/table-resize/table-resize.js +144 -139
  144. package/dist/npm/plugins/table-resize/table-view.js +59 -61
  145. package/dist/npm/plugins/table-resize/utils.d.ts +7 -17
  146. package/dist/npm/plugins/table-resize/utils.js +51 -52
  147. package/dist/npm/source.d.ts +18 -11
  148. package/dist/npm/source.js +94 -91
  149. package/dist/npm/table.d.ts +10 -9
  150. package/dist/npm/table.js +93 -82
  151. package/dist/npm/text.d.ts +6 -3
  152. package/dist/npm/text.js +5 -5
  153. package/dist/npm/types/active-marks.d.ts +4 -1
  154. package/dist/npm/types/command.d.ts +5 -2
  155. package/dist/npm/types/dispatchFn.d.ts +4 -1
  156. package/dist/npm/types/paste-cleanup-settings.d.ts +3 -1
  157. package/dist/npm/utils.d.ts +14 -29
  158. package/dist/npm/utils.js +133 -145
  159. package/package.json +35 -53
  160. package/dist/cdn/js/kendo-editor-common.js +0 -1
  161. package/dist/es/types/active-marks.js +0 -1
  162. package/dist/es/types/command.js +0 -1
  163. package/dist/es/types/dispatchFn.js +0 -1
  164. package/dist/es/types/paste-cleanup-settings.js +0 -1
  165. package/dist/es/types/predicate.js +0 -1
  166. package/dist/es2015/types/active-marks.js +0 -1
  167. package/dist/es2015/types/command.js +0 -1
  168. package/dist/es2015/types/dispatchFn.js +0 -1
  169. package/dist/es2015/types/paste-cleanup-settings.js +0 -1
  170. package/dist/es2015/types/predicate.js +0 -1
  171. package/dist/npm/DOMSerializer.d.ts +0 -35
  172. package/dist/npm/config/constants.d.ts +0 -7
  173. package/dist/npm/config/list-settings.d.ts +0 -30
  174. package/dist/npm/plugins/resize-utils.d.ts +0 -35
  175. package/dist/npm/plugins/table-resize/column-resize.d.ts +0 -2
  176. package/dist/npm/plugins/table-resize/row-resize.d.ts +0 -2
  177. package/dist/npm/plugins/table-resize/table-resize.d.ts +0 -18
  178. package/dist/npm/plugins/table-resize/table-view.d.ts +0 -28
  179. package/dist/npm/types/active-marks.js +0 -2
  180. package/dist/npm/types/command.js +0 -2
  181. package/dist/npm/types/dispatchFn.js +0 -2
  182. package/dist/npm/types/paste-cleanup-settings.js +0 -2
  183. package/dist/npm/types/predicate.d.ts +0 -1
  184. package/dist/npm/types/predicate.js +0 -2
  185. package/dist/systemjs/kendo-editor-common.js +0 -1
@@ -1,99 +1,97 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyInlineStyle = exports.toggleInlineFormat = exports.getInlineStyles = void 0;
4
- var tslib_1 = require("tslib");
5
- var prosemirror_transform_1 = require("prosemirror-transform");
6
- var prosemirror_state_1 = require("prosemirror-state");
7
- var utils_1 = require("./utils");
8
- var mark_1 = require("./mark");
9
- var changeStyleFromMark = function (marks, toChange) {
10
- var styleMark = marks.find(function (m) { return m.type.name === 'style'; });
11
- var elementStyle = styleMark && styleMark.attrs.style;
12
- return (0, utils_1.changeStylesString)(elementStyle, toChange);
1
+ 'use strict';
2
+
3
+ var prosemirrorTransform = require('prosemirror-transform');
4
+ var prosemirrorState = require('prosemirror-state');
5
+ var utils = require('./utils.js');
6
+ var mark = require('./mark.js');
7
+
8
+ const changeStyleFromMark = (marks, toChange) => {
9
+ const styleMark = marks.find(m => m.type.name === 'style');
10
+ const elementStyle = styleMark && styleMark.attrs.style;
11
+ return utils.changeStylesString(elementStyle, toChange);
13
12
  };
14
- var changeStyleMark = function (tr, from, to, attrs, markType) {
15
- var mark = markType.create({ style: attrs.style });
16
- var removed = [], added = [], removing = null, adding = null;
17
- tr.doc.nodesBetween(from, to, function (node, pos, parent) {
13
+ const changeStyleMark = (tr, from, to, attrs, markType) => {
14
+ const mark = markType.create({ style: attrs.style });
15
+ let removed = [], added = [], removing = null, adding = null;
16
+ tr.doc.nodesBetween(from, to, (node, pos, parent) => {
18
17
  if (!node.isInline) {
19
18
  return;
20
19
  }
21
- var marks = node.marks;
20
+ const marks = node.marks;
22
21
  if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) {
23
- var start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to);
24
- var newStyle = changeStyleFromMark(marks, attrs);
22
+ const start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to);
23
+ const newStyle = changeStyleFromMark(marks, attrs);
25
24
  if (newStyle.changed || attrs.newValue) {
26
- var style = newStyle.changed ?
27
- { style: newStyle.style || null } : { style: "".concat([attrs.style], ": ").concat(attrs.newValue, ";") };
28
- var currentMark = markType.isInSet(marks) ? marks.find(function (m) { return m.type.name === 'style'; }) : null;
29
- var newMarkAttrs_1 = currentMark ? tslib_1.__assign(tslib_1.__assign({}, currentMark.attrs), style) : style;
30
- var newStyleMark = markType.create(newMarkAttrs_1);
31
- var newSet = newStyleMark.addToSet(marks);
32
- for (var i = 0; i < marks.length; i++) {
25
+ const style = newStyle.changed ?
26
+ { style: newStyle.style || null } : { style: `${[attrs.style]}: ${attrs.newValue};` };
27
+ const currentMark = markType.isInSet(marks) ? marks.find(m => m.type.name === 'style') : null;
28
+ const newMarkAttrs = currentMark ? { ...currentMark.attrs, ...style } : style;
29
+ const newStyleMark = markType.create(newMarkAttrs);
30
+ const newSet = newStyleMark.addToSet(marks);
31
+ for (let i = 0; i < marks.length; i++) {
33
32
  if (!marks[i].isInSet(newSet)) {
34
33
  if (removing && removing.to === start && removing.mark.eq(marks[i])) {
35
34
  removing.to = end;
36
35
  }
37
36
  else {
38
- removing = new prosemirror_transform_1.RemoveMarkStep(start, end, marks[i]);
37
+ removing = new prosemirrorTransform.RemoveMarkStep(start, end, marks[i]);
39
38
  removed.push(removing);
40
39
  }
41
40
  }
42
41
  }
43
- var previousAdded = adding && adding.to === start;
44
- var sameAdding = previousAdded && newStyleMark.attrs.style === adding.mark.attrs.style;
42
+ const previousAdded = adding && adding.to === start;
43
+ const sameAdding = previousAdded && newStyleMark.attrs.style === adding.mark.attrs.style;
45
44
  if (previousAdded && sameAdding) {
46
45
  adding.to = end;
47
46
  }
48
- else if (Object.keys(newMarkAttrs_1).some(function (attrName) { return newMarkAttrs_1[attrName] !== null; })) {
49
- adding = new prosemirror_transform_1.AddMarkStep(start, end, newStyleMark);
47
+ else if (Object.keys(newMarkAttrs).some(attrName => newMarkAttrs[attrName] !== null)) {
48
+ adding = new prosemirrorTransform.AddMarkStep(start, end, newStyleMark);
50
49
  added.push(adding);
51
50
  }
52
51
  }
53
52
  }
54
53
  });
55
- removed.forEach(function (s) { return tr.step(s); });
56
- added.forEach(function (s) { return tr.step(s); });
54
+ removed.forEach(s => tr.step(s));
55
+ added.forEach(s => tr.step(s));
57
56
  return removed.length + added.length > 0;
58
57
  };
59
58
  /**
60
59
  * Used by FontSize and FontName tools for getting their state.
61
60
  */
62
- var getInlineStyles = function (state, style) {
63
- var styleMark = state.schema.marks.style;
64
- var marks = styleMark ? (0, mark_1.selectionMarks)(state, styleMark) : [];
65
- return marks.map(function (mark) { return (0, mark_1.styleValue)(mark, style); }).filter(function (m) { return m !== null; });
61
+ const getInlineStyles = (state, style) => {
62
+ const styleMark = state.schema.marks.style;
63
+ const marks = styleMark ? mark.selectionMarks(state, styleMark) : [];
64
+ return marks.map(mark$1 => mark.styleValue(mark$1, style)).filter(m => m !== null);
66
65
  };
67
- exports.getInlineStyles = getInlineStyles;
68
- var changeStyle = function (markType, attrs) {
66
+ const changeStyle = (markType, attrs) => {
69
67
  return function (state, dispatch, tr) {
70
- var _a = state.selection, empty = _a.empty, ranges = _a.ranges;
71
- var $cursor = state.selection instanceof prosemirror_state_1.TextSelection && state.selection.$cursor;
72
- if ((empty && !$cursor) || !(0, mark_1.markApplies)(state.doc, ranges, markType)) {
68
+ const { empty, ranges } = state.selection;
69
+ const $cursor = state.selection instanceof prosemirrorState.TextSelection && state.selection.$cursor;
70
+ if ((empty && !$cursor) || !mark.markApplies(state.doc, ranges, markType)) {
73
71
  return false;
74
72
  }
75
- var result = false;
73
+ let result = false;
76
74
  if (dispatch) {
77
- var transaction = tr || state.tr;
75
+ const transaction = tr || state.tr;
78
76
  if ($cursor) {
79
- var currentMarks = state.storedMarks || $cursor.marks();
77
+ const currentMarks = state.storedMarks || $cursor.marks();
80
78
  if (markType.isInSet(currentMarks)) {
81
- var newStyle = changeStyleFromMark(currentMarks, attrs);
82
- var styleMark = currentMarks.find(function (m) { return m.type.name === 'style'; });
83
- var newAttrs_1 = tslib_1.__assign(tslib_1.__assign({}, (styleMark ? styleMark.attrs : {})), { style: newStyle.style || null });
84
- if ((0, utils_1.shallowEqual)(styleMark.attrs, newAttrs_1)) {
79
+ const newStyle = changeStyleFromMark(currentMarks, attrs);
80
+ const styleMark = currentMarks.find(m => m.type.name === 'style');
81
+ const newAttrs = { ...(styleMark ? styleMark.attrs : {}), style: newStyle.style || null };
82
+ if (utils.shallowEqual(styleMark.attrs, newAttrs)) {
85
83
  return false;
86
84
  }
87
85
  dispatch(transaction.removeStoredMark(markType));
88
- if (Object.keys(newAttrs_1).some(function (attrName) { return newAttrs_1[attrName] !== null; })) {
89
- dispatch(transaction.addStoredMark(markType.create(newAttrs_1)));
86
+ if (Object.keys(newAttrs).some(attrName => newAttrs[attrName] !== null)) {
87
+ dispatch(transaction.addStoredMark(markType.create(newAttrs)));
90
88
  }
91
89
  result = true;
92
90
  }
93
91
  }
94
92
  else {
95
- for (var i = 0; i < ranges.length; i++) {
96
- var _b = ranges[i], $from = _b.$from, $to = _b.$to;
93
+ for (let i = 0; i < ranges.length; i++) {
94
+ const { $from, $to } = ranges[i];
97
95
  result = changeStyleMark(transaction, $from.pos, $to.pos, attrs, markType) || result;
98
96
  }
99
97
  if (result) {
@@ -108,68 +106,67 @@ var changeStyle = function (markType, attrs) {
108
106
  /**
109
107
  * Used by bold, italic, ... and link commands.
110
108
  */
111
- var toggleInlineFormat = function (options, tr, markAttrs) { return function (state, dispatch) {
112
- var marks = state.schema.marks;
113
- var altStyle = options.altStyle, _a = options.altMarks, altMarks = _a === void 0 ? [] : _a, mark = options.mark;
114
- var transaction = tr || state.tr;
115
- var styleRemoved = false;
116
- var dispatched = false;
117
- var markDispatched = function () { return dispatched = true; };
109
+ const toggleInlineFormat = (options, tr, markAttrs) => (state, dispatch) => {
110
+ const marks = state.schema.marks;
111
+ const { altStyle, altMarks = [], mark: mark$1 } = options;
112
+ const transaction = tr || state.tr;
113
+ let styleRemoved = false;
114
+ let dispatched = false;
115
+ const markDispatched = () => dispatched = true;
118
116
  if (altStyle && marks.style) {
119
- var cmd = changeStyle(marks.style, { style: altStyle.name, value: altStyle.value });
117
+ const cmd = changeStyle(marks.style, { style: altStyle.name, value: altStyle.value });
120
118
  styleRemoved = cmd(state, markDispatched, transaction);
121
119
  }
122
- var allMarks = tslib_1.__spreadArray([mark], altMarks, true).filter(function (m) { return marks[m]; });
123
- var toRemove = allMarks.map(function (m) { return (0, mark_1.hasMark)(state, { mark: m }) && marks[m]; }).filter(function (m) { return m; });
120
+ const allMarks = [mark$1, ...altMarks].filter(m => marks[m]);
121
+ const toRemove = allMarks.map(m => mark.hasMark(state, { mark: m }) && marks[m]).filter(m => m);
124
122
  if (toRemove.length) {
125
- (0, mark_1.removeMarks)(toRemove, state, markDispatched, transaction);
123
+ mark.removeMarks(toRemove, state, markDispatched, transaction);
126
124
  }
127
125
  else {
128
126
  if (!styleRemoved) {
129
- (0, mark_1.toggleMark)(marks[mark], markAttrs, transaction)(state, markDispatched);
127
+ mark.toggleMark(marks[mark$1], markAttrs, transaction)(state, markDispatched);
130
128
  }
131
129
  }
132
130
  if (dispatched) {
133
131
  dispatch(transaction);
134
132
  }
135
133
  return dispatched;
136
- }; };
137
- exports.toggleInlineFormat = toggleInlineFormat;
134
+ };
138
135
  /**
139
136
  * Used by FontSize, FontName, Color and BackColor commands.
140
137
  */
141
- var applyInlineStyle = function (options, command) { return function (state, dispatch) {
142
- var marks = state.schema.marks;
143
- var markType = marks.style;
144
- var attrs = {
138
+ const applyInlineStyle = (options, command) => (state, dispatch) => {
139
+ const marks = state.schema.marks;
140
+ const markType = marks.style;
141
+ const attrs = {
145
142
  style: options.style, value: /^.+$/, newValue: options.value
146
143
  };
147
- var tr = state.tr;
144
+ const tr = state.tr;
148
145
  if (command) {
149
146
  tr.setMeta('commandName', command);
150
147
  }
151
148
  tr.setMeta('args', options);
152
- var _a = state.selection, empty = _a.empty, $cursor = _a.$cursor, ranges = _a.ranges;
153
- if ((empty && !$cursor) || !markType || !(0, mark_1.markApplies)(state.doc, ranges, markType)) {
149
+ const { empty, $cursor, ranges } = state.selection;
150
+ if ((empty && !$cursor) || !markType || !mark.markApplies(state.doc, ranges, markType)) {
154
151
  return false;
155
152
  }
156
153
  // Empty selection
157
154
  if ($cursor) {
158
- var marksFromSelection = state.storedMarks || $cursor.marks();
159
- var currentMark = markType.isInSet(marksFromSelection) ? marksFromSelection.find(function (m) { return m.type.name === 'style'; }) : null;
160
- var newStyles = { style: null };
155
+ const marksFromSelection = state.storedMarks || $cursor.marks();
156
+ const currentMark = markType.isInSet(marksFromSelection) ? marksFromSelection.find(m => m.type.name === 'style') : null;
157
+ const newStyles = { style: null };
161
158
  if (currentMark && currentMark.attrs.style) {
162
- var resultStyles = (0, utils_1.changeStylesString)(currentMark.attrs.style, attrs);
159
+ const resultStyles = utils.changeStylesString(currentMark.attrs.style, attrs);
163
160
  if (resultStyles.changed && resultStyles.style) {
164
161
  newStyles.style = resultStyles.style;
165
162
  }
166
163
  }
167
164
  else if (attrs.newValue) {
168
- newStyles.style = "".concat([attrs.style], ": ").concat(attrs.newValue, ";");
165
+ newStyles.style = `${[attrs.style]}: ${attrs.newValue};`;
169
166
  }
170
- var newMarkAttrs_2 = currentMark ? tslib_1.__assign(tslib_1.__assign({}, currentMark.attrs), newStyles) : newStyles;
171
- if (Object.keys(newMarkAttrs_2).some(function (attrName) { return newMarkAttrs_2[attrName] !== null; })) {
172
- dispatch(tr.addStoredMark(markType.create(newMarkAttrs_2)));
167
+ const newMarkAttrs = currentMark ? { ...currentMark.attrs, ...newStyles } : newStyles;
168
+ if (Object.keys(newMarkAttrs).some(attrName => newMarkAttrs[attrName] !== null)) {
169
+ dispatch(tr.addStoredMark(markType.create(newMarkAttrs)));
173
170
  }
174
171
  else {
175
172
  dispatch(tr.removeStoredMark(markType));
@@ -177,5 +174,8 @@ var applyInlineStyle = function (options, command) { return function (state, dis
177
174
  return true;
178
175
  }
179
176
  return changeStyle(markType, attrs)(state, dispatch, tr);
180
- }; };
177
+ };
178
+
181
179
  exports.applyInlineStyle = applyInlineStyle;
180
+ exports.getInlineStyles = getInlineStyles;
181
+ exports.toggleInlineFormat = toggleInlineFormat;
@@ -1,5 +1,7 @@
1
- export declare const removeLink: (options: any, tr?: any) => (state: any, dispatch: any) => void;
2
- export declare const applyLink: ({ mark, attrs }: {
1
+ declare const removeLink: (options: any, tr?: any) => (state: any, dispatch: any) => void;
2
+ declare const applyLink: ({ mark, attrs }: {
3
3
  mark: any;
4
4
  attrs: any;
5
5
  }, commandName?: string) => (state: any, dispatch: any) => boolean;
6
+
7
+ export { applyLink, removeLink };
package/dist/npm/link.js CHANGED
@@ -1,14 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyLink = exports.removeLink = void 0;
4
- var inline_style_1 = require("./inline-style");
5
- var mark_1 = require("./mark");
6
- var prosemirror_state_1 = require("prosemirror-state");
7
- var modifyLink = function (options, tr) { return function (state, dispatch) {
8
- var _a = state.selection, $cursor = _a.$cursor, from = _a.from, to = _a.to;
9
- var markType = state.schema.marks[options.mark];
1
+ 'use strict';
2
+
3
+ var inlineStyle = require('./inline-style.js');
4
+ var mark = require('./mark.js');
5
+ var prosemirrorState = require('prosemirror-state');
6
+
7
+ const modifyLink = (options, tr) => (state, dispatch) => {
8
+ const { $cursor, from, to } = state.selection;
9
+ const markType = state.schema.marks[options.mark];
10
10
  if (!$cursor) {
11
- tr.doc.nodesBetween(from, to, function (node, pos) {
11
+ tr.doc.nodesBetween(from, to, (node, pos) => {
12
12
  if (node.isInline && markType.isInSet(node.marks)) {
13
13
  tr.removeMark(pos, pos + node.nodeSize, markType);
14
14
  tr.addMark(pos, pos + node.nodeSize, markType.create(options.attrs));
@@ -17,11 +17,11 @@ var modifyLink = function (options, tr) { return function (state, dispatch) {
17
17
  });
18
18
  }
19
19
  else {
20
- var parentNode = $cursor.parent;
21
- var cursorNodeIndex = $cursor.index();
22
- var mark = parentNode.child(cursorNodeIndex).marks.find(function (m) { return m.type === markType; });
23
- var childCount = parentNode.childCount;
24
- var linkStart = $cursor.pos - $cursor.textOffset, linkSize = parentNode.child(cursorNodeIndex).nodeSize, index = void 0, nodeSize = void 0;
20
+ const parentNode = $cursor.parent;
21
+ const cursorNodeIndex = $cursor.index();
22
+ const mark = parentNode.child(cursorNodeIndex).marks.find(m => m.type === markType);
23
+ const childCount = parentNode.childCount;
24
+ let linkStart = $cursor.pos - $cursor.textOffset, linkSize = parentNode.child(cursorNodeIndex).nodeSize, index, nodeSize;
25
25
  index = cursorNodeIndex - 1;
26
26
  while (index >= 0 && mark.isInSet(parentNode.child(index).marks)) {
27
27
  nodeSize = parentNode.child(index).nodeSize;
@@ -38,74 +38,71 @@ var modifyLink = function (options, tr) { return function (state, dispatch) {
38
38
  tr.addMark(linkStart, linkStart + linkSize, markType.create(options.attrs));
39
39
  dispatch(tr);
40
40
  }
41
- }; };
42
- var removeLink = function (options, tr) { return function (state, dispatch) {
43
- var $cursor = state.selection.$cursor;
41
+ };
42
+ const removeLink = (options, tr) => (state, dispatch) => {
43
+ const { $cursor } = state.selection;
44
44
  if (!$cursor) {
45
- (0, inline_style_1.toggleInlineFormat)(options, tr)(state, dispatch);
45
+ inlineStyle.toggleInlineFormat(options, tr)(state, dispatch);
46
46
  }
47
47
  else {
48
- var parentNode = $cursor.parent;
49
- var cursorNodeIndex = $cursor.index();
50
- var toolMark_1 = state.schema.marks[options.mark];
51
- var mark = parentNode.child(cursorNodeIndex).marks.find(function (m) { return m.type === toolMark_1; });
52
- var childCount = parentNode.childCount;
53
- var linkStart = $cursor.pos - $cursor.textOffset, linkSize = parentNode.child(cursorNodeIndex).nodeSize, index = void 0, nodeSize = void 0;
48
+ const parentNode = $cursor.parent;
49
+ const cursorNodeIndex = $cursor.index();
50
+ const toolMark = state.schema.marks[options.mark];
51
+ const mark$1 = parentNode.child(cursorNodeIndex).marks.find(m => m.type === toolMark);
52
+ const childCount = parentNode.childCount;
53
+ let linkStart = $cursor.pos - $cursor.textOffset, linkSize = parentNode.child(cursorNodeIndex).nodeSize, index, nodeSize;
54
54
  index = cursorNodeIndex - 1;
55
- while (index >= 0 && mark.isInSet(parentNode.child(index).marks)) {
55
+ while (index >= 0 && mark$1.isInSet(parentNode.child(index).marks)) {
56
56
  nodeSize = parentNode.child(index).nodeSize;
57
57
  linkSize += nodeSize;
58
58
  linkStart -= nodeSize;
59
59
  index -= 1;
60
60
  }
61
61
  index = cursorNodeIndex + 1;
62
- while (index < childCount && mark.isInSet(parentNode.child(index).marks)) {
62
+ while (index < childCount && mark$1.isInSet(parentNode.child(index).marks)) {
63
63
  linkSize += parentNode.child(index).nodeSize;
64
64
  index += 1;
65
65
  }
66
- dispatch((0, mark_1.removeMark)(tr || state.tr, linkStart, linkStart + linkSize, mark));
66
+ dispatch(mark.removeMark(tr || state.tr, linkStart, linkStart + linkSize, mark$1));
67
67
  }
68
- }; };
69
- exports.removeLink = removeLink;
68
+ };
70
69
  /**
71
70
  * Returns a mark which wraps the selection.
72
71
  */
73
- var getParentMark = function (state, markType) {
74
- var marks = (0, mark_1.selectionMarks)(state, markType);
72
+ const getParentMark = (state, markType) => {
73
+ const marks = mark.selectionMarks(state, markType);
75
74
  return marks.length === 1 && marks[0] ? marks[0] : null;
76
75
  };
77
- var applyLink = function (_a, commandName) {
78
- var mark = _a.mark, attrs = _a.attrs;
79
- if (commandName === void 0) { commandName = 'link'; }
80
- return function (state, dispatch) {
81
- var marks = state.schema.marks;
82
- var tr = state.tr;
83
- if (commandName) {
84
- tr.setMeta('commandName', commandName);
85
- tr.setMeta('args', attrs);
76
+ const applyLink = ({ mark: mark$1, attrs }, commandName = 'link') => (state, dispatch) => {
77
+ const marks = state.schema.marks;
78
+ const tr = state.tr;
79
+ if (commandName) {
80
+ tr.setMeta('commandName', commandName);
81
+ tr.setMeta('args', attrs);
82
+ }
83
+ let dispatched = false;
84
+ const markDispatched = () => dispatched = true;
85
+ if (getParentMark(state, marks[mark$1])) {
86
+ modifyLink({ mark: mark$1, attrs }, tr)(state, markDispatched);
87
+ }
88
+ else {
89
+ let nextState = state;
90
+ if (mark.hasMark(state, { mark: mark$1 })) {
91
+ removeLink({ mark: mark$1, attrs }, tr)(state, markDispatched);
92
+ nextState = prosemirrorState.EditorState.create({ doc: tr.doc, selection: tr.selection });
86
93
  }
87
- var dispatched = false;
88
- var markDispatched = function () { return dispatched = true; };
89
- if (getParentMark(state, marks[mark])) {
90
- modifyLink({ mark: mark, attrs: attrs }, tr)(state, markDispatched);
94
+ if (dispatched) {
95
+ mark.toggleMark(marks[mark$1], attrs, tr)(nextState, markDispatched);
91
96
  }
92
97
  else {
93
- var nextState = state;
94
- if ((0, mark_1.hasMark)(state, { mark: mark })) {
95
- (0, exports.removeLink)({ mark: mark, attrs: attrs }, tr)(state, markDispatched);
96
- nextState = prosemirror_state_1.EditorState.create({ doc: tr.doc, selection: tr.selection });
97
- }
98
- if (dispatched) {
99
- (0, mark_1.toggleMark)(marks[mark], attrs, tr)(nextState, markDispatched);
100
- }
101
- else {
102
- (0, inline_style_1.toggleInlineFormat)({ mark: mark }, tr, attrs)(nextState, markDispatched);
103
- }
104
- }
105
- if (dispatched) {
106
- dispatch(tr);
98
+ inlineStyle.toggleInlineFormat({ mark: mark$1 }, tr, attrs)(nextState, markDispatched);
107
99
  }
108
- return dispatched;
109
- };
100
+ }
101
+ if (dispatched) {
102
+ dispatch(tr);
103
+ }
104
+ return dispatched;
110
105
  };
106
+
111
107
  exports.applyLink = applyLink;
108
+ exports.removeLink = removeLink;
@@ -1 +1,3 @@
1
- export declare const convertMsLists: (html: string) => string;
1
+ declare const convertMsLists: (html: string) => string;
2
+
3
+ export { convertMsLists };
@@ -1,29 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertMsLists = void 0;
4
- var source_1 = require("./source");
5
- var msoListRegExp = /style=['"]?[^'"]*?mso-list:\s*[a-zA-Z]+(\d+)\s[a-zA-Z]+(\d+)\s(\w+)/gi;
6
- var extractListLevels = function (html) {
7
- html = html.replace(msoListRegExp, function (match, list, level) {
8
- return "datalist=\"".concat(list, "\" datalevel=\"").concat(level, "\" ").concat(match);
1
+ 'use strict';
2
+
3
+ var source = require('./source.js');
4
+
5
+ const msoListRegExp = /style=['"]?[^'"]*?mso-list:\s*[a-zA-Z]+(\d+)\s[a-zA-Z]+(\d+)\s(\w+)/gi;
6
+ const extractListLevels = (html) => {
7
+ html = html.replace(msoListRegExp, (match, list, level) => {
8
+ return `datalist="${list}" datalevel="${level}" ${match}`;
9
9
  });
10
10
  return html;
11
11
  };
12
- var isPartOfListItem = function (element) {
12
+ const isPartOfListItem = (element) => {
13
13
  return /^MsoListParagraph/.test(element.className);
14
14
  };
15
- var innerText = function (node) {
16
- var text = node.innerHTML;
15
+ const innerText = (node) => {
16
+ let text = node.innerHTML;
17
17
  text = text.replace(/<!--(.|\s)*?-->/gi, '');
18
18
  text = text.replace(/<\/?[^>]+?\/?>/gm, '');
19
19
  return text;
20
20
  };
21
- var createList = function (type, styleType) {
22
- var list = document.createElement(type);
21
+ const createList = (type, styleType) => {
22
+ const list = document.createElement(type);
23
23
  list.style.listStyleType = styleType;
24
24
  return list;
25
25
  };
26
- var guessUnorderedListStyle = function (symbol) {
26
+ const guessUnorderedListStyle = (symbol) => {
27
27
  if (/^[\u2022\u00b7\u00FC\u00D8\u002dv-]/.test(symbol)) {
28
28
  return null; // return "disc"; //default CSS value
29
29
  }
@@ -34,21 +34,21 @@ var guessUnorderedListStyle = function (symbol) {
34
34
  return 'square';
35
35
  }
36
36
  };
37
- var guessOrderedListStyle = function (symbol) {
38
- var type = null;
37
+ const guessOrderedListStyle = (symbol) => {
38
+ let type = null;
39
39
  if (!/^\d/.test(symbol)) {
40
40
  type = (/^[a-z]/.test(symbol) ? 'lower-' : 'upper-') +
41
41
  (/^[ivxlcdm]/i.test(symbol) ? 'roman' : 'alpha');
42
42
  }
43
43
  return type;
44
44
  };
45
- var mapListsCandidates = function (nodes, groups) {
46
- var group = [];
47
- Array.from(nodes).forEach(function (node) {
45
+ const mapListsCandidates = (nodes, groups) => {
46
+ let group = [];
47
+ Array.from(nodes).forEach(node => {
48
48
  if (node.nodeType !== Node.ELEMENT_NODE) {
49
49
  return;
50
50
  }
51
- var element = node;
51
+ const element = node;
52
52
  if (element.getAttribute('datalist')) {
53
53
  group.push(node);
54
54
  groups.add(group);
@@ -62,16 +62,16 @@ var mapListsCandidates = function (nodes, groups) {
62
62
  mapListsCandidates(element.children, groups);
63
63
  }
64
64
  else if (element.nodeName === 'TABLE') {
65
- Array.from(element.querySelectorAll('td,th')).forEach(function (cell) {
65
+ Array.from(element.querySelectorAll('td,th')).forEach(cell => {
66
66
  mapListsCandidates(cell.children, groups);
67
67
  });
68
68
  }
69
69
  }
70
70
  });
71
71
  };
72
- var listTypes = function (p) {
73
- var html = p.innerHTML;
74
- var trimStartText = function (t) {
72
+ const listTypes = (p) => {
73
+ let html = p.innerHTML;
74
+ const trimStartText = (t) => {
75
75
  return t.replace(/^(?:&nbsp;|[\u00a0\n\r\s])+/, '');
76
76
  };
77
77
  html = html.replace(/<\/?\w+[^>]*>/g, '').replace(/&nbsp;/g, '\u00a0');
@@ -88,8 +88,8 @@ var listTypes = function (p) {
88
88
  };
89
89
  }
90
90
  };
91
- var convertToLi = function (p) {
92
- var content, name = p.nodeName.toLowerCase();
91
+ const convertToLi = (p) => {
92
+ let content, name = p.nodeName.toLowerCase();
93
93
  if (p.firstChild && p.firstChild.nodeType === Node.COMMENT_NODE) {
94
94
  p.removeChild(p.firstChild);
95
95
  }
@@ -116,20 +116,20 @@ var convertToLi = function (p) {
116
116
  }
117
117
  }
118
118
  p.parentNode.removeChild(p);
119
- var li = document.createElement('li');
120
- li.appendChild((0, source_1.htmlToFragment)(content));
119
+ const li = document.createElement('li');
120
+ li.appendChild(source.htmlToFragment(content));
121
121
  return li;
122
122
  };
123
- var toList = function (blockNodes) {
124
- var lastMargin = -1, levels = {}, li, rootMargin, rootIndex, lastRootLi, isLastRootLi, rootList, items, i, p, type, margin, list, listData;
123
+ const toList = (blockNodes) => {
124
+ let lastMargin = -1, levels = {}, li, rootMargin, rootIndex, lastRootLi, isLastRootLi, rootList, items, i, p, type, margin, list, listData;
125
125
  for (i = 0; i < blockNodes.length; i++) {
126
126
  p = blockNodes[i];
127
127
  listData = {
128
128
  datalist: p.getAttribute('datalist'),
129
129
  datalevel: p.getAttribute('datalevel')
130
130
  };
131
- var listIndex = listData.datalist;
132
- var listType = listTypes(p);
131
+ const listIndex = listData.datalist;
132
+ const listType = listTypes(p);
133
133
  type = listType && listType.tag;
134
134
  if (!type) {
135
135
  if (li && (!isLastRootLi || isPartOfListItem(p))) {
@@ -148,14 +148,14 @@ var toList = function (blockNodes) {
148
148
  if (!listData.datalevel && !p.style.marginLeft) {
149
149
  continue;
150
150
  }
151
- var levelType = type + listIndex;
151
+ const levelType = type + listIndex;
152
152
  if (!levels[margin]) {
153
153
  levels[margin] = {};
154
154
  }
155
155
  if (!rootMargin || rootMargin < 0) {
156
156
  rootMargin = margin;
157
157
  rootIndex = listIndex;
158
- items = blockNodes.filter(function (e) { return e.getAttribute('datalist') === String(rootIndex); });
158
+ items = blockNodes.filter(e => e.getAttribute('datalist') === String(rootIndex));
159
159
  lastRootLi = items[items.length - 1];
160
160
  rootList = createList(type, listType && listType.style);
161
161
  p.parentNode.insertBefore(rootList, p);
@@ -179,11 +179,12 @@ var toList = function (blockNodes) {
179
179
  }
180
180
  }
181
181
  };
182
- var convertMsLists = function (html) {
183
- var container = (0, source_1.htmlToFragment)(extractListLevels(html));
184
- var groups = new Set();
182
+ const convertMsLists = (html) => {
183
+ const container = source.htmlToFragment(extractListLevels(html));
184
+ const groups = new Set();
185
185
  mapListsCandidates(container.children, groups);
186
- groups.forEach(function (listsCandidates) { return toList(listsCandidates); });
187
- return (0, source_1.fragmentToHtml)(container);
186
+ groups.forEach(listsCandidates => toList(listsCandidates));
187
+ return source.fragmentToHtml(container);
188
188
  };
189
+
189
190
  exports.convertMsLists = convertMsLists;
@@ -1,8 +1,8 @@
1
- import { NodeType, Node } from 'prosemirror-model';
1
+ import { Node } from 'prosemirror-model';
2
2
  import { EditorState, Transaction } from 'prosemirror-state';
3
3
  import { EditorView } from 'prosemirror-view';
4
- import { Command } from './types/command';
5
- declare type ListOptions = {
4
+
5
+ type ListOptions = {
6
6
  listType: string;
7
7
  orderedList: string;
8
8
  bulletList: string;
@@ -15,9 +15,9 @@ declare type ListOptions = {
15
15
  * @param attrs - The attributes of the list node
16
16
  * @returns The extracted list-style-type.
17
17
  */
18
- export declare const listStyle: (attrs: Node['attrs']) => string;
19
- export declare const toggleList: (state: EditorState, dispatch: (tr: Transaction) => void, view: EditorView, options: ListOptions, command?: string) => boolean;
20
- export declare function toggleUnorderedList(state: EditorState, dispatch: (tr: Transaction) => void, view: EditorView): any;
21
- export declare function toggleOrderedList(state: EditorState, dispatch: (tr: Transaction) => void, view: EditorView): any;
22
- export declare const splitListItemKeepMarks: (itemType: NodeType) => Command;
23
- export {};
18
+ declare const listStyle: (attrs: Node["attrs"]) => string;
19
+ declare const toggleList: (state: EditorState, dispatch: (tr: Transaction) => void, view: EditorView, options: ListOptions, command?: string) => boolean;
20
+ declare function toggleUnorderedList(state: EditorState, dispatch: (tr: Transaction) => void, view: EditorView): any;
21
+ declare function toggleOrderedList(state: EditorState, dispatch: (tr: Transaction) => void, view: EditorView): any;
22
+
23
+ export { listStyle, toggleList, toggleOrderedList, toggleUnorderedList };