@softheon/armature 21.17.0 → 21.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3661,6 +3661,32 @@ var States;
3661
3661
  States["WY"] = "Wyoming";
3662
3662
  })(States || (States = {}));
3663
3663
 
3664
+ /**
3665
+ * Helpers shared by the input filtering directives.
3666
+ */
3667
+ /**
3668
+ * Keys that never insert a character and must always reach the input:
3669
+ * delete, backspace, tab, escape, enter, decimal point (numpad and keyboard).
3670
+ */
3671
+ const NON_PRINTABLE_KEY_CODES = [46, 8, 9, 27, 13, 110, 190];
3672
+ /**
3673
+ * Determines whether a keydown is a modifier driven editing shortcut.
3674
+ *
3675
+ * Copy, cut, paste, select all, undo and redo are triggered with `Ctrl` on
3676
+ * Windows/Linux and with `Cmd` on macOS. macOS reports `Cmd` through
3677
+ * `metaKey`, not `ctrlKey`, so both must be accepted or the filtering
3678
+ * directives end up calling `preventDefault()` on those shortcuts.
3679
+ *
3680
+ * `altKey` is excluded on purpose: `AltGr` is reported as `Ctrl + Alt` on some
3681
+ * layouts and is used to type characters that these directives still filter.
3682
+ *
3683
+ * @param event The keyboard event raised by the input.
3684
+ * @returns True when the event is a non destructive modifier shortcut that must be allowed.
3685
+ */
3686
+ function isEditingShortcut(event) {
3687
+ return (event.ctrlKey || event.metaKey) && !event.altKey;
3688
+ }
3689
+
3664
3690
  /**
3665
3691
  * Numbers only directive
3666
3692
  */
@@ -3679,15 +3705,11 @@ class NumbersOnlyDirective {
3679
3705
  onKeyDown(event) {
3680
3706
  const e = event;
3681
3707
  if (this.sofArNumbersOnly) {
3682
- if ([46, 8, 9, 27, 13, 110, 190].indexOf(e.keyCode) !== -1 ||
3683
- // Allow: Ctrl+A
3684
- (e.keyCode === 65 && e.ctrlKey) ||
3685
- // Allow: Ctrl+C
3686
- (e.keyCode === 67 && e.ctrlKey) ||
3687
- // Allow: Ctrl+X
3688
- (e.keyCode === 88 && e.ctrlKey) ||
3689
- // Allow: Ctrl+V
3690
- (e.keyCode === 86 && e.ctrlKey) ||
3708
+ // Allow Ctrl/Cmd shortcuts (copy, cut, paste, select all, undo, redo).
3709
+ if (isEditingShortcut(e)) {
3710
+ return;
3711
+ }
3712
+ if (NON_PRINTABLE_KEY_CODES.indexOf(e.keyCode) !== -1 ||
3691
3713
  // Allow: home, end, left, right
3692
3714
  (e.keyCode >= 35 && e.keyCode <= 39)) {
3693
3715
  // let it happen, don't do anything
@@ -3838,13 +3860,11 @@ class AlphaNumericDirective {
3838
3860
  // Reset values each time
3839
3861
  this.isNumber = false;
3840
3862
  this.isLetter = false;
3841
- if (this.allowedKeys.indexOf(e.code.toLowerCase()) !== -1 ||
3842
- // Allow: Ctrl+A
3843
- (e.code.toLowerCase() === 'keya' && e.ctrlKey) ||
3844
- // Allow: Ctrl+C
3845
- (e.code.toLowerCase() === 'keyc' && e.ctrlKey) ||
3846
- // Allow: Ctrl+X
3847
- (e.code.toLowerCase() === 'keyx' && e.ctrlKey)) {
3863
+ // Allow Ctrl/Cmd shortcuts (copy, cut, paste, select all, undo, redo).
3864
+ if (isEditingShortcut(e)) {
3865
+ return;
3866
+ }
3867
+ if (this.allowedKeys.indexOf(e.code.toLowerCase()) !== -1) {
3848
3868
  // let it happen, don't do anything
3849
3869
  return;
3850
3870
  }
@@ -4021,13 +4041,11 @@ class LettersCharactersDirective {
4021
4041
  onKeyDown(event) {
4022
4042
  const e = event;
4023
4043
  if (this.sofArLettersAndSpecialCharacters) {
4024
- if ([46, 8, 9, 27, 13, 110, 190].indexOf(e.keyCode) !== -1 ||
4025
- // Allow: Ctrl+A
4026
- (e.keyCode === 65 && e.ctrlKey) ||
4027
- // Allow: Ctrl+C
4028
- (e.keyCode === 67 && e.ctrlKey) ||
4029
- // Allow: Ctrl+X
4030
- (e.keyCode === 88 && e.ctrlKey) ||
4044
+ // Allow Ctrl/Cmd shortcuts (copy, cut, paste, select all, undo, redo).
4045
+ if (isEditingShortcut(e)) {
4046
+ return;
4047
+ }
4048
+ if (NON_PRINTABLE_KEY_CODES.indexOf(e.keyCode) !== -1 ||
4031
4049
  // Allow: spaces
4032
4050
  (e.keyCode === 32) ||
4033
4051
  // Allow: - (minus sign) on numpad or alphabet keyboard key
@@ -4107,13 +4125,11 @@ class LettersOnlyDirective {
4107
4125
  onKeyDown(event) {
4108
4126
  const e = event;
4109
4127
  if (this.sofArLettersOnly) {
4110
- if ([46, 8, 9, 27, 13, 110, 190].indexOf(e.keyCode) !== -1 ||
4111
- // Allow: Ctrl+A
4112
- (e.keyCode === 65 && e.ctrlKey) ||
4113
- // Allow: Ctrl+C
4114
- (e.keyCode === 67 && e.ctrlKey) ||
4115
- // Allow: Ctrl+X
4116
- (e.keyCode === 88 && e.ctrlKey) ||
4128
+ // Allow Ctrl/Cmd shortcuts (copy, cut, paste, select all, undo, redo).
4129
+ if (isEditingShortcut(e)) {
4130
+ return;
4131
+ }
4132
+ if (NON_PRINTABLE_KEY_CODES.indexOf(e.keyCode) !== -1 ||
4117
4133
  // Allow: spaces
4118
4134
  (e.keyCode === 32) ||
4119
4135
  // Allow: - (minus sign) on numpad or alphabet keyboard key