@progress/kendo-editor-common 1.10.4-dev.202311091213 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -162,7 +162,7 @@ function handleMouseDown(view, event, cellMinWidth) {
162
162
  var widths = Array.from(col.parentNode.children).map(function (c) { return c.style.width; });
163
163
  if (widths.every(Boolean)) {
164
164
  var sum = widths.reduce(function (acc, cur) { return acc + parseFloat(cur); }, 0);
165
- tableAttrs = utils_2.setNodeStyle(tableAttrs || tableNode.attrs, 'width', sum + 'px');
165
+ tableAttrs = utils_1.setNodeStyle(tableAttrs || tableNode.attrs, 'width', sum + 'px');
166
166
  }
167
167
  }
168
168
  if (tableAttrs) {
@@ -216,7 +216,7 @@ function updateColumnWidth(view, tr, cell, _width) {
216
216
  }
217
217
  var tableDomWidth = tableDom.style.width;
218
218
  if (tableDom && tableDomWidth && utils_1.parseStyle(attrs.style).width !== tableDomWidth) {
219
- attrs = utils_2.setNodeStyle(attrs, 'width', tableDomWidth);
219
+ attrs = utils_1.setNodeStyle(attrs, 'width', tableDomWidth);
220
220
  }
221
221
  tr.setNodeMarkup(tablePos, null, attrs);
222
222
  }
@@ -182,13 +182,13 @@ function updateRowHeight(view, tr, cellPos) {
182
182
  var dom = view.nodeDOM(rowPos);
183
183
  var win = (dom.ownerDocument && dom.ownerDocument.defaultView) || window;
184
184
  dom.style.height = win.getComputedStyle(dom).height;
185
- tr.setNodeMarkup(rowPos, null, utils_1.setNodeStyle(row.attrs, 'height', dom.style.height));
185
+ tr.setNodeMarkup(rowPos, null, utils_2.setNodeStyle(row.attrs, 'height', dom.style.height));
186
186
  var table = dom && dom.closest('table');
187
187
  var tableHeight = table && table.style.height;
188
188
  if (tableHeight) {
189
189
  var $pos = doc.resolve(rowPos);
190
190
  var tablePos = $pos.start($pos.depth) - 1;
191
- tr.setNodeMarkup(tablePos, null, utils_1.setNodeStyle($pos.parent.attrs, 'height', tableHeight));
191
+ tr.setNodeMarkup(tablePos, null, utils_2.setNodeStyle($pos.parent.attrs, 'height', tableHeight));
192
192
  }
193
193
  }
194
194
  function displayRowHeight(view, cellPos, height, offset, tableHeight) {
@@ -81,19 +81,19 @@ var toPercents = function (view, tr, tablePos) {
81
81
  tableNode.forEach(function (row, offset, index) {
82
82
  var rowHeight = utils_2.parseStyle(row.attrs.style).height;
83
83
  if (rowHeight && !/%$/.test(rowHeight)) {
84
- tr.setNodeMarkup(tablePos + offset + 1, null, utils_1.setNodeStyle(row.attrs, 'height', (rowsHeight[index] * 100 / height) + '%'));
84
+ tr.setNodeMarkup(tablePos + offset + 1, null, utils_2.setNodeStyle(row.attrs, 'height', (rowsHeight[index] * 100 / height) + '%'));
85
85
  heightChange = true;
86
86
  }
87
87
  });
88
88
  var tableAttrs = tableNode.attrs;
89
89
  if (utils_2.parseStyle(tableAttrs.style).width !== offsetWidth + 'px') {
90
- tableAttrs = utils_1.setNodeStyle(tableAttrs, 'width', offsetWidth + 'px');
90
+ tableAttrs = utils_2.setNodeStyle(tableAttrs, 'width', offsetWidth + 'px');
91
91
  }
92
92
  if (widthChanged) {
93
93
  tableAttrs[constants_1.colgroupAttr] = colgroup.outerHTML;
94
94
  }
95
95
  if (heightChange) {
96
- tableAttrs = utils_1.setNodeStyle(tableAttrs, 'height', offsetHeight + 'px');
96
+ tableAttrs = utils_2.setNodeStyle(tableAttrs, 'height', offsetHeight + 'px');
97
97
  }
98
98
  if (widthChanged || heightChange) {
99
99
  tr.setNodeMarkup(tablePos, null, tableAttrs);
@@ -108,7 +108,7 @@ var toPixels = function (view, tr, tablePos, attrs) {
108
108
  tableNode.forEach(function (row, offset, index) {
109
109
  var rowHeight = utils_2.parseStyle(row.attrs.style).height;
110
110
  if (rowHeight && !/px$/.test(rowHeight)) {
111
- tr.setNodeMarkup(tablePos + offset + 1, null, utils_1.setNodeStyle(row.attrs, 'height', calcStyle(rows[index]).height));
111
+ tr.setNodeMarkup(tablePos + offset + 1, null, utils_2.setNodeStyle(row.attrs, 'height', calcStyle(rows[index]).height));
112
112
  }
113
113
  });
114
114
  var colgroup = tableDom.firstChild;
@@ -149,10 +149,10 @@ var handleMouseUp = function (view) {
149
149
  var attrs = node.attrs;
150
150
  var parsedStyles = utils_2.parseStyle(attrs.style);
151
151
  if (horizontalDir[activeHandle] && dom.style.width && parsedStyles.width !== width) {
152
- attrs = utils_1.setNodeStyle(attrs, 'width', width);
152
+ attrs = utils_2.setNodeStyle(attrs, 'width', width);
153
153
  }
154
154
  if (verticalDir[activeHandle] && dom.style.height && parsedStyles.height !== height) {
155
- attrs = utils_1.setNodeStyle(attrs, 'height', height);
155
+ attrs = utils_2.setNodeStyle(attrs, 'height', height);
156
156
  }
157
157
  attrs = toPixels(view, tr, nodePosition, attrs);
158
158
  tr.setNodeMarkup(nodePosition, null, attrs);
@@ -165,9 +165,9 @@ var handleMouseUp = function (view) {
165
165
  });
166
166
  if (!/%/.test(utils_2.parseStyle(attrs.style).width || '')) {
167
167
  var $pos = tr.doc.resolve(nodePosition);
168
- var wrapper = utils_1.parentNode($pos, function (n) { return n.type.name === 'table_wrapper'; });
168
+ var wrapper = utils_2.parentNode($pos, function (n) { return n.type.name === 'table_wrapper'; });
169
169
  if (wrapper && /%/.test(utils_2.parseStyle(wrapper.node.attrs.style).width || '')) {
170
- var wrapperAttrs = utils_1.setNodeStyle(wrapper.node.attrs, 'width', '');
170
+ var wrapperAttrs = utils_2.setNodeStyle(wrapper.node.attrs, 'width', '');
171
171
  var wrapperPos = $pos.start(wrapper.depth) - 1;
172
172
  tr.setNodeMarkup(wrapperPos, null, wrapperAttrs);
173
173
  }
@@ -217,7 +217,7 @@ var tableResizing = function (options) {
217
217
  if (isNodeSelected && selection instanceof prosemirror_state_1.NodeSelection) {
218
218
  return { node: selection.node, pos: selection.from };
219
219
  }
220
- var parent = utils_1.parentNode(selection.$from, function (n) { return n.type === nodeType; });
220
+ var parent = utils_2.parentNode(selection.$from, function (n) { return n.type === nodeType; });
221
221
  var node = parent && parent.node;
222
222
  if (node) {
223
223
  var pos = selection.$from.start(parent.depth) - 1;
@@ -1,8 +1,5 @@
1
- import { Node, ResolvedPos } from 'prosemirror-model';
2
1
  import { EditorState, PluginKey } from 'prosemirror-state';
3
2
  import { EditorView } from 'prosemirror-view';
4
- export declare const reAnyValue: RegExp;
5
- export declare function setNodeStyle(nodeAttrs: any, styleType: string, value: string): any;
6
3
  export declare const tableResizeKey: PluginKey<any>;
7
4
  export declare const tableColumnResizeKey: PluginKey<any>;
8
5
  export declare const tableRowResizeKey: PluginKey<any>;
@@ -14,10 +11,6 @@ export declare function cellIndexes(dataCell: HTMLTableCellElement): {
14
11
  cellIndex: number;
15
12
  rowIndex: number;
16
13
  };
17
- export declare function parentNode(pos: ResolvedPos, predicate: (node: Node) => boolean): {
18
- node: Node;
19
- depth: number;
20
- } | null;
21
14
  export declare function edgeCell(view: EditorView, event: MouseEvent, indexes: {
22
15
  cellIndex: number;
23
16
  rowIndex: number;
@@ -1,26 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.edgeCell = exports.parentNode = exports.cellIndexes = exports.domCellAround = exports.getTable = exports.otherResizeHandle = exports.otherResizing = exports.tableRowResizeKey = exports.tableColumnResizeKey = exports.tableResizeKey = exports.setNodeStyle = exports.reAnyValue = void 0;
4
- var tslib_1 = require("tslib");
3
+ exports.edgeCell = exports.cellIndexes = exports.domCellAround = exports.getTable = exports.otherResizeHandle = exports.otherResizing = exports.tableRowResizeKey = exports.tableColumnResizeKey = exports.tableResizeKey = void 0;
5
4
  var prosemirror_state_1 = require("prosemirror-state");
6
5
  var prosemirror_tables_1 = require("prosemirror-tables");
7
6
  var utils_1 = require("../../utils");
8
- exports.reAnyValue = /^.+$/;
9
- function setNodeStyle(nodeAttrs, styleType, value) {
10
- var attrs;
11
- if (new RegExp('[^-]?' + styleType + ':').test(nodeAttrs.style || '')) {
12
- var style = utils_1.changeStylesString(nodeAttrs.style || '', { style: styleType, value: exports.reAnyValue, newValue: value }).style;
13
- attrs = tslib_1.__assign(tslib_1.__assign({}, nodeAttrs), { style: style });
14
- }
15
- else if (nodeAttrs.style) {
16
- attrs = tslib_1.__assign(tslib_1.__assign({}, nodeAttrs), { style: nodeAttrs.style.replace(/;$/, '') + '; ' + styleType + ': ' + value + ';' });
17
- }
18
- else {
19
- attrs = tslib_1.__assign(tslib_1.__assign({}, nodeAttrs), { style: styleType + ': ' + value + ';' });
20
- }
21
- return attrs;
22
- }
23
- exports.setNodeStyle = setNodeStyle;
24
7
  exports.tableResizeKey = new prosemirror_state_1.PluginKey('table-resize');
25
8
  exports.tableColumnResizeKey = new prosemirror_state_1.PluginKey('table-column-resizing');
26
9
  exports.tableRowResizeKey = new prosemirror_state_1.PluginKey('table-row-resizing');
@@ -102,23 +85,13 @@ function cellIndexes(dataCell) {
102
85
  return result || { rowIndex: -1, cellIndex: -1 };
103
86
  }
104
87
  exports.cellIndexes = cellIndexes;
105
- function parentNode(pos, predicate) {
106
- for (var depth = pos.depth; depth > 0; depth--) {
107
- var node = pos.node(depth);
108
- if (predicate(node)) {
109
- return { node: node, depth: depth };
110
- }
111
- }
112
- return null;
113
- }
114
- exports.parentNode = parentNode;
115
88
  function edgeCell(view, event, indexes) {
116
89
  var found = view.posAtCoords({ left: event.clientX, top: event.clientY });
117
90
  if (!found) {
118
91
  return -1;
119
92
  }
120
93
  var $pos = view.state.doc.resolve(found.pos);
121
- var parentTable = parentNode($pos, function (n) { return n.type.spec.tableRole === 'table'; });
94
+ var parentTable = utils_1.parentNode($pos, function (n) { return n.type.spec.tableRole === 'table'; });
122
95
  if (parentTable === null) {
123
96
  return -1;
124
97
  }
@@ -1,4 +1,4 @@
1
- import { Node, NodeType, ParseOptions, Schema } from 'prosemirror-model';
1
+ import { Node, NodeType, ParseOptions, Schema, ResolvedPos } from 'prosemirror-model';
2
2
  import { EditorState } from 'prosemirror-state';
3
3
  import { Command } from './types/command';
4
4
  export declare const changeStylesString: (styleText: string, newStyle: {
@@ -9,11 +9,16 @@ export declare const changeStylesString: (styleText: string, newStyle: {
9
9
  changed: boolean;
10
10
  style: string | null;
11
11
  };
12
+ export declare function setNodeStyle(nodeAttrs: any, styleType: string, value: string): any;
12
13
  /**
13
14
  * Determines if a given node type can be inserted at the current cursor position.
14
15
  */
15
16
  export declare const canInsert: (state: EditorState, nodeType: NodeType) => boolean;
16
17
  export declare const findNthParentNodeOfType: (nodeType: NodeType, depth?: number) => Function;
18
+ export declare function parentNode(pos: ResolvedPos, predicate: (node: Node) => boolean): {
19
+ node: Node;
20
+ depth: number;
21
+ } | null;
17
22
  /**
18
23
  * Inserts the given node at the place of current selection.
19
24
  */
@@ -59,4 +64,5 @@ export declare const expandToWordWrap: (command: any, options: any) => (state: a
59
64
  export declare const parseStyle: (styleText: string | null) => {
60
65
  [x: string]: string;
61
66
  };
67
+ export declare const applyStyle: (styleText: string | null, styleType: string, styleValue: string) => string;
62
68
  export declare const setAttribute: (node: HTMLElement, attrName: string, value?: string) => void;
package/dist/npm/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setAttribute = exports.parseStyle = exports.expandToWordWrap = exports.expandSelection = exports.shallowEqual = exports.indentHtml = exports.selectedLineTextOnly = exports.getNodeFromSelection = exports.getSelectionText = exports.hasSameMarkup = exports.insertNode = exports.findNthParentNodeOfType = exports.canInsert = exports.changeStylesString = void 0;
3
+ exports.setAttribute = exports.applyStyle = exports.parseStyle = exports.expandToWordWrap = exports.expandSelection = exports.shallowEqual = exports.indentHtml = exports.selectedLineTextOnly = exports.getNodeFromSelection = exports.getSelectionText = exports.hasSameMarkup = exports.insertNode = exports.parentNode = exports.findNthParentNodeOfType = exports.canInsert = exports.setNodeStyle = exports.changeStylesString = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var prosemirror_model_1 = require("prosemirror-model");
6
6
  var prosemirror_state_1 = require("prosemirror-state");
@@ -26,6 +26,22 @@ var changeStylesString = function (styleText, newStyle) {
26
26
  };
27
27
  };
28
28
  exports.changeStylesString = changeStylesString;
29
+ var reAnyValue = /^.+$/;
30
+ function setNodeStyle(nodeAttrs, styleType, value) {
31
+ var attrs;
32
+ if (new RegExp('[^-]?' + styleType + ':').test(nodeAttrs.style || '')) {
33
+ var style = exports.changeStylesString(nodeAttrs.style || '', { style: styleType, value: reAnyValue, newValue: value }).style;
34
+ attrs = tslib_1.__assign(tslib_1.__assign({}, nodeAttrs), { style: style });
35
+ }
36
+ else if (nodeAttrs.style) {
37
+ attrs = tslib_1.__assign(tslib_1.__assign({}, nodeAttrs), { style: nodeAttrs.style.replace(/;$/, '') + '; ' + styleType + ': ' + value + ';' });
38
+ }
39
+ else {
40
+ attrs = tslib_1.__assign(tslib_1.__assign({}, nodeAttrs), { style: styleType + ': ' + value + ';' });
41
+ }
42
+ return attrs;
43
+ }
44
+ exports.setNodeStyle = setNodeStyle;
29
45
  /**
30
46
  * Determines if a given node type can be inserted at the current cursor position.
31
47
  */
@@ -65,6 +81,16 @@ var findNthParentNodeOfType = function (nodeType, depth) {
65
81
  };
66
82
  };
67
83
  exports.findNthParentNodeOfType = findNthParentNodeOfType;
84
+ function parentNode(pos, predicate) {
85
+ for (var depth = pos.depth; depth > 0; depth--) {
86
+ var node = pos.node(depth);
87
+ if (predicate(node)) {
88
+ return { node: node, depth: depth };
89
+ }
90
+ }
91
+ return null;
92
+ }
93
+ exports.parentNode = parentNode;
68
94
  var filterEmptyAttrs = function (attrs) {
69
95
  var result = {};
70
96
  for (var attr in attrs) {
@@ -256,6 +282,16 @@ var parseStyle = function (styleText) {
256
282
  return styles;
257
283
  };
258
284
  exports.parseStyle = parseStyle;
285
+ var applyStyle = function (styleText, styleType, styleValue) {
286
+ var styles = exports.parseStyle(styleText);
287
+ styles[styleType] = styleValue;
288
+ var result = Object.keys(styles)
289
+ .map(function (name) { return styles[name] ? name + ": " + styles[name] : null; })
290
+ .filter(Boolean)
291
+ .join('; ');
292
+ return result ? result + ';' : null;
293
+ };
294
+ exports.applyStyle = applyStyle;
259
295
  var setStyleAttr = function (element, styleString) {
260
296
  var styles = exports.parseStyle(styleString);
261
297
  for (var style in styles) {