stimulus-library 0.9.1 → 0.9.3

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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +43 -43
  3. package/dist/controllers/ajax/async_block_controller.js +9 -20
  4. package/dist/controllers/ajax/lazy_block_controller.js +17 -30
  5. package/dist/controllers/ajax/load_block_controller.js +36 -47
  6. package/dist/controllers/ajax/poll_block_controller.js +10 -21
  7. package/dist/controllers/anchor_spy_controller.js +3 -3
  8. package/dist/controllers/back_link_controller.js +2 -2
  9. package/dist/controllers/clipboard_controller.js +3 -6
  10. package/dist/controllers/confirm_controller.js +3 -3
  11. package/dist/controllers/confirm_navigation_controller.js +1 -1
  12. package/dist/controllers/debug_controller.js +1 -1
  13. package/dist/controllers/disable_with_controller.js +7 -7
  14. package/dist/controllers/element_save_controller.js +8 -8
  15. package/dist/controllers/empty_dom_controller.js +3 -3
  16. package/dist/controllers/equalize_controller.js +1 -1
  17. package/dist/controllers/forms/auto_submit_form_controller.js +1 -1
  18. package/dist/controllers/forms/char_count_controller.js +4 -4
  19. package/dist/controllers/forms/checkbox_disable_inputs_controller.js +4 -4
  20. package/dist/controllers/forms/checkbox_enable_inputs_controller.js +4 -4
  21. package/dist/controllers/forms/checkbox_select_all_controller.js +1 -1
  22. package/dist/controllers/forms/checkbox_xor_controller.js +1 -1
  23. package/dist/controllers/forms/detect_dirty_controller.js +1 -1
  24. package/dist/controllers/forms/detect_dirty_form_controller.js +1 -1
  25. package/dist/controllers/forms/enable_inputs_controller.js +4 -4
  26. package/dist/controllers/forms/focus_steal_controller.js +3 -3
  27. package/dist/controllers/forms/form_rc_controller.js +7 -7
  28. package/dist/controllers/forms/form_save_controller.js +7 -7
  29. package/dist/controllers/forms/limited_selection_checkboxes_controller.js +2 -2
  30. package/dist/controllers/forms/navigate_form_errors_controller.js +38 -56
  31. package/dist/controllers/forms/nested_form_controller.js +6 -6
  32. package/dist/controllers/forms/password_confirm_controller.js +2 -2
  33. package/dist/controllers/forms/password_peek_controller.js +4 -4
  34. package/dist/controllers/forms/remote_form_controller.js +2 -2
  35. package/dist/controllers/forms/sync_inputs_controller.js +3 -3
  36. package/dist/controllers/forms/value_warn_controller.js +8 -8
  37. package/dist/controllers/forms/word_count_controller.js +3 -3
  38. package/dist/controllers/media/fallback_image_controller.js +2 -2
  39. package/dist/controllers/media/lightbox_image_controller.js +7 -10
  40. package/dist/controllers/media/media_player_controller.js +7 -18
  41. package/dist/controllers/persisted_dismissable_controller.js +3 -3
  42. package/dist/controllers/prefetch_controller.js +2 -3
  43. package/dist/controllers/print_button_controller.js +3 -3
  44. package/dist/controllers/refresh_page_controller.js +3 -3
  45. package/dist/controllers/scroll/scroll_container_controller.js +28 -53
  46. package/dist/controllers/scroll/scroll_into_focus_controller.js +5 -5
  47. package/dist/controllers/scroll/scroll_to_bottom_controller.js +8 -19
  48. package/dist/controllers/scroll/scroll_to_controller.js +6 -6
  49. package/dist/controllers/scroll/scroll_to_top_controller.js +8 -19
  50. package/dist/controllers/self_destruct_controller.js +1 -1
  51. package/dist/controllers/signal/base_controller.js +3 -3
  52. package/dist/controllers/signal/signal_action_controller.js +7 -4
  53. package/dist/controllers/signal/signal_disable_controller.js +17 -6
  54. package/dist/controllers/signal/signal_dom_children_controller.js +4 -4
  55. package/dist/controllers/signal/signal_enable_controller.js +19 -6
  56. package/dist/controllers/signal/signal_input_controller.js +5 -6
  57. package/dist/controllers/signal/signal_visibility_controller.js +13 -5
  58. package/dist/controllers/sticky_controller.js +3 -6
  59. package/dist/controllers/tables/table_sort_controller.js +22 -13
  60. package/dist/controllers/tables/table_truncate_controller.js +18 -10
  61. package/dist/controllers/teleport_controller.js +2 -2
  62. package/dist/controllers/temporary_state_controller.js +7 -11
  63. package/dist/controllers/toggle_class_controller.js +8 -8
  64. package/dist/controllers/trix_modifier_controller.js +1 -1
  65. package/dist/controllers/turbo_frame_rc_controller.js +8 -8
  66. package/dist/controllers/turbo_frame_refresh_controller.js +7 -6
  67. package/dist/controllers/utility/alert_controller.js +1 -1
  68. package/dist/controllers/utility/intersection_controller.js +1 -1
  69. package/dist/controllers/utility/interval_controller.js +1 -1
  70. package/dist/controllers/utility/presence_controller.js +1 -1
  71. package/dist/controllers/utility/print_controller.js +1 -1
  72. package/dist/controllers/utility/timeout_controller.js +1 -1
  73. package/dist/controllers/visual/clock_controller.js +1 -1
  74. package/dist/controllers/visual/countdown_controller.js +7 -8
  75. package/dist/controllers/visual/duration_controller.js +13 -13
  76. package/dist/controllers/visual/tabs_controller.js +3 -3
  77. package/dist/controllers/visual/time_distance_controller.js +3 -3
  78. package/dist/controllers/visual/tree_view_controller.js +4 -4
  79. package/dist/controllers/visual/tween_number_controller.js +6 -6
  80. package/dist/mixins/use_event_bus.js +1 -1
  81. package/dist/mixins/use_event_listener.js +1 -1
  82. package/dist/mixins/use_fullscreen.js +8 -17
  83. package/dist/mixins/use_intersection.js +4 -4
  84. package/dist/utilities/base_controller.js +1 -1
  85. package/dist/utilities/ephemeral_controller.js +3 -4
  86. package/dist/utilities/fetchRetry.js +9 -20
  87. package/dist/utilities/logging.js +11 -3
  88. package/dist/utilities/scroll.js +37 -64
  89. package/package.json +8 -8
  90. package/dist/controllers/forms/disable_inputs_controller.js +0 -21
  91. package/dist/controllers/media/fallback_iframe_controller.js +0 -44
@@ -1,15 +1,10 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { BaseController } from "../../utilities/base_controller";
11
2
  import { scrollAbsoluteBottom, scrollAbsoluteLeft, scrollAbsoluteTop, scrollDown, scrollLeft, scrollRight, scrollUp } from "../../utilities/scroll";
12
3
  export class ScrollContainerController extends BaseController {
4
+ static values = {
5
+ behaviour: String,
6
+ increment: Number,
7
+ };
13
8
  get _increment() {
14
9
  return this.hasIncrementValue ? this.incrementValue : 50;
15
10
  }
@@ -26,56 +21,36 @@ export class ScrollContainerController extends BaseController {
26
21
  return "auto";
27
22
  }
28
23
  }
29
- scrollTop(event) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- event === null || event === void 0 ? void 0 : event.preventDefault();
32
- yield scrollAbsoluteTop(this.el, { behavior: this._behaviour });
33
- });
24
+ async scrollTop(event) {
25
+ event?.preventDefault();
26
+ await scrollAbsoluteTop(this.el, { behavior: this._behaviour });
34
27
  }
35
- scrollBottom(event) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- event === null || event === void 0 ? void 0 : event.preventDefault();
38
- yield scrollAbsoluteBottom(this.el, { behavior: this._behaviour });
39
- });
28
+ async scrollBottom(event) {
29
+ event?.preventDefault();
30
+ await scrollAbsoluteBottom(this.el, { behavior: this._behaviour });
40
31
  }
41
- scrollLeft(event) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- event === null || event === void 0 ? void 0 : event.preventDefault();
44
- yield scrollAbsoluteLeft(this.el, { behavior: this._behaviour });
45
- });
32
+ async scrollLeft(event) {
33
+ event?.preventDefault();
34
+ await scrollAbsoluteLeft(this.el, { behavior: this._behaviour });
46
35
  }
47
- scrollRight(event) {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- event === null || event === void 0 ? void 0 : event.preventDefault();
50
- yield scrollAbsoluteLeft(this.el, { behavior: this._behaviour });
51
- });
36
+ async scrollRight(event) {
37
+ event?.preventDefault();
38
+ await scrollAbsoluteLeft(this.el, { behavior: this._behaviour });
52
39
  }
53
- up(event) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- event === null || event === void 0 ? void 0 : event.preventDefault();
56
- yield scrollUp(this.el, this._increment, { behavior: this._behaviour });
57
- });
40
+ async up(event) {
41
+ event?.preventDefault();
42
+ await scrollUp(this.el, this._increment, { behavior: this._behaviour });
58
43
  }
59
- down(event) {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- event === null || event === void 0 ? void 0 : event.preventDefault();
62
- yield scrollDown(this.el, this._increment, { behavior: this._behaviour });
63
- });
44
+ async down(event) {
45
+ event?.preventDefault();
46
+ await scrollDown(this.el, this._increment, { behavior: this._behaviour });
64
47
  }
65
- left(event) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- event === null || event === void 0 ? void 0 : event.preventDefault();
68
- yield scrollLeft(this.el, this._increment, { behavior: this._behaviour });
69
- });
48
+ async left(event) {
49
+ event?.preventDefault();
50
+ await scrollLeft(this.el, this._increment, { behavior: this._behaviour });
70
51
  }
71
- right(event) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- event === null || event === void 0 ? void 0 : event.preventDefault();
74
- yield scrollRight(this.el, this._increment, { behavior: this._behaviour });
75
- });
52
+ async right(event) {
53
+ event?.preventDefault();
54
+ await scrollRight(this.el, this._increment, { behavior: this._behaviour });
76
55
  }
77
56
  }
78
- ScrollContainerController.values = {
79
- behaviour: String,
80
- increment: Number,
81
- };
@@ -1,6 +1,11 @@
1
1
  import { EphemeralController } from "../../utilities/ephemeral_controller";
2
2
  import { scrollToElement } from "../../utilities/scroll";
3
3
  export class ScrollIntoFocusController extends EphemeralController {
4
+ static values = {
5
+ behavior: String,
6
+ block: String,
7
+ inline: String,
8
+ };
4
9
  connect() {
5
10
  requestAnimationFrame(() => {
6
11
  // Attempt smooth scrolling, with polyfill
@@ -13,8 +18,3 @@ export class ScrollIntoFocusController extends EphemeralController {
13
18
  });
14
19
  }
15
20
  }
16
- ScrollIntoFocusController.values = {
17
- behavior: String,
18
- block: String,
19
- inline: String,
20
- };
@@ -1,15 +1,9 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { BaseController } from "../../utilities/base_controller";
11
2
  import { getScrollParent, scrollAbsoluteBottom } from "../../utilities/scroll";
12
3
  export class ScrollToBottomController extends BaseController {
4
+ static values = {
5
+ mode: String,
6
+ };
13
7
  get _mode() {
14
8
  return this.hasModeValue ? this.modeValue : "document";
15
9
  }
@@ -23,15 +17,10 @@ export class ScrollToBottomController extends BaseController {
23
17
  }
24
18
  return target;
25
19
  }
26
- scroll(event) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- event === null || event === void 0 ? void 0 : event.preventDefault();
29
- if (this._scrollTarget) {
30
- yield scrollAbsoluteBottom(this._scrollTarget);
31
- }
32
- });
20
+ async scroll(event) {
21
+ event?.preventDefault();
22
+ if (this._scrollTarget) {
23
+ await scrollAbsoluteBottom(this._scrollTarget);
24
+ }
33
25
  }
34
26
  }
35
- ScrollToBottomController.values = {
36
- mode: String,
37
- };
@@ -1,6 +1,12 @@
1
1
  import { BaseController } from "../../utilities/base_controller";
2
2
  import { scrollToElement } from "../../utilities/scroll";
3
3
  export class ScrollToController extends BaseController {
4
+ static values = {
5
+ selector: String,
6
+ behavior: String,
7
+ block: String,
8
+ inline: String,
9
+ };
4
10
  scroll() {
5
11
  let target = document.querySelector(this.selectorValue);
6
12
  if (!target) {
@@ -14,9 +20,3 @@ export class ScrollToController extends BaseController {
14
20
  }).catch(() => target.scrollIntoView()); // Fallback to snap-scrolling
15
21
  }
16
22
  }
17
- ScrollToController.values = {
18
- selector: String,
19
- behavior: String,
20
- block: String,
21
- inline: String,
22
- };
@@ -1,15 +1,9 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { BaseController } from "../../utilities/base_controller";
11
2
  import { getScrollParent, scrollAbsoluteTop } from "../../utilities/scroll";
12
3
  export class ScrollToTopController extends BaseController {
4
+ static values = {
5
+ mode: String,
6
+ };
13
7
  get _mode() {
14
8
  return this.hasModeValue ? this.modeValue : "document";
15
9
  }
@@ -23,15 +17,10 @@ export class ScrollToTopController extends BaseController {
23
17
  }
24
18
  return target;
25
19
  }
26
- scroll(event) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- event === null || event === void 0 ? void 0 : event.preventDefault();
29
- if (this._scrollTarget) {
30
- yield scrollAbsoluteTop(this._scrollTarget);
31
- }
32
- });
20
+ async scroll(event) {
21
+ event?.preventDefault();
22
+ if (this._scrollTarget) {
23
+ await scrollAbsoluteTop(this._scrollTarget);
24
+ }
33
25
  }
34
26
  }
35
- ScrollToTopController.values = {
36
- mode: String,
37
- };
@@ -1,6 +1,7 @@
1
1
  import { BaseController } from "../utilities/base_controller";
2
2
  import { useTimeout } from "../mixins/use_timeout";
3
3
  export class SelfDestructController extends BaseController {
4
+ static values = { seconds: Number };
4
5
  connect() {
5
6
  requestAnimationFrame(() => {
6
7
  // Only start countdown on first paint
@@ -8,4 +9,3 @@ export class SelfDestructController extends BaseController {
8
9
  });
9
10
  }
10
11
  }
11
- SelfDestructController.values = { seconds: Number };
@@ -4,6 +4,9 @@ import { EventBus } from "../../utilities/event_bus";
4
4
  import { signalConnectEvent, signalValueEvent } from "./events";
5
5
  import { useEventBus } from "../../mixins/use_event_bus";
6
6
  export class SignalBaseController extends BaseController {
7
+ static values = {
8
+ name: String,
9
+ };
7
10
  connect() {
8
11
  EventBus.emit(signalConnectEvent(this.nameValue));
9
12
  useEventBus(this, signalValueEvent(this.nameValue), this._onSignal);
@@ -18,6 +21,3 @@ export class SignalBaseController extends BaseController {
18
21
  return this._predicates.every(predicate => predicate(value));
19
22
  }
20
23
  }
21
- SignalBaseController.values = {
22
- name: String,
23
- };
@@ -1,6 +1,13 @@
1
1
  import { signalEventName } from "./events";
2
2
  import { SignalBaseController } from "./base_controller";
3
3
  export class SignalActionController extends SignalBaseController {
4
+ static values = {
5
+ name: String,
6
+ when: String,
7
+ };
8
+ get predicateString() {
9
+ return this.whenValue;
10
+ }
4
11
  _onSignal(payload) {
5
12
  let value = payload.value;
6
13
  if (!this.hasWhenValue) {
@@ -15,7 +22,3 @@ export class SignalActionController extends SignalBaseController {
15
22
  }
16
23
  }
17
24
  }
18
- SignalActionController.values = {
19
- name: String,
20
- when: String,
21
- };
@@ -1,6 +1,13 @@
1
1
  import { signalEventName } from "./events";
2
2
  import { SignalBaseController } from "./base_controller";
3
3
  export class SignalDisableController extends SignalBaseController {
4
+ static values = {
5
+ name: String,
6
+ when: String,
7
+ };
8
+ get predicateString() {
9
+ return this.whenValue;
10
+ }
4
11
  disable() {
5
12
  this.el.setAttribute("disabled", "true");
6
13
  }
@@ -19,16 +26,20 @@ export class SignalDisableController extends SignalBaseController {
19
26
  return;
20
27
  }
21
28
  if (this.allPredicatesMatch(value)) {
22
- this.dispatchEvent(this.el, signalEventName(this.nameValue, "disable"), { detail: { predicate: this.whenValue, value } });
29
+ this.dispatchEvent(this.el, signalEventName(this.nameValue, "disable"), {
30
+ detail: {
31
+ predicate: this.whenValue, value
32
+ }
33
+ });
23
34
  this.disable();
24
35
  }
25
36
  else {
26
- this.dispatchEvent(this.el, signalEventName(this.nameValue, "enable"), { detail: { predicate: this.whenValue, value } });
37
+ this.dispatchEvent(this.el, signalEventName(this.nameValue, "enable"), {
38
+ detail: {
39
+ predicate: this.whenValue, value
40
+ }
41
+ });
27
42
  this.enable();
28
43
  }
29
44
  }
30
45
  }
31
- SignalDisableController.values = {
32
- name: String,
33
- when: String,
34
- };
@@ -4,6 +4,10 @@ import { signalConnectEvent, signalValueEvent } from "./events";
4
4
  import { useMutationObserver } from "../../mixins/use_mutation_observer";
5
5
  import { useEventBus } from "../../mixins/use_event_bus";
6
6
  export class SignalDomChildrenController extends BaseController {
7
+ static values = {
8
+ name: String,
9
+ scopeSelector: String,
10
+ };
7
11
  get _children() {
8
12
  if (this.hasScopeSelectorValue) {
9
13
  return Array.from(this.el.querySelectorAll(this.scopeSelectorValue));
@@ -36,7 +40,3 @@ export class SignalDomChildrenController extends BaseController {
36
40
  EventBus.emit(signalValueEvent(this._name), { element: this.el, value });
37
41
  }
38
42
  }
39
- SignalDomChildrenController.values = {
40
- name: String,
41
- scopeSelector: String,
42
- };
@@ -1,6 +1,13 @@
1
1
  import { signalEventName } from "./events";
2
2
  import { SignalBaseController } from "./base_controller";
3
3
  export class SignalEnableController extends SignalBaseController {
4
+ static values = {
5
+ name: String,
6
+ when: String,
7
+ };
8
+ get predicateString() {
9
+ return this.whenValue;
10
+ }
4
11
  disable() {
5
12
  this.el.setAttribute("disabled", "true");
6
13
  }
@@ -19,16 +26,22 @@ export class SignalEnableController extends SignalBaseController {
19
26
  return;
20
27
  }
21
28
  if (this.allPredicatesMatch(value)) {
22
- this.dispatchEvent(this.el, signalEventName(this.nameValue, "enable"), { detail: { predicate: this.whenValue, value } });
29
+ this.dispatchEvent(this.el, signalEventName(this.nameValue, "enable"), {
30
+ detail: {
31
+ predicate: this.whenValue,
32
+ value
33
+ }
34
+ });
23
35
  this.enable();
24
36
  }
25
37
  else {
26
- this.dispatchEvent(this.el, signalEventName(this.nameValue, "disable"), { detail: { predicate: this.whenValue, value } });
38
+ this.dispatchEvent(this.el, signalEventName(this.nameValue, "disable"), {
39
+ detail: {
40
+ predicate: this.whenValue,
41
+ value
42
+ }
43
+ });
27
44
  this.disable();
28
45
  }
29
46
  }
30
47
  }
31
- SignalEnableController.values = {
32
- name: String,
33
- when: String,
34
- };
@@ -5,6 +5,10 @@ import { getAllRadiosInGroup, isHTMLInputElement } from "../../utilities";
5
5
  import { signalConnectEvent, signalValueEvent } from "./events";
6
6
  import { useEventBus } from "../../mixins/use_event_bus";
7
7
  export class SignalInputController extends BaseController {
8
+ static values = {
9
+ name: String,
10
+ debounceInterval: Number,
11
+ };
8
12
  get _debounceTimeout() {
9
13
  return this.hasDebounceIntervalValue ? this.debounceIntervalValue : 1;
10
14
  }
@@ -17,20 +21,15 @@ export class SignalInputController extends BaseController {
17
21
  requestAnimationFrame(() => this.emitValue());
18
22
  }
19
23
  emitValue() {
20
- var _a;
21
24
  let value = this.el.value;
22
25
  if (isHTMLInputElement(this.el) && this.el.type === "checkbox") {
23
26
  value = this.el.checked ? "true" : "false";
24
27
  }
25
28
  else if (isHTMLInputElement(this.el) && this.el.type === "radio") {
26
- let selectedValue = (_a = getAllRadiosInGroup(this.el).find(el => el.checked)) === null || _a === void 0 ? void 0 : _a.value;
29
+ let selectedValue = getAllRadiosInGroup(this.el).find(el => el.checked)?.value;
27
30
  value = selectedValue ? selectedValue : "";
28
31
  }
29
32
  this.dispatchEvent(this.el, signalValueEvent(this._name), { detail: { value } });
30
33
  EventBus.emit(signalValueEvent(this._name), { element: this.el, value });
31
34
  }
32
35
  }
33
- SignalInputController.values = {
34
- name: String,
35
- debounceInterval: Number,
36
- };
@@ -1,9 +1,22 @@
1
1
  import { signalVisibilityEvent } from "./events";
2
2
  import { SignalBaseController } from "./base_controller";
3
+ import { installClassMethods } from "../../mixins/install_class_methods";
3
4
  export class SignalVisibilityController extends SignalBaseController {
5
+ static values = {
6
+ name: String,
7
+ show: String,
8
+ };
9
+ static classes = ['hide'];
4
10
  get defaultHideClasses() {
5
11
  return ["hide"];
6
12
  }
13
+ get predicateString() {
14
+ return this.showValue;
15
+ }
16
+ connect() {
17
+ super.connect();
18
+ installClassMethods(this);
19
+ }
7
20
  _onSignal(payload) {
8
21
  let value = payload.value;
9
22
  if (this.showValue == "default") {
@@ -25,8 +38,3 @@ export class SignalVisibilityController extends SignalBaseController {
25
38
  }
26
39
  }
27
40
  }
28
- SignalVisibilityController.values = {
29
- name: String,
30
- show: String,
31
- };
32
- SignalVisibilityController.classes = ['hide'];
@@ -1,10 +1,9 @@
1
1
  import { BaseController } from "../utilities/base_controller";
2
2
  import { useInjectedElement } from "../mixins/use_injected_html";
3
3
  export class StickyController extends BaseController {
4
- constructor() {
5
- super(...arguments);
6
- this._magicElement = null;
7
- }
4
+ static classes = ["stuck"];
5
+ static values = { mode: String };
6
+ _magicElement = null;
8
7
  get defaultStuckClasses() {
9
8
  return ["stuck"];
10
9
  }
@@ -40,5 +39,3 @@ export class StickyController extends BaseController {
40
39
  observer.observe(this._magicElement);
41
40
  }
42
41
  }
43
- StickyController.classes = ["stuck"];
44
- StickyController.values = { mode: String };
@@ -1,11 +1,9 @@
1
1
  import { BaseController } from "../../utilities/base_controller";
2
2
  import { useCollectionEventListener } from "../../mixins/use_event_listener";
3
3
  export class TableSortController extends BaseController {
4
- constructor() {
5
- super(...arguments);
6
- this._lastIndex = null;
7
- this._reverse = false;
8
- }
4
+ static values = { startSort: Number };
5
+ _lastIndex = null;
6
+ _reverse = false;
9
7
  get _tableHead() {
10
8
  let head = this.el.tHead;
11
9
  if (head == null) {
@@ -30,13 +28,19 @@ export class TableSortController extends BaseController {
30
28
  requestAnimationFrame(() => {
31
29
  useCollectionEventListener(this, this._tableHeaders, "click", this.sort);
32
30
  if (this.hasStartSortValue) {
33
- this._sortByColumn(this.startSortValue);
31
+ this.sort(this._headerCellByIndex(this.startSortValue));
34
32
  }
35
33
  });
36
34
  }
37
- sort(event) {
38
- event.preventDefault();
39
- let headerCell = event.target;
35
+ sort(event_or_target) {
36
+ let headerCell;
37
+ if (event_or_target instanceof Event) {
38
+ event_or_target.preventDefault();
39
+ headerCell = event_or_target.target;
40
+ }
41
+ else {
42
+ headerCell = event_or_target;
43
+ }
40
44
  let headerCellIndex = this._indexOfHeaderCell(headerCell);
41
45
  if (headerCell.dataset.sortable == "false") {
42
46
  return;
@@ -57,6 +61,13 @@ export class TableSortController extends BaseController {
57
61
  _indexOfHeaderCell(cell) {
58
62
  return this._tableHeaders.indexOf(cell);
59
63
  }
64
+ _headerCellByIndex(index) {
65
+ let cell = this._tableHeaders.at(index);
66
+ if (!cell) {
67
+ throw new Error(`No cell at index ${index}`);
68
+ }
69
+ return cell;
70
+ }
60
71
  _otherHeaderCells(cell) {
61
72
  return Array.from(this._tableHeaders).filter(otherCell => otherCell != cell);
62
73
  }
@@ -64,12 +75,11 @@ export class TableSortController extends BaseController {
64
75
  let frag = document.createDocumentFragment();
65
76
  let rows = this._tableRows;
66
77
  let newRows = rows.sort((row, otherRow) => {
67
- var _a, _b;
68
78
  let cells = Array.from(row.cells);
69
79
  let otherCells = Array.from(otherRow.cells);
70
80
  // TODO: Handle colspans?
71
- let x = ((_a = cells[index]) === null || _a === void 0 ? void 0 : _a.innerText) || "";
72
- let y = ((_b = otherCells[index]) === null || _b === void 0 ? void 0 : _b.innerText) || "";
81
+ let x = cells[index]?.innerText || "";
82
+ let y = otherCells[index]?.innerText || "";
73
83
  let sortVal = x.localeCompare(y, "en", { sensitivity: "base", numeric: true, caseFirst: "upper" });
74
84
  if (row.dataset.sortTop || otherRow.dataset.sortBottom) {
75
85
  if (row.dataset.sortTop && otherRow.dataset.sortTop) {
@@ -94,4 +104,3 @@ export class TableSortController extends BaseController {
94
104
  this._lastIndex = index;
95
105
  }
96
106
  }
97
- TableSortController.values = { startSort: Number };
@@ -2,12 +2,24 @@ import { BaseController } from "../../utilities/base_controller";
2
2
  import { useEventListener } from "../../mixins/use_event_listener";
3
3
  import { useMutationObserver } from "../../mixins/use_mutation_observer";
4
4
  export class TableTruncateController extends BaseController {
5
+ static targets = ["showMore"];
6
+ static values = {
7
+ limit: Number,
8
+ truncated: Boolean,
9
+ expanded: Boolean,
10
+ };
5
11
  get _truncated() {
6
12
  return this.hasTruncatedValue ? this.truncatedValue : false;
7
13
  }
8
14
  set _truncated(value) {
9
15
  this.truncatedValue = value;
10
16
  }
17
+ get _expanded() {
18
+ return this.hasExpandedValue ? this.expandedValue : false;
19
+ }
20
+ set _expanded(value) {
21
+ this.expandedValue = value;
22
+ }
11
23
  get _tableBody() {
12
24
  return this.el.tBodies[0];
13
25
  }
@@ -25,9 +37,9 @@ export class TableTruncateController extends BaseController {
25
37
  });
26
38
  }
27
39
  truncate(event) {
28
- event === null || event === void 0 ? void 0 : event.preventDefault();
29
- this._truncated = true;
40
+ event?.preventDefault();
30
41
  if (this._tableRows.length >= this._limit) {
42
+ this._truncated = true;
31
43
  this._tableRows.slice(this._limit).forEach((el) => {
32
44
  if (el !== this.showMoreTarget) {
33
45
  this._hideElement(el);
@@ -36,12 +48,13 @@ export class TableTruncateController extends BaseController {
36
48
  this._showElement(this.showMoreTarget);
37
49
  }
38
50
  else {
51
+ this._truncated = false;
39
52
  this._hideElement(this.showMoreTarget);
40
53
  }
41
54
  }
42
55
  expand(event) {
43
- this._truncated = false;
44
- event === null || event === void 0 ? void 0 : event.preventDefault();
56
+ this._expanded = true;
57
+ event?.preventDefault();
45
58
  this._tableRows.slice(this._limit).forEach((el) => {
46
59
  if (el !== this.showMoreTarget) {
47
60
  this._showElement(el);
@@ -50,7 +63,7 @@ export class TableTruncateController extends BaseController {
50
63
  this._hideElement(this.showMoreTarget);
51
64
  }
52
65
  mutate(entries) {
53
- if (this._truncated) {
66
+ if (this._tableRows.length >= this._limit && !this._expanded) {
54
67
  this._reTruncate();
55
68
  }
56
69
  }
@@ -74,8 +87,3 @@ export class TableTruncateController extends BaseController {
74
87
  this._showElement(this.showMoreTarget);
75
88
  }
76
89
  }
77
- TableTruncateController.targets = ["showMore"];
78
- TableTruncateController.values = {
79
- limit: Number,
80
- truncated: Boolean,
81
- };
@@ -1,5 +1,6 @@
1
1
  import { EphemeralController } from "../utilities/ephemeral_controller";
2
2
  export class TeleportController extends EphemeralController {
3
+ static values = { target: String, insert: String, immediate: Boolean };
3
4
  connect() {
4
5
  if (!this.hasInsertValue) {
5
6
  throw new Error("`insert` value was not specified");
@@ -11,7 +12,7 @@ export class TeleportController extends EphemeralController {
11
12
  });
12
13
  }
13
14
  execute(event) {
14
- event === null || event === void 0 ? void 0 : event.preventDefault();
15
+ event?.preventDefault();
15
16
  let element = this.el;
16
17
  let destination = document.querySelector(this.targetValue);
17
18
  if (destination == null) {
@@ -45,4 +46,3 @@ export class TeleportController extends EphemeralController {
45
46
  element.remove();
46
47
  }
47
48
  }
48
- TeleportController.values = { target: String, insert: String, immediate: Boolean };
@@ -5,10 +5,12 @@ import { EphemeralController } from "../utilities/ephemeral_controller";
5
5
  import { useTimeout } from "../mixins/use_timeout";
6
6
  import "../polyfills/string.replaceAll";
7
7
  export class TemporaryStateController extends EphemeralController {
8
- constructor() {
9
- super(...arguments);
10
- this._previousState = {};
11
- }
8
+ static values = {
9
+ attribute: String,
10
+ seconds: Number,
11
+ value: String,
12
+ };
13
+ _previousState = {};
12
14
  get _value() {
13
15
  if (this.hasValueValue) {
14
16
  return this.valueValue;
@@ -42,14 +44,8 @@ export class TemporaryStateController extends EphemeralController {
42
44
  _set(this.el, this._attribute, this._previousState[this._attribute]);
43
45
  }
44
46
  }
45
- TemporaryStateController.values = {
46
- attribute: String,
47
- seconds: Number,
48
- value: String,
49
- };
50
47
  export function applyTemporaryState(element, propertyString, value, seconds, controllerIdentifier = "temporary-state") {
51
- var _a;
52
- if (!element.dataset.controller || !((_a = element.dataset.controller) === null || _a === void 0 ? void 0 : _a.includes(controllerIdentifier))) {
48
+ if (!element.dataset.controller || !element.dataset.controller?.includes(controllerIdentifier)) {
53
49
  let controllerName = (element.dataset.controller || '' + ` ${controllerIdentifier} `).trim();
54
50
  // @ts-ignore
55
51
  controllerName = controllerName.replaceAll(' ', ' ');