Skip to content

Commit

Permalink
In _onKeyDown, Inline a few variables which are only used once
Browse files Browse the repository at this point in the history
  • Loading branch information
Xon committed Aug 25, 2024
1 parent 6eb1bf3 commit ad5a704
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 38 deletions.
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ An example of changing what js:watch will bind to:
npm run js:watch -- --environment WATCH_HOST:0.0.0.0
```

## Build flags

The following build flags are supported via environment variables:

### CHOICES_SEARCH_FUSE
**Values:**: **"full" / "basic" / "null" **
**Usage:** The level of integration with fuse. `full` is the entire fuse.js build, `basic` is fuse.js with just standard fuzzy searching. `null` is a basic prefix string search with no fuse.js
**Example**:
```
npm run js:watch -- --environment CHOICES_SEARCH_FUSE:basic
```

### CHOICES_CAN_USE_DOM
**Values:**: **"1" / "0" **
**Usage:** Indicates if DOM methods are supported in the global namespace. Useful if importing into DOM or the e2e tests without a DOM implementation available.
**Example**:
```
npm run js:watch -- --environment CHOICES_CAN_USE_DOM:1
```

## Pull requests
When submitting a pull request that resolves a bug, feel free to use the following template:

Expand Down
7 changes: 2 additions & 5 deletions public/assets/scripts/choices.js
Original file line number Diff line number Diff line change
Expand Up @@ -4493,10 +4493,7 @@
};
Choices.prototype._onKeyDown = function (event) {
var keyCode = event.keyCode;
var items = this._store.items;
var hasFocusedInput = this.input.isFocussed;
var hasActiveDropdown = this.dropdown.isActive;
var hasItems = this.itemList.element.hasChildNodes();
/*
See:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
Expand Down Expand Up @@ -4545,7 +4542,7 @@
}
switch (keyCode) {
case 65 /* KeyCodeMap.A_KEY */:
return this._onSelectKey(event, hasItems);
return this._onSelectKey(event, this.itemList.element.hasChildNodes());
case 13 /* KeyCodeMap.ENTER_KEY */:
return this._onEnterKey(event, hasActiveDropdown);
case 27 /* KeyCodeMap.ESC_KEY */:
Expand All @@ -4557,7 +4554,7 @@
return this._onDirectionKey(event, hasActiveDropdown);
case 8 /* KeyCodeMap.DELETE_KEY */:
case 46 /* KeyCodeMap.BACK_KEY */:
return this._onDeleteKey(event, items, hasFocusedInput);
return this._onDeleteKey(event, this._store.items, this.input.isFocussed);
}
};
Choices.prototype._onKeyUp = function ( /* event: KeyboardEvent */) {
Expand Down
2 changes: 1 addition & 1 deletion public/assets/scripts/choices.min.js

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions public/assets/scripts/choices.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4487,10 +4487,7 @@ var Choices = /** @class */ (function () {
};
Choices.prototype._onKeyDown = function (event) {
var keyCode = event.keyCode;
var items = this._store.items;
var hasFocusedInput = this.input.isFocussed;
var hasActiveDropdown = this.dropdown.isActive;
var hasItems = this.itemList.element.hasChildNodes();
/*
See:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
Expand Down Expand Up @@ -4539,7 +4536,7 @@ var Choices = /** @class */ (function () {
}
switch (keyCode) {
case 65 /* KeyCodeMap.A_KEY */:
return this._onSelectKey(event, hasItems);
return this._onSelectKey(event, this.itemList.element.hasChildNodes());
case 13 /* KeyCodeMap.ENTER_KEY */:
return this._onEnterKey(event, hasActiveDropdown);
case 27 /* KeyCodeMap.ESC_KEY */:
Expand All @@ -4551,7 +4548,7 @@ var Choices = /** @class */ (function () {
return this._onDirectionKey(event, hasActiveDropdown);
case 8 /* KeyCodeMap.DELETE_KEY */:
case 46 /* KeyCodeMap.BACK_KEY */:
return this._onDeleteKey(event, items, hasFocusedInput);
return this._onDeleteKey(event, this._store.items, this.input.isFocussed);
}
};
Choices.prototype._onKeyUp = function ( /* event: KeyboardEvent */) {
Expand Down
7 changes: 2 additions & 5 deletions public/assets/scripts/choices.search-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4011,10 +4011,7 @@
};
Choices.prototype._onKeyDown = function (event) {
var keyCode = event.keyCode;
var items = this._store.items;
var hasFocusedInput = this.input.isFocussed;
var hasActiveDropdown = this.dropdown.isActive;
var hasItems = this.itemList.element.hasChildNodes();
/*
See:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
Expand Down Expand Up @@ -4063,7 +4060,7 @@
}
switch (keyCode) {
case 65 /* KeyCodeMap.A_KEY */:
return this._onSelectKey(event, hasItems);
return this._onSelectKey(event, this.itemList.element.hasChildNodes());
case 13 /* KeyCodeMap.ENTER_KEY */:
return this._onEnterKey(event, hasActiveDropdown);
case 27 /* KeyCodeMap.ESC_KEY */:
Expand All @@ -4075,7 +4072,7 @@
return this._onDirectionKey(event, hasActiveDropdown);
case 8 /* KeyCodeMap.DELETE_KEY */:
case 46 /* KeyCodeMap.BACK_KEY */:
return this._onDeleteKey(event, items, hasFocusedInput);
return this._onDeleteKey(event, this._store.items, this.input.isFocussed);
}
};
Choices.prototype._onKeyUp = function ( /* event: KeyboardEvent */) {
Expand Down
2 changes: 1 addition & 1 deletion public/assets/scripts/choices.search-basic.min.js

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions public/assets/scripts/choices.search-basic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4005,10 +4005,7 @@ var Choices = /** @class */ (function () {
};
Choices.prototype._onKeyDown = function (event) {
var keyCode = event.keyCode;
var items = this._store.items;
var hasFocusedInput = this.input.isFocussed;
var hasActiveDropdown = this.dropdown.isActive;
var hasItems = this.itemList.element.hasChildNodes();
/*
See:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
Expand Down Expand Up @@ -4057,7 +4054,7 @@ var Choices = /** @class */ (function () {
}
switch (keyCode) {
case 65 /* KeyCodeMap.A_KEY */:
return this._onSelectKey(event, hasItems);
return this._onSelectKey(event, this.itemList.element.hasChildNodes());
case 13 /* KeyCodeMap.ENTER_KEY */:
return this._onEnterKey(event, hasActiveDropdown);
case 27 /* KeyCodeMap.ESC_KEY */:
Expand All @@ -4069,7 +4066,7 @@ var Choices = /** @class */ (function () {
return this._onDirectionKey(event, hasActiveDropdown);
case 8 /* KeyCodeMap.DELETE_KEY */:
case 46 /* KeyCodeMap.BACK_KEY */:
return this._onDeleteKey(event, items, hasFocusedInput);
return this._onDeleteKey(event, this._store.items, this.input.isFocussed);
}
};
Choices.prototype._onKeyUp = function ( /* event: KeyboardEvent */) {
Expand Down
7 changes: 2 additions & 5 deletions public/assets/scripts/choices.search-prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2862,10 +2862,7 @@
};
Choices.prototype._onKeyDown = function (event) {
var keyCode = event.keyCode;
var items = this._store.items;
var hasFocusedInput = this.input.isFocussed;
var hasActiveDropdown = this.dropdown.isActive;
var hasItems = this.itemList.element.hasChildNodes();
/*
See:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
Expand Down Expand Up @@ -2914,7 +2911,7 @@
}
switch (keyCode) {
case 65 /* KeyCodeMap.A_KEY */:
return this._onSelectKey(event, hasItems);
return this._onSelectKey(event, this.itemList.element.hasChildNodes());
case 13 /* KeyCodeMap.ENTER_KEY */:
return this._onEnterKey(event, hasActiveDropdown);
case 27 /* KeyCodeMap.ESC_KEY */:
Expand All @@ -2926,7 +2923,7 @@
return this._onDirectionKey(event, hasActiveDropdown);
case 8 /* KeyCodeMap.DELETE_KEY */:
case 46 /* KeyCodeMap.BACK_KEY */:
return this._onDeleteKey(event, items, hasFocusedInput);
return this._onDeleteKey(event, this._store.items, this.input.isFocussed);
}
};
Choices.prototype._onKeyUp = function ( /* event: KeyboardEvent */) {
Expand Down
2 changes: 1 addition & 1 deletion public/assets/scripts/choices.search-prefix.min.js

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions public/assets/scripts/choices.search-prefix.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2856,10 +2856,7 @@ var Choices = /** @class */ (function () {
};
Choices.prototype._onKeyDown = function (event) {
var keyCode = event.keyCode;
var items = this._store.items;
var hasFocusedInput = this.input.isFocussed;
var hasActiveDropdown = this.dropdown.isActive;
var hasItems = this.itemList.element.hasChildNodes();
/*
See:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
Expand Down Expand Up @@ -2908,7 +2905,7 @@ var Choices = /** @class */ (function () {
}
switch (keyCode) {
case 65 /* KeyCodeMap.A_KEY */:
return this._onSelectKey(event, hasItems);
return this._onSelectKey(event, this.itemList.element.hasChildNodes());
case 13 /* KeyCodeMap.ENTER_KEY */:
return this._onEnterKey(event, hasActiveDropdown);
case 27 /* KeyCodeMap.ESC_KEY */:
Expand All @@ -2920,7 +2917,7 @@ var Choices = /** @class */ (function () {
return this._onDirectionKey(event, hasActiveDropdown);
case 8 /* KeyCodeMap.DELETE_KEY */:
case 46 /* KeyCodeMap.BACK_KEY */:
return this._onDeleteKey(event, items, hasFocusedInput);
return this._onDeleteKey(event, this._store.items, this.input.isFocussed);
}
};
Choices.prototype._onKeyUp = function ( /* event: KeyboardEvent */) {
Expand Down
7 changes: 2 additions & 5 deletions src/scripts/choices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1583,10 +1583,7 @@ class Choices {

_onKeyDown(event: KeyboardEvent): void {
const { keyCode } = event;
const { items } = this._store;
const hasFocusedInput = this.input.isFocussed;
const hasActiveDropdown = this.dropdown.isActive;
const hasItems = this.itemList.element.hasChildNodes();
/*
See:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
Expand Down Expand Up @@ -1639,7 +1636,7 @@ class Choices {

switch (keyCode) {
case KeyCodeMap.A_KEY:
return this._onSelectKey(event, hasItems);
return this._onSelectKey(event, this.itemList.element.hasChildNodes());
case KeyCodeMap.ENTER_KEY:
return this._onEnterKey(event, hasActiveDropdown);
case KeyCodeMap.ESC_KEY:
Expand All @@ -1651,7 +1648,7 @@ class Choices {
return this._onDirectionKey(event, hasActiveDropdown);
case KeyCodeMap.DELETE_KEY:
case KeyCodeMap.BACK_KEY:
return this._onDeleteKey(event, items, hasFocusedInput);
return this._onDeleteKey(event, this._store.items, this.input.isFocussed);
default:
}
}
Expand Down

0 comments on commit ad5a704

Please sign in to comment.