@revolist/revogrid 4.27.11 → 4.28.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.
@@ -273,13 +273,13 @@ const RevogrFocus$1 = class RevogrFocus {
273
273
  };
274
274
  RevogrFocus$1.style = revogrFocusStyleCss();
275
275
 
276
- const DIRECTION_CODES = [
277
- dimension_helpers.codesLetter.TAB,
276
+ const ARROW_CODES = [
278
277
  dimension_helpers.codesLetter.ARROW_UP,
279
278
  dimension_helpers.codesLetter.ARROW_DOWN,
280
279
  dimension_helpers.codesLetter.ARROW_LEFT,
281
280
  dimension_helpers.codesLetter.ARROW_RIGHT,
282
281
  ];
282
+ const DIRECTION_CODES = new Set([dimension_helpers.codesLetter.TAB, ...ARROW_CODES]);
283
283
  class KeyboardService {
284
284
  constructor(sv) {
285
285
  this.sv = sv;
@@ -416,7 +416,9 @@ class KeyboardService {
416
416
  this.applyingKeyChange = true;
417
417
  let changed;
418
418
  try {
419
- changed = this.keyPositionChange(data.changes, range, focus, data.isMulti);
419
+ changed = data.edge
420
+ ? this.keyEdgeChange(data.changes, range, focus, !!data.isMulti)
421
+ : this.keyPositionChange(data.changes, range, focus, data.isMulti);
420
422
  }
421
423
  finally {
422
424
  this.applyingKeyChange = false;
@@ -453,10 +455,33 @@ class KeyboardService {
453
455
  ? -1
454
456
  : 0);
455
457
  }
458
+ keyEdgeChange(changes, range, focus, isMulti) {
459
+ if (!range || !focus) {
460
+ return false;
461
+ }
462
+ const { lastCell } = this.sv.getData();
463
+ const coordinate = changes.x ? 'x' : 'y';
464
+ const direction = changes[coordinate];
465
+ const target = direction > 0 ? lastCell[coordinate] - 1 : 0;
466
+ if (isMulti) {
467
+ const edgeCoordinate = coordinate === 'x' ? 'x1' : 'y1';
468
+ return this.sv.range(Object.assign(Object.assign({}, range), { [coordinate]: direction < 0 ? target : focus[coordinate], [edgeCoordinate]: direction > 0 ? target : focus[coordinate] }));
469
+ }
470
+ const edgeFocus = Object.assign(Object.assign({}, focus), { [coordinate]: target });
471
+ return this.sv.focus(edgeFocus, {
472
+ [coordinate]: target - focus[coordinate],
473
+ });
474
+ }
456
475
  /** Monitor key direction changes */
457
476
  changeDirectionKey(e, canRange) {
458
477
  const isMulti = canRange && e.shiftKey;
459
- if (DIRECTION_CODES.includes(e.code)) {
478
+ const hasPrimaryModifier = e.ctrlKey || e.metaKey;
479
+ const isArrow = ARROW_CODES.includes(e.code);
480
+ const isEdgeShortcut = hasPrimaryModifier && !e.altKey && isArrow;
481
+ if (hasPrimaryModifier && !isEdgeShortcut) {
482
+ return;
483
+ }
484
+ if (DIRECTION_CODES.has(e.code)) {
460
485
  e.preventDefault();
461
486
  }
462
487
  if (e.shiftKey) {
@@ -465,17 +490,25 @@ class KeyboardService {
465
490
  return { changes: { x: -1 }, isMulti: false };
466
491
  }
467
492
  }
493
+ let changes;
468
494
  switch (e.code) {
469
495
  case dimension_helpers.codesLetter.ARROW_UP:
470
- return { changes: { y: -1 }, isMulti };
496
+ changes = { y: -1 };
497
+ break;
471
498
  case dimension_helpers.codesLetter.ARROW_DOWN:
472
- return { changes: { y: 1 }, isMulti };
499
+ changes = { y: 1 };
500
+ break;
473
501
  case dimension_helpers.codesLetter.ARROW_LEFT:
474
- return { changes: { x: -1 }, isMulti };
502
+ changes = { x: -1 };
503
+ break;
475
504
  case dimension_helpers.codesLetter.TAB:
476
505
  case dimension_helpers.codesLetter.ARROW_RIGHT:
477
- return { changes: { x: 1 }, isMulti };
506
+ changes = { x: 1 };
507
+ break;
508
+ default:
509
+ return;
478
510
  }
511
+ return Object.assign({ changes, isMulti }, (isEdgeShortcut && { edge: true }));
479
512
  }
480
513
  }
481
514
 
@@ -5,13 +5,13 @@ import { getRange } from "../../store/index";
5
5
  import { codesLetter, isAll, isClear, isCopy, isCut, isEnterKeyValue, isPaste, isShortcutModifier, isTab, timeout, RESIZE_INTERVAL, } from "../../utils";
6
6
  import { getCoordinate, isAfterLast, isBeforeFirst, } from "./selection.utils";
7
7
  import { isEditInput } from "../editors/edit.utils";
8
- const DIRECTION_CODES = [
9
- codesLetter.TAB,
8
+ const ARROW_CODES = [
10
9
  codesLetter.ARROW_UP,
11
10
  codesLetter.ARROW_DOWN,
12
11
  codesLetter.ARROW_LEFT,
13
12
  codesLetter.ARROW_RIGHT,
14
13
  ];
14
+ const DIRECTION_CODES = new Set([codesLetter.TAB, ...ARROW_CODES]);
15
15
  export class KeyboardService {
16
16
  constructor(sv) {
17
17
  this.sv = sv;
@@ -148,7 +148,9 @@ export class KeyboardService {
148
148
  this.applyingKeyChange = true;
149
149
  let changed;
150
150
  try {
151
- changed = this.keyPositionChange(data.changes, range, focus, data.isMulti);
151
+ changed = data.edge
152
+ ? this.keyEdgeChange(data.changes, range, focus, !!data.isMulti)
153
+ : this.keyPositionChange(data.changes, range, focus, data.isMulti);
152
154
  }
153
155
  finally {
154
156
  this.applyingKeyChange = false;
@@ -185,10 +187,33 @@ export class KeyboardService {
185
187
  ? -1
186
188
  : 0);
187
189
  }
190
+ keyEdgeChange(changes, range, focus, isMulti) {
191
+ if (!range || !focus) {
192
+ return false;
193
+ }
194
+ const { lastCell } = this.sv.getData();
195
+ const coordinate = changes.x ? 'x' : 'y';
196
+ const direction = changes[coordinate];
197
+ const target = direction > 0 ? lastCell[coordinate] - 1 : 0;
198
+ if (isMulti) {
199
+ const edgeCoordinate = coordinate === 'x' ? 'x1' : 'y1';
200
+ return this.sv.range(Object.assign(Object.assign({}, range), { [coordinate]: direction < 0 ? target : focus[coordinate], [edgeCoordinate]: direction > 0 ? target : focus[coordinate] }));
201
+ }
202
+ const edgeFocus = Object.assign(Object.assign({}, focus), { [coordinate]: target });
203
+ return this.sv.focus(edgeFocus, {
204
+ [coordinate]: target - focus[coordinate],
205
+ });
206
+ }
188
207
  /** Monitor key direction changes */
189
208
  changeDirectionKey(e, canRange) {
190
209
  const isMulti = canRange && e.shiftKey;
191
- if (DIRECTION_CODES.includes(e.code)) {
210
+ const hasPrimaryModifier = e.ctrlKey || e.metaKey;
211
+ const isArrow = ARROW_CODES.includes(e.code);
212
+ const isEdgeShortcut = hasPrimaryModifier && !e.altKey && isArrow;
213
+ if (hasPrimaryModifier && !isEdgeShortcut) {
214
+ return;
215
+ }
216
+ if (DIRECTION_CODES.has(e.code)) {
192
217
  e.preventDefault();
193
218
  }
194
219
  if (e.shiftKey) {
@@ -197,16 +222,24 @@ export class KeyboardService {
197
222
  return { changes: { x: -1 }, isMulti: false };
198
223
  }
199
224
  }
225
+ let changes;
200
226
  switch (e.code) {
201
227
  case codesLetter.ARROW_UP:
202
- return { changes: { y: -1 }, isMulti };
228
+ changes = { y: -1 };
229
+ break;
203
230
  case codesLetter.ARROW_DOWN:
204
- return { changes: { y: 1 }, isMulti };
231
+ changes = { y: 1 };
232
+ break;
205
233
  case codesLetter.ARROW_LEFT:
206
- return { changes: { x: -1 }, isMulti };
234
+ changes = { x: -1 };
235
+ break;
207
236
  case codesLetter.TAB:
208
237
  case codesLetter.ARROW_RIGHT:
209
- return { changes: { x: 1 }, isMulti };
238
+ changes = { x: 1 };
239
+ break;
240
+ default:
241
+ return;
210
242
  }
243
+ return Object.assign({ changes, isMulti }, (isEdgeShortcut && { edge: true }));
211
244
  }
212
245
  }
@@ -271,13 +271,13 @@ const RevogrFocus$1 = class RevogrFocus {
271
271
  };
272
272
  RevogrFocus$1.style = revogrFocusStyleCss();
273
273
 
274
- const DIRECTION_CODES = [
275
- codesLetter.TAB,
274
+ const ARROW_CODES = [
276
275
  codesLetter.ARROW_UP,
277
276
  codesLetter.ARROW_DOWN,
278
277
  codesLetter.ARROW_LEFT,
279
278
  codesLetter.ARROW_RIGHT,
280
279
  ];
280
+ const DIRECTION_CODES = new Set([codesLetter.TAB, ...ARROW_CODES]);
281
281
  class KeyboardService {
282
282
  constructor(sv) {
283
283
  this.sv = sv;
@@ -414,7 +414,9 @@ class KeyboardService {
414
414
  this.applyingKeyChange = true;
415
415
  let changed;
416
416
  try {
417
- changed = this.keyPositionChange(data.changes, range, focus, data.isMulti);
417
+ changed = data.edge
418
+ ? this.keyEdgeChange(data.changes, range, focus, !!data.isMulti)
419
+ : this.keyPositionChange(data.changes, range, focus, data.isMulti);
418
420
  }
419
421
  finally {
420
422
  this.applyingKeyChange = false;
@@ -451,10 +453,33 @@ class KeyboardService {
451
453
  ? -1
452
454
  : 0);
453
455
  }
456
+ keyEdgeChange(changes, range, focus, isMulti) {
457
+ if (!range || !focus) {
458
+ return false;
459
+ }
460
+ const { lastCell } = this.sv.getData();
461
+ const coordinate = changes.x ? 'x' : 'y';
462
+ const direction = changes[coordinate];
463
+ const target = direction > 0 ? lastCell[coordinate] - 1 : 0;
464
+ if (isMulti) {
465
+ const edgeCoordinate = coordinate === 'x' ? 'x1' : 'y1';
466
+ return this.sv.range(Object.assign(Object.assign({}, range), { [coordinate]: direction < 0 ? target : focus[coordinate], [edgeCoordinate]: direction > 0 ? target : focus[coordinate] }));
467
+ }
468
+ const edgeFocus = Object.assign(Object.assign({}, focus), { [coordinate]: target });
469
+ return this.sv.focus(edgeFocus, {
470
+ [coordinate]: target - focus[coordinate],
471
+ });
472
+ }
454
473
  /** Monitor key direction changes */
455
474
  changeDirectionKey(e, canRange) {
456
475
  const isMulti = canRange && e.shiftKey;
457
- if (DIRECTION_CODES.includes(e.code)) {
476
+ const hasPrimaryModifier = e.ctrlKey || e.metaKey;
477
+ const isArrow = ARROW_CODES.includes(e.code);
478
+ const isEdgeShortcut = hasPrimaryModifier && !e.altKey && isArrow;
479
+ if (hasPrimaryModifier && !isEdgeShortcut) {
480
+ return;
481
+ }
482
+ if (DIRECTION_CODES.has(e.code)) {
458
483
  e.preventDefault();
459
484
  }
460
485
  if (e.shiftKey) {
@@ -463,17 +488,25 @@ class KeyboardService {
463
488
  return { changes: { x: -1 }, isMulti: false };
464
489
  }
465
490
  }
491
+ let changes;
466
492
  switch (e.code) {
467
493
  case codesLetter.ARROW_UP:
468
- return { changes: { y: -1 }, isMulti };
494
+ changes = { y: -1 };
495
+ break;
469
496
  case codesLetter.ARROW_DOWN:
470
- return { changes: { y: 1 }, isMulti };
497
+ changes = { y: 1 };
498
+ break;
471
499
  case codesLetter.ARROW_LEFT:
472
- return { changes: { x: -1 }, isMulti };
500
+ changes = { x: -1 };
501
+ break;
473
502
  case codesLetter.TAB:
474
503
  case codesLetter.ARROW_RIGHT:
475
- return { changes: { x: 1 }, isMulti };
504
+ changes = { x: 1 };
505
+ break;
506
+ default:
507
+ return;
476
508
  }
509
+ return Object.assign({ changes, isMulti }, (isEdgeShortcut && { edge: true }));
477
510
  }
478
511
  }
479
512
 
@@ -271,13 +271,13 @@ const RevogrFocus$1 = class RevogrFocus {
271
271
  };
272
272
  RevogrFocus$1.style = revogrFocusStyleCss();
273
273
 
274
- const DIRECTION_CODES = [
275
- codesLetter.TAB,
274
+ const ARROW_CODES = [
276
275
  codesLetter.ARROW_UP,
277
276
  codesLetter.ARROW_DOWN,
278
277
  codesLetter.ARROW_LEFT,
279
278
  codesLetter.ARROW_RIGHT,
280
279
  ];
280
+ const DIRECTION_CODES = new Set([codesLetter.TAB, ...ARROW_CODES]);
281
281
  class KeyboardService {
282
282
  constructor(sv) {
283
283
  this.sv = sv;
@@ -414,7 +414,9 @@ class KeyboardService {
414
414
  this.applyingKeyChange = true;
415
415
  let changed;
416
416
  try {
417
- changed = this.keyPositionChange(data.changes, range, focus, data.isMulti);
417
+ changed = data.edge
418
+ ? this.keyEdgeChange(data.changes, range, focus, !!data.isMulti)
419
+ : this.keyPositionChange(data.changes, range, focus, data.isMulti);
418
420
  }
419
421
  finally {
420
422
  this.applyingKeyChange = false;
@@ -451,10 +453,33 @@ class KeyboardService {
451
453
  ? -1
452
454
  : 0);
453
455
  }
456
+ keyEdgeChange(changes, range, focus, isMulti) {
457
+ if (!range || !focus) {
458
+ return false;
459
+ }
460
+ const { lastCell } = this.sv.getData();
461
+ const coordinate = changes.x ? 'x' : 'y';
462
+ const direction = changes[coordinate];
463
+ const target = direction > 0 ? lastCell[coordinate] - 1 : 0;
464
+ if (isMulti) {
465
+ const edgeCoordinate = coordinate === 'x' ? 'x1' : 'y1';
466
+ return this.sv.range(Object.assign(Object.assign({}, range), { [coordinate]: direction < 0 ? target : focus[coordinate], [edgeCoordinate]: direction > 0 ? target : focus[coordinate] }));
467
+ }
468
+ const edgeFocus = Object.assign(Object.assign({}, focus), { [coordinate]: target });
469
+ return this.sv.focus(edgeFocus, {
470
+ [coordinate]: target - focus[coordinate],
471
+ });
472
+ }
454
473
  /** Monitor key direction changes */
455
474
  changeDirectionKey(e, canRange) {
456
475
  const isMulti = canRange && e.shiftKey;
457
- if (DIRECTION_CODES.includes(e.code)) {
476
+ const hasPrimaryModifier = e.ctrlKey || e.metaKey;
477
+ const isArrow = ARROW_CODES.includes(e.code);
478
+ const isEdgeShortcut = hasPrimaryModifier && !e.altKey && isArrow;
479
+ if (hasPrimaryModifier && !isEdgeShortcut) {
480
+ return;
481
+ }
482
+ if (DIRECTION_CODES.has(e.code)) {
458
483
  e.preventDefault();
459
484
  }
460
485
  if (e.shiftKey) {
@@ -463,17 +488,25 @@ class KeyboardService {
463
488
  return { changes: { x: -1 }, isMulti: false };
464
489
  }
465
490
  }
491
+ let changes;
466
492
  switch (e.code) {
467
493
  case codesLetter.ARROW_UP:
468
- return { changes: { y: -1 }, isMulti };
494
+ changes = { y: -1 };
495
+ break;
469
496
  case codesLetter.ARROW_DOWN:
470
- return { changes: { y: 1 }, isMulti };
497
+ changes = { y: 1 };
498
+ break;
471
499
  case codesLetter.ARROW_LEFT:
472
- return { changes: { x: -1 }, isMulti };
500
+ changes = { x: -1 };
501
+ break;
473
502
  case codesLetter.TAB:
474
503
  case codesLetter.ARROW_RIGHT:
475
- return { changes: { x: 1 }, isMulti };
504
+ changes = { x: 1 };
505
+ break;
506
+ default:
507
+ return;
476
508
  }
509
+ return Object.assign({ changes, isMulti }, (isEdgeShortcut && { edge: true }));
477
510
  }
478
511
  }
479
512
 
@@ -13,6 +13,11 @@ type Config = {
13
13
  range(range: RangeArea | null): boolean;
14
14
  selectAll(): void;
15
15
  };
16
+ type DirectionKeyChange = {
17
+ changes: Partial<Cell>;
18
+ isMulti?: boolean;
19
+ edge?: boolean;
20
+ };
16
21
  export declare class KeyboardService {
17
22
  private readonly sv;
18
23
  /** Keep focus transitions in keydown order so rendering can scroll each cell into view. */
@@ -35,10 +40,8 @@ export declare class KeyboardService {
35
40
  private selectAll;
36
41
  keyChangeSelection(e: KeyboardEvent, canRange: boolean): Promise<boolean>;
37
42
  keyPositionChange(changes: Partial<Cell>, range: RangeArea | null, focus: Cell | null, isMulti?: boolean): boolean;
43
+ private keyEdgeChange;
38
44
  /** Monitor key direction changes */
39
- changeDirectionKey(e: KeyboardEvent, canRange: boolean): {
40
- changes: Partial<Cell>;
41
- isMulti?: boolean;
42
- } | void;
45
+ changeDirectionKey(e: KeyboardEvent, canRange: boolean): DirectionKeyChange | void;
43
46
  }
44
47
  export {};
package/hydrate/index.js CHANGED
@@ -13833,13 +13833,13 @@ function isEditorCtrConstructible(editor) {
13833
13833
  return typeof editor === 'function' && typeof editor.prototype === 'object';
13834
13834
  }
13835
13835
 
13836
- const DIRECTION_CODES = [
13837
- codesLetter.TAB,
13836
+ const ARROW_CODES = [
13838
13837
  codesLetter.ARROW_UP,
13839
13838
  codesLetter.ARROW_DOWN,
13840
13839
  codesLetter.ARROW_LEFT,
13841
13840
  codesLetter.ARROW_RIGHT,
13842
13841
  ];
13842
+ const DIRECTION_CODES = new Set([codesLetter.TAB, ...ARROW_CODES]);
13843
13843
  class KeyboardService {
13844
13844
  constructor(sv) {
13845
13845
  this.sv = sv;
@@ -13976,7 +13976,9 @@ class KeyboardService {
13976
13976
  this.applyingKeyChange = true;
13977
13977
  let changed;
13978
13978
  try {
13979
- changed = this.keyPositionChange(data.changes, range, focus, data.isMulti);
13979
+ changed = data.edge
13980
+ ? this.keyEdgeChange(data.changes, range, focus, !!data.isMulti)
13981
+ : this.keyPositionChange(data.changes, range, focus, data.isMulti);
13980
13982
  }
13981
13983
  finally {
13982
13984
  this.applyingKeyChange = false;
@@ -14013,10 +14015,33 @@ class KeyboardService {
14013
14015
  ? -1
14014
14016
  : 0);
14015
14017
  }
14018
+ keyEdgeChange(changes, range, focus, isMulti) {
14019
+ if (!range || !focus) {
14020
+ return false;
14021
+ }
14022
+ const { lastCell } = this.sv.getData();
14023
+ const coordinate = changes.x ? 'x' : 'y';
14024
+ const direction = changes[coordinate];
14025
+ const target = direction > 0 ? lastCell[coordinate] - 1 : 0;
14026
+ if (isMulti) {
14027
+ const edgeCoordinate = coordinate === 'x' ? 'x1' : 'y1';
14028
+ return this.sv.range(Object.assign(Object.assign({}, range), { [coordinate]: direction < 0 ? target : focus[coordinate], [edgeCoordinate]: direction > 0 ? target : focus[coordinate] }));
14029
+ }
14030
+ const edgeFocus = Object.assign(Object.assign({}, focus), { [coordinate]: target });
14031
+ return this.sv.focus(edgeFocus, {
14032
+ [coordinate]: target - focus[coordinate],
14033
+ });
14034
+ }
14016
14035
  /** Monitor key direction changes */
14017
14036
  changeDirectionKey(e, canRange) {
14018
14037
  const isMulti = canRange && e.shiftKey;
14019
- if (DIRECTION_CODES.includes(e.code)) {
14038
+ const hasPrimaryModifier = e.ctrlKey || e.metaKey;
14039
+ const isArrow = ARROW_CODES.includes(e.code);
14040
+ const isEdgeShortcut = hasPrimaryModifier && !e.altKey && isArrow;
14041
+ if (hasPrimaryModifier && !isEdgeShortcut) {
14042
+ return;
14043
+ }
14044
+ if (DIRECTION_CODES.has(e.code)) {
14020
14045
  e.preventDefault();
14021
14046
  }
14022
14047
  if (e.shiftKey) {
@@ -14025,17 +14050,25 @@ class KeyboardService {
14025
14050
  return { changes: { x: -1 }, isMulti: false };
14026
14051
  }
14027
14052
  }
14053
+ let changes;
14028
14054
  switch (e.code) {
14029
14055
  case codesLetter.ARROW_UP:
14030
- return { changes: { y: -1 }, isMulti };
14056
+ changes = { y: -1 };
14057
+ break;
14031
14058
  case codesLetter.ARROW_DOWN:
14032
- return { changes: { y: 1 }, isMulti };
14059
+ changes = { y: 1 };
14060
+ break;
14033
14061
  case codesLetter.ARROW_LEFT:
14034
- return { changes: { x: -1 }, isMulti };
14062
+ changes = { x: -1 };
14063
+ break;
14035
14064
  case codesLetter.TAB:
14036
14065
  case codesLetter.ARROW_RIGHT:
14037
- return { changes: { x: 1 }, isMulti };
14066
+ changes = { x: 1 };
14067
+ break;
14068
+ default:
14069
+ return;
14038
14070
  }
14071
+ return Object.assign({ changes, isMulti }, (isEdgeShortcut && { edge: true }));
14039
14072
  }
14040
14073
  }
14041
14074
 
package/hydrate/index.mjs CHANGED
@@ -13831,13 +13831,13 @@ function isEditorCtrConstructible(editor) {
13831
13831
  return typeof editor === 'function' && typeof editor.prototype === 'object';
13832
13832
  }
13833
13833
 
13834
- const DIRECTION_CODES = [
13835
- codesLetter.TAB,
13834
+ const ARROW_CODES = [
13836
13835
  codesLetter.ARROW_UP,
13837
13836
  codesLetter.ARROW_DOWN,
13838
13837
  codesLetter.ARROW_LEFT,
13839
13838
  codesLetter.ARROW_RIGHT,
13840
13839
  ];
13840
+ const DIRECTION_CODES = new Set([codesLetter.TAB, ...ARROW_CODES]);
13841
13841
  class KeyboardService {
13842
13842
  constructor(sv) {
13843
13843
  this.sv = sv;
@@ -13974,7 +13974,9 @@ class KeyboardService {
13974
13974
  this.applyingKeyChange = true;
13975
13975
  let changed;
13976
13976
  try {
13977
- changed = this.keyPositionChange(data.changes, range, focus, data.isMulti);
13977
+ changed = data.edge
13978
+ ? this.keyEdgeChange(data.changes, range, focus, !!data.isMulti)
13979
+ : this.keyPositionChange(data.changes, range, focus, data.isMulti);
13978
13980
  }
13979
13981
  finally {
13980
13982
  this.applyingKeyChange = false;
@@ -14011,10 +14013,33 @@ class KeyboardService {
14011
14013
  ? -1
14012
14014
  : 0);
14013
14015
  }
14016
+ keyEdgeChange(changes, range, focus, isMulti) {
14017
+ if (!range || !focus) {
14018
+ return false;
14019
+ }
14020
+ const { lastCell } = this.sv.getData();
14021
+ const coordinate = changes.x ? 'x' : 'y';
14022
+ const direction = changes[coordinate];
14023
+ const target = direction > 0 ? lastCell[coordinate] - 1 : 0;
14024
+ if (isMulti) {
14025
+ const edgeCoordinate = coordinate === 'x' ? 'x1' : 'y1';
14026
+ return this.sv.range(Object.assign(Object.assign({}, range), { [coordinate]: direction < 0 ? target : focus[coordinate], [edgeCoordinate]: direction > 0 ? target : focus[coordinate] }));
14027
+ }
14028
+ const edgeFocus = Object.assign(Object.assign({}, focus), { [coordinate]: target });
14029
+ return this.sv.focus(edgeFocus, {
14030
+ [coordinate]: target - focus[coordinate],
14031
+ });
14032
+ }
14014
14033
  /** Monitor key direction changes */
14015
14034
  changeDirectionKey(e, canRange) {
14016
14035
  const isMulti = canRange && e.shiftKey;
14017
- if (DIRECTION_CODES.includes(e.code)) {
14036
+ const hasPrimaryModifier = e.ctrlKey || e.metaKey;
14037
+ const isArrow = ARROW_CODES.includes(e.code);
14038
+ const isEdgeShortcut = hasPrimaryModifier && !e.altKey && isArrow;
14039
+ if (hasPrimaryModifier && !isEdgeShortcut) {
14040
+ return;
14041
+ }
14042
+ if (DIRECTION_CODES.has(e.code)) {
14018
14043
  e.preventDefault();
14019
14044
  }
14020
14045
  if (e.shiftKey) {
@@ -14023,17 +14048,25 @@ class KeyboardService {
14023
14048
  return { changes: { x: -1 }, isMulti: false };
14024
14049
  }
14025
14050
  }
14051
+ let changes;
14026
14052
  switch (e.code) {
14027
14053
  case codesLetter.ARROW_UP:
14028
- return { changes: { y: -1 }, isMulti };
14054
+ changes = { y: -1 };
14055
+ break;
14029
14056
  case codesLetter.ARROW_DOWN:
14030
- return { changes: { y: 1 }, isMulti };
14057
+ changes = { y: 1 };
14058
+ break;
14031
14059
  case codesLetter.ARROW_LEFT:
14032
- return { changes: { x: -1 }, isMulti };
14060
+ changes = { x: -1 };
14061
+ break;
14033
14062
  case codesLetter.TAB:
14034
14063
  case codesLetter.ARROW_RIGHT:
14035
- return { changes: { x: 1 }, isMulti };
14064
+ changes = { x: 1 };
14065
+ break;
14066
+ default:
14067
+ return;
14036
14068
  }
14069
+ return Object.assign({ changes, isMulti }, (isEdgeShortcut && { edge: true }));
14037
14070
  }
14038
14071
  }
14039
14072
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revolist/revogrid",
3
- "version": "4.27.11",
3
+ "version": "4.28.0",
4
4
  "type": "module",
5
5
  "description": "Virtual reactive data grid spreadsheet component - RevoGrid.",
6
6
  "license": "MIT",
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * Built by Revolist OU ❤️
3
3
  */
4
- import{h as t,proxyCustomElement as e,HTMLElement as i,createEvent as s,Host as o,transformTag as n}from"@stencil/core/internal/client";import{g as r,N as a,z as l,O as h,b as c}from"./column.service.js";import{c as d}from"./platform.js";import{R as u,i as g,j as v,S as p}from"./consts.js";import{b as f,i as b,c as m,a as y,g as x,d as w,e as j,s as O,f as S,v as C}from"./selection.utils.js";import{l as D,m as k,c as E,d as M,f as R,h as A,g as F,j as P,k as T,o as z}from"./revogr-edit2.js";import{t as K}from"./index2.js";import{d as U}from"./debounce.js";import{d as X}from"./revogr-clipboard2.js";import{d as $}from"./revogr-order-editor2.js";const H=[d.TAB,d.ARROW_UP,d.ARROW_DOWN,d.ARROW_LEFT,d.ARROW_RIGHT];class q{constructor(t){this.sv=t,this.keyChangeQueue=Promise.resolve(!1),this.keyChangeGeneration=0,this.applyingKeyChange=!1}invalidatePendingChanges(){this.applyingKeyChange||(this.keyChangeGeneration+=1)}appendPendingEditValue(t){if(D(t)||1!==t.key.length||t.target instanceof HTMLElement&&k(t.target))return!1;const e=this.sv.selectionStore.get("edit");return"string"==typeof(null==e?void 0:e.val)&&(t.preventDefault(),this.sv.appendEditValue(t.key)||this.sv.selectionStore.set("edit",Object.assign(Object.assign({},e),{val:`${e.val}${t.key}`})),!0)}async keyDown(t,e,i,{range:s,focus:o}){if(i){if(this.appendPendingEditValue(t))return;switch(t.code){case d.ESCAPE:this.sv.cancel();break;case d.TAB:this.keyChangeSelection(t,e)}}else s&&E(t.code)?this.sv.clearCell():o&&(M(t.code)?this.keyChangeSelection(t,e):R(t.key)?this.sv.change():A(t)||F(t)||(P(t)?this.sv.internalPaste():T(t)?e&&this.selectAll(t):D(t)||1!==t.key.length?await this.keyChangeSelection(t,e):this.sv.change(t.key)&&t.preventDefault()))}selectAll(t){const e=this.sv.selectionStore.get("range"),i=this.sv.selectionStore.get("focus");e&&i&&(t.preventDefault(),this.sv.selectAll())}async keyChangeSelection(t,e){const i=this.changeDirectionKey(t,e);if(!i)return!1;const s=this.keyChangeGeneration;await K(u+30);const o=async()=>{if(s!==this.keyChangeGeneration)return!1;const t=this.sv.selectionStore.get("range"),e=this.sv.selectionStore.get("focus");let o;this.applyingKeyChange=!0;try{o=this.keyPositionChange(i.changes,t,e,i.isMulti)}finally{this.applyingKeyChange=!1}return await new Promise((t=>requestAnimationFrame((()=>{requestAnimationFrame((()=>t()))})))),o},n=this.keyChangeQueue.then(o,o);return this.keyChangeQueue=n.catch((()=>!1)),n}keyPositionChange(t,e,i,s=!1){if(!e||!i)return!1;const o=f(e,i,t,s);if(!o)return!1;const n=this.sv.getData();if(s){if([o.start,o.end].some((t=>b(t,n.lastCell)||m(t))))return!1;const t=r(o.start,o.end);return this.sv.range(t)}return this.sv.focus(o.start,t,b(o.start,n.lastCell)?1:m(o.start)?-1:0)}changeDirectionKey(t,e){const i=e&&t.shiftKey;if(H.includes(t.code)&&t.preventDefault(),t.shiftKey&&t.code===d.TAB)return{changes:{x:-1},isMulti:!1};switch(t.code){case d.ARROW_UP:return{changes:{y:-1},isMulti:i};case d.ARROW_DOWN:return{changes:{y:1},isMulti:i};case d.ARROW_LEFT:return{changes:{x:-1},isMulti:i};case d.TAB:case d.ARROW_RIGHT:return{changes:{x:1},isMulti:i}}}}class L{constructor(t){this.sv=t,this.autoFillType=null,this.autoFillInitial=null,this.autoFillStart=null,this.autoFillLast=null}renderAutofill(e,i,s=!1){let o;return o=y(e||Object.assign(Object.assign({},i),{x1:i.x,y1:i.y}),this.sv.dimensionRow.state,this.sv.dimensionCol.state),t("div",{class:{[v]:!0,[g]:s},style:{left:`${o.right}px`,top:`${o.bottom}px`},onMouseDown:t=>this.autoFillHandler(t),onTouchStart:t=>this.autoFillHandler(t)})}autoFillHandler(t,e="AutoFill"){let i=null;t.target instanceof Element&&(i=t.target),i&&(this.selectionStart(i,this.sv.getData(),e),t.preventDefault())}get isAutoFill(){return!!this.autoFillType}selectionMouseMove(t){this.onMouseMoveAutofill||(this.onMouseMoveAutofill=U(((t,e)=>this.doAutofillMouseMove(t,e)),5)),this.isAutoFill&&this.onMouseMoveAutofill(t,this.sv.getData())}getFocus(t,e){return!t&&e&&(t={x:e.x,y:e.y}),t||null}doAutofillMouseMove(t,e){if(!this.autoFillInitial)return;const i=x(t,"clientX",g),s=x(t,"clientY",g);if(null===i||null===s)return;const o=w({x:i,y:s},e);if(this.autoFillLast||this.autoFillLast||(this.autoFillLast=this.autoFillStart),!b(o,e.lastCell))if(this.autoFillLast=o,o.x===this.autoFillInitial.x&&o.y===this.autoFillInitial.y)this.sv.setTempRange(null);else{const t=r(this.autoFillInitial,this.autoFillLast);this.sv.setTempRange({area:t,type:this.autoFillType})}}selectionStart(t,e,i="Selection"){const{top:s,left:o}=t.getBoundingClientRect();this.autoFillInitial=this.getFocus(e.focus,e.range),this.autoFillType=i,this.autoFillStart=w({x:o,y:s},e)}clearAutoFillSelection(t,e){if(this.autoFillInitial)if(this.autoFillInitial=this.getFocus(t,e),"AutoFill"===this.autoFillType){const t=r(this.autoFillInitial,this.autoFillLast);if(t){const{defaultPrevented:i,detail:{range:s}}=this.sv.clearRangeDataApply({range:t});!i&&e?this.applyRangeWithData(s,e):this.sv.setTempRange(null)}}else this.applyRangeOnly(this.autoFillInitial,this.autoFillLast);this.resetAutoFillState()}resetAutoFillState(){this.autoFillType=null,this.autoFillInitial=null,this.autoFillLast=null,this.autoFillStart=null}onRangeApply(t,e,i){this.sv.rangeDataApply({data:t,models:j(t,this.sv.dataStore),type:this.sv.dataStore.get("type"),oldRange:i,newRange:e}),this.sv.setRange(e)}applyRangeWithData(t,e){const i={type:this.sv.dataStore.get("type"),colType:this.sv.columnService.type,newData:{},mapping:{},newRange:t,oldRange:e},{mapping:s,changed:o}=this.sv.columnService.getRangeData(i,this.sv.columnService.columns);i.newData=o,i.mapping=s;let n=this.sv.selectionChanged(i);n.defaultPrevented?this.sv.setTempRange(null):(n=this.sv.rangeCopy(i),n.defaultPrevented?this.sv.setRange(t):this.onRangeApply(i.newData,t,e))}applyRangeOnly(t,e){if(!t||!e)return;const i=r(t,e);this.sv.setRange(i)}}const N=e(class extends i{constructor(t){super(),!1!==t&&this.__registerHost(),this.beforeCopyRegion=s(this,"beforecopyregion",7),this.beforeRegionPaste=s(this,"beforepasteregion",7),this.cellEditApply=s(this,"celleditapply",7),this.beforeFocusCell=s(this,"beforecellfocusinit",7),this.beforeNextViewportFocus=s(this,"beforenextvpfocus",7),this.setEdit=s(this,"setedit",7),this.beforeApplyRange=s(this,"beforeapplyrange",7),this.beforeSetRange=s(this,"beforesetrange",7),this.setRange=s(this,"setrange",7),this.beforeEditRender=s(this,"beforeeditrender",7),this.selectAll=s(this,"selectall",7),this.cancelEdit=s(this,"canceledit",7),this.setTempRange=s(this,"settemprange",7),this.beforeSetTempRange=s(this,"beforesettemprange",7),this.applyFocus=s(this,"applyfocus",7),this.focusCell=s(this,"focuscell",7),this.beforeRangeDataApply=s(this,"beforerangedataapply",7),this.selectionChange=s(this,"selectionchangeinit",7),this.beforeRangeCopyApply=s(this,"beforerangecopyapply",7),this.rangeEditApply=s(this,"rangeeditapply",7),this.rangeClipboardCopy=s(this,"clipboardrangecopy",7),this.rangeClipboardPaste=s(this,"clipboardrangepaste",7),this.beforeKeyDown=s(this,"beforekeydown",7),this.beforeKeyUp=s(this,"beforekeyup",7),this.beforeCellSave=s(this,"beforecellsave",7),this.cellEditDone=s(this,"celledit",7),this.applyChangesOnClose=!1,this.keyboardService=null,this.autoFillService=null,this.unsubscribeSelectionStore=[]}onMouseMove(t){var e;this.selectionStore.get("focus")&&(null===(e=this.autoFillService)||void 0===e||e.selectionMouseMove(t))}onMouseUp(){var t;null===(t=this.autoFillService)||void 0===t||t.clearAutoFillSelection(this.selectionStore.get("focus"),this.selectionStore.get("range"))}onCellDrag(t){var e;null===(e=this.orderEditor)||void 0===e||e.dragStart(t.detail)}onKeyUp(t){this.beforeKeyUp.emit(Object.assign({original:t},this.getData()))}onKeyDown(t){var e;const i=this.beforeKeyDown.emit(Object.assign({original:t},this.getData()));t.defaultPrevented||i.defaultPrevented||null===(e=this.keyboardService)||void 0===e||e.keyDown(t,this.range,!!this.selectionStore.get("edit"),{focus:this.selectionStore.get("focus"),range:this.selectionStore.get("range")})}selectionServiceSet(t){var e;null===(e=this.keyboardService)||void 0===e||e.invalidatePendingChanges(),this.unsubscribeSelectionStore.forEach((t=>t())),this.unsubscribeSelectionStore.length=0,this.unsubscribeSelectionStore.push(t.onChange("nextFocus",(t=>t&&this.doFocus(t,t)))),this.keyboardService=new q({selectionStore:t,range:t=>!!t&&this.triggerRangeEvent(t),focus:(t,e,i)=>i?(this.beforeNextViewportFocus.emit(t),!1):this.doFocus(t,t,e),change:t=>this.doEdit(t),cancel:async()=>{var t;await(null===(t=this.revogrEdit)||void 0===t?void 0:t.cancelChanges()),this.closeEdit()},appendEditValue:t=>!!this.revogrEdit&&!this.revogrEdit.dispatchEvent(new CustomEvent("internalappendeditvalue",{cancelable:!0,detail:t})),clearCell:()=>!this.readonly&&this.clearCell(),internalPaste:()=>!this.readonly&&this.beforeRegionPaste.emit(),getData:()=>this.getData(),selectAll:()=>this.selectAll.emit()}),this.unsubscribeSelectionStore.push(t.onChange("focus",(()=>{var t;return null===(t=this.keyboardService)||void 0===t?void 0:t.invalidatePendingChanges()})),t.onChange("edit",(()=>{var t;return null===(t=this.keyboardService)||void 0===t?void 0:t.invalidatePendingChanges()}))),this.createAutoFillService()}createAutoFillService(){this.autoFillService=new L({dimensionRow:this.dimensionRow,dimensionCol:this.dimensionCol,columnService:this.columnService,dataStore:this.dataStore,clearRangeDataApply:t=>this.beforeRangeDataApply.emit(Object.assign(Object.assign(Object.assign({},t),this.types),{rowDimension:Object.assign({},this.dimensionRow.state),colDimension:Object.assign({},this.dimensionCol.state)})),setTempRange:t=>{const e=this.beforeSetTempRange.emit(Object.assign(Object.assign({tempRange:t},this.getData()),this.types));return e.defaultPrevented?null:this.setTempRange.emit(e.detail.tempRange)},selectionChanged:t=>this.selectionChange.emit(t),rangeCopy:t=>this.beforeRangeCopyApply.emit(t),rangeDataApply:t=>this.rangeEditApply.emit(t),setRange:t=>!!t&&this.triggerRangeEvent(t),getData:()=>this.getData()})}columnServiceSet(){var t;null===(t=this.columnService)||void 0===t||t.destroy(),this.columnService=new a(this.dataStore,this.colData),this.createAutoFillService()}connectedCallback(){this.columnServiceSet(),this.selectionServiceSet(this.selectionStore)}disconnectedCallback(){var t,e;null===(t=this.keyboardService)||void 0===t||t.invalidatePendingChanges(),this.unsubscribeSelectionStore.forEach((t=>t())),this.unsubscribeSelectionStore.length=0,null===(e=this.columnService)||void 0===e||e.destroy()}async componentWillRender(){var t,e;this.selectionStore.get("edit")||await(null===(e=null===(t=this.revogrEdit)||void 0===t?void 0:t.beforeDisconnect)||void 0===e?void 0:e.call(t))}renderRange(e){const i=y(e,this.dimensionRow.state,this.dimensionCol.state),s=O(i);return t("div",{class:p,style:s},this.isMobileDevice&&t("div",{class:"range-handlers"},t("span",{class:g}),t("span",{class:g})))}renderEditor(){const e=this.selectionStore.get("edit");if(this.readonly||!e)return null;const i=e.val||l(this.columnService.rowDataModel(e.y,e.x).value),s=Object.assign(Object.assign({},e),this.columnService.getSaveData(e.y,e.x,i)),o=this.beforeEditRender.emit(Object.assign(Object.assign({range:Object.assign(Object.assign({},e),{x1:e.x,y1:e.y})},this.types),{rowDimension:Object.assign({},this.dimensionRow.state),colDimension:Object.assign({},this.dimensionCol.state)}));if(o.defaultPrevented)return null;const n=y(o.detail.range,o.detail.rowDimension,o.detail.colDimension),r=O(n);return t("revogr-edit",{style:r,ref:t=>this.revogrEdit=t,additionalData:this.additionalData,editCell:s,saveOnClose:this.applyChangesOnClose,onCelleditinit:t=>{this.cellEditDone.emit(t.detail)},column:this.columnService.rowDataModel(e.y,e.x),editor:h(this.columnService.columns[e.x],this.editors)})}onEditCell(t){if(t.defaultPrevented)return;const e=this.beforeCellSave.emit(t.detail);e.defaultPrevented||this.cellEdit(e.detail),e.detail.preventFocus||this.focusNext()}render(){var e;const i=[],s=this.renderEditor();if(s)i.push(s);else{const s=this.selectionStore.get("range"),o=this.selectionStore.get("focus");(s||o)&&this.useClipboard&&i.push(t("revogr-clipboard",{readonly:this.readonly,onCopyregion:t=>this.onCopy(t.detail),onClearregion:()=>!this.readonly&&this.clearCell(),ref:t=>this.clipboard=t,onPasteregion:t=>this.onPaste(t.detail)})),s&&i.push(this.renderRange(s)),o&&!this.readonly&&this.range&&i.push(null===(e=this.autoFillService)||void 0===e?void 0:e.renderAutofill(s,o,this.isMobileDevice)),this.canDrag&&i.push(t("revogr-order-editor",{ref:t=>this.orderEditor=t,dataStore:this.dataStore,dimensionRow:this.dimensionRow,dimensionCol:this.dimensionCol,parent:this.element,rowType:this.types.rowType,onRowdragstartinit:t=>this.rowDragStart(t)}))}return t(o,{key:"84d904c108e39ebf82b215afc7052d634eba677e",class:{mobile:this.isMobileDevice},onDblClick:t=>this.onElementDblClick(t),onMouseDown:t=>this.onElementMouseDown(t),onTouchStart:t=>this.onElementMouseDown(t,!0),onCloseedit:t=>this.closeEdit(t),onCelledit:t=>this.onEditCell(t)},i,t("slot",{key:"7434c5fceb445de4510675b7627bb5f2efc1a365",name:"data"}))}doFocus(t,e,i,s){const{defaultPrevented:o}=this.beforeFocusCell.emit(Object.assign(Object.assign({},this.columnService.getSaveData(t.y,t.x)),{originalEvent:s}));if(o)return!1;const n=Object.assign(Object.assign({range:Object.assign(Object.assign({},t),{x1:e.x,y1:e.y}),next:i},this.types),{rowDimension:Object.assign({},this.dimensionRow.state),colDimension:Object.assign({},this.dimensionCol.state),originalEvent:s}),r=this.applyFocus.emit(n);if(r.defaultPrevented)return!1;const{range:a}=r.detail;return!this.focusCell.emit(Object.assign({focus:{x:a.x,y:a.y},end:{x:a.x1,y:a.y1}},r.detail)).defaultPrevented}triggerRangeEvent(t,e){const i=this.types.rowType,s=this.beforeApplyRange.emit(Object.assign(Object.assign({range:Object.assign({},t)},this.types),{rowDimension:Object.assign({},this.dimensionRow.state),colDimension:Object.assign({},this.dimensionCol.state),originalEvent:e}));if(s.defaultPrevented)return!1;const o=this.columnService.getRangeTransformedToProps(s.detail.range,this.dataStore);let n=this.beforeSetRange.emit(o);return!n.defaultPrevented&&(n=this.setRange.emit(Object.assign(Object.assign({},s.detail.range),{type:i})),!n.defaultPrevented&&!n.defaultPrevented)}onElementDblClick(t){if(t.defaultPrevented)return;const e=this.getData();S(t,e)&&this.doEdit()}onElementMouseDown(t,e=!1){var i;const s=t.target;if(k(s)||t.defaultPrevented)return;const o=this.getData(),n=S(t,o);n&&(this.focus(n,this.range&&t.shiftKey,t),this.range&&(s&&(null===(i=this.autoFillService)||void 0===i||i.selectionStart(s,this.getData())),e?C(t.touches[0],g)&&t.preventDefault():t.preventDefault()))}doEdit(t=""){if(!this.canEdit())return!1;const e=this.selectionStore.get("focus");if(!e)return!1;const i=this.columnService.getSaveData(e.y,e.x);return!this.setEdit.emit(Object.assign(Object.assign({},i),{val:t})).defaultPrevented}async closeEdit(t){this.cancelEdit.emit(),(null==t?void 0:t.detail)&&await this.focusNext()}cellEdit(t){const e=this.columnService.getSaveData(t.rgRow,t.rgCol,t.val);this.cellEditApply.emit(e)}getRegion(){const t=this.selectionStore.get("focus");let e=this.selectionStore.get("range");return e||(e=r(t,t)),e}onCopy(t){var e;const i=this.getRegion();if(this.beforeCopyRegion.emit(i).defaultPrevented)return!1;let s;if(i){const{data:t,mapping:e}=this.columnService.copyRangeArray(i,this.dataStore),o=this.rangeClipboardCopy.emit(Object.assign({range:i,data:t,mapping:e},this.types));o.defaultPrevented||(s=o.detail.data)}return null===(e=this.clipboard)||void 0===e||e.doCopy(t,s),!0}onPaste(t){var e;const i=this.selectionStore.get("focus"),s=null!==this.selectionStore.get("edit");if(!i||s)return;const o=function(t,e){var i;if(!function(t){return"object"==typeof t&&!0===t.rangeFill}(e))return null;const s=function(t){const e=[...t];for(;e.length>1&&(!(i=e[e.length-1])||i.every((t=>""===t)));)e.pop();var i;return e}(t);return 1===s.length&&1===(null===(i=s[0])||void 0===i?void 0:i.length)?s:null}(t,this.useClipboard),n=o?this.getClipboardPasteTargetRange():null;let{changed:r,range:a}=this.columnService.getTransformedDataToApply({start:i,data:o||t,targetRange:n});const{defaultPrevented:l}=this.rangeClipboardPaste.emit(Object.assign({data:r,models:j(r,this.dataStore),range:a},this.types));l||null===(e=this.autoFillService)||void 0===e||e.onRangeApply(r,a,a)}getClipboardPasteTargetRange(){const t=this.selectionStore.get("range");return t&&!c(t)?t:null}async focusNext(){var t;await(null===(t=this.keyboardService)||void 0===t?void 0:t.keyChangeSelection(new KeyboardEvent("keydown",{code:d.ARROW_DOWN}),this.range))||this.closeEdit()}clearCell(){var t;const e=this.selectionStore.get("range"),i=this.selectionStore.get("focus");if(!e||c(e)&&i){if(this.canEdit()){if(!i)return;const t=this.columnService.getSaveData(i.y,i.x);this.cellEdit({rgRow:i.y,rgCol:i.x,val:"",type:t.type,prop:t.prop})}}else{const i=this.columnService.getRangeStaticData(e,"");null===(t=this.autoFillService)||void 0===t||t.onRangeApply(i,e,e)}}rowDragStart({detail:t}){t.text=l(this.columnService.rowDataModel(t.cell.y,t.cell.x).value)}canEdit(){var t;if(this.readonly)return!1;const e=this.selectionStore.get("focus");return e&&!(null===(t=this.columnService)||void 0===t?void 0:t.isReadOnly(e.y,e.x))}get edited(){return this.selectionStore.get("edit")}focus(t,e=!1,i){if(!t)return!1;const s=t,o=this.selectionStore.get("focus");if(e&&o){const t=r(o,s);if(t)return this.triggerRangeEvent(t,i)}return this.doFocus(t,s,void 0,i)}get types(){return{rowType:this.dataStore.get("type"),colType:this.columnService.type}}getData(){return{el:this.element,rows:this.dimensionRow.state,cols:this.dimensionCol.state,lastCell:this.lastCell,focus:this.selectionStore.get("focus"),range:this.selectionStore.get("range"),edit:this.selectionStore.get("edit")}}get element(){return this}static get watchers(){return{selectionStore:[{selectionServiceSet:0}],dimensionRow:[{createAutoFillService:0}],dimensionCol:[{createAutoFillService:0}],dataStore:[{columnServiceSet:0}],colData:[{columnServiceSet:0}]}}static get style(){return'revogr-overlay-selection{display:block;position:relative;width:100%}revogr-overlay-selection .autofill-handle{position:absolute;width:14px;height:14px;margin-left:-13px;margin-top:-13px;z-index:10;cursor:crosshair}revogr-overlay-selection .autofill-handle::before{content:"";position:absolute;right:0;bottom:0;width:10px;height:10px;background:var(--rg-theme-autofill-handle-bg);border:1px solid var(--rg-theme-autofill-handle-border);box-sizing:border-box}revogr-overlay-selection.mobile .autofill-handle{position:absolute;width:30px;height:30px;margin-left:-29px;margin-top:-29px;z-index:10;cursor:crosshair}revogr-overlay-selection.mobile .autofill-handle::before{content:"";position:absolute;right:0;bottom:0;width:12px;height:12px;background:var(--rg-theme-autofill-handle-bg);border:1px solid var(--rg-theme-autofill-handle-border);box-sizing:border-box}revogr-overlay-selection .selection-border-range{position:absolute;pointer-events:none;z-index:9;background-color:var(--rg-theme-selection-bg)}revogr-overlay-selection .selection-border-range .range-handlers{height:100%;background-color:transparent;width:75%;max-width:50px;min-width:20px;left:50%;transform:translateX(-50%);position:absolute}revogr-overlay-selection .selection-border-range .range-handlers>span{pointer-events:auto;height:20px;width:20px;position:absolute;left:50%;transform:translateX(-50%)}revogr-overlay-selection .selection-border-range .range-handlers>span:before,revogr-overlay-selection .selection-border-range .range-handlers>span:after{position:absolute;border-radius:5px;width:15px;height:5px;left:50%;transform:translateX(-50%);background-color:var(--rg-theme-range-handle-bg)}revogr-overlay-selection .selection-border-range .range-handlers>span:first-child{top:-7px}revogr-overlay-selection .selection-border-range .range-handlers>span:first-child:before{content:"";top:0}revogr-overlay-selection .selection-border-range .range-handlers>span:last-child{bottom:-7px}revogr-overlay-selection .selection-border-range .range-handlers>span:last-child:after{content:"";bottom:0}revogr-overlay-selection .selection-border-range{box-shadow:-1px 0 0 var(--rg-theme-selection-border) inset, 1px 0 0 var(--rg-theme-selection-border) inset, 0 -1px 0 var(--rg-theme-selection-border) inset, 0 1px 0 var(--rg-theme-selection-border) inset}revogr-overlay-selection revogr-edit{z-index:10}'}},[260,"revogr-overlay-selection",{readonly:[4],range:[4],canDrag:[4,"can-drag"],useClipboard:[4,"use-clipboard"],selectionStore:[16],dimensionRow:[16],dimensionCol:[16],dataStore:[16],colData:[16],lastCell:[16],editors:[16],applyChangesOnClose:[4,"apply-changes-on-close"],additionalData:[8,"additional-data"],isMobileDevice:[4,"is-mobile-device"]},[[5,"touchmove","onMouseMove"],[5,"mousemove","onMouseMove"],[5,"touchend","onMouseUp"],[5,"mouseup","onMouseUp"],[5,"mouseleave","onMouseUp"],[0,"dragstartcell","onCellDrag"],[4,"keyup","onKeyUp"],[4,"keydown","onKeyDown"]],{selectionStore:[{selectionServiceSet:0}],dimensionRow:[{createAutoFillService:0}],dimensionCol:[{createAutoFillService:0}],dataStore:[{columnServiceSet:0}],colData:[{columnServiceSet:0}]}]);function V(){"undefined"!=typeof customElements&&["revogr-overlay-selection","revogr-clipboard","revogr-edit","revogr-order-editor"].forEach((t=>{switch(t){case"revogr-overlay-selection":customElements.get(n(t))||customElements.define(n(t),N);break;case"revogr-clipboard":customElements.get(n(t))||X();break;case"revogr-edit":customElements.get(n(t))||z();break;case"revogr-order-editor":customElements.get(n(t))||$()}}))}export{N as O,V as d}
4
+ import{h as t,proxyCustomElement as e,HTMLElement as i,createEvent as s,Host as o,transformTag as n}from"@stencil/core/internal/client";import{g as r,N as a,z as l,O as h,b as c}from"./column.service.js";import{c as d}from"./platform.js";import{R as u,i as g,j as v,S as p}from"./consts.js";import{b,i as f,c as m,a as y,g as x,d as j,e as w,s as O,f as S,v as C}from"./selection.utils.js";import{l as D,m as k,c as E,d as R,f as M,h as A,g as F,j as P,k as T,o as z}from"./revogr-edit2.js";import{t as K}from"./index2.js";import{d as U}from"./debounce.js";import{d as X}from"./revogr-clipboard2.js";import{d as $}from"./revogr-order-editor2.js";const H=[d.ARROW_UP,d.ARROW_DOWN,d.ARROW_LEFT,d.ARROW_RIGHT],q=new Set([d.TAB,...H]);class L{constructor(t){this.sv=t,this.keyChangeQueue=Promise.resolve(!1),this.keyChangeGeneration=0,this.applyingKeyChange=!1}invalidatePendingChanges(){this.applyingKeyChange||(this.keyChangeGeneration+=1)}appendPendingEditValue(t){if(D(t)||1!==t.key.length||t.target instanceof HTMLElement&&k(t.target))return!1;const e=this.sv.selectionStore.get("edit");return"string"==typeof(null==e?void 0:e.val)&&(t.preventDefault(),this.sv.appendEditValue(t.key)||this.sv.selectionStore.set("edit",Object.assign(Object.assign({},e),{val:`${e.val}${t.key}`})),!0)}async keyDown(t,e,i,{range:s,focus:o}){if(i){if(this.appendPendingEditValue(t))return;switch(t.code){case d.ESCAPE:this.sv.cancel();break;case d.TAB:this.keyChangeSelection(t,e)}}else s&&E(t.code)?this.sv.clearCell():o&&(R(t.code)?this.keyChangeSelection(t,e):M(t.key)?this.sv.change():A(t)||F(t)||(P(t)?this.sv.internalPaste():T(t)?e&&this.selectAll(t):D(t)||1!==t.key.length?await this.keyChangeSelection(t,e):this.sv.change(t.key)&&t.preventDefault()))}selectAll(t){const e=this.sv.selectionStore.get("range"),i=this.sv.selectionStore.get("focus");e&&i&&(t.preventDefault(),this.sv.selectAll())}async keyChangeSelection(t,e){const i=this.changeDirectionKey(t,e);if(!i)return!1;const s=this.keyChangeGeneration;await K(u+30);const o=async()=>{if(s!==this.keyChangeGeneration)return!1;const t=this.sv.selectionStore.get("range"),e=this.sv.selectionStore.get("focus");let o;this.applyingKeyChange=!0;try{o=i.edge?this.keyEdgeChange(i.changes,t,e,!!i.isMulti):this.keyPositionChange(i.changes,t,e,i.isMulti)}finally{this.applyingKeyChange=!1}return await new Promise((t=>requestAnimationFrame((()=>{requestAnimationFrame((()=>t()))})))),o},n=this.keyChangeQueue.then(o,o);return this.keyChangeQueue=n.catch((()=>!1)),n}keyPositionChange(t,e,i,s=!1){if(!e||!i)return!1;const o=b(e,i,t,s);if(!o)return!1;const n=this.sv.getData();if(s){if([o.start,o.end].some((t=>f(t,n.lastCell)||m(t))))return!1;const t=r(o.start,o.end);return this.sv.range(t)}return this.sv.focus(o.start,t,f(o.start,n.lastCell)?1:m(o.start)?-1:0)}keyEdgeChange(t,e,i,s){if(!e||!i)return!1;const{lastCell:o}=this.sv.getData(),n=t.x?"x":"y",r=t[n],a=r>0?o[n]-1:0;if(s){const t="x"===n?"x1":"y1";return this.sv.range(Object.assign(Object.assign({},e),{[n]:r<0?a:i[n],[t]:r>0?a:i[n]}))}const l=Object.assign(Object.assign({},i),{[n]:a});return this.sv.focus(l,{[n]:a-i[n]})}changeDirectionKey(t,e){const i=e&&t.shiftKey,s=t.ctrlKey||t.metaKey,o=H.includes(t.code),n=s&&!t.altKey&&o;if(s&&!n)return;if(q.has(t.code)&&t.preventDefault(),t.shiftKey&&t.code===d.TAB)return{changes:{x:-1},isMulti:!1};let r;switch(t.code){case d.ARROW_UP:r={y:-1};break;case d.ARROW_DOWN:r={y:1};break;case d.ARROW_LEFT:r={x:-1};break;case d.TAB:case d.ARROW_RIGHT:r={x:1};break;default:return}return Object.assign({changes:r,isMulti:i},n&&{edge:!0})}}class N{constructor(t){this.sv=t,this.autoFillType=null,this.autoFillInitial=null,this.autoFillStart=null,this.autoFillLast=null}renderAutofill(e,i,s=!1){let o;return o=y(e||Object.assign(Object.assign({},i),{x1:i.x,y1:i.y}),this.sv.dimensionRow.state,this.sv.dimensionCol.state),t("div",{class:{[v]:!0,[g]:s},style:{left:`${o.right}px`,top:`${o.bottom}px`},onMouseDown:t=>this.autoFillHandler(t),onTouchStart:t=>this.autoFillHandler(t)})}autoFillHandler(t,e="AutoFill"){let i=null;t.target instanceof Element&&(i=t.target),i&&(this.selectionStart(i,this.sv.getData(),e),t.preventDefault())}get isAutoFill(){return!!this.autoFillType}selectionMouseMove(t){this.onMouseMoveAutofill||(this.onMouseMoveAutofill=U(((t,e)=>this.doAutofillMouseMove(t,e)),5)),this.isAutoFill&&this.onMouseMoveAutofill(t,this.sv.getData())}getFocus(t,e){return!t&&e&&(t={x:e.x,y:e.y}),t||null}doAutofillMouseMove(t,e){if(!this.autoFillInitial)return;const i=x(t,"clientX",g),s=x(t,"clientY",g);if(null===i||null===s)return;const o=j({x:i,y:s},e);if(this.autoFillLast||this.autoFillLast||(this.autoFillLast=this.autoFillStart),!f(o,e.lastCell))if(this.autoFillLast=o,o.x===this.autoFillInitial.x&&o.y===this.autoFillInitial.y)this.sv.setTempRange(null);else{const t=r(this.autoFillInitial,this.autoFillLast);this.sv.setTempRange({area:t,type:this.autoFillType})}}selectionStart(t,e,i="Selection"){const{top:s,left:o}=t.getBoundingClientRect();this.autoFillInitial=this.getFocus(e.focus,e.range),this.autoFillType=i,this.autoFillStart=j({x:o,y:s},e)}clearAutoFillSelection(t,e){if(this.autoFillInitial)if(this.autoFillInitial=this.getFocus(t,e),"AutoFill"===this.autoFillType){const t=r(this.autoFillInitial,this.autoFillLast);if(t){const{defaultPrevented:i,detail:{range:s}}=this.sv.clearRangeDataApply({range:t});!i&&e?this.applyRangeWithData(s,e):this.sv.setTempRange(null)}}else this.applyRangeOnly(this.autoFillInitial,this.autoFillLast);this.resetAutoFillState()}resetAutoFillState(){this.autoFillType=null,this.autoFillInitial=null,this.autoFillLast=null,this.autoFillStart=null}onRangeApply(t,e,i){this.sv.rangeDataApply({data:t,models:w(t,this.sv.dataStore),type:this.sv.dataStore.get("type"),oldRange:i,newRange:e}),this.sv.setRange(e)}applyRangeWithData(t,e){const i={type:this.sv.dataStore.get("type"),colType:this.sv.columnService.type,newData:{},mapping:{},newRange:t,oldRange:e},{mapping:s,changed:o}=this.sv.columnService.getRangeData(i,this.sv.columnService.columns);i.newData=o,i.mapping=s;let n=this.sv.selectionChanged(i);n.defaultPrevented?this.sv.setTempRange(null):(n=this.sv.rangeCopy(i),n.defaultPrevented?this.sv.setRange(t):this.onRangeApply(i.newData,t,e))}applyRangeOnly(t,e){if(!t||!e)return;const i=r(t,e);this.sv.setRange(i)}}const V=e(class extends i{constructor(t){super(),!1!==t&&this.__registerHost(),this.beforeCopyRegion=s(this,"beforecopyregion",7),this.beforeRegionPaste=s(this,"beforepasteregion",7),this.cellEditApply=s(this,"celleditapply",7),this.beforeFocusCell=s(this,"beforecellfocusinit",7),this.beforeNextViewportFocus=s(this,"beforenextvpfocus",7),this.setEdit=s(this,"setedit",7),this.beforeApplyRange=s(this,"beforeapplyrange",7),this.beforeSetRange=s(this,"beforesetrange",7),this.setRange=s(this,"setrange",7),this.beforeEditRender=s(this,"beforeeditrender",7),this.selectAll=s(this,"selectall",7),this.cancelEdit=s(this,"canceledit",7),this.setTempRange=s(this,"settemprange",7),this.beforeSetTempRange=s(this,"beforesettemprange",7),this.applyFocus=s(this,"applyfocus",7),this.focusCell=s(this,"focuscell",7),this.beforeRangeDataApply=s(this,"beforerangedataapply",7),this.selectionChange=s(this,"selectionchangeinit",7),this.beforeRangeCopyApply=s(this,"beforerangecopyapply",7),this.rangeEditApply=s(this,"rangeeditapply",7),this.rangeClipboardCopy=s(this,"clipboardrangecopy",7),this.rangeClipboardPaste=s(this,"clipboardrangepaste",7),this.beforeKeyDown=s(this,"beforekeydown",7),this.beforeKeyUp=s(this,"beforekeyup",7),this.beforeCellSave=s(this,"beforecellsave",7),this.cellEditDone=s(this,"celledit",7),this.applyChangesOnClose=!1,this.keyboardService=null,this.autoFillService=null,this.unsubscribeSelectionStore=[]}onMouseMove(t){var e;this.selectionStore.get("focus")&&(null===(e=this.autoFillService)||void 0===e||e.selectionMouseMove(t))}onMouseUp(){var t;null===(t=this.autoFillService)||void 0===t||t.clearAutoFillSelection(this.selectionStore.get("focus"),this.selectionStore.get("range"))}onCellDrag(t){var e;null===(e=this.orderEditor)||void 0===e||e.dragStart(t.detail)}onKeyUp(t){this.beforeKeyUp.emit(Object.assign({original:t},this.getData()))}onKeyDown(t){var e;const i=this.beforeKeyDown.emit(Object.assign({original:t},this.getData()));t.defaultPrevented||i.defaultPrevented||null===(e=this.keyboardService)||void 0===e||e.keyDown(t,this.range,!!this.selectionStore.get("edit"),{focus:this.selectionStore.get("focus"),range:this.selectionStore.get("range")})}selectionServiceSet(t){var e;null===(e=this.keyboardService)||void 0===e||e.invalidatePendingChanges(),this.unsubscribeSelectionStore.forEach((t=>t())),this.unsubscribeSelectionStore.length=0,this.unsubscribeSelectionStore.push(t.onChange("nextFocus",(t=>t&&this.doFocus(t,t)))),this.keyboardService=new L({selectionStore:t,range:t=>!!t&&this.triggerRangeEvent(t),focus:(t,e,i)=>i?(this.beforeNextViewportFocus.emit(t),!1):this.doFocus(t,t,e),change:t=>this.doEdit(t),cancel:async()=>{var t;await(null===(t=this.revogrEdit)||void 0===t?void 0:t.cancelChanges()),this.closeEdit()},appendEditValue:t=>!!this.revogrEdit&&!this.revogrEdit.dispatchEvent(new CustomEvent("internalappendeditvalue",{cancelable:!0,detail:t})),clearCell:()=>!this.readonly&&this.clearCell(),internalPaste:()=>!this.readonly&&this.beforeRegionPaste.emit(),getData:()=>this.getData(),selectAll:()=>this.selectAll.emit()}),this.unsubscribeSelectionStore.push(t.onChange("focus",(()=>{var t;return null===(t=this.keyboardService)||void 0===t?void 0:t.invalidatePendingChanges()})),t.onChange("edit",(()=>{var t;return null===(t=this.keyboardService)||void 0===t?void 0:t.invalidatePendingChanges()}))),this.createAutoFillService()}createAutoFillService(){this.autoFillService=new N({dimensionRow:this.dimensionRow,dimensionCol:this.dimensionCol,columnService:this.columnService,dataStore:this.dataStore,clearRangeDataApply:t=>this.beforeRangeDataApply.emit(Object.assign(Object.assign(Object.assign({},t),this.types),{rowDimension:Object.assign({},this.dimensionRow.state),colDimension:Object.assign({},this.dimensionCol.state)})),setTempRange:t=>{const e=this.beforeSetTempRange.emit(Object.assign(Object.assign({tempRange:t},this.getData()),this.types));return e.defaultPrevented?null:this.setTempRange.emit(e.detail.tempRange)},selectionChanged:t=>this.selectionChange.emit(t),rangeCopy:t=>this.beforeRangeCopyApply.emit(t),rangeDataApply:t=>this.rangeEditApply.emit(t),setRange:t=>!!t&&this.triggerRangeEvent(t),getData:()=>this.getData()})}columnServiceSet(){var t;null===(t=this.columnService)||void 0===t||t.destroy(),this.columnService=new a(this.dataStore,this.colData),this.createAutoFillService()}connectedCallback(){this.columnServiceSet(),this.selectionServiceSet(this.selectionStore)}disconnectedCallback(){var t,e;null===(t=this.keyboardService)||void 0===t||t.invalidatePendingChanges(),this.unsubscribeSelectionStore.forEach((t=>t())),this.unsubscribeSelectionStore.length=0,null===(e=this.columnService)||void 0===e||e.destroy()}async componentWillRender(){var t,e;this.selectionStore.get("edit")||await(null===(e=null===(t=this.revogrEdit)||void 0===t?void 0:t.beforeDisconnect)||void 0===e?void 0:e.call(t))}renderRange(e){const i=y(e,this.dimensionRow.state,this.dimensionCol.state),s=O(i);return t("div",{class:p,style:s},this.isMobileDevice&&t("div",{class:"range-handlers"},t("span",{class:g}),t("span",{class:g})))}renderEditor(){const e=this.selectionStore.get("edit");if(this.readonly||!e)return null;const i=e.val||l(this.columnService.rowDataModel(e.y,e.x).value),s=Object.assign(Object.assign({},e),this.columnService.getSaveData(e.y,e.x,i)),o=this.beforeEditRender.emit(Object.assign(Object.assign({range:Object.assign(Object.assign({},e),{x1:e.x,y1:e.y})},this.types),{rowDimension:Object.assign({},this.dimensionRow.state),colDimension:Object.assign({},this.dimensionCol.state)}));if(o.defaultPrevented)return null;const n=y(o.detail.range,o.detail.rowDimension,o.detail.colDimension),r=O(n);return t("revogr-edit",{style:r,ref:t=>this.revogrEdit=t,additionalData:this.additionalData,editCell:s,saveOnClose:this.applyChangesOnClose,onCelleditinit:t=>{this.cellEditDone.emit(t.detail)},column:this.columnService.rowDataModel(e.y,e.x),editor:h(this.columnService.columns[e.x],this.editors)})}onEditCell(t){if(t.defaultPrevented)return;const e=this.beforeCellSave.emit(t.detail);e.defaultPrevented||this.cellEdit(e.detail),e.detail.preventFocus||this.focusNext()}render(){var e;const i=[],s=this.renderEditor();if(s)i.push(s);else{const s=this.selectionStore.get("range"),o=this.selectionStore.get("focus");(s||o)&&this.useClipboard&&i.push(t("revogr-clipboard",{readonly:this.readonly,onCopyregion:t=>this.onCopy(t.detail),onClearregion:()=>!this.readonly&&this.clearCell(),ref:t=>this.clipboard=t,onPasteregion:t=>this.onPaste(t.detail)})),s&&i.push(this.renderRange(s)),o&&!this.readonly&&this.range&&i.push(null===(e=this.autoFillService)||void 0===e?void 0:e.renderAutofill(s,o,this.isMobileDevice)),this.canDrag&&i.push(t("revogr-order-editor",{ref:t=>this.orderEditor=t,dataStore:this.dataStore,dimensionRow:this.dimensionRow,dimensionCol:this.dimensionCol,parent:this.element,rowType:this.types.rowType,onRowdragstartinit:t=>this.rowDragStart(t)}))}return t(o,{key:"84d904c108e39ebf82b215afc7052d634eba677e",class:{mobile:this.isMobileDevice},onDblClick:t=>this.onElementDblClick(t),onMouseDown:t=>this.onElementMouseDown(t),onTouchStart:t=>this.onElementMouseDown(t,!0),onCloseedit:t=>this.closeEdit(t),onCelledit:t=>this.onEditCell(t)},i,t("slot",{key:"7434c5fceb445de4510675b7627bb5f2efc1a365",name:"data"}))}doFocus(t,e,i,s){const{defaultPrevented:o}=this.beforeFocusCell.emit(Object.assign(Object.assign({},this.columnService.getSaveData(t.y,t.x)),{originalEvent:s}));if(o)return!1;const n=Object.assign(Object.assign({range:Object.assign(Object.assign({},t),{x1:e.x,y1:e.y}),next:i},this.types),{rowDimension:Object.assign({},this.dimensionRow.state),colDimension:Object.assign({},this.dimensionCol.state),originalEvent:s}),r=this.applyFocus.emit(n);if(r.defaultPrevented)return!1;const{range:a}=r.detail;return!this.focusCell.emit(Object.assign({focus:{x:a.x,y:a.y},end:{x:a.x1,y:a.y1}},r.detail)).defaultPrevented}triggerRangeEvent(t,e){const i=this.types.rowType,s=this.beforeApplyRange.emit(Object.assign(Object.assign({range:Object.assign({},t)},this.types),{rowDimension:Object.assign({},this.dimensionRow.state),colDimension:Object.assign({},this.dimensionCol.state),originalEvent:e}));if(s.defaultPrevented)return!1;const o=this.columnService.getRangeTransformedToProps(s.detail.range,this.dataStore);let n=this.beforeSetRange.emit(o);return!n.defaultPrevented&&(n=this.setRange.emit(Object.assign(Object.assign({},s.detail.range),{type:i})),!n.defaultPrevented&&!n.defaultPrevented)}onElementDblClick(t){if(t.defaultPrevented)return;const e=this.getData();S(t,e)&&this.doEdit()}onElementMouseDown(t,e=!1){var i;const s=t.target;if(k(s)||t.defaultPrevented)return;const o=this.getData(),n=S(t,o);n&&(this.focus(n,this.range&&t.shiftKey,t),this.range&&(s&&(null===(i=this.autoFillService)||void 0===i||i.selectionStart(s,this.getData())),e?C(t.touches[0],g)&&t.preventDefault():t.preventDefault()))}doEdit(t=""){if(!this.canEdit())return!1;const e=this.selectionStore.get("focus");if(!e)return!1;const i=this.columnService.getSaveData(e.y,e.x);return!this.setEdit.emit(Object.assign(Object.assign({},i),{val:t})).defaultPrevented}async closeEdit(t){this.cancelEdit.emit(),(null==t?void 0:t.detail)&&await this.focusNext()}cellEdit(t){const e=this.columnService.getSaveData(t.rgRow,t.rgCol,t.val);this.cellEditApply.emit(e)}getRegion(){const t=this.selectionStore.get("focus");let e=this.selectionStore.get("range");return e||(e=r(t,t)),e}onCopy(t){var e;const i=this.getRegion();if(this.beforeCopyRegion.emit(i).defaultPrevented)return!1;let s;if(i){const{data:t,mapping:e}=this.columnService.copyRangeArray(i,this.dataStore),o=this.rangeClipboardCopy.emit(Object.assign({range:i,data:t,mapping:e},this.types));o.defaultPrevented||(s=o.detail.data)}return null===(e=this.clipboard)||void 0===e||e.doCopy(t,s),!0}onPaste(t){var e;const i=this.selectionStore.get("focus"),s=null!==this.selectionStore.get("edit");if(!i||s)return;const o=function(t,e){var i;if(!function(t){return"object"==typeof t&&!0===t.rangeFill}(e))return null;const s=function(t){const e=[...t];for(;e.length>1&&(!(i=e[e.length-1])||i.every((t=>""===t)));)e.pop();var i;return e}(t);return 1===s.length&&1===(null===(i=s[0])||void 0===i?void 0:i.length)?s:null}(t,this.useClipboard),n=o?this.getClipboardPasteTargetRange():null;let{changed:r,range:a}=this.columnService.getTransformedDataToApply({start:i,data:o||t,targetRange:n});const{defaultPrevented:l}=this.rangeClipboardPaste.emit(Object.assign({data:r,models:w(r,this.dataStore),range:a},this.types));l||null===(e=this.autoFillService)||void 0===e||e.onRangeApply(r,a,a)}getClipboardPasteTargetRange(){const t=this.selectionStore.get("range");return t&&!c(t)?t:null}async focusNext(){var t;await(null===(t=this.keyboardService)||void 0===t?void 0:t.keyChangeSelection(new KeyboardEvent("keydown",{code:d.ARROW_DOWN}),this.range))||this.closeEdit()}clearCell(){var t;const e=this.selectionStore.get("range"),i=this.selectionStore.get("focus");if(!e||c(e)&&i){if(this.canEdit()){if(!i)return;const t=this.columnService.getSaveData(i.y,i.x);this.cellEdit({rgRow:i.y,rgCol:i.x,val:"",type:t.type,prop:t.prop})}}else{const i=this.columnService.getRangeStaticData(e,"");null===(t=this.autoFillService)||void 0===t||t.onRangeApply(i,e,e)}}rowDragStart({detail:t}){t.text=l(this.columnService.rowDataModel(t.cell.y,t.cell.x).value)}canEdit(){var t;if(this.readonly)return!1;const e=this.selectionStore.get("focus");return e&&!(null===(t=this.columnService)||void 0===t?void 0:t.isReadOnly(e.y,e.x))}get edited(){return this.selectionStore.get("edit")}focus(t,e=!1,i){if(!t)return!1;const s=t,o=this.selectionStore.get("focus");if(e&&o){const t=r(o,s);if(t)return this.triggerRangeEvent(t,i)}return this.doFocus(t,s,void 0,i)}get types(){return{rowType:this.dataStore.get("type"),colType:this.columnService.type}}getData(){return{el:this.element,rows:this.dimensionRow.state,cols:this.dimensionCol.state,lastCell:this.lastCell,focus:this.selectionStore.get("focus"),range:this.selectionStore.get("range"),edit:this.selectionStore.get("edit")}}get element(){return this}static get watchers(){return{selectionStore:[{selectionServiceSet:0}],dimensionRow:[{createAutoFillService:0}],dimensionCol:[{createAutoFillService:0}],dataStore:[{columnServiceSet:0}],colData:[{columnServiceSet:0}]}}static get style(){return'revogr-overlay-selection{display:block;position:relative;width:100%}revogr-overlay-selection .autofill-handle{position:absolute;width:14px;height:14px;margin-left:-13px;margin-top:-13px;z-index:10;cursor:crosshair}revogr-overlay-selection .autofill-handle::before{content:"";position:absolute;right:0;bottom:0;width:10px;height:10px;background:var(--rg-theme-autofill-handle-bg);border:1px solid var(--rg-theme-autofill-handle-border);box-sizing:border-box}revogr-overlay-selection.mobile .autofill-handle{position:absolute;width:30px;height:30px;margin-left:-29px;margin-top:-29px;z-index:10;cursor:crosshair}revogr-overlay-selection.mobile .autofill-handle::before{content:"";position:absolute;right:0;bottom:0;width:12px;height:12px;background:var(--rg-theme-autofill-handle-bg);border:1px solid var(--rg-theme-autofill-handle-border);box-sizing:border-box}revogr-overlay-selection .selection-border-range{position:absolute;pointer-events:none;z-index:9;background-color:var(--rg-theme-selection-bg)}revogr-overlay-selection .selection-border-range .range-handlers{height:100%;background-color:transparent;width:75%;max-width:50px;min-width:20px;left:50%;transform:translateX(-50%);position:absolute}revogr-overlay-selection .selection-border-range .range-handlers>span{pointer-events:auto;height:20px;width:20px;position:absolute;left:50%;transform:translateX(-50%)}revogr-overlay-selection .selection-border-range .range-handlers>span:before,revogr-overlay-selection .selection-border-range .range-handlers>span:after{position:absolute;border-radius:5px;width:15px;height:5px;left:50%;transform:translateX(-50%);background-color:var(--rg-theme-range-handle-bg)}revogr-overlay-selection .selection-border-range .range-handlers>span:first-child{top:-7px}revogr-overlay-selection .selection-border-range .range-handlers>span:first-child:before{content:"";top:0}revogr-overlay-selection .selection-border-range .range-handlers>span:last-child{bottom:-7px}revogr-overlay-selection .selection-border-range .range-handlers>span:last-child:after{content:"";bottom:0}revogr-overlay-selection .selection-border-range{box-shadow:-1px 0 0 var(--rg-theme-selection-border) inset, 1px 0 0 var(--rg-theme-selection-border) inset, 0 -1px 0 var(--rg-theme-selection-border) inset, 0 1px 0 var(--rg-theme-selection-border) inset}revogr-overlay-selection revogr-edit{z-index:10}'}},[260,"revogr-overlay-selection",{readonly:[4],range:[4],canDrag:[4,"can-drag"],useClipboard:[4,"use-clipboard"],selectionStore:[16],dimensionRow:[16],dimensionCol:[16],dataStore:[16],colData:[16],lastCell:[16],editors:[16],applyChangesOnClose:[4,"apply-changes-on-close"],additionalData:[8,"additional-data"],isMobileDevice:[4,"is-mobile-device"]},[[5,"touchmove","onMouseMove"],[5,"mousemove","onMouseMove"],[5,"touchend","onMouseUp"],[5,"mouseup","onMouseUp"],[5,"mouseleave","onMouseUp"],[0,"dragstartcell","onCellDrag"],[4,"keyup","onKeyUp"],[4,"keydown","onKeyDown"]],{selectionStore:[{selectionServiceSet:0}],dimensionRow:[{createAutoFillService:0}],dimensionCol:[{createAutoFillService:0}],dataStore:[{columnServiceSet:0}],colData:[{columnServiceSet:0}]}]);function W(){"undefined"!=typeof customElements&&["revogr-overlay-selection","revogr-clipboard","revogr-edit","revogr-order-editor"].forEach((t=>{switch(t){case"revogr-overlay-selection":customElements.get(n(t))||customElements.define(n(t),V);break;case"revogr-clipboard":customElements.get(n(t))||X();break;case"revogr-edit":customElements.get(n(t))||z();break;case"revogr-order-editor":customElements.get(n(t))||$()}}))}export{V as O,W as d}