handsontable 0.0.0-next-c3d199b-20230626 → 0.0.0-next-74a68c1-20230627

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of handsontable might be problematic. Click here for more details.

Files changed (37) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/base.js +2 -2
  3. package/base.mjs +2 -2
  4. package/dist/handsontable.css +2 -2
  5. package/dist/handsontable.full.css +2 -2
  6. package/dist/handsontable.full.js +3347 -3475
  7. package/dist/handsontable.full.min.css +2 -2
  8. package/dist/handsontable.full.min.js +53 -53
  9. package/dist/handsontable.js +5524 -5652
  10. package/dist/handsontable.min.css +2 -2
  11. package/dist/handsontable.min.js +4 -4
  12. package/helpers/mixed.js +2 -2
  13. package/helpers/mixed.mjs +2 -2
  14. package/package.json +1 -1
  15. package/plugins/comments/commentEditor.js +0 -1
  16. package/plugins/comments/commentEditor.mjs +0 -1
  17. package/plugins/comments/comments.js +231 -263
  18. package/plugins/comments/comments.mjs +241 -271
  19. package/plugins/copyPaste/copyPaste.js +1 -1
  20. package/plugins/copyPaste/copyPaste.mjs +1 -1
  21. package/plugins/filters/filters.js +62 -42
  22. package/plugins/filters/filters.mjs +61 -41
  23. package/shortcutContexts/commands/index.js +2 -1
  24. package/shortcutContexts/commands/index.mjs +2 -1
  25. package/shortcutContexts/commands/scrollToFocusedCell.js +38 -0
  26. package/shortcutContexts/commands/scrollToFocusedCell.mjs +33 -0
  27. package/shortcutContexts/grid.js +5 -0
  28. package/shortcutContexts/grid.mjs +5 -0
  29. package/tableView.js +2 -5
  30. package/tableView.mjs +2 -5
  31. package/translations/indexMapper.d.ts +0 -2
  32. package/plugins/comments/contextMenuItem/addEditComment.js +0 -51
  33. package/plugins/comments/contextMenuItem/addEditComment.mjs +0 -35
  34. package/plugins/comments/contextMenuItem/readOnlyComment.js +0 -63
  35. package/plugins/comments/contextMenuItem/readOnlyComment.mjs +0 -55
  36. package/plugins/comments/contextMenuItem/removeComment.js +0 -48
  37. package/plugins/comments/contextMenuItem/removeComment.mjs +0 -32
@@ -1,24 +1,10 @@
1
1
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- import "core-js/modules/es.array.concat.js";
3
- import "core-js/modules/es.array.iterator.js";
4
- import "core-js/modules/es.object.to-string.js";
5
- import "core-js/modules/es.string.iterator.js";
6
- import "core-js/modules/es.weak-map.js";
7
- import "core-js/modules/web.dom-collections.iterator.js";
8
- import "core-js/modules/es.symbol.to-primitive.js";
9
- import "core-js/modules/es.date.to-primitive.js";
10
- import "core-js/modules/es.symbol.js";
11
- import "core-js/modules/es.symbol.description.js";
12
- import "core-js/modules/es.number.constructor.js";
13
- import "core-js/modules/es.object.set-prototype-of.js";
14
- import "core-js/modules/es.object.get-prototype-of.js";
15
- import "core-js/modules/es.reflect.construct.js";
16
- import "core-js/modules/es.reflect.get.js";
17
- import "core-js/modules/es.object.get-own-property-descriptor.js";
18
- import "core-js/modules/es.symbol.iterator.js";
2
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
3
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
20
4
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
21
5
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
22
8
  function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
23
9
  function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
24
10
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
@@ -28,35 +14,37 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
28
14
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
29
15
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
30
16
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
31
- function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
32
- function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
33
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
34
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
35
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
36
- function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
37
- function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
38
- function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
39
- function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
40
- function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
17
+ import "core-js/modules/es.array.iterator.js";
18
+ import "core-js/modules/es.object.to-string.js";
19
+ import "core-js/modules/es.string.iterator.js";
20
+ import "core-js/modules/es.weak-map.js";
21
+ import "core-js/modules/web.dom-collections.iterator.js";
22
+ import "core-js/modules/es.object.set-prototype-of.js";
23
+ import "core-js/modules/es.object.get-prototype-of.js";
24
+ import "core-js/modules/es.reflect.construct.js";
25
+ import "core-js/modules/es.reflect.get.js";
26
+ import "core-js/modules/es.object.get-own-property-descriptor.js";
27
+ import "core-js/modules/es.symbol.to-primitive.js";
28
+ import "core-js/modules/es.date.to-primitive.js";
29
+ import "core-js/modules/es.symbol.js";
30
+ import "core-js/modules/es.symbol.description.js";
31
+ import "core-js/modules/es.number.constructor.js";
32
+ import "core-js/modules/es.symbol.iterator.js";
41
33
  import { addClass, closest, isChildOf, hasClass, outerWidth, outerHeight } from "../../helpers/dom/element.mjs";
42
- import { stopImmediatePropagation } from "../../helpers/dom/event.mjs";
43
34
  import { deepClone, deepExtend, isObject } from "../../helpers/object.mjs";
44
35
  import EventManager from "../../eventManager.mjs";
45
36
  import { BasePlugin } from "../base/index.mjs";
46
37
  import CommentEditor from "./commentEditor.mjs";
38
+ import { checkSelectionConsistency, markLabelAsSelected } from "../contextMenu/utils.mjs";
47
39
  import DisplaySwitch from "./displaySwitch.mjs";
48
- import { SEPARATOR } from "../contextMenu/predefinedItems.mjs";
49
- import addEditCommentItem from "./contextMenuItem/addEditComment.mjs";
50
- import removeCommentItem from "./contextMenuItem/removeComment.mjs";
51
- import readOnlyCommentItem from "./contextMenuItem/readOnlyComment.mjs";
40
+ import * as C from "../../i18n/constants.mjs";
52
41
  export var PLUGIN_KEY = 'comments';
53
42
  export var PLUGIN_PRIORITY = 60;
54
- export var META_COMMENT = 'comment';
55
- export var META_COMMENT_VALUE = 'value';
56
- export var META_STYLE = 'style';
57
- export var META_READONLY = 'readOnly';
58
- var SHORTCUTS_GROUP = PLUGIN_KEY;
59
- var SHORTCUTS_CONTEXT_NAME = "plugin:".concat(PLUGIN_KEY);
43
+ var privatePool = new WeakMap();
44
+ var META_COMMENT = 'comment';
45
+ var META_COMMENT_VALUE = 'value';
46
+ var META_STYLE = 'style';
47
+ var META_READONLY = 'readOnly';
60
48
 
61
49
  /* eslint-disable jsdoc/require-description-complete-sentence */
62
50
  /**
@@ -148,107 +136,63 @@ var SHORTCUTS_CONTEXT_NAME = "plugin:".concat(PLUGIN_KEY);
148
136
  * ```
149
137
  * :::
150
138
  */
151
- var _editor = /*#__PURE__*/new WeakMap();
152
- var _displaySwitch = /*#__PURE__*/new WeakMap();
153
- var _preventEditorAutoSwitch = /*#__PURE__*/new WeakMap();
154
- var _tempEditorDimensions = /*#__PURE__*/new WeakMap();
155
- var _cellBelowCursor = /*#__PURE__*/new WeakMap();
156
- var _commentValueBeforeSave = /*#__PURE__*/new WeakMap();
157
139
  export var Comments = /*#__PURE__*/function (_BasePlugin) {
158
140
  _inherits(Comments, _BasePlugin);
159
141
  var _super = _createSuper(Comments);
160
- function Comments() {
142
+ function Comments(hotInstance) {
161
143
  var _this;
162
144
  _classCallCheck(this, Comments);
163
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
164
- args[_key] = arguments[_key];
165
- }
166
- _this = _super.call.apply(_super, [this].concat(args));
167
- /**
168
- * Current cell range, an object with `from` property, with `row` and `col` properties (e.q. `{from: {row: 1, col: 6}}`).
169
- *
170
- * @type {object}
171
- */
172
- _defineProperty(_assertThisInitialized(_this), "range", {});
173
- /**
174
- * Instance of {@link EventManager}.
175
- *
176
- * @protected
177
- * @type {EventManager}
178
- */
179
- _defineProperty(_assertThisInitialized(_this), "eventManager", null);
145
+ _this = _super.call(this, hotInstance);
180
146
  /**
181
147
  * Instance of {@link CommentEditor}.
182
148
  *
183
149
  * @private
184
150
  * @type {CommentEditor}
185
151
  */
186
- _classPrivateFieldInitSpec(_assertThisInitialized(_this), _editor, {
187
- writable: true,
188
- value: null
189
- });
152
+ _this.editor = null;
190
153
  /**
191
154
  * Instance of {@link DisplaySwitch}.
192
155
  *
193
156
  * @private
194
157
  * @type {DisplaySwitch}
195
158
  */
196
- _classPrivateFieldInitSpec(_assertThisInitialized(_this), _displaySwitch, {
197
- writable: true,
198
- value: null
199
- });
159
+ _this.displaySwitch = null;
200
160
  /**
201
- * Prevents showing/hiding editor that reacts on the logic triggered by the "mouseover" events.
161
+ * Instance of {@link EventManager}.
202
162
  *
203
163
  * @private
204
- * @type {boolean}
164
+ * @type {EventManager}
205
165
  */
206
- _classPrivateFieldInitSpec(_assertThisInitialized(_this), _preventEditorAutoSwitch, {
207
- writable: true,
208
- value: false
209
- });
166
+ _this.eventManager = null;
210
167
  /**
211
- * The property for holding editor dimensions for further processing.
168
+ * Current cell range, an object with `from` property, with `row` and `col` properties (e.q. `{from: {row: 1, col: 6}}`).
212
169
  *
213
- * @private
214
170
  * @type {object}
215
171
  */
216
- _classPrivateFieldInitSpec(_assertThisInitialized(_this), _tempEditorDimensions, {
217
- writable: true,
218
- value: {}
219
- });
172
+ _this.range = {};
220
173
  /**
221
- * The flag that allows processing mousedown event correctly when comments editor is triggered.
174
+ * Prevents showing/hiding editor that reacts on the logic triggered by the "mouseover" events.
222
175
  *
223
176
  * @private
224
177
  * @type {boolean}
225
178
  */
226
- _classPrivateFieldInitSpec(_assertThisInitialized(_this), _cellBelowCursor, {
227
- writable: true,
228
- value: null
229
- });
230
- /**
231
- * Holds the comment value before it's actually saved to the cell meta.
232
- *
233
- * @private
234
- * @type {string}
235
- */
236
- _classPrivateFieldInitSpec(_assertThisInitialized(_this), _commentValueBeforeSave, {
237
- writable: true,
238
- value: ''
179
+ _this.preventEditorAutoSwitch = false;
180
+ privatePool.set(_assertThisInitialized(_this), {
181
+ tempEditorDimensions: {},
182
+ cellBelowCursor: null
239
183
  });
240
184
  return _this;
241
185
  }
186
+
187
+ /**
188
+ * Checks if the plugin is enabled in the handsontable settings. This method is executed in {@link Hooks#beforeInit}
189
+ * hook and if it returns `true` then the {@link Comments#enablePlugin} method is called.
190
+ *
191
+ * @returns {boolean}
192
+ */
242
193
  _createClass(Comments, [{
243
194
  key: "isEnabled",
244
- value:
245
- /**
246
- * Checks if the plugin is enabled in the handsontable settings. This method is executed in {@link Hooks#beforeInit}
247
- * hook and if it returns `true` then the {@link Comments#enablePlugin} method is called.
248
- *
249
- * @returns {boolean}
250
- */
251
- function isEnabled() {
195
+ value: function isEnabled() {
252
196
  return !!this.hot.getSettings()[PLUGIN_KEY];
253
197
  }
254
198
 
@@ -262,14 +206,14 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
262
206
  if (this.enabled) {
263
207
  return;
264
208
  }
265
- if (!_classPrivateFieldGet(this, _editor)) {
266
- _classPrivateFieldSet(this, _editor, new CommentEditor(this.hot.rootDocument, this.hot.isRtl()));
209
+ if (!this.editor) {
210
+ this.editor = new CommentEditor(this.hot.rootDocument, this.hot.isRtl());
267
211
  }
268
212
  if (!this.eventManager) {
269
213
  this.eventManager = new EventManager(this);
270
214
  }
271
- if (!_classPrivateFieldGet(this, _displaySwitch)) {
272
- _classPrivateFieldSet(this, _displaySwitch, new DisplaySwitch(this.getDisplayDelaySetting()));
215
+ if (!this.displaySwitch) {
216
+ this.displaySwitch = new DisplaySwitch(this.getDisplayDelaySetting());
273
217
  }
274
218
  this.addHook('afterContextMenuDefaultOptions', function (options) {
275
219
  return _this2.addToContextMenu(options);
@@ -286,16 +230,12 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
286
230
  this.addHook('afterBeginEditing', function () {
287
231
  return _this2.hide();
288
232
  });
289
- this.addHook('afterDocumentKeyDown', function (event) {
290
- return _this2.onAfterDocumentKeyDown(event);
291
- });
292
- _classPrivateFieldGet(this, _displaySwitch).addLocalHook('hide', function () {
233
+ this.displaySwitch.addLocalHook('hide', function () {
293
234
  return _this2.hide();
294
235
  });
295
- _classPrivateFieldGet(this, _displaySwitch).addLocalHook('show', function (row, col) {
236
+ this.displaySwitch.addLocalHook('show', function (row, col) {
296
237
  return _this2.showAtCell(row, col);
297
238
  });
298
- this.registerShortcuts();
299
239
  this.registerListeners();
300
240
  _get(_getPrototypeOf(Comments.prototype), "enablePlugin", this).call(this);
301
241
  }
@@ -309,8 +249,10 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
309
249
  }, {
310
250
  key: "updatePlugin",
311
251
  value: function updatePlugin() {
312
- _classPrivateFieldGet(this, _displaySwitch).updateDelay(this.getDisplayDelaySetting());
252
+ this.disablePlugin();
253
+ this.enablePlugin();
313
254
  _get(_getPrototypeOf(Comments.prototype), "updatePlugin", this).call(this);
255
+ this.displaySwitch.updateDelay(this.getDisplayDelaySetting());
314
256
  }
315
257
 
316
258
  /**
@@ -319,76 +261,9 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
319
261
  }, {
320
262
  key: "disablePlugin",
321
263
  value: function disablePlugin() {
322
- this.unregisterShortcuts();
323
264
  _get(_getPrototypeOf(Comments.prototype), "disablePlugin", this).call(this);
324
265
  }
325
266
 
326
- /**
327
- * Register shortcuts responsible for toggling context menu.
328
- *
329
- * @private
330
- */
331
- }, {
332
- key: "registerShortcuts",
333
- value: function registerShortcuts() {
334
- var _this3 = this;
335
- var manager = this.hot.getShortcutManager();
336
- var gridContext = manager.getContext('grid');
337
- var pluginContext = manager.addContext(SHORTCUTS_CONTEXT_NAME);
338
- gridContext.addShortcut({
339
- keys: [['Control', 'Alt', 'M']],
340
- callback: function callback() {
341
- var range = _this3.hot.getSelectedRangeLast();
342
- _this3.setRange(range);
343
- _this3.show();
344
- _this3.focusEditor();
345
- manager.setActiveContextName(SHORTCUTS_CONTEXT_NAME);
346
- },
347
- stopPropagation: true,
348
- runOnlyIf: function runOnlyIf() {
349
- var _this3$hot$getSelecte;
350
- return ((_this3$hot$getSelecte = _this3.hot.getSelectedRangeLast()) === null || _this3$hot$getSelecte === void 0 ? void 0 : _this3$hot$getSelecte.highlight.isCell()) && !_classPrivateFieldGet(_this3, _editor).isVisible();
351
- },
352
- group: SHORTCUTS_GROUP
353
- });
354
- pluginContext.addShortcut({
355
- keys: [['Escape']],
356
- callback: function callback() {
357
- _classPrivateFieldGet(_this3, _editor).setValue(_classPrivateFieldGet(_this3, _commentValueBeforeSave));
358
- _this3.hide();
359
- manager.setActiveContextName('grid');
360
- },
361
- runOnlyIf: function runOnlyIf() {
362
- var _this3$hot$getSelecte2;
363
- return ((_this3$hot$getSelecte2 = _this3.hot.getSelectedRangeLast()) === null || _this3$hot$getSelecte2 === void 0 ? void 0 : _this3$hot$getSelecte2.highlight.isCell()) && _classPrivateFieldGet(_this3, _editor).isVisible();
364
- },
365
- group: SHORTCUTS_GROUP
366
- });
367
- pluginContext.addShortcut({
368
- keys: [['Control/Meta', 'Enter']],
369
- callback: function callback() {
370
- _this3.hide();
371
- manager.setActiveContextName('grid');
372
- },
373
- runOnlyIf: function runOnlyIf() {
374
- var _this3$hot$getSelecte3;
375
- return ((_this3$hot$getSelecte3 = _this3.hot.getSelectedRangeLast()) === null || _this3$hot$getSelecte3 === void 0 ? void 0 : _this3$hot$getSelecte3.highlight.isCell()) && _classPrivateFieldGet(_this3, _editor).isVisible();
376
- },
377
- group: SHORTCUTS_GROUP
378
- });
379
- }
380
-
381
- /**
382
- * Unregister shortcuts responsible for toggling context menu.
383
- *
384
- * @private
385
- */
386
- }, {
387
- key: "unregisterShortcuts",
388
- value: function unregisterShortcuts() {
389
- this.hot.getShortcutManager().getContext('grid').removeShortcutsByGroup(SHORTCUTS_GROUP);
390
- }
391
-
392
267
  /**
393
268
  * Registers all necessary DOM listeners.
394
269
  *
@@ -397,29 +272,25 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
397
272
  }, {
398
273
  key: "registerListeners",
399
274
  value: function registerListeners() {
400
- var _this4 = this;
275
+ var _this3 = this;
401
276
  var rootDocument = this.hot.rootDocument;
402
- var editorElement = this.getEditorInputElement();
403
277
  this.eventManager.addEventListener(rootDocument, 'mouseover', function (event) {
404
- return _this4.onMouseOver(event);
278
+ return _this3.onMouseOver(event);
405
279
  });
406
280
  this.eventManager.addEventListener(rootDocument, 'mousedown', function (event) {
407
- return _this4.onMouseDown(event);
281
+ return _this3.onMouseDown(event);
408
282
  });
409
283
  this.eventManager.addEventListener(rootDocument, 'mouseup', function () {
410
- return _this4.onMouseUp();
284
+ return _this3.onMouseUp();
411
285
  });
412
- this.eventManager.addEventListener(editorElement, 'focus', function () {
413
- return _this4.onEditorFocus();
286
+ this.eventManager.addEventListener(this.editor.getInputElement(), 'blur', function () {
287
+ return _this3.onEditorBlur();
414
288
  });
415
- this.eventManager.addEventListener(editorElement, 'blur', function () {
416
- return _this4.onEditorBlur();
289
+ this.eventManager.addEventListener(this.editor.getInputElement(), 'mousedown', function (event) {
290
+ return _this3.onEditorMouseDown(event);
417
291
  });
418
- this.eventManager.addEventListener(editorElement, 'mousedown', function (event) {
419
- return _this4.onEditorMouseDown(event);
420
- });
421
- this.eventManager.addEventListener(editorElement, 'mouseup', function (event) {
422
- return _this4.onEditorMouseUp(event);
292
+ this.eventManager.addEventListener(this.editor.getInputElement(), 'mouseup', function (event) {
293
+ return _this3.onEditorMouseUp(event);
423
294
  });
424
295
  }
425
296
 
@@ -467,7 +338,7 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
467
338
  }, {
468
339
  key: "targetIsCommentTextArea",
469
340
  value: function targetIsCommentTextArea(event) {
470
- return this.getEditorInputElement() === event.target;
341
+ return this.editor.getInputElement() === event.target;
471
342
  }
472
343
 
473
344
  /**
@@ -481,7 +352,7 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
481
352
  if (!this.range.from) {
482
353
  throw new Error('Before using this method, first set cell range (hot.getPlugin("comment").setRange())');
483
354
  }
484
- var editorValue = _classPrivateFieldGet(this, _editor).getValue();
355
+ var editorValue = this.editor.getValue();
485
356
  var comment = '';
486
357
  if (value !== null && value !== void 0) {
487
358
  comment = value;
@@ -590,9 +461,8 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
590
461
  return false;
591
462
  }
592
463
  var meta = this.hot.getCellMeta(this.range.from.row, this.range.from.col);
593
- _classPrivateFieldGet(this, _displaySwitch).cancelHiding();
594
- _classPrivateFieldGet(this, _editor).setValue(meta[META_COMMENT] ? meta[META_COMMENT][META_COMMENT_VALUE] : null || '');
595
- _classPrivateFieldGet(this, _editor).show();
464
+ this.editor.setValue(meta[META_COMMENT] ? meta[META_COMMENT][META_COMMENT_VALUE] : null || '');
465
+ this.editor.show();
596
466
  this.refreshEditor(true);
597
467
  return true;
598
468
  }
@@ -619,7 +489,7 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
619
489
  }, {
620
490
  key: "hide",
621
491
  value: function hide() {
622
- _classPrivateFieldGet(this, _editor).hide();
492
+ this.editor.hide();
623
493
  }
624
494
 
625
495
  /**
@@ -632,7 +502,7 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
632
502
  value: function refreshEditor() {
633
503
  var _renderableRow, _renderableColumn;
634
504
  var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
635
- if (!force && (!this.range.from || !_classPrivateFieldGet(this, _editor).isVisible())) {
505
+ if (!force && (!this.range.from || !this.editor.isVisible())) {
636
506
  return;
637
507
  }
638
508
  var _this$hot = this.hot,
@@ -648,7 +518,7 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
648
518
 
649
519
  // Reset the editor position to (0, 0) so the opening direction calculation wouldn't be influenced by its
650
520
  // previous position
651
- _classPrivateFieldGet(this, _editor).setPosition(0, 0);
521
+ this.editor.setPosition(0, 0);
652
522
  if (renderableRow === null) {
653
523
  renderableRow = rowIndexMapper.getRenderableFromVisualIndex(rowIndexMapper.getNearestNotHiddenIndex(visualRow, -1));
654
524
  }
@@ -671,9 +541,9 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
671
541
  }, true);
672
542
  var commentStyle = this.getCommentMeta(visualRow, visualColumn, META_STYLE);
673
543
  if (commentStyle) {
674
- _classPrivateFieldGet(this, _editor).setSize(commentStyle.width, commentStyle.height);
544
+ this.editor.setSize(commentStyle.width, commentStyle.height);
675
545
  } else {
676
- _classPrivateFieldGet(this, _editor).resetSize();
546
+ this.editor.resetSize();
677
547
  }
678
548
  var lastColWidth = isBeforeRenderedColumns ? 0 : wtTable.getStretchedColumnWidth(renderableColumn);
679
549
  var lastRowHeight = targetingPreviousRow && !isBeforeRenderedRows ? outerHeight(TD) : 0;
@@ -682,9 +552,9 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
682
552
  top = _TD$getBoundingClient.top,
683
553
  cellWidth = _TD$getBoundingClient.width,
684
554
  cellHeight = _TD$getBoundingClient.height;
685
- var _classPrivateFieldGet2 = _classPrivateFieldGet(this, _editor).getSize(),
686
- editorWidth = _classPrivateFieldGet2.width,
687
- editorHeight = _classPrivateFieldGet2.height;
555
+ var _this$editor$getSize = this.editor.getSize(),
556
+ editorWidth = _this$editor$getSize.width,
557
+ editorHeight = _this$editor$getSize.height;
688
558
  var _this$hot$rootWindow = this.hot.rootWindow,
689
559
  innerWidth = _this$hot$rootWindow.innerWidth,
690
560
  innerHeight = _this$hot$rootWindow.innerHeight;
@@ -704,17 +574,30 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
704
574
  if (top + editorHeight > innerHeight) {
705
575
  y -= editorHeight - cellHeight + 1;
706
576
  }
707
- _classPrivateFieldGet(this, _editor).setPosition(x, y);
708
- _classPrivateFieldGet(this, _editor).setReadOnlyState(this.getCommentMeta(visualRow, visualColumn, META_READONLY));
577
+ this.editor.setPosition(x, y);
578
+ this.editor.setReadOnlyState(this.getCommentMeta(visualRow, visualColumn, META_READONLY));
709
579
  }
710
580
 
711
581
  /**
712
- * Focuses the comments editor element.
582
+ * Checks if there is a comment for selected range.
583
+ *
584
+ * @private
585
+ * @returns {boolean}
713
586
  */
714
587
  }, {
715
- key: "focusEditor",
716
- value: function focusEditor() {
717
- _classPrivateFieldGet(this, _editor).focus();
588
+ key: "checkSelectionCommentsConsistency",
589
+ value: function checkSelectionCommentsConsistency() {
590
+ var selected = this.hot.getSelectedRangeLast();
591
+ if (!selected) {
592
+ return false;
593
+ }
594
+ var hasComment = false;
595
+ var cell = selected.getTopStartCorner(); // IN EXCEL THERE IS COMMENT ONLY FOR TOP LEFT CELL IN SELECTION
596
+
597
+ if (this.getCommentMeta(cell.row, cell.col, META_COMMENT_VALUE)) {
598
+ hasComment = true;
599
+ }
600
+ return hasComment;
718
601
  }
719
602
 
720
603
  /**
@@ -768,7 +651,7 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
768
651
  if (!this.hot.view || !this.hot.view._wt) {
769
652
  return;
770
653
  }
771
- if (!_classPrivateFieldGet(this, _preventEditorAutoSwitch) && !this.targetIsCommentTextArea(event)) {
654
+ if (!this.preventEditorAutoSwitch && !this.targetIsCommentTextArea(event)) {
772
655
  var eventCell = closest(event.target, 'TD', 'TBODY');
773
656
  var coordinates = null;
774
657
  if (eventCell) {
@@ -789,16 +672,17 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
789
672
  }, {
790
673
  key: "onMouseOver",
791
674
  value: function onMouseOver(event) {
675
+ var priv = privatePool.get(this);
792
676
  var rootDocument = this.hot.rootDocument;
793
- if (_classPrivateFieldGet(this, _preventEditorAutoSwitch) || _classPrivateFieldGet(this, _editor).isFocused() || hasClass(event.target, 'wtBorder') || _classPrivateFieldGet(this, _cellBelowCursor) === event.target || !_classPrivateFieldGet(this, _editor)) {
677
+ if (this.preventEditorAutoSwitch || this.editor.isFocused() || hasClass(event.target, 'wtBorder') || priv.cellBelowCursor === event.target || !this.editor) {
794
678
  return;
795
679
  }
796
- _classPrivateFieldSet(this, _cellBelowCursor, rootDocument.elementFromPoint(event.clientX, event.clientY));
680
+ priv.cellBelowCursor = rootDocument.elementFromPoint(event.clientX, event.clientY);
797
681
  if (this.targetIsCellWithComment(event)) {
798
682
  var range = this.hot._createCellRange(this.hot.getCoords(event.target));
799
- _classPrivateFieldGet(this, _displaySwitch).show(range);
683
+ this.displaySwitch.show(range);
800
684
  } else if (isChildOf(event.target, rootDocument) && !this.targetIsCommentTextArea(event)) {
801
- _classPrivateFieldGet(this, _displaySwitch).hide();
685
+ this.displaySwitch.hide();
802
686
  }
803
687
  }
804
688
 
@@ -810,7 +694,7 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
810
694
  }, {
811
695
  key: "onMouseUp",
812
696
  value: function onMouseUp() {
813
- _classPrivateFieldSet(this, _preventEditorAutoSwitch, false);
697
+ this.preventEditorAutoSwitch = false;
814
698
  }
815
699
 
816
700
  /**
@@ -829,33 +713,16 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
829
713
  }
830
714
 
831
715
  /**
832
- * Hook observer the "blur" event from the comments editor element. The hook clears the
833
- * editor content and gives back the keyboard shortcuts control by switching to the "grid" context.
716
+ * `blur` event callback for the comment editor.
834
717
  *
835
718
  * @private
836
719
  */
837
720
  }, {
838
721
  key: "onEditorBlur",
839
722
  value: function onEditorBlur() {
840
- _classPrivateFieldSet(this, _commentValueBeforeSave, '');
841
- this.hot.getShortcutManager().setActiveContextName('grid');
842
723
  this.setComment();
843
724
  }
844
725
 
845
- /**
846
- * Hook observer the "focus" event from the comments editor element. The hook takes the control of
847
- * the keyboard shortcuts by switching the context to plugins one.
848
- *
849
- * @private
850
- */
851
- }, {
852
- key: "onEditorFocus",
853
- value: function onEditorFocus() {
854
- _classPrivateFieldSet(this, _commentValueBeforeSave, this.getComment());
855
- this.hot.listen();
856
- this.hot.getShortcutManager().setActiveContextName(SHORTCUTS_CONTEXT_NAME);
857
- }
858
-
859
726
  /**
860
727
  * `mousedown` hook. Along with `onEditorMouseUp` used to simulate the textarea resizing event.
861
728
  *
@@ -865,10 +732,11 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
865
732
  }, {
866
733
  key: "onEditorMouseDown",
867
734
  value: function onEditorMouseDown(event) {
868
- _classPrivateFieldSet(this, _tempEditorDimensions, {
735
+ var priv = privatePool.get(this);
736
+ priv.tempEditorDimensions = {
869
737
  width: outerWidth(event.target),
870
738
  height: outerHeight(event.target)
871
- });
739
+ };
872
740
  }
873
741
 
874
742
  /**
@@ -880,9 +748,10 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
880
748
  }, {
881
749
  key: "onEditorMouseUp",
882
750
  value: function onEditorMouseUp(event) {
751
+ var priv = privatePool.get(this);
883
752
  var currentWidth = outerWidth(event.target);
884
753
  var currentHeight = outerHeight(event.target);
885
- if (currentWidth !== _classPrivateFieldGet(this, _tempEditorDimensions).width + 1 || currentHeight !== _classPrivateFieldGet(this, _tempEditorDimensions).height + 2) {
754
+ if (currentWidth !== priv.tempEditorDimensions.width + 1 || currentHeight !== priv.tempEditorDimensions.height + 2) {
886
755
  this.updateCommentMeta(this.range.from.row, this.range.from.col, _defineProperty({}, META_STYLE, {
887
756
  width: currentWidth,
888
757
  height: currentHeight
@@ -891,31 +760,144 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
891
760
  }
892
761
 
893
762
  /**
894
- * Observes the pressed keys and if there is already opened the comment editor prevents open
895
- * the table editor into the fast edit mode.
763
+ * Context Menu's "Add comment" callback. Results in showing the comment editor.
896
764
  *
897
- * @param {Event} event The keydown event.
765
+ * @private
898
766
  */
899
767
  }, {
900
- key: "onAfterDocumentKeyDown",
901
- value: function onAfterDocumentKeyDown(event) {
902
- if (_classPrivateFieldGet(this, _editor).isVisible()) {
903
- stopImmediatePropagation(event);
904
- }
768
+ key: "onContextMenuAddComment",
769
+ value: function onContextMenuAddComment() {
770
+ var coords = this.hot.getSelectedRangeLast();
771
+ this.preventEditorAutoSwitch = true;
772
+ this.displaySwitch.cancelHiding();
773
+ this.setRange({
774
+ from: coords.highlight
775
+ });
776
+ this.show();
777
+ this.hot.deselectCell();
778
+ this.editor.focus();
779
+ }
780
+
781
+ /**
782
+ * Context Menu's "remove comment" callback.
783
+ *
784
+ * @private
785
+ */
786
+ }, {
787
+ key: "onContextMenuRemoveComment",
788
+ value: function onContextMenuRemoveComment() {
789
+ var _this4 = this;
790
+ var coords = this.hot.getSelectedRangeLast();
791
+ this.preventEditorAutoSwitch = true;
792
+ coords.forAll(function (row, column) {
793
+ if (row >= 0 && column >= 0) {
794
+ _this4.removeCommentAtCell(row, column, false);
795
+ }
796
+ });
797
+ this.hot.render();
798
+ }
799
+
800
+ /**
801
+ * Context Menu's "make comment read-only" callback.
802
+ *
803
+ * @private
804
+ */
805
+ }, {
806
+ key: "onContextMenuMakeReadOnly",
807
+ value: function onContextMenuMakeReadOnly() {
808
+ var _this5 = this;
809
+ var coords = this.hot.getSelectedRangeLast();
810
+ this.preventEditorAutoSwitch = true;
811
+ coords.forAll(function (row, column) {
812
+ if (row >= 0 && column >= 0) {
813
+ var currentState = !!_this5.getCommentMeta(row, column, META_READONLY);
814
+ _this5.updateCommentMeta(row, column, _defineProperty({}, META_READONLY, !currentState));
815
+ }
816
+ });
905
817
  }
906
818
 
907
819
  /**
908
820
  * Add Comments plugin options to the Context Menu.
909
821
  *
910
822
  * @private
911
- * @param {object} options The menu options.
823
+ * @param {object} defaultOptions The menu options.
912
824
  */
913
825
  }, {
914
826
  key: "addToContextMenu",
915
- value: function addToContextMenu(options) {
916
- options.items.push({
917
- name: SEPARATOR
918
- }, addEditCommentItem(this), removeCommentItem(this), readOnlyCommentItem(this));
827
+ value: function addToContextMenu(defaultOptions) {
828
+ var _this6 = this;
829
+ var isThereAnySelectedCellToProcess = function isThereAnySelectedCellToProcess() {
830
+ var range = _this6.hot.getSelectedRangeLast();
831
+ if (!range) {
832
+ return false;
833
+ }
834
+ if (range.isSingleHeader() || range.highlight.isHeader()) {
835
+ return false;
836
+ }
837
+ return _this6.hot.rowIndexMapper.getRenderableIndexesLength() > 0 && _this6.hot.columnIndexMapper.getRenderableIndexesLength() > 0;
838
+ };
839
+ defaultOptions.items.push({
840
+ name: '---------'
841
+ }, {
842
+ key: 'commentsAddEdit',
843
+ name: function name() {
844
+ if (_this6.checkSelectionCommentsConsistency()) {
845
+ return _this6.hot.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_EDIT_COMMENT);
846
+ }
847
+ return _this6.hot.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_ADD_COMMENT);
848
+ },
849
+ callback: function callback() {
850
+ return _this6.onContextMenuAddComment();
851
+ },
852
+ disabled: function disabled() {
853
+ if (!isThereAnySelectedCellToProcess()) {
854
+ return true;
855
+ }
856
+ return !(_this6.hot.getSelectedLast() && !_this6.hot.selection.isSelectedByCorner());
857
+ }
858
+ }, {
859
+ key: 'commentsRemove',
860
+ name: function name() {
861
+ return this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_REMOVE_COMMENT);
862
+ },
863
+ callback: function callback() {
864
+ return _this6.onContextMenuRemoveComment();
865
+ },
866
+ disabled: function disabled() {
867
+ if (!isThereAnySelectedCellToProcess()) {
868
+ return true;
869
+ }
870
+ return !(_this6.hot.getSelectedLast() && !_this6.hot.selection.isSelectedByCorner());
871
+ }
872
+ }, {
873
+ key: 'commentsReadOnly',
874
+ name: function name() {
875
+ var _this7 = this;
876
+ var label = this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_READ_ONLY_COMMENT);
877
+ var hasProperty = checkSelectionConsistency(this.getSelectedRangeLast(), function (row, col) {
878
+ var readOnlyProperty = _this7.getCellMeta(row, col)[META_COMMENT];
879
+ if (readOnlyProperty) {
880
+ readOnlyProperty = readOnlyProperty[META_READONLY];
881
+ }
882
+ if (readOnlyProperty) {
883
+ return true;
884
+ }
885
+ });
886
+ if (hasProperty) {
887
+ label = markLabelAsSelected(label);
888
+ }
889
+ return label;
890
+ },
891
+ callback: function callback() {
892
+ return _this6.onContextMenuMakeReadOnly();
893
+ },
894
+ disabled: function disabled() {
895
+ if (!isThereAnySelectedCellToProcess()) {
896
+ return true;
897
+ }
898
+ return !(_this6.hot.getSelectedLast() && !_this6.hot.selection.isSelectedByCorner()) || !_this6.checkSelectionCommentsConsistency();
899
+ }
900
+ });
919
901
  }
920
902
 
921
903
  /**
@@ -933,29 +915,17 @@ export var Comments = /*#__PURE__*/function (_BasePlugin) {
933
915
  }
934
916
  }
935
917
 
936
- /**
937
- * Gets the editors input element.
938
- *
939
- * @private
940
- * @returns {HTMLTextAreaElement}
941
- */
942
- }, {
943
- key: "getEditorInputElement",
944
- value: function getEditorInputElement() {
945
- return _classPrivateFieldGet(this, _editor).getInputElement();
946
- }
947
-
948
918
  /**
949
919
  * Destroys the plugin instance.
950
920
  */
951
921
  }, {
952
922
  key: "destroy",
953
923
  value: function destroy() {
954
- if (_classPrivateFieldGet(this, _editor)) {
955
- _classPrivateFieldGet(this, _editor).destroy();
924
+ if (this.editor) {
925
+ this.editor.destroy();
956
926
  }
957
- if (_classPrivateFieldGet(this, _displaySwitch)) {
958
- _classPrivateFieldGet(this, _displaySwitch).destroy();
927
+ if (this.displaySwitch) {
928
+ this.displaySwitch.destroy();
959
929
  }
960
930
  _get(_getPrototypeOf(Comments.prototype), "destroy", this).call(this);
961
931
  }