@progress/kendo-editor-common 1.11.9-dev.202412020819 → 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 +34 -52
  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,8 +1,8 @@
1
- import { Node, Fragment } from 'prosemirror-model';
2
- import { TextSelection, AllSelection, NodeSelection } from 'prosemirror-state';
1
+ import { Node } from 'prosemirror-model';
2
+ import { NodeSelection, TextSelection, AllSelection } from 'prosemirror-state';
3
3
  import { parseInlineStyles } from '@progress/kendo-common';
4
- import { parseContent } from './source';
5
- export const changeStylesString = (styleText, newStyle) => {
4
+
5
+ const changeStylesString = (styleText, newStyle) => {
6
6
  const styleToChange = newStyle.style;
7
7
  const regExp = newStyle.value;
8
8
  const newValue = newStyle.newValue;
@@ -27,7 +27,7 @@ export const changeStylesString = (styleText, newStyle) => {
27
27
  };
28
28
  };
29
29
  const reAnyValue = /^.+$/;
30
- export function setNodeStyle(nodeAttrs, styleType, value) {
30
+ function setNodeStyle(nodeAttrs, styleType, value) {
31
31
  let attrs;
32
32
  if (new RegExp('[^-]?' + styleType + ':').test(nodeAttrs.style || '')) {
33
33
  const { style } = changeStylesString(nodeAttrs.style || '', { style: styleType, value: reAnyValue, newValue: value });
@@ -44,7 +44,7 @@ export function setNodeStyle(nodeAttrs, styleType, value) {
44
44
  /**
45
45
  * Determines if a given node type can be inserted at the current cursor position.
46
46
  */
47
- export const canInsert = (state, nodeType) => {
47
+ const canInsert = (state, nodeType) => {
48
48
  const $from = state.selection.$from;
49
49
  for (let d = $from.depth; d >= 0; d--) {
50
50
  const index = $from.index(d);
@@ -71,12 +71,12 @@ const findNthParentNode = (predicate, depth = 1) => {
71
71
  }
72
72
  };
73
73
  };
74
- export const findNthParentNodeOfType = (nodeType, depth = 1) => {
74
+ const findNthParentNodeOfType = (nodeType, depth = 1) => {
75
75
  return (selection) => {
76
76
  return findNthParentNode((node) => getTypeName(node) === getTypeName(nodeType), depth)(selection);
77
77
  };
78
78
  };
79
- export function parentNode(pos, predicate) {
79
+ function parentNode(pos, predicate) {
80
80
  for (let depth = pos.depth; depth > 0; depth--) {
81
81
  const node = pos.node(depth);
82
82
  if (predicate(node)) {
@@ -97,7 +97,7 @@ const filterEmptyAttrs = (attrs) => {
97
97
  /**
98
98
  * Inserts the given node at the place of current selection.
99
99
  */
100
- export const insertNode = (node, scrollIntoView) => (state, dispatch) => {
100
+ const insertNode = (node, scrollIntoView) => (state, dispatch) => {
101
101
  const { selection, tr } = state;
102
102
  if (selection instanceof NodeSelection
103
103
  && selection.node.type.name === node.type.name
@@ -113,12 +113,7 @@ export const insertNode = (node, scrollIntoView) => (state, dispatch) => {
113
113
  }
114
114
  dispatch(tr);
115
115
  };
116
- export const hasSameMarkup = (dom1, dom2, schema, parseOptions) => {
117
- const fragment1 = Fragment.from(parseContent(dom1, schema, parseOptions));
118
- const fragment2 = Fragment.from(parseContent(dom2, schema, parseOptions));
119
- return fragment1.eq(fragment2);
120
- };
121
- export const getSelectionText = (state) => {
116
+ const getSelectionText = (state) => {
122
117
  const sel = state.selection;
123
118
  if (sel instanceof TextSelection || sel instanceof AllSelection) {
124
119
  const fragment = sel.content().content;
@@ -126,7 +121,7 @@ export const getSelectionText = (state) => {
126
121
  }
127
122
  return '';
128
123
  };
129
- export const getNodeFromSelection = (state) => {
124
+ const getNodeFromSelection = (state) => {
130
125
  if (state.selection instanceof NodeSelection) {
131
126
  return state.selection.node;
132
127
  }
@@ -139,7 +134,7 @@ export const getNodeFromSelection = (state) => {
139
134
  * Useful for values of the inputs of Link and Find&Replace dialogs where the inputs value has been retrieved from the selection and
140
135
  * should be single line text only.
141
136
  */
142
- export const selectedLineTextOnly = (state) => {
137
+ const selectedLineTextOnly = (state) => {
143
138
  let result = '', hasLeafs = false;
144
139
  const { selection, doc } = state;
145
140
  const { $from, $to, from, to } = selection;
@@ -156,13 +151,13 @@ export const selectedLineTextOnly = (state) => {
156
151
  /**
157
152
  * Used by ViewHtml/ViewSource dialogs for making the HTML more readable.
158
153
  */
159
- export const indentHtml = (content) => {
154
+ const indentHtml = (content) => {
160
155
  return content.replace(/<\/(p|li|ul|ol|h[1-6]|table|tr|td|th)>/ig, '</$1>\n')
161
156
  .replace(/<(ul|ol)([^>]*)><li/ig, '<$1$2>\n<li')
162
157
  .replace(/<br \/>/ig, '<br />\n')
163
158
  .replace(/\n$/, '');
164
159
  };
165
- export const shallowEqual = (object1, object2) => {
160
+ const shallowEqual = (object1, object2) => {
166
161
  const keys1 = Object.keys(object1);
167
162
  const keys2 = Object.keys(object2);
168
163
  return keys1.length === keys2.length &&
@@ -173,7 +168,7 @@ const applyToWordDefault = { before: /[^ !,?.\[\]{}()]+$/i, after: /^[^ !,?.\[\]
173
168
  * if options.applyToWord is set, expands the selection to the word where the cursor is and
174
169
  * returns modified state and dispatch.
175
170
  */
176
- export const expandSelection = (state, dispatch, options) => {
171
+ const expandSelection = (state, dispatch, options) => {
177
172
  if (!options.applyToWord || !state.selection.empty) {
178
173
  return { state, dispatch };
179
174
  }
@@ -249,16 +244,16 @@ export const expandSelection = (state, dispatch, options) => {
249
244
  * const command = expandToWordWrap(toggleInlineFormat, {...bold, applyToWord );
250
245
  * command(view.state, view.dispatch);
251
246
  */
252
- export const expandToWordWrap = (command, options) => {
247
+ const expandToWordWrap = (command, options) => {
253
248
  return (state, dispatch) => {
254
249
  const { state: cmdState, dispatch: cmdDispatch } = expandSelection(state, dispatch, options);
255
250
  return command(options)(cmdState, cmdDispatch);
256
251
  };
257
252
  };
258
- export const parseStyle = (styleText) => {
253
+ const parseStyle = (styleText) => {
259
254
  return parseInlineStyles(styleText);
260
255
  };
261
- export const applyStyle = (styleText, styleType, styleValue) => {
256
+ const applyStyle = (styleText, styleType, styleValue) => {
262
257
  const styles = parseStyle(styleText);
263
258
  styles[styleType] = styleValue;
264
259
  const result = Object.keys(styles)
@@ -267,7 +262,7 @@ export const applyStyle = (styleText, styleType, styleValue) => {
267
262
  .join('; ');
268
263
  return result ? result + ';' : null;
269
264
  };
270
- export const setStyleAttr = (element, styleString) => {
265
+ const setStyleAttr = (element, styleString) => {
271
266
  const styles = parseStyle(styleString);
272
267
  for (const style in styles) {
273
268
  if (style && typeof element.style[style] !== 'undefined') {
@@ -275,7 +270,7 @@ export const setStyleAttr = (element, styleString) => {
275
270
  }
276
271
  }
277
272
  };
278
- export const setAttribute = (node, attrName, value) => {
273
+ const setAttribute = (node, attrName, value) => {
279
274
  const current = node.getAttribute(attrName);
280
275
  if (value !== undefined && value !== current) {
281
276
  if (attrName === 'style') {
@@ -290,3 +285,5 @@ export const setAttribute = (node, attrName, value) => {
290
285
  node.removeAttribute(attrName);
291
286
  }
292
287
  };
288
+
289
+ export { applyStyle, canInsert, changeStylesString, expandSelection, expandToWordWrap, findNthParentNodeOfType, getNodeFromSelection, getSelectionText, indentHtml, insertNode, parentNode, parseStyle, selectedLineTextOnly, setAttribute, setNodeStyle, setStyleAttr, shallowEqual };
@@ -1,28 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DOMSerializer = void 0;
4
- var utils_1 = require("./utils");
5
- var DOMSerializer = /** @class */ (function () {
6
- /// Create a serializer. `nodes` should map node names to functions
7
- /// that take a node and return a description of the corresponding
8
- /// DOM. `marks` does the same for mark names, but also gets an
9
- /// argument that tells it whether the mark's content is block or
10
- /// inline content (for typical use, it'll always be inline). A mark
11
- /// serializer may be `null` to indicate that marks of that type
12
- /// should not be serialized.
13
- function DOMSerializer(
14
- /// The node serialization functions.
15
- nodes,
16
- /// The mark serialization functions.
17
- marks) {
18
- this.nodes = nodes;
19
- this.marks = marks;
20
- }
1
+ 'use strict';
2
+
3
+ var utils = require('./utils.js');
4
+
5
+ class DOMSerializer {
21
6
  /// Render an [output spec](#model.DOMOutputSpec) to a DOM node. If
22
7
  /// the spec has a hole (zero) in it, `contentDOM` will point at the
23
8
  /// node with the hole.
24
- DOMSerializer.renderSpec = function (docum, structure, xmlNS) {
25
- if (xmlNS === void 0) { xmlNS = null; }
9
+ static renderSpec(docum, structure, xmlNS = null) {
26
10
  if (typeof structure === 'string') {
27
11
  return { dom: docum.createTextNode(structure) };
28
12
  }
@@ -32,38 +16,38 @@ var DOMSerializer = /** @class */ (function () {
32
16
  if (structure.dom && structure.dom.nodeType != null) {
33
17
  return structure;
34
18
  }
35
- var tagName = structure[0], space = tagName.indexOf(' ');
19
+ let tagName = structure[0], space = tagName.indexOf(' ');
36
20
  if (space > 0) {
37
21
  xmlNS = tagName.slice(0, space);
38
22
  tagName = tagName.slice(space + 1);
39
23
  }
40
- var contentDOM;
41
- var dom = (xmlNS ? docum.createElementNS(xmlNS, tagName) : docum.createElement(tagName));
42
- var attrs = structure[1], start = 1;
24
+ let contentDOM;
25
+ const dom = (xmlNS ? docum.createElementNS(xmlNS, tagName) : docum.createElement(tagName));
26
+ let attrs = structure[1], start = 1;
43
27
  if (attrs && typeof attrs === 'object' && attrs.nodeType == null && !Array.isArray(attrs)) {
44
28
  start = 2;
45
- for (var name_1 in attrs) {
46
- if (attrs[name_1] != null) {
47
- space = name_1.indexOf(' ');
29
+ for (const name in attrs) {
30
+ if (attrs[name] != null) {
31
+ space = name.indexOf(' ');
48
32
  if (space > 0) {
49
- dom.setAttributeNS(name_1.slice(0, space), name_1.slice(space + 1), attrs[name_1]);
33
+ dom.setAttributeNS(name.slice(0, space), name.slice(space + 1), attrs[name]);
50
34
  }
51
35
  else {
52
- (0, utils_1.setAttribute)(dom, name_1, attrs[name_1]);
36
+ utils.setAttribute(dom, name, attrs[name]);
53
37
  }
54
38
  }
55
39
  }
56
40
  }
57
- for (var i = start; i < structure.length; i++) {
58
- var child = structure[i];
41
+ for (let i = start; i < structure.length; i++) {
42
+ const child = structure[i];
59
43
  if (child === 0) {
60
44
  if (i < structure.length - 1 || i > start) {
61
45
  throw new RangeError('Content hole must be the only child of its parent node');
62
46
  }
63
- return { dom: dom, contentDOM: dom };
47
+ return { dom, contentDOM: dom };
64
48
  }
65
49
  else {
66
- var _a = DOMSerializer.renderSpec(docum, child, xmlNS), inner = _a.dom, innerContent = _a.contentDOM;
50
+ const { dom: inner, contentDOM: innerContent } = DOMSerializer.renderSpec(docum, child, xmlNS);
67
51
  dom.appendChild(inner);
68
52
  if (innerContent) {
69
53
  if (contentDOM) {
@@ -73,44 +57,57 @@ var DOMSerializer = /** @class */ (function () {
73
57
  }
74
58
  }
75
59
  }
76
- return { dom: dom, contentDOM: contentDOM };
77
- };
60
+ return { dom, contentDOM };
61
+ }
78
62
  /// Build a serializer using the [`toDOM`](#model.NodeSpec.toDOM)
79
63
  /// properties in a schema's node and mark specs.
80
- DOMSerializer.fromSchema = function (schema) {
64
+ static fromSchema(schema) {
81
65
  return schema.cached.domSerializer ||
82
66
  (schema.cached.domSerializer = new DOMSerializer(this.nodesFromSchema(schema), this.marksFromSchema(schema)));
83
- };
67
+ }
84
68
  /// Gather the serializers in a schema's node specs into an object.
85
69
  /// This can be useful as a base to build a custom serializer from.
86
- DOMSerializer.nodesFromSchema = function (schema) {
87
- var result = gatherToDOM(schema.nodes);
70
+ static nodesFromSchema(schema) {
71
+ const result = gatherToDOM(schema.nodes);
88
72
  if (!result.text) {
89
- result.text = function (node) { return node.text; };
73
+ result.text = node => node.text;
90
74
  }
91
75
  return result;
92
- };
76
+ }
93
77
  /// Gather the serializers in a schema's mark specs into an object.
94
- DOMSerializer.marksFromSchema = function (schema) {
78
+ static marksFromSchema(schema) {
95
79
  return gatherToDOM(schema.marks);
96
- };
80
+ }
81
+ /// Create a serializer. `nodes` should map node names to functions
82
+ /// that take a node and return a description of the corresponding
83
+ /// DOM. `marks` does the same for mark names, but also gets an
84
+ /// argument that tells it whether the mark's content is block or
85
+ /// inline content (for typical use, it'll always be inline). A mark
86
+ /// serializer may be `null` to indicate that marks of that type
87
+ /// should not be serialized.
88
+ constructor(
89
+ /// The node serialization functions.
90
+ nodes,
91
+ /// The mark serialization functions.
92
+ marks) {
93
+ this.nodes = nodes;
94
+ this.marks = marks;
95
+ }
97
96
  /// Serialize the content of this fragment to a DOM fragment. When
98
97
  /// not in the browser, the `document` option, containing a DOM
99
98
  /// document, should be passed so that the serializer can create
100
99
  /// nodes.
101
- DOMSerializer.prototype.serializeFragment = function (fragment, options, target) {
102
- var _this = this;
103
- if (options === void 0) { options = {}; }
100
+ serializeFragment(fragment, options = {}, target) {
104
101
  if (!target) {
105
102
  target = doc(options).createDocumentFragment();
106
103
  }
107
- var top = target, active = [];
108
- fragment.forEach(function (node) {
104
+ let top = target, active = [];
105
+ fragment.forEach(node => {
109
106
  if (active.length || node.marks.length) {
110
- var keep = 0, rendered = 0;
107
+ let keep = 0, rendered = 0;
111
108
  while (keep < active.length && rendered < node.marks.length) {
112
- var next = node.marks[rendered];
113
- if (!_this.marks[next.type.name]) {
109
+ const next = node.marks[rendered];
110
+ if (!this.marks[next.type.name]) {
114
111
  rendered++;
115
112
  continue;
116
113
  }
@@ -124,8 +121,8 @@ var DOMSerializer = /** @class */ (function () {
124
121
  top = active.pop()[1];
125
122
  }
126
123
  while (rendered < node.marks.length) {
127
- var add = node.marks[rendered++];
128
- var markDOM = _this.serializeMark(add, node.isInline, options);
124
+ const add = node.marks[rendered++];
125
+ const markDOM = this.serializeMark(add, node.isInline, options);
129
126
  if (markDOM) {
130
127
  active.push([add, top]);
131
128
  top.appendChild(markDOM.dom);
@@ -133,36 +130,34 @@ var DOMSerializer = /** @class */ (function () {
133
130
  }
134
131
  }
135
132
  }
136
- top.appendChild(_this.serializeNodeInner(node, options));
133
+ top.appendChild(this.serializeNodeInner(node, options));
137
134
  });
138
135
  return target;
139
- };
136
+ }
140
137
  /// Serialize this node to a DOM node. This can be useful when you
141
138
  /// need to serialize a part of a document, as opposed to the whole
142
139
  /// document. To serialize a whole document, use
143
140
  /// [`serializeFragment`](#model.DOMSerializer.serializeFragment) on
144
141
  /// its [content](#model.Node.content).
145
- DOMSerializer.prototype.serializeNode = function (node, options) {
146
- if (options === void 0) { options = {}; }
147
- var dom = this.serializeNodeInner(node, options);
148
- for (var i = node.marks.length - 1; i >= 0; i--) {
149
- var wrap = this.serializeMark(node.marks[i], node.isInline, options);
142
+ serializeNode(node, options = {}) {
143
+ let dom = this.serializeNodeInner(node, options);
144
+ for (let i = node.marks.length - 1; i >= 0; i--) {
145
+ const wrap = this.serializeMark(node.marks[i], node.isInline, options);
150
146
  if (wrap) {
151
147
  (wrap.contentDOM || wrap.dom).appendChild(dom);
152
148
  dom = wrap.dom;
153
149
  }
154
150
  }
155
151
  return dom;
156
- };
152
+ }
157
153
  /// @internal
158
- DOMSerializer.prototype.serializeMark = function (mark, inline, options) {
159
- if (options === void 0) { options = {}; }
160
- var toDOM = this.marks[mark.type.name];
154
+ serializeMark(mark, inline, options = {}) {
155
+ const toDOM = this.marks[mark.type.name];
161
156
  return toDOM && DOMSerializer.renderSpec(doc(options), toDOM(mark, inline));
162
- };
157
+ }
163
158
  /// @internal
164
- DOMSerializer.prototype.serializeNodeInner = function (node, options) {
165
- var _a = DOMSerializer.renderSpec(doc(options), this.nodes[node.type.name](node)), dom = _a.dom, contentDOM = _a.contentDOM;
159
+ serializeNodeInner(node, options) {
160
+ const { dom, contentDOM } = DOMSerializer.renderSpec(doc(options), this.nodes[node.type.name](node));
166
161
  if (contentDOM) {
167
162
  if (node.isLeaf) {
168
163
  throw new RangeError('Content hole not allowed in a leaf node spec');
@@ -170,17 +165,15 @@ var DOMSerializer = /** @class */ (function () {
170
165
  this.serializeFragment(node.content, options, contentDOM);
171
166
  }
172
167
  return dom;
173
- };
174
- return DOMSerializer;
175
- }());
176
- exports.DOMSerializer = DOMSerializer;
168
+ }
169
+ }
177
170
  function gatherToDOM(obj) {
178
- var result = {};
179
- for (var name_2 in obj) {
180
- if (obj[name_2]) {
181
- var toDOM = obj[name_2].spec.toDOM;
171
+ const result = {};
172
+ for (const name in obj) {
173
+ if (obj[name]) {
174
+ const toDOM = obj[name].spec.toDOM;
182
175
  if (toDOM) {
183
- result[name_2] = toDOM;
176
+ result[name] = toDOM;
184
177
  }
185
178
  }
186
179
  }
@@ -189,3 +182,5 @@ function gatherToDOM(obj) {
189
182
  function doc(options) {
190
183
  return options.document || window.document;
191
184
  }
185
+
186
+ exports.DOMSerializer = DOMSerializer;
@@ -1,10 +1,13 @@
1
1
  import { EditorState } from 'prosemirror-state';
2
- import { AlignRule } from './config/align-rules';
3
- import { Command } from './types/command';
2
+ import { AlignRule } from './config/align-rules.js';
3
+ import { Command } from './types/command.js';
4
+
4
5
  /**
5
6
  * Aligning block elements in the selection.
6
7
  *
7
8
  * @returns {boolean} - Returns true if any alignment is applied.
8
9
  */
9
- export declare const alignBlocks: (actions: Array<AlignRule>, commandName?: string) => Command;
10
- export declare const isAligned: (state: EditorState, actions: Array<AlignRule>) => boolean;
10
+ declare const alignBlocks: (actions: Array<AlignRule>, commandName?: string) => Command;
11
+ declare const isAligned: (state: EditorState, actions: Array<AlignRule>) => boolean;
12
+
13
+ export { alignBlocks, isAligned };
package/dist/npm/align.js CHANGED
@@ -1,45 +1,46 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAligned = exports.alignBlocks = void 0;
4
- var blockNode_1 = require("./blockNode");
1
+ 'use strict';
2
+
3
+ var blockNode = require('./blockNode.js');
4
+
5
5
  /**
6
6
  * Aligning block elements in the selection.
7
7
  *
8
8
  * @returns {boolean} - Returns true if any alignment is applied.
9
9
  */
10
- var alignBlocks = function (actions, commandName) { return function (state, dispatch) {
11
- var blocks = (0, blockNode_1.blockNodes)(state);
12
- var tr = state.tr;
10
+ const alignBlocks = (actions, commandName) => (state, dispatch) => {
11
+ const blocks = blockNode.blockNodes(state);
12
+ const tr = state.tr;
13
13
  tr.setMeta('commandName', commandName);
14
- blocks.forEach(function (node) {
14
+ blocks.forEach(node => {
15
15
  if (node.type.isTextblock) {
16
- var action = actions.find(function (n) { return n.node === node.type.name; });
16
+ const action = actions.find(n => n.node === node.type.name);
17
17
  if (action) {
18
- var newAttrs = (0, blockNode_1.addStyles)(node, action.style);
19
- (0, blockNode_1.changeTextBlock)(tr, node, node.type, newAttrs);
18
+ const newAttrs = blockNode.addStyles(node, action.style);
19
+ blockNode.changeTextBlock(tr, node, node.type, newAttrs);
20
20
  }
21
21
  }
22
22
  });
23
- var result = tr.docChanged;
23
+ const result = tr.docChanged;
24
24
  if (result) {
25
25
  dispatch(tr.scrollIntoView());
26
26
  }
27
27
  return result;
28
- }; };
29
- exports.alignBlocks = alignBlocks;
30
- var isAligned = function (state, actions) {
31
- var blocks = (0, blockNode_1.blockNodes)(state);
32
- var result = false;
33
- blocks.forEach(function (node) {
28
+ };
29
+ const isAligned = (state, actions) => {
30
+ const blocks = blockNode.blockNodes(state);
31
+ let result = false;
32
+ blocks.forEach(node => {
34
33
  if (!result && node.type.isTextblock && node.attrs.style) {
35
- var action = actions.find(function (a) { return a.node === node.type.name; });
34
+ const action = actions.find(a => a.node === node.type.name);
36
35
  if (action) {
37
- result = action.style.every(function (style) {
38
- return !!style.value && new RegExp("".concat(style.name, ":\\s?").concat(style.value), 'i').test(node.attrs.style);
36
+ result = action.style.every(style => {
37
+ return !!style.value && new RegExp(`${style.name}:\\s?${style.value}`, 'i').test(node.attrs.style);
39
38
  });
40
39
  }
41
40
  }
42
41
  });
43
42
  return result;
44
43
  };
44
+
45
+ exports.alignBlocks = alignBlocks;
45
46
  exports.isAligned = isAligned;
@@ -1,13 +1,14 @@
1
- import { NodeType, Node } from 'prosemirror-model';
2
- import { EditorState, Transaction, Selection } from 'prosemirror-state';
3
- import { CleanFormattingOptions } from './cleanFormatting';
1
+ import { Node, NodeType } from 'prosemirror-model';
2
+ import { Transaction, EditorState, Selection } from 'prosemirror-state';
3
+ import { CleanFormattingOptions } from './cleanFormatting.js';
4
+
4
5
  /**
5
6
  * Changes the type or the attributes of the passed node.
6
7
  *
7
8
  * @example
8
9
  * See `cleanTextBlockFormatting` or `formatBlockElements` function.
9
10
  */
10
- export declare const changeTextBlock: (tr: Transaction, node: Node, nodeType: NodeType, attrs?: {
11
+ declare const changeTextBlock: (tr: Transaction, node: Node, nodeType: NodeType, attrs?: {
11
12
  [key: string]: any;
12
13
  }) => boolean;
13
14
  /**
@@ -16,13 +17,13 @@ export declare const changeTextBlock: (tr: Transaction, node: Node, nodeType: No
16
17
  * @example
17
18
  * See `cleanTextBlockFormatting` function.
18
19
  */
19
- export declare const blockNodes: (state: EditorState | {
20
+ declare const blockNodes: (state: EditorState | {
20
21
  doc: Node;
21
22
  selection: Selection;
22
23
  }, options?: {
23
24
  blocksInSelection: boolean;
24
25
  }) => Array<Node>;
25
- export declare const formatBlockElements: (value: 'p' | 'blockquote' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6', commandName?: string) => (state: any, dispatch: any) => any;
26
+ declare const formatBlockElements: (value: "p" | "blockquote" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6", commandName?: string) => (state: any, dispatch: any) => any;
26
27
  /**
27
28
  * Removes the style and class attributes of text block elements.
28
29
  * Requires to dispatch the transaction.
@@ -30,17 +31,15 @@ export declare const formatBlockElements: (value: 'p' | 'blockquote' | 'h1' | 'h
30
31
  * @example
31
32
  * See `cleanFormatting` function.
32
33
  */
33
- export declare const cleanTextBlockFormatting: (tr: Transaction, options?: CleanFormattingOptions) => void;
34
- export declare const getBlockFormats: (state: EditorState) => Array<string>;
35
- export declare const addStyles: (node: Node, stylesToApply: Array<{
36
- name: string;
37
- value: string;
38
- }>) => {};
39
- export declare const hasNode: (state: EditorState, nodeType: NodeType) => boolean;
40
- export declare const parentBlockFormat: (state: EditorState) => string | null;
34
+ declare const cleanTextBlockFormatting: (tr: Transaction, options?: CleanFormattingOptions) => void;
35
+ declare const getBlockFormats: (state: EditorState) => Array<string>;
36
+ declare const hasNode: (state: EditorState, nodeType: NodeType) => boolean;
37
+ declare const parentBlockFormat: (state: EditorState) => string | null;
41
38
  /**
42
39
  * **Deprecated.** Use `parentBlockFormat` function instead.
43
40
  */
44
- export declare const activeNode: (state: EditorState) => {
41
+ declare const activeNode: (state: EditorState) => {
45
42
  tag: string;
46
43
  };
44
+
45
+ export { activeNode, blockNodes, changeTextBlock, cleanTextBlockFormatting, formatBlockElements, getBlockFormats, hasNode, parentBlockFormat };