@revolist/revogrid 4.0.10 → 4.0.12

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 (125) hide show
  1. package/dist/cjs/{column.service-e83d9809.js → column.service-bc269420.js} +23 -9
  2. package/dist/cjs/column.service-bc269420.js.map +1 -0
  3. package/dist/cjs/{events-7ccd6894.js → events-f8893bba.js} +15 -5
  4. package/dist/cjs/events-f8893bba.js.map +1 -0
  5. package/dist/cjs/{header-cell-renderer-8ba9b56d.js → header-cell-renderer-57acd2f7.js} +2 -2
  6. package/dist/cjs/{header-cell-renderer-8ba9b56d.js.map → header-cell-renderer-57acd2f7.js.map} +1 -1
  7. package/dist/cjs/{key.utils-dc4ac217.js → key.utils-59b9b528.js} +13 -1
  8. package/dist/cjs/key.utils-59b9b528.js.map +1 -0
  9. package/dist/cjs/revo-grid.cjs.entry.js +29 -13
  10. package/dist/cjs/revo-grid.cjs.entry.js.map +1 -1
  11. package/dist/cjs/revogr-attribution_6.cjs.entry.js +176 -131
  12. package/dist/cjs/revogr-attribution_6.cjs.entry.js.map +1 -1
  13. package/dist/cjs/revogr-clipboard_3.cjs.entry.js +28 -11
  14. package/dist/cjs/revogr-clipboard_3.cjs.entry.js.map +1 -1
  15. package/dist/cjs/revogr-data_4.cjs.entry.js +2 -2
  16. package/dist/collection/components/data/column.service.js.map +1 -1
  17. package/dist/collection/components/data/revogr-data.js +1 -1
  18. package/dist/collection/components/editors/edit.utils.js +4 -0
  19. package/dist/collection/components/editors/edit.utils.js.map +1 -1
  20. package/dist/collection/components/editors/revogr-edit.js +30 -12
  21. package/dist/collection/components/editors/revogr-edit.js.map +1 -1
  22. package/dist/collection/components/order/revogr-order-editor.js +4 -1
  23. package/dist/collection/components/order/revogr-order-editor.js.map +1 -1
  24. package/dist/collection/components/overlay/autofill.service.js +36 -24
  25. package/dist/collection/components/overlay/autofill.service.js.map +1 -1
  26. package/dist/collection/components/overlay/keyboard.service.js +7 -7
  27. package/dist/collection/components/overlay/keyboard.service.js.map +1 -1
  28. package/dist/collection/components/overlay/revogr-overlay-selection.js +107 -59
  29. package/dist/collection/components/overlay/revogr-overlay-selection.js.map +1 -1
  30. package/dist/collection/components/overlay/selection.utils.js +37 -9
  31. package/dist/collection/components/overlay/selection.utils.js.map +1 -1
  32. package/dist/collection/components/revoGrid/revo-grid-style.css +8 -3
  33. package/dist/collection/components/revoGrid/revo-grid.js +26 -11
  34. package/dist/collection/components/revoGrid/revo-grid.js.map +1 -1
  35. package/dist/collection/components/revoGrid/viewport.helpers.js +22 -8
  36. package/dist/collection/components/revoGrid/viewport.helpers.js.map +1 -1
  37. package/dist/collection/components/revoGrid/viewport.service.js +1 -0
  38. package/dist/collection/components/revoGrid/viewport.service.js.map +1 -1
  39. package/dist/collection/serve/controller.js +86 -18
  40. package/dist/collection/store/selection/index.js +0 -1
  41. package/dist/collection/store/selection/index.js.map +1 -1
  42. package/dist/collection/types/interfaces.js +4 -0
  43. package/dist/collection/types/interfaces.js.map +1 -1
  44. package/dist/collection/types/selection.js.map +1 -1
  45. package/dist/collection/utils/events.js +11 -1
  46. package/dist/collection/utils/events.js.map +1 -1
  47. package/dist/collection/utils/row-header-utils.js +2 -2
  48. package/dist/collection/utils/row-header-utils.js.map +1 -1
  49. package/dist/esm/{column.service-f4922a8d.js → column.service-195345ab.js} +23 -9
  50. package/dist/esm/column.service-195345ab.js.map +1 -0
  51. package/dist/esm/{events-3dd8ee7c.js → events-3e39de50.js} +15 -5
  52. package/dist/esm/events-3e39de50.js.map +1 -0
  53. package/dist/esm/{header-cell-renderer-ac962570.js → header-cell-renderer-7c76465d.js} +2 -2
  54. package/dist/esm/{header-cell-renderer-ac962570.js.map → header-cell-renderer-7c76465d.js.map} +1 -1
  55. package/dist/esm/{key.utils-4586a3d6.js → key.utils-2836e8ae.js} +12 -2
  56. package/dist/esm/key.utils-2836e8ae.js.map +1 -0
  57. package/dist/esm/revo-grid.entry.js +29 -13
  58. package/dist/esm/revo-grid.entry.js.map +1 -1
  59. package/dist/esm/revogr-attribution_6.entry.js +177 -132
  60. package/dist/esm/revogr-attribution_6.entry.js.map +1 -1
  61. package/dist/esm/revogr-clipboard_3.entry.js +28 -11
  62. package/dist/esm/revogr-clipboard_3.entry.js.map +1 -1
  63. package/dist/esm/revogr-data_4.entry.js +2 -2
  64. package/dist/revo-grid/column.service-195345ab.js +5 -0
  65. package/dist/revo-grid/column.service-195345ab.js.map +1 -0
  66. package/dist/revo-grid/{events-3dd8ee7c.js → events-3e39de50.js} +2 -2
  67. package/dist/revo-grid/events-3e39de50.js.map +1 -0
  68. package/dist/revo-grid/{header-cell-renderer-ac962570.js → header-cell-renderer-7c76465d.js} +2 -2
  69. package/dist/revo-grid/key.utils-2836e8ae.js +5 -0
  70. package/dist/revo-grid/key.utils-2836e8ae.js.map +1 -0
  71. package/dist/revo-grid/revo-grid.entry.js +1 -1
  72. package/dist/revo-grid/revo-grid.entry.js.map +1 -1
  73. package/dist/revo-grid/revogr-attribution_6.entry.js +1 -1
  74. package/dist/revo-grid/revogr-attribution_6.entry.js.map +1 -1
  75. package/dist/revo-grid/revogr-clipboard_3.entry.js +1 -1
  76. package/dist/revo-grid/revogr-clipboard_3.entry.js.map +1 -1
  77. package/dist/revo-grid/revogr-data_4.entry.js +1 -1
  78. package/dist/types/components/data/column.service.d.ts +2 -2
  79. package/dist/types/components/editors/edit.utils.d.ts +2 -0
  80. package/dist/types/components/order/revogr-order-editor.d.ts +3 -0
  81. package/dist/types/components/overlay/autofill.service.d.ts +9 -6
  82. package/dist/types/components/overlay/keyboard.service.d.ts +2 -3
  83. package/dist/types/components/overlay/revogr-overlay-selection.d.ts +38 -15
  84. package/dist/types/components/overlay/selection.utils.d.ts +12 -4
  85. package/dist/types/components/revoGrid/revo-grid.d.ts +4 -1
  86. package/dist/types/components/revoGrid/viewport.helpers.d.ts +11 -2
  87. package/dist/types/components.d.ts +26 -2
  88. package/dist/types/store/selection/index.d.ts +0 -1
  89. package/dist/types/types/interfaces.d.ts +444 -23
  90. package/dist/types/types/selection.d.ts +1 -1
  91. package/dist/types/utils/events.d.ts +4 -1
  92. package/dist/types/utils/row-header-utils.d.ts +1 -1
  93. package/hydrate/index.js +296 -179
  94. package/package.json +5 -6
  95. package/standalone/column.service.js.map +1 -1
  96. package/standalone/revo-grid.js +28 -11
  97. package/standalone/revo-grid.js.map +1 -1
  98. package/standalone/revogr-edit2.js +37 -11
  99. package/standalone/revogr-edit2.js.map +1 -1
  100. package/standalone/revogr-focus2.js +1 -1
  101. package/standalone/revogr-order-editor2.js.map +1 -1
  102. package/standalone/revogr-overlay-selection2.js +142 -150
  103. package/standalone/revogr-overlay-selection2.js.map +1 -1
  104. package/standalone/revogr-row-headers2.js +2 -2
  105. package/standalone/revogr-row-headers2.js.map +1 -1
  106. package/standalone/revogr-temp-range2.js +1 -1
  107. package/standalone/revogr-viewport-scroll2.js +22 -8
  108. package/standalone/revogr-viewport-scroll2.js.map +1 -1
  109. package/standalone/selection.utils.js +72 -9
  110. package/standalone/selection.utils.js.map +1 -1
  111. package/dist/cjs/column.service-e83d9809.js.map +0 -1
  112. package/dist/cjs/events-7ccd6894.js.map +0 -1
  113. package/dist/cjs/key.utils-dc4ac217.js.map +0 -1
  114. package/dist/collection/store/selection/selection.store.service.js +0 -39
  115. package/dist/collection/store/selection/selection.store.service.js.map +0 -1
  116. package/dist/esm/column.service-f4922a8d.js.map +0 -1
  117. package/dist/esm/events-3dd8ee7c.js.map +0 -1
  118. package/dist/esm/key.utils-4586a3d6.js.map +0 -1
  119. package/dist/revo-grid/column.service-f4922a8d.js +0 -5
  120. package/dist/revo-grid/column.service-f4922a8d.js.map +0 -1
  121. package/dist/revo-grid/events-3dd8ee7c.js.map +0 -1
  122. package/dist/revo-grid/key.utils-4586a3d6.js +0 -5
  123. package/dist/revo-grid/key.utils-4586a3d6.js.map +0 -1
  124. package/dist/types/store/selection/selection.store.service.d.ts +0 -17
  125. /package/dist/revo-grid/{header-cell-renderer-ac962570.js.map → header-cell-renderer-7c76465d.js.map} +0 -0
@@ -8,50 +8,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
8
8
  const index = require('./index-84e32c2a.js');
9
9
  const index$1 = require('./index-73c149e3.js');
10
10
  const dimension_helpers = require('./dimension.helpers-ee39d6c4.js');
11
- const column_service = require('./column.service-e83d9809.js');
11
+ const events = require('./events-f8893bba.js');
12
+ const column_service = require('./column.service-bc269420.js');
13
+ const key_utils = require('./key.utils-59b9b528.js');
12
14
  const selection_store = require('./selection.store-2e110a67.js');
13
- const key_utils = require('./key.utils-dc4ac217.js');
14
15
  const debounce = require('./debounce-e2b7c6fb.js');
15
- const events = require('./events-7ccd6894.js');
16
16
  const throttle = require('./throttle-f7aee21b.js');
17
17
  require('./toNumber-838e6ff5.js');
18
18
  require('./viewport.helpers-6670177c.js');
19
19
 
20
- class SelectionStoreService {
21
- constructor(store, config) {
22
- this.store = store;
23
- this.config = config;
24
- this.store = store;
25
- }
26
- get edited() {
27
- return this.store.get('edit');
28
- }
29
- get focused() {
30
- return this.store.get('focus');
31
- }
32
- get ranged() {
33
- return this.store.get('range');
34
- }
35
- changeRange(range) {
36
- return this.config.changeRange(range);
37
- }
38
- focus(cell, isMulti = false) {
39
- if (!cell) {
40
- return false;
41
- }
42
- let end = cell;
43
- // range edit
44
- if (isMulti) {
45
- let start = this.store.get('focus');
46
- if (start) {
47
- return this.config.changeRange(selection_store.getRange(start, end));
48
- }
49
- }
50
- // single focus
51
- return this.config.focus(cell, end);
52
- }
53
- }
54
-
55
20
  const Attribution = class {
56
21
  constructor(hostRef) {
57
22
  index.registerInstance(this, hostRef);
@@ -61,26 +26,50 @@ const Attribution = class {
61
26
  }
62
27
  };
63
28
 
64
- /** Calculate cell based on x, y position */
29
+ function getFocusCellBasedOnEvent(e, data) {
30
+ // If event default is prevented, return
31
+ if (e.defaultPrevented) {
32
+ return null;
33
+ }
34
+ // Get coordinates from event object
35
+ const x = events.getPropertyFromEvent(e, 'clientX');
36
+ const y = events.getPropertyFromEvent(e, 'clientY');
37
+ // If coordinates are not available, return
38
+ if (x === null || y === null) {
39
+ return null;
40
+ }
41
+ // Get current cell based on coordinates and data
42
+ const focusCell = getCurrentCell({ x, y }, data);
43
+ // If current cell is not available, return
44
+ if (isAfterLast(focusCell, data.lastCell)) {
45
+ return null;
46
+ }
47
+ return focusCell;
48
+ }
49
+ /**
50
+ * Calculate cell based on x, y position
51
+ */
65
52
  function getCurrentCell({ x, y }, { el, rows, cols }) {
53
+ // Get the bounding rectangle of the element
66
54
  const { top, left, height, width } = el.getBoundingClientRect();
55
+ // Calculate the cell position relative to the element
67
56
  let cellY = y - top;
68
- // limit to element height
57
+ let cellX = x - left;
58
+ // Limit the cell position to the element height
69
59
  if (cellY >= height) {
70
60
  cellY = height - 1;
71
61
  }
72
- let cellX = x - left;
73
- // limit to element width
62
+ // Limit the cell position to the element width
74
63
  if (cellX >= width) {
75
64
  cellX = width - 1;
76
65
  }
66
+ // Get the row and column items based on the cell position
77
67
  const rgRow = dimension_helpers.getItemByPosition(rows, cellY);
78
68
  const rgCol = dimension_helpers.getItemByPosition(cols, cellX);
79
- // before first
69
+ // Set the row and column index to 0 if they are before the first item
80
70
  if (rgCol.itemIndex < 0) {
81
71
  rgCol.itemIndex = 0;
82
72
  }
83
- // before first
84
73
  if (rgRow.itemIndex < 0) {
85
74
  rgRow.itemIndex = 0;
86
75
  }
@@ -102,8 +91,11 @@ function getCoordinate(range, focus, changes, isMulti = false) {
102
91
  }
103
92
  return null;
104
93
  }
105
- /** check if out of range */
106
- function isAfterLast({ x, y }, { lastCell }) {
94
+ /**
95
+ * Check if the x coordinate of the cell position is after or equal to the x coordinate of the last cell position
96
+ * or if the y coordinate of the cell position is after or equal to the y coordinate of the last cell position
97
+ */
98
+ function isAfterLast({ x, y }, lastCell) {
107
99
  return x >= lastCell.x || y >= lastCell.y;
108
100
  }
109
101
  /** check if out of range */
@@ -233,11 +225,6 @@ const RevogrFocus$1 = class {
233
225
  };
234
226
  RevogrFocus$1.style = RevogrFocusStyle0;
235
227
 
236
- // is edit input
237
- function isEditInput(el) {
238
- return !!(el === null || el === void 0 ? void 0 : el.closest(`.${index$1.EDIT_INPUT_WR}`));
239
- }
240
-
241
228
  const DIRECTION_CODES = [
242
229
  key_utils.codesLetter.TAB,
243
230
  key_utils.codesLetter.ARROW_UP,
@@ -249,9 +236,9 @@ class KeyboardService {
249
236
  constructor(sv) {
250
237
  this.sv = sv;
251
238
  }
252
- async keyDown(e, canRange) {
239
+ async keyDown(e, canRange, isEditMode, { range, focus }) {
253
240
  // IF EDIT MODE
254
- if (this.sv.selectionStoreService.edited) {
241
+ if (isEditMode) {
255
242
  switch (e.code) {
256
243
  case key_utils.codesLetter.ESCAPE:
257
244
  this.sv.cancel();
@@ -261,12 +248,12 @@ class KeyboardService {
261
248
  }
262
249
  // IF NOT EDIT MODE
263
250
  // pressed clear key
264
- if (this.sv.selectionStoreService.ranged && key_utils.isClear(e.code)) {
251
+ if (range && key_utils.isClear(e.code)) {
265
252
  this.sv.clearCell();
266
253
  return;
267
254
  }
268
255
  // below works with focus only
269
- if (!this.sv.selectionStoreService.focused) {
256
+ if (!focus) {
270
257
  return;
271
258
  }
272
259
  // tab key means same as arrow right
@@ -342,7 +329,7 @@ class KeyboardService {
342
329
  }
343
330
  if (isMulti) {
344
331
  const eData = this.sv.getData();
345
- if (isAfterLast(data.end, eData) || isBeforeFirst(data.start)) {
332
+ if (isAfterLast(data.end, eData.lastCell) || isBeforeFirst(data.start)) {
346
333
  return false;
347
334
  }
348
335
  const range = selection_store.getRange(data.start, data.end);
@@ -394,7 +381,10 @@ class AutoFillService {
394
381
  return (index.h("div", { class: {
395
382
  [index$1.CELL_HANDLER_CLASS]: true,
396
383
  [index$1.MOBILE_CLASS]: true,
397
- }, style: { left: `${handlerStyle.right}px`, top: `${handlerStyle.bottom}px` }, onMouseDown: (e) => this.autoFillHandler(e), onTouchStart: (e) => this.autoFillHandler(e) }));
384
+ }, style: {
385
+ left: `${handlerStyle.right}px`,
386
+ top: `${handlerStyle.bottom}px`,
387
+ }, onMouseDown: (e) => this.autoFillHandler(e), onTouchStart: (e) => this.autoFillHandler(e) }));
398
388
  }
399
389
  autoFillHandler(e, type = "AutoFill" /* AutoFillType.autoFill */) {
400
390
  let target = null;
@@ -410,7 +400,9 @@ class AutoFillService {
410
400
  get isAutoFill() {
411
401
  return !!this.autoFillType;
412
402
  }
413
- /** Process mouse move events */
403
+ /**
404
+ * Process mouse move events
405
+ */
414
406
  selectionMouseMove(e) {
415
407
  // initiate mouse move debounce if not present
416
408
  if (!this.onMouseMoveAutofill) {
@@ -420,9 +412,7 @@ class AutoFillService {
420
412
  this.onMouseMoveAutofill(e, this.sv.getData());
421
413
  }
422
414
  }
423
- getFocus() {
424
- let focus = this.sv.selectionStoreService.focused;
425
- const range = this.sv.selectionStoreService.ranged;
415
+ getFocus(focus, range) {
426
416
  // there was an issue that it was taking last cell from range but focus was out
427
417
  if (!focus && range) {
428
418
  focus = { x: range.x, y: range.y };
@@ -438,8 +428,8 @@ class AutoFillService {
438
428
  if (!this.autoFillInitial) {
439
429
  return;
440
430
  }
441
- const x = events.getFromEvent(event, 'clientX', index$1.MOBILE_CLASS);
442
- const y = events.getFromEvent(event, 'clientY', index$1.MOBILE_CLASS);
431
+ const x = events.getPropertyFromEvent(event, 'clientX', index$1.MOBILE_CLASS);
432
+ const y = events.getPropertyFromEvent(event, 'clientY', index$1.MOBILE_CLASS);
443
433
  // skip touch
444
434
  if (x === null || y === null) {
445
435
  return;
@@ -452,11 +442,12 @@ class AutoFillService {
452
442
  }
453
443
  }
454
444
  // check if not the latest, if latest - do nothing
455
- if (isAfterLast(current, data)) {
445
+ if (isAfterLast(current, data.lastCell)) {
456
446
  return;
457
447
  }
458
448
  this.autoFillLast = current;
459
- const isSame = current.x === this.autoFillInitial.x && current.y === this.autoFillInitial.y;
449
+ const isSame = current.x === this.autoFillInitial.x &&
450
+ current.y === this.autoFillInitial.y;
460
451
  // if same as initial - clear
461
452
  if (isSame) {
462
453
  this.sv.setTempRange(null);
@@ -477,39 +468,48 @@ class AutoFillService {
477
468
  selectionStart(target, data, type = "Selection" /* AutoFillType.selection */) {
478
469
  /** Get cell by autofill element */
479
470
  const { top, left } = target.getBoundingClientRect();
480
- this.autoFillInitial = this.getFocus();
471
+ this.autoFillInitial = this.getFocus(data.focus, data.range);
481
472
  this.autoFillType = type;
482
473
  this.autoFillStart = getCurrentCell({ x: left, y: top }, data);
483
474
  }
484
475
  /**
485
- * Clear current range selection
486
- * on mouse up and mouse leave events
476
+ * Clear current range selection on mouse up and mouse leave events
487
477
  */
488
- clearAutoFillSelection() {
489
- // Apply autofill values on mouse up if present
478
+ clearAutoFillSelection(focus, oldRange) {
479
+ // If autofill was active, apply autofill values
490
480
  if (this.autoFillInitial) {
491
- // Get latest
492
- this.autoFillInitial = this.getFocus();
493
- // Apply range data if present
481
+ // Fetch latest focus
482
+ this.autoFillInitial = this.getFocus(focus, oldRange);
483
+ // Apply range data if autofill mode is active
494
484
  if (this.autoFillType === "AutoFill" /* AutoFillType.autoFill */) {
495
485
  const range = selection_store.getRange(this.autoFillInitial, this.autoFillLast);
486
+ // If range is present, apply data
496
487
  if (range) {
497
- const { defaultPrevented: stopApply, detail: { range: newRange } } = this.sv.clearRangeDataApply({
488
+ const { defaultPrevented: stopApply, detail: { range: newRange }, } = this.sv.clearRangeDataApply({
498
489
  range,
499
490
  });
491
+ // If data apply was not prevented, apply new range
500
492
  if (!stopApply) {
501
- this.applyRangeWithData(newRange);
493
+ this.applyRangeWithData(newRange, oldRange);
502
494
  }
503
495
  else {
504
- // if prevented - clear temp range
496
+ // If data apply was prevented, clear temporary range
505
497
  this.sv.setTempRange(null);
506
498
  }
507
499
  }
508
500
  }
509
501
  else {
502
+ // If not autofill mode, apply range only
510
503
  this.applyRangeOnly(this.autoFillInitial, this.autoFillLast);
511
504
  }
512
505
  }
506
+ // Reset autofill state
507
+ this.resetAutoFillState();
508
+ }
509
+ /**
510
+ * Reset autofill state
511
+ */
512
+ resetAutoFillState() {
513
513
  this.autoFillType = null;
514
514
  this.autoFillInitial = null;
515
515
  this.autoFillLast = null;
@@ -529,8 +529,7 @@ class AutoFillService {
529
529
  this.sv.setRange(range);
530
530
  }
531
531
  /** Apply range and copy data during range application */
532
- applyRangeWithData(newRange) {
533
- const oldRange = this.sv.selectionStoreService.ranged;
532
+ applyRangeWithData(newRange, oldRange) {
534
533
  const rangeData = {
535
534
  type: this.sv.dataStore.get('type'),
536
535
  colType: this.sv.columnService.type,
@@ -619,44 +618,60 @@ const OverlaySelection = class {
619
618
  // #endregion
620
619
  // #region Listeners
621
620
  onMouseMove(e) {
622
- if (this.selectionStoreService.focused) {
621
+ if (this.selectionStore.get('focus')) {
623
622
  this.autoFillService.selectionMouseMove(e);
624
623
  }
625
624
  }
626
- /** Action finished inside of the document. */
627
- /** Pointer left document, clear any active operation. */
625
+ /**
626
+ * Action finished inside of the document.
627
+ * Pointer left document, clear any active operation.
628
+ */
628
629
  onMouseUp() {
629
- this.autoFillService.clearAutoFillSelection();
630
+ // Clear auto fill selection
631
+ // when pointer left document,
632
+ // clear any active operation.
633
+ this.autoFillService.clearAutoFillSelection(this.selectionStore.get('focus'), this.selectionStore.get('range'));
630
634
  }
631
- /** Row drag started. */
635
+ /**
636
+ * Row drag started.
637
+ * This event is fired when drag action started on cell.
638
+ */
632
639
  onCellDrag(e) {
633
640
  var _a;
641
+ // Invoke drag start on order editor.
634
642
  (_a = this.orderEditor) === null || _a === void 0 ? void 0 : _a.dragStart(e.detail);
635
643
  }
636
- /** Get keyboard down from element. */
644
+ /**
645
+ * Get keyboard down from element.
646
+ * This event is fired when keyboard key is released.
647
+ */
637
648
  onKeyUp(e) {
649
+ // Emit before key up event.
638
650
  this.beforeKeyUp.emit(e);
639
651
  }
640
- /** Get keyboard down from element. */
652
+ /**
653
+ * Get keyboard down from element.
654
+ * This event is fired when keyboard key is pressed.
655
+ */
641
656
  onKeyDown(e) {
642
657
  var _a;
658
+ // Emit before key down event and check if default prevention is set.
643
659
  const proxy = this.beforeKeyDown.emit(e);
644
660
  if (e.defaultPrevented || proxy.defaultPrevented) {
645
661
  return;
646
662
  }
647
- (_a = this.keyboardService) === null || _a === void 0 ? void 0 : _a.keyDown(e, this.range);
663
+ // Invoke key down on keyboard service.
664
+ (_a = this.keyboardService) === null || _a === void 0 ? void 0 : _a.keyDown(e, this.range, !!this.selectionStore.get('edit'), {
665
+ focus: this.selectionStore.get('focus'),
666
+ range: this.selectionStore.get('range'),
667
+ });
648
668
  }
649
669
  // #endregion
650
670
  /** Selection & Keyboard */
651
671
  selectionServiceSet(s) {
652
- this.selectionStoreService = new SelectionStoreService(s, {
653
- changeRange: range => this.triggerRangeEvent(range),
654
- focus: (focus, end) => this.doFocus(focus, end),
655
- });
656
672
  this.keyboardService = new KeyboardService({
657
- selectionStoreService: this.selectionStoreService,
658
673
  selectionStore: s,
659
- range: r => this.selectionStoreService.changeRange(r),
674
+ range: r => this.triggerRangeEvent(r),
660
675
  focusNext: (f, next) => this.doFocus(f, f, next),
661
676
  change: val => {
662
677
  if (this.readonly) {
@@ -678,7 +693,6 @@ const OverlaySelection = class {
678
693
  /** Autofill */
679
694
  createAutoFillService() {
680
695
  this.autoFillService = new AutoFillService({
681
- selectionStoreService: this.selectionStoreService,
682
696
  dimensionRow: this.dimensionRow,
683
697
  dimensionCol: this.dimensionCol,
684
698
  columnService: this.columnService,
@@ -754,10 +768,10 @@ const OverlaySelection = class {
754
768
  nodes.push(editCell);
755
769
  }
756
770
  else {
757
- const range = this.selectionStoreService.ranged;
758
- const selectionFocus = this.selectionStoreService.focused;
771
+ const range = this.selectionStore.get('range');
772
+ const focus = this.selectionStore.get('focus');
759
773
  // Clipboard
760
- if ((range || selectionFocus) && this.useClipboard) {
774
+ if ((range || focus) && this.useClipboard) {
761
775
  nodes.push(index.h("revogr-clipboard", { readonly: this.readonly, onCopyregion: e => this.onCopy(e.detail), onClearregion: () => !this.readonly && this.clearCell(), ref: e => (this.clipboard = e), onPasteregion: e => this.onPaste(e.detail) }));
762
776
  }
763
777
  // Range
@@ -765,23 +779,19 @@ const OverlaySelection = class {
765
779
  nodes.push(...this.renderRange(range));
766
780
  }
767
781
  // Autofill
768
- if (selectionFocus && !this.readonly && this.range) {
769
- nodes.push(this.autoFillService.renderAutofill(range, selectionFocus));
782
+ if (focus && !this.readonly && this.range) {
783
+ nodes.push(this.autoFillService.renderAutofill(range, focus));
770
784
  }
771
785
  // Order
772
786
  if (this.canDrag) {
773
787
  nodes.push(index.h("revogr-order-editor", { ref: e => (this.orderEditor = e), dataStore: this.dataStore, dimensionRow: this.dimensionRow, dimensionCol: this.dimensionCol, parent: this.element, onRowdragstartinit: e => this.rowDragStart(e) }));
774
788
  }
775
789
  }
776
- return (index.h(index.Host, { key: 'd20fcf63958e3d491f4fd881a4a5dd242cfdd9ac', class: { mobile: this.isMobileDevice },
777
- // Open Editor on DblClick
778
- onDblClick: (e) => {
779
- // DblClick prevented outside - Editor will not open
780
- if (!e.defaultPrevented) {
781
- this.doEdit();
782
- }
783
- }, onMouseDown: (e) => this.onElementMouseDown(e), onTouchStart: (e) => this.onElementMouseDown(e, true) }, nodes, index.h("slot", { key: '89b9bec7824739ea11fadeecbf3908ac74e85c96', name: "data" })));
790
+ return (index.h(index.Host, { key: '9dbb6247aebf4ad00c1c8c78852191671be33a11', class: { mobile: this.isMobileDevice }, onDblClick: (e) => this.onElementDblClick(e), onMouseDown: (e) => this.onElementMouseDown(e), onTouchStart: (e) => this.onElementMouseDown(e, true) }, nodes, index.h("slot", { key: '7769092a5029c5a49da8c2d6f36eb9f17b461bc2', name: "data" })));
784
791
  }
792
+ /**
793
+ * Executes the focus operation on the specified range of cells.
794
+ */
785
795
  doFocus(focus, end, next) {
786
796
  const { defaultPrevented } = this.beforeFocusCell.emit(this.columnService.getSaveData(focus.y, focus.x));
787
797
  if (defaultPrevented) {
@@ -815,31 +825,48 @@ const OverlaySelection = class {
815
825
  }
816
826
  return !e.defaultPrevented;
817
827
  }
828
+ /**
829
+ * Open Editor on DblClick
830
+ */
831
+ onElementDblClick(e) {
832
+ // DblClick prevented outside - Editor will not open
833
+ // Get data from the component
834
+ const data = this.getData();
835
+ const focusCell = getFocusCellBasedOnEvent(e, data);
836
+ if (!focusCell) {
837
+ return;
838
+ }
839
+ this.doEdit();
840
+ }
841
+ /**
842
+ * Handle mouse down event on Host element
843
+ */
818
844
  onElementMouseDown(e, touch = false) {
845
+ // Get the target element from the event object
846
+ const targetElement = e.target;
819
847
  // Ignore focus if clicked input
820
- if (isEditInput(e.target)) {
848
+ if (key_utils.isEditInput(targetElement)) {
821
849
  return;
822
850
  }
851
+ // Get data from the component
823
852
  const data = this.getData();
824
- if (e.defaultPrevented) {
825
- return;
826
- }
827
- const x = events.getFromEvent(e, 'clientX');
828
- const y = events.getFromEvent(e, 'clientY');
829
- // skip touch
830
- if (x === null || y === null) {
853
+ const focusCell = getFocusCellBasedOnEvent(e, data);
854
+ if (!focusCell) {
831
855
  return;
832
856
  }
833
- // Regular cell click
834
- const focusCell = getCurrentCell({ x, y }, data);
835
- this.selectionStoreService.focus(focusCell, this.range && e.shiftKey);
857
+ // Set focus on the current cell
858
+ this.focus(focusCell, this.range && e.shiftKey);
836
859
  // Initiate autofill selection
837
860
  if (this.range) {
838
- this.autoFillService.selectionStart(e.target, data);
861
+ this.autoFillService.selectionStart(targetElement, this.getData());
862
+ // Prevent default behavior for mouse events,
863
+ // but only if target element is not a mobile input
839
864
  if (!touch) {
840
865
  e.preventDefault();
841
866
  }
842
867
  else if (events.verifyTouchTarget(e.touches[0], index$1.MOBILE_CLASS)) {
868
+ // Prevent default behavior for touch events
869
+ // if target element is a mobile input
843
870
  e.preventDefault();
844
871
  }
845
872
  }
@@ -850,8 +877,8 @@ const OverlaySelection = class {
850
877
  doEdit(val = '') {
851
878
  var _a;
852
879
  if (this.canEdit()) {
853
- const editCell = this.selectionStore.get('focus');
854
- const data = this.columnService.getSaveData(editCell.y, editCell.x);
880
+ const focus = this.selectionStore.get('focus');
881
+ const data = this.columnService.getSaveData(focus.y, focus.x);
855
882
  (_a = this.setEdit) === null || _a === void 0 ? void 0 : _a.emit(Object.assign(Object.assign({}, data), { val }));
856
883
  }
857
884
  }
@@ -874,8 +901,8 @@ const OverlaySelection = class {
874
901
  this.cellEditApply.emit(dataToSave);
875
902
  }
876
903
  getRegion() {
877
- const focus = this.selectionStoreService.focused;
878
- let range = this.selectionStoreService.ranged;
904
+ const focus = this.selectionStore.get('focus');
905
+ let range = this.selectionStore.get('range');
879
906
  if (!range) {
880
907
  range = selection_store.getRange(focus, focus);
881
908
  }
@@ -901,8 +928,8 @@ const OverlaySelection = class {
901
928
  return true;
902
929
  }
903
930
  onPaste(data) {
904
- const focus = this.selectionStoreService.focused;
905
- const isEditing = this.selectionStoreService.edited !== null;
931
+ const focus = this.selectionStore.get('focus');
932
+ const isEditing = this.selectionStore.get('edit') !== null;
906
933
  if (!focus || isEditing) {
907
934
  return;
908
935
  }
@@ -922,13 +949,13 @@ const OverlaySelection = class {
922
949
  }
923
950
  }
924
951
  clearCell() {
925
- if (this.selectionStoreService.ranged &&
926
- !selection_store.isRangeSingleCell(this.selectionStoreService.ranged)) {
927
- const data = this.columnService.getRangeStaticData(this.selectionStoreService.ranged, '');
928
- this.autoFillService.onRangeApply(data, this.selectionStoreService.ranged);
952
+ if (this.selectionStore.get('range') &&
953
+ !selection_store.isRangeSingleCell(this.selectionStore.get('range'))) {
954
+ const data = this.columnService.getRangeStaticData(this.selectionStore.get('range'), '');
955
+ this.autoFillService.onRangeApply(data, this.selectionStore.get('range'));
929
956
  }
930
957
  else if (this.canEdit()) {
931
- const focused = this.selectionStoreService.focused;
958
+ const focused = this.selectionStore.get('focus');
932
959
  const cell = this.columnService.getSaveData(focused.y, focused.x);
933
960
  this.cellEdit({
934
961
  rgRow: focused.y,
@@ -950,8 +977,24 @@ const OverlaySelection = class {
950
977
  if (this.readonly) {
951
978
  return false;
952
979
  }
953
- const editCell = this.selectionStoreService.focused;
954
- return editCell && !((_a = this.columnService) === null || _a === void 0 ? void 0 : _a.isReadOnly(editCell.y, editCell.x));
980
+ const focus = this.selectionStore.get('focus');
981
+ return focus && !((_a = this.columnService) === null || _a === void 0 ? void 0 : _a.isReadOnly(focus.y, focus.x));
982
+ }
983
+ get edited() {
984
+ return this.selectionStore.get('edit');
985
+ }
986
+ /**
987
+ * Sets the focus on a cell and optionally edits a range.
988
+ */
989
+ focus(cell, isRangeEdit = false) {
990
+ if (!cell)
991
+ return false;
992
+ const end = cell;
993
+ const start = this.selectionStore.get('focus');
994
+ if (isRangeEdit && start) {
995
+ return this.triggerRangeEvent(selection_store.getRange(start, end));
996
+ }
997
+ return this.doFocus(cell, end);
955
998
  }
956
999
  get types() {
957
1000
  return {
@@ -968,6 +1011,8 @@ const OverlaySelection = class {
968
1011
  rows: this.dimensionRow.state,
969
1012
  cols: this.dimensionCol.state,
970
1013
  lastCell: this.lastCell,
1014
+ focus: this.selectionStore.get('focus'),
1015
+ range: this.selectionStore.get('range'),
971
1016
  };
972
1017
  }
973
1018
  get element() { return index.getElement(this); }