@progress/kendo-editor-common 1.11.9-dev.202411251354 → 1.11.9-develop.1

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 +388 -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 +13 -32
  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
package/dist/es/indent.js CHANGED
@@ -1,34 +1,35 @@
1
1
  import { sinkListItem, liftListItem } from 'prosemirror-schema-list';
2
- import { indentRules, outdentRules } from './config/indent-rules';
3
- import { blockNodes, addStyles, changeTextBlock, hasNode } from './blockNode';
4
- import { findNthParentNodeOfType } from './utils';
5
- import { liftBlockquote } from './blockquote';
2
+ import { indentRules, outdentRules } from './config/indent-rules.js';
3
+ import { blockNodes, addStyles, changeTextBlock, hasNode } from './blockNode.js';
4
+ import { findNthParentNodeOfType } from './utils.js';
5
+ import { liftBlockquote } from './blockquote.js';
6
+
6
7
  /**
7
8
  * Indenting block elements in the selection.
8
9
  *
9
10
  * @returns {boolean} - Returns true if any indentation is applied.
10
11
  */
11
- export var indentBlocks = function (actions, command, dir) { return function (state, dispatch) {
12
- var blocks = blockNodes(state);
13
- var tr = state.tr;
12
+ const indentBlocks = (actions, command, dir) => (state, dispatch) => {
13
+ const blocks = blockNodes(state);
14
+ const tr = state.tr;
14
15
  tr.setMeta('commandName', command);
15
- blocks.forEach(function (node) {
16
+ blocks.forEach(node => {
16
17
  if (node.type.isTextblock) {
17
- var newAttrs = void 0;
18
- var action = actions.find(function (a) { return a.node === node.type.name; });
18
+ let newAttrs;
19
+ const action = actions.find(a => a.node === node.type.name);
19
20
  if (action) {
20
- var style = dir === 'rtl' ? action.rtlStyle : action.style;
21
- var newStyle = {
21
+ const style = dir === 'rtl' ? action.rtlStyle : action.style;
22
+ const newStyle = {
22
23
  name: style,
23
- value: action.step > 0 ? "".concat(action.step).concat(action.unit) : ''
24
+ value: action.step > 0 ? `${action.step}${action.unit}` : ''
24
25
  };
25
26
  if (node.attrs.style) {
26
- var re = new RegExp("".concat(style, ":\\s?(\\d+)").concat(action.unit), 'i');
27
- var match = node.attrs.style.match(re);
27
+ const re = new RegExp(`${style}:\\s?(\\d+)${action.unit}`, 'i');
28
+ const match = node.attrs.style.match(re);
28
29
  if (match) {
29
- var newMargin = parseFloat(match[1]) + action.step;
30
+ let newMargin = parseFloat(match[1]) + action.step;
30
31
  newMargin = newMargin <= 0 ? '' : newMargin;
31
- newStyle.value = "".concat(newMargin).concat(newMargin ? action.unit : '');
32
+ newStyle.value = `${newMargin}${newMargin ? action.unit : ''}`;
32
33
  }
33
34
  }
34
35
  newAttrs = addStyles(node, [newStyle]);
@@ -38,47 +39,47 @@ export var indentBlocks = function (actions, command, dir) { return function (st
38
39
  }
39
40
  }
40
41
  });
41
- var result = tr.docChanged;
42
+ const result = tr.docChanged;
42
43
  if (result) {
43
44
  dispatch(tr.scrollIntoView());
44
45
  }
45
46
  return result;
46
- }; };
47
- export var isIndented = function (state, rules, dir) {
48
- var blocks = blockNodes(state);
49
- var result = false;
50
- blocks.forEach(function (node) {
47
+ };
48
+ const isIndented = (state, rules, dir) => {
49
+ const blocks = blockNodes(state);
50
+ let result = false;
51
+ blocks.forEach(node => {
51
52
  if (!result && node.type.isTextblock && node.attrs.style) {
52
- var action = rules.find(function (a) { return a.node === node.type.name; });
53
+ const action = rules.find(a => a.node === node.type.name);
53
54
  if (action) {
54
- var style = dir === 'rtl' ? action.rtlStyle : action.style;
55
- var reIndent = new RegExp("".concat(style, ":\\s?\\d+").concat(action.unit), 'i');
55
+ const style = dir === 'rtl' ? action.rtlStyle : action.style;
56
+ const reIndent = new RegExp(`${style}:\\s?\\d+${action.unit}`, 'i');
56
57
  result = reIndent.test(node.attrs.style);
57
58
  }
58
59
  }
59
60
  });
60
61
  return result;
61
62
  };
62
- export var canIndentAsListItem = function (state, nodeType) {
63
+ const canIndentAsListItem = (state, nodeType) => {
63
64
  return sinkListItem(nodeType)(state);
64
65
  };
65
- export var canOutdentAsListItem = function (state, rules) {
66
- var listItem = state.schema.nodes[rules.listsTypes.listItem];
67
- var orderedList = state.schema.nodes[rules.listsTypes.orderedList];
68
- var bulletList = state.schema.nodes[rules.listsTypes.bulletList];
69
- var isNestedInOL = !!findNthParentNodeOfType(orderedList, 2)(state.selection);
70
- var isNestedInUL = !!findNthParentNodeOfType(bulletList, 2)(state.selection);
66
+ const canOutdentAsListItem = (state, rules) => {
67
+ const listItem = state.schema.nodes[rules.listsTypes.listItem];
68
+ const orderedList = state.schema.nodes[rules.listsTypes.orderedList];
69
+ const bulletList = state.schema.nodes[rules.listsTypes.bulletList];
70
+ const isNestedInOL = !!findNthParentNodeOfType(orderedList, 2)(state.selection);
71
+ const isNestedInUL = !!findNthParentNodeOfType(bulletList, 2)(state.selection);
71
72
  return (isNestedInOL || isNestedInUL) && liftListItem(listItem)(state);
72
73
  };
73
- export var canBeIndented = function (state, rules) {
74
- var nodes = state.schema.nodes;
75
- var listItem = nodes[indentRules.listsTypes.listItem];
76
- return ((isIndented(state, rules.nodes) || indentRules.nodes.some(function (rule) { return nodes[rule.node] && hasNode(state, nodes[rule.node]); })) &&
74
+ const canBeIndented = (state, rules) => {
75
+ const nodes = state.schema.nodes;
76
+ const listItem = nodes[indentRules.listsTypes.listItem];
77
+ return ((isIndented(state, rules.nodes) || indentRules.nodes.some(rule => nodes[rule.node] && hasNode(state, nodes[rule.node]))) &&
77
78
  !hasNode(state, listItem));
78
79
  };
79
- export var indent = function (state, dispatch) {
80
- var listItem = state.schema.nodes[indentRules.listsTypes.listItem];
81
- var isIndentableBlock = canBeIndented(state, indentRules);
80
+ const indent = (state, dispatch) => {
81
+ const listItem = state.schema.nodes[indentRules.listsTypes.listItem];
82
+ const isIndentableBlock = canBeIndented(state, indentRules);
82
83
  if (canIndentAsListItem(state, listItem)) {
83
84
  sinkListItem(listItem)(state, dispatch);
84
85
  }
@@ -86,10 +87,10 @@ export var indent = function (state, dispatch) {
86
87
  indentBlocks(indentRules.nodes)(state, dispatch);
87
88
  }
88
89
  };
89
- export var outdent = function (state, dispatch) {
90
- var nodes = state.schema.nodes;
91
- var listItem = nodes[outdentRules.listsTypes.listItem];
92
- var isIndentableBlock = canBeIndented(state, outdentRules);
90
+ const outdent = (state, dispatch) => {
91
+ const nodes = state.schema.nodes;
92
+ const listItem = nodes[outdentRules.listsTypes.listItem];
93
+ const isIndentableBlock = canBeIndented(state, outdentRules);
93
94
  if (hasNode(state, nodes.blockquote)) {
94
95
  liftBlockquote(state, dispatch);
95
96
  }
@@ -100,3 +101,5 @@ export var outdent = function (state, dispatch) {
100
101
  indentBlocks(outdentRules.nodes)(state, dispatch);
101
102
  }
102
103
  };
104
+
105
+ export { canBeIndented, canIndentAsListItem, canOutdentAsListItem, indent, indentBlocks, isIndented, outdent };
@@ -1,32 +1,32 @@
1
- import { __assign, __spreadArray } from "tslib";
2
- import { AddMarkStep, RemoveMarkStep } from 'prosemirror-transform';
1
+ import { RemoveMarkStep, AddMarkStep } from 'prosemirror-transform';
3
2
  import { TextSelection } from 'prosemirror-state';
4
- import { changeStylesString, shallowEqual } from './utils';
5
- import { markApplies, hasMark, removeMarks, toggleMark, styleValue, selectionMarks } from './mark';
6
- var changeStyleFromMark = function (marks, toChange) {
7
- var styleMark = marks.find(function (m) { return m.type.name === 'style'; });
8
- var elementStyle = styleMark && styleMark.attrs.style;
3
+ import { changeStylesString, shallowEqual } from './utils.js';
4
+ import { selectionMarks, styleValue, hasMark, removeMarks, toggleMark, markApplies } from './mark.js';
5
+
6
+ const changeStyleFromMark = (marks, toChange) => {
7
+ const styleMark = marks.find(m => m.type.name === 'style');
8
+ const elementStyle = styleMark && styleMark.attrs.style;
9
9
  return changeStylesString(elementStyle, toChange);
10
10
  };
11
- var changeStyleMark = function (tr, from, to, attrs, markType) {
12
- var mark = markType.create({ style: attrs.style });
13
- var removed = [], added = [], removing = null, adding = null;
14
- tr.doc.nodesBetween(from, to, function (node, pos, parent) {
11
+ const changeStyleMark = (tr, from, to, attrs, markType) => {
12
+ const mark = markType.create({ style: attrs.style });
13
+ let removed = [], added = [], removing = null, adding = null;
14
+ tr.doc.nodesBetween(from, to, (node, pos, parent) => {
15
15
  if (!node.isInline) {
16
16
  return;
17
17
  }
18
- var marks = node.marks;
18
+ const marks = node.marks;
19
19
  if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) {
20
- var start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to);
21
- var newStyle = changeStyleFromMark(marks, attrs);
20
+ const start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to);
21
+ const newStyle = changeStyleFromMark(marks, attrs);
22
22
  if (newStyle.changed || attrs.newValue) {
23
- var style = newStyle.changed ?
24
- { style: newStyle.style || null } : { style: "".concat([attrs.style], ": ").concat(attrs.newValue, ";") };
25
- var currentMark = markType.isInSet(marks) ? marks.find(function (m) { return m.type.name === 'style'; }) : null;
26
- var newMarkAttrs_1 = currentMark ? __assign(__assign({}, currentMark.attrs), style) : style;
27
- var newStyleMark = markType.create(newMarkAttrs_1);
28
- var newSet = newStyleMark.addToSet(marks);
29
- for (var i = 0; i < marks.length; i++) {
23
+ const style = newStyle.changed ?
24
+ { style: newStyle.style || null } : { style: `${[attrs.style]}: ${attrs.newValue};` };
25
+ const currentMark = markType.isInSet(marks) ? marks.find(m => m.type.name === 'style') : null;
26
+ const newMarkAttrs = currentMark ? { ...currentMark.attrs, ...style } : style;
27
+ const newStyleMark = markType.create(newMarkAttrs);
28
+ const newSet = newStyleMark.addToSet(marks);
29
+ for (let i = 0; i < marks.length; i++) {
30
30
  if (!marks[i].isInSet(newSet)) {
31
31
  if (removing && removing.to === start && removing.mark.eq(marks[i])) {
32
32
  removing.to = end;
@@ -37,59 +37,59 @@ var changeStyleMark = function (tr, from, to, attrs, markType) {
37
37
  }
38
38
  }
39
39
  }
40
- var previousAdded = adding && adding.to === start;
41
- var sameAdding = previousAdded && newStyleMark.attrs.style === adding.mark.attrs.style;
40
+ const previousAdded = adding && adding.to === start;
41
+ const sameAdding = previousAdded && newStyleMark.attrs.style === adding.mark.attrs.style;
42
42
  if (previousAdded && sameAdding) {
43
43
  adding.to = end;
44
44
  }
45
- else if (Object.keys(newMarkAttrs_1).some(function (attrName) { return newMarkAttrs_1[attrName] !== null; })) {
45
+ else if (Object.keys(newMarkAttrs).some(attrName => newMarkAttrs[attrName] !== null)) {
46
46
  adding = new AddMarkStep(start, end, newStyleMark);
47
47
  added.push(adding);
48
48
  }
49
49
  }
50
50
  }
51
51
  });
52
- removed.forEach(function (s) { return tr.step(s); });
53
- added.forEach(function (s) { return tr.step(s); });
52
+ removed.forEach(s => tr.step(s));
53
+ added.forEach(s => tr.step(s));
54
54
  return removed.length + added.length > 0;
55
55
  };
56
56
  /**
57
57
  * Used by FontSize and FontName tools for getting their state.
58
58
  */
59
- export var getInlineStyles = function (state, style) {
60
- var styleMark = state.schema.marks.style;
61
- var marks = styleMark ? selectionMarks(state, styleMark) : [];
62
- return marks.map(function (mark) { return styleValue(mark, style); }).filter(function (m) { return m !== null; });
59
+ const getInlineStyles = (state, style) => {
60
+ const styleMark = state.schema.marks.style;
61
+ const marks = styleMark ? selectionMarks(state, styleMark) : [];
62
+ return marks.map(mark => styleValue(mark, style)).filter(m => m !== null);
63
63
  };
64
- var changeStyle = function (markType, attrs) {
64
+ const changeStyle = (markType, attrs) => {
65
65
  return function (state, dispatch, tr) {
66
- var _a = state.selection, empty = _a.empty, ranges = _a.ranges;
67
- var $cursor = state.selection instanceof TextSelection && state.selection.$cursor;
66
+ const { empty, ranges } = state.selection;
67
+ const $cursor = state.selection instanceof TextSelection && state.selection.$cursor;
68
68
  if ((empty && !$cursor) || !markApplies(state.doc, ranges, markType)) {
69
69
  return false;
70
70
  }
71
- var result = false;
71
+ let result = false;
72
72
  if (dispatch) {
73
- var transaction = tr || state.tr;
73
+ const transaction = tr || state.tr;
74
74
  if ($cursor) {
75
- var currentMarks = state.storedMarks || $cursor.marks();
75
+ const currentMarks = state.storedMarks || $cursor.marks();
76
76
  if (markType.isInSet(currentMarks)) {
77
- var newStyle = changeStyleFromMark(currentMarks, attrs);
78
- var styleMark = currentMarks.find(function (m) { return m.type.name === 'style'; });
79
- var newAttrs_1 = __assign(__assign({}, (styleMark ? styleMark.attrs : {})), { style: newStyle.style || null });
80
- if (shallowEqual(styleMark.attrs, newAttrs_1)) {
77
+ const newStyle = changeStyleFromMark(currentMarks, attrs);
78
+ const styleMark = currentMarks.find(m => m.type.name === 'style');
79
+ const newAttrs = { ...(styleMark ? styleMark.attrs : {}), style: newStyle.style || null };
80
+ if (shallowEqual(styleMark.attrs, newAttrs)) {
81
81
  return false;
82
82
  }
83
83
  dispatch(transaction.removeStoredMark(markType));
84
- if (Object.keys(newAttrs_1).some(function (attrName) { return newAttrs_1[attrName] !== null; })) {
85
- dispatch(transaction.addStoredMark(markType.create(newAttrs_1)));
84
+ if (Object.keys(newAttrs).some(attrName => newAttrs[attrName] !== null)) {
85
+ dispatch(transaction.addStoredMark(markType.create(newAttrs)));
86
86
  }
87
87
  result = true;
88
88
  }
89
89
  }
90
90
  else {
91
- for (var i = 0; i < ranges.length; i++) {
92
- var _b = ranges[i], $from = _b.$from, $to = _b.$to;
91
+ for (let i = 0; i < ranges.length; i++) {
92
+ const { $from, $to } = ranges[i];
93
93
  result = changeStyleMark(transaction, $from.pos, $to.pos, attrs, markType) || result;
94
94
  }
95
95
  if (result) {
@@ -104,19 +104,19 @@ var changeStyle = function (markType, attrs) {
104
104
  /**
105
105
  * Used by bold, italic, ... and link commands.
106
106
  */
107
- export var toggleInlineFormat = function (options, tr, markAttrs) { return function (state, dispatch) {
108
- var marks = state.schema.marks;
109
- var altStyle = options.altStyle, _a = options.altMarks, altMarks = _a === void 0 ? [] : _a, mark = options.mark;
110
- var transaction = tr || state.tr;
111
- var styleRemoved = false;
112
- var dispatched = false;
113
- var markDispatched = function () { return dispatched = true; };
107
+ const toggleInlineFormat = (options, tr, markAttrs) => (state, dispatch) => {
108
+ const marks = state.schema.marks;
109
+ const { altStyle, altMarks = [], mark } = options;
110
+ const transaction = tr || state.tr;
111
+ let styleRemoved = false;
112
+ let dispatched = false;
113
+ const markDispatched = () => dispatched = true;
114
114
  if (altStyle && marks.style) {
115
- var cmd = changeStyle(marks.style, { style: altStyle.name, value: altStyle.value });
115
+ const cmd = changeStyle(marks.style, { style: altStyle.name, value: altStyle.value });
116
116
  styleRemoved = cmd(state, markDispatched, transaction);
117
117
  }
118
- var allMarks = __spreadArray([mark], altMarks, true).filter(function (m) { return marks[m]; });
119
- var toRemove = allMarks.map(function (m) { return hasMark(state, { mark: m }) && marks[m]; }).filter(function (m) { return m; });
118
+ const allMarks = [mark, ...altMarks].filter(m => marks[m]);
119
+ const toRemove = allMarks.map(m => hasMark(state, { mark: m }) && marks[m]).filter(m => m);
120
120
  if (toRemove.length) {
121
121
  removeMarks(toRemove, state, markDispatched, transaction);
122
122
  }
@@ -129,42 +129,42 @@ export var toggleInlineFormat = function (options, tr, markAttrs) { return funct
129
129
  dispatch(transaction);
130
130
  }
131
131
  return dispatched;
132
- }; };
132
+ };
133
133
  /**
134
134
  * Used by FontSize, FontName, Color and BackColor commands.
135
135
  */
136
- export var applyInlineStyle = function (options, command) { return function (state, dispatch) {
137
- var marks = state.schema.marks;
138
- var markType = marks.style;
139
- var attrs = {
136
+ const applyInlineStyle = (options, command) => (state, dispatch) => {
137
+ const marks = state.schema.marks;
138
+ const markType = marks.style;
139
+ const attrs = {
140
140
  style: options.style, value: /^.+$/, newValue: options.value
141
141
  };
142
- var tr = state.tr;
142
+ const tr = state.tr;
143
143
  if (command) {
144
144
  tr.setMeta('commandName', command);
145
145
  }
146
146
  tr.setMeta('args', options);
147
- var _a = state.selection, empty = _a.empty, $cursor = _a.$cursor, ranges = _a.ranges;
147
+ const { empty, $cursor, ranges } = state.selection;
148
148
  if ((empty && !$cursor) || !markType || !markApplies(state.doc, ranges, markType)) {
149
149
  return false;
150
150
  }
151
151
  // Empty selection
152
152
  if ($cursor) {
153
- var marksFromSelection = state.storedMarks || $cursor.marks();
154
- var currentMark = markType.isInSet(marksFromSelection) ? marksFromSelection.find(function (m) { return m.type.name === 'style'; }) : null;
155
- var newStyles = { style: null };
153
+ const marksFromSelection = state.storedMarks || $cursor.marks();
154
+ const currentMark = markType.isInSet(marksFromSelection) ? marksFromSelection.find(m => m.type.name === 'style') : null;
155
+ const newStyles = { style: null };
156
156
  if (currentMark && currentMark.attrs.style) {
157
- var resultStyles = changeStylesString(currentMark.attrs.style, attrs);
157
+ const resultStyles = changeStylesString(currentMark.attrs.style, attrs);
158
158
  if (resultStyles.changed && resultStyles.style) {
159
159
  newStyles.style = resultStyles.style;
160
160
  }
161
161
  }
162
162
  else if (attrs.newValue) {
163
- newStyles.style = "".concat([attrs.style], ": ").concat(attrs.newValue, ";");
163
+ newStyles.style = `${[attrs.style]}: ${attrs.newValue};`;
164
164
  }
165
- var newMarkAttrs_2 = currentMark ? __assign(__assign({}, currentMark.attrs), newStyles) : newStyles;
166
- if (Object.keys(newMarkAttrs_2).some(function (attrName) { return newMarkAttrs_2[attrName] !== null; })) {
167
- dispatch(tr.addStoredMark(markType.create(newMarkAttrs_2)));
165
+ const newMarkAttrs = currentMark ? { ...currentMark.attrs, ...newStyles } : newStyles;
166
+ if (Object.keys(newMarkAttrs).some(attrName => newMarkAttrs[attrName] !== null)) {
167
+ dispatch(tr.addStoredMark(markType.create(newMarkAttrs)));
168
168
  }
169
169
  else {
170
170
  dispatch(tr.removeStoredMark(markType));
@@ -172,4 +172,6 @@ export var applyInlineStyle = function (options, command) { return function (sta
172
172
  return true;
173
173
  }
174
174
  return changeStyle(markType, attrs)(state, dispatch, tr);
175
- }; };
175
+ };
176
+
177
+ export { applyInlineStyle, getInlineStyles, toggleInlineFormat };
package/dist/es/link.js CHANGED
@@ -1,11 +1,12 @@
1
- import { toggleInlineFormat } from './inline-style';
2
- import { hasMark, toggleMark, removeMark, selectionMarks } from './mark';
1
+ import { toggleInlineFormat } from './inline-style.js';
2
+ import { removeMark, hasMark, selectionMarks, toggleMark } from './mark.js';
3
3
  import { EditorState } from 'prosemirror-state';
4
- var modifyLink = function (options, tr) { return function (state, dispatch) {
5
- var _a = state.selection, $cursor = _a.$cursor, from = _a.from, to = _a.to;
6
- var markType = state.schema.marks[options.mark];
4
+
5
+ const modifyLink = (options, tr) => (state, dispatch) => {
6
+ const { $cursor, from, to } = state.selection;
7
+ const markType = state.schema.marks[options.mark];
7
8
  if (!$cursor) {
8
- tr.doc.nodesBetween(from, to, function (node, pos) {
9
+ tr.doc.nodesBetween(from, to, (node, pos) => {
9
10
  if (node.isInline && markType.isInSet(node.marks)) {
10
11
  tr.removeMark(pos, pos + node.nodeSize, markType);
11
12
  tr.addMark(pos, pos + node.nodeSize, markType.create(options.attrs));
@@ -14,11 +15,11 @@ var modifyLink = function (options, tr) { return function (state, dispatch) {
14
15
  });
15
16
  }
16
17
  else {
17
- var parentNode = $cursor.parent;
18
- var cursorNodeIndex = $cursor.index();
19
- var mark = parentNode.child(cursorNodeIndex).marks.find(function (m) { return m.type === markType; });
20
- var childCount = parentNode.childCount;
21
- var linkStart = $cursor.pos - $cursor.textOffset, linkSize = parentNode.child(cursorNodeIndex).nodeSize, index = void 0, nodeSize = void 0;
18
+ const parentNode = $cursor.parent;
19
+ const cursorNodeIndex = $cursor.index();
20
+ const mark = parentNode.child(cursorNodeIndex).marks.find(m => m.type === markType);
21
+ const childCount = parentNode.childCount;
22
+ let linkStart = $cursor.pos - $cursor.textOffset, linkSize = parentNode.child(cursorNodeIndex).nodeSize, index, nodeSize;
22
23
  index = cursorNodeIndex - 1;
23
24
  while (index >= 0 && mark.isInSet(parentNode.child(index).marks)) {
24
25
  nodeSize = parentNode.child(index).nodeSize;
@@ -35,19 +36,19 @@ var modifyLink = function (options, tr) { return function (state, dispatch) {
35
36
  tr.addMark(linkStart, linkStart + linkSize, markType.create(options.attrs));
36
37
  dispatch(tr);
37
38
  }
38
- }; };
39
- export var removeLink = function (options, tr) { return function (state, dispatch) {
40
- var $cursor = state.selection.$cursor;
39
+ };
40
+ const removeLink = (options, tr) => (state, dispatch) => {
41
+ const { $cursor } = state.selection;
41
42
  if (!$cursor) {
42
43
  toggleInlineFormat(options, tr)(state, dispatch);
43
44
  }
44
45
  else {
45
- var parentNode = $cursor.parent;
46
- var cursorNodeIndex = $cursor.index();
47
- var toolMark_1 = state.schema.marks[options.mark];
48
- var mark = parentNode.child(cursorNodeIndex).marks.find(function (m) { return m.type === toolMark_1; });
49
- var childCount = parentNode.childCount;
50
- var linkStart = $cursor.pos - $cursor.textOffset, linkSize = parentNode.child(cursorNodeIndex).nodeSize, index = void 0, nodeSize = void 0;
46
+ const parentNode = $cursor.parent;
47
+ const cursorNodeIndex = $cursor.index();
48
+ const toolMark = state.schema.marks[options.mark];
49
+ const mark = parentNode.child(cursorNodeIndex).marks.find(m => m.type === toolMark);
50
+ const childCount = parentNode.childCount;
51
+ let linkStart = $cursor.pos - $cursor.textOffset, linkSize = parentNode.child(cursorNodeIndex).nodeSize, index, nodeSize;
51
52
  index = cursorNodeIndex - 1;
52
53
  while (index >= 0 && mark.isInSet(parentNode.child(index).marks)) {
53
54
  nodeSize = parentNode.child(index).nodeSize;
@@ -62,45 +63,43 @@ export var removeLink = function (options, tr) { return function (state, dispatc
62
63
  }
63
64
  dispatch(removeMark(tr || state.tr, linkStart, linkStart + linkSize, mark));
64
65
  }
65
- }; };
66
+ };
66
67
  /**
67
68
  * Returns a mark which wraps the selection.
68
69
  */
69
- var getParentMark = function (state, markType) {
70
- var marks = selectionMarks(state, markType);
70
+ const getParentMark = (state, markType) => {
71
+ const marks = selectionMarks(state, markType);
71
72
  return marks.length === 1 && marks[0] ? marks[0] : null;
72
73
  };
73
- export var applyLink = function (_a, commandName) {
74
- var mark = _a.mark, attrs = _a.attrs;
75
- if (commandName === void 0) { commandName = 'link'; }
76
- return function (state, dispatch) {
77
- var marks = state.schema.marks;
78
- var tr = state.tr;
79
- if (commandName) {
80
- tr.setMeta('commandName', commandName);
81
- tr.setMeta('args', attrs);
74
+ const applyLink = ({ mark, attrs }, commandName = 'link') => (state, dispatch) => {
75
+ const marks = state.schema.marks;
76
+ const tr = state.tr;
77
+ if (commandName) {
78
+ tr.setMeta('commandName', commandName);
79
+ tr.setMeta('args', attrs);
80
+ }
81
+ let dispatched = false;
82
+ const markDispatched = () => dispatched = true;
83
+ if (getParentMark(state, marks[mark])) {
84
+ modifyLink({ mark, attrs }, tr)(state, markDispatched);
85
+ }
86
+ else {
87
+ let nextState = state;
88
+ if (hasMark(state, { mark })) {
89
+ removeLink({ mark, attrs }, tr)(state, markDispatched);
90
+ nextState = EditorState.create({ doc: tr.doc, selection: tr.selection });
82
91
  }
83
- var dispatched = false;
84
- var markDispatched = function () { return dispatched = true; };
85
- if (getParentMark(state, marks[mark])) {
86
- modifyLink({ mark: mark, attrs: attrs }, tr)(state, markDispatched);
92
+ if (dispatched) {
93
+ toggleMark(marks[mark], attrs, tr)(nextState, markDispatched);
87
94
  }
88
95
  else {
89
- var nextState = state;
90
- if (hasMark(state, { mark: mark })) {
91
- removeLink({ mark: mark, attrs: attrs }, tr)(state, markDispatched);
92
- nextState = EditorState.create({ doc: tr.doc, selection: tr.selection });
93
- }
94
- if (dispatched) {
95
- toggleMark(marks[mark], attrs, tr)(nextState, markDispatched);
96
- }
97
- else {
98
- toggleInlineFormat({ mark: mark }, tr, attrs)(nextState, markDispatched);
99
- }
100
- }
101
- if (dispatched) {
102
- dispatch(tr);
96
+ toggleInlineFormat({ mark: mark }, tr, attrs)(nextState, markDispatched);
103
97
  }
104
- return dispatched;
105
- };
98
+ }
99
+ if (dispatched) {
100
+ dispatch(tr);
101
+ }
102
+ return dispatched;
106
103
  };
104
+
105
+ export { applyLink, removeLink };